gcc/libgo/go/runtime/crash_gccgo_test.go
Ian Lance Taylor 74e6f14adb runtime: get missing function name from symbol table
If we trace back through code that has no debug info, as when calling
    through C code compiled with -g0, we won't have a function name.
    Try to fetch the function name using the symbol table.
    
    Adding the test case revealed that gotest failed to use the gccgo tag
    when matching files, so add that.
    
    Reviewed-on: https://go-review.googlesource.com/92756

From-SVN: r257495
2018-02-08 15:37:43 +00:00

60 lines
1.3 KiB
Go

// Copyright 2018 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.
// +build cgo,gccgo
package runtime_test
import (
"bytes"
"fmt"
"internal/testenv"
"os"
"os/exec"
"strings"
"testing"
)
func TestGccgoCrashTraceback(t *testing.T) {
t.Parallel()
got := runTestProg(t, "testprogcgo", "CrashTracebackGccgo")
ok := true
for i := 1; i <= 3; i++ {
if !strings.Contains(got, fmt.Sprintf("CFunction%d", i)) {
t.Errorf("missing C function CFunction%d", i)
ok = false
}
}
if !ok {
t.Log(got)
}
}
func TestGccgoCrashTracebackNodebug(t *testing.T) {
testenv.MustHaveGoBuild(t)
if os.Getenv("CC") == "" {
t.Skip("no compiler in environment")
}
cc := strings.Fields(os.Getenv("CC"))
cc = append(cc, "-x", "c++", "-")
out, _ := exec.Command(cc[0], cc[1:]...).CombinedOutput()
if bytes.Contains(out, []byte("error trying to exec 'cc1plus'")) {
t.Skip("no C++ compiler")
}
os.Setenv("CXX", os.Getenv("CC"))
got := runTestProg(t, "testprogcxx", "CrashTracebackNodebug")
ok := true
for i := 1; i <= 3; i++ {
if !strings.Contains(got, fmt.Sprintf("cxxFunction%d", i)) {
t.Errorf("missing C++ function cxxFunction%d", i)
ok = false
}
}
if !ok {
t.Log(got)
}
}