|
From: <sv...@va...> - 2011-09-29 03:08:50
|
Author: florian
Date: 2011-09-29 04:03:45 +0100 (Thu, 29 Sep 2011)
New Revision: 12063
Log:
Remove hardwired /tmp directory in vgdb. Honour VG_TMPDIR
and TMPDIR which was introduced when fixing bugzilla #267020.
Factor out VG_(tmpdir). New function VG_(vgdb_path_prefix).
Partially fixes bugzilla #280757.
Modified:
trunk/coregrind/m_gdbserver/remote-utils.c
trunk/coregrind/m_libcfile.c
trunk/coregrind/m_main.c
trunk/coregrind/m_options.c
trunk/coregrind/pub_core_gdbserver.h
trunk/coregrind/pub_core_libcfile.h
trunk/coregrind/pub_core_options.h
trunk/coregrind/vgdb.c
Modified: trunk/coregrind/m_gdbserver/remote-utils.c
===================================================================
--- trunk/coregrind/m_gdbserver/remote-utils.c 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/m_gdbserver/remote-utils.c 2011-09-29 03:03:45 UTC (rev 12063)
@@ -228,7 +228,7 @@
offsetof(ThreadState, status),
offsetof(ThreadState, os_state) + offsetof(ThreadOSstate, lwpid)};
const int pid = VG_(getpid)();
- const int name_default = strcmp(name, VG_CLO_VGDB_PREFIX_DEFAULT) == 0;
+ const int name_default = strcmp(name, VG_(vgdb_prefix_default)()) == 0;
Addr addr_shared;
SysRes o;
int shared_mem_fd = INVALID_DESCRIPTOR;
@@ -1059,3 +1059,19 @@
return 0;
}
+
+/* Return the path prefix for the named pipes (FIFOs) used by vgdb/gdb
+ to communicate with valgrind */
+HChar *
+VG_(vgdb_prefix_default)(void)
+{
+ const HChar *tmpdir;
+ HChar *prefix;
+
+ tmpdir = VG_(tmpdir)();
+ prefix = malloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1);
+ strcpy(prefix, tmpdir);
+ strcat(prefix, "/vgdb-pipe");
+
+ return prefix;
+}
Modified: trunk/coregrind/m_libcfile.c
===================================================================
--- trunk/coregrind/m_libcfile.c 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/m_libcfile.c 2011-09-29 03:03:45 UTC (rev 12063)
@@ -601,6 +601,18 @@
# endif
}
+/* Return the name of a directory for temporary files. */
+const HChar *VG_(tmpdir)(void)
+{
+ const HChar *tmpdir;
+
+ tmpdir = VG_(getenv)("TMPDIR");
+ if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR;
+ if (tmpdir == NULL || *tmpdir == '\0') tmpdir = "/tmp"; /* fallback */
+
+ return tmpdir;
+}
+
/* Create and open (-rw------) a tmp file name incorporating said arg.
Returns -1 on failure, else the fd of the file. If fullname is
non-NULL, the file's name is written into it. The number of bytes
@@ -621,9 +633,7 @@
seed = (VG_(getpid)() << 9) ^ VG_(getppid)();
/* Determine sensible location for temporary files */
- tmpdir = VG_(getenv)("TMPDIR");
- if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR;
- if (tmpdir == NULL || *tmpdir == '\0') tmpdir = "/tmp"; /* fallback */
+ tmpdir = VG_(tmpdir)();
tries = 0;
while (True) {
Modified: trunk/coregrind/m_main.c
===================================================================
--- trunk/coregrind/m_main.c 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/m_main.c 2011-09-29 03:03:45 UTC (rev 12063)
@@ -671,6 +671,10 @@
/* END command-line processing loop */
+ /* Determine the path prefix for vgdb */
+ if (VG_(clo_vgdb_prefix) == NULL)
+ VG_(clo_vgdb_prefix) = VG_(vgdb_prefix_default)();
+
/* Make VEX control parameters sane */
if (VG_(clo_vex_control).guest_chase_thresh
Modified: trunk/coregrind/m_options.c
===================================================================
--- trunk/coregrind/m_options.c 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/m_options.c 2011-09-29 03:03:45 UTC (rev 12063)
@@ -54,7 +54,7 @@
#endif
Int VG_(clo_vgdb_poll) = 5000;
Int VG_(clo_vgdb_error) = 999999999;
-Char* VG_(clo_vgdb_prefix) = VG_CLO_VGDB_PREFIX_DEFAULT;
+HChar* VG_(clo_vgdb_prefix) = NULL;
Bool VG_(clo_vgdb_shadow_registers) = False;
Bool VG_(clo_db_attach) = False;
Modified: trunk/coregrind/pub_core_gdbserver.h
===================================================================
--- trunk/coregrind/pub_core_gdbserver.h 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/pub_core_gdbserver.h 2011-09-29 03:03:45 UTC (rev 12063)
@@ -32,6 +32,9 @@
#include "pub_tool_gdbserver.h"
+/* Return the path prefix for the named pipes (FIFOs) used by vgdb/gdb
+ to communicate with valgrind */
+HChar* VG_(vgdb_prefix_default)(void);
// After a fork or after an exec, call the below to (possibly) terminate
// the previous gdbserver and then activate a new gdbserver
Modified: trunk/coregrind/pub_core_libcfile.h
===================================================================
--- trunk/coregrind/pub_core_libcfile.h 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/pub_core_libcfile.h 2011-09-29 03:03:45 UTC (rev 12063)
@@ -90,6 +90,9 @@
written is guaranteed not to exceed 64+strlen(part_of_name). */
extern Int VG_(mkstemp) ( HChar* part_of_name, /*OUT*/HChar* fullname );
+/* Return the name of a directory for temporary files. */
+extern const HChar* VG_(tmpdir)(void);
+
/* Record the process' working directory at startup. Is intended to
be called exactly once, at startup, before the working directory
changes. Return True for success, False for failure, so that the
Modified: trunk/coregrind/pub_core_options.h
===================================================================
--- trunk/coregrind/pub_core_options.h 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/pub_core_options.h 2011-09-29 03:03:45 UTC (rev 12063)
@@ -69,11 +69,10 @@
/* if > 0, checks every VG_(clo_vgdb_poll) BBS if vgdb wants to be served. */
extern Int VG_(clo_vgdb_poll);
/* prefix for the named pipes (FIFOs) used by vgdb/gdb to communicate with valgrind */
-extern Char* VG_(clo_vgdb_prefix);
+extern HChar* VG_(clo_vgdb_prefix);
/* if True, gdbserver in valgrind will expose a target description containing
shadow registers */
extern Bool VG_(clo_vgdb_shadow_registers);
-#define VG_CLO_VGDB_PREFIX_DEFAULT "/tmp/vgdb-pipe"
/* Enquire about whether to attach to a debugger at errors? default: NO */
extern Bool VG_(clo_db_attach);
Modified: trunk/coregrind/vgdb.c
===================================================================
--- trunk/coregrind/vgdb.c 2011-09-28 17:43:44 UTC (rev 12062)
+++ trunk/coregrind/vgdb.c 2011-09-29 03:03:45 UTC (rev 12063)
@@ -46,6 +46,7 @@
#include "pub_core_libcsetjmp.h"
#include "pub_core_threadstate.h"
#include "pub_core_gdbserver.h"
+#include "config.h"
#include <limits.h>
#include <unistd.h>
@@ -141,7 +142,7 @@
fflush(stderr), \
exit(1))
-static char *vgdb_prefix = "/tmp/vgdb-pipe";
+static char *vgdb_prefix = NULL;
/* Will be set to True when any condition indicating we have to shutdown
is encountered. */
@@ -178,6 +179,35 @@
return mem;
}
+/* Return the name of a directory for temporary files. */
+static
+const char *vgdb_tmpdir(void)
+{
+ const char *tmpdir;
+
+ tmpdir = getenv("TMPDIR");
+ if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR;
+ if (tmpdir == NULL || *tmpdir == '\0') tmpdir = "/tmp"; /* fallback */
+
+ return tmpdir;
+}
+
+/* Return the path prefix for the named pipes (FIFOs) used by vgdb/gdb
+ to communicate with valgrind */
+static
+char *vgdb_prefix_default(void)
+{
+ const char *tmpdir;
+ HChar *prefix;
+
+ tmpdir = vgdb_tmpdir();
+ prefix = vmalloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1);
+ strcpy(prefix, tmpdir);
+ strcat(prefix, "/vgdb-pipe");
+
+ return prefix;
+}
+
/* add nrw to the written_by_vgdb field of shared32 or shared64 */
static
void add_written(int nrw)
@@ -2264,6 +2294,9 @@
}
}
+ if (vgdb_prefix == NULL)
+ vgdb_prefix = vgdb_prefix_default();
+
if (isatty(0)
&& !show_shared_mem
&& !show_list
|