public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Yonghong Song <yonghong.song@linux.dev>,
	Alan Maguire <alan.maguire@oracle.com>
Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org, q66 <me@q66.moe>
Subject: Re: [PATCH dwarves] dwarf_loader: Handle DW_AT_location attrs containing DW_OP_plus_uconst
Date: Sat, 13 Dec 2025 08:20:14 +0000	[thread overview]
Message-ID: <aT0hjyVstASDsl-E@pie> (raw)
In-Reply-To: <a3f82302-09d2-45e1-a30a-38a32ddbf947@linux.dev>

Hi Yonghong,

Sorry for the late reply,

On Wed, Dec 03, 2025 at 04:46:20PM -0800, Yonghong Song wrote:
> 
> 
> On 11/29/25 7:21 PM, Yao Zi wrote:

...

> > diff --git a/dwarf_loader.c b/dwarf_loader.c
> > index 79be3f516a26..635015676389 100644
> > --- a/dwarf_loader.c
> > +++ b/dwarf_loader.c
> > @@ -708,6 +708,11 @@ static enum vscope dwarf__location(Dwarf_Die *die, uint64_t *addr, struct locati
> >   		case DW_OP_addrx:
> >   			scope = VSCOPE_GLOBAL;
> >   			*addr = expr[0].number;
> > +
> > +			if (location->exprlen == 2 &&
> > +			    expr[1].atom == DW_OP_plus_uconst)
> > +				addr += expr[1].number;
> 
> This does not work. 'addr' is the parameter and the above new 'addr' value won't
> pass back to caller so the above is effectively a noop.

Oops, this is a silly problem.

> I think we need to add an additional parameter to pass the 'expr[1].number' back
> to the caller, e.g.,

However, I don't think it's necessary. See my explanation below,

> static enum vscope dwarf__location(Dwarf_Die *die, uint64_t *addr, uint32_t *offset, struct location *location) { ... }
> 
> and
> 
>    in the above
>        *offset = expr[1].number.
> 
> Now the caller has the following information:
>   . The deference of *addr stores the index to .debug_addr

No, dwarf__location() invokes attr_location(), which calls
dwarf_getlocation() and dwarf_formaddr(), the latter already performs a
lookup in .debug_addr[1], so what is stored in *addr is right the symbol
address.

Thus I think it's enough to keep the signature, but add the offset to
*addr.

>   . The offset to the address in .debug_addr
> and the final address will be debug_addr[*addr] + offset.
> 
> > +
> >   			break;
> >   		case DW_OP_reg1 ... DW_OP_reg31:
> >   		case DW_OP_breg0 ... DW_OP_breg31:
> 

Thanks for your review, I'll soon send a patch with the missing pointer
dereference to addr added.

Best regards,
Yao Zi

[1]: https://github.com/sourceware-org/elfutils/blob/67199e1c974db37f2bd200dcca7d7103f42ed06e/libdw/dwarf_formaddr.c#L37-L77

  reply	other threads:[~2025-12-13  8:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-30  3:21 [PATCH dwarves] dwarf_loader: Handle DW_AT_location attrs containing DW_OP_plus_uconst Yao Zi
2025-12-04  0:46 ` Yonghong Song
2025-12-13  8:20   ` Yao Zi [this message]
2025-12-17  4:12     ` Yonghong Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aT0hjyVstASDsl-E@pie \
    --to=me@ziyao.cc \
    --cc=alan.maguire@oracle.com \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=me@q66.moe \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox