[PATCH 0/8] Add Ada support for .debug_names

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/8] Add Ada support for .debug_names

Tom Tromey-4
This series adds support for Ada in the .debug_names index.

This is mostly straightforward.  The series starts with a few cleanup
patches, to make it simpler to share code with psymtabs.

While doing this I found two existing bugs.

One bug is fixed in patch #5, which includes a test case.

The other bug is more serious: gdb does not put the correct contents
into .debug_names.  Fixing this would be very good, but it was not
something I wanted to do immediately.  I've filed a bug with details:

    https://sourceware.org/bugzilla/show_bug.cgi?id=24820

Regression tested on x86-64 Fedora 29.

Tom


Reply | Threaded
Open this post in threaded view
|

[PATCH 1/8] Change map_matching_symbols to take a symbol_found_callback_ftype

Tom Tromey-4
This changes map_matching_symbols to take a
symbol_found_callback_ftype, rather than separate callback and data
parameters.  This enables a future patch to clean up some existing
code so that it can more readily be shared.

gdb/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * ada-lang.c (aux_add_nonlocal_symbols): Change type.
        (add_nonlocal_symbols): Update.
        * dwarf2read.c (dw2_map_matching_symbols): Change type.
        * psymtab.c (map_block, psym_map_matching_symbols): Change type.
        * symfile-debug.c (debug_qf_map_matching_symbols): Change type.
        * symfile.h (struct quick_symbol_functions) <map_matching_symbols>:
        Change type of "callback".  Remove "data".
---
 gdb/ChangeLog       | 10 ++++++++++
 gdb/ada-lang.c      | 34 ++++++++++++++++++----------------
 gdb/dwarf2read.c    | 14 +++++++-------
 gdb/psymtab.c       | 38 +++++++++++++++++++-------------------
 gdb/symfile-debug.c | 21 +++++++++------------
 gdb/symfile.h       | 23 +++++++++++------------
 6 files changed, 74 insertions(+), 66 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7a5cc4272c6..d1784431946 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5332,8 +5332,8 @@ struct match_data
   int found_sym;
 };
 
-/* A callback for add_nonlocal_symbols that adds SYM, found in BLOCK,
-   to a list of symbols.  DATA0 is a pointer to a struct match_data *
+/* A callback for add_nonlocal_symbols that adds symbol, found in BSYM,
+   to a list of symbols.  DATA is a pointer to a struct match_data *
    containing the obstack that collects the symbol list, the file that SYM
    must come from, a flag indicating whether a non-argument symbol has
    been found in the current block, and the last argument symbol
@@ -5341,12 +5341,13 @@ struct match_data
    marking the end of a block, the argument symbol is added if no
    other has been found.  */
 
-static int
-aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym,
-  void *data0)
+static bool
+aux_add_nonlocal_symbols (struct block_symbol *bsym,
+  struct match_data *data)
 {
-  struct match_data *data = (struct match_data *) data0;
-  
+  const struct block *block = bsym->block;
+  struct symbol *sym = bsym->symbol;
+
   if (sym == NULL)
     {
       if (!data->found_sym && data->arg_sym != NULL)
@@ -5359,7 +5360,7 @@ aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym,
   else
     {
       if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
- return 0;
+ return true;
       else if (SYMBOL_IS_ARGUMENT (sym))
  data->arg_sym = sym;
       else
@@ -5370,7 +5371,7 @@ aux_add_nonlocal_symbols (const struct block *block, struct symbol *sym,
    block);
  }
     }
-  return 0;
+  return true;
 }
 
 /* Helper for add_nonlocal_symbols.  Find symbols in DOMAIN which are
@@ -5541,20 +5542,23 @@ add_nonlocal_symbols (struct obstack *obstackp,
 
   bool is_wild_match = lookup_name.ada ().wild_match_p ();
 
+  auto callback = [&] (struct block_symbol *bsym)
+    {
+      return aux_add_nonlocal_symbols (bsym, &data);
+    };
+
   for (objfile *objfile : current_program_space->objfiles ())
     {
       data.objfile = objfile;
 
       if (is_wild_match)
  objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-       domain, global,
-       aux_add_nonlocal_symbols, &data,
+       domain, global, callback,
        symbol_name_match_type::WILD,
        NULL);
       else
  objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-       domain, global,
-       aux_add_nonlocal_symbols, &data,
+       domain, global, callback,
        symbol_name_match_type::FULL,
        compare_names);
 
@@ -5578,9 +5582,7 @@ add_nonlocal_symbols (struct obstack *obstackp,
         {
   data.objfile = objfile;
   objfile->sf->qf->map_matching_symbols (objfile, name1.c_str (),
- domain, global,
- aux_add_nonlocal_symbols,
- &data,
+ domain, global, callback,
  symbol_name_match_type::FULL,
  compare_names);
  }
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 3d90d632891..e86fdaa7bc8 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -4181,13 +4181,13 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
 }
 
 static void
-dw2_map_matching_symbols (struct objfile *objfile,
-  const char * name, domain_enum domain,
-  int global,
-  int (*callback) (const struct block *,
-   struct symbol *, void *),
-  void *data, symbol_name_match_type match,
-  symbol_compare_ftype *ordered_compare)
+dw2_map_matching_symbols
+  (struct objfile *objfile,
+   const char * name, domain_enum domain,
+   int global,
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_name_match_type match,
+   symbol_compare_ftype *ordered_compare)
 {
   /* Currently unimplemented; used for Ada.  The function can be called if the
      current language is Ada for a non-Ada objfile using GNU index.  As Ada
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 6cc7566580a..c667a6273c2 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1164,14 +1164,14 @@ psymtab_to_fullname (struct partial_symtab *ps)
 
 /* For all symbols, s, in BLOCK that are in DOMAIN and match NAME
    according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
-   BLOCK is assumed to come from OBJFILE.  Returns 1 iff CALLBACK
-   ever returns non-zero, and otherwise returns 0.  */
+   BLOCK is assumed to come from OBJFILE.  Returns false iff CALLBACK
+   ever returns false, and otherwise returns true.  */
 
-static int
+static bool
 map_block (const char *name, domain_enum domain, struct objfile *objfile,
    const struct block *block,
-   int (*callback) (const struct block *, struct symbol *, void *),
-   void *data, symbol_name_match_type match)
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_name_match_type match)
 {
   struct block_iterator iter;
   struct symbol *sym;
@@ -1185,26 +1185,26 @@ map_block (const char *name, domain_enum domain, struct objfile *objfile,
       if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
  SYMBOL_DOMAIN (sym), domain))
  {
-  if (callback (block, sym, data))
-    return 1;
+  struct block_symbol block_sym = {sym, block};
+  if (!callback (&block_sym))
+    return false;
  }
     }
 
