http://sourceware.org/ml/gdb-cvs/2012-02/msg00181.html ### src/gdb/ChangeLog 2012/02/24 23:48:37 1.13869 ### src/gdb/ChangeLog 2012/02/27 16:22:06 1.13870 ## -1,3 +1,13 @@ +2012-02-27 Pedro Alves + + * linux-nat.c (pid_is_stopped): Delete, moved to common/. + (linux_nat_post_attach_wait): Adjust to use + linux_proc_pid_is_stopped. + * common/linux-procfs.h (linux_proc_pid_is_stopped): Declare. + * common/linux-procfs.c (linux_proc_pid_is_stopped): New function, + based on pid_is_stopped from both linux-nat.c and + gdbserver/linux-low.c, and renamed. + 2012-02-24 Maciej W. Rozycki * remote.c (remote_watchpoint_addr_within_range): New function. --- src/gdb/linux-nat.c 2012/02/16 21:07:20 1.239 +++ src/gdb/linux-nat.c 2012/02/27 16:22:13 1.240 @@ -1356,37 +1356,6 @@ delete_lwp (lp->ptid); } -/* Detect `T (stopped)' in `/proc/PID/status'. - Other states including `T (tracing stop)' are reported as false. */ - -static int -pid_is_stopped (pid_t pid) -{ - FILE *status_file; - char buf[100]; - int retval = 0; - - snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid); - status_file = fopen (buf, "r"); - if (status_file != NULL) - { - int have_state = 0; - - while (fgets (buf, sizeof (buf), status_file)) - { - if (strncmp (buf, "State:", 6) == 0) - { - have_state = 1; - break; - } - } - if (have_state && strstr (buf, "T (stopped)") != NULL) - retval = 1; - fclose (status_file); - } - return retval; -} - /* Wait for the LWP specified by LP, which we have just attached to. Returns a wait status for that LWP, to cache. */ @@ -1397,7 +1366,7 @@ pid_t new_pid, pid = GET_LWP (ptid); int status; - if (pid_is_stopped (pid)) + if (linux_proc_pid_is_stopped (pid)) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, --- src/gdb/common/linux-procfs.c 2012/01/04 08:17:18 1.2 +++ src/gdb/common/linux-procfs.c 2012/02/27 16:22:14 1.3 @@ -53,3 +53,34 @@ return tgid; } + +/* Detect `T (stopped)' in `/proc/PID/status'. + Other states including `T (tracing stop)' are reported as false. */ + +int +linux_proc_pid_is_stopped (pid_t pid) +{ + FILE *status_file; + char buf[100]; + int retval = 0; + + snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid); + status_file = fopen (buf, "r"); + if (status_file != NULL) + { + int have_state = 0; + + while (fgets (buf, sizeof (buf), status_file)) + { + if (strncmp (buf, "State:", 6) == 0) + { + have_state = 1; + break; + } + } + if (have_state && strstr (buf, "T (stopped)") != NULL) + retval = 1; + fclose (status_file); + } + return retval; +} --- src/gdb/common/linux-procfs.h 2012/01/04 08:17:18 1.2 +++ src/gdb/common/linux-procfs.h 2012/02/27 16:22:15 1.3 @@ -26,4 +26,9 @@ extern int linux_proc_get_tgid (int lwpid); +/* Detect `T (stopped)' in `/proc/PID/status'. + Other states including `T (tracing stop)' are reported as false. */ + +extern int linux_proc_pid_is_stopped (pid_t pid); + #endif /* COMMON_LINUX_PROCFS_H */ ### src/gdb/gdbserver/ChangeLog 2012/02/27 16:19:19 1.557 ### src/gdb/gdbserver/ChangeLog 2012/02/27 16:22:15 1.558 ## -1,5 +1,10 @@ 2012-02-27 Pedro Alves + * linux-low.c (pid_is_stopped): Delete, moved to common/. + (linux_attach_lwp_1): Adjust to use linux_proc_pid_is_stopped. + +2012-02-27 Pedro Alves + PR server/9684 * linux-low.c (pid_is_stopped): New. (linux_attach_lwp_1): Handle attaching to 'T (stopped)' processes. --- src/gdb/gdbserver/linux-low.c 2012/02/27 16:19:19 1.194 +++ src/gdb/gdbserver/linux-low.c 2012/02/27 16:22:16 1.195 @@ -598,37 +598,6 @@ return pid; } -/* Detect `T (stopped)' in `/proc/PID/status'. - Other states including `T (tracing stop)' are reported as false. */ - -static int -pid_is_stopped (pid_t pid) -{ - FILE *status_file; - char buf[100]; - int retval = 0; - - snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid); - status_file = fopen (buf, "r"); - if (status_file != NULL) - { - int have_state = 0; - - while (fgets (buf, sizeof (buf), status_file)) - { - if (strncmp (buf, "State:", 6) == 0) - { - have_state = 1; - break; - } - } - if (have_state && strstr (buf, "T (stopped)") != NULL) - retval = 1; - fclose (status_file); - } - return retval; -} - /* Attach to an inferior process. */ static void @@ -674,7 +643,7 @@ ptrace call on this LWP. */ new_lwp->must_set_ptrace_flags = 1; - if (pid_is_stopped (lwpid)) + if (linux_proc_pid_is_stopped (lwpid)) { if (debug_threads) fprintf (stderr,