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