aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
AgeCommit message (Collapse)Author
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2022-11-12Make invalidFmtError public and use in place of compileErrors for bad format ↵Nick Cernis
strings (#13526) * Export invalidFmtErr To allow consistent use of "invalid format string" compile error response for badly formatted format strings. See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340. * Replace format compile errors with invalidFmtErr - Provides more consistent compile errors. - Gives user info about the type of the badly formated value. * Rename invalidFmtErr as invalidFmtError For consistency. Zig seems to use “Error” more often than “Err”. * std: add invalid format string checks to remaining custom formatters * pass reference-trace to comp when building build file; fix checkobjectstep
2022-11-04all: rename i386 to x86Ali Chraghi
2022-10-25cbe: get enough things working to support basic programsJacob Young
* Enable advanced start support. * Enable advanced test_runner support. * Zig Language Reference's Hello World now works.
2022-10-21builtin.zig: Do not overwrite error frames when trace fullCody Tapscott
Previously, we'd overwrite the errors in a circular buffer. Now that error return traces are intended to follow a stack discipline, we no longer have to support the index rolling over. By treating the trace like a saturating stack, any pop/restore code still behaves correctly past-the-end of the trace. As a bonus, this adds a small blurb to let the user know when the trace saturated and x number of frames were dropped.
2022-10-20Revert "add std.debug.todo"Andrew Kelley
This reverts commit 80ac022c4667e1995ccdf70fff90e5af26b6eb97. I changed my mind on this one, sorry. I don't think this belongs in the standard library.
2022-10-18all: rename `@maximum` to `@max` and `@minimum` to `@min`Ali Chraghi
2022-10-18std.debug: define error set in DebugInfo.lookupModuleDlMeghan
2022-10-18std: check for overflow in dumpStackTraceFromBaseXavier Bouchoux
same change as [68e26a2ceea85a1] "std: check for overflow in writeCurrentStackTrace" On arm64 macOS, the address of the last frame is 0x0 rather than a positive value like 0x1 on x86_64 macOS, therefore, we overflow an integer trying to subtract 1 when printing the stack trace. This patch fixes it by first checking for this condition before trying to subtract 1. Same behaviour on i386-windows-msvc. Note that we do not need to signal the `SignalIterator` about this as it will correctly detect this condition on the subsequent iteration and return `null`, thus terminating the loop.
2022-09-20std: add return address parameter to panic fnVeikka Tuominen
2022-08-23std.debug: DWARFv5 fixesAndrew Kelley
handle str_offsets_base and addr_base correctly. handle data16 fix compilation on 32-bit hosts remove stray debug print statement closes #12120
2022-08-23coff: fix compile errors in std.debugJakub Konka
2022-08-23macho: fix compile errors in std.debugJakub Konka
2022-08-23std.debug: implement support for DWARFv5Andrew Kelley
2022-08-23coff: improve default COFF/PE object parserJakub Konka
We now do not allocate memory for headers and other metadata unless requested by the caller. Instead, we read-in the entire contents of the image into memory and operate on pointers and casts wherever possible. I have a left a TODO to hook up Windows' memory-mapped API here in-place of standard `readToEndAlloc` which should be more memory proof on memory constrained hosts. This commit also supplements our `std.coff` with a lot missing basic extern structs required to make our COFF linker.
2022-08-22Windows: Fix incorrect output when .pdb file is not found during stack traceRyan Liptak
This `pdb.Pdb.init` call can return `error.FileNotFound`, which was previously resulting in: Unable to print stack trace: FileNotFound which also aborts the stack trace printing (so any deeper stack traces are not printed). It makes more sense to treat it as `MissingDebugInfo` which then gets printed as: ???:?:?: 0x7fffa8817033 in ??? (???) and allows the stack trace to continue printing. Note: locally, the error.FileNotFound was being triggered for me when looking for kernel32.pdb and ntdll.pdb
2022-08-22Dwarf: Added stroffsetsptr support (#12270)Keith Chambers
* Added support for stroffsetsptr class in Dwarf stdlib * Proper initializion of debug_str_offsets in DwarfInfo * Added missing null initializer to DwarfInfo in Macho * Added missing is_64 field to getAttrString in DwarfInfo * Fixed formatting * Added missing is_64 param to getAttrString * Added required cast to usize * Adding missing .debug_str_offsets initialization * getAttrString now uses the str_offsets_base attr
2022-08-16AstGen: detect declarations shadowing localsVeikka Tuominen
Closes #9355
2022-08-11std: fix definition of SIG_IGN, SIG_DFL, etc.Isaac Freund
POSIX specifies that the sa_handler field of the sigaction struct may be set to SIG_IGN or SIG_DFL. However, the current constants in the standard library use the function pointer signature corresponding to the sa_sigaction field instead. This may not cause issues in practice because the fields usually occupy the same memory in a union, but this isn't required by POSIX and there may be systems we do not yet support that do this differently. Fixing this also makes the Zig interface less confusing to use after reading the man page.
2022-08-06std: use std.macho.LoadCommandIterator for MachO parsing in std.debugJakub Konka
2022-07-29std.debug: default signal handler also handles SIGFPEAndrew Kelley
2022-06-28Merge pull request #11919 from squeek502/failing-allocator-stacktraceAndrew Kelley
Add stack trace capturing to `FailingAllocator` and use it to improve `checkAllAllocationFailures`
2022-06-27Fix stack traces with non-null `first_address` on WindowsRyan Liptak
Before this commit, the passed in length would always be given to the RtlCaptureStackBackTrace call. Now we always give the length of the actual buffer we're using (the addr_buf_stack size of 32 or the passed in length if it's larger than 32; this matches what the doc comment says the function was meant to be doing as well). This was causing empty stack traces for things like the GeneralPurposeAllocator leak checking. Fixes #6687
2022-06-25Move sys_can_stack_trace from GPA to std.debug so that it can be re-used as ↵Ryan Liptak
needed
2022-06-23std.debug: fix ConfigurableTrace.dump OOBFlandreScarlet
The for-loop in dump() would index out of bounds if `t.index` is greater than size, because `end` is the maximum of `t.index` and `size` rather than the minimum.
2022-06-12add std.debug.Trace.formatAndrew Kelley
This makes it show up in some useful places; for example in the self-hosted compiler we already print it now with --debug-compile-errors.
2022-06-09std.debug.Trace: improve APIAndrew Kelley
Now `std.debug.Trace` is a concrete type with pre-chosen defaults. `std.debug.ConfigurableTrace` can be used for more advanced cases.
2022-06-09introduce std.debug.TraceAndrew Kelley
And use it to debug a LazySrcLoc in stage2 that is set to a bogus value. The actual fix in this commit is: ```diff - try sema.emitBackwardBranch(&child_block, call_src); + try sema.emitBackwardBranch(block, call_src); ```
2022-05-27math: make `cast` return optional instead of an errorAli Chraghi
2022-05-24stage2: fixes for error union semanticsAndrew Kelley
* Sema: avoid unnecessary safety checks when an error set is empty. * Sema: make zirErrorToInt handle comptime errors that are represented as integers. * Sema: make empty error sets properly integrate with typeHasOnePossibleValue. * Type: correct the ABI alignment and size of error unions which have both zero-bit error set and zero-bit payload. The previous code did not account for the fact that we still need to store a bit for whether there is an error. * LLVM: lower error unions possibly with the payload first or with the error code first, depending on alignment. Previously it always put the error code first and used a padding array. * LLVM: lower functions which have an empty error set as the return type the same as anyerror, so that they can be used where fn()anyerror function pointers are expected. In such functions, Zig will lower ret to returning zero instead of void. As a result, one more behavior test is passing.
2022-05-13target: Rename sparcv9 -> sparc64Koakuma
Rename all references of sparcv9 to sparc64, to make Zig align more with other projects. Also, added new function to convert glibc arch name to Zig arch name, since it refers to the architecture as sparcv9. This is based on the suggestion by @kubkon in PR 11847. (https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-04std: Single-threaded `panicImpl` sleep is unreachable (#11569)Jay Petacat
Adding `unreachable` prevents the futex code from being inspected during a single-threaded build. Without futex, first draft BYOS packages don't need to implement `nanosleep` to get a single-threaded "hello world" program working. Use of `assert()` did not achieve the desired effect of avoiding futex in a single-threaded build.
2022-04-26std.Thread: ResetEvent improvements (#11523)protty
* std: start removing redundant ResetEvents * src: fix other uses of std.Thread.ResetEvent * src: add builtin.sanitize_thread for tsan detection * atomic: add Atomic.fence for proper fencing with tsan * Thread: remove the other ResetEvent's and rewrite the current one * Thread: ResetEvent docs * zig fmt + WaitGroup.reset() fix * src: fix build issues for ResetEvent + tsan * Thread: ResetEvent tests * Thread: ResetEvent module doc * Atomic: replace llvm *p memory constraint with *m * panicking: handle spurious wakeups in futex.wait() when waiting for abort() * zig fmt
2022-04-21debug: add smoke testJakub Konka
2022-04-21debug: fix resource (de)allocation for Elf and Coff targetsJakub Konka
With this change, it is now possible to safely call `var di = std.debug.openSelfDebugInfo(gpa)`. Calling then `di.deinit()` on the object will correctly free all allocated resources. Ensure we store the result of `mmap` with correct alignment.
2022-04-21debug: fix resource (de)allocation for MachO targetsJakub Konka
With this change, it is now possible to safely call `var di = std.debug.openSelfDebugInfo(gpa)`. Calling then `di.deinit()` on the object will correctly free all allocated resources.
2022-04-21dwarf: clean up allocations in std.dwarf moduleJakub Konka
While this code probably could do with some love and a redesign, this commit fixes the allocations by making sure we explicitly pass an allocator where required, and we use arenas for temporary or narrowly-scoped objects such as a `Die` (for `Die` in particular, not every `FormValue` will be allocated - we could duplicate, or we can use an arena which is the proposal of this commit).
2022-04-19wasm: Fix unreachable pathsLuuk de Gram
When the last instruction is a debug instruction, the type of it is void. Similarly for 'noreturn' emit an 'unreachable' instruction to tell the wasm-validator the path cannot be reached. Also respect the '--strip' flag in the self-hosted wasm linker and not emit a 'name' section when the flag is set to `true`.
2022-04-18wasm: Add support for debug infoLuuk de Gram
This implements basic DWARF output when building for the wasm target. Stacktraces, however, are currently not supported.
2022-04-04Pull elf magic string out to re-used constantTom Read Cutting
2022-03-19Merge pull request #11228 from Vexu/panicAndrew Kelley
enable default panic handler for stage2 LLVM
2022-03-19fix sigaction double paniczseri
Fixes #8357
2022-03-19std: enable default panic handler for stage2 LLVM on LinuxVeikka Tuominen
2022-03-17debug: msync only current page when validation frame pointerJakub Konka
This fixes lack of stack traces on arm64 macOS which were regressed and not getting generated at all after this addition to write current stack traces. Prior to this, function `isValidMemory` would sync two subsequent pages if the aligned (base) address was different than the frame pointer. I fail to see what the logic for such assumption here is as the manual of `msync` clearly states it will fail with error if the passed in memory region length contains unmapped regions. This was the very reason why there were no stack traces print on arm64 macOS as the second page was unmapped thus incorrectly flagging the frame pointer as invalid.
2022-03-15std.dwarf: implement basic DWARF 5 parsingWilliam Sengir
DWARF 5 moves around some fields and adds a few new ones that can't be parsed or ignored by our current DWARF 4 parser. This isn't a complete implementation of DWARF 5, but this is enough to make stack traces mostly work. Line numbers from C++ don't show up, but I know the info is there. I think the answer is to iterate through .debug_line_str in getLineNumberInfo, but I didn't want to fall into an even deeper rabbit hole tonight.
2022-03-12stage2 llvm: do not use getIntrinsic for airFrameAddressVeikka Tuominen
getIntrinsic gets the return type wrong so we have to add the function manually
2022-02-19StackIterator should not try to check validity on freestandingLee Cannon
2022-02-11validate in Windows using VirtualQuerym
2022-02-11std: validate frame-pointer address in stack walkingm
2022-02-07debug: implement segfault handler for macOS aarch64John Schmidt
Tested on a M1 MacBook Pro, macOS Monterey 12.2.