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