From 14a92352bc6f350a8db76aab2a2033477f03df7d Mon Sep 17 00:00:00 2001 From: aarzilli Date: Sun, 21 Feb 2016 17:26:13 +0100 Subject: [PATCH] proc: Add filter for non-variable global symbols to PackageVariables --- proc/proc_test.go | 21 +++++++++++++++++++++ proc/variables.go | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/proc/proc_test.go b/proc/proc_test.go index 44179e41..43499c9f 100644 --- a/proc/proc_test.go +++ b/proc/proc_test.go @@ -1576,3 +1576,24 @@ func TestIssue414(t *testing.T) { } }) } + +func TestPackageVariables(t *testing.T) { + withTestProcess("testvariables", t, func(p *Process, fixture protest.Fixture) { + err := p.Continue() + assertNoError(err, t, "Continue()") + scope, err := p.CurrentThread.Scope() + assertNoError(err, t, "Scope()") + vars, err := scope.PackageVariables() + assertNoError(err, t, "PackageVariables()") + failed := false + for _, v := range vars { + if v.Unreadable != nil { + failed = true + t.Logf("Unreadable variable %s: %v", v.Name, v.Unreadable) + } + } + if failed { + t.Fatalf("previous errors") + } + }) +} diff --git a/proc/variables.go b/proc/variables.go index 1e0a0669..a6856cf5 100644 --- a/proc/variables.go +++ b/proc/variables.go @@ -541,11 +541,21 @@ func (scope *EvalScope) PackageVariables() ([]*Variable, error) { var vars []*Variable reader := scope.DwarfReader() + var utypoff dwarf.Offset + utypentry, err := reader.SeekToTypeNamed("") + if err == nil { + utypoff = utypentry.Offset + } + for entry, err := reader.NextPackageVariable(); entry != nil; entry, err = reader.NextPackageVariable() { if err != nil { return nil, err } + if typoff, ok := entry.Val(dwarf.AttrType).(dwarf.Offset); !ok || typoff == utypoff { + continue + } + // Ignore errors trying to extract values val, err := scope.extractVariableFromEntry(entry) if err != nil { -- GitLab