gdb
[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, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
5    1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
6    2011 Free Software Foundation, Inc.
7
8    This file is part of GDB.
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
23 #if !defined (INFERIOR_H)
24 #define INFERIOR_H 1
25
26 struct target_waitstatus;
27 struct frame_info;
28 struct ui_file;
29 struct type;
30 struct gdbarch;
31 struct regcache;
32 struct ui_out;
33 struct terminal_info;
34
35 /* For bpstat.  */
36 #include "breakpoint.h"
37
38 /* For enum target_signal.  */
39 #include "target.h"
40
41 /* For struct frame_id.  */
42 #include "frame.h"
43
44 #include "progspace.h"
45
46 struct infcall_suspend_state;
47 struct infcall_control_state;
48
49 extern struct infcall_suspend_state *save_infcall_suspend_state (void);
50 extern struct infcall_control_state *save_infcall_control_state (void);
51
52 extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
53 extern void restore_infcall_control_state (struct infcall_control_state *);
54
55 extern struct cleanup *make_cleanup_restore_infcall_suspend_state
56                                             (struct infcall_suspend_state *);
57 extern struct cleanup *make_cleanup_restore_infcall_control_state
58                                             (struct infcall_control_state *);
59
60 extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
61 extern void discard_infcall_control_state (struct infcall_control_state *);
62
63 extern struct regcache *
64   get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
65
66 /* The -1 ptid, often used to indicate either an error condition
67    or a "don't care" condition, i.e, "run all threads."  */
68 extern ptid_t minus_one_ptid;
69
70 /* The null or zero ptid, often used to indicate no process.  */
71 extern ptid_t null_ptid;
72
73 /* Attempt to find and return an existing ptid with the given PID, LWP,
74    and TID components.  If none exists, create a new one and return
75    that.  */
76 ptid_t ptid_build (int pid, long lwp, long tid);
77
78 /* Find/Create a ptid from just a pid.  */
79 ptid_t pid_to_ptid (int pid);
80
81 /* Fetch the pid (process id) component from a ptid.  */
82 int ptid_get_pid (ptid_t ptid);
83
84 /* Fetch the lwp (lightweight process) component from a ptid.  */
85 long ptid_get_lwp (ptid_t ptid);
86
87 /* Fetch the tid (thread id) component from a ptid.  */
88 long ptid_get_tid (ptid_t ptid);
89
90 /* Compare two ptids to see if they are equal.  */
91 extern int ptid_equal (ptid_t p1, ptid_t p2);
92
93 /* Return true if PTID represents a process id.  */
94 extern int ptid_is_pid (ptid_t ptid);
95
96 /* Returns true if PTID matches filter FILTER.  FILTER can be the wild
97    card MINUS_ONE_PTID (all ptid match it); can be a ptid representing
98    a process (ptid_is_pid returns true), in which case, all lwps and
99    threads of that given process match, lwps and threads of other
100    processes do not; or, it can represent a specific thread, in which
101    case, only that thread will match true.  PTID must represent a
102    specific LWP or THREAD, it can never be a wild card.  */
103
104 extern int ptid_match (ptid_t ptid, ptid_t filter);
105
106 /* Save value of inferior_ptid so that it may be restored by
107    a later call to do_cleanups().  Returns the struct cleanup
108    pointer needed for later doing the cleanup.  */
109 extern struct cleanup * save_inferior_ptid (void);
110
111 extern void set_sigint_trap (void);
112
113 extern void clear_sigint_trap (void);
114
115 /* Set/get file name for default use for standard in/out in the inferior.  */
116
117 extern void set_inferior_io_terminal (const char *terminal_name);
118 extern const char *get_inferior_io_terminal (void);
119
120 /* Collected pid, tid, etc. of the debugged inferior.  When there's
121    no inferior, PIDGET (inferior_ptid) will be 0.  */
122
123 extern ptid_t inferior_ptid;
124
125 /* Are we simulating synchronous execution? This is used in async gdb
126    to implement the 'run', 'continue' etc commands, which will not
127    redisplay the prompt until the execution is actually over.  */
128 extern int sync_execution;
129
130 /* Inferior environment.  */
131
132 extern void clear_proceed_status (void);
133
134 extern void proceed (CORE_ADDR, enum target_signal, int);
135
136 extern int sched_multi;
137
138 /* When set, stop the 'step' command if we enter a function which has
139    no line number information.  The normal behavior is that we step
140    over such function.  */
141 extern int step_stop_if_no_debug;
142
143 /* If set, the inferior should be controlled in non-stop mode.  In
144    this mode, each thread is controlled independently.  Execution
145    commands apply only to the selected thread by default, and stop
146    events stop only the thread that had the event -- the other threads
147    are kept running freely.  */
148 extern int non_stop;
149
150 /* If set (default), when following a fork, GDB will detach from one
151    the fork branches, child or parent.  Exactly which branch is
152    detached depends on 'set follow-fork-mode' setting.  */
153 extern int detach_fork;
154
155 extern void generic_mourn_inferior (void);
156
157 extern void terminal_save_ours (void);
158
159 extern void terminal_ours (void);
160
161 extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
162                                               struct type *type,
163                                               const gdb_byte *buf);
164 extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
165                                          struct type *type, gdb_byte *buf,
166                                          CORE_ADDR addr);
167 extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
168                                             struct type *type,
169                                             const gdb_byte *buf);
170 extern void address_to_signed_pointer (struct gdbarch *gdbarch,
171                                        struct type *type, gdb_byte *buf,
172                                        CORE_ADDR addr);
173
174 extern void wait_for_inferior (void);
175
176 extern void prepare_for_detach (void);
177
178 extern void fetch_inferior_event (void *);
179
180 extern void init_wait_for_inferior (void);
181
182 extern void close_exec_file (void);
183
184 extern void reopen_exec_file (void);
185
186 /* The `resume' routine should only be called in special circumstances.
187    Normally, use `proceed', which handles a lot of bookkeeping.  */
188
189 extern void resume (int, enum target_signal);
190
191 extern ptid_t user_visible_resume_ptid (int step);
192
193 extern void insert_step_resume_breakpoint_at_sal (struct gdbarch *,
194                                                   struct symtab_and_line ,
195                                                   struct frame_id);
196
197 /* From misc files */
198
199 extern void default_print_registers_info (struct gdbarch *gdbarch,
200                                           struct ui_file *file,
201                                           struct frame_info *frame,
202                                           int regnum, int all);
203
204 extern void child_terminal_info (char *, int);
205
206 extern void term_info (char *, int);
207
208 extern void terminal_ours_for_output (void);
209
210 extern void terminal_inferior (void);
211
212 extern void terminal_init_inferior (void);
213
214 extern void terminal_init_inferior_with_pgrp (int pgrp);
215
216 /* From fork-child.c */
217
218 extern int fork_inferior (char *, char *, char **,
219                           void (*)(void),
220                           void (*)(int), void (*)(void), char *);
221
222
223 extern void startup_inferior (int);
224
225 extern char *construct_inferior_arguments (int, char **);
226
227 /* From infrun.c */
228
229 extern int debug_infrun;
230
231 extern int stop_on_solib_events;
232
233 extern void start_remote (int from_tty);
234
235 extern void normal_stop (void);
236
237 extern int signal_stop_state (int);
238
239 extern int signal_print_state (int);
240
241 extern int signal_pass_state (int);
242
243 extern int signal_stop_update (int, int);
244
245 extern int signal_print_update (int, int);
246
247 extern int signal_pass_update (int, int);
248
249 extern void get_last_target_status(ptid_t *ptid,
250                                    struct target_waitstatus *status);
251
252 extern void follow_inferior_reset_breakpoints (void);
253
254 /* Throw an error indicating the current thread is running.  */
255 extern void error_is_running (void);
256
257 /* Calls error_is_running if the current thread is running.  */
258 extern void ensure_not_running (void);
259
260 void set_step_info (struct frame_info *frame, struct symtab_and_line sal);
261
262 /* From infcmd.c */
263
264 extern void post_create_inferior (struct target_ops *, int);
265
266 extern void attach_command (char *, int);
267
268 extern char *get_inferior_args (void);
269
270 extern void set_inferior_args (char *);
271
272 extern void set_inferior_args_vector (int, char **);
273
274 extern void registers_info (char *, int);
275
276 extern void nexti_command (char *, int);
277
278 extern void stepi_command (char *, int);
279
280 extern void continue_1 (int all_threads);
281
282 extern void continue_command (char *, int);
283
284 extern void interrupt_target_command (char *args, int from_tty);
285
286 extern void interrupt_target_1 (int all_threads);
287
288 extern void delete_longjmp_breakpoint_cleanup (void *arg);
289
290 extern void detach_command (char *, int);
291
292 extern void notice_new_inferior (ptid_t, int, int);
293
294 /* Address at which inferior stopped.  */
295
296 extern CORE_ADDR stop_pc;
297
298 /* Nonzero if stopped due to completion of a stack dummy routine.  */
299
300 extern enum stop_stack_kind stop_stack_dummy;
301
302 /* Nonzero if program stopped due to a random (unexpected) signal in
303    inferior process.  */
304
305 extern int stopped_by_random_signal;
306
307 /* STEP_OVER_ALL means step over all subroutine calls.
308    STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
309    STEP_OVER_NONE means don't step over any subroutine calls.  */
310
311 enum step_over_calls_kind
312   {
313     STEP_OVER_NONE,
314     STEP_OVER_ALL,
315     STEP_OVER_UNDEBUGGABLE
316   };
317
318 /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
319    will handle it themselves.  STOP_QUIETLY is used when running in
320    the shell before the child program has been exec'd and when running
321    through shared library loading.  STOP_QUIETLY_REMOTE is used when
322    setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
323    except that there is no need to hide a signal.  */
324
325 /* It is also used after attach, due to attaching to a process.  This
326    is a bit trickier.  When doing an attach, the kernel stops the
327    debuggee with a SIGSTOP.  On newer GNU/Linux kernels (>= 2.5.61)
328    the handling of SIGSTOP for a ptraced process has changed.  Earlier
329    versions of the kernel would ignore these SIGSTOPs, while now
330    SIGSTOP is treated like any other signal, i.e. it is not muffled.
331    
332    If the gdb user does a 'continue' after the 'attach', gdb passes
333    the global variable stop_signal (which stores the signal from the
334    attach, SIGSTOP) to the ptrace(PTRACE_CONT,...)  call.  This is
335    problematic, because the kernel doesn't ignore such SIGSTOP
336    now.  I.e. it is reported back to gdb, which in turn presents it
337    back to the user.
338  
339    To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
340    gdb to clear the value of stop_signal after the attach, so that it
341    is not passed back down to the kernel.  */
342
343 enum stop_kind
344   {
345     NO_STOP_QUIETLY = 0,
346     STOP_QUIETLY,
347     STOP_QUIETLY_REMOTE,
348     STOP_QUIETLY_NO_SIGSTOP
349   };
350
351 /* Reverse execution.  */
352 enum exec_direction_kind
353   {
354     EXEC_FORWARD,
355     EXEC_REVERSE
356   };
357
358 /* The current execution direction.  This should only be set to enum
359    exec_direction_kind values.  It is only an int to make it
360    compatible with make_cleanup_restore_integer.  */
361 extern int execution_direction;
362
363 /* Save register contents here when executing a "finish" command or are
364    about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
365    Thus this contains the return value from the called function (assuming
366    values are returned in a register).  */
367
368 extern struct regcache *stop_registers;
369
370 /* True if we are debugging displaced stepping.  */
371 extern int debug_displaced;
372
373 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline.  */
374 void displaced_step_dump_bytes (struct ui_file *file,
375                                 const gdb_byte *buf, size_t len);
376
377 struct displaced_step_closure *get_displaced_step_closure_by_addr (CORE_ADDR addr);
378 \f
379 /* Possible values for gdbarch_call_dummy_location.  */
380 #define ON_STACK 1
381 #define AT_ENTRY_POINT 4
382 #define AT_SYMBOL 5
383
384 /* If STARTUP_WITH_SHELL is set, GDB's "run"
385    will attempts to start up the debugee under a shell.
386    This is in order for argument-expansion to occur.  E.g.,
387    (gdb) run *
388    The "*" gets expanded by the shell into a list of files.
389    While this is a nice feature, it turns out to interact badly
390    with some of the catch-fork/catch-exec features we have added.
391    In particular, if the shell does any fork/exec's before
392    the exec of the target program, that can confuse GDB.
393    To disable this feature, set STARTUP_WITH_SHELL to 0.
394    To enable this feature, set STARTUP_WITH_SHELL to 1.
395    The catch-exec traps expected during start-up will
396    be 1 if target is not started up with a shell, 2 if it is.
397    - RT
398    If you disable this, you need to decrement
399    START_INFERIOR_TRAPS_EXPECTED in tm.h.  */
400 #define STARTUP_WITH_SHELL 1
401 #if !defined(START_INFERIOR_TRAPS_EXPECTED)
402 #define START_INFERIOR_TRAPS_EXPECTED   2
403 #endif
404
405 struct private_inferior;
406
407 /* Inferior process specific part of `struct infcall_control_state'.
408
409    Inferior thread counterpart is `struct thread_control_state'.  */
410
411 struct inferior_control_state
412 {
413   /* See the definition of stop_kind above.  */
414   enum stop_kind stop_soon;
415 };
416
417 /* Inferior process specific part of `struct infcall_suspend_state'.
418
419    Inferior thread counterpart is `struct thread_suspend_state'.  */
420
421 struct inferior_suspend_state
422 {
423 };
424
425 /* GDB represents the state of each program execution with an object
426    called an inferior.  An inferior typically corresponds to a process
427    but is more general and applies also to targets that do not have a
428    notion of processes.  Each run of an executable creates a new
429    inferior, as does each attachment to an existing process.
430    Inferiors have unique internal identifiers that are different from
431    target process ids.  Each inferior may in turn have multiple
432    threads running in it.  */
433
434 struct inferior
435 {
436   /* Pointer to next inferior in singly-linked list of inferiors.  */
437   struct inferior *next;
438
439   /* Convenient handle (GDB inferior id).  Unique across all
440      inferiors.  */
441   int num;
442
443   /* Actual target inferior id, usually, a process id.  This matches
444      the ptid_t.pid member of threads of this inferior.  */
445   int pid;
446
447   /* State of GDB control of inferior process execution.
448      See `struct inferior_control_state'.  */
449   struct inferior_control_state control;
450
451   /* State of inferior process to restore after GDB is done with an inferior
452      call.  See `struct inferior_suspend_state'.  */
453   struct inferior_suspend_state suspend;
454
455   /* True if this was an auto-created inferior, e.g. created from
456      following a fork; false, if this inferior was manually added by
457      the user, and we should not attempt to prune it
458      automatically.  */
459   int removable;
460
461   /* The address space bound to this inferior.  */
462   struct address_space *aspace;
463
464   /* The program space bound to this inferior.  */
465   struct program_space *pspace;
466
467   /* The arguments string to use when running.  */
468   char *args;
469
470   /* The size of elements in argv.  */
471   int argc;
472
473   /* The vector version of arguments.  If ARGC is nonzero,
474      then we must compute ARGS from this (via the target).
475      This is always coming from main's argv and therefore
476      should never be freed.  */
477   char **argv;
478
479   /* The name of terminal device to use for I/O.  */
480   char *terminal;
481
482   /* Environment to use for running inferior,
483      in format described in environ.h.  */
484   struct gdb_environ *environment;
485
486   /* Nonzero if this child process was attached rather than
487      forked.  */
488   int attach_flag;
489
490   /* If this inferior is a vfork child, then this is the pointer to
491      its vfork parent, if GDB is still attached to it.  */
492   struct inferior *vfork_parent;
493
494   /* If this process is a vfork parent, this is the pointer to the
495      child.  Since a vfork parent is left frozen by the kernel until
496      the child execs or exits, a process can only have one vfork child
497      at a given time.  */
498   struct inferior *vfork_child;
499
500   /* True if this inferior should be detached when it's vfork sibling
501      exits or execs.  */
502   int pending_detach;
503
504   /* True if this inferior is a vfork parent waiting for a vfork child
505      not under our control to be done with the shared memory region,
506      either by exiting or execing.  */
507   int waiting_for_vfork_done;
508
509   /* True if we're in the process of detaching from this inferior.  */
510   int detaching;
511
512   /* What is left to do for an execution command after any thread of
513      this inferior stops.  For continuations associated with a
514      specific thread, see `struct thread_info'.  */
515   struct continuation *continuations;
516
517   /* Private data used by the target vector implementation.  */
518   struct private_inferior *private;
519
520   /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
521      In this case, the EXIT_CODE field is also valid.  */
522   int has_exit_code;
523   LONGEST exit_code;
524
525   /* We keep a count of the number of times the user has requested a
526      particular syscall to be tracked, and pass this information to the
527      target.  This lets capable targets implement filtering directly.  */
528
529   /* Number of times that "any" syscall is requested.  */
530   int any_syscall_count;
531
532   /* Count of each system call.  */
533   VEC(int) *syscalls_counts;
534
535   /* This counts all syscall catch requests, so we can readily determine
536      if any catching is necessary.  */
537   int total_syscalls_count;
538
539   /* Per inferior data-pointers required by other GDB modules.  */
540   void **data;
541   unsigned num_data;
542 };
543
544 /* Keep a registry of per-inferior data-pointers required by other GDB
545    modules.  */
546
547 extern const struct inferior_data *register_inferior_data (void);
548 extern const struct inferior_data *register_inferior_data_with_cleanup
549   (void (*cleanup) (struct inferior *, void *));
550 extern void clear_inferior_data (struct inferior *inf);
551 extern void set_inferior_data (struct inferior *inf,
552                                const struct inferior_data *data, void *value);
553 extern void *inferior_data (struct inferior *inf,
554                             const struct inferior_data *data);
555
556 /* Create an empty inferior list, or empty the existing one.  */
557 extern void init_inferior_list (void);
558
559 /* Add an inferior to the inferior list, print a message that a new
560    inferior is found, and return the pointer to the new inferior.
561    Caller may use this pointer to initialize the private inferior
562    data.  */
563 extern struct inferior *add_inferior (int pid);
564
565 /* Same as add_inferior, but don't print new inferior notifications to
566    the CLI.  */
567 extern struct inferior *add_inferior_silent (int pid);
568
569 /* Delete an existing inferior list entry, due to inferior exit.  */
570 extern void delete_inferior (int pid);
571
572 extern void delete_inferior_1 (struct inferior *todel, int silent);
573
574 /* Same as delete_inferior, but don't print new inferior notifications
575    to the CLI.  */
576 extern void delete_inferior_silent (int pid);
577
578 /* Delete an existing inferior list entry, due to inferior detaching.  */
579 extern void detach_inferior (int pid);
580
581 extern void exit_inferior (int pid);
582
583 extern void exit_inferior_silent (int pid);
584
585 extern void exit_inferior_num_silent (int num);
586
587 extern void inferior_appeared (struct inferior *inf, int pid);
588
589 /* Get rid of all inferiors.  */
590 extern void discard_all_inferiors (void);
591
592 /* Translate the integer inferior id (GDB's homegrown id, not the system's)
593    into a "pid" (which may be overloaded with extra inferior information).  */
594 extern int gdb_inferior_id_to_pid (int);
595
596 /* Translate a target 'pid' into the integer inferior id (GDB's
597    homegrown id, not the system's).  */
598 extern int pid_to_gdb_inferior_id (int pid);
599
600 /* Boolean test for an already-known pid.  */
601 extern int in_inferior_list (int pid);
602
603 /* Boolean test for an already-known inferior id (GDB's homegrown id,
604    not the system's).  */
605 extern int valid_gdb_inferior_id (int num);
606
607 /* Search function to lookup an inferior by target 'pid'.  */
608 extern struct inferior *find_inferior_pid (int pid);
609
610 /* Search function to lookup an inferior by GDB 'num'.  */
611 extern struct inferior *find_inferior_id (int num);
612
613 /* Find an inferior bound to PSPACE.  */
614 extern struct inferior *
615   find_inferior_for_program_space (struct program_space *pspace);
616
617 /* Inferior iterator function.
618
619    Calls a callback function once for each inferior, so long as the
620    callback function returns false.  If the callback function returns
621    true, the iteration will end and the current inferior will be
622    returned.  This can be useful for implementing a search for a
623    inferior with arbitrary attributes, or for applying some operation
624    to every inferior.
625
626    It is safe to delete the iterated inferior from the callback.  */
627 extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
628                                                          void *),
629                                                 void *);
630
631 /* Returns true if the inferior list is not empty.  */
632 extern int have_inferiors (void);
633
634 /* Returns true if there are any live inferiors in the inferior list
635    (not cores, not executables, real live processes).  */
636 extern int have_live_inferiors (void);
637
638 /* Return a pointer to the current inferior.  It is an error to call
639    this if there is no current inferior.  */
640 extern struct inferior *current_inferior (void);
641
642 extern void set_current_inferior (struct inferior *);
643
644 extern struct cleanup *save_current_inferior (void);
645
646 extern struct inferior *inferior_list;
647
648 /* Prune away automatically added inferiors that aren't required
649    anymore.  */
650 extern void prune_inferiors (void);
651
652 extern int number_of_inferiors (void);
653
654 extern struct inferior *add_inferior_with_spaces (void);
655
656 extern void update_observer_mode (void);
657
658 #endif /* !defined (INFERIOR_H) */