-  return 0;
+  return true;
 }
 
 /* Psymtab version of map_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
 static void
-psym_map_matching_symbols (struct objfile *objfile,
-   const char *name, domain_enum domain,
-   int global,
-   int (*callback) (const struct block *,
-    struct symbol *, void *),
-   void *data,
-   symbol_name_match_type match,
-   symbol_compare_ftype *ordered_compare)
+psym_map_matching_symbols
+  (struct objfile *objfile,
+   const char *name, domain_enum domain,
+   int global,
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_name_match_type match,
+   symbol_compare_ftype *ordered_compare)
 {
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
@@ -1221,10 +1221,10 @@ psym_map_matching_symbols (struct objfile *objfile,
   if (cust == NULL)
     continue;
   block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-  if (map_block (name, domain, objfile, block,
- callback, data, match))
+  if (!map_block (name, domain, objfile, block, callback, match))
     return;
-  if (callback (block, NULL, data))
+  struct block_symbol block_sym = {nullptr, block};
+  if (!callback (&block_sym))
     return;
  }
     }
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 0f9da66e536..17bc5e8b977 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -228,30 +228,27 @@ debug_qf_expand_symtabs_with_fullname (struct objfile *objfile,
 }
 
 static void
-debug_qf_map_matching_symbols (struct objfile *objfile,
-       const char *name, domain_enum domain,
-       int global,
-       int (*callback) (const struct block *,
- struct symbol *, void *),
-       void *data,
-       symbol_name_match_type match,
-       symbol_compare_ftype *ordered_compare)
+debug_qf_map_matching_symbols
+  (struct objfile *objfile,
+   const char *name, domain_enum domain,
+   int global,
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_name_match_type match,
+   symbol_compare_ftype *ordered_compare)
 {
   const struct debug_sym_fns_data *debug_data
     = symfile_debug_objfile_data_key.get (objfile);
 
   fprintf_filtered (gdb_stdlog,
-    "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n",
+    "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s)\n",
     objfile_debug_name (objfile), name,
     domain_name (domain), global,
-    host_address_to_string (callback),
-    host_address_to_string (data),
     plongest ((LONGEST) match),
     host_address_to_string (ordered_compare));
 
   debug_data->real_sf->qf->map_matching_symbols (objfile, name,
  domain, global,
- callback, data,
+ callback,
  match,
  ordered_compare);
 }
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 741b085e0c4..9121d883ee0 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -211,7 +211,7 @@ struct quick_symbol_functions
      and for which MATCH (symbol name, NAME) == 0, passing each to
      CALLBACK, reading in partial symbol tables as needed.  Look
      through global symbols if GLOBAL and otherwise static symbols.
-     Passes NAME, NAMESPACE, and DATA to CALLBACK with each symbol
+     Passes NAME and NAMESPACE to CALLBACK with each symbol
      found.  After each block is processed, passes NULL to CALLBACK.
      MATCH must be weaker than strcmp_iw_ordered in the sense that
      strcmp_iw_ordered(x,y) == 0 --> MATCH(x,y) == 0.  ORDERED_COMPARE,
@@ -221,17 +221,16 @@ struct quick_symbol_functions
      and
             strcmp_iw_ordered(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0
      (allowing strcmp_iw_ordered(x,y) < 0 while ORDERED_COMPARE(x, y) == 0).
-     CALLBACK returns 0 to indicate that the scan should continue, or
-     non-zero to indicate that the scan should be terminated.  */
-
-  void (*map_matching_symbols) (struct objfile *,
- const char *name, domain_enum domain,
- int global,
- int (*callback) (const struct block *,
- struct symbol *, void *),
- void *data,
- symbol_name_match_type match,
- symbol_compare_ftype *ordered_compare);
+     CALLBACK returns true to indicate that the scan should continue, or
+     false to indicate that the scan should be terminated.  */
+
+  void (*map_matching_symbols)
+    (struct objfile *,
+     const char *name, domain_enum domain,
+     int global,
+     gdb::function_view<symbol_found_callback_ftype> callback,
+     symbol_name_match_type match,
+     symbol_compare_ftype *ordered_compare);
 
   /* Expand all symbol tables in OBJFILE matching some criteria.
 
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 2/8] Change iterate_over_symbols to return bool

Tom Tromey-4
In reply to this post by Tom Tromey-4
This changes iterate_over_symbols to return a bool.  This allows it to
be reused in another context in a subsequent patch.

gdb/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * ada-lang.c (ada_iterate_over_symbols): Return bool.
        * language.h (struct language_defn) <la_iterate_over_symbols>:
        Return bool.
        * symtab.c (iterate_over_symbols): Return bool.
        * symtab.h (iterate_over_symbols): Return bool.
---
 gdb/ChangeLog  |  8 ++++++++
 gdb/ada-lang.c |  6 ++++--
 gdb/language.h |  2 +-
 gdb/symtab.c   | 13 ++++---------
 gdb/symtab.h   | 11 ++++++++++-
 5 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d1784431946..8294101c06e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5741,7 +5741,7 @@ ada_lookup_symbol_list (const char *name, const struct block *block,
 
 /* Implementation of the la_iterate_over_symbols method.  */
 
-static void
+static bool
 ada_iterate_over_symbols
   (const struct block *block, const lookup_name_info &name,
    domain_enum domain,
@@ -5755,8 +5755,10 @@ ada_iterate_over_symbols
   for (i = 0; i < ndefs; ++i)
     {
       if (!callback (&results[i]))
- break;
+ return false;
     }
+
+  return true;
 }
 
 /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
diff --git a/gdb/language.h b/gdb/language.h
index 2a100b04917..0088e5de2dd 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -407,7 +407,7 @@ struct language_defn
        This field may not be NULL.  If the language does not need any
        special processing here, 'iterate_over_symbols' should be
        used as the definition.  */
-    void (*la_iterate_over_symbols)
+    bool (*la_iterate_over_symbols)
       (const struct block *block, const lookup_name_info &name,
        domain_enum domain,
        gdb::function_view<symbol_found_callback_ftype> callback);
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 87a0c8e4da6..ba348f01bbf 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2832,15 +2832,9 @@ basic_lookup_transparent_type (const char *name)
   return (struct type *) 0;
 }
 
-/* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
-
-   For each symbol that matches, CALLBACK is called.  The symbol is
-   passed to the callback.
-
-   If CALLBACK returns false, the iteration ends.  Otherwise, the
-   search continues.  */
+/* See symtab.h.  */
 
-void
+bool
 iterate_over_symbols (const struct block *block,
       const lookup_name_info &name,
       const domain_enum domain,
@@ -2857,9 +2851,10 @@ iterate_over_symbols (const struct block *block,
   struct block_symbol block_sym = {sym, block};
 
   if (!callback (&block_sym))
-    return;
+    return false;
  }
     }
+  return true;
 }
 
 /* Find the compunit symtab associated with PC and SECTION.
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 9880ecc4c53..e62dd2b0ab3 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2101,7 +2101,16 @@ std::vector<CORE_ADDR> find_pcs_for_symtab_line
 
 typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym);
 
-void iterate_over_symbols (const struct block *block,
+/* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
+
+   For each symbol that matches, CALLBACK is called.  The symbol is
+   passed to the callback.
+
+   If CALLBACK returns false, the iteration ends and this function
+   returns false.  Otherwise, the search continues, and the function
+   eventually returns true.  */
+
+bool iterate_over_symbols (const struct block *block,
    const lookup_name_info &name,
    const domain_enum domain,
    gdb::function_view<symbol_found_callback_ftype> callback);
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 3/8] Simplify psym_map_matching_symbols

Tom Tromey-4
In reply to this post by Tom Tromey-4
This introduces a new helper function,
iterate_over_symbols_terminated, and changes psym_map_matching_symbols
to use it.  A subsequent patch will introduce a new user of this
function in the DWARF reader.

gdb/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * psymtab.c (map_block): Remove.
        (psym_map_matching_symbols): Use iterate_over_symbols_terminated.
        * symtab.c (iterate_over_symbols_terminated): New function.
        * symtab.c (iterate_over_symbols_terminated): Declare.
---
 gdb/ChangeLog |  7 +++++++
 gdb/psymtab.c | 40 ++++------------------------------------
 gdb/symtab.c  | 15 +++++++++++++++
 gdb/symtab.h  | 10 ++++++++++
 4 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index c667a6273c2..daaa608d5d1 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1162,38 +1162,6 @@ psymtab_to_fullname (struct partial_symtab *ps)
   return ps->fullname;
 }
 
-/* For all symbols, s, in BLOCK that are in DOMAIN and match NAME
-   according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
-   BLOCK is assumed to come from OBJFILE.  Returns false iff CALLBACK
-   ever returns false, and otherwise returns true.  */
-
-static bool
-map_block (const char *name, domain_enum domain, struct objfile *objfile,
-   const struct block *block,
-   gdb::function_view<symbol_found_callback_ftype> callback,
-   symbol_name_match_type match)
-{
-  struct block_iterator iter;
-  struct symbol *sym;
-
-  lookup_name_info lookup_name (name, match);
-
-  for (sym = block_iter_match_first (block, lookup_name, &iter);
-       sym != NULL;
-       sym = block_iter_match_next (lookup_name, &iter))
-    {
-      if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
- SYMBOL_DOMAIN (sym), domain))
- {
-  struct block_symbol block_sym = {sym, block};
-  if (!callback (&block_sym))
-    return false;
- }
-    }
-
-  return true;
-}
-
 /* Psymtab version of map_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
@@ -1208,6 +1176,8 @@ psym_map_matching_symbols
 {
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
+  lookup_name_info lookup_name (name, match);
+
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     {
       QUIT;
@@ -1221,10 +1191,8 @@ psym_map_matching_symbols
   if (cust == NULL)
     continue;
   block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-  if (!map_block (name, domain, objfile, block, callback, match))
-    return;
-  struct block_symbol block_sym = {nullptr, block};
-  if (!callback (&block_sym))
+  if (!iterate_over_symbols_terminated (block, lookup_name,
+ domain, callback))
     return;
  }
     }
diff --git a/gdb/symtab.c b/gdb/symtab.c
index ba348f01bbf..f6d05c2fd06 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2857,6 +2857,21 @@ iterate_over_symbols (const struct block *block,
   return true;
 }
 
+/* See symtab.h.  */
+
+bool
+iterate_over_symbols_terminated
+  (const struct block *block,
+   const lookup_name_info &name,
+   const domain_enum domain,
+   gdb::function_view<symbol_found_callback_ftype> callback)
+{
+  if (!iterate_over_symbols (block, name, domain, callback))
+    return false;
+  struct block_symbol block_sym = {nullptr, block};
+  return callback (&block_sym);
+}
+
 /* Find the compunit symtab associated with PC and SECTION.
    This will read in debug info as necessary.  */
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index e62dd2b0ab3..50cf84ad929 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2115,6 +2115,16 @@ bool iterate_over_symbols (const struct block *block,
    const domain_enum domain,
    gdb::function_view<symbol_found_callback_ftype> callback);
 
+/* Like iterate_over_symbols, but if all calls to CALLBACK return
+   true, then calls CALLBACK one additional time with a block_symbol
+   that has a valid block but a NULL symbol.  */
+
+bool iterate_over_symbols_terminated
+  (const struct block *block,
+   const lookup_name_info &name,
+   const domain_enum domain,
+   gdb::function_view<symbol_found_callback_ftype> callback);
+
 /* Storage type used by demangle_for_lookup.  demangle_for_lookup
    either returns a const char * pointer that points to either of the
    fields of this type, or a pointer to the input NAME.  This is done
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 4/8] Change map_matching_symbols to take a lookup_name_info

Tom Tromey-4
In reply to this post by Tom Tromey-4
This patch further simplified the map_matching_symbols callback, by
having it take a lookup_name_info rather than a plain string.

gdb/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * ada-lang.c (add_nonlocal_symbols): Combine calls to
        map_matching_symbols.  Update.
        * dwarf2read.c (dw2_map_matching_symbols): Update.
        * psymtab.c (match_partial_symbol): Change type; update.
        (psym_map_matching_symbols): Likewise.
        * symfile-debug.c (debug_qf_map_matching_symbols): Change
        type; update.
        * symfile.h (struct quick_symbol_functions)
        <map_matching_symbols>: Change "name" to be a lookup_name_info.
        Remove "match".
---
 gdb/ChangeLog       | 13 +++++++++++++
 gdb/ada-lang.c      | 20 +++++++-------------
 gdb/dwarf2read.c    |  3 +--
 gdb/psymtab.c       | 27 +++++++--------------------
 gdb/symfile-debug.c |  9 +++------
 gdb/symfile.h       |  4 ++--
 6 files changed, 33 insertions(+), 43 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 8294101c06e..73045c272e7 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5551,16 +5551,10 @@ add_nonlocal_symbols (struct obstack *obstackp,
     {
       data.objfile = objfile;
 
-      if (is_wild_match)
- objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-       domain, global, callback,
-       symbol_name_match_type::WILD,
-       NULL);
-      else
- objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-       domain, global, callback,
-       symbol_name_match_type::FULL,
-       compare_names);
+      objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
+     domain, global, callback,
+     (is_wild_match
+      ? NULL : compare_names));
 
       for (compunit_symtab *cu : objfile->compunits ())
  {
@@ -5576,14 +5570,14 @@ add_nonlocal_symbols (struct obstack *obstackp,
   if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
     {
       const char *name = ada_lookup_name (lookup_name);
-      std::string name1 = std::string ("<_ada_") + name + '>';
+      lookup_name_info name1 (std::string ("<_ada_") + name + '>',
+      symbol_name_match_type::FULL);
 
       for (objfile *objfile : current_program_space->objfiles ())
         {
   data.objfile = objfile;
-  objfile->sf->qf->map_matching_symbols (objfile, name1.c_str (),
+  objfile->sf->qf->map_matching_symbols (objfile, name1,
  domain, global, callback,
- symbol_name_match_type::FULL,
  compare_names);
  }
     }      
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index e86fdaa7bc8..2c55f8d7cd9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -4183,10 +4183,9 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
 static void
 dw2_map_matching_symbols
   (struct objfile *objfile,
-   const char * name, domain_enum domain,
+   const lookup_name_info &name, domain_enum domain,
    int global,
    gdb::function_view<symbol_found_callback_ftype> callback,
-   symbol_name_match_type match,
    symbol_compare_ftype *ordered_compare)
 {
   /* Currently unimplemented; used for Ada.  The function can be called if the
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index daaa608d5d1..f730b9d08e1 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -37,13 +37,6 @@
 #include <algorithm>
 #include <set>
 
-static struct partial_symbol *match_partial_symbol (struct objfile *,
-    struct partial_symtab *,
-    int,
-    const char *, domain_enum,
-    symbol_name_match_type,
-    symbol_compare_ftype *);
-
 static struct partial_symbol *lookup_partial_symbol (struct objfile *,
      struct partial_symtab *,
      const char *, int,
@@ -545,8 +538,7 @@ psymbol_name_matches (partial_symbol *psym,
 static struct partial_symbol *
 match_partial_symbol (struct objfile *objfile,
       struct partial_symtab *pst, int global,
-      const char *name, domain_enum domain,
-      symbol_name_match_type match_type,
+      const lookup_name_info &name, domain_enum domain,
       symbol_compare_ftype *ordered_compare)
 {
   struct partial_symbol **start, **psym;
@@ -557,8 +549,6 @@ match_partial_symbol (struct objfile *objfile,
   if (length == 0)
     return NULL;
 
-  lookup_name_info lookup_name (name, match_type);
-
   start = (global ?
    &objfile->partial_symtabs->global_psymbols[pst->globals_offset] :
    &objfile->partial_symtabs->static_psymbols[pst->statics_offset]);
@@ -583,7 +573,7 @@ match_partial_symbol (struct objfile *objfile,
 
   enum language lang = (*center)->ginfo.language;
   const char *lang_ln
-    = lookup_name.language_lookup_name (lang).c_str ();
+    = name.language_lookup_name (lang).c_str ();
 
   if (ordered_compare (symbol_search_name (&(*center)->ginfo),
        lang_ln) >= 0)
@@ -594,7 +584,7 @@ match_partial_symbol (struct objfile *objfile,
       gdb_assert (top == bottom);
 
       while (top <= real_top
-     && psymbol_name_matches (*top, lookup_name))
+     && psymbol_name_matches (*top, name))
  {
   if (symbol_matches_domain ((*top)->ginfo.language,
      (*top)->domain, domain))
@@ -612,7 +602,7 @@ match_partial_symbol (struct objfile *objfile,
  {
   if (symbol_matches_domain ((*psym)->ginfo.language,
      (*psym)->domain, domain)
-      && psymbol_name_matches (*psym, lookup_name))
+      && psymbol_name_matches (*psym, name))
     return *psym;
  }
     }
@@ -1168,21 +1158,18 @@ psymtab_to_fullname (struct partial_symtab *ps)
 static void
 psym_map_matching_symbols
   (struct objfile *objfile,
-   const char *name, domain_enum domain,
+   const lookup_name_info &name, domain_enum domain,
    int global,
    gdb::function_view<symbol_found_callback_ftype> callback,
-   symbol_name_match_type match,
    symbol_compare_ftype *ordered_compare)
 {
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
-  lookup_name_info lookup_name (name, match);
-
   for (partial_symtab *ps : require_partial_symbols (objfile, 1))
     {
       QUIT;
       if (ps->readin
-  || match_partial_symbol (objfile, ps, global, name, domain, match,
+  || match_partial_symbol (objfile, ps, global, name, domain,
    ordered_compare))
  {
   struct compunit_symtab *cust = psymtab_to_symtab (objfile, ps);
@@ -1191,7 +1178,7 @@ psym_map_matching_symbols
   if (cust == NULL)
     continue;
   block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-  if (!iterate_over_symbols_terminated (block, lookup_name,
+  if (!iterate_over_symbols_terminated (block, name,
  domain, callback))
     return;
  }
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 17bc5e8b977..b059be3552a 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -230,26 +230,23 @@ debug_qf_expand_symtabs_with_fullname (struct objfile *objfile,
 static void
 debug_qf_map_matching_symbols
   (struct objfile *objfile,
-   const char *name, domain_enum domain,
+   const lookup_name_info &name, domain_enum domain,
    int global,
    gdb::function_view<symbol_found_callback_ftype> callback,
-   symbol_name_match_type match,
    symbol_compare_ftype *ordered_compare)
 {
   const struct debug_sym_fns_data *debug_data
     = symfile_debug_objfile_data_key.get (objfile);
 
   fprintf_filtered (gdb_stdlog,
-    "qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s)\n",
-    objfile_debug_name (objfile), name,
+    "qf->map_matching_symbols (%s, %s, %d, %s)\n",
+    objfile_debug_name (objfile),
     domain_name (domain), global,
-    plongest ((LONGEST) match),
     host_address_to_string (ordered_compare));
 
   debug_data->real_sf->qf->map_matching_symbols (objfile, name,
  domain, global,
  callback,
- match,
  ordered_compare);
 }
 
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 9121d883ee0..98fb377806b 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -226,10 +226,10 @@ struct quick_symbol_functions
 
   void (*map_matching_symbols)
     (struct objfile *,
-     const char *name, domain_enum domain,
+     const lookup_name_info &lookup_name,
+     domain_enum domain,
      int global,
      gdb::function_view<symbol_found_callback_ftype> callback,
-     symbol_name_match_type match,
      symbol_compare_ftype *ordered_compare);
 
   /* Expand all symbol tables in OBJFILE matching some criteria.
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 5/8] Fix latent bug in .debug_names file-name handling

Tom Tromey-4
In reply to this post by Tom Tromey-4
An internal Ada test case showed that the .debug_names code does not
compute the same list of file names as the partial symbol reader.  In
particular, the partial symbol reader uses the DW_AT_name of the CU:

  /* Allocate a new partial symbol table structure.  */
  filename = dwarf2_string_attr (comp_unit_die, DW_AT_name, cu);
  if (filename == NULL)
    filename = "";

  pst = create_partial_symtab (per_cu, filename);

This patch changes the .debug_names reader to follow.

gdb/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * dwarf2read.c (dw2_get_file_names_reader): Add the
        CU's file name to the results.

gdb/testsuite/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * gdb.ada/dgopt.exp: New file.
        * gdb.ada/dgopt/x.adb: New file.
---
 gdb/ChangeLog                     |  5 +++++
 gdb/dwarf2read.c                  | 12 ++++++++---
 gdb/testsuite/ChangeLog           |  5 +++++
 gdb/testsuite/gdb.ada/dgopt.exp   | 34 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.ada/dgopt/x.adb | 19 +++++++++++++++++
 5 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 gdb/testsuite/gdb.ada/dgopt.exp
 create mode 100644 gdb/testsuite/gdb.ada/dgopt/x.adb

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2c55f8d7cd9..4332f73991a 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3685,11 +3685,17 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
 
   file_and_directory fnd = find_file_and_directory (comp_unit_die, cu);
 
-  qfn->num_file_names = lh->file_names.size ();
+  int offset = 0;
+  if (strcmp (fnd.name, "<unknown>") != 0)
+    ++offset;
+
+  qfn->num_file_names = offset + lh->file_names.size ();
   qfn->file_names =
-    XOBNEWVEC (&objfile->objfile_obstack, const char *, lh->file_names.size ());
+    XOBNEWVEC (&objfile->objfile_obstack, const char *, qfn->num_file_names);
+  if (offset != 0)
+    qfn->file_names[0] = xstrdup (fnd.name);
   for (i = 0; i < lh->file_names.size (); ++i)
-    qfn->file_names[i] = file_full_name (i + 1, lh.get (), fnd.comp_dir);
+    qfn->file_names[i + offset] = file_full_name (i + 1, lh.get (), fnd.comp_dir);
   qfn->real_names = NULL;
 
   lh_cu->v.quick->file_names = qfn;
diff --git a/gdb/testsuite/gdb.ada/dgopt.exp b/gdb/testsuite/gdb.ada/dgopt.exp
new file mode 100644
index 00000000000..db69121b400
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/dgopt.exp
@@ -0,0 +1,34 @@
+# Copyright 2019 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/>.
+
+# Test case using the -gnatDG option.
+
+load_lib "ada.exp"
+
+standard_ada_testfile x
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \
+ {debug additional_flags=-gnatDG}] != "" } {
+  return -1
+}
+
+clean_restart ${testfile}
+
+# The bug occurs with .debug_names, but here we don't check whether
+# the appropriate target board is in use.  The problem was that the
+# .adb file did not end up in the file table, but did show up in the
+# DWARF, which the psymtab reader handled, but which the .debug_names
+# reader did not.
+gdb_test "list x.adb:16, 16" "16.*procedure X is"
diff --git a/gdb/testsuite/gdb.ada/dgopt/x.adb b/gdb/testsuite/gdb.ada/dgopt/x.adb
new file mode 100644
index 00000000000..039e99d3933
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/dgopt/x.adb
@@ -0,0 +1,19 @@
+--  Copyright 2019 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 X is
+begin
+   null;
+end X;
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 6/8] Add Ada support for .debug_names

Tom Tromey-4
In reply to this post by Tom Tromey-4
This patch adds support for Ada to .debug_names.  I opted to leave
.gdb_index alone, because in my view it is a defunct format.

gdb/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * dwarf-index-write.c (write_psymbols): Extend error message.
        (debug_names::insert): Add Ada code.
        (debug_names::write_psymbols): Remove Ada check.
        (debug_names) <m_string_obstack>: New member.
        * dwarf2read.c (gdb_index_symbol_name_matcher): Remove.
        (gdb_index_symbol_name_matcher::matches): Remove.
        (mapped_index_base::find_name_components_bounds): Add "lang"
        parameter.
        (mapped_index_base::build_name_components): Also split names
        according to Ada syntax.
        (dw2_expand_symtabs_matching_symbol): Loop over languages.  Change
        type of "match_callback".
        (check_match, check_find_bounds_finds)
        (dw2_expand_symtabs_matching): Update.
        (dw2_debug_names_iterator): Add new constructor.
        (dw2_debug_names_map_matching_symbols): New function.
        (dw2_debug_names_expand_symtabs_matching): Update.
        (dwarf2_debug_names_functions): Use
        dw2_debug_names_map_matching_symbols.
---
 gdb/ChangeLog           |  22 ++++
 gdb/dwarf-index-write.c |  48 ++++++-
 gdb/dwarf2read.c        | 285 ++++++++++++++++++++++------------------
 3 files changed, 225 insertions(+), 130 deletions(-)

diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 7d59a1ba160..153c6792f0c 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -34,6 +34,7 @@
 #include "gdbcmd.h"
 #include "objfiles.h"
 #include "psympriv.h"
+#include "ada-lang.h"
 
 #include <algorithm>
 #include <cmath>
@@ -541,7 +542,8 @@ write_psymbols (struct mapped_symtab *symtab,
       struct partial_symbol *psym = *psymp;
 
       if (psym->ginfo.language == language_ada)
- error (_("Ada is not currently supported by the index"));
+ error (_("Ada is not currently supported by the index; "
+ "use the DWARF 5 index instead"));
 
       /* Only add a given psymbol once.  */
       if (psyms_seen.insert (psym).second)
@@ -684,7 +686,43 @@ public:
     const int dwarf_tag = psymbol_tag (psym);
     if (dwarf_tag == 0)
       return;
-    const char *const name = symbol_search_name (&psym->ginfo);
+    const char *name = symbol_search_name (&psym->ginfo);
+
+    if (psym->ginfo.language == language_ada)
+      {
+ /* We want to ensure that the Ada main function's name appears
+   verbatim in the index.  However, this name will be of the
+   form "_ada_mumble", and will be rewritten by ada_decode.
+   So, recognize it specially here and add it to the index by
+   hand.  */
+ if (strcmp (main_name (), name) == 0)
+  {
+    const auto insertpair
+      = m_name_to_value_set.emplace (c_str_view (name),
+     std::set<symbol_value> ());
+    std::set<symbol_value> &value_set = insertpair.first->second;
+    value_set.emplace (symbol_value (dwarf_tag, cu_index, is_static,
+     kind));
+  }
+
+ /* In order for the index to work when read back into gdb, it
+   has to supply a funny form of the name: it should be the
+   encoded name, with any suffixes stripped.  Using the
+   ordinary encoded name will not work properly with the
+   searching logic in find_name_components_bounds; nor will
+   using the decoded name.  Furthermore, an Ada "verbatim"
+   name (of the form "<MumBle>") must be entered without the
+   angle brackets.  Note that the current index is unusual,
+   see PR symtab/24820 for details.  */
+ const char *decoded = ada_decode (name);
+ if (decoded[0] == '<')
+  name = (char *) obstack_copy0 (&m_string_obstack,
+ decoded + 1,
+ strlen (decoded + 1) - 1);
+ else
+  name = obstack_strdup (&m_string_obstack, ada_encode (decoded));
+      }
+
     const auto insertpair
       = m_name_to_value_set.emplace (c_str_view (name),
      std::set<symbol_value> ());
@@ -1181,9 +1219,6 @@ private:
       {
  struct partial_symbol *psym = *psymp;
 
- if (psym->ginfo.language == language_ada)
-  error (_("Ada is not currently supported by the index"));
-
  /* Only add a given psymbol once.  */
  if (psyms_seen.insert (psym).second)
   insert (psym, cu_index, is_static, kind);
@@ -1244,6 +1279,9 @@ private:
 
   /* .debug_names entry pool.  */
   data_buf m_entry_pool;
+
+  /* Temporary storage for Ada names.  */
+  auto_obstack m_string_obstack;
 };
 
 /* Return iff any of the needed offsets does not fit into 32-bit
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4332f73991a..6b7306082ec 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -179,7 +179,8 @@ struct mapped_index_base
      vector.  */
   std::pair<std::vector<name_component>::const_iterator,
     std::vector<name_component>::const_iterator>
-    find_name_components_bounds (const lookup_name_info &ln_no_params) const;
+    find_name_components_bounds (const lookup_name_info &ln_no_params,
+ enum language lang) const;
 
   /* Prevent deleting/destroying via a base class pointer.  */
 protected:
@@ -4199,93 +4200,6 @@ dw2_map_matching_symbols
      does not look for non-Ada symbols this function should just return.  */
 }
 
