[SATYR PATCH 5/5] Short text representation for core stacktraces

Martin Milata mmilata at redhat.com
Fri May 24 15:55:23 UTC 2013


Closes #64 with previous commits.

Signed-off-by: Martin Milata <mmilata at redhat.com>
---
 lib/core_frame.c      | 20 ++++++++++++++++++++
 lib/core_frame.h      |  7 +++++++
 lib/core_stacktrace.c | 28 ++++++++++++++++++++++++++++
 lib/core_stacktrace.h |  8 ++++++++
 4 files changed, 63 insertions(+)

diff --git a/lib/core_frame.c b/lib/core_frame.c
index 3af451a..5268828 100644
--- a/lib/core_frame.c
+++ b/lib/core_frame.c
@@ -351,3 +351,23 @@ sr_core_frame_to_json(struct sr_core_frame *frame)
     sr_strbuf_append_char(strbuf, '}');
     return sr_strbuf_free_nobuf(strbuf);
 }
+
+void
+sr_core_frame_append_to_str(struct sr_core_frame *frame,
+                            struct sr_strbuf *dest)
+{
+    if (frame->function_name)
+    {
+        sr_strbuf_append_str(dest, frame->function_name);
+    }
+    else
+    {
+        sr_strbuf_append_strf(dest, "%s+%"PRIu64, frame->build_id,
+                              frame->build_id_offset);
+    }
+
+    if (frame->file_name)
+    {
+        sr_strbuf_append_strf(dest, "in %s", frame->file_name);
+    }
+}
diff --git a/lib/core_frame.h b/lib/core_frame.h
index bca035a..b5f45c7 100644
--- a/lib/core_frame.h
+++ b/lib/core_frame.h
@@ -196,6 +196,13 @@ sr_core_frame_from_json(struct sr_json_value *root,
 char *
 sr_core_frame_to_json(struct sr_core_frame *frame);
 
+/**
+ * Appends textual representation of the frame to the string buffer dest.
+ */
+void
+sr_core_frame_append_to_str(struct sr_core_frame *frame,
+                            struct sr_strbuf *dest);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/core_stacktrace.c b/lib/core_stacktrace.c
index a19fc36..3b0c221 100644
--- a/lib/core_stacktrace.c
+++ b/lib/core_stacktrace.c
@@ -368,3 +368,31 @@ sr_core_stacktrace_get_reason(struct sr_core_stacktrace *stacktrace)
 
     return sr_asprintf("Program %s was terminated by signal %"PRIu16, prog, stacktrace->signal);
 }
+
+char *
+sr_core_stacktrace_to_short_text(struct sr_core_stacktrace *stacktrace,
+                                 int max_frames)
+{
+    struct sr_core_thread *thread = sr_core_stacktrace_find_crash_thread(stacktrace);
+    if (!thread)
+    {
+        return NULL;
+    }
+
+    struct sr_strbuf *strbuf = sr_strbuf_new();
+    struct sr_core_frame *frame;
+    int i = 0;
+
+    for (frame = thread->frames; frame; frame = frame->next)
+    {
+        i++;
+        sr_strbuf_append_strf(strbuf, "#%d ", i);
+        sr_core_frame_append_to_str(frame, strbuf);
+        sr_strbuf_append_char(strbuf, '\n');
+
+        if (max_frames && i >= max_frames)
+            break;
+    }
+
+    return sr_strbuf_free_nobuf(strbuf);
+}
diff --git a/lib/core_stacktrace.h b/lib/core_stacktrace.h
index 6ee7509..c496a74 100644
--- a/lib/core_stacktrace.h
+++ b/lib/core_stacktrace.h
@@ -137,6 +137,14 @@ sr_core_stacktrace_create(const char *gdb_stacktrace_text,
                           const char *unstrip_text,
                           const char *executable_path);
 
+/**
+ * Returns brief textual representation of the stacktrace, or NULL in case of
+ * failure. Caller has to free it using free().
+ */
+char *
+sr_core_stacktrace_to_short_text(struct sr_core_stacktrace *stacktrace,
+                                 int max_frames);
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.7.11.7



More information about the Crash-catcher mailing list