Added command-line option --prefix-to-strip=... Closes #245535.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11312 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c
index 08babd0..25f5615 100644
--- a/coregrind/m_debuginfo/debuginfo.c
+++ b/coregrind/m_debuginfo/debuginfo.c
@@ -1854,7 +1854,21 @@
APPEND("???");
}
if (know_srcloc) {
+ const Char* const pfx = VG_(clo_prefix_to_strip);
APPEND(" (");
+ if (pfx) {
+ const int pfxlen = VG_(strlen)(pfx);
+ const int matchlen = VG_(strncmp)(pfx, buf_dirname, pfxlen) == 0
+ ? pfxlen : 0;
+ if (matchlen && buf_dirname[matchlen] == '/'
+ && buf_dirname[matchlen + 1]) {
+ APPEND(buf_dirname + matchlen + 1);
+ APPEND("/");
+ } else if (buf_dirname[matchlen]) {
+ APPEND(buf_dirname + matchlen);
+ APPEND("/");
+ }
+ }
APPEND(buf_srcloc);
APPEND(":");
VG_(sprintf)(ibuf,"%d",lineno);
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index db74fd0..340af09 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -163,6 +163,9 @@
" and use it to print better error messages in\n"
" tools that make use of it (Memcheck, Helgrind,\n"
" DRD) [no]\n"
+" --prefix-to-strip=<pfx> If not empty, specifies that full source file\n"
+" paths must be printed in call stacks and also\n" " that <pfx> must be stripped from these paths.\n"
+" [""].\n"
" --run-libc-freeres=no|yes free up glibc memory at exit on Linux? [yes]\n"
" --sim-hints=hint1,hint2,... known hints:\n"
" lax-ioctls, enable-outer [none]\n"
@@ -479,6 +482,13 @@
else if VG_STR_CLO (arg, "--sim-hints", VG_(clo_sim_hints)) {}
else if VG_BOOL_CLO(arg, "--sym-offsets", VG_(clo_sym_offsets)) {}
else if VG_BOOL_CLO(arg, "--read-var-info", VG_(clo_read_var_info)) {}
+ else if VG_STR_CLO (arg, "--prefix-to-strip", VG_(clo_prefix_to_strip)) {
+ Char *const pfx = VG_(clo_prefix_to_strip);
+ Char *const pfx_end = pfx + VG_(strlen)(pfx);
+ Char *const last_slash = VG_(strrchr)(pfx, '/');
+ if (last_slash == pfx_end - 1)
+ *last_slash = '\0';
+ }
else if VG_INT_CLO (arg, "--dump-error", VG_(clo_dump_error)) {}
else if VG_INT_CLO (arg, "--input-fd", VG_(clo_input_fd)) {}
diff --git a/coregrind/m_options.c b/coregrind/m_options.c
index 90672c1..8438cae 100644
--- a/coregrind/m_options.c
+++ b/coregrind/m_options.c
@@ -83,6 +83,7 @@
Char* VG_(clo_sim_hints) = NULL;
Bool VG_(clo_sym_offsets) = False;
Bool VG_(clo_read_var_info) = False;
+Char* VG_(clo_prefix_to_strip) = NULL;
Int VG_(clo_n_req_tsyms) = 0;
HChar* VG_(clo_req_tsyms)[VG_CLO_MAX_REQ_TSYMS];
HChar* VG_(clo_require_text_symbol) = NULL;
diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h
index 24125bc..d737cdf 100644
--- a/coregrind/pub_core_options.h
+++ b/coregrind/pub_core_options.h
@@ -128,6 +128,8 @@
extern Bool VG_(clo_sym_offsets);
/* Read DWARF3 variable info even if tool doesn't ask for it? */
extern Bool VG_(clo_read_var_info);
+/* Which prefix to strip from full source file paths, if any. */
+extern Char* VG_(clo_prefix_to_strip);
/* An array of strings harvested from --require-text-symbol=
flags.
diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml
index 8a75292..4c2ed15 100644
--- a/docs/xml/manual-core.xml
+++ b/docs/xml/manual-core.xml
@@ -997,6 +997,20 @@
</listitem>
</varlistentry>
+ <varlistentry id="opt.prefix-to-strip" xreflabel="--prefix-to-strip">
+ <term>
+ <option><![CDATA[--prefix-to-strip=<prefix> [default: off] ]]></option>
+ </term>
+ <listitem>
+ <para>By default Valgrind only shows the filename in stack traces and
+ not the full path of the source file. When using
+ <option>--prefix-to-strip</option>, Valgrind will include the full
+ path of source files in stack traces. If a path starts with the
+ specified prefix, the prefix will be left out from the printed path.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="opt.suppressions" xreflabel="--suppressions">
<term>
<option><![CDATA[--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] ]]></option>
diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am
index c891476..3ad0210 100644
--- a/memcheck/tests/Makefile.am
+++ b/memcheck/tests/Makefile.am
@@ -46,6 +46,7 @@
badaddrvalue.stdout.exp badaddrvalue.vgtest \
badfree-2trace.stderr.exp badfree-2trace.vgtest \
badfree.stderr.exp badfree.vgtest \
+ badfree3.stderr.exp badfree3.vgtest \
badjump.stderr.exp badjump.vgtest \
badjump2.stderr.exp badjump2.vgtest \
badloop.stderr.exp badloop.vgtest \
diff --git a/memcheck/tests/badfree3.stderr.exp b/memcheck/tests/badfree3.stderr.exp
new file mode 100644
index 0000000..ca3ecf5
--- /dev/null
+++ b/memcheck/tests/badfree3.stderr.exp
@@ -0,0 +1,10 @@
+Invalid free() / delete / delete[]
+ at 0x........: free (coregrind/vg_replace_malloc.c:...)
+ by 0x........: main (memcheck/tests/badfree.c:12)
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
+Invalid free() / delete / delete[]
+ at 0x........: free (coregrind/vg_replace_malloc.c:...)
+ by 0x........: main (memcheck/tests/badfree.c:15)
+ Address 0x........ is on thread 1's stack
+
diff --git a/memcheck/tests/badfree3.vgtest b/memcheck/tests/badfree3.vgtest
new file mode 100644
index 0000000..97283ab
--- /dev/null
+++ b/memcheck/tests/badfree3.vgtest
@@ -0,0 +1,2 @@
+prog: badfree
+vgopts: -q --prefix-to-strip=${PWD}
diff --git a/none/tests/cmdline1.stdout.exp b/none/tests/cmdline1.stdout.exp
index c06b53f..9ce72c0 100644
--- a/none/tests/cmdline1.stdout.exp
+++ b/none/tests/cmdline1.stdout.exp
@@ -51,6 +51,10 @@
and use it to print better error messages in
tools that make use of it (Memcheck, Helgrind,
DRD) [no]
+ --prefix-to-strip=<pfx> If not empty, specifies that full source file
+ paths must be printed in call stacks and also
+ that <pfx> must be stripped from these paths.
+ [].
--run-libc-freeres=no|yes free up glibc memory at exit on Linux? [yes]
--sim-hints=hint1,hint2,... known hints:
lax-ioctls, enable-outer [none]
diff --git a/none/tests/cmdline2.stdout.exp b/none/tests/cmdline2.stdout.exp
index caa7eb0..9ab2d12 100644
--- a/none/tests/cmdline2.stdout.exp
+++ b/none/tests/cmdline2.stdout.exp
@@ -51,6 +51,10 @@
and use it to print better error messages in
tools that make use of it (Memcheck, Helgrind,
DRD) [no]
+ --prefix-to-strip=<pfx> If not empty, specifies that full source file
+ paths must be printed in call stacks and also
+ that <pfx> must be stripped from these paths.
+ [].
--run-libc-freeres=no|yes free up glibc memory at exit on Linux? [yes]
--sim-hints=hint1,hint2,... known hints:
lax-ioctls, enable-outer [none]