Jakub Konka
61d5b7c957
Merge pull request #15823 from kcbanner/dwarf_unwind
...
Add DWARF unwinding, and an external debug info loader for ELF
2023-07-21 17:37:22 +02:00
Jakub Konka
c43ee5bb22
Merge pull request #16456 from ziglang/check-object-more-elf
...
std: dump .dynamic, .symtab, .dysym for ELF in `CheckObject`; remove wildcard matchers in favour of `checkContains` helper
2023-07-21 07:25:44 +02:00
kcbanner
b1d86db7b4
dwarf: move macho unwind code from macho -> dwarf
...
dwarf: fixup unchecked .eh_frame CIE offset subtraction
2023-07-20 22:58:16 -04:00
kcbanner
8e6a62ba10
test: disable omit_frame_pointer unwinding tests on aarch64-macos
...
dwarf: handle signal frame CIE flag
2023-07-20 22:58:16 -04:00
kcbanner
6d87bb370a
debug: disable the new unwinder on aarch64-macos
2023-07-20 22:58:16 -04:00
kcbanner
253e6971ad
dwarf: implement aarch64 default register rules
2023-07-20 22:58:16 -04:00
kcbanner
4421b14878
dwarf: fixup rules for setting ip
2023-07-20 22:58:16 -04:00
kcbanner
2bc2b01dbc
dwarf: update the pc register
2023-07-20 22:58:16 -04:00
kcbanner
d99b40d38b
dwarf: fix the unwinder using the incorrect row from the FDE in certain cases
2023-07-20 22:58:16 -04:00
kcbanner
1a2bb70956
dwarf: write the CFA as SP before the register update, in case the SP itself is updated by a column rule
2023-07-20 22:58:16 -04:00
kcbanner
97bda56306
macho: don't scan all eh_frame entries, instead follow the offset from the __unwind_info directly
2023-07-20 22:58:16 -04:00
kcbanner
774dc2fdb7
dwarf: add explicit_fde_offset to support more optimal __unwind_info dwarf lookups
2023-07-20 22:58:16 -04:00
kcbanner
2c76020e77
debug: load the macho unwind sections from the already-mapped image
2023-07-20 22:58:16 -04:00
kcbanner
618b0eb3d3
dwarf: fixup integer overflow in readEhPointer
...
debug: handle the possibility of eh_frame / debug_frame being mapped in memory or loaded from disk
2023-07-20 22:58:16 -04:00
kcbanner
5e399d97d7
use eh_frame from the mapped binary if available
2023-07-20 22:58:16 -04:00
kcbanner
ba813d00f5
dwarf: add abi.stripInstructionPtrAuthCode
2023-07-20 22:58:16 -04:00
kcbanner
7d8b423477
macho: remove unnecessary checks
2023-07-20 22:58:16 -04:00
kcbanner
9549b4acf6
debug: fixup an inconsistency in the getcontext implementation on aarch64-macos
2023-07-20 22:58:16 -04:00
kcbanner
b18031335a
dwarf: use cie.return_address_register instead of assuming it's in the IP register
2023-07-20 22:58:16 -04:00
kcbanner
9b25bee42c
debug: fixup have_getcontext
2023-07-20 22:58:15 -04:00
kcbanner
e5aa2bb224
debug: fixup last_error being printed too many times
2023-07-20 22:58:15 -04:00
kcbanner
891fa3b8b5
debug: fix initialization of the optional fields on StackIterator
...
dwarf: documentation fixups
target: enable unwind tables on macho
2023-07-20 22:58:15 -04:00
kcbanner
5dfb159e15
macho: add aarch64 implementation to unwindFrame
...
dwarf: map the V registers in abi.regBytes
test: add test case that exercises the stack-indirect __unwind_info mode in x86_64
2023-07-20 22:58:15 -04:00
kcbanner
203d96ae97
debug: add relocateContext
...
dwarf: fixup tests that used a ThreadContext
2023-07-20 22:58:15 -04:00
kcbanner
94354aa6aa
macho: add unwindFrame which can unwind stack frames using the __unwind_info section
...
dwarf: fixup missing error
2023-07-20 22:58:15 -04:00
kcbanner
d226b74ae8
dwarf: add ExpressionError to work around the compiler not being able to infer it
...
dwarf: implement OP.entry_value, add tests
2023-07-20 22:58:15 -04:00
kcbanner
21d0154139
dwarf: skip register tests on unimplemented arch / os, add tests for type convesions
...
debug: dupeContext -> copyContext
2023-07-20 22:58:15 -04:00
kcbanner
021f537863
dwarf: fixup default endianness in ExpressionOptions, add control flow tests
2023-07-20 22:58:15 -04:00
kcbanner
54ca62fef4
dwarf: fixup regBytes for the case where there is no context support
...
expressions: add more tests, fix tests for mipsel
debug: add lookupModuleName implementation for macos
2023-07-20 22:58:15 -04:00
kcbanner
5c0d4cef1a
debug: add dupeContext, store a pointer to a copy of ThreadContext on UnwindContext
2023-07-20 22:58:15 -04:00
kcbanner
463bbe7807
dwarf: implement constx,addrx, begin adding DWARF expression tests
2023-07-20 22:58:15 -04:00
kcbanner
5f72c6508d
debug: rename StackTraceContext to ThreadContext
...
dwarf: use ThreadContext instead of os.ucontext_t
dwarf: add regBytes impl for windows
dwarf: fixup expression types for non-native
2023-07-20 22:58:15 -04:00
kcbanner
8547c42ba5
dwarf: expression fixups for non-64bit arches, check call_frame_context when writing expressions
2023-07-20 22:58:15 -04:00
kcbanner
424b1299a8
dwarf: add expression writer
2023-07-20 22:58:14 -04:00
kcbanner
ad5f74c0b1
dwarf: introduce ExpressionContext, add more expression opcodes
2023-07-20 22:58:14 -04:00
kcbanner
576ffaa329
darwin: update mcontext_t definition for aarch64 to add neon state
2023-07-20 22:58:14 -04:00
kcbanner
412cd789bf
debug: fixup base address calculations for macho
...
dwarf: fixup x86 register mapping logic
dwarf: change the register context update to update in-place instead of copying
debug: always print the unwind error type
2023-07-20 22:58:14 -04:00
kcbanner
b85f84061a
dwarf: don't dupe function names, as they are backed by the memory mapped sections
...
dwarf: const-correctness fixups
dwarf: implement the remaining register rules
dwarf: start implmenting the DWARF expression stack machine
2023-07-20 22:58:14 -04:00
kcbanner
62598c2187
debug: rework how unwind errors are printed, and add module name lookup for linux
...
This change enhances stack trace output to include a note that debug info was missing,
and therefore the stack trace may not be accurate. For example, if the user is using a libc
compiled with -fomit-frame-pointer and doesn't have debug symbols installed, any traces
that begin in a libc function may not unwind correctly. This allows the user to notice this and
potentially install debug symbols to improve the output.
2023-07-20 22:58:14 -04:00
kcbanner
f04f9705cc
dwarf: add support for DWARF5 DW_AT_ranges in subprograms, add DebugRangeIterator
...
Some DWARF5 subprograms have non-contiguous instruction ranges. An example of such
a function is `puts` in Ubuntu's libc. This change fixes name lookups for functions that use
DW_AT_range in their DIE.
2023-07-20 22:58:14 -04:00
kcbanner
395ab474eb
dwarf: fix logic error in eh_frame_hdry binary search
2023-07-20 22:58:14 -04:00
kcbanner
6a5e2b713f
debug: de-duplicate some code in macos ModuleDebugInfo
2023-07-20 22:58:14 -04:00
kcbanner
ccc9f82068
c: fixup getcontext
...
debug: supports_context -> have_ucontext, supports_getcontext -> have_getcontext
test: rework dwarf_unwind test case to also test the non-libc path
2023-07-20 22:58:14 -04:00
kcbanner
7bc1695f15
c: musl doesn't implement getcontext, so defer to our implementation in that case
2023-07-20 22:58:14 -04:00
kcbanner
23d9b59b86
c: add getcontext
...
debug: make getContext public
2023-07-20 22:58:14 -04:00
kcbanner
f991b9dc05
debug: fix reading -gdwarf generated debug sections in COFF files
...
I had accidentally regressed support for -gdwarf in 461fb499f3
when I changed the logic to
use the already-mapped exe/dll image instead of loading it from disk. The string table is mapped as all zeroes by the loader,
so if a section header's name is longer than 8 bytes (like the ones generated by -gdwarf), then the name can't be read.
Now, if any section headers require the string table, the file is mapped from disk.
windows: Add NtCreateSection/NtMapViewOfSection/NtUnmapViewOfSection
2023-07-20 22:58:14 -04:00
kcbanner
caa334712f
linux: rework getcontext to closer match the specification (saved IP/SP match the state after it would return)
...
debug: fixup ucontext_t check
2023-07-20 22:58:14 -04:00
kcbanner
89ef004646
debug: x86 unwinding support, more unwinding fixes
...
- Fix unwindFrame using the previous FDE row instead of the current one
- Handle unwinding through noreturn functions
- Add x86-linux getcontext
- Fixup x86_64-linux getcontext not restoring the fp env
- Fix start_addr filtering on x86-windows
2023-07-20 22:58:14 -04:00
kcbanner
5cd8ab2473
debug: enhance writeCurrentStackTrace to use context-based unwinding when available
2023-07-20 22:58:14 -04:00
kcbanner
a9b6f2d929
dwarf: add support for .debug_frame and CIE version 4
2023-07-20 22:58:14 -04:00