public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC] mi: add -a option to the "-data-disassemble" command
@ 2018-07-06  9:39 Jan Vrany
  2018-07-06 12:37 ` Eli Zaretskii
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-07-06  9:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

A CLI command "disassemble" allows use to specify a single
address - in that case function surrounding that address is
disassembled.

This commit adds this feature to MI command "-data-disassemble".

gdb/ChangeLog:

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi/mi-main.c): Add new feature
	data-disassemble-a-option to indicate that -data-disassemble
	supports -a.

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document data-disassemble-a-option
	feature

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
	tests for -data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           |  9 ++++++++
 gdb/doc/ChangeLog                       |  7 +++++++
 gdb/doc/gdb.texinfo                     |  7 +++++++
 gdb/mi/mi-cmd-disas.c                   | 28 ++++++++++++++++++-------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/ChangeLog                 |  6 ++++++
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 ++++++++++++++++--
 7 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f601bdbf0..999d63d2c1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi/mi-main.c): Add new feature
+	data-disassemble-a-option to indicate that -data-disassemble
+	supports -a.
+
 2018-07-02  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
 	* riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0" entries.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6954398e43..f52074f2df 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document data-disassemble-a-option
+	feature
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
 	* gdb.texinfo (Files): Document "add-symbol-file -o offset".
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7fb6ac5636..e7a0c65576 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30947,6 +30947,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -30959,6 +30960,9 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is the address anywhere in function code (or function name). If @var{addr}
+is specified, whole function surrounding that address will be disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33095,6 +33099,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34..51f9aa2594 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,6 +125,10 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+        case ADDR_OPT:
+          addr = parse_and_eval_address (oarg);
+          addr_seen = 1;
+          break;
 	}
     }
   argv += oind;
@@ -130,15 +137,16 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   /* Allow only filename + linenum (with how_many which is not
      required) OR start_addr + end_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)))
+  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen && addr_seen)))
     error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
-	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
+	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
+             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +192,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen) 
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2177abd0ed..f503b3149e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 93c849c040..11d1440535 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
+	tests for -data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-06-29  Pedro Alves  <palves@redhat.com>
 
 	* gdb.threads/names.exp: Adjust expected "info threads" output.
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf5884..bbf29d7b63 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "112-data-disassemble -a callee4 -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address (-s -e)"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address (-a)"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.18.0

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-06  9:39 [RFC] mi: add -a option to the "-data-disassemble" command Jan Vrany
@ 2018-07-06 12:37 ` Eli Zaretskii
  2018-07-14 17:39   ` Jan Vrany
  0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2018-07-06 12:37 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

> From: Jan Vrany <jan.vrany@fit.cvut.cz>
> Cc: Jan Vrany <jan.vrany@fit.cvut.cz>
> Date: Fri,  6 Jul 2018 10:39:25 +0100
> 
> A CLI command "disassemble" allows use to specify a single
> address - in that case function surrounding that address is
> disassembled.
> 
> This commit adds this feature to MI command "-data-disassemble".

Thanks.

> @@ -30959,6 +30960,9 @@ Where:
>  is the beginning address (or @code{$pc})
>  @item @var{end-addr}
>  is the end address
> +@item @var{addr}
> +is the address anywhere in function code (or function name). If @var{addr}
                                                              ^^
Two spaces between sentences, please.

> +is specified, whole function surrounding that address will be disassembled.
                 ^^^^^^^^^^^^^^
"the whole function"

Also, since ADDR could be the name of a function, I'd add here a
sentence describing that situation, since there could be no function
"surrounding" a function name.

What about NEWS?

The documentation part is approved when the above nits are fixed.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-06 12:37 ` Eli Zaretskii
@ 2018-07-14 17:39   ` Jan Vrany
  2018-07-14 18:27     ` Eli Zaretskii
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-07-14 17:39 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

A CLI command "disassemble" allows use to specify a single
address - in that case function surrounding that address is
disassembled.

This commit adds this feature to MI command "-data-disassemble".

gdb/ChangeLog:

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi/mi-main.c): Add new feature
	data-disassemble-a-option to indicate that -data-disassemble
	supports -a.
	* NEWS: Mention new -data-disassemble option -a

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document data-disassemble-a-option
	feature

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
	tests for -data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           | 10 +++++++++
 gdb/NEWS                                |  3 +++
 gdb/doc/ChangeLog                       |  7 +++++++
 gdb/doc/gdb.texinfo                     |  9 ++++++++
 gdb/mi/mi-cmd-disas.c                   | 28 ++++++++++++++++++-------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/ChangeLog                 |  6 ++++++
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 ++++++++++++++++--
 8 files changed, 75 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f601bdbf0..53a417706f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi/mi-main.c): Add new feature
+	data-disassemble-a-option to indicate that -data-disassemble
+	supports -a.
+	* NEWS: Mention new -data-disassemble option -a
+
 2018-07-02  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
 	* riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0" entries.
diff --git a/gdb/NEWS b/gdb/NEWS
index 839466e7e0..3367be4375 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 8.1
 
+* The '-data-disassemble' MI command now accepts an '-a' option to disassemble
+  the whole function surrounding given program counter value or function name.
+
 * The 'symbol-file' command now accepts an '-o' option to add a relative
   offset to all sections.
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6954398e43..f52074f2df 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document data-disassemble-a-option
+	feature
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
 	* gdb.texinfo (Files): Document "add-symbol-file -o offset".
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7fb6ac5636..114054244c 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30947,6 +30947,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -30959,6 +30960,11 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is the address anywhere in function code (or function name).  If @var{addr}
+is specified, the whole function surrounding that address will be disassembled.
+Id @var{addr} is a function name, the whole function with that name will be
+disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34..51f9aa2594 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,6 +125,10 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+        case ADDR_OPT:
+          addr = parse_and_eval_address (oarg);
+          addr_seen = 1;
+          break;
 	}
     }
   argv += oind;
