gdb/fortran: Allow for matching symbols with missing scope
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 2 Sep 2019 22:31:10 +0000 (23:31 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 3 Oct 2019 20:25:22 +0000 (21:25 +0100)
This commit allows symbol matching within Fortran code without having
to specify all of the symbol's scope.  For example, given this Fortran
code:

    module aaa
    contains
      subroutine foo
        print *, "hello."
      end subroutine foo
    end module aaa

    subroutine foo
      print *, "hello."
    end subroutine foo

    program test
      call foo
    contains
      subroutine foo
        print *, "hello."
      end subroutine foo

      subroutine bar
        use aaa
        call foo
      end subroutine bar
    end program test

The user can now do this:

    (gdb) b foo
    Breakpoint 1 at 0x4006c2: foo. (3 locations)
    (gdb) info breakpoints
    Num     Type           Disp Enb Address            What
    1       breakpoint     keep y   <MULTIPLE>
    1.1                         y   0x00000000004006c2 in aaa::foo at nest.f90:4
    1.2                         y   0x0000000000400730 in foo at nest.f90:9
    1.3                         y   0x00000000004007c3 in test::foo at nest.f90:16

The user asks for a breakpoint on 'foo' and is given a breakpoint on
all three possible 'foo' locations.  The user is, of course, still
able to specify the scope in order to place a single breakpoint on
just one of the foo functions (or use 'break -qualified foo' to break
on just the global foo).

gdb/ChangeLog:

* f-lang.c (f_language_defn): Use cp_get_symbol_name_matcher and
cp_search_name_hash.
* NEWS: Add entry about nested function support.

gdb/testsuite/ChangeLog:

* gdb.fortran/nested-funcs-2.exp: Run tests with and without the
nested function prefix.

gdb/ChangeLog
gdb/NEWS
gdb/f-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/nested-funcs-2.exp

index afda7532d210fac97c0e40784b49f9c67259744d..446c45501dcd778d8aeaba446cfe1ac01aa352ae 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-03  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * f-lang.c (f_language_defn): Use cp_get_symbol_name_matcher and
+       cp_search_name_hash.
+       * NEWS: Add entry about nested function support.
+
 2019-10-03  Bernhard Heckel  <bernhard.heckel@intel.com>
            Andrew Burgess  <andrew.burgess@embecosm.com>
 
index 3211ec9542c00f53628ada2939ad0775e027df3d..25e67e43c88ab0123a84effba2ae37cef9062a63 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
 * New convenience variable $_ada_exception holds the address of the
   Ada exception being thrown.  This is set by Ada-related catchpoints.
 
+* GDB can now place breakpoints on nested functions and subroutines in
+  Fortran code.  The '::' operator can be used between parent and
+  child scopes when placing breakpoints, for example:
+
+    (gdb) break outer_function::inner_function
+
+  The 'outer_function::' prefix is only needed if 'inner_function' is
+  not visible in the current scope.
+
 * Python API
 
   ** The gdb.Value type has a new method 'format_string' which returns a
index ce7f1471c52d9c6f3338946841d7f4a7e3931d4a..5681379b3b3c0872e071b857300adbdf1c89d070 100644 (file)
@@ -673,9 +673,9 @@ extern const struct language_defn f_language_defn =
   default_pass_by_reference,
   default_get_string,
   c_watch_location_expression,
-  NULL,                                /* la_get_symbol_name_matcher */
+  cp_get_symbol_name_matcher,  /* la_get_symbol_name_matcher */
   iterate_over_symbols,
-  default_search_name_hash,
+  cp_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 6441c1bc09a38f78a7df9d4b2446b2ed8ebf5fb7..fd7614403c23f584fccc8b2ffb9e1e7bdb1ab1ad 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-03  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.fortran/nested-funcs-2.exp: Run tests with and without the
+       nested function prefix.
+
 2019-10-03  Bernhard Heckel  <bernhard.heckel@intel.com>
            Richard Bunt  <richard.bunt@arm.com>
            Andrew Burgess  <andrew.burgess@embecosm.com>
index 4e121cd9da5dfbb3715e0756a7080fc358ff7445..4dc49bc726880e1a37cbc211e786d4713d696de6 100644 (file)
@@ -124,12 +124,6 @@ proc do_bp_tests {with_src_prefix_p with_nest_prefix_p} {
        ".*print \\\*, program_i ! post_hidden"
     gdb_test "p program_i" " = 30" "printing hidden global"
 
-    # Check that the methods in the container module still require the
-    # module name as context.
-    gdb_test_no_output "set confirm off"
-    gdb_test "break print_from_module" \
-        "Function \\\"print_from_module\\\" not defined."
-
     # Check info symbol, whatis and ptype can find information on
     # these nested functions.
     foreach entry \
@@ -150,10 +144,7 @@ proc do_bp_tests {with_src_prefix_p with_nest_prefix_p} {
 }
 
 foreach_with_prefix src_prefix { 0 1 } {
-    # For now this loop is only run with a value of '1'.  A later
-    # patch will extend this with the value '0', at which point this
-    # comment will be removed.
-    foreach_with_prefix nest_prefix { 1 } {
+    foreach_with_prefix nest_prefix { 0 1 } {
        do_bp_tests ${src_prefix} ${nest_prefix}
     }
 }
This page took 0.038996 seconds and 4 git commands to generate.