From 77f136cef414e8c3f3657bf9c8de2721afd45d1f Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Wed, 12 Nov 2014 19:43:29 +0000 Subject: [PATCH] Implement Option --error-markers=, * This option can be used to mark the begin/end of errors in textual output mode, to facilitate searching/extracting errors in output files mixing valgrind errors with program output. * Use the new option in various existing regtests to test the various possible usage. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14714 --- NEWS | 5 +++++ coregrind/m_errormgr.c | 4 ++++ coregrind/m_main.c | 27 ++++++++++++++++++++++++++ coregrind/m_options.c | 1 + coregrind/pub_core_options.h | 6 ++++++ docs/xml/manual-core.xml | 17 ++++++++++++++++ memcheck/tests/badaddrvalue.stderr.exp | 4 ++++ memcheck/tests/badaddrvalue.vgtest | 2 +- memcheck/tests/manuel1.stderr.exp | 1 + memcheck/tests/manuel1.vgtest | 2 +- memcheck/tests/manuel2.stderr.exp | 1 + memcheck/tests/manuel2.stderr.exp64 | 1 + memcheck/tests/manuel2.vgtest | 2 +- memcheck/tests/manuel3.vgtest | 2 +- none/tests/cmdline1.stdout.exp | 2 ++ none/tests/cmdline2.stdout.exp | 2 ++ 16 files changed, 75 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 4bcf9293e7..b6f36d7e1b 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,11 @@ Release 3.11.0 is under development, not yet released. * ==================== OTHER CHANGES ==================== +* Option --error-markers=, can be used to mark + the begin/end of errors in textual output mode, to facilitate + searching/extracting errors in output files mixing valgrind + errors with program output. + * ==================== FIXED BUGS ==================== The following bugs have been fixed or resolved. Note that "n-i-bz" diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index 7a801f59bd..b00d9e77d8 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -626,6 +626,8 @@ static void pp_Error ( const Error* err, Bool allow_db_attach, Bool xml ) } else { + if (VG_(clo_error_markers)[0]) + VG_(umsg)("%s\n", VG_(clo_error_markers)[0]); VG_TDICT_CALL( tool_before_pp_Error, err ); if (VG_(tdict).tool_show_ThreadIDs_for_errors @@ -641,6 +643,8 @@ static void pp_Error ( const Error* err, Bool allow_db_attach, Bool xml ) VG_TDICT_CALL( tool_pp_Error, err ); VG_(umsg)("\n"); + if (VG_(clo_error_markers)[1]) + VG_(umsg)("%s\n", VG_(clo_error_markers)[1]); do_actions_on_error(err, allow_db_attach); } diff --git a/coregrind/m_main.c b/coregrind/m_main.c index c61f19de13..403955870f 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -127,6 +127,8 @@ static void usage_NORETURN ( Bool debug_help ) " --num-callers= show callers in stack traces [12]\n" " --error-limit=no|yes stop showing new errors if too many? [yes]\n" " --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-below-main=no|yes continue stack traces below main() [no]\n" " --default-suppressions=yes|no\n" " load default suppressions [yes]\n" @@ -580,6 +582,31 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, else if VG_STR_CLO (arg, "--soname-synonyms",VG_(clo_soname_synonyms)) {} else if VG_BOOL_CLO(arg, "--error-limit", VG_(clo_error_limit)) {} else if VG_INT_CLO (arg, "--error-exitcode", VG_(clo_error_exitcode)) {} + else if VG_STR_CLO (arg, "--error-markers", tmp_str) { + Int m; + const HChar *startpos = tmp_str; + const HChar *nextpos; + for (m = 0; + m < sizeof(VG_(clo_error_markers)) + /sizeof(VG_(clo_error_markers)[0]); + m++) { + /* Release previous value if clo given multiple times. */ + VG_(free)(VG_(clo_error_markers)[m]); + VG_(clo_error_markers)[m] = NULL; + + nextpos = VG_(strchr)(startpos, ','); + if (!nextpos) + nextpos = startpos + VG_(strlen)(startpos); + if (startpos != nextpos) { + VG_(clo_error_markers)[m] + = VG_(malloc)("", nextpos - startpos + 1); + VG_(memcpy)(VG_(clo_error_markers)[m], startpos, + nextpos - startpos); + VG_(clo_error_markers)[m][nextpos - startpos] = '\0'; + } + startpos = *nextpos ? nextpos + 1 : nextpos; + } + } 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)) {} diff --git a/coregrind/m_options.c b/coregrind/m_options.c index 6c1d1bfa1c..5284f2552f 100644 --- a/coregrind/m_options.c +++ b/coregrind/m_options.c @@ -46,6 +46,7 @@ VexControl VG_(clo_vex_control); Bool VG_(clo_error_limit) = True; Int VG_(clo_error_exitcode) = 0; +HChar *VG_(clo_error_markers)[2] = {NULL, NULL}; #if defined(VGPV_arm_linux_android) \ || defined(VGPV_x86_linux_android) \ diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h index de2adf24c1..1b49554161 100644 --- a/coregrind/pub_core_options.h +++ b/coregrind/pub_core_options.h @@ -46,6 +46,12 @@ extern Bool VG_(clo_error_limit); way. */ extern Int VG_(clo_error_exitcode); +/* 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. + default: no markers. */ +extern HChar *VG_(clo_error_markers)[2]; + typedef enum { Vg_VgdbNo, // Do not activate gdbserver. diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml index 55c831af68..f11e9b166b 100644 --- a/docs/xml/manual-core.xml +++ b/docs/xml/manual-core.xml @@ -1160,6 +1160,23 @@ that can report errors, e.g. Memcheck, but not Cachegrind. + + + + + + When errors are output as plain text (i.e. XML not used), + instructs to output a line + containing the () + string before (after) each error. + Such marker lines facilitate searching for errors and/or + extracting errors in an output file that contain valgrind errors mixed + with the program output. + Note that empty markers are accepted. So, only using a begin + (or an end) marker is possible. + + + diff --git a/memcheck/tests/badaddrvalue.stderr.exp b/memcheck/tests/badaddrvalue.stderr.exp index 7d2407e29f..fced525b76 100644 --- a/memcheck/tests/badaddrvalue.stderr.exp +++ b/memcheck/tests/badaddrvalue.stderr.exp @@ -1,12 +1,16 @@ +[[[ Invalid write of size 1 at 0x........: main (badaddrvalue.c:8) Address 0x........ is 1 bytes before a block of size 8 alloc'd at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: main (badaddrvalue.c:7) +]]] +[[[ Invalid read of size 1 at 0x........: main (badaddrvalue.c:9) Address 0x........ is 1 bytes before a block of size 8 alloc'd at 0x........: malloc (vg_replace_malloc.c:...) by 0x........: main (badaddrvalue.c:7) +]]] diff --git a/memcheck/tests/badaddrvalue.vgtest b/memcheck/tests/badaddrvalue.vgtest index 4d4b7f6806..f58e9608a5 100644 --- a/memcheck/tests/badaddrvalue.vgtest +++ b/memcheck/tests/badaddrvalue.vgtest @@ -1,2 +1,2 @@ prog: badaddrvalue -vgopts: -q +vgopts: -q --error-markers=[[[,]]] diff --git a/memcheck/tests/manuel1.stderr.exp b/memcheck/tests/manuel1.stderr.exp index f55ce0b646..3e825da3b6 100644 --- a/memcheck/tests/manuel1.stderr.exp +++ b/memcheck/tests/manuel1.stderr.exp @@ -1,3 +1,4 @@ +[[[ Conditional jump or move depends on uninitialised value(s) at 0x........: main (manuel1.c:7) diff --git a/memcheck/tests/manuel1.vgtest b/memcheck/tests/manuel1.vgtest index 853f8dfdbc..5590b0f29a 100644 --- a/memcheck/tests/manuel1.vgtest +++ b/memcheck/tests/manuel1.vgtest @@ -1,2 +1,2 @@ prog: manuel1 -vgopts: -q +vgopts: -q --error-markers=[[[ diff --git a/memcheck/tests/manuel2.stderr.exp b/memcheck/tests/manuel2.stderr.exp index a9d575d0f4..7a29c11ee3 100644 --- a/memcheck/tests/manuel2.stderr.exp +++ b/memcheck/tests/manuel2.stderr.exp @@ -1,3 +1,4 @@ Use of uninitialised value of size 4 at 0x........: main (manuel2.c:10) +]]] diff --git a/memcheck/tests/manuel2.stderr.exp64 b/memcheck/tests/manuel2.stderr.exp64 index 5bc75f510e..3fe5e52aea 100644 --- a/memcheck/tests/manuel2.stderr.exp64 +++ b/memcheck/tests/manuel2.stderr.exp64 @@ -1,3 +1,4 @@ Use of uninitialised value of size 8 at 0x........: main (manuel2.c:10) +]]] diff --git a/memcheck/tests/manuel2.vgtest b/memcheck/tests/manuel2.vgtest index b3729b1663..e51fae5003 100644 --- a/memcheck/tests/manuel2.vgtest +++ b/memcheck/tests/manuel2.vgtest @@ -1,2 +1,2 @@ prog: manuel2 -vgopts: -q +vgopts: -q --error-markers=,]]] diff --git a/memcheck/tests/manuel3.vgtest b/memcheck/tests/manuel3.vgtest index 14e5f24f34..c785435991 100644 --- a/memcheck/tests/manuel3.vgtest +++ b/memcheck/tests/manuel3.vgtest @@ -1,2 +1,2 @@ prog: manuel3 -vgopts: -q +vgopts: -q --error-markers=, diff --git a/none/tests/cmdline1.stdout.exp b/none/tests/cmdline1.stdout.exp index 3837816ccb..8367d4ebba 100644 --- a/none/tests/cmdline1.stdout.exp +++ b/none/tests/cmdline1.stdout.exp @@ -40,6 +40,8 @@ usage: valgrind [options] prog-and-args --num-callers= show callers in stack traces [12] --error-limit=no|yes stop showing new errors if too many? [yes] --error-exitcode= exit code to return if errors found [0=disable] + --error-markers=, add lines with begin/end markers before/after + each error output in plain text mode [none] --show-below-main=no|yes continue stack traces below main() [no] --default-suppressions=yes|no load default suppressions [yes] diff --git a/none/tests/cmdline2.stdout.exp b/none/tests/cmdline2.stdout.exp index 72b25066c0..bccb28d961 100644 --- a/none/tests/cmdline2.stdout.exp +++ b/none/tests/cmdline2.stdout.exp @@ -40,6 +40,8 @@ usage: valgrind [options] prog-and-args --num-callers= show callers in stack traces [12] --error-limit=no|yes stop showing new errors if too many? [yes] --error-exitcode= exit code to return if errors found [0=disable] + --error-markers=, add lines with begin/end markers before/after + each error output in plain text mode [none] --show-below-main=no|yes continue stack traces below main() [no] --default-suppressions=yes|no load default suppressions [yes] -- 2.47.2