I'm in the middle of a major yak-shave, trying to figure out why my rails application crashes on my mac with the following error:
$rails s -e production
=> Booting WEBrick
=> Rails 6.1.6.1 application starting in production http://0.0.0.0:3000
=> Run `bin/rails server --help` for more startup options
ruby(18016,0x202c48240) malloc: double free for ptr 0x7fe670963a00
ruby(18016,0x202c48240) malloc: *** set a breakpoint in malloc_error_break to debug
One of the suggestions on the internet is to use a debugger (lldb or gdb) to debug this. Attaching lldb to the "running process" just errors out with
$lldb --attach-pid 18016
(lldb) process attach --pid 18016
error: attach failed: tried to attach to process already being debugged
(lldb)
error: attach failed: debugserver is x86_64 binary running in translation, attach failed.
This seems to indicate that I can't attach lldb to a process running using the Rosetta2 translation layer. And I need to run the app under Rosetta2 since it uses the ruby-oci8 gem and there is no arm64 version of the underlying oracle client libraries needed by the ruby-oci8 gem.
So next attempt is to try and launch the process itself under lldb. Trying this:
$lldb --arch x86_64 `asdf which rails` s -- -e production
(lldb) target create --arch=x86_64 "/Users/rohith/.asdf/installs/ruby/3.0.1/bin/rails"
error: '/Users/rohith/.asdf/installs/ruby/3.0.1/bin/rails' doesn't contain the architecture x86_64
says lldb is trying to launch rails directly, which is a ruby file and not a binary. So ideally I want to get lldb to launch ruby which should then launch rails.
Any ideas on how to solve any of these problems?
Update 1: I can debug ruby using lldb
lldb --arch x86_64 `asdf which ruby`
(lldb) target create --arch=x86_64 "/Users/rohith/.asdf/installs/ruby/3.0.1/bin/ruby"
Current executable set to '/Users/rohith/.asdf/installs/ruby/3.0.1/bin/ruby' (x86_64).
Now I just need a way to launch rails via ruby rather than directly.
The answer turned out to be so simple I'm kicking myself
All I needed to do was call ruby and pass in rails as one of the arguments. The clue was when I opened the rails file and saw this at the beginning of the file:
So invoking rails is equivalent to getting ruby to run the rails ruby file.