443 Commits

Author SHA1 Message Date
Cezary Kupaj
c4237e8909
Fix SIGSEGV handler for AArch64 Darwin targets
* ucontext_t ptr is 8-byte aligned instead of 16-byte aligned which @alignCast() expects
* Retrieve pc address from ucontext_t since unwind_state is null
* Work around __mcontext_data being written incorrectly by the kernel
2025-05-14 05:39:01 +02:00
Arnau Camprubí
9c857bb32d
Fix std.debug.dumpHex address offsets 2025-03-26 15:40:56 +01:00
mlugg
5e20e9b449 Sema: allow @ptrCast of slices changing the length
Also, refactor `Sema.ptrCastFull` to not be a horrifying hellscape.
2025-02-23 08:28:58 +00:00
Alex Rønne Petersen
481b7bf3f0
std.Target: Remove functions that just wrap component functions.
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look
at multiple components of the target. But functions like isWasm(), isDarwin(),
isGnu(), etc only exist to save 4-8 characters. I don't think this is a good
enough reason to keep them, especially given that:

* It's not immediately obvious to a reader whether target.isDarwin() means the
  same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar
  functions *do* look at multiple components.
* It's not clear where we would draw the line. The logical conclusion before
  this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(),
  Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand.
* It's nice to just have a single correct way of doing something.
2025-02-17 19:18:19 +01:00
Linus Groh
0a7502e886 std.os.uefi: Adjust casing of remaining enum fields
Work towards #2101.
2025-02-09 02:23:53 +00:00
Andrew Kelley
284de7d957 adjust runtime page size APIs
* 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-06 14:23:23 -08:00
Archbirdplus
439667be04 runtime page size detection
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-02-06 14:23:23 -08:00
Michael Dusan
c44be99f1a debug: fix MemoryAccessor file leak
- patch authored by Jacob Young
- tested on alpine-aarch64, 3.21.0, qemu-system 9.2.0
- issue manifested on Alpine Linux aarch64 under qemu-system where
  zig2 fails during bootstrap: error.ProcessFdQuotaExceeded
2025-02-01 04:27:24 +01:00
mlugg
3232e59ab9
std: remove old declarations now a zig1 update has happened 2025-01-24 22:33:23 +00:00
mlugg
5a6666db55
all: update for panic.unwrapError and panic.call signature changes 2025-01-24 22:33:23 +00:00
mlugg
83991efe10
compiler: yet more panic handler changes
* `std.builtin.Panic` -> `std.builtin.panic`, because it is a namespace.
* `root.Panic` -> `root.panic` for the same reason. There are type
  checks so that we still allow the legacy `pub fn panic` strategy in
  the 0.14.0 release.
* `std.debug.SimplePanic` -> `std.debug.simple_panic`, same reason.
* `std.debug.NoPanic` -> `std.debug.no_panic`, same reason.
* `std.debug.FormattedPanic` is now a function `std.debug.FullPanic`
  which takes as input a `panicFn` and returns a namespace with all the
  panic functions. This handles the incredibly common case of just
  wanting to override how the message is printed, whilst keeping nice
  formatted panics.
* Remove `std.builtin.panic.messages`; now, every safety panic has its
  own function. This reduces binary bloat, as calls to these functions
  no longer need to prepare any arguments (aside from the error return
  trace).
* Remove some legacy declarations, since a zig1.wasm update has
  happened. Most of these were related to the panic handler, but a quick
  grep for "zig1" brought up a couple more results too.

Also, add some missing type checks to Sema.

Resolves: #22584

formatted -> full
2025-01-24 19:29:51 +00:00
Alex Rønne Petersen
180db2bf23
std.debug: Fall back to .eh_frame/.debug_frame if .eh_frame_hdr is incomplete.
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.
2025-01-23 23:22:38 +00:00
mlugg
6e7ae66871
std.debug: remove errorReturnTraceHelper
This function doesn't do what it says; it's a nop.
2025-01-22 02:02:33 +00:00
andrewkraevskii
f1ce1aff11 std.debug: fix format on ConfigurableTrace 2025-01-21 10:54:14 +01:00
Jacob Young
63730441d0 x86_64: implement union access 2025-01-16 20:47:30 -05:00
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
mlugg
d00e05f186
all: update to std.builtin.Type.Pointer.Size field renames
This was done by regex substitution with `sed`. I then manually went
over the entire diff and fixed any incorrect changes.

This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since
my regex happened to also trigger here. I opted to leave these changes
in, since they *are* a correct migration, even if they're not the one I
was trying to do!
2025-01-16 12:46:29 +00:00
Pat Tullmann
5e1a83ad29 defaultPanic: @trap on 'other' target
The freestanding and other OS targets by default need to just @trap in the
default Panic implementation.

