-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add debug file dump #7375
Add debug file dump #7375
Conversation
14d6720
to
7cdf9ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not too sure i am fond of this approach, ideally we'd move away from allocating a big chunk of memory for the debugger, i.e. ideally we'd move away from record/replay
Thanks for comment! Do you find the idea of changing record/replay approach as a new feature request or a blocker for that functionality? This record/replay could be also run only for the dumping or dump can be created on the fly and written to file. The main idea is to be able to use that output for post processing things. Other approach could be to create a plugin system and move things like that out of the core of foundry. What do you think? |
hmm, thinking about this more, I think this is ok. if/when we move away from record/replay we can always change this as well would like input from @DaniPopes iirc there are some coming changes to the debugger? |
a131d07
to
940393c
Compare
940393c
to
0026488
Compare
26f36b6
to
84608e0
Compare
ping @DaniPopes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
84608e0
to
27dbb83
Compare
Just fixed tests (clippy + fmt) |
27dbb83
to
fc8a710
Compare
Fixed (again) - now using proper rust version locally. I don't know if this is intentional or not but in Cargo.toml there is |
Any chances for merging this one? :) I don't want to mix same code and I could then work on fixing this #7292. |
very sorry about this @piohei this now has a few conflicts that must be resolved first, still supportive of that feature |
No problem. I will fix them. :) |
Hi @piohei thanks for your PR! Would you mind updating the PR to resolve the merge conflicts? Looks like there is consensus on the feature and the approach so it would be great to get this merged |
1ca5252
to
04eee70
Compare
@zerosnacks Updated with suggestions and rebased with master again to allow merging. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, latest changes LGTM
Would like to get one more review before merging cc @grandizzy
To setup:
$ forge init counter
$ git clone https://github.com/reilabs/foundry.git reilabs-foundry
$ cd reilabs-foundry
$ git checkout add_debug_file_dump
$ make build
$ cd ..
$ cd counter
$ ../reilabs-foundry/target/debug/forge test --debug test_Increment --dump dump.json
$ ../reilabs-foundry/target/debug/forge debug --debug script/Counter.s.sol --dump dump.json
Side note: forge debug --debug
is a bit of a weird syntax but changing it is out of scope of this PR
@piohei would you mind fixing the merge conflicts one last time? I don't have the permissions to push directly to your fork as I normally would. |
58dc7d1
to
fbaf708
Compare
@zerosnacks rebased with master. :) should be fine now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Pending review of @grandizzy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thank you! couple of nits and I suggest adding a test too (like make sure json file is created when running forge test --debug
…debugger context to file as json.
Co-authored-by: zerosnacks <[email protected]>
Co-authored-by: zerosnacks <[email protected]>
bdd7f75
to
62e1466
Compare
@grandizzy Thanks for suggestions! Test added and code refactored as suggested. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, lgtm! CC @DaniPopes if you want to have a look too before merging
Merging this, any additional feedback or improvements can be handled in follow-ups Thanks @piohei for your contribution! |
* Refactored debugger to extract TUI abstraction. Added option to dump debugger context to file as json. * Update crates/forge/bin/cmd/test/mod.rs Co-authored-by: zerosnacks <[email protected]> * Update crates/script/src/lib.rs Co-authored-by: zerosnacks <[email protected]> * Cleanup code. * Added test. * Reformat code. * Reformat code. --------- Co-authored-by: zerosnacks <[email protected]>
* Refactored debugger to extract TUI abstraction. Added option to dump debugger context to file as json. * Update crates/forge/bin/cmd/test/mod.rs Co-authored-by: zerosnacks <[email protected]> * Update crates/script/src/lib.rs Co-authored-by: zerosnacks <[email protected]> * Cleanup code. * Added test. * Reformat code. * Reformat code. --------- Co-authored-by: zerosnacks <[email protected]>
Motivation
It could be very helpful to be able to dump to a JSON file whole debugger context: calls, source code, refs, etc. It would allow then to do a post processing like for example creating heatmap for most costly lines in terms of gas usage.
Closes #7364
Closes #7112
Solution
New
--dump
param is being added toforge debug
andforge test --debug
commands. It requires a path to file where to dump data and passing --debug flag same time. Debugger code is refactored to create abstraction over it. It is then used by two different presenters: TUI (interactive debugger) and file dumper. I also added to debugger data original path for the source file to allow figuring out where to make changes when debugging.