Blame SOURCES/0166-UUID-from-core-backtrace-if-coredump-is-missing.patch

a60cd7
From 54ff71a2bec4386c871b54100e02065384aefb63 Mon Sep 17 00:00:00 2001
a60cd7
From: Martin Milata <mmilata@redhat.com>
a60cd7
Date: Tue, 2 Dec 2014 12:44:49 +0100
a60cd7
Subject: [PATCH] UUID from core backtrace if coredump is missing
a60cd7
a60cd7
Closes #882.
a60cd7
a60cd7
Signed-off-by: Martin Milata <mmilata@redhat.com>
a60cd7
---
a60cd7
 src/plugins/abrt-action-analyze-c.c | 91 ++++++++++++++++++++++++++++++++++---
a60cd7
 1 file changed, 85 insertions(+), 6 deletions(-)
a60cd7
a60cd7
diff --git a/src/plugins/abrt-action-analyze-c.c b/src/plugins/abrt-action-analyze-c.c
a60cd7
index a53f4fb..f98cfe5 100644
a60cd7
--- a/src/plugins/abrt-action-analyze-c.c
a60cd7
+++ b/src/plugins/abrt-action-analyze-c.c
a60cd7
@@ -18,6 +18,13 @@
a60cd7
 */
a60cd7
 #include "libabrt.h"
a60cd7
 
a60cd7
+#include <glib.h>
a60cd7
+
a60cd7
+#include <satyr/thread.h>
a60cd7
+#include <satyr/core/stacktrace.h>
a60cd7
+#include <satyr/core/thread.h>
a60cd7
+#include <satyr/core/frame.h>
a60cd7
+
a60cd7
 static void trim_unstrip_output(char *result, const char *unstrip_n_output)
a60cd7
 {
a60cd7
     // lines look like this:
a60cd7
@@ -49,6 +56,62 @@ static void trim_unstrip_output(char *result, const char *unstrip_n_output)
a60cd7
     *dst = '\0';
a60cd7
 }
a60cd7
 
a60cd7
+static char *build_ids_from_core_backtrace(const char *dump_dir_name)
a60cd7
+{
a60cd7
+    char *error = NULL;
a60cd7
+    char *core_backtrace_path = xasprintf("%s/"FILENAME_CORE_BACKTRACE, dump_dir_name);
a60cd7
+    char *json = xmalloc_open_read_close(core_backtrace_path, /*maxsize:*/ NULL);
a60cd7
+    free(core_backtrace_path);
a60cd7
+
a60cd7
+    if (!json)
a60cd7
+        return NULL;
a60cd7
+
a60cd7
+    struct sr_core_stacktrace *stacktrace = sr_core_stacktrace_from_json_text(json, &error);
a60cd7
+    free(json);
a60cd7
+    if (!stacktrace)
a60cd7
+    {
a60cd7
+        if (error)
a60cd7
+        {
a60cd7
+            log_info("Failed to parse core backtrace: %s", error);
a60cd7
+            free(error);
a60cd7
+        }
a60cd7
+        return NULL;
a60cd7
+    }
a60cd7
+
a60cd7
+    struct sr_core_thread *thread = sr_core_stacktrace_find_crash_thread(stacktrace);
a60cd7
+    if (!thread)
a60cd7
+    {
a60cd7
+        log_info("Failed to find crash thread");
a60cd7
+        sr_core_stacktrace_free(stacktrace);
a60cd7
+        return NULL;
a60cd7
+    }
a60cd7
+
a60cd7
+    void *build_id_list = NULL;
a60cd7
+
a60cd7
+    struct strbuf *strbuf = strbuf_new();
a60cd7
+    for (struct sr_core_frame *frame = thread->frames;
a60cd7
+         frame;
a60cd7
+         frame = frame->next)
a60cd7
+    {
a60cd7
+        if (frame->build_id)
a60cd7
+            build_id_list = g_list_prepend(build_id_list, frame->build_id);
a60cd7
+    }
a60cd7
+
a60cd7
+    build_id_list = g_list_sort(build_id_list, (GCompareFunc)strcmp);
a60cd7
+    for (GList *iter = build_id_list; iter; iter = g_list_next(iter))
a60cd7
+    {
a60cd7
+        GList *next = g_list_next(iter);
a60cd7
+        if (next == NULL || 0 != strcmp(iter->data, next->data))
a60cd7
+        {
a60cd7
+            strbuf = strbuf_append_strf(strbuf, "%s\n", (char *)iter->data);
a60cd7
+        }
a60cd7
+    }
a60cd7
+    g_list_free(build_id_list);
a60cd7
+    sr_core_stacktrace_free(stacktrace);
a60cd7
+
a60cd7
+    return strbuf_free_nobuf(strbuf);
a60cd7
+}
a60cd7
+
a60cd7
 int main(int argc, char **argv)
a60cd7
 {
a60cd7
     /* I18n */
a60cd7
@@ -82,13 +145,27 @@ int main(int argc, char **argv)
a60cd7
 
a60cd7
     export_abrt_envvars(0);
a60cd7
 
a60cd7
-    /* Run unstrip -n and trim its output, leaving only sizes and build ids */
a60cd7
+    char *unstrip_n_output = NULL;
a60cd7
+    char *coredump_path = xasprintf("%s/"FILENAME_COREDUMP, dump_dir_name);
a60cd7
+    if (access(coredump_path, R_OK) == 0)
a60cd7
+        unstrip_n_output = run_unstrip_n(dump_dir_name, /*timeout_sec:*/ 30);
a60cd7
 
a60cd7
-    char *unstrip_n_output = run_unstrip_n(dump_dir_name, /*timeout_sec:*/ 30);
a60cd7
-    if (!unstrip_n_output)
a60cd7
-        return 1; /* bad dump_dir_name, can't run unstrip, etc... */
a60cd7
-    /* modifies unstrip_n_output in-place: */
a60cd7
-    trim_unstrip_output(unstrip_n_output, unstrip_n_output);
a60cd7
+    free(coredump_path);
a60cd7
+
a60cd7
+    if (unstrip_n_output)
a60cd7
+    {
a60cd7
+        /* Run unstrip -n and trim its output, leaving only sizes and build ids */
a60cd7
+        /* modifies unstrip_n_output in-place: */
a60cd7
+        trim_unstrip_output(unstrip_n_output, unstrip_n_output);
a60cd7
+    }
a60cd7
+    else
a60cd7
+    {
a60cd7
+        /* bad dump_dir_name, can't run unstrip, etc...
a60cd7
+         * or maybe missing coredump - try generating it from core_backtrace
a60cd7
+         */
a60cd7
+
a60cd7
+        unstrip_n_output = build_ids_from_core_backtrace(dump_dir_name);
a60cd7
+    }
a60cd7
 
a60cd7
     /* Hash package + executable + unstrip_n_output and save it as UUID */
a60cd7
 
a60cd7
@@ -131,6 +208,8 @@ int main(int argc, char **argv)
a60cd7
     /*free(executable);*/
a60cd7
     /*free(unstrip_n_output);*/
a60cd7
 
a60cd7
+    log_debug("String to hash: %s", string_to_hash);
a60cd7
+
a60cd7
     char hash_str[SHA1_RESULT_LEN*2 + 1];
a60cd7
     str_to_sha1str(hash_str, string_to_hash);
a60cd7
 
a60cd7
-- 
a60cd7
2.4.3
a60cd7