| ... | @@ -567,13 +567,11 @@ pub const StackUnwindOptions = struct { | ... | @@ -567,13 +567,11 @@ pub const StackUnwindOptions = struct { |
| 567 | /// | 567 | /// |
| 568 | /// See `writeCurrentStackTrace` to immediately print the trace instead of capturing it. | 568 | /// See `writeCurrentStackTrace` to immediately print the trace instead of capturing it. |
| 569 | pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) std.builtin.StackTrace { | 569 | pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) std.builtin.StackTrace { |
| 570 | var it = StackIterator.init(options.context) catch { | 570 | const empty_trace: std.builtin.StackTrace = .{ .index = 0, .instruction_addresses = &.{} }; |
| 571 | return .{ .index = 0, .instruction_addresses = &.{} }; | 571 | if (!std.options.allow_stack_tracing) return empty_trace; |
| 572 | }; | 572 | var it = StackIterator.init(options.context) catch return empty_trace; |
| 573 | defer it.deinit(); | 573 | defer it.deinit(); |
| 574 | if (!it.stratOk(options.allow_unsafe_unwind)) { | 574 | if (!it.stratOk(options.allow_unsafe_unwind)) return empty_trace; |
| 575 | return .{ .index = 0, .instruction_addresses = &.{} }; | | |
| 576 | } | | |
| 577 | var frame_idx: usize = 0; | 575 | var frame_idx: usize = 0; |
| 578 | var wait_for = options.first_address; | 576 | var wait_for = options.first_address; |
| 579 | while (true) switch (it.next()) { | 577 | while (true) switch (it.next()) { |
| ... | @@ -599,6 +597,12 @@ pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) | ... | @@ -599,6 +597,12 @@ pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) |
| 599 | /// | 597 | /// |
| 600 | /// See `captureCurrentStackTrace` to capture the trace addresses into a buffer instead of printing. | 598 | /// See `captureCurrentStackTrace` to capture the trace addresses into a buffer instead of printing. |
| 601 | pub fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Writer, tty_config: tty.Config) Writer.Error!void { | 599 | pub fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Writer, tty_config: tty.Config) Writer.Error!void { |
| | 600 | if (!std.options.allow_stack_tracing) { |
| | 601 | tty_config.setColor(writer, .dim) catch {}; |
| | 602 | try writer.print("Cannot print stack trace: stack tracing is disabled\n", .{}); |
| | 603 | tty_config.setColor(writer, .reset) catch {}; |
| | 604 | return; |
| | 605 | } |
| 602 | const di_gpa = getDebugInfoAllocator(); | 606 | const di_gpa = getDebugInfoAllocator(); |
| 603 | const di = getSelfDebugInfo() catch |err| switch (err) { | 607 | const di = getSelfDebugInfo() catch |err| switch (err) { |
| 604 | error.UnsupportedTarget => { | 608 | error.UnsupportedTarget => { |
| ... | @@ -688,6 +692,12 @@ pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void { | ... | @@ -688,6 +692,12 @@ pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void { |
| 688 | | 692 | |
| 689 | /// Write a previously captured stack trace to `writer`, annotated with source locations. | 693 | /// Write a previously captured stack trace to `writer`, annotated with source locations. |
| 690 | pub fn writeStackTrace(st: *const std.builtin.StackTrace, writer: *Writer, tty_config: tty.Config) Writer.Error!void { | 694 | pub fn writeStackTrace(st: *const std.builtin.StackTrace, writer: *Writer, tty_config: tty.Config) Writer.Error!void { |
| | 695 | if (!std.options.allow_stack_tracing) { |
| | 696 | tty_config.setColor(writer, .dim) catch {}; |
| | 697 | try writer.print("Cannot print stack trace: stack tracing is disabled\n", .{}); |
| | 698 | tty_config.setColor(writer, .reset) catch {}; |
| | 699 | return; |
| | 700 | } |
| 691 | // Fetch `st.index` straight away. Aside from avoiding redundant loads, this prevents issues if | 701 | // Fetch `st.index` straight away. Aside from avoiding redundant loads, this prevents issues if |
| 692 | // `st` is `@errorReturnTrace()` and errors are encountered while writing the stack trace. | 702 | // `st` is `@errorReturnTrace()` and errors are encountered while writing the stack trace. |
| 693 | const n_frames = st.index; | 703 | const n_frames = st.index; |