From d680f664651e34cfde6f183aa1ff5a9e76870367 Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Sun, 23 Dec 2018 22:56:38 +0100 Subject: [PATCH] Implement option --show-error-list=no|yes -s This option allows to list the detected errors and show the used suppressions without increasing the verbosity. Increasing the verbosity also activates a lot of messages that are often not very useful for the user. So, this option allows to see the list of errors and used suppressions independently of the verbosity. Note if a high verbosity is selected, the behaviour is unchanged. In other words, when specifying -v, the list of detected errors and the used suppressions are still shown, even if --show-error-list=yes and -s are not used. --- coregrind/m_errormgr.c | 34 ++++++++++++++++++--------------- coregrind/m_main.c | 29 ++++++++++++++++++++++++---- coregrind/m_options.c | 2 ++ coregrind/pub_core_options.h | 7 +++++++ drd/tests/filter_stderr | 2 +- exp-sgcheck/tests/filter_stderr | 2 +- helgrind/tests/filter_stderr | 2 +- 7 files changed, 56 insertions(+), 22 deletions(-) diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index 5dc1725200..fb41e4ebd5 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -979,29 +979,31 @@ void VG_(show_all_errors) ( Int verbosity, Bool xml ) Int i, n_min; Error *p, *p_min; Bool any_supp; + Bool any_error = False; - if (verbosity == 0) + if (verbosity == 0 && !VG_(clo_show_error_list)) return; /* If we're printing XML, just show the suppressions and stop. */ if (xml) { - (void)show_used_suppressions(); + if (VG_(clo_show_error_list)) + (void)show_used_suppressions(); return; } /* We only get here if not printing XML. */ VG_(umsg)("ERROR SUMMARY: " "%u errors from %u contexts (suppressed: %u from %u)\n", - n_errs_found, n_err_contexts, + n_errs_found, n_err_contexts, n_errs_suppressed, n_supp_contexts ); - if (verbosity <= 1) + if (!VG_(clo_show_error_list)) return; - // We do the following only at -v or above, and only in non-XML - // mode + // We do the following if VG_(clo_show_error_list) + // or at -v or above, and only in non-XML mode. - /* Print the contexts in order of increasing error count. + /* Print the contexts in order of increasing error count. Once an error is shown, we add a huge value to its count to filter it out. After having shown all errors, we reset count to the original value. */ @@ -1018,6 +1020,7 @@ void VG_(show_all_errors) ( Int verbosity, Bool xml ) // XXX: this isn't right. See bug 203651. if (p_min == NULL) continue; //VG_(core_panic)("show_all_errors()"); + any_error = True; VG_(umsg)("\n"); VG_(umsg)("%d errors in context %d of %u:\n", p_min->count, i+1, n_err_contexts); @@ -1035,9 +1038,9 @@ void VG_(show_all_errors) ( Int verbosity, Bool xml ) } p_min->count = p_min->count + (1 << 30); - } + } - /* reset the counts, otherwise a 2nd call does not show anything anymore */ + /* reset the counts, otherwise a 2nd call does not show anything anymore */ for (p = errors; p != NULL; p = p->next) { if (p->count >= (1 << 30)) p->count = p->count - (1 << 30); @@ -1046,14 +1049,15 @@ void VG_(show_all_errors) ( Int verbosity, Bool xml ) any_supp = show_used_suppressions(); - if (any_supp) + if (any_supp) VG_(umsg)("\n"); - // reprint this, so users don't have to scroll way up to find + // reprint summary, so users don't have to scroll way up to find // the first printing - VG_(umsg)("ERROR SUMMARY: " - "%u errors from %u contexts (suppressed: %u from %u)\n", - n_errs_found, n_err_contexts, n_errs_suppressed, - n_supp_contexts ); + if (any_supp || any_error) + VG_(umsg)("ERROR SUMMARY: " + "%u errors from %u contexts (suppressed: %u from %u)\n", + n_errs_found, n_err_contexts, n_errs_suppressed, + n_supp_contexts ); } void VG_(show_last_error) ( void ) diff --git a/coregrind/m_main.c b/coregrind/m_main.c index cb4268569d..7d987ea266 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -129,6 +129,9 @@ static void usage_NORETURN ( Bool debug_help ) " --error-exitcode= exit code to return if errors found [0=disable]\n" " --error-markers=, add lines with begin/end markers before/after\n" " each error output in plain text mode [none]\n" +" --show-error-list=no|yes show detected errors list and\n" +" suppression counts at exit [no]\n" +" -s same as --show-error-list=yes\n" " --keep-debuginfo=no|yes Keep symbols etc for unloaded code [no]\n" " This allows saved stack traces (e.g. memory leaks)\n" " to include file/line info for code that has been\n" @@ -459,9 +462,11 @@ void main_process_cmd_line_options( void ) Int toolname_len = VG_(strlen)(VG_(clo_toolname)); const HChar* tmp_str; // Used in a couple of places. - /* Whether the user has explicitly provided --sigill-diagnostics. + /* Whether the user has explicitly provided --sigill-diagnostics + or --show-error-list. If not explicitly given depends on general verbosity setting. */ Bool sigill_diag_set = False; + Bool show_error_list_set = False; /* Log to stderr by default, but usage message goes to stdout. XML output is initially disabled. */ @@ -636,6 +641,12 @@ void main_process_cmd_line_options( void ) startpos = *nextpos ? nextpos + 1 : nextpos; } } + else if VG_BOOL_CLO(arg, "--show-error-list", VG_(clo_show_error_list)) { + show_error_list_set = True; } + else if (VG_STREQ(arg, "-s")) { + VG_(clo_show_error_list) = True; + show_error_list_set = True; + } else if VG_BOOL_CLO(arg, "--show-emwarns", VG_(clo_show_emwarns)) {} else if VG_BOOL_CLO(arg, "--run-libc-freeres", VG_(clo_run_libc_freeres)) {} @@ -920,6 +931,13 @@ void main_process_cmd_line_options( void ) if (!sigill_diag_set) VG_(clo_sigill_diag) = (VG_(clo_verbosity) > 0); + if (!show_error_list_set) { + if (VG_(clo_xml)) + VG_(clo_show_error_list) = VG_(clo_verbosity) >= 1; + else + VG_(clo_show_error_list) = VG_(clo_verbosity) >= 2; + } + if (VG_(clo_trace_notbelow) == -1) { if (VG_(clo_trace_notabove) == -1) { /* [] */ @@ -2153,9 +2171,12 @@ void shutdown_actions_NORETURN( ThreadId tid, VG_TDICT_CALL(tool_fini, 0/*exitcode*/); if (VG_(needs).core_errors || VG_(needs).tool_errors) { - if (VG_(clo_verbosity) == 1 && !VG_(clo_xml)) - VG_(message)(Vg_UserMsg, - "For counts of detected and suppressed errors, rerun with: -v\n"); + if (VG_(clo_verbosity) == 1 + && !VG_(clo_xml) + && !VG_(clo_show_error_list)) + VG_(message)(Vg_UserMsg, + "For lists of detected and suppressed errors," + " rerun with: -s\n"); /* Show the error counts. */ if (VG_(clo_xml)) { diff --git a/coregrind/m_options.c b/coregrind/m_options.c index 67eed342ba..f9e9c8b0f6 100644 --- a/coregrind/m_options.c +++ b/coregrind/m_options.c @@ -54,6 +54,8 @@ Int VG_(clo_error_exitcode) = 0; HChar *VG_(clo_error_markers)[2] = {NULL, NULL}; Bool VG_(clo_exit_on_first_error) = False; +Bool VG_(clo_show_error_list) = False; + #if defined(VGPV_arm_linux_android) \ || defined(VGPV_x86_linux_android) \ || defined(VGPV_mips32_linux_android) \ diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h index 3bae7f3f19..9a75da70c6 100644 --- a/coregrind/pub_core_options.h +++ b/coregrind/pub_core_options.h @@ -51,6 +51,13 @@ extern Bool VG_(clo_exit_on_first_error); way. */ extern Int VG_(clo_error_exitcode); +/* For tools that report errors, list detected errors and show suppression + usage counts at exit. Default: No. + Unless set explicitly by the user, the option is automatically + considered as set to yes for verbosity > 1. */ +extern Bool VG_(clo_show_error_list); + + /* Markers used to mark the begin/end of an error, when errors are printed in textual (non xml) format. [0] is the error begin marker, [1] is the error end marker. diff --git a/drd/tests/filter_stderr b/drd/tests/filter_stderr index 9347e4ecd8..7fbddbfe2e 100755 --- a/drd/tests/filter_stderr +++ b/drd/tests/filter_stderr @@ -42,7 +42,7 @@ sed \ -e "s/ (\([a-zA-Z_]*\.cpp\):[0-9]*)/ (\1:?)/" \ -e "s/\( name [^ ]*\)-[0-9]*\( oflag \)/\1\2/" \ -e '/^ by 0x[0-9a-fA-F]*: process_dl_debug (in \/lib[0-9]*\/ld-[0-9.]*\.so)$/d' \ --e "/^For counts of detected and suppressed errors, rerun with: -v$/d" | +-e "/^For detected errors list and suppressed errors count, rerun with: -s$/d" | # Remove the message that more than hundred errors have been detected # (consists of two lines) and also the empty line above it. diff --git a/exp-sgcheck/tests/filter_stderr b/exp-sgcheck/tests/filter_stderr index 174bc94377..94bd8736aa 100755 --- a/exp-sgcheck/tests/filter_stderr +++ b/exp-sgcheck/tests/filter_stderr @@ -19,7 +19,7 @@ sed \ -e "/^exp-sgcheck, a stack and global array overrun detector$/d" \ -e "/^NOTE: This is an Experimental-Class Valgrind Tool$/d" \ -e "/^Copyright (C) 2003-201., and GNU GPL'd, by OpenWorks Ltd et al.$/d" \ --e "/^For counts of detected and suppressed errors, rerun with: -v$/d" | +-e "/^For detected errors list and suppressed errors count, rerun with: -s$/d" | # Tidy up in cases where glibc (+ libdl + libpthread + ld) have # been built with debugging information, hence source locs are present. diff --git a/helgrind/tests/filter_stderr b/helgrind/tests/filter_stderr index cfdd89496a..0e7072357b 100755 --- a/helgrind/tests/filter_stderr +++ b/helgrind/tests/filter_stderr @@ -42,7 +42,7 @@ sed \ # do not contain them (at least on gcc110/fedora18). sed \ -e "/^Helgrind, a thread error detector/ , /./ d" \ - -e "/^For counts of detected and suppressed errors, rerun with: -v$/d" \ + -e "/^For detected errors list and suppressed errors count, rerun with: -s$/d" \ -e "/^Use --history-level=approx or =none to gain increased speed, at$/d" \ -e "/^the cost of reduced accuracy of conflicting-access information$/d" \ -e "/pthread_create_WRK (hg_intercepts.c:/d" | -- 2.47.2