diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-01-15 16:26:13 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-01-15 16:26:13 -0500 |
| commit | 6ec9933fd80013104982debab9fbff1463582f19 (patch) | |
| tree | 2fb5a768a59e95a94cbeb9ac853643f8777936e5 /std/debug/index.zig | |
| parent | c9ac607bd3bf2cc1cfb941e54e6bcd53f2fcc59d (diff) | |
| download | zig-6ec9933fd80013104982debab9fbff1463582f19.tar.gz zig-6ec9933fd80013104982debab9fbff1463582f19.zip | |
fix getting debug info twice in default panic handler
Diffstat (limited to 'std/debug/index.zig')
| -rw-r--r-- | std/debug/index.zig | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/std/debug/index.zig b/std/debug/index.zig index 5dc7b0dbfa..87e81ab8c2 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -41,10 +41,21 @@ fn getStderrStream() -> %&io.OutStream { } } +var self_debug_info: ?&ElfStackTrace = null; +pub fn getSelfDebugInfo() -> %&ElfStackTrace { + if (self_debug_info) |info| { + return info; + } else { + const info = try openSelfDebugInfo(global_allocator); + self_debug_info = info; + return info; + } +} + /// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned. pub fn dumpCurrentStackTrace() { const stderr = getStderrStream() catch return; - const debug_info = openSelfDebugInfo(global_allocator) catch |err| { + const debug_info = getSelfDebugInfo() catch |err| { stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return; return; }; @@ -58,7 +69,7 @@ pub fn dumpCurrentStackTrace() { /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. pub fn dumpStackTrace(stack_trace: &const builtin.StackTrace) { const stderr = getStderrStream() catch return; - const debug_info = openSelfDebugInfo(global_allocator) catch |err| { + const debug_info = getSelfDebugInfo() catch |err| { stderr.print("Unable to open debug info: {}\n", @errorName(err)) catch return; return; }; @@ -119,6 +130,20 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn { os.abort(); } +pub fn panicWithTrace(trace: &const builtin.StackTrace, comptime format: []const u8, args: ...) -> noreturn { + if (panicking) { + os.abort(); + } else { + panicking = true; + } + const stderr = getStderrStream() catch os.abort(); + stderr.print(format ++ "\n", args) catch os.abort(); + dumpStackTrace(trace); + dumpCurrentStackTrace(); + + os.abort(); +} + const GREEN = "\x1b[32;1m"; const WHITE = "\x1b[37;1m"; const DIM = "\x1b[2m"; |
