]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-attach-fail-reasons-1of5.patch
- updated (performance fixes).
[packages/gdb.git] / gdb-attach-fail-reasons-1of5.patch
CommitLineData
f412e1b4
PS
1http://sourceware.org/ml/gdb-cvs/2012-02/msg00180.html
2
3### src/gdb/gdbserver/ChangeLog 2012/02/25 19:54:50 1.556
4### src/gdb/gdbserver/ChangeLog 2012/02/27 16:19:19 1.557
5## -1,3 +1,9 @@
6+2012-02-27 Pedro Alves <palves@redhat.com>
7+
8+ PR server/9684
9+ * linux-low.c (pid_is_stopped): New.
10+ (linux_attach_lwp_1): Handle attaching to 'T (stopped)' processes.
11+
12 2012-02-25 Luis Machado <lgustavo@codesourcery.com>
13
14 * mem-break.c (clear_gdb_breakpoint_conditions): Fix de-allocation
15--- src/gdb/gdbserver/linux-low.c 2012/02/24 15:15:56 1.193
16+++ src/gdb/gdbserver/linux-low.c 2012/02/27 16:19:19 1.194
17@@ -598,6 +598,37 @@
18 return pid;
19 }
20
21+/* Detect `T (stopped)' in `/proc/PID/status'.
22+ Other states including `T (tracing stop)' are reported as false. */
23+
24+static int
25+pid_is_stopped (pid_t pid)
26+{
27+ FILE *status_file;
28+ char buf[100];
29+ int retval = 0;
30+
31+ snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid);
32+ status_file = fopen (buf, "r");
33+ if (status_file != NULL)
34+ {
35+ int have_state = 0;
36+
37+ while (fgets (buf, sizeof (buf), status_file))
38+ {
39+ if (strncmp (buf, "State:", 6) == 0)
40+ {
41+ have_state = 1;
42+ break;
43+ }
44+ }
45+ if (have_state && strstr (buf, "T (stopped)") != NULL)
46+ retval = 1;
47+ fclose (status_file);
48+ }
49+ return retval;
50+}
51+
52 /* Attach to an inferior process. */
53
54 static void
55@@ -643,6 +674,33 @@
56 ptrace call on this LWP. */
57 new_lwp->must_set_ptrace_flags = 1;
58
59+ if (pid_is_stopped (lwpid))
60+ {
61+ if (debug_threads)
62+ fprintf (stderr,
63+ "Attached to a stopped process\n");
64+
65+ /* The process is definitely stopped. It is in a job control
66+ stop, unless the kernel predates the TASK_STOPPED /
67+ TASK_TRACED distinction, in which case it might be in a
68+ ptrace stop. Make sure it is in a ptrace stop; from there we
69+ can kill it, signal it, et cetera.
70+
71+ First make sure there is a pending SIGSTOP. Since we are
72+ already attached, the process can not transition from stopped
73+ to running without a PTRACE_CONT; so we know this signal will
74+ go into the queue. The SIGSTOP generated by PTRACE_ATTACH is
75+ probably already in the queue (unless this kernel is old
76+ enough to use TASK_STOPPED for ptrace stops); but since
77+ SIGSTOP is not an RT signal, it can only be queued once. */
78+ kill_lwp (lwpid, SIGSTOP);
79+
80+ /* Finally, resume the stopped process. This will deliver the
81+ SIGSTOP (or a higher priority signal, just like normal
82+ PTRACE_ATTACH), which we'll catch later on. */
83+ ptrace (PTRACE_CONT, lwpid, 0, 0);
84+ }
85+
86 /* The next time we wait for this LWP we'll see a SIGSTOP as PTRACE_ATTACH
87 brings it to a halt.
88
This page took 0.050102 seconds and 4 git commands to generate.