]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: avoid truncating fieldname var locations
authorThan McIntosh <thanm@google.com>
Mon, 24 Oct 2016 17:05:10 +0000 (13:05 -0400)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 26 Oct 2016 21:14:46 +0000 (21:14 +0000)
Don't include package path when creating LSyms for auto and param
variables during Prog generation, and update the DWARF emit routine
accordingly (remove the code that chops off package path from names in
DWARF var location expressions). Implementation suggested by mdempsky@.

The intent of this change is to have saner location expressions in cases
where the variable corresponds to a structure field. For example, the
SSA compiler's "decompose" phase can take a slice value and break it
apart into three scalar variables corresponding to the fields (slice "X"
gets split into "X.len", "X.cap", "X.ptr"). In such cases we want the
name in the location expression to omit the package path but preserve
the original variable name (e.g. "X").

Fixes #16338

Change-Id: Ibc444e7f3454b70fc500a33f0397e669d127daa1
Reviewed-on: https://go-review.googlesource.com/31819
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/pgen.go
src/cmd/internal/dwarf/dwarf.go
src/runtime/runtime-gdb_test.go

index a1665ea0220463b413ae2513fb75a079d8053d92..5d77ec66aa4b2d978f23e24532d00921714b8fa2 100644 (file)
@@ -423,6 +423,7 @@ func compile(fn *Node) {
                        fallthrough
                case PPARAM, PPARAMOUT:
                        p := Gins(obj.ATYPE, n, nil)
+                       p.From.Sym = obj.Linklookup(Ctxt, n.Sym.Name, 0)
                        p.To.Type = obj.TYPE_MEM
                        p.To.Name = obj.NAME_EXTERN
                        p.To.Sym = Linksym(ngotype(n))
index 58dcf4e55d5e4e788ef2c6b1d602e44c592b2d43..725f5027bb531636d89d31631036e56d85568821 100644 (file)
@@ -588,11 +588,6 @@ func PutFunc(ctxt Context, s Sym, name string, external bool, startPC Sym, size
                }
                names[n] = true
 
-               // Drop the package prefix from locals and arguments.
-               if i := strings.LastIndex(n, "."); i >= 0 {
-                       n = n[i+1:]
-               }
-
                Uleb128put(ctxt, s, int64(v.Abbrev))
                putattr(ctxt, s, v.Abbrev, DW_FORM_string, DW_CLS_STRING, int64(len(n)), n)
                loc := append(encbuf[:0], DW_OP_call_frame_cfa)
index ba005ac35b594c9de5ebbc426d0a36fddea6f1b4..3f2d74248ba3665f030514bb153e856ef65333de 100644 (file)
@@ -68,14 +68,18 @@ func checkGdbPython(t *testing.T) {
 const helloSource = `
 package main
 import "fmt"
+var gslice []string
 func main() {
        mapvar := make(map[string]string,5)
        mapvar["abc"] = "def"
        mapvar["ghi"] = "jkl"
        strvar := "abc"
        ptrvar := &strvar
-       fmt.Println("hi") // line 10
+       slicevar := make([]string, 0, 16)
+       slicevar = append(slicevar, mapvar["abc"])
+       fmt.Println("hi") // line 12
        _ = ptrvar
+       gslice = slicevar
 }
 `
 
@@ -120,6 +124,9 @@ func TestGdbPython(t *testing.T) {
                "-ex", "echo BEGIN print strvar\n",
                "-ex", "print strvar",
                "-ex", "echo END\n",
+               "-ex", "echo BEGIN info locals\n",
+               "-ex", "info locals",
+               "-ex", "echo END\n",
                "-ex", "down", // back to fmt.Println (goroutine 2 below only works at bottom of stack.  TODO: fix that)
                "-ex", "echo BEGIN goroutine 2 bt\n",
                "-ex", "goroutine 2 bt",
@@ -168,6 +175,15 @@ func TestGdbPython(t *testing.T) {
                t.Fatalf("print strvar failed: %s", bl)
        }
 
+       // Issue 16338: ssa decompose phase can split a structure into
+       // a collection of scalar vars holding the fields. In such cases
+       // the DWARF variable location expression should be of the
+       // form "var.field" and not just "field".
+       infoLocalsRe := regexp.MustCompile(`^slicevar.len = `)
+       if bl := blocks["info locals"]; !infoLocalsRe.MatchString(bl) {
+               t.Fatalf("info locals 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)