foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Add debug file dump

Open piohei opened this issue 1 year ago • 16 comments

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.

piohei avatar Mar 12 '24 12:03 piohei

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?

piohei avatar Mar 12 '24 13:03 piohei

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?

onbjerg avatar Mar 12 '24 14:03 onbjerg

ping @DaniPopes

onbjerg avatar Mar 19 '24 15:03 onbjerg

Just fixed tests (clippy + fmt)

piohei avatar Mar 19 '24 20:03 piohei

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.

piohei avatar Mar 20 '24 09:03 piohei

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.

piohei avatar Mar 22 '24 10:03 piohei

very sorry about this @piohei

this now has a few conflicts that must be resolved first, still supportive of that feature

mattsse avatar Apr 08 '24 17:04 mattsse

No problem. I will fix them. :)

piohei avatar Apr 08 '24 18:04 piohei

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

zerosnacks avatar Jul 12 '24 11:07 zerosnacks

Hi @zerosnacks! Sorry for late response. I will try to find some time to resolve conflicts here and prepare it to merge.

piohei avatar Jul 30 '24 13:07 piohei

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!

zerosnacks avatar Jul 30 '24 13:07 zerosnacks

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

zerosnacks avatar Jul 31 '24 11:07 zerosnacks

Friendly ping @piohei on the above ^

onbjerg avatar Sep 23 '24 00:09 onbjerg

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

zerosnacks avatar Oct 03 '24 12:10 zerosnacks

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.

piohei avatar Oct 04 '24 09:10 piohei

@zerosnacks Updated with suggestions and rebased with master again to allow merging. :)

piohei avatar Oct 11 '24 11:10 piohei

@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 avatar Oct 21 '24 12:10 zerosnacks

@zerosnacks rebased with master. :) should be fine now

piohei avatar Oct 21 '24 12:10 piohei

@grandizzy Thanks for suggestions! Test added and code refactored as suggested. :) @zerosnacks I have rebased with master once again.

piohei avatar Oct 22 '24 11:10 piohei

Merging this, any additional feedback or improvements can be handled in follow-ups

Thanks @piohei for your contribution!

zerosnacks avatar Oct 23 '24 10:10 zerosnacks