diff options
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/NEWS | 3 | ||||
-rw-r--r-- | gdb/disasm.c | 14 | ||||
-rw-r--r-- | gdb/doc/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 5 | ||||
-rw-r--r-- | gdb/mi/mi-cmd-disas.c | 30 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-disassemble.exp | 56 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi2-disassemble.exp | 56 |
9 files changed, 164 insertions, 17 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3ee9097..aff33a5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2011-01-12 Andrew Burgess <aburgess@broadcom.com> + + * disasm.c (dump_insns): Support dumping opcodes for MI. + * mi/mi-cmd-disas.c (mi_cmd_disassemble): Allow mode to control + dumping of instruction opcodes. + 2011-01-09 Robert Millan <rmh@gnu.org> (tiny patch) * configure.tgt: Detect GNU/kFreeBSD and set `gdb_osabi' @@ -3,6 +3,9 @@ *** Changes since GDB 7.2 +* The -data-disassemble MI command now supports modes 2 and 3 for + dumping the instruction opcodes. + * New command line options -data-directory DIR Specify DIR as the "data-directory". diff --git a/gdb/disasm.c b/gdb/disasm.c index 096cec4..9180bc5 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/ChangeLog b/gdb/doc/ChangeLog index 9529a4a..8863d0e 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2011-01-12 Andrew Burgess <aburgess@broadcom.com> + + * gdb.texinfo (GDB/MI Data Manipulation): Update to reflect + changes in mi/mi-cmd-disas.c + 2011-01-12 Tom Tromey <tromey@redhat.com> * gdb.texinfo (Threads): Remove duplicate text. Update examples. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index b86e8d2..d48d95c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -27621,8 +27621,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 1932ae2..e5ce66f 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.")); + "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.")); + "[-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. */ @@ -157,6 +167,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/ChangeLog b/gdb/testsuite/ChangeLog index 544e0f1..a3fc4e4 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-01-12 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. + 2011-01-11 Tom Tromey <tromey@redhat.com> * gdb.python/py-infthread.exp: Load gdb-python.exp. diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp index 2c34ac1..7141201 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-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" +} + 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-disassembly -f basics.c -l $line_callee2_open_brace -- 3 + # -data-disassembly -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 8a04397..53f65e5 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-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" +} + 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-disassembly -f basics.c -l $line_callee2_open_brace -- 3 + # -data-disassembly -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 |