aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug
diff options
context:
space:
mode:
authorXavier Bouchoux <xavierb@gmail.com>2024-08-07 08:57:25 +0200
committerXavier Bouchoux <xavierb@gmail.com>2024-08-08 07:28:59 +0200
commitcbdf9bf5eee3200efbcf7e1ca65dc93e34f94508 (patch)
tree9784bb3e508428dfd8b5a5f94fda569dfeb52d09 /lib/std/debug
parent7e966de45e06c42b40f5fd4b862c3d320a21a486 (diff)
downloadzig-cbdf9bf5eee3200efbcf7e1ca65dc93e34f94508.tar.gz
zig-cbdf9bf5eee3200efbcf7e1ca65dc93e34f94508.zip
std.debug.Dwarf: try to load the debuginfo from the debuginfod cache.
The previous mecanism for linux distributions to delivers debug info into `/usr/lib/debug` no longer seems in use. the current mecanism often is using `debuginfod` (https://sourceware.org/elfutils/Debuginfod.html) This commit only tries to load already available debuginfo but does not try to make any download requests. the user can manually run `debuginfod-find debuginfo PATH` to populate the cache.
Diffstat (limited to 'lib/std/debug')
-rw-r--r--lib/std/debug/Dwarf.zig40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/std/debug/Dwarf.zig b/lib/std/debug/Dwarf.zig
index eb14b3168d..6bbe43274f 100644
--- a/lib/std/debug/Dwarf.zig
+++ b/lib/std/debug/Dwarf.zig
@@ -2215,6 +2215,46 @@ pub const ElfModule = struct {
return error.MissingDebugInfo;
}
+ // $XDG_CACHE_HOME/debuginfod_client/<buildid>/debuginfo
+ // This only opportunisticly tries to load from the debuginfod cache, but doesn't try to populate it.
+ // One can manually run `debuginfod-find debuginfo PATH` to download the symbols
+ if (build_id) |id| blk: {
+ var debuginfod_dir: std.fs.Dir = switch (builtin.os.tag) {
+ .wasi, .windows => break :blk,
+ else => dir: {
+ if (std.posix.getenv("DEBUGINFOD_CACHE_PATH")) |path| {
+ break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
+ }
+ if (std.posix.getenv("XDG_CACHE_HOME")) |cache_path| {
+ const path = std.fs.path.join(gpa, &[_][]const u8{ cache_path, "debuginfod_client" }) catch break :blk;
+ defer gpa.free(path);
+ break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
+ }
+ if (std.posix.getenv("HOME")) |home_path| {
+ const path = std.fs.path.join(gpa, &[_][]const u8{ home_path, ".cache", "debuginfod_client" }) catch break :blk;
+ defer gpa.free(path);
+ break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
+ }
+ break :blk;
+ },
+ };
+ defer debuginfod_dir.close();
+
+ const filename = std.fmt.allocPrint(
+ gpa,
+ "{s}/debuginfo",
+ .{std.fmt.fmtSliceHexLower(id)},
+ ) catch break :blk;
+ defer gpa.free(filename);
+
+ const path: Path = .{
+ .root_dir = .{ .path = null, .handle = debuginfod_dir },
+ .sub_path = filename,
+ };
+
+ return loadPath(gpa, path, null, separate_debug_crc, &sections, mapped_mem) catch break :blk;
+ }
+
const global_debug_directories = [_][]const u8{
"/usr/lib/debug",
};