forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use
revm-inspectors
traces for debugger (foundry-rs#8249)
* move calldata to DebugNode * refactor: use tracer from inspectors for debugger * fix: rm hex * clippy * bump inspectors * newline * docs * fix * fmt
- Loading branch information
Showing
29 changed files
with
280 additions
and
644 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ mod op; | |
|
||
mod tui; | ||
pub use tui::{Debugger, DebuggerBuilder, ExitReason}; | ||
|
||
mod node; | ||
pub use node::DebugNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use alloy_primitives::{Address, Bytes}; | ||
use foundry_evm_traces::{CallKind, CallTraceArena}; | ||
use revm_inspectors::tracing::types::{CallTraceStep, TraceMemberOrder}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Represents a part of the execution frame before the next call or end of the execution. | ||
#[derive(Clone, Debug, Default, Serialize, Deserialize)] | ||
pub struct DebugNode { | ||
/// Execution context. | ||
/// | ||
/// Note that this is the address of the *code*, not necessarily the address of the storage. | ||
pub address: Address, | ||
/// The kind of call this is. | ||
pub kind: CallKind, | ||
/// Calldata of the call. | ||
pub calldata: Bytes, | ||
/// The debug steps. | ||
pub steps: Vec<CallTraceStep>, | ||
} | ||
|
||
impl DebugNode { | ||
/// Creates a new debug node. | ||
pub fn new( | ||
address: Address, | ||
kind: CallKind, | ||
steps: Vec<CallTraceStep>, | ||
calldata: Bytes, | ||
) -> Self { | ||
Self { address, kind, steps, calldata } | ||
} | ||
} | ||
|
||
/// Flattens given [CallTraceArena] into a list of [DebugNode]s. | ||
/// | ||
/// This is done by recursively traversing the call tree and collecting the steps in-between the | ||
/// calls. | ||
pub fn flatten_call_trace(arena: CallTraceArena, out: &mut Vec<DebugNode>) { | ||
#[derive(Debug, Clone, Copy)] | ||
struct PendingNode { | ||
node_idx: usize, | ||
steps_count: usize, | ||
} | ||
|
||
fn inner(arena: &CallTraceArena, node_idx: usize, out: &mut Vec<PendingNode>) { | ||
let mut pending = PendingNode { node_idx, steps_count: 0 }; | ||
let node = &arena.nodes()[node_idx]; | ||
for order in node.ordering.iter() { | ||
match order { | ||
TraceMemberOrder::Call(idx) => { | ||
out.push(pending); | ||
pending.steps_count = 0; | ||
inner(arena, node.children[*idx], out); | ||
} | ||
TraceMemberOrder::Step(_) => { | ||
pending.steps_count += 1; | ||
} | ||
_ => {} | ||
} | ||
} | ||
out.push(pending); | ||
} | ||
let mut nodes = Vec::new(); | ||
inner(&arena, 0, &mut nodes); | ||
|
||
let mut arena_nodes = arena.into_nodes(); | ||
|
||
for pending in nodes { | ||
let steps = { | ||
let other_steps = | ||
arena_nodes[pending.node_idx].trace.steps.split_off(pending.steps_count); | ||
std::mem::replace(&mut arena_nodes[pending.node_idx].trace.steps, other_steps) | ||
}; | ||
|
||
// Skip nodes with empty steps as there's nothing to display for them. | ||
if steps.is_empty() { | ||
continue | ||
} | ||
|
||
let call = &arena_nodes[pending.node_idx].trace; | ||
let calldata = if call.kind.is_any_create() { Bytes::new() } else { call.data.clone() }; | ||
let node = DebugNode::new(call.address, call.kind, steps, calldata); | ||
|
||
out.push(node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.