Skip to content

Commit

Permalink
Fix bug introduced by commit 5820bf6 (#688)
Browse files Browse the repository at this point in the history
Commit 5820bf6 removes field `addr` and
`size` from BinaryInfo, which are used when feature `unwind` is enabled.
So recover these two fields.

Fix building error:
cargo build --all-features
error[E0609]: no field `addr` on type `&BinaryInfo`
  --> src/binary_parser.rs:18:22
   |
18 |         addr >= self.addr && addr < (self.addr + self.size)
   |                      ^^^^ unknown field
   |
   = note: available fields are: `symbols`, `bss_addr`, `bss_size`

error[E0609]: no field `addr` on type `&BinaryInfo`
  --> src/binary_parser.rs:18:43
   |
18 |         addr >= self.addr && addr < (self.addr + self.size)
   |                                           ^^^^ unknown field
   |
   = note: available fields are: `symbols`, `bss_addr`, `bss_size`

error[E0609]: no field `size` on type `&BinaryInfo`
  --> src/binary_parser.rs:18:55
   |
18 |         addr >= self.addr && addr < (self.addr + self.size)
   |                                                       ^^^^ unknown field
   |
   = note: available fields are: `symbols`, `bss_addr`, `bss_size`

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu authored Oct 11, 2024
1 parent cd165c8 commit c9e422b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/binary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub struct BinaryInfo {
pub symbols: HashMap<String, u64>,
pub bss_addr: u64,
pub bss_size: u64,
#[allow(dead_code)]
pub addr: u64,
#[allow(dead_code)]
pub size: u64,
}

impl BinaryInfo {
Expand All @@ -20,7 +24,7 @@ impl BinaryInfo {
}

/// Uses goblin to parse a binary file, returns information on symbols/bss/adjusted offset etc
pub fn parse_binary(filename: &Path, addr: u64) -> Result<BinaryInfo, Error> {
pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo, Error> {
let offset = addr;

let mut symbols = HashMap::new();
Expand Down Expand Up @@ -78,6 +82,8 @@ pub fn parse_binary(filename: &Path, addr: u64) -> Result<BinaryInfo, Error> {
symbols,
bss_addr,
bss_size,
addr,
size,
})
}

Expand Down Expand Up @@ -132,6 +138,8 @@ pub fn parse_binary(filename: &Path, addr: u64) -> Result<BinaryInfo, Error> {
symbols,
bss_addr: bss_header.sh_addr + offset,
bss_size: bss_header.sh_size,
addr,
size,
})
}
Object::PE(pe) => {
Expand Down Expand Up @@ -160,6 +168,8 @@ pub fn parse_binary(filename: &Path, addr: u64) -> Result<BinaryInfo, Error> {
symbols,
bss_addr,
bss_size,
addr,
size,
}
})
}
Expand Down
5 changes: 3 additions & 2 deletions src/coredump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl PythonCoreDump {
.find(|m| m.filename().is_some() & m.is_exec())
.ok_or_else(|| format_err!("Failed to get binary from coredump"))?;
let python_filename = map.filename().unwrap();
let python_binary = parse_binary(python_filename, map.start() as _);
let python_binary = parse_binary(python_filename, map.start() as _, map.size() as _);
info!("Found python binary @ {}", python_filename.display());
(python_filename.to_owned(), python_binary)
};
Expand All @@ -211,7 +211,8 @@ impl PythonCoreDump {
if let Some(libpython) = libmap {
if let Some(filename) = &libpython.filename() {
info!("Found libpython binary @ {}", filename.display());
let parsed = parse_binary(filename, libpython.start() as u64)?;
let parsed =
parse_binary(filename, libpython.start() as u64, libpython.size() as u64)?;
libpython_binary = Some(parsed);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/python_process_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl PythonProcessInfo {
let filename = std::path::PathBuf::from(format!("/proc/{}/exe", process.pid));

// TODO: consistent types? u64 -> usize? for map.start etc
let python_binary = parse_binary(&filename, map.start() as u64);
let python_binary = parse_binary(&filename, map.start() as u64, map.size() as u64);

// windows symbols are stored in separate files (.pdb), load
#[cfg(windows)]
Expand Down Expand Up @@ -158,7 +158,8 @@ impl PythonProcessInfo {
));

#[allow(unused_mut)]
let mut parsed = parse_binary(filename, libpython.start() as u64)?;
let mut parsed =
parse_binary(filename, libpython.start() as u64, libpython.size() as u64)?;
#[cfg(windows)]
parsed.symbols.extend(get_windows_python_symbols(
process.pid,
Expand Down Expand Up @@ -204,8 +205,11 @@ impl PythonProcessInfo {
libpython.filename.display()
);

let mut binary =
parse_binary(&libpython.filename, libpython.segment.vmaddr)?;
let mut binary = parse_binary(
&libpython.filename,
libpython.segment.vmaddr,
libpython.segment.vmsize,
)?;

// TODO: bss addr offsets returned from parsing binary are wrong
// (assumes data section isn't split from text section like done here).
Expand Down

0 comments on commit c9e422b

Please sign in to comment.