public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix incorrect .gdb_index with new DWARF scanner
@ 2022-10-17 19:41 Tom Tromey
  2022-10-18 13:41 ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2022-10-17 19:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

PR symtab/29694 points out a regression caused by the new DWARF
scanner when the cc-with-gdb-index target board is used.

What happens here is that an older version of gdb will make an index
describing the "A" type as:

[737] A: 1 [global, type]

whereas the new gdb says:

[1008] A: 0 [global, type]

Here the old one is correct because the A in CU 0 is just a
declaration without a size:

 <1><45>: Abbrev Number: 10 (DW_TAG_structure_type)
    <46>   DW_AT_name        : A
    <48>   DW_AT_declaration : 1
    <48>   DW_AT_sibling     : <0x6d>

This patch fixes the problem by introducing the idea of a "type
declaration".  I think gdb still needs to recurse into these types,
searching for methods, but by marking the type itself as a
declaration, gdb can skip this type during lookups and when writing
the index.

Regression tested on x86-64 using the cc-with-gdb-index board.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29694
---
 gdb/dwarf2/cooked-index.h | 15 +++++++++++++++
 gdb/dwarf2/index-write.c  |  5 +++++
 gdb/dwarf2/read.c         | 22 ++++++++++++++--------
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index f3c26480a81..2ea32781be5 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -48,6 +48,9 @@ enum cooked_index_flag_enum : unsigned char
   IS_ENUM_CLASS = 4,
   /* True if this entry uses the linkage name.  */
   IS_LINKAGE = 8,
+  /* True if this entry is just for the declaration of a type, not the
+     definition.  */
+  IS_TYPE_DECLARATION = 16,
 };
 DEF_ENUM_FLAGS_TYPE (enum cooked_index_flag_enum, cooked_index_flag);
 
