Commit 692054e7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: check for findmoduledatap returning nil

The findmoduledatap function will not return nil in ordinary use, but
check for nil to try to avoid crashing when we are already crashing.

Update #11783.

Change-Id: If7b1adb51efab13b4c1a37b6f3c9ad22641a0b56
Reviewed-on: https://go-review.googlesource.com/12391
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent e1ee3140
...@@ -223,6 +223,13 @@ func pcvalue(f *_func, off int32, targetpc uintptr, strict bool) int32 { ...@@ -223,6 +223,13 @@ func pcvalue(f *_func, off int32, targetpc uintptr, strict bool) int32 {
return -1 return -1
} }
datap := findmoduledatap(f.entry) // inefficient datap := findmoduledatap(f.entry) // inefficient
if datap == nil {
if strict && panicking == 0 {
print("runtime: no module data for ", hex(f.entry), "\n")
throw("no module data")
}
return -1
}
p := datap.pclntable[off:] p := datap.pclntable[off:]
pc := f.entry pc := f.entry
val := int32(-1) val := int32(-1)
...@@ -266,6 +273,9 @@ func cfuncname(f *_func) *byte { ...@@ -266,6 +273,9 @@ func cfuncname(f *_func) *byte {
return nil return nil
} }
datap := findmoduledatap(f.entry) // inefficient datap := findmoduledatap(f.entry) // inefficient
if datap == nil {
return nil
}
return (*byte)(unsafe.Pointer(&datap.pclntable[f.nameoff])) return (*byte)(unsafe.Pointer(&datap.pclntable[f.nameoff]))
} }
...@@ -275,6 +285,9 @@ func funcname(f *_func) string { ...@@ -275,6 +285,9 @@ func funcname(f *_func) string {
func funcline1(f *_func, targetpc uintptr, strict bool) (file string, line int32) { func funcline1(f *_func, targetpc uintptr, strict bool) (file string, line int32) {
datap := findmoduledatap(f.entry) // inefficient datap := findmoduledatap(f.entry) // inefficient
if datap == nil {
return "?", 0
}
fileno := int(pcvalue(f, f.pcfile, targetpc, strict)) fileno := int(pcvalue(f, f.pcfile, targetpc, strict))
line = pcvalue(f, f.pcln, targetpc, strict) line = pcvalue(f, f.pcln, targetpc, strict)
if fileno == -1 || line == -1 || fileno >= len(datap.filetab) { if fileno == -1 || line == -1 || fileno >= len(datap.filetab) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment