Skip to content

Commit

Permalink
UGLY fix for borrowck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Jun 2, 2018
1 parent 881008c commit 66252bd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
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
15 changes: 7 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ 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 {
Expand All @@ -143,13 +143,12 @@ impl<'a> Context<gimli::EndianSlice<'a, gimli::RunTimeEndian>> {
S::from(gimli::EndianSlice::new(data_ref, endian))
}

let mut arena = Arena::new();
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 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

0 comments on commit 66252bd

Please sign in to comment.