Skip to content

Commit 4220b95

Browse files
committed
Resolve debug symbols in containers
For the ELF file itself blazesym does the right thing by reading files like: ``` /proc/2367/map_files/79c8000-20aec000 ``` This works great when the ELF files are in a container in a separate mount namespace. When it comes to looking for split debug info via `debuglink`, it tries looking in by the path in the root mount namespace, which does not work, as the files are just not there. With this change we try checking the process mount namespace first via `/proc/<xxx>/root`. Signed-off-by: Ivan Babrou <[email protected]>
1 parent 0fca873 commit 4220b95

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/maps.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub struct EntryPath {
4646
/// parsed. This path has been sanitized and no longer contains any
4747
/// `(deleted)` suffixes.
4848
pub symbolic_path: PathBuf,
49+
/// The path to the root of the mount namespace through `/proc/<xxx>/root`.
50+
pub root_path: PathBuf,
4951
/// The struct is non-exhaustive and open to extension.
5052
#[doc(hidden)]
5153
pub _non_exhaustive: (),
@@ -211,9 +213,11 @@ pub(crate) fn parse_path_name(
211213
let pid = pid.resolve();
212214
let maps_file =
213215
PathBuf::from(format!("/proc/{pid}/map_files/{vma_start:x}-{vma_end:x}"));
216+
let root_path = PathBuf::from(format!("/proc/{pid}/root"));
214217
Some(PathName::Path(EntryPath {
215218
maps_file,
216219
symbolic_path,
220+
root_path,
217221
_non_exhaustive: (),
218222
}))
219223
}

src/symbolize/symbolizer.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,26 @@ impl SymbolizeHandler<'_> {
534534
}
535535

536536
fn handle_elf_addr(&mut self, addr: Addr, file_off: u64, entry_path: &EntryPath) -> Result<()> {
537+
let debug_dirs = self
538+
.symbolizer
539+
.maybe_debug_dirs(self.debug_syms)
540+
.map(|dirs| {
541+
dirs.iter()
542+
.filter_map(|dir| Some(entry_path.root_path.join(dir.strip_prefix("/").ok()?)))
543+
.chain(dirs.iter().cloned())
544+
.collect::<Vec<_>>()
545+
});
546+
547+
537548
let resolver = if self.map_files {
538-
self.symbolizer.elf_cache.elf_resolver(
539-
entry_path,
540-
self.symbolizer.maybe_debug_dirs(self.debug_syms),
541-
)
549+
self.symbolizer
550+
.elf_cache
551+
.elf_resolver(entry_path, debug_dirs.as_deref())
542552
} else {
543553
let path = &entry_path.symbolic_path;
544554
self.symbolizer
545555
.elf_cache
546-
.elf_resolver(path, self.symbolizer.maybe_debug_dirs(self.debug_syms))
556+
.elf_resolver(path, debug_dirs.as_deref())
547557
}?;
548558

549559

0 commit comments

Comments
 (0)