mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile,cmd/link: export int global consts to DWARF
Updates #14517 Change-Id: I23ef88e71c89da12dffcadf5562ea2d7557b62cf Reviewed-on: https://go-review.googlesource.com/61019 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
f366379d84
commit
9daee93121
6 changed files with 173 additions and 29 deletions
|
|
@ -381,3 +381,61 @@ func TestGdbAutotmpTypes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
const constsSource = `
|
||||
package main
|
||||
|
||||
const aConstant int = 42
|
||||
const largeConstant uint64 = ^uint64(0)
|
||||
const minusOne int64 = -1
|
||||
|
||||
func main() {
|
||||
println("hello world")
|
||||
}
|
||||
`
|
||||
|
||||
func TestGdbConst(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(constsSource), 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.CleanCmdEnv(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", "print main.aConstant",
|
||||
"-ex", "print main.largeConstant",
|
||||
"-ex", "print main.minusOne",
|
||||
"-ex", "print 'runtime._MSpanInUse'",
|
||||
filepath.Join(dir, "a.exe"),
|
||||
}
|
||||
got, _ := exec.Command("gdb", args...).CombinedOutput()
|
||||
|
||||
sgot := string(got)
|
||||
|
||||
t.Logf("output %q", sgot)
|
||||
|
||||
if strings.Index(sgot, "\n$1 = 42\n$2 = 18446744073709551615\n$3 = -1\n$4 = 1 '\\001'") < 0 {
|
||||
t.Fatalf("output mismatch")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue