1 |
330 |
jeremybenn |
/* Native debugging support for GNU/Linux (LWP layer).
|
2 |
|
|
|
3 |
|
|
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
4 |
|
|
2010 Free Software Foundation, Inc.
|
5 |
|
|
|
6 |
|
|
This file is part of GDB.
|
7 |
|
|
|
8 |
|
|
This program is free software; you can redistribute it and/or modify
|
9 |
|
|
it under the terms of the GNU General Public License as published by
|
10 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
11 |
|
|
(at your option) any later version.
|
12 |
|
|
|
13 |
|
|
This program is distributed in the hope that it will be useful,
|
14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
GNU General Public License for more details.
|
17 |
|
|
|
18 |
|
|
You should have received a copy of the GNU General Public License
|
19 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
20 |
|
|
|
21 |
|
|
#include "target.h"
|
22 |
|
|
|
23 |
|
|
#include <signal.h>
|
24 |
|
|
|
25 |
|
|
/* Structure describing an LWP. This is public only for the purposes
|
26 |
|
|
of ALL_LWPS; target-specific code should generally not access it
|
27 |
|
|
directly. */
|
28 |
|
|
|
29 |
|
|
struct lwp_info
|
30 |
|
|
{
|
31 |
|
|
/* The process id of the LWP. This is a combination of the LWP id
|
32 |
|
|
and overall process id. */
|
33 |
|
|
ptid_t ptid;
|
34 |
|
|
|
35 |
|
|
/* Non-zero if this LWP is cloned. In this context "cloned" means
|
36 |
|
|
that the LWP is reporting to its parent using a signal other than
|
37 |
|
|
SIGCHLD. */
|
38 |
|
|
int cloned;
|
39 |
|
|
|
40 |
|
|
/* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
|
41 |
|
|
it back yet). */
|
42 |
|
|
int signalled;
|
43 |
|
|
|
44 |
|
|
/* Non-zero if this LWP is stopped. */
|
45 |
|
|
int stopped;
|
46 |
|
|
|
47 |
|
|
/* Non-zero if this LWP will be/has been resumed. Note that an LWP
|
48 |
|
|
can be marked both as stopped and resumed at the same time. This
|
49 |
|
|
happens if we try to resume an LWP that has a wait status
|
50 |
|
|
pending. We shouldn't let the LWP run until that wait status has
|
51 |
|
|
been processed, but we should not report that wait status if GDB
|
52 |
|
|
didn't try to let the LWP run. */
|
53 |
|
|
int resumed;
|
54 |
|
|
|
55 |
|
|
/* If non-zero, a pending wait status. */
|
56 |
|
|
int status;
|
57 |
|
|
|
58 |
|
|
/* Non-zero if we were stepping this LWP. */
|
59 |
|
|
int step;
|
60 |
|
|
|
61 |
|
|
/* Non-zero si_signo if this LWP stopped with a trap. si_addr may
|
62 |
|
|
be the address of a hardware watchpoint. */
|
63 |
|
|
struct siginfo siginfo;
|
64 |
|
|
|
65 |
|
|
/* STOPPED_BY_WATCHPOINT is non-zero if this LWP stopped with a data
|
66 |
|
|
watchpoint trap. */
|
67 |
|
|
int stopped_by_watchpoint;
|
68 |
|
|
|
69 |
|
|
/* On architectures where it is possible to know the data address of
|
70 |
|
|
a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
|
71 |
|
|
STOPPED_DATA_ADDRESS contains such data address. Otherwise,
|
72 |
|
|
STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
|
73 |
|
|
undefined. Only valid if STOPPED_BY_WATCHPOINT is true. */
|
74 |
|
|
int stopped_data_address_p;
|
75 |
|
|
CORE_ADDR stopped_data_address;
|
76 |
|
|
|
77 |
|
|
/* Non-zero if we expect a duplicated SIGINT. */
|
78 |
|
|
int ignore_sigint;
|
79 |
|
|
|
80 |
|
|
/* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus
|
81 |
|
|
for this LWP's last event. This may correspond to STATUS above,
|
82 |
|
|
or to a local variable in lin_lwp_wait. */
|
83 |
|
|
struct target_waitstatus waitstatus;
|
84 |
|
|
|
85 |
|
|
/* Signal wether we are in a SYSCALL_ENTRY or
|
86 |
|
|
in a SYSCALL_RETURN event.
|
87 |
|
|
Values:
|
88 |
|
|
- TARGET_WAITKIND_SYSCALL_ENTRY
|
89 |
|
|
- TARGET_WAITKIND_SYSCALL_RETURN */
|
90 |
|
|
int syscall_state;
|
91 |
|
|
|
92 |
|
|
/* The processor core this LWP was last seen on. */
|
93 |
|
|
int core;
|
94 |
|
|
|
95 |
|
|
/* Next LWP in list. */
|
96 |
|
|
struct lwp_info *next;
|
97 |
|
|
};
|
98 |
|
|
|
99 |
|
|
/* The global list of LWPs, for ALL_LWPS. Unlike the threads list,
|
100 |
|
|
there is always at least one LWP on the list while the GNU/Linux
|
101 |
|
|
native target is active. */
|
102 |
|
|
extern struct lwp_info *lwp_list;
|
103 |
|
|
|
104 |
|
|
/* Iterate over the PTID each active thread (light-weight process). There
|
105 |
|
|
must be at least one. */
|
106 |
|
|
#define ALL_LWPS(LP, PTID) \
|
107 |
|
|
for ((LP) = lwp_list, (PTID) = (LP)->ptid; \
|
108 |
|
|
(LP) != NULL; \
|
109 |
|
|
(LP) = (LP)->next, (PTID) = (LP) ? (LP)->ptid : (PTID))
|
110 |
|
|
|
111 |
|
|
#define GET_LWP(ptid) ptid_get_lwp (ptid)
|
112 |
|
|
#define GET_PID(ptid) ptid_get_pid (ptid)
|
113 |
|
|
#define is_lwp(ptid) (GET_LWP (ptid) != 0)
|
114 |
|
|
#define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
|
115 |
|
|
|
116 |
|
|
/* Attempt to initialize libthread_db. */
|
117 |
|
|
void check_for_thread_db (void);
|
118 |
|
|
|
119 |
|
|
int thread_db_attach_lwp (ptid_t ptid);
|
120 |
|
|
|
121 |
|
|
/* Return the set of signals used by the threads library. */
|
122 |
|
|
extern void lin_thread_get_thread_signals (sigset_t *mask);
|
123 |
|
|
|
124 |
|
|
/* Find process PID's pending signal set from /proc/pid/status. */
|
125 |
|
|
void linux_proc_pending_signals (int pid, sigset_t *pending, sigset_t *blocked, sigset_t *ignored);
|
126 |
|
|
|
127 |
|
|
/* Return the TGID of LWPID from /proc/pid/status. Returns -1 if not
|
128 |
|
|
found. */
|
129 |
|
|
extern int linux_proc_get_tgid (int lwpid);
|
130 |
|
|
|
131 |
|
|
/* linux-nat functions for handling fork events. */
|
132 |
|
|
extern void linux_enable_event_reporting (ptid_t ptid);
|
133 |
|
|
|
134 |
|
|
extern int lin_lwp_attach_lwp (ptid_t ptid);
|
135 |
|
|
|
136 |
|
|
/* Iterator function for lin-lwp's lwp list. */
|
137 |
|
|
struct lwp_info *iterate_over_lwps (ptid_t filter,
|
138 |
|
|
int (*callback) (struct lwp_info *,
|
139 |
|
|
void *),
|
140 |
|
|
void *data);
|
141 |
|
|
|
142 |
|
|
/* Create a prototype generic GNU/Linux target. The client can
|
143 |
|
|
override it with local methods. */
|
144 |
|
|
struct target_ops * linux_target (void);
|
145 |
|
|
|
146 |
|
|
/* Create a generic GNU/Linux target using traditional
|
147 |
|
|
ptrace register access. */
|
148 |
|
|
struct target_ops *
|
149 |
|
|
linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int));
|
150 |
|
|
|
151 |
|
|
/* Register the customized GNU/Linux target. This should be used
|
152 |
|
|
instead of calling add_target directly. */
|
153 |
|
|
void linux_nat_add_target (struct target_ops *);
|
154 |
|
|
|
155 |
|
|
/* Register a method to call whenever a new thread is attached. */
|
156 |
|
|
void linux_nat_set_new_thread (struct target_ops *, void (*) (ptid_t));
|
157 |
|
|
|
158 |
|
|
/* Register a method that converts a siginfo object between the layout
|
159 |
|
|
that ptrace returns, and the layout in the architecture of the
|
160 |
|
|
inferior. */
|
161 |
|
|
void linux_nat_set_siginfo_fixup (struct target_ops *,
|
162 |
|
|
int (*) (struct siginfo *,
|
163 |
|
|
gdb_byte *,
|
164 |
|
|
int));
|
165 |
|
|
|
166 |
|
|
/* Update linux-nat internal state when changing from one fork
|
167 |
|
|
to another. */
|
168 |
|
|
void linux_nat_switch_fork (ptid_t new_ptid);
|
169 |
|
|
|
170 |
|
|
/* Return the saved siginfo associated with PTID. */
|
171 |
|
|
struct siginfo *linux_nat_get_siginfo (ptid_t ptid);
|
172 |
|
|
|
173 |
|
|
/* Compute and return the processor core of a given thread. */
|
174 |
|
|
int linux_nat_core_of_thread_1 (ptid_t ptid);
|