@@ -76,6 +79,10 @@ struct cooked_index_entry : public allocate_on_obstack
   /* Return true if this entry matches SEARCH_FLAGS.  */
   bool matches (block_search_flags search_flags) const
   {
+    /* Just reject type declarations.  */
+    if ((flags & IS_TYPE_DECLARATION) != 0)
+      return false;
+
     if ((search_flags & SEARCH_STATIC_BLOCK) != 0
 	&& (flags & IS_STATIC) != 0)
       return true;
@@ -88,6 +95,10 @@ struct cooked_index_entry : public allocate_on_obstack
   /* Return true if this entry matches DOMAIN.  */
   bool matches (domain_enum domain) const
   {
+    /* Just reject type declarations.  */
+    if ((flags & IS_TYPE_DECLARATION) != 0)
+      return false;
+
     switch (domain)
       {
       case LABEL_DOMAIN:
@@ -106,6 +117,10 @@ struct cooked_index_entry : public allocate_on_obstack
   /* Return true if this entry matches KIND.  */
   bool matches (enum search_domain kind) const
   {
+    /* Just reject type declarations.  */
+    if ((flags & IS_TYPE_DECLARATION) != 0)
+      return false;
+
     switch (kind)
       {
       case VARIABLES_DOMAIN:
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index f592734addc..3d215a6307b 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1167,6 +1167,11 @@ write_cooked_index (cooked_index_vector *table,
 	     be redundant are rare and not worth supporting.  */
 	  continue;
 	}
+      else if ((entry->flags & IS_TYPE_DECLARATION) != 0)
+	{
+	  /* Don't add type declarations to the index.  */
+	  continue;
+	}
 
       gdb_index_symbol_kind kind;
       if (entry->tag == DW_TAG_subprogram)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index b5efcb3cc09..e849f62576d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18192,14 +18192,20 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
      that is ok.  Similarly, we allow an external variable without a
      location; those are resolved via minimal symbols.  */
   if (is_declaration && !for_specification
-      && !(abbrev->tag == DW_TAG_variable && (*flags & IS_STATIC) == 0)
-      && !((abbrev->tag == DW_TAG_class_type
-	    || abbrev->tag == DW_TAG_structure_type
-	    || abbrev->tag == DW_TAG_union_type)
-	   && abbrev->has_children))
-    {
-      *linkage_name = nullptr;
-      *name = nullptr;
+      && !(abbrev->tag == DW_TAG_variable && (*flags & IS_STATIC) == 0))
+    {
+      /* We always want to recurse into some types, but we may not
+	 want to treat them as definitions.  */
+      if ((abbrev->tag == DW_TAG_class_type
+	   || abbrev->tag == DW_TAG_structure_type
+	   || abbrev->tag == DW_TAG_union_type)
+	  && abbrev->has_children)
+	*flags |= IS_TYPE_DECLARATION;
+      else
+	{
+	  *linkage_name = nullptr;
+	  *name = nullptr;
+	}
     }
   else if ((*name == nullptr
 	    || (*linkage_name == nullptr
-- 
2.34.3


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

* Re: [PATCH] Fix incorrect .gdb_index with new DWARF scanner
  2022-10-17 19:41 [PATCH] Fix incorrect .gdb_index with new DWARF scanner Tom Tromey
@ 2022-10-18 13:41 ` Tom de Vries
  2022-10-21 16:13   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2022-10-18 13:41 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 10/17/22 21:41, Tom Tromey via Gdb-patches wrote:
> PR symtab/29694 points out a regression caused by the new DWARF
> scanner when the cc-with-gdb-index target board is used.
> 
> What happens here is that an older version of gdb will make an index
> describing the "A" type as:
> 
> [737] A: 1 [global, type]
> 
> whereas the new gdb says:
> 
> [1008] A: 0 [global, type]
> 
> Here the old one is correct because the A in CU 0 is just a
> declaration without a size:
> 
>   <1><45>: Abbrev Number: 10 (DW_TAG_structure_type)
>      <46>   DW_AT_name        : A
>      <48>   DW_AT_declaration : 1
>      <48>   DW_AT_sibling     : <0x6d>
> 
> This patch fixes the problem by introducing the idea of a "type
> declaration".  I think gdb still needs to recurse into these types,
> searching for methods, but by marking the type itself as a
> declaration, gdb can skip this type during lookups and when writing
> the index.
> 
> Regression tested on x86-64 using the cc-with-gdb-index board.
> 

Regression tested on openSUSE Tumbleweed x86_64 with native and 
cc-with-gdb-index board, results looks good.

Patch LGTM.

Thanks,
- Tom

> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29694
> ---
>   gdb/dwarf2/cooked-index.h | 15 +++++++++++++++
>   gdb/dwarf2/index-write.c  |  5 +++++
>   gdb/dwarf2/read.c         | 22 ++++++++++++++--------
>   3 files changed, 34 insertions(+), 8 deletions(-)
> 
> diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
> index f3c26480a81..2ea32781be5 100644
> --- a/gdb/dwarf2/cooked-index.h
> +++ b/gdb/dwarf2/cooked-index.h
> @@ -48,6 +48,9 @@ enum cooked_index_flag_enum : unsigned char
>     IS_ENUM_CLASS = 4,
>     /* True if this entry uses the linkage name.  */
>     IS_LINKAGE = 8,
> +  /* True if this entry is just for the declaration of a type, not the
> +     definition.  */
> +  IS_TYPE_DECLARATION = 16,
>   };
>   DEF_ENUM_FLAGS_TYPE (enum cooked_index_flag_enum, cooked_index_flag);
>   
> @@ -76,6 +79,10 @@ struct cooked_index_entry : public allocate_on_obstack
>     /* Return true if this entry matches SEARCH_FLAGS.  */
>     bool matches (block_search_flags search_flags) const
>     {
> +    /* Just reject type declarations.  */
> +    if ((flags & IS_TYPE_DECLARATION) != 0)
> +      return false;
> +
>       if ((search_flags & SEARCH_STATIC_BLOCK) != 0
>   	&& (flags & IS_STATIC) != 0)
>         return true;
> @@ -88,6 +95,10 @@ struct cooked_index_entry : public allocate_on_obstack
>     /* Return true if this entry matches DOMAIN.  */
>     bool matches (domain_enum domain) const
>     {
> +    /* Just reject type declarations.  */
> +    if ((flags & IS_TYPE_DECLARATION) != 0)
> +      return false;
> +
>       switch (domain)
>         {
>         case LABEL_DOMAIN:
> @@ -106,6 +117,10 @@ struct cooked_index_entry : public allocate_on_obstack
>     /* Return true if this entry matches KIND.  */
>     bool matches (enum search_domain kind) const
>     {
> +    /* Just reject type declarations.  */
> +    if ((flags & IS_TYPE_DECLARATION) != 0)
> +      return false;
> +
>       switch (kind)
>         {
>         case VARIABLES_DOMAIN:
> diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
> index f592734addc..3d215a6307b 100644
> --- a/gdb/dwarf2/index-write.c
> +++ b/gdb/dwarf2/index-write.c
> @@ -1167,6 +1167,11 @@ write_cooked_index (cooked_index_vector *table,
>   	     be redundant are rare and not worth supporting.  */
>   	  continue;
>   	}
> +      else if ((entry->flags & IS_TYPE_DECLARATION) != 0)
> +	{
> +	  /* Don't add type declarations to the index.  */
> +	  continue;
> +	}
>   
>         gdb_index_symbol_kind kind;
>         if (entry->tag == DW_TAG_subprogram)
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index b5efcb3cc09..e849f62576d 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -18192,14 +18192,20 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
>        that is ok.  Similarly, we allow an external variable without a
>        location; those are resolved via minimal symbols.  */
>     if (is_declaration && !for_specification
> -      && !(abbrev->tag == DW_TAG_variable && (*flags & IS_STATIC) == 0)
> -      && !((abbrev->tag == DW_TAG_class_type
> -	    || abbrev->tag == DW_TAG_structure_type
> -	    || abbrev->tag == DW_TAG_union_type)
> -	   && abbrev->has_children))
> -    {
> -      *linkage_name = nullptr;
> -      *name = nullptr;
> +      && !(abbrev->tag == DW_TAG_variable && (*flags & IS_STATIC) == 0))
> +    {
> +      /* We always want to recurse into some types, but we may not
> +	 want to treat them as definitions.  */
> +      if ((abbrev->tag == DW_TAG_class_type
> +	   || abbrev->tag == DW_TAG_structure_type
> +	   || abbrev->tag == DW_TAG_union_type)
> +	  && abbrev->has_children)
> +	*flags |= IS_TYPE_DECLARATION;
> +      else
> +	{
> +	  *linkage_name = nullptr;
> +	  *name = nullptr;
> +	}
>       }
>     else if ((*name == nullptr
>   	    || (*linkage_name == nullptr

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

* Re: [PATCH] Fix incorrect .gdb_index with new DWARF scanner
  2022-10-18 13:41 ` Tom de Vries
@ 2022-10-21 16:13   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2022-10-21 16:13 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom Tromey, Tom de Vries

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

>> PR symtab/29694 points out a regression caused by the new DWARF
>> scanner when the cc-with-gdb-index target board is used.
[...]

Tom> Regression tested on openSUSE Tumbleweed x86_64 with native and
Tom> cc-with-gdb-index board, results looks good.

Tom> Patch LGTM.

Thank you.  I'm going to check it in.

There's still one open regression for the new DWARF reader.  I haven't
fully investigated it yet.

(There's also the TSan bug(s), but on my machine TSan reports a lot of
obviously untrue things, like captured_main being called from a signal
handler.  So I haven't really looked at this at all.)

Tom

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

end of thread, other threads:[~2022-10-21 16:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-17 19:41 [PATCH] Fix incorrect .gdb_index with new DWARF scanner Tom Tromey
2022-10-18 13:41 ` Tom de Vries
2022-10-21 16:13   ` Tom Tromey

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