authorgravatar for jari.vetoniemi@cloudef.pwJari Vetoniemi <jari.vetoniemi@cloudef.pw> 2026-06-05 08:35:05+09:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-17 23:17:01+02:00
log7255f3e724d7f889c32c65481b27110ef48f077d
tree506188c2c9031a16feff907dd279a9a3cc1889e8
parenteedf7d92990676922ddbf1d2928d3d2a4d2e7487

std.debug: add TargetInfo function which returns the default SelfInfo

If one overrides `SelfInfo` in their `root.debug`, it is no longer possible to refer to the default `SelfInfo` that the std.debug uses. This allows the developer to still refer to the std's default without copying the SelfInfo zig files to their project.

1 files changed, 16 insertions(+), 10 deletions(-)

lib/std/debug.zig+16-10
...@@ -63,16 +63,22 @@ pub const cpu_context = @import("debug/cpu_context.zig");...@@ -63,16 +63,22 @@ pub const cpu_context = @import("debug/cpu_context.zig");
63/// ```63/// ```
64pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfInfo"))64pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfInfo"))
65 root.debug.SelfInfo65 root.debug.SelfInfo
66else switch (std.Target.ObjectFormat.default(native_os, native_arch)) {66else
67 .coff => if (native_os == .windows) @import("debug/SelfInfo/Windows.zig") else void,67 TargetInfo(native_os, native_arch);
68 .elf => switch (native_os) {68
69 .freestanding, .other => void,69/// Returns the default `SelfInfo` for the given `os` and `arch`.
70 else => @import("debug/SelfInfo/Elf.zig"),70pub fn TargetInfo(os: std.Target.Os.Tag, arch: std.Target.Cpu.Arch) type {
71 },71 return switch (std.Target.ObjectFormat.default(os, arch)) {
72 .macho => @import("debug/SelfInfo/MachO.zig"),72 .coff => if (os == .windows) @import("debug/SelfInfo/Windows.zig") else void,
73 .plan9, .spirv, .wasm => void,73 .elf => switch (os) {
74 .c, .hex, .raw => unreachable,74 .freestanding, .other => void,
75};75 else => @import("debug/SelfInfo/Elf.zig"),
76 },
77 .macho => @import("debug/SelfInfo/MachO.zig"),
78 .plan9, .spirv, .wasm => void,
79 .c, .hex, .raw => unreachable,
80 };
81}
7682
77pub const SelfInfoError = error{83pub const SelfInfoError = error{
78 /// The required debug info is invalid or corrupted.84 /// The required debug info is invalid or corrupted.