#include "pub_core_xarray.h"
#include "pub_core_clientstate.h"
#include "pub_core_debuglog.h"
+#include "pub_tool_gdbserver.h" // VG_(gdbserver)
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
/* After this point, we can't recover if the execve fails. */
VG_(debugLog)(1, "syswrap", "Exec of %s\n", (Char*)ARG1);
+ // Terminate gdbserver if it is active.
+ if (VG_(clo_vgdb) != Vg_VgdbNo) {
+ // If the child will not be traced, we need to terminate gdbserver
+ // to cleanup the gdbserver resources (e.g. the FIFO files).
+ // If child will be traced, we also terminate gdbserver: the new
+ // Valgrind will start a fresh gdbserver after exec.
+ VG_(gdbserver) (0);
+ }
+
/* Resistance is futile. Nuke all other threads. POSIX mandates
this. (Really, nuke them all, since the new process will make
its own new thread.) */