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

Add a name_to_register routine to convert names into register numbers #532

Merged
merged 1 commit into from
Aug 29, 2020

Conversation

nbaksalyar
Copy link
Contributor

This PR adds a converse of register_name, i.e. a function that converts a string register name into a register number. It's useful for debugger command-line interfaces.

Please let me know if this needs a test case.

Copy link
Collaborator

@philipc philipc left a comment

Choose a reason for hiding this comment

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

I suspect that this is not really what you want.

  • do you want RA to be a register name?
  • how are you going to handle rax/eax/ax/ah/al?
  • how are you going to handle synonyms for ARM register names?

I haven't looked at what gdb/lldb do, but you may not even want to use the DWARF register numbers in user interface code. One of the other register numbering schemes might be better (e.g. ptrace or your assembler/disassembler).

src/arch.rs Outdated
@@ -19,6 +19,16 @@ macro_rules! registers {
_ => return None,
}
}

/// Converts a register name into a register number.
pub fn name_to_register(value: &'static str) -> Option<Register> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub fn name_to_register(value: &'static str) -> Option<Register> {
pub fn name_to_register(name: &str) -> Option<Register> {

@nbaksalyar
Copy link
Contributor Author

I haven't looked at what gdb/lldb do, but you may not even want to use the DWARF register numbers in user interface code

Yes, more likely these are going to be used only as helper methods and not directly in the UI code.

Thanks for the review!

Copy link
Collaborator

@philipc philipc left a comment

Choose a reason for hiding this comment

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

Thanks!

@philipc philipc merged commit e046ca5 into gimli-rs:master Aug 29, 2020
@nbaksalyar nbaksalyar deleted the convert-string-into-register branch August 30, 2020 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants