public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Handle block-local names for Ada
@ 2020-12-10 16:24 Tom Tromey
  2020-12-10 16:24 ` [PATCH v2 1/2] Use exact match in get_var_value Tom Tromey
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom Tromey @ 2020-12-10 16:24 UTC (permalink / raw)
  To: gdb-patches

Here's v2 of the patches to handle block-local Ada names.

v1 was here:

https://sourceware.org/pipermail/gdb-patches/2020-November/173130.html

With some commentary here:

https://sourceware.org/pipermail/gdb-patches/2020-December/173778.html

This fixes the performance problem we found in v1.  Joel also found an
additional problem, namely that multiple levels of nesting are
possible.  This series handles this as well.

Tom



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] Use exact match in get_var_value
  2020-12-10 16:24 [PATCH v2 0/2] Handle block-local names for Ada Tom Tromey
@ 2020-12-10 16:24 ` Tom Tromey
  2020-12-10 16:24 ` [PATCH v2 2/2] Handle block-local names for Ada Tom Tromey
  2020-12-13 13:58 ` [PATCH v2 0/2] " Joel Brobecker
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2020-12-10 16:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

get_var_value is only used when an exact match is needed.  This
changes this function to ensure this sort of matching is done.

2020-12-10  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (get_var_value): Only consider exact matches.
---
 gdb/ChangeLog  | 4 ++++
 gdb/ada-lang.c | 8 +++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3351b95fce1..e9cbc4bcf1a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11350,14 +11350,16 @@ scan_discrim_bound (const char *str, int k, struct value *dval, LONGEST * px,
   return 1;
 }
 
-/* Value of variable named NAME in the current environment.  If
-   no such variable found, then if ERR_MSG is null, returns 0, and
+/* Value of variable named NAME.  Only exact matches are considered.
+   If no such variable found, then if ERR_MSG is null, returns 0, and
    otherwise causes an error with message ERR_MSG.  */
 
 static struct value *
 get_var_value (const char *name, const char *err_msg)
 {
-  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
+  std::string quoted_name = add_angle_brackets (name);
+
+  lookup_name_info lookup_name (quoted_name, symbol_name_match_type::FULL);
 
   std::vector<struct block_symbol> syms;
   int nsyms = ada_lookup_symbol_list_worker (lookup_name,
-- 
2.26.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] Handle block-local names for Ada
  2020-12-10 16:24 [PATCH v2 0/2] Handle block-local names for Ada Tom Tromey
  2020-12-10 16:24 ` [PATCH v2 1/2] Use exact match in get_var_value Tom Tromey
@ 2020-12-10 16:24 ` Tom Tromey
  2020-12-13 13:58 ` [PATCH v2 0/2] " Joel Brobecker
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2020-12-10 16:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

GNAT can generate a mangled name with "B_N" (where N is a number) in
the middle, like "hello__B_1__fourth.0".  This is used for names local
to a block.  Multiple levels of block-local name can also occur, a
possibility that was neglected by v1 of this patch.  This patch
changes gdb to handle these names.

The wild name matcher is updated a straightforward way.  The full
matcher is rewritten.  The hash function is updated to ensure that
this works.

This version does not seem to have the performance problems that
affected v1.  In particular, the previously-slow "bt" problem has been
fixed.

gdb/ChangeLog
2020-12-10  Tom Tromey  <tromey@adacore.com>

	* dictionary.c (language_defn::search_name_hash): Ignore "B".
	* ada-lang.c (advance_wild_match): Ignore "B".
	(full_match): Remove.
	(do_full_match): Rewrite.

gdb/testsuite/ChangeLog
2020-12-10  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/nested.exp: Add new tests.
	* gdb.ada/nested/hello.adb (Fourth, Fifth): New procedures.
---
 gdb/ChangeLog                          |  7 +++
 gdb/ada-lang.c                         | 65 +++++++++++++++++---------
 gdb/dictionary.c                       |  7 +++
 gdb/testsuite/ChangeLog                |  5 ++
 gdb/testsuite/gdb.ada/nested.exp       | 15 ++++++
 gdb/testsuite/gdb.ada/nested/hello.adb | 18 ++++++-
 6 files changed, 92 insertions(+), 25 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e9cbc4bcf1a..2719a2bfbd0 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -6036,6 +6036,13 @@ advance_wild_match (const char **namep, const char *name0, char target0)
 	      name += 2;
 	      break;
 	    }
+	  else if (t1 == '_' && name[2] == 'B' && name[3] == '_')
+	    {
+	      /* Names like "pkg__B_N__name", where N is a number, are
+		 block-local.  We can handle these by simply skipping
+		 the "B_" here.  */
+	      name += 4;
+	    }
 	  else
 	    return 0;
 	}
@@ -6080,28 +6087,6 @@ wild_match (const char *name, const char *patn)
     }
 }
 
-/* Returns true iff symbol name SYM_NAME matches SEARCH_NAME, ignoring
-   any trailing suffixes that encode debugging information or leading
-   _ada_ on SYM_NAME (see is_name_suffix commentary for the debugging
-   information that is ignored).  */
-
-static bool
-full_match (const char *sym_name, const char *search_name)
-{
-  size_t search_name_len = strlen (search_name);
-
-  if (strncmp (sym_name, search_name, search_name_len) == 0
-      && is_name_suffix (sym_name + search_name_len))
-    return true;
-
-  if (startswith (sym_name, "_ada_")
-      && strncmp (sym_name + 5, search_name, search_name_len) == 0
-      && is_name_suffix (sym_name + search_name_len + 5))
-    return true;
-
-  return false;
-}
-
 /* Add symbols from BLOCK matching LOOKUP_NAME in DOMAIN to vector
    *defn_symbols, updating the list of symbols in OBSTACKP (if
    necessary).  OBJFILE is the section containing BLOCK.  */
@@ -13605,7 +13590,41 @@ do_full_match (const char *symbol_search_name,
 	       const lookup_name_info &lookup_name,
 	       completion_match_result *comp_match_res)
 {
-  return full_match (symbol_search_name, ada_lookup_name (lookup_name));
+  if (startswith (symbol_search_name, "_ada_"))
+    symbol_search_name += 5;
+
+  const char *lname = lookup_name.ada ().lookup_name ().c_str ();
+  int uscore_count = 0;
+  while (*lname != '\0')
+    {
+      if (*symbol_search_name != *lname)
+	{
+	  if (*symbol_search_name == 'B' && uscore_count == 2
+	      && symbol_search_name[1] == '_')
+	    {
+	      symbol_search_name += 2;
+	      while (isdigit (*symbol_search_name))
+		++symbol_search_name;
+	      if (symbol_search_name[0] == '_'
+		  && symbol_search_name[1] == '_')
+		{
+		  symbol_search_name += 2;
+		  continue;
+		}
+	    }
+	  return false;
+	}
+
+      if (*symbol_search_name == '_')
+	++uscore_count;
+      else
+	uscore_count = 0;
+
+      ++symbol_search_name;
+      ++lname;
+    }
+
+  return is_name_suffix (symbol_search_name);
 }
 
 /* symbol_name_matcher_ftype for exact (verbatim) matches.  */
diff --git a/gdb/dictionary.c b/gdb/dictionary.c
index c94a49ee373..d51f209e715 100644
--- a/gdb/dictionary.c
+++ b/gdb/dictionary.c
@@ -761,6 +761,13 @@ language_defn::search_name_hash (const char *string0) const
 	    {
 	      int c = string[2];
 
+	      if (c == 'B' && string[3] == '_')
+		{
+		  for (string += 4; ISDIGIT (*string); ++string)
+		    ;
+		  continue;
+		}
+
 	      if ((c < 'a' || c > 'z') && c != 'O')
 		return hash;
 	      hash = 0;
diff --git a/gdb/testsuite/gdb.ada/nested.exp b/gdb/testsuite/gdb.ada/nested.exp
index ea4bb4de355..74f9f1f87ae 100644
--- a/gdb/testsuite/gdb.ada/nested.exp
+++ b/gdb/testsuite/gdb.ada/nested.exp
@@ -34,3 +34,18 @@ gdb_test "break first" \
          "Breakpoint $any_nb at $any_addr: file .*hello.adb, line $any_nb." \
          "break on nested function First"
 
+gdb_test "break fourth" \
+    "Breakpoint $any_nb at $any_addr: file .*hello.adb, line $any_nb." \
+    "break on nested function fourth"
+
+gdb_test "break hello.fourth" \
+    "Breakpoint $any_nb at $any_addr: file .*hello.adb, line $any_nb." \
+    "full-qualified break on nested function fourth"
+
+gdb_test "break fifth" \
+    "Breakpoint $any_nb at $any_addr: file .*hello.adb, line $any_nb." \
+    "break on nested function fifth"
+
+gdb_test "break hello.fourth.fifth" \
+    "Breakpoint $any_nb at $any_addr: file .*hello.adb, line $any_nb." \
+    "full-qualified break on nested function fifth"
diff --git a/gdb/testsuite/gdb.ada/nested/hello.adb b/gdb/testsuite/gdb.ada/nested/hello.adb
index 2d1e532e47d..10ec6bf8201 100644
--- a/gdb/testsuite/gdb.ada/nested/hello.adb
+++ b/gdb/testsuite/gdb.ada/nested/hello.adb
@@ -31,6 +31,20 @@ procedure Hello is
    end Third;
 
 begin
-   Third;
+   declare
+      procedure Fourth is
+      begin
+         Third;
+         declare
+            procedure Fifth is
+            begin
+               Second;
+            end Fifth;
+         begin
+            Fifth;
+         end;
+      end Fourth;
+   begin
+      Fourth;
+   end;
 end Hello;
-
-- 
2.26.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] Handle block-local names for Ada
  2020-12-10 16:24 [PATCH v2 0/2] Handle block-local names for Ada Tom Tromey
  2020-12-10 16:24 ` [PATCH v2 1/2] Use exact match in get_var_value Tom Tromey
  2020-12-10 16:24 ` [PATCH v2 2/2] Handle block-local names for Ada Tom Tromey
@ 2020-12-13 13:58 ` Joel Brobecker
  2 siblings, 0 replies; 4+ messages in thread
From: Joel Brobecker @ 2020-12-13 13:58 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> Here's v2 of the patches to handle block-local Ada names.
> 
> v1 was here:
> 
> https://sourceware.org/pipermail/gdb-patches/2020-November/173130.html
> 
> With some commentary here:
> 
> https://sourceware.org/pipermail/gdb-patches/2020-December/173778.html
> 
> This fixes the performance problem we found in v1.  Joel also found an
> additional problem, namely that multiple levels of nesting are
> possible.  This series handles this as well.

For the record, I reviewed those patches internally at AdaCore, and
for me, they looked good.

-- 
Joel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-13 13:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 16:24 [PATCH v2 0/2] Handle block-local names for Ada Tom Tromey
2020-12-10 16:24 ` [PATCH v2 1/2] Use exact match in get_var_value Tom Tromey
2020-12-10 16:24 ` [PATCH v2 2/2] Handle block-local names for Ada Tom Tromey
2020-12-13 13:58 ` [PATCH v2 0/2] " Joel Brobecker

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).