mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-analyze: give shape to ELF loading APIs
We need to separate a number of concerns here, such as debug-dirs within the process namespace vs global debug-dirs (external symbols on a developer workstation vs IoT/Laptop/VM/alternate-device). That means we need to be able to resolve paths via the mount namespace of the process as it was seen in the capture file. Additionally, we need to follow .gnu_debuglink section headers so that we can associate the version with symbols with the ELF that is loaded from the processes SysprofAddressLayout.
This commit is contained in:
201
src/libsysprof-analyze/sysprof-elf.c
Normal file
201
src/libsysprof-analyze/sysprof-elf.c
Normal file
@ -0,0 +1,201 @@
|
||||
/* sysprof-elf.c
|
||||
*
|
||||
* Copyright 2023 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "sysprof-elf-private.h"
|
||||
|
||||
struct _SysprofElf
|
||||
{
|
||||
GObject parent_instance;
|
||||
char *build_id;
|
||||
char *debug_link;
|
||||
SysprofElf *debug_link_elf;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_BUILD_ID,
|
||||
PROP_DEBUG_LINK,
|
||||
PROP_DEBUG_LINK_ELF,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (SysprofElf, sysprof_elf, G_TYPE_OBJECT)
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
sysprof_elf_finalize (GObject *object)
|
||||
{
|
||||
SysprofElf *self = (SysprofElf *)object;
|
||||
|
||||
g_clear_pointer (&self->build_id, g_free);
|
||||
g_clear_pointer (&self->debug_link, g_free);
|
||||
g_clear_object (&self->debug_link_elf);
|
||||
|
||||
G_OBJECT_CLASS (sysprof_elf_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_elf_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofElf *self = SYSPROF_ELF (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_BUILD_ID:
|
||||
g_value_set_string (value, sysprof_elf_get_build_id (self));
|
||||
break;
|
||||
|
||||
case PROP_DEBUG_LINK:
|
||||
g_value_set_string (value, sysprof_elf_get_debug_link (self));
|
||||
break;
|
||||
|
||||
case PROP_DEBUG_LINK_ELF:
|
||||
g_value_set_object (value, sysprof_elf_get_debug_link_elf (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_elf_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofElf *self = SYSPROF_ELF (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DEBUG_LINK_ELF:
|
||||
sysprof_elf_set_debug_link_elf (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_elf_class_init (SysprofElfClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = sysprof_elf_finalize;
|
||||
object_class->get_property = sysprof_elf_get_property;
|
||||
object_class->set_property = sysprof_elf_set_property;
|
||||
|
||||
properties [PROP_BUILD_ID] =
|
||||
g_param_spec_string ("build-id", NULL, NULL,
|
||||
NULL,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_DEBUG_LINK] =
|
||||
g_param_spec_string ("debug-link", NULL, NULL,
|
||||
NULL,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_DEBUG_LINK_ELF] =
|
||||
g_param_spec_object ("debug-link-elf", NULL, NULL,
|
||||
SYSPROF_TYPE_ELF,
|
||||
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_elf_init (SysprofElf *self)
|
||||
{
|
||||
}
|
||||
|
||||
SysprofElf *
|
||||
sysprof_elf_new (const char *filename,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
sysprof_elf_get_build_id (SysprofElf *self)
|
||||
{
|
||||
g_return_val_if_fail (SYSPROF_IS_ELF (self), NULL);
|
||||
|
||||
return self->build_id;
|
||||
}
|
||||
|
||||
const char *
|
||||
sysprof_elf_get_debug_link (SysprofElf *self)
|
||||
{
|
||||
g_return_val_if_fail (SYSPROF_IS_ELF (self), NULL);
|
||||
|
||||
return self->debug_link;
|
||||
}
|
||||
|
||||
const char *
|
||||
sysprof_elf_get_symbol_at_address (SysprofElf *self,
|
||||
guint64 address,
|
||||
guint64 *begin_address,
|
||||
guint64 *end_address)
|
||||
{
|
||||
g_return_val_if_fail (SYSPROF_IS_ELF (self), NULL);
|
||||
g_return_val_if_fail (begin_address != NULL, NULL);
|
||||
g_return_val_if_fail (end_address != NULL, NULL);
|
||||
|
||||
*begin_address = *end_address = 0;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* sysprof_elf_get_debug_link_elf:
|
||||
* @self: a #SysprofElf
|
||||
*
|
||||
* Gets a #SysprofElf that was resolved from the `.gnu_debuglink`
|
||||
* ELF section header.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): a #SysprofElf or %NULL
|
||||
*/
|
||||
SysprofElf *
|
||||
sysprof_elf_get_debug_link_elf (SysprofElf *self)
|
||||
{
|
||||
g_return_val_if_fail (SYSPROF_IS_ELF (self), NULL);
|
||||
|
||||
return self->debug_link_elf;
|
||||
}
|
||||
|
||||
void
|
||||
sysprof_elf_set_debug_link_elf (SysprofElf *self,
|
||||
SysprofElf *debug_link_elf)
|
||||
{
|
||||
g_return_if_fail (SYSPROF_IS_ELF (self));
|
||||
g_return_if_fail (!debug_link_elf || SYSPROF_IS_ELF (debug_link_elf));
|
||||
|
||||
if (g_set_object (&self->debug_link_elf, debug_link_elf))
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_DEBUG_LINK_ELF]);
|
||||
}
|
||||
Reference in New Issue
Block a user