public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [RFA 2/3] Ada: allow unqualified function names in linespecs
Date: Fri, 23 Dec 2011 10:39:00 -0000	[thread overview]
Message-ID: <1324636693-24034-3-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <20111221140128.GK23376@adacore.com>

This is the meat, where we replace the old la_symbol_name_compare
language method with the new ada_get_symbol_name_match_p.
It fixes the problem when trying to insert a breakpoint on "+".

gdb/ChangeLog:

        * language.h (symbol_name_match_p_ftype): New typedef.
        (struct language_defn): Replace field la_symbol_name_compare
        by la_get_symbol_name_match_p.
        * ada-lang.c (ada_get_symbol_name_match_p): New function.
        (ada_language_defn): Use it.
        * linespec.c (struct symbol_matcher_data): New type.
        (iterate_name_matcher): Rewrite.
        (iterate_over_all_matching_symtabs): Pass a pointer to
        a symbol_matcher_data struct to expand_symtabs_matching
        instead of just the lookup name.
        * c-lang.c, d-lang.c, jv-lang.c, m2-lang.c, objc-lang.c,
        opencl-lang.c, p-lang.c, language.c: Delete field
        la_symbol_name_compare, and replace by NULL for new field
        la_get_symbol_name_match_p.
        * symfile.h (struct quick_symbol_functions): Update comment.

OK to commit?
Thanks,
-- 
Joel

---
 gdb/ada-lang.c    |   14 +++++++++++++-
 gdb/c-lang.c      |    8 ++++----
 gdb/d-lang.c      |    2 +-
 gdb/f-lang.c      |    2 +-
 gdb/jv-lang.c     |    2 +-
 gdb/language.c    |    6 +++---
 gdb/language.h    |   29 +++++++++++++++++------------
 gdb/linespec.c    |   24 +++++++++++++++++++++---
 gdb/m2-lang.c     |    2 +-
 gdb/objc-lang.c   |    2 +-
 gdb/opencl-lang.c |    2 +-
 gdb/p-lang.c      |    2 +-
 gdb/symfile.h     |    8 +++-----
 13 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 09ab38d..d871193 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12385,6 +12385,18 @@ static const struct exp_descriptor ada_exp_descriptor = {
   ada_evaluate_subexp
 };
 
+/* Implement the "la_get_symbol_name_match_p" language_defn method
+   for Ada.  */
+
+static symbol_name_match_p_ftype
+ada_get_symbol_name_match_p (const char *lookup_name)
+{
+  if (should_use_wild_match (lookup_name))
+    return wild_match;
+  else
+    return compare_names;
+}
+
 const struct language_defn ada_language_defn = {
   "ada",                        /* Language name */
   language_ada,
@@ -12421,7 +12433,7 @@ const struct language_defn ada_language_defn = {
   ada_print_array_index,
   default_pass_by_reference,
   c_get_string,
-  compare_names,
+  ada_get_symbol_name_match_p,	/* la_get_symbol_name_match_p */
   ada_iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 7be916c..1545d08 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -863,7 +863,7 @@ const struct language_defn c_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   c_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
@@ -986,7 +986,7 @@ const struct language_defn cplus_language_defn =
   default_print_array_index,
   cp_pass_by_reference,
   c_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
@@ -1027,7 +1027,7 @@ const struct language_defn asm_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   c_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
@@ -1073,7 +1073,7 @@ const struct language_defn minimal_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   c_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index fb6bacd..0af328d 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -273,7 +273,7 @@ static const struct language_defn d_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   c_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   NULL,
   LANG_MAGIC
 };
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 00926fb..ab8fcca 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -309,7 +309,7 @@ const struct language_defn f_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index 80fe4a1..2504151 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -1197,7 +1197,7 @@ const struct language_defn java_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/language.c b/gdb/language.c
index 1bbbfba..739c79e 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1200,7 +1200,7 @@ const struct language_defn unknown_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
@@ -1243,7 +1243,7 @@ const struct language_defn auto_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
@@ -1284,7 +1284,7 @@ const struct language_defn local_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/language.h b/gdb/language.h
index 65d55db..da25ed8 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -136,6 +136,16 @@ struct language_arch_info
   struct type *bool_type_default;
 };
 
+/* A pointer to a function expected to return nonzero if
+   SYMBOL_SEARCH_NAME matches the given LOOKUP_NAME.
+
+   SYMBOL_SEARCH_NAME should be a symbol's "search" name.
+   LOOKUP_NAME should be the name of an entity after it has been
+   transformed for lookup.  */
+
+typedef int (*symbol_name_match_p_ftype) (const char *symbol_search_name,
+					  const char *lookup_name);
+
 /* Structure tying together assorted information about a language.  */
 
 struct language_defn
@@ -318,19 +328,14 @@ struct language_defn
     void (*la_get_string) (struct value *value, gdb_byte **buffer, int *length,
 			   struct type **chartype, const char **charset);
 
