@@ -8,6 +8,11 @@ import (
88
99type Variable struct {
1010 * godwarf.Tree
11+ // Depth represents the depth of the lexical block in which this variable
12+ // was declared, relative to a root scope (e.g. a function) passed to
13+ // Variables(). The depth is used to figure out if a variable is shadowed at
14+ // a particular pc by another one with the same name declared in an inner
15+ // block.
1116 Depth int
1217}
1318
@@ -21,12 +26,16 @@ const (
2126)
2227
2328// Variables returns a list of variables contained inside 'root'.
24- // If onlyVisible is true only variables visible at pc will be returned.
25- // If skipInlinedSubroutines is true inlined subroutines will be skipped
29+ //
30+ // If the VariablesOnlyVisible flag is set, only variables visible at 'pc' will be
31+ // returned. If the VariablesSkipInlinedSubroutines is set, variables from
32+ // inlined subroutines will be skipped.
2633func Variables (root * godwarf.Tree , pc uint64 , line int , flags VariablesFlags ) []Variable {
2734 return variablesInternal (nil , root , 0 , pc , line , flags )
2835}
2936
37+ // variablesInternal appends to 'v' variables from 'root'. The function calls
38+ // itself with an incremented scope for all sub-blocks in 'root'.
3039func variablesInternal (v []Variable , root * godwarf.Tree , depth int , pc uint64 , line int , flags VariablesFlags ) []Variable {
3140 switch root .Tag {
3241 case dwarf .TagInlinedSubroutine :
@@ -35,6 +44,8 @@ func variablesInternal(v []Variable, root *godwarf.Tree, depth int, pc uint64, l
3544 }
3645 fallthrough
3746 case dwarf .TagLexDwarfBlock , dwarf .TagSubprogram :
47+ // Recurse into blocks and functions, if the respective block contains
48+ // pc (or if we don't care about visibility).
3849 if (flags & VariablesOnlyVisible == 0 ) || root .ContainsPC (pc ) {
3950 for _ , child := range root .Children {
4051 v = variablesInternal (v , child , depth + 1 , pc , line , flags )
0 commit comments