From patchwork Fri Nov 22 16:41:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36118 Received: (qmail 82013 invoked by alias); 22 Nov 2019 16:42:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 81940 invoked by uid 89); 22 Nov 2019 16:42:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=fullname, disconnect, 2009-2019, 20092019 X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Nov 2019 16:42:11 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id E76032041E; Fri, 22 Nov 2019 11:42:08 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 8B30520555; Fri, 22 Nov 2019 11:41:54 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 75B4F28172; Fri, 22 Nov 2019 11:41:54 -0500 (EST) X-Gerrit-PatchSet: 4 Date: Fri, 22 Nov 2019 11:41:52 -0500 From: "Andrew Burgess (Code Review)" To: gdb-patches@sourceware.org Cc: Joel Brobecker Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v4] gdb/mi: Add -symbol-info-modules command X-Gerrit-Change-Id: Ibc618010d1d5f36ae8a8baba4fb9d9d724e62b0f X-Gerrit-Change-Number: 267 X-Gerrit-ChangeURL: X-Gerrit-Commit: 1c0cc72177dd3894270700afea8c4b81216d0f5e In-Reply-To: References: Reply-To: andrew.burgess@embecosm.com, brobecker@adacore.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191122164154.75B4F28172@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/267 ...................................................................... gdb/mi: Add -symbol-info-modules command 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 --- M gdb/ChangeLog M gdb/NEWS M gdb/doc/ChangeLog M gdb/doc/gdb.texinfo M gdb/mi/mi-cmds.c M gdb/mi/mi-cmds.h M gdb/mi/mi-symbol-cmds.c M gdb/testsuite/ChangeLog A gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90 A gdb/testsuite/gdb.mi/mi-fortran-modules.exp A gdb/testsuite/gdb.mi/mi-fortran-modules.f90 11 files changed, 286 insertions(+), 0 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9e5b635..b83d493 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2019-11-22 Andrew Burgess + * 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. + +2019-11-22 Andrew Burgess + * mi/mi-cmds.c (mi_cmds): Add '-symbol-info-functions', '-symbol-info-variables', and '-symbol-info-types'. * mi/mi-cmds.h (mi_cmd_symbol_info_functions): Declare. diff --git a/gdb/NEWS b/gdb/NEWS index 55ab897..ddc74f1 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -357,6 +357,9 @@ 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/ChangeLog b/gdb/doc/ChangeLog index 0c5680a..c25f6d7 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,6 +1,11 @@ 2019-11-22 Andrew Burgess * doc/gdb.texinfo (GDB/MI Symbol Query): Document new MI command + -symbol-info-modules. + +2019-11-22 Andrew Burgess + + * doc/gdb.texinfo (GDB/MI Symbol Query): Document new MI command -symbol-info-functions, -symbol-info-types, and -symbol-info-variables. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9af0563..46001cc 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -33982,6 +33982,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 df9f25f..85c15ec 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -154,6 +154,7 @@ 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 c2fd7d3..30de780 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_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 35eb598..5f7b165 100644 --- a/gdb/mi/mi-symbol-cmds.c +++ b/gdb/mi/mi-symbol-cmds.c @@ -322,6 +322,43 @@ 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/ChangeLog b/gdb/testsuite/ChangeLog index 13d81f3..19511f4 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2019-11-22 Andrew Burgess + * 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. + +2019-11-22 Andrew Burgess + * gdb.mi/mi-sym-info-1.c: New file. * gdb.mi/mi-sym-info-2.c: New file. * gdb.mi/mi-sym-info.exp: New file. 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 0000000..690d54d --- /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 . + +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 0000000..640bb12 --- /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 . + +# 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 0000000..d254627 --- /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 . + +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