Implement Option --error-markers=<begin>,<end>

* 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
This commit is contained in:
Philippe Waroquiers 2014-11-12 19:43:29 +00:00
parent 73df75ebba
commit 77f136cef4
16 changed files with 75 additions and 4 deletions

5
NEWS
View File

@ -14,6 +14,11 @@ Release 3.11.0 is under development, not yet released.
* ==================== OTHER CHANGES ====================
* Option --error-markers=<begin>,<end> 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"

View File

@ -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);
}

View File

@ -127,6 +127,8 @@ static void usage_NORETURN ( Bool debug_help )
" --num-callers=<number> show <number> callers in stack traces [12]\n"
" --error-limit=no|yes stop showing new errors if too many? [yes]\n"
" --error-exitcode=<number> exit code to return if errors found [0=disable]\n"
" --error-markers=<begin>,<end> 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)) {}

View File

@ -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) \

View File

@ -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.

View File

@ -1160,6 +1160,23 @@ that can report errors, e.g. Memcheck, but not Cachegrind.</para>
</listitem>
</varlistentry>
<varlistentry id="opt.error-markers" xreflabel="--error-markers">
<term>
<option><![CDATA[--error-markers=<begin>,<end> [default: none]]]></option>
</term>
<listitem>
<para>When errors are output as plain text (i.e. XML not used),
<option>--error-markers</option> instructs to output a line
containing the <option>begin</option> (<option>end</option>)
string before (after) each error. </para>
<para> Such marker lines facilitate searching for errors and/or
extracting errors in an output file that contain valgrind errors mixed
with the program output. </para>
<para> Note that empty markers are accepted. So, only using a begin
(or an end) marker is possible.</para>
</listitem>
</varlistentry>
<varlistentry id="opt.sigill-diagnostics" xreflabel="--sigill-diagnostics">
<term>
<option><![CDATA[--sigill-diagnostics=<yes|no> [default: yes] ]]></option>

View File

@ -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)
]]]

View File

@ -1,2 +1,2 @@
prog: badaddrvalue
vgopts: -q
vgopts: -q --error-markers=[[[,]]]

View File

@ -1,3 +1,4 @@
[[[
Conditional jump or move depends on uninitialised value(s)
at 0x........: main (manuel1.c:7)

View File

@ -1,2 +1,2 @@
prog: manuel1
vgopts: -q
vgopts: -q --error-markers=[[[

View File

@ -1,3 +1,4 @@
Use of uninitialised value of size 4
at 0x........: main (manuel2.c:10)
]]]

View File

@ -1,3 +1,4 @@
Use of uninitialised value of size 8
at 0x........: main (manuel2.c:10)
]]]

View File

@ -1,2 +1,2 @@
prog: manuel2
vgopts: -q
vgopts: -q --error-markers=,]]]

View File

@ -1,2 +1,2 @@
prog: manuel3
vgopts: -q
vgopts: -q --error-markers=,

View File

@ -40,6 +40,8 @@ usage: valgrind [options] prog-and-args
--num-callers=<number> show <number> callers in stack traces [12]
--error-limit=no|yes stop showing new errors if too many? [yes]
--error-exitcode=<number> exit code to return if errors found [0=disable]
--error-markers=<begin>,<end> 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]

View File

@ -40,6 +40,8 @@ usage: valgrind [options] prog-and-args
--num-callers=<number> show <number> callers in stack traces [12]
--error-limit=no|yes stop showing new errors if too many? [yes]
--error-exitcode=<number> exit code to return if errors found [0=disable]
--error-markers=<begin>,<end> 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]