import (
"fmt"
+ "strings"
)
// InfoPrefix is the prefix for all the symbols containing DWARF info entries.
putattr(ctxt, s, DW_ABRV_FUNCTION, DW_FORM_flag, DW_CLS_FLAG, ev, 0)
names := make(map[string]bool)
for v := vars; v != nil; v = v.Link {
+ if strings.Contains(v.Name, ".autotmp_") {
+ continue
+ }
var n string
if names[v.Name] {
n = fmt.Sprintf("%s#%d", v.Name, len(names))
"regexp"
"runtime"
"strconv"
+ "strings"
"testing"
)
}
}
}
+
+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)
+ }
+ }
+}