binutils-gdb/include/opcode
Andrew Burgess 76a4c1e063 libopcodes/aarch64: add support for disassembler styling
This commit enables disassembler styling for AArch64.  After this
commit it is possible to have objdump style AArch64 disassembler
output (using --disassembler-color option).  Once the required GDB
patches are merged, GDB will also style the disassembler output.

The changes to support styling are mostly split between two files
opcodes/aarch64-dis.c and opcodes/aarch64-opc.c.

The entry point for the AArch64 disassembler can be found in
aarch64-dis.c, this file handles printing the instruction mnemonics,
and assembler directives (e.g. '.byte', '.word', etc).  Some operands,
mostly relating to assembler directives are also printed from this
file.  This commit changes all of this to pass through suitable
styling information.

However, for most "normal" instructions, the instruction operands are
printed using a two step process.  From aarch64-dis.c, in the
print_operands function, the function aarch64_print_operand is called,
this function is in aarch64-opc.c, and converts an instruction operand
into a string.  Then, back in print_operands (aarch64-dis.c), the
operand string is printed.

Unfortunately, the string returned by aarch64_print_operand can be
quite complex, it will include syntax elements, like '[' and ']', in
addition to register names and immediate values.  In some cases, a
single operand will expand into what will appear (to the user) as
multiple operands separated with a ','.

This makes the task of styling more complex, all these different
components need to by styled differently, so we need to get the
styling information out of aarch64_print_operand in some way.

The solution that I propose here is similar to the solution that I
used for the i386 disassembler.

Currently, aarch64_print_operand uses snprintf to write the operand
text into a buffer provided by the caller.

What I propose is that we pass an extra argument to the
aarch64_print_operand function, this argument will be a structure, the
structure contains a callback function and some state.

When aarch64_print_operand needs to format part of its output this can
be done by using the callback function within the new structure, this
callback returns a string with special embedded markers that indicate
which mode should be used for each piece of text.  Back in
aarch64-dis.c we can spot these special style markers and use this to
split the disassembler output up and apply the correct style to each
piece.

To make aarch64-opc.c clearer a series of new static functions have
been added, e.g. 'style_reg', 'style_imm', etc.  Each of these
functions formats a piece of text in a different style, 'register' and
'immediate' in this case.

Here's an example taken from aarch64-opc.c of the new functions in
use:

    snprintf (buf, size, "[%s, %s]!",
              style_reg (styler, base),
              style_imm (styler, "#%d", opnd->addr.offset.imm));

The aarch64_print_operand function is also called from the assembler
to aid in printing diagnostic messages.  Right now I have no plans to
add styling to the assembler output, and so, the callback function
used in the assembler ignores the styling information and just returns
an plain string.

I've used the source files in gas/testsuite/gas/aarch64/ for testing,
and have manually gone through and checked that the styling looks
reasonable, however, I'm not an AArch64 expert, so it is possible that
the odd piece is styled incorrectly.  Please point out any mistakes
I've made.

With objdump disassembler color turned off, there should be no change
in the output after this commit.
2022-07-29 13:58:32 +01:00
..
aarch64.h libopcodes/aarch64: add support for disassembler styling 2022-07-29 13:58:32 +01:00
alpha.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
arc-attrs.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
arc-func.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
arc.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
arm.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
avr.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
bfin.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
cgen.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ChangeLog-0415
ChangeLog-9103
convex.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
cr16.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
cris.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
crx.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
csky.h Remove use of bfd_uint64_t and similar 2022-05-27 22:08:59 +09:30
d10v.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
d30v.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
dlx.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ft32.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
h8300.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
hppa.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
i386.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ia64.h Remove use of bfd_uint64_t and similar 2022-05-27 22:08:59 +09:30
loongarch.h gas:LoongArch: Fix segment error in compilation due to too long symbol name. 2022-03-20 09:37:12 +08:00
m68hc11.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
m68k.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
metag.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
mips.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
mmix.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
mn10200.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
mn10300.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
moxie.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
msp430-decode.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
msp430.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
nds32.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
nfp.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
nios2.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
nios2r1.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
nios2r2.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
np1.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ns32k.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
pdp11.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
pj.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
pn.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ppc.h ppc: extend opindex to 16 bits 2022-05-25 12:13:44 +09:30
pru.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
pyr.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
riscv-opc.h RISC-V: Add 'Sstc' extension and its CSRs 2022-06-28 09:08:42 +08:00
riscv.h RISC-V: Added Zfhmin and Zhinxmin. 2022-07-07 16:23:54 +08:00
rl78.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
rx.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
s12z.h
s390.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
score-datadep.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
score-inst.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
sparc.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
spu-insns.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
spu.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tic4x.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tic6x-control-registers.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tic6x-insn-formats.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tic6x-opcode-table.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tic6x.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tic30.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tic54x.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tilegx.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
tilepro.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
v850.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
vax.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
visium.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
wasm.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
xgate.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30