From 00c02f0f186982521e10f8918d6b49008c8b5e58 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 28 Aug 2023 13:30:23 -0700 Subject: [PATCH] libsysprof: handle missing process gracefully If we get a request for a process that we have not captured any information about then give it the "Unknown Process" symbol. That way we do not crash and we also maintain our invariant of not mutating the hash table. --- src/libsysprof/sysprof-document.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libsysprof/sysprof-document.c b/src/libsysprof/sysprof-document.c index db57be4f..632d201c 100644 --- a/src/libsysprof/sysprof-document.c +++ b/src/libsysprof/sysprof-document.c @@ -79,6 +79,7 @@ struct _SysprofDocument GHashTable *counter_id_to_values; SysprofStrings *strings; + SysprofSymbol *missing_process; EggBitset *allocations; EggBitset *ctrdefs; @@ -519,6 +520,9 @@ sysprof_document_init (SysprofDocument *self) self->cpu_info = g_list_store_new (SYSPROF_TYPE_CPU_INFO); + self->missing_process = _sysprof_symbol_new (g_ref_string_new (_("Unknown Process")), + NULL, NULL, 0, 0, SYSPROF_SYMBOL_KIND_UNWINDABLE); + self->counters = g_list_store_new (SYSPROF_TYPE_DOCUMENT_COUNTER); self->counter_id_to_values = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_array_unref); @@ -768,6 +772,12 @@ sysprof_document_load_processes (SysprofDocument *self) _sysprof_symbol_new (sysprof_strings_get (self->strings, parts[0]), NULL, g_steal_pointer (&nick), 0, 0, SYSPROF_SYMBOL_KIND_PROCESS); + + g_clear_object (&process_info->shared_symbol); + process_info->shared_symbol = + _sysprof_symbol_new (sysprof_strings_get (self->strings, parts[0]), + NULL, NULL, 0, 0, + SYSPROF_SYMBOL_KIND_PROCESS); } } } @@ -2108,7 +2118,7 @@ _sysprof_document_process_symbol (SysprofDocument *self, info = _sysprof_document_process_info (self, pid, FALSE); if (info == NULL) - g_error ("Failed to find info for PID %d", pid); + return self->missing_process; if (info->symbol) return info->symbol;