Skip to content

Commit

Permalink
proc: Find executable should follow symbol links.
Browse files Browse the repository at this point in the history
On linux platform, we simply treated `/proc/$pid/exe` as the
executable of targeting process when doing `dlv attach`. The
`/proc/$pid/exe` is a symbol link of the real executable file.
Delve couldn't find the corrsponding external debug file based on the
symbol link:

```
could not attach to pid $pid: could not open debug info
```

The fix is to evaluate the symbol links to the actual executable path.
  • Loading branch information
coderplay authored and derekparker committed Apr 27, 2020
1 parent 37bee98 commit 3e04ad0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/proc/native/proc_linux.go
Expand Up @@ -119,7 +119,12 @@ func Attach(pid int, debugInfoDirs []string) (*proc.Target, error) {
return nil, err
}

tgt, err := dbp.initialize(findExecutable("", dbp.pid), debugInfoDirs)
execPath, err := findExecutable(pid)
if err != nil {
return nil, err
}

tgt, err := dbp.initialize(execPath, debugInfoDirs)
if err != nil {
dbp.Detach(false)
return nil, err
Expand Down Expand Up @@ -249,11 +254,9 @@ func (dbp *nativeProcess) updateThreadList() error {
return linutil.ElfUpdateSharedObjects(dbp)
}

func findExecutable(path string, pid int) string {
if path == "" {
path = fmt.Sprintf("/proc/%d/exe", pid)
}
return path
func findExecutable(pid int) (string, error) {
path := fmt.Sprintf("/proc/%d/exe", pid)
return filepath.EvalSymlinks(path)
}

func (dbp *nativeProcess) trapWait(pid int) (*nativeThread, error) {
Expand Down

0 comments on commit 3e04ad0

Please sign in to comment.