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 {...@@ -242,8 +242,7 @@ pub fn dumpStackTraceFromBase(context: *const ThreadContext) void {
242 printSourceAtAddress(debug_info, stderr, it.unwind_state.?.dwarf_context.pc, tty_config) catch return;242 printSourceAtAddress(debug_info, stderr, it.unwind_state.?.dwarf_context.pc, tty_config) catch return;
243243
244 while (it.next()) |return_address| {244 while (it.next()) |return_address| {
245 if (it.getLastError()) |unwind_error|245 printLastUnwindError(&it, debug_info, stderr, tty_config);
246 printUnwindError(debug_info, stderr, unwind_error.address, unwind_error.err, tty_config) catch {};
247246
248 // On arm64 macOS, the address of the last frame is 0x0 rather than 0x1 as on x86_64 macOS,247 // On arm64 macOS, the address of the last frame is 0x0 rather than 0x1 as on x86_64 macOS,
249 // therefore, we do a check for `return_address == 0` before subtracting 1 from it to avoid248 // 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 {...@@ -252,10 +251,7 @@ pub fn dumpStackTraceFromBase(context: *const ThreadContext) void {
252 // same behaviour for x86-windows-msvc251 // same behaviour for x86-windows-msvc
253 const address = if (return_address == 0) return_address else return_address - 1;252 const address = if (return_address == 0) return_address else return_address - 1;
254 printSourceAtAddress(debug_info, stderr, address, tty_config) catch return;253 printSourceAtAddress(debug_info, stderr, address, tty_config) catch return;
255 } else {254 } else printLastUnwindError(&it, debug_info, stderr, tty_config);
256 if (it.getLastError()) |unwind_error|
257 printUnwindError(debug_info, stderr, unwind_error.address, unwind_error.err, tty_config) catch {};
258 }
259 }255 }
260}256}
261257
...@@ -734,8 +730,7 @@ pub fn writeCurrentStackTrace(...@@ -734,8 +730,7 @@ pub fn writeCurrentStackTrace(
734 defer it.deinit();730 defer it.deinit();
735731
736 while (it.next()) |return_address| {732 while (it.next()) |return_address| {
737 if (it.getLastError()) |unwind_error|733 printLastUnwindError(&it, debug_info, out_stream, tty_config);
738 try printUnwindError(debug_info, out_stream, unwind_error.address, unwind_error.err, tty_config);
739734
740 // On arm64 macOS, the address of the last frame is 0x0 rather than 0x1 as on x86_64 macOS,735 // On arm64 macOS, the address of the last frame is 0x0 rather than 0x1 as on x86_64 macOS,
741 // therefore, we do a check for `return_address == 0` before subtracting 1 from it to avoid736 // therefore, we do a check for `return_address == 0` before subtracting 1 from it to avoid
...@@ -744,10 +739,7 @@ pub fn writeCurrentStackTrace(...@@ -744,10 +739,7 @@ pub fn writeCurrentStackTrace(
744 // same behaviour for x86-windows-msvc739 // same behaviour for x86-windows-msvc
745 const address = if (return_address == 0) return_address else return_address - 1;740 const address = if (return_address == 0) return_address else return_address - 1;
746 try printSourceAtAddress(debug_info, out_stream, address, tty_config);741 try printSourceAtAddress(debug_info, out_stream, address, tty_config);
747 } else {742 } else printLastUnwindError(&it, debug_info, out_stream, tty_config);
748 if (it.getLastError()) |unwind_error|
749 try printUnwindError(debug_info, out_stream, unwind_error.address, unwind_error.err, tty_config);
750 }
751}743}
752744
753pub noinline fn walkStackWindows(addresses: []usize, existing_context: ?*const windows.CONTEXT) usize {745pub 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...@@ -885,7 +877,14 @@ fn printUnknownSource(debug_info: *DebugInfo, out_stream: anytype, address: usiz
885 );877 );
886}878}
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 {
889 const module_name = debug_info.getModuleNameForAddress(address) orelse "???";888 const module_name = debug_info.getModuleNameForAddress(address) orelse "???";
890 try tty_config.setColor(out_stream, .dim);889 try tty_config.setColor(out_stream, .dim);
891 if (err == error.MissingDebugInfo) {890 if (err == error.MissingDebugInfo) {