authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-15 16:26:13-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-15 16:26:13-05:00
log6ec9933fd80013104982debab9fbff1463582f19
tree2fb5a768a59e95a94cbeb9ac853643f8777936e5
parentc9ac607bd3bf2cc1cfb941e54e6bcd53f2fcc59d

fix getting debug info twice in default panic handler


2 files changed, 29 insertions(+), 8 deletions(-)

std/debug/index.zig+27-2
......@@ -41,10 +41,21 @@ fn getStderrStream() -> %&io.OutStream {
4141 }
4242}
4343
44var self_debug_info: ?&ElfStackTrace = null;
45pub fn getSelfDebugInfo() -> %&ElfStackTrace {
46 if (self_debug_info) |info| {
47 return info;
48 } else {
49 const info = try openSelfDebugInfo(global_allocator);
50 self_debug_info = info;
51 return info;
52 }
53}
54
4455/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
4556pub fn dumpCurrentStackTrace() {
4657 const stderr = getStderrStream() catch return;
47 const debug_info = openSelfDebugInfo(global_allocator) catch |err| {
58 const debug_info = getSelfDebugInfo() catch |err| {
4859 stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return;
4960 return;
5061 };
......@@ -58,7 +69,7 @@ pub fn dumpCurrentStackTrace() {
5869/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
5970pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) {
6071 const stderr = getStderrStream() catch return;
61 const debug_info = openSelfDebugInfo(global_allocator) catch |err| {
72 const debug_info = getSelfDebugInfo() catch |err| {
6273 stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return;
6374 return;
6475 };
......@@ -119,6 +130,20 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn {
119130 os.abort();
120131}
121132
133pub fn panicWithTrace(trace: &const builtin.StackTrace, comptime format: []const u8, args: ...) -> noreturn {
134 if (panicking) {
135 os.abort();
136 } else {
137 panicking = true;
138 }
139 const stderr = getStderrStream() catch os.abort();
140 stderr.print(format ++ "\n", args) catch os.abort();
141 dumpStackTrace(trace);
142 dumpCurrentStackTrace();
143
144 os.abort();
145}
146
122147const GREEN = "\x1b[32;1m";
123148const WHITE = "\x1b[37;1m";
124149const DIM = "\x1b[2m";
std/special/panic.zig+2-6
......@@ -13,12 +13,8 @@ pub coldcc fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -
1313 while (true) {}
1414 },
1515 else => {
16 if (builtin.have_error_return_tracing) {
17 if (error_return_trace) |trace| {
18 std.debug.warn("{}\n", msg);
19 std.debug.dumpStackTrace(trace);
20 @import("std").debug.panic("");
21 }
16 if (error_return_trace) |trace| {
17 @import("std").debug.panicWithTrace(trace, "{}", msg);
2218 }
2319 @import("std").debug.panic("{}", msg);
2420 },