From d74d9f79b014d1f371dea044cd0bc5f6be4ba8cf Mon Sep 17 00:00:00 2001 From: weidendo Date: Fri, 24 Oct 2008 18:50:00 +0000 Subject: 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 --- callgrind/dump.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'callgrind') 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) * 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; } -- cgit v1.2.3