-/* Symbol name matcher for .gdb_index names.
-
-   Symbol names in .gdb_index have a few particularities:
-
-   - There's no indication of which is the language of each symbol.
-
-     Since each language has its own symbol name matching algorithm,
-     and we don't know which language is the right one, we must match
-     each symbol against all languages.  This would be a potential
-     performance problem if it were not mitigated by the
-     mapped_index::name_components lookup table, which significantly
-     reduces the number of times we need to call into this matcher,
-     making it a non-issue.
-
-   - Symbol names in the index have no overload (parameter)
-     information.  I.e., in C++, "foo(int)" and "foo(long)" both
-     appear as "foo" in the index, for example.
-
-     This means that the lookup names passed to the symbol name
-     matcher functions must have no parameter information either
-     because (e.g.) symbol search name "foo" does not match
-     lookup-name "foo(int)" [while swapping search name for lookup
-     name would match].
-*/
-class gdb_index_symbol_name_matcher
-{
-public:
-  /* Prepares the vector of comparison functions for LOOKUP_NAME.  */
-  gdb_index_symbol_name_matcher (const lookup_name_info &lookup_name);
-
-  /* Walk all the matcher routines and match SYMBOL_NAME against them.
-     Returns true if any matcher matches.  */
-  bool matches (const char *symbol_name);
-
-private:
-  /* A reference to the lookup name we're matching against.  */
-  const lookup_name_info &m_lookup_name;
-
-  /* A vector holding all the different symbol name matchers, for all
-     languages.  */
-  std::vector<symbol_name_matcher_ftype *> m_symbol_name_matcher_funcs;
-};
-
-gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
-  (const lookup_name_info &lookup_name)
-    : m_lookup_name (lookup_name)
-{
-  /* Prepare the vector of comparison functions upfront, to avoid
-     doing the same work for each symbol.  Care is taken to avoid
-     matching with the same matcher more than once if/when multiple
-     languages use the same matcher function.  */
-  auto &matchers = m_symbol_name_matcher_funcs;
-  matchers.reserve (nr_languages);
-
-  matchers.push_back (default_symbol_name_matcher);
-
-  for (int i = 0; i < nr_languages; i++)
-    {
-      const language_defn *lang = language_def ((enum language) i);
-      symbol_name_matcher_ftype *name_matcher
- = get_symbol_name_matcher (lang, m_lookup_name);
-
-      /* Don't insert the same comparison routine more than once.
- Note that we do this linear walk instead of a seemingly
- cheaper sorted insert, or use a std::set or something like
- that, because relative order of function addresses is not
- stable.  This is not a problem in practice because the number
- of supported languages is low, and the cost here is tiny
- compared to the number of searches we'll do afterwards using
- this object.  */
-      if (name_matcher != default_symbol_name_matcher
-  && (std::find (matchers.begin (), matchers.end (), name_matcher)
-      == matchers.end ()))
- matchers.push_back (name_matcher);
-    }
-}
-
-bool
-gdb_index_symbol_name_matcher::matches (const char *symbol_name)
-{
-  for (auto matches_name : m_symbol_name_matcher_funcs)
-    if (matches_name (symbol_name, m_lookup_name, NULL))
-      return true;
-
-  return false;
-}
-
 /* Starting from a search name, return the string that finds the upper
    bound of all strings that start with SEARCH_NAME in a sorted name
    list.  Returns the empty string to indicate that the upper bound is
@@ -4364,13 +4278,13 @@ make_sort_after_prefix_name (const char *search_name)
 std::pair<std::vector<name_component>::const_iterator,
   std::vector<name_component>::const_iterator>
 mapped_index_base::find_name_components_bounds
-  (const lookup_name_info &lookup_name_without_params) const
+  (const lookup_name_info &lookup_name_without_params, language lang) const
 {
   auto *name_cmp
     = this->name_components_casing == case_sensitive_on ? strcmp : strcasecmp;
 
-  const char *cplus
-    = lookup_name_without_params.cplus ().lookup_name ().c_str ();
+  const char *lang_name
+    = lookup_name_without_params.language_lookup_name (lang).c_str ();
 
   /* Comparison function object for lower_bound that matches against a
      given symbol name.  */
@@ -4398,10 +4312,10 @@ mapped_index_base::find_name_components_bounds
   /* Find the lower bound.  */
   auto lower = [&] ()
     {
-      if (lookup_name_without_params.completion_mode () && cplus[0] == '\0')
+      if (lookup_name_without_params.completion_mode () && lang_name[0] == '\0')
  return begin;
       else
- return std::lower_bound (begin, end, cplus, lookup_compare_lower);
+ return std::lower_bound (begin, end, lang_name, lookup_compare_lower);
     } ();
 
   /* Find the upper bound.  */
@@ -4420,14 +4334,14 @@ mapped_index_base::find_name_components_bounds
      We find the upper bound by looking for the insertion
      point of "func"-with-last-character-incremented,
      i.e. "fund".  */
-  std::string after = make_sort_after_prefix_name (cplus);
+  std::string after = make_sort_after_prefix_name (lang_name);
   if (after.empty ())
     return end;
   return std::lower_bound (lower, end, after.c_str (),
    lookup_compare_lower);
  }
       else
- return std::upper_bound (lower, end, cplus, lookup_compare_upper);
+ return std::upper_bound (lower, end, lang_name, lookup_compare_upper);
     } ();
 
   return {lower, upper};
