Skip to content

Commit

Permalink
Fix debuginfo search on Ubuntu
Browse files Browse the repository at this point in the history
bcc on Ubuntu picks up the glibc binary instead of the debuginfo file
because find_debug_via_debuglink() doesn't handle symbolic or hard
links when checking if two paths point to the same file.

Add a helper, same_file() which uses the device and inode to check if
the two paths do point to the same file.

Signed-off-by: Anton Blanchard <[email protected]>
  • Loading branch information
antonblanchard committed Feb 1, 2019
1 parent e94833f commit 9d5f972
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/cc/bcc_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,21 @@ static int verify_checksum(const char *file, unsigned int crc) {
return actual == crc;
}

// Check if two filenames point to the same file, including hard or soft links.
static bool same_file(char *a, const char *b)
{
struct stat stat_a, stat_b;

if (stat(a, &stat_a) || stat(b, &stat_b))
return false;

if ((stat_a.st_dev == stat_b.st_dev) &&
(stat_a.st_ino == stat_b.st_ino))
return true;
else
return false;
}

static char *find_debug_via_debuglink(Elf *e, const char *binpath,
int check_crc) {
char fullpath[PATH_MAX];
Expand All @@ -473,7 +488,7 @@ static char *find_debug_via_debuglink(Elf *e, const char *binpath,
// and it might contain poorer symbols (e.g. stripped or partial symbols)
// than the external debuginfo that might be available elsewhere.
snprintf(fullpath, sizeof(fullpath),"%s/%s", bindir, name);
if (strcmp(fullpath, binpath) != 0 && access(fullpath, F_OK) != -1) {
if (same_file(fullpath, binpath) != true && access(fullpath, F_OK) != -1) {
res = strdup(fullpath);
goto DONE;
}
Expand Down

0 comments on commit 9d5f972

Please sign in to comment.