Related to abrt/satyr#88.
Signed-off-by: Martin Milata mmilata@redhat.com --- configure.ac | 18 +-- libreport-web.pc.in | 2 +- src/lib/json.c | 288 +--------------------------------------- src/plugins/reporter-bugzilla.c | 75 +++-------- 4 files changed, 27 insertions(+), 356 deletions(-)
diff --git a/configure.ac b/configure.ac index 671d6a4..da7f480 100644 --- a/configure.ac +++ b/configure.ac @@ -145,11 +145,6 @@ PYTHON_LIBS=`python-config --libs 2> /dev/null` AC_SUBST(PYTHON_CFLAGS) AC_SUBST(PYTHON_LIBS)
-AC_ARG_WITH([satyr], - AS_HELP_STRING([--with-satyr], - [use satyr instead of btparser (default is no)]), - [], [with_satyr=no]) - PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.21]) PKG_CHECK_MODULES([DBUS], [dbus-1]) PKG_CHECK_MODULES([LIBXML], [libxml-2.0]) @@ -158,18 +153,7 @@ PKG_CHECK_MODULES([CURL], [libcurl]) PKG_CHECK_MODULES([PROXY], [libproxy-1.0], [ AC_DEFINE([HAVE_PROXY], [1], [Use libproxy]) ], [:]) - -[if test "$with_satyr" = "yes"] -[then] - PKG_CHECK_MODULES([SATYR], [satyr]) - AC_DEFINE([USE_SATYR], [1], [Use satyr instead of btparser]) - SATYR_PKG="satyr" -[else] - PKG_CHECK_MODULES([SATYR], [btparser]) - SATYR_PKG="btparser" -[fi] -AC_SUBST(SATYR_PKG) -AM_CONDITIONAL([USE_SATYR], [test "$with_satyr" = "yes"]) +PKG_CHECK_MODULES([SATYR], [satyr])
AC_ARG_WITH(newt, AS_HELP_STRING([--with-newt],[use newt (default is YES)]), diff --git a/libreport-web.pc.in b/libreport-web.pc.in index ec4ab8e..288e613 100644 --- a/libreport-web.pc.in +++ b/libreport-web.pc.in @@ -6,7 +6,7 @@ includedir=@includedir@ Name: libreport Description: Library providing network API for libreport Version: @VERSION@ -Requires: glib-2.0 libcurl libproxy-1.0 libxml-2.0 xmlrpc xmlrpc_client json @SATYR_PKG@ libreport +Requires: glib-2.0 libcurl libproxy-1.0 libxml-2.0 xmlrpc xmlrpc_client json satyr libreport Libs: -L${libdir} -lreport-web Cflags:
diff --git a/src/lib/json.c b/src/lib/json.c index d5c6f2d..68348ad 100644 --- a/src/lib/json.c +++ b/src/lib/json.c @@ -19,6 +19,9 @@
#include <json/json.h>
+#include <satyr/abrt.h> +#include <satyr/report.h> + #include "internal_libreport.h" #include "ureport.h" #include "libreport_curl.h" @@ -34,11 +37,6 @@ static void ureport_add_str(struct json_object *ur, const char *key, json_object_object_add(ur, key, jstring); }
-#if USE_SATYR - -#include <satyr/abrt.h> -#include <satyr/report.h> - char *ureport_from_dump_dir(const char *dump_dir_path) { char *error_message; @@ -54,286 +52,6 @@ char *ureport_from_dump_dir(const char *dump_dir_path) return json_ureport; }
-#else /* USE_SATYR */ - -#include <btparser/thread.h> -#include <btparser/core-backtrace.h> - -/* on success 1 returned, on error zero is returned and appropriate value - * is returned as third argument. You should never read third argument when - * function fails - * - * json-c library doesn't have any json_object_new_long, - * thus we have to use only int - */ -static int get_pd_int_item(problem_data_t *pd, const char *key, int *result) -{ - if (!pd || !key) - return 0; - - char *pd_item = problem_data_get_content_or_NULL(pd, key); - if (!pd_item) - { - VERB1 log("warning: '%s' is not an item in problem directory", key); - return 0; - } - - errno = 0; - char *e; - long i = strtol(pd_item, &e, 10); - if (errno || pd_item == e || *e != '\0' || (int) i != i) - return 0; - - *result = i; - return 1; -} - -static void ureport_add_int(struct json_object *ur, const char *key, int i) -{ - struct json_object *jint = json_object_new_int(i); - if (!jint) - die_out_of_memory(); - - json_object_object_add(ur, key, jint); -} - -static void ureport_add_os(struct json_object *ur, problem_data_t *pd) -{ - char *name; - char *version; - map_string_t *osinfo = new_map_string(); - problem_data_get_osinfo(pd, osinfo); - parse_osinfo_for_rhts(osinfo, &name, &version); - free_map_string(osinfo); - - if (!name || !version) - { - free(name); - free(version); - return; - } - - struct json_object *jobject = json_object_new_object(); - if (!jobject) - die_out_of_memory(); - - ureport_add_str(jobject, "name", name); - ureport_add_str(jobject, "version", version); - - free(name); - free(version); - - json_object_object_add(ur, "os", jobject); -} - -static bool ureport_add_type(struct json_object *ur, problem_data_t *pd) -{ - char *pd_item = problem_data_get_content_or_NULL(pd, FILENAME_ANALYZER); - if (!pd_item) - { - error_msg(_("Missing problem element '%s'"), FILENAME_ANALYZER); - return false; - } - - if (strcmp(pd_item, "CCpp") == 0) - ureport_add_str(ur, "type", "USERSPACE"); - else if (strcmp(pd_item, "Python") == 0) - ureport_add_str(ur, "type", "PYTHON"); - else if (strcmp(pd_item, "Kerneloops") == 0 || strcmp(pd_item, "vmcore") == 0) - ureport_add_str(ur, "type", "KERNELOOPS"); - else - { - error_msg(_("An unsupported value '%s' in problem element '%s'"), pd_item, FILENAME_ANALYZER); - return false; - } - - return true; -} - -static void ureport_add_core_backtrace(struct json_object *ur, problem_data_t *pd) -{ - char *pd_item = problem_data_get_content_or_NULL(pd, FILENAME_CORE_BACKTRACE); - if (!pd_item) - return; - - struct btp_thread *core_bt = btp_load_core_backtrace(pd_item); - if (!core_bt) - return; - - struct json_object *jarray = json_object_new_array(); - if (!jarray) - die_out_of_memory(); - - struct btp_frame *frame; - unsigned frame_nr = 0; - for (frame = core_bt->frames; frame; frame = frame->next) - { - struct frame_aux *aux = frame->user_data; - - struct json_object *item = json_object_new_object(); - if (!item) - die_out_of_memory(); - - if (aux->filename) - ureport_add_str(item, "path", aux->filename); - - if (frame->function_name) - ureport_add_str(item, "funcname", frame->function_name); - - if (aux->build_id) - ureport_add_str(item, "buildid", aux->build_id); - - if (aux->fingerprint) - ureport_add_str(item, "funchash", aux->fingerprint); - - /* always add offset - even offset 0 is valid */ - ureport_add_int(item, "offset", (uintmax_t)frame->address); - - ureport_add_int(item, "frame", frame_nr++); - ureport_add_int(item, "thread", 0); - - - json_object_array_add(jarray, item); - } - - btp_thread_free(core_bt); - - json_object_object_add(ur, FILENAME_CORE_BACKTRACE, jarray); -} -static void ureport_add_item_str(struct json_object *ur, problem_data_t *pd, - const char *key, const char *rename) -{ - char *pd_item = problem_data_get_content_or_NULL(pd, key); - if (!pd_item) - return; - - ureport_add_str(ur, (rename) ?: key, pd_item); -} - -static void ureport_add_item_int(struct json_object *ur, problem_data_t *pd, - const char *key, const char *rename) -{ - int nr; - int stat = get_pd_int_item(pd, key, &nr); - if (!stat) - return; - - ureport_add_int(ur, (rename) ?: key, nr); -} - -static void ureport_add_pkg(struct json_object *ur, problem_data_t *pd) -{ - struct json_object *jobject = json_object_new_object(); - if (!jobject) - die_out_of_memory(); - - ureport_add_item_int(jobject, pd, FILENAME_PKG_EPOCH, "epoch"); - ureport_add_item_str(jobject, pd, FILENAME_PKG_NAME, "name"); - ureport_add_item_str(jobject, pd, FILENAME_PKG_VERSION, "version"); - ureport_add_item_str(jobject, pd, FILENAME_PKG_RELEASE, "release"); - ureport_add_item_str(jobject, pd, FILENAME_PKG_ARCH, "architecture"); - - json_object_object_add(ur, "installed_package", jobject); -} - -static void ureport_add_related_pkgs(struct json_object *ur, problem_data_t *pd) -{ - // TODO: populate this field - struct json_object *jobject = json_object_new_array(); - json_object_object_add(ur, "related_packages", jobject); -} - -static void ureport_add_reporter(struct json_object *ur, const char *name, const char *version) -{ - struct json_object *jobject = json_object_new_object(); - if (!jobject) - die_out_of_memory(); - - ureport_add_str(jobject, "name", name); - ureport_add_str(jobject, "version", version); - - json_object_object_add(ur, "reporter", jobject); -} - -static void ureport_add_oops(struct json_object *ur, problem_data_t *pd) -{ - char *pd_item = problem_data_get_content_or_NULL(pd, FILENAME_ANALYZER); - if (!pd_item) - return; - - if (!strcmp(pd_item, "Kerneloops")) - ureport_add_item_str(ur, pd, FILENAME_BACKTRACE, "oops"); -} - -char *new_json_ureport(problem_data_t *pd) -{ - struct json_object *ureport = json_object_new_object(); - if (!ureport) - die_out_of_memory(); - - ureport_add_item_str(ureport, pd, "user_type", NULL); - ureport_add_item_int(ureport, pd, "uptime", NULL); - - /* mandatory, but not in problem-dir - * - * ureport_add_item_int(ureport, pd, "crash_thread", NULL); - */ - ureport_add_int(ureport, "ureport_version", 1); - ureport_add_int(ureport, "crash_thread", 0); - - ureport_add_item_str(ureport, pd, FILENAME_ARCHITECTURE, NULL); - ureport_add_item_str(ureport, pd, FILENAME_EXECUTABLE, NULL); - ureport_add_item_str(ureport, pd, FILENAME_REASON, NULL); - ureport_add_item_str(ureport, pd, FILENAME_COMPONENT, NULL); - - if (!ureport_add_type(ureport, pd)) - { - error_msg(_("Can't create an uReport without 'type'")); - json_object_put(ureport); - return NULL; - } - - ureport_add_pkg(ureport, pd); - ureport_add_related_pkgs(ureport, pd); - ureport_add_os(ureport, pd); - - ureport_add_core_backtrace(ureport, pd); - ureport_add_reporter(ureport, "ABRT", VERSION); - - ureport_add_oops(ureport, pd); - - char *j = xstrdup(json_object_to_json_string(ureport)); - json_object_put(ureport); - - return j; -} - -char *ureport_from_dump_dir(const char *dump_dir_path) -{ - struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY); - if (!dd) - xfunc_die(); - - problem_data_t *pd = create_problem_data_from_dump_dir(dd); - - dd_close(dd); - if (!pd) - xfunc_die(); /* create_problem_data_from_dump_dir already emitted error msg */ - - char *json_ureport = new_json_ureport(pd); - problem_data_free(pd); - - if (json_ureport == NULL) - { - error_msg(_("Not uploading an empty uReport")); - return NULL; - } - - return json_ureport; -} - -#endif /* USE_SATYR */ - char *new_json_attachment(const char *bthash, const char *type, const char *data) { struct json_object *attachment = json_object_new_object(); diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c index 626b41f..972a1f0 100644 --- a/src/plugins/reporter-bugzilla.c +++ b/src/plugins/reporter-bugzilla.c @@ -21,39 +21,8 @@ #include "abrt_xmlrpc.h" #include "rhbz.h"
-/* btparser compatibility - once we move to satyr, the else branch of the ifdef - * can be removed - */ -#ifdef USE_SATYR - -#include <satyr/location.h> -#include <satyr/gdb_stacktrace.h> -#include <satyr/gdb_thread.h> -#include <satyr/gdb_frame.h> -#include <satyr/strbuf.h> - -#else /* USE_SATYR */ - -#include <btparser/location.h> -#include <btparser/backtrace.h> -#include <btparser/thread.h> -#include <btparser/frame.h> -#include <btparser/strbuf.h> - -#define sr_location btp_location -#define sr_location_init btp_location_init -#define sr_gdb_stacktrace btp_backtrace -#define sr_gdb_stacktrace_parse btp_backtrace_parse -#define sr_gdb_stacktrace_get_optimized_thread btp_backtrace_get_optimized_thread -#define sr_gdb_stacktrace_free btp_backtrace_free -#define sr_gdb_thread btp_thread -#define sr_gdb_thread_append_to_str btp_thread_append_to_str -#define sr_gdb_thread_free btp_thread_free -#define sr_strbuf btp_strbuf -#define sr_strbuf_new btp_strbuf_new -#define sr_strbuf_free_nobuf btp_strbuf_free_nobuf - -#endif /* USE_SATYR */ +#include <satyr/stacktrace.h> +#include <satyr/abrt.h>
struct section_t { char *name; @@ -365,38 +334,38 @@ int append_short_backtrace(struct strbuf *result, problem_data_t *problem_data,
if (strlen(item->content) >= max_text_size) { - struct sr_location location; - sr_location_init(&location); + char *error_msg = NULL; + const char *analyzer = problem_data_get_content_or_NULL(problem_data, FILENAME_ANALYZER); + if (!analyzer) + return 0; + + /* For CCpp crashes, use the GDB-produced backtrace which should be + * available by now. sr_abrt_type_from_analyzer returns SR_REPORT_CORE + * by default for CCpp crashes. + */ + enum sr_report_type report_type = sr_abrt_type_from_analyzer(analyzer); + if (strcmp(analyzer, "CCpp") == 0) + report_type = SR_REPORT_GDB;
- /* sr_gdb_stacktrace_parse modifies the input parameter */ - char *content = item->content; - struct sr_gdb_stacktrace *backtrace = sr_gdb_stacktrace_parse((const char **)&content, &location); + struct sr_stacktrace *backtrace = sr_stacktrace_parse(report_type, + item->content, &error_msg);
if (!backtrace) { - log(_("Can't parse backtrace")); + log(_("Can't parse backtrace: %s"), error_msg); + free(error_msg); return 0; }
/* Get optimized thread stack trace for 10 top most frames */ - struct sr_gdb_thread *thread = sr_gdb_stacktrace_get_optimized_thread(backtrace, 10); - - sr_gdb_stacktrace_free(backtrace); + truncated = sr_stacktrace_to_short_text(backtrace, 10); + sr_stacktrace_free(backtrace);
- if (!thread) + if (!truncated) { - log(_("Can't find crash thread")); + log(_("Can't generate stacktrace description (no crash thread?)")); return 0; } - - /* Cannot be NULL, it dies on memory error */ - struct sr_strbuf *bt = sr_strbuf_new(); - - sr_gdb_thread_append_to_str(thread, bt, true); - - sr_gdb_thread_free(thread); - - truncated = sr_strbuf_free_nobuf(bt); }
append_text(result,