You probably already know that variable entries in debug_info have a
DW_AT_location that's supposed to tell you where they are in memory. This is
either a DWARF location expression or a reference to debug_loc.
If it is the latter you have to scan the referenced list looking for the
current value of your PC register and get the location expression from
there.
Location expressions are little programs for a stack based VM. The
implementation of that for delve is in pkg/dwarf/op/op.go. If you are
debugging unoptimized go programs almost all variables will have a location
that looks like this:
DW_OP_fbreg <a constant>
This gives you the offset of the varible from the "frame base". To find the
frame base which means that you have to get the DW_AT_frame_base of the
subroutine containing your variable, which happens to be an expression, and
evaluate it.
For all go programs this expression is simply 'DW_OP_call_frame_cfa'.
The problem with executing those expression is that first you have to unwind
the stack using debug_frame which is very complicated. We do this in
pkg/proc/stack.go with assistence from pkg/dwarf/frame. In particular
advanceRegs in stack.go. This will get you the value of 'CFA' (which is a
special pseudo-register that DWARF uses) to use to resolve the address of a
stack variable.
For go programs then CFA is just the value of SP just before the CALL
instruction that created the current frame was executed and the size of the
current frame is always described with a constant (all IIRC).
So you can cheat and just implement enough debug_frame stuff that you can
just get CFA in those circumstances and you'll be fine. Very old versions of
delve did this. You could look at stack.go in, a ~2016 version of delve.
> --
> You received this message because you are subscribed to the Google Groups "delve-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
delve-dev+...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/delve-dev/9f88cbdb-994d-4e03-bb52-69ba7139c90d%40googlegroups.com.