diff options
| author | LE Manh Cuong <cuong.manhle.vn@gmail.com> | 2019-01-05 01:42:44 +0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2019-03-09 00:24:42 +0000 |
| commit | b37b35edd75af0c175079029bfa3d302637a9c8e (patch) | |
| tree | c97aca0d9514f7c25d7f0cf877f2c2fbc47951a8 /src/debug | |
| parent | 91c9ed084096b105858ab13a3c26925d82592d56 (diff) | |
| download | go-b37b35edd75af0c175079029bfa3d302637a9c8e.tar.xz | |
debug/gosym: simplify parsing symbol name rule
Symbol name with linker prefix like "type." and "go." is not parsed
correctly and returns the prefix as parts of package name.
So just returns empty string for symbol name start with linker prefix.
Fixes #29551
Change-Id: Idb4ce872345e5781a5a5da2b2146faeeebd9e63b
Reviewed-on: https://go-review.googlesource.com/c/go/+/156397
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/gosym/symtab.go | 14 | ||||
| -rw-r--r-- | src/debug/gosym/symtab_test.go | 15 |
2 files changed, 26 insertions, 3 deletions
diff --git a/src/debug/gosym/symtab.go b/src/debug/gosym/symtab.go index a84b7f6def..3be612e1df 100644 --- a/src/debug/gosym/symtab.go +++ b/src/debug/gosym/symtab.go @@ -35,13 +35,21 @@ func (s *Sym) Static() bool { return s.Type >= 'a' } // PackageName returns the package part of the symbol name, // or the empty string if there is none. func (s *Sym) PackageName() string { - pathend := strings.LastIndex(s.Name, "/") + name := s.Name + + // A prefix of "type." and "go." is a compiler-generated symbol that doesn't belong to any package. + // See variable reservedimports in cmd/compile/internal/gc/subr.go + if strings.HasPrefix(name, "go.") || strings.HasPrefix(name, "type.") { + return "" + } + + pathend := strings.LastIndex(name, "/") if pathend < 0 { pathend = 0 } - if i := strings.Index(s.Name[pathend:], "."); i != -1 { - return s.Name[:pathend+i] + if i := strings.Index(name[pathend:], "."); i != -1 { + return name[:pathend+i] } return "" } diff --git a/src/debug/gosym/symtab_test.go b/src/debug/gosym/symtab_test.go index 08e86336b8..b6ed8f554c 100644 --- a/src/debug/gosym/symtab_test.go +++ b/src/debug/gosym/symtab_test.go @@ -41,3 +41,18 @@ func TestRemotePackage(t *testing.T) { assertString(t, fmt.Sprintf("receiver of %q", s1.Name), s1.ReceiverName(), "(*FlagSet)") assertString(t, fmt.Sprintf("receiver of %q", s2.Name), s2.ReceiverName(), "") } + +func TestIssue29551(t *testing.T) { + symNames := []string{ + "type..eq.[9]debug/elf.intName", + "type..hash.debug/elf.ProgHeader", + "type..eq.runtime._panic", + "type..hash.struct { runtime.gList; runtime.n int32 }", + "go.(*struct { sync.Mutex; math/big.table [64]math/big", + } + + for _, symName := range symNames { + s := Sym{Name: symName} + assertString(t, fmt.Sprintf("package of %q", s.Name), s.PackageName(), "") + } +} |