@@ -130,15 +137,16 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   /* Allow only filename + linenum (with how_many which is not
      required) OR start_addr + end_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)))
+  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen && addr_seen)))
     error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
-	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
+	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
+             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +192,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen) 
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2177abd0ed..f503b3149e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 93c849c040..11d1440535 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
+	tests for -data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-06-29  Pedro Alves  <palves@redhat.com>
 
 	* gdb.threads/names.exp: Adjust expected "info threads" output.
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf5884..bbf29d7b63 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "112-data-disassemble -a callee4 -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address (-s -e)"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address (-a)"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.18.0

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-14 17:39   ` Jan Vrany
@ 2018-07-14 18:27     ` Eli Zaretskii
  2018-07-26 14:56       ` Jan Vrany
  0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2018-07-14 18:27 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

> From: Jan Vrany <jan.vrany@fit.cvut.cz>
> Cc: Jan Vrany <jan.vrany@fit.cvut.cz>
> Date: Sat, 14 Jul 2018 18:39:31 +0100
> 
> A CLI command "disassemble" allows use to specify a single
> address - in that case function surrounding that address is
> disassembled.

Thanks.

> diff --git a/gdb/NEWS b/gdb/NEWS
> index 839466e7e0..3367be4375 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,9 @@
>  
>  *** Changes since GDB 8.1
>  
> +* The '-data-disassemble' MI command now accepts an '-a' option to disassemble
> +  the whole function surrounding given program counter value or function name.
> +
>  * The 'symbol-file' command now accepts an '-o' option to add a relative
>    offset to all sections.

This part is okay.

> +@item @var{addr}
> +is the address anywhere in function code (or function name).  If @var{addr}
> +is specified, the whole function surrounding that address will be disassembled.
> +Id @var{addr} is a function name, the whole function with that name will be
   ^^
Typo.

Otherwise, the documentation part is approved.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-14 18:27     ` Eli Zaretskii
@ 2018-07-26 14:56       ` Jan Vrany
  2018-07-26 17:47         ` Eli Zaretskii
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-07-26 14:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

A CLI command "disassemble" allows use to specify a single
address - in that case function surrounding that address is
disassembled.

This commit adds this feature to MI command "-data-disassemble".

gdb/ChangeLog:

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi/mi-main.c): Add new feature
	data-disassemble-a-option to indicate that -data-disassemble
	supports -a.
	* NEWS: Mention new -data-disassemble option -a

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document data-disassemble-a-option
	feature

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
	tests for -data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           | 10 +++++++++
 gdb/NEWS                                |  3 +++
 gdb/doc/ChangeLog                       |  7 +++++++
 gdb/doc/gdb.texinfo                     |  9 ++++++++
 gdb/mi/mi-cmd-disas.c                   | 28 ++++++++++++++++++-------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/ChangeLog                 |  6 ++++++
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 ++++++++++++++++--
 8 files changed, 75 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f601bdbf0..53a417706f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi/mi-main.c): Add new feature
+	data-disassemble-a-option to indicate that -data-disassemble
+	supports -a.
+	* NEWS: Mention new -data-disassemble option -a
+
 2018-07-02  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
 	* riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0" entries.
diff --git a/gdb/NEWS b/gdb/NEWS
index 839466e7e0..3367be4375 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 8.1
 
+* The '-data-disassemble' MI command now accepts an '-a' option to disassemble
+  the whole function surrounding given program counter value or function name.
+
 * The 'symbol-file' command now accepts an '-o' option to add a relative
   offset to all sections.
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6954398e43..f52074f2df 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document data-disassemble-a-option
+	feature
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
 	* gdb.texinfo (Files): Document "add-symbol-file -o offset".
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7fb6ac5636..af2a0948c3 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30947,6 +30947,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -30959,6 +30960,11 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is the address anywhere in function code (or function name).  If @var{addr}
+is specified, the whole function surrounding that address will be disassembled.
+If @var{addr} is a function name, the whole function with that name will be
+disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34..51f9aa2594 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,6 +125,10 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+        case ADDR_OPT:
+          addr = parse_and_eval_address (oarg);
+          addr_seen = 1;
+          break;
 	}
     }
   argv += oind;
@@ -130,15 +137,16 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   /* Allow only filename + linenum (with how_many which is not
      required) OR start_addr + end_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)))
+  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen && addr_seen)))
     error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
-	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
+	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
+             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +192,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen) 
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2177abd0ed..f503b3149e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 93c849c040..11d1440535 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
+	tests for -data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-06-29  Pedro Alves  <palves@redhat.com>
 
 	* gdb.threads/names.exp: Adjust expected "info threads" output.
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf5884..bbf29d7b63 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "112-data-disassemble -a callee4 -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address (-s -e)"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address (-a)"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.18.0

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-26 14:56       ` Jan Vrany
@ 2018-07-26 17:47         ` Eli Zaretskii
  2018-07-27  7:57           ` Jan Vrany
  0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2018-07-26 17:47 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

> From: Jan Vrany <jan.vrany@fit.cvut.cz>
> Cc: Jan Vrany <jan.vrany@fit.cvut.cz>
> Date: Thu, 26 Jul 2018 15:55:57 +0100
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 839466e7e0..3367be4375 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,9 @@
>  
>  *** Changes since GDB 8.1
>  
> +* The '-data-disassemble' MI command now accepts an '-a' option to disassemble
                                                    ^^^^^^^^^^^^^^
"the '-a' option"

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 7fb6ac5636..af2a0948c3 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -30947,6 +30947,7 @@ For details about what an addressable memory unit is,
>  @smallexample
>   -data-disassemble
>      [ -s @var{start-addr} -e @var{end-addr} ]
> +  | [ -a @var{addr} ]
>    | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
>    -- @var{mode}
>  @end smallexample
> @@ -30959,6 +30960,11 @@ Where:
>  is the beginning address (or @code{$pc})
>  @item @var{end-addr}
>  is the end address
> +@item @var{addr}
> +is the address anywhere in function code (or function name).  If @var{addr}
> +is specified, the whole function surrounding that address will be disassembled.
> +If @var{addr} is a function name, the whole function with that name will be
> +disassembled.

You never mention the -a option in the text.  I think you should.

Thanks.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-26 17:47         ` Eli Zaretskii
@ 2018-07-27  7:57           ` Jan Vrany
  2018-07-30 15:05             ` Tom Tromey
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-07-27  7:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

A CLI command "disassemble" allows use to specify a single
address - in that case function surrounding that address is
disassembled.

This commit adds this feature to MI command "-data-disassemble".

gdb/ChangeLog:

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi/mi-main.c): Add new feature
	data-disassemble-a-option to indicate that -data-disassemble
	supports -a.
	* NEWS: Mention new -data-disassemble option -a

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document data-disassemble-a-option
	feature

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
	tests for -data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           | 10 +++++++++
 gdb/NEWS                                |  3 +++
 gdb/doc/ChangeLog                       |  7 +++++++
 gdb/doc/gdb.texinfo                     |  9 ++++++++
 gdb/mi/mi-cmd-disas.c                   | 28 ++++++++++++++++++-------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/ChangeLog                 |  6 ++++++
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 ++++++++++++++++--
 8 files changed, 75 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f601bdbf0..53a417706f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi/mi-main.c): Add new feature
+	data-disassemble-a-option to indicate that -data-disassemble
+	supports -a.
+	* NEWS: Mention new -data-disassemble option -a
+
 2018-07-02  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
 	* riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0" entries.
diff --git a/gdb/NEWS b/gdb/NEWS
index 839466e7e0..19f353495b 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 8.1
 
+* The '-data-disassemble' MI command now accepts the '-a' option to disassemble
+  the whole function surrounding given program counter value or function name.
+
 * The 'symbol-file' command now accepts an '-o' option to add a relative
   offset to all sections.
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6954398e43..f52074f2df 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document data-disassemble-a-option
+	feature
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
 	* gdb.texinfo (Files): Document "add-symbol-file -o offset".
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7fb6ac5636..47acf6cdd0 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30947,6 +30947,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -30959,6 +30960,11 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is the address anywhere in function code (or function name).  If @code{-a}
+@var{addr} is used, the whole function surrounding that address will be
+disassembled. If @var{addr} is a function name, the whole function with that
+name will be disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34..51f9aa2594 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,6 +125,10 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+        case ADDR_OPT:
+          addr = parse_and_eval_address (oarg);
+          addr_seen = 1;
+          break;
 	}
     }
   argv += oind;
@@ -130,15 +137,16 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   /* Allow only filename + linenum (with how_many which is not
      required) OR start_addr + end_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)))
+  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen && addr_seen)))
     error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
-	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
+	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
+             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +192,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen) 
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2177abd0ed..f503b3149e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 93c849c040..11d1440535 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
+	tests for -data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-06-29  Pedro Alves  <palves@redhat.com>
 
 	* gdb.threads/names.exp: Adjust expected "info threads" output.
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf5884..bbf29d7b63 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "112-data-disassemble -a callee4 -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address (-s -e)"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address (-a)"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.18.0

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-27  7:57           ` Jan Vrany
@ 2018-07-30 15:05             ` Tom Tromey
  2018-07-31 10:23               ` Jan Vrany
  0 siblings, 1 reply; 21+ messages in thread
From: Tom Tromey @ 2018-07-30 15:05 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:

Jan> A CLI command "disassemble" allows use to specify a single
Jan> address - in that case function surrounding that address is
Jan> disassembled.

Jan>  	  high = parse_and_eval_address (oarg);
Jan>  	  end_seen = 1;
Jan>  	  break;
Jan> +        case ADDR_OPT:
Jan> +          addr = parse_and_eval_address (oarg);
Jan> +          addr_seen = 1;
Jan> +          break;

The indentation looked slightly off here.
It could just be how the patch looked here, but could you double-check
just in case?

Jan> +  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen && !addr_seen)
Jan> +	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen && !addr_seen)
Jan> +	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen && !addr_seen)
Jan> +	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen && addr_seen)))

I suppose this ought to check for the case where either -s or -e is
given along with -a.  That seems like an error.

This "if" made me laugh.

Jan> +    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
Jan> +	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
Jan> +             "data-disassemble function around pc assembly only"
Jan> +
Jan> +    mi_gdb_test "112-data-disassemble -a callee4 -- 0" \
Jan> +	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
Jan> +             "data-disassemble function callee4 assembly only"

Probably the second "112" should be "113".  I don't know if you can
reuse tokens or not, but it seems simple and safe not to.

Thanks for doing this.  It seems like a good addition to me.

Tom

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-30 15:05             ` Tom Tromey
@ 2018-07-31 10:23               ` Jan Vrany
  2018-07-31 15:48                 ` Tom Tromey
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-07-31 10:23 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On Mon, 2018-07-30 at 09:04 -0600, Tom Tromey wrote:
> > > > > > "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:
> 
> Jan> A CLI command "disassemble" allows use to specify a single
> Jan> address - in that case function surrounding that address is
> Jan> disassembled.
> 
> Jan>  	  high = parse_and_eval_address (oarg);
> Jan>  	  end_seen = 1;
> Jan>  	  break;
> Jan> +        case ADDR_OPT:
> Jan> +          addr = parse_and_eval_address (oarg);
> Jan> +          addr_seen = 1;
> Jan> +          break;
> 
> The indentation looked slightly off here.
> It could just be how the patch looked here, but could you double-check
> just in case?

My fault. My editor put 8 spaces instead of tab (\t) at the beginning of
my lines. Will fix. 

> 
> Jan> +  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen && !addr_seen)
> Jan> +	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen && !addr_seen)
> Jan> +	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen && !addr_seen)
> Jan> +	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen && addr_seen)))
> 
> I suppose this ought to check for the case where either -s or -e is
> given along with -a.  That seems like an error.
> 

I'm sorry I'm confused. Let me try to explain. There are (now) four forms:

1a) -f filename -l linenum 
1b) -f filename -l linenum -n lines 
 2) -s start-addr -e end-addr
 3) -a addr

Command  must have one of the above four forms, otherwise it's invalid. Each
"line" in the code above checks one of the above form (in order as written here). 
Note, that there's negation at the very beginning, so the condition holds 
if the command has none of the four forms. Seems "good" to me. Makes sense? 

Perhaps it's easier to see with little reformatting (hope email won't screw it):

  if (!   (( line_seen &&  file_seen &&  num_seen && !start_seen && !end_seen && !addr_seen)
	|| ( line_seen &&  file_seen && !num_seen && !start_seen && !end_seen && !addr_seen)
	|| (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen && !addr_seen)
	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen &&  addr_seen)))
    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));

Now, it appears to me that first two lines can be merged as forms 1a and 1b differ only
in presence of lines. Also, I forgot to update the comment above. So, what about:

   /* Allow only filename + linenum (with how_many which is not
-     required) OR start_addr + end_addr.  */
+     required) OR start_addr + end_addr OR 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)))
+  if (!(  ( line_seen &&  file_seen &&              !start_seen && !end_seen && !addr_seen)
+       || (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen && !addr_seen)
+       || (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen &&  addr_seen)))

