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