Skip to content

Instantly share code, notes, and snippets.

@mikdusan
Created December 22, 2022 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikdusan/089521d342f5a6417f883966fd0f2220 to your computer and use it in GitHub Desktop.
Save mikdusan/089521d342f5a6417f883966fd0f2220 to your computer and use it in GitHub Desktop.
const std = @import("std");
pub fn main() !void {
try one();
}
fn one() !void {
try two();
}
fn two() !void {
try three();
}
fn three() !void {
var a: []const u8 = "hello";
_ = a[0];
unreachable;
// @breakpoint();
//return error.WHUT;
}
@mikdusan
Copy link
Author

[master] alpine▸ ./main
thread 18550 panic: reached unreachable code
/home/mike/project/zig/work/main/main.zig:18:5: 0x20b09b in three (main)
    unreachable;
    ^
/home/mike/project/zig/work/main/main.zig:12:14: 0x20b0a8 in two (main)
    try three();
             ^
/home/mike/project/zig/work/main/main.zig:8:12: 0x20b0b8 in one (main)
    try two();
           ^
/home/mike/project/zig/work/main/main.zig:4:12: 0x20b0c8 in main (main)
    try one();
           ^
/home/mike/project/zig/work/main/zig-linux-x86_64-0.11.0-dev.926+266e2e9a3/lib/std/start.zig:614:37: 0x20ab2f in posixCallMainAndExit (main)
            const result = root.main() catch |err| {
                                    ^
/home/mike/project/zig/work/main/zig-linux-x86_64-0.11.0-dev.926+266e2e9a3/lib/std/start.zig:376:5: 0x20a5c1 in _start (main)
    @call(.never_inline, posixCallMainAndExit, .{});
    ^
zsh: abort      ./main

@mikdusan
Copy link
Author

Thread 1 "main" received signal SIGABRT, Aborted.
0x0000000000238d42 in os.linux.x86_64.syscall4 (number=rt_sigprocmask, arg1=2, arg2=140737488347680, arg3=0, arg4=8) at /home/mike/project/zig/work/main/lib/std/os/linux/x86_64.zig:57
57	    return asm volatile ("syscall"
(gdb) bt
#0  0x0000000000238d42 in os.linux.x86_64.syscall4 (number=rt_sigprocmask, arg1=2, arg2=140737488347680, arg3=0, arg4=8)
    at /home/mike/project/zig/work/main/lib/std/os/linux/x86_64.zig:57
#1  0x00000000002304bd in os.linux.sigprocmask (flags=2, set=0x7fffffffe220, oldset=0x0) at /home/mike/project/zig/work/main/lib/std/os/linux.zig:1135
#2  0x000000000020e6b8 in os.sigprocmask (flags=2, set=0x7fffffffe220, oldset=0x0) at /home/mike/project/zig/work/main/lib/std/os.zig:5405
#3  0x000000000020e624 in os.raise (sig=6 '\006') at /home/mike/project/zig/work/main/lib/std/os.zig:585
#4  0x000000000020ba5f in os.abort () at /home/mike/project/zig/work/main/lib/std/os.zig:516
#5  0x000000000020b03d in debug.panicImpl (trace=0x0, first_trace_addr=..., msg=...) at /home/mike/project/zig/work/main/lib/std/debug.zig:391
#6  0x000000000020a49a in builtin.default_panic (msg=..., error_return_trace=0x0, ret_addr=...) at /home/mike/project/zig/work/main/lib/std/builtin.zig:909
#7  0x000000000020b09c in main.three () at main.zig:18
#8  0x000000000020b0a9 in main.two () at main.zig:12
#9  0x000000000020b0b9 in main.one () at main.zig:8
#10 0x000000000020b0c9 in main.main () at main.zig:4
(gdb) quit
A debugging session is active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment