public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/symtab] Fix too many symbols in gdbpy_lookup_static_symbols
@ 2023-08-26 10:07 Tom de Vries
  2023-09-06  9:03 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2023-08-26 10:07 UTC (permalink / raw)
  To: gdb-patches

When running test-case gdb.python/py-symbol.exp with target board
cc-with-dwz-m, we run into:
...
(gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
4^M
(gdb) FAIL: gdb.python/py-symbol.exp: \
  print (len (gdb.lookup_static_symbols ('rr')))
...
while with target board unix we have instead:
...
(gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
2^M
(gdb) PASS: gdb.python/py-symbol.exp: \
  print (len (gdb.lookup_static_symbols ('rr')))
...

The problem is that the loop in gdbpy_lookup_static_symbols loops over compunits
representing both CUs and PUs:
...
 	  for (compunit_symtab *cust : objfile->compunits ())
...

When doing a lookup on a PU, the user link is followed until we end up at a CU,
and the lookup is done in that CU.

In other words, when doing a lookup in the loop for a PU we duplicate the
lookup for a CU that is already handled by the loop.

Fix this by skipping PUs in the loop in gdb.lookup_static_symbols.

Tested on x86_64-linux.

PR symtab/25261
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25261
---
 gdb/python/py-symbol.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index ee863aa4df4..43a20c7a366 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -602,9 +602,12 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
 	{
 	  for (compunit_symtab *cust : objfile->compunits ())
 	    {
-	      const struct blockvector *bv;
+	      /* Skip included compunits to prevent including compunits from
+		 being searched twice.  */
+	      if (cust->user != nullptr)
+		continue;
 
-	      bv = cust->blockvector ();
+	      const struct blockvector *bv = cust->blockvector ();
 	      const struct block *block = bv->static_block ();
 
 	      if (block != nullptr)

base-commit: d2ac569f7b443aef7b2be2f0c80d8ab0d67b4292
-- 
2.35.3


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

* Re: [PATCH] [gdb/symtab] Fix too many symbols in gdbpy_lookup_static_symbols
  2023-08-26 10:07 [PATCH] [gdb/symtab] Fix too many symbols in gdbpy_lookup_static_symbols Tom de Vries
@ 2023-09-06  9:03 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2023-09-06  9:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On 8/26/23 12:07, Tom de Vries via Gdb-patches wrote:
> When running test-case gdb.python/py-symbol.exp with target board
> cc-with-dwz-m, we run into:
> ...
> (gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
> 4^M
> (gdb) FAIL: gdb.python/py-symbol.exp: \
>    print (len (gdb.lookup_static_symbols ('rr')))
> ...
> while with target board unix we have instead:
> ...
> (gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
> 2^M
> (gdb) PASS: gdb.python/py-symbol.exp: \
>    print (len (gdb.lookup_static_symbols ('rr')))
> ...
> 
> The problem is that the loop in gdbpy_lookup_static_symbols loops over compunits
> representing both CUs and PUs:
> ...
>   	  for (compunit_symtab *cust : objfile->compunits ())
> ...
> 
> When doing a lookup on a PU, the user link is followed until we end up at a CU,
> and the lookup is done in that CU.
> 
> In other words, when doing a lookup in the loop for a PU we duplicate the
> lookup for a CU that is already handled by the loop.
> 
> Fix this by skipping PUs in the loop in gdb.lookup_static_symbols.
> 

Given that:
- the approach of this patch is similar to what is done in commit
   7023b8d86c6 ("[gdb/symtab] Handle PU in iterate_over_some_symtabs"),
   and
- that patch was approved,
I've pushed this.

Thanks,
- Tom

> Tested on x86_64-linux.
> 
> PR symtab/25261
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25261
> ---
>   gdb/python/py-symbol.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
> index ee863aa4df4..43a20c7a366 100644
> --- a/gdb/python/py-symbol.c
> +++ b/gdb/python/py-symbol.c
> @@ -602,9 +602,12 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
>   	{
>   	  for (compunit_symtab *cust : objfile->compunits ())
>   	    {
> -	      const struct blockvector *bv;
> +	      /* Skip included compunits to prevent including compunits from
> +		 being searched twice.  */
> +	      if (cust->user != nullptr)
> +		continue;
>   
> -	      bv = cust->blockvector ();
> +	      const struct blockvector *bv = cust->blockvector ();
>   	      const struct block *block = bv->static_block ();
>   
>   	      if (block != nullptr)
> 
> base-commit: d2ac569f7b443aef7b2be2f0c80d8ab0d67b4292


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

end of thread, other threads:[~2023-09-06  9:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-26 10:07 [PATCH] [gdb/symtab] Fix too many symbols in gdbpy_lookup_static_symbols Tom de Vries
2023-09-06  9:03 ` Tom de Vries

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