public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* GDB | DWARF expression | Extracting a range of bits from an 'xmm' register
@ 2021-05-21  8:57 vaibhav kurhe
  2021-05-21 14:03 ` Andrew Burgess
  0 siblings, 1 reply; 6+ messages in thread
From: vaibhav kurhe @ 2021-05-21  8:57 UTC (permalink / raw)
  To: gdb

Hello all,
For a use case, I am trying to build a DWARF expression which represents
the value of an arbitrary range of bits (e.g. 96-127 bits) in an *128-bit
xmm register* to be used as a *location attribute value* for a variable DIE.
I am using GDB to consume the debug info and test it.

Following is the expression I started with to test out a shift operation on
an 128-bit xmm0 register using Typed DWARF stack :-

*"DW_OP_GNU_regval_type: 21 (xmm0) <0x30>; DW_OP_GNU_const_type: <0x30>  16
byte block: 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; DW_OP_shl;
DW_OP_stack_value"*
But, while testing it in GDB, I got an error :-
*"That operation is not available on integers of more than 8 bytes."*

Could you please provide any suggestions/pointers on this? Am I missing
something?

Please let me know, if you need any additional info.

Thanks & Regards,
Vaibhav

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

* Re: GDB | DWARF expression | Extracting a range of bits from an 'xmm' register
  2021-05-21  8:57 GDB | DWARF expression | Extracting a range of bits from an 'xmm' register vaibhav kurhe
@ 2021-05-21 14:03 ` Andrew Burgess
  2021-05-21 16:02   ` Zaric, Zoran (Zare)
  2021-05-21 20:37   ` vaibhav kurhe
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Burgess @ 2021-05-21 14:03 UTC (permalink / raw)
  To: vaibhav kurhe; +Cc: gdb

* vaibhav kurhe via Gdb <gdb@sourceware.org> [2021-05-21 14:27:15 +0530]:

> Hello all,
> For a use case, I am trying to build a DWARF expression which represents
> the value of an arbitrary range of bits (e.g. 96-127 bits) in an *128-bit
> xmm register* to be used as a *location attribute value* for a variable DIE.
> I am using GDB to consume the debug info and test it.
> 
> Following is the expression I started with to test out a shift operation on
> an 128-bit xmm0 register using Typed DWARF stack :-
> 
> *"DW_OP_GNU_regval_type: 21 (xmm0) <0x30>; DW_OP_GNU_const_type: <0x30>  16
> byte block: 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; DW_OP_shl;

I'm probably just not understanding correctly, but I'm confused by the
use of DW_OP_GNU_const_type.  Isn't this providing the number of bits
to shift?  I'd have expected something like 'DW_OP_const1u 96'.

Thanks,
Andrew

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

* Re: Re: GDB | DWARF expression | Extracting a range of bits from an 'xmm' register
  2021-05-21 14:03 ` Andrew Burgess
@ 2021-05-21 16:02   ` Zaric, Zoran (Zare)
  2021-05-21 21:09     ` vaibhav kurhe
  2021-05-21 20:37   ` vaibhav kurhe
  1 sibling, 1 reply; 6+ messages in thread
From: Zaric, Zoran (Zare) @ 2021-05-21 16:02 UTC (permalink / raw)
  To: gdb

On 5/21/21 3:03 PM, Andrew Burgess wrote:
> * vaibhav kurhe via Gdb <gdb@sourceware.org> [2021-05-21 14:27:15 +0530]:
> 
>> Hello all,
>> For a use case, I am trying to build a DWARF expression which represents
>> the value of an arbitrary range of bits (e.g. 96-127 bits) in an *128-bit
>> xmm register* to be used as a *location attribute value* for a variable DIE.
>> I am using GDB to consume the debug info and test it.
>>
>> Following is the expression I started with to test out a shift operation on
>> an 128-bit xmm0 register using Typed DWARF stack :-
>>
>> *"DW_OP_GNU_regval_type: 21 (xmm0) <0x30>; DW_OP_GNU_const_type: <0x30>  16
>> byte block: 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; DW_OP_shl;
> 
> I'm probably just not understanding correctly, but I'm confused by the
> use of DW_OP_GNU_const_type.  Isn't this providing the number of bits
> to shift?  I'd have expected something like 'DW_OP_const1u 96'.
> 
> Thanks,
> Andrew
> 

Hi Vaibhav,

Maybe I am missing something, but what is the end goal that you are 
trying to accomplish?

The way how you formed your expression, you can only get a read only 
stack value location description.

Why not use the DW_OP_bit_piece with your register being the only piece 
inside of it and then use that as your end location description?

