Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-struct-independent code to start (run) and stop an inferior process. |
7a292a7a | 2 | Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc. |
c906108c SS |
3 | |
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "gdb_string.h" | |
22 | #include <ctype.h> | |
23 | #include "symtab.h" | |
24 | #include "frame.h" | |
25 | #include "inferior.h" | |
26 | #include "breakpoint.h" | |
27 | #include "wait.h" | |
28 | #include "gdbcore.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "target.h" | |
31 | #include "gdbthread.h" | |
32 | #include "annotate.h" | |
33 | #include "symfile.h" /* for overlay functions */ | |
7a292a7a | 34 | #include "top.h" |
c906108c SS |
35 | |
36 | #include <signal.h> | |
37 | ||
38 | /* Prototypes for local functions */ | |
39 | ||
40 | static void signals_info PARAMS ((char *, int)); | |
41 | ||
42 | static void handle_command PARAMS ((char *, int)); | |
43 | ||
44 | static void sig_print_info PARAMS ((enum target_signal)); | |
45 | ||
46 | static void sig_print_header PARAMS ((void)); | |
47 | ||
48 | static void resume_cleanups PARAMS ((int)); | |
49 | ||
50 | static int hook_stop_stub PARAMS ((PTR)); | |
51 | ||
52 | static void delete_breakpoint_current_contents PARAMS ((PTR)); | |
53 | ||
7a292a7a SS |
54 | static void set_follow_fork_mode_command PARAMS ((char *arg, int from_tty, struct cmd_list_element *c)); |
55 | ||
c906108c SS |
56 | int inferior_ignoring_startup_exec_events = 0; |
57 | int inferior_ignoring_leading_exec_events = 0; | |
58 | ||
c906108c SS |
59 | /* wait_for_inferior and normal_stop use this to notify the user |
60 | when the inferior stopped in a different thread than it had been | |
61 | running in. */ | |
62 | static int switched_from_inferior_pid; | |
7a292a7a SS |
63 | |
64 | /* This will be true for configurations that may actually report an | |
65 | inferior pid different from the original. At present this is only | |
66 | true for HP-UX native. */ | |
67 | ||
68 | #ifndef MAY_SWITCH_FROM_INFERIOR_PID | |
69 | #define MAY_SWITCH_FROM_INFERIOR_PID (0) | |
70 | #endif | |
71 | ||
72 | static int may_switch_from_inferior_pid = MAY_SWITCH_FROM_INFERIOR_PID; | |
73 | ||
74 | /* This is true for configurations that may follow through execl() and | |
75 | similar functions. At present this is only true for HP-UX native. */ | |
76 | ||
77 | #ifndef MAY_FOLLOW_EXEC | |
78 | #define MAY_FOLLOW_EXEC (0) | |
c906108c SS |
79 | #endif |
80 | ||
7a292a7a SS |
81 | static int may_follow_exec = MAY_FOLLOW_EXEC; |
82 | ||
c906108c SS |
83 | /* resume and wait_for_inferior use this to ensure that when |
84 | stepping over a hit breakpoint in a threaded application | |
85 | only the thread that hit the breakpoint is stepped and the | |
86 | other threads don't continue. This prevents having another | |
87 | thread run past the breakpoint while it is temporarily | |
88 | removed. | |
89 | ||
90 | This is not thread-specific, so it isn't saved as part of | |
91 | the infrun state. | |
92 | ||
93 | Versions of gdb which don't use the "step == this thread steps | |
94 | and others continue" model but instead use the "step == this | |
95 | thread steps and others wait" shouldn't do this. */ | |
96 | static int thread_step_needed = 0; | |
97 | ||
7a292a7a SS |
98 | /* This is true if thread_step_needed should actually be used. At |
99 | present this is only true for HP-UX native. */ | |
100 | ||
101 | #ifndef USE_THREAD_STEP_NEEDED | |
102 | #define USE_THREAD_STEP_NEEDED (0) | |
103 | #endif | |
104 | ||
105 | static int use_thread_step_needed = USE_THREAD_STEP_NEEDED; | |
106 | ||
392a587b JM |
107 | static void follow_inferior_fork PARAMS ((int parent_pid, |
108 | int child_pid, | |
109 | int has_forked, | |
110 | int has_vforked)); | |
111 | ||
112 | static void follow_fork PARAMS ((int parent_pid, int child_pid)); | |
113 | ||
114 | static void follow_vfork PARAMS ((int parent_pid, int child_pid)); | |
115 | ||
116 | static void set_schedlock_func PARAMS ((char *args, int from_tty, | |
117 | struct cmd_list_element *c)); | |
118 | ||
119 | static int is_internal_shlib_eventpoint PARAMS ((struct breakpoint *ep)); | |
120 | ||
121 | static int stopped_for_internal_shlib_event PARAMS ((bpstat bs)); | |
122 | ||
123 | static int stopped_for_shlib_catchpoint PARAMS ((bpstat bs, | |
124 | struct breakpoint **cp_p)); | |
125 | ||
126 | #if __STDC__ | |
127 | struct execution_control_state; | |
128 | #endif | |
129 | static int currently_stepping PARAMS ((struct execution_control_state *ecs)); | |
130 | ||
131 | static void xdb_handle_command PARAMS ((char *args, int from_tty)); | |
132 | ||
c906108c SS |
133 | void _initialize_infrun PARAMS ((void)); |
134 | ||
135 | /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the | |
136 | program. It needs to examine the jmp_buf argument and extract the PC | |
137 | from it. The return value is non-zero on success, zero otherwise. */ | |
138 | ||
139 | #ifndef GET_LONGJMP_TARGET | |
140 | #define GET_LONGJMP_TARGET(PC_ADDR) 0 | |
141 | #endif | |
142 | ||
143 | ||
144 | /* Some machines have trampoline code that sits between function callers | |
145 | and the actual functions themselves. If this machine doesn't have | |
146 | such things, disable their processing. */ | |
147 | ||
148 | #ifndef SKIP_TRAMPOLINE_CODE | |
149 | #define SKIP_TRAMPOLINE_CODE(pc) 0 | |
150 | #endif | |
151 | ||
152 | /* Dynamic function trampolines are similar to solib trampolines in that they | |
153 | are between the caller and the callee. The difference is that when you | |
154 | enter a dynamic trampoline, you can't determine the callee's address. Some | |
155 | (usually complex) code needs to run in the dynamic trampoline to figure out | |
156 | the callee's address. This macro is usually called twice. First, when we | |
157 | enter the trampoline (looks like a normal function call at that point). It | |
158 | should return the PC of a point within the trampoline where the callee's | |
159 | address is known. Second, when we hit the breakpoint, this routine returns | |
160 | the callee's address. At that point, things proceed as per a step resume | |
161 | breakpoint. */ | |
162 | ||
163 | #ifndef DYNAMIC_TRAMPOLINE_NEXTPC | |
164 | #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0 | |
165 | #endif | |
166 | ||
167 | /* On SVR4 based systems, determining the callee's address is exceedingly | |
168 | difficult and depends on the implementation of the run time loader. | |
169 | If we are stepping at the source level, we single step until we exit | |
170 | the run time loader code and reach the callee's address. */ | |
171 | ||
172 | #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE | |
173 | #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0 | |
174 | #endif | |
175 | ||
176 | /* For SVR4 shared libraries, each call goes through a small piece of | |
177 | trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates | |
178 | to nonzero if we are current stopped in one of these. */ | |
179 | ||
180 | #ifndef IN_SOLIB_CALL_TRAMPOLINE | |
181 | #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0 | |
182 | #endif | |
183 | ||
184 | /* In some shared library schemes, the return path from a shared library | |
185 | call may need to go through a trampoline too. */ | |
186 | ||
187 | #ifndef IN_SOLIB_RETURN_TRAMPOLINE | |
188 | #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0 | |
189 | #endif | |
190 | ||
191 | /* This function returns TRUE if pc is the address of an instruction | |
192 | that lies within the dynamic linker (such as the event hook, or the | |
193 | dld itself). | |
194 | ||
195 | This function must be used only when a dynamic linker event has | |
196 | been caught, and the inferior is being stepped out of the hook, or | |
197 | undefined results are guaranteed. */ | |
198 | ||
199 | #ifndef SOLIB_IN_DYNAMIC_LINKER | |
200 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 | |
201 | #endif | |
202 | ||
203 | /* On MIPS16, a function that returns a floating point value may call | |
204 | a library helper function to copy the return value to a floating point | |
205 | register. The IGNORE_HELPER_CALL macro returns non-zero if we | |
206 | should ignore (i.e. step over) this function call. */ | |
207 | #ifndef IGNORE_HELPER_CALL | |
208 | #define IGNORE_HELPER_CALL(pc) 0 | |
209 | #endif | |
210 | ||
211 | /* On some systems, the PC may be left pointing at an instruction that won't | |
212 | actually be executed. This is usually indicated by a bit in the PSW. If | |
213 | we find ourselves in such a state, then we step the target beyond the | |
214 | nullified instruction before returning control to the user so as to avoid | |
215 | confusion. */ | |
216 | ||
217 | #ifndef INSTRUCTION_NULLIFIED | |
218 | #define INSTRUCTION_NULLIFIED 0 | |
219 | #endif | |
220 | ||
7a292a7a SS |
221 | /* Convert the #defines into values. This is temporary until wfi control |
222 | flow is completely sorted out. */ | |
223 | ||
224 | #ifndef HAVE_STEPPABLE_WATCHPOINT | |
225 | #define HAVE_STEPPABLE_WATCHPOINT 0 | |
226 | #else | |
227 | #undef HAVE_STEPPABLE_WATCHPOINT | |
228 | #define HAVE_STEPPABLE_WATCHPOINT 1 | |
229 | #endif | |
230 | ||
231 | #ifndef HAVE_NONSTEPPABLE_WATCHPOINT | |
232 | #define HAVE_NONSTEPPABLE_WATCHPOINT 0 | |
233 | #else | |
234 | #undef HAVE_NONSTEPPABLE_WATCHPOINT | |
235 | #define HAVE_NONSTEPPABLE_WATCHPOINT 1 | |
236 | #endif | |
237 | ||
238 | #ifndef HAVE_CONTINUABLE_WATCHPOINT | |
239 | #define HAVE_CONTINUABLE_WATCHPOINT 0 | |
240 | #else | |
241 | #undef HAVE_CONTINUABLE_WATCHPOINT | |
242 | #define HAVE_CONTINUABLE_WATCHPOINT 1 | |
243 | #endif | |
244 | ||
c906108c SS |
245 | /* Tables of how to react to signals; the user sets them. */ |
246 | ||
247 | static unsigned char *signal_stop; | |
248 | static unsigned char *signal_print; | |
249 | static unsigned char *signal_program; | |
250 | ||
251 | #define SET_SIGS(nsigs,sigs,flags) \ | |
252 | do { \ | |
253 | int signum = (nsigs); \ | |
254 | while (signum-- > 0) \ | |
255 | if ((sigs)[signum]) \ | |
256 | (flags)[signum] = 1; \ | |
257 | } while (0) | |
258 | ||
259 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
260 | do { \ | |
261 | int signum = (nsigs); \ | |
262 | while (signum-- > 0) \ | |
263 | if ((sigs)[signum]) \ | |
264 | (flags)[signum] = 0; \ | |
265 | } while (0) | |
266 | ||
267 | ||
268 | /* Command list pointer for the "stop" placeholder. */ | |
269 | ||
270 | static struct cmd_list_element *stop_command; | |
271 | ||
272 | /* Nonzero if breakpoints are now inserted in the inferior. */ | |
273 | ||
274 | static int breakpoints_inserted; | |
275 | ||
276 | /* Function inferior was in as of last step command. */ | |
277 | ||
278 | static struct symbol *step_start_function; | |
279 | ||
280 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ | |
281 | ||
282 | static int trap_expected; | |
283 | ||
284 | #ifdef SOLIB_ADD | |
285 | /* Nonzero if we want to give control to the user when we're notified | |
286 | of shared library events by the dynamic linker. */ | |
287 | static int stop_on_solib_events; | |
288 | #endif | |
289 | ||
290 | #ifdef HP_OS_BUG | |
291 | /* Nonzero if the next time we try to continue the inferior, it will | |
292 | step one instruction and generate a spurious trace trap. | |
293 | This is used to compensate for a bug in HP-UX. */ | |
294 | ||
295 | static int trap_expected_after_continue; | |
296 | #endif | |
297 | ||
298 | /* Nonzero means expecting a trace trap | |
299 | and should stop the inferior and return silently when it happens. */ | |
300 | ||
301 | int stop_after_trap; | |
302 | ||
303 | /* Nonzero means expecting a trap and caller will handle it themselves. | |
304 | It is used after attach, due to attaching to a process; | |
305 | when running in the shell before the child program has been exec'd; | |
306 | and when running some kinds of remote stuff (FIXME?). */ | |
307 | ||
308 | int stop_soon_quietly; | |
309 | ||
310 | /* Nonzero if proceed is being used for a "finish" command or a similar | |
311 | situation when stop_registers should be saved. */ | |
312 | ||
313 | int proceed_to_finish; | |
314 | ||
315 | /* Save register contents here when about to pop a stack dummy frame, | |
316 | if-and-only-if proceed_to_finish is set. | |
317 | Thus this contains the return value from the called function (assuming | |
318 | values are returned in a register). */ | |
319 | ||
7a292a7a | 320 | char *stop_registers; |
c906108c SS |
321 | |
322 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ | |
323 | ||
324 | static int breakpoints_failed; | |
325 | ||
326 | /* Nonzero after stop if current stack frame should be printed. */ | |
327 | ||
328 | static int stop_print_frame; | |
329 | ||
330 | static struct breakpoint *step_resume_breakpoint = NULL; | |
331 | static struct breakpoint *through_sigtramp_breakpoint = NULL; | |
332 | ||
333 | /* On some platforms (e.g., HP-UX), hardware watchpoints have bad | |
334 | interactions with an inferior that is running a kernel function | |
335 | (aka, a system call or "syscall"). wait_for_inferior therefore | |
336 | may have a need to know when the inferior is in a syscall. This | |
337 | is a count of the number of inferior threads which are known to | |
338 | currently be running in a syscall. */ | |
339 | static int number_of_threads_in_syscalls; | |
340 | ||
341 | /* This is used to remember when a fork, vfork or exec event | |
342 | was caught by a catchpoint, and thus the event is to be | |
343 | followed at the next resume of the inferior, and not | |
344 | immediately. */ | |
345 | static struct | |
346 | { | |
347 | enum target_waitkind kind; | |
348 | struct | |
349 | { | |
350 | int parent_pid; | |
351 | int saw_parent_fork; | |
352 | int child_pid; | |
353 | int saw_child_fork; | |
354 | int saw_child_exec; | |
355 | } | |
356 | fork_event; | |
357 | char *execd_pathname; | |
358 | } | |
359 | pending_follow; | |
360 | ||
361 | /* Some platforms don't allow us to do anything meaningful with a | |
362 | vforked child until it has exec'd. Vforked processes on such | |
363 | platforms can only be followed after they've exec'd. | |
364 | ||
365 | When this is set to 0, a vfork can be immediately followed, | |
366 | and an exec can be followed merely as an exec. When this is | |
367 | set to 1, a vfork event has been seen, but cannot be followed | |
368 | until the exec is seen. | |
369 | ||
370 | (In the latter case, inferior_pid is still the parent of the | |
371 | vfork, and pending_follow.fork_event.child_pid is the child. The | |
372 | appropriate process is followed, according to the setting of | |
373 | follow-fork-mode.) */ | |
374 | static int follow_vfork_when_exec; | |
375 | ||
376 | static char *follow_fork_mode_kind_names[] = | |
377 | { | |
378 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 | |
379 | kernel problem. It's also not terribly useful without a GUI to | |
380 | help the user drive two debuggers. So for now, I'm disabling | |
381 | the "both" option. | |
382 | "parent", "child", "both", "ask" }; | |
383 | */ | |
384 | "parent", "child", "ask"}; | |
385 | ||
386 | static char *follow_fork_mode_string = NULL; | |
387 | \f | |
388 | ||
c906108c SS |
389 | static void |
390 | follow_inferior_fork (parent_pid, child_pid, has_forked, has_vforked) | |
391 | int parent_pid; | |
392 | int child_pid; | |
393 | int has_forked; | |
394 | int has_vforked; | |
395 | { | |
396 | int followed_parent = 0; | |
397 | int followed_child = 0; | |
398 | int ima_clone = 0; | |
399 | ||
400 | /* Which process did the user want us to follow? */ | |
401 | char *follow_mode = | |
402 | savestring (follow_fork_mode_string, strlen (follow_fork_mode_string)); | |
403 | ||
404 | /* Or, did the user not know, and want us to ask? */ | |
405 | if (STREQ (follow_fork_mode_string, "ask")) | |
406 | { | |
407 | char requested_mode[100]; | |
408 | ||
409 | free (follow_mode); | |
410 | error ("\"ask\" mode NYI"); | |
411 | follow_mode = savestring (requested_mode, strlen (requested_mode)); | |
412 | } | |
413 | ||
414 | /* If we're to be following the parent, then detach from child_pid. | |
415 | We're already following the parent, so need do nothing explicit | |
416 | for it. */ | |
417 | if (STREQ (follow_mode, "parent")) | |
418 | { | |
419 | followed_parent = 1; | |
420 | ||
421 | /* We're already attached to the parent, by default. */ | |
422 | ||
423 | /* Before detaching from the child, remove all breakpoints from | |
424 | it. (This won't actually modify the breakpoint list, but will | |
425 | physically remove the breakpoints from the child.) */ | |
426 | if (!has_vforked || !follow_vfork_when_exec) | |
427 | { | |
428 | detach_breakpoints (child_pid); | |
7a292a7a | 429 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
c906108c | 430 | SOLIB_REMOVE_INFERIOR_HOOK (child_pid); |
7a292a7a | 431 | #endif |
c906108c SS |
432 | } |
433 | ||
434 | /* Detach from the child. */ | |
435 | dont_repeat (); | |
436 | ||
437 | target_require_detach (child_pid, "", 1); | |
438 | } | |
439 | ||
440 | /* If we're to be following the child, then attach to it, detach | |
441 | from inferior_pid, and set inferior_pid to child_pid. */ | |
442 | else if (STREQ (follow_mode, "child")) | |
443 | { | |
444 | char child_pid_spelling[100]; /* Arbitrary length. */ | |
445 | ||
446 | followed_child = 1; | |
447 | ||
448 | /* Before detaching from the parent, detach all breakpoints from | |
449 | the child. But only if we're forking, or if we follow vforks | |
450 | as soon as they happen. (If we're following vforks only when | |
451 | the child has exec'd, then it's very wrong to try to write | |
452 | back the "shadow contents" of inserted breakpoints now -- they | |
453 | belong to the child's pre-exec'd a.out.) */ | |
454 | if (!has_vforked || !follow_vfork_when_exec) | |
455 | { | |
456 | detach_breakpoints (child_pid); | |
457 | } | |
458 | ||
459 | /* Before detaching from the parent, remove all breakpoints from it. */ | |
460 | remove_breakpoints (); | |
461 | ||
462 | /* Also reset the solib inferior hook from the parent. */ | |
7a292a7a | 463 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
c906108c | 464 | SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid); |
7a292a7a | 465 | #endif |
c906108c SS |
466 | |
467 | /* Detach from the parent. */ | |
468 | dont_repeat (); | |
469 | target_detach (NULL, 1); | |
470 | ||
471 | /* Attach to the child. */ | |
472 | inferior_pid = child_pid; | |
473 | sprintf (child_pid_spelling, "%d", child_pid); | |
474 | dont_repeat (); | |
475 | ||
476 | target_require_attach (child_pid_spelling, 1); | |
477 | ||
478 | /* Was there a step_resume breakpoint? (There was if the user | |
479 | did a "next" at the fork() call.) If so, explicitly reset its | |
480 | thread number. | |
481 | ||
482 | step_resumes are a form of bp that are made to be per-thread. | |
483 | Since we created the step_resume bp when the parent process | |
484 | was being debugged, and now are switching to the child process, | |
485 | from the breakpoint package's viewpoint, that's a switch of | |
486 | "threads". We must update the bp's notion of which thread | |
487 | it is for, or it'll be ignored when it triggers... */ | |
488 | if (step_resume_breakpoint && | |
489 | (!has_vforked || !follow_vfork_when_exec)) | |
490 | breakpoint_re_set_thread (step_resume_breakpoint); | |
491 | ||
492 | /* Reinsert all breakpoints in the child. (The user may've set | |
493 | breakpoints after catching the fork, in which case those | |
494 | actually didn't get set in the child, but only in the parent.) */ | |
495 | if (!has_vforked || !follow_vfork_when_exec) | |
496 | { | |
497 | breakpoint_re_set (); | |
498 | insert_breakpoints (); | |
499 | } | |
500 | } | |
501 | ||
502 | /* If we're to be following both parent and child, then fork ourselves, | |
503 | and attach the debugger clone to the child. */ | |
504 | else if (STREQ (follow_mode, "both")) | |
505 | { | |
506 | char pid_suffix[100]; /* Arbitrary length. */ | |
507 | ||
508 | /* Clone ourselves to follow the child. This is the end of our | |
509 | involvement with child_pid; our clone will take it from here... */ | |
510 | dont_repeat (); | |
511 | target_clone_and_follow_inferior (child_pid, &followed_child); | |
512 | followed_parent = !followed_child; | |
513 | ||
514 | /* We continue to follow the parent. To help distinguish the two | |
515 | debuggers, though, both we and our clone will reset our prompts. */ | |
516 | sprintf (pid_suffix, "[%d] ", inferior_pid); | |
517 | set_prompt (strcat (get_prompt (), pid_suffix)); | |
518 | } | |
519 | ||
520 | /* The parent and child of a vfork share the same address space. | |
521 | Also, on some targets the order in which vfork and exec events | |
522 | are received for parent in child requires some delicate handling | |
523 | of the events. | |
524 | ||
525 | For instance, on ptrace-based HPUX we receive the child's vfork | |
526 | event first, at which time the parent has been suspended by the | |
527 | OS and is essentially untouchable until the child's exit or second | |
528 | exec event arrives. At that time, the parent's vfork event is | |
529 | delivered to us, and that's when we see and decide how to follow | |
530 | the vfork. But to get to that point, we must continue the child | |
531 | until it execs or exits. To do that smoothly, all breakpoints | |
532 | must be removed from the child, in case there are any set between | |
533 | the vfork() and exec() calls. But removing them from the child | |
534 | also removes them from the parent, due to the shared-address-space | |
535 | nature of a vfork'd parent and child. On HPUX, therefore, we must | |
536 | take care to restore the bp's to the parent before we continue it. | |
537 | Else, it's likely that we may not stop in the expected place. (The | |
538 | worst scenario is when the user tries to step over a vfork() call; | |
539 | the step-resume bp must be restored for the step to properly stop | |
540 | in the parent after the call completes!) | |
541 | ||
542 | Sequence of events, as reported to gdb from HPUX: | |
543 | ||
544 | Parent Child Action for gdb to take | |
545 | ------------------------------------------------------- | |
546 | 1 VFORK Continue child | |
547 | 2 EXEC | |
548 | 3 EXEC or EXIT | |
549 | 4 VFORK */ | |
550 | if (has_vforked) | |
551 | { | |
552 | target_post_follow_vfork (parent_pid, | |
553 | followed_parent, | |
554 | child_pid, | |
555 | followed_child); | |
556 | } | |
557 | ||
558 | pending_follow.fork_event.saw_parent_fork = 0; | |
559 | pending_follow.fork_event.saw_child_fork = 0; | |
560 | ||
561 | free (follow_mode); | |
562 | } | |
563 | ||
564 | static void | |
565 | follow_fork (parent_pid, child_pid) | |
566 | int parent_pid; | |
567 | int child_pid; | |
568 | { | |
569 | follow_inferior_fork (parent_pid, child_pid, 1, 0); | |
570 | } | |
571 | ||
572 | ||
573 | /* Forward declaration. */ | |
574 | static void follow_exec PARAMS ((int, char *)); | |
575 | ||
576 | static void | |
577 | follow_vfork (parent_pid, child_pid) | |
578 | int parent_pid; | |
579 | int child_pid; | |
580 | { | |
581 | follow_inferior_fork (parent_pid, child_pid, 0, 1); | |
582 | ||
583 | /* Did we follow the child? Had it exec'd before we saw the parent vfork? */ | |
584 | if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid)) | |
585 | { | |
586 | pending_follow.fork_event.saw_child_exec = 0; | |
587 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
588 | follow_exec (inferior_pid, pending_follow.execd_pathname); | |
589 | free (pending_follow.execd_pathname); | |
590 | } | |
591 | } | |
c906108c SS |
592 | |
593 | static void | |
594 | follow_exec (pid, execd_pathname) | |
595 | int pid; | |
596 | char *execd_pathname; | |
597 | { | |
c906108c | 598 | int saved_pid = pid; |
7a292a7a SS |
599 | struct target_ops *tgt; |
600 | ||
601 | if (!may_follow_exec) | |
602 | return; | |
c906108c SS |
603 | |
604 | /* Did this exec() follow a vfork()? If so, we must follow the | |
605 | vfork now too. Do it before following the exec. */ | |
606 | if (follow_vfork_when_exec && | |
607 | (pending_follow.kind == TARGET_WAITKIND_VFORKED)) | |
608 | { | |
609 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
610 | follow_vfork (inferior_pid, pending_follow.fork_event.child_pid); | |
611 | follow_vfork_when_exec = 0; | |
612 | saved_pid = inferior_pid; | |
613 | ||
614 | /* Did we follow the parent? If so, we're done. If we followed | |
615 | the child then we must also follow its exec(). */ | |
616 | if (inferior_pid == pending_follow.fork_event.parent_pid) | |
617 | return; | |
618 | } | |
619 | ||
620 | /* This is an exec event that we actually wish to pay attention to. | |
621 | Refresh our symbol table to the newly exec'd program, remove any | |
622 | momentary bp's, etc. | |
623 | ||
624 | If there are breakpoints, they aren't really inserted now, | |
625 | since the exec() transformed our inferior into a fresh set | |
626 | of instructions. | |
627 | ||
628 | We want to preserve symbolic breakpoints on the list, since | |
629 | we have hopes that they can be reset after the new a.out's | |
630 | symbol table is read. | |
631 | ||
632 | However, any "raw" breakpoints must be removed from the list | |
633 | (e.g., the solib bp's), since their address is probably invalid | |
634 | now. | |
635 | ||
636 | And, we DON'T want to call delete_breakpoints() here, since | |
637 | that may write the bp's "shadow contents" (the instruction | |
638 | value that was overwritten witha TRAP instruction). Since | |
639 | we now have a new a.out, those shadow contents aren't valid. */ | |
640 | update_breakpoints_after_exec (); | |
641 | ||
642 | /* If there was one, it's gone now. We cannot truly step-to-next | |
643 | statement through an exec(). */ | |
644 | step_resume_breakpoint = NULL; | |
645 | step_range_start = 0; | |
646 | step_range_end = 0; | |
647 | ||
648 | /* If there was one, it's gone now. */ | |
649 | through_sigtramp_breakpoint = NULL; | |
650 | ||
651 | /* What is this a.out's name? */ | |
652 | printf_unfiltered ("Executing new program: %s\n", execd_pathname); | |
653 | ||
654 | /* We've followed the inferior through an exec. Therefore, the | |
655 | inferior has essentially been killed & reborn. */ | |
7a292a7a SS |
656 | |
657 | /* First collect the run target in effect. */ | |
658 | tgt = find_run_target (); | |
659 | /* If we can't find one, things are in a very strange state... */ | |
660 | if (tgt == NULL) | |
661 | error ("Could find run target to save before following exec"); | |
662 | ||
c906108c SS |
663 | gdb_flush (gdb_stdout); |
664 | target_mourn_inferior (); | |
7a292a7a SS |
665 | inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */ |
666 | push_target (tgt); | |
c906108c SS |
667 | |
668 | /* That a.out is now the one to use. */ | |
669 | exec_file_attach (execd_pathname, 0); | |
670 | ||
671 | /* And also is where symbols can be found. */ | |
672 | symbol_file_command (execd_pathname, 0); | |
673 | ||
674 | /* Reset the shared library package. This ensures that we get | |
675 | a shlib event when the child reaches "_start", at which point | |
676 | the dld will have had a chance to initialize the child. */ | |
7a292a7a | 677 | #if defined(SOLIB_RESTART) |
c906108c | 678 | SOLIB_RESTART (); |
7a292a7a SS |
679 | #endif |
680 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
c906108c | 681 | SOLIB_CREATE_INFERIOR_HOOK (inferior_pid); |
7a292a7a | 682 | #endif |
c906108c SS |
683 | |
684 | /* Reinsert all breakpoints. (Those which were symbolic have | |
685 | been reset to the proper address in the new a.out, thanks | |
686 | to symbol_file_command...) */ | |
687 | insert_breakpoints (); | |
688 | ||
689 | /* The next resume of this inferior should bring it to the shlib | |
690 | startup breakpoints. (If the user had also set bp's on | |
691 | "main" from the old (parent) process, then they'll auto- | |
692 | matically get reset there in the new process.) */ | |
c906108c SS |
693 | } |
694 | ||
695 | /* Non-zero if we just simulating a single-step. This is needed | |
696 | because we cannot remove the breakpoints in the inferior process | |
697 | until after the `wait' in `wait_for_inferior'. */ | |
698 | static int singlestep_breakpoints_inserted_p = 0; | |
699 | \f | |
700 | ||
701 | /* Things to clean up if we QUIT out of resume (). */ | |
702 | /* ARGSUSED */ | |
703 | static void | |
704 | resume_cleanups (arg) | |
705 | int arg; | |
706 | { | |
707 | normal_stop (); | |
708 | } | |
709 | ||
710 | static char schedlock_off[] = "off"; | |
711 | static char schedlock_on[] = "on"; | |
712 | static char schedlock_step[] = "step"; | |
713 | static char *scheduler_mode = schedlock_off; | |
714 | static char *scheduler_enums[] = | |
715 | {schedlock_off, schedlock_on, schedlock_step}; | |
716 | ||
717 | static void | |
718 | set_schedlock_func (args, from_tty, c) | |
719 | char *args; | |
720 | int from_tty; | |
721 | struct cmd_list_element *c; | |
722 | { | |
723 | if (c->type == set_cmd) | |
724 | if (!target_can_lock_scheduler) | |
725 | { | |
726 | scheduler_mode = schedlock_off; | |
727 | error ("Target '%s' cannot support this command.", | |
728 | target_shortname); | |
729 | } | |
730 | } | |
731 | ||
732 | ||
733 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
734 | wants to interrupt some lengthy single-stepping operation | |
735 | (for child processes, the SIGINT goes to the inferior, and so | |
736 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
737 | other targets, that's not true). | |
738 | ||
739 | STEP nonzero if we should step (zero to continue instead). | |
740 | SIG is the signal to give the inferior (zero for none). */ | |
741 | void | |
742 | resume (step, sig) | |
743 | int step; | |
744 | enum target_signal sig; | |
745 | { | |
746 | int should_resume = 1; | |
747 | struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func) | |
748 | resume_cleanups, 0); | |
749 | QUIT; | |
750 | ||
751 | #ifdef CANNOT_STEP_BREAKPOINT | |
752 | /* Most targets can step a breakpoint instruction, thus executing it | |
753 | normally. But if this one cannot, just continue and we will hit | |
754 | it anyway. */ | |
755 | if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) | |
756 | step = 0; | |
757 | #endif | |
758 | ||
759 | if (SOFTWARE_SINGLE_STEP_P && step) | |
760 | { | |
761 | /* Do it the hard way, w/temp breakpoints */ | |
762 | SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints*/ ); | |
763 | /* ...and don't ask hardware to do it. */ | |
764 | step = 0; | |
765 | /* and do not pull these breakpoints until after a `wait' in | |
766 | `wait_for_inferior' */ | |
767 | singlestep_breakpoints_inserted_p = 1; | |
768 | } | |
769 | ||
770 | /* Handle any optimized stores to the inferior NOW... */ | |
771 | #ifdef DO_DEFERRED_STORES | |
772 | DO_DEFERRED_STORES; | |
773 | #endif | |
774 | ||
c906108c SS |
775 | /* If there were any forks/vforks/execs that were caught and are |
776 | now to be followed, then do so. */ | |
777 | switch (pending_follow.kind) | |
778 | { | |
779 | case (TARGET_WAITKIND_FORKED): | |
780 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
781 | follow_fork (inferior_pid, pending_follow.fork_event.child_pid); | |
782 | break; | |
783 | ||
784 | case (TARGET_WAITKIND_VFORKED): | |
785 | { | |
786 | int saw_child_exec = pending_follow.fork_event.saw_child_exec; | |
787 | ||
788 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
789 | follow_vfork (inferior_pid, pending_follow.fork_event.child_pid); | |
790 | ||
791 | /* Did we follow the child, but not yet see the child's exec event? | |
792 | If so, then it actually ought to be waiting for us; we respond to | |
793 | parent vfork events. We don't actually want to resume the child | |
794 | in this situation; we want to just get its exec event. */ | |
795 | if (!saw_child_exec && | |
796 | (inferior_pid == pending_follow.fork_event.child_pid)) | |
797 | should_resume = 0; | |
798 | } | |
799 | break; | |
800 | ||
801 | case (TARGET_WAITKIND_EXECD): | |
802 | /* If we saw a vfork event but couldn't follow it until we saw | |
803 | an exec, then now might be the time! */ | |
804 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
805 | /* follow_exec is called as soon as the exec event is seen. */ | |
806 | break; | |
807 | ||
808 | default: | |
809 | break; | |
810 | } | |
c906108c SS |
811 | |
812 | /* Install inferior's terminal modes. */ | |
813 | target_terminal_inferior (); | |
814 | ||
815 | if (should_resume) | |
816 | { | |
7a292a7a | 817 | if (use_thread_step_needed && thread_step_needed) |
c906108c SS |
818 | { |
819 | /* We stopped on a BPT instruction; | |
820 | don't continue other threads and | |
821 | just step this thread. */ | |
822 | thread_step_needed = 0; | |
823 | ||
824 | if (!breakpoint_here_p (read_pc ())) | |
825 | { | |
826 | /* Breakpoint deleted: ok to do regular resume | |
827 | where all the threads either step or continue. */ | |
828 | target_resume (-1, step, sig); | |
829 | } | |
830 | else | |
831 | { | |
832 | if (!step) | |
833 | { | |
834 | warning ("Internal error, changing continue to step."); | |
835 | remove_breakpoints (); | |
836 | breakpoints_inserted = 0; | |
837 | trap_expected = 1; | |
838 | step = 1; | |
839 | } | |
840 | ||
841 | target_resume (inferior_pid, step, sig); | |
842 | } | |
843 | } | |
844 | else | |
c906108c SS |
845 | { |
846 | /* Vanilla resume. */ | |
847 | ||
848 | if ((scheduler_mode == schedlock_on) || | |
849 | (scheduler_mode == schedlock_step && step != 0)) | |
850 | target_resume (inferior_pid, step, sig); | |
851 | else | |
852 | target_resume (-1, step, sig); | |
853 | } | |
854 | } | |
855 | ||
856 | discard_cleanups (old_cleanups); | |
857 | } | |
858 | \f | |
859 | ||
860 | /* Clear out all variables saying what to do when inferior is continued. | |
861 | First do this, then set the ones you want, then call `proceed'. */ | |
862 | ||
863 | void | |
864 | clear_proceed_status () | |
865 | { | |
866 | trap_expected = 0; | |
867 | step_range_start = 0; | |
868 | step_range_end = 0; | |
869 | step_frame_address = 0; | |
870 | step_over_calls = -1; | |
871 | stop_after_trap = 0; | |
872 | stop_soon_quietly = 0; | |
873 | proceed_to_finish = 0; | |
874 | breakpoint_proceeded = 1; /* We're about to proceed... */ | |
875 | ||
876 | /* Discard any remaining commands or status from previous stop. */ | |
877 | bpstat_clear (&stop_bpstat); | |
878 | } | |
879 | ||
880 | /* Basic routine for continuing the program in various fashions. | |
881 | ||
882 | ADDR is the address to resume at, or -1 for resume where stopped. | |
883 | SIGGNAL is the signal to give it, or 0 for none, | |
884 | or -1 for act according to how it stopped. | |
885 | STEP is nonzero if should trap after one instruction. | |
886 | -1 means return after that and print nothing. | |
887 | You should probably set various step_... variables | |
888 | before calling here, if you are stepping. | |
889 | ||
890 | You should call clear_proceed_status before calling proceed. */ | |
891 | ||
892 | void | |
893 | proceed (addr, siggnal, step) | |
894 | CORE_ADDR addr; | |
895 | enum target_signal siggnal; | |
896 | int step; | |
897 | { | |
898 | int oneproc = 0; | |
899 | ||
900 | if (step > 0) | |
901 | step_start_function = find_pc_function (read_pc ()); | |
902 | if (step < 0) | |
903 | stop_after_trap = 1; | |
904 | ||
905 | if (addr == (CORE_ADDR) - 1) | |
906 | { | |
907 | /* If there is a breakpoint at the address we will resume at, | |
908 | step one instruction before inserting breakpoints | |
909 | so that we do not stop right away (and report a second | |
910 | hit at this breakpoint). */ | |
911 | ||
912 | if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) | |
913 | oneproc = 1; | |
914 | ||
915 | #ifndef STEP_SKIPS_DELAY | |
916 | #define STEP_SKIPS_DELAY(pc) (0) | |
917 | #define STEP_SKIPS_DELAY_P (0) | |
918 | #endif | |
919 | /* Check breakpoint_here_p first, because breakpoint_here_p is fast | |
920 | (it just checks internal GDB data structures) and STEP_SKIPS_DELAY | |
921 | is slow (it needs to read memory from the target). */ | |
922 | if (STEP_SKIPS_DELAY_P | |
923 | && breakpoint_here_p (read_pc () + 4) | |
924 | && STEP_SKIPS_DELAY (read_pc ())) | |
925 | oneproc = 1; | |
926 | } | |
927 | else | |
928 | { | |
929 | write_pc (addr); | |
930 | ||
931 | /* New address; we don't need to single-step a thread | |
932 | over a breakpoint we just hit, 'cause we aren't | |
933 | continuing from there. | |
934 | ||
935 | It's not worth worrying about the case where a user | |
936 | asks for a "jump" at the current PC--if they get the | |
937 | hiccup of re-hiting a hit breakpoint, what else do | |
938 | they expect? */ | |
939 | thread_step_needed = 0; | |
940 | } | |
941 | ||
942 | #ifdef PREPARE_TO_PROCEED | |
943 | /* In a multi-threaded task we may select another thread | |
944 | and then continue or step. | |
945 | ||
946 | But if the old thread was stopped at a breakpoint, it | |
947 | will immediately cause another breakpoint stop without | |
948 | any execution (i.e. it will report a breakpoint hit | |
949 | incorrectly). So we must step over it first. | |
950 | ||
951 | PREPARE_TO_PROCEED checks the current thread against the thread | |
952 | that reported the most recent event. If a step-over is required | |
953 | it returns TRUE and sets the current thread to the old thread. */ | |
9e086581 | 954 | if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ())) |
c906108c SS |
955 | { |
956 | oneproc = 1; | |
957 | thread_step_needed = 1; | |
958 | } | |
959 | ||
960 | #endif /* PREPARE_TO_PROCEED */ | |
961 | ||
962 | #ifdef HP_OS_BUG | |
963 | if (trap_expected_after_continue) | |
964 | { | |
965 | /* If (step == 0), a trap will be automatically generated after | |
966 | the first instruction is executed. Force step one | |
967 | instruction to clear this condition. This should not occur | |
968 | if step is nonzero, but it is harmless in that case. */ | |
969 | oneproc = 1; | |
970 | trap_expected_after_continue = 0; | |
971 | } | |
972 | #endif /* HP_OS_BUG */ | |
973 | ||
974 | if (oneproc) | |
975 | /* We will get a trace trap after one instruction. | |
976 | Continue it automatically and insert breakpoints then. */ | |
977 | trap_expected = 1; | |
978 | else | |
979 | { | |
980 | int temp = insert_breakpoints (); | |
981 | if (temp) | |
982 | { | |
983 | print_sys_errmsg ("ptrace", temp); | |
984 | error ("Cannot insert breakpoints.\n\ | |
985 | The same program may be running in another process."); | |
986 | } | |
987 | ||
988 | breakpoints_inserted = 1; | |
989 | } | |
990 | ||
991 | if (siggnal != TARGET_SIGNAL_DEFAULT) | |
992 | stop_signal = siggnal; | |
993 | /* If this signal should not be seen by program, | |
994 | give it zero. Used for debugging signals. */ | |
995 | else if (!signal_program[stop_signal]) | |
996 | stop_signal = TARGET_SIGNAL_0; | |
997 | ||
998 | annotate_starting (); | |
999 | ||
1000 | /* Make sure that output from GDB appears before output from the | |
1001 | inferior. */ | |
1002 | gdb_flush (gdb_stdout); | |
1003 | ||
1004 | /* Resume inferior. */ | |
1005 | resume (oneproc || step || bpstat_should_step (), stop_signal); | |
1006 | ||
1007 | /* Wait for it to stop (if not standalone) | |
1008 | and in any case decode why it stopped, and act accordingly. */ | |
1009 | ||
1010 | wait_for_inferior (); | |
1011 | normal_stop (); | |
1012 | } | |
1013 | ||
1014 | /* Record the pc and sp of the program the last time it stopped. | |
1015 | These are just used internally by wait_for_inferior, but need | |
1016 | to be preserved over calls to it and cleared when the inferior | |
1017 | is started. */ | |
1018 | static CORE_ADDR prev_pc; | |
1019 | static CORE_ADDR prev_func_start; | |
1020 | static char *prev_func_name; | |
1021 | \f | |
1022 | ||
1023 | /* Start remote-debugging of a machine over a serial link. */ | |
1024 | ||
1025 | void | |
1026 | start_remote () | |
1027 | { | |
1028 | init_thread_list (); | |
1029 | init_wait_for_inferior (); | |
1030 | stop_soon_quietly = 1; | |
1031 | trap_expected = 0; | |
1032 | wait_for_inferior (); | |
1033 | normal_stop (); | |
1034 | } | |
1035 | ||
1036 | /* Initialize static vars when a new inferior begins. */ | |
1037 | ||
1038 | void | |
1039 | init_wait_for_inferior () | |
1040 | { | |
1041 | /* These are meaningless until the first time through wait_for_inferior. */ | |
1042 | prev_pc = 0; | |
1043 | prev_func_start = 0; | |
1044 | prev_func_name = NULL; | |
1045 | ||
1046 | #ifdef HP_OS_BUG | |
1047 | trap_expected_after_continue = 0; | |
1048 | #endif | |
1049 | breakpoints_inserted = 0; | |
1050 | breakpoint_init_inferior (inf_starting); | |
1051 | ||
1052 | /* Don't confuse first call to proceed(). */ | |
1053 | stop_signal = TARGET_SIGNAL_0; | |
1054 | ||
1055 | /* The first resume is not following a fork/vfork/exec. */ | |
1056 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ | |
1057 | pending_follow.fork_event.saw_parent_fork = 0; | |
1058 | pending_follow.fork_event.saw_child_fork = 0; | |
1059 | pending_follow.fork_event.saw_child_exec = 0; | |
1060 | ||
1061 | /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */ | |
1062 | number_of_threads_in_syscalls = 0; | |
1063 | ||
1064 | clear_proceed_status (); | |
1065 | } | |
1066 | ||
1067 | static void | |
1068 | delete_breakpoint_current_contents (arg) | |
1069 | PTR arg; | |
1070 | { | |
1071 | struct breakpoint **breakpointp = (struct breakpoint **) arg; | |
1072 | if (*breakpointp != NULL) | |
1073 | { | |
1074 | delete_breakpoint (*breakpointp); | |
1075 | *breakpointp = NULL; | |
1076 | } | |
1077 | } | |
1078 | \f | |
b83266a0 SS |
1079 | /* This enum encodes possible reasons for doing a target_wait, so that |
1080 | wfi can call target_wait in one place. (Ultimately the call will be | |
1081 | moved out of the infinite loop entirely.) */ | |
1082 | ||
cd0fc7c3 SS |
1083 | enum infwait_states { |
1084 | infwait_normal_state, | |
1085 | infwait_thread_hop_state, | |
1086 | infwait_nullified_state, | |
1087 | infwait_nonstep_watch_state | |
b83266a0 SS |
1088 | }; |
1089 | ||
cd0fc7c3 SS |
1090 | /* This structure contains what used to be local variables in |
1091 | wait_for_inferior. Probably many of them can return to being | |
1092 | locals in handle_inferior_event. */ | |
1093 | ||
1094 | struct execution_control_state { | |
1095 | struct target_waitstatus ws; | |
1096 | struct target_waitstatus *wp; | |
c906108c | 1097 | int another_trap; |
cd0fc7c3 | 1098 | int random_signal; |
c906108c SS |
1099 | CORE_ADDR stop_func_start; |
1100 | CORE_ADDR stop_func_end; | |
1101 | char *stop_func_name; | |
c906108c | 1102 | struct symtab_and_line sal; |
cd0fc7c3 | 1103 | int remove_breakpoints_on_following_step; |
c906108c SS |
1104 | int current_line; |
1105 | struct symtab *current_symtab; | |
cd0fc7c3 | 1106 | int handling_longjmp; /* FIXME */ |
c906108c SS |
1107 | int pid; |
1108 | int saved_inferior_pid; | |
cd0fc7c3 SS |
1109 | int update_step_sp; |
1110 | int stepping_through_solib_after_catch; | |
1111 | bpstat stepping_through_solib_catchpoints; | |
1112 | int enable_hw_watchpoints_after_wait; | |
1113 | int stepping_through_sigtramp; | |
c906108c | 1114 | int new_thread_event; |
b83266a0 | 1115 | struct target_waitstatus tmpstatus; |
cd0fc7c3 | 1116 | enum infwait_states infwait_state; |
b83266a0 | 1117 | int waiton_pid; |
cd0fc7c3 SS |
1118 | int wait_some_more; |
1119 | }; | |
1120 | ||
1121 | void init_execution_control_state PARAMS ((struct execution_control_state *ecs)); | |
1122 | ||
1123 | void handle_inferior_event PARAMS ((struct execution_control_state *ecs)); | |
1124 | ||
1125 | /* Wait for control to return from inferior to debugger. | |
1126 | If inferior gets a signal, we may decide to start it up again | |
1127 | instead of returning. That is why there is a loop in this function. | |
1128 | When this function actually returns it means the inferior | |
1129 | should be left stopped and GDB should read more commands. */ | |
1130 | ||
1131 | void | |
1132 | wait_for_inferior () | |
1133 | { | |
1134 | struct cleanup *old_cleanups; | |
1135 | struct execution_control_state ecss; | |
1136 | struct execution_control_state *ecs; | |
c906108c SS |
1137 | |
1138 | old_cleanups = make_cleanup (delete_breakpoint_current_contents, | |
1139 | &step_resume_breakpoint); | |
1140 | make_cleanup (delete_breakpoint_current_contents, | |
1141 | &through_sigtramp_breakpoint); | |
cd0fc7c3 SS |
1142 | |
1143 | /* wfi still stays in a loop, so it's OK just to take the address of | |
1144 | a local to get the ecs pointer. */ | |
1145 | ecs = &ecss; | |
1146 | ||
1147 | /* Fill in with reasonable starting values. */ | |
1148 | init_execution_control_state (ecs); | |
1149 | ||
c906108c SS |
1150 | thread_step_needed = 0; |
1151 | ||
c906108c | 1152 | /* We'll update this if & when we switch to a new thread. */ |
7a292a7a SS |
1153 | if (may_switch_from_inferior_pid) |
1154 | switched_from_inferior_pid = inferior_pid; | |
c906108c | 1155 | |
cd0fc7c3 SS |
1156 | overlay_cache_invalid = 1; |
1157 | ||
1158 | /* We have to invalidate the registers BEFORE calling target_wait | |
1159 | because they can be loaded from the target while in target_wait. | |
1160 | This makes remote debugging a bit more efficient for those | |
1161 | targets that provide critical registers as part of their normal | |
1162 | status mechanism. */ | |
1163 | ||
1164 | registers_changed (); | |
b83266a0 | 1165 | |
c906108c SS |
1166 | while (1) |
1167 | { | |
cd0fc7c3 SS |
1168 | if (target_wait_hook) |
1169 | ecs->pid = target_wait_hook (ecs->waiton_pid, ecs->wp); | |
1170 | else | |
1171 | ecs->pid = target_wait (ecs->waiton_pid, ecs->wp); | |
c906108c | 1172 | |
cd0fc7c3 SS |
1173 | /* Now figure out what to do with the result of the result. */ |
1174 | handle_inferior_event (ecs); | |
c906108c | 1175 | |
cd0fc7c3 SS |
1176 | if (!ecs->wait_some_more) |
1177 | break; | |
1178 | } | |
1179 | do_cleanups (old_cleanups); | |
1180 | } | |
c906108c | 1181 | |
cd0fc7c3 SS |
1182 | /* Prepare an execution control state for looping through a |
1183 | wait_for_inferior-type loop. */ | |
1184 | ||
1185 | void | |
1186 | init_execution_control_state (ecs) | |
1187 | struct execution_control_state *ecs; | |
1188 | { | |
1189 | ecs->random_signal = 0; | |
1190 | ecs->remove_breakpoints_on_following_step = 0; | |
1191 | ecs->handling_longjmp = 0; /* FIXME */ | |
1192 | ecs->update_step_sp = 0; | |
1193 | ecs->stepping_through_solib_after_catch = 0; | |
1194 | ecs->stepping_through_solib_catchpoints = NULL; | |
1195 | ecs->enable_hw_watchpoints_after_wait = 0; | |
1196 | ecs->stepping_through_sigtramp = 0; | |
1197 | ecs->sal = find_pc_line (prev_pc, 0); | |
1198 | ecs->current_line = ecs->sal.line; | |
1199 | ecs->current_symtab = ecs->sal.symtab; | |
1200 | ecs->infwait_state = infwait_normal_state; | |
1201 | ecs->waiton_pid = -1; | |
1202 | ecs->wp = &(ecs->ws); | |
1203 | } | |
1204 | ||
1205 | /* Given an execution control state that has been freshly filled in | |
1206 | by an event from the inferior, figure out what it means and take | |
1207 | appropriate action. */ | |
c906108c | 1208 | |
cd0fc7c3 SS |
1209 | void |
1210 | handle_inferior_event (ecs) | |
1211 | struct execution_control_state *ecs; | |
1212 | { | |
1213 | CORE_ADDR tmp; | |
1214 | int stepped_after_stopped_by_watchpoint; | |
1215 | ||
1216 | /* Keep this extra brace for now, minimizes diffs. */ | |
1217 | { | |
1218 | switch (ecs->infwait_state) | |
c906108c | 1219 | { |
cd0fc7c3 | 1220 | case infwait_normal_state: |
b83266a0 SS |
1221 | /* Since we've done a wait, we have a new event. Don't |
1222 | carry over any expectations about needing to step over a | |
1223 | breakpoint. */ | |
1224 | thread_step_needed = 0; | |
c906108c | 1225 | |
b83266a0 SS |
1226 | /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event |
1227 | is serviced in this loop, below. */ | |
cd0fc7c3 | 1228 | if (ecs->enable_hw_watchpoints_after_wait) |
b83266a0 SS |
1229 | { |
1230 | TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid); | |
cd0fc7c3 | 1231 | ecs->enable_hw_watchpoints_after_wait = 0; |
b83266a0 SS |
1232 | } |
1233 | stepped_after_stopped_by_watchpoint = 0; | |
1234 | break; | |
1235 | ||
cd0fc7c3 | 1236 | case infwait_thread_hop_state: |
b83266a0 | 1237 | insert_breakpoints (); |
c906108c | 1238 | |
b83266a0 SS |
1239 | /* We need to restart all the threads now, |
1240 | * unles we're running in scheduler-locked mode. | |
cd0fc7c3 | 1241 | * FIXME: shouldn't we look at currently_stepping ()? |
b83266a0 SS |
1242 | */ |
1243 | if (scheduler_mode == schedlock_on) | |
cd0fc7c3 | 1244 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); |
b83266a0 SS |
1245 | else |
1246 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
cd0fc7c3 SS |
1247 | ecs->infwait_state = infwait_normal_state; |
1248 | goto wfi_continue; | |
c906108c | 1249 | |
cd0fc7c3 | 1250 | case infwait_nullified_state: |
b83266a0 SS |
1251 | break; |
1252 | ||
cd0fc7c3 | 1253 | case infwait_nonstep_watch_state: |
b83266a0 SS |
1254 | insert_breakpoints (); |
1255 | ||
1256 | /* FIXME-maybe: is this cleaner than setting a flag? Does it | |
1257 | handle things like signals arriving and other things happening | |
1258 | in combination correctly? */ | |
1259 | stepped_after_stopped_by_watchpoint = 1; | |
1260 | break; | |
1261 | } | |
cd0fc7c3 | 1262 | ecs->infwait_state = infwait_normal_state; |
c906108c SS |
1263 | |
1264 | flush_cached_frames (); | |
1265 | ||
1266 | /* If it's a new process, add it to the thread database */ | |
1267 | ||
cd0fc7c3 | 1268 | ecs->new_thread_event = ((ecs->pid != inferior_pid) && !in_thread_list (ecs->pid)); |
c906108c | 1269 | |
cd0fc7c3 SS |
1270 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
1271 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
1272 | && ecs->new_thread_event) | |
c906108c | 1273 | { |
cd0fc7c3 | 1274 | add_thread (ecs->pid); |
c906108c | 1275 | |
cd0fc7c3 | 1276 | printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid)); |
c906108c SS |
1277 | |
1278 | #if 0 | |
1279 | /* NOTE: This block is ONLY meant to be invoked in case of a | |
1280 | "thread creation event"! If it is invoked for any other | |
1281 | sort of event (such as a new thread landing on a breakpoint), | |
1282 | the event will be discarded, which is almost certainly | |
1283 | a bad thing! | |
1284 | ||
1285 | To avoid this, the low-level module (eg. target_wait) | |
1286 | should call in_thread_list and add_thread, so that the | |
1287 | new thread is known by the time we get here. */ | |
1288 | ||
1289 | /* We may want to consider not doing a resume here in order | |
1290 | to give the user a chance to play with the new thread. | |
1291 | It might be good to make that a user-settable option. */ | |
1292 | ||
1293 | /* At this point, all threads are stopped (happens | |
1294 | automatically in either the OS or the native code). | |
1295 | Therefore we need to continue all threads in order to | |
1296 | make progress. */ | |
1297 | ||
1298 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
cd0fc7c3 | 1299 | goto wfi_continue; |
c906108c SS |
1300 | #endif |
1301 | } | |
1302 | ||
cd0fc7c3 | 1303 | switch (ecs->ws.kind) |
c906108c SS |
1304 | { |
1305 | case TARGET_WAITKIND_LOADED: | |
1306 | /* Ignore gracefully during startup of the inferior, as it | |
1307 | might be the shell which has just loaded some objects, | |
1308 | otherwise add the symbols for the newly loaded objects. */ | |
1309 | #ifdef SOLIB_ADD | |
1310 | if (!stop_soon_quietly) | |
1311 | { | |
c906108c SS |
1312 | /* Remove breakpoints, SOLIB_ADD might adjust |
1313 | breakpoint addresses via breakpoint_re_set. */ | |
1314 | if (breakpoints_inserted) | |
1315 | remove_breakpoints (); | |
1316 | ||
1317 | /* Check for any newly added shared libraries if we're | |
1318 | supposed to be adding them automatically. */ | |
1319 | if (auto_solib_add) | |
1320 | { | |
1321 | /* Switch terminal for any messages produced by | |
1322 | breakpoint_re_set. */ | |
1323 | target_terminal_ours_for_output (); | |
1324 | SOLIB_ADD (NULL, 0, NULL); | |
1325 | target_terminal_inferior (); | |
1326 | } | |
1327 | ||
1328 | /* Reinsert breakpoints and continue. */ | |
1329 | if (breakpoints_inserted) | |
1330 | insert_breakpoints (); | |
1331 | } | |
1332 | #endif | |
1333 | resume (0, TARGET_SIGNAL_0); | |
cd0fc7c3 | 1334 | goto wfi_continue; |
c906108c SS |
1335 | |
1336 | case TARGET_WAITKIND_SPURIOUS: | |
1337 | resume (0, TARGET_SIGNAL_0); | |
cd0fc7c3 | 1338 | goto wfi_continue; |
c906108c SS |
1339 | |
1340 | case TARGET_WAITKIND_EXITED: | |
1341 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
cd0fc7c3 SS |
1342 | annotate_exited (ecs->ws.value.integer); |
1343 | if (ecs->ws.value.integer) | |
c906108c | 1344 | printf_filtered ("\nProgram exited with code 0%o.\n", |
cd0fc7c3 | 1345 | (unsigned int) ecs->ws.value.integer); |
c906108c SS |
1346 | else |
1347 | printf_filtered ("\nProgram exited normally.\n"); | |
1348 | ||
1349 | /* Record the exit code in the convenience variable $_exitcode, so | |
1350 | that the user can inspect this again later. */ | |
1351 | set_internalvar (lookup_internalvar ("_exitcode"), | |
1352 | value_from_longest (builtin_type_int, | |
cd0fc7c3 | 1353 | (LONGEST) ecs->ws.value.integer)); |
c906108c SS |
1354 | gdb_flush (gdb_stdout); |
1355 | target_mourn_inferior (); | |
1356 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/ | |
1357 | stop_print_frame = 0; | |
1358 | goto stop_stepping; | |
1359 | ||
1360 | case TARGET_WAITKIND_SIGNALLED: | |
1361 | stop_print_frame = 0; | |
cd0fc7c3 | 1362 | stop_signal = ecs->ws.value.sig; |
c906108c SS |
1363 | target_terminal_ours (); /* Must do this before mourn anyway */ |
1364 | annotate_signalled (); | |
1365 | ||
1366 | /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED | |
1367 | mean it is already dead? This has been here since GDB 2.8, so | |
1368 | perhaps it means rms didn't understand unix waitstatuses? | |
1369 | For the moment I'm just kludging around this in remote.c | |
1370 | rather than trying to change it here --kingdon, 5 Dec 1994. */ | |
1371 | target_kill (); /* kill mourns as well */ | |
1372 | ||
1373 | printf_filtered ("\nProgram terminated with signal "); | |
1374 | annotate_signal_name (); | |
1375 | printf_filtered ("%s", target_signal_to_name (stop_signal)); | |
1376 | annotate_signal_name_end (); | |
1377 | printf_filtered (", "); | |
1378 | annotate_signal_string (); | |
1379 | printf_filtered ("%s", target_signal_to_string (stop_signal)); | |
1380 | annotate_signal_string_end (); | |
1381 | printf_filtered (".\n"); | |
1382 | ||
1383 | printf_filtered ("The program no longer exists.\n"); | |
1384 | gdb_flush (gdb_stdout); | |
1385 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/ | |
1386 | goto stop_stepping; | |
1387 | ||
1388 | /* The following are the only cases in which we keep going; | |
1389 | the above cases end in a continue or goto. */ | |
1390 | case TARGET_WAITKIND_FORKED: | |
1391 | stop_signal = TARGET_SIGNAL_TRAP; | |
cd0fc7c3 | 1392 | pending_follow.kind = ecs->ws.kind; |
c906108c SS |
1393 | |
1394 | /* Ignore fork events reported for the parent; we're only | |
1395 | interested in reacting to forks of the child. Note that | |
1396 | we expect the child's fork event to be available if we | |
1397 | waited for it now. */ | |
cd0fc7c3 | 1398 | if (inferior_pid == ecs->pid) |
c906108c SS |
1399 | { |
1400 | pending_follow.fork_event.saw_parent_fork = 1; | |
cd0fc7c3 SS |
1401 | pending_follow.fork_event.parent_pid = ecs->pid; |
1402 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; | |
1403 | goto wfi_continue; | |
c906108c SS |
1404 | } |
1405 | else | |
1406 | { | |
1407 | pending_follow.fork_event.saw_child_fork = 1; | |
cd0fc7c3 SS |
1408 | pending_follow.fork_event.child_pid = ecs->pid; |
1409 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; | |
c906108c SS |
1410 | } |
1411 | ||
cd0fc7c3 SS |
1412 | stop_pc = read_pc_pid (ecs->pid); |
1413 | ecs->saved_inferior_pid = inferior_pid; | |
1414 | inferior_pid = ecs->pid; | |
c906108c SS |
1415 | stop_bpstat = bpstat_stop_status |
1416 | (&stop_pc, | |
7a292a7a SS |
1417 | (DECR_PC_AFTER_BREAK ? |
1418 | (prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
cd0fc7c3 | 1419 | && currently_stepping (ecs)) |
7a292a7a | 1420 | : 0) |
c906108c | 1421 | ); |
cd0fc7c3 SS |
1422 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
1423 | inferior_pid = ecs->saved_inferior_pid; | |
c906108c SS |
1424 | goto process_event_stop_test; |
1425 | ||
1426 | /* If this a platform which doesn't allow a debugger to touch a | |
1427 | vfork'd inferior until after it exec's, then we'd best keep | |
1428 | our fingers entirely off the inferior, other than continuing | |
1429 | it. This has the unfortunate side-effect that catchpoints | |
1430 | of vforks will be ignored. But since the platform doesn't | |
1431 | allow the inferior be touched at vfork time, there's really | |
1432 | little choice. */ | |
1433 | case TARGET_WAITKIND_VFORKED: | |
1434 | stop_signal = TARGET_SIGNAL_TRAP; | |
cd0fc7c3 | 1435 | pending_follow.kind = ecs->ws.kind; |
c906108c SS |
1436 | |
1437 | /* Is this a vfork of the parent? If so, then give any | |
1438 | vfork catchpoints a chance to trigger now. (It's | |
1439 | dangerous to do so if the child canot be touched until | |
1440 | it execs, and the child has not yet exec'd. We probably | |
1441 | should warn the user to that effect when the catchpoint | |
1442 | triggers...) */ | |
cd0fc7c3 | 1443 | if (ecs->pid == inferior_pid) |
c906108c SS |
1444 | { |
1445 | pending_follow.fork_event.saw_parent_fork = 1; | |
cd0fc7c3 SS |
1446 | pending_follow.fork_event.parent_pid = ecs->pid; |
1447 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; | |
c906108c SS |
1448 | } |
1449 | ||
1450 | /* If we've seen the child's vfork event but cannot really touch | |
1451 | the child until it execs, then we must continue the child now. | |
1452 | Else, give any vfork catchpoints a chance to trigger now. */ | |
1453 | else | |
1454 | { | |
1455 | pending_follow.fork_event.saw_child_fork = 1; | |
cd0fc7c3 SS |
1456 | pending_follow.fork_event.child_pid = ecs->pid; |
1457 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; | |
c906108c SS |
1458 | target_post_startup_inferior (pending_follow.fork_event.child_pid); |
1459 | follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec (); | |
1460 | if (follow_vfork_when_exec) | |
1461 | { | |
cd0fc7c3 SS |
1462 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); |
1463 | goto wfi_continue; | |
c906108c SS |
1464 | } |
1465 | } | |
1466 | ||
1467 | stop_pc = read_pc (); | |
1468 | stop_bpstat = bpstat_stop_status | |
1469 | (&stop_pc, | |
7a292a7a SS |
1470 | (DECR_PC_AFTER_BREAK ? |
1471 | (prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
cd0fc7c3 | 1472 | && currently_stepping (ecs)) |
7a292a7a SS |
1473 | : 0) |
1474 | ); | |
cd0fc7c3 | 1475 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
c906108c SS |
1476 | goto process_event_stop_test; |
1477 | ||
1478 | case TARGET_WAITKIND_EXECD: | |
1479 | stop_signal = TARGET_SIGNAL_TRAP; | |
1480 | ||
1481 | /* Is this a target which reports multiple exec events per actual | |
1482 | call to exec()? (HP-UX using ptrace does, for example.) If so, | |
1483 | ignore all but the last one. Just resume the exec'r, and wait | |
1484 | for the next exec event. */ | |
1485 | if (inferior_ignoring_leading_exec_events) | |
1486 | { | |
1487 | inferior_ignoring_leading_exec_events--; | |
1488 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
1489 | ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid); | |
cd0fc7c3 SS |
1490 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); |
1491 | goto wfi_continue; | |
c906108c SS |
1492 | } |
1493 | inferior_ignoring_leading_exec_events = | |
1494 | target_reported_exec_events_per_exec_call () - 1; | |
1495 | ||
cd0fc7c3 SS |
1496 | pending_follow.execd_pathname = savestring (ecs->ws.value.execd_pathname, |
1497 | strlen (ecs->ws.value.execd_pathname)); | |
c906108c SS |
1498 | |
1499 | /* Did inferior_pid exec, or did a (possibly not-yet-followed) | |
1500 | child of a vfork exec? | |
1501 | ||
1502 | ??rehrauer: This is unabashedly an HP-UX specific thing. On | |
1503 | HP-UX, events associated with a vforking inferior come in | |
1504 | threes: a vfork event for the child (always first), followed | |
1505 | a vfork event for the parent and an exec event for the child. | |
1506 | The latter two can come in either order. | |
1507 | ||
1508 | If we get the parent vfork event first, life's good: We follow | |
1509 | either the parent or child, and then the child's exec event is | |
1510 | a "don't care". | |
1511 | ||
1512 | But if we get the child's exec event first, then we delay | |
1513 | responding to it until we handle the parent's vfork. Because, | |
1514 | otherwise we can't satisfy a "catch vfork". */ | |
1515 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
1516 | { | |
1517 | pending_follow.fork_event.saw_child_exec = 1; | |
1518 | ||
1519 | /* On some targets, the child must be resumed before | |
1520 | the parent vfork event is delivered. A single-step | |
1521 | suffices. */ | |
1522 | if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ()) | |
cd0fc7c3 | 1523 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); |
c906108c | 1524 | /* We expect the parent vfork event to be available now. */ |
cd0fc7c3 | 1525 | goto wfi_continue; |
c906108c SS |
1526 | } |
1527 | ||
1528 | /* This causes the eventpoints and symbol table to be reset. Must | |
1529 | do this now, before trying to determine whether to stop. */ | |
1530 | follow_exec (inferior_pid, pending_follow.execd_pathname); | |
1531 | free (pending_follow.execd_pathname); | |
1532 | ||
cd0fc7c3 SS |
1533 | stop_pc = read_pc_pid (ecs->pid); |
1534 | ecs->saved_inferior_pid = inferior_pid; | |
1535 | inferior_pid = ecs->pid; | |
c906108c SS |
1536 | stop_bpstat = bpstat_stop_status |
1537 | (&stop_pc, | |
7a292a7a SS |
1538 | (DECR_PC_AFTER_BREAK ? |
1539 | (prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
cd0fc7c3 | 1540 | && currently_stepping (ecs)) |
7a292a7a SS |
1541 | : 0) |
1542 | ); | |
cd0fc7c3 SS |
1543 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
1544 | inferior_pid = ecs->saved_inferior_pid; | |
c906108c SS |
1545 | goto process_event_stop_test; |
1546 | ||
1547 | /* These syscall events are returned on HP-UX, as part of its | |
1548 | implementation of page-protection-based "hardware" watchpoints. | |
1549 | HP-UX has unfortunate interactions between page-protections and | |
1550 | some system calls. Our solution is to disable hardware watches | |
1551 | when a system call is entered, and reenable them when the syscall | |
1552 | completes. The downside of this is that we may miss the precise | |
1553 | point at which a watched piece of memory is modified. "Oh well." | |
1554 | ||
1555 | Note that we may have multiple threads running, which may each | |
1556 | enter syscalls at roughly the same time. Since we don't have a | |
1557 | good notion currently of whether a watched piece of memory is | |
1558 | thread-private, we'd best not have any page-protections active | |
1559 | when any thread is in a syscall. Thus, we only want to reenable | |
1560 | hardware watches when no threads are in a syscall. | |
1561 | ||
1562 | Also, be careful not to try to gather much state about a thread | |
1563 | that's in a syscall. It's frequently a losing proposition. */ | |
1564 | case TARGET_WAITKIND_SYSCALL_ENTRY: | |
1565 | number_of_threads_in_syscalls++; | |
1566 | if (number_of_threads_in_syscalls == 1) | |
1567 | { | |
1568 | TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid); | |
1569 | } | |
1570 | resume (0, TARGET_SIGNAL_0); | |
cd0fc7c3 | 1571 | goto wfi_continue; |
c906108c SS |
1572 | |
1573 | /* Before examining the threads further, step this thread to | |
1574 | get it entirely out of the syscall. (We get notice of the | |
1575 | event when the thread is just on the verge of exiting a | |
1576 | syscall. Stepping one instruction seems to get it back | |
1577 | into user code.) | |
1578 | ||
1579 | Note that although the logical place to reenable h/w watches | |
1580 | is here, we cannot. We cannot reenable them before stepping | |
1581 | the thread (this causes the next wait on the thread to hang). | |
1582 | ||
1583 | Nor can we enable them after stepping until we've done a wait. | |
cd0fc7c3 | 1584 | Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait |
c906108c SS |
1585 | here, which will be serviced immediately after the target |
1586 | is waited on. */ | |
1587 | case TARGET_WAITKIND_SYSCALL_RETURN: | |
cd0fc7c3 | 1588 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); |
c906108c SS |
1589 | |
1590 | if (number_of_threads_in_syscalls > 0) | |
1591 | { | |
1592 | number_of_threads_in_syscalls--; | |
cd0fc7c3 | 1593 | ecs->enable_hw_watchpoints_after_wait = |
c906108c SS |
1594 | (number_of_threads_in_syscalls == 0); |
1595 | } | |
cd0fc7c3 | 1596 | goto wfi_continue; |
c906108c SS |
1597 | |
1598 | case TARGET_WAITKIND_STOPPED: | |
cd0fc7c3 | 1599 | stop_signal = ecs->ws.value.sig; |
c906108c SS |
1600 | break; |
1601 | } | |
1602 | ||
1603 | /* We may want to consider not doing a resume here in order to give | |
1604 | the user a chance to play with the new thread. It might be good | |
1605 | to make that a user-settable option. */ | |
1606 | ||
1607 | /* At this point, all threads are stopped (happens automatically in | |
1608 | either the OS or the native code). Therefore we need to continue | |
1609 | all threads in order to make progress. */ | |
cd0fc7c3 | 1610 | if (ecs->new_thread_event) |
c906108c SS |
1611 | { |
1612 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
cd0fc7c3 | 1613 | goto wfi_continue; |
c906108c SS |
1614 | } |
1615 | ||
cd0fc7c3 | 1616 | stop_pc = read_pc_pid (ecs->pid); |
c906108c SS |
1617 | |
1618 | /* See if a thread hit a thread-specific breakpoint that was meant for | |
1619 | another thread. If so, then step that thread past the breakpoint, | |
1620 | and continue it. */ | |
1621 | ||
1622 | if (stop_signal == TARGET_SIGNAL_TRAP) | |
1623 | { | |
1624 | if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p) | |
cd0fc7c3 | 1625 | ecs->random_signal = 0; |
c906108c SS |
1626 | else if (breakpoints_inserted |
1627 | && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK)) | |
1628 | { | |
cd0fc7c3 | 1629 | ecs->random_signal = 0; |
c906108c | 1630 | if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, |
cd0fc7c3 | 1631 | ecs->pid)) |
c906108c SS |
1632 | { |
1633 | int remove_status; | |
1634 | ||
1635 | /* Saw a breakpoint, but it was hit by the wrong thread. | |
1636 | Just continue. */ | |
cd0fc7c3 | 1637 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->pid); |
c906108c SS |
1638 | |
1639 | remove_status = remove_breakpoints (); | |
1640 | /* Did we fail to remove breakpoints? If so, try | |
1641 | to set the PC past the bp. (There's at least | |
1642 | one situation in which we can fail to remove | |
1643 | the bp's: On HP-UX's that use ttrace, we can't | |
1644 | change the address space of a vforking child | |
1645 | process until the child exits (well, okay, not | |
1646 | then either :-) or execs. */ | |
1647 | if (remove_status != 0) | |
1648 | { | |
cd0fc7c3 | 1649 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->pid); |
c906108c SS |
1650 | } |
1651 | else | |
1652 | { /* Single step */ | |
cd0fc7c3 | 1653 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); |
c906108c SS |
1654 | /* FIXME: What if a signal arrives instead of the |
1655 | single-step happening? */ | |
1656 | ||
cd0fc7c3 SS |
1657 | ecs->waiton_pid = ecs->pid; |
1658 | ecs->wp = &(ecs->ws); | |
1659 | ecs->infwait_state = infwait_thread_hop_state; | |
1660 | goto wfi_continue; | |
c906108c SS |
1661 | } |
1662 | ||
7a292a7a SS |
1663 | /* We need to restart all the threads now, |
1664 | * unles we're running in scheduler-locked mode. | |
cd0fc7c3 | 1665 | * FIXME: shouldn't we look at currently_stepping ()? |
7a292a7a SS |
1666 | */ |
1667 | if (scheduler_mode == schedlock_on) | |
cd0fc7c3 | 1668 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); |
7a292a7a SS |
1669 | else |
1670 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
cd0fc7c3 | 1671 | goto wfi_continue; |
c906108c SS |
1672 | } |
1673 | else | |
1674 | { | |
1675 | /* This breakpoint matches--either it is the right | |
1676 | thread or it's a generic breakpoint for all threads. | |
1677 | Remember that we'll need to step just _this_ thread | |
1678 | on any following user continuation! */ | |
1679 | thread_step_needed = 1; | |
1680 | } | |
1681 | } | |
1682 | } | |
1683 | else | |
cd0fc7c3 | 1684 | ecs->random_signal = 1; |
c906108c SS |
1685 | |
1686 | /* See if something interesting happened to the non-current thread. If | |
1687 | so, then switch to that thread, and eventually give control back to | |
1688 | the user. | |
1689 | ||
1690 | Note that if there's any kind of pending follow (i.e., of a fork, | |
1691 | vfork or exec), we don't want to do this now. Rather, we'll let | |
1692 | the next resume handle it. */ | |
cd0fc7c3 | 1693 | if ((ecs->pid != inferior_pid) && |
c906108c SS |
1694 | (pending_follow.kind == TARGET_WAITKIND_SPURIOUS)) |
1695 | { | |
1696 | int printed = 0; | |
1697 | ||
1698 | /* If it's a random signal for a non-current thread, notify user | |
1699 | if he's expressed an interest. */ | |
cd0fc7c3 | 1700 | if (ecs->random_signal |
c906108c SS |
1701 | && signal_print[stop_signal]) |
1702 | { | |
1703 | /* ??rehrauer: I don't understand the rationale for this code. If the | |
1704 | inferior will stop as a result of this signal, then the act of handling | |
1705 | the stop ought to print a message that's couches the stoppage in user | |
1706 | terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior | |
1707 | won't stop as a result of the signal -- i.e., if the signal is merely | |
1708 | a side-effect of something GDB's doing "under the covers" for the | |
1709 | user, such as stepping threads over a breakpoint they shouldn't stop | |
1710 | for -- then the message seems to be a serious annoyance at best. | |
1711 | ||
1712 | For now, remove the message altogether. */ | |
1713 | #if 0 | |
1714 | printed = 1; | |
1715 | target_terminal_ours_for_output (); | |
1716 | printf_filtered ("\nProgram received signal %s, %s.\n", | |
1717 | target_signal_to_name (stop_signal), | |
1718 | target_signal_to_string (stop_signal)); | |
1719 | gdb_flush (gdb_stdout); | |
1720 | #endif | |
1721 | } | |
1722 | ||
1723 | /* If it's not SIGTRAP and not a signal we want to stop for, then | |
1724 | continue the thread. */ | |
1725 | ||
1726 | if (stop_signal != TARGET_SIGNAL_TRAP | |
1727 | && !signal_stop[stop_signal]) | |
1728 | { | |
1729 | if (printed) | |
1730 | target_terminal_inferior (); | |
1731 | ||
1732 | /* Clear the signal if it should not be passed. */ | |
1733 | if (signal_program[stop_signal] == 0) | |
1734 | stop_signal = TARGET_SIGNAL_0; | |
1735 | ||
cd0fc7c3 SS |
1736 | target_resume (ecs->pid, 0, stop_signal); |
1737 | goto wfi_continue; | |
c906108c SS |
1738 | } |
1739 | ||
1740 | /* It's a SIGTRAP or a signal we're interested in. Switch threads, | |
1741 | and fall into the rest of wait_for_inferior(). */ | |
1742 | ||
1743 | /* Save infrun state for the old thread. */ | |
1744 | save_infrun_state (inferior_pid, prev_pc, | |
1745 | prev_func_start, prev_func_name, | |
1746 | trap_expected, step_resume_breakpoint, | |
1747 | through_sigtramp_breakpoint, | |
1748 | step_range_start, step_range_end, | |
cd0fc7c3 SS |
1749 | step_frame_address, ecs->handling_longjmp, |
1750 | ecs->another_trap, | |
1751 | ecs->stepping_through_solib_after_catch, | |
1752 | ecs->stepping_through_solib_catchpoints, | |
1753 | ecs->stepping_through_sigtramp); | |
c906108c | 1754 | |
7a292a7a SS |
1755 | if (may_switch_from_inferior_pid) |
1756 | switched_from_inferior_pid = inferior_pid; | |
c906108c | 1757 | |
cd0fc7c3 | 1758 | inferior_pid = ecs->pid; |
c906108c SS |
1759 | |
1760 | /* Load infrun state for the new thread. */ | |
1761 | load_infrun_state (inferior_pid, &prev_pc, | |
1762 | &prev_func_start, &prev_func_name, | |
1763 | &trap_expected, &step_resume_breakpoint, | |
1764 | &through_sigtramp_breakpoint, | |
1765 | &step_range_start, &step_range_end, | |
cd0fc7c3 SS |
1766 | &step_frame_address, &ecs->handling_longjmp, |
1767 | &ecs->another_trap, | |
1768 | &ecs->stepping_through_solib_after_catch, | |
1769 | &ecs->stepping_through_solib_catchpoints, | |
1770 | &ecs->stepping_through_sigtramp); | |
c906108c SS |
1771 | |
1772 | if (context_hook) | |
cd0fc7c3 | 1773 | context_hook (pid_to_thread_id (ecs->pid)); |
c906108c | 1774 | |
cd0fc7c3 | 1775 | printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs->pid)); |
c906108c SS |
1776 | flush_cached_frames (); |
1777 | } | |
1778 | ||
1779 | if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p) | |
1780 | { | |
1781 | /* Pull the single step breakpoints out of the target. */ | |
1782 | SOFTWARE_SINGLE_STEP (0, 0); | |
1783 | singlestep_breakpoints_inserted_p = 0; | |
1784 | } | |
1785 | ||
1786 | /* If PC is pointing at a nullified instruction, then step beyond | |
1787 | it so that the user won't be confused when GDB appears to be ready | |
1788 | to execute it. */ | |
1789 | ||
cd0fc7c3 | 1790 | /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */ |
c906108c SS |
1791 | if (INSTRUCTION_NULLIFIED) |
1792 | { | |
c906108c | 1793 | registers_changed (); |
cd0fc7c3 | 1794 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); |
c906108c SS |
1795 | |
1796 | /* We may have received a signal that we want to pass to | |
1797 | the inferior; therefore, we must not clobber the waitstatus | |
cd0fc7c3 | 1798 | in WS. */ |
c906108c | 1799 | |
cd0fc7c3 SS |
1800 | ecs->infwait_state = infwait_nullified_state; |
1801 | ecs->waiton_pid = ecs->pid; | |
1802 | ecs->wp = &(ecs->tmpstatus); | |
1803 | goto wfi_continue; | |
c906108c SS |
1804 | } |
1805 | ||
c906108c SS |
1806 | /* It may not be necessary to disable the watchpoint to stop over |
1807 | it. For example, the PA can (with some kernel cooperation) | |
1808 | single step over a watchpoint without disabling the watchpoint. */ | |
cd0fc7c3 | 1809 | if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) |
c906108c SS |
1810 | { |
1811 | resume (1, 0); | |
cd0fc7c3 | 1812 | goto wfi_continue; |
c906108c | 1813 | } |
c906108c | 1814 | |
7a292a7a SS |
1815 | /* It is far more common to need to disable a watchpoint to step |
1816 | the inferior over it. FIXME. What else might a debug | |
1817 | register or page protection watchpoint scheme need here? */ | |
cd0fc7c3 | 1818 | if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) |
c906108c | 1819 | { |
7a292a7a SS |
1820 | /* At this point, we are stopped at an instruction which has |
1821 | attempted to write to a piece of memory under control of | |
1822 | a watchpoint. The instruction hasn't actually executed | |
1823 | yet. If we were to evaluate the watchpoint expression | |
1824 | now, we would get the old value, and therefore no change | |
1825 | would seem to have occurred. | |
1826 | ||
1827 | In order to make watchpoints work `right', we really need | |
1828 | to complete the memory write, and then evaluate the | |
1829 | watchpoint expression. The following code does that by | |
1830 | removing the watchpoint (actually, all watchpoints and | |
1831 | breakpoints), single-stepping the target, re-inserting | |
1832 | watchpoints, and then falling through to let normal | |
1833 | single-step processing handle proceed. Since this | |
1834 | includes evaluating watchpoints, things will come to a | |
1835 | stop in the correct manner. */ | |
c906108c SS |
1836 | |
1837 | write_pc (stop_pc - DECR_PC_AFTER_BREAK); | |
1838 | ||
1839 | remove_breakpoints (); | |
1840 | registers_changed (); | |
cd0fc7c3 | 1841 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); /* Single step */ |
c906108c | 1842 | |
cd0fc7c3 SS |
1843 | ecs->waiton_pid = ecs->pid; |
1844 | ecs->wp = &(ecs->ws); | |
1845 | ecs->infwait_state = infwait_nonstep_watch_state; | |
1846 | goto wfi_continue; | |
c906108c | 1847 | } |
c906108c | 1848 | |
c906108c | 1849 | /* It may be possible to simply continue after a watchpoint. */ |
7a292a7a | 1850 | if (HAVE_CONTINUABLE_WATCHPOINT) |
cd0fc7c3 | 1851 | STOPPED_BY_WATCHPOINT (ecs->ws); |
c906108c | 1852 | |
cd0fc7c3 SS |
1853 | ecs->stop_func_start = 0; |
1854 | ecs->stop_func_end = 0; | |
1855 | ecs->stop_func_name = 0; | |
c906108c SS |
1856 | /* Don't care about return value; stop_func_start and stop_func_name |
1857 | will both be 0 if it doesn't work. */ | |
cd0fc7c3 SS |
1858 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, |
1859 | &ecs->stop_func_start, &ecs->stop_func_end); | |
1860 | ecs->stop_func_start += FUNCTION_START_OFFSET; | |
1861 | ecs->another_trap = 0; | |
c906108c SS |
1862 | bpstat_clear (&stop_bpstat); |
1863 | stop_step = 0; | |
1864 | stop_stack_dummy = 0; | |
1865 | stop_print_frame = 1; | |
cd0fc7c3 | 1866 | ecs->random_signal = 0; |
c906108c SS |
1867 | stopped_by_random_signal = 0; |
1868 | breakpoints_failed = 0; | |
1869 | ||
1870 | /* Look at the cause of the stop, and decide what to do. | |
1871 | The alternatives are: | |
1872 | 1) break; to really stop and return to the debugger, | |
1873 | 2) drop through to start up again | |
cd0fc7c3 SS |
1874 | (set ecs->another_trap to 1 to single step once) |
1875 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 | |
c906108c SS |
1876 | will be made according to the signal handling tables. */ |
1877 | ||
1878 | /* First, distinguish signals caused by the debugger from signals | |
1879 | that have to do with the program's own actions. | |
1880 | Note that breakpoint insns may cause SIGTRAP or SIGILL | |
1881 | or SIGEMT, depending on the operating system version. | |
1882 | Here we detect when a SIGILL or SIGEMT is really a breakpoint | |
1883 | and change it to SIGTRAP. */ | |
1884 | ||
1885 | if (stop_signal == TARGET_SIGNAL_TRAP | |
1886 | || (breakpoints_inserted && | |
1887 | (stop_signal == TARGET_SIGNAL_ILL | |
1888 | || stop_signal == TARGET_SIGNAL_EMT | |
1889 | )) | |
1890 | || stop_soon_quietly) | |
1891 | { | |
1892 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) | |
1893 | { | |
1894 | stop_print_frame = 0; | |
cd0fc7c3 | 1895 | goto wfi_break; |
c906108c SS |
1896 | } |
1897 | if (stop_soon_quietly) | |
cd0fc7c3 | 1898 | goto wfi_break; |
c906108c SS |
1899 | |
1900 | /* Don't even think about breakpoints | |
1901 | if just proceeded over a breakpoint. | |
1902 | ||
1903 | However, if we are trying to proceed over a breakpoint | |
1904 | and end up in sigtramp, then through_sigtramp_breakpoint | |
1905 | will be set and we should check whether we've hit the | |
1906 | step breakpoint. */ | |
1907 | if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected | |
1908 | && through_sigtramp_breakpoint == NULL) | |
1909 | bpstat_clear (&stop_bpstat); | |
1910 | else | |
1911 | { | |
1912 | /* See if there is a breakpoint at the current PC. */ | |
1913 | stop_bpstat = bpstat_stop_status | |
1914 | (&stop_pc, | |
1915 | (DECR_PC_AFTER_BREAK ? | |
1916 | /* Notice the case of stepping through a jump | |
1917 | that lands just after a breakpoint. | |
1918 | Don't confuse that with hitting the breakpoint. | |
1919 | What we check for is that 1) stepping is going on | |
1920 | and 2) the pc before the last insn does not match | |
1921 | the address of the breakpoint before the current pc | |
1922 | and 3) we didn't hit a breakpoint in a signal handler | |
1923 | without an intervening stop in sigtramp, which is | |
1924 | detected by a new stack pointer value below | |
1925 | any usual function calling stack adjustments. */ | |
cd0fc7c3 | 1926 | (currently_stepping (ecs) |
c906108c SS |
1927 | && prev_pc != stop_pc - DECR_PC_AFTER_BREAK |
1928 | && !(step_range_end | |
1929 | && INNER_THAN (read_sp (), (step_sp - 16)))) : | |
1930 | 0) | |
1931 | ); | |
1932 | /* Following in case break condition called a | |
1933 | function. */ | |
1934 | stop_print_frame = 1; | |
1935 | } | |
1936 | ||
1937 | if (stop_signal == TARGET_SIGNAL_TRAP) | |
cd0fc7c3 | 1938 | ecs->random_signal |
c906108c SS |
1939 | = !(bpstat_explains_signal (stop_bpstat) |
1940 | || trap_expected | |
7a292a7a SS |
1941 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P |
1942 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), | |
1943 | FRAME_FP (get_current_frame ()))) | |
c906108c SS |
1944 | || (step_range_end && step_resume_breakpoint == NULL)); |
1945 | ||
1946 | else | |
1947 | { | |
cd0fc7c3 | 1948 | ecs->random_signal |
c906108c | 1949 | = !(bpstat_explains_signal (stop_bpstat) |
7a292a7a SS |
1950 | /* End of a stack dummy. Some systems (e.g. Sony |
1951 | news) give another signal besides SIGTRAP, so | |
1952 | check here as well as above. */ | |
1953 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P | |
1954 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), | |
1955 | FRAME_FP (get_current_frame ()))) | |
c906108c | 1956 | ); |
cd0fc7c3 | 1957 | if (!ecs->random_signal) |
c906108c SS |
1958 | stop_signal = TARGET_SIGNAL_TRAP; |
1959 | } | |
1960 | } | |
1961 | ||
1962 | /* When we reach this point, we've pretty much decided | |
1963 | that the reason for stopping must've been a random | |
1964 | (unexpected) signal. */ | |
1965 | ||
1966 | else | |
cd0fc7c3 | 1967 | ecs->random_signal = 1; |
c906108c SS |
1968 | /* If a fork, vfork or exec event was seen, then there are two |
1969 | possible responses we can make: | |
1970 | ||
cd0fc7c3 | 1971 | 1. If a catchpoint triggers for the event (ecs->random_signal == 0), |
c906108c SS |
1972 | then we must stop now and issue a prompt. We will resume |
1973 | the inferior when the user tells us to. | |
cd0fc7c3 | 1974 | 2. If no catchpoint triggers for the event (ecs->random_signal == 1), |
c906108c SS |
1975 | then we must resume the inferior now and keep checking. |
1976 | ||
1977 | In either case, we must take appropriate steps to "follow" the | |
1978 | the fork/vfork/exec when the inferior is resumed. For example, | |
1979 | if follow-fork-mode is "child", then we must detach from the | |
1980 | parent inferior and follow the new child inferior. | |
1981 | ||
1982 | In either case, setting pending_follow causes the next resume() | |
1983 | to take the appropriate following action. */ | |
1984 | process_event_stop_test: | |
cd0fc7c3 | 1985 | if (ecs->ws.kind == TARGET_WAITKIND_FORKED) |
c906108c | 1986 | { |
cd0fc7c3 | 1987 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ |
c906108c SS |
1988 | { |
1989 | trap_expected = 1; | |
1990 | stop_signal = TARGET_SIGNAL_0; | |
1991 | goto keep_going; | |
1992 | } | |
1993 | } | |
cd0fc7c3 | 1994 | else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED) |
c906108c | 1995 | { |
cd0fc7c3 | 1996 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ |
c906108c SS |
1997 | { |
1998 | stop_signal = TARGET_SIGNAL_0; | |
1999 | goto keep_going; | |
2000 | } | |
2001 | } | |
cd0fc7c3 | 2002 | else if (ecs->ws.kind == TARGET_WAITKIND_EXECD) |
c906108c | 2003 | { |
cd0fc7c3 SS |
2004 | pending_follow.kind = ecs->ws.kind; |
2005 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ | |
c906108c SS |
2006 | { |
2007 | trap_expected = 1; | |
2008 | stop_signal = TARGET_SIGNAL_0; | |
2009 | goto keep_going; | |
2010 | } | |
2011 | } | |
2012 | ||
2013 | /* For the program's own signals, act according to | |
2014 | the signal handling tables. */ | |
2015 | ||
cd0fc7c3 | 2016 | if (ecs->random_signal) |
c906108c SS |
2017 | { |
2018 | /* Signal not for debugging purposes. */ | |
2019 | int printed = 0; | |
2020 | ||
2021 | stopped_by_random_signal = 1; | |
2022 | ||
2023 | if (signal_print[stop_signal]) | |
2024 | { | |
2025 | printed = 1; | |
2026 | target_terminal_ours_for_output (); | |
2027 | annotate_signal (); | |
2028 | printf_filtered ("\nProgram received signal "); | |
2029 | annotate_signal_name (); | |
2030 | printf_filtered ("%s", target_signal_to_name (stop_signal)); | |
2031 | annotate_signal_name_end (); | |
2032 | printf_filtered (", "); | |
2033 | annotate_signal_string (); | |
2034 | printf_filtered ("%s", target_signal_to_string (stop_signal)); | |
2035 | annotate_signal_string_end (); | |
2036 | printf_filtered (".\n"); | |
2037 | gdb_flush (gdb_stdout); | |
2038 | } | |
2039 | if (signal_stop[stop_signal]) | |
cd0fc7c3 | 2040 | goto wfi_break; |
c906108c SS |
2041 | /* If not going to stop, give terminal back |
2042 | if we took it away. */ | |
2043 | else if (printed) | |
2044 | target_terminal_inferior (); | |
2045 | ||
2046 | /* Clear the signal if it should not be passed. */ | |
2047 | if (signal_program[stop_signal] == 0) | |
2048 | stop_signal = TARGET_SIGNAL_0; | |
2049 | ||
2050 | /* If we're in the middle of a "next" command, let the code for | |
2051 | stepping over a function handle this. pai/1997-09-10 | |
2052 | ||
2053 | A previous comment here suggested it was possible to change | |
2054 | this to jump to keep_going in all cases. */ | |
2055 | ||
2056 | if (step_over_calls > 0) | |
2057 | goto step_over_function; | |
2058 | else | |
2059 | goto check_sigtramp2; | |
2060 | } | |
2061 | ||
2062 | /* Handle cases caused by hitting a breakpoint. */ | |
2063 | { | |
2064 | CORE_ADDR jmp_buf_pc; | |
2065 | struct bpstat_what what; | |
2066 | ||
2067 | what = bpstat_what (stop_bpstat); | |
2068 | ||
2069 | if (what.call_dummy) | |
2070 | { | |
2071 | stop_stack_dummy = 1; | |
2072 | #ifdef HP_OS_BUG | |
2073 | trap_expected_after_continue = 1; | |
2074 | #endif | |
2075 | } | |
2076 | ||
2077 | switch (what.main_action) | |
2078 | { | |
2079 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: | |
2080 | /* If we hit the breakpoint at longjmp, disable it for the | |
2081 | duration of this command. Then, install a temporary | |
2082 | breakpoint at the target of the jmp_buf. */ | |
2083 | disable_longjmp_breakpoint (); | |
2084 | remove_breakpoints (); | |
2085 | breakpoints_inserted = 0; | |
2086 | if (!GET_LONGJMP_TARGET (&jmp_buf_pc)) | |
2087 | goto keep_going; | |
2088 | ||
2089 | /* Need to blow away step-resume breakpoint, as it | |
2090 | interferes with us */ | |
2091 | if (step_resume_breakpoint != NULL) | |
2092 | { | |
2093 | delete_breakpoint (step_resume_breakpoint); | |
2094 | step_resume_breakpoint = NULL; | |
2095 | } | |
2096 | /* Not sure whether we need to blow this away too, but probably | |
2097 | it is like the step-resume breakpoint. */ | |
2098 | if (through_sigtramp_breakpoint != NULL) | |
2099 | { | |
2100 | delete_breakpoint (through_sigtramp_breakpoint); | |
2101 | through_sigtramp_breakpoint = NULL; | |
2102 | } | |
2103 | ||
2104 | #if 0 | |
2105 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2106 | if (step_over_calls > 0) | |
2107 | set_longjmp_resume_breakpoint (jmp_buf_pc, | |
2108 | get_current_frame ()); | |
2109 | else | |
2110 | #endif /* 0 */ | |
2111 | set_longjmp_resume_breakpoint (jmp_buf_pc, NULL); | |
cd0fc7c3 | 2112 | ecs->handling_longjmp = 1; /* FIXME */ |
c906108c SS |
2113 | goto keep_going; |
2114 | ||
2115 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: | |
2116 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: | |
2117 | remove_breakpoints (); | |
2118 | breakpoints_inserted = 0; | |
2119 | #if 0 | |
2120 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2121 | if (step_over_calls | |
2122 | && (INNER_THAN (FRAME_FP (get_current_frame ()), | |
2123 | step_frame_address))) | |
2124 | { | |
cd0fc7c3 | 2125 | ecs->another_trap = 1; |
c906108c SS |
2126 | goto keep_going; |
2127 | } | |
2128 | #endif /* 0 */ | |
2129 | disable_longjmp_breakpoint (); | |
cd0fc7c3 | 2130 | ecs->handling_longjmp = 0; /* FIXME */ |
c906108c SS |
2131 | if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) |
2132 | break; | |
2133 | /* else fallthrough */ | |
2134 | ||
2135 | case BPSTAT_WHAT_SINGLE: | |
2136 | if (breakpoints_inserted) | |
2137 | { | |
2138 | thread_step_needed = 1; | |
2139 | remove_breakpoints (); | |
2140 | } | |
2141 | breakpoints_inserted = 0; | |
cd0fc7c3 | 2142 | ecs->another_trap = 1; |
c906108c SS |
2143 | /* Still need to check other stuff, at least the case |
2144 | where we are stepping and step out of the right range. */ | |
2145 | break; | |
2146 | ||
2147 | case BPSTAT_WHAT_STOP_NOISY: | |
2148 | stop_print_frame = 1; | |
2149 | ||
2150 | /* We are about to nuke the step_resume_breakpoint and | |
2151 | through_sigtramp_breakpoint via the cleanup chain, so | |
2152 | no need to worry about it here. */ | |
2153 | ||
2154 | goto stop_stepping; | |
2155 | ||
2156 | case BPSTAT_WHAT_STOP_SILENT: | |
2157 | stop_print_frame = 0; | |
2158 | ||
2159 | /* We are about to nuke the step_resume_breakpoint and | |
2160 | through_sigtramp_breakpoint via the cleanup chain, so | |
2161 | no need to worry about it here. */ | |
2162 | ||
2163 | goto stop_stepping; | |
2164 | ||
2165 | case BPSTAT_WHAT_STEP_RESUME: | |
2166 | /* This proably demands a more elegant solution, but, yeah | |
2167 | right... | |
2168 | ||
2169 | This function's use of the simple variable | |
2170 | step_resume_breakpoint doesn't seem to accomodate | |
2171 | simultaneously active step-resume bp's, although the | |
2172 | breakpoint list certainly can. | |
2173 | ||
2174 | If we reach here and step_resume_breakpoint is already | |
2175 | NULL, then apparently we have multiple active | |
2176 | step-resume bp's. We'll just delete the breakpoint we | |
2177 | stopped at, and carry on. */ | |
2178 | if (step_resume_breakpoint == NULL) | |
2179 | { | |
2180 | step_resume_breakpoint = | |
2181 | bpstat_find_step_resume_breakpoint (stop_bpstat); | |
2182 | } | |
2183 | delete_breakpoint (step_resume_breakpoint); | |
2184 | step_resume_breakpoint = NULL; | |
2185 | break; | |
2186 | ||
2187 | case BPSTAT_WHAT_THROUGH_SIGTRAMP: | |
2188 | if (through_sigtramp_breakpoint) | |
2189 | delete_breakpoint (through_sigtramp_breakpoint); | |
2190 | through_sigtramp_breakpoint = NULL; | |
2191 | ||
2192 | /* If were waiting for a trap, hitting the step_resume_break | |
2193 | doesn't count as getting it. */ | |
2194 | if (trap_expected) | |
cd0fc7c3 | 2195 | ecs->another_trap = 1; |
c906108c SS |
2196 | break; |
2197 | ||
2198 | case BPSTAT_WHAT_CHECK_SHLIBS: | |
2199 | case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: | |
2200 | #ifdef SOLIB_ADD | |
2201 | { | |
c906108c SS |
2202 | /* Remove breakpoints, we eventually want to step over the |
2203 | shlib event breakpoint, and SOLIB_ADD might adjust | |
2204 | breakpoint addresses via breakpoint_re_set. */ | |
2205 | if (breakpoints_inserted) | |
2206 | remove_breakpoints (); | |
2207 | breakpoints_inserted = 0; | |
2208 | ||
2209 | /* Check for any newly added shared libraries if we're | |
2210 | supposed to be adding them automatically. */ | |
2211 | if (auto_solib_add) | |
2212 | { | |
2213 | /* Switch terminal for any messages produced by | |
2214 | breakpoint_re_set. */ | |
2215 | target_terminal_ours_for_output (); | |
2216 | SOLIB_ADD (NULL, 0, NULL); | |
2217 | target_terminal_inferior (); | |
2218 | } | |
2219 | ||
2220 | /* Try to reenable shared library breakpoints, additional | |
2221 | code segments in shared libraries might be mapped in now. */ | |
2222 | re_enable_breakpoints_in_shlibs (); | |
2223 | ||
2224 | /* If requested, stop when the dynamic linker notifies | |
2225 | gdb of events. This allows the user to get control | |
2226 | and place breakpoints in initializer routines for | |
2227 | dynamically loaded objects (among other things). */ | |
2228 | if (stop_on_solib_events) | |
2229 | { | |
2230 | stop_print_frame = 0; | |
2231 | goto stop_stepping; | |
2232 | } | |
2233 | ||
2234 | /* If we stopped due to an explicit catchpoint, then the | |
2235 | (see above) call to SOLIB_ADD pulled in any symbols | |
2236 | from a newly-loaded library, if appropriate. | |
2237 | ||
2238 | We do want the inferior to stop, but not where it is | |
2239 | now, which is in the dynamic linker callback. Rather, | |
2240 | we would like it stop in the user's program, just after | |
2241 | the call that caused this catchpoint to trigger. That | |
2242 | gives the user a more useful vantage from which to | |
2243 | examine their program's state. */ | |
2244 | else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) | |
2245 | { | |
2246 | /* ??rehrauer: If I could figure out how to get the | |
2247 | right return PC from here, we could just set a temp | |
2248 | breakpoint and resume. I'm not sure we can without | |
2249 | cracking open the dld's shared libraries and sniffing | |
2250 | their unwind tables and text/data ranges, and that's | |
2251 | not a terribly portable notion. | |
2252 | ||
2253 | Until that time, we must step the inferior out of the | |
2254 | dld callback, and also out of the dld itself (and any | |
2255 | code or stubs in libdld.sl, such as "shl_load" and | |
2256 | friends) until we reach non-dld code. At that point, | |
2257 | we can stop stepping. */ | |
2258 | bpstat_get_triggered_catchpoints (stop_bpstat, | |
cd0fc7c3 SS |
2259 | &ecs->stepping_through_solib_catchpoints); |
2260 | ecs->stepping_through_solib_after_catch = 1; | |
c906108c SS |
2261 | |
2262 | /* Be sure to lift all breakpoints, so the inferior does | |
2263 | actually step past this point... */ | |
cd0fc7c3 | 2264 | ecs->another_trap = 1; |
c906108c SS |
2265 | break; |
2266 | } | |
2267 | else | |
2268 | { | |
2269 | /* We want to step over this breakpoint, then keep going. */ | |
cd0fc7c3 | 2270 | ecs->another_trap = 1; |
c906108c SS |
2271 | break; |
2272 | } | |
2273 | } | |
2274 | #endif | |
2275 | break; | |
2276 | ||
2277 | case BPSTAT_WHAT_LAST: | |
2278 | /* Not a real code, but listed here to shut up gcc -Wall. */ | |
2279 | ||
2280 | case BPSTAT_WHAT_KEEP_CHECKING: | |
2281 | break; | |
2282 | } | |
2283 | } | |
2284 | ||
2285 | /* We come here if we hit a breakpoint but should not | |
2286 | stop for it. Possibly we also were stepping | |
2287 | and should stop for that. So fall through and | |
2288 | test for stepping. But, if not stepping, | |
2289 | do not stop. */ | |
2290 | ||
2291 | /* Are we stepping to get the inferior out of the dynamic | |
2292 | linker's hook (and possibly the dld itself) after catching | |
2293 | a shlib event? */ | |
cd0fc7c3 | 2294 | if (ecs->stepping_through_solib_after_catch) |
c906108c SS |
2295 | { |
2296 | #if defined(SOLIB_ADD) | |
2297 | /* Have we reached our destination? If not, keep going. */ | |
cd0fc7c3 | 2298 | if (SOLIB_IN_DYNAMIC_LINKER (ecs->pid, stop_pc)) |
c906108c | 2299 | { |
cd0fc7c3 | 2300 | ecs->another_trap = 1; |
c906108c SS |
2301 | goto keep_going; |
2302 | } | |
2303 | #endif | |
2304 | /* Else, stop and report the catchpoint(s) whose triggering | |
2305 | caused us to begin stepping. */ | |
cd0fc7c3 | 2306 | ecs->stepping_through_solib_after_catch = 0; |
c906108c | 2307 | bpstat_clear (&stop_bpstat); |
cd0fc7c3 SS |
2308 | stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); |
2309 | bpstat_clear (&ecs->stepping_through_solib_catchpoints); | |
c906108c SS |
2310 | stop_print_frame = 1; |
2311 | goto stop_stepping; | |
2312 | } | |
2313 | ||
7a292a7a | 2314 | if (!CALL_DUMMY_BREAKPOINT_OFFSET_P) |
c906108c | 2315 | { |
7a292a7a SS |
2316 | /* This is the old way of detecting the end of the stack dummy. |
2317 | An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets | |
2318 | handled above. As soon as we can test it on all of them, all | |
2319 | architectures should define it. */ | |
2320 | ||
2321 | /* If this is the breakpoint at the end of a stack dummy, | |
2322 | just stop silently, unless the user was doing an si/ni, in which | |
2323 | case she'd better know what she's doing. */ | |
2324 | ||
2325 | if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (), | |
2326 | FRAME_FP (get_current_frame ())) | |
2327 | && !step_range_end) | |
2328 | { | |
2329 | stop_print_frame = 0; | |
2330 | stop_stack_dummy = 1; | |
c906108c | 2331 | #ifdef HP_OS_BUG |
7a292a7a | 2332 | trap_expected_after_continue = 1; |
c906108c | 2333 | #endif |
cd0fc7c3 | 2334 | goto wfi_break; |
7a292a7a | 2335 | } |
c906108c | 2336 | } |
7a292a7a | 2337 | |
c906108c SS |
2338 | if (step_resume_breakpoint) |
2339 | /* Having a step-resume breakpoint overrides anything | |
2340 | else having to do with stepping commands until | |
2341 | that breakpoint is reached. */ | |
2342 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2343 | whether it could/should be keep_going. */ | |
2344 | goto check_sigtramp2; | |
7a292a7a | 2345 | |
c906108c SS |
2346 | if (step_range_end == 0) |
2347 | /* Likewise if we aren't even stepping. */ | |
2348 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2349 | whether it could/should be keep_going. */ | |
2350 | goto check_sigtramp2; | |
7a292a7a | 2351 | |
c906108c | 2352 | /* If stepping through a line, keep going if still within it. |
7a292a7a | 2353 | |
c906108c SS |
2354 | Note that step_range_end is the address of the first instruction |
2355 | beyond the step range, and NOT the address of the last instruction | |
2356 | within it! */ | |
2357 | if (stop_pc >= step_range_start | |
7a292a7a | 2358 | && stop_pc < step_range_end) |
c906108c SS |
2359 | { |
2360 | /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. | |
2361 | So definately need to check for sigtramp here. */ | |
2362 | goto check_sigtramp2; | |
2363 | } | |
2364 | ||
2365 | /* We stepped out of the stepping range. */ | |
2366 | ||
2367 | /* If we are stepping at the source level and entered the runtime | |
2368 | loader dynamic symbol resolution code, we keep on single stepping | |
2369 | until we exit the run time loader code and reach the callee's | |
2370 | address. */ | |
2371 | if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc)) | |
2372 | goto keep_going; | |
2373 | ||
2374 | /* We can't update step_sp every time through the loop, because | |
2375 | reading the stack pointer would slow down stepping too much. | |
2376 | But we can update it every time we leave the step range. */ | |
cd0fc7c3 | 2377 | ecs->update_step_sp = 1; |
c906108c SS |
2378 | |
2379 | /* Did we just take a signal? */ | |
cd0fc7c3 | 2380 | if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name) |
c906108c SS |
2381 | && !IN_SIGTRAMP (prev_pc, prev_func_name) |
2382 | && INNER_THAN (read_sp (), step_sp)) | |
2383 | { | |
2384 | /* We've just taken a signal; go until we are back to | |
2385 | the point where we took it and one more. */ | |
2386 | ||
2387 | /* Note: The test above succeeds not only when we stepped | |
2388 | into a signal handler, but also when we step past the last | |
2389 | statement of a signal handler and end up in the return stub | |
2390 | of the signal handler trampoline. To distinguish between | |
2391 | these two cases, check that the frame is INNER_THAN the | |
2392 | previous one below. pai/1997-09-11 */ | |
2393 | ||
2394 | ||
2395 | { | |
2396 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); | |
2397 | ||
2398 | if (INNER_THAN (current_frame, step_frame_address)) | |
2399 | { | |
2400 | /* We have just taken a signal; go until we are back to | |
2401 | the point where we took it and one more. */ | |
2402 | ||
2403 | /* This code is needed at least in the following case: | |
2404 | The user types "next" and then a signal arrives (before | |
2405 | the "next" is done). */ | |
2406 | ||
2407 | /* Note that if we are stopped at a breakpoint, then we need | |
2408 | the step_resume breakpoint to override any breakpoints at | |
2409 | the same location, so that we will still step over the | |
2410 | breakpoint even though the signal happened. */ | |
2411 | struct symtab_and_line sr_sal; | |
2412 | ||
2413 | INIT_SAL (&sr_sal); | |
2414 | sr_sal.symtab = NULL; | |
2415 | sr_sal.line = 0; | |
2416 | sr_sal.pc = prev_pc; | |
2417 | /* We could probably be setting the frame to | |
2418 | step_frame_address; I don't think anyone thought to | |
2419 | try it. */ | |
2420 | step_resume_breakpoint = | |
2421 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2422 | if (breakpoints_inserted) | |
2423 | insert_breakpoints (); | |
2424 | } | |
2425 | else | |
2426 | { | |
2427 | /* We just stepped out of a signal handler and into | |
2428 | its calling trampoline. | |
2429 | ||
2430 | Normally, we'd jump to step_over_function from | |
2431 | here, but for some reason GDB can't unwind the | |
2432 | stack correctly to find the real PC for the point | |
2433 | user code where the signal trampoline will return | |
2434 | -- FRAME_SAVED_PC fails, at least on HP-UX 10.20. | |
2435 | But signal trampolines are pretty small stubs of | |
2436 | code, anyway, so it's OK instead to just | |
2437 | single-step out. Note: assuming such trampolines | |
2438 | don't exhibit recursion on any platform... */ | |
cd0fc7c3 SS |
2439 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, |
2440 | &ecs->stop_func_start, | |
2441 | &ecs->stop_func_end); | |
c906108c | 2442 | /* Readjust stepping range */ |
cd0fc7c3 SS |
2443 | step_range_start = ecs->stop_func_start; |
2444 | step_range_end = ecs->stop_func_end; | |
2445 | ecs->stepping_through_sigtramp = 1; | |
c906108c SS |
2446 | } |
2447 | } | |
2448 | ||
2449 | ||
2450 | /* If this is stepi or nexti, make sure that the stepping range | |
2451 | gets us past that instruction. */ | |
2452 | if (step_range_end == 1) | |
2453 | /* FIXME: Does this run afoul of the code below which, if | |
2454 | we step into the middle of a line, resets the stepping | |
2455 | range? */ | |
2456 | step_range_end = (step_range_start = prev_pc) + 1; | |
2457 | ||
cd0fc7c3 | 2458 | ecs->remove_breakpoints_on_following_step = 1; |
c906108c SS |
2459 | goto keep_going; |
2460 | } | |
2461 | ||
cd0fc7c3 SS |
2462 | if (stop_pc == ecs->stop_func_start /* Quick test */ |
2463 | || (in_prologue (stop_pc, ecs->stop_func_start) && | |
2464 | !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) | |
2465 | || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name) | |
2466 | || ecs->stop_func_name == 0) | |
c906108c SS |
2467 | { |
2468 | /* It's a subroutine call. */ | |
2469 | ||
2470 | if (step_over_calls == 0) | |
2471 | { | |
2472 | /* I presume that step_over_calls is only 0 when we're | |
2473 | supposed to be stepping at the assembly language level | |
2474 | ("stepi"). Just stop. */ | |
2475 | stop_step = 1; | |
cd0fc7c3 | 2476 | goto wfi_break; |
c906108c SS |
2477 | } |
2478 | ||
2479 | if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc)) | |
2480 | /* We're doing a "next". */ | |
2481 | goto step_over_function; | |
2482 | ||
2483 | /* If we are in a function call trampoline (a stub between | |
2484 | the calling routine and the real function), locate the real | |
2485 | function. That's what tells us (a) whether we want to step | |
2486 | into it at all, and (b) what prologue we want to run to | |
2487 | the end of, if we do step into it. */ | |
2488 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); | |
2489 | if (tmp != 0) | |
cd0fc7c3 | 2490 | ecs->stop_func_start = tmp; |
c906108c SS |
2491 | else |
2492 | { | |
2493 | tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc); | |
2494 | if (tmp) | |
2495 | { | |
2496 | struct symtab_and_line xxx; | |
2497 | /* Why isn't this s_a_l called "sr_sal", like all of the | |
2498 | other s_a_l's where this code is duplicated? */ | |
2499 | INIT_SAL (&xxx); /* initialize to zeroes */ | |
2500 | xxx.pc = tmp; | |
2501 | xxx.section = find_pc_overlay (xxx.pc); | |
2502 | step_resume_breakpoint = | |
2503 | set_momentary_breakpoint (xxx, NULL, bp_step_resume); | |
2504 | insert_breakpoints (); | |
2505 | goto keep_going; | |
2506 | } | |
2507 | } | |
2508 | ||
2509 | /* If we have line number information for the function we | |
2510 | are thinking of stepping into, step into it. | |
2511 | ||
2512 | If there are several symtabs at that PC (e.g. with include | |
2513 | files), just want to know whether *any* of them have line | |
2514 | numbers. find_pc_line handles this. */ | |
2515 | { | |
2516 | struct symtab_and_line tmp_sal; | |
2517 | ||
cd0fc7c3 | 2518 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
c906108c SS |
2519 | if (tmp_sal.line != 0) |
2520 | goto step_into_function; | |
2521 | } | |
2522 | ||
2523 | step_over_function: | |
2524 | /* A subroutine call has happened. */ | |
2525 | { | |
2526 | /* Set a special breakpoint after the return */ | |
2527 | struct symtab_and_line sr_sal; | |
2528 | ||
2529 | INIT_SAL (&sr_sal); | |
2530 | sr_sal.symtab = NULL; | |
2531 | sr_sal.line = 0; | |
2532 | ||
2533 | /* If we came here after encountering a signal in the middle of | |
2534 | a "next", use the stashed-away previous frame pc */ | |
2535 | sr_sal.pc | |
2536 | = stopped_by_random_signal | |
2537 | ? prev_pc | |
2538 | : ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ())); | |
2539 | ||
2540 | step_resume_breakpoint = | |
2541 | set_momentary_breakpoint (sr_sal, | |
2542 | stopped_by_random_signal ? | |
2543 | NULL : get_current_frame (), | |
2544 | bp_step_resume); | |
2545 | ||
2546 | /* We've just entered a callee, and we wish to resume until | |
2547 | it returns to the caller. Setting a step_resume bp on | |
2548 | the return PC will catch a return from the callee. | |
2549 | ||
2550 | However, if the callee is recursing, we want to be | |
2551 | careful not to catch returns of those recursive calls, | |
2552 | but of THIS instance of the call. | |
2553 | ||
2554 | To do this, we set the step_resume bp's frame to our | |
2555 | current caller's frame (step_frame_address, which is | |
2556 | set by the "next" or "until" command, before execution | |
2557 | begins). | |
2558 | ||
2559 | But ... don't do it if we're single-stepping out of a | |
2560 | sigtramp, because the reason we're single-stepping is | |
2561 | precisely because unwinding is a problem (HP-UX 10.20, | |
2562 | e.g.) and the frame address is likely to be incorrect. | |
2563 | No danger of sigtramp recursion. */ | |
2564 | ||
cd0fc7c3 | 2565 | if (ecs->stepping_through_sigtramp) |
c906108c SS |
2566 | { |
2567 | step_resume_breakpoint->frame = (CORE_ADDR) NULL; | |
cd0fc7c3 | 2568 | ecs->stepping_through_sigtramp = 0; |
c906108c SS |
2569 | } |
2570 | else if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc)) | |
2571 | step_resume_breakpoint->frame = step_frame_address; | |
2572 | ||
2573 | if (breakpoints_inserted) | |
2574 | insert_breakpoints (); | |
2575 | } | |
2576 | goto keep_going; | |
2577 | ||
2578 | step_into_function: | |
2579 | /* Subroutine call with source code we should not step over. | |
2580 | Do step to the first line of code in it. */ | |
2581 | { | |
2582 | struct symtab *s; | |
2583 | ||
2584 | s = find_pc_symtab (stop_pc); | |
2585 | if (s && s->language != language_asm) | |
cd0fc7c3 | 2586 | ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start); |
c906108c | 2587 | } |
cd0fc7c3 | 2588 | ecs->sal = find_pc_line (ecs->stop_func_start, 0); |
c906108c SS |
2589 | /* Use the step_resume_break to step until |
2590 | the end of the prologue, even if that involves jumps | |
2591 | (as it seems to on the vax under 4.2). */ | |
2592 | /* If the prologue ends in the middle of a source line, | |
2593 | continue to the end of that source line (if it is still | |
2594 | within the function). Otherwise, just go to end of prologue. */ | |
2595 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
2596 | /* no, don't either. It skips any code that's | |
2597 | legitimately on the first line. */ | |
2598 | #else | |
cd0fc7c3 SS |
2599 | if (ecs->sal.end && ecs->sal.pc != ecs->stop_func_start && ecs->sal.end < ecs->stop_func_end) |
2600 | ecs->stop_func_start = ecs->sal.end; | |
c906108c SS |
2601 | #endif |
2602 | ||
cd0fc7c3 | 2603 | if (ecs->stop_func_start == stop_pc) |
c906108c SS |
2604 | { |
2605 | /* We are already there: stop now. */ | |
2606 | stop_step = 1; | |
cd0fc7c3 | 2607 | goto wfi_break; |
c906108c SS |
2608 | } |
2609 | else | |
2610 | /* Put the step-breakpoint there and go until there. */ | |
2611 | { | |
2612 | struct symtab_and_line sr_sal; | |
2613 | ||
2614 | INIT_SAL (&sr_sal); /* initialize to zeroes */ | |
cd0fc7c3 SS |
2615 | sr_sal.pc = ecs->stop_func_start; |
2616 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
c906108c SS |
2617 | /* Do not specify what the fp should be when we stop |
2618 | since on some machines the prologue | |
2619 | is where the new fp value is established. */ | |
2620 | step_resume_breakpoint = | |
2621 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2622 | if (breakpoints_inserted) | |
2623 | insert_breakpoints (); | |
2624 | ||
2625 | /* And make sure stepping stops right away then. */ | |
2626 | step_range_end = step_range_start; | |
2627 | } | |
2628 | goto keep_going; | |
2629 | } | |
2630 | ||
2631 | /* We've wandered out of the step range. */ | |
2632 | ||
cd0fc7c3 | 2633 | ecs->sal = find_pc_line (stop_pc, 0); |
c906108c SS |
2634 | |
2635 | if (step_range_end == 1) | |
2636 | { | |
2637 | /* It is stepi or nexti. We always want to stop stepping after | |
2638 | one instruction. */ | |
2639 | stop_step = 1; | |
cd0fc7c3 | 2640 | goto wfi_break; |
c906108c SS |
2641 | } |
2642 | ||
2643 | /* If we're in the return path from a shared library trampoline, | |
2644 | we want to proceed through the trampoline when stepping. */ | |
cd0fc7c3 | 2645 | if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) |
c906108c SS |
2646 | { |
2647 | CORE_ADDR tmp; | |
2648 | ||
2649 | /* Determine where this trampoline returns. */ | |
2650 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); | |
2651 | ||
2652 | /* Only proceed through if we know where it's going. */ | |
2653 | if (tmp) | |
2654 | { | |
2655 | /* And put the step-breakpoint there and go until there. */ | |
2656 | struct symtab_and_line sr_sal; | |
2657 | ||
2658 | INIT_SAL (&sr_sal); /* initialize to zeroes */ | |
2659 | sr_sal.pc = tmp; | |
2660 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
2661 | /* Do not specify what the fp should be when we stop | |
2662 | since on some machines the prologue | |
2663 | is where the new fp value is established. */ | |
2664 | step_resume_breakpoint = | |
2665 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2666 | if (breakpoints_inserted) | |
2667 | insert_breakpoints (); | |
2668 | ||
2669 | /* Restart without fiddling with the step ranges or | |
2670 | other state. */ | |
2671 | goto keep_going; | |
2672 | } | |
2673 | } | |
2674 | ||
cd0fc7c3 | 2675 | if (ecs->sal.line == 0) |
c906108c SS |
2676 | { |
2677 | /* We have no line number information. That means to stop | |
2678 | stepping (does this always happen right after one instruction, | |
2679 | when we do "s" in a function with no line numbers, | |
2680 | or can this happen as a result of a return or longjmp?). */ | |
2681 | stop_step = 1; | |
cd0fc7c3 | 2682 | goto wfi_break; |
c906108c SS |
2683 | } |
2684 | ||
cd0fc7c3 SS |
2685 | if ((stop_pc == ecs->sal.pc) |
2686 | && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab)) | |
c906108c SS |
2687 | { |
2688 | /* We are at the start of a different line. So stop. Note that | |
2689 | we don't stop if we step into the middle of a different line. | |
2690 | That is said to make things like for (;;) statements work | |
2691 | better. */ | |
2692 | stop_step = 1; | |
cd0fc7c3 | 2693 | goto wfi_break; |
c906108c SS |
2694 | } |
2695 | ||
2696 | /* We aren't done stepping. | |
2697 | ||
2698 | Optimize by setting the stepping range to the line. | |
2699 | (We might not be in the original line, but if we entered a | |
2700 | new line in mid-statement, we continue stepping. This makes | |
2701 | things like for(;;) statements work better.) */ | |
2702 | ||
cd0fc7c3 | 2703 | if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end) |
c906108c SS |
2704 | { |
2705 | /* If this is the last line of the function, don't keep stepping | |
2706 | (it would probably step us out of the function). | |
2707 | This is particularly necessary for a one-line function, | |
2708 | in which after skipping the prologue we better stop even though | |
2709 | we will be in mid-line. */ | |
2710 | stop_step = 1; | |
cd0fc7c3 | 2711 | goto wfi_break; |
c906108c | 2712 | } |
cd0fc7c3 SS |
2713 | step_range_start = ecs->sal.pc; |
2714 | step_range_end = ecs->sal.end; | |
c906108c | 2715 | step_frame_address = FRAME_FP (get_current_frame ()); |
cd0fc7c3 SS |
2716 | ecs->current_line = ecs->sal.line; |
2717 | ecs->current_symtab = ecs->sal.symtab; | |
c906108c SS |
2718 | |
2719 | /* In the case where we just stepped out of a function into the middle | |
2720 | of a line of the caller, continue stepping, but step_frame_address | |
2721 | must be modified to current frame */ | |
2722 | { | |
2723 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); | |
2724 | if (!(INNER_THAN (current_frame, step_frame_address))) | |
2725 | step_frame_address = current_frame; | |
2726 | } | |
2727 | ||
2728 | ||
2729 | goto keep_going; | |
2730 | ||
2731 | check_sigtramp2: | |
2732 | if (trap_expected | |
cd0fc7c3 | 2733 | && IN_SIGTRAMP (stop_pc, ecs->stop_func_name) |
c906108c SS |
2734 | && !IN_SIGTRAMP (prev_pc, prev_func_name) |
2735 | && INNER_THAN (read_sp (), step_sp)) | |
2736 | { | |
2737 | /* What has happened here is that we have just stepped the inferior | |
2738 | with a signal (because it is a signal which shouldn't make | |
2739 | us stop), thus stepping into sigtramp. | |
2740 | ||
2741 | So we need to set a step_resume_break_address breakpoint | |
2742 | and continue until we hit it, and then step. FIXME: This should | |
2743 | be more enduring than a step_resume breakpoint; we should know | |
2744 | that we will later need to keep going rather than re-hitting | |
2745 | the breakpoint here (see testsuite/gdb.t06/signals.exp where | |
2746 | it says "exceedingly difficult"). */ | |
2747 | struct symtab_and_line sr_sal; | |
2748 | ||
2749 | INIT_SAL (&sr_sal); /* initialize to zeroes */ | |
2750 | sr_sal.pc = prev_pc; | |
2751 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
2752 | /* We perhaps could set the frame if we kept track of what | |
2753 | the frame corresponding to prev_pc was. But we don't, | |
2754 | so don't. */ | |
2755 | through_sigtramp_breakpoint = | |
2756 | set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp); | |
2757 | if (breakpoints_inserted) | |
2758 | insert_breakpoints (); | |
2759 | ||
cd0fc7c3 SS |
2760 | ecs->remove_breakpoints_on_following_step = 1; |
2761 | ecs->another_trap = 1; | |
c906108c SS |
2762 | } |
2763 | ||
2764 | keep_going: | |
2765 | /* Come to this label when you need to resume the inferior. | |
2766 | It's really much cleaner to do a goto than a maze of if-else | |
2767 | conditions. */ | |
2768 | ||
2769 | /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug | |
2770 | a vforked child beetween its creation and subsequent exit or | |
2771 | call to exec(). However, I had big problems in this rather | |
2772 | creaky exec engine, getting that to work. The fundamental | |
2773 | problem is that I'm trying to debug two processes via an | |
2774 | engine that only understands a single process with possibly | |
2775 | multiple threads. | |
2776 | ||
2777 | Hence, this spot is known to have problems when | |
2778 | target_can_follow_vfork_prior_to_exec returns 1. */ | |
2779 | ||
2780 | /* Save the pc before execution, to compare with pc after stop. */ | |
2781 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ | |
cd0fc7c3 | 2782 | prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER |
c906108c SS |
2783 | BREAK is defined, the |
2784 | original pc would not have | |
2785 | been at the start of a | |
2786 | function. */ | |
cd0fc7c3 | 2787 | prev_func_name = ecs->stop_func_name; |
c906108c | 2788 | |
cd0fc7c3 | 2789 | if (ecs->update_step_sp) |
c906108c | 2790 | step_sp = read_sp (); |
cd0fc7c3 | 2791 | ecs->update_step_sp = 0; |
c906108c SS |
2792 | |
2793 | /* If we did not do break;, it means we should keep | |
2794 | running the inferior and not return to debugger. */ | |
2795 | ||
2796 | if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) | |
2797 | { | |
2798 | /* We took a signal (which we are supposed to pass through to | |
2799 | the inferior, else we'd have done a break above) and we | |
2800 | haven't yet gotten our trap. Simply continue. */ | |
cd0fc7c3 | 2801 | resume (currently_stepping (ecs), stop_signal); |
c906108c SS |
2802 | } |
2803 | else | |
2804 | { | |
2805 | /* Either the trap was not expected, but we are continuing | |
2806 | anyway (the user asked that this signal be passed to the | |
2807 | child) | |
2808 | -- or -- | |
2809 | The signal was SIGTRAP, e.g. it was our signal, but we | |
2810 | decided we should resume from it. | |
2811 | ||
2812 | We're going to run this baby now! | |
2813 | ||
2814 | Insert breakpoints now, unless we are trying | |
2815 | to one-proceed past a breakpoint. */ | |
2816 | /* If we've just finished a special step resume and we don't | |
2817 | want to hit a breakpoint, pull em out. */ | |
2818 | if (step_resume_breakpoint == NULL | |
2819 | && through_sigtramp_breakpoint == NULL | |
cd0fc7c3 | 2820 | && ecs->remove_breakpoints_on_following_step) |
c906108c | 2821 | { |
cd0fc7c3 | 2822 | ecs->remove_breakpoints_on_following_step = 0; |
c906108c SS |
2823 | remove_breakpoints (); |
2824 | breakpoints_inserted = 0; | |
2825 | } | |
2826 | else if (!breakpoints_inserted && | |
cd0fc7c3 | 2827 | (through_sigtramp_breakpoint != NULL || !ecs->another_trap)) |
c906108c SS |
2828 | { |
2829 | breakpoints_failed = insert_breakpoints (); | |
2830 | if (breakpoints_failed) | |
cd0fc7c3 | 2831 | goto wfi_break; |
c906108c SS |
2832 | breakpoints_inserted = 1; |
2833 | } | |
2834 | ||
cd0fc7c3 | 2835 | trap_expected = ecs->another_trap; |
c906108c SS |
2836 | |
2837 | /* Do not deliver SIGNAL_TRAP (except when the user | |
2838 | explicitly specifies that such a signal should be | |
2839 | delivered to the target program). | |
2840 | ||
2841 | Typically, this would occure when a user is debugging a | |
2842 | target monitor on a simulator: the target monitor sets a | |
2843 | breakpoint; the simulator encounters this break-point and | |
2844 | halts the simulation handing control to GDB; GDB, noteing | |
2845 | that the break-point isn't valid, returns control back to | |
2846 | the simulator; the simulator then delivers the hardware | |
2847 | equivalent of a SIGNAL_TRAP to the program being | |
2848 | debugged. */ | |
2849 | ||
2850 | if (stop_signal == TARGET_SIGNAL_TRAP | |
2851 | && !signal_program[stop_signal]) | |
2852 | stop_signal = TARGET_SIGNAL_0; | |
2853 | ||
2854 | #ifdef SHIFT_INST_REGS | |
2855 | /* I'm not sure when this following segment applies. I do know, | |
2856 | now, that we shouldn't rewrite the regs when we were stopped | |
2857 | by a random signal from the inferior process. */ | |
2858 | /* FIXME: Shouldn't this be based on the valid bit of the SXIP? | |
2859 | (this is only used on the 88k). */ | |
2860 | ||
2861 | if (!bpstat_explains_signal (stop_bpstat) | |
2862 | && (stop_signal != TARGET_SIGNAL_CHLD) | |
2863 | && !stopped_by_random_signal) | |
2864 | SHIFT_INST_REGS (); | |
2865 | #endif /* SHIFT_INST_REGS */ | |
2866 | ||
cd0fc7c3 SS |
2867 | resume (currently_stepping (ecs), stop_signal); |
2868 | } | |
2869 | ||
2870 | /* Former continues in the main loop goto here. */ | |
2871 | wfi_continue: | |
2872 | /* This used to be at the top of the loop. */ | |
2873 | if (ecs->infwait_state == infwait_normal_state) | |
2874 | { | |
2875 | overlay_cache_invalid = 1; | |
2876 | ||
2877 | /* We have to invalidate the registers BEFORE calling | |
2878 | target_wait because they can be loaded from the target | |
2879 | while in target_wait. This makes remote debugging a bit | |
2880 | more efficient for those targets that provide critical | |
2881 | registers as part of their normal status mechanism. */ | |
2882 | ||
2883 | registers_changed (); | |
2884 | ecs->waiton_pid = -1; | |
2885 | ecs->wp = &(ecs->ws); | |
c906108c | 2886 | } |
cd0fc7c3 SS |
2887 | /* This is the old end of the while loop. Let everybody know |
2888 | we want to wait for the inferior some more and get called | |
2889 | again soon. */ | |
2890 | ecs->wait_some_more = 1; | |
2891 | return; | |
c906108c SS |
2892 | } |
2893 | ||
cd0fc7c3 SS |
2894 | /* Former breaks in the main loop goto here. */ |
2895 | wfi_break: | |
2896 | ||
c906108c SS |
2897 | stop_stepping: |
2898 | if (target_has_execution) | |
2899 | { | |
2900 | /* Are we stopping for a vfork event? We only stop when we see | |
2901 | the child's event. However, we may not yet have seen the | |
2902 | parent's event. And, inferior_pid is still set to the parent's | |
2903 | pid, until we resume again and follow either the parent or child. | |
2904 | ||
2905 | To ensure that we can really touch inferior_pid (aka, the | |
2906 | parent process) -- which calls to functions like read_pc | |
2907 | implicitly do -- wait on the parent if necessary. */ | |
2908 | if ((pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
2909 | && !pending_follow.fork_event.saw_parent_fork) | |
2910 | { | |
2911 | int parent_pid; | |
2912 | ||
2913 | do | |
2914 | { | |
2915 | if (target_wait_hook) | |
cd0fc7c3 | 2916 | parent_pid = target_wait_hook (-1, &(ecs->ws)); |
c906108c | 2917 | else |
cd0fc7c3 | 2918 | parent_pid = target_wait (-1, &(ecs->ws)); |
c906108c SS |
2919 | } |
2920 | while (parent_pid != inferior_pid); | |
2921 | } | |
2922 | ||
c906108c SS |
2923 | /* Assuming the inferior still exists, set these up for next |
2924 | time, just like we did above if we didn't break out of the | |
2925 | loop. */ | |
2926 | prev_pc = read_pc (); | |
cd0fc7c3 SS |
2927 | prev_func_start = ecs->stop_func_start; |
2928 | prev_func_name = ecs->stop_func_name; | |
c906108c | 2929 | } |
cd0fc7c3 SS |
2930 | /* Let callers know we don't want to wait for the inferior anymore. */ |
2931 | ecs->wait_some_more = 0; | |
2932 | } | |
2933 | ||
2934 | /* Are we in the middle of stepping? */ | |
2935 | ||
392a587b | 2936 | static int |
cd0fc7c3 SS |
2937 | currently_stepping (ecs) |
2938 | struct execution_control_state *ecs; | |
2939 | { | |
2940 | return ((through_sigtramp_breakpoint == NULL | |
2941 | && !ecs->handling_longjmp | |
2942 | && ((step_range_end && step_resume_breakpoint == NULL) | |
2943 | || trap_expected)) | |
2944 | || ecs->stepping_through_solib_after_catch | |
2945 | || bpstat_should_step ()); | |
c906108c SS |
2946 | } |
2947 | ||
2948 | /* This function returns TRUE if ep is an internal breakpoint | |
2949 | set to catch generic shared library (aka dynamically-linked | |
2950 | library) events. (This is *NOT* the same as a catchpoint for a | |
2951 | shlib event. The latter is something a user can set; this is | |
2952 | something gdb sets for its own use, and isn't ever shown to a | |
2953 | user.) */ | |
2954 | static int | |
2955 | is_internal_shlib_eventpoint (ep) | |
2956 | struct breakpoint *ep; | |
2957 | { | |
2958 | return | |
2959 | (ep->type == bp_shlib_event) | |
2960 | ; | |
2961 | } | |
2962 | ||
2963 | /* This function returns TRUE if bs indicates that the inferior | |
2964 | stopped due to a shared library (aka dynamically-linked library) | |
2965 | event. */ | |
2966 | static int | |
2967 | stopped_for_internal_shlib_event (bs) | |
2968 | bpstat bs; | |
2969 | { | |
2970 | /* Note that multiple eventpoints may've caused the stop. Any | |
2971 | that are associated with shlib events will be accepted. */ | |
2972 | for (; bs != NULL; bs = bs->next) | |
2973 | { | |
2974 | if ((bs->breakpoint_at != NULL) | |
2975 | && is_internal_shlib_eventpoint (bs->breakpoint_at)) | |
2976 | return 1; | |
2977 | } | |
2978 | ||
2979 | /* If we get here, then no candidate was found. */ | |
2980 | return 0; | |
2981 | } | |
2982 | ||
2983 | /* This function returns TRUE if bs indicates that the inferior | |
2984 | stopped due to a shared library (aka dynamically-linked library) | |
2985 | event caught by a catchpoint. | |
2986 | ||
2987 | If TRUE, cp_p is set to point to the catchpoint. | |
2988 | ||
2989 | Else, the value of cp_p is undefined. */ | |
2990 | static int | |
2991 | stopped_for_shlib_catchpoint (bs, cp_p) | |
2992 | bpstat bs; | |
2993 | struct breakpoint **cp_p; | |
2994 | { | |
2995 | /* Note that multiple eventpoints may've caused the stop. Any | |
2996 | that are associated with shlib events will be accepted. */ | |
2997 | *cp_p = NULL; | |
2998 | ||
2999 | for (; bs != NULL; bs = bs->next) | |
3000 | { | |
3001 | if ((bs->breakpoint_at != NULL) | |
3002 | && ep_is_shlib_catchpoint (bs->breakpoint_at)) | |
3003 | { | |
3004 | *cp_p = bs->breakpoint_at; | |
3005 | return 1; | |
3006 | } | |
3007 | } | |
3008 | ||
3009 | /* If we get here, then no candidate was found. */ | |
3010 | return 0; | |
3011 | } | |
3012 | \f | |
3013 | ||
3014 | /* Here to return control to GDB when the inferior stops for real. | |
3015 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
3016 | ||
3017 | STOP_PRINT_FRAME nonzero means print the executing frame | |
3018 | (pc, function, args, file, line number and line text). | |
3019 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
3020 | attempting to insert breakpoints. */ | |
3021 | ||
3022 | void | |
3023 | normal_stop () | |
3024 | { | |
c906108c SS |
3025 | /* As with the notification of thread events, we want to delay |
3026 | notifying the user that we've switched thread context until | |
3027 | the inferior actually stops. | |
3028 | ||
3029 | (Note that there's no point in saying anything if the inferior | |
3030 | has exited!) */ | |
7a292a7a SS |
3031 | if (may_switch_from_inferior_pid |
3032 | && (switched_from_inferior_pid != inferior_pid) | |
3033 | && target_has_execution) | |
c906108c SS |
3034 | { |
3035 | target_terminal_ours_for_output (); | |
3036 | printf_filtered ("[Switched to %s]\n", | |
3037 | target_pid_or_tid_to_str (inferior_pid)); | |
3038 | switched_from_inferior_pid = inferior_pid; | |
3039 | } | |
c906108c SS |
3040 | |
3041 | /* Make sure that the current_frame's pc is correct. This | |
3042 | is a correction for setting up the frame info before doing | |
3043 | DECR_PC_AFTER_BREAK */ | |
3044 | if (target_has_execution && get_current_frame ()) | |
3045 | (get_current_frame ())->pc = read_pc (); | |
3046 | ||
3047 | if (breakpoints_failed) | |
3048 | { | |
3049 | target_terminal_ours_for_output (); | |
3050 | print_sys_errmsg ("ptrace", breakpoints_failed); | |
3051 | printf_filtered ("Stopped; cannot insert breakpoints.\n\ | |
3052 | The same program may be running in another process.\n"); | |
3053 | } | |
3054 | ||
3055 | if (target_has_execution && breakpoints_inserted) | |
3056 | { | |
3057 | if (remove_breakpoints ()) | |
3058 | { | |
3059 | target_terminal_ours_for_output (); | |
3060 | printf_filtered ("Cannot remove breakpoints because "); | |
3061 | printf_filtered ("program is no longer writable.\n"); | |
3062 | printf_filtered ("It might be running in another process.\n"); | |
3063 | printf_filtered ("Further execution is probably impossible.\n"); | |
3064 | } | |
3065 | } | |
3066 | breakpoints_inserted = 0; | |
3067 | ||
3068 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
3069 | Delete any breakpoint that is to be deleted at the next stop. */ | |
3070 | ||
3071 | breakpoint_auto_delete (stop_bpstat); | |
3072 | ||
3073 | /* If an auto-display called a function and that got a signal, | |
3074 | delete that auto-display to avoid an infinite recursion. */ | |
3075 | ||
3076 | if (stopped_by_random_signal) | |
3077 | disable_current_display (); | |
3078 | ||
3079 | /* Don't print a message if in the middle of doing a "step n" | |
3080 | operation for n > 1 */ | |
3081 | if (step_multi && stop_step) | |
3082 | goto done; | |
3083 | ||
3084 | target_terminal_ours (); | |
3085 | ||
3086 | /* Did we stop because the user set the stop_on_solib_events | |
3087 | variable? (If so, we report this as a generic, "Stopped due | |
3088 | to shlib event" message.) */ | |
3089 | if (stopped_for_internal_shlib_event (stop_bpstat)) | |
3090 | { | |
3091 | printf_filtered ("Stopped due to shared library event\n"); | |
3092 | } | |
3093 | ||
3094 | /* Look up the hook_stop and run it if it exists. */ | |
3095 | ||
3096 | if (stop_command && stop_command->hook) | |
3097 | { | |
3098 | catch_errors (hook_stop_stub, stop_command->hook, | |
3099 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
3100 | } | |
3101 | ||
3102 | if (!target_has_stack) | |
3103 | { | |
3104 | ||
3105 | goto done; | |
3106 | } | |
3107 | ||
3108 | /* Select innermost stack frame - i.e., current frame is frame 0, | |
3109 | and current location is based on that. | |
3110 | Don't do this on return from a stack dummy routine, | |
3111 | or if the program has exited. */ | |
3112 | ||
3113 | if (!stop_stack_dummy) | |
3114 | { | |
3115 | select_frame (get_current_frame (), 0); | |
3116 | ||
3117 | /* Print current location without a level number, if | |
3118 | we have changed functions or hit a breakpoint. | |
3119 | Print source line if we have one. | |
3120 | bpstat_print() contains the logic deciding in detail | |
3121 | what to print, based on the event(s) that just occurred. */ | |
3122 | ||
3123 | if (stop_print_frame) | |
3124 | { | |
3125 | int bpstat_ret; | |
3126 | int source_flag; | |
3127 | ||
3128 | bpstat_ret = bpstat_print (stop_bpstat); | |
3129 | /* bpstat_print() returned one of: | |
3130 | -1: Didn't print anything | |
3131 | 0: Printed preliminary "Breakpoint n, " message, desires | |
3132 | location tacked on | |
3133 | 1: Printed something, don't tack on location */ | |
3134 | ||
3135 | if (bpstat_ret == -1) | |
3136 | if (stop_step | |
3137 | && step_frame_address == FRAME_FP (get_current_frame ()) | |
3138 | && step_start_function == find_pc_function (stop_pc)) | |
3139 | source_flag = -1; /* finished step, just print source line */ | |
3140 | else | |
3141 | source_flag = 1; /* print location and source line */ | |
3142 | else if (bpstat_ret == 0) /* hit bpt, desire location */ | |
3143 | source_flag = 1; /* print location and source line */ | |
3144 | else /* bpstat_ret == 1, hit bpt, do not desire location */ | |
3145 | source_flag = -1; /* just print source line */ | |
3146 | ||
3147 | /* The behavior of this routine with respect to the source | |
3148 | flag is: | |
3149 | -1: Print only source line | |
3150 | 0: Print only location | |
3151 | 1: Print location and source line */ | |
3152 | show_and_print_stack_frame (selected_frame, -1, source_flag); | |
3153 | ||
3154 | /* Display the auto-display expressions. */ | |
3155 | do_displays (); | |
3156 | } | |
3157 | } | |
3158 | ||
3159 | /* Save the function value return registers, if we care. | |
3160 | We might be about to restore their previous contents. */ | |
3161 | if (proceed_to_finish) | |
3162 | read_register_bytes (0, stop_registers, REGISTER_BYTES); | |
3163 | ||
3164 | if (stop_stack_dummy) | |
3165 | { | |
3166 | /* Pop the empty frame that contains the stack dummy. | |
3167 | POP_FRAME ends with a setting of the current frame, so we | |
3168 | can use that next. */ | |
3169 | POP_FRAME; | |
3170 | /* Set stop_pc to what it was before we called the function. | |
3171 | Can't rely on restore_inferior_status because that only gets | |
3172 | called if we don't stop in the called function. */ | |
3173 | stop_pc = read_pc (); | |
3174 | select_frame (get_current_frame (), 0); | |
3175 | } | |
3176 | ||
3177 | ||
3178 | TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame)); | |
3179 | ||
3180 | done: | |
3181 | annotate_stopped (); | |
3182 | } | |
3183 | ||
3184 | static int | |
3185 | hook_stop_stub (cmd) | |
3186 | PTR cmd; | |
3187 | { | |
3188 | execute_user_command ((struct cmd_list_element *) cmd, 0); | |
3189 | return (0); | |
3190 | } | |
3191 | \f | |
3192 | int | |
3193 | signal_stop_state (signo) | |
3194 | int signo; | |
3195 | { | |
3196 | return signal_stop[signo]; | |
3197 | } | |
3198 | ||
3199 | int | |
3200 | signal_print_state (signo) | |
3201 | int signo; | |
3202 | { | |
3203 | return signal_print[signo]; | |
3204 | } | |
3205 | ||
3206 | int | |
3207 | signal_pass_state (signo) | |
3208 | int signo; | |
3209 | { | |
3210 | return signal_program[signo]; | |
3211 | } | |
3212 | ||
3213 | static void | |
3214 | sig_print_header () | |
3215 | { | |
3216 | printf_filtered ("\ | |
3217 | Signal Stop\tPrint\tPass to program\tDescription\n"); | |
3218 | } | |
3219 | ||
3220 | static void | |
3221 | sig_print_info (oursig) | |
3222 | enum target_signal oursig; | |
3223 | { | |
3224 | char *name = target_signal_to_name (oursig); | |
3225 | int name_padding = 13 - strlen (name); | |
3226 | if (name_padding <= 0) | |
3227 | name_padding = 0; | |
3228 | ||
3229 | printf_filtered ("%s", name); | |
3230 | printf_filtered ("%*.*s ", name_padding, name_padding, | |
3231 | " "); | |
3232 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); | |
3233 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
3234 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
3235 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
3236 | } | |
3237 | ||
3238 | /* Specify how various signals in the inferior should be handled. */ | |
3239 | ||
3240 | static void | |
3241 | handle_command (args, from_tty) | |
3242 | char *args; | |
3243 | int from_tty; | |
3244 | { | |
3245 | char **argv; | |
3246 | int digits, wordlen; | |
3247 | int sigfirst, signum, siglast; | |
3248 | enum target_signal oursig; | |
3249 | int allsigs; | |
3250 | int nsigs; | |
3251 | unsigned char *sigs; | |
3252 | struct cleanup *old_chain; | |
3253 | ||
3254 | if (args == NULL) | |
3255 | { | |
3256 | error_no_arg ("signal to handle"); | |
3257 | } | |
3258 | ||
3259 | /* Allocate and zero an array of flags for which signals to handle. */ | |
3260 | ||
3261 | nsigs = (int) TARGET_SIGNAL_LAST; | |
3262 | sigs = (unsigned char *) alloca (nsigs); | |
3263 | memset (sigs, 0, nsigs); | |
3264 | ||
3265 | /* Break the command line up into args. */ | |
3266 | ||
3267 | argv = buildargv (args); | |
3268 | if (argv == NULL) | |
3269 | { | |
3270 | nomem (0); | |
3271 | } | |
7a292a7a | 3272 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3273 | |
3274 | /* Walk through the args, looking for signal oursigs, signal names, and | |
3275 | actions. Signal numbers and signal names may be interspersed with | |
3276 | actions, with the actions being performed for all signals cumulatively | |
3277 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
3278 | ||
3279 | while (*argv != NULL) | |
3280 | { | |
3281 | wordlen = strlen (*argv); | |
3282 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
3283 | {; | |
3284 | } | |
3285 | allsigs = 0; | |
3286 | sigfirst = siglast = -1; | |
3287 | ||
3288 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
3289 | { | |
3290 | /* Apply action to all signals except those used by the | |
3291 | debugger. Silently skip those. */ | |
3292 | allsigs = 1; | |
3293 | sigfirst = 0; | |
3294 | siglast = nsigs - 1; | |
3295 | } | |
3296 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
3297 | { | |
3298 | SET_SIGS (nsigs, sigs, signal_stop); | |
3299 | SET_SIGS (nsigs, sigs, signal_print); | |
3300 | } | |
3301 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
3302 | { | |
3303 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3304 | } | |
3305 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
3306 | { | |
3307 | SET_SIGS (nsigs, sigs, signal_print); | |
3308 | } | |
3309 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
3310 | { | |
3311 | SET_SIGS (nsigs, sigs, signal_program); | |
3312 | } | |
3313 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
3314 | { | |
3315 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3316 | } | |
3317 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
3318 | { | |
3319 | SET_SIGS (nsigs, sigs, signal_program); | |
3320 | } | |
3321 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
3322 | { | |
3323 | UNSET_SIGS (nsigs, sigs, signal_print); | |
3324 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3325 | } | |
3326 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
3327 | { | |
3328 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3329 | } | |
3330 | else if (digits > 0) | |
3331 | { | |
3332 | /* It is numeric. The numeric signal refers to our own | |
3333 | internal signal numbering from target.h, not to host/target | |
3334 | signal number. This is a feature; users really should be | |
3335 | using symbolic names anyway, and the common ones like | |
3336 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
3337 | ||
3338 | sigfirst = siglast = (int) | |
3339 | target_signal_from_command (atoi (*argv)); | |
3340 | if ((*argv)[digits] == '-') | |
3341 | { | |
3342 | siglast = (int) | |
3343 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
3344 | } | |
3345 | if (sigfirst > siglast) | |
3346 | { | |
3347 | /* Bet he didn't figure we'd think of this case... */ | |
3348 | signum = sigfirst; | |
3349 | sigfirst = siglast; | |
3350 | siglast = signum; | |
3351 | } | |
3352 | } | |
3353 | else | |
3354 | { | |
3355 | oursig = target_signal_from_name (*argv); | |
3356 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
3357 | { | |
3358 | sigfirst = siglast = (int) oursig; | |
3359 | } | |
3360 | else | |
3361 | { | |
3362 | /* Not a number and not a recognized flag word => complain. */ | |
3363 | error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); | |
3364 | } | |
3365 | } | |
3366 | ||
3367 | /* If any signal numbers or symbol names were found, set flags for | |
3368 | which signals to apply actions to. */ | |
3369 | ||
3370 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
3371 | { | |
3372 | switch ((enum target_signal) signum) | |
3373 | { | |
3374 | case TARGET_SIGNAL_TRAP: | |
3375 | case TARGET_SIGNAL_INT: | |
3376 | if (!allsigs && !sigs[signum]) | |
3377 | { | |
3378 | if (query ("%s is used by the debugger.\n\ | |
3379 | Are you sure you want to change it? ", | |
3380 | target_signal_to_name | |
3381 | ((enum target_signal) signum))) | |
3382 | { | |
3383 | sigs[signum] = 1; | |
3384 | } | |
3385 | else | |
3386 | { | |
3387 | printf_unfiltered ("Not confirmed, unchanged.\n"); | |
3388 | gdb_flush (gdb_stdout); | |
3389 | } | |
3390 | } | |
3391 | break; | |
3392 | case TARGET_SIGNAL_0: | |
3393 | case TARGET_SIGNAL_DEFAULT: | |
3394 | case TARGET_SIGNAL_UNKNOWN: | |
3395 | /* Make sure that "all" doesn't print these. */ | |
3396 | break; | |
3397 | default: | |
3398 | sigs[signum] = 1; | |
3399 | break; | |
3400 | } | |
3401 | } | |
3402 | ||
3403 | argv++; | |
3404 | } | |
3405 | ||
3406 | target_notice_signals (inferior_pid); | |
3407 | ||
3408 | if (from_tty) | |
3409 | { | |
3410 | /* Show the results. */ | |
3411 | sig_print_header (); | |
3412 | for (signum = 0; signum < nsigs; signum++) | |
3413 | { | |
3414 | if (sigs[signum]) | |
3415 | { | |
3416 | sig_print_info (signum); | |
3417 | } | |
3418 | } | |
3419 | } | |
3420 | ||
3421 | do_cleanups (old_chain); | |
3422 | } | |
3423 | ||
3424 | static void | |
3425 | xdb_handle_command (args, from_tty) | |
3426 | char *args; | |
3427 | int from_tty; | |
3428 | { | |
3429 | char **argv; | |
3430 | struct cleanup *old_chain; | |
3431 | ||
3432 | /* Break the command line up into args. */ | |
3433 | ||
3434 | argv = buildargv (args); | |
3435 | if (argv == NULL) | |
3436 | { | |
3437 | nomem (0); | |
3438 | } | |
7a292a7a | 3439 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3440 | if (argv[1] != (char *) NULL) |
3441 | { | |
3442 | char *argBuf; | |
3443 | int bufLen; | |
3444 | ||
3445 | bufLen = strlen (argv[0]) + 20; | |
3446 | argBuf = (char *) xmalloc (bufLen); | |
3447 | if (argBuf) | |
3448 | { | |
3449 | int validFlag = 1; | |
3450 | enum target_signal oursig; | |
3451 | ||
3452 | oursig = target_signal_from_name (argv[0]); | |
3453 | memset (argBuf, 0, bufLen); | |
3454 | if (strcmp (argv[1], "Q") == 0) | |
3455 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3456 | else | |
3457 | { | |
3458 | if (strcmp (argv[1], "s") == 0) | |
3459 | { | |
3460 | if (!signal_stop[oursig]) | |
3461 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
3462 | else | |
3463 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
3464 | } | |
3465 | else if (strcmp (argv[1], "i") == 0) | |
3466 | { | |
3467 | if (!signal_program[oursig]) | |
3468 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
3469 | else | |
3470 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
3471 | } | |
3472 | else if (strcmp (argv[1], "r") == 0) | |
3473 | { | |
3474 | if (!signal_print[oursig]) | |
3475 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
3476 | else | |
3477 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3478 | } | |
3479 | else | |
3480 | validFlag = 0; | |
3481 | } | |
3482 | if (validFlag) | |
3483 | handle_command (argBuf, from_tty); | |
3484 | else | |
3485 | printf_filtered ("Invalid signal handling flag.\n"); | |
3486 | if (argBuf) | |
3487 | free (argBuf); | |
3488 | } | |
3489 | } | |
3490 | do_cleanups (old_chain); | |
3491 | } | |
3492 | ||
3493 | /* Print current contents of the tables set by the handle command. | |
3494 | It is possible we should just be printing signals actually used | |
3495 | by the current target (but for things to work right when switching | |
3496 | targets, all signals should be in the signal tables). */ | |
3497 | ||
3498 | static void | |
3499 | signals_info (signum_exp, from_tty) | |
3500 | char *signum_exp; | |
3501 | int from_tty; | |
3502 | { | |
3503 | enum target_signal oursig; | |
3504 | sig_print_header (); | |
3505 | ||
3506 | if (signum_exp) | |
3507 | { | |
3508 | /* First see if this is a symbol name. */ | |
3509 | oursig = target_signal_from_name (signum_exp); | |
3510 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
3511 | { | |
3512 | /* No, try numeric. */ | |
3513 | oursig = | |
3514 | target_signal_from_command (parse_and_eval_address (signum_exp)); | |
3515 | } | |
3516 | sig_print_info (oursig); | |
3517 | return; | |
3518 | } | |
3519 | ||
3520 | printf_filtered ("\n"); | |
3521 | /* These ugly casts brought to you by the native VAX compiler. */ | |
3522 | for (oursig = TARGET_SIGNAL_FIRST; | |
3523 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
3524 | oursig = (enum target_signal) ((int) oursig + 1)) | |
3525 | { | |
3526 | QUIT; | |
3527 | ||
3528 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
3529 | && oursig != TARGET_SIGNAL_DEFAULT | |
3530 | && oursig != TARGET_SIGNAL_0) | |
3531 | sig_print_info (oursig); | |
3532 | } | |
3533 | ||
3534 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); | |
3535 | } | |
3536 | \f | |
7a292a7a SS |
3537 | struct inferior_status |
3538 | { | |
3539 | enum target_signal stop_signal; | |
3540 | CORE_ADDR stop_pc; | |
3541 | bpstat stop_bpstat; | |
3542 | int stop_step; | |
3543 | int stop_stack_dummy; | |
3544 | int stopped_by_random_signal; | |
3545 | int trap_expected; | |
3546 | CORE_ADDR step_range_start; | |
3547 | CORE_ADDR step_range_end; | |
3548 | CORE_ADDR step_frame_address; | |
3549 | int step_over_calls; | |
3550 | CORE_ADDR step_resume_break_address; | |
3551 | int stop_after_trap; | |
3552 | int stop_soon_quietly; | |
3553 | CORE_ADDR selected_frame_address; | |
3554 | char *stop_registers; | |
3555 | ||
3556 | /* These are here because if call_function_by_hand has written some | |
3557 | registers and then decides to call error(), we better not have changed | |
3558 | any registers. */ | |
3559 | char *registers; | |
3560 | ||
3561 | int selected_level; | |
3562 | int breakpoint_proceeded; | |
3563 | int restore_stack_info; | |
3564 | int proceed_to_finish; | |
3565 | }; | |
3566 | ||
3567 | ||
3568 | static struct inferior_status *xmalloc_inferior_status PARAMS ((void)); | |
3569 | static struct inferior_status * | |
3570 | xmalloc_inferior_status () | |
3571 | { | |
3572 | struct inferior_status *inf_status; | |
3573 | inf_status = xmalloc (sizeof (struct inferior_status)); | |
3574 | inf_status->stop_registers = xmalloc (REGISTER_BYTES); | |
3575 | inf_status->registers = xmalloc (REGISTER_BYTES); | |
3576 | return inf_status; | |
3577 | } | |
3578 | ||
3579 | static void free_inferior_status PARAMS ((struct inferior_status *)); | |
3580 | static void | |
3581 | free_inferior_status (inf_status) | |
3582 | struct inferior_status *inf_status; | |
3583 | { | |
3584 | free (inf_status->registers); | |
3585 | free (inf_status->stop_registers); | |
3586 | free (inf_status); | |
3587 | } | |
3588 | ||
3589 | void | |
3590 | write_inferior_status_register (inf_status, regno, val) | |
3591 | struct inferior_status *inf_status; | |
3592 | int regno; | |
3593 | LONGEST val; | |
3594 | { | |
3595 | int size = REGISTER_RAW_SIZE(regno); | |
3596 | void *buf = alloca (size); | |
3597 | store_signed_integer (buf, size, val); | |
3598 | memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size); | |
3599 | } | |
3600 | ||
3601 | ||
3602 | ||
c906108c SS |
3603 | /* Save all of the information associated with the inferior<==>gdb |
3604 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
3605 | (defined in inferior.h). */ | |
3606 | ||
7a292a7a SS |
3607 | struct inferior_status * |
3608 | save_inferior_status (restore_stack_info) | |
c906108c SS |
3609 | int restore_stack_info; |
3610 | { | |
7a292a7a SS |
3611 | struct inferior_status *inf_status = xmalloc_inferior_status (); |
3612 | ||
c906108c SS |
3613 | inf_status->stop_signal = stop_signal; |
3614 | inf_status->stop_pc = stop_pc; | |
3615 | inf_status->stop_step = stop_step; | |
3616 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
3617 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
3618 | inf_status->trap_expected = trap_expected; | |
3619 | inf_status->step_range_start = step_range_start; | |
3620 | inf_status->step_range_end = step_range_end; | |
3621 | inf_status->step_frame_address = step_frame_address; | |
3622 | inf_status->step_over_calls = step_over_calls; | |
3623 | inf_status->stop_after_trap = stop_after_trap; | |
3624 | inf_status->stop_soon_quietly = stop_soon_quietly; | |
3625 | /* Save original bpstat chain here; replace it with copy of chain. | |
3626 | If caller's caller is walking the chain, they'll be happier if we | |
7a292a7a SS |
3627 | hand them back the original chain when restore_inferior_status is |
3628 | called. */ | |
c906108c SS |
3629 | inf_status->stop_bpstat = stop_bpstat; |
3630 | stop_bpstat = bpstat_copy (stop_bpstat); | |
3631 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
3632 | inf_status->restore_stack_info = restore_stack_info; | |
3633 | inf_status->proceed_to_finish = proceed_to_finish; | |
7a292a7a | 3634 | |
c906108c SS |
3635 | memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); |
3636 | ||
3637 | read_register_bytes (0, inf_status->registers, REGISTER_BYTES); | |
3638 | ||
3639 | record_selected_frame (&(inf_status->selected_frame_address), | |
3640 | &(inf_status->selected_level)); | |
7a292a7a | 3641 | return inf_status; |
c906108c SS |
3642 | } |
3643 | ||
3644 | struct restore_selected_frame_args | |
3645 | { | |
3646 | CORE_ADDR frame_address; | |
3647 | int level; | |
3648 | }; | |
3649 | ||
3650 | static int restore_selected_frame PARAMS ((PTR)); | |
3651 | ||
c906108c SS |
3652 | static int |
3653 | restore_selected_frame (args) | |
3654 | PTR args; | |
3655 | { | |
3656 | struct restore_selected_frame_args *fr = | |
3657 | (struct restore_selected_frame_args *) args; | |
3658 | struct frame_info *frame; | |
3659 | int level = fr->level; | |
3660 | ||
3661 | frame = find_relative_frame (get_current_frame (), &level); | |
3662 | ||
3663 | /* If inf_status->selected_frame_address is NULL, there was no | |
3664 | previously selected frame. */ | |
3665 | if (frame == NULL || | |
3666 | /* FRAME_FP (frame) != fr->frame_address || */ | |
3667 | /* elz: deleted this check as a quick fix to the problem that | |
3668 | for function called by hand gdb creates no internal frame | |
3669 | structure and the real stack and gdb's idea of stack are | |
3670 | different if nested calls by hands are made. | |
3671 | ||
3672 | mvs: this worries me. */ | |
3673 | level != 0) | |
3674 | { | |
3675 | warning ("Unable to restore previously selected frame.\n"); | |
3676 | return 0; | |
3677 | } | |
3678 | ||
3679 | select_frame (frame, fr->level); | |
3680 | ||
3681 | return (1); | |
3682 | } | |
3683 | ||
3684 | void | |
3685 | restore_inferior_status (inf_status) | |
3686 | struct inferior_status *inf_status; | |
3687 | { | |
3688 | stop_signal = inf_status->stop_signal; | |
3689 | stop_pc = inf_status->stop_pc; | |
3690 | stop_step = inf_status->stop_step; | |
3691 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
3692 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
3693 | trap_expected = inf_status->trap_expected; | |
3694 | step_range_start = inf_status->step_range_start; | |
3695 | step_range_end = inf_status->step_range_end; | |
3696 | step_frame_address = inf_status->step_frame_address; | |
3697 | step_over_calls = inf_status->step_over_calls; | |
3698 | stop_after_trap = inf_status->stop_after_trap; | |
3699 | stop_soon_quietly = inf_status->stop_soon_quietly; | |
3700 | bpstat_clear (&stop_bpstat); | |
3701 | stop_bpstat = inf_status->stop_bpstat; | |
3702 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
3703 | proceed_to_finish = inf_status->proceed_to_finish; | |
3704 | ||
7a292a7a | 3705 | /* FIXME: Is the restore of stop_registers always needed */ |
c906108c SS |
3706 | memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); |
3707 | ||
3708 | /* The inferior can be gone if the user types "print exit(0)" | |
3709 | (and perhaps other times). */ | |
3710 | if (target_has_execution) | |
3711 | write_register_bytes (0, inf_status->registers, REGISTER_BYTES); | |
3712 | ||
c906108c SS |
3713 | /* FIXME: If we are being called after stopping in a function which |
3714 | is called from gdb, we should not be trying to restore the | |
3715 | selected frame; it just prints a spurious error message (The | |
3716 | message is useful, however, in detecting bugs in gdb (like if gdb | |
3717 | clobbers the stack)). In fact, should we be restoring the | |
3718 | inferior status at all in that case? . */ | |
3719 | ||
3720 | if (target_has_stack && inf_status->restore_stack_info) | |
3721 | { | |
3722 | struct restore_selected_frame_args fr; | |
3723 | fr.level = inf_status->selected_level; | |
3724 | fr.frame_address = inf_status->selected_frame_address; | |
3725 | /* The point of catch_errors is that if the stack is clobbered, | |
3726 | walking the stack might encounter a garbage pointer and error() | |
3727 | trying to dereference it. */ | |
3728 | if (catch_errors (restore_selected_frame, &fr, | |
3729 | "Unable to restore previously selected frame:\n", | |
3730 | RETURN_MASK_ERROR) == 0) | |
3731 | /* Error in restoring the selected frame. Select the innermost | |
3732 | frame. */ | |
3733 | ||
3734 | ||
3735 | select_frame (get_current_frame (), 0); | |
3736 | ||
3737 | } | |
c906108c | 3738 | |
7a292a7a SS |
3739 | free_inferior_status (inf_status); |
3740 | } | |
c906108c SS |
3741 | |
3742 | void | |
7a292a7a SS |
3743 | discard_inferior_status (inf_status) |
3744 | struct inferior_status *inf_status; | |
3745 | { | |
3746 | /* See save_inferior_status for info on stop_bpstat. */ | |
3747 | bpstat_clear (&inf_status->stop_bpstat); | |
3748 | free_inferior_status (inf_status); | |
3749 | } | |
3750 | ||
3751 | static void | |
c906108c SS |
3752 | set_follow_fork_mode_command (arg, from_tty, c) |
3753 | char *arg; | |
3754 | int from_tty; | |
3755 | struct cmd_list_element *c; | |
3756 | { | |
3757 | if (!STREQ (arg, "parent") && | |
3758 | !STREQ (arg, "child") && | |
3759 | !STREQ (arg, "both") && | |
3760 | !STREQ (arg, "ask")) | |
3761 | error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\"."); | |
3762 | ||
3763 | if (follow_fork_mode_string != NULL) | |
3764 | free (follow_fork_mode_string); | |
3765 | follow_fork_mode_string = savestring (arg, strlen (arg)); | |
3766 | } | |
7a292a7a SS |
3767 | |
3768 | ||
c906108c | 3769 | \f |
7a292a7a SS |
3770 | static void build_infrun PARAMS ((void)); |
3771 | static void | |
3772 | build_infrun () | |
3773 | { | |
3774 | stop_registers = xmalloc (REGISTER_BYTES); | |
3775 | } | |
c906108c SS |
3776 | |
3777 | ||
3778 | void | |
3779 | _initialize_infrun () | |
3780 | { | |
3781 | register int i; | |
3782 | register int numsigs; | |
3783 | struct cmd_list_element *c; | |
3784 | ||
7a292a7a SS |
3785 | build_infrun (); |
3786 | ||
c906108c SS |
3787 | add_info ("signals", signals_info, |
3788 | "What debugger does when program gets various signals.\n\ | |
3789 | Specify a signal as argument to print info on that signal only."); | |
3790 | add_info_alias ("handle", "signals", 0); | |
3791 | ||
3792 | add_com ("handle", class_run, handle_command, | |
3793 | concat ("Specify how to handle a signal.\n\ | |
3794 | Args are signals and actions to apply to those signals.\n\ | |
3795 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
3796 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
3797 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
3798 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
3799 | used by the debugger, typically SIGTRAP and SIGINT.\n", | |
3800 | "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
3801 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ | |
3802 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
3803 | Print means print a message if this signal happens.\n\ | |
3804 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
3805 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
3806 | Pass and Stop may be combined.", NULL)); | |
3807 | if (xdb_commands) | |
3808 | { | |
3809 | add_com ("lz", class_info, signals_info, | |
3810 | "What debugger does when program gets various signals.\n\ | |
3811 | Specify a signal as argument to print info on that signal only."); | |
3812 | add_com ("z", class_run, xdb_handle_command, | |
3813 | concat ("Specify how to handle a signal.\n\ | |
3814 | Args are signals and actions to apply to those signals.\n\ | |
3815 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
3816 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
3817 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
3818 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
3819 | used by the debugger, typically SIGTRAP and SIGINT.\n", | |
3820 | "Recognized actions include \"s\" (toggles between stop and nostop), \n\ | |
3821 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ | |
3822 | nopass), \"Q\" (noprint)\n\ | |
3823 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
3824 | Print means print a message if this signal happens.\n\ | |
3825 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
3826 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
3827 | Pass and Stop may be combined.", NULL)); | |
3828 | } | |
3829 | ||
3830 | if (!dbx_commands) | |
3831 | stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command, | |
3832 | "There is no `stop' command, but you can set a hook on `stop'.\n\ | |
3833 | This allows you to set a list of commands to be run each time execution\n\ | |
3834 | of the program stops.", &cmdlist); | |
3835 | ||
3836 | numsigs = (int) TARGET_SIGNAL_LAST; | |
3837 | signal_stop = (unsigned char *) | |
3838 | xmalloc (sizeof (signal_stop[0]) * numsigs); | |
3839 | signal_print = (unsigned char *) | |
3840 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
3841 | signal_program = (unsigned char *) | |
3842 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
3843 | for (i = 0; i < numsigs; i++) | |
3844 | { | |
3845 | signal_stop[i] = 1; | |
3846 | signal_print[i] = 1; | |
3847 | signal_program[i] = 1; | |
3848 | } | |
3849 | ||
3850 | /* Signals caused by debugger's own actions | |
3851 | should not be given to the program afterwards. */ | |
3852 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
3853 | signal_program[TARGET_SIGNAL_INT] = 0; | |
3854 | ||
3855 | /* Signals that are not errors should not normally enter the debugger. */ | |
3856 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
3857 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
3858 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
3859 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
3860 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
3861 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
3862 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
3863 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
3864 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
3865 | signal_print[TARGET_SIGNAL_IO] = 0; | |
3866 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
3867 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
3868 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
3869 | signal_print[TARGET_SIGNAL_URG] = 0; | |
3870 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
3871 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
3872 | ||
cd0fc7c3 SS |
3873 | /* These signals are used internally by user-level thread |
3874 | implementations. (See signal(5) on Solaris.) Like the above | |
3875 | signals, a healthy program receives and handles them as part of | |
3876 | its normal operation. */ | |
3877 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
3878 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
3879 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
3880 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
3881 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
3882 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
3883 | ||
c906108c SS |
3884 | #ifdef SOLIB_ADD |
3885 | add_show_from_set | |
3886 | (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, | |
3887 | (char *) &stop_on_solib_events, | |
3888 | "Set stopping for shared library events.\n\ | |
3889 | If nonzero, gdb will give control to the user when the dynamic linker\n\ | |
3890 | notifies gdb of shared library events. The most common event of interest\n\ | |
3891 | to the user would be loading/unloading of a new library.\n", | |
3892 | &setlist), | |
3893 | &showlist); | |
3894 | #endif | |
3895 | ||
3896 | c = add_set_enum_cmd ("follow-fork-mode", | |
3897 | class_run, | |
3898 | follow_fork_mode_kind_names, | |
3899 | (char *) &follow_fork_mode_string, | |
3900 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 | |
3901 | kernel problem. It's also not terribly useful without a GUI to | |
3902 | help the user drive two debuggers. So for now, I'm disabling | |
3903 | the "both" option. */ | |
3904 | /* "Set debugger response to a program call of fork \ | |
3905 | or vfork.\n\ | |
3906 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
3907 | parent - the original process is debugged after a fork\n\ | |
3908 | child - the new process is debugged after a fork\n\ | |
3909 | both - both the parent and child are debugged after a fork\n\ | |
3910 | ask - the debugger will ask for one of the above choices\n\ | |
3911 | For \"both\", another copy of the debugger will be started to follow\n\ | |
3912 | the new child process. The original debugger will continue to follow\n\ | |
3913 | the original parent process. To distinguish their prompts, the\n\ | |
3914 | debugger copy's prompt will be changed.\n\ | |
3915 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
3916 | By default, the debugger will follow the parent process.", | |
3917 | */ | |
3918 | "Set debugger response to a program call of fork \ | |
3919 | or vfork.\n\ | |
3920 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
3921 | parent - the original process is debugged after a fork\n\ | |
3922 | child - the new process is debugged after a fork\n\ | |
3923 | ask - the debugger will ask for one of the above choices\n\ | |
3924 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
3925 | By default, the debugger will follow the parent process.", | |
3926 | &setlist); | |
3927 | /* c->function.sfunc = ;*/ | |
3928 | add_show_from_set (c, &showlist); | |
3929 | ||
3930 | set_follow_fork_mode_command ("parent", 0, NULL); | |
3931 | ||
3932 | c = add_set_enum_cmd ("scheduler-locking", class_run, | |
3933 | scheduler_enums, /* array of string names */ | |
3934 | (char *) &scheduler_mode, /* current mode */ | |
3935 | "Set mode for locking scheduler during execution.\n\ | |
3936 | off == no locking (threads may preempt at any time)\n\ | |
3937 | on == full locking (no thread except the current thread may run)\n\ | |
3938 | step == scheduler locked during every single-step operation.\n\ | |
3939 | In this mode, no other thread may run during a step command.\n\ | |
3940 | Other threads may run while stepping over a function call ('next').", | |
3941 | &setlist); | |
3942 | ||
3943 | c->function.sfunc = set_schedlock_func; /* traps on target vector */ | |
3944 | add_show_from_set (c, &showlist); | |
3945 | } |