Fix C level backtraces for USE_ELF#13195
Conversation
This comment has been minimized.
This comment has been minimized.
addr2line.c
Outdated
| append_obj(&obj); | ||
| obj->path = main_path; | ||
| #ifdef USE_ELF | ||
| addr = fill_lines(num_traces, traces, 1, &obj, lines, -1, errout); |
There was a problem hiding this comment.
Wouldn't it make more sense to make the fill_lines function defined for Mach-O handle the -1 offset (and convert it to 0) too, instead of knowing how to exactly call the function depending on the platform?
There was a problem hiding this comment.
Yeah, that makes sense to me. I'll update it.
1be2ed1 to
eb6e385
Compare
|
Are you able to reproduce this issue in any way? I tried to reproduce this issue from my Linux machine and I wasn't able to.
|
|
Hm, I was able to reproduce it by building Ruby master ( Not sure if there's something specific to the machine, or to the way I'm building Ruby. |
eb6e385 to
428d26a
Compare
|
After chatting with Peter I've gone in a slightly different direction. I don't think we need this special meaning for -1 after all, and can instead treat offset 0 as the main executable directly. |
428d26a to
3329b14
Compare
peterzhu2118
left a comment
There was a problem hiding this comment.
This looks good. Could you add [Bug #21289] to your commit message so the commit is linked to the issue when this is merged?
After upgrading GitHub to Ruby 3.4 we noticed that we stopped getting useful C level backtrace information in our crash reports. We traced it back to github@7dd2afb. Passing 0 instead of -1 made sense for the Mach-O version of `fill_lines`, but there is a separate ELF version of `fill_lines` that still has special handling for -1: https://github.com/ruby/ruby/blob/58e3aa02240a9ec1b5fe6ce60d63828c2cf0c73a/addr2line.c#L2178-L2209 Without this special handling for the main executable, we don't have the right `base_addr` when reading debug info, and so we fail to populate the information for that line: https://github.com/ruby/ruby/blob/58e3aa02240a9ec1b5fe6ce60d63828c2cf0c73a/addr2line.c#L1948 Then we get to https://github.com/ruby/ruby/blob/58e3aa02240a9ec1b5fe6ce60d63828c2cf0c73a/addr2line.c#L2649, and potentially (depending on how things were run) get back `"ruby"` as `info.dli_fname` instead of the absolute path for the executable. We set that as the `binary_filename` and then try to open it inside the next call to `fill_lines`, but that fails (unless you happen to be in the directory where the ruby executable lives) and break out of filling lines entirely: https://github.com/ruby/ruby/blob/58e3aa02240a9ec1b5fe6ce60d63828c2cf0c73a/addr2line.c#L2673-L2674 This commit treats offset 0 as the main executable, rather than having a special meaning for -1 (which gets turned into 0 anyway). [Bug #21289]
3329b14 to
c293390
Compare
After upgrading GitHub to Ruby 3.4 we noticed that we stopped getting useful C level backtrace information in our crash reports. We traced it back to 7dd2afb.
Passing 0 instead of -1 makes sense for the Mach-O version of
fill_lines, but there is a separate ELF version offill_linesthat still has special handling for -1:ruby/addr2line.c
Lines 2178 to 2209 in 58e3aa0
Without this special handling for the main executable, we don't have the right
base_addrwhen reading debug info, and so we fail to populate the information for that line:ruby/addr2line.c
Line 1948 in 58e3aa0
ruby/addr2line.c
Line 2649 in 58e3aa0
"ruby"asinfo.dli_fnameinstead of the absolute path for the executable. We set that as thebinary_filenameand then try to open it inside the next call tofill_lines, but that fails (unless you happen to be in the directory where the ruby executable lives) and breaks out of filling lines entirely:ruby/addr2line.c
Lines 2673 to 2674 in 58e3aa0
[Bug #21289]