@@ -4447,11 +4361,7 @@ mapped_index_base::build_name_components ()
 
   /* The code below only knows how to break apart components of C++
      symbol names (and other languages that use '::' as
-     namespace/module separator).  If we add support for wild matching
-     to some language that uses some other operator (E.g., Ada, Go and
-     D use '.'), then we'll need to try splitting the symbol name
-     according to that language too.  Note that Ada does support wild
-     matching, but doesn't currently support .gdb_index.  */
+     namespace/module separator) and Ada symbol names.  */
   auto count = this->symbol_name_count ();
   for (offset_type idx = 0; idx < count; idx++)
     {
@@ -4462,16 +4372,33 @@ mapped_index_base::build_name_components ()
 
       /* Add each name component to the name component table.  */
       unsigned int previous_len = 0;
-      for (unsigned int current_len = cp_find_first_component (name);
-   name[current_len] != '\0';
-   current_len += cp_find_first_component (name + current_len))
+
+      if (strstr (name, "::") != nullptr)
+ {
+  for (unsigned int current_len = cp_find_first_component (name);
+       name[current_len] != '\0';
+       current_len += cp_find_first_component (name + current_len))
+    {
+      gdb_assert (name[current_len] == ':');
+      this->name_components.push_back ({previous_len, idx});
+      /* Skip the '::'.  */
+      current_len += 2;
+      previous_len = current_len;
+    }
+ }
+      else
  {
-  gdb_assert (name[current_len] == ':');
-  this->name_components.push_back ({previous_len, idx});
-  /* Skip the '::'.  */
-  current_len += 2;
-  previous_len = current_len;
+  /* Handle the Ada encoded (aka mangled) form here.  */
+  for (const char *iter = strstr (name, "__");
+       iter != nullptr;
+       iter = strstr (iter, "__"))
+    {
+      this->name_components.push_back ({previous_len, idx});
+      iter += 2;
+      previous_len = iter - name;
+    }
  }
+
       this->name_components.push_back ({previous_len, idx});
     }
 
@@ -4506,22 +4433,15 @@ dw2_expand_symtabs_matching_symbol
    const lookup_name_info &lookup_name_in,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
    enum search_domain kind,
-   gdb::function_view<void (offset_type)> match_callback)
+   gdb::function_view<bool (offset_type)> match_callback)
 {
   lookup_name_info lookup_name_without_params
     = lookup_name_in.make_ignore_params ();
-  gdb_index_symbol_name_matcher lookup_name_matcher
-    (lookup_name_without_params);
 
   /* Build the symbol name component sorted vector, if we haven't
      yet.  */
   index.build_name_components ();
 
-  auto bounds = index.find_name_components_bounds (lookup_name_without_params);
-
-  /* Now for each symbol name in range, check to see if we have a name
-     match, and if so, call the MATCH_CALLBACK callback.  */
-
   /* The same symbol may appear more than once in the range though.
      E.g., if we're looking for symbols that complete "w", and we have
      a symbol named "w1::w2", we'll find the two name components for
@@ -4530,17 +4450,61 @@ dw2_expand_symtabs_matching_symbol
      indexes that matched in a temporary vector and ignore
      duplicates.  */
   std::vector<offset_type> matches;
-  matches.reserve (std::distance (bounds.first, bounds.second));
 
-  for (; bounds.first != bounds.second; ++bounds.first)
+  struct name_and_matcher
+  {
+    symbol_name_matcher_ftype *matcher;
+    const std::string &name;
+
+    bool operator== (const name_and_matcher &other) const
+    {
+      return matcher == other.matcher && name == other.name;
+    }
+  };
+
+  /* A vector holding all the different symbol name matchers, for all
+     languages.  */
+  std::vector<name_and_matcher> matchers;
+
+  for (int i = 0; i < nr_languages; i++)
     {
-      const char *qualified = index.symbol_name_at (bounds.first->idx);
+      enum language lang_e = (enum language) i;
+
+      const language_defn *lang = language_def (lang_e);
+      symbol_name_matcher_ftype *name_matcher
+ = get_symbol_name_matcher (lang, lookup_name_without_params);
+
+      name_and_matcher key {
+         name_matcher,
+ lookup_name_without_params.language_lookup_name (lang_e)
+      };
 
-      if (!lookup_name_matcher.matches (qualified)
-  || (symbol_matcher != NULL && !symbol_matcher (qualified)))
+      /* Don't insert the same comparison routine more than once.
+ Note that we do this linear walk.  This is not a problem in
+ practice because the number of supported languages is
+ low.  */
+      if (std::find (matchers.begin (), matchers.end (), key)
+  != matchers.end ())
  continue;
+      matchers.push_back (std::move (key));
+
+      auto bounds
+ = index.find_name_components_bounds (lookup_name_without_params,
+     lang_e);
+
+      /* Now for each symbol name in range, check to see if we have a name
+ match, and if so, call the MATCH_CALLBACK callback.  */
+
+      for (; bounds.first != bounds.second; ++bounds.first)
+ {
+  const char *qualified = index.symbol_name_at (bounds.first->idx);
+
+  if (!name_matcher (qualified, lookup_name_without_params, NULL)
+      || (symbol_matcher != NULL && !symbol_matcher (qualified)))
+    continue;
 
-      matches.push_back (bounds.first->idx);
+  matches.push_back (bounds.first->idx);
+ }
     }
 
   std::sort (matches.begin (), matches.end ());
@@ -4551,7 +4515,8 @@ dw2_expand_symtabs_matching_symbol
     {
       if (prev != idx)
  {
-  match_callback (idx);
+  if (!match_callback (idx))
+    break;
   prev = idx;
  }
     }
@@ -4646,6 +4611,7 @@ check_match (const char *file, int line,
 
     if (expected_str == NULL || strcmp (expected_str, matched_name) != 0)
       mismatch (expected_str, matched_name);
+    return true;
   });
 
   const char *expected_str
@@ -4712,7 +4678,8 @@ check_find_bounds_finds (mapped_index_base &index,
   lookup_name_info lookup_name (search_name,
  symbol_name_match_type::FULL, true);
 
-  auto bounds = index.find_name_components_bounds (lookup_name);
+  auto bounds = index.find_name_components_bounds (lookup_name,
+   language_cplus);
 
   size_t distance = std::distance (bounds.first, bounds.second);
   if (distance != expected_syms.size ())
@@ -5197,6 +5164,7 @@ dw2_expand_symtabs_matching
     {
       dw2_expand_marked_cus (dwarf2_per_objfile, idx, file_matcher,
      expansion_notify, kind);
+      return true;
     });
 }
 
@@ -5684,6 +5652,15 @@ public:
       m_addr (find_vec_in_debug_names (map, namei))
   {}
 
+  dw2_debug_names_iterator (const mapped_debug_names &map,
+    bool want_specific_block,
+    block_enum block_index, domain_enum domain,
+    uint32_t namei)
+    : m_map (map), m_want_specific_block (want_specific_block),
+      m_block_index (block_index), m_domain (domain),
+      m_addr (find_vec_in_debug_names (map, namei))
+  {}
+
   /* Return the next matching CU or NULL if there are no more.  */
   dwarf2_per_cu_data *next ();
 
