mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-19 17:18:24 +08:00
opcodes/aarch64: split off creation of comment text in disassembler
The function aarch64_print_operand (aarch64-opc.c) is responsible for converting an instruction operand into the textual representation of that operand. In some cases, a comment is included in the operand representation, though this (currently) only happens for the last operand of the instruction. In a future commit I would like to enable the new libopcodes styling for AArch64, this will allow objdump and GDB[1] to syntax highlight the disassembler output, however, having operands and comments combined in a single string like this makes such styling harder. In this commit, I propose to extend aarch64_print_operand to take a second buffer. Any comments for the instruction are written into this extra buffer. The two callers of aarch64_print_operand are then updated to pass an extra buffer, and print any resulting comment. In this commit no styling is added, that will come later. However, I have adjusted the output slightly. Before this commit some comments would be separated from the instruction operands with a tab character, while in other cases the comment was separated with two single spaces. After this commit I use a single tab character in all cases. This means a few test cases needed updated. If people would prefer me to move everyone to use the two spaces, then just let me know. Or maybe there was a good reason why we used a mix of styles, I could probably figure out a way to maintain the old output exactly if that is critical. Other than that, there should be no user visible changes after this commit. [1] GDB patches have not been merged yet, but have been posted to the GDB mailing list: https://sourceware.org/pipermail/gdb-patches/2022-June/190142.html
This commit is contained in:
@ -5358,6 +5358,7 @@ print_operands (char *buf, const aarch64_opcode *opcode,
|
||||
for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
|
||||
{
|
||||
char str[128];
|
||||
char cmt[128];
|
||||
|
||||
/* We regard the opcode operand info more, however we also look into
|
||||
the inst->operands to support the disassembling of the optional
|
||||
@ -5370,7 +5371,7 @@ print_operands (char *buf, const aarch64_opcode *opcode,
|
||||
|
||||
/* Generate the operand string in STR. */
|
||||
aarch64_print_operand (str, sizeof (str), 0, opcode, opnds, i, NULL, NULL,
|
||||
NULL, cpu_variant);
|
||||
NULL, cmt, sizeof (cmt), cpu_variant);
|
||||
|
||||
/* Delimiter. */
|
||||
if (str[0] != '\0')
|
||||
@ -5378,6 +5379,15 @@ print_operands (char *buf, const aarch64_opcode *opcode,
|
||||
|
||||
/* Append the operand string. */
|
||||
strcat (buf, str);
|
||||
|
||||
/* Append a comment. This works because only the last operand ever
|
||||
adds a comment. If that ever changes then we'll need to be
|
||||
smarter here. */
|
||||
if (cmt[0] != '\0')
|
||||
{
|
||||
strcat (buf, "\t// ");
|
||||
strcat (buf, cmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1371,7 +1371,7 @@ aarch64_get_opcode (enum aarch64_op);
|
||||
extern void
|
||||
aarch64_print_operand (char *, size_t, bfd_vma, const aarch64_opcode *,
|
||||
const aarch64_opnd_info *, int, int *, bfd_vma *,
|
||||
char **,
|
||||
char **, char *, size_t,
|
||||
aarch64_feature_set features);
|
||||
|
||||
/* Miscellaneous interface. */
|
||||
|
@ -3287,6 +3287,8 @@ print_operands (bfd_vma pc, const aarch64_opcode *opcode,
|
||||
for (i = 0, num_printed = 0; i < AARCH64_MAX_OPND_NUM; ++i)
|
||||
{
|
||||
char str[128];
|
||||
char cmt[128];
|
||||
|
||||
/* We regard the opcode operand info more, however we also look into
|
||||
the inst->operands to support the disassembling of the optional
|
||||
operand.
|
||||
@ -3298,7 +3300,8 @@ print_operands (bfd_vma pc, const aarch64_opcode *opcode,
|
||||
|
||||
/* Generate the operand string in STR. */
|
||||
aarch64_print_operand (str, sizeof (str), pc, opcode, opnds, i, &pcrel_p,
|
||||
&info->target, ¬es, arch_variant);
|
||||
&info->target, ¬es, cmt, sizeof (cmt),
|
||||
arch_variant);
|
||||
|
||||
/* Print the delimiter (taking account of omitted operand(s)). */
|
||||
if (str[0] != '\0')
|
||||
@ -3309,7 +3312,15 @@ print_operands (bfd_vma pc, const aarch64_opcode *opcode,
|
||||
if (pcrel_p)
|
||||
(*info->print_address_func) (info->target, info);
|
||||
else
|
||||
{
|
||||
(*info->fprintf_func) (info->stream, "%s", str);
|
||||
|
||||
/* Print the comment. This works because only the last operand
|
||||
ever adds a comment. If that ever changes then we'll need to
|
||||
be smarter here. */
|
||||
if (cmt[0] != '\0')
|
||||
(*info->fprintf_func) (info->stream, "\t// %s", cmt);
|
||||
}
|
||||
}
|
||||
|
||||
if (notes && !no_notes)
|
||||
|
@ -3229,6 +3229,7 @@ aarch64_print_operand (char *buf, size_t size, bfd_vma pc,
|
||||
const aarch64_opcode *opcode,
|
||||
const aarch64_opnd_info *opnds, int idx, int *pcrel_p,
|
||||
bfd_vma *address, char** notes,
|
||||
char *comment, size_t comment_size,
|
||||
aarch64_feature_set features)
|
||||
{
|
||||
unsigned int i, num_conds;
|
||||
@ -3237,6 +3238,14 @@ aarch64_print_operand (char *buf, size_t size, bfd_vma pc,
|
||||
enum aarch64_modifier_kind kind;
|
||||
uint64_t addr, enum_value;
|
||||
|
||||
if (comment != NULL)
|
||||
{
|
||||
assert (comment_size > 0);
|
||||
comment[0] = '\0';
|
||||
}
|
||||
else
|
||||
assert (comment_size == 0);
|
||||
|
||||
buf[0] = '\0';
|
||||
if (pcrel_p)
|
||||
*pcrel_p = 0;
|
||||
@ -3572,12 +3581,13 @@ aarch64_print_operand (char *buf, size_t size, bfd_vma pc,
|
||||
case 4: /* e.g. MOV Wd, #<imm32>. */
|
||||
{
|
||||
int imm32 = opnd->imm.value;
|
||||
snprintf (buf, size, "#0x%-20x\t// #%d", imm32, imm32);
|
||||
snprintf (buf, size, "#0x%-20x", imm32);
|
||||
snprintf (comment, comment_size, "#%d", imm32);
|
||||
}
|
||||
break;
|
||||
case 8: /* e.g. MOV Xd, #<imm64>. */
|
||||
snprintf (buf, size, "#0x%-20" PRIx64 "\t// #%" PRIi64,
|
||||
opnd->imm.value, opnd->imm.value);
|
||||
snprintf (buf, size, "#0x%-20" PRIx64, opnd->imm.value);
|
||||
snprintf (comment, comment_size, "#%" PRIi64, opnd->imm.value);
|
||||
break;
|
||||
default:
|
||||
snprintf (buf, size, "<invalid>");
|
||||
@ -3675,12 +3685,12 @@ aarch64_print_operand (char *buf, size_t size, bfd_vma pc,
|
||||
num_conds = ARRAY_SIZE (opnd->cond->names);
|
||||
for (i = 1; i < num_conds && opnd->cond->names[i]; ++i)
|
||||
{
|
||||
size_t len = strlen (buf);
|
||||
size_t len = comment != NULL ? strlen (comment) : 0;
|
||||
if (i == 1)
|
||||
snprintf (buf + len, size - len, " // %s = %s",
|
||||
snprintf (comment + len, comment_size - len, "%s = %s",
|
||||
opnd->cond->names[0], opnd->cond->names[i]);
|
||||
else
|
||||
snprintf (buf + len, size - len, ", %s",
|
||||
snprintf (comment + len, comment_size - len, ", %s",
|
||||
opnd->cond->names[i]);
|
||||
}
|
||||
break;
|
||||
|
Reference in New Issue
Block a user