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