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

Add flag to avoid filtering out native functions #497

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub struct Config {
pub full_filenames: bool,
#[doc(hidden)]
pub lineno: LineNo,
#[doc(hidden)]
pub native_unfiltered: bool,
}

#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -116,7 +118,7 @@ impl Default for Config {
duration: RecordDuration::Unlimited, native: false,
gil_only: false, include_idle: false, include_thread_ids: false,
hide_progress: false, capture_output: true, dump_json: false, dump_locals: 0, subprocesses: false,
full_filenames: false, lineno: LineNo::LastInstruction }
full_filenames: false, lineno: LineNo::LastInstruction, native_unfiltered: false }
}
}

Expand All @@ -143,6 +145,11 @@ impl Config {
.long("native")
.help("Collect stack traces from native extensions written in Cython, C or C++");

#[cfg(unwind)]
let native_unfiltered = Arg::new("native_unfiltered")
.long("native-unfiltered")
.help("Do not filter libpython native functions.");

#[cfg(not(target_os="freebsd"))]
let nonblocking = Arg::new("nonblocking")
.long("nonblocking")
Expand Down Expand Up @@ -265,11 +272,11 @@ impl Config {

// add native unwinding if appropriate
#[cfg(unwind)]
let record = record.arg(native.clone());
let record = record.arg(native.clone()).arg(native_unfiltered.clone());
#[cfg(unwind)]
let top = top.arg(native.clone());
let top = top.arg(native.clone()).arg(native_unfiltered.clone());
#[cfg(unwind)]
let dump = dump.arg(native.clone());
let dump = dump.arg(native.clone()).arg(native_unfiltered.clone());

// Nonblocking isn't an option for freebsd, remove
#[cfg(not(target_os="freebsd"))]
Expand Down Expand Up @@ -350,6 +357,7 @@ impl Config {
config.full_filenames = matches.occurrences_of("full_filenames") > 0;
if cfg!(unwind) {
config.native = matches.occurrences_of("native") > 0;
config.native_unfiltered = matches.occurrences_of("native_unfiltered") > 0;
}

config.capture_output = config.command != "record" || matches.occurrences_of("capture") > 0;
Expand Down
7 changes: 5 additions & 2 deletions src/native_stack_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ pub struct NativeStack {
#[allow(dead_code)]
process: remoteprocess::Process,
symbol_cache: LruCache<u64, remoteprocess::StackFrame>,
native_unfiltered: bool,
}

impl NativeStack {
pub fn new(pid: Pid, python: Option<BinaryInfo>, libpython: Option<BinaryInfo>) -> Result<NativeStack, Error> {
pub fn new(pid: Pid, python: Option<BinaryInfo>, libpython: Option<BinaryInfo>, native_unfiltered: bool) -> Result<NativeStack, Error> {
let cython_maps = cython::SourceMaps::new();

let process = remoteprocess::Process::new(pid)?;
Expand All @@ -36,7 +37,8 @@ impl NativeStack {
python,
libpython,
process,
symbol_cache: LruCache::new(65536)
symbol_cache: LruCache::new(65536),
native_unfiltered: native_unfiltered,
});
}

Expand Down Expand Up @@ -189,6 +191,7 @@ impl NativeStack {
_ => MergeType::Ignore
}
},
_ if self.native_unfiltered => MergeType::MergeNativeFrame,
Some(prefix) if WHITELISTED_PREFIXES.contains(prefix) => MergeType::MergeNativeFrame,
_ => MergeType::Ignore
}
Expand Down
2 changes: 1 addition & 1 deletion src/python_spy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl PythonSpy {

#[cfg(unwind)]
let native = if config.native {
Some(NativeStack::new(pid, python_info.python_binary, python_info.libpython_binary)?)
Some(NativeStack::new(pid, python_info.python_binary, python_info.libpython_binary, config.native_unfiltered)?)
} else {
None
};
Expand Down