| 1 | /* Variables that describe the inferior process running under GDB: |
| 2 | Where it is, why it stopped, and how to step it. |
| 3 | Copyright 1986, 1989, 1992, 1996, 1998 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #if !defined (INFERIOR_H) |
| 22 | #define INFERIOR_H 1 |
| 23 | |
| 24 | /* For bpstat. */ |
| 25 | #include "breakpoint.h" |
| 26 | |
| 27 | /* For enum target_signal. */ |
| 28 | #include "target.h" |
| 29 | |
| 30 | /* Structure in which to save the status of the inferior. Save |
| 31 | through "save_inferior_status", restore through |
| 32 | "restore_inferior_status". |
| 33 | This pair of routines should be called around any transfer of |
| 34 | control to the inferior which you don't want showing up in your |
| 35 | control variables. */ |
| 36 | |
| 37 | struct inferior_status { |
| 38 | enum target_signal stop_signal; |
| 39 | CORE_ADDR stop_pc; |
| 40 | bpstat stop_bpstat; |
| 41 | int stop_step; |
| 42 | int stop_stack_dummy; |
| 43 | int stopped_by_random_signal; |
| 44 | int trap_expected; |
| 45 | CORE_ADDR step_range_start; |
| 46 | CORE_ADDR step_range_end; |
| 47 | CORE_ADDR step_frame_address; |
| 48 | int step_over_calls; |
| 49 | CORE_ADDR step_resume_break_address; |
| 50 | int stop_after_trap; |
| 51 | int stop_soon_quietly; |
| 52 | CORE_ADDR selected_frame_address; |
| 53 | char stop_registers[REGISTER_BYTES]; |
| 54 | |
| 55 | /* These are here because if call_function_by_hand has written some |
| 56 | registers and then decides to call error(), we better not have changed |
| 57 | any registers. */ |
| 58 | char registers[REGISTER_BYTES]; |
| 59 | |
| 60 | int selected_level; |
| 61 | int breakpoint_proceeded; |
| 62 | int restore_stack_info; |
| 63 | int proceed_to_finish; |
| 64 | }; |
| 65 | |
| 66 | /* This macro gives the number of registers actually in use by the |
| 67 | inferior. This may be less than the total number of registers, |
| 68 | perhaps depending on the actual CPU in use or program being run. */ |
| 69 | |
| 70 | #ifndef ARCH_NUM_REGS |
| 71 | #define ARCH_NUM_REGS NUM_REGS |
| 72 | #endif |
| 73 | |
| 74 | extern void save_inferior_status PARAMS ((struct inferior_status *, int)); |
| 75 | |
| 76 | extern void restore_inferior_status PARAMS ((struct inferior_status *)); |
| 77 | |
| 78 | extern void set_sigint_trap PARAMS ((void)); |
| 79 | |
| 80 | extern void clear_sigint_trap PARAMS ((void)); |
| 81 | |
| 82 | extern void set_sigio_trap PARAMS ((void)); |
| 83 | |
| 84 | extern void clear_sigio_trap PARAMS ((void)); |
| 85 | |
| 86 | /* File name for default use for standard in/out in the inferior. */ |
| 87 | |
| 88 | extern char *inferior_io_terminal; |
| 89 | |
| 90 | /* Pid of our debugged inferior, or 0 if no inferior now. */ |
| 91 | |
| 92 | extern int inferior_pid; |
| 93 | |
| 94 | /* This is only valid when inferior_pid is non-zero. |
| 95 | |
| 96 | If this is 0, then exec events should be noticed and responded to |
| 97 | by the debugger (i.e., be reported to the user). |
| 98 | |
| 99 | If this is > 0, then that many subsequent exec events should be |
| 100 | ignored (i.e., not be reported to the user). |
| 101 | */ |
| 102 | extern int inferior_ignoring_startup_exec_events; |
| 103 | |
| 104 | /* This is only valid when inferior_ignoring_startup_exec_events is |
| 105 | zero. |
| 106 | |
| 107 | Some targets (stupidly) report more than one exec event per actual |
| 108 | call to an event() system call. If only the last such exec event |
| 109 | need actually be noticed and responded to by the debugger (i.e., |
| 110 | be reported to the user), then this is the number of "leading" |
| 111 | exec events which should be ignored. |
| 112 | */ |
| 113 | extern int inferior_ignoring_leading_exec_events; |
| 114 | |
| 115 | /* Inferior environment. */ |
| 116 | |
| 117 | extern struct environ *inferior_environ; |
| 118 | |
| 119 | /* Character array containing an image of the inferior programs' registers. */ |
| 120 | |
| 121 | extern char registers[]; |
| 122 | |
| 123 | /* Array of validity bits (one per register). Nonzero at position XXX_REGNUM |
| 124 | means that `registers' contains a valid copy of inferior register XXX. |
| 125 | -1 if register value is not available. */ |
| 126 | |
| 127 | extern SIGNED char register_valid[NUM_REGS]; |
| 128 | |
| 129 | extern void clear_proceed_status PARAMS ((void)); |
| 130 | |
| 131 | extern void proceed PARAMS ((CORE_ADDR, enum target_signal, int)); |
| 132 | |
| 133 | extern void kill_inferior PARAMS ((void)); |
| 134 | |
| 135 | extern void generic_mourn_inferior PARAMS ((void)); |
| 136 | |
| 137 | extern void terminal_ours PARAMS ((void)); |
| 138 | |
| 139 | extern int run_stack_dummy PARAMS ((CORE_ADDR, char [REGISTER_BYTES])); |
| 140 | |
| 141 | extern CORE_ADDR read_pc PARAMS ((void)); |
| 142 | |
| 143 | extern CORE_ADDR read_pc_pid PARAMS ((int)); |
| 144 | |
| 145 | extern void write_pc PARAMS ((CORE_ADDR)); |
| 146 | |
| 147 | extern void write_pc_pid PARAMS ((CORE_ADDR, int)); |
| 148 | |
| 149 | extern CORE_ADDR read_sp PARAMS ((void)); |
| 150 | |
| 151 | extern void write_sp PARAMS ((CORE_ADDR)); |
| 152 | |
| 153 | extern CORE_ADDR read_fp PARAMS ((void)); |
| 154 | |
| 155 | extern void write_fp PARAMS ((CORE_ADDR)); |
| 156 | |
| 157 | extern void wait_for_inferior PARAMS ((void)); |
| 158 | |
| 159 | extern void init_wait_for_inferior PARAMS ((void)); |
| 160 | |
| 161 | extern void close_exec_file PARAMS ((void)); |
| 162 | |
| 163 | extern void reopen_exec_file PARAMS ((void)); |
| 164 | |
| 165 | /* The `resume' routine should only be called in special circumstances. |
| 166 | Normally, use `proceed', which handles a lot of bookkeeping. */ |
| 167 | |
| 168 | extern void resume PARAMS ((int, enum target_signal)); |
| 169 | |
| 170 | /* From misc files */ |
| 171 | |
| 172 | extern void store_inferior_registers PARAMS ((int)); |
| 173 | |
| 174 | extern void fetch_inferior_registers PARAMS ((int)); |
| 175 | |
| 176 | extern void solib_create_inferior_hook PARAMS ((void)); |
| 177 | |
| 178 | extern void child_terminal_info PARAMS ((char *, int)); |
| 179 | |
| 180 | extern void term_info PARAMS ((char *, int)); |
| 181 | |
| 182 | extern void terminal_ours_for_output PARAMS ((void)); |
| 183 | |
| 184 | extern void terminal_inferior PARAMS ((void)); |
| 185 | |
| 186 | extern void terminal_init_inferior PARAMS ((void)); |
| 187 | |
| 188 | extern void terminal_init_inferior_with_pgrp PARAMS ((int pgrp)); |
| 189 | |
| 190 | /* From infptrace.c or infttrace.c */ |
| 191 | |
| 192 | extern int attach PARAMS ((int)); |
| 193 | |
| 194 | #if !defined(REQUIRE_ATTACH) |
| 195 | #define REQUIRE_ATTACH attach |
| 196 | #endif |
| 197 | |
| 198 | #if !defined(REQUIRE_DETACH) |
| 199 | #define REQUIRE_DETACH(pid,siggnal) detach (siggnal) |
| 200 | #endif |
| 201 | |
| 202 | extern void detach PARAMS ((int)); |
| 203 | |
| 204 | int proc_wait PARAMS ((int, int *)); |
| 205 | |
| 206 | extern void child_resume PARAMS ((int, int, enum target_signal)); |
| 207 | |
| 208 | #ifndef PTRACE_ARG3_TYPE |
| 209 | #define PTRACE_ARG3_TYPE int /* Correct definition for most systems. */ |
| 210 | #endif |
| 211 | |
| 212 | extern int call_ptrace PARAMS ((int, int, PTRACE_ARG3_TYPE, int)); |
| 213 | |
| 214 | extern void pre_fork_inferior PARAMS ((void)); |
| 215 | |
| 216 | /* From procfs.c */ |
| 217 | |
| 218 | extern int proc_iterate_over_mappings PARAMS ((int (*) (int, CORE_ADDR))); |
| 219 | |
| 220 | extern int procfs_first_available PARAMS ((void)); |
| 221 | |
| 222 | extern int procfs_get_pid_fd PARAMS ((int)); |
| 223 | |
| 224 | /* From fork-child.c */ |
| 225 | |
| 226 | extern void fork_inferior PARAMS ((char *, char *, char **, |
| 227 | void (*) (void), |
| 228 | void (*) (int), |
| 229 | void (*) (void), |
| 230 | char *)); |
| 231 | |
| 232 | |
| 233 | extern void |
| 234 | clone_and_follow_inferior PARAMS ((int, int *)); |
| 235 | |
| 236 | extern void startup_inferior PARAMS ((int)); |
| 237 | |
| 238 | /* From inflow.c */ |
| 239 | |
| 240 | extern void new_tty_prefork PARAMS ((char *)); |
| 241 | |
| 242 | extern int gdb_has_a_terminal PARAMS ((void)); |
| 243 | |
| 244 | /* From infrun.c */ |
| 245 | |
| 246 | extern void start_remote PARAMS ((void)); |
| 247 | |
| 248 | extern void normal_stop PARAMS ((void)); |
| 249 | |
| 250 | extern int signal_stop_state PARAMS ((int)); |
| 251 | |
| 252 | extern int signal_print_state PARAMS ((int)); |
| 253 | |
| 254 | extern int signal_pass_state PARAMS ((int)); |
| 255 | |
| 256 | /* From infcmd.c */ |
| 257 | |
| 258 | extern void tty_command PARAMS ((char *, int)); |
| 259 | |
| 260 | extern void attach_command PARAMS ((char *, int)); |
| 261 | |
| 262 | /* Last signal that the inferior received (why it stopped). */ |
| 263 | |
| 264 | extern enum target_signal stop_signal; |
| 265 | |
| 266 | /* Address at which inferior stopped. */ |
| 267 | |
| 268 | extern CORE_ADDR stop_pc; |
| 269 | |
| 270 | /* Chain containing status of breakpoint(s) that we have stopped at. */ |
| 271 | |
| 272 | extern bpstat stop_bpstat; |
| 273 | |
| 274 | /* Flag indicating that a command has proceeded the inferior past the |
| 275 | current breakpoint. */ |
| 276 | |
| 277 | extern int breakpoint_proceeded; |
| 278 | |
| 279 | /* Nonzero if stopped due to a step command. */ |
| 280 | |
| 281 | extern int stop_step; |
| 282 | |
| 283 | /* Nonzero if stopped due to completion of a stack dummy routine. */ |
| 284 | |
| 285 | extern int stop_stack_dummy; |
| 286 | |
| 287 | /* Nonzero if program stopped due to a random (unexpected) signal in |
| 288 | inferior process. */ |
| 289 | |
| 290 | extern int stopped_by_random_signal; |
| 291 | |
| 292 | /* Range to single step within. |
| 293 | If this is nonzero, respond to a single-step signal |
| 294 | by continuing to step if the pc is in this range. |
| 295 | |
| 296 | If step_range_start and step_range_end are both 1, it means to step for |
| 297 | a single instruction (FIXME: it might clean up wait_for_inferior in a |
| 298 | minor way if this were changed to the address of the instruction and |
| 299 | that address plus one. But maybe not.). */ |
| 300 | |
| 301 | extern CORE_ADDR step_range_start; /* Inclusive */ |
| 302 | extern CORE_ADDR step_range_end; /* Exclusive */ |
| 303 | |
| 304 | /* Stack frame address as of when stepping command was issued. |
| 305 | This is how we know when we step into a subroutine call, |
| 306 | and how to set the frame for the breakpoint used to step out. */ |
| 307 | |
| 308 | extern CORE_ADDR step_frame_address; |
| 309 | |
| 310 | /* Our notion of the current stack pointer. */ |
| 311 | |
| 312 | extern CORE_ADDR step_sp; |
| 313 | |
| 314 | /* 1 means step over all subroutine calls. |
| 315 | -1 means step over calls to undebuggable functions. */ |
| 316 | |
| 317 | extern int step_over_calls; |
| 318 | |
| 319 | /* If stepping, nonzero means step count is > 1 |
| 320 | so don't print frame next time inferior stops |
| 321 | if it stops due to stepping. */ |
| 322 | |
| 323 | extern int step_multi; |
| 324 | |
| 325 | /* Nonzero means expecting a trap and caller will handle it themselves. |
| 326 | It is used after attach, due to attaching to a process; |
| 327 | when running in the shell before the child program has been exec'd; |
| 328 | and when running some kinds of remote stuff (FIXME?). */ |
| 329 | |
| 330 | extern int stop_soon_quietly; |
| 331 | |
| 332 | /* Nonzero if proceed is being used for a "finish" command or a similar |
| 333 | situation when stop_registers should be saved. */ |
| 334 | |
| 335 | extern int proceed_to_finish; |
| 336 | |
| 337 | /* Save register contents here when about to pop a stack dummy frame, |
| 338 | if-and-only-if proceed_to_finish is set. |
| 339 | Thus this contains the return value from the called function (assuming |
| 340 | values are returned in a register). */ |
| 341 | |
| 342 | extern char stop_registers[REGISTER_BYTES]; |
| 343 | |
| 344 | /* Nonzero if the child process in inferior_pid was attached rather |
| 345 | than forked. */ |
| 346 | |
| 347 | extern int attach_flag; |
| 348 | \f |
| 349 | /* Sigtramp is a routine that the kernel calls (which then calls the |
| 350 | signal handler). On most machines it is a library routine that |
| 351 | is linked into the executable. |
| 352 | |
| 353 | This macro, given a program counter value and the name of the |
| 354 | function in which that PC resides (which can be null if the |
| 355 | name is not known), returns nonzero if the PC and name show |
| 356 | that we are in sigtramp. |
| 357 | |
| 358 | On most machines just see if the name is sigtramp (and if we have |
| 359 | no name, assume we are not in sigtramp). */ |
| 360 | #if !defined (IN_SIGTRAMP) |
| 361 | # if defined (SIGTRAMP_START) |
| 362 | # define IN_SIGTRAMP(pc, name) \ |
| 363 | ((pc) >= SIGTRAMP_START(pc) \ |
| 364 | && (pc) < SIGTRAMP_END(pc) \ |
| 365 | ) |
| 366 | # else |
| 367 | # define IN_SIGTRAMP(pc, name) \ |
| 368 | (name && STREQ ("_sigtramp", name)) |
| 369 | # endif |
| 370 | #endif |
| 371 | \f |
| 372 | /* Possible values for CALL_DUMMY_LOCATION. */ |
| 373 | #define ON_STACK 1 |
| 374 | #define BEFORE_TEXT_END 2 |
| 375 | #define AFTER_TEXT_END 3 |
| 376 | #define AT_ENTRY_POINT 4 |
| 377 | |
| 378 | #if !defined (CALL_DUMMY_LOCATION) |
| 379 | #define CALL_DUMMY_LOCATION ON_STACK |
| 380 | #endif /* No CALL_DUMMY_LOCATION. */ |
| 381 | |
| 382 | /* Are we in a call dummy? The code below which allows DECR_PC_AFTER_BREAK |
| 383 | below is for infrun.c, which may give the macro a pc without that |
| 384 | subtracted out. */ |
| 385 | #if !defined (PC_IN_CALL_DUMMY) |
| 386 | #if CALL_DUMMY_LOCATION == BEFORE_TEXT_END |
| 387 | extern CORE_ADDR text_end; |
| 388 | #define PC_IN_CALL_DUMMY(pc, sp, frame_address) \ |
| 389 | ((pc) >= text_end - CALL_DUMMY_LENGTH \ |
| 390 | && (pc) <= text_end + DECR_PC_AFTER_BREAK) |
| 391 | #endif /* Before text_end. */ |
| 392 | |
| 393 | #if CALL_DUMMY_LOCATION == AFTER_TEXT_END |
| 394 | extern CORE_ADDR text_end; |
| 395 | #define PC_IN_CALL_DUMMY(pc, sp, frame_address) \ |
| 396 | ((pc) >= text_end \ |
| 397 | && (pc) <= text_end + CALL_DUMMY_LENGTH + DECR_PC_AFTER_BREAK) |
| 398 | #endif /* After text_end. */ |
| 399 | |
| 400 | #if CALL_DUMMY_LOCATION == ON_STACK |
| 401 | /* Is the PC in a call dummy? SP and FRAME_ADDRESS are the bottom and |
| 402 | top of the stack frame which we are checking, where "bottom" and |
| 403 | "top" refer to some section of memory which contains the code for |
| 404 | the call dummy. Calls to this macro assume that the contents of |
| 405 | SP_REGNUM and FP_REGNUM (or the saved values thereof), respectively, |
| 406 | are the things to pass. |
| 407 | |
| 408 | This won't work on the 29k, where SP_REGNUM and FP_REGNUM don't |
| 409 | have that meaning, but the 29k doesn't use ON_STACK. This could be |
| 410 | fixed by generalizing this scheme, perhaps by passing in a frame |
| 411 | and adding a few fields, at least on machines which need them for |
| 412 | PC_IN_CALL_DUMMY. |
| 413 | |
| 414 | Something simpler, like checking for the stack segment, doesn't work, |
| 415 | since various programs (threads implementations, gcc nested function |
| 416 | stubs, etc) may either allocate stack frames in another segment, or |
| 417 | allocate other kinds of code on the stack. */ |
| 418 | |
| 419 | #define PC_IN_CALL_DUMMY(pc, sp, frame_address) \ |
| 420 | (INNER_THAN ((sp), (pc)) && (frame_address != 0) && INNER_THAN ((pc), (frame_address))) |
| 421 | #endif /* On stack. */ |
| 422 | |
| 423 | #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT |
| 424 | #define PC_IN_CALL_DUMMY(pc, sp, frame_address) \ |
| 425 | ((pc) >= CALL_DUMMY_ADDRESS () \ |
| 426 | && (pc) <= (CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK)) |
| 427 | #endif /* At entry point. */ |
| 428 | #endif /* No PC_IN_CALL_DUMMY. */ |
| 429 | |
| 430 | /* It's often not enough for our clients to know whether the PC is merely |
| 431 | somewhere within the call dummy. They may need to know whether the |
| 432 | call dummy has actually completed. (For example, wait_for_inferior |
| 433 | wants to know when it should truly stop because the call dummy has |
| 434 | completed. If we're single-stepping because of slow watchpoints, |
| 435 | then we may find ourselves stopped at the entry of the call dummy, |
| 436 | and want to continue stepping until we reach the end.) |
| 437 | |
| 438 | Note that this macro is intended for targets (like HP-UX) which |
| 439 | require more than a single breakpoint in their call dummies, and |
| 440 | therefore cannot use the CALL_DUMMY_BREAKPOINT_OFFSET mechanism. |
| 441 | |
| 442 | If a target does define CALL_DUMMY_BREAKPOINT_OFFSET, then this |
| 443 | default implementation of CALL_DUMMY_HAS_COMPLETED is sufficient. |
| 444 | Else, a target may wish to supply an implementation that works in |
| 445 | the presense of multiple breakpoints in its call dummy. |
| 446 | */ |
| 447 | #if !defined(CALL_DUMMY_HAS_COMPLETED) |
| 448 | #define CALL_DUMMY_HAS_COMPLETED(pc, sp, frame_address) \ |
| 449 | PC_IN_CALL_DUMMY((pc), (sp), (frame_address)) |
| 450 | #endif |
| 451 | |
| 452 | /* If STARTUP_WITH_SHELL is set, GDB's "run" |
| 453 | will attempts to start up the debugee under a shell. |
| 454 | This is in order for argument-expansion to occur. E.g., |
| 455 | (gdb) run * |
| 456 | The "*" gets expanded by the shell into a list of files. |
| 457 | While this is a nice feature, it turns out to interact badly |
| 458 | with some of the catch-fork/catch-exec features we have added. |
| 459 | In particular, if the shell does any fork/exec's before |
| 460 | the exec of the target program, that can confuse GDB. |
| 461 | To disable this feature, set STARTUP_WITH_SHELL to 0. |
| 462 | To enable this feature, set STARTUP_WITH_SHELL to 1. |
| 463 | The catch-exec traps expected during start-up will |
| 464 | be 1 if target is not started up with a shell, 2 if it is. |
| 465 | - RT |
| 466 | If you disable this, you need to decrement |
| 467 | START_INFERIOR_TRAPS_EXPECTED in tm.h. */ |
| 468 | #define STARTUP_WITH_SHELL 1 |
| 469 | |
| 470 | #endif /* !defined (INFERIOR_H) */ |
| 471 | |