]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: dedup function name logic into moduledata method
authorAustin Clements <austin@google.com>
Fri, 3 Feb 2023 22:49:53 +0000 (17:49 -0500)
committerAustin Clements <austin@google.com>
Fri, 10 Mar 2023 17:18:26 +0000 (17:18 +0000)
For #54466.

Change-Id: I4d8e1953703b6c763e5bd53024da43efcc993489
Reviewed-on: https://go-review.googlesource.com/c/go/+/466095
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Austin Clements <austin@google.com>

src/runtime/race.go
src/runtime/symtab.go

index 7e9ef40e6cb51342460fd3a7d3b3496facd2085e..144043bb66b0238e375f21dac37557a425032402 100644 (file)
@@ -187,7 +187,8 @@ func raceSymbolizeCode(ctx *symbolizeCodeContext) {
                                                        continue
                                                }
                                                ctx.pc = f.Entry() + uintptr(inltree[ix].parentPc) // "caller" pc
-                                               ctx.fn = cfuncnameFromNameOff(fi, inltree[ix].nameOff)
+                                               name := funcnameFromNameOff(fi, inltree[ix].nameOff)
+                                               ctx.fn = &bytes(name)[0] // assume NUL-terminated
                                                ctx.line = uintptr(line)
                                                ctx.file = &bytes(file)[0] // assume NUL-terminated
                                                ctx.off = pc - f.Entry()
@@ -197,7 +198,8 @@ func raceSymbolizeCode(ctx *symbolizeCodeContext) {
                                        break
                                }
                        }
-                       ctx.fn = cfuncname(fi)
+                       name := funcname(fi)
+                       ctx.fn = &bytes(name)[0] // assume NUL-terminated
                        ctx.line = uintptr(line)
                        ctx.file = &bytes(file)[0] // assume NUL-terminated
                        ctx.off = pc - f.Entry()
index da83fd93ea7cccddfe08af8f6d50562ac950bcf3..4f41749353b37a7e583929fcf10c2ab38bf85790 100644 (file)
@@ -733,6 +733,14 @@ func (md *moduledata) textOff(pc uintptr) (uint32, bool) {
        return res, true
 }
 
+// funcName returns the string at nameOff in the function name table.
+func (md *moduledata) funcName(nameOff int32) string {
+       if nameOff == 0 {
+               return ""
+       }
+       return gostringnocopy(&md.funcnametab[nameOff])
+}
+
 // FuncForPC returns a *Func describing the function that contains the
 // given program counter address, or else nil.
 //
@@ -1004,15 +1012,11 @@ func pcvalue(f funcInfo, off uint32, targetpc uintptr, cache *pcvalueCache, stri
        return -1, 0
 }
 
-func cfuncname(f funcInfo) *byte {
-       if !f.valid() || f.nameOff == 0 {
-               return nil
-       }
-       return &f.datap.funcnametab[f.nameOff]
-}
-
 func funcname(f funcInfo) string {
-       return gostringnocopy(cfuncname(f))
+       if !f.valid() {
+               return ""
+       }
+       return f.datap.funcName(f.nameOff)
 }
 
 func funcpkgpath(f funcInfo) string {
@@ -1031,15 +1035,11 @@ func funcpkgpath(f funcInfo) string {
        return name[:i]
 }
 
-func cfuncnameFromNameOff(f funcInfo, nameOff int32) *byte {
+func funcnameFromNameOff(f funcInfo, nameOff int32) string {
        if !f.valid() {
-               return nil
+               return ""
        }
-       return &f.datap.funcnametab[nameOff]
-}
-
-func funcnameFromNameOff(f funcInfo, nameOff int32) string {
-       return gostringnocopy(cfuncnameFromNameOff(f, nameOff))
+       return f.datap.funcName(nameOff)
 }
 
 func funcfile(f funcInfo, fileno int32) string {