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

Update object to 0.8.0 #92

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ travis-ci = { repository = "gimli-rs/addr2line" }
[dependencies]
gimli = "0.16"
fallible-iterator = "0.1"
object = "0.7"
object = "0.8"
intervaltree = "0.2"
smallvec = "0.6"
lazy-init = "0.3"
typed-arena = "1"
rustc-demangle = { version = "0.1", optional = true }
cpp_demangle = { version = "0.2", optional = true }

Expand Down
8 changes: 6 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ extern crate addr2line;
extern crate memmap;
extern crate object;
extern crate test;
extern crate typed_arena;

use std::env;
use std::fs::File;
use std::path::{self, PathBuf};
use std::process;
use typed_arena::Arena;

fn release_fixture_path() -> PathBuf {
let mut path = PathBuf::new();
Expand Down Expand Up @@ -61,7 +63,8 @@ fn context_new_location(b: &mut test::Bencher) {

with_file(&target, |file| {
b.iter(|| {
addr2line::Context::new(file).unwrap();
let arena = Arena::new();
addr2line::Context::new(&arena, file).unwrap();
});
});
}
Expand All @@ -72,7 +75,8 @@ fn context_new_with_functions(b: &mut test::Bencher) {

with_file(&target, |file| {
b.iter(|| {
addr2line::Context::new(file)
let arena = Arena::new();
addr2line::Context::new(&arena, file)
.unwrap();
});
});
Expand Down
5 changes: 4 additions & 1 deletion examples/addr2line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate fallible_iterator;
extern crate gimli;
extern crate memmap;
extern crate object;
extern crate typed_arena;

use std::fs::File;
use std::path::Path;
Expand All @@ -13,6 +14,7 @@ use std::borrow::Cow;
use clap::{App, Arg, Values};
use fallible_iterator::FallibleIterator;
use object::Object;
use typed_arena::Arena;

use addr2line::{Context, Location};

Expand Down Expand Up @@ -156,7 +158,8 @@ fn main() {
let file = &object::File::parse(&*map).unwrap();

let symbols = file.symbol_map();
let ctx = Context::new(file).unwrap();
let arena = Arena::new();
let ctx = Context::new(&arena, file).unwrap();

let stdin = std::io::stdin();
let addrs = matches
Expand Down
30 changes: 18 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ extern crate object;
#[cfg(feature = "rustc-demangle")]
extern crate rustc_demangle;
extern crate smallvec;
extern crate typed_arena;

use std::path::PathBuf;
use std::cmp::Ordering;
use std::borrow::Cow;
use std::borrow::{Cow, Borrow};
use std::u64;

use fallible_iterator::FallibleIterator;
Expand All @@ -45,6 +46,8 @@ use lazy_init::Lazy;
use object::Object;
use smallvec::SmallVec;

use typed_arena::Arena;

struct Func<T> {
entry_off: gimli::UnitOffset<T>,
depth: isize,
Expand Down Expand Up @@ -117,32 +120,35 @@ fn read_ranges<R: gimli::Reader>(

impl<'a> Context<gimli::EndianSlice<'a, gimli::RunTimeEndian>> {
/// Construct a new `Context`.
pub fn new(file: &object::File<'a>) -> Result<Self, Error> {
pub fn new(arena: &'a Arena<Cow<'a, [u8]>>, file: &'a object::File<'a>) -> Result<Self, Error> {
let endian = if file.is_little_endian() {
gimli::RunTimeEndian::Little
} else {
gimli::RunTimeEndian::Big
};

fn load_section<'input, 'file, S, Endian>(
file: &object::File<'input>,
fn load_section<'a, 'input, 'file, S, Endian>(
arena: &'a Arena<Cow<'file, [u8]>>,
file: &'file object::File<'input>,
endian: Endian,
) -> S
where
S: gimli::Section<gimli::EndianSlice<'input, Endian>>,
Endian: gimli::Endianity,
'file: 'input,
'a: 'file,
{
let data = file.section_data_by_name(S::section_name()).unwrap_or(&[]);
S::from(gimli::EndianSlice::new(data, endian))
let data = file.section_data_by_name(S::section_name()).unwrap_or(Cow::Borrowed(&[]));
let data_ref = (*arena.alloc(data)).borrow();
S::from(gimli::EndianSlice::new(data_ref, endian))
}

let debug_abbrev: gimli::DebugAbbrev<_> = load_section(file, endian);
let debug_info: gimli::DebugInfo<_> = load_section(file, endian);
let debug_line: gimli::DebugLine<_> = load_section(file, endian);
let debug_ranges: gimli::DebugRanges<_> = load_section(file, endian);
let debug_rnglists: gimli::DebugRngLists<_> = load_section(file, endian);
let debug_str: gimli::DebugStr<_> = load_section(file, endian);
let debug_abbrev: gimli::DebugAbbrev<_> = load_section(arena, file, endian);
let debug_info: gimli::DebugInfo<_> = load_section(arena, file, endian);
let debug_line: gimli::DebugLine<_> = load_section(arena, file, endian);
let debug_ranges: gimli::DebugRanges<_> = load_section(arena, file, endian);
let debug_rnglists: gimli::DebugRngLists<_> = load_section(arena, file, endian);
let debug_str: gimli::DebugStr<_> = load_section(arena, file, endian);

let range_lists = gimli::RangeLists::new(debug_ranges, debug_rnglists)?;

Expand Down
11 changes: 8 additions & 3 deletions tests/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ extern crate findshlibs;
extern crate gimli;
extern crate memmap;
extern crate object;
extern crate typed_arena;

use std::fs::File;

use findshlibs::{IterationControl, SharedLibrary, TargetSharedLibrary};
use addr2line::Context;
use typed_arena::Arena;

#[test]
fn correctness() {
let file = File::open("/proc/self/exe").unwrap();
let map = unsafe { memmap::Mmap::map(&file).unwrap() };
let file = &object::File::parse(&*map).unwrap();
let ctx = Context::new(file).unwrap();
let arena = Arena::new();
let ctx = Context::new(&arena, file).unwrap();

let mut bias = None;
TargetSharedLibrary::each(|lib| {
Expand All @@ -40,7 +43,8 @@ fn zero_sequence() {
let file = File::open("/proc/self/exe").unwrap();
let map = unsafe { memmap::Mmap::map(&file).unwrap() };
let file = &object::File::parse(&*map).unwrap();
let ctx = Context::new(file).unwrap();
let arena = Arena::new();
let ctx = Context::new(&arena, file).unwrap();
for probe in 0..10 {
assert!(ctx.find_location(probe).unwrap().is_none());
}
Expand All @@ -51,7 +55,8 @@ fn zero_function() {
let file = File::open("/proc/self/exe").unwrap();
let map = unsafe { memmap::Mmap::map(&file).unwrap() };
let file = &object::File::parse(&*map).unwrap();
let ctx = Context::new(file).unwrap();
let arena = Arena::new();
let ctx = Context::new(&arena, file).unwrap();
for probe in 0..10 {
assert!(ctx.find_frames(probe).unwrap().next().unwrap().is_none());
}
Expand Down