diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-08-10 19:34:27 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-08-11 02:01:32 -0400 |
| commit | 20510d209be44590f390c370f9e477d84ab46454 (patch) | |
| tree | d8d9cae0a71467a27d54292b1cfbb4aabfd094b4 /lib/std/builtin.zig | |
| parent | 900a897e90eca08f78ef632fd11e01ec9bcb3674 (diff) | |
| download | zig-20510d209be44590f390c370f9e477d84ab46454.tar.gz zig-20510d209be44590f390c370f9e477d84ab46454.zip | |
GeneralPurposeAllocator: use std.log instead of std.debug.print
`std.builtin.StackTrace` gains a `format` function.
GeneralPurposeAllocator uses `std.log.err` instead of directly printing
to stderr. Some errors are recoverable.
The test runner is modified to fail the test run if any log messages of
"err" or worse severity are encountered.
self-hosted is modified to always print log messages of "err" severity
or worse even if they have not been explicitly enabled.
This makes GeneralPurposeAllocator available on the freestanding target.
Diffstat (limited to 'lib/std/builtin.zig')
| -rw-r--r-- | lib/std/builtin.zig | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 499011eab9..e9c53d7ee5 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -52,6 +52,25 @@ pub const subsystem: ?SubSystem = blk: { pub const StackTrace = struct { index: usize, instruction_addresses: []usize, + + pub fn format( + self: StackTrace, + comptime fmt: []const u8, + options: std.fmt.FormatOptions, + writer: anytype, + ) !void { + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + defer arena.deinit(); + const debug_info = std.debug.getSelfDebugInfo() catch |err| { + return writer.print("\nUnable to print stack trace: Unable to open debug info: {}\n", .{@errorName(err)}); + }; + const tty_config = std.debug.detectTTYConfig(); + try writer.writeAll("\n"); + std.debug.writeStackTrace(self, writer, &arena.allocator, debug_info, tty_config) catch |err| { + try writer.print("Unable to print stack trace: {}\n", .{@errorName(err)}); + }; + try writer.writeAll("\n"); + } }; /// This data structure is used by the Zig language code generation and |
