gdb/inferior.h - gdb

Global variables defined

Data types defined

Macros defined

Source code

  1. /* Variables that describe the inferior process running under GDB:
  2.    Where it is, why it stopped, and how to step it.

  3.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  4.    This file is part of GDB.

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

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

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

  15. #if !defined (INFERIOR_H)
  16. #define INFERIOR_H 1

  17. struct target_waitstatus;
  18. struct frame_info;
  19. struct ui_file;
  20. struct type;
  21. struct gdbarch;
  22. struct regcache;
  23. struct ui_out;
  24. struct terminal_info;
  25. struct target_desc_info;

  26. /* For bpstat.  */
  27. #include "breakpoint.h"

  28. /* For enum gdb_signal.  */
  29. #include "target.h"

  30. /* For struct frame_id.  */
  31. #include "frame.h"

  32. #include "progspace.h"
  33. #include "registry.h"

  34. struct infcall_suspend_state;
  35. struct infcall_control_state;

  36. extern struct infcall_suspend_state *save_infcall_suspend_state (void);
  37. extern struct infcall_control_state *save_infcall_control_state (void);

  38. extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
  39. extern void restore_infcall_control_state (struct infcall_control_state *);

  40. extern struct cleanup *make_cleanup_restore_infcall_suspend_state
  41.                                             (struct infcall_suspend_state *);
  42. extern struct cleanup *make_cleanup_restore_infcall_control_state
  43.                                             (struct infcall_control_state *);

  44. extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
  45. extern void discard_infcall_control_state (struct infcall_control_state *);

  46. extern struct regcache *
  47.   get_infcall_suspend_state_regcache (struct infcall_suspend_state *);

  48. /* Save value of inferior_ptid so that it may be restored by
  49.    a later call to do_cleanups().  Returns the struct cleanup
  50.    pointer needed for later doing the cleanup.  */
  51. extern struct cleanup * save_inferior_ptid (void);

  52. extern void set_sigint_trap (void);

  53. extern void clear_sigint_trap (void);

  54. /* Set/get file name for default use for standard in/out in the inferior.  */

  55. extern void set_inferior_io_terminal (const char *terminal_name);
  56. extern const char *get_inferior_io_terminal (void);

  57. /* Collected pid, tid, etc. of the debugged inferior.  When there's
  58.    no inferior, ptid_get_pid (inferior_ptid) will be 0.  */

  59. extern ptid_t inferior_ptid;

  60. extern void generic_mourn_inferior (void);

  61. extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
  62.                                               struct type *type,
  63.                                               const gdb_byte *buf);
  64. extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
  65.                                          struct type *type, gdb_byte *buf,
  66.                                          CORE_ADDR addr);
  67. extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
  68.                                             struct type *type,
  69.                                             const gdb_byte *buf);
  70. extern void address_to_signed_pointer (struct gdbarch *gdbarch,
  71.                                        struct type *type, gdb_byte *buf,
  72.                                        CORE_ADDR addr);

  73. extern void reopen_exec_file (void);

  74. /* From misc files */

  75. extern void default_print_registers_info (struct gdbarch *gdbarch,
  76.                                           struct ui_file *file,
  77.                                           struct frame_info *frame,
  78.                                           int regnum, int all);

  79. /* Default implementation of gdbarch_print_float_info.  Print
  80.    the values of all floating point registers.  */

  81. extern void default_print_float_info (struct gdbarch *gdbarch,
  82.                                       struct ui_file *file,
  83.                                       struct frame_info *frame,
  84.                                       const char *args);

  85. extern void child_terminal_info (struct target_ops *self, const char *, int);

  86. extern void term_info (char *, int);

  87. extern void child_terminal_ours (struct target_ops *self);

  88. extern void child_terminal_ours_for_output (struct target_ops *self);

  89. extern void child_terminal_inferior (struct target_ops *self);

  90. extern void child_terminal_init (struct target_ops *self);

  91. extern void child_terminal_init_with_pgrp (int pgrp);

  92. /* From fork-child.c */

  93. extern int fork_inferior (char *, char *, char **,
  94.                           void (*)(void),
  95.                           void (*)(int), void (*)(void), char *,
  96.                           void (*)(const char *,
  97.                                    char * const *, char * const *));


  98. extern void startup_inferior (int);

  99. extern char *construct_inferior_arguments (int, char **);

  100. /* From infcmd.c */

  101. extern void post_create_inferior (struct target_ops *, int);

  102. extern void attach_command (char *, int);

  103. extern char *get_inferior_args (void);

  104. extern void set_inferior_args (char *);

  105. extern void set_inferior_args_vector (int, char **);

  106. extern void registers_info (char *, int);

  107. extern void continue_1 (int all_threads);

  108. extern void interrupt_target_1 (int all_threads);

  109. extern void delete_longjmp_breakpoint_cleanup (void *arg);

  110. extern void detach_command (char *, int);

  111. extern void notice_new_inferior (ptid_t, int, int);

  112. extern struct value *get_return_value (struct value *function,
  113.                                        struct type *value_type);

  114. /* Prepare for execution command.  TARGET is the target that will run
  115.    the command.  BACKGROUND determines whether this is a foreground
  116.    (synchronous) or background (asynchronous) command.  */

  117. extern void prepare_execution_command (struct target_ops *target,
  118.                                        int background);

  119. /* Whether to start up the debuggee under a shell.

  120.    If startup-with-shell is set, GDB's "run" will attempt to start up
  121.    the debuggee under a shell.

  122.    This is in order for argument-expansion to occur.  E.g.,

  123.    (gdb) run *

  124.    The "*" gets expanded by the shell into a list of files.

  125.    While this is a nice feature, it may be handy to bypass the shell
  126.    in some cases.  To disable this feature, do "set startup-with-shell
  127.    false".

  128.    The catch-exec traps expected during start-up will be one more if
  129.    the target is started up with a shell.  */
  130. extern int startup_with_shell;

  131. /* Address at which inferior stopped.  */

  132. extern CORE_ADDR stop_pc;

  133. /* Nonzero if stopped due to completion of a stack dummy routine.  */

  134. extern enum stop_stack_kind stop_stack_dummy;

  135. /* Nonzero if program stopped due to a random (unexpected) signal in
  136.    inferior process.  */

  137. extern int stopped_by_random_signal;

  138. /* STEP_OVER_ALL means step over all subroutine calls.
  139.    STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
  140.    STEP_OVER_NONE means don't step over any subroutine calls.  */

  141. enum step_over_calls_kind
  142.   {
  143.     STEP_OVER_NONE,
  144.     STEP_OVER_ALL,
  145.     STEP_OVER_UNDEBUGGABLE
  146.   };

  147. /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
  148.    will handle it themselves.  STOP_QUIETLY is used when running in
  149.    the shell before the child program has been exec'd and when running
  150.    through shared library loading.  STOP_QUIETLY_REMOTE is used when
  151.    setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
  152.    except that there is no need to hide a signal.  */

  153. /* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
  154.    When doing an attach, the kernel stops the debuggee with a SIGSTOP.
  155.    On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
  156.    a ptraced process has changed.  Earlier versions of the kernel
  157.    would ignore these SIGSTOPs, while now SIGSTOP is treated like any
  158.    other signal, i.e. it is not muffled.

  159.    If the gdb user does a 'continue' after the 'attach', gdb passes
  160.    the global variable stop_signal (which stores the signal from the
  161.    attach, SIGSTOP) to the ptrace(PTRACE_CONT,...)  call.  This is
  162.    problematic, because the kernel doesn't ignore such SIGSTOP
  163.    now.  I.e. it is reported back to gdb, which in turn presents it
  164.    back to the user.

  165.    To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
  166.    gdb to clear the value of stop_signal after the attach, so that it
  167.    is not passed back down to the kernel.  */

  168. enum stop_kind
  169.   {
  170.     NO_STOP_QUIETLY = 0,
  171.     STOP_QUIETLY,
  172.     STOP_QUIETLY_REMOTE,
  173.     STOP_QUIETLY_NO_SIGSTOP
  174.   };


  175. /* Possible values for gdbarch_call_dummy_location.  */
  176. #define ON_STACK 1
  177. #define AT_ENTRY_POINT 4

  178. /* Number of traps that happen between exec'ing the shell to run an
  179.    inferior and when we finally get to the inferior code, not counting
  180.    the exec for the shell.  This is 1 on all supported
  181.    implementations.  */
  182. #define START_INFERIOR_TRAPS_EXPECTED        1

  183. struct private_inferior;

  184. /* Inferior process specific part of `struct infcall_control_state'.

  185.    Inferior thread counterpart is `struct thread_control_state'.  */

  186. struct inferior_control_state
  187. {
  188.   /* See the definition of stop_kind above.  */
  189.   enum stop_kind stop_soon;
  190. };

  191. /* Inferior process specific part of `struct infcall_suspend_state'.

  192.    Inferior thread counterpart is `struct thread_suspend_state'.  */

  193. #if 0 /* Currently unused and empty structures are not valid C.  */
  194. struct inferior_suspend_state
  195. {
  196. };
  197. #endif

  198. /* GDB represents the state of each program execution with an object
  199.    called an inferior.  An inferior typically corresponds to a process
  200.    but is more general and applies also to targets that do not have a
  201.    notion of processes.  Each run of an executable creates a new
  202.    inferior, as does each attachment to an existing process.
  203.    Inferiors have unique internal identifiers that are different from
  204.    target process ids.  Each inferior may in turn have multiple
  205.    threads running in it.  */

  206. struct inferior
  207. {
  208.   /* Pointer to next inferior in singly-linked list of inferiors.  */
  209.   struct inferior *next;

  210.   /* Convenient handle (GDB inferior id).  Unique across all
  211.      inferiors.  */
  212.   int num;

  213.   /* Actual target inferior id, usually, a process id.  This matches
  214.      the ptid_t.pid member of threads of this inferior.  */
  215.   int pid;
  216.   /* True if the PID was actually faked by GDB.  */
  217.   int fake_pid_p;

  218.   /* State of GDB control of inferior process execution.
  219.      See `struct inferior_control_state'.  */
  220.   struct inferior_control_state control;

  221.   /* State of inferior process to restore after GDB is done with an inferior
  222.      call.  See `struct inferior_suspend_state'.  */
  223. #if 0 /* Currently unused and empty structures are not valid C.  */
  224.   struct inferior_suspend_state suspend;
  225. #endif

  226.   /* True if this was an auto-created inferior, e.g. created from
  227.      following a fork; false, if this inferior was manually added by
  228.      the user, and we should not attempt to prune it
  229.      automatically.  */
  230.   int removable;

  231.   /* The address space bound to this inferior.  */
  232.   struct address_space *aspace;

  233.   /* The program space bound to this inferior.  */
  234.   struct program_space *pspace;

  235.   /* The arguments string to use when running.  */
  236.   char *args;

  237.   /* The size of elements in argv.  */
  238.   int argc;

  239.   /* The vector version of arguments.  If ARGC is nonzero,
  240.      then we must compute ARGS from this (via the target).
  241.      This is always coming from main's argv and therefore
  242.      should never be freed.  */
  243.   char **argv;

  244.   /* The name of terminal device to use for I/O.  */
  245.   char *terminal;

  246.   /* Environment to use for running inferior,
  247.      in format described in environ.h.  */
  248.   struct gdb_environ *environment;

  249.   /* Nonzero if this child process was attached rather than
  250.      forked.  */
  251.   int attach_flag;

  252.   /* If this inferior is a vfork child, then this is the pointer to
  253.      its vfork parent, if GDB is still attached to it.  */
  254.   struct inferior *vfork_parent;

  255.   /* If this process is a vfork parent, this is the pointer to the
  256.      child.  Since a vfork parent is left frozen by the kernel until
  257.      the child execs or exits, a process can only have one vfork child
  258.      at a given time.  */
  259.   struct inferior *vfork_child;

  260.   /* True if this inferior should be detached when it's vfork sibling
  261.      exits or execs.  */
  262.   int pending_detach;

  263.   /* True if this inferior is a vfork parent waiting for a vfork child
  264.      not under our control to be done with the shared memory region,
  265.      either by exiting or execing.  */
  266.   int waiting_for_vfork_done;

  267.   /* True if we're in the process of detaching from this inferior.  */
  268.   int detaching;

  269.   /* What is left to do for an execution command after any thread of
  270.      this inferior stops.  For continuations associated with a
  271.      specific thread, see `struct thread_info'.  */
  272.   struct continuation *continuations;

  273.   /* Private data used by the target vector implementation.  */
  274.   struct private_inferior *private;

  275.   /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
  276.      In this case, the EXIT_CODE field is also valid.  */
  277.   int has_exit_code;
  278.   LONGEST exit_code;

  279.   /* Default flags to pass to the symbol reading functions.  These are
  280.      used whenever a new objfile is created.  The valid values come
  281.      from enum symfile_add_flags.  */
  282.   int symfile_flags;

  283.   /* Info about an inferior's target description (if it's fetched; the
  284.      user supplied description's filename, if any; etc.).  */
  285.   struct target_desc_info *tdesc_info;

  286.   /* The architecture associated with the inferior through the
  287.      connection to the target.

  288.      The architecture vector provides some information that is really
  289.      a property of the inferior, accessed through a particular target:
  290.      ptrace operations; the layout of certain RSP packets; the
  291.      solib_ops vector; etc.  To differentiate architecture accesses to
  292.      per-inferior/target properties from
  293.      per-thread/per-frame/per-objfile properties, accesses to
  294.      per-inferior/target properties should be made through
  295.      this gdbarch.  */
  296.   struct gdbarch *gdbarch;

  297.   /* Per inferior data-pointers required by other GDB modules.  */
  298.   REGISTRY_FIELDS;
  299. };

  300. /* Keep a registry of per-inferior data-pointers required by other GDB
  301.    modules.  */

  302. DECLARE_REGISTRY (inferior);

  303. /* Create an empty inferior list, or empty the existing one.  */
  304. extern void init_inferior_list (void);

  305. /* Add an inferior to the inferior list, print a message that a new
  306.    inferior is found, and return the pointer to the new inferior.
  307.    Caller may use this pointer to initialize the private inferior
  308.    data.  */
  309. extern struct inferior *add_inferior (int pid);

  310. /* Same as add_inferior, but don't print new inferior notifications to
  311.    the CLI.  */
  312. extern struct inferior *add_inferior_silent (int pid);

  313. /* Delete an existing inferior list entry, due to inferior exit.  */
  314. extern void delete_inferior (int pid);

  315. extern void delete_inferior_1 (struct inferior *todel, int silent);

  316. /* Same as delete_inferior, but don't print new inferior notifications
  317.    to the CLI.  */
  318. extern void delete_inferior_silent (int pid);

  319. /* Delete an existing inferior list entry, due to inferior detaching.  */
  320. extern void detach_inferior (int pid);

  321. extern void exit_inferior (int pid);

  322. extern void exit_inferior_silent (int pid);

  323. extern void exit_inferior_num_silent (int num);

  324. extern void inferior_appeared (struct inferior *inf, int pid);

  325. /* Get rid of all inferiors.  */
  326. extern void discard_all_inferiors (void);

  327. /* Translate the integer inferior id (GDB's homegrown id, not the system's)
  328.    into a "pid" (which may be overloaded with extra inferior information).  */
  329. extern int gdb_inferior_id_to_pid (int);

  330. /* Translate a target 'pid' into the integer inferior id (GDB's
  331.    homegrown id, not the system's).  */
  332. extern int pid_to_gdb_inferior_id (int pid);

  333. /* Boolean test for an already-known pid.  */
  334. extern int in_inferior_list (int pid);

  335. /* Boolean test for an already-known inferior id (GDB's homegrown id,
  336.    not the system's).  */
  337. extern int valid_gdb_inferior_id (int num);

  338. /* Search function to lookup an inferior by target 'pid'.  */
  339. extern struct inferior *find_inferior_pid (int pid);

  340. /* Search function to lookup an inferior whose pid is equal to 'ptid.pid'. */
  341. extern struct inferior *find_inferior_ptid (ptid_t ptid);

  342. /* Search function to lookup an inferior by GDB 'num'.  */
  343. extern struct inferior *find_inferior_id (int num);

  344. /* Find an inferior bound to PSPACE, giving preference to the current
  345.    inferior.  */
  346. extern struct inferior *
  347.   find_inferior_for_program_space (struct program_space *pspace);

  348. /* Inferior iterator function.

  349.    Calls a callback function once for each inferior, so long as the
  350.    callback function returns false.  If the callback function returns
  351.    true, the iteration will end and the current inferior will be
  352.    returned.  This can be useful for implementing a search for a
  353.    inferior with arbitrary attributes, or for applying some operation
  354.    to every inferior.

  355.    It is safe to delete the iterated inferior from the callback.  */
  356. extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
  357.                                                          void *),
  358.                                                 void *);

  359. /* Returns true if the inferior list is not empty.  */
  360. extern int have_inferiors (void);

  361. /* Returns true if there are any live inferiors in the inferior list
  362.    (not cores, not executables, real live processes).  */
  363. extern int have_live_inferiors (void);

  364. /* Return a pointer to the current inferior.  It is an error to call
  365.    this if there is no current inferior.  */
  366. extern struct inferior *current_inferior (void);

  367. extern void set_current_inferior (struct inferior *);

  368. extern struct cleanup *save_current_inferior (void);

  369. /* Traverse all inferiors.  */

  370. #define ALL_INFERIORS(I) \
  371.   for ((I) = inferior_list; (I); (I) = (I)->next)

  372. extern struct inferior *inferior_list;

  373. /* Prune away automatically added inferiors that aren't required
  374.    anymore.  */
  375. extern void prune_inferiors (void);

  376. extern int number_of_inferiors (void);

  377. extern struct inferior *add_inferior_with_spaces (void);

  378. #endif /* !defined (INFERIOR_H) */