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

Instruction debug fmt improvements #546

Merged
merged 4 commits into from
Aug 10, 2023
Merged

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal commented Aug 9, 2023

Currently the reason.instruction sub-field of PanicInstruction is just a raw integer representation of the instruction bytes. This PR changes the Debug implementation to decode the instruction when possible. It will also show the bytes in hexadecimal format, which is more useful for debugging as it can be used to spot the instruction in a hexdump, and it shows the opcode byte separately.

This PR also changes the debug format of register (non-immediate) operands to be hexadecimal, as it is the established convention (e.g. the specification lists registers using hex values, and do does most of the test code).

Before

reason: PanicInstruction {
    reason: OutOfGas,
    instruction: 1920991264,
},
reason: PanicInstruction {
    reason: ErrorFlag,
    instruction: 0,
},

After

reason: PanicInstruction {
    reason: OutOfGas,
    instruction: MOVI { dst: 0x20, val: 32 } (bytes 72 80 00 20),
}
reason: PanicInstruction {
    reason: ErrorFlag,
    instruction: Unknown (bytes 00 00 00 00),
},

@Dentosal Dentosal added tech-debt fuel-asm Related to the `fuel-asm` crate. labels Aug 9, 2023
@Dentosal Dentosal requested a review from a team August 9, 2023 23:06
@Dentosal Dentosal self-assigned this Aug 9, 2023
Copy link
Member

@MitchTurner MitchTurner left a comment

Choose a reason for hiding this comment

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

LGTM. I just left a couple nits.
I hadn't thought of just adding it to the Debug. This seems like a good way to get what we wanted without touching much code.

Ok(instr) => write!(f, "{:?}", instr)?,
Err(_) => write!(f, "Unknown")?,
};
write!(f, " (bytes ")?;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think I'd prefer bytes: .

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, changed.

fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match Instruction::try_from(self.0) {
Ok(instr) => write!(f, "{:?}", instr)?,
Err(_) => write!(f, "Unknown")?,
Copy link
Member

@MitchTurner MitchTurner Aug 9, 2023

Choose a reason for hiding this comment

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

Nit: Maybe something like Unknown Instruction or Unknown Operation might be slightly more clear when the caller doesn't know what to expect in this field. I don't feel strongly about it though.

Copy link
Member Author

Choose a reason for hiding this comment

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

It already says instruction: Unknown, so I think it's good enough

xgreenx
xgreenx previously approved these changes Aug 10, 2023
Copy link
Collaborator

@xgreenx xgreenx left a comment

Choose a reason for hiding this comment

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

I like both variants=D

Merged via the queue into master with commit a364fc8 Aug 10, 2023
33 checks passed
@Dentosal Dentosal deleted the dento/instruction-dbg-fmt branch August 10, 2023 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuel-asm Related to the `fuel-asm` crate. tech-debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants