Commit | Line | Data |
---|---|---|
ca557f44 AC |
1 | /* Target-struct-independent code to start (run) and stop an inferior |
2 | process. | |
8926118c | 3 | |
32d0add0 | 4 | Copyright (C) 1986-2015 Free Software Foundation, Inc. |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #include "defs.h" | |
45741a9c | 22 | #include "infrun.h" |
c906108c SS |
23 | #include <ctype.h> |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
27 | #include "breakpoint.h" | |
03f2053f | 28 | #include "gdb_wait.h" |
c906108c SS |
29 | #include "gdbcore.h" |
30 | #include "gdbcmd.h" | |
210661e7 | 31 | #include "cli/cli-script.h" |
c906108c SS |
32 | #include "target.h" |
33 | #include "gdbthread.h" | |
34 | #include "annotate.h" | |
1adeb98a | 35 | #include "symfile.h" |
7a292a7a | 36 | #include "top.h" |
c906108c | 37 | #include <signal.h> |
2acceee2 | 38 | #include "inf-loop.h" |
4e052eda | 39 | #include "regcache.h" |
fd0407d6 | 40 | #include "value.h" |
06600e06 | 41 | #include "observer.h" |
f636b87d | 42 | #include "language.h" |
a77053c2 | 43 | #include "solib.h" |
f17517ea | 44 | #include "main.h" |
186c406b TT |
45 | #include "dictionary.h" |
46 | #include "block.h" | |
034dad6f | 47 | #include "mi/mi-common.h" |
4f8d22e3 | 48 | #include "event-top.h" |
96429cc8 | 49 | #include "record.h" |
d02ed0bb | 50 | #include "record-full.h" |
edb3359d | 51 | #include "inline-frame.h" |
4efc6507 | 52 | #include "jit.h" |
06cd862c | 53 | #include "tracepoint.h" |
be34f849 | 54 | #include "continuations.h" |
b4a14fd0 | 55 | #include "interps.h" |
1bfeeb0f | 56 | #include "skip.h" |
28106bc2 SDJ |
57 | #include "probe.h" |
58 | #include "objfiles.h" | |
de0bea00 | 59 | #include "completer.h" |
9107fc8d | 60 | #include "target-descriptions.h" |
f15cb84a | 61 | #include "target-dcache.h" |
d83ad864 | 62 | #include "terminal.h" |
ff862be4 | 63 | #include "solist.h" |
c906108c SS |
64 | |
65 | /* Prototypes for local functions */ | |
66 | ||
96baa820 | 67 | static void signals_info (char *, int); |
c906108c | 68 | |
96baa820 | 69 | static void handle_command (char *, int); |
c906108c | 70 | |
2ea28649 | 71 | static void sig_print_info (enum gdb_signal); |
c906108c | 72 | |
96baa820 | 73 | static void sig_print_header (void); |
c906108c | 74 | |
74b7792f | 75 | static void resume_cleanups (void *); |
c906108c | 76 | |
96baa820 | 77 | static int hook_stop_stub (void *); |
c906108c | 78 | |
96baa820 JM |
79 | static int restore_selected_frame (void *); |
80 | ||
4ef3f3be | 81 | static int follow_fork (void); |
96baa820 | 82 | |
d83ad864 DB |
83 | static int follow_fork_inferior (int follow_child, int detach_fork); |
84 | ||
85 | static void follow_inferior_reset_breakpoints (void); | |
86 | ||
96baa820 | 87 | static void set_schedlock_func (char *args, int from_tty, |
488f131b | 88 | struct cmd_list_element *c); |
96baa820 | 89 | |
a289b8f6 JK |
90 | static int currently_stepping (struct thread_info *tp); |
91 | ||
96baa820 | 92 | void _initialize_infrun (void); |
43ff13b4 | 93 | |
e58b0e63 PA |
94 | void nullify_last_target_wait_ptid (void); |
95 | ||
2c03e5be | 96 | static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *); |
2484c66b UW |
97 | |
98 | static void insert_step_resume_breakpoint_at_caller (struct frame_info *); | |
99 | ||
2484c66b UW |
100 | static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR); |
101 | ||
8550d3b3 YQ |
102 | static int maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc); |
103 | ||
5fbbeb29 CF |
104 | /* When set, stop the 'step' command if we enter a function which has |
105 | no line number information. The normal behavior is that we step | |
106 | over such function. */ | |
107 | int step_stop_if_no_debug = 0; | |
920d2a44 AC |
108 | static void |
109 | show_step_stop_if_no_debug (struct ui_file *file, int from_tty, | |
110 | struct cmd_list_element *c, const char *value) | |
111 | { | |
112 | fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value); | |
113 | } | |
5fbbeb29 | 114 | |
1777feb0 | 115 | /* In asynchronous mode, but simulating synchronous execution. */ |
96baa820 | 116 | |
43ff13b4 JM |
117 | int sync_execution = 0; |
118 | ||
b9f437de PA |
119 | /* proceed and normal_stop use this to notify the user when the |
120 | inferior stopped in a different thread than it had been running | |
121 | in. */ | |
96baa820 | 122 | |
39f77062 | 123 | static ptid_t previous_inferior_ptid; |
7a292a7a | 124 | |
07107ca6 LM |
125 | /* If set (default for legacy reasons), when following a fork, GDB |
126 | will detach from one of the fork branches, child or parent. | |
127 | Exactly which branch is detached depends on 'set follow-fork-mode' | |
128 | setting. */ | |
129 | ||
130 | static int detach_fork = 1; | |
6c95b8df | 131 | |
237fc4c9 PA |
132 | int debug_displaced = 0; |
133 | static void | |
134 | show_debug_displaced (struct ui_file *file, int from_tty, | |
135 | struct cmd_list_element *c, const char *value) | |
136 | { | |
137 | fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value); | |
138 | } | |
139 | ||
ccce17b0 | 140 | unsigned int debug_infrun = 0; |
920d2a44 AC |
141 | static void |
142 | show_debug_infrun (struct ui_file *file, int from_tty, | |
143 | struct cmd_list_element *c, const char *value) | |
144 | { | |
145 | fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); | |
146 | } | |
527159b7 | 147 | |
03583c20 UW |
148 | |
149 | /* Support for disabling address space randomization. */ | |
150 | ||
151 | int disable_randomization = 1; | |
152 | ||
153 | static void | |
154 | show_disable_randomization (struct ui_file *file, int from_tty, | |
155 | struct cmd_list_element *c, const char *value) | |
156 | { | |
157 | if (target_supports_disable_randomization ()) | |
158 | fprintf_filtered (file, | |
159 | _("Disabling randomization of debuggee's " | |
160 | "virtual address space is %s.\n"), | |
161 | value); | |
162 | else | |
163 | fputs_filtered (_("Disabling randomization of debuggee's " | |
164 | "virtual address space is unsupported on\n" | |
165 | "this platform.\n"), file); | |
166 | } | |
167 | ||
168 | static void | |
169 | set_disable_randomization (char *args, int from_tty, | |
170 | struct cmd_list_element *c) | |
171 | { | |
172 | if (!target_supports_disable_randomization ()) | |
173 | error (_("Disabling randomization of debuggee's " | |
174 | "virtual address space is unsupported on\n" | |
175 | "this platform.")); | |
176 | } | |
177 | ||
d32dc48e PA |
178 | /* User interface for non-stop mode. */ |
179 | ||
180 | int non_stop = 0; | |
181 | static int non_stop_1 = 0; | |
182 | ||
183 | static void | |
184 | set_non_stop (char *args, int from_tty, | |
185 | struct cmd_list_element *c) | |
186 | { | |
187 | if (target_has_execution) | |
188 | { | |
189 | non_stop_1 = non_stop; | |
190 | error (_("Cannot change this setting while the inferior is running.")); | |
191 | } | |
192 | ||
193 | non_stop = non_stop_1; | |
194 | } | |
195 | ||
196 | static void | |
197 | show_non_stop (struct ui_file *file, int from_tty, | |
198 | struct cmd_list_element *c, const char *value) | |
199 | { | |
200 | fprintf_filtered (file, | |
201 | _("Controlling the inferior in non-stop mode is %s.\n"), | |
202 | value); | |
203 | } | |
204 | ||
d914c394 SS |
205 | /* "Observer mode" is somewhat like a more extreme version of |
206 | non-stop, in which all GDB operations that might affect the | |
207 | target's execution have been disabled. */ | |
208 | ||
d914c394 SS |
209 | int observer_mode = 0; |
210 | static int observer_mode_1 = 0; | |
211 | ||
212 | static void | |
213 | set_observer_mode (char *args, int from_tty, | |
214 | struct cmd_list_element *c) | |
215 | { | |
d914c394 SS |
216 | if (target_has_execution) |
217 | { | |
218 | observer_mode_1 = observer_mode; | |
219 | error (_("Cannot change this setting while the inferior is running.")); | |
220 | } | |
221 | ||
222 | observer_mode = observer_mode_1; | |
223 | ||
224 | may_write_registers = !observer_mode; | |
225 | may_write_memory = !observer_mode; | |
226 | may_insert_breakpoints = !observer_mode; | |
227 | may_insert_tracepoints = !observer_mode; | |
228 | /* We can insert fast tracepoints in or out of observer mode, | |
229 | but enable them if we're going into this mode. */ | |
230 | if (observer_mode) | |
231 | may_insert_fast_tracepoints = 1; | |
232 | may_stop = !observer_mode; | |
233 | update_target_permissions (); | |
234 | ||
235 | /* Going *into* observer mode we must force non-stop, then | |
236 | going out we leave it that way. */ | |
237 | if (observer_mode) | |
238 | { | |
d914c394 SS |
239 | pagination_enabled = 0; |
240 | non_stop = non_stop_1 = 1; | |
241 | } | |
242 | ||
243 | if (from_tty) | |
244 | printf_filtered (_("Observer mode is now %s.\n"), | |
245 | (observer_mode ? "on" : "off")); | |
246 | } | |
247 | ||
248 | static void | |
249 | show_observer_mode (struct ui_file *file, int from_tty, | |
250 | struct cmd_list_element *c, const char *value) | |
251 | { | |
252 | fprintf_filtered (file, _("Observer mode is %s.\n"), value); | |
253 | } | |
254 | ||
255 | /* This updates the value of observer mode based on changes in | |
256 | permissions. Note that we are deliberately ignoring the values of | |
257 | may-write-registers and may-write-memory, since the user may have | |
258 | reason to enable these during a session, for instance to turn on a | |
259 | debugging-related global. */ | |
260 | ||
261 | void | |
262 | update_observer_mode (void) | |
263 | { | |
264 | int newval; | |
265 | ||
266 | newval = (!may_insert_breakpoints | |
267 | && !may_insert_tracepoints | |
268 | && may_insert_fast_tracepoints | |
269 | && !may_stop | |
270 | && non_stop); | |
271 | ||
272 | /* Let the user know if things change. */ | |
273 | if (newval != observer_mode) | |
274 | printf_filtered (_("Observer mode is now %s.\n"), | |
275 | (newval ? "on" : "off")); | |
276 | ||
277 | observer_mode = observer_mode_1 = newval; | |
278 | } | |
c2c6d25f | 279 | |
c906108c SS |
280 | /* Tables of how to react to signals; the user sets them. */ |
281 | ||
282 | static unsigned char *signal_stop; | |
283 | static unsigned char *signal_print; | |
284 | static unsigned char *signal_program; | |
285 | ||
ab04a2af TT |
286 | /* Table of signals that are registered with "catch signal". A |
287 | non-zero entry indicates that the signal is caught by some "catch | |
288 | signal" command. This has size GDB_SIGNAL_LAST, to accommodate all | |
289 | signals. */ | |
290 | static unsigned char *signal_catch; | |
291 | ||
2455069d UW |
292 | /* Table of signals that the target may silently handle. |
293 | This is automatically determined from the flags above, | |
294 | and simply cached here. */ | |
295 | static unsigned char *signal_pass; | |
296 | ||
c906108c SS |
297 | #define SET_SIGS(nsigs,sigs,flags) \ |
298 | do { \ | |
299 | int signum = (nsigs); \ | |
300 | while (signum-- > 0) \ | |
301 | if ((sigs)[signum]) \ | |
302 | (flags)[signum] = 1; \ | |
303 | } while (0) | |
304 | ||
305 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
306 | do { \ | |
307 | int signum = (nsigs); \ | |
308 | while (signum-- > 0) \ | |
309 | if ((sigs)[signum]) \ | |
310 | (flags)[signum] = 0; \ | |
311 | } while (0) | |
312 | ||
9b224c5e PA |
313 | /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of |
314 | this function is to avoid exporting `signal_program'. */ | |
315 | ||
316 | void | |
317 | update_signals_program_target (void) | |
318 | { | |
a493e3e2 | 319 | target_program_signals ((int) GDB_SIGNAL_LAST, signal_program); |
9b224c5e PA |
320 | } |
321 | ||
1777feb0 | 322 | /* Value to pass to target_resume() to cause all threads to resume. */ |
39f77062 | 323 | |
edb3359d | 324 | #define RESUME_ALL minus_one_ptid |
c906108c SS |
325 | |
326 | /* Command list pointer for the "stop" placeholder. */ | |
327 | ||
328 | static struct cmd_list_element *stop_command; | |
329 | ||
c906108c SS |
330 | /* Nonzero if we want to give control to the user when we're notified |
331 | of shared library events by the dynamic linker. */ | |
628fe4e4 | 332 | int stop_on_solib_events; |
f9e14852 GB |
333 | |
334 | /* Enable or disable optional shared library event breakpoints | |
335 | as appropriate when the above flag is changed. */ | |
336 | ||
337 | static void | |
338 | set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c) | |
339 | { | |
340 | update_solib_breakpoints (); | |
341 | } | |
342 | ||
920d2a44 AC |
343 | static void |
344 | show_stop_on_solib_events (struct ui_file *file, int from_tty, | |
345 | struct cmd_list_element *c, const char *value) | |
346 | { | |
347 | fprintf_filtered (file, _("Stopping for shared library events is %s.\n"), | |
348 | value); | |
349 | } | |
c906108c | 350 | |
c906108c SS |
351 | /* Nonzero means expecting a trace trap |
352 | and should stop the inferior and return silently when it happens. */ | |
353 | ||
354 | int stop_after_trap; | |
355 | ||
642fd101 DE |
356 | /* Save register contents here when executing a "finish" command or are |
357 | about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set. | |
c906108c SS |
358 | Thus this contains the return value from the called function (assuming |
359 | values are returned in a register). */ | |
360 | ||
72cec141 | 361 | struct regcache *stop_registers; |
c906108c | 362 | |
c906108c SS |
363 | /* Nonzero after stop if current stack frame should be printed. */ |
364 | ||
365 | static int stop_print_frame; | |
366 | ||
e02bc4cc | 367 | /* This is a cached copy of the pid/waitstatus of the last event |
9a4105ab AC |
368 | returned by target_wait()/deprecated_target_wait_hook(). This |
369 | information is returned by get_last_target_status(). */ | |
39f77062 | 370 | static ptid_t target_last_wait_ptid; |
e02bc4cc DS |
371 | static struct target_waitstatus target_last_waitstatus; |
372 | ||
0d1e5fa7 PA |
373 | static void context_switch (ptid_t ptid); |
374 | ||
4e1c45ea | 375 | void init_thread_stepping_state (struct thread_info *tss); |
0d1e5fa7 | 376 | |
53904c9e AC |
377 | static const char follow_fork_mode_child[] = "child"; |
378 | static const char follow_fork_mode_parent[] = "parent"; | |
379 | ||
40478521 | 380 | static const char *const follow_fork_mode_kind_names[] = { |
53904c9e AC |
381 | follow_fork_mode_child, |
382 | follow_fork_mode_parent, | |
383 | NULL | |
ef346e04 | 384 | }; |
c906108c | 385 | |
53904c9e | 386 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
920d2a44 AC |
387 | static void |
388 | show_follow_fork_mode_string (struct ui_file *file, int from_tty, | |
389 | struct cmd_list_element *c, const char *value) | |
390 | { | |
3e43a32a MS |
391 | fprintf_filtered (file, |
392 | _("Debugger response to a program " | |
393 | "call of fork or vfork is \"%s\".\n"), | |
920d2a44 AC |
394 | value); |
395 | } | |
c906108c SS |
396 | \f |
397 | ||
d83ad864 DB |
398 | /* Handle changes to the inferior list based on the type of fork, |
399 | which process is being followed, and whether the other process | |
400 | should be detached. On entry inferior_ptid must be the ptid of | |
401 | the fork parent. At return inferior_ptid is the ptid of the | |
402 | followed inferior. */ | |
403 | ||
404 | static int | |
405 | follow_fork_inferior (int follow_child, int detach_fork) | |
406 | { | |
407 | int has_vforked; | |
79639e11 | 408 | ptid_t parent_ptid, child_ptid; |
d83ad864 DB |
409 | |
410 | has_vforked = (inferior_thread ()->pending_follow.kind | |
411 | == TARGET_WAITKIND_VFORKED); | |
79639e11 PA |
412 | parent_ptid = inferior_ptid; |
413 | child_ptid = inferior_thread ()->pending_follow.value.related_pid; | |
d83ad864 DB |
414 | |
415 | if (has_vforked | |
416 | && !non_stop /* Non-stop always resumes both branches. */ | |
417 | && (!target_is_async_p () || sync_execution) | |
418 | && !(follow_child || detach_fork || sched_multi)) | |
419 | { | |
420 | /* The parent stays blocked inside the vfork syscall until the | |
421 | child execs or exits. If we don't let the child run, then | |
422 | the parent stays blocked. If we're telling the parent to run | |
423 | in the foreground, the user will not be able to ctrl-c to get | |
424 | back the terminal, effectively hanging the debug session. */ | |
425 | fprintf_filtered (gdb_stderr, _("\ | |
426 | Can not resume the parent process over vfork in the foreground while\n\ | |
427 | holding the child stopped. Try \"set detach-on-fork\" or \ | |
428 | \"set schedule-multiple\".\n")); | |
429 | /* FIXME output string > 80 columns. */ | |
430 | return 1; | |
431 | } | |
432 | ||
433 | if (!follow_child) | |
434 | { | |
435 | /* Detach new forked process? */ | |
436 | if (detach_fork) | |
437 | { | |
438 | struct cleanup *old_chain; | |
439 | ||
440 | /* Before detaching from the child, remove all breakpoints | |
441 | from it. If we forked, then this has already been taken | |
442 | care of by infrun.c. If we vforked however, any | |
443 | breakpoint inserted in the parent is visible in the | |
444 | child, even those added while stopped in a vfork | |
445 | catchpoint. This will remove the breakpoints from the | |
446 | parent also, but they'll be reinserted below. */ | |
447 | if (has_vforked) | |
448 | { | |
449 | /* Keep breakpoints list in sync. */ | |
450 | remove_breakpoints_pid (ptid_get_pid (inferior_ptid)); | |
451 | } | |
452 | ||
453 | if (info_verbose || debug_infrun) | |
454 | { | |
6f259a23 | 455 | target_terminal_ours_for_output (); |
d83ad864 | 456 | fprintf_filtered (gdb_stdlog, |
79639e11 | 457 | _("Detaching after %s from child %s.\n"), |
6f259a23 | 458 | has_vforked ? "vfork" : "fork", |
79639e11 | 459 | target_pid_to_str (child_ptid)); |
d83ad864 DB |
460 | } |
461 | } | |
462 | else | |
463 | { | |
464 | struct inferior *parent_inf, *child_inf; | |
465 | struct cleanup *old_chain; | |
466 | ||
467 | /* Add process to GDB's tables. */ | |
79639e11 | 468 | child_inf = add_inferior (ptid_get_pid (child_ptid)); |
d83ad864 DB |
469 | |
470 | parent_inf = current_inferior (); | |
471 | child_inf->attach_flag = parent_inf->attach_flag; | |
472 | copy_terminal_info (child_inf, parent_inf); | |
473 | child_inf->gdbarch = parent_inf->gdbarch; | |
474 | copy_inferior_target_desc_info (child_inf, parent_inf); | |
475 | ||
476 | old_chain = save_inferior_ptid (); | |
477 | save_current_program_space (); | |
478 | ||
79639e11 | 479 | inferior_ptid = child_ptid; |
d83ad864 DB |
480 | add_thread (inferior_ptid); |
481 | child_inf->symfile_flags = SYMFILE_NO_READ; | |
482 | ||
483 | /* If this is a vfork child, then the address-space is | |
484 | shared with the parent. */ | |
485 | if (has_vforked) | |
486 | { | |
487 | child_inf->pspace = parent_inf->pspace; | |
488 | child_inf->aspace = parent_inf->aspace; | |
489 | ||
490 | /* The parent will be frozen until the child is done | |
491 | with the shared region. Keep track of the | |
492 | parent. */ | |
493 | child_inf->vfork_parent = parent_inf; | |
494 | child_inf->pending_detach = 0; | |
495 | parent_inf->vfork_child = child_inf; | |
496 | parent_inf->pending_detach = 0; | |
497 | } | |
498 | else | |
499 | { | |
500 | child_inf->aspace = new_address_space (); | |
501 | child_inf->pspace = add_program_space (child_inf->aspace); | |
502 | child_inf->removable = 1; | |
503 | set_current_program_space (child_inf->pspace); | |
504 | clone_program_space (child_inf->pspace, parent_inf->pspace); | |
505 | ||
506 | /* Let the shared library layer (e.g., solib-svr4) learn | |
507 | about this new process, relocate the cloned exec, pull | |
508 | in shared libraries, and install the solib event | |
509 | breakpoint. If a "cloned-VM" event was propagated | |
510 | better throughout the core, this wouldn't be | |
511 | required. */ | |
512 | solib_create_inferior_hook (0); | |
513 | } | |
514 | ||
515 | do_cleanups (old_chain); | |
516 | } | |
517 | ||
518 | if (has_vforked) | |
519 | { | |
520 | struct inferior *parent_inf; | |
521 | ||
522 | parent_inf = current_inferior (); | |
523 | ||
524 | /* If we detached from the child, then we have to be careful | |
525 | to not insert breakpoints in the parent until the child | |
526 | is done with the shared memory region. However, if we're | |
527 | staying attached to the child, then we can and should | |
528 | insert breakpoints, so that we can debug it. A | |
529 | subsequent child exec or exit is enough to know when does | |
530 | the child stops using the parent's address space. */ | |
531 | parent_inf->waiting_for_vfork_done = detach_fork; | |
532 | parent_inf->pspace->breakpoints_not_allowed = detach_fork; | |
533 | } | |
534 | } | |
535 | else | |
536 | { | |
537 | /* Follow the child. */ | |
538 | struct inferior *parent_inf, *child_inf; | |
539 | struct program_space *parent_pspace; | |
540 | ||
541 | if (info_verbose || debug_infrun) | |
542 | { | |
6f259a23 DB |
543 | target_terminal_ours_for_output (); |
544 | fprintf_filtered (gdb_stdlog, | |
79639e11 PA |
545 | _("Attaching after %s %s to child %s.\n"), |
546 | target_pid_to_str (parent_ptid), | |
6f259a23 | 547 | has_vforked ? "vfork" : "fork", |
79639e11 | 548 | target_pid_to_str (child_ptid)); |
d83ad864 DB |
549 | } |
550 | ||
551 | /* Add the new inferior first, so that the target_detach below | |
552 | doesn't unpush the target. */ | |
553 | ||
79639e11 | 554 | child_inf = add_inferior (ptid_get_pid (child_ptid)); |
d83ad864 DB |
555 | |
556 | parent_inf = current_inferior (); | |
557 | child_inf->attach_flag = parent_inf->attach_flag; | |
558 | copy_terminal_info (child_inf, parent_inf); | |
559 | child_inf->gdbarch = parent_inf->gdbarch; | |
560 | copy_inferior_target_desc_info (child_inf, parent_inf); | |
561 | ||
562 | parent_pspace = parent_inf->pspace; | |
563 | ||
564 | /* If we're vforking, we want to hold on to the parent until the | |
565 | child exits or execs. At child exec or exit time we can | |
566 | remove the old breakpoints from the parent and detach or | |
567 | resume debugging it. Otherwise, detach the parent now; we'll | |
568 | want to reuse it's program/address spaces, but we can't set | |
569 | them to the child before removing breakpoints from the | |
570 | parent, otherwise, the breakpoints module could decide to | |
571 | remove breakpoints from the wrong process (since they'd be | |
572 | assigned to the same address space). */ | |
573 | ||
574 | if (has_vforked) | |
575 | { | |
576 | gdb_assert (child_inf->vfork_parent == NULL); | |
577 | gdb_assert (parent_inf->vfork_child == NULL); | |
578 | child_inf->vfork_parent = parent_inf; | |
579 | child_inf->pending_detach = 0; | |
580 | parent_inf->vfork_child = child_inf; | |
581 | parent_inf->pending_detach = detach_fork; | |
582 | parent_inf->waiting_for_vfork_done = 0; | |
583 | } | |
584 | else if (detach_fork) | |
6f259a23 DB |
585 | { |
586 | if (info_verbose || debug_infrun) | |
587 | { | |
588 | target_terminal_ours_for_output (); | |
589 | fprintf_filtered (gdb_stdlog, | |
590 | _("Detaching after fork from " | |
79639e11 PA |
591 | "child %s.\n"), |
592 | target_pid_to_str (child_ptid)); | |
6f259a23 DB |
593 | } |
594 | ||
595 | target_detach (NULL, 0); | |
596 | } | |
d83ad864 DB |
597 | |
598 | /* Note that the detach above makes PARENT_INF dangling. */ | |
599 | ||
600 | /* Add the child thread to the appropriate lists, and switch to | |
601 | this new thread, before cloning the program space, and | |
602 | informing the solib layer about this new process. */ | |
603 | ||
79639e11 | 604 | inferior_ptid = child_ptid; |
d83ad864 DB |
605 | add_thread (inferior_ptid); |
606 | ||
607 | /* If this is a vfork child, then the address-space is shared | |
608 | with the parent. If we detached from the parent, then we can | |
609 | reuse the parent's program/address spaces. */ | |
610 | if (has_vforked || detach_fork) | |
611 | { | |
612 | child_inf->pspace = parent_pspace; | |
613 | child_inf->aspace = child_inf->pspace->aspace; | |
614 | } | |
615 | else | |
616 | { | |
617 | child_inf->aspace = new_address_space (); | |
618 | child_inf->pspace = add_program_space (child_inf->aspace); | |
619 | child_inf->removable = 1; | |
620 | child_inf->symfile_flags = SYMFILE_NO_READ; | |
621 | set_current_program_space (child_inf->pspace); | |
622 | clone_program_space (child_inf->pspace, parent_pspace); | |
623 | ||
624 | /* Let the shared library layer (e.g., solib-svr4) learn | |
625 | about this new process, relocate the cloned exec, pull in | |
626 | shared libraries, and install the solib event breakpoint. | |
627 | If a "cloned-VM" event was propagated better throughout | |
628 | the core, this wouldn't be required. */ | |
629 | solib_create_inferior_hook (0); | |
630 | } | |
631 | } | |
632 | ||
633 | return target_follow_fork (follow_child, detach_fork); | |
634 | } | |
635 | ||
e58b0e63 PA |
636 | /* Tell the target to follow the fork we're stopped at. Returns true |
637 | if the inferior should be resumed; false, if the target for some | |
638 | reason decided it's best not to resume. */ | |
639 | ||
6604731b | 640 | static int |
4ef3f3be | 641 | follow_fork (void) |
c906108c | 642 | { |
ea1dd7bc | 643 | int follow_child = (follow_fork_mode_string == follow_fork_mode_child); |
e58b0e63 PA |
644 | int should_resume = 1; |
645 | struct thread_info *tp; | |
646 | ||
647 | /* Copy user stepping state to the new inferior thread. FIXME: the | |
648 | followed fork child thread should have a copy of most of the | |
4e3990f4 DE |
649 | parent thread structure's run control related fields, not just these. |
650 | Initialized to avoid "may be used uninitialized" warnings from gcc. */ | |
651 | struct breakpoint *step_resume_breakpoint = NULL; | |
186c406b | 652 | struct breakpoint *exception_resume_breakpoint = NULL; |
4e3990f4 DE |
653 | CORE_ADDR step_range_start = 0; |
654 | CORE_ADDR step_range_end = 0; | |
655 | struct frame_id step_frame_id = { 0 }; | |
17b2616c | 656 | struct interp *command_interp = NULL; |
e58b0e63 PA |
657 | |
658 | if (!non_stop) | |
659 | { | |
660 | ptid_t wait_ptid; | |
661 | struct target_waitstatus wait_status; | |
662 | ||
663 | /* Get the last target status returned by target_wait(). */ | |
664 | get_last_target_status (&wait_ptid, &wait_status); | |
665 | ||
666 | /* If not stopped at a fork event, then there's nothing else to | |
667 | do. */ | |
668 | if (wait_status.kind != TARGET_WAITKIND_FORKED | |
669 | && wait_status.kind != TARGET_WAITKIND_VFORKED) | |
670 | return 1; | |
671 | ||
672 | /* Check if we switched over from WAIT_PTID, since the event was | |
673 | reported. */ | |
674 | if (!ptid_equal (wait_ptid, minus_one_ptid) | |
675 | && !ptid_equal (inferior_ptid, wait_ptid)) | |
676 | { | |
677 | /* We did. Switch back to WAIT_PTID thread, to tell the | |
678 | target to follow it (in either direction). We'll | |
679 | afterwards refuse to resume, and inform the user what | |
680 | happened. */ | |
681 | switch_to_thread (wait_ptid); | |
682 | should_resume = 0; | |
683 | } | |
684 | } | |
685 | ||
686 | tp = inferior_thread (); | |
687 | ||
688 | /* If there were any forks/vforks that were caught and are now to be | |
689 | followed, then do so now. */ | |
690 | switch (tp->pending_follow.kind) | |
691 | { | |
692 | case TARGET_WAITKIND_FORKED: | |
693 | case TARGET_WAITKIND_VFORKED: | |
694 | { | |
695 | ptid_t parent, child; | |
696 | ||
697 | /* If the user did a next/step, etc, over a fork call, | |
698 | preserve the stepping state in the fork child. */ | |
699 | if (follow_child && should_resume) | |
700 | { | |
8358c15c JK |
701 | step_resume_breakpoint = clone_momentary_breakpoint |
702 | (tp->control.step_resume_breakpoint); | |
16c381f0 JK |
703 | step_range_start = tp->control.step_range_start; |
704 | step_range_end = tp->control.step_range_end; | |
705 | step_frame_id = tp->control.step_frame_id; | |
186c406b TT |
706 | exception_resume_breakpoint |
707 | = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint); | |
17b2616c | 708 | command_interp = tp->control.command_interp; |
e58b0e63 PA |
709 | |
710 | /* For now, delete the parent's sr breakpoint, otherwise, | |
711 | parent/child sr breakpoints are considered duplicates, | |
712 | and the child version will not be installed. Remove | |
713 | this when the breakpoints module becomes aware of | |
714 | inferiors and address spaces. */ | |
715 | delete_step_resume_breakpoint (tp); | |
16c381f0 JK |
716 | tp->control.step_range_start = 0; |
717 | tp->control.step_range_end = 0; | |
718 | tp->control.step_frame_id = null_frame_id; | |
186c406b | 719 | delete_exception_resume_breakpoint (tp); |
17b2616c | 720 | tp->control.command_interp = NULL; |
e58b0e63 PA |
721 | } |
722 | ||
723 | parent = inferior_ptid; | |
724 | child = tp->pending_follow.value.related_pid; | |
725 | ||
d83ad864 DB |
726 | /* Set up inferior(s) as specified by the caller, and tell the |
727 | target to do whatever is necessary to follow either parent | |
728 | or child. */ | |
729 | if (follow_fork_inferior (follow_child, detach_fork)) | |
e58b0e63 PA |
730 | { |
731 | /* Target refused to follow, or there's some other reason | |
732 | we shouldn't resume. */ | |
733 | should_resume = 0; | |
734 | } | |
735 | else | |
736 | { | |
737 | /* This pending follow fork event is now handled, one way | |
738 | or another. The previous selected thread may be gone | |
739 | from the lists by now, but if it is still around, need | |
740 | to clear the pending follow request. */ | |
e09875d4 | 741 | tp = find_thread_ptid (parent); |
e58b0e63 PA |
742 | if (tp) |
743 | tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
744 | ||
745 | /* This makes sure we don't try to apply the "Switched | |
746 | over from WAIT_PID" logic above. */ | |
747 | nullify_last_target_wait_ptid (); | |
748 | ||
1777feb0 | 749 | /* If we followed the child, switch to it... */ |
e58b0e63 PA |
750 | if (follow_child) |
751 | { | |
752 | switch_to_thread (child); | |
753 | ||
754 | /* ... and preserve the stepping state, in case the | |
755 | user was stepping over the fork call. */ | |
756 | if (should_resume) | |
757 | { | |
758 | tp = inferior_thread (); | |
8358c15c JK |
759 | tp->control.step_resume_breakpoint |
760 | = step_resume_breakpoint; | |
16c381f0 JK |
761 | tp->control.step_range_start = step_range_start; |
762 | tp->control.step_range_end = step_range_end; | |
763 | tp->control.step_frame_id = step_frame_id; | |
186c406b TT |
764 | tp->control.exception_resume_breakpoint |
765 | = exception_resume_breakpoint; | |
17b2616c | 766 | tp->control.command_interp = command_interp; |
e58b0e63 PA |
767 | } |
768 | else | |
769 | { | |
770 | /* If we get here, it was because we're trying to | |
771 | resume from a fork catchpoint, but, the user | |
772 | has switched threads away from the thread that | |
773 | forked. In that case, the resume command | |
774 | issued is most likely not applicable to the | |
775 | child, so just warn, and refuse to resume. */ | |
3e43a32a MS |
776 | warning (_("Not resuming: switched threads " |
777 | "before following fork child.\n")); | |
e58b0e63 PA |
778 | } |
779 | ||
780 | /* Reset breakpoints in the child as appropriate. */ | |
781 | follow_inferior_reset_breakpoints (); | |
782 | } | |
783 | else | |
784 | switch_to_thread (parent); | |
785 | } | |
786 | } | |
787 | break; | |
788 | case TARGET_WAITKIND_SPURIOUS: | |
789 | /* Nothing to follow. */ | |
790 | break; | |
791 | default: | |
792 | internal_error (__FILE__, __LINE__, | |
793 | "Unexpected pending_follow.kind %d\n", | |
794 | tp->pending_follow.kind); | |
795 | break; | |
796 | } | |
c906108c | 797 | |
e58b0e63 | 798 | return should_resume; |
c906108c SS |
799 | } |
800 | ||
d83ad864 | 801 | static void |
6604731b | 802 | follow_inferior_reset_breakpoints (void) |
c906108c | 803 | { |
4e1c45ea PA |
804 | struct thread_info *tp = inferior_thread (); |
805 | ||
6604731b DJ |
806 | /* Was there a step_resume breakpoint? (There was if the user |
807 | did a "next" at the fork() call.) If so, explicitly reset its | |
a1aa2221 LM |
808 | thread number. Cloned step_resume breakpoints are disabled on |
809 | creation, so enable it here now that it is associated with the | |
810 | correct thread. | |
6604731b DJ |
811 | |
812 | step_resumes are a form of bp that are made to be per-thread. | |
813 | Since we created the step_resume bp when the parent process | |
814 | was being debugged, and now are switching to the child process, | |
815 | from the breakpoint package's viewpoint, that's a switch of | |
816 | "threads". We must update the bp's notion of which thread | |
817 | it is for, or it'll be ignored when it triggers. */ | |
818 | ||
8358c15c | 819 | if (tp->control.step_resume_breakpoint) |
a1aa2221 LM |
820 | { |
821 | breakpoint_re_set_thread (tp->control.step_resume_breakpoint); | |
822 | tp->control.step_resume_breakpoint->loc->enabled = 1; | |
823 | } | |
6604731b | 824 | |
a1aa2221 | 825 | /* Treat exception_resume breakpoints like step_resume breakpoints. */ |
186c406b | 826 | if (tp->control.exception_resume_breakpoint) |
a1aa2221 LM |
827 | { |
828 | breakpoint_re_set_thread (tp->control.exception_resume_breakpoint); | |
829 | tp->control.exception_resume_breakpoint->loc->enabled = 1; | |
830 | } | |
186c406b | 831 | |
6604731b DJ |
832 | /* Reinsert all breakpoints in the child. The user may have set |
833 | breakpoints after catching the fork, in which case those | |
834 | were never set in the child, but only in the parent. This makes | |
835 | sure the inserted breakpoints match the breakpoint list. */ | |
836 | ||
837 | breakpoint_re_set (); | |
838 | insert_breakpoints (); | |
c906108c | 839 | } |
c906108c | 840 | |
6c95b8df PA |
841 | /* The child has exited or execed: resume threads of the parent the |
842 | user wanted to be executing. */ | |
843 | ||
844 | static int | |
845 | proceed_after_vfork_done (struct thread_info *thread, | |
846 | void *arg) | |
847 | { | |
848 | int pid = * (int *) arg; | |
849 | ||
850 | if (ptid_get_pid (thread->ptid) == pid | |
851 | && is_running (thread->ptid) | |
852 | && !is_executing (thread->ptid) | |
853 | && !thread->stop_requested | |
a493e3e2 | 854 | && thread->suspend.stop_signal == GDB_SIGNAL_0) |
6c95b8df PA |
855 | { |
856 | if (debug_infrun) | |
857 | fprintf_unfiltered (gdb_stdlog, | |
858 | "infrun: resuming vfork parent thread %s\n", | |
859 | target_pid_to_str (thread->ptid)); | |
860 | ||
861 | switch_to_thread (thread->ptid); | |
70509625 | 862 | clear_proceed_status (0); |
64ce06e4 | 863 | proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); |
6c95b8df PA |
864 | } |
865 | ||
866 | return 0; | |
867 | } | |
868 | ||
869 | /* Called whenever we notice an exec or exit event, to handle | |
870 | detaching or resuming a vfork parent. */ | |
871 | ||
872 | static void | |
873 | handle_vfork_child_exec_or_exit (int exec) | |
874 | { | |
875 | struct inferior *inf = current_inferior (); | |
876 | ||
877 | if (inf->vfork_parent) | |
878 | { | |
879 | int resume_parent = -1; | |
880 | ||
881 | /* This exec or exit marks the end of the shared memory region | |
882 | between the parent and the child. If the user wanted to | |
883 | detach from the parent, now is the time. */ | |
884 | ||
885 | if (inf->vfork_parent->pending_detach) | |
886 | { | |
887 | struct thread_info *tp; | |
888 | struct cleanup *old_chain; | |
889 | struct program_space *pspace; | |
890 | struct address_space *aspace; | |
891 | ||
1777feb0 | 892 | /* follow-fork child, detach-on-fork on. */ |
6c95b8df | 893 | |
68c9da30 PA |
894 | inf->vfork_parent->pending_detach = 0; |
895 | ||
f50f4e56 PA |
896 | if (!exec) |
897 | { | |
898 | /* If we're handling a child exit, then inferior_ptid | |
899 | points at the inferior's pid, not to a thread. */ | |
900 | old_chain = save_inferior_ptid (); | |
901 | save_current_program_space (); | |
902 | save_current_inferior (); | |
903 | } | |
904 | else | |
905 | old_chain = save_current_space_and_thread (); | |
6c95b8df PA |
906 | |
907 | /* We're letting loose of the parent. */ | |
908 | tp = any_live_thread_of_process (inf->vfork_parent->pid); | |
909 | switch_to_thread (tp->ptid); | |
910 | ||
911 | /* We're about to detach from the parent, which implicitly | |
912 | removes breakpoints from its address space. There's a | |
913 | catch here: we want to reuse the spaces for the child, | |
914 | but, parent/child are still sharing the pspace at this | |
915 | point, although the exec in reality makes the kernel give | |
916 | the child a fresh set of new pages. The problem here is | |
917 | that the breakpoints module being unaware of this, would | |
918 | likely chose the child process to write to the parent | |
919 | address space. Swapping the child temporarily away from | |
920 | the spaces has the desired effect. Yes, this is "sort | |
921 | of" a hack. */ | |
922 | ||
923 | pspace = inf->pspace; | |
924 | aspace = inf->aspace; | |
925 | inf->aspace = NULL; | |
926 | inf->pspace = NULL; | |
927 | ||
928 | if (debug_infrun || info_verbose) | |
929 | { | |
6f259a23 | 930 | target_terminal_ours_for_output (); |
6c95b8df PA |
931 | |
932 | if (exec) | |
6f259a23 DB |
933 | { |
934 | fprintf_filtered (gdb_stdlog, | |
935 | _("Detaching vfork parent process " | |
936 | "%d after child exec.\n"), | |
937 | inf->vfork_parent->pid); | |
938 | } | |
6c95b8df | 939 | else |
6f259a23 DB |
940 | { |
941 | fprintf_filtered (gdb_stdlog, | |
942 | _("Detaching vfork parent process " | |
943 | "%d after child exit.\n"), | |
944 | inf->vfork_parent->pid); | |
945 | } | |
6c95b8df PA |
946 | } |
947 | ||
948 | target_detach (NULL, 0); | |
949 | ||
950 | /* Put it back. */ | |
951 | inf->pspace = pspace; | |
952 | inf->aspace = aspace; | |
953 | ||
954 | do_cleanups (old_chain); | |
955 | } | |
956 | else if (exec) | |
957 | { | |
958 | /* We're staying attached to the parent, so, really give the | |
959 | child a new address space. */ | |
960 | inf->pspace = add_program_space (maybe_new_address_space ()); | |
961 | inf->aspace = inf->pspace->aspace; | |
962 | inf->removable = 1; | |
963 | set_current_program_space (inf->pspace); | |
964 | ||
965 | resume_parent = inf->vfork_parent->pid; | |
966 | ||
967 | /* Break the bonds. */ | |
968 | inf->vfork_parent->vfork_child = NULL; | |
969 | } | |
970 | else | |
971 | { | |
972 | struct cleanup *old_chain; | |
973 | struct program_space *pspace; | |
974 | ||
975 | /* If this is a vfork child exiting, then the pspace and | |
976 | aspaces were shared with the parent. Since we're | |
977 | reporting the process exit, we'll be mourning all that is | |
978 | found in the address space, and switching to null_ptid, | |
979 | preparing to start a new inferior. But, since we don't | |
980 | want to clobber the parent's address/program spaces, we | |
981 | go ahead and create a new one for this exiting | |
982 | inferior. */ | |
983 | ||
984 | /* Switch to null_ptid, so that clone_program_space doesn't want | |
985 | to read the selected frame of a dead process. */ | |
986 | old_chain = save_inferior_ptid (); | |
987 | inferior_ptid = null_ptid; | |
988 | ||
989 | /* This inferior is dead, so avoid giving the breakpoints | |
990 | module the option to write through to it (cloning a | |
991 | program space resets breakpoints). */ | |
992 | inf->aspace = NULL; | |
993 | inf->pspace = NULL; | |
994 | pspace = add_program_space (maybe_new_address_space ()); | |
995 | set_current_program_space (pspace); | |
996 | inf->removable = 1; | |
7dcd53a0 | 997 | inf->symfile_flags = SYMFILE_NO_READ; |
6c95b8df PA |
998 | clone_program_space (pspace, inf->vfork_parent->pspace); |
999 | inf->pspace = pspace; | |
1000 | inf->aspace = pspace->aspace; | |
1001 | ||
1002 | /* Put back inferior_ptid. We'll continue mourning this | |
1777feb0 | 1003 | inferior. */ |
6c95b8df PA |
1004 | do_cleanups (old_chain); |
1005 | ||
1006 | resume_parent = inf->vfork_parent->pid; | |
1007 | /* Break the bonds. */ | |
1008 | inf->vfork_parent->vfork_child = NULL; | |
1009 | } | |
1010 | ||
1011 | inf->vfork_parent = NULL; | |
1012 | ||
1013 | gdb_assert (current_program_space == inf->pspace); | |
1014 | ||
1015 | if (non_stop && resume_parent != -1) | |
1016 | { | |
1017 | /* If the user wanted the parent to be running, let it go | |
1018 | free now. */ | |
1019 | struct cleanup *old_chain = make_cleanup_restore_current_thread (); | |
1020 | ||
1021 | if (debug_infrun) | |
3e43a32a MS |
1022 | fprintf_unfiltered (gdb_stdlog, |
1023 | "infrun: resuming vfork parent process %d\n", | |
6c95b8df PA |
1024 | resume_parent); |
1025 | ||
1026 | iterate_over_threads (proceed_after_vfork_done, &resume_parent); | |
1027 | ||
1028 | do_cleanups (old_chain); | |
1029 | } | |
1030 | } | |
1031 | } | |
1032 | ||
eb6c553b | 1033 | /* Enum strings for "set|show follow-exec-mode". */ |
6c95b8df PA |
1034 | |
1035 | static const char follow_exec_mode_new[] = "new"; | |
1036 | static const char follow_exec_mode_same[] = "same"; | |
40478521 | 1037 | static const char *const follow_exec_mode_names[] = |
6c95b8df PA |
1038 | { |
1039 | follow_exec_mode_new, | |
1040 | follow_exec_mode_same, | |
1041 | NULL, | |
1042 | }; | |
1043 | ||
1044 | static const char *follow_exec_mode_string = follow_exec_mode_same; | |
1045 | static void | |
1046 | show_follow_exec_mode_string (struct ui_file *file, int from_tty, | |
1047 | struct cmd_list_element *c, const char *value) | |
1048 | { | |
1049 | fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value); | |
1050 | } | |
1051 | ||
1777feb0 | 1052 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
1adeb98a | 1053 | |
c906108c | 1054 | static void |
95e50b27 | 1055 | follow_exec (ptid_t ptid, char *execd_pathname) |
c906108c | 1056 | { |
95e50b27 | 1057 | struct thread_info *th, *tmp; |
6c95b8df | 1058 | struct inferior *inf = current_inferior (); |
95e50b27 | 1059 | int pid = ptid_get_pid (ptid); |
7a292a7a | 1060 | |
c906108c SS |
1061 | /* This is an exec event that we actually wish to pay attention to. |
1062 | Refresh our symbol table to the newly exec'd program, remove any | |
1063 | momentary bp's, etc. | |
1064 | ||
1065 | If there are breakpoints, they aren't really inserted now, | |
1066 | since the exec() transformed our inferior into a fresh set | |
1067 | of instructions. | |
1068 | ||
1069 | We want to preserve symbolic breakpoints on the list, since | |
1070 | we have hopes that they can be reset after the new a.out's | |
1071 | symbol table is read. | |
1072 | ||
1073 | However, any "raw" breakpoints must be removed from the list | |
1074 | (e.g., the solib bp's), since their address is probably invalid | |
1075 | now. | |
1076 | ||
1077 | And, we DON'T want to call delete_breakpoints() here, since | |
1078 | that may write the bp's "shadow contents" (the instruction | |
1079 | value that was overwritten witha TRAP instruction). Since | |
1777feb0 | 1080 | we now have a new a.out, those shadow contents aren't valid. */ |
6c95b8df PA |
1081 | |
1082 | mark_breakpoints_out (); | |
1083 | ||
95e50b27 PA |
1084 | /* The target reports the exec event to the main thread, even if |
1085 | some other thread does the exec, and even if the main thread was | |
1086 | stopped or already gone. We may still have non-leader threads of | |
1087 | the process on our list. E.g., on targets that don't have thread | |
1088 | exit events (like remote); or on native Linux in non-stop mode if | |
1089 | there were only two threads in the inferior and the non-leader | |
1090 | one is the one that execs (and nothing forces an update of the | |
1091 | thread list up to here). When debugging remotely, it's best to | |
1092 | avoid extra traffic, when possible, so avoid syncing the thread | |
1093 | list with the target, and instead go ahead and delete all threads | |
1094 | of the process but one that reported the event. Note this must | |
1095 | be done before calling update_breakpoints_after_exec, as | |
1096 | otherwise clearing the threads' resources would reference stale | |
1097 | thread breakpoints -- it may have been one of these threads that | |
1098 | stepped across the exec. We could just clear their stepping | |
1099 | states, but as long as we're iterating, might as well delete | |
1100 | them. Deleting them now rather than at the next user-visible | |
1101 | stop provides a nicer sequence of events for user and MI | |
1102 | notifications. */ | |
8a06aea7 | 1103 | ALL_THREADS_SAFE (th, tmp) |
95e50b27 PA |
1104 | if (ptid_get_pid (th->ptid) == pid && !ptid_equal (th->ptid, ptid)) |
1105 | delete_thread (th->ptid); | |
1106 | ||
1107 | /* We also need to clear any left over stale state for the | |
1108 | leader/event thread. E.g., if there was any step-resume | |
1109 | breakpoint or similar, it's gone now. We cannot truly | |
1110 | step-to-next statement through an exec(). */ | |
1111 | th = inferior_thread (); | |
8358c15c | 1112 | th->control.step_resume_breakpoint = NULL; |
186c406b | 1113 | th->control.exception_resume_breakpoint = NULL; |
34b7e8a6 | 1114 | th->control.single_step_breakpoints = NULL; |
16c381f0 JK |
1115 | th->control.step_range_start = 0; |
1116 | th->control.step_range_end = 0; | |
c906108c | 1117 | |
95e50b27 PA |
1118 | /* The user may have had the main thread held stopped in the |
1119 | previous image (e.g., schedlock on, or non-stop). Release | |
1120 | it now. */ | |
a75724bc PA |
1121 | th->stop_requested = 0; |
1122 | ||
95e50b27 PA |
1123 | update_breakpoints_after_exec (); |
1124 | ||
1777feb0 | 1125 | /* What is this a.out's name? */ |
6c95b8df PA |
1126 | printf_unfiltered (_("%s is executing new program: %s\n"), |
1127 | target_pid_to_str (inferior_ptid), | |
1128 | execd_pathname); | |
c906108c SS |
1129 | |
1130 | /* We've followed the inferior through an exec. Therefore, the | |
1777feb0 | 1131 | inferior has essentially been killed & reborn. */ |
7a292a7a | 1132 | |
c906108c | 1133 | gdb_flush (gdb_stdout); |
6ca15a4b PA |
1134 | |
1135 | breakpoint_init_inferior (inf_execd); | |
e85a822c | 1136 | |
ff862be4 | 1137 | if (gdb_sysroot != NULL && *gdb_sysroot != '\0') |
e85a822c | 1138 | { |
998d2a3e | 1139 | char *name = exec_file_find (execd_pathname, NULL); |
ff862be4 GB |
1140 | |
1141 | execd_pathname = alloca (strlen (name) + 1); | |
1142 | strcpy (execd_pathname, name); | |
1143 | xfree (name); | |
e85a822c | 1144 | } |
c906108c | 1145 | |
cce9b6bf PA |
1146 | /* Reset the shared library package. This ensures that we get a |
1147 | shlib event when the child reaches "_start", at which point the | |
1148 | dld will have had a chance to initialize the child. */ | |
1149 | /* Also, loading a symbol file below may trigger symbol lookups, and | |
1150 | we don't want those to be satisfied by the libraries of the | |
1151 | previous incarnation of this process. */ | |
1152 | no_shared_libraries (NULL, 0); | |
1153 | ||
6c95b8df PA |
1154 | if (follow_exec_mode_string == follow_exec_mode_new) |
1155 | { | |
1156 | struct program_space *pspace; | |
6c95b8df PA |
1157 | |
1158 | /* The user wants to keep the old inferior and program spaces | |
1159 | around. Create a new fresh one, and switch to it. */ | |
1160 | ||
1161 | inf = add_inferior (current_inferior ()->pid); | |
1162 | pspace = add_program_space (maybe_new_address_space ()); | |
1163 | inf->pspace = pspace; | |
1164 | inf->aspace = pspace->aspace; | |
1165 | ||
1166 | exit_inferior_num_silent (current_inferior ()->num); | |
1167 | ||
1168 | set_current_inferior (inf); | |
1169 | set_current_program_space (pspace); | |
1170 | } | |
9107fc8d PA |
1171 | else |
1172 | { | |
1173 | /* The old description may no longer be fit for the new image. | |
1174 | E.g, a 64-bit process exec'ed a 32-bit process. Clear the | |
1175 | old description; we'll read a new one below. No need to do | |
1176 | this on "follow-exec-mode new", as the old inferior stays | |
1177 | around (its description is later cleared/refetched on | |
1178 | restart). */ | |
1179 | target_clear_description (); | |
1180 | } | |
6c95b8df PA |
1181 | |
1182 | gdb_assert (current_program_space == inf->pspace); | |
1183 | ||
1777feb0 | 1184 | /* That a.out is now the one to use. */ |
6c95b8df PA |
1185 | exec_file_attach (execd_pathname, 0); |
1186 | ||
c1e56572 JK |
1187 | /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE |
1188 | (Position Independent Executable) main symbol file will get applied by | |
1189 | solib_create_inferior_hook below. breakpoint_re_set would fail to insert | |
1190 | the breakpoints with the zero displacement. */ | |
1191 | ||
7dcd53a0 TT |
1192 | symbol_file_add (execd_pathname, |
1193 | (inf->symfile_flags | |
1194 | | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET), | |
c1e56572 JK |
1195 | NULL, 0); |
1196 | ||
7dcd53a0 TT |
1197 | if ((inf->symfile_flags & SYMFILE_NO_READ) == 0) |
1198 | set_initial_language (); | |
c906108c | 1199 | |
9107fc8d PA |
1200 | /* If the target can specify a description, read it. Must do this |
1201 | after flipping to the new executable (because the target supplied | |
1202 | description must be compatible with the executable's | |
1203 | architecture, and the old executable may e.g., be 32-bit, while | |
1204 | the new one 64-bit), and before anything involving memory or | |
1205 | registers. */ | |
1206 | target_find_description (); | |
1207 | ||
268a4a75 | 1208 | solib_create_inferior_hook (0); |
c906108c | 1209 | |
4efc6507 DE |
1210 | jit_inferior_created_hook (); |
1211 | ||
c1e56572 JK |
1212 | breakpoint_re_set (); |
1213 | ||
c906108c SS |
1214 | /* Reinsert all breakpoints. (Those which were symbolic have |
1215 | been reset to the proper address in the new a.out, thanks | |
1777feb0 | 1216 | to symbol_file_command...). */ |
c906108c SS |
1217 | insert_breakpoints (); |
1218 | ||
1219 | /* The next resume of this inferior should bring it to the shlib | |
1220 | startup breakpoints. (If the user had also set bp's on | |
1221 | "main" from the old (parent) process, then they'll auto- | |
1777feb0 | 1222 | matically get reset there in the new process.). */ |
c906108c SS |
1223 | } |
1224 | ||
963f9c80 | 1225 | /* Info about an instruction that is being stepped over. */ |
31e77af2 PA |
1226 | |
1227 | struct step_over_info | |
1228 | { | |
963f9c80 PA |
1229 | /* If we're stepping past a breakpoint, this is the address space |
1230 | and address of the instruction the breakpoint is set at. We'll | |
1231 | skip inserting all breakpoints here. Valid iff ASPACE is | |
1232 | non-NULL. */ | |
31e77af2 | 1233 | struct address_space *aspace; |
31e77af2 | 1234 | CORE_ADDR address; |
963f9c80 PA |
1235 | |
1236 | /* The instruction being stepped over triggers a nonsteppable | |
1237 | watchpoint. If true, we'll skip inserting watchpoints. */ | |
1238 | int nonsteppable_watchpoint_p; | |
31e77af2 PA |
1239 | }; |
1240 | ||
1241 | /* The step-over info of the location that is being stepped over. | |
1242 | ||
1243 | Note that with async/breakpoint always-inserted mode, a user might | |
1244 | set a new breakpoint/watchpoint/etc. exactly while a breakpoint is | |
1245 | being stepped over. As setting a new breakpoint inserts all | |
1246 | breakpoints, we need to make sure the breakpoint being stepped over | |
1247 | isn't inserted then. We do that by only clearing the step-over | |
1248 | info when the step-over is actually finished (or aborted). | |
1249 | ||
1250 | Presently GDB can only step over one breakpoint at any given time. | |
1251 | Given threads that can't run code in the same address space as the | |
1252 | breakpoint's can't really miss the breakpoint, GDB could be taught | |
1253 | to step-over at most one breakpoint per address space (so this info | |
1254 | could move to the address space object if/when GDB is extended). | |
1255 | The set of breakpoints being stepped over will normally be much | |
1256 | smaller than the set of all breakpoints, so a flag in the | |
1257 | breakpoint location structure would be wasteful. A separate list | |
1258 | also saves complexity and run-time, as otherwise we'd have to go | |
1259 | through all breakpoint locations clearing their flag whenever we | |
1260 | start a new sequence. Similar considerations weigh against storing | |
1261 | this info in the thread object. Plus, not all step overs actually | |
1262 | have breakpoint locations -- e.g., stepping past a single-step | |
1263 | breakpoint, or stepping to complete a non-continuable | |
1264 | watchpoint. */ | |
1265 | static struct step_over_info step_over_info; | |
1266 | ||
1267 | /* Record the address of the breakpoint/instruction we're currently | |
1268 | stepping over. */ | |
1269 | ||
1270 | static void | |
963f9c80 PA |
1271 | set_step_over_info (struct address_space *aspace, CORE_ADDR address, |
1272 | int nonsteppable_watchpoint_p) | |
31e77af2 PA |
1273 | { |
1274 | step_over_info.aspace = aspace; | |
1275 | step_over_info.address = address; | |
963f9c80 | 1276 | step_over_info.nonsteppable_watchpoint_p = nonsteppable_watchpoint_p; |
31e77af2 PA |
1277 | } |
1278 | ||
1279 | /* Called when we're not longer stepping over a breakpoint / an | |
1280 | instruction, so all breakpoints are free to be (re)inserted. */ | |
1281 | ||
1282 | static void | |
1283 | clear_step_over_info (void) | |
1284 | { | |
1285 | step_over_info.aspace = NULL; | |
1286 | step_over_info.address = 0; | |
963f9c80 | 1287 | step_over_info.nonsteppable_watchpoint_p = 0; |
31e77af2 PA |
1288 | } |
1289 | ||
7f89fd65 | 1290 | /* See infrun.h. */ |
31e77af2 PA |
1291 | |
1292 | int | |
1293 | stepping_past_instruction_at (struct address_space *aspace, | |
1294 | CORE_ADDR address) | |
1295 | { | |
1296 | return (step_over_info.aspace != NULL | |
1297 | && breakpoint_address_match (aspace, address, | |
1298 | step_over_info.aspace, | |
1299 | step_over_info.address)); | |
1300 | } | |
1301 | ||
963f9c80 PA |
1302 | /* See infrun.h. */ |
1303 | ||
1304 | int | |
1305 | stepping_past_nonsteppable_watchpoint (void) | |
1306 | { | |
1307 | return step_over_info.nonsteppable_watchpoint_p; | |
1308 | } | |
1309 | ||
6cc83d2a PA |
1310 | /* Returns true if step-over info is valid. */ |
1311 | ||
1312 | static int | |
1313 | step_over_info_valid_p (void) | |
1314 | { | |
963f9c80 PA |
1315 | return (step_over_info.aspace != NULL |
1316 | || stepping_past_nonsteppable_watchpoint ()); | |
6cc83d2a PA |
1317 | } |
1318 | ||
c906108c | 1319 | \f |
237fc4c9 PA |
1320 | /* Displaced stepping. */ |
1321 | ||
1322 | /* In non-stop debugging mode, we must take special care to manage | |
1323 | breakpoints properly; in particular, the traditional strategy for | |
1324 | stepping a thread past a breakpoint it has hit is unsuitable. | |
1325 | 'Displaced stepping' is a tactic for stepping one thread past a | |
1326 | breakpoint it has hit while ensuring that other threads running | |
1327 | concurrently will hit the breakpoint as they should. | |
1328 | ||
1329 | The traditional way to step a thread T off a breakpoint in a | |
1330 | multi-threaded program in all-stop mode is as follows: | |
1331 | ||
1332 | a0) Initially, all threads are stopped, and breakpoints are not | |
1333 | inserted. | |
1334 | a1) We single-step T, leaving breakpoints uninserted. | |
1335 | a2) We insert breakpoints, and resume all threads. | |
1336 | ||
1337 | In non-stop debugging, however, this strategy is unsuitable: we | |
1338 | don't want to have to stop all threads in the system in order to | |
1339 | continue or step T past a breakpoint. Instead, we use displaced | |
1340 | stepping: | |
1341 | ||
1342 | n0) Initially, T is stopped, other threads are running, and | |
1343 | breakpoints are inserted. | |
1344 | n1) We copy the instruction "under" the breakpoint to a separate | |
1345 | location, outside the main code stream, making any adjustments | |
1346 | to the instruction, register, and memory state as directed by | |
1347 | T's architecture. | |
1348 | n2) We single-step T over the instruction at its new location. | |
1349 | n3) We adjust the resulting register and memory state as directed | |
1350 | by T's architecture. This includes resetting T's PC to point | |
1351 | back into the main instruction stream. | |
1352 | n4) We resume T. | |
1353 | ||
1354 | This approach depends on the following gdbarch methods: | |
1355 | ||
1356 | - gdbarch_max_insn_length and gdbarch_displaced_step_location | |
1357 | indicate where to copy the instruction, and how much space must | |
1358 | be reserved there. We use these in step n1. | |
1359 | ||
1360 | - gdbarch_displaced_step_copy_insn copies a instruction to a new | |
1361 | address, and makes any necessary adjustments to the instruction, | |
1362 | register contents, and memory. We use this in step n1. | |
1363 | ||
1364 | - gdbarch_displaced_step_fixup adjusts registers and memory after | |
1365 | we have successfuly single-stepped the instruction, to yield the | |
1366 | same effect the instruction would have had if we had executed it | |
1367 | at its original address. We use this in step n3. | |
1368 | ||
1369 | - gdbarch_displaced_step_free_closure provides cleanup. | |
1370 | ||
1371 | The gdbarch_displaced_step_copy_insn and | |
1372 | gdbarch_displaced_step_fixup functions must be written so that | |
1373 | copying an instruction with gdbarch_displaced_step_copy_insn, | |
1374 | single-stepping across the copied instruction, and then applying | |
1375 | gdbarch_displaced_insn_fixup should have the same effects on the | |
1376 | thread's memory and registers as stepping the instruction in place | |
1377 | would have. Exactly which responsibilities fall to the copy and | |
1378 | which fall to the fixup is up to the author of those functions. | |
1379 | ||
1380 | See the comments in gdbarch.sh for details. | |
1381 | ||
1382 | Note that displaced stepping and software single-step cannot | |
1383 | currently be used in combination, although with some care I think | |
1384 | they could be made to. Software single-step works by placing | |
1385 | breakpoints on all possible subsequent instructions; if the | |
1386 | displaced instruction is a PC-relative jump, those breakpoints | |
1387 | could fall in very strange places --- on pages that aren't | |
1388 | executable, or at addresses that are not proper instruction | |
1389 | boundaries. (We do generally let other threads run while we wait | |
1390 | to hit the software single-step breakpoint, and they might | |
1391 | encounter such a corrupted instruction.) One way to work around | |
1392 | this would be to have gdbarch_displaced_step_copy_insn fully | |
1393 | simulate the effect of PC-relative instructions (and return NULL) | |
1394 | on architectures that use software single-stepping. | |
1395 | ||
1396 | In non-stop mode, we can have independent and simultaneous step | |
1397 | requests, so more than one thread may need to simultaneously step | |
1398 | over a breakpoint. The current implementation assumes there is | |
1399 | only one scratch space per process. In this case, we have to | |
1400 | serialize access to the scratch space. If thread A wants to step | |
1401 | over a breakpoint, but we are currently waiting for some other | |
1402 | thread to complete a displaced step, we leave thread A stopped and | |
1403 | place it in the displaced_step_request_queue. Whenever a displaced | |
1404 | step finishes, we pick the next thread in the queue and start a new | |
1405 | displaced step operation on it. See displaced_step_prepare and | |
1406 | displaced_step_fixup for details. */ | |
1407 | ||
237fc4c9 PA |
1408 | struct displaced_step_request |
1409 | { | |
1410 | ptid_t ptid; | |
1411 | struct displaced_step_request *next; | |
1412 | }; | |
1413 | ||
fc1cf338 PA |
1414 | /* Per-inferior displaced stepping state. */ |
1415 | struct displaced_step_inferior_state | |
1416 | { | |
1417 | /* Pointer to next in linked list. */ | |
1418 | struct displaced_step_inferior_state *next; | |
1419 | ||
1420 | /* The process this displaced step state refers to. */ | |
1421 | int pid; | |
1422 | ||
1423 | /* A queue of pending displaced stepping requests. One entry per | |
1424 | thread that needs to do a displaced step. */ | |
1425 | struct displaced_step_request *step_request_queue; | |
1426 | ||
1427 | /* If this is not null_ptid, this is the thread carrying out a | |
1428 | displaced single-step in process PID. This thread's state will | |
1429 | require fixing up once it has completed its step. */ | |
1430 | ptid_t step_ptid; | |
1431 | ||
1432 | /* The architecture the thread had when we stepped it. */ | |
1433 | struct gdbarch *step_gdbarch; | |
1434 | ||
1435 | /* The closure provided gdbarch_displaced_step_copy_insn, to be used | |
1436 | for post-step cleanup. */ | |
1437 | struct displaced_step_closure *step_closure; | |
1438 | ||
1439 | /* The address of the original instruction, and the copy we | |
1440 | made. */ | |
1441 | CORE_ADDR step_original, step_copy; | |
1442 | ||
1443 | /* Saved contents of copy area. */ | |
1444 | gdb_byte *step_saved_copy; | |
1445 | }; | |
1446 | ||
1447 | /* The list of states of processes involved in displaced stepping | |
1448 | presently. */ | |
1449 | static struct displaced_step_inferior_state *displaced_step_inferior_states; | |
1450 | ||
1451 | /* Get the displaced stepping state of process PID. */ | |
1452 | ||
1453 | static struct displaced_step_inferior_state * | |
1454 | get_displaced_stepping_state (int pid) | |
1455 | { | |
1456 | struct displaced_step_inferior_state *state; | |
1457 | ||
1458 | for (state = displaced_step_inferior_states; | |
1459 | state != NULL; | |
1460 | state = state->next) | |
1461 | if (state->pid == pid) | |
1462 | return state; | |
1463 | ||
1464 | return NULL; | |
1465 | } | |
1466 | ||
8f572e5c PA |
1467 | /* Return true if process PID has a thread doing a displaced step. */ |
1468 | ||
1469 | static int | |
1470 | displaced_step_in_progress (int pid) | |
1471 | { | |
1472 | struct displaced_step_inferior_state *displaced; | |
1473 | ||
1474 | displaced = get_displaced_stepping_state (pid); | |
1475 | if (displaced != NULL && !ptid_equal (displaced->step_ptid, null_ptid)) | |
1476 | return 1; | |
1477 | ||
1478 | return 0; | |
1479 | } | |
1480 | ||
fc1cf338 PA |
1481 | /* Add a new displaced stepping state for process PID to the displaced |
1482 | stepping state list, or return a pointer to an already existing | |
1483 | entry, if it already exists. Never returns NULL. */ | |
1484 | ||
1485 | static struct displaced_step_inferior_state * | |
1486 | add_displaced_stepping_state (int pid) | |
1487 | { | |
1488 | struct displaced_step_inferior_state *state; | |
1489 | ||
1490 | for (state = displaced_step_inferior_states; | |
1491 | state != NULL; | |
1492 | state = state->next) | |
1493 | if (state->pid == pid) | |
1494 | return state; | |
237fc4c9 | 1495 | |
fc1cf338 PA |
1496 | state = xcalloc (1, sizeof (*state)); |
1497 | state->pid = pid; | |
1498 | state->next = displaced_step_inferior_states; | |
1499 | displaced_step_inferior_states = state; | |
237fc4c9 | 1500 | |
fc1cf338 PA |
1501 | return state; |
1502 | } | |
1503 | ||
a42244db YQ |
1504 | /* If inferior is in displaced stepping, and ADDR equals to starting address |
1505 | of copy area, return corresponding displaced_step_closure. Otherwise, | |
1506 | return NULL. */ | |
1507 | ||
1508 | struct displaced_step_closure* | |
1509 | get_displaced_step_closure_by_addr (CORE_ADDR addr) | |
1510 | { | |
1511 | struct displaced_step_inferior_state *displaced | |
1512 | = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); | |
1513 | ||
1514 | /* If checking the mode of displaced instruction in copy area. */ | |
1515 | if (displaced && !ptid_equal (displaced->step_ptid, null_ptid) | |
1516 | && (displaced->step_copy == addr)) | |
1517 | return displaced->step_closure; | |
1518 | ||
1519 | return NULL; | |
1520 | } | |
1521 | ||
fc1cf338 | 1522 | /* Remove the displaced stepping state of process PID. */ |
237fc4c9 | 1523 | |
fc1cf338 PA |
1524 | static void |
1525 | remove_displaced_stepping_state (int pid) | |
1526 | { | |
1527 | struct displaced_step_inferior_state *it, **prev_next_p; | |
237fc4c9 | 1528 | |
fc1cf338 PA |
1529 | gdb_assert (pid != 0); |
1530 | ||
1531 | it = displaced_step_inferior_states; | |
1532 | prev_next_p = &displaced_step_inferior_states; | |
1533 | while (it) | |
1534 | { | |
1535 | if (it->pid == pid) | |
1536 | { | |
1537 | *prev_next_p = it->next; | |
1538 | xfree (it); | |
1539 | return; | |
1540 | } | |
1541 | ||
1542 | prev_next_p = &it->next; | |
1543 | it = *prev_next_p; | |
1544 | } | |
1545 | } | |
1546 | ||
1547 | static void | |
1548 | infrun_inferior_exit (struct inferior *inf) | |
1549 | { | |
1550 | remove_displaced_stepping_state (inf->pid); | |
1551 | } | |
237fc4c9 | 1552 | |
fff08868 HZ |
1553 | /* If ON, and the architecture supports it, GDB will use displaced |
1554 | stepping to step over breakpoints. If OFF, or if the architecture | |
1555 | doesn't support it, GDB will instead use the traditional | |
1556 | hold-and-step approach. If AUTO (which is the default), GDB will | |
1557 | decide which technique to use to step over breakpoints depending on | |
1558 | which of all-stop or non-stop mode is active --- displaced stepping | |
1559 | in non-stop mode; hold-and-step in all-stop mode. */ | |
1560 | ||
72d0e2c5 | 1561 | static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO; |
fff08868 | 1562 | |
237fc4c9 PA |
1563 | static void |
1564 | show_can_use_displaced_stepping (struct ui_file *file, int from_tty, | |
1565 | struct cmd_list_element *c, | |
1566 | const char *value) | |
1567 | { | |
72d0e2c5 | 1568 | if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO) |
3e43a32a MS |
1569 | fprintf_filtered (file, |
1570 | _("Debugger's willingness to use displaced stepping " | |
1571 | "to step over breakpoints is %s (currently %s).\n"), | |
fff08868 HZ |
1572 | value, non_stop ? "on" : "off"); |
1573 | else | |
3e43a32a MS |
1574 | fprintf_filtered (file, |
1575 | _("Debugger's willingness to use displaced stepping " | |
1576 | "to step over breakpoints is %s.\n"), value); | |
237fc4c9 PA |
1577 | } |
1578 | ||
fff08868 HZ |
1579 | /* Return non-zero if displaced stepping can/should be used to step |
1580 | over breakpoints. */ | |
1581 | ||
237fc4c9 PA |
1582 | static int |
1583 | use_displaced_stepping (struct gdbarch *gdbarch) | |
1584 | { | |
72d0e2c5 YQ |
1585 | return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop) |
1586 | || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE) | |
96429cc8 | 1587 | && gdbarch_displaced_step_copy_insn_p (gdbarch) |
8213266a | 1588 | && find_record_target () == NULL); |
237fc4c9 PA |
1589 | } |
1590 | ||
1591 | /* Clean out any stray displaced stepping state. */ | |
1592 | static void | |
fc1cf338 | 1593 | displaced_step_clear (struct displaced_step_inferior_state *displaced) |
237fc4c9 PA |
1594 | { |
1595 | /* Indicate that there is no cleanup pending. */ | |
fc1cf338 | 1596 | displaced->step_ptid = null_ptid; |
237fc4c9 | 1597 | |
fc1cf338 | 1598 | if (displaced->step_closure) |
237fc4c9 | 1599 | { |
fc1cf338 PA |
1600 | gdbarch_displaced_step_free_closure (displaced->step_gdbarch, |
1601 | displaced->step_closure); | |
1602 | displaced->step_closure = NULL; | |
237fc4c9 PA |
1603 | } |
1604 | } | |
1605 | ||
1606 | static void | |
fc1cf338 | 1607 | displaced_step_clear_cleanup (void *arg) |
237fc4c9 | 1608 | { |
fc1cf338 PA |
1609 | struct displaced_step_inferior_state *state = arg; |
1610 | ||
1611 | displaced_step_clear (state); | |
237fc4c9 PA |
1612 | } |
1613 | ||
1614 | /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ | |
1615 | void | |
1616 | displaced_step_dump_bytes (struct ui_file *file, | |
1617 | const gdb_byte *buf, | |
1618 | size_t len) | |
1619 | { | |
1620 | int i; | |
1621 | ||
1622 | for (i = 0; i < len; i++) | |
1623 | fprintf_unfiltered (file, "%02x ", buf[i]); | |
1624 | fputs_unfiltered ("\n", file); | |
1625 | } | |
1626 | ||
1627 | /* Prepare to single-step, using displaced stepping. | |
1628 | ||
1629 | Note that we cannot use displaced stepping when we have a signal to | |
1630 | deliver. If we have a signal to deliver and an instruction to step | |
1631 | over, then after the step, there will be no indication from the | |
1632 | target whether the thread entered a signal handler or ignored the | |
1633 | signal and stepped over the instruction successfully --- both cases | |
1634 | result in a simple SIGTRAP. In the first case we mustn't do a | |
1635 | fixup, and in the second case we must --- but we can't tell which. | |
1636 | Comments in the code for 'random signals' in handle_inferior_event | |
1637 | explain how we handle this case instead. | |
1638 | ||
1639 | Returns 1 if preparing was successful -- this thread is going to be | |
1640 | stepped now; or 0 if displaced stepping this thread got queued. */ | |
1641 | static int | |
1642 | displaced_step_prepare (ptid_t ptid) | |
1643 | { | |
ad53cd71 | 1644 | struct cleanup *old_cleanups, *ignore_cleanups; |
c1e36e3e | 1645 | struct thread_info *tp = find_thread_ptid (ptid); |
237fc4c9 PA |
1646 | struct regcache *regcache = get_thread_regcache (ptid); |
1647 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1648 | CORE_ADDR original, copy; | |
1649 | ULONGEST len; | |
1650 | struct displaced_step_closure *closure; | |
fc1cf338 | 1651 | struct displaced_step_inferior_state *displaced; |
9e529e1d | 1652 | int status; |
237fc4c9 PA |
1653 | |
1654 | /* We should never reach this function if the architecture does not | |
1655 | support displaced stepping. */ | |
1656 | gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch)); | |
1657 | ||
c1e36e3e PA |
1658 | /* Disable range stepping while executing in the scratch pad. We |
1659 | want a single-step even if executing the displaced instruction in | |
1660 | the scratch buffer lands within the stepping range (e.g., a | |
1661 | jump/branch). */ | |
1662 | tp->control.may_range_step = 0; | |
1663 | ||
fc1cf338 PA |
1664 | /* We have to displaced step one thread at a time, as we only have |
1665 | access to a single scratch space per inferior. */ | |
237fc4c9 | 1666 | |
fc1cf338 PA |
1667 | displaced = add_displaced_stepping_state (ptid_get_pid (ptid)); |
1668 | ||
1669 | if (!ptid_equal (displaced->step_ptid, null_ptid)) | |
237fc4c9 PA |
1670 | { |
1671 | /* Already waiting for a displaced step to finish. Defer this | |
1672 | request and place in queue. */ | |
1673 | struct displaced_step_request *req, *new_req; | |
1674 | ||
1675 | if (debug_displaced) | |
1676 | fprintf_unfiltered (gdb_stdlog, | |
1677 | "displaced: defering step of %s\n", | |
1678 | target_pid_to_str (ptid)); | |
1679 | ||
1680 | new_req = xmalloc (sizeof (*new_req)); | |
1681 | new_req->ptid = ptid; | |
1682 | new_req->next = NULL; | |
1683 | ||
fc1cf338 | 1684 | if (displaced->step_request_queue) |
237fc4c9 | 1685 | { |
fc1cf338 | 1686 | for (req = displaced->step_request_queue; |
237fc4c9 PA |
1687 | req && req->next; |
1688 | req = req->next) | |
1689 | ; | |
1690 | req->next = new_req; | |
1691 | } | |
1692 | else | |
fc1cf338 | 1693 | displaced->step_request_queue = new_req; |
237fc4c9 PA |
1694 | |
1695 | return 0; | |
1696 | } | |
1697 | else | |
1698 | { | |
1699 | if (debug_displaced) | |
1700 | fprintf_unfiltered (gdb_stdlog, | |
1701 | "displaced: stepping %s now\n", | |
1702 | target_pid_to_str (ptid)); | |
1703 | } | |
1704 | ||
fc1cf338 | 1705 | displaced_step_clear (displaced); |
237fc4c9 | 1706 | |
ad53cd71 PA |
1707 | old_cleanups = save_inferior_ptid (); |
1708 | inferior_ptid = ptid; | |
1709 | ||
515630c5 | 1710 | original = regcache_read_pc (regcache); |
237fc4c9 PA |
1711 | |
1712 | copy = gdbarch_displaced_step_location (gdbarch); | |
1713 | len = gdbarch_max_insn_length (gdbarch); | |
1714 | ||
1715 | /* Save the original contents of the copy area. */ | |
fc1cf338 | 1716 | displaced->step_saved_copy = xmalloc (len); |
ad53cd71 | 1717 | ignore_cleanups = make_cleanup (free_current_contents, |
fc1cf338 | 1718 | &displaced->step_saved_copy); |
9e529e1d JK |
1719 | status = target_read_memory (copy, displaced->step_saved_copy, len); |
1720 | if (status != 0) | |
1721 | throw_error (MEMORY_ERROR, | |
1722 | _("Error accessing memory address %s (%s) for " | |
1723 | "displaced-stepping scratch space."), | |
1724 | paddress (gdbarch, copy), safe_strerror (status)); | |
237fc4c9 PA |
1725 | if (debug_displaced) |
1726 | { | |
5af949e3 UW |
1727 | fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ", |
1728 | paddress (gdbarch, copy)); | |
fc1cf338 PA |
1729 | displaced_step_dump_bytes (gdb_stdlog, |
1730 | displaced->step_saved_copy, | |
1731 | len); | |
237fc4c9 PA |
1732 | }; |
1733 | ||
1734 | closure = gdbarch_displaced_step_copy_insn (gdbarch, | |
ad53cd71 | 1735 | original, copy, regcache); |
237fc4c9 PA |
1736 | |
1737 | /* We don't support the fully-simulated case at present. */ | |
1738 | gdb_assert (closure); | |
1739 | ||
9f5a595d UW |
1740 | /* Save the information we need to fix things up if the step |
1741 | succeeds. */ | |
fc1cf338 PA |
1742 | displaced->step_ptid = ptid; |
1743 | displaced->step_gdbarch = gdbarch; | |
1744 | displaced->step_closure = closure; | |
1745 | displaced->step_original = original; | |
1746 | displaced->step_copy = copy; | |
9f5a595d | 1747 | |
fc1cf338 | 1748 | make_cleanup (displaced_step_clear_cleanup, displaced); |
237fc4c9 PA |
1749 | |
1750 | /* Resume execution at the copy. */ | |
515630c5 | 1751 | regcache_write_pc (regcache, copy); |
237fc4c9 | 1752 | |
ad53cd71 PA |
1753 | discard_cleanups (ignore_cleanups); |
1754 | ||
1755 | do_cleanups (old_cleanups); | |
237fc4c9 PA |
1756 | |
1757 | if (debug_displaced) | |
5af949e3 UW |
1758 | fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n", |
1759 | paddress (gdbarch, copy)); | |
237fc4c9 | 1760 | |
237fc4c9 PA |
1761 | return 1; |
1762 | } | |
1763 | ||
237fc4c9 | 1764 | static void |
3e43a32a MS |
1765 | write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, |
1766 | const gdb_byte *myaddr, int len) | |
237fc4c9 PA |
1767 | { |
1768 | struct cleanup *ptid_cleanup = save_inferior_ptid (); | |
abbb1732 | 1769 | |
237fc4c9 PA |
1770 | inferior_ptid = ptid; |
1771 | write_memory (memaddr, myaddr, len); | |
1772 | do_cleanups (ptid_cleanup); | |
1773 | } | |
1774 | ||
e2d96639 YQ |
1775 | /* Restore the contents of the copy area for thread PTID. */ |
1776 | ||
1777 | static void | |
1778 | displaced_step_restore (struct displaced_step_inferior_state *displaced, | |
1779 | ptid_t ptid) | |
1780 | { | |
1781 | ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch); | |
1782 | ||
1783 | write_memory_ptid (ptid, displaced->step_copy, | |
1784 | displaced->step_saved_copy, len); | |
1785 | if (debug_displaced) | |
1786 | fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n", | |
1787 | target_pid_to_str (ptid), | |
1788 | paddress (displaced->step_gdbarch, | |
1789 | displaced->step_copy)); | |
1790 | } | |
1791 | ||
237fc4c9 | 1792 | static void |
2ea28649 | 1793 | displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal) |
237fc4c9 PA |
1794 | { |
1795 | struct cleanup *old_cleanups; | |
fc1cf338 PA |
1796 | struct displaced_step_inferior_state *displaced |
1797 | = get_displaced_stepping_state (ptid_get_pid (event_ptid)); | |
1798 | ||
1799 | /* Was any thread of this process doing a displaced step? */ | |
1800 | if (displaced == NULL) | |
1801 | return; | |
237fc4c9 PA |
1802 | |
1803 | /* Was this event for the pid we displaced? */ | |
fc1cf338 PA |
1804 | if (ptid_equal (displaced->step_ptid, null_ptid) |
1805 | || ! ptid_equal (displaced->step_ptid, event_ptid)) | |
237fc4c9 PA |
1806 | return; |
1807 | ||
fc1cf338 | 1808 | old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced); |
237fc4c9 | 1809 | |
e2d96639 | 1810 | displaced_step_restore (displaced, displaced->step_ptid); |
237fc4c9 | 1811 | |
cb71640d PA |
1812 | /* Fixup may need to read memory/registers. Switch to the thread |
1813 | that we're fixing up. Also, target_stopped_by_watchpoint checks | |
1814 | the current thread. */ | |
1815 | switch_to_thread (event_ptid); | |
1816 | ||
237fc4c9 | 1817 | /* Did the instruction complete successfully? */ |
cb71640d PA |
1818 | if (signal == GDB_SIGNAL_TRAP |
1819 | && !(target_stopped_by_watchpoint () | |
1820 | && (gdbarch_have_nonsteppable_watchpoint (displaced->step_gdbarch) | |
1821 | || target_have_steppable_watchpoint))) | |
237fc4c9 PA |
1822 | { |
1823 | /* Fix up the resulting state. */ | |
fc1cf338 PA |
1824 | gdbarch_displaced_step_fixup (displaced->step_gdbarch, |
1825 | displaced->step_closure, | |
1826 | displaced->step_original, | |
1827 | displaced->step_copy, | |
1828 | get_thread_regcache (displaced->step_ptid)); | |
237fc4c9 PA |
1829 | } |
1830 | else | |
1831 | { | |
1832 | /* Since the instruction didn't complete, all we can do is | |
1833 | relocate the PC. */ | |
515630c5 UW |
1834 | struct regcache *regcache = get_thread_regcache (event_ptid); |
1835 | CORE_ADDR pc = regcache_read_pc (regcache); | |
abbb1732 | 1836 | |
fc1cf338 | 1837 | pc = displaced->step_original + (pc - displaced->step_copy); |
515630c5 | 1838 | regcache_write_pc (regcache, pc); |
237fc4c9 PA |
1839 | } |
1840 | ||
1841 | do_cleanups (old_cleanups); | |
1842 | ||
fc1cf338 | 1843 | displaced->step_ptid = null_ptid; |
1c5cfe86 | 1844 | |
237fc4c9 | 1845 | /* Are there any pending displaced stepping requests? If so, run |
fc1cf338 PA |
1846 | one now. Leave the state object around, since we're likely to |
1847 | need it again soon. */ | |
1848 | while (displaced->step_request_queue) | |
237fc4c9 PA |
1849 | { |
1850 | struct displaced_step_request *head; | |
1851 | ptid_t ptid; | |
5af949e3 | 1852 | struct regcache *regcache; |
929dfd4f | 1853 | struct gdbarch *gdbarch; |
1c5cfe86 | 1854 | CORE_ADDR actual_pc; |
6c95b8df | 1855 | struct address_space *aspace; |
237fc4c9 | 1856 | |
fc1cf338 | 1857 | head = displaced->step_request_queue; |
237fc4c9 | 1858 | ptid = head->ptid; |
fc1cf338 | 1859 | displaced->step_request_queue = head->next; |
237fc4c9 PA |
1860 | xfree (head); |
1861 | ||
ad53cd71 PA |
1862 | context_switch (ptid); |
1863 | ||
5af949e3 UW |
1864 | regcache = get_thread_regcache (ptid); |
1865 | actual_pc = regcache_read_pc (regcache); | |
6c95b8df | 1866 | aspace = get_regcache_aspace (regcache); |
8550d3b3 | 1867 | gdbarch = get_regcache_arch (regcache); |
1c5cfe86 | 1868 | |
6c95b8df | 1869 | if (breakpoint_here_p (aspace, actual_pc)) |
ad53cd71 | 1870 | { |
1c5cfe86 PA |
1871 | if (debug_displaced) |
1872 | fprintf_unfiltered (gdb_stdlog, | |
1873 | "displaced: stepping queued %s now\n", | |
1874 | target_pid_to_str (ptid)); | |
1875 | ||
1876 | displaced_step_prepare (ptid); | |
1877 | ||
1878 | if (debug_displaced) | |
1879 | { | |
929dfd4f | 1880 | CORE_ADDR actual_pc = regcache_read_pc (regcache); |
1c5cfe86 PA |
1881 | gdb_byte buf[4]; |
1882 | ||
5af949e3 UW |
1883 | fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", |
1884 | paddress (gdbarch, actual_pc)); | |
1c5cfe86 PA |
1885 | read_memory (actual_pc, buf, sizeof (buf)); |
1886 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); | |
1887 | } | |
1888 | ||
fc1cf338 PA |
1889 | if (gdbarch_displaced_step_hw_singlestep (gdbarch, |
1890 | displaced->step_closure)) | |
a493e3e2 | 1891 | target_resume (ptid, 1, GDB_SIGNAL_0); |
99e40580 | 1892 | else |
a493e3e2 | 1893 | target_resume (ptid, 0, GDB_SIGNAL_0); |
1c5cfe86 PA |
1894 | |
1895 | /* Done, we're stepping a thread. */ | |
1896 | break; | |
ad53cd71 | 1897 | } |
1c5cfe86 PA |
1898 | else |
1899 | { | |
1900 | int step; | |
1901 | struct thread_info *tp = inferior_thread (); | |
1902 | ||
1903 | /* The breakpoint we were sitting under has since been | |
1904 | removed. */ | |
16c381f0 | 1905 | tp->control.trap_expected = 0; |
1c5cfe86 PA |
1906 | |
1907 | /* Go back to what we were trying to do. */ | |
1908 | step = currently_stepping (tp); | |
ad53cd71 | 1909 | |
8550d3b3 YQ |
1910 | if (step) |
1911 | step = maybe_software_singlestep (gdbarch, actual_pc); | |
1912 | ||
1c5cfe86 | 1913 | if (debug_displaced) |
3e43a32a | 1914 | fprintf_unfiltered (gdb_stdlog, |
27d2932e | 1915 | "displaced: breakpoint is gone: %s, step(%d)\n", |
1c5cfe86 PA |
1916 | target_pid_to_str (tp->ptid), step); |
1917 | ||
a493e3e2 PA |
1918 | target_resume (ptid, step, GDB_SIGNAL_0); |
1919 | tp->suspend.stop_signal = GDB_SIGNAL_0; | |
1c5cfe86 PA |
1920 | |
1921 | /* This request was discarded. See if there's any other | |
1922 | thread waiting for its turn. */ | |
1923 | } | |
237fc4c9 PA |
1924 | } |
1925 | } | |
1926 | ||
5231c1fd PA |
1927 | /* Update global variables holding ptids to hold NEW_PTID if they were |
1928 | holding OLD_PTID. */ | |
1929 | static void | |
1930 | infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) | |
1931 | { | |
1932 | struct displaced_step_request *it; | |
fc1cf338 | 1933 | struct displaced_step_inferior_state *displaced; |
5231c1fd PA |
1934 | |
1935 | if (ptid_equal (inferior_ptid, old_ptid)) | |
1936 | inferior_ptid = new_ptid; | |
1937 | ||
fc1cf338 PA |
1938 | for (displaced = displaced_step_inferior_states; |
1939 | displaced; | |
1940 | displaced = displaced->next) | |
1941 | { | |
1942 | if (ptid_equal (displaced->step_ptid, old_ptid)) | |
1943 | displaced->step_ptid = new_ptid; | |
1944 | ||
1945 | for (it = displaced->step_request_queue; it; it = it->next) | |
1946 | if (ptid_equal (it->ptid, old_ptid)) | |
1947 | it->ptid = new_ptid; | |
1948 | } | |
5231c1fd PA |
1949 | } |
1950 | ||
237fc4c9 PA |
1951 | \f |
1952 | /* Resuming. */ | |
c906108c SS |
1953 | |
1954 | /* Things to clean up if we QUIT out of resume (). */ | |
c906108c | 1955 | static void |
74b7792f | 1956 | resume_cleanups (void *ignore) |
c906108c | 1957 | { |
34b7e8a6 PA |
1958 | if (!ptid_equal (inferior_ptid, null_ptid)) |
1959 | delete_single_step_breakpoints (inferior_thread ()); | |
7c16b83e | 1960 | |
c906108c SS |
1961 | normal_stop (); |
1962 | } | |
1963 | ||
53904c9e AC |
1964 | static const char schedlock_off[] = "off"; |
1965 | static const char schedlock_on[] = "on"; | |
1966 | static const char schedlock_step[] = "step"; | |
40478521 | 1967 | static const char *const scheduler_enums[] = { |
ef346e04 AC |
1968 | schedlock_off, |
1969 | schedlock_on, | |
1970 | schedlock_step, | |
1971 | NULL | |
1972 | }; | |
920d2a44 AC |
1973 | static const char *scheduler_mode = schedlock_off; |
1974 | static void | |
1975 | show_scheduler_mode (struct ui_file *file, int from_tty, | |
1976 | struct cmd_list_element *c, const char *value) | |
1977 | { | |
3e43a32a MS |
1978 | fprintf_filtered (file, |
1979 | _("Mode for locking scheduler " | |
1980 | "during execution is \"%s\".\n"), | |
920d2a44 AC |
1981 | value); |
1982 | } | |
c906108c SS |
1983 | |
1984 | static void | |
96baa820 | 1985 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
c906108c | 1986 | { |
eefe576e AC |
1987 | if (!target_can_lock_scheduler) |
1988 | { | |
1989 | scheduler_mode = schedlock_off; | |
1990 | error (_("Target '%s' cannot support this command."), target_shortname); | |
1991 | } | |
c906108c SS |
1992 | } |
1993 | ||
d4db2f36 PA |
1994 | /* True if execution commands resume all threads of all processes by |
1995 | default; otherwise, resume only threads of the current inferior | |
1996 | process. */ | |
1997 | int sched_multi = 0; | |
1998 | ||
2facfe5c DD |
1999 | /* Try to setup for software single stepping over the specified location. |
2000 | Return 1 if target_resume() should use hardware single step. | |
2001 | ||
2002 | GDBARCH the current gdbarch. | |
2003 | PC the location to step over. */ | |
2004 | ||
2005 | static int | |
2006 | maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc) | |
2007 | { | |
2008 | int hw_step = 1; | |
2009 | ||
f02253f1 HZ |
2010 | if (execution_direction == EXEC_FORWARD |
2011 | && gdbarch_software_single_step_p (gdbarch) | |
99e40580 | 2012 | && gdbarch_software_single_step (gdbarch, get_current_frame ())) |
2facfe5c | 2013 | { |
99e40580 | 2014 | hw_step = 0; |
2facfe5c DD |
2015 | } |
2016 | return hw_step; | |
2017 | } | |
c906108c | 2018 | |
f3263aa4 PA |
2019 | /* See infrun.h. */ |
2020 | ||
09cee04b PA |
2021 | ptid_t |
2022 | user_visible_resume_ptid (int step) | |
2023 | { | |
f3263aa4 | 2024 | ptid_t resume_ptid; |
09cee04b | 2025 | |
09cee04b PA |
2026 | if (non_stop) |
2027 | { | |
2028 | /* With non-stop mode on, threads are always handled | |
2029 | individually. */ | |
2030 | resume_ptid = inferior_ptid; | |
2031 | } | |
2032 | else if ((scheduler_mode == schedlock_on) | |
03d46957 | 2033 | || (scheduler_mode == schedlock_step && step)) |
09cee04b | 2034 | { |
f3263aa4 PA |
2035 | /* User-settable 'scheduler' mode requires solo thread |
2036 | resume. */ | |
09cee04b PA |
2037 | resume_ptid = inferior_ptid; |
2038 | } | |
f3263aa4 PA |
2039 | else if (!sched_multi && target_supports_multi_process ()) |
2040 | { | |
2041 | /* Resume all threads of the current process (and none of other | |
2042 | processes). */ | |
2043 | resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); | |
2044 | } | |
2045 | else | |
2046 | { | |
2047 | /* Resume all threads of all processes. */ | |
2048 | resume_ptid = RESUME_ALL; | |
2049 | } | |
09cee04b PA |
2050 | |
2051 | return resume_ptid; | |
2052 | } | |
2053 | ||
64ce06e4 PA |
2054 | /* Wrapper for target_resume, that handles infrun-specific |
2055 | bookkeeping. */ | |
2056 | ||
2057 | static void | |
2058 | do_target_resume (ptid_t resume_ptid, int step, enum gdb_signal sig) | |
2059 | { | |
2060 | struct thread_info *tp = inferior_thread (); | |
2061 | ||
2062 | /* Install inferior's terminal modes. */ | |
2063 | target_terminal_inferior (); | |
2064 | ||
2065 | /* Avoid confusing the next resume, if the next stop/resume | |
2066 | happens to apply to another thread. */ | |
2067 | tp->suspend.stop_signal = GDB_SIGNAL_0; | |
2068 | ||
8f572e5c PA |
2069 | /* Advise target which signals may be handled silently. |
2070 | ||
2071 | If we have removed breakpoints because we are stepping over one | |
2072 | in-line (in any thread), we need to receive all signals to avoid | |
2073 | accidentally skipping a breakpoint during execution of a signal | |
2074 | handler. | |
2075 | ||
2076 | Likewise if we're displaced stepping, otherwise a trap for a | |
2077 | breakpoint in a signal handler might be confused with the | |
2078 | displaced step finishing. We don't make the displaced_step_fixup | |
2079 | step distinguish the cases instead, because: | |
2080 | ||
2081 | - a backtrace while stopped in the signal handler would show the | |
2082 | scratch pad as frame older than the signal handler, instead of | |
2083 | the real mainline code. | |
2084 | ||
2085 | - when the thread is later resumed, the signal handler would | |
2086 | return to the scratch pad area, which would no longer be | |
2087 | valid. */ | |
2088 | if (step_over_info_valid_p () | |
2089 | || displaced_step_in_progress (ptid_get_pid (tp->ptid))) | |
64ce06e4 PA |
2090 | target_pass_signals (0, NULL); |
2091 | else | |
2092 | target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass); | |
2093 | ||
2094 | target_resume (resume_ptid, step, sig); | |
2095 | } | |
2096 | ||
c906108c SS |
2097 | /* Resume the inferior, but allow a QUIT. This is useful if the user |
2098 | wants to interrupt some lengthy single-stepping operation | |
2099 | (for child processes, the SIGINT goes to the inferior, and so | |
2100 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
2101 | other targets, that's not true). | |
2102 | ||
c906108c SS |
2103 | SIG is the signal to give the inferior (zero for none). */ |
2104 | void | |
64ce06e4 | 2105 | resume (enum gdb_signal sig) |
c906108c | 2106 | { |
74b7792f | 2107 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
515630c5 UW |
2108 | struct regcache *regcache = get_current_regcache (); |
2109 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
4e1c45ea | 2110 | struct thread_info *tp = inferior_thread (); |
515630c5 | 2111 | CORE_ADDR pc = regcache_read_pc (regcache); |
6c95b8df | 2112 | struct address_space *aspace = get_regcache_aspace (regcache); |
b0f16a3e | 2113 | ptid_t resume_ptid; |
856e7dd6 PA |
2114 | /* This represents the user's step vs continue request. When |
2115 | deciding whether "set scheduler-locking step" applies, it's the | |
2116 | user's intention that counts. */ | |
2117 | const int user_step = tp->control.stepping_command; | |
64ce06e4 PA |
2118 | /* This represents what we'll actually request the target to do. |
2119 | This can decay from a step to a continue, if e.g., we need to | |
2120 | implement single-stepping with breakpoints (software | |
2121 | single-step). */ | |
6b403daa | 2122 | int step; |
c7e8a53c | 2123 | |
af48d08f PA |
2124 | tp->stepped_breakpoint = 0; |
2125 | ||
c906108c SS |
2126 | QUIT; |
2127 | ||
6b403daa PA |
2128 | /* Depends on stepped_breakpoint. */ |
2129 | step = currently_stepping (tp); | |
2130 | ||
74609e71 YQ |
2131 | if (current_inferior ()->waiting_for_vfork_done) |
2132 | { | |
48f9886d PA |
2133 | /* Don't try to single-step a vfork parent that is waiting for |
2134 | the child to get out of the shared memory region (by exec'ing | |
2135 | or exiting). This is particularly important on software | |
2136 | single-step archs, as the child process would trip on the | |
2137 | software single step breakpoint inserted for the parent | |
2138 | process. Since the parent will not actually execute any | |
2139 | instruction until the child is out of the shared region (such | |
2140 | are vfork's semantics), it is safe to simply continue it. | |
2141 | Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for | |
2142 | the parent, and tell it to `keep_going', which automatically | |
2143 | re-sets it stepping. */ | |
74609e71 YQ |
2144 | if (debug_infrun) |
2145 | fprintf_unfiltered (gdb_stdlog, | |
2146 | "infrun: resume : clear step\n"); | |
a09dd441 | 2147 | step = 0; |
74609e71 YQ |
2148 | } |
2149 | ||
527159b7 | 2150 | if (debug_infrun) |
237fc4c9 | 2151 | fprintf_unfiltered (gdb_stdlog, |
c9737c08 | 2152 | "infrun: resume (step=%d, signal=%s), " |
0d9a9a5f | 2153 | "trap_expected=%d, current thread [%s] at %s\n", |
c9737c08 PA |
2154 | step, gdb_signal_to_symbol_string (sig), |
2155 | tp->control.trap_expected, | |
0d9a9a5f PA |
2156 | target_pid_to_str (inferior_ptid), |
2157 | paddress (gdbarch, pc)); | |
c906108c | 2158 | |
c2c6d25f JM |
2159 | /* Normally, by the time we reach `resume', the breakpoints are either |
2160 | removed or inserted, as appropriate. The exception is if we're sitting | |
2161 | at a permanent breakpoint; we need to step over it, but permanent | |
2162 | breakpoints can't be removed. So we have to test for it here. */ | |
6c95b8df | 2163 | if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here) |
6d350bb5 | 2164 | { |
af48d08f PA |
2165 | if (sig != GDB_SIGNAL_0) |
2166 | { | |
2167 | /* We have a signal to pass to the inferior. The resume | |
2168 | may, or may not take us to the signal handler. If this | |
2169 | is a step, we'll need to stop in the signal handler, if | |
2170 | there's one, (if the target supports stepping into | |
2171 | handlers), or in the next mainline instruction, if | |
2172 | there's no handler. If this is a continue, we need to be | |
2173 | sure to run the handler with all breakpoints inserted. | |
2174 | In all cases, set a breakpoint at the current address | |
2175 | (where the handler returns to), and once that breakpoint | |
2176 | is hit, resume skipping the permanent breakpoint. If | |
2177 | that breakpoint isn't hit, then we've stepped into the | |
2178 | signal handler (or hit some other event). We'll delete | |
2179 | the step-resume breakpoint then. */ | |
2180 | ||
2181 | if (debug_infrun) | |
2182 | fprintf_unfiltered (gdb_stdlog, | |
2183 | "infrun: resume: skipping permanent breakpoint, " | |
2184 | "deliver signal first\n"); | |
2185 | ||
2186 | clear_step_over_info (); | |
2187 | tp->control.trap_expected = 0; | |
2188 | ||
2189 | if (tp->control.step_resume_breakpoint == NULL) | |
2190 | { | |
2191 | /* Set a "high-priority" step-resume, as we don't want | |
2192 | user breakpoints at PC to trigger (again) when this | |
2193 | hits. */ | |
2194 | insert_hp_step_resume_breakpoint_at_frame (get_current_frame ()); | |
2195 | gdb_assert (tp->control.step_resume_breakpoint->loc->permanent); | |
2196 | ||
2197 | tp->step_after_step_resume_breakpoint = step; | |
2198 | } | |
2199 | ||
2200 | insert_breakpoints (); | |
2201 | } | |
2202 | else | |
2203 | { | |
2204 | /* There's no signal to pass, we can go ahead and skip the | |
2205 | permanent breakpoint manually. */ | |
2206 | if (debug_infrun) | |
2207 | fprintf_unfiltered (gdb_stdlog, | |
2208 | "infrun: resume: skipping permanent breakpoint\n"); | |
2209 | gdbarch_skip_permanent_breakpoint (gdbarch, regcache); | |
2210 | /* Update pc to reflect the new address from which we will | |
2211 | execute instructions. */ | |
2212 | pc = regcache_read_pc (regcache); | |
2213 | ||
2214 | if (step) | |
2215 | { | |
2216 | /* We've already advanced the PC, so the stepping part | |
2217 | is done. Now we need to arrange for a trap to be | |
2218 | reported to handle_inferior_event. Set a breakpoint | |
2219 | at the current PC, and run to it. Don't update | |
2220 | prev_pc, because if we end in | |
44a1ee51 PA |
2221 | switch_back_to_stepped_thread, we want the "expected |
2222 | thread advanced also" branch to be taken. IOW, we | |
2223 | don't want this thread to step further from PC | |
af48d08f | 2224 | (overstep). */ |
1ac806b8 | 2225 | gdb_assert (!step_over_info_valid_p ()); |
af48d08f PA |
2226 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
2227 | insert_breakpoints (); | |
2228 | ||
856e7dd6 | 2229 | resume_ptid = user_visible_resume_ptid (user_step); |
1ac806b8 | 2230 | do_target_resume (resume_ptid, 0, GDB_SIGNAL_0); |
af48d08f PA |
2231 | discard_cleanups (old_cleanups); |
2232 | return; | |
2233 | } | |
2234 | } | |
6d350bb5 | 2235 | } |
c2c6d25f | 2236 | |
c1e36e3e PA |
2237 | /* If we have a breakpoint to step over, make sure to do a single |
2238 | step only. Same if we have software watchpoints. */ | |
2239 | if (tp->control.trap_expected || bpstat_should_step ()) | |
2240 | tp->control.may_range_step = 0; | |
2241 | ||
237fc4c9 PA |
2242 | /* If enabled, step over breakpoints by executing a copy of the |
2243 | instruction at a different address. | |
2244 | ||
2245 | We can't use displaced stepping when we have a signal to deliver; | |
2246 | the comments for displaced_step_prepare explain why. The | |
2247 | comments in the handle_inferior event for dealing with 'random | |
74609e71 YQ |
2248 | signals' explain what we do instead. |
2249 | ||
2250 | We can't use displaced stepping when we are waiting for vfork_done | |
2251 | event, displaced stepping breaks the vfork child similarly as single | |
2252 | step software breakpoint. */ | |
515630c5 | 2253 | if (use_displaced_stepping (gdbarch) |
36728e82 | 2254 | && tp->control.trap_expected |
cb71640d | 2255 | && !step_over_info_valid_p () |
a493e3e2 | 2256 | && sig == GDB_SIGNAL_0 |
74609e71 | 2257 | && !current_inferior ()->waiting_for_vfork_done) |
237fc4c9 | 2258 | { |
fc1cf338 PA |
2259 | struct displaced_step_inferior_state *displaced; |
2260 | ||
237fc4c9 | 2261 | if (!displaced_step_prepare (inferior_ptid)) |
d56b7306 VP |
2262 | { |
2263 | /* Got placed in displaced stepping queue. Will be resumed | |
2264 | later when all the currently queued displaced stepping | |
251bde03 PA |
2265 | requests finish. The thread is not executing at this |
2266 | point, and the call to set_executing will be made later. | |
2267 | But we need to call set_running here, since from the | |
2268 | user/frontend's point of view, threads were set running. | |
2269 | Unless we're calling an inferior function, as in that | |
2270 | case we pretend the inferior doesn't run at all. */ | |
2271 | if (!tp->control.in_infcall) | |
856e7dd6 | 2272 | set_running (user_visible_resume_ptid (user_step), 1); |
d56b7306 VP |
2273 | discard_cleanups (old_cleanups); |
2274 | return; | |
2275 | } | |
99e40580 | 2276 | |
ca7781d2 LM |
2277 | /* Update pc to reflect the new address from which we will execute |
2278 | instructions due to displaced stepping. */ | |
2279 | pc = regcache_read_pc (get_thread_regcache (inferior_ptid)); | |
2280 | ||
fc1cf338 | 2281 | displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); |
a09dd441 PA |
2282 | step = gdbarch_displaced_step_hw_singlestep (gdbarch, |
2283 | displaced->step_closure); | |
237fc4c9 PA |
2284 | } |
2285 | ||
2facfe5c | 2286 | /* Do we need to do it the hard way, w/temp breakpoints? */ |
99e40580 | 2287 | else if (step) |
2facfe5c | 2288 | step = maybe_software_singlestep (gdbarch, pc); |
c906108c | 2289 | |
30852783 UW |
2290 | /* Currently, our software single-step implementation leads to different |
2291 | results than hardware single-stepping in one situation: when stepping | |
2292 | into delivering a signal which has an associated signal handler, | |
2293 | hardware single-step will stop at the first instruction of the handler, | |
2294 | while software single-step will simply skip execution of the handler. | |
2295 | ||
2296 | For now, this difference in behavior is accepted since there is no | |
2297 | easy way to actually implement single-stepping into a signal handler | |
2298 | without kernel support. | |
2299 | ||
2300 | However, there is one scenario where this difference leads to follow-on | |
2301 | problems: if we're stepping off a breakpoint by removing all breakpoints | |
2302 | and then single-stepping. In this case, the software single-step | |
2303 | behavior means that even if there is a *breakpoint* in the signal | |
2304 | handler, GDB still would not stop. | |
2305 | ||
2306 | Fortunately, we can at least fix this particular issue. We detect | |
2307 | here the case where we are about to deliver a signal while software | |
2308 | single-stepping with breakpoints removed. In this situation, we | |
2309 | revert the decisions to remove all breakpoints and insert single- | |
2310 | step breakpoints, and instead we install a step-resume breakpoint | |
2311 | at the current address, deliver the signal without stepping, and | |
2312 | once we arrive back at the step-resume breakpoint, actually step | |
2313 | over the breakpoint we originally wanted to step over. */ | |
34b7e8a6 | 2314 | if (thread_has_single_step_breakpoints_set (tp) |
6cc83d2a PA |
2315 | && sig != GDB_SIGNAL_0 |
2316 | && step_over_info_valid_p ()) | |
30852783 UW |
2317 | { |
2318 | /* If we have nested signals or a pending signal is delivered | |
2319 | immediately after a handler returns, might might already have | |
2320 | a step-resume breakpoint set on the earlier handler. We cannot | |
2321 | set another step-resume breakpoint; just continue on until the | |
2322 | original breakpoint is hit. */ | |
2323 | if (tp->control.step_resume_breakpoint == NULL) | |
2324 | { | |
2c03e5be | 2325 | insert_hp_step_resume_breakpoint_at_frame (get_current_frame ()); |
30852783 UW |
2326 | tp->step_after_step_resume_breakpoint = 1; |
2327 | } | |
2328 | ||
34b7e8a6 | 2329 | delete_single_step_breakpoints (tp); |
30852783 | 2330 | |
31e77af2 | 2331 | clear_step_over_info (); |
30852783 | 2332 | tp->control.trap_expected = 0; |
31e77af2 PA |
2333 | |
2334 | insert_breakpoints (); | |
30852783 UW |
2335 | } |
2336 | ||
b0f16a3e SM |
2337 | /* If STEP is set, it's a request to use hardware stepping |
2338 | facilities. But in that case, we should never | |
2339 | use singlestep breakpoint. */ | |
34b7e8a6 | 2340 | gdb_assert (!(thread_has_single_step_breakpoints_set (tp) && step)); |
dfcd3bfb | 2341 | |
b0f16a3e SM |
2342 | /* Decide the set of threads to ask the target to resume. Start |
2343 | by assuming everything will be resumed, than narrow the set | |
2344 | by applying increasingly restricting conditions. */ | |
856e7dd6 | 2345 | resume_ptid = user_visible_resume_ptid (user_step); |
cd76b0b7 | 2346 | |
251bde03 PA |
2347 | /* Even if RESUME_PTID is a wildcard, and we end up resuming less |
2348 | (e.g., we might need to step over a breakpoint), from the | |
2349 | user/frontend's point of view, all threads in RESUME_PTID are now | |
2350 | running. Unless we're calling an inferior function, as in that | |
2351 | case pretend we inferior doesn't run at all. */ | |
2352 | if (!tp->control.in_infcall) | |
2353 | set_running (resume_ptid, 1); | |
2354 | ||
b0f16a3e | 2355 | /* Maybe resume a single thread after all. */ |
34b7e8a6 | 2356 | if ((step || thread_has_single_step_breakpoints_set (tp)) |
b0f16a3e SM |
2357 | && tp->control.trap_expected) |
2358 | { | |
2359 | /* We're allowing a thread to run past a breakpoint it has | |
2360 | hit, by single-stepping the thread with the breakpoint | |
2361 | removed. In which case, we need to single-step only this | |
2362 | thread, and keep others stopped, as they can miss this | |
2363 | breakpoint if allowed to run. */ | |
2364 | resume_ptid = inferior_ptid; | |
2365 | } | |
d4db2f36 | 2366 | |
7f5ef605 PA |
2367 | if (execution_direction != EXEC_REVERSE |
2368 | && step && breakpoint_inserted_here_p (aspace, pc)) | |
b0f16a3e | 2369 | { |
7f5ef605 PA |
2370 | /* The only case we currently need to step a breakpoint |
2371 | instruction is when we have a signal to deliver. See | |
2372 | handle_signal_stop where we handle random signals that could | |
2373 | take out us out of the stepping range. Normally, in that | |
2374 | case we end up continuing (instead of stepping) over the | |
2375 | signal handler with a breakpoint at PC, but there are cases | |
2376 | where we should _always_ single-step, even if we have a | |
2377 | step-resume breakpoint, like when a software watchpoint is | |
2378 | set. Assuming single-stepping and delivering a signal at the | |
2379 | same time would takes us to the signal handler, then we could | |
2380 | have removed the breakpoint at PC to step over it. However, | |
2381 | some hardware step targets (like e.g., Mac OS) can't step | |
2382 | into signal handlers, and for those, we need to leave the | |
2383 | breakpoint at PC inserted, as otherwise if the handler | |
2384 | recurses and executes PC again, it'll miss the breakpoint. | |
2385 | So we leave the breakpoint inserted anyway, but we need to | |
2386 | record that we tried to step a breakpoint instruction, so | |
2387 | that adjust_pc_after_break doesn't end up confused. */ | |
2388 | gdb_assert (sig != GDB_SIGNAL_0); | |
2389 | ||
2390 | tp->stepped_breakpoint = 1; | |
2391 | ||
b0f16a3e SM |
2392 | /* Most targets can step a breakpoint instruction, thus |
2393 | executing it normally. But if this one cannot, just | |
2394 | continue and we will hit it anyway. */ | |
7f5ef605 | 2395 | if (gdbarch_cannot_step_breakpoint (gdbarch)) |
b0f16a3e SM |
2396 | step = 0; |
2397 | } | |
ef5cf84e | 2398 | |
b0f16a3e SM |
2399 | if (debug_displaced |
2400 | && use_displaced_stepping (gdbarch) | |
cb71640d PA |
2401 | && tp->control.trap_expected |
2402 | && !step_over_info_valid_p ()) | |
b0f16a3e | 2403 | { |
d9b67d9f | 2404 | struct regcache *resume_regcache = get_thread_regcache (tp->ptid); |
b0f16a3e SM |
2405 | struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache); |
2406 | CORE_ADDR actual_pc = regcache_read_pc (resume_regcache); | |
2407 | gdb_byte buf[4]; | |
2408 | ||
2409 | fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", | |
2410 | paddress (resume_gdbarch, actual_pc)); | |
2411 | read_memory (actual_pc, buf, sizeof (buf)); | |
2412 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); | |
2413 | } | |
237fc4c9 | 2414 | |
b0f16a3e SM |
2415 | if (tp->control.may_range_step) |
2416 | { | |
2417 | /* If we're resuming a thread with the PC out of the step | |
2418 | range, then we're doing some nested/finer run control | |
2419 | operation, like stepping the thread out of the dynamic | |
2420 | linker or the displaced stepping scratch pad. We | |
2421 | shouldn't have allowed a range step then. */ | |
2422 | gdb_assert (pc_in_thread_step_range (pc, tp)); | |
2423 | } | |
c1e36e3e | 2424 | |
64ce06e4 | 2425 | do_target_resume (resume_ptid, step, sig); |
c906108c SS |
2426 | discard_cleanups (old_cleanups); |
2427 | } | |
2428 | \f | |
237fc4c9 | 2429 | /* Proceeding. */ |
c906108c SS |
2430 | |
2431 | /* Clear out all variables saying what to do when inferior is continued. | |
2432 | First do this, then set the ones you want, then call `proceed'. */ | |
2433 | ||
a7212384 UW |
2434 | static void |
2435 | clear_proceed_status_thread (struct thread_info *tp) | |
c906108c | 2436 | { |
a7212384 UW |
2437 | if (debug_infrun) |
2438 | fprintf_unfiltered (gdb_stdlog, | |
2439 | "infrun: clear_proceed_status_thread (%s)\n", | |
2440 | target_pid_to_str (tp->ptid)); | |
d6b48e9c | 2441 | |
70509625 PA |
2442 | /* If this signal should not be seen by program, give it zero. |
2443 | Used for debugging signals. */ | |
2444 | if (!signal_pass_state (tp->suspend.stop_signal)) | |
2445 | tp->suspend.stop_signal = GDB_SIGNAL_0; | |
2446 | ||
16c381f0 JK |
2447 | tp->control.trap_expected = 0; |
2448 | tp->control.step_range_start = 0; | |
2449 | tp->control.step_range_end = 0; | |
c1e36e3e | 2450 | tp->control.may_range_step = 0; |
16c381f0 JK |
2451 | tp->control.step_frame_id = null_frame_id; |
2452 | tp->control.step_stack_frame_id = null_frame_id; | |
2453 | tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE; | |
885eeb5b | 2454 | tp->control.step_start_function = NULL; |
a7212384 | 2455 | tp->stop_requested = 0; |
4e1c45ea | 2456 | |
16c381f0 | 2457 | tp->control.stop_step = 0; |
32400beb | 2458 | |
16c381f0 | 2459 | tp->control.proceed_to_finish = 0; |
414c69f7 | 2460 | |
17b2616c | 2461 | tp->control.command_interp = NULL; |
856e7dd6 | 2462 | tp->control.stepping_command = 0; |
17b2616c | 2463 | |
a7212384 | 2464 | /* Discard any remaining commands or status from previous stop. */ |
16c381f0 | 2465 | bpstat_clear (&tp->control.stop_bpstat); |
a7212384 | 2466 | } |
32400beb | 2467 | |
a7212384 | 2468 | void |
70509625 | 2469 | clear_proceed_status (int step) |
a7212384 | 2470 | { |
6c95b8df PA |
2471 | if (!non_stop) |
2472 | { | |
70509625 PA |
2473 | struct thread_info *tp; |
2474 | ptid_t resume_ptid; | |
2475 | ||
2476 | resume_ptid = user_visible_resume_ptid (step); | |
2477 | ||
2478 | /* In all-stop mode, delete the per-thread status of all threads | |
2479 | we're about to resume, implicitly and explicitly. */ | |
2480 | ALL_NON_EXITED_THREADS (tp) | |
2481 | { | |
2482 | if (!ptid_match (tp->ptid, resume_ptid)) | |
2483 | continue; | |
2484 | clear_proceed_status_thread (tp); | |
2485 | } | |
6c95b8df PA |
2486 | } |
2487 | ||
a7212384 UW |
2488 | if (!ptid_equal (inferior_ptid, null_ptid)) |
2489 | { | |
2490 | struct inferior *inferior; | |
2491 | ||
2492 | if (non_stop) | |
2493 | { | |
6c95b8df PA |
2494 | /* If in non-stop mode, only delete the per-thread status of |
2495 | the current thread. */ | |
a7212384 UW |
2496 | clear_proceed_status_thread (inferior_thread ()); |
2497 | } | |
6c95b8df | 2498 | |
d6b48e9c | 2499 | inferior = current_inferior (); |
16c381f0 | 2500 | inferior->control.stop_soon = NO_STOP_QUIETLY; |
4e1c45ea PA |
2501 | } |
2502 | ||
c906108c | 2503 | stop_after_trap = 0; |
f3b1572e | 2504 | |
31e77af2 PA |
2505 | clear_step_over_info (); |
2506 | ||
f3b1572e | 2507 | observer_notify_about_to_proceed (); |
c906108c | 2508 | |
d5c31457 UW |
2509 | if (stop_registers) |
2510 | { | |
2511 | regcache_xfree (stop_registers); | |
2512 | stop_registers = NULL; | |
2513 | } | |
c906108c SS |
2514 | } |
2515 | ||
99619bea PA |
2516 | /* Returns true if TP is still stopped at a breakpoint that needs |
2517 | stepping-over in order to make progress. If the breakpoint is gone | |
2518 | meanwhile, we can skip the whole step-over dance. */ | |
ea67f13b DJ |
2519 | |
2520 | static int | |
99619bea PA |
2521 | thread_still_needs_step_over (struct thread_info *tp) |
2522 | { | |
2523 | if (tp->stepping_over_breakpoint) | |
2524 | { | |
2525 | struct regcache *regcache = get_thread_regcache (tp->ptid); | |
2526 | ||
2527 | if (breakpoint_here_p (get_regcache_aspace (regcache), | |
af48d08f PA |
2528 | regcache_read_pc (regcache)) |
2529 | == ordinary_breakpoint_here) | |
99619bea PA |
2530 | return 1; |
2531 | ||
2532 | tp->stepping_over_breakpoint = 0; | |
2533 | } | |
2534 | ||
2535 | return 0; | |
2536 | } | |
2537 | ||
483805cf PA |
2538 | /* Returns true if scheduler locking applies. STEP indicates whether |
2539 | we're about to do a step/next-like command to a thread. */ | |
2540 | ||
2541 | static int | |
856e7dd6 | 2542 | schedlock_applies (struct thread_info *tp) |
483805cf PA |
2543 | { |
2544 | return (scheduler_mode == schedlock_on | |
2545 | || (scheduler_mode == schedlock_step | |
856e7dd6 | 2546 | && tp->control.stepping_command)); |
483805cf PA |
2547 | } |
2548 | ||
99619bea PA |
2549 | /* Look a thread other than EXCEPT that has previously reported a |
2550 | breakpoint event, and thus needs a step-over in order to make | |
856e7dd6 | 2551 | progress. Returns NULL is none is found. */ |
99619bea PA |
2552 | |
2553 | static struct thread_info * | |
856e7dd6 | 2554 | find_thread_needs_step_over (struct thread_info *except) |
ea67f13b | 2555 | { |
99619bea | 2556 | struct thread_info *tp, *current; |
5a437975 DE |
2557 | |
2558 | /* With non-stop mode on, threads are always handled individually. */ | |
2559 | gdb_assert (! non_stop); | |
ea67f13b | 2560 | |
99619bea | 2561 | current = inferior_thread (); |
d4db2f36 | 2562 | |
99619bea PA |
2563 | /* If scheduler locking applies, we can avoid iterating over all |
2564 | threads. */ | |
856e7dd6 | 2565 | if (schedlock_applies (except)) |
ea67f13b | 2566 | { |
99619bea PA |
2567 | if (except != current |
2568 | && thread_still_needs_step_over (current)) | |
2569 | return current; | |
515630c5 | 2570 | |
99619bea PA |
2571 | return NULL; |
2572 | } | |
0d9a9a5f | 2573 | |
034f788c | 2574 | ALL_NON_EXITED_THREADS (tp) |
99619bea PA |
2575 | { |
2576 | /* Ignore the EXCEPT thread. */ | |
2577 | if (tp == except) | |
2578 | continue; | |
2579 | /* Ignore threads of processes we're not resuming. */ | |
2580 | if (!sched_multi | |
2581 | && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid)) | |
2582 | continue; | |
2583 | ||
2584 | if (thread_still_needs_step_over (tp)) | |
2585 | return tp; | |
ea67f13b DJ |
2586 | } |
2587 | ||
99619bea | 2588 | return NULL; |
ea67f13b | 2589 | } |
e4846b08 | 2590 | |
c906108c SS |
2591 | /* Basic routine for continuing the program in various fashions. |
2592 | ||
2593 | ADDR is the address to resume at, or -1 for resume where stopped. | |
2594 | SIGGNAL is the signal to give it, or 0 for none, | |
c5aa993b | 2595 | or -1 for act according to how it stopped. |
c906108c | 2596 | STEP is nonzero if should trap after one instruction. |
c5aa993b JM |
2597 | -1 means return after that and print nothing. |
2598 | You should probably set various step_... variables | |
2599 | before calling here, if you are stepping. | |
c906108c SS |
2600 | |
2601 | You should call clear_proceed_status before calling proceed. */ | |
2602 | ||
2603 | void | |
64ce06e4 | 2604 | proceed (CORE_ADDR addr, enum gdb_signal siggnal) |
c906108c | 2605 | { |
e58b0e63 PA |
2606 | struct regcache *regcache; |
2607 | struct gdbarch *gdbarch; | |
4e1c45ea | 2608 | struct thread_info *tp; |
e58b0e63 | 2609 | CORE_ADDR pc; |
6c95b8df | 2610 | struct address_space *aspace; |
c906108c | 2611 | |
e58b0e63 PA |
2612 | /* If we're stopped at a fork/vfork, follow the branch set by the |
2613 | "set follow-fork-mode" command; otherwise, we'll just proceed | |
2614 | resuming the current thread. */ | |
2615 | if (!follow_fork ()) | |
2616 | { | |
2617 | /* The target for some reason decided not to resume. */ | |
2618 | normal_stop (); | |
f148b27e PA |
2619 | if (target_can_async_p ()) |
2620 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
e58b0e63 PA |
2621 | return; |
2622 | } | |
2623 | ||
842951eb PA |
2624 | /* We'll update this if & when we switch to a new thread. */ |
2625 | previous_inferior_ptid = inferior_ptid; | |
2626 | ||
e58b0e63 PA |
2627 | regcache = get_current_regcache (); |
2628 | gdbarch = get_regcache_arch (regcache); | |
6c95b8df | 2629 | aspace = get_regcache_aspace (regcache); |
e58b0e63 | 2630 | pc = regcache_read_pc (regcache); |
2adfaa28 | 2631 | tp = inferior_thread (); |
e58b0e63 | 2632 | |
99619bea PA |
2633 | /* Fill in with reasonable starting values. */ |
2634 | init_thread_stepping_state (tp); | |
2635 | ||
2acceee2 | 2636 | if (addr == (CORE_ADDR) -1) |
c906108c | 2637 | { |
af48d08f PA |
2638 | if (pc == stop_pc |
2639 | && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here | |
b2175913 | 2640 | && execution_direction != EXEC_REVERSE) |
3352ef37 AC |
2641 | /* There is a breakpoint at the address we will resume at, |
2642 | step one instruction before inserting breakpoints so that | |
2643 | we do not stop right away (and report a second hit at this | |
b2175913 MS |
2644 | breakpoint). |
2645 | ||
2646 | Note, we don't do this in reverse, because we won't | |
2647 | actually be executing the breakpoint insn anyway. | |
2648 | We'll be (un-)executing the previous instruction. */ | |
99619bea | 2649 | tp->stepping_over_breakpoint = 1; |
515630c5 UW |
2650 | else if (gdbarch_single_step_through_delay_p (gdbarch) |
2651 | && gdbarch_single_step_through_delay (gdbarch, | |
2652 | get_current_frame ())) | |
3352ef37 AC |
2653 | /* We stepped onto an instruction that needs to be stepped |
2654 | again before re-inserting the breakpoint, do so. */ | |
99619bea | 2655 | tp->stepping_over_breakpoint = 1; |
c906108c SS |
2656 | } |
2657 | else | |
2658 | { | |
515630c5 | 2659 | regcache_write_pc (regcache, addr); |
c906108c SS |
2660 | } |
2661 | ||
70509625 PA |
2662 | if (siggnal != GDB_SIGNAL_DEFAULT) |
2663 | tp->suspend.stop_signal = siggnal; | |
2664 | ||
17b2616c PA |
2665 | /* Record the interpreter that issued the execution command that |
2666 | caused this thread to resume. If the top level interpreter is | |
2667 | MI/async, and the execution command was a CLI command | |
2668 | (next/step/etc.), we'll want to print stop event output to the MI | |
2669 | console channel (the stepped-to line, etc.), as if the user | |
2670 | entered the execution command on a real GDB console. */ | |
2671 | inferior_thread ()->control.command_interp = command_interp (); | |
2672 | ||
527159b7 | 2673 | if (debug_infrun) |
8a9de0e4 | 2674 | fprintf_unfiltered (gdb_stdlog, |
64ce06e4 | 2675 | "infrun: proceed (addr=%s, signal=%s)\n", |
c9737c08 | 2676 | paddress (gdbarch, addr), |
64ce06e4 | 2677 | gdb_signal_to_symbol_string (siggnal)); |
527159b7 | 2678 | |
94cc34af PA |
2679 | if (non_stop) |
2680 | /* In non-stop, each thread is handled individually. The context | |
2681 | must already be set to the right thread here. */ | |
2682 | ; | |
2683 | else | |
2684 | { | |
99619bea PA |
2685 | struct thread_info *step_over; |
2686 | ||
94cc34af PA |
2687 | /* In a multi-threaded task we may select another thread and |
2688 | then continue or step. | |
c906108c | 2689 | |
94cc34af PA |
2690 | But if the old thread was stopped at a breakpoint, it will |
2691 | immediately cause another breakpoint stop without any | |
2692 | execution (i.e. it will report a breakpoint hit incorrectly). | |
2693 | So we must step over it first. | |
c906108c | 2694 | |
99619bea PA |
2695 | Look for a thread other than the current (TP) that reported a |
2696 | breakpoint hit and hasn't been resumed yet since. */ | |
856e7dd6 | 2697 | step_over = find_thread_needs_step_over (tp); |
99619bea | 2698 | if (step_over != NULL) |
2adfaa28 | 2699 | { |
99619bea PA |
2700 | if (debug_infrun) |
2701 | fprintf_unfiltered (gdb_stdlog, | |
2702 | "infrun: need to step-over [%s] first\n", | |
2703 | target_pid_to_str (step_over->ptid)); | |
2704 | ||
2705 | /* Store the prev_pc for the stepping thread too, needed by | |
44a1ee51 | 2706 | switch_back_to_stepped_thread. */ |
99619bea PA |
2707 | tp->prev_pc = regcache_read_pc (get_current_regcache ()); |
2708 | switch_to_thread (step_over->ptid); | |
2709 | tp = step_over; | |
2adfaa28 | 2710 | } |
94cc34af | 2711 | } |
c906108c | 2712 | |
31e77af2 PA |
2713 | /* If we need to step over a breakpoint, and we're not using |
2714 | displaced stepping to do so, insert all breakpoints (watchpoints, | |
2715 | etc.) but the one we're stepping over, step one instruction, and | |
2716 | then re-insert the breakpoint when that step is finished. */ | |
99619bea | 2717 | if (tp->stepping_over_breakpoint && !use_displaced_stepping (gdbarch)) |
30852783 | 2718 | { |
31e77af2 PA |
2719 | struct regcache *regcache = get_current_regcache (); |
2720 | ||
2721 | set_step_over_info (get_regcache_aspace (regcache), | |
963f9c80 | 2722 | regcache_read_pc (regcache), 0); |
30852783 | 2723 | } |
31e77af2 PA |
2724 | else |
2725 | clear_step_over_info (); | |
30852783 | 2726 | |
31e77af2 | 2727 | insert_breakpoints (); |
30852783 | 2728 | |
99619bea PA |
2729 | tp->control.trap_expected = tp->stepping_over_breakpoint; |
2730 | ||
c906108c SS |
2731 | annotate_starting (); |
2732 | ||
2733 | /* Make sure that output from GDB appears before output from the | |
2734 | inferior. */ | |
2735 | gdb_flush (gdb_stdout); | |
2736 | ||
e4846b08 | 2737 | /* Refresh prev_pc value just prior to resuming. This used to be |
22bcd14b | 2738 | done in stop_waiting, however, setting prev_pc there did not handle |
e4846b08 JJ |
2739 | scenarios such as inferior function calls or returning from |
2740 | a function via the return command. In those cases, the prev_pc | |
2741 | value was not set properly for subsequent commands. The prev_pc value | |
2742 | is used to initialize the starting line number in the ecs. With an | |
2743 | invalid value, the gdb next command ends up stopping at the position | |
2744 | represented by the next line table entry past our start position. | |
2745 | On platforms that generate one line table entry per line, this | |
2746 | is not a problem. However, on the ia64, the compiler generates | |
2747 | extraneous line table entries that do not increase the line number. | |
2748 | When we issue the gdb next command on the ia64 after an inferior call | |
2749 | or a return command, we often end up a few instructions forward, still | |
2750 | within the original line we started. | |
2751 | ||
d5cd6034 JB |
2752 | An attempt was made to refresh the prev_pc at the same time the |
2753 | execution_control_state is initialized (for instance, just before | |
2754 | waiting for an inferior event). But this approach did not work | |
2755 | because of platforms that use ptrace, where the pc register cannot | |
2756 | be read unless the inferior is stopped. At that point, we are not | |
2757 | guaranteed the inferior is stopped and so the regcache_read_pc() call | |
2758 | can fail. Setting the prev_pc value here ensures the value is updated | |
2759 | correctly when the inferior is stopped. */ | |
4e1c45ea | 2760 | tp->prev_pc = regcache_read_pc (get_current_regcache ()); |
e4846b08 | 2761 | |
c906108c | 2762 | /* Resume inferior. */ |
64ce06e4 | 2763 | resume (tp->suspend.stop_signal); |
c906108c SS |
2764 | |
2765 | /* Wait for it to stop (if not standalone) | |
2766 | and in any case decode why it stopped, and act accordingly. */ | |
43ff13b4 | 2767 | /* Do this only if we are not using the event loop, or if the target |
1777feb0 | 2768 | does not support asynchronous execution. */ |
362646f5 | 2769 | if (!target_can_async_p ()) |
43ff13b4 | 2770 | { |
e4c8541f | 2771 | wait_for_inferior (); |
43ff13b4 JM |
2772 | normal_stop (); |
2773 | } | |
c906108c | 2774 | } |
c906108c SS |
2775 | \f |
2776 | ||
2777 | /* Start remote-debugging of a machine over a serial link. */ | |
96baa820 | 2778 | |
c906108c | 2779 | void |
8621d6a9 | 2780 | start_remote (int from_tty) |
c906108c | 2781 | { |
d6b48e9c | 2782 | struct inferior *inferior; |
d6b48e9c PA |
2783 | |
2784 | inferior = current_inferior (); | |
16c381f0 | 2785 | inferior->control.stop_soon = STOP_QUIETLY_REMOTE; |
43ff13b4 | 2786 | |
1777feb0 | 2787 | /* Always go on waiting for the target, regardless of the mode. */ |
6426a772 | 2788 | /* FIXME: cagney/1999-09-23: At present it isn't possible to |
7e73cedf | 2789 | indicate to wait_for_inferior that a target should timeout if |
6426a772 JM |
2790 | nothing is returned (instead of just blocking). Because of this, |
2791 | targets expecting an immediate response need to, internally, set | |
2792 | things up so that the target_wait() is forced to eventually | |
1777feb0 | 2793 | timeout. */ |
6426a772 JM |
2794 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to |
2795 | differentiate to its caller what the state of the target is after | |
2796 | the initial open has been performed. Here we're assuming that | |
2797 | the target has stopped. It should be possible to eventually have | |
2798 | target_open() return to the caller an indication that the target | |
2799 | is currently running and GDB state should be set to the same as | |
1777feb0 | 2800 | for an async run. */ |
e4c8541f | 2801 | wait_for_inferior (); |
8621d6a9 DJ |
2802 | |
2803 | /* Now that the inferior has stopped, do any bookkeeping like | |
2804 | loading shared libraries. We want to do this before normal_stop, | |
2805 | so that the displayed frame is up to date. */ | |
2806 | post_create_inferior (¤t_target, from_tty); | |
2807 | ||
6426a772 | 2808 | normal_stop (); |
c906108c SS |
2809 | } |
2810 | ||
2811 | /* Initialize static vars when a new inferior begins. */ | |
2812 | ||
2813 | void | |
96baa820 | 2814 | init_wait_for_inferior (void) |
c906108c SS |
2815 | { |
2816 | /* These are meaningless until the first time through wait_for_inferior. */ | |
c906108c | 2817 | |
c906108c SS |
2818 | breakpoint_init_inferior (inf_starting); |
2819 | ||
70509625 | 2820 | clear_proceed_status (0); |
9f976b41 | 2821 | |
ca005067 | 2822 | target_last_wait_ptid = minus_one_ptid; |
237fc4c9 | 2823 | |
842951eb | 2824 | previous_inferior_ptid = inferior_ptid; |
0d1e5fa7 | 2825 | |
edb3359d DJ |
2826 | /* Discard any skipped inlined frames. */ |
2827 | clear_inline_frame_state (minus_one_ptid); | |
c906108c | 2828 | } |
237fc4c9 | 2829 | |
c906108c | 2830 | \f |
0d1e5fa7 PA |
2831 | /* Data to be passed around while handling an event. This data is |
2832 | discarded between events. */ | |
c5aa993b | 2833 | struct execution_control_state |
488f131b | 2834 | { |
0d1e5fa7 | 2835 | ptid_t ptid; |
4e1c45ea PA |
2836 | /* The thread that got the event, if this was a thread event; NULL |
2837 | otherwise. */ | |
2838 | struct thread_info *event_thread; | |
2839 | ||
488f131b | 2840 | struct target_waitstatus ws; |
7e324e48 | 2841 | int stop_func_filled_in; |
488f131b JB |
2842 | CORE_ADDR stop_func_start; |
2843 | CORE_ADDR stop_func_end; | |
2c02bd72 | 2844 | const char *stop_func_name; |
488f131b | 2845 | int wait_some_more; |
4f5d7f63 | 2846 | |
2adfaa28 PA |
2847 | /* True if the event thread hit the single-step breakpoint of |
2848 | another thread. Thus the event doesn't cause a stop, the thread | |
2849 | needs to be single-stepped past the single-step breakpoint before | |
2850 | we can switch back to the original stepping thread. */ | |
2851 | int hit_singlestep_breakpoint; | |
488f131b JB |
2852 | }; |
2853 | ||
ec9499be | 2854 | static void handle_inferior_event (struct execution_control_state *ecs); |
cd0fc7c3 | 2855 | |
568d6575 UW |
2856 | static void handle_step_into_function (struct gdbarch *gdbarch, |
2857 | struct execution_control_state *ecs); | |
2858 | static void handle_step_into_function_backward (struct gdbarch *gdbarch, | |
2859 | struct execution_control_state *ecs); | |
4f5d7f63 | 2860 | static void handle_signal_stop (struct execution_control_state *ecs); |
186c406b | 2861 | static void check_exception_resume (struct execution_control_state *, |
28106bc2 | 2862 | struct frame_info *); |
611c83ae | 2863 | |
bdc36728 | 2864 | static void end_stepping_range (struct execution_control_state *ecs); |
22bcd14b | 2865 | static void stop_waiting (struct execution_control_state *ecs); |
104c1213 | 2866 | static void prepare_to_wait (struct execution_control_state *ecs); |
d4f3574e | 2867 | static void keep_going (struct execution_control_state *ecs); |
94c57d6a | 2868 | static void process_event_stop_test (struct execution_control_state *ecs); |
c447ac0b | 2869 | static int switch_back_to_stepped_thread (struct execution_control_state *ecs); |
104c1213 | 2870 | |
252fbfc8 PA |
2871 | /* Callback for iterate over threads. If the thread is stopped, but |
2872 | the user/frontend doesn't know about that yet, go through | |
2873 | normal_stop, as if the thread had just stopped now. ARG points at | |
2874 | a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If | |
2875 | ptid_is_pid(PTID) is true, applies to all threads of the process | |
2876 | pointed at by PTID. Otherwise, apply only to the thread pointed by | |
2877 | PTID. */ | |
2878 | ||
2879 | static int | |
2880 | infrun_thread_stop_requested_callback (struct thread_info *info, void *arg) | |
2881 | { | |
2882 | ptid_t ptid = * (ptid_t *) arg; | |
2883 | ||
2884 | if ((ptid_equal (info->ptid, ptid) | |
2885 | || ptid_equal (minus_one_ptid, ptid) | |
2886 | || (ptid_is_pid (ptid) | |
2887 | && ptid_get_pid (ptid) == ptid_get_pid (info->ptid))) | |
2888 | && is_running (info->ptid) | |
2889 | && !is_executing (info->ptid)) | |
2890 | { | |
2891 | struct cleanup *old_chain; | |
2892 | struct execution_control_state ecss; | |
2893 | struct execution_control_state *ecs = &ecss; | |
2894 | ||
2895 | memset (ecs, 0, sizeof (*ecs)); | |
2896 | ||
2897 | old_chain = make_cleanup_restore_current_thread (); | |
2898 | ||
f15cb84a YQ |
2899 | overlay_cache_invalid = 1; |
2900 | /* Flush target cache before starting to handle each event. | |
2901 | Target was running and cache could be stale. This is just a | |
2902 | heuristic. Running threads may modify target memory, but we | |
2903 | don't get any event. */ | |
2904 | target_dcache_invalidate (); | |
2905 | ||
252fbfc8 PA |
2906 | /* Go through handle_inferior_event/normal_stop, so we always |
2907 | have consistent output as if the stop event had been | |
2908 | reported. */ | |
2909 | ecs->ptid = info->ptid; | |
e09875d4 | 2910 | ecs->event_thread = find_thread_ptid (info->ptid); |
252fbfc8 | 2911 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; |
a493e3e2 | 2912 | ecs->ws.value.sig = GDB_SIGNAL_0; |
252fbfc8 PA |
2913 | |
2914 | handle_inferior_event (ecs); | |
2915 | ||
2916 | if (!ecs->wait_some_more) | |
2917 | { | |
2918 | struct thread_info *tp; | |
2919 | ||
2920 | normal_stop (); | |
2921 | ||
fa4cd53f | 2922 | /* Finish off the continuations. */ |
252fbfc8 | 2923 | tp = inferior_thread (); |
fa4cd53f PA |
2924 | do_all_intermediate_continuations_thread (tp, 1); |
2925 | do_all_continuations_thread (tp, 1); | |
252fbfc8 PA |
2926 | } |
2927 | ||
2928 | do_cleanups (old_chain); | |
2929 | } | |
2930 | ||
2931 | return 0; | |
2932 | } | |
2933 | ||
2934 | /* This function is attached as a "thread_stop_requested" observer. | |
2935 | Cleanup local state that assumed the PTID was to be resumed, and | |
2936 | report the stop to the frontend. */ | |
2937 | ||
2c0b251b | 2938 | static void |
252fbfc8 PA |
2939 | infrun_thread_stop_requested (ptid_t ptid) |
2940 | { | |
fc1cf338 | 2941 | struct displaced_step_inferior_state *displaced; |
252fbfc8 PA |
2942 | |
2943 | /* PTID was requested to stop. Remove it from the displaced | |
2944 | stepping queue, so we don't try to resume it automatically. */ | |
fc1cf338 PA |
2945 | |
2946 | for (displaced = displaced_step_inferior_states; | |
2947 | displaced; | |
2948 | displaced = displaced->next) | |
252fbfc8 | 2949 | { |
fc1cf338 | 2950 | struct displaced_step_request *it, **prev_next_p; |
252fbfc8 | 2951 | |
fc1cf338 PA |
2952 | it = displaced->step_request_queue; |
2953 | prev_next_p = &displaced->step_request_queue; | |
2954 | while (it) | |
252fbfc8 | 2955 | { |
fc1cf338 PA |
2956 | if (ptid_match (it->ptid, ptid)) |
2957 | { | |
2958 | *prev_next_p = it->next; | |
2959 | it->next = NULL; | |
2960 | xfree (it); | |
2961 | } | |
252fbfc8 | 2962 | else |
fc1cf338 PA |
2963 | { |
2964 | prev_next_p = &it->next; | |
2965 | } | |
252fbfc8 | 2966 | |
fc1cf338 | 2967 | it = *prev_next_p; |
252fbfc8 | 2968 | } |
252fbfc8 PA |
2969 | } |
2970 | ||
2971 | iterate_over_threads (infrun_thread_stop_requested_callback, &ptid); | |
2972 | } | |
2973 | ||
a07daef3 PA |
2974 | static void |
2975 | infrun_thread_thread_exit (struct thread_info *tp, int silent) | |
2976 | { | |
2977 | if (ptid_equal (target_last_wait_ptid, tp->ptid)) | |
2978 | nullify_last_target_wait_ptid (); | |
2979 | } | |
2980 | ||
0cbcdb96 PA |
2981 | /* Delete the step resume, single-step and longjmp/exception resume |
2982 | breakpoints of TP. */ | |
4e1c45ea | 2983 | |
0cbcdb96 PA |
2984 | static void |
2985 | delete_thread_infrun_breakpoints (struct thread_info *tp) | |
4e1c45ea | 2986 | { |
0cbcdb96 PA |
2987 | delete_step_resume_breakpoint (tp); |
2988 | delete_exception_resume_breakpoint (tp); | |
34b7e8a6 | 2989 | delete_single_step_breakpoints (tp); |
4e1c45ea PA |
2990 | } |
2991 | ||
0cbcdb96 PA |
2992 | /* If the target still has execution, call FUNC for each thread that |
2993 | just stopped. In all-stop, that's all the non-exited threads; in | |
2994 | non-stop, that's the current thread, only. */ | |
2995 | ||
2996 | typedef void (*for_each_just_stopped_thread_callback_func) | |
2997 | (struct thread_info *tp); | |
4e1c45ea PA |
2998 | |
2999 | static void | |
0cbcdb96 | 3000 | for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func) |
4e1c45ea | 3001 | { |
0cbcdb96 | 3002 | if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid)) |
4e1c45ea PA |
3003 | return; |
3004 | ||
3005 | if (non_stop) | |
3006 | { | |
0cbcdb96 PA |
3007 | /* If in non-stop mode, only the current thread stopped. */ |
3008 | func (inferior_thread ()); | |
4e1c45ea PA |
3009 | } |
3010 | else | |
0cbcdb96 PA |
3011 | { |
3012 | struct thread_info *tp; | |
3013 | ||
3014 | /* In all-stop mode, all threads have stopped. */ | |
3015 | ALL_NON_EXITED_THREADS (tp) | |
3016 | { | |
3017 | func (tp); | |
3018 | } | |
3019 | } | |
3020 | } | |
3021 | ||
3022 | /* Delete the step resume and longjmp/exception resume breakpoints of | |
3023 | the threads that just stopped. */ | |
3024 | ||
3025 | static void | |
3026 | delete_just_stopped_threads_infrun_breakpoints (void) | |
3027 | { | |
3028 | for_each_just_stopped_thread (delete_thread_infrun_breakpoints); | |
34b7e8a6 PA |
3029 | } |
3030 | ||
3031 | /* Delete the single-step breakpoints of the threads that just | |
3032 | stopped. */ | |
7c16b83e | 3033 | |
34b7e8a6 PA |
3034 | static void |
3035 | delete_just_stopped_threads_single_step_breakpoints (void) | |
3036 | { | |
3037 | for_each_just_stopped_thread (delete_single_step_breakpoints); | |
4e1c45ea PA |
3038 | } |
3039 | ||
1777feb0 | 3040 | /* A cleanup wrapper. */ |
4e1c45ea PA |
3041 | |
3042 | static void | |
0cbcdb96 | 3043 | delete_just_stopped_threads_infrun_breakpoints_cleanup (void *arg) |
4e1c45ea | 3044 | { |
0cbcdb96 | 3045 | delete_just_stopped_threads_infrun_breakpoints (); |
4e1c45ea PA |
3046 | } |
3047 | ||
223698f8 DE |
3048 | /* Pretty print the results of target_wait, for debugging purposes. */ |
3049 | ||
3050 | static void | |
3051 | print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, | |
3052 | const struct target_waitstatus *ws) | |
3053 | { | |
3054 | char *status_string = target_waitstatus_to_string (ws); | |
3055 | struct ui_file *tmp_stream = mem_fileopen (); | |
3056 | char *text; | |
223698f8 DE |
3057 | |
3058 | /* The text is split over several lines because it was getting too long. | |
3059 | Call fprintf_unfiltered (gdb_stdlog) once so that the text is still | |
3060 | output as a unit; we want only one timestamp printed if debug_timestamp | |
3061 | is set. */ | |
3062 | ||
3063 | fprintf_unfiltered (tmp_stream, | |
1176ecec PA |
3064 | "infrun: target_wait (%d.%ld.%ld", |
3065 | ptid_get_pid (waiton_ptid), | |
3066 | ptid_get_lwp (waiton_ptid), | |
3067 | ptid_get_tid (waiton_ptid)); | |
dfd4cc63 | 3068 | if (ptid_get_pid (waiton_ptid) != -1) |
223698f8 DE |
3069 | fprintf_unfiltered (tmp_stream, |
3070 | " [%s]", target_pid_to_str (waiton_ptid)); | |
3071 | fprintf_unfiltered (tmp_stream, ", status) =\n"); | |
3072 | fprintf_unfiltered (tmp_stream, | |
1176ecec | 3073 | "infrun: %d.%ld.%ld [%s],\n", |
dfd4cc63 | 3074 | ptid_get_pid (result_ptid), |
1176ecec PA |
3075 | ptid_get_lwp (result_ptid), |
3076 | ptid_get_tid (result_ptid), | |
dfd4cc63 | 3077 | target_pid_to_str (result_ptid)); |
223698f8 DE |
3078 | fprintf_unfiltered (tmp_stream, |
3079 | "infrun: %s\n", | |
3080 | status_string); | |
3081 | ||
759ef836 | 3082 | text = ui_file_xstrdup (tmp_stream, NULL); |
223698f8 DE |
3083 | |
3084 | /* This uses %s in part to handle %'s in the text, but also to avoid | |
3085 | a gcc error: the format attribute requires a string literal. */ | |
3086 | fprintf_unfiltered (gdb_stdlog, "%s", text); | |
3087 | ||
3088 | xfree (status_string); | |
3089 | xfree (text); | |
3090 | ui_file_delete (tmp_stream); | |
3091 | } | |
3092 | ||
24291992 PA |
3093 | /* Prepare and stabilize the inferior for detaching it. E.g., |
3094 | detaching while a thread is displaced stepping is a recipe for | |
3095 | crashing it, as nothing would readjust the PC out of the scratch | |
3096 | pad. */ | |
3097 | ||
3098 | void | |
3099 | prepare_for_detach (void) | |
3100 | { | |
3101 | struct inferior *inf = current_inferior (); | |
3102 | ptid_t pid_ptid = pid_to_ptid (inf->pid); | |
3103 | struct cleanup *old_chain_1; | |
3104 | struct displaced_step_inferior_state *displaced; | |
3105 | ||
3106 | displaced = get_displaced_stepping_state (inf->pid); | |
3107 | ||
3108 | /* Is any thread of this process displaced stepping? If not, | |
3109 | there's nothing else to do. */ | |
3110 | if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid)) | |
3111 | return; | |
3112 | ||
3113 | if (debug_infrun) | |
3114 | fprintf_unfiltered (gdb_stdlog, | |
3115 | "displaced-stepping in-process while detaching"); | |
3116 | ||
3117 | old_chain_1 = make_cleanup_restore_integer (&inf->detaching); | |
3118 | inf->detaching = 1; | |
3119 | ||
3120 | while (!ptid_equal (displaced->step_ptid, null_ptid)) | |
3121 | { | |
3122 | struct cleanup *old_chain_2; | |
3123 | struct execution_control_state ecss; | |
3124 | struct execution_control_state *ecs; | |
3125 | ||
3126 | ecs = &ecss; | |
3127 | memset (ecs, 0, sizeof (*ecs)); | |
3128 | ||
3129 | overlay_cache_invalid = 1; | |
f15cb84a YQ |
3130 | /* Flush target cache before starting to handle each event. |
3131 | Target was running and cache could be stale. This is just a | |
3132 | heuristic. Running threads may modify target memory, but we | |
3133 | don't get any event. */ | |
3134 | target_dcache_invalidate (); | |
24291992 | 3135 | |
24291992 PA |
3136 | if (deprecated_target_wait_hook) |
3137 | ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0); | |
3138 | else | |
3139 | ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0); | |
3140 | ||
3141 | if (debug_infrun) | |
3142 | print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws); | |
3143 | ||
3144 | /* If an error happens while handling the event, propagate GDB's | |
3145 | knowledge of the executing state to the frontend/user running | |
3146 | state. */ | |
3e43a32a MS |
3147 | old_chain_2 = make_cleanup (finish_thread_state_cleanup, |
3148 | &minus_one_ptid); | |
24291992 PA |
3149 | |
3150 | /* Now figure out what to do with the result of the result. */ | |
3151 | handle_inferior_event (ecs); | |
3152 | ||
3153 | /* No error, don't finish the state yet. */ | |
3154 | discard_cleanups (old_chain_2); | |
3155 | ||
3156 | /* Breakpoints and watchpoints are not installed on the target | |
3157 | at this point, and signals are passed directly to the | |
3158 | inferior, so this must mean the process is gone. */ | |
3159 | if (!ecs->wait_some_more) | |
3160 | { | |
3161 | discard_cleanups (old_chain_1); | |
3162 | error (_("Program exited while detaching")); | |
3163 | } | |
3164 | } | |
3165 | ||
3166 | discard_cleanups (old_chain_1); | |
3167 | } | |
3168 | ||
cd0fc7c3 | 3169 | /* Wait for control to return from inferior to debugger. |
ae123ec6 | 3170 | |
cd0fc7c3 SS |
3171 | If inferior gets a signal, we may decide to start it up again |
3172 | instead of returning. That is why there is a loop in this function. | |
3173 | When this function actually returns it means the inferior | |
3174 | should be left stopped and GDB should read more commands. */ | |
3175 | ||
3176 | void | |
e4c8541f | 3177 | wait_for_inferior (void) |
cd0fc7c3 SS |
3178 | { |
3179 | struct cleanup *old_cleanups; | |
e6f5c25b | 3180 | struct cleanup *thread_state_chain; |
c906108c | 3181 | |
527159b7 | 3182 | if (debug_infrun) |
ae123ec6 | 3183 | fprintf_unfiltered |
e4c8541f | 3184 | (gdb_stdlog, "infrun: wait_for_inferior ()\n"); |
527159b7 | 3185 | |
0cbcdb96 PA |
3186 | old_cleanups |
3187 | = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup, | |
3188 | NULL); | |
cd0fc7c3 | 3189 | |
e6f5c25b PA |
3190 | /* If an error happens while handling the event, propagate GDB's |
3191 | knowledge of the executing state to the frontend/user running | |
3192 | state. */ | |
3193 | thread_state_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
3194 | ||
c906108c SS |
3195 | while (1) |
3196 | { | |
ae25568b PA |
3197 | struct execution_control_state ecss; |
3198 | struct execution_control_state *ecs = &ecss; | |
963f9c80 | 3199 | ptid_t waiton_ptid = minus_one_ptid; |
29f49a6a | 3200 | |
ae25568b PA |
3201 | memset (ecs, 0, sizeof (*ecs)); |
3202 | ||
ec9499be | 3203 | overlay_cache_invalid = 1; |
ec9499be | 3204 | |
f15cb84a YQ |
3205 | /* Flush target cache before starting to handle each event. |
3206 | Target was running and cache could be stale. This is just a | |
3207 | heuristic. Running threads may modify target memory, but we | |
3208 | don't get any event. */ | |
3209 | target_dcache_invalidate (); | |
3210 | ||
9a4105ab | 3211 | if (deprecated_target_wait_hook) |
47608cb1 | 3212 | ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0); |
cd0fc7c3 | 3213 | else |
47608cb1 | 3214 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0); |
c906108c | 3215 | |
f00150c9 | 3216 | if (debug_infrun) |
223698f8 | 3217 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
f00150c9 | 3218 | |
cd0fc7c3 SS |
3219 | /* Now figure out what to do with the result of the result. */ |
3220 | handle_inferior_event (ecs); | |
c906108c | 3221 | |
cd0fc7c3 SS |
3222 | if (!ecs->wait_some_more) |
3223 | break; | |
3224 | } | |
4e1c45ea | 3225 | |
e6f5c25b PA |
3226 | /* No error, don't finish the state yet. */ |
3227 | discard_cleanups (thread_state_chain); | |
3228 | ||
cd0fc7c3 SS |
3229 | do_cleanups (old_cleanups); |
3230 | } | |
c906108c | 3231 | |
d3d4baed PA |
3232 | /* Cleanup that reinstalls the readline callback handler, if the |
3233 | target is running in the background. If while handling the target | |
3234 | event something triggered a secondary prompt, like e.g., a | |
3235 | pagination prompt, we'll have removed the callback handler (see | |
3236 | gdb_readline_wrapper_line). Need to do this as we go back to the | |
3237 | event loop, ready to process further input. Note this has no | |
3238 | effect if the handler hasn't actually been removed, because calling | |
3239 | rl_callback_handler_install resets the line buffer, thus losing | |
3240 | input. */ | |
3241 | ||
3242 | static void | |
3243 | reinstall_readline_callback_handler_cleanup (void *arg) | |
3244 | { | |
6c400b59 PA |
3245 | if (!interpreter_async) |
3246 | { | |
3247 | /* We're not going back to the top level event loop yet. Don't | |
3248 | install the readline callback, as it'd prep the terminal, | |
3249 | readline-style (raw, noecho) (e.g., --batch). We'll install | |
3250 | it the next time the prompt is displayed, when we're ready | |
3251 | for input. */ | |
3252 | return; | |
3253 | } | |
3254 | ||
d3d4baed PA |
3255 | if (async_command_editing_p && !sync_execution) |
3256 | gdb_rl_callback_handler_reinstall (); | |
3257 | } | |
3258 | ||
1777feb0 | 3259 | /* Asynchronous version of wait_for_inferior. It is called by the |
43ff13b4 | 3260 | event loop whenever a change of state is detected on the file |
1777feb0 MS |
3261 | descriptor corresponding to the target. It can be called more than |
3262 | once to complete a single execution command. In such cases we need | |
3263 | to keep the state in a global variable ECSS. If it is the last time | |
a474d7c2 PA |
3264 | that this function is called for a single execution command, then |
3265 | report to the user that the inferior has stopped, and do the | |
1777feb0 | 3266 | necessary cleanups. */ |
43ff13b4 JM |
3267 | |
3268 | void | |
fba45db2 | 3269 | fetch_inferior_event (void *client_data) |
43ff13b4 | 3270 | { |
0d1e5fa7 | 3271 | struct execution_control_state ecss; |
a474d7c2 | 3272 | struct execution_control_state *ecs = &ecss; |
4f8d22e3 | 3273 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
29f49a6a | 3274 | struct cleanup *ts_old_chain; |
4f8d22e3 | 3275 | int was_sync = sync_execution; |
0f641c01 | 3276 | int cmd_done = 0; |
963f9c80 | 3277 | ptid_t waiton_ptid = minus_one_ptid; |
43ff13b4 | 3278 | |
0d1e5fa7 PA |
3279 | memset (ecs, 0, sizeof (*ecs)); |
3280 | ||
d3d4baed PA |
3281 | /* End up with readline processing input, if necessary. */ |
3282 | make_cleanup (reinstall_readline_callback_handler_cleanup, NULL); | |
3283 | ||
c5187ac6 PA |
3284 | /* We're handling a live event, so make sure we're doing live |
3285 | debugging. If we're looking at traceframes while the target is | |
3286 | running, we're going to need to get back to that mode after | |
3287 | handling the event. */ | |
3288 | if (non_stop) | |
3289 | { | |
3290 | make_cleanup_restore_current_traceframe (); | |
e6e4e701 | 3291 | set_current_traceframe (-1); |
c5187ac6 PA |
3292 | } |
3293 | ||
4f8d22e3 PA |
3294 | if (non_stop) |
3295 | /* In non-stop mode, the user/frontend should not notice a thread | |
3296 | switch due to internal events. Make sure we reverse to the | |
3297 | user selected thread and frame after handling the event and | |
3298 | running any breakpoint commands. */ | |
3299 | make_cleanup_restore_current_thread (); | |
3300 | ||
ec9499be | 3301 | overlay_cache_invalid = 1; |
f15cb84a YQ |
3302 | /* Flush target cache before starting to handle each event. Target |
3303 | was running and cache could be stale. This is just a heuristic. | |
3304 | Running threads may modify target memory, but we don't get any | |
3305 | event. */ | |
3306 | target_dcache_invalidate (); | |
3dd5b83d | 3307 | |
32231432 PA |
3308 | make_cleanup_restore_integer (&execution_direction); |
3309 | execution_direction = target_execution_direction (); | |
3310 | ||
9a4105ab | 3311 | if (deprecated_target_wait_hook) |
a474d7c2 | 3312 | ecs->ptid = |
47608cb1 | 3313 | deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
43ff13b4 | 3314 | else |
47608cb1 | 3315 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
43ff13b4 | 3316 | |
f00150c9 | 3317 | if (debug_infrun) |
223698f8 | 3318 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
f00150c9 | 3319 | |
29f49a6a PA |
3320 | /* If an error happens while handling the event, propagate GDB's |
3321 | knowledge of the executing state to the frontend/user running | |
3322 | state. */ | |
3323 | if (!non_stop) | |
3324 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
3325 | else | |
3326 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid); | |
3327 | ||
353d1d73 JK |
3328 | /* Get executed before make_cleanup_restore_current_thread above to apply |
3329 | still for the thread which has thrown the exception. */ | |
3330 | make_bpstat_clear_actions_cleanup (); | |
3331 | ||
7c16b83e PA |
3332 | make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup, NULL); |
3333 | ||
43ff13b4 | 3334 | /* Now figure out what to do with the result of the result. */ |
a474d7c2 | 3335 | handle_inferior_event (ecs); |
43ff13b4 | 3336 | |
a474d7c2 | 3337 | if (!ecs->wait_some_more) |
43ff13b4 | 3338 | { |
c9657e70 | 3339 | struct inferior *inf = find_inferior_ptid (ecs->ptid); |
d6b48e9c | 3340 | |
0cbcdb96 | 3341 | delete_just_stopped_threads_infrun_breakpoints (); |
f107f563 | 3342 | |
d6b48e9c | 3343 | /* We may not find an inferior if this was a process exit. */ |
16c381f0 | 3344 | if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY) |
83c265ab PA |
3345 | normal_stop (); |
3346 | ||
af679fd0 | 3347 | if (target_has_execution |
0e5bf2a8 | 3348 | && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED |
af679fd0 PA |
3349 | && ecs->ws.kind != TARGET_WAITKIND_EXITED |
3350 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
3351 | && ecs->event_thread->step_multi | |
16c381f0 | 3352 | && ecs->event_thread->control.stop_step) |
c2d11a7d JM |
3353 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); |
3354 | else | |
0f641c01 PA |
3355 | { |
3356 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
3357 | cmd_done = 1; | |
3358 | } | |
43ff13b4 | 3359 | } |
4f8d22e3 | 3360 | |
29f49a6a PA |
3361 | /* No error, don't finish the thread states yet. */ |
3362 | discard_cleanups (ts_old_chain); | |
3363 | ||
4f8d22e3 PA |
3364 | /* Revert thread and frame. */ |
3365 | do_cleanups (old_chain); | |
3366 | ||
3367 | /* If the inferior was in sync execution mode, and now isn't, | |
0f641c01 PA |
3368 | restore the prompt (a synchronous execution command has finished, |
3369 | and we're ready for input). */ | |
b4a14fd0 | 3370 | if (interpreter_async && was_sync && !sync_execution) |
92bcb5f9 | 3371 | observer_notify_sync_execution_done (); |
0f641c01 PA |
3372 | |
3373 | if (cmd_done | |
3374 | && !was_sync | |
3375 | && exec_done_display_p | |
3376 | && (ptid_equal (inferior_ptid, null_ptid) | |
3377 | || !is_running (inferior_ptid))) | |
3378 | printf_unfiltered (_("completed.\n")); | |
43ff13b4 JM |
3379 | } |
3380 | ||
edb3359d DJ |
3381 | /* Record the frame and location we're currently stepping through. */ |
3382 | void | |
3383 | set_step_info (struct frame_info *frame, struct symtab_and_line sal) | |
3384 | { | |
3385 | struct thread_info *tp = inferior_thread (); | |
3386 | ||
16c381f0 JK |
3387 | tp->control.step_frame_id = get_frame_id (frame); |
3388 | tp->control.step_stack_frame_id = get_stack_frame_id (frame); | |
edb3359d DJ |
3389 | |
3390 | tp->current_symtab = sal.symtab; | |
3391 | tp->current_line = sal.line; | |
3392 | } | |
3393 | ||
0d1e5fa7 PA |
3394 | /* Clear context switchable stepping state. */ |
3395 | ||
3396 | void | |
4e1c45ea | 3397 | init_thread_stepping_state (struct thread_info *tss) |
0d1e5fa7 | 3398 | { |
7f5ef605 | 3399 | tss->stepped_breakpoint = 0; |
0d1e5fa7 | 3400 | tss->stepping_over_breakpoint = 0; |
963f9c80 | 3401 | tss->stepping_over_watchpoint = 0; |
0d1e5fa7 | 3402 | tss->step_after_step_resume_breakpoint = 0; |
cd0fc7c3 SS |
3403 | } |
3404 | ||
c32c64b7 DE |
3405 | /* Set the cached copy of the last ptid/waitstatus. */ |
3406 | ||
3407 | static void | |
3408 | set_last_target_status (ptid_t ptid, struct target_waitstatus status) | |
3409 | { | |
3410 | target_last_wait_ptid = ptid; | |
3411 | target_last_waitstatus = status; | |
3412 | } | |
3413 | ||
e02bc4cc | 3414 | /* Return the cached copy of the last pid/waitstatus returned by |
9a4105ab AC |
3415 | target_wait()/deprecated_target_wait_hook(). The data is actually |
3416 | cached by handle_inferior_event(), which gets called immediately | |
3417 | after target_wait()/deprecated_target_wait_hook(). */ | |
e02bc4cc DS |
3418 | |
3419 | void | |
488f131b | 3420 | get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) |
e02bc4cc | 3421 | { |
39f77062 | 3422 | *ptidp = target_last_wait_ptid; |
e02bc4cc DS |
3423 | *status = target_last_waitstatus; |
3424 | } | |
3425 | ||
ac264b3b MS |
3426 | void |
3427 | nullify_last_target_wait_ptid (void) | |
3428 | { | |
3429 | target_last_wait_ptid = minus_one_ptid; | |
3430 | } | |
3431 | ||
dcf4fbde | 3432 | /* Switch thread contexts. */ |
dd80620e MS |
3433 | |
3434 | static void | |
0d1e5fa7 | 3435 | context_switch (ptid_t ptid) |
dd80620e | 3436 | { |
4b51d87b | 3437 | if (debug_infrun && !ptid_equal (ptid, inferior_ptid)) |
fd48f117 DJ |
3438 | { |
3439 | fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", | |
3440 | target_pid_to_str (inferior_ptid)); | |
3441 | fprintf_unfiltered (gdb_stdlog, "to %s\n", | |
0d1e5fa7 | 3442 | target_pid_to_str (ptid)); |
fd48f117 DJ |
3443 | } |
3444 | ||
0d1e5fa7 | 3445 | switch_to_thread (ptid); |
dd80620e MS |
3446 | } |
3447 | ||
4fa8626c DJ |
3448 | static void |
3449 | adjust_pc_after_break (struct execution_control_state *ecs) | |
3450 | { | |
24a73cce UW |
3451 | struct regcache *regcache; |
3452 | struct gdbarch *gdbarch; | |
6c95b8df | 3453 | struct address_space *aspace; |
118e6252 | 3454 | CORE_ADDR breakpoint_pc, decr_pc; |
4fa8626c | 3455 | |
4fa8626c DJ |
3456 | /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If |
3457 | we aren't, just return. | |
9709f61c DJ |
3458 | |
3459 | We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not | |
b798847d UW |
3460 | affected by gdbarch_decr_pc_after_break. Other waitkinds which are |
3461 | implemented by software breakpoints should be handled through the normal | |
3462 | breakpoint layer. | |
8fb3e588 | 3463 | |
4fa8626c DJ |
3464 | NOTE drow/2004-01-31: On some targets, breakpoints may generate |
3465 | different signals (SIGILL or SIGEMT for instance), but it is less | |
3466 | clear where the PC is pointing afterwards. It may not match | |
b798847d UW |
3467 | gdbarch_decr_pc_after_break. I don't know any specific target that |
3468 | generates these signals at breakpoints (the code has been in GDB since at | |
3469 | least 1992) so I can not guess how to handle them here. | |
8fb3e588 | 3470 | |
e6cf7916 UW |
3471 | In earlier versions of GDB, a target with |
3472 | gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a | |
b798847d UW |
3473 | watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any |
3474 | target with both of these set in GDB history, and it seems unlikely to be | |
3475 | correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ | |
4fa8626c DJ |
3476 | |
3477 | if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) | |
3478 | return; | |
3479 | ||
a493e3e2 | 3480 | if (ecs->ws.value.sig != GDB_SIGNAL_TRAP) |
4fa8626c DJ |
3481 | return; |
3482 | ||
4058b839 PA |
3483 | /* In reverse execution, when a breakpoint is hit, the instruction |
3484 | under it has already been de-executed. The reported PC always | |
3485 | points at the breakpoint address, so adjusting it further would | |
3486 | be wrong. E.g., consider this case on a decr_pc_after_break == 1 | |
3487 | architecture: | |
3488 | ||
3489 | B1 0x08000000 : INSN1 | |
3490 | B2 0x08000001 : INSN2 | |
3491 | 0x08000002 : INSN3 | |
3492 | PC -> 0x08000003 : INSN4 | |
3493 | ||
3494 | Say you're stopped at 0x08000003 as above. Reverse continuing | |
3495 | from that point should hit B2 as below. Reading the PC when the | |
3496 | SIGTRAP is reported should read 0x08000001 and INSN2 should have | |
3497 | been de-executed already. | |
3498 | ||
3499 | B1 0x08000000 : INSN1 | |
3500 | B2 PC -> 0x08000001 : INSN2 | |
3501 | 0x08000002 : INSN3 | |
3502 | 0x08000003 : INSN4 | |
3503 | ||
3504 | We can't apply the same logic as for forward execution, because | |
3505 | we would wrongly adjust the PC to 0x08000000, since there's a | |
3506 | breakpoint at PC - 1. We'd then report a hit on B1, although | |
3507 | INSN1 hadn't been de-executed yet. Doing nothing is the correct | |
3508 | behaviour. */ | |
3509 | if (execution_direction == EXEC_REVERSE) | |
3510 | return; | |
3511 | ||
1cf4d951 PA |
3512 | /* If the target can tell whether the thread hit a SW breakpoint, |
3513 | trust it. Targets that can tell also adjust the PC | |
3514 | themselves. */ | |
3515 | if (target_supports_stopped_by_sw_breakpoint ()) | |
3516 | return; | |
3517 | ||
3518 | /* Note that relying on whether a breakpoint is planted in memory to | |
3519 | determine this can fail. E.g,. the breakpoint could have been | |
3520 | removed since. Or the thread could have been told to step an | |
3521 | instruction the size of a breakpoint instruction, and only | |
3522 | _after_ was a breakpoint inserted at its address. */ | |
3523 | ||
24a73cce UW |
3524 | /* If this target does not decrement the PC after breakpoints, then |
3525 | we have nothing to do. */ | |
3526 | regcache = get_thread_regcache (ecs->ptid); | |
3527 | gdbarch = get_regcache_arch (regcache); | |
118e6252 | 3528 | |
527a273a | 3529 | decr_pc = gdbarch_decr_pc_after_break (gdbarch); |
118e6252 | 3530 | if (decr_pc == 0) |
24a73cce UW |
3531 | return; |
3532 | ||
6c95b8df PA |
3533 | aspace = get_regcache_aspace (regcache); |
3534 | ||
8aad930b AC |
3535 | /* Find the location where (if we've hit a breakpoint) the |
3536 | breakpoint would be. */ | |
118e6252 | 3537 | breakpoint_pc = regcache_read_pc (regcache) - decr_pc; |
8aad930b | 3538 | |
1cf4d951 PA |
3539 | /* If the target can't tell whether a software breakpoint triggered, |
3540 | fallback to figuring it out based on breakpoints we think were | |
3541 | inserted in the target, and on whether the thread was stepped or | |
3542 | continued. */ | |
3543 | ||
1c5cfe86 PA |
3544 | /* Check whether there actually is a software breakpoint inserted at |
3545 | that location. | |
3546 | ||
3547 | If in non-stop mode, a race condition is possible where we've | |
3548 | removed a breakpoint, but stop events for that breakpoint were | |
3549 | already queued and arrive later. To suppress those spurious | |
3550 | SIGTRAPs, we keep a list of such breakpoint locations for a bit, | |
1cf4d951 PA |
3551 | and retire them after a number of stop events are reported. Note |
3552 | this is an heuristic and can thus get confused. The real fix is | |
3553 | to get the "stopped by SW BP and needs adjustment" info out of | |
3554 | the target/kernel (and thus never reach here; see above). */ | |
6c95b8df PA |
3555 | if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc) |
3556 | || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc))) | |
8aad930b | 3557 | { |
77f9e713 | 3558 | struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL); |
abbb1732 | 3559 | |
8213266a | 3560 | if (record_full_is_used ()) |
77f9e713 | 3561 | record_full_gdb_operation_disable_set (); |
96429cc8 | 3562 | |
1c0fdd0e UW |
3563 | /* When using hardware single-step, a SIGTRAP is reported for both |
3564 | a completed single-step and a software breakpoint. Need to | |
3565 | differentiate between the two, as the latter needs adjusting | |
3566 | but the former does not. | |
3567 | ||
3568 | The SIGTRAP can be due to a completed hardware single-step only if | |
3569 | - we didn't insert software single-step breakpoints | |
1c0fdd0e UW |
3570 | - this thread is currently being stepped |
3571 | ||
3572 | If any of these events did not occur, we must have stopped due | |
3573 | to hitting a software breakpoint, and have to back up to the | |
3574 | breakpoint address. | |
3575 | ||
3576 | As a special case, we could have hardware single-stepped a | |
3577 | software breakpoint. In this case (prev_pc == breakpoint_pc), | |
3578 | we also need to back up to the breakpoint address. */ | |
3579 | ||
34b7e8a6 | 3580 | if (thread_has_single_step_breakpoints_set (ecs->event_thread) |
4e1c45ea | 3581 | || !currently_stepping (ecs->event_thread) |
7f5ef605 PA |
3582 | || (ecs->event_thread->stepped_breakpoint |
3583 | && ecs->event_thread->prev_pc == breakpoint_pc)) | |
515630c5 | 3584 | regcache_write_pc (regcache, breakpoint_pc); |
96429cc8 | 3585 | |
77f9e713 | 3586 | do_cleanups (old_cleanups); |
8aad930b | 3587 | } |
4fa8626c DJ |
3588 | } |
3589 | ||
edb3359d DJ |
3590 | static int |
3591 | stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id) | |
3592 | { | |
3593 | for (frame = get_prev_frame (frame); | |
3594 | frame != NULL; | |
3595 | frame = get_prev_frame (frame)) | |
3596 | { | |
3597 | if (frame_id_eq (get_frame_id (frame), step_frame_id)) | |
3598 | return 1; | |
3599 | if (get_frame_type (frame) != INLINE_FRAME) | |
3600 | break; | |
3601 | } | |
3602 | ||
3603 | return 0; | |
3604 | } | |
3605 | ||
a96d9b2e SDJ |
3606 | /* Auxiliary function that handles syscall entry/return events. |
3607 | It returns 1 if the inferior should keep going (and GDB | |
3608 | should ignore the event), or 0 if the event deserves to be | |
3609 | processed. */ | |
ca2163eb | 3610 | |
a96d9b2e | 3611 | static int |
ca2163eb | 3612 | handle_syscall_event (struct execution_control_state *ecs) |
a96d9b2e | 3613 | { |
ca2163eb | 3614 | struct regcache *regcache; |
ca2163eb PA |
3615 | int syscall_number; |
3616 | ||
3617 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
3618 | context_switch (ecs->ptid); | |
3619 | ||
3620 | regcache = get_thread_regcache (ecs->ptid); | |
f90263c1 | 3621 | syscall_number = ecs->ws.value.syscall_number; |
ca2163eb PA |
3622 | stop_pc = regcache_read_pc (regcache); |
3623 | ||
a96d9b2e SDJ |
3624 | if (catch_syscall_enabled () > 0 |
3625 | && catching_syscall_number (syscall_number) > 0) | |
3626 | { | |
3627 | if (debug_infrun) | |
3628 | fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n", | |
3629 | syscall_number); | |
a96d9b2e | 3630 | |
16c381f0 | 3631 | ecs->event_thread->control.stop_bpstat |
6c95b8df | 3632 | = bpstat_stop_status (get_regcache_aspace (regcache), |
09ac7c10 | 3633 | stop_pc, ecs->ptid, &ecs->ws); |
ab04a2af | 3634 | |
ce12b012 | 3635 | if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat)) |
ca2163eb PA |
3636 | { |
3637 | /* Catchpoint hit. */ | |
ca2163eb PA |
3638 | return 0; |
3639 | } | |
a96d9b2e | 3640 | } |
ca2163eb PA |
3641 | |
3642 | /* If no catchpoint triggered for this, then keep going. */ | |
ca2163eb PA |
3643 | keep_going (ecs); |
3644 | return 1; | |
a96d9b2e SDJ |
3645 | } |
3646 | ||
7e324e48 GB |
3647 | /* Lazily fill in the execution_control_state's stop_func_* fields. */ |
3648 | ||
3649 | static void | |
3650 | fill_in_stop_func (struct gdbarch *gdbarch, | |
3651 | struct execution_control_state *ecs) | |
3652 | { | |
3653 | if (!ecs->stop_func_filled_in) | |
3654 | { | |
3655 | /* Don't care about return value; stop_func_start and stop_func_name | |
3656 | will both be 0 if it doesn't work. */ | |
3657 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
3658 | &ecs->stop_func_start, &ecs->stop_func_end); | |
3659 | ecs->stop_func_start | |
3660 | += gdbarch_deprecated_function_start_offset (gdbarch); | |
3661 | ||
591a12a1 UW |
3662 | if (gdbarch_skip_entrypoint_p (gdbarch)) |
3663 | ecs->stop_func_start = gdbarch_skip_entrypoint (gdbarch, | |
3664 | ecs->stop_func_start); | |
3665 | ||
7e324e48 GB |
3666 | ecs->stop_func_filled_in = 1; |
3667 | } | |
3668 | } | |
3669 | ||
4f5d7f63 PA |
3670 | |
3671 | /* Return the STOP_SOON field of the inferior pointed at by PTID. */ | |
3672 | ||
3673 | static enum stop_kind | |
3674 | get_inferior_stop_soon (ptid_t ptid) | |
3675 | { | |
c9657e70 | 3676 | struct inferior *inf = find_inferior_ptid (ptid); |
4f5d7f63 PA |
3677 | |
3678 | gdb_assert (inf != NULL); | |
3679 | return inf->control.stop_soon; | |
3680 | } | |
3681 | ||
05ba8510 PA |
3682 | /* Given an execution control state that has been freshly filled in by |
3683 | an event from the inferior, figure out what it means and take | |
3684 | appropriate action. | |
3685 | ||
3686 | The alternatives are: | |
3687 | ||
22bcd14b | 3688 | 1) stop_waiting and return; to really stop and return to the |
05ba8510 PA |
3689 | debugger. |
3690 | ||
3691 | 2) keep_going and return; to wait for the next event (set | |
3692 | ecs->event_thread->stepping_over_breakpoint to 1 to single step | |
3693 | once). */ | |
c906108c | 3694 | |
ec9499be | 3695 | static void |
96baa820 | 3696 | handle_inferior_event (struct execution_control_state *ecs) |
cd0fc7c3 | 3697 | { |
d6b48e9c PA |
3698 | enum stop_kind stop_soon; |
3699 | ||
28736962 PA |
3700 | if (ecs->ws.kind == TARGET_WAITKIND_IGNORE) |
3701 | { | |
3702 | /* We had an event in the inferior, but we are not interested in | |
3703 | handling it at this level. The lower layers have already | |
3704 | done what needs to be done, if anything. | |
3705 | ||
3706 | One of the possible circumstances for this is when the | |
3707 | inferior produces output for the console. The inferior has | |
3708 | not stopped, and we are ignoring the event. Another possible | |
3709 | circumstance is any event which the lower level knows will be | |
3710 | reported multiple times without an intervening resume. */ | |
3711 | if (debug_infrun) | |
3712 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); | |
3713 | prepare_to_wait (ecs); | |
3714 | return; | |
3715 | } | |
3716 | ||
0e5bf2a8 PA |
3717 | if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED |
3718 | && target_can_async_p () && !sync_execution) | |
3719 | { | |
3720 | /* There were no unwaited-for children left in the target, but, | |
3721 | we're not synchronously waiting for events either. Just | |
3722 | ignore. Otherwise, if we were running a synchronous | |
3723 | execution command, we need to cancel it and give the user | |
3724 | back the terminal. */ | |
3725 | if (debug_infrun) | |
3726 | fprintf_unfiltered (gdb_stdlog, | |
3727 | "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n"); | |
3728 | prepare_to_wait (ecs); | |
3729 | return; | |
3730 | } | |
3731 | ||
1777feb0 | 3732 | /* Cache the last pid/waitstatus. */ |
c32c64b7 | 3733 | set_last_target_status (ecs->ptid, ecs->ws); |
e02bc4cc | 3734 | |
ca005067 | 3735 | /* Always clear state belonging to the previous time we stopped. */ |
aa7d318d | 3736 | stop_stack_dummy = STOP_NONE; |
ca005067 | 3737 | |
0e5bf2a8 PA |
3738 | if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED) |
3739 | { | |
3740 | /* No unwaited-for children left. IOW, all resumed children | |
3741 | have exited. */ | |
3742 | if (debug_infrun) | |
3743 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n"); | |
3744 | ||
3745 | stop_print_frame = 0; | |
22bcd14b | 3746 | stop_waiting (ecs); |
0e5bf2a8 PA |
3747 | return; |
3748 | } | |
3749 | ||
8c90c137 | 3750 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
64776a0b | 3751 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) |
359f5fe6 PA |
3752 | { |
3753 | ecs->event_thread = find_thread_ptid (ecs->ptid); | |
3754 | /* If it's a new thread, add it to the thread database. */ | |
3755 | if (ecs->event_thread == NULL) | |
3756 | ecs->event_thread = add_thread (ecs->ptid); | |
c1e36e3e PA |
3757 | |
3758 | /* Disable range stepping. If the next step request could use a | |
3759 | range, this will be end up re-enabled then. */ | |
3760 | ecs->event_thread->control.may_range_step = 0; | |
359f5fe6 | 3761 | } |
88ed393a JK |
3762 | |
3763 | /* Dependent on valid ECS->EVENT_THREAD. */ | |
3764 | adjust_pc_after_break (ecs); | |
3765 | ||
3766 | /* Dependent on the current PC value modified by adjust_pc_after_break. */ | |
3767 | reinit_frame_cache (); | |
3768 | ||
28736962 PA |
3769 | breakpoint_retire_moribund (); |
3770 | ||
2b009048 DJ |
3771 | /* First, distinguish signals caused by the debugger from signals |
3772 | that have to do with the program's own actions. Note that | |
3773 | breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending | |
3774 | on the operating system version. Here we detect when a SIGILL or | |
3775 | SIGEMT is really a breakpoint and change it to SIGTRAP. We do | |
3776 | something similar for SIGSEGV, since a SIGSEGV will be generated | |
3777 | when we're trying to execute a breakpoint instruction on a | |
3778 | non-executable stack. This happens for call dummy breakpoints | |
3779 | for architectures like SPARC that place call dummies on the | |
3780 | stack. */ | |
2b009048 | 3781 | if (ecs->ws.kind == TARGET_WAITKIND_STOPPED |
a493e3e2 PA |
3782 | && (ecs->ws.value.sig == GDB_SIGNAL_ILL |
3783 | || ecs->ws.value.sig == GDB_SIGNAL_SEGV | |
3784 | || ecs->ws.value.sig == GDB_SIGNAL_EMT)) | |
2b009048 | 3785 | { |
de0a0249 UW |
3786 | struct regcache *regcache = get_thread_regcache (ecs->ptid); |
3787 | ||
3788 | if (breakpoint_inserted_here_p (get_regcache_aspace (regcache), | |
3789 | regcache_read_pc (regcache))) | |
3790 | { | |
3791 | if (debug_infrun) | |
3792 | fprintf_unfiltered (gdb_stdlog, | |
3793 | "infrun: Treating signal as SIGTRAP\n"); | |
a493e3e2 | 3794 | ecs->ws.value.sig = GDB_SIGNAL_TRAP; |
de0a0249 | 3795 | } |
2b009048 DJ |
3796 | } |
3797 | ||
28736962 PA |
3798 | /* Mark the non-executing threads accordingly. In all-stop, all |
3799 | threads of all processes are stopped when we get any event | |
3800 | reported. In non-stop mode, only the event thread stops. If | |
3801 | we're handling a process exit in non-stop mode, there's nothing | |
3802 | to do, as threads of the dead process are gone, and threads of | |
3803 | any other process were left running. */ | |
3804 | if (!non_stop) | |
3805 | set_executing (minus_one_ptid, 0); | |
3806 | else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
3807 | && ecs->ws.kind != TARGET_WAITKIND_EXITED) | |
7aee8dc2 | 3808 | set_executing (ecs->ptid, 0); |
8c90c137 | 3809 | |
488f131b JB |
3810 | switch (ecs->ws.kind) |
3811 | { | |
3812 | case TARGET_WAITKIND_LOADED: | |
527159b7 | 3813 | if (debug_infrun) |
8a9de0e4 | 3814 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); |
5c09a2c5 PA |
3815 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
3816 | context_switch (ecs->ptid); | |
b0f4b84b DJ |
3817 | /* Ignore gracefully during startup of the inferior, as it might |
3818 | be the shell which has just loaded some objects, otherwise | |
3819 | add the symbols for the newly loaded objects. Also ignore at | |
3820 | the beginning of an attach or remote session; we will query | |
3821 | the full list of libraries once the connection is | |
3822 | established. */ | |
4f5d7f63 PA |
3823 | |
3824 | stop_soon = get_inferior_stop_soon (ecs->ptid); | |
c0236d92 | 3825 | if (stop_soon == NO_STOP_QUIETLY) |
488f131b | 3826 | { |
edcc5120 TT |
3827 | struct regcache *regcache; |
3828 | ||
edcc5120 TT |
3829 | regcache = get_thread_regcache (ecs->ptid); |
3830 | ||
3831 | handle_solib_event (); | |
3832 | ||
3833 | ecs->event_thread->control.stop_bpstat | |
3834 | = bpstat_stop_status (get_regcache_aspace (regcache), | |
3835 | stop_pc, ecs->ptid, &ecs->ws); | |
ab04a2af | 3836 | |
ce12b012 | 3837 | if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat)) |
edcc5120 TT |
3838 | { |
3839 | /* A catchpoint triggered. */ | |
94c57d6a PA |
3840 | process_event_stop_test (ecs); |
3841 | return; | |
edcc5120 | 3842 | } |
488f131b | 3843 | |
b0f4b84b DJ |
3844 | /* If requested, stop when the dynamic linker notifies |
3845 | gdb of events. This allows the user to get control | |
3846 | and place breakpoints in initializer routines for | |
3847 | dynamically loaded objects (among other things). */ | |
a493e3e2 | 3848 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; |
b0f4b84b DJ |
3849 | if (stop_on_solib_events) |
3850 | { | |
55409f9d DJ |
3851 | /* Make sure we print "Stopped due to solib-event" in |
3852 | normal_stop. */ | |
3853 | stop_print_frame = 1; | |
3854 | ||
22bcd14b | 3855 | stop_waiting (ecs); |
b0f4b84b DJ |
3856 | return; |
3857 | } | |
488f131b | 3858 | } |
b0f4b84b DJ |
3859 | |
3860 | /* If we are skipping through a shell, or through shared library | |
3861 | loading that we aren't interested in, resume the program. If | |
5c09a2c5 | 3862 | we're running the program normally, also resume. */ |
b0f4b84b DJ |
3863 | if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) |
3864 | { | |
74960c60 VP |
3865 | /* Loading of shared libraries might have changed breakpoint |
3866 | addresses. Make sure new breakpoints are inserted. */ | |
a25a5a45 | 3867 | if (stop_soon == NO_STOP_QUIETLY) |
74960c60 | 3868 | insert_breakpoints (); |
64ce06e4 | 3869 | resume (GDB_SIGNAL_0); |
b0f4b84b DJ |
3870 | prepare_to_wait (ecs); |
3871 | return; | |
3872 | } | |
3873 | ||
5c09a2c5 PA |
3874 | /* But stop if we're attaching or setting up a remote |
3875 | connection. */ | |
3876 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP | |
3877 | || stop_soon == STOP_QUIETLY_REMOTE) | |
3878 | { | |
3879 | if (debug_infrun) | |
3880 | fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); | |
22bcd14b | 3881 | stop_waiting (ecs); |
5c09a2c5 PA |
3882 | return; |
3883 | } | |
3884 | ||
3885 | internal_error (__FILE__, __LINE__, | |
3886 | _("unhandled stop_soon: %d"), (int) stop_soon); | |
c5aa993b | 3887 | |
488f131b | 3888 | case TARGET_WAITKIND_SPURIOUS: |
527159b7 | 3889 | if (debug_infrun) |
8a9de0e4 | 3890 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); |
64776a0b | 3891 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
8b3ee56d | 3892 | context_switch (ecs->ptid); |
64ce06e4 | 3893 | resume (GDB_SIGNAL_0); |
488f131b JB |
3894 | prepare_to_wait (ecs); |
3895 | return; | |
c5aa993b | 3896 | |
488f131b | 3897 | case TARGET_WAITKIND_EXITED: |
940c3c06 | 3898 | case TARGET_WAITKIND_SIGNALLED: |
527159b7 | 3899 | if (debug_infrun) |
940c3c06 PA |
3900 | { |
3901 | if (ecs->ws.kind == TARGET_WAITKIND_EXITED) | |
3902 | fprintf_unfiltered (gdb_stdlog, | |
3903 | "infrun: TARGET_WAITKIND_EXITED\n"); | |
3904 | else | |
3905 | fprintf_unfiltered (gdb_stdlog, | |
3906 | "infrun: TARGET_WAITKIND_SIGNALLED\n"); | |
3907 | } | |
3908 | ||
fb66883a | 3909 | inferior_ptid = ecs->ptid; |
c9657e70 | 3910 | set_current_inferior (find_inferior_ptid (ecs->ptid)); |
6c95b8df PA |
3911 | set_current_program_space (current_inferior ()->pspace); |
3912 | handle_vfork_child_exec_or_exit (0); | |
1777feb0 | 3913 | target_terminal_ours (); /* Must do this before mourn anyway. */ |
488f131b | 3914 | |
0c557179 SDJ |
3915 | /* Clearing any previous state of convenience variables. */ |
3916 | clear_exit_convenience_vars (); | |
3917 | ||
940c3c06 PA |
3918 | if (ecs->ws.kind == TARGET_WAITKIND_EXITED) |
3919 | { | |
3920 | /* Record the exit code in the convenience variable $_exitcode, so | |
3921 | that the user can inspect this again later. */ | |
3922 | set_internalvar_integer (lookup_internalvar ("_exitcode"), | |
3923 | (LONGEST) ecs->ws.value.integer); | |
3924 | ||
3925 | /* Also record this in the inferior itself. */ | |
3926 | current_inferior ()->has_exit_code = 1; | |
3927 | current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer; | |
8cf64490 | 3928 | |
98eb56a4 PA |
3929 | /* Support the --return-child-result option. */ |
3930 | return_child_result_value = ecs->ws.value.integer; | |
3931 | ||
fd664c91 | 3932 | observer_notify_exited (ecs->ws.value.integer); |
940c3c06 PA |
3933 | } |
3934 | else | |
0c557179 SDJ |
3935 | { |
3936 | struct regcache *regcache = get_thread_regcache (ecs->ptid); | |
3937 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
3938 | ||
3939 | if (gdbarch_gdb_signal_to_target_p (gdbarch)) | |
3940 | { | |
3941 | /* Set the value of the internal variable $_exitsignal, | |
3942 | which holds the signal uncaught by the inferior. */ | |
3943 | set_internalvar_integer (lookup_internalvar ("_exitsignal"), | |
3944 | gdbarch_gdb_signal_to_target (gdbarch, | |
3945 | ecs->ws.value.sig)); | |
3946 | } | |
3947 | else | |
3948 | { | |
3949 | /* We don't have access to the target's method used for | |
3950 | converting between signal numbers (GDB's internal | |
3951 | representation <-> target's representation). | |
3952 | Therefore, we cannot do a good job at displaying this | |
3953 | information to the user. It's better to just warn | |
3954 | her about it (if infrun debugging is enabled), and | |
3955 | give up. */ | |
3956 | if (debug_infrun) | |
3957 | fprintf_filtered (gdb_stdlog, _("\ | |
3958 | Cannot fill $_exitsignal with the correct signal number.\n")); | |
3959 | } | |
3960 | ||
fd664c91 | 3961 | observer_notify_signal_exited (ecs->ws.value.sig); |
0c557179 | 3962 | } |
8cf64490 | 3963 | |
488f131b JB |
3964 | gdb_flush (gdb_stdout); |
3965 | target_mourn_inferior (); | |
488f131b | 3966 | stop_print_frame = 0; |
22bcd14b | 3967 | stop_waiting (ecs); |
488f131b | 3968 | return; |
c5aa993b | 3969 | |
488f131b | 3970 | /* The following are the only cases in which we keep going; |
1777feb0 | 3971 | the above cases end in a continue or goto. */ |
488f131b | 3972 | case TARGET_WAITKIND_FORKED: |
deb3b17b | 3973 | case TARGET_WAITKIND_VFORKED: |
527159b7 | 3974 | if (debug_infrun) |
fed708ed PA |
3975 | { |
3976 | if (ecs->ws.kind == TARGET_WAITKIND_FORKED) | |
3977 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); | |
3978 | else | |
3979 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n"); | |
3980 | } | |
c906108c | 3981 | |
e2d96639 YQ |
3982 | /* Check whether the inferior is displaced stepping. */ |
3983 | { | |
3984 | struct regcache *regcache = get_thread_regcache (ecs->ptid); | |
3985 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
3986 | struct displaced_step_inferior_state *displaced | |
3987 | = get_displaced_stepping_state (ptid_get_pid (ecs->ptid)); | |
3988 | ||
3989 | /* If checking displaced stepping is supported, and thread | |
3990 | ecs->ptid is displaced stepping. */ | |
3991 | if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid)) | |
3992 | { | |
3993 | struct inferior *parent_inf | |
c9657e70 | 3994 | = find_inferior_ptid (ecs->ptid); |
e2d96639 YQ |
3995 | struct regcache *child_regcache; |
3996 | CORE_ADDR parent_pc; | |
3997 | ||
3998 | /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED, | |
3999 | indicating that the displaced stepping of syscall instruction | |
4000 | has been done. Perform cleanup for parent process here. Note | |
4001 | that this operation also cleans up the child process for vfork, | |
4002 | because their pages are shared. */ | |
a493e3e2 | 4003 | displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP); |
e2d96639 YQ |
4004 | |
4005 | if (ecs->ws.kind == TARGET_WAITKIND_FORKED) | |
4006 | { | |
4007 | /* Restore scratch pad for child process. */ | |
4008 | displaced_step_restore (displaced, ecs->ws.value.related_pid); | |
4009 | } | |
4010 | ||
4011 | /* Since the vfork/fork syscall instruction was executed in the scratchpad, | |
4012 | the child's PC is also within the scratchpad. Set the child's PC | |
4013 | to the parent's PC value, which has already been fixed up. | |
4014 | FIXME: we use the parent's aspace here, although we're touching | |
4015 | the child, because the child hasn't been added to the inferior | |
4016 | list yet at this point. */ | |
4017 | ||
4018 | child_regcache | |
4019 | = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid, | |
4020 | gdbarch, | |
4021 | parent_inf->aspace); | |
4022 | /* Read PC value of parent process. */ | |
4023 | parent_pc = regcache_read_pc (regcache); | |
4024 | ||
4025 | if (debug_displaced) | |
4026 | fprintf_unfiltered (gdb_stdlog, | |
4027 | "displaced: write child pc from %s to %s\n", | |
4028 | paddress (gdbarch, | |
4029 | regcache_read_pc (child_regcache)), | |
4030 | paddress (gdbarch, parent_pc)); | |
4031 | ||
4032 | regcache_write_pc (child_regcache, parent_pc); | |
4033 | } | |
4034 | } | |
4035 | ||
5a2901d9 | 4036 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
c3a01a22 | 4037 | context_switch (ecs->ptid); |
5a2901d9 | 4038 | |
b242c3c2 PA |
4039 | /* Immediately detach breakpoints from the child before there's |
4040 | any chance of letting the user delete breakpoints from the | |
4041 | breakpoint lists. If we don't do this early, it's easy to | |
4042 | leave left over traps in the child, vis: "break foo; catch | |
4043 | fork; c; <fork>; del; c; <child calls foo>". We only follow | |
4044 | the fork on the last `continue', and by that time the | |
4045 | breakpoint at "foo" is long gone from the breakpoint table. | |
4046 | If we vforked, then we don't need to unpatch here, since both | |
4047 | parent and child are sharing the same memory pages; we'll | |
4048 | need to unpatch at follow/detach time instead to be certain | |
4049 | that new breakpoints added between catchpoint hit time and | |
4050 | vfork follow are detached. */ | |
4051 | if (ecs->ws.kind != TARGET_WAITKIND_VFORKED) | |
4052 | { | |
b242c3c2 PA |
4053 | /* This won't actually modify the breakpoint list, but will |
4054 | physically remove the breakpoints from the child. */ | |
d80ee84f | 4055 | detach_breakpoints (ecs->ws.value.related_pid); |
b242c3c2 PA |
4056 | } |
4057 | ||
34b7e8a6 | 4058 | delete_just_stopped_threads_single_step_breakpoints (); |
d03285ec | 4059 | |
e58b0e63 PA |
4060 | /* In case the event is caught by a catchpoint, remember that |
4061 | the event is to be followed at the next resume of the thread, | |
4062 | and not immediately. */ | |
4063 | ecs->event_thread->pending_follow = ecs->ws; | |
4064 | ||
fb14de7b | 4065 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
675bf4cb | 4066 | |
16c381f0 | 4067 | ecs->event_thread->control.stop_bpstat |
6c95b8df | 4068 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
09ac7c10 | 4069 | stop_pc, ecs->ptid, &ecs->ws); |
675bf4cb | 4070 | |
ce12b012 PA |
4071 | /* If no catchpoint triggered for this, then keep going. Note |
4072 | that we're interested in knowing the bpstat actually causes a | |
4073 | stop, not just if it may explain the signal. Software | |
4074 | watchpoints, for example, always appear in the bpstat. */ | |
4075 | if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat)) | |
04e68871 | 4076 | { |
6c95b8df PA |
4077 | ptid_t parent; |
4078 | ptid_t child; | |
e58b0e63 | 4079 | int should_resume; |
3e43a32a MS |
4080 | int follow_child |
4081 | = (follow_fork_mode_string == follow_fork_mode_child); | |
e58b0e63 | 4082 | |
a493e3e2 | 4083 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; |
e58b0e63 PA |
4084 | |
4085 | should_resume = follow_fork (); | |
4086 | ||
6c95b8df PA |
4087 | parent = ecs->ptid; |
4088 | child = ecs->ws.value.related_pid; | |
4089 | ||
4090 | /* In non-stop mode, also resume the other branch. */ | |
4091 | if (non_stop && !detach_fork) | |
4092 | { | |
4093 | if (follow_child) | |
4094 | switch_to_thread (parent); | |
4095 | else | |
4096 | switch_to_thread (child); | |
4097 | ||
4098 | ecs->event_thread = inferior_thread (); | |
4099 | ecs->ptid = inferior_ptid; | |
4100 | keep_going (ecs); | |
4101 | } | |
4102 | ||
4103 | if (follow_child) | |
4104 | switch_to_thread (child); | |
4105 | else | |
4106 | switch_to_thread (parent); | |
4107 | ||
e58b0e63 PA |
4108 | ecs->event_thread = inferior_thread (); |
4109 | ecs->ptid = inferior_ptid; | |
4110 | ||
4111 | if (should_resume) | |
4112 | keep_going (ecs); | |
4113 | else | |
22bcd14b | 4114 | stop_waiting (ecs); |
04e68871 DJ |
4115 | return; |
4116 | } | |
94c57d6a PA |
4117 | process_event_stop_test (ecs); |
4118 | return; | |
488f131b | 4119 | |
6c95b8df PA |
4120 | case TARGET_WAITKIND_VFORK_DONE: |
4121 | /* Done with the shared memory region. Re-insert breakpoints in | |
4122 | the parent, and keep going. */ | |
4123 | ||
4124 | if (debug_infrun) | |
3e43a32a MS |
4125 | fprintf_unfiltered (gdb_stdlog, |
4126 | "infrun: TARGET_WAITKIND_VFORK_DONE\n"); | |
6c95b8df PA |
4127 | |
4128 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
4129 | context_switch (ecs->ptid); | |
4130 | ||
4131 | current_inferior ()->waiting_for_vfork_done = 0; | |
56710373 | 4132 | current_inferior ()->pspace->breakpoints_not_allowed = 0; |
6c95b8df PA |
4133 | /* This also takes care of reinserting breakpoints in the |
4134 | previously locked inferior. */ | |
4135 | keep_going (ecs); | |
4136 | return; | |
4137 | ||
488f131b | 4138 | case TARGET_WAITKIND_EXECD: |
527159b7 | 4139 | if (debug_infrun) |
fc5261f2 | 4140 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); |
488f131b | 4141 | |
5a2901d9 | 4142 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
c3a01a22 | 4143 | context_switch (ecs->ptid); |
5a2901d9 | 4144 | |
fb14de7b | 4145 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
795e548f | 4146 | |
6c95b8df PA |
4147 | /* Do whatever is necessary to the parent branch of the vfork. */ |
4148 | handle_vfork_child_exec_or_exit (1); | |
4149 | ||
795e548f PA |
4150 | /* This causes the eventpoints and symbol table to be reset. |
4151 | Must do this now, before trying to determine whether to | |
4152 | stop. */ | |
71b43ef8 | 4153 | follow_exec (inferior_ptid, ecs->ws.value.execd_pathname); |
795e548f | 4154 | |
16c381f0 | 4155 | ecs->event_thread->control.stop_bpstat |
6c95b8df | 4156 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
09ac7c10 | 4157 | stop_pc, ecs->ptid, &ecs->ws); |
795e548f | 4158 | |
71b43ef8 PA |
4159 | /* Note that this may be referenced from inside |
4160 | bpstat_stop_status above, through inferior_has_execd. */ | |
4161 | xfree (ecs->ws.value.execd_pathname); | |
4162 | ecs->ws.value.execd_pathname = NULL; | |
4163 | ||
04e68871 | 4164 | /* If no catchpoint triggered for this, then keep going. */ |
ce12b012 | 4165 | if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat)) |
04e68871 | 4166 | { |
a493e3e2 | 4167 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; |
04e68871 DJ |
4168 | keep_going (ecs); |
4169 | return; | |
4170 | } | |
94c57d6a PA |
4171 | process_event_stop_test (ecs); |
4172 | return; | |
488f131b | 4173 | |
b4dc5ffa MK |
4174 | /* Be careful not to try to gather much state about a thread |
4175 | that's in a syscall. It's frequently a losing proposition. */ | |
488f131b | 4176 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
527159b7 | 4177 | if (debug_infrun) |
3e43a32a MS |
4178 | fprintf_unfiltered (gdb_stdlog, |
4179 | "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); | |
1777feb0 | 4180 | /* Getting the current syscall number. */ |
94c57d6a PA |
4181 | if (handle_syscall_event (ecs) == 0) |
4182 | process_event_stop_test (ecs); | |
4183 | return; | |
c906108c | 4184 | |
488f131b JB |
4185 | /* Before examining the threads further, step this thread to |
4186 | get it entirely out of the syscall. (We get notice of the | |
4187 | event when the thread is just on the verge of exiting a | |
4188 | syscall. Stepping one instruction seems to get it back | |
b4dc5ffa | 4189 | into user code.) */ |
488f131b | 4190 | case TARGET_WAITKIND_SYSCALL_RETURN: |
527159b7 | 4191 | if (debug_infrun) |
3e43a32a MS |
4192 | fprintf_unfiltered (gdb_stdlog, |
4193 | "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); | |
94c57d6a PA |
4194 | if (handle_syscall_event (ecs) == 0) |
4195 | process_event_stop_test (ecs); | |
4196 | return; | |
c906108c | 4197 | |
488f131b | 4198 | case TARGET_WAITKIND_STOPPED: |
527159b7 | 4199 | if (debug_infrun) |
8a9de0e4 | 4200 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); |
16c381f0 | 4201 | ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig; |
4f5d7f63 PA |
4202 | handle_signal_stop (ecs); |
4203 | return; | |
c906108c | 4204 | |
b2175913 | 4205 | case TARGET_WAITKIND_NO_HISTORY: |
4b4e080e PA |
4206 | if (debug_infrun) |
4207 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n"); | |
b2175913 | 4208 | /* Reverse execution: target ran out of history info. */ |
eab402df | 4209 | |
34b7e8a6 | 4210 | delete_just_stopped_threads_single_step_breakpoints (); |
fb14de7b | 4211 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
fd664c91 | 4212 | observer_notify_no_history (); |
22bcd14b | 4213 | stop_waiting (ecs); |
b2175913 | 4214 | return; |
488f131b | 4215 | } |
4f5d7f63 PA |
4216 | } |
4217 | ||
4218 | /* Come here when the program has stopped with a signal. */ | |
4219 | ||
4220 | static void | |
4221 | handle_signal_stop (struct execution_control_state *ecs) | |
4222 | { | |
4223 | struct frame_info *frame; | |
4224 | struct gdbarch *gdbarch; | |
4225 | int stopped_by_watchpoint; | |
4226 | enum stop_kind stop_soon; | |
4227 | int random_signal; | |
c906108c | 4228 | |
f0407826 DE |
4229 | gdb_assert (ecs->ws.kind == TARGET_WAITKIND_STOPPED); |
4230 | ||
4231 | /* Do we need to clean up the state of a thread that has | |
4232 | completed a displaced single-step? (Doing so usually affects | |
4233 | the PC, so do it here, before we set stop_pc.) */ | |
4234 | displaced_step_fixup (ecs->ptid, | |
4235 | ecs->event_thread->suspend.stop_signal); | |
4236 | ||
4237 | /* If we either finished a single-step or hit a breakpoint, but | |
4238 | the user wanted this thread to be stopped, pretend we got a | |
4239 | SIG0 (generic unsignaled stop). */ | |
4240 | if (ecs->event_thread->stop_requested | |
4241 | && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP) | |
4242 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; | |
237fc4c9 | 4243 | |
515630c5 | 4244 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
488f131b | 4245 | |
527159b7 | 4246 | if (debug_infrun) |
237fc4c9 | 4247 | { |
5af949e3 UW |
4248 | struct regcache *regcache = get_thread_regcache (ecs->ptid); |
4249 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
7f82dfc7 JK |
4250 | struct cleanup *old_chain = save_inferior_ptid (); |
4251 | ||
4252 | inferior_ptid = ecs->ptid; | |
5af949e3 UW |
4253 | |
4254 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n", | |
4255 | paddress (gdbarch, stop_pc)); | |
d92524f1 | 4256 | if (target_stopped_by_watchpoint ()) |
237fc4c9 PA |
4257 | { |
4258 | CORE_ADDR addr; | |
abbb1732 | 4259 | |
237fc4c9 PA |
4260 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n"); |
4261 | ||
4262 | if (target_stopped_data_address (¤t_target, &addr)) | |
4263 | fprintf_unfiltered (gdb_stdlog, | |
5af949e3 UW |
4264 | "infrun: stopped data address = %s\n", |
4265 | paddress (gdbarch, addr)); | |
237fc4c9 PA |
4266 | else |
4267 | fprintf_unfiltered (gdb_stdlog, | |
4268 | "infrun: (no data address available)\n"); | |
4269 | } | |
7f82dfc7 JK |
4270 | |
4271 | do_cleanups (old_chain); | |
237fc4c9 | 4272 | } |
527159b7 | 4273 | |
36fa8042 PA |
4274 | /* This is originated from start_remote(), start_inferior() and |
4275 | shared libraries hook functions. */ | |
4276 | stop_soon = get_inferior_stop_soon (ecs->ptid); | |
4277 | if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) | |
4278 | { | |
4279 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
4280 | context_switch (ecs->ptid); | |
4281 | if (debug_infrun) | |
4282 | fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); | |
4283 | stop_print_frame = 1; | |
22bcd14b | 4284 | stop_waiting (ecs); |
36fa8042 PA |
4285 | return; |
4286 | } | |
4287 | ||
4288 | if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP | |
4289 | && stop_after_trap) | |
4290 | { | |
4291 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
4292 | context_switch (ecs->ptid); | |
4293 | if (debug_infrun) | |
4294 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); | |
4295 | stop_print_frame = 0; | |
22bcd14b | 4296 | stop_waiting (ecs); |
36fa8042 PA |
4297 | return; |
4298 | } | |
4299 | ||
4300 | /* This originates from attach_command(). We need to overwrite | |
4301 | the stop_signal here, because some kernels don't ignore a | |
4302 | SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call. | |
4303 | See more comments in inferior.h. On the other hand, if we | |
4304 | get a non-SIGSTOP, report it to the user - assume the backend | |
4305 | will handle the SIGSTOP if it should show up later. | |
4306 | ||
4307 | Also consider that the attach is complete when we see a | |
4308 | SIGTRAP. Some systems (e.g. Windows), and stubs supporting | |
4309 | target extended-remote report it instead of a SIGSTOP | |
4310 | (e.g. gdbserver). We already rely on SIGTRAP being our | |
4311 | signal, so this is no exception. | |
4312 | ||
4313 | Also consider that the attach is complete when we see a | |
4314 | GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell | |
4315 | the target to stop all threads of the inferior, in case the | |
4316 | low level attach operation doesn't stop them implicitly. If | |
4317 | they weren't stopped implicitly, then the stub will report a | |
4318 | GDB_SIGNAL_0, meaning: stopped for no particular reason | |
4319 | other than GDB's request. */ | |
4320 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP | |
4321 | && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP | |
4322 | || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP | |
4323 | || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0)) | |
4324 | { | |
4325 | stop_print_frame = 1; | |
22bcd14b | 4326 | stop_waiting (ecs); |
36fa8042 PA |
4327 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; |
4328 | return; | |
4329 | } | |
4330 | ||
488f131b | 4331 | /* See if something interesting happened to the non-current thread. If |
b40c7d58 DJ |
4332 | so, then switch to that thread. */ |
4333 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
488f131b | 4334 | { |
527159b7 | 4335 | if (debug_infrun) |
8a9de0e4 | 4336 | fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); |
527159b7 | 4337 | |
0d1e5fa7 | 4338 | context_switch (ecs->ptid); |
c5aa993b | 4339 | |
9a4105ab AC |
4340 | if (deprecated_context_hook) |
4341 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
488f131b | 4342 | } |
c906108c | 4343 | |
568d6575 UW |
4344 | /* At this point, get hold of the now-current thread's frame. */ |
4345 | frame = get_current_frame (); | |
4346 | gdbarch = get_frame_arch (frame); | |
4347 | ||
2adfaa28 | 4348 | /* Pull the single step breakpoints out of the target. */ |
af48d08f | 4349 | if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP) |
488f131b | 4350 | { |
af48d08f PA |
4351 | struct regcache *regcache; |
4352 | struct address_space *aspace; | |
4353 | CORE_ADDR pc; | |
2adfaa28 | 4354 | |
af48d08f PA |
4355 | regcache = get_thread_regcache (ecs->ptid); |
4356 | aspace = get_regcache_aspace (regcache); | |
4357 | pc = regcache_read_pc (regcache); | |
34b7e8a6 | 4358 | |
af48d08f PA |
4359 | /* However, before doing so, if this single-step breakpoint was |
4360 | actually for another thread, set this thread up for moving | |
4361 | past it. */ | |
4362 | if (!thread_has_single_step_breakpoint_here (ecs->event_thread, | |
4363 | aspace, pc)) | |
4364 | { | |
4365 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) | |
2adfaa28 PA |
4366 | { |
4367 | if (debug_infrun) | |
4368 | { | |
4369 | fprintf_unfiltered (gdb_stdlog, | |
af48d08f | 4370 | "infrun: [%s] hit another thread's " |
34b7e8a6 PA |
4371 | "single-step breakpoint\n", |
4372 | target_pid_to_str (ecs->ptid)); | |
2adfaa28 | 4373 | } |
af48d08f PA |
4374 | ecs->hit_singlestep_breakpoint = 1; |
4375 | } | |
4376 | } | |
4377 | else | |
4378 | { | |
4379 | if (debug_infrun) | |
4380 | { | |
4381 | fprintf_unfiltered (gdb_stdlog, | |
4382 | "infrun: [%s] hit its " | |
4383 | "single-step breakpoint\n", | |
4384 | target_pid_to_str (ecs->ptid)); | |
2adfaa28 PA |
4385 | } |
4386 | } | |
488f131b | 4387 | } |
af48d08f | 4388 | delete_just_stopped_threads_single_step_breakpoints (); |
c906108c | 4389 | |
963f9c80 PA |
4390 | if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP |
4391 | && ecs->event_thread->control.trap_expected | |
4392 | && ecs->event_thread->stepping_over_watchpoint) | |
d983da9c DJ |
4393 | stopped_by_watchpoint = 0; |
4394 | else | |
4395 | stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); | |
4396 | ||
4397 | /* If necessary, step over this watchpoint. We'll be back to display | |
4398 | it in a moment. */ | |
4399 | if (stopped_by_watchpoint | |
d92524f1 | 4400 | && (target_have_steppable_watchpoint |
568d6575 | 4401 | || gdbarch_have_nonsteppable_watchpoint (gdbarch))) |
488f131b | 4402 | { |
488f131b JB |
4403 | /* At this point, we are stopped at an instruction which has |
4404 | attempted to write to a piece of memory under control of | |
4405 | a watchpoint. The instruction hasn't actually executed | |
4406 | yet. If we were to evaluate the watchpoint expression | |
4407 | now, we would get the old value, and therefore no change | |
4408 | would seem to have occurred. | |
4409 | ||
4410 | In order to make watchpoints work `right', we really need | |
4411 | to complete the memory write, and then evaluate the | |
d983da9c DJ |
4412 | watchpoint expression. We do this by single-stepping the |
4413 | target. | |
4414 | ||
7f89fd65 | 4415 | It may not be necessary to disable the watchpoint to step over |
d983da9c DJ |
4416 | it. For example, the PA can (with some kernel cooperation) |
4417 | single step over a watchpoint without disabling the watchpoint. | |
4418 | ||
4419 | It is far more common to need to disable a watchpoint to step | |
4420 | the inferior over it. If we have non-steppable watchpoints, | |
4421 | we must disable the current watchpoint; it's simplest to | |
963f9c80 PA |
4422 | disable all watchpoints. |
4423 | ||
4424 | Any breakpoint at PC must also be stepped over -- if there's | |
4425 | one, it will have already triggered before the watchpoint | |
4426 | triggered, and we either already reported it to the user, or | |
4427 | it didn't cause a stop and we called keep_going. In either | |
4428 | case, if there was a breakpoint at PC, we must be trying to | |
4429 | step past it. */ | |
4430 | ecs->event_thread->stepping_over_watchpoint = 1; | |
4431 | keep_going (ecs); | |
488f131b JB |
4432 | return; |
4433 | } | |
4434 | ||
4e1c45ea | 4435 | ecs->event_thread->stepping_over_breakpoint = 0; |
963f9c80 | 4436 | ecs->event_thread->stepping_over_watchpoint = 0; |
16c381f0 JK |
4437 | bpstat_clear (&ecs->event_thread->control.stop_bpstat); |
4438 | ecs->event_thread->control.stop_step = 0; | |
488f131b | 4439 | stop_print_frame = 1; |
488f131b | 4440 | stopped_by_random_signal = 0; |
488f131b | 4441 | |
edb3359d DJ |
4442 | /* Hide inlined functions starting here, unless we just performed stepi or |
4443 | nexti. After stepi and nexti, always show the innermost frame (not any | |
4444 | inline function call sites). */ | |
16c381f0 | 4445 | if (ecs->event_thread->control.step_range_end != 1) |
0574c78f GB |
4446 | { |
4447 | struct address_space *aspace = | |
4448 | get_regcache_aspace (get_thread_regcache (ecs->ptid)); | |
4449 | ||
4450 | /* skip_inline_frames is expensive, so we avoid it if we can | |
4451 | determine that the address is one where functions cannot have | |
4452 | been inlined. This improves performance with inferiors that | |
4453 | load a lot of shared libraries, because the solib event | |
4454 | breakpoint is defined as the address of a function (i.e. not | |
4455 | inline). Note that we have to check the previous PC as well | |
4456 | as the current one to catch cases when we have just | |
4457 | single-stepped off a breakpoint prior to reinstating it. | |
4458 | Note that we're assuming that the code we single-step to is | |
4459 | not inline, but that's not definitive: there's nothing | |
4460 | preventing the event breakpoint function from containing | |
4461 | inlined code, and the single-step ending up there. If the | |
4462 | user had set a breakpoint on that inlined code, the missing | |
4463 | skip_inline_frames call would break things. Fortunately | |
4464 | that's an extremely unlikely scenario. */ | |
09ac7c10 | 4465 | if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws) |
a210c238 MR |
4466 | && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP |
4467 | && ecs->event_thread->control.trap_expected | |
4468 | && pc_at_non_inline_function (aspace, | |
4469 | ecs->event_thread->prev_pc, | |
09ac7c10 | 4470 | &ecs->ws))) |
1c5a993e MR |
4471 | { |
4472 | skip_inline_frames (ecs->ptid); | |
4473 | ||
4474 | /* Re-fetch current thread's frame in case that invalidated | |
4475 | the frame cache. */ | |
4476 | frame = get_current_frame (); | |
4477 | gdbarch = get_frame_arch (frame); | |
4478 | } | |
0574c78f | 4479 | } |
edb3359d | 4480 | |
a493e3e2 | 4481 | if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP |
16c381f0 | 4482 | && ecs->event_thread->control.trap_expected |
568d6575 | 4483 | && gdbarch_single_step_through_delay_p (gdbarch) |
4e1c45ea | 4484 | && currently_stepping (ecs->event_thread)) |
3352ef37 | 4485 | { |
b50d7442 | 4486 | /* We're trying to step off a breakpoint. Turns out that we're |
3352ef37 | 4487 | also on an instruction that needs to be stepped multiple |
1777feb0 | 4488 | times before it's been fully executing. E.g., architectures |
3352ef37 AC |
4489 | with a delay slot. It needs to be stepped twice, once for |
4490 | the instruction and once for the delay slot. */ | |
4491 | int step_through_delay | |
568d6575 | 4492 | = gdbarch_single_step_through_delay (gdbarch, frame); |
abbb1732 | 4493 | |
527159b7 | 4494 | if (debug_infrun && step_through_delay) |
8a9de0e4 | 4495 | fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); |
16c381f0 JK |
4496 | if (ecs->event_thread->control.step_range_end == 0 |
4497 | && step_through_delay) | |
3352ef37 AC |
4498 | { |
4499 | /* The user issued a continue when stopped at a breakpoint. | |
4500 | Set up for another trap and get out of here. */ | |
4e1c45ea | 4501 | ecs->event_thread->stepping_over_breakpoint = 1; |
3352ef37 AC |
4502 | keep_going (ecs); |
4503 | return; | |
4504 | } | |
4505 | else if (step_through_delay) | |
4506 | { | |
4507 | /* The user issued a step when stopped at a breakpoint. | |
4508 | Maybe we should stop, maybe we should not - the delay | |
4509 | slot *might* correspond to a line of source. In any | |
ca67fcb8 VP |
4510 | case, don't decide that here, just set |
4511 | ecs->stepping_over_breakpoint, making sure we | |
4512 | single-step again before breakpoints are re-inserted. */ | |
4e1c45ea | 4513 | ecs->event_thread->stepping_over_breakpoint = 1; |
3352ef37 AC |
4514 | } |
4515 | } | |
4516 | ||
ab04a2af TT |
4517 | /* See if there is a breakpoint/watchpoint/catchpoint/etc. that |
4518 | handles this event. */ | |
4519 | ecs->event_thread->control.stop_bpstat | |
4520 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), | |
4521 | stop_pc, ecs->ptid, &ecs->ws); | |
db82e815 | 4522 | |
ab04a2af TT |
4523 | /* Following in case break condition called a |
4524 | function. */ | |
4525 | stop_print_frame = 1; | |
73dd234f | 4526 | |
ab04a2af TT |
4527 | /* This is where we handle "moribund" watchpoints. Unlike |
4528 | software breakpoints traps, hardware watchpoint traps are | |
4529 | always distinguishable from random traps. If no high-level | |
4530 | watchpoint is associated with the reported stop data address | |
4531 | anymore, then the bpstat does not explain the signal --- | |
4532 | simply make sure to ignore it if `stopped_by_watchpoint' is | |
4533 | set. */ | |
4534 | ||
4535 | if (debug_infrun | |
4536 | && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP | |
47591c29 | 4537 | && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, |
427cd150 | 4538 | GDB_SIGNAL_TRAP) |
ab04a2af TT |
4539 | && stopped_by_watchpoint) |
4540 | fprintf_unfiltered (gdb_stdlog, | |
4541 | "infrun: no user watchpoint explains " | |
4542 | "watchpoint SIGTRAP, ignoring\n"); | |
73dd234f | 4543 | |
bac7d97b | 4544 | /* NOTE: cagney/2003-03-29: These checks for a random signal |
ab04a2af TT |
4545 | at one stage in the past included checks for an inferior |
4546 | function call's call dummy's return breakpoint. The original | |
4547 | comment, that went with the test, read: | |
03cebad2 | 4548 | |
ab04a2af TT |
4549 | ``End of a stack dummy. Some systems (e.g. Sony news) give |
4550 | another signal besides SIGTRAP, so check here as well as | |
4551 | above.'' | |
73dd234f | 4552 | |
ab04a2af TT |
4553 | If someone ever tries to get call dummys on a |
4554 | non-executable stack to work (where the target would stop | |
4555 | with something like a SIGSEGV), then those tests might need | |
4556 | to be re-instated. Given, however, that the tests were only | |
4557 | enabled when momentary breakpoints were not being used, I | |
4558 | suspect that it won't be the case. | |
488f131b | 4559 | |
ab04a2af TT |
4560 | NOTE: kettenis/2004-02-05: Indeed such checks don't seem to |
4561 | be necessary for call dummies on a non-executable stack on | |
4562 | SPARC. */ | |
488f131b | 4563 | |
bac7d97b | 4564 | /* See if the breakpoints module can explain the signal. */ |
47591c29 PA |
4565 | random_signal |
4566 | = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, | |
4567 | ecs->event_thread->suspend.stop_signal); | |
bac7d97b | 4568 | |
1cf4d951 PA |
4569 | /* Maybe this was a trap for a software breakpoint that has since |
4570 | been removed. */ | |
4571 | if (random_signal && target_stopped_by_sw_breakpoint ()) | |
4572 | { | |
4573 | if (program_breakpoint_here_p (gdbarch, stop_pc)) | |
4574 | { | |
4575 | struct regcache *regcache; | |
4576 | int decr_pc; | |
4577 | ||
4578 | /* Re-adjust PC to what the program would see if GDB was not | |
4579 | debugging it. */ | |
4580 | regcache = get_thread_regcache (ecs->event_thread->ptid); | |
527a273a | 4581 | decr_pc = gdbarch_decr_pc_after_break (gdbarch); |
1cf4d951 PA |
4582 | if (decr_pc != 0) |
4583 | { | |
4584 | struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL); | |
4585 | ||
4586 | if (record_full_is_used ()) | |
4587 | record_full_gdb_operation_disable_set (); | |
4588 | ||
4589 | regcache_write_pc (regcache, stop_pc + decr_pc); | |
4590 | ||
4591 | do_cleanups (old_cleanups); | |
4592 | } | |
4593 | } | |
4594 | else | |
4595 | { | |
4596 | /* A delayed software breakpoint event. Ignore the trap. */ | |
4597 | if (debug_infrun) | |
4598 | fprintf_unfiltered (gdb_stdlog, | |
4599 | "infrun: delayed software breakpoint " | |
4600 | "trap, ignoring\n"); | |
4601 | random_signal = 0; | |
4602 | } | |
4603 | } | |
4604 | ||
4605 | /* Maybe this was a trap for a hardware breakpoint/watchpoint that | |
4606 | has since been removed. */ | |
4607 | if (random_signal && target_stopped_by_hw_breakpoint ()) | |
4608 | { | |
4609 | /* A delayed hardware breakpoint event. Ignore the trap. */ | |
4610 | if (debug_infrun) | |
4611 | fprintf_unfiltered (gdb_stdlog, | |
4612 | "infrun: delayed hardware breakpoint/watchpoint " | |
4613 | "trap, ignoring\n"); | |
4614 | random_signal = 0; | |
4615 | } | |
4616 | ||
bac7d97b PA |
4617 | /* If not, perhaps stepping/nexting can. */ |
4618 | if (random_signal) | |
4619 | random_signal = !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP | |
4620 | && currently_stepping (ecs->event_thread)); | |
ab04a2af | 4621 | |
2adfaa28 PA |
4622 | /* Perhaps the thread hit a single-step breakpoint of _another_ |
4623 | thread. Single-step breakpoints are transparent to the | |
4624 | breakpoints module. */ | |
4625 | if (random_signal) | |
4626 | random_signal = !ecs->hit_singlestep_breakpoint; | |
4627 | ||
bac7d97b PA |
4628 | /* No? Perhaps we got a moribund watchpoint. */ |
4629 | if (random_signal) | |
4630 | random_signal = !stopped_by_watchpoint; | |
ab04a2af | 4631 | |
488f131b JB |
4632 | /* For the program's own signals, act according to |
4633 | the signal handling tables. */ | |
4634 | ||
ce12b012 | 4635 | if (random_signal) |
488f131b JB |
4636 | { |
4637 | /* Signal not for debugging purposes. */ | |
c9657e70 | 4638 | struct inferior *inf = find_inferior_ptid (ecs->ptid); |
c9737c08 | 4639 | enum gdb_signal stop_signal = ecs->event_thread->suspend.stop_signal; |
488f131b | 4640 | |
527159b7 | 4641 | if (debug_infrun) |
c9737c08 PA |
4642 | fprintf_unfiltered (gdb_stdlog, "infrun: random signal (%s)\n", |
4643 | gdb_signal_to_symbol_string (stop_signal)); | |
527159b7 | 4644 | |
488f131b JB |
4645 | stopped_by_random_signal = 1; |
4646 | ||
252fbfc8 PA |
4647 | /* Always stop on signals if we're either just gaining control |
4648 | of the program, or the user explicitly requested this thread | |
4649 | to remain stopped. */ | |
d6b48e9c | 4650 | if (stop_soon != NO_STOP_QUIETLY |
252fbfc8 | 4651 | || ecs->event_thread->stop_requested |
24291992 | 4652 | || (!inf->detaching |
16c381f0 | 4653 | && signal_stop_state (ecs->event_thread->suspend.stop_signal))) |
488f131b | 4654 | { |
22bcd14b | 4655 | stop_waiting (ecs); |
488f131b JB |
4656 | return; |
4657 | } | |
b57bacec PA |
4658 | |
4659 | /* Notify observers the signal has "handle print" set. Note we | |
4660 | returned early above if stopping; normal_stop handles the | |
4661 | printing in that case. */ | |
4662 | if (signal_print[ecs->event_thread->suspend.stop_signal]) | |
4663 | { | |
4664 | /* The signal table tells us to print about this signal. */ | |
4665 | target_terminal_ours_for_output (); | |
4666 | observer_notify_signal_received (ecs->event_thread->suspend.stop_signal); | |
4667 | target_terminal_inferior (); | |
4668 | } | |
488f131b JB |
4669 | |
4670 | /* Clear the signal if it should not be passed. */ | |
16c381f0 | 4671 | if (signal_program[ecs->event_thread->suspend.stop_signal] == 0) |
a493e3e2 | 4672 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; |
488f131b | 4673 | |
fb14de7b | 4674 | if (ecs->event_thread->prev_pc == stop_pc |
16c381f0 | 4675 | && ecs->event_thread->control.trap_expected |
8358c15c | 4676 | && ecs->event_thread->control.step_resume_breakpoint == NULL) |
68f53502 AC |
4677 | { |
4678 | /* We were just starting a new sequence, attempting to | |
4679 | single-step off of a breakpoint and expecting a SIGTRAP. | |
237fc4c9 | 4680 | Instead this signal arrives. This signal will take us out |
68f53502 AC |
4681 | of the stepping range so GDB needs to remember to, when |
4682 | the signal handler returns, resume stepping off that | |
4683 | breakpoint. */ | |
4684 | /* To simplify things, "continue" is forced to use the same | |
4685 | code paths as single-step - set a breakpoint at the | |
4686 | signal return address and then, once hit, step off that | |
4687 | breakpoint. */ | |
237fc4c9 PA |
4688 | if (debug_infrun) |
4689 | fprintf_unfiltered (gdb_stdlog, | |
4690 | "infrun: signal arrived while stepping over " | |
4691 | "breakpoint\n"); | |
d3169d93 | 4692 | |
2c03e5be | 4693 | insert_hp_step_resume_breakpoint_at_frame (frame); |
4e1c45ea | 4694 | ecs->event_thread->step_after_step_resume_breakpoint = 1; |
2455069d UW |
4695 | /* Reset trap_expected to ensure breakpoints are re-inserted. */ |
4696 | ecs->event_thread->control.trap_expected = 0; | |
d137e6dc PA |
4697 | |
4698 | /* If we were nexting/stepping some other thread, switch to | |
4699 | it, so that we don't continue it, losing control. */ | |
4700 | if (!switch_back_to_stepped_thread (ecs)) | |
4701 | keep_going (ecs); | |
9d799f85 | 4702 | return; |
68f53502 | 4703 | } |
9d799f85 | 4704 | |
e5f8a7cc PA |
4705 | if (ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0 |
4706 | && (pc_in_thread_step_range (stop_pc, ecs->event_thread) | |
4707 | || ecs->event_thread->control.step_range_end == 1) | |
edb3359d | 4708 | && frame_id_eq (get_stack_frame_id (frame), |
16c381f0 | 4709 | ecs->event_thread->control.step_stack_frame_id) |
8358c15c | 4710 | && ecs->event_thread->control.step_resume_breakpoint == NULL) |
d303a6c7 AC |
4711 | { |
4712 | /* The inferior is about to take a signal that will take it | |
4713 | out of the single step range. Set a breakpoint at the | |
4714 | current PC (which is presumably where the signal handler | |
4715 | will eventually return) and then allow the inferior to | |
4716 | run free. | |
4717 | ||
4718 | Note that this is only needed for a signal delivered | |
4719 | while in the single-step range. Nested signals aren't a | |
4720 | problem as they eventually all return. */ | |
237fc4c9 PA |
4721 | if (debug_infrun) |
4722 | fprintf_unfiltered (gdb_stdlog, | |
4723 | "infrun: signal may take us out of " | |
4724 | "single-step range\n"); | |
4725 | ||
2c03e5be | 4726 | insert_hp_step_resume_breakpoint_at_frame (frame); |
e5f8a7cc | 4727 | ecs->event_thread->step_after_step_resume_breakpoint = 1; |
2455069d UW |
4728 | /* Reset trap_expected to ensure breakpoints are re-inserted. */ |
4729 | ecs->event_thread->control.trap_expected = 0; | |
9d799f85 AC |
4730 | keep_going (ecs); |
4731 | return; | |
d303a6c7 | 4732 | } |
9d799f85 AC |
4733 | |
4734 | /* Note: step_resume_breakpoint may be non-NULL. This occures | |
4735 | when either there's a nested signal, or when there's a | |
4736 | pending signal enabled just as the signal handler returns | |
4737 | (leaving the inferior at the step-resume-breakpoint without | |
4738 | actually executing it). Either way continue until the | |
4739 | breakpoint is really hit. */ | |
c447ac0b PA |
4740 | |
4741 | if (!switch_back_to_stepped_thread (ecs)) | |
4742 | { | |
4743 | if (debug_infrun) | |
4744 | fprintf_unfiltered (gdb_stdlog, | |
4745 | "infrun: random signal, keep going\n"); | |
4746 | ||
4747 | keep_going (ecs); | |
4748 | } | |
4749 | return; | |
488f131b | 4750 | } |
94c57d6a PA |
4751 | |
4752 | process_event_stop_test (ecs); | |
4753 | } | |
4754 | ||
4755 | /* Come here when we've got some debug event / signal we can explain | |
4756 | (IOW, not a random signal), and test whether it should cause a | |
4757 | stop, or whether we should resume the inferior (transparently). | |
4758 | E.g., could be a breakpoint whose condition evaluates false; we | |
4759 | could be still stepping within the line; etc. */ | |
4760 | ||
4761 | static void | |
4762 | process_event_stop_test (struct execution_control_state *ecs) | |
4763 | { | |
4764 | struct symtab_and_line stop_pc_sal; | |
4765 | struct frame_info *frame; | |
4766 | struct gdbarch *gdbarch; | |
cdaa5b73 PA |
4767 | CORE_ADDR jmp_buf_pc; |
4768 | struct bpstat_what what; | |
94c57d6a | 4769 | |
cdaa5b73 | 4770 | /* Handle cases caused by hitting a breakpoint. */ |
611c83ae | 4771 | |
cdaa5b73 PA |
4772 | frame = get_current_frame (); |
4773 | gdbarch = get_frame_arch (frame); | |
fcf3daef | 4774 | |
cdaa5b73 | 4775 | what = bpstat_what (ecs->event_thread->control.stop_bpstat); |
611c83ae | 4776 | |
cdaa5b73 PA |
4777 | if (what.call_dummy) |
4778 | { | |
4779 | stop_stack_dummy = what.call_dummy; | |
4780 | } | |
186c406b | 4781 | |
cdaa5b73 PA |
4782 | /* If we hit an internal event that triggers symbol changes, the |
4783 | current frame will be invalidated within bpstat_what (e.g., if we | |
4784 | hit an internal solib event). Re-fetch it. */ | |
4785 | frame = get_current_frame (); | |
4786 | gdbarch = get_frame_arch (frame); | |
e2e4d78b | 4787 | |
cdaa5b73 PA |
4788 | switch (what.main_action) |
4789 | { | |
4790 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: | |
4791 | /* If we hit the breakpoint at longjmp while stepping, we | |
4792 | install a momentary breakpoint at the target of the | |
4793 | jmp_buf. */ | |
186c406b | 4794 | |
cdaa5b73 PA |
4795 | if (debug_infrun) |
4796 | fprintf_unfiltered (gdb_stdlog, | |
4797 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); | |
186c406b | 4798 | |
cdaa5b73 | 4799 | ecs->event_thread->stepping_over_breakpoint = 1; |
611c83ae | 4800 | |
cdaa5b73 PA |
4801 | if (what.is_longjmp) |
4802 | { | |
4803 | struct value *arg_value; | |
4804 | ||
4805 | /* If we set the longjmp breakpoint via a SystemTap probe, | |
4806 | then use it to extract the arguments. The destination PC | |
4807 | is the third argument to the probe. */ | |
4808 | arg_value = probe_safe_evaluate_at_pc (frame, 2); | |
4809 | if (arg_value) | |
8fa0c4f8 AA |
4810 | { |
4811 | jmp_buf_pc = value_as_address (arg_value); | |
4812 | jmp_buf_pc = gdbarch_addr_bits_remove (gdbarch, jmp_buf_pc); | |
4813 | } | |
cdaa5b73 PA |
4814 | else if (!gdbarch_get_longjmp_target_p (gdbarch) |
4815 | || !gdbarch_get_longjmp_target (gdbarch, | |
4816 | frame, &jmp_buf_pc)) | |
e2e4d78b | 4817 | { |
cdaa5b73 PA |
4818 | if (debug_infrun) |
4819 | fprintf_unfiltered (gdb_stdlog, | |
4820 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME " | |
4821 | "(!gdbarch_get_longjmp_target)\n"); | |
4822 | keep_going (ecs); | |
4823 | return; | |
e2e4d78b | 4824 | } |
e2e4d78b | 4825 | |
cdaa5b73 PA |
4826 | /* Insert a breakpoint at resume address. */ |
4827 | insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc); | |
4828 | } | |
4829 | else | |
4830 | check_exception_resume (ecs, frame); | |
4831 | keep_going (ecs); | |
4832 | return; | |
e81a37f7 | 4833 | |
cdaa5b73 PA |
4834 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
4835 | { | |
4836 | struct frame_info *init_frame; | |
e81a37f7 | 4837 | |
cdaa5b73 | 4838 | /* There are several cases to consider. |
c906108c | 4839 | |
cdaa5b73 PA |
4840 | 1. The initiating frame no longer exists. In this case we |
4841 | must stop, because the exception or longjmp has gone too | |
4842 | far. | |
2c03e5be | 4843 | |
cdaa5b73 PA |
4844 | 2. The initiating frame exists, and is the same as the |
4845 | current frame. We stop, because the exception or longjmp | |
4846 | has been caught. | |
2c03e5be | 4847 | |
cdaa5b73 PA |
4848 | 3. The initiating frame exists and is different from the |
4849 | current frame. This means the exception or longjmp has | |
4850 | been caught beneath the initiating frame, so keep going. | |
c906108c | 4851 | |
cdaa5b73 PA |
4852 | 4. longjmp breakpoint has been placed just to protect |
4853 | against stale dummy frames and user is not interested in | |
4854 | stopping around longjmps. */ | |
c5aa993b | 4855 | |
cdaa5b73 PA |
4856 | if (debug_infrun) |
4857 | fprintf_unfiltered (gdb_stdlog, | |
4858 | "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); | |
c5aa993b | 4859 | |
cdaa5b73 PA |
4860 | gdb_assert (ecs->event_thread->control.exception_resume_breakpoint |
4861 | != NULL); | |
4862 | delete_exception_resume_breakpoint (ecs->event_thread); | |
c5aa993b | 4863 | |
cdaa5b73 PA |
4864 | if (what.is_longjmp) |
4865 | { | |
b67a2c6f | 4866 | check_longjmp_breakpoint_for_call_dummy (ecs->event_thread); |
c5aa993b | 4867 | |
cdaa5b73 | 4868 | if (!frame_id_p (ecs->event_thread->initiating_frame)) |
e5ef252a | 4869 | { |
cdaa5b73 PA |
4870 | /* Case 4. */ |
4871 | keep_going (ecs); | |
4872 | return; | |
e5ef252a | 4873 | } |
cdaa5b73 | 4874 | } |
c5aa993b | 4875 | |
cdaa5b73 | 4876 | init_frame = frame_find_by_id (ecs->event_thread->initiating_frame); |
527159b7 | 4877 | |
cdaa5b73 PA |
4878 | if (init_frame) |
4879 | { | |
4880 | struct frame_id current_id | |
4881 | = get_frame_id (get_current_frame ()); | |
4882 | if (frame_id_eq (current_id, | |
4883 | ecs->event_thread->initiating_frame)) | |
4884 | { | |
4885 | /* Case 2. Fall through. */ | |
4886 | } | |
4887 | else | |
4888 | { | |
4889 | /* Case 3. */ | |
4890 | keep_going (ecs); | |
4891 | return; | |
4892 | } | |
68f53502 | 4893 | } |
488f131b | 4894 | |
cdaa5b73 PA |
4895 | /* For Cases 1 and 2, remove the step-resume breakpoint, if it |
4896 | exists. */ | |
4897 | delete_step_resume_breakpoint (ecs->event_thread); | |
e5ef252a | 4898 | |
bdc36728 | 4899 | end_stepping_range (ecs); |
cdaa5b73 PA |
4900 | } |
4901 | return; | |
e5ef252a | 4902 | |
cdaa5b73 PA |
4903 | case BPSTAT_WHAT_SINGLE: |
4904 | if (debug_infrun) | |
4905 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); | |
4906 | ecs->event_thread->stepping_over_breakpoint = 1; | |
4907 | /* Still need to check other stuff, at least the case where we | |
4908 | are stepping and step out of the right range. */ | |
4909 | break; | |
e5ef252a | 4910 | |
cdaa5b73 PA |
4911 | case BPSTAT_WHAT_STEP_RESUME: |
4912 | if (debug_infrun) | |
4913 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); | |
e5ef252a | 4914 | |
cdaa5b73 PA |
4915 | delete_step_resume_breakpoint (ecs->event_thread); |
4916 | if (ecs->event_thread->control.proceed_to_finish | |
4917 | && execution_direction == EXEC_REVERSE) | |
4918 | { | |
4919 | struct thread_info *tp = ecs->event_thread; | |
4920 | ||
4921 | /* We are finishing a function in reverse, and just hit the | |
4922 | step-resume breakpoint at the start address of the | |
4923 | function, and we're almost there -- just need to back up | |
4924 | by one more single-step, which should take us back to the | |
4925 | function call. */ | |
4926 | tp->control.step_range_start = tp->control.step_range_end = 1; | |
4927 | keep_going (ecs); | |
e5ef252a | 4928 | return; |
cdaa5b73 PA |
4929 | } |
4930 | fill_in_stop_func (gdbarch, ecs); | |
4931 | if (stop_pc == ecs->stop_func_start | |
4932 | && execution_direction == EXEC_REVERSE) | |
4933 | { | |
4934 | /* We are stepping over a function call in reverse, and just | |
4935 | hit the step-resume breakpoint at the start address of | |
4936 | the function. Go back to single-stepping, which should | |
4937 | take us back to the function call. */ | |
4938 | ecs->event_thread->stepping_over_breakpoint = 1; | |
4939 | keep_going (ecs); | |
4940 | return; | |
4941 | } | |
4942 | break; | |
e5ef252a | 4943 | |
cdaa5b73 PA |
4944 | case BPSTAT_WHAT_STOP_NOISY: |
4945 | if (debug_infrun) | |
4946 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); | |
4947 | stop_print_frame = 1; | |
e5ef252a | 4948 | |
99619bea PA |
4949 | /* Assume the thread stopped for a breapoint. We'll still check |
4950 | whether a/the breakpoint is there when the thread is next | |
4951 | resumed. */ | |
4952 | ecs->event_thread->stepping_over_breakpoint = 1; | |
e5ef252a | 4953 | |
22bcd14b | 4954 | stop_waiting (ecs); |
cdaa5b73 | 4955 | return; |
e5ef252a | 4956 | |
cdaa5b73 PA |
4957 | case BPSTAT_WHAT_STOP_SILENT: |
4958 | if (debug_infrun) | |
4959 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); | |
4960 | stop_print_frame = 0; | |
e5ef252a | 4961 | |
99619bea PA |
4962 | /* Assume the thread stopped for a breapoint. We'll still check |
4963 | whether a/the breakpoint is there when the thread is next | |
4964 | resumed. */ | |
4965 | ecs->event_thread->stepping_over_breakpoint = 1; | |
22bcd14b | 4966 | stop_waiting (ecs); |
cdaa5b73 PA |
4967 | return; |
4968 | ||
4969 | case BPSTAT_WHAT_HP_STEP_RESUME: | |
4970 | if (debug_infrun) | |
4971 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n"); | |
4972 | ||
4973 | delete_step_resume_breakpoint (ecs->event_thread); | |
4974 | if (ecs->event_thread->step_after_step_resume_breakpoint) | |
4975 | { | |
4976 | /* Back when the step-resume breakpoint was inserted, we | |
4977 | were trying to single-step off a breakpoint. Go back to | |
4978 | doing that. */ | |
4979 | ecs->event_thread->step_after_step_resume_breakpoint = 0; | |
4980 | ecs->event_thread->stepping_over_breakpoint = 1; | |
4981 | keep_going (ecs); | |
4982 | return; | |
e5ef252a | 4983 | } |
cdaa5b73 PA |
4984 | break; |
4985 | ||
4986 | case BPSTAT_WHAT_KEEP_CHECKING: | |
4987 | break; | |
e5ef252a | 4988 | } |
c906108c | 4989 | |
af48d08f PA |
4990 | /* If we stepped a permanent breakpoint and we had a high priority |
4991 | step-resume breakpoint for the address we stepped, but we didn't | |
4992 | hit it, then we must have stepped into the signal handler. The | |
4993 | step-resume was only necessary to catch the case of _not_ | |
4994 | stepping into the handler, so delete it, and fall through to | |
4995 | checking whether the step finished. */ | |
4996 | if (ecs->event_thread->stepped_breakpoint) | |
4997 | { | |
4998 | struct breakpoint *sr_bp | |
4999 | = ecs->event_thread->control.step_resume_breakpoint; | |
5000 | ||
8d707a12 PA |
5001 | if (sr_bp != NULL |
5002 | && sr_bp->loc->permanent | |
af48d08f PA |
5003 | && sr_bp->type == bp_hp_step_resume |
5004 | && sr_bp->loc->address == ecs->event_thread->prev_pc) | |
5005 | { | |
5006 | if (debug_infrun) | |
5007 | fprintf_unfiltered (gdb_stdlog, | |
5008 | "infrun: stepped permanent breakpoint, stopped in " | |
5009 | "handler\n"); | |
5010 | delete_step_resume_breakpoint (ecs->event_thread); | |
5011 | ecs->event_thread->step_after_step_resume_breakpoint = 0; | |
5012 | } | |
5013 | } | |
5014 | ||
cdaa5b73 PA |
5015 | /* We come here if we hit a breakpoint but should not stop for it. |
5016 | Possibly we also were stepping and should stop for that. So fall | |
5017 | through and test for stepping. But, if not stepping, do not | |
5018 | stop. */ | |
c906108c | 5019 | |
a7212384 UW |
5020 | /* In all-stop mode, if we're currently stepping but have stopped in |
5021 | some other thread, we need to switch back to the stepped thread. */ | |
c447ac0b PA |
5022 | if (switch_back_to_stepped_thread (ecs)) |
5023 | return; | |
776f04fa | 5024 | |
8358c15c | 5025 | if (ecs->event_thread->control.step_resume_breakpoint) |
488f131b | 5026 | { |
527159b7 | 5027 | if (debug_infrun) |
d3169d93 DJ |
5028 | fprintf_unfiltered (gdb_stdlog, |
5029 | "infrun: step-resume breakpoint is inserted\n"); | |
527159b7 | 5030 | |
488f131b JB |
5031 | /* Having a step-resume breakpoint overrides anything |
5032 | else having to do with stepping commands until | |
5033 | that breakpoint is reached. */ | |
488f131b JB |
5034 | keep_going (ecs); |
5035 | return; | |
5036 | } | |
c5aa993b | 5037 | |
16c381f0 | 5038 | if (ecs->event_thread->control.step_range_end == 0) |
488f131b | 5039 | { |
527159b7 | 5040 | if (debug_infrun) |
8a9de0e4 | 5041 | fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); |
488f131b | 5042 | /* Likewise if we aren't even stepping. */ |
488f131b JB |
5043 | keep_going (ecs); |
5044 | return; | |
5045 | } | |
c5aa993b | 5046 | |
4b7703ad JB |
5047 | /* Re-fetch current thread's frame in case the code above caused |
5048 | the frame cache to be re-initialized, making our FRAME variable | |
5049 | a dangling pointer. */ | |
5050 | frame = get_current_frame (); | |
628fe4e4 | 5051 | gdbarch = get_frame_arch (frame); |
7e324e48 | 5052 | fill_in_stop_func (gdbarch, ecs); |
4b7703ad | 5053 | |
488f131b | 5054 | /* If stepping through a line, keep going if still within it. |
c906108c | 5055 | |
488f131b JB |
5056 | Note that step_range_end is the address of the first instruction |
5057 | beyond the step range, and NOT the address of the last instruction | |
31410e84 MS |
5058 | within it! |
5059 | ||
5060 | Note also that during reverse execution, we may be stepping | |
5061 | through a function epilogue and therefore must detect when | |
5062 | the current-frame changes in the middle of a line. */ | |
5063 | ||
ce4c476a | 5064 | if (pc_in_thread_step_range (stop_pc, ecs->event_thread) |
31410e84 | 5065 | && (execution_direction != EXEC_REVERSE |
388a8562 | 5066 | || frame_id_eq (get_frame_id (frame), |
16c381f0 | 5067 | ecs->event_thread->control.step_frame_id))) |
488f131b | 5068 | { |
527159b7 | 5069 | if (debug_infrun) |
5af949e3 UW |
5070 | fprintf_unfiltered |
5071 | (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n", | |
16c381f0 JK |
5072 | paddress (gdbarch, ecs->event_thread->control.step_range_start), |
5073 | paddress (gdbarch, ecs->event_thread->control.step_range_end)); | |
b2175913 | 5074 | |
c1e36e3e PA |
5075 | /* Tentatively re-enable range stepping; `resume' disables it if |
5076 | necessary (e.g., if we're stepping over a breakpoint or we | |
5077 | have software watchpoints). */ | |
5078 | ecs->event_thread->control.may_range_step = 1; | |
5079 | ||
b2175913 MS |
5080 | /* When stepping backward, stop at beginning of line range |
5081 | (unless it's the function entry point, in which case | |
5082 | keep going back to the call point). */ | |
16c381f0 | 5083 | if (stop_pc == ecs->event_thread->control.step_range_start |
b2175913 MS |
5084 | && stop_pc != ecs->stop_func_start |
5085 | && execution_direction == EXEC_REVERSE) | |
bdc36728 | 5086 | end_stepping_range (ecs); |
b2175913 MS |
5087 | else |
5088 | keep_going (ecs); | |
5089 | ||
488f131b JB |
5090 | return; |
5091 | } | |
c5aa993b | 5092 | |
488f131b | 5093 | /* We stepped out of the stepping range. */ |
c906108c | 5094 | |
488f131b | 5095 | /* If we are stepping at the source level and entered the runtime |
388a8562 MS |
5096 | loader dynamic symbol resolution code... |
5097 | ||
5098 | EXEC_FORWARD: we keep on single stepping until we exit the run | |
5099 | time loader code and reach the callee's address. | |
5100 | ||
5101 | EXEC_REVERSE: we've already executed the callee (backward), and | |
5102 | the runtime loader code is handled just like any other | |
5103 | undebuggable function call. Now we need only keep stepping | |
5104 | backward through the trampoline code, and that's handled further | |
5105 | down, so there is nothing for us to do here. */ | |
5106 | ||
5107 | if (execution_direction != EXEC_REVERSE | |
16c381f0 | 5108 | && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
cfd8ab24 | 5109 | && in_solib_dynsym_resolve_code (stop_pc)) |
488f131b | 5110 | { |
4c8c40e6 | 5111 | CORE_ADDR pc_after_resolver = |
568d6575 | 5112 | gdbarch_skip_solib_resolver (gdbarch, stop_pc); |
c906108c | 5113 | |
527159b7 | 5114 | if (debug_infrun) |
3e43a32a MS |
5115 | fprintf_unfiltered (gdb_stdlog, |
5116 | "infrun: stepped into dynsym resolve code\n"); | |
527159b7 | 5117 | |
488f131b JB |
5118 | if (pc_after_resolver) |
5119 | { | |
5120 | /* Set up a step-resume breakpoint at the address | |
5121 | indicated by SKIP_SOLIB_RESOLVER. */ | |
5122 | struct symtab_and_line sr_sal; | |
abbb1732 | 5123 | |
fe39c653 | 5124 | init_sal (&sr_sal); |
488f131b | 5125 | sr_sal.pc = pc_after_resolver; |
6c95b8df | 5126 | sr_sal.pspace = get_frame_program_space (frame); |
488f131b | 5127 | |
a6d9a66e UW |
5128 | insert_step_resume_breakpoint_at_sal (gdbarch, |
5129 | sr_sal, null_frame_id); | |
c5aa993b | 5130 | } |
c906108c | 5131 | |
488f131b JB |
5132 | keep_going (ecs); |
5133 | return; | |
5134 | } | |
c906108c | 5135 | |
16c381f0 JK |
5136 | if (ecs->event_thread->control.step_range_end != 1 |
5137 | && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE | |
5138 | || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) | |
568d6575 | 5139 | && get_frame_type (frame) == SIGTRAMP_FRAME) |
488f131b | 5140 | { |
527159b7 | 5141 | if (debug_infrun) |
3e43a32a MS |
5142 | fprintf_unfiltered (gdb_stdlog, |
5143 | "infrun: stepped into signal trampoline\n"); | |
42edda50 | 5144 | /* The inferior, while doing a "step" or "next", has ended up in |
8fb3e588 AC |
5145 | a signal trampoline (either by a signal being delivered or by |
5146 | the signal handler returning). Just single-step until the | |
5147 | inferior leaves the trampoline (either by calling the handler | |
5148 | or returning). */ | |
488f131b JB |
5149 | keep_going (ecs); |
5150 | return; | |
5151 | } | |
c906108c | 5152 | |
14132e89 MR |
5153 | /* If we're in the return path from a shared library trampoline, |
5154 | we want to proceed through the trampoline when stepping. */ | |
5155 | /* macro/2012-04-25: This needs to come before the subroutine | |
5156 | call check below as on some targets return trampolines look | |
5157 | like subroutine calls (MIPS16 return thunks). */ | |
5158 | if (gdbarch_in_solib_return_trampoline (gdbarch, | |
5159 | stop_pc, ecs->stop_func_name) | |
5160 | && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE) | |
5161 | { | |
5162 | /* Determine where this trampoline returns. */ | |
5163 | CORE_ADDR real_stop_pc; | |
5164 | ||
5165 | real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); | |
5166 | ||
5167 | if (debug_infrun) | |
5168 | fprintf_unfiltered (gdb_stdlog, | |
5169 | "infrun: stepped into solib return tramp\n"); | |
5170 | ||
5171 | /* Only proceed through if we know where it's going. */ | |
5172 | if (real_stop_pc) | |
5173 | { | |
5174 | /* And put the step-breakpoint there and go until there. */ | |
5175 | struct symtab_and_line sr_sal; | |
5176 | ||
5177 | init_sal (&sr_sal); /* initialize to zeroes */ | |
5178 | sr_sal.pc = real_stop_pc; | |
5179 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
5180 | sr_sal.pspace = get_frame_program_space (frame); | |
5181 | ||
5182 | /* Do not specify what the fp should be when we stop since | |
5183 | on some machines the prologue is where the new fp value | |
5184 | is established. */ | |
5185 | insert_step_resume_breakpoint_at_sal (gdbarch, | |
5186 | sr_sal, null_frame_id); | |
5187 | ||
5188 | /* Restart without fiddling with the step ranges or | |
5189 | other state. */ | |
5190 | keep_going (ecs); | |
5191 | return; | |
5192 | } | |
5193 | } | |
5194 | ||
c17eaafe DJ |
5195 | /* Check for subroutine calls. The check for the current frame |
5196 | equalling the step ID is not necessary - the check of the | |
5197 | previous frame's ID is sufficient - but it is a common case and | |
5198 | cheaper than checking the previous frame's ID. | |
14e60db5 DJ |
5199 | |
5200 | NOTE: frame_id_eq will never report two invalid frame IDs as | |
5201 | being equal, so to get into this block, both the current and | |
5202 | previous frame must have valid frame IDs. */ | |
005ca36a JB |
5203 | /* The outer_frame_id check is a heuristic to detect stepping |
5204 | through startup code. If we step over an instruction which | |
5205 | sets the stack pointer from an invalid value to a valid value, | |
5206 | we may detect that as a subroutine call from the mythical | |
5207 | "outermost" function. This could be fixed by marking | |
5208 | outermost frames as !stack_p,code_p,special_p. Then the | |
5209 | initial outermost frame, before sp was valid, would | |
ce6cca6d | 5210 | have code_addr == &_start. See the comment in frame_id_eq |
005ca36a | 5211 | for more. */ |
edb3359d | 5212 | if (!frame_id_eq (get_stack_frame_id (frame), |
16c381f0 | 5213 | ecs->event_thread->control.step_stack_frame_id) |
005ca36a | 5214 | && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()), |
16c381f0 JK |
5215 | ecs->event_thread->control.step_stack_frame_id) |
5216 | && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id, | |
005ca36a | 5217 | outer_frame_id) |
885eeb5b PA |
5218 | || (ecs->event_thread->control.step_start_function |
5219 | != find_pc_function (stop_pc))))) | |
488f131b | 5220 | { |
95918acb | 5221 | CORE_ADDR real_stop_pc; |
8fb3e588 | 5222 | |
527159b7 | 5223 | if (debug_infrun) |
8a9de0e4 | 5224 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); |
527159b7 | 5225 | |
b7a084be | 5226 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_NONE) |
95918acb AC |
5227 | { |
5228 | /* I presume that step_over_calls is only 0 when we're | |
5229 | supposed to be stepping at the assembly language level | |
5230 | ("stepi"). Just stop. */ | |
388a8562 | 5231 | /* And this works the same backward as frontward. MVS */ |
bdc36728 | 5232 | end_stepping_range (ecs); |
95918acb AC |
5233 | return; |
5234 | } | |
8fb3e588 | 5235 | |
388a8562 MS |
5236 | /* Reverse stepping through solib trampolines. */ |
5237 | ||
5238 | if (execution_direction == EXEC_REVERSE | |
16c381f0 | 5239 | && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE |
388a8562 MS |
5240 | && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) |
5241 | || (ecs->stop_func_start == 0 | |
5242 | && in_solib_dynsym_resolve_code (stop_pc)))) | |
5243 | { | |
5244 | /* Any solib trampoline code can be handled in reverse | |
5245 | by simply continuing to single-step. We have already | |
5246 | executed the solib function (backwards), and a few | |
5247 | steps will take us back through the trampoline to the | |
5248 | caller. */ | |
5249 | keep_going (ecs); | |
5250 | return; | |
5251 | } | |
5252 | ||
16c381f0 | 5253 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) |
8567c30f | 5254 | { |
b2175913 MS |
5255 | /* We're doing a "next". |
5256 | ||
5257 | Normal (forward) execution: set a breakpoint at the | |
5258 | callee's return address (the address at which the caller | |
5259 | will resume). | |
5260 | ||
5261 | Reverse (backward) execution. set the step-resume | |
5262 | breakpoint at the start of the function that we just | |
5263 | stepped into (backwards), and continue to there. When we | |
6130d0b7 | 5264 | get there, we'll need to single-step back to the caller. */ |
b2175913 MS |
5265 | |
5266 | if (execution_direction == EXEC_REVERSE) | |
5267 | { | |
acf9414f JK |
5268 | /* If we're already at the start of the function, we've either |
5269 | just stepped backward into a single instruction function, | |
5270 | or stepped back out of a signal handler to the first instruction | |
5271 | of the function. Just keep going, which will single-step back | |
5272 | to the caller. */ | |
58c48e72 | 5273 | if (ecs->stop_func_start != stop_pc && ecs->stop_func_start != 0) |
acf9414f JK |
5274 | { |
5275 | struct symtab_and_line sr_sal; | |
5276 | ||
5277 | /* Normal function call return (static or dynamic). */ | |
5278 | init_sal (&sr_sal); | |
5279 | sr_sal.pc = ecs->stop_func_start; | |
5280 | sr_sal.pspace = get_frame_program_space (frame); | |
5281 | insert_step_resume_breakpoint_at_sal (gdbarch, | |
5282 | sr_sal, null_frame_id); | |
5283 | } | |
b2175913 MS |
5284 | } |
5285 | else | |
568d6575 | 5286 | insert_step_resume_breakpoint_at_caller (frame); |
b2175913 | 5287 | |
8567c30f AC |
5288 | keep_going (ecs); |
5289 | return; | |
5290 | } | |
a53c66de | 5291 | |
95918acb | 5292 | /* If we are in a function call trampoline (a stub between the |
8fb3e588 AC |
5293 | calling routine and the real function), locate the real |
5294 | function. That's what tells us (a) whether we want to step | |
5295 | into it at all, and (b) what prologue we want to run to the | |
5296 | end of, if we do step into it. */ | |
568d6575 | 5297 | real_stop_pc = skip_language_trampoline (frame, stop_pc); |
95918acb | 5298 | if (real_stop_pc == 0) |
568d6575 | 5299 | real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); |
95918acb AC |
5300 | if (real_stop_pc != 0) |
5301 | ecs->stop_func_start = real_stop_pc; | |
8fb3e588 | 5302 | |
db5f024e | 5303 | if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc)) |
1b2bfbb9 RC |
5304 | { |
5305 | struct symtab_and_line sr_sal; | |
abbb1732 | 5306 | |
1b2bfbb9 RC |
5307 | init_sal (&sr_sal); |
5308 | sr_sal.pc = ecs->stop_func_start; | |
6c95b8df | 5309 | sr_sal.pspace = get_frame_program_space (frame); |
1b2bfbb9 | 5310 | |
a6d9a66e UW |
5311 | insert_step_resume_breakpoint_at_sal (gdbarch, |
5312 | sr_sal, null_frame_id); | |
8fb3e588 AC |
5313 | keep_going (ecs); |
5314 | return; | |
1b2bfbb9 RC |
5315 | } |
5316 | ||
95918acb | 5317 | /* If we have line number information for the function we are |
1bfeeb0f JL |
5318 | thinking of stepping into and the function isn't on the skip |
5319 | list, step into it. | |
95918acb | 5320 | |
8fb3e588 AC |
5321 | If there are several symtabs at that PC (e.g. with include |
5322 | files), just want to know whether *any* of them have line | |
5323 | numbers. find_pc_line handles this. */ | |
95918acb AC |
5324 | { |
5325 | struct symtab_and_line tmp_sal; | |
8fb3e588 | 5326 | |
95918acb | 5327 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
2b914b52 | 5328 | if (tmp_sal.line != 0 |
85817405 JK |
5329 | && !function_name_is_marked_for_skip (ecs->stop_func_name, |
5330 | &tmp_sal)) | |
95918acb | 5331 | { |
b2175913 | 5332 | if (execution_direction == EXEC_REVERSE) |
568d6575 | 5333 | handle_step_into_function_backward (gdbarch, ecs); |
b2175913 | 5334 | else |
568d6575 | 5335 | handle_step_into_function (gdbarch, ecs); |
95918acb AC |
5336 | return; |
5337 | } | |
5338 | } | |
5339 | ||
5340 | /* If we have no line number and the step-stop-if-no-debug is | |
8fb3e588 AC |
5341 | set, we stop the step so that the user has a chance to switch |
5342 | in assembly mode. */ | |
16c381f0 | 5343 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
078130d0 | 5344 | && step_stop_if_no_debug) |
95918acb | 5345 | { |
bdc36728 | 5346 | end_stepping_range (ecs); |
95918acb AC |
5347 | return; |
5348 | } | |
5349 | ||
b2175913 MS |
5350 | if (execution_direction == EXEC_REVERSE) |
5351 | { | |
acf9414f JK |
5352 | /* If we're already at the start of the function, we've either just |
5353 | stepped backward into a single instruction function without line | |
5354 | number info, or stepped back out of a signal handler to the first | |
5355 | instruction of the function without line number info. Just keep | |
5356 | going, which will single-step back to the caller. */ | |
5357 | if (ecs->stop_func_start != stop_pc) | |
5358 | { | |
5359 | /* Set a breakpoint at callee's start address. | |
5360 | From there we can step once and be back in the caller. */ | |
5361 | struct symtab_and_line sr_sal; | |
abbb1732 | 5362 | |
acf9414f JK |
5363 | init_sal (&sr_sal); |
5364 | sr_sal.pc = ecs->stop_func_start; | |
5365 | sr_sal.pspace = get_frame_program_space (frame); | |
5366 | insert_step_resume_breakpoint_at_sal (gdbarch, | |
5367 | sr_sal, null_frame_id); | |
5368 | } | |
b2175913 MS |
5369 | } |
5370 | else | |
5371 | /* Set a breakpoint at callee's return address (the address | |
5372 | at which the caller will resume). */ | |
568d6575 | 5373 | insert_step_resume_breakpoint_at_caller (frame); |
b2175913 | 5374 | |
95918acb | 5375 | keep_going (ecs); |
488f131b | 5376 | return; |
488f131b | 5377 | } |
c906108c | 5378 | |
fdd654f3 MS |
5379 | /* Reverse stepping through solib trampolines. */ |
5380 | ||
5381 | if (execution_direction == EXEC_REVERSE | |
16c381f0 | 5382 | && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE) |
fdd654f3 MS |
5383 | { |
5384 | if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) | |
5385 | || (ecs->stop_func_start == 0 | |
5386 | && in_solib_dynsym_resolve_code (stop_pc))) | |
5387 | { | |
5388 | /* Any solib trampoline code can be handled in reverse | |
5389 | by simply continuing to single-step. We have already | |
5390 | executed the solib function (backwards), and a few | |
5391 | steps will take us back through the trampoline to the | |
5392 | caller. */ | |
5393 | keep_going (ecs); | |
5394 | return; | |
5395 | } | |
5396 | else if (in_solib_dynsym_resolve_code (stop_pc)) | |
5397 | { | |
5398 | /* Stepped backward into the solib dynsym resolver. | |
5399 | Set a breakpoint at its start and continue, then | |
5400 | one more step will take us out. */ | |
5401 | struct symtab_and_line sr_sal; | |
abbb1732 | 5402 | |
fdd654f3 MS |
5403 | init_sal (&sr_sal); |
5404 | sr_sal.pc = ecs->stop_func_start; | |
9d1807c3 | 5405 | sr_sal.pspace = get_frame_program_space (frame); |
fdd654f3 MS |
5406 | insert_step_resume_breakpoint_at_sal (gdbarch, |
5407 | sr_sal, null_frame_id); | |
5408 | keep_going (ecs); | |
5409 | return; | |
5410 | } | |
5411 | } | |
5412 | ||
2afb61aa | 5413 | stop_pc_sal = find_pc_line (stop_pc, 0); |
7ed0fe66 | 5414 | |
1b2bfbb9 RC |
5415 | /* NOTE: tausq/2004-05-24: This if block used to be done before all |
5416 | the trampoline processing logic, however, there are some trampolines | |
5417 | that have no names, so we should do trampoline handling first. */ | |
16c381f0 | 5418 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
7ed0fe66 | 5419 | && ecs->stop_func_name == NULL |
2afb61aa | 5420 | && stop_pc_sal.line == 0) |
1b2bfbb9 | 5421 | { |
527159b7 | 5422 | if (debug_infrun) |
3e43a32a MS |
5423 | fprintf_unfiltered (gdb_stdlog, |
5424 | "infrun: stepped into undebuggable function\n"); | |
527159b7 | 5425 | |
1b2bfbb9 | 5426 | /* The inferior just stepped into, or returned to, an |
7ed0fe66 DJ |
5427 | undebuggable function (where there is no debugging information |
5428 | and no line number corresponding to the address where the | |
1b2bfbb9 RC |
5429 | inferior stopped). Since we want to skip this kind of code, |
5430 | we keep going until the inferior returns from this | |
14e60db5 DJ |
5431 | function - unless the user has asked us not to (via |
5432 | set step-mode) or we no longer know how to get back | |
5433 | to the call site. */ | |
5434 | if (step_stop_if_no_debug | |
c7ce8faa | 5435 | || !frame_id_p (frame_unwind_caller_id (frame))) |
1b2bfbb9 RC |
5436 | { |
5437 | /* If we have no line number and the step-stop-if-no-debug | |
5438 | is set, we stop the step so that the user has a chance to | |
5439 | switch in assembly mode. */ | |
bdc36728 | 5440 | end_stepping_range (ecs); |
1b2bfbb9 RC |
5441 | return; |
5442 | } | |
5443 | else | |
5444 | { | |
5445 | /* Set a breakpoint at callee's return address (the address | |
5446 | at which the caller will resume). */ | |
568d6575 | 5447 | insert_step_resume_breakpoint_at_caller (frame); |
1b2bfbb9 RC |
5448 | keep_going (ecs); |
5449 | return; | |
5450 | } | |
5451 | } | |
5452 | ||
16c381f0 | 5453 | if (ecs->event_thread->control.step_range_end == 1) |
1b2bfbb9 RC |
5454 | { |
5455 | /* It is stepi or nexti. We always want to stop stepping after | |
5456 | one instruction. */ | |
527159b7 | 5457 | if (debug_infrun) |
8a9de0e4 | 5458 | fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); |
bdc36728 | 5459 | end_stepping_range (ecs); |
1b2bfbb9 RC |
5460 | return; |
5461 | } | |
5462 | ||
2afb61aa | 5463 | if (stop_pc_sal.line == 0) |
488f131b JB |
5464 | { |
5465 | /* We have no line number information. That means to stop | |
5466 | stepping (does this always happen right after one instruction, | |
5467 | when we do "s" in a function with no line numbers, | |
5468 | or can this happen as a result of a return or longjmp?). */ | |
527159b7 | 5469 | if (debug_infrun) |
8a9de0e4 | 5470 | fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); |
bdc36728 | 5471 | end_stepping_range (ecs); |
488f131b JB |
5472 | return; |
5473 | } | |
c906108c | 5474 | |
edb3359d DJ |
5475 | /* Look for "calls" to inlined functions, part one. If the inline |
5476 | frame machinery detected some skipped call sites, we have entered | |
5477 | a new inline function. */ | |
5478 | ||
5479 | if (frame_id_eq (get_frame_id (get_current_frame ()), | |
16c381f0 | 5480 | ecs->event_thread->control.step_frame_id) |
edb3359d DJ |
5481 | && inline_skipped_frames (ecs->ptid)) |
5482 | { | |
5483 | struct symtab_and_line call_sal; | |
5484 | ||
5485 | if (debug_infrun) | |
5486 | fprintf_unfiltered (gdb_stdlog, | |
5487 | "infrun: stepped into inlined function\n"); | |
5488 | ||
5489 | find_frame_sal (get_current_frame (), &call_sal); | |
5490 | ||
16c381f0 | 5491 | if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL) |
edb3359d DJ |
5492 | { |
5493 | /* For "step", we're going to stop. But if the call site | |
5494 | for this inlined function is on the same source line as | |
5495 | we were previously stepping, go down into the function | |
5496 | first. Otherwise stop at the call site. */ | |
5497 | ||
5498 | if (call_sal.line == ecs->event_thread->current_line | |
5499 | && call_sal.symtab == ecs->event_thread->current_symtab) | |
5500 | step_into_inline_frame (ecs->ptid); | |
5501 | ||
bdc36728 | 5502 | end_stepping_range (ecs); |
edb3359d DJ |
5503 | return; |
5504 | } | |
5505 | else | |
5506 | { | |
5507 | /* For "next", we should stop at the call site if it is on a | |
5508 | different source line. Otherwise continue through the | |
5509 | inlined function. */ | |
5510 | if (call_sal.line == ecs->event_thread->current_line | |
5511 | && call_sal.symtab == ecs->event_thread->current_symtab) | |
5512 | keep_going (ecs); | |
5513 | else | |
bdc36728 | 5514 | end_stepping_range (ecs); |
edb3359d DJ |
5515 | return; |
5516 | } | |
5517 | } | |
5518 | ||
5519 | /* Look for "calls" to inlined functions, part two. If we are still | |
5520 | in the same real function we were stepping through, but we have | |
5521 | to go further up to find the exact frame ID, we are stepping | |
5522 | through a more inlined call beyond its call site. */ | |
5523 | ||
5524 | if (get_frame_type (get_current_frame ()) == INLINE_FRAME | |
5525 | && !frame_id_eq (get_frame_id (get_current_frame ()), | |
16c381f0 | 5526 | ecs->event_thread->control.step_frame_id) |
edb3359d | 5527 | && stepped_in_from (get_current_frame (), |
16c381f0 | 5528 | ecs->event_thread->control.step_frame_id)) |
edb3359d DJ |
5529 | { |
5530 | if (debug_infrun) | |
5531 | fprintf_unfiltered (gdb_stdlog, | |
5532 | "infrun: stepping through inlined function\n"); | |
5533 | ||
16c381f0 | 5534 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) |
edb3359d DJ |
5535 | keep_going (ecs); |
5536 | else | |
bdc36728 | 5537 | end_stepping_range (ecs); |
edb3359d DJ |
5538 | return; |
5539 | } | |
5540 | ||
2afb61aa | 5541 | if ((stop_pc == stop_pc_sal.pc) |
4e1c45ea PA |
5542 | && (ecs->event_thread->current_line != stop_pc_sal.line |
5543 | || ecs->event_thread->current_symtab != stop_pc_sal.symtab)) | |
488f131b JB |
5544 | { |
5545 | /* We are at the start of a different line. So stop. Note that | |
5546 | we don't stop if we step into the middle of a different line. | |
5547 | That is said to make things like for (;;) statements work | |
5548 | better. */ | |
527159b7 | 5549 | if (debug_infrun) |
3e43a32a MS |
5550 | fprintf_unfiltered (gdb_stdlog, |
5551 | "infrun: stepped to a different line\n"); | |
bdc36728 | 5552 | end_stepping_range (ecs); |
488f131b JB |
5553 | return; |
5554 | } | |
c906108c | 5555 | |
488f131b | 5556 | /* We aren't done stepping. |
c906108c | 5557 | |
488f131b JB |
5558 | Optimize by setting the stepping range to the line. |
5559 | (We might not be in the original line, but if we entered a | |
5560 | new line in mid-statement, we continue stepping. This makes | |
5561 | things like for(;;) statements work better.) */ | |
c906108c | 5562 | |
16c381f0 JK |
5563 | ecs->event_thread->control.step_range_start = stop_pc_sal.pc; |
5564 | ecs->event_thread->control.step_range_end = stop_pc_sal.end; | |
c1e36e3e | 5565 | ecs->event_thread->control.may_range_step = 1; |
edb3359d | 5566 | set_step_info (frame, stop_pc_sal); |
488f131b | 5567 | |
527159b7 | 5568 | if (debug_infrun) |
8a9de0e4 | 5569 | fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); |
488f131b | 5570 | keep_going (ecs); |
104c1213 JM |
5571 | } |
5572 | ||
c447ac0b PA |
5573 | /* In all-stop mode, if we're currently stepping but have stopped in |
5574 | some other thread, we may need to switch back to the stepped | |
5575 | thread. Returns true we set the inferior running, false if we left | |
5576 | it stopped (and the event needs further processing). */ | |
5577 | ||
5578 | static int | |
5579 | switch_back_to_stepped_thread (struct execution_control_state *ecs) | |
5580 | { | |
5581 | if (!non_stop) | |
5582 | { | |
5583 | struct thread_info *tp; | |
99619bea | 5584 | struct thread_info *stepping_thread; |
483805cf | 5585 | struct thread_info *step_over; |
99619bea PA |
5586 | |
5587 | /* If any thread is blocked on some internal breakpoint, and we | |
5588 | simply need to step over that breakpoint to get it going | |
5589 | again, do that first. */ | |
5590 | ||
5591 | /* However, if we see an event for the stepping thread, then we | |
5592 | know all other threads have been moved past their breakpoints | |
5593 | already. Let the caller check whether the step is finished, | |
5594 | etc., before deciding to move it past a breakpoint. */ | |
5595 | if (ecs->event_thread->control.step_range_end != 0) | |
5596 | return 0; | |
5597 | ||
5598 | /* Check if the current thread is blocked on an incomplete | |
5599 | step-over, interrupted by a random signal. */ | |
5600 | if (ecs->event_thread->control.trap_expected | |
5601 | && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP) | |
c447ac0b | 5602 | { |
99619bea PA |
5603 | if (debug_infrun) |
5604 | { | |
5605 | fprintf_unfiltered (gdb_stdlog, | |
5606 | "infrun: need to finish step-over of [%s]\n", | |
5607 | target_pid_to_str (ecs->event_thread->ptid)); | |
5608 | } | |
5609 | keep_going (ecs); | |
5610 | return 1; | |
5611 | } | |
2adfaa28 | 5612 | |
99619bea PA |
5613 | /* Check if the current thread is blocked by a single-step |
5614 | breakpoint of another thread. */ | |
5615 | if (ecs->hit_singlestep_breakpoint) | |
5616 | { | |
5617 | if (debug_infrun) | |
5618 | { | |
5619 | fprintf_unfiltered (gdb_stdlog, | |
5620 | "infrun: need to step [%s] over single-step " | |
5621 | "breakpoint\n", | |
5622 | target_pid_to_str (ecs->ptid)); | |
5623 | } | |
5624 | keep_going (ecs); | |
5625 | return 1; | |
5626 | } | |
5627 | ||
483805cf PA |
5628 | /* Otherwise, we no longer expect a trap in the current thread. |
5629 | Clear the trap_expected flag before switching back -- this is | |
5630 | what keep_going does as well, if we call it. */ | |
5631 | ecs->event_thread->control.trap_expected = 0; | |
5632 | ||
70509625 PA |
5633 | /* Likewise, clear the signal if it should not be passed. */ |
5634 | if (!signal_program[ecs->event_thread->suspend.stop_signal]) | |
5635 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; | |
5636 | ||
483805cf PA |
5637 | /* If scheduler locking applies even if not stepping, there's no |
5638 | need to walk over threads. Above we've checked whether the | |
5639 | current thread is stepping. If some other thread not the | |
5640 | event thread is stepping, then it must be that scheduler | |
5641 | locking is not in effect. */ | |
856e7dd6 | 5642 | if (schedlock_applies (ecs->event_thread)) |
483805cf PA |
5643 | return 0; |
5644 | ||
5645 | /* Look for the stepping/nexting thread, and check if any other | |
5646 | thread other than the stepping thread needs to start a | |
5647 | step-over. Do all step-overs before actually proceeding with | |
5648 | step/next/etc. */ | |
5649 | stepping_thread = NULL; | |
5650 | step_over = NULL; | |
034f788c | 5651 | ALL_NON_EXITED_THREADS (tp) |
483805cf PA |
5652 | { |
5653 | /* Ignore threads of processes we're not resuming. */ | |
5654 | if (!sched_multi | |
5655 | && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid)) | |
5656 | continue; | |
5657 | ||
5658 | /* When stepping over a breakpoint, we lock all threads | |
5659 | except the one that needs to move past the breakpoint. | |
5660 | If a non-event thread has this set, the "incomplete | |
5661 | step-over" check above should have caught it earlier. */ | |
5662 | gdb_assert (!tp->control.trap_expected); | |
5663 | ||
5664 | /* Did we find the stepping thread? */ | |
5665 | if (tp->control.step_range_end) | |
5666 | { | |
5667 | /* Yep. There should only one though. */ | |
5668 | gdb_assert (stepping_thread == NULL); | |
5669 | ||
5670 | /* The event thread is handled at the top, before we | |
5671 | enter this loop. */ | |
5672 | gdb_assert (tp != ecs->event_thread); | |
5673 | ||
5674 | /* If some thread other than the event thread is | |
5675 | stepping, then scheduler locking can't be in effect, | |
5676 | otherwise we wouldn't have resumed the current event | |
5677 | thread in the first place. */ | |
856e7dd6 | 5678 | gdb_assert (!schedlock_applies (tp)); |
483805cf PA |
5679 | |
5680 | stepping_thread = tp; | |
5681 | } | |
5682 | else if (thread_still_needs_step_over (tp)) | |
5683 | { | |
5684 | step_over = tp; | |
5685 | ||
5686 | /* At the top we've returned early if the event thread | |
5687 | is stepping. If some other thread not the event | |
5688 | thread is stepping, then scheduler locking can't be | |
5689 | in effect, and we can resume this thread. No need to | |
5690 | keep looking for the stepping thread then. */ | |
5691 | break; | |
5692 | } | |
5693 | } | |
99619bea | 5694 | |
483805cf | 5695 | if (step_over != NULL) |
99619bea | 5696 | { |
483805cf | 5697 | tp = step_over; |
99619bea | 5698 | if (debug_infrun) |
c447ac0b | 5699 | { |
99619bea PA |
5700 | fprintf_unfiltered (gdb_stdlog, |
5701 | "infrun: need to step-over [%s]\n", | |
5702 | target_pid_to_str (tp->ptid)); | |
c447ac0b PA |
5703 | } |
5704 | ||
483805cf | 5705 | /* Only the stepping thread should have this set. */ |
99619bea PA |
5706 | gdb_assert (tp->control.step_range_end == 0); |
5707 | ||
99619bea PA |
5708 | ecs->ptid = tp->ptid; |
5709 | ecs->event_thread = tp; | |
5710 | switch_to_thread (ecs->ptid); | |
5711 | keep_going (ecs); | |
5712 | return 1; | |
5713 | } | |
5714 | ||
483805cf | 5715 | if (stepping_thread != NULL) |
99619bea PA |
5716 | { |
5717 | struct frame_info *frame; | |
5718 | struct gdbarch *gdbarch; | |
5719 | ||
483805cf PA |
5720 | tp = stepping_thread; |
5721 | ||
c447ac0b PA |
5722 | /* If the stepping thread exited, then don't try to switch |
5723 | back and resume it, which could fail in several different | |
5724 | ways depending on the target. Instead, just keep going. | |
5725 | ||
5726 | We can find a stepping dead thread in the thread list in | |
5727 | two cases: | |
5728 | ||
5729 | - The target supports thread exit events, and when the | |
5730 | target tries to delete the thread from the thread list, | |
5731 | inferior_ptid pointed at the exiting thread. In such | |
5732 | case, calling delete_thread does not really remove the | |
5733 | thread from the list; instead, the thread is left listed, | |
5734 | with 'exited' state. | |
5735 | ||
5736 | - The target's debug interface does not support thread | |
5737 | exit events, and so we have no idea whatsoever if the | |
5738 | previously stepping thread is still alive. For that | |
5739 | reason, we need to synchronously query the target | |
5740 | now. */ | |
5741 | if (is_exited (tp->ptid) | |
5742 | || !target_thread_alive (tp->ptid)) | |
5743 | { | |
5744 | if (debug_infrun) | |
5745 | fprintf_unfiltered (gdb_stdlog, | |
5746 | "infrun: not switching back to " | |
5747 | "stepped thread, it has vanished\n"); | |
5748 | ||
5749 | delete_thread (tp->ptid); | |
5750 | keep_going (ecs); | |
5751 | return 1; | |
5752 | } | |
5753 | ||
c447ac0b PA |
5754 | if (debug_infrun) |
5755 | fprintf_unfiltered (gdb_stdlog, | |
5756 | "infrun: switching back to stepped thread\n"); | |
5757 | ||
5758 | ecs->event_thread = tp; | |
5759 | ecs->ptid = tp->ptid; | |
5760 | context_switch (ecs->ptid); | |
2adfaa28 PA |
5761 | |
5762 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); | |
5763 | frame = get_current_frame (); | |
5764 | gdbarch = get_frame_arch (frame); | |
5765 | ||
5766 | /* If the PC of the thread we were trying to single-step has | |
99619bea PA |
5767 | changed, then that thread has trapped or been signaled, |
5768 | but the event has not been reported to GDB yet. Re-poll | |
5769 | the target looking for this particular thread's event | |
5770 | (i.e. temporarily enable schedlock) by: | |
2adfaa28 PA |
5771 | |
5772 | - setting a break at the current PC | |
5773 | - resuming that particular thread, only (by setting | |
5774 | trap expected) | |
5775 | ||
5776 | This prevents us continuously moving the single-step | |
5777 | breakpoint forward, one instruction at a time, | |
5778 | overstepping. */ | |
5779 | ||
af48d08f | 5780 | if (stop_pc != tp->prev_pc) |
2adfaa28 | 5781 | { |
64ce06e4 PA |
5782 | ptid_t resume_ptid; |
5783 | ||
2adfaa28 PA |
5784 | if (debug_infrun) |
5785 | fprintf_unfiltered (gdb_stdlog, | |
5786 | "infrun: expected thread advanced also\n"); | |
5787 | ||
7c16b83e PA |
5788 | /* Clear the info of the previous step-over, as it's no |
5789 | longer valid. It's what keep_going would do too, if | |
5790 | we called it. Must do this before trying to insert | |
5791 | the sss breakpoint, otherwise if we were previously | |
5792 | trying to step over this exact address in another | |
5793 | thread, the breakpoint ends up not installed. */ | |
5794 | clear_step_over_info (); | |
5795 | ||
2adfaa28 PA |
5796 | insert_single_step_breakpoint (get_frame_arch (frame), |
5797 | get_frame_address_space (frame), | |
5798 | stop_pc); | |
2adfaa28 | 5799 | |
64ce06e4 PA |
5800 | resume_ptid = user_visible_resume_ptid (tp->control.stepping_command); |
5801 | do_target_resume (resume_ptid, | |
5802 | currently_stepping (tp), GDB_SIGNAL_0); | |
2adfaa28 PA |
5803 | prepare_to_wait (ecs); |
5804 | } | |
5805 | else | |
5806 | { | |
5807 | if (debug_infrun) | |
5808 | fprintf_unfiltered (gdb_stdlog, | |
5809 | "infrun: expected thread still " | |
5810 | "hasn't advanced\n"); | |
5811 | keep_going (ecs); | |
5812 | } | |
5813 | ||
c447ac0b PA |
5814 | return 1; |
5815 | } | |
5816 | } | |
5817 | return 0; | |
5818 | } | |
5819 | ||
b3444185 | 5820 | /* Is thread TP in the middle of single-stepping? */ |
104c1213 | 5821 | |
a289b8f6 | 5822 | static int |
b3444185 | 5823 | currently_stepping (struct thread_info *tp) |
a7212384 | 5824 | { |
8358c15c JK |
5825 | return ((tp->control.step_range_end |
5826 | && tp->control.step_resume_breakpoint == NULL) | |
5827 | || tp->control.trap_expected | |
af48d08f | 5828 | || tp->stepped_breakpoint |
8358c15c | 5829 | || bpstat_should_step ()); |
a7212384 UW |
5830 | } |
5831 | ||
b2175913 MS |
5832 | /* Inferior has stepped into a subroutine call with source code that |
5833 | we should not step over. Do step to the first line of code in | |
5834 | it. */ | |
c2c6d25f JM |
5835 | |
5836 | static void | |
568d6575 UW |
5837 | handle_step_into_function (struct gdbarch *gdbarch, |
5838 | struct execution_control_state *ecs) | |
c2c6d25f | 5839 | { |
43f3e411 | 5840 | struct compunit_symtab *cust; |
2afb61aa | 5841 | struct symtab_and_line stop_func_sal, sr_sal; |
c2c6d25f | 5842 | |
7e324e48 GB |
5843 | fill_in_stop_func (gdbarch, ecs); |
5844 | ||
43f3e411 DE |
5845 | cust = find_pc_compunit_symtab (stop_pc); |
5846 | if (cust != NULL && compunit_language (cust) != language_asm) | |
568d6575 | 5847 | ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, |
b2175913 | 5848 | ecs->stop_func_start); |
c2c6d25f | 5849 | |
2afb61aa | 5850 | stop_func_sal = find_pc_line (ecs->stop_func_start, 0); |
c2c6d25f JM |
5851 | /* Use the step_resume_break to step until the end of the prologue, |
5852 | even if that involves jumps (as it seems to on the vax under | |
5853 | 4.2). */ | |
5854 | /* If the prologue ends in the middle of a source line, continue to | |
5855 | the end of that source line (if it is still within the function). | |
5856 | Otherwise, just go to end of prologue. */ | |
2afb61aa PA |
5857 | if (stop_func_sal.end |
5858 | && stop_func_sal.pc != ecs->stop_func_start | |
5859 | && stop_func_sal.end < ecs->stop_func_end) | |
5860 | ecs->stop_func_start = stop_func_sal.end; | |
c2c6d25f | 5861 | |
2dbd5e30 KB |
5862 | /* Architectures which require breakpoint adjustment might not be able |
5863 | to place a breakpoint at the computed address. If so, the test | |
5864 | ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust | |
5865 | ecs->stop_func_start to an address at which a breakpoint may be | |
5866 | legitimately placed. | |
8fb3e588 | 5867 | |
2dbd5e30 KB |
5868 | Note: kevinb/2004-01-19: On FR-V, if this adjustment is not |
5869 | made, GDB will enter an infinite loop when stepping through | |
5870 | optimized code consisting of VLIW instructions which contain | |
5871 | subinstructions corresponding to different source lines. On | |
5872 | FR-V, it's not permitted to place a breakpoint on any but the | |
5873 | first subinstruction of a VLIW instruction. When a breakpoint is | |
5874 | set, GDB will adjust the breakpoint address to the beginning of | |
5875 | the VLIW instruction. Thus, we need to make the corresponding | |
5876 | adjustment here when computing the stop address. */ | |
8fb3e588 | 5877 | |
568d6575 | 5878 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) |
2dbd5e30 KB |
5879 | { |
5880 | ecs->stop_func_start | |
568d6575 | 5881 | = gdbarch_adjust_breakpoint_address (gdbarch, |
8fb3e588 | 5882 | ecs->stop_func_start); |
2dbd5e30 KB |
5883 | } |
5884 | ||
c2c6d25f JM |
5885 | if (ecs->stop_func_start == stop_pc) |
5886 | { | |
5887 | /* We are already there: stop now. */ | |
bdc36728 | 5888 | end_stepping_range (ecs); |
c2c6d25f JM |
5889 | return; |
5890 | } | |
5891 | else | |
5892 | { | |
5893 | /* Put the step-breakpoint there and go until there. */ | |
fe39c653 | 5894 | init_sal (&sr_sal); /* initialize to zeroes */ |
c2c6d25f JM |
5895 | sr_sal.pc = ecs->stop_func_start; |
5896 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
6c95b8df | 5897 | sr_sal.pspace = get_frame_program_space (get_current_frame ()); |
44cbf7b5 | 5898 | |
c2c6d25f | 5899 | /* Do not specify what the fp should be when we stop since on |
488f131b JB |
5900 | some machines the prologue is where the new fp value is |
5901 | established. */ | |
a6d9a66e | 5902 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id); |
c2c6d25f JM |
5903 | |
5904 | /* And make sure stepping stops right away then. */ | |
16c381f0 JK |
5905 | ecs->event_thread->control.step_range_end |
5906 | = ecs->event_thread->control.step_range_start; | |
c2c6d25f JM |
5907 | } |
5908 | keep_going (ecs); | |
5909 | } | |
d4f3574e | 5910 | |
b2175913 MS |
5911 | /* Inferior has stepped backward into a subroutine call with source |
5912 | code that we should not step over. Do step to the beginning of the | |
5913 | last line of code in it. */ | |
5914 | ||
5915 | static void | |
568d6575 UW |
5916 | handle_step_into_function_backward (struct gdbarch *gdbarch, |
5917 | struct execution_control_state *ecs) | |
b2175913 | 5918 | { |
43f3e411 | 5919 | struct compunit_symtab *cust; |
167e4384 | 5920 | struct symtab_and_line stop_func_sal; |
b2175913 | 5921 | |
7e324e48 GB |
5922 | fill_in_stop_func (gdbarch, ecs); |
5923 | ||
43f3e411 DE |
5924 | cust = find_pc_compunit_symtab (stop_pc); |
5925 | if (cust != NULL && compunit_language (cust) != language_asm) | |
568d6575 | 5926 | ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, |
b2175913 MS |
5927 | ecs->stop_func_start); |
5928 | ||
5929 | stop_func_sal = find_pc_line (stop_pc, 0); | |
5930 | ||
5931 | /* OK, we're just going to keep stepping here. */ | |
5932 | if (stop_func_sal.pc == stop_pc) | |
5933 | { | |
5934 | /* We're there already. Just stop stepping now. */ | |
bdc36728 | 5935 | end_stepping_range (ecs); |
b2175913 MS |
5936 | } |
5937 | else | |
5938 | { | |
5939 | /* Else just reset the step range and keep going. | |
5940 | No step-resume breakpoint, they don't work for | |
5941 | epilogues, which can have multiple entry paths. */ | |
16c381f0 JK |
5942 | ecs->event_thread->control.step_range_start = stop_func_sal.pc; |
5943 | ecs->event_thread->control.step_range_end = stop_func_sal.end; | |
b2175913 MS |
5944 | keep_going (ecs); |
5945 | } | |
5946 | return; | |
5947 | } | |
5948 | ||
d3169d93 | 5949 | /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. |
44cbf7b5 AC |
5950 | This is used to both functions and to skip over code. */ |
5951 | ||
5952 | static void | |
2c03e5be PA |
5953 | insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch, |
5954 | struct symtab_and_line sr_sal, | |
5955 | struct frame_id sr_id, | |
5956 | enum bptype sr_type) | |
44cbf7b5 | 5957 | { |
611c83ae PA |
5958 | /* There should never be more than one step-resume or longjmp-resume |
5959 | breakpoint per thread, so we should never be setting a new | |
44cbf7b5 | 5960 | step_resume_breakpoint when one is already active. */ |
8358c15c | 5961 | gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL); |
2c03e5be | 5962 | gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume); |
d3169d93 DJ |
5963 | |
5964 | if (debug_infrun) | |
5965 | fprintf_unfiltered (gdb_stdlog, | |
5af949e3 UW |
5966 | "infrun: inserting step-resume breakpoint at %s\n", |
5967 | paddress (gdbarch, sr_sal.pc)); | |
d3169d93 | 5968 | |
8358c15c | 5969 | inferior_thread ()->control.step_resume_breakpoint |
2c03e5be PA |
5970 | = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type); |
5971 | } | |
5972 | ||
9da8c2a0 | 5973 | void |
2c03e5be PA |
5974 | insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch, |
5975 | struct symtab_and_line sr_sal, | |
5976 | struct frame_id sr_id) | |
5977 | { | |
5978 | insert_step_resume_breakpoint_at_sal_1 (gdbarch, | |
5979 | sr_sal, sr_id, | |
5980 | bp_step_resume); | |
44cbf7b5 | 5981 | } |
7ce450bd | 5982 | |
2c03e5be PA |
5983 | /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc. |
5984 | This is used to skip a potential signal handler. | |
7ce450bd | 5985 | |
14e60db5 DJ |
5986 | This is called with the interrupted function's frame. The signal |
5987 | handler, when it returns, will resume the interrupted function at | |
5988 | RETURN_FRAME.pc. */ | |
d303a6c7 AC |
5989 | |
5990 | static void | |
2c03e5be | 5991 | insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame) |
d303a6c7 AC |
5992 | { |
5993 | struct symtab_and_line sr_sal; | |
a6d9a66e | 5994 | struct gdbarch *gdbarch; |
d303a6c7 | 5995 | |
f4c1edd8 | 5996 | gdb_assert (return_frame != NULL); |
d303a6c7 AC |
5997 | init_sal (&sr_sal); /* initialize to zeros */ |
5998 | ||
a6d9a66e | 5999 | gdbarch = get_frame_arch (return_frame); |
568d6575 | 6000 | sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame)); |
d303a6c7 | 6001 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
6c95b8df | 6002 | sr_sal.pspace = get_frame_program_space (return_frame); |
d303a6c7 | 6003 | |
2c03e5be PA |
6004 | insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal, |
6005 | get_stack_frame_id (return_frame), | |
6006 | bp_hp_step_resume); | |
d303a6c7 AC |
6007 | } |
6008 | ||
2c03e5be PA |
6009 | /* Insert a "step-resume breakpoint" at the previous frame's PC. This |
6010 | is used to skip a function after stepping into it (for "next" or if | |
6011 | the called function has no debugging information). | |
14e60db5 DJ |
6012 | |
6013 | The current function has almost always been reached by single | |
6014 | stepping a call or return instruction. NEXT_FRAME belongs to the | |
6015 | current function, and the breakpoint will be set at the caller's | |
6016 | resume address. | |
6017 | ||
6018 | This is a separate function rather than reusing | |
2c03e5be | 6019 | insert_hp_step_resume_breakpoint_at_frame in order to avoid |
14e60db5 | 6020 | get_prev_frame, which may stop prematurely (see the implementation |
c7ce8faa | 6021 | of frame_unwind_caller_id for an example). */ |
14e60db5 DJ |
6022 | |
6023 | static void | |
6024 | insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) | |
6025 | { | |
6026 | struct symtab_and_line sr_sal; | |
a6d9a66e | 6027 | struct gdbarch *gdbarch; |
14e60db5 DJ |
6028 | |
6029 | /* We shouldn't have gotten here if we don't know where the call site | |
6030 | is. */ | |
c7ce8faa | 6031 | gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame))); |
14e60db5 DJ |
6032 | |
6033 | init_sal (&sr_sal); /* initialize to zeros */ | |
6034 | ||
a6d9a66e | 6035 | gdbarch = frame_unwind_caller_arch (next_frame); |
c7ce8faa DJ |
6036 | sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, |
6037 | frame_unwind_caller_pc (next_frame)); | |
14e60db5 | 6038 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
6c95b8df | 6039 | sr_sal.pspace = frame_unwind_program_space (next_frame); |
14e60db5 | 6040 | |
a6d9a66e | 6041 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, |
c7ce8faa | 6042 | frame_unwind_caller_id (next_frame)); |
14e60db5 DJ |
6043 | } |
6044 | ||
611c83ae PA |
6045 | /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a |
6046 | new breakpoint at the target of a jmp_buf. The handling of | |
6047 | longjmp-resume uses the same mechanisms used for handling | |
6048 | "step-resume" breakpoints. */ | |
6049 | ||
6050 | static void | |
a6d9a66e | 6051 | insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
611c83ae | 6052 | { |
e81a37f7 TT |
6053 | /* There should never be more than one longjmp-resume breakpoint per |
6054 | thread, so we should never be setting a new | |
611c83ae | 6055 | longjmp_resume_breakpoint when one is already active. */ |
e81a37f7 | 6056 | gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL); |
611c83ae PA |
6057 | |
6058 | if (debug_infrun) | |
6059 | fprintf_unfiltered (gdb_stdlog, | |
5af949e3 UW |
6060 | "infrun: inserting longjmp-resume breakpoint at %s\n", |
6061 | paddress (gdbarch, pc)); | |
611c83ae | 6062 | |
e81a37f7 | 6063 | inferior_thread ()->control.exception_resume_breakpoint = |
a6d9a66e | 6064 | set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume); |
611c83ae PA |
6065 | } |
6066 | ||
186c406b TT |
6067 | /* Insert an exception resume breakpoint. TP is the thread throwing |
6068 | the exception. The block B is the block of the unwinder debug hook | |
6069 | function. FRAME is the frame corresponding to the call to this | |
6070 | function. SYM is the symbol of the function argument holding the | |
6071 | target PC of the exception. */ | |
6072 | ||
6073 | static void | |
6074 | insert_exception_resume_breakpoint (struct thread_info *tp, | |
3977b71f | 6075 | const struct block *b, |
186c406b TT |
6076 | struct frame_info *frame, |
6077 | struct symbol *sym) | |
6078 | { | |
492d29ea | 6079 | TRY |
186c406b TT |
6080 | { |
6081 | struct symbol *vsym; | |
6082 | struct value *value; | |
6083 | CORE_ADDR handler; | |
6084 | struct breakpoint *bp; | |
6085 | ||
6086 | vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL); | |
6087 | value = read_var_value (vsym, frame); | |
6088 | /* If the value was optimized out, revert to the old behavior. */ | |
6089 | if (! value_optimized_out (value)) | |
6090 | { | |
6091 | handler = value_as_address (value); | |
6092 | ||
6093 | if (debug_infrun) | |
6094 | fprintf_unfiltered (gdb_stdlog, | |
6095 | "infrun: exception resume at %lx\n", | |
6096 | (unsigned long) handler); | |
6097 | ||
6098 | bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), | |
6099 | handler, bp_exception_resume); | |
c70a6932 JK |
6100 | |
6101 | /* set_momentary_breakpoint_at_pc invalidates FRAME. */ | |
6102 | frame = NULL; | |
6103 | ||
186c406b TT |
6104 | bp->thread = tp->num; |
6105 | inferior_thread ()->control.exception_resume_breakpoint = bp; | |
6106 | } | |
6107 | } | |
492d29ea PA |
6108 | CATCH (e, RETURN_MASK_ERROR) |
6109 | { | |
6110 | /* We want to ignore errors here. */ | |
6111 | } | |
6112 | END_CATCH | |
186c406b TT |
6113 | } |
6114 | ||
28106bc2 SDJ |
6115 | /* A helper for check_exception_resume that sets an |
6116 | exception-breakpoint based on a SystemTap probe. */ | |
6117 | ||
6118 | static void | |
6119 | insert_exception_resume_from_probe (struct thread_info *tp, | |
729662a5 | 6120 | const struct bound_probe *probe, |
28106bc2 SDJ |
6121 | struct frame_info *frame) |
6122 | { | |
6123 | struct value *arg_value; | |
6124 | CORE_ADDR handler; | |
6125 | struct breakpoint *bp; | |
6126 | ||
6127 | arg_value = probe_safe_evaluate_at_pc (frame, 1); | |
6128 | if (!arg_value) | |
6129 | return; | |
6130 | ||
6131 | handler = value_as_address (arg_value); | |
6132 | ||
6133 | if (debug_infrun) | |
6134 | fprintf_unfiltered (gdb_stdlog, | |
6135 | "infrun: exception resume at %s\n", | |
6bac7473 | 6136 | paddress (get_objfile_arch (probe->objfile), |
28106bc2 SDJ |
6137 | handler)); |
6138 | ||
6139 | bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), | |
6140 | handler, bp_exception_resume); | |
6141 | bp->thread = tp->num; | |
6142 | inferior_thread ()->control.exception_resume_breakpoint = bp; | |
6143 | } | |
6144 | ||
186c406b TT |
6145 | /* This is called when an exception has been intercepted. Check to |
6146 | see whether the exception's destination is of interest, and if so, | |
6147 | set an exception resume breakpoint there. */ | |
6148 | ||
6149 | static void | |
6150 | check_exception_resume (struct execution_control_state *ecs, | |
28106bc2 | 6151 | struct frame_info *frame) |
186c406b | 6152 | { |
729662a5 | 6153 | struct bound_probe probe; |
28106bc2 SDJ |
6154 | struct symbol *func; |
6155 | ||
6156 | /* First see if this exception unwinding breakpoint was set via a | |
6157 | SystemTap probe point. If so, the probe has two arguments: the | |
6158 | CFA and the HANDLER. We ignore the CFA, extract the handler, and | |
6159 | set a breakpoint there. */ | |
6bac7473 | 6160 | probe = find_probe_by_pc (get_frame_pc (frame)); |
729662a5 | 6161 | if (probe.probe) |
28106bc2 | 6162 | { |
729662a5 | 6163 | insert_exception_resume_from_probe (ecs->event_thread, &probe, frame); |
28106bc2 SDJ |
6164 | return; |
6165 | } | |
6166 | ||
6167 | func = get_frame_function (frame); | |
6168 | if (!func) | |
6169 | return; | |
186c406b | 6170 | |
492d29ea | 6171 | TRY |
186c406b | 6172 | { |
3977b71f | 6173 | const struct block *b; |
8157b174 | 6174 | struct block_iterator iter; |
186c406b TT |
6175 | struct symbol *sym; |
6176 | int argno = 0; | |
6177 | ||
6178 | /* The exception breakpoint is a thread-specific breakpoint on | |
6179 | the unwinder's debug hook, declared as: | |
6180 | ||
6181 | void _Unwind_DebugHook (void *cfa, void *handler); | |
6182 | ||
6183 | The CFA argument indicates the frame to which control is | |
6184 | about to be transferred. HANDLER is the destination PC. | |
6185 | ||
6186 | We ignore the CFA and set a temporary breakpoint at HANDLER. | |
6187 | This is not extremely efficient but it avoids issues in gdb | |
6188 | with computing the DWARF CFA, and it also works even in weird | |
6189 | cases such as throwing an exception from inside a signal | |
6190 | handler. */ | |
6191 | ||
6192 | b = SYMBOL_BLOCK_VALUE (func); | |
6193 | ALL_BLOCK_SYMBOLS (b, iter, sym) | |
6194 | { | |
6195 | if (!SYMBOL_IS_ARGUMENT (sym)) | |
6196 | continue; | |
6197 | ||
6198 | if (argno == 0) | |
6199 | ++argno; | |
6200 | else | |
6201 | { | |
6202 | insert_exception_resume_breakpoint (ecs->event_thread, | |
6203 | b, frame, sym); | |
6204 | break; | |
6205 | } | |
6206 | } | |
6207 | } | |
492d29ea PA |
6208 | CATCH (e, RETURN_MASK_ERROR) |
6209 | { | |
6210 | } | |
6211 | END_CATCH | |
186c406b TT |
6212 | } |
6213 | ||
104c1213 | 6214 | static void |
22bcd14b | 6215 | stop_waiting (struct execution_control_state *ecs) |
104c1213 | 6216 | { |
527159b7 | 6217 | if (debug_infrun) |
22bcd14b | 6218 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_waiting\n"); |
527159b7 | 6219 | |
31e77af2 PA |
6220 | clear_step_over_info (); |
6221 | ||
cd0fc7c3 SS |
6222 | /* Let callers know we don't want to wait for the inferior anymore. */ |
6223 | ecs->wait_some_more = 0; | |
6224 | } | |
6225 | ||
a9ba6bae PA |
6226 | /* Called when we should continue running the inferior, because the |
6227 | current event doesn't cause a user visible stop. This does the | |
6228 | resuming part; waiting for the next event is done elsewhere. */ | |
d4f3574e SS |
6229 | |
6230 | static void | |
6231 | keep_going (struct execution_control_state *ecs) | |
6232 | { | |
c4dbc9af PA |
6233 | /* Make sure normal_stop is called if we get a QUIT handled before |
6234 | reaching resume. */ | |
6235 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); | |
6236 | ||
d4f3574e | 6237 | /* Save the pc before execution, to compare with pc after stop. */ |
fb14de7b UW |
6238 | ecs->event_thread->prev_pc |
6239 | = regcache_read_pc (get_thread_regcache (ecs->ptid)); | |
d4f3574e | 6240 | |
16c381f0 | 6241 | if (ecs->event_thread->control.trap_expected |
a493e3e2 | 6242 | && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP) |
d4f3574e | 6243 | { |
a9ba6bae PA |
6244 | /* We haven't yet gotten our trap, and either: intercepted a |
6245 | non-signal event (e.g., a fork); or took a signal which we | |
6246 | are supposed to pass through to the inferior. Simply | |
6247 | continue. */ | |
c4dbc9af | 6248 | discard_cleanups (old_cleanups); |
64ce06e4 | 6249 | resume (ecs->event_thread->suspend.stop_signal); |
d4f3574e SS |
6250 | } |
6251 | else | |
6252 | { | |
31e77af2 | 6253 | struct regcache *regcache = get_current_regcache (); |
963f9c80 PA |
6254 | int remove_bp; |
6255 | int remove_wps; | |
31e77af2 | 6256 | |
d4f3574e | 6257 | /* Either the trap was not expected, but we are continuing |
a9ba6bae PA |
6258 | anyway (if we got a signal, the user asked it be passed to |
6259 | the child) | |
6260 | -- or -- | |
6261 | We got our expected trap, but decided we should resume from | |
6262 | it. | |
d4f3574e | 6263 | |
a9ba6bae | 6264 | We're going to run this baby now! |
d4f3574e | 6265 | |
c36b740a VP |
6266 | Note that insert_breakpoints won't try to re-insert |
6267 | already inserted breakpoints. Therefore, we don't | |
6268 | care if breakpoints were already inserted, or not. */ | |
a9ba6bae | 6269 | |
31e77af2 PA |
6270 | /* If we need to step over a breakpoint, and we're not using |
6271 | displaced stepping to do so, insert all breakpoints | |
6272 | (watchpoints, etc.) but the one we're stepping over, step one | |
6273 | instruction, and then re-insert the breakpoint when that step | |
6274 | is finished. */ | |
963f9c80 PA |
6275 | |
6276 | remove_bp = (ecs->hit_singlestep_breakpoint | |
6277 | || thread_still_needs_step_over (ecs->event_thread)); | |
6278 | remove_wps = (ecs->event_thread->stepping_over_watchpoint | |
6279 | && !target_have_steppable_watchpoint); | |
6280 | ||
cb71640d PA |
6281 | /* We can't use displaced stepping if we need to step past a |
6282 | watchpoint. The instruction copied to the scratch pad would | |
6283 | still trigger the watchpoint. */ | |
6284 | if (remove_bp | |
6285 | && (remove_wps | |
6286 | || !use_displaced_stepping (get_regcache_arch (regcache)))) | |
45e8c884 | 6287 | { |
31e77af2 | 6288 | set_step_over_info (get_regcache_aspace (regcache), |
963f9c80 | 6289 | regcache_read_pc (regcache), remove_wps); |
45e8c884 | 6290 | } |
963f9c80 PA |
6291 | else if (remove_wps) |
6292 | set_step_over_info (NULL, 0, remove_wps); | |
45e8c884 | 6293 | else |
31e77af2 | 6294 | clear_step_over_info (); |
abbb1732 | 6295 | |
31e77af2 | 6296 | /* Stop stepping if inserting breakpoints fails. */ |
492d29ea | 6297 | TRY |
31e77af2 PA |
6298 | { |
6299 | insert_breakpoints (); | |
6300 | } | |
492d29ea | 6301 | CATCH (e, RETURN_MASK_ERROR) |
31e77af2 PA |
6302 | { |
6303 | exception_print (gdb_stderr, e); | |
22bcd14b | 6304 | stop_waiting (ecs); |
de1fe8c8 | 6305 | discard_cleanups (old_cleanups); |
31e77af2 | 6306 | return; |
d4f3574e | 6307 | } |
492d29ea | 6308 | END_CATCH |
d4f3574e | 6309 | |
963f9c80 | 6310 | ecs->event_thread->control.trap_expected = (remove_bp || remove_wps); |
d4f3574e | 6311 | |
a9ba6bae PA |
6312 | /* Do not deliver GDB_SIGNAL_TRAP (except when the user |
6313 | explicitly specifies that such a signal should be delivered | |
6314 | to the target program). Typically, that would occur when a | |
6315 | user is debugging a target monitor on a simulator: the target | |
6316 | monitor sets a breakpoint; the simulator encounters this | |
6317 | breakpoint and halts the simulation handing control to GDB; | |
6318 | GDB, noting that the stop address doesn't map to any known | |
6319 | breakpoint, returns control back to the simulator; the | |
6320 | simulator then delivers the hardware equivalent of a | |
6321 | GDB_SIGNAL_TRAP to the program being debugged. */ | |
a493e3e2 | 6322 | if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP |
16c381f0 | 6323 | && !signal_program[ecs->event_thread->suspend.stop_signal]) |
a493e3e2 | 6324 | ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; |
d4f3574e | 6325 | |
c4dbc9af | 6326 | discard_cleanups (old_cleanups); |
64ce06e4 | 6327 | resume (ecs->event_thread->suspend.stop_signal); |
d4f3574e SS |
6328 | } |
6329 | ||
488f131b | 6330 | prepare_to_wait (ecs); |
d4f3574e SS |
6331 | } |
6332 | ||
104c1213 JM |
6333 | /* This function normally comes after a resume, before |
6334 | handle_inferior_event exits. It takes care of any last bits of | |
6335 | housekeeping, and sets the all-important wait_some_more flag. */ | |
cd0fc7c3 | 6336 | |
104c1213 JM |
6337 | static void |
6338 | prepare_to_wait (struct execution_control_state *ecs) | |
cd0fc7c3 | 6339 | { |
527159b7 | 6340 | if (debug_infrun) |
8a9de0e4 | 6341 | fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); |
104c1213 | 6342 | |
104c1213 JM |
6343 | /* This is the old end of the while loop. Let everybody know we |
6344 | want to wait for the inferior some more and get called again | |
6345 | soon. */ | |
6346 | ecs->wait_some_more = 1; | |
c906108c | 6347 | } |
11cf8741 | 6348 | |
fd664c91 | 6349 | /* We are done with the step range of a step/next/si/ni command. |
b57bacec | 6350 | Called once for each n of a "step n" operation. */ |
fd664c91 PA |
6351 | |
6352 | static void | |
bdc36728 | 6353 | end_stepping_range (struct execution_control_state *ecs) |
fd664c91 | 6354 | { |
bdc36728 | 6355 | ecs->event_thread->control.stop_step = 1; |
bdc36728 | 6356 | stop_waiting (ecs); |
fd664c91 PA |
6357 | } |
6358 | ||
33d62d64 JK |
6359 | /* Several print_*_reason functions to print why the inferior has stopped. |
6360 | We always print something when the inferior exits, or receives a signal. | |
6361 | The rest of the cases are dealt with later on in normal_stop and | |
6362 | print_it_typical. Ideally there should be a call to one of these | |
6363 | print_*_reason functions functions from handle_inferior_event each time | |
22bcd14b | 6364 | stop_waiting is called. |
33d62d64 | 6365 | |
fd664c91 PA |
6366 | Note that we don't call these directly, instead we delegate that to |
6367 | the interpreters, through observers. Interpreters then call these | |
6368 | with whatever uiout is right. */ | |
33d62d64 | 6369 | |
fd664c91 PA |
6370 | void |
6371 | print_end_stepping_range_reason (struct ui_out *uiout) | |
33d62d64 | 6372 | { |
fd664c91 | 6373 | /* For CLI-like interpreters, print nothing. */ |
33d62d64 | 6374 | |
fd664c91 PA |
6375 | if (ui_out_is_mi_like_p (uiout)) |
6376 | { | |
6377 | ui_out_field_string (uiout, "reason", | |
6378 | async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); | |
6379 | } | |
6380 | } | |
33d62d64 | 6381 | |
fd664c91 PA |
6382 | void |
6383 | print_signal_exited_reason (struct ui_out *uiout, enum gdb_signal siggnal) | |
11cf8741 | 6384 | { |
33d62d64 JK |
6385 | annotate_signalled (); |
6386 | if (ui_out_is_mi_like_p (uiout)) | |
6387 | ui_out_field_string | |
6388 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); | |
6389 | ui_out_text (uiout, "\nProgram terminated with signal "); | |
6390 | annotate_signal_name (); | |
6391 | ui_out_field_string (uiout, "signal-name", | |
2ea28649 | 6392 | gdb_signal_to_name (siggnal)); |
33d62d64 JK |
6393 | annotate_signal_name_end (); |
6394 | ui_out_text (uiout, ", "); | |
6395 | annotate_signal_string (); | |
6396 | ui_out_field_string (uiout, "signal-meaning", | |
2ea28649 | 6397 | gdb_signal_to_string (siggnal)); |
33d62d64 JK |
6398 | annotate_signal_string_end (); |
6399 | ui_out_text (uiout, ".\n"); | |
6400 | ui_out_text (uiout, "The program no longer exists.\n"); | |
6401 | } | |
6402 | ||
fd664c91 PA |
6403 | void |
6404 | print_exited_reason (struct ui_out *uiout, int exitstatus) | |
33d62d64 | 6405 | { |
fda326dd TT |
6406 | struct inferior *inf = current_inferior (); |
6407 | const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid)); | |
6408 | ||
33d62d64 JK |
6409 | annotate_exited (exitstatus); |
6410 | if (exitstatus) | |
6411 | { | |
6412 | if (ui_out_is_mi_like_p (uiout)) | |
6413 | ui_out_field_string (uiout, "reason", | |
6414 | async_reason_lookup (EXEC_ASYNC_EXITED)); | |
fda326dd TT |
6415 | ui_out_text (uiout, "[Inferior "); |
6416 | ui_out_text (uiout, plongest (inf->num)); | |
6417 | ui_out_text (uiout, " ("); | |
6418 | ui_out_text (uiout, pidstr); | |
6419 | ui_out_text (uiout, ") exited with code "); | |
33d62d64 | 6420 | ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus); |
fda326dd | 6421 | ui_out_text (uiout, "]\n"); |
33d62d64 JK |
6422 | } |
6423 | else | |
11cf8741 | 6424 | { |
9dc5e2a9 | 6425 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f | 6426 | ui_out_field_string |
33d62d64 | 6427 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); |
fda326dd TT |
6428 | ui_out_text (uiout, "[Inferior "); |
6429 | ui_out_text (uiout, plongest (inf->num)); | |
6430 | ui_out_text (uiout, " ("); | |
6431 | ui_out_text (uiout, pidstr); | |
6432 | ui_out_text (uiout, ") exited normally]\n"); | |
33d62d64 | 6433 | } |
33d62d64 JK |
6434 | } |
6435 | ||
fd664c91 PA |
6436 | void |
6437 | print_signal_received_reason (struct ui_out *uiout, enum gdb_signal siggnal) | |
33d62d64 JK |
6438 | { |
6439 | annotate_signal (); | |
6440 | ||
a493e3e2 | 6441 | if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout)) |
33d62d64 JK |
6442 | { |
6443 | struct thread_info *t = inferior_thread (); | |
6444 | ||
6445 | ui_out_text (uiout, "\n["); | |
6446 | ui_out_field_string (uiout, "thread-name", | |
6447 | target_pid_to_str (t->ptid)); | |
6448 | ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num); | |
6449 | ui_out_text (uiout, " stopped"); | |
6450 | } | |
6451 | else | |
6452 | { | |
6453 | ui_out_text (uiout, "\nProgram received signal "); | |
8b93c638 | 6454 | annotate_signal_name (); |
33d62d64 JK |
6455 | if (ui_out_is_mi_like_p (uiout)) |
6456 | ui_out_field_string | |
6457 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); | |
488f131b | 6458 | ui_out_field_string (uiout, "signal-name", |
2ea28649 | 6459 | gdb_signal_to_name (siggnal)); |
8b93c638 JM |
6460 | annotate_signal_name_end (); |
6461 | ui_out_text (uiout, ", "); | |
6462 | annotate_signal_string (); | |
488f131b | 6463 | ui_out_field_string (uiout, "signal-meaning", |
2ea28649 | 6464 | gdb_signal_to_string (siggnal)); |
8b93c638 | 6465 | annotate_signal_string_end (); |
33d62d64 JK |
6466 | } |
6467 | ui_out_text (uiout, ".\n"); | |
6468 | } | |
252fbfc8 | 6469 | |
fd664c91 PA |
6470 | void |
6471 | print_no_history_reason (struct ui_out *uiout) | |
33d62d64 | 6472 | { |
fd664c91 | 6473 | ui_out_text (uiout, "\nNo more reverse-execution history.\n"); |
11cf8741 | 6474 | } |
43ff13b4 | 6475 | |
0c7e1a46 PA |
6476 | /* Print current location without a level number, if we have changed |
6477 | functions or hit a breakpoint. Print source line if we have one. | |
6478 | bpstat_print contains the logic deciding in detail what to print, | |
6479 | based on the event(s) that just occurred. */ | |
6480 | ||
6481 | void | |
6482 | print_stop_event (struct target_waitstatus *ws) | |
6483 | { | |
6484 | int bpstat_ret; | |
6485 | int source_flag; | |
6486 | int do_frame_printing = 1; | |
6487 | struct thread_info *tp = inferior_thread (); | |
6488 | ||
6489 | bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind); | |
6490 | switch (bpstat_ret) | |
6491 | { | |
6492 | case PRINT_UNKNOWN: | |
6493 | /* FIXME: cagney/2002-12-01: Given that a frame ID does (or | |
6494 | should) carry around the function and does (or should) use | |
6495 | that when doing a frame comparison. */ | |
6496 | if (tp->control.stop_step | |
6497 | && frame_id_eq (tp->control.step_frame_id, | |
6498 | get_frame_id (get_current_frame ())) | |
885eeb5b | 6499 | && tp->control.step_start_function == find_pc_function (stop_pc)) |
0c7e1a46 PA |
6500 | { |
6501 | /* Finished step, just print source line. */ | |
6502 | source_flag = SRC_LINE; | |
6503 | } | |
6504 | else | |
6505 | { | |
6506 | /* Print location and source line. */ | |
6507 | source_flag = SRC_AND_LOC; | |
6508 | } | |
6509 | break; | |
6510 | case PRINT_SRC_AND_LOC: | |
6511 | /* Print location and source line. */ | |
6512 | source_flag = SRC_AND_LOC; | |
6513 | break; | |
6514 | case PRINT_SRC_ONLY: | |
6515 | source_flag = SRC_LINE; | |
6516 | break; | |
6517 | case PRINT_NOTHING: | |
6518 | /* Something bogus. */ | |
6519 | source_flag = SRC_LINE; | |
6520 | do_frame_printing = 0; | |
6521 | break; | |
6522 | default: | |
6523 | internal_error (__FILE__, __LINE__, _("Unknown value.")); | |
6524 | } | |
6525 | ||
6526 | /* The behavior of this routine with respect to the source | |
6527 | flag is: | |
6528 | SRC_LINE: Print only source line | |
6529 | LOCATION: Print only location | |
6530 | SRC_AND_LOC: Print location and source line. */ | |
6531 | if (do_frame_printing) | |
6532 | print_stack_frame (get_selected_frame (NULL), 0, source_flag, 1); | |
6533 | ||
6534 | /* Display the auto-display expressions. */ | |
6535 | do_displays (); | |
6536 | } | |
6537 | ||
c906108c SS |
6538 | /* Here to return control to GDB when the inferior stops for real. |
6539 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
6540 | ||
6541 | STOP_PRINT_FRAME nonzero means print the executing frame | |
6542 | (pc, function, args, file, line number and line text). | |
6543 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
6544 | attempting to insert breakpoints. */ | |
6545 | ||
6546 | void | |
96baa820 | 6547 | normal_stop (void) |
c906108c | 6548 | { |
73b65bb0 DJ |
6549 | struct target_waitstatus last; |
6550 | ptid_t last_ptid; | |
29f49a6a | 6551 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
73b65bb0 DJ |
6552 | |
6553 | get_last_target_status (&last_ptid, &last); | |
6554 | ||
29f49a6a PA |
6555 | /* If an exception is thrown from this point on, make sure to |
6556 | propagate GDB's knowledge of the executing state to the | |
6557 | frontend/user running state. A QUIT is an easy exception to see | |
6558 | here, so do this before any filtered output. */ | |
c35b1492 PA |
6559 | if (!non_stop) |
6560 | make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
6561 | else if (last.kind != TARGET_WAITKIND_SIGNALLED | |
0e5bf2a8 PA |
6562 | && last.kind != TARGET_WAITKIND_EXITED |
6563 | && last.kind != TARGET_WAITKIND_NO_RESUMED) | |
c35b1492 | 6564 | make_cleanup (finish_thread_state_cleanup, &inferior_ptid); |
29f49a6a | 6565 | |
b57bacec PA |
6566 | /* As we're presenting a stop, and potentially removing breakpoints, |
6567 | update the thread list so we can tell whether there are threads | |
6568 | running on the target. With target remote, for example, we can | |
6569 | only learn about new threads when we explicitly update the thread | |
6570 | list. Do this before notifying the interpreters about signal | |
6571 | stops, end of stepping ranges, etc., so that the "new thread" | |
6572 | output is emitted before e.g., "Program received signal FOO", | |
6573 | instead of after. */ | |
6574 | update_thread_list (); | |
6575 | ||
6576 | if (last.kind == TARGET_WAITKIND_STOPPED && stopped_by_random_signal) | |
6577 | observer_notify_signal_received (inferior_thread ()->suspend.stop_signal); | |
6578 | ||
c906108c SS |
6579 | /* As with the notification of thread events, we want to delay |
6580 | notifying the user that we've switched thread context until | |
6581 | the inferior actually stops. | |
6582 | ||
73b65bb0 DJ |
6583 | There's no point in saying anything if the inferior has exited. |
6584 | Note that SIGNALLED here means "exited with a signal", not | |
b65dc60b PA |
6585 | "received a signal". |
6586 | ||
6587 | Also skip saying anything in non-stop mode. In that mode, as we | |
6588 | don't want GDB to switch threads behind the user's back, to avoid | |
6589 | races where the user is typing a command to apply to thread x, | |
6590 | but GDB switches to thread y before the user finishes entering | |
6591 | the command, fetch_inferior_event installs a cleanup to restore | |
6592 | the current thread back to the thread the user had selected right | |
6593 | after this event is handled, so we're not really switching, only | |
6594 | informing of a stop. */ | |
4f8d22e3 PA |
6595 | if (!non_stop |
6596 | && !ptid_equal (previous_inferior_ptid, inferior_ptid) | |
73b65bb0 DJ |
6597 | && target_has_execution |
6598 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
0e5bf2a8 PA |
6599 | && last.kind != TARGET_WAITKIND_EXITED |
6600 | && last.kind != TARGET_WAITKIND_NO_RESUMED) | |
c906108c SS |
6601 | { |
6602 | target_terminal_ours_for_output (); | |
a3f17187 | 6603 | printf_filtered (_("[Switching to %s]\n"), |
c95310c6 | 6604 | target_pid_to_str (inferior_ptid)); |
b8fa951a | 6605 | annotate_thread_changed (); |
39f77062 | 6606 | previous_inferior_ptid = inferior_ptid; |
c906108c | 6607 | } |
c906108c | 6608 | |
0e5bf2a8 PA |
6609 | if (last.kind == TARGET_WAITKIND_NO_RESUMED) |
6610 | { | |
6611 | gdb_assert (sync_execution || !target_can_async_p ()); | |
6612 | ||
6613 | target_terminal_ours_for_output (); | |
6614 | printf_filtered (_("No unwaited-for children left.\n")); | |
6615 | } | |
6616 | ||
b57bacec | 6617 | /* Note: this depends on the update_thread_list call above. */ |
a25a5a45 | 6618 | if (!breakpoints_should_be_inserted_now () && target_has_execution) |
c906108c SS |
6619 | { |
6620 | if (remove_breakpoints ()) | |
6621 | { | |
6622 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6623 | printf_filtered (_("Cannot remove breakpoints because " |
6624 | "program is no longer writable.\nFurther " | |
6625 | "execution is probably impossible.\n")); | |
c906108c SS |
6626 | } |
6627 | } | |
c906108c | 6628 | |
c906108c SS |
6629 | /* If an auto-display called a function and that got a signal, |
6630 | delete that auto-display to avoid an infinite recursion. */ | |
6631 | ||
6632 | if (stopped_by_random_signal) | |
6633 | disable_current_display (); | |
6634 | ||
b57bacec | 6635 | /* Notify observers if we finished a "step"-like command, etc. */ |
af679fd0 PA |
6636 | if (target_has_execution |
6637 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
6638 | && last.kind != TARGET_WAITKIND_EXITED | |
16c381f0 | 6639 | && inferior_thread ()->control.stop_step) |
b57bacec | 6640 | { |
31cc0b80 | 6641 | /* But not if in the middle of doing a "step n" operation for |
b57bacec PA |
6642 | n > 1 */ |
6643 | if (inferior_thread ()->step_multi) | |
6644 | goto done; | |
6645 | ||
6646 | observer_notify_end_stepping_range (); | |
6647 | } | |
c906108c SS |
6648 | |
6649 | target_terminal_ours (); | |
0f641c01 | 6650 | async_enable_stdin (); |
c906108c | 6651 | |
7abfe014 DJ |
6652 | /* Set the current source location. This will also happen if we |
6653 | display the frame below, but the current SAL will be incorrect | |
6654 | during a user hook-stop function. */ | |
d729566a | 6655 | if (has_stack_frames () && !stop_stack_dummy) |
5166082f | 6656 | set_current_sal_from_frame (get_current_frame ()); |
7abfe014 | 6657 | |
251bde03 PA |
6658 | /* Let the user/frontend see the threads as stopped, but do nothing |
6659 | if the thread was running an infcall. We may be e.g., evaluating | |
6660 | a breakpoint condition. In that case, the thread had state | |
6661 | THREAD_RUNNING before the infcall, and shall remain set to | |
6662 | running, all without informing the user/frontend about state | |
6663 | transition changes. If this is actually a call command, then the | |
6664 | thread was originally already stopped, so there's no state to | |
6665 | finish either. */ | |
6666 | if (target_has_execution && inferior_thread ()->control.in_infcall) | |
6667 | discard_cleanups (old_chain); | |
6668 | else | |
6669 | do_cleanups (old_chain); | |
dd7e2d2b PA |
6670 | |
6671 | /* Look up the hook_stop and run it (CLI internally handles problem | |
6672 | of stop_command's pre-hook not existing). */ | |
6673 | if (stop_command) | |
6674 | catch_errors (hook_stop_stub, stop_command, | |
6675 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
6676 | ||
d729566a | 6677 | if (!has_stack_frames ()) |
d51fd4c8 | 6678 | goto done; |
c906108c | 6679 | |
32400beb PA |
6680 | if (last.kind == TARGET_WAITKIND_SIGNALLED |
6681 | || last.kind == TARGET_WAITKIND_EXITED) | |
6682 | goto done; | |
6683 | ||
c906108c SS |
6684 | /* Select innermost stack frame - i.e., current frame is frame 0, |
6685 | and current location is based on that. | |
6686 | Don't do this on return from a stack dummy routine, | |
1777feb0 | 6687 | or if the program has exited. */ |
c906108c SS |
6688 | |
6689 | if (!stop_stack_dummy) | |
6690 | { | |
0f7d239c | 6691 | select_frame (get_current_frame ()); |
c906108c | 6692 | |
d01a8610 AS |
6693 | /* If --batch-silent is enabled then there's no need to print the current |
6694 | source location, and to try risks causing an error message about | |
6695 | missing source files. */ | |
6696 | if (stop_print_frame && !batch_silent) | |
0c7e1a46 | 6697 | print_stop_event (&last); |
c906108c SS |
6698 | } |
6699 | ||
6700 | /* Save the function value return registers, if we care. | |
6701 | We might be about to restore their previous contents. */ | |
9da8c2a0 PA |
6702 | if (inferior_thread ()->control.proceed_to_finish |
6703 | && execution_direction != EXEC_REVERSE) | |
d5c31457 UW |
6704 | { |
6705 | /* This should not be necessary. */ | |
6706 | if (stop_registers) | |
6707 | regcache_xfree (stop_registers); | |
6708 | ||
6709 | /* NB: The copy goes through to the target picking up the value of | |
6710 | all the registers. */ | |
6711 | stop_registers = regcache_dup (get_current_regcache ()); | |
6712 | } | |
c906108c | 6713 | |
aa7d318d | 6714 | if (stop_stack_dummy == STOP_STACK_DUMMY) |
c906108c | 6715 | { |
b89667eb DE |
6716 | /* Pop the empty frame that contains the stack dummy. |
6717 | This also restores inferior state prior to the call | |
16c381f0 | 6718 | (struct infcall_suspend_state). */ |
b89667eb | 6719 | struct frame_info *frame = get_current_frame (); |
abbb1732 | 6720 | |
b89667eb DE |
6721 | gdb_assert (get_frame_type (frame) == DUMMY_FRAME); |
6722 | frame_pop (frame); | |
3e43a32a MS |
6723 | /* frame_pop() calls reinit_frame_cache as the last thing it |
6724 | does which means there's currently no selected frame. We | |
6725 | don't need to re-establish a selected frame if the dummy call | |
6726 | returns normally, that will be done by | |
6727 | restore_infcall_control_state. However, we do have to handle | |
6728 | the case where the dummy call is returning after being | |
6729 | stopped (e.g. the dummy call previously hit a breakpoint). | |
6730 | We can't know which case we have so just always re-establish | |
6731 | a selected frame here. */ | |
0f7d239c | 6732 | select_frame (get_current_frame ()); |
c906108c SS |
6733 | } |
6734 | ||
c906108c SS |
6735 | done: |
6736 | annotate_stopped (); | |
41d2bdb4 PA |
6737 | |
6738 | /* Suppress the stop observer if we're in the middle of: | |
6739 | ||
6740 | - a step n (n > 1), as there still more steps to be done. | |
6741 | ||
6742 | - a "finish" command, as the observer will be called in | |
6743 | finish_command_continuation, so it can include the inferior | |
6744 | function's return value. | |
6745 | ||
6746 | - calling an inferior function, as we pretend we inferior didn't | |
6747 | run at all. The return value of the call is handled by the | |
6748 | expression evaluator, through call_function_by_hand. */ | |
6749 | ||
6750 | if (!target_has_execution | |
6751 | || last.kind == TARGET_WAITKIND_SIGNALLED | |
6752 | || last.kind == TARGET_WAITKIND_EXITED | |
0e5bf2a8 | 6753 | || last.kind == TARGET_WAITKIND_NO_RESUMED |
2ca0b532 PA |
6754 | || (!(inferior_thread ()->step_multi |
6755 | && inferior_thread ()->control.stop_step) | |
16c381f0 JK |
6756 | && !(inferior_thread ()->control.stop_bpstat |
6757 | && inferior_thread ()->control.proceed_to_finish) | |
6758 | && !inferior_thread ()->control.in_infcall)) | |
347bddb7 PA |
6759 | { |
6760 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
16c381f0 | 6761 | observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat, |
1d33d6ba | 6762 | stop_print_frame); |
347bddb7 | 6763 | else |
1d33d6ba | 6764 | observer_notify_normal_stop (NULL, stop_print_frame); |
347bddb7 | 6765 | } |
347bddb7 | 6766 | |
48844aa6 PA |
6767 | if (target_has_execution) |
6768 | { | |
6769 | if (last.kind != TARGET_WAITKIND_SIGNALLED | |
6770 | && last.kind != TARGET_WAITKIND_EXITED) | |
6771 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
6772 | Delete any breakpoint that is to be deleted at the next stop. */ | |
16c381f0 | 6773 | breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat); |
94cc34af | 6774 | } |
6c95b8df PA |
6775 | |
6776 | /* Try to get rid of automatically added inferiors that are no | |
6777 | longer needed. Keeping those around slows down things linearly. | |
6778 | Note that this never removes the current inferior. */ | |
6779 | prune_inferiors (); | |
c906108c SS |
6780 | } |
6781 | ||
6782 | static int | |
96baa820 | 6783 | hook_stop_stub (void *cmd) |
c906108c | 6784 | { |
5913bcb0 | 6785 | execute_cmd_pre_hook ((struct cmd_list_element *) cmd); |
c906108c SS |
6786 | return (0); |
6787 | } | |
6788 | \f | |
c5aa993b | 6789 | int |
96baa820 | 6790 | signal_stop_state (int signo) |
c906108c | 6791 | { |
d6b48e9c | 6792 | return signal_stop[signo]; |
c906108c SS |
6793 | } |
6794 | ||
c5aa993b | 6795 | int |
96baa820 | 6796 | signal_print_state (int signo) |
c906108c SS |
6797 | { |
6798 | return signal_print[signo]; | |
6799 | } | |
6800 | ||
c5aa993b | 6801 | int |
96baa820 | 6802 | signal_pass_state (int signo) |
c906108c SS |
6803 | { |
6804 | return signal_program[signo]; | |
6805 | } | |
6806 | ||
2455069d UW |
6807 | static void |
6808 | signal_cache_update (int signo) | |
6809 | { | |
6810 | if (signo == -1) | |
6811 | { | |
a493e3e2 | 6812 | for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++) |
2455069d UW |
6813 | signal_cache_update (signo); |
6814 | ||
6815 | return; | |
6816 | } | |
6817 | ||
6818 | signal_pass[signo] = (signal_stop[signo] == 0 | |
6819 | && signal_print[signo] == 0 | |
ab04a2af TT |
6820 | && signal_program[signo] == 1 |
6821 | && signal_catch[signo] == 0); | |
2455069d UW |
6822 | } |
6823 | ||
488f131b | 6824 | int |
7bda5e4a | 6825 | signal_stop_update (int signo, int state) |
d4f3574e SS |
6826 | { |
6827 | int ret = signal_stop[signo]; | |
abbb1732 | 6828 | |
d4f3574e | 6829 | signal_stop[signo] = state; |
2455069d | 6830 | signal_cache_update (signo); |
d4f3574e SS |
6831 | return ret; |
6832 | } | |
6833 | ||
488f131b | 6834 | int |
7bda5e4a | 6835 | signal_print_update (int signo, int state) |
d4f3574e SS |
6836 | { |
6837 | int ret = signal_print[signo]; | |
abbb1732 | 6838 | |
d4f3574e | 6839 | signal_print[signo] = state; |
2455069d | 6840 | signal_cache_update (signo); |
d4f3574e SS |
6841 | return ret; |
6842 | } | |
6843 | ||
488f131b | 6844 | int |
7bda5e4a | 6845 | signal_pass_update (int signo, int state) |
d4f3574e SS |
6846 | { |
6847 | int ret = signal_program[signo]; | |
abbb1732 | 6848 | |
d4f3574e | 6849 | signal_program[signo] = state; |
2455069d | 6850 | signal_cache_update (signo); |
d4f3574e SS |
6851 | return ret; |
6852 | } | |
6853 | ||
ab04a2af TT |
6854 | /* Update the global 'signal_catch' from INFO and notify the |
6855 | target. */ | |
6856 | ||
6857 | void | |
6858 | signal_catch_update (const unsigned int *info) | |
6859 | { | |
6860 | int i; | |
6861 | ||
6862 | for (i = 0; i < GDB_SIGNAL_LAST; ++i) | |
6863 | signal_catch[i] = info[i] > 0; | |
6864 | signal_cache_update (-1); | |
6865 | target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass); | |
6866 | } | |
6867 | ||
c906108c | 6868 | static void |
96baa820 | 6869 | sig_print_header (void) |
c906108c | 6870 | { |
3e43a32a MS |
6871 | printf_filtered (_("Signal Stop\tPrint\tPass " |
6872 | "to program\tDescription\n")); | |
c906108c SS |
6873 | } |
6874 | ||
6875 | static void | |
2ea28649 | 6876 | sig_print_info (enum gdb_signal oursig) |
c906108c | 6877 | { |
2ea28649 | 6878 | const char *name = gdb_signal_to_name (oursig); |
c906108c | 6879 | int name_padding = 13 - strlen (name); |
96baa820 | 6880 | |
c906108c SS |
6881 | if (name_padding <= 0) |
6882 | name_padding = 0; | |
6883 | ||
6884 | printf_filtered ("%s", name); | |
488f131b | 6885 | printf_filtered ("%*.*s ", name_padding, name_padding, " "); |
c906108c SS |
6886 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
6887 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
6888 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
2ea28649 | 6889 | printf_filtered ("%s\n", gdb_signal_to_string (oursig)); |
c906108c SS |
6890 | } |
6891 | ||
6892 | /* Specify how various signals in the inferior should be handled. */ | |
6893 | ||
6894 | static void | |
96baa820 | 6895 | handle_command (char *args, int from_tty) |
c906108c SS |
6896 | { |
6897 | char **argv; | |
6898 | int digits, wordlen; | |
6899 | int sigfirst, signum, siglast; | |
2ea28649 | 6900 | enum gdb_signal oursig; |
c906108c SS |
6901 | int allsigs; |
6902 | int nsigs; | |
6903 | unsigned char *sigs; | |
6904 | struct cleanup *old_chain; | |
6905 | ||
6906 | if (args == NULL) | |
6907 | { | |
e2e0b3e5 | 6908 | error_no_arg (_("signal to handle")); |
c906108c SS |
6909 | } |
6910 | ||
1777feb0 | 6911 | /* Allocate and zero an array of flags for which signals to handle. */ |
c906108c | 6912 | |
a493e3e2 | 6913 | nsigs = (int) GDB_SIGNAL_LAST; |
c906108c SS |
6914 | sigs = (unsigned char *) alloca (nsigs); |
6915 | memset (sigs, 0, nsigs); | |
6916 | ||
1777feb0 | 6917 | /* Break the command line up into args. */ |
c906108c | 6918 | |
d1a41061 | 6919 | argv = gdb_buildargv (args); |
7a292a7a | 6920 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
6921 | |
6922 | /* Walk through the args, looking for signal oursigs, signal names, and | |
6923 | actions. Signal numbers and signal names may be interspersed with | |
6924 | actions, with the actions being performed for all signals cumulatively | |
1777feb0 | 6925 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ |
c906108c SS |
6926 | |
6927 | while (*argv != NULL) | |
6928 | { | |
6929 | wordlen = strlen (*argv); | |
6930 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
6931 | {; | |
6932 | } | |
6933 | allsigs = 0; | |
6934 | sigfirst = siglast = -1; | |
6935 | ||
6936 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
6937 | { | |
6938 | /* Apply action to all signals except those used by the | |
1777feb0 | 6939 | debugger. Silently skip those. */ |
c906108c SS |
6940 | allsigs = 1; |
6941 | sigfirst = 0; | |
6942 | siglast = nsigs - 1; | |
6943 | } | |
6944 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
6945 | { | |
6946 | SET_SIGS (nsigs, sigs, signal_stop); | |
6947 | SET_SIGS (nsigs, sigs, signal_print); | |
6948 | } | |
6949 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
6950 | { | |
6951 | UNSET_SIGS (nsigs, sigs, signal_program); | |
6952 | } | |
6953 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
6954 | { | |
6955 | SET_SIGS (nsigs, sigs, signal_print); | |
6956 | } | |
6957 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
6958 | { | |
6959 | SET_SIGS (nsigs, sigs, signal_program); | |
6960 | } | |
6961 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
6962 | { | |
6963 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
6964 | } | |
6965 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
6966 | { | |
6967 | SET_SIGS (nsigs, sigs, signal_program); | |
6968 | } | |
6969 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
6970 | { | |
6971 | UNSET_SIGS (nsigs, sigs, signal_print); | |
6972 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
6973 | } | |
6974 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
6975 | { | |
6976 | UNSET_SIGS (nsigs, sigs, signal_program); | |
6977 | } | |
6978 | else if (digits > 0) | |
6979 | { | |
6980 | /* It is numeric. The numeric signal refers to our own | |
6981 | internal signal numbering from target.h, not to host/target | |
6982 | signal number. This is a feature; users really should be | |
6983 | using symbolic names anyway, and the common ones like | |
6984 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
6985 | ||
6986 | sigfirst = siglast = (int) | |
2ea28649 | 6987 | gdb_signal_from_command (atoi (*argv)); |
c906108c SS |
6988 | if ((*argv)[digits] == '-') |
6989 | { | |
6990 | siglast = (int) | |
2ea28649 | 6991 | gdb_signal_from_command (atoi ((*argv) + digits + 1)); |
c906108c SS |
6992 | } |
6993 | if (sigfirst > siglast) | |
6994 | { | |
1777feb0 | 6995 | /* Bet he didn't figure we'd think of this case... */ |
c906108c SS |
6996 | signum = sigfirst; |
6997 | sigfirst = siglast; | |
6998 | siglast = signum; | |
6999 | } | |
7000 | } | |
7001 | else | |
7002 | { | |
2ea28649 | 7003 | oursig = gdb_signal_from_name (*argv); |
a493e3e2 | 7004 | if (oursig != GDB_SIGNAL_UNKNOWN) |
c906108c SS |
7005 | { |
7006 | sigfirst = siglast = (int) oursig; | |
7007 | } | |
7008 | else | |
7009 | { | |
7010 | /* Not a number and not a recognized flag word => complain. */ | |
8a3fe4f8 | 7011 | error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); |
c906108c SS |
7012 | } |
7013 | } | |
7014 | ||
7015 | /* If any signal numbers or symbol names were found, set flags for | |
1777feb0 | 7016 | which signals to apply actions to. */ |
c906108c SS |
7017 | |
7018 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
7019 | { | |
2ea28649 | 7020 | switch ((enum gdb_signal) signum) |
c906108c | 7021 | { |
a493e3e2 PA |
7022 | case GDB_SIGNAL_TRAP: |
7023 | case GDB_SIGNAL_INT: | |
c906108c SS |
7024 | if (!allsigs && !sigs[signum]) |
7025 | { | |
9e2f0ad4 | 7026 | if (query (_("%s is used by the debugger.\n\ |
3e43a32a | 7027 | Are you sure you want to change it? "), |
2ea28649 | 7028 | gdb_signal_to_name ((enum gdb_signal) signum))) |
c906108c SS |
7029 | { |
7030 | sigs[signum] = 1; | |
7031 | } | |
7032 | else | |
7033 | { | |
a3f17187 | 7034 | printf_unfiltered (_("Not confirmed, unchanged.\n")); |
c906108c SS |
7035 | gdb_flush (gdb_stdout); |
7036 | } | |
7037 | } | |
7038 | break; | |
a493e3e2 PA |
7039 | case GDB_SIGNAL_0: |
7040 | case GDB_SIGNAL_DEFAULT: | |
7041 | case GDB_SIGNAL_UNKNOWN: | |
c906108c SS |
7042 | /* Make sure that "all" doesn't print these. */ |
7043 | break; | |
7044 | default: | |
7045 | sigs[signum] = 1; | |
7046 | break; | |
7047 | } | |
7048 | } | |
7049 | ||
7050 | argv++; | |
7051 | } | |
7052 | ||
3a031f65 PA |
7053 | for (signum = 0; signum < nsigs; signum++) |
7054 | if (sigs[signum]) | |
7055 | { | |
2455069d | 7056 | signal_cache_update (-1); |
a493e3e2 PA |
7057 | target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass); |
7058 | target_program_signals ((int) GDB_SIGNAL_LAST, signal_program); | |
c906108c | 7059 | |
3a031f65 PA |
7060 | if (from_tty) |
7061 | { | |
7062 | /* Show the results. */ | |
7063 | sig_print_header (); | |
7064 | for (; signum < nsigs; signum++) | |
7065 | if (sigs[signum]) | |
7066 | sig_print_info (signum); | |
7067 | } | |
7068 | ||
7069 | break; | |
7070 | } | |
c906108c SS |
7071 | |
7072 | do_cleanups (old_chain); | |
7073 | } | |
7074 | ||
de0bea00 MF |
7075 | /* Complete the "handle" command. */ |
7076 | ||
7077 | static VEC (char_ptr) * | |
7078 | handle_completer (struct cmd_list_element *ignore, | |
6f937416 | 7079 | const char *text, const char *word) |
de0bea00 MF |
7080 | { |
7081 | VEC (char_ptr) *vec_signals, *vec_keywords, *return_val; | |
7082 | static const char * const keywords[] = | |
7083 | { | |
7084 | "all", | |
7085 | "stop", | |
7086 | "ignore", | |
7087 | "print", | |
7088 | "pass", | |
7089 | "nostop", | |
7090 | "noignore", | |
7091 | "noprint", | |
7092 | "nopass", | |
7093 | NULL, | |
7094 | }; | |
7095 | ||
7096 | vec_signals = signal_completer (ignore, text, word); | |
7097 | vec_keywords = complete_on_enum (keywords, word, word); | |
7098 | ||
7099 | return_val = VEC_merge (char_ptr, vec_signals, vec_keywords); | |
7100 | VEC_free (char_ptr, vec_signals); | |
7101 | VEC_free (char_ptr, vec_keywords); | |
7102 | return return_val; | |
7103 | } | |
7104 | ||
2ea28649 PA |
7105 | enum gdb_signal |
7106 | gdb_signal_from_command (int num) | |
ed01b82c PA |
7107 | { |
7108 | if (num >= 1 && num <= 15) | |
2ea28649 | 7109 | return (enum gdb_signal) num; |
ed01b82c PA |
7110 | error (_("Only signals 1-15 are valid as numeric signals.\n\ |
7111 | Use \"info signals\" for a list of symbolic signals.")); | |
7112 | } | |
7113 | ||
c906108c SS |
7114 | /* Print current contents of the tables set by the handle command. |
7115 | It is possible we should just be printing signals actually used | |
7116 | by the current target (but for things to work right when switching | |
7117 | targets, all signals should be in the signal tables). */ | |
7118 | ||
7119 | static void | |
96baa820 | 7120 | signals_info (char *signum_exp, int from_tty) |
c906108c | 7121 | { |
2ea28649 | 7122 | enum gdb_signal oursig; |
abbb1732 | 7123 | |
c906108c SS |
7124 | sig_print_header (); |
7125 | ||
7126 | if (signum_exp) | |
7127 | { | |
7128 | /* First see if this is a symbol name. */ | |
2ea28649 | 7129 | oursig = gdb_signal_from_name (signum_exp); |
a493e3e2 | 7130 | if (oursig == GDB_SIGNAL_UNKNOWN) |
c906108c SS |
7131 | { |
7132 | /* No, try numeric. */ | |
7133 | oursig = | |
2ea28649 | 7134 | gdb_signal_from_command (parse_and_eval_long (signum_exp)); |
c906108c SS |
7135 | } |
7136 | sig_print_info (oursig); | |
7137 | return; | |
7138 | } | |
7139 | ||
7140 | printf_filtered ("\n"); | |
7141 | /* These ugly casts brought to you by the native VAX compiler. */ | |
a493e3e2 PA |
7142 | for (oursig = GDB_SIGNAL_FIRST; |
7143 | (int) oursig < (int) GDB_SIGNAL_LAST; | |
2ea28649 | 7144 | oursig = (enum gdb_signal) ((int) oursig + 1)) |
c906108c SS |
7145 | { |
7146 | QUIT; | |
7147 | ||
a493e3e2 PA |
7148 | if (oursig != GDB_SIGNAL_UNKNOWN |
7149 | && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0) | |
c906108c SS |
7150 | sig_print_info (oursig); |
7151 | } | |
7152 | ||
3e43a32a MS |
7153 | printf_filtered (_("\nUse the \"handle\" command " |
7154 | "to change these tables.\n")); | |
c906108c | 7155 | } |
4aa995e1 | 7156 | |
c709acd1 PA |
7157 | /* Check if it makes sense to read $_siginfo from the current thread |
7158 | at this point. If not, throw an error. */ | |
7159 | ||
7160 | static void | |
7161 | validate_siginfo_access (void) | |
7162 | { | |
7163 | /* No current inferior, no siginfo. */ | |
7164 | if (ptid_equal (inferior_ptid, null_ptid)) | |
7165 | error (_("No thread selected.")); | |
7166 | ||
7167 | /* Don't try to read from a dead thread. */ | |
7168 | if (is_exited (inferior_ptid)) | |
7169 | error (_("The current thread has terminated")); | |
7170 | ||
7171 | /* ... or from a spinning thread. */ | |
7172 | if (is_running (inferior_ptid)) | |
7173 | error (_("Selected thread is running.")); | |
7174 | } | |
7175 | ||
4aa995e1 PA |
7176 | /* The $_siginfo convenience variable is a bit special. We don't know |
7177 | for sure the type of the value until we actually have a chance to | |
7a9dd1b2 | 7178 | fetch the data. The type can change depending on gdbarch, so it is |
4aa995e1 PA |
7179 | also dependent on which thread you have selected. |
7180 | ||
7181 | 1. making $_siginfo be an internalvar that creates a new value on | |
7182 | access. | |
7183 | ||
7184 | 2. making the value of $_siginfo be an lval_computed value. */ | |
7185 | ||
7186 | /* This function implements the lval_computed support for reading a | |
7187 | $_siginfo value. */ | |
7188 | ||
7189 | static void | |
7190 | siginfo_value_read (struct value *v) | |
7191 | { | |
7192 | LONGEST transferred; | |
7193 | ||
c709acd1 PA |
7194 | validate_siginfo_access (); |
7195 | ||
4aa995e1 PA |
7196 | transferred = |
7197 | target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, | |
7198 | NULL, | |
7199 | value_contents_all_raw (v), | |
7200 | value_offset (v), | |
7201 | TYPE_LENGTH (value_type (v))); | |
7202 | ||
7203 | if (transferred != TYPE_LENGTH (value_type (v))) | |
7204 | error (_("Unable to read siginfo")); | |
7205 | } | |
7206 | ||
7207 | /* This function implements the lval_computed support for writing a | |
7208 | $_siginfo value. */ | |
7209 | ||
7210 | static void | |
7211 | siginfo_value_write (struct value *v, struct value *fromval) | |
7212 | { | |
7213 | LONGEST transferred; | |
7214 | ||
c709acd1 PA |
7215 | validate_siginfo_access (); |
7216 | ||
4aa995e1 PA |
7217 | transferred = target_write (¤t_target, |
7218 | TARGET_OBJECT_SIGNAL_INFO, | |
7219 | NULL, | |
7220 | value_contents_all_raw (fromval), | |
7221 | value_offset (v), | |
7222 | TYPE_LENGTH (value_type (fromval))); | |
7223 | ||
7224 | if (transferred != TYPE_LENGTH (value_type (fromval))) | |
7225 | error (_("Unable to write siginfo")); | |
7226 | } | |
7227 | ||
c8f2448a | 7228 | static const struct lval_funcs siginfo_value_funcs = |
4aa995e1 PA |
7229 | { |
7230 | siginfo_value_read, | |
7231 | siginfo_value_write | |
7232 | }; | |
7233 | ||
7234 | /* Return a new value with the correct type for the siginfo object of | |
78267919 UW |
7235 | the current thread using architecture GDBARCH. Return a void value |
7236 | if there's no object available. */ | |
4aa995e1 | 7237 | |
2c0b251b | 7238 | static struct value * |
22d2b532 SDJ |
7239 | siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var, |
7240 | void *ignore) | |
4aa995e1 | 7241 | { |
4aa995e1 | 7242 | if (target_has_stack |
78267919 UW |
7243 | && !ptid_equal (inferior_ptid, null_ptid) |
7244 | && gdbarch_get_siginfo_type_p (gdbarch)) | |
4aa995e1 | 7245 | { |
78267919 | 7246 | struct type *type = gdbarch_get_siginfo_type (gdbarch); |
abbb1732 | 7247 | |
78267919 | 7248 | return allocate_computed_value (type, &siginfo_value_funcs, NULL); |
4aa995e1 PA |
7249 | } |
7250 | ||
78267919 | 7251 | return allocate_value (builtin_type (gdbarch)->builtin_void); |
4aa995e1 PA |
7252 | } |
7253 | ||
c906108c | 7254 | \f |
16c381f0 JK |
7255 | /* infcall_suspend_state contains state about the program itself like its |
7256 | registers and any signal it received when it last stopped. | |
7257 | This state must be restored regardless of how the inferior function call | |
7258 | ends (either successfully, or after it hits a breakpoint or signal) | |
7259 | if the program is to properly continue where it left off. */ | |
7260 | ||
7261 | struct infcall_suspend_state | |
7a292a7a | 7262 | { |
16c381f0 | 7263 | struct thread_suspend_state thread_suspend; |
dd80ea3c | 7264 | #if 0 /* Currently unused and empty structures are not valid C. */ |
16c381f0 | 7265 | struct inferior_suspend_state inferior_suspend; |
dd80ea3c | 7266 | #endif |
16c381f0 JK |
7267 | |
7268 | /* Other fields: */ | |
7a292a7a | 7269 | CORE_ADDR stop_pc; |
b89667eb | 7270 | struct regcache *registers; |
1736ad11 | 7271 | |
35515841 | 7272 | /* Format of SIGINFO_DATA or NULL if it is not present. */ |
1736ad11 JK |
7273 | struct gdbarch *siginfo_gdbarch; |
7274 | ||
7275 | /* The inferior format depends on SIGINFO_GDBARCH and it has a length of | |
7276 | TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the | |
7277 | content would be invalid. */ | |
7278 | gdb_byte *siginfo_data; | |
b89667eb DE |
7279 | }; |
7280 | ||
16c381f0 JK |
7281 | struct infcall_suspend_state * |
7282 | save_infcall_suspend_state (void) | |
b89667eb | 7283 | { |
16c381f0 | 7284 | struct infcall_suspend_state *inf_state; |
b89667eb | 7285 | struct thread_info *tp = inferior_thread (); |
974a734b | 7286 | #if 0 |
16c381f0 | 7287 | struct inferior *inf = current_inferior (); |
974a734b | 7288 | #endif |
1736ad11 JK |
7289 | struct regcache *regcache = get_current_regcache (); |
7290 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
7291 | gdb_byte *siginfo_data = NULL; | |
7292 | ||
7293 | if (gdbarch_get_siginfo_type_p (gdbarch)) | |
7294 | { | |
7295 | struct type *type = gdbarch_get_siginfo_type (gdbarch); | |
7296 | size_t len = TYPE_LENGTH (type); | |
7297 | struct cleanup *back_to; | |
7298 | ||
7299 | siginfo_data = xmalloc (len); | |
7300 | back_to = make_cleanup (xfree, siginfo_data); | |
7301 | ||
7302 | if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, | |
7303 | siginfo_data, 0, len) == len) | |
7304 | discard_cleanups (back_to); | |
7305 | else | |
7306 | { | |
7307 | /* Errors ignored. */ | |
7308 | do_cleanups (back_to); | |
7309 | siginfo_data = NULL; | |
7310 | } | |
7311 | } | |
7312 | ||
41bf6aca | 7313 | inf_state = XCNEW (struct infcall_suspend_state); |
1736ad11 JK |
7314 | |
7315 | if (siginfo_data) | |
7316 | { | |
7317 | inf_state->siginfo_gdbarch = gdbarch; | |
7318 | inf_state->siginfo_data = siginfo_data; | |
7319 | } | |
b89667eb | 7320 | |
16c381f0 | 7321 | inf_state->thread_suspend = tp->suspend; |
dd80ea3c | 7322 | #if 0 /* Currently unused and empty structures are not valid C. */ |
16c381f0 | 7323 | inf_state->inferior_suspend = inf->suspend; |
dd80ea3c | 7324 | #endif |
16c381f0 | 7325 | |
35515841 | 7326 | /* run_inferior_call will not use the signal due to its `proceed' call with |
a493e3e2 PA |
7327 | GDB_SIGNAL_0 anyway. */ |
7328 | tp->suspend.stop_signal = GDB_SIGNAL_0; | |
35515841 | 7329 | |
b89667eb DE |
7330 | inf_state->stop_pc = stop_pc; |
7331 | ||
1736ad11 | 7332 | inf_state->registers = regcache_dup (regcache); |
b89667eb DE |
7333 | |
7334 | return inf_state; | |
7335 | } | |
7336 | ||
7337 | /* Restore inferior session state to INF_STATE. */ | |
7338 | ||
7339 | void | |
16c381f0 | 7340 | restore_infcall_suspend_state (struct infcall_suspend_state *inf_state) |
b89667eb DE |
7341 | { |
7342 | struct thread_info *tp = inferior_thread (); | |
974a734b | 7343 | #if 0 |
16c381f0 | 7344 | struct inferior *inf = current_inferior (); |
974a734b | 7345 | #endif |
1736ad11 JK |
7346 | struct regcache *regcache = get_current_regcache (); |
7347 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
b89667eb | 7348 | |
16c381f0 | 7349 | tp->suspend = inf_state->thread_suspend; |
dd80ea3c | 7350 | #if 0 /* Currently unused and empty structures are not valid C. */ |
16c381f0 | 7351 | inf->suspend = inf_state->inferior_suspend; |
dd80ea3c | 7352 | #endif |
16c381f0 | 7353 | |
b89667eb DE |
7354 | stop_pc = inf_state->stop_pc; |
7355 | ||
1736ad11 JK |
7356 | if (inf_state->siginfo_gdbarch == gdbarch) |
7357 | { | |
7358 | struct type *type = gdbarch_get_siginfo_type (gdbarch); | |
1736ad11 JK |
7359 | |
7360 | /* Errors ignored. */ | |
7361 | target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, | |
6acef6cd | 7362 | inf_state->siginfo_data, 0, TYPE_LENGTH (type)); |
1736ad11 JK |
7363 | } |
7364 | ||
b89667eb DE |
7365 | /* The inferior can be gone if the user types "print exit(0)" |
7366 | (and perhaps other times). */ | |
7367 | if (target_has_execution) | |
7368 | /* NB: The register write goes through to the target. */ | |
1736ad11 | 7369 | regcache_cpy (regcache, inf_state->registers); |
803b5f95 | 7370 | |
16c381f0 | 7371 | discard_infcall_suspend_state (inf_state); |
b89667eb DE |
7372 | } |
7373 | ||
7374 | static void | |
16c381f0 | 7375 | do_restore_infcall_suspend_state_cleanup (void *state) |
b89667eb | 7376 | { |
16c381f0 | 7377 | restore_infcall_suspend_state (state); |
b89667eb DE |
7378 | } |
7379 | ||
7380 | struct cleanup * | |
16c381f0 JK |
7381 | make_cleanup_restore_infcall_suspend_state |
7382 | (struct infcall_suspend_state *inf_state) | |
b89667eb | 7383 | { |
16c381f0 | 7384 | return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state); |
b89667eb DE |
7385 | } |
7386 | ||
7387 | void | |
16c381f0 | 7388 | discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) |
b89667eb DE |
7389 | { |
7390 | regcache_xfree (inf_state->registers); | |
803b5f95 | 7391 | xfree (inf_state->siginfo_data); |
b89667eb DE |
7392 | xfree (inf_state); |
7393 | } | |
7394 | ||
7395 | struct regcache * | |
16c381f0 | 7396 | get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state) |
b89667eb DE |
7397 | { |
7398 | return inf_state->registers; | |
7399 | } | |
7400 | ||
16c381f0 JK |
7401 | /* infcall_control_state contains state regarding gdb's control of the |
7402 | inferior itself like stepping control. It also contains session state like | |
7403 | the user's currently selected frame. */ | |
b89667eb | 7404 | |
16c381f0 | 7405 | struct infcall_control_state |
b89667eb | 7406 | { |
16c381f0 JK |
7407 | struct thread_control_state thread_control; |
7408 | struct inferior_control_state inferior_control; | |
d82142e2 JK |
7409 | |
7410 | /* Other fields: */ | |
7411 | enum stop_stack_kind stop_stack_dummy; | |
7412 | int stopped_by_random_signal; | |
7a292a7a | 7413 | int stop_after_trap; |
7a292a7a | 7414 | |
b89667eb | 7415 | /* ID if the selected frame when the inferior function call was made. */ |
101dcfbe | 7416 | struct frame_id selected_frame_id; |
7a292a7a SS |
7417 | }; |
7418 | ||
c906108c | 7419 | /* Save all of the information associated with the inferior<==>gdb |
b89667eb | 7420 | connection. */ |
c906108c | 7421 | |
16c381f0 JK |
7422 | struct infcall_control_state * |
7423 | save_infcall_control_state (void) | |
c906108c | 7424 | { |
16c381f0 | 7425 | struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status)); |
4e1c45ea | 7426 | struct thread_info *tp = inferior_thread (); |
d6b48e9c | 7427 | struct inferior *inf = current_inferior (); |
7a292a7a | 7428 | |
16c381f0 JK |
7429 | inf_status->thread_control = tp->control; |
7430 | inf_status->inferior_control = inf->control; | |
d82142e2 | 7431 | |
8358c15c | 7432 | tp->control.step_resume_breakpoint = NULL; |
5b79abe7 | 7433 | tp->control.exception_resume_breakpoint = NULL; |
8358c15c | 7434 | |
16c381f0 JK |
7435 | /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of |
7436 | chain. If caller's caller is walking the chain, they'll be happier if we | |
7437 | hand them back the original chain when restore_infcall_control_state is | |
7438 | called. */ | |
7439 | tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat); | |
d82142e2 JK |
7440 | |
7441 | /* Other fields: */ | |
7442 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
7443 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
7444 | inf_status->stop_after_trap = stop_after_trap; | |
c5aa993b | 7445 | |
206415a3 | 7446 | inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); |
b89667eb | 7447 | |
7a292a7a | 7448 | return inf_status; |
c906108c SS |
7449 | } |
7450 | ||
c906108c | 7451 | static int |
96baa820 | 7452 | restore_selected_frame (void *args) |
c906108c | 7453 | { |
488f131b | 7454 | struct frame_id *fid = (struct frame_id *) args; |
c906108c | 7455 | struct frame_info *frame; |
c906108c | 7456 | |
101dcfbe | 7457 | frame = frame_find_by_id (*fid); |
c906108c | 7458 | |
aa0cd9c1 AC |
7459 | /* If inf_status->selected_frame_id is NULL, there was no previously |
7460 | selected frame. */ | |
101dcfbe | 7461 | if (frame == NULL) |
c906108c | 7462 | { |
8a3fe4f8 | 7463 | warning (_("Unable to restore previously selected frame.")); |
c906108c SS |
7464 | return 0; |
7465 | } | |
7466 | ||
0f7d239c | 7467 | select_frame (frame); |
c906108c SS |
7468 | |
7469 | return (1); | |
7470 | } | |
7471 | ||
b89667eb DE |
7472 | /* Restore inferior session state to INF_STATUS. */ |
7473 | ||
c906108c | 7474 | void |
16c381f0 | 7475 | restore_infcall_control_state (struct infcall_control_state *inf_status) |
c906108c | 7476 | { |
4e1c45ea | 7477 | struct thread_info *tp = inferior_thread (); |
d6b48e9c | 7478 | struct inferior *inf = current_inferior (); |
4e1c45ea | 7479 | |
8358c15c JK |
7480 | if (tp->control.step_resume_breakpoint) |
7481 | tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop; | |
7482 | ||
5b79abe7 TT |
7483 | if (tp->control.exception_resume_breakpoint) |
7484 | tp->control.exception_resume_breakpoint->disposition | |
7485 | = disp_del_at_next_stop; | |
7486 | ||
d82142e2 | 7487 | /* Handle the bpstat_copy of the chain. */ |
16c381f0 | 7488 | bpstat_clear (&tp->control.stop_bpstat); |
d82142e2 | 7489 | |
16c381f0 JK |
7490 | tp->control = inf_status->thread_control; |
7491 | inf->control = inf_status->inferior_control; | |
d82142e2 JK |
7492 | |
7493 | /* Other fields: */ | |
7494 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
7495 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
7496 | stop_after_trap = inf_status->stop_after_trap; | |
c906108c | 7497 | |
b89667eb | 7498 | if (target_has_stack) |
c906108c | 7499 | { |
c906108c | 7500 | /* The point of catch_errors is that if the stack is clobbered, |
101dcfbe AC |
7501 | walking the stack might encounter a garbage pointer and |
7502 | error() trying to dereference it. */ | |
488f131b JB |
7503 | if (catch_errors |
7504 | (restore_selected_frame, &inf_status->selected_frame_id, | |
7505 | "Unable to restore previously selected frame:\n", | |
7506 | RETURN_MASK_ERROR) == 0) | |
c906108c SS |
7507 | /* Error in restoring the selected frame. Select the innermost |
7508 | frame. */ | |
0f7d239c | 7509 | select_frame (get_current_frame ()); |
c906108c | 7510 | } |
c906108c | 7511 | |
72cec141 | 7512 | xfree (inf_status); |
7a292a7a | 7513 | } |
c906108c | 7514 | |
74b7792f | 7515 | static void |
16c381f0 | 7516 | do_restore_infcall_control_state_cleanup (void *sts) |
74b7792f | 7517 | { |
16c381f0 | 7518 | restore_infcall_control_state (sts); |
74b7792f AC |
7519 | } |
7520 | ||
7521 | struct cleanup * | |
16c381f0 JK |
7522 | make_cleanup_restore_infcall_control_state |
7523 | (struct infcall_control_state *inf_status) | |
74b7792f | 7524 | { |
16c381f0 | 7525 | return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status); |
74b7792f AC |
7526 | } |
7527 | ||
c906108c | 7528 | void |
16c381f0 | 7529 | discard_infcall_control_state (struct infcall_control_state *inf_status) |
7a292a7a | 7530 | { |
8358c15c JK |
7531 | if (inf_status->thread_control.step_resume_breakpoint) |
7532 | inf_status->thread_control.step_resume_breakpoint->disposition | |
7533 | = disp_del_at_next_stop; | |
7534 | ||
5b79abe7 TT |
7535 | if (inf_status->thread_control.exception_resume_breakpoint) |
7536 | inf_status->thread_control.exception_resume_breakpoint->disposition | |
7537 | = disp_del_at_next_stop; | |
7538 | ||
1777feb0 | 7539 | /* See save_infcall_control_state for info on stop_bpstat. */ |
16c381f0 | 7540 | bpstat_clear (&inf_status->thread_control.stop_bpstat); |
8358c15c | 7541 | |
72cec141 | 7542 | xfree (inf_status); |
7a292a7a | 7543 | } |
b89667eb | 7544 | \f |
ca6724c1 KB |
7545 | /* restore_inferior_ptid() will be used by the cleanup machinery |
7546 | to restore the inferior_ptid value saved in a call to | |
7547 | save_inferior_ptid(). */ | |
ce696e05 KB |
7548 | |
7549 | static void | |
7550 | restore_inferior_ptid (void *arg) | |
7551 | { | |
7552 | ptid_t *saved_ptid_ptr = arg; | |
abbb1732 | 7553 | |
ce696e05 KB |
7554 | inferior_ptid = *saved_ptid_ptr; |
7555 | xfree (arg); | |
7556 | } | |
7557 | ||
7558 | /* Save the value of inferior_ptid so that it may be restored by a | |
7559 | later call to do_cleanups(). Returns the struct cleanup pointer | |
7560 | needed for later doing the cleanup. */ | |
7561 | ||
7562 | struct cleanup * | |
7563 | save_inferior_ptid (void) | |
7564 | { | |
7565 | ptid_t *saved_ptid_ptr; | |
7566 | ||
7567 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); | |
7568 | *saved_ptid_ptr = inferior_ptid; | |
7569 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); | |
7570 | } | |
0c557179 | 7571 | |
7f89fd65 | 7572 | /* See infrun.h. */ |
0c557179 SDJ |
7573 | |
7574 | void | |
7575 | clear_exit_convenience_vars (void) | |
7576 | { | |
7577 | clear_internalvar (lookup_internalvar ("_exitsignal")); | |
7578 | clear_internalvar (lookup_internalvar ("_exitcode")); | |
7579 | } | |
c5aa993b | 7580 | \f |
488f131b | 7581 | |
b2175913 MS |
7582 | /* User interface for reverse debugging: |
7583 | Set exec-direction / show exec-direction commands | |
7584 | (returns error unless target implements to_set_exec_direction method). */ | |
7585 | ||
32231432 | 7586 | int execution_direction = EXEC_FORWARD; |
b2175913 MS |
7587 | static const char exec_forward[] = "forward"; |
7588 | static const char exec_reverse[] = "reverse"; | |
7589 | static const char *exec_direction = exec_forward; | |
40478521 | 7590 | static const char *const exec_direction_names[] = { |
b2175913 MS |
7591 | exec_forward, |
7592 | exec_reverse, | |
7593 | NULL | |
7594 | }; | |
7595 | ||
7596 | static void | |
7597 | set_exec_direction_func (char *args, int from_tty, | |
7598 | struct cmd_list_element *cmd) | |
7599 | { | |
7600 | if (target_can_execute_reverse) | |
7601 | { | |
7602 | if (!strcmp (exec_direction, exec_forward)) | |
7603 | execution_direction = EXEC_FORWARD; | |
7604 | else if (!strcmp (exec_direction, exec_reverse)) | |
7605 | execution_direction = EXEC_REVERSE; | |
7606 | } | |
8bbed405 MS |
7607 | else |
7608 | { | |
7609 | exec_direction = exec_forward; | |
7610 | error (_("Target does not support this operation.")); | |
7611 | } | |
b2175913 MS |
7612 | } |
7613 | ||
7614 | static void | |
7615 | show_exec_direction_func (struct ui_file *out, int from_tty, | |
7616 | struct cmd_list_element *cmd, const char *value) | |
7617 | { | |
7618 | switch (execution_direction) { | |
7619 | case EXEC_FORWARD: | |
7620 | fprintf_filtered (out, _("Forward.\n")); | |
7621 | break; | |
7622 | case EXEC_REVERSE: | |
7623 | fprintf_filtered (out, _("Reverse.\n")); | |
7624 | break; | |
b2175913 | 7625 | default: |
d8b34453 PA |
7626 | internal_error (__FILE__, __LINE__, |
7627 | _("bogus execution_direction value: %d"), | |
7628 | (int) execution_direction); | |
b2175913 MS |
7629 | } |
7630 | } | |
7631 | ||
d4db2f36 PA |
7632 | static void |
7633 | show_schedule_multiple (struct ui_file *file, int from_tty, | |
7634 | struct cmd_list_element *c, const char *value) | |
7635 | { | |
3e43a32a MS |
7636 | fprintf_filtered (file, _("Resuming the execution of threads " |
7637 | "of all processes is %s.\n"), value); | |
d4db2f36 | 7638 | } |
ad52ddc6 | 7639 | |
22d2b532 SDJ |
7640 | /* Implementation of `siginfo' variable. */ |
7641 | ||
7642 | static const struct internalvar_funcs siginfo_funcs = | |
7643 | { | |
7644 | siginfo_make_value, | |
7645 | NULL, | |
7646 | NULL | |
7647 | }; | |
7648 | ||
c906108c | 7649 | void |
96baa820 | 7650 | _initialize_infrun (void) |
c906108c | 7651 | { |
52f0bd74 AC |
7652 | int i; |
7653 | int numsigs; | |
de0bea00 | 7654 | struct cmd_list_element *c; |
c906108c | 7655 | |
1bedd215 AC |
7656 | add_info ("signals", signals_info, _("\ |
7657 | What debugger does when program gets various signals.\n\ | |
7658 | Specify a signal as argument to print info on that signal only.")); | |
c906108c SS |
7659 | add_info_alias ("handle", "signals", 0); |
7660 | ||
de0bea00 | 7661 | c = add_com ("handle", class_run, handle_command, _("\ |
dfbd5e7b | 7662 | Specify how to handle signals.\n\ |
486c7739 | 7663 | Usage: handle SIGNAL [ACTIONS]\n\ |
c906108c | 7664 | Args are signals and actions to apply to those signals.\n\ |
dfbd5e7b | 7665 | If no actions are specified, the current settings for the specified signals\n\ |
486c7739 MF |
7666 | will be displayed instead.\n\ |
7667 | \n\ | |
c906108c SS |
7668 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ |
7669 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
7670 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
7671 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 | 7672 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
486c7739 | 7673 | \n\ |
1bedd215 | 7674 | Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ |
c906108c SS |
7675 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
7676 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
7677 | Print means print a message if this signal happens.\n\ | |
7678 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
7679 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
dfbd5e7b PA |
7680 | Pass and Stop may be combined.\n\ |
7681 | \n\ | |
7682 | Multiple signals may be specified. Signal numbers and signal names\n\ | |
7683 | may be interspersed with actions, with the actions being performed for\n\ | |
7684 | all signals cumulatively specified.")); | |
de0bea00 | 7685 | set_cmd_completer (c, handle_completer); |
486c7739 | 7686 | |
c906108c | 7687 | if (!dbx_commands) |
1a966eab AC |
7688 | stop_command = add_cmd ("stop", class_obscure, |
7689 | not_just_help_class_command, _("\ | |
7690 | There is no `stop' command, but you can set a hook on `stop'.\n\ | |
c906108c | 7691 | This allows you to set a list of commands to be run each time execution\n\ |
1a966eab | 7692 | of the program stops."), &cmdlist); |
c906108c | 7693 | |
ccce17b0 | 7694 | add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ |
85c07804 AC |
7695 | Set inferior debugging."), _("\ |
7696 | Show inferior debugging."), _("\ | |
7697 | When non-zero, inferior specific debugging is enabled."), | |
ccce17b0 YQ |
7698 | NULL, |
7699 | show_debug_infrun, | |
7700 | &setdebuglist, &showdebuglist); | |
527159b7 | 7701 | |
3e43a32a MS |
7702 | add_setshow_boolean_cmd ("displaced", class_maintenance, |
7703 | &debug_displaced, _("\ | |
237fc4c9 PA |
7704 | Set displaced stepping debugging."), _("\ |
7705 | Show displaced stepping debugging."), _("\ | |
7706 | When non-zero, displaced stepping specific debugging is enabled."), | |
7707 | NULL, | |
7708 | show_debug_displaced, | |
7709 | &setdebuglist, &showdebuglist); | |
7710 | ||
ad52ddc6 PA |
7711 | add_setshow_boolean_cmd ("non-stop", no_class, |
7712 | &non_stop_1, _("\ | |
7713 | Set whether gdb controls the inferior in non-stop mode."), _("\ | |
7714 | Show whether gdb controls the inferior in non-stop mode."), _("\ | |
7715 | When debugging a multi-threaded program and this setting is\n\ | |
7716 | off (the default, also called all-stop mode), when one thread stops\n\ | |
7717 | (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\ | |
7718 | all other threads in the program while you interact with the thread of\n\ | |
7719 | interest. When you continue or step a thread, you can allow the other\n\ | |
7720 | threads to run, or have them remain stopped, but while you inspect any\n\ | |
7721 | thread's state, all threads stop.\n\ | |
7722 | \n\ | |
7723 | In non-stop mode, when one thread stops, other threads can continue\n\ | |
7724 | to run freely. You'll be able to step each thread independently,\n\ | |
7725 | leave it stopped or free to run as needed."), | |
7726 | set_non_stop, | |
7727 | show_non_stop, | |
7728 | &setlist, | |
7729 | &showlist); | |
7730 | ||
a493e3e2 | 7731 | numsigs = (int) GDB_SIGNAL_LAST; |
488f131b | 7732 | signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); |
c906108c SS |
7733 | signal_print = (unsigned char *) |
7734 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
7735 | signal_program = (unsigned char *) | |
7736 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
ab04a2af TT |
7737 | signal_catch = (unsigned char *) |
7738 | xmalloc (sizeof (signal_catch[0]) * numsigs); | |
2455069d | 7739 | signal_pass = (unsigned char *) |
4395285e | 7740 | xmalloc (sizeof (signal_pass[0]) * numsigs); |
c906108c SS |
7741 | for (i = 0; i < numsigs; i++) |
7742 | { | |
7743 | signal_stop[i] = 1; | |
7744 | signal_print[i] = 1; | |
7745 | signal_program[i] = 1; | |
ab04a2af | 7746 | signal_catch[i] = 0; |
c906108c SS |
7747 | } |
7748 | ||
7749 | /* Signals caused by debugger's own actions | |
7750 | should not be given to the program afterwards. */ | |
a493e3e2 PA |
7751 | signal_program[GDB_SIGNAL_TRAP] = 0; |
7752 | signal_program[GDB_SIGNAL_INT] = 0; | |
c906108c SS |
7753 | |
7754 | /* Signals that are not errors should not normally enter the debugger. */ | |
a493e3e2 PA |
7755 | signal_stop[GDB_SIGNAL_ALRM] = 0; |
7756 | signal_print[GDB_SIGNAL_ALRM] = 0; | |
7757 | signal_stop[GDB_SIGNAL_VTALRM] = 0; | |
7758 | signal_print[GDB_SIGNAL_VTALRM] = 0; | |
7759 | signal_stop[GDB_SIGNAL_PROF] = 0; | |
7760 | signal_print[GDB_SIGNAL_PROF] = 0; | |
7761 | signal_stop[GDB_SIGNAL_CHLD] = 0; | |
7762 | signal_print[GDB_SIGNAL_CHLD] = 0; | |
7763 | signal_stop[GDB_SIGNAL_IO] = 0; | |
7764 | signal_print[GDB_SIGNAL_IO] = 0; | |
7765 | signal_stop[GDB_SIGNAL_POLL] = 0; | |
7766 | signal_print[GDB_SIGNAL_POLL] = 0; | |
7767 | signal_stop[GDB_SIGNAL_URG] = 0; | |
7768 | signal_print[GDB_SIGNAL_URG] = 0; | |
7769 | signal_stop[GDB_SIGNAL_WINCH] = 0; | |
7770 | signal_print[GDB_SIGNAL_WINCH] = 0; | |
7771 | signal_stop[GDB_SIGNAL_PRIO] = 0; | |
7772 | signal_print[GDB_SIGNAL_PRIO] = 0; | |
c906108c | 7773 | |
cd0fc7c3 SS |
7774 | /* These signals are used internally by user-level thread |
7775 | implementations. (See signal(5) on Solaris.) Like the above | |
7776 | signals, a healthy program receives and handles them as part of | |
7777 | its normal operation. */ | |
a493e3e2 PA |
7778 | signal_stop[GDB_SIGNAL_LWP] = 0; |
7779 | signal_print[GDB_SIGNAL_LWP] = 0; | |
7780 | signal_stop[GDB_SIGNAL_WAITING] = 0; | |
7781 | signal_print[GDB_SIGNAL_WAITING] = 0; | |
7782 | signal_stop[GDB_SIGNAL_CANCEL] = 0; | |
7783 | signal_print[GDB_SIGNAL_CANCEL] = 0; | |
cd0fc7c3 | 7784 | |
2455069d UW |
7785 | /* Update cached state. */ |
7786 | signal_cache_update (-1); | |
7787 | ||
85c07804 AC |
7788 | add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, |
7789 | &stop_on_solib_events, _("\ | |
7790 | Set stopping for shared library events."), _("\ | |
7791 | Show stopping for shared library events."), _("\ | |
c906108c SS |
7792 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
7793 | notifies gdb of shared library events. The most common event of interest\n\ | |
85c07804 | 7794 | to the user would be loading/unloading of a new library."), |
f9e14852 | 7795 | set_stop_on_solib_events, |
920d2a44 | 7796 | show_stop_on_solib_events, |
85c07804 | 7797 | &setlist, &showlist); |
c906108c | 7798 | |
7ab04401 AC |
7799 | add_setshow_enum_cmd ("follow-fork-mode", class_run, |
7800 | follow_fork_mode_kind_names, | |
7801 | &follow_fork_mode_string, _("\ | |
7802 | Set debugger response to a program call of fork or vfork."), _("\ | |
7803 | Show debugger response to a program call of fork or vfork."), _("\ | |
c906108c SS |
7804 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
7805 | parent - the original process is debugged after a fork\n\ | |
7806 | child - the new process is debugged after a fork\n\ | |
ea1dd7bc | 7807 | The unfollowed process will continue to run.\n\ |
7ab04401 AC |
7808 | By default, the debugger will follow the parent process."), |
7809 | NULL, | |
920d2a44 | 7810 | show_follow_fork_mode_string, |
7ab04401 AC |
7811 | &setlist, &showlist); |
7812 | ||
6c95b8df PA |
7813 | add_setshow_enum_cmd ("follow-exec-mode", class_run, |
7814 | follow_exec_mode_names, | |
7815 | &follow_exec_mode_string, _("\ | |
7816 | Set debugger response to a program call of exec."), _("\ | |
7817 | Show debugger response to a program call of exec."), _("\ | |
7818 | An exec call replaces the program image of a process.\n\ | |
7819 | \n\ | |
7820 | follow-exec-mode can be:\n\ | |
7821 | \n\ | |
cce7e648 | 7822 | new - the debugger creates a new inferior and rebinds the process\n\ |
6c95b8df PA |
7823 | to this new inferior. The program the process was running before\n\ |
7824 | the exec call can be restarted afterwards by restarting the original\n\ | |
7825 | inferior.\n\ | |
7826 | \n\ | |
7827 | same - the debugger keeps the process bound to the same inferior.\n\ | |
7828 | The new executable image replaces the previous executable loaded in\n\ | |
7829 | the inferior. Restarting the inferior after the exec call restarts\n\ | |
7830 | the executable the process was running after the exec call.\n\ | |
7831 | \n\ | |
7832 | By default, the debugger will use the same inferior."), | |
7833 | NULL, | |
7834 | show_follow_exec_mode_string, | |
7835 | &setlist, &showlist); | |
7836 | ||
7ab04401 AC |
7837 | add_setshow_enum_cmd ("scheduler-locking", class_run, |
7838 | scheduler_enums, &scheduler_mode, _("\ | |
7839 | Set mode for locking scheduler during execution."), _("\ | |
7840 | Show mode for locking scheduler during execution."), _("\ | |
c906108c SS |
7841 | off == no locking (threads may preempt at any time)\n\ |
7842 | on == full locking (no thread except the current thread may run)\n\ | |
856e7dd6 PA |
7843 | step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\ |
7844 | In this mode, other threads may run during other commands."), | |
7ab04401 | 7845 | set_schedlock_func, /* traps on target vector */ |
920d2a44 | 7846 | show_scheduler_mode, |
7ab04401 | 7847 | &setlist, &showlist); |
5fbbeb29 | 7848 | |
d4db2f36 PA |
7849 | add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\ |
7850 | Set mode for resuming threads of all processes."), _("\ | |
7851 | Show mode for resuming threads of all processes."), _("\ | |
7852 | When on, execution commands (such as 'continue' or 'next') resume all\n\ | |
7853 | threads of all processes. When off (which is the default), execution\n\ | |
7854 | commands only resume the threads of the current process. The set of\n\ | |
7855 | threads that are resumed is further refined by the scheduler-locking\n\ | |
7856 | mode (see help set scheduler-locking)."), | |
7857 | NULL, | |
7858 | show_schedule_multiple, | |
7859 | &setlist, &showlist); | |
7860 | ||
5bf193a2 AC |
7861 | add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ |
7862 | Set mode of the step operation."), _("\ | |
7863 | Show mode of the step operation."), _("\ | |
7864 | When set, doing a step over a function without debug line information\n\ | |
7865 | will stop at the first instruction of that function. Otherwise, the\n\ | |
7866 | function is skipped and the step command stops at a different source line."), | |
7867 | NULL, | |
920d2a44 | 7868 | show_step_stop_if_no_debug, |
5bf193a2 | 7869 | &setlist, &showlist); |
ca6724c1 | 7870 | |
72d0e2c5 YQ |
7871 | add_setshow_auto_boolean_cmd ("displaced-stepping", class_run, |
7872 | &can_use_displaced_stepping, _("\ | |
237fc4c9 PA |
7873 | Set debugger's willingness to use displaced stepping."), _("\ |
7874 | Show debugger's willingness to use displaced stepping."), _("\ | |
fff08868 HZ |
7875 | If on, gdb will use displaced stepping to step over breakpoints if it is\n\ |
7876 | supported by the target architecture. If off, gdb will not use displaced\n\ | |
7877 | stepping to step over breakpoints, even if such is supported by the target\n\ | |
7878 | architecture. If auto (which is the default), gdb will use displaced stepping\n\ | |
7879 | if the target architecture supports it and non-stop mode is active, but will not\n\ | |
7880 | use it in all-stop mode (see help set non-stop)."), | |
72d0e2c5 YQ |
7881 | NULL, |
7882 | show_can_use_displaced_stepping, | |
7883 | &setlist, &showlist); | |
237fc4c9 | 7884 | |
b2175913 MS |
7885 | add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names, |
7886 | &exec_direction, _("Set direction of execution.\n\ | |
7887 | Options are 'forward' or 'reverse'."), | |
7888 | _("Show direction of execution (forward/reverse)."), | |
7889 | _("Tells gdb whether to execute forward or backward."), | |
7890 | set_exec_direction_func, show_exec_direction_func, | |
7891 | &setlist, &showlist); | |
7892 | ||
6c95b8df PA |
7893 | /* Set/show detach-on-fork: user-settable mode. */ |
7894 | ||
7895 | add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\ | |
7896 | Set whether gdb will detach the child of a fork."), _("\ | |
7897 | Show whether gdb will detach the child of a fork."), _("\ | |
7898 | Tells gdb whether to detach the child of a fork."), | |
7899 | NULL, NULL, &setlist, &showlist); | |
7900 | ||
03583c20 UW |
7901 | /* Set/show disable address space randomization mode. */ |
7902 | ||
7903 | add_setshow_boolean_cmd ("disable-randomization", class_support, | |
7904 | &disable_randomization, _("\ | |
7905 | Set disabling of debuggee's virtual address space randomization."), _("\ | |
7906 | Show disabling of debuggee's virtual address space randomization."), _("\ | |
7907 | When this mode is on (which is the default), randomization of the virtual\n\ | |
7908 | address space is disabled. Standalone programs run with the randomization\n\ | |
7909 | enabled by default on some platforms."), | |
7910 | &set_disable_randomization, | |
7911 | &show_disable_randomization, | |
7912 | &setlist, &showlist); | |
7913 | ||
ca6724c1 | 7914 | /* ptid initializations */ |
ca6724c1 KB |
7915 | inferior_ptid = null_ptid; |
7916 | target_last_wait_ptid = minus_one_ptid; | |
5231c1fd PA |
7917 | |
7918 | observer_attach_thread_ptid_changed (infrun_thread_ptid_changed); | |
252fbfc8 | 7919 | observer_attach_thread_stop_requested (infrun_thread_stop_requested); |
a07daef3 | 7920 | observer_attach_thread_exit (infrun_thread_thread_exit); |
fc1cf338 | 7921 | observer_attach_inferior_exit (infrun_inferior_exit); |
4aa995e1 PA |
7922 | |
7923 | /* Explicitly create without lookup, since that tries to create a | |
7924 | value with a void typed value, and when we get here, gdbarch | |
7925 | isn't initialized yet. At this point, we're quite sure there | |
7926 | isn't another convenience variable of the same name. */ | |
22d2b532 | 7927 | create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL); |
d914c394 SS |
7928 | |
7929 | add_setshow_boolean_cmd ("observer", no_class, | |
7930 | &observer_mode_1, _("\ | |
7931 | Set whether gdb controls the inferior in observer mode."), _("\ | |
7932 | Show whether gdb controls the inferior in observer mode."), _("\ | |
7933 | In observer mode, GDB can get data from the inferior, but not\n\ | |
7934 | affect its execution. Registers and memory may not be changed,\n\ | |
7935 | breakpoints may not be set, and the program cannot be interrupted\n\ | |
7936 | or signalled."), | |
7937 | set_observer_mode, | |
7938 | show_observer_mode, | |
7939 | &setlist, | |
7940 | &showlist); | |
c906108c | 7941 | } |