Skip to content

Commit

Permalink
Remove unused struct members to fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjcg committed Sep 3, 2024
1 parent 093e3ba commit 3e59996
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 34 deletions.
18 changes: 1 addition & 17 deletions src/binary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ use goblin::Object;
use memmap::Mmap;

pub struct BinaryInfo {
pub filename: std::path::PathBuf,
pub symbols: HashMap<String, u64>,
pub bss_addr: u64,
pub bss_size: u64,
pub offset: u64,
pub addr: u64,
pub size: u64,
}

impl BinaryInfo {
Expand All @@ -24,7 +20,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, size: u64) -> Result<BinaryInfo, Error> {
pub fn parse_binary(filename: &Path, addr: u64) -> Result<BinaryInfo, Error> {
let offset = addr;

let mut symbols = HashMap::new();
Expand Down Expand Up @@ -79,13 +75,9 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
}
}
Ok(BinaryInfo {
filename: filename.to_owned(),
symbols,
bss_addr,
bss_size,
offset,
addr,
size,
})
}

Expand Down Expand Up @@ -137,13 +129,9 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
symbols.insert(name, dynsym.st_value + offset);
}
Ok(BinaryInfo {
filename: filename.to_owned(),
symbols,
bss_addr: bss_header.sh_addr + offset,
bss_size: bss_header.sh_size,
offset,
addr,
size,
})
}
Object::PE(pe) => {
Expand All @@ -169,13 +157,9 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
let bss_size = u64::from(data_section.virtual_size);

BinaryInfo {
filename: filename.to_owned(),
symbols,
bss_addr,
bss_size,
offset,
addr,
size,
}
})
}
Expand Down
5 changes: 2 additions & 3 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 _, map.size() as _);
let python_binary = parse_binary(python_filename, map.start() as _);
info!("Found python binary @ {}", python_filename.display());
(python_filename.to_owned(), python_binary)
};
Expand All @@ -211,8 +211,7 @@ 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, libpython.size() as u64)?;
let parsed = parse_binary(filename, libpython.start() as u64)?;
libpython_binary = Some(parsed);
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/python_process_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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, map.size() as u64);
let python_binary = parse_binary(&filename, map.start() as u64);

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

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

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

// TODO: bss addr offsets returned from parsing binary are wrong
// (assumes data section isn't split from text section like done here).
Expand Down
6 changes: 0 additions & 6 deletions src/python_spy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ pub struct PythonSpy {
pub version: Version,
pub interpreter_address: usize,
pub threadstate_address: usize,
pub python_filename: std::path::PathBuf,
pub version_string: String,
pub config: Config,
#[cfg(feature = "unwind")]
pub native: Option<NativeStack>,
Expand Down Expand Up @@ -68,8 +66,6 @@ impl PythonSpy {
// lets us figure out which thread has the GIL
let threadstate_address = get_threadstate_address(&python_info, &version, config)?;

let version_string = format!("python{}.{}", version.major, version.minor);

#[cfg(feature = "unwind")]
let native = if config.native {
Some(NativeStack::new(
Expand All @@ -87,8 +83,6 @@ impl PythonSpy {
version,
interpreter_address,
threadstate_address,
python_filename: python_info.python_filename,
version_string,
#[cfg(feature = "unwind")]
native,
#[cfg(target_os = "linux")]
Expand Down

0 comments on commit 3e59996

Please sign in to comment.