Skip to content

Commit

Permalink
[Cider2] Watchpoint fixes (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclecticGriffin authored Aug 6, 2024
1 parent aa74381 commit 8945254
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 83 deletions.
14 changes: 14 additions & 0 deletions interp/src/debugger/commands/command_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ impl CommandParser {
))
}

fn enable_watch(input: Node) -> ParseResult<Command> {
Ok(match_nodes!(input.into_children();
[brk_id(br)..] => Command::EnableWatch(br.collect())
))
}

fn disable_watch(input: Node) -> ParseResult<Command> {
Ok(match_nodes!(input.into_children();
[brk_id(br)..] => Command::DisableWatch(br.collect())
))
}

fn explain(_input: Node) -> ParseResult<Command> {
Ok(Command::Explain)
}
Expand Down Expand Up @@ -261,6 +273,8 @@ impl CommandParser {
[info_watch(iw), EOI(_)] => iw,
[delete(del), EOI(_)] => del,
[delete_watch(del), EOI(_)] => del,
[enable_watch(ew), EOI(_)] => ew,
[disable_watch(dw), EOI(_)] => dw,
[enable(e), EOI(_)] => e,
[disable(dis), EOI(_)] => dis,
[exit(exit), EOI(_)] => exit,
Expand Down
9 changes: 6 additions & 3 deletions interp/src/debugger/commands/commands.pest
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ delete = { (^"delete" | ^"del") ~ brk_id+ }

delete_watch = { (^"delete-watch" | ^"del-watch") ~ brk_id+ }

enable = { (^"enable") ~ brk_id+ }
disable = { (^"disable") ~ brk_id+ }
enable = { (^"enable" | ^"en") ~ brk_id+ }
disable = { (^"disable" | ^"dis") ~ brk_id+ }

enable_watch = { (^"enable-watch" | ^"enw") ~ brk_id+ }
disable_watch = { (^"disable-watch" | ^"disw") ~ brk_id+ }

exit = { ^"exit" | ^"quit" }

Expand All @@ -71,6 +74,6 @@ explain = { ^"explain" }
restart = { ^"restart" }

command = {
SOI ~ (watch | comm_where | print_state | print | print_fail | delete_watch | delete | brk | enable | disable | step_over | step // commands without input
SOI ~ (watch | comm_where | print_state | print | print_fail | delete_watch | delete | brk | enable_watch | disable_watch | enable | disable | step_over | step // commands without input
| cont | help | info_break | info_watch | display | exit | explain | restart)? ~ EOI
}
2 changes: 2 additions & 0 deletions interp/src/debugger/commands/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ pub enum Command {
Disable(Vec<ParsedBreakPointID>),
Enable(Vec<ParsedBreakPointID>),
Delete(Vec<ParsedBreakPointID>),
EnableWatch(Vec<ParsedBreakPointID>),
DisableWatch(Vec<ParsedBreakPointID>),
DeleteWatch(Vec<ParsedBreakPointID>),
StepOver(ParsedGroupName),
Watch(
Expand Down
18 changes: 18 additions & 0 deletions interp/src/debugger/debugger_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,24 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {
}
}

Command::EnableWatch(targets) => {
for target in targets {
let target = target
.parse_to_watch_ids(self.program_context.as_ref());
unwrap_error_message!(target);
self.debugging_context.enable_watchpoint(target)
}
}

Command::DisableWatch(targets) => {
for target in targets {
let target = target
.parse_to_watch_ids(self.program_context.as_ref());
unwrap_error_message!(target);
self.debugging_context.disable_watchpoint(target)
}
}

Command::Watch(
group,
watch_pos,
Expand Down
26 changes: 17 additions & 9 deletions interp/src/debugger/debugging_context/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ pub struct WatchPoint {
}

impl WatchPoint {
pub fn _enable(&mut self) {
pub fn enable(&mut self) {
self.state = PointStatus::Enabled;
}

pub fn _disable(&mut self) {
pub fn disable(&mut self) {
self.state = PointStatus::Disabled;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ impl WatchPointIndices {
fn get_before(&self) -> Option<&[WatchpointIdx]> {
match self {
Self::Before(idx) => Some(idx),
Self::Both { after, .. } => Some(after),
Self::Both { before, .. } => Some(before),
Self::After(_) => None,
}
}
Expand All @@ -263,7 +263,7 @@ impl WatchPointIndices {
match self {
Self::Before(_) => None,
Self::After(idx) => Some(idx),
Self::Both { before, .. } => Some(before),
Self::Both { after, .. } => Some(after),
}
}

Expand Down Expand Up @@ -531,14 +531,22 @@ impl DebuggingContext {
self.watchpoints.delete_by_idx(target)
}

fn _act_watchpoint(&mut self, target: WatchID, action: PointAction) {
pub fn enable_watchpoint(&mut self, target: WatchID) {
self.act_watchpoint(target, PointAction::Enable)
}

pub fn disable_watchpoint(&mut self, target: WatchID) {
self.act_watchpoint(target, PointAction::Disable)
}

fn act_watchpoint(&mut self, target: WatchID, action: PointAction) {
fn act(target: &mut WatchPoint, action: PointAction) {
match action {
PointAction::Enable => {
target._enable();
target.enable();
}
PointAction::Disable => {
target._disable();
target.disable();
}
}
}
Expand Down Expand Up @@ -582,11 +590,11 @@ impl DebuggingContext {
}

pub fn _enable_watchpoint(&mut self, target: WatchID) {
self._act_watchpoint(target, PointAction::Enable)
self.act_watchpoint(target, PointAction::Enable)
}

pub fn _disable_watchpoint(&mut self, target: WatchID) {
self._act_watchpoint(target, PointAction::Disable)
self.act_watchpoint(target, PointAction::Disable)
}

pub fn hit_breakpoints(&self) -> impl Iterator<Item = GroupIdx> + '_ {
Expand Down
98 changes: 88 additions & 10 deletions interp/src/flatten/structures/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use crate::{
errors::{BoxedInterpreterError, InterpreterError, InterpreterResult},
flatten::{
flat_ir::{
base::{
LocalCellOffset, LocalPortOffset, LocalRefCellOffset,
LocalRefPortOffset,
},
cell_prototype::{CellPrototype, SingleWidthType},
prelude::{
AssignedValue, AssignmentIdx, BaseIndices,
Expand All @@ -23,7 +27,7 @@ use crate::{
},
primitives::{self, prim_trait::UpdateStatus, Primitive},
structures::{
context::LookupName,
context::{LookupName, PortDefinitionInfo},
environment::{
program_counter::ControlPoint, traverser::Traverser,
},
Expand Down Expand Up @@ -691,8 +695,15 @@ impl<C: AsRef<Context> + Clone> Environment<C> {
&self.cells[point.comp].unwrap_comp().index_bases
+ l,
),
CellRef::Ref(_) => {
"<REF CELLS NOT YET SUPPORTED>".to_string()
CellRef::Ref(r) => {
let ref_global_offset = &self.cells[point.comp]
.unwrap_comp()
.index_bases
+ r;
let ref_actual =
self.ref_cells[ref_global_offset].unwrap();

self.get_full_name(ref_actual)
}
};

Expand Down Expand Up @@ -843,12 +854,12 @@ impl<C: AsRef<Context> + Clone> Environment<C> {
break;
}
}
}

if let Some(highest_found) = highest_found {
path.push(highest_found);
} else {
return None;
}
if let Some(highest_found) = highest_found {
path.push(highest_found);
} else {
return None;
}
}
}
Expand Down Expand Up @@ -1124,6 +1135,48 @@ impl<C: AsRef<Context> + Clone> Environment<C> {
let port = self.get_root_input_port(port);
self.pinned_ports.remove(port);
}

pub fn get_def_info(
&self,
comp_idx: ComponentIdx,
cell: LocalCellOffset,
) -> &crate::flatten::flat_ir::base::CellDefinitionInfo<LocalPortOffset>
{
let comp = &self.ctx.as_ref().secondary[comp_idx];
let idx = comp.cell_offset_map[cell];
&self.ctx.as_ref().secondary[idx]
}

pub fn get_def_info_ref(
&self,
comp_idx: ComponentIdx,
cell: LocalRefCellOffset,
) -> &crate::flatten::flat_ir::base::CellDefinitionInfo<LocalRefPortOffset>
{
let comp = &self.ctx.as_ref().secondary[comp_idx];
let idx = comp.ref_cell_offset_map[cell];
&self.ctx.as_ref().secondary[idx]
}

pub fn get_port_def_info(
&self,
comp_idx: ComponentIdx,
port: LocalPortOffset,
) -> &PortDefinitionInfo {
let comp = &self.ctx.as_ref().secondary[comp_idx];
let idx = comp.port_offset_map[port];
&self.ctx.as_ref().secondary[idx]
}

pub fn get_port_def_info_ref(
&self,
comp_idx: ComponentIdx,
port: LocalRefPortOffset,
) -> Identifier {
let comp = &self.ctx.as_ref().secondary[comp_idx];
let idx = comp.ref_port_offset_map[port];
self.ctx.as_ref().secondary[idx]
}
}

/// A wrapper struct for the environment that provides the functions used to
Expand Down Expand Up @@ -2155,9 +2208,9 @@ impl<C: AsRef<Context> + Clone> Simulator<C> {

if state.has_state() {
if let Some(name_override) = name {
write!(output, "{name_override}:").unwrap();
write!(output, "{name_override}: ").unwrap();
} else {
write!(output, "{}:", self.get_full_name(cell_idx)).unwrap();
write!(output, "{}: ", self.get_full_name(cell_idx)).unwrap();
}

writeln!(output, "{state}").unwrap();
Expand Down Expand Up @@ -2214,3 +2267,28 @@ impl<C: AsRef<Context> + Clone> GetFullName<C> for GlobalPortIdx {
format!("{path_str}.{name}")
}
}

impl<C: AsRef<Context> + Clone> GetFullName<C> for GlobalRefCellIdx {
fn get_full_name(&self, env: &Environment<C>) -> String {
let parent_path = env.get_parent_path_from_cell(*self).unwrap();
let path_str = env.format_path(&parent_path);

let immediate_parent = parent_path.last().unwrap();
let comp = if env.cells[*immediate_parent].as_comp().is_some() {
*immediate_parent
} else {
// get second-to-last parent
parent_path[parent_path.len() - 2]
};

let ledger = env.cells[comp].as_comp().unwrap();

let local_offset = *self - &ledger.index_bases;
let comp_def = &env.ctx().secondary[ledger.comp_id];
let ref_cell_def_idx = &comp_def.ref_cell_offset_map[local_offset];
let ref_cell_def = &env.ctx().secondary[*ref_cell_def_idx];
let name = env.ctx().lookup_name(ref_cell_def.name);

format!("{path_str}.{name}")
}
}
Loading

0 comments on commit 8945254

Please sign in to comment.