( -s @var{start-addr} -e @var{end-addr}
| -a @var{addr}
| -f @var{filename} -l @var{linenum} [ -n @var{lines} ] )
- -- @var{mode}
+ [ --opcodes @var{opcodes-mode} ]
+ [ --source ]
+ [ -- @var{mode} ]
@end smallexample
@noindent
displayed; if @var{lines} is higher than the number of lines between
@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
are displayed.
+@item @var{opcodes-mode}
+can only be used with @var{mode} 0, and should be one of the following:
+@table @samp
+@item none
+no opcode information will be included in the result.
+
+@item bytes
+opcodes will be included in the result, the opcodes will be formatted
+as for @kbd{disassemble /b}.
+
+@item display
+opcodes will be included in the result, the opcodes will be formatted
+as for @kbd{disassemble /r}.
+@end table
@item @var{mode}
-is one of:
-@itemize @bullet
-@item 0 disassembly only
-@item 1 mixed source and disassembly (deprecated)
-@item 2 disassembly with raw opcodes
-@item 3 mixed source and disassembly with raw opcodes (deprecated)
-@item 4 mixed source and disassembly
-@item 5 mixed source and disassembly with raw opcodes
-@end itemize
+the use of @var{mode} is deprecated in favour of using the
+@code{--opcodes} and @code{--source} options. When no @var{mode} is
+given, @var{mode} 0 will be assumed. However, the @var{mode} is still
+available for backward compatibility. The @var{mode} should be one of:
+@table @samp
+@item 0
+@emph{disassembly only}, this is the default mode if no mode is
+specified.
+
+@item 1
+@emph{mixed source and disassembly (deprecated)}, it is not possible
+to recreate this mode using @code{--opcodes} and @code{--source}
+options.
+
+@item 2
+@emph{disassembly with raw opcodes}, this mode is equivalent to using
+@var{mode} 0 and passing @code{--opcodes bytes} to the command.
+
+@item 3
+@emph{mixed source and disassembly with raw opcodes (deprecated)}, it
+is not possible to recreate this mode using @code{--opcodes} and
+@code{--source} options.
+
+@item 4
+@emph{mixed source and disassembly}, this mode is equivalent to using
+@var{mode} 0 and passing @code{--source} to the command.
+@item 5
+@emph{mixed source and disassembly with raw opcodes}, this mode is
+equivalent to using @var{mode} 0 and passing @code{--opcodes bytes}
+and @code{--source} to the command.
+@end table
Modes 1 and 3 are deprecated. The output is ``source centric''
which hasn't proved useful in practice.
@xref{Machine Code}, for a discussion of the difference between
@code{/m} and @code{/s} output of the @code{disassemble} command.
@end table
+The @code{--source} can only be used with @var{mode} 0. Passing this
+option will include the source code in the disassembly result as if
+@var{mode} 4 or 5 had been used.
+
@subsubheading Result
The result of the @code{-data-disassemble} command will be a list named
-@samp{asm_insns}, the contents of this list depend on the @var{mode}
-used with the @code{-data-disassemble} command.
+@samp{asm_insns}, the contents of this list depend on the options used
+with the @code{-data-disassemble} command.
-For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
-following fields:
+For modes 0 and 2, and when the @code{--source} option is not used, the
+@samp{asm_insns} list contains tuples with the following fields:
@table @code
@item address
The text disassembly for this @samp{address}.
@item opcodes
-This field is only present for modes 2, 3 and 5. This contains the
-raw opcode bytes for the @samp{inst} field. The bytes are formatted
-as single bytes, in hex, in ascending address order, with a single
-space between each byte.
+This field is only present for modes 2, 3 and 5, or when the
+@code{--opcodes} option @samp{bytes} or @samp{display} is used. This
+contains the raw opcode bytes for the @samp{inst} field.
+
+When the @samp{--opcodes} option is not passed to
+@code{-data-disassemble}, or the @samp{bytes} value is passed to
+@samp{--opcodes}, then the bytes are formatted as a series of single
+bytes, in hex, in ascending address order, with a single space between
+each byte. This format is equivalent to the @samp{/b} option being
+used with the @kbd{disassemble} command
+(@pxref{disassemble,,@kbd{disassemble}}).
+When @samp{--opcodes} is passed the value @samp{display} then the bytes
+are formatted in the natural instruction display order. This means
+multiple bytes can be grouped together, and the bytes might be
+byte-swapped. This format is equivalent to the @samp{/r} option being
+used with the @kbd{disassemble} command.
@end table
-For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
-@samp{src_and_asm_line}, each of which has the following fields:
+For modes 1, 3, 4 and 5, or when the @code{--source} option is used, the
+@samp{asm_insns} list contains tuples named @samp{src_and_asm_line},
+each of which has the following fields:
@table @code
@item line
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;
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[] =
{
{"s", START_OPT, 1},
{"e", END_OPT, 1},
{"a", ADDR_OPT, 1},
+ {"-opcodes", OPCODES_OPT, 1},
+ {"-source", SHOW_SRC_OPT, 0},
{ 0, 0, 0 }
};
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;
|| (!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. */
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. */
mi_gdb_test "print/x \$pc" "" ""
- mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
- "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
- "data-disassemble from pc to pc+12 assembly only"
- mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
- "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
- "data-disassemble function around pc assembly only"
+ foreach { test_name option_string } [list "mode 0" "-- 0" \
+ "default mode" "" ] {
+ with_test_prefix $test_name {
+ mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" ${option_string}" \
+ "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+ "data-disassemble from pc to pc+12 assembly only"
- mi_gdb_test "113-data-disassemble -a callee4 -- 0" \
- "113\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
- "data-disassemble function callee4 assembly only"
+ mi_gdb_test "112-data-disassemble -a \$pc ${option_string}" \
+ "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+ "data-disassemble function around pc assembly only"
- mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 0" \
- "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
- "data-disassemble file & line, assembly only"
+ mi_gdb_test "113-data-disassemble -a callee4 ${option_string}" \
+ "113\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+ "data-disassemble function callee4 assembly only"
+
+ mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body ${option_string}" \
+ "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}\\\]" \
+ "data-disassemble file & line, assembly only"
+ }
+ }
}
proc test_disassembly_with_opcodes {} {
# -data-disassembly -f basics.c -l $line_main_body -- 2
mi_gdb_test "print/x \$pc" "" ""
- mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 2" \
- "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\]" \
- "data-disassemble from pc to pc+12 assembly with opcodes"
- mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body -- 2" \
- "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",opcodes=\".*\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]" \
- "data-disassemble file & line, assembly with opcodes"
+ foreach { test_name option_string} [list "mode 2" "-- 2" \
+ "mode 0 and --opcodes bytes" "--opcodes bytes -- 0" \
+ "default mode and --opcodes bytes" "--opcodes bytes"] {
+ with_test_prefix $test_name {
+ mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" ${option_string}" \
+ "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\]" \
+ "data-disassemble from pc to pc+12 assembly"
+
+ mi_gdb_test "222-data-disassemble -f basics.c -l $line_main_body ${option_string}" \
+ "222\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"0\",opcodes=\".*\",inst=\".*\"\},.*,\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]" \
+ "data-disassemble file & line, assembly"
+ }
+ }
}
proc test_disassembly_lines_limit {} {
"data-disassemble bogus address, -a"
mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
- "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
- "data-disassemble mix different args"
+ "456\\^error,msg=\"-data-disassemble: Usage: \\( -f filename -l linenum .-n howmany. \\| -s startaddr -e endaddr \\| -a addr \\) . --opcodes mode . . --source . . .--. mode .\\.\"" \
+ "data-disassemble mix different args"
mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
"789\\^error,msg=\"-data-disassemble: Mode argument must be in the range 0-5.\"" \
- "data-disassemble wrong mode arg"
+ "data-disassemble wrong mode arg"
+
+ foreach mode { 1 2 3 4 5 } {
+ foreach opcode_arg { none bytes display } {
+ mi_gdb_test "801-data-disassemble -s \$pc -e \"\$pc + 12\" --opcodes ${opcode_arg} -- ${mode}" \
+ "801\\^error,msg=\"-data-disassemble: --opcodes and --source can only be used with mode 0\"" \
+ "data-disassemble use --opcode ${opcode_arg} with mode ${mode}"
+ }
+ mi_gdb_test "802-data-disassemble -s \$pc -e \"\$pc + 12\" --source -- ${mode}" \
+ "802\\^error,msg=\"-data-disassemble: --opcodes and --source can only be used with mode 0\"" \
+ "data-disassemble use --source with mode ${mode}"
+ }
}
# Check the format of the opcode bytes.