this passes mi-disassemble.exp on my machine. 


> This "if" made me laugh.

:-) I cannot say I was exactly laughing. But followed the crowed anyway.

> 
> Jan> +    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
> Jan> +	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
> Jan> +             "data-disassemble function around pc assembly only"
> Jan> +
> Jan> +    mi_gdb_test "112-data-disassemble -a callee4 -- 0" \
> Jan> +	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" 
> \
> Jan> +             "data-disassemble function callee4 assembly only"
> 
> Probably the second "112" should be "113".  I don't know if you can
> reuse tokens or not, but it seems simple and safe not to.

Sure, will fix and send a patch once we agree on the "if". 

Thanks, Jan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-31 10:23               ` Jan Vrany
@ 2018-07-31 15:48                 ` Tom Tromey
  2018-07-31 20:35                   ` Jan Vrany
  0 siblings, 1 reply; 21+ messages in thread
From: Tom Tromey @ 2018-07-31 15:48 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches, Tom Tromey

>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:

>> The indentation looked slightly off here.
>> It could just be how the patch looked here, but could you double-check
>> just in case?

Jan> My fault. My editor put 8 spaces instead of tab (\t) at the beginning of
Jan> my lines. Will fix. 

Thanks.  According to .dir-locals.el, tabs are fine, assuming things
line up properly.  (But there's been talk over the years of switching
purely to spaces, and IIRC using only spaces is also fine.)

Jan> I'm sorry I'm confused. Let me try to explain. There are (now) four forms:

Jan> 1a) -f filename -l linenum 
Jan> 1b) -f filename -l linenum -n lines 
Jan>  2) -s start-addr -e end-addr
Jan>  3) -a addr

Jan> Command  must have one of the above four forms, otherwise it's invalid. Each
Jan> "line" in the code above checks one of the above form (in order as written here). 
Jan> Note, that there's negation at the very beginning, so the condition holds 
Jan> if the command has none of the four forms. Seems "good" to me. Makes sense? 

Yes, thanks for explaining this.  I was misreading the new code here.

Jan> Now, it appears to me that first two lines can be merged as forms 1a and 1b differ only
Jan> in presence of lines. Also, I forgot to update the comment above. So, what about:
[...]

Thank you, that seems like a good improvement.

Tom

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-31 15:48                 ` Tom Tromey
@ 2018-07-31 20:35                   ` Jan Vrany
  2018-08-09 20:47                     ` Tom Tromey
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-07-31 20:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

A CLI command "disassemble" allows use to specify a single
address - in that case function surrounding that address is
disassembled.

This commit adds this feature to MI command "-data-disassemble".

gdb/ChangeLog:

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi/mi-main.c): Add new feature
	data-disassemble-a-option to indicate that -data-disassemble
	supports -a.
	* NEWS: Mention new -data-disassemble option -a

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document data-disassemble-a-option
	feature

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
	tests for -data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           | 10 +++++++++
 gdb/NEWS                                |  3 +++
 gdb/doc/ChangeLog                       |  7 ++++++
 gdb/doc/gdb.texinfo                     |  9 ++++++++
 gdb/mi/mi-cmd-disas.c                   | 29 ++++++++++++++++++-------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/ChangeLog                 |  6 +++++
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 +++++++++++++++--
 8 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f601bdbf0..53a417706f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi/mi-main.c): Add new feature
