From: Bart Van Assche Date: Tue, 31 Aug 2010 15:18:32 +0000 (+0000) Subject: Added command-line option --prefix-to-strip=... Closes #245535. X-Git-Tag: svn/VALGRIND_3_6_0~145 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=35eece7dd560554363cba29114825b889b896826;p=thirdparty%2Fvalgrind.git Added command-line option --prefix-to-strip=... Closes #245535. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11312 --- diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index 08babd0e43..25f5615e7f 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -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); diff --git a/coregrind/m_main.c b/coregrind/m_main.c index db74fd0e93..340af095d6 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -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= If not empty, specifies that full source file\n" +" paths must be printed in call stacks and also\n" " that 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)) {} diff --git a/coregrind/m_options.c b/coregrind/m_options.c index 90672c1c33..8438cae7f5 100644 --- a/coregrind/m_options.c +++ b/coregrind/m_options.c @@ -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; diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h index 24125bc89c..d737cdfd0b 100644 --- a/coregrind/pub_core_options.h +++ b/coregrind/pub_core_options.h @@ -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. diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml index 8a75292d36..4c2ed15a08 100644 --- a/docs/xml/manual-core.xml +++ b/docs/xml/manual-core.xml @@ -997,6 +997,20 @@ that can report errors, e.g. Memcheck, but not Cachegrind. + + + + + + By default Valgrind only shows the filename in stack traces and + not the full path of the source file. When using + , 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. + + + + diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index c8914762bb..3ad021092c 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -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 index 0000000000..ca3ecf55e3 --- /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 0000000000..97283abe00 --- /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 c06b53fd32..9ce72c05f3 100644 --- a/none/tests/cmdline1.stdout.exp +++ b/none/tests/cmdline1.stdout.exp @@ -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= If not empty, specifies that full source file + paths must be printed in call stacks and also + that 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 caa7eb0689..9ab2d126c8 100644 --- a/none/tests/cmdline2.stdout.exp +++ b/none/tests/cmdline2.stdout.exp @@ -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= If not empty, specifies that full source file + paths must be printed in call stacks and also + that 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]