From 755650d90956c1ca4ab452f4bf356634f51a1cfb Mon Sep 17 00:00:00 2001 From: Michal Srb Date: Sun, 26 Feb 2023 16:59:16 +0100 Subject: [PATCH] Find crash thread before stacktrace is normalized When we normalize a stacktrace, we sometimes remove certain frames. The problem is when crash frame is one of those removed frames. In such cases, we simply cannot (reliably) find the crash thread. Therefore, before we normalize the stacktrace, we look for the crash thread and remember its id. We can then use that id later, if needed. Related: rhbz#2168223 Fixes: #337 Signed-off-by: Michal Srb --- lib/normalize.c | 14 ++++++++++++++ python/py_gdb_stacktrace.c | 1 + 2 files changed, 15 insertions(+) diff --git a/lib/normalize.c b/lib/normalize.c index 6cdf5e6..df74e41 100644 --- a/lib/normalize.c +++ b/lib/normalize.c @@ -505,6 +505,20 @@ sr_normalize_core_thread(struct sr_core_thread *thread) void sr_normalize_gdb_stacktrace(struct sr_gdb_stacktrace *stacktrace) { + + if (stacktrace->crash_tid == UINT32_MAX) + { + // We don't have the crash thread id yet and it will be more + // difficult to find the crach thread once we normalize the stacktrace. + // So let's just look for it now and remember it. + struct sr_gdb_thread *crash_thread; + crash_thread = sr_gdb_stacktrace_find_crash_thread(stacktrace); + if (crash_thread) + { + stacktrace->crash_tid = crash_thread->tid; + } + } + struct sr_gdb_thread *thread = stacktrace->threads; while (thread) { diff --git a/python/py_gdb_stacktrace.c b/python/py_gdb_stacktrace.c index 73a1958..35d9d65 100644 --- a/python/py_gdb_stacktrace.c +++ b/python/py_gdb_stacktrace.c @@ -533,6 +533,7 @@ sr_py_gdb_stacktrace_normalize(PyObject *self, PyObject *args) this->stacktrace->threads = tmp->threads; this->stacktrace->crash = tmp->crash; + this->stacktrace->crash_tid = tmp->crash_tid; tmp->threads = NULL; tmp->crash = NULL; sr_gdb_stacktrace_free(tmp);