Make -e optional for -data-disassemble
Brett Lee
brett.lee.nps@gmail.com
Sun Mar 11 18:57:00 GMT 2012
Since John Lindal's patch could not be accepted due to copyright
issues, he asked me to independently create a patch.
The attached files make the end address (-e option) optional for the
MI command -data-disassemble. This is backward compatible because all
existing code that calls -data-disassemble passes both -s and -e.
Sincerely,
Brett Lee
-------------- next part --------------
2012-03-09 Brett Lee <brett.lee.nps@gmail.com>
* mi-cmd-disas.c: Allow -s option without -e option. Automatically
stops at the end of the function containing the start address or
displays an error if the address is not inside any function.
-------------- next part --------------
--- gdb-7.3/gdb/mi/mi-cmd-disas.c 2012-03-08 11:21:37.000000000 -0800
+++ gdb-7.3-patched/gdb/mi/mi-cmd-disas.c 2012-03-09 09:49:10.000000000 -0800
@@ -37,6 +37,11 @@
or:
+ START-ADDRESS: address to start the disassembly at.
+ (Automatically stops at the end of the function containing START-ADDRESS.)
+
+ or:
+
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.
@@ -127,18 +132,24 @@
argv += optind;
argc -= optind;
+ if (start_seen && !end_seen && !file_seen && !line_seen && !num_seen)
+ {
+ if (!find_pc_partial_function (low, NULL, NULL, &high))
+ error (_("-data-disassemble: "
+ "No function contains specified address"));
+ else
+ end_seen = 1;
+ }
+
/* Allow only filename + linenum (with how_many which is not
required) OR start_addr + and_addr */
if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen)
|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen)
- || (!line_seen && !file_seen && !num_seen && start_seen && end_seen)))
- error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
- "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
-
- if (argc != 1)
+ || (!line_seen && !file_seen && !num_seen && start_seen && end_seen))
+ || argc != 1)
error (_("-data-disassemble: Usage: [-f filename -l linenum "
- "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+ "[-n howmany]] [-s startaddr [-e endaddr]] [--] mode."));
mode = atoi (argv[0]);
if (mode < 0 || mode > 3)
-------------- next part --------------
--- gdb-7.3/gdb/doc/gdb.texinfo 2012-03-08 11:21:37.000000000 -0800
+++ gdb-7.3-patched/gdb/doc/gdb.texinfo 2012-03-09 10:16:40.000000000 -0800
@@ -28051,7 +28051,7 @@
@smallexample
-data-disassemble
- [ -s @var{start-addr} -e @var{end-addr} ]
+ [ -s @var{start-addr} [ -e @var{end-addr} ] ]
| [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
-- @var{mode}
@end smallexample
@@ -28063,7 +28063,8 @@
@item @var{start-addr}
is the beginning address (or @code{$pc})
@item @var{end-addr}
-is the end address
+is the end address. If this is omitted, then disassembly stops
+at the end of the function containing @var{start-addr}.
@item @var{filename}
is the name of the file to disassemble
@item @var{linenum}
@@ -28123,6 +28124,21 @@
(gdb)
@end smallexample
+Disassemble to the end of @code{main} function.
+
+@smallexample
+-data-disassemble -s $pc -- 0
+^done,asm_insns=[
+@{address="0x000107c0",func-name="main",offset="4",
+inst="mov 2, %o0"@},
+@{address="0x000107c4",func-name="main",offset="8",
+inst="sethi %hi(0x11800), %o2"@},
+[@dots{}]
+@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
+@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
+(gdb)
+@end smallexample
+
Disassemble the whole @code{main} function. Line 32 is part of
@code{main}.
-------------- next part --------------
--- gdb-7.3/gdb/testsuite/gdb.mi/mi2-disassemble.exp 2012-03-08 11:21:37.000000000 -0800
+++ gdb-7.3-patched/gdb/testsuite/gdb.mi/mi2-disassemble.exp 2012-03-09 10:04:55.000000000 -0800
@@ -58,6 +58,10 @@
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 "333-data-disassemble -s \$pc -- 0" \
+ "333\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+ "data-disassemble from pc to end of function"
}
proc test_disassembly_with_opcodes {} {
More information about the Gdb-patches
mailing list