Ada: allow unqualified function names in linespecs
authorJoel Brobecker <brobecker@gnat.com>
Thu, 26 Jan 2012 04:20:36 +0000 (04:20 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Thu, 26 Jan 2012 04:20:36 +0000 (04:20 +0000)
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.

14 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/c-lang.c
gdb/d-lang.c
gdb/f-lang.c
gdb/jv-lang.c
gdb/language.c
gdb/language.h
gdb/linespec.c
gdb/m2-lang.c
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/p-lang.c
gdb/symfile.h

index 15a7b6af2b9007705f1866e69ce56619b06aa1e9..ab288c9b0f91d77b56bd5a8e3e0d659270167592 100644 (file)
@@ -1,3 +1,21 @@
+2012-01-26  Joel Brobecker  <brobecker@adacore.com>
+
+       * 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.
+
 2012-01-25  Tom Tromey  <tromey@redhat.com>
 
        * breakpoint.c (bpstat_stop_status): Check 'breakpoint_at' before
index 11ff73f88c9e9ee1ca0448162e9f57c942630758..2f70980b4caef7134c6ba658d765dd9cb078a715 100644 (file)
@@ -12319,6 +12319,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,
@@ -12355,7 +12367,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
 };
index c4d841fa9d489626074615b02299ea8aaaa41538..6e92fb93ba003b198540dc43eb6b58884e69c703 100644 (file)
@@ -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
 };
index da2785c90c34b389fd732c76bbbffacc277334de..29dcfe47489621993e6b9d0919663a251efa6873 100644 (file)
@@ -272,7 +272,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
 };
index 4149cefc094bd8e1846f0b2baa1089882781cb25..5f1540299a0eee439764d8836eb4e34a4bfa8c36 100644 (file)
@@ -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
 };
index 2acf592414278516f64e6163b7d508cc050bfff3..e6fcaee2626c1e18ed9de9e1505d0890a77c58f9 100644 (file)
@@ -1196,7 +1196,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
 };
index d70ae81cac9dcbbc42f8f7c9ebcc442d229cc740..46b7dce8a7c33184dc65f308e681e2ebeb903c47 100644 (file)
@@ -933,7 +933,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
 };
@@ -976,7 +976,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
 };
@@ -1017,7 +1017,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
 };
index 2ea2dcab8a6490c5a4038c0fdde3d2937a492298..7a1bcb799254da6b52dc8bc305d114f5ccf18e9d 100644 (file)
@@ -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.
index 0782c546fda75dc9736fd51eafe81717cc55ed30..28fcf4dd4dd21b150db1b95a31db53120f541d3f 100644 (file)
@@ -321,6 +321,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.  */
 
@@ -328,9 +339,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;
 }
@@ -349,6 +360,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)
   {
@@ -367,7 +385,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)
        {
index e91ea32287d43c0822a494e3c87cef9bc6b78187..d7b16f4bdfcb84e00968598cec1987502cce4185 100644 (file)
@@ -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
 };
index 1c963096fa5dc52f5bcd7714dda806d550a754da..94951fe470be54a3b3e2273c22169122d983be17 100644 (file)
@@ -540,7 +540,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
 };
index 6557a08f20836fcec54e0da0be5472c07e351770..d779591610014cf139202b45eb1ab2470f287e96 100644 (file)
@@ -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
 };
index cd56630efd92f3e19c2c86583d5f6bcb00685af0..b634b9994acc4b018abbce0b6fd8530f4839733b 100644 (file)
@@ -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
 };
index 6b664cd36b2966d26015fb370bd1de89b029d44f..7af6094561a11fc6c14ebf8f304bf65e37878a64 100644 (file)
@@ -258,12 +258,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.