aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug/Dwarf.zig
AgeCommit message (Collapse)Author
2025-10-23std.Target: add arceb and xtensaeb Cpu.Arch tagsAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for arcAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for m68kAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for or1kAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for cskyAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for lanaiAlex Rønne Petersen
2025-10-18std.debug: add CPU context and DWARF mappings for veAlex Rønne Petersen
2025-10-15std.debug.Dwarf: add SPARC register number mappingsAlex Rønne Petersen
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-05std.debug: add unwind support for hexagon-linuxAlex Rønne Petersen
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-09-30std.debug.SelfInfo: remove shared logicmlugg
There were only a few dozen lines of common logic, and they frankly introduced more complexity than they eliminated. Instead, let's accept that the implementations of `SelfInfo` are all pretty different and want to track different state. This probably fixes some synchronization and memory bugs by simplifying a bunch of stuff. It also improves the DWARF unwind cache, making it around twice as fast in a debug build with the self-hosted x86_64 backend, because we no longer have to redundantly go through the hashmap lookup logic to find the module. Unwinding on Windows will also see a slight performance boost from this change, because `RtlVirtualUnwind` does not need to know the module whatsoever, so the old `SelfInfo` implementation was doing redundant work. Lastly, this makes it even easier to implement `SelfInfo` on freestanding targets; there is no longer a need to emulate a real module system, since the user controls the whole implementation! There are various other small refactors here in the `SelfInfo` implementations as well as in the DWARF unwinding logic. This change turned out to make a lot of stuff simpler!
2025-09-30std.debug: significantly speed up capturing stack tracesmlugg
By my estimation, these changes speed up DWARF unwinding when using the self-hosted x86_64 backend by around 7x. There are two very significant enhancements: we no longer iterate frames which don't fit in the stack trace buffer, and we cache register rules (in a fixed buffer) to avoid re-parsing and evaluating CFI instructions in most cases. Alongside this are a bunch of smaller enhancements, such as pre-caching the result of evaluating the CIE's initial instructions, avoiding re-parsing of CIEs, and big simplifications to the `Dwarf.Unwind.VirtualMachine` logic.
2025-09-30std.debug.SelfInfo: thread safetymlugg
This has been a TODO for ages, but in the past it didn't really matter because stack traces are typically printed to stderr for which a mutex is held so in practice there was a mutex guarding usage of `SelfInfo`. However, now that `SelfInfo` is also used for simply capturing traces, thread safety is needed. Instead of just a single mutex, though, there are a couple of different mutexes involved; this helps make critical sections smaller, particularly when unwinding the stack as `unwindFrame` doesn't typically need to hold any lock at all.
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
2025-09-30std.debug.Dwarf: fix names of inlined functionsmlugg
2025-09-30Dwarf: use 'gpa' terminologymlugg
2025-09-30std: replace debug.Dwarf.ElfModule with debug.ElfFilemlugg
This abstraction isn't really tied to DWARF at all! Really, we're just loading some information from an ELF file which is useful for debugging. That *includes* DWARF, but it also includes other information. For instance, the other change here: Now, if DWARF information is missing, `debug.SelfInfo.ElfModule` will name symbols by finding a matching symtab entry. We actually already do this on Mach-O, so it makes obvious sense to do the same on ELF! This change is what motivated the restructuring to begin with. The symtab work is derived from #22077. Co-authored-by: geemili <opensource@geemili.xyz>
2025-09-30std.debug: unwinding on Windowsmlugg
...using `RtlVirtualUnwind` on x86_64 and aarch64, and `RtaCaptureStackBackTrace` on x86.
2025-09-30std: fix debug.Info and debug.Coveragemlugg
2025-09-30std.debug: improve the APIs and stuffmlugg
2025-09-30tweaksmlugg
2025-09-30std.debug.SelfInfo: concrete error setsmlugg
The downside of this commit is that more precise errors are no longer propagated up. However, these errors were pretty useless in isolation due to them having no context; and regardless, we intentionally swallow most of them in `std.debug` anyway. Therefore, this is better in practice, because it allows `std.debug` to give slightly more useful warnings when handling errors. This commit does that for unwind errors, for instance, which differentiate between the unwind info being corrupt vs missing vs inaccessible vs unsupported. A better solution would be to also include more detailed information via the diagnostics pattern, but this commit is an incremental improvement.
2025-09-30std.debug.Dwarf: eliminate host pointer size dependencymlugg
2025-09-30the world if Dwarf.ElfModule was like REALLY good:mlugg
2025-09-30the world if ElfModule didn't suck:mlugg
2025-09-30me when i did a thingmlugg
2025-09-30more stillmlugg
2025-09-30more stuffmlugg
2025-09-30change one million thingsmlugg
2025-09-30debug: refactor stack frame capturingJacob Young
2025-08-25delete std.debug.FixedBufferReaderAndrew Kelley
now that std.Io.Reader has sufficient debug performance
2025-08-23std.debug: delete MemoryAccessorAndrew Kelley
This API is based around the unsound idea that a process can perform checked virtual memory loads to prevent crashing. This depends on OS-specific APIs that may be unavailable, disabled, or impossible due to virtualization. It also makes collecting stack traces ridiculously slow, which is a problem for users of DebugAllocator - in other words, everybody, all the time. It also makes strace go from being superbly clean to being awful.
2025-08-15std.compress.zstd.Decompress fixesAndrew Kelley
* std.Io.Reader: appendRemaining no longer supports alignment and has different rules about how exceeding limit. Fixed bug where it would return success instead of error.StreamTooLong like it was supposed to. * std.Io.Reader: simplify appendRemaining and appendRemainingUnlimited to be implemented based on std.Io.Writer.Allocating * std.Io.Writer: introduce unreachableRebase * std.Io.Writer: remove minimum_unused_capacity from Allocating. maybe that flexibility could have been handy, but let's see if anyone actually needs it. The field is redundant with the superlinear growth of ArrayList capacity. * std.Io.Writer: growingRebase also ensures total capacity on the preserve parameter, making it no longer necessary to do ensureTotalCapacity at the usage site of decompression streams. * std.compress.flate.Decompress: fix rebase not taking into account seek * std.compress.zstd.Decompress: split into "direct" and "indirect" usage patterns depending on whether a buffer is provided to init, matching how flate works. Remove some overzealous asserts that prevented buffer expansion from within rebase implementation. * std.zig: fix readSourceFileToAlloc returning an overaligned slice which was difficult to free correctly. fixes #24608
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-07-31std.debug.Dwarf: work around API deficiencyAndrew Kelley
need to supply a big enough buffer when working with decompression
2025-07-31std.compress: rework flate to new I/O APIAndrew Kelley
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-05-17debug: correctly detect missing entries in `.eh_frame_hdr`Jacob Young
2025-02-24stdlib: handle EEXIST in mmap with FIXED_NOREPLACE. Fixes #21475Alec Fessler
2025-02-06adjust runtime page size APIsAndrew Kelley
* fix merge conflicts * rename the declarations * reword documentation * extract FixedBufferAllocator to separate file * take advantage of locals * remove the assertion about max alignment in Allocator API, leaving it Allocator implementation defined * fix non-inline function call in start logic The GeneralPurposeAllocator implementation is totally broken because it uses global state but I didn't address that in this commit.
2025-02-06runtime page size detectionArchbirdplus
heap.zig: define new default page sizes heap.zig: add min/max_page_size and their options lib/std/c: add miscellaneous declarations heap.zig: add pageSize() and its options switch to new page sizes, especially in GPA/stdlib mem.zig: remove page_size
2025-01-23std.debug: Fall back to .eh_frame/.debug_frame if .eh_frame_hdr is incomplete.Alex Rønne Petersen
When using the self-hosted backends, especially in incremental mode, the .eh_frame_hdr section may be incomplete, so we can't treat it as authoritative. Instead, if we started out intending to use .eh_frame_hdr but find that it's incomplete, load .eh_frame/.debug_frame on demand and use that info going forward.