libsysprof: improve decoding a bit from flatpak

This commit is contained in:
Christian Hergert
2019-08-02 13:22:03 -07:00
parent ba725d1599
commit 0c3f2df42b
2 changed files with 30 additions and 2 deletions

View File

@ -356,14 +356,18 @@ get_vdso_bytes (size_t *length)
bin_file_t *
bin_file_new (const char *filename)
{
const gchar *real_filename = filename;
ElfParser *elf = NULL;
bin_file_t *bf;
if (g_str_has_prefix (filename, "/var/run/host"))
real_filename = filename + strlen ("/var/run/host");
bf = g_new0 (bin_file_t, 1);
bf->inode_check = FALSE;
bf->filename = g_strdup (filename);
bf->undefined_name = g_strdup_printf ("In file %s", filename);
bf->undefined_name = g_strdup_printf ("In file %s", real_filename);
bf->ref_count = 1;
bf->elf_files = NULL;

View File

@ -126,6 +126,21 @@ sysprof_elf_symbol_resolver_load (SysprofSymbolResolver *resolver,
}
}
static gboolean
is_flatpak (void)
{
static gsize did_init = FALSE;
static gboolean ret;
if (g_once_init_enter (&did_init))
{
ret = g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
g_once_init_leave (&did_init, TRUE);
}
return ret;
}
static bin_file_t *
sysprof_elf_symbol_resolver_get_bin_file (SysprofElfSymbolResolver *self,
const gchar *filename)
@ -151,7 +166,16 @@ sysprof_elf_symbol_resolver_get_bin_file (SysprofElfSymbolResolver *self,
if (g_str_has_prefix (filename, "/newroot/"))
alternate += strlen ("/newroot");
bin_file = bin_file_new (alternate);
if (is_flatpak () && g_str_has_prefix (filename, "/usr/"))
{
g_autofree gchar *path = g_build_filename ("/var/run/host", alternate, NULL);
bin_file = bin_file_new (path);
}
else
{
bin_file = bin_file_new (alternate);
}
g_hash_table_insert (self->bin_files, g_strdup (filename), bin_file);
}