aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime-gdb_test.go
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2016-11-14 18:00:17 -0500
committerDavid Chase <drchase@google.com>2016-11-16 22:05:19 +0000
commit9f5673d9307572ff3b435a845470e3b7fd3c6a43 (patch)
treef4c0a4db2896b4c8776ec944d550d2cc772423fe /src/runtime/runtime-gdb_test.go
parent1e3c57c2cc1500b12a35a859f3d6e8aa27aeebc5 (diff)
downloadgo-9f5673d9307572ff3b435a845470e3b7fd3c6a43.tar.xz
cmd/compile: ensure necessary types appear in .debug_info
Autotmp filtering was too aggressive and excluded types necessary to make debuggers work properly. Restore the "late filter" in dwarf.go based on names to exclude autotmps, and remove the "early filter" in pgen.go based on how the name was introduced. However, the updated naming scheme with a dot prefix is retained to prevent accidental clashes with legal Go identifier names. Includes test (grouped with runtime gdb tests), verified to fail without the fix. Updates #17644. Fixes #17830. Change-Id: I7ec3f7230083889660236e5f6bc77ba5fe434e93 Reviewed-on: https://go-review.googlesource.com/33233 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/runtime/runtime-gdb_test.go')
-rw-r--r--src/runtime/runtime-gdb_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go
index 06e61e9ced..94ba879ed1 100644
--- a/src/runtime/runtime-gdb_test.go
+++ b/src/runtime/runtime-gdb_test.go
@@ -15,6 +15,7 @@ import (
"regexp"
"runtime"
"strconv"
+ "strings"
"testing"
)
@@ -275,3 +276,72 @@ func TestGdbBacktrace(t *testing.T) {
}
}
}
+
+const autotmpTypeSource = `
+package main
+
+type astruct struct {
+ a, b int
+}
+
+func main() {
+ var iface interface{} = map[string]astruct{}
+ var iface2 interface{} = []astruct{}
+ println(iface, iface2)
+}
+`
+
+// TestGdbAutotmpTypes ensures that types of autotmp variables appear in .debug_info
+// See bug #17830.
+func TestGdbAutotmpTypes(t *testing.T) {
+ t.Parallel()
+ checkGdbEnvironment(t)
+ checkGdbVersion(t)
+
+ dir, err := ioutil.TempDir("", "go-build")
+ if err != nil {
+ t.Fatalf("failed to create temp directory: %v", err)
+ }
+ defer os.RemoveAll(dir)
+
+ // Build the source code.
+ src := filepath.Join(dir, "main.go")
+ err = ioutil.WriteFile(src, []byte(autotmpTypeSource), 0644)
+ if err != nil {
+ t.Fatalf("failed to create file: %v", err)
+ }
+ cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags=-N -l", "-o", "a.exe")
+ cmd.Dir = dir
+ out, err := testEnv(cmd).CombinedOutput()
+ if err != nil {
+ t.Fatalf("building source %v\n%s", err, out)
+ }
+
+ // Execute gdb commands.
+ args := []string{"-nx", "-batch",
+ "-ex", "set startup-with-shell off",
+ "-ex", "break main.main",
+ "-ex", "run",
+ "-ex", "step",
+ "-ex", "info types astruct",
+ filepath.Join(dir, "a.exe"),
+ }
+ got, _ := exec.Command("gdb", args...).CombinedOutput()
+
+ sgot := string(got)
+
+ // Check that the backtrace matches the source code.
+ types := []string{
+ "struct []main.astruct;",
+ "struct bucket<string,main.astruct>;",
+ "struct hash<string,main.astruct>;",
+ "struct main.astruct;",
+ "typedef struct hash<string,main.astruct> * map[string]main.astruct;",
+ }
+ for _, name := range types {
+ if !strings.Contains(sgot, name) {
+ t.Errorf("could not find %s in 'info typrs astruct' output", name)
+ t.Fatalf("gdb output:\n%v", sgot)
+ }
+ }
+}