Skip to content

Commit

Permalink
Fix local debuginfo file discovery
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun committed Mar 18, 2022
1 parent 5c3ea8c commit ecfc16a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
1 change: 1 addition & 0 deletions deploy/dev.jsonnet
Expand Up @@ -25,6 +25,7 @@ function(serverVersion='v0.4.2')
logLevel: 'debug',
insecure: true,
insecureSkipVerify: true,
// debugInfoDisable: true,
tempDir: '/tmp',
// podLabelSelector: 'app.kubernetes.io/name=parca',
});
Expand Down
46 changes: 12 additions & 34 deletions pkg/debuginfo/find.go
Expand Up @@ -19,14 +19,10 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"

"github.com/go-kit/log"
"github.com/goburrow/cache"

"github.com/parca-dev/parca-agent/pkg/buildid"
)

// Finder finds the additional debug information on the system.
Expand Down Expand Up @@ -77,38 +73,20 @@ func (f *Finder) Find(ctx context.Context, buildID, root string) (string, error)
}

func find(buildID, root string) (string, error) {
var (
found = false
file string
)
// TODO(kakkoyun): Distros may have different locations for debuginfo files.
// Add support for all of them. Add an issue fir this.
err := filepath.Walk(path.Join(root, "/usr/lib/debug"), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
id, err := buildid.BuildID(path)
if err != nil {
return fmt.Errorf("failed to extract elf build ID, %w", err)
}
if strings.EqualFold(id, buildID) {
found = true
file = path
}
}
return nil
})
if err != nil {
if os.IsNotExist(err) {
return "", errNotFound
}

return "", fmt.Errorf("failed to walk debug files: %w", err)
// Debian: /usr/lib/debug/.build-id/f9/02f8a561c3abdb9c8d8c859d4243bd8c3f928f.debug
// -- apt install <package>-dbg
// Fedora: /usr/lib/debug/.build-id/da/40581445b62eff074d67fae906792cb26e8d54.debug
// -- dnf --enablerepo=fedora-debuginfo --enablerepo=updates-debuginfo install <package>-debuginfo
// Arch: https://wiki.archlinux.org/title/Debugging/Getting_traces
file := filepath.Join(root, "/usr/lib/debug", ".build-id", buildID[:2], buildID[2:])
_, err := os.Stat(file)
if err == nil {
return file, nil
}

if !found {
if os.IsNotExist(err) {
return "", errNotFound
}
return file, nil

return "", fmt.Errorf("failed to search debug files: %w", err)
}

0 comments on commit ecfc16a

Please sign in to comment.