From 53840ad6f19b0c1b27a0731a37341d6159625355 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Fri, 10 Apr 2015 15:13:04 -0400 Subject: [PATCH] runtime: Fix GDB integration with Python 2 A similar fix was applied in 545686857bc4c2e7a5306d97e5ef48f631d277bc but another instance of 'pc' was missed. Also adds a test for the goroutine gdb command. It currently uses goroutine 2 for the test, since goroutine 1 has its stack pointer set to 0 for some reason. Change-Id: I53ca22be6952f03a862edbdebd9b5c292e0853ae Reviewed-on: https://go-review.googlesource.com/8729 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/runtime-gdb.py | 2 +- src/runtime/runtime-gdb_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/runtime/runtime-gdb.py b/src/runtime/runtime-gdb.py index c70aea71bb..e57fa00e1a 100644 --- a/src/runtime/runtime-gdb.py +++ b/src/runtime/runtime-gdb.py @@ -446,7 +446,7 @@ class GoroutineCmd(gdb.Command): #python3 / newer versions of gdb pc = int(pc) except gdb.error: - pc = int(str(pc), 16) + pc = int(str(pc).split(None, 1)[0], 16) save_frame = gdb.selected_frame() gdb.parse_and_eval('$save_pc = $pc') gdb.parse_and_eval('$save_sp = $sp') diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index 7569d07466..d6d0003572 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -80,6 +80,9 @@ func TestGdbPython(t *testing.T) { "-ex", "echo BEGIN print ptrvar\n", "-ex", "print ptrvar", "-ex", "echo END\n", + "-ex", "echo BEGIN goroutine 2 bt\n", + "-ex", "goroutine 2 bt", + "-ex", "echo END\n", filepath.Join(dir, "a.exe")).CombinedOutput() firstLine := bytes.SplitN(got, []byte("\n"), 2)[0] @@ -112,4 +115,9 @@ func TestGdbPython(t *testing.T) { if bl := blocks["print ptrvar"]; !strVarRe.MatchString(bl) { t.Fatalf("print ptrvar failed: %s", bl) } + + btGoroutineRe := regexp.MustCompile(`^#0\s+runtime.+at`) + if bl := blocks["goroutine 2 bt"]; !btGoroutineRe.MatchString(bl) { + t.Fatalf("goroutine 2 bt failed: %s", bl) + } } -- 2.48.1