Skip to content

std.debug should stop depending on getcontext() #23801

Closed

Description

@rootbeer

Zig Version

0.15.0-dev.451+bd230215f

Steps to Reproduce and Observed Behavior

I believe the only current use of getcontext in the Zig library is in std.debug. From what I can tell, this code doesn't need a full ucontext_t (which includes a signal mask, floating point state, and a shadow stack). The existing debug code just needs the basic CPU registers. Perhaps just the mcontext_t register state would be sufficient?

I think moving away from getcontext() would make it easier to get the stack walking code working on other platforms (e.g., Android and OpenBSD don't provide a getcontext() at all, nor generally do freestanding and other targets). This also might make it simpler to get new platforms to support this debug code since they would just need a bit of arch-specific assembly to capture the basic registers.

Finally, the getcontext() API is "deprecated" (See https://man7.org/linux/man-pages/man3/getcontext.3.html: "POSIX.1-2008 removes these functions, citing portability issues, and recommending that applications be rewritten to use POSIX threads instead.") and has some hairy portability issues (it's a struct with embedded pointers that need to be fixed up when copied and its size can vary across C library versions and kernel versions).

Expected Behavior

std.debug uses locally defined assembly to capture register values, removing Zig's dependency on the getcontext() API.

Activity

  1. added
    bug
    on May 5, 2025
  2. alexrp commented on May 5, 2025

    @alexrp
    Member
  3. alexrp commented on May 6, 2025

    @alexrp
    Member

    To be clear, I intended for #23494 to be an incremental step towards what this issue is proposing. So, if this is something you feel like tackling, feel free to skip over the #23494 step.

  4. added
    enhancement
    and removed
    bug
    enhancement
    on May 6, 2025
  5. added this to the 0.15.0 milestone on May 6, 2025
  6. added
    standard library
    on May 6, 2025
  7. modified the milestones: urgent, upcoming on Jun 26, 2025
  8. added 8 commits that reference this issue on Sep 17, 2025
    0b1f5ac
    04a86a8
    420506e
    9ddc79d
    5598a9a
    eb35d32
    d5fb6b1
    a18fd41
  9. added a commit that references this issue on Oct 3, 2025
    eeb4264
  10. 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

    optimizationos-linuxstandard library

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions