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