Commit graph

99 commits

Author SHA1 Message Date
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
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
ba813d00f5 dwarf: add abi.stripInstructionPtrAuthCode 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
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
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
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
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
ad5f74c0b1 dwarf: introduce ExpressionContext, add more expression opcodes 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
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
a9b6f2d929 dwarf: add support for .debug_frame and CIE version 4 2023-07-20 22:58:14 -04:00
kcbanner
6abf1fbfe6 update to new builtin syntax 2023-07-20 22:58:14 -04:00
kcbanner
84a1244b6c dwarf: use eh_frame length if it's available 2023-07-20 22:58:14 -04:00
kcbanner
521988299d add more safety checks when searching for eh_frame entries using findEntry 2023-07-20 22:58:13 -04:00
kcbanner
a47212c72e - rebase and update to lastest master 2023-07-20 22:58:13 -04:00
kcbanner
adbc5bbdb3 dwarf: fixup pointer cast 2023-07-20 22:58:13 -04:00
kcbanner
5781016c35 dwarf: add support for .eh_frame_hdr when unwinding
- .eh_frame_hdr contains a binary-searchable data structure for finding an FDE. If present, we can use this
section to avoid having to parse the entire FDE/CIE list in the binary, instead only entries that are actually
required for unwinding are read.
- rework the inputs pc-relative pointer decoding to support both already-mapped sections as well as sections
mapped from a file
- store the VirtualMachine on UnwindContext so the allocations can be reused
2023-07-20 22:58:13 -04:00
kcbanner
5ebca4392e debug: fixing more compile errors on arches that I hadn't tested on yet 2023-07-20 22:58:13 -04:00
kcbanner
551f153718 dwarf: fixes for non-64 bit systems 2023-07-20 22:58:13 -04:00
kcbanner
d74c8acdfb dwarf: fixup for sort changes 2023-07-20 22:58:13 -04:00
kcbanner
a325d7f6d1 fmt and cleanup 2023-07-20 22:58:13 -04:00
kcbanner
e72e762d1e dwarf: implement more register mappings, fix up macos compile 2023-07-20 22:58:13 -04:00
kcbanner
9145ff7da0 dwarf: implement more register number mappings
- add dwarf.abi.RegisterContext to handle register numbers changing based on DWARF format
2023-07-20 22:58:13 -04:00
kcbanner
b449d98a93 - rework StackIterator to optionally use debug_info to unwind the stack
- add abi routines for getting register values
- unwding is working!
2023-07-20 22:58:13 -04:00
kcbanner
69399fbb82 - add default register rule
- fixup eh pointer decoding
2023-07-20 22:58:13 -04:00
kcbanner
7b4611cfb3 - move writing code to zig-dwarfdump
- implement restore_state, restore_extended, offset_extended
2023-07-20 22:58:13 -04:00
kcbanner
8b8d627137 - add call frame instruction parser
- add register printing
2023-07-20 22:58:13 -04:00
kcbanner
6c1d1aa45c begin working on parsing unwind info 2023-07-20 22:58:13 -04:00
kcbanner
f6148f123e add CommonInformationEntry parser 2023-07-20 22:58:12 -04:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
mlugg
52e7934a21 std.dwarf: fix findCompileUnit when ranges offset is given by const 2023-06-12 14:22:45 -07:00
mlugg
46e724ab28 std.dwarf: handle DWARF 5 compile unit DW_AT_ranges correctly
This data changed quite significantly between DWARF 4 and 5. Some
systems are shipping DWARF 5 libraries (Void Linux on musl libc seems to
use it for crt1 etc), which meant when printing stack traces, a random
compile unit might be incorrectly identified as containing an address,
resulting in incorrect location information.

I was consistently experiencing this issue with compiler stack traces,
and this change fixed it.
2023-05-29 11:28:39 -07:00
Andrew Kelley
ceff278202 fixes to the previous commit
* CompileStep: Avoid calling producesPdbFile() to determine whether the
   option should be respected. If the user asks for it, put it on the
   command line and let the Zig CLI deal with it appropriately.
 * Make the namespace of `std.dwarf.Format.dwarf32` no longer have a
   redundant "dwarf" in it.
 * Add `zig cc` integration for `-gdwarf32` and `-gdwarf64`.
 * Toss in a bonus bug fix for `-gdwarf-2`, `-gdwarf-3`, etc.
 * Avoid using default init values for struct fields unnecessarily.
 * Add missing cache hash addition for the new option.
2023-04-20 15:17:07 -07:00