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

Use /proc/self/maps when available instead of std::env::current_exe #488

Prev Previous commit
Next Next commit
fix code to work for cargo test --no-default-features .
  • Loading branch information
pnkfelix committed Oct 21, 2022
commit 12f4fbc5161ec51b5bad11b8a695360b89fa388e
10 changes: 6 additions & 4 deletions src/symbolize/gimli/parse_running_mmaps_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,9 @@
// in `mod libs_dl_iterate_phdr` (e.g. linux, freebsd, ...); it may be more
// general purpose, but it hasn't been tested elsewhere.

use super::mystd::io::BufRead;
use super::mystd::fs::File;
use super::mystd::io::{BufRead, BufReader};
use super::mystd::str::FromStr;
use super::{OsString, Vec};

#[derive(PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -53,8 55,8 @@ pub(super) struct MapsEntry {

pub(super) fn parse_maps() -> Result<Vec<MapsEntry>, &'static str> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic only applies to linux I think. Netbsd has /proc/curproc/. macOS doesn't have /proc at all. As for other unixes I'm not quite sure.

Copy link
Member Author

@pnkfelix pnkfelix Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to revise this so that only Linux pulls in the "interesting" parse_maps file, and every other target just goes to the no-op variant.

(I was hoping that I had gotten the logic right such that targets that didn't have the /proc/self/maps pseudo-file, or if it failed to parse said file, it would silently just fall back on std::env::current_exe, but I haven't confirmed that yet.)

Copy link
Member Author

@pnkfelix pnkfelix Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked again, and realized that the sole calling module is solely defined here:

} else if #[cfg(all(
any(
target_os = "linux",
target_os = "fuchsia",
target_os = "freebsd",
target_os = "openbsd",
all(target_os = "android", feature = "dl_iterate_phdr"),
),
not(target_env = "uclibc"),
))] {
mod libs_dl_iterate_phdr;

That makes this a lot easier to limit to just these small subset of targets.

I force-pushed an update that fixes that (and backtraces my API to a simpler one now enabled by removing the parse_running_mmaps_noop.rs code).

let mut v = Vec::new();
let proc_self_maps = std::fs::File::open("/proc/self/maps").map_err(|_| "couldnt open /proc/self/maps")?;
let proc_self_maps = std::io::BufReader::new(proc_self_maps);
let proc_self_maps = File::open("/proc/self/maps").map_err(|_| "couldnt open /proc/self/maps")?;
let proc_self_maps = BufReader::new(proc_self_maps);
for line in proc_self_maps.lines() {
let line = line.map_err(|_io_error| "couldnt read line from /proc/self/maps")?;
v.push(line.parse()?);
Expand All @@ -73,7 75,7 @@ impl MapsEntry {
}
}

impl std::str::FromStr for MapsEntry {
impl FromStr for MapsEntry {
type Err = &'static str;

// Format: address perms offset dev inode pathname
Expand Down