diff options
author | weidendo <weidendo@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2008-10-24 18:50:00 +0000 |
---|---|---|
committer | weidendo <weidendo@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2008-10-24 18:50:00 +0000 |
commit | d74d9f79b014d1f371dea044cd0bc5f6be4ba8cf (patch) | |
tree | 6ed6de0a520126adbf420008d84649f712ba5e9f /callgrind | |
parent | b2769e2327186df5bf622dee3d6e2f834ec43716 (diff) | |
download | valgrind-d74d9f79b014d1f371dea044cd0bc5f6be4ba8cf.tar.gz |
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.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8704 a5019735-40e9-0310-863c-91ae7b9d1cf9
Diffstat (limited to 'callgrind')
-rw-r--r-- | callgrind/dump.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/callgrind/dump.c b/callgrind/dump.c index 6fda45964..44fb276a5 100644 --- a/callgrind/dump.c +++ b/callgrind/dump.c @@ -64,13 +64,13 @@ Int CLG_(get_dump_counter)(void) 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 @@ void CLG_(dump_profile)(Char* trigger, Bool only_current_thread) 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 @@ void init_cmdbuf(void) * <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 @@ void CLG_(init_dumps)() } if (!res.isError) VG_(close)( (Int)res.res ); - init_cmdbuf(); + if (!dumps_initialized) + init_cmdbuf(); dumps_initialized = True; } |