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