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