Skip to content

Commit

Permalink
fix(debugger):
Browse files Browse the repository at this point in the history
- usize overflow in `Unit::find_place_by_pc`
- `next` step now takes into account that the debugee can finish execution while stepping
  • Loading branch information
godzie44 committed Sep 17, 2023
1 parent 9eb021b commit 9e8a686
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/debugger/breakpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,14 @@ impl Debugger {
DeferredBreakpoint::Function(function) => self.set_breakpoint_at_fn(function).err(),
};

let retain_brkpt = match mb_error {
match mb_error {
None => false,
Some(SetBreakpointError::PlaceNotFound(_)) => true,
Some(err) => {
errors.push(err);
true
}
};
retain_brkpt
}
});
self.breakpoints.deferred_breakpoints = deferred_brkpts;

Expand Down
2 changes: 1 addition & 1 deletion src/debugger/command/break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a> Break<'a> {
vec![self.dbg.set_breakpoint_at_addr((*addr).into())?]
}
Breakpoint::Line(file, line) => self.dbg.set_breakpoint_at_line(file, *line)?,
Breakpoint::Function(func_name) => self.dbg.set_breakpoint_at_fn(&func_name)?,
Breakpoint::Function(func_name) => self.dbg.set_breakpoint_at_fn(func_name)?,
};
HandlingResult::New(res)
}
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/debugee/dwarf/unit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl Unit {
let pc = u64::from(pc);
let pos = match self.lines.binary_search_by_key(&pc, |line| line.address) {
Ok(p) => p,
Err(p) => p - 1,
Err(p) => p.saturating_sub(1),
};

self.find_place_by_idx(pos)
Expand Down
7 changes: 5 additions & 2 deletions src/debugger/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::debugger::breakpoint::Breakpoint;
use crate::debugger::debugee::dwarf::unit::PlaceDescriptorOwned;
use crate::debugger::debugee::tracer::{StopReason, TraceContext};
use crate::debugger::{Debugger, ExplorationContext};
use anyhow::anyhow;
use anyhow::{anyhow, bail};
use nix::sys::signal::Signal;

/// Result of a step, if [`SignalInterrupt`] then step process interrupted by a signal and user must know it.
Expand Down Expand Up @@ -331,14 +331,17 @@ impl Debugger {
.debug_info(new_location.pc)?
.find_place_from_pc(new_location.global_pc)?
.ok_or_else(|| anyhow!("unknown function range"))?;

if place.address != new_location.global_pc {
if let StepResult::SignalInterrupt { signal, .. } = self.step_in()? {
return Ok(StepResult::signal_interrupt(signal));
}
}
}

if self.debugee.is_exited() {
bail!("debugee exited while step execution");
}

self.expl_ctx_update_location()?;
Ok(StepResult::Done)
}
Expand Down

0 comments on commit 9e8a686

Please sign in to comment.