authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-11 08:49:20+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 15:03:16-07:00
log3e2ddbfdd7e43788de51b3166e3dbc523c6b7b88
treec07f67a76f22a08bb453d4ae7e7bb45cf07e1bf7
parent6f39ce93ce358743df0abe1acdac75f3fd6a2eab

Remove incorrect assertion in readMachODebugInfo panicking during panic

This fixes a class of bugs on macOS where a segfault happening in a loaded dylib with no debug info would cause a panic in the panic handler instead of simply noting that the dylib has no valid debug info via `error.MissingDebugInfo`. An example could be code linking some system dylib and causing some routine to segfault on say invalid pointer value, which should normally cause Zig to print an incomplete stack trace anchored at the currently loaded image and backtrace all the way back to the Zig binary with valid debug info. Currently, in a situation like this we would trigger a panic within a panic.

1 files changed, 6 insertions(+), 1 deletions(-)

lib/std/debug.zig+6-1
...@@ -1110,7 +1110,12 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn...@@ -1110,7 +1110,12 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
1110 else => {},1110 else => {},
1111 }1111 }
1112 }1112 }
1113 assert(state == .oso_close);1113
1114 switch (state) {
1115 .init => return error.MissingDebugInfo,
1116 .oso_close => {},
1117 else => return error.InvalidDebugInfo,
1118 }
11141119
1115 const symbols = allocator.shrink(symbols_buf, symbol_index);1120 const symbols = allocator.shrink(symbols_buf, symbol_index);
11161121