mirror of
https://github.com/golang/go
synced 2024-11-18 06:04:53 -07:00
cmd/compile: avoid truncating fieldname var locations
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>
This commit is contained in:
parent
c7e0dda450
commit
d80e8de54e
@ -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))
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user