Skip to content
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

feat(chisel): rawstack / rs command #3982

Merged
merged 5 commits into from
Dec 28, 2022

Conversation

clabby
Copy link
Contributor

@clabby clabby commented Dec 28, 2022

Overview

Adds a new !rawstack / !rs command to chisel that displays the raw value of a variable's stack allocation.

Motivation

Feature requested by @transmissions11

Solution

  1. Clone the current session source.
  2. Append the following code to the cloned source's run() function, where to_inspect is the argument supplied to !rawstack
bytes32 __raw__;
assembly {
    __raw__ := to_inspect
}
  1. Inspect the __raw__ variable.

Usage

Screenshot from 2022-12-28 14-31-32

@transmissions11
Copy link
Contributor

fireee

@transmissions11
Copy link
Contributor

how/does this work w/ memory types like strings or packed structs?

@clabby
Copy link
Contributor Author

clabby commented Dec 28, 2022

how/does this work w/ memory types like strings or packed structs?

For memory types, it'll just give you the memory pointer (which is the corresponding stack value for any memory var).

bytes32 __raw__;
assembly {
    // if `to_inspect` is a memory var, it will equal the pointer to the var's data in memory
    __raw__ := to_inspect
}

Included that piece in the help menu for anyone unfamiliar w/ how that works 😄

@mattsse mattsse added T-feature Type: feature C-chisel Command: chisel labels Dec 28, 2022
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codewise lgtm, pending approval @transmissions11

Comment on lines 653 to 655
DispatchResult::CommandFailed(String::from(
"Variable must exist within `run()` function.",
))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
DispatchResult::CommandFailed(String::from(
"Variable must exist within `run()` function.",
))
DispatchResult::CommandFailed(
"Variable must exist within `run()` function.".to_string())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's definitely some inconsistencies across chisel w/ String::from(...) / .to_owned() / .to_string(). Is to_string() what you guys normally go w/ ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are all the same, but to_string is preferable because it is immediately clear what it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it- changed this one for now, can go through and change others when I get back home 👍

@mattsse
Copy link
Member

mattsse commented Dec 28, 2022

there are apparently conflicts, but github doesn't display which files are affected -.-

@clabby could you please merge master and resolve conflicts

@clabby
Copy link
Contributor Author

clabby commented Dec 28, 2022

there are apparently conflicts, but github doesn't display which files are affected -.-

@clabby could you please merge master and resolve conflicts

Done 👍

@mattsse mattsse merged commit 135ee3e into foundry-rs:master Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-chisel Command: chisel T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants