From 8560f431f38ad2b359c2caa8652a93e174f0695a Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Thu, 28 Feb 2019 12:42:48 -0600 Subject: [PATCH] Extend .debug_line info to the generated code range. --- lib/debug/src/address_transform.rs | 17 ++++++++++++++--- lib/debug/src/transform.rs | 27 ++++++++++++++++----------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/debug/src/address_transform.rs b/lib/debug/src/address_transform.rs index f8eff81d0dfc..8f19ecddf1b1 100644 --- a/lib/debug/src/address_transform.rs +++ b/lib/debug/src/address_transform.rs @@ -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, - map: PrimaryMap>, + map: PrimaryMap, func_ranges: Vec<(usize, usize)>, } @@ -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, @@ -118,7 +129,7 @@ impl AddressTransform { self.diff(addr1, addr1 + u) } - pub fn map(&self) -> &PrimaryMap> { + pub fn map(&self) -> &PrimaryMap { &self.map } diff --git a/lib/debug/src/transform.rs b/lib/debug/src/transform.rs index ff2a9d48111e..114dac3b1d65 100644 --- a/lib/debug/src/transform.rs +++ b/lib/debug/src/transform.rs @@ -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. @@ -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; @@ -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 {