Skip to content

Commit 60b5e9d

Browse files
authored
dwarf/reader: minor comments around variable resolving (#2253)
Fix some stale comments and add some comments that I would have found useful.
1 parent 34ffa2e commit 60b5e9d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/dwarf/reader/variables.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88

99
type 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.
2633
func 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'.
3039
func 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)

pkg/proc/eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func isAssignment(err error) (int, bool) {
200200
return 0, false
201201
}
202202

203-
// Locals fetches all variables of a specific type in the current function scope.
203+
// Locals returns all variables in 'scope'.
204204
func (scope *EvalScope) Locals() ([]*Variable, error) {
205205
if scope.Fn == nil {
206206
return nil, errors.New("unable to find function context")

0 commit comments

Comments
 (0)