Home | History | Annotate | Line # | Download | only in gdb
linux-nat.h revision 1.3.2.1
      1      1.1  christos /* Native debugging support for GNU/Linux (LWP layer).
      2      1.1  christos 
      3      1.3  christos    Copyright (C) 2000-2015 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.3.2.1  pgoyette #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 this LWP is cloned.  In this context "cloned" means
     41      1.1  christos      that the LWP is reporting to its parent using a signal other than
     42      1.1  christos      SIGCHLD.  */
     43      1.1  christos   int cloned;
     44      1.1  christos 
     45      1.1  christos   /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
     46      1.1  christos      it back yet).  */
     47      1.1  christos   int signalled;
     48      1.1  christos 
     49      1.1  christos   /* Non-zero if this LWP is stopped.  */
     50      1.1  christos   int stopped;
     51      1.1  christos 
     52      1.1  christos   /* Non-zero if this LWP will be/has been resumed.  Note that an LWP
     53      1.1  christos      can be marked both as stopped and resumed at the same time.  This
     54      1.1  christos      happens if we try to resume an LWP that has a wait status
     55      1.1  christos      pending.  We shouldn't let the LWP run until that wait status has
     56      1.1  christos      been processed, but we should not report that wait status if GDB
     57      1.1  christos      didn't try to let the LWP run.  */
     58      1.1  christos   int resumed;
     59      1.1  christos 
     60      1.1  christos   /* The last resume GDB requested on this thread.  */
     61      1.1  christos   enum resume_kind last_resume_kind;
     62      1.1  christos 
     63      1.1  christos   /* If non-zero, a pending wait status.  */
     64      1.1  christos   int status;
     65      1.1  christos 
     66      1.3  christos   /* When 'stopped' is set, this is where the lwp last stopped, with
     67      1.3  christos      decr_pc_after_break already accounted for.  If the LWP is
     68      1.3  christos      running, and stepping, this is the address at which the lwp was
     69      1.3  christos      resumed (that is, it's the previous stop PC).  If the LWP is
     70      1.3  christos      running and not stepping, this is 0.  */
     71      1.3  christos   CORE_ADDR stop_pc;
     72      1.3  christos 
     73      1.1  christos   /* Non-zero if we were stepping this LWP.  */
     74      1.1  christos   int step;
     75      1.1  christos 
     76      1.3  christos   /* The reason the LWP last stopped, if we need to track it
     77      1.3  christos      (breakpoint, watchpoint, etc.)  */
     78  1.3.2.1  pgoyette   enum target_stop_reason stop_reason;
     79      1.1  christos 
     80      1.1  christos   /* On architectures where it is possible to know the data address of
     81      1.1  christos      a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
     82      1.1  christos      STOPPED_DATA_ADDRESS contains such data address.  Otherwise,
     83      1.1  christos      STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
     84      1.1  christos      undefined.  Only valid if STOPPED_BY_WATCHPOINT is true.  */
     85      1.1  christos   int stopped_data_address_p;
     86      1.1  christos   CORE_ADDR stopped_data_address;
     87      1.1  christos 
     88      1.1  christos   /* Non-zero if we expect a duplicated SIGINT.  */
     89      1.1  christos   int ignore_sigint;
     90      1.1  christos 
     91      1.1  christos   /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus
     92      1.1  christos      for this LWP's last event.  This may correspond to STATUS above,
     93      1.1  christos      or to a local variable in lin_lwp_wait.  */
     94      1.1  christos   struct target_waitstatus waitstatus;
     95      1.1  christos 
     96      1.1  christos   /* Signal wether we are in a SYSCALL_ENTRY or
     97      1.1  christos      in a SYSCALL_RETURN event.
     98      1.1  christos      Values:
     99      1.1  christos      - TARGET_WAITKIND_SYSCALL_ENTRY
    100      1.1  christos      - TARGET_WAITKIND_SYSCALL_RETURN */
    101      1.1  christos   int syscall_state;
    102      1.1  christos 
    103      1.1  christos   /* The processor core this LWP was last seen on.  */
    104      1.1  christos   int core;
    105      1.1  christos 
    106      1.1  christos   /* Arch-specific additions.  */
    107      1.1  christos   struct arch_lwp_info *arch_private;
    108      1.1  christos 
    109      1.1  christos   /* Next LWP in list.  */
    110      1.1  christos   struct lwp_info *next;
    111      1.1  christos };
    112      1.1  christos 
    113      1.1  christos /* The global list of LWPs, for ALL_LWPS.  Unlike the threads list,
    114      1.1  christos    there is always at least one LWP on the list while the GNU/Linux
    115      1.1  christos    native target is active.  */
    116      1.1  christos extern struct lwp_info *lwp_list;
    117      1.1  christos 
    118  1.3.2.1  pgoyette /* Does the current host support PTRACE_GETREGSET?  */
    119  1.3.2.1  pgoyette enum tribool { TRIBOOL_UNKNOWN = -1, TRIBOOL_FALSE = 0, TRIBOOL_TRUE = 1 };
    120  1.3.2.1  pgoyette extern enum tribool have_ptrace_getregset;
    121  1.3.2.1  pgoyette 
    122      1.1  christos /* Iterate over each active thread (light-weight process).  */
    123      1.1  christos #define ALL_LWPS(LP)							\
    124      1.1  christos   for ((LP) = lwp_list;							\
    125      1.1  christos        (LP) != NULL;							\
    126      1.1  christos        (LP) = (LP)->next)
    127      1.1  christos 
    128      1.1  christos /* Attempt to initialize libthread_db.  */
    129      1.1  christos void check_for_thread_db (void);
    130      1.1  christos 
    131  1.3.2.1  pgoyette /* Called from the LWP layer to inform the thread_db layer that PARENT
    132  1.3.2.1  pgoyette    spawned CHILD.  Both LWPs are currently stopped.  This function
    133  1.3.2.1  pgoyette    does whatever is required to have the child LWP under the
    134  1.3.2.1  pgoyette    thread_db's control --- e.g., enabling event reporting.  Returns
    135  1.3.2.1  pgoyette    true on success, false if the process isn't using libpthread.  */
    136  1.3.2.1  pgoyette extern int thread_db_notice_clone (ptid_t parent, ptid_t child);
    137      1.1  christos 
    138      1.1  christos /* Return the set of signals used by the threads library.  */
    139      1.1  christos extern void lin_thread_get_thread_signals (sigset_t *mask);
    140      1.1  christos 
    141      1.1  christos /* Find process PID's pending signal set from /proc/pid/status.  */
    142      1.1  christos void linux_proc_pending_signals (int pid, sigset_t *pending,
    143      1.1  christos 				 sigset_t *blocked, sigset_t *ignored);
    144      1.1  christos 
    145      1.1  christos extern int lin_lwp_attach_lwp (ptid_t ptid);
    146      1.1  christos 
    147  1.3.2.1  pgoyette /* For linux_stop_lwp see nat/linux-nat.h.  */
    148      1.1  christos 
    149  1.3.2.1  pgoyette /* Stop all LWPs, synchronously.  (Any events that trigger while LWPs
    150  1.3.2.1  pgoyette    are being stopped are left pending.)  */
    151  1.3.2.1  pgoyette extern void linux_stop_and_wait_all_lwps (void);
    152  1.3.2.1  pgoyette 
    153  1.3.2.1  pgoyette /* Set resumed LWPs running again, as they were before being stopped
    154  1.3.2.1  pgoyette    with linux_stop_and_wait_all_lwps.  (LWPS with pending events are
    155  1.3.2.1  pgoyette    left stopped.)  */
    156  1.3.2.1  pgoyette extern void linux_unstop_all_lwps (void);
    157      1.1  christos 
    158      1.1  christos /* Create a prototype generic GNU/Linux target.  The client can
    159      1.1  christos    override it with local methods.  */
    160      1.1  christos struct target_ops * linux_target (void);
    161      1.1  christos 
    162      1.1  christos /* Create a generic GNU/Linux target using traditional
    163      1.1  christos    ptrace register access.  */
    164      1.1  christos struct target_ops *
    165      1.1  christos linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int));
    166      1.1  christos 
    167      1.1  christos /* Register the customized GNU/Linux target.  This should be used
    168      1.1  christos    instead of calling add_target directly.  */
    169      1.1  christos void linux_nat_add_target (struct target_ops *);
    170      1.1  christos 
    171      1.1  christos /* Register a method to call whenever a new thread is attached.  */
    172      1.1  christos void linux_nat_set_new_thread (struct target_ops *, void (*) (struct lwp_info *));
    173      1.1  christos 
    174      1.1  christos 
    175      1.1  christos /* Register a method to call whenever a new fork is attached.  */
    176      1.1  christos typedef void (linux_nat_new_fork_ftype) (struct lwp_info *parent,
    177      1.1  christos 					 pid_t child_pid);
    178      1.1  christos void linux_nat_set_new_fork (struct target_ops *ops,
    179      1.1  christos 			     linux_nat_new_fork_ftype *fn);
    180      1.1  christos 
    181      1.1  christos /* Register a method to call whenever a process is killed or
    182      1.1  christos    detached.  */
    183      1.1  christos typedef void (linux_nat_forget_process_ftype) (pid_t pid);
    184      1.1  christos void linux_nat_set_forget_process (struct target_ops *ops,
    185      1.1  christos 				   linux_nat_forget_process_ftype *fn);
    186      1.1  christos 
    187      1.1  christos /* Call the method registered with the function above.  PID is the
    188      1.1  christos    process to forget about.  */
    189      1.1  christos void linux_nat_forget_process (pid_t pid);
    190      1.1  christos 
    191      1.1  christos /* Register a method that converts a siginfo object between the layout
    192      1.1  christos    that ptrace returns, and the layout in the architecture of the
    193      1.1  christos    inferior.  */
    194      1.1  christos void linux_nat_set_siginfo_fixup (struct target_ops *,
    195      1.1  christos 				  int (*) (siginfo_t *,
    196      1.1  christos 					   gdb_byte *,
    197      1.1  christos 					   int));
    198      1.1  christos 
    199      1.1  christos /* Register a method to call prior to resuming a thread.  */
    200      1.1  christos 
    201      1.1  christos void linux_nat_set_prepare_to_resume (struct target_ops *,
    202      1.1  christos 				      void (*) (struct lwp_info *));
    203      1.1  christos 
    204      1.1  christos /* Update linux-nat internal state when changing from one fork
    205      1.1  christos    to another.  */
    206      1.1  christos void linux_nat_switch_fork (ptid_t new_ptid);
    207      1.1  christos 
    208      1.1  christos /* Store the saved siginfo associated with PTID in *SIGINFO.
    209      1.1  christos    Return 1 if it was retrieved successfully, 0 otherwise (*SIGINFO is
    210      1.1  christos    uninitialized in such case).  */
    211      1.1  christos int linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);
    212      1.1  christos 
    213      1.1  christos /* Set alternative SIGTRAP-like events recognizer.  */
    214      1.1  christos void linux_nat_set_status_is_event (struct target_ops *t,
    215      1.1  christos 				    int (*status_is_event) (int status));
    216