]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: have ReadMemStats do a nil check before switching stacks
authorKeith Randall <khr@golang.org>
Mon, 3 Jul 2023 20:16:59 +0000 (13:16 -0700)
committerKeith Randall <khr@golang.org>
Tue, 4 Jul 2023 16:54:39 +0000 (16:54 +0000)
This gives the user a better stack trace experience. No need to
expose them to runtime.systemstack and friends.

Fixes #61158

Change-Id: I4f423f82e54b062773067c0ae64622e37cb3948b
Reviewed-on: https://go-review.googlesource.com/c/go/+/507755
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
src/runtime/mstats.go
src/runtime/traceback.go

index ab383dd8e37e383728473caee6f29beb783359a1..9a247b87b53032d31244774a887df70beb1fbe38 100644 (file)
@@ -347,6 +347,7 @@ func init() {
 // which is a snapshot as of the most recently completed garbage
 // collection cycle.
 func ReadMemStats(m *MemStats) {
+       _ = m.Alloc // nil check test before we switch stacks, see issue 61158
        stopTheWorld(stwReadMemStats)
 
        systemstack(func() {
index d6f89210a4053494be2386620cb81d8bd1e439ea..86df1155b5c114bdcf3588039b1109e675b1d07b 100644 (file)
@@ -1147,6 +1147,7 @@ func showfuncinfo(sf srcFunc, firstFrame bool, calleeID abi.FuncID) bool {
 
 // isExportedRuntime reports whether name is an exported runtime function.
 // It is only for runtime functions, so ASCII A-Z is fine.
+// TODO: this handles exported functions but not exported methods.
 func isExportedRuntime(name string) bool {
        const n = len("runtime.")
        return len(name) > n && name[:n] == "runtime." && 'A' <= name[n] && name[n] <= 'Z'