403c0967e69c6b1180137910ea44450ae2025cbc
[external/binutils.git] / gdb / inferior.h
1 /* Variables that describe the inferior process running under GDB:
2    Where it is, why it stopped, and how to step it.
3
4    Copyright (C) 1986-2016 Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 #if !defined (INFERIOR_H)
22 #define INFERIOR_H 1
23
24 struct target_waitstatus;
25 struct frame_info;
26 struct ui_file;
27 struct type;
28 struct gdbarch;
29 struct regcache;
30 struct ui_out;
31 struct terminal_info;
32 struct target_desc_info;
33
34 /* For bpstat.  */
35 #include "breakpoint.h"
36
37 /* For enum gdb_signal.  */
38 #include "target.h"
39
40 /* For struct frame_id.  */
41 #include "frame.h"
42
43 #include "progspace.h"
44 #include "registry.h"
45
46 #include "symfile-add-flags.h"
47
48 struct infcall_suspend_state;
49 struct infcall_control_state;
50
51 extern struct infcall_suspend_state *save_infcall_suspend_state (void);
52 extern struct infcall_control_state *save_infcall_control_state (void);
53
54 extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
55 extern void restore_infcall_control_state (struct infcall_control_state *);
56
57 extern struct cleanup *make_cleanup_restore_infcall_suspend_state
58                                             (struct infcall_suspend_state *);
59 extern struct cleanup *make_cleanup_restore_infcall_control_state
60                                             (struct infcall_control_state *);
61
62 extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
63 extern void discard_infcall_control_state (struct infcall_control_state *);
64
65 extern struct regcache *
66   get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
67
68 /* Save value of inferior_ptid so that it may be restored by
69    a later call to do_cleanups().  Returns the struct cleanup
70    pointer needed for later doing the cleanup.  */
71 extern struct cleanup * save_inferior_ptid (void);
72
73 extern void set_sigint_trap (void);
74
75 extern void clear_sigint_trap (void);
76
77 /* Set/get file name for default use for standard in/out in the inferior.  */
78
79 extern void set_inferior_io_terminal (const char *terminal_name);
80 extern const char *get_inferior_io_terminal (void);
81
82 /* Collected pid, tid, etc. of the debugged inferior.  When there's
83    no inferior, ptid_get_pid (inferior_ptid) will be 0.  */
84
85 extern ptid_t inferior_ptid;
86
87 extern void generic_mourn_inferior (void);
88
89 extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
90                                               struct type *type,
91                                               const gdb_byte *buf);
92 extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
93                                          struct type *type, gdb_byte *buf,
94                                          CORE_ADDR addr);
95 extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
96                                             struct type *type,
97                                             const gdb_byte *buf);
98 extern void address_to_signed_pointer (struct gdbarch *gdbarch,
99                                        struct type *type, gdb_byte *buf,
100                                        CORE_ADDR addr);
101
102 extern void reopen_exec_file (void);
103
104 /* From misc files */
105
106 extern void default_print_registers_info (struct gdbarch *gdbarch,
107                                           struct ui_file *file,
108                                           struct frame_info *frame,
109                                           int regnum, int all);
110
111 /* Default implementation of gdbarch_print_float_info.  Print
112    the values of all floating point registers.  */
113
114 extern void default_print_float_info (struct gdbarch *gdbarch,
115                                       struct ui_file *file,
116                                       struct frame_info *frame,
117                                       const char *args);
118
119 extern void child_terminal_info (struct target_ops *self, const char *, int);
120
121 extern void term_info (char *, int);
122
123 extern void child_terminal_ours (struct target_ops *self);
124
125 extern void child_terminal_ours_for_output (struct target_ops *self);
126
127 extern void child_terminal_inferior (struct target_ops *self);
128
129 extern void child_terminal_init (struct target_ops *self);
130
131 extern void child_terminal_init_with_pgrp (int pgrp);
132
133 /* From fork-child.c */
134
135 extern int fork_inferior (char *, char *, char **,
136                           void (*)(void),
137                           void (*)(int), void (*)(void), char *,
138                           void (*)(const char *,
139                                    char * const *, char * const *));
140
141
142 extern void startup_inferior (int);
143
144 extern char *construct_inferior_arguments (int, char **);
145
146 /* From infcmd.c */
147
148 /* Initial inferior setup.  Determines the exec file is not yet known,
149    takes any necessary post-attaching actions, fetches the target
150    description and syncs the shared library list.  */
151
152 extern void setup_inferior (int from_tty);
153
154 extern void post_create_inferior (struct target_ops *, int);
155
156 extern void attach_command (char *, int);
157
158 extern char *get_inferior_args (void);
159
160 extern void set_inferior_args (char *);
161
162 extern void set_inferior_args_vector (int, char **);
163
164 extern void registers_info (char *, int);
165
166 extern void continue_1 (int all_threads);
167
168 extern void interrupt_target_1 (int all_threads);
169
170 extern void delete_longjmp_breakpoint_cleanup (void *arg);
171
172 extern void detach_command (char *, int);
173
174 extern void notice_new_inferior (ptid_t, int, int);
175
176 extern struct value *get_return_value (struct value *function,
177                                        struct type *value_type);
178
179 /* Prepare for execution command.  TARGET is the target that will run
180    the command.  BACKGROUND determines whether this is a foreground
181    (synchronous) or background (asynchronous) command.  */
182
183 extern void prepare_execution_command (struct target_ops *target,
184                                        int background);
185
186 /* Whether to start up the debuggee under a shell.
187
188    If startup-with-shell is set, GDB's "run" will attempt to start up
189    the debuggee under a shell.
190
191    This is in order for argument-expansion to occur.  E.g.,
192
193    (gdb) run *
194
195    The "*" gets expanded by the shell into a list of files.
196
197    While this is a nice feature, it may be handy to bypass the shell
198    in some cases.  To disable this feature, do "set startup-with-shell
199    false".
200
201    The catch-exec traps expected during start-up will be one more if
202    the target is started up with a shell.  */
203 extern int startup_with_shell;
204
205 /* Address at which inferior stopped.  */
206
207 extern CORE_ADDR stop_pc;
208
209 /* Nonzero if stopped due to completion of a stack dummy routine.  */
210
211 extern enum stop_stack_kind stop_stack_dummy;
212
213 /* Nonzero if program stopped due to a random (unexpected) signal in
214    inferior process.  */
215
216 extern int stopped_by_random_signal;
217
218 /* STEP_OVER_ALL means step over all subroutine calls.
219    STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
220    STEP_OVER_NONE means don't step over any subroutine calls.  */
221
222 enum step_over_calls_kind
223   {
224     STEP_OVER_NONE,
225     STEP_OVER_ALL,
226     STEP_OVER_UNDEBUGGABLE
227   };
228
229 /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
230    will handle it themselves.  STOP_QUIETLY is used when running in
231    the shell before the child program has been exec'd and when running
232    through shared library loading.  STOP_QUIETLY_REMOTE is used when
233    setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
234    except that there is no need to hide a signal.  */
235
236 /* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
237    When doing an attach, the kernel stops the debuggee with a SIGSTOP.
238    On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
239    a ptraced process has changed.  Earlier versions of the kernel
240    would ignore these SIGSTOPs, while now SIGSTOP is treated like any
241    other signal, i.e. it is not muffled.
242
243    If the gdb user does a 'continue' after the 'attach', gdb passes
244    the global variable stop_signal (which stores the signal from the
245    attach, SIGSTOP) to the ptrace(PTRACE_CONT,...)  call.  This is
246    problematic, because the kernel doesn't ignore such SIGSTOP
247    now.  I.e. it is reported back to gdb, which in turn presents it
248    back to the user.
249
250    To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
251    gdb to clear the value of stop_signal after the attach, so that it
252    is not passed back down to the kernel.  */
253
254 enum stop_kind
255   {
256     NO_STOP_QUIETLY = 0,
257     STOP_QUIETLY,
258     STOP_QUIETLY_REMOTE,
259     STOP_QUIETLY_NO_SIGSTOP
260   };
261
262 \f
263 /* Possible values for gdbarch_call_dummy_location.  */
264 #define ON_STACK 1
265 #define AT_ENTRY_POINT 4
266
267 /* Number of traps that happen between exec'ing the shell to run an
268    inferior and when we finally get to the inferior code, not counting
269    the exec for the shell.  This is 1 on all supported
270    implementations.  */
271 #define START_INFERIOR_TRAPS_EXPECTED   1
272
273 struct private_inferior;
274
275 /* Inferior process specific part of `struct infcall_control_state'.
276
277    Inferior thread counterpart is `struct thread_control_state'.  */
278
279 struct inferior_control_state
280 {
281   /* See the definition of stop_kind above.  */
282   enum stop_kind stop_soon;
283 };
284
285 /* GDB represents the state of each program execution with an object
286    called an inferior.  An inferior typically corresponds to a process
287    but is more general and applies also to targets that do not have a
288    notion of processes.  Each run of an executable creates a new
289    inferior, as does each attachment to an existing process.
290    Inferiors have unique internal identifiers that are different from
291    target process ids.  Each inferior may in turn have multiple
292    threads running in it.  */
293
294 struct inferior
295 {
296   /* Pointer to next inferior in singly-linked list of inferiors.  */
297   struct inferior *next;
298
299   /* Convenient handle (GDB inferior id).  Unique across all
300      inferiors.  */
301   int num;
302
303   /* Actual target inferior id, usually, a process id.  This matches
304      the ptid_t.pid member of threads of this inferior.  */
305   int pid;
306   /* True if the PID was actually faked by GDB.  */
307   int fake_pid_p;
308
309   /* The highest thread number this inferior ever had.  */
310   int highest_thread_num;
311
312   /* State of GDB control of inferior process execution.
313      See `struct inferior_control_state'.  */
314   struct inferior_control_state control;
315
316   /* True if this was an auto-created inferior, e.g. created from
317      following a fork; false, if this inferior was manually added by
318      the user, and we should not attempt to prune it
319      automatically.  */
320   int removable;
321
322   /* The address space bound to this inferior.  */
323   struct address_space *aspace;
324
325   /* The program space bound to this inferior.  */
326   struct program_space *pspace;
327
328   /* The arguments string to use when running.  */
329   char *args;
330
331   /* The size of elements in argv.  */
332   int argc;
333
334   /* The vector version of arguments.  If ARGC is nonzero,
335      then we must compute ARGS from this (via the target).
336      This is always coming from main's argv and therefore
337      should never be freed.  */
338   char **argv;
339
340   /* The name of terminal device to use for I/O.  */
341   char *terminal;
342
343   /* Environment to use for running inferior,
344      in format described in environ.h.  */
345   struct gdb_environ *environment;
346
347   /* Nonzero if this child process was attached rather than
348      forked.  */
349   int attach_flag;
350
351   /* If this inferior is a vfork child, then this is the pointer to
352      its vfork parent, if GDB is still attached to it.  */
353   struct inferior *vfork_parent;
354
355   /* If this process is a vfork parent, this is the pointer to the
356      child.  Since a vfork parent is left frozen by the kernel until
357      the child execs or exits, a process can only have one vfork child
358      at a given time.  */
359   struct inferior *vfork_child;
360
361   /* True if this inferior should be detached when it's vfork sibling
362      exits or execs.  */
363   int pending_detach;
364
365   /* True if this inferior is a vfork parent waiting for a vfork child
366      not under our control to be done with the shared memory region,
367      either by exiting or execing.  */
368   int waiting_for_vfork_done;
369
370   /* True if we're in the process of detaching from this inferior.  */
371   int detaching;
372
373   /* What is left to do for an execution command after any thread of
374      this inferior stops.  For continuations associated with a
375      specific thread, see `struct thread_info'.  */
376   struct continuation *continuations;
377
378   /* True if setup_inferior wasn't called for this inferior yet.
379      Until that is done, we must not access inferior memory or
380      registers, as we haven't determined the target
381      architecture/description.  */
382   int needs_setup;
383
384   /* Private data used by the target vector implementation.  */
385   struct private_inferior *priv;
386
387   /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
388      In this case, the EXIT_CODE field is also valid.  */
389   int has_exit_code;
390   LONGEST exit_code;
391
392   /* Default flags to pass to the symbol reading functions.  These are
393      used whenever a new objfile is created.  */
394   symfile_add_flags symfile_flags;
395
396   /* Info about an inferior's target description (if it's fetched; the
397      user supplied description's filename, if any; etc.).  */
398   struct target_desc_info *tdesc_info;
399
400   /* The architecture associated with the inferior through the
401      connection to the target.
402
403      The architecture vector provides some information that is really
404      a property of the inferior, accessed through a particular target:
405      ptrace operations; the layout of certain RSP packets; the
406      solib_ops vector; etc.  To differentiate architecture accesses to
407      per-inferior/target properties from
408      per-thread/per-frame/per-objfile properties, accesses to
409      per-inferior/target properties should be made through
410      this gdbarch.  */
411   struct gdbarch *gdbarch;
412
413   /* Per inferior data-pointers required by other GDB modules.  */
414   REGISTRY_FIELDS;
415 };
416
417 /* Keep a registry of per-inferior data-pointers required by other GDB
418    modules.  */
419
420 DECLARE_REGISTRY (inferior);
421
422 /* Create an empty inferior list, or empty the existing one.  */
423 extern void init_inferior_list (void);
424
425 /* Add an inferior to the inferior list, print a message that a new
426    inferior is found, and return the pointer to the new inferior.
427    Caller may use this pointer to initialize the private inferior
428    data.  */
429 extern struct inferior *add_inferior (int pid);
430
431 /* Same as add_inferior, but don't print new inferior notifications to
432    the CLI.  */
433 extern struct inferior *add_inferior_silent (int pid);
434
435 extern void delete_inferior (struct inferior *todel);
436
437 /* Delete an existing inferior list entry, due to inferior detaching.  */
438 extern void detach_inferior (int pid);
439
440 extern void exit_inferior (int pid);
441
442 extern void exit_inferior_silent (int pid);
443
444 extern void exit_inferior_num_silent (int num);
445
446 extern void inferior_appeared (struct inferior *inf, int pid);
447
448 /* Get rid of all inferiors.  */
449 extern void discard_all_inferiors (void);
450
451 /* Translate the integer inferior id (GDB's homegrown id, not the system's)
452    into a "pid" (which may be overloaded with extra inferior information).  */
453 extern int gdb_inferior_id_to_pid (int);
454
455 /* Translate a target 'pid' into the integer inferior id (GDB's
456    homegrown id, not the system's).  */
457 extern int pid_to_gdb_inferior_id (int pid);
458
459 /* Boolean test for an already-known pid.  */
460 extern int in_inferior_list (int pid);
461
462 /* Boolean test for an already-known inferior id (GDB's homegrown id,
463    not the system's).  */
464 extern int valid_gdb_inferior_id (int num);
465
466 /* Search function to lookup an inferior by target 'pid'.  */
467 extern struct inferior *find_inferior_pid (int pid);
468
469 /* Search function to lookup an inferior whose pid is equal to 'ptid.pid'. */
470 extern struct inferior *find_inferior_ptid (ptid_t ptid);
471
472 /* Search function to lookup an inferior by GDB 'num'.  */
473 extern struct inferior *find_inferior_id (int num);
474
475 /* Find an inferior bound to PSPACE, giving preference to the current
476    inferior.  */
477 extern struct inferior *
478   find_inferior_for_program_space (struct program_space *pspace);
479
480 /* Inferior iterator function.
481
482    Calls a callback function once for each inferior, so long as the
483    callback function returns false.  If the callback function returns
484    true, the iteration will end and the current inferior will be
485    returned.  This can be useful for implementing a search for a
486    inferior with arbitrary attributes, or for applying some operation
487    to every inferior.
488
489    It is safe to delete the iterated inferior from the callback.  */
490 extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
491                                                          void *),
492                                                 void *);
493
494 /* Returns true if the inferior list is not empty.  */
495 extern int have_inferiors (void);
496
497 /* Returns the number of live inferiors (real live processes).  */
498 extern int number_of_live_inferiors (void);
499
500 /* Returns true if there are any live inferiors in the inferior list
501    (not cores, not executables, real live processes).  */
502 extern int have_live_inferiors (void);
503
504 /* Return a pointer to the current inferior.  It is an error to call
505    this if there is no current inferior.  */
506 extern struct inferior *current_inferior (void);
507
508 extern void set_current_inferior (struct inferior *);
509
510 extern struct cleanup *save_current_inferior (void);
511
512 /* Traverse all inferiors.  */
513
514 #define ALL_INFERIORS(I) \
515   for ((I) = inferior_list; (I); (I) = (I)->next)
516
517 /* Traverse all non-exited inferiors.  */
518
519 #define ALL_NON_EXITED_INFERIORS(I) \
520   ALL_INFERIORS (I)                 \
521     if ((I)->pid != 0)
522
523 extern struct inferior *inferior_list;
524
525 /* Prune away automatically added inferiors that aren't required
526    anymore.  */
527 extern void prune_inferiors (void);
528
529 extern int number_of_inferiors (void);
530
531 extern struct inferior *add_inferior_with_spaces (void);
532
533 /* Print the current selected inferior.  */
534 extern void print_selected_inferior (struct ui_out *uiout);
535
536 #endif /* !defined (INFERIOR_H) */