diff --git a/corecheck/tests/Makefile.am b/corecheck/tests/Makefile.am index 319c8de6e..d1a9ba94f 100644 --- a/corecheck/tests/Makefile.am +++ b/corecheck/tests/Makefile.am @@ -1,24 +1 @@ -##--------------------------------------------------------------------------- -## These test core error checking, eg. "silly values" for malloc/calloc, -## pthread errors (and suppressions), signal handling errors, invalid fds for -## blocking syscalls, etc. -##--------------------------------------------------------------------------- - noinst_SCRIPTS = filter_stderr - -EXTRA_DIST = $(noinst_SCRIPTS) \ - erringfds.stderr.exp erringfds.stdout.exp erringfds.vgtest \ - sigkill.stderr.exp sigkill.stderr.exp2 sigkill.vgtest \ - stack_changes.vgtest - -check_PROGRAMS = \ - erringfds sigkill stack_changes - -AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -g -O0 -AM_CPPFLAGS = -I$(top_srcdir)/include -AM_CXXFLAGS = $(AM_CFLAGS) - -sigkill_SOURCES = sigkill.c - -# Stack tests -stack_changes_SOURCES = stack_changes.c diff --git a/corecheck/tests/erringfds.stderr.exp b/corecheck/tests/erringfds.stderr.exp deleted file mode 100644 index b6a487d38..000000000 --- a/corecheck/tests/erringfds.stderr.exp +++ /dev/null @@ -1,4 +0,0 @@ - -Warning: invalid file descriptor -1 in syscall read() - -ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index cf6cfb025..364c38c0d 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -231,6 +231,13 @@ void VG_(set_supp_extra) ( Supp* su, void* extra ) /*--- Helper fns ---*/ /*------------------------------------------------------------*/ +// Only show core errors if the tool wants to, we're not running with -q, +// and were not outputting XML. +Bool VG_(showing_core_errors)(void) +{ + return VG_(needs).core_errors && VG_(clo_verbosity) >= 1 && !VG_(clo_xml); +} + /* Compare error contexts, to detect duplicates. Note that if they are otherwise the same, the faulting addrs and associated rwoffsets are allowed to be different. */ diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c index fc66e2370..248d29891 100644 --- a/coregrind/m_signals.c +++ b/coregrind/m_signals.c @@ -617,8 +617,7 @@ SysRes VG_(do_sys_sigaction) ( Int signo, return VG_(mk_SysRes_Success)( 0 ); bad_signo: - if (VG_(needs).core_errors && VG_(clo_verbosity) >= 1 - && !VG_(clo_xml)) { + if (VG_(showing_core_errors)()) { VG_(message)(Vg_UserMsg, "Warning: bad signal number %d in sigaction()", signo); @@ -626,8 +625,7 @@ SysRes VG_(do_sys_sigaction) ( Int signo, return VG_(mk_SysRes_Error)( VKI_EINVAL ); bad_signo_reserved: - if (VG_(needs).core_errors && VG_(clo_verbosity) >= 1 - && !VG_(clo_xml)) { + if (VG_(showing_core_errors)()) { VG_(message)(Vg_UserMsg, "Warning: ignored attempt to set %s handler in sigaction();", signame(signo)); @@ -638,8 +636,7 @@ SysRes VG_(do_sys_sigaction) ( Int signo, return VG_(mk_SysRes_Error)( VKI_EINVAL ); bad_sigkill_or_sigstop: - if (VG_(needs).core_errors && VG_(clo_verbosity) >= 1 - && !VG_(clo_xml)) { + if (VG_(showing_core_errors)()) { VG_(message)(Vg_UserMsg, "Warning: ignored attempt to set %s handler in sigaction();", signame(signo)); diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index cbef16bea..69a793d32 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -33,6 +33,7 @@ #include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr :( #include "pub_core_aspacemgr.h" #include "pub_core_debuglog.h" +#include "pub_core_errormgr.h" #include "pub_core_libcbase.h" #include "pub_core_libcassert.h" #include "pub_core_libcfile.h" @@ -857,7 +858,9 @@ static Addr do_brk(Addr newbrk) /* Return true if we're allowed to use or create this fd */ Bool ML_(fd_allowed)(Int fd, const Char *syscallname, ThreadId tid, Bool soft) { - if (fd < 0 || fd >= VG_(fd_hard_limit) || fd == VG_(clo_log_fd)) { + if ((fd < 0 || fd >= VG_(fd_hard_limit) || fd == VG_(clo_log_fd)) && + VG_(showing_core_errors)()) + { VG_(message)(Vg_UserMsg, "Warning: invalid file descriptor %d in syscall %s()", fd, syscallname); diff --git a/coregrind/pub_core_errormgr.h b/coregrind/pub_core_errormgr.h index 4483555b6..bcd1f3b15 100644 --- a/coregrind/pub_core_errormgr.h +++ b/coregrind/pub_core_errormgr.h @@ -1,3 +1,4 @@ + /*--------------------------------------------------------------------*/ /*--- ErrorMgr: management of errors and suppressions. ---*/ /*--- pub_core_errormgr.h ---*/ @@ -55,6 +56,8 @@ extern void VG_(show_error_counts_as_XML) ( void ); extern Bool VG_(is_action_requested) ( Char* action, Bool* clo ); +extern Bool VG_(showing_core_errors) ( void ); + extern UInt VG_(get_n_errs_found) ( void ); #endif // __PUB_CORE_ERRORMGR_H diff --git a/include/pub_tool_tooliface.h b/include/pub_tool_tooliface.h index 92e413a0f..3482c0103 100644 --- a/include/pub_tool_tooliface.h +++ b/include/pub_tool_tooliface.h @@ -130,8 +130,9 @@ extern void VG_(details_bug_reports_to) ( Char* bug_reports_to ); extern void VG_(needs_libc_freeres) ( void ); /* Want to have errors detected by Valgrind's core reported? Includes: - - pthread API errors (many; eg. unlocking a non-locked mutex) - - invalid file descriptors to blocking syscalls read() and write() + - pthread API errors (many; eg. unlocking a non-locked mutex) + [currently disabled] + - invalid file descriptors to syscalls like read() and write() - bad signal numbers passed to sigaction() - attempt to install signal handler for SIGKILL or SIGSTOP */ extern void VG_(needs_core_errors) ( void ); diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index bb1537fa1..85d2eed0f 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -23,6 +23,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ custom_alloc.stderr.exp custom_alloc.vgtest \ 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 \ errs1.stderr.exp errs1.vgtest \ exitprog.stderr.exp exitprog.vgtest \ @@ -65,8 +66,10 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ realloc2.stderr.exp realloc2.vgtest \ realloc3.stderr.exp realloc3.vgtest \ sigaltstack.stderr.exp sigaltstack.vgtest \ + sigkill.stderr.exp sigkill.stderr.exp2 sigkill.vgtest \ signal2.stderr.exp signal2.stdout.exp signal2.vgtest \ sigprocmask.stderr.exp sigprocmask.vgtest \ + stack_changes.stderr.exp stack_changes.stdout.exp stack_changes.vgtest \ strchr.stderr.exp strchr.vgtest \ str_tester.stderr.exp str_tester.vgtest \ supp1.stderr.exp supp1.vgtest \ @@ -88,7 +91,7 @@ check_PROGRAMS = \ badloop badpoll badrw brk brk2 buflen_check \ clientperm custom_alloc \ describe-block \ - doublefree error_counts errs1 exitprog execve execve2 \ + doublefree error_counts errs1 exitprog execve execve2 erringfds \ fprw fwrite hello inits inline \ leak-0 leak-cycle leak-tree leak-regroot leakotron \ malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \ @@ -99,8 +102,8 @@ check_PROGRAMS = \ pointer-trace \ post-syscall \ realloc1 realloc2 realloc3 \ - sigaltstack signal2 sigprocmask \ - strchr str_tester supp1 supp2 suppfree \ + sigaltstack signal2 sigprocmask sigkill \ + stack_changes strchr str_tester supp1 supp2 suppfree \ trivialleak weirdioctl \ mismatches new_override metadata \ vgtest_ume xml1 \ @@ -112,18 +115,18 @@ AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -g AM_CXXFLAGS = $(AM_CFLAGS) # C ones -addressable_SOURCES = addressable.c -badaddrvalue_SOURCES = badaddrvalue.c -badfree_SOURCES = badfree.c -badjump_SOURCES = badjump.c -badjump2_SOURCES = badjump2.c -badloop_SOURCES = badloop.c -badpoll_SOURCES = badpoll.c -badrw_SOURCES = badrw.c -brk_SOURCES = brk.c -brk2_SOURCES = brk2.c -buflen_check_SOURCES = buflen_check.c -clientperm_SOURCES = clientperm.c +#addressable_SOURCES = addressable.c +#badaddrvalue_SOURCES = badaddrvalue.c +#badfree_SOURCES = badfree.c +#badjump_SOURCES = badjump.c +#badjump2_SOURCES = badjump2.c +#badloop_SOURCES = badloop.c +#badpoll_SOURCES = badpoll.c +#badrw_SOURCES = badrw.c +#brk_SOURCES = brk.c +#brk2_SOURCES = brk2.c +#buflen_check_SOURCES = buflen_check.c +#clientperm_SOURCES = clientperm.c custom_alloc_SOURCES = custom_alloc.c describe_block_SOURCES = describe-block.c doublefree_SOURCES = doublefree.c @@ -159,13 +162,15 @@ null_socket_SOURCES = null_socket.c overlap_SOURCES = overlap.c # Don't allow GCC to inline memcpy(), because then we can't intercept it overlap_CFLAGS = $(AM_CFLAGS) -fno-builtin-memcpy -pointer_trace_SOURCES = pointer-trace.c +#pointer_trace_SOURCES = pointer-trace.c post_syscall_SOURCES = post-syscall.c realloc1_SOURCES = realloc1.c realloc2_SOURCES = realloc2.c realloc3_SOURCES = realloc3.c +sigkill_SOURCES = sigkill.c signal2_SOURCES = signal2.c sigprocmask_SOURCES = sigprocmask.c +stack_changes_SOURCES = stack_changes.c supp1_SOURCES = supp.c supp2_SOURCES = supp.c suppfree_SOURCES = suppfree.c diff --git a/corecheck/tests/erringfds.c b/memcheck/tests/erringfds.c similarity index 100% rename from corecheck/tests/erringfds.c rename to memcheck/tests/erringfds.c diff --git a/memcheck/tests/erringfds.stderr.exp b/memcheck/tests/erringfds.stderr.exp new file mode 100644 index 000000000..0516e0908 --- /dev/null +++ b/memcheck/tests/erringfds.stderr.exp @@ -0,0 +1,8 @@ + +Warning: invalid file descriptor -1 in syscall read() + +ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +malloc/free: in use at exit: 0 bytes in 0 blocks. +malloc/free: 0 allocs, 0 frees, 0 bytes allocated. +For a detailed leak analysis, rerun with: --leak-check=yes +For counts of detected errors, rerun with: -v diff --git a/corecheck/tests/erringfds.stdout.exp b/memcheck/tests/erringfds.stdout.exp similarity index 100% rename from corecheck/tests/erringfds.stdout.exp rename to memcheck/tests/erringfds.stdout.exp diff --git a/corecheck/tests/erringfds.vgtest b/memcheck/tests/erringfds.vgtest similarity index 100% rename from corecheck/tests/erringfds.vgtest rename to memcheck/tests/erringfds.vgtest diff --git a/corecheck/tests/sigkill.c b/memcheck/tests/sigkill.c similarity index 100% rename from corecheck/tests/sigkill.c rename to memcheck/tests/sigkill.c diff --git a/corecheck/tests/sigkill.stderr.exp b/memcheck/tests/sigkill.stderr.exp similarity index 94% rename from corecheck/tests/sigkill.stderr.exp rename to memcheck/tests/sigkill.stderr.exp index b71799dda..7dbb0d48f 100644 --- a/corecheck/tests/sigkill.stderr.exp +++ b/memcheck/tests/sigkill.stderr.exp @@ -196,3 +196,7 @@ Invalid argument ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +malloc/free: in use at exit: 0 bytes in 0 blocks. +malloc/free: 0 allocs, 0 frees, 0 bytes allocated. +For a detailed leak analysis, rerun with: --leak-check=yes +For counts of detected errors, rerun with: -v diff --git a/corecheck/tests/sigkill.stderr.exp2 b/memcheck/tests/sigkill.stderr.exp2 similarity index 94% rename from corecheck/tests/sigkill.stderr.exp2 rename to memcheck/tests/sigkill.stderr.exp2 index 896213faa..3cc35594a 100644 --- a/corecheck/tests/sigkill.stderr.exp2 +++ b/memcheck/tests/sigkill.stderr.exp2 @@ -196,3 +196,7 @@ Invalid argument ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +malloc/free: in use at exit: 0 bytes in 0 blocks. +malloc/free: 0 allocs, 0 frees, 0 bytes allocated. +For a detailed leak analysis, rerun with: --leak-check=yes +For counts of detected errors, rerun with: -v diff --git a/corecheck/tests/sigkill.stderr.exp3 b/memcheck/tests/sigkill.stderr.exp3 similarity index 94% rename from corecheck/tests/sigkill.stderr.exp3 rename to memcheck/tests/sigkill.stderr.exp3 index a538a530f..dfe65480d 100644 --- a/corecheck/tests/sigkill.stderr.exp3 +++ b/memcheck/tests/sigkill.stderr.exp3 @@ -196,3 +196,7 @@ Invalid argument ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +malloc/free: in use at exit: 0 bytes in 0 blocks. +malloc/free: 0 allocs, 0 frees, 0 bytes allocated. +For a detailed leak analysis, rerun with: --leak-check=yes +For counts of detected errors, rerun with: -v diff --git a/corecheck/tests/sigkill.vgtest b/memcheck/tests/sigkill.vgtest similarity index 100% rename from corecheck/tests/sigkill.vgtest rename to memcheck/tests/sigkill.vgtest diff --git a/corecheck/tests/stack_changes.c b/memcheck/tests/stack_changes.c similarity index 100% rename from corecheck/tests/stack_changes.c rename to memcheck/tests/stack_changes.c diff --git a/corecheck/tests/stack_changes.stderr.exp b/memcheck/tests/stack_changes.stderr.exp similarity index 100% rename from corecheck/tests/stack_changes.stderr.exp rename to memcheck/tests/stack_changes.stderr.exp diff --git a/corecheck/tests/stack_changes.stdout.exp b/memcheck/tests/stack_changes.stdout.exp similarity index 100% rename from corecheck/tests/stack_changes.stdout.exp rename to memcheck/tests/stack_changes.stdout.exp diff --git a/corecheck/tests/stack_changes.vgtest b/memcheck/tests/stack_changes.vgtest similarity index 100% rename from corecheck/tests/stack_changes.vgtest rename to memcheck/tests/stack_changes.vgtest