public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const
@ 2021-02-05 12:28 Tom de Vries
  2021-02-24  8:14 ` [PING][PATCH][gdb/symtab] " Tom de Vries
  2021-02-24 20:35 ` [PATCH][gdb/symtab] " Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Tom de Vries @ 2021-02-05 12:28 UTC (permalink / raw)
  To: gdb-patches

Hi,

With test-case gdb.cp/temargs.exp on target board \
unix/gdb:debug_flags=-gdwarf-5 I run into:
...
(gdb) info addr I^M
ERROR: GDB process no longer exists
GDB process exited with wait status 32286 exp19 0 0 CHILDKILLED SIGABRT SIGABRT
UNRESOLVED: gdb.cp/temargs.exp: test address of I in templ_m
...

This is a regression since commit 529908cbd0a "Remove DW_UNSND".

The problem is that this DW_AT_decl_file:
...
 <1><221>: Abbrev Number: 4 (DW_TAG_structure_type)
    <222>   DW_AT_name        : Base<double, 23, (& a_global), &S::f>
    <226>   DW_AT_byte_size   : 1
    <226>   DW_AT_decl_file   : 1
    <226>   DW_AT_decl_line   : 30
    <227>   DW_AT_sibling     : <0x299>
...
is not read by this code in new_symbol:
....
      attr = dwarf2_attr (die,
                          inlined_func ? DW_AT_call_file : DW_AT_decl_file,
                          cu);
      if (attr != nullptr && attr->form_is_unsigned ())
...
because DW_AT_decl_file has form DW_FORM_implicit_const:
...
   4      DW_TAG_structure_type    [has children]
    DW_AT_name         DW_FORM_strp
    DW_AT_byte_size    DW_FORM_implicit_const: 1
    DW_AT_decl_file    DW_FORM_implicit_const: 1
    DW_AT_decl_line    DW_FORM_data1
    DW_AT_sibling      DW_FORM_ref4
    DW_AT value: 0     DW_FORM value: 0
...
which is a signed LEB128, so attr->form_is_unsigned () returns false.

Fix this by introducing new functions is_nonnegative and as_nonnegative, and
use these instead of form_is_unsigned and as_unsigned.

Tested on x86_64-linux.

Any comments?

Thanks,
- Tom

[gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const

gdb/ChangeLog:

2021-02-05  Tom de Vries  <tdevries@suse.de>

	PR symtab/27336
	* dwarf2/attribute.c (attribute::form_is_signed): New function
	factored out of ...
	* dwarf2/attribute.h (attribute::as_signed): ... here.
	(attribute::is_nonnegative, attribute::as_nonnegative): New function.
	(attribute::form_is_signed): Declare.
	* dwarf2/read.c (new_symbol): Use is_nonnegative and as_nonnegative
	for DW_AT_decl_file.

---
 gdb/dwarf2/attribute.c |  8 ++++++++
 gdb/dwarf2/attribute.h | 27 ++++++++++++++++++++++++++-
 gdb/dwarf2/read.c      |  4 ++--
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index b4f188a096e..8c58f1bcd9f 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -189,6 +189,14 @@ attribute::form_is_unsigned () const
 
 /* See attribute.h.  */
 
+bool
+attribute::form_is_signed () const
+{
+  return form == DW_FORM_sdata || form == DW_FORM_implicit_const;
+}
+
+/* See attribute.h.  */
+
 bool
 attribute::form_requires_reprocessing () const
 {
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 56776d64ed3..b0b3e14cc68 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -70,7 +70,7 @@ struct attribute
      form.  */
   LONGEST as_signed () const
   {
-    gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
+    gdb_assert (form_is_signed ());
     return u.snd;
   }
 
@@ -92,6 +92,28 @@ struct attribute
     return u.unsnd;
   }
 
+  /* Return true if the value is nonnegative.  Requires that that
+     reprocessing not be needed.  */
+  bool is_nonnegative () const
+  {
+    if (form_is_unsigned ())
+      return true;
+    if (form_is_signed ())
+      return as_signed () >= (LONGEST)0;
+    return false;
+  }
+
+  /* Return the nonnegative value.  Requires that that reprocessing not be
+     needed.  */
+  ULONGEST as_nonnegative () const
+  {
+    if (form_is_unsigned ())
+      return as_unsigned ();
+    if (form_is_signed ())
+      return (ULONGEST)as_signed ();
+    gdb_assert (false);
+  }
+
   /* Return non-zero if ATTR's value is a section offset --- classes
      lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
      You may use the as_unsigned method to retrieve such offsets.
@@ -147,6 +169,9 @@ struct attribute
   /* Check if the attribute's form is an unsigned integer form.  */
   bool form_is_unsigned () const;
 
+  /* Check if the attribute's form is a signed integer form.  */
+  bool form_is_signed () const;
+
   /* Check if the attribute's form is a form that requires
      "reprocessing".  */
   bool form_requires_reprocessing () const;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 98189f7b566..424a0da3d6c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -22180,10 +22180,10 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       attr = dwarf2_attr (die,
 			  inlined_func ? DW_AT_call_file : DW_AT_decl_file,
 			  cu);
-      if (attr != nullptr && attr->form_is_unsigned ())
+      if (attr != nullptr && attr->is_nonnegative ())
 	{
 	  file_name_index file_index
-	    = (file_name_index) attr->as_unsigned ();
+	    = (file_name_index) attr->as_nonnegative ();
 	  struct file_entry *fe;
 
 	  if (cu->line_header != NULL)

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

* [PING][PATCH][gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const
  2021-02-05 12:28 [PATCH][gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const Tom de Vries
@ 2021-02-24  8:14 ` Tom de Vries
  2021-02-24 20:35 ` [PATCH][gdb/symtab] " Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2021-02-24  8:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On 2/5/21 1:28 PM, Tom de Vries wrote:
> Hi,
> 
> With test-case gdb.cp/temargs.exp on target board \
> unix/gdb:debug_flags=-gdwarf-5 I run into:
> ...
> (gdb) info addr I^M
> ERROR: GDB process no longer exists
> GDB process exited with wait status 32286 exp19 0 0 CHILDKILLED SIGABRT SIGABRT
> UNRESOLVED: gdb.cp/temargs.exp: test address of I in templ_m
> ...
> 
> This is a regression since commit 529908cbd0a "Remove DW_UNSND".
> 
> The problem is that this DW_AT_decl_file:
> ...
>  <1><221>: Abbrev Number: 4 (DW_TAG_structure_type)
>     <222>   DW_AT_name        : Base<double, 23, (& a_global), &S::f>
>     <226>   DW_AT_byte_size   : 1
>     <226>   DW_AT_decl_file   : 1
>     <226>   DW_AT_decl_line   : 30
>     <227>   DW_AT_sibling     : <0x299>
> ...
> is not read by this code in new_symbol:
> ....
>       attr = dwarf2_attr (die,
>                           inlined_func ? DW_AT_call_file : DW_AT_decl_file,
>                           cu);
>       if (attr != nullptr && attr->form_is_unsigned ())
> ...
> because DW_AT_decl_file has form DW_FORM_implicit_const:
> ...
>    4      DW_TAG_structure_type    [has children]
>     DW_AT_name         DW_FORM_strp
>     DW_AT_byte_size    DW_FORM_implicit_const: 1
>     DW_AT_decl_file    DW_FORM_implicit_const: 1
>     DW_AT_decl_line    DW_FORM_data1
>     DW_AT_sibling      DW_FORM_ref4
>     DW_AT value: 0     DW_FORM value: 0
> ...
> which is a signed LEB128, so attr->form_is_unsigned () returns false.
> 
> Fix this by introducing new functions is_nonnegative and as_nonnegative, and
> use these instead of form_is_unsigned and as_unsigned.
> 
> Tested on x86_64-linux.
> 
> Any comments?
> 

Ping.

Thanks,
- Tom

> [gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const
> 
> gdb/ChangeLog:
> 
> 2021-02-05  Tom de Vries  <tdevries@suse.de>
> 
> 	PR symtab/27336
> 	* dwarf2/attribute.c (attribute::form_is_signed): New function
> 	factored out of ...
> 	* dwarf2/attribute.h (attribute::as_signed): ... here.
> 	(attribute::is_nonnegative, attribute::as_nonnegative): New function.
> 	(attribute::form_is_signed): Declare.
> 	* dwarf2/read.c (new_symbol): Use is_nonnegative and as_nonnegative
> 	for DW_AT_decl_file.
> 
> ---
>  gdb/dwarf2/attribute.c |  8 ++++++++
>  gdb/dwarf2/attribute.h | 27 ++++++++++++++++++++++++++-
>  gdb/dwarf2/read.c      |  4 ++--
>  3 files changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
> index b4f188a096e..8c58f1bcd9f 100644
> --- a/gdb/dwarf2/attribute.c
> +++ b/gdb/dwarf2/attribute.c
> @@ -189,6 +189,14 @@ attribute::form_is_unsigned () const
>  
>  /* See attribute.h.  */
>  
> +bool
> +attribute::form_is_signed () const
> +{
> +  return form == DW_FORM_sdata || form == DW_FORM_implicit_const;
> +}
> +
> +/* See attribute.h.  */
> +
>  bool
>  attribute::form_requires_reprocessing () const
>  {
> diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
> index 56776d64ed3..b0b3e14cc68 100644
> --- a/gdb/dwarf2/attribute.h
> +++ b/gdb/dwarf2/attribute.h
> @@ -70,7 +70,7 @@ struct attribute
>       form.  */
>    LONGEST as_signed () const
>    {
> -    gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
> +    gdb_assert (form_is_signed ());
>      return u.snd;
>    }
>  
> @@ -92,6 +92,28 @@ struct attribute
>      return u.unsnd;
>    }
>  
> +  /* Return true if the value is nonnegative.  Requires that that
> +     reprocessing not be needed.  */
> +  bool is_nonnegative () const
> +  {
> +    if (form_is_unsigned ())
> +      return true;
> +    if (form_is_signed ())
> +      return as_signed () >= (LONGEST)0;
> +    return false;
> +  }
> +
> +  /* Return the nonnegative value.  Requires that that reprocessing not be
> +     needed.  */
> +  ULONGEST as_nonnegative () const
> +  {
> +    if (form_is_unsigned ())
> +      return as_unsigned ();
> +    if (form_is_signed ())
> +      return (ULONGEST)as_signed ();
> +    gdb_assert (false);
> +  }
> +
>    /* Return non-zero if ATTR's value is a section offset --- classes
>       lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
>       You may use the as_unsigned method to retrieve such offsets.
> @@ -147,6 +169,9 @@ struct attribute
>    /* Check if the attribute's form is an unsigned integer form.  */
>    bool form_is_unsigned () const;
>  
> +  /* Check if the attribute's form is a signed integer form.  */
> +  bool form_is_signed () const;
> +
>    /* Check if the attribute's form is a form that requires
>       "reprocessing".  */
>    bool form_requires_reprocessing () const;
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index 98189f7b566..424a0da3d6c 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -22180,10 +22180,10 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
>        attr = dwarf2_attr (die,
>  			  inlined_func ? DW_AT_call_file : DW_AT_decl_file,
>  			  cu);
> -      if (attr != nullptr && attr->form_is_unsigned ())
> +      if (attr != nullptr && attr->is_nonnegative ())
>  	{
>  	  file_name_index file_index
> -	    = (file_name_index) attr->as_unsigned ();
> +	    = (file_name_index) attr->as_nonnegative ();
>  	  struct file_entry *fe;
>  
>  	  if (cu->line_header != NULL)
> 

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

* Re: [PATCH][gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const
  2021-02-05 12:28 [PATCH][gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const Tom de Vries
  2021-02-24  8:14 ` [PING][PATCH][gdb/symtab] " Tom de Vries
@ 2021-02-24 20:35 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2021-02-24 20:35 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> 2021-02-05  Tom de Vries  <tdevries@suse.de>

Tom> 	PR symtab/27336
Tom> 	* dwarf2/attribute.c (attribute::form_is_signed): New function
Tom> 	factored out of ...
Tom> 	* dwarf2/attribute.h (attribute::as_signed): ... here.
Tom> 	(attribute::is_nonnegative, attribute::as_nonnegative): New function.
Tom> 	(attribute::form_is_signed): Declare.
Tom> 	* dwarf2/read.c (new_symbol): Use is_nonnegative and as_nonnegative
Tom> 	for DW_AT_decl_file.

Thank you for doing this.

Tom> +    if (form_is_signed ())
Tom> +      return as_signed () >= (LONGEST)0;

I don't think this cast is needed.

Otherwise this looks good to me.

Tom

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

end of thread, other threads:[~2021-02-24 20:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 12:28 [PATCH][gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const Tom de Vries
2021-02-24  8:14 ` [PING][PATCH][gdb/symtab] " Tom de Vries
2021-02-24 20:35 ` [PATCH][gdb/symtab] " 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).