Skip to content

proposal: allow stack traces to be disabled even when not stripping debug info #18387

Closed

Description

@xdBronch

the current logic to decide when to include stack tracing code is simply checking if debug info is stripped or not

zig/lib/std/debug.zig

Lines 119 to 122 in ff17b11

if (builtin.strip_debug_info) {
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
return;
}

in most cases this is fine, its extremely convenient to just run your program and get stack traces on panics, errors, crashes, etc. its like your program is a debugger itself. but this isnt always the best, in embedded applications for example. you have to use ReleaseSmall but if you want to keep debug info it compiles in an insane amount of code for something you dont want or need. in cases this like its quite trivial to separate the debug info manually with e.g. objcopy and now you have the best of both worlds, tiny binary and stack traces by using a debugger.
i did a simple test on a program that only consisted of a blank panic in main and the binary sizes were the following

Config Size
ReleaseSmall (stripped) 8.0K
ReleaseSmall (-fno-strip) 1.2M
ReleaseSmall (-fno-strip) + strip -s 130K
ReleaseSmall (-fno-strip, no stack traces) 526K
ReleaseSmall (-fno-strip, no stack traces) + strip -s 8K

im thinking this could be something in std_options then the checks in debug.zig can just be changed to something like if (!std.options.keep_stack_traces or builtin.strip_debug_info)

Activity

  1. cn-cn-cn commented on Dec 31, 2023

    @cn-cn-cn
    Contributor

    In general, the concept of using "is stripped" as a setting for things to include in the binary is misleading, whether the binary will be stripped is not comptime-known.

  2. added
    enhancement
    standard library
    on Dec 8, 2024
  3. added this to the 0.15.0 milestone on Dec 8, 2024
  4. modified the milestones: urgent, upcoming on Jun 26, 2025
  5. mlugg commented on Oct 1, 2025

    @mlugg
    Member

    Resolved by b64535e with this new field in std.Options:

        /// Whether to allow capturing and writing stack traces. This affects the following functions:
        /// * `debug.captureCurrentStackTrace`
        /// * `debug.writeCurrentStackTrace`
        /// * `debug.dumpCurrentStackTrace`
        /// * `debug.writeStackTrace`
        /// * `debug.dumpStackTrace`
        ///
        /// Stack traces can generally be collected and printed when debug info is stripped, but are
        /// often less useful since they usually cannot be mapped to source locations and/or have bad
        /// source locations. The stack tracing logic can also be quite large, which may be undesirable,
        /// particularly in ReleaseSmall.
        ///
        /// If this is `false`, then captured stack traces will always be empty, and attempts to write
        /// stack traces will just print an error to the relevant `Io.Writer` and return.
        allow_stack_tracing: bool = !@import("builtin").strip_debug_info,
  6. modified the milestones: upcoming, 0.16.0 on Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementstandard library

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions