From patchwork Fri Jan 5 16:28:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 25233 Received: (qmail 1183 invoked by alias); 5 Jan 2018 16:28:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 1174 invoked by uid 89); 5 Jan 2018 16:28:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-21.9 required=5.0 tests=BAYES_50, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, KAM_STOCKGEN, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=cust, accessibility, declares, sees X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 05 Jan 2018 16:28:26 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F65B81DE2; Fri, 5 Jan 2018 16:28:25 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1443258826; Fri, 5 Jan 2018 16:28:23 +0000 (UTC) Subject: Re: [RFC] regresssion(internal-error) printing subprogram argument To: Joel Brobecker References: <20171213103655.msbaxfrykc36f4a7@adacore.com> <20171215094755.dwocipbcwvtdm6f6@adacore.com> <00320239-44c8-b9c3-013b-b27c771e3401@redhat.com> <07a154ef-b6f5-ad86-1410-a73620de4b5b@redhat.com> <20180103043345.n6blge377ybsdx6q@adacore.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <8df5cf8b-6e4e-e310-fcbd-2615334fe5b9@redhat.com> Date: Fri, 5 Jan 2018 16:28:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20180103043345.n6blge377ybsdx6q@adacore.com> On 01/03/2018 04:33 AM, Joel Brobecker wrote: > Hi Pedro, > >>> Maybe what we need is to 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 like symbol_name_match_type::LITERAL >>> was, and then we skip any decoding/demangling steps (like LITERAL) and make: >>> - Ada treat that as a verbatim match, >>> - other languages treat it as symbol_name_match_type::FULL. > [...] >> With the patch below applied on top, which is a minimal version of >> the design change I suggested (LITERAL -> SEARCH_SYMBOL), I now get >> again the same "maint check-psymtabs" output that I get with system gdb. >> So seems like this is on the good track. >> >> Your internal-error test still passes as well as the new >> "maint check-psymtabs" for gdb.ada/ testcase. > > Sounds like we are indeed on the right track! > > I ran the changes through both the official testsuite and AdaCore's > testsuite, and I can confirm no regression :). Is there something > else I can do to help? I just needed to fold both patches in, do the renaming thing, update comments and compose git log + ChangeLog. After looking at the other regressions and convincing myself that this is good enough, that is. :-) Here's the resulting patch, which I merged to both master and branch now. I remembered to update the copyright year in the new testcase, and to include a short description of what the testcase is about in the .exp file. From de63c46b549d1cf4f7851e47872cb759a12983f4 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 5 Jan 2018 14:04:09 +0000 Subject: [PATCH] Fix regresssion(internal-error) printing subprogram argument (PR gdb/22670) At , 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 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 PR gdb/22670 * gdb.ada/access_tagged_param.exp: New file. * gdb.ada/access_tagged_param/foo.adb: New file. --- gdb/ChangeLog | 37 +++++++++++++++ gdb/testsuite/ChangeLog | 6 +++ gdb/ada-lang.c | 26 +++++++++++ gdb/block.c | 3 +- gdb/block.h | 1 + gdb/c-valprint.c | 9 ++-- gdb/compile/compile-object-load.c | 6 ++- gdb/cp-namespace.c | 4 +- gdb/cp-support.c | 1 + gdb/infrun.c | 3 +- gdb/p-valprint.c | 10 +++-- gdb/psymtab.c | 6 ++- gdb/stack.c | 8 ++-- gdb/symtab.c | 55 +++++++++++++++++------ gdb/symtab.h | 25 +++++++++++ gdb/testsuite/gdb.ada/access_tagged_param.exp | 40 +++++++++++++++++ gdb/testsuite/gdb.ada/access_tagged_param/foo.adb | 20 +++++++++ gdb/testsuite/gdb.ada/access_tagged_param/pck.adb | 21 +++++++++ gdb/testsuite/gdb.ada/access_tagged_param/pck.ads | 21 +++++++++ 19 files changed, 271 insertions(+), 31 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/access_tagged_param.exp create mode 100644 gdb/testsuite/gdb.ada/access_tagged_param/foo.adb create mode 100644 gdb/testsuite/gdb.ada/access_tagged_param/pck.adb create mode 100644 gdb/testsuite/gdb.ada/access_tagged_param/pck.ads diff --git a/gdb/ChangeLog b/gdb/ChangeLog index badced8f061..10aabcde3bb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,40 @@ +2018-01-05 Pedro Alves + + 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 PR gdb/22670 diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 94486316d24..18ad7403b49 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-01-05 Joel Brobecker + + 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 PR gdb/22670 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index e7c2197ca7d..622cfd0a81e 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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 diff --git a/gdb/block.c b/gdb/block.c index fb91eb9fee0..57da7ba7393 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -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)) { diff --git a/gdb/block.h b/gdb/block.h index 8f400cf8c0f..ff127256ad7 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -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 diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 7f8154e6601..c4c0918e26a 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -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) { diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 0b7215b3236..fac16d70dde 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -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); diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 0751fda7e63..185607e4eb8 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -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; } } diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 2efc38557ac..dde417be80e 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -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; diff --git a/gdb/infrun.c b/gdb/infrun.c index 3f7d185240b..7e8d8da5884 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -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)) diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index 6d5358630e1..933dbfb6c4d 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -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) { diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 3075be29b77..88d234a7da2 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -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) { diff --git a/gdb/stack.c b/gdb/stack.c index 263e7bb0fc6..9993ae654ad 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -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); } } diff --git a/gdb/symtab.c b/gdb/symtab.c index 3865420cd1e..146dc2e4213 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -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, diff --git a/gdb/symtab.h b/gdb/symtab.h index b49d56ba2a8..a7b1ed2131c 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -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); diff --git a/gdb/testsuite/gdb.ada/access_tagged_param.exp b/gdb/testsuite/gdb.ada/access_tagged_param.exp new file mode 100644 index 00000000000..598cf89b4ec --- /dev/null +++ b/gdb/testsuite/gdb.ada/access_tagged_param.exp @@ -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 . + +# 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, =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 index 00000000000..76d738c373c --- /dev/null +++ b/gdb/testsuite/gdb.ada/access_tagged_param/foo.adb @@ -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 . + +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 index 00000000000..d156cee34b7 --- /dev/null +++ b/gdb/testsuite/gdb.ada/access_tagged_param/pck.adb @@ -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 . + +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 index 00000000000..f1973d201aa --- /dev/null +++ b/gdb/testsuite/gdb.ada/access_tagged_param/pck.ads @@ -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 . + +package Pck is + type Top_T is tagged record + N : Integer := 1; + end record; + procedure Inspect (Obj: access Top_T'Class); +end Pck;