diff --git a/src/libsysprof/binfile.c b/src/libsysprof/binfile.c index b8cf7cc1..a68598ff 100644 --- a/src/libsysprof/binfile.c +++ b/src/libsysprof/binfile.c @@ -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);