Граф коммитов

164 Коммитов

Автор SHA1 Сообщение Дата
Alan Wu b572595918 addr2line.c: Silence GCC 11 false -Wmaybe-uninitialized warning
No warnings from GCC 12.
2023-01-16 15:45:51 -05:00
Alan Wu e22a1fbe18
addr2line.c: Don't special-case DWARF 5 parsing with GCC
While trying to fix YJIT's symbol hygiene issue over at GH-7115, I found
that addr2line.c's DWARF 5 parsing is half-disabled when building with
GCC. Rust's output contains some DW_AT_rnglists_base records, which the
disabled code reads. Without DW_AT_rnglists_base, it crashes when
generating a backtrace.

In common Ruby build configurations, GCC opts to only use
DW_FORM_sec_offset for the range lists, and so it doesn't generate
DW_AT_rnglists_base records, so consuming GCC's DWARF 5 while building
with GCC was not a problem.

However, even when building with GCC, we might need to parse DWARF 5
generated by other compilers at runtime. They could come from C
extensions built by Clang, or come from Rust extensions. This
can happen even when building without YJIT.
2023-01-16 14:25:39 -05:00
NARUSE, Yui ee60756495
Fix backtrace beyond _singtramp on macOS arm64 (#7015)
* move ptrauth_strip logic into vm_dump.c
* don't use _sigtramp special logic on arm64
2022-12-24 02:24:55 +09:00
Yusuke Endoh 65920cfc40 addr2line.c: Strip pointer authentication
We need to manually strip pointer authentication bits on M1 mac because
libunwind leaks them out.

Co-Authored-By: NARUSE, Yui <naruse@airemix.jp>
Co-Authored-By: Yuta Saito <kateinoigakukun@gmail.com>
2022-12-23 23:48:18 +09:00
Yusuke Endoh 95a1d1fde8 addr2line.c: Support DW_FORM_rnglistx 2022-12-23 00:32:35 +09:00
Yusuke Endoh 53c82a6ce4 addr2line.c: Implement DW_AT_*_base
... and add code to parse the sections of .debug_addr_base and
.debug_rnglists_base.
2022-12-23 00:32:35 +09:00
Yusuke Endoh 515f816b7f addr2line.c: Support DW_FORM_strx* forms 2022-12-23 00:32:35 +09:00
Yusuke Endoh 5234f99b76 addr2line.c: Support DW_FORM_addrx* forms
... and add VAL_addr value type
2022-12-23 00:32:35 +09:00
Yusuke Endoh 303e11697d addr2line.c: Keep .debug_str_offsets and .debug_addr sections as well
clang generates DWARF with the sections
2022-12-23 00:32:35 +09:00
Yusuke Endoh d1d61cabbc addr2line.c: Fix another indexing bug 2022-12-22 20:37:40 +09:00
Yusuke Endoh ebd6b5d826 addr2line.c: Fix indexing bug 2022-12-22 20:28:03 +09:00
Yusuke Endoh 78826ad486 addr2info.c: Make it work with --enable-yjit
Background: GCC 12 generates DWARF 5 with .debug_rnglists, while rustc
generates DWARF 4 with .debug_ranges.

The previous logic always used .debug_rnglists if there is the section.
However, we need to refer .debug_ranges for DWARF 4.

This change keeps DWARF version of the current compilation unit and use
a proper section depending on the version.
2022-12-22 18:57:06 +09:00
Yusuke Endoh c827d724b7 addr2line.c: Support "Line Number Program Header" in DWARF 5 2022-12-22 18:57:06 +09:00
Yusuke Endoh 2445a4c5b7 addr2line.c: Keep .debug_line_str section as well
... and properly support DW_FORM_line_strp.

This is a prepartion to support DWARF 5.
2022-12-22 18:57:06 +09:00
Sergey Fedorov 567725ed30
Fix and improve coroutines for Darwin (macOS) ppc/ppc64. (#5975) 2022-10-19 23:49:45 +13:00
Nobuyoshi Nakada b180ffa622
Fix warnings by old gcc
* Use PRIxSIZE instead of "z"
* Fix sign-compare warning
* Suppress unused-but-set-variable warning
2022-06-23 22:52:45 +09:00
xtkoba 940c8b093d Skip `NULL` values from `dladdr(3)`
Fixes [Bug #17810]
2022-06-09 20:43:41 +09:00
Peter Zhu 09c72f41ce Print function name in backtrace when available
If we don't have `saddr` but have `sname` we should output `sname`.
2022-05-13 10:47:50 -04:00
Nobuyoshi Nakada 768ceb4ead
Cast to void pointer for `%p` in commented out code [ci skip] 2021-10-20 11:22:33 +09:00
xtkoba 5d756118af Use the correct address size 2021-09-23 12:29:07 -07:00
xtkoba 77e6715d67 Interpret `DW_RLE_start_length`
Fixes [Bug #17823]
2021-09-23 12:29:07 -07:00
xtkoba f140965b97 Fix return value when `base != 0` 2021-09-23 12:29:07 -07:00
David CARLIER 3ffca65047 addr2line: DragonFlyBSD build update.
same code path as FreeBSD's.
2021-08-31 20:52:49 +09:00
xtkoba+ruby@gmail.com 72317b333b
Ignore `DW_FORM_ref_addr` [Bug #17052]
Ignore `DW_FORM_ref_addr` form and other forms that are not supposed
to be used currently.
2021-08-14 23:57:52 +09:00
Nobuyoshi Nakada a9977ba2f9 Constified addr2line.c 2021-08-14 11:34:31 +09:00
xtkoba d795f494a8 Avoid `free(3)`ing invalid pointer
Fixes [Bug #17794]
2021-06-28 14:06:28 -07:00
David Carlier 5e16c3a12a solaris/illumos build fix. 2021-03-22 22:51:15 +09:00
Yusuke Endoh 9e5105ca45
Support GCC's DWARF 5 [Bug #17585] (#4240)
Co-Authored-By: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
2021-03-15 15:22:34 +09:00
Yusuke Endoh 7d22060c14 addr2line.c: DW_LNS_fixed_advance_pc takes a single uhalf operand
Fixes [Bug #17609]

Co-Authored-By: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>
2021-02-04 17:45:54 +09:00
David CARLIER 739f9297c5
NetBSD build update. (#4079) 2021-02-02 22:05:19 +09:00
Yusuke Endoh c718c30007 addr2line.c: support debuglink by build_id
Currently, addr2line.c supports only one path format of debuglink:
"/usr/lib/debug/usr/bin/ruby.debug".

However, recent debian packages seem to use another format by build_id:
"/usr/lib/debug/.build-id/ab/cdef1234.debug".

5d1bb29841/dh_strip (L292)
5d1bb29841/dh_strip (L353)

This changeset makes ruby backtrace support the second format.
2020-12-11 14:08:33 +09:00
Yusuke Endoh f3c19ddfbc Show C backtrace appropriately at core dump for GCC 8 or later
When ruby is compiled by GCC 8 or later, some frames of C level
backtrace information lacks.

```
$ ./miniruby -e '1.times { Process.kill(:SEGV, $$) }'

...

-- C level backtrace information
-------------------------------------------
/home/mame/work/ruby-gcc-9/miniruby(rb_vm_bugreport+0x611) [0x558a5fdcbc21] ../ruby/vm_dump.c:758
[0x558a5fbc789a]
/home/mame/work/ruby-gcc-9/miniruby(sigsegv+0x4d) [0x558a5fd1eaed] ../ruby/signal.c:959
/lib/x86_64-linux-gnu/libpthread.so.0(__restore_rt+0x0) [0x7f687e6713c0]
/lib/x86_64-linux-gnu/libc.so.6(kill+0xb) [0x7f687e31355b] ../sysdeps/unix/syscall-template.S:78
/home/mame/work/ruby-gcc-9/miniruby(rb_f_kill+0x350) [0x558a5fd1fe60] ../ruby/signal.c:480
[0x558a5fda50d3]
[0x558a5fdb085c]
[0x558a5fdb0fe7]
[0x558a5fdbae1a]
[0x558a5fdaf484]
/home/mame/work/ruby-gcc-9/miniruby(rb_yield_1+0x29f) [0x558a5fdb2fbf] ../ruby/vm.c:1265
/home/mame/work/ruby-gcc-9/miniruby(int_dotimes+0x5c) [0x558a5fc72f2c] ../ruby/numeric.c:5198
[0x558a5fda50d3]
[0x558a5fdb085c]
[0x558a5fdb0fe7]
[0x558a5fdbaf21]
[0x558a5fdaf484]
/home/mame/work/ruby-gcc-9/miniruby(rb_ec_exec_node+0xed) [0x558a5fbcc4fd] ../ruby/eval.c:317
/home/mame/work/ruby-gcc-9/miniruby(ruby_run_node+0x4f) [0x558a5fbd110f] ../ruby/eval.c:375
/home/mame/work/ruby-gcc-9/miniruby(main+0x73) [0x558a5fb2c083] ../ruby/main.c:50
```

By this one-line change, it shows all locations.

```
$ ./miniruby -e '1.times { Process.kill(:SEGV, $$) }'

...

-- C level backtrace information -------------------------------------------
/home/mame/work/ruby-gcc-9/miniruby(rb_print_backtrace+0x11) [0x558247adec21] ../ruby/vm_dump.c:758
/home/mame/work/ruby-gcc-9/miniruby(rb_vm_bugreport) ../ruby/vm_dump.c:956
/home/mame/work/ruby-gcc-9/miniruby(rb_bug_for_fatal_signal+0x15a) [0x5582478da89a] ../ruby/error.c:773
/home/mame/work/ruby-gcc-9/miniruby(sigsegv+0x4d) [0x558247a31aed] ../ruby/signal.c:959
/lib/x86_64-linux-gnu/libpthread.so.0(__restore_rt+0x0) [0x7f82202f73c0]
/lib/x86_64-linux-gnu/libc.so.6(kill+0xb) [0x7f821ff9955b] ../sysdeps/unix/syscall-template.S:78
/home/mame/work/ruby-gcc-9/miniruby(rb_f_kill+0x350) [0x558247a32e60] ../ruby/signal.c:480
/home/mame/work/ruby-gcc-9/miniruby(vm_call_cfunc_with_frame+0x123) [0x558247ab80d3] ../ruby/vm_insnhelper.c:2821
/home/mame/work/ruby-gcc-9/miniruby(vm_call_method_each_type+0x7c) [0x558247ac385c] ../ruby/vm_insnhelper.c:3324
/home/mame/work/ruby-gcc-9/miniruby(vm_call_method+0xc7) [0x558247ac3fe7] ../ruby/vm_insnhelper.c:3428
/home/mame/work/ruby-gcc-9/miniruby(vm_sendish+0x14) [0x558247acde1a] ../ruby/vm_insnhelper.c:4412
/home/mame/work/ruby-gcc-9/miniruby(vm_exec_core) ../ruby/insns.def:789
/home/mame/work/ruby-gcc-9/miniruby(rb_vm_exec+0x1a4) [0x558247ac2484] ../ruby/vm.c:2165
/home/mame/work/ruby-gcc-9/miniruby(rb_yield_1+0x29f) [0x558247ac5fbf] ../ruby/vm.c:1265
/home/mame/work/ruby-gcc-9/miniruby(int_dotimes+0x5c) [0x558247985f2c] ../ruby/numeric.c:5198
/home/mame/work/ruby-gcc-9/miniruby(vm_call_cfunc_with_frame+0x123) [0x558247ab80d3] ../ruby/vm_insnhelper.c:2821
/home/mame/work/ruby-gcc-9/miniruby(vm_call_method_each_type+0x7c) [0x558247ac385c] ../ruby/vm_insnhelper.c:3324
/home/mame/work/ruby-gcc-9/miniruby(vm_call_method+0xc7) [0x558247ac3fe7] ../ruby/vm_insnhelper.c:3428
/home/mame/work/ruby-gcc-9/miniruby(vm_sendish+0x14) [0x558247acdf21] ../ruby/vm_insnhelper.c:4412
/home/mame/work/ruby-gcc-9/miniruby(vm_exec_core) ../ruby/insns.def:770
/home/mame/work/ruby-gcc-9/miniruby(rb_vm_exec+0x1a4) [0x558247ac2484] ../ruby/vm.c:2165
/home/mame/work/ruby-gcc-9/miniruby(rb_ec_exec_node+0xed) [0x5582478df4fd] ../ruby/eval.c:317
/home/mame/work/ruby-gcc-9/miniruby(ruby_run_node+0x4f) [0x5582478e410f] ../ruby/eval.c:375
/home/mame/work/ruby-gcc-9/miniruby(main+0x73) [0x55824783f083] ../ruby/main.c:50
```

Details:

In short, it is an uninitialized variable bug.

Until GCC 7, all function locations are represented by a pair of
DW_AT_low_pc and DW_AT_high_pc in DWARF information.
But since GCC 8, some functions are split to multiple chunks, which are
represented by DW_AT_ranges.
DW_AT_ranges are represented as offsets from a base address.
According to DWARF specification, it is the base address of the
compilation unit, but GCC seems to use zero as default.
The function "di_read_cu" in addr2line.c had a comment about the fact.
However, the base address wasn't initialized as zero.
2020-12-11 01:32:20 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
卜部昌平 8184adabe5 internal/stdbool.h rework
Noticed that internal/stdbool.h and addr2line.c are the only two place
where missing/stdbool.h is included.  Why not delete the file so that
we can merge internal/stdbool.h and missing/stdbool.h into one.
2019-12-26 20:45:12 +09:00
David Carlier e6b72e8cae retrieve current path on macOS 2019-08-20 02:05:10 +09:00
Yusuke Endoh a197579073 addr2line.c: clarify the type of integer expression
to suppress Coverity Scan warning.
This expression converted uint8_t to int, and then int to unsigned long.
Now it directly converts uint8_t to unsigned long.
2019-07-15 08:38:37 +09:00
Yusuke Endoh 41e09ca4be addr2line.c (binary_filename): extend the buffer for NUL terminator 2019-07-14 20:23:29 +09:00
Yusuke Endoh db1c30b37f addr2line.c (main_exe_path): avoid SEGV when /proc is not available
readlink would return -1 if /proc is not mounted.
Coverity Scan found this issue.
2019-07-14 17:54:48 +09:00
Kazuhiro NISHIYAMA c1ebb384fd
Fix a typo 2019-07-07 20:16:31 +09:00
Nobuyoshi Nakada 1ca03dc4f7
Suppress warnings by gcc 9.1 2019-06-08 19:46:32 +09:00
naruse 1f64192494 Use _NSGetMachExecuteHeader() instead of _mh_execute_header
_mh_execute_header is not accessible from a dylib unless libruby.dylib is
built with -undefined dynamic_lookup. And using -undefined
dynamic_lookup is not good style.

Reported by Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-31 12:58:33 +00:00
k0kubun dd67af4892 addr2line.c: fix -Wextra-semi
and ignore only -Wgnu-empty-initializer.
https://travis-ci.org/ruby/ruby/jobs/477867392

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 15:42:44 +00:00
k0kubun d74fc1b175 addr2line.c: do not suppress -Wpedantic
because it was for "-assi -Wpedantic" on Travis, but we changed the
Travis build to "-std=c99 -Wpedantic".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 15:02:35 +00:00
k0kubun 299e9cd91a revert r66768 for Ruby 2.7 due to Misc#15347
It's safer to backport r66768 to 2.6 branch, but for 2.7 it's not
needed anymore.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 15:00:40 +00:00
nobu 671ef4e9e3 Get rid of C99 feature for now [ruby-core:90949] [Bug #15519]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10 00:36:28 +00:00
naruse b755c26146 Show function name based on dladdr
If there's no dwarf and symbol table, this will be a last resort.
(mainly on macOS)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20 22:40:21 +00:00
naruse 529adb6872 Support Universal Binary for macOS
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20 22:40:20 +00:00
shyouhei 9d9e1a4d65 addr2line.c: more on suppressing warnings
See also: https://travis-ci.org/ruby/ruby/jobs/454269559#L1898


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13 02:19:49 +00:00