-    /* Compare two symbol names according to language rules.  For
-       instance, in C++, we might want to ignore whitespaces in
-       the symbol name.  Or some case-insensitive language might
-       want to ignore casing during the match.
-
-       Both STR1 and STR2 are expected to be demangled name, except
-       for Ada, where STR1 and STR2 are expected to be encoded names.
-       The latter is because searches are performed using the encoded
-       name in Ada.
-
-       The return value follows the same spirit as strcmp.  */
+    /* Return a pointer to the function that should be used to match
+       a symbol name against LOOKUP_NAME. This is mostly for languages
+       such as Ada where the matching algorithm depends on LOOKUP_NAME.
 
-    int (*la_symbol_name_compare) (const char *str1, const char *str2);
+       This field may be NULL, in which case strcmp_iw will be used
+       to perform the matching.  */
+    symbol_name_match_p_ftype (*la_get_symbol_name_match_p)
+      (const char *lookup_name);
 
     /* Find all symbols in the current program space matching NAME in
        DOMAIN, according to this language's rules.
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 9d753e5..6f463a4 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -323,6 +323,17 @@ cplusplus_error (const char *name, const char *fmt, ...)
   throw_error (NOT_FOUND_ERROR, "%s", message);
 }
 
+/* Some data for the expand_symtabs_matching callback.  */
+
+struct symbol_matcher_data
+{
+  /* The lookup name against which symbol name should be compared.  */
+  const char *lookup_name;
+
+  /* The routine to be used for comparison.  */
+  symbol_name_match_p_ftype symbol_name_match_p;
+};
+
 /* A helper for iterate_over_all_matching_symtabs that is passed as a
    callback to the expand_symtabs_matching method.  */
 
@@ -330,9 +341,9 @@ static int
 iterate_name_matcher (const struct language_defn *language,
 		      const char *name, void *d)
 {
-  const char **dname = d;
+  const struct symbol_matcher_data *data = d;
 
-  if (language->la_symbol_name_compare (name, *dname) == 0)
+  if (data->symbol_name_match_p (name, data->lookup_name))
     return 1;
   return 0;
 }
@@ -351,6 +362,13 @@ iterate_over_all_matching_symtabs (const char *name,
 {
   struct objfile *objfile;
   struct program_space *pspace;
+  struct symbol_matcher_data matcher_data;
+
+  matcher_data.lookup_name = name;
+  matcher_data.symbol_name_match_p =
+    current_language->la_get_symbol_name_match_p != NULL
+    ? current_language->la_get_symbol_name_match_p (name)
+    : strcmp_iw;
 
   ALL_PSPACES (pspace)
   {
@@ -369,7 +387,7 @@ iterate_over_all_matching_symtabs (const char *name,
 	objfile->sf->qf->expand_symtabs_matching (objfile, NULL,
 						  iterate_name_matcher,
 						  ALL_DOMAIN,
-						  &name);
+						  &matcher_data);
 
       ALL_OBJFILE_SYMTABS (objfile, symtab)
 	{
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index c850b1f..f572f54 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -401,7 +401,7 @@ const struct language_defn m2_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index cb7fa0e..3c8c0cb 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -541,7 +541,7 @@ const struct language_defn objc_language_defn = {
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 1deb9d8..afde3b4 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1024,7 +1024,7 @@ const struct language_defn opencl_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   c_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index f66d471..e633582 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -459,7 +459,7 @@ const struct language_defn pascal_language_defn =
   default_print_array_index,
   default_pass_by_reference,
   default_get_string,
-  strcmp_iw_ordered,
+  NULL,				/* la_get_symbol_name_match_p */
   iterate_over_symbols,
   LANG_MAGIC
 };
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 91605a2..ef1ca24 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -260,12 +260,10 @@ struct quick_symbol_functions
      file is skipped.  If FILE_MATCHER is NULL such file is not skipped.
 
      Otherwise, if KIND does not match this symbol is skipped.
-     
+
      If even KIND matches, then NAME_MATCHER is called for each symbol
-     defined in the file.  The current language, the symbol name and
-     DATA are passed to NAME_MATCHER.  The symbol "search" name should
-     be passed to NAME_MATCHER (see la_symbol_name_compare in struct
-     language_defn for more details on this).
+     defined in the file.  The current language, the symbol "search"
+     name and DATA are passed to NAME_MATCHER.
 
      If NAME_MATCHER returns zero, then this symbol is skipped.
 
-- 
1.7.1

  reply	other threads:[~2011-12-23 10:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-14 14:36 [RFC] " Joel Brobecker
2011-12-20 15:24 ` Tom Tromey
2011-12-21 14:08   ` Joel Brobecker
2011-12-23 10:39     ` Joel Brobecker [this message]
2012-01-12  3:13       ` [RFA 2/3] Ada: " Joel Brobecker
2012-01-19 15:40       ` Joel Brobecker
2012-01-24 19:41       ` Tom Tromey
2012-01-26  4:23         ` Joel Brobecker
2012-01-26 10:22           ` Crash regression gdb.cp/no-dmgl-verbose.exp: " Jan Kratochvil
2012-01-26 10:55             ` Jan Kratochvil
2012-01-27  5:15             ` Jan Kratochvil
2012-01-27  5:25               ` Joel Brobecker
2012-01-27 17:09                 ` [patch] Fix the 2012-01-26 regression by la_get_symbol_name_match_p [Re: Crash regression gdb.cp/no-dmgl-verbose.exp] Jan Kratochvil
2012-01-27 19:27                   ` Joel Brobecker
2012-01-27 20:33                     ` [commit] " Jan Kratochvil
2011-12-23 10:39     ` [commit/Ada 1/3] New function ada-lang.c:should_use_wild_match Joel Brobecker
2011-12-27  4:27       ` Checked in: " Joel Brobecker
2011-12-23 10:39     ` unqualified function names in linespecs in Ada... (try #2) Joel Brobecker
2011-12-23 11:01     ` [RFA 3/3] Remove language param from name_matcher in struct quick_symbol_functions Joel Brobecker
2012-01-12  4:30       ` Joel Brobecker
2012-01-19 15:47       ` Joel Brobecker
2012-01-24 19:45       ` Tom Tromey
2012-01-26  4:57         ` Joel Brobecker
2012-01-24 19:17     ` [RFC] allow unqualified function names in linespecs Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324636693-24034-3-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).