public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Issue in dwarf2/expr.c
@ 2022-04-13 16:57 Rohr, Stephan
  2022-04-14 13:51 ` Andreas Arnez
  0 siblings, 1 reply; 4+ messages in thread
From: Rohr, Stephan @ 2022-04-13 16:57 UTC (permalink / raw)
  To: gdb

Hi all,

I came across a bug in dwarf2/expr.c:177 in function  rw_pieced_value. when reading a pieced value described by DW_OP_piece or DW_OP_bit_piece.

      if (value_type (v) != value_enclosing_type (v))
                internal_error (__FILE__, __LINE__,
                                                _("Should not be able to create a lazy value with "
                                                  "an enclosing type"));

This check can easily be triggered when casting a variable with location described by DW_OP_piece or DW_OP_bit_piece.

A minimal reproducer can be found in gdb/testsuite/gdb.dwarf2/shortpiece.exp, e.g. casting s1 to an array type triggers the error

p (short []) s1

I currently struggle to understand the reasoning for this check. I could think of changing this to

if (TYPE_LENGTH(value_type (v)) > TYPE_LENGTH( value_enclosing_type (v)))
to support the cast operation.

But in general, I'm not sure why this check is needed at all.

I appreciate your feedback.


Best
stephan


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

* Re: Issue in dwarf2/expr.c
  2022-04-13 16:57 Issue in dwarf2/expr.c Rohr, Stephan
@ 2022-04-14 13:51 ` Andreas Arnez
  2022-04-15 20:24   ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Arnez @ 2022-04-14 13:51 UTC (permalink / raw)
  To: Rohr, Stephan via Gdb; +Cc: Rohr, Stephan, Tom Tromey

On Wed, Apr 13 2022, Rohr, Stephan via Gdb wrote:

> Hi all,
>
> I came across a bug in dwarf2/expr.c:177 in function  rw_pieced_value. when reading a pieced value described by DW_OP_piece or DW_OP_bit_piece.
>
>       if (value_type (v) != value_enclosing_type (v))
>                 internal_error (__FILE__, __LINE__,
>                                                 _("Should not be able to create a lazy value with "
>                                                   "an enclosing type"));

Since I did some work on this function in the past, I just looked where
this check comes from, and it turns out that it was introduced in 2010
by Tom Tromey with commit afd74c5ff76010405caddd2834be4a0178fa93dd --

gdb
	* dwarf2loc.c (read_pieced_value): Work properly when 'v' has an
	offset.
	(write_pieced_value): Likewise.

Perhaps Tom still remembers the rationale?

>
> This check can easily be triggered when casting a variable with location described by DW_OP_piece or DW_OP_bit_piece.
>
> A minimal reproducer can be found in gdb/testsuite/gdb.dwarf2/shortpiece.exp, e.g. casting s1 to an array type triggers the error
>
> p (short []) s1
>
> I currently struggle to understand the reasoning for this check. I could think of changing this to
>
> if (TYPE_LENGTH(value_type (v)) > TYPE_LENGTH( value_enclosing_type (v)))
> to support the cast operation.
>
> But in general, I'm not sure why this check is needed at all.
>
> I appreciate your feedback.
>
>
> Best
> stephan

--
Andreas

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

* Re: Issue in dwarf2/expr.c
  2022-04-14 13:51 ` Andreas Arnez
@ 2022-04-15 20:24   ` Tom Tromey
  2022-04-19  6:28     ` Rohr, Stephan
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2022-04-15 20:24 UTC (permalink / raw)
  To: Andreas Arnez; +Cc: Rohr, Stephan via Gdb, Rohr, Stephan, Tom Tromey

>> I came across a bug in dwarf2/expr.c:177 in function  rw_pieced_value. when reading a pieced value described by DW_OP_piece or DW_OP_bit_piece.
>> 
>> if (value_type (v) != value_enclosing_type (v))
>> internal_error (__FILE__, __LINE__,
>> _("Should not be able to create a lazy value with "
>> "an enclosing type"));

> Since I did some work on this function in the past, I just looked where
> this check comes from, and it turns out that it was introduced in 2010
> by Tom Tromey with commit afd74c5ff76010405caddd2834be4a0178fa93dd --

> gdb
> 	* dwarf2loc.c (read_pieced_value): Work properly when 'v' has an
> 	offset.
> 	(write_pieced_value): Likewise.

> Perhaps Tom still remembers the rationale?

I don't remember, sorry.
It's possible I assumed that it should be impossible to create a value
with an enclosing type without un-lazying it.

Removing the assertion seems fine but it's important to make sure the
result works correctly.  An enclosing type normally means that the data
representing the 'type' is at some offset in the contents, but it seems
to me that rw_pieced_value may not handle this case.

Tom

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

* RE: Issue in dwarf2/expr.c
  2022-04-15 20:24   ` Tom Tromey
@ 2022-04-19  6:28     ` Rohr, Stephan
  0 siblings, 0 replies; 4+ messages in thread
From: Rohr, Stephan @ 2022-04-19  6:28 UTC (permalink / raw)
  To: Tom Tromey, Andreas Arnez; +Cc: Rohr, Stephan via Gdb

Hi Tom,

Thanks for your feedback. 

The 'embedded_offset' is considered in the ' value_contents_raw (v)' function call whereas the 'offset' is handled in 'rw_pieced_value'. So from my understanding it should work as expected. I will check for regressions and submit a patch.

Best
stephan

-----Original Message-----
From: Tom Tromey <tom@tromey.com> 
Sent: Friday, April 15, 2022 10:25 PM
To: Andreas Arnez <arnez@linux.ibm.com>
Cc: Rohr, Stephan via Gdb <gdb@sourceware.org>; Rohr, Stephan <stephan.rohr@intel.com>; Tom Tromey <tom@tromey.com>
Subject: Re: Issue in dwarf2/expr.c

>> I came across a bug in dwarf2/expr.c:177 in function  rw_pieced_value. when reading a pieced value described by DW_OP_piece or DW_OP_bit_piece.
>> 
>> if (value_type (v) != value_enclosing_type (v)) internal_error 
>> (__FILE__, __LINE__, _("Should not be able to create a lazy value 
>> with "
>> "an enclosing type"));

> Since I did some work on this function in the past, I just looked 
> where this check comes from, and it turns out that it was introduced 
> in 2010 by Tom Tromey with commit 
> afd74c5ff76010405caddd2834be4a0178fa93dd --

> gdb
> 	* dwarf2loc.c (read_pieced_value): Work properly when 'v' has an
> 	offset.
> 	(write_pieced_value): Likewise.

> Perhaps Tom still remembers the rationale?

I don't remember, sorry.
It's possible I assumed that it should be impossible to create a value with an enclosing type without un-lazying it.

Removing the assertion seems fine but it's important to make sure the result works correctly.  An enclosing type normally means that the data representing the 'type' is at some offset in the contents, but it seems to me that rw_pieced_value may not handle this case.

Tom

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

end of thread, other threads:[~2022-04-19  6:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 16:57 Issue in dwarf2/expr.c Rohr, Stephan
2022-04-14 13:51 ` Andreas Arnez
2022-04-15 20:24   ` Tom Tromey
2022-04-19  6:28     ` Rohr, Stephan

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