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