A detach patch for gdb
H.J. Lu
hjl@lucon.org
Thu Nov 19 10:29:00 GMT 1998
Hi,
Detaching a process in gdb 4.17 will go into an infinite loop if the
process is killed. You cannot even get out of gdb. Here is a patch to
fix it.
Thanks.
--
H.J. Lu (hjl@gnu.org)
--
Thu Nov 19 08:17:43 1998 H.J. Lu <hjl@gnu.org>
* infptrace.c (detach): Handle errno == ESRCH gracefully.
* target.c (print_waitstatus): New function.
(debug_to_wait): Use it.
* target.h (print_waitstatus): Add prototype.
Index: infptrace.c
===================================================================
RCS file: /home/work/cvs/gnu/gdb/gdb/infptrace.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 infptrace.c
--- infptrace.c 1998/05/29 13:57:35 1.1.1.1
+++ infptrace.c 1998/11/19 18:12:27
@@ -221,7 +221,26 @@ detach (signal)
errno = 0;
ptrace (PT_DETACH, inferior_pid, (PTRACE_ARG3_TYPE) 1, signal);
if (errno)
- perror_with_name ("ptrace");
+ {
+ if (errno == ESRCH)
+ {
+ /* When we detach from a process, it may be killed and no
+ longer exists. We should not go into an infinite loop. */
+ print_sys_errmsg ("ptrace", errno);
+
+ if (current_target.to_wait)
+ {
+ /* Let the process go. */
+ int retval;
+ struct target_waitstatus status;
+
+ retval = current_target.to_wait (inferior_pid, &status);
+ print_waitstatus (inferior_pid, &status, retval);
+ }
+ }
+ else
+ perror_with_name ("ptrace");
+ }
attach_flag = 0;
}
#endif /* ATTACH_DETACH */
Index: target.c
===================================================================
RCS file: /home/work/cvs/gnu/gdb/gdb/target.c,v
retrieving revision 1.2
diff -u -p -r1.2 target.c
--- target.c 1998/05/29 14:03:38 1.2
+++ target.c 1998/11/19 18:10:33
@@ -1696,6 +1696,17 @@ debug_to_wait (pid, status)
retval = debug_target.to_wait (pid, status);
+ print_waitstatus (pid, status, retval);
+
+ return retval;
+}
+
+void
+print_waitstatus (pid, status, retval)
+ int pid;
+ struct target_waitstatus *status;
+ int retval;
+{
fprintf_unfiltered (stderr, "target_wait (%d, status) = %d, ", pid, retval);
fprintf_unfiltered (stderr, "status->kind = ");
switch (status->kind)
@@ -1721,8 +1732,6 @@ debug_to_wait (pid, status)
fprintf_unfiltered (stderr, "unknown???\n");
break;
}
-
- return retval;
}
static void
Index: target.h
===================================================================
RCS file: /home/work/cvs/gnu/gdb/gdb/target.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 target.h
--- target.h 1998/05/29 13:57:38 1.1.1.1
+++ target.h 1998/11/19 18:10:51
@@ -770,8 +770,10 @@ extern asection *target_memory_bfd_secti
/* Functions for helping to write a native target. */
-/* This is for native targets which use a unix/POSIX-style waitstatus. */
+/* These are for native targets which use a unix/POSIX-style waitstatus. */
extern void store_waitstatus PARAMS ((struct target_waitstatus *, int));
+extern void print_waitstatus PARAMS ((int, struct target_waitstatus *,
+ int));
/* Convert between host signal numbers and enum target_signal's. */
extern enum target_signal target_signal_from_host PARAMS ((int));
More information about the Gdb
mailing list