runtime: add stringStructOf helper function

Instead of open-coding conversions from *string to unsafe.Pointer then
to *stringStruct, add a helper function to add some type safety.
Bonus: This caught two **string values being converted to
*stringStruct in heapdump.go.

While here, get rid of the redundant _string type, but add in a
stringStructDWARF type used for generating DWARF debug info.

Change-Id: I8882f8cca66ac45190270f82019a5d85db023bd2
Reviewed-on: https://go-review.googlesource.com/16131
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Matthew Dempsky 2015-10-20 00:35:12 -07:00
parent ef986fa3fc
commit d4a7ea1b71
9 changed files with 26 additions and 22 deletions

View file

@ -142,7 +142,7 @@ func dumpslice(b []byte) {
}
func dumpstr(s string) {
sp := (*stringStruct)(unsafe.Pointer(&s))
sp := stringStructOf(&s)
dumpmemrange(sp.str, uintptr(sp.len))
}
@ -183,8 +183,8 @@ func dumptype(t *_type) {
if t.x == nil || t.x.pkgpath == nil || t.x.name == nil {
dumpstr(*t._string)
} else {
pkgpath := (*stringStruct)(unsafe.Pointer(&t.x.pkgpath))
name := (*stringStruct)(unsafe.Pointer(&t.x.name))
pkgpath := stringStructOf(t.x.pkgpath)
name := stringStructOf(t.x.name)
dumpint(uint64(uintptr(pkgpath.len) + 1 + uintptr(name.len)))
dwrite(pkgpath.str, uintptr(pkgpath.len))
dwritebyte('.')