diff --git a/src/libsysprof-analyze/sysprof-elf-loader.c b/src/libsysprof-analyze/sysprof-elf-loader.c index 1437c827..c035f797 100644 --- a/src/libsysprof-analyze/sysprof-elf-loader.c +++ b/src/libsysprof-analyze/sysprof-elf-loader.c @@ -299,7 +299,7 @@ sysprof_elf_loader_load (SysprofElfLoader *self, if (!(mapped_file = g_mapped_file_new (path, FALSE, NULL))) continue; - if (!(elf = sysprof_elf_new (mapped_file, &local_error))) + if (!(elf = sysprof_elf_new (path, g_steal_pointer (&mapped_file), &local_error))) continue; if ((debug_link = sysprof_elf_get_debug_link (elf))) diff --git a/src/libsysprof-analyze/sysprof-elf-private.h b/src/libsysprof-analyze/sysprof-elf-private.h index b0191389..95a1d51b 100644 --- a/src/libsysprof-analyze/sysprof-elf-private.h +++ b/src/libsysprof-analyze/sysprof-elf-private.h @@ -28,7 +28,8 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (SysprofElf, sysprof_elf, SYSPROF, ELF, GObject) -SysprofElf *sysprof_elf_new (GMappedFile *mapped_file, +SysprofElf *sysprof_elf_new (const char *filename, + GMappedFile *mapped_file, GError **error); const char *sysprof_elf_get_file (SysprofElf *self); const char *sysprof_elf_get_build_id (SysprofElf *self); diff --git a/src/libsysprof-analyze/sysprof-elf.c b/src/libsysprof-analyze/sysprof-elf.c index e287fd2b..1cc50502 100644 --- a/src/libsysprof-analyze/sysprof-elf.c +++ b/src/libsysprof-analyze/sysprof-elf.c @@ -20,6 +20,8 @@ #include "config.h" +#include "../libsysprof/elfparser.h" + #include "sysprof-elf-private.h" struct _SysprofElf @@ -29,6 +31,7 @@ struct _SysprofElf char *debug_link; char *file; SysprofElf *debug_link_elf; + ElfParser *parser; }; enum { @@ -52,6 +55,7 @@ sysprof_elf_finalize (GObject *object) g_clear_pointer (&self->build_id, g_free); g_clear_pointer (&self->debug_link, g_free); g_clear_pointer (&self->file, g_free); + g_clear_pointer (&self->parser, elf_parser_free); g_clear_object (&self->debug_link_elf); G_OBJECT_CLASS (sysprof_elf_parent_class)->finalize (object); @@ -145,12 +149,23 @@ sysprof_elf_init (SysprofElf *self) } SysprofElf * -sysprof_elf_new (GMappedFile *mapped_file, +sysprof_elf_new (const char *filename, + GMappedFile *mapped_file, GError **error) { + SysprofElf *self; + ElfParser *parser; + g_return_val_if_fail (mapped_file != NULL, NULL); - return NULL; + if (!(parser = elf_parser_new_from_mmap (g_steal_pointer (&mapped_file), error))) + return NULL; + + self = g_object_new (SYSPROF_TYPE_ELF, NULL); + self->file = g_strdup (filename); + self->parser = g_steal_pointer (&parser); + + return self; } const char *