Skip to main content

vihaco_stdlib/debugger/
loadable.rs

1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4use super::{DebugAction, Debugger, DebuggerState, HasBreakpointInstruction, IsBreakpointToggled};
5use crate::{ExecutionState, Image, Loadable};
6use vihaco_module::module::LocalModule;
7use vihaco_runtime::{Composite, Dispatch, Field, HasProgram};
8
9impl<Inst, V, Ty, Info, M> Loadable<Image<Inst, V, Ty, Info>, M>
10where
11    M: Composite + HasProgram<Program = ExecutionState<DebuggerState>>,
12{
13    /// Install a gutter breakpoint in the owned image.
14    pub fn set_breakpoint<F>(&mut self, pc: u32) -> IsBreakpointToggled
15    where
16        M: Field<F, Child = Debugger<u32, Inst>>,
17        Inst: HasBreakpointInstruction,
18    {
19        let (image, machine) = self.breakpoint_parts_mut();
20        <M as Field<F>>::get_mut(machine).set_breakpoint(&mut image.module, pc)
21    }
22
23    /// Restore a gutter breakpoint's instruction in the owned image.
24    pub fn clear_breakpoint<F>(&mut self, pc: u32) -> IsBreakpointToggled
25    where
26        M: Field<F, Child = Debugger<u32, Inst>>,
27        Inst: HasBreakpointInstruction,
28    {
29        let (image, machine) = self.breakpoint_parts_mut();
30        <M as Field<F>>::get_mut(machine).clear_breakpoint(&mut image.module, pc)
31    }
32
33    /// Continue or single-step an invocation through the selected debugger.
34    pub fn resume_with_breaks<F>(&mut self, action: DebugAction) -> eyre::Result<()>
35    where
36        M: Field<F, Child = Debugger<u32, Inst>>
37            + Dispatch<LocalModule<Inst, V, Ty, Info>, Instruction = Inst>,
38        Inst: Clone,
39    {
40        let (image, machine) = self.parts_mut();
41        super::resume_with_breaks::<F, _, _, _, _, _>(&image.module, machine, action)
42    }
43}