Skip to content

Instantly share code, notes, and snippets.

@alazycoder101
Last active July 27, 2024 00:12
Show Gist options
  • Save alazycoder101/89ff01181f4c6d59850505e6e7cd478a to your computer and use it in GitHub Desktop.
Save alazycoder101/89ff01181f4c6d59850505e6e7cd478a to your computer and use it in GitHub Desktop.

Debug Ruby

Installation

# install ruby with debug options with asdf
RUBY_CFLAGS=-O0 CONFIGURE_OPTS='cppflags=-DUSE_RUBY_DEBUG_LOG=1 --enable-debug-env optflags=-fno-omit-frame-pointer' asdf install ruby 3.3.2

output

-> aria2c --allow-overwrite=true --no-conf=true --console-log-level=warn --stderr -o ruby-3.3.2.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.2.tar.gz

-> ./configure "--prefix=$HOME/.asdf/installs/ruby/3.3.2" --with-openssl-dir=/opt/homebrew/opt/openssl@3 --enable-shared --with-libyaml-dir=/opt/homebrew/opt/libyaml --with-gmp-dir=/opt/homebrew/opt/gmp --with-ext=openssl,psych,+ CONFIGURE_OPTS='cppflags=-DUSE_RUBY_DEBUG_LOG=1 --enable-debug-env optflags="-fno-omit-frame-pointer"
-> make -j 8
-> make install

Debug

# use ruby 3.3.3 installed with debug
asdf shell ruby 3.3.3

➜ RUBY_DEBUG_LOG=stderr ruby -e '' 2>&1 | head -5
RUBY_DEBUG_LOG=stderr [stderr]
   0: thread_sched_setup_running_threads	+:0 -:0 +ts:0 -ts:0	thread_pthread.c:572
   1: ractor_sched_lock_	cr:1	thread_pthread.c:574
   2: ractor_sched_unlock_	cr:1	thread_pthread.c:626
   3: thread_sched_setup_running_threads	run:0->1	thread_pthread.c:645
   
➜ 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:2809		th:1
   1: vm_lock_enter	rec:1 owner:1	gc.c:2809		th:1
   2: vm_lock_enter	start locked:0	gc.c:2809		th:1

Output to log file

➜ RUBY_DEBUG_LOG=debug.log ruby -e '' 2>&1

➜ awk -F '\t' '{print $2}' debug.log|sort|uniq
blocking_region_begin
blocking_region_end
consume_communication_pipe
do_mutex_lock
gc_enter
gc_exit
gc_sweep_step
heap_add_freepage
heap_next_free_page
native_stop_timer_thread
native_thread_dedicated_dec
native_thread_dedicated_inc
ractor_check_blocking
ractor_lock
ractor_sched_lock_
ractor_sched_unlock_
ractor_status_set
ractor_unlock
rb_gc_ractor_newobj_cache_clear
rb_mutex_trylock
rb_mutex_unlock_th
rb_ractor_blocking_threads_dec
rb_ractor_blocking_threads_inc
rb_ractor_living_threads_insert
rb_ractor_set_current_ec_
rb_ractor_terminate_all
rb_ractor_thread_switch
rb_thread_create_timer_thread
rb_thread_io_blocking_call
rb_thread_terminate_all
rb_threadptr_interrupt
rb_threadptr_interrupt_common
rb_vm_ractor_blocking_cnt_dec
terminate_all
th_init
thread_sched_deq
thread_sched_lock_
thread_sched_set_running
thread_sched_setup_running_threads
thread_sched_to_ready_common
thread_sched_to_running_common
thread_sched_to_waiting_common
thread_sched_to_waiting_common0
thread_sched_unlock_
thread_sched_wait_running_turn
thread_sched_wakeup_next_thread
thread_sched_wakeup_running_thread
timer_thread_func
timer_thread_polling
timer_thread_register_waiting
timer_thread_set_timeout
timer_thread_setup_mn
unregister_ubf_list
vm_insert_ractor0
vm_lock_enter
vm_lock_leave
vm_ractor_blocking_cnt_inc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment