Skip to content

Commit

Permalink
Extend .debug_line info to the generated code range.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Feb 28, 2019
1 parent ee89540 commit 8560f43
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
17 changes: 14 additions & 3 deletions lib/debug/src/address_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ pub struct AddressMap {
pub wasm: WasmAddress,
}

#[derive(Debug)]
pub struct FunctionMap {
pub offset: GeneratedAddress,
pub len: GeneratedAddress,
pub addresses: Box<[AddressMap]>,
}

#[derive(Debug)]
pub struct AddressTransform {
lookup: BTreeMap<WasmAddress, (SymbolIndex, GeneratedAddress, GeneratedAddress)>,
map: PrimaryMap<DefinedFuncIndex, Box<[AddressMap]>>,
map: PrimaryMap<DefinedFuncIndex, FunctionMap>,
func_ranges: Vec<(usize, usize)>,
}

Expand Down Expand Up @@ -63,7 +70,11 @@ impl AddressTransform {
let last_addr = ft.body_offset + ft.body_len;
lookup.insert(fn_offset + fn_size, (index, last_addr, last_addr));
fn_map.sort_by(|a, b| a.generated.cmp(&b.generated));
map.push(fn_map.into_boxed_slice());
map.push(FunctionMap {
offset: ft.body_offset,
len: ft.body_len,
addresses: fn_map.into_boxed_slice(),
});
}
AddressTransform {
lookup,
Expand Down Expand Up @@ -118,7 +129,7 @@ impl AddressTransform {
self.diff(addr1, addr1 + u)
}

pub fn map(&self) -> &PrimaryMap<DefinedFuncIndex, Box<[AddressMap]>> {
pub fn map(&self) -> &PrimaryMap<DefinedFuncIndex, FunctionMap> {
&self.map
}

Expand Down
27 changes: 16 additions & 11 deletions lib/debug/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,12 @@ where
}

for (i, map) in addr_tr.map() {
if map.len() == 0 {
continue;
}
let symbol = i.index();
let base_addr = map[0].generated; // Assume it where function symbol starts at
let base_addr = map.offset;
out_program.begin_sequence(Some(write::Address::Relative { symbol, addend: 0 }));
let mut last_address = base_addr as u64;
for addr_map in map.iter() {
// TODO track and place function declaration line here
let mut last_address = None;
for addr_map in map.addresses.iter() {
let mut saved_row = saved_rows.get(&addr_map.wasm);
if saved_row.is_none() {
// No direct match -- repeat search with range.
Expand All @@ -399,8 +397,15 @@ where
}) = saved_row
{
// Ignore duplicates
if *address != last_address {
out_program.row().address_offset = (addr_map.generated - base_addr) as u64;
if Some(*address) != last_address {
let address_offset = if last_address.is_none() {
// Extend first entry to the function declaration
// TODO use the function declaration line instead
0
} else {
(addr_map.generated - base_addr) as u64
};
out_program.row().address_offset = address_offset;
out_program.row().op_index = *op_index;
out_program.row().file = files[(file_index - 1) as usize];
out_program.row().line = *line;
Expand All @@ -412,12 +417,12 @@ where
out_program.row().epilogue_begin = *epilogue_begin;
out_program.row().isa = *isa;
out_program.generate_row();
last_address = *address;
last_address = Some(*address);
}
}
}
let last_addr = (map[map.len() - 1].generated - base_addr) as u64;
out_program.end_sequence(last_addr);
let end_addr = (map.offset + map.len - 1) as u64;
out_program.end_sequence(end_addr);
}
Ok((out_program, offset, files))
} else {
Expand Down

0 comments on commit 8560f43

Please sign in to comment.