+	data-disassemble-a-option to indicate that -data-disassemble
+	supports -a.
+	* NEWS: Mention new -data-disassemble option -a
+
 2018-07-02  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
 	* riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0" entries.
diff --git a/gdb/NEWS b/gdb/NEWS
index 839466e7e0..19f353495b 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 8.1
 
+* The '-data-disassemble' MI command now accepts the '-a' option to disassemble
+  the whole function surrounding given program counter value or function name.
+
 * The 'symbol-file' command now accepts an '-o' option to add a relative
   offset to all sections.
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6954398e43..f52074f2df 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document data-disassemble-a-option
+	feature
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
 	* gdb.texinfo (Files): Document "add-symbol-file -o offset".
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7fb6ac5636..47acf6cdd0 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30947,6 +30947,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -30959,6 +30960,11 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is the address anywhere in function code (or function name).  If @code{-a}
+@var{addr} is used, the whole function surrounding that address will be
+disassembled. If @var{addr} is a function name, the whole function with that
+name will be disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34..013bfe9186 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,23 +125,27 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+	case ADDR_OPT:
+	  addr = parse_and_eval_address (oarg);
+	  addr_seen = 1;
+	  break;
 	}
     }
   argv += oind;
   argc -= oind;
 
   /* Allow only filename + linenum (with how_many which is not
-     required) OR start_addr + end_addr.  */
+     required) OR start_addr + end_addr OR 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)))
+  if (!(  ( line_seen &&  file_seen &&              !start_seen && !end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen && !addr_seen)
+	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen &&  addr_seen)))
     error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
-	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
+	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
+             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +191,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen) 
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2177abd0ed..f503b3149e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 93c849c040..11d1440535 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
+	tests for -data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-06-29  Pedro Alves  <palves@redhat.com>
 
 	* gdb.threads/names.exp: Adjust expected "info threads" output.
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf5884..393e8b35b5 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "113-data-disassemble -a callee4 -- 0" \
+	    "113\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address (-s -e)"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address (-a)"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.18.0

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-07-31 20:35                   ` Jan Vrany
@ 2018-08-09 20:47                     ` Tom Tromey
  2018-08-10  8:29                       ` Jan Vrany
  2018-08-10  8:30                       ` Jan Vrany
  0 siblings, 2 replies; 21+ messages in thread
From: Tom Tromey @ 2018-08-09 20:47 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:

Jan> A CLI command "disassemble" allows use to specify a single
Jan> address - in that case function surrounding that address is
Jan> disassembled.

Hi, I didn't see this go in and I thought maybe it needed a new reply?

Jan> -  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen)
Jan> -	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen)
Jan> -	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen)))
Jan> +  if (!(  ( line_seen &&  file_seen &&              !start_seen && !end_seen && !addr_seen)
Jan> +	|| (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen && !addr_seen)
Jan> +	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen &&  addr_seen)))

These go over 80 columns now, so I think they need to be reformatted
somehow to fit.  Please use your judgment, what you did here is already
better than the status quo...

No need to re-post the patch, you can just put it in with the
correction.  Thank you.

Tom

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-09 20:47                     ` Tom Tromey
@ 2018-08-10  8:29                       ` Jan Vrany
  2018-08-10 13:22                         ` Tom Tromey
  2018-08-10  8:30                       ` Jan Vrany
  1 sibling, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-08-10  8:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On Thu, 2018-08-09 at 14:47 -0600, Tom Tromey wrote:
> > > > > > Jan> -  if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen)
> Jan> -	|| (line_seen && file_seen && !num_seen && !start_seen && !end_seen)
> Jan> -	|| (!line_seen && !file_seen && !num_seen && start_seen && end_seen)))
> Jan> +  if (!(  ( line_seen &&  file_seen &&              !start_seen && !end_seen && !addr_seen)
> Jan> +	|| (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen && !addr_seen)
> Jan> +	|| (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen &&  addr_seen)))
> 
> These go over 80 columns now, so I think they need to be reformatted
> somehow to fit.  

Hi, that'd be tricky but I'll do my best...

> Please use your judgment, what you did here is already
> better than the status quo...
> 
> No need to re-post the patch, you can just put it in with the
> correction.  Thank you.

I do not have commit access to the repo (it's my preference for the moment). 
New patch will follow shortly. Simon, could you please push it for me if 
it's OK? 

Thanks!

Jan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-09 20:47                     ` Tom Tromey
  2018-08-10  8:29                       ` Jan Vrany
@ 2018-08-10  8:30                       ` Jan Vrany
  2018-08-10  9:47                         ` Pedro Alves
  1 sibling, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-08-10  8:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

A CLI command "disassemble" allows use to specify a single
address - in that case function surrounding that address is
disassembled.

This commit adds this feature to MI command "-data-disassemble".

gdb/ChangeLog:

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi/mi-main.c): Add new feature
	data-disassemble-a-option to indicate that -data-disassemble
	supports -a.
	* NEWS: Mention new -data-disassemble option -a

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document data-disassemble-a-option
	feature

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
	tests for -data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           | 10 +++++++
 gdb/NEWS                                |  3 +++
 gdb/doc/ChangeLog                       |  7 +++++
 gdb/doc/gdb.texinfo                     |  9 +++++++
 gdb/mi/mi-cmd-disas.c                   | 35 +++++++++++++++++++------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/ChangeLog                 |  6 +++++
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 ++++++++++++--
 8 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f601bdbf0..53a417706f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi/mi-main.c): Add new feature
+	data-disassemble-a-option to indicate that -data-disassemble
+	supports -a.
+	* NEWS: Mention new -data-disassemble option -a
+
 2018-07-02  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
 	* riscv-tdep.c (riscv_register_aliases): Swap "fp" and "s0" entries.
diff --git a/gdb/NEWS b/gdb/NEWS
index 839466e7e0..19f353495b 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 8.1
 
+* The '-data-disassemble' MI command now accepts the '-a' option to disassemble
+  the whole function surrounding given program counter value or function name.
+
 * The 'symbol-file' command now accepts an '-o' option to add a relative
   offset to all sections.
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6954398e43..f52074f2df 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document data-disassemble-a-option
+	feature
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
 	* gdb.texinfo (Files): Document "add-symbol-file -o offset".
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 7fb6ac5636..47acf6cdd0 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30947,6 +30947,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -30959,6 +30960,11 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is the address anywhere in function code (or function name).  If @code{-a}
+@var{addr} is used, the whole function surrounding that address will be
+disassembled. If @var{addr} is a function name, the whole function with that
+name will be disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34..8f0b126fb3 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,23 +125,33 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+	case ADDR_OPT:
+	  addr = parse_and_eval_address (oarg);
+	  addr_seen = 1;
+	  break;
 	}
     }
   argv += oind;
   argc -= oind;
 
   /* Allow only filename + linenum (with how_many which is not
-     required) OR start_addr + end_addr.  */
+     required) OR start_addr + end_addr OR addr  */
+
+  if (!(
+          ( line_seen &&  file_seen &&              !start_seen && !end_seen
+								&& !addr_seen)
+
+       || (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen
+								&& !addr_seen)
 
-  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)))
+       || (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen
+								&&  addr_seen)))
     error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
