Skip to content
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

std: add std.options.debug_stacktrace_kind #19650

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nektro
Copy link
Contributor

@nektro nektro commented Apr 14, 2024

given the following test file we can run it with the various option values.

const std = @import("std");

pub const std_options = std.Options{
    .debug_stacktrace_kind = .full,
};

pub fn main() !void {
    foo();
}

fn foo() void {
    bar();
}

fn bar() void {
    qux();
}

fn qux() void {
    lorem();
}

fn lorem() void {
    ipsum();
}

fn ipsum() void {
    @panic("oops!");
}
thread 182792 panic: oops!
/home/meghan/src/zig/test4.zig:28:5: 0x10762c0 in ipsum (test4)
    @panic("oops!");
    ^
/home/meghan/src/zig/test4.zig:24:10: 0x10687e8 in lorem (test4)
    ipsum();
         ^
/home/meghan/src/zig/test4.zig:20:10: 0x1038158 in qux (test4)
    lorem();
         ^
/home/meghan/src/zig/test4.zig:16:8: 0x1036098 in bar (test4)
    qux();
       ^
/home/meghan/src/zig/test4.zig:12:8: 0x1033938 in foo (test4)
    bar();
       ^
/home/meghan/src/zig/test4.zig:8:8: 0x1033928 in main (test4)
    foo();
       ^
/home/meghan/src/zig/lib/std/start.zig:511:37: 0x1033904 in posixCallMainAndExit (test4)
            const result = root.main() catch |err| {
                                    ^
/home/meghan/src/zig/lib/std/start.zig:253:5: 0x1033441 in _start (test4)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
thread 182911 panic: oops!
/home/meghan/src/zig/test4.zig:28:5: 0x1073880 in ipsum (test4)
/home/meghan/src/zig/test4.zig:24:10: 0x10660e8 in lorem (test4)
/home/meghan/src/zig/test4.zig:20:10: 0x1037a78 in qux (test4)
/home/meghan/src/zig/test4.zig:16:8: 0x10359b8 in bar (test4)
/home/meghan/src/zig/test4.zig:12:8: 0x1033258 in foo (test4)
/home/meghan/src/zig/test4.zig:8:8: 0x1033248 in main (test4)
/home/meghan/src/zig/lib/std/start.zig:511:37: 0x1033224 in posixCallMainAndExit (test4)
/home/meghan/src/zig/lib/std/start.zig:253:5: 0x1032d61 in _start (test4)
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
thread 183137 panic: oops!
Aborted (core dumped)

beyond stylistic desires, the various options also have performance and binary size ramifications. .none exits faster not having to inspect the program's debug info and results in a smaller file. however since this does not require the file to be stripped to get the effect, using an external debugger remains totally possible.

-rwxr-xr-x 1 meghan users 2227856 Apr 14 02:01 ./test4-full
-rwxr-xr-x 1 meghan users 2208816 Apr 14 02:03 ./test4-slim
-rwxr-xr-x 1 meghan users 1921440 Apr 14 02:04 ./test4-none

@Khitiara
Copy link

Khitiara commented May 8, 2024

a version that prints out stack addresses without needing any debug info (so no file, line, or symbol name info) could be useful too

@nektro
Copy link
Contributor Author

nektro commented May 8, 2024

afaik that's already what happens if you use .full and strip. it will print out the addresses with the line info replaced with ????

@Khitiara
Copy link

Khitiara commented May 8, 2024

if you strip debug info then dumpStackTrace prints out a warning and returns early, and writeStackTrace returns error.MissingDebugInfo, though printSourceAtAddress does work for what you describe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants