1 http://sourceware.org/ml/gdb-cvs/2012-02/msg00180.html
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
6 +2012-02-27 Pedro Alves <palves@redhat.com>
9 + * linux-low.c (pid_is_stopped): New.
10 + (linux_attach_lwp_1): Handle attaching to 'T (stopped)' processes.
12 2012-02-25 Luis Machado <lgustavo@codesourcery.com>
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
21 +/* Detect `T (stopped)' in `/proc/PID/status'.
22 + Other states including `T (tracing stop)' are reported as false. */
25 +pid_is_stopped (pid_t pid)
31 + snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid);
32 + status_file = fopen (buf, "r");
33 + if (status_file != NULL)
37 + while (fgets (buf, sizeof (buf), status_file))
39 + if (strncmp (buf, "State:", 6) == 0)
45 + if (have_state && strstr (buf, "T (stopped)") != NULL)
47 + fclose (status_file);
52 /* Attach to an inferior process. */
56 ptrace call on this LWP. */
57 new_lwp->must_set_ptrace_flags = 1;
59 + if (pid_is_stopped (lwpid))
63 + "Attached to a stopped process\n");
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.
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);
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);
86 /* The next time we wait for this LWP we'll see a SIGSTOP as PTRACE_ATTACH