Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(win, python >= 3.10) Fix symbol address resolution #672

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 36 additions & 97 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ serde_derive = "1.0"
serde_json = "1.0"
rand = "0.8"
rand_distr = "0.4"
remoteprocess = {version="0.4.12", features=["unwind"]}
remoteprocess = { git = "https://github.com/akhramov/remoteprocess", branch = "feature/windows-aarch64", features = ["unwind"] }
chrono = "0.4.26"
cfg-if = "1.0.0"

[dev-dependencies]
py-spy-testdata = "0.1.0"
Expand Down
5 changes: 2 additions & 3 deletions src/binary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Error;
use goblin::Object;
use memmap::Mmap;

#[allow(dead_code)]
pub struct BinaryInfo {
pub filename: std::path::PathBuf,
pub symbols: HashMap<String, u64>,
Expand Down Expand Up @@ -149,9 +150,7 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
Object::PE(pe) => {
for export in pe.exports {
if let Some(name) = export.name {
if let Some(export_offset) = export.offset {
symbols.insert(name.to_string(), export_offset as u64 + offset);
}
symbols.insert(name.to_string(), export.rva as u64 + offset);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl Config {
}

config.subprocesses = matches.occurrences_of("subprocesses") > 0;
config.command = subcommand.to_owned();
subcommand.clone_into(&mut config.command);

// options that can be shared between subcommands
config.pid = matches
Expand Down
2 changes: 1 addition & 1 deletion src/cython.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl SourceMaps {
if let Some(map) = self.maps.get(&frame.filename) {
if let Some(map) = map {
if let Some((file, line)) = map.lookup(line) {
frame.filename = file.clone();
frame.filename.clone_from(file);
frame.line = *line as i32;
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/python_process_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,17 @@ impl PythonProcessInfo {
let libmap = maps.iter().find(|m| {
if let Some(pathname) = m.filename() {
if let Some(pathname) = pathname.to_str() {
return is_python_lib(pathname) && m.is_exec();
cfg_if::cfg_if! {
if #[cfg(windows)] {
// On windows we use utilize RVA (relative
// virtual addresses), so we need to know just
// the base address.
return is_python_lib(pathname);
} else {
return is_python_lib(pathname) && m.is_exec();
}

};
}
}
false
Expand Down Expand Up @@ -603,7 +613,7 @@ pub trait ContainsAddr {

impl ContainsAddr for Vec<MapRange> {
#[cfg(windows)]
fn contains_addr(&self, addr: usize) -> bool {
fn contains_addr(&self, _addr: usize) -> bool {
// On windows, we can't just check if a pointer is valid by looking to see if it points
// to something in the virtual memory map. Brute-force it instead
true
Expand Down
3 changes: 1 addition & 2 deletions src/python_spy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(windows)]
use regex::RegexBuilder;
use std::collections::HashMap;
#[cfg(all(target_os = "linux", unwind))]
use std::collections::HashSet;
Expand All @@ -26,6 +24,7 @@ use crate::stack_trace::{get_gil_threadid, get_stack_trace, StackTrace};
use crate::version::Version;

/// Lets you retrieve stack traces of a running python program
#[allow(dead_code)]
pub struct PythonSpy {
pub pid: Pid,
pub process: Process,
Expand Down
2 changes: 1 addition & 1 deletion src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Sampler {
let process = process_info
.entry(pid)
.or_insert_with(|| get_process_info(pid, &spies).map(|p| Arc::new(*p)));
trace.process_info = process.clone();
trace.process_info.clone_from(process);
}

// Send the collected info back
Expand Down
Loading