Skip to content

Commit 031907d

Browse files
committed
Add range & fix small bug
1 parent 00ee90b commit 031907d

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
- Fix small crash when evaluating a variable location.
6+
- Now it will accurately report that the memory doesn't exist instead of returning an error.
7+
- *Breaking*: Add range to memory region
8+
59
## 0.10.1 (24-07-25)
610

711
- Fix accidental use of std

core/src/memory_region.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub const MEMORY_REGION_IDENTIFIER: u8 = 0x01;
99
/// A collection of bytes that capture a memory region
1010
#[cfg(feature = "std")]
1111
pub trait MemoryRegion {
12+
/// Get the address range of this region
13+
fn range(&self) -> std::ops::Range<u64>;
14+
1215
/// Returns the slice of memory that can be found at the given address_range.
1316
/// If the given address range is not fully within the captured region, then None is returned.
1417
fn read(
@@ -107,6 +110,10 @@ impl<const SIZE: usize> ArrayMemoryRegion<SIZE> {
107110

108111
#[cfg(feature = "std")]
109112
impl<const SIZE: usize> MemoryRegion for ArrayMemoryRegion<SIZE> {
113+
fn range(&self) -> std::ops::Range<u64> {
114+
self.start_address..self.start_address + self.data.len() as u64
115+
}
116+
110117
fn read(
111118
&self,
112119
index: core::ops::Range<u64>,
@@ -238,6 +245,10 @@ impl VecMemoryRegion {
238245

239246
#[cfg(feature = "std")]
240247
impl MemoryRegion for VecMemoryRegion {
248+
fn range(&self) -> std::ops::Range<u64> {
249+
self.start_address..self.start_address + self.data.len() as u64
250+
}
251+
241252
fn read(
242253
&self,
243254
index: core::ops::Range<u64>,
@@ -364,6 +375,11 @@ impl<'a> SliceMemoryRegion<'a> {
364375

365376
#[cfg(feature = "std")]
366377
impl<'a> MemoryRegion for SliceMemoryRegion<'a> {
378+
fn range(&self) -> std::ops::Range<u64> {
379+
let range = self.data.as_ptr_range();
380+
range.start as u64..range.end as u64
381+
}
382+
367383
fn read(
368384
&self,
369385
index: core::ops::Range<u64>,

trace/src/platform/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,16 @@ fn add_current_frames<'a, P: Platform<'a>>(
234234
where
235235
<P::Word as funty::Numeric>::Bytes: bitvec::view::BitView<Store = u8>,
236236
{
237+
let pc = device_memory.register(gimli::Arm::PC)?.as_u64();
238+
237239
// Find the frames of the current register context
238-
let mut context_frames = addr2line_context
239-
.find_frames(device_memory.register(gimli::Arm::PC)?.as_u64())
240-
.skip_all_loads()?;
240+
let mut context_frames = addr2line_context.find_frames(pc).skip_all_loads()?;
241241

242242
// Get the debug compilation unit of the current register context
243243
let unit_ref = addr2line_context
244-
.find_dwarf_and_unit(device_memory.register(gimli::Arm::PC)?.as_u64())
244+
.find_dwarf_and_unit(pc)
245245
.skip_all_loads()
246-
.ok_or(TraceError::DwarfUnitNotFound {
247-
pc: device_memory.register(gimli::Arm::PC)?.as_u64(),
248-
})?;
246+
.ok_or(TraceError::DwarfUnitNotFound { pc })?;
249247

250248
// Get the abbreviations of the unit
251249
let abbreviations = unit_ref.dwarf.abbreviations(&unit_ref.header)?;

trace/src/variables/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ where
560560
Err(TraceError::LocationEvaluationStepNotImplemented(step)) => {
561561
Ok(VariableLocationResult::LocationEvaluationStepNotImplemented(step))
562562
}
563+
Err(TraceError::MissingMemory(_)) => Ok(VariableLocationResult::NoLocationFound),
563564
Err(e) => Err(e),
564565
Ok(pieces) if pieces.is_empty() => Ok(VariableLocationResult::NoLocationFound),
565566
Ok(pieces) => Ok(VariableLocationResult::LocationsFound(pieces)),

0 commit comments

Comments
 (0)