Skip to content

Commit 3949cae

Browse files
committed
runtime: repair gdb printing fix for 7.12, 8.{1,2,3}.1, 9.2
Hand-verified for listed gdb versions. Gdb (apparently) changed the way it names certain Go types, and this change broke the pretty-printer-activating code in runtime-gdb.py runtime-gdb_test.go now checks channel, map, string, and slice printing unconditionally (i.e., no opt-out for old versions). Updates #39368. Change-Id: I98d72e1291c66bd40d970990e1a377ff2ed0c5d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/236164 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent 9e56bcb commit 3949cae

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

Diff for: src/runtime/runtime-gdb.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,22 @@
2828
goobjfile = gdb.current_objfile() or gdb.objfiles()[0]
2929
goobjfile.pretty_printers = []
3030

31+
# A bit of hand optimization since oldnew is used for slice printing
32+
splitgdbversion = gdb.VERSION.split('.')
33+
majorgdbversion = int(splitgdbversion[0])
34+
3135
# Older gdb renders some types differently.
3236
def oldnew(old, new):
33-
if (gdb.VERSION[0] == '7'):
37+
if majorgdbversion < 8:
3438
return old
39+
if majorgdbversion > 8:
40+
return new
41+
try:
42+
# Minor versions need not be actual numbers, e.g., 7.3a.
43+
if int(splitgdbversion[1]) < 2:
44+
return old
45+
except Exception:
46+
return new # All the existing gdb 8.minor versions are numbers, so if it is not a number, it is new.
3547
return new
3648

3749
# G state (runtime2.go)
@@ -202,7 +214,7 @@ class ChanTypePrinter:
202214
to inspect their contents with this pretty printer.
203215
"""
204216

205-
pattern = re.compile(oldnew(r'^struct hchan<.*>$',r'^chan '))
217+
pattern = re.compile(r'^chan ')
206218

207219
def __init__(self, val):
208220
self.val = val

Diff for: src/runtime/runtime-gdb_test.go

+14-19
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ func checkGdbEnvironment(t *testing.T) {
5555
}
5656
}
5757

58-
// checkGdbVersion ensures gdb version is supported, and returns major version
59-
// to allow testing conditional on gdb version.
60-
func checkGdbVersion(t *testing.T) int {
58+
func checkGdbVersion(t *testing.T) {
6159
// Issue 11214 reports various failures with older versions of gdb.
6260
out, err := exec.Command("gdb", "--version").CombinedOutput()
6361
if err != nil {
@@ -77,7 +75,6 @@ func checkGdbVersion(t *testing.T) int {
7775
t.Skipf("skipping: gdb version %d.%d too old", major, minor)
7876
}
7977
t.Logf("gdb version %d.%d", major, minor)
80-
return major
8178
}
8279

8380
func checkGdbPython(t *testing.T) {
@@ -170,7 +167,7 @@ func testGdbPython(t *testing.T, cgo bool) {
170167

171168
checkGdbEnvironment(t)
172169
t.Parallel()
173-
gdbMajor := checkGdbVersion(t)
170+
checkGdbVersion(t)
174171
checkGdbPython(t)
175172

176173
dir, err := ioutil.TempDir("", "go-build")
@@ -319,16 +316,14 @@ func testGdbPython(t *testing.T, cgo bool) {
319316
t.Fatalf("print slicemap failed: %s", bl)
320317
}
321318

322-
if gdbMajor > 7 {
323-
chanIntSfx := `chan int = {99, 11}`
324-
if bl := strings.ReplaceAll(blocks["print chanint"], " ", " "); !strings.HasSuffix(bl, chanIntSfx) {
325-
t.Fatalf("print chanint failed: %s", bl)
326-
}
319+
chanIntSfx := `chan int = {99, 11}`
320+
if bl := strings.ReplaceAll(blocks["print chanint"], " ", " "); !strings.HasSuffix(bl, chanIntSfx) {
321+
t.Fatalf("print chanint failed: %s", bl)
322+
}
327323

328-
chanStrSfx := `chan string = {"spongepants", "squarebob"}`
329-
if bl := strings.ReplaceAll(blocks["print chanstr"], " ", " "); !strings.HasSuffix(bl, chanStrSfx) {
330-
t.Fatalf("print chanstr failed: %s", bl)
331-
}
324+
chanStrSfx := `chan string = {"spongepants", "squarebob"}`
325+
if bl := strings.ReplaceAll(blocks["print chanstr"], " ", " "); !strings.HasSuffix(bl, chanStrSfx) {
326+
t.Fatalf("print chanstr failed: %s", bl)
332327
}
333328

334329
strVarRe := regexp.MustCompile(`^\$[0-9]+ = (0x[0-9a-f]+\s+)?"abc"$`)
@@ -407,7 +402,7 @@ func TestGdbBacktrace(t *testing.T) {
407402

408403
checkGdbEnvironment(t)
409404
t.Parallel()
410-
_ = checkGdbVersion(t)
405+
checkGdbVersion(t)
411406

412407
dir, err := ioutil.TempDir("", "go-build")
413408
if err != nil {
@@ -481,7 +476,7 @@ func main() {
481476
func TestGdbAutotmpTypes(t *testing.T) {
482477
checkGdbEnvironment(t)
483478
t.Parallel()
484-
_ = checkGdbVersion(t)
479+
checkGdbVersion(t)
485480

486481
if runtime.GOOS == "aix" && testing.Short() {
487482
t.Skip("TestGdbAutotmpTypes is too slow on aix/ppc64")
@@ -554,7 +549,7 @@ func main() {
554549
func TestGdbConst(t *testing.T) {
555550
checkGdbEnvironment(t)
556551
t.Parallel()
557-
_ = checkGdbVersion(t)
552+
checkGdbVersion(t)
558553

559554
dir, err := ioutil.TempDir("", "go-build")
560555
if err != nil {
@@ -621,7 +616,7 @@ func crash() {
621616
func TestGdbPanic(t *testing.T) {
622617
checkGdbEnvironment(t)
623618
t.Parallel()
624-
_ = checkGdbVersion(t)
619+
checkGdbVersion(t)
625620

626621
dir, err := ioutil.TempDir("", "go-build")
627622
if err != nil {
@@ -699,7 +694,7 @@ func TestGdbInfCallstack(t *testing.T) {
699694
}
700695

701696
t.Parallel()
702-
_ = checkGdbVersion(t)
697+
checkGdbVersion(t)
703698

704699
dir, err := ioutil.TempDir("", "go-build")
705700
if err != nil {

0 commit comments

Comments
 (0)