gimli-rs / gimli

A library for reading and writing the DWARF debugging format
https://docs.rs/gimli/
Apache License 2.0
846 stars 108 forks source link

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

Open vaibspider opened 3 years ago

vaibspider commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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.