diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-07-10 15:54:03 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-10-31 23:02:59 +0000 |
commit | 165f8965d770708f1dee623e308374ac108e6578 (patch) | |
tree | ba457b4dbe2fe85bf195d1da7feb22a8bab0abe7 /gdb/testsuite | |
parent | 59c35742fb785b1e454f45c2ace663000bf34f4c (diff) | |
download | gdb-165f8965d770708f1dee623e308374ac108e6578.zip gdb-165f8965d770708f1dee623e308374ac108e6578.tar.gz gdb-165f8965d770708f1dee623e308374ac108e6578.tar.bz2 |
gdb: Add new commands to list module variables and functions
This patch adds two new commands "info module functions" and "info
module variables". These commands list all of the functions and
variables grouped by module and then by file.
For example:
(gdb) info module functions
All functions in all modules:
Module "mod1":
File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
35: void mod1::__copy_mod1_M1t1(Type m1t1, Type m1t1);
25: void mod1::sub_m1_a(integer(kind=4));
31: integer(kind=4) mod1::sub_m1_b(void);
Module "mod2":
File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
41: void mod2::sub_m2_a(integer(kind=4), logical(kind=4));
49: logical(kind=4) mod2::sub_m2_b(real(kind=4));
The new commands take set of flags that allow the output to be
filtered, the user can filter by variable/function name, type, or
containing module.
As GDB doesn't currently track the relationship between a module and
the variables or functions within it in the symbol table, so I filter
based on the module prefix in order to find the functions or variables
in each module. What this makes clear is that a user could get this
same information using "info variables" and simply provide the prefix
themselves, for example:
(gdb) info module functions -m mod1 _a
All functions matching regular expression "_a",
in all modules matching regular expression "mod1":
Module "mod1":
File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
25: void mod1::sub_m1_a(integer(kind=4));
Is similar to:
(gdb) info functions mod1::.*_a.*
All functions matching regular expression "mod1::.*_a":
File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
25: void mod1::sub_m1_a(integer(kind=4));
The benefits I see for a separate command are that the user doesn't
have to think (or know) about the module prefix format, nor worry
about building a proper regexp. The user can also easily scan across
modules without having to build complex regexps.
The new function search_module_symbols is extern in this patch despite
only being used within symtab.c, this is because a later patch in this
series will also be using this function from outside symtab.c.
This patch is a new implementation of an idea originally worked on by
Mark O'Connor, Chris January, David Lecomber, and Xavier Oro from ARM.
gdb/ChangeLog:
* symtab.c (info_module_cmdlist): New variable.
(info_module_command): New function.
(search_module_symbols): New function.
(info_module_subcommand): New function.
(struct info_modules_var_func_options): New struct.
(info_modules_var_func_options_defs): New variable.
(make_info_modules_var_func_options_def_group): New function.
(info_module_functions_command): New function.
(info_module_variables_command): New function.
(info_module_var_func_command_completer): New function.
(_initialize_symtab): Register new 'info module functions' and
'info module variables' commands.
* symtab.h (typedef symbol_search_in_module): New typedef.
(search_module_symbols): Declare new function.
* NEWS: Mention new commands.
gdb/doc/ChangeLog:
* gdb.texinfo (Symbols): Document new 'info module variables' and
'info module functions' commands.
gdb/testsuite/ChangeLog:
* gdb.fortran/info-modules.exp: Update expected results, and add
additional tests for 'info module functinos', and 'info module
variables'.
* gdb.fortran/info-types.exp: Update expected results.
* gdb.fortran/info-types.f90: Extend testcase with additional
module variables and functions.
Change-Id: I8c2960640e2e101b77eff54027d687e21ec22e2b
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/info-modules.exp | 123 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/info-types-2.f90 | 16 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/info-types.exp | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/info-types.f90 | 15 |
5 files changed, 166 insertions, 3 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6514c07..4d1eecd 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,14 @@ 2019-10-31 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.fortran/info-modules.exp: Update expected results, and add + additional tests for 'info module functinos', and 'info module + variables'. + * gdb.fortran/info-types.exp: Update expected results. + * gdb.fortran/info-types.f90: Extend testcase with additional + module variables and functions. + +2019-10-31 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.fortran/info-modules.exp: New file. * gdb.fortran/info-types.exp: Build with new file. * gdb.fortran/info-types.f90: Include and use new module. diff --git a/gdb/testsuite/gdb.fortran/info-modules.exp b/gdb/testsuite/gdb.fortran/info-modules.exp index f961d28..4357006 100644 --- a/gdb/testsuite/gdb.fortran/info-modules.exp +++ b/gdb/testsuite/gdb.fortran/info-modules.exp @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# This file tests 'info modules'. +# This file tests 'info modules', 'info module functions', and 'info +# module variables'. load_lib "fortran.exp" @@ -31,6 +32,12 @@ if { ![runto MAIN__] } { continue } +set logical4 [fortran_logical4] +set integer4 [fortran_int4] +set real4 [fortran_real4] + +# Test 'info modules' command. + gdb_test "info modules" \ [multi_line \ "All defined modules:" \ @@ -64,3 +71,117 @@ gdb_test "info modules mod" \ "" \ "File .*${srcfile}:" \ "16:\[\t \]+mod1" ] + +# Test 'info module functions'. + +gdb_test "info module functions" \ + [multi_line \ + "All functions in all modules:" \ + "" \ + "Module \"mod2\":" \ + "" \ + "File .*${srcfile2}:" \ + "22:\[\t \]+void mod2::sub_m2_a\\(${integer4}, ${logical4}\\);" \ + "30:\[\t \]+${logical4} mod2::sub_m2_b\\(${real4}\\);" \ + "" \ + "Module \"mod1\":" \ + "" \ + "File .*${srcfile}:" \ + "35:\[\t \]+void mod1::__copy_mod1_M1t1\\(Type m1t1, Type m1t1\\);" \ + "25:\[\t \]+void mod1::sub_m1_a\\(${integer4}\\);" \ + "31:\[\t \]+${integer4} mod1::sub_m1_b\\(void\\);" ] + +gdb_test "info module functions -m mod1" \ + [multi_line \ + "All functions in all modules matching regular expression \"mod1\":" \ + "" \ + "Module \"mod1\":" \ + "" \ + "File .*:" \ + "35:\[\t \]+void mod1::__copy_mod1_M1t1\\(Type m1t1, Type m1t1\\);" \ + "25:\[\t \]+void mod1::sub_m1_a\\(${integer4}\\);" \ + "31:\[\t \]+${integer4} mod1::sub_m1_b\\(void\\);" ] + +gdb_test "info module functions -t integer" \ + [multi_line \ + "All functions with type matching regular expression \"integer\" in all modules:" \ + "" \ + "Module \"mod2\":" \ + "" \ + "File .*${srcfile2}:" \ + "22:\[\t \]+void mod2::sub_m2_a\\(${integer4}, ${logical4}\\);" \ + "" \ + "Module \"mod1\":" \ + "" \ + "File .*${srcfile}:" \ + "25:\[\t \]+void mod1::sub_m1_a\\(${integer4}\\);" \ + "31:\[\t \]+${integer4} mod1::sub_m1_b\\(void\\);" ] + +# Test 'info module variables'. + +gdb_test "info module variables" \ + [multi_line \ + "All variables in all modules:" \ + "" \ + "Module \"mod2\":" \ + "" \ + "File .*${srcfile2}:" \ + "19:\[\t \]+${integer4} mod2::mod2_var_1;" \ + "20:\[\t \]+${real4} mod2::mod2_var_2;" \ + "" \ + "Module \"mod1\":" \ + "" \ + "File .*${srcfile}:" \ + "35:\[\t \]+Type m1t1 mod1::__def_init_mod1_M1t1;" \ + "35:\[\t \]+Type __vtype_mod1_M1t1 mod1::__vtab_mod1_M1t1;" \ + "21:\[\t \]+${real4} mod1::mod1_var_1;" \ + "22:\[\t \]+${integer4} mod1::mod1_var_2;" ] + +gdb_test "info module variables -t real" \ + [multi_line \ + "All variables with type matching regular expression \"real\" in all modules:" \ + "" \ + "Module \"mod2\":" \ + "" \ + "File .*:" \ + "20:\[\t \]+${real4} mod2::mod2_var_2;" \ + "" \ + "Module \"mod1\":" \ + "" \ + "File .*:" \ + "21:\[\t \]+${real4} mod1::mod1_var_1;" ] + +gdb_test "info module variables -m mod2" \ + [multi_line \ + "All variables in all modules matching regular expression \"mod2\":" \ + "" \ + "Module \"mod2\":" \ + "" \ + "File .*${srcfile2}:" \ + "19:\[\t \]+${integer4} mod2::mod2_var_1;" \ + "20:\[\t \]+${real4} mod2::mod2_var_2;" ] + +gdb_test "info module variables -m mod2 -t real" \ + [multi_line \ + "All variables with type matching regular expression \"real\"" \ + " in all modules matching regular expression \"mod2\":" \ + "" \ + "Module \"mod2\":" \ + "" \ + "File .*${srcfile2}:" \ + "20:\[\t \]+${real4} mod2::mod2_var_2;" ] + +gdb_test "info module variables _1" \ + [multi_line \ + "All variables matching regular expression \"_1\" in all modules:" \ + "" \ + "Module \"mod2\":" \ + "" \ + "File .*:" \ + "19:\[\t \]+${integer4} mod2::mod2_var_1;" \ + "" \ + "Module \"mod1\":" \ + "" \ + "File .*:" \ + "21:\[\t \]+${real4} mod1::mod1_var_1;" ] + diff --git a/gdb/testsuite/gdb.fortran/info-types-2.f90 b/gdb/testsuite/gdb.fortran/info-types-2.f90 index a404418..3fe2259 100644 --- a/gdb/testsuite/gdb.fortran/info-types-2.f90 +++ b/gdb/testsuite/gdb.fortran/info-types-2.f90 @@ -17,4 +17,20 @@ ! mod2 is defined. module mod2 integer :: mod2_var_1 = 123 + real, parameter :: mod2_var_2 = 0.5 +contains + subroutine sub_m2_a(a, b) + integer :: a + logical :: b + print*, "sub_m2_a = ", abc + print*, "a = ", a + print*, "b = ", b + end subroutine sub_m2_a + + logical function sub_m2_b(x) + real :: x + print*, "sub_m2_b = ", cde + print*, "x = ", x + sub_m2_b = .true. + end function sub_m2_b end module mod2 diff --git a/gdb/testsuite/gdb.fortran/info-types.exp b/gdb/testsuite/gdb.fortran/info-types.exp index 954e083..324b4e0 100644 --- a/gdb/testsuite/gdb.fortran/info-types.exp +++ b/gdb/testsuite/gdb.fortran/info-types.exp @@ -35,6 +35,7 @@ set integer4 [fortran_int4] set integer8 [fortran_int8] set logical4 [fortran_logical4] set character1 [fortran_character1] +set real4 [fortran_real4] gdb_test "info types" \ [multi_line \ @@ -45,7 +46,8 @@ gdb_test "info types" \ "\[\t \]+${integer4}" \ "(\[\t \]+${integer8}" \ ")?\[\t \]+${logical4}" \ - "(20:\[\t \]+Type __vtype_mod1_M1t1;" \ + "(35:\[\t \]+Type __vtype_mod1_M1t1;" \ ")?$decimal:\[\t \]+Type m1t1;" \ - "22:\[\t \]+Type s1;(" \ + "\[\t \]+${real4}" \ + "37:\[\t \]+Type s1;(" \ ".*)?"] diff --git a/gdb/testsuite/gdb.fortran/info-types.f90 b/gdb/testsuite/gdb.fortran/info-types.f90 index ec52ef9..d3513ac 100644 --- a/gdb/testsuite/gdb.fortran/info-types.f90 +++ b/gdb/testsuite/gdb.fortran/info-types.f90 @@ -17,6 +17,21 @@ module mod1 type :: m1t1 integer :: b end type m1t1 + + real :: mod1_var_1 = 1.0 + integer, parameter :: mod1_var_2 = 456 + +contains + subroutine sub_m1_a(arg) + integer :: arg + print*, "sub_m1_a" + print*, "arg = ", arg + end subroutine sub_m1_a + + integer function sub_m1_b() + print*, "sub_m1_b" + sub_m1_b = 3 + end function sub_m1_b end module mod1 program info_types_test |