Skip to content

Commit dcb4c1c

Browse files
committed
runtime: dedup function name logic into moduledata method
For #54466. Change-Id: I4d8e1953703b6c763e5bd53024da43efcc993489 Reviewed-on: https://go-review.googlesource.com/c/go/+/466095 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Run-TryBot: Austin Clements <[email protected]>
1 parent 6f22d42 commit dcb4c1c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/runtime/race.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ func raceSymbolizeCode(ctx *symbolizeCodeContext) {
187187
continue
188188
}
189189
ctx.pc = f.Entry() + uintptr(inltree[ix].parentPc) // "caller" pc
190-
ctx.fn = cfuncnameFromNameOff(fi, inltree[ix].nameOff)
190+
name := funcnameFromNameOff(fi, inltree[ix].nameOff)
191+
ctx.fn = &bytes(name)[0] // assume NUL-terminated
191192
ctx.line = uintptr(line)
192193
ctx.file = &bytes(file)[0] // assume NUL-terminated
193194
ctx.off = pc - f.Entry()
@@ -197,7 +198,8 @@ func raceSymbolizeCode(ctx *symbolizeCodeContext) {
197198
break
198199
}
199200
}
200-
ctx.fn = cfuncname(fi)
201+
name := funcname(fi)
202+
ctx.fn = &bytes(name)[0] // assume NUL-terminated
201203
ctx.line = uintptr(line)
202204
ctx.file = &bytes(file)[0] // assume NUL-terminated
203205
ctx.off = pc - f.Entry()

src/runtime/symtab.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,14 @@ func (md *moduledata) textOff(pc uintptr) (uint32, bool) {
733733
return res, true
734734
}
735735

736+
// funcName returns the string at nameOff in the function name table.
737+
func (md *moduledata) funcName(nameOff int32) string {
738+
if nameOff == 0 {
739+
return ""
740+
}
741+
return gostringnocopy(&md.funcnametab[nameOff])
742+
}
743+
736744
// FuncForPC returns a *Func describing the function that contains the
737745
// given program counter address, or else nil.
738746
//
@@ -1004,15 +1012,11 @@ func pcvalue(f funcInfo, off uint32, targetpc uintptr, cache *pcvalueCache, stri
10041012
return -1, 0
10051013
}
10061014

1007-
func cfuncname(f funcInfo) *byte {
1008-
if !f.valid() || f.nameOff == 0 {
1009-
return nil
1010-
}
1011-
return &f.datap.funcnametab[f.nameOff]
1012-
}
1013-
10141015
func funcname(f funcInfo) string {
1015-
return gostringnocopy(cfuncname(f))
1016+
if !f.valid() {
1017+
return ""
1018+
}
1019+
return f.datap.funcName(f.nameOff)
10161020
}
10171021

10181022
func funcpkgpath(f funcInfo) string {
@@ -1031,15 +1035,11 @@ func funcpkgpath(f funcInfo) string {
10311035
return name[:i]
10321036
}
10331037

1034-
func cfuncnameFromNameOff(f funcInfo, nameOff int32) *byte {
1038+
func funcnameFromNameOff(f funcInfo, nameOff int32) string {
10351039
if !f.valid() {
1036-
return nil
1040+
return ""
10371041
}
1038-
return &f.datap.funcnametab[nameOff]
1039-
}
1040-
1041-
func funcnameFromNameOff(f funcInfo, nameOff int32) string {
1042-
return gostringnocopy(cfuncnameFromNameOff(f, nameOff))
1042+
return f.datap.funcName(nameOff)
10431043
}
10441044

10451045
func funcfile(f funcInfo, fileno int32) string {

0 commit comments

Comments
 (0)