2012-02-27 Pedro Alves <palves@redhat.com>

gdb/gdbserver/
	* linux-low.c (pid_is_stopped): Delete, moved to common/.
	(linux_attach_lwp_1): Adjust to use linux_proc_pid_is_stopped.

	gdb/
	* 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.
This commit is contained in:
Pedro Alves
2012-02-27 16:22:16 +00:00
parent c14d7ab2b6
commit 644cebc98c
6 changed files with 53 additions and 64 deletions

View File

@ -53,3 +53,34 @@ linux_proc_get_tgid (int lwpid)
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;
}

View File

@ -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 */