| ... | ... | @@ -2215,6 +2215,46 @@ pub const ElfModule = struct { |
| 2215 | 2215 | return error.MissingDebugInfo; |
| 2216 | 2216 | } |
| 2217 | 2217 | |
| 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 | |
| 2218 | 2258 | const global_debug_directories = [_][]const u8{ |
| 2219 | 2259 | "/usr/lib/debug", |
| 2220 | 2260 | }; |