|
From: <sv...@va...> - 2006-04-21 00:59:10
|
Author: weidendo
Date: 2006-04-21 01:58:58 +0100 (Fri, 21 Apr 2006)
New Revision: 5861
Log:
Fixes for interactive control:
- callgrind_control was not working, because it checks the
"command syntax version" to be at most 1 before doing anything.
But callgrind used Valgrinds version for this (3.2.0). Now we
define a separate version COMMAND_VERSION for the syntax format
of control and result files.
Strictly, such a version is not needed for interaction of
callgrind and the script callgrind_control itself, as they are
delivered in the same package. But there are also external
controlling tools (most notable KCachegrind)
- Some systems make it difficult for callgrind_control to
automatically detect running callgrind processes. To make
interactivity work, one has to provide the cwd with -w.
For commands expecting a result from callgrind, this result
was delivered in the wrong result file.
Modified:
trunk/callgrind/callgrind_control.in
trunk/callgrind/command.c
Modified: trunk/callgrind/callgrind_control.in
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/callgrind/callgrind_control.in 2006-04-20 14:38:50 UTC (rev 586=
0)
+++ trunk/callgrind/callgrind_control.in 2006-04-21 00:58:58 UTC (rev 586=
1)
@@ -37,7 +37,7 @@
open MAP, "<$mapfile";
$found =3D 0;
while(<MAP>) {
- # works both for VG 3.0 and VG 3.1
+ # works both for VG 3.0 and VG 3.1+
if (/callgrind/) { $found =3D 1; }
}
close MAP;
@@ -54,7 +54,7 @@
close INFO;
=20
if ($mversion{$pid} > 1) {
- #print " Unsupported Callgrind Major Version $mversion.\n\n";
+ print " $pid: Unsupported command interface (version $mversion) ?!=
\n\n";
next;
}
=20
@@ -290,12 +290,11 @@
if ($workingDir ne "") {
# Generate dummy information for dummy pid 0
$pid =3D "0";
- $mversion{$pid} =3D "@VERSION@";
+ $mversion{$pid} =3D "1.0";
$cmd{$pid} =3D "???";
$base{$pid} =3D $workingDir;
$control{$pid} =3D "$workingDir/callgrind.cmd";
- # do not wait for any result...
- $result{$pid} =3D "";
+ $result{$pid} =3D "$workingDir/callgrind.res";
=20
# Only handle this faked callgrind run
@pids =3D ($pid);
@@ -328,7 +327,7 @@
=20
foreach $pid (@pids) {
$pidstr =3D "PID $pid: ";
- print $pidstr.$cmd{$pid};
+ if ($pid >0) { print $pidstr.$cmd{$pid}; }
=20
if ($command eq "") {
if ($printLong) {
@@ -355,6 +354,7 @@
}
}
=20
+ #print "Reading ".$result{$pid}. "...\n";
if ($result{$pid} eq "") { $waitForAnswer=3D0; }
if (!$waitForAnswer) { print " OK.\n"; next; }
=20
Modified: trunk/callgrind/command.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/callgrind/command.c 2006-04-20 14:38:50 UTC (rev 5860)
+++ trunk/callgrind/command.c 2006-04-21 00:58:58 UTC (rev 5861)
@@ -34,11 +34,17 @@
=20
#include <pub_tool_threadstate.h> // VG_N_THREADS
=20
+// Version for the syntax in command/result files for interactive contro=
l
+#define COMMAND_VERSION "1.0"
+
static Char outbuf[FILENAME_LEN + FN_NAME_LEN + OBJ_NAME_LEN];
=20
static Char* command_file =3D 0;
static Char* command_file2 =3D 0;
+static Char* current_command_file =3D 0;
static Char* result_file =3D 0;
+static Char* result_file2 =3D 0;
+static Char* current_result_file =3D 0;
static Char* info_file =3D 0;
static Char* dump_base =3D 0;
=20
@@ -60,7 +66,6 @@
/* This is for compatibility with the "Force Now" Button of current
* KCachegrind releases, as it doesn't use ".pid" to distinguish
* different callgrind instances from same base directory.
- * Should be removed sometimes in the future (29.10.03)
*/
command_file2 =3D (char*) CLG_MALLOC(size);
CLG_ASSERT(command_file2 !=3D 0);
@@ -73,6 +78,14 @@
VG_(sprintf)(result_file, "%s/%s.%d",
dir, DEFAULT_RESULTNAME, VG_(getpid)());
=20
+ /* If we get a command from a command file without .pid, use
+ * a result file without .pid suffix
+ */
+ result_file2 =3D (char*) CLG_MALLOC(size);
+ CLG_ASSERT(result_file2 !=3D 0);
+ VG_(sprintf)(result_file2, "%s/%s",
+ dir, DEFAULT_RESULTNAME);
+
info_file =3D (char*) CLG_MALLOC(VG_(strlen)(DEFAULT_INFONAME) + 10);
CLG_ASSERT(info_file !=3D 0);
VG_(sprintf)(info_file, "%s.%d", DEFAULT_INFONAME, VG_(getpid)());
@@ -105,15 +118,11 @@
"# It is used to enable controlling the supervision of\n"
"# '%s'\n"
"# by external tools.\n\n",
-#if VG_CORE_INTERFACE_VERSION < 9
- VG_(client_argv[0])
-#else
VG_(args_the_exename)
-#endif
);
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
=20
- VG_(sprintf)(buf, "version: " VERSION "\n");
+ VG_(sprintf)(buf, "version: " COMMAND_VERSION "\n");
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
=20
VG_(sprintf)(buf, "base: %s\n", dir);
@@ -130,13 +139,6 @@
=20
VG_(strcpy)(buf, "cmd:");
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
-#if VG_CORE_INTERFACE_VERSION < 9
- for (i =3D 0; i < VG_(client_argc); i++) {
- if (!VG_(client_argv[i])) continue;
- VG_(sprintf)(buf, " %s", VG_(client_argv[i]));
- VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
- }
-#else
VG_(sprintf)(buf, " %s", VG_(args_the_exename));
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
for (i =3D 0; i < VG_(args_for_client).used; i++) {
@@ -144,7 +146,6 @@
VG_(sprintf)(buf, " %s", VG_(args_for_client).strs[i]);
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
}
-#endif
VG_(write)(fd, "\n", 1);
VG_(close)(fd);
}
@@ -166,7 +167,8 @@
if (fd > -2) return fd;
=20
/* fd =3D=3D -2: No error, but we need to create the file */
- res =3D VG_(open)(result_file,
+ CLG_ASSERT(current_result_file !=3D 0);
+ res =3D VG_(open)(current_result_file,
VKI_O_CREAT|VKI_O_WRONLY|VKI_O_TRUNC,
VKI_S_IRUSR|VKI_S_IWUSR);
=20
@@ -179,7 +181,7 @@
return fd;
}
=20
-/* Run Info: Fixed information for a callgrind run */
+/* Run Info: Persistant information of the callgrind run */
static Int dump_info(Int fd)
{
Char* buf =3D outbuf;
@@ -187,8 +189,12 @@
=20
if ( (fd =3D createRes(fd)) <0) return fd;
=20
+ /* creator */
+ VG_(sprintf)(buf, "creator: callgrind-" VERSION "\n");
+ VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
+
/* version */
- VG_(sprintf)(buf, "version: " VERSION "\n");
+ VG_(sprintf)(buf, "version: " COMMAND_VERSION "\n");
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
=20
/* "pid:" line */
@@ -202,13 +208,6 @@
/* "cmd:" line */
VG_(strcpy)(buf, "cmd:");
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
-#if VG_CORE_INTERFACE_VERSION < 9
- for (i =3D 0; i < VG_(client_argc); i++) {
- if (!VG_(client_argv[i])) continue;
- VG_(sprintf)(buf, " %s", VG_(client_argv[i]));
- VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
- }
-#else
VG_(sprintf)(buf, " %s", VG_(args_the_exename));
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
for (i =3D 0; i < VG_(args_for_client).used; i++) {
@@ -216,7 +215,7 @@
VG_(sprintf)(buf, " %s", VG_(args_for_client).strs[i]);
VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
}
-#endif
+ VG_(write)(fd, "\n", 1);
=20
return fd;
}
@@ -355,17 +354,17 @@
static Char cmdBuffer[512];
Char *cmdPos =3D 0, *cmdNextLine =3D 0;
Int fd, bytesRead =3D 0, do_kill =3D 0;
- static Char* cfile =3D 0;
SysRes res;
=20
if (!command_inited) return;
=20
/* toggle between 2 command files, with/without ".pid" postfix */
- cfile =3D ((cfile =3D=3D command_file) || (cfile =3D=3D 0)) ?=20
- command_file2 : command_file;
+ current_command_file =3D (current_command_file =3D=3D command_file2)=
?=20
+ command_file : command_file2;
+ current_result_file =3D (current_command_file =3D=3D command_file2)=
?
+ result_file2 : result_file; =20
=20
- =20
- res =3D VG_(open)(cfile, VKI_O_RDONLY,0);
+ res =3D VG_(open)(current_command_file, VKI_O_RDONLY,0);
if (!res.isError) {
fd =3D (Int) res.val;
bytesRead =3D VG_(read)(fd,cmdBuffer,500);
@@ -505,12 +504,12 @@
}
=20
/* If command executed, delete command file */
- if (cmdPos) VG_(unlink)(cfile);
+ if (cmdPos) VG_(unlink)(current_command_file);
if (fd>=3D0) VG_(close)(fd); =20
=20
if (do_kill) {
VG_(message)(Vg_UserMsg,
- "Killed because of command from %s", cfile);
+ "Killed because of command from %s", current_command_file);
CLG_(fini)(0);
VG_(exit)(1);
}
|