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