Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com --- src/cli/cli.c | 34 +++++++++++++++- src/cli/report.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++---- src/cli/report.h | 3 +- src/plugins/Makefile.am | 4 +- 4 files changed, 122 insertions(+), 15 deletions(-)
diff --git a/src/cli/cli.c b/src/cli/cli.c index 0c895a7..a9e70bc 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -360,6 +360,9 @@ int main(int argc, char** argv) print_usage_and_die(argv[0]); }
+ /* Get settings */ + load_event_config_data(); + /* Do the selected operation. */ int exitcode = 0; switch (op) @@ -409,15 +412,40 @@ int main(int argc, char** argv) } case OPT_INFO: { - if (run_analyze_event(dump_dir_name) != 0) - return 1; - /* Load crash_data from (possibly updated by analyze) dump dir */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return -1; + + char *events_as_lines = list_possible_events(dd, NULL, "analyze"); crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); dd_close(dd); + + GList *list_events = NULL; + if (events_as_lines && *events_as_lines) + { + char *events = events_as_lines; + while (*events) + { + char *end = strchrnul(events, '\n'); + char *tmp = xstrndup(events, end - events); + list_events = g_list_append(list_events, tmp); + events = end; + if (!*events) + break; + events++; + } + + char *event = select_event_option(list_events); + list_free_with_free(list_events); + + int analyzer_result = run_analyze_event(dump_dir_name, event); + free(event); + + if (analyzer_result != 0) + return 1; + } + add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name, CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE);
diff --git a/src/cli/report.cpp b/src/cli/report.cpp index da37bea..f1836b4 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -15,9 +15,9 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "report.h" -#include "run-command.h" #include "abrtlib.h" +#include "run-command.h" +#include "report.h"
/* Field separator for the crash report file that is edited by user. */ #define FIELD_SEP "%----" @@ -553,7 +553,8 @@ static int run_events(const char *dump_dir_name, int r = run_event_on_dir_name(run_state, dump_dir_name, event.c_str()); if (r == 0 && run_state->children_count == 0) { - l_state.last_line = xasprintf("Error: no processing is specified for event '%s'", event.c_str()); + l_state.last_line = xasprintf("Error: no processing is specified for event '%s'", + event.c_str()); r = -1; } if (r == 0) @@ -585,33 +586,110 @@ static char *do_log(char *log_line, void *param) log("%s", log_line); return log_line; } -int run_analyze_event(const char *dump_dir_name) + +int run_analyze_event(const char *dump_dir_name, const char *analyzer) { VERB2 log("run_analyze_event('%s')", dump_dir_name);
struct run_event_state *run_state = new_run_event_state(); run_state->logging_callback = do_log; - int res = run_event_on_dir_name(run_state, dump_dir_name, "analyze_LocalGDB"); + int res = run_event_on_dir_name(run_state, dump_dir_name, analyzer); free_run_event_state(run_state); return res; }
+/* show even description? */ +char *select_event_option(GList *list_options) +{ + if (!list_options) + return NULL; + + unsigned count = g_list_length(list_options) - 1; + if (!count) + return NULL; + + int pos = -1; + fprintf(stdout, "Select how you would like to analyze the problem:\n"); + for (GList *li = list_options; li; li = li->next) + { + char *opt = (char*)li->data; + event_config_t *config = get_event_config(opt); + if (config) + { + ++pos; + printf(" %i) %s\n", pos, config->screen_name); + } + } + + unsigned picked; + unsigned ii; + for (ii = 0; ii < 3; ++ii) + { + fprintf(stdout, "Choose option [0 - %u]: ", count); + fflush(NULL); + + char answer[16]; + if (!fgets(answer, sizeof(answer), stdin)) + continue; + + answer[strlen(answer) - 1] = '\0'; + if (!*answer) + continue; + + picked = xatou(answer); + if (picked > count) + { + log(_("You have chosen number out of range")); + continue; + } + + break; + } + + if (ii == 3) + error_msg_and_die(_("Invalid input, porgram exiting...")); + + GList *choosen = g_list_nth(list_options, picked); + return xstrdup((char*)choosen->data); +}
/* Report the crash */ int report(const char *dump_dir_name, int flags) { - if (run_analyze_event(dump_dir_name) != 0) - return 1; - /* Load crash_data from (possibly updated by analyze) dump dir */ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return -1;
crash_data_t *crash_data = create_crash_data_from_dump_dir(dd); - char *events_as_lines = list_possible_events(dd, NULL, ""); + char *events_as_lines = list_possible_events(dd, NULL, "analyze"); dd_close(dd);
+ GList *list_events = NULL; + if (events_as_lines && *events_as_lines) + { + char *events = events_as_lines; + while (*events) + { + char *end = strchrnul(events, '\n'); + char *tmp = xstrndup(events, end - events); + list_events = g_list_append(list_events, tmp); + events = end; + if (!*events) + break; + events++; + } + + char *event = select_event_option(list_events); + list_free_with_free(list_events); + + int analyzer_result = run_analyze_event(dump_dir_name, event); + free(event); + + if (analyzer_result != 0) + return 1; + } + if (!(flags & CLI_REPORT_BATCH)) { /* Open text editor and give a chance to review the backtrace etc */ diff --git a/src/cli/report.h b/src/cli/report.h index 58b8c25..28485d7 100644 --- a/src/cli/report.h +++ b/src/cli/report.h @@ -22,7 +22,8 @@ extern "C" { #endif
-int run_analyze_event(const char *dump_dir_name); +int run_analyze_event(const char *dump_dir_name, const char *analyzer); +char *select_event_option(GList *list_options);
/* Report the crash */ enum { diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 5344cdb..7468188 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -65,8 +65,8 @@ $(DESTDIR)/$(DEBUG_INFO_DIR): $(mkdir_p) '$@'
install-data-hook: $(DESTDIR)/$(DEBUG_INFO_DIR) - $(LN_S) analyze_RetraceServer.xml $(DESTDIR)$(eventsdir)/reanalyze_RetraceServer.xml - $(LN_S) analyze_LocalGDB.xml $(DESTDIR)$(eventsdir)/reanalyze_LocalGDB.xml + $(LN_S) -f analyze_RetraceServer.xml $(DESTDIR)$(eventsdir)/reanalyze_RetraceServer.xml + $(LN_S) -f analyze_LocalGDB.xml $(DESTDIR)$(eventsdir)/reanalyze_LocalGDB.xml
abrt_dump_oops_SOURCES = \ abrt-dump-oops.c