Skip to content

Commit

Permalink
Move create_apk_elf_path() into symbolize module
Browse files Browse the repository at this point in the history
With the rework of the normalization APIs a while back, the
create_apk_elf_path() function is no longer used by the normalization
code itself -- yet it is defined in there.
Move it over into the symbolize module, where it is actually used.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Nov 14, 2023
1 parent 1290c56 commit b00c17c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/normalize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ pub use normalizer::Normalizer;
pub use normalizer::Output;
pub use user::UserOutput;

pub(crate) use user::create_apk_elf_path;
pub(crate) use user::normalize_sorted_user_addrs_with_entries;
pub(crate) use user::Handler;
32 changes: 0 additions & 32 deletions src/normalize/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ use super::meta::UserMeta;
use super::normalizer::Output;


pub(crate) fn create_apk_elf_path(apk: &Path, elf: &Path) -> Result<PathBuf> {
let mut extension = apk
.extension()
.unwrap_or_else(|| OsStr::new("apk"))
.to_os_string();
// Append '!' to indicate separation from archive internal contents
// that follow. This is an Android convention.
let () = extension.push("!");

let mut apk = apk.to_path_buf();
if !apk.set_extension(extension) {
return Err(Error::new(
ErrorKind::InvalidInput,
format!("path {} is not valid", apk.display()),
)
.into())
}

let path = apk.join(elf);
Ok(path)
}


/// Make a [`UserMeta::Elf`] variant.
fn make_elf_meta(entry: &PathMapsEntry, get_build_id: &BuildIdFn) -> Result<UserMeta> {
let elf = Elf {
Expand Down Expand Up @@ -310,15 +287,6 @@ mod tests {
use test_log::test;


/// Check that we can create a path to an ELF inside an APK as expected.
#[test]
fn elf_apk_path_creation() {
let apk = Path::new("/root/test.apk");
let elf = Path::new("subdir/libc.so");
let path = create_apk_elf_path(apk, elf).unwrap();
assert_eq!(path, Path::new("/root/test.apk!/subdir/libc.so"));
}

/// Check that we correctly handle normalization of an address not
/// in any executable segment.
#[test]
Expand Down
33 changes: 32 additions & 1 deletion src/symbolize/symbolizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fs::File;
use std::ops::Deref as _;
use std::ops::Range;
use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;

#[cfg(feature = "dwarf")]
Expand All @@ -24,7 +25,6 @@ use crate::maps;
use crate::maps::PathMapsEntry;
use crate::mmap::Mmap;
use crate::normalize;
use crate::normalize::create_apk_elf_path;
use crate::normalize::normalize_sorted_user_addrs_with_entries;
use crate::normalize::Handler as _;
use crate::util;
Expand Down Expand Up @@ -55,6 +55,28 @@ use super::Sym;
use super::Symbolized;


fn create_apk_elf_path(apk: &Path, elf: &Path) -> Result<PathBuf> {
let mut extension = apk
.extension()
.unwrap_or_else(|| OsStr::new("apk"))
.to_os_string();
// Append '!' to indicate separation from archive internal contents
// that follow. This is an Android convention.
let () = extension.push("!");

let mut apk = apk.to_path_buf();
if !apk.set_extension(extension) {
return Err(Error::with_invalid_data(format!(
"path {} is not valid",
apk.display()
)))
}

let path = apk.join(elf);
Ok(path)
}


/// Demangle a symbol name using the demangling scheme for the given language.
#[cfg(feature = "demangle")]
fn maybe_demangle(name: Cow<'_, str>, language: SrcLang) -> Cow<'_, str> {
Expand Down Expand Up @@ -984,6 +1006,15 @@ mod tests {
assert_ne!(format!("{symbolizer:?}"), "");
}

/// Check that we can create a path to an ELF inside an APK as expected.
#[test]
fn elf_apk_path_creation() {
let apk = Path::new("/root/test.apk");
let elf = Path::new("subdir/libc.so");
let path = create_apk_elf_path(apk, elf).unwrap();
assert_eq!(path, Path::new("/root/test.apk!/subdir/libc.so"));
}

/// Check that we can correctly construct the source code path to a symbol.
#[test]
fn symbol_source_code_path() {
Expand Down

0 comments on commit b00c17c

Please sign in to comment.