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