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