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