Skip to content

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

@rootbeer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions