Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.debug: reorg and clarify API goals #20908

Merged
merged 6 commits into from
Aug 3, 2024
Merged

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Aug 2, 2024

With this changeset:

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 no longer assumes 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. I plan to remove this limitation is a future enhancement.

Unwind tables are emitted more often by default because the logic uses whether dwarf supports unwinding rather than whether the Zig standard library supports unwinding.

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.
@andrewrk andrewrk force-pushed the reorg-std.debug-again branch from 8a88397 to 7e4553c Compare August 2, 2024 05:24
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.
@andrewrk andrewrk force-pushed the reorg-std.debug-again branch from 7e4553c to 48d584e Compare August 2, 2024 06:12
@andrewrk andrewrk added the release notes This PR should be mentioned in the release notes. label Aug 2, 2024
...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.
There are two concepts here: one for whether dwarf supports unwinding on
that target, and another for whether the Zig standard library
implements it yet.
@andrewrk andrewrk force-pushed the reorg-std.debug-again branch from 6240e8b to 6d606cc Compare August 2, 2024 21:15
@andrewrk andrewrk enabled auto-merge August 2, 2024 22:38
@andrewrk andrewrk merged commit a931bfa into master Aug 3, 2024
10 checks passed
@andrewrk andrewrk deleted the reorg-std.debug-again branch August 3, 2024 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes This PR should be mentioned in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant