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