Add new infrun.h header.
[platform/upstream/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-2014 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 #include "ptid.h"
35
36 /* For bpstat.  */
37 #include "breakpoint.h"
38
39 /* For enum gdb_signal.  */
40 #include "target.h"
41
42 /* For struct frame_id.  */
43 #include "frame.h"
44
45 #include "progspace.h"
46 #include "registry.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 extern void child_terminal_info (struct target_ops *self, const char *, int);
112
113 extern void term_info (char *, int);
114
115 extern void child_terminal_save_ours (struct target_ops *self);
116
117 extern void child_terminal_ours (struct target_ops *self);
118
119 extern void child_terminal_ours_for_output (struct target_ops *self);
120
121 extern void child_terminal_inferior (struct target_ops *self);
122
123 extern void child_terminal_init (struct target_ops *self);
124
125 extern void child_terminal_init_with_pgrp (int pgrp);
126
127 /* From fork-child.c */
128
129 extern int fork_inferior (char *, char *, char **,
130                           void (*)(void),
131                           void (*)(int), void (*)(void), char *,
132                           void (*)(const char *,
133                                    char * const *, char * const *));
134
135
136 extern void startup_inferior (int);
137
138 extern char *construct_inferior_arguments (int, char **);
139
140 /* From infcmd.c */
141
142 extern void post_create_inferior (struct target_ops *, int);
143
144 extern void attach_command (char *, int);
145
146 extern char *get_inferior_args (void);
147
148 extern void set_inferior_args (char *);
149
150 extern void set_inferior_args_vector (int, char **);
151
152 extern void registers_info (char *, int);
153
154 extern void continue_1 (int all_threads);
155
156 extern void interrupt_target_1 (int all_threads);
157
158 extern void delete_longjmp_breakpoint_cleanup (void *arg);
159
160 extern void detach_command (char *, int);
161
162 extern void notice_new_inferior (ptid_t, int, int);
163
164 extern struct value *get_return_value (struct value *function,
165                                        struct type *value_type);
166
167 /* Whether to start up the debuggee under a shell.
168
169    If startup-with-shell is set, GDB's "run" will attempt to start up
170    the debuggee under a shell.
171
172    This is in order for argument-expansion to occur.  E.g.,
173
174    (gdb) run *
175
176    The "*" gets expanded by the shell into a list of files.
177
178    While this is a nice feature, it may be handy to bypass the shell
179    in some cases.  To disable this feature, do "set startup-with-shell
180    false".
181
182    The catch-exec traps expected during start-up will be one more if
183    the target is started up with a shell.  */
184 extern int startup_with_shell;
185
186 /* Address at which inferior stopped.  */
187
188 extern CORE_ADDR stop_pc;
189
190 /* Nonzero if stopped due to completion of a stack dummy routine.  */
191
192 extern enum stop_stack_kind stop_stack_dummy;
193
194 /* Nonzero if program stopped due to a random (unexpected) signal in
195    inferior process.  */
196
197 extern int stopped_by_random_signal;
198
199 /* STEP_OVER_ALL means step over all subroutine calls.
200    STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
201    STEP_OVER_NONE means don't step over any subroutine calls.  */
202
203 enum step_over_calls_kind
204   {
205     STEP_OVER_NONE,
206     STEP_OVER_ALL,
207     STEP_OVER_UNDEBUGGABLE
208   };
209
210 /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
211    will handle it themselves.  STOP_QUIETLY is used when running in
212    the shell before the child program has been exec'd and when running
213    through shared library loading.  STOP_QUIETLY_REMOTE is used when
214    setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
215    except that there is no need to hide a signal.  */
216
217 /* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
218    When doing an attach, the kernel stops the debuggee with a SIGSTOP.
219    On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
220    a ptraced process has changed.  Earlier versions of the kernel
221    would ignore these SIGSTOPs, while now SIGSTOP is treated like any
222    other signal, i.e. it is not muffled.
223
224    If the gdb user does a 'continue' after the 'attach', gdb passes
225    the global variable stop_signal (which stores the signal from the
226    attach, SIGSTOP) to the ptrace(PTRACE_CONT,...)  call.  This is
227    problematic, because the kernel doesn't ignore such SIGSTOP
228    now.  I.e. it is reported back to gdb, which in turn presents it
229    back to the user.
230
231    To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
232    gdb to clear the value of stop_signal after the attach, so that it
233    is not passed back down to the kernel.  */
234
235 enum stop_kind
236   {
237     NO_STOP_QUIETLY = 0,
238     STOP_QUIETLY,
239     STOP_QUIETLY_REMOTE,
240     STOP_QUIETLY_NO_SIGSTOP
241   };
242
243 \f
244 /* Possible values for gdbarch_call_dummy_location.  */
245 #define ON_STACK 1
246 #define AT_ENTRY_POINT 4
247
248 /* Number of traps that happen between exec'ing the shell to run an
249    inferior and when we finally get to the inferior code, not counting
250    the exec for the shell.  This is 1 on most implementations.
251    Overridden in nm.h files.  */
252 #if !defined(START_INFERIOR_TRAPS_EXPECTED)
253 #define START_INFERIOR_TRAPS_EXPECTED   1
254 #endif
255
256 struct private_inferior;
257
258 /* Inferior process specific part of `struct infcall_control_state'.
259
260    Inferior thread counterpart is `struct thread_control_state'.  */
261
262 struct inferior_control_state
263 {
264   /* See the definition of stop_kind above.  */
265   enum stop_kind stop_soon;
266 };
267
268 /* Inferior process specific part of `struct infcall_suspend_state'.
269
270    Inferior thread counterpart is `struct thread_suspend_state'.  */
271
272 #if 0 /* Currently unused and empty structures are not valid C.  */
273 struct inferior_suspend_state
274 {
275 };
276 #endif
277
278 /* GDB represents the state of each program execution with an object
279    called an inferior.  An inferior typically corresponds to a process
280    but is more general and applies also to targets that do not have a
281    notion of processes.  Each run of an executable creates a new
282    inferior, as does each attachment to an existing process.
283    Inferiors have unique internal identifiers that are different from
284    target process ids.  Each inferior may in turn have multiple
285    threads running in it.  */
286
287 struct inferior
288 {
289   /* Pointer to next inferior in singly-linked list of inferiors.  */
290   struct inferior *next;
291
292   /* Convenient handle (GDB inferior id).  Unique across all
293      inferiors.  */
294   int num;
295
296   /* Actual target inferior id, usually, a process id.  This matches
297      the ptid_t.pid member of threads of this inferior.  */
298   int pid;
299   /* True if the PID was actually faked by GDB.  */
300   int fake_pid_p;
301
302   /* State of GDB control of inferior process execution.
303      See `struct inferior_control_state'.  */
304   struct inferior_control_state control;
305
306   /* State of inferior process to restore after GDB is done with an inferior
307      call.  See `struct inferior_suspend_state'.  */
308 #if 0 /* Currently unused and empty structures are not valid C.  */
309   struct inferior_suspend_state suspend;
310 #endif
311
312   /* True if this was an auto-created inferior, e.g. created from
313      following a fork; false, if this inferior was manually added by
314      the user, and we should not attempt to prune it
315      automatically.  */
316   int removable;
317
318   /* The address space bound to this inferior.  */
319   struct address_space *aspace;
320
321   /* The program space bound to this inferior.  */
322   struct program_space *pspace;
323
324   /* The arguments string to use when running.  */
325   char *args;
326
327   /* The size of elements in argv.  */
328   int argc;
329
330   /* The vector version of arguments.  If ARGC is nonzero,
331      then we must compute ARGS from this (via the target).
332      This is always coming from main's argv and therefore
333      should never be freed.  */
334   char **argv;
335
336   /* The name of terminal device to use for I/O.  */
337   char *terminal;
338
339   /* Environment to use for running inferior,
340      in format described in environ.h.  */
341   struct gdb_environ *environment;
342
343   /* Nonzero if this child process was attached rather than
344      forked.  */
345   int attach_flag;
346
347   /* If this inferior is a vfork child, then this is the pointer to
348      its vfork parent, if GDB is still attached to it.  */
349   struct inferior *vfork_parent;
350
351   /* If this process is a vfork parent, this is the pointer to the
352      child.  Since a vfork parent is left frozen by the kernel until
353      the child execs or exits, a process can only have one vfork child
354      at a given time.  */
355   struct inferior *vfork_child;
356
357   /* True if this inferior should be detached when it's vfork sibling
358      exits or execs.  */
359   int pending_detach;
360
361   /* True if this inferior is a vfork parent waiting for a vfork child
362      not under our control to be done with the shared memory region,
363      either by exiting or execing.  */
364   int waiting_for_vfork_done;
365
366   /* True if we're in the process of detaching from this inferior.  */
367   int detaching;
368
369   /* What is left to do for an execution command after any thread of
370      this inferior stops.  For continuations associated with a
371      specific thread, see `struct thread_info'.  */
372   struct continuation *continuations;
373
374   /* Private data used by the target vector implementation.  */
375   struct private_inferior *private;
376
377   /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
378      In this case, the EXIT_CODE field is also valid.  */
379   int has_exit_code;
380   LONGEST exit_code;
381
382   /* Default flags to pass to the symbol reading functions.  These are
383      used whenever a new objfile is created.  The valid values come
384      from enum symfile_add_flags.  */
385   int symfile_flags;
386
387   /* Info about an inferior's target description (if it's fetched; the
388      user supplied description's filename, if any; etc.).  */
389   struct target_desc_info *tdesc_info;
390
391   /* The architecture associated with the inferior through the
392      connection to the target.
393
394      The architecture vector provides some information that is really
395      a property of the inferior, accessed through a particular target:
396      ptrace operations; the layout of certain RSP packets; the
397      solib_ops vector; etc.  To differentiate architecture accesses to
398      per-inferior/target properties from
399      per-thread/per-frame/per-objfile properties, accesses to
400      per-inferior/target properties should be made through
401      this gdbarch.  */
402   struct gdbarch *gdbarch;
403
404   /* Per inferior data-pointers required by other GDB modules.  */
405   REGISTRY_FIELDS;
406 };
407
408 /* Keep a registry of per-inferior data-pointers required by other GDB
409    modules.  */
410
411 DECLARE_REGISTRY (inferior);
412
413 /* Create an empty inferior list, or empty the existing one.  */
414 extern void init_inferior_list (void);
415
416 /* Add an inferior to the inferior list, print a message that a new
417    inferior is found, and return the pointer to the new inferior.
418    Caller may use this pointer to initialize the private inferior
419    data.  */
420 extern struct inferior *add_inferior (int pid);
421
422 /* Same as add_inferior, but don't print new inferior notifications to
423    the CLI.  */
424 extern struct inferior *add_inferior_silent (int pid);
425
426 /* Delete an existing inferior list entry, due to inferior exit.  */
427 extern void delete_inferior (int pid);
428
429 extern void delete_inferior_1 (struct inferior *todel, int silent);
430
431 /* Same as delete_inferior, but don't print new inferior notifications
432    to the CLI.  */
433 extern void delete_inferior_silent (int pid);
434
435 /* Delete an existing inferior list entry, due to inferior detaching.  */
436 extern void detach_inferior (int pid);
437
438 extern void exit_inferior (int pid);
439
440 extern void exit_inferior_silent (int pid);
441
442 extern void exit_inferior_num_silent (int num);
443
444 extern void inferior_appeared (struct inferior *inf, int pid);
445
446 /* Get rid of all inferiors.  */
447 extern void discard_all_inferiors (void);
448
449 /* Translate the integer inferior id (GDB's homegrown id, not the system's)
450    into a "pid" (which may be overloaded with extra inferior information).  */
451 extern int gdb_inferior_id_to_pid (int);
452
453 /* Translate a target 'pid' into the integer inferior id (GDB's
454    homegrown id, not the system's).  */
455 extern int pid_to_gdb_inferior_id (int pid);
456
457 /* Boolean test for an already-known pid.  */
458 extern int in_inferior_list (int pid);
459
460 /* Boolean test for an already-known inferior id (GDB's homegrown id,
461    not the system's).  */
462 extern int valid_gdb_inferior_id (int num);
463
464 /* Search function to lookup an inferior by target 'pid'.  */
465 extern struct inferior *find_inferior_pid (int pid);
466
467 /* Search function to lookup an inferior by GDB 'num'.  */
468 extern struct inferior *find_inferior_id (int num);
469
470 /* Find an inferior bound to PSPACE.  */
471 extern struct inferior *
472   find_inferior_for_program_space (struct program_space *pspace);
473
474 /* Inferior iterator function.
475
476    Calls a callback function once for each inferior, so long as the
477    callback function returns false.  If the callback function returns
478    true, the iteration will end and the current inferior will be
479    returned.  This can be useful for implementing a search for a
480    inferior with arbitrary attributes, or for applying some operation
481    to every inferior.
482
483    It is safe to delete the iterated inferior from the callback.  */
484 extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
485                                                          void *),
486                                                 void *);
487
488 /* Returns true if the inferior list is not empty.  */
489 extern int have_inferiors (void);
490
491 /* Returns true if there are any live inferiors in the inferior list
492    (not cores, not executables, real live processes).  */
493 extern int have_live_inferiors (void);
494
495 /* Return a pointer to the current inferior.  It is an error to call
496    this if there is no current inferior.  */
497 extern struct inferior *current_inferior (void);
498
499 extern void set_current_inferior (struct inferior *);
500
501 extern struct cleanup *save_current_inferior (void);
502
503 /* Traverse all inferiors.  */
504
505 #define ALL_INFERIORS(I) \
506   for ((I) = inferior_list; (I); (I) = (I)->next)
507
508 extern struct inferior *inferior_list;
509
510 /* Prune away automatically added inferiors that aren't required
511    anymore.  */
512 extern void prune_inferiors (void);
513
514 extern int number_of_inferiors (void);
515
516 extern struct inferior *add_inferior_with_spaces (void);
517
518 #endif /* !defined (INFERIOR_H) */