authorgravatar for xavierb@gmail.comXavier Bouchoux <xavierb@gmail.com> 2024-08-07 08:57:25+02:00
committergravatar for xavierb@gmail.comXavier Bouchoux <xavierb@gmail.com> 2024-08-08 07:28:59+02:00
logcbdf9bf5eee3200efbcf7e1ca65dc93e34f94508
tree9784bb3e508428dfd8b5a5f94fda569dfeb52d09
parent7e966de45e06c42b40f5fd4b862c3d320a21a486

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.

1 files changed, 40 insertions(+), 0 deletions(-)

lib/std/debug/Dwarf.zig+40
......@@ -2215,6 +2215,46 @@ pub const ElfModule = struct {
22152215 return error.MissingDebugInfo;
22162216 }
22172217
2218 // $XDG_CACHE_HOME/debuginfod_client/<buildid>/debuginfo
2219 // This only opportunisticly tries to load from the debuginfod cache, but doesn't try to populate it.
2220 // One can manually run `debuginfod-find debuginfo PATH` to download the symbols
2221 if (build_id) |id| blk: {
2222 var debuginfod_dir: std.fs.Dir = switch (builtin.os.tag) {
2223 .wasi, .windows => break :blk,
2224 else => dir: {
2225 if (std.posix.getenv("DEBUGINFOD_CACHE_PATH")) |path| {
2226 break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
2227 }
2228 if (std.posix.getenv("XDG_CACHE_HOME")) |cache_path| {
2229 const path = std.fs.path.join(gpa, &[_][]const u8{ cache_path, "debuginfod_client" }) catch break :blk;
2230 defer gpa.free(path);
2231 break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
2232 }
2233 if (std.posix.getenv("HOME")) |home_path| {
2234 const path = std.fs.path.join(gpa, &[_][]const u8{ home_path, ".cache", "debuginfod_client" }) catch break :blk;
2235 defer gpa.free(path);
2236 break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
2237 }
2238 break :blk;
2239 },
2240 };
2241 defer debuginfod_dir.close();
2242
2243 const filename = std.fmt.allocPrint(
2244 gpa,
2245 "{s}/debuginfo",
2246 .{std.fmt.fmtSliceHexLower(id)},
2247 ) catch break :blk;
2248 defer gpa.free(filename);
2249
2250 const path: Path = .{
2251 .root_dir = .{ .path = null, .handle = debuginfod_dir },
2252 .sub_path = filename,
2253 };
2254
2255 return loadPath(gpa, path, null, separate_debug_crc, &sections, mapped_mem) catch break :blk;
2256 }
2257
22182258 const global_debug_directories = [_][]const u8{
22192259 "/usr/lib/debug",
22202260 };