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