[SATYR PATCH 6/8] report: use generic stacktrace type
Martin Milata
mmilata at redhat.com
Mon Aug 26 14:49:05 UTC 2013
Makes it possible to simplify some code and the structure won't have to
be extended when adding new stacktrace type.
Related to #86.
Signed-off-by: Martin Milata <mmilata at redhat.com>
---
include/report.h | 6 ++---
lib/Makefile.am | 2 +-
lib/abrt.c | 16 ++++++-------
lib/report.c | 70 +++++++++-----------------------------------------------
4 files changed, 22 insertions(+), 72 deletions(-)
diff --git a/include/report.h b/include/report.h
index 52d0149..424b730 100644
--- a/include/report.h
+++ b/include/report.h
@@ -29,6 +29,7 @@ extern "C" {
#include <stdbool.h>
struct sr_json_value;
+struct sr_stacktrace;
struct sr_report
{
@@ -47,10 +48,7 @@ struct sr_report
char *component_name;
struct sr_rpm_package *rpm_packages;
- struct sr_python_stacktrace *python_stacktrace;
- struct sr_koops_stacktrace *koops_stacktrace;
- struct sr_core_stacktrace *core_stacktrace;
- struct sr_java_stacktrace *java_stacktrace;
+ struct sr_stacktrace *stacktrace;
};
struct sr_report *
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 65b0807..8cd7fce 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -51,7 +51,7 @@ libsatyr_la_SOURCES = \
utils.c
libsatyr_la_CFLAGS = -Wall -std=gnu99 -D_GNU_SOURCE -I$(top_srcdir)/include $(GLIB_CFLAGS)
-libsatyr_la_LDFLAGS = -version-info 1:0:0 -export-symbols-regex '^sr_' $(GLIB_LIBS)
+libsatyr_la_LDFLAGS = -version-info 2:0:0 -export-symbols-regex '^sr_' $(GLIB_LIBS)
if HAVE_LIBOPCODES
# Conditional link is required to avoid linking to a library without
diff --git a/lib/abrt.c b/lib/abrt.c
index e59c30d..53f84cd 100644
--- a/lib/abrt.c
+++ b/lib/abrt.c
@@ -373,11 +373,11 @@ sr_abrt_report_from_dir(const char *directory,
return NULL;
}
- report->core_stacktrace = sr_core_stacktrace_from_json_text(
+ report->stacktrace = (struct sr_stacktrace *)sr_core_stacktrace_from_json_text(
core_backtrace_contents, error_message);
free(core_backtrace_contents);
- if (!report->core_stacktrace)
+ if (!report->stacktrace)
{
sr_report_free(report);
return NULL;
@@ -399,12 +399,12 @@ sr_abrt_report_from_dir(const char *directory,
struct sr_location location;
sr_location_init(&location);
const char *contents_pointer = backtrace_contents;
- report->python_stacktrace = sr_python_stacktrace_parse(
+ report->stacktrace = (struct sr_stacktrace *)sr_python_stacktrace_parse(
&contents_pointer,
&location);
free(backtrace_contents);
- if (!report->python_stacktrace)
+ if (!report->stacktrace)
{
*error_message = sr_location_to_string(&location);
sr_report_free(report);
@@ -456,12 +456,12 @@ sr_abrt_report_from_dir(const char *directory,
struct sr_location location;
sr_location_init(&location);
const char *contents_pointer = backtrace_contents;
- report->koops_stacktrace = sr_koops_stacktrace_parse(
+ report->stacktrace = (struct sr_stacktrace *)sr_koops_stacktrace_parse(
&contents_pointer,
&location);
free(backtrace_contents);
- if (!report->koops_stacktrace)
+ if (!report->stacktrace)
{
*error_message = sr_location_to_string(&location);
sr_report_free(report);
@@ -483,12 +483,12 @@ sr_abrt_report_from_dir(const char *directory,
struct sr_location location;
sr_location_init(&location);
const char *contents_pointer = backtrace_contents;
- report->java_stacktrace = sr_java_stacktrace_parse(
+ report->stacktrace = (struct sr_stacktrace *)sr_java_stacktrace_parse(
&contents_pointer,
&location);
free(backtrace_contents);
- if (!report->java_stacktrace)
+ if (!report->stacktrace)
{
*error_message = sr_location_to_string(&location);
sr_report_free(report);
diff --git a/lib/report.c b/lib/report.c
index 92b77cf..a6ecae4 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "utils.h"
#include "json.h"
+#include "stacktrace.h"
#include "koops/stacktrace.h"
#include "core/stacktrace.h"
#include "python/stacktrace.h"
@@ -64,10 +65,7 @@ sr_report_init(struct sr_report *report)
report->operating_system = NULL;
report->component_name = NULL;
report->rpm_packages = NULL;
- report->python_stacktrace = NULL;
- report->koops_stacktrace = NULL;
- report->core_stacktrace = NULL;
- report->java_stacktrace = NULL;
+ report->stacktrace = NULL;
}
void
@@ -76,10 +74,7 @@ sr_report_free(struct sr_report *report)
free(report->component_name);
sr_operating_system_free(report->operating_system);
sr_rpm_package_free(report->rpm_packages, true);
- sr_python_stacktrace_free(report->python_stacktrace);
- sr_koops_stacktrace_free(report->koops_stacktrace);
- sr_core_stacktrace_free(report->core_stacktrace);
- sr_java_stacktrace_free(report->java_stacktrace);
+ sr_stacktrace_free(report->stacktrace);
free(report);
}
@@ -128,43 +123,14 @@ problem_object_string(struct sr_report *report, const char *report_type)
}
/* Stacktrace. */
-
- /* Core stacktrace. */
- if (report->core_stacktrace)
- {
- char *stacktrace = sr_core_stacktrace_to_json(report->core_stacktrace);
- dismantle_object(stacktrace);
- sr_strbuf_append_str(strbuf, stacktrace);
- free(stacktrace);
- }
-
- /* Python stacktrace. */
- if (report->python_stacktrace)
- {
- char *stacktrace = sr_python_stacktrace_to_json(report->python_stacktrace);
- dismantle_object(stacktrace);
- sr_strbuf_append_str(strbuf, stacktrace);
- free(stacktrace);
- }
-
- /* Koops stacktrace. */
- if (report->koops_stacktrace)
+ if (report->stacktrace)
{
- char *stacktrace = sr_koops_stacktrace_to_json(report->koops_stacktrace);
+ char *stacktrace = sr_stacktrace_to_json(report->stacktrace);
dismantle_object(stacktrace);
sr_strbuf_append_str(strbuf, stacktrace);
free(stacktrace);
}
- /* Java stacktrace. */
- if (report->java_stacktrace)
- {
- char *stacktrace = sr_java_stacktrace_to_json(report->java_stacktrace);
- dismantle_object(stacktrace);
- sr_strbuf_append_strf(strbuf, stacktrace);
- free(stacktrace);
- }
-
sr_strbuf_append_str(strbuf, "}");
return sr_strbuf_free_nobuf(strbuf);
@@ -181,31 +147,22 @@ sr_report_to_json(struct sr_report *report)
report->report_version);
/* Report type. */
- const char *report_type;
+ char *report_type;
char *reason;
switch (report->report_type)
{
default:
case SR_REPORT_INVALID:
case SR_REPORT_GDB: /* gdb ureports are not supported */
- report_type = "invalid";
+ report_type = sr_strdup("invalid");
reason = sr_strdup("invalid");
break;
case SR_REPORT_CORE:
- report_type = "core";
- reason = sr_core_stacktrace_get_reason(report->core_stacktrace);
- break;
case SR_REPORT_PYTHON:
- report_type = "python";
- reason = sr_python_stacktrace_get_reason(report->python_stacktrace);
- break;
case SR_REPORT_KERNELOOPS:
- report_type = "kerneloops";
- reason = sr_koops_stacktrace_get_reason(report->koops_stacktrace);
- break;
case SR_REPORT_JAVA:
- report_type = "java";
- reason = sr_java_stacktrace_get_reason(report->java_stacktrace);
+ report_type = sr_report_type_to_string(report->report_type);
+ reason = sr_stacktrace_get_reason(report->stacktrace);
break;
}
@@ -245,6 +202,7 @@ sr_report_to_json(struct sr_report *report)
char *problem = problem_object_string(report, report_type);
char *problem_indented = sr_indent_except_first_line(problem, strlen(", \"problem\": "));
free(problem);
+ free(report_type);
sr_strbuf_append_strf(strbuf,
", \"problem\": %s\n",
problem_indented);
@@ -366,16 +324,10 @@ sr_report_from_json(struct sr_json_value *root, char **error_message)
switch (report->report_type)
{
case SR_REPORT_CORE:
- report->core_stacktrace = sr_core_stacktrace_from_json(problem, error_message);
- break;
case SR_REPORT_PYTHON:
- report->python_stacktrace = sr_python_stacktrace_from_json(problem, error_message);
- break;
case SR_REPORT_KERNELOOPS:
- report->koops_stacktrace = sr_koops_stacktrace_from_json(problem, error_message);
- break;
case SR_REPORT_JAVA:
- report->java_stacktrace = sr_java_stacktrace_from_json(problem, error_message);
+ report->stacktrace = sr_stacktrace_from_json(report->report_type, problem, error_message);
break;
default:
/* Invalid report type -> no stacktrace. */
--
1.8.3.1
More information about the Crash-catcher
mailing list