Commit 9d5f9721 authored by Anton Blanchard's avatar Anton Blanchard

Fix debuginfo search on Ubuntu

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: default avatarAnton Blanchard <anton@ozlabs.org>
parent e94833fd
...@@ -453,6 +453,21 @@ static int verify_checksum(const char *file, unsigned int crc) { ...@@ -453,6 +453,21 @@ static int verify_checksum(const char *file, unsigned int crc) {
return actual == 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, static char *find_debug_via_debuglink(Elf *e, const char *binpath,
int check_crc) { int check_crc) {
char fullpath[PATH_MAX]; char fullpath[PATH_MAX];
...@@ -473,7 +488,7 @@ static char *find_debug_via_debuglink(Elf *e, const char *binpath, ...@@ -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) // and it might contain poorer symbols (e.g. stripped or partial symbols)
// than the external debuginfo that might be available elsewhere. // than the external debuginfo that might be available elsewhere.
snprintf(fullpath, sizeof(fullpath),"%s/%s", bindir, name); 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); res = strdup(fullpath);
goto DONE; goto DONE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment