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.