aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2001-10-26 09:29:31 +0000
committerCorinna Vinschen <corinna@vinschen.de>2001-10-26 09:29:31 +0000
commit02cc9f49aed3ba8b9dc21450e567f16c5f9981fe (patch)
tree3a40c65e0ce21e9cea355c2cbe8b7f94a750c3e7
parent560ba567a08f995fe5e2d24f47b504e3aca28fa6 (diff)
downloadfsf-binutils-gdb-02cc9f49aed3ba8b9dc21450e567f16c5f9981fe.zip
fsf-binutils-gdb-02cc9f49aed3ba8b9dc21450e567f16c5f9981fe.tar.gz
fsf-binutils-gdb-02cc9f49aed3ba8b9dc21450e567f16c5f9981fe.tar.bz2
* win32-nat.c (DebugSetProcessKillOnExit): New static function
pointer to Windows' DebugSetProcessKillOnExit() function. (DebugActiveProcessStop): Ditto for DebugActiveProcessStop(). (has_detach_ability): New function. (child_attach): If system has detach ability, enable it. (child_detach): If system has detach ability, actually detach from process. Change tty output to Linux format.
-rw-r--r--gdb/ChangeLog11
-rw-r--r--gdb/win32-nat.c56
-rw-r--r--gdb/windows-nat.c56
3 files changed, 115 insertions, 8 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 66dc87a..068fd0b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2001-10-24 Corinna Vinschen <vinschen@redhat.com>
+
+ * win32-nat.c (DebugSetProcessKillOnExit): New static function
+ pointer to Windows' DebugSetProcessKillOnExit() function.
+ (DebugActiveProcessStop): Ditto for DebugActiveProcessStop().
+ (has_detach_ability): New function.
+ (child_attach): If system has detach ability, enable it.
+ (child_detach): If system has detach ability, actually
+ detach from process.
+ Change tty output to Linux format.
+
2001-10-23 Jim Blandy <jimb@redhat.com>
Isolate STABS readers' use of the `textlow' and `texthigh' fields
diff --git a/gdb/win32-nat.c b/gdb/win32-nat.c
index fab5d03..0e2fb5d 100644
--- a/gdb/win32-nat.c
+++ b/gdb/win32-nat.c
@@ -1022,8 +1022,36 @@ do_initial_child_stuff (DWORD pid)
return;
}
-/* Attach to process PID, then initialize for debugging it. */
+/* Since Windows XP, detaching from a process is supported by Windows.
+ The following code tries loading the appropriate functions dynamically.
+ If loading these functions succeeds use them to actually detach from
+ the inferior process, otherwise behave as usual, pretending that
+ detach has worked. */
+static BOOL WINAPI (*DebugSetProcessKillOnExit)(BOOL);
+static BOOL WINAPI (*DebugActiveProcessStop)(DWORD);
+
+static int
+has_detach_ability ()
+{
+ static HMODULE kernel32 = NULL;
+
+ if (!kernel32)
+ kernel32 = LoadLibrary ("kernel32.dll");
+ if (kernel32)
+ {
+ if (!DebugSetProcessKillOnExit)
+ DebugSetProcessKillOnExit = GetProcAddress (kernel32,
+ "DebugSetProcessKillOnExit");
+ if (!DebugActiveProcessStop)
+ DebugActiveProcessStop = GetProcAddress (kernel32,
+ "DebugActiveProcessStop");
+ if (DebugSetProcessKillOnExit && DebugActiveProcessStop)
+ return 1;
+ }
+ return 0;
+}
+/* Attach to process PID, then initialize for debugging it. */
static void
child_attach (char *args, int from_tty)
{
@@ -1039,6 +1067,12 @@ child_attach (char *args, int from_tty)
if (!ok)
error ("Can't attach to process.");
+ if (has_detach_ability ())
+ {
+ attach_flag = 1;
+ DebugSetProcessKillOnExit (FALSE);
+ }
+
if (from_tty)
{
char *exec_file = (char *) get_exec_file (0);
@@ -1060,13 +1094,27 @@ child_attach (char *args, int from_tty)
static void
child_detach (char *args ATTRIBUTE_UNUSED, int from_tty)
{
- if (from_tty)
+ int detached = 1;
+
+ if (has_detach_ability ())
+ {
+ delete_command (NULL, 0);
+ child_continue (DBG_CONTINUE, -1);
+ if (!DebugActiveProcessStop (current_event.dwProcessId))
+ {
+ error ("Can't detach process %lu (error %lu)",
+ current_event.dwProcessId, GetLastError ());
+ detached = 0;
+ }
+ DebugSetProcessKillOnExit (FALSE);
+ }
+ if (detached && from_tty)
{
char *exec_file = get_exec_file (0);
if (exec_file == 0)
exec_file = "";
- printf_unfiltered ("Detaching from program: %s %s\n", exec_file,
- target_pid_to_str (inferior_ptid));
+ printf_unfiltered ("Detaching from program: %s, Pid %lu\n", exec_file,
+ current_event.dwProcessId);
gdb_flush (gdb_stdout);
}
inferior_ptid = null_ptid;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index fab5d03..0e2fb5d 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1022,8 +1022,36 @@ do_initial_child_stuff (DWORD pid)
return;
}
-/* Attach to process PID, then initialize for debugging it. */
+/* Since Windows XP, detaching from a process is supported by Windows.
+ The following code tries loading the appropriate functions dynamically.
+ If loading these functions succeeds use them to actually detach from
+ the inferior process, otherwise behave as usual, pretending that
+ detach has worked. */
+static BOOL WINAPI (*DebugSetProcessKillOnExit)(BOOL);
+static BOOL WINAPI (*DebugActiveProcessStop)(DWORD);
+
+static int
+has_detach_ability ()
+{
+ static HMODULE kernel32 = NULL;
+
+ if (!kernel32)
+ kernel32 = LoadLibrary ("kernel32.dll");
+ if (kernel32)
+ {
+ if (!DebugSetProcessKillOnExit)
+ DebugSetProcessKillOnExit = GetProcAddress (kernel32,
+ "DebugSetProcessKillOnExit");
+ if (!DebugActiveProcessStop)
+ DebugActiveProcessStop = GetProcAddress (kernel32,
+ "DebugActiveProcessStop");
+ if (DebugSetProcessKillOnExit && DebugActiveProcessStop)
+ return 1;
+ }
+ return 0;
+}
+/* Attach to process PID, then initialize for debugging it. */
static void
child_attach (char *args, int from_tty)
{
@@ -1039,6 +1067,12 @@ child_attach (char *args, int from_tty)
if (!ok)
error ("Can't attach to process.");
+ if (has_detach_ability ())
+ {
+ attach_flag = 1;
+ DebugSetProcessKillOnExit (FALSE);
+ }
+
if (from_tty)
{
char *exec_file = (char *) get_exec_file (0);
@@ -1060,13 +1094,27 @@ child_attach (char *args, int from_tty)
static void
child_detach (char *args ATTRIBUTE_UNUSED, int from_tty)
{
- if (from_tty)
+ int detached = 1;
+
+ if (has_detach_ability ())
+ {
+ delete_command (NULL, 0);
+ child_continue (DBG_CONTINUE, -1);
+ if (!DebugActiveProcessStop (current_event.dwProcessId))
+ {
+ error ("Can't detach process %lu (error %lu)",
+ current_event.dwProcessId, GetLastError ());
+ detached = 0;
+ }
+ DebugSetProcessKillOnExit (FALSE);
+ }
+ if (detached && from_tty)
{
char *exec_file = get_exec_file (0);
if (exec_file == 0)
exec_file = "";
- printf_unfiltered ("Detaching from program: %s %s\n", exec_file,
- target_pid_to_str (inferior_ptid));
+ printf_unfiltered ("Detaching from program: %s, Pid %lu\n", exec_file,
+ current_event.dwProcessId);
gdb_flush (gdb_stdout);
}
inferior_ptid = null_ptid;