Skip to content

Fix lldb debug scripts #13048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged

Conversation

eileencodes
Copy link
Member

In #13008 RVALUE was removed without replacement. This means the lldb scripts that relied on RVALUE stopped working.

I updated the ones that were using it just for the bytesize to use slot_size and then round to the nearest power of 40. We can't use slot_size directly because in debug mode it's 48 but RVALUE is 40 bytes.

For the as_type method, I updated it to check the type. It's only used for bignum and array so that's a simple change.

Lastly, for the dump_page method I replaced it with struct free_slot since that's looking at the freelist.

struct RVALUE has been removed from all the scripts and I verified that rp is fixed. I'm not confident the dump_page method is fixed, the freelist looks off, but for now this gets us closer.

@etiennebarrie
Copy link
Contributor

It's not really working for me. After a clean and rebuild:

$ echo '"string".hash' > test.rb
$ make -C target/debug lldb
compiling ../../version.c
linking miniruby
lldb -o 'command script import -r ../../misc/lldb_cruby.py' miniruby --  ../../test.rb 
(lldb) target create "miniruby"
Current executable set to '/Users/etienne/src/github.com/ruby/ruby/target/debug/miniruby' (arm64).
(lldb) settings set -- target.run-args  "../../test.rb"
(lldb) command script import -r ../../misc/lldb_cruby.py
lldb scripts for ruby has been installed.
(lldb) b rb_str_hash_m                                                                                                                                                                                                                                                          Breakpoint 1: where = miniruby`rb_str_hash_m + 16 at string.c:4086:35, address = 0x0000000100304c60
(lldb) r
Process 86318 launched: '/Users/etienne/src/github.com/ruby/ruby/target/debug/miniruby' (arm64)
Process 86318 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100304c60 miniruby`rb_str_hash_m(str=4751833240) at string.c:4086:35
   4083	static VALUE
   4084	rb_str_hash_m(VALUE str)
   4085	{
-> 4086	    st_index_t hval = rb_str_hash(str);
   4087	    return ST2FIX(hval);
   4088	}
   4089	
Target 0: (miniruby) stopped.
(lldb) rp str
bits: [     ]
T_NONE: No value
(lldb) ^D

It's better than main which is crashing but not a whole lot.

@eileencodes
Copy link
Member Author

ok I had checked iseq and a few others which looked correct, but yea it's still broken. I'll look into what's up later on - probably won't get to it until next week.

@eileencodes
Copy link
Member Author

eileencodes commented Apr 4, 2025

That's weird I just tested it and rp str is not broken for me. 🤔

How is your Ruby configured? This is how I'm configuring

./configure --prefix=$HOME/.rubies/ruby-debug --disable-install-rdoc --with-openssl-dir=$(brew --prefix)/opt/openssl@3 optflags='-O0    ' debugflags='-g3' cppflags='-DRUBY_DEBUG'

And my lldb output:

lldb -o 'command script import -r ./misc/lldb_cruby.py' miniruby --  ./test.rb 
(lldb) target create "miniruby"
Current executable set to '/Users/eileencodes/src/github.com/open_source/ruby/miniruby' (arm64).
(lldb) settings set -- target.run-args  "./test.rb"
(lldb) command script import -r ./misc/lldb_cruby.py
lldb scripts for ruby has been installed.
(lldb) b rb_str_hash_m
Breakpoint 1: where = miniruby`rb_str_hash_m + 16 at string.c:4086:35, address = 0x0000000100311a18
(lldb) r
Process 39748 launched: '/Users/eileencodes/src/github.com/open_source/ruby/miniruby' (arm64)
Process 39748 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100311a18 miniruby`rb_str_hash_m(str=0x00000001038f69f0) at string.c:4086:35
   4083	static VALUE
   4084	rb_str_hash_m(VALUE str)
   4085	{
-> 4086	    st_index_t hval = rb_str_hash(str);
   4087	    return ST2FIX(hval);
   4088	}
   4089	
Target 0: (miniruby) stopped.
(lldb) rp str
bits: [     ]
T_STRING: [UTF_8] [7BIT] (const char[6]) $1 = "string"

@etiennebarrie
Copy link
Contributor

I used something like this:

../../configure --prefix=/Users/etienne/.ruby/debug --cache-file=../../config.cache --disable-shared --disable-install-doc --with-ext=openssl,psych,json,+ CFLAGS=-march=native --with-libyaml-dir=/opt/homebrew/opt/libyaml --with-openssl-dir=/opt/homebrew/opt/openssl@3 --with-gmp-dir=/opt/homebrew/opt/gmp --enable-debug-env 'optflags=-O0 -fno-omit-frame-pointer'

I removed the CFLAGS and get the same results. The debugging configure flags come from:

./configure --enable-debug-env optflags="-O0 -fno-omit-frame-pointer"

I tried with debugflags='-g3' too but it's not working still.

@eileencodes
Copy link
Member Author

Can you go back to the commit before 0350290 and check that it works as expected?

@eileencodes
Copy link
Member Author

Also when I run lldb I'm using make lldb - not sure if that makes a difference.

@etiennebarrie
Copy link
Contributor

Can you go back to the commit before 0350290 and check that it works as expected?

Arg sorry indeed I can't even get something to work in that case. Something must be wrong with my environment, I've used your configure options on a clean repo and I still get the same behavior. I tried on multiple computers (under macOS) too.

I did just manage to make it work under lima using clang, though 👍

It does solve the issue in that case. cc @byroot

In ruby#13008 `RVALUE` was removed without replacement. This means
the lldb scripts that relied on `RVALUE` stopped working.

I updated the ones that were using it just for the bytesize to use
`slot_size` and then round to the nearest power of 40. We can't use
`slot_size` directly because in debug mode it's `48` but `RVALUE` is
`40` bytes.

For the `as_type` method, I updated it to check the type. It's only used
for `bignum` and `array` so that's a simple change.

Lastly, for the `dump_page` method I replaced it with `struct free_slot`
since that's looking at the freelist.

`struct RVALUE` has been removed from all the scripts and I verified
that `rp` is fixed. I'm not confident the `dump_page` method is fixed,
the freelist looks off, but for now this gets us closer.
Copy link

launchable-app bot commented Apr 8, 2025

All Tests passed!

✖️no tests failed ✔️61930 tests passed(3 flakes)

@eileencodes eileencodes merged commit 5aa05f1 into ruby:master Apr 8, 2025
75 checks passed
@eileencodes eileencodes deleted the fix-lldb-scripts branch April 8, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants