[PATCH] MI disassemble opcode support
Andrew Burgess
aburgess@broadcom.com
Tue Jan 4 11:35:00 GMT 2011
On 28/12/2010 05:47, Joel Brobecker wrote:
>
> I think a NEWS entry might be worthwhile (this can be treated as a
> separate patch
I've included a NEWS entry in the same style as the ChangeLog entries (that is, not an actual patch) hopefully this is correct.
> The alignment of your ChangeLog entries is incorrect. Everything should
> be aligned on a tabulation.
Fixed below.
> A general comment: The ChangeLog should explain the WHAT. If you feel
> that you need to explain the WHY, that comment should be in the code.
Ok, I've updated the comments/ChangeLog.
> Formatting: space before the first '(', and also space after the
> unsigned cast.
Ooops, sorry! Fixed.
>
>> error
>> ("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mixed_mode.");
>
> This error message need to be updated (replace "mixed_mode" by "mode").
Done, tests updated to match.
>> + /* Convert the mode into a set of disassembly flags */
>
> Period and 2 spaces at the end of the sentence.
Done.
As I don't have commit access I'm hoping someone who does will commit this for me please.
Thanks,
Andrew
gdb/
2010-12-10 Andrew Burgess <aburgess@broadcom.com>
* disasm.c (dump_insns): Support dumping opcodes for MI.
gdb/doc/
2010-12-10 Andrew Burgess <aburgess@broadcom.com>
* gdb.texinfo (GDB/MI Data Manipulation): Update to reflect
changes in mi/mi-cmd-disas.c
gdb/mi/
2010-12-10 Andrew Burgess <aburgess@broadcom.com>
* mi-cmd-disas.c (mi_cmd_disassemble): Allow mode to control
dumping of instruction opcodes.
gdb/testsuite/
2010-12-10 Andrew Burgess <aburgess@broadcom.com>
* gdb.mi/mi-disassemble.exp, gdb.mi/mi2-disassemble.exp: Update
expected output to reflect changes in gdb/mi/mi-cmd-disas.c and
add new tests for opcode dumping.
gdb/NEWS
* The -data-disassemble MI command now supports modes 2 and 3 for dumping
the instruction opcodes.
diff --git a/gdb/disasm.c b/gdb/disasm.c
index c51f0bf..d57bf90 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -143,6 +143,13 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
CORE_ADDR old_pc = pc;
bfd_byte data;
int status;
+ const char *spacer = "";
+
+ /* Build the opcodes using a temporary stream so we can
+ write them out in a single go for the MI. */
+ struct ui_stream *opcode_stream = ui_out_stream_new (uiout);
+ struct cleanup *cleanups =
+ make_cleanup_ui_out_stream_delete (opcode_stream);
pc += gdbarch_print_insn (gdbarch, pc, di);
for (;old_pc < pc; old_pc++)
@@ -150,9 +157,14 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
status = (*di->read_memory_func) (old_pc, &data, 1, di);
if (status != 0)
(*di->memory_error_func) (status, old_pc, di);
- ui_out_message (uiout, 0, " %02x", (unsigned)data);
+ fprintf_filtered (opcode_stream->stream, "%s%02x",
+ spacer, (unsigned) data);
+ spacer = " ";
}
+ ui_out_field_stream (uiout, "opcodes", opcode_stream);
ui_out_text (uiout, "\t");
+
+ do_cleanups (cleanups);
}
else
pc += gdbarch_print_insn (gdbarch, pc, di);
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ddc711b..57c89a8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -27567,8 +27567,9 @@ 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{mode}
-is either 0 (meaning only disassembly) or 1 (meaning mixed source and
-disassembly).
+is either 0 (meaning only disassembly), 1 (meaning mixed source and
+disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
+mixed source and disassembly with raw opcodes).
@end table
@subsubheading Result
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index b543acc..b4564e8 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -40,21 +40,24 @@
FILENAME: The name of the file where we want disassemble from.
LINE: The line around which we want to disassemble. It will
disassemble the function that contins that line.
- HOW_MANY: Number of disassembly lines to display. In mixed mode, it
+ HOW_MANY: Number of disassembly lines to display. With source, it
is the number of disassembly lines only, not counting the source
lines.
always required:
- MODE: 0 or 1 for disassembly only, or mixed source and disassembly,
- respectively. */
+ MODE: 0 -- disassembly.
+ 1 -- disassembly and source.
+ 2 -- disassembly and opcodes.
+ 3 -- disassembly, source and opcodes.
+*/
void
mi_cmd_disassemble (char *command, char **argv, int argc)
{
struct gdbarch *gdbarch = get_current_arch ();
CORE_ADDR start;
- int mixed_source_and_assembly;
+ int mode, disasm_flags;
struct symtab *s;
/* Which options have we processed ... */
@@ -129,16 +132,23 @@ mi_cmd_disassemble (char *command, char **argv, int argc)
|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen)
|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen)))
error
- ("mi_cmd_disassemble: Usage: ( [-f filename -l linenum [-n howmany]] | [-s startaddr -e endaddr]) [--] mixed_mode.");
+ ("mi_cmd_disassemble: Usage: ( [-f filename -l linenum [-n howmany]] | [-s startaddr -e endaddr]) [--] mode.");
if (argc != 1)
error
- ("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mixed_mode.");
+ ("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mode.");
- mixed_source_and_assembly = atoi (argv[0]);
- if ((mixed_source_and_assembly != 0) && (mixed_source_and_assembly != 1))
- error (_("mi_cmd_disassemble: Mixed_mode argument must be 0 or 1."));
+ mode = atoi (argv[0]);
+ if (mode < 0 || mode > 3)
+ error (_("mi_cmd_disassemble: Mode argument must be 0, 1, 2, or 3."));
+ /* Convert the mode into a set of disassembly flags. */
+
+ disasm_flags = 0;
+ if (mode & 0x1)
+ disasm_flags |= DISASSEMBLY_SOURCE;
+ if (mode & 0x2)
+ disasm_flags |= DISASSEMBLY_RAW_INSN;
/* We must get the function beginning and end where line_num is
contained. */
@@ -156,6 +166,6 @@ mi_cmd_disassemble (char *command, char **argv, int argc)
gdb_disassembly (gdbarch, uiout,
file_string,
- mixed_source_and_assembly? DISASSEMBLY_SOURCE : 0,
+ disasm_flags,
how_many, low, high);
}
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index f5aa784..7c2029c 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -60,6 +60,29 @@ proc test_disassembly_only {} {
"data-disassemble file & line, assembly only"
}
+proc test_disassembly_with_opcodes {} {
+ global mi_gdb_prompt
+ global hex
+ global decimal
+
+ set line_main_head [gdb_get_line_number "main ("]
+ set line_main_body [expr $line_main_head + 2]
+
+ # Test disassembly with opcodes for the current function.
+ # Tests:
+ # -data-disassemble -s $pc -e "$pc+8" -- 2
+ # -data-disassemble -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"
+}
+
proc test_disassembly_lines_limit {} {
global mi_gdb_prompt
global hex
@@ -116,6 +139,33 @@ proc test_disassembly_mixed {} {
"data-disassemble range assembly mixed"
}
+proc test_disassembly_mixed_with_opcodes {} {
+ global mi_gdb_prompt
+ global hex
+ global decimal
+
+ set line_callee2_head [gdb_get_line_number "callee2 ("]
+ set line_callee2_open_brace [expr $line_callee2_head + 1]
+
+ # Test disassembly mixed with opcodes for the current function.
+ # Tests:
+ # -data-disassemble -f basics.c -l $line_callee2_open_brace -- 3
+ # -data-disassemble -s $pc -e "$pc+8" -- 3
+
+ mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 3" \
+ "002\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_callee2_open_brace\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"callee2\",offset=\"0\",opcodes=\".*\",inst=\".*\"\}.*\\\]\}.*,src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[.*\{address=\"$hex\",func-name=\"callee2\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
+ "data-disassemble file, line assembly mixed with opcodes"
+
+ #
+ # In mixed mode, the lowest level of granularity is the source line.
+ # So we are going to get the disassembly for the source line at
+ # which we are now, even if we have specified that the range is only 2 insns.
+ #
+ mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 3" \
+ "003\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
+ "data-disassemble range assembly mixed with opcodes"
+}
+
proc test_disassembly_mixed_lines_limit {} {
global mi_gdb_prompt
global hex
@@ -168,18 +218,20 @@ proc test_disassembly_bogus_args {} {
"data-disassemble bogus address"
mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
- "456\\^error,msg=\"mi_cmd_disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mixed_mode.\"" \
+ "456\\^error,msg=\"mi_cmd_disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
"data-disassemble mix different args"
mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
- "789\\^error,msg=\"mi_cmd_disassemble: Mixed_mode argument must be 0 or 1.\"" \
+ "789\\^error,msg=\"mi_cmd_disassemble: Mode argument must be 0, 1, 2, or 3.\"" \
"data-disassemble wrong mode arg"
}
mi_run_to_main
test_disassembly_only
+test_disassembly_with_opcodes
test_disassembly_mixed
+test_disassembly_mixed_with_opcodes
test_disassembly_bogus_args
test_disassembly_lines_limit
test_disassembly_mixed_lines_limit
diff --git a/gdb/testsuite/gdb.mi/mi2-disassemble.exp b/gdb/testsuite/gdb.mi/mi2-disassemble.exp
index 8ccbc9f..2486513 100644
--- a/gdb/testsuite/gdb.mi/mi2-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi2-disassemble.exp
@@ -60,6 +60,29 @@ proc test_disassembly_only {} {
"data-disassemble file & line, assembly only"
}
+proc test_disassembly_with_opcodes {} {
+ global mi_gdb_prompt
+ global hex
+ global decimal
+
+ set line_main_head [gdb_get_line_number "main ("]
+ set line_main_body [expr $line_main_head + 2]
+
+ # Test disassembly with opcodes for the current function.
+ # Tests:
+ # -data-disassemble -s $pc -e "$pc+8" -- 2
+ # -data-disassemble -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"
+}
+
proc test_disassembly_lines_limit {} {
global mi_gdb_prompt
global hex
@@ -116,6 +139,33 @@ proc test_disassembly_mixed {} {
"data-disassemble range assembly mixed"
}
+proc test_disassembly_mixed_with_opcodes {} {
+ global mi_gdb_prompt
+ global hex
+ global decimal
+
+ set line_callee2_head [gdb_get_line_number "callee2 ("]
+ set line_callee2_open_brace [expr $line_callee2_head + 1]
+
+ # Test disassembly mixed with opcodes for the current function.
+ # Tests:
+ # -data-disassemble -f basics.c -l $line_callee2_open_brace -- 3
+ # -data-disassemble -s $pc -e "$pc+8" -- 3
+
+ mi_gdb_test "002-data-disassemble -f basics.c -l $line_callee2_open_brace -- 3" \
+ "002\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$line_callee2_open_brace\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"callee2\",offset=\"0\",opcodes=\".*\",inst=\".*\"\}.*\\\]\}.*,src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[.*\{address=\"$hex\",func-name=\"callee2\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
+ "data-disassemble file, line assembly mixed with opcodes"
+
+ #
+ # In mixed mode, the lowest level of granularity is the source line.
+ # So we are going to get the disassembly for the source line at
+ # which we are now, even if we have specified that the range is only 2 insns.
+ #
+ mi_gdb_test "003-data-disassemble -s \$pc -e \"\$pc+4\" -- 3" \
+ "003\\^done,asm_insns=\\\[src_and_asm_line=\{line=\"$decimal\",file=\".*basics.c\",line_asm_insn=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}.*\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",opcodes=\".*\",inst=\".*\"\}\\\]\}\\\]" \
+ "data-disassemble range assembly mixed with opcodes"
+}
+
proc test_disassembly_mixed_lines_limit {} {
global mi_gdb_prompt
global hex
@@ -168,18 +218,20 @@ proc test_disassembly_bogus_args {} {
"data-disassemble bogus address"
mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
- "456\\^error,msg=\"mi_cmd_disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mixed_mode.\"" \
+ "456\\^error,msg=\"mi_cmd_disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
"data-disassemble mix different args"
mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
- "789\\^error,msg=\"mi_cmd_disassemble: Mixed_mode argument must be 0 or 1.\"" \
+ "789\\^error,msg=\"mi_cmd_disassemble: Mode argument must be 0, 1, 2, or 3.\"" \
"data-disassemble wrong mode arg"
}
mi_run_to_main
test_disassembly_only
+test_disassembly_with_opcodes
test_disassembly_mixed
+test_disassembly_mixed_with_opcodes
test_disassembly_bogus_args
test_disassembly_lines_limit
test_disassembly_mixed_lines_limit
More information about the Gdb-patches
mailing list