edb_engine/analysis/hook.rs
1// EDB - Ethereum Debugger
2// Copyright (C) 2024 Zhuo Zhang and Wuqi Zhang
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Affero General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Affero General Public License for more details.
13//
14// You should have received a copy of the GNU Affero General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17use serde::{Deserialize, Serialize};
18
19use crate::{USID, UVID};
20
21/// Contains information that should be recoreded before and after each step.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub enum StepHook {
24 /// The hook to mark that a step is about to be executed. The debugger will pause here during step-by-step execution.
25 BeforeStep(USID),
26
27 /// The hook to mark which variables becomes in scope.
28 VariableInScope(UVID),
29
30 /// The hook to mark that a variable becomes out of scope.
31 VariableOutOfScope(UVID),
32
33 /// The hook to mark that a variable is updated.
34 VariableUpdate(UVID),
35}
36
37impl StepHook {
38 /// Returns the variant name of this hook.
39 ///
40 /// # Returns
41 ///
42 /// A string slice representing the variant name.
43 pub fn variant_name(&self) -> &'static str {
44 match self {
45 Self::BeforeStep(_) => "BeforeStep",
46 Self::VariableInScope(_) => "VariableInScope",
47 Self::VariableOutOfScope(_) => "VariableOutOfScope",
48 Self::VariableUpdate(_) => "VariableUpdate",
49 }
50 }
51}