Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2011-09-15 20:49:51 +0400
committerJon TURNEY <jon.turney@dronecode.org.uk>2011-09-15 20:49:51 +0400
commit02a7f96ef75f02f81125fe92b989cf9deeab462e (patch)
tree8e8ed9ac9b52c60d7d8d54bb82e28041577bf443
parentc9925bf4973dfa744fa86e5e1ff6b591e4d3f655 (diff)
* strace.cc (attach_process): Try to turn off DEBUG_ONLY_THIS_PROCESS
if Attaching to a process with the trace-children flag set. (handle_output_debug_string): Apparently we don't need to explicitly attach for debugging when a child process starts * Makefile.in (strace.exe): Link with ntdll
-rw-r--r--winsup/utils/ChangeLog8
-rw-r--r--winsup/utils/Makefile.in1
-rw-r--r--winsup/utils/strace.cc24
3 files changed, 30 insertions, 3 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 3ff2fd7b7..9c2328b14 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,11 @@
+2011-09-12 Jon TURNEY <jon.turney@dronecode.org.uk>
+
+ * strace.cc (attach_process): Try to turn off DEBUG_ONLY_THIS_PROCESS
+ if Attaching to a process with the trace-children flag set.
+ (handle_output_debug_string): Apparently we don't need to explicitly
+ attach for debugging when a child process starts
+ * Makefile.in (strace.exe): Link with ntdll
+
2011-08-21 Christopher Faylor <me.cygwin2011@cgf.cx>
* Makefile.in: Check for header file existence when building dumper.exe
diff --git a/winsup/utils/Makefile.in b/winsup/utils/Makefile.in
index dbdb16751..50e4396e2 100644
--- a/winsup/utils/Makefile.in
+++ b/winsup/utils/Makefile.in
@@ -78,6 +78,7 @@ cygcheck.exe: MINGW_LDFLAGS += -lntdll
cygpath.exe: ALL_LDFLAGS += -lcygwin -lntdll
cygpath.exe: CXXFLAGS += -fno-threadsafe-statics
ps.exe: ALL_LDFLAGS += -lcygwin -lntdll
+strace.exe: MINGW_LDFLAGS += -lntdll
ldd.exe: ALL_LDFLAGS += -lpsapi
diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc
index 2eb3b82db..0c06d0b0f 100644
--- a/winsup/utils/strace.cc
+++ b/winsup/utils/strace.cc
@@ -27,6 +27,7 @@ details. */
#include "path.h"
#undef cygwin_internal
#include "loadlib.h"
+#include "ddk/ntapi.h"
/* we *know* we're being built with GCC */
#define alloca __builtin_alloca
@@ -293,6 +294,9 @@ load_cygwin ()
return 1;
}
+#define DEBUG_PROCESS_DETACH_ON_EXIT 0x00000001
+#define DEBUG_PROCESS_ONLY_THIS_PROCESS 0x00000002
+
static void
attach_process (pid_t pid)
{
@@ -303,6 +307,23 @@ attach_process (pid_t pid)
if (!DebugActiveProcess (child_pid))
error (0, "couldn't attach to pid %d for debugging", child_pid);
+ if (forkdebug)
+ {
+ HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, child_pid);
+
+ if (h)
+ {
+ /* Try to turn off DEBUG_ONLY_THIS_PROCESS so we can follow forks */
+ /* This is only supported on XP and later */
+ ULONG DebugFlags = DEBUG_PROCESS_DETACH_ON_EXIT;
+ NTSTATUS status = NtSetInformationProcess(h, ProcessDebugFlags, &DebugFlags, sizeof(DebugFlags));
+ if (status)
+ warn (0, "Could not clear DEBUG_ONLY_THIS_PROCESS (%x), will not trace child processes", status);
+
+ CloseHandle(h);
+ }
+ }
+
return;
}
@@ -467,9 +488,6 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile)
if (special == _STRACE_CHILD_PID)
{
- if (!DebugActiveProcess (n))
- error (0, "couldn't attach to subprocess %d for debugging, "
- "windows error %d", n, GetLastError ());
return;
}