]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added command-line option --prefix-to-strip=... Closes #245535.
authorBart Van Assche <bvanassche@acm.org>
Tue, 31 Aug 2010 15:18:32 +0000 (15:18 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 31 Aug 2010 15:18:32 +0000 (15:18 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11312

coregrind/m_debuginfo/debuginfo.c
coregrind/m_main.c
coregrind/m_options.c
coregrind/pub_core_options.h
docs/xml/manual-core.xml
memcheck/tests/Makefile.am
memcheck/tests/badfree3.stderr.exp [new file with mode: 0644]
memcheck/tests/badfree3.vgtest [new file with mode: 0644]
none/tests/cmdline1.stdout.exp
none/tests/cmdline2.stdout.exp

index 08babd0e4382c66dda3c3c3a2565232ffa62de06..25f5615e7f56b68704f07d970c465d49d0122561 100644 (file)
@@ -1854,7 +1854,21 @@ Char* VG_(describe_IP)(Addr eip, Char* buf, Int n_buf)
          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);
index db74fd0e938129ef089d519ae8a580192b79adc2..340af095d6e00cd21790fd9a2141235194be2533 100644 (file)
@@ -163,6 +163,9 @@ static void usage_NORETURN ( Bool debug_help )
 "                              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 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd,
       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))     {}
index 90672c1c33e1a8d723e20274dd656506e30c5f72..8438cae7f5018841c255c0567545741eefb477ab 100644 (file)
@@ -83,6 +83,7 @@ Int    VG_(clo_backtrace_size) = 12;
 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;
index 24125bc89c705a3e525ac6f494a107a8b6b6e0ab..d737cdfd0b67a94f63983afd6a03e98ad7198578 100644 (file)
@@ -128,6 +128,8 @@ extern Char* VG_(clo_sim_hints);
 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.
index 8a75292d369d00b730b522ae3d3e03b0dc2bcee7..4c2ed15a080c9a3d91a6ec59becc6f649e53cab7 100644 (file)
@@ -997,6 +997,20 @@ that can report errors, e.g. Memcheck, but not Cachegrind.</para>
     </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>
index c8914762bb63e8e27a0d162d971703d24d58c385..3ad021092c30a8e5150d7a5c26c04370b3723066 100644 (file)
@@ -46,6 +46,7 @@ EXTRA_DIST = \
        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 (file)
index 0000000..ca3ecf5
--- /dev/null
@@ -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 (file)
index 0000000..97283ab
--- /dev/null
@@ -0,0 +1,2 @@
+prog: badfree
+vgopts: -q --prefix-to-strip=${PWD}
index c06b53fd3264d914ba3c70c7b564eed237967af9..9ce72c05f3ac59c2fbd27a0d59a6370d2dc95c11 100644 (file)
@@ -51,6 +51,10 @@ usage: valgrind [options] prog-and-args
                               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]
index caa7eb0689a3c2c1752b643837a8fc0aa12f8aaa..9ab2d126c8e402a42a7bbc33315e694309835a6f 100644 (file)
@@ -51,6 +51,10 @@ usage: valgrind [options] prog-and-args
                               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]