Skip to content

Zig crash from stack overflow gives no details #16902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VisenDev opened this issue Aug 20, 2023 · 1 comment
Closed

Zig crash from stack overflow gives no details #16902

VisenDev opened this issue Aug 20, 2023 · 1 comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.

Comments

@VisenDev
Copy link

Zig Version

0.11.0

Steps to Reproduce and Observed Output

My system details

                    'c.          [email protected]
                 ,xNMM.          ----------------------------------
               .OMMMMo           OS: macOS 13.2 22D49 x86_64
               OMMM0,            Host: MacBookPro15,1
     .;loddo:' loolloddol;.      Kernel: 22.3.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 20 days, 2 hours, 53 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 286 (brew)
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: fish 3.6.1
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 1680x1050
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Quartz Compositor
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    WM Theme: Blue (Dark)
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal: /dev/ttys000
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   CPU: Intel i7-9750H (12) @ 2.60GHz
    kMMMMMMMMMMMMMMMMMMMMMMd     GPU: Intel UHD Graphics 630, Radeon Pro 555X
     ;KMMMMMMMWXXWMMMMMMMk.      Memory: 10043MiB / 16384MiB
       .cooc,.    .,coo:.

Here is example code that will cause this crash

//main.zig
test "stack" {
    var foo: [1000][1000][1000]u32 = undefined;
    _ = foo;
}

Run it with zig test main.zig. The exact size of the foo array required to cause the crash may change based off of what system you are using.

Output:

Robert@Roberts-MacBook-Pro-2 ~/z/d/src (master)> zig test reproduce.zig
Test [1/1] test.stack... error: the following test command crashed:
/Users/Robert/zig/dev/zig-cache/o/149dee587edb8951878581bc06128f82/test

Additionally, using a debugger provides very little useful information on what caused the crash

Robert@Roberts-MacBook-Pro-2 ~/z/d/src (master)> lldb /Users/Robert/zig/dev/zig-cache/o/149dee587edb8951878581bc06128f82/test
(lldb) target create "/Users/Robert/zig/dev/zig-cache/o/149dee587edb8951878581bc06128f82/test"
Current executable set to '/Users/Robert/zig/dev/zig-cache/o/149dee587edb8951878581bc06128f82/test' (x86_64).
(lldb) run
Process 6881 launched: '/Users/Robert/zig/dev/zig-cache/o/149dee587edb8951878581bc06128f82/test' (x86_64)
Process 6881 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7ff7bf6ffec0)
    frame #0: 0x00000001000b3364 test`__zig_probe_stack at stack_probe.zig:53:13 [opt]
   50  	    switch (arch) {
   51  	        .x86_64 => {
   52  	            // %rax = probe length, %rsp = stack pointer
-> 53  	            asm volatile (
   54  	                \\        push   %%rcx
   55  	                \\        mov    %%rax, %%rcx
   56  	                \\        cmp    $0x1000,%%rcx
warning: test was compiled with optimization - stepping may behave oddly; variables may not be available.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7ff7bf6ffec0)
  * frame #0: 0x00000001000b3364 test`__zig_probe_stack at stack_probe.zig:53:13 [opt]
    frame #1: 0x0000000100007ce4 test`test_runner.mainTerminal at test_runner.zig:176:28
    frame #2: 0x0000000100000e29 test`test_runner.main at test_runner.zig:36:28
    frame #3: 0x00000001000009af test`main [inlined] start.callMain at start.zig:564:22
    frame #4: 0x00000001000009aa test`main [inlined] start.initEventLoopAndCallMain at start.zig:508:5
    frame #5: 0x00000001000009aa test`main at start.zig:458:36
    frame #6: 0x000000010000094d test`main(c_argc=1, c_argv=0x00007ff7bfeff908, c_envp=0x00007ff7bfeff918) at start.zig:473:101
    frame #7: 0x00007ff802941310 dyld`start + 2432
(lldb)

Expected Output

Ideally there would be some sort of details as to what caused the crash, and what line of my code caused the crash.

@VisenDev VisenDev added the error message This issue points out an error message that is unhelpful and should be improved. label Aug 20, 2023
@Vexu
Copy link
Member

Vexu commented Aug 21, 2023

Duplicate of #7371

@Vexu Vexu marked this as a duplicate of #7371 Aug 21, 2023
@Vexu Vexu closed this as completed Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

2 participants