Commit | Line | Data |
---|---|---|
ca557f44 AC |
1 | /* Target-struct-independent code to start (run) and stop an inferior |
2 | process. | |
8926118c | 3 | |
6aba47ca | 4 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 5 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
0fb0cc75 | 6 | 2008, 2009 Free Software Foundation, Inc. |
c906108c | 7 | |
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 13 | (at your option) any later version. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b | 20 | You should have received a copy of the GNU General Public License |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "gdb_string.h" | |
25 | #include <ctype.h> | |
26 | #include "symtab.h" | |
27 | #include "frame.h" | |
28 | #include "inferior.h" | |
60250e8b | 29 | #include "exceptions.h" |
c906108c | 30 | #include "breakpoint.h" |
03f2053f | 31 | #include "gdb_wait.h" |
c906108c SS |
32 | #include "gdbcore.h" |
33 | #include "gdbcmd.h" | |
210661e7 | 34 | #include "cli/cli-script.h" |
c906108c SS |
35 | #include "target.h" |
36 | #include "gdbthread.h" | |
37 | #include "annotate.h" | |
1adeb98a | 38 | #include "symfile.h" |
7a292a7a | 39 | #include "top.h" |
c906108c | 40 | #include <signal.h> |
2acceee2 | 41 | #include "inf-loop.h" |
4e052eda | 42 | #include "regcache.h" |
fd0407d6 | 43 | #include "value.h" |
06600e06 | 44 | #include "observer.h" |
f636b87d | 45 | #include "language.h" |
a77053c2 | 46 | #include "solib.h" |
f17517ea | 47 | #include "main.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" |
c906108c SS |
52 | |
53 | /* Prototypes for local functions */ | |
54 | ||
96baa820 | 55 | static void signals_info (char *, int); |
c906108c | 56 | |
96baa820 | 57 | static void handle_command (char *, int); |
c906108c | 58 | |
96baa820 | 59 | static void sig_print_info (enum target_signal); |
c906108c | 60 | |
96baa820 | 61 | static void sig_print_header (void); |
c906108c | 62 | |
74b7792f | 63 | static void resume_cleanups (void *); |
c906108c | 64 | |
96baa820 | 65 | static int hook_stop_stub (void *); |
c906108c | 66 | |
96baa820 JM |
67 | static int restore_selected_frame (void *); |
68 | ||
69 | static void build_infrun (void); | |
70 | ||
4ef3f3be | 71 | static int follow_fork (void); |
96baa820 JM |
72 | |
73 | static void set_schedlock_func (char *args, int from_tty, | |
488f131b | 74 | struct cmd_list_element *c); |
96baa820 | 75 | |
4e1c45ea | 76 | static int currently_stepping (struct thread_info *tp); |
96baa820 | 77 | |
a7212384 UW |
78 | static int currently_stepping_callback (struct thread_info *tp, void *data); |
79 | ||
96baa820 JM |
80 | static void xdb_handle_command (char *args, int from_tty); |
81 | ||
6a6b96b9 | 82 | static int prepare_to_proceed (int); |
ea67f13b | 83 | |
96baa820 | 84 | void _initialize_infrun (void); |
43ff13b4 | 85 | |
e58b0e63 PA |
86 | void nullify_last_target_wait_ptid (void); |
87 | ||
5fbbeb29 CF |
88 | /* When set, stop the 'step' command if we enter a function which has |
89 | no line number information. The normal behavior is that we step | |
90 | over such function. */ | |
91 | int step_stop_if_no_debug = 0; | |
920d2a44 AC |
92 | static void |
93 | show_step_stop_if_no_debug (struct ui_file *file, int from_tty, | |
94 | struct cmd_list_element *c, const char *value) | |
95 | { | |
96 | fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value); | |
97 | } | |
5fbbeb29 | 98 | |
43ff13b4 | 99 | /* In asynchronous mode, but simulating synchronous execution. */ |
96baa820 | 100 | |
43ff13b4 JM |
101 | int sync_execution = 0; |
102 | ||
c906108c SS |
103 | /* wait_for_inferior and normal_stop use this to notify the user |
104 | when the inferior stopped in a different thread than it had been | |
96baa820 JM |
105 | running in. */ |
106 | ||
39f77062 | 107 | static ptid_t previous_inferior_ptid; |
7a292a7a | 108 | |
237fc4c9 PA |
109 | int debug_displaced = 0; |
110 | static void | |
111 | show_debug_displaced (struct ui_file *file, int from_tty, | |
112 | struct cmd_list_element *c, const char *value) | |
113 | { | |
114 | fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value); | |
115 | } | |
116 | ||
527159b7 | 117 | static int debug_infrun = 0; |
920d2a44 AC |
118 | static void |
119 | show_debug_infrun (struct ui_file *file, int from_tty, | |
120 | struct cmd_list_element *c, const char *value) | |
121 | { | |
122 | fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); | |
123 | } | |
527159b7 | 124 | |
d4f3574e SS |
125 | /* If the program uses ELF-style shared libraries, then calls to |
126 | functions in shared libraries go through stubs, which live in a | |
127 | table called the PLT (Procedure Linkage Table). The first time the | |
128 | function is called, the stub sends control to the dynamic linker, | |
129 | which looks up the function's real address, patches the stub so | |
130 | that future calls will go directly to the function, and then passes | |
131 | control to the function. | |
132 | ||
133 | If we are stepping at the source level, we don't want to see any of | |
134 | this --- we just want to skip over the stub and the dynamic linker. | |
135 | The simple approach is to single-step until control leaves the | |
136 | dynamic linker. | |
137 | ||
ca557f44 AC |
138 | However, on some systems (e.g., Red Hat's 5.2 distribution) the |
139 | dynamic linker calls functions in the shared C library, so you | |
140 | can't tell from the PC alone whether the dynamic linker is still | |
141 | running. In this case, we use a step-resume breakpoint to get us | |
142 | past the dynamic linker, as if we were using "next" to step over a | |
143 | function call. | |
d4f3574e | 144 | |
cfd8ab24 | 145 | in_solib_dynsym_resolve_code() says whether we're in the dynamic |
d4f3574e SS |
146 | linker code or not. Normally, this means we single-step. However, |
147 | if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an | |
148 | address where we can place a step-resume breakpoint to get past the | |
149 | linker's symbol resolution function. | |
150 | ||
cfd8ab24 | 151 | in_solib_dynsym_resolve_code() can generally be implemented in a |
d4f3574e SS |
152 | pretty portable way, by comparing the PC against the address ranges |
153 | of the dynamic linker's sections. | |
154 | ||
155 | SKIP_SOLIB_RESOLVER is generally going to be system-specific, since | |
156 | it depends on internal details of the dynamic linker. It's usually | |
157 | not too hard to figure out where to put a breakpoint, but it | |
158 | certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of | |
159 | sanity checking. If it can't figure things out, returning zero and | |
160 | getting the (possibly confusing) stepping behavior is better than | |
161 | signalling an error, which will obscure the change in the | |
162 | inferior's state. */ | |
c906108c | 163 | |
c906108c SS |
164 | /* This function returns TRUE if pc is the address of an instruction |
165 | that lies within the dynamic linker (such as the event hook, or the | |
166 | dld itself). | |
167 | ||
168 | This function must be used only when a dynamic linker event has | |
169 | been caught, and the inferior is being stepped out of the hook, or | |
170 | undefined results are guaranteed. */ | |
171 | ||
172 | #ifndef SOLIB_IN_DYNAMIC_LINKER | |
173 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 | |
174 | #endif | |
175 | ||
c2c6d25f | 176 | |
7a292a7a SS |
177 | /* Convert the #defines into values. This is temporary until wfi control |
178 | flow is completely sorted out. */ | |
179 | ||
692590c1 MS |
180 | #ifndef CANNOT_STEP_HW_WATCHPOINTS |
181 | #define CANNOT_STEP_HW_WATCHPOINTS 0 | |
182 | #else | |
183 | #undef CANNOT_STEP_HW_WATCHPOINTS | |
184 | #define CANNOT_STEP_HW_WATCHPOINTS 1 | |
185 | #endif | |
186 | ||
c906108c SS |
187 | /* Tables of how to react to signals; the user sets them. */ |
188 | ||
189 | static unsigned char *signal_stop; | |
190 | static unsigned char *signal_print; | |
191 | static unsigned char *signal_program; | |
192 | ||
193 | #define SET_SIGS(nsigs,sigs,flags) \ | |
194 | do { \ | |
195 | int signum = (nsigs); \ | |
196 | while (signum-- > 0) \ | |
197 | if ((sigs)[signum]) \ | |
198 | (flags)[signum] = 1; \ | |
199 | } while (0) | |
200 | ||
201 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
202 | do { \ | |
203 | int signum = (nsigs); \ | |
204 | while (signum-- > 0) \ | |
205 | if ((sigs)[signum]) \ | |
206 | (flags)[signum] = 0; \ | |
207 | } while (0) | |
208 | ||
39f77062 KB |
209 | /* Value to pass to target_resume() to cause all threads to resume */ |
210 | ||
211 | #define RESUME_ALL (pid_to_ptid (-1)) | |
c906108c SS |
212 | |
213 | /* Command list pointer for the "stop" placeholder. */ | |
214 | ||
215 | static struct cmd_list_element *stop_command; | |
216 | ||
c906108c SS |
217 | /* Function inferior was in as of last step command. */ |
218 | ||
219 | static struct symbol *step_start_function; | |
220 | ||
c906108c SS |
221 | /* Nonzero if we want to give control to the user when we're notified |
222 | of shared library events by the dynamic linker. */ | |
223 | static int stop_on_solib_events; | |
920d2a44 AC |
224 | static void |
225 | show_stop_on_solib_events (struct ui_file *file, int from_tty, | |
226 | struct cmd_list_element *c, const char *value) | |
227 | { | |
228 | fprintf_filtered (file, _("Stopping for shared library events is %s.\n"), | |
229 | value); | |
230 | } | |
c906108c | 231 | |
c906108c SS |
232 | /* Nonzero means expecting a trace trap |
233 | and should stop the inferior and return silently when it happens. */ | |
234 | ||
235 | int stop_after_trap; | |
236 | ||
642fd101 DE |
237 | /* Save register contents here when executing a "finish" command or are |
238 | about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set. | |
c906108c SS |
239 | Thus this contains the return value from the called function (assuming |
240 | values are returned in a register). */ | |
241 | ||
72cec141 | 242 | struct regcache *stop_registers; |
c906108c | 243 | |
c906108c SS |
244 | /* Nonzero after stop if current stack frame should be printed. */ |
245 | ||
246 | static int stop_print_frame; | |
247 | ||
e02bc4cc | 248 | /* This is a cached copy of the pid/waitstatus of the last event |
9a4105ab AC |
249 | returned by target_wait()/deprecated_target_wait_hook(). This |
250 | information is returned by get_last_target_status(). */ | |
39f77062 | 251 | static ptid_t target_last_wait_ptid; |
e02bc4cc DS |
252 | static struct target_waitstatus target_last_waitstatus; |
253 | ||
0d1e5fa7 PA |
254 | static void context_switch (ptid_t ptid); |
255 | ||
4e1c45ea | 256 | void init_thread_stepping_state (struct thread_info *tss); |
0d1e5fa7 PA |
257 | |
258 | void init_infwait_state (void); | |
a474d7c2 | 259 | |
53904c9e AC |
260 | static const char follow_fork_mode_child[] = "child"; |
261 | static const char follow_fork_mode_parent[] = "parent"; | |
262 | ||
488f131b | 263 | static const char *follow_fork_mode_kind_names[] = { |
53904c9e AC |
264 | follow_fork_mode_child, |
265 | follow_fork_mode_parent, | |
266 | NULL | |
ef346e04 | 267 | }; |
c906108c | 268 | |
53904c9e | 269 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
920d2a44 AC |
270 | static void |
271 | show_follow_fork_mode_string (struct ui_file *file, int from_tty, | |
272 | struct cmd_list_element *c, const char *value) | |
273 | { | |
274 | fprintf_filtered (file, _("\ | |
275 | Debugger response to a program call of fork or vfork is \"%s\".\n"), | |
276 | value); | |
277 | } | |
c906108c SS |
278 | \f |
279 | ||
e58b0e63 PA |
280 | /* Tell the target to follow the fork we're stopped at. Returns true |
281 | if the inferior should be resumed; false, if the target for some | |
282 | reason decided it's best not to resume. */ | |
283 | ||
6604731b | 284 | static int |
4ef3f3be | 285 | follow_fork (void) |
c906108c | 286 | { |
ea1dd7bc | 287 | int follow_child = (follow_fork_mode_string == follow_fork_mode_child); |
e58b0e63 PA |
288 | int should_resume = 1; |
289 | struct thread_info *tp; | |
290 | ||
291 | /* Copy user stepping state to the new inferior thread. FIXME: the | |
292 | followed fork child thread should have a copy of most of the | |
4e3990f4 DE |
293 | parent thread structure's run control related fields, not just these. |
294 | Initialized to avoid "may be used uninitialized" warnings from gcc. */ | |
295 | struct breakpoint *step_resume_breakpoint = NULL; | |
296 | CORE_ADDR step_range_start = 0; | |
297 | CORE_ADDR step_range_end = 0; | |
298 | struct frame_id step_frame_id = { 0 }; | |
e58b0e63 PA |
299 | |
300 | if (!non_stop) | |
301 | { | |
302 | ptid_t wait_ptid; | |
303 | struct target_waitstatus wait_status; | |
304 | ||
305 | /* Get the last target status returned by target_wait(). */ | |
306 | get_last_target_status (&wait_ptid, &wait_status); | |
307 | ||
308 | /* If not stopped at a fork event, then there's nothing else to | |
309 | do. */ | |
310 | if (wait_status.kind != TARGET_WAITKIND_FORKED | |
311 | && wait_status.kind != TARGET_WAITKIND_VFORKED) | |
312 | return 1; | |
313 | ||
314 | /* Check if we switched over from WAIT_PTID, since the event was | |
315 | reported. */ | |
316 | if (!ptid_equal (wait_ptid, minus_one_ptid) | |
317 | && !ptid_equal (inferior_ptid, wait_ptid)) | |
318 | { | |
319 | /* We did. Switch back to WAIT_PTID thread, to tell the | |
320 | target to follow it (in either direction). We'll | |
321 | afterwards refuse to resume, and inform the user what | |
322 | happened. */ | |
323 | switch_to_thread (wait_ptid); | |
324 | should_resume = 0; | |
325 | } | |
326 | } | |
327 | ||
328 | tp = inferior_thread (); | |
329 | ||
330 | /* If there were any forks/vforks that were caught and are now to be | |
331 | followed, then do so now. */ | |
332 | switch (tp->pending_follow.kind) | |
333 | { | |
334 | case TARGET_WAITKIND_FORKED: | |
335 | case TARGET_WAITKIND_VFORKED: | |
336 | { | |
337 | ptid_t parent, child; | |
338 | ||
339 | /* If the user did a next/step, etc, over a fork call, | |
340 | preserve the stepping state in the fork child. */ | |
341 | if (follow_child && should_resume) | |
342 | { | |
343 | step_resume_breakpoint | |
344 | = clone_momentary_breakpoint (tp->step_resume_breakpoint); | |
345 | step_range_start = tp->step_range_start; | |
346 | step_range_end = tp->step_range_end; | |
347 | step_frame_id = tp->step_frame_id; | |
348 | ||
349 | /* For now, delete the parent's sr breakpoint, otherwise, | |
350 | parent/child sr breakpoints are considered duplicates, | |
351 | and the child version will not be installed. Remove | |
352 | this when the breakpoints module becomes aware of | |
353 | inferiors and address spaces. */ | |
354 | delete_step_resume_breakpoint (tp); | |
355 | tp->step_range_start = 0; | |
356 | tp->step_range_end = 0; | |
357 | tp->step_frame_id = null_frame_id; | |
358 | } | |
359 | ||
360 | parent = inferior_ptid; | |
361 | child = tp->pending_follow.value.related_pid; | |
362 | ||
363 | /* Tell the target to do whatever is necessary to follow | |
364 | either parent or child. */ | |
365 | if (target_follow_fork (follow_child)) | |
366 | { | |
367 | /* Target refused to follow, or there's some other reason | |
368 | we shouldn't resume. */ | |
369 | should_resume = 0; | |
370 | } | |
371 | else | |
372 | { | |
373 | /* This pending follow fork event is now handled, one way | |
374 | or another. The previous selected thread may be gone | |
375 | from the lists by now, but if it is still around, need | |
376 | to clear the pending follow request. */ | |
e09875d4 | 377 | tp = find_thread_ptid (parent); |
e58b0e63 PA |
378 | if (tp) |
379 | tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
380 | ||
381 | /* This makes sure we don't try to apply the "Switched | |
382 | over from WAIT_PID" logic above. */ | |
383 | nullify_last_target_wait_ptid (); | |
384 | ||
385 | /* If we followed the child, switch to it... */ | |
386 | if (follow_child) | |
387 | { | |
388 | switch_to_thread (child); | |
389 | ||
390 | /* ... and preserve the stepping state, in case the | |
391 | user was stepping over the fork call. */ | |
392 | if (should_resume) | |
393 | { | |
394 | tp = inferior_thread (); | |
395 | tp->step_resume_breakpoint = step_resume_breakpoint; | |
396 | tp->step_range_start = step_range_start; | |
397 | tp->step_range_end = step_range_end; | |
398 | tp->step_frame_id = step_frame_id; | |
399 | } | |
400 | else | |
401 | { | |
402 | /* If we get here, it was because we're trying to | |
403 | resume from a fork catchpoint, but, the user | |
404 | has switched threads away from the thread that | |
405 | forked. In that case, the resume command | |
406 | issued is most likely not applicable to the | |
407 | child, so just warn, and refuse to resume. */ | |
408 | warning (_("\ | |
409 | Not resuming: switched threads before following fork child.\n")); | |
410 | } | |
411 | ||
412 | /* Reset breakpoints in the child as appropriate. */ | |
413 | follow_inferior_reset_breakpoints (); | |
414 | } | |
415 | else | |
416 | switch_to_thread (parent); | |
417 | } | |
418 | } | |
419 | break; | |
420 | case TARGET_WAITKIND_SPURIOUS: | |
421 | /* Nothing to follow. */ | |
422 | break; | |
423 | default: | |
424 | internal_error (__FILE__, __LINE__, | |
425 | "Unexpected pending_follow.kind %d\n", | |
426 | tp->pending_follow.kind); | |
427 | break; | |
428 | } | |
c906108c | 429 | |
e58b0e63 | 430 | return should_resume; |
c906108c SS |
431 | } |
432 | ||
6604731b DJ |
433 | void |
434 | follow_inferior_reset_breakpoints (void) | |
c906108c | 435 | { |
4e1c45ea PA |
436 | struct thread_info *tp = inferior_thread (); |
437 | ||
6604731b DJ |
438 | /* Was there a step_resume breakpoint? (There was if the user |
439 | did a "next" at the fork() call.) If so, explicitly reset its | |
440 | thread number. | |
441 | ||
442 | step_resumes are a form of bp that are made to be per-thread. | |
443 | Since we created the step_resume bp when the parent process | |
444 | was being debugged, and now are switching to the child process, | |
445 | from the breakpoint package's viewpoint, that's a switch of | |
446 | "threads". We must update the bp's notion of which thread | |
447 | it is for, or it'll be ignored when it triggers. */ | |
448 | ||
4e1c45ea PA |
449 | if (tp->step_resume_breakpoint) |
450 | breakpoint_re_set_thread (tp->step_resume_breakpoint); | |
6604731b DJ |
451 | |
452 | /* Reinsert all breakpoints in the child. The user may have set | |
453 | breakpoints after catching the fork, in which case those | |
454 | were never set in the child, but only in the parent. This makes | |
455 | sure the inserted breakpoints match the breakpoint list. */ | |
456 | ||
457 | breakpoint_re_set (); | |
458 | insert_breakpoints (); | |
c906108c | 459 | } |
c906108c | 460 | |
1adeb98a FN |
461 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
462 | ||
c906108c | 463 | static void |
3a3e9ee3 | 464 | follow_exec (ptid_t pid, char *execd_pathname) |
c906108c | 465 | { |
7a292a7a | 466 | struct target_ops *tgt; |
4e1c45ea | 467 | struct thread_info *th = inferior_thread (); |
7a292a7a | 468 | |
c906108c SS |
469 | /* This is an exec event that we actually wish to pay attention to. |
470 | Refresh our symbol table to the newly exec'd program, remove any | |
471 | momentary bp's, etc. | |
472 | ||
473 | If there are breakpoints, they aren't really inserted now, | |
474 | since the exec() transformed our inferior into a fresh set | |
475 | of instructions. | |
476 | ||
477 | We want to preserve symbolic breakpoints on the list, since | |
478 | we have hopes that they can be reset after the new a.out's | |
479 | symbol table is read. | |
480 | ||
481 | However, any "raw" breakpoints must be removed from the list | |
482 | (e.g., the solib bp's), since their address is probably invalid | |
483 | now. | |
484 | ||
485 | And, we DON'T want to call delete_breakpoints() here, since | |
486 | that may write the bp's "shadow contents" (the instruction | |
487 | value that was overwritten witha TRAP instruction). Since | |
488 | we now have a new a.out, those shadow contents aren't valid. */ | |
489 | update_breakpoints_after_exec (); | |
490 | ||
491 | /* If there was one, it's gone now. We cannot truly step-to-next | |
492 | statement through an exec(). */ | |
4e1c45ea PA |
493 | th->step_resume_breakpoint = NULL; |
494 | th->step_range_start = 0; | |
495 | th->step_range_end = 0; | |
c906108c | 496 | |
a75724bc PA |
497 | /* The target reports the exec event to the main thread, even if |
498 | some other thread does the exec, and even if the main thread was | |
499 | already stopped --- if debugging in non-stop mode, it's possible | |
500 | the user had the main thread held stopped in the previous image | |
501 | --- release it now. This is the same behavior as step-over-exec | |
502 | with scheduler-locking on in all-stop mode. */ | |
503 | th->stop_requested = 0; | |
504 | ||
c906108c | 505 | /* What is this a.out's name? */ |
a3f17187 | 506 | printf_unfiltered (_("Executing new program: %s\n"), execd_pathname); |
c906108c SS |
507 | |
508 | /* We've followed the inferior through an exec. Therefore, the | |
509 | inferior has essentially been killed & reborn. */ | |
7a292a7a | 510 | |
c906108c | 511 | gdb_flush (gdb_stdout); |
6ca15a4b PA |
512 | |
513 | breakpoint_init_inferior (inf_execd); | |
e85a822c DJ |
514 | |
515 | if (gdb_sysroot && *gdb_sysroot) | |
516 | { | |
517 | char *name = alloca (strlen (gdb_sysroot) | |
518 | + strlen (execd_pathname) | |
519 | + 1); | |
520 | strcpy (name, gdb_sysroot); | |
521 | strcat (name, execd_pathname); | |
522 | execd_pathname = name; | |
523 | } | |
c906108c SS |
524 | |
525 | /* That a.out is now the one to use. */ | |
526 | exec_file_attach (execd_pathname, 0); | |
527 | ||
cce9b6bf PA |
528 | /* Reset the shared library package. This ensures that we get a |
529 | shlib event when the child reaches "_start", at which point the | |
530 | dld will have had a chance to initialize the child. */ | |
531 | /* Also, loading a symbol file below may trigger symbol lookups, and | |
532 | we don't want those to be satisfied by the libraries of the | |
533 | previous incarnation of this process. */ | |
534 | no_shared_libraries (NULL, 0); | |
535 | ||
536 | /* Load the main file's symbols. */ | |
1adeb98a | 537 | symbol_file_add_main (execd_pathname, 0); |
c906108c | 538 | |
7a292a7a | 539 | #ifdef SOLIB_CREATE_INFERIOR_HOOK |
39f77062 | 540 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
a77053c2 MK |
541 | #else |
542 | solib_create_inferior_hook (); | |
7a292a7a | 543 | #endif |
c906108c SS |
544 | |
545 | /* Reinsert all breakpoints. (Those which were symbolic have | |
546 | been reset to the proper address in the new a.out, thanks | |
547 | to symbol_file_command...) */ | |
548 | insert_breakpoints (); | |
549 | ||
550 | /* The next resume of this inferior should bring it to the shlib | |
551 | startup breakpoints. (If the user had also set bp's on | |
552 | "main" from the old (parent) process, then they'll auto- | |
553 | matically get reset there in the new process.) */ | |
c906108c SS |
554 | } |
555 | ||
556 | /* Non-zero if we just simulating a single-step. This is needed | |
557 | because we cannot remove the breakpoints in the inferior process | |
558 | until after the `wait' in `wait_for_inferior'. */ | |
559 | static int singlestep_breakpoints_inserted_p = 0; | |
9f976b41 DJ |
560 | |
561 | /* The thread we inserted single-step breakpoints for. */ | |
562 | static ptid_t singlestep_ptid; | |
563 | ||
fd48f117 DJ |
564 | /* PC when we started this single-step. */ |
565 | static CORE_ADDR singlestep_pc; | |
566 | ||
9f976b41 DJ |
567 | /* If another thread hit the singlestep breakpoint, we save the original |
568 | thread here so that we can resume single-stepping it later. */ | |
569 | static ptid_t saved_singlestep_ptid; | |
570 | static int stepping_past_singlestep_breakpoint; | |
6a6b96b9 | 571 | |
ca67fcb8 VP |
572 | /* If not equal to null_ptid, this means that after stepping over breakpoint |
573 | is finished, we need to switch to deferred_step_ptid, and step it. | |
574 | ||
575 | The use case is when one thread has hit a breakpoint, and then the user | |
576 | has switched to another thread and issued 'step'. We need to step over | |
577 | breakpoint in the thread which hit the breakpoint, but then continue | |
578 | stepping the thread user has selected. */ | |
579 | static ptid_t deferred_step_ptid; | |
c906108c | 580 | \f |
237fc4c9 PA |
581 | /* Displaced stepping. */ |
582 | ||
583 | /* In non-stop debugging mode, we must take special care to manage | |
584 | breakpoints properly; in particular, the traditional strategy for | |
585 | stepping a thread past a breakpoint it has hit is unsuitable. | |
586 | 'Displaced stepping' is a tactic for stepping one thread past a | |
587 | breakpoint it has hit while ensuring that other threads running | |
588 | concurrently will hit the breakpoint as they should. | |
589 | ||
590 | The traditional way to step a thread T off a breakpoint in a | |
591 | multi-threaded program in all-stop mode is as follows: | |
592 | ||
593 | a0) Initially, all threads are stopped, and breakpoints are not | |
594 | inserted. | |
595 | a1) We single-step T, leaving breakpoints uninserted. | |
596 | a2) We insert breakpoints, and resume all threads. | |
597 | ||
598 | In non-stop debugging, however, this strategy is unsuitable: we | |
599 | don't want to have to stop all threads in the system in order to | |
600 | continue or step T past a breakpoint. Instead, we use displaced | |
601 | stepping: | |
602 | ||
603 | n0) Initially, T is stopped, other threads are running, and | |
604 | breakpoints are inserted. | |
605 | n1) We copy the instruction "under" the breakpoint to a separate | |
606 | location, outside the main code stream, making any adjustments | |
607 | to the instruction, register, and memory state as directed by | |
608 | T's architecture. | |
609 | n2) We single-step T over the instruction at its new location. | |
610 | n3) We adjust the resulting register and memory state as directed | |
611 | by T's architecture. This includes resetting T's PC to point | |
612 | back into the main instruction stream. | |
613 | n4) We resume T. | |
614 | ||
615 | This approach depends on the following gdbarch methods: | |
616 | ||
617 | - gdbarch_max_insn_length and gdbarch_displaced_step_location | |
618 | indicate where to copy the instruction, and how much space must | |
619 | be reserved there. We use these in step n1. | |
620 | ||
621 | - gdbarch_displaced_step_copy_insn copies a instruction to a new | |
622 | address, and makes any necessary adjustments to the instruction, | |
623 | register contents, and memory. We use this in step n1. | |
624 | ||
625 | - gdbarch_displaced_step_fixup adjusts registers and memory after | |
626 | we have successfuly single-stepped the instruction, to yield the | |
627 | same effect the instruction would have had if we had executed it | |
628 | at its original address. We use this in step n3. | |
629 | ||
630 | - gdbarch_displaced_step_free_closure provides cleanup. | |
631 | ||
632 | The gdbarch_displaced_step_copy_insn and | |
633 | gdbarch_displaced_step_fixup functions must be written so that | |
634 | copying an instruction with gdbarch_displaced_step_copy_insn, | |
635 | single-stepping across the copied instruction, and then applying | |
636 | gdbarch_displaced_insn_fixup should have the same effects on the | |
637 | thread's memory and registers as stepping the instruction in place | |
638 | would have. Exactly which responsibilities fall to the copy and | |
639 | which fall to the fixup is up to the author of those functions. | |
640 | ||
641 | See the comments in gdbarch.sh for details. | |
642 | ||
643 | Note that displaced stepping and software single-step cannot | |
644 | currently be used in combination, although with some care I think | |
645 | they could be made to. Software single-step works by placing | |
646 | breakpoints on all possible subsequent instructions; if the | |
647 | displaced instruction is a PC-relative jump, those breakpoints | |
648 | could fall in very strange places --- on pages that aren't | |
649 | executable, or at addresses that are not proper instruction | |
650 | boundaries. (We do generally let other threads run while we wait | |
651 | to hit the software single-step breakpoint, and they might | |
652 | encounter such a corrupted instruction.) One way to work around | |
653 | this would be to have gdbarch_displaced_step_copy_insn fully | |
654 | simulate the effect of PC-relative instructions (and return NULL) | |
655 | on architectures that use software single-stepping. | |
656 | ||
657 | In non-stop mode, we can have independent and simultaneous step | |
658 | requests, so more than one thread may need to simultaneously step | |
659 | over a breakpoint. The current implementation assumes there is | |
660 | only one scratch space per process. In this case, we have to | |
661 | serialize access to the scratch space. If thread A wants to step | |
662 | over a breakpoint, but we are currently waiting for some other | |
663 | thread to complete a displaced step, we leave thread A stopped and | |
664 | place it in the displaced_step_request_queue. Whenever a displaced | |
665 | step finishes, we pick the next thread in the queue and start a new | |
666 | displaced step operation on it. See displaced_step_prepare and | |
667 | displaced_step_fixup for details. */ | |
668 | ||
669 | /* If this is not null_ptid, this is the thread carrying out a | |
670 | displaced single-step. This thread's state will require fixing up | |
671 | once it has completed its step. */ | |
672 | static ptid_t displaced_step_ptid; | |
673 | ||
674 | struct displaced_step_request | |
675 | { | |
676 | ptid_t ptid; | |
677 | struct displaced_step_request *next; | |
678 | }; | |
679 | ||
680 | /* A queue of pending displaced stepping requests. */ | |
681 | struct displaced_step_request *displaced_step_request_queue; | |
682 | ||
683 | /* The architecture the thread had when we stepped it. */ | |
684 | static struct gdbarch *displaced_step_gdbarch; | |
685 | ||
686 | /* The closure provided gdbarch_displaced_step_copy_insn, to be used | |
687 | for post-step cleanup. */ | |
688 | static struct displaced_step_closure *displaced_step_closure; | |
689 | ||
690 | /* The address of the original instruction, and the copy we made. */ | |
691 | static CORE_ADDR displaced_step_original, displaced_step_copy; | |
692 | ||
693 | /* Saved contents of copy area. */ | |
694 | static gdb_byte *displaced_step_saved_copy; | |
695 | ||
fff08868 HZ |
696 | /* Enum strings for "set|show displaced-stepping". */ |
697 | ||
698 | static const char can_use_displaced_stepping_auto[] = "auto"; | |
699 | static const char can_use_displaced_stepping_on[] = "on"; | |
700 | static const char can_use_displaced_stepping_off[] = "off"; | |
701 | static const char *can_use_displaced_stepping_enum[] = | |
702 | { | |
703 | can_use_displaced_stepping_auto, | |
704 | can_use_displaced_stepping_on, | |
705 | can_use_displaced_stepping_off, | |
706 | NULL, | |
707 | }; | |
708 | ||
709 | /* If ON, and the architecture supports it, GDB will use displaced | |
710 | stepping to step over breakpoints. If OFF, or if the architecture | |
711 | doesn't support it, GDB will instead use the traditional | |
712 | hold-and-step approach. If AUTO (which is the default), GDB will | |
713 | decide which technique to use to step over breakpoints depending on | |
714 | which of all-stop or non-stop mode is active --- displaced stepping | |
715 | in non-stop mode; hold-and-step in all-stop mode. */ | |
716 | ||
717 | static const char *can_use_displaced_stepping = | |
718 | can_use_displaced_stepping_auto; | |
719 | ||
237fc4c9 PA |
720 | static void |
721 | show_can_use_displaced_stepping (struct ui_file *file, int from_tty, | |
722 | struct cmd_list_element *c, | |
723 | const char *value) | |
724 | { | |
fff08868 HZ |
725 | if (can_use_displaced_stepping == can_use_displaced_stepping_auto) |
726 | fprintf_filtered (file, _("\ | |
727 | Debugger's willingness to use displaced stepping to step over \ | |
728 | breakpoints is %s (currently %s).\n"), | |
729 | value, non_stop ? "on" : "off"); | |
730 | else | |
731 | fprintf_filtered (file, _("\ | |
732 | Debugger's willingness to use displaced stepping to step over \ | |
733 | breakpoints is %s.\n"), value); | |
237fc4c9 PA |
734 | } |
735 | ||
fff08868 HZ |
736 | /* Return non-zero if displaced stepping can/should be used to step |
737 | over breakpoints. */ | |
738 | ||
237fc4c9 PA |
739 | static int |
740 | use_displaced_stepping (struct gdbarch *gdbarch) | |
741 | { | |
fff08868 HZ |
742 | return (((can_use_displaced_stepping == can_use_displaced_stepping_auto |
743 | && non_stop) | |
744 | || can_use_displaced_stepping == can_use_displaced_stepping_on) | |
96429cc8 HZ |
745 | && gdbarch_displaced_step_copy_insn_p (gdbarch) |
746 | && !RECORD_IS_USED); | |
237fc4c9 PA |
747 | } |
748 | ||
749 | /* Clean out any stray displaced stepping state. */ | |
750 | static void | |
751 | displaced_step_clear (void) | |
752 | { | |
753 | /* Indicate that there is no cleanup pending. */ | |
754 | displaced_step_ptid = null_ptid; | |
755 | ||
756 | if (displaced_step_closure) | |
757 | { | |
758 | gdbarch_displaced_step_free_closure (displaced_step_gdbarch, | |
759 | displaced_step_closure); | |
760 | displaced_step_closure = NULL; | |
761 | } | |
762 | } | |
763 | ||
764 | static void | |
765 | cleanup_displaced_step_closure (void *ptr) | |
766 | { | |
767 | struct displaced_step_closure *closure = ptr; | |
768 | ||
769 | gdbarch_displaced_step_free_closure (current_gdbarch, closure); | |
770 | } | |
771 | ||
772 | /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ | |
773 | void | |
774 | displaced_step_dump_bytes (struct ui_file *file, | |
775 | const gdb_byte *buf, | |
776 | size_t len) | |
777 | { | |
778 | int i; | |
779 | ||
780 | for (i = 0; i < len; i++) | |
781 | fprintf_unfiltered (file, "%02x ", buf[i]); | |
782 | fputs_unfiltered ("\n", file); | |
783 | } | |
784 | ||
785 | /* Prepare to single-step, using displaced stepping. | |
786 | ||
787 | Note that we cannot use displaced stepping when we have a signal to | |
788 | deliver. If we have a signal to deliver and an instruction to step | |
789 | over, then after the step, there will be no indication from the | |
790 | target whether the thread entered a signal handler or ignored the | |
791 | signal and stepped over the instruction successfully --- both cases | |
792 | result in a simple SIGTRAP. In the first case we mustn't do a | |
793 | fixup, and in the second case we must --- but we can't tell which. | |
794 | Comments in the code for 'random signals' in handle_inferior_event | |
795 | explain how we handle this case instead. | |
796 | ||
797 | Returns 1 if preparing was successful -- this thread is going to be | |
798 | stepped now; or 0 if displaced stepping this thread got queued. */ | |
799 | static int | |
800 | displaced_step_prepare (ptid_t ptid) | |
801 | { | |
ad53cd71 | 802 | struct cleanup *old_cleanups, *ignore_cleanups; |
237fc4c9 PA |
803 | struct regcache *regcache = get_thread_regcache (ptid); |
804 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
805 | CORE_ADDR original, copy; | |
806 | ULONGEST len; | |
807 | struct displaced_step_closure *closure; | |
808 | ||
809 | /* We should never reach this function if the architecture does not | |
810 | support displaced stepping. */ | |
811 | gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch)); | |
812 | ||
813 | /* For the first cut, we're displaced stepping one thread at a | |
814 | time. */ | |
815 | ||
816 | if (!ptid_equal (displaced_step_ptid, null_ptid)) | |
817 | { | |
818 | /* Already waiting for a displaced step to finish. Defer this | |
819 | request and place in queue. */ | |
820 | struct displaced_step_request *req, *new_req; | |
821 | ||
822 | if (debug_displaced) | |
823 | fprintf_unfiltered (gdb_stdlog, | |
824 | "displaced: defering step of %s\n", | |
825 | target_pid_to_str (ptid)); | |
826 | ||
827 | new_req = xmalloc (sizeof (*new_req)); | |
828 | new_req->ptid = ptid; | |
829 | new_req->next = NULL; | |
830 | ||
831 | if (displaced_step_request_queue) | |
832 | { | |
833 | for (req = displaced_step_request_queue; | |
834 | req && req->next; | |
835 | req = req->next) | |
836 | ; | |
837 | req->next = new_req; | |
838 | } | |
839 | else | |
840 | displaced_step_request_queue = new_req; | |
841 | ||
842 | return 0; | |
843 | } | |
844 | else | |
845 | { | |
846 | if (debug_displaced) | |
847 | fprintf_unfiltered (gdb_stdlog, | |
848 | "displaced: stepping %s now\n", | |
849 | target_pid_to_str (ptid)); | |
850 | } | |
851 | ||
852 | displaced_step_clear (); | |
853 | ||
ad53cd71 PA |
854 | old_cleanups = save_inferior_ptid (); |
855 | inferior_ptid = ptid; | |
856 | ||
515630c5 | 857 | original = regcache_read_pc (regcache); |
237fc4c9 PA |
858 | |
859 | copy = gdbarch_displaced_step_location (gdbarch); | |
860 | len = gdbarch_max_insn_length (gdbarch); | |
861 | ||
862 | /* Save the original contents of the copy area. */ | |
863 | displaced_step_saved_copy = xmalloc (len); | |
ad53cd71 PA |
864 | ignore_cleanups = make_cleanup (free_current_contents, |
865 | &displaced_step_saved_copy); | |
237fc4c9 PA |
866 | read_memory (copy, displaced_step_saved_copy, len); |
867 | if (debug_displaced) | |
868 | { | |
869 | fprintf_unfiltered (gdb_stdlog, "displaced: saved 0x%s: ", | |
870 | paddr_nz (copy)); | |
871 | displaced_step_dump_bytes (gdb_stdlog, displaced_step_saved_copy, len); | |
872 | }; | |
873 | ||
874 | closure = gdbarch_displaced_step_copy_insn (gdbarch, | |
ad53cd71 | 875 | original, copy, regcache); |
237fc4c9 PA |
876 | |
877 | /* We don't support the fully-simulated case at present. */ | |
878 | gdb_assert (closure); | |
879 | ||
880 | make_cleanup (cleanup_displaced_step_closure, closure); | |
881 | ||
882 | /* Resume execution at the copy. */ | |
515630c5 | 883 | regcache_write_pc (regcache, copy); |
237fc4c9 | 884 | |
ad53cd71 PA |
885 | discard_cleanups (ignore_cleanups); |
886 | ||
887 | do_cleanups (old_cleanups); | |
237fc4c9 PA |
888 | |
889 | if (debug_displaced) | |
890 | fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to 0x%s\n", | |
ad53cd71 | 891 | paddr_nz (copy)); |
237fc4c9 PA |
892 | |
893 | /* Save the information we need to fix things up if the step | |
894 | succeeds. */ | |
895 | displaced_step_ptid = ptid; | |
896 | displaced_step_gdbarch = gdbarch; | |
897 | displaced_step_closure = closure; | |
898 | displaced_step_original = original; | |
899 | displaced_step_copy = copy; | |
900 | return 1; | |
901 | } | |
902 | ||
903 | static void | |
904 | displaced_step_clear_cleanup (void *ignore) | |
905 | { | |
906 | displaced_step_clear (); | |
907 | } | |
908 | ||
909 | static void | |
910 | write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len) | |
911 | { | |
912 | struct cleanup *ptid_cleanup = save_inferior_ptid (); | |
913 | inferior_ptid = ptid; | |
914 | write_memory (memaddr, myaddr, len); | |
915 | do_cleanups (ptid_cleanup); | |
916 | } | |
917 | ||
918 | static void | |
919 | displaced_step_fixup (ptid_t event_ptid, enum target_signal signal) | |
920 | { | |
921 | struct cleanup *old_cleanups; | |
922 | ||
923 | /* Was this event for the pid we displaced? */ | |
924 | if (ptid_equal (displaced_step_ptid, null_ptid) | |
925 | || ! ptid_equal (displaced_step_ptid, event_ptid)) | |
926 | return; | |
927 | ||
928 | old_cleanups = make_cleanup (displaced_step_clear_cleanup, 0); | |
929 | ||
930 | /* Restore the contents of the copy area. */ | |
931 | { | |
932 | ULONGEST len = gdbarch_max_insn_length (displaced_step_gdbarch); | |
933 | write_memory_ptid (displaced_step_ptid, displaced_step_copy, | |
934 | displaced_step_saved_copy, len); | |
935 | if (debug_displaced) | |
936 | fprintf_unfiltered (gdb_stdlog, "displaced: restored 0x%s\n", | |
937 | paddr_nz (displaced_step_copy)); | |
938 | } | |
939 | ||
940 | /* Did the instruction complete successfully? */ | |
941 | if (signal == TARGET_SIGNAL_TRAP) | |
942 | { | |
943 | /* Fix up the resulting state. */ | |
944 | gdbarch_displaced_step_fixup (displaced_step_gdbarch, | |
945 | displaced_step_closure, | |
946 | displaced_step_original, | |
947 | displaced_step_copy, | |
948 | get_thread_regcache (displaced_step_ptid)); | |
949 | } | |
950 | else | |
951 | { | |
952 | /* Since the instruction didn't complete, all we can do is | |
953 | relocate the PC. */ | |
515630c5 UW |
954 | struct regcache *regcache = get_thread_regcache (event_ptid); |
955 | CORE_ADDR pc = regcache_read_pc (regcache); | |
237fc4c9 | 956 | pc = displaced_step_original + (pc - displaced_step_copy); |
515630c5 | 957 | regcache_write_pc (regcache, pc); |
237fc4c9 PA |
958 | } |
959 | ||
960 | do_cleanups (old_cleanups); | |
961 | ||
1c5cfe86 PA |
962 | displaced_step_ptid = null_ptid; |
963 | ||
237fc4c9 PA |
964 | /* Are there any pending displaced stepping requests? If so, run |
965 | one now. */ | |
1c5cfe86 | 966 | while (displaced_step_request_queue) |
237fc4c9 PA |
967 | { |
968 | struct displaced_step_request *head; | |
969 | ptid_t ptid; | |
1c5cfe86 | 970 | CORE_ADDR actual_pc; |
237fc4c9 PA |
971 | |
972 | head = displaced_step_request_queue; | |
973 | ptid = head->ptid; | |
974 | displaced_step_request_queue = head->next; | |
975 | xfree (head); | |
976 | ||
ad53cd71 PA |
977 | context_switch (ptid); |
978 | ||
fb14de7b | 979 | actual_pc = regcache_read_pc (get_thread_regcache (ptid)); |
1c5cfe86 PA |
980 | |
981 | if (breakpoint_here_p (actual_pc)) | |
ad53cd71 | 982 | { |
1c5cfe86 PA |
983 | if (debug_displaced) |
984 | fprintf_unfiltered (gdb_stdlog, | |
985 | "displaced: stepping queued %s now\n", | |
986 | target_pid_to_str (ptid)); | |
987 | ||
988 | displaced_step_prepare (ptid); | |
989 | ||
990 | if (debug_displaced) | |
991 | { | |
992 | gdb_byte buf[4]; | |
993 | ||
994 | fprintf_unfiltered (gdb_stdlog, "displaced: run 0x%s: ", | |
995 | paddr_nz (actual_pc)); | |
996 | read_memory (actual_pc, buf, sizeof (buf)); | |
997 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); | |
998 | } | |
999 | ||
1000 | target_resume (ptid, 1, TARGET_SIGNAL_0); | |
1001 | ||
1002 | /* Done, we're stepping a thread. */ | |
1003 | break; | |
ad53cd71 | 1004 | } |
1c5cfe86 PA |
1005 | else |
1006 | { | |
1007 | int step; | |
1008 | struct thread_info *tp = inferior_thread (); | |
1009 | ||
1010 | /* The breakpoint we were sitting under has since been | |
1011 | removed. */ | |
1012 | tp->trap_expected = 0; | |
1013 | ||
1014 | /* Go back to what we were trying to do. */ | |
1015 | step = currently_stepping (tp); | |
ad53cd71 | 1016 | |
1c5cfe86 PA |
1017 | if (debug_displaced) |
1018 | fprintf_unfiltered (gdb_stdlog, "breakpoint is gone %s: step(%d)\n", | |
1019 | target_pid_to_str (tp->ptid), step); | |
1020 | ||
1021 | target_resume (ptid, step, TARGET_SIGNAL_0); | |
1022 | tp->stop_signal = TARGET_SIGNAL_0; | |
1023 | ||
1024 | /* This request was discarded. See if there's any other | |
1025 | thread waiting for its turn. */ | |
1026 | } | |
237fc4c9 PA |
1027 | } |
1028 | } | |
1029 | ||
5231c1fd PA |
1030 | /* Update global variables holding ptids to hold NEW_PTID if they were |
1031 | holding OLD_PTID. */ | |
1032 | static void | |
1033 | infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) | |
1034 | { | |
1035 | struct displaced_step_request *it; | |
1036 | ||
1037 | if (ptid_equal (inferior_ptid, old_ptid)) | |
1038 | inferior_ptid = new_ptid; | |
1039 | ||
1040 | if (ptid_equal (singlestep_ptid, old_ptid)) | |
1041 | singlestep_ptid = new_ptid; | |
1042 | ||
1043 | if (ptid_equal (displaced_step_ptid, old_ptid)) | |
1044 | displaced_step_ptid = new_ptid; | |
1045 | ||
1046 | if (ptid_equal (deferred_step_ptid, old_ptid)) | |
1047 | deferred_step_ptid = new_ptid; | |
1048 | ||
1049 | for (it = displaced_step_request_queue; it; it = it->next) | |
1050 | if (ptid_equal (it->ptid, old_ptid)) | |
1051 | it->ptid = new_ptid; | |
1052 | } | |
1053 | ||
237fc4c9 PA |
1054 | \f |
1055 | /* Resuming. */ | |
c906108c SS |
1056 | |
1057 | /* Things to clean up if we QUIT out of resume (). */ | |
c906108c | 1058 | static void |
74b7792f | 1059 | resume_cleanups (void *ignore) |
c906108c SS |
1060 | { |
1061 | normal_stop (); | |
1062 | } | |
1063 | ||
53904c9e AC |
1064 | static const char schedlock_off[] = "off"; |
1065 | static const char schedlock_on[] = "on"; | |
1066 | static const char schedlock_step[] = "step"; | |
488f131b | 1067 | static const char *scheduler_enums[] = { |
ef346e04 AC |
1068 | schedlock_off, |
1069 | schedlock_on, | |
1070 | schedlock_step, | |
1071 | NULL | |
1072 | }; | |
920d2a44 AC |
1073 | static const char *scheduler_mode = schedlock_off; |
1074 | static void | |
1075 | show_scheduler_mode (struct ui_file *file, int from_tty, | |
1076 | struct cmd_list_element *c, const char *value) | |
1077 | { | |
1078 | fprintf_filtered (file, _("\ | |
1079 | Mode for locking scheduler during execution is \"%s\".\n"), | |
1080 | value); | |
1081 | } | |
c906108c SS |
1082 | |
1083 | static void | |
96baa820 | 1084 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
c906108c | 1085 | { |
eefe576e AC |
1086 | if (!target_can_lock_scheduler) |
1087 | { | |
1088 | scheduler_mode = schedlock_off; | |
1089 | error (_("Target '%s' cannot support this command."), target_shortname); | |
1090 | } | |
c906108c SS |
1091 | } |
1092 | ||
2facfe5c DD |
1093 | /* Try to setup for software single stepping over the specified location. |
1094 | Return 1 if target_resume() should use hardware single step. | |
1095 | ||
1096 | GDBARCH the current gdbarch. | |
1097 | PC the location to step over. */ | |
1098 | ||
1099 | static int | |
1100 | maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc) | |
1101 | { | |
1102 | int hw_step = 1; | |
1103 | ||
1104 | if (gdbarch_software_single_step_p (gdbarch) | |
1105 | && gdbarch_software_single_step (gdbarch, get_current_frame ())) | |
1106 | { | |
1107 | hw_step = 0; | |
1108 | /* Do not pull these breakpoints until after a `wait' in | |
1109 | `wait_for_inferior' */ | |
1110 | singlestep_breakpoints_inserted_p = 1; | |
1111 | singlestep_ptid = inferior_ptid; | |
1112 | singlestep_pc = pc; | |
1113 | } | |
1114 | return hw_step; | |
1115 | } | |
c906108c SS |
1116 | |
1117 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
1118 | wants to interrupt some lengthy single-stepping operation | |
1119 | (for child processes, the SIGINT goes to the inferior, and so | |
1120 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
1121 | other targets, that's not true). | |
1122 | ||
1123 | STEP nonzero if we should step (zero to continue instead). | |
1124 | SIG is the signal to give the inferior (zero for none). */ | |
1125 | void | |
96baa820 | 1126 | resume (int step, enum target_signal sig) |
c906108c SS |
1127 | { |
1128 | int should_resume = 1; | |
74b7792f | 1129 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
515630c5 UW |
1130 | struct regcache *regcache = get_current_regcache (); |
1131 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
4e1c45ea | 1132 | struct thread_info *tp = inferior_thread (); |
515630c5 | 1133 | CORE_ADDR pc = regcache_read_pc (regcache); |
c7e8a53c | 1134 | |
c906108c SS |
1135 | QUIT; |
1136 | ||
527159b7 | 1137 | if (debug_infrun) |
237fc4c9 PA |
1138 | fprintf_unfiltered (gdb_stdlog, |
1139 | "infrun: resume (step=%d, signal=%d), " | |
4e1c45ea PA |
1140 | "trap_expected=%d\n", |
1141 | step, sig, tp->trap_expected); | |
c906108c | 1142 | |
692590c1 MS |
1143 | /* Some targets (e.g. Solaris x86) have a kernel bug when stepping |
1144 | over an instruction that causes a page fault without triggering | |
1145 | a hardware watchpoint. The kernel properly notices that it shouldn't | |
1146 | stop, because the hardware watchpoint is not triggered, but it forgets | |
1147 | the step request and continues the program normally. | |
1148 | Work around the problem by removing hardware watchpoints if a step is | |
1149 | requested, GDB will check for a hardware watchpoint trigger after the | |
1150 | step anyway. */ | |
c36b740a | 1151 | if (CANNOT_STEP_HW_WATCHPOINTS && step) |
692590c1 | 1152 | remove_hw_watchpoints (); |
488f131b | 1153 | |
692590c1 | 1154 | |
c2c6d25f JM |
1155 | /* Normally, by the time we reach `resume', the breakpoints are either |
1156 | removed or inserted, as appropriate. The exception is if we're sitting | |
1157 | at a permanent breakpoint; we need to step over it, but permanent | |
1158 | breakpoints can't be removed. So we have to test for it here. */ | |
237fc4c9 | 1159 | if (breakpoint_here_p (pc) == permanent_breakpoint_here) |
6d350bb5 | 1160 | { |
515630c5 UW |
1161 | if (gdbarch_skip_permanent_breakpoint_p (gdbarch)) |
1162 | gdbarch_skip_permanent_breakpoint (gdbarch, regcache); | |
6d350bb5 UW |
1163 | else |
1164 | error (_("\ | |
1165 | The program is stopped at a permanent breakpoint, but GDB does not know\n\ | |
1166 | how to step past a permanent breakpoint on this architecture. Try using\n\ | |
1167 | a command like `return' or `jump' to continue execution.")); | |
1168 | } | |
c2c6d25f | 1169 | |
237fc4c9 PA |
1170 | /* If enabled, step over breakpoints by executing a copy of the |
1171 | instruction at a different address. | |
1172 | ||
1173 | We can't use displaced stepping when we have a signal to deliver; | |
1174 | the comments for displaced_step_prepare explain why. The | |
1175 | comments in the handle_inferior event for dealing with 'random | |
1176 | signals' explain what we do instead. */ | |
515630c5 | 1177 | if (use_displaced_stepping (gdbarch) |
4e1c45ea | 1178 | && tp->trap_expected |
237fc4c9 PA |
1179 | && sig == TARGET_SIGNAL_0) |
1180 | { | |
1181 | if (!displaced_step_prepare (inferior_ptid)) | |
d56b7306 VP |
1182 | { |
1183 | /* Got placed in displaced stepping queue. Will be resumed | |
1184 | later when all the currently queued displaced stepping | |
7f7efbd9 VP |
1185 | requests finish. The thread is not executing at this point, |
1186 | and the call to set_executing will be made later. But we | |
1187 | need to call set_running here, since from frontend point of view, | |
1188 | the thread is running. */ | |
1189 | set_running (inferior_ptid, 1); | |
d56b7306 VP |
1190 | discard_cleanups (old_cleanups); |
1191 | return; | |
1192 | } | |
237fc4c9 PA |
1193 | } |
1194 | ||
2facfe5c DD |
1195 | /* Do we need to do it the hard way, w/temp breakpoints? */ |
1196 | if (step) | |
1197 | step = maybe_software_singlestep (gdbarch, pc); | |
c906108c | 1198 | |
c906108c SS |
1199 | if (should_resume) |
1200 | { | |
39f77062 | 1201 | ptid_t resume_ptid; |
dfcd3bfb | 1202 | |
488f131b | 1203 | resume_ptid = RESUME_ALL; /* Default */ |
ef5cf84e | 1204 | |
cd76b0b7 VP |
1205 | /* If STEP is set, it's a request to use hardware stepping |
1206 | facilities. But in that case, we should never | |
1207 | use singlestep breakpoint. */ | |
1208 | gdb_assert (!(singlestep_breakpoints_inserted_p && step)); | |
1209 | ||
1210 | if (singlestep_breakpoints_inserted_p | |
1211 | && stepping_past_singlestep_breakpoint) | |
c906108c | 1212 | { |
cd76b0b7 VP |
1213 | /* The situation here is as follows. In thread T1 we wanted to |
1214 | single-step. Lacking hardware single-stepping we've | |
1215 | set breakpoint at the PC of the next instruction -- call it | |
1216 | P. After resuming, we've hit that breakpoint in thread T2. | |
1217 | Now we've removed original breakpoint, inserted breakpoint | |
1218 | at P+1, and try to step to advance T2 past breakpoint. | |
1219 | We need to step only T2, as if T1 is allowed to freely run, | |
1220 | it can run past P, and if other threads are allowed to run, | |
1221 | they can hit breakpoint at P+1, and nested hits of single-step | |
1222 | breakpoints is not something we'd want -- that's complicated | |
1223 | to support, and has no value. */ | |
1224 | resume_ptid = inferior_ptid; | |
1225 | } | |
c906108c | 1226 | |
e842223a | 1227 | if ((step || singlestep_breakpoints_inserted_p) |
4e1c45ea | 1228 | && tp->trap_expected) |
cd76b0b7 | 1229 | { |
74960c60 VP |
1230 | /* We're allowing a thread to run past a breakpoint it has |
1231 | hit, by single-stepping the thread with the breakpoint | |
1232 | removed. In which case, we need to single-step only this | |
1233 | thread, and keep others stopped, as they can miss this | |
1234 | breakpoint if allowed to run. | |
1235 | ||
1236 | The current code actually removes all breakpoints when | |
1237 | doing this, not just the one being stepped over, so if we | |
1238 | let other threads run, we can actually miss any | |
1239 | breakpoint, not just the one at PC. */ | |
ef5cf84e | 1240 | resume_ptid = inferior_ptid; |
c906108c | 1241 | } |
ef5cf84e | 1242 | |
94cc34af PA |
1243 | if (non_stop) |
1244 | { | |
1245 | /* With non-stop mode on, threads are always handled | |
1246 | individually. */ | |
1247 | resume_ptid = inferior_ptid; | |
1248 | } | |
1249 | else if ((scheduler_mode == schedlock_on) | |
1250 | || (scheduler_mode == schedlock_step | |
1251 | && (step || singlestep_breakpoints_inserted_p))) | |
c906108c | 1252 | { |
ef5cf84e | 1253 | /* User-settable 'scheduler' mode requires solo thread resume. */ |
488f131b | 1254 | resume_ptid = inferior_ptid; |
c906108c | 1255 | } |
ef5cf84e | 1256 | |
515630c5 | 1257 | if (gdbarch_cannot_step_breakpoint (gdbarch)) |
c4ed33b9 AC |
1258 | { |
1259 | /* Most targets can step a breakpoint instruction, thus | |
1260 | executing it normally. But if this one cannot, just | |
1261 | continue and we will hit it anyway. */ | |
237fc4c9 | 1262 | if (step && breakpoint_inserted_here_p (pc)) |
c4ed33b9 AC |
1263 | step = 0; |
1264 | } | |
237fc4c9 PA |
1265 | |
1266 | if (debug_displaced | |
515630c5 | 1267 | && use_displaced_stepping (gdbarch) |
4e1c45ea | 1268 | && tp->trap_expected) |
237fc4c9 | 1269 | { |
515630c5 UW |
1270 | struct regcache *resume_regcache = get_thread_regcache (resume_ptid); |
1271 | CORE_ADDR actual_pc = regcache_read_pc (resume_regcache); | |
237fc4c9 PA |
1272 | gdb_byte buf[4]; |
1273 | ||
1274 | fprintf_unfiltered (gdb_stdlog, "displaced: run 0x%s: ", | |
1275 | paddr_nz (actual_pc)); | |
1276 | read_memory (actual_pc, buf, sizeof (buf)); | |
1277 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); | |
1278 | } | |
1279 | ||
e58b0e63 PA |
1280 | /* Install inferior's terminal modes. */ |
1281 | target_terminal_inferior (); | |
1282 | ||
2020b7ab PA |
1283 | /* Avoid confusing the next resume, if the next stop/resume |
1284 | happens to apply to another thread. */ | |
1285 | tp->stop_signal = TARGET_SIGNAL_0; | |
607cecd2 PA |
1286 | |
1287 | target_resume (resume_ptid, step, sig); | |
c906108c SS |
1288 | } |
1289 | ||
1290 | discard_cleanups (old_cleanups); | |
1291 | } | |
1292 | \f | |
237fc4c9 | 1293 | /* Proceeding. */ |
c906108c SS |
1294 | |
1295 | /* Clear out all variables saying what to do when inferior is continued. | |
1296 | First do this, then set the ones you want, then call `proceed'. */ | |
1297 | ||
a7212384 UW |
1298 | static void |
1299 | clear_proceed_status_thread (struct thread_info *tp) | |
c906108c | 1300 | { |
a7212384 UW |
1301 | if (debug_infrun) |
1302 | fprintf_unfiltered (gdb_stdlog, | |
1303 | "infrun: clear_proceed_status_thread (%s)\n", | |
1304 | target_pid_to_str (tp->ptid)); | |
d6b48e9c | 1305 | |
a7212384 UW |
1306 | tp->trap_expected = 0; |
1307 | tp->step_range_start = 0; | |
1308 | tp->step_range_end = 0; | |
1309 | tp->step_frame_id = null_frame_id; | |
1310 | tp->step_over_calls = STEP_OVER_UNDEBUGGABLE; | |
1311 | tp->stop_requested = 0; | |
4e1c45ea | 1312 | |
a7212384 | 1313 | tp->stop_step = 0; |
32400beb | 1314 | |
a7212384 | 1315 | tp->proceed_to_finish = 0; |
414c69f7 | 1316 | |
a7212384 UW |
1317 | /* Discard any remaining commands or status from previous stop. */ |
1318 | bpstat_clear (&tp->stop_bpstat); | |
1319 | } | |
32400beb | 1320 | |
a7212384 UW |
1321 | static int |
1322 | clear_proceed_status_callback (struct thread_info *tp, void *data) | |
1323 | { | |
1324 | if (is_exited (tp->ptid)) | |
1325 | return 0; | |
d6b48e9c | 1326 | |
a7212384 UW |
1327 | clear_proceed_status_thread (tp); |
1328 | return 0; | |
1329 | } | |
1330 | ||
1331 | void | |
1332 | clear_proceed_status (void) | |
1333 | { | |
1334 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
1335 | { | |
1336 | struct inferior *inferior; | |
1337 | ||
1338 | if (non_stop) | |
1339 | { | |
1340 | /* If in non-stop mode, only delete the per-thread status | |
1341 | of the current thread. */ | |
1342 | clear_proceed_status_thread (inferior_thread ()); | |
1343 | } | |
1344 | else | |
1345 | { | |
1346 | /* In all-stop mode, delete the per-thread status of | |
1347 | *all* threads. */ | |
1348 | iterate_over_threads (clear_proceed_status_callback, NULL); | |
1349 | } | |
1350 | ||
d6b48e9c PA |
1351 | inferior = current_inferior (); |
1352 | inferior->stop_soon = NO_STOP_QUIETLY; | |
4e1c45ea PA |
1353 | } |
1354 | ||
c906108c | 1355 | stop_after_trap = 0; |
f3b1572e PA |
1356 | |
1357 | observer_notify_about_to_proceed (); | |
c906108c | 1358 | |
d5c31457 UW |
1359 | if (stop_registers) |
1360 | { | |
1361 | regcache_xfree (stop_registers); | |
1362 | stop_registers = NULL; | |
1363 | } | |
c906108c SS |
1364 | } |
1365 | ||
ea67f13b DJ |
1366 | /* This should be suitable for any targets that support threads. */ |
1367 | ||
1368 | static int | |
6a6b96b9 | 1369 | prepare_to_proceed (int step) |
ea67f13b DJ |
1370 | { |
1371 | ptid_t wait_ptid; | |
1372 | struct target_waitstatus wait_status; | |
1373 | ||
1374 | /* Get the last target status returned by target_wait(). */ | |
1375 | get_last_target_status (&wait_ptid, &wait_status); | |
1376 | ||
6a6b96b9 | 1377 | /* Make sure we were stopped at a breakpoint. */ |
ea67f13b | 1378 | if (wait_status.kind != TARGET_WAITKIND_STOPPED |
6a6b96b9 | 1379 | || wait_status.value.sig != TARGET_SIGNAL_TRAP) |
ea67f13b DJ |
1380 | { |
1381 | return 0; | |
1382 | } | |
1383 | ||
6a6b96b9 | 1384 | /* Switched over from WAIT_PID. */ |
ea67f13b | 1385 | if (!ptid_equal (wait_ptid, minus_one_ptid) |
515630c5 | 1386 | && !ptid_equal (inferior_ptid, wait_ptid)) |
ea67f13b | 1387 | { |
515630c5 UW |
1388 | struct regcache *regcache = get_thread_regcache (wait_ptid); |
1389 | ||
1390 | if (breakpoint_here_p (regcache_read_pc (regcache))) | |
ea67f13b | 1391 | { |
515630c5 UW |
1392 | /* If stepping, remember current thread to switch back to. */ |
1393 | if (step) | |
1394 | deferred_step_ptid = inferior_ptid; | |
ea67f13b | 1395 | |
515630c5 UW |
1396 | /* Switch back to WAIT_PID thread. */ |
1397 | switch_to_thread (wait_ptid); | |
6a6b96b9 | 1398 | |
515630c5 UW |
1399 | /* We return 1 to indicate that there is a breakpoint here, |
1400 | so we need to step over it before continuing to avoid | |
1401 | hitting it straight away. */ | |
1402 | return 1; | |
1403 | } | |
ea67f13b DJ |
1404 | } |
1405 | ||
1406 | return 0; | |
ea67f13b | 1407 | } |
e4846b08 | 1408 | |
c906108c SS |
1409 | /* Basic routine for continuing the program in various fashions. |
1410 | ||
1411 | ADDR is the address to resume at, or -1 for resume where stopped. | |
1412 | SIGGNAL is the signal to give it, or 0 for none, | |
c5aa993b | 1413 | or -1 for act according to how it stopped. |
c906108c | 1414 | STEP is nonzero if should trap after one instruction. |
c5aa993b JM |
1415 | -1 means return after that and print nothing. |
1416 | You should probably set various step_... variables | |
1417 | before calling here, if you are stepping. | |
c906108c SS |
1418 | |
1419 | You should call clear_proceed_status before calling proceed. */ | |
1420 | ||
1421 | void | |
96baa820 | 1422 | proceed (CORE_ADDR addr, enum target_signal siggnal, int step) |
c906108c | 1423 | { |
e58b0e63 PA |
1424 | struct regcache *regcache; |
1425 | struct gdbarch *gdbarch; | |
4e1c45ea | 1426 | struct thread_info *tp; |
e58b0e63 | 1427 | CORE_ADDR pc; |
c906108c SS |
1428 | int oneproc = 0; |
1429 | ||
e58b0e63 PA |
1430 | /* If we're stopped at a fork/vfork, follow the branch set by the |
1431 | "set follow-fork-mode" command; otherwise, we'll just proceed | |
1432 | resuming the current thread. */ | |
1433 | if (!follow_fork ()) | |
1434 | { | |
1435 | /* The target for some reason decided not to resume. */ | |
1436 | normal_stop (); | |
1437 | return; | |
1438 | } | |
1439 | ||
1440 | regcache = get_current_regcache (); | |
1441 | gdbarch = get_regcache_arch (regcache); | |
1442 | pc = regcache_read_pc (regcache); | |
1443 | ||
c906108c | 1444 | if (step > 0) |
515630c5 | 1445 | step_start_function = find_pc_function (pc); |
c906108c SS |
1446 | if (step < 0) |
1447 | stop_after_trap = 1; | |
1448 | ||
2acceee2 | 1449 | if (addr == (CORE_ADDR) -1) |
c906108c | 1450 | { |
b2175913 MS |
1451 | if (pc == stop_pc && breakpoint_here_p (pc) |
1452 | && execution_direction != EXEC_REVERSE) | |
3352ef37 AC |
1453 | /* There is a breakpoint at the address we will resume at, |
1454 | step one instruction before inserting breakpoints so that | |
1455 | we do not stop right away (and report a second hit at this | |
b2175913 MS |
1456 | breakpoint). |
1457 | ||
1458 | Note, we don't do this in reverse, because we won't | |
1459 | actually be executing the breakpoint insn anyway. | |
1460 | We'll be (un-)executing the previous instruction. */ | |
1461 | ||
c906108c | 1462 | oneproc = 1; |
515630c5 UW |
1463 | else if (gdbarch_single_step_through_delay_p (gdbarch) |
1464 | && gdbarch_single_step_through_delay (gdbarch, | |
1465 | get_current_frame ())) | |
3352ef37 AC |
1466 | /* We stepped onto an instruction that needs to be stepped |
1467 | again before re-inserting the breakpoint, do so. */ | |
c906108c SS |
1468 | oneproc = 1; |
1469 | } | |
1470 | else | |
1471 | { | |
515630c5 | 1472 | regcache_write_pc (regcache, addr); |
c906108c SS |
1473 | } |
1474 | ||
527159b7 | 1475 | if (debug_infrun) |
8a9de0e4 AC |
1476 | fprintf_unfiltered (gdb_stdlog, |
1477 | "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n", | |
1478 | paddr_nz (addr), siggnal, step); | |
527159b7 | 1479 | |
94cc34af PA |
1480 | if (non_stop) |
1481 | /* In non-stop, each thread is handled individually. The context | |
1482 | must already be set to the right thread here. */ | |
1483 | ; | |
1484 | else | |
1485 | { | |
1486 | /* In a multi-threaded task we may select another thread and | |
1487 | then continue or step. | |
c906108c | 1488 | |
94cc34af PA |
1489 | But if the old thread was stopped at a breakpoint, it will |
1490 | immediately cause another breakpoint stop without any | |
1491 | execution (i.e. it will report a breakpoint hit incorrectly). | |
1492 | So we must step over it first. | |
c906108c | 1493 | |
94cc34af PA |
1494 | prepare_to_proceed checks the current thread against the |
1495 | thread that reported the most recent event. If a step-over | |
1496 | is required it returns TRUE and sets the current thread to | |
1497 | the old thread. */ | |
1498 | if (prepare_to_proceed (step)) | |
1499 | oneproc = 1; | |
1500 | } | |
c906108c | 1501 | |
4e1c45ea PA |
1502 | /* prepare_to_proceed may change the current thread. */ |
1503 | tp = inferior_thread (); | |
1504 | ||
c906108c | 1505 | if (oneproc) |
74960c60 | 1506 | { |
4e1c45ea | 1507 | tp->trap_expected = 1; |
237fc4c9 PA |
1508 | /* If displaced stepping is enabled, we can step over the |
1509 | breakpoint without hitting it, so leave all breakpoints | |
1510 | inserted. Otherwise we need to disable all breakpoints, step | |
1511 | one instruction, and then re-add them when that step is | |
1512 | finished. */ | |
515630c5 | 1513 | if (!use_displaced_stepping (gdbarch)) |
237fc4c9 | 1514 | remove_breakpoints (); |
74960c60 | 1515 | } |
237fc4c9 PA |
1516 | |
1517 | /* We can insert breakpoints if we're not trying to step over one, | |
1518 | or if we are stepping over one but we're using displaced stepping | |
1519 | to do so. */ | |
4e1c45ea | 1520 | if (! tp->trap_expected || use_displaced_stepping (gdbarch)) |
c36b740a | 1521 | insert_breakpoints (); |
c906108c | 1522 | |
2020b7ab PA |
1523 | if (!non_stop) |
1524 | { | |
1525 | /* Pass the last stop signal to the thread we're resuming, | |
1526 | irrespective of whether the current thread is the thread that | |
1527 | got the last event or not. This was historically GDB's | |
1528 | behaviour before keeping a stop_signal per thread. */ | |
1529 | ||
1530 | struct thread_info *last_thread; | |
1531 | ptid_t last_ptid; | |
1532 | struct target_waitstatus last_status; | |
1533 | ||
1534 | get_last_target_status (&last_ptid, &last_status); | |
1535 | if (!ptid_equal (inferior_ptid, last_ptid) | |
1536 | && !ptid_equal (last_ptid, null_ptid) | |
1537 | && !ptid_equal (last_ptid, minus_one_ptid)) | |
1538 | { | |
e09875d4 | 1539 | last_thread = find_thread_ptid (last_ptid); |
2020b7ab PA |
1540 | if (last_thread) |
1541 | { | |
1542 | tp->stop_signal = last_thread->stop_signal; | |
1543 | last_thread->stop_signal = TARGET_SIGNAL_0; | |
1544 | } | |
1545 | } | |
1546 | } | |
1547 | ||
c906108c | 1548 | if (siggnal != TARGET_SIGNAL_DEFAULT) |
2020b7ab | 1549 | tp->stop_signal = siggnal; |
c906108c SS |
1550 | /* If this signal should not be seen by program, |
1551 | give it zero. Used for debugging signals. */ | |
2020b7ab PA |
1552 | else if (!signal_program[tp->stop_signal]) |
1553 | tp->stop_signal = TARGET_SIGNAL_0; | |
c906108c SS |
1554 | |
1555 | annotate_starting (); | |
1556 | ||
1557 | /* Make sure that output from GDB appears before output from the | |
1558 | inferior. */ | |
1559 | gdb_flush (gdb_stdout); | |
1560 | ||
e4846b08 JJ |
1561 | /* Refresh prev_pc value just prior to resuming. This used to be |
1562 | done in stop_stepping, however, setting prev_pc there did not handle | |
1563 | scenarios such as inferior function calls or returning from | |
1564 | a function via the return command. In those cases, the prev_pc | |
1565 | value was not set properly for subsequent commands. The prev_pc value | |
1566 | is used to initialize the starting line number in the ecs. With an | |
1567 | invalid value, the gdb next command ends up stopping at the position | |
1568 | represented by the next line table entry past our start position. | |
1569 | On platforms that generate one line table entry per line, this | |
1570 | is not a problem. However, on the ia64, the compiler generates | |
1571 | extraneous line table entries that do not increase the line number. | |
1572 | When we issue the gdb next command on the ia64 after an inferior call | |
1573 | or a return command, we often end up a few instructions forward, still | |
1574 | within the original line we started. | |
1575 | ||
1576 | An attempt was made to have init_execution_control_state () refresh | |
1577 | the prev_pc value before calculating the line number. This approach | |
1578 | did not work because on platforms that use ptrace, the pc register | |
1579 | cannot be read unless the inferior is stopped. At that point, we | |
515630c5 | 1580 | are not guaranteed the inferior is stopped and so the regcache_read_pc () |
e4846b08 | 1581 | call can fail. Setting the prev_pc value here ensures the value is |
8fb3e588 | 1582 | updated correctly when the inferior is stopped. */ |
4e1c45ea | 1583 | tp->prev_pc = regcache_read_pc (get_current_regcache ()); |
e4846b08 | 1584 | |
59f0d5d9 | 1585 | /* Fill in with reasonable starting values. */ |
4e1c45ea | 1586 | init_thread_stepping_state (tp); |
59f0d5d9 | 1587 | |
59f0d5d9 PA |
1588 | /* Reset to normal state. */ |
1589 | init_infwait_state (); | |
1590 | ||
c906108c | 1591 | /* Resume inferior. */ |
2020b7ab | 1592 | resume (oneproc || step || bpstat_should_step (), tp->stop_signal); |
c906108c SS |
1593 | |
1594 | /* Wait for it to stop (if not standalone) | |
1595 | and in any case decode why it stopped, and act accordingly. */ | |
43ff13b4 JM |
1596 | /* Do this only if we are not using the event loop, or if the target |
1597 | does not support asynchronous execution. */ | |
362646f5 | 1598 | if (!target_can_async_p ()) |
43ff13b4 | 1599 | { |
ae123ec6 | 1600 | wait_for_inferior (0); |
43ff13b4 JM |
1601 | normal_stop (); |
1602 | } | |
c906108c | 1603 | } |
c906108c SS |
1604 | \f |
1605 | ||
1606 | /* Start remote-debugging of a machine over a serial link. */ | |
96baa820 | 1607 | |
c906108c | 1608 | void |
8621d6a9 | 1609 | start_remote (int from_tty) |
c906108c | 1610 | { |
d6b48e9c | 1611 | struct inferior *inferior; |
c906108c | 1612 | init_wait_for_inferior (); |
d6b48e9c PA |
1613 | |
1614 | inferior = current_inferior (); | |
1615 | inferior->stop_soon = STOP_QUIETLY_REMOTE; | |
43ff13b4 | 1616 | |
6426a772 JM |
1617 | /* Always go on waiting for the target, regardless of the mode. */ |
1618 | /* FIXME: cagney/1999-09-23: At present it isn't possible to | |
7e73cedf | 1619 | indicate to wait_for_inferior that a target should timeout if |
6426a772 JM |
1620 | nothing is returned (instead of just blocking). Because of this, |
1621 | targets expecting an immediate response need to, internally, set | |
1622 | things up so that the target_wait() is forced to eventually | |
1623 | timeout. */ | |
1624 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to | |
1625 | differentiate to its caller what the state of the target is after | |
1626 | the initial open has been performed. Here we're assuming that | |
1627 | the target has stopped. It should be possible to eventually have | |
1628 | target_open() return to the caller an indication that the target | |
1629 | is currently running and GDB state should be set to the same as | |
1630 | for an async run. */ | |
ae123ec6 | 1631 | wait_for_inferior (0); |
8621d6a9 DJ |
1632 | |
1633 | /* Now that the inferior has stopped, do any bookkeeping like | |
1634 | loading shared libraries. We want to do this before normal_stop, | |
1635 | so that the displayed frame is up to date. */ | |
1636 | post_create_inferior (¤t_target, from_tty); | |
1637 | ||
6426a772 | 1638 | normal_stop (); |
c906108c SS |
1639 | } |
1640 | ||
1641 | /* Initialize static vars when a new inferior begins. */ | |
1642 | ||
1643 | void | |
96baa820 | 1644 | init_wait_for_inferior (void) |
c906108c SS |
1645 | { |
1646 | /* These are meaningless until the first time through wait_for_inferior. */ | |
c906108c | 1647 | |
c906108c SS |
1648 | breakpoint_init_inferior (inf_starting); |
1649 | ||
c906108c | 1650 | clear_proceed_status (); |
9f976b41 DJ |
1651 | |
1652 | stepping_past_singlestep_breakpoint = 0; | |
ca67fcb8 | 1653 | deferred_step_ptid = null_ptid; |
ca005067 DJ |
1654 | |
1655 | target_last_wait_ptid = minus_one_ptid; | |
237fc4c9 | 1656 | |
0d1e5fa7 PA |
1657 | previous_inferior_ptid = null_ptid; |
1658 | init_infwait_state (); | |
1659 | ||
237fc4c9 | 1660 | displaced_step_clear (); |
c906108c | 1661 | } |
237fc4c9 | 1662 | |
c906108c | 1663 | \f |
b83266a0 SS |
1664 | /* This enum encodes possible reasons for doing a target_wait, so that |
1665 | wfi can call target_wait in one place. (Ultimately the call will be | |
1666 | moved out of the infinite loop entirely.) */ | |
1667 | ||
c5aa993b JM |
1668 | enum infwait_states |
1669 | { | |
cd0fc7c3 SS |
1670 | infwait_normal_state, |
1671 | infwait_thread_hop_state, | |
d983da9c | 1672 | infwait_step_watch_state, |
cd0fc7c3 | 1673 | infwait_nonstep_watch_state |
b83266a0 SS |
1674 | }; |
1675 | ||
11cf8741 JM |
1676 | /* Why did the inferior stop? Used to print the appropriate messages |
1677 | to the interface from within handle_inferior_event(). */ | |
1678 | enum inferior_stop_reason | |
1679 | { | |
11cf8741 JM |
1680 | /* Step, next, nexti, stepi finished. */ |
1681 | END_STEPPING_RANGE, | |
11cf8741 JM |
1682 | /* Inferior terminated by signal. */ |
1683 | SIGNAL_EXITED, | |
1684 | /* Inferior exited. */ | |
1685 | EXITED, | |
1686 | /* Inferior received signal, and user asked to be notified. */ | |
b2175913 MS |
1687 | SIGNAL_RECEIVED, |
1688 | /* Reverse execution -- target ran out of history info. */ | |
1689 | NO_HISTORY | |
11cf8741 JM |
1690 | }; |
1691 | ||
0d1e5fa7 PA |
1692 | /* The PTID we'll do a target_wait on.*/ |
1693 | ptid_t waiton_ptid; | |
1694 | ||
1695 | /* Current inferior wait state. */ | |
1696 | enum infwait_states infwait_state; | |
cd0fc7c3 | 1697 | |
0d1e5fa7 PA |
1698 | /* Data to be passed around while handling an event. This data is |
1699 | discarded between events. */ | |
c5aa993b | 1700 | struct execution_control_state |
488f131b | 1701 | { |
0d1e5fa7 | 1702 | ptid_t ptid; |
4e1c45ea PA |
1703 | /* The thread that got the event, if this was a thread event; NULL |
1704 | otherwise. */ | |
1705 | struct thread_info *event_thread; | |
1706 | ||
488f131b | 1707 | struct target_waitstatus ws; |
488f131b JB |
1708 | int random_signal; |
1709 | CORE_ADDR stop_func_start; | |
1710 | CORE_ADDR stop_func_end; | |
1711 | char *stop_func_name; | |
488f131b | 1712 | int new_thread_event; |
488f131b JB |
1713 | int wait_some_more; |
1714 | }; | |
1715 | ||
1716 | void init_execution_control_state (struct execution_control_state *ecs); | |
1717 | ||
1718 | void handle_inferior_event (struct execution_control_state *ecs); | |
cd0fc7c3 | 1719 | |
b2175913 MS |
1720 | static void handle_step_into_function (struct execution_control_state *ecs); |
1721 | static void handle_step_into_function_backward (struct execution_control_state *ecs); | |
44cbf7b5 | 1722 | static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame); |
14e60db5 | 1723 | static void insert_step_resume_breakpoint_at_caller (struct frame_info *); |
44cbf7b5 AC |
1724 | static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, |
1725 | struct frame_id sr_id); | |
611c83ae PA |
1726 | static void insert_longjmp_resume_breakpoint (CORE_ADDR); |
1727 | ||
104c1213 JM |
1728 | static void stop_stepping (struct execution_control_state *ecs); |
1729 | static void prepare_to_wait (struct execution_control_state *ecs); | |
d4f3574e | 1730 | static void keep_going (struct execution_control_state *ecs); |
488f131b JB |
1731 | static void print_stop_reason (enum inferior_stop_reason stop_reason, |
1732 | int stop_info); | |
104c1213 | 1733 | |
252fbfc8 PA |
1734 | /* Callback for iterate over threads. If the thread is stopped, but |
1735 | the user/frontend doesn't know about that yet, go through | |
1736 | normal_stop, as if the thread had just stopped now. ARG points at | |
1737 | a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If | |
1738 | ptid_is_pid(PTID) is true, applies to all threads of the process | |
1739 | pointed at by PTID. Otherwise, apply only to the thread pointed by | |
1740 | PTID. */ | |
1741 | ||
1742 | static int | |
1743 | infrun_thread_stop_requested_callback (struct thread_info *info, void *arg) | |
1744 | { | |
1745 | ptid_t ptid = * (ptid_t *) arg; | |
1746 | ||
1747 | if ((ptid_equal (info->ptid, ptid) | |
1748 | || ptid_equal (minus_one_ptid, ptid) | |
1749 | || (ptid_is_pid (ptid) | |
1750 | && ptid_get_pid (ptid) == ptid_get_pid (info->ptid))) | |
1751 | && is_running (info->ptid) | |
1752 | && !is_executing (info->ptid)) | |
1753 | { | |
1754 | struct cleanup *old_chain; | |
1755 | struct execution_control_state ecss; | |
1756 | struct execution_control_state *ecs = &ecss; | |
1757 | ||
1758 | memset (ecs, 0, sizeof (*ecs)); | |
1759 | ||
1760 | old_chain = make_cleanup_restore_current_thread (); | |
1761 | ||
1762 | switch_to_thread (info->ptid); | |
1763 | ||
1764 | /* Go through handle_inferior_event/normal_stop, so we always | |
1765 | have consistent output as if the stop event had been | |
1766 | reported. */ | |
1767 | ecs->ptid = info->ptid; | |
e09875d4 | 1768 | ecs->event_thread = find_thread_ptid (info->ptid); |
252fbfc8 PA |
1769 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; |
1770 | ecs->ws.value.sig = TARGET_SIGNAL_0; | |
1771 | ||
1772 | handle_inferior_event (ecs); | |
1773 | ||
1774 | if (!ecs->wait_some_more) | |
1775 | { | |
1776 | struct thread_info *tp; | |
1777 | ||
1778 | normal_stop (); | |
1779 | ||
1780 | /* Finish off the continuations. The continations | |
1781 | themselves are responsible for realising the thread | |
1782 | didn't finish what it was supposed to do. */ | |
1783 | tp = inferior_thread (); | |
1784 | do_all_intermediate_continuations_thread (tp); | |
1785 | do_all_continuations_thread (tp); | |
1786 | } | |
1787 | ||
1788 | do_cleanups (old_chain); | |
1789 | } | |
1790 | ||
1791 | return 0; | |
1792 | } | |
1793 | ||
1794 | /* This function is attached as a "thread_stop_requested" observer. | |
1795 | Cleanup local state that assumed the PTID was to be resumed, and | |
1796 | report the stop to the frontend. */ | |
1797 | ||
2c0b251b | 1798 | static void |
252fbfc8 PA |
1799 | infrun_thread_stop_requested (ptid_t ptid) |
1800 | { | |
1801 | struct displaced_step_request *it, *next, *prev = NULL; | |
1802 | ||
1803 | /* PTID was requested to stop. Remove it from the displaced | |
1804 | stepping queue, so we don't try to resume it automatically. */ | |
1805 | for (it = displaced_step_request_queue; it; it = next) | |
1806 | { | |
1807 | next = it->next; | |
1808 | ||
1809 | if (ptid_equal (it->ptid, ptid) | |
1810 | || ptid_equal (minus_one_ptid, ptid) | |
1811 | || (ptid_is_pid (ptid) | |
1812 | && ptid_get_pid (ptid) == ptid_get_pid (it->ptid))) | |
1813 | { | |
1814 | if (displaced_step_request_queue == it) | |
1815 | displaced_step_request_queue = it->next; | |
1816 | else | |
1817 | prev->next = it->next; | |
1818 | ||
1819 | xfree (it); | |
1820 | } | |
1821 | else | |
1822 | prev = it; | |
1823 | } | |
1824 | ||
1825 | iterate_over_threads (infrun_thread_stop_requested_callback, &ptid); | |
1826 | } | |
1827 | ||
a07daef3 PA |
1828 | static void |
1829 | infrun_thread_thread_exit (struct thread_info *tp, int silent) | |
1830 | { | |
1831 | if (ptid_equal (target_last_wait_ptid, tp->ptid)) | |
1832 | nullify_last_target_wait_ptid (); | |
1833 | } | |
1834 | ||
4e1c45ea PA |
1835 | /* Callback for iterate_over_threads. */ |
1836 | ||
1837 | static int | |
1838 | delete_step_resume_breakpoint_callback (struct thread_info *info, void *data) | |
1839 | { | |
1840 | if (is_exited (info->ptid)) | |
1841 | return 0; | |
1842 | ||
1843 | delete_step_resume_breakpoint (info); | |
1844 | return 0; | |
1845 | } | |
1846 | ||
1847 | /* In all-stop, delete the step resume breakpoint of any thread that | |
1848 | had one. In non-stop, delete the step resume breakpoint of the | |
1849 | thread that just stopped. */ | |
1850 | ||
1851 | static void | |
1852 | delete_step_thread_step_resume_breakpoint (void) | |
1853 | { | |
1854 | if (!target_has_execution | |
1855 | || ptid_equal (inferior_ptid, null_ptid)) | |
1856 | /* If the inferior has exited, we have already deleted the step | |
1857 | resume breakpoints out of GDB's lists. */ | |
1858 | return; | |
1859 | ||
1860 | if (non_stop) | |
1861 | { | |
1862 | /* If in non-stop mode, only delete the step-resume or | |
1863 | longjmp-resume breakpoint of the thread that just stopped | |
1864 | stepping. */ | |
1865 | struct thread_info *tp = inferior_thread (); | |
1866 | delete_step_resume_breakpoint (tp); | |
1867 | } | |
1868 | else | |
1869 | /* In all-stop mode, delete all step-resume and longjmp-resume | |
1870 | breakpoints of any thread that had them. */ | |
1871 | iterate_over_threads (delete_step_resume_breakpoint_callback, NULL); | |
1872 | } | |
1873 | ||
1874 | /* A cleanup wrapper. */ | |
1875 | ||
1876 | static void | |
1877 | delete_step_thread_step_resume_breakpoint_cleanup (void *arg) | |
1878 | { | |
1879 | delete_step_thread_step_resume_breakpoint (); | |
1880 | } | |
1881 | ||
223698f8 DE |
1882 | /* Pretty print the results of target_wait, for debugging purposes. */ |
1883 | ||
1884 | static void | |
1885 | print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, | |
1886 | const struct target_waitstatus *ws) | |
1887 | { | |
1888 | char *status_string = target_waitstatus_to_string (ws); | |
1889 | struct ui_file *tmp_stream = mem_fileopen (); | |
1890 | char *text; | |
1891 | long len; | |
1892 | ||
1893 | /* The text is split over several lines because it was getting too long. | |
1894 | Call fprintf_unfiltered (gdb_stdlog) once so that the text is still | |
1895 | output as a unit; we want only one timestamp printed if debug_timestamp | |
1896 | is set. */ | |
1897 | ||
1898 | fprintf_unfiltered (tmp_stream, | |
1899 | "infrun: target_wait (%d", PIDGET (waiton_ptid)); | |
1900 | if (PIDGET (waiton_ptid) != -1) | |
1901 | fprintf_unfiltered (tmp_stream, | |
1902 | " [%s]", target_pid_to_str (waiton_ptid)); | |
1903 | fprintf_unfiltered (tmp_stream, ", status) =\n"); | |
1904 | fprintf_unfiltered (tmp_stream, | |
1905 | "infrun: %d [%s],\n", | |
1906 | PIDGET (result_ptid), target_pid_to_str (result_ptid)); | |
1907 | fprintf_unfiltered (tmp_stream, | |
1908 | "infrun: %s\n", | |
1909 | status_string); | |
1910 | ||
1911 | text = ui_file_xstrdup (tmp_stream, &len); | |
1912 | ||
1913 | /* This uses %s in part to handle %'s in the text, but also to avoid | |
1914 | a gcc error: the format attribute requires a string literal. */ | |
1915 | fprintf_unfiltered (gdb_stdlog, "%s", text); | |
1916 | ||
1917 | xfree (status_string); | |
1918 | xfree (text); | |
1919 | ui_file_delete (tmp_stream); | |
1920 | } | |
1921 | ||
cd0fc7c3 | 1922 | /* Wait for control to return from inferior to debugger. |
ae123ec6 JB |
1923 | |
1924 | If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals | |
1925 | as if they were SIGTRAP signals. This can be useful during | |
1926 | the startup sequence on some targets such as HP/UX, where | |
1927 | we receive an EXEC event instead of the expected SIGTRAP. | |
1928 | ||
cd0fc7c3 SS |
1929 | If inferior gets a signal, we may decide to start it up again |
1930 | instead of returning. That is why there is a loop in this function. | |
1931 | When this function actually returns it means the inferior | |
1932 | should be left stopped and GDB should read more commands. */ | |
1933 | ||
1934 | void | |
ae123ec6 | 1935 | wait_for_inferior (int treat_exec_as_sigtrap) |
cd0fc7c3 SS |
1936 | { |
1937 | struct cleanup *old_cleanups; | |
0d1e5fa7 | 1938 | struct execution_control_state ecss; |
cd0fc7c3 | 1939 | struct execution_control_state *ecs; |
c906108c | 1940 | |
527159b7 | 1941 | if (debug_infrun) |
ae123ec6 JB |
1942 | fprintf_unfiltered |
1943 | (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n", | |
1944 | treat_exec_as_sigtrap); | |
527159b7 | 1945 | |
4e1c45ea PA |
1946 | old_cleanups = |
1947 | make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL); | |
cd0fc7c3 | 1948 | |
cd0fc7c3 | 1949 | ecs = &ecss; |
0d1e5fa7 PA |
1950 | memset (ecs, 0, sizeof (*ecs)); |
1951 | ||
cd0fc7c3 SS |
1952 | overlay_cache_invalid = 1; |
1953 | ||
e0bb1c1c PA |
1954 | /* We'll update this if & when we switch to a new thread. */ |
1955 | previous_inferior_ptid = inferior_ptid; | |
1956 | ||
cd0fc7c3 SS |
1957 | /* We have to invalidate the registers BEFORE calling target_wait |
1958 | because they can be loaded from the target while in target_wait. | |
1959 | This makes remote debugging a bit more efficient for those | |
1960 | targets that provide critical registers as part of their normal | |
1961 | status mechanism. */ | |
1962 | ||
1963 | registers_changed (); | |
b83266a0 | 1964 | |
c906108c SS |
1965 | while (1) |
1966 | { | |
29f49a6a PA |
1967 | struct cleanup *old_chain; |
1968 | ||
9a4105ab | 1969 | if (deprecated_target_wait_hook) |
47608cb1 | 1970 | ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0); |
cd0fc7c3 | 1971 | else |
47608cb1 | 1972 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0); |
c906108c | 1973 | |
f00150c9 | 1974 | if (debug_infrun) |
223698f8 | 1975 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
f00150c9 | 1976 | |
ae123ec6 JB |
1977 | if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) |
1978 | { | |
1979 | xfree (ecs->ws.value.execd_pathname); | |
1980 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; | |
1981 | ecs->ws.value.sig = TARGET_SIGNAL_TRAP; | |
1982 | } | |
1983 | ||
29f49a6a PA |
1984 | /* If an error happens while handling the event, propagate GDB's |
1985 | knowledge of the executing state to the frontend/user running | |
1986 | state. */ | |
1987 | old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
1988 | ||
cd0fc7c3 SS |
1989 | /* Now figure out what to do with the result of the result. */ |
1990 | handle_inferior_event (ecs); | |
c906108c | 1991 | |
29f49a6a PA |
1992 | /* No error, don't finish the state yet. */ |
1993 | discard_cleanups (old_chain); | |
1994 | ||
cd0fc7c3 SS |
1995 | if (!ecs->wait_some_more) |
1996 | break; | |
1997 | } | |
4e1c45ea | 1998 | |
cd0fc7c3 SS |
1999 | do_cleanups (old_cleanups); |
2000 | } | |
c906108c | 2001 | |
43ff13b4 JM |
2002 | /* Asynchronous version of wait_for_inferior. It is called by the |
2003 | event loop whenever a change of state is detected on the file | |
2004 | descriptor corresponding to the target. It can be called more than | |
2005 | once to complete a single execution command. In such cases we need | |
a474d7c2 PA |
2006 | to keep the state in a global variable ECSS. If it is the last time |
2007 | that this function is called for a single execution command, then | |
2008 | report to the user that the inferior has stopped, and do the | |
2009 | necessary cleanups. */ | |
43ff13b4 JM |
2010 | |
2011 | void | |
fba45db2 | 2012 | fetch_inferior_event (void *client_data) |
43ff13b4 | 2013 | { |
0d1e5fa7 | 2014 | struct execution_control_state ecss; |
a474d7c2 | 2015 | struct execution_control_state *ecs = &ecss; |
4f8d22e3 | 2016 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
29f49a6a | 2017 | struct cleanup *ts_old_chain; |
4f8d22e3 | 2018 | int was_sync = sync_execution; |
43ff13b4 | 2019 | |
0d1e5fa7 PA |
2020 | memset (ecs, 0, sizeof (*ecs)); |
2021 | ||
59f0d5d9 | 2022 | overlay_cache_invalid = 1; |
43ff13b4 | 2023 | |
e0bb1c1c PA |
2024 | /* We can only rely on wait_for_more being correct before handling |
2025 | the event in all-stop, but previous_inferior_ptid isn't used in | |
2026 | non-stop. */ | |
2027 | if (!ecs->wait_some_more) | |
2028 | /* We'll update this if & when we switch to a new thread. */ | |
2029 | previous_inferior_ptid = inferior_ptid; | |
2030 | ||
4f8d22e3 PA |
2031 | if (non_stop) |
2032 | /* In non-stop mode, the user/frontend should not notice a thread | |
2033 | switch due to internal events. Make sure we reverse to the | |
2034 | user selected thread and frame after handling the event and | |
2035 | running any breakpoint commands. */ | |
2036 | make_cleanup_restore_current_thread (); | |
2037 | ||
59f0d5d9 PA |
2038 | /* We have to invalidate the registers BEFORE calling target_wait |
2039 | because they can be loaded from the target while in target_wait. | |
2040 | This makes remote debugging a bit more efficient for those | |
2041 | targets that provide critical registers as part of their normal | |
2042 | status mechanism. */ | |
43ff13b4 | 2043 | |
59f0d5d9 | 2044 | registers_changed (); |
43ff13b4 | 2045 | |
9a4105ab | 2046 | if (deprecated_target_wait_hook) |
a474d7c2 | 2047 | ecs->ptid = |
47608cb1 | 2048 | deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
43ff13b4 | 2049 | else |
47608cb1 | 2050 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
43ff13b4 | 2051 | |
f00150c9 | 2052 | if (debug_infrun) |
223698f8 | 2053 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
f00150c9 | 2054 | |
94cc34af PA |
2055 | if (non_stop |
2056 | && ecs->ws.kind != TARGET_WAITKIND_IGNORE | |
2057 | && ecs->ws.kind != TARGET_WAITKIND_EXITED | |
2058 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) | |
2059 | /* In non-stop mode, each thread is handled individually. Switch | |
2060 | early, so the global state is set correctly for this | |
2061 | thread. */ | |
2062 | context_switch (ecs->ptid); | |
2063 | ||
29f49a6a PA |
2064 | /* If an error happens while handling the event, propagate GDB's |
2065 | knowledge of the executing state to the frontend/user running | |
2066 | state. */ | |
2067 | if (!non_stop) | |
2068 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
2069 | else | |
2070 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid); | |
2071 | ||
43ff13b4 | 2072 | /* Now figure out what to do with the result of the result. */ |
a474d7c2 | 2073 | handle_inferior_event (ecs); |
43ff13b4 | 2074 | |
a474d7c2 | 2075 | if (!ecs->wait_some_more) |
43ff13b4 | 2076 | { |
d6b48e9c PA |
2077 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); |
2078 | ||
4e1c45ea | 2079 | delete_step_thread_step_resume_breakpoint (); |
f107f563 | 2080 | |
d6b48e9c PA |
2081 | /* We may not find an inferior if this was a process exit. */ |
2082 | if (inf == NULL || inf->stop_soon == NO_STOP_QUIETLY) | |
83c265ab PA |
2083 | normal_stop (); |
2084 | ||
af679fd0 PA |
2085 | if (target_has_execution |
2086 | && ecs->ws.kind != TARGET_WAITKIND_EXITED | |
2087 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
2088 | && ecs->event_thread->step_multi | |
414c69f7 | 2089 | && ecs->event_thread->stop_step) |
c2d11a7d JM |
2090 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); |
2091 | else | |
2092 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
43ff13b4 | 2093 | } |
4f8d22e3 | 2094 | |
29f49a6a PA |
2095 | /* No error, don't finish the thread states yet. */ |
2096 | discard_cleanups (ts_old_chain); | |
2097 | ||
4f8d22e3 PA |
2098 | /* Revert thread and frame. */ |
2099 | do_cleanups (old_chain); | |
2100 | ||
2101 | /* If the inferior was in sync execution mode, and now isn't, | |
2102 | restore the prompt. */ | |
2103 | if (was_sync && !sync_execution) | |
2104 | display_gdb_prompt (0); | |
43ff13b4 JM |
2105 | } |
2106 | ||
cd0fc7c3 SS |
2107 | /* Prepare an execution control state for looping through a |
2108 | wait_for_inferior-type loop. */ | |
2109 | ||
2110 | void | |
96baa820 | 2111 | init_execution_control_state (struct execution_control_state *ecs) |
cd0fc7c3 SS |
2112 | { |
2113 | ecs->random_signal = 0; | |
0d1e5fa7 PA |
2114 | } |
2115 | ||
2116 | /* Clear context switchable stepping state. */ | |
2117 | ||
2118 | void | |
4e1c45ea | 2119 | init_thread_stepping_state (struct thread_info *tss) |
0d1e5fa7 | 2120 | { |
2afb61aa PA |
2121 | struct symtab_and_line sal; |
2122 | ||
0d1e5fa7 PA |
2123 | tss->stepping_over_breakpoint = 0; |
2124 | tss->step_after_step_resume_breakpoint = 0; | |
2125 | tss->stepping_through_solib_after_catch = 0; | |
2126 | tss->stepping_through_solib_catchpoints = NULL; | |
2afb61aa | 2127 | |
4e1c45ea | 2128 | sal = find_pc_line (tss->prev_pc, 0); |
2afb61aa PA |
2129 | tss->current_line = sal.line; |
2130 | tss->current_symtab = sal.symtab; | |
cd0fc7c3 SS |
2131 | } |
2132 | ||
e02bc4cc | 2133 | /* Return the cached copy of the last pid/waitstatus returned by |
9a4105ab AC |
2134 | target_wait()/deprecated_target_wait_hook(). The data is actually |
2135 | cached by handle_inferior_event(), which gets called immediately | |
2136 | after target_wait()/deprecated_target_wait_hook(). */ | |
e02bc4cc DS |
2137 | |
2138 | void | |
488f131b | 2139 | get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) |
e02bc4cc | 2140 | { |
39f77062 | 2141 | *ptidp = target_last_wait_ptid; |
e02bc4cc DS |
2142 | *status = target_last_waitstatus; |
2143 | } | |
2144 | ||
ac264b3b MS |
2145 | void |
2146 | nullify_last_target_wait_ptid (void) | |
2147 | { | |
2148 | target_last_wait_ptid = minus_one_ptid; | |
2149 | } | |
2150 | ||
dcf4fbde | 2151 | /* Switch thread contexts. */ |
dd80620e MS |
2152 | |
2153 | static void | |
0d1e5fa7 | 2154 | context_switch (ptid_t ptid) |
dd80620e | 2155 | { |
fd48f117 DJ |
2156 | if (debug_infrun) |
2157 | { | |
2158 | fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", | |
2159 | target_pid_to_str (inferior_ptid)); | |
2160 | fprintf_unfiltered (gdb_stdlog, "to %s\n", | |
0d1e5fa7 | 2161 | target_pid_to_str (ptid)); |
fd48f117 DJ |
2162 | } |
2163 | ||
0d1e5fa7 | 2164 | switch_to_thread (ptid); |
dd80620e MS |
2165 | } |
2166 | ||
4fa8626c DJ |
2167 | static void |
2168 | adjust_pc_after_break (struct execution_control_state *ecs) | |
2169 | { | |
24a73cce UW |
2170 | struct regcache *regcache; |
2171 | struct gdbarch *gdbarch; | |
8aad930b | 2172 | CORE_ADDR breakpoint_pc; |
4fa8626c | 2173 | |
4fa8626c DJ |
2174 | /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If |
2175 | we aren't, just return. | |
9709f61c DJ |
2176 | |
2177 | We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not | |
b798847d UW |
2178 | affected by gdbarch_decr_pc_after_break. Other waitkinds which are |
2179 | implemented by software breakpoints should be handled through the normal | |
2180 | breakpoint layer. | |
8fb3e588 | 2181 | |
4fa8626c DJ |
2182 | NOTE drow/2004-01-31: On some targets, breakpoints may generate |
2183 | different signals (SIGILL or SIGEMT for instance), but it is less | |
2184 | clear where the PC is pointing afterwards. It may not match | |
b798847d UW |
2185 | gdbarch_decr_pc_after_break. I don't know any specific target that |
2186 | generates these signals at breakpoints (the code has been in GDB since at | |
2187 | least 1992) so I can not guess how to handle them here. | |
8fb3e588 | 2188 | |
e6cf7916 UW |
2189 | In earlier versions of GDB, a target with |
2190 | gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a | |
b798847d UW |
2191 | watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any |
2192 | target with both of these set in GDB history, and it seems unlikely to be | |
2193 | correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ | |
4fa8626c DJ |
2194 | |
2195 | if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) | |
2196 | return; | |
2197 | ||
2198 | if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP) | |
2199 | return; | |
2200 | ||
4058b839 PA |
2201 | /* In reverse execution, when a breakpoint is hit, the instruction |
2202 | under it has already been de-executed. The reported PC always | |
2203 | points at the breakpoint address, so adjusting it further would | |
2204 | be wrong. E.g., consider this case on a decr_pc_after_break == 1 | |
2205 | architecture: | |
2206 | ||
2207 | B1 0x08000000 : INSN1 | |
2208 | B2 0x08000001 : INSN2 | |
2209 | 0x08000002 : INSN3 | |
2210 | PC -> 0x08000003 : INSN4 | |
2211 | ||
2212 | Say you're stopped at 0x08000003 as above. Reverse continuing | |
2213 | from that point should hit B2 as below. Reading the PC when the | |
2214 | SIGTRAP is reported should read 0x08000001 and INSN2 should have | |
2215 | been de-executed already. | |
2216 | ||
2217 | B1 0x08000000 : INSN1 | |
2218 | B2 PC -> 0x08000001 : INSN2 | |
2219 | 0x08000002 : INSN3 | |
2220 | 0x08000003 : INSN4 | |
2221 | ||
2222 | We can't apply the same logic as for forward execution, because | |
2223 | we would wrongly adjust the PC to 0x08000000, since there's a | |
2224 | breakpoint at PC - 1. We'd then report a hit on B1, although | |
2225 | INSN1 hadn't been de-executed yet. Doing nothing is the correct | |
2226 | behaviour. */ | |
2227 | if (execution_direction == EXEC_REVERSE) | |
2228 | return; | |
2229 | ||
24a73cce UW |
2230 | /* If this target does not decrement the PC after breakpoints, then |
2231 | we have nothing to do. */ | |
2232 | regcache = get_thread_regcache (ecs->ptid); | |
2233 | gdbarch = get_regcache_arch (regcache); | |
2234 | if (gdbarch_decr_pc_after_break (gdbarch) == 0) | |
2235 | return; | |
2236 | ||
8aad930b AC |
2237 | /* Find the location where (if we've hit a breakpoint) the |
2238 | breakpoint would be. */ | |
515630c5 UW |
2239 | breakpoint_pc = regcache_read_pc (regcache) |
2240 | - gdbarch_decr_pc_after_break (gdbarch); | |
8aad930b | 2241 | |
1c5cfe86 PA |
2242 | /* Check whether there actually is a software breakpoint inserted at |
2243 | that location. | |
2244 | ||
2245 | If in non-stop mode, a race condition is possible where we've | |
2246 | removed a breakpoint, but stop events for that breakpoint were | |
2247 | already queued and arrive later. To suppress those spurious | |
2248 | SIGTRAPs, we keep a list of such breakpoint locations for a bit, | |
2249 | and retire them after a number of stop events are reported. */ | |
2250 | if (software_breakpoint_inserted_here_p (breakpoint_pc) | |
2251 | || (non_stop && moribund_breakpoint_here_p (breakpoint_pc))) | |
8aad930b | 2252 | { |
96429cc8 HZ |
2253 | struct cleanup *old_cleanups = NULL; |
2254 | if (RECORD_IS_USED) | |
2255 | old_cleanups = record_gdb_operation_disable_set (); | |
2256 | ||
1c0fdd0e UW |
2257 | /* When using hardware single-step, a SIGTRAP is reported for both |
2258 | a completed single-step and a software breakpoint. Need to | |
2259 | differentiate between the two, as the latter needs adjusting | |
2260 | but the former does not. | |
2261 | ||
2262 | The SIGTRAP can be due to a completed hardware single-step only if | |
2263 | - we didn't insert software single-step breakpoints | |
2264 | - the thread to be examined is still the current thread | |
2265 | - this thread is currently being stepped | |
2266 | ||
2267 | If any of these events did not occur, we must have stopped due | |
2268 | to hitting a software breakpoint, and have to back up to the | |
2269 | breakpoint address. | |
2270 | ||
2271 | As a special case, we could have hardware single-stepped a | |
2272 | software breakpoint. In this case (prev_pc == breakpoint_pc), | |
2273 | we also need to back up to the breakpoint address. */ | |
2274 | ||
2275 | if (singlestep_breakpoints_inserted_p | |
2276 | || !ptid_equal (ecs->ptid, inferior_ptid) | |
4e1c45ea PA |
2277 | || !currently_stepping (ecs->event_thread) |
2278 | || ecs->event_thread->prev_pc == breakpoint_pc) | |
515630c5 | 2279 | regcache_write_pc (regcache, breakpoint_pc); |
96429cc8 HZ |
2280 | |
2281 | if (RECORD_IS_USED) | |
2282 | do_cleanups (old_cleanups); | |
8aad930b | 2283 | } |
4fa8626c DJ |
2284 | } |
2285 | ||
0d1e5fa7 PA |
2286 | void |
2287 | init_infwait_state (void) | |
2288 | { | |
2289 | waiton_ptid = pid_to_ptid (-1); | |
2290 | infwait_state = infwait_normal_state; | |
2291 | } | |
2292 | ||
94cc34af PA |
2293 | void |
2294 | error_is_running (void) | |
2295 | { | |
2296 | error (_("\ | |
2297 | Cannot execute this command while the selected thread is running.")); | |
2298 | } | |
2299 | ||
2300 | void | |
2301 | ensure_not_running (void) | |
2302 | { | |
2303 | if (is_running (inferior_ptid)) | |
2304 | error_is_running (); | |
2305 | } | |
2306 | ||
cd0fc7c3 SS |
2307 | /* Given an execution control state that has been freshly filled in |
2308 | by an event from the inferior, figure out what it means and take | |
2309 | appropriate action. */ | |
c906108c | 2310 | |
cd0fc7c3 | 2311 | void |
96baa820 | 2312 | handle_inferior_event (struct execution_control_state *ecs) |
cd0fc7c3 | 2313 | { |
c8edd8b4 | 2314 | int sw_single_step_trap_p = 0; |
d983da9c DJ |
2315 | int stopped_by_watchpoint; |
2316 | int stepped_after_stopped_by_watchpoint = 0; | |
2afb61aa | 2317 | struct symtab_and_line stop_pc_sal; |
d6b48e9c PA |
2318 | enum stop_kind stop_soon; |
2319 | ||
2320 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED | |
2321 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
2322 | && ecs->ws.kind != TARGET_WAITKIND_IGNORE) | |
2323 | { | |
2324 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); | |
2325 | gdb_assert (inf); | |
2326 | stop_soon = inf->stop_soon; | |
2327 | } | |
2328 | else | |
2329 | stop_soon = NO_STOP_QUIETLY; | |
cd0fc7c3 | 2330 | |
e02bc4cc | 2331 | /* Cache the last pid/waitstatus. */ |
39f77062 | 2332 | target_last_wait_ptid = ecs->ptid; |
0d1e5fa7 | 2333 | target_last_waitstatus = ecs->ws; |
e02bc4cc | 2334 | |
ca005067 DJ |
2335 | /* Always clear state belonging to the previous time we stopped. */ |
2336 | stop_stack_dummy = 0; | |
2337 | ||
8c90c137 LM |
2338 | /* If it's a new process, add it to the thread database */ |
2339 | ||
2340 | ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) | |
2341 | && !ptid_equal (ecs->ptid, minus_one_ptid) | |
2342 | && !in_thread_list (ecs->ptid)); | |
2343 | ||
2344 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED | |
2345 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) | |
2346 | add_thread (ecs->ptid); | |
2347 | ||
e09875d4 | 2348 | ecs->event_thread = find_thread_ptid (ecs->ptid); |
88ed393a JK |
2349 | |
2350 | /* Dependent on valid ECS->EVENT_THREAD. */ | |
2351 | adjust_pc_after_break (ecs); | |
2352 | ||
2353 | /* Dependent on the current PC value modified by adjust_pc_after_break. */ | |
2354 | reinit_frame_cache (); | |
2355 | ||
8c90c137 LM |
2356 | if (ecs->ws.kind != TARGET_WAITKIND_IGNORE) |
2357 | { | |
1c5cfe86 PA |
2358 | breakpoint_retire_moribund (); |
2359 | ||
48844aa6 PA |
2360 | /* Mark the non-executing threads accordingly. In all-stop, all |
2361 | threads of all processes are stopped when we get any event | |
2362 | reported. In non-stop mode, only the event thread stops. If | |
2363 | we're handling a process exit in non-stop mode, there's | |
2364 | nothing to do, as threads of the dead process are gone, and | |
2365 | threads of any other process were left running. */ | |
2366 | if (!non_stop) | |
2367 | set_executing (minus_one_ptid, 0); | |
2368 | else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
2369 | && ecs->ws.kind != TARGET_WAITKIND_EXITED) | |
2370 | set_executing (inferior_ptid, 0); | |
8c90c137 LM |
2371 | } |
2372 | ||
0d1e5fa7 | 2373 | switch (infwait_state) |
488f131b JB |
2374 | { |
2375 | case infwait_thread_hop_state: | |
527159b7 | 2376 | if (debug_infrun) |
8a9de0e4 | 2377 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n"); |
488f131b | 2378 | /* Cancel the waiton_ptid. */ |
0d1e5fa7 | 2379 | waiton_ptid = pid_to_ptid (-1); |
65e82032 | 2380 | break; |
b83266a0 | 2381 | |
488f131b | 2382 | case infwait_normal_state: |
527159b7 | 2383 | if (debug_infrun) |
8a9de0e4 | 2384 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n"); |
d983da9c DJ |
2385 | break; |
2386 | ||
2387 | case infwait_step_watch_state: | |
2388 | if (debug_infrun) | |
2389 | fprintf_unfiltered (gdb_stdlog, | |
2390 | "infrun: infwait_step_watch_state\n"); | |
2391 | ||
2392 | stepped_after_stopped_by_watchpoint = 1; | |
488f131b | 2393 | break; |
b83266a0 | 2394 | |
488f131b | 2395 | case infwait_nonstep_watch_state: |
527159b7 | 2396 | if (debug_infrun) |
8a9de0e4 AC |
2397 | fprintf_unfiltered (gdb_stdlog, |
2398 | "infrun: infwait_nonstep_watch_state\n"); | |
488f131b | 2399 | insert_breakpoints (); |
c906108c | 2400 | |
488f131b JB |
2401 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
2402 | handle things like signals arriving and other things happening | |
2403 | in combination correctly? */ | |
2404 | stepped_after_stopped_by_watchpoint = 1; | |
2405 | break; | |
65e82032 AC |
2406 | |
2407 | default: | |
e2e0b3e5 | 2408 | internal_error (__FILE__, __LINE__, _("bad switch")); |
488f131b | 2409 | } |
0d1e5fa7 | 2410 | infwait_state = infwait_normal_state; |
c906108c | 2411 | |
488f131b JB |
2412 | switch (ecs->ws.kind) |
2413 | { | |
2414 | case TARGET_WAITKIND_LOADED: | |
527159b7 | 2415 | if (debug_infrun) |
8a9de0e4 | 2416 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); |
b0f4b84b DJ |
2417 | /* Ignore gracefully during startup of the inferior, as it might |
2418 | be the shell which has just loaded some objects, otherwise | |
2419 | add the symbols for the newly loaded objects. Also ignore at | |
2420 | the beginning of an attach or remote session; we will query | |
2421 | the full list of libraries once the connection is | |
2422 | established. */ | |
c0236d92 | 2423 | if (stop_soon == NO_STOP_QUIETLY) |
488f131b | 2424 | { |
488f131b JB |
2425 | /* Check for any newly added shared libraries if we're |
2426 | supposed to be adding them automatically. Switch | |
2427 | terminal for any messages produced by | |
2428 | breakpoint_re_set. */ | |
2429 | target_terminal_ours_for_output (); | |
aff6338a | 2430 | /* NOTE: cagney/2003-11-25: Make certain that the target |
8fb3e588 AC |
2431 | stack's section table is kept up-to-date. Architectures, |
2432 | (e.g., PPC64), use the section table to perform | |
2433 | operations such as address => section name and hence | |
2434 | require the table to contain all sections (including | |
2435 | those found in shared libraries). */ | |
aff6338a | 2436 | /* NOTE: cagney/2003-11-25: Pass current_target and not |
8fb3e588 AC |
2437 | exec_ops to SOLIB_ADD. This is because current GDB is |
2438 | only tooled to propagate section_table changes out from | |
2439 | the "current_target" (see target_resize_to_sections), and | |
2440 | not up from the exec stratum. This, of course, isn't | |
2441 | right. "infrun.c" should only interact with the | |
2442 | exec/process stratum, instead relying on the target stack | |
2443 | to propagate relevant changes (stop, section table | |
2444 | changed, ...) up to other layers. */ | |
b0f4b84b | 2445 | #ifdef SOLIB_ADD |
aff6338a | 2446 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
b0f4b84b DJ |
2447 | #else |
2448 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
2449 | #endif | |
488f131b JB |
2450 | target_terminal_inferior (); |
2451 | ||
b0f4b84b DJ |
2452 | /* If requested, stop when the dynamic linker notifies |
2453 | gdb of events. This allows the user to get control | |
2454 | and place breakpoints in initializer routines for | |
2455 | dynamically loaded objects (among other things). */ | |
2456 | if (stop_on_solib_events) | |
2457 | { | |
2458 | stop_stepping (ecs); | |
2459 | return; | |
2460 | } | |
2461 | ||
2462 | /* NOTE drow/2007-05-11: This might be a good place to check | |
2463 | for "catch load". */ | |
488f131b | 2464 | } |
b0f4b84b DJ |
2465 | |
2466 | /* If we are skipping through a shell, or through shared library | |
2467 | loading that we aren't interested in, resume the program. If | |
2468 | we're running the program normally, also resume. But stop if | |
2469 | we're attaching or setting up a remote connection. */ | |
2470 | if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) | |
2471 | { | |
74960c60 VP |
2472 | /* Loading of shared libraries might have changed breakpoint |
2473 | addresses. Make sure new breakpoints are inserted. */ | |
0b02b92d UW |
2474 | if (stop_soon == NO_STOP_QUIETLY |
2475 | && !breakpoints_always_inserted_mode ()) | |
74960c60 | 2476 | insert_breakpoints (); |
b0f4b84b DJ |
2477 | resume (0, TARGET_SIGNAL_0); |
2478 | prepare_to_wait (ecs); | |
2479 | return; | |
2480 | } | |
2481 | ||
2482 | break; | |
c5aa993b | 2483 | |
488f131b | 2484 | case TARGET_WAITKIND_SPURIOUS: |
527159b7 | 2485 | if (debug_infrun) |
8a9de0e4 | 2486 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); |
488f131b JB |
2487 | resume (0, TARGET_SIGNAL_0); |
2488 | prepare_to_wait (ecs); | |
2489 | return; | |
c5aa993b | 2490 | |
488f131b | 2491 | case TARGET_WAITKIND_EXITED: |
527159b7 | 2492 | if (debug_infrun) |
8a9de0e4 | 2493 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n"); |
fb66883a | 2494 | inferior_ptid = ecs->ptid; |
488f131b JB |
2495 | target_terminal_ours (); /* Must do this before mourn anyway */ |
2496 | print_stop_reason (EXITED, ecs->ws.value.integer); | |
2497 | ||
2498 | /* Record the exit code in the convenience variable $_exitcode, so | |
2499 | that the user can inspect this again later. */ | |
2500 | set_internalvar (lookup_internalvar ("_exitcode"), | |
8b9b9e1a | 2501 | value_from_longest (builtin_type_int32, |
488f131b JB |
2502 | (LONGEST) ecs->ws.value.integer)); |
2503 | gdb_flush (gdb_stdout); | |
2504 | target_mourn_inferior (); | |
1c0fdd0e | 2505 | singlestep_breakpoints_inserted_p = 0; |
488f131b JB |
2506 | stop_print_frame = 0; |
2507 | stop_stepping (ecs); | |
2508 | return; | |
c5aa993b | 2509 | |
488f131b | 2510 | case TARGET_WAITKIND_SIGNALLED: |
527159b7 | 2511 | if (debug_infrun) |
8a9de0e4 | 2512 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n"); |
fb66883a | 2513 | inferior_ptid = ecs->ptid; |
488f131b | 2514 | stop_print_frame = 0; |
488f131b | 2515 | target_terminal_ours (); /* Must do this before mourn anyway */ |
c5aa993b | 2516 | |
488f131b JB |
2517 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
2518 | reach here unless the inferior is dead. However, for years | |
2519 | target_kill() was called here, which hints that fatal signals aren't | |
2520 | really fatal on some systems. If that's true, then some changes | |
2521 | may be needed. */ | |
2522 | target_mourn_inferior (); | |
c906108c | 2523 | |
2020b7ab | 2524 | print_stop_reason (SIGNAL_EXITED, ecs->ws.value.sig); |
1c0fdd0e | 2525 | singlestep_breakpoints_inserted_p = 0; |
488f131b JB |
2526 | stop_stepping (ecs); |
2527 | return; | |
c906108c | 2528 | |
488f131b JB |
2529 | /* The following are the only cases in which we keep going; |
2530 | the above cases end in a continue or goto. */ | |
2531 | case TARGET_WAITKIND_FORKED: | |
deb3b17b | 2532 | case TARGET_WAITKIND_VFORKED: |
527159b7 | 2533 | if (debug_infrun) |
8a9de0e4 | 2534 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); |
c906108c | 2535 | |
5a2901d9 DJ |
2536 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
2537 | { | |
0d1e5fa7 | 2538 | context_switch (ecs->ptid); |
35f196d9 | 2539 | reinit_frame_cache (); |
5a2901d9 DJ |
2540 | } |
2541 | ||
b242c3c2 PA |
2542 | /* Immediately detach breakpoints from the child before there's |
2543 | any chance of letting the user delete breakpoints from the | |
2544 | breakpoint lists. If we don't do this early, it's easy to | |
2545 | leave left over traps in the child, vis: "break foo; catch | |
2546 | fork; c; <fork>; del; c; <child calls foo>". We only follow | |
2547 | the fork on the last `continue', and by that time the | |
2548 | breakpoint at "foo" is long gone from the breakpoint table. | |
2549 | If we vforked, then we don't need to unpatch here, since both | |
2550 | parent and child are sharing the same memory pages; we'll | |
2551 | need to unpatch at follow/detach time instead to be certain | |
2552 | that new breakpoints added between catchpoint hit time and | |
2553 | vfork follow are detached. */ | |
2554 | if (ecs->ws.kind != TARGET_WAITKIND_VFORKED) | |
2555 | { | |
2556 | int child_pid = ptid_get_pid (ecs->ws.value.related_pid); | |
2557 | ||
2558 | /* This won't actually modify the breakpoint list, but will | |
2559 | physically remove the breakpoints from the child. */ | |
2560 | detach_breakpoints (child_pid); | |
2561 | } | |
2562 | ||
e58b0e63 PA |
2563 | /* In case the event is caught by a catchpoint, remember that |
2564 | the event is to be followed at the next resume of the thread, | |
2565 | and not immediately. */ | |
2566 | ecs->event_thread->pending_follow = ecs->ws; | |
2567 | ||
fb14de7b | 2568 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
675bf4cb | 2569 | |
347bddb7 | 2570 | ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); |
675bf4cb | 2571 | |
347bddb7 | 2572 | ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat); |
04e68871 DJ |
2573 | |
2574 | /* If no catchpoint triggered for this, then keep going. */ | |
2575 | if (ecs->random_signal) | |
2576 | { | |
e58b0e63 PA |
2577 | int should_resume; |
2578 | ||
2020b7ab | 2579 | ecs->event_thread->stop_signal = TARGET_SIGNAL_0; |
e58b0e63 PA |
2580 | |
2581 | should_resume = follow_fork (); | |
2582 | ||
2583 | ecs->event_thread = inferior_thread (); | |
2584 | ecs->ptid = inferior_ptid; | |
2585 | ||
2586 | if (should_resume) | |
2587 | keep_going (ecs); | |
2588 | else | |
2589 | stop_stepping (ecs); | |
04e68871 DJ |
2590 | return; |
2591 | } | |
2020b7ab | 2592 | ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP; |
488f131b JB |
2593 | goto process_event_stop_test; |
2594 | ||
2595 | case TARGET_WAITKIND_EXECD: | |
527159b7 | 2596 | if (debug_infrun) |
fc5261f2 | 2597 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); |
488f131b | 2598 | |
5a2901d9 DJ |
2599 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
2600 | { | |
0d1e5fa7 | 2601 | context_switch (ecs->ptid); |
35f196d9 | 2602 | reinit_frame_cache (); |
5a2901d9 DJ |
2603 | } |
2604 | ||
fb14de7b | 2605 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
795e548f PA |
2606 | |
2607 | /* This causes the eventpoints and symbol table to be reset. | |
2608 | Must do this now, before trying to determine whether to | |
2609 | stop. */ | |
71b43ef8 | 2610 | follow_exec (inferior_ptid, ecs->ws.value.execd_pathname); |
795e548f PA |
2611 | |
2612 | ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); | |
2613 | ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat); | |
2614 | ||
71b43ef8 PA |
2615 | /* Note that this may be referenced from inside |
2616 | bpstat_stop_status above, through inferior_has_execd. */ | |
2617 | xfree (ecs->ws.value.execd_pathname); | |
2618 | ecs->ws.value.execd_pathname = NULL; | |
2619 | ||
04e68871 DJ |
2620 | /* If no catchpoint triggered for this, then keep going. */ |
2621 | if (ecs->random_signal) | |
2622 | { | |
2020b7ab | 2623 | ecs->event_thread->stop_signal = TARGET_SIGNAL_0; |
04e68871 DJ |
2624 | keep_going (ecs); |
2625 | return; | |
2626 | } | |
2020b7ab | 2627 | ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP; |
488f131b JB |
2628 | goto process_event_stop_test; |
2629 | ||
b4dc5ffa MK |
2630 | /* Be careful not to try to gather much state about a thread |
2631 | that's in a syscall. It's frequently a losing proposition. */ | |
488f131b | 2632 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
527159b7 | 2633 | if (debug_infrun) |
8a9de0e4 | 2634 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); |
488f131b JB |
2635 | resume (0, TARGET_SIGNAL_0); |
2636 | prepare_to_wait (ecs); | |
2637 | return; | |
c906108c | 2638 | |
488f131b JB |
2639 | /* Before examining the threads further, step this thread to |
2640 | get it entirely out of the syscall. (We get notice of the | |
2641 | event when the thread is just on the verge of exiting a | |
2642 | syscall. Stepping one instruction seems to get it back | |
b4dc5ffa | 2643 | into user code.) */ |
488f131b | 2644 | case TARGET_WAITKIND_SYSCALL_RETURN: |
527159b7 | 2645 | if (debug_infrun) |
8a9de0e4 | 2646 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); |
488f131b | 2647 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
488f131b JB |
2648 | prepare_to_wait (ecs); |
2649 | return; | |
c906108c | 2650 | |
488f131b | 2651 | case TARGET_WAITKIND_STOPPED: |
527159b7 | 2652 | if (debug_infrun) |
8a9de0e4 | 2653 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); |
2020b7ab | 2654 | ecs->event_thread->stop_signal = ecs->ws.value.sig; |
488f131b | 2655 | break; |
c906108c | 2656 | |
b2175913 MS |
2657 | case TARGET_WAITKIND_NO_HISTORY: |
2658 | /* Reverse execution: target ran out of history info. */ | |
fb14de7b | 2659 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
b2175913 MS |
2660 | print_stop_reason (NO_HISTORY, 0); |
2661 | stop_stepping (ecs); | |
2662 | return; | |
2663 | ||
488f131b JB |
2664 | /* We had an event in the inferior, but we are not interested |
2665 | in handling it at this level. The lower layers have already | |
8e7d2c16 | 2666 | done what needs to be done, if anything. |
8fb3e588 AC |
2667 | |
2668 | One of the possible circumstances for this is when the | |
2669 | inferior produces output for the console. The inferior has | |
2670 | not stopped, and we are ignoring the event. Another possible | |
2671 | circumstance is any event which the lower level knows will be | |
2672 | reported multiple times without an intervening resume. */ | |
488f131b | 2673 | case TARGET_WAITKIND_IGNORE: |
527159b7 | 2674 | if (debug_infrun) |
8a9de0e4 | 2675 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); |
8e7d2c16 | 2676 | prepare_to_wait (ecs); |
488f131b JB |
2677 | return; |
2678 | } | |
c906108c | 2679 | |
488f131b JB |
2680 | if (ecs->new_thread_event) |
2681 | { | |
94cc34af PA |
2682 | if (non_stop) |
2683 | /* Non-stop assumes that the target handles adding new threads | |
2684 | to the thread list. */ | |
2685 | internal_error (__FILE__, __LINE__, "\ | |
2686 | targets should add new threads to the thread list themselves in non-stop mode."); | |
2687 | ||
2688 | /* We may want to consider not doing a resume here in order to | |
2689 | give the user a chance to play with the new thread. It might | |
2690 | be good to make that a user-settable option. */ | |
2691 | ||
2692 | /* At this point, all threads are stopped (happens automatically | |
2693 | in either the OS or the native code). Therefore we need to | |
2694 | continue all threads in order to make progress. */ | |
2695 | ||
488f131b JB |
2696 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); |
2697 | prepare_to_wait (ecs); | |
2698 | return; | |
2699 | } | |
c906108c | 2700 | |
2020b7ab | 2701 | if (ecs->ws.kind == TARGET_WAITKIND_STOPPED) |
252fbfc8 PA |
2702 | { |
2703 | /* Do we need to clean up the state of a thread that has | |
2704 | completed a displaced single-step? (Doing so usually affects | |
2705 | the PC, so do it here, before we set stop_pc.) */ | |
2706 | displaced_step_fixup (ecs->ptid, ecs->event_thread->stop_signal); | |
2707 | ||
2708 | /* If we either finished a single-step or hit a breakpoint, but | |
2709 | the user wanted this thread to be stopped, pretend we got a | |
2710 | SIG0 (generic unsignaled stop). */ | |
2711 | ||
2712 | if (ecs->event_thread->stop_requested | |
2713 | && ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP) | |
2714 | ecs->event_thread->stop_signal = TARGET_SIGNAL_0; | |
2715 | } | |
237fc4c9 | 2716 | |
515630c5 | 2717 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
488f131b | 2718 | |
527159b7 | 2719 | if (debug_infrun) |
237fc4c9 PA |
2720 | { |
2721 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n", | |
2722 | paddr_nz (stop_pc)); | |
d92524f1 | 2723 | if (target_stopped_by_watchpoint ()) |
237fc4c9 PA |
2724 | { |
2725 | CORE_ADDR addr; | |
2726 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n"); | |
2727 | ||
2728 | if (target_stopped_data_address (¤t_target, &addr)) | |
2729 | fprintf_unfiltered (gdb_stdlog, | |
2730 | "infrun: stopped data address = 0x%s\n", | |
2731 | paddr_nz (addr)); | |
2732 | else | |
2733 | fprintf_unfiltered (gdb_stdlog, | |
2734 | "infrun: (no data address available)\n"); | |
2735 | } | |
2736 | } | |
527159b7 | 2737 | |
9f976b41 DJ |
2738 | if (stepping_past_singlestep_breakpoint) |
2739 | { | |
1c0fdd0e | 2740 | gdb_assert (singlestep_breakpoints_inserted_p); |
9f976b41 DJ |
2741 | gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); |
2742 | gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); | |
2743 | ||
2744 | stepping_past_singlestep_breakpoint = 0; | |
2745 | ||
2746 | /* We've either finished single-stepping past the single-step | |
8fb3e588 AC |
2747 | breakpoint, or stopped for some other reason. It would be nice if |
2748 | we could tell, but we can't reliably. */ | |
2020b7ab | 2749 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP) |
8fb3e588 | 2750 | { |
527159b7 | 2751 | if (debug_infrun) |
8a9de0e4 | 2752 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n"); |
9f976b41 | 2753 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 2754 | remove_single_step_breakpoints (); |
9f976b41 DJ |
2755 | singlestep_breakpoints_inserted_p = 0; |
2756 | ||
2757 | ecs->random_signal = 0; | |
2758 | ||
0d1e5fa7 | 2759 | context_switch (saved_singlestep_ptid); |
9a4105ab AC |
2760 | if (deprecated_context_hook) |
2761 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
9f976b41 DJ |
2762 | |
2763 | resume (1, TARGET_SIGNAL_0); | |
2764 | prepare_to_wait (ecs); | |
2765 | return; | |
2766 | } | |
2767 | } | |
2768 | ||
ca67fcb8 | 2769 | if (!ptid_equal (deferred_step_ptid, null_ptid)) |
6a6b96b9 | 2770 | { |
94cc34af PA |
2771 | /* In non-stop mode, there's never a deferred_step_ptid set. */ |
2772 | gdb_assert (!non_stop); | |
2773 | ||
6a6b96b9 UW |
2774 | /* If we stopped for some other reason than single-stepping, ignore |
2775 | the fact that we were supposed to switch back. */ | |
2020b7ab | 2776 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP) |
6a6b96b9 UW |
2777 | { |
2778 | if (debug_infrun) | |
2779 | fprintf_unfiltered (gdb_stdlog, | |
ca67fcb8 | 2780 | "infrun: handling deferred step\n"); |
6a6b96b9 UW |
2781 | |
2782 | /* Pull the single step breakpoints out of the target. */ | |
2783 | if (singlestep_breakpoints_inserted_p) | |
2784 | { | |
2785 | remove_single_step_breakpoints (); | |
2786 | singlestep_breakpoints_inserted_p = 0; | |
2787 | } | |
2788 | ||
2789 | /* Note: We do not call context_switch at this point, as the | |
2790 | context is already set up for stepping the original thread. */ | |
ca67fcb8 VP |
2791 | switch_to_thread (deferred_step_ptid); |
2792 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
2793 | /* Suppress spurious "Switching to ..." message. */ |
2794 | previous_inferior_ptid = inferior_ptid; | |
2795 | ||
2796 | resume (1, TARGET_SIGNAL_0); | |
2797 | prepare_to_wait (ecs); | |
2798 | return; | |
2799 | } | |
ca67fcb8 VP |
2800 | |
2801 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
2802 | } |
2803 | ||
488f131b JB |
2804 | /* See if a thread hit a thread-specific breakpoint that was meant for |
2805 | another thread. If so, then step that thread past the breakpoint, | |
2806 | and continue it. */ | |
2807 | ||
2020b7ab | 2808 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP) |
488f131b | 2809 | { |
9f976b41 DJ |
2810 | int thread_hop_needed = 0; |
2811 | ||
f8d40ec8 JB |
2812 | /* Check if a regular breakpoint has been hit before checking |
2813 | for a potential single step breakpoint. Otherwise, GDB will | |
2814 | not see this breakpoint hit when stepping onto breakpoints. */ | |
c36b740a | 2815 | if (regular_breakpoint_inserted_here_p (stop_pc)) |
488f131b | 2816 | { |
c5aa993b | 2817 | ecs->random_signal = 0; |
4fa8626c | 2818 | if (!breakpoint_thread_match (stop_pc, ecs->ptid)) |
9f976b41 DJ |
2819 | thread_hop_needed = 1; |
2820 | } | |
1c0fdd0e | 2821 | else if (singlestep_breakpoints_inserted_p) |
9f976b41 | 2822 | { |
fd48f117 DJ |
2823 | /* We have not context switched yet, so this should be true |
2824 | no matter which thread hit the singlestep breakpoint. */ | |
2825 | gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid)); | |
2826 | if (debug_infrun) | |
2827 | fprintf_unfiltered (gdb_stdlog, "infrun: software single step " | |
2828 | "trap for %s\n", | |
2829 | target_pid_to_str (ecs->ptid)); | |
2830 | ||
9f976b41 DJ |
2831 | ecs->random_signal = 0; |
2832 | /* The call to in_thread_list is necessary because PTIDs sometimes | |
2833 | change when we go from single-threaded to multi-threaded. If | |
2834 | the singlestep_ptid is still in the list, assume that it is | |
2835 | really different from ecs->ptid. */ | |
2836 | if (!ptid_equal (singlestep_ptid, ecs->ptid) | |
2837 | && in_thread_list (singlestep_ptid)) | |
2838 | { | |
fd48f117 DJ |
2839 | /* If the PC of the thread we were trying to single-step |
2840 | has changed, discard this event (which we were going | |
2841 | to ignore anyway), and pretend we saw that thread | |
2842 | trap. This prevents us continuously moving the | |
2843 | single-step breakpoint forward, one instruction at a | |
2844 | time. If the PC has changed, then the thread we were | |
2845 | trying to single-step has trapped or been signalled, | |
2846 | but the event has not been reported to GDB yet. | |
2847 | ||
2848 | There might be some cases where this loses signal | |
2849 | information, if a signal has arrived at exactly the | |
2850 | same time that the PC changed, but this is the best | |
2851 | we can do with the information available. Perhaps we | |
2852 | should arrange to report all events for all threads | |
2853 | when they stop, or to re-poll the remote looking for | |
2854 | this particular thread (i.e. temporarily enable | |
2855 | schedlock). */ | |
515630c5 UW |
2856 | |
2857 | CORE_ADDR new_singlestep_pc | |
2858 | = regcache_read_pc (get_thread_regcache (singlestep_ptid)); | |
2859 | ||
2860 | if (new_singlestep_pc != singlestep_pc) | |
fd48f117 | 2861 | { |
2020b7ab PA |
2862 | enum target_signal stop_signal; |
2863 | ||
fd48f117 DJ |
2864 | if (debug_infrun) |
2865 | fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread," | |
2866 | " but expected thread advanced also\n"); | |
2867 | ||
2868 | /* The current context still belongs to | |
2869 | singlestep_ptid. Don't swap here, since that's | |
2870 | the context we want to use. Just fudge our | |
2871 | state and continue. */ | |
2020b7ab PA |
2872 | stop_signal = ecs->event_thread->stop_signal; |
2873 | ecs->event_thread->stop_signal = TARGET_SIGNAL_0; | |
fd48f117 | 2874 | ecs->ptid = singlestep_ptid; |
e09875d4 | 2875 | ecs->event_thread = find_thread_ptid (ecs->ptid); |
2020b7ab | 2876 | ecs->event_thread->stop_signal = stop_signal; |
515630c5 | 2877 | stop_pc = new_singlestep_pc; |
fd48f117 DJ |
2878 | } |
2879 | else | |
2880 | { | |
2881 | if (debug_infrun) | |
2882 | fprintf_unfiltered (gdb_stdlog, | |
2883 | "infrun: unexpected thread\n"); | |
2884 | ||
2885 | thread_hop_needed = 1; | |
2886 | stepping_past_singlestep_breakpoint = 1; | |
2887 | saved_singlestep_ptid = singlestep_ptid; | |
2888 | } | |
9f976b41 DJ |
2889 | } |
2890 | } | |
2891 | ||
2892 | if (thread_hop_needed) | |
8fb3e588 | 2893 | { |
237fc4c9 | 2894 | int remove_status = 0; |
8fb3e588 | 2895 | |
527159b7 | 2896 | if (debug_infrun) |
8a9de0e4 | 2897 | fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n"); |
527159b7 | 2898 | |
8fb3e588 AC |
2899 | /* Saw a breakpoint, but it was hit by the wrong thread. |
2900 | Just continue. */ | |
2901 | ||
1c0fdd0e | 2902 | if (singlestep_breakpoints_inserted_p) |
488f131b | 2903 | { |
8fb3e588 | 2904 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 2905 | remove_single_step_breakpoints (); |
8fb3e588 AC |
2906 | singlestep_breakpoints_inserted_p = 0; |
2907 | } | |
2908 | ||
237fc4c9 PA |
2909 | /* If the arch can displace step, don't remove the |
2910 | breakpoints. */ | |
2911 | if (!use_displaced_stepping (current_gdbarch)) | |
2912 | remove_status = remove_breakpoints (); | |
2913 | ||
8fb3e588 AC |
2914 | /* Did we fail to remove breakpoints? If so, try |
2915 | to set the PC past the bp. (There's at least | |
2916 | one situation in which we can fail to remove | |
2917 | the bp's: On HP-UX's that use ttrace, we can't | |
2918 | change the address space of a vforking child | |
2919 | process until the child exits (well, okay, not | |
2920 | then either :-) or execs. */ | |
2921 | if (remove_status != 0) | |
9d9cd7ac | 2922 | error (_("Cannot step over breakpoint hit in wrong thread")); |
8fb3e588 AC |
2923 | else |
2924 | { /* Single step */ | |
8fb3e588 | 2925 | if (!ptid_equal (inferior_ptid, ecs->ptid)) |
0d1e5fa7 PA |
2926 | context_switch (ecs->ptid); |
2927 | ||
94cc34af PA |
2928 | if (!non_stop) |
2929 | { | |
2930 | /* Only need to require the next event from this | |
2931 | thread in all-stop mode. */ | |
2932 | waiton_ptid = ecs->ptid; | |
2933 | infwait_state = infwait_thread_hop_state; | |
2934 | } | |
8fb3e588 | 2935 | |
4e1c45ea | 2936 | ecs->event_thread->stepping_over_breakpoint = 1; |
8fb3e588 AC |
2937 | keep_going (ecs); |
2938 | registers_changed (); | |
2939 | return; | |
2940 | } | |
488f131b | 2941 | } |
1c0fdd0e | 2942 | else if (singlestep_breakpoints_inserted_p) |
8fb3e588 AC |
2943 | { |
2944 | sw_single_step_trap_p = 1; | |
2945 | ecs->random_signal = 0; | |
2946 | } | |
488f131b JB |
2947 | } |
2948 | else | |
2949 | ecs->random_signal = 1; | |
c906108c | 2950 | |
488f131b | 2951 | /* See if something interesting happened to the non-current thread. If |
b40c7d58 DJ |
2952 | so, then switch to that thread. */ |
2953 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
488f131b | 2954 | { |
527159b7 | 2955 | if (debug_infrun) |
8a9de0e4 | 2956 | fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); |
527159b7 | 2957 | |
0d1e5fa7 | 2958 | context_switch (ecs->ptid); |
c5aa993b | 2959 | |
9a4105ab AC |
2960 | if (deprecated_context_hook) |
2961 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
488f131b | 2962 | } |
c906108c | 2963 | |
1c0fdd0e | 2964 | if (singlestep_breakpoints_inserted_p) |
488f131b JB |
2965 | { |
2966 | /* Pull the single step breakpoints out of the target. */ | |
e0cd558a | 2967 | remove_single_step_breakpoints (); |
488f131b JB |
2968 | singlestep_breakpoints_inserted_p = 0; |
2969 | } | |
c906108c | 2970 | |
d983da9c DJ |
2971 | if (stepped_after_stopped_by_watchpoint) |
2972 | stopped_by_watchpoint = 0; | |
2973 | else | |
2974 | stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); | |
2975 | ||
2976 | /* If necessary, step over this watchpoint. We'll be back to display | |
2977 | it in a moment. */ | |
2978 | if (stopped_by_watchpoint | |
d92524f1 | 2979 | && (target_have_steppable_watchpoint |
d983da9c | 2980 | || gdbarch_have_nonsteppable_watchpoint (current_gdbarch))) |
488f131b | 2981 | { |
488f131b JB |
2982 | /* At this point, we are stopped at an instruction which has |
2983 | attempted to write to a piece of memory under control of | |
2984 | a watchpoint. The instruction hasn't actually executed | |
2985 | yet. If we were to evaluate the watchpoint expression | |
2986 | now, we would get the old value, and therefore no change | |
2987 | would seem to have occurred. | |
2988 | ||
2989 | In order to make watchpoints work `right', we really need | |
2990 | to complete the memory write, and then evaluate the | |
d983da9c DJ |
2991 | watchpoint expression. We do this by single-stepping the |
2992 | target. | |
2993 | ||
2994 | It may not be necessary to disable the watchpoint to stop over | |
2995 | it. For example, the PA can (with some kernel cooperation) | |
2996 | single step over a watchpoint without disabling the watchpoint. | |
2997 | ||
2998 | It is far more common to need to disable a watchpoint to step | |
2999 | the inferior over it. If we have non-steppable watchpoints, | |
3000 | we must disable the current watchpoint; it's simplest to | |
3001 | disable all watchpoints and breakpoints. */ | |
2facfe5c DD |
3002 | int hw_step = 1; |
3003 | ||
d92524f1 | 3004 | if (!target_have_steppable_watchpoint) |
d983da9c | 3005 | remove_breakpoints (); |
2facfe5c | 3006 | /* Single step */ |
fb14de7b | 3007 | hw_step = maybe_software_singlestep (current_gdbarch, stop_pc); |
2facfe5c | 3008 | target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0); |
b9412953 | 3009 | registers_changed (); |
0d1e5fa7 | 3010 | waiton_ptid = ecs->ptid; |
d92524f1 | 3011 | if (target_have_steppable_watchpoint) |
0d1e5fa7 | 3012 | infwait_state = infwait_step_watch_state; |
d983da9c | 3013 | else |
0d1e5fa7 | 3014 | infwait_state = infwait_nonstep_watch_state; |
488f131b JB |
3015 | prepare_to_wait (ecs); |
3016 | return; | |
3017 | } | |
3018 | ||
488f131b JB |
3019 | ecs->stop_func_start = 0; |
3020 | ecs->stop_func_end = 0; | |
3021 | ecs->stop_func_name = 0; | |
3022 | /* Don't care about return value; stop_func_start and stop_func_name | |
3023 | will both be 0 if it doesn't work. */ | |
3024 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
3025 | &ecs->stop_func_start, &ecs->stop_func_end); | |
cbf3b44a UW |
3026 | ecs->stop_func_start |
3027 | += gdbarch_deprecated_function_start_offset (current_gdbarch); | |
4e1c45ea | 3028 | ecs->event_thread->stepping_over_breakpoint = 0; |
347bddb7 | 3029 | bpstat_clear (&ecs->event_thread->stop_bpstat); |
414c69f7 | 3030 | ecs->event_thread->stop_step = 0; |
488f131b JB |
3031 | stop_print_frame = 1; |
3032 | ecs->random_signal = 0; | |
3033 | stopped_by_random_signal = 0; | |
488f131b | 3034 | |
2020b7ab | 3035 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP |
4e1c45ea | 3036 | && ecs->event_thread->trap_expected |
3352ef37 | 3037 | && gdbarch_single_step_through_delay_p (current_gdbarch) |
4e1c45ea | 3038 | && currently_stepping (ecs->event_thread)) |
3352ef37 | 3039 | { |
b50d7442 | 3040 | /* We're trying to step off a breakpoint. Turns out that we're |
3352ef37 AC |
3041 | also on an instruction that needs to be stepped multiple |
3042 | times before it's been fully executing. E.g., architectures | |
3043 | with a delay slot. It needs to be stepped twice, once for | |
3044 | the instruction and once for the delay slot. */ | |
3045 | int step_through_delay | |
3046 | = gdbarch_single_step_through_delay (current_gdbarch, | |
3047 | get_current_frame ()); | |
527159b7 | 3048 | if (debug_infrun && step_through_delay) |
8a9de0e4 | 3049 | fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); |
4e1c45ea | 3050 | if (ecs->event_thread->step_range_end == 0 && step_through_delay) |
3352ef37 AC |
3051 | { |
3052 | /* The user issued a continue when stopped at a breakpoint. | |
3053 | Set up for another trap and get out of here. */ | |
4e1c45ea | 3054 | ecs->event_thread->stepping_over_breakpoint = 1; |
3352ef37 AC |
3055 | keep_going (ecs); |
3056 | return; | |
3057 | } | |
3058 | else if (step_through_delay) | |
3059 | { | |
3060 | /* The user issued a step when stopped at a breakpoint. | |
3061 | Maybe we should stop, maybe we should not - the delay | |
3062 | slot *might* correspond to a line of source. In any | |
ca67fcb8 VP |
3063 | case, don't decide that here, just set |
3064 | ecs->stepping_over_breakpoint, making sure we | |
3065 | single-step again before breakpoints are re-inserted. */ | |
4e1c45ea | 3066 | ecs->event_thread->stepping_over_breakpoint = 1; |
3352ef37 AC |
3067 | } |
3068 | } | |
3069 | ||
488f131b JB |
3070 | /* Look at the cause of the stop, and decide what to do. |
3071 | The alternatives are: | |
0d1e5fa7 PA |
3072 | 1) stop_stepping and return; to really stop and return to the debugger, |
3073 | 2) keep_going and return to start up again | |
4e1c45ea | 3074 | (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once) |
488f131b JB |
3075 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 |
3076 | will be made according to the signal handling tables. */ | |
3077 | ||
3078 | /* First, distinguish signals caused by the debugger from signals | |
03cebad2 MK |
3079 | that have to do with the program's own actions. Note that |
3080 | breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending | |
3081 | on the operating system version. Here we detect when a SIGILL or | |
3082 | SIGEMT is really a breakpoint and change it to SIGTRAP. We do | |
3083 | something similar for SIGSEGV, since a SIGSEGV will be generated | |
3084 | when we're trying to execute a breakpoint instruction on a | |
3085 | non-executable stack. This happens for call dummy breakpoints | |
3086 | for architectures like SPARC that place call dummies on the | |
237fc4c9 | 3087 | stack. |
488f131b | 3088 | |
237fc4c9 PA |
3089 | If we're doing a displaced step past a breakpoint, then the |
3090 | breakpoint is always inserted at the original instruction; | |
3091 | non-standard signals can't be explained by the breakpoint. */ | |
2020b7ab | 3092 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP |
4e1c45ea | 3093 | || (! ecs->event_thread->trap_expected |
237fc4c9 | 3094 | && breakpoint_inserted_here_p (stop_pc) |
2020b7ab PA |
3095 | && (ecs->event_thread->stop_signal == TARGET_SIGNAL_ILL |
3096 | || ecs->event_thread->stop_signal == TARGET_SIGNAL_SEGV | |
3097 | || ecs->event_thread->stop_signal == TARGET_SIGNAL_EMT)) | |
b0f4b84b DJ |
3098 | || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP |
3099 | || stop_soon == STOP_QUIETLY_REMOTE) | |
488f131b | 3100 | { |
2020b7ab | 3101 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) |
488f131b | 3102 | { |
527159b7 | 3103 | if (debug_infrun) |
8a9de0e4 | 3104 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); |
488f131b JB |
3105 | stop_print_frame = 0; |
3106 | stop_stepping (ecs); | |
3107 | return; | |
3108 | } | |
c54cfec8 EZ |
3109 | |
3110 | /* This is originated from start_remote(), start_inferior() and | |
3111 | shared libraries hook functions. */ | |
b0f4b84b | 3112 | if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) |
488f131b | 3113 | { |
527159b7 | 3114 | if (debug_infrun) |
8a9de0e4 | 3115 | fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); |
488f131b JB |
3116 | stop_stepping (ecs); |
3117 | return; | |
3118 | } | |
3119 | ||
c54cfec8 | 3120 | /* This originates from attach_command(). We need to overwrite |
a0d21d28 PA |
3121 | the stop_signal here, because some kernels don't ignore a |
3122 | SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call. | |
3123 | See more comments in inferior.h. On the other hand, if we | |
a0ef4274 | 3124 | get a non-SIGSTOP, report it to the user - assume the backend |
a0d21d28 PA |
3125 | will handle the SIGSTOP if it should show up later. |
3126 | ||
3127 | Also consider that the attach is complete when we see a | |
3128 | SIGTRAP. Some systems (e.g. Windows), and stubs supporting | |
3129 | target extended-remote report it instead of a SIGSTOP | |
3130 | (e.g. gdbserver). We already rely on SIGTRAP being our | |
e0ba6746 PA |
3131 | signal, so this is no exception. |
3132 | ||
3133 | Also consider that the attach is complete when we see a | |
3134 | TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell | |
3135 | the target to stop all threads of the inferior, in case the | |
3136 | low level attach operation doesn't stop them implicitly. If | |
3137 | they weren't stopped implicitly, then the stub will report a | |
3138 | TARGET_SIGNAL_0, meaning: stopped for no particular reason | |
3139 | other than GDB's request. */ | |
a0ef4274 | 3140 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP |
2020b7ab | 3141 | && (ecs->event_thread->stop_signal == TARGET_SIGNAL_STOP |
e0ba6746 PA |
3142 | || ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP |
3143 | || ecs->event_thread->stop_signal == TARGET_SIGNAL_0)) | |
c54cfec8 EZ |
3144 | { |
3145 | stop_stepping (ecs); | |
2020b7ab | 3146 | ecs->event_thread->stop_signal = TARGET_SIGNAL_0; |
c54cfec8 EZ |
3147 | return; |
3148 | } | |
3149 | ||
fba57f8f | 3150 | /* See if there is a breakpoint at the current PC. */ |
347bddb7 | 3151 | ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); |
fba57f8f VP |
3152 | |
3153 | /* Following in case break condition called a | |
3154 | function. */ | |
3155 | stop_print_frame = 1; | |
488f131b | 3156 | |
73dd234f | 3157 | /* NOTE: cagney/2003-03-29: These two checks for a random signal |
8fb3e588 AC |
3158 | at one stage in the past included checks for an inferior |
3159 | function call's call dummy's return breakpoint. The original | |
3160 | comment, that went with the test, read: | |
73dd234f | 3161 | |
8fb3e588 AC |
3162 | ``End of a stack dummy. Some systems (e.g. Sony news) give |
3163 | another signal besides SIGTRAP, so check here as well as | |
3164 | above.'' | |
73dd234f | 3165 | |
8002d778 | 3166 | If someone ever tries to get call dummys on a |
73dd234f | 3167 | non-executable stack to work (where the target would stop |
03cebad2 MK |
3168 | with something like a SIGSEGV), then those tests might need |
3169 | to be re-instated. Given, however, that the tests were only | |
73dd234f | 3170 | enabled when momentary breakpoints were not being used, I |
03cebad2 MK |
3171 | suspect that it won't be the case. |
3172 | ||
8fb3e588 AC |
3173 | NOTE: kettenis/2004-02-05: Indeed such checks don't seem to |
3174 | be necessary for call dummies on a non-executable stack on | |
3175 | SPARC. */ | |
73dd234f | 3176 | |
2020b7ab | 3177 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP) |
488f131b | 3178 | ecs->random_signal |
347bddb7 | 3179 | = !(bpstat_explains_signal (ecs->event_thread->stop_bpstat) |
4e1c45ea PA |
3180 | || ecs->event_thread->trap_expected |
3181 | || (ecs->event_thread->step_range_end | |
3182 | && ecs->event_thread->step_resume_breakpoint == NULL)); | |
488f131b JB |
3183 | else |
3184 | { | |
347bddb7 | 3185 | ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat); |
488f131b | 3186 | if (!ecs->random_signal) |
2020b7ab | 3187 | ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP; |
488f131b JB |
3188 | } |
3189 | } | |
3190 | ||
3191 | /* When we reach this point, we've pretty much decided | |
3192 | that the reason for stopping must've been a random | |
3193 | (unexpected) signal. */ | |
3194 | ||
3195 | else | |
3196 | ecs->random_signal = 1; | |
488f131b | 3197 | |
04e68871 | 3198 | process_event_stop_test: |
488f131b JB |
3199 | /* For the program's own signals, act according to |
3200 | the signal handling tables. */ | |
3201 | ||
3202 | if (ecs->random_signal) | |
3203 | { | |
3204 | /* Signal not for debugging purposes. */ | |
3205 | int printed = 0; | |
3206 | ||
527159b7 | 3207 | if (debug_infrun) |
2020b7ab PA |
3208 | fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", |
3209 | ecs->event_thread->stop_signal); | |
527159b7 | 3210 | |
488f131b JB |
3211 | stopped_by_random_signal = 1; |
3212 | ||
2020b7ab | 3213 | if (signal_print[ecs->event_thread->stop_signal]) |
488f131b JB |
3214 | { |
3215 | printed = 1; | |
3216 | target_terminal_ours_for_output (); | |
2020b7ab | 3217 | print_stop_reason (SIGNAL_RECEIVED, ecs->event_thread->stop_signal); |
488f131b | 3218 | } |
252fbfc8 PA |
3219 | /* Always stop on signals if we're either just gaining control |
3220 | of the program, or the user explicitly requested this thread | |
3221 | to remain stopped. */ | |
d6b48e9c | 3222 | if (stop_soon != NO_STOP_QUIETLY |
252fbfc8 | 3223 | || ecs->event_thread->stop_requested |
d6b48e9c | 3224 | || signal_stop_state (ecs->event_thread->stop_signal)) |
488f131b JB |
3225 | { |
3226 | stop_stepping (ecs); | |
3227 | return; | |
3228 | } | |
3229 | /* If not going to stop, give terminal back | |
3230 | if we took it away. */ | |
3231 | else if (printed) | |
3232 | target_terminal_inferior (); | |
3233 | ||
3234 | /* Clear the signal if it should not be passed. */ | |
2020b7ab PA |
3235 | if (signal_program[ecs->event_thread->stop_signal] == 0) |
3236 | ecs->event_thread->stop_signal = TARGET_SIGNAL_0; | |
488f131b | 3237 | |
fb14de7b | 3238 | if (ecs->event_thread->prev_pc == stop_pc |
4e1c45ea PA |
3239 | && ecs->event_thread->trap_expected |
3240 | && ecs->event_thread->step_resume_breakpoint == NULL) | |
68f53502 AC |
3241 | { |
3242 | /* We were just starting a new sequence, attempting to | |
3243 | single-step off of a breakpoint and expecting a SIGTRAP. | |
237fc4c9 | 3244 | Instead this signal arrives. This signal will take us out |
68f53502 AC |
3245 | of the stepping range so GDB needs to remember to, when |
3246 | the signal handler returns, resume stepping off that | |
3247 | breakpoint. */ | |
3248 | /* To simplify things, "continue" is forced to use the same | |
3249 | code paths as single-step - set a breakpoint at the | |
3250 | signal return address and then, once hit, step off that | |
3251 | breakpoint. */ | |
237fc4c9 PA |
3252 | if (debug_infrun) |
3253 | fprintf_unfiltered (gdb_stdlog, | |
3254 | "infrun: signal arrived while stepping over " | |
3255 | "breakpoint\n"); | |
d3169d93 | 3256 | |
44cbf7b5 | 3257 | insert_step_resume_breakpoint_at_frame (get_current_frame ()); |
4e1c45ea | 3258 | ecs->event_thread->step_after_step_resume_breakpoint = 1; |
9d799f85 AC |
3259 | keep_going (ecs); |
3260 | return; | |
68f53502 | 3261 | } |
9d799f85 | 3262 | |
4e1c45ea | 3263 | if (ecs->event_thread->step_range_end != 0 |
2020b7ab | 3264 | && ecs->event_thread->stop_signal != TARGET_SIGNAL_0 |
4e1c45ea PA |
3265 | && (ecs->event_thread->step_range_start <= stop_pc |
3266 | && stop_pc < ecs->event_thread->step_range_end) | |
9d799f85 | 3267 | && frame_id_eq (get_frame_id (get_current_frame ()), |
4e1c45ea PA |
3268 | ecs->event_thread->step_frame_id) |
3269 | && ecs->event_thread->step_resume_breakpoint == NULL) | |
d303a6c7 AC |
3270 | { |
3271 | /* The inferior is about to take a signal that will take it | |
3272 | out of the single step range. Set a breakpoint at the | |
3273 | current PC (which is presumably where the signal handler | |
3274 | will eventually return) and then allow the inferior to | |
3275 | run free. | |
3276 | ||
3277 | Note that this is only needed for a signal delivered | |
3278 | while in the single-step range. Nested signals aren't a | |
3279 | problem as they eventually all return. */ | |
237fc4c9 PA |
3280 | if (debug_infrun) |
3281 | fprintf_unfiltered (gdb_stdlog, | |
3282 | "infrun: signal may take us out of " | |
3283 | "single-step range\n"); | |
3284 | ||
44cbf7b5 | 3285 | insert_step_resume_breakpoint_at_frame (get_current_frame ()); |
9d799f85 AC |
3286 | keep_going (ecs); |
3287 | return; | |
d303a6c7 | 3288 | } |
9d799f85 AC |
3289 | |
3290 | /* Note: step_resume_breakpoint may be non-NULL. This occures | |
3291 | when either there's a nested signal, or when there's a | |
3292 | pending signal enabled just as the signal handler returns | |
3293 | (leaving the inferior at the step-resume-breakpoint without | |
3294 | actually executing it). Either way continue until the | |
3295 | breakpoint is really hit. */ | |
488f131b JB |
3296 | keep_going (ecs); |
3297 | return; | |
3298 | } | |
3299 | ||
3300 | /* Handle cases caused by hitting a breakpoint. */ | |
3301 | { | |
3302 | CORE_ADDR jmp_buf_pc; | |
3303 | struct bpstat_what what; | |
3304 | ||
347bddb7 | 3305 | what = bpstat_what (ecs->event_thread->stop_bpstat); |
488f131b JB |
3306 | |
3307 | if (what.call_dummy) | |
3308 | { | |
3309 | stop_stack_dummy = 1; | |
c5aa993b | 3310 | } |
c906108c | 3311 | |
488f131b | 3312 | switch (what.main_action) |
c5aa993b | 3313 | { |
488f131b | 3314 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
611c83ae PA |
3315 | /* If we hit the breakpoint at longjmp while stepping, we |
3316 | install a momentary breakpoint at the target of the | |
3317 | jmp_buf. */ | |
3318 | ||
3319 | if (debug_infrun) | |
3320 | fprintf_unfiltered (gdb_stdlog, | |
3321 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); | |
3322 | ||
4e1c45ea | 3323 | ecs->event_thread->stepping_over_breakpoint = 1; |
611c83ae | 3324 | |
91104499 | 3325 | if (!gdbarch_get_longjmp_target_p (current_gdbarch) |
60ade65d UW |
3326 | || !gdbarch_get_longjmp_target (current_gdbarch, |
3327 | get_current_frame (), &jmp_buf_pc)) | |
c5aa993b | 3328 | { |
611c83ae PA |
3329 | if (debug_infrun) |
3330 | fprintf_unfiltered (gdb_stdlog, "\ | |
3331 | infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n"); | |
488f131b | 3332 | keep_going (ecs); |
104c1213 | 3333 | return; |
c5aa993b | 3334 | } |
488f131b | 3335 | |
611c83ae PA |
3336 | /* We're going to replace the current step-resume breakpoint |
3337 | with a longjmp-resume breakpoint. */ | |
4e1c45ea | 3338 | delete_step_resume_breakpoint (ecs->event_thread); |
611c83ae PA |
3339 | |
3340 | /* Insert a breakpoint at resume address. */ | |
3341 | insert_longjmp_resume_breakpoint (jmp_buf_pc); | |
c906108c | 3342 | |
488f131b JB |
3343 | keep_going (ecs); |
3344 | return; | |
c906108c | 3345 | |
488f131b | 3346 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
527159b7 | 3347 | if (debug_infrun) |
611c83ae PA |
3348 | fprintf_unfiltered (gdb_stdlog, |
3349 | "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); | |
3350 | ||
4e1c45ea PA |
3351 | gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL); |
3352 | delete_step_resume_breakpoint (ecs->event_thread); | |
611c83ae | 3353 | |
414c69f7 | 3354 | ecs->event_thread->stop_step = 1; |
611c83ae PA |
3355 | print_stop_reason (END_STEPPING_RANGE, 0); |
3356 | stop_stepping (ecs); | |
3357 | return; | |
488f131b JB |
3358 | |
3359 | case BPSTAT_WHAT_SINGLE: | |
527159b7 | 3360 | if (debug_infrun) |
8802d8ed | 3361 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); |
4e1c45ea | 3362 | ecs->event_thread->stepping_over_breakpoint = 1; |
488f131b JB |
3363 | /* Still need to check other stuff, at least the case |
3364 | where we are stepping and step out of the right range. */ | |
3365 | break; | |
c906108c | 3366 | |
488f131b | 3367 | case BPSTAT_WHAT_STOP_NOISY: |
527159b7 | 3368 | if (debug_infrun) |
8802d8ed | 3369 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); |
488f131b | 3370 | stop_print_frame = 1; |
c906108c | 3371 | |
d303a6c7 AC |
3372 | /* We are about to nuke the step_resume_breakpointt via the |
3373 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 3374 | |
488f131b JB |
3375 | stop_stepping (ecs); |
3376 | return; | |
c5aa993b | 3377 | |
488f131b | 3378 | case BPSTAT_WHAT_STOP_SILENT: |
527159b7 | 3379 | if (debug_infrun) |
8802d8ed | 3380 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); |
488f131b | 3381 | stop_print_frame = 0; |
c5aa993b | 3382 | |
d303a6c7 AC |
3383 | /* We are about to nuke the step_resume_breakpoin via the |
3384 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 3385 | |
488f131b | 3386 | stop_stepping (ecs); |
e441088d | 3387 | return; |
c5aa993b | 3388 | |
488f131b | 3389 | case BPSTAT_WHAT_STEP_RESUME: |
527159b7 | 3390 | if (debug_infrun) |
8802d8ed | 3391 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); |
527159b7 | 3392 | |
4e1c45ea PA |
3393 | delete_step_resume_breakpoint (ecs->event_thread); |
3394 | if (ecs->event_thread->step_after_step_resume_breakpoint) | |
68f53502 AC |
3395 | { |
3396 | /* Back when the step-resume breakpoint was inserted, we | |
3397 | were trying to single-step off a breakpoint. Go back | |
3398 | to doing that. */ | |
4e1c45ea PA |
3399 | ecs->event_thread->step_after_step_resume_breakpoint = 0; |
3400 | ecs->event_thread->stepping_over_breakpoint = 1; | |
68f53502 AC |
3401 | keep_going (ecs); |
3402 | return; | |
3403 | } | |
b2175913 MS |
3404 | if (stop_pc == ecs->stop_func_start |
3405 | && execution_direction == EXEC_REVERSE) | |
3406 | { | |
3407 | /* We are stepping over a function call in reverse, and | |
3408 | just hit the step-resume breakpoint at the start | |
3409 | address of the function. Go back to single-stepping, | |
3410 | which should take us back to the function call. */ | |
3411 | ecs->event_thread->stepping_over_breakpoint = 1; | |
3412 | keep_going (ecs); | |
3413 | return; | |
3414 | } | |
488f131b JB |
3415 | break; |
3416 | ||
488f131b | 3417 | case BPSTAT_WHAT_CHECK_SHLIBS: |
c906108c | 3418 | { |
527159b7 | 3419 | if (debug_infrun) |
8802d8ed | 3420 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n"); |
488f131b JB |
3421 | |
3422 | /* Check for any newly added shared libraries if we're | |
3423 | supposed to be adding them automatically. Switch | |
3424 | terminal for any messages produced by | |
3425 | breakpoint_re_set. */ | |
3426 | target_terminal_ours_for_output (); | |
aff6338a | 3427 | /* NOTE: cagney/2003-11-25: Make certain that the target |
8fb3e588 AC |
3428 | stack's section table is kept up-to-date. Architectures, |
3429 | (e.g., PPC64), use the section table to perform | |
3430 | operations such as address => section name and hence | |
3431 | require the table to contain all sections (including | |
3432 | those found in shared libraries). */ | |
aff6338a | 3433 | /* NOTE: cagney/2003-11-25: Pass current_target and not |
8fb3e588 AC |
3434 | exec_ops to SOLIB_ADD. This is because current GDB is |
3435 | only tooled to propagate section_table changes out from | |
3436 | the "current_target" (see target_resize_to_sections), and | |
3437 | not up from the exec stratum. This, of course, isn't | |
3438 | right. "infrun.c" should only interact with the | |
3439 | exec/process stratum, instead relying on the target stack | |
3440 | to propagate relevant changes (stop, section table | |
3441 | changed, ...) up to other layers. */ | |
a77053c2 | 3442 | #ifdef SOLIB_ADD |
aff6338a | 3443 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
a77053c2 MK |
3444 | #else |
3445 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
3446 | #endif | |
488f131b JB |
3447 | target_terminal_inferior (); |
3448 | ||
488f131b JB |
3449 | /* If requested, stop when the dynamic linker notifies |
3450 | gdb of events. This allows the user to get control | |
3451 | and place breakpoints in initializer routines for | |
3452 | dynamically loaded objects (among other things). */ | |
877522db | 3453 | if (stop_on_solib_events || stop_stack_dummy) |
d4f3574e | 3454 | { |
488f131b | 3455 | stop_stepping (ecs); |
d4f3574e SS |
3456 | return; |
3457 | } | |
c5aa993b | 3458 | else |
c5aa993b | 3459 | { |
488f131b | 3460 | /* We want to step over this breakpoint, then keep going. */ |
4e1c45ea | 3461 | ecs->event_thread->stepping_over_breakpoint = 1; |
488f131b | 3462 | break; |
c5aa993b | 3463 | } |
488f131b | 3464 | } |
488f131b | 3465 | break; |
c906108c | 3466 | |
488f131b JB |
3467 | case BPSTAT_WHAT_LAST: |
3468 | /* Not a real code, but listed here to shut up gcc -Wall. */ | |
c906108c | 3469 | |
488f131b JB |
3470 | case BPSTAT_WHAT_KEEP_CHECKING: |
3471 | break; | |
3472 | } | |
3473 | } | |
c906108c | 3474 | |
488f131b JB |
3475 | /* We come here if we hit a breakpoint but should not |
3476 | stop for it. Possibly we also were stepping | |
3477 | and should stop for that. So fall through and | |
3478 | test for stepping. But, if not stepping, | |
3479 | do not stop. */ | |
c906108c | 3480 | |
a7212384 UW |
3481 | /* In all-stop mode, if we're currently stepping but have stopped in |
3482 | some other thread, we need to switch back to the stepped thread. */ | |
3483 | if (!non_stop) | |
3484 | { | |
3485 | struct thread_info *tp; | |
3486 | tp = iterate_over_threads (currently_stepping_callback, | |
3487 | ecs->event_thread); | |
3488 | if (tp) | |
3489 | { | |
3490 | /* However, if the current thread is blocked on some internal | |
3491 | breakpoint, and we simply need to step over that breakpoint | |
3492 | to get it going again, do that first. */ | |
3493 | if ((ecs->event_thread->trap_expected | |
3494 | && ecs->event_thread->stop_signal != TARGET_SIGNAL_TRAP) | |
3495 | || ecs->event_thread->stepping_over_breakpoint) | |
3496 | { | |
3497 | keep_going (ecs); | |
3498 | return; | |
3499 | } | |
3500 | ||
3501 | /* Otherwise, we no longer expect a trap in the current thread. | |
3502 | Clear the trap_expected flag before switching back -- this is | |
3503 | what keep_going would do as well, if we called it. */ | |
3504 | ecs->event_thread->trap_expected = 0; | |
3505 | ||
3506 | if (debug_infrun) | |
3507 | fprintf_unfiltered (gdb_stdlog, | |
3508 | "infrun: switching back to stepped thread\n"); | |
3509 | ||
3510 | ecs->event_thread = tp; | |
3511 | ecs->ptid = tp->ptid; | |
3512 | context_switch (ecs->ptid); | |
3513 | keep_going (ecs); | |
3514 | return; | |
3515 | } | |
3516 | } | |
3517 | ||
9d1ff73f MS |
3518 | /* Are we stepping to get the inferior out of the dynamic linker's |
3519 | hook (and possibly the dld itself) after catching a shlib | |
3520 | event? */ | |
4e1c45ea | 3521 | if (ecs->event_thread->stepping_through_solib_after_catch) |
488f131b JB |
3522 | { |
3523 | #if defined(SOLIB_ADD) | |
3524 | /* Have we reached our destination? If not, keep going. */ | |
3525 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) | |
3526 | { | |
527159b7 | 3527 | if (debug_infrun) |
8a9de0e4 | 3528 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n"); |
4e1c45ea | 3529 | ecs->event_thread->stepping_over_breakpoint = 1; |
488f131b | 3530 | keep_going (ecs); |
104c1213 | 3531 | return; |
488f131b JB |
3532 | } |
3533 | #endif | |
527159b7 | 3534 | if (debug_infrun) |
8a9de0e4 | 3535 | fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n"); |
488f131b JB |
3536 | /* Else, stop and report the catchpoint(s) whose triggering |
3537 | caused us to begin stepping. */ | |
4e1c45ea | 3538 | ecs->event_thread->stepping_through_solib_after_catch = 0; |
347bddb7 PA |
3539 | bpstat_clear (&ecs->event_thread->stop_bpstat); |
3540 | ecs->event_thread->stop_bpstat | |
3541 | = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints); | |
4e1c45ea | 3542 | bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints); |
488f131b JB |
3543 | stop_print_frame = 1; |
3544 | stop_stepping (ecs); | |
3545 | return; | |
3546 | } | |
c906108c | 3547 | |
4e1c45ea | 3548 | if (ecs->event_thread->step_resume_breakpoint) |
488f131b | 3549 | { |
527159b7 | 3550 | if (debug_infrun) |
d3169d93 DJ |
3551 | fprintf_unfiltered (gdb_stdlog, |
3552 | "infrun: step-resume breakpoint is inserted\n"); | |
527159b7 | 3553 | |
488f131b JB |
3554 | /* Having a step-resume breakpoint overrides anything |
3555 | else having to do with stepping commands until | |
3556 | that breakpoint is reached. */ | |
488f131b JB |
3557 | keep_going (ecs); |
3558 | return; | |
3559 | } | |
c5aa993b | 3560 | |
4e1c45ea | 3561 | if (ecs->event_thread->step_range_end == 0) |
488f131b | 3562 | { |
527159b7 | 3563 | if (debug_infrun) |
8a9de0e4 | 3564 | fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); |
488f131b | 3565 | /* Likewise if we aren't even stepping. */ |
488f131b JB |
3566 | keep_going (ecs); |
3567 | return; | |
3568 | } | |
c5aa993b | 3569 | |
488f131b | 3570 | /* If stepping through a line, keep going if still within it. |
c906108c | 3571 | |
488f131b JB |
3572 | Note that step_range_end is the address of the first instruction |
3573 | beyond the step range, and NOT the address of the last instruction | |
3574 | within it! */ | |
4e1c45ea PA |
3575 | if (stop_pc >= ecs->event_thread->step_range_start |
3576 | && stop_pc < ecs->event_thread->step_range_end) | |
488f131b | 3577 | { |
527159b7 | 3578 | if (debug_infrun) |
b2175913 | 3579 | fprintf_unfiltered (gdb_stdlog, "infrun: stepping inside range [0x%s-0x%s]\n", |
4e1c45ea PA |
3580 | paddr_nz (ecs->event_thread->step_range_start), |
3581 | paddr_nz (ecs->event_thread->step_range_end)); | |
b2175913 MS |
3582 | |
3583 | /* When stepping backward, stop at beginning of line range | |
3584 | (unless it's the function entry point, in which case | |
3585 | keep going back to the call point). */ | |
3586 | if (stop_pc == ecs->event_thread->step_range_start | |
3587 | && stop_pc != ecs->stop_func_start | |
3588 | && execution_direction == EXEC_REVERSE) | |
3589 | { | |
3590 | ecs->event_thread->stop_step = 1; | |
3591 | print_stop_reason (END_STEPPING_RANGE, 0); | |
3592 | stop_stepping (ecs); | |
3593 | } | |
3594 | else | |
3595 | keep_going (ecs); | |
3596 | ||
488f131b JB |
3597 | return; |
3598 | } | |
c5aa993b | 3599 | |
488f131b | 3600 | /* We stepped out of the stepping range. */ |
c906108c | 3601 | |
488f131b JB |
3602 | /* If we are stepping at the source level and entered the runtime |
3603 | loader dynamic symbol resolution code, we keep on single stepping | |
3604 | until we exit the run time loader code and reach the callee's | |
3605 | address. */ | |
078130d0 | 3606 | if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE |
cfd8ab24 | 3607 | && in_solib_dynsym_resolve_code (stop_pc)) |
488f131b | 3608 | { |
4c8c40e6 MK |
3609 | CORE_ADDR pc_after_resolver = |
3610 | gdbarch_skip_solib_resolver (current_gdbarch, stop_pc); | |
c906108c | 3611 | |
527159b7 | 3612 | if (debug_infrun) |
8a9de0e4 | 3613 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n"); |
527159b7 | 3614 | |
488f131b JB |
3615 | if (pc_after_resolver) |
3616 | { | |
3617 | /* Set up a step-resume breakpoint at the address | |
3618 | indicated by SKIP_SOLIB_RESOLVER. */ | |
3619 | struct symtab_and_line sr_sal; | |
fe39c653 | 3620 | init_sal (&sr_sal); |
488f131b JB |
3621 | sr_sal.pc = pc_after_resolver; |
3622 | ||
44cbf7b5 | 3623 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
c5aa993b | 3624 | } |
c906108c | 3625 | |
488f131b JB |
3626 | keep_going (ecs); |
3627 | return; | |
3628 | } | |
c906108c | 3629 | |
4e1c45ea | 3630 | if (ecs->event_thread->step_range_end != 1 |
078130d0 PA |
3631 | && (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE |
3632 | || ecs->event_thread->step_over_calls == STEP_OVER_ALL) | |
42edda50 | 3633 | && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME) |
488f131b | 3634 | { |
527159b7 | 3635 | if (debug_infrun) |
8a9de0e4 | 3636 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n"); |
42edda50 | 3637 | /* The inferior, while doing a "step" or "next", has ended up in |
8fb3e588 AC |
3638 | a signal trampoline (either by a signal being delivered or by |
3639 | the signal handler returning). Just single-step until the | |
3640 | inferior leaves the trampoline (either by calling the handler | |
3641 | or returning). */ | |
488f131b JB |
3642 | keep_going (ecs); |
3643 | return; | |
3644 | } | |
c906108c | 3645 | |
c17eaafe DJ |
3646 | /* Check for subroutine calls. The check for the current frame |
3647 | equalling the step ID is not necessary - the check of the | |
3648 | previous frame's ID is sufficient - but it is a common case and | |
3649 | cheaper than checking the previous frame's ID. | |
14e60db5 DJ |
3650 | |
3651 | NOTE: frame_id_eq will never report two invalid frame IDs as | |
3652 | being equal, so to get into this block, both the current and | |
3653 | previous frame must have valid frame IDs. */ | |
4e1c45ea PA |
3654 | if (!frame_id_eq (get_frame_id (get_current_frame ()), |
3655 | ecs->event_thread->step_frame_id) | |
b2175913 MS |
3656 | && (frame_id_eq (frame_unwind_id (get_current_frame ()), |
3657 | ecs->event_thread->step_frame_id) | |
3658 | || execution_direction == EXEC_REVERSE)) | |
488f131b | 3659 | { |
95918acb | 3660 | CORE_ADDR real_stop_pc; |
8fb3e588 | 3661 | |
527159b7 | 3662 | if (debug_infrun) |
8a9de0e4 | 3663 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); |
527159b7 | 3664 | |
078130d0 | 3665 | if ((ecs->event_thread->step_over_calls == STEP_OVER_NONE) |
4e1c45ea PA |
3666 | || ((ecs->event_thread->step_range_end == 1) |
3667 | && in_prologue (ecs->event_thread->prev_pc, | |
3668 | ecs->stop_func_start))) | |
95918acb AC |
3669 | { |
3670 | /* I presume that step_over_calls is only 0 when we're | |
3671 | supposed to be stepping at the assembly language level | |
3672 | ("stepi"). Just stop. */ | |
3673 | /* Also, maybe we just did a "nexti" inside a prolog, so we | |
3674 | thought it was a subroutine call but it was not. Stop as | |
3675 | well. FENN */ | |
414c69f7 | 3676 | ecs->event_thread->stop_step = 1; |
95918acb AC |
3677 | print_stop_reason (END_STEPPING_RANGE, 0); |
3678 | stop_stepping (ecs); | |
3679 | return; | |
3680 | } | |
8fb3e588 | 3681 | |
078130d0 | 3682 | if (ecs->event_thread->step_over_calls == STEP_OVER_ALL) |
8567c30f | 3683 | { |
b2175913 MS |
3684 | /* We're doing a "next". |
3685 | ||
3686 | Normal (forward) execution: set a breakpoint at the | |
3687 | callee's return address (the address at which the caller | |
3688 | will resume). | |
3689 | ||
3690 | Reverse (backward) execution. set the step-resume | |
3691 | breakpoint at the start of the function that we just | |
3692 | stepped into (backwards), and continue to there. When we | |
6130d0b7 | 3693 | get there, we'll need to single-step back to the caller. */ |
b2175913 MS |
3694 | |
3695 | if (execution_direction == EXEC_REVERSE) | |
3696 | { | |
3697 | struct symtab_and_line sr_sal; | |
3067f6e5 MS |
3698 | |
3699 | if (ecs->stop_func_start == 0 | |
3700 | && in_solib_dynsym_resolve_code (stop_pc)) | |
3701 | { | |
3702 | /* Stepped into runtime loader dynamic symbol | |
3703 | resolution code. Since we're in reverse, | |
3704 | we have already backed up through the runtime | |
3705 | loader and the dynamic function. This is just | |
3706 | the trampoline (jump table). | |
3707 | ||
3708 | Just keep stepping, we'll soon be home. | |
3709 | */ | |
3710 | keep_going (ecs); | |
3711 | return; | |
3712 | } | |
3713 | /* Normal (staticly linked) function call return. */ | |
b2175913 MS |
3714 | init_sal (&sr_sal); |
3715 | sr_sal.pc = ecs->stop_func_start; | |
3716 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); | |
3717 | } | |
3718 | else | |
3719 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); | |
3720 | ||
8567c30f AC |
3721 | keep_going (ecs); |
3722 | return; | |
3723 | } | |
a53c66de | 3724 | |
95918acb | 3725 | /* If we are in a function call trampoline (a stub between the |
8fb3e588 AC |
3726 | calling routine and the real function), locate the real |
3727 | function. That's what tells us (a) whether we want to step | |
3728 | into it at all, and (b) what prologue we want to run to the | |
3729 | end of, if we do step into it. */ | |
52f729a7 | 3730 | real_stop_pc = skip_language_trampoline (get_current_frame (), stop_pc); |
95918acb | 3731 | if (real_stop_pc == 0) |
52f729a7 UW |
3732 | real_stop_pc = gdbarch_skip_trampoline_code |
3733 | (current_gdbarch, get_current_frame (), stop_pc); | |
95918acb AC |
3734 | if (real_stop_pc != 0) |
3735 | ecs->stop_func_start = real_stop_pc; | |
8fb3e588 | 3736 | |
db5f024e | 3737 | if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc)) |
1b2bfbb9 RC |
3738 | { |
3739 | struct symtab_and_line sr_sal; | |
3740 | init_sal (&sr_sal); | |
3741 | sr_sal.pc = ecs->stop_func_start; | |
3742 | ||
44cbf7b5 | 3743 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
8fb3e588 AC |
3744 | keep_going (ecs); |
3745 | return; | |
1b2bfbb9 RC |
3746 | } |
3747 | ||
95918acb | 3748 | /* If we have line number information for the function we are |
8fb3e588 | 3749 | thinking of stepping into, step into it. |
95918acb | 3750 | |
8fb3e588 AC |
3751 | If there are several symtabs at that PC (e.g. with include |
3752 | files), just want to know whether *any* of them have line | |
3753 | numbers. find_pc_line handles this. */ | |
95918acb AC |
3754 | { |
3755 | struct symtab_and_line tmp_sal; | |
8fb3e588 | 3756 | |
95918acb AC |
3757 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
3758 | if (tmp_sal.line != 0) | |
3759 | { | |
b2175913 MS |
3760 | if (execution_direction == EXEC_REVERSE) |
3761 | handle_step_into_function_backward (ecs); | |
3762 | else | |
3763 | handle_step_into_function (ecs); | |
95918acb AC |
3764 | return; |
3765 | } | |
3766 | } | |
3767 | ||
3768 | /* If we have no line number and the step-stop-if-no-debug is | |
8fb3e588 AC |
3769 | set, we stop the step so that the user has a chance to switch |
3770 | in assembly mode. */ | |
078130d0 PA |
3771 | if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE |
3772 | && step_stop_if_no_debug) | |
95918acb | 3773 | { |
414c69f7 | 3774 | ecs->event_thread->stop_step = 1; |
95918acb AC |
3775 | print_stop_reason (END_STEPPING_RANGE, 0); |
3776 | stop_stepping (ecs); | |
3777 | return; | |
3778 | } | |
3779 | ||
b2175913 MS |
3780 | if (execution_direction == EXEC_REVERSE) |
3781 | { | |
3782 | /* Set a breakpoint at callee's start address. | |
3783 | From there we can step once and be back in the caller. */ | |
3784 | struct symtab_and_line sr_sal; | |
3785 | init_sal (&sr_sal); | |
3786 | sr_sal.pc = ecs->stop_func_start; | |
3787 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); | |
3788 | } | |
3789 | else | |
3790 | /* Set a breakpoint at callee's return address (the address | |
3791 | at which the caller will resume). */ | |
3792 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); | |
3793 | ||
95918acb | 3794 | keep_going (ecs); |
488f131b | 3795 | return; |
488f131b | 3796 | } |
c906108c | 3797 | |
488f131b JB |
3798 | /* If we're in the return path from a shared library trampoline, |
3799 | we want to proceed through the trampoline when stepping. */ | |
e76f05fa UW |
3800 | if (gdbarch_in_solib_return_trampoline (current_gdbarch, |
3801 | stop_pc, ecs->stop_func_name)) | |
488f131b | 3802 | { |
488f131b | 3803 | /* Determine where this trampoline returns. */ |
52f729a7 UW |
3804 | CORE_ADDR real_stop_pc; |
3805 | real_stop_pc = gdbarch_skip_trampoline_code | |
3806 | (current_gdbarch, get_current_frame (), stop_pc); | |
c906108c | 3807 | |
527159b7 | 3808 | if (debug_infrun) |
8a9de0e4 | 3809 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n"); |
527159b7 | 3810 | |
488f131b | 3811 | /* Only proceed through if we know where it's going. */ |
d764a824 | 3812 | if (real_stop_pc) |
488f131b JB |
3813 | { |
3814 | /* And put the step-breakpoint there and go until there. */ | |
3815 | struct symtab_and_line sr_sal; | |
3816 | ||
fe39c653 | 3817 | init_sal (&sr_sal); /* initialize to zeroes */ |
d764a824 | 3818 | sr_sal.pc = real_stop_pc; |
488f131b | 3819 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
44cbf7b5 AC |
3820 | |
3821 | /* Do not specify what the fp should be when we stop since | |
3822 | on some machines the prologue is where the new fp value | |
3823 | is established. */ | |
3824 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); | |
c906108c | 3825 | |
488f131b JB |
3826 | /* Restart without fiddling with the step ranges or |
3827 | other state. */ | |
3828 | keep_going (ecs); | |
3829 | return; | |
3830 | } | |
3831 | } | |
c906108c | 3832 | |
2afb61aa | 3833 | stop_pc_sal = find_pc_line (stop_pc, 0); |
7ed0fe66 | 3834 | |
1b2bfbb9 RC |
3835 | /* NOTE: tausq/2004-05-24: This if block used to be done before all |
3836 | the trampoline processing logic, however, there are some trampolines | |
3837 | that have no names, so we should do trampoline handling first. */ | |
078130d0 | 3838 | if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE |
7ed0fe66 | 3839 | && ecs->stop_func_name == NULL |
2afb61aa | 3840 | && stop_pc_sal.line == 0) |
1b2bfbb9 | 3841 | { |
527159b7 | 3842 | if (debug_infrun) |
8a9de0e4 | 3843 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n"); |
527159b7 | 3844 | |
1b2bfbb9 | 3845 | /* The inferior just stepped into, or returned to, an |
7ed0fe66 DJ |
3846 | undebuggable function (where there is no debugging information |
3847 | and no line number corresponding to the address where the | |
1b2bfbb9 RC |
3848 | inferior stopped). Since we want to skip this kind of code, |
3849 | we keep going until the inferior returns from this | |
14e60db5 DJ |
3850 | function - unless the user has asked us not to (via |
3851 | set step-mode) or we no longer know how to get back | |
3852 | to the call site. */ | |
3853 | if (step_stop_if_no_debug | |
eb2f4a08 | 3854 | || !frame_id_p (frame_unwind_id (get_current_frame ()))) |
1b2bfbb9 RC |
3855 | { |
3856 | /* If we have no line number and the step-stop-if-no-debug | |
3857 | is set, we stop the step so that the user has a chance to | |
3858 | switch in assembly mode. */ | |
414c69f7 | 3859 | ecs->event_thread->stop_step = 1; |
1b2bfbb9 RC |
3860 | print_stop_reason (END_STEPPING_RANGE, 0); |
3861 | stop_stepping (ecs); | |
3862 | return; | |
3863 | } | |
3864 | else | |
3865 | { | |
3866 | /* Set a breakpoint at callee's return address (the address | |
3867 | at which the caller will resume). */ | |
14e60db5 | 3868 | insert_step_resume_breakpoint_at_caller (get_current_frame ()); |
1b2bfbb9 RC |
3869 | keep_going (ecs); |
3870 | return; | |
3871 | } | |
3872 | } | |
3873 | ||
4e1c45ea | 3874 | if (ecs->event_thread->step_range_end == 1) |
1b2bfbb9 RC |
3875 | { |
3876 | /* It is stepi or nexti. We always want to stop stepping after | |
3877 | one instruction. */ | |
527159b7 | 3878 | if (debug_infrun) |
8a9de0e4 | 3879 | fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); |
414c69f7 | 3880 | ecs->event_thread->stop_step = 1; |
1b2bfbb9 RC |
3881 | print_stop_reason (END_STEPPING_RANGE, 0); |
3882 | stop_stepping (ecs); | |
3883 | return; | |
3884 | } | |
3885 | ||
2afb61aa | 3886 | if (stop_pc_sal.line == 0) |
488f131b JB |
3887 | { |
3888 | /* We have no line number information. That means to stop | |
3889 | stepping (does this always happen right after one instruction, | |
3890 | when we do "s" in a function with no line numbers, | |
3891 | or can this happen as a result of a return or longjmp?). */ | |
527159b7 | 3892 | if (debug_infrun) |
8a9de0e4 | 3893 | fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); |
414c69f7 | 3894 | ecs->event_thread->stop_step = 1; |
488f131b JB |
3895 | print_stop_reason (END_STEPPING_RANGE, 0); |
3896 | stop_stepping (ecs); | |
3897 | return; | |
3898 | } | |
c906108c | 3899 | |
2afb61aa | 3900 | if ((stop_pc == stop_pc_sal.pc) |
4e1c45ea PA |
3901 | && (ecs->event_thread->current_line != stop_pc_sal.line |
3902 | || ecs->event_thread->current_symtab != stop_pc_sal.symtab)) | |
488f131b JB |
3903 | { |
3904 | /* We are at the start of a different line. So stop. Note that | |
3905 | we don't stop if we step into the middle of a different line. | |
3906 | That is said to make things like for (;;) statements work | |
3907 | better. */ | |
527159b7 | 3908 | if (debug_infrun) |
8a9de0e4 | 3909 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n"); |
414c69f7 | 3910 | ecs->event_thread->stop_step = 1; |
488f131b JB |
3911 | print_stop_reason (END_STEPPING_RANGE, 0); |
3912 | stop_stepping (ecs); | |
3913 | return; | |
3914 | } | |
c906108c | 3915 | |
488f131b | 3916 | /* We aren't done stepping. |
c906108c | 3917 | |
488f131b JB |
3918 | Optimize by setting the stepping range to the line. |
3919 | (We might not be in the original line, but if we entered a | |
3920 | new line in mid-statement, we continue stepping. This makes | |
3921 | things like for(;;) statements work better.) */ | |
c906108c | 3922 | |
4e1c45ea PA |
3923 | ecs->event_thread->step_range_start = stop_pc_sal.pc; |
3924 | ecs->event_thread->step_range_end = stop_pc_sal.end; | |
3925 | ecs->event_thread->step_frame_id = get_frame_id (get_current_frame ()); | |
3926 | ecs->event_thread->current_line = stop_pc_sal.line; | |
3927 | ecs->event_thread->current_symtab = stop_pc_sal.symtab; | |
488f131b | 3928 | |
527159b7 | 3929 | if (debug_infrun) |
8a9de0e4 | 3930 | fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); |
488f131b | 3931 | keep_going (ecs); |
104c1213 JM |
3932 | } |
3933 | ||
3934 | /* Are we in the middle of stepping? */ | |
3935 | ||
a7212384 UW |
3936 | static int |
3937 | currently_stepping_thread (struct thread_info *tp) | |
3938 | { | |
3939 | return (tp->step_range_end && tp->step_resume_breakpoint == NULL) | |
3940 | || tp->trap_expected | |
3941 | || tp->stepping_through_solib_after_catch; | |
3942 | } | |
3943 | ||
3944 | static int | |
3945 | currently_stepping_callback (struct thread_info *tp, void *data) | |
3946 | { | |
3947 | /* Return true if any thread *but* the one passed in "data" is | |
3948 | in the middle of stepping. */ | |
3949 | return tp != data && currently_stepping_thread (tp); | |
3950 | } | |
3951 | ||
104c1213 | 3952 | static int |
4e1c45ea | 3953 | currently_stepping (struct thread_info *tp) |
104c1213 | 3954 | { |
a7212384 | 3955 | return currently_stepping_thread (tp) || bpstat_should_step (); |
104c1213 | 3956 | } |
c906108c | 3957 | |
b2175913 MS |
3958 | /* Inferior has stepped into a subroutine call with source code that |
3959 | we should not step over. Do step to the first line of code in | |
3960 | it. */ | |
c2c6d25f JM |
3961 | |
3962 | static void | |
b2175913 | 3963 | handle_step_into_function (struct execution_control_state *ecs) |
c2c6d25f JM |
3964 | { |
3965 | struct symtab *s; | |
2afb61aa | 3966 | struct symtab_and_line stop_func_sal, sr_sal; |
c2c6d25f JM |
3967 | |
3968 | s = find_pc_symtab (stop_pc); | |
3969 | if (s && s->language != language_asm) | |
b2175913 MS |
3970 | ecs->stop_func_start = gdbarch_skip_prologue (current_gdbarch, |
3971 | ecs->stop_func_start); | |
c2c6d25f | 3972 | |
2afb61aa | 3973 | stop_func_sal = find_pc_line (ecs->stop_func_start, 0); |
c2c6d25f JM |
3974 | /* Use the step_resume_break to step until the end of the prologue, |
3975 | even if that involves jumps (as it seems to on the vax under | |
3976 | 4.2). */ | |
3977 | /* If the prologue ends in the middle of a source line, continue to | |
3978 | the end of that source line (if it is still within the function). | |
3979 | Otherwise, just go to end of prologue. */ | |
2afb61aa PA |
3980 | if (stop_func_sal.end |
3981 | && stop_func_sal.pc != ecs->stop_func_start | |
3982 | && stop_func_sal.end < ecs->stop_func_end) | |
3983 | ecs->stop_func_start = stop_func_sal.end; | |
c2c6d25f | 3984 | |
2dbd5e30 KB |
3985 | /* Architectures which require breakpoint adjustment might not be able |
3986 | to place a breakpoint at the computed address. If so, the test | |
3987 | ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust | |
3988 | ecs->stop_func_start to an address at which a breakpoint may be | |
3989 | legitimately placed. | |
8fb3e588 | 3990 | |
2dbd5e30 KB |
3991 | Note: kevinb/2004-01-19: On FR-V, if this adjustment is not |
3992 | made, GDB will enter an infinite loop when stepping through | |
3993 | optimized code consisting of VLIW instructions which contain | |
3994 | subinstructions corresponding to different source lines. On | |
3995 | FR-V, it's not permitted to place a breakpoint on any but the | |
3996 | first subinstruction of a VLIW instruction. When a breakpoint is | |
3997 | set, GDB will adjust the breakpoint address to the beginning of | |
3998 | the VLIW instruction. Thus, we need to make the corresponding | |
3999 | adjustment here when computing the stop address. */ | |
8fb3e588 | 4000 | |
2dbd5e30 KB |
4001 | if (gdbarch_adjust_breakpoint_address_p (current_gdbarch)) |
4002 | { | |
4003 | ecs->stop_func_start | |
4004 | = gdbarch_adjust_breakpoint_address (current_gdbarch, | |
8fb3e588 | 4005 | ecs->stop_func_start); |
2dbd5e30 KB |
4006 | } |
4007 | ||
c2c6d25f JM |
4008 | if (ecs->stop_func_start == stop_pc) |
4009 | { | |
4010 | /* We are already there: stop now. */ | |
414c69f7 | 4011 | ecs->event_thread->stop_step = 1; |
488f131b | 4012 | print_stop_reason (END_STEPPING_RANGE, 0); |
c2c6d25f JM |
4013 | stop_stepping (ecs); |
4014 | return; | |
4015 | } | |
4016 | else | |
4017 | { | |
4018 | /* Put the step-breakpoint there and go until there. */ | |
fe39c653 | 4019 | init_sal (&sr_sal); /* initialize to zeroes */ |
c2c6d25f JM |
4020 | sr_sal.pc = ecs->stop_func_start; |
4021 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
44cbf7b5 | 4022 | |
c2c6d25f | 4023 | /* Do not specify what the fp should be when we stop since on |
488f131b JB |
4024 | some machines the prologue is where the new fp value is |
4025 | established. */ | |
44cbf7b5 | 4026 | insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); |
c2c6d25f JM |
4027 | |
4028 | /* And make sure stepping stops right away then. */ | |
4e1c45ea | 4029 | ecs->event_thread->step_range_end = ecs->event_thread->step_range_start; |
c2c6d25f JM |
4030 | } |
4031 | keep_going (ecs); | |
4032 | } | |
d4f3574e | 4033 | |
b2175913 MS |
4034 | /* Inferior has stepped backward into a subroutine call with source |
4035 | code that we should not step over. Do step to the beginning of the | |
4036 | last line of code in it. */ | |
4037 | ||
4038 | static void | |
4039 | handle_step_into_function_backward (struct execution_control_state *ecs) | |
4040 | { | |
4041 | struct symtab *s; | |
4042 | struct symtab_and_line stop_func_sal, sr_sal; | |
4043 | ||
4044 | s = find_pc_symtab (stop_pc); | |
4045 | if (s && s->language != language_asm) | |
4046 | ecs->stop_func_start = gdbarch_skip_prologue (current_gdbarch, | |
4047 | ecs->stop_func_start); | |
4048 | ||
4049 | stop_func_sal = find_pc_line (stop_pc, 0); | |
4050 | ||
4051 | /* OK, we're just going to keep stepping here. */ | |
4052 | if (stop_func_sal.pc == stop_pc) | |
4053 | { | |
4054 | /* We're there already. Just stop stepping now. */ | |
4055 | ecs->event_thread->stop_step = 1; | |
4056 | print_stop_reason (END_STEPPING_RANGE, 0); | |
4057 | stop_stepping (ecs); | |
4058 | } | |
4059 | else | |
4060 | { | |
4061 | /* Else just reset the step range and keep going. | |
4062 | No step-resume breakpoint, they don't work for | |
4063 | epilogues, which can have multiple entry paths. */ | |
4064 | ecs->event_thread->step_range_start = stop_func_sal.pc; | |
4065 | ecs->event_thread->step_range_end = stop_func_sal.end; | |
4066 | keep_going (ecs); | |
4067 | } | |
4068 | return; | |
4069 | } | |
4070 | ||
d3169d93 | 4071 | /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. |
44cbf7b5 AC |
4072 | This is used to both functions and to skip over code. */ |
4073 | ||
4074 | static void | |
4075 | insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, | |
4076 | struct frame_id sr_id) | |
4077 | { | |
611c83ae PA |
4078 | /* There should never be more than one step-resume or longjmp-resume |
4079 | breakpoint per thread, so we should never be setting a new | |
44cbf7b5 | 4080 | step_resume_breakpoint when one is already active. */ |
4e1c45ea | 4081 | gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL); |
d3169d93 DJ |
4082 | |
4083 | if (debug_infrun) | |
4084 | fprintf_unfiltered (gdb_stdlog, | |
4085 | "infrun: inserting step-resume breakpoint at 0x%s\n", | |
4086 | paddr_nz (sr_sal.pc)); | |
4087 | ||
4e1c45ea PA |
4088 | inferior_thread ()->step_resume_breakpoint |
4089 | = set_momentary_breakpoint (sr_sal, sr_id, bp_step_resume); | |
44cbf7b5 | 4090 | } |
7ce450bd | 4091 | |
d3169d93 | 4092 | /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used |
14e60db5 | 4093 | to skip a potential signal handler. |
7ce450bd | 4094 | |
14e60db5 DJ |
4095 | This is called with the interrupted function's frame. The signal |
4096 | handler, when it returns, will resume the interrupted function at | |
4097 | RETURN_FRAME.pc. */ | |
d303a6c7 AC |
4098 | |
4099 | static void | |
44cbf7b5 | 4100 | insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame) |
d303a6c7 AC |
4101 | { |
4102 | struct symtab_and_line sr_sal; | |
4103 | ||
f4c1edd8 | 4104 | gdb_assert (return_frame != NULL); |
d303a6c7 AC |
4105 | init_sal (&sr_sal); /* initialize to zeros */ |
4106 | ||
bf6ae464 UW |
4107 | sr_sal.pc = gdbarch_addr_bits_remove |
4108 | (current_gdbarch, get_frame_pc (return_frame)); | |
d303a6c7 AC |
4109 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
4110 | ||
44cbf7b5 | 4111 | insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame)); |
d303a6c7 AC |
4112 | } |
4113 | ||
14e60db5 DJ |
4114 | /* Similar to insert_step_resume_breakpoint_at_frame, except |
4115 | but a breakpoint at the previous frame's PC. This is used to | |
4116 | skip a function after stepping into it (for "next" or if the called | |
4117 | function has no debugging information). | |
4118 | ||
4119 | The current function has almost always been reached by single | |
4120 | stepping a call or return instruction. NEXT_FRAME belongs to the | |
4121 | current function, and the breakpoint will be set at the caller's | |
4122 | resume address. | |
4123 | ||
4124 | This is a separate function rather than reusing | |
4125 | insert_step_resume_breakpoint_at_frame in order to avoid | |
4126 | get_prev_frame, which may stop prematurely (see the implementation | |
eb2f4a08 | 4127 | of frame_unwind_id for an example). */ |
14e60db5 DJ |
4128 | |
4129 | static void | |
4130 | insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) | |
4131 | { | |
4132 | struct symtab_and_line sr_sal; | |
4133 | ||
4134 | /* We shouldn't have gotten here if we don't know where the call site | |
4135 | is. */ | |
eb2f4a08 | 4136 | gdb_assert (frame_id_p (frame_unwind_id (next_frame))); |
14e60db5 DJ |
4137 | |
4138 | init_sal (&sr_sal); /* initialize to zeros */ | |
4139 | ||
bf6ae464 | 4140 | sr_sal.pc = gdbarch_addr_bits_remove |
eb2f4a08 | 4141 | (current_gdbarch, frame_pc_unwind (next_frame)); |
14e60db5 DJ |
4142 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
4143 | ||
eb2f4a08 | 4144 | insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame)); |
14e60db5 DJ |
4145 | } |
4146 | ||
611c83ae PA |
4147 | /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a |
4148 | new breakpoint at the target of a jmp_buf. The handling of | |
4149 | longjmp-resume uses the same mechanisms used for handling | |
4150 | "step-resume" breakpoints. */ | |
4151 | ||
4152 | static void | |
4153 | insert_longjmp_resume_breakpoint (CORE_ADDR pc) | |
4154 | { | |
4155 | /* There should never be more than one step-resume or longjmp-resume | |
4156 | breakpoint per thread, so we should never be setting a new | |
4157 | longjmp_resume_breakpoint when one is already active. */ | |
4e1c45ea | 4158 | gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL); |
611c83ae PA |
4159 | |
4160 | if (debug_infrun) | |
4161 | fprintf_unfiltered (gdb_stdlog, | |
4162 | "infrun: inserting longjmp-resume breakpoint at 0x%s\n", | |
4163 | paddr_nz (pc)); | |
4164 | ||
4e1c45ea | 4165 | inferior_thread ()->step_resume_breakpoint = |
611c83ae PA |
4166 | set_momentary_breakpoint_at_pc (pc, bp_longjmp_resume); |
4167 | } | |
4168 | ||
104c1213 JM |
4169 | static void |
4170 | stop_stepping (struct execution_control_state *ecs) | |
4171 | { | |
527159b7 | 4172 | if (debug_infrun) |
8a9de0e4 | 4173 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n"); |
527159b7 | 4174 | |
cd0fc7c3 SS |
4175 | /* Let callers know we don't want to wait for the inferior anymore. */ |
4176 | ecs->wait_some_more = 0; | |
4177 | } | |
4178 | ||
d4f3574e SS |
4179 | /* This function handles various cases where we need to continue |
4180 | waiting for the inferior. */ | |
4181 | /* (Used to be the keep_going: label in the old wait_for_inferior) */ | |
4182 | ||
4183 | static void | |
4184 | keep_going (struct execution_control_state *ecs) | |
4185 | { | |
d4f3574e | 4186 | /* Save the pc before execution, to compare with pc after stop. */ |
fb14de7b UW |
4187 | ecs->event_thread->prev_pc |
4188 | = regcache_read_pc (get_thread_regcache (ecs->ptid)); | |
d4f3574e | 4189 | |
d4f3574e SS |
4190 | /* If we did not do break;, it means we should keep running the |
4191 | inferior and not return to debugger. */ | |
4192 | ||
2020b7ab PA |
4193 | if (ecs->event_thread->trap_expected |
4194 | && ecs->event_thread->stop_signal != TARGET_SIGNAL_TRAP) | |
d4f3574e SS |
4195 | { |
4196 | /* We took a signal (which we are supposed to pass through to | |
4e1c45ea PA |
4197 | the inferior, else we'd not get here) and we haven't yet |
4198 | gotten our trap. Simply continue. */ | |
2020b7ab PA |
4199 | resume (currently_stepping (ecs->event_thread), |
4200 | ecs->event_thread->stop_signal); | |
d4f3574e SS |
4201 | } |
4202 | else | |
4203 | { | |
4204 | /* Either the trap was not expected, but we are continuing | |
488f131b JB |
4205 | anyway (the user asked that this signal be passed to the |
4206 | child) | |
4207 | -- or -- | |
4208 | The signal was SIGTRAP, e.g. it was our signal, but we | |
4209 | decided we should resume from it. | |
d4f3574e | 4210 | |
c36b740a | 4211 | We're going to run this baby now! |
d4f3574e | 4212 | |
c36b740a VP |
4213 | Note that insert_breakpoints won't try to re-insert |
4214 | already inserted breakpoints. Therefore, we don't | |
4215 | care if breakpoints were already inserted, or not. */ | |
4216 | ||
4e1c45ea | 4217 | if (ecs->event_thread->stepping_over_breakpoint) |
45e8c884 | 4218 | { |
237fc4c9 PA |
4219 | if (! use_displaced_stepping (current_gdbarch)) |
4220 | /* Since we can't do a displaced step, we have to remove | |
4221 | the breakpoint while we step it. To keep things | |
4222 | simple, we remove them all. */ | |
4223 | remove_breakpoints (); | |
45e8c884 VP |
4224 | } |
4225 | else | |
d4f3574e | 4226 | { |
e236ba44 | 4227 | struct gdb_exception e; |
569631c6 UW |
4228 | /* Stop stepping when inserting breakpoints |
4229 | has failed. */ | |
e236ba44 VP |
4230 | TRY_CATCH (e, RETURN_MASK_ERROR) |
4231 | { | |
4232 | insert_breakpoints (); | |
4233 | } | |
4234 | if (e.reason < 0) | |
d4f3574e SS |
4235 | { |
4236 | stop_stepping (ecs); | |
4237 | return; | |
4238 | } | |
d4f3574e SS |
4239 | } |
4240 | ||
4e1c45ea | 4241 | ecs->event_thread->trap_expected = ecs->event_thread->stepping_over_breakpoint; |
d4f3574e SS |
4242 | |
4243 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly | |
488f131b JB |
4244 | specifies that such a signal should be delivered to the |
4245 | target program). | |
4246 | ||
4247 | Typically, this would occure when a user is debugging a | |
4248 | target monitor on a simulator: the target monitor sets a | |
4249 | breakpoint; the simulator encounters this break-point and | |
4250 | halts the simulation handing control to GDB; GDB, noteing | |
4251 | that the break-point isn't valid, returns control back to the | |
4252 | simulator; the simulator then delivers the hardware | |
4253 | equivalent of a SIGNAL_TRAP to the program being debugged. */ | |
4254 | ||
2020b7ab PA |
4255 | if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP |
4256 | && !signal_program[ecs->event_thread->stop_signal]) | |
4257 | ecs->event_thread->stop_signal = TARGET_SIGNAL_0; | |
d4f3574e | 4258 | |
2020b7ab PA |
4259 | resume (currently_stepping (ecs->event_thread), |
4260 | ecs->event_thread->stop_signal); | |
d4f3574e SS |
4261 | } |
4262 | ||
488f131b | 4263 | prepare_to_wait (ecs); |
d4f3574e SS |
4264 | } |
4265 | ||
104c1213 JM |
4266 | /* This function normally comes after a resume, before |
4267 | handle_inferior_event exits. It takes care of any last bits of | |
4268 | housekeeping, and sets the all-important wait_some_more flag. */ | |
cd0fc7c3 | 4269 | |
104c1213 JM |
4270 | static void |
4271 | prepare_to_wait (struct execution_control_state *ecs) | |
cd0fc7c3 | 4272 | { |
527159b7 | 4273 | if (debug_infrun) |
8a9de0e4 | 4274 | fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); |
0d1e5fa7 | 4275 | if (infwait_state == infwait_normal_state) |
104c1213 JM |
4276 | { |
4277 | overlay_cache_invalid = 1; | |
4278 | ||
4279 | /* We have to invalidate the registers BEFORE calling | |
488f131b JB |
4280 | target_wait because they can be loaded from the target while |
4281 | in target_wait. This makes remote debugging a bit more | |
4282 | efficient for those targets that provide critical registers | |
4283 | as part of their normal status mechanism. */ | |
104c1213 JM |
4284 | |
4285 | registers_changed (); | |
0d1e5fa7 | 4286 | waiton_ptid = pid_to_ptid (-1); |
104c1213 JM |
4287 | } |
4288 | /* This is the old end of the while loop. Let everybody know we | |
4289 | want to wait for the inferior some more and get called again | |
4290 | soon. */ | |
4291 | ecs->wait_some_more = 1; | |
c906108c | 4292 | } |
11cf8741 JM |
4293 | |
4294 | /* Print why the inferior has stopped. We always print something when | |
4295 | the inferior exits, or receives a signal. The rest of the cases are | |
4296 | dealt with later on in normal_stop() and print_it_typical(). Ideally | |
4297 | there should be a call to this function from handle_inferior_event() | |
4298 | each time stop_stepping() is called.*/ | |
4299 | static void | |
4300 | print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) | |
4301 | { | |
4302 | switch (stop_reason) | |
4303 | { | |
11cf8741 JM |
4304 | case END_STEPPING_RANGE: |
4305 | /* We are done with a step/next/si/ni command. */ | |
4306 | /* For now print nothing. */ | |
fb40c209 | 4307 | /* Print a message only if not in the middle of doing a "step n" |
488f131b | 4308 | operation for n > 1 */ |
414c69f7 PA |
4309 | if (!inferior_thread ()->step_multi |
4310 | || !inferior_thread ()->stop_step) | |
9dc5e2a9 | 4311 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4312 | ui_out_field_string |
4313 | (uiout, "reason", | |
4314 | async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); | |
11cf8741 | 4315 | break; |
11cf8741 JM |
4316 | case SIGNAL_EXITED: |
4317 | /* The inferior was terminated by a signal. */ | |
8b93c638 | 4318 | annotate_signalled (); |
9dc5e2a9 | 4319 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4320 | ui_out_field_string |
4321 | (uiout, "reason", | |
4322 | async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); | |
8b93c638 JM |
4323 | ui_out_text (uiout, "\nProgram terminated with signal "); |
4324 | annotate_signal_name (); | |
488f131b JB |
4325 | ui_out_field_string (uiout, "signal-name", |
4326 | target_signal_to_name (stop_info)); | |
8b93c638 JM |
4327 | annotate_signal_name_end (); |
4328 | ui_out_text (uiout, ", "); | |
4329 | annotate_signal_string (); | |
488f131b JB |
4330 | ui_out_field_string (uiout, "signal-meaning", |
4331 | target_signal_to_string (stop_info)); | |
8b93c638 JM |
4332 | annotate_signal_string_end (); |
4333 | ui_out_text (uiout, ".\n"); | |
4334 | ui_out_text (uiout, "The program no longer exists.\n"); | |
11cf8741 JM |
4335 | break; |
4336 | case EXITED: | |
4337 | /* The inferior program is finished. */ | |
8b93c638 JM |
4338 | annotate_exited (stop_info); |
4339 | if (stop_info) | |
4340 | { | |
9dc5e2a9 | 4341 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4342 | ui_out_field_string (uiout, "reason", |
4343 | async_reason_lookup (EXEC_ASYNC_EXITED)); | |
8b93c638 | 4344 | ui_out_text (uiout, "\nProgram exited with code "); |
488f131b JB |
4345 | ui_out_field_fmt (uiout, "exit-code", "0%o", |
4346 | (unsigned int) stop_info); | |
8b93c638 JM |
4347 | ui_out_text (uiout, ".\n"); |
4348 | } | |
4349 | else | |
4350 | { | |
9dc5e2a9 | 4351 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
4352 | ui_out_field_string |
4353 | (uiout, "reason", | |
4354 | async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); | |
8b93c638 JM |
4355 | ui_out_text (uiout, "\nProgram exited normally.\n"); |
4356 | } | |
f17517ea AS |
4357 | /* Support the --return-child-result option. */ |
4358 | return_child_result_value = stop_info; | |
11cf8741 JM |
4359 | break; |
4360 | case SIGNAL_RECEIVED: | |
252fbfc8 PA |
4361 | /* Signal received. The signal table tells us to print about |
4362 | it. */ | |
8b93c638 | 4363 | annotate_signal (); |
252fbfc8 PA |
4364 | |
4365 | if (stop_info == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout)) | |
4366 | { | |
4367 | struct thread_info *t = inferior_thread (); | |
4368 | ||
4369 | ui_out_text (uiout, "\n["); | |
4370 | ui_out_field_string (uiout, "thread-name", | |
4371 | target_pid_to_str (t->ptid)); | |
4372 | ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num); | |
4373 | ui_out_text (uiout, " stopped"); | |
4374 | } | |
4375 | else | |
4376 | { | |
4377 | ui_out_text (uiout, "\nProgram received signal "); | |
4378 | annotate_signal_name (); | |
4379 | if (ui_out_is_mi_like_p (uiout)) | |
4380 | ui_out_field_string | |
4381 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); | |
4382 | ui_out_field_string (uiout, "signal-name", | |
4383 | target_signal_to_name (stop_info)); | |
4384 | annotate_signal_name_end (); | |
4385 | ui_out_text (uiout, ", "); | |
4386 | annotate_signal_string (); | |
4387 | ui_out_field_string (uiout, "signal-meaning", | |
4388 | target_signal_to_string (stop_info)); | |
4389 | annotate_signal_string_end (); | |
4390 | } | |
8b93c638 | 4391 | ui_out_text (uiout, ".\n"); |
11cf8741 | 4392 | break; |
b2175913 MS |
4393 | case NO_HISTORY: |
4394 | /* Reverse execution: target ran out of history info. */ | |
4395 | ui_out_text (uiout, "\nNo more reverse-execution history.\n"); | |
4396 | break; | |
11cf8741 | 4397 | default: |
8e65ff28 | 4398 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4399 | _("print_stop_reason: unrecognized enum value")); |
11cf8741 JM |
4400 | break; |
4401 | } | |
4402 | } | |
c906108c | 4403 | \f |
43ff13b4 | 4404 | |
c906108c SS |
4405 | /* Here to return control to GDB when the inferior stops for real. |
4406 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
4407 | ||
4408 | STOP_PRINT_FRAME nonzero means print the executing frame | |
4409 | (pc, function, args, file, line number and line text). | |
4410 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
4411 | attempting to insert breakpoints. */ | |
4412 | ||
4413 | void | |
96baa820 | 4414 | normal_stop (void) |
c906108c | 4415 | { |
73b65bb0 DJ |
4416 | struct target_waitstatus last; |
4417 | ptid_t last_ptid; | |
29f49a6a | 4418 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
73b65bb0 DJ |
4419 | |
4420 | get_last_target_status (&last_ptid, &last); | |
4421 | ||
29f49a6a PA |
4422 | /* If an exception is thrown from this point on, make sure to |
4423 | propagate GDB's knowledge of the executing state to the | |
4424 | frontend/user running state. A QUIT is an easy exception to see | |
4425 | here, so do this before any filtered output. */ | |
4426 | if (target_has_execution) | |
4427 | { | |
4428 | if (!non_stop) | |
fee0be5d | 4429 | make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); |
29f49a6a PA |
4430 | else if (last.kind != TARGET_WAITKIND_SIGNALLED |
4431 | && last.kind != TARGET_WAITKIND_EXITED) | |
fee0be5d | 4432 | make_cleanup (finish_thread_state_cleanup, &inferior_ptid); |
29f49a6a PA |
4433 | } |
4434 | ||
4f8d22e3 PA |
4435 | /* In non-stop mode, we don't want GDB to switch threads behind the |
4436 | user's back, to avoid races where the user is typing a command to | |
4437 | apply to thread x, but GDB switches to thread y before the user | |
4438 | finishes entering the command. */ | |
4439 | ||
c906108c SS |
4440 | /* As with the notification of thread events, we want to delay |
4441 | notifying the user that we've switched thread context until | |
4442 | the inferior actually stops. | |
4443 | ||
73b65bb0 DJ |
4444 | There's no point in saying anything if the inferior has exited. |
4445 | Note that SIGNALLED here means "exited with a signal", not | |
4446 | "received a signal". */ | |
4f8d22e3 PA |
4447 | if (!non_stop |
4448 | && !ptid_equal (previous_inferior_ptid, inferior_ptid) | |
73b65bb0 DJ |
4449 | && target_has_execution |
4450 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
4451 | && last.kind != TARGET_WAITKIND_EXITED) | |
c906108c SS |
4452 | { |
4453 | target_terminal_ours_for_output (); | |
a3f17187 | 4454 | printf_filtered (_("[Switching to %s]\n"), |
c95310c6 | 4455 | target_pid_to_str (inferior_ptid)); |
b8fa951a | 4456 | annotate_thread_changed (); |
39f77062 | 4457 | previous_inferior_ptid = inferior_ptid; |
c906108c | 4458 | } |
c906108c | 4459 | |
74960c60 | 4460 | if (!breakpoints_always_inserted_mode () && target_has_execution) |
c906108c SS |
4461 | { |
4462 | if (remove_breakpoints ()) | |
4463 | { | |
4464 | target_terminal_ours_for_output (); | |
a3f17187 AC |
4465 | printf_filtered (_("\ |
4466 | Cannot remove breakpoints because program is no longer writable.\n\ | |
a3f17187 | 4467 | Further execution is probably impossible.\n")); |
c906108c SS |
4468 | } |
4469 | } | |
c906108c | 4470 | |
c906108c SS |
4471 | /* If an auto-display called a function and that got a signal, |
4472 | delete that auto-display to avoid an infinite recursion. */ | |
4473 | ||
4474 | if (stopped_by_random_signal) | |
4475 | disable_current_display (); | |
4476 | ||
4477 | /* Don't print a message if in the middle of doing a "step n" | |
4478 | operation for n > 1 */ | |
af679fd0 PA |
4479 | if (target_has_execution |
4480 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
4481 | && last.kind != TARGET_WAITKIND_EXITED | |
4482 | && inferior_thread ()->step_multi | |
414c69f7 | 4483 | && inferior_thread ()->stop_step) |
c906108c SS |
4484 | goto done; |
4485 | ||
4486 | target_terminal_ours (); | |
4487 | ||
7abfe014 DJ |
4488 | /* Set the current source location. This will also happen if we |
4489 | display the frame below, but the current SAL will be incorrect | |
4490 | during a user hook-stop function. */ | |
d729566a | 4491 | if (has_stack_frames () && !stop_stack_dummy) |
7abfe014 DJ |
4492 | set_current_sal_from_frame (get_current_frame (), 1); |
4493 | ||
dd7e2d2b PA |
4494 | /* Let the user/frontend see the threads as stopped. */ |
4495 | do_cleanups (old_chain); | |
4496 | ||
4497 | /* Look up the hook_stop and run it (CLI internally handles problem | |
4498 | of stop_command's pre-hook not existing). */ | |
4499 | if (stop_command) | |
4500 | catch_errors (hook_stop_stub, stop_command, | |
4501 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
4502 | ||
d729566a | 4503 | if (!has_stack_frames ()) |
d51fd4c8 | 4504 | goto done; |
c906108c | 4505 | |
32400beb PA |
4506 | if (last.kind == TARGET_WAITKIND_SIGNALLED |
4507 | || last.kind == TARGET_WAITKIND_EXITED) | |
4508 | goto done; | |
4509 | ||
c906108c SS |
4510 | /* Select innermost stack frame - i.e., current frame is frame 0, |
4511 | and current location is based on that. | |
4512 | Don't do this on return from a stack dummy routine, | |
4513 | or if the program has exited. */ | |
4514 | ||
4515 | if (!stop_stack_dummy) | |
4516 | { | |
0f7d239c | 4517 | select_frame (get_current_frame ()); |
c906108c SS |
4518 | |
4519 | /* Print current location without a level number, if | |
c5aa993b JM |
4520 | we have changed functions or hit a breakpoint. |
4521 | Print source line if we have one. | |
4522 | bpstat_print() contains the logic deciding in detail | |
4523 | what to print, based on the event(s) that just occurred. */ | |
c906108c | 4524 | |
d01a8610 AS |
4525 | /* If --batch-silent is enabled then there's no need to print the current |
4526 | source location, and to try risks causing an error message about | |
4527 | missing source files. */ | |
4528 | if (stop_print_frame && !batch_silent) | |
c906108c SS |
4529 | { |
4530 | int bpstat_ret; | |
4531 | int source_flag; | |
917317f4 | 4532 | int do_frame_printing = 1; |
347bddb7 | 4533 | struct thread_info *tp = inferior_thread (); |
c906108c | 4534 | |
347bddb7 | 4535 | bpstat_ret = bpstat_print (tp->stop_bpstat); |
917317f4 JM |
4536 | switch (bpstat_ret) |
4537 | { | |
4538 | case PRINT_UNKNOWN: | |
b0f4b84b DJ |
4539 | /* If we had hit a shared library event breakpoint, |
4540 | bpstat_print would print out this message. If we hit | |
4541 | an OS-level shared library event, do the same | |
4542 | thing. */ | |
4543 | if (last.kind == TARGET_WAITKIND_LOADED) | |
4544 | { | |
4545 | printf_filtered (_("Stopped due to shared library event\n")); | |
4546 | source_flag = SRC_LINE; /* something bogus */ | |
4547 | do_frame_printing = 0; | |
4548 | break; | |
4549 | } | |
4550 | ||
aa0cd9c1 | 4551 | /* FIXME: cagney/2002-12-01: Given that a frame ID does |
8fb3e588 AC |
4552 | (or should) carry around the function and does (or |
4553 | should) use that when doing a frame comparison. */ | |
414c69f7 | 4554 | if (tp->stop_step |
347bddb7 | 4555 | && frame_id_eq (tp->step_frame_id, |
aa0cd9c1 | 4556 | get_frame_id (get_current_frame ())) |
917317f4 | 4557 | && step_start_function == find_pc_function (stop_pc)) |
488f131b | 4558 | source_flag = SRC_LINE; /* finished step, just print source line */ |
917317f4 | 4559 | else |
488f131b | 4560 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
4561 | break; |
4562 | case PRINT_SRC_AND_LOC: | |
488f131b | 4563 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
4564 | break; |
4565 | case PRINT_SRC_ONLY: | |
c5394b80 | 4566 | source_flag = SRC_LINE; |
917317f4 JM |
4567 | break; |
4568 | case PRINT_NOTHING: | |
488f131b | 4569 | source_flag = SRC_LINE; /* something bogus */ |
917317f4 JM |
4570 | do_frame_printing = 0; |
4571 | break; | |
4572 | default: | |
e2e0b3e5 | 4573 | internal_error (__FILE__, __LINE__, _("Unknown value.")); |
917317f4 | 4574 | } |
c906108c SS |
4575 | |
4576 | /* The behavior of this routine with respect to the source | |
4577 | flag is: | |
c5394b80 JM |
4578 | SRC_LINE: Print only source line |
4579 | LOCATION: Print only location | |
4580 | SRC_AND_LOC: Print location and source line */ | |
917317f4 | 4581 | if (do_frame_printing) |
b04f3ab4 | 4582 | print_stack_frame (get_selected_frame (NULL), 0, source_flag); |
c906108c SS |
4583 | |
4584 | /* Display the auto-display expressions. */ | |
4585 | do_displays (); | |
4586 | } | |
4587 | } | |
4588 | ||
4589 | /* Save the function value return registers, if we care. | |
4590 | We might be about to restore their previous contents. */ | |
32400beb | 4591 | if (inferior_thread ()->proceed_to_finish) |
d5c31457 UW |
4592 | { |
4593 | /* This should not be necessary. */ | |
4594 | if (stop_registers) | |
4595 | regcache_xfree (stop_registers); | |
4596 | ||
4597 | /* NB: The copy goes through to the target picking up the value of | |
4598 | all the registers. */ | |
4599 | stop_registers = regcache_dup (get_current_regcache ()); | |
4600 | } | |
c906108c SS |
4601 | |
4602 | if (stop_stack_dummy) | |
4603 | { | |
b89667eb DE |
4604 | /* Pop the empty frame that contains the stack dummy. |
4605 | This also restores inferior state prior to the call | |
4606 | (struct inferior_thread_state). */ | |
4607 | struct frame_info *frame = get_current_frame (); | |
4608 | gdb_assert (get_frame_type (frame) == DUMMY_FRAME); | |
4609 | frame_pop (frame); | |
4610 | /* frame_pop() calls reinit_frame_cache as the last thing it does | |
4611 | which means there's currently no selected frame. We don't need | |
4612 | to re-establish a selected frame if the dummy call returns normally, | |
4613 | that will be done by restore_inferior_status. However, we do have | |
4614 | to handle the case where the dummy call is returning after being | |
4615 | stopped (e.g. the dummy call previously hit a breakpoint). We | |
4616 | can't know which case we have so just always re-establish a | |
4617 | selected frame here. */ | |
0f7d239c | 4618 | select_frame (get_current_frame ()); |
c906108c SS |
4619 | } |
4620 | ||
c906108c SS |
4621 | done: |
4622 | annotate_stopped (); | |
41d2bdb4 PA |
4623 | |
4624 | /* Suppress the stop observer if we're in the middle of: | |
4625 | ||
4626 | - a step n (n > 1), as there still more steps to be done. | |
4627 | ||
4628 | - a "finish" command, as the observer will be called in | |
4629 | finish_command_continuation, so it can include the inferior | |
4630 | function's return value. | |
4631 | ||
4632 | - calling an inferior function, as we pretend we inferior didn't | |
4633 | run at all. The return value of the call is handled by the | |
4634 | expression evaluator, through call_function_by_hand. */ | |
4635 | ||
4636 | if (!target_has_execution | |
4637 | || last.kind == TARGET_WAITKIND_SIGNALLED | |
4638 | || last.kind == TARGET_WAITKIND_EXITED | |
4639 | || (!inferior_thread ()->step_multi | |
4640 | && !(inferior_thread ()->stop_bpstat | |
c5a4d20b PA |
4641 | && inferior_thread ()->proceed_to_finish) |
4642 | && !inferior_thread ()->in_infcall)) | |
347bddb7 PA |
4643 | { |
4644 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
1d33d6ba VP |
4645 | observer_notify_normal_stop (inferior_thread ()->stop_bpstat, |
4646 | stop_print_frame); | |
347bddb7 | 4647 | else |
1d33d6ba | 4648 | observer_notify_normal_stop (NULL, stop_print_frame); |
347bddb7 | 4649 | } |
347bddb7 | 4650 | |
48844aa6 PA |
4651 | if (target_has_execution) |
4652 | { | |
4653 | if (last.kind != TARGET_WAITKIND_SIGNALLED | |
4654 | && last.kind != TARGET_WAITKIND_EXITED) | |
4655 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
4656 | Delete any breakpoint that is to be deleted at the next stop. */ | |
4657 | breakpoint_auto_delete (inferior_thread ()->stop_bpstat); | |
94cc34af | 4658 | } |
c906108c SS |
4659 | } |
4660 | ||
4661 | static int | |
96baa820 | 4662 | hook_stop_stub (void *cmd) |
c906108c | 4663 | { |
5913bcb0 | 4664 | execute_cmd_pre_hook ((struct cmd_list_element *) cmd); |
c906108c SS |
4665 | return (0); |
4666 | } | |
4667 | \f | |
c5aa993b | 4668 | int |
96baa820 | 4669 | signal_stop_state (int signo) |
c906108c | 4670 | { |
d6b48e9c | 4671 | return signal_stop[signo]; |
c906108c SS |
4672 | } |
4673 | ||
c5aa993b | 4674 | int |
96baa820 | 4675 | signal_print_state (int signo) |
c906108c SS |
4676 | { |
4677 | return signal_print[signo]; | |
4678 | } | |
4679 | ||
c5aa993b | 4680 | int |
96baa820 | 4681 | signal_pass_state (int signo) |
c906108c SS |
4682 | { |
4683 | return signal_program[signo]; | |
4684 | } | |
4685 | ||
488f131b | 4686 | int |
7bda5e4a | 4687 | signal_stop_update (int signo, int state) |
d4f3574e SS |
4688 | { |
4689 | int ret = signal_stop[signo]; | |
4690 | signal_stop[signo] = state; | |
4691 | return ret; | |
4692 | } | |
4693 | ||
488f131b | 4694 | int |
7bda5e4a | 4695 | signal_print_update (int signo, int state) |
d4f3574e SS |
4696 | { |
4697 | int ret = signal_print[signo]; | |
4698 | signal_print[signo] = state; | |
4699 | return ret; | |
4700 | } | |
4701 | ||
488f131b | 4702 | int |
7bda5e4a | 4703 | signal_pass_update (int signo, int state) |
d4f3574e SS |
4704 | { |
4705 | int ret = signal_program[signo]; | |
4706 | signal_program[signo] = state; | |
4707 | return ret; | |
4708 | } | |
4709 | ||
c906108c | 4710 | static void |
96baa820 | 4711 | sig_print_header (void) |
c906108c | 4712 | { |
a3f17187 AC |
4713 | printf_filtered (_("\ |
4714 | Signal Stop\tPrint\tPass to program\tDescription\n")); | |
c906108c SS |
4715 | } |
4716 | ||
4717 | static void | |
96baa820 | 4718 | sig_print_info (enum target_signal oursig) |
c906108c | 4719 | { |
54363045 | 4720 | const char *name = target_signal_to_name (oursig); |
c906108c | 4721 | int name_padding = 13 - strlen (name); |
96baa820 | 4722 | |
c906108c SS |
4723 | if (name_padding <= 0) |
4724 | name_padding = 0; | |
4725 | ||
4726 | printf_filtered ("%s", name); | |
488f131b | 4727 | printf_filtered ("%*.*s ", name_padding, name_padding, " "); |
c906108c SS |
4728 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
4729 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
4730 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
4731 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
4732 | } | |
4733 | ||
4734 | /* Specify how various signals in the inferior should be handled. */ | |
4735 | ||
4736 | static void | |
96baa820 | 4737 | handle_command (char *args, int from_tty) |
c906108c SS |
4738 | { |
4739 | char **argv; | |
4740 | int digits, wordlen; | |
4741 | int sigfirst, signum, siglast; | |
4742 | enum target_signal oursig; | |
4743 | int allsigs; | |
4744 | int nsigs; | |
4745 | unsigned char *sigs; | |
4746 | struct cleanup *old_chain; | |
4747 | ||
4748 | if (args == NULL) | |
4749 | { | |
e2e0b3e5 | 4750 | error_no_arg (_("signal to handle")); |
c906108c SS |
4751 | } |
4752 | ||
4753 | /* Allocate and zero an array of flags for which signals to handle. */ | |
4754 | ||
4755 | nsigs = (int) TARGET_SIGNAL_LAST; | |
4756 | sigs = (unsigned char *) alloca (nsigs); | |
4757 | memset (sigs, 0, nsigs); | |
4758 | ||
4759 | /* Break the command line up into args. */ | |
4760 | ||
d1a41061 | 4761 | argv = gdb_buildargv (args); |
7a292a7a | 4762 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
4763 | |
4764 | /* Walk through the args, looking for signal oursigs, signal names, and | |
4765 | actions. Signal numbers and signal names may be interspersed with | |
4766 | actions, with the actions being performed for all signals cumulatively | |
4767 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
4768 | ||
4769 | while (*argv != NULL) | |
4770 | { | |
4771 | wordlen = strlen (*argv); | |
4772 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
4773 | {; | |
4774 | } | |
4775 | allsigs = 0; | |
4776 | sigfirst = siglast = -1; | |
4777 | ||
4778 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
4779 | { | |
4780 | /* Apply action to all signals except those used by the | |
4781 | debugger. Silently skip those. */ | |
4782 | allsigs = 1; | |
4783 | sigfirst = 0; | |
4784 | siglast = nsigs - 1; | |
4785 | } | |
4786 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
4787 | { | |
4788 | SET_SIGS (nsigs, sigs, signal_stop); | |
4789 | SET_SIGS (nsigs, sigs, signal_print); | |
4790 | } | |
4791 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
4792 | { | |
4793 | UNSET_SIGS (nsigs, sigs, signal_program); | |
4794 | } | |
4795 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
4796 | { | |
4797 | SET_SIGS (nsigs, sigs, signal_print); | |
4798 | } | |
4799 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
4800 | { | |
4801 | SET_SIGS (nsigs, sigs, signal_program); | |
4802 | } | |
4803 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
4804 | { | |
4805 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
4806 | } | |
4807 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
4808 | { | |
4809 | SET_SIGS (nsigs, sigs, signal_program); | |
4810 | } | |
4811 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
4812 | { | |
4813 | UNSET_SIGS (nsigs, sigs, signal_print); | |
4814 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
4815 | } | |
4816 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
4817 | { | |
4818 | UNSET_SIGS (nsigs, sigs, signal_program); | |
4819 | } | |
4820 | else if (digits > 0) | |
4821 | { | |
4822 | /* It is numeric. The numeric signal refers to our own | |
4823 | internal signal numbering from target.h, not to host/target | |
4824 | signal number. This is a feature; users really should be | |
4825 | using symbolic names anyway, and the common ones like | |
4826 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
4827 | ||
4828 | sigfirst = siglast = (int) | |
4829 | target_signal_from_command (atoi (*argv)); | |
4830 | if ((*argv)[digits] == '-') | |
4831 | { | |
4832 | siglast = (int) | |
4833 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
4834 | } | |
4835 | if (sigfirst > siglast) | |
4836 | { | |
4837 | /* Bet he didn't figure we'd think of this case... */ | |
4838 | signum = sigfirst; | |
4839 | sigfirst = siglast; | |
4840 | siglast = signum; | |
4841 | } | |
4842 | } | |
4843 | else | |
4844 | { | |
4845 | oursig = target_signal_from_name (*argv); | |
4846 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
4847 | { | |
4848 | sigfirst = siglast = (int) oursig; | |
4849 | } | |
4850 | else | |
4851 | { | |
4852 | /* Not a number and not a recognized flag word => complain. */ | |
8a3fe4f8 | 4853 | error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); |
c906108c SS |
4854 | } |
4855 | } | |
4856 | ||
4857 | /* If any signal numbers or symbol names were found, set flags for | |
c5aa993b | 4858 | which signals to apply actions to. */ |
c906108c SS |
4859 | |
4860 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
4861 | { | |
4862 | switch ((enum target_signal) signum) | |
4863 | { | |
4864 | case TARGET_SIGNAL_TRAP: | |
4865 | case TARGET_SIGNAL_INT: | |
4866 | if (!allsigs && !sigs[signum]) | |
4867 | { | |
9e2f0ad4 HZ |
4868 | if (query (_("%s is used by the debugger.\n\ |
4869 | Are you sure you want to change it? "), target_signal_to_name ((enum target_signal) signum))) | |
c906108c SS |
4870 | { |
4871 | sigs[signum] = 1; | |
4872 | } | |
4873 | else | |
4874 | { | |
a3f17187 | 4875 | printf_unfiltered (_("Not confirmed, unchanged.\n")); |
c906108c SS |
4876 | gdb_flush (gdb_stdout); |
4877 | } | |
4878 | } | |
4879 | break; | |
4880 | case TARGET_SIGNAL_0: | |
4881 | case TARGET_SIGNAL_DEFAULT: | |
4882 | case TARGET_SIGNAL_UNKNOWN: | |
4883 | /* Make sure that "all" doesn't print these. */ | |
4884 | break; | |
4885 | default: | |
4886 | sigs[signum] = 1; | |
4887 | break; | |
4888 | } | |
4889 | } | |
4890 | ||
4891 | argv++; | |
4892 | } | |
4893 | ||
3a031f65 PA |
4894 | for (signum = 0; signum < nsigs; signum++) |
4895 | if (sigs[signum]) | |
4896 | { | |
4897 | target_notice_signals (inferior_ptid); | |
c906108c | 4898 | |
3a031f65 PA |
4899 | if (from_tty) |
4900 | { | |
4901 | /* Show the results. */ | |
4902 | sig_print_header (); | |
4903 | for (; signum < nsigs; signum++) | |
4904 | if (sigs[signum]) | |
4905 | sig_print_info (signum); | |
4906 | } | |
4907 | ||
4908 | break; | |
4909 | } | |
c906108c SS |
4910 | |
4911 | do_cleanups (old_chain); | |
4912 | } | |
4913 | ||
4914 | static void | |
96baa820 | 4915 | xdb_handle_command (char *args, int from_tty) |
c906108c SS |
4916 | { |
4917 | char **argv; | |
4918 | struct cleanup *old_chain; | |
4919 | ||
d1a41061 PP |
4920 | if (args == NULL) |
4921 | error_no_arg (_("xdb command")); | |
4922 | ||
c906108c SS |
4923 | /* Break the command line up into args. */ |
4924 | ||
d1a41061 | 4925 | argv = gdb_buildargv (args); |
7a292a7a | 4926 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
4927 | if (argv[1] != (char *) NULL) |
4928 | { | |
4929 | char *argBuf; | |
4930 | int bufLen; | |
4931 | ||
4932 | bufLen = strlen (argv[0]) + 20; | |
4933 | argBuf = (char *) xmalloc (bufLen); | |
4934 | if (argBuf) | |
4935 | { | |
4936 | int validFlag = 1; | |
4937 | enum target_signal oursig; | |
4938 | ||
4939 | oursig = target_signal_from_name (argv[0]); | |
4940 | memset (argBuf, 0, bufLen); | |
4941 | if (strcmp (argv[1], "Q") == 0) | |
4942 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
4943 | else | |
4944 | { | |
4945 | if (strcmp (argv[1], "s") == 0) | |
4946 | { | |
4947 | if (!signal_stop[oursig]) | |
4948 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
4949 | else | |
4950 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
4951 | } | |
4952 | else if (strcmp (argv[1], "i") == 0) | |
4953 | { | |
4954 | if (!signal_program[oursig]) | |
4955 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
4956 | else | |
4957 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
4958 | } | |
4959 | else if (strcmp (argv[1], "r") == 0) | |
4960 | { | |
4961 | if (!signal_print[oursig]) | |
4962 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
4963 | else | |
4964 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
4965 | } | |
4966 | else | |
4967 | validFlag = 0; | |
4968 | } | |
4969 | if (validFlag) | |
4970 | handle_command (argBuf, from_tty); | |
4971 | else | |
a3f17187 | 4972 | printf_filtered (_("Invalid signal handling flag.\n")); |
c906108c | 4973 | if (argBuf) |
b8c9b27d | 4974 | xfree (argBuf); |
c906108c SS |
4975 | } |
4976 | } | |
4977 | do_cleanups (old_chain); | |
4978 | } | |
4979 | ||
4980 | /* Print current contents of the tables set by the handle command. | |
4981 | It is possible we should just be printing signals actually used | |
4982 | by the current target (but for things to work right when switching | |
4983 | targets, all signals should be in the signal tables). */ | |
4984 | ||
4985 | static void | |
96baa820 | 4986 | signals_info (char *signum_exp, int from_tty) |
c906108c SS |
4987 | { |
4988 | enum target_signal oursig; | |
4989 | sig_print_header (); | |
4990 | ||
4991 | if (signum_exp) | |
4992 | { | |
4993 | /* First see if this is a symbol name. */ | |
4994 | oursig = target_signal_from_name (signum_exp); | |
4995 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
4996 | { | |
4997 | /* No, try numeric. */ | |
4998 | oursig = | |
bb518678 | 4999 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
c906108c SS |
5000 | } |
5001 | sig_print_info (oursig); | |
5002 | return; | |
5003 | } | |
5004 | ||
5005 | printf_filtered ("\n"); | |
5006 | /* These ugly casts brought to you by the native VAX compiler. */ | |
5007 | for (oursig = TARGET_SIGNAL_FIRST; | |
5008 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
5009 | oursig = (enum target_signal) ((int) oursig + 1)) | |
5010 | { | |
5011 | QUIT; | |
5012 | ||
5013 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
488f131b | 5014 | && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) |
c906108c SS |
5015 | sig_print_info (oursig); |
5016 | } | |
5017 | ||
a3f17187 | 5018 | printf_filtered (_("\nUse the \"handle\" command to change these tables.\n")); |
c906108c | 5019 | } |
4aa995e1 PA |
5020 | |
5021 | /* The $_siginfo convenience variable is a bit special. We don't know | |
5022 | for sure the type of the value until we actually have a chance to | |
5023 | fetch the data. The type can change depending on gdbarch, so it it | |
5024 | also dependent on which thread you have selected. | |
5025 | ||
5026 | 1. making $_siginfo be an internalvar that creates a new value on | |
5027 | access. | |
5028 | ||
5029 | 2. making the value of $_siginfo be an lval_computed value. */ | |
5030 | ||
5031 | /* This function implements the lval_computed support for reading a | |
5032 | $_siginfo value. */ | |
5033 | ||
5034 | static void | |
5035 | siginfo_value_read (struct value *v) | |
5036 | { | |
5037 | LONGEST transferred; | |
5038 | ||
5039 | transferred = | |
5040 | target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, | |
5041 | NULL, | |
5042 | value_contents_all_raw (v), | |
5043 | value_offset (v), | |
5044 | TYPE_LENGTH (value_type (v))); | |
5045 | ||
5046 | if (transferred != TYPE_LENGTH (value_type (v))) | |
5047 | error (_("Unable to read siginfo")); | |
5048 | } | |
5049 | ||
5050 | /* This function implements the lval_computed support for writing a | |
5051 | $_siginfo value. */ | |
5052 | ||
5053 | static void | |
5054 | siginfo_value_write (struct value *v, struct value *fromval) | |
5055 | { | |
5056 | LONGEST transferred; | |
5057 | ||
5058 | transferred = target_write (¤t_target, | |
5059 | TARGET_OBJECT_SIGNAL_INFO, | |
5060 | NULL, | |
5061 | value_contents_all_raw (fromval), | |
5062 | value_offset (v), | |
5063 | TYPE_LENGTH (value_type (fromval))); | |
5064 | ||
5065 | if (transferred != TYPE_LENGTH (value_type (fromval))) | |
5066 | error (_("Unable to write siginfo")); | |
5067 | } | |
5068 | ||
5069 | static struct lval_funcs siginfo_value_funcs = | |
5070 | { | |
5071 | siginfo_value_read, | |
5072 | siginfo_value_write | |
5073 | }; | |
5074 | ||
5075 | /* Return a new value with the correct type for the siginfo object of | |
5076 | the current thread. Return a void value if there's no object | |
5077 | available. */ | |
5078 | ||
2c0b251b | 5079 | static struct value * |
4aa995e1 PA |
5080 | siginfo_make_value (struct internalvar *var) |
5081 | { | |
5082 | struct type *type; | |
5083 | struct gdbarch *gdbarch; | |
5084 | ||
5085 | if (target_has_stack | |
5086 | && !ptid_equal (inferior_ptid, null_ptid)) | |
5087 | { | |
5088 | gdbarch = get_frame_arch (get_current_frame ()); | |
5089 | ||
5090 | if (gdbarch_get_siginfo_type_p (gdbarch)) | |
5091 | { | |
5092 | type = gdbarch_get_siginfo_type (gdbarch); | |
5093 | ||
5094 | return allocate_computed_value (type, &siginfo_value_funcs, NULL); | |
5095 | } | |
5096 | } | |
5097 | ||
5098 | return allocate_value (builtin_type_void); | |
5099 | } | |
5100 | ||
c906108c | 5101 | \f |
b89667eb DE |
5102 | /* Inferior thread state. |
5103 | These are details related to the inferior itself, and don't include | |
5104 | things like what frame the user had selected or what gdb was doing | |
5105 | with the target at the time. | |
5106 | For inferior function calls these are things we want to restore | |
5107 | regardless of whether the function call successfully completes | |
5108 | or the dummy frame has to be manually popped. */ | |
5109 | ||
5110 | struct inferior_thread_state | |
7a292a7a SS |
5111 | { |
5112 | enum target_signal stop_signal; | |
5113 | CORE_ADDR stop_pc; | |
b89667eb DE |
5114 | struct regcache *registers; |
5115 | }; | |
5116 | ||
5117 | struct inferior_thread_state * | |
5118 | save_inferior_thread_state (void) | |
5119 | { | |
5120 | struct inferior_thread_state *inf_state = XMALLOC (struct inferior_thread_state); | |
5121 | struct thread_info *tp = inferior_thread (); | |
5122 | ||
5123 | inf_state->stop_signal = tp->stop_signal; | |
5124 | inf_state->stop_pc = stop_pc; | |
5125 | ||
5126 | inf_state->registers = regcache_dup (get_current_regcache ()); | |
5127 | ||
5128 | return inf_state; | |
5129 | } | |
5130 | ||
5131 | /* Restore inferior session state to INF_STATE. */ | |
5132 | ||
5133 | void | |
5134 | restore_inferior_thread_state (struct inferior_thread_state *inf_state) | |
5135 | { | |
5136 | struct thread_info *tp = inferior_thread (); | |
5137 | ||
5138 | tp->stop_signal = inf_state->stop_signal; | |
5139 | stop_pc = inf_state->stop_pc; | |
5140 | ||
5141 | /* The inferior can be gone if the user types "print exit(0)" | |
5142 | (and perhaps other times). */ | |
5143 | if (target_has_execution) | |
5144 | /* NB: The register write goes through to the target. */ | |
5145 | regcache_cpy (get_current_regcache (), inf_state->registers); | |
5146 | regcache_xfree (inf_state->registers); | |
5147 | xfree (inf_state); | |
5148 | } | |
5149 | ||
5150 | static void | |
5151 | do_restore_inferior_thread_state_cleanup (void *state) | |
5152 | { | |
5153 | restore_inferior_thread_state (state); | |
5154 | } | |
5155 | ||
5156 | struct cleanup * | |
5157 | make_cleanup_restore_inferior_thread_state (struct inferior_thread_state *inf_state) | |
5158 | { | |
5159 | return make_cleanup (do_restore_inferior_thread_state_cleanup, inf_state); | |
5160 | } | |
5161 | ||
5162 | void | |
5163 | discard_inferior_thread_state (struct inferior_thread_state *inf_state) | |
5164 | { | |
5165 | regcache_xfree (inf_state->registers); | |
5166 | xfree (inf_state); | |
5167 | } | |
5168 | ||
5169 | struct regcache * | |
5170 | get_inferior_thread_state_regcache (struct inferior_thread_state *inf_state) | |
5171 | { | |
5172 | return inf_state->registers; | |
5173 | } | |
5174 | ||
5175 | /* Session related state for inferior function calls. | |
5176 | These are the additional bits of state that need to be restored | |
5177 | when an inferior function call successfully completes. */ | |
5178 | ||
5179 | struct inferior_status | |
5180 | { | |
7a292a7a SS |
5181 | bpstat stop_bpstat; |
5182 | int stop_step; | |
5183 | int stop_stack_dummy; | |
5184 | int stopped_by_random_signal; | |
ca67fcb8 | 5185 | int stepping_over_breakpoint; |
7a292a7a SS |
5186 | CORE_ADDR step_range_start; |
5187 | CORE_ADDR step_range_end; | |
aa0cd9c1 | 5188 | struct frame_id step_frame_id; |
5fbbeb29 | 5189 | enum step_over_calls_kind step_over_calls; |
7a292a7a SS |
5190 | CORE_ADDR step_resume_break_address; |
5191 | int stop_after_trap; | |
c0236d92 | 5192 | int stop_soon; |
7a292a7a | 5193 | |
b89667eb | 5194 | /* ID if the selected frame when the inferior function call was made. */ |
101dcfbe AC |
5195 | struct frame_id selected_frame_id; |
5196 | ||
7a292a7a | 5197 | int proceed_to_finish; |
c5a4d20b | 5198 | int in_infcall; |
7a292a7a SS |
5199 | }; |
5200 | ||
c906108c | 5201 | /* Save all of the information associated with the inferior<==>gdb |
b89667eb | 5202 | connection. */ |
c906108c | 5203 | |
7a292a7a | 5204 | struct inferior_status * |
b89667eb | 5205 | save_inferior_status (void) |
c906108c | 5206 | { |
72cec141 | 5207 | struct inferior_status *inf_status = XMALLOC (struct inferior_status); |
4e1c45ea | 5208 | struct thread_info *tp = inferior_thread (); |
d6b48e9c | 5209 | struct inferior *inf = current_inferior (); |
7a292a7a | 5210 | |
414c69f7 | 5211 | inf_status->stop_step = tp->stop_step; |
c906108c SS |
5212 | inf_status->stop_stack_dummy = stop_stack_dummy; |
5213 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
4e1c45ea PA |
5214 | inf_status->stepping_over_breakpoint = tp->trap_expected; |
5215 | inf_status->step_range_start = tp->step_range_start; | |
5216 | inf_status->step_range_end = tp->step_range_end; | |
5217 | inf_status->step_frame_id = tp->step_frame_id; | |
078130d0 | 5218 | inf_status->step_over_calls = tp->step_over_calls; |
c906108c | 5219 | inf_status->stop_after_trap = stop_after_trap; |
d6b48e9c | 5220 | inf_status->stop_soon = inf->stop_soon; |
c906108c SS |
5221 | /* Save original bpstat chain here; replace it with copy of chain. |
5222 | If caller's caller is walking the chain, they'll be happier if we | |
7a292a7a SS |
5223 | hand them back the original chain when restore_inferior_status is |
5224 | called. */ | |
347bddb7 PA |
5225 | inf_status->stop_bpstat = tp->stop_bpstat; |
5226 | tp->stop_bpstat = bpstat_copy (tp->stop_bpstat); | |
32400beb | 5227 | inf_status->proceed_to_finish = tp->proceed_to_finish; |
c5a4d20b | 5228 | inf_status->in_infcall = tp->in_infcall; |
c5aa993b | 5229 | |
206415a3 | 5230 | inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); |
b89667eb | 5231 | |
7a292a7a | 5232 | return inf_status; |
c906108c SS |
5233 | } |
5234 | ||
c906108c | 5235 | static int |
96baa820 | 5236 | restore_selected_frame (void *args) |
c906108c | 5237 | { |
488f131b | 5238 | struct frame_id *fid = (struct frame_id *) args; |
c906108c | 5239 | struct frame_info *frame; |
c906108c | 5240 | |
101dcfbe | 5241 | frame = frame_find_by_id (*fid); |
c906108c | 5242 | |
aa0cd9c1 AC |
5243 | /* If inf_status->selected_frame_id is NULL, there was no previously |
5244 | selected frame. */ | |
101dcfbe | 5245 | if (frame == NULL) |
c906108c | 5246 | { |
8a3fe4f8 | 5247 | warning (_("Unable to restore previously selected frame.")); |
c906108c SS |
5248 | return 0; |
5249 | } | |
5250 | ||
0f7d239c | 5251 | select_frame (frame); |
c906108c SS |
5252 | |
5253 | return (1); | |
5254 | } | |
5255 | ||
b89667eb DE |
5256 | /* Restore inferior session state to INF_STATUS. */ |
5257 | ||
c906108c | 5258 | void |
96baa820 | 5259 | restore_inferior_status (struct inferior_status *inf_status) |
c906108c | 5260 | { |
4e1c45ea | 5261 | struct thread_info *tp = inferior_thread (); |
d6b48e9c | 5262 | struct inferior *inf = current_inferior (); |
4e1c45ea | 5263 | |
414c69f7 | 5264 | tp->stop_step = inf_status->stop_step; |
c906108c SS |
5265 | stop_stack_dummy = inf_status->stop_stack_dummy; |
5266 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
4e1c45ea PA |
5267 | tp->trap_expected = inf_status->stepping_over_breakpoint; |
5268 | tp->step_range_start = inf_status->step_range_start; | |
5269 | tp->step_range_end = inf_status->step_range_end; | |
5270 | tp->step_frame_id = inf_status->step_frame_id; | |
078130d0 | 5271 | tp->step_over_calls = inf_status->step_over_calls; |
c906108c | 5272 | stop_after_trap = inf_status->stop_after_trap; |
d6b48e9c | 5273 | inf->stop_soon = inf_status->stop_soon; |
347bddb7 PA |
5274 | bpstat_clear (&tp->stop_bpstat); |
5275 | tp->stop_bpstat = inf_status->stop_bpstat; | |
b89667eb | 5276 | inf_status->stop_bpstat = NULL; |
32400beb | 5277 | tp->proceed_to_finish = inf_status->proceed_to_finish; |
c5a4d20b | 5278 | tp->in_infcall = inf_status->in_infcall; |
c906108c | 5279 | |
b89667eb | 5280 | if (target_has_stack) |
c906108c | 5281 | { |
c906108c | 5282 | /* The point of catch_errors is that if the stack is clobbered, |
101dcfbe AC |
5283 | walking the stack might encounter a garbage pointer and |
5284 | error() trying to dereference it. */ | |
488f131b JB |
5285 | if (catch_errors |
5286 | (restore_selected_frame, &inf_status->selected_frame_id, | |
5287 | "Unable to restore previously selected frame:\n", | |
5288 | RETURN_MASK_ERROR) == 0) | |
c906108c SS |
5289 | /* Error in restoring the selected frame. Select the innermost |
5290 | frame. */ | |
0f7d239c | 5291 | select_frame (get_current_frame ()); |
c906108c | 5292 | } |
c906108c | 5293 | |
72cec141 | 5294 | xfree (inf_status); |
7a292a7a | 5295 | } |
c906108c | 5296 | |
74b7792f AC |
5297 | static void |
5298 | do_restore_inferior_status_cleanup (void *sts) | |
5299 | { | |
5300 | restore_inferior_status (sts); | |
5301 | } | |
5302 | ||
5303 | struct cleanup * | |
5304 | make_cleanup_restore_inferior_status (struct inferior_status *inf_status) | |
5305 | { | |
5306 | return make_cleanup (do_restore_inferior_status_cleanup, inf_status); | |
5307 | } | |
5308 | ||
c906108c | 5309 | void |
96baa820 | 5310 | discard_inferior_status (struct inferior_status *inf_status) |
7a292a7a SS |
5311 | { |
5312 | /* See save_inferior_status for info on stop_bpstat. */ | |
5313 | bpstat_clear (&inf_status->stop_bpstat); | |
72cec141 | 5314 | xfree (inf_status); |
7a292a7a | 5315 | } |
b89667eb | 5316 | \f |
47932f85 | 5317 | int |
3a3e9ee3 | 5318 | inferior_has_forked (ptid_t pid, ptid_t *child_pid) |
47932f85 DJ |
5319 | { |
5320 | struct target_waitstatus last; | |
5321 | ptid_t last_ptid; | |
5322 | ||
5323 | get_last_target_status (&last_ptid, &last); | |
5324 | ||
5325 | if (last.kind != TARGET_WAITKIND_FORKED) | |
5326 | return 0; | |
5327 | ||
3a3e9ee3 | 5328 | if (!ptid_equal (last_ptid, pid)) |
47932f85 DJ |
5329 | return 0; |
5330 | ||
5331 | *child_pid = last.value.related_pid; | |
5332 | return 1; | |
5333 | } | |
5334 | ||
5335 | int | |
3a3e9ee3 | 5336 | inferior_has_vforked (ptid_t pid, ptid_t *child_pid) |
47932f85 DJ |
5337 | { |
5338 | struct target_waitstatus last; | |
5339 | ptid_t last_ptid; | |
5340 | ||
5341 | get_last_target_status (&last_ptid, &last); | |
5342 | ||
5343 | if (last.kind != TARGET_WAITKIND_VFORKED) | |
5344 | return 0; | |
5345 | ||
3a3e9ee3 | 5346 | if (!ptid_equal (last_ptid, pid)) |
47932f85 DJ |
5347 | return 0; |
5348 | ||
5349 | *child_pid = last.value.related_pid; | |
5350 | return 1; | |
5351 | } | |
5352 | ||
5353 | int | |
3a3e9ee3 | 5354 | inferior_has_execd (ptid_t pid, char **execd_pathname) |
47932f85 DJ |
5355 | { |
5356 | struct target_waitstatus last; | |
5357 | ptid_t last_ptid; | |
5358 | ||
5359 | get_last_target_status (&last_ptid, &last); | |
5360 | ||
5361 | if (last.kind != TARGET_WAITKIND_EXECD) | |
5362 | return 0; | |
5363 | ||
3a3e9ee3 | 5364 | if (!ptid_equal (last_ptid, pid)) |
47932f85 DJ |
5365 | return 0; |
5366 | ||
5367 | *execd_pathname = xstrdup (last.value.execd_pathname); | |
5368 | return 1; | |
5369 | } | |
5370 | ||
ca6724c1 KB |
5371 | /* Oft used ptids */ |
5372 | ptid_t null_ptid; | |
5373 | ptid_t minus_one_ptid; | |
5374 | ||
5375 | /* Create a ptid given the necessary PID, LWP, and TID components. */ | |
488f131b | 5376 | |
ca6724c1 KB |
5377 | ptid_t |
5378 | ptid_build (int pid, long lwp, long tid) | |
5379 | { | |
5380 | ptid_t ptid; | |
5381 | ||
5382 | ptid.pid = pid; | |
5383 | ptid.lwp = lwp; | |
5384 | ptid.tid = tid; | |
5385 | return ptid; | |
5386 | } | |
5387 | ||
5388 | /* Create a ptid from just a pid. */ | |
5389 | ||
5390 | ptid_t | |
5391 | pid_to_ptid (int pid) | |
5392 | { | |
5393 | return ptid_build (pid, 0, 0); | |
5394 | } | |
5395 | ||
5396 | /* Fetch the pid (process id) component from a ptid. */ | |
5397 | ||
5398 | int | |
5399 | ptid_get_pid (ptid_t ptid) | |
5400 | { | |
5401 | return ptid.pid; | |
5402 | } | |
5403 | ||
5404 | /* Fetch the lwp (lightweight process) component from a ptid. */ | |
5405 | ||
5406 | long | |
5407 | ptid_get_lwp (ptid_t ptid) | |
5408 | { | |
5409 | return ptid.lwp; | |
5410 | } | |
5411 | ||
5412 | /* Fetch the tid (thread id) component from a ptid. */ | |
5413 | ||
5414 | long | |
5415 | ptid_get_tid (ptid_t ptid) | |
5416 | { | |
5417 | return ptid.tid; | |
5418 | } | |
5419 | ||
5420 | /* ptid_equal() is used to test equality of two ptids. */ | |
5421 | ||
5422 | int | |
5423 | ptid_equal (ptid_t ptid1, ptid_t ptid2) | |
5424 | { | |
5425 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp | |
488f131b | 5426 | && ptid1.tid == ptid2.tid); |
ca6724c1 KB |
5427 | } |
5428 | ||
252fbfc8 PA |
5429 | /* Returns true if PTID represents a process. */ |
5430 | ||
5431 | int | |
5432 | ptid_is_pid (ptid_t ptid) | |
5433 | { | |
5434 | if (ptid_equal (minus_one_ptid, ptid)) | |
5435 | return 0; | |
5436 | if (ptid_equal (null_ptid, ptid)) | |
5437 | return 0; | |
5438 | ||
5439 | return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0); | |
5440 | } | |
5441 | ||
ca6724c1 KB |
5442 | /* restore_inferior_ptid() will be used by the cleanup machinery |
5443 | to restore the inferior_ptid value saved in a call to | |
5444 | save_inferior_ptid(). */ | |
ce696e05 KB |
5445 | |
5446 | static void | |
5447 | restore_inferior_ptid (void *arg) | |
5448 | { | |
5449 | ptid_t *saved_ptid_ptr = arg; | |
5450 | inferior_ptid = *saved_ptid_ptr; | |
5451 | xfree (arg); | |
5452 | } | |
5453 | ||
5454 | /* Save the value of inferior_ptid so that it may be restored by a | |
5455 | later call to do_cleanups(). Returns the struct cleanup pointer | |
5456 | needed for later doing the cleanup. */ | |
5457 | ||
5458 | struct cleanup * | |
5459 | save_inferior_ptid (void) | |
5460 | { | |
5461 | ptid_t *saved_ptid_ptr; | |
5462 | ||
5463 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); | |
5464 | *saved_ptid_ptr = inferior_ptid; | |
5465 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); | |
5466 | } | |
c5aa993b | 5467 | \f |
488f131b | 5468 | |
b2175913 MS |
5469 | /* User interface for reverse debugging: |
5470 | Set exec-direction / show exec-direction commands | |
5471 | (returns error unless target implements to_set_exec_direction method). */ | |
5472 | ||
5473 | enum exec_direction_kind execution_direction = EXEC_FORWARD; | |
5474 | static const char exec_forward[] = "forward"; | |
5475 | static const char exec_reverse[] = "reverse"; | |
5476 | static const char *exec_direction = exec_forward; | |
5477 | static const char *exec_direction_names[] = { | |
5478 | exec_forward, | |
5479 | exec_reverse, | |
5480 | NULL | |
5481 | }; | |
5482 | ||
5483 | static void | |
5484 | set_exec_direction_func (char *args, int from_tty, | |
5485 | struct cmd_list_element *cmd) | |
5486 | { | |
5487 | if (target_can_execute_reverse) | |
5488 | { | |
5489 | if (!strcmp (exec_direction, exec_forward)) | |
5490 | execution_direction = EXEC_FORWARD; | |
5491 | else if (!strcmp (exec_direction, exec_reverse)) | |
5492 | execution_direction = EXEC_REVERSE; | |
5493 | } | |
5494 | } | |
5495 | ||
5496 | static void | |
5497 | show_exec_direction_func (struct ui_file *out, int from_tty, | |
5498 | struct cmd_list_element *cmd, const char *value) | |
5499 | { | |
5500 | switch (execution_direction) { | |
5501 | case EXEC_FORWARD: | |
5502 | fprintf_filtered (out, _("Forward.\n")); | |
5503 | break; | |
5504 | case EXEC_REVERSE: | |
5505 | fprintf_filtered (out, _("Reverse.\n")); | |
5506 | break; | |
5507 | case EXEC_ERROR: | |
5508 | default: | |
5509 | fprintf_filtered (out, | |
5510 | _("Forward (target `%s' does not support exec-direction).\n"), | |
5511 | target_shortname); | |
5512 | break; | |
5513 | } | |
5514 | } | |
5515 | ||
5516 | /* User interface for non-stop mode. */ | |
5517 | ||
ad52ddc6 PA |
5518 | int non_stop = 0; |
5519 | static int non_stop_1 = 0; | |
5520 | ||
5521 | static void | |
5522 | set_non_stop (char *args, int from_tty, | |
5523 | struct cmd_list_element *c) | |
5524 | { | |
5525 | if (target_has_execution) | |
5526 | { | |
5527 | non_stop_1 = non_stop; | |
5528 | error (_("Cannot change this setting while the inferior is running.")); | |
5529 | } | |
5530 | ||
5531 | non_stop = non_stop_1; | |
5532 | } | |
5533 | ||
5534 | static void | |
5535 | show_non_stop (struct ui_file *file, int from_tty, | |
5536 | struct cmd_list_element *c, const char *value) | |
5537 | { | |
5538 | fprintf_filtered (file, | |
5539 | _("Controlling the inferior in non-stop mode is %s.\n"), | |
5540 | value); | |
5541 | } | |
5542 | ||
5543 | ||
c906108c | 5544 | void |
96baa820 | 5545 | _initialize_infrun (void) |
c906108c | 5546 | { |
52f0bd74 AC |
5547 | int i; |
5548 | int numsigs; | |
c906108c SS |
5549 | struct cmd_list_element *c; |
5550 | ||
1bedd215 AC |
5551 | add_info ("signals", signals_info, _("\ |
5552 | What debugger does when program gets various signals.\n\ | |
5553 | Specify a signal as argument to print info on that signal only.")); | |
c906108c SS |
5554 | add_info_alias ("handle", "signals", 0); |
5555 | ||
1bedd215 AC |
5556 | add_com ("handle", class_run, handle_command, _("\ |
5557 | Specify how to handle a signal.\n\ | |
c906108c SS |
5558 | Args are signals and actions to apply to those signals.\n\ |
5559 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
5560 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
5561 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
5562 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 AC |
5563 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
5564 | Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
c906108c SS |
5565 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
5566 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
5567 | Print means print a message if this signal happens.\n\ | |
5568 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
5569 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 5570 | Pass and Stop may be combined.")); |
c906108c SS |
5571 | if (xdb_commands) |
5572 | { | |
1bedd215 AC |
5573 | add_com ("lz", class_info, signals_info, _("\ |
5574 | What debugger does when program gets various signals.\n\ | |
5575 | Specify a signal as argument to print info on that signal only.")); | |
5576 | add_com ("z", class_run, xdb_handle_command, _("\ | |
5577 | Specify how to handle a signal.\n\ | |
c906108c SS |
5578 | Args are signals and actions to apply to those signals.\n\ |
5579 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
5580 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
5581 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
5582 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 AC |
5583 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
5584 | Recognized actions include \"s\" (toggles between stop and nostop), \n\ | |
c906108c SS |
5585 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ |
5586 | nopass), \"Q\" (noprint)\n\ | |
5587 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
5588 | Print means print a message if this signal happens.\n\ | |
5589 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
5590 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 5591 | Pass and Stop may be combined.")); |
c906108c SS |
5592 | } |
5593 | ||
5594 | if (!dbx_commands) | |
1a966eab AC |
5595 | stop_command = add_cmd ("stop", class_obscure, |
5596 | not_just_help_class_command, _("\ | |
5597 | There is no `stop' command, but you can set a hook on `stop'.\n\ | |
c906108c | 5598 | This allows you to set a list of commands to be run each time execution\n\ |
1a966eab | 5599 | of the program stops."), &cmdlist); |
c906108c | 5600 | |
85c07804 AC |
5601 | add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ |
5602 | Set inferior debugging."), _("\ | |
5603 | Show inferior debugging."), _("\ | |
5604 | When non-zero, inferior specific debugging is enabled."), | |
5605 | NULL, | |
920d2a44 | 5606 | show_debug_infrun, |
85c07804 | 5607 | &setdebuglist, &showdebuglist); |
527159b7 | 5608 | |
237fc4c9 PA |
5609 | add_setshow_boolean_cmd ("displaced", class_maintenance, &debug_displaced, _("\ |
5610 | Set displaced stepping debugging."), _("\ | |
5611 | Show displaced stepping debugging."), _("\ | |
5612 | When non-zero, displaced stepping specific debugging is enabled."), | |
5613 | NULL, | |
5614 | show_debug_displaced, | |
5615 | &setdebuglist, &showdebuglist); | |
5616 | ||
ad52ddc6 PA |
5617 | add_setshow_boolean_cmd ("non-stop", no_class, |
5618 | &non_stop_1, _("\ | |
5619 | Set whether gdb controls the inferior in non-stop mode."), _("\ | |
5620 | Show whether gdb controls the inferior in non-stop mode."), _("\ | |
5621 | When debugging a multi-threaded program and this setting is\n\ | |
5622 | off (the default, also called all-stop mode), when one thread stops\n\ | |
5623 | (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\ | |
5624 | all other threads in the program while you interact with the thread of\n\ | |
5625 | interest. When you continue or step a thread, you can allow the other\n\ | |
5626 | threads to run, or have them remain stopped, but while you inspect any\n\ | |
5627 | thread's state, all threads stop.\n\ | |
5628 | \n\ | |
5629 | In non-stop mode, when one thread stops, other threads can continue\n\ | |
5630 | to run freely. You'll be able to step each thread independently,\n\ | |
5631 | leave it stopped or free to run as needed."), | |
5632 | set_non_stop, | |
5633 | show_non_stop, | |
5634 | &setlist, | |
5635 | &showlist); | |
5636 | ||
c906108c | 5637 | numsigs = (int) TARGET_SIGNAL_LAST; |
488f131b | 5638 | signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); |
c906108c SS |
5639 | signal_print = (unsigned char *) |
5640 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
5641 | signal_program = (unsigned char *) | |
5642 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
5643 | for (i = 0; i < numsigs; i++) | |
5644 | { | |
5645 | signal_stop[i] = 1; | |
5646 | signal_print[i] = 1; | |
5647 | signal_program[i] = 1; | |
5648 | } | |
5649 | ||
5650 | /* Signals caused by debugger's own actions | |
5651 | should not be given to the program afterwards. */ | |
5652 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
5653 | signal_program[TARGET_SIGNAL_INT] = 0; | |
5654 | ||
5655 | /* Signals that are not errors should not normally enter the debugger. */ | |
5656 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
5657 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
5658 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
5659 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
5660 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
5661 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
5662 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
5663 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
5664 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
5665 | signal_print[TARGET_SIGNAL_IO] = 0; | |
5666 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
5667 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
5668 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
5669 | signal_print[TARGET_SIGNAL_URG] = 0; | |
5670 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
5671 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
5672 | ||
cd0fc7c3 SS |
5673 | /* These signals are used internally by user-level thread |
5674 | implementations. (See signal(5) on Solaris.) Like the above | |
5675 | signals, a healthy program receives and handles them as part of | |
5676 | its normal operation. */ | |
5677 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
5678 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
5679 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
5680 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
5681 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
5682 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
5683 | ||
85c07804 AC |
5684 | add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, |
5685 | &stop_on_solib_events, _("\ | |
5686 | Set stopping for shared library events."), _("\ | |
5687 | Show stopping for shared library events."), _("\ | |
c906108c SS |
5688 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
5689 | notifies gdb of shared library events. The most common event of interest\n\ | |
85c07804 AC |
5690 | to the user would be loading/unloading of a new library."), |
5691 | NULL, | |
920d2a44 | 5692 | show_stop_on_solib_events, |
85c07804 | 5693 | &setlist, &showlist); |
c906108c | 5694 | |
7ab04401 AC |
5695 | add_setshow_enum_cmd ("follow-fork-mode", class_run, |
5696 | follow_fork_mode_kind_names, | |
5697 | &follow_fork_mode_string, _("\ | |
5698 | Set debugger response to a program call of fork or vfork."), _("\ | |
5699 | Show debugger response to a program call of fork or vfork."), _("\ | |
c906108c SS |
5700 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
5701 | parent - the original process is debugged after a fork\n\ | |
5702 | child - the new process is debugged after a fork\n\ | |
ea1dd7bc | 5703 | The unfollowed process will continue to run.\n\ |
7ab04401 AC |
5704 | By default, the debugger will follow the parent process."), |
5705 | NULL, | |
920d2a44 | 5706 | show_follow_fork_mode_string, |
7ab04401 AC |
5707 | &setlist, &showlist); |
5708 | ||
5709 | add_setshow_enum_cmd ("scheduler-locking", class_run, | |
5710 | scheduler_enums, &scheduler_mode, _("\ | |
5711 | Set mode for locking scheduler during execution."), _("\ | |
5712 | Show mode for locking scheduler during execution."), _("\ | |
c906108c SS |
5713 | off == no locking (threads may preempt at any time)\n\ |
5714 | on == full locking (no thread except the current thread may run)\n\ | |
5715 | step == scheduler locked during every single-step operation.\n\ | |
5716 | In this mode, no other thread may run during a step command.\n\ | |
7ab04401 AC |
5717 | Other threads may run while stepping over a function call ('next')."), |
5718 | set_schedlock_func, /* traps on target vector */ | |
920d2a44 | 5719 | show_scheduler_mode, |
7ab04401 | 5720 | &setlist, &showlist); |
5fbbeb29 | 5721 | |
5bf193a2 AC |
5722 | add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ |
5723 | Set mode of the step operation."), _("\ | |
5724 | Show mode of the step operation."), _("\ | |
5725 | When set, doing a step over a function without debug line information\n\ | |
5726 | will stop at the first instruction of that function. Otherwise, the\n\ | |
5727 | function is skipped and the step command stops at a different source line."), | |
5728 | NULL, | |
920d2a44 | 5729 | show_step_stop_if_no_debug, |
5bf193a2 | 5730 | &setlist, &showlist); |
ca6724c1 | 5731 | |
fff08868 HZ |
5732 | add_setshow_enum_cmd ("displaced-stepping", class_run, |
5733 | can_use_displaced_stepping_enum, | |
5734 | &can_use_displaced_stepping, _("\ | |
237fc4c9 PA |
5735 | Set debugger's willingness to use displaced stepping."), _("\ |
5736 | Show debugger's willingness to use displaced stepping."), _("\ | |
fff08868 HZ |
5737 | If on, gdb will use displaced stepping to step over breakpoints if it is\n\ |
5738 | supported by the target architecture. If off, gdb will not use displaced\n\ | |
5739 | stepping to step over breakpoints, even if such is supported by the target\n\ | |
5740 | architecture. If auto (which is the default), gdb will use displaced stepping\n\ | |
5741 | if the target architecture supports it and non-stop mode is active, but will not\n\ | |
5742 | use it in all-stop mode (see help set non-stop)."), | |
5743 | NULL, | |
5744 | show_can_use_displaced_stepping, | |
5745 | &setlist, &showlist); | |
237fc4c9 | 5746 | |
b2175913 MS |
5747 | add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names, |
5748 | &exec_direction, _("Set direction of execution.\n\ | |
5749 | Options are 'forward' or 'reverse'."), | |
5750 | _("Show direction of execution (forward/reverse)."), | |
5751 | _("Tells gdb whether to execute forward or backward."), | |
5752 | set_exec_direction_func, show_exec_direction_func, | |
5753 | &setlist, &showlist); | |
5754 | ||
ca6724c1 KB |
5755 | /* ptid initializations */ |
5756 | null_ptid = ptid_build (0, 0, 0); | |
5757 | minus_one_ptid = ptid_build (-1, 0, 0); | |
5758 | inferior_ptid = null_ptid; | |
5759 | target_last_wait_ptid = minus_one_ptid; | |
237fc4c9 | 5760 | displaced_step_ptid = null_ptid; |
5231c1fd PA |
5761 | |
5762 | observer_attach_thread_ptid_changed (infrun_thread_ptid_changed); | |
252fbfc8 | 5763 | observer_attach_thread_stop_requested (infrun_thread_stop_requested); |
a07daef3 | 5764 | observer_attach_thread_exit (infrun_thread_thread_exit); |
4aa995e1 PA |
5765 | |
5766 | /* Explicitly create without lookup, since that tries to create a | |
5767 | value with a void typed value, and when we get here, gdbarch | |
5768 | isn't initialized yet. At this point, we're quite sure there | |
5769 | isn't another convenience variable of the same name. */ | |
5770 | create_internalvar_type_lazy ("_siginfo", siginfo_make_value); | |
c906108c | 5771 | } |