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