Skip to content

Commit

Permalink
opcodes: Add non-enum disassembler options
Browse files Browse the repository at this point in the history
This is paired with "gdb: Add non-enum disassembler options".

There is a portable mechanism for disassembler options and used on some
architectures:

-   ARC
-   Arm
-   MIPS
-   PowerPC
-   RISC-V
-   S/390

However, it only supports following forms:

-   [NAME]
-   [NAME]=[ENUM_VALUE]

Valid values for [ENUM_VALUE] must be predefined in
disasm_option_arg_t.values. For instance, for -M cpu=[CPU] in ARC
architecture, opcodes/arc-dis.c builds valid CPU model list from
include/elf/arc-cpu.def.

In this commit, it adds following format:

-   [NAME]=[ARBITRARY_VALUE] (cannot contain "," though)

This is identified by NULL value of disasm_option_arg_t.values
(normally, this is a non-NULL pointer to a NULL-terminated list).

include/ChangeLog:

	* dis-asm.h (disasm_option_arg_t): Update comment of values
	to allow non-enum disassembler options.

opcodes/ChangeLog:

	* riscv-dis.c (print_riscv_disassembler_options): Support
	non-enum disassembler options on printing disassembler help.
	* arc-dis.c (print_arc_disassembler_options): Likewise.
	* mips-dis.c (print_mips_disassembler_options): Likewise.
  • Loading branch information
a4lg committed Sep 6, 2022
1 parent a49fdb4 commit 9869e2e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/dis-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ typedef struct
/* Option argument name to use in descriptions. */
const char *name;

/* Vector of acceptable option argument values, NULL-terminated. */
/* Vector of acceptable option argument values, NULL-terminated.
NULL if any values are accepted. */
const char **values;
} disasm_option_arg_t;

Expand Down
2 changes: 2 additions & 0 deletions opcodes/arc-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,8 @@ print_arc_disassembler_options (FILE *stream)
for (i = 0; args[i].name != NULL; ++i)
{
size_t len = 3;
if (args[i].values == NULL)
continue;
fprintf (stream, _("\n\
For the options above, the following values are supported for \"%s\":\n "),
args[i].name);
Expand Down
2 changes: 2 additions & 0 deletions opcodes/mips-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,8 @@ with the -M switch (multiple options should be separated by commas):\n\n"));

for (i = 0; args[i].name != NULL; i++)
{
if (args[i].values == NULL)
continue;
fprintf (stream, _("\n\
For the options above, the following values are supported for \"%s\":\n "),
args[i].name);
Expand Down
2 changes: 2 additions & 0 deletions opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,8 @@ with the -M switch (multiple options should be separated by commas):\n"));

for (i = 0; args[i].name != NULL; i++)
{
if (args[i].values == NULL)
continue;
fprintf (stream, _("\n\
For the options above, the following values are supported for \"%s\":\n "),
args[i].name);
Expand Down

0 comments on commit 9869e2e

Please sign in to comment.