* [PATCH] MI disassemble opcode support
@ 2010-12-15 13:32 Andrew Burgess
2010-12-15 18:17 ` Eli Zaretskii
2010-12-28 6:35 ` Joel Brobecker
0 siblings, 2 replies; 6+ messages in thread
From: Andrew Burgess @ 2010-12-15 13:32 UTC (permalink / raw)
To: gdb-patches
Provide an equivalent to "disassemble /r" for the MI interface. The mode parameter to -data-disassemble is extended to control opcode dumping.
I've updated the docs in gdb/doc/gdb.texinfo but I didn't know what I was supposed to do to update the gdb/doc/gdb.info-4 file, let me know what to do and I'll update the patch if needed.
Thanks,
Andrew
gdb/
2010-12-10 Andrew Burgess <aburgess@broadcom.com>
* disasm.c (dump_insns): Build the opcodes into a stream so
that we can dump them as a field for MI.
gdb/doc/
2010-12-10 Andrew Burgess <aburgess@broadcom.com>
* gdb.texinfo: 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 to check opcode dumping works.
diff --git a/gdb/disasm.c b/gdb/disasm.c
index c51f0bf..9fa34a0 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -143,6 +143,12 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
CORE_ADDR old_pc = pc;
bfd_byte data;
int status;
+ const char *spacer = "";
+
+ /* Temporary stream for building up the opcodes */
+ 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 +156,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..7ca53ea 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -46,15 +46,18 @@
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 and 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 ... */
@@ -135,10 +138,17 @@ mi_cmd_disassemble (char *command, char **argv, int argc)
error
("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mixed_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..4c1f1e4 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
@@ -172,14 +222,16 @@ proc test_disassembly_bogus_args {} {
"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..1f2ee0c 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
@@ -172,14 +222,16 @@ proc test_disassembly_bogus_args {} {
"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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] MI disassemble opcode support 2010-12-15 13:32 [PATCH] MI disassemble opcode support Andrew Burgess @ 2010-12-15 18:17 ` Eli Zaretskii 2010-12-16 10:46 ` Andrew Burgess 2010-12-28 6:35 ` Joel Brobecker 1 sibling, 1 reply; 6+ messages in thread From: Eli Zaretskii @ 2010-12-15 18:17 UTC (permalink / raw) To: Andrew Burgess; +Cc: gdb-patches > Date: Wed, 15 Dec 2010 13:32:05 +0000 > From: "Andrew Burgess" <aburgess@broadcom.com> > > Provide an equivalent to "disassemble /r" for the MI interface. The mode parameter to -data-disassemble is extended to control opcode dumping. Thanks. > I've updated the docs in gdb/doc/gdb.texinfo but I didn't know what I was supposed to do to update the gdb/doc/gdb.info-4 file Nothing. gdb.info-* files are produced from gdb.texinfo when GDB is built. > 2010-12-10 Andrew Burgess <aburgess@broadcom.com> > > * gdb.texinfo: Update to reflect changes in mi/mi-cmd-disas.c The ChangeLog entry should show the name of the node where this change was made (as if the node were a function). > --- 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 This part is okay. > + MODE: 0 -- disassembly. > + 1 -- disassembly and source. > + 2 -- disassembly and opcodes. > + 3 -- disassembly and source and opcodes. Please edit the last line to be valid English: 3 -- disassembly, source and opcodes. The patch for the manual is okay with these changes. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] MI disassemble opcode support 2010-12-15 18:17 ` Eli Zaretskii @ 2010-12-16 10:46 ` Andrew Burgess 0 siblings, 0 replies; 6+ messages in thread From: Andrew Burgess @ 2010-12-16 10:46 UTC (permalink / raw) To: gdb-patches On 15/12/2010 18:16, Eli Zaretskii wrote: >> Date: Wed, 15 Dec 2010 13:32:05 +0000 >> From: "Andrew Burgess"<aburgess@broadcom.com> >> >> 2010-12-10 Andrew Burgess<aburgess@broadcom.com> >> >> * gdb.texinfo: Update to reflect changes in mi/mi-cmd-disas.c > > The ChangeLog entry should show the name of the node where this change > was made (as if the node were a function). done. >> + MODE: 0 -- disassembly. >> + 1 -- disassembly and source. >> + 2 -- disassembly and opcodes. >> + 3 -- disassembly and source and opcodes. > > Please edit the last line to be valid English: done. Thanks for taking the time to review this change. Andrew gdb/ 2010-12-10 Andrew Burgess <aburgess@broadcom.com> * disasm.c (dump_insns): Build the opcodes into a stream so that we can dump them as a field 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 to check opcode dumping works. diff --git a/gdb/disasm.c b/gdb/disasm.c index c51f0bf..9fa34a0 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -143,6 +143,12 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout, CORE_ADDR old_pc = pc; bfd_byte data; int status; + const char *spacer = ""; + + /* Temporary stream for building up the opcodes */ + 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 +156,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..a93b5de 100644 --- a/gdb/mi/mi-cmd-disas.c +++ b/gdb/mi/mi-cmd-disas.c @@ -46,15 +46,18 @@ 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 ... */ @@ -135,10 +138,17 @@ mi_cmd_disassemble (char *command, char **argv, int argc) error ("mi_cmd_disassemble: Usage: [-f filename -l linenum [-n howmany]] [-s startaddr -e endaddr] [--] mixed_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..4c1f1e4 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 @@ -172,14 +222,16 @@ proc test_disassembly_bogus_args {} { "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..1f2ee0c 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 @@ -172,14 +222,16 @@ proc test_disassembly_bogus_args {} { "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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] MI disassemble opcode support 2010-12-15 13:32 [PATCH] MI disassemble opcode support Andrew Burgess 2010-12-15 18:17 ` Eli Zaretskii @ 2010-12-28 6:35 ` Joel Brobecker 2010-12-28 19:12 ` Eli Zaretskii 2011-01-04 11:35 ` Andrew Burgess 1 sibling, 2 replies; 6+ messages in thread From: Joel Brobecker @ 2010-12-28 6:35 UTC (permalink / raw) To: Andrew Burgess; +Cc: gdb-patches > 2010-12-10 Andrew Burgess <aburgess@broadcom.com> > > * disasm.c (dump_insns): Build the opcodes into a stream so > that we can dump them as a field for MI. > > gdb/doc/ > > 2010-12-10 Andrew Burgess <aburgess@broadcom.com> > > * gdb.texinfo: 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 to check opcode dumping works. Pre-approved with the following changes made: I think a NEWS entry might be worthwhile (this can be treated as a separate patch - maybe ask Eli if he thinks it's significant enough to be mentioned there). The alignment of your ChangeLog entries is incorrect. Everything should be aligned on a tabulation. Therefore: * 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 to check opcode dumping works. 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. For instance: > + const char *spacer = ""; > + > + /* Temporary stream for building up the opcodes */ You can put the reason why you are building the opcode in a stream here instead of inside the ChangeLog. > + fprintf_filtered(opcode_stream->stream, "%s%02x", > + spacer, (unsigned)data); > + spacer = " "; Formatting: space before the first '(', and also space after the unsigned cast. I know the second one is not your doing, but might as well fix it. > 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"). > + /* Convert the mode into a set of disassembly flags */ Period and 2 spaces at the end of the sentence. -- Joel ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] MI disassemble opcode support 2010-12-28 6:35 ` Joel Brobecker @ 2010-12-28 19:12 ` Eli Zaretskii 2011-01-04 11:35 ` Andrew Burgess 1 sibling, 0 replies; 6+ messages in thread From: Eli Zaretskii @ 2010-12-28 19:12 UTC (permalink / raw) To: Joel Brobecker; +Cc: aburgess, gdb-patches > Date: Tue, 28 Dec 2010 09:47:33 +0400 > From: Joel Brobecker <brobecker@adacore.com> > Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org> > > I think a NEWS entry might be worthwhile (this can be treated as a > separate patch - maybe ask Eli if he thinks it's significant enough > to be mentioned there). If you think it is, then it is ;-) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] MI disassemble opcode support 2010-12-28 6:35 ` Joel Brobecker 2010-12-28 19:12 ` Eli Zaretskii @ 2011-01-04 11:35 ` Andrew Burgess 1 sibling, 0 replies; 6+ messages in thread From: Andrew Burgess @ 2011-01-04 11:35 UTC (permalink / raw) To: gdb-patches 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-01-04 11:35 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-12-15 13:32 [PATCH] MI disassemble opcode support Andrew Burgess 2010-12-15 18:17 ` Eli Zaretskii 2010-12-16 10:46 ` Andrew Burgess 2010-12-28 6:35 ` Joel Brobecker 2010-12-28 19:12 ` Eli Zaretskii 2011-01-04 11:35 ` Andrew Burgess
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox