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