From: Nicholas Nethercote Date: Mon, 10 Aug 2009 08:25:39 +0000 (+0000) Subject: Try to fix error_counts. X-Git-Tag: svn/VALGRIND_3_5_0~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=675914e02586d8b31d5efaa720bf4c1855010627;p=thirdparty%2Fvalgrind.git Try to fix error_counts. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10768 --- diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index 51ed7cf90d..41918357cc 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -737,10 +737,11 @@ void VG_(maybe_record_error) ( ThreadId tid, guaranteed to only happen once. This avoids all the recording and comparing stuff. But they can be suppressed; returns True if it is suppressed. Bool 'print_error' dictates whether to print the error. + Bool 'count_error' dictates whether to count the error in n_errs_found. */ Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s, void* extra, ExeContext* where, Bool print_error, - Bool allow_db_attach ) + Bool allow_db_attach, Bool count_error ) { Error err; Supp *su; @@ -759,7 +760,8 @@ Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s, su = is_suppressible_error(&err); if (NULL == su) { - n_errs_found++; + if (count_error) + n_errs_found++; if (print_error) { /* A bit of prettyprinting, to ensure there's a blank line diff --git a/include/pub_tool_errormgr.h b/include/pub_tool_errormgr.h index 01c073e9fc..a473c6b641 100644 --- a/include/pub_tool_errormgr.h +++ b/include/pub_tool_errormgr.h @@ -85,7 +85,7 @@ extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind, extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s, void* extra, ExeContext* where, Bool print_error, - Bool allow_GDB_attach ); + Bool allow_GDB_attach, Bool count_error ); /* Gets a non-blank, non-comment line from fd. bufpp is a pointer to a pointer to a buffer that must be allocated with VG_(malloc); nBufp is a diff --git a/memcheck/mc_errors.c b/memcheck/mc_errors.c index d57e819885..07b42742da 100644 --- a/memcheck/mc_errors.c +++ b/memcheck/mc_errors.c @@ -942,7 +942,7 @@ void MC_(record_overlap_error) ( ThreadId tid, Char* function, Bool MC_(record_leak_error) ( ThreadId tid, UInt n_this_record, UInt n_total_records, LossRecord* lr, - Bool print_record ) + Bool print_record, Bool count_error ) { MC_Error extra; extra.Err.Leak.n_this_record = n_this_record; @@ -951,7 +951,7 @@ Bool MC_(record_leak_error) ( ThreadId tid, UInt n_this_record, return VG_(unique_error) ( tid, Err_Leak, /*Addr*/0, /*s*/NULL, &extra, lr->key.allocated_at, print_record, - /*allow_GDB_attach*/False ); + /*allow_GDB_attach*/False, count_error ); } void MC_(record_user_error) ( ThreadId tid, Addr a, diff --git a/memcheck/mc_include.h b/memcheck/mc_include.h index c6ff0c8417..920378362a 100644 --- a/memcheck/mc_include.h +++ b/memcheck/mc_include.h @@ -348,7 +348,8 @@ Bool MC_(record_leak_error) ( ThreadId tid, UInt n_this_record, UInt n_total_records, LossRecord* lossRecord, - Bool print_record ); + Bool print_record, + Bool count_error ); /* Is this address in a user-specified "ignored range" ? */ Bool MC_(in_ignored_range) ( Addr a ); diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c index 723a6e1176..68b317e1ad 100644 --- a/memcheck/mc_leakcheck.c +++ b/memcheck/mc_leakcheck.c @@ -828,7 +828,7 @@ static void print_results(ThreadId tid, Bool is_full_check) // Print the loss records (in size order) and collect summary stats. for (i = 0; i < n_lossrecords; i++) { - Bool print_record; + Bool count_as_error, print_record; // Rules for printing: // - We don't show suppressed loss records ever (and that's controlled // within the error manager). @@ -842,12 +842,13 @@ static void print_results(ThreadId tid, Bool is_full_check) // includes indirectly lost blocks! // lr = lr_array[i]; + count_as_error = Unreached == lr->key.state || + Possible == lr->key.state; print_record = is_full_check && - ( MC_(clo_show_reachable) || - Unreached == lr->key.state || - Possible == lr->key.state ); + ( MC_(clo_show_reachable) || count_as_error ); is_suppressed = - MC_(record_leak_error) ( tid, i+1, n_lossrecords, lr, print_record ); + MC_(record_leak_error) ( tid, i+1, n_lossrecords, lr, print_record, + count_as_error ); if (is_suppressed) { MC_(blocks_suppressed) += lr->num_blocks; diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index f8e6e92031..14200ad5a6 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -59,7 +59,7 @@ EXTRA_DIST = \ describe-block.stderr.exp describe-block.vgtest \ doublefree.stderr.exp doublefree.vgtest \ erringfds.stderr.exp erringfds.stdout.exp erringfds.vgtest \ - error_counts.stderr.exp error_counts.stdout.exp error_counts.vgtest \ + error_counts.stderr.exp error_counts.vgtest \ errs1.stderr.exp errs1.vgtest \ exitprog.stderr.exp exitprog.vgtest \ execve.stderr.exp execve.vgtest \ diff --git a/memcheck/tests/error_counts.c b/memcheck/tests/error_counts.c index 336be0c656..5268cdbc0d 100644 --- a/memcheck/tests/error_counts.c +++ b/memcheck/tests/error_counts.c @@ -17,7 +17,7 @@ int main(void) assert(sizeof(long) == sizeof(void*)); /* Error counting */ - printf("errors: %d\n\n", VALGRIND_COUNT_ERRORS); + fprintf(stderr, "errors: %d\n\n", VALGRIND_COUNT_ERRORS); if (x == 0) { y++; @@ -25,16 +25,20 @@ int main(void) y--; } - printf("errors: %d\n\n", VALGRIND_COUNT_ERRORS); + fprintf(stderr, "errors: %d\n\n", VALGRIND_COUNT_ERRORS); // Get a baseline, after start-up and also after printf (because Darwin // printf allocates memory the first time it's called!) GET_INITIAL_LEAK_COUNTS; + fprintf(stderr, "errors: %d\n\n", VALGRIND_COUNT_ERRORS); + /* Leak checking */ GET_FINAL_LEAK_COUNTS; - PRINT_LEAK_COUNTS(stdout); - printf("\n"); + PRINT_LEAK_COUNTS(stderr); + fprintf(stderr, "\n"); + + fprintf(stderr, "errors: %d\n\n", VALGRIND_COUNT_ERRORS); leaked = malloc(77); leaked = 0; @@ -45,10 +49,10 @@ int main(void) reachable = malloc(99); GET_FINAL_LEAK_COUNTS; - PRINT_LEAK_COUNTS(stdout); - printf("\n"); + PRINT_LEAK_COUNTS(stderr); + fprintf(stderr, "\n"); - printf("errors: %d\n", VALGRIND_COUNT_ERRORS); + fprintf(stderr, "errors: %d\n", VALGRIND_COUNT_ERRORS); return 0; } diff --git a/memcheck/tests/error_counts.stderr.exp b/memcheck/tests/error_counts.stderr.exp index e69de29bb2..cb366e964b 100644 --- a/memcheck/tests/error_counts.stderr.exp +++ b/memcheck/tests/error_counts.stderr.exp @@ -0,0 +1,19 @@ +errors: 0 + +errors: 1 + +errors: 1 + +leaked: 0 bytes in 0 blocks +dubious: 0 bytes in 0 blocks +reachable: 0 bytes in 0 blocks +suppressed: 0 bytes in 0 blocks + +errors: 1 + +leaked: 77 bytes in 1 blocks +dubious: 88 bytes in 1 blocks +reachable: 99 bytes in 1 blocks +suppressed: 0 bytes in 0 blocks + +errors: 3 diff --git a/memcheck/tests/error_counts.stdout.exp b/memcheck/tests/error_counts.stdout.exp deleted file mode 100644 index 9ad46a128c..0000000000 --- a/memcheck/tests/error_counts.stdout.exp +++ /dev/null @@ -1,15 +0,0 @@ -errors: 0 - -errors: 1 - -leaked: 0 bytes in 0 blocks -dubious: 0 bytes in 0 blocks -reachable: 0 bytes in 0 blocks -suppressed: 0 bytes in 0 blocks - -leaked: 77 bytes in 1 blocks -dubious: 88 bytes in 1 blocks -reachable: 99 bytes in 1 blocks -suppressed: 0 bytes in 0 blocks - -errors: 10