And `isValidMemory` won't work with freestanding or other targets.

Update the unwind_freestanding.zig test case to also run on the 'other' OS
target, too.  This should keep the Zig's stacktrace generation from
regressing on the standalone targets.
2024-11-29 15:30:05 -05:00
Scott Redig
b2c62bcbf6 add assertLocked to std.debug.SafetyLock 2024-11-22 18:39:17 -05:00
Alex Rønne Petersen
af71694dd9
std.debug: Add handling for armeb, thumb, thumbeb, and aarch64_be. 2024-11-04 08:29:42 +01:00
Alex Rønne Petersen
be8a527eb2
std.os.windows: Deprecate WINAPI in favor of CallingConvention.winapi. 2024-11-02 10:44:18 +01:00
Mario Nachbaur
4661705a0e
std.debug: watchOS: fixes for ilp32 ABI (#21765)
Xcode requires target arm64_32 (aarch64-watchos-ilp32) in order to
build code for Apple Watches. This commit fixes compilation errors
that appear when compiling with that target.
2024-10-29 22:12:57 +01:00
Linus Groh
f18c71ba73 std.debug: Fix defaultPanic() uefi build
lib/std/debug.zig:491:38: error: slice of non-array type 'u16'
            utf16_buffer[len_minus_3][0..3].* = .{ '\r', '\n', 0 };
            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

lib/std/debug.zig:510:70: error: expected type '?*const anyopaque', found '[]u16'
                _ = bs.exit(uefi.handle, .Aborted, exit_msg.len + 1, exit_data);
                                                                     ^~~~~~~~~

Regressed in #21520.
2024-10-07 02:40:01 +09:00
Alex Rønne Petersen
07c943598d
std.debug: Disable stack traces on s390x. 2024-10-03 06:19:23 +02:00
Andrew Kelley
c9c080a187 embrace panic helpers
Introduces `std.builtin.Panic` which is a complete interface for
panicking. Provide `std.debug.FormattedPanic` and
`std.debug.SimplePanic` and let the user choose, or make their own.
2024-09-26 16:06:05 -07:00
Andrew Kelley
fcfbedc2f0 work around riscv64 backend deficiencies 2024-09-26 16:06:05 -07:00
Andrew Kelley
f2c8940aa6 reintroduce the std.builtin safety panic helpers
motivated by performance
2024-09-26 12:35:14 -07:00
Andrew Kelley
9ccf8d3332 fixes for this branch
I had to bring back some of the old API so that I could compile the new
compiler with an old compiler.
2024-09-26 12:35:14 -07:00
Andrew Kelley
4f8d244e7e remove formatted panics
implements #17969
2024-09-26 12:35:14 -07:00
Nico Elbers
cad65307b7 std: make debug.dumpStackPointerAddr compile
Very simply add the format specifier to the print statement.
Since debug.print is hard coded I couldn't come up with a reasonalble
way to add a test, and since this function is simple enough I doubt it's
useful.

fixes one part of #21094
2024-09-01 00:45:31 -07:00
Andrew Kelley
96daca7b3b
Merge pull request #21173 from mrjbq7/writeStackTrace
std.debug: remove allocator from std.debug.writeStackTrace()
2024-08-31 20:57:27 -07:00
Andrew Kelley
a4cc43c42b
Merge pull request #21174 from alexrp/win-arm
Change `arm-windows-gnu` to `thumb-windows-gnu`, plus some initial port work
2024-08-30 14:34:53 -07:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
Alex Rønne Petersen
34c6482403
std.debug: Fix a bitness portability issue in walkStackWindows(). 2024-08-28 03:13:01 +02:00
mlugg
6808ce27bd
compiler,lib,test,langref: migrate @setCold to @branchHint 2024-08-27 00:44:35 +01:00
John Benediktsson
c690537154 std.debug: remove allocator from std.debug.writeStackTrace() 2024-08-22 21:23:53 -07:00
Alex Rønne Petersen
4320611e6d std.debug: Also disable stack traces on mips64. 2024-08-18 07:27:23 +02:00
Jacob Young
e9df5ab7f1 std: disable failing debug info test for self-hosted 2024-08-16 16:23:53 -04:00
Alex Rønne Petersen
b470d2a7de std.debug: Support sparc32 in StackIterator.init(). 2024-08-13 23:54:20 -07:00
Andrew Kelley
517cfb0dd1 fuzzing: progress towards web UI
* libfuzzer: close file after mmap
* fuzzer/main.js: connect with EventSource and debug dump the messages.
  currently this prints how many fuzzer runs have been attempted to
  console.log.
* extract some `std.debug.Info` logic into `std.debug.Coverage`.
  Prepares for consolidation across multiple different executables which
  share source files, and makes it possible to send all the
  PC/SourceLocation mapping data with 4 memcpy'd arrays.
* std.Build.Fuzz:
  - spawn a thread to watch the message queue and signal event
    subscribers.
  - track coverage map data
  - respond to /events URL with EventSource messages on a timer
2024-08-07 00:48:32 -07:00
Andrew Kelley
1792258dc8 std.debug.Dwarf: precompute .debug_line table
yields a 60x speedup for resolveSourceLocations in debug builds
2024-08-07 00:48:32 -07:00
Andrew Kelley
66954e8330 std.debug.FixedBufferReader is fine
it does not need to be deprecated
2024-08-07 00:48:32 -07:00
Andrew Kelley
de47acd732 code coverage dumping tool basic implementation
* std.debug.Dwarf: add `sortCompileUnits` along with a field to track
  the state for the purpose of assertions and correct API usage.
  This makes batch lookups faster.
  - in the future, findCompileUnit should be enhanced to rely on sorted
    compile units as well.
* implement `std.debug.Dwarf.resolveSourceLocations` as well as
  `std.debug.Info.resolveSourceLocations`. It's still pretty slow, since
  it calls getLineNumberInfo for each array element, repeating a lot of
  work unnecessarily.
* integrate these APIs with `std.Progress` to understand what is taking
  so long.

The output I'm seeing from this tool shows a lot of missing source
locations. In particular, the main area of interest is missing for my
tokenizer fuzzing example.
2024-08-07 00:48:32 -07:00
Andrew Kelley
2e12b45d8b introduce tool for dumping coverage file
with debug info resolved.

begin efforts of providing `std.debug.Info`, a cross-platform
abstraction for loading debug information into an in-memory format that
supports queries such as "what is the source location of this virtual
memory address?"

Unlike `std.debug.SelfInfo`, this API does not assume the debug
information in question happens to match the host CPU architecture, OS,
or other target properties.
2024-08-07 00:48:32 -07:00
Andrew Kelley
975c185b92 fix compilation on powerpc GNU systems
...which have a ucontext_t but not a PC register. The current stack
unwinding implementation does not yet support this architecture.

Also fix name of `std.debug.SelfInfo.openSelf` to remove redundancy.

Also removed this hook into root providing an "openSelfDebugInfo"
function. Sorry, this debugging code is not of sufficient quality to
offer a plugin API right now.
2024-08-02 14:14:59 -07:00
Andrew Kelley
48d584e3a3 std.debug: reorg and clarify API goals
After this commit:

`std.debug.SelfInfo` is a cross-platform abstraction for the current
executable's own debug information, with a goal of minimal code bloat
and compilation speed penalty.

`std.debug.Dwarf` does not assume the current executable is itself the
thing being debugged, however, it does assume the debug info has the
same CPU architecture and OS as the current executable. It is planned to
remove this limitation.
2024-08-01 23:11:59 -07:00
Andrew Kelley
290966c249 std.debug: rename Info to SelfInfo
This code has the hard-coded goal of supporting the executable's own
debug information and makes design choices along that goal, such as
memory-mapping the inputs, using dl_iterate_phdr, and doing conditional
compilation on the host target.

A more general-purpose implementation of debug information may be able
to share code with this, but there are some fundamental
incompatibilities. For example, the "SelfInfo" implementation wants to
avoid bloating the binary with PDB on POSIX systems, and likewise DWARF
on Windows systems, while a general-purpose implementation needs to
support both PDB and DWARF from the same binary. It might, for example,
inspect the debug information from a cross-compiled binary.

`SourceLocation` now lives at `std.debug.SourceLocation` and is
documented.

Deprecate `std.debug.runtime_safety` because it returns the optimization
mode of the standard library, when the caller probably wants to use the
optimization mode of their own module.

`std.pdb.Pdb` is moved to `std.debug.Pdb`, mirroring the recent
extraction of `std.debug.Dwarf` from `std.dwarf`.

I have no idea why we have both Module (with a Windows-specific
definition) and WindowsModule. I left some passive aggressive doc
comments to express my frustration.
2024-08-01 22:11:35 -07:00
Andrew Kelley
1ba6b56c81 std.debug.Info: extract to separate file 2024-08-01 22:11:23 -07:00
Andrew Kelley
e5b46eab3b std: dwarf namespace reorg
std.debug.Dwarf is the parsing/decoding logic. std.dwarf remains the
unopinionated types and bits alone.

If you look at this diff you can see a lot less redundancy in
namespaces.
2024-08-01 13:56:12 -07:00
Andrew Kelley
377274ee9a std.debug.DebugInfo: rename to std.debug.Info
avoiding redundancy in the fully qualified namespace
2024-08-01 13:47:42 -07:00