delve/cmd/dlv/main.go
Alessandro Arzilli c9c455cc38 cmd/dlv: actually disable C compiler optimizations when building (#1647)
* proc: fix stacktraces when a SIGSEGV happens during a cgo call

When a SIGSEGV happens in a cgo call (for example as a result of
dereferencing a NULL pointer) the stack layout will look like this:

(system stack) runtime.fatalthrow
(system stack) runtime.throw
(system stack) runtime.sigpanic
(system stack) offending C function
... other C functions...
(system stack) runtime.asmcgocall
(goroutine stack) call inside cgo

The code in switchStack would switch directly from the
runtime.fatalthrow frame to the first frame in the goroutine stack,
hiding important information.

Disable this switch for runtime.fatalthrow and reintroduce the check
for runtime.mstart that existed before this version of the code was
implemented in commit 7bec20.

This problem was reported in comment:
https://github.com/go-delve/delve/issues/935#issuecomment-512182533

* cmd/dlv: actually disable C compiler optimizations when building
2019-08-01 16:31:50 -07:00

26 lines
547 B
Go

package main
import (
"os"
"github.com/go-delve/delve/cmd/dlv/cmds"
"github.com/go-delve/delve/pkg/version"
"github.com/sirupsen/logrus"
)
// Build is the git sha of this binaries build.
var Build string
func main() {
if Build != "" {
version.DelveVersion.Build = Build
}
const cgoCflagsEnv = "CGO_CFLAGS"
if os.Getenv(cgoCflagsEnv) == "" {
os.Setenv(cgoCflagsEnv, "-O0 -g")
} else {
logrus.WithFields(logrus.Fields{"layer": "dlv"}).Warnln("CGO_CFLAGS already set, Cgo code could be optimized.")
}
cmds.New(false).Execute()
}