[PATCHv3,7/9] gdb/mi: Add -symbol-info-modules command

Message ID 8e9444763b04392bdfdd9d378c4a6e9bde2c119b.1571268432.git.andrew.burgess@embecosm.com
State New, archived
Headers

Commit Message

Andrew Burgess Oct. 16, 2019, 11:28 p.m. UTC
  Add '-symbol-info-modules', an MI version of the CLI 'info modules'
command.

gdb/ChangeLog:

	* mi/mi-cmds.c (mi_cmds): Add 'symbol-info-modules' entry.
	* mi/mi-cmds.h (mi_cmd_symbol_info_modules): Declare.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_info_modules): New function.
	* NEWS: Mention new MI command.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-fortran-modules-2.f90: New file.
	* gdb.mi/mi-fortran-modules.exp: New file.
	* gdb.mi/mi-fortran-modules.f90: New file.

gdb/doc/ChangeLog:

	* doc/gdb.texinfo (GDB/MI Symbol Query): Document new MI command
	-symbol-info-modules.

Change-Id: Ibc618010d1d5f36ae8a8baba4fb9d9d724e62b0f
---
 gdb/ChangeLog                                 |  7 +++
 gdb/NEWS                                      |  3 +
 gdb/doc/ChangeLog                             |  5 ++
 gdb/doc/gdb.texinfo                           | 54 +++++++++++++++++
 gdb/mi/mi-cmds.c                              |  1 +
 gdb/mi/mi-cmds.h                              |  1 +
 gdb/mi/mi-symbol-cmds.c                       | 37 ++++++++++++
 gdb/testsuite/ChangeLog                       |  6 ++
 gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90 | 33 ++++++++++
 gdb/testsuite/gdb.mi/mi-fortran-modules.exp   | 52 ++++++++++++++++
 gdb/testsuite/gdb.mi/mi-fortran-modules.f90   | 87 +++++++++++++++++++++++++++
 11 files changed, 286 insertions(+)
 create mode 100644 gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90
 create mode 100644 gdb/testsuite/gdb.mi/mi-fortran-modules.exp
 create mode 100644 gdb/testsuite/gdb.mi/mi-fortran-modules.f90
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 81ad7f26bfb..b8c92e046eb 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -336,6 +336,9 @@  focus, winheight, +, -, >, <
   These commands are the MI equivalent of the CLI commands 'info
   functions', 'info types', and 'info variables' respectively.
 
+-symbol-info-modules, this is the MI equivalent of the CLI 'info
+  modules' command.
+
 * Other MI changes
 
  ** The default version of the MI interpreter is now 3 (-i=mi3).
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 57bcde19894..e8985e107a7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -33851,6 +33851,60 @@ 
 @end group
 @end smallexample
 
+@subheading The @code{-symbol-info-modules} Command
+@findex -symbol-info-modules
+@anchor{-symbol-info-modules}
+
+@subsubheading Synopsis
+
+@smallexample
+ -symbol-info-modules [--name @var{name_regexp}]
+@end smallexample
+
+@noindent
+Return a list containing the names of all known Fortran modules.  The
+modules are grouped by source file, and shown with the line number on
+which each modules is defined.
+
+The option @code{--name} allows the modules returned to be filtered
+based the name of the module.
+
+@subsubheading @value{GDBN} Command
+
+The corresponding @value{GDBN} command is @samp{info modules}.
+
+@subsubheading Example
+@smallexample
+@group
+(gdb)
+-symbol-info-modules
+^done,symbols=
+  @{debug=
+    [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
+      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
+      symbols=[@{line="16",name="mod1"@},
+               @{line="22",name="mod2"@}]@},
+     @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
+      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
+      symbols=[@{line="16",name="mod3"@},
+               @{line="22",name="modmany"@},
+               @{line="26",name="moduse"@}]@}]@}
+@end group
+@group
+(gdb)
+-symbol-info-modules --name mod[123]
+^done,symbols=
+  @{debug=
+    [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
+      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
+      symbols=[@{line="16",name="mod1"@},
+               @{line="22",name="mod2"@}]@},
+     @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
+      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
+      symbols=[@{line="16",name="mod3"@}]@}]@}
+@end group
+@end smallexample
+
 @subheading The @code{-symbol-info-types} Command
 @findex -symbol-info-types
 @anchor{-symbol-info-types}
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index df9f25fcbd0..85c15ec5357 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -154,6 +154,7 @@  static struct mi_cmd mi_cmds[] =
   DEF_MI_CMD_MI ("symbol-info-functions", mi_cmd_symbol_info_functions),
   DEF_MI_CMD_MI ("symbol-info-variables", mi_cmd_symbol_info_variables),
   DEF_MI_CMD_MI ("symbol-info-types", mi_cmd_symbol_info_types),
+  DEF_MI_CMD_MI ("symbol-info-modules", mi_cmd_symbol_info_modules),
   DEF_MI_CMD_CLI ("target-attach", "attach", 1),
   DEF_MI_CMD_MI ("target-detach", mi_cmd_target_detach),
   DEF_MI_CMD_CLI ("target-disconnect", "disconnect", 0),
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index c2fd7d30d63..30de780286b 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -95,6 +95,7 @@  extern mi_cmd_argv_ftype mi_cmd_stack_list_variables;
 extern mi_cmd_argv_ftype mi_cmd_stack_select_frame;
 extern mi_cmd_argv_ftype mi_cmd_symbol_list_lines;
 extern mi_cmd_argv_ftype mi_cmd_symbol_info_functions;
+extern mi_cmd_argv_ftype mi_cmd_symbol_info_modules;
 extern mi_cmd_argv_ftype mi_cmd_symbol_info_types;
 extern mi_cmd_argv_ftype mi_cmd_symbol_info_variables;
 extern mi_cmd_argv_ftype mi_cmd_target_detach;
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index 6b0aa9538f5..ecf5293f874 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -238,6 +238,43 @@  mi_cmd_symbol_info_functions (const char *command, char **argv, int argc)
   mi_info_functions_or_variables (FUNCTIONS_DOMAIN, argv, argc);
 }
 
+/* Implement -symbol-inf-modules command.  */
+
+void
+mi_cmd_symbol_info_modules (const char *command, char **argv, int argc)
+{
+  const char *regexp = nullptr;
+
+  enum opt
+    {
+     NAME_REGEXP_OPT
+    };
+  static const struct mi_opt opts[] =
+  {
+    {"-name", NAME_REGEXP_OPT, 1},
+    { 0, 0, 0 }
+  };
+
+  int oind = 0;
+  char *oarg = nullptr;
+
+  while (1)
+    {
+      int opt = mi_getopt ("-symbol-info-modules", argc, argv, opts,
+			   &oind, &oarg);
+      if (opt < 0)
+	break;
+      switch ((enum opt) opt)
+	{
+	case NAME_REGEXP_OPT:
+	  regexp = oarg;
+	  break;
+	}
+    }
+
+  mi_symbol_info (MODULES_DOMAIN, regexp, nullptr, true);
+}
+
 /* Implement -symbol-info-types command.  */
 
 void
