aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug/cpu_context.zig
AgeCommit message (Collapse)Author
2025-10-15std.debug.cpu_context: add sparc*-linux context conversion supportAlex Rønne Petersen
It's not really a ucontext_t at all. Lovely stuff.
2025-10-15std.debug.cpu_context.Sparc: flush register windows in current()Alex Rønne Petersen
It's better to do this here than in StackIterator.init() so that std.debug.cpu_context.Native.current() isn't a footgun on SPARC.
2025-10-15std.debug.cpu_context: add Sparc contextAlex Rønne Petersen
2025-10-12std.debug.cpu_context: consider arm and aarch64 reserved register ranges ↵Alex Rønne Petersen
unsupported If these ever get allocated, it's most likely going to be for things that don't matter to us anyway, so completely abandoning DWARF unwinding just because we see these doesn't seem justified. We will still do so if we're actually asked to read from such a register, which is the only actually problematic case; see c23a5ccd19 for more details.
2025-10-10std.debug: greatly expand target support for segfault handling/unwindingAlex Rønne Petersen
I made a couple of decisions for this based on the fact that we don't expose the signal_ucontext_t type outside of the file: * Adding all the floating point and vector state to every ucontext_t and mcontext_t variant was way, way too much work, especially when we don't even use the stuff. So I deleted all that and kept only the bare minimum needed to reach into general-purpose registers. * There is no particularly compelling reason to stick to the naming and struct nesting used in the system headers. So we can actually unify the access patterns for almost all of these variants by taking some liberties here; as a result, fromPosixSignalContext() is now much nicer to read and extend.
2025-10-07std.debug.cpu_context: make arch-specific implementations privateAlex Rønne Petersen
2025-10-07std.debug.cpu_context: map a bunch of known registers as unsupported instead ↵Alex Rønne Petersen
of invalid
2025-10-07std.debug.cpu_context: remove support for s390x float registersAlex Rønne Petersen
Let's for the moment assume that compilers haven't lost the plot. Fingers crossed.
2025-10-07std.debug.Dwarf: use 66 as the (fake) MIPS PC registerAlex Rønne Petersen
32-63 conflict with the floating point registers. 64 and 65 are used for the ac0 hi/lo registers.
2025-10-07std.debug.Dwarf: use 67 as the (fake) PowerPC PC registerAlex Rønne Petersen
It's free real estate, as it turns out.
2025-10-07std.debug.Dwarf: use 65 as the (fake) RISC-V PC registerAlex Rønne Petersen
32-63 conflict with the floating point registers. 64 is the Alternate Frame Return Column.
2025-10-07std.debug.Dwarf: use 64 as the (fake) LoongArch PC registerAlex Rønne Petersen
32-63 conflict with the floating point registers.
2025-10-07std.debug: add unwind support for powerpc*-linuxAlex Rønne Petersen
2025-10-07std.debug: add unwind support for mips*-linuxAlex Rønne Petersen
2025-10-07std.debug.cpu_context: check for architecture, i.e. register size, not bitnessAlex Rønne Petersen
We care about the hardware here, not the ABI.
2025-10-05std.debug: add unwind support for hexagon-linuxAlex Rønne Petersen
2025-10-03std.debug: Add unwind support for serenityLinus Groh
2025-10-03std.debug: add s390x-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: add riscv32-linux and riscv64-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: add loongarch64-linux unwind supportAlex Rønne Petersen
2025-10-01std.debug: some adjustments to target handlingAlex Rønne Petersen
* driverkit handling missing in a few places. * x86-solaris is a dead target. * aarch64_be does not exist on Darwin, FreeBSD, Windows.
2025-09-30typomlugg
2025-09-30std: clarify cpu_context register order rationalemlugg
2025-09-30std: don't get CPU context when using CBE targeting MSVCmlugg
Calling `current` here causes compilation failures as the C backend currently does not emit valid MSVC inline assembly. This change means that when building for MSVC with the self-hosted C backend, only FP unwinding can be used.
2025-09-30std.debug: miscellaneous fixesmlugg
Mostly on macOS, since Loris showed me a not-great stack trace, and I spent 8 hours trying to make it better. The dyld shared cache is designed in a way which makes this really hard to do right, and documentation is non-existent, but this *seems* to work pretty well. I'll leave the ruling on whether I did a good job to CI and our users.
2025-09-30std: rework/remove ucontext_tmlugg
Our usage of `ucontext_t` in the standard library was kind of problematic. We unnecessarily mimiced libc-specific structures, and our `getcontext` implementation was overkill for our use case of stack tracing. This commit introduces a new namespace, `std.debug.cpu_context`, which contains "context" types for various architectures (currently x86, x86_64, ARM, and AARCH64) containing the general-purpose CPU registers; the ones needed in practice for stack unwinding. Each implementation has a function `current` which populates the structure using inline assembly. The structure is user-overrideable, though that should only be necessary if the standard library does not have an implementation for the *architecture*: that is to say, none of this is OS-dependent. Of course, in POSIX signal handlers, we get a `ucontext_t` from the kernel. The function `std.debug.cpu_context.fromPosixSignalContext` converts this to a `std.debug.cpu_context.Native` with a big ol' target switch. This functionality is not exposed from `std.c` or `std.posix`, and neither are `ucontext_t`, `mcontext_t`, or `getcontext`. The rationale is that these types and functions do not conform to a specific ABI, and in fact tend to get updated over time based on CPU features and extensions; in addition, different libcs use different structures which are "partially compatible" with the kernel structure. Overall, it's a mess, but all we need is the kernel context, so we can just define a kernel-compatible structure as long as we don't claim C compatibility by putting it in `std.c` or `std.posix`. This change resulted in a few nice `std.debug` simplifications, but nothing too noteworthy. However, the main benefit of this change is that DWARF unwinding---sometimes necessary for collecting stack traces reliably---now requires far less target-specific integration. Also fix a bug I noticed in `PageAllocator` (I found this due to a bug in my distro's QEMU distribution; thanks, broken QEMU patch!) and I think a couple of minor bugs in `std.debug`. Resolves: #23801 Resolves: #23802