aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/linux-procfs.c31
-rw-r--r--gdb/common/linux-procfs.h5
2 files changed, 36 insertions, 0 deletions
diff --git a/gdb/common/linux-procfs.c b/gdb/common/linux-procfs.c
index 421f36e..165383e 100644
--- a/gdb/common/linux-procfs.c
+++ b/gdb/common/linux-procfs.c
@@ -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;
+}
diff --git a/gdb/common/linux-procfs.h b/gdb/common/linux-procfs.h
index a4ba4a1..c1e5547 100644
--- a/gdb/common/linux-procfs.h
+++ b/gdb/common/linux-procfs.h
@@ -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 */