Re: Issue in dwarf2/expr.c

Andreas Arnez via Gdb <[email protected]>
Newsgroups gmane.comp.gdb.devel
Organization IBM Deutschland Research & Development GmbH
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.