ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.86k stars 2.48k forks source link

Improve error message when stack limit reached, test crashes with `error: the following test command crashed` and backtrace only `__zig_probe_stack` #13671

Open GavinRay97 opened 1 year ago

GavinRay97 commented 1 year ago

Zig Version

0.11.0-dev.230+fca776f8f

Steps to Reproduce and Observed Output

const std = @import("std");

const PAGE_SIZE = 8192;
const NUM_FRAMES = 1024;

const BufferPool = struct {
    frames: [NUM_FRAMES][PAGE_SIZE]u8 align(PAGE_SIZE)
};

pub fn main() !void {}

test "buffer pool" {
    var bp = BufferPool{
        // A 2-D array of PAGE_SIZE bytes x NUM_FRAMES elements.
        .frames = [_][PAGE_SIZE]u8{[_]u8{0} ** PAGE_SIZE} ** NUM_FRAMES,
    };
    std.debug.print("bp.frames: {any}\n", .{bp.frames});
}
[user@MSI zig-example]$ zig test src/main.zig 
Test [1/2] test.BufferPoolManager... error: the following test command crashed:
/home/user/projects/zig-example/zig-cache/o/844821ca13c71e1a820c61439d2ca2ea/tes

image

Expected Output

Something like:


error: SEGFAULT, allocation of "bp" at main.zig:13 of size XXX exceeds stack allocation size limit of YYY bytes.
"bp" must be heap-allocated, consider using an allocator:
   (some sample allocator code like GPA or whatnot)
Vexu commented 1 year ago

Related #7371

IntegratedQuantum commented 1 year ago

Is there any way to debug this?

I just got this error after updating my zig version and now I have no clue where to look for the cause. And gdb doesn't seem to be able to give me the stack trace for this error:

(gdb) bt
#0  0x0000000001391b04 in __zig_probe_stack ()
Backtrace stopped: Cannot access memory at address 0x7ffffeffe7f0
nektro commented 1 year ago

the common case where bt would point to the answer is in the case of runaway recursion. in this case its happening because an array on the stack is too big

VisenDev commented 1 year ago

I am also having an issue with this

mlugg commented 1 year ago

Note that if you hit this, you can work around it (in the sense of getting a useful backtrace) by compiling with -fno-stack-check to disable stack probing.