Re: [PATCH v2 10/10] perf dwarf-aux: support DW_OP_piece expressions
From: Zecheng Li
Date: Tue Sep 16 2025 - 21:22:39 EST
On Sat, Aug 30, 2025 at 3:34 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> On Mon, Aug 25, 2025 at 07:58:33PM +0000, Zecheng Li wrote:
> > Support variables split across multiple registers or stack locations by
> > handling DW_OP_piece in DWARF expressions. This enables correct matching
> > of such variables by iterating over all pieces in the expression.
>
> Can you show me a real world example of these variables?
An optimizing compiler can sometimes split a struct (mostly stack
variable) to multiple locations, or even optimized out. DW_OP_piece
describes the location of each part. For example,
DW_OP_reg2 RCX, DW_OP_piece 0x4, DW_OP_breg7 RSP+28, DW_OP_piece 0x4
The first part is in RCX, the second part is in the memory location
RSP+28, each of size 0x4 byte. Memory access on 0(RCX) corresponds to
case 2 and 28(RSP) corresponds to case 1.
> >
> > There are two cases for matching memory access on the target register:
> >
> > 1. Accessing a struct member:
> > - The type is the original variable's type.
> > - The offset is the sum of the piece's offset and the operand's
> > offset.
> > 2. Dereferencing a member:
> > - The type is the member of the original variable (the member must be
> > a pointer).
> > - The size must match the piece size.
> > - The access offset is the operand's offset.
> >
> > This change improves support for piece-wise variable locations in DWARF
> > expressions.