From 9e01216945da5941e58c42807d33507f8c820aef Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 11 May 2023 13:14:19 -0700 Subject: [PATCH] libsysprof-analyze: remove unused code We went a different route for this, so we can just drop the unused code. --- src/libsysprof-analyze/meson.build | 2 - .../sysprof-mapped-file-private.h | 42 ---- src/libsysprof-analyze/sysprof-mapped-file.c | 197 ------------------ .../sysprof-memory-map-private.h | 58 ------ src/libsysprof-analyze/sysprof-memory-map.c | 146 ------------- 5 files changed, 445 deletions(-) delete mode 100644 src/libsysprof-analyze/sysprof-mapped-file-private.h delete mode 100644 src/libsysprof-analyze/sysprof-mapped-file.c delete mode 100644 src/libsysprof-analyze/sysprof-memory-map-private.h delete mode 100644 src/libsysprof-analyze/sysprof-memory-map.c diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index ae7d037d..707852e9 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -24,8 +24,6 @@ libsysprof_analyze_public_sources = [ libsysprof_analyze_private_sources = [ 'sysprof-address-layout.c', 'sysprof-document-bitset-index.c', - 'sysprof-mapped-file.c', - 'sysprof-memory-map.c', 'sysprof-mount.c', 'sysprof-mount-device.c', 'sysprof-mount-namespace.c', diff --git a/src/libsysprof-analyze/sysprof-mapped-file-private.h b/src/libsysprof-analyze/sysprof-mapped-file-private.h deleted file mode 100644 index dc666471..00000000 --- a/src/libsysprof-analyze/sysprof-mapped-file-private.h +++ /dev/null @@ -1,42 +0,0 @@ -/* sysprof-mapped-file-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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MAPPED_FILE (sysprof_mapped_file_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMappedFile, sysprof_mapped_file, SYSPROF, MAPPED_FILE, GObject) - -SysprofMappedFile *sysprof_mapped_file_new (char *path, - guint64 address, - guint64 offset, - guint64 length, - gint64 inode); -guint64 sysprof_mapped_file_get_address (SysprofMappedFile *self); -guint64 sysprof_mapped_file_get_offset (SysprofMappedFile *self); -guint64 sysprof_mapped_file_get_length (SysprofMappedFile *self); -gint64 sysprof_mapped_file_get_inode (SysprofMappedFile *self); -const char *sysprof_mapped_file_get_path (SysprofMappedFile *self); - -G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-mapped-file.c b/src/libsysprof-analyze/sysprof-mapped-file.c deleted file mode 100644 index 87c9d177..00000000 --- a/src/libsysprof-analyze/sysprof-mapped-file.c +++ /dev/null @@ -1,197 +0,0 @@ -/* sysprof-mapped-file.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-mapped-file-private.h" - -struct _SysprofMappedFile -{ - GObject parent_instance; - char *path; - guint64 address; - guint64 offset; - guint64 length; - gint64 inode; -}; - -enum { - PROP_0, - PROP_ADDRESS, - PROP_INODE, - PROP_LENGTH, - PROP_OFFSET, - PROP_PATH, - N_PROPS -}; - -G_DEFINE_FINAL_TYPE (SysprofMappedFile, sysprof_mapped_file, G_TYPE_OBJECT) - -static GParamSpec *properties [N_PROPS]; - -static void -sysprof_mapped_file_finalize (GObject *object) -{ - SysprofMappedFile *self = (SysprofMappedFile *)object; - - g_clear_pointer (&self->path, g_ref_string_release); - - G_OBJECT_CLASS (sysprof_mapped_file_parent_class)->finalize (object); -} - -static void -sysprof_mapped_file_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofMappedFile *self = SYSPROF_MAPPED_FILE (object); - - switch (prop_id) - { - case PROP_ADDRESS: - g_value_set_uint64 (value, self->address); - break; - - case PROP_INODE: - g_value_set_int64 (value, self->inode); - break; - - case PROP_LENGTH: - g_value_set_uint64 (value, self->length); - break; - - case PROP_OFFSET: - g_value_set_uint64 (value, self->offset); - break; - - case PROP_PATH: - g_value_set_string (value, self->path); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_mapped_file_class_init (SysprofMappedFileClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_mapped_file_finalize; - object_class->get_property = sysprof_mapped_file_get_property; - - properties [PROP_ADDRESS] = - g_param_spec_uint64 ("address", NULL, NULL, - 0, G_MAXUINT64, 0, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_INODE] = - g_param_spec_int64 ("inode", NULL, NULL, - G_MININT64, G_MAXINT64, 0, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_LENGTH] = - g_param_spec_uint64 ("length", NULL, NULL, - 0, G_MAXUINT64, 0, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_OFFSET] = - g_param_spec_uint64 ("offset", NULL, NULL, - 0, G_MAXUINT64, 0, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_PATH] = - g_param_spec_string ("path", NULL, NULL, - NULL, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_mapped_file_init (SysprofMappedFile *self) -{ -} - -/** - * sysprof_mapped_file_new: - * @path: a ref-string for use with g_ref_string_acquire(). - * @address: the address where the file is mapped - * @offset: the offset of the file which is mapped at @address - * @length: the length of the memory mapping in bytes - * @inode: an optional inode of the mapped file, used for validation checks - * - * Creates a new #SysprofMappedFile which represents a mapping within the - * address range of a process. - * - * Returns: (transfer full): a #SysprofMappedFile - */ -SysprofMappedFile * -sysprof_mapped_file_new (char *path, - guint64 address, - guint64 offset, - guint64 length, - gint64 inode) -{ - SysprofMappedFile *self; - - g_return_val_if_fail (path != NULL, NULL); - - self = g_object_new (SYSPROF_TYPE_MAPPED_FILE, NULL); - self->path = g_ref_string_acquire (path); - self->address = address; - self->offset = offset; - self->length = length; - self->inode = inode; - - return self; -} - -guint64 -sysprof_mapped_file_get_address (SysprofMappedFile *self) -{ - return self->address; -} - -guint64 -sysprof_mapped_file_get_offset (SysprofMappedFile *self) -{ - return self->offset; -} - -guint64 -sysprof_mapped_file_get_length (SysprofMappedFile *self) -{ - return self->length; -} - -gint64 -sysprof_mapped_file_get_inode (SysprofMappedFile *self) -{ - return self->inode; -} - -const char * -sysprof_mapped_file_get_path (SysprofMappedFile *self) -{ - return self->path; -} diff --git a/src/libsysprof-analyze/sysprof-memory-map-private.h b/src/libsysprof-analyze/sysprof-memory-map-private.h deleted file mode 100644 index adf740b8..00000000 --- a/src/libsysprof-analyze/sysprof-memory-map-private.h +++ /dev/null @@ -1,58 +0,0 @@ -/* sysprof-memory-map-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 - -#include "sysprof-mapped-file-private.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MEMORY_MAP (sysprof_memory_map_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMemoryMap, sysprof_memory_map, SYSPROF, MEMORY_MAP, GObject) - -SysprofMemoryMap *sysprof_memory_map_new (GPtrArray *mapped_files); -SysprofMappedFile *sysprof_memory_map_find_at_address (SysprofMemoryMap *self, - guint64 address); - -typedef GPtrArray* SysprofMemoryMapBuilder; - -static inline void -sysprof_memory_map_builder_init (SysprofMemoryMapBuilder *builder) -{ - *builder = g_ptr_array_new_with_free_func (g_object_unref); -} - -static inline void -sysprof_memory_map_builder_add (SysprofMemoryMapBuilder *builder, - SysprofMappedFile *mapped_file) -{ - g_ptr_array_add (*builder, mapped_file); -} - -static inline SysprofMemoryMap * -sysprof_memory_map_builder_end (SysprofMemoryMapBuilder *builder) -{ - return sysprof_memory_map_new (g_steal_pointer (builder)); -} - -G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-memory-map.c b/src/libsysprof-analyze/sysprof-memory-map.c deleted file mode 100644 index 6c265416..00000000 --- a/src/libsysprof-analyze/sysprof-memory-map.c +++ /dev/null @@ -1,146 +0,0 @@ -/* sysprof-memory-map.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 - -#include "sysprof-memory-map-private.h" - -struct _SysprofMemoryMap -{ - GObject parent_instance; - GPtrArray *mapped_files; -}; - -G_DEFINE_FINAL_TYPE (SysprofMemoryMap, sysprof_memory_map, G_TYPE_OBJECT) - -static void -sysprof_memory_map_finalize (GObject *object) -{ - SysprofMemoryMap *self = (SysprofMemoryMap *)object; - - g_clear_pointer (&self->mapped_files, g_ptr_array_unref); - - G_OBJECT_CLASS (sysprof_memory_map_parent_class)->finalize (object); -} - -static void -sysprof_memory_map_class_init (SysprofMemoryMapClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_memory_map_finalize; -} - -static void -sysprof_memory_map_init (SysprofMemoryMap *self) -{ - self->mapped_files = g_ptr_array_new_with_free_func (g_object_unref); -} - -static int -mapped_file_compare (gconstpointer aptr, - gconstpointer bptr) -{ - SysprofMappedFile * const *a = aptr; - SysprofMappedFile * const *b = bptr; - guint64 aaddr = sysprof_mapped_file_get_address (*a); - guint64 baddr = sysprof_mapped_file_get_address (*b); - - if (aaddr < baddr) - return -1; - else if (aaddr > baddr) - return 1; - else - return 0; -} - -static int -mapped_file_bsearch (gconstpointer keyptr, - gconstpointer elemptr) -{ - guint64 address = *(const guint64 *)keyptr; - SysprofMappedFile *mapped_file = *(SysprofMappedFile * const *)elemptr; - guint64 begin = sysprof_mapped_file_get_address (mapped_file); - guint64 length = sysprof_mapped_file_get_length (mapped_file); - - if (address < begin) - return -1; - - if (address >= begin + length) - return 1; - - return 0; -} - -/** - * sysprof_memory_map_new: - * @mapped_files: (transfer full): a #GPtrArray of #SysprofMappedFile - * - * Creates a new #SysprofMemoryMap that can be used to locate a mapped - * file which contains a particular address within a target process. - * - * You should use SysprofMemoryMapBuilder instead of this function. - * - * Returns: (transfer full): a #SysprofMemoryMap - */ -SysprofMemoryMap * -sysprof_memory_map_new (GPtrArray *mapped_files) -{ - SysprofMemoryMap *self; - - g_return_val_if_fail (mapped_files != NULL, NULL); - - g_ptr_array_set_free_func (mapped_files, g_object_unref); - g_ptr_array_sort (mapped_files, mapped_file_compare); - - self = g_object_new (SYSPROF_TYPE_MEMORY_MAP, NULL); - self->mapped_files = mapped_files; - - return self; -} - -/** - * sysprof_memory_map_find_at_address: - * @self: a #SysprofMemoryMap - * @address: an address - * - * Attempts to locate the #SysprofMappedFile which contains @address. - * - * Returns: (transfer none) (nullable): a #SysprofMappedFile if there - * was a mapping containing @address, otherwise %NULL. - */ -SysprofMappedFile * -sysprof_memory_map_find_at_address (SysprofMemoryMap *self, - guint64 address) -{ - SysprofMappedFile **match; - - g_return_val_if_fail (SYSPROF_IS_MEMORY_MAP (self), NULL); - - match = bsearch (&address, - (gpointer)self->mapped_files->pdata, - self->mapped_files->len, - sizeof (gpointer), - mapped_file_bsearch); - - return match ? *match : NULL; -}