Skip to content

Commit dac3c09

Browse files
authored
Fix symbol mapping issue when we have multiple executable segments (#765)
1 parent 9ab9703 commit dac3c09

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/python_process_info.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,37 @@ impl PythonProcessInfo {
143143

144144
// likewise handle libpython for python versions compiled with --enabled-shared
145145
let libpython_binary = {
146-
let libmap = maps.iter().find(|m| {
147-
if let Some(pathname) = m.filename() {
148-
if let Some(pathname) = pathname.to_str() {
149-
#[cfg(not(windows))]
150-
{
151-
return is_python_lib(pathname) && m.is_exec();
152-
}
153-
#[cfg(windows)]
154-
{
155-
return is_python_lib(pathname);
146+
let libmaps: Vec<_> = maps
147+
.iter()
148+
.filter(|m| {
149+
if let Some(pathname) = m.filename() {
150+
if let Some(pathname) = pathname.to_str() {
151+
#[cfg(not(windows))]
152+
{
153+
return is_python_lib(pathname) && m.is_exec();
154+
}
155+
#[cfg(windows)]
156+
{
157+
return is_python_lib(pathname);
158+
}
156159
}
157160
}
158-
}
159-
false
160-
});
161+
false
162+
})
163+
.collect();
161164

162165
let mut libpython_binary: Option<BinaryInfo> = None;
163-
if let Some(libpython) = libmap {
166+
167+
#[cfg(not(target_os = "linux"))]
168+
let libpython_option = if !libmaps.is_empty() {
169+
Some(&libmaps[0])
170+
} else {
171+
None
172+
};
173+
#[cfg(target_os = "linux")]
174+
let libpython_option = libmaps.iter().min_by_key(|m| m.offset);
175+
176+
if let Some(libpython) = libpython_option {
164177
if let Some(filename) = &libpython.filename() {
165178
info!("Found libpython binary @ {}", filename.display());
166179

0 commit comments

Comments
 (0)