Skip to content

Commit

Permalink
uprade crate dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Wen <[email protected]>
  • Loading branch information
yan-ace62 authored and anakryiko committed May 22, 2023
1 parent 30003e4 commit 61e3ea6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ name = "btf"
path = "src/main.rs"

[dependencies]
structopt = "0.2"
goblin = "0.0.20"
object = "0.11.0"
structopt = "0.3"
goblin = "0.6.1"
object = "0.31.1"
memmap = "0.7.0"
scroll = "0.9.2"
scroll_derive = "0.9.5"
scroll = "0.11.0"
scroll_derive = "0.11.0"
regex = "1"
lazy_static = "1"
bitflags = "1"
bitflags = "2"

[dependencies.clap]
version = "2.32"
version = "4.3"
features = ["wrap_help"]
39 changes: 14 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ bitflags! {
const LINEINFOS = 0b0100;
const RELOCS = 0b1000;

const DEFAULT = Self::TYPES.bits | Self::RELOCS.bits;
const EXT = Self::FUNCINFOS.bits | Self::LINEINFOS.bits | Self::RELOCS.bits;
const ALL = Self::TYPES.bits | Self::EXT.bits;
const DEFAULT = Self::TYPES.bits() | Self::RELOCS.bits();
const EXT = Self::FUNCINFOS.bits() | Self::LINEINFOS.bits() | Self::RELOCS.bits();
const ALL = Self::TYPES.bits() | Self::EXT.bits();
}
}

