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