Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
benfred committed Nov 1, 2024
1 parent b509256 commit 1553396
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/python_process_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,11 @@ where
P: ProcessMemory,
{
// First check the pyruntime section it was found
info!("getting interpreter addresses from {:#?}", binary);
if binary.pyruntime_addr != 0 {
info!(
"getting interpreter addresses from {:#016x} {}",
binary.pyruntime_addr, binary.pyruntime_size
);
let bss = process.copy(
binary.pyruntime_addr as usize,
binary.pyruntime_size as usize,
Expand All @@ -451,6 +454,7 @@ where
if let Ok(addr) = check_interpreter_addresses(addrs, maps, process, version) {
return Ok(addr);
}
info!("failed to get interpreter address from pyruntime section");
}

// We're going to scan the BSS/data section for things, and try to narrowly scan things that
Expand Down Expand Up @@ -482,7 +486,9 @@ where
P: ProcessMemory,
{
for &addr in addrs {
info!("checking addr {:016x}", addr);
if maps.contains_addr(addr) {
info!(" -> contains addr");
// this address points to valid memory. try loading it up as a PyInterpreterState
// to further check
let interp: I = match process.copy_struct(addr) {
Expand All @@ -494,13 +500,14 @@ where
// a valid pointer then load it up.
let threads = interp.head();
if maps.contains_addr(threads as usize) {
info!(" -> contains threads");
// If the threadstate points back to the interpreter like we expect, then
// this is almost certainly the address of the intrepreter
let thread = match process.copy_pointer(threads) {
Ok(thread) => thread,
Err(_) => continue,
};

info!(" -> pointer matches {}", thread.interp() as usize == addr);
// as a final sanity check, try getting the stack_traces, and only return if this works
if thread.interp() as usize == addr
&& get_stack_traces(&interp, process, 0, None).is_ok()
Expand Down

0 comments on commit 1553396

Please sign in to comment.