-	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
+	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
+             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +197,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen) 
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2177abd0ed..f503b3149e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 93c849c040..11d1440535 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
+	tests for -data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-06-29  Pedro Alves  <palves@redhat.com>
 
 	* gdb.threads/names.exp: Adjust expected "info threads" output.
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf5884..393e8b35b5 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "113-data-disassemble -a callee4 -- 0" \
+	    "113\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address (-s -e)"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address (-a)"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.18.0

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-10  8:30                       ` Jan Vrany
@ 2018-08-10  9:47                         ` Pedro Alves
  2018-08-10 10:28                           ` Jan Vrany
  0 siblings, 1 reply; 21+ messages in thread
From: Pedro Alves @ 2018-08-10  9:47 UTC (permalink / raw)
  To: Jan Vrany, gdb-patches

On 08/10/2018 09:29 AM, Jan Vrany wrote:
> @@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
>  @item exec-run-start-option
>  Indicates that the @code{-exec-run} command supports the @option{--start}
>  option (@pxref{GDB/MI Program Execution}).
> +@item data-disassemble-a-option
> +Indicates that the @code{-data-disassemble} command supports the @option{-a}
> +option (@pxref{GDB/MI Data Manipulation}).
>  @end ftable

I'm curious about how you intend to use this new -list-features feature.
Are you enabling/disabling some UI element depending on presence of the
feature?  I.e., something that you wouldn't be able to do by just
trying the "-data-disassemble -a" command and looking for error?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-10  9:47                         ` Pedro Alves
@ 2018-08-10 10:28                           ` Jan Vrany
  2018-08-10 10:41                             ` Pedro Alves
  0 siblings, 1 reply; 21+ messages in thread
From: Jan Vrany @ 2018-08-10 10:28 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On Fri, 2018-08-10 at 10:47 +0100, Pedro Alves wrote:
> On 08/10/2018 09:29 AM, Jan Vrany wrote:
> > @@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
> >  @item exec-run-start-option
> >  Indicates that the @code{-exec-run} command supports the @option{--start}
> >  option (@pxref{GDB/MI Program Execution}).
> > +@item data-disassemble-a-option
> > +Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > +option (@pxref{GDB/MI Data Manipulation}).
> >  @end ftable
> 
> I'm curious about how you intend to use this new -list-features feature.
> Are you enabling/disabling some UI element depending on presence of the
> feature?  I.e., something that you wouldn't be able to do by just
> trying the "-data-disassemble -a" command and looking for error?

Yes. Basically I have a menu item on frame that opens another window with
disassembly of the coresponding function (showing current instruction, 
(basic) blocks and alike). 

For programs with debug information, I can do that even without -a option. 
For programs without debug information, I need -a option and - to make the
frontend robust w.r.t UX - I disable the menu item. 

I can indeed just try and catch the error, but this seems to be too heavyweight.
It would mean to disassemble function whenever user switches frames in the 
UI or in CLI. I can cache the result, but still. This new feature just makes
it trivial and fast enough (no MI roundtrip to enable/disable menu item)

That being said, I do not insist on having this feature. I'm close to the point
of just saying "you need to use my patched GDB, anyway.  At least for "now" and 
hope that my patches will eventually make it into official GDB release. Not a big 
deal for me, not at all. 

So, if you (meaning you maintainers) prefer not having this feature, I'll just remove 
it. Absolutely no problem! Just let me know. 

Jan

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-10 10:28                           ` Jan Vrany
@ 2018-08-10 10:41                             ` Pedro Alves
  2018-08-14  9:16                               ` Jan Vrany
  0 siblings, 1 reply; 21+ messages in thread
From: Pedro Alves @ 2018-08-10 10:41 UTC (permalink / raw)
  To: Jan Vrany, gdb-patches

On 08/10/2018 11:28 AM, Jan Vrany wrote:
> On Fri, 2018-08-10 at 10:47 +0100, Pedro Alves wrote:
>> On 08/10/2018 09:29 AM, Jan Vrany wrote:
>>> @@ -33095,6 +33101,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
>>>  @item exec-run-start-option
>>>  Indicates that the @code{-exec-run} command supports the @option{--start}
>>>  option (@pxref{GDB/MI Program Execution}).
>>> +@item data-disassemble-a-option
>>> +Indicates that the @code{-data-disassemble} command supports the @option{-a}
>>> +option (@pxref{GDB/MI Data Manipulation}).
>>>  @end ftable
>>
>> I'm curious about how you intend to use this new -list-features feature.
>> Are you enabling/disabling some UI element depending on presence of the
>> feature?  I.e., something that you wouldn't be able to do by just
>> trying the "-data-disassemble -a" command and looking for error?
> 
> Yes. Basically I have a menu item on frame that opens another window with
> disassembly of the coresponding function (showing current instruction, 
> (basic) blocks and alike). 
> 
> For programs with debug information, I can do that even without -a option. 
> For programs without debug information, I need -a option and - to make the
> frontend robust w.r.t UX - I disable the menu item. 
> 
> I can indeed just try and catch the error, but this seems to be too heavyweight.
> It would mean to disassemble function whenever user switches frames in the 
> UI or in CLI. I can cache the result, but still. This new feature just makes
> it trivial and fast enough (no MI roundtrip to enable/disable menu item)

Ahah, thanks.  (IMHO, that's useful info that include in a submission that
proposes a -list-features addition.)

> 
> That being said, I do not insist on having this feature. I'm close to the point
> of just saying "you need to use my patched GDB, anyway.  At least for "now" and 
> hope that my patches will eventually make it into official GDB release. Not a big 
> deal for me, not at all. 
> 
> So, if you (meaning you maintainers) prefer not having this feature, I'll just remove 
> it. Absolutely no problem! Just let me know. 

I was really just curious.  And TBC, I was just talking about the -list-features
entry, not the actual whole "-a" feature added by the patch, which I agree is useful.

> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,9 @@
>  
>  *** Changes since GDB 8.1
>  
> +* The '-data-disassemble' MI command now accepts the '-a' option to disassemble
> +  the whole function surrounding given program counter value or function name.

This should be moved to the "since 8.2" section.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-10  8:29                       ` Jan Vrany
@ 2018-08-10 13:22                         ` Tom Tromey
  0 siblings, 0 replies; 21+ messages in thread
From: Tom Tromey @ 2018-08-10 13:22 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches, Tom Tromey

>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:

Jan> I do not have commit access to the repo (it's my preference for the moment). 
Jan> New patch will follow shortly. Simon, could you please push it for me if 
Jan> it's OK? 

It's no problem for me to do it as well.

Tom

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-10 10:41                             ` Pedro Alves
@ 2018-08-14  9:16                               ` Jan Vrany
  2018-08-14 13:57                                 ` Pedro Alves
  2018-08-14 14:40                                 ` Eli Zaretskii
  0 siblings, 2 replies; 21+ messages in thread
From: Jan Vrany @ 2018-08-14  9:16 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

A CLI command "disassemble" allows use to specify a single
address - in that case function surrounding that address is
disassembled.

This commit adds this feature to MI command "-data-disassemble".

gdb/ChangeLog:

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi/mi-main.c): Add new feature
	data-disassemble-a-option to indicate that -data-disassemble
	supports -a.
	* NEWS: Mention new -data-disassemble option -a

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document data-disassemble-a-option
	feature

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
	tests for -data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           | 10 +++++++
 gdb/NEWS                                |  3 +++
 gdb/doc/ChangeLog                       |  7 +++++
 gdb/doc/gdb.texinfo                     |  9 +++++++
 gdb/mi/mi-cmd-disas.c                   | 35 +++++++++++++++++++------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/ChangeLog                 |  6 +++++
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 ++++++++++++--
 8 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0e1848c00c..f4b880d545 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi/mi-main.c): Add new feature
+	data-disassemble-a-option to indicate that -data-disassemble
+	supports -a.
+	* NEWS: Mention new -data-disassemble option -a
+
 2018-08-13  Alan Hayward  <alan.hayward@arm.com>
 
 	* aarch64-linux-tdep.c (aarch64_linux_supply_sve_regset): New function.
diff --git a/gdb/NEWS b/gdb/NEWS
index f275031345..3110210bb9 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 8.2
 
+* The '-data-disassemble' MI command now accepts the '-a' option to disassemble
+  the whole function surrounding given program counter value or function name.
+
 * GDB and GDBserver now support IPv6 connections.  IPv6 addresses
   can be passed using the '[ADDRESS]:PORT' notation, or the regular
   'ADDRESS:PORT' method.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ceb4043e32..e1e6a31c95 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document data-disassemble-a-option
+	feature
+
 2018-08-07  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* gdb.texinfo (Index Files Speed Up GDB): Add section about
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b931834400..c6452220a4 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -31208,6 +31208,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -31220,6 +31221,11 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is the address anywhere in function code (or function name).  If @code{-a}
+@var{addr} is used, the whole function surrounding that address will be
+disassembled. If @var{addr} is a function name, the whole function with that
+name will be disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33356,6 +33362,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34..8f0b126fb3 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,23 +125,33 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+	case ADDR_OPT:
+	  addr = parse_and_eval_address (oarg);
+	  addr_seen = 1;
+	  break;
 	}
     }
   argv += oind;
   argc -= oind;
 
   /* Allow only filename + linenum (with how_many which is not
-     required) OR start_addr + end_addr.  */
+     required) OR start_addr + end_addr OR addr  */
+
+  if (!(
+          ( line_seen &&  file_seen &&              !start_seen && !end_seen
+								&& !addr_seen)
+
+       || (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen
+								&& !addr_seen)
 
-  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)))
+       || (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen
+								&&  addr_seen)))
     error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
-	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
+	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
+             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +197,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen) 
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2163d42302..1e31040d1e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index bd3c3bfec5..aaaef820ed 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added
+	tests for -data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-08-09  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* gdb.base/vla-optimized-out.exp: Add new test.
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf5884..393e8b35b5 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "113-data-disassemble -a callee4 -- 0" \
+	    "113\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address (-s -e)"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address (-a)"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.18.0

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-14  9:16                               ` Jan Vrany
@ 2018-08-14 13:57                                 ` Pedro Alves
  2018-08-14 14:40                                 ` Eli Zaretskii
  1 sibling, 0 replies; 21+ messages in thread
