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

improve intel instruction & operand formatting #1463

Merged
merged 2 commits into from Jul 25, 2023

Conversation

kupsch
Copy link
Contributor

@kupsch kupsch commented Jul 25, 2023

This fixes three issues when formatting an x86_64 instruction or its operands:

  1. Fix the order of operands when formatting the instruction to be the
    AT&T syntax order. If the instruction had three or more operands.
    Conversion from the internal (Intel) order rotated right by 1 instead
    of reversing the operands.
    Fixes Fix x86_64 instruction formatting for >2 operands #1459

  2. Eliminate special treatment of register %kN as the first operand as
    mask registers in Instruction::format as Operand::format already
    formats these as masks (enclosed in braces) and not all uses of mask
    registers are as a mask.
    Fixes formatting x86_64 instruction incorrectly makes kN registers masks in some cases #1461

  3. Fix Operand::format to produce the correct disassembly operand
    string. The formatting of the internal Expression needs to be done
    for some indirect values. This was done in the Instruction::format
    instead of directly in Operand::format
    Fixes Intel X86_64 operand formatting is incorrect #1460

Methods changed:

  • x86Formatter::getInstructionString - fixes 1, 2, 3
  • Operand::format - fixes 3
  • x86Formatter::formatRegister - cleanup, remove malloc that could leak

This fixes three issues when formatting an x86_64 instruction or its
operands:

1) Fix the order of operands when formatting the instruction to be the
   AT&T syntax order.  If the instruction had three or more operands.
   Conversion from the internal (Intel) order rotated right by 1 instead
   of reversing the operands.

2) Eliminate special treatment of register %kN as the first operand as
   mask registers in Instruction::format as Operand::format already
   formats these as masks (enclosed in braces) and not all uses of mask
   registers are as a mask.

3) Fix Operand::format to produce the correct disassembly operand
   string.  The formatting of the internal Expression needs to be done
   for some indirect values.  This was done in the Instruction::format
   instead of directly in Operand::format

* x86Formatter::getInstructionString - fixes 1, 2, 3

* Operand::format - fixes 3

* x86Formatter::formatRegister - cleanup, remove malloc that could leak
@kupsch kupsch added bug code cleanup Bring the code up to modern standards or remove deprecated features instructionAPI This issue is directly related to instructionAPI x86_64 Related to x86 family of ISAs labels Jul 25, 2023
@kupsch kupsch requested a review from hainest July 25, 2023 14:34
@kupsch kupsch self-assigned this Jul 25, 2023
} else {
source_ops += "," + op;
}
std::string s;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a quick comment with an example? On first pass, I missed the 'r' in crbegin.

Since we're in here fixing things, we might as well change the param to a const&. But I'll let you decide if you want to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment. What type of example are looking for?

I was going to update the ArchSpecificFormatter interface to use const refs for vectors and strings for all the methods in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess an example wouldn't really be helpful here.

} else {
source_ops += "," + op;
}
std::string s;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess an example wouldn't really be helpful here.

@kupsch kupsch merged commit 25ad35c into dyninst:master Jul 25, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug code cleanup Bring the code up to modern standards or remove deprecated features instructionAPI This issue is directly related to instructionAPI x86_64 Related to x86 family of ISAs
Projects
None yet
2 participants