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

pkg/proc,service/debugger: fix debuginfod-find source #3762

Merged
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
16 changes: 7 additions & 9 deletions pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ type BinaryInfo struct {

DebugInfoDirectories []string

// BuildID of this binary.
BuildID string

// Functions is a list of all DW_TAG_subprogram entries in debug_info, sorted by entry point
Functions []Function
// Sources is a list of all source files found in debug_line.
Expand Down Expand Up @@ -952,6 +949,7 @@ func (bi *BinaryInfo) PCToImage(pc uint64) *Image {
type Image struct {
Path string
StaticBase uint64
BuildID string
addr uint64

index int // index of this object in BinaryInfo.SharedObjects
Expand Down Expand Up @@ -1437,10 +1435,10 @@ func (bi *BinaryInfo) openSeparateDebugInfo(image *Image, exe *elf.File, debugIn
}
}

if debugFilePath == "" && len(bi.BuildID) > 2 {
if debugFilePath == "" && len(image.BuildID) > 2 {
// Build ID method: look for a file named .build-id/nn/nnnnnnnn.debug in
// every debug info directory.
find(nil, fmt.Sprintf(".build-id/%s/%s.debug", bi.BuildID[:2], bi.BuildID[2:]))
find(nil, fmt.Sprintf(".build-id/%s/%s.debug", image.BuildID[:2], image.BuildID[2:]))
}

if debugFilePath == "" {
Expand Down Expand Up @@ -1478,11 +1476,11 @@ func (bi *BinaryInfo) openSeparateDebugInfo(image *Image, exe *elf.File, debugIn
}
}

if debugFilePath == "" && len(bi.BuildID) > 2 {
if debugFilePath == "" && len(image.BuildID) > 2 {
// Previous versions of delve looked for the build id in every debug info
// directory that contained the build-id substring. This behavior deviates
// from the ones specified by GDB but we keep it for backwards compatibility.
find(func(dir string) bool { return strings.Contains(dir, "build-id") }, fmt.Sprintf("%s/%s.debug", bi.BuildID[:2], bi.BuildID[2:]))
find(func(dir string) bool { return strings.Contains(dir, "build-id") }, fmt.Sprintf("%s/%s.debug", image.BuildID[:2], image.BuildID[2:]))
}

if debugFilePath == "" {
Expand All @@ -1497,7 +1495,7 @@ func (bi *BinaryInfo) openSeparateDebugInfo(image *Image, exe *elf.File, debugIn
// has debuginfod so that we can use that in order to find any relevant debug information.
if debugFilePath == "" {
var err error
debugFilePath, err = debuginfod.GetDebuginfo(bi.BuildID)
debugFilePath, err = debuginfod.GetDebuginfo(image.BuildID)
if err != nil {
return nil, nil, ErrNoDebugInfoFound
}
Expand Down Expand Up @@ -1708,7 +1706,7 @@ func (bi *BinaryInfo) loadBuildID(image *Image, file *elf.File) {
bi.logger.Warnf("can't read build-id desc: %v", err)
return
}
bi.BuildID = hex.EncodeToString(descBinary)
image.BuildID = hex.EncodeToString(descBinary)
}

func (bi *BinaryInfo) getDebugLink(exe *elf.File) (debugLink string, crc uint32) {
Expand Down
7 changes: 6 additions & 1 deletion service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,12 @@ func (d *Debugger) TargetGroup() *proc.TargetGroup {
}

func (d *Debugger) BuildID() string {
return d.target.Selected.BinInfo().BuildID
loc, err := d.target.Selected.CurrentThread().Location()
if err != nil {
return ""
}
img := d.target.Selected.BinInfo().PCToImage(loc.PC)
return img.BuildID
}

func (d *Debugger) AttachPid() int {
Expand Down