Use forward_scope_exit for scoped_finish_thread_state
[deliverable/binutils-gdb.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-2019 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 struct continuation;
34 struct inferior;
35 struct thread_info;
36
37 /* For bpstat. */
38 #include "breakpoint.h"
39
40 /* For enum gdb_signal. */
41 #include "target.h"
42
43 /* For struct frame_id. */
44 #include "frame.h"
45
46 /* For gdb_environ. */
47 #include "environ.h"
48
49 #include "progspace.h"
50 #include "registry.h"
51
52 #include "symfile-add-flags.h"
53 #include "common/refcounted-object.h"
54
55 #include "common-inferior.h"
56 #include "gdbthread.h"
57
58 struct infcall_suspend_state;
59 struct infcall_control_state;
60
61 extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
62 extern void restore_infcall_control_state (struct infcall_control_state *);
63
64 /* A deleter for infcall_suspend_state that calls
65 restore_infcall_suspend_state. */
66 struct infcall_suspend_state_deleter
67 {
68 void operator() (struct infcall_suspend_state *state) const
69 {
70 restore_infcall_suspend_state (state);
71 }
72 };
73
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;
77
78 extern infcall_suspend_state_up save_infcall_suspend_state ();
79
80 /* A deleter for infcall_control_state that calls
81 restore_infcall_control_state. */
82 struct infcall_control_state_deleter
83 {
84 void operator() (struct infcall_control_state *state) const
85 {
86 restore_infcall_control_state (state);
87 }
88 };
89
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;
93
94 extern infcall_control_state_up save_infcall_control_state ();
95
96 extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
97 extern void discard_infcall_control_state (struct infcall_control_state *);
98
99 extern readonly_detached_regcache *
100 get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
101
102 extern void set_sigint_trap (void);
103
104 extern void clear_sigint_trap (void);
105
106 /* Set/get file name for default use for standard in/out in the inferior. */
107
108 extern void set_inferior_io_terminal (const char *terminal_name);
109 extern const char *get_inferior_io_terminal (void);
110
111 /* Collected pid, tid, etc. of the debugged inferior. When there's
112 no inferior, inferior_ptid.pid () will be 0. */
113
114 extern ptid_t inferior_ptid;
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 reopen_exec_file (void);
132
133 /* From misc files */
134
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);
139
140 /* Default implementation of gdbarch_print_float_info. Print
141 the values of all floating point registers. */
142
143 extern void default_print_float_info (struct gdbarch *gdbarch,
144 struct ui_file *file,
145 struct frame_info *frame,
146 const char *args);
147
148 extern void child_terminal_info (struct target_ops *self, const char *, int);
149
150 extern void info_terminal_command (char *, int);
151
152 extern void child_terminal_ours (struct target_ops *self);
153
154 extern void child_terminal_ours_for_output (struct target_ops *self);
155
156 extern void child_terminal_inferior (struct target_ops *self);
157
158 extern void child_terminal_save_inferior (struct target_ops *self);
159
160 extern void child_terminal_init (struct target_ops *self);
161
162 extern void child_terminal_init_with_pgrp (int pgrp);
163
164 extern void child_pass_ctrlc (struct target_ops *self);
165
166 extern void child_interrupt (struct target_ops *self);
167
168 /* From fork-child.c */
169
170 /* Helper function to call STARTUP_INFERIOR with PID and NUM_TRAPS.
171 This function already calls set_executing. Return the ptid_t from
172 STARTUP_INFERIOR. */
173 extern ptid_t gdb_startup_inferior (pid_t pid, int num_traps);
174
175 extern char *construct_inferior_arguments (int, char **);
176
177 /* From infcmd.c */
178
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. */
182
183 extern void setup_inferior (int from_tty);
184
185 extern void post_create_inferior (struct target_ops *, int);
186
187 extern void attach_command (const char *, int);
188
189 extern const char *get_inferior_args (void);
190
191 extern void set_inferior_args (const char *);
192
193 extern void set_inferior_args_vector (int, char **);
194
195 extern void registers_info (const char *, int);
196
197 extern void continue_1 (int all_threads);
198
199 extern void interrupt_target_1 (int all_threads);
200
201 extern void delete_longjmp_breakpoint_cleanup (void *arg);
202
203 extern void detach_command (const char *, int);
204
205 extern void notice_new_inferior (struct thread_info *, int, int);
206
207 extern struct value *get_return_value (struct value *function,
208 struct type *value_type);
209
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. */
213
214 extern void prepare_execution_command (struct target_ops *target,
215 int background);
216
217 /* Whether to start up the debuggee under a shell.
218
219 If startup-with-shell is set, GDB's "run" will attempt to start up
220 the debuggee under a shell.
221
222 This is in order for argument-expansion to occur. E.g.,
223
224 (gdb) run *
225
226 The "*" gets expanded by the shell into a list of files.
227
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
230 false".
231
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;
235
236 /* Nonzero if stopped due to completion of a stack dummy routine. */
237
238 extern enum stop_stack_kind stop_stack_dummy;
239
240 /* Nonzero if program stopped due to a random (unexpected) signal in
241 inferior process. */
242
243 extern int stopped_by_random_signal;
244
245 /* Print notices on inferior events (attach, detach, etc.), set with
246 `set print inferior-events'. */
247 extern int print_inferior_events;
248
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. */
255
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.
262
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
268 back to the user.
269
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. */
273
274 enum stop_kind
275 {
276 NO_STOP_QUIETLY = 0,
277 STOP_QUIETLY,
278 STOP_QUIETLY_REMOTE,
279 STOP_QUIETLY_NO_SIGSTOP
280 };
281
282 \f
283 /* Possible values for gdbarch_call_dummy_location. */
284 #define ON_STACK 1
285 #define AT_ENTRY_POINT 4
286
287 /* Base class for target-specific inferior data. */
288
289 struct private_inferior
290 {
291 virtual ~private_inferior () = 0;
292 };
293
294 /* Inferior process specific part of `struct infcall_control_state'.
295
296 Inferior thread counterpart is `struct thread_control_state'. */
297
298 struct inferior_control_state
299 {
300 inferior_control_state ()
301 : stop_soon (NO_STOP_QUIETLY)
302 {
303 }
304
305 explicit inferior_control_state (enum stop_kind when)
306 : stop_soon (when)
307 {
308 }
309
310 /* See the definition of stop_kind above. */
311 enum stop_kind stop_soon;
312 };
313
314 /* Return a pointer to the current inferior. */
315 extern inferior *current_inferior ();
316
317 extern void set_current_inferior (inferior *);
318
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.
327
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. */
340
341 class inferior : public refcounted_object
342 {
343 public:
344 explicit inferior (int pid);
345 ~inferior ();
346
347 /* Returns true if we can delete this inferior. */
348 bool deletable () const { return refcount () == 0; }
349
350 /* Pointer to next inferior in singly-linked list of inferiors. */
351 struct inferior *next = NULL;
352
353 /* This inferior's thread list. */
354 thread_info *thread_list = nullptr;
355
356 /* Returns a range adapter covering the inferior's threads,
357 including exited threads. Used like this:
358
359 for (thread_info *thr : inf->threads ())
360 { .... }
361 */
362 inf_threads_range threads ()
363 { return inf_threads_range (this->thread_list); }
364
365 /* Returns a range adapter covering the inferior's non-exited
366 threads. Used like this:
367
368 for (thread_info *thr : inf->non_exited_threads ())
369 { .... }
370 */
371 inf_non_exited_threads_range non_exited_threads ()
372 { return inf_non_exited_threads_range (this->thread_list); }
373
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:
377
378 for (thread_info *t : inf->threads_safe ())
379 if (some_condition ())
380 delete f;
381 */
382 inline safe_inf_threads_range threads_safe ()
383 { return safe_inf_threads_range (this->thread_list); }
384
385 /* Convenient handle (GDB inferior id). Unique across all
386 inferiors. */
387 int num = 0;
388
389 /* Actual target inferior id, usually, a process id. This matches
390 the ptid_t.pid member of threads of this inferior. */
391 int pid = 0;
392 /* True if the PID was actually faked by GDB. */
393 bool fake_pid_p = false;
394
395 /* The highest thread number this inferior ever had. */
396 int highest_thread_num = 0;
397
398 /* State of GDB control of inferior process execution.
399 See `struct inferior_control_state'. */
400 inferior_control_state control;
401
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
405 automatically. */
406 bool removable = false;
407
408 /* The address space bound to this inferior. */
409 struct address_space *aspace = NULL;
410
411 /* The program space bound to this inferior. */
412 struct program_space *pspace = NULL;
413
414 /* The arguments string to use when running. */
415 char *args = NULL;
416
417 /* The size of elements in argv. */
418 int argc = 0;
419
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. */
424 char **argv = NULL;
425
426 /* The current working directory that will be used when starting
427 this inferior. */
428 gdb::unique_xmalloc_ptr<char> cwd;
429
430 /* The name of terminal device to use for I/O. */
431 char *terminal = NULL;
432
433 /* The terminal state as set by the last target_terminal::terminal_*
434 call. */
435 target_terminal_state terminal_state = target_terminal_state::is_ours;
436
437 /* Environment to use for running inferior,
438 in format described in environ.h. */
439 gdb_environ environment;
440
441 /* True if this child process was attached rather than forked. */
442 bool attach_flag = false;
443
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;
447
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
451 at a given time. */
452 inferior *vfork_child = NULL;
453
454 /* True if this inferior should be detached when it's vfork sibling
455 exits or execs. */
456 bool pending_detach = false;
457
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;
462
463 /* True if we're in the process of detaching from this inferior. */
464 bool detaching = false;
465
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;
470
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;
476
477 /* Private data used by the target vector implementation. */
478 std::unique_ptr<private_inferior> priv;
479
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;
484
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;
488
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;
492
493 /* The architecture associated with the inferior through the
494 connection to the target.
495
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
503 this gdbarch. */
504 struct gdbarch *gdbarch = NULL;
505
506 /* Data related to displaced stepping. */
507 displaced_step_inferior_state displaced_step_state;
508
509 /* Per inferior data-pointers required by other GDB modules. */
510 REGISTRY_FIELDS;
511 };
512
513 /* Keep a registry of per-inferior data-pointers required by other GDB
514 modules. */
515
516 DECLARE_REGISTRY (inferior);
517
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
521 data. */
522 extern struct inferior *add_inferior (int pid);
523
524 /* Same as add_inferior, but don't print new inferior notifications to
525 the CLI. */
526 extern struct inferior *add_inferior_silent (int pid);
527
528 extern void delete_inferior (struct inferior *todel);
529
530 /* Delete an existing inferior list entry, due to inferior detaching. */
531 extern void detach_inferior (inferior *inf);
532
533 extern void exit_inferior (inferior *inf);
534
535 extern void exit_inferior_silent (inferior *inf);
536
537 extern void exit_inferior_num_silent (int num);
538
539 extern void inferior_appeared (struct inferior *inf, int pid);
540
541 /* Get rid of all inferiors. */
542 extern void discard_all_inferiors (void);
543
544 /* Search function to lookup an inferior by target 'pid'. */
545 extern struct inferior *find_inferior_pid (int pid);
546
547 /* Search function to lookup an inferior whose pid is equal to 'ptid.pid'. */
548 extern struct inferior *find_inferior_ptid (ptid_t ptid);
549
550 /* Search function to lookup an inferior by GDB 'num'. */
551 extern struct inferior *find_inferior_id (int num);
552
553 /* Find an inferior bound to PSPACE, giving preference to the current
554 inferior. */
555 extern struct inferior *
556 find_inferior_for_program_space (struct program_space *pspace);
557
558 /* Inferior iterator function.
559
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
565 to every inferior.
566
567 It is safe to delete the iterated inferior from the callback. */
568 extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
569 void *),
570 void *);
571
572 /* Returns true if the inferior list is not empty. */
573 extern int have_inferiors (void);
574
575 /* Returns the number of live inferiors (real live processes). */
576 extern int number_of_live_inferiors (void);
577
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);
581
582 /* Save/restore the current inferior. */
583
584 class scoped_restore_current_inferior
585 {
586 public:
587 scoped_restore_current_inferior ()
588 : m_saved_inf (current_inferior ())
589 {}
590
591 ~scoped_restore_current_inferior ()
592 { set_current_inferior (m_saved_inf); }
593
594 DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior);
595
596 private:
597 inferior *m_saved_inf;
598 };
599
600
601 /* Traverse all inferiors. */
602
603 extern struct inferior *inferior_list;
604
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"
608
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:
613
614 for (inferior *inf : all_inferiors_safe ())
615 if (some_condition ())
616 delete inf;
617 */
618
619 inline all_inferiors_safe_range
620 all_inferiors_safe ()
621 {
622 return {};
623 }
624
625 /* Returns a range representing all inferiors, suitable to use with
626 range-for, like this:
627
628 for (inferior *inf : all_inferiors ())
629 [...]
630 */
631
632 inline all_inferiors_range
633 all_inferiors ()
634 {
635 return {};
636 }
637
638 /* Return a range that can be used to walk over all inferiors with PID
639 not zero, with range-for. */
640
641 inline all_non_exited_inferiors_range
642 all_non_exited_inferiors ()
643 {
644 return {};
645 }
646
647 /* Prune away automatically added inferiors that aren't required
648 anymore. */
649 extern void prune_inferiors (void);
650
651 extern int number_of_inferiors (void);
652
653 extern struct inferior *add_inferior_with_spaces (void);
654
655 /* Print the current selected inferior. */
656 extern void print_selected_inferior (struct ui_out *uiout);
657
658 #endif /* !defined (INFERIOR_H) */
This page took 0.044572 seconds and 4 git commands to generate.