linux-nat.h revision 1.6 1 1.1 christos /* Native debugging support for GNU/Linux (LWP layer).
2 1.1 christos
3 1.6 christos Copyright (C) 2000-2016 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.5 christos #include "nat/linux-nat.h"
21 1.1 christos #include "target.h"
22 1.1 christos #include <signal.h>
23 1.1 christos
24 1.1 christos struct arch_lwp_info;
25 1.1 christos
26 1.1 christos /* Structure describing an LWP. This is public only for the purposes
27 1.1 christos of ALL_LWPS; target-specific code should generally not access it
28 1.1 christos directly. */
29 1.1 christos
30 1.1 christos struct lwp_info
31 1.1 christos {
32 1.1 christos /* The process id of the LWP. This is a combination of the LWP id
33 1.1 christos and overall process id. */
34 1.1 christos ptid_t ptid;
35 1.1 christos
36 1.3 christos /* If this flag is set, we need to set the event request flags the
37 1.3 christos next time we see this LWP stop. */
38 1.3 christos int must_set_ptrace_flags;
39 1.3 christos
40 1.1 christos /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
41 1.1 christos it back yet). */
42 1.1 christos int signalled;
43 1.1 christos
44 1.1 christos /* Non-zero if this LWP is stopped. */
45 1.1 christos int stopped;
46 1.1 christos
47 1.1 christos /* Non-zero if this LWP will be/has been resumed. Note that an LWP
48 1.1 christos can be marked both as stopped and resumed at the same time. This
49 1.1 christos happens if we try to resume an LWP that has a wait status
50 1.1 christos pending. We shouldn't let the LWP run until that wait status has
51 1.1 christos been processed, but we should not report that wait status if GDB
52 1.1 christos didn't try to let the LWP run. */
53 1.1 christos int resumed;
54 1.1 christos
55 1.1 christos /* The last resume GDB requested on this thread. */
56 1.1 christos enum resume_kind last_resume_kind;
57 1.1 christos
58 1.1 christos /* If non-zero, a pending wait status. */
59 1.1 christos int status;
60 1.1 christos
61 1.3 christos /* When 'stopped' is set, this is where the lwp last stopped, with
62 1.3 christos decr_pc_after_break already accounted for. If the LWP is
63 1.3 christos running, and stepping, this is the address at which the lwp was
64 1.3 christos resumed (that is, it's the previous stop PC). If the LWP is
65 1.3 christos running and not stepping, this is 0. */
66 1.3 christos CORE_ADDR stop_pc;
67 1.3 christos
68 1.1 christos /* Non-zero if we were stepping this LWP. */
69 1.1 christos int step;
70 1.1 christos
71 1.3 christos /* The reason the LWP last stopped, if we need to track it
72 1.3 christos (breakpoint, watchpoint, etc.) */
73 1.5 christos enum target_stop_reason stop_reason;
74 1.1 christos
75 1.1 christos /* On architectures where it is possible to know the data address of
76 1.1 christos a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
77 1.1 christos STOPPED_DATA_ADDRESS contains such data address. Otherwise,
78 1.1 christos STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
79 1.1 christos undefined. Only valid if STOPPED_BY_WATCHPOINT is true. */
80 1.1 christos int stopped_data_address_p;
81 1.1 christos CORE_ADDR stopped_data_address;
82 1.1 christos
83 1.1 christos /* Non-zero if we expect a duplicated SIGINT. */
84 1.1 christos int ignore_sigint;
85 1.1 christos
86 1.1 christos /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus
87 1.1 christos for this LWP's last event. This may correspond to STATUS above,
88 1.1 christos or to a local variable in lin_lwp_wait. */
89 1.1 christos struct target_waitstatus waitstatus;
90 1.1 christos
91 1.6 christos /* Signal whether we are in a SYSCALL_ENTRY or
92 1.1 christos in a SYSCALL_RETURN event.
93 1.1 christos Values:
94 1.1 christos - TARGET_WAITKIND_SYSCALL_ENTRY
95 1.1 christos - TARGET_WAITKIND_SYSCALL_RETURN */
96 1.6 christos enum target_waitkind syscall_state;
97 1.1 christos
98 1.1 christos /* The processor core this LWP was last seen on. */
99 1.1 christos int core;
100 1.1 christos
101 1.1 christos /* Arch-specific additions. */
102 1.1 christos struct arch_lwp_info *arch_private;
103 1.1 christos
104 1.6 christos /* Previous and next pointers in doubly-linked list of known LWPs,
105 1.6 christos sorted by reverse creation order. */
106 1.6 christos struct lwp_info *prev;
107 1.1 christos struct lwp_info *next;
108 1.1 christos };
109 1.1 christos
110 1.1 christos /* The global list of LWPs, for ALL_LWPS. Unlike the threads list,
111 1.1 christos there is always at least one LWP on the list while the GNU/Linux
112 1.1 christos native target is active. */
113 1.1 christos extern struct lwp_info *lwp_list;
114 1.1 christos
115 1.5 christos /* Does the current host support PTRACE_GETREGSET? */
116 1.5 christos extern enum tribool have_ptrace_getregset;
117 1.5 christos
118 1.1 christos /* Iterate over each active thread (light-weight process). */
119 1.1 christos #define ALL_LWPS(LP) \
120 1.1 christos for ((LP) = lwp_list; \
121 1.1 christos (LP) != NULL; \
122 1.1 christos (LP) = (LP)->next)
123 1.1 christos
124 1.1 christos /* Attempt to initialize libthread_db. */
125 1.1 christos void check_for_thread_db (void);
126 1.1 christos
127 1.5 christos /* Called from the LWP layer to inform the thread_db layer that PARENT
128 1.5 christos spawned CHILD. Both LWPs are currently stopped. This function
129 1.5 christos does whatever is required to have the child LWP under the
130 1.5 christos thread_db's control --- e.g., enabling event reporting. Returns
131 1.5 christos true on success, false if the process isn't using libpthread. */
132 1.5 christos extern int thread_db_notice_clone (ptid_t parent, ptid_t child);
133 1.1 christos
134 1.1 christos /* Return the set of signals used by the threads library. */
135 1.1 christos extern void lin_thread_get_thread_signals (sigset_t *mask);
136 1.1 christos
137 1.1 christos /* Find process PID's pending signal set from /proc/pid/status. */
138 1.1 christos void linux_proc_pending_signals (int pid, sigset_t *pending,
139 1.1 christos sigset_t *blocked, sigset_t *ignored);
140 1.1 christos
141 1.5 christos /* For linux_stop_lwp see nat/linux-nat.h. */
142 1.1 christos
143 1.5 christos /* Stop all LWPs, synchronously. (Any events that trigger while LWPs
144 1.5 christos are being stopped are left pending.) */
145 1.5 christos extern void linux_stop_and_wait_all_lwps (void);
146 1.5 christos
147 1.5 christos /* Set resumed LWPs running again, as they were before being stopped
148 1.5 christos with linux_stop_and_wait_all_lwps. (LWPS with pending events are
149 1.5 christos left stopped.) */
150 1.5 christos extern void linux_unstop_all_lwps (void);
151 1.1 christos
152 1.1 christos /* Create a prototype generic GNU/Linux target. The client can
153 1.1 christos override it with local methods. */
154 1.1 christos struct target_ops * linux_target (void);
155 1.1 christos
156 1.1 christos /* Create a generic GNU/Linux target using traditional
157 1.1 christos ptrace register access. */
158 1.1 christos struct target_ops *
159 1.1 christos linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int));
160 1.1 christos
161 1.1 christos /* Register the customized GNU/Linux target. This should be used
162 1.1 christos instead of calling add_target directly. */
163 1.1 christos void linux_nat_add_target (struct target_ops *);
164 1.1 christos
165 1.1 christos /* Register a method to call whenever a new thread is attached. */
166 1.1 christos void linux_nat_set_new_thread (struct target_ops *, void (*) (struct lwp_info *));
167 1.1 christos
168 1.1 christos
169 1.1 christos /* Register a method to call whenever a new fork is attached. */
170 1.1 christos typedef void (linux_nat_new_fork_ftype) (struct lwp_info *parent,
171 1.1 christos pid_t child_pid);
172 1.1 christos void linux_nat_set_new_fork (struct target_ops *ops,
173 1.1 christos linux_nat_new_fork_ftype *fn);
174 1.1 christos
175 1.1 christos /* Register a method to call whenever a process is killed or
176 1.1 christos detached. */
177 1.1 christos typedef void (linux_nat_forget_process_ftype) (pid_t pid);
178 1.1 christos void linux_nat_set_forget_process (struct target_ops *ops,
179 1.1 christos linux_nat_forget_process_ftype *fn);
180 1.1 christos
181 1.1 christos /* Call the method registered with the function above. PID is the
182 1.1 christos process to forget about. */
183 1.1 christos void linux_nat_forget_process (pid_t pid);
184 1.1 christos
185 1.1 christos /* Register a method that converts a siginfo object between the layout
186 1.1 christos that ptrace returns, and the layout in the architecture of the
187 1.1 christos inferior. */
188 1.1 christos void linux_nat_set_siginfo_fixup (struct target_ops *,
189 1.1 christos int (*) (siginfo_t *,
190 1.1 christos gdb_byte *,
191 1.1 christos int));
192 1.1 christos
193 1.1 christos /* Register a method to call prior to resuming a thread. */
194 1.1 christos
195 1.1 christos void linux_nat_set_prepare_to_resume (struct target_ops *,
196 1.1 christos void (*) (struct lwp_info *));
197 1.1 christos
198 1.1 christos /* Update linux-nat internal state when changing from one fork
199 1.1 christos to another. */
200 1.1 christos void linux_nat_switch_fork (ptid_t new_ptid);
201 1.1 christos
202 1.1 christos /* Store the saved siginfo associated with PTID in *SIGINFO.
203 1.1 christos Return 1 if it was retrieved successfully, 0 otherwise (*SIGINFO is
204 1.1 christos uninitialized in such case). */
205 1.1 christos int linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);
206 1.1 christos
207 1.1 christos /* Set alternative SIGTRAP-like events recognizer. */
208 1.1 christos void linux_nat_set_status_is_event (struct target_ops *t,
209 1.1 christos int (*status_is_event) (int status));
210