From 7774287fdca1b56e12a420c446e83191c05fb468 Mon Sep 17 00:00:00 2001 From: mlugg Date: Thu, 23 Jan 2025 04:48:01 +0000 Subject: tests: enable stack trace tests for x86_64-selfhosted Allows the stack trace tests to be additionally compiled and run with `.use_llvm = false, .use_lld = false` depending on the host target. This is currently enabled for x86_64 targets emitting ELF. Self-hosted backends emit slightly different DWARF info to the LLVM backend, so the checking logic (and the tests themselves) had to be tweaked slightly to support both backends at once. --- test/src/check-stack-trace.zig | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'test/src/check-stack-trace.zig') diff --git a/test/src/check-stack-trace.zig b/test/src/check-stack-trace.zig index 9856b5738e..fccbbe3609 100644 --- a/test/src/check-stack-trace.zig +++ b/test/src/check-stack-trace.zig @@ -58,14 +58,23 @@ pub fn main() !void { try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]); try buf.appendSlice(" [address]"); if (optimize_mode == .Debug) { - // On certain platforms (windows) or possibly depending on how we choose to link main - // the object file extension may be present so we simply strip any extension. - if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| { - try buf.appendSlice(line[marks[3] .. marks[4] + idot]); - try buf.appendSlice(line[marks[5]..]); + try buf.appendSlice(line[marks[3] .. marks[4] + delims[4].len]); + + const file_name = line[marks[4] + delims[4].len .. marks[5]]; + // The LLVM backend currently uses the object file name in the debug info here. + // This actually violates the DWARF specification (DWARF5 ยง 3.1.1, lines 24-27). + // The self-hosted backend uses the root Zig source file of the module (in compilance with the spec). + if (std.mem.eql(u8, file_name, "test") or + std.mem.eql(u8, file_name, "test.exe.obj") or + std.mem.endsWith(u8, file_name, ".zig")) + { + try buf.appendSlice("[main_file]"); } else { - try buf.appendSlice(line[marks[3]..]); + // Something unexpected; include it verbatim. + try buf.appendSlice(file_name); } + + try buf.appendSlice(line[marks[5]..]); } else { try buf.appendSlice(line[marks[3] .. marks[3] + delims[3].len]); try buf.appendSlice("[function]"); -- cgit v1.2.3