From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13127 invoked by alias); 15 Dec 2010 13:32:33 -0000 Received: (qmail 13118 invoked by uid 22791); 15 Dec 2010 13:32:32 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mms1.broadcom.com (HELO mms1.broadcom.com) (216.31.210.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Dec 2010 13:32:26 +0000 Received: from [10.9.200.131] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Wed, 15 Dec 2010 05:32:52 -0800 X-Server-Uuid: 02CED230-5797-4B57-9875-D5D2FEE4708A Received: from mail-irva-13.broadcom.com (10.11.16.103) by IRVEXCHHUB01.corp.ad.broadcom.com (10.9.200.131) with Microsoft SMTP Server id 8.2.247.2; Wed, 15 Dec 2010 05:32:07 -0800 Received: from [10.177.69.119] (unknown [10.177.69.119]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id AFF3F74D05 for ; Wed, 15 Dec 2010 05:32:06 -0800 (PST) Message-ID: <4D08C355.9010809@broadcom.com> Date: Wed, 15 Dec 2010 13:32:00 -0000 From: "Andrew Burgess" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: "gdb-patches@sourceware.org" Subject: [PATCH] MI disassemble opcode support Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-12/txt/msg00299.txt.bz2 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 * 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 * gdb.texinfo: Update to reflect changes in mi/mi-cmd-disas.c gdb/mi/ 2010-12-10 Andrew Burgess * mi-cmd-disas.c (mi_cmd_disassemble): Allow mode to control dumping of instruction opcodes. gdb/testsuite/ 2010-12-10 Andrew Burgess * 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