authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-26 22:10:22-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-26 22:10:22-04:00
log78449b6d980fc78d418f9b44d815781eda7587f7
treebe214125adb2cde692215ccf357c46cf6a5995b8
parent661028a907a66ad94b6c052286a59da3bcd6f287

debug: skip unwind error printing on platforms that don't have_ucontext


1 files changed, 12 insertions(+), 13 deletions(-)

lib/std/debug.zig+12-13
......@@ -242,8 +242,7 @@ pub fn dumpStackTraceFromBase(context: *const ThreadContext) void {
242242 printSourceAtAddress(debug_info, stderr, it.unwind_state.?.dwarf_context.pc, tty_config) catch return;
243243
244244 while (it.next()) |return_address| {
245 if (it.getLastError()) |unwind_error|
246 printUnwindError(debug_info, stderr, unwind_error.address, unwind_error.err, tty_config) catch {};
245 printLastUnwindError(&it, debug_info, stderr, tty_config);
247246
248247 // On arm64 macOS, the address of the last frame is 0x0 rather than 0x1 as on x86_64 macOS,
249248 // therefore, we do a check for `return_address == 0` before subtracting 1 from it to avoid
......@@ -252,10 +251,7 @@ pub fn dumpStackTraceFromBase(context: *const ThreadContext) void {
252251 // same behaviour for x86-windows-msvc
253252 const address = if (return_address == 0) return_address else return_address - 1;
254253 printSourceAtAddress(debug_info, stderr, address, tty_config) catch return;
255 } else {
256 if (it.getLastError()) |unwind_error|
257 printUnwindError(debug_info, stderr, unwind_error.address, unwind_error.err, tty_config) catch {};
258 }
254 } else printLastUnwindError(&it, debug_info, stderr, tty_config);
259255 }
260256}
261257
......@@ -734,8 +730,7 @@ pub fn writeCurrentStackTrace(
734730 defer it.deinit();
735731
736732 while (it.next()) |return_address| {
737 if (it.getLastError()) |unwind_error|
738 try printUnwindError(debug_info, out_stream, unwind_error.address, unwind_error.err, tty_config);
733 printLastUnwindError(&it, debug_info, out_stream, tty_config);
739734
740735 // On arm64 macOS, the address of the last frame is 0x0 rather than 0x1 as on x86_64 macOS,
741736 // therefore, we do a check for `return_address == 0` before subtracting 1 from it to avoid
......@@ -744,10 +739,7 @@ pub fn writeCurrentStackTrace(
744739 // same behaviour for x86-windows-msvc
745740 const address = if (return_address == 0) return_address else return_address - 1;
746741 try printSourceAtAddress(debug_info, out_stream, address, tty_config);
747 } else {
748 if (it.getLastError()) |unwind_error|
749 try printUnwindError(debug_info, out_stream, unwind_error.address, unwind_error.err, tty_config);
750 }
742 } else printLastUnwindError(&it, debug_info, out_stream, tty_config);
751743}
752744
753745pub noinline fn walkStackWindows(addresses: []usize, existing_context: ?*const windows.CONTEXT) usize {
......@@ -885,7 +877,14 @@ fn printUnknownSource(debug_info: *DebugInfo, out_stream: anytype, address: usiz
885877 );
886878}
887879
888pub fn printUnwindError(debug_info: *DebugInfo, out_stream: anytype, address: usize, err: UnwindError, tty_config: io.tty.Config) !void {
880fn printLastUnwindError(it: *StackIterator, debug_info: *DebugInfo, out_stream: anytype, tty_config: io.tty.Config) void {
881 if (!have_ucontext) return;
882 if (it.getLastError()) |unwind_error| {
883 printUnwindError(debug_info, out_stream, unwind_error.address, unwind_error.err, tty_config) catch {};
884 }
885}
886
887fn printUnwindError(debug_info: *DebugInfo, out_stream: anytype, address: usize, err: UnwindError, tty_config: io.tty.Config) !void {
889888 const module_name = debug_info.getModuleNameForAddress(address) orelse "???";
890889 try tty_config.setColor(out_stream, .dim);
891890 if (err == error.MissingDebugInfo) {