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-2019 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
;
38 #include "breakpoint.h"
40 /* For enum gdb_signal. */
43 /* For struct frame_id. */
46 /* For gdb_environ. */
49 #include "progspace.h"
52 #include "symfile-add-flags.h"
53 #include "common/refcounted-object.h"
55 #include "common-inferior.h"
56 #include "gdbthread.h"
58 struct infcall_suspend_state
;
59 struct infcall_control_state
;
61 extern void restore_infcall_suspend_state (struct infcall_suspend_state
*);
62 extern void restore_infcall_control_state (struct infcall_control_state
*);
64 /* A deleter for infcall_suspend_state that calls
65 restore_infcall_suspend_state. */
66 struct infcall_suspend_state_deleter
68 void operator() (struct infcall_suspend_state
*state
) const
70 restore_infcall_suspend_state (state
);
74 /* A unique_ptr specialization for infcall_suspend_state. */
75 typedef std::unique_ptr
<infcall_suspend_state
, infcall_suspend_state_deleter
>
76 infcall_suspend_state_up
;
78 extern infcall_suspend_state_up
save_infcall_suspend_state ();
80 /* A deleter for infcall_control_state that calls
81 restore_infcall_control_state. */
82 struct infcall_control_state_deleter
84 void operator() (struct infcall_control_state
*state
) const
86 restore_infcall_control_state (state
);
90 /* A unique_ptr specialization for infcall_control_state. */
91 typedef std::unique_ptr
<infcall_control_state
, infcall_control_state_deleter
>
92 infcall_control_state_up
;
94 extern infcall_control_state_up
save_infcall_control_state ();
96 extern void discard_infcall_suspend_state (struct infcall_suspend_state
*);
97 extern void discard_infcall_control_state (struct infcall_control_state
*);
99 extern readonly_detached_regcache
*
100 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*);
102 extern void set_sigint_trap (void);
104 extern void clear_sigint_trap (void);
106 /* Set/get file name for default use for standard in/out in the inferior. */
108 extern void set_inferior_io_terminal (const char *terminal_name
);
109 extern const char *get_inferior_io_terminal (void);
111 /* Collected pid, tid, etc. of the debugged inferior. When there's
112 no inferior, inferior_ptid.pid () will be 0. */
114 extern ptid_t inferior_ptid
;
116 extern void generic_mourn_inferior (void);
118 extern CORE_ADDR
unsigned_pointer_to_address (struct gdbarch
*gdbarch
,
120 const gdb_byte
*buf
);
121 extern void unsigned_address_to_pointer (struct gdbarch
*gdbarch
,
122 struct type
*type
, gdb_byte
*buf
,
124 extern CORE_ADDR
signed_pointer_to_address (struct gdbarch
*gdbarch
,
126 const gdb_byte
*buf
);
127 extern void address_to_signed_pointer (struct gdbarch
*gdbarch
,
128 struct type
*type
, gdb_byte
*buf
,
131 extern void reopen_exec_file (void);
133 /* From misc files */
135 extern void default_print_registers_info (struct gdbarch
*gdbarch
,
136 struct ui_file
*file
,
137 struct frame_info
*frame
,
138 int regnum
, int all
);
140 /* Default implementation of gdbarch_print_float_info. Print
141 the values of all floating point registers. */
143 extern void default_print_float_info (struct gdbarch
*gdbarch
,
144 struct ui_file
*file
,
145 struct frame_info
*frame
,
148 extern void child_terminal_info (struct target_ops
*self
, const char *, int);
150 extern void info_terminal_command (char *, int);
152 extern void child_terminal_ours (struct target_ops
*self
);
154 extern void child_terminal_ours_for_output (struct target_ops
*self
);
156 extern void child_terminal_inferior (struct target_ops
*self
);
158 extern void child_terminal_save_inferior (struct target_ops
*self
);
160 extern void child_terminal_init (struct target_ops
*self
);
162 extern void child_terminal_init_with_pgrp (int pgrp
);
164 extern void child_pass_ctrlc (struct target_ops
*self
);
166 extern void child_interrupt (struct target_ops
*self
);
168 /* From fork-child.c */
170 /* Helper function to call STARTUP_INFERIOR with PID and NUM_TRAPS.
171 This function already calls set_executing. Return the ptid_t from
173 extern ptid_t
gdb_startup_inferior (pid_t pid
, int num_traps
);
175 extern char *construct_inferior_arguments (int, char **);
179 /* Initial inferior setup. Determines the exec file is not yet known,
180 takes any necessary post-attaching actions, fetches the target
181 description and syncs the shared library list. */
183 extern void setup_inferior (int from_tty
);
185 extern void post_create_inferior (struct target_ops
*, int);
187 extern void attach_command (const char *, int);
189 extern const char *get_inferior_args (void);
191 extern void set_inferior_args (const char *);
193 extern void set_inferior_args_vector (int, char **);
195 extern void registers_info (const char *, int);
197 extern void continue_1 (int all_threads
);
199 extern void interrupt_target_1 (int all_threads
);
201 extern void delete_longjmp_breakpoint_cleanup (void *arg
);
203 extern void detach_command (const char *, int);
205 extern void notice_new_inferior (struct thread_info
*, int, int);
207 extern struct value
*get_return_value (struct value
*function
,
208 struct type
*value_type
);
210 /* Prepare for execution command. TARGET is the target that will run
211 the command. BACKGROUND determines whether this is a foreground
212 (synchronous) or background (asynchronous) command. */
214 extern void prepare_execution_command (struct target_ops
*target
,
217 /* Whether to start up the debuggee under a shell.
219 If startup-with-shell is set, GDB's "run" will attempt to start up
220 the debuggee under a shell.
222 This is in order for argument-expansion to occur. E.g.,
226 The "*" gets expanded by the shell into a list of files.
228 While this is a nice feature, it may be handy to bypass the shell
229 in some cases. To disable this feature, do "set startup-with-shell
232 The catch-exec traps expected during start-up will be one more if
233 the target is started up with a shell. */
234 extern int startup_with_shell
;
236 /* Nonzero if stopped due to completion of a stack dummy routine. */
238 extern enum stop_stack_kind stop_stack_dummy
;
240 /* Nonzero if program stopped due to a random (unexpected) signal in
243 extern int stopped_by_random_signal
;
245 /* Print notices on inferior events (attach, detach, etc.), set with
246 `set print inferior-events'. */
247 extern int print_inferior_events
;
249 /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
250 will handle it themselves. STOP_QUIETLY is used when running in
251 the shell before the child program has been exec'd and when running
252 through shared library loading. STOP_QUIETLY_REMOTE is used when
253 setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
254 except that there is no need to hide a signal. */
256 /* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
257 When doing an attach, the kernel stops the debuggee with a SIGSTOP.
258 On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
259 a ptraced process has changed. Earlier versions of the kernel
260 would ignore these SIGSTOPs, while now SIGSTOP is treated like any
261 other signal, i.e. it is not muffled.
263 If the gdb user does a 'continue' after the 'attach', gdb passes
264 the global variable stop_signal (which stores the signal from the
265 attach, SIGSTOP) to the ptrace(PTRACE_CONT,...) call. This is
266 problematic, because the kernel doesn't ignore such SIGSTOP
267 now. I.e. it is reported back to gdb, which in turn presents it
270 To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
271 gdb to clear the value of stop_signal after the attach, so that it
272 is not passed back down to the kernel. */
279 STOP_QUIETLY_NO_SIGSTOP
283 /* Possible values for gdbarch_call_dummy_location. */
285 #define AT_ENTRY_POINT 4
287 /* Base class for target-specific inferior data. */
289 struct private_inferior
291 virtual ~private_inferior () = 0;
294 /* Inferior process specific part of `struct infcall_control_state'.
296 Inferior thread counterpart is `struct thread_control_state'. */
298 struct inferior_control_state
300 inferior_control_state ()
301 : stop_soon (NO_STOP_QUIETLY
)
305 explicit inferior_control_state (enum stop_kind when
)
310 /* See the definition of stop_kind above. */
311 enum stop_kind stop_soon
;
314 /* Return a pointer to the current inferior. */
315 extern inferior
*current_inferior ();
317 extern void set_current_inferior (inferior
*);
319 /* GDB represents the state of each program execution with an object
320 called an inferior. An inferior typically corresponds to a process
321 but is more general and applies also to targets that do not have a
322 notion of processes. Each run of an executable creates a new
323 inferior, as does each attachment to an existing process.
324 Inferiors have unique internal identifiers that are different from
325 target process ids. Each inferior may in turn have multiple
326 threads running in it.
328 Inferiors are intrusively refcounted objects. Unlike thread
329 objects, being the user-selected inferior is considered a strong
330 reference and is thus accounted for in the inferior object's
331 refcount (see set_current_inferior). When GDB needs to remember
332 the selected inferior to later restore it, GDB temporarily bumps
333 the inferior object's refcount, to prevent something deleting the
334 inferior object before reverting back (e.g., due to a
335 "remove-inferiors" command (see
336 make_cleanup_restore_current_thread). All other inferior
337 references are considered weak references. Inferiors are always
338 listed exactly once in the inferior list, so placing an inferior in
339 the inferior list is an implicit, not counted strong reference. */
341 class inferior
: public refcounted_object
344 explicit inferior (int pid
);
347 /* Returns true if we can delete this inferior. */
348 bool deletable () const { return refcount () == 0; }
350 /* Pointer to next inferior in singly-linked list of inferiors. */
351 struct inferior
*next
= NULL
;
353 /* This inferior's thread list. */
354 thread_info
*thread_list
= nullptr;
356 /* Returns a range adapter covering the inferior's threads,
357 including exited threads. Used like this:
359 for (thread_info *thr : inf->threads ())
362 inf_threads_range
threads ()
363 { return inf_threads_range (this->thread_list
); }
365 /* Returns a range adapter covering the inferior's non-exited
366 threads. Used like this:
368 for (thread_info *thr : inf->non_exited_threads ())
371 inf_non_exited_threads_range
non_exited_threads ()
372 { return inf_non_exited_threads_range (this->thread_list
); }
374 /* Like inferior::threads(), but returns a range adapter that can be
375 used with range-for, safely. I.e., it is safe to delete the
376 currently-iterated thread, like this:
378 for (thread_info *t : inf->threads_safe ())
379 if (some_condition ())
382 inline safe_inf_threads_range
threads_safe ()
383 { return safe_inf_threads_range (this->thread_list
); }
385 /* Convenient handle (GDB inferior id). Unique across all
389 /* Actual target inferior id, usually, a process id. This matches
390 the ptid_t.pid member of threads of this inferior. */
392 /* True if the PID was actually faked by GDB. */
393 bool fake_pid_p
= false;
395 /* The highest thread number this inferior ever had. */
396 int highest_thread_num
= 0;
398 /* State of GDB control of inferior process execution.
399 See `struct inferior_control_state'. */
400 inferior_control_state control
;
402 /* True if this was an auto-created inferior, e.g. created from
403 following a fork; false, if this inferior was manually added by
404 the user, and we should not attempt to prune it
406 bool removable
= false;
408 /* The address space bound to this inferior. */
409 struct address_space
*aspace
= NULL
;
411 /* The program space bound to this inferior. */
412 struct program_space
*pspace
= NULL
;
414 /* The arguments string to use when running. */
417 /* The size of elements in argv. */
420 /* The vector version of arguments. If ARGC is nonzero,
421 then we must compute ARGS from this (via the target).
422 This is always coming from main's argv and therefore
423 should never be freed. */
426 /* The current working directory that will be used when starting
428 gdb::unique_xmalloc_ptr
<char> cwd
;
430 /* The name of terminal device to use for I/O. */
431 char *terminal
= NULL
;
433 /* The terminal state as set by the last target_terminal::terminal_*
435 target_terminal_state terminal_state
= target_terminal_state::is_ours
;
437 /* Environment to use for running inferior,
438 in format described in environ.h. */
439 gdb_environ environment
;
441 /* True if this child process was attached rather than forked. */
442 bool attach_flag
= false;
444 /* If this inferior is a vfork child, then this is the pointer to
445 its vfork parent, if GDB is still attached to it. */
446 inferior
*vfork_parent
= NULL
;
448 /* If this process is a vfork parent, this is the pointer to the
449 child. Since a vfork parent is left frozen by the kernel until
450 the child execs or exits, a process can only have one vfork child
452 inferior
*vfork_child
= NULL
;
454 /* True if this inferior should be detached when it's vfork sibling
456 bool pending_detach
= false;
458 /* True if this inferior is a vfork parent waiting for a vfork child
459 not under our control to be done with the shared memory region,
460 either by exiting or execing. */
461 bool waiting_for_vfork_done
= false;
463 /* True if we're in the process of detaching from this inferior. */
464 bool detaching
= false;
466 /* What is left to do for an execution command after any thread of
467 this inferior stops. For continuations associated with a
468 specific thread, see `struct thread_info'. */
469 continuation
*continuations
= NULL
;
471 /* True if setup_inferior wasn't called for this inferior yet.
472 Until that is done, we must not access inferior memory or
473 registers, as we haven't determined the target
474 architecture/description. */
475 bool needs_setup
= false;
477 /* Private data used by the target vector implementation. */
478 std::unique_ptr
<private_inferior
> priv
;
480 /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
481 In this case, the EXIT_CODE field is also valid. */
482 bool has_exit_code
= false;
483 LONGEST exit_code
= 0;
485 /* Default flags to pass to the symbol reading functions. These are
486 used whenever a new objfile is created. */
487 symfile_add_flags symfile_flags
= 0;
489 /* Info about an inferior's target description (if it's fetched; the
490 user supplied description's filename, if any; etc.). */
491 target_desc_info
*tdesc_info
= NULL
;
493 /* The architecture associated with the inferior through the
494 connection to the target.
496 The architecture vector provides some information that is really
497 a property of the inferior, accessed through a particular target:
498 ptrace operations; the layout of certain RSP packets; the
499 solib_ops vector; etc. To differentiate architecture accesses to
500 per-inferior/target properties from
501 per-thread/per-frame/per-objfile properties, accesses to
502 per-inferior/target properties should be made through
504 struct gdbarch
*gdbarch
= NULL
;
506 /* Data related to displaced stepping. */
507 displaced_step_inferior_state displaced_step_state
;
509 /* Per inferior data-pointers required by other GDB modules. */
513 /* Keep a registry of per-inferior data-pointers required by other GDB
516 DECLARE_REGISTRY (inferior
);
518 /* Add an inferior to the inferior list, print a message that a new
519 inferior is found, and return the pointer to the new inferior.
520 Caller may use this pointer to initialize the private inferior
522 extern struct inferior
*add_inferior (int pid
);
524 /* Same as add_inferior, but don't print new inferior notifications to
526 extern struct inferior
*add_inferior_silent (int pid
);
528 extern void delete_inferior (struct inferior
*todel
);
530 /* Delete an existing inferior list entry, due to inferior detaching. */
531 extern void detach_inferior (inferior
*inf
);
533 extern void exit_inferior (inferior
*inf
);
535 extern void exit_inferior_silent (inferior
*inf
);
537 extern void exit_inferior_num_silent (int num
);
539 extern void inferior_appeared (struct inferior
*inf
, int pid
);
541 /* Get rid of all inferiors. */
542 extern void discard_all_inferiors (void);
544 /* Search function to lookup an inferior by target 'pid'. */
545 extern struct inferior
*find_inferior_pid (int pid
);
547 /* Search function to lookup an inferior whose pid is equal to 'ptid.pid'. */
548 extern struct inferior
*find_inferior_ptid (ptid_t ptid
);
550 /* Search function to lookup an inferior by GDB 'num'. */
551 extern struct inferior
*find_inferior_id (int num
);
553 /* Find an inferior bound to PSPACE, giving preference to the current
555 extern struct inferior
*
556 find_inferior_for_program_space (struct program_space
*pspace
);
558 /* Inferior iterator function.
560 Calls a callback function once for each inferior, so long as the
561 callback function returns false. If the callback function returns
562 true, the iteration will end and the current inferior will be
563 returned. This can be useful for implementing a search for a
564 inferior with arbitrary attributes, or for applying some operation
567 It is safe to delete the iterated inferior from the callback. */
568 extern struct inferior
*iterate_over_inferiors (int (*) (struct inferior
*,
572 /* Returns true if the inferior list is not empty. */
573 extern int have_inferiors (void);
575 /* Returns the number of live inferiors (real live processes). */
576 extern int number_of_live_inferiors (void);
578 /* Returns true if there are any live inferiors in the inferior list
579 (not cores, not executables, real live processes). */
580 extern int have_live_inferiors (void);
582 /* Save/restore the current inferior. */
584 class scoped_restore_current_inferior
587 scoped_restore_current_inferior ()
588 : m_saved_inf (current_inferior ())
591 ~scoped_restore_current_inferior ()
592 { set_current_inferior (m_saved_inf
); }
594 DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior
);
597 inferior
*m_saved_inf
;
601 /* Traverse all inferiors. */
603 extern struct inferior
*inferior_list
;
605 /* Pull in the internals of the inferiors ranges and iterators. Must
606 be done after struct inferior is defined. */
607 #include "inferior-iter.h"
609 /* Return a range that can be used to walk over all inferiors
610 inferiors, with range-for, safely. I.e., it is safe to delete the
611 currently-iterated inferior. When combined with range-for, this
612 allow convenient patterns like this:
614 for (inferior *inf : all_inferiors_safe ())
615 if (some_condition ())
619 inline all_inferiors_safe_range
620 all_inferiors_safe ()
625 /* Returns a range representing all inferiors, suitable to use with
626 range-for, like this:
628 for (inferior *inf : all_inferiors ())
632 inline all_inferiors_range
638 /* Return a range that can be used to walk over all inferiors with PID
639 not zero, with range-for. */
641 inline all_non_exited_inferiors_range
642 all_non_exited_inferiors ()
647 /* Prune away automatically added inferiors that aren't required
649 extern void prune_inferiors (void);
651 extern int number_of_inferiors (void);
653 extern struct inferior
*add_inferior_with_spaces (void);
655 /* Print the current selected inferior. */
656 extern void print_selected_inferior (struct ui_out
*uiout
);
658 #endif /* !defined (INFERIOR_H) */