proc: resolve symlinks when searching for split debug_info if path is /proc/pid/exe (#2170)

* Revert "proc: Find executable should follow symbol links."

This reverts commit 3e04ad0fada0c3ab57caf58bc024e4c0f9a3e01a.

* proc: resolve symlinks when searching for split debug_info if path is /proc/pid/exe

Fixes #2168
This commit is contained in:
Alessandro Arzilli 2020-09-15 23:49:30 +02:00 committed by GitHub
parent 347777295d
commit 85952c0826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

@ -1037,6 +1037,11 @@ func (bi *BinaryInfo) openSeparateDebugInfo(image *Image, exe *elf.File, debugIn
continue continue
} }
potentialDebugFilePath = fmt.Sprintf("%s/%s/%s.debug", dir, desc1, desc2) potentialDebugFilePath = fmt.Sprintf("%s/%s/%s.debug", dir, desc1, desc2)
} else if strings.HasPrefix(image.Path, "/proc") {
path, err := filepath.EvalSymlinks(image.Path)
if err == nil {
potentialDebugFilePath = fmt.Sprintf("%s/%s.debug", dir, filepath.Base(path))
}
} else { } else {
potentialDebugFilePath = fmt.Sprintf("%s/%s.debug", dir, filepath.Base(image.Path)) potentialDebugFilePath = fmt.Sprintf("%s/%s.debug", dir, filepath.Base(image.Path))
} }

@ -130,12 +130,7 @@ func Attach(pid int, debugInfoDirs []string) (*proc.Target, error) {
return nil, err return nil, err
} }
execPath, err := findExecutable(pid) tgt, err := dbp.initialize(findExecutable("", dbp.pid), debugInfoDirs)
if err != nil {
return nil, err
}
tgt, err := dbp.initialize(execPath, debugInfoDirs)
if err != nil { if err != nil {
_ = dbp.Detach(false) _ = dbp.Detach(false)
return nil, err return nil, err
@ -265,9 +260,11 @@ func (dbp *nativeProcess) updateThreadList() error {
return linutil.ElfUpdateSharedObjects(dbp) return linutil.ElfUpdateSharedObjects(dbp)
} }
func findExecutable(pid int) (string, error) { func findExecutable(path string, pid int) string {
path := fmt.Sprintf("/proc/%d/exe", pid) if path == "" {
return filepath.EvalSymlinks(path) path = fmt.Sprintf("/proc/%d/exe", pid)
}
return path
} }
func (dbp *nativeProcess) trapWait(pid int) (*nativeThread, error) { func (dbp *nativeProcess) trapWait(pid int) (*nativeThread, error) {