Fix crash with empty Rust enum
[external/binutils.git] / gdb / linux-nat.h
1 /* Native debugging support for GNU/Linux (LWP layer).
2
3    Copyright (C) 2000-2018 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "nat/linux-nat.h"
21 #include "inf-ptrace.h"
22 #include "target.h"
23 #include <signal.h>
24
25 /* A prototype generic GNU/Linux target.  A concrete instance should
26    override it with local methods.  */
27
28 class linux_nat_target : public inf_ptrace_target
29 {
30 public:
31   linux_nat_target ();
32   ~linux_nat_target () override = 0;
33
34   thread_control_capabilities get_thread_control_capabilities () override
35   { return tc_schedlock; }
36
37   void create_inferior (const char *, const std::string &,
38                         char **, int) override;
39
40   void attach (const char *, int) override;
41
42   void detach (inferior *, int) override;
43
44   void resume (ptid_t, int, enum gdb_signal) override;
45
46   ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
47
48   void pass_signals (int, unsigned char *) override;
49
50   enum target_xfer_status xfer_partial (enum target_object object,
51                                         const char *annex,
52                                         gdb_byte *readbuf,
53                                         const gdb_byte *writebuf,
54                                         ULONGEST offset, ULONGEST len,
55                                         ULONGEST *xfered_len) override;
56
57   void kill () override;
58
59   void mourn_inferior () override;
60   bool thread_alive (ptid_t ptid) override;
61
62   void update_thread_list () override;
63
64   const char *pid_to_str (ptid_t) override;
65
66   const char *thread_name (struct thread_info *) override;
67
68   struct address_space *thread_address_space (ptid_t) override;
69
70   bool stopped_by_watchpoint () override;
71
72   bool stopped_data_address (CORE_ADDR *) override;
73
74   bool stopped_by_sw_breakpoint () override;
75   bool supports_stopped_by_sw_breakpoint () override;
76
77   bool stopped_by_hw_breakpoint () override;
78   bool supports_stopped_by_hw_breakpoint () override;
79
80   void thread_events (int) override;
81
82   bool can_async_p () override;
83   bool is_async_p () override;
84
85   bool supports_non_stop () override;
86   bool always_non_stop_p () override;
87
88   void async (int) override;
89
90   void close () override;
91
92   void stop (ptid_t) override;
93
94   bool supports_multi_process () override;
95
96   bool supports_disable_randomization () override;
97
98   int core_of_thread (ptid_t ptid) override;
99
100   bool filesystem_is_local () override;
101
102   int fileio_open (struct inferior *inf, const char *filename,
103                    int flags, int mode, int warn_if_slow,
104                    int *target_errno) override;
105
106   gdb::optional<std::string>
107     fileio_readlink (struct inferior *inf,
108                      const char *filename,
109                      int *target_errno) override;
110
111   int fileio_unlink (struct inferior *inf,
112                      const char *filename,
113                      int *target_errno) override;
114
115   int insert_fork_catchpoint (int) override;
116   int remove_fork_catchpoint (int) override;
117   int insert_vfork_catchpoint (int) override;
118   int remove_vfork_catchpoint (int) override;
119
120   int insert_exec_catchpoint (int) override;
121   int remove_exec_catchpoint (int) override;
122
123   int set_syscall_catchpoint (int pid, bool needed, int any_count,
124                               gdb::array_view<const int> syscall_counts) override;
125
126   char *pid_to_exec_file (int pid) override;
127
128   void post_startup_inferior (ptid_t) override;
129
130   void post_attach (int) override;
131
132   int follow_fork (int, int) override;
133
134   std::vector<static_tracepoint_marker>
135     static_tracepoint_markers_by_strid (const char *id) override;
136
137   /* Methods that are meant to overridden by the concrete
138      arch-specific target instance.  */
139
140   virtual void low_resume (ptid_t ptid, int step, enum gdb_signal sig)
141   { inf_ptrace_target::resume (ptid, step, sig); }
142
143   virtual bool low_stopped_by_watchpoint ()
144   { return false; }
145
146   virtual bool low_stopped_data_address (CORE_ADDR *addr_p)
147   { return false; }
148
149   /* The method to call, if any, when a new thread is attached.  */
150   virtual void low_new_thread (struct lwp_info *)
151   {}
152
153   /* The method to call, if any, when a thread is destroyed.  */
154   virtual void low_delete_thread (struct arch_lwp_info *lp)
155   {
156     gdb_assert (lp == NULL);
157   }
158
159   /* The method to call, if any, when a new fork is attached.  */
160   virtual void low_new_fork (struct lwp_info *parent, pid_t child_pid)
161   {}
162
163   /* The method to call, if any, when a process is no longer
164      attached.  */
165   virtual void low_forget_process (pid_t pid)
166   {}
167
168   /* Hook to call prior to resuming a thread.  */
169   virtual void low_prepare_to_resume (struct lwp_info *)
170   {}
171
172   /* Convert a ptrace/host siginfo object, into/from the siginfo in
173      the layout of the inferiors' architecture.  Returns true if any
174      conversion was done; false otherwise, in which case the caller
175      does a straight memcpy.  If DIRECTION is 1, then copy from INF to
176      PTRACE.  If DIRECTION is 0, copy from PTRACE to INF.  */
177   virtual bool low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf,
178                                   int direction)
179   { return false; }
180
181   /* SIGTRAP-like breakpoint status events recognizer.  The default
182      recognizes SIGTRAP only.  */
183   virtual bool low_status_is_event (int status);
184 };
185
186 /* The final/concrete instance.  */
187 extern linux_nat_target *linux_target;
188
189 struct arch_lwp_info;
190
191 /* Structure describing an LWP.  This is public only for the purposes
192    of ALL_LWPS; target-specific code should generally not access it
193    directly.  */
194
195 struct lwp_info
196 {
197   /* The process id of the LWP.  This is a combination of the LWP id
198      and overall process id.  */
199   ptid_t ptid;
200
201   /* If this flag is set, we need to set the event request flags the
202      next time we see this LWP stop.  */
203   int must_set_ptrace_flags;
204
205   /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
206      it back yet).  */
207   int signalled;
208
209   /* Non-zero if this LWP is stopped.  */
210   int stopped;
211
212   /* Non-zero if this LWP will be/has been resumed.  Note that an LWP
213      can be marked both as stopped and resumed at the same time.  This
214      happens if we try to resume an LWP that has a wait status
215      pending.  We shouldn't let the LWP run until that wait status has
216      been processed, but we should not report that wait status if GDB
217      didn't try to let the LWP run.  */
218   int resumed;
219
220   /* The last resume GDB requested on this thread.  */
221   enum resume_kind last_resume_kind;
222
223   /* If non-zero, a pending wait status.  */
224   int status;
225
226   /* When 'stopped' is set, this is where the lwp last stopped, with
227      decr_pc_after_break already accounted for.  If the LWP is
228      running, and stepping, this is the address at which the lwp was
229      resumed (that is, it's the previous stop PC).  If the LWP is
230      running and not stepping, this is 0.  */
231   CORE_ADDR stop_pc;
232
233   /* Non-zero if we were stepping this LWP.  */
234   int step;
235
236   /* The reason the LWP last stopped, if we need to track it
237      (breakpoint, watchpoint, etc.)  */
238   enum target_stop_reason stop_reason;
239
240   /* On architectures where it is possible to know the data address of
241      a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
242      STOPPED_DATA_ADDRESS contains such data address.  Otherwise,
243      STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
244      undefined.  Only valid if STOPPED_BY_WATCHPOINT is true.  */
245   int stopped_data_address_p;
246   CORE_ADDR stopped_data_address;
247
248   /* Non-zero if we expect a duplicated SIGINT.  */
249   int ignore_sigint;
250
251   /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus
252      for this LWP's last event.  This may correspond to STATUS above,
253      or to a local variable in lin_lwp_wait.  */
254   struct target_waitstatus waitstatus;
255
256   /* Signal whether we are in a SYSCALL_ENTRY or
257      in a SYSCALL_RETURN event.
258      Values:
259      - TARGET_WAITKIND_SYSCALL_ENTRY
260      - TARGET_WAITKIND_SYSCALL_RETURN */
261   enum target_waitkind syscall_state;
262
263   /* The processor core this LWP was last seen on.  */
264   int core;
265
266   /* Arch-specific additions.  */
267   struct arch_lwp_info *arch_private;
268
269   /* Previous and next pointers in doubly-linked list of known LWPs,
270      sorted by reverse creation order.  */
271   struct lwp_info *prev;
272   struct lwp_info *next;
273 };
274
275 /* The global list of LWPs, for ALL_LWPS.  Unlike the threads list,
276    there is always at least one LWP on the list while the GNU/Linux
277    native target is active.  */
278 extern struct lwp_info *lwp_list;
279
280 /* Does the current host support PTRACE_GETREGSET?  */
281 extern enum tribool have_ptrace_getregset;
282
283 /* Iterate over each active thread (light-weight process).  */
284 #define ALL_LWPS(LP)                                                    \
285   for ((LP) = lwp_list;                                                 \
286        (LP) != NULL;                                                    \
287        (LP) = (LP)->next)
288
289 /* Attempt to initialize libthread_db.  */
290 void check_for_thread_db (void);
291
292 /* Called from the LWP layer to inform the thread_db layer that PARENT
293    spawned CHILD.  Both LWPs are currently stopped.  This function
294    does whatever is required to have the child LWP under the
295    thread_db's control --- e.g., enabling event reporting.  Returns
296    true on success, false if the process isn't using libpthread.  */
297 extern int thread_db_notice_clone (ptid_t parent, ptid_t child);
298
299 /* Return the set of signals used by the threads library.  */
300 extern void lin_thread_get_thread_signals (sigset_t *mask);
301
302 /* Find process PID's pending signal set from /proc/pid/status.  */
303 void linux_proc_pending_signals (int pid, sigset_t *pending,
304                                  sigset_t *blocked, sigset_t *ignored);
305
306 /* For linux_stop_lwp see nat/linux-nat.h.  */
307
308 /* Stop all LWPs, synchronously.  (Any events that trigger while LWPs
309    are being stopped are left pending.)  */
310 extern void linux_stop_and_wait_all_lwps (void);
311
312 /* Set resumed LWPs running again, as they were before being stopped
313    with linux_stop_and_wait_all_lwps.  (LWPS with pending events are
314    left stopped.)  */
315 extern void linux_unstop_all_lwps (void);
316
317 /* Update linux-nat internal state when changing from one fork
318    to another.  */
319 void linux_nat_switch_fork (ptid_t new_ptid);
320
321 /* Store the saved siginfo associated with PTID in *SIGINFO.
322    Return 1 if it was retrieved successfully, 0 otherwise (*SIGINFO is
323    uninitialized in such case).  */
324 int linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);