From: Julian Seward Date: Tue, 19 Jul 2005 11:25:02 +0000 (+0000) Subject: New command line option: --log-file-qualifier=VAR. When specified, X-Git-Tag: svn/VALGRIND_3_0_0~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89b76a72f48e18cb73234801e9ba597701304262;p=thirdparty%2Fvalgrind.git New command line option: --log-file-qualifier=VAR. When specified, 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 --- diff --git a/README_XML_OUTPUT.txt b/README_XML_OUTPUT.txt index bd90cf9544..3ad26967ca 100644 --- a/README_XML_OUTPUT.txt +++ b/README_XML_OUTPUT.txt @@ -134,6 +134,14 @@ following in sequence: TEXT +* OPTIONALLY, if --log-file-qualifier=VAR flag was given: + + VAR $VAR + + + That is, both the name of the environment variable and its value + are given. + * The program and args being run. diff --git a/coregrind/m_main.c b/coregrind/m_main.c index d4e2e457ef..da97ed5501 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -1275,6 +1275,7 @@ static void usage ( Bool debug_help ) " --log-fd= log messages to file descriptor [2=stderr]\n" " --log-file= log messages to .pid\n" " --log-file-exactly= log messages to \n" +" --log-file-qualifier= 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= show 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, "%d", VG_(getpid)()); VG_(message)(Vg_UserMsg, "%d", VG_(getppid)()); VG_(message)(Vg_UserMsg, "%s", toolname); + if (VG_(clo_log_file_qualifier)) { + HChar* val = VG_(getenv)(VG_(clo_log_file_qualifier)); + VG_(message)(Vg_UserMsg, " %s " + "%s ", + VG_(clo_log_file_qualifier), + val ? val : ""); + } VG_(message)(Vg_UserMsg, ""); VG_(message)(Vg_UserMsg, ""); for (i = 0; i < VG_(client_argc); i++) { diff --git a/coregrind/m_options.c b/coregrind/m_options.c index 16f4a35cc9..cf989245ef 100644 --- a/coregrind/m_options.c +++ b/coregrind/m_options.c @@ -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; diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h index 14faef4ea8..b24ad94ffe 100644 --- a/coregrind/pub_core_options.h +++ b/coregrind/pub_core_options.h @@ -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);