diff --git a/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90 b/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90
new file mode 100644
index 00000000000..690d54dde8c
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90
@@ -0,0 +1,33 @@ 
+! Copyright 2009-2019 Free Software Foundation, Inc.
+!
+! This program is free software; you can redistribute it and/or modify
+! it under the terms of the GNU General Public License as published by
+! the Free Software Foundation; either version 3 of the License, or
+! (at your option) any later version.
+!
+! This program is distributed in the hope that it will be useful,
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+! GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+module mod1
+  integer :: var_i = 1
+  integer :: var_const
+  parameter (var_const = 20)
+contains
+  subroutine check_all
+    if (var_i .ne. 1) call abort
+    if (var_const .ne. 20) call abort
+  end subroutine check_all
+end module mod1
+
+module mod2
+  integer :: var_i = 2
+contains
+    subroutine check_var_i
+    if (var_i .ne. 2) call abort
+  end subroutine check_var_i
+end module mod2
diff --git a/gdb/testsuite/gdb.mi/mi-fortran-modules.exp b/gdb/testsuite/gdb.mi/mi-fortran-modules.exp
new file mode 100644
index 00000000000..640bb12642d
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-fortran-modules.exp
@@ -0,0 +1,52 @@ 
+# Copyright 2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test -symbol-info-modules, listing Fortran modules.
+
+load_lib fortran.exp
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile "mi-fortran-modules.f90" "mi-fortran-modules-2.f90"
+
+if {[prepare_for_testing "failed to prepare" ${testfile} \
+	 [list $srcfile $srcfile2] {debug f90}]} {
+    return -1
+}
+
+gdb_exit
+if {[mi_gdb_start]} {
+    continue
+}
+
+mi_run_to_main
+
+mi_gdb_test "101-symbol-info-modules" \
+    "101\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"16\",name=\"mod1\"\},\{line=\"27\",name=\"mod2\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"16\",name=\"mod3\"\},\{line=\"32\",name=\"modmany\"\},\{line=\"41\",name=\"moduse\"\}\\\]\}\\\]\}" \
+    "-symbol-info-modules"
+
+mi_gdb_test "102-symbol-info-modules --name mod\[123\]" \
+    "102\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"16\",name=\"mod1\"\},\{line=\"27\",name=\"mod2\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"16\",name=\"mod3\"\}\\\]\}\\\]\}" \
+    "-symbol-info-modules --name mod\[123\]"
+
+mi_gdb_test "103-symbol-info-modules --name moduse" \
+    "103\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"41\",name=\"moduse\"\}\\\]\}\\\]\}" \
+    "-symbol-info-modules --name moduse"
+
+
+
+
+
+
diff --git a/gdb/testsuite/gdb.mi/mi-fortran-modules.f90 b/gdb/testsuite/gdb.mi/mi-fortran-modules.f90
new file mode 100644
index 00000000000..d2546270c6e
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-fortran-modules.f90
@@ -0,0 +1,87 @@ 
+! Copyright 2009-2019 Free Software Foundation, Inc.
+! 
+! This program is free software; you can redistribute it and/or modify
+! it under the terms of the GNU General Public License as published by
+! the Free Software Foundation; either version 3 of the License, or
+! (at your option) any later version.
+! 
+! This program is distributed in the hope that it will be useful,
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+! GNU General Public License for more details.
+! 
+! You should have received a copy of the GNU General Public License
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+module mod3
+  integer :: mod2 = 3
+  integer :: mod1 = 3
+  integer :: var_i = 3
+contains
+  subroutine check_all
+    if (mod2 .ne. 3) call abort
+    if (mod1 .ne. 3) call abort
+    if (var_i .ne. 3) call abort
+  end subroutine check_all
+
+  subroutine check_mod2
+    if (mod2 .ne. 3) call abort
+  end subroutine check_mod2
+end module mod3
+
+module modmany
+  integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
+contains
+  subroutine check_some
+    if (var_a .ne. 10) call abort
+    if (var_b .ne. 11) call abort
+  end subroutine check_some
+end module modmany
+
+module moduse
+  integer :: var_x = 30, var_y = 31
+contains
+  subroutine check_all
+    if (var_x .ne. 30) call abort
+    if (var_y .ne. 31) call abort
+  end subroutine check_all
+
+  subroutine check_var_x
+    if (var_x .ne. 30) call abort
+  end subroutine check_var_x
+end module moduse
+
+subroutine sub1
+  use mod1
+  if (var_i .ne. 1) call abort
+  var_i = var_i                         ! i-is-1
+end subroutine sub1
+
+subroutine sub2
+  use mod2
+  if (var_i .ne. 2) call abort
+  var_i = var_i                         ! i-is-2
+end subroutine sub2
+
+subroutine sub3
+  use mod3
+  var_i = var_i                         ! i-is-3
+end subroutine sub3
+
+program module
+
+  use modmany, only: var_b, var_d => var_c, var_i
+  use moduse, var_z => var_y
+
+  call sub1
+  call sub2
+  call sub3
+
+  if (var_b .ne. 11) call abort
+  if (var_d .ne. 12) call abort
+  if (var_i .ne. 14) call abort
+  if (var_x .ne. 30) call abort
+  if (var_z .ne. 31) call abort
+  var_b = var_b                         ! a-b-c-d
+
+end program module