19#include "gdbsupport/common-defs.h"
21#include "gdbsupport/filestuff.h"
31 size_t field_len = strlen (
field);
35 snprintf (buf,
sizeof (buf),
"/proc/%d/status", (
int) lwpid);
36 gdb_file_up status_file = gdb_fopen_cloexec (buf,
"r");
37 if (status_file == NULL)
40 warning (_(
"unable to open /proc file '%s'"), buf);
44 while (fgets (buf,
sizeof (buf), status_file.get ()))
45 if (strncmp (buf,
field, field_len) == 0 && buf[field_len] ==
':')
47 retval = strtol (&buf[field_len + 1], NULL, 10);
99 state = skip_spaces (state);
107 if (strcmp (state,
"T (stopped)\n") == 0)
132 xsnprintf (buffer,
sizeof (buffer),
"/proc/%d/status", (
int)
pid);
133 gdb_file_up procfile = gdb_fopen_cloexec (buffer,
"r");
134 if (procfile == NULL)
137 warning (_(
"unable to open /proc file '%s'"), buffer);
142 while (fgets (buffer,
sizeof (buffer), procfile.get ()) != NULL)
143 if (startswith (buffer,
"State:"))
167 else if (have_state == 0)
186 return (have_state > 0 && cur_state == state);
237#define TASK_COMM_LEN 16
241 const char *comm_val;
242 pid_t
pid = ptid.pid ();
243 pid_t tid = ptid.lwp_p () ? ptid.lwp () : ptid.pid ();
245 xsnprintf (comm_path,
sizeof (comm_path),
246 "/proc/%ld/task/%ld/comm", (
long)
pid, (
long) tid);
248 gdb_file_up comm_file = gdb_fopen_cloexec (comm_path,
"r");
249 if (comm_file == NULL)
252 comm_val = fgets (comm_buf,
sizeof (comm_buf), comm_file.get ());
254 if (comm_val != NULL)
259 for (i = 0; i <
sizeof (comm_buf); i++)
261 if (comm_buf[i] ==
'\n')
280 int new_threads_found;
286 xsnprintf (pathname,
sizeof (pathname),
"/proc/%ld/task", (
long)
pid);
287 dir = opendir (pathname);
290 warning (_(
"Could not open /proc/%ld/task."), (
long)
pid);
298 for (iterations = 0; iterations < 2; iterations++)
302 new_threads_found = 0;
303 while ((dp = readdir (dir)) != NULL)
308 lwp = strtoul (dp->d_name, NULL, 10);
311 ptid_t ptid = ptid_t (
pid, lwp);
313 if (attach_lwp (ptid))
314 new_threads_found = 1;
318 if (new_threads_found)
338 xsnprintf (pathname,
sizeof (pathname),
"/proc/%ld/task", (
long)
pid);
339 return (stat (pathname, &buf) == 0);
347 static char buf[PATH_MAX];
351 xsnprintf (
name, PATH_MAX,
"/proc/%d/exe",
pid);
352 len = readlink (
name, buf, PATH_MAX - 1);
366 static bool warned =
false;
374 if (stat (
"/proc/self", &st) != 0)
375 warning (_(
"/proc is not accessible."));
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
@ PROC_STATE_TRACING_STOP
int linux_proc_pid_is_gone(pid_t pid)
int linux_proc_pid_is_zombie_nowarn(pid_t pid)
const char * linux_proc_pid_to_exec_file(int pid)
static int linux_proc_pid_get_state(pid_t pid, int warn, enum proc_state *state)
static int linux_proc_get_int(pid_t lwpid, const char *field, int warn)
static enum proc_state parse_proc_status_state(const char *state)
void linux_proc_init_warnings()
int linux_proc_pid_is_trace_stopped_nowarn(pid_t pid)
int linux_proc_pid_is_zombie(pid_t pid)
void linux_proc_attach_tgid_threads(pid_t pid, linux_proc_attach_lwp_func attach_lwp)
const char * linux_proc_tid_get_name(ptid_t ptid)
int linux_proc_pid_is_stopped(pid_t pid)
static int linux_proc_pid_has_state(pid_t pid, enum proc_state state, int warn)
int linux_proc_get_tgid(pid_t lwpid)
pid_t linux_proc_get_tracerpid_nowarn(pid_t lwpid)
int linux_proc_task_list_dir_exists(pid_t pid)
static int linux_proc_pid_is_zombie_maybe_warn(pid_t pid, int warn)
int(* linux_proc_attach_lwp_func)(ptid_t ptid)