]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix DWARF type symbol buglet
authorThan McIntosh <thanm@google.com>
Fri, 1 Dec 2017 14:39:59 +0000 (09:39 -0500)
committerThan McIntosh <thanm@google.com>
Fri, 1 Dec 2017 18:52:50 +0000 (18:52 +0000)
The code that generates the list of DWARF variables for a function
(params and autos) will emit a "no-location" entry in the DWARF for a
user var that appears in the original pre-optimization version of the
function but is no longer around when optimization is complete. The
intent is that if a GDB user types "print foo" (where foo has been
optimized out), the response will be "<optimized out>" as opposed to
"there is no such variable 'foo'). This change fixes said code to
include vars on the autom list for the function, to insure that the
type symbol for the variable makes it to the linker.

Fixes #22941.

Change-Id: Id29f1f39d68fbb798602dfd6728603040624fc41
Reviewed-on: https://go-review.googlesource.com/81415
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/pgen.go
test/fixedbugs/issue22941.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue22941.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue22941.dir/main.go [new file with mode: 0644]
test/fixedbugs/issue22941.go [new file with mode: 0644]

index 39da514d5378c9eab303f2bbac59c4e94436eb0e..3d099ad6c052bf4a3d43f967a44ada6b95e725c9 100644 (file)
@@ -558,6 +558,18 @@ func createDwarfVars(fnsym *obj.LSym, debugInfo *ssa.FuncDebug, automDecls []*No
                        InlIndex:      int32(inlIndex),
                        ChildIndex:    -1,
                })
+               // Note: the auto that we're appending here is simply to insure
+               // that the DWARF type in question is picked up by the linker --
+               // there isn't a real auto variable with this name. This is
+               // to fix issue 22941.
+               gotype := ngotype(n).Linksym()
+               fnsym.Func.Autom = append(fnsym.Func.Autom, &obj.Auto{
+                       Asym:    Ctxt.Lookup(n.Sym.Name),
+                       Aoffset: int32(-1),
+                       Name:    obj.NAME_AUTO,
+                       Gotype:  gotype,
+               })
+
        }
 
        // Parameter and local variable names are given middle dot
diff --git a/test/fixedbugs/issue22941.dir/a.go b/test/fixedbugs/issue22941.dir/a.go
new file mode 100644 (file)
index 0000000..7a4ede4
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package q
+
+type P int
diff --git a/test/fixedbugs/issue22941.dir/b.go b/test/fixedbugs/issue22941.dir/b.go
new file mode 100644 (file)
index 0000000..87d59a6
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+import q "./a"
+
+type T struct {
+       X *q.P
+}
+
+func F(in, out *T) {
+       *out = *in
+       if in.X != nil {
+               in, out := &in.X, &out.X
+               if *in == nil {
+                       *out = nil
+               } else {
+                       *out = new(q.P)
+                       **out = **in
+               }
+       }
+       return
+}
+
+//go:noinline
+func G(x, y *T) {
+       F(x, y)
+}
diff --git a/test/fixedbugs/issue22941.dir/main.go b/test/fixedbugs/issue22941.dir/main.go
new file mode 100644 (file)
index 0000000..84666ad
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import p "./b"
+
+var G int
+
+func main() {
+       if G == 101 {
+               p.G(nil, nil)
+       }
+}
diff --git a/test/fixedbugs/issue22941.go b/test/fixedbugs/issue22941.go
new file mode 100644 (file)
index 0000000..c3732c3
--- /dev/null
@@ -0,0 +1,7 @@
+// rundir
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ignored