public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>, gdb-patches@sourceware.org
Subject: [PATCH] Fix gdb.ada/complete.exp's "complete break ada" test (PR, gdb/22670) (Re: [PATCH 2/3] Add "complete break ada" test to gdb.ada/complete.exp)
Date: Fri, 05 Jan 2018 16:37:00 -0000	[thread overview]
Message-ID: <05e600e1-c48c-de04-7e33-2c962b75bc25@redhat.com> (raw)
In-Reply-To: <1515054953-81012-3-git-send-email-brobecker@adacore.com>

On 01/04/2018 08:35 AM, Joel Brobecker wrote:
> This patch adds a new test to demonstrate a regression introduced by:
> 
>     commit b5ec771e60c1a0863e51eb491c85c674097e9e13
>     Date:   Wed Nov 8 14:22:32 2017 +0000
>     Subject: Introduce lookup_name_info and generalize Ada's FULL/WILD name matching
> 
> The original purpose of the new test is to exercise the "complete"
> command with an expression for which a large number of matches are
> returned and to verify that each match returned is a plausible match.
> In this particular case, the commit above causes GDB to generate
> additional matches which should in fact not appear in the list
> (internally generated symbols, or symbols that should be enclosed
> between "<...>"). These extraneous entries are easy to spot, because
> they have uppercase characters, such as:
> 
>     break ada__stringsS
>     break ada__strings__R11s
>     [etc]
> 
> For now, the new test is KFAIL'ed, to avoid generating a new FAIL
> while we work on fixing that regression.

And here's the fix for this one.  Also pushed to the
users/palves/literal-matching branch.

I think I addressed all the Ada regressions you reported.  Let me
know if I missed some.

From 2805fc780e497535f3966dea932023cad9b92b61 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 5 Jan 2018 12:21:25 +0000
Subject: [PATCH 2/2] Fix gdb.ada/complete.exp's "complete break ada" test (PR
 gdb/22670)

This patch fixes the regression covered by the test added by:

    commit 344420da6beac1e0b2f7964e7101f8dcdb509b0d
    Date: Thu Jan 4 03:30:37 2018 -0500
    Subject: Add "complete break ada" test to gdb.ada/complete.exp

The regression had been introduced by:

    commit b5ec771e60c1a0863e51eb491c85c674097e9e13
    Date:   Wed Nov 8 14:22:32 2017 +0000
    Subject: Introduce lookup_name_info and generalize Ada's FULL/WILD name matching

The gist of it is that linespec completion in Ada mode is generating
additional matches that should not appear in the match list
(internally generated symbols, or symbols that should be enclosed
between "<...>").  These extraneous entries have uppercase characters, such as:

    break ada__stringsS
    break ada__strings__R11s
    [etc]

These matches come from minimal symbols.  The problem is that Ada
minsyms end up with no language set (language_auto), and thus we end
up using the generic symbol name matcher for those instead of Ada's.
We already had a special case for in compare_symbol_name to handle
this, but it was limited to expressions, while the case at hand is
completing a linespec.  Fix this by applying the special case to
linespec completion as well.  I.e., remove the EXPRESSION check from
compare_symbol_name.  That alone turns out to not be sufficient still
-- GDB would still show a couple entries that shouldn't be there:

~~
    break ada__exceptions__exception_data__append_info_exception_name__2Xn
    break ada__exceptions__exception_data__exception_name_length__2Xn
~~

The reason is that these minimal symbols end up with their language
set to language_cplus / C++, because those encoded names manage to
demangle successfully as C++ symbols (using an old C++ mangling
scheme):

  $ echo ada__exceptions__exception_data__append_info_exception_name__2Xn | c++filt
  Xn::ada__exceptions__exception_data__append_info_exception_name(void)

It's unfortunate that Ada's encoding scheme doesn't start with some
unique prefix like "_Z" in the C++ Itanium ABI mangling scheme.  For
now, paper over that by treating C++ minsyms as Ada minsyms.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

        PR gdb/22670
	* ada-lang.c (ada_collect_symbol_completion_matches): If the
	minsym's language is language_auto or language_cplus, pass down
	language_ada instead.
	* symtab.c (compare_symbol_name): Don't frob symbol language here.

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

        PR gdb/22670
	* gdb.ada/complete.exp ("complete break ada"): Replace kfail with
	a fail.
---
 gdb/ada-lang.c                     | 19 ++++++++++++++++++-
 gdb/symtab.c                       | 16 +---------------
 gdb/testsuite/gdb.ada/complete.exp |  4 ++--
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 622cfd0a81e..ab1083830ed 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -6499,8 +6499,25 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
     if (completion_skip_symbol (mode, msymbol))
       continue;
 
