feat[tool]: Add extra debugging output #4718
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I did
This commit contains two main changes.
The first are two new output modes: the
symbol_map
andsymbol_map_runtime
. These contain both contain the raw "symbol map" produced during the respective assembly of the deployment and runtime code into bytecode. This information is crucial for determining the exact starting position of internal functions in the assembled bytecode.The second component is a change to the existing metadata output. When the user selects the experimental codegen, the metadata for internal functions will contain a list of the parameter names which are passed via the stack in
venom_via_stack
key. Similarly, if the function returns its value via the stack, the "venom_return_via_stack" key records this as a boolean. These keys are omitted if experimental codegen is not selected. (Credit where credit is due: this feature was primarily developed by Charles Coop).How I did it
The
symbol_map
outputs are generated by calling theassembly_to_evm_with_symbol_map
with the correct assembly and then throwing away all of the output except for the symbol map. I confess I cargo-culted the other arguments (pc_ofst
andcompiler_metadata
) with their declared defaults; if these are indeed the correct values to use and they should always just be whatever the defaults are, we can remove their explicit inclusion.The "calling convention" changes simply queries the same functions which determines the calling convention used during codegen and records that during metadata generation.
How to verify it
The
test_output_json
test ensures that the output machinery works as intended.To verify the metadata and symbol map generation works correctly, we can look at the following simple contract:
When using
-f symbol_map_runtime,metadata,opcodes_runtime --experimental-codegen
we get the following output for thesymbol_map
This tells us that
int
starts at PC 119. Looking at the opcodes:We can see that 0x0077 (aka 119) is the PC of the start of int.
Further, we see in the metadata output:
which reflects that
a
is passed via the stack and the return value is on the stack, as we expect.Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Adds additional debugging output for
metadata
and accessing internal mappings generated by the compiler.Cute Animal Picture