I built Ruby today with debugging, and here's what I did. I experimented with several configure options and flags; this was the minimum I needed for VM logging.
I have a guess about why your build didn't work, which I'll describe at the end.
- Clone ruby, it's at:
git rev-parse master --short # => 191e4ae33f
- Follow the instructions in
doc/contributing/building_ruby.md
.
- Configure as:
- Enable the debug CPP macro
- An install prefix
- Disable documentation (particular to this build, I didn't need docs)
- Configure OpenSSL (particular to this build, on macOS)
- Build, I didn't bother to
make install
Just to be clear, there were no Ruby or debug-related environment variables influencing the build.
$ env | egrep -i 'RUBY|DEBUG'
$ git clone https://github.com/ruby/ruby.git
$ cd ruby
$ ./autogen.sh
$ mkdir build && cd build
$ ../configure cppflags="-DUSE_RUBY_DEBUG_LOG=1" --prefix=${HOME}/.rubies/ruby-master --disable-install-doc --with-openssl-dir=$(
$ make -j8
There is no need to pass -d
or all those environment variables for Ruby to emit the VM debug information, RUBY_DEBUG_LOG=[dest]
is sufficient.
Below is Ruby emitting debug output, and I also verified filtering works.
- Verify there is no output unless requested, this is expected:
$ ./ruby -e '' # No output, ok
- Ask for debug output on stderr:
$ RUBY_DEBUG_LOG=stderr ./ruby -e '' 2>&1 | head -5
RUBY_DEBUG_LOG=stderr [stderr]
0: rb_ractor_set_current_ec_ ec:0x0000000000000000->0x000000013a704740 vm.c:4046 th:0
1: heap_add_freepage page:0x000000013b80b000 freelist:0x000000010491ffc8 gc.c:2026 th:0
2: heap_add_freepage page:0x000000013b80b600 freelist:0x000000010493ffd0 gc.c:2026 th:0
3: heap_add_freepage page:0x000000013b80bc00 freelist:0x000000010495ffd8 gc.c:2026 th:0
- Ask for specific debug output on stderr:
$ RUBY_DEBUG_LOG=stderr RUBY_DEBUG_LOG_FILTER='vm_lock_enter' ./ruby -e '' 2>&1 | head -5
RUBY_DEBUG_LOG=stderr [stderr]
RUBY_DEBUG_LOG_FILTER[0]=vm_lock_enter (all)
0: vm_lock_enter start locked:0 gc.c:2799 th:0
1: vm_lock_enter rec:1 owner:1 gc.c:2799 th:0
2: vm_lock_enter start locked:0 gc.c:2799 th:0
You don't mention what revision (or commit) of Ruby you were building. Since the date of your post, there is this patch on master
:
commit 0d415a322f5dd7158efcbc6c3226266e312620c7
Author: Koichi Sasada <ko1@atdot.net>
Date: Wed Mar 1 17:07:50 2023 +0900
Enable DEBUG_LOG feature on USE_RUBY_DEBUG_LOG
`ruby_set_debug_option` is needed for `RUBY_DEBUG_LOG` feature
so it should be called when `USE_RUBY_DEBUG_LOG` is true.
diff --git a/main.c b/main.c
index 0d0ec147cd..072dc56dd5 100644
--- a/main.c
+++ b/main.c
@@ -23,6 +23,7 @@
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
+
#if defined RUBY_DEVEL && !defined RUBY_DEBUG_ENV
# define RUBY_DEBUG_ENV 1
#endif
@@ -46,7 +47,7 @@ int rb_wasm_rt_start(int (main)(int argc, char **argv), int argc, char **argv);
int
main(int argc, char **argv)
{
-#ifdef RUBY_DEBUG_ENV
+#if defined(RUBY_DEBUG_ENV) || USE_RUBY_DEBUG_LOG
ruby_set_debug_option(getenv("RUBY_DEBUG"));
#endif
#ifdef HAVE_LOCALE_H
Reading the diff and the context lines, and looking at your ./configure
, I think (back in October) you would have needed to pass --enable-devel
or cppflags="-DRUBY_DEBUG_ENV"
, and not "-DRUBY_DEBUG"
. I didn't checkout a commit from that time and to test. :-)
After this patch, if only USE_RUBY_DEBUG_LOG
is set, then RUBY_DEBUG
will be enabled in the VM, which is presumably happening in ruby_set_debug_option()
.
Aside, you may also be interested in the --enable-devel
option, I did subsequently build with it, but I didn't want to confuse this answer, nor have I investigated details yet.