GDB (API)
|
00001 /* Variables that describe the inferior process running under GDB: 00002 Where it is, why it stopped, and how to step it. 00003 00004 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00005 00006 This file is part of GDB. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00020 00021 #if !defined (INFERIOR_H) 00022 #define INFERIOR_H 1 00023 00024 struct target_waitstatus; 00025 struct frame_info; 00026 struct ui_file; 00027 struct type; 00028 struct gdbarch; 00029 struct regcache; 00030 struct ui_out; 00031 struct terminal_info; 00032 struct target_desc_info; 00033 00034 #include "ptid.h" 00035 00036 /* For bpstat. */ 00037 #include "breakpoint.h" 00038 00039 /* For enum gdb_signal. */ 00040 #include "target.h" 00041 00042 /* For struct frame_id. */ 00043 #include "frame.h" 00044 00045 #include "progspace.h" 00046 #include "registry.h" 00047 00048 struct infcall_suspend_state; 00049 struct infcall_control_state; 00050 00051 extern struct infcall_suspend_state *save_infcall_suspend_state (void); 00052 extern struct infcall_control_state *save_infcall_control_state (void); 00053 00054 extern void restore_infcall_suspend_state (struct infcall_suspend_state *); 00055 extern void restore_infcall_control_state (struct infcall_control_state *); 00056 00057 extern struct cleanup *make_cleanup_restore_infcall_suspend_state 00058 (struct infcall_suspend_state *); 00059 extern struct cleanup *make_cleanup_restore_infcall_control_state 00060 (struct infcall_control_state *); 00061 00062 extern void discard_infcall_suspend_state (struct infcall_suspend_state *); 00063 extern void discard_infcall_control_state (struct infcall_control_state *); 00064 00065 extern struct regcache * 00066 get_infcall_suspend_state_regcache (struct infcall_suspend_state *); 00067 00068 /* Returns true if PTID matches filter FILTER. FILTER can be the wild 00069 card MINUS_ONE_PTID (all ptid match it); can be a ptid representing 00070 a process (ptid_is_pid returns true), in which case, all lwps and 00071 threads of that given process match, lwps and threads of other 00072 processes do not; or, it can represent a specific thread, in which 00073 case, only that thread will match true. PTID must represent a 00074 specific LWP or THREAD, it can never be a wild card. */ 00075 00076 extern int ptid_match (ptid_t ptid, ptid_t filter); 00077 00078 /* Save value of inferior_ptid so that it may be restored by 00079 a later call to do_cleanups(). Returns the struct cleanup 00080 pointer needed for later doing the cleanup. */ 00081 extern struct cleanup * save_inferior_ptid (void); 00082 00083 extern void set_sigint_trap (void); 00084 00085 extern void clear_sigint_trap (void); 00086 00087 /* Set/get file name for default use for standard in/out in the inferior. */ 00088 00089 extern void set_inferior_io_terminal (const char *terminal_name); 00090 extern const char *get_inferior_io_terminal (void); 00091 00092 /* Collected pid, tid, etc. of the debugged inferior. When there's 00093 no inferior, ptid_get_pid (inferior_ptid) will be 0. */ 00094 00095 extern ptid_t inferior_ptid; 00096 00097 /* Are we simulating synchronous execution? This is used in async gdb 00098 to implement the 'run', 'continue' etc commands, which will not 00099 redisplay the prompt until the execution is actually over. */ 00100 extern int sync_execution; 00101 00102 /* Inferior environment. */ 00103 00104 extern void clear_proceed_status (void); 00105 00106 extern void proceed (CORE_ADDR, enum gdb_signal, int); 00107 00108 extern int sched_multi; 00109 00110 /* When set, stop the 'step' command if we enter a function which has 00111 no line number information. The normal behavior is that we step 00112 over such function. */ 00113 extern int step_stop_if_no_debug; 00114 00115 /* If set, the inferior should be controlled in non-stop mode. In 00116 this mode, each thread is controlled independently. Execution 00117 commands apply only to the selected thread by default, and stop 00118 events stop only the thread that had the event -- the other threads 00119 are kept running freely. */ 00120 extern int non_stop; 00121 00122 /* When set (default), the target should attempt to disable the operating 00123 system's address space randomization feature when starting an inferior. */ 00124 extern int disable_randomization; 00125 00126 extern void generic_mourn_inferior (void); 00127 00128 extern void terminal_save_ours (void); 00129 00130 extern void terminal_ours (void); 00131 00132 extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch, 00133 struct type *type, 00134 const gdb_byte *buf); 00135 extern void unsigned_address_to_pointer (struct gdbarch *gdbarch, 00136 struct type *type, gdb_byte *buf, 00137 CORE_ADDR addr); 00138 extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch, 00139 struct type *type, 00140 const gdb_byte *buf); 00141 extern void address_to_signed_pointer (struct gdbarch *gdbarch, 00142 struct type *type, gdb_byte *buf, 00143 CORE_ADDR addr); 00144 00145 extern void wait_for_inferior (void); 00146 00147 extern void prepare_for_detach (void); 00148 00149 extern void fetch_inferior_event (void *); 00150 00151 extern void init_wait_for_inferior (void); 00152 00153 extern void reopen_exec_file (void); 00154 00155 /* The `resume' routine should only be called in special circumstances. 00156 Normally, use `proceed', which handles a lot of bookkeeping. */ 00157 00158 extern void resume (int, enum gdb_signal); 00159 00160 extern ptid_t user_visible_resume_ptid (int step); 00161 00162 extern void insert_step_resume_breakpoint_at_sal (struct gdbarch *, 00163 struct symtab_and_line , 00164 struct frame_id); 00165 00166 /* From misc files */ 00167 00168 extern void default_print_registers_info (struct gdbarch *gdbarch, 00169 struct ui_file *file, 00170 struct frame_info *frame, 00171 int regnum, int all); 00172 00173 extern void child_terminal_info (const char *, int); 00174 00175 extern void term_info (char *, int); 00176 00177 extern void terminal_ours_for_output (void); 00178 00179 extern void terminal_inferior (void); 00180 00181 extern void terminal_init_inferior (void); 00182 00183 extern void terminal_init_inferior_with_pgrp (int pgrp); 00184 00185 /* From fork-child.c */ 00186 00187 extern int fork_inferior (char *, char *, char **, 00188 void (*)(void), 00189 void (*)(int), void (*)(void), char *, 00190 void (*)(const char *, 00191 char * const *, char * const *)); 00192 00193 00194 extern void startup_inferior (int); 00195 00196 extern char *construct_inferior_arguments (int, char **); 00197 00198 /* From infrun.c */ 00199 00200 extern unsigned int debug_infrun; 00201 00202 extern int stop_on_solib_events; 00203 00204 extern void start_remote (int from_tty); 00205 00206 extern void normal_stop (void); 00207 00208 extern int signal_stop_state (int); 00209 00210 extern int signal_print_state (int); 00211 00212 extern int signal_pass_state (int); 00213 00214 extern int signal_stop_update (int, int); 00215 00216 extern int signal_print_update (int, int); 00217 00218 extern int signal_pass_update (int, int); 00219 00220 extern void get_last_target_status(ptid_t *ptid, 00221 struct target_waitstatus *status); 00222 00223 extern void follow_inferior_reset_breakpoints (void); 00224 00225 void set_step_info (struct frame_info *frame, struct symtab_and_line sal); 00226 00227 /* Clear the convenience variables associated with the exit of the 00228 inferior. Currently, those variables are $_exitcode and 00229 $_exitsignal. */ 00230 00231 extern void clear_exit_convenience_vars (void); 00232 00233 /* From infcmd.c */ 00234 00235 extern void post_create_inferior (struct target_ops *, int); 00236 00237 extern void attach_command (char *, int); 00238 00239 extern char *get_inferior_args (void); 00240 00241 extern void set_inferior_args (char *); 00242 00243 extern void set_inferior_args_vector (int, char **); 00244 00245 extern void registers_info (char *, int); 00246 00247 extern void continue_1 (int all_threads); 00248 00249 extern void interrupt_target_1 (int all_threads); 00250 00251 extern void delete_longjmp_breakpoint_cleanup (void *arg); 00252 00253 extern void detach_command (char *, int); 00254 00255 extern void notice_new_inferior (ptid_t, int, int); 00256 00257 extern struct value *get_return_value (struct value *function, 00258 struct type *value_type); 00259 00260 /* Address at which inferior stopped. */ 00261 00262 extern CORE_ADDR stop_pc; 00263 00264 /* Nonzero if stopped due to completion of a stack dummy routine. */ 00265 00266 extern enum stop_stack_kind stop_stack_dummy; 00267 00268 /* Nonzero if program stopped due to a random (unexpected) signal in 00269 inferior process. */ 00270 00271 extern int stopped_by_random_signal; 00272 00273 /* STEP_OVER_ALL means step over all subroutine calls. 00274 STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions. 00275 STEP_OVER_NONE means don't step over any subroutine calls. */ 00276 00277 enum step_over_calls_kind 00278 { 00279 STEP_OVER_NONE, 00280 STEP_OVER_ALL, 00281 STEP_OVER_UNDEBUGGABLE 00282 }; 00283 00284 /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller 00285 will handle it themselves. STOP_QUIETLY is used when running in 00286 the shell before the child program has been exec'd and when running 00287 through shared library loading. STOP_QUIETLY_REMOTE is used when 00288 setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP 00289 except that there is no need to hide a signal. */ 00290 00291 /* It is also used after attach, due to attaching to a process. This 00292 is a bit trickier. When doing an attach, the kernel stops the 00293 debuggee with a SIGSTOP. On newer GNU/Linux kernels (>= 2.5.61) 00294 the handling of SIGSTOP for a ptraced process has changed. Earlier 00295 versions of the kernel would ignore these SIGSTOPs, while now 00296 SIGSTOP is treated like any other signal, i.e. it is not muffled. 00297 00298 If the gdb user does a 'continue' after the 'attach', gdb passes 00299 the global variable stop_signal (which stores the signal from the 00300 attach, SIGSTOP) to the ptrace(PTRACE_CONT,...) call. This is 00301 problematic, because the kernel doesn't ignore such SIGSTOP 00302 now. I.e. it is reported back to gdb, which in turn presents it 00303 back to the user. 00304 00305 To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows 00306 gdb to clear the value of stop_signal after the attach, so that it 00307 is not passed back down to the kernel. */ 00308 00309 enum stop_kind 00310 { 00311 NO_STOP_QUIETLY = 0, 00312 STOP_QUIETLY, 00313 STOP_QUIETLY_REMOTE, 00314 STOP_QUIETLY_NO_SIGSTOP 00315 }; 00316 00317 /* Reverse execution. */ 00318 enum exec_direction_kind 00319 { 00320 EXEC_FORWARD, 00321 EXEC_REVERSE 00322 }; 00323 00324 /* The current execution direction. This should only be set to enum 00325 exec_direction_kind values. It is only an int to make it 00326 compatible with make_cleanup_restore_integer. */ 00327 extern int execution_direction; 00328 00329 /* Save register contents here when executing a "finish" command or are 00330 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set. 00331 Thus this contains the return value from the called function (assuming 00332 values are returned in a register). */ 00333 00334 extern struct regcache *stop_registers; 00335 00336 /* True if we are debugging displaced stepping. */ 00337 extern int debug_displaced; 00338 00339 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ 00340 void displaced_step_dump_bytes (struct ui_file *file, 00341 const gdb_byte *buf, size_t len); 00342 00343 struct displaced_step_closure *get_displaced_step_closure_by_addr (CORE_ADDR addr); 00344 00345 /* Possible values for gdbarch_call_dummy_location. */ 00346 #define ON_STACK 1 00347 #define AT_ENTRY_POINT 4 00348 00349 /* If STARTUP_WITH_SHELL is set, GDB's "run" 00350 will attempts to start up the debugee under a shell. 00351 This is in order for argument-expansion to occur. E.g., 00352 (gdb) run * 00353 The "*" gets expanded by the shell into a list of files. 00354 While this is a nice feature, it turns out to interact badly 00355 with some of the catch-fork/catch-exec features we have added. 00356 In particular, if the shell does any fork/exec's before 00357 the exec of the target program, that can confuse GDB. 00358 To disable this feature, set STARTUP_WITH_SHELL to 0. 00359 To enable this feature, set STARTUP_WITH_SHELL to 1. 00360 The catch-exec traps expected during start-up will 00361 be 1 if target is not started up with a shell, 2 if it is. 00362 - RT 00363 If you disable this, you need to decrement 00364 START_INFERIOR_TRAPS_EXPECTED in tm.h. */ 00365 #define STARTUP_WITH_SHELL 1 00366 #if !defined(START_INFERIOR_TRAPS_EXPECTED) 00367 #define START_INFERIOR_TRAPS_EXPECTED 2 00368 #endif 00369 00370 struct private_inferior; 00371 00372 /* Inferior process specific part of `struct infcall_control_state'. 00373 00374 Inferior thread counterpart is `struct thread_control_state'. */ 00375 00376 struct inferior_control_state 00377 { 00378 /* See the definition of stop_kind above. */ 00379 enum stop_kind stop_soon; 00380 }; 00381 00382 /* Inferior process specific part of `struct infcall_suspend_state'. 00383 00384 Inferior thread counterpart is `struct thread_suspend_state'. */ 00385 00386 #if 0 /* Currently unused and empty structures are not valid C. */ 00387 struct inferior_suspend_state 00388 { 00389 }; 00390 #endif 00391 00392 /* GDB represents the state of each program execution with an object 00393 called an inferior. An inferior typically corresponds to a process 00394 but is more general and applies also to targets that do not have a 00395 notion of processes. Each run of an executable creates a new 00396 inferior, as does each attachment to an existing process. 00397 Inferiors have unique internal identifiers that are different from 00398 target process ids. Each inferior may in turn have multiple 00399 threads running in it. */ 00400 00401 struct inferior 00402 { 00403 /* Pointer to next inferior in singly-linked list of inferiors. */ 00404 struct inferior *next; 00405 00406 /* Convenient handle (GDB inferior id). Unique across all 00407 inferiors. */ 00408 int num; 00409 00410 /* Actual target inferior id, usually, a process id. This matches 00411 the ptid_t.pid member of threads of this inferior. */ 00412 int pid; 00413 /* True if the PID was actually faked by GDB. */ 00414 int fake_pid_p; 00415 00416 /* State of GDB control of inferior process execution. 00417 See `struct inferior_control_state'. */ 00418 struct inferior_control_state control; 00419 00420 /* State of inferior process to restore after GDB is done with an inferior 00421 call. See `struct inferior_suspend_state'. */ 00422 #if 0 /* Currently unused and empty structures are not valid C. */ 00423 struct inferior_suspend_state suspend; 00424 #endif 00425 00426 /* True if this was an auto-created inferior, e.g. created from 00427 following a fork; false, if this inferior was manually added by 00428 the user, and we should not attempt to prune it 00429 automatically. */ 00430 int removable; 00431 00432 /* The address space bound to this inferior. */ 00433 struct address_space *aspace; 00434 00435 /* The program space bound to this inferior. */ 00436 struct program_space *pspace; 00437 00438 /* The arguments string to use when running. */ 00439 char *args; 00440 00441 /* The size of elements in argv. */ 00442 int argc; 00443 00444 /* The vector version of arguments. If ARGC is nonzero, 00445 then we must compute ARGS from this (via the target). 00446 This is always coming from main's argv and therefore 00447 should never be freed. */ 00448 char **argv; 00449 00450 /* The name of terminal device to use for I/O. */ 00451 char *terminal; 00452 00453 /* Environment to use for running inferior, 00454 in format described in environ.h. */ 00455 struct gdb_environ *environment; 00456 00457 /* Nonzero if this child process was attached rather than 00458 forked. */ 00459 int attach_flag; 00460 00461 /* If this inferior is a vfork child, then this is the pointer to 00462 its vfork parent, if GDB is still attached to it. */ 00463 struct inferior *vfork_parent; 00464 00465 /* If this process is a vfork parent, this is the pointer to the 00466 child. Since a vfork parent is left frozen by the kernel until 00467 the child execs or exits, a process can only have one vfork child 00468 at a given time. */ 00469 struct inferior *vfork_child; 00470 00471 /* True if this inferior should be detached when it's vfork sibling 00472 exits or execs. */ 00473 int pending_detach; 00474 00475 /* True if this inferior is a vfork parent waiting for a vfork child 00476 not under our control to be done with the shared memory region, 00477 either by exiting or execing. */ 00478 int waiting_for_vfork_done; 00479 00480 /* True if we're in the process of detaching from this inferior. */ 00481 int detaching; 00482 00483 /* What is left to do for an execution command after any thread of 00484 this inferior stops. For continuations associated with a 00485 specific thread, see `struct thread_info'. */ 00486 struct continuation *continuations; 00487 00488 /* Private data used by the target vector implementation. */ 00489 struct private_inferior *private; 00490 00491 /* HAS_EXIT_CODE is true if the inferior exited with an exit code. 00492 In this case, the EXIT_CODE field is also valid. */ 00493 int has_exit_code; 00494 LONGEST exit_code; 00495 00496 /* Default flags to pass to the symbol reading functions. These are 00497 used whenever a new objfile is created. The valid values come 00498 from enum symfile_add_flags. */ 00499 int symfile_flags; 00500 00501 /* Info about an inferior's target description (if it's fetched; the 00502 user supplied description's filename, if any; etc.). */ 00503 struct target_desc_info *tdesc_info; 00504 00505 /* The architecture associated with the inferior through the 00506 connection to the target. 00507 00508 The architecture vector provides some information that is really 00509 a property of the inferior, accessed through a particular target: 00510 ptrace operations; the layout of certain RSP packets; the 00511 solib_ops vector; etc. To differentiate architecture accesses to 00512 per-inferior/target properties from 00513 per-thread/per-frame/per-objfile properties, accesses to 00514 per-inferior/target properties should be made through 00515 this gdbarch. */ 00516 struct gdbarch *gdbarch; 00517 00518 /* Per inferior data-pointers required by other GDB modules. */ 00519 REGISTRY_FIELDS; 00520 }; 00521 00522 /* Keep a registry of per-inferior data-pointers required by other GDB 00523 modules. */ 00524 00525 DECLARE_REGISTRY (inferior); 00526 00527 /* Create an empty inferior list, or empty the existing one. */ 00528 extern void init_inferior_list (void); 00529 00530 /* Add an inferior to the inferior list, print a message that a new 00531 inferior is found, and return the pointer to the new inferior. 00532 Caller may use this pointer to initialize the private inferior 00533 data. */ 00534 extern struct inferior *add_inferior (int pid); 00535 00536 /* Same as add_inferior, but don't print new inferior notifications to 00537 the CLI. */ 00538 extern struct inferior *add_inferior_silent (int pid); 00539 00540 /* Delete an existing inferior list entry, due to inferior exit. */ 00541 extern void delete_inferior (int pid); 00542 00543 extern void delete_inferior_1 (struct inferior *todel, int silent); 00544 00545 /* Same as delete_inferior, but don't print new inferior notifications 00546 to the CLI. */ 00547 extern void delete_inferior_silent (int pid); 00548 00549 /* Delete an existing inferior list entry, due to inferior detaching. */ 00550 extern void detach_inferior (int pid); 00551 00552 extern void exit_inferior (int pid); 00553 00554 extern void exit_inferior_silent (int pid); 00555 00556 extern void exit_inferior_num_silent (int num); 00557 00558 extern void inferior_appeared (struct inferior *inf, int pid); 00559 00560 /* Get rid of all inferiors. */ 00561 extern void discard_all_inferiors (void); 00562 00563 /* Translate the integer inferior id (GDB's homegrown id, not the system's) 00564 into a "pid" (which may be overloaded with extra inferior information). */ 00565 extern int gdb_inferior_id_to_pid (int); 00566 00567 /* Translate a target 'pid' into the integer inferior id (GDB's 00568 homegrown id, not the system's). */ 00569 extern int pid_to_gdb_inferior_id (int pid); 00570 00571 /* Boolean test for an already-known pid. */ 00572 extern int in_inferior_list (int pid); 00573 00574 /* Boolean test for an already-known inferior id (GDB's homegrown id, 00575 not the system's). */ 00576 extern int valid_gdb_inferior_id (int num); 00577 00578 /* Search function to lookup an inferior by target 'pid'. */ 00579 extern struct inferior *find_inferior_pid (int pid); 00580 00581 /* Search function to lookup an inferior by GDB 'num'. */ 00582 extern struct inferior *find_inferior_id (int num); 00583 00584 /* Find an inferior bound to PSPACE. */ 00585 extern struct inferior * 00586 find_inferior_for_program_space (struct program_space *pspace); 00587 00588 /* Inferior iterator function. 00589 00590 Calls a callback function once for each inferior, so long as the 00591 callback function returns false. If the callback function returns 00592 true, the iteration will end and the current inferior will be 00593 returned. This can be useful for implementing a search for a 00594 inferior with arbitrary attributes, or for applying some operation 00595 to every inferior. 00596 00597 It is safe to delete the iterated inferior from the callback. */ 00598 extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *, 00599 void *), 00600 void *); 00601 00602 /* Returns true if the inferior list is not empty. */ 00603 extern int have_inferiors (void); 00604 00605 /* Returns true if there are any live inferiors in the inferior list 00606 (not cores, not executables, real live processes). */ 00607 extern int have_live_inferiors (void); 00608 00609 /* Return a pointer to the current inferior. It is an error to call 00610 this if there is no current inferior. */ 00611 extern struct inferior *current_inferior (void); 00612 00613 extern void set_current_inferior (struct inferior *); 00614 00615 extern struct cleanup *save_current_inferior (void); 00616 00617 /* Traverse all inferiors. */ 00618 00619 #define ALL_INFERIORS(I) \ 00620 for ((I) = inferior_list; (I); (I) = (I)->next) 00621 00622 extern struct inferior *inferior_list; 00623 00624 /* Prune away automatically added inferiors that aren't required 00625 anymore. */ 00626 extern void prune_inferiors (void); 00627 00628 extern int number_of_inferiors (void); 00629 00630 extern struct inferior *add_inferior_with_spaces (void); 00631 00632 extern void update_observer_mode (void); 00633 00634 extern void update_signals_program_target (void); 00635 00636 extern void signal_catch_update (const unsigned int *); 00637 00638 /* In some circumstances we allow a command to specify a numeric 00639 signal. The idea is to keep these circumstances limited so that 00640 users (and scripts) develop portable habits. For comparison, 00641 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a 00642 numeric signal at all is obsolescent. We are slightly more lenient 00643 and allow 1-15 which should match host signal numbers on most 00644 systems. Use of symbolic signal names is strongly encouraged. */ 00645 00646 enum gdb_signal gdb_signal_from_command (int num); 00647 00648 #endif /* !defined (INFERIOR_H) */