debugger: clarify no debug info errors (#2954)

* debugger: clarify no debug info errors

* Fix typo

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
polinasok 2022-04-01 10:31:03 -07:00 committed by GitHub
parent 65e03d673d
commit 6c368b78a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

@ -26,6 +26,7 @@ import (
"github.com/go-delve/delve/pkg/terminal"
"github.com/go-delve/delve/service/dap"
"github.com/go-delve/delve/service/dap/daptest"
"github.com/go-delve/delve/service/debugger"
"github.com/go-delve/delve/service/rpc2"
godap "github.com/google/go-dap"
"golang.org/x/tools/go/packages"
@ -301,8 +302,8 @@ func TestChildProcessExitWhenNoDebugInfo(t *testing.T) {
t.Fatalf("Expected err when launching the binary without debug info, but got nil")
}
// Test only for dlv's prefix of the error like "could not launch process: could not open debug info"
if !strings.Contains(string(out), "could not launch process") {
t.Fatalf("Expected logged error 'could not launch process: ...'")
if !strings.Contains(string(out), "could not launch process") || !strings.Contains(string(out), debugger.NoDebugWarning) {
t.Fatalf("Expected logged error 'could not launch process: ... - %s'", debugger.NoDebugWarning)
}
// search the running process named fix.Name

@ -162,6 +162,7 @@ func New(config *Config, processArgs []string) (*Debugger, error) {
p, err := d.Attach(d.config.AttachPid, path)
if err != nil {
err = go11DecodeErrorCheck(err)
err = noDebugErrorWarning(err)
return nil, attachErrorMessage(d.config.AttachPid, err)
}
d.target = p
@ -193,6 +194,7 @@ func New(config *Config, processArgs []string) (*Debugger, error) {
if err != nil {
if _, ok := err.(*proc.ErrUnsupportedArch); !ok {
err = go11DecodeErrorCheck(err)
err = noDebugErrorWarning(err)
err = fmt.Errorf("could not launch process: %s", err)
}
return nil, err
@ -2240,6 +2242,15 @@ func go11DecodeErrorCheck(err error) error {
return fmt.Errorf("executables built by Go 1.11 or later need Delve built by Go 1.11 or later")
}
const NoDebugWarning string = "debuggee must not be built with 'go run' or -ldflags='-s -w', which strip debug info"
func noDebugErrorWarning(err error) error {
if _, isdecodeerr := err.(dwarf.DecodeError); isdecodeerr || strings.Contains(err.Error(), "could not open debug info") {
return fmt.Errorf("%s - %s", err.Error(), NoDebugWarning)
}
return err
}
type breakpointsByLogicalID []*proc.Breakpoint
func (v breakpointsByLogicalID) Len() int { return len(v) }