Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWARF expression: Extracting a range of bits in an xmm register #553

Open
vaibspider opened this issue Apr 20, 2021 · 6 comments
Open

DWARF expression: Extracting a range of bits in an xmm register #553

vaibspider opened this issue Apr 20, 2021 · 6 comments

Comments

@vaibspider
Copy link
Contributor

Hi,
I am trying to build a DWARF expression using gimli, which involves extracting a range of bits from an xmm register e.g. 32-63 bits from xmm0.
But I found that the DWARF4 standard, section 2.5.1 mentions :

Each general operation represents a postfix operation on a simple stack machine. Each element of the stack is the size of an address on the target machine

So it seems that - if we have a 32-bit machine, value of an 128-bit register such as xmm0 would be truncated to 32 bits.
Could you please confirm this and let me know if I'm missing something?
Thanks!

@philipc
Copy link
Collaborator

philipc commented Apr 20, 2021

If you need the value then I think you need to use DW_OP_regval_type to specify a different type rather than using the target address size. If you only need the location, then use DW_OP_bit_piece.

@philipc
Copy link
Collaborator

philipc commented Apr 20, 2021

You probably need to look at how your intended consumer handles these to be certain (or gdb/lldb if you want this for general use).

@vaibspider
Copy link
Contributor Author

Thanks for pointing out the DW_OP_regval_type operation! I was looking for a similar dwarf operation.
But, I found that it's added in DWARF5 and not present in earlier standards <= 4.
So now, I will try switching to DWARF5 from DWARF4 and using the typed stack operation.

@vaibspider
Copy link
Contributor Author

Hi @philipc !
I tried using DW_OP_GNU_regval_type (op_regval_type() in gimli) with a DW_OP_shl operation as follows:

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

I was testing whether I could access the higher order 32-bits in xmm0 register, by first shifting it. But, gdb gave an error for the DWARF expression above:

That operation is not available on integers of more than 8 bytes.

I couldn't think of a way to implement an "32-bit value extract" operation from an xmm register without using a shift on its 128-bit value.

Could you please provide any pointers on this?

Thanks!

@philipc
Copy link
Collaborator

philipc commented May 20, 2021

So we need to know how to encode this in a way that gdb can support it, which sounds like more of a question for gdb folks. You could try the gdb mailing list, or maybe @tromey is able to answer this.

@philipc
Copy link
Collaborator

philipc commented Oct 28, 2021

This may be of interest to you: https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html
It allows offsets within registers, among other things, which would allow you to specify a location as the higher order 32-bits of a register. This is still all in development I think, but they are working on gdb support too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants