binfile: Use correct prefix for debug files

This commit is contained in:
Ivan Molodetskikh
2021-10-14 10:37:51 +03:00
parent 46e7e31f45
commit 32a7436837

View File

@ -157,6 +157,8 @@ get_debuglink_file (ElfParser *elf,
ElfParser *result = NULL;
const char *build_id;
char *dir;
const char *files;
const char *prefix = "";
if (!elf)
return NULL;
@ -174,13 +176,29 @@ get_debuglink_file (ElfParser *elf,
dir = g_path_get_dirname (filename);
/* Flatpak paths have the form of ".../files/bin" or ".../files/lib/x86_64-linux-gnu". */
files = g_strrstr (dir, "/files/");
if (files)
prefix = files + sizeof ("/files/") - 1;
for (guint i = 0; debug_dirs[i]; i++)
{
char *name = g_build_filename (debug_dirs[i], basename, NULL);
/* Most files from Flatpak will be from .Platform, which usually has a prefix like "lib/x86_64-linux-gnu"
* but in the debug dir the files are under "usr/lib/x86_64-linux-gnu", so try with "usr" first. */
g_autofree char *name = g_build_filename (debug_dirs[i], "usr", prefix, basename, NULL);
ElfParser *parser = elf_parser_new (name, NULL);
guint32 file_crc;
const char *file_build_id;
if (!parser)
{
/* Files from Flatpak com.example.App.Debug have prefixes like "bin" or "lib",
* and they don't need the "usr" for the debug dir, so try without "usr". */
g_free (name);
name = g_build_filename (debug_dirs[i], prefix, basename, NULL);
parser = elf_parser_new (name, NULL);
}
if (parser)
{
/* If both files have build ids, and they don't match,
@ -211,8 +229,6 @@ get_debuglink_file (ElfParser *elf,
skip:
elf_parser_free (parser);
}
g_free (name);
}
g_free (dir);