Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugger: clarify no debug info errors #2954

Merged
merged 2 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down