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]

[RFC] allow unqualified function names in linespecs


This is just a proof of concept patch that shows that, for Ada, we
need two kinds of symbol-matching routines when iterating over all
partial symbols.

The approach we currently implement is the full-match. In other words,
to break on function Foo inside package Pck, you do:

    (gdb) break pck.foo

But there are situation where it's either convenient or necessary to
avoid the fully-qualified name, and use the "simple" name instead.
For instance:

    (gdb) break foo

In that situation, using a full-name match as we do while iterating
over the partial symtab isn't going to work.  As it happens, though,
we usually do not see the problem at the user-level. We get lucky,
enjoying the side-effects of a call cp_canonicalize_string_no_typedefs,
which indirectly causes us to perform an Ada lookup which itself
causes the matching partial psymtabs to be expanded to full symtabs.

Ignoring the fact that calling cp_canonicalize_string_no_typedefs
when the current language is Ada seems wrong (I will propose we fix
that in a followup patch), there is in fact a situation where we do
see a problem. This is when inserting a breakpoint on an Ada operator.
For instance:

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

What this patch does is something that I feel should be hidden
inside ada-lang. Namely, decide which matching routine to use based
on the name we are using to search for matches. I think that the
real question is to trying to find the proper interface for this.

In the end, I don't think that the la_symbol_name_compare method
as I designed it worked for us. It was convenient, because we could
just use strcmp_iw_ordered as the default and ada-lang.c:compare_names
for Ada. But it doesn't do enough.

A few ideas crossed my mind:

  . Have Ada's la_symbol_name_compare check the reference name and
    determine at each call whether to do a wild match, or a full
    match.  But I don't think that this is a reasonable solution
    for performance reasons;

  . Use a compare routine that always performs the "wild" matches,
    even in the case where a full match should have been used.
    I think it's better, but still has an unwanted performance cost.
    Maybe it small enough to be ignored, but maybe not. I am
    particularly worried about the large programs that are so common
    with Ada applications.

  . Redesign a bit the interface.  For instance, let the language
    itself iterate over all partial symbols? The default implementation
    would do what we already do. The Ada implementation would do
    something else, not sure what yet.  And we could get rid of
    the la_symbol_name_compare method.

Thoughts?

No ChangeLog provided as this patch is not meant to be checked in.

---
 gdb/ada-lang.c |    4 +---
 gdb/ada-lang.h |    2 ++
 gdb/linespec.c |   18 +++++++++++++++++-
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 30a561d..aeb2850 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -203,8 +203,6 @@ static int is_name_suffix (const char *);
 
 static int advance_wild_match (const char **, const char *, int);
 
-static int wild_match (const char *, const char *);
-
 static struct value *ada_coerce_ref (struct value *);
 
 static LONGEST pos_atr (struct value *);
@@ -5364,7 +5362,7 @@ advance_wild_match (const char **namep, const char *name0, int target0)
    informational suffixes of NAME (i.e., for which is_name_suffix is
    true).  Assumes that PATN is a lower-cased Ada simple name.  */
 
-static int
+int
 wild_match (const char *name, const char *patn)
 {
   const char *p, *n;
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index fa4bb51..7a91f70 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -367,6 +367,8 @@ extern char *ada_main_name (void);
 
 extern char *ada_name_for_lookup (const char *name);
 
+extern int wild_match (const char *name, const char *patn);
+
 /* Tasking-related: ada-tasks.c */
 
 extern int valid_task_id (int);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 0d9d759..0dde714 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -340,6 +340,15 @@ iterate_name_matcher (const struct language_defn *language,
   return 0;
 }
 
+static int
+iterate_wild_name_matcher (const struct language_defn *language,
+			   const char *name, void *d)
+{
+  const char **dname = d;
+
+  return wild_match (name, *dname) == 0;
+}
+
 /* A helper that walks over all matching symtabs in all objfiles and
    calls CALLBACK for each symbol matching NAME.  If SEARCH_PSPACE is
    not NULL, then the search is restricted to just that program
@@ -354,6 +363,13 @@ iterate_over_all_matching_symtabs (const char *name,
 {
   struct objfile *objfile;
   struct program_space *pspace;
+  int (*name_matcher) (const struct language_defn *, const char *, void *)
+    = iterate_name_matcher;
+
+  if (current_language->la_language == language_ada
+      && strstr (name, "__") == NULL)
+    /* Perform a wild match instead of a full match.  */
+    name_matcher = iterate_wild_name_matcher;
 
   ALL_PSPACES (pspace)
   {
@@ -370,7 +386,7 @@ iterate_over_all_matching_symtabs (const char *name,
 
       if (objfile->sf)
 	objfile->sf->qf->expand_symtabs_matching (objfile, NULL,
-						  iterate_name_matcher,
+						  name_matcher,
 						  ALL_DOMAIN,
 						  &name);
 
-- 
1.7.1


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