]>
Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Start (run) and stop the inferior process, for GDB. |
2 | Copyright (C) 1986, 1987, 1988, 1989, 1991 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
3b271cf4 | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
3b271cf4 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
3b271cf4 | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
3b271cf4 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 RP |
19 | |
20 | /* Notes on the algorithm used in wait_for_inferior to determine if we | |
21 | just did a subroutine call when stepping. We have the following | |
22 | information at that point: | |
23 | ||
24 | Current and previous (just before this step) pc. | |
25 | Current and previous sp. | |
26 | Current and previous start of current function. | |
27 | ||
28 | If the start's of the functions don't match, then | |
29 | ||
30 | a) We did a subroutine call. | |
31 | ||
32 | In this case, the pc will be at the beginning of a function. | |
33 | ||
34 | b) We did a subroutine return. | |
35 | ||
36 | Otherwise. | |
37 | ||
38 | c) We did a longjmp. | |
39 | ||
40 | If we did a longjump, we were doing "nexti", since a next would | |
41 | have attempted to skip over the assembly language routine in which | |
42 | the longjmp is coded and would have simply been the equivalent of a | |
43 | continue. I consider this ok behaivior. We'd like one of two | |
44 | things to happen if we are doing a nexti through the longjmp() | |
45 | routine: 1) It behaves as a stepi, or 2) It acts like a continue as | |
46 | above. Given that this is a special case, and that anybody who | |
47 | thinks that the concept of sub calls is meaningful in the context | |
48 | of a longjmp, I'll take either one. Let's see what happens. | |
49 | ||
50 | Acts like a subroutine return. I can handle that with no problem | |
51 | at all. | |
52 | ||
53 | -->So: If the current and previous beginnings of the current | |
54 | function don't match, *and* the pc is at the start of a function, | |
55 | we've done a subroutine call. If the pc is not at the start of a | |
56 | function, we *didn't* do a subroutine call. | |
57 | ||
58 | -->If the beginnings of the current and previous function do match, | |
59 | either: | |
60 | ||
61 | a) We just did a recursive call. | |
62 | ||
63 | In this case, we would be at the very beginning of a | |
64 | function and 1) it will have a prologue (don't jump to | |
65 | before prologue, or 2) (we assume here that it doesn't have | |
66 | a prologue) there will have been a change in the stack | |
67 | pointer over the last instruction. (Ie. it's got to put | |
68 | the saved pc somewhere. The stack is the usual place. In | |
69 | a recursive call a register is only an option if there's a | |
70 | prologue to do something with it. This is even true on | |
71 | register window machines; the prologue sets up the new | |
72 | window. It might not be true on a register window machine | |
73 | where the call instruction moved the register window | |
74 | itself. Hmmm. One would hope that the stack pointer would | |
75 | also change. If it doesn't, somebody send me a note, and | |
76 | I'll work out a more general theory. | |
77 | [email protected]). This is true (albeit slipperly | |
78 | so) on all machines I'm aware of: | |
79 | ||
80 | m68k: Call changes stack pointer. Regular jumps don't. | |
81 | ||
82 | sparc: Recursive calls must have frames and therefor, | |
83 | prologues. | |
84 | ||
85 | vax: All calls have frames and hence change the | |
86 | stack pointer. | |
87 | ||
88 | b) We did a return from a recursive call. I don't see that we | |
89 | have either the ability or the need to distinguish this | |
90 | from an ordinary jump. The stack frame will be printed | |
91 | when and if the frame pointer changes; if we are in a | |
92 | function without a frame pointer, it's the users own | |
93 | lookout. | |
94 | ||
95 | c) We did a jump within a function. We assume that this is | |
96 | true if we didn't do a recursive call. | |
97 | ||
98 | d) We are in no-man's land ("I see no symbols here"). We | |
99 | don't worry about this; it will make calls look like simple | |
100 | jumps (and the stack frames will be printed when the frame | |
101 | pointer moves), which is a reasonably non-violent response. | |
102 | ||
103 | #if 0 | |
104 | We skip this; it causes more problems than it's worth. | |
105 | #ifdef SUN4_COMPILER_FEATURE | |
106 | We do a special ifdef for the sun 4, forcing it to single step | |
107 | into calls which don't have prologues. This means that we can't | |
108 | nexti over leaf nodes, we can probably next over them (since they | |
109 | won't have debugging symbols, usually), and we can next out of | |
110 | functions returning structures (with a "call .stret4" at the end). | |
111 | #endif | |
112 | #endif | |
113 | */ | |
114 | ||
115 | ||
116 | ||
117 | ||
118 | ||
119 | #include <stdio.h> | |
120 | #include <string.h> | |
121 | #include "defs.h" | |
122 | #include "param.h" | |
123 | #include "symtab.h" | |
124 | #include "frame.h" | |
125 | #include "inferior.h" | |
126 | #include "breakpoint.h" | |
127 | #include "wait.h" | |
128 | #include "gdbcore.h" | |
129 | #include "signame.h" | |
130 | #include "command.h" | |
131 | #include "terminal.h" /* For #ifdef TIOCGPGRP and new_tty */ | |
132 | #include "target.h" | |
133 | ||
134 | #include <signal.h> | |
135 | ||
136 | /* unistd.h is needed to #define X_OK */ | |
137 | #ifdef USG | |
138 | #include <unistd.h> | |
139 | #else | |
140 | #include <sys/file.h> | |
141 | #endif | |
142 | ||
143 | #ifdef SET_STACK_LIMIT_HUGE | |
79043f9e JK |
144 | #include <sys/time.h> |
145 | #include <sys/resource.h> | |
146 | ||
bd5635a1 RP |
147 | extern int original_stack_limit; |
148 | #endif /* SET_STACK_LIMIT_HUGE */ | |
149 | ||
bd5635a1 | 150 | extern char *getenv (); |
3b271cf4 | 151 | extern char **environ; |
bd5635a1 RP |
152 | |
153 | extern struct target_ops child_ops; /* In inftarg.c */ | |
154 | ||
bd5635a1 RP |
155 | |
156 | /* Sigtramp is a routine that the kernel calls (which then calls the | |
157 | signal handler). On most machines it is a library routine that | |
158 | is linked into the executable. | |
159 | ||
160 | This macro, given a program counter value and the name of the | |
161 | function in which that PC resides (which can be null if the | |
162 | name is not known), returns nonzero if the PC and name show | |
163 | that we are in sigtramp. | |
164 | ||
165 | On most machines just see if the name is sigtramp (and if we have | |
166 | no name, assume we are not in sigtramp). */ | |
167 | #if !defined (IN_SIGTRAMP) | |
168 | #define IN_SIGTRAMP(pc, name) \ | |
680c9dfa | 169 | (name && !strcmp ("_sigtramp", name)) |
bd5635a1 RP |
170 | #endif |
171 | ||
d11c44f1 JG |
172 | #ifdef TDESC |
173 | #include "tdesc.h" | |
174 | int safe_to_init_tdesc_context = 0; | |
175 | extern dc_dcontext_t current_context; | |
176 | #endif | |
177 | ||
bd5635a1 RP |
178 | /* Tables of how to react to signals; the user sets them. */ |
179 | ||
180 | static char signal_stop[NSIG]; | |
181 | static char signal_print[NSIG]; | |
182 | static char signal_program[NSIG]; | |
183 | ||
184 | /* Nonzero if breakpoints are now inserted in the inferior. */ | |
185 | /* Nonstatic for initialization during xxx_create_inferior. FIXME. */ | |
186 | ||
187 | /*static*/ int breakpoints_inserted; | |
188 | ||
189 | /* Function inferior was in as of last step command. */ | |
190 | ||
191 | static struct symbol *step_start_function; | |
192 | ||
193 | /* Nonzero => address for special breakpoint for resuming stepping. */ | |
194 | ||
195 | static CORE_ADDR step_resume_break_address; | |
196 | ||
197 | /* Pointer to orig contents of the byte where the special breakpoint is. */ | |
198 | ||
199 | static char step_resume_break_shadow[BREAKPOINT_MAX]; | |
200 | ||
201 | /* Nonzero means the special breakpoint is a duplicate | |
202 | so it has not itself been inserted. */ | |
203 | ||
204 | static int step_resume_break_duplicate; | |
205 | ||
206 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ | |
207 | ||
208 | static int trap_expected; | |
209 | ||
210 | /* Nonzero if the next time we try to continue the inferior, it will | |
211 | step one instruction and generate a spurious trace trap. | |
212 | This is used to compensate for a bug in HP-UX. */ | |
213 | ||
214 | static int trap_expected_after_continue; | |
215 | ||
216 | /* Nonzero means expecting a trace trap | |
217 | and should stop the inferior and return silently when it happens. */ | |
218 | ||
219 | int stop_after_trap; | |
220 | ||
221 | /* Nonzero means expecting a trap and caller will handle it themselves. | |
222 | It is used after attach, due to attaching to a process; | |
223 | when running in the shell before the child program has been exec'd; | |
224 | and when running some kinds of remote stuff (FIXME?). */ | |
225 | ||
226 | int stop_soon_quietly; | |
227 | ||
228 | /* Nonzero if pc has been changed by the debugger | |
229 | since the inferior stopped. */ | |
230 | ||
231 | int pc_changed; | |
232 | ||
233 | /* Nonzero if proceed is being used for a "finish" command or a similar | |
234 | situation when stop_registers should be saved. */ | |
235 | ||
236 | int proceed_to_finish; | |
237 | ||
238 | /* Save register contents here when about to pop a stack dummy frame, | |
239 | if-and-only-if proceed_to_finish is set. | |
240 | Thus this contains the return value from the called function (assuming | |
241 | values are returned in a register). */ | |
242 | ||
243 | char stop_registers[REGISTER_BYTES]; | |
244 | ||
245 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ | |
246 | ||
247 | static int breakpoints_failed; | |
248 | ||
249 | /* Nonzero after stop if current stack frame should be printed. */ | |
250 | ||
251 | static int stop_print_frame; | |
252 | ||
253 | #ifdef NO_SINGLE_STEP | |
254 | extern int one_stepped; /* From machine dependent code */ | |
255 | extern void single_step (); /* Same. */ | |
256 | #endif /* NO_SINGLE_STEP */ | |
257 | ||
258 | static void insert_step_breakpoint (); | |
259 | static void remove_step_breakpoint (); | |
260 | /*static*/ void wait_for_inferior (); | |
261 | void init_wait_for_inferior (); | |
262 | void normal_stop (); | |
263 | ||
a71d17b1 JK |
264 | \f |
265 | /* Things to clean up if we QUIT out of resume (). */ | |
e1ce8aa5 | 266 | /* ARGSUSED */ |
a71d17b1 JK |
267 | static void |
268 | resume_cleanups (arg) | |
269 | int arg; | |
270 | { | |
271 | normal_stop (); | |
272 | } | |
273 | ||
274 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
275 | wants to interrupt some lengthy single-stepping operation | |
276 | (for child processes, the SIGINT goes to the inferior, and so | |
277 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
278 | other targets, that's not true). | |
279 | ||
280 | STEP nonzero if we should step (zero to continue instead). | |
281 | SIG is the signal to give the inferior (zero for none). */ | |
282 | static void | |
283 | resume (step, sig) | |
284 | int step; | |
285 | int sig; | |
286 | { | |
287 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); | |
288 | QUIT; | |
d11c44f1 JG |
289 | |
290 | #ifdef NO_SINGLE_STEP | |
291 | if (step) { | |
292 | single_step(); /* Do it the hard way, w/temp breakpoints */ | |
293 | step = 0; /* ...and don't ask hardware to do it. */ | |
294 | } | |
295 | #endif | |
296 | ||
bdbd5f50 JG |
297 | /* Handle any optimized stores to the inferior NOW... */ |
298 | #ifdef DO_DEFERRED_STORES | |
299 | DO_DEFERRED_STORES; | |
300 | #endif | |
301 | ||
a71d17b1 JK |
302 | target_resume (step, sig); |
303 | discard_cleanups (old_cleanups); | |
304 | } | |
305 | ||
bd5635a1 RP |
306 | \f |
307 | /* Clear out all variables saying what to do when inferior is continued. | |
308 | First do this, then set the ones you want, then call `proceed'. */ | |
309 | ||
310 | void | |
311 | clear_proceed_status () | |
312 | { | |
313 | trap_expected = 0; | |
314 | step_range_start = 0; | |
315 | step_range_end = 0; | |
316 | step_frame_address = 0; | |
317 | step_over_calls = -1; | |
318 | step_resume_break_address = 0; | |
319 | stop_after_trap = 0; | |
320 | stop_soon_quietly = 0; | |
321 | proceed_to_finish = 0; | |
322 | breakpoint_proceeded = 1; /* We're about to proceed... */ | |
323 | ||
324 | /* Discard any remaining commands or status from previous stop. */ | |
325 | bpstat_clear (&stop_bpstat); | |
326 | } | |
327 | ||
328 | /* Basic routine for continuing the program in various fashions. | |
329 | ||
330 | ADDR is the address to resume at, or -1 for resume where stopped. | |
331 | SIGGNAL is the signal to give it, or 0 for none, | |
332 | or -1 for act according to how it stopped. | |
333 | STEP is nonzero if should trap after one instruction. | |
334 | -1 means return after that and print nothing. | |
335 | You should probably set various step_... variables | |
336 | before calling here, if you are stepping. | |
337 | ||
338 | You should call clear_proceed_status before calling proceed. */ | |
339 | ||
340 | void | |
341 | proceed (addr, siggnal, step) | |
342 | CORE_ADDR addr; | |
343 | int siggnal; | |
344 | int step; | |
345 | { | |
346 | int oneproc = 0; | |
347 | ||
348 | if (step > 0) | |
349 | step_start_function = find_pc_function (read_pc ()); | |
350 | if (step < 0) | |
351 | stop_after_trap = 1; | |
352 | ||
bdbd5f50 | 353 | if (addr == (CORE_ADDR)-1) |
bd5635a1 RP |
354 | { |
355 | /* If there is a breakpoint at the address we will resume at, | |
356 | step one instruction before inserting breakpoints | |
357 | so that we do not stop right away. */ | |
358 | ||
359 | if (!pc_changed && breakpoint_here_p (read_pc ())) | |
360 | oneproc = 1; | |
361 | } | |
362 | else | |
363 | { | |
364 | write_register (PC_REGNUM, addr); | |
365 | #ifdef NPC_REGNUM | |
366 | write_register (NPC_REGNUM, addr + 4); | |
367 | #ifdef NNPC_REGNUM | |
368 | write_register (NNPC_REGNUM, addr + 8); | |
369 | #endif | |
370 | #endif | |
371 | } | |
372 | ||
373 | if (trap_expected_after_continue) | |
374 | { | |
375 | /* If (step == 0), a trap will be automatically generated after | |
376 | the first instruction is executed. Force step one | |
377 | instruction to clear this condition. This should not occur | |
378 | if step is nonzero, but it is harmless in that case. */ | |
379 | oneproc = 1; | |
380 | trap_expected_after_continue = 0; | |
381 | } | |
382 | ||
383 | if (oneproc) | |
384 | /* We will get a trace trap after one instruction. | |
385 | Continue it automatically and insert breakpoints then. */ | |
386 | trap_expected = 1; | |
387 | else | |
388 | { | |
389 | int temp = insert_breakpoints (); | |
390 | if (temp) | |
391 | { | |
392 | print_sys_errmsg ("ptrace", temp); | |
393 | error ("Cannot insert breakpoints.\n\ | |
394 | The same program may be running in another process."); | |
395 | } | |
396 | breakpoints_inserted = 1; | |
397 | } | |
398 | ||
399 | /* Install inferior's terminal modes. */ | |
400 | target_terminal_inferior (); | |
401 | ||
402 | if (siggnal >= 0) | |
403 | stop_signal = siggnal; | |
404 | /* If this signal should not be seen by program, | |
405 | give it zero. Used for debugging signals. */ | |
406 | else if (stop_signal < NSIG && !signal_program[stop_signal]) | |
407 | stop_signal= 0; | |
408 | ||
bd5635a1 | 409 | /* Resume inferior. */ |
a71d17b1 | 410 | resume (oneproc || step || bpstat_should_step (), stop_signal); |
bd5635a1 RP |
411 | |
412 | /* Wait for it to stop (if not standalone) | |
413 | and in any case decode why it stopped, and act accordingly. */ | |
414 | ||
415 | wait_for_inferior (); | |
416 | normal_stop (); | |
417 | } | |
418 | ||
419 | #if 0 | |
420 | /* This might be useful (not sure), but isn't currently used. See also | |
421 | write_pc(). */ | |
422 | /* Writing the inferior pc as a register calls this function | |
423 | to inform infrun that the pc has been set in the debugger. */ | |
424 | ||
425 | void | |
426 | writing_pc (val) | |
427 | CORE_ADDR val; | |
428 | { | |
429 | stop_pc = val; | |
430 | pc_changed = 1; | |
431 | } | |
432 | #endif | |
433 | ||
434 | /* Record the pc and sp of the program the last time it stopped. | |
435 | These are just used internally by wait_for_inferior, but need | |
436 | to be preserved over calls to it and cleared when the inferior | |
437 | is started. */ | |
438 | static CORE_ADDR prev_pc; | |
439 | static CORE_ADDR prev_sp; | |
440 | static CORE_ADDR prev_func_start; | |
441 | static char *prev_func_name; | |
442 | ||
a71d17b1 | 443 | \f |
bd5635a1 RP |
444 | /* Start an inferior Unix child process and sets inferior_pid to its pid. |
445 | EXEC_FILE is the file to run. | |
446 | ALLARGS is a string containing the arguments to the program. | |
447 | ENV is the environment vector to pass. Errors reported with error(). */ | |
448 | ||
449 | #ifndef SHELL_FILE | |
450 | #define SHELL_FILE "/bin/sh" | |
451 | #endif | |
452 | ||
453 | void | |
454 | child_create_inferior (exec_file, allargs, env) | |
455 | char *exec_file; | |
456 | char *allargs; | |
457 | char **env; | |
458 | { | |
459 | int pid; | |
460 | char *shell_command; | |
461 | extern int sys_nerr; | |
462 | extern char *sys_errlist[]; | |
463 | char *shell_file; | |
464 | static char default_shell_file[] = SHELL_FILE; | |
465 | int len; | |
466 | int pending_execs; | |
467 | /* Set debug_fork then attach to the child while it sleeps, to debug. */ | |
468 | static int debug_fork = 0; | |
469 | /* This is set to the result of setpgrp, which if vforked, will be visible | |
470 | to you in the parent process. It's only used by humans for debugging. */ | |
471 | static int debug_setpgrp = 657473; | |
3b271cf4 | 472 | char **save_our_env; |
bd5635a1 RP |
473 | |
474 | /* The user might want tilde-expansion, and in general probably wants | |
475 | the program to behave the same way as if run from | |
476 | his/her favorite shell. So we let the shell run it for us. | |
477 | FIXME, this should probably search the local environment (as | |
478 | modified by the setenv command), not the env gdb inherited. */ | |
479 | shell_file = getenv ("SHELL"); | |
480 | if (shell_file == NULL) | |
481 | shell_file = default_shell_file; | |
482 | ||
483 | len = 5 + strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 10; | |
484 | /* If desired, concat something onto the front of ALLARGS. | |
485 | SHELL_COMMAND is the result. */ | |
486 | #ifdef SHELL_COMMAND_CONCAT | |
487 | shell_command = (char *) alloca (strlen (SHELL_COMMAND_CONCAT) + len); | |
488 | strcpy (shell_command, SHELL_COMMAND_CONCAT); | |
489 | #else | |
490 | shell_command = (char *) alloca (len); | |
491 | shell_command[0] = '\0'; | |
492 | #endif | |
493 | strcat (shell_command, "exec "); | |
494 | strcat (shell_command, exec_file); | |
495 | strcat (shell_command, " "); | |
496 | strcat (shell_command, allargs); | |
497 | ||
498 | /* exec is said to fail if the executable is open. */ | |
499 | close_exec_file (); | |
500 | ||
3b271cf4 JG |
501 | /* Retain a copy of our environment variables, since the child will |
502 | replace the value of environ and if we're vforked, we have to | |
503 | restore it. */ | |
504 | save_our_env = environ; | |
505 | ||
bdbd5f50 JG |
506 | /* Tell the terminal handling subsystem what tty we plan to run on; |
507 | it will just record the information for later. */ | |
508 | ||
509 | new_tty_prefork (inferior_io_terminal); | |
510 | ||
b3b39c0c SG |
511 | /* It is generally good practice to flush any possible pending stdio |
512 | output prior to doing a fork, to avoid the possibility of both the | |
513 | parent and child flushing the same data after the fork. */ | |
514 | ||
515 | fflush (stdout); | |
516 | fflush (stderr); | |
517 | ||
bd5635a1 RP |
518 | #if defined(USG) && !defined(HAVE_VFORK) |
519 | pid = fork (); | |
520 | #else | |
521 | if (debug_fork) | |
522 | pid = fork (); | |
523 | else | |
524 | pid = vfork (); | |
525 | #endif | |
526 | ||
527 | if (pid < 0) | |
528 | perror_with_name ("vfork"); | |
529 | ||
530 | if (pid == 0) | |
531 | { | |
532 | if (debug_fork) | |
533 | sleep (debug_fork); | |
534 | ||
535 | #ifdef TIOCGPGRP | |
536 | /* Run inferior in a separate process group. */ | |
150f5436 FF |
537 | #ifdef USG |
538 | debug_setpgrp = setpgrp (); | |
539 | #else | |
bd5635a1 | 540 | debug_setpgrp = setpgrp (getpid (), getpid ()); |
150f5436 | 541 | #endif |
680c9dfa | 542 | if (debug_setpgrp == -1) |
bd5635a1 RP |
543 | perror("setpgrp failed in child"); |
544 | #endif /* TIOCGPGRP */ | |
545 | ||
546 | #ifdef SET_STACK_LIMIT_HUGE | |
547 | /* Reset the stack limit back to what it was. */ | |
548 | { | |
549 | struct rlimit rlim; | |
550 | ||
551 | getrlimit (RLIMIT_STACK, &rlim); | |
552 | rlim.rlim_cur = original_stack_limit; | |
553 | setrlimit (RLIMIT_STACK, &rlim); | |
554 | } | |
555 | #endif /* SET_STACK_LIMIT_HUGE */ | |
556 | ||
bdbd5f50 JG |
557 | /* Ask the tty subsystem to switch to the one we specified earlier |
558 | (or to share the current terminal, if none was specified). */ | |
bd5635a1 | 559 | |
bdbd5f50 | 560 | new_tty (); |
bd5635a1 RP |
561 | |
562 | /* Changing the signal handlers for the inferior after | |
563 | a vfork can also change them for the superior, so we don't mess | |
564 | with signals here. See comments in | |
565 | initialize_signals for how we get the right signal handlers | |
566 | for the inferior. */ | |
567 | ||
63ac7ef3 FF |
568 | #ifdef USE_PROC_FS |
569 | proc_set_exec_trap (); /* Use SVR4 /proc interface */ | |
570 | #else | |
bd5635a1 | 571 | call_ptrace (0, 0, 0, 0); /* "Trace me, Dr. Memory!" */ |
63ac7ef3 | 572 | #endif |
3b271cf4 JG |
573 | |
574 | /* There is no execlpe call, so we have to set the environment | |
575 | for our child in the global variable. If we've vforked, this | |
576 | clobbers the parent, but environ is restored a few lines down | |
577 | in the parent. By the way, yes we do need to look down the | |
578 | path to find $SHELL. Rich Pixley says so, and I agree. */ | |
579 | environ = env; | |
580 | execlp (shell_file, shell_file, "-c", shell_command, (char *)0); | |
bd5635a1 RP |
581 | |
582 | fprintf (stderr, "Cannot exec %s: %s.\n", shell_file, | |
583 | errno < sys_nerr ? sys_errlist[errno] : "unknown error"); | |
584 | fflush (stderr); | |
585 | _exit (0177); | |
586 | } | |
587 | ||
3b271cf4 JG |
588 | /* Restore our environment in case a vforked child clob'd it. */ |
589 | environ = save_our_env; | |
590 | ||
bd5635a1 RP |
591 | /* Now that we have a child process, make it our target. */ |
592 | push_target (&child_ops); | |
593 | ||
594 | #ifdef CREATE_INFERIOR_HOOK | |
595 | CREATE_INFERIOR_HOOK (pid); | |
596 | #endif | |
597 | ||
598 | /* The process was started by the fork that created it, | |
599 | but it will have stopped one instruction after execing the shell. | |
600 | Here we must get it up to actual execution of the real program. */ | |
601 | ||
602 | inferior_pid = pid; /* Needed for wait_for_inferior stuff below */ | |
603 | ||
604 | clear_proceed_status (); | |
605 | ||
606 | #if defined (START_INFERIOR_HOOK) | |
607 | START_INFERIOR_HOOK (); | |
608 | #endif | |
609 | ||
610 | /* We will get a trace trap after one instruction. | |
611 | Continue it automatically. Eventually (after shell does an exec) | |
612 | it will get another trace trap. Then insert breakpoints and continue. */ | |
613 | ||
614 | #ifdef START_INFERIOR_TRAPS_EXPECTED | |
615 | pending_execs = START_INFERIOR_TRAPS_EXPECTED; | |
616 | #else | |
617 | pending_execs = 2; | |
618 | #endif | |
619 | ||
620 | init_wait_for_inferior (); | |
621 | ||
622 | /* Set up the "saved terminal modes" of the inferior | |
623 | based on what modes we are starting it with. */ | |
624 | target_terminal_init (); | |
625 | ||
626 | /* Install inferior's terminal modes. */ | |
627 | target_terminal_inferior (); | |
628 | ||
629 | while (1) | |
630 | { | |
631 | stop_soon_quietly = 1; /* Make wait_for_inferior be quiet */ | |
632 | wait_for_inferior (); | |
633 | if (stop_signal != SIGTRAP) | |
634 | { | |
635 | /* Let shell child handle its own signals in its own way */ | |
636 | /* FIXME, what if child has exit()ed? Must exit loop somehow */ | |
a71d17b1 | 637 | resume (0, stop_signal); |
bd5635a1 RP |
638 | } |
639 | else | |
640 | { | |
641 | /* We handle SIGTRAP, however; it means child did an exec. */ | |
642 | if (0 == --pending_execs) | |
643 | break; | |
a71d17b1 | 644 | resume (0, 0); /* Just make it go on */ |
bd5635a1 RP |
645 | } |
646 | } | |
647 | stop_soon_quietly = 0; | |
648 | ||
bdbd5f50 JG |
649 | /* We are now in the child process of interest, having exec'd the |
650 | correct program, and are poised at the first instruction of the | |
651 | new program. */ | |
652 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
653 | SOLIB_CREATE_INFERIOR_HOOK (); | |
654 | #endif | |
655 | ||
bd5635a1 RP |
656 | /* Should this perhaps just be a "proceed" call? FIXME */ |
657 | insert_step_breakpoint (); | |
658 | breakpoints_failed = insert_breakpoints (); | |
659 | if (!breakpoints_failed) | |
660 | { | |
661 | breakpoints_inserted = 1; | |
662 | target_terminal_inferior(); | |
663 | /* Start the child program going on its first instruction, single- | |
664 | stepping if we need to. */ | |
a71d17b1 | 665 | resume (bpstat_should_step (), 0); |
bd5635a1 RP |
666 | wait_for_inferior (); |
667 | normal_stop (); | |
668 | } | |
669 | } | |
670 | ||
671 | /* Start remote-debugging of a machine over a serial link. */ | |
672 | ||
673 | void | |
674 | start_remote () | |
675 | { | |
676 | init_wait_for_inferior (); | |
677 | clear_proceed_status (); | |
678 | stop_soon_quietly = 1; | |
679 | trap_expected = 0; | |
98885d76 JK |
680 | wait_for_inferior (); |
681 | normal_stop (); | |
bd5635a1 RP |
682 | } |
683 | ||
684 | /* Initialize static vars when a new inferior begins. */ | |
685 | ||
686 | void | |
687 | init_wait_for_inferior () | |
688 | { | |
689 | /* These are meaningless until the first time through wait_for_inferior. */ | |
690 | prev_pc = 0; | |
691 | prev_sp = 0; | |
692 | prev_func_start = 0; | |
693 | prev_func_name = NULL; | |
694 | ||
695 | trap_expected_after_continue = 0; | |
696 | breakpoints_inserted = 0; | |
697 | mark_breakpoints_out (); | |
698 | stop_signal = 0; /* Don't confuse first call to proceed(). */ | |
699 | } | |
700 | ||
701 | ||
702 | /* Attach to process PID, then initialize for debugging it | |
703 | and wait for the trace-trap that results from attaching. */ | |
704 | ||
705 | void | |
706 | child_attach (args, from_tty) | |
707 | char *args; | |
708 | int from_tty; | |
709 | { | |
710 | char *exec_file; | |
711 | int pid; | |
712 | ||
713 | dont_repeat(); | |
714 | ||
715 | if (!args) | |
716 | error_no_arg ("process-id to attach"); | |
717 | ||
718 | #ifndef ATTACH_DETACH | |
719 | error ("Can't attach to a process on this machine."); | |
720 | #else | |
721 | pid = atoi (args); | |
722 | ||
723 | if (target_has_execution) | |
724 | { | |
725 | if (query ("A program is being debugged already. Kill it? ")) | |
726 | target_kill ((char *)0, from_tty); | |
727 | else | |
728 | error ("Inferior not killed."); | |
729 | } | |
730 | ||
731 | exec_file = (char *) get_exec_file (1); | |
732 | ||
733 | if (from_tty) | |
734 | { | |
735 | printf ("Attaching program: %s pid %d\n", | |
736 | exec_file, pid); | |
737 | fflush (stdout); | |
738 | } | |
739 | ||
740 | attach (pid); | |
741 | inferior_pid = pid; | |
742 | push_target (&child_ops); | |
743 | ||
744 | mark_breakpoints_out (); | |
745 | target_terminal_init (); | |
746 | clear_proceed_status (); | |
747 | stop_soon_quietly = 1; | |
748 | /*proceed (-1, 0, -2);*/ | |
749 | target_terminal_inferior (); | |
750 | wait_for_inferior (); | |
bdbd5f50 | 751 | #ifdef SOLIB_ADD |
1515ff18 | 752 | SOLIB_ADD ((char *)0, from_tty, (struct target_ops *)0); |
bdbd5f50 | 753 | #endif |
bd5635a1 RP |
754 | normal_stop (); |
755 | #endif /* ATTACH_DETACH */ | |
756 | } | |
757 | \f | |
758 | /* Wait for control to return from inferior to debugger. | |
759 | If inferior gets a signal, we may decide to start it up again | |
760 | instead of returning. That is why there is a loop in this function. | |
761 | When this function actually returns it means the inferior | |
762 | should be left stopped and GDB should read more commands. */ | |
763 | ||
764 | void | |
765 | wait_for_inferior () | |
766 | { | |
767 | WAITTYPE w; | |
768 | int another_trap; | |
769 | int random_signal; | |
770 | CORE_ADDR stop_sp; | |
771 | CORE_ADDR stop_func_start; | |
772 | char *stop_func_name; | |
773 | CORE_ADDR prologue_pc; | |
774 | int stop_step_resume_break; | |
775 | struct symtab_and_line sal; | |
776 | int remove_breakpoints_on_following_step = 0; | |
d11c44f1 JG |
777 | #ifdef TDESC |
778 | extern dc_handle_t tdesc_handle; | |
779 | #endif | |
b3b39c0c | 780 | int current_line; |
bd5635a1 RP |
781 | |
782 | #if 0 | |
783 | /* This no longer works now that read_register is lazy; | |
784 | it might try to ptrace when the process is not stopped. */ | |
785 | prev_pc = read_pc (); | |
786 | (void) find_pc_partial_function (prev_pc, &prev_func_name, | |
787 | &prev_func_start); | |
788 | prev_func_start += FUNCTION_START_OFFSET; | |
789 | prev_sp = read_register (SP_REGNUM); | |
790 | #endif /* 0 */ | |
791 | ||
b3b39c0c SG |
792 | sal = find_pc_line(prev_pc, 0); |
793 | current_line = sal.line; | |
794 | ||
bd5635a1 RP |
795 | while (1) |
796 | { | |
797 | /* Clean up saved state that will become invalid. */ | |
798 | pc_changed = 0; | |
799 | flush_cached_frames (); | |
800 | registers_changed (); | |
801 | ||
802 | target_wait (&w); | |
803 | ||
804 | /* See if the process still exists; clean up if it doesn't. */ | |
805 | if (WIFEXITED (w)) | |
806 | { | |
807 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
d11c44f1 JG |
808 | #ifdef TDESC |
809 | safe_to_init_tdesc_context = 0; | |
810 | #endif | |
bd5635a1 RP |
811 | if (WEXITSTATUS (w)) |
812 | printf ("\nProgram exited with code 0%o.\n", | |
813 | (unsigned int)WEXITSTATUS (w)); | |
814 | else | |
815 | if (!batch_mode()) | |
816 | printf ("\nProgram exited normally.\n"); | |
817 | fflush (stdout); | |
818 | target_mourn_inferior (); | |
819 | #ifdef NO_SINGLE_STEP | |
820 | one_stepped = 0; | |
821 | #endif | |
822 | stop_print_frame = 0; | |
823 | break; | |
824 | } | |
825 | else if (!WIFSTOPPED (w)) | |
826 | { | |
827 | stop_print_frame = 0; | |
828 | stop_signal = WTERMSIG (w); | |
829 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
830 | target_kill ((char *)0, 0); /* kill mourns as well */ | |
d11c44f1 JG |
831 | #ifdef TDESC |
832 | safe_to_init_tdesc_context = 0; | |
833 | #endif | |
bd5635a1 RP |
834 | #ifdef PRINT_RANDOM_SIGNAL |
835 | printf ("\nProgram terminated: "); | |
836 | PRINT_RANDOM_SIGNAL (stop_signal); | |
837 | #else | |
838 | printf ("\nProgram terminated with signal %d, %s\n", | |
839 | stop_signal, | |
840 | stop_signal < NSIG | |
841 | ? sys_siglist[stop_signal] | |
842 | : "(undocumented)"); | |
843 | #endif | |
844 | printf ("The inferior process no longer exists.\n"); | |
845 | fflush (stdout); | |
846 | #ifdef NO_SINGLE_STEP | |
847 | one_stepped = 0; | |
848 | #endif | |
849 | break; | |
850 | } | |
851 | ||
852 | #ifdef NO_SINGLE_STEP | |
853 | if (one_stepped) | |
854 | single_step (0); /* This actually cleans up the ss */ | |
855 | #endif /* NO_SINGLE_STEP */ | |
856 | ||
857 | stop_pc = read_pc (); | |
d11c44f1 JG |
858 | #ifdef TDESC |
859 | if (safe_to_init_tdesc_context) | |
860 | { | |
861 | current_context = init_dcontext(); | |
862 | set_current_frame ( create_new_frame (get_frame_base (read_pc()),read_pc())); | |
863 | } | |
864 | else | |
865 | #endif /* TDESC */ | |
bd5635a1 RP |
866 | set_current_frame ( create_new_frame (read_register (FP_REGNUM), |
867 | read_pc ())); | |
868 | ||
869 | stop_frame_address = FRAME_FP (get_current_frame ()); | |
870 | stop_sp = read_register (SP_REGNUM); | |
871 | stop_func_start = 0; | |
872 | stop_func_name = 0; | |
873 | /* Don't care about return value; stop_func_start and stop_func_name | |
874 | will both be 0 if it doesn't work. */ | |
875 | (void) find_pc_partial_function (stop_pc, &stop_func_name, | |
876 | &stop_func_start); | |
877 | stop_func_start += FUNCTION_START_OFFSET; | |
878 | another_trap = 0; | |
879 | bpstat_clear (&stop_bpstat); | |
880 | stop_step = 0; | |
881 | stop_stack_dummy = 0; | |
882 | stop_print_frame = 1; | |
883 | stop_step_resume_break = 0; | |
884 | random_signal = 0; | |
885 | stopped_by_random_signal = 0; | |
886 | breakpoints_failed = 0; | |
887 | ||
888 | /* Look at the cause of the stop, and decide what to do. | |
889 | The alternatives are: | |
890 | 1) break; to really stop and return to the debugger, | |
891 | 2) drop through to start up again | |
892 | (set another_trap to 1 to single step once) | |
893 | 3) set random_signal to 1, and the decision between 1 and 2 | |
894 | will be made according to the signal handling tables. */ | |
895 | ||
896 | stop_signal = WSTOPSIG (w); | |
897 | ||
898 | /* First, distinguish signals caused by the debugger from signals | |
899 | that have to do with the program's own actions. | |
900 | Note that breakpoint insns may cause SIGTRAP or SIGILL | |
901 | or SIGEMT, depending on the operating system version. | |
902 | Here we detect when a SIGILL or SIGEMT is really a breakpoint | |
903 | and change it to SIGTRAP. */ | |
904 | ||
905 | if (stop_signal == SIGTRAP | |
906 | || (breakpoints_inserted && | |
907 | (stop_signal == SIGILL | |
908 | || stop_signal == SIGEMT)) | |
909 | || stop_soon_quietly) | |
910 | { | |
911 | if (stop_signal == SIGTRAP && stop_after_trap) | |
912 | { | |
913 | stop_print_frame = 0; | |
914 | break; | |
915 | } | |
916 | if (stop_soon_quietly) | |
917 | break; | |
918 | ||
919 | /* Don't even think about breakpoints | |
920 | if just proceeded over a breakpoint. | |
921 | ||
922 | However, if we are trying to proceed over a breakpoint | |
923 | and end up in sigtramp, then step_resume_break_address | |
924 | will be set and we should check whether we've hit the | |
925 | step breakpoint. */ | |
926 | if (stop_signal == SIGTRAP && trap_expected | |
927 | && step_resume_break_address == NULL) | |
928 | bpstat_clear (&stop_bpstat); | |
929 | else | |
930 | { | |
931 | /* See if there is a breakpoint at the current PC. */ | |
932 | #if DECR_PC_AFTER_BREAK | |
933 | /* Notice the case of stepping through a jump | |
934 | that leads just after a breakpoint. | |
935 | Don't confuse that with hitting the breakpoint. | |
936 | What we check for is that 1) stepping is going on | |
937 | and 2) the pc before the last insn does not match | |
938 | the address of the breakpoint before the current pc. */ | |
939 | if (!(prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
940 | && step_range_end && !step_resume_break_address)) | |
941 | #endif /* DECR_PC_AFTER_BREAK not zero */ | |
942 | { | |
943 | /* See if we stopped at the special breakpoint for | |
944 | stepping over a subroutine call. If both are zero, | |
945 | this wasn't the reason for the stop. */ | |
946 | if (stop_pc - DECR_PC_AFTER_BREAK | |
947 | == step_resume_break_address | |
948 | && step_resume_break_address) | |
949 | { | |
950 | stop_step_resume_break = 1; | |
951 | if (DECR_PC_AFTER_BREAK) | |
952 | { | |
953 | stop_pc -= DECR_PC_AFTER_BREAK; | |
954 | write_register (PC_REGNUM, stop_pc); | |
955 | pc_changed = 0; | |
956 | } | |
957 | } | |
958 | else | |
959 | { | |
960 | stop_bpstat = | |
961 | bpstat_stop_status (&stop_pc, stop_frame_address); | |
962 | /* Following in case break condition called a | |
963 | function. */ | |
964 | stop_print_frame = 1; | |
965 | } | |
966 | } | |
967 | } | |
968 | ||
969 | if (stop_signal == SIGTRAP) | |
970 | random_signal | |
971 | = !(bpstat_explains_signal (stop_bpstat) | |
972 | || trap_expected | |
973 | || stop_step_resume_break | |
974 | || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address) | |
975 | || (step_range_end && !step_resume_break_address)); | |
976 | else | |
977 | { | |
978 | random_signal | |
979 | = !(bpstat_explains_signal (stop_bpstat) | |
980 | || stop_step_resume_break | |
981 | /* End of a stack dummy. Some systems (e.g. Sony | |
982 | news) give another signal besides SIGTRAP, | |
983 | so check here as well as above. */ | |
984 | || (stop_sp INNER_THAN stop_pc | |
985 | && stop_pc INNER_THAN stop_frame_address) | |
986 | ); | |
987 | if (!random_signal) | |
988 | stop_signal = SIGTRAP; | |
989 | } | |
990 | } | |
991 | else | |
992 | random_signal = 1; | |
993 | ||
994 | /* For the program's own signals, act according to | |
995 | the signal handling tables. */ | |
996 | ||
997 | if (random_signal) | |
998 | { | |
999 | /* Signal not for debugging purposes. */ | |
1000 | int printed = 0; | |
1001 | ||
1002 | stopped_by_random_signal = 1; | |
1003 | ||
1004 | if (stop_signal >= NSIG | |
1005 | || signal_print[stop_signal]) | |
1006 | { | |
1007 | printed = 1; | |
1008 | target_terminal_ours_for_output (); | |
1009 | #ifdef PRINT_RANDOM_SIGNAL | |
1010 | PRINT_RANDOM_SIGNAL (stop_signal); | |
1011 | #else | |
1012 | printf ("\nProgram received signal %d, %s\n", | |
1013 | stop_signal, | |
1014 | stop_signal < NSIG | |
1015 | ? sys_siglist[stop_signal] | |
1016 | : "(undocumented)"); | |
1017 | #endif /* PRINT_RANDOM_SIGNAL */ | |
1018 | fflush (stdout); | |
1019 | } | |
1020 | if (stop_signal >= NSIG | |
1021 | || signal_stop[stop_signal]) | |
1022 | break; | |
1023 | /* If not going to stop, give terminal back | |
1024 | if we took it away. */ | |
1025 | else if (printed) | |
1026 | target_terminal_inferior (); | |
b7f81b57 JG |
1027 | |
1028 | /* Note that virtually all the code below does `if !random_signal'. | |
1029 | Perhaps this code should end with a goto or continue. At least | |
1030 | one (now fixed) bug was caused by this -- a !random_signal was | |
1031 | missing in one of the tests below. */ | |
bd5635a1 RP |
1032 | } |
1033 | ||
1034 | /* Handle cases caused by hitting a breakpoint. */ | |
1035 | ||
1036 | if (!random_signal | |
1037 | && (bpstat_explains_signal (stop_bpstat) || stop_step_resume_break)) | |
1038 | { | |
1039 | /* Does a breakpoint want us to stop? */ | |
1040 | if (bpstat_stop (stop_bpstat)) | |
1041 | { | |
1042 | stop_print_frame = bpstat_should_print (stop_bpstat); | |
1043 | break; | |
1044 | } | |
1045 | /* But if we have hit the step-resumption breakpoint, | |
1046 | remove it. It has done its job getting us here. | |
1047 | The sp test is to make sure that we don't get hung | |
1048 | up in recursive calls in functions without frame | |
1049 | pointers. If the stack pointer isn't outside of | |
1050 | where the breakpoint was set (within a routine to be | |
1051 | stepped over), we're in the middle of a recursive | |
1052 | call. Not true for reg window machines (sparc) | |
1053 | because the must change frames to call things and | |
1054 | the stack pointer doesn't have to change if it | |
1055 | the bp was set in a routine without a frame (pc can | |
1056 | be stored in some other window). | |
1057 | ||
1058 | The removal of the sp test is to allow calls to | |
1059 | alloca. Nasty things were happening. Oh, well, | |
1060 | gdb can only handle one level deep of lack of | |
1061 | frame pointer. */ | |
1062 | if (stop_step_resume_break | |
1063 | && (step_frame_address == 0 | |
1064 | || (stop_frame_address == step_frame_address))) | |
1065 | { | |
1066 | remove_step_breakpoint (); | |
1067 | step_resume_break_address = 0; | |
1068 | ||
1069 | /* If were waiting for a trap, hitting the step_resume_break | |
1070 | doesn't count as getting it. */ | |
1071 | if (trap_expected) | |
1072 | another_trap = 1; | |
1073 | } | |
1074 | /* Otherwise, must remove breakpoints and single-step | |
1075 | to get us past the one we hit. */ | |
1076 | else | |
1077 | { | |
1078 | remove_breakpoints (); | |
1079 | remove_step_breakpoint (); | |
1080 | breakpoints_inserted = 0; | |
1081 | another_trap = 1; | |
1082 | } | |
1083 | ||
1084 | /* We come here if we hit a breakpoint but should not | |
1085 | stop for it. Possibly we also were stepping | |
1086 | and should stop for that. So fall through and | |
1087 | test for stepping. But, if not stepping, | |
1088 | do not stop. */ | |
1089 | } | |
1090 | ||
1091 | /* If this is the breakpoint at the end of a stack dummy, | |
1092 | just stop silently. */ | |
b7f81b57 JG |
1093 | if (!random_signal |
1094 | && PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)) | |
bd5635a1 RP |
1095 | { |
1096 | stop_print_frame = 0; | |
1097 | stop_stack_dummy = 1; | |
1098 | #ifdef HP_OS_BUG | |
1099 | trap_expected_after_continue = 1; | |
1100 | #endif | |
1101 | break; | |
1102 | } | |
1103 | ||
1104 | if (step_resume_break_address) | |
1105 | /* Having a step-resume breakpoint overrides anything | |
1106 | else having to do with stepping commands until | |
1107 | that breakpoint is reached. */ | |
1108 | ; | |
1109 | /* If stepping through a line, keep going if still within it. */ | |
1110 | else if (!random_signal | |
1111 | && step_range_end | |
1112 | && stop_pc >= step_range_start | |
1113 | && stop_pc < step_range_end | |
1114 | /* The step range might include the start of the | |
1115 | function, so if we are at the start of the | |
1116 | step range and either the stack or frame pointers | |
1117 | just changed, we've stepped outside */ | |
1118 | && !(stop_pc == step_range_start | |
1119 | && stop_frame_address | |
1120 | && (stop_sp INNER_THAN prev_sp | |
1121 | || stop_frame_address != step_frame_address))) | |
1122 | { | |
1123 | #if 0 | |
1124 | /* When "next"ing through a function, | |
1125 | This causes an extra stop at the end. | |
1126 | Is there any reason for this? | |
1127 | It's confusing to the user. */ | |
1128 | /* Don't step through the return from a function | |
1129 | unless that is the first instruction stepped through. */ | |
1130 | if (ABOUT_TO_RETURN (stop_pc)) | |
1131 | { | |
1132 | stop_step = 1; | |
1133 | break; | |
1134 | } | |
1135 | #endif | |
1136 | } | |
1137 | ||
1138 | /* We stepped out of the stepping range. See if that was due | |
1139 | to a subroutine call that we should proceed to the end of. */ | |
1140 | else if (!random_signal && step_range_end) | |
1141 | { | |
1142 | if (stop_func_start) | |
1143 | { | |
1144 | prologue_pc = stop_func_start; | |
1145 | SKIP_PROLOGUE (prologue_pc); | |
1146 | } | |
1147 | ||
1148 | /* Did we just take a signal? */ | |
1149 | if (IN_SIGTRAMP (stop_pc, stop_func_name) | |
1150 | && !IN_SIGTRAMP (prev_pc, prev_func_name)) | |
1151 | { | |
1152 | /* This code is needed at least in the following case: | |
1153 | The user types "next" and then a signal arrives (before | |
1154 | the "next" is done). */ | |
1155 | /* We've just taken a signal; go until we are back to | |
1156 | the point where we took it and one more. */ | |
1157 | step_resume_break_address = prev_pc; | |
1158 | step_resume_break_duplicate = | |
1159 | breakpoint_here_p (step_resume_break_address); | |
1160 | if (breakpoints_inserted) | |
1161 | insert_step_breakpoint (); | |
1162 | /* Make sure that the stepping range gets us past | |
1163 | that instruction. */ | |
1164 | if (step_range_end == 1) | |
1165 | step_range_end = (step_range_start = prev_pc) + 1; | |
1166 | remove_breakpoints_on_following_step = 1; | |
1167 | } | |
1168 | ||
1169 | /* ==> See comments at top of file on this algorithm. <==*/ | |
1170 | ||
1171 | else if (stop_pc == stop_func_start | |
1172 | && (stop_func_start != prev_func_start | |
1173 | || prologue_pc != stop_func_start | |
1174 | || stop_sp != prev_sp)) | |
1175 | { | |
1176 | /* It's a subroutine call */ | |
1177 | if (step_over_calls > 0 | |
1178 | || (step_over_calls && find_pc_function (stop_pc) == 0)) | |
1179 | { | |
1180 | /* A subroutine call has happened. */ | |
1181 | /* Set a special breakpoint after the return */ | |
1182 | step_resume_break_address = | |
1183 | ADDR_BITS_REMOVE | |
1184 | (SAVED_PC_AFTER_CALL (get_current_frame ())); | |
1185 | step_resume_break_duplicate | |
1186 | = breakpoint_here_p (step_resume_break_address); | |
1187 | if (breakpoints_inserted) | |
1188 | insert_step_breakpoint (); | |
1189 | } | |
1190 | /* Subroutine call with source code we should not step over. | |
1191 | Do step to the first line of code in it. */ | |
1192 | else if (step_over_calls) | |
1193 | { | |
1194 | SKIP_PROLOGUE (stop_func_start); | |
1195 | sal = find_pc_line (stop_func_start, 0); | |
1196 | /* Use the step_resume_break to step until | |
1197 | the end of the prologue, even if that involves jumps | |
1198 | (as it seems to on the vax under 4.2). */ | |
1199 | /* If the prologue ends in the middle of a source line, | |
1200 | continue to the end of that source line. | |
1201 | Otherwise, just go to end of prologue. */ | |
1202 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
1203 | /* no, don't either. It skips any code that's | |
1204 | legitimately on the first line. */ | |
1205 | #else | |
1206 | if (sal.end && sal.pc != stop_func_start) | |
1207 | stop_func_start = sal.end; | |
1208 | #endif | |
1209 | ||
1210 | if (stop_func_start == stop_pc) | |
1211 | { | |
1212 | /* We are already there: stop now. */ | |
1213 | stop_step = 1; | |
1214 | break; | |
1215 | } | |
1216 | else | |
1217 | /* Put the step-breakpoint there and go until there. */ | |
1218 | { | |
1219 | step_resume_break_address = stop_func_start; | |
1220 | ||
1221 | step_resume_break_duplicate | |
1222 | = breakpoint_here_p (step_resume_break_address); | |
1223 | if (breakpoints_inserted) | |
1224 | insert_step_breakpoint (); | |
1225 | /* Do not specify what the fp should be when we stop | |
1226 | since on some machines the prologue | |
1227 | is where the new fp value is established. */ | |
1228 | step_frame_address = 0; | |
1229 | /* And make sure stepping stops right away then. */ | |
1230 | step_range_end = step_range_start; | |
1231 | } | |
1232 | } | |
1233 | else | |
1234 | { | |
1235 | /* We get here only if step_over_calls is 0 and we | |
1236 | just stepped into a subroutine. I presume | |
1237 | that step_over_calls is only 0 when we're | |
1238 | supposed to be stepping at the assembly | |
1239 | language level.*/ | |
1240 | stop_step = 1; | |
1241 | break; | |
1242 | } | |
1243 | } | |
b3b39c0c | 1244 | /* No subroutine call; stop now. */ |
bd5635a1 RP |
1245 | else |
1246 | { | |
b3b39c0c SG |
1247 | /* We've wandered out of the step range (but we haven't done a |
1248 | subroutine call or return (that's handled elsewhere)). We | |
1249 | don't really want to stop until we encounter the start of a | |
1250 | new statement. If so, we stop. Otherwise, we reset | |
1251 | step_range_start and step_range_end, and just continue. */ | |
1252 | sal = find_pc_line(stop_pc, 0); | |
1253 | ||
d7d1098d SG |
1254 | if (step_range_end == 1 || /* Don't do this for stepi/nexti */ |
1255 | sal.line == 0 || /* Stop now if no line # info */ | |
2e393ce4 SG |
1256 | (current_line != sal.line |
1257 | && stop_pc == sal.pc)) { | |
b3b39c0c SG |
1258 | stop_step = 1; |
1259 | break; | |
1260 | } else { | |
1261 | /* This is probably not necessary, but it probably makes | |
1262 | stepping more efficient, as we avoid calling find_pc_line() | |
1263 | for each instruction we step over. */ | |
1264 | step_range_start = sal.pc; | |
1265 | step_range_end = sal.end; | |
1266 | } | |
bd5635a1 RP |
1267 | } |
1268 | } | |
1269 | ||
1270 | else if (trap_expected | |
1271 | && IN_SIGTRAMP (stop_pc, stop_func_name) | |
1272 | && !IN_SIGTRAMP (prev_pc, prev_func_name)) | |
1273 | { | |
1274 | /* What has happened here is that we have just stepped the inferior | |
1275 | with a signal (because it is a signal which shouldn't make | |
1276 | us stop), thus stepping into sigtramp. | |
1277 | ||
1278 | So we need to set a step_resume_break_address breakpoint | |
1279 | and continue until we hit it, and then step. */ | |
1280 | step_resume_break_address = prev_pc; | |
1281 | /* Always 1, I think, but it's probably easier to have | |
1282 | the step_resume_break as usual rather than trying to | |
1283 | re-use the breakpoint which is already there. */ | |
1284 | step_resume_break_duplicate = | |
1285 | breakpoint_here_p (step_resume_break_address); | |
1286 | if (breakpoints_inserted) | |
1287 | insert_step_breakpoint (); | |
1288 | remove_breakpoints_on_following_step = 1; | |
1289 | another_trap = 1; | |
1290 | } | |
1291 | ||
1292 | /* Save the pc before execution, to compare with pc after stop. */ | |
1293 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ | |
1294 | prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER | |
1295 | BREAK is defined, the | |
1296 | original pc would not have | |
1297 | been at the start of a | |
1298 | function. */ | |
1299 | prev_func_name = stop_func_name; | |
1300 | prev_sp = stop_sp; | |
1301 | ||
1302 | /* If we did not do break;, it means we should keep | |
1303 | running the inferior and not return to debugger. */ | |
1304 | ||
1305 | if (trap_expected && stop_signal != SIGTRAP) | |
1306 | { | |
1307 | /* We took a signal (which we are supposed to pass through to | |
1308 | the inferior, else we'd have done a break above) and we | |
1309 | haven't yet gotten our trap. Simply continue. */ | |
a71d17b1 | 1310 | resume ((step_range_end && !step_resume_break_address) |
bd5635a1 RP |
1311 | || (trap_expected && !step_resume_break_address) |
1312 | || bpstat_should_step (), | |
1313 | stop_signal); | |
1314 | } | |
1315 | else | |
1316 | { | |
1317 | /* Either the trap was not expected, but we are continuing | |
1318 | anyway (the user asked that this signal be passed to the | |
1319 | child) | |
1320 | -- or -- | |
1321 | The signal was SIGTRAP, e.g. it was our signal, but we | |
1322 | decided we should resume from it. | |
1323 | ||
1324 | We're going to run this baby now! | |
1325 | ||
1326 | Insert breakpoints now, unless we are trying | |
1327 | to one-proceed past a breakpoint. */ | |
1328 | /* If we've just finished a special step resume and we don't | |
1329 | want to hit a breakpoint, pull em out. */ | |
d11c44f1 JG |
1330 | #ifdef TDESC |
1331 | if (!tdesc_handle) | |
1332 | { | |
1333 | init_tdesc(); | |
1334 | safe_to_init_tdesc_context = 1; | |
1335 | } | |
1336 | #endif | |
1337 | ||
bd5635a1 RP |
1338 | if (!step_resume_break_address && |
1339 | remove_breakpoints_on_following_step) | |
1340 | { | |
1341 | remove_breakpoints_on_following_step = 0; | |
1342 | remove_breakpoints (); | |
1343 | breakpoints_inserted = 0; | |
1344 | } | |
1345 | else if (!breakpoints_inserted && | |
1346 | (step_resume_break_address != NULL || !another_trap)) | |
1347 | { | |
1348 | insert_step_breakpoint (); | |
1349 | breakpoints_failed = insert_breakpoints (); | |
1350 | if (breakpoints_failed) | |
1351 | break; | |
1352 | breakpoints_inserted = 1; | |
1353 | } | |
1354 | ||
1355 | trap_expected = another_trap; | |
1356 | ||
1357 | if (stop_signal == SIGTRAP) | |
1358 | stop_signal = 0; | |
1359 | ||
1360 | #ifdef SHIFT_INST_REGS | |
1361 | /* I'm not sure when this following segment applies. I do know, now, | |
1362 | that we shouldn't rewrite the regs when we were stopped by a | |
1363 | random signal from the inferior process. */ | |
1364 | ||
d11c44f1 JG |
1365 | if (!bpstat_explains_signal (stop_bpstat) |
1366 | && (stop_signal != SIGCLD) | |
bd5635a1 RP |
1367 | && !stopped_by_random_signal) |
1368 | { | |
1369 | CORE_ADDR pc_contents = read_register (PC_REGNUM); | |
1370 | CORE_ADDR npc_contents = read_register (NPC_REGNUM); | |
1371 | if (pc_contents != npc_contents) | |
1372 | { | |
1373 | write_register (NNPC_REGNUM, npc_contents); | |
1374 | write_register (NPC_REGNUM, pc_contents); | |
1375 | } | |
1376 | } | |
1377 | #endif /* SHIFT_INST_REGS */ | |
1378 | ||
a71d17b1 | 1379 | resume ((step_range_end && !step_resume_break_address) |
bd5635a1 RP |
1380 | || (trap_expected && !step_resume_break_address) |
1381 | || bpstat_should_step (), | |
1382 | stop_signal); | |
1383 | } | |
1384 | } | |
1385 | if (target_has_execution) | |
1386 | { | |
1387 | /* Assuming the inferior still exists, set these up for next | |
1388 | time, just like we did above if we didn't break out of the | |
1389 | loop. */ | |
1390 | prev_pc = read_pc (); | |
1391 | prev_func_start = stop_func_start; | |
1392 | prev_func_name = stop_func_name; | |
1393 | prev_sp = stop_sp; | |
1394 | } | |
1395 | } | |
1396 | \f | |
1397 | /* Here to return control to GDB when the inferior stops for real. | |
1398 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
1399 | ||
1400 | STOP_PRINT_FRAME nonzero means print the executing frame | |
1401 | (pc, function, args, file, line number and line text). | |
1402 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
1403 | attempting to insert breakpoints. */ | |
1404 | ||
1405 | void | |
1406 | normal_stop () | |
1407 | { | |
1408 | /* Make sure that the current_frame's pc is correct. This | |
1409 | is a correction for setting up the frame info before doing | |
1410 | DECR_PC_AFTER_BREAK */ | |
1411 | if (target_has_execution) | |
1412 | (get_current_frame ())->pc = read_pc (); | |
1413 | ||
1414 | if (breakpoints_failed) | |
1415 | { | |
1416 | target_terminal_ours_for_output (); | |
1417 | print_sys_errmsg ("ptrace", breakpoints_failed); | |
1418 | printf ("Stopped; cannot insert breakpoints.\n\ | |
1419 | The same program may be running in another process.\n"); | |
1420 | } | |
1421 | ||
1422 | if (target_has_execution) | |
1423 | remove_step_breakpoint (); | |
1424 | ||
1425 | if (target_has_execution && breakpoints_inserted) | |
1426 | if (remove_breakpoints ()) | |
1427 | { | |
1428 | target_terminal_ours_for_output (); | |
1429 | printf ("Cannot remove breakpoints because program is no longer writable.\n\ | |
1430 | It might be running in another process.\n\ | |
1431 | Further execution is probably impossible.\n"); | |
1432 | } | |
1433 | ||
1434 | breakpoints_inserted = 0; | |
1435 | ||
1436 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
1437 | Delete any breakpoint that is to be deleted at the next stop. */ | |
1438 | ||
1439 | breakpoint_auto_delete (stop_bpstat); | |
1440 | ||
1441 | /* If an auto-display called a function and that got a signal, | |
1442 | delete that auto-display to avoid an infinite recursion. */ | |
1443 | ||
1444 | if (stopped_by_random_signal) | |
1445 | disable_current_display (); | |
1446 | ||
1447 | if (step_multi && stop_step) | |
1448 | return; | |
1449 | ||
1450 | target_terminal_ours (); | |
1451 | ||
1452 | if (!target_has_stack) | |
1453 | return; | |
1454 | ||
1455 | /* Select innermost stack frame except on return from a stack dummy routine, | |
1515ff18 JG |
1456 | or if the program has exited. Print it without a level number if |
1457 | we have changed functions or hit a breakpoint. Print source line | |
1458 | if we have one. */ | |
bd5635a1 RP |
1459 | if (!stop_stack_dummy) |
1460 | { | |
1461 | select_frame (get_current_frame (), 0); | |
1462 | ||
1463 | if (stop_print_frame) | |
1464 | { | |
1515ff18 JG |
1465 | int source_only; |
1466 | ||
1467 | source_only = bpstat_print (stop_bpstat); | |
1468 | source_only = source_only || | |
1469 | ( stop_step | |
bd5635a1 | 1470 | && step_frame_address == stop_frame_address |
1515ff18 JG |
1471 | && step_start_function == find_pc_function (stop_pc)); |
1472 | ||
1473 | print_stack_frame (selected_frame, -1, source_only? -1: 1); | |
bd5635a1 RP |
1474 | |
1475 | /* Display the auto-display expressions. */ | |
1476 | do_displays (); | |
1477 | } | |
1478 | } | |
1479 | ||
1480 | /* Save the function value return registers, if we care. | |
1481 | We might be about to restore their previous contents. */ | |
1482 | if (proceed_to_finish) | |
1483 | read_register_bytes (0, stop_registers, REGISTER_BYTES); | |
1484 | ||
1485 | if (stop_stack_dummy) | |
1486 | { | |
1487 | /* Pop the empty frame that contains the stack dummy. | |
1488 | POP_FRAME ends with a setting of the current frame, so we | |
1489 | can use that next. */ | |
1490 | POP_FRAME; | |
1491 | select_frame (get_current_frame (), 0); | |
1492 | } | |
1493 | } | |
1494 | \f | |
1495 | static void | |
1496 | insert_step_breakpoint () | |
1497 | { | |
1498 | if (step_resume_break_address && !step_resume_break_duplicate) | |
1499 | target_insert_breakpoint (step_resume_break_address, | |
1500 | step_resume_break_shadow); | |
1501 | } | |
1502 | ||
1503 | static void | |
1504 | remove_step_breakpoint () | |
1505 | { | |
1506 | if (step_resume_break_address && !step_resume_break_duplicate) | |
1507 | target_remove_breakpoint (step_resume_break_address, | |
1508 | step_resume_break_shadow); | |
1509 | } | |
1510 | \f | |
1511 | static void | |
1512 | sig_print_header () | |
1513 | { | |
1514 | printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n"); | |
1515 | } | |
1516 | ||
1517 | static void | |
1518 | sig_print_info (number) | |
1519 | int number; | |
1520 | { | |
1521 | char *abbrev = sig_abbrev(number); | |
1522 | if (abbrev == NULL) | |
1523 | printf_filtered ("%d\t\t", number); | |
1524 | else | |
1525 | printf_filtered ("SIG%s (%d)\t", abbrev, number); | |
1526 | printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No"); | |
1527 | printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No"); | |
1528 | printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No"); | |
1529 | printf_filtered ("%s\n", sys_siglist[number]); | |
1530 | } | |
1531 | ||
1532 | /* Specify how various signals in the inferior should be handled. */ | |
1533 | ||
1534 | static void | |
1535 | handle_command (args, from_tty) | |
1536 | char *args; | |
1537 | int from_tty; | |
1538 | { | |
1539 | register char *p = args; | |
1540 | int signum = 0; | |
1541 | register int digits, wordlen; | |
1542 | char *nextarg; | |
1543 | ||
1544 | if (!args) | |
1545 | error_no_arg ("signal to handle"); | |
1546 | ||
1547 | while (*p) | |
1548 | { | |
1549 | /* Find the end of the next word in the args. */ | |
1550 | for (wordlen = 0; | |
1551 | p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t'; | |
1552 | wordlen++); | |
1553 | /* Set nextarg to the start of the word after the one we just | |
1554 | found, and null-terminate this one. */ | |
1555 | if (p[wordlen] == '\0') | |
1556 | nextarg = p + wordlen; | |
1557 | else | |
1558 | { | |
1559 | p[wordlen] = '\0'; | |
1560 | nextarg = p + wordlen + 1; | |
1561 | } | |
1562 | ||
1563 | ||
1564 | for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++); | |
1565 | ||
1566 | if (signum == 0) | |
1567 | { | |
1568 | /* It is the first argument--must be the signal to operate on. */ | |
1569 | if (digits == wordlen) | |
1570 | { | |
1571 | /* Numeric. */ | |
1572 | signum = atoi (p); | |
1573 | if (signum <= 0 || signum >= NSIG) | |
1574 | { | |
1575 | p[wordlen] = '\0'; | |
1576 | error ("Invalid signal %s given as argument to \"handle\".", p); | |
1577 | } | |
1578 | } | |
1579 | else | |
1580 | { | |
1581 | /* Symbolic. */ | |
1582 | signum = sig_number (p); | |
1583 | if (signum == -1) | |
1584 | error ("No such signal \"%s\"", p); | |
1585 | } | |
1586 | ||
1587 | if (signum == SIGTRAP || signum == SIGINT) | |
1588 | { | |
1589 | if (!query ("SIG%s is used by the debugger.\nAre you sure you want to change it? ", sig_abbrev (signum))) | |
1590 | error ("Not confirmed."); | |
1591 | } | |
1592 | } | |
1593 | /* Else, if already got a signal number, look for flag words | |
1594 | saying what to do for it. */ | |
1595 | else if (!strncmp (p, "stop", wordlen)) | |
1596 | { | |
1597 | signal_stop[signum] = 1; | |
1598 | signal_print[signum] = 1; | |
1599 | } | |
1600 | else if (wordlen >= 2 && !strncmp (p, "print", wordlen)) | |
1601 | signal_print[signum] = 1; | |
1602 | else if (wordlen >= 2 && !strncmp (p, "pass", wordlen)) | |
1603 | signal_program[signum] = 1; | |
1604 | else if (!strncmp (p, "ignore", wordlen)) | |
1605 | signal_program[signum] = 0; | |
1606 | else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen)) | |
1607 | signal_stop[signum] = 0; | |
1608 | else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen)) | |
1609 | { | |
1610 | signal_print[signum] = 0; | |
1611 | signal_stop[signum] = 0; | |
1612 | } | |
1613 | else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen)) | |
1614 | signal_program[signum] = 0; | |
1615 | else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen)) | |
1616 | signal_program[signum] = 1; | |
1617 | /* Not a number and not a recognized flag word => complain. */ | |
1618 | else | |
1619 | { | |
1620 | error ("Unrecognized flag word: \"%s\".", p); | |
1621 | } | |
1622 | ||
1623 | /* Find start of next word. */ | |
1624 | p = nextarg; | |
1625 | while (*p == ' ' || *p == '\t') p++; | |
1626 | } | |
1627 | ||
1628 | if (from_tty) | |
1629 | { | |
1630 | /* Show the results. */ | |
1631 | sig_print_header (); | |
1632 | sig_print_info (signum); | |
1633 | } | |
1634 | } | |
1635 | ||
1636 | /* Print current contents of the tables set by the handle command. */ | |
1637 | ||
1638 | static void | |
1639 | signals_info (signum_exp) | |
1640 | char *signum_exp; | |
1641 | { | |
1642 | register int i; | |
1643 | sig_print_header (); | |
1644 | ||
1645 | if (signum_exp) | |
1646 | { | |
1647 | /* First see if this is a symbol name. */ | |
1648 | i = sig_number (signum_exp); | |
1649 | if (i == -1) | |
1650 | { | |
1651 | /* Nope, maybe it's an address which evaluates to a signal | |
1652 | number. */ | |
1653 | i = parse_and_eval_address (signum_exp); | |
1654 | if (i >= NSIG || i < 0) | |
1655 | error ("Signal number out of bounds."); | |
1656 | } | |
1657 | sig_print_info (i); | |
1658 | return; | |
1659 | } | |
1660 | ||
1661 | printf_filtered ("\n"); | |
1662 | for (i = 0; i < NSIG; i++) | |
1663 | { | |
1664 | QUIT; | |
1665 | ||
1666 | sig_print_info (i); | |
1667 | } | |
1668 | ||
1669 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); | |
1670 | } | |
1671 | \f | |
1672 | /* Save all of the information associated with the inferior<==>gdb | |
1673 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
1674 | (defined in inferior.h). */ | |
1675 | ||
1676 | void | |
1677 | save_inferior_status (inf_status, restore_stack_info) | |
1678 | struct inferior_status *inf_status; | |
1679 | int restore_stack_info; | |
1680 | { | |
1681 | inf_status->pc_changed = pc_changed; | |
1682 | inf_status->stop_signal = stop_signal; | |
1683 | inf_status->stop_pc = stop_pc; | |
1684 | inf_status->stop_frame_address = stop_frame_address; | |
1685 | inf_status->stop_step = stop_step; | |
1686 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
1687 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
1688 | inf_status->trap_expected = trap_expected; | |
1689 | inf_status->step_range_start = step_range_start; | |
1690 | inf_status->step_range_end = step_range_end; | |
1691 | inf_status->step_frame_address = step_frame_address; | |
1692 | inf_status->step_over_calls = step_over_calls; | |
1693 | inf_status->step_resume_break_address = step_resume_break_address; | |
1694 | inf_status->stop_after_trap = stop_after_trap; | |
1695 | inf_status->stop_soon_quietly = stop_soon_quietly; | |
1696 | /* Save original bpstat chain here; replace it with copy of chain. | |
1697 | If caller's caller is walking the chain, they'll be happier if we | |
1698 | hand them back the original chain when restore_i_s is called. */ | |
1699 | inf_status->stop_bpstat = stop_bpstat; | |
1700 | stop_bpstat = bpstat_copy (stop_bpstat); | |
1701 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
1702 | inf_status->restore_stack_info = restore_stack_info; | |
1703 | inf_status->proceed_to_finish = proceed_to_finish; | |
1704 | ||
1705 | bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); | |
1706 | ||
1707 | record_selected_frame (&(inf_status->selected_frame_address), | |
1708 | &(inf_status->selected_level)); | |
1709 | return; | |
1710 | } | |
1711 | ||
1712 | void | |
1713 | restore_inferior_status (inf_status) | |
1714 | struct inferior_status *inf_status; | |
1715 | { | |
1716 | FRAME fid; | |
1717 | int level = inf_status->selected_level; | |
1718 | ||
1719 | pc_changed = inf_status->pc_changed; | |
1720 | stop_signal = inf_status->stop_signal; | |
1721 | stop_pc = inf_status->stop_pc; | |
1722 | stop_frame_address = inf_status->stop_frame_address; | |
1723 | stop_step = inf_status->stop_step; | |
1724 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
1725 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
1726 | trap_expected = inf_status->trap_expected; | |
1727 | step_range_start = inf_status->step_range_start; | |
1728 | step_range_end = inf_status->step_range_end; | |
1729 | step_frame_address = inf_status->step_frame_address; | |
1730 | step_over_calls = inf_status->step_over_calls; | |
1731 | step_resume_break_address = inf_status->step_resume_break_address; | |
1732 | stop_after_trap = inf_status->stop_after_trap; | |
1733 | stop_soon_quietly = inf_status->stop_soon_quietly; | |
1734 | bpstat_clear (&stop_bpstat); | |
1735 | stop_bpstat = inf_status->stop_bpstat; | |
1736 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
1737 | proceed_to_finish = inf_status->proceed_to_finish; | |
1738 | ||
1739 | bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); | |
1740 | ||
1741 | /* The inferior can be gone if the user types "print exit(0)" | |
1742 | (and perhaps other times). */ | |
1743 | if (target_has_stack && inf_status->restore_stack_info) | |
1744 | { | |
1745 | fid = find_relative_frame (get_current_frame (), | |
1746 | &level); | |
1747 | ||
777bef06 JK |
1748 | /* If inf_status->selected_frame_address is NULL, there was no |
1749 | previously selected frame. */ | |
bd5635a1 RP |
1750 | if (fid == 0 || |
1751 | FRAME_FP (fid) != inf_status->selected_frame_address || | |
1752 | level != 0) | |
1753 | { | |
1754 | #if 0 | |
1755 | /* I'm not sure this error message is a good idea. I have | |
1756 | only seen it occur after "Can't continue previously | |
1757 | requested operation" (we get called from do_cleanups), in | |
1758 | which case it just adds insult to injury (one confusing | |
1759 | error message after another. Besides which, does the | |
1760 | user really care if we can't restore the previously | |
1761 | selected frame? */ | |
1762 | fprintf (stderr, "Unable to restore previously selected frame.\n"); | |
1763 | #endif | |
1764 | select_frame (get_current_frame (), 0); | |
1765 | return; | |
1766 | } | |
1767 | ||
1768 | select_frame (fid, inf_status->selected_level); | |
1769 | } | |
1770 | } | |
1771 | ||
1772 | \f | |
1773 | void | |
1774 | _initialize_infrun () | |
1775 | { | |
1776 | register int i; | |
1777 | ||
1778 | add_info ("signals", signals_info, | |
1779 | "What debugger does when program gets various signals.\n\ | |
1780 | Specify a signal number as argument to print info on that signal only."); | |
1781 | ||
1782 | add_com ("handle", class_run, handle_command, | |
1783 | "Specify how to handle a signal.\n\ | |
1784 | Args are signal number followed by flags.\n\ | |
1785 | Flags allowed are \"stop\", \"print\", \"pass\",\n\ | |
1786 | \"nostop\", \"noprint\" or \"nopass\".\n\ | |
1787 | Print means print a message if this signal happens.\n\ | |
1788 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
1789 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
1790 | Pass and Stop may be combined."); | |
1791 | ||
1792 | for (i = 0; i < NSIG; i++) | |
1793 | { | |
1794 | signal_stop[i] = 1; | |
1795 | signal_print[i] = 1; | |
1796 | signal_program[i] = 1; | |
1797 | } | |
1798 | ||
1799 | /* Signals caused by debugger's own actions | |
1800 | should not be given to the program afterwards. */ | |
1801 | signal_program[SIGTRAP] = 0; | |
1802 | signal_program[SIGINT] = 0; | |
1803 | ||
1804 | /* Signals that are not errors should not normally enter the debugger. */ | |
1805 | #ifdef SIGALRM | |
1806 | signal_stop[SIGALRM] = 0; | |
1807 | signal_print[SIGALRM] = 0; | |
1808 | #endif /* SIGALRM */ | |
1809 | #ifdef SIGVTALRM | |
1810 | signal_stop[SIGVTALRM] = 0; | |
1811 | signal_print[SIGVTALRM] = 0; | |
1812 | #endif /* SIGVTALRM */ | |
1813 | #ifdef SIGPROF | |
1814 | signal_stop[SIGPROF] = 0; | |
1815 | signal_print[SIGPROF] = 0; | |
1816 | #endif /* SIGPROF */ | |
1817 | #ifdef SIGCHLD | |
1818 | signal_stop[SIGCHLD] = 0; | |
1819 | signal_print[SIGCHLD] = 0; | |
1820 | #endif /* SIGCHLD */ | |
1821 | #ifdef SIGCLD | |
1822 | signal_stop[SIGCLD] = 0; | |
1823 | signal_print[SIGCLD] = 0; | |
1824 | #endif /* SIGCLD */ | |
1825 | #ifdef SIGIO | |
1826 | signal_stop[SIGIO] = 0; | |
1827 | signal_print[SIGIO] = 0; | |
1828 | #endif /* SIGIO */ | |
1829 | #ifdef SIGURG | |
1830 | signal_stop[SIGURG] = 0; | |
1831 | signal_print[SIGURG] = 0; | |
1832 | #endif /* SIGURG */ | |
1833 | } | |
1834 |