]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Remove hardwired /tmp directory in vgdb. Honour VG_TMPDIR
authorFlorian Krohm <florian@eich-krohm.de>
Thu, 29 Sep 2011 03:03:45 +0000 (03:03 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Thu, 29 Sep 2011 03:03:45 +0000 (03:03 +0000)
and TMPDIR which was introduced when fixing bugzilla #267020.
Factor out VG_(tmpdir). New function VG_(vgdb_path_prefix).
Partially fixes bugzilla #280757.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12063

coregrind/m_gdbserver/remote-utils.c
coregrind/m_libcfile.c
coregrind/m_main.c
coregrind/m_options.c
coregrind/pub_core_gdbserver.h
coregrind/pub_core_libcfile.h
coregrind/pub_core_options.h
coregrind/vgdb.c

index 022049c31833515922fa3cb2c94931691613d47e..69f6aed922e80346bea4c8c25f3f90e12809384e 100644 (file)
@@ -228,7 +228,7 @@ void remote_open (char *name)
        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 @@ int decode_X_packet (char *from, int packet_len, CORE_ADDR *mem_addr_ptr,
    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;
+}
index d5b425dff502d42a51d409d54f4c8d60b12cabe5..0b8ab414372a2241ab0fca34bcac2a1e779429d1 100644 (file)
@@ -601,6 +601,18 @@ SysRes VG_(pread) ( Int fd, void* buf, Int count, OffT offset )
 #  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 @@ Int VG_(mkstemp) ( HChar* part_of_name, /*OUT*/HChar* fullname )
    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) {
index ca82eb473b5ca7a69d556893a7f26aea2cdf3caf..49b2daf0ce4c5ce300f1072f204c60da6852eb9c 100644 (file)
@@ -671,6 +671,10 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd,
 
    /* 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
index abc5b2da0fc6654bd7c69ae0b2bbc473c18673d8..7ae9a7a2b94d2f0c4b9cf5cae48d12fba23bb9c4 100644 (file)
@@ -54,7 +54,7 @@ VgVgdb VG_(clo_vgdb)           = Vg_VgdbYes;
 #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;
index a001cc6c09a08ecfa1711754032200ebb1e7776f..481162c5c6fb95183bd672e212566b5ef68a21ec 100644 (file)
@@ -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
index 9cfaab20d51559a792924459c2c250dc4923b229..9a5bc5477b7cb9796d4371d653b5e1ff2ad2c4b3 100644 (file)
@@ -90,6 +90,9 @@ extern SysRes VG_(pread) ( Int fd, void* buf, Int count, OffT offset );
    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
index 7706d8ee1928e9f37e22239396d347039eead1c3..9b06a59d6b52ab14365c499802372054d77edf4e 100644 (file)
@@ -69,11 +69,10 @@ extern VgVgdb VG_(clo_vgdb);
 /* 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);
index 46e7b6811c00b387d161e5f5861b9f33d209ed00..f0a66e1c494a4d12e6710e782a16376762700dcd 100644 (file)
@@ -46,6 +46,7 @@ int main (int argc, char** argv)
 #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 @@ static struct timeval dbgtv;
                             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 @@ void *vrealloc(void *ptr,size_t size)
    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 @@ void parse_options(int argc, char** argv,
       }
    }
 
+   if (vgdb_prefix == NULL)
+      vgdb_prefix = vgdb_prefix_default();
+
    if (isatty(0) 
        && !show_shared_mem 
        && !show_list