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