Thanks,
Zoran

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

* Re: GDB | DWARF expression | Extracting a range of bits from an 'xmm' register
  2021-05-21 14:03 ` Andrew Burgess
  2021-05-21 16:02   ` Zaric, Zoran (Zare)
@ 2021-05-21 20:37   ` vaibhav kurhe
  1 sibling, 0 replies; 6+ messages in thread
From: vaibhav kurhe @ 2021-05-21 20:37 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb

On Fri, May 21, 2021 at 7:33 PM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
>
> * vaibhav kurhe via Gdb <gdb@sourceware.org> [2021-05-21 14:27:15 +0530]:
>
> > Hello all,
> > For a use case, I am trying to build a DWARF expression which represents
> > the value of an arbitrary range of bits (e.g. 96-127 bits) in an *128-bit
> > xmm register* to be used as a *location attri
bute value* for a variable DIE.
> > I am using GDB to consume the debug info and test it.
> >
> > Following is the expression I started with to test out a shift operation on
> > an 128-bit xmm0 register using Typed DWARF stack :-
> >
> > *"DW_OP_GNU_regval_type: 21 (xmm0) <0x30>; DW_OP_GNU_const_type: <0x30>  16
> > byte block: 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; DW_OP_shl;
>
> I'm probably just not understanding correctly, but I'm confused by the
> use of DW_OP_GNU_const_type.  Isn't this providing the number of bits
> to shift?  I'd have expected something like 'DW_OP_const1u 96'.
>
> Thanks,
> Andrew

Hi Andrew,
Thanks for the reply!

Yes, the second operand to DW_OP_shl is indeed the number of bits to
shift. But, I saw that the DWARF5 standard mentions that both the
operands should be of the same type.
So, in this case, as the 1st operand is typed (which points to a DIE
for the base type), I think the 2nd operand also has to be typed and
hence used the operation DW_OP_const_type.

Regards,
Vaibhav

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

* Re: Re: GDB | DWARF expression | Extracting a range of bits from an 'xmm' register
  2021-05-21 16:02   ` Zaric, Zoran (Zare)
@ 2021-05-21 21:09     ` vaibhav kurhe
  2021-05-24 10:00       ` Zaric, Zoran (Zare)
  0 siblings, 1 reply; 6+ messages in thread
From: vaibhav kurhe @ 2021-05-21 21:09 UTC (permalink / raw)
  To: Zaric, Zoran (Zare); +Cc: gdb

On Fri, May 21, 2021 at 10:36 PM Zaric, Zoran (Zare) via Gdb
<gdb@sourceware.org> wrote:
>
> On 5/21/21 3:03 PM, Andrew Burgess wrote:
> > * vaibhav kurhe via Gdb <gdb@sourceware.org> [2021-05-21 14:27:15 +0530]:
> >
> >> Hello all,
> >> For a use case, I am trying to build a DWARF expression which represents
> >> the value of an arbitrary range of bits (e.g. 96-127 bits) in an *128-bit
> >> xmm register* to be used as a *location attribute value* for a variable DIE.
> >> I am using GDB to consume the debug info and test it.
> >>
> >> Following is the expression I started with to test out a shift operation on
> >> an 128-bit xmm0 register using Typed DWARF stack :-
> >>
> >> *"DW_OP_GNU_regval_type: 21 (xmm0) <0x30>; DW_OP_GNU_const_type: <0x30>  16
> >> byte block: 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; DW_OP_shl;
> >
> > I'm probably just not understanding correctly, but I'm confused by the
> > use of DW_OP_GNU_const_type.  Isn't this providing the number of bits
> > to shift?  I'd have expected something like 'DW_OP_const1u 96'.
> >
> > Thanks,
> > Andrew
> >
>
> Hi Vaibhav,
>
> Maybe I am missing something, but what is the end goal that you are
> trying to accomplish?
>
> The way how you formed your expression, you can only get a read only
> stack value location description.
>
> Why not use the DW_OP_bit_piece with your register being the only piece
> inside of it and then use that as your end location description?
>
> Thanks,
> Zoran

Hi Zoran,
Thanks for the reply!

Actually I am trying to improve an object file's debug info in case of
a vectorized transformation by the compiler.
e.g. when a source variable, 'sum' = (xmm0[0-31] + xmm0[32-63] +
xmm0[64-95] + xmm0[96-127]).

Thanks for pointing out the DW_OP_bit_piece operation! It worked in a
setting where a source variable resides directly in a 32-bit chunk of
an 128-bit xmm register.
But, I think it won't be possible for the above example(?).
Here, we'll have to do 128-bit operations (such as DW_OP_shl) on the
register to get its 32-bit chunks. Is that correct?

