2023-07-01 06:40:34 +01:00
|
|
|
const std = @import("std");
|
2023-07-19 07:06:17 +01:00
|
|
|
const builtin = @import("builtin");
|
2023-07-01 06:40:34 +01:00
|
|
|
const debug = std.debug;
|
|
|
|
const testing = std.testing;
|
|
|
|
|
2023-07-12 23:41:53 +01:00
|
|
|
noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void {
|
2023-07-01 06:40:34 +01:00
|
|
|
expected[0] = @returnAddress();
|
|
|
|
|
2023-07-07 03:02:47 +01:00
|
|
|
var context: debug.ThreadContext = undefined;
|
2023-07-01 06:40:34 +01:00
|
|
|
testing.expect(debug.getContext(&context)) catch @panic("failed to getContext");
|
|
|
|
|
|
|
|
var debug_info = debug.getSelfDebugInfo() catch @panic("failed to openSelfDebugInfo");
|
2023-07-01 20:23:37 +01:00
|
|
|
var it = debug.StackIterator.initWithContext(expected[0], debug_info, &context) catch @panic("failed to initWithContext");
|
2023-07-01 06:40:34 +01:00
|
|
|
defer it.deinit();
|
|
|
|
|
|
|
|
for (unwound) |*addr| {
|
|
|
|
if (it.next()) |return_address| addr.* = return_address;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 23:41:53 +01:00
|
|
|
noinline fn frame3(expected: *[5]usize, unwound: *[5]usize) void {
|
2023-07-01 06:40:34 +01:00
|
|
|
expected[1] = @returnAddress();
|
|
|
|
frame4(expected, unwound);
|
|
|
|
}
|
|
|
|
|
2023-07-12 23:41:53 +01:00
|
|
|
fn frame2(expected: *[5]usize, unwound: *[5]usize) callconv(.C) void {
|
|
|
|
expected[2] = @returnAddress();
|
2023-07-01 06:40:34 +01:00
|
|
|
frame3(expected, unwound);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern fn frame0(
|
2023-07-12 23:41:53 +01:00
|
|
|
expected: *[5]usize,
|
|
|
|
unwound: *[5]usize,
|
|
|
|
frame_2: *const fn (expected: *[5]usize, unwound: *[5]usize) callconv(.C) void,
|
2023-07-01 06:40:34 +01:00
|
|
|
) void;
|
|
|
|
|
|
|
|
pub fn main() !void {
|
2023-07-19 07:06:17 +01:00
|
|
|
// 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;
|
|
|
|
|
2023-07-01 20:23:37 +01:00
|
|
|
if (!std.debug.have_ucontext or !std.debug.have_getcontext) return;
|
|
|
|
|
2023-07-12 23:41:53 +01:00
|
|
|
var expected: [5]usize = undefined;
|
|
|
|
var unwound: [5]usize = undefined;
|
2023-07-01 06:40:34 +01:00
|
|
|
frame0(&expected, &unwound, &frame2);
|
|
|
|
try testing.expectEqual(expected, unwound);
|
|
|
|
}
|