aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-06-23 14:49:55 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-10-02 11:58:28 +0100
commit08f406e9a1e3b83d0778493cb219075bbae7bb59 (patch)
tree398a06f209c2011a1166fd604a016ba071da87ac /gdb/mi
parent924272f2bf5e398412473b14041f84397293c3d3 (diff)
downloadgdb-08f406e9a1e3b83d0778493cb219075bbae7bb59.zip
gdb-08f406e9a1e3b83d0778493cb219075bbae7bb59.tar.gz
gdb-08f406e9a1e3b83d0778493cb219075bbae7bb59.tar.bz2
gdb/mi: new options for -data-disassemble command
Now that the disassembler has two different strategies for laying out the opcode bytes of an instruction (see /r vs /b for the disassemble command), I wanted to add support for this to the MI disassemble command. Currently the -data-disassemble command takes a single 'mode' value, which currently has 6 different values (0 -> 5), 3 of these modes relate to opcode display. So, clearly I should just add an additional 3 modes to handle the new opcode format, right? No, I didn't think that was a great idea either. So, I wonder, could I adjust the -data-disassemble command in a backward compatible way, that would allow GDB to move away from using the mode value altogether? I think we can. In this commit, I propose adding two new options to -data-disassemble, these are: --opcodes none|bytes|display --source Additionally, I will make the mode optional, and default to mode 0 if no mode value is given. Mode 0 is the simplest, no source code, no opcodes disassembly mode. The two new options are only valid for mode 0, if they are used with any other mode then an error is thrown. The --opcodes option can add opcodes to the result, with 'bytes' being equivalent to 'disassemble /b' and 'display' being 'disassemble /r'. The --source option will enable the /s style source code display, this is equivalent to modes 4 and 5. There is no way, using the new command options to get the now deprecated /m style source code display, that is mode 1 and 3. My hope is that new users of the MI will not use the mode at all, and instead will just use the new options to achieve the output they need. Existing MI users can continue to use the mode, and will not need to be updated to use the new options.
Diffstat (limited to 'gdb/mi')
-rw-r--r--gdb/mi/mi-cmd-disas.c75
1 files changed, 68 insertions, 7 deletions
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index 4f6e561..db5a788 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -68,6 +68,8 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
bool start_seen = false;
bool end_seen = false;
bool addr_seen = false;
+ bool opcodes_seen = false;
+ bool source_seen = false;
/* ... and their corresponding value. */
char *file_string = NULL;
@@ -77,12 +79,23 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
CORE_ADDR high = 0;
CORE_ADDR addr = 0;
+ /* Flags to handle the --opcodes option. */
+ enum opcodes_mode
+ {
+ OPCODES_DEFAULT, OPCODES_NONE, OPCODES_DISPLAY, OPCODES_BYTES
+ };
+ enum opcodes_mode opcodes_mode = OPCODES_DEFAULT;
+
+ /* Handle the -source option. */
+ bool show_source = false;
+
/* Options processing stuff. */
int oind = 0;
char *oarg;
enum opt
{
- FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
+ FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT, OPCODES_OPT,
+ SHOW_SRC_OPT
};
static const struct mi_opt opts[] =
{
@@ -92,6 +105,8 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
{"s", START_OPT, 1},
{"e", END_OPT, 1},
{"a", ADDR_OPT, 1},
+ {"-opcodes", OPCODES_OPT, 1},
+ {"-source", SHOW_SRC_OPT, 0},
{ 0, 0, 0 }
};
@@ -129,6 +144,21 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
addr = parse_and_eval_address (oarg);
addr_seen = true;
break;
+ case OPCODES_OPT:
+ opcodes_seen = true;
+ if (strcmp (oarg, "none") == 0)
+ opcodes_mode = OPCODES_NONE;
+ else if (strcmp (oarg, "display") == 0)
+ opcodes_mode = OPCODES_DISPLAY;
+ else if (strcmp (oarg, "bytes") == 0)
+ opcodes_mode = OPCODES_BYTES;
+ else
+ error (_("-data-disassemble: unknown value for -opcodes argument"));
+ break;
+ case SHOW_SRC_OPT:
+ source_seen = true;
+ show_source = true;
+ break;
}
}
argv += oind;
@@ -146,13 +176,23 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen
&& addr_seen))
- || argc != 1)
- error (_("-data-disassemble: Usage: ( [-f filename -l linenum "
- "[-n howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
+ || argc > 1)
+ error (_("-data-disassemble: Usage: "
+ "( -f filename -l linenum [-n howmany] |"
+ " -s startaddr -e endaddr | -a addr ) "
+ "[ --opcodes mode ] [ --source ] [ [--] mode ]."));
+
+ if (argc == 1)
+ {
+ mode = atoi (argv[0]);
+ if (mode < 0 || mode > 5)
+ error (_("-data-disassemble: Mode argument must be in the range 0-5."));
+ }
+ else
+ mode = 0;
- mode = atoi (argv[0]);
- if (mode < 0 || mode > 5)
- error (_("-data-disassemble: Mode argument must be in the range 0-5."));
+ if (mode != 0 && (source_seen || opcodes_seen))
+ error (_("-data-disassemble: --opcodes and --source can only be used with mode 0"));
/* Convert the mode into a set of disassembly flags. */
@@ -180,6 +220,27 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
gdb_assert_not_reached ("bad disassembly mode");
}
+ /* Now handle the (optional) --opcodes argument. This partially
+ overrides the mode value. */
+ if (opcodes_mode != OPCODES_DEFAULT)
+ {
+ /* Remove any existing flags related to opcodes display. */
+ disasm_flags &= ~(DISASSEMBLY_RAW_BYTES | DISASSEMBLY_RAW_INSN);
+
+ /* Add back any required flags. */
+ if (opcodes_mode == OPCODES_DISPLAY)
+ disasm_flags |= DISASSEMBLY_RAW_INSN;
+ else if (opcodes_mode == OPCODES_BYTES)
+ disasm_flags |= DISASSEMBLY_RAW_BYTES;
+ }
+
+ /* Handle the optional --source argument. */
+ if (show_source)
+ {
+ disasm_flags &= ~DISASSEMBLY_SOURCE_DEPRECATED;
+ disasm_flags |= DISASSEMBLY_SOURCE;
+ }
+
/* We must get the function beginning and end where line_num is
contained. */