Commit Graph

135 Commits

Author SHA1 Message Date
mlugg c1a30bd0d8 std: replace debug.Dwarf.ElfModule with debug.ElfFile
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-30 13:44:52 +01:00
mlugg e6adddf80c small reasonable change 2025-09-30 13:44:52 +01:00
mlugg 229f0a01b8 std.debug: handle ThreadContext slightly better
It's now user-overrideable, and uses `noreturn` types to neatly stop
analysis.
2025-09-30 13:44:52 +01:00
mlugg 1392a7af17 std.debug: unwinding on Windows
...using `RtlVirtualUnwind` on x86_64 and aarch64, and
`RtaCaptureStackBackTrace` on x86.
2025-09-30 13:44:52 +01:00
mlugg ac4d633ed6 std: fix debug.Info and debug.Coverage 2025-09-30 13:44:52 +01:00
mlugg 3a561da38d std: doc comments and tweaks 2025-09-30 13:44:51 +01:00
mlugg 0c7b2a7bd5 fix compiler ftbfs from std.macho and std.dwarf changes 2025-09-30 13:44:51 +01:00
mlugg f1215adeda SelfInfo.DarwinModule: rename field 2025-09-30 13:44:51 +01:00
mlugg 253fdfce70 SelfInfo: be honest about how general unwinding is
...in that it isn't: it's currently very specialized to DWARF unwinding.

Also, make a type unmanaged.
2025-09-30 13:44:51 +01:00
mlugg 9859440d83 add freestanding support IN THEORY
untested because this branch has errors rn
2025-09-30 13:44:51 +01:00
mlugg 5709369d05 std.debug: improve the APIs and stuff 2025-09-30 13:44:51 +01:00
mlugg d4f710791f tweaks 2025-09-30 13:44:51 +01:00
mlugg ba5d9d5a41 remove redundant test
turns out this actually has coverage in std.debug
2025-09-30 13:44:50 +01:00
mlugg 405075f745 SelfInfo: load eh_frame/debug_frame from ELF file if eh_frame_hdr omitted 2025-09-30 13:44:50 +01:00
mlugg c895aa7a35 std.debug.SelfInfo: concrete error sets
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-30 13:44:50 +01:00
mlugg dd9cb1beea doc comments 2025-09-30 13:44:50 +01:00
mlugg 5e6a1919c7 fix aarch64-macos DWARF unwinding
turns out this isn't technically specific to that target at all; other
targets just don't emit mid-function 'ret' instructions as much so
certain CFI instruction patterns were only seen on aarch64.

thanks to jacob for finding the bug <3
2025-09-30 13:44:50 +01:00
mlugg 4b47a37717 stash? more like no 2025-09-30 13:44:50 +01:00
mlugg 665f13b0cd SelfInfo deinit magic 2025-09-30 13:44:50 +01:00
mlugg ba3f38959a split SelfInfo into a file per impl 2025-09-30 13:44:50 +01:00
mlugg 1397b95143 std.debug.Dwarf: eliminate host pointer size dependency 2025-09-30 13:44:50 +01:00
mlugg b762cd30fd remove TODOs which are done or which i'm not actually gonna do lol 2025-09-30 13:44:50 +01:00
mlugg e4dbfc109b dont dupe state you silly billy 2025-09-30 13:44:50 +01:00
mlugg 8fdcdb8c69 the world if Dwarf.ElfModule was like REALLY good: 2025-09-30 13:44:49 +01:00
mlugg 84b65860cf the world if ElfModule didn't suck: 2025-09-30 13:44:49 +01:00
mlugg 55a7affea4 me when i did a thing 2025-09-30 13:44:49 +01:00
mlugg 25e02bed4c less hacky :D 2025-09-30 13:44:49 +01:00
mlugg 55ae6747e2 names 2025-09-30 13:44:49 +01:00
mlugg 3f6a90766c sky pirates! which are even better! 2025-09-30 13:44:49 +01:00
mlugg fb88dab4c9 more still 2025-09-30 13:44:49 +01:00
mlugg ed6ed62c42 more stuff 2025-09-30 13:44:49 +01:00
mlugg b750e7cf9e change one million things 2025-09-30 13:44:49 +01:00
Jacob Young b706949736 debug: refactor stack frame capturing 2025-09-30 13:44:48 +01:00
Andrew Kelley 9a0970a12b rework std.Io.Writer.Allocating to support runtime-known alignment
Also, breaking API changes to:
* std.fs.Dir.readFileAlloc
* std.fs.Dir.readFileAllocOptions
2025-08-30 00:48:50 -07:00
Andrew Kelley 79f267f6b9 std.Io: delete GenericReader
and delete deprecated alias std.io
2025-08-29 17:14:26 -07:00
Andrew Kelley 43fbc37a49 std.debug.Pdb: migrate more towards new Reader API
There was some bug in this branch, and rather than diagnosing it, I
fully finished porting over to new Reader API. Did it fix the bug?
2025-08-28 22:41:06 -07:00
Andrew Kelley 8023f3dceb fix not discarding delimiter
perhaps these APIs have the defaults backwards, eh?
2025-08-28 18:30:57 -07:00
Andrew Kelley ea3471288a update GenericWriter usage found by test-cases 2025-08-28 18:30:57 -07:00
Andrew Kelley 9860dd475a std: delete most remaining uses of GenericWriter 2025-08-28 18:30:57 -07:00
Alex Rønne Petersen 5d019abe4e start adding big endian RISC-V support
The big endian RISC-V effort is mostly driven by MIPS (the company) which is
pivoting to RISC-V, and presumably needs a big endian variant to fill the niche
that big endian MIPS (the ISA) did.

GCC already supports these targets, but LLVM support will only appear in 22;
this commit just adds the necessary target knowledge and checks on our end.
2025-08-25 16:15:17 +02:00
Andrew Kelley 12686d9b7d delete std.debug.FixedBufferReader
now that std.Io.Reader has sufficient debug performance
2025-08-25 04:05:37 -07:00
Andrew Kelley d00cc10086 std.debug: delete MemoryAccessor
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-23 13:48:52 -07:00
Andrew Kelley 30b41dc510 std.compress.zstd.Decompress fixes
* 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-15 10:44:35 -07:00
Andrew Kelley 749f10af49 std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
Justus Klausecker 7c35070b90 zig fmt: apply new cast builtin order 2025-08-03 14:59:56 +02:00
Andrew Kelley 2024abda6a std.debug.Dwarf: work around API deficiency
need to supply a big enough buffer when working with decompression
2025-07-31 22:10:11 -07:00
Andrew Kelley 83513ade35 std.compress: rework flate to new I/O API 2025-07-31 22:10:11 -07:00
Andrew Kelley 76d04c1662 zig fmt 2025-07-16 10:27:39 -07:00
Andrew Kelley 0e37ff0d59 std.fmt: breaking API changes
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-07-07 22:43:51 -07:00
Andrew Kelley 0b3f0124dc std.io: move getStdIn, getStdOut, getStdErr functions to fs.File
preparing to rearrange std.io namespace into an interface

how to upgrade:

std.io.getStdIn() -> std.fs.File.stdin()
std.io.getStdOut() -> std.fs.File.stdout()
std.io.getStdErr() -> std.fs.File.stderr()
2025-07-07 22:43:51 -07:00