|
From: <sv...@va...> - 2008-10-24 18:50:06
|
Author: weidendo
Date: 2008-10-24 19:50:00 +0100 (Fri, 24 Oct 2008)
New Revision: 8704
Log:
Fix for bug 166581: use correct output file name after PID change
This is a little tricky because
* we want to check directly at startup whether the output file
can be written, thus the file name is set at beginning.
* a fork changes the PID in the child, and thus (potentially) the
output file name has to be updated. This best is directly before
generating the profile dump.
* the child after fork needs to be controllable via callgrind_control.
The setup of the control interface needs the new file name, too.
The fix is to allow multiple calls of CLG(init_dumps), everytime the
output file name is needed.
Modified:
trunk/callgrind/dump.c
Modified: trunk/callgrind/dump.c
===================================================================
--- trunk/callgrind/dump.c 2008-10-23 22:16:41 UTC (rev 8703)
+++ trunk/callgrind/dump.c 2008-10-24 18:50:00 UTC (rev 8704)
@@ -64,13 +64,13 @@
Char* CLG_(get_out_file)()
{
- CLG_ASSERT(dumps_initialized);
+ CLG_(init_dumps)();
return out_file;
}
Char* CLG_(get_out_directory)()
{
- CLG_ASSERT(dumps_initialized);
+ CLG_(init_dumps)();
return out_directory;
}
@@ -1616,6 +1616,8 @@
CLG_DEBUG(2, "+ dump_profile(Trigger '%s')\n",
trigger ? trigger : (Char*)"Prg.Term.");
+ CLG_(init_dumps)();
+
if (VG_(clo_verbosity) > 1)
VG_(message)(Vg_DebugMsg, "Start dumping at BB %llu (%s)...",
CLG_(stat).bb_executions,
@@ -1673,15 +1675,35 @@
* <out_file> always starts with a full absolute path.
* If the output format string represents a relative path, the current
* working directory at program start is used.
+ *
+ * This function has to be called every time a profile dump is generated
+ * to be able to react on PID changes.
*/
void CLG_(init_dumps)()
{
Int lastSlash, i;
SysRes res;
+ static int thisPID = 0;
+ int currentPID = VG_(getpid)();
+ if (currentPID == thisPID) {
+ /* already initialized, and no PID change */
+ CLG_ASSERT(out_file != 0);
+ return;
+ }
+ thisPID = currentPID;
+
if (!CLG_(clo).out_format)
CLG_(clo).out_format = DEFAULT_OUTFORMAT;
+ /* If a file name was already set, clean up before */
+ if (out_file) {
+ VG_(free)(out_file);
+ VG_(free)(out_directory);
+ VG_(free)(filename);
+ out_counter = 0;
+ }
+
// Setup output filename.
out_file =
VG_(expand_file_name)("--callgrind-out-file", CLG_(clo).out_format);
@@ -1721,7 +1743,8 @@
}
if (!res.isError) VG_(close)( (Int)res.res );
- init_cmdbuf();
+ if (!dumps_initialized)
+ init_cmdbuf();
dumps_initialized = True;
}
|