Skip to content
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

Add DWARF unwinding, and an external debug info loader for ELF #15823

Merged
merged 81 commits into from
Jul 21, 2023

Commits on Jul 21, 2023

  1. debug: support loading elf debug info from external files

    Some distributions (ie. Ubuntu) have their libc debug
    info in separate files. This change allows the stack walking
    code to read that debug info.
    
    - add support for reading compressed ELF sections
    - support reading the build-id from the elf headers in order to lookup external debug info
    - support reading the .gnu_debuglink section to look up external debug info
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    ea9917d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f6148f1 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    6c1d1aa View commit details
    Browse the repository at this point in the history
  4. - add call frame instruction parser

    - add register printing
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    8b8d627 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    38303d7 View commit details
    Browse the repository at this point in the history
  6. - add DWARF expression parser

    - change read apis to use a stream
    - add register formatters
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    f3f3c87 View commit details
    Browse the repository at this point in the history
  7. - fix remember_state

    - implement def_cfa_register
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    338df86 View commit details
    Browse the repository at this point in the history
  8. - move writing code to zig-dwarfdump

    - implement restore_state, restore_extended, offset_extended
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    7b4611c View commit details
    Browse the repository at this point in the history
  9. - implement more opcodes

    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    a0a40c2 View commit details
    Browse the repository at this point in the history
  10. - add default register rule

    - fixup eh pointer decoding
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    69399fb View commit details
    Browse the repository at this point in the history
  11. - rework StackIterator to optionally use debug_info to unwind the stack

    - add abi routines for getting register values
    - unwding is working!
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    b449d98 View commit details
    Browse the repository at this point in the history
  12. dwarf: implement more register number mappings

    - add dwarf.abi.RegisterContext to handle register numbers changing based on DWARF format
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    9145ff7 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    e72e762 View commit details
    Browse the repository at this point in the history
  14. - rework CFI instruction parsing to not use std.meta

    - move register formatting code to zig-dwardump
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    c98e03f View commit details
    Browse the repository at this point in the history
  15. fmt and cleanup

    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    a325d7f View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    d1a9bb1 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    d74c8ac View commit details
    Browse the repository at this point in the history
  18. debug: use an explicit context type instead of anytype for dumpStackT…

    …raceFromBase, update crash_report to use this for exceptions
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    2f75d20 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    551f153 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    5ebca43 View commit details
    Browse the repository at this point in the history
  21. debug: more fixups for mips linux not having ucontext_t

    - increase test-std max_rss to 1.1 above the CI observed amount
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    865d4d2 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    dd20357 View commit details
    Browse the repository at this point in the history
  23. 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    5781016 View commit details
    Browse the repository at this point in the history
  24. dwarf: fixup pointer cast

    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    adbc5bb View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    a47212c View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    5219882 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    84a1244 View commit details
    Browse the repository at this point in the history
  28. update to new builtin syntax

    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    6abf1fb View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    41832aa View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    a9b6f2d View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    5cd8ab2 View commit details
    Browse the repository at this point in the history
  32. 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    89ef004 View commit details
    Browse the repository at this point in the history
  33. linux: rework getcontext to closer match the specification (saved IP/…

    …SP match the state after it would return)
    
    debug: fixup ucontext_t check
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    caa3347 View commit details
    Browse the repository at this point in the history
  34. debug: fix reading -gdwarf generated debug sections in COFF files

    I had accidentally regressed support for -gdwarf in 461fb49 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    f991b9d View commit details
    Browse the repository at this point in the history
  35. c: add getcontext

    debug: make getContext public
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    23d9b59 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    9c908ea View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    7bc1695 View commit details
    Browse the repository at this point in the history
  38. 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    ccc9f82 View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    6a5e2b7 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    395ab47 View commit details
    Browse the repository at this point in the history
  41. dwarf: add support for DWARF5 DW_AT_ranges in subprograms, add DebugR…

    …angeIterator
    
    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.
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    f04f970 View commit details
    Browse the repository at this point in the history
  42. debug: rework how unwind errors are printed, and add module name look…

    …up 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.
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    62598c2 View commit details
    Browse the repository at this point in the history
  43. dwarf: don't dupe function names, as they are backed by the memory ma…

    …pped sections
    
    dwarf: const-correctness fixups
    dwarf: implement the remaining register rules
    dwarf: start implmenting the DWARF expression stack machine
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    b85f840 View commit details
    Browse the repository at this point in the history
  44. 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    412cd78 View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    576ffaa View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    ad5f74c View commit details
    Browse the repository at this point in the history
  47. dwarf: add expression writer

    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    424b129 View commit details
    Browse the repository at this point in the history
  48. dwarf: expression fixups for non-64bit arches, check call_frame_conte…

    …xt when writing expressions
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    8547c42 View commit details
    Browse the repository at this point in the history
  49. 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    5f72c65 View commit details
    Browse the repository at this point in the history
  50. Configuration menu
    Copy the full SHA
    463bbe7 View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    5c0d4ce View commit details
    Browse the repository at this point in the history
  52. 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    54ca62f View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    021f537 View commit details
    Browse the repository at this point in the history
  54. dwarf: skip register tests on unimplemented arch / os, add tests for …

    …type convesions
    
    debug: dupeContext -> copyContext
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    21d0154 View commit details
    Browse the repository at this point in the history
  55. dwarf: add ExpressionError to work around the compiler not being able…

    … to infer it
    
    dwarf: implement OP.entry_value, add tests
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    d226b74 View commit details
    Browse the repository at this point in the history
  56. macho: add unwindFrame which can unwind stack frames using the __unwi…

    …nd_info section
    
    dwarf: fixup missing error
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    94354aa View commit details
    Browse the repository at this point in the history
  57. debug: add relocateContext

    dwarf: fixup tests that used a ThreadContext
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    203d96a View commit details
    Browse the repository at this point in the history
  58. 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
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    5dfb159 View commit details
    Browse the repository at this point in the history
  59. debug: fix initialization of the optional fields on StackIterator

    dwarf: documentation fixups
    target: enable unwind tables on macho
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    891fa3b View commit details
    Browse the repository at this point in the history
  60. Configuration menu
    Copy the full SHA
    e5aa2bb View commit details
    Browse the repository at this point in the history
  61. debug: fixup have_getcontext

    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    9b25bee View commit details
    Browse the repository at this point in the history
  62. Configuration menu
    Copy the full SHA
    b180313 View commit details
    Browse the repository at this point in the history
  63. Configuration menu
    Copy the full SHA
    06bf2e0 View commit details
    Browse the repository at this point in the history
  64. Configuration menu
    Copy the full SHA
    9549b4a View commit details
    Browse the repository at this point in the history
  65. Configuration menu
    Copy the full SHA
    7d8b423 View commit details
    Browse the repository at this point in the history
  66. compilation: pass omit_frame_pointer through to builtin.zig

    Renamed dwarf_unwinding -> stack_iterator to better reflect that it's not just DWARF unwinding.
    Added a test for unwinding with a frame pointer.
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    ec96095 View commit details
    Browse the repository at this point in the history
  67. Configuration menu
    Copy the full SHA
    ba813d0 View commit details
    Browse the repository at this point in the history
  68. Configuration menu
    Copy the full SHA
    5e399d9 View commit details
    Browse the repository at this point in the history
  69. dwarf: fixup integer overflow in readEhPointer

    debug: handle the possibility of eh_frame / debug_frame being mapped in memory or loaded from disk
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    618b0eb View commit details
    Browse the repository at this point in the history
  70. Configuration menu
    Copy the full SHA
    2c76020 View commit details
    Browse the repository at this point in the history
  71. Configuration menu
    Copy the full SHA
    bdb0a6f View commit details
    Browse the repository at this point in the history
  72. Configuration menu
    Copy the full SHA
    774dc2f View commit details
    Browse the repository at this point in the history
  73. macho: don't scan all eh_frame entries, instead follow the offset fro…

    …m the __unwind_info directly
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    97bda56 View commit details
    Browse the repository at this point in the history
  74. dwarf: write the CFA as SP before the register update, in case the SP…

    … itself is updated by a column rule
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    1a2bb70 View commit details
    Browse the repository at this point in the history
  75. Configuration menu
    Copy the full SHA
    d99b40d View commit details
    Browse the repository at this point in the history
  76. Configuration menu
    Copy the full SHA
    2bc2b01 View commit details
    Browse the repository at this point in the history
  77. Configuration menu
    Copy the full SHA
    4421b14 View commit details
    Browse the repository at this point in the history
  78. Configuration menu
    Copy the full SHA
    253e697 View commit details
    Browse the repository at this point in the history
  79. Configuration menu
    Copy the full SHA
    6d87bb3 View commit details
    Browse the repository at this point in the history
  80. test: disable omit_frame_pointer unwinding tests on aarch64-macos

    dwarf: handle signal frame CIE flag
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    8e6a62b View commit details
    Browse the repository at this point in the history
  81. dwarf: move macho unwind code from macho -> dwarf

    dwarf: fixup unchecked .eh_frame CIE offset subtraction
    kcbanner committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    b1d86db View commit details
    Browse the repository at this point in the history