1 /* Variables that describe the inferior process running under GDB:
2 Where it is, why it stopped, and how to step it.
4 Copyright (C) 1986-2014 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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/>. */
21 #if !defined (INFERIOR_H)
24 struct target_waitstatus;
32 struct target_desc_info;
37 #include "breakpoint.h"
39 /* For enum gdb_signal. */
42 /* For struct frame_id. */
45 #include "progspace.h"
48 struct infcall_suspend_state;
49 struct infcall_control_state;
51 extern struct infcall_suspend_state *save_infcall_suspend_state (void);
52 extern struct infcall_control_state *save_infcall_control_state (void);
54 extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
55 extern void restore_infcall_control_state (struct infcall_control_state *);
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 *);
62 extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
63 extern void discard_infcall_control_state (struct infcall_control_state *);
65 extern struct regcache *
66 get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
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);
73 extern void set_sigint_trap (void);
75 extern void clear_sigint_trap (void);
77 /* Set/get file name for default use for standard in/out in the inferior. */
79 extern void set_inferior_io_terminal (const char *terminal_name);
80 extern const char *get_inferior_io_terminal (void);
82 /* Collected pid, tid, etc. of the debugged inferior. When there's
83 no inferior, ptid_get_pid (inferior_ptid) will be 0. */
85 extern ptid_t inferior_ptid;
87 extern void generic_mourn_inferior (void);
89 extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
92 extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
93 struct type *type, gdb_byte *buf,
95 extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
98 extern void address_to_signed_pointer (struct gdbarch *gdbarch,
99 struct type *type, gdb_byte *buf,
102 extern void reopen_exec_file (void);
104 /* From misc files */
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);
111 extern void child_terminal_info (struct target_ops *self, const char *, int);
113 extern void term_info (char *, int);
115 extern void child_terminal_save_ours (struct target_ops *self);
117 extern void child_terminal_ours (struct target_ops *self);
119 extern void child_terminal_ours_for_output (struct target_ops *self);
121 extern void child_terminal_inferior (struct target_ops *self);
123 extern void child_terminal_init (struct target_ops *self);
125 extern void child_terminal_init_with_pgrp (int pgrp);
127 /* From fork-child.c */
129 extern int fork_inferior (char *, char *, char **,
131 void (*)(int), void (*)(void), char *,
132 void (*)(const char *,
133 char * const *, char * const *));
136 extern void startup_inferior (int);
138 extern char *construct_inferior_arguments (int, char **);
142 extern void post_create_inferior (struct target_ops *, int);
144 extern void attach_command (char *, int);
146 extern char *get_inferior_args (void);
148 extern void set_inferior_args (char *);
150 extern void set_inferior_args_vector (int, char **);
152 extern void registers_info (char *, int);
154 extern void continue_1 (int all_threads);
156 extern void interrupt_target_1 (int all_threads);
158 extern void delete_longjmp_breakpoint_cleanup (void *arg);
160 extern void detach_command (char *, int);
162 extern void notice_new_inferior (ptid_t, int, int);
164 extern struct value *get_return_value (struct value *function,
165 struct type *value_type);
167 /* Prepare for execution command. TARGET is the target that will run
168 the command. BACKGROUND determines whether this is a foreground
169 (synchronous) or background (asynchronous) command. */
171 extern void prepare_execution_command (struct target_ops *target,
174 /* Whether to start up the debuggee under a shell.
176 If startup-with-shell is set, GDB's "run" will attempt to start up
177 the debuggee under a shell.
179 This is in order for argument-expansion to occur. E.g.,
183 The "*" gets expanded by the shell into a list of files.
185 While this is a nice feature, it may be handy to bypass the shell
186 in some cases. To disable this feature, do "set startup-with-shell
189 The catch-exec traps expected during start-up will be one more if
190 the target is started up with a shell. */
191 extern int startup_with_shell;
193 /* Address at which inferior stopped. */
195 extern CORE_ADDR stop_pc;
197 /* Nonzero if stopped due to completion of a stack dummy routine. */
199 extern enum stop_stack_kind stop_stack_dummy;
201 /* Nonzero if program stopped due to a random (unexpected) signal in
204 extern int stopped_by_random_signal;
206 /* STEP_OVER_ALL means step over all subroutine calls.
207 STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
208 STEP_OVER_NONE means don't step over any subroutine calls. */
210 enum step_over_calls_kind
214 STEP_OVER_UNDEBUGGABLE
217 /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
218 will handle it themselves. STOP_QUIETLY is used when running in
219 the shell before the child program has been exec'd and when running
220 through shared library loading. STOP_QUIETLY_REMOTE is used when
221 setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
222 except that there is no need to hide a signal. */
224 /* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
225 When doing an attach, the kernel stops the debuggee with a SIGSTOP.
226 On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
227 a ptraced process has changed. Earlier versions of the kernel
228 would ignore these SIGSTOPs, while now SIGSTOP is treated like any
229 other signal, i.e. it is not muffled.
231 If the gdb user does a 'continue' after the 'attach', gdb passes
232 the global variable stop_signal (which stores the signal from the
233 attach, SIGSTOP) to the ptrace(PTRACE_CONT,...) call. This is
234 problematic, because the kernel doesn't ignore such SIGSTOP
235 now. I.e. it is reported back to gdb, which in turn presents it
238 To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
239 gdb to clear the value of stop_signal after the attach, so that it
240 is not passed back down to the kernel. */
247 STOP_QUIETLY_NO_SIGSTOP
251 /* Possible values for gdbarch_call_dummy_location. */
253 #define AT_ENTRY_POINT 4
255 /* Number of traps that happen between exec'ing the shell to run an
256 inferior and when we finally get to the inferior code, not counting
257 the exec for the shell. This is 1 on most implementations.
258 Overridden in nm.h files. */
259 #if !defined(START_INFERIOR_TRAPS_EXPECTED)
260 #define START_INFERIOR_TRAPS_EXPECTED 1
263 struct private_inferior;
265 /* Inferior process specific part of `struct infcall_control_state'.
267 Inferior thread counterpart is `struct thread_control_state'. */
269 struct inferior_control_state
271 /* See the definition of stop_kind above. */
272 enum stop_kind stop_soon;
275 /* Inferior process specific part of `struct infcall_suspend_state'.
277 Inferior thread counterpart is `struct thread_suspend_state'. */
279 #if 0 /* Currently unused and empty structures are not valid C. */
280 struct inferior_suspend_state
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. */
296 /* Pointer to next inferior in singly-linked list of inferiors. */
297 struct inferior *next;
299 /* Convenient handle (GDB inferior id). Unique across all
303 /* Actual target inferior id, usually, a process id. This matches
304 the ptid_t.pid member of threads of this inferior. */
306 /* True if the PID was actually faked by GDB. */
309 /* State of GDB control of inferior process execution.
310 See `struct inferior_control_state'. */
311 struct inferior_control_state control;
313 /* State of inferior process to restore after GDB is done with an inferior
314 call. See `struct inferior_suspend_state'. */
315 #if 0 /* Currently unused and empty structures are not valid C. */
316 struct inferior_suspend_state suspend;
319 /* True if this was an auto-created inferior, e.g. created from
320 following a fork; false, if this inferior was manually added by
321 the user, and we should not attempt to prune it
325 /* The address space bound to this inferior. */
326 struct address_space *aspace;
328 /* The program space bound to this inferior. */
329 struct program_space *pspace;
331 /* The arguments string to use when running. */
334 /* The size of elements in argv. */
337 /* The vector version of arguments. If ARGC is nonzero,
338 then we must compute ARGS from this (via the target).
339 This is always coming from main's argv and therefore
340 should never be freed. */
343 /* The name of terminal device to use for I/O. */
346 /* Environment to use for running inferior,
347 in format described in environ.h. */
348 struct gdb_environ *environment;
350 /* Nonzero if this child process was attached rather than
354 /* If this inferior is a vfork child, then this is the pointer to
355 its vfork parent, if GDB is still attached to it. */
356 struct inferior *vfork_parent;
358 /* If this process is a vfork parent, this is the pointer to the
359 child. Since a vfork parent is left frozen by the kernel until
360 the child execs or exits, a process can only have one vfork child
362 struct inferior *vfork_child;
364 /* True if this inferior should be detached when it's vfork sibling
368 /* True if this inferior is a vfork parent waiting for a vfork child
369 not under our control to be done with the shared memory region,
370 either by exiting or execing. */
371 int waiting_for_vfork_done;
373 /* True if we're in the process of detaching from this inferior. */
376 /* What is left to do for an execution command after any thread of
377 this inferior stops. For continuations associated with a
378 specific thread, see `struct thread_info'. */
379 struct continuation *continuations;
381 /* Private data used by the target vector implementation. */
382 struct private_inferior *private;
384 /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
385 In this case, the EXIT_CODE field is also valid. */
389 /* Default flags to pass to the symbol reading functions. These are
390 used whenever a new objfile is created. The valid values come
391 from enum symfile_add_flags. */
394 /* Info about an inferior's target description (if it's fetched; the
395 user supplied description's filename, if any; etc.). */
396 struct target_desc_info *tdesc_info;
398 /* The architecture associated with the inferior through the
399 connection to the target.
401 The architecture vector provides some information that is really
402 a property of the inferior, accessed through a particular target:
403 ptrace operations; the layout of certain RSP packets; the
404 solib_ops vector; etc. To differentiate architecture accesses to
405 per-inferior/target properties from
406 per-thread/per-frame/per-objfile properties, accesses to
407 per-inferior/target properties should be made through
409 struct gdbarch *gdbarch;
411 /* Per inferior data-pointers required by other GDB modules. */
415 /* Keep a registry of per-inferior data-pointers required by other GDB
418 DECLARE_REGISTRY (inferior);
420 /* Create an empty inferior list, or empty the existing one. */
421 extern void init_inferior_list (void);
423 /* Add an inferior to the inferior list, print a message that a new
424 inferior is found, and return the pointer to the new inferior.
425 Caller may use this pointer to initialize the private inferior
427 extern struct inferior *add_inferior (int pid);
429 /* Same as add_inferior, but don't print new inferior notifications to
431 extern struct inferior *add_inferior_silent (int pid);
433 /* Delete an existing inferior list entry, due to inferior exit. */
434 extern void delete_inferior (int pid);
436 extern void delete_inferior_1 (struct inferior *todel, int silent);
438 /* Same as delete_inferior, but don't print new inferior notifications
440 extern void delete_inferior_silent (int pid);
442 /* Delete an existing inferior list entry, due to inferior detaching. */
443 extern void detach_inferior (int pid);
445 extern void exit_inferior (int pid);
447 extern void exit_inferior_silent (int pid);
449 extern void exit_inferior_num_silent (int num);
451 extern void inferior_appeared (struct inferior *inf, int pid);
453 /* Get rid of all inferiors. */
454 extern void discard_all_inferiors (void);
456 /* Translate the integer inferior id (GDB's homegrown id, not the system's)
457 into a "pid" (which may be overloaded with extra inferior information). */
458 extern int gdb_inferior_id_to_pid (int);
460 /* Translate a target 'pid' into the integer inferior id (GDB's
461 homegrown id, not the system's). */
462 extern int pid_to_gdb_inferior_id (int pid);
464 /* Boolean test for an already-known pid. */
465 extern int in_inferior_list (int pid);
467 /* Boolean test for an already-known inferior id (GDB's homegrown id,
468 not the system's). */
469 extern int valid_gdb_inferior_id (int num);
471 /* Search function to lookup an inferior by target 'pid'. */
472 extern struct inferior *find_inferior_pid (int pid);
474 /* Search function to lookup an inferior by GDB 'num'. */
475 extern struct inferior *find_inferior_id (int num);
477 /* Find an inferior bound to PSPACE. */
478 extern struct inferior *
479 find_inferior_for_program_space (struct program_space *pspace);
481 /* Inferior iterator function.
483 Calls a callback function once for each inferior, so long as the
484 callback function returns false. If the callback function returns
485 true, the iteration will end and the current inferior will be
486 returned. This can be useful for implementing a search for a
487 inferior with arbitrary attributes, or for applying some operation
490 It is safe to delete the iterated inferior from the callback. */
491 extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
495 /* Returns true if the inferior list is not empty. */
496 extern int have_inferiors (void);
498 /* Returns true if there are any live inferiors in the inferior list
499 (not cores, not executables, real live processes). */
500 extern int have_live_inferiors (void);
502 /* Return a pointer to the current inferior. It is an error to call
503 this if there is no current inferior. */
504 extern struct inferior *current_inferior (void);
506 extern void set_current_inferior (struct inferior *);
508 extern struct cleanup *save_current_inferior (void);
510 /* Traverse all inferiors. */
512 #define ALL_INFERIORS(I) \
513 for ((I) = inferior_list; (I); (I) = (I)->next)
515 extern struct inferior *inferior_list;
517 /* Prune away automatically added inferiors that aren't required
519 extern void prune_inferiors (void);
521 extern int number_of_inferiors (void);
523 extern struct inferior *add_inferior_with_spaces (void);
525 #endif /* !defined (INFERIOR_H) */