These can be concatenated to get short backtrace suitable for inclusion
in bugzilla comment.
Signed-off-by: Martin Milata <mmilata(a)redhat.com>
---
lib/core_frame.c | 20 ++++++++++++++++++++
lib/core_frame.h | 7 +++++++
lib/koops_frame.c | 12 ++++++++++++
lib/koops_frame.h | 9 +++++++++
lib/python_frame.c | 23 +++++++++++++++++++++++
lib/python_frame.h | 8 ++++++++
6 files changed, 79 insertions(+)
diff --git a/lib/core_frame.c b/lib/core_frame.c
index 3af451a..2335e32 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/koops_frame.c b/lib/koops_frame.c
index 0cfa614..8fed0bc 100644
--- a/lib/koops_frame.c
+++ b/lib/koops_frame.c
@@ -482,3 +482,15 @@ sr_koops_frame_to_json(struct sr_koops_frame *frame)
sr_strbuf_append_str(strbuf, "}");
return sr_strbuf_free_nobuf(strbuf);
}
+
+void
+sr_koops_frame_append_to_str(struct sr_koops_frame *frame,
+ struct sr_strbuf *str)
+{
+ sr_strbuf_append_strf(str, "%s%s",
+ (frame->reliable ? "" : "? "),
+ (frame->function_name ? frame->function_name :
"??"));
+
+ if (frame->module_name)
+ sr_strbuf_append_strf(str, " in %s", frame->module_name);
+}
diff --git a/lib/koops_frame.h b/lib/koops_frame.h
index aeccd42..733dbcf 100644
--- a/lib/koops_frame.h
+++ b/lib/koops_frame.h
@@ -33,6 +33,8 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
+struct sr_strbuf;
+
/**
* @brief Kernel oops stack frame.
*/
@@ -214,6 +216,13 @@ sr_koops_parse_function(const char **input,
char *
sr_koops_frame_to_json(struct sr_koops_frame *frame);
+/**
+ * Appends textual representation of the frame to the string buffer dest.
+ */
+void
+sr_koops_frame_append_to_str(struct sr_koops_frame *frame,
+ struct sr_strbuf *dest);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/python_frame.c b/lib/python_frame.c
index 24a07c2..59f3e88 100644
--- a/lib/python_frame.c
+++ b/lib/python_frame.c
@@ -302,3 +302,26 @@ sr_python_frame_to_json(struct sr_python_frame *frame)
sr_strbuf_append_char(strbuf, '}');
return sr_strbuf_free_nobuf(strbuf);
}
+
+void
+sr_python_frame_append_to_str(struct sr_python_frame *frame,
+ struct sr_strbuf *dest)
+{
+ sr_strbuf_append_strf(dest, "%s%s%s",
+ (frame->special_function ? "<" :
""),
+ (frame->function_name ? frame->function_name :
"??"),
+ (frame->special_function ? ">" :
""));
+
+ if (frame->file_name)
+ {
+ sr_strbuf_append_strf(dest, " in %s%s%s",
+ (frame->special_file ? "<" :
""),
+ frame->file_name,
+ (frame->special_file ? ">" :
""));
+
+ if (frame->file_line)
+ {
+ sr_strbuf_append_strf(dest, ":%d", frame->file_line);
+ }
+ }
+}
diff --git a/lib/python_frame.h b/lib/python_frame.h
index 0466f85..fc9be79 100644
--- a/lib/python_frame.h
+++ b/lib/python_frame.h
@@ -34,6 +34,7 @@ extern "C" {
#include <stdint.h>
struct sr_location;
+struct sr_strbuf;
struct sr_python_frame
{
@@ -170,6 +171,13 @@ sr_python_frame_parse(const char **input,
char *
sr_python_frame_to_json(struct sr_python_frame *frame);
+/**
+ * Appends textual representation of the frame to the string buffer dest.
+ */
+void
+sr_python_frame_append_to_str(struct sr_python_frame *frame,
+ struct sr_strbuf *dest);
+
#ifdef __cplusplus
}
#endif
--
1.7.11.7