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