diff options
| author | kcbanner <kcbanner@gmail.com> | 2023-07-13 01:14:31 -0400 |
|---|---|---|
| committer | kcbanner <kcbanner@gmail.com> | 2023-07-20 22:58:16 -0400 |
| commit | ec96095efd8671ae280df15eaf73f63bf029fbfa (patch) | |
| tree | 06308ef842ad3f6984f673d607fabebcbed28a7b /test/standalone/stack_iterator/shared_lib_unwind.zig | |
| parent | 7d8b4234774200ff071103399613ed444280a8d0 (diff) | |
| download | zig-ec96095efd8671ae280df15eaf73f63bf029fbfa.tar.gz zig-ec96095efd8671ae280df15eaf73f63bf029fbfa.zip | |
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.
Diffstat (limited to 'test/standalone/stack_iterator/shared_lib_unwind.zig')
| -rw-r--r-- | test/standalone/stack_iterator/shared_lib_unwind.zig | 43 |
1 files changed, 43 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..22f0081744 --- /dev/null +++ b/test/standalone/stack_iterator/shared_lib_unwind.zig @@ -0,0 +1,43 @@ +const std = @import("std"); +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 { + 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); +} |
