PR gdb/13860: make "-exec-foo"'s MI output equal to "foo"'s MI output.
[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 /* Are we simulating synchronous execution? This is used in async gdb
88    to implement the 'run', 'continue' etc commands, which will not
89    redisplay the prompt until the execution is actually over.  */
90 extern int sync_execution;
91
92 /* Inferior environment.  */
93
94 extern void clear_proceed_status (void);
95
96 extern void proceed (CORE_ADDR, enum gdb_signal, int);
97
98 extern int sched_multi;
99
100 /* When set, stop the 'step' command if we enter a function which has
101    no line number information.  The normal behavior is that we step
102    over such function.  */
103 extern int step_stop_if_no_debug;
104
105 /* If set, the inferior should be controlled in non-stop mode.  In
106    this mode, each thread is controlled independently.  Execution
107    commands apply only to the selected thread by default, and stop
108    events stop only the thread that had the event -- the other threads
109    are kept running freely.  */
110 extern int non_stop;
111
112 /* When set (default), the target should attempt to disable the operating
113    system's address space randomization feature when starting an inferior.  */
114 extern int disable_randomization;
115
116 extern void generic_mourn_inferior (void);
117
118 extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
119                                               struct type *type,
120                                               const gdb_byte *buf);
121 extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
122                                          struct type *type, gdb_byte *buf,
123                                          CORE_ADDR addr);
124 extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
125                                             struct type *type,
126                                             const gdb_byte *buf);
127 extern void address_to_signed_pointer (struct gdbarch *gdbarch,
128                                        struct type *type, gdb_byte *buf,
129                                        CORE_ADDR addr);
130
131 extern void wait_for_inferior (void);
132
133 extern void prepare_for_detach (void);
134
135 extern void fetch_inferior_event (void *);
136
137 extern void init_wait_for_inferior (void);
138
139 extern void reopen_exec_file (void);
140
141 /* The `resume' routine should only be called in special circumstances.
142    Normally, use `proceed', which handles a lot of bookkeeping.  */
143
144 extern void resume (int, enum gdb_signal);
145
146 extern ptid_t user_visible_resume_ptid (int step);
147
148 extern void insert_step_resume_breakpoint_at_sal (struct gdbarch *,
149                                                   struct symtab_and_line ,
150                                                   struct frame_id);
151
152 /* From misc files */
153
154 extern void default_print_registers_info (struct gdbarch *gdbarch,
155                                           struct ui_file *file,
156                                           struct frame_info *frame,
157                                           int regnum, int all);
158
159 extern void child_terminal_info (struct target_ops *self, const char *, int);
160
161 extern void term_info (char *, int);
162
163 extern void child_terminal_save_ours (struct target_ops *self);
164
165 extern void child_terminal_ours (struct target_ops *self);
166
167 extern void child_terminal_ours_for_output (struct target_ops *self);
168
169 extern void child_terminal_inferior (struct target_ops *self);
170
171 extern void child_terminal_init (struct target_ops *self);
172
173 extern void child_terminal_init_with_pgrp (int pgrp);
174
175 /* From fork-child.c */
176
177 extern int fork_inferior (char *, char *, char **,
178                           void (*)(void),
179                           void (*)(int), void (*)(void), char *,
180                           void (*)(const char *,
181                                    char * const *, char * const *));
182
183
184 extern void startup_inferior (int);
185
186 extern char *construct_inferior_arguments (int, char **);
187
188 /* From infrun.c */
189
190 extern unsigned int debug_infrun;
191
192 extern int stop_on_solib_events;
193
194 extern void start_remote (int from_tty);
195
196 extern void normal_stop (void);
197
198 extern void print_stop_event (struct target_waitstatus *ws);
199
200 extern int signal_stop_state (int);
201
202 extern int signal_print_state (int);
203
204 extern int signal_pass_state (int);
205
206 extern int signal_stop_update (int, int);
207
208 extern int signal_print_update (int, int);
209
210 extern int signal_pass_update (int, int);
211
212 extern void get_last_target_status(ptid_t *ptid,
213                                    struct target_waitstatus *status);
214
215 extern void follow_inferior_reset_breakpoints (void);
216
217 void set_step_info (struct frame_info *frame, struct symtab_and_line sal);
218
219 /* Clear the convenience variables associated with the exit of the
220    inferior.  Currently, those variables are $_exitcode and
221    $_exitsignal.  */
222
223 extern void clear_exit_convenience_vars (void);
224
225 /* From infcmd.c */
226
227 extern void post_create_inferior (struct target_ops *, int);
228
229 extern void attach_command (char *, int);
230
231 extern char *get_inferior_args (void);
232
233 extern void set_inferior_args (char *);
234
235 extern void set_inferior_args_vector (int, char **);
236
237 extern void registers_info (char *, int);
238
239 extern void continue_1 (int all_threads);
240
241 extern void interrupt_target_1 (int all_threads);
242
243 extern void delete_longjmp_breakpoint_cleanup (void *arg);
244
245 extern void detach_command (char *, int);
246
247 extern void notice_new_inferior (ptid_t, int, int);
248
249 extern struct value *get_return_value (struct value *function,
250                                        struct type *value_type);
251
252 /* Whether to start up the debuggee under a shell.
253
254    If startup-with-shell is set, GDB's "run" will attempt to start up
255    the debuggee under a shell.
256
257    This is in order for argument-expansion to occur.  E.g.,
258
259    (gdb) run *
260
261    The "*" gets expanded by the shell into a list of files.
262
263    While this is a nice feature, it may be handy to bypass the shell
264    in some cases.  To disable this feature, do "set startup-with-shell
265    false".
266
267    The catch-exec traps expected during start-up will be one more if
268    the target is started up with a shell.  */
269 extern int startup_with_shell;
270
271 /* Address at which inferior stopped.  */
272
273 extern CORE_ADDR stop_pc;
274
275 /* Nonzero if stopped due to completion of a stack dummy routine.  */
276
277 extern enum stop_stack_kind stop_stack_dummy;
278
279 /* Nonzero if program stopped due to a random (unexpected) signal in
280    inferior process.  */
281
282 extern int stopped_by_random_signal;
283
284 /* STEP_OVER_ALL means step over all subroutine calls.
285    STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
286    STEP_OVER_NONE means don't step over any subroutine calls.  */
287
288 enum step_over_calls_kind
289   {
290     STEP_OVER_NONE,
291     STEP_OVER_ALL,
292     STEP_OVER_UNDEBUGGABLE
293   };
294
295 /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
296    will handle it themselves.  STOP_QUIETLY is used when running in
297    the shell before the child program has been exec'd and when running
298    through shared library loading.  STOP_QUIETLY_REMOTE is used when
299    setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
300    except that there is no need to hide a signal.  */
301
302 /* It is also used after attach, due to attaching to a process.  This
303    is a bit trickier.  When doing an attach, the kernel stops the
304    debuggee with a SIGSTOP.  On newer GNU/Linux kernels (>= 2.5.61)
305    the handling of SIGSTOP for a ptraced process has changed.  Earlier
306    versions of the kernel would ignore these SIGSTOPs, while now
307    SIGSTOP is treated like any other signal, i.e. it is not muffled.
308    
309    If the gdb user does a 'continue' after the 'attach', gdb passes
310    the global variable stop_signal (which stores the signal from the
311    attach, SIGSTOP) to the ptrace(PTRACE_CONT,...)  call.  This is
312    problematic, because the kernel doesn't ignore such SIGSTOP
313    now.  I.e. it is reported back to gdb, which in turn presents it
314    back to the user.
315  
316    To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
317    gdb to clear the value of stop_signal after the attach, so that it
318    is not passed back down to the kernel.  */
319
320 enum stop_kind
321   {
322     NO_STOP_QUIETLY = 0,
323     STOP_QUIETLY,
324     STOP_QUIETLY_REMOTE,
325     STOP_QUIETLY_NO_SIGSTOP
326   };
327
328 /* Reverse execution.  */
329 enum exec_direction_kind
330   {
331     EXEC_FORWARD,
332     EXEC_REVERSE
333   };
334
335 /* The current execution direction.  This should only be set to enum
336    exec_direction_kind values.  It is only an int to make it
337    compatible with make_cleanup_restore_integer.  */
338 extern int execution_direction;
339
340 /* Save register contents here when executing a "finish" command or are
341    about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
342    Thus this contains the return value from the called function (assuming
343    values are returned in a register).  */
344
345 extern struct regcache *stop_registers;
346
347 /* True if we are debugging displaced stepping.  */
348 extern int debug_displaced;
349
350 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline.  */
351 void displaced_step_dump_bytes (struct ui_file *file,
352                                 const gdb_byte *buf, size_t len);
353
354 struct displaced_step_closure *get_displaced_step_closure_by_addr (CORE_ADDR addr);
355 \f
356 /* Possible values for gdbarch_call_dummy_location.  */
357 #define ON_STACK 1
358 #define AT_ENTRY_POINT 4
359
360 /* Number of traps that happen between exec'ing the shell to run an
361    inferior and when we finally get to the inferior code, not counting
362    the exec for the shell.  This is 1 on most implementations.
363    Overridden in nm.h files.  */
364 #if !defined(START_INFERIOR_TRAPS_EXPECTED)
365 #define START_INFERIOR_TRAPS_EXPECTED   1
366 #endif
367
368 struct private_inferior;
369
370 /* Inferior process specific part of `struct infcall_control_state'.
371
372    Inferior thread counterpart is `struct thread_control_state'.  */
373
374 struct inferior_control_state
375 {
376   /* See the definition of stop_kind above.  */
377   enum stop_kind stop_soon;
378 };
379
380 /* Inferior process specific part of `struct infcall_suspend_state'.
381
382    Inferior thread counterpart is `struct thread_suspend_state'.  */
383
384 #if 0 /* Currently unused and empty structures are not valid C.  */
385 struct inferior_suspend_state
386 {
387 };
388 #endif
389
390 /* GDB represents the state of each program execution with an object
391    called an inferior.  An inferior typically corresponds to a process
392    but is more general and applies also to targets that do not have a
393    notion of processes.  Each run of an executable creates a new
394    inferior, as does each attachment to an existing process.
395    Inferiors have unique internal identifiers that are different from
396    target process ids.  Each inferior may in turn have multiple
397    threads running in it.  */
398
399 struct inferior
400 {
401   /* Pointer to next inferior in singly-linked list of inferiors.  */
402   struct inferior *next;
403
404   /* Convenient handle (GDB inferior id).  Unique across all
405      inferiors.  */
406   int num;
407
408   /* Actual target inferior id, usually, a process id.  This matches
409      the ptid_t.pid member of threads of this inferior.  */
410   int pid;
411   /* True if the PID was actually faked by GDB.  */
412   int fake_pid_p;
413
414   /* State of GDB control of inferior process execution.
415      See `struct inferior_control_state'.  */
416   struct inferior_control_state control;
417
418   /* State of inferior process to restore after GDB is done with an inferior
419      call.  See `struct inferior_suspend_state'.  */
420 #if 0 /* Currently unused and empty structures are not valid C.  */
421   struct inferior_suspend_state suspend;
422 #endif
423
424   /* True if this was an auto-created inferior, e.g. created from
425      following a fork; false, if this inferior was manually added by
426      the user, and we should not attempt to prune it
427      automatically.  */
428   int removable;
429
430   /* The address space bound to this inferior.  */
431   struct address_space *aspace;
432
433   /* The program space bound to this inferior.  */
434   struct program_space *pspace;
435
436   /* The arguments string to use when running.  */
437   char *args;
438
439   /* The size of elements in argv.  */
440   int argc;
441
442   /* The vector version of arguments.  If ARGC is nonzero,
443      then we must compute ARGS from this (via the target).
444      This is always coming from main's argv and therefore
445      should never be freed.  */
446   char **argv;
447
448   /* The name of terminal device to use for I/O.  */
449   char *terminal;
450
451   /* Environment to use for running inferior,
452      in format described in environ.h.  */
453   struct gdb_environ *environment;
454
455   /* Nonzero if this child process was attached rather than
456      forked.  */
457   int attach_flag;
458
459   /* If this inferior is a vfork child, then this is the pointer to
460      its vfork parent, if GDB is still attached to it.  */
461   struct inferior *vfork_parent;
462
463   /* If this process is a vfork parent, this is the pointer to the
464      child.  Since a vfork parent is left frozen by the kernel until
465      the child execs or exits, a process can only have one vfork child
466      at a given time.  */
467   struct inferior *vfork_child;
468
469   /* True if this inferior should be detached when it's vfork sibling
470      exits or execs.  */
471   int pending_detach;
472
473   /* True if this inferior is a vfork parent waiting for a vfork child
474      not under our control to be done with the shared memory region,
475      either by exiting or execing.  */
476   int waiting_for_vfork_done;
477
478   /* True if we're in the process of detaching from this inferior.  */
479   int detaching;
480
481   /* What is left to do for an execution command after any thread of
482      this inferior stops.  For continuations associated with a
483      specific thread, see `struct thread_info'.  */
484   struct continuation *continuations;
485
486   /* Private data used by the target vector implementation.  */
487   struct private_inferior *private;
488
489   /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
490      In this case, the EXIT_CODE field is also valid.  */
491   int has_exit_code;
492   LONGEST exit_code;
493
494   /* Default flags to pass to the symbol reading functions.  These are
495      used whenever a new objfile is created.  The valid values come
496      from enum symfile_add_flags.  */
497   int symfile_flags;
498
499   /* Info about an inferior's target description (if it's fetched; the
500      user supplied description's filename, if any; etc.).  */
501   struct target_desc_info *tdesc_info;
502
503   /* The architecture associated with the inferior through the
504      connection to the target.
505
506      The architecture vector provides some information that is really
507      a property of the inferior, accessed through a particular target:
508      ptrace operations; the layout of certain RSP packets; the
509      solib_ops vector; etc.  To differentiate architecture accesses to
510      per-inferior/target properties from
511      per-thread/per-frame/per-objfile properties, accesses to
512      per-inferior/target properties should be made through
513      this gdbarch.  */
514   struct gdbarch *gdbarch;
515
516   /* Per inferior data-pointers required by other GDB modules.  */
517   REGISTRY_FIELDS;
518 };
519
520 /* Keep a registry of per-inferior data-pointers required by other GDB
521    modules.  */
522
523 DECLARE_REGISTRY (inferior);
524
525 /* Create an empty inferior list, or empty the existing one.  */
526 extern void init_inferior_list (void);
527
528 /* Add an inferior to the inferior list, print a message that a new
529    inferior is found, and return the pointer to the new inferior.
530    Caller may use this pointer to initialize the private inferior
531    data.  */
532 extern struct inferior *add_inferior (int pid);
533
534 /* Same as add_inferior, but don't print new inferior notifications to
535    the CLI.  */
536 extern struct inferior *add_inferior_silent (int pid);
537
538 /* Delete an existing inferior list entry, due to inferior exit.  */
539 extern void delete_inferior (int pid);
540
541 extern void delete_inferior_1 (struct inferior *todel, int silent);
542
543 /* Same as delete_inferior, but don't print new inferior notifications
544    to the CLI.  */
545 extern void delete_inferior_silent (int pid);
546
547 /* Delete an existing inferior list entry, due to inferior detaching.  */
548 extern void detach_inferior (int pid);
549
550 extern void exit_inferior (int pid);
551
552 extern void exit_inferior_silent (int pid);
553
554 extern void exit_inferior_num_silent (int num);
555
556 extern void inferior_appeared (struct inferior *inf, int pid);
557
558 /* Get rid of all inferiors.  */
559 extern void discard_all_inferiors (void);
560
561 /* Translate the integer inferior id (GDB's homegrown id, not the system's)
562    into a "pid" (which may be overloaded with extra inferior information).  */
563 extern int gdb_inferior_id_to_pid (int);
564
565 /* Translate a target 'pid' into the integer inferior id (GDB's
566    homegrown id, not the system's).  */
567 extern int pid_to_gdb_inferior_id (int pid);
568
569 /* Boolean test for an already-known pid.  */
570 extern int in_inferior_list (int pid);
571
572 /* Boolean test for an already-known inferior id (GDB's homegrown id,
573    not the system's).  */
574 extern int valid_gdb_inferior_id (int num);
575
576 /* Search function to lookup an inferior by target 'pid'.  */
577 extern struct inferior *find_inferior_pid (int pid);
578
579 /* Search function to lookup an inferior by GDB 'num'.  */
580 extern struct inferior *find_inferior_id (int num);
581
582 /* Find an inferior bound to PSPACE.  */
583 extern struct inferior *
584   find_inferior_for_program_space (struct program_space *pspace);
585
586 /* Inferior iterator function.
587
588    Calls a callback function once for each inferior, so long as the
589    callback function returns false.  If the callback function returns
590    true, the iteration will end and the current inferior will be
591    returned.  This can be useful for implementing a search for a
592    inferior with arbitrary attributes, or for applying some operation
593    to every inferior.
594
595    It is safe to delete the iterated inferior from the callback.  */
596 extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
597                                                          void *),
598                                                 void *);
599
600 /* Returns true if the inferior list is not empty.  */
601 extern int have_inferiors (void);
602
603 /* Returns true if there are any live inferiors in the inferior list
604    (not cores, not executables, real live processes).  */
605 extern int have_live_inferiors (void);
606
607 /* Return a pointer to the current inferior.  It is an error to call
608    this if there is no current inferior.  */
609 extern struct inferior *current_inferior (void);
610
611 extern void set_current_inferior (struct inferior *);
612
613 extern struct cleanup *save_current_inferior (void);
614
615 /* Traverse all inferiors.  */
616
617 #define ALL_INFERIORS(I) \
618   for ((I) = inferior_list; (I); (I) = (I)->next)
619
620 extern struct inferior *inferior_list;
621
622 /* Prune away automatically added inferiors that aren't required
623    anymore.  */
624 extern void prune_inferiors (void);
625
626 extern int number_of_inferiors (void);
627
628 extern struct inferior *add_inferior_with_spaces (void);
629
630 extern void update_observer_mode (void);
631
632 extern void update_signals_program_target (void);
633
634 extern void signal_catch_update (const unsigned int *);
635
636 /* In some circumstances we allow a command to specify a numeric
637    signal.  The idea is to keep these circumstances limited so that
638    users (and scripts) develop portable habits.  For comparison,
639    POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
640    numeric signal at all is obsolescent.  We are slightly more lenient
641    and allow 1-15 which should match host signal numbers on most
642    systems.  Use of symbolic signal names is strongly encouraged.  */
643
644 enum gdb_signal gdb_signal_from_command (int num);
645
646 #endif /* !defined (INFERIOR_H) */