+    language symbol_language = MSYMBOL_LANGUAGE (msymbol);
+
+    /* Ada minimal symbols won't have their language set to Ada.  If
+       we let completion_list_add_name compare using the
+       default/C-like matcher, then when completing e.g., symbols in a
+       package named "pck", we'd match internal Ada symbols like
+       "pckS", which are invalid in an Ada expression, unless you wrap
+       them in '<' '>' to request a verbatim match.
+
+       Unfortunately, some Ada encoded names successfully demangle as
+       C++ symbols (using an old mangling scheme), such as "name__2Xn"
+       -> "Xn::name(void)" and thus some Ada minimal symbols end up
+       with the wrong language set.  Paper over that issue here.  */
+    if (symbol_language == language_auto
+	|| symbol_language == language_cplus)
+      symbol_language = language_ada;
+
     completion_list_add_name (tracker,
-			      MSYMBOL_LANGUAGE (msymbol),
+			      symbol_language,
 			      MSYMBOL_LINKAGE_NAME (msymbol),
 			      lookup_name, text, word);
   }
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 146dc2e4213..2fe249682f2 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4704,21 +4704,7 @@ compare_symbol_name (const char *symbol_name, language symbol_language,
 		     const lookup_name_info &lookup_name,
 		     completion_match_result &match_res)
 {
-  const language_defn *lang;
-
-  /* If we're completing for an expression and the symbol doesn't have
-     an explicit language set, fallback to the current language.  Ada
-     minimal symbols won't have their language set to Ada, for
-     example, and if we compared using the default/C-like matcher,
-     then when completing e.g., symbols in a package named "pck", we'd
-     match internal Ada symbols like "pckS", which are invalid in an
-     Ada expression, unless you wrap them in '<' '>' to request a
-     verbatim match.  */
-  if (symbol_language == language_auto
-      && lookup_name.match_type () == symbol_name_match_type::EXPRESSION)
-    lang = current_language;
-  else
-    lang = language_def (symbol_language);
+  const language_defn *lang = language_def (symbol_language);
 
   symbol_name_matcher_ftype *name_match
     = language_get_symbol_name_matcher (lang, lookup_name);
diff --git a/gdb/testsuite/gdb.ada/complete.exp b/gdb/testsuite/gdb.ada/complete.exp
index c1f22c2a3e4..cb9e4ae7ffc 100644
--- a/gdb/testsuite/gdb.ada/complete.exp
+++ b/gdb/testsuite/gdb.ada/complete.exp
@@ -212,7 +212,7 @@ test_gdb_complete "ambiguous_func" \
 # However, we want to sanity-check each one of them, knowing that
 # each result should start with "break ada" and that the proposed
 # completion should look like a valid symbol name (in particular,
-# no uppercase letters...).
+# no uppercase letters...).  See gdb/22670.
 
 gdb_test_no_output "set max-completions unlimited"
 
@@ -222,6 +222,6 @@ gdb_test_multiple "$test" $test {
         pass $test
     }
     -re "\[A-Z\].*$gdb_prompt $" {
-        kfail gdb/22670 $test
+	fail "$test (gdb/22670)"
     }
 }
-- 
2.14.3

  reply	other threads:[~2018-01-05 16:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-04  8:36 FYI/pushed: Additional tests showing regression post C++ wild matching Joel Brobecker
2018-01-04  8:36 ` [PATCH 1/3] Add gdb.ada/info_addr_mixed_case new testcase Joel Brobecker
2018-01-04 13:25   ` Pedro Alves
2018-01-04 18:33     ` Pedro Alves
2018-01-05  3:22       ` Joel Brobecker
2018-01-05 16:06         ` Pedro Alves
2018-01-04  8:36 ` [PATCH 2/3] Add "complete break ada" test to gdb.ada/complete.exp Joel Brobecker
2018-01-05 16:37   ` Pedro Alves [this message]
2018-01-08  4:05     ` [PATCH] Fix gdb.ada/complete.exp's "complete break ada" test (PR, gdb/22670) (Re: [PATCH 2/3] Add "complete break ada" test to gdb.ada/complete.exp) Joel Brobecker
2018-01-04  8:36 ` [PATCH 3/3] Add new gdb.ada/bp_c_mixed_case testcase for PR gdb/22670 Joel Brobecker
2018-01-05 16:34   ` Fix gdb.ada/bp_c_mixed_case.exp (PR gdb/22670) (Re: [PATCH 3/3] Add new gdb.ada/bp_c_mixed_case testcase for PR gdb/22670) Pedro Alves
2018-01-08  3:57     ` Joel Brobecker
2018-01-08 15:00       ` Pedro Alves
2018-01-09  9:46         ` Joel Brobecker
2018-01-09 14:59           ` Pedro Alves
2018-01-09 16:45             ` Pedro Alves
2018-01-09 17:22               ` Pedro Alves
2018-01-10  3:36               ` Joel Brobecker
2018-01-10 23:41                 ` Pedro Alves
2018-01-11  4:00                   ` Joel Brobecker

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=05e600e1-c48c-de04-7e33-2c962b75bc25@redhat.com \
    --to=palves@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

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

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