aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2007-11-23 01:41:32 +0000
committernjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2007-11-23 01:41:32 +0000
commit374a36dbfb6d08ed8d77c31a88e198a861ffadf0 (patch)
tree70b56afcf1a57ad8cafb5e769e7354342f4fe847
parentf36ae99840c45960187073d140934e45daa6b066 (diff)
downloadvalgrind-374a36dbfb6d08ed8d77c31a88e198a861ffadf0.tar.gz
Fixed up the log file mess throughout, including the docs. This killed
--log-file-qualifier and --log-file-exactly. Updated NEWS some in preparation for 3.3.0. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7202 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r--NEWS64
-rw-r--r--cachegrind/cg_annotate.in44
-rw-r--r--cachegrind/cg_main.c62
-rw-r--r--cachegrind/docs/cg-manual.xml140
-rw-r--r--coregrind/m_main.c110
-rw-r--r--coregrind/m_options.c111
-rw-r--r--coregrind/pub_core_options.h16
-rw-r--r--docs/internals/xml-output.txt2
-rw-r--r--docs/xml/manual-core.xml90
-rw-r--r--include/pub_tool_options.h15
-rw-r--r--massif/ms_main.c127
-rw-r--r--none/tests/cmdline1.stdout.exp7
-rw-r--r--none/tests/cmdline2.stdout.exp7
13 files changed, 321 insertions, 474 deletions
diff --git a/NEWS b/NEWS
index ddf6945b3..7374d8579 100644
--- a/NEWS
+++ b/NEWS
@@ -4,13 +4,67 @@ Release 3.3.0 (XX XXX 2007)
XXX: AIX support (ppc32 and ppc64?)
-Other user-visible changes:
+Several large improvements to existing tools have been implemented.
+
+- Helgrind has been completely overhauled and now works for the first time
+ since Valgrind 2.2.0. [XXX: ...]
+
+- Massif has been completely overhauled. Instead of measuring space-time
+ usage -- which wasn't always useful and many people found confusing -- it
+ now measures space usage at various points in the execution, including the
+ point of peak memory allocation. Its output format has also changed:
+ instead of producing PostScript graphs and HTML text, it produces a single
+ text output (via the new 'ms_print' script) that contains both a graph and
+ the old textual information, but in a more compact and readable form.
+ Finally, the new version should be more reliable than the old one, as it
+ has been tested more thoroughly.
- Cachegrind has been extended to do branch-misprediction profiling.
Both conditional and indirect branches are profiled. The default
behaviour of Cachegrind is unchanged. To use the new functionality,
give the option --branch-sim=yes.
+Two new tools have also been added. These are "experimental tools", which
+means that they may not work as well as the standard tools, but they are
+included because some people will find them useful. The notion of
+experimental tools was added in order to provide a way for tools to get
+wider exposure among Valgrind users. These tools have a "exp-" prefix
+attached to their names to indicate their experimental nature.
+
+- exp-Omega [XXX ...]
+
+- exp-DRD [XXX ...]
+
+Other user-visible changes:
+
+- The --log-file-exactly and --log-file-qualifier options have been removed.
+ To make up for this --log-file option has been made more powerful and
+ flexible; it can now accept a %p format specifier, which is replaced with
+ the process ID, and the a %q{FOO} format specifier, which is replaced with
+ the contents of the environment variable $FOO.
+
+- [XXX: --child-silent-after-fork...]
+
+- There are new --cachegrind-out-file, --callgrind-out-file and
+ --massif-out-file options, which control the names of the output files
+ produced by Cachegrind, Callgrind and Massif. They accept the same %p and
+ %q format specifiers that --log-file accepts.
+
+- Cachegrind's 'cg_annotate' script no longer uses the --<pid> option to
+ specify the output file. Instead, the first non-option argument is taken
+ to be the name of the output file, and any subsequent non-option arguments
+ are taken to be the names of source files to be annotated. This change
+ was necessary due to the addition of the --cachegrind-out-file option.
+ 'callgrind_annotate' already had this behaviour.
+
+- Cachegrind now uses directory names where possible in its output files.
+ This means that the -I option to 'cg_annotate' should not be needed in
+ most cases. It also means it can correctly handle the case where two
+ source files in different directories have the same name.
+ The same is true for Callgrind and callgrind_annotate, respectively.
+ The benefits also apply to KCachegrind, without any further change
+ (ie. in most cases there is no configuration of source directories needed).
+
- A new suppression kind has been introduced: "Jump". This is for
suppressing jump-to-invalid-address errors. Previously you had to use an
"Addr1" suppression, which didn't make much sense.
@@ -26,14 +80,6 @@ Other user-visible changes:
traces. Second, a new option --trace-superblocks has been added, which
shows the addresses of superblocks (code blocks) as they are executed.
-- Cachegrind now uses directory names where possible in its output files.
- This means that the -I option to 'cg_annotate' should not be needed in
- most cases. It also means it can correctly handle the case where two
- source files in different directories have the same name.
- The same is true for Callgrind and callgrind_annotate, respectively.
- The benefits also apply to KCachegrind, without any further change
- (ie. in most cases there is no configuration of source directories needed).
-
Developer-visible changes:
- New debugging command line options: --debug-dump, --trace-symtab-patt...
diff --git a/cachegrind/cg_annotate.in b/cachegrind/cg_annotate.in
index cb7e17e7a..31e95069b 100644
--- a/cachegrind/cg_annotate.in
+++ b/cachegrind/cg_annotate.in
@@ -142,13 +142,11 @@ my $version = "@VERSION@";
# Usage message.
my $usage = <<END
-usage: cg_annotate [options] [source-files]
+usage: cg_annotate [options] output-file [source-files]
options for the user, with defaults in [ ], are:
-h --help show this message
-v --version show version
- --<pid> read profile data from cachegrind.out.<pid>
- --cachegrind-out-file=<file> read profile data from <file>
--show=A,B,C only show figures for events A,B,C [all]
--sort=A,B,C sort columns by events A,B,C [event column order]
--threshold=<0--100> percentage of counts (of primary sort event) we
@@ -160,9 +158,6 @@ usage: cg_annotate [options] [source-files]
-I<d> --include=<d> add <d> to list of directories to search for
source files
- You must use either --<pid> or --cachegrind-out-file exactly once
- in order that cg_annotate knows what file to read profile data from.
-
cg_annotate is Copyright (C) 2002-2007 Nicholas Nethercote.
and licensed under the GNU General Public License, version 2.
Bug reports, feedback, admiration, abuse, etc, to: njn\@valgrind.org.
@@ -241,25 +236,6 @@ sub process_cmd_line()
$inc =~ s|/$||; # trim trailing '/'
push(@include_dirs, "$inc/");
- # --cachegrind-out-file=<filename>
- } elsif ($arg =~ /^--cachegrind-out-file=(.*)$/) {
- if (not defined $input_file) {
- $input_file = $1;
- } else {
- die("You may only specify one input file\n" .
- "using the --<pid> and --cachegrind-out-file options.\n");
- }
-
- # --<pid>
- } elsif ($arg =~ /^--(\d+)$/) {
- my $pid = $1;
- if (not defined $input_file) {
- $input_file = "cachegrind.out.$pid";
- } else {
- die("You may only specify one input file\n" .
- "using the --<pid> and --cachegrind-out-file options.\n");
- }
-
} else { # -h and --help fall under this case
die($usage);
}
@@ -267,14 +243,20 @@ sub process_cmd_line()
# Argument handling -- annotation file checking and selection.
# Stick filenames into a hash for quick 'n easy lookup throughout.
} else {
- my $readable = 0;
- foreach my $include_dir (@include_dirs) {
- if (-r $include_dir . $arg) {
- $readable = 1;
+ if (not defined $input_file) {
+ # First non-option argument is the output file.
+ $input_file = $arg;
+ } else {
+ # Subsequent non-option arguments are source files.
+ my $readable = 0;
+ foreach my $include_dir (@include_dirs) {
+ if (-r $include_dir . $arg) {
+ $readable = 1;
+ }
}
+ $readable or die("File $arg not found in any of: @include_dirs\n");
+ $user_ann_files{$arg} = 1;
}
- $readable or die("File $arg not found in any of: @include_dirs\n");
- $user_ann_files{$arg} = 1;
}
}
diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c
index d8627fb86..9fae9de57 100644
--- a/cachegrind/cg_main.c
+++ b/cachegrind/cg_main.c
@@ -65,8 +65,9 @@
/*--- Options ---*/
/*------------------------------------------------------------*/
-static Bool clo_cache_sim = True; /* do cache simulation? */
-static Bool clo_branch_sim = False; /* do branch simulation? */
+static Bool clo_cache_sim = True; /* do cache simulation? */
+static Bool clo_branch_sim = False; /* do branch simulation? */
+static Char* clo_cachegrind_out_file = "cachegrind.out.%p";
/*------------------------------------------------------------*/
/*--- Types and Data Structures ---*/
@@ -1255,17 +1256,9 @@ static CacheCC Dw_total;
static BranchCC Bc_total;
static BranchCC Bi_total;
-// The output file base name specified by the user using the
-// --cachegrind-out-file switch. This is combined with the
-// process ID and optional user-supplied qualifier (from
-// --log-file-qualifier) to produce the name stored in
-// cachegrind_out_file.
-static Char* cachegrind_out_file_basename = "cachegrind.out";
-
-// The final, completed name for the output file.
+// The output file name. Controlled by --cachegrind-out-file.
static Char* cachegrind_out_file = NULL;
-
static void fprint_CC_table_and_calc_totals(void)
{
Int i, fd;
@@ -1691,7 +1684,7 @@ static Bool cg_process_cmd_line_option(Char* arg)
else if (VG_CLO_STREQN(5, arg, "--L2="))
parse_cache_opt(&clo_L2_cache, &arg[5]);
else if (VG_CLO_STREQN(22, arg, "--cachegrind-out-file=")) {
- cachegrind_out_file_basename = &arg[22];
+ clo_cachegrind_out_file = &arg[22];
}
else VG_BOOL_CLO(arg, "--cache-sim", clo_cache_sim)
else VG_BOOL_CLO(arg, "--branch-sim", clo_branch_sim)
@@ -1709,8 +1702,7 @@ static void cg_print_usage(void)
" --L2=<size>,<assoc>,<line_size> set L2 cache manually\n"
" --cache-sim=yes|no [yes] collect cache stats?\n"
" --branch-sim=yes|no [no] collect branch prediction stats?\n"
-" --cachegrind-out-file=<file> write profile data to <file>.<pid>\n"
-" [cachegrind.out.<pid>]\n"
+" --cachegrind-out-file=<file> output file name [cachegrind.out.%%p]\n"
);
}
@@ -1725,8 +1717,6 @@ static void cg_print_debug_usage(void)
/*--- Setup ---*/
/*--------------------------------------------------------------------*/
-static Char base_dir[VKI_PATH_MAX];
-
static void cg_post_clo_init(void); /* just below */
static void cg_pre_clo_init(void)
@@ -1751,9 +1741,7 @@ static void cg_pre_clo_init(void)
static void cg_post_clo_init(void)
{
- HChar* qual = NULL;
cache_t I1c, D1c, L2c;
- Int filename_szB;
/* Can't disable both cache and branch profiling */
if ((!clo_cache_sim) && (!clo_branch_sim)) {
@@ -1764,41 +1752,9 @@ static void cg_post_clo_init(void)
VG_(exit)(2);
}
- /* Get working directory */
- tl_assert( VG_(get_startup_wd)(base_dir, VKI_PATH_MAX) );
-
- /* Do we have a --log-file-qualifier= to consider? */
- if (VG_(clo_log_file_qualifier)) {
- qual = VG_(getenv)(VG_(clo_log_file_qualifier));
- }
-
- /* Block is big enough for
- dir name ++ cachegrind_out_file_basename
- ++ ".<pid>"
- ++ the log file qualifier, if in use */
- filename_szB
- = VG_(strlen)(base_dir)
- + 1 /* "/" */
- + VG_(strlen)(cachegrind_out_file_basename)
- + 11 /* "." <pid>, assuming sizeof(pid) <= 4 */
- + (qual ? (10 + VG_(strlen)(qual)) : 0)
- + 1; /* to guarantee checkable zero at the end */
-
- tl_assert(filename_szB > 0);
- cachegrind_out_file
- = VG_(calloc)( sizeof(Char), filename_szB );
-
- if (qual) {
- VG_(sprintf)(cachegrind_out_file, "%s/%s.%d.lfq.%s",
- base_dir, cachegrind_out_file_basename,
- VG_(getpid)(), qual);
- } else {
- VG_(sprintf)(cachegrind_out_file, "%s/%s.%d",
- base_dir, cachegrind_out_file_basename,
- VG_(getpid)());
- }
-
- tl_assert( cachegrind_out_file[filename_szB-1] == 0 );
+ // Setup output filename.
+ cachegrind_out_file =
+ VG_(expand_file_name)("--cachegrind-out-file", clo_cachegrind_out_file);
CC_table =
VG_(OSetGen_Create)(offsetof(LineCC, loc),
diff --git a/cachegrind/docs/cg-manual.xml b/cachegrind/docs/cg-manual.xml
index 59b70e1d8..30857fa9f 100644
--- a/cachegrind/docs/cg-manual.xml
+++ b/cachegrind/docs/cg-manual.xml
@@ -78,9 +78,9 @@ be normally run.</para>
command line invocation. When the program finishes,
Cachegrind will print summary cache statistics. It also
collects line-by-line information in a file
- <computeroutput>cachegrind.out.pid</computeroutput>, where
- <computeroutput>pid</computeroutput> is the program's process
- id.</para>
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput>, where
+ <computeroutput>&lt;pid&gt;</computeroutput> is the program's process
+ ID.</para>
<para>Branch prediction statistics are not collected by default.
To do so, add the flag
@@ -95,7 +95,7 @@ be normally run.</para>
<listitem>
<para>Generate a function-by-function summary, and possibly
annotate source files, using the supplied
- <computeroutput>cg_annotate</computeroutput> program. Source
+ cg_annotate program. Source
files to annotate can be specified manually, or manually on
the command line, or "interesting" source files can be
annotated automatically with the
@@ -111,10 +111,9 @@ be normally run.</para>
</orderedlist>
<para>As an optional intermediate step, you can use the supplied
-<computeroutput>cg_merge</computeroutput> program to sum together the
+cg_merge program to sum together the
outputs of multiple Cachegrind runs, into a single file which you then
-use as the input for
-<computeroutput>cg_annotate</computeroutput>.</para>
+use as the input for cg_annotate.</para>
<para>These steps are described in detail in the following
sections.</para>
@@ -336,46 +335,38 @@ follow that.</para>
<para>As well as printing summary information, Cachegrind also
writes line-by-line cache profiling information to a user-specified
file. By default this file is named
-<computeroutput>cachegrind.out.pid</computeroutput>. This file
+<computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput>. This file
is human-readable, but is intended to be interpreted by the accompanying
-program <computeroutput>cg_annotate</computeroutput>, described
-in the next section.</para>
+program cg_annotate, described in the next section.</para>
<para>Things to note about the
-<computeroutput>cachegrind.out.pid</computeroutput>
+<computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput>
file:</para>
<itemizedlist>
<listitem>
<para>It is written every time Cachegrind is run, and will
overwrite any existing
- <computeroutput>cachegrind.out.pid</computeroutput>
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput>
in the current directory (but that won't happen very often
because it takes some time for process ids to be
recycled).</para>
- <para>
- To use a basename other than the default
+ </listitem>
+ <listitem>
+ <para>To use an output file name other than the default
<computeroutput>cachegrind.out</computeroutput>,
use the <computeroutput>--cachegrind-out-file</computeroutput>
switch.</para>
- <para>
- To add further qualifiers to the output filename you can use
- the core's <computeroutput>--log-file-qualifier</computeroutput>
- flag. This extends the file name further with the text
- <computeroutput>.lfq.</computeroutput>followed by the
- contents of the environment variable specified by
- <computeroutput>--log-file-qualifier</computeroutput>.
- </para>
</listitem>
<listitem>
- <para>It can be huge: <computeroutput>ls -l</computeroutput>
+ <para>It can be big: <computeroutput>ls -l</computeroutput>
generates a file of about 350KB. Browsing a few files and
web pages with a Konqueror built with full debugging
information generates a file of around 15 MB.</para>
</listitem>
</itemizedlist>
-<para>The <computeroutput>.pid</computeroutput> suffix
+<para>The default <computeroutput>.&lt;pid&gt;</computeroutput> suffix
on the output file name serves two purposes. Firstly, it means you
don't have to rename old log files that you don't want to overwrite.
Secondly, and more importantly, it allows correct profiling with the
@@ -439,13 +430,18 @@ configuration, or failing that, via defaults).</para>
<varlistentry id="opt.cachegrind-out-file" xreflabel="--cachegrind-out-file">
<term>
- <option><![CDATA[--cachegrind-out-file=<basename> ]]></option>
+ <option><![CDATA[--cachegrind-out-file=<file> ]]></option>
</term>
<listitem>
<para>Write the profile data to
- <computeroutput>basename.pid</computeroutput>
- rather than to the default output file,
- <computeroutput>cachegrind.out.pid</computeroutput>.
+ <computeroutput>file</computeroutput> rather than to the default
+ output file,
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput>. The
+ <option>%p</option> and <option>%q</option> format specifiers
+ can be used to embed the process ID and/or the contents of an
+ environment variable in the name, as is the case for the core
+ option <option>--log-file</option>. See <link
+ linkend="manual-core.basicopts">here</link> for details.
</para>
</listitem>
</varlistentry>
@@ -485,16 +481,12 @@ configuration, or failing that, via defaults).</para>
<sect2 id="cg-manual.annotate" xreflabel="Annotating C/C++ programs">
<title>Annotating C/C++ programs</title>
-<para>Before using <computeroutput>cg_annotate</computeroutput>,
+<para>Before using cg_annotate,
it is worth widening your window to be at least 120-characters
wide if possible, as the output lines can be quite long.</para>
-<para>To get a function-by-function summary, run
-<computeroutput>cg_annotate --pid</computeroutput> in a directory
-containing a <filename>cachegrind.out.pid</filename> file. The
-<emphasis>--pid</emphasis> is required so that
-<computeroutput>cg_annotate</computeroutput> knows which log file to use
-when several are present.</para>
+<para>To get a function-by-function summary, run <computeroutput>cg_annotate
+&lt;filename&gt;</computeroutput> on a Cachegrind output file.</para>
<para>The output looks like this:</para>
@@ -643,7 +635,7 @@ Ir I1mr I2mr Dr D1mr D2mr Dw D1mw D2mw file:function
</listitem>
<listitem>
- <para>Threshold: <computeroutput>cg_annotate</computeroutput>
+ <para>Threshold: cg_annotate
by default omits functions that cause very low counts
to avoid drowning you in information. In this case,
cg_annotate shows summaries the functions that account for
@@ -696,12 +688,12 @@ and from libraries (eg. <filename>getc.c</filename>)</para>
<para>There are two ways to annotate source files -- by choosing
them manually, or with the
<computeroutput>--auto=yes</computeroutput> option. To do it
-manually, just specify the filenames as arguments to
-<computeroutput>cg_annotate</computeroutput>. For example, the
-output from running <filename>cg_annotate concord.c</filename>
-for our example produces the same output as above followed by an
-annotated version of <filename>concord.c</filename>, a section of
-which looks like:</para>
+manually, just specify the filenames as additional arguments to
+cg_annotate. For example, the
+output from running <filename>cg_annotate &lt;filename&gt;
+concord.c</filename> for our example produces the same output as above
+followed by an annotated version of <filename>concord.c</filename>, a
+section of which looks like:</para>
<programlisting><![CDATA[
--------------------------------------------------------------------------------
@@ -768,7 +760,7 @@ controlled by the <computeroutput>--context</computeroutput>
option.</para>
<para>To get automatic annotation, run
-<computeroutput>cg_annotate --auto=yes</computeroutput>.
+<computeroutput>cg_annotate &lt;filename&gt; --auto=yes</computeroutput>.
cg_annotate will automatically annotate every source file it can
find that is mentioned in the function-by-function summary.
Therefore, the files chosen for auto-annotation are affected by
@@ -798,7 +790,7 @@ for source files if the filenames found from the debugging
information aren't specific enough.</para>
<para>Beware that cg_annotate can take some time to digest large
-<computeroutput>cachegrind.out.pid</computeroutput> files,
+<computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput> files,
e.g. 30 seconds or more. Also beware that auto-annotation can
produce a lot of output if your program is large!</para>
@@ -806,10 +798,10 @@ produce a lot of output if your program is large!</para>
<sect2 id="cg-manual.assembler" xreflabel="Annotating assembler programs">
-<title>Annotating assembler programs</title>
+<title>Annotating assembly code programs</title>
-<para>Valgrind can annotate assembler programs too, or annotate
-the assembler generated for your C program. Sometimes this is
+<para>Valgrind can annotate assembly code programs too, or annotate
+the assembly code generated for your C program. Sometimes this is
useful for understanding what is really happening when an
interesting line of C code is translated into multiple
instructions.</para>
@@ -832,34 +824,10 @@ way as for C/C++ programs.</para>
<sect1 id="cg-manual.annopts" xreflabel="cg_annotate options">
-<title><computeroutput>cg_annotate</computeroutput> options</title>
+<title>cg_annotate options</title>
<itemizedlist>
- <listitem id="pid">
- <para><computeroutput>--pid</computeroutput></para>
- <para>Indicates that profile data should be read from
- the file
- <computeroutput>cachegrind.out.pid</computeroutput>.
- read.
- Note that you must specify either
- <computeroutput>--pid</computeroutput>
- or <computeroutput>--cachegrind-out-file=filename</computeroutput>
- exactly once.
- </para>
- </listitem>
-
- <listitem id="cachegrind-out-file">
- <para><computeroutput>--cachegrind-out-file=filename</computeroutput></para>
- <para>Indicates that profile data
- should be read from <computeroutput>filename</computeroutput>.
- Note that you must specify either
- <computeroutput>--pid</computeroutput>
- or <computeroutput>--cachegrind-out-file=filename</computeroutput>
- exactly once.
- </para>
- </listitem>
-
<listitem>
<para><computeroutput>-h, --help</computeroutput></para>
<para><computeroutput>-v, --version</computeroutput></para>
@@ -869,7 +837,7 @@ way as for C/C++ programs.</para>
<listitem id="sort">
<para><computeroutput>--sort=A,B,C</computeroutput> [default:
order in
- <computeroutput>cachegrind.out.pid</computeroutput>]</para>
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput>]</para>
<para>Specifies the events upon which the sorting of the
function-by-function entries will be based. Useful if you
want to concentrate on eg. I cache misses
@@ -883,10 +851,10 @@ way as for C/C++ programs.</para>
<listitem id="show">
<para><computeroutput>--show=A,B,C</computeroutput> [default:
all, using order in
- <computeroutput>cachegrind.out.pid</computeroutput>]</para>
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput>]</para>
<para>Specifies which events to show (and the column
order). Default is to use all present in the
- <computeroutput>cachegrind.out.pid</computeroutput> file (and
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput> file (and
use the order in the file).</para>
</listitem>
@@ -941,15 +909,14 @@ way as for C/C++ programs.</para>
<title>Warnings</title>
<para>There are a couple of situations in which
-<computeroutput>cg_annotate</computeroutput> issues
-warnings.</para>
+cg_annotate issues warnings.</para>
<itemizedlist>
<listitem>
<para>If a source file is more recent than the
- <computeroutput>cachegrind.out.pid</computeroutput> file.
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput> file.
This is because the information in
- <computeroutput>cachegrind.out.pid</computeroutput> is only
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput> is only
recorded with line numbers, so if the line numbers change at
all in the source (eg. lines added, deleted, swapped), any
annotations will be incorrect.</para>
@@ -958,7 +925,7 @@ warnings.</para>
<para>If information is recorded about line numbers past the
end of a file. This can be caused by the above problem,
ie. shortening the source file while using an old
- <computeroutput>cachegrind.out.pid</computeroutput> file. If
+ <computeroutput>cachegrind.out.&lt;pid&gt;</computeroutput> file. If
this happens, the figures for the bogus lines are printed
anyway (clearly marked as bogus) in case they are
important.</para>
@@ -1167,22 +1134,21 @@ useful.</para>
<sect1 id="cg-manual.cg_merge" xreflabel="cg_merge">
-<title>Merging profiles with <computeroutput>cg_merge</computeroutput></title>
+<title>Merging profiles with cg_merge</title>
<para>
-<computeroutput>cg_merge</computeroutput> is a simple program which
+cg_merge is a simple program which
reads multiple profile files, as created by cachegrind, merges them
together, and writes the results into another file in the same format.
You can then examine the merged results using
-<computeroutput>cg_annotate
---cachegrind-out-file=outputfile</computeroutput>, as
+<computeroutput>cg_annotate &lt;filename&gt;</computeroutput>, as
described above. The merging functionality might be useful if you
want to aggregate costs over multiple runs of the same program, or
from a single parallel run with multiple instances of the same
program.</para>
<para>
-<computeroutput>cg_merge</computeroutput> is invoked as follows:
+cg_merge is invoked as follows:
</para>
<programlisting><![CDATA[
@@ -1203,7 +1169,7 @@ matter, although you should take care to only mention each file once,
since any file mentioned twice will be added in twice.</para>
<para>
-<computeroutput>cg_merge</computeroutput> does not attempt to check
+cg_merge does not attempt to check
that the input files come from runs of the same executable. It will
happily merge together profile files from completely unrelated
programs. It does however check that the
@@ -1215,7 +1181,7 @@ write misses.</para>
<para>
A number of other syntax and sanity checks are done whilst reading the
-inputs. <computeroutput>cg_merge</computeroutput> will stop and
+inputs. cg_merge will stop and
attempt to print a helpful error message if any of the input files
fail these checks.</para>
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index a7adbe893..bf586c166 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -121,9 +121,7 @@ static void usage_NORETURN ( Bool debug_help )
" --track-fds=no|yes track open file descriptors? [no]\n"
" --time-stamp=no|yes add timestamps to log messages? [no]\n"
" --log-fd=<number> log messages to file descriptor [2=stderr]\n"
-" --log-file=<file> log messages to <file>.<pid>\n"
-" --log-file-exactly=<file> log messages to <file>\n"
-" --log-file-qualifier=<VAR> incorporate $VAR in logfile name [none]\n"
+" --log-file=<file> log messages to <file>\n"
" --log-socket=ipaddr:port log messages to socket ipaddr:port\n"
"\n"
" uncommon user options for all Valgrind tools:\n"
@@ -293,7 +291,6 @@ static Bool process_cmd_line_options( UInt* client_auxv, const char* toolname )
enum {
VgLogTo_Fd,
VgLogTo_File,
- VgLogTo_FileExactly,
VgLogTo_Socket
} log_to = VgLogTo_Fd; // Where is logging output to be sent?
@@ -435,15 +432,6 @@ static Bool process_cmd_line_options( UInt* client_auxv, const char* toolname )
VG_(clo_log_name) = &arg[11];
}
- else if (VG_CLO_STREQN(21, arg, "--log-file-qualifier=")) {
- VG_(clo_log_file_qualifier) = &arg[21];
- }
-
- else if (VG_CLO_STREQN(19, arg, "--log-file-exactly=")) {
- log_to = VgLogTo_FileExactly;
- VG_(clo_log_name) = &arg[19];
- }
-
else if (VG_CLO_STREQN(13, arg, "--log-socket=")) {
log_to = VgLogTo_Socket;
VG_(clo_log_name) = &arg[13];
@@ -601,80 +589,27 @@ static Bool process_cmd_line_options( UInt* client_auxv, const char* toolname )
break;
case VgLogTo_File: {
- HChar logfilename[1000];
- Int seq = 0;
- Int pid = VG_(getpid)();
- HChar* qual = NULL;
-
- vg_assert(VG_(clo_log_name) != NULL);
- vg_assert(VG_(strlen)(VG_(clo_log_name)) <= 900); /* paranoia */
-
- if (VG_(clo_log_file_qualifier)) {
- qual = VG_(getenv)(VG_(clo_log_file_qualifier));
- }
+ Char* logfilename;
- for (;;) {
- HChar pidtxt[20], seqtxt[20];
-
- VG_(sprintf)(pidtxt, "%d", pid);
-
- if (seq == 0)
- seqtxt[0] = 0;
- else
- VG_(sprintf)(seqtxt, ".%d", seq);
-
- seq++;
-
- /* Result:
- if (qual) base_name ++ "." ++ qual ++ seqtxt
- if (not qual) base_name ++ "." ++ pid ++ seqtxt
- */
- VG_(sprintf)( logfilename,
- "%s.%s%s",
- VG_(clo_log_name),
- qual ? qual : pidtxt,
- seqtxt );
-
- // EXCL: it will fail with EEXIST if the file already exists.
- sres = VG_(open)(logfilename,
- VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC,
- VKI_S_IRUSR|VKI_S_IWUSR);
- if (!sres.isError) {
- tmp_log_fd = sres.res;
- break; /* for (;;) */
- } else {
- // If the file already existed, we try the next name. If it
- // was some other file error, we give up.
- if (sres.err != VKI_EEXIST) {
- VG_(message)(Vg_UserMsg,
- "Can't create log file '%s' (%s); giving up!",
- logfilename, VG_(strerror)(sres.err));
- VG_(err_bad_option)(
- "--log-file=<file> (didn't work out for some reason.)");
- /*NOTREACHED*/
- }
- }
- }
- break; /* switch (VG_(clo_log_to)) */
- }
-
- case VgLogTo_FileExactly: {
vg_assert(VG_(clo_log_name) != NULL);
vg_assert(VG_(strlen)(VG_(clo_log_name)) <= 900); /* paranoia */
- sres = VG_(open)(VG_(clo_log_name),
+ // Nb: we overwrite an existing file of this name without asking
+ // any questions.
+ logfilename = VG_(expand_file_name)("--log-file", VG_(clo_log_name));
+ sres = VG_(open)(logfilename,
VKI_O_CREAT|VKI_O_WRONLY|VKI_O_TRUNC,
VKI_S_IRUSR|VKI_S_IWUSR);
if (!sres.isError) {
tmp_log_fd = sres.res;
} else {
VG_(message)(Vg_UserMsg,
- "Can't create/open log file '%s'; giving up!",
- VG_(clo_log_name));
+ "Can't create log file '%s' (%s); giving up!",
+ logfilename, VG_(strerror)(sres.err));
VG_(err_bad_option)(
- "--log-file-exactly=<file> (didn't work out for some reason.)");
+ "--log-file=<file> (didn't work out for some reason.)");
/*NOTREACHED*/
- }
+ }
break; /* switch (VG_(clo_log_to)) */
}
@@ -838,13 +773,6 @@ static void print_preamble(Bool logging_to_fd, const char* toolname)
VG_(message)(Vg_UserMsg,
" %s",
* (HChar**) VG_(indexXA)( VG_(args_for_client), i ));
- if (VG_(clo_log_file_qualifier)) {
- HChar* val = VG_(getenv)(VG_(clo_log_file_qualifier));
- VG_(message)(Vg_UserMsg, "");
- VG_(message)(Vg_UserMsg, "Log file qualifier: var %s, value %s.",
- VG_(clo_log_file_qualifier),
- val ? val : "");
- }
}
else
if (VG_(clo_xml)) {
@@ -852,13 +780,16 @@ static void print_preamble(Bool logging_to_fd, const char* toolname)
VG_(message)(Vg_UserMsg, "<pid>%d</pid>", VG_(getpid)());
VG_(message)(Vg_UserMsg, "<ppid>%d</ppid>", VG_(getppid)());
VG_(message)(Vg_UserMsg, "<tool>%t</tool>", toolname);
- if (VG_(clo_log_file_qualifier)) {
- HChar* val = VG_(getenv)(VG_(clo_log_file_qualifier));
- VG_(message)(Vg_UserMsg, "<logfilequalifier> <var>%t</var> "
- "<value>%t</value> </logfilequalifier>",
- VG_(clo_log_file_qualifier),
- val ? val : "");
- }
+// [This was made obsolete by the --log-file change in 3.3.0. But
+// I'm leaving it here (commented out) in case it needs to be reinstated in
+// some way --njn]
+// if (VG_(clo_log_file_qualifier)) {
+// HChar* val = VG_(getenv)(VG_(clo_log_file_qualifier));
+// VG_(message)(Vg_UserMsg, "<logfilequalifier> <var>%t</var> "
+// "<value>%t</value> </logfilequalifier>",
+// VG_(clo_log_file_qualifier),
+// val ? val : "");
+// }
if (VG_(clo_xml_user_comment)) {
/* Note: the user comment itself is XML and is therefore to
be passed through verbatim (%s) rather than escaped
@@ -1630,7 +1561,6 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
// Print the preamble
// p: tl_pre_clo_init [for 'VG_(details).name' and friends]
// p: process_cmd_line_options() [for VG_(clo_verbosity), VG_(clo_xml),
- // VG_(clo_log_file_qualifier),
// logging_to_fd]
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Print the preamble...\n");
diff --git a/coregrind/m_options.c b/coregrind/m_options.c
index cd35f6680..1e32a20b4 100644
--- a/coregrind/m_options.c
+++ b/coregrind/m_options.c
@@ -30,9 +30,14 @@
*/
#include "pub_core_basics.h"
+#include "pub_core_vki.h"
#include "pub_core_options.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
+#include "pub_core_libcproc.h"
+#include "pub_core_mallocfree.h"
// See pub_{core,tool}_options.h for explanations of all these.
@@ -53,7 +58,6 @@ Bool VG_(clo_trace_children) = False;
Bool VG_(clo_child_silent_after_fork) = False;
Int VG_(clo_log_fd) = 2; /* must be signed, as -1 is possible. */
Char* VG_(clo_log_name) = NULL;
-Char* VG_(clo_log_file_qualifier) = NULL;
Bool VG_(clo_time_stamp) = False;
Int VG_(clo_input_fd) = 0; /* stdin */
Int VG_(clo_n_suppressions) = 0;
@@ -123,6 +127,111 @@ void VG_(err_config_error) ( Char* msg )
VG_(exit)(1);
}
+// Copies the string, prepending it with the startup working directory, and
+// expanding %p and %q entries. Returns a new, malloc'd string.
+Char* VG_(expand_file_name)(Char* option_name, Char* format)
+{
+ static Char base_dir[VKI_PATH_MAX];
+ Int len, i = 0, j = 0;
+ Char* out;
+
+ Bool ok = VG_(get_startup_wd)(base_dir, VKI_PATH_MAX);
+ tl_assert(ok);
+
+ if (VG_STREQ(format, "")) {
+ // Empty name, bad.
+ VG_(message)(Vg_UserMsg, "%s: filename is empty", option_name);
+ goto bad;
+ }
+
+ // The 10 is slop, it should be enough in most cases.
+ j = VG_(strlen)(base_dir);
+ len = j + VG_(strlen)(format) + 10;
+ out = VG_(malloc)( len );
+ VG_(strcpy)(out, base_dir);
+
+#define ENSURE_THIS_MUCH_SPACE(x) \
+ if (j + x >= len) { \
+ len += (10 + x); \
+ out = VG_(realloc)(out, len); \
+ }
+
+ out[j++] = '/';
+ while (format[i]) {
+ if (format[i] != '%') {
+ ENSURE_THIS_MUCH_SPACE(1);
+ out[j++] = format[i++];
+
+ } else {
+ // We saw a '%'. What's next...
+ i++;
+ if ('%' == format[i]) {
+ // Replace '%%' with '%'.
+ ENSURE_THIS_MUCH_SPACE(1);
+ out[j++] = format[i++];
+ }
+ else if ('p' == format[i]) {
+ // Print the PID. Assume that it's not longer than 10 chars --
+ // reasonable since 'pid' is an Int (ie. 32 bits).
+ Int pid = VG_(getpid)();
+ ENSURE_THIS_MUCH_SPACE(10);
+ j += VG_(sprintf)(&out[j], "%d", pid);
+ i++;
+ }
+ else if ('q' == format[i] && '{' == format[i+1]) {
+ // Get the env var name, print its contents.
+ Char* qualname;
+ Char* qual;
+ i += 2;
+ qualname = &format[i];
+ while (True) {
+ if (0 == format[i]) {
+ VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier",
+ option_name);
+ goto bad;
+ } else if ('}' == format[i]) {
+ // Temporarily replace the '}' with NUL to extract var name.
+ format[i] = 0;
+ qual = VG_(getenv)(qualname);
+ if (NULL == qual) {
+ VG_(message)(Vg_UserMsg,
+ "%s: environment variable %s is not set",
+ option_name, qualname);
+ goto bad;
+ }
+ format[i] = '}'; // Put the '}' back.
+ i++;
+ break;
+ }
+ i++;
+ }
+ ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual));
+ j += VG_(sprintf)(&out[j], "%s", qual);
+ }
+ else {
+ // Something else, abort.
+ VG_(message)(Vg_UserMsg,
+ "%s: expected 'p' or 'q' or '%%' after '%%'", option_name);
+ goto bad;
+ }
+ }
+ }
+ ENSURE_THIS_MUCH_SPACE(1);
+ out[j++] = 0;
+
+ return out;
+
+ bad: {
+ Char* opt = // 2: 1 for the '=', 1 for the NUL.
+ VG_(malloc)( VG_(strlen)(option_name) + VG_(strlen)(format) + 2 );
+ VG_(strcpy)(opt, option_name);
+ VG_(strcat)(opt, "=");
+ VG_(strcat)(opt, format);
+ VG_(err_bad_option)(opt);
+ }
+}
+
+
/*--------------------------------------------------------------------*/
/*--- end m_options.c ---*/
diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h
index 39947dbd3..384a6a5e3 100644
--- a/coregrind/pub_core_options.h
+++ b/coregrind/pub_core_options.h
@@ -74,16 +74,11 @@ extern Bool VG_(clo_child_silent_after_fork);
taken from the command line. (fd 2, stderr, is the default.)
clo_log_name is irrelevant.
- With --log-file/--log-file-exactly, clo_log_name holds the log-file
- name, and is taken from the command line. clo_log_fd is then
- made to hold the relevant file id, by opening clo_log_name
- (concatenated with the process ID) for writing.
-
- With --log-file, there is an additional twist: if
- clo_log_file_qualifier is non-NULL, the contents of the environment
- variable specified by clo_log_file_qualifier is incorporated into
- the logfile name. This is useful in that it allows the logfile
- name to incorporate environmental information.
+ With --log-file, clo_log_name holds the log-file name, and is taken from
+ the command line (and possibly has process ID/env var contents in it, if
+ the %p or %q format specifiers are used). clo_log_fd is then made to
+ hold the relevant file id, by opening clo_log_name (concatenated with the
+ process ID) for writing.
With --log-socket, clo_log_name holds the hostname:portnumber pair,
and is taken from the command line. clo_log_fd is then made to hold
@@ -94,7 +89,6 @@ extern Bool VG_(clo_child_silent_after_fork);
(stderr). */
extern Int VG_(clo_log_fd);
extern Char* VG_(clo_log_name);
-/* extern Char* VG_(clo_log_file_qualifier); moved to pub_tool_options.h */
/* Add timestamps to log messages? default: NO */
extern Bool VG_(clo_time_stamp);
diff --git a/docs/internals/xml-output.txt b/docs/internals/xml-output.txt
index eaf16dca7..03cea9505 100644
--- a/docs/internals/xml-output.txt
+++ b/docs/internals/xml-output.txt
@@ -154,6 +154,8 @@ following in sequence:
That is, both the name of the environment variable and its value
are given.
+ [update: as of v3.3.0, this is not present, as the --log-file-qualifier
+ option has been removed, replaced by the %q format specifier in --log-file.]
* OPTIONALLY, if --xml-user-comment=STRING was given:
diff --git a/docs/xml/manual-core.xml b/docs/xml/manual-core.xml
index a7f5d22f8..5ff421bfc 100644
--- a/docs/xml/manual-core.xml
+++ b/docs/xml/manual-core.xml
@@ -191,32 +191,12 @@ re-run, passing the <option>-v</option> flag to Valgrind. A second
<listitem id="manual-core.out2file"
xreflabel="Directing output to file"> <para>A less intrusive
option is to write the commentary to a file, which you specify by
- <option>--log-file=filename</option>. Note carefully that the
- commentary is <command>not</command> written to the file you
- specify, but instead to one called
- <filename>filename.12345</filename>, if for example the pid of the
- traced process is 12345. This is helpful when Valgrinding a whole
- tree of processes at once, since it means that each process writes
- to its own logfile, rather than the result being jumbled up in one
- big logfile. If <filename>filename.12345</filename> already exists,
- then it will name new files <filename>filename.12345.1</filename>
- and so on.</para>
-
- <para>If you want to specify precisely the file name to use, without
- the trailing <computeroutput>.12345</computeroutput> part, you can
- instead use <option>--log-file-exactly=filename</option>.</para>
-
- <para>You can also use the
- <option>--log-file-qualifier=&lt;VAR&gt;</option> option to
- incorporate into the filename the contents of environment variable
- <varname>VAR</varname>. This is rarely needed, but very useful in
- certain circumstances (eg. when running MPI programs). In this
- case, the trailing <computeroutput>.12345</computeroutput> part is
- replaced by (the contents of) <varname>$VAR</varname>. The idea is
- that you specify a variable which will be set differently for each
- process in the job, for example
- <computeroutput>BPROC_RANK</computeroutput> or whatever is
- applicable in your MPI setup.</para>
+ <option>--log-file=filename</option>. There are special format
+ specifiers that can be used to use a process ID or an environment
+ variable name in the log file name. These are useful/necessary if your
+ program invokes multiple processes (especially for MPI programs).
+ See the <link linkend="manual-core.basicopts">basic options section</link>
+ for more details.</para>
</listitem>
<listitem id="manual-core.out2socket"
@@ -720,40 +700,34 @@ categories.</para>
</term>
<listitem>
<para>Specifies that Valgrind should send all of its messages to
- the specified file. In fact, the file name used is created by
- concatenating the text <filename>filename</filename>, "." and the
- process ID, (ie. <![CDATA[<filename>.<pid>]]>), so as to create a
- file per process. The specified file name may not be the empty
- string.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry id="opt.log-file-exactly" xreflabel="--log-file-exactly">
- <term>
- <option><![CDATA[--log-file-exactly=<filename> ]]></option>
- </term>
- <listitem>
- <para>Just like <option>--log-file</option>, but the suffix
- <computeroutput>".pid"</computeroutput> is not added. WARNING: If you
- use this option with <option>--trace-children=yes</option> and your
- program invokes multiple processes, the Valgrind output from all those
- processes will go into this one file, possibly jumbled up, and
+ the specified file. If the file name is empty, it causes an abort.
+ There are three special format specifiers that can be used in the file
+ name.</para>
+
+ <para><option>%p</option> is replaced with the current process ID.
+ This is very useful for program that invoke multiple processes.
+ WARNING: If you use <option>--trace-children=yes</option> and your
+ program invokes multiple processes and you don't use this specifier
+ (or the <option>%q</option> specifier below), the Valgrind output from
+ all those processes will go into one file, possibly jumbled up, and
possibly incomplete.</para>
- </listitem>
- </varlistentry>
- <varlistentry id="opt.log-file-qualifier" xreflabel="--log-file-qualifier">
- <term>
- <option><![CDATA[--log-file-qualifier=<VAR> ]]></option>
- </term>
- <listitem>
- <para>When used in conjunction with <option>--log-file</option>,
- causes the log file name to be qualified using the contents of the
- environment variable <computeroutput>$VAR</computeroutput>. This
- is useful when running MPI programs. For further details, see
- <link linkend="manual-core.comment">the commentary</link>
- in the manual.
- </para>
+ <para><option>%q{FOO}</option> is replaced with the contents of the
+ environment variable <varname>FOO</varname>. If the
+ <option>{FOO}</option> part is malformed, it causes an abort. This
+ specifier is rarely needed, but very useful in certain circumstances
+ (eg. when running MPI programs). The idea is that you specify a
+ variable which will be set differently for each process in the job,
+ for example <computeroutput>BPROC_RANK</computeroutput> or whatever is
+ applicable in your MPI setup. If the named environment variable is not
+ set, it causes an abort. Note that in some shells, the
+ <option>{</option> and <option>}</option> characters may need to be
+ escaped with a backslash.</para>
+
+ <para><option>%%</option> is replaced with <option>%</option>.</para>
+
+ <para>If an <option>%</option> is followed by any other character, it
+ causes an abort.</para>
</listitem>
</varlistentry>
diff --git a/include/pub_tool_options.h b/include/pub_tool_options.h
index 369f8a28d..c03920b40 100644
--- a/include/pub_tool_options.h
+++ b/include/pub_tool_options.h
@@ -110,11 +110,6 @@ extern Bool VG_(clo_xml);
XML output, in between <usercomment> tags. */
extern HChar* VG_(clo_xml_user_comment);
-/* Name of an environment variable which, if set, is to be used as
- part of any output file name. See pub_core_options.h for
- details. */
-extern Char* VG_(clo_log_file_qualifier);
-
/* Vex iropt control. Tool-visible so tools can make Vex optimise
less aggressively if that is needed (callgrind needs this). */
extern VexControl VG_(clo_vex_control);
@@ -127,6 +122,16 @@ extern VexControl VG_(clo_vex_control);
__attribute__((noreturn))
extern void VG_(err_bad_option) ( Char* opt );
+/* Used to expand file names. 'option_name" is the option name, eg.
+ "--log-file". 'format' is what follows, eg. "cachegrind.out.%p". In
+ 'format':
+ - "%p" is replaced with PID.
+ - "%q{QUAL}" is replaced with the environment variable $QUAL. If $QUAL
+ isn't set, we abort. If the "{QUAL}" part is malformed, we abort.
+ - "%%" is replaced with "%".
+ Anything else after '%' causes an abort.
+*/
+extern Char* VG_(expand_file_name)(Char* option_name, Char* format);
#endif // __PUB_TOOL_OPTIONS_H
diff --git a/massif/ms_main.c b/massif/ms_main.c
index 578bc16c7..f940a9144 100644
--- a/massif/ms_main.c
+++ b/massif/ms_main.c
@@ -36,24 +36,8 @@
// - do a graph-drawing test
// - write a good basic test that shows how the tool works, suitable for
// documentation
-// - do filename properly, clean up Valgrind-wide log file naming mess.
-// Expected behaviour:
-// - Main log file:
-// default --> stderr
-// --log-file=X --> X.<pid>
-// --log-file-exactly=X --> X
-// --log-file-qualifier=QUAL --> [error]
-// --log-file=X --log-file-qualifier=QUAL --> X.$QUAL
-// - Massif out file:
-// default --> cachegrind.out.<pid>
-// --cg-out-file=X --> X.<pid>
-// --cg-out-file-exactly=X --> X
-// --cg-out-file-qualifier=QUAL --> [error]
-// --cg-out-file=X --cg-out-file-qualifier=QUAL --> X.$QUAL
-// - Likewise for Cachegrind, but with --cg-out/cg.out.
-// - And in cg_annotate, remove the --<pid> option.
-// - Likewise for Callgrind, but with --cl-out/cl.out (?)
-// - And don't create .1, .2 etc suffixed files.
+// - In cg_annotate, remove the --<pid> option.
+// - Get Josef to update the Callgrind --callgrind-out-file option.
//
// Todo -- nice, but less critical:
// - make file format more generic. Obstacles:
@@ -326,9 +310,6 @@ static SizeT peak_snapshot_total_szB = 0;
// memory. An alternative to milliseconds as a unit of program "time".
static ULong total_allocs_deallocs_szB = 0;
-// The output file name. Controlled by --massif-out-file.
-static Char* massif_out_file = NULL;
-
// We don't start taking snapshots until the first basic block is executed,
// rather than doing it in ms_post_clo_init (which is the obvious spot), for
// two reasons.
@@ -476,7 +457,7 @@ static void ms_print_usage(void)
" alloc'd/dealloc'd on the heap [ms]\n"
" --detailed-freq=<N> every Nth snapshot should be detailed [10]\n"
" --max-snapshots=<N> maximum number of snapshots recorded [100]\n"
-" --massif-out-file=<s> output file name [massif.out.%%p]\n"
+" --massif-out-file=<file> output file name [massif.out.%%p]\n"
);
VG_(replacement_malloc_print_usage)();
}
@@ -1815,6 +1796,9 @@ IRSB* ms_instrument ( VgCallbackClosure* closure,
//--- Writing snapshots ---//
//------------------------------------------------------------//
+// The output file name. Controlled by --massif-out-file.
+static Char* massif_out_file = NULL;
+
#define FP_BUF_SIZE 1024
Char FP_buf[FP_BUF_SIZE];
@@ -2052,105 +2036,6 @@ static void ms_fini(Int exit_status)
//--- Initialisation ---//
//------------------------------------------------------------//
-// Copies the string, prepending it with the startup working directory, and
-// expanding %p and %q entries. Returns a new, malloc'd string.
-static Char* VG_(expand_file_name)(Char* option_name, Char* format)
-{
- static Char base_dir[VKI_PATH_MAX];
- Int len, i = 0, j = 0;
- Char* out;
-
- Bool ok = VG_(get_startup_wd)(base_dir, VKI_PATH_MAX);
- tl_assert(ok);
-
- // The 10 is slop, it should be enough in most cases.
- j = VG_(strlen)(base_dir);
- len = j + VG_(strlen)(format) + 10;
- out = VG_(malloc)( len );
- VG_(strcpy)(out, base_dir);
-
-#define ENSURE_THIS_MUCH_SPACE(x) \
- if (j + x >= len) { \
- len += (10 + x); \
- out = VG_(realloc)(out, len); \
- }
-
- out[j++] = '/';
- while (format[i]) {
- if (format[i] != '%') {
- ENSURE_THIS_MUCH_SPACE(1);
- out[j++] = format[i++];
-
- } else {
- // We saw a '%'. What's next...
- i++;
- if ('%' == format[i]) {
- // Replace '%%' with '%'.
- ENSURE_THIS_MUCH_SPACE(1);
- out[j++] = format[i++];
- }
- else if ('p' == format[i]) {
- // Print the PID. Assume that it's not longer than 10 chars --
- // reasonable since 'pid' is an Int (ie. 32 bits).
- Int pid = VG_(getpid)();
- ENSURE_THIS_MUCH_SPACE(10);
- j += VG_(sprintf)(&out[j], "%d", pid);
- i++;
- }
- else if ('q' == format[i] && '{' == format[i+1]) {
- // Get the env var name, print its contents.
- Char* qualname;
- Char* qual;
- i += 2;
- qualname = &format[i];
- while (True) {
- if (0 == format[i]) {
- VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier",
- option_name);
- goto bad;
- } else if ('}' == format[i]) {
- // Temporarily replace the '}' with NUL to extract var name.
- format[i] = 0;
- qual = VG_(getenv)(qualname);
- if (NULL == qual) {
- VG_(message)(Vg_UserMsg,
- "%s: environment variable %s is not set",
- option_name, qualname);
- goto bad;
- }
- format[i] = '}'; // Put the '}' back.
- i++;
- break;
- }
- i++;
- }
- ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual));
- j += VG_(sprintf)(&out[j], "%s", qual);
- }
- else {
- // Something else, abort.
- VG_(message)(Vg_UserMsg,
- "%s: expected 'p' or 'q' or '%%' after '%%'", option_name);
- goto bad;
- }
- }
- }
- ENSURE_THIS_MUCH_SPACE(1);
- out[j++] = 0;
-
- return out;
-
- bad: {
- Char* opt = // 2: 1 for the '=', 1 for the NUL.
- VG_(malloc)( VG_(strlen)(option_name) + VG_(strlen)(format) + 2 );
- VG_(strcpy)(opt, option_name);
- VG_(strcat)(opt, "=");
- VG_(strcat)(opt, format);
- VG_(err_bad_option)(opt);
- }
-}
-
-
static void ms_post_clo_init(void)
{
Int i;
diff --git a/none/tests/cmdline1.stdout.exp b/none/tests/cmdline1.stdout.exp
index 2dd41f209..fbae97564 100644
--- a/none/tests/cmdline1.stdout.exp
+++ b/none/tests/cmdline1.stdout.exp
@@ -7,13 +7,12 @@ usage: valgrind [options] prog-and-args
--version show version
-q --quiet run silently; only print error msgs
-v --verbose be more verbose, incl counts of errors
- --trace-children=no|yes Valgrind-ise child processes? [no]
+ --trace-children=no|yes Valgrind-ise child processes (follow execve)? [no]
+ --child-silent-after-fork=no|yes omit child output between fork & exec? [no]
--track-fds=no|yes track open file descriptors? [no]
--time-stamp=no|yes add timestamps to log messages? [no]
--log-fd=<number> log messages to file descriptor [2=stderr]
- --log-file=<file> log messages to <file>.<pid>
- --log-file-exactly=<file> log messages to <file>
- --log-file-qualifier=<VAR> incorporate $VAR in logfile name [none]
+ --log-file=<file> log messages to <file>
--log-socket=ipaddr:port log messages to socket ipaddr:port
uncommon user options for all Valgrind tools:
diff --git a/none/tests/cmdline2.stdout.exp b/none/tests/cmdline2.stdout.exp
index 9bf47235d..3242b5e33 100644
--- a/none/tests/cmdline2.stdout.exp
+++ b/none/tests/cmdline2.stdout.exp
@@ -7,13 +7,12 @@ usage: valgrind [options] prog-and-args
--version show version
-q --quiet run silently; only print error msgs
-v --verbose be more verbose, incl counts of errors
- --trace-children=no|yes Valgrind-ise child processes? [no]
+ --trace-children=no|yes Valgrind-ise child processes (follow execve)? [no]
+ --child-silent-after-fork=no|yes omit child output between fork & exec? [no]
--track-fds=no|yes track open file descriptors? [no]
--time-stamp=no|yes add timestamps to log messages? [no]
--log-fd=<number> log messages to file descriptor [2=stderr]
- --log-file=<file> log messages to <file>.<pid>
- --log-file-exactly=<file> log messages to <file>
- --log-file-qualifier=<VAR> incorporate $VAR in logfile name [none]
+ --log-file=<file> log messages to <file>
--log-socket=ipaddr:port log messages to socket ipaddr:port
uncommon user options for all Valgrind tools: