public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix Rust regression with -readnow
@ 2020-11-01  1:00 Tom Tromey
  2020-11-01 21:44 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2020-11-01  1:00 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

PR rust/26799 points out that a certain test case fails with -readnow.
This happens because, with -readnow, there are no partial symtabs; but
find_symbol_at_address requires these.

This patch fixes this problem by searching all of an objfile's
compunit symtabs if it does not have partial symbols.

Note that this test will still fail with .gdb_index.  I don't think
that is readily fixable.

gdb/ChangeLog
2020-10-31  Tom Tromey  <tom@tromey.com>

	PR rust/26799:
	* symtab.c (find_symbol_at_address): Search symtabs if no psymtabs
	exist.

gdb/testsuite/ChangeLog
2020-10-31  Tom Tromey  <tom@tromey.com>

	PR rust/26799:
	* gdb.rust/traits.exp: Remove kfails.
---
 gdb/ChangeLog                     |  6 ++++
 gdb/symtab.c                      | 59 +++++++++++++++++++++----------
 gdb/testsuite/ChangeLog           |  5 +++
 gdb/testsuite/gdb.rust/traits.exp |  6 ----
 4 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index b7aae1bed14..cff069730b3 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3024,30 +3024,53 @@ find_pc_compunit_symtab (CORE_ADDR pc)
 struct symbol *
 find_symbol_at_address (CORE_ADDR address)
 {
-  for (objfile *objfile : current_program_space->objfiles ())
+  /* A helper function to search a given symtab for a symbol matching
+     ADDR.  */
+  auto search_symtab = [] (compunit_symtab *symtab, CORE_ADDR addr) -> symbol *
     {
-      if (objfile->sf == NULL
-	  || objfile->sf->qf->find_compunit_symtab_by_address == NULL)
-	continue;
+      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (symtab);
 
-      struct compunit_symtab *symtab
-	= objfile->sf->qf->find_compunit_symtab_by_address (objfile, address);
-      if (symtab != NULL)
+      for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
 	{
-	  const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (symtab);
+	  const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
+	  struct block_iterator iter;
+	  struct symbol *sym;
 
-	  for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
+	  ALL_BLOCK_SYMBOLS (b, iter, sym)
 	    {
-	      const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
-	      struct block_iterator iter;
-	      struct symbol *sym;
+	      if (SYMBOL_CLASS (sym) == LOC_STATIC
+		  && SYMBOL_VALUE_ADDRESS (sym) == addr)
+		return sym;
+	    }
+	}
+      return nullptr;
+    };
 
-	      ALL_BLOCK_SYMBOLS (b, iter, sym)
-		{
-		  if (SYMBOL_CLASS (sym) == LOC_STATIC
-		      && SYMBOL_VALUE_ADDRESS (sym) == address)
-		    return sym;
-		}
+  for (objfile *objfile : current_program_space->objfiles ())
+    {
+      /* If this objfile doesn't have "quick" functions, then it may
+	 have been read with -readnow, in which case we need to search
+	 the symtabs directly.  */
+      if (objfile->sf == NULL
+	  || objfile->sf->qf->find_compunit_symtab_by_address == NULL)
+	{
+	  for (compunit_symtab *symtab : objfile->compunits ())
+	    {
+	      struct symbol *sym = search_symtab (symtab, address);
+	      if (sym != nullptr)
+		return sym;
+	    }
+	}
+      else
+	{
+	  struct compunit_symtab *symtab
+	    = objfile->sf->qf->find_compunit_symtab_by_address (objfile,
+								address);
+	  if (symtab != NULL)
+	    {
+	      struct symbol *sym = search_symtab (symtab, address);
+	      if (sym != nullptr)
+		return sym;
 	    }
 	}
     }
diff --git a/gdb/testsuite/gdb.rust/traits.exp b/gdb/testsuite/gdb.rust/traits.exp
index d237b928720..73a75b08e54 100644
--- a/gdb/testsuite/gdb.rust/traits.exp
+++ b/gdb/testsuite/gdb.rust/traits.exp
@@ -45,11 +45,5 @@ if {![runto ${srcfile}:$line]} {
 
 set readnow_p [readnow $binfile]
 
-if { $readnow_p } {
-    setup_kfail "gdb/26799" *-*-*
-}
 gdb_test "print *td" " = 23.5"
-if { $readnow_p } {
-    setup_kfail "gdb/26799" *-*-*
-}
 gdb_test "print *tu" " = 23"
-- 
2.17.2


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

* Re: [PATCH] Fix Rust regression with -readnow
  2020-11-01  1:00 [PATCH] Fix Rust regression with -readnow Tom Tromey
@ 2020-11-01 21:44 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2020-11-01 21:44 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 11/1/20 2:00 AM, Tom Tromey wrote:
> PR rust/26799 points out that a certain test case fails with -readnow.
> This happens because, with -readnow, there are no partial symtabs; but
> find_symbol_at_address requires these.
> 
> This patch fixes this problem by searching all of an objfile's
> compunit symtabs if it does not have partial symbols.
> 

Hi,

I've tested this both with native and readnow, and both test results
look good.

> Note that this test will still fail with .gdb_index.  I don't think
> that is readily fixable.
> 

Doesn't fail for me with either cc-with-gdb-index or cc-with-debug-names
target boards.

FWIW, patch LGTM.

Thanks,
- Tom

> gdb/ChangeLog
> 2020-10-31  Tom Tromey  <tom@tromey.com>
> 
> 	PR rust/26799:
> 	* symtab.c (find_symbol_at_address): Search symtabs if no psymtabs
> 	exist.
> 
> gdb/testsuite/ChangeLog
> 2020-10-31  Tom Tromey  <tom@tromey.com>
> 
> 	PR rust/26799:
> 	* gdb.rust/traits.exp: Remove kfails.
> ---
>  gdb/ChangeLog                     |  6 ++++
>  gdb/symtab.c                      | 59 +++++++++++++++++++++----------
>  gdb/testsuite/ChangeLog           |  5 +++
>  gdb/testsuite/gdb.rust/traits.exp |  6 ----
>  4 files changed, 52 insertions(+), 24 deletions(-)
> 
> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index b7aae1bed14..cff069730b3 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -3024,30 +3024,53 @@ find_pc_compunit_symtab (CORE_ADDR pc)
>  struct symbol *
>  find_symbol_at_address (CORE_ADDR address)
>  {
> -  for (objfile *objfile : current_program_space->objfiles ())
> +  /* A helper function to search a given symtab for a symbol matching
> +     ADDR.  */
> +  auto search_symtab = [] (compunit_symtab *symtab, CORE_ADDR addr) -> symbol *
>      {
> -      if (objfile->sf == NULL
> -	  || objfile->sf->qf->find_compunit_symtab_by_address == NULL)
> -	continue;
> +      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (symtab);
>  
> -      struct compunit_symtab *symtab
> -	= objfile->sf->qf->find_compunit_symtab_by_address (objfile, address);
> -      if (symtab != NULL)
> +      for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
>  	{
> -	  const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (symtab);
> +	  const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
> +	  struct block_iterator iter;
> +	  struct symbol *sym;
>  
> -	  for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
> +	  ALL_BLOCK_SYMBOLS (b, iter, sym)
>  	    {
> -	      const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
> -	      struct block_iterator iter;
> -	      struct symbol *sym;
> +	      if (SYMBOL_CLASS (sym) == LOC_STATIC
> +		  && SYMBOL_VALUE_ADDRESS (sym) == addr)
> +		return sym;
> +	    }
> +	}
> +      return nullptr;
> +    };
>  
> -	      ALL_BLOCK_SYMBOLS (b, iter, sym)
> -		{
> -		  if (SYMBOL_CLASS (sym) == LOC_STATIC
> -		      && SYMBOL_VALUE_ADDRESS (sym) == address)
> -		    return sym;
> -		}
> +  for (objfile *objfile : current_program_space->objfiles ())
> +    {
> +      /* If this objfile doesn't have "quick" functions, then it may
> +	 have been read with -readnow, in which case we need to search
> +	 the symtabs directly.  */
> +      if (objfile->sf == NULL
> +	  || objfile->sf->qf->find_compunit_symtab_by_address == NULL)
> +	{
> +	  for (compunit_symtab *symtab : objfile->compunits ())
> +	    {
> +	      struct symbol *sym = search_symtab (symtab, address);
> +	      if (sym != nullptr)
> +		return sym;
> +	    }
> +	}
> +      else
> +	{
> +	  struct compunit_symtab *symtab
> +	    = objfile->sf->qf->find_compunit_symtab_by_address (objfile,
> +								address);
> +	  if (symtab != NULL)
> +	    {
> +	      struct symbol *sym = search_symtab (symtab, address);
> +	      if (sym != nullptr)
> +		return sym;
>  	    }
>  	}
>      }
> diff --git a/gdb/testsuite/gdb.rust/traits.exp b/gdb/testsuite/gdb.rust/traits.exp
> index d237b928720..73a75b08e54 100644
> --- a/gdb/testsuite/gdb.rust/traits.exp
> +++ b/gdb/testsuite/gdb.rust/traits.exp
> @@ -45,11 +45,5 @@ if {![runto ${srcfile}:$line]} {
>  
>  set readnow_p [readnow $binfile]
>  
> -if { $readnow_p } {
> -    setup_kfail "gdb/26799" *-*-*
> -}
>  gdb_test "print *td" " = 23.5"
> -if { $readnow_p } {
> -    setup_kfail "gdb/26799" *-*-*
> -}
>  gdb_test "print *tu" " = 23"
> 

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

end of thread, other threads:[~2020-11-01 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01  1:00 [PATCH] Fix Rust regression with -readnow Tom Tromey
2020-11-01 21:44 ` 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).