gdb/linux-nat.h - gdb

Data types defined

Macros defined

Source code

  1. /* Native debugging support for GNU/Linux (LWP layer).

  2.    Copyright (C) 2000-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "target.h"

  15. #include <signal.h>

  16. struct arch_lwp_info;

  17. /* Reasons an LWP last stopped.  */

  18. enum lwp_stop_reason
  19. {
  20.   /* Either not stopped, or stopped for a reason that doesn't require
  21.      special tracking.  */
  22.   LWP_STOPPED_BY_NO_REASON,

  23.   /* Stopped by a software breakpoint.  */
  24.   LWP_STOPPED_BY_SW_BREAKPOINT,

  25.   /* Stopped by a hardware breakpoint.  */
  26.   LWP_STOPPED_BY_HW_BREAKPOINT,

  27.   /* Stopped by a watchpoint.  */
  28.   LWP_STOPPED_BY_WATCHPOINT
  29. };

  30. /* Structure describing an LWP.  This is public only for the purposes
  31.    of ALL_LWPS; target-specific code should generally not access it
  32.    directly.  */

  33. struct lwp_info
  34. {
  35.   /* The process id of the LWP.  This is a combination of the LWP id
  36.      and overall process id.  */
  37.   ptid_t ptid;

  38.   /* If this flag is set, we need to set the event request flags the
  39.      next time we see this LWP stop.  */
  40.   int must_set_ptrace_flags;

  41.   /* Non-zero if this LWP is cloned.  In this context "cloned" means
  42.      that the LWP is reporting to its parent using a signal other than
  43.      SIGCHLD.  */
  44.   int cloned;

  45.   /* Non-zero if we sent this LWP a SIGSTOP (but the LWP didn't report
  46.      it back yet).  */
  47.   int signalled;

  48.   /* Non-zero if this LWP is stopped.  */
  49.   int stopped;

  50.   /* Non-zero if this LWP will be/has been resumed.  Note that an LWP
  51.      can be marked both as stopped and resumed at the same time.  This
  52.      happens if we try to resume an LWP that has a wait status
  53.      pending.  We shouldn't let the LWP run until that wait status has
  54.      been processed, but we should not report that wait status if GDB
  55.      didn't try to let the LWP run.  */
  56.   int resumed;

  57.   /* The last resume GDB requested on this thread.  */
  58.   enum resume_kind last_resume_kind;

  59.   /* If non-zero, a pending wait status.  */
  60.   int status;

  61.   /* When 'stopped' is set, this is where the lwp last stopped, with
  62.      decr_pc_after_break already accounted for.  If the LWP is
  63.      running, and stepping, this is the address at which the lwp was
  64.      resumed (that is, it's the previous stop PC).  If the LWP is
  65.      running and not stepping, this is 0.  */
  66.   CORE_ADDR stop_pc;

  67.   /* Non-zero if we were stepping this LWP.  */
  68.   int step;

  69.   /* The reason the LWP last stopped, if we need to track it
  70.      (breakpoint, watchpoint, etc.)  */
  71.   enum lwp_stop_reason stop_reason;

  72.   /* On architectures where it is possible to know the data address of
  73.      a triggered watchpoint, STOPPED_DATA_ADDRESS_P is non-zero, and
  74.      STOPPED_DATA_ADDRESS contains such data address.  Otherwise,
  75.      STOPPED_DATA_ADDRESS_P is false, and STOPPED_DATA_ADDRESS is
  76.      undefined.  Only valid if STOPPED_BY_WATCHPOINT is true.  */
  77.   int stopped_data_address_p;
  78.   CORE_ADDR stopped_data_address;

  79.   /* Non-zero if we expect a duplicated SIGINT.  */
  80.   int ignore_sigint;

  81.   /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus
  82.      for this LWP's last event.  This may correspond to STATUS above,
  83.      or to a local variable in lin_lwp_wait.  */
  84.   struct target_waitstatus waitstatus;

  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.   /* The processor core this LWP was last seen on.  */
  92.   int core;

  93.   /* Arch-specific additions.  */
  94.   struct arch_lwp_info *arch_private;

  95.   /* Next LWP in list.  */
  96.   struct lwp_info *next;
  97. };

  98. /* The global list of LWPs, for ALL_LWPS.  Unlike the threads list,
  99.    there is always at least one LWP on the list while the GNU/Linux
  100.    native target is active.  */
  101. extern struct lwp_info *lwp_list;

  102. /* Iterate over each active thread (light-weight process).  */
  103. #define ALL_LWPS(LP)                                                        \
  104.   for ((LP) = lwp_list;                                                        \
  105.        (LP) != NULL;                                                        \
  106.        (LP) = (LP)->next)

  107. /* Attempt to initialize libthread_db.  */
  108. void check_for_thread_db (void);

  109. int thread_db_attach_lwp (ptid_t ptid);

  110. /* Return the set of signals used by the threads library.  */
  111. extern void lin_thread_get_thread_signals (sigset_t *mask);

  112. /* Find process PID's pending signal set from /proc/pid/status.  */
  113. void linux_proc_pending_signals (int pid, sigset_t *pending,
  114.                                  sigset_t *blocked, sigset_t *ignored);

  115. extern int lin_lwp_attach_lwp (ptid_t ptid);

  116. extern void linux_stop_lwp (struct lwp_info *lwp);

  117. /* Iterator function for lin-lwp's lwp list.  */
  118. struct lwp_info *iterate_over_lwps (ptid_t filter,
  119.                                     int (*callback) (struct lwp_info *,
  120.                                                      void *),
  121.                                     void *data);

  122. /* Create a prototype generic GNU/Linux target.  The client can
  123.    override it with local methods.  */
  124. struct target_ops * linux_target (void);

  125. /* Create a generic GNU/Linux target using traditional
  126.    ptrace register access.  */
  127. struct target_ops *
  128. linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int));

  129. /* Register the customized GNU/Linux target.  This should be used
  130.    instead of calling add_target directly.  */
  131. void linux_nat_add_target (struct target_ops *);

  132. /* Register a method to call whenever a new thread is attached.  */
  133. void linux_nat_set_new_thread (struct target_ops *, void (*) (struct lwp_info *));


  134. /* Register a method to call whenever a new fork is attached.  */
  135. typedef void (linux_nat_new_fork_ftype) (struct lwp_info *parent,
  136.                                          pid_t child_pid);
  137. void linux_nat_set_new_fork (struct target_ops *ops,
  138.                              linux_nat_new_fork_ftype *fn);

  139. /* Register a method to call whenever a process is killed or
  140.    detached.  */
  141. typedef void (linux_nat_forget_process_ftype) (pid_t pid);
  142. void linux_nat_set_forget_process (struct target_ops *ops,
  143.                                    linux_nat_forget_process_ftype *fn);

  144. /* Call the method registered with the function above.  PID is the
  145.    process to forget about.  */
  146. void linux_nat_forget_process (pid_t pid);

  147. /* Register a method that converts a siginfo object between the layout
  148.    that ptrace returns, and the layout in the architecture of the
  149.    inferior.  */
  150. void linux_nat_set_siginfo_fixup (struct target_ops *,
  151.                                   int (*) (siginfo_t *,
  152.                                            gdb_byte *,
  153.                                            int));

  154. /* Register a method to call prior to resuming a thread.  */

  155. void linux_nat_set_prepare_to_resume (struct target_ops *,
  156.                                       void (*) (struct lwp_info *));

  157. /* Update linux-nat internal state when changing from one fork
  158.    to another.  */
  159. void linux_nat_switch_fork (ptid_t new_ptid);

  160. /* Store the saved siginfo associated with PTID in *SIGINFO.
  161.    Return 1 if it was retrieved successfully, 0 otherwise (*SIGINFO is
  162.    uninitialized in such case).  */
  163. int linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo);

  164. /* Set alternative SIGTRAP-like events recognizer.  */
  165. void linux_nat_set_status_is_event (struct target_ops *t,
  166.                                     int (*status_is_event) (int status));