Fix regresssion(internal-error) printing subprogram argument (PR gdb/22670)
authorPedro Alves <palves@redhat.com>
Fri, 5 Jan 2018 14:04:09 +0000 (14:04 +0000)
committerPedro Alves <palves@redhat.com>
Fri, 5 Jan 2018 16:07:00 +0000 (16:07 +0000)
At <https://sourceware.org/ml/gdb-patches/2017-12/msg00298.html>, Joel
wrote:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider the following code which first declares a tagged type (the
equivalent of a class in Ada), and then a procedure which takes a
pointer (access) to this type's 'Class.

    package Pck is
       type Top_T is tagged record
          N : Integer := 1;
       end record;
       procedure Inspect (Obj: access Top_T'Class);
    end Pck;

Putting a breakpoint in that procedure and then running to it triggers
an internal error:

    (gdb) break inspect
    (gdb) continue
    Breakpoint 1, pck.inspect (obj=0x63e010
    /[...]/gdb/stack.c:621: internal-error: void print_frame_args(symbol*, frame_info*, int, ui_file*): Assertion `nsym != NULL' failed.

What's special about this subprogram is that it takes an access to
what we call a 'Class type, and for implementation reasons, the
compiler adds an extra argument named "objL". If you are curious why,
it allows the compiler for perform dynamic accessibility checks that
are mandated by the language.

If we look at the location where we get the internal error (in
stack.c), we find that we are looping over the symbol of each
parameter, and for each parameter, we do:

    /* We have to look up the symbol because arguments can have
       two entries (one a parameter, one a local) and the one we
       want is the local, which lookup_symbol will find for us.
    [...]
        nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
                              b, VAR_DOMAIN, NULL).symbol;
        gdb_assert (nsym != NULL);

The lookup_symbol goes through the lookup structure, which means the
symbol's linkage name ("objL") gets transformed into a
lookup_name_info object (in block_lookup_symbol), before it gets fed
to the block symbol dictionary iterators.  This, in turn, triggers the
symbol matching by comparing the "lookup" name which, for Ada, means
among other things, lowercasing the given name to "objl".  It is this
transformation that causes the lookup find no matches, and therefore
trip this assertion.

Going back to the "offending" call to lookup_symbol in stack.c, what
we are trying to do, here, is do a lookup by linkage name.  So, I
think what we mean to be doing is a completely literal symbol lookup,
so maybe not even strcmp_iw, but actually just plain strcmp???

In the past, in practice, you could get that effect by doing a lookup
using the C language. But that doesn't work, because we still end up
somehow using Ada's lookup_name routine which transforms "objL".

So, ideally, as I hinted before, I think what we need is a way to
perform a literal lookup so that searches by linkage names like the
above can be performed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This commit fixes the problem by implementing something similar to
Joel's literal idea, but with some important differences.

I considered adding a symbol_name_match_type::LINKAGE and supporting
searching by linkage name for any language, but the problem with that
is that the dictionaries only work with SYMBOL_SEARCH_NAME, because
that's what is used for hashing.  We'd need separate dictionaries for
hashed linkage names.

So with the current symbol tables infrastructure, it's not literal
linkage names that we want to pass down, but instead literal _search_
names (SYMBOL_SEARCH_NAME, etc.).

However, psymbols have no overload/function parameter info in C++, so
a straight strcmp doesn't work properly for C++ name matching.

So what we do is be a little less aggressive then and add a new
symbol_name_match_type::SEARCH_SYMBOL instead that takes as input a
non-user-input search symbol, and then we skip any decoding/demangling
steps and make:

 - Ada treat that as a verbatim match,
 - other languages treat it as symbol_name_match_type::FULL.

This also fixes the new '"maint check-psymtabs" for Ada' testcase for
me (gdb.ada/maint_with_ada.exp).  I've not removed the kfail yet
because Joel still sees that testcase failing with this patch.
That'll be fixed in follow up patches.

gdb/ChangeLog:
2018-01-05  Pedro Alves  <palves@redhat.com>

PR gdb/22670
* ada-lang.c (literal_symbol_name_matcher): New function.
(ada_get_symbol_name_matcher): Use it for
symbol_name_match_type::SEARCH_NAME.
* block.c (block_lookup_symbol): New parameter 'match_type'.  Pass
it down instead of assuming symbol_name_match_type::FULL.
* block.h (block_lookup_symbol): New parameter 'match_type'.
* c-valprint.c (print_unpacked_pointer): Use
lookup_symbol_search_name instead of lookup_symbol.
* compile/compile-object-load.c (get_out_value_type): Pass down
symbol_name_match_type::SEARCH_NAME.
* cp-namespace.c (cp_basic_lookup_symbol): Pass down
symbol_name_match_type::FULL.
* cp-support.c (cp_get_symbol_name_matcher): Handle
symbol_name_match_type::SEARCH_NAME.
* infrun.c (insert_exception_resume_breakpoint): Use
lookup_symbol_search_name.
* p-valprint.c (pascal_val_print): Use lookup_symbol_search_name.
* psymtab.c (maintenance_check_psymtabs): Use
symbol_name_match_type::SEARCH_NAME and SYMBOL_SEARCH_NAME.
* stack.c (print_frame_args): Use lookup_symbol_search_name and
SYMBOL_SEARCH_NAME.
* symtab.c (lookup_local_symbol): Don't demangle the lookup name
if symbol_name_match_type::SEARCH_NAME.
(lookup_symbol_in_language): Pass down
symbol_name_match_type::FULL.
(lookup_symbol_search_name): New.
(lookup_language_this): Pass down
symbol_name_match_type::SEARCH_NAME.
(lookup_symbol_aux, lookup_local_symbol): New parameter
'match_type'.  Pass it down.
* symtab.h (symbol_name_match_type::SEARCH_NAME): New enumerator.
(lookup_symbol_search_name): New declaration.
(lookup_symbol_in_block): New 'match_type' parameter.

gdb/testsuite/ChangeLog:
2018-01-05  Joel Brobecker  <brobecker@adacore.com>

PR gdb/22670
* gdb.ada/access_tagged_param.exp: New file.
* gdb.ada/access_tagged_param/foo.adb: New file.

19 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/block.c
gdb/block.h
gdb/c-valprint.c
gdb/compile/compile-object-load.c
gdb/cp-namespace.c
gdb/cp-support.c
gdb/infrun.c
gdb/p-valprint.c
gdb/psymtab.c
gdb/stack.c
gdb/symtab.c
gdb/symtab.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/access_tagged_param.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_tagged_param/foo.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_tagged_param/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/access_tagged_param/pck.ads [new file with mode: 0644]

index badced8f061859e185c5fb93283cad13efee6559..10aabcde3bb9b0c5ecfdf59d73640117bcf18a8f 100644 (file)
@@ -1,3 +1,40 @@
+2018-01-05  Pedro Alves  <palves@redhat.com>
+
+       PR gdb/22670
+       * ada-lang.c (literal_symbol_name_matcher): New function.
+       (ada_get_symbol_name_matcher): Use it for
+       symbol_name_match_type::SEARCH_NAME.
+       * block.c (block_lookup_symbol): New parameter 'match_type'.  Pass
+       it down instead of assuming symbol_name_match_type::FULL.
+       * block.h (block_lookup_symbol): New parameter 'match_type'.
+       * c-valprint.c (print_unpacked_pointer): Use
+       lookup_symbol_search_name instead of lookup_symbol.
+       * compile/compile-object-load.c (get_out_value_type): Pass down
+       symbol_name_match_type::SEARCH_NAME.
+       * cp-namespace.c (cp_basic_lookup_symbol): Pass down
+       symbol_name_match_type::FULL.
+       * cp-support.c (cp_get_symbol_name_matcher): Handle
+       symbol_name_match_type::SEARCH_NAME.
+       * infrun.c (insert_exception_resume_breakpoint): Use
+       lookup_symbol_search_name.
+       * p-valprint.c (pascal_val_print): Use lookup_symbol_search_name.
+       * psymtab.c (maintenance_check_psymtabs): Use
+       symbol_name_match_type::SEARCH_NAME and SYMBOL_SEARCH_NAME.
+       * stack.c (print_frame_args): Use lookup_symbol_search_name and
+       SYMBOL_SEARCH_NAME.
+       * symtab.c (lookup_local_symbol): Don't demangle the lookup name
+       if symbol_name_match_type::SEARCH_NAME.
+       (lookup_symbol_in_language): Pass down
+       symbol_name_match_type::FULL.
+       (lookup_symbol_search_name): New.
+       (lookup_language_this): Pass down
+       symbol_name_match_type::SEARCH_NAME.
+       (lookup_symbol_aux, lookup_local_symbol): New parameter
+       'match_type'.  Pass it down.
+       * symtab.h (symbol_name_match_type::SEARCH_NAME): New enumerator.
+       (lookup_symbol_search_name): New declaration.
+       (lookup_symbol_in_block): New 'match_type' parameter.
+
 2018-01-05  Pedro Alves  <palves@redhat.com>
 
        PR gdb/22670
index e7c2197ca7debad9b0a560e5856f51a6fbb8ff3b..622cfd0a81ec30ca87ad9c2a9fe0ad2017074879 100644 (file)
@@ -14412,12 +14412,38 @@ ada_symbol_name_matches (const char *symbol_search_name,
                                     comp_match_res);
 }
 
+/* A name matcher that matches the symbol name exactly, with
+   strcmp.  */
+
+static bool
+literal_symbol_name_matcher (const char *symbol_search_name,
+                            const lookup_name_info &lookup_name,
+                            completion_match_result *comp_match_res)
+{
+  const std::string &name = lookup_name.name ();
+
+  int cmp = (lookup_name.completion_mode ()
+            ? strncmp (symbol_search_name, name.c_str (), name.size ())
+            : strcmp (symbol_search_name, name.c_str ()));
+  if (cmp == 0)
+    {
+      if (comp_match_res != NULL)
+       comp_match_res->set_match (symbol_search_name);
+      return true;
+    }
+  else
+    return false;
+}
+
 /* Implement the "la_get_symbol_name_matcher" language_defn method for
    Ada.  */
 
 static symbol_name_matcher_ftype *
 ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 {
+  if (lookup_name.match_type () == symbol_name_match_type::SEARCH_NAME)
+    return literal_symbol_name_matcher;
+
   if (lookup_name.completion_mode ())
     return ada_symbol_name_matches;
   else
index fb91eb9fee05d349f9ae19504b15d2536f479052..57da7ba73934e793589f5e151b369113ea38635e 100644 (file)
@@ -673,12 +673,13 @@ block_iter_match_next (const lookup_name_info &name,
 
 struct symbol *
 block_lookup_symbol (const struct block *block, const char *name,
+                    symbol_name_match_type match_type,
                     const domain_enum domain)
 {
   struct block_iterator iter;
   struct symbol *sym;
 
-  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
+  lookup_name_info lookup_name (name, match_type);
 
   if (!BLOCK_FUNCTION (block))
     {
index 8f400cf8c0fc1805870222465be5ec21138e499d..ff127256ad702866651a8b7f5459e22ee702aac1 100644 (file)
@@ -258,6 +258,7 @@ extern struct symbol *block_iter_match_next
 
 extern struct symbol *block_lookup_symbol (const struct block *block,
                                           const char *name,
+                                          symbol_name_match_type match_type,
                                           const domain_enum domain);
 
 /* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of
index 7f8154e6601071a4a81d86929deb1fa002a2ce42..c4c0918e26afe58dc488f0d1ba2a39af4b1bddd7 100644 (file)
@@ -198,14 +198,17 @@ print_unpacked_pointer (struct type *type, struct type *elttype,
          struct symbol *wsym = NULL;
          struct type *wtype;
          struct block *block = NULL;
-         struct field_of_this_result is_this_fld;
 
          if (want_space)
            fputs_filtered (" ", stream);
 
          if (msymbol.minsym != NULL)
-           wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME(msymbol.minsym), block,
-                                 VAR_DOMAIN, &is_this_fld).symbol;
+           {
+             const char *search_name
+               = MSYMBOL_SEARCH_NAME (msymbol.minsym);
+             wsym = lookup_symbol_search_name (search_name, block,
+                                               VAR_DOMAIN).symbol;
+           }
 
          if (wsym)
            {
index 0b7215b323607b195d552849ecacf5f9cb2abdcc..fac16d70ddee367e27bfb09f0f7f624532ac3c88 100644 (file)
@@ -439,7 +439,10 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
       block = BLOCKVECTOR_BLOCK (bv, block_loop);
       if (BLOCK_FUNCTION (block) != NULL)
        continue;
-      gdb_val_sym = block_lookup_symbol (block, COMPILE_I_EXPR_VAL, VAR_DOMAIN);
+      gdb_val_sym = block_lookup_symbol (block,
+                                        COMPILE_I_EXPR_VAL,
+                                        symbol_name_match_type::SEARCH_NAME,
+                                        VAR_DOMAIN);
       if (gdb_val_sym == NULL)
        continue;
 
@@ -466,6 +469,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
   gdb_type = check_typedef (gdb_type);
 
   gdb_ptr_type_sym = block_lookup_symbol (block, COMPILE_I_EXPR_PTR_TYPE,
+                                         symbol_name_match_type::SEARCH_NAME,
                                          VAR_DOMAIN);
   if (gdb_ptr_type_sym == NULL)
     error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE);
index 0751fda7e6360a1712ab24c5905625a161903d66..185607e4eb84f901dc974dbd26b3ed0bd5815bff 100644 (file)
@@ -141,7 +141,9 @@ cp_basic_lookup_symbol (const char *name, const struct block *block,
 
       if (global_block != NULL)
        {
-         sym.symbol = lookup_symbol_in_block (name, global_block, domain);
+         sym.symbol = lookup_symbol_in_block (name,
+                                              symbol_name_match_type::FULL,
+                                              global_block, domain);
          sym.block = global_block;
        }
     }
index 2efc38557acb3590a780ab0c87aa1d185a57569a..dde417be80ee433405f739d5df51500f87089e89 100644 (file)
@@ -1793,6 +1793,7 @@ cp_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     {
     case symbol_name_match_type::FULL:
     case symbol_name_match_type::EXPRESSION:
+    case symbol_name_match_type::SEARCH_NAME:
       return cp_fq_symbol_name_matches;
     case symbol_name_match_type::WILD:
       return cp_symbol_name_matches;
index 3f7d185240be1004e902d35458473356aaff0553..7e8d8da588496292ccfbe7bdbb40e46ae5847997 100644 (file)
@@ -7489,7 +7489,8 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
       CORE_ADDR handler;
       struct breakpoint *bp;
 
-      vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
+      vsym = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym),
+                                       b, VAR_DOMAIN);
       value = read_var_value (vsym.symbol, vsym.block, frame);
       /* If the value was optimized out, revert to the old behavior.  */
       if (! value_optimized_out (value))
index 6d5358630e1132c796d6c439327fc432924cddc1..933dbfb6c4d0b8a39c1d208183a82acc7c28a8a0 100644 (file)
@@ -246,15 +246,17 @@ pascal_val_print (struct type *type,
              struct symbol *wsym = NULL;
              struct type *wtype;
              struct block *block = NULL;
-             struct field_of_this_result is_this_fld;
 
              if (want_space)
                fputs_filtered (" ", stream);
 
              if (msymbol.minsym != NULL)
-               wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME (msymbol.minsym),
-                                     block,
-                                     VAR_DOMAIN, &is_this_fld).symbol;
+               {
+                 const char *search_name
+                   = MSYMBOL_SEARCH_NAME (msymbol.minsym);
+                 wsym = lookup_symbol_search_name (search_name, block,
+                                                   VAR_DOMAIN).symbol;
+               }
 
              if (wsym)
                {
index 3075be29b77786845acba7b8112deb0ca950b07f..88d234a7da230022399112e6e3291363111a7d20 100644 (file)
@@ -2254,7 +2254,8 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
     length = ps->n_static_syms;
     while (length--)
       {
-       sym = block_lookup_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
+       sym = block_lookup_symbol (b, SYMBOL_SEARCH_NAME (*psym),
+                                  symbol_name_match_type::SEARCH_NAME,
                                   SYMBOL_DOMAIN (*psym));
        if (!sym)
          {
@@ -2271,7 +2272,8 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
     length = ps->n_global_syms;
     while (length--)
       {
-       sym = block_lookup_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
+       sym = block_lookup_symbol (b, SYMBOL_SEARCH_NAME (*psym),
+                                  symbol_name_match_type::SEARCH_NAME,
                                   SYMBOL_DOMAIN (*psym));
        if (!sym)
          {
index 263e7bb0fc65cf60247f83022ac7068e7c235ef9..9993ae654ad592197b96af82a859734b7f4ec868 100644 (file)
@@ -616,8 +616,8 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
            {
              struct symbol *nsym;
 
-             nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
-                                   b, VAR_DOMAIN, NULL).symbol;
+             nsym = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym),
+                                               b, VAR_DOMAIN).symbol;
              gdb_assert (nsym != NULL);
              if (SYMBOL_CLASS (nsym) == LOC_REGISTER
                  && !SYMBOL_IS_ARGUMENT (nsym))
@@ -2141,8 +2141,8 @@ iterate_over_block_arg_vars (const struct block *b,
             float).  There are also LOC_ARG/LOC_REGISTER pairs which
             are not combined in symbol-reading.  */
 
-         sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
-                               b, VAR_DOMAIN, NULL).symbol;
+         sym2 = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym),
+                                           b, VAR_DOMAIN).symbol;
          (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
        }
     }
index 3865420cd1e5de184a150319966388c2486a5b2d..146dc2e42134e94c2c88f0330983ea19524bfcc0 100644 (file)
@@ -75,6 +75,7 @@ static int find_line_common (struct linetable *, int, int *, int);
 
 static struct block_symbol
   lookup_symbol_aux (const char *name,
+                    symbol_name_match_type match_type,
                     const struct block *block,
                     const domain_enum domain,
                     enum language language,
@@ -82,6 +83,7 @@ static struct block_symbol
 
 static
 struct block_symbol lookup_local_symbol (const char *name,
+                                        symbol_name_match_type match_type,
                                         const struct block *block,
                                         const domain_enum domain,
                                         enum language language);
@@ -1773,14 +1775,18 @@ demangle_for_lookup_info::demangle_for_lookup_info
 
       if (without_params != NULL)
        {
-         m_demangled_name = demangle_for_lookup (without_params.get (),
-                                                 lang, storage);
+         if (lookup_name.match_type () != symbol_name_match_type::SEARCH_NAME)
+           m_demangled_name = demangle_for_lookup (without_params.get (),
+                                                   lang, storage);
          return;
        }
     }
 
-  m_demangled_name = demangle_for_lookup (lookup_name.name ().c_str (),
-                                         lang, storage);
+  if (lookup_name.match_type () == symbol_name_match_type::SEARCH_NAME)
+    m_demangled_name = lookup_name.name ();
+  else
+    m_demangled_name = demangle_for_lookup (lookup_name.name ().c_str (),
+                                           lang, storage);
 }
 
 /* See symtab.h.  */
@@ -1876,7 +1882,9 @@ lookup_symbol_in_language (const char *name, const struct block *block,
   demangle_result_storage storage;
   const char *modified_name = demangle_for_lookup (name, lang, storage);
 
-  return lookup_symbol_aux (modified_name, block, domain, lang,
+  return lookup_symbol_aux (modified_name,
+                           symbol_name_match_type::FULL,
+                           block, domain, lang,
                            is_a_field_of_this);
 }
 
@@ -1894,6 +1902,16 @@ lookup_symbol (const char *name, const struct block *block,
 
 /* See symtab.h.  */
 
+struct block_symbol
+lookup_symbol_search_name (const char *search_name, const struct block *block,
+                          domain_enum domain)
+{
+  return lookup_symbol_aux (search_name, symbol_name_match_type::SEARCH_NAME,
+                           block, domain, language_asm, NULL);
+}
+
+/* See symtab.h.  */
+
 struct block_symbol
 lookup_language_this (const struct language_defn *lang,
                      const struct block *block)
@@ -1915,7 +1933,9 @@ lookup_language_this (const struct language_defn *lang,
     {
       struct symbol *sym;
 
-      sym = block_lookup_symbol (block, lang->la_name_of_this, VAR_DOMAIN);
+      sym = block_lookup_symbol (block, lang->la_name_of_this,
+                                symbol_name_match_type::SEARCH_NAME,
+                                VAR_DOMAIN);
       if (sym != NULL)
        {
          if (symbol_lookup_debug > 1)
@@ -1986,7 +2006,8 @@ check_field (struct type *type, const char *name,
    (e.g., demangled name) of the symbol that we're looking for.  */
 
 static struct block_symbol
-lookup_symbol_aux (const char *name, const struct block *block,
+lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
+                  const struct block *block,
                   const domain_enum domain, enum language language,
                   struct field_of_this_result *is_a_field_of_this)
 {
@@ -2015,7 +2036,7 @@ lookup_symbol_aux (const char *name, const struct block *block,
   /* Search specified block and its superiors.  Don't search
      STATIC_BLOCK or GLOBAL_BLOCK.  */
 
-  result = lookup_local_symbol (name, block, domain, language);
+  result = lookup_local_symbol (name, match_type, block, domain, language);
   if (result.symbol != NULL)
     {
       if (symbol_lookup_debug)
@@ -2097,7 +2118,9 @@ lookup_symbol_aux (const char *name, const struct block *block,
    Don't search STATIC_BLOCK or GLOBAL_BLOCK.  */
 
 static struct block_symbol
-lookup_local_symbol (const char *name, const struct block *block,
+lookup_local_symbol (const char *name,
+                    symbol_name_match_type match_type,
+                    const struct block *block,
                     const domain_enum domain,
                     enum language language)
 {
@@ -2112,7 +2135,7 @@ lookup_local_symbol (const char *name, const struct block *block,
 
   while (block != static_block)
     {
-      sym = lookup_symbol_in_block (name, block, domain);
+      sym = lookup_symbol_in_block (name, match_type, block, domain);
       if (sym != NULL)
        return (struct block_symbol) {sym, block};
 
@@ -2165,7 +2188,8 @@ lookup_objfile_from_block (const struct block *block)
 /* See symtab.h.  */
 
 struct symbol *
-lookup_symbol_in_block (const char *name, const struct block *block,
+lookup_symbol_in_block (const char *name, symbol_name_match_type match_type,
+                       const struct block *block,
                        const domain_enum domain)
 {
   struct symbol *sym;
@@ -2181,7 +2205,7 @@ lookup_symbol_in_block (const char *name, const struct block *block,
                          domain_name (domain));
     }
 
-  sym = block_lookup_symbol (block, name, domain);
+  sym = block_lookup_symbol (block, name, match_type, domain);
   if (sym)
     {
       if (symbol_lookup_debug > 1)
@@ -2370,7 +2394,8 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, int block_index,
 
   bv = COMPUNIT_BLOCKVECTOR (cust);
   block = BLOCKVECTOR_BLOCK (bv, block_index);
-  result.symbol = block_lookup_symbol (block, name, domain);
+  result.symbol = block_lookup_symbol (block, name,
+                                      symbol_name_match_type::FULL, domain);
   if (result.symbol == NULL)
     error_in_psymtab_expansion (block_index, name, cust);
 
@@ -2483,7 +2508,9 @@ lookup_symbol_in_static_block (const char *name,
                          domain_name (domain));
     }
 
-  sym = lookup_symbol_in_block (name, static_block, domain);
+  sym = lookup_symbol_in_block (name,
+                               symbol_name_match_type::FULL,
+                               static_block, domain);
   if (symbol_lookup_debug)
     {
       fprintf_unfiltered (gdb_stdlog,
index b49d56ba2a8d9a795b4cbf90f6ee652e05a0d030..a7b1ed2131c8d43faac28034203bc1073e506501 100644 (file)
@@ -60,6 +60,16 @@ enum class symbol_name_match_type
      namespace/module/package.  */
   FULL,
 
+  /* Search name matching.  This is like FULL, but the search name did
+     not come from the user; instead it is already a search name
+     retrieved from a SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call.
+     For Ada, this avoids re-encoding an already-encoded search name
+     (which would potentially incorrectly lowercase letters in the
+     linkage/search name that should remain uppercase).  For C++, it
+     avoids trying to demangle a name we already know is
+     demangled.  */
+  SEARCH_NAME,
+
   /* Expression matching.  The same as FULL matching in most
      languages.  The same as WILD matching in Ada.  */
   EXPRESSION,
@@ -1554,6 +1564,20 @@ extern struct block_symbol lookup_symbol (const char *,
                                          const domain_enum,
                                          struct field_of_this_result *);
 
+/* Find the definition for a specified symbol search name in domain
+   DOMAIN, visible from lexical block BLOCK if non-NULL or from
+   global/static blocks if BLOCK is NULL.  The passed-in search name
+   should not come from the user; instead it should already be a
+   search name as retrieved from a
+   SYMBOL_SEARCH_NAME/MSYMBOL_SEARCH_NAME call.  See definition of
+   symbol_name_match_type::SEARCH_NAME.  Returns the struct symbol
+   pointer, or NULL if no symbol is found.  The symbol's section is
+   fixed up if necessary.  */
+
+extern struct block_symbol lookup_symbol_search_name (const char *search_name,
+                                                     const struct block *block,
+                                                     domain_enum domain);
+
 /* A default version of lookup_symbol_nonlocal for use by languages
    that can't think of anything better to do.
    This implements the C lookup rules.  */
@@ -1603,6 +1627,7 @@ extern struct block_symbol
 
 extern struct symbol *
   lookup_symbol_in_block (const char *name,
+                         symbol_name_match_type match_type,
                          const struct block *block,
                          const domain_enum domain);
 
index 94486316d242b3fa2026c3442d167ff37991e3a8..18ad7403b4978393fc9141fe53bb9f12165d759b 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-05  Joel Brobecker  <brobecker@adacore.com>
+
+       PR gdb/22670
+       * gdb.ada/access_tagged_param.exp: New file.
+       * gdb.ada/access_tagged_param/foo.adb: New file.
+
 2018-01-05  Pedro Alves  <palves@redhat.com>
 
        PR gdb/22670
diff --git a/gdb/testsuite/gdb.ada/access_tagged_param.exp b/gdb/testsuite/gdb.ada/access_tagged_param.exp
new file mode 100644 (file)
index 0000000..598cf89
--- /dev/null
@@ -0,0 +1,40 @@
+# Copyright 2017-2018 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/>.
+
+# Check that we can print values of parameters of type 'pointer
+# (access) to tagged type'.  See PR gdb/22670.
+
+load_lib "ada.exp"
+
+standard_ada_testfile foo
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
+  return -1
+}
+
+clean_restart ${testfile}
+
+if ![runto "foo"] then {
+  perror "Couldn't run ${testfile}"
+  return
+}
+
+gdb_breakpoint "pck.inspect"
+
+# Continue until we reach the breakpoint, and verify that we can print
+# the value of all the parameters.
+
+gdb_test "continue" \
+         ".*Breakpoint $decimal, pck\\.inspect \\(obj=$hex, <objL>=2\\) at .*"
diff --git a/gdb/testsuite/gdb.ada/access_tagged_param/foo.adb b/gdb/testsuite/gdb.ada/access_tagged_param/foo.adb
new file mode 100644 (file)
index 0000000..76d738c
--- /dev/null
@@ -0,0 +1,20 @@
+--  Copyright 2017-2018 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/>.
+
+with Pck; use Pck;
+procedure Foo is
+begin
+   Inspect (new Top_T'(N => 2));
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/access_tagged_param/pck.adb b/gdb/testsuite/gdb.ada/access_tagged_param/pck.adb
new file mode 100644 (file)
index 0000000..d156cee
--- /dev/null
@@ -0,0 +1,21 @@
+--  Copyright 2017-2018 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/>.
+
+package body Pck is
+   procedure Inspect (Obj: access Top_T'Class) is
+   begin
+      null;
+   end Inspect;
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/access_tagged_param/pck.ads b/gdb/testsuite/gdb.ada/access_tagged_param/pck.ads
new file mode 100644 (file)
index 0000000..f1973d2
--- /dev/null
@@ -0,0 +1,21 @@
+--  Copyright 2017-2018 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/>.
+
+package Pck is
+   type Top_T is tagged record
+      N : Integer := 1;
+   end record;
+   procedure Inspect (Obj: access Top_T'Class);
+end Pck;