aboutsummaryrefslogtreecommitdiff
path: root/test/stack_traces.zig
AgeCommit message (Collapse)Author
2025-09-30tests: split up and enhance stack trace testsmlugg
Previously, the `test-stack-traces` step was essentially just testing error traces, and even there we didn't have much coverage. This commit solves that by splitting the "stack trace" tests into two separate harnesses: the "stack trace" tests are for actual stack traces (i.e. involving stack unwinding), while the "error trace" tests are specifically for error return traces. The "stack trace" tests will test different configurations of: * `-lc` * `-fPIE` * `-fomit-frame-pointer` * `-fllvm` * unwind tables (currently disabled) * strip debug info (currently disabled) The main goal there is to test *stack unwinding* under different conditions. Meanwhile, the "error trace" tests will test different configurations of `-O` and `-fllvm`; the main goal here, aside from checking that error traces themselves do not miscompile, is to check whether debug info is still working even in optimized builds. Of course, aggressive optimizations *can* thwart debug info no matter what, so as before, there is a way to disable cases for specific targets / optimize modes. The program which converts stack traces into a more validatable format by removing things like addresses (previously `check-stack-trace.zig`, now `convert-stack-trace.zig`) has been rewritten and simplified. Also, thanks to various fixes in this branch, several workarounds have become unnecessary: for instance, we don't need to ignore the function name printed in stack traces in release modes, because `std.debug.Dwarf` now uses the correct DIE for inlined functions! Neither `test-stack-traces` nor `test-error-traces` does general foreign architecture testing, because it seems that (at least for now) external executors often aren't particularly good at handling stack tracing correctly (looking at you, Wine). Generally, they just test the native target (this matches the old behavior of `test-stack-traces`). However, there is one exception: when on an x86_64 or aarch64 host, we will also test the 32-bit version (x86 or arm) if the OS supports it, because such executables can be trivially tested without an external executor. Oh, also, I wrote a bunch of stack trace tests. Previously there was, erm, *one* test in `test-stack-traces` which wasn't for error traces. Now there are a good few!
2025-09-22test: disable some stack trace tests on FreeBSDalexrp
2025-09-18test: skip dumpCurrentStackTrace test on architectures with no unwind supportAlex Rønne Petersen
2025-04-04test: Disable `error union switch with call operand` (ReleaseSafe) on macos.Alex Rønne Petersen
This started failing in LLVM 20: test +- test-stack-traces +- check error union switch with call operand (ReleaseSafe llvm) failure error: ========= expected this stdout: ========= error: TheSkyIsFalling source.zig:3:5: [address] in [function] return error.TheSkyIsFalling; ^ ========= but found: ==================== error: TheSkyIsFalling source.zig:13:27: [address] in [function] error.NonFatal => return, ^
2025-01-23tests: enable stack trace tests for x86_64-selfhostedmlugg
Allows the stack trace tests to be additionally compiled and run with `.use_llvm = false, .use_lld = false` depending on the host target. This is currently enabled for x86_64 targets emitting ELF. Self-hosted backends emit slightly different DWARF info to the LLVM backend, so the checking logic (and the tests themselves) had to be tweaked slightly to support both backends at once.
2024-01-18test/stack_traces.zig: add err union switch casedweiller
2024-01-01update stack trace tests to account for new defaultsAndrew Kelley
ReleaseSafe optimization mode now defaults error tracing to false.
2022-12-17zig fmt: fix extra whitespace with multiline stringsyujiri8
Fixes #13937
2022-11-22AstGen: Pop error trace for `continue`Cody Tapscott
PR #12837 handled control flow for break and return, but I forgot about `continue`. This is effectively another break, so we just need another `.restore_err_ret_index` ZIR instruction. Resolves #13618.
2022-10-21stage2: Keep error return traces alive when storing to `const`Cody Tapscott
This change extends the "lifetime" of the error return trace associated with an error to continue throughout the block of a `const` variable that it is assigned to. This is necessary to support patterns like this one in test_runner.zig: ```zig const result = foo(); if (result) |_| { // ... success logic } else |err| { // `foo()` should be included in the error trace here return error.TestFailed; } ``` To make this happen, the majority of the error return trace popping logic needed to move into Sema, since `const x = foo();` cannot be examined syntactically to determine whether it modifies the error return trace. We also have to make sure not to delete pertinent block information before it makes it to Sema, so that Sema can pop/restore around blocks correctly. * Why do this only for `const` and not `var`? * There is room to relax things for `var`, but only a little bit. We could do the same thing we do for const and keep the error trace alive for the remainder of the block where the *assignment* happens. Any wider scope would violate the stack discipline for traces, so it's not viable. In the end, I decided the most consistent behavior for the user is just to kill all error return traces assigned to a mutable `var`.
2022-10-21stage2: Propagate error return trace into fn callCody Tapscott
This change extends the "lifetime" of the error return trace associated with an error to include the duration of a function call it is passed to. This means that if a function returns an error, its return trace will include the error return trace for any error inputs. This is needed to support `testing.expectError` and similar functions. If a function returns a non-error, we have to clean up any error return traces created by error-able call arguments.
2022-10-21stage2: Pop error trace when storing error to var/constCody Tapscott
In order to enforce a strict stack discipline for error return traces, we cannot track error return traces that are stored in variables: ```zig const x = errorable(); // errorable()'s error return trace is killed here // v-- error trace starts here instead return x catch error.UnknownError; ``` In order to propagate error return traces, function calls need to be passed directly to an error-handling expression (`if`, `catch`, `try` or `return`): ```zig // When passed directly to `catch`, the return trace is propagated return errorable() catch error.UnknownError; // Using a break also works return blk: { // code here break :blk errorable(); } catch error.UnknownError; ``` Why do we need this restriction? Without it, multiple errors can co-exist with their own error traces. Handling that situation correctly means either: a. Dynamically allocating trace memory and tracking lifetimes, OR b. Allowing the production of one error to interfere with the trace of another (which is the current status quo) This is piece (3/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21stage2: Do not pop error trace if result is an errorCody Tapscott
This allows for errors to be "re-thrown" by yielding any error as the result of a catch block. For example: ```zig fn errorable() !void { return error.FallingOutOfPlane; } fn foo(have_parachute: bool) !void { return errorable() catch |err| b: { if (have_parachute) { // error trace will include the call to errorable() break :b error.NoParachute; } else { return; } }; } pub fn main() !void { // Anything that returns a non-error does not pollute the error trace. try foo(true); // This error trace will still include errorable(), whose error was "re-thrown" by foo() try foo(false); } ``` This is piece (2/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21stage2: "Pop" error trace for break/return within catchCody Tapscott
This implement trace "popping" for correctly handled errors within `catch { ... }` and `else { ... }` blocks. When breaking from these blocks with any non-error, we pop the error trace frames corresponding to the operand. When breaking with an error, we preserve the frames so that error traces "chain" together as usual. ```zig fn foo(cond1: bool, cond2: bool) !void { bar() catch { if (cond1) { // If baz() result is a non-error, pop the error trace frames from bar() // If baz() result is an error, leave the bar() frames on the error trace return baz(); } else if (cond2) { // If we break/return an error, then leave the error frames from bar() on the error trace return error.Foo; } }; // An error returned from here does not include bar()'s error frames in the trace return error.Bar; } ``` Notice that if foo() does not return an error it, it leaves no extra frames on the error trace. This is piece (1/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-08-24test-stack-traces: restore test coverageAndrew Kelley
reverts 1ce71c86bff351a4ade4321e188a13c9d3cff8b4
2022-08-23std.debug: implement support for DWARFv5Andrew Kelley
2022-08-17libstd: fix off-by-one error in def of ProcSym in pdbJakub Konka
Make sure `ProcSym` includes a single element byte-array which delimits the start of the symbol's name as part of its definition. This makes the code more elegant in that accessing the name is equivalent to taking the address of this one element array.
2022-08-11disable failing stack traces tests on windowsAndrew Kelley
See tracking issue #12422
2022-08-08AstGen: emit debug stmt for tryAndrew Kelley
This improves the following test case: ```zig pub fn main() !void { try foo(); } fn foo() !void { return error.Bad; } ``` The error return trace now points to the `try` token instead of pointing to the foo() function call, matching stage1. Closes #12308.
2021-05-23overhaul elf csu (c-runtime startup) logicMichael Dusan
- more support for linux, android, freebsd, netbsd, openbsd, dragonfly - centralize musl utils; musl logic is no longer intertwined with csu - fix musl compilation to build crti/crtn for full archs list - fix openbsd to support `zig build-lib -dynamic` - initial dragonfly linking success (with a warning) ancillary: - fix emutls (openbsd) tests to use `try`
2021-05-08update usage of std.testing in behavior and standalone testsVeikka Tuominen
2021-04-10test: overhaul stack_trace testingMichael Dusan
- limit expected-output to main source file; ie. tolerate changes to start.zig - when mode != .Debug the function name is now symbolically represented; ie. tolerate changes in llvm optimizer effects on the callstack - cleanup how test cases are specified - add test case predicates for excluding by arch, os or custom fn
2021-04-08update stack trace test cases to new start.zig line offsetsAndrew Kelley
2020-12-18std.crypto.random: introduce fork safetyAndrew Kelley
Everybody gets what they want! * AT_RANDOM is completely ignored. * On Linux, MADV_WIPEONFORK is used to provide fork safety. * On pthread systems, `pthread_atfork` is used to provide fork safety. * For systems that do not have the capability to provide fork safety, the implementation falls back to calling getrandom() every time. * If madvise is unavailable or returns an error, or pthread_atfork fails for whatever reason, it falls back to calling getrandom() every time. * Applications may choose to opt-out of fork safety. * Applications may choose to opt-in to unconditionally calling getrandom() for every call to std.crypto.random.fillFn. * Added `std.meta.globalOption`. * Added `std.os.madvise` and related bits. * Bumped up the size of the main thread TLS buffer. See the comment there for justification. * Simpler hot path in TLS initialization.
2020-12-18update test-stack-traces because start.zig updatedAndrew Kelley
2020-11-25update stack trace test with new start.zig line numberAndrew Kelley
2020-11-23Update stack_traces testLemonBoy
2020-10-28Update stack traces testcasesKoakuma
2020-10-22update stack trace test caseAndrew Kelley
2020-10-19Update the stack-traces testsLemonBoy
2020-10-17fix compilation error when building with io_mode eventedAndrew Kelley
The merge of #5613 introduced a regression when building with io_mode evented, fixed in this commit. closes #6715
2020-10-15fixups regarding windows wide stringsAndrew Kelley
* remove GetModuleHandleA from kernel32.zig. use of A functions considered harmful. * make it a compile error to expose WinMain instead of wWinMain. same thing. * start code declares wWinMainCRTStartup instead of WinMainCRTStartup when it has the choice.
2020-10-15Merge branch '5002-fix-entrypoint-with-winmain' of ↵Andrew Kelley
https://github.com/AnthonyYoManz/zig into AnthonyYoManz-5002-fix-entrypoint-with-winmain
2020-10-12Rename .macosx to .macosVignesh Rajagopalan
2020-09-10update the stack trace test case for lines added to start.zigAndrew Kelley
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-06-15Update Stack Trace For start.zig ChangesDixiE
2020-05-05update docs/tests for async/extern fn removalTadeo Kondrak
2020-03-28std: Minor changes to TLS handlingLemonBoy
* Always allocate an info block per-thread so that libc can store important stuff there. * Respect ABI-mandated alignment in more places. * Nicer code, use slices/pointers instead of raw addresses whenever possible.
2020-03-22disable failing stack trace test for aarch64Andrew Kelley
2020-03-22update stack trace test expected outputAndrew Kelley
2020-03-13update stack traces test expectationsAndrew Kelley
2020-03-03Merge remote-tracking branch 'origin/master' into llvm10Andrew Kelley
2020-02-28improve the "external executor" detection logicAndrew Kelley
2020-02-28update std lib to new Target APIAndrew Kelley
2020-02-26update test expectationsAndrew Kelley
2020-02-23correct test expectationsLemonBoy
2020-02-07codegen: Use the new frame-pointer fn attributesLemonBoy
no-frame-pointer-elim and no-frame-pointer-elim-non-leaf have been deprecated for a while in favour of the newer (and clearer) frame-pointer attribute. Starting with LLVM10 the old attributes are silently ignored, leading to no stack traces in debug mode.
2020-01-21Adjust tests & work around a nasty ICELemonBoy
2019-12-12update stack traces testsAndrew Kelley