diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-07-21 17:37:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-21 17:37:22 +0200 |
| commit | 61d5b7c957e63239f1ebbdbfb94105d53f2dbaa4 (patch) | |
| tree | a49da9a773faff32301383f9bffaed99852c26f6 /test/standalone/stack_iterator/shared_lib_unwind.zig | |
| parent | c43ee5bb22298eefc3fae919807f5da8f7be70f1 (diff) | |
| parent | b1d86db7b45c57b2a9d48655738bce8d77327438 (diff) | |
| download | zig-61d5b7c957e63239f1ebbdbfb94105d53f2dbaa4.tar.gz zig-61d5b7c957e63239f1ebbdbfb94105d53f2dbaa4.zip | |
Merge pull request #15823 from kcbanner/dwarf_unwind
Add DWARF unwinding, and an external debug info loader for ELF
Diffstat (limited to 'test/standalone/stack_iterator/shared_lib_unwind.zig')
| -rw-r--r-- | test/standalone/stack_iterator/shared_lib_unwind.zig | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/standalone/stack_iterator/shared_lib_unwind.zig b/test/standalone/stack_iterator/shared_lib_unwind.zig new file mode 100644 index 0000000000..50e0421e2a --- /dev/null +++ b/test/standalone/stack_iterator/shared_lib_unwind.zig @@ -0,0 +1,47 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const debug = std.debug; +const testing = std.testing; + +noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void { + expected[0] = @returnAddress(); + + var context: debug.ThreadContext = undefined; + testing.expect(debug.getContext(&context)) catch @panic("failed to getContext"); + + var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo"); + var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext"); + defer it.deinit(); + + for (unwound) |*addr| { + if (it.next()) |return_address| addr.* = return_address; + } +} + +noinline fn frame3(expected: *[5]usize, unwound: *[5]usize) void { + expected[1] = @returnAddress(); + frame4(expected, unwound); +} + +fn frame2(expected: *[5]usize, unwound: *[5]usize) callconv(.C) void { + expected[2] = @returnAddress(); + frame3(expected, unwound); +} + +extern fn frame0( + expected: *[5]usize, + unwound: *[5]usize, + frame_2: *const fn (expected: *[5]usize, unwound: *[5]usize) callconv(.C) void, +) void; + +pub fn main() !void { + // Disabled until the DWARF unwinder bugs on .aarch64 are solved + if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return; + + if (!std.debug.have_ucontext or !std.debug.have_getcontext) return; + + var expected: [5]usize = undefined; + var unwound: [5]usize = undefined; + frame0(&expected, &unwound, &frame2); + try testing.expectEqual(expected, unwound); +} |
