Add debug file dump
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 https://github.com/foundry-rs/foundry/issues/7364 Closes https://github.com/foundry-rs/foundry/issues/7112
Solution
New --dump param is being added to forge debug and forge 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.
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?
ping @DaniPopes
Just fixed tests (clippy + fmt)
Fixed (again) - now using proper rust version locally. I don't know if this is intentional or not but in Cargo.toml there is rust-version = "1.76" while CI is using nightly version.
Any chances for merging this one? :) I don't want to mix same code and I could then work on fixing this https://github.com/foundry-rs/foundry/issues/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
Hi @zerosnacks! Sorry for late response. I will try to find some time to resolve conflicts here and prepare it to merge.
Hi @zerosnacks! Sorry for late response. I will try to find some time to resolve conflicts here and prepare it to merge.
No problem! Thanks!
Just so I understand correctly, would this supersede https://github.com/foundry-rs/foundry/pull/7135?
I quite like the idea of having a keybinding that would trigger the dump to disk from inside of the debugger so you can decide on-the-fly too
Friendly ping @piohei on the above ^
Just so I understand correctly, would this supersede #7135?
I quite like the idea of having a keybinding that would trigger the dump to disk from inside of the debugger so you can decide on-the-fly too
@piohei would be great to get this functionality included as part of this PR
Sorry for such a big delay. I added dumping whole "debug data" and workflow should pass (fixed fmt and clippy). About the buffers dump during debug mode - it would be better to make this as a seperate PR. It is different kind of dumping as the need is to have only the part of the big dump from current "moment" during debug. I will try to find time to create this PR as well.
@zerosnacks Updated with suggestions and rebased with master again to allow merging. :)
@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.
@zerosnacks rebased with master. :) should be fine now
@grandizzy Thanks for suggestions! Test added and code refactored as suggested. :) @zerosnacks I have rebased with master once again.
Merging this, any additional feedback or improvements can be handled in follow-ups
Thanks @piohei for your contribution!