gocore: fix removal of package paths
They aren't always prefixes. For instance, map[string]foo/bar.
Do a better job by removing word/ everywhere it appears in a type.
Change-Id: I22d8e00f9eef225dd143cad1db3aa0eeb901ad10
Reviewed-on: https://go-review.googlesource.com/92416
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
diff --git a/gocore/dwarf.go b/gocore/dwarf.go
index 6aa0fdd..57b389e 100644
--- a/gocore/dwarf.go
+++ b/gocore/dwarf.go
@@ -7,6 +7,7 @@
import (
"debug/dwarf"
"fmt"
+ "regexp"
"sort"
"strings"
@@ -299,13 +300,17 @@
return s
default:
name := dt.String()
- if i := strings.LastIndex(name, "/"); i >= 0 {
- name = name[i+1:] // Runtime uses only last name in package path.
- }
- return name
+ // The runtime uses just package names. DWARF uses whole package paths.
+ // To convert from the latter to the former, get rid of the package paths.
+ // Examples:
+ // text/template.Template -> template.Template
+ // map[string]compress/gzip.Writer -> map[string]gzip.Writer
+ return strings.Join(pathRegexp.Split(name, -1), "")
}
}
+var pathRegexp = regexp.MustCompile("\\w+/")
+
// readRuntimeConstants populates the p.rtConstants map.
func (p *Process) readRuntimeConstants() {
p.rtConstants = map[string]int64{}