From f7374f325272da8433f0fedbff2709055704bc79 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 3 May 2023 14:16:31 -0700 Subject: [PATCH] libsysprof-analyze: add minimal symbolizer API This exposes the types and hierarchy but won't expose the API details that we need internally. The idea here is that we can keep that private so we can adjust how it is used should we need to since the public interface would be the SysprofDocumentSymbols, not the SysprofSymbolizer which does decoding directly via address/context state. --- src/libsysprof-analyze/meson.build | 4 + src/libsysprof-analyze/sysprof-analyze.h | 2 + .../sysprof-multi-symbolizer.c | 77 +++++++++++++++++++ .../sysprof-multi-symbolizer.h | 45 +++++++++++ .../sysprof-symbolizer-private.h | 37 +++++++++ src/libsysprof-analyze/sysprof-symbolizer.c | 44 +++++++++++ src/libsysprof-analyze/sysprof-symbolizer.h | 42 ++++++++++ 7 files changed, 251 insertions(+) create mode 100644 src/libsysprof-analyze/sysprof-multi-symbolizer.c create mode 100644 src/libsysprof-analyze/sysprof-multi-symbolizer.h create mode 100644 src/libsysprof-analyze/sysprof-symbolizer-private.h create mode 100644 src/libsysprof-analyze/sysprof-symbolizer.c create mode 100644 src/libsysprof-analyze/sysprof-symbolizer.h diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index 430e474f..95772299 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -12,7 +12,9 @@ libsysprof_analyze_public_sources = [ 'sysprof-document-process-list.c', 'sysprof-document-sample.c', 'sysprof-document-traceable.c', + 'sysprof-multi-symbolizer.c', 'sysprof-symbol.c', + 'sysprof-symbolizer.c', ] libsysprof_analyze_public_headers = [ @@ -30,7 +32,9 @@ libsysprof_analyze_public_headers = [ 'sysprof-document-process-list.h', 'sysprof-document-sample.h', 'sysprof-document-traceable.h', + 'sysprof-multi-symbolizer.h', 'sysprof-symbol.h', + 'sysprof-symbolizer.h', ] libsysprof_analyze_deps = [ diff --git a/src/libsysprof-analyze/sysprof-analyze.h b/src/libsysprof-analyze/sysprof-analyze.h index 735fa683..c84348b0 100644 --- a/src/libsysprof-analyze/sysprof-analyze.h +++ b/src/libsysprof-analyze/sysprof-analyze.h @@ -38,7 +38,9 @@ G_BEGIN_DECLS # include "sysprof-document-process-list.h" # include "sysprof-document-sample.h" # include "sysprof-document-traceable.h" +# include "sysprof-multi-symbolizer.h" # include "sysprof-symbol.h" +# include "sysprof-symbolizer.h" #undef SYSPROF_ANALYZE_INSIDE G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-multi-symbolizer.c b/src/libsysprof-analyze/sysprof-multi-symbolizer.c new file mode 100644 index 00000000..2b386907 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-multi-symbolizer.c @@ -0,0 +1,77 @@ +/* sysprof-multi-symbolizer.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-multi-symbolizer.h" +#include "sysprof-symbolizer-private.h" + +struct _SysprofMultiSymbolizer +{ + SysprofSymbolizer parent_instance; + GPtrArray *symbolizers; +}; + +struct _SysprofMultiSymbolizerClass +{ + SysprofSymbolizerClass parent_class; +}; + +G_DEFINE_FINAL_TYPE (SysprofMultiSymbolizer, sysprof_multi_symbolizer, SYSPROF_TYPE_SYMBOLIZER) + +static void +sysprof_multi_symbolizer_finalize (GObject *object) +{ + SysprofMultiSymbolizer *self = (SysprofMultiSymbolizer *)object; + + g_clear_pointer (&self->symbolizers, g_ptr_array_unref); + + G_OBJECT_CLASS (sysprof_multi_symbolizer_parent_class)->finalize (object); +} + +static void +sysprof_multi_symbolizer_class_init (SysprofMultiSymbolizerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sysprof_multi_symbolizer_finalize; +} + +static void +sysprof_multi_symbolizer_init (SysprofMultiSymbolizer *self) +{ + self->symbolizers = g_ptr_array_new_with_free_func (g_object_unref); +} + +SysprofMultiSymbolizer * +sysprof_multi_symbolizer_new (void) +{ + return g_object_new (SYSPROF_TYPE_MULTI_SYMBOLIZER, NULL); +} + +void +sysprof_multi_symbolizer_add (SysprofMultiSymbolizer *self, + SysprofSymbolizer *symbolizer) +{ + g_return_if_fail (SYSPROF_IS_MULTI_SYMBOLIZER (self)); + g_return_if_fail (SYSPROF_IS_SYMBOLIZER (symbolizer)); + + g_ptr_array_add (self->symbolizers, g_object_ref (symbolizer)); +} diff --git a/src/libsysprof-analyze/sysprof-multi-symbolizer.h b/src/libsysprof-analyze/sysprof-multi-symbolizer.h new file mode 100644 index 00000000..9beffe91 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-multi-symbolizer.h @@ -0,0 +1,45 @@ +/* sysprof-multi-symbolizer.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-symbolizer.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_MULTI_SYMBOLIZER (sysprof_multi_symbolizer_get_type()) +#define SYSPROF_IS_MULTI_SYMBOLIZER(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_MULTI_SYMBOLIZER) +#define SYSPROF_MULTI_SYMBOLIZER(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_MULTI_SYMBOLIZER, SysprofMultiSymbolizer) +#define SYSPROF_MULTI_SYMBOLIZER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_MULTI_SYMBOLIZER, SysprofMultiSymbolizerClass) + +typedef struct _SysprofMultiSymbolizer SysprofMultiSymbolizer; +typedef struct _SysprofMultiSymbolizerClass SysprofMultiSymbolizerClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_multi_symbolizer_get_type (void) G_GNUC_CONST; +SYSPROF_AVAILABLE_IN_ALL +SysprofMultiSymbolizer *sysprof_multi_symbolizer_new (void); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_multi_symbolizer_add (SysprofMultiSymbolizer *self, + SysprofSymbolizer *symbolizer); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofMultiSymbolizer, g_object_unref) + +G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-symbolizer-private.h b/src/libsysprof-analyze/sysprof-symbolizer-private.h new file mode 100644 index 00000000..d7f65b75 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-symbolizer-private.h @@ -0,0 +1,37 @@ +/* sysprof-symbolizer-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-symbolizer.h" + +G_BEGIN_DECLS + +struct _SysprofSymbolizer +{ + GObject parent; +}; + +struct _SysprofSymbolizerClass +{ + GObjectClass parent_class; +}; + +G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-symbolizer.c b/src/libsysprof-analyze/sysprof-symbolizer.c new file mode 100644 index 00000000..bc8642c1 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-symbolizer.c @@ -0,0 +1,44 @@ +/* sysprof-symbolizer.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-symbolizer-private.h" + +G_DEFINE_ABSTRACT_TYPE (SysprofSymbolizer, sysprof_symbolizer, G_TYPE_OBJECT) + +static void +sysprof_symbolizer_finalize (GObject *object) +{ + G_OBJECT_CLASS (sysprof_symbolizer_parent_class)->finalize (object); +} + +static void +sysprof_symbolizer_class_init (SysprofSymbolizerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sysprof_symbolizer_finalize; +} + +static void +sysprof_symbolizer_init (SysprofSymbolizer *self) +{ +} diff --git a/src/libsysprof-analyze/sysprof-symbolizer.h b/src/libsysprof-analyze/sysprof-symbolizer.h new file mode 100644 index 00000000..929007bc --- /dev/null +++ b/src/libsysprof-analyze/sysprof-symbolizer.h @@ -0,0 +1,42 @@ +/* sysprof-symbolizer.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_SYMBOLIZER (sysprof_symbolizer_get_type()) +#define SYSPROF_IS_SYMBOLIZER(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_SYMBOLIZER) +#define SYSPROF_SYMBOLIZER(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_SYMBOLIZER, SysprofSymbolizer) +#define SYSPROF_SYMBOLIZER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_SYMBOLIZER, SysprofSymbolizerClass) + +typedef struct _SysprofSymbolizer SysprofSymbolizer; +typedef struct _SysprofSymbolizerClass SysprofSymbolizerClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_symbolizer_get_type (void) G_GNUC_CONST; + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofSymbolizer, g_object_unref) + +G_END_DECLS