]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
New command line option: --log-file-qualifier=VAR. When specified,
authorJulian Seward <jseward@acm.org>
Tue, 19 Jul 2005 11:25:02 +0000 (11:25 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 19 Jul 2005 11:25:02 +0000 (11:25 +0000)
the contents of environment variable VAR (viz, $VAR) are incorporated
into logfile names.  This makes it easy to incorporate environmental
information into logfile names.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4180

README_XML_OUTPUT.txt
coregrind/m_main.c
coregrind/m_options.c
coregrind/pub_core_options.h

index bd90cf95443f8a0ab30f3fa0f234efe3b69efd43..3ad26967ca3de46f453c71637f1fe1b68a014a68 100644 (file)
@@ -134,6 +134,14 @@ following in sequence:
 
      <tool>TEXT</tool>
 
+* OPTIONALLY, if --log-file-qualifier=VAR flag was given:
+
+     <logfilequalifier> <var>VAR</var> <value>$VAR</value>
+     </logfilequalifier>
+
+  That is, both the name of the environment variable and its value
+  are given.
+
 * The program and args being run.
 
      <argv>
index d4e2e457ef3f042d695e6f8732f24755d83efd3e..da97ed5501db60e687720b28e06e91fc2ed304f0 100644 (file)
@@ -1275,6 +1275,7 @@ static void usage ( Bool debug_help )
 "    --log-fd=<number>         log messages to file descriptor [2=stderr]\n"
 "    --log-file=<file>         log messages to <file>.pid<pid>\n"
 "    --log-file-exactly=<file> log messages to <file>\n"
+"    --log-file-qualifier=<VAR> incorporate $VAR in logfile name [none]\n"
 "    --log-socket=ipaddr:port  log messages to socket ipaddr:port\n"
 "    --demangle=no|yes         automatically demangle C++ names? [yes]\n"
 "    --num-callers=<number>    show <num> callers in stack traces [12]\n"
@@ -1534,6 +1535,15 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
          VG_(clo_log_name) = &arg[11];
       }
 
+      else if (VG_CLO_STREQN(11, arg, "--log-file=")) {
+         log_to            = VgLogTo_File;
+         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];
@@ -1696,20 +1706,29 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
          break;
 
       case VgLogTo_File: {
-         Char logfilename[1000];
-        Int seq = 0;
-        Int pid = VG_(getpid)();
+         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));
+        }
+
         for (;;) {
            if (seq == 0)
-              VG_(sprintf)(logfilename, "%s.pid%d",
-                           VG_(clo_log_name), pid );
+              VG_(sprintf)( logfilename, "%s%s%s.pid%d",
+                             VG_(clo_log_name), 
+                             qual ? "." : "", qual ? qual : "",
+                             pid );
            else
-              VG_(sprintf)(logfilename, "%s.pid%d.%d",
-                           VG_(clo_log_name), pid, seq );
+              VG_(sprintf)( logfilename, "%s%s%s.pid%d.%d",
+                            VG_(clo_log_name), 
+                             qual ? "." : "", qual ? qual : "",
+                             pid, seq );
            seq++;
 
             // EXCL: it will fail with EEXIST if the file already exists.
@@ -1879,6 +1898,13 @@ static void process_cmd_line_options( UInt* client_auxv, 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>%s</tool>", toolname);
+      if (VG_(clo_log_file_qualifier)) {
+         HChar* val = VG_(getenv)(VG_(clo_log_file_qualifier));
+         VG_(message)(Vg_UserMsg, "<logfilequalifier> <var>%s</var> "
+                                  "<value>%s</value> </logfilequalifier>",
+                                  VG_(clo_log_file_qualifier),
+                                  val ? val : "");
+      }
       VG_(message)(Vg_UserMsg, "");
       VG_(message)(Vg_UserMsg, "<argv>");   
       for (i = 0; i < VG_(client_argc); i++) {
index 16f4a35cc9e35605db12fb86b6c290c71243288d..cf989245efafe2991a630b75722d7aa87c52378b 100644 (file)
@@ -48,6 +48,7 @@ Bool   VG_(clo_demangle)       = True;
 Bool   VG_(clo_trace_children) = False;
 Int    VG_(clo_log_fd)         = 2;
 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;
index 14faef4ea84a63ac08d90934a43597874f822408..b24ad94ffe18d8c264fb27cc7336c6729c94ea8d 100644 (file)
@@ -71,6 +71,12 @@ extern Bool  VG_(clo_trace_children);
    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-socket, clo_log_name holds the hostname:portnumber pair,
    and is taken from the command line.  clo_log_fd is then made to hold
    the relevant file handle, by opening a connection to that
@@ -78,8 +84,9 @@ extern Bool  VG_(clo_trace_children);
 
    Global default is to set log_to == VgLogTo_Fd and log_fd == 2
    (stderr). */
-extern Int     VG_(clo_log_fd);
-extern Char*   VG_(clo_log_name);
+extern Int   VG_(clo_log_fd);
+extern Char* VG_(clo_log_name);
+extern Char* VG_(clo_log_file_qualifier);
 
 /* Add timestamps to log messages?  default: NO */
 extern Bool  VG_(clo_time_stamp);