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