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