Expand Down Expand Up @@ -87,15 +87,10 @@ struct QueryArgs {
#[structopt(short = "n", long = "name")]
/// Regex of type names to include
name: Option<String>,
#[structopt(
short = "t",
long = "type",
parse(try_from_str),
raw(use_delimiter = "true")
)]
#[structopt(short = "t", long = "type", parse(try_from_str), use_delimiter = true)]
/// BTF type kinds to include
kinds: Vec<BtfKind>,
#[structopt(long = "id", parse(try_from_str), raw(use_delimiter = "true"))]
#[structopt(long = "id", parse(try_from_str), use_delimiter = true)]
/// Type IDs to include
ids: Vec<u32>,
}
Expand All @@ -113,21 +108,15 @@ enum Cmd {
short = "f",
long = "format",
default_value = "human",
raw(
possible_values = r#"&["human", "h", "c", "json", "j", "json-pretty", "jp"]"#,
next_line_help = "true"
)
possible_values = &["human", "h", "c", "json", "j", "json-pretty", "jp"],
)]
/// Output format
format: DumpFormat,
#[structopt(
short = "d",
long = "dataset",
default_value = "default",
raw(
possible_values = r#"&["default", "def", "d", "types", "type", "t", "funcs", "func", "f", "lines", "line", "l", "relocs", "reloc", "r", "all", "a", "exts", "ext", "none"]"#,
next_line_help = "true"
)
possible_values = &["default", "def", "d", "types", "type", "t", "funcs", "func", "f", "lines", "line", "l", "relocs", "reloc", "r", "all", "a", "exts", "ext", "none"],
)]
/// Datasets to output
datasets: Datasets,
Expand Down Expand Up @@ -175,7 +164,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} => {
let file = std::fs::File::open(&file)?;
let file = unsafe { memmap::Mmap::map(&file) }?;
let file = object::ElfFile::parse(&*file)?;
let file = object::File::parse(&*file)?;
let btf = Btf::load(&file)?;
let filter = create_query_filter(query)?;

Expand Down Expand Up @@ -238,7 +227,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} => {
let local_file = std::fs::File::open(&local_file)?;
let local_mmap = unsafe { memmap::Mmap::map(&local_file) }?;
let local_elf = object::ElfFile::parse(&*local_mmap)?;
let local_elf = object::File::parse(&*local_mmap)?;
let local_btf = Btf::load(&local_elf)?;
if !local_btf.has_ext() {
return btf_error(format!(
Expand All @@ -248,7 +237,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
let targ_file = std::fs::File::open(&targ_file)?;
let targ_mmap = unsafe { memmap::Mmap::map(&targ_file) }?;
let targ_elf = object::ElfFile::parse(&*targ_mmap)?;
let targ_elf = object::File::parse(&*targ_mmap)?;
let targ_btf = Btf::load(&targ_elf)?;
let cfg = RelocatorCfg { verbose: verbose };
let mut relocator = Relocator::new(&targ_btf, &local_btf, cfg);
Expand All @@ -260,7 +249,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Cmd::Stat { file } => {
let file = std::fs::File::open(&file)?;
let file = unsafe { memmap::Mmap::map(&file) }?;
let file = object::ElfFile::parse(&*file)?;
let file = object::File::parse(&*file)?;
stat_btf(&file)?;
}
}
Expand Down Expand Up @@ -301,14 +290,14 @@ fn create_query_filter(q: QueryArgs) -> BtfResult<Box<dyn Fn(u32, &BtfType) -> b
}
}

fn stat_btf(elf: &object::ElfFile) -> BtfResult<()> {
fn stat_btf(elf: &object::File) -> BtfResult<()> {
let endian = if elf.is_little_endian() {
scroll::LE
} else {
scroll::BE
};
if let Some(btf_section) = elf.section_by_name(BTF_ELF_SEC) {
let data = btf_section.data();
let data = btf_section.data()?;
let hdr = data.pread_with::<btf_header>(0, endian)?;
println!(
"{} ELF section\n=======================================",
Expand All @@ -327,7 +316,7 @@ fn stat_btf(elf: &object::ElfFile) -> BtfResult<()> {
BTF_EXT_ELF_SEC
);
if let Some(ext_section) = elf.section_by_name(BTF_EXT_ELF_SEC) {
let ext_data = ext_section.data();
let ext_data = ext_section.data()?;
let ext_hdr = ext_data.pread_with::<btf_ext_header_v1>(0, endian)?;
println!("Data size:\t{}", ext_data.len());
println!("Header size:\t{}", ext_hdr.hdr_len);
Expand Down
9 changes: 4 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::cmp::{max, min};
use std::ffi::{c_char, CStr};
use std::fmt;
Expand Down Expand Up @@ -1032,15 +1031,15 @@ impl<'a> Btf<'a> {
}
}

pub fn load(elf: &object::ElfFile<'a>) -> BtfResult<Btf<'a>> {
pub fn load(elf: &object::File<'a>) -> BtfResult<Btf<'a>> {
let endian = if elf.is_little_endian() {
scroll::LE
} else {
scroll::BE
};
let mut btf = Btf::<'a> {
endian: endian,
ptr_sz: if elf.elf().is_64 { 8 } else { 4 },
ptr_sz: if elf.is_64() { 8 } else { 4 },
types: vec![BtfType::Void],
has_ext: false,
func_secs: Vec::new(),
Expand All @@ -1052,7 +1051,7 @@ impl<'a> Btf<'a> {
.section_by_name(BTF_ELF_SEC)
.ok_or_else(|| Box::new(BtfError::new("No .BTF section found!")))?;
let data = match btf_section.data() {
Cow::Borrowed(d) => d,
Ok(d) => d,
_ => panic!("expected borrowed data"),
};
let hdr = data.pread_with::<btf_header>(0, endian)?;
Expand Down Expand Up @@ -1081,7 +1080,7 @@ impl<'a> Btf<'a> {
if let Some(ext_section) = elf.section_by_name(BTF_EXT_ELF_SEC) {
btf.has_ext = true;
let ext_data = match ext_section.data() {
Cow::Borrowed(d) => d,
Ok(d) => d,
_ => panic!("expected borrowed data"),
};
let ext_hdr = ext_data.pread_with::<btf_ext_header_v1>(0, endian)?;
Expand Down

0 comments on commit 61e3ea6

Please sign in to comment.