This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

iterate_over_symbols should be a wrapper? (was: "Re: GDB 7.4 branching status? (2011-11-23)")


I noticed that the following linespec does not work for Ada anymore:

    (gdb) break FILE:FUNCTION

And that got me into looking how we do symbol matching. When no filename
is provided in the linespec, we call iterate_over_all_matching_symtabs,
which calls iterate_over_symbols over all symtabs, immediately followed
by:

    if (current_language->la_iterate_over_symbols)
      (*current_language->la_iterate_over_symbols) (name, domain,

So, basically, we do a first pass collecting symbols that follow
a certain matching algorithm, and then we do a second pass for
language that might require a different matching algorithm...
It seems to me that there should be only one, language-specific
matching routine, and iterate_over_symbols should call it.

So, my proposal is to change the profile of la_iterate_over_symbols
to match the iterate_over_symbols routine, and then then set
the la_iterate_over_symbols field to iterate_over_symbols for
all languages except Ada. The changes in ada_iterate_over_symbols
should be straightforward, since ada_lookup_symbol_list accepts
a block as well.

That would solve the problem above as well: When the linespec contains
a filename in it, add_matching_symbols_to_info only calls
iterate_over_symbols:

      else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt))
        {
          [...]
          iterate_over_symbols (get_search_block (elt), name,
                                VAR_DOMAIN, collect_symbols,
                                info);
        }

In the meantime, I applied a different type of patch which just
follows the current approach of doing the generic matching first,
followed by the language-specific one next. Attached is the
corresponding patch.

-- 
Joel
>From a86c5755b965bb1e060130319cb1e09ab2e2d92c Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Fri, 25 Nov 2011 15:21:19 -0800
Subject: [PATCH 5/5] Call current_language->la_iterate_over_symbols for FILE:FUNCTION linespecs

Without this, breakpoints using FILE:FUNCTION linespecs fail
for Ada units. For instance, consider for the following trivial program:

    procedure Foo is
    begin
       null;
    end Foo;

Trying to insert a breakpoint on foo.adb:foo fails:

    (gdb) b foo.adb:foo
    Function "foo" not defined in "foo.adb".
    Make breakpoint pending on future shared library load? (y or [n])

This is because the default method of matching symbols does not work
in this case, because the linkage name for procedure "Foo" here is
_ada_foo. We need to apply Ada-specific symbol-name matching.

gdb/ChangeLog:

        * linespec.c (add_matching_symbols_to_info): Add call
        current_language->la_iterate_over_symbols after call to
        iterate_over_symbols.

gdb/testsuite/ChangeLog:

        * gdb.ada/file_fun_bp: New testcase.
---
 gdb/linespec.c                            |    4 +++
 gdb/testsuite/gdb.ada/file_fun_bp.exp     |   32 +++++++++++++++++++++++++++++
 gdb/testsuite/gdb.ada/file_fun_bp/foo.adb |   19 +++++++++++++++++
 3 files changed, 55 insertions(+), 0 deletions(-)
 create mode 100644 gdb/testsuite/gdb.ada/file_fun_bp.exp
 create mode 100644 gdb/testsuite/gdb.ada/file_fun_bp/foo.adb

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 146163a..1e713ee 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2806,6 +2806,10 @@ add_matching_symbols_to_info (const char *name,
 	  iterate_over_symbols (get_search_block (elt), name,
 				VAR_DOMAIN, collect_symbols,
 				info);
+	  if (current_language->la_iterate_over_symbols)
+	    (*current_language->la_iterate_over_symbols) (name, VAR_DOMAIN,
+							  collect_symbols,
+							  info);
 	}
     }
 }
diff --git a/gdb/testsuite/gdb.ada/file_fun_bp.exp b/gdb/testsuite/gdb.ada/file_fun_bp.exp
new file mode 100644
index 0000000..06b757a
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/file_fun_bp.exp
@@ -0,0 +1,32 @@
+# Copyright 2011 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/>.
+
+load_lib "ada.exp"
+
+set testdir "file_fun_bp"
+set testfile "${testdir}/foo"
+set srcfile ${srcdir}/${subdir}/${testfile}.adb
+set binfile ${objdir}/${subdir}/${testfile}
+
+file mkdir ${objdir}/${subdir}/${testdir}
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+  return -1
+}
+
+clean_restart ${testfile}
+
+gdb_test "break foo.adb:foo" \
+         "Breakpoint \[0-9\]+ at 0x\[0-9a-f]+: file .*foo.adb, line \[0-9\]+."
+
diff --git a/gdb/testsuite/gdb.ada/file_fun_bp/foo.adb b/gdb/testsuite/gdb.ada/file_fun_bp/foo.adb
new file mode 100644
index 0000000..6d251fc
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/file_fun_bp/foo.adb
@@ -0,0 +1,19 @@
+--  Copyright 2011 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/>.
+
+procedure Foo is
+begin
+   null;
+end Foo;
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]