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