From: Pedro Alves @ 2018-08-14 13:57 UTC (permalink / raw)
  To: Jan Vrany, gdb-patches

On 08/14/2018 10:15 AM, Jan Vrany wrote:
> A CLI command "disassemble" allows use to specify a single
> address - in that case function surrounding that address is
> disassembled.
> 
> This commit adds this feature to MI command "-data-disassemble".
> 

Thanks.  I've pushed in the patch as at the end of this message,
after fixing a few nits I'll mention below.

> gdb/ChangeLog:
> 
> 	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Added -a option.

Write present tense.

> 	If used, use find_pc_partial_function to find address range
> 	to disassemble.
> 	* mi/mi-main.c (mi/mi-main.c): Add new feature

Should be function name instead of "(mi/mi-main.c)".

> 	data-disassemble-a-option to indicate that -data-disassemble
> 	supports -a.
> 	* NEWS: Mention new -data-disassemble option -a

Missing period.

> 
> gdb/doc/ChangeLog:
> 
> 	* gdb.texinfo (GDB/MI Data Manipulation): Document
> 	"-data-disassemble -a addr".
> 	(GDB/MI Support Commands): Document data-disassemble-a-option
> 	feature

Missing period.

> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Added

Present tense.

> 	tests for -data-disassemble -a.
> 	(test_disassembly_bogus_args): Likewise.

>  	* aarch64-linux-tdep.c (aarch64_linux_supply_sve_regset): New function.
> diff --git a/gdb/NEWS b/gdb/NEWS
> index f275031345..3110210bb9 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,9 @@
>  
>  *** Changes since GDB 8.2
>  
> +* The '-data-disassemble' MI command now accepts the '-a' option to disassemble
> +  the whole function surrounding given program counter value or function name.

I moved this into a new "MI changes" section below the CLI commands, and
also added a new sentence for the -list-features addition (borrowed from
earlier MI changes).

> +
>  * GDB and GDBserver now support IPv6 connections.  IPv6 addresses
>    can be passed using the '[ADDRESS]:PORT' notation, or the regular
>    'ADDRESS:PORT' method.
> diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
> index ceb4043e32..e1e6a31c95 100644
> --- a/gdb/doc/ChangeLog
> +++ b/gdb/doc/ChangeLog
> @@ -1,3 +1,10 @@
> +2018-07-05  Jan Vrany  <jan.vrany@fit.cvut.cz>
> +
> +	* gdb.texinfo (GDB/MI Data Manipulation): Document
> +	"-data-disassemble -a addr".
> +	(GDB/MI Support Commands): Document data-disassemble-a-option
> +	feature
> +
>  2018-08-07  Simon Marchi  <simon.marchi@ericsson.com>
>  
>  	* gdb.texinfo (Index Files Speed Up GDB): Add section about
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index b931834400..c6452220a4 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -31208,6 +31208,7 @@ For details about what an addressable memory unit is,
>  @smallexample
>   -data-disassemble
>      [ -s @var{start-addr} -e @var{end-addr} ]
> +  | [ -a @var{addr} ]
>    | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
>    -- @var{mode}
>  @end smallexample
> @@ -31220,6 +31221,11 @@ Where:
>  is the beginning address (or @code{$pc})
>  @item @var{end-addr}
>  is the end address
> +@item @var{addr}
> +is the address anywhere in function code (or function name).  If @code{-a}
> +@var{addr} is used, the whole function surrounding that address will be
> +disassembled. If @var{addr} is a function name, the whole function with that
> +name will be disassembled.

It took me a bit to understand what "address anywhere in function code"
meant.  I took the liberty of rewording the sentence a bit.

>  @item @var{filename}
>  is the name of the file to disassemble
>  @item @var{linenum}
> @@ -33356,6 +33362,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
>  @item exec-run-start-option
>  Indicates that the @code{-exec-run} command supports the @option{--start}
>  option (@pxref{GDB/MI Program Execution}).
> +@item data-disassemble-a-option
> +Indicates that the @code{-data-disassemble} command supports the @option{-a}
> +option (@pxref{GDB/MI Data Manipulation}).
>  @end ftable
>  
>  @subheading The @code{-list-target-features} Command

