authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-12 18:41:53-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:16-04:00
log06bf2e048b24dcba28bcb7b00236b3cdb2504cc4
tree7b382725df7e3ef4da5703977182cdf7249d273e
parentb18031335a13d8f356c1764ebae83b5f93be8fa3

tests: use a more portable way of determining the return address in the test code


2 files changed, 11 insertions(+), 12 deletions(-)

test/standalone/dwarf_unwinding/shared_lib.c+2-4
......@@ -8,17 +8,15 @@ __attribute__((noinline)) void frame1(
88 void** expected,
99 void** unwound,
1010 void (*frame2)(void** expected, void** unwound)) {
11 expected[2] = &&frame_2_ret;
11 expected[3] = __builtin_extract_return_addr(__builtin_return_address(0));
1212 frame2(expected, unwound);
13 frame_2_ret:
1413}
1514
1615LIB_API void frame0(
1716 void** expected,
1817 void** unwound,
1918 void (*frame2)(void** expected, void** unwound)) {
20 expected[3] = &&frame_1_ret;
19 expected[4] = __builtin_extract_return_addr(__builtin_return_address(0));
2120 frame1(expected, unwound, frame2);
22 frame_1_ret:
2321}
2422
test/standalone/dwarf_unwinding/shared_lib_unwind.zig+9-8
......@@ -2,7 +2,7 @@ const std = @import("std");
22const debug = std.debug;
33const testing = std.testing;
44
5noinline fn frame4(expected: *[4]usize, unwound: *[4]usize) void {
5noinline fn frame4(expected: *[5]usize, unwound: *[5]usize) void {
66 expected[0] = @returnAddress();
77
88 var context: debug.ThreadContext = undefined;
......@@ -17,26 +17,27 @@ noinline fn frame4(expected: *[4]usize, unwound: *[4]usize) void {
1717 }
1818}
1919
20noinline fn frame3(expected: *[4]usize, unwound: *[4]usize) void {
20noinline fn frame3(expected: *[5]usize, unwound: *[5]usize) void {
2121 expected[1] = @returnAddress();
2222 frame4(expected, unwound);
2323}
2424
25fn frame2(expected: *[4]usize, unwound: *[4]usize) callconv(.C) void {
25fn frame2(expected: *[5]usize, unwound: *[5]usize) callconv(.C) void {
26 expected[2] = @returnAddress();
2627 frame3(expected, unwound);
2728}
2829
2930extern fn frame0(
30 expected: *[4]usize,
31 unwound: *[4]usize,
32 frame_2: *const fn (expected: *[4]usize, unwound: *[4]usize) callconv(.C) void,
31 expected: *[5]usize,
32 unwound: *[5]usize,
33 frame_2: *const fn (expected: *[5]usize, unwound: *[5]usize) callconv(.C) void,
3334) void;
3435
3536pub fn main() !void {
3637 if (!std.debug.have_ucontext or !std.debug.have_getcontext) return;
3738
38 var expected: [4]usize = undefined;
39 var unwound: [4]usize = undefined;
39 var expected: [5]usize = undefined;
40 var unwound: [5]usize = undefined;
4041 frame0(&expected, &unwound, &frame2);
4142 try testing.expectEqual(expected, unwound);
4243}