Make inferior::detaching a bool, and introduce scoped_restore::release()
[deliverable/binutils-gdb.git] / gdb / inferior.h
CommitLineData
c906108c
SS
1/* Variables that describe the inferior process running under GDB:
2 Where it is, why it stopped, and how to step it.
1bac305b 3
61baf725 4 Copyright (C) 1986-2017 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#if !defined (INFERIOR_H)
22#define INFERIOR_H 1
23
da3331ec
AC
24struct target_waitstatus;
25struct frame_info;
26struct ui_file;
27struct type;
67a2b77e 28struct gdbarch;
72cec141 29struct regcache;
b77209e0 30struct ui_out;
7e1789f5 31struct terminal_info;
6ecd4729 32struct target_desc_info;
0550c955
PA
33struct gdb_environ;
34struct continuation;
67a2b77e 35
c906108c
SS
36/* For bpstat. */
37#include "breakpoint.h"
38
2ea28649 39/* For enum gdb_signal. */
c906108c
SS
40#include "target.h"
41
aa0cd9c1
AC
42/* For struct frame_id. */
43#include "frame.h"
44
6c95b8df 45#include "progspace.h"
8e260fc0 46#include "registry.h"
6c95b8df 47
b15cc25c
PA
48#include "symfile-add-flags.h"
49
16c381f0
JK
50struct infcall_suspend_state;
51struct infcall_control_state;
7a292a7a 52
16c381f0
JK
53extern struct infcall_suspend_state *save_infcall_suspend_state (void);
54extern struct infcall_control_state *save_infcall_control_state (void);
c906108c 55
16c381f0
JK
56extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
57extern void restore_infcall_control_state (struct infcall_control_state *);
b89667eb 58
16c381f0
JK
59extern struct cleanup *make_cleanup_restore_infcall_suspend_state
60 (struct infcall_suspend_state *);
61extern struct cleanup *make_cleanup_restore_infcall_control_state
62 (struct infcall_control_state *);
b89667eb 63
16c381f0
JK
64extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
65extern void discard_infcall_control_state (struct infcall_control_state *);
7a292a7a 66
16c381f0
JK
67extern struct regcache *
68 get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
b89667eb 69
ce696e05
KB
70/* Save value of inferior_ptid so that it may be restored by
71 a later call to do_cleanups(). Returns the struct cleanup
72 pointer needed for later doing the cleanup. */
73extern struct cleanup * save_inferior_ptid (void);
74
a14ed312 75extern void set_sigint_trap (void);
c906108c 76
a14ed312 77extern void clear_sigint_trap (void);
c906108c 78
3cb3b8df 79/* Set/get file name for default use for standard in/out in the inferior. */
c906108c 80
3cb3b8df
BR
81extern void set_inferior_io_terminal (const char *terminal_name);
82extern const char *get_inferior_io_terminal (void);
c906108c 83
39f77062 84/* Collected pid, tid, etc. of the debugged inferior. When there's
dfd4cc63 85 no inferior, ptid_get_pid (inferior_ptid) will be 0. */
c906108c 86
39f77062 87extern ptid_t inferior_ptid;
c906108c 88
a14ed312 89extern void generic_mourn_inferior (void);
c906108c 90
9898f801
UW
91extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
92 struct type *type,
b60c417a 93 const gdb_byte *buf);
9898f801
UW
94extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
95 struct type *type, gdb_byte *buf,
ac2e2ef7 96 CORE_ADDR addr);
9898f801
UW
97extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
98 struct type *type,
b60c417a 99 const gdb_byte *buf);
9898f801
UW
100extern void address_to_signed_pointer (struct gdbarch *gdbarch,
101 struct type *type, gdb_byte *buf,
ac2e2ef7 102 CORE_ADDR addr);
4478b372 103
a14ed312 104extern void reopen_exec_file (void);
c906108c 105
c906108c
SS
106/* From misc files */
107
0ab7a791
AC
108extern void default_print_registers_info (struct gdbarch *gdbarch,
109 struct ui_file *file,
110 struct frame_info *frame,
111 int regnum, int all);
666e11c5 112
cc86d1cb
YQ
113/* Default implementation of gdbarch_print_float_info. Print
114 the values of all floating point registers. */
115
116extern void default_print_float_info (struct gdbarch *gdbarch,
117 struct ui_file *file,
118 struct frame_info *frame,
119 const char *args);
120
0a4f40a2 121extern void child_terminal_info (struct target_ops *self, const char *, int);
c906108c 122
a14ed312 123extern void term_info (char *, int);
c906108c 124
d6b64346
PA
125extern void child_terminal_ours (struct target_ops *self);
126
127extern void child_terminal_ours_for_output (struct target_ops *self);
c906108c 128
d6b64346 129extern void child_terminal_inferior (struct target_ops *self);
c906108c 130
d6b64346 131extern void child_terminal_init (struct target_ops *self);
c906108c 132
d6b64346 133extern void child_terminal_init_with_pgrp (int pgrp);
c906108c 134
c906108c
SS
135/* From fork-child.c */
136
0db8980c
SDJ
137/* Report an error that happened when starting to trace the inferior
138 (i.e., when the "traceme_fun" callback is called on fork_inferior)
139 and bail out. This function does not return. */
140
141extern void trace_start_error (const char *fmt, ...)
142 ATTRIBUTE_NORETURN;
143
144/* Like "trace_start_error", but the error message is constructed by
145 combining STRING with the system error message for errno. This
146 function does not return. */
147
148extern void trace_start_error_with_name (const char *string)
149 ATTRIBUTE_NORETURN;
150
7c5ded6a 151extern int fork_inferior (const char *, const std::string &, char **,
136d6dae 152 void (*)(void),
e69860f1
TG
153 void (*)(int), void (*)(void), char *,
154 void (*)(const char *,
155 char * const *, char * const *));
c906108c
SS
156
157
a14ed312 158extern void startup_inferior (int);
c906108c 159
bd57a748 160extern char *construct_inferior_arguments (int, char **);
552c04a7 161
c906108c
SS
162/* From infcmd.c */
163
6efcd9a8
PA
164/* Initial inferior setup. Determines the exec file is not yet known,
165 takes any necessary post-attaching actions, fetches the target
166 description and syncs the shared library list. */
167
168extern void setup_inferior (int from_tty);
169
281b533b
DJ
170extern void post_create_inferior (struct target_ops *, int);
171
a14ed312 172extern void attach_command (char *, int);
c906108c 173
a250df2e 174extern char *get_inferior_args (void);
07091751 175
3f81c18a 176extern void set_inferior_args (char *);
07091751 177
552c04a7
TT
178extern void set_inferior_args_vector (int, char **);
179
36dc181b
EZ
180extern void registers_info (char *, int);
181
77ebaa5a
VP
182extern void continue_1 (int all_threads);
183
77ebaa5a
VP
184extern void interrupt_target_1 (int all_threads);
185
186c406b
TT
186extern void delete_longjmp_breakpoint_cleanup (void *arg);
187
6418d433
VP
188extern void detach_command (char *, int);
189
1941c569
PA
190extern void notice_new_inferior (ptid_t, int, int);
191
0700e23e
PA
192extern struct value *get_return_value (struct value *function,
193 struct type *value_type);
cc72b2a2 194
329ea579
PA
195/* Prepare for execution command. TARGET is the target that will run
196 the command. BACKGROUND determines whether this is a foreground
197 (synchronous) or background (asynchronous) command. */
198
199extern void prepare_execution_command (struct target_ops *target,
200 int background);
201
98882a26
PA
202/* Whether to start up the debuggee under a shell.
203
204 If startup-with-shell is set, GDB's "run" will attempt to start up
205 the debuggee under a shell.
206
207 This is in order for argument-expansion to occur. E.g.,
208
209 (gdb) run *
210
211 The "*" gets expanded by the shell into a list of files.
212
213 While this is a nice feature, it may be handy to bypass the shell
214 in some cases. To disable this feature, do "set startup-with-shell
215 false".
216
217 The catch-exec traps expected during start-up will be one more if
218 the target is started up with a shell. */
219extern int startup_with_shell;
220
c906108c
SS
221/* Address at which inferior stopped. */
222
223extern CORE_ADDR stop_pc;
224
c906108c
SS
225/* Nonzero if stopped due to completion of a stack dummy routine. */
226
aa7d318d 227extern enum stop_stack_kind stop_stack_dummy;
c906108c
SS
228
229/* Nonzero if program stopped due to a random (unexpected) signal in
230 inferior process. */
231
232extern int stopped_by_random_signal;
233
a49f981f
MS
234/* STEP_OVER_ALL means step over all subroutine calls.
235 STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
236 STEP_OVER_NONE means don't step over any subroutine calls. */
c906108c 237
5fbbeb29
CF
238enum step_over_calls_kind
239 {
240 STEP_OVER_NONE,
241 STEP_OVER_ALL,
a4acd088
CF
242 STEP_OVER_UNDEBUGGABLE
243 };
244
b0f4b84b
DJ
245/* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
246 will handle it themselves. STOP_QUIETLY is used when running in
247 the shell before the child program has been exec'd and when running
248 through shared library loading. STOP_QUIETLY_REMOTE is used when
249 setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
250 except that there is no need to hide a signal. */
c54cfec8 251
7c0bc051
DE
252/* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
253 When doing an attach, the kernel stops the debuggee with a SIGSTOP.
254 On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
255 a ptraced process has changed. Earlier versions of the kernel
256 would ignore these SIGSTOPs, while now SIGSTOP is treated like any
257 other signal, i.e. it is not muffled.
258
c54cfec8
EZ
259 If the gdb user does a 'continue' after the 'attach', gdb passes
260 the global variable stop_signal (which stores the signal from the
261 attach, SIGSTOP) to the ptrace(PTRACE_CONT,...) call. This is
262 problematic, because the kernel doesn't ignore such SIGSTOP
1777feb0 263 now. I.e. it is reported back to gdb, which in turn presents it
c54cfec8 264 back to the user.
7c0bc051 265
c54cfec8
EZ
266 To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
267 gdb to clear the value of stop_signal after the attach, so that it
268 is not passed back down to the kernel. */
269
270enum stop_kind
271 {
272 NO_STOP_QUIETLY = 0,
273 STOP_QUIETLY,
b0f4b84b 274 STOP_QUIETLY_REMOTE,
c54cfec8
EZ
275 STOP_QUIETLY_NO_SIGSTOP
276 };
c906108c 277
c906108c 278\f
faaf634c 279/* Possible values for gdbarch_call_dummy_location. */
c906108c 280#define ON_STACK 1
c906108c
SS
281#define AT_ENTRY_POINT 4
282
98882a26
PA
283/* Number of traps that happen between exec'ing the shell to run an
284 inferior and when we finally get to the inferior code, not counting
32a8097b
PA
285 the exec for the shell. This is 1 on all supported
286 implementations. */
98882a26 287#define START_INFERIOR_TRAPS_EXPECTED 1
b77209e0
PA
288
289struct private_inferior;
290
16c381f0
JK
291/* Inferior process specific part of `struct infcall_control_state'.
292
293 Inferior thread counterpart is `struct thread_control_state'. */
294
295struct inferior_control_state
296{
297 /* See the definition of stop_kind above. */
298 enum stop_kind stop_soon;
299};
300
b77209e0
PA
301/* GDB represents the state of each program execution with an object
302 called an inferior. An inferior typically corresponds to a process
303 but is more general and applies also to targets that do not have a
304 notion of processes. Each run of an executable creates a new
305 inferior, as does each attachment to an existing process.
306 Inferiors have unique internal identifiers that are different from
307 target process ids. Each inferior may in turn have multiple
308 threads running in it. */
309
0550c955 310class inferior
b77209e0 311{
0550c955
PA
312public:
313 explicit inferior (int pid);
314 ~inferior ();
315
b77209e0 316 /* Pointer to next inferior in singly-linked list of inferiors. */
0550c955 317 struct inferior *next = NULL;
b77209e0
PA
318
319 /* Convenient handle (GDB inferior id). Unique across all
320 inferiors. */
0550c955 321 int num = 0;
b77209e0
PA
322
323 /* Actual target inferior id, usually, a process id. This matches
324 the ptid_t.pid member of threads of this inferior. */
0550c955 325 int pid = 0;
e714e1bf 326 /* True if the PID was actually faked by GDB. */
0550c955 327 bool fake_pid_p = false;
b77209e0 328
5d5658a1 329 /* The highest thread number this inferior ever had. */
0550c955 330 int highest_thread_num = 0;
5d5658a1 331
16c381f0
JK
332 /* State of GDB control of inferior process execution.
333 See `struct inferior_control_state'. */
0550c955 334 inferior_control_state control {NO_STOP_QUIETLY};
16c381f0 335
6c95b8df
PA
336 /* True if this was an auto-created inferior, e.g. created from
337 following a fork; false, if this inferior was manually added by
338 the user, and we should not attempt to prune it
339 automatically. */
0550c955 340 bool removable = false;
6c95b8df
PA
341
342 /* The address space bound to this inferior. */
0550c955 343 struct address_space *aspace = NULL;
6c95b8df
PA
344
345 /* The program space bound to this inferior. */
0550c955 346 struct program_space *pspace = NULL;
6c95b8df 347
3f81c18a 348 /* The arguments string to use when running. */
0550c955 349 char *args = NULL;
3f81c18a
VP
350
351 /* The size of elements in argv. */
0550c955 352 int argc = 0;
3f81c18a
VP
353
354 /* The vector version of arguments. If ARGC is nonzero,
355 then we must compute ARGS from this (via the target).
356 This is always coming from main's argv and therefore
357 should never be freed. */
0550c955 358 char **argv = NULL;
3f81c18a
VP
359
360 /* The name of terminal device to use for I/O. */
0550c955 361 char *terminal = NULL;
3f81c18a
VP
362
363 /* Environment to use for running inferior,
364 in format described in environ.h. */
0550c955 365 gdb_environ *environment = NULL;
3f81c18a 366
0550c955
PA
367 /* True if this child process was attached rather than forked. */
368 bool attach_flag = false;
181e7f93 369
6c95b8df
PA
370 /* If this inferior is a vfork child, then this is the pointer to
371 its vfork parent, if GDB is still attached to it. */
0550c955 372 inferior *vfork_parent = NULL;
6c95b8df
PA
373
374 /* If this process is a vfork parent, this is the pointer to the
375 child. Since a vfork parent is left frozen by the kernel until
376 the child execs or exits, a process can only have one vfork child
377 at a given time. */
0550c955 378 inferior *vfork_child = NULL;
6c95b8df
PA
379
380 /* True if this inferior should be detached when it's vfork sibling
381 exits or execs. */
0550c955 382 bool pending_detach = false;
6c95b8df
PA
383
384 /* True if this inferior is a vfork parent waiting for a vfork child
385 not under our control to be done with the shared memory region,
386 either by exiting or execing. */
0550c955 387 bool waiting_for_vfork_done = false;
6c95b8df 388
24291992 389 /* True if we're in the process of detaching from this inferior. */
9bcb1f16 390 bool detaching = false;
24291992 391
e0ba6746
PA
392 /* What is left to do for an execution command after any thread of
393 this inferior stops. For continuations associated with a
394 specific thread, see `struct thread_info'. */
0550c955 395 continuation *continuations = NULL;
e0ba6746 396
6efcd9a8
PA
397 /* True if setup_inferior wasn't called for this inferior yet.
398 Until that is done, we must not access inferior memory or
399 registers, as we haven't determined the target
400 architecture/description. */
0550c955 401 bool needs_setup = false;
6efcd9a8 402
b77209e0 403 /* Private data used by the target vector implementation. */
0550c955 404 private_inferior *priv = NULL;
a96d9b2e 405
8cf64490
TT
406 /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
407 In this case, the EXIT_CODE field is also valid. */
0550c955
PA
408 bool has_exit_code = false;
409 LONGEST exit_code = 0;
8cf64490 410
7dcd53a0 411 /* Default flags to pass to the symbol reading functions. These are
b15cc25c 412 used whenever a new objfile is created. */
0550c955 413 symfile_add_flags symfile_flags = 0;
7dcd53a0 414
6ecd4729
PA
415 /* Info about an inferior's target description (if it's fetched; the
416 user supplied description's filename, if any; etc.). */
0550c955 417 target_desc_info *tdesc_info = NULL;
6ecd4729
PA
418
419 /* The architecture associated with the inferior through the
420 connection to the target.
421
422 The architecture vector provides some information that is really
423 a property of the inferior, accessed through a particular target:
424 ptrace operations; the layout of certain RSP packets; the
425 solib_ops vector; etc. To differentiate architecture accesses to
426 per-inferior/target properties from
427 per-thread/per-frame/per-objfile properties, accesses to
428 per-inferior/target properties should be made through
429 this gdbarch. */
0550c955 430 struct gdbarch *gdbarch = NULL;
6ecd4729 431
6c95b8df 432 /* Per inferior data-pointers required by other GDB modules. */
8e260fc0 433 REGISTRY_FIELDS;
b77209e0
PA
434};
435
6c95b8df
PA
436/* Keep a registry of per-inferior data-pointers required by other GDB
437 modules. */
438
8e260fc0 439DECLARE_REGISTRY (inferior);
6c95b8df 440
b77209e0
PA
441/* Add an inferior to the inferior list, print a message that a new
442 inferior is found, and return the pointer to the new inferior.
443 Caller may use this pointer to initialize the private inferior
444 data. */
445extern struct inferior *add_inferior (int pid);
446
447/* Same as add_inferior, but don't print new inferior notifications to
448 the CLI. */
449extern struct inferior *add_inferior_silent (int pid);
450
7a41607e 451extern void delete_inferior (struct inferior *todel);
b77209e0
PA
452
453/* Delete an existing inferior list entry, due to inferior detaching. */
454extern void detach_inferior (int pid);
455
6c95b8df
PA
456extern void exit_inferior (int pid);
457
458extern void exit_inferior_silent (int pid);
459
460extern void exit_inferior_num_silent (int num);
461
462extern void inferior_appeared (struct inferior *inf, int pid);
463
82f73884
PA
464/* Get rid of all inferiors. */
465extern void discard_all_inferiors (void);
466
b77209e0
PA
467/* Translate the integer inferior id (GDB's homegrown id, not the system's)
468 into a "pid" (which may be overloaded with extra inferior information). */
469extern int gdb_inferior_id_to_pid (int);
470
471/* Translate a target 'pid' into the integer inferior id (GDB's
472 homegrown id, not the system's). */
473extern int pid_to_gdb_inferior_id (int pid);
474
475/* Boolean test for an already-known pid. */
476extern int in_inferior_list (int pid);
477
478/* Boolean test for an already-known inferior id (GDB's homegrown id,
479 not the system's). */
2c0b251b 480extern int valid_gdb_inferior_id (int num);
b77209e0 481
6c95b8df 482/* Search function to lookup an inferior by target 'pid'. */
b77209e0
PA
483extern struct inferior *find_inferior_pid (int pid);
484
c9657e70
SM
485/* Search function to lookup an inferior whose pid is equal to 'ptid.pid'. */
486extern struct inferior *find_inferior_ptid (ptid_t ptid);
487
6c95b8df
PA
488/* Search function to lookup an inferior by GDB 'num'. */
489extern struct inferior *find_inferior_id (int num);
490
32990ada
PA
491/* Find an inferior bound to PSPACE, giving preference to the current
492 inferior. */
6c95b8df
PA
493extern struct inferior *
494 find_inferior_for_program_space (struct program_space *pspace);
495
b77209e0
PA
496/* Inferior iterator function.
497
498 Calls a callback function once for each inferior, so long as the
499 callback function returns false. If the callback function returns
500 true, the iteration will end and the current inferior will be
501 returned. This can be useful for implementing a search for a
502 inferior with arbitrary attributes, or for applying some operation
503 to every inferior.
504
505 It is safe to delete the iterated inferior from the callback. */
506extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
507 void *),
508 void *);
509
b77209e0
PA
510/* Returns true if the inferior list is not empty. */
511extern int have_inferiors (void);
512
8020350c
DB
513/* Returns the number of live inferiors (real live processes). */
514extern int number_of_live_inferiors (void);
515
c35b1492
PA
516/* Returns true if there are any live inferiors in the inferior list
517 (not cores, not executables, real live processes). */
518extern int have_live_inferiors (void);
519
b77209e0
PA
520/* Return a pointer to the current inferior. It is an error to call
521 this if there is no current inferior. */
522extern struct inferior *current_inferior (void);
523
6c95b8df
PA
524extern void set_current_inferior (struct inferior *);
525
526extern struct cleanup *save_current_inferior (void);
527
c65b3e0d
PA
528/* Traverse all inferiors. */
529
530#define ALL_INFERIORS(I) \
531 for ((I) = inferior_list; (I); (I) = (I)->next)
532
85ad3aaf
PA
533/* Traverse all non-exited inferiors. */
534
535#define ALL_NON_EXITED_INFERIORS(I) \
536 ALL_INFERIORS (I) \
537 if ((I)->pid != 0)
538
6c95b8df
PA
539extern struct inferior *inferior_list;
540
541/* Prune away automatically added inferiors that aren't required
542 anymore. */
543extern void prune_inferiors (void);
544
545extern int number_of_inferiors (void);
546
a79b8f6e
VP
547extern struct inferior *add_inferior_with_spaces (void);
548
4034d0ff
AT
549/* Print the current selected inferior. */
550extern void print_selected_inferior (struct ui_out *uiout);
551
c906108c 552#endif /* !defined (INFERIOR_H) */
This page took 1.473103 seconds and 4 git commands to generate.