Regards,
Vaibhav

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

* Re: GDB | DWARF expression | Extracting a range of bits from an 'xmm' register
  2021-05-21 21:09     ` vaibhav kurhe
@ 2021-05-24 10:00       ` Zaric, Zoran (Zare)
  0 siblings, 0 replies; 6+ messages in thread
From: Zaric, Zoran (Zare) @ 2021-05-24 10:00 UTC (permalink / raw)
  To: vaibhav kurhe; +Cc: gdb

On 5/21/21 10:09 PM, vaibhav kurhe wrote:
> [CAUTION: External Email]
> 
> On Fri, May 21, 2021 at 10:36 PM Zaric, Zoran (Zare) via Gdb
> <gdb@sourceware.org> wrote:
>>
>> On 5/21/21 3:03 PM, Andrew Burgess wrote:
>>> * vaibhav kurhe via Gdb <gdb@sourceware.org> [2021-05-21 14:27:15 +0530]:
>>>
>>>> Hello all,
>>>> For a use case, I am trying to build a DWARF expression which represents
>>>> the value of an arbitrary range of bits (e.g. 96-127 bits) in an *128-bit
>>>> xmm register* to be used as a *location attribute value* for a variable DIE.
>>>> I am using GDB to consume the debug info and test it.
>>>>
>>>> Following is the expression I started with to test out a shift operation on
>>>> an 128-bit xmm0 register using Typed DWARF stack :-
>>>>
>>>> *"DW_OP_GNU_regval_type: 21 (xmm0) <0x30>; DW_OP_GNU_const_type: <0x30>  16
>>>> byte block: 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ; DW_OP_shl;
>>>
>>> I'm probably just not understanding correctly, but I'm confused by the
>>> use of DW_OP_GNU_const_type.  Isn't this providing the number of bits
>>> to shift?  I'd have expected something like 'DW_OP_const1u 96'.
>>>
>>> Thanks,
>>> Andrew
>>>
>>
>> Hi Vaibhav,
>>
>> Maybe I am missing something, but what is the end goal that you are
>> trying to accomplish?
>>
>> The way how you formed your expression, you can only get a read only
>> stack value location description.
>>
>> Why not use the DW_OP_bit_piece with your register being the only piece
>> inside of it and then use that as your end location description?
>>
>> Thanks,
>> Zoran
> 
> Hi Zoran,
> Thanks for the reply!
> 
> Actually I am trying to improve an object file's debug info in case of
> a vectorized transformation by the compiler.
> e.g. when a source variable, 'sum' = (xmm0[0-31] + xmm0[32-63] +
> xmm0[64-95] + xmm0[96-127]).
> 
> Thanks for pointing out the DW_OP_bit_piece operation! It worked in a
> setting where a source variable resides directly in a 32-bit chunk of
> an 128-bit xmm register.
> But, I think it won't be possible for the above example(?).
> Here, we'll have to do 128-bit operations (such as DW_OP_shl) on the
> register to get its 32-bit chunks. Is that correct?
> 
> Regards,
> Vaibhav
> 

Right, so for that use case, Andrew's suggestion is the way to go and it 
should work unless there are bugs in gdb evaluator (which there could be).

Your original approach should work too, but there seems to be some 
unexpected limitation when using the shift operation with user based 
types or something similar.

I would also suggest to use the DWARF standard operations instead of GNU 
extensions whenever possible (like DW_OP_regval_type).

On another note, if you are trying to support debugging of a heavily 
optimized and vectorized code, maybe it would be worth your time 
checking out what we are trying to do with our extensions of the DWARF 
standard.

The idea is to support more descriptive and better compose-able location 
descriptions and expressions.

You can find more on this link:
https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html

There is also a working implementation in gdb that is currently being 
reviewed and can be found here:

https://sourceware.org/pipermail/gdb-patches/2021-March/176656.html

We would greatly appreciate any input you might have about it.

Hope this helps,
Zoran






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

end of thread, other threads:[~2021-05-24 10:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21  8:57 GDB | DWARF expression | Extracting a range of bits from an 'xmm' register vaibhav kurhe
2021-05-21 14:03 ` Andrew Burgess
2021-05-21 16:02   ` Zaric, Zoran (Zare)
2021-05-21 21:09     ` vaibhav kurhe
2021-05-24 10:00       ` Zaric, Zoran (Zare)
2021-05-21 20:37   ` vaibhav kurhe

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