trying to undestand dwarf variables traversal

16 views
Skip to first unread message

Andrei Matei

unread,
Dec 6, 2020, 12:47:23 PM12/6/20
to delv...@googlegroups.com
I'd like to kindly ask for help understanding some code: in dwarf/reader/variables.go:variablesInternal(), we're recursing through a dwarf tree. We're explicitly handling a few dwarf node types, but everything else we surprisingly treat as a variable. Why is that / how come we're not filtering for specific tags indicating variables, formal parameters, things like that? Also surprising to me, the code checks for a DeclLine attribute, and if the attribute is not present, it treats that as further encouragement to consider the entry as a variable.
There are many dwarf entry types which are not variables, and so I'm surprised that we're not discarding them. I looked around to see if there's filtering going on the tree before we get to this point, but I haven't seen it. What am I missing?

Thanks a lot!

- Andrei

Alessandro Arzilli

unread,
Dec 8, 2020, 8:28:13 AM12/8/20
to Andrei Matei, delv...@googlegroups.com
On Sun, Dec 06, 2020 at 12:47:10PM -0500, Andrei Matei wrote:
> I'd like to kindly ask for help understanding some code: in
> dwarf/reader/variables.go:variablesInternal(), we're recursing through a
> dwarf tree. We're explicitly handling a few dwarf node types, but
> everything else we surprisingly treat as a variable
> <https://github.com/go-delve/delve/blob/34ffa2e763d02881dfbf4dbf7ff00068871b21e7/pkg/dwarf/reader/variables.go#L52>.
> Why is that / how come we're not filtering for specific tags indicating
> variables, formal parameters, things like that?

Because those are the only things that the Go compiler writes there, inlined
subroutines, lexical blocks, variables and formal parameters. Also the code
that calls reader.Variables filters out things that aren't DW_TAG_variable
or DW_TAG_FormalParameter. But yes, it would be more correct if this was
explicit.

> Also surprising to me, the
> code checks for a DeclLine attribute, and if the attribute is *not* present*,
> *it treats that as further encouragement to consider the entry as a
> variable.

That's not exactly what's happening. The DeclLine attribute is optional, if
it isn't present we can't check that the varaible is visible (based on
declaration line) and so we assume that it is.
Reply all
Reply to author
Forward
0 new messages