From 793740b20ff685b832d900cfa2f61a6cea633416 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 2 May 2023 13:31:22 -0700 Subject: [PATCH] libsysprof-analyze: add SysprofSymbol The goal here is to get an object to represent a symbol so that we can more easily extend things in the future. We'll still use those pointers as unique in the stackstash in the future. --- src/libsysprof-analyze/meson.build | 2 + src/libsysprof-analyze/sysprof-analyze.h | 1 + .../sysprof-symbol-private.h | 32 ++++ src/libsysprof-analyze/sysprof-symbol.c | 155 ++++++++++++++++++ src/libsysprof-analyze/sysprof-symbol.h | 45 +++++ 5 files changed, 235 insertions(+) create mode 100644 src/libsysprof-analyze/sysprof-symbol-private.h create mode 100644 src/libsysprof-analyze/sysprof-symbol.c create mode 100644 src/libsysprof-analyze/sysprof-symbol.h diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index ba3136b7..430e474f 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -12,6 +12,7 @@ libsysprof_analyze_public_sources = [ 'sysprof-document-process-list.c', 'sysprof-document-sample.c', 'sysprof-document-traceable.c', + 'sysprof-symbol.c', ] libsysprof_analyze_public_headers = [ @@ -29,6 +30,7 @@ libsysprof_analyze_public_headers = [ 'sysprof-document-process-list.h', 'sysprof-document-sample.h', 'sysprof-document-traceable.h', + 'sysprof-symbol.h', ] libsysprof_analyze_deps = [ diff --git a/src/libsysprof-analyze/sysprof-analyze.h b/src/libsysprof-analyze/sysprof-analyze.h index 133bcb60..735fa683 100644 --- a/src/libsysprof-analyze/sysprof-analyze.h +++ b/src/libsysprof-analyze/sysprof-analyze.h @@ -38,6 +38,7 @@ G_BEGIN_DECLS # include "sysprof-document-process-list.h" # include "sysprof-document-sample.h" # include "sysprof-document-traceable.h" +# include "sysprof-symbol.h" #undef SYSPROF_ANALYZE_INSIDE G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-symbol-private.h b/src/libsysprof-analyze/sysprof-symbol-private.h new file mode 100644 index 00000000..acbc26ec --- /dev/null +++ b/src/libsysprof-analyze/sysprof-symbol-private.h @@ -0,0 +1,32 @@ +/* + * sysprof-symbol-private.h + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "sysprof-symbol.h" + +G_BEGIN_DECLS + +SysprofSymbol *_sysprof_symbol_new (char *name, + char *binary_nick, + char *binary_path); + +G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-symbol.c b/src/libsysprof-analyze/sysprof-symbol.c new file mode 100644 index 00000000..66c03c12 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-symbol.c @@ -0,0 +1,155 @@ +/* + * sysprof-symbol.c + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-symbol.h" + +struct _SysprofSymbol +{ + GObject parent_instance; + + /* All are GRefString */ + char *name; + char *binary_path; + char *binary_nick; +}; + +G_DEFINE_FINAL_TYPE (SysprofSymbol, sysprof_symbol, G_TYPE_OBJECT) + +enum { + PROP_0, + PROP_NAME, + PROP_BINARY_NICK, + PROP_BINARY_PATH, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_symbol_finalize (GObject *object) +{ + SysprofSymbol *self = (SysprofSymbol *)object; + + g_clear_pointer (&self->name, g_ref_string_release); + g_clear_pointer (&self->binary_path, g_ref_string_release); + g_clear_pointer (&self->binary_nick, g_ref_string_release); + + G_OBJECT_CLASS (sysprof_symbol_parent_class)->finalize (object); +} + +static void +sysprof_symbol_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofSymbol *self = SYSPROF_SYMBOL (object); + + switch (prop_id) + { + case PROP_NAME: + g_value_set_string (value, sysprof_symbol_get_name (self)); + break; + + case PROP_BINARY_NICK: + g_value_set_string (value, sysprof_symbol_get_binary_nick (self)); + break; + + case PROP_BINARY_PATH: + g_value_set_string (value, sysprof_symbol_get_binary_path (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_symbol_class_init (SysprofSymbolClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sysprof_symbol_finalize; + object_class->get_property = sysprof_symbol_get_property; + + properties [PROP_NAME] = + g_param_spec_string ("name", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties [PROP_BINARY_NICK] = + g_param_spec_string ("binary-nick", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties [PROP_BINARY_PATH] = + g_param_spec_string ("binary-path", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); +} + +static void +sysprof_symbol_init (SysprofSymbol *self) +{ +} + +const char * +sysprof_symbol_get_name (SysprofSymbol *self) +{ + g_return_val_if_fail (SYSPROF_IS_SYMBOL (self), NULL); + + return self->name; +} + +const char * +sysprof_symbol_get_binary_nick (SysprofSymbol *self) +{ + g_return_val_if_fail (SYSPROF_IS_SYMBOL (self), NULL); + + return self->binary_nick; +} + +const char * +sysprof_symbol_get_binary_path (SysprofSymbol *self) +{ + g_return_val_if_fail (SYSPROF_IS_SYMBOL (self), NULL); + + return self->binary_path; +} + +SysprofSymbol * +_sysprof_symbol_new (char *name, + char *binary_path, + char *binary_nick) +{ + SysprofSymbol *self; + + self = g_object_new (SYSPROF_TYPE_SYMBOL, NULL); + self->name = name ? g_ref_string_acquire (name) : NULL; + self->binary_path = binary_path ? g_ref_string_acquire (binary_path) : NULL; + self->binary_nick = binary_nick ? g_ref_string_acquire (binary_nick) : NULL; + + return self; +} diff --git a/src/libsysprof-analyze/sysprof-symbol.h b/src/libsysprof-analyze/sysprof-symbol.h new file mode 100644 index 00000000..01e0522b --- /dev/null +++ b/src/libsysprof-analyze/sysprof-symbol.h @@ -0,0 +1,45 @@ +/* + * sysprof-symbol.h + * + * Copyright 2023 Christian Hergert + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +#include + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_SYMBOL (sysprof_symbol_get_type()) + +SYSPROF_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (SysprofSymbol, sysprof_symbol, SYSPROF, SYMBOL, GObject) + +SYSPROF_AVAILABLE_IN_ALL +const char *sysprof_symbol_get_name (SysprofSymbol *self); +SYSPROF_AVAILABLE_IN_ALL +const char *sysprof_symbol_get_binary_nick (SysprofSymbol *self); +SYSPROF_AVAILABLE_IN_ALL +const char *sysprof_symbol_get_binary_path (SysprofSymbol *self); +SYSPROF_AVAILABLE_IN_ALL +gboolean sysprof_symbol_equal (const SysprofSymbol *a, + const SysprofSymbol *b); + +G_END_DECLS