>      error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
> -	     "howmany]] | [-s startaddr -e endaddr]) [--] mode."));
> +	     "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
>  
>    if (argc != 1)
> -    error (_("-data-disassemble: Usage: [-f filename -l linenum "
> -	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
> +    error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n "
> +             "howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
>  

While at it, might as well merge the 'if's instead of changing the same
string twice.

>    mode = atoi (argv[0]);
>    if (mode < 0 || mode > 5)
> @@ -184,6 +197,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
>  	error (_("-data-disassemble: "
>  		 "No function contains specified address"));
>      }
> +  else if (addr_seen) 

Spurious whitespace after "(addr_seen)".

> +    {
> +      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
> +        error (_("-data-disassemble: "
> +                 "No function contains specified address"));
> +    }
>  
>    gdb_disassembly (gdbarch, uiout,
>    		   disasm_flags,
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index 2163d42302..1e31040d1e 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c

> @@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
>  
>      mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
>               "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
> -             "data-disassemble bogus address"
> +             "data-disassemble bogus address (-s -e)"
> +
> +    mi_gdb_test "322-data-disassemble -a foo -- 0" \
> +             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
> +             "data-disassemble bogus address (-a)"

No tail " (foo)" in test names:

  https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages

I've switched those to use "," instead.

>  
>      mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
> -             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
> +             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
>               "data-disassemble mix different args"
>  
>      mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
> 

Here's what I merged.

From 26fb3983d7062c6f6bc43028ae2074cc29d22c7e Mon Sep 17 00:00:00 2001
From: Jan Vrany <jan.vrany@fit.cvut.cz>
Date: Tue, 14 Aug 2018 14:13:28 +0100
Subject: [PATCH] MI: Add -a option to the "-data-disassemble" command

The CLI "disassemble" command allows specifying a single address - in
that case the function surrounding that address is disassembled.

This commit adds this feature to the equivalent MI command
"-data-disassemble".

gdb/ChangeLog:
2018-08-14  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Add -a option.
	If used, use find_pc_partial_function to find address range
	to disassemble.
	* mi/mi-main.c (mi_cmd_list_features): Report
	"data-disassemble-a-option" feature.
	* NEWS: Mention new -data-disassemble option -a.

gdb/doc/ChangeLog:
2018-08-14  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.texinfo (GDB/MI Data Manipulation): Document
	"-data-disassemble -a addr".
	(GDB/MI Support Commands): Document "data-disassemble-a-option"
	feature.

gdb/testsuite/ChangeLog:
2018-08-14  Jan Vrany  <jan.vrany@fit.cvut.cz>

	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Add tests for
	-data-disassemble -a.
	(test_disassembly_bogus_args): Likewise.
---
 gdb/ChangeLog                           |  9 +++++++++
 gdb/doc/ChangeLog                       |  7 +++++++
 gdb/testsuite/ChangeLog                 |  6 ++++++
 gdb/doc/gdb.texinfo                     |  9 +++++++++
 gdb/NEWS                                |  8 ++++++++
 gdb/mi/mi-cmd-disas.c                   | 36 ++++++++++++++++++++++++---------
 gdb/mi/mi-main.c                        |  1 +
 gdb/testsuite/gdb.mi/mi-disassemble.exp | 20 ++++++++++++++++--
 8 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 37ab81b0a93..d16920d80e9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2018-08-14  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* mi/mi-cmd-disas.c (mi_cmd_disassemble): Add -a option.
+	If used, use find_pc_partial_function to find address range
+	to disassemble.
+	* mi/mi-main.c (mi_cmd_list_features): Report
+	"data-disassemble-a-option" feature.
+	* NEWS: Mention new -data-disassemble option -a.
+
 2018-08-13  Tom Tromey  <tom@tromey.com>
 
 	* common/common-defs.h (_FORTIFY_SOURCE): Define.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index ceb4043e326..8688b7fdd93 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,10 @@
+2018-08-14  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.texinfo (GDB/MI Data Manipulation): Document
+	"-data-disassemble -a addr".
+	(GDB/MI Support Commands): Document "data-disassemble-a-option"
+	feature.
+
 2018-08-07  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* gdb.texinfo (Index Files Speed Up GDB): Add section about
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 33749aa6763..1b4dde59bb6 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-08-14  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+	* gdb.mi/mi-disassemble.exp (test_disassembly_only): Add tests for
+	-data-disassemble -a.
+	(test_disassembly_bogus_args): Likewise.
+
 2018-08-14  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* gdb.mi/list-thread-groups-available.exp: Update test regexp.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b9318344002..433a2698a92 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -31208,6 +31208,7 @@ For details about what an addressable memory unit is,
 @smallexample
  -data-disassemble
     [ -s @var{start-addr} -e @var{end-addr} ]
+  | [ -a @var{addr} ]
   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
   -- @var{mode}
 @end smallexample
@@ -31220,6 +31221,11 @@ Where:
 is the beginning address (or @code{$pc})
 @item @var{end-addr}
 is the end address
+@item @var{addr}
+is an address anywhere within (or the name of) the function to
+disassemble.  If an address is specified, the whole function
+surrounding that address will be disassembled.  If a name is
+specified, the whole function with that name will be disassembled.
 @item @var{filename}
 is the name of the file to disassemble
 @item @var{linenum}
@@ -33356,6 +33362,9 @@ records, produced when trying to execute an undefined @sc{gdb/mi} command
 @item exec-run-start-option
 Indicates that the @code{-exec-run} command supports the @option{--start}
 option (@pxref{GDB/MI Program Execution}).
+@item data-disassemble-a-option
+Indicates that the @code{-data-disassemble} command supports the @option{-a}
+option (@pxref{GDB/MI Data Manipulation}).
 @end ftable
 
 @subheading The @code{-list-target-features} Command
diff --git a/gdb/NEWS b/gdb/NEWS
index f2750313454..16d3d725897 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -41,6 +41,14 @@ thread apply [all | COUNT | -COUNT] [FLAG]... COMMAND
   FLAG arguments allow to control what output to produce and how to handle
   errors raised when applying COMMAND to a thread.
 
+* MI changes
+
+  ** The '-data-disassemble' MI command now accepts an '-a' option to
+     disassemble the whole function surrounding the given program
+     counter value or function name.  Support for this feature can be
+     verified by using the "-list-features" command, which should
+     contain "data-disassemble-a-option".
+
 * New native configurations
 
 GNU/Linux/RISC-V		riscv*-*-linux*
diff --git a/gdb/mi/mi-cmd-disas.c b/gdb/mi/mi-cmd-disas.c
index e704e35b34b..f0f26356c2d 100644
--- a/gdb/mi/mi-cmd-disas.c
+++ b/gdb/mi/mi-cmd-disas.c
@@ -67,6 +67,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int num_seen = 0;
   int start_seen = 0;
   int end_seen = 0;
+  int addr_seen = 0;
 
   /* ... and their corresponding value. */
   char *file_string = NULL;
@@ -74,13 +75,14 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
   int how_many = -1;
   CORE_ADDR low = 0;
   CORE_ADDR high = 0;
+  CORE_ADDR addr = 0;
 
   /* Options processing stuff.  */
   int oind = 0;
   char *oarg;
   enum opt
   {
-    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT
+    FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT, ADDR_OPT
   };
   static const struct mi_opt opts[] =
     {
@@ -89,6 +91,7 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
       {"n", NUM_OPT, 1},
       {"s", START_OPT, 1},
       {"e", END_OPT, 1},
+      {"a", ADDR_OPT, 1},
       { 0, 0, 0 }
     };
 
@@ -122,23 +125,30 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	  high = parse_and_eval_address (oarg);
 	  end_seen = 1;
 	  break;
+	case ADDR_OPT:
+	  addr = parse_and_eval_address (oarg);
+	  addr_seen = 1;
+	  break;
 	}
     }
   argv += oind;
   argc -= oind;
 
   /* Allow only filename + linenum (with how_many which is not
-     required) OR start_addr + end_addr.  */
+     required) OR start_addr + end_addr OR addr.  */
+
+  if (!(
+          ( line_seen &&  file_seen &&              !start_seen && !end_seen
+								&& !addr_seen)
 
-  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."));
+       || (!line_seen && !file_seen && !num_seen &&  start_seen &&  end_seen
+								&& !addr_seen)
 
-  if (argc != 1)
-    error (_("-data-disassemble: Usage: [-f filename -l linenum "
-	     "[-n howmany]] [-s startaddr -e endaddr] [--] mode."));
+       || (!line_seen && !file_seen && !num_seen && !start_seen && !end_seen
+								&&  addr_seen))
+      || argc != 1)
+    error (_("-data-disassemble: Usage: ( [-f filename -l linenum "
+	     "[-n howmany]] | [-s startaddr -e endaddr] | [-a addr] ) [--] mode."));
 
   mode = atoi (argv[0]);
   if (mode < 0 || mode > 5)
@@ -184,6 +194,12 @@ mi_cmd_disassemble (const char *command, char **argv, int argc)
 	error (_("-data-disassemble: "
 		 "No function contains specified address"));
     }
+  else if (addr_seen)
+    {
+      if (find_pc_partial_function (addr, NULL, &low, &high) == 0)
+        error (_("-data-disassemble: "
+                 "No function contains specified address"));
+    }
 
   gdb_disassembly (gdbarch, uiout,
   		   disasm_flags,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 2163d423028..1e31040d1e2 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1683,6 +1683,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
       uiout->field_string (NULL, "info-gdb-mi-command");
       uiout->field_string (NULL, "undefined-command-error-code");
       uiout->field_string (NULL, "exec-run-start-option");
+      uiout->field_string (NULL, "data-disassemble-a-option");
 
       if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
 	uiout->field_string (NULL, "python");
diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp
index 6b1fcf58845..f9399477e5a 100644
--- a/gdb/testsuite/gdb.mi/mi-disassemble.exp
+++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp
@@ -46,13 +46,24 @@ proc test_disassembly_only {} {
     # Test disassembly more only for the current function.
     # Tests:
     # -data-disassemble -s $pc -e "$pc+8" -- 0
+    # -data-disassemble -a $pc -- 0
+    # -data-disassemble -a callee4 -- 0
     # -data-disassembly -f basics.c -l $line_main_body -- 0
 
+
     mi_gdb_test "print/x \$pc" "" ""
     mi_gdb_test "111-data-disassemble -s \$pc -e \"\$pc + 12\" -- 0" \
 	    "111\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
              "data-disassemble from pc to pc+12 assembly only"
 
+    mi_gdb_test "112-data-disassemble -a \$pc -- 0" \
+	    "112\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"main\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function around pc assembly only"
+
+    mi_gdb_test "113-data-disassemble -a callee4 -- 0" \
+	    "113\\^done,asm_insns=\\\[\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\},\{address=\"$hex\",func-name=\"callee4\",offset=\"$decimal\",inst=\".*\"\}.*\]" \
+             "data-disassemble function callee4 assembly only"
+
     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"
@@ -207,6 +218,7 @@ proc test_disassembly_bogus_args {} {
     # Tests:
     # -data-disassembly -f foo -l abc -n 0 -- 0
     # -data-disassembly -s foo -e bar -- 0
+    # -data-disassembly -a foo -- 0
     # -data-disassembly -s $pc -f basics.c -- 0
     # -data-disassembly -f basics.c -l 32 -- 9
 
@@ -216,10 +228,14 @@ proc test_disassembly_bogus_args {} {
 
     mi_gdb_test "321-data-disassemble -s foo -e bar -- 0" \
              "321\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
-             "data-disassemble bogus address"
+             "data-disassemble bogus address, -s -e"
+
+    mi_gdb_test "322-data-disassemble -a foo -- 0" \
+             "322\\^error,msg=\"No symbol \\\\\"foo\\\\\" in current context.\"" \
+             "data-disassemble bogus address, -a"
 
     mi_gdb_test "456-data-disassemble -s \$pc -f basics.c -- 0" \
-             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr.\\) .--. mode.\"" \
+             "456\\^error,msg=\"-data-disassemble: Usage: \\( .-f filename -l linenum .-n howmany.. \\| .-s startaddr -e endaddr. \\| .-a addr. \\) .--. mode.\"" \
              "data-disassemble mix different args"
 
     mi_gdb_test "789-data-disassemble -f basics.c -l $line_main_body -- 9" \
-- 
2.14.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [RFC] mi: add -a option to the "-data-disassemble" command
  2018-08-14  9:16                               ` Jan Vrany
  2018-08-14 13:57                                 ` Pedro Alves
@ 2018-08-14 14:40                                 ` Eli Zaretskii
  1 sibling, 0 replies; 21+ messages in thread
From: Eli Zaretskii @ 2018-08-14 14:40 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches

> From: Jan Vrany <jan.vrany@fit.cvut.cz>
> Cc: Jan Vrany <jan.vrany@fit.cvut.cz>
> Date: Tue, 14 Aug 2018 10:15:43 +0100
> 
> A CLI command "disassemble" allows use to specify a single
> address - in that case function surrounding that address is
> disassembled.
> 
> This commit adds this feature to MI command "-data-disassemble".

Thanks.

>  *** Changes since GDB 8.2
>  
> +* The '-data-disassemble' MI command now accepts the '-a' option to disassemble
> +  the whole function surrounding given program counter value or function name.

This is OK, but please make the lines shorter by a couple of
characters.

> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -31208,6 +31208,7 @@ For details about what an addressable memory unit is,
>  @smallexample
>   -data-disassemble
>      [ -s @var{start-addr} -e @var{end-addr} ]
> +  | [ -a @var{addr} ]
>    | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
>    -- @var{mode}
>  @end smallexample
> @@ -31220,6 +31221,11 @@ Where:
>  is the beginning address (or @code{$pc})
>  @item @var{end-addr}
>  is the end address
> +@item @var{addr}
> +is the address anywhere in function code (or function name).  If @code{-a}
> +@var{addr} is used, the whole function surrounding that address will be

This separates -a and ADDR, which can confuse the reader.  Suggest to
reword:

  @item @var{addr}
  is either the name of a function, or an address anywhere in
  function's code.  If @code{-a} followed by an @var{addr} is used,
  the specified function will be disassembled

> +disassembled. If @var{addr} is a function name, the whole function with that
> +name will be disassembled.

The last sentence can be dropped if you agree with my rewording, as it
is now redundant.

The documentation parts are OK with the above fixed.

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2018-08-14 14:40 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-06  9:39 [RFC] mi: add -a option to the "-data-disassemble" command Jan Vrany
2018-07-06 12:37 ` Eli Zaretskii
2018-07-14 17:39   ` Jan Vrany
2018-07-14 18:27     ` Eli Zaretskii
2018-07-26 14:56       ` Jan Vrany
2018-07-26 17:47         ` Eli Zaretskii
2018-07-27  7:57           ` Jan Vrany
2018-07-30 15:05             ` Tom Tromey
2018-07-31 10:23               ` Jan Vrany
2018-07-31 15:48                 ` Tom Tromey
2018-07-31 20:35                   ` Jan Vrany
2018-08-09 20:47                     ` Tom Tromey
2018-08-10  8:29                       ` Jan Vrany
2018-08-10 13:22                         ` Tom Tromey
2018-08-10  8:30                       ` Jan Vrany
2018-08-10  9:47                         ` Pedro Alves
2018-08-10 10:28                           ` Jan Vrany
2018-08-10 10:41                             ` Pedro Alves
2018-08-14  9:16                               ` Jan Vrany
2018-08-14 13:57                                 ` Pedro Alves
2018-08-14 14:40                                 ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).