func TestAddr2Line(t *testing.T) {
testenv.MustHaveGoBuild(t)
- syms := loadSyms(t)
-
tmpDir, err := ioutil.TempDir("", "TestAddr2Line")
if err != nil {
t.Fatal("TempDir failed: ", err)
}
defer os.RemoveAll(tmpDir)
- exepath := filepath.Join(tmpDir, "testaddr2line.exe")
- out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", exepath, "cmd/addr2line").CombinedOutput()
+ // Build copy of test binary with debug symbols,
+ // since the one running now may not have them.
+ exepath := filepath.Join(tmpDir, "testaddr2line_test.exe")
+ out, err := exec.Command(testenv.GoToolPath(t), "test", "-c", "-o", exepath, "cmd/addr2line").CombinedOutput()
+ if err != nil {
+ t.Fatalf("go test -c -o %v cmd/addr2line: %v\n%s", exepath, err, string(out))
+ }
+ os.Args[0] = exepath
+
+ syms := loadSyms(t)
+
+ exepath = filepath.Join(tmpDir, "testaddr2line.exe")
+ out, err = exec.Command(testenv.GoToolPath(t), "build", "-o", exepath, "cmd/addr2line").CombinedOutput()
if err != nil {
t.Fatalf("go build -o %v cmd/addr2line: %v\n%s", exepath, err, string(out))
}
ExeName string // desired name for temporary executable
CoverMode string // preprocess Go source files with the coverage tool in this mode
CoverVars map[string]*CoverVar // variables created by coverage analysis
- OmitDWARF bool // tell linker not to write DWARF information
+ OmitDebug bool // tell linker not to write debug information
BuildID string // expected build ID for generated package
GobinSubdir bool // install target would be subdir of GOBIN
}
if p.Error != nil {
base.Fatalf("%s", p.Error)
}
- p.Internal.OmitDWARF = true
+ p.Internal.OmitDebug = true
if len(p.DepsErrors) > 0 {
// Since these are errors in dependencies,
// the same error might show up multiple times,
if cfg.BuildContext.InstallSuffix != "" {
ldflags = append(ldflags, "-installsuffix", cfg.BuildContext.InstallSuffix)
}
- if root.Package.Internal.OmitDWARF {
- ldflags = append(ldflags, "-w")
+ if root.Package.Internal.OmitDebug {
+ ldflags = append(ldflags, "-s", "-w")
}
if cfg.BuildBuildmode == "plugin" {
pluginpath := root.Package.ImportPath