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