From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17076 invoked by alias); 14 Dec 2011 14:25:01 -0000 Received: (qmail 17055 invoked by uid 22791); 14 Dec 2011 14:24:58 -0000 X-SWARE-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,TW_BJ,WEIRD_QUOTING X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Dec 2011 14:24:43 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0D2762BAAE3; Wed, 14 Dec 2011 09:24:43 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id y0P0Jm2VZWdF; Wed, 14 Dec 2011 09:24:42 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id EE9412BAAE1; Wed, 14 Dec 2011 09:24:42 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 0C793145615; Wed, 14 Dec 2011 06:24:41 -0800 (PST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [RFC] allow unqualified function names in linespecs Date: Wed, 14 Dec 2011 14:36:00 -0000 Message-Id: <1323872680-12843-1-git-send-email-brobecker@adacore.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-12/txt/msg00450.txt.bz2 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