Skip to content

Commit 0867fc1

Browse files
yash-atreyagrandizzyDaniPopes
authored
feat(forge): backtraces (#11547)
* basic backtrace impl * cleanup + remove frame kind * nit * cleanup * nit * display backtrace after traces * move backtrace extraction * fix inversion * tests * remove unused fields and args * nit * nit * cleanup: extract_backtrace * fix: don't set incorrect source location if we're unable to locate it * don't collect creation source map * use typed Path instead of String * unify the HashMap keyed by artifact id * mv source maps collection from multi_runner * more cleanup * feat: collect sources by build_id to work across fresh and cached compiler runs * add mixed compilation test * fork tests * clippy * feat: detect internal library calls using ast * test_library_backtrace * feat: detect external libraries * cleanup: consolidate logic in the Backtrace type * collect and store libs once not per source + add offset in SourceLocation to identify multiple contract / libs accurately * lazy source data collection * cleanup * resolve labels using known_contracts * fmt * feat: BacktraceBuilder * consolidate in backtrace builder * don't clone library sources * remove source_data from Backtrace * fix breaking tests * nit * nit * unify source and lib collection * use parsed_libraries * nit * cleanup * docs nits * fix * nit * nit * remove: contract_by_address from runner * nit * TraceMode::Debug for steps tracing when -vvv * rm redundant clone * rm unused deployed_bytecode from TestContract * rm redundant verbosity from mcr * nit * nit * fix tests * don't enable ast * minify json test fixture * fix test svg * ignore windows * fix * ignore win msg * win fix, Forge fmt new backtraces tests * defer source data collection + collect only required sources * rm artifact_ids from BacktraceBuilder * rm ast from SourceData * avoid source data cloning * defer BacktraceBuilder instatiation only in case of failure + pass required fields from config * nit * fix: oom due to TraceMode::Debug being set on verbosity >= 3 * fix backtrace tests - removal of internal lib detection * fix * fix: can_run_test_with_json_output_verbose * fix: ext tests by setting verbosity for forge-std and sablier * verbosity * minify * fix * fix(backtraces): reduce TraceMode level + don't hold sources in memory + avoid cloning (#11648) * defer source data collection + collect only required sources * rm artifact_ids from BacktraceBuilder * rm ast from SourceData * avoid source data cloning * defer BacktraceBuilder instatiation only in case of failure + pass required fields from config * nit * fix: oom due to TraceMode::Debug being set on verbosity >= 3 * fix backtrace tests - removal of internal lib detection * fix * fix: can_run_test_with_json_output_verbose * fix: ext tests by setting verbosity for forge-std and sablier * verbosity * minify * fix * check for silent and verbosity outside iter + use with_capacity * flattened - use filter_map outside * rm unused solidity file * make fns private + push to frames directly * nit * cleanup extract_frames * cleanup retrieving names from trace.decoded * format nit * nit Co-authored-by: DaniPopes <[email protected]> * use output.artifact_ids to chain cached and compiled * format nits * feat: disable detecting source location on via-ir * cleanup collect_source_data - rm redundant sorting * rm redundant loop and ptr comparios in from_traces * rm redundant prefix stripping * fix * unify resolving addresses for artifacts * nits + move format to Display * don't check linked libs if artifact already found * internalize extract_frames + make BacktraceFrame private * move to evm::traces * init backtrace builder outside loop * use memchr_iter * maintain source_cache in builder to avoid collect sources on multiple failures + pass SourceData by reference * cache by build_id in BacktraceBuilder to fetch sources for a build_id only once * non_exhaustive Backtrace * feat(traces): new TraceMode::Steps - enabled on -vvv * nits * fix: can_run_test_with_json_output_verbose --------- Co-authored-by: grandizzy <[email protected]> Co-authored-by: grandizzy <[email protected]> Co-authored-by: DaniPopes <[email protected]>
1 parent 322b227 commit 0867fc1

31 files changed

+1885
-216
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ itertools = "0.14"
320320
jsonpath_lib = "0.3"
321321
k256 = "0.13"
322322
mesc = "0.3"
323+
memchr = "2.7"
323324
num-format = "0.4"
324325
parking_lot = "0.12"
325326
proptest = "1.7.0"

crates/cheatcodes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ eyre.workspace = true
5151
itertools.workspace = true
5252
jsonpath_lib.workspace = true
5353
k256.workspace = true
54-
memchr = "2.7"
54+
memchr.workspace = true
5555
p256 = "0.13"
5656
ecdsa = "0.16"
5757
rand.workspace = true

crates/cheatcodes/src/evm.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use foundry_evm_core::{
2727
constants::{CALLER, CHEATCODE_ADDRESS, HARDHAT_CONSOLE_ADDRESS, TEST_CONTRACT_ADDRESS},
2828
utils::get_blob_base_fee_update_fraction_by_spec_id,
2929
};
30-
use foundry_evm_traces::StackSnapshotType;
30+
use foundry_evm_traces::TraceMode;
3131
use itertools::Itertools;
3232
use rand::Rng;
3333
use revm::{
@@ -1055,13 +1055,8 @@ impl Cheatcode for startDebugTraceRecordingCall {
10551055
original_tracer_config: *tracer.config(),
10561056
};
10571057

1058-
// turn on tracer configuration for recording
1059-
tracer.update_config(|config| {
1060-
config
1061-
.set_steps(true)
1062-
.set_memory_snapshots(true)
1063-
.set_stack_snapshots(StackSnapshotType::Full)
1064-
});
1058+
// turn on tracer debug configuration for recording
1059+
*tracer.config_mut() = TraceMode::Debug.into_config().expect("cannot be None");
10651060

10661061
// track where the recording starts
10671062
if let Some(last_node) = tracer.traces().nodes().last() {

crates/evm/traces/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ tempfile.workspace = true
4343
rayon.workspace = true
4444
solar.workspace = true
4545
revm.workspace = true
46+
yansi.workspace = true
47+
memchr.workspace = true
4648

4749
[dev-dependencies]
4850
tempfile.workspace = true

0 commit comments

Comments
 (0)