@@ -6106,6 +6083,63 @@ dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile,
     }
 }
 
+static void
+dw2_debug_names_map_matching_symbols
+  (struct objfile *objfile,
+   const lookup_name_info &name, domain_enum domain,
+   int global,
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_compare_ftype *ordered_compare)
+{
+  struct dwarf2_per_objfile *dwarf2_per_objfile
+    = get_dwarf2_per_objfile (objfile);
+
+  /* debug_names_table is NULL if OBJF_READNOW.  */
+  if (!dwarf2_per_objfile->debug_names_table)
+    return;
+
+  mapped_debug_names &map = *dwarf2_per_objfile->debug_names_table;
+  const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+
+  const char *match_name = name.ada ().lookup_name ().c_str ();
+  auto matcher = [&] (const char *symname)
+    {
+      if (ordered_compare == nullptr)
+ return true;
+      return ordered_compare (symname, match_name) == 0;
+    };
+
+  dw2_expand_symtabs_matching_symbol (map, name, matcher, ALL_DOMAIN,
+      [&] (offset_type namei)
+    {
+      /* The name was matched, now expand corresponding CUs that were
+ marked.  */
+      dw2_debug_names_iterator iter (map, true, block_kind, domain, namei);
+
+      struct dwarf2_per_cu_data *per_cu;
+      while ((per_cu = iter.next ()) != NULL)
+ dw2_expand_symtabs_matching_one (per_cu, nullptr, nullptr);
+      return true;
+    });
+
+  /* It's a shame we couldn't do this inside the
+     dw2_expand_symtabs_matching_symbol callback, but that skips CUs
+     that have already been expanded.  Instead, this loop matches what
+     the psymtab code does.  */
+  for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
+    {
+      struct compunit_symtab *cust = per_cu->v.quick->compunit_symtab;
+      if (cust != nullptr)
+ {
+  const struct block *block
+    = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
+  if (!iterate_over_symbols_terminated (block, name,
+ domain, callback))
+    break;
+ }
+    }
+}
+
 static void
 dw2_debug_names_expand_symtabs_matching
   (struct objfile *objfile,
@@ -6138,6 +6172,7 @@ dw2_debug_names_expand_symtabs_matching
       while ((per_cu = iter.next ()) != NULL)
  dw2_expand_symtabs_matching_one (per_cu, file_matcher,
  expansion_notify);
+      return true;
     });
 }
 
@@ -6153,7 +6188,7 @@ const struct quick_symbol_functions dwarf2_debug_names_functions =
   dw2_debug_names_expand_symtabs_for_function,
   dw2_expand_all_symtabs,
   dw2_expand_symtabs_with_fullname,
-  dw2_map_matching_symbols,
+  dw2_debug_names_map_matching_symbols,
   dw2_debug_names_expand_symtabs_matching,
   dw2_find_pc_sect_compunit_symtab,
   NULL,
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 7/8] Add Ada support to cc-with-tweaks.exp

Tom Tromey-4
In reply to this post by Tom Tromey-4
This adds Ada support to the cc-with-tweaks.exp board file, so that we
can test Ada this way.  The cc-with-tweaks.sh script already works
reasonably well as a wrapper for gnatmake.

gdb/testsuite/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * boards/cc-with-tweaks.exp: Set GNATMAKE_FOR_TARGET.
---
 gdb/testsuite/ChangeLog                 | 4 ++++
 gdb/testsuite/boards/cc-with-tweaks.exp | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/gdb/testsuite/boards/cc-with-tweaks.exp b/gdb/testsuite/boards/cc-with-tweaks.exp
index c50a0065c28..371481477ae 100644
--- a/gdb/testsuite/boards/cc-with-tweaks.exp
+++ b/gdb/testsuite/boards/cc-with-tweaks.exp
@@ -42,6 +42,7 @@ load_generic_config "unix"
 process_multilib_options ""
 set found_gcc [find_gcc]
 set found_gxx [find_g++]
+set found_gnatmake [find_gnatmake]
 set_board_info compiler "$found_gcc"
 
 set contrib_dir [file normalize $srcdir/../contrib]
@@ -53,6 +54,10 @@ if ![info exists CXX_FOR_TARGET] {
     set CXX_FOR_TARGET "$found_gxx"
 }
 set CXX_FOR_TARGET "$contrib_dir/cc-with-tweaks.sh $CC_WITH_TWEAKS_FLAGS $CXX_FOR_TARGET"
+if ![info exists GNATMAKE_FOR_TARGET] {
+    set GNATMAKE_FOR_TARGET "$found_gnatmake"
+}
+set GNATMAKE_FOR_TARGET "$contrib_dir/cc-with-tweaks.sh $CC_WITH_TWEAKS_FLAGS $GNATMAKE_FOR_TARGET"
 
 set pwd [exec pwd -P]
 exec echo $GDB $INTERNAL_GDBFLAGS $GDBFLAGS \"\$@\" > $pwd/gdb.sh
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 8/8] Update "save gdb-index" documentation

Tom Tromey-4
In reply to this post by Tom Tromey-4
This updates the "save gdb-index" documentation to reflect the new
state of Ada support.  It also corrects an existing grammatical error.

gdb/doc/ChangeLog
2019-07-31  Tom Tromey  <[hidden email]>

        * gdb.texinfo (Index Files): Update Ada text.
---
 gdb/doc/ChangeLog   | 4 ++++
 gdb/doc/gdb.texinfo | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 0fcd131f71e..906162c90c1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20919,8 +20919,8 @@ $ gdb -iex "set use-deprecated-index-sections on" <program>
 @end smallexample
 
 There are currently some limitation on indices.  They only work when
-for DWARF debugging information, not stabs.  And, they do not
-currently work for programs using Ada.
+using DWARF debugging information, not stabs.  And, only the
+@code{-dwarf-5} index works for programs using Ada.
 
 @subsection Automatic symbol index cache
 
--
2.20.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 8/8] Update "save gdb-index" documentation

Eli Zaretskii
> From: Tom Tromey <[hidden email]>
> Cc: Tom Tromey <[hidden email]>
> Date: Wed, 31 Jul 2019 14:14:11 -0600
>
> This updates the "save gdb-index" documentation to reflect the new
> state of Ada support.  It also corrects an existing grammatical error.
>
> gdb/doc/ChangeLog
> 2019-07-31  Tom Tromey  <[hidden email]>
>
> * gdb.texinfo (Index Files): Update Ada text.

OK, thanks.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/8] Add Ada support for .debug_names

Tom Tromey-4
In reply to this post by Tom Tromey-4
>>>>> "Tom" == Tom Tromey <[hidden email]> writes:

Tom> This series adds support for Ada in the .debug_names index.
Tom> This is mostly straightforward.  The series starts with a few cleanup
Tom> patches, to make it simpler to share code with psymtabs.

I've rebased this and fixed a small merge conflict.  I re-tested it, and
I'm checking it in now.

Tom