mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Move sys_can_stack_trace from GPA to std.debug so that it can be re-used as needed
This commit is contained in:
parent
19d7f4dd82
commit
22720981ea
3 changed files with 25 additions and 22 deletions
|
|
@ -26,6 +26,27 @@ pub const runtime_safety = switch (builtin.mode) {
|
||||||
.ReleaseFast, .ReleaseSmall => false,
|
.ReleaseFast, .ReleaseSmall => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const sys_can_stack_trace = switch (builtin.cpu.arch) {
|
||||||
|
// Observed to go into an infinite loop.
|
||||||
|
// TODO: Make this work.
|
||||||
|
.mips,
|
||||||
|
.mipsel,
|
||||||
|
=> false,
|
||||||
|
|
||||||
|
// `@returnAddress()` in LLVM 10 gives
|
||||||
|
// "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address".
|
||||||
|
.wasm32,
|
||||||
|
.wasm64,
|
||||||
|
=> builtin.os.tag == .emscripten,
|
||||||
|
|
||||||
|
// `@returnAddress()` is unsupported in LLVM 13.
|
||||||
|
.bpfel,
|
||||||
|
.bpfeb,
|
||||||
|
=> false,
|
||||||
|
|
||||||
|
else => true,
|
||||||
|
};
|
||||||
|
|
||||||
pub const LineInfo = struct {
|
pub const LineInfo = struct {
|
||||||
line: u64,
|
line: u64,
|
||||||
column: u64,
|
column: u64,
|
||||||
|
|
|
||||||
|
|
@ -105,28 +105,8 @@ const StackTrace = std.builtin.StackTrace;
|
||||||
/// Integer type for pointing to slots in a small allocation
|
/// Integer type for pointing to slots in a small allocation
|
||||||
const SlotIndex = std.meta.Int(.unsigned, math.log2(page_size) + 1);
|
const SlotIndex = std.meta.Int(.unsigned, math.log2(page_size) + 1);
|
||||||
|
|
||||||
const sys_can_stack_trace = switch (builtin.cpu.arch) {
|
|
||||||
// Observed to go into an infinite loop.
|
|
||||||
// TODO: Make this work.
|
|
||||||
.mips,
|
|
||||||
.mipsel,
|
|
||||||
=> false,
|
|
||||||
|
|
||||||
// `@returnAddress()` in LLVM 10 gives
|
|
||||||
// "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address".
|
|
||||||
.wasm32,
|
|
||||||
.wasm64,
|
|
||||||
=> builtin.os.tag == .emscripten,
|
|
||||||
|
|
||||||
// `@returnAddress()` is unsupported in LLVM 13.
|
|
||||||
.bpfel,
|
|
||||||
.bpfeb,
|
|
||||||
=> false,
|
|
||||||
|
|
||||||
else => true,
|
|
||||||
};
|
|
||||||
const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4;
|
const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4;
|
||||||
const default_sys_stack_trace_frames: usize = if (sys_can_stack_trace) default_test_stack_trace_frames else 0;
|
const default_sys_stack_trace_frames: usize = if (std.debug.sys_can_stack_trace) default_test_stack_trace_frames else 0;
|
||||||
const default_stack_trace_frames: usize = switch (builtin.mode) {
|
const default_stack_trace_frames: usize = switch (builtin.mode) {
|
||||||
.Debug => default_sys_stack_trace_frames,
|
.Debug => default_sys_stack_trace_frames,
|
||||||
else => 0,
|
else => 0,
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,11 @@ pub const FailingAllocator = struct {
|
||||||
freed_bytes: usize,
|
freed_bytes: usize,
|
||||||
allocations: usize,
|
allocations: usize,
|
||||||
deallocations: usize,
|
deallocations: usize,
|
||||||
stack_addresses: [16]usize,
|
stack_addresses: [num_stack_frames]usize,
|
||||||
has_induced_failure: bool,
|
has_induced_failure: bool,
|
||||||
|
|
||||||
|
const num_stack_frames = if (std.debug.sys_can_stack_trace) 16 else 0;
|
||||||
|
|
||||||
/// `fail_index` is the number of successful allocations you can
|
/// `fail_index` is the number of successful allocations you can
|
||||||
/// expect from this allocator. The next allocation will fail.
|
/// expect from this allocator. The next allocation will fail.
|
||||||
/// For example, if this is called with `fail_index` equal to 2,
|
/// For example, if this is called with `fail_index` equal to 2,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue