[sysprof: 4/5] binfile: Use correct prefix for debug files




commit 32a743683754ed7e6f3b17365273a37ec34b4290
Author: Ivan Molodetskikh <yalterz gmail com>
Date:   Thu Oct 14 10:37:51 2021 +0300

    binfile: Use correct prefix for debug files

 src/libsysprof/binfile.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
---
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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]