Commit | Line | Data |
---|---|---|
ca557f44 AC |
1 | /* Target-struct-independent code to start (run) and stop an inferior |
2 | process. | |
8926118c AC |
3 | |
4 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, | |
7789c6f5 | 5 | 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software |
8926118c | 6 | 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 | |
12 | the Free Software Foundation; either version 2 of the License, or | |
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 JM |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | #include "gdb_string.h" | |
27 | #include <ctype.h> | |
28 | #include "symtab.h" | |
29 | #include "frame.h" | |
30 | #include "inferior.h" | |
31 | #include "breakpoint.h" | |
03f2053f | 32 | #include "gdb_wait.h" |
c906108c SS |
33 | #include "gdbcore.h" |
34 | #include "gdbcmd.h" | |
210661e7 | 35 | #include "cli/cli-script.h" |
c906108c SS |
36 | #include "target.h" |
37 | #include "gdbthread.h" | |
38 | #include "annotate.h" | |
1adeb98a | 39 | #include "symfile.h" |
7a292a7a | 40 | #include "top.h" |
c906108c | 41 | #include <signal.h> |
2acceee2 | 42 | #include "inf-loop.h" |
4e052eda | 43 | #include "regcache.h" |
fd0407d6 | 44 | #include "value.h" |
06600e06 | 45 | #include "observer.h" |
f636b87d | 46 | #include "language.h" |
c906108c SS |
47 | |
48 | /* Prototypes for local functions */ | |
49 | ||
96baa820 | 50 | static void signals_info (char *, int); |
c906108c | 51 | |
96baa820 | 52 | static void handle_command (char *, int); |
c906108c | 53 | |
96baa820 | 54 | static void sig_print_info (enum target_signal); |
c906108c | 55 | |
96baa820 | 56 | static void sig_print_header (void); |
c906108c | 57 | |
74b7792f | 58 | static void resume_cleanups (void *); |
c906108c | 59 | |
96baa820 | 60 | static int hook_stop_stub (void *); |
c906108c | 61 | |
96baa820 | 62 | static void delete_breakpoint_current_contents (void *); |
c906108c | 63 | |
96baa820 | 64 | static void set_follow_fork_mode_command (char *arg, int from_tty, |
488f131b | 65 | struct cmd_list_element *c); |
7a292a7a | 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 | |
96baa820 JM |
76 | struct execution_control_state; |
77 | ||
78 | static int currently_stepping (struct execution_control_state *ecs); | |
79 | ||
80 | static void xdb_handle_command (char *args, int from_tty); | |
81 | ||
82 | void _initialize_infrun (void); | |
43ff13b4 | 83 | |
c906108c SS |
84 | int inferior_ignoring_startup_exec_events = 0; |
85 | int inferior_ignoring_leading_exec_events = 0; | |
86 | ||
5fbbeb29 CF |
87 | /* When set, stop the 'step' command if we enter a function which has |
88 | no line number information. The normal behavior is that we step | |
89 | over such function. */ | |
90 | int step_stop_if_no_debug = 0; | |
91 | ||
43ff13b4 | 92 | /* In asynchronous mode, but simulating synchronous execution. */ |
96baa820 | 93 | |
43ff13b4 JM |
94 | int sync_execution = 0; |
95 | ||
c906108c SS |
96 | /* wait_for_inferior and normal_stop use this to notify the user |
97 | when the inferior stopped in a different thread than it had been | |
96baa820 JM |
98 | running in. */ |
99 | ||
39f77062 | 100 | static ptid_t previous_inferior_ptid; |
7a292a7a SS |
101 | |
102 | /* This is true for configurations that may follow through execl() and | |
103 | similar functions. At present this is only true for HP-UX native. */ | |
104 | ||
105 | #ifndef MAY_FOLLOW_EXEC | |
106 | #define MAY_FOLLOW_EXEC (0) | |
c906108c SS |
107 | #endif |
108 | ||
7a292a7a SS |
109 | static int may_follow_exec = MAY_FOLLOW_EXEC; |
110 | ||
d4f3574e SS |
111 | /* If the program uses ELF-style shared libraries, then calls to |
112 | functions in shared libraries go through stubs, which live in a | |
113 | table called the PLT (Procedure Linkage Table). The first time the | |
114 | function is called, the stub sends control to the dynamic linker, | |
115 | which looks up the function's real address, patches the stub so | |
116 | that future calls will go directly to the function, and then passes | |
117 | control to the function. | |
118 | ||
119 | If we are stepping at the source level, we don't want to see any of | |
120 | this --- we just want to skip over the stub and the dynamic linker. | |
121 | The simple approach is to single-step until control leaves the | |
122 | dynamic linker. | |
123 | ||
ca557f44 AC |
124 | However, on some systems (e.g., Red Hat's 5.2 distribution) the |
125 | dynamic linker calls functions in the shared C library, so you | |
126 | can't tell from the PC alone whether the dynamic linker is still | |
127 | running. In this case, we use a step-resume breakpoint to get us | |
128 | past the dynamic linker, as if we were using "next" to step over a | |
129 | function call. | |
d4f3574e SS |
130 | |
131 | IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic | |
132 | linker code or not. Normally, this means we single-step. However, | |
133 | if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an | |
134 | address where we can place a step-resume breakpoint to get past the | |
135 | linker's symbol resolution function. | |
136 | ||
137 | IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a | |
138 | pretty portable way, by comparing the PC against the address ranges | |
139 | of the dynamic linker's sections. | |
140 | ||
141 | SKIP_SOLIB_RESOLVER is generally going to be system-specific, since | |
142 | it depends on internal details of the dynamic linker. It's usually | |
143 | not too hard to figure out where to put a breakpoint, but it | |
144 | certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of | |
145 | sanity checking. If it can't figure things out, returning zero and | |
146 | getting the (possibly confusing) stepping behavior is better than | |
147 | signalling an error, which will obscure the change in the | |
148 | inferior's state. */ | |
c906108c SS |
149 | |
150 | #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE | |
151 | #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0 | |
152 | #endif | |
153 | ||
d4f3574e SS |
154 | #ifndef SKIP_SOLIB_RESOLVER |
155 | #define SKIP_SOLIB_RESOLVER(pc) 0 | |
156 | #endif | |
157 | ||
c906108c SS |
158 | /* This function returns TRUE if pc is the address of an instruction |
159 | that lies within the dynamic linker (such as the event hook, or the | |
160 | dld itself). | |
161 | ||
162 | This function must be used only when a dynamic linker event has | |
163 | been caught, and the inferior is being stepped out of the hook, or | |
164 | undefined results are guaranteed. */ | |
165 | ||
166 | #ifndef SOLIB_IN_DYNAMIC_LINKER | |
167 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 | |
168 | #endif | |
169 | ||
170 | /* On MIPS16, a function that returns a floating point value may call | |
171 | a library helper function to copy the return value to a floating point | |
172 | register. The IGNORE_HELPER_CALL macro returns non-zero if we | |
173 | should ignore (i.e. step over) this function call. */ | |
174 | #ifndef IGNORE_HELPER_CALL | |
175 | #define IGNORE_HELPER_CALL(pc) 0 | |
176 | #endif | |
177 | ||
178 | /* On some systems, the PC may be left pointing at an instruction that won't | |
179 | actually be executed. This is usually indicated by a bit in the PSW. If | |
180 | we find ourselves in such a state, then we step the target beyond the | |
181 | nullified instruction before returning control to the user so as to avoid | |
182 | confusion. */ | |
183 | ||
184 | #ifndef INSTRUCTION_NULLIFIED | |
185 | #define INSTRUCTION_NULLIFIED 0 | |
186 | #endif | |
187 | ||
c2c6d25f JM |
188 | /* We can't step off a permanent breakpoint in the ordinary way, because we |
189 | can't remove it. Instead, we have to advance the PC to the next | |
190 | instruction. This macro should expand to a pointer to a function that | |
191 | does that, or zero if we have no such function. If we don't have a | |
192 | definition for it, we have to report an error. */ | |
488f131b | 193 | #ifndef SKIP_PERMANENT_BREAKPOINT |
c2c6d25f JM |
194 | #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint) |
195 | static void | |
c2d11a7d | 196 | default_skip_permanent_breakpoint (void) |
c2c6d25f | 197 | { |
255e7dbf | 198 | error ("\ |
c2c6d25f JM |
199 | The program is stopped at a permanent breakpoint, but GDB does not know\n\ |
200 | how to step past a permanent breakpoint on this architecture. Try using\n\ | |
255e7dbf | 201 | a command like `return' or `jump' to continue execution."); |
c2c6d25f JM |
202 | } |
203 | #endif | |
488f131b | 204 | |
c2c6d25f | 205 | |
7a292a7a SS |
206 | /* Convert the #defines into values. This is temporary until wfi control |
207 | flow is completely sorted out. */ | |
208 | ||
209 | #ifndef HAVE_STEPPABLE_WATCHPOINT | |
210 | #define HAVE_STEPPABLE_WATCHPOINT 0 | |
211 | #else | |
212 | #undef HAVE_STEPPABLE_WATCHPOINT | |
213 | #define HAVE_STEPPABLE_WATCHPOINT 1 | |
214 | #endif | |
215 | ||
692590c1 MS |
216 | #ifndef CANNOT_STEP_HW_WATCHPOINTS |
217 | #define CANNOT_STEP_HW_WATCHPOINTS 0 | |
218 | #else | |
219 | #undef CANNOT_STEP_HW_WATCHPOINTS | |
220 | #define CANNOT_STEP_HW_WATCHPOINTS 1 | |
221 | #endif | |
222 | ||
c906108c SS |
223 | /* Tables of how to react to signals; the user sets them. */ |
224 | ||
225 | static unsigned char *signal_stop; | |
226 | static unsigned char *signal_print; | |
227 | static unsigned char *signal_program; | |
228 | ||
229 | #define SET_SIGS(nsigs,sigs,flags) \ | |
230 | do { \ | |
231 | int signum = (nsigs); \ | |
232 | while (signum-- > 0) \ | |
233 | if ((sigs)[signum]) \ | |
234 | (flags)[signum] = 1; \ | |
235 | } while (0) | |
236 | ||
237 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
238 | do { \ | |
239 | int signum = (nsigs); \ | |
240 | while (signum-- > 0) \ | |
241 | if ((sigs)[signum]) \ | |
242 | (flags)[signum] = 0; \ | |
243 | } while (0) | |
244 | ||
39f77062 KB |
245 | /* Value to pass to target_resume() to cause all threads to resume */ |
246 | ||
247 | #define RESUME_ALL (pid_to_ptid (-1)) | |
c906108c SS |
248 | |
249 | /* Command list pointer for the "stop" placeholder. */ | |
250 | ||
251 | static struct cmd_list_element *stop_command; | |
252 | ||
253 | /* Nonzero if breakpoints are now inserted in the inferior. */ | |
254 | ||
255 | static int breakpoints_inserted; | |
256 | ||
257 | /* Function inferior was in as of last step command. */ | |
258 | ||
259 | static struct symbol *step_start_function; | |
260 | ||
261 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ | |
262 | ||
263 | static int trap_expected; | |
264 | ||
265 | #ifdef SOLIB_ADD | |
266 | /* Nonzero if we want to give control to the user when we're notified | |
267 | of shared library events by the dynamic linker. */ | |
268 | static int stop_on_solib_events; | |
269 | #endif | |
270 | ||
271 | #ifdef HP_OS_BUG | |
272 | /* Nonzero if the next time we try to continue the inferior, it will | |
273 | step one instruction and generate a spurious trace trap. | |
274 | This is used to compensate for a bug in HP-UX. */ | |
275 | ||
276 | static int trap_expected_after_continue; | |
277 | #endif | |
278 | ||
279 | /* Nonzero means expecting a trace trap | |
280 | and should stop the inferior and return silently when it happens. */ | |
281 | ||
282 | int stop_after_trap; | |
283 | ||
284 | /* Nonzero means expecting a trap and caller will handle it themselves. | |
285 | It is used after attach, due to attaching to a process; | |
286 | when running in the shell before the child program has been exec'd; | |
287 | and when running some kinds of remote stuff (FIXME?). */ | |
288 | ||
c0236d92 | 289 | enum stop_kind stop_soon; |
c906108c SS |
290 | |
291 | /* Nonzero if proceed is being used for a "finish" command or a similar | |
292 | situation when stop_registers should be saved. */ | |
293 | ||
294 | int proceed_to_finish; | |
295 | ||
296 | /* Save register contents here when about to pop a stack dummy frame, | |
297 | if-and-only-if proceed_to_finish is set. | |
298 | Thus this contains the return value from the called function (assuming | |
299 | values are returned in a register). */ | |
300 | ||
72cec141 | 301 | struct regcache *stop_registers; |
c906108c SS |
302 | |
303 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ | |
304 | ||
305 | static int breakpoints_failed; | |
306 | ||
307 | /* Nonzero after stop if current stack frame should be printed. */ | |
308 | ||
309 | static int stop_print_frame; | |
310 | ||
311 | static struct breakpoint *step_resume_breakpoint = NULL; | |
312 | static struct breakpoint *through_sigtramp_breakpoint = NULL; | |
313 | ||
314 | /* On some platforms (e.g., HP-UX), hardware watchpoints have bad | |
315 | interactions with an inferior that is running a kernel function | |
316 | (aka, a system call or "syscall"). wait_for_inferior therefore | |
317 | may have a need to know when the inferior is in a syscall. This | |
318 | is a count of the number of inferior threads which are known to | |
319 | currently be running in a syscall. */ | |
320 | static int number_of_threads_in_syscalls; | |
321 | ||
e02bc4cc DS |
322 | /* This is a cached copy of the pid/waitstatus of the last event |
323 | returned by target_wait()/target_wait_hook(). This information is | |
324 | returned by get_last_target_status(). */ | |
39f77062 | 325 | static ptid_t target_last_wait_ptid; |
e02bc4cc DS |
326 | static struct target_waitstatus target_last_waitstatus; |
327 | ||
c906108c SS |
328 | /* This is used to remember when a fork, vfork or exec event |
329 | was caught by a catchpoint, and thus the event is to be | |
330 | followed at the next resume of the inferior, and not | |
331 | immediately. */ | |
332 | static struct | |
488f131b JB |
333 | { |
334 | enum target_waitkind kind; | |
335 | struct | |
c906108c | 336 | { |
488f131b | 337 | int parent_pid; |
488f131b | 338 | int child_pid; |
c906108c | 339 | } |
488f131b JB |
340 | fork_event; |
341 | char *execd_pathname; | |
342 | } | |
c906108c SS |
343 | pending_follow; |
344 | ||
53904c9e | 345 | static const char follow_fork_mode_ask[] = "ask"; |
53904c9e AC |
346 | static const char follow_fork_mode_child[] = "child"; |
347 | static const char follow_fork_mode_parent[] = "parent"; | |
348 | ||
488f131b | 349 | static const char *follow_fork_mode_kind_names[] = { |
53904c9e | 350 | follow_fork_mode_ask, |
53904c9e AC |
351 | follow_fork_mode_child, |
352 | follow_fork_mode_parent, | |
353 | NULL | |
ef346e04 | 354 | }; |
c906108c | 355 | |
53904c9e | 356 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
c906108c SS |
357 | \f |
358 | ||
6604731b | 359 | static int |
4ef3f3be | 360 | follow_fork (void) |
c906108c | 361 | { |
53904c9e | 362 | const char *follow_mode = follow_fork_mode_string; |
6604731b | 363 | int follow_child = (follow_mode == follow_fork_mode_child); |
c906108c SS |
364 | |
365 | /* Or, did the user not know, and want us to ask? */ | |
e28d556f | 366 | if (follow_fork_mode_string == follow_fork_mode_ask) |
c906108c | 367 | { |
8e65ff28 AC |
368 | internal_error (__FILE__, __LINE__, |
369 | "follow_inferior_fork: \"ask\" mode not implemented"); | |
53904c9e | 370 | /* follow_mode = follow_fork_mode_...; */ |
c906108c SS |
371 | } |
372 | ||
6604731b | 373 | return target_follow_fork (follow_child); |
c906108c SS |
374 | } |
375 | ||
6604731b DJ |
376 | void |
377 | follow_inferior_reset_breakpoints (void) | |
c906108c | 378 | { |
6604731b DJ |
379 | /* Was there a step_resume breakpoint? (There was if the user |
380 | did a "next" at the fork() call.) If so, explicitly reset its | |
381 | thread number. | |
382 | ||
383 | step_resumes are a form of bp that are made to be per-thread. | |
384 | Since we created the step_resume bp when the parent process | |
385 | was being debugged, and now are switching to the child process, | |
386 | from the breakpoint package's viewpoint, that's a switch of | |
387 | "threads". We must update the bp's notion of which thread | |
388 | it is for, or it'll be ignored when it triggers. */ | |
389 | ||
390 | if (step_resume_breakpoint) | |
391 | breakpoint_re_set_thread (step_resume_breakpoint); | |
392 | ||
393 | /* Reinsert all breakpoints in the child. The user may have set | |
394 | breakpoints after catching the fork, in which case those | |
395 | were never set in the child, but only in the parent. This makes | |
396 | sure the inserted breakpoints match the breakpoint list. */ | |
397 | ||
398 | breakpoint_re_set (); | |
399 | insert_breakpoints (); | |
c906108c | 400 | } |
c906108c | 401 | |
1adeb98a FN |
402 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
403 | ||
c906108c | 404 | static void |
96baa820 | 405 | follow_exec (int pid, char *execd_pathname) |
c906108c | 406 | { |
c906108c | 407 | int saved_pid = pid; |
7a292a7a SS |
408 | struct target_ops *tgt; |
409 | ||
410 | if (!may_follow_exec) | |
411 | return; | |
c906108c | 412 | |
c906108c SS |
413 | /* This is an exec event that we actually wish to pay attention to. |
414 | Refresh our symbol table to the newly exec'd program, remove any | |
415 | momentary bp's, etc. | |
416 | ||
417 | If there are breakpoints, they aren't really inserted now, | |
418 | since the exec() transformed our inferior into a fresh set | |
419 | of instructions. | |
420 | ||
421 | We want to preserve symbolic breakpoints on the list, since | |
422 | we have hopes that they can be reset after the new a.out's | |
423 | symbol table is read. | |
424 | ||
425 | However, any "raw" breakpoints must be removed from the list | |
426 | (e.g., the solib bp's), since their address is probably invalid | |
427 | now. | |
428 | ||
429 | And, we DON'T want to call delete_breakpoints() here, since | |
430 | that may write the bp's "shadow contents" (the instruction | |
431 | value that was overwritten witha TRAP instruction). Since | |
432 | we now have a new a.out, those shadow contents aren't valid. */ | |
433 | update_breakpoints_after_exec (); | |
434 | ||
435 | /* If there was one, it's gone now. We cannot truly step-to-next | |
436 | statement through an exec(). */ | |
437 | step_resume_breakpoint = NULL; | |
438 | step_range_start = 0; | |
439 | step_range_end = 0; | |
440 | ||
441 | /* If there was one, it's gone now. */ | |
442 | through_sigtramp_breakpoint = NULL; | |
443 | ||
444 | /* What is this a.out's name? */ | |
445 | printf_unfiltered ("Executing new program: %s\n", execd_pathname); | |
446 | ||
447 | /* We've followed the inferior through an exec. Therefore, the | |
448 | inferior has essentially been killed & reborn. */ | |
7a292a7a SS |
449 | |
450 | /* First collect the run target in effect. */ | |
451 | tgt = find_run_target (); | |
452 | /* If we can't find one, things are in a very strange state... */ | |
453 | if (tgt == NULL) | |
454 | error ("Could find run target to save before following exec"); | |
455 | ||
c906108c SS |
456 | gdb_flush (gdb_stdout); |
457 | target_mourn_inferior (); | |
39f77062 | 458 | inferior_ptid = pid_to_ptid (saved_pid); |
488f131b | 459 | /* Because mourn_inferior resets inferior_ptid. */ |
7a292a7a | 460 | push_target (tgt); |
c906108c SS |
461 | |
462 | /* That a.out is now the one to use. */ | |
463 | exec_file_attach (execd_pathname, 0); | |
464 | ||
465 | /* And also is where symbols can be found. */ | |
1adeb98a | 466 | symbol_file_add_main (execd_pathname, 0); |
c906108c SS |
467 | |
468 | /* Reset the shared library package. This ensures that we get | |
469 | a shlib event when the child reaches "_start", at which point | |
470 | the dld will have had a chance to initialize the child. */ | |
7a292a7a | 471 | #if defined(SOLIB_RESTART) |
c906108c | 472 | SOLIB_RESTART (); |
7a292a7a SS |
473 | #endif |
474 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
39f77062 | 475 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
7a292a7a | 476 | #endif |
c906108c SS |
477 | |
478 | /* Reinsert all breakpoints. (Those which were symbolic have | |
479 | been reset to the proper address in the new a.out, thanks | |
480 | to symbol_file_command...) */ | |
481 | insert_breakpoints (); | |
482 | ||
483 | /* The next resume of this inferior should bring it to the shlib | |
484 | startup breakpoints. (If the user had also set bp's on | |
485 | "main" from the old (parent) process, then they'll auto- | |
486 | matically get reset there in the new process.) */ | |
c906108c SS |
487 | } |
488 | ||
489 | /* Non-zero if we just simulating a single-step. This is needed | |
490 | because we cannot remove the breakpoints in the inferior process | |
491 | until after the `wait' in `wait_for_inferior'. */ | |
492 | static int singlestep_breakpoints_inserted_p = 0; | |
493 | \f | |
494 | ||
495 | /* Things to clean up if we QUIT out of resume (). */ | |
496 | /* ARGSUSED */ | |
497 | static void | |
74b7792f | 498 | resume_cleanups (void *ignore) |
c906108c SS |
499 | { |
500 | normal_stop (); | |
501 | } | |
502 | ||
53904c9e AC |
503 | static const char schedlock_off[] = "off"; |
504 | static const char schedlock_on[] = "on"; | |
505 | static const char schedlock_step[] = "step"; | |
506 | static const char *scheduler_mode = schedlock_off; | |
488f131b | 507 | static const char *scheduler_enums[] = { |
ef346e04 AC |
508 | schedlock_off, |
509 | schedlock_on, | |
510 | schedlock_step, | |
511 | NULL | |
512 | }; | |
c906108c SS |
513 | |
514 | static void | |
96baa820 | 515 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
c906108c | 516 | { |
1868c04e AC |
517 | /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones |
518 | the set command passed as a parameter. The clone operation will | |
519 | include (BUG?) any ``set'' command callback, if present. | |
520 | Commands like ``info set'' call all the ``show'' command | |
521 | callbacks. Unfortunatly, for ``show'' commands cloned from | |
522 | ``set'', this includes callbacks belonging to ``set'' commands. | |
523 | Making this worse, this only occures if add_show_from_set() is | |
524 | called after add_cmd_sfunc() (BUG?). */ | |
525 | if (cmd_type (c) == set_cmd) | |
c906108c SS |
526 | if (!target_can_lock_scheduler) |
527 | { | |
528 | scheduler_mode = schedlock_off; | |
488f131b | 529 | error ("Target '%s' cannot support this command.", target_shortname); |
c906108c SS |
530 | } |
531 | } | |
532 | ||
533 | ||
534 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
535 | wants to interrupt some lengthy single-stepping operation | |
536 | (for child processes, the SIGINT goes to the inferior, and so | |
537 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
538 | other targets, that's not true). | |
539 | ||
540 | STEP nonzero if we should step (zero to continue instead). | |
541 | SIG is the signal to give the inferior (zero for none). */ | |
542 | void | |
96baa820 | 543 | resume (int step, enum target_signal sig) |
c906108c SS |
544 | { |
545 | int should_resume = 1; | |
74b7792f | 546 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
c906108c SS |
547 | QUIT; |
548 | ||
ef5cf84e MS |
549 | /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */ |
550 | ||
c906108c | 551 | |
692590c1 MS |
552 | /* Some targets (e.g. Solaris x86) have a kernel bug when stepping |
553 | over an instruction that causes a page fault without triggering | |
554 | a hardware watchpoint. The kernel properly notices that it shouldn't | |
555 | stop, because the hardware watchpoint is not triggered, but it forgets | |
556 | the step request and continues the program normally. | |
557 | Work around the problem by removing hardware watchpoints if a step is | |
558 | requested, GDB will check for a hardware watchpoint trigger after the | |
559 | step anyway. */ | |
560 | if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted) | |
561 | remove_hw_watchpoints (); | |
488f131b | 562 | |
692590c1 | 563 | |
c2c6d25f JM |
564 | /* Normally, by the time we reach `resume', the breakpoints are either |
565 | removed or inserted, as appropriate. The exception is if we're sitting | |
566 | at a permanent breakpoint; we need to step over it, but permanent | |
567 | breakpoints can't be removed. So we have to test for it here. */ | |
568 | if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here) | |
569 | SKIP_PERMANENT_BREAKPOINT (); | |
570 | ||
b0ed3589 | 571 | if (SOFTWARE_SINGLE_STEP_P () && step) |
c906108c SS |
572 | { |
573 | /* Do it the hard way, w/temp breakpoints */ | |
c5aa993b | 574 | SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ ); |
c906108c SS |
575 | /* ...and don't ask hardware to do it. */ |
576 | step = 0; | |
577 | /* and do not pull these breakpoints until after a `wait' in | |
578 | `wait_for_inferior' */ | |
579 | singlestep_breakpoints_inserted_p = 1; | |
580 | } | |
581 | ||
582 | /* Handle any optimized stores to the inferior NOW... */ | |
583 | #ifdef DO_DEFERRED_STORES | |
584 | DO_DEFERRED_STORES; | |
585 | #endif | |
586 | ||
c906108c | 587 | /* If there were any forks/vforks/execs that were caught and are |
6604731b | 588 | now to be followed, then do so. */ |
c906108c SS |
589 | switch (pending_follow.kind) |
590 | { | |
6604731b DJ |
591 | case TARGET_WAITKIND_FORKED: |
592 | case TARGET_WAITKIND_VFORKED: | |
c906108c | 593 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
6604731b DJ |
594 | if (follow_fork ()) |
595 | should_resume = 0; | |
c906108c SS |
596 | break; |
597 | ||
6604731b | 598 | case TARGET_WAITKIND_EXECD: |
c906108c | 599 | /* follow_exec is called as soon as the exec event is seen. */ |
6604731b | 600 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
c906108c SS |
601 | break; |
602 | ||
603 | default: | |
604 | break; | |
605 | } | |
c906108c SS |
606 | |
607 | /* Install inferior's terminal modes. */ | |
608 | target_terminal_inferior (); | |
609 | ||
610 | if (should_resume) | |
611 | { | |
39f77062 | 612 | ptid_t resume_ptid; |
dfcd3bfb | 613 | |
488f131b | 614 | resume_ptid = RESUME_ALL; /* Default */ |
ef5cf84e MS |
615 | |
616 | if ((step || singlestep_breakpoints_inserted_p) && | |
617 | !breakpoints_inserted && breakpoint_here_p (read_pc ())) | |
c906108c | 618 | { |
ef5cf84e MS |
619 | /* Stepping past a breakpoint without inserting breakpoints. |
620 | Make sure only the current thread gets to step, so that | |
621 | other threads don't sneak past breakpoints while they are | |
622 | not inserted. */ | |
c906108c | 623 | |
ef5cf84e | 624 | resume_ptid = inferior_ptid; |
c906108c | 625 | } |
ef5cf84e MS |
626 | |
627 | if ((scheduler_mode == schedlock_on) || | |
488f131b | 628 | (scheduler_mode == schedlock_step && |
ef5cf84e | 629 | (step || singlestep_breakpoints_inserted_p))) |
c906108c | 630 | { |
ef5cf84e | 631 | /* User-settable 'scheduler' mode requires solo thread resume. */ |
488f131b | 632 | resume_ptid = inferior_ptid; |
c906108c | 633 | } |
ef5cf84e | 634 | |
c4ed33b9 AC |
635 | if (CANNOT_STEP_BREAKPOINT) |
636 | { | |
637 | /* Most targets can step a breakpoint instruction, thus | |
638 | executing it normally. But if this one cannot, just | |
639 | continue and we will hit it anyway. */ | |
640 | if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) | |
641 | step = 0; | |
642 | } | |
39f77062 | 643 | target_resume (resume_ptid, step, sig); |
c906108c SS |
644 | } |
645 | ||
646 | discard_cleanups (old_cleanups); | |
647 | } | |
648 | \f | |
649 | ||
650 | /* Clear out all variables saying what to do when inferior is continued. | |
651 | First do this, then set the ones you want, then call `proceed'. */ | |
652 | ||
653 | void | |
96baa820 | 654 | clear_proceed_status (void) |
c906108c SS |
655 | { |
656 | trap_expected = 0; | |
657 | step_range_start = 0; | |
658 | step_range_end = 0; | |
aa0cd9c1 | 659 | step_frame_id = null_frame_id; |
5fbbeb29 | 660 | step_over_calls = STEP_OVER_UNDEBUGGABLE; |
c906108c | 661 | stop_after_trap = 0; |
c0236d92 | 662 | stop_soon = NO_STOP_QUIETLY; |
c906108c SS |
663 | proceed_to_finish = 0; |
664 | breakpoint_proceeded = 1; /* We're about to proceed... */ | |
665 | ||
666 | /* Discard any remaining commands or status from previous stop. */ | |
667 | bpstat_clear (&stop_bpstat); | |
668 | } | |
669 | ||
e4846b08 JJ |
670 | |
671 | /* Record the pc of the program the last time it stopped. This is | |
672 | just used internally by wait_for_inferior, but need to be preserved | |
673 | over calls to it and cleared when the inferior is started. */ | |
674 | static CORE_ADDR prev_pc; | |
675 | ||
c906108c SS |
676 | /* Basic routine for continuing the program in various fashions. |
677 | ||
678 | ADDR is the address to resume at, or -1 for resume where stopped. | |
679 | SIGGNAL is the signal to give it, or 0 for none, | |
c5aa993b | 680 | or -1 for act according to how it stopped. |
c906108c | 681 | STEP is nonzero if should trap after one instruction. |
c5aa993b JM |
682 | -1 means return after that and print nothing. |
683 | You should probably set various step_... variables | |
684 | before calling here, if you are stepping. | |
c906108c SS |
685 | |
686 | You should call clear_proceed_status before calling proceed. */ | |
687 | ||
688 | void | |
96baa820 | 689 | proceed (CORE_ADDR addr, enum target_signal siggnal, int step) |
c906108c SS |
690 | { |
691 | int oneproc = 0; | |
692 | ||
693 | if (step > 0) | |
694 | step_start_function = find_pc_function (read_pc ()); | |
695 | if (step < 0) | |
696 | stop_after_trap = 1; | |
697 | ||
2acceee2 | 698 | if (addr == (CORE_ADDR) -1) |
c906108c SS |
699 | { |
700 | /* If there is a breakpoint at the address we will resume at, | |
c5aa993b JM |
701 | step one instruction before inserting breakpoints |
702 | so that we do not stop right away (and report a second | |
c906108c SS |
703 | hit at this breakpoint). */ |
704 | ||
705 | if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) | |
706 | oneproc = 1; | |
707 | ||
708 | #ifndef STEP_SKIPS_DELAY | |
709 | #define STEP_SKIPS_DELAY(pc) (0) | |
710 | #define STEP_SKIPS_DELAY_P (0) | |
711 | #endif | |
712 | /* Check breakpoint_here_p first, because breakpoint_here_p is fast | |
c5aa993b JM |
713 | (it just checks internal GDB data structures) and STEP_SKIPS_DELAY |
714 | is slow (it needs to read memory from the target). */ | |
c906108c SS |
715 | if (STEP_SKIPS_DELAY_P |
716 | && breakpoint_here_p (read_pc () + 4) | |
717 | && STEP_SKIPS_DELAY (read_pc ())) | |
718 | oneproc = 1; | |
719 | } | |
720 | else | |
721 | { | |
722 | write_pc (addr); | |
c906108c SS |
723 | } |
724 | ||
725 | #ifdef PREPARE_TO_PROCEED | |
726 | /* In a multi-threaded task we may select another thread | |
727 | and then continue or step. | |
728 | ||
729 | But if the old thread was stopped at a breakpoint, it | |
730 | will immediately cause another breakpoint stop without | |
731 | any execution (i.e. it will report a breakpoint hit | |
732 | incorrectly). So we must step over it first. | |
733 | ||
734 | PREPARE_TO_PROCEED checks the current thread against the thread | |
735 | that reported the most recent event. If a step-over is required | |
736 | it returns TRUE and sets the current thread to the old thread. */ | |
9e086581 | 737 | if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ())) |
c906108c SS |
738 | { |
739 | oneproc = 1; | |
c906108c SS |
740 | } |
741 | ||
742 | #endif /* PREPARE_TO_PROCEED */ | |
743 | ||
744 | #ifdef HP_OS_BUG | |
745 | if (trap_expected_after_continue) | |
746 | { | |
747 | /* If (step == 0), a trap will be automatically generated after | |
c5aa993b JM |
748 | the first instruction is executed. Force step one |
749 | instruction to clear this condition. This should not occur | |
750 | if step is nonzero, but it is harmless in that case. */ | |
c906108c SS |
751 | oneproc = 1; |
752 | trap_expected_after_continue = 0; | |
753 | } | |
754 | #endif /* HP_OS_BUG */ | |
755 | ||
756 | if (oneproc) | |
757 | /* We will get a trace trap after one instruction. | |
758 | Continue it automatically and insert breakpoints then. */ | |
759 | trap_expected = 1; | |
760 | else | |
761 | { | |
81d0cc19 GS |
762 | insert_breakpoints (); |
763 | /* If we get here there was no call to error() in | |
764 | insert breakpoints -- so they were inserted. */ | |
c906108c SS |
765 | breakpoints_inserted = 1; |
766 | } | |
767 | ||
768 | if (siggnal != TARGET_SIGNAL_DEFAULT) | |
769 | stop_signal = siggnal; | |
770 | /* If this signal should not be seen by program, | |
771 | give it zero. Used for debugging signals. */ | |
772 | else if (!signal_program[stop_signal]) | |
773 | stop_signal = TARGET_SIGNAL_0; | |
774 | ||
775 | annotate_starting (); | |
776 | ||
777 | /* Make sure that output from GDB appears before output from the | |
778 | inferior. */ | |
779 | gdb_flush (gdb_stdout); | |
780 | ||
e4846b08 JJ |
781 | /* Refresh prev_pc value just prior to resuming. This used to be |
782 | done in stop_stepping, however, setting prev_pc there did not handle | |
783 | scenarios such as inferior function calls or returning from | |
784 | a function via the return command. In those cases, the prev_pc | |
785 | value was not set properly for subsequent commands. The prev_pc value | |
786 | is used to initialize the starting line number in the ecs. With an | |
787 | invalid value, the gdb next command ends up stopping at the position | |
788 | represented by the next line table entry past our start position. | |
789 | On platforms that generate one line table entry per line, this | |
790 | is not a problem. However, on the ia64, the compiler generates | |
791 | extraneous line table entries that do not increase the line number. | |
792 | When we issue the gdb next command on the ia64 after an inferior call | |
793 | or a return command, we often end up a few instructions forward, still | |
794 | within the original line we started. | |
795 | ||
796 | An attempt was made to have init_execution_control_state () refresh | |
797 | the prev_pc value before calculating the line number. This approach | |
798 | did not work because on platforms that use ptrace, the pc register | |
799 | cannot be read unless the inferior is stopped. At that point, we | |
800 | are not guaranteed the inferior is stopped and so the read_pc () | |
801 | call can fail. Setting the prev_pc value here ensures the value is | |
802 | updated correctly when the inferior is stopped. */ | |
803 | prev_pc = read_pc (); | |
804 | ||
c906108c SS |
805 | /* Resume inferior. */ |
806 | resume (oneproc || step || bpstat_should_step (), stop_signal); | |
807 | ||
808 | /* Wait for it to stop (if not standalone) | |
809 | and in any case decode why it stopped, and act accordingly. */ | |
43ff13b4 JM |
810 | /* Do this only if we are not using the event loop, or if the target |
811 | does not support asynchronous execution. */ | |
6426a772 | 812 | if (!event_loop_p || !target_can_async_p ()) |
43ff13b4 JM |
813 | { |
814 | wait_for_inferior (); | |
815 | normal_stop (); | |
816 | } | |
c906108c | 817 | } |
c906108c SS |
818 | \f |
819 | ||
820 | /* Start remote-debugging of a machine over a serial link. */ | |
96baa820 | 821 | |
c906108c | 822 | void |
96baa820 | 823 | start_remote (void) |
c906108c SS |
824 | { |
825 | init_thread_list (); | |
826 | init_wait_for_inferior (); | |
c0236d92 | 827 | stop_soon = STOP_QUIETLY; |
c906108c | 828 | trap_expected = 0; |
43ff13b4 | 829 | |
6426a772 JM |
830 | /* Always go on waiting for the target, regardless of the mode. */ |
831 | /* FIXME: cagney/1999-09-23: At present it isn't possible to | |
7e73cedf | 832 | indicate to wait_for_inferior that a target should timeout if |
6426a772 JM |
833 | nothing is returned (instead of just blocking). Because of this, |
834 | targets expecting an immediate response need to, internally, set | |
835 | things up so that the target_wait() is forced to eventually | |
836 | timeout. */ | |
837 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to | |
838 | differentiate to its caller what the state of the target is after | |
839 | the initial open has been performed. Here we're assuming that | |
840 | the target has stopped. It should be possible to eventually have | |
841 | target_open() return to the caller an indication that the target | |
842 | is currently running and GDB state should be set to the same as | |
843 | for an async run. */ | |
844 | wait_for_inferior (); | |
845 | normal_stop (); | |
c906108c SS |
846 | } |
847 | ||
848 | /* Initialize static vars when a new inferior begins. */ | |
849 | ||
850 | void | |
96baa820 | 851 | init_wait_for_inferior (void) |
c906108c SS |
852 | { |
853 | /* These are meaningless until the first time through wait_for_inferior. */ | |
854 | prev_pc = 0; | |
c906108c SS |
855 | |
856 | #ifdef HP_OS_BUG | |
857 | trap_expected_after_continue = 0; | |
858 | #endif | |
859 | breakpoints_inserted = 0; | |
860 | breakpoint_init_inferior (inf_starting); | |
861 | ||
862 | /* Don't confuse first call to proceed(). */ | |
863 | stop_signal = TARGET_SIGNAL_0; | |
864 | ||
865 | /* The first resume is not following a fork/vfork/exec. */ | |
866 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ | |
c906108c SS |
867 | |
868 | /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */ | |
869 | number_of_threads_in_syscalls = 0; | |
870 | ||
871 | clear_proceed_status (); | |
872 | } | |
873 | ||
874 | static void | |
96baa820 | 875 | delete_breakpoint_current_contents (void *arg) |
c906108c SS |
876 | { |
877 | struct breakpoint **breakpointp = (struct breakpoint **) arg; | |
878 | if (*breakpointp != NULL) | |
879 | { | |
880 | delete_breakpoint (*breakpointp); | |
881 | *breakpointp = NULL; | |
882 | } | |
883 | } | |
884 | \f | |
b83266a0 SS |
885 | /* This enum encodes possible reasons for doing a target_wait, so that |
886 | wfi can call target_wait in one place. (Ultimately the call will be | |
887 | moved out of the infinite loop entirely.) */ | |
888 | ||
c5aa993b JM |
889 | enum infwait_states |
890 | { | |
cd0fc7c3 SS |
891 | infwait_normal_state, |
892 | infwait_thread_hop_state, | |
893 | infwait_nullified_state, | |
894 | infwait_nonstep_watch_state | |
b83266a0 SS |
895 | }; |
896 | ||
11cf8741 JM |
897 | /* Why did the inferior stop? Used to print the appropriate messages |
898 | to the interface from within handle_inferior_event(). */ | |
899 | enum inferior_stop_reason | |
900 | { | |
901 | /* We don't know why. */ | |
902 | STOP_UNKNOWN, | |
903 | /* Step, next, nexti, stepi finished. */ | |
904 | END_STEPPING_RANGE, | |
905 | /* Found breakpoint. */ | |
906 | BREAKPOINT_HIT, | |
907 | /* Inferior terminated by signal. */ | |
908 | SIGNAL_EXITED, | |
909 | /* Inferior exited. */ | |
910 | EXITED, | |
911 | /* Inferior received signal, and user asked to be notified. */ | |
912 | SIGNAL_RECEIVED | |
913 | }; | |
914 | ||
cd0fc7c3 SS |
915 | /* This structure contains what used to be local variables in |
916 | wait_for_inferior. Probably many of them can return to being | |
917 | locals in handle_inferior_event. */ | |
918 | ||
c5aa993b | 919 | struct execution_control_state |
488f131b JB |
920 | { |
921 | struct target_waitstatus ws; | |
922 | struct target_waitstatus *wp; | |
923 | int another_trap; | |
924 | int random_signal; | |
925 | CORE_ADDR stop_func_start; | |
926 | CORE_ADDR stop_func_end; | |
927 | char *stop_func_name; | |
928 | struct symtab_and_line sal; | |
929 | int remove_breakpoints_on_following_step; | |
930 | int current_line; | |
931 | struct symtab *current_symtab; | |
932 | int handling_longjmp; /* FIXME */ | |
933 | ptid_t ptid; | |
934 | ptid_t saved_inferior_ptid; | |
935 | int update_step_sp; | |
936 | int stepping_through_solib_after_catch; | |
937 | bpstat stepping_through_solib_catchpoints; | |
938 | int enable_hw_watchpoints_after_wait; | |
939 | int stepping_through_sigtramp; | |
940 | int new_thread_event; | |
941 | struct target_waitstatus tmpstatus; | |
942 | enum infwait_states infwait_state; | |
943 | ptid_t waiton_ptid; | |
944 | int wait_some_more; | |
945 | }; | |
946 | ||
947 | void init_execution_control_state (struct execution_control_state *ecs); | |
948 | ||
949 | void handle_inferior_event (struct execution_control_state *ecs); | |
cd0fc7c3 | 950 | |
104c1213 | 951 | static void check_sigtramp2 (struct execution_control_state *ecs); |
c2c6d25f | 952 | static void step_into_function (struct execution_control_state *ecs); |
d4f3574e | 953 | static void step_over_function (struct execution_control_state *ecs); |
104c1213 JM |
954 | static void stop_stepping (struct execution_control_state *ecs); |
955 | static void prepare_to_wait (struct execution_control_state *ecs); | |
d4f3574e | 956 | static void keep_going (struct execution_control_state *ecs); |
488f131b JB |
957 | static void print_stop_reason (enum inferior_stop_reason stop_reason, |
958 | int stop_info); | |
104c1213 | 959 | |
cd0fc7c3 SS |
960 | /* Wait for control to return from inferior to debugger. |
961 | If inferior gets a signal, we may decide to start it up again | |
962 | instead of returning. That is why there is a loop in this function. | |
963 | When this function actually returns it means the inferior | |
964 | should be left stopped and GDB should read more commands. */ | |
965 | ||
966 | void | |
96baa820 | 967 | wait_for_inferior (void) |
cd0fc7c3 SS |
968 | { |
969 | struct cleanup *old_cleanups; | |
970 | struct execution_control_state ecss; | |
971 | struct execution_control_state *ecs; | |
c906108c | 972 | |
8601f500 | 973 | old_cleanups = make_cleanup (delete_step_resume_breakpoint, |
c906108c SS |
974 | &step_resume_breakpoint); |
975 | make_cleanup (delete_breakpoint_current_contents, | |
976 | &through_sigtramp_breakpoint); | |
cd0fc7c3 SS |
977 | |
978 | /* wfi still stays in a loop, so it's OK just to take the address of | |
979 | a local to get the ecs pointer. */ | |
980 | ecs = &ecss; | |
981 | ||
982 | /* Fill in with reasonable starting values. */ | |
983 | init_execution_control_state (ecs); | |
984 | ||
c906108c | 985 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 986 | previous_inferior_ptid = inferior_ptid; |
c906108c | 987 | |
cd0fc7c3 SS |
988 | overlay_cache_invalid = 1; |
989 | ||
990 | /* We have to invalidate the registers BEFORE calling target_wait | |
991 | because they can be loaded from the target while in target_wait. | |
992 | This makes remote debugging a bit more efficient for those | |
993 | targets that provide critical registers as part of their normal | |
994 | status mechanism. */ | |
995 | ||
996 | registers_changed (); | |
b83266a0 | 997 | |
c906108c SS |
998 | while (1) |
999 | { | |
cd0fc7c3 | 1000 | if (target_wait_hook) |
39f77062 | 1001 | ecs->ptid = target_wait_hook (ecs->waiton_ptid, ecs->wp); |
cd0fc7c3 | 1002 | else |
39f77062 | 1003 | ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp); |
c906108c | 1004 | |
cd0fc7c3 SS |
1005 | /* Now figure out what to do with the result of the result. */ |
1006 | handle_inferior_event (ecs); | |
c906108c | 1007 | |
cd0fc7c3 SS |
1008 | if (!ecs->wait_some_more) |
1009 | break; | |
1010 | } | |
1011 | do_cleanups (old_cleanups); | |
1012 | } | |
c906108c | 1013 | |
43ff13b4 JM |
1014 | /* Asynchronous version of wait_for_inferior. It is called by the |
1015 | event loop whenever a change of state is detected on the file | |
1016 | descriptor corresponding to the target. It can be called more than | |
1017 | once to complete a single execution command. In such cases we need | |
1018 | to keep the state in a global variable ASYNC_ECSS. If it is the | |
1019 | last time that this function is called for a single execution | |
1020 | command, then report to the user that the inferior has stopped, and | |
1021 | do the necessary cleanups. */ | |
1022 | ||
1023 | struct execution_control_state async_ecss; | |
1024 | struct execution_control_state *async_ecs; | |
1025 | ||
1026 | void | |
fba45db2 | 1027 | fetch_inferior_event (void *client_data) |
43ff13b4 JM |
1028 | { |
1029 | static struct cleanup *old_cleanups; | |
1030 | ||
c5aa993b | 1031 | async_ecs = &async_ecss; |
43ff13b4 JM |
1032 | |
1033 | if (!async_ecs->wait_some_more) | |
1034 | { | |
488f131b | 1035 | old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint, |
c5aa993b | 1036 | &step_resume_breakpoint); |
43ff13b4 | 1037 | make_exec_cleanup (delete_breakpoint_current_contents, |
c5aa993b | 1038 | &through_sigtramp_breakpoint); |
43ff13b4 JM |
1039 | |
1040 | /* Fill in with reasonable starting values. */ | |
1041 | init_execution_control_state (async_ecs); | |
1042 | ||
43ff13b4 | 1043 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 1044 | previous_inferior_ptid = inferior_ptid; |
43ff13b4 JM |
1045 | |
1046 | overlay_cache_invalid = 1; | |
1047 | ||
1048 | /* We have to invalidate the registers BEFORE calling target_wait | |
c5aa993b JM |
1049 | because they can be loaded from the target while in target_wait. |
1050 | This makes remote debugging a bit more efficient for those | |
1051 | targets that provide critical registers as part of their normal | |
1052 | status mechanism. */ | |
43ff13b4 JM |
1053 | |
1054 | registers_changed (); | |
1055 | } | |
1056 | ||
1057 | if (target_wait_hook) | |
488f131b JB |
1058 | async_ecs->ptid = |
1059 | target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp); | |
43ff13b4 | 1060 | else |
39f77062 | 1061 | async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp); |
43ff13b4 JM |
1062 | |
1063 | /* Now figure out what to do with the result of the result. */ | |
1064 | handle_inferior_event (async_ecs); | |
1065 | ||
1066 | if (!async_ecs->wait_some_more) | |
1067 | { | |
adf40b2e | 1068 | /* Do only the cleanups that have been added by this |
488f131b JB |
1069 | function. Let the continuations for the commands do the rest, |
1070 | if there are any. */ | |
43ff13b4 JM |
1071 | do_exec_cleanups (old_cleanups); |
1072 | normal_stop (); | |
c2d11a7d JM |
1073 | if (step_multi && stop_step) |
1074 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); | |
1075 | else | |
1076 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
43ff13b4 JM |
1077 | } |
1078 | } | |
1079 | ||
cd0fc7c3 SS |
1080 | /* Prepare an execution control state for looping through a |
1081 | wait_for_inferior-type loop. */ | |
1082 | ||
1083 | void | |
96baa820 | 1084 | init_execution_control_state (struct execution_control_state *ecs) |
cd0fc7c3 | 1085 | { |
c2d11a7d | 1086 | /* ecs->another_trap? */ |
cd0fc7c3 SS |
1087 | ecs->random_signal = 0; |
1088 | ecs->remove_breakpoints_on_following_step = 0; | |
1089 | ecs->handling_longjmp = 0; /* FIXME */ | |
1090 | ecs->update_step_sp = 0; | |
1091 | ecs->stepping_through_solib_after_catch = 0; | |
1092 | ecs->stepping_through_solib_catchpoints = NULL; | |
1093 | ecs->enable_hw_watchpoints_after_wait = 0; | |
1094 | ecs->stepping_through_sigtramp = 0; | |
1095 | ecs->sal = find_pc_line (prev_pc, 0); | |
1096 | ecs->current_line = ecs->sal.line; | |
1097 | ecs->current_symtab = ecs->sal.symtab; | |
1098 | ecs->infwait_state = infwait_normal_state; | |
39f77062 | 1099 | ecs->waiton_ptid = pid_to_ptid (-1); |
cd0fc7c3 SS |
1100 | ecs->wp = &(ecs->ws); |
1101 | } | |
1102 | ||
a0b3c4fd | 1103 | /* Call this function before setting step_resume_breakpoint, as a |
53a5351d JM |
1104 | sanity check. There should never be more than one step-resume |
1105 | breakpoint per thread, so we should never be setting a new | |
1106 | step_resume_breakpoint when one is already active. */ | |
a0b3c4fd | 1107 | static void |
96baa820 | 1108 | check_for_old_step_resume_breakpoint (void) |
a0b3c4fd JM |
1109 | { |
1110 | if (step_resume_breakpoint) | |
488f131b JB |
1111 | warning |
1112 | ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint"); | |
a0b3c4fd JM |
1113 | } |
1114 | ||
e02bc4cc DS |
1115 | /* Return the cached copy of the last pid/waitstatus returned by |
1116 | target_wait()/target_wait_hook(). The data is actually cached by | |
1117 | handle_inferior_event(), which gets called immediately after | |
1118 | target_wait()/target_wait_hook(). */ | |
1119 | ||
1120 | void | |
488f131b | 1121 | get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) |
e02bc4cc | 1122 | { |
39f77062 | 1123 | *ptidp = target_last_wait_ptid; |
e02bc4cc DS |
1124 | *status = target_last_waitstatus; |
1125 | } | |
1126 | ||
dd80620e MS |
1127 | /* Switch thread contexts, maintaining "infrun state". */ |
1128 | ||
1129 | static void | |
1130 | context_switch (struct execution_control_state *ecs) | |
1131 | { | |
1132 | /* Caution: it may happen that the new thread (or the old one!) | |
1133 | is not in the thread list. In this case we must not attempt | |
1134 | to "switch context", or we run the risk that our context may | |
1135 | be lost. This may happen as a result of the target module | |
1136 | mishandling thread creation. */ | |
1137 | ||
1138 | if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid)) | |
488f131b | 1139 | { /* Perform infrun state context switch: */ |
dd80620e | 1140 | /* Save infrun state for the old thread. */ |
0ce3d317 | 1141 | save_infrun_state (inferior_ptid, prev_pc, |
dd80620e | 1142 | trap_expected, step_resume_breakpoint, |
488f131b | 1143 | through_sigtramp_breakpoint, step_range_start, |
aa0cd9c1 | 1144 | step_range_end, &step_frame_id, |
dd80620e MS |
1145 | ecs->handling_longjmp, ecs->another_trap, |
1146 | ecs->stepping_through_solib_after_catch, | |
1147 | ecs->stepping_through_solib_catchpoints, | |
1148 | ecs->stepping_through_sigtramp, | |
488f131b | 1149 | ecs->current_line, ecs->current_symtab, step_sp); |
dd80620e MS |
1150 | |
1151 | /* Load infrun state for the new thread. */ | |
0ce3d317 | 1152 | load_infrun_state (ecs->ptid, &prev_pc, |
dd80620e | 1153 | &trap_expected, &step_resume_breakpoint, |
488f131b | 1154 | &through_sigtramp_breakpoint, &step_range_start, |
aa0cd9c1 | 1155 | &step_range_end, &step_frame_id, |
dd80620e MS |
1156 | &ecs->handling_longjmp, &ecs->another_trap, |
1157 | &ecs->stepping_through_solib_after_catch, | |
1158 | &ecs->stepping_through_solib_catchpoints, | |
488f131b JB |
1159 | &ecs->stepping_through_sigtramp, |
1160 | &ecs->current_line, &ecs->current_symtab, &step_sp); | |
dd80620e MS |
1161 | } |
1162 | inferior_ptid = ecs->ptid; | |
1163 | } | |
1164 | ||
0ce3d317 AC |
1165 | /* Wrapper for PC_IN_SIGTRAMP that takes care of the need to find the |
1166 | function's name. | |
1167 | ||
1168 | In a classic example of "left hand VS right hand", "infrun.c" was | |
1169 | trying to improve GDB's performance by caching the result of calls | |
1170 | to calls to find_pc_partial_funtion, while at the same time | |
1171 | find_pc_partial_function was also trying to ramp up performance by | |
1172 | caching its most recent return value. The below makes the the | |
1173 | function find_pc_partial_function solely responsibile for | |
1174 | performance issues (the local cache that relied on a global | |
1175 | variable - arrrggg - deleted). | |
1176 | ||
1177 | Using the testsuite and gcov, it was found that dropping the local | |
1178 | "infrun.c" cache and instead relying on find_pc_partial_function | |
1179 | increased the number of calls to 12000 (from 10000), but the number | |
1180 | of times find_pc_partial_function's cache missed (this is what | |
1181 | matters) was only increased by only 4 (to 3569). (A quick back of | |
1182 | envelope caculation suggests that the extra 2000 function calls | |
1183 | @1000 extra instructions per call make the 1 MIP VAX testsuite run | |
1184 | take two extra seconds, oops :-) | |
1185 | ||
1186 | Long term, this function can be eliminated, replaced by the code: | |
1187 | get_frame_type(current_frame()) == SIGTRAMP_FRAME (for new | |
1188 | architectures this is very cheap). */ | |
1189 | ||
1190 | static int | |
1191 | pc_in_sigtramp (CORE_ADDR pc) | |
1192 | { | |
1193 | char *name; | |
1194 | find_pc_partial_function (pc, &name, NULL, NULL); | |
1195 | return PC_IN_SIGTRAMP (pc, name); | |
1196 | } | |
1197 | ||
dd80620e | 1198 | |
cd0fc7c3 SS |
1199 | /* Given an execution control state that has been freshly filled in |
1200 | by an event from the inferior, figure out what it means and take | |
1201 | appropriate action. */ | |
c906108c | 1202 | |
cd0fc7c3 | 1203 | void |
96baa820 | 1204 | handle_inferior_event (struct execution_control_state *ecs) |
cd0fc7c3 | 1205 | { |
d764a824 | 1206 | CORE_ADDR real_stop_pc; |
65e82032 AC |
1207 | /* NOTE: cagney/2003-03-28: If you're looking at this code and |
1208 | thinking that the variable stepped_after_stopped_by_watchpoint | |
1209 | isn't used, then you're wrong! The macro STOPPED_BY_WATCHPOINT, | |
1210 | defined in the file "config/pa/nm-hppah.h", accesses the variable | |
1211 | indirectly. Mutter something rude about the HP merge. */ | |
cd0fc7c3 | 1212 | int stepped_after_stopped_by_watchpoint; |
c8edd8b4 | 1213 | int sw_single_step_trap_p = 0; |
cd0fc7c3 | 1214 | |
e02bc4cc | 1215 | /* Cache the last pid/waitstatus. */ |
39f77062 | 1216 | target_last_wait_ptid = ecs->ptid; |
e02bc4cc DS |
1217 | target_last_waitstatus = *ecs->wp; |
1218 | ||
488f131b JB |
1219 | switch (ecs->infwait_state) |
1220 | { | |
1221 | case infwait_thread_hop_state: | |
1222 | /* Cancel the waiton_ptid. */ | |
1223 | ecs->waiton_ptid = pid_to_ptid (-1); | |
65e82032 AC |
1224 | /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event |
1225 | is serviced in this loop, below. */ | |
1226 | if (ecs->enable_hw_watchpoints_after_wait) | |
1227 | { | |
1228 | TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); | |
1229 | ecs->enable_hw_watchpoints_after_wait = 0; | |
1230 | } | |
1231 | stepped_after_stopped_by_watchpoint = 0; | |
1232 | break; | |
b83266a0 | 1233 | |
488f131b JB |
1234 | case infwait_normal_state: |
1235 | /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event | |
1236 | is serviced in this loop, below. */ | |
1237 | if (ecs->enable_hw_watchpoints_after_wait) | |
1238 | { | |
1239 | TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); | |
1240 | ecs->enable_hw_watchpoints_after_wait = 0; | |
1241 | } | |
1242 | stepped_after_stopped_by_watchpoint = 0; | |
1243 | break; | |
b83266a0 | 1244 | |
488f131b | 1245 | case infwait_nullified_state: |
65e82032 | 1246 | stepped_after_stopped_by_watchpoint = 0; |
488f131b | 1247 | break; |
b83266a0 | 1248 | |
488f131b JB |
1249 | case infwait_nonstep_watch_state: |
1250 | insert_breakpoints (); | |
c906108c | 1251 | |
488f131b JB |
1252 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
1253 | handle things like signals arriving and other things happening | |
1254 | in combination correctly? */ | |
1255 | stepped_after_stopped_by_watchpoint = 1; | |
1256 | break; | |
65e82032 AC |
1257 | |
1258 | default: | |
1259 | internal_error (__FILE__, __LINE__, "bad switch"); | |
488f131b JB |
1260 | } |
1261 | ecs->infwait_state = infwait_normal_state; | |
c906108c | 1262 | |
488f131b | 1263 | flush_cached_frames (); |
c906108c | 1264 | |
488f131b | 1265 | /* If it's a new process, add it to the thread database */ |
c906108c | 1266 | |
488f131b JB |
1267 | ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) |
1268 | && !in_thread_list (ecs->ptid)); | |
1269 | ||
1270 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED | |
1271 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) | |
1272 | { | |
1273 | add_thread (ecs->ptid); | |
c906108c | 1274 | |
488f131b JB |
1275 | ui_out_text (uiout, "[New "); |
1276 | ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid)); | |
1277 | ui_out_text (uiout, "]\n"); | |
c906108c SS |
1278 | |
1279 | #if 0 | |
488f131b JB |
1280 | /* NOTE: This block is ONLY meant to be invoked in case of a |
1281 | "thread creation event"! If it is invoked for any other | |
1282 | sort of event (such as a new thread landing on a breakpoint), | |
1283 | the event will be discarded, which is almost certainly | |
1284 | a bad thing! | |
1285 | ||
1286 | To avoid this, the low-level module (eg. target_wait) | |
1287 | should call in_thread_list and add_thread, so that the | |
1288 | new thread is known by the time we get here. */ | |
1289 | ||
1290 | /* We may want to consider not doing a resume here in order | |
1291 | to give the user a chance to play with the new thread. | |
1292 | It might be good to make that a user-settable option. */ | |
1293 | ||
1294 | /* At this point, all threads are stopped (happens | |
1295 | automatically in either the OS or the native code). | |
1296 | Therefore we need to continue all threads in order to | |
1297 | make progress. */ | |
1298 | ||
1299 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); | |
1300 | prepare_to_wait (ecs); | |
1301 | return; | |
c906108c | 1302 | #endif |
488f131b | 1303 | } |
c906108c | 1304 | |
488f131b JB |
1305 | switch (ecs->ws.kind) |
1306 | { | |
1307 | case TARGET_WAITKIND_LOADED: | |
1308 | /* Ignore gracefully during startup of the inferior, as it | |
1309 | might be the shell which has just loaded some objects, | |
1310 | otherwise add the symbols for the newly loaded objects. */ | |
c906108c | 1311 | #ifdef SOLIB_ADD |
c0236d92 | 1312 | if (stop_soon == NO_STOP_QUIETLY) |
488f131b JB |
1313 | { |
1314 | /* Remove breakpoints, SOLIB_ADD might adjust | |
1315 | breakpoint addresses via breakpoint_re_set. */ | |
1316 | if (breakpoints_inserted) | |
1317 | remove_breakpoints (); | |
c906108c | 1318 | |
488f131b JB |
1319 | /* Check for any newly added shared libraries if we're |
1320 | supposed to be adding them automatically. Switch | |
1321 | terminal for any messages produced by | |
1322 | breakpoint_re_set. */ | |
1323 | target_terminal_ours_for_output (); | |
1324 | SOLIB_ADD (NULL, 0, NULL, auto_solib_add); | |
1325 | target_terminal_inferior (); | |
1326 | ||
1327 | /* Reinsert breakpoints and continue. */ | |
1328 | if (breakpoints_inserted) | |
1329 | insert_breakpoints (); | |
1330 | } | |
c906108c | 1331 | #endif |
488f131b JB |
1332 | resume (0, TARGET_SIGNAL_0); |
1333 | prepare_to_wait (ecs); | |
1334 | return; | |
c5aa993b | 1335 | |
488f131b JB |
1336 | case TARGET_WAITKIND_SPURIOUS: |
1337 | resume (0, TARGET_SIGNAL_0); | |
1338 | prepare_to_wait (ecs); | |
1339 | return; | |
c5aa993b | 1340 | |
488f131b JB |
1341 | case TARGET_WAITKIND_EXITED: |
1342 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
1343 | print_stop_reason (EXITED, ecs->ws.value.integer); | |
1344 | ||
1345 | /* Record the exit code in the convenience variable $_exitcode, so | |
1346 | that the user can inspect this again later. */ | |
1347 | set_internalvar (lookup_internalvar ("_exitcode"), | |
1348 | value_from_longest (builtin_type_int, | |
1349 | (LONGEST) ecs->ws.value.integer)); | |
1350 | gdb_flush (gdb_stdout); | |
1351 | target_mourn_inferior (); | |
1352 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ | |
1353 | stop_print_frame = 0; | |
1354 | stop_stepping (ecs); | |
1355 | return; | |
c5aa993b | 1356 | |
488f131b JB |
1357 | case TARGET_WAITKIND_SIGNALLED: |
1358 | stop_print_frame = 0; | |
1359 | stop_signal = ecs->ws.value.sig; | |
1360 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
c5aa993b | 1361 | |
488f131b JB |
1362 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
1363 | reach here unless the inferior is dead. However, for years | |
1364 | target_kill() was called here, which hints that fatal signals aren't | |
1365 | really fatal on some systems. If that's true, then some changes | |
1366 | may be needed. */ | |
1367 | target_mourn_inferior (); | |
c906108c | 1368 | |
488f131b JB |
1369 | print_stop_reason (SIGNAL_EXITED, stop_signal); |
1370 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ | |
1371 | stop_stepping (ecs); | |
1372 | return; | |
c906108c | 1373 | |
488f131b JB |
1374 | /* The following are the only cases in which we keep going; |
1375 | the above cases end in a continue or goto. */ | |
1376 | case TARGET_WAITKIND_FORKED: | |
deb3b17b | 1377 | case TARGET_WAITKIND_VFORKED: |
488f131b JB |
1378 | stop_signal = TARGET_SIGNAL_TRAP; |
1379 | pending_follow.kind = ecs->ws.kind; | |
1380 | ||
8e7d2c16 DJ |
1381 | pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); |
1382 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; | |
c906108c | 1383 | |
488f131b | 1384 | stop_pc = read_pc (); |
675bf4cb DJ |
1385 | |
1386 | /* Assume that catchpoints are not really software breakpoints. If | |
1387 | some future target implements them using software breakpoints then | |
1388 | that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus | |
1389 | we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that | |
1390 | bpstat_stop_status will not decrement the PC. */ | |
1391 | ||
1392 | stop_bpstat = bpstat_stop_status (&stop_pc, 1); | |
1393 | ||
488f131b | 1394 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
04e68871 DJ |
1395 | |
1396 | /* If no catchpoint triggered for this, then keep going. */ | |
1397 | if (ecs->random_signal) | |
1398 | { | |
1399 | stop_signal = TARGET_SIGNAL_0; | |
1400 | keep_going (ecs); | |
1401 | return; | |
1402 | } | |
488f131b JB |
1403 | goto process_event_stop_test; |
1404 | ||
1405 | case TARGET_WAITKIND_EXECD: | |
1406 | stop_signal = TARGET_SIGNAL_TRAP; | |
1407 | ||
7d2830a3 DJ |
1408 | /* NOTE drow/2002-12-05: This code should be pushed down into the |
1409 | target_wait function. Until then following vfork on HP/UX 10.20 | |
1410 | is probably broken by this. Of course, it's broken anyway. */ | |
488f131b JB |
1411 | /* Is this a target which reports multiple exec events per actual |
1412 | call to exec()? (HP-UX using ptrace does, for example.) If so, | |
1413 | ignore all but the last one. Just resume the exec'r, and wait | |
1414 | for the next exec event. */ | |
1415 | if (inferior_ignoring_leading_exec_events) | |
1416 | { | |
1417 | inferior_ignoring_leading_exec_events--; | |
1418 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
1419 | ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event. | |
1420 | parent_pid); | |
1421 | target_resume (ecs->ptid, 0, TARGET_SIGNAL_0); | |
1422 | prepare_to_wait (ecs); | |
1423 | return; | |
1424 | } | |
1425 | inferior_ignoring_leading_exec_events = | |
1426 | target_reported_exec_events_per_exec_call () - 1; | |
1427 | ||
1428 | pending_follow.execd_pathname = | |
1429 | savestring (ecs->ws.value.execd_pathname, | |
1430 | strlen (ecs->ws.value.execd_pathname)); | |
1431 | ||
488f131b JB |
1432 | /* This causes the eventpoints and symbol table to be reset. Must |
1433 | do this now, before trying to determine whether to stop. */ | |
1434 | follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); | |
1435 | xfree (pending_follow.execd_pathname); | |
c906108c | 1436 | |
488f131b JB |
1437 | stop_pc = read_pc_pid (ecs->ptid); |
1438 | ecs->saved_inferior_ptid = inferior_ptid; | |
1439 | inferior_ptid = ecs->ptid; | |
675bf4cb DJ |
1440 | |
1441 | /* Assume that catchpoints are not really software breakpoints. If | |
1442 | some future target implements them using software breakpoints then | |
1443 | that target is responsible for fudging DECR_PC_AFTER_BREAK. Thus | |
1444 | we pass 1 for the NOT_A_SW_BREAKPOINT argument, so that | |
1445 | bpstat_stop_status will not decrement the PC. */ | |
1446 | ||
1447 | stop_bpstat = bpstat_stop_status (&stop_pc, 1); | |
1448 | ||
488f131b JB |
1449 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
1450 | inferior_ptid = ecs->saved_inferior_ptid; | |
04e68871 DJ |
1451 | |
1452 | /* If no catchpoint triggered for this, then keep going. */ | |
1453 | if (ecs->random_signal) | |
1454 | { | |
1455 | stop_signal = TARGET_SIGNAL_0; | |
1456 | keep_going (ecs); | |
1457 | return; | |
1458 | } | |
488f131b JB |
1459 | goto process_event_stop_test; |
1460 | ||
1461 | /* These syscall events are returned on HP-UX, as part of its | |
1462 | implementation of page-protection-based "hardware" watchpoints. | |
1463 | HP-UX has unfortunate interactions between page-protections and | |
1464 | some system calls. Our solution is to disable hardware watches | |
1465 | when a system call is entered, and reenable them when the syscall | |
1466 | completes. The downside of this is that we may miss the precise | |
1467 | point at which a watched piece of memory is modified. "Oh well." | |
1468 | ||
1469 | Note that we may have multiple threads running, which may each | |
1470 | enter syscalls at roughly the same time. Since we don't have a | |
1471 | good notion currently of whether a watched piece of memory is | |
1472 | thread-private, we'd best not have any page-protections active | |
1473 | when any thread is in a syscall. Thus, we only want to reenable | |
1474 | hardware watches when no threads are in a syscall. | |
1475 | ||
1476 | Also, be careful not to try to gather much state about a thread | |
1477 | that's in a syscall. It's frequently a losing proposition. */ | |
1478 | case TARGET_WAITKIND_SYSCALL_ENTRY: | |
1479 | number_of_threads_in_syscalls++; | |
1480 | if (number_of_threads_in_syscalls == 1) | |
1481 | { | |
1482 | TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); | |
1483 | } | |
1484 | resume (0, TARGET_SIGNAL_0); | |
1485 | prepare_to_wait (ecs); | |
1486 | return; | |
c906108c | 1487 | |
488f131b JB |
1488 | /* Before examining the threads further, step this thread to |
1489 | get it entirely out of the syscall. (We get notice of the | |
1490 | event when the thread is just on the verge of exiting a | |
1491 | syscall. Stepping one instruction seems to get it back | |
1492 | into user code.) | |
c906108c | 1493 | |
488f131b JB |
1494 | Note that although the logical place to reenable h/w watches |
1495 | is here, we cannot. We cannot reenable them before stepping | |
1496 | the thread (this causes the next wait on the thread to hang). | |
c4093a6a | 1497 | |
488f131b JB |
1498 | Nor can we enable them after stepping until we've done a wait. |
1499 | Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait | |
1500 | here, which will be serviced immediately after the target | |
1501 | is waited on. */ | |
1502 | case TARGET_WAITKIND_SYSCALL_RETURN: | |
1503 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); | |
1504 | ||
1505 | if (number_of_threads_in_syscalls > 0) | |
1506 | { | |
1507 | number_of_threads_in_syscalls--; | |
1508 | ecs->enable_hw_watchpoints_after_wait = | |
1509 | (number_of_threads_in_syscalls == 0); | |
1510 | } | |
1511 | prepare_to_wait (ecs); | |
1512 | return; | |
c906108c | 1513 | |
488f131b JB |
1514 | case TARGET_WAITKIND_STOPPED: |
1515 | stop_signal = ecs->ws.value.sig; | |
1516 | break; | |
c906108c | 1517 | |
488f131b JB |
1518 | /* We had an event in the inferior, but we are not interested |
1519 | in handling it at this level. The lower layers have already | |
8e7d2c16 DJ |
1520 | done what needs to be done, if anything. |
1521 | ||
1522 | One of the possible circumstances for this is when the | |
1523 | inferior produces output for the console. The inferior has | |
1524 | not stopped, and we are ignoring the event. Another possible | |
1525 | circumstance is any event which the lower level knows will be | |
1526 | reported multiple times without an intervening resume. */ | |
488f131b | 1527 | case TARGET_WAITKIND_IGNORE: |
8e7d2c16 | 1528 | prepare_to_wait (ecs); |
488f131b JB |
1529 | return; |
1530 | } | |
c906108c | 1531 | |
488f131b JB |
1532 | /* We may want to consider not doing a resume here in order to give |
1533 | the user a chance to play with the new thread. It might be good | |
1534 | to make that a user-settable option. */ | |
c906108c | 1535 | |
488f131b JB |
1536 | /* At this point, all threads are stopped (happens automatically in |
1537 | either the OS or the native code). Therefore we need to continue | |
1538 | all threads in order to make progress. */ | |
1539 | if (ecs->new_thread_event) | |
1540 | { | |
1541 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); | |
1542 | prepare_to_wait (ecs); | |
1543 | return; | |
1544 | } | |
c906108c | 1545 | |
488f131b JB |
1546 | stop_pc = read_pc_pid (ecs->ptid); |
1547 | ||
1548 | /* See if a thread hit a thread-specific breakpoint that was meant for | |
1549 | another thread. If so, then step that thread past the breakpoint, | |
1550 | and continue it. */ | |
1551 | ||
1552 | if (stop_signal == TARGET_SIGNAL_TRAP) | |
1553 | { | |
f8d40ec8 JB |
1554 | /* Check if a regular breakpoint has been hit before checking |
1555 | for a potential single step breakpoint. Otherwise, GDB will | |
1556 | not see this breakpoint hit when stepping onto breakpoints. */ | |
1557 | if (breakpoints_inserted | |
1558 | && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK)) | |
488f131b | 1559 | { |
c5aa993b | 1560 | ecs->random_signal = 0; |
488f131b JB |
1561 | if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, |
1562 | ecs->ptid)) | |
1563 | { | |
1564 | int remove_status; | |
1565 | ||
1566 | /* Saw a breakpoint, but it was hit by the wrong thread. | |
1567 | Just continue. */ | |
1568 | if (DECR_PC_AFTER_BREAK) | |
1569 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->ptid); | |
1570 | ||
1571 | remove_status = remove_breakpoints (); | |
1572 | /* Did we fail to remove breakpoints? If so, try | |
1573 | to set the PC past the bp. (There's at least | |
1574 | one situation in which we can fail to remove | |
1575 | the bp's: On HP-UX's that use ttrace, we can't | |
1576 | change the address space of a vforking child | |
1577 | process until the child exits (well, okay, not | |
1578 | then either :-) or execs. */ | |
1579 | if (remove_status != 0) | |
1580 | { | |
1581 | /* FIXME! This is obviously non-portable! */ | |
1582 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->ptid); | |
1583 | /* We need to restart all the threads now, | |
1584 | * unles we're running in scheduler-locked mode. | |
1585 | * Use currently_stepping to determine whether to | |
1586 | * step or continue. | |
1587 | */ | |
1588 | /* FIXME MVS: is there any reason not to call resume()? */ | |
1589 | if (scheduler_mode == schedlock_on) | |
1590 | target_resume (ecs->ptid, | |
1591 | currently_stepping (ecs), TARGET_SIGNAL_0); | |
1592 | else | |
1593 | target_resume (RESUME_ALL, | |
1594 | currently_stepping (ecs), TARGET_SIGNAL_0); | |
1595 | prepare_to_wait (ecs); | |
1596 | return; | |
1597 | } | |
1598 | else | |
1599 | { /* Single step */ | |
1600 | breakpoints_inserted = 0; | |
1601 | if (!ptid_equal (inferior_ptid, ecs->ptid)) | |
1602 | context_switch (ecs); | |
1603 | ecs->waiton_ptid = ecs->ptid; | |
1604 | ecs->wp = &(ecs->ws); | |
1605 | ecs->another_trap = 1; | |
1606 | ||
1607 | ecs->infwait_state = infwait_thread_hop_state; | |
1608 | keep_going (ecs); | |
1609 | registers_changed (); | |
1610 | return; | |
1611 | } | |
1612 | } | |
1613 | } | |
f8d40ec8 JB |
1614 | else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) |
1615 | { | |
c8edd8b4 JB |
1616 | /* Readjust the stop_pc as it is off by DECR_PC_AFTER_BREAK |
1617 | compared to the value it would have if the system stepping | |
1618 | capability was used. This allows the rest of the code in | |
1619 | this function to use this address without having to worry | |
1620 | whether software single step is in use or not. */ | |
1621 | if (DECR_PC_AFTER_BREAK) | |
1622 | { | |
1623 | stop_pc -= DECR_PC_AFTER_BREAK; | |
1624 | write_pc_pid (stop_pc, ecs->ptid); | |
1625 | } | |
1626 | ||
1627 | sw_single_step_trap_p = 1; | |
f8d40ec8 JB |
1628 | ecs->random_signal = 0; |
1629 | } | |
488f131b JB |
1630 | } |
1631 | else | |
1632 | ecs->random_signal = 1; | |
c906108c | 1633 | |
488f131b JB |
1634 | /* See if something interesting happened to the non-current thread. If |
1635 | so, then switch to that thread, and eventually give control back to | |
1636 | the user. | |
1637 | ||
1638 | Note that if there's any kind of pending follow (i.e., of a fork, | |
1639 | vfork or exec), we don't want to do this now. Rather, we'll let | |
1640 | the next resume handle it. */ | |
1641 | if (!ptid_equal (ecs->ptid, inferior_ptid) && | |
1642 | (pending_follow.kind == TARGET_WAITKIND_SPURIOUS)) | |
1643 | { | |
1644 | int printed = 0; | |
1645 | ||
1646 | /* If it's a random signal for a non-current thread, notify user | |
1647 | if he's expressed an interest. */ | |
1648 | if (ecs->random_signal && signal_print[stop_signal]) | |
1649 | { | |
c906108c SS |
1650 | /* ??rehrauer: I don't understand the rationale for this code. If the |
1651 | inferior will stop as a result of this signal, then the act of handling | |
1652 | the stop ought to print a message that's couches the stoppage in user | |
1653 | terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior | |
1654 | won't stop as a result of the signal -- i.e., if the signal is merely | |
1655 | a side-effect of something GDB's doing "under the covers" for the | |
1656 | user, such as stepping threads over a breakpoint they shouldn't stop | |
1657 | for -- then the message seems to be a serious annoyance at best. | |
1658 | ||
1659 | For now, remove the message altogether. */ | |
1660 | #if 0 | |
488f131b JB |
1661 | printed = 1; |
1662 | target_terminal_ours_for_output (); | |
1663 | printf_filtered ("\nProgram received signal %s, %s.\n", | |
1664 | target_signal_to_name (stop_signal), | |
1665 | target_signal_to_string (stop_signal)); | |
1666 | gdb_flush (gdb_stdout); | |
c906108c | 1667 | #endif |
488f131b | 1668 | } |
c906108c | 1669 | |
488f131b JB |
1670 | /* If it's not SIGTRAP and not a signal we want to stop for, then |
1671 | continue the thread. */ | |
c906108c | 1672 | |
488f131b JB |
1673 | if (stop_signal != TARGET_SIGNAL_TRAP && !signal_stop[stop_signal]) |
1674 | { | |
1675 | if (printed) | |
1676 | target_terminal_inferior (); | |
c906108c | 1677 | |
488f131b JB |
1678 | /* Clear the signal if it should not be passed. */ |
1679 | if (signal_program[stop_signal] == 0) | |
1680 | stop_signal = TARGET_SIGNAL_0; | |
c906108c | 1681 | |
488f131b JB |
1682 | target_resume (ecs->ptid, 0, stop_signal); |
1683 | prepare_to_wait (ecs); | |
1684 | return; | |
1685 | } | |
c906108c | 1686 | |
488f131b JB |
1687 | /* It's a SIGTRAP or a signal we're interested in. Switch threads, |
1688 | and fall into the rest of wait_for_inferior(). */ | |
c5aa993b | 1689 | |
488f131b | 1690 | context_switch (ecs); |
c5aa993b | 1691 | |
488f131b JB |
1692 | if (context_hook) |
1693 | context_hook (pid_to_thread_id (ecs->ptid)); | |
c5aa993b | 1694 | |
488f131b JB |
1695 | flush_cached_frames (); |
1696 | } | |
c906108c | 1697 | |
488f131b JB |
1698 | if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) |
1699 | { | |
1700 | /* Pull the single step breakpoints out of the target. */ | |
1701 | SOFTWARE_SINGLE_STEP (0, 0); | |
1702 | singlestep_breakpoints_inserted_p = 0; | |
1703 | } | |
c906108c | 1704 | |
488f131b JB |
1705 | /* If PC is pointing at a nullified instruction, then step beyond |
1706 | it so that the user won't be confused when GDB appears to be ready | |
1707 | to execute it. */ | |
c906108c | 1708 | |
488f131b JB |
1709 | /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */ |
1710 | if (INSTRUCTION_NULLIFIED) | |
1711 | { | |
1712 | registers_changed (); | |
1713 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); | |
c906108c | 1714 | |
488f131b JB |
1715 | /* We may have received a signal that we want to pass to |
1716 | the inferior; therefore, we must not clobber the waitstatus | |
1717 | in WS. */ | |
c906108c | 1718 | |
488f131b JB |
1719 | ecs->infwait_state = infwait_nullified_state; |
1720 | ecs->waiton_ptid = ecs->ptid; | |
1721 | ecs->wp = &(ecs->tmpstatus); | |
1722 | prepare_to_wait (ecs); | |
1723 | return; | |
1724 | } | |
c906108c | 1725 | |
488f131b JB |
1726 | /* It may not be necessary to disable the watchpoint to stop over |
1727 | it. For example, the PA can (with some kernel cooperation) | |
1728 | single step over a watchpoint without disabling the watchpoint. */ | |
1729 | if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) | |
1730 | { | |
1731 | resume (1, 0); | |
1732 | prepare_to_wait (ecs); | |
1733 | return; | |
1734 | } | |
c906108c | 1735 | |
488f131b JB |
1736 | /* It is far more common to need to disable a watchpoint to step |
1737 | the inferior over it. FIXME. What else might a debug | |
1738 | register or page protection watchpoint scheme need here? */ | |
1739 | if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) | |
1740 | { | |
1741 | /* At this point, we are stopped at an instruction which has | |
1742 | attempted to write to a piece of memory under control of | |
1743 | a watchpoint. The instruction hasn't actually executed | |
1744 | yet. If we were to evaluate the watchpoint expression | |
1745 | now, we would get the old value, and therefore no change | |
1746 | would seem to have occurred. | |
1747 | ||
1748 | In order to make watchpoints work `right', we really need | |
1749 | to complete the memory write, and then evaluate the | |
1750 | watchpoint expression. The following code does that by | |
1751 | removing the watchpoint (actually, all watchpoints and | |
1752 | breakpoints), single-stepping the target, re-inserting | |
1753 | watchpoints, and then falling through to let normal | |
1754 | single-step processing handle proceed. Since this | |
1755 | includes evaluating watchpoints, things will come to a | |
1756 | stop in the correct manner. */ | |
1757 | ||
1758 | if (DECR_PC_AFTER_BREAK) | |
1759 | write_pc (stop_pc - DECR_PC_AFTER_BREAK); | |
c5aa993b | 1760 | |
488f131b JB |
1761 | remove_breakpoints (); |
1762 | registers_changed (); | |
1763 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */ | |
c5aa993b | 1764 | |
488f131b JB |
1765 | ecs->waiton_ptid = ecs->ptid; |
1766 | ecs->wp = &(ecs->ws); | |
1767 | ecs->infwait_state = infwait_nonstep_watch_state; | |
1768 | prepare_to_wait (ecs); | |
1769 | return; | |
1770 | } | |
1771 | ||
1772 | /* It may be possible to simply continue after a watchpoint. */ | |
1773 | if (HAVE_CONTINUABLE_WATCHPOINT) | |
1774 | STOPPED_BY_WATCHPOINT (ecs->ws); | |
1775 | ||
1776 | ecs->stop_func_start = 0; | |
1777 | ecs->stop_func_end = 0; | |
1778 | ecs->stop_func_name = 0; | |
1779 | /* Don't care about return value; stop_func_start and stop_func_name | |
1780 | will both be 0 if it doesn't work. */ | |
1781 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
1782 | &ecs->stop_func_start, &ecs->stop_func_end); | |
1783 | ecs->stop_func_start += FUNCTION_START_OFFSET; | |
1784 | ecs->another_trap = 0; | |
1785 | bpstat_clear (&stop_bpstat); | |
1786 | stop_step = 0; | |
1787 | stop_stack_dummy = 0; | |
1788 | stop_print_frame = 1; | |
1789 | ecs->random_signal = 0; | |
1790 | stopped_by_random_signal = 0; | |
1791 | breakpoints_failed = 0; | |
1792 | ||
1793 | /* Look at the cause of the stop, and decide what to do. | |
1794 | The alternatives are: | |
1795 | 1) break; to really stop and return to the debugger, | |
1796 | 2) drop through to start up again | |
1797 | (set ecs->another_trap to 1 to single step once) | |
1798 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 | |
1799 | will be made according to the signal handling tables. */ | |
1800 | ||
1801 | /* First, distinguish signals caused by the debugger from signals | |
1802 | that have to do with the program's own actions. | |
1803 | Note that breakpoint insns may cause SIGTRAP or SIGILL | |
1804 | or SIGEMT, depending on the operating system version. | |
1805 | Here we detect when a SIGILL or SIGEMT is really a breakpoint | |
1806 | and change it to SIGTRAP. */ | |
1807 | ||
1808 | if (stop_signal == TARGET_SIGNAL_TRAP | |
1809 | || (breakpoints_inserted && | |
1810 | (stop_signal == TARGET_SIGNAL_ILL | |
c54cfec8 | 1811 | || stop_signal == TARGET_SIGNAL_EMT)) |
c0236d92 EZ |
1812 | || stop_soon == STOP_QUIETLY |
1813 | || stop_soon == STOP_QUIETLY_NO_SIGSTOP) | |
488f131b JB |
1814 | { |
1815 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) | |
1816 | { | |
1817 | stop_print_frame = 0; | |
1818 | stop_stepping (ecs); | |
1819 | return; | |
1820 | } | |
c54cfec8 EZ |
1821 | |
1822 | /* This is originated from start_remote(), start_inferior() and | |
1823 | shared libraries hook functions. */ | |
c0236d92 | 1824 | if (stop_soon == STOP_QUIETLY) |
488f131b JB |
1825 | { |
1826 | stop_stepping (ecs); | |
1827 | return; | |
1828 | } | |
1829 | ||
c54cfec8 EZ |
1830 | /* This originates from attach_command(). We need to overwrite |
1831 | the stop_signal here, because some kernels don't ignore a | |
1832 | SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call. | |
1833 | See more comments in inferior.h. */ | |
c0236d92 | 1834 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP) |
c54cfec8 EZ |
1835 | { |
1836 | stop_stepping (ecs); | |
1837 | if (stop_signal == TARGET_SIGNAL_STOP) | |
1838 | stop_signal = TARGET_SIGNAL_0; | |
1839 | return; | |
1840 | } | |
1841 | ||
488f131b JB |
1842 | /* Don't even think about breakpoints |
1843 | if just proceeded over a breakpoint. | |
1844 | ||
1845 | However, if we are trying to proceed over a breakpoint | |
1846 | and end up in sigtramp, then through_sigtramp_breakpoint | |
1847 | will be set and we should check whether we've hit the | |
1848 | step breakpoint. */ | |
1849 | if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected | |
1850 | && through_sigtramp_breakpoint == NULL) | |
1851 | bpstat_clear (&stop_bpstat); | |
1852 | else | |
1853 | { | |
1854 | /* See if there is a breakpoint at the current PC. */ | |
1855 | ||
1856 | /* The second argument of bpstat_stop_status is meant to help | |
1857 | distinguish between a breakpoint trap and a singlestep trap. | |
1858 | This is only important on targets where DECR_PC_AFTER_BREAK | |
1859 | is non-zero. The prev_pc test is meant to distinguish between | |
1860 | singlestepping a trap instruction, and singlestepping thru a | |
3e6564e1 JB |
1861 | jump to the instruction following a trap instruction. |
1862 | ||
1863 | Therefore, pass TRUE if our reason for stopping is | |
1864 | something other than hitting a breakpoint. We do this by | |
1865 | checking that either: we detected earlier a software single | |
1866 | step trap or, 1) stepping is going on and 2) we didn't hit | |
1867 | a breakpoint in a signal handler without an intervening stop | |
1868 | in sigtramp, which is detected by a new stack pointer value | |
1869 | below any usual function calling stack adjustments. */ | |
238617f6 JB |
1870 | stop_bpstat = |
1871 | bpstat_stop_status | |
1872 | (&stop_pc, | |
c8edd8b4 JB |
1873 | sw_single_step_trap_p |
1874 | || (currently_stepping (ecs) | |
1875 | && prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
1876 | && !(step_range_end | |
1877 | && INNER_THAN (read_sp (), (step_sp - 16))))); | |
488f131b JB |
1878 | /* Following in case break condition called a |
1879 | function. */ | |
1880 | stop_print_frame = 1; | |
1881 | } | |
1882 | ||
73dd234f AC |
1883 | /* NOTE: cagney/2003-03-29: These two checks for a random signal |
1884 | at one stage in the past included checks for an inferior | |
1885 | function call's call dummy's return breakpoint. The original | |
1886 | comment, that went with the test, read: | |
1887 | ||
1888 | ``End of a stack dummy. Some systems (e.g. Sony news) give | |
1889 | another signal besides SIGTRAP, so check here as well as | |
1890 | above.'' | |
1891 | ||
1892 | If someone ever tries to get get call dummys on a | |
1893 | non-executable stack to work (where the target would stop | |
1894 | with something like a SIGSEG), then those tests might need to | |
1895 | be re-instated. Given, however, that the tests were only | |
1896 | enabled when momentary breakpoints were not being used, I | |
1897 | suspect that it won't be the case. */ | |
1898 | ||
488f131b JB |
1899 | if (stop_signal == TARGET_SIGNAL_TRAP) |
1900 | ecs->random_signal | |
1901 | = !(bpstat_explains_signal (stop_bpstat) | |
1902 | || trap_expected | |
488f131b | 1903 | || (step_range_end && step_resume_breakpoint == NULL)); |
488f131b JB |
1904 | else |
1905 | { | |
73dd234f | 1906 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
488f131b JB |
1907 | if (!ecs->random_signal) |
1908 | stop_signal = TARGET_SIGNAL_TRAP; | |
1909 | } | |
1910 | } | |
1911 | ||
1912 | /* When we reach this point, we've pretty much decided | |
1913 | that the reason for stopping must've been a random | |
1914 | (unexpected) signal. */ | |
1915 | ||
1916 | else | |
1917 | ecs->random_signal = 1; | |
488f131b | 1918 | |
04e68871 | 1919 | process_event_stop_test: |
488f131b JB |
1920 | /* For the program's own signals, act according to |
1921 | the signal handling tables. */ | |
1922 | ||
1923 | if (ecs->random_signal) | |
1924 | { | |
1925 | /* Signal not for debugging purposes. */ | |
1926 | int printed = 0; | |
1927 | ||
1928 | stopped_by_random_signal = 1; | |
1929 | ||
1930 | if (signal_print[stop_signal]) | |
1931 | { | |
1932 | printed = 1; | |
1933 | target_terminal_ours_for_output (); | |
1934 | print_stop_reason (SIGNAL_RECEIVED, stop_signal); | |
1935 | } | |
1936 | if (signal_stop[stop_signal]) | |
1937 | { | |
1938 | stop_stepping (ecs); | |
1939 | return; | |
1940 | } | |
1941 | /* If not going to stop, give terminal back | |
1942 | if we took it away. */ | |
1943 | else if (printed) | |
1944 | target_terminal_inferior (); | |
1945 | ||
1946 | /* Clear the signal if it should not be passed. */ | |
1947 | if (signal_program[stop_signal] == 0) | |
1948 | stop_signal = TARGET_SIGNAL_0; | |
1949 | ||
1950 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
1951 | whether it could/should be keep_going. | |
1952 | ||
1953 | This used to jump to step_over_function if we are stepping, | |
1954 | which is wrong. | |
1955 | ||
1956 | Suppose the user does a `next' over a function call, and while | |
1957 | that call is in progress, the inferior receives a signal for | |
1958 | which GDB does not stop (i.e., signal_stop[SIG] is false). In | |
1959 | that case, when we reach this point, there is already a | |
1960 | step-resume breakpoint established, right where it should be: | |
1961 | immediately after the function call the user is "next"-ing | |
1962 | over. If we call step_over_function now, two bad things | |
1963 | happen: | |
1964 | ||
1965 | - we'll create a new breakpoint, at wherever the current | |
1966 | frame's return address happens to be. That could be | |
1967 | anywhere, depending on what function call happens to be on | |
1968 | the top of the stack at that point. Point is, it's probably | |
1969 | not where we need it. | |
1970 | ||
1971 | - the existing step-resume breakpoint (which is at the correct | |
1972 | address) will get orphaned: step_resume_breakpoint will point | |
1973 | to the new breakpoint, and the old step-resume breakpoint | |
1974 | will never be cleaned up. | |
1975 | ||
1976 | The old behavior was meant to help HP-UX single-step out of | |
1977 | sigtramps. It would place the new breakpoint at prev_pc, which | |
1978 | was certainly wrong. I don't know the details there, so fixing | |
1979 | this probably breaks that. As with anything else, it's up to | |
1980 | the HP-UX maintainer to furnish a fix that doesn't break other | |
1981 | platforms. --JimB, 20 May 1999 */ | |
1982 | check_sigtramp2 (ecs); | |
1983 | keep_going (ecs); | |
1984 | return; | |
1985 | } | |
1986 | ||
1987 | /* Handle cases caused by hitting a breakpoint. */ | |
1988 | { | |
1989 | CORE_ADDR jmp_buf_pc; | |
1990 | struct bpstat_what what; | |
1991 | ||
1992 | what = bpstat_what (stop_bpstat); | |
1993 | ||
1994 | if (what.call_dummy) | |
1995 | { | |
1996 | stop_stack_dummy = 1; | |
1997 | #ifdef HP_OS_BUG | |
1998 | trap_expected_after_continue = 1; | |
1999 | #endif | |
c5aa993b | 2000 | } |
c906108c | 2001 | |
488f131b | 2002 | switch (what.main_action) |
c5aa993b | 2003 | { |
488f131b JB |
2004 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
2005 | /* If we hit the breakpoint at longjmp, disable it for the | |
2006 | duration of this command. Then, install a temporary | |
2007 | breakpoint at the target of the jmp_buf. */ | |
2008 | disable_longjmp_breakpoint (); | |
2009 | remove_breakpoints (); | |
2010 | breakpoints_inserted = 0; | |
2011 | if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc)) | |
c5aa993b | 2012 | { |
488f131b | 2013 | keep_going (ecs); |
104c1213 | 2014 | return; |
c5aa993b | 2015 | } |
488f131b JB |
2016 | |
2017 | /* Need to blow away step-resume breakpoint, as it | |
2018 | interferes with us */ | |
2019 | if (step_resume_breakpoint != NULL) | |
104c1213 | 2020 | { |
488f131b | 2021 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
104c1213 | 2022 | } |
488f131b JB |
2023 | /* Not sure whether we need to blow this away too, but probably |
2024 | it is like the step-resume breakpoint. */ | |
2025 | if (through_sigtramp_breakpoint != NULL) | |
c5aa993b | 2026 | { |
488f131b JB |
2027 | delete_breakpoint (through_sigtramp_breakpoint); |
2028 | through_sigtramp_breakpoint = NULL; | |
c5aa993b | 2029 | } |
c906108c | 2030 | |
488f131b JB |
2031 | #if 0 |
2032 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2033 | if (step_over_calls > 0) | |
2034 | set_longjmp_resume_breakpoint (jmp_buf_pc, get_current_frame ()); | |
c5aa993b | 2035 | else |
488f131b | 2036 | #endif /* 0 */ |
818dd999 | 2037 | set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id); |
488f131b JB |
2038 | ecs->handling_longjmp = 1; /* FIXME */ |
2039 | keep_going (ecs); | |
2040 | return; | |
c906108c | 2041 | |
488f131b JB |
2042 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
2043 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: | |
2044 | remove_breakpoints (); | |
2045 | breakpoints_inserted = 0; | |
2046 | #if 0 | |
2047 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2048 | if (step_over_calls | |
aa0cd9c1 AC |
2049 | && (frame_id_inner (get_frame_id (get_current_frame ()), |
2050 | step_frame_id))) | |
c5aa993b | 2051 | { |
488f131b | 2052 | ecs->another_trap = 1; |
d4f3574e SS |
2053 | keep_going (ecs); |
2054 | return; | |
c5aa993b | 2055 | } |
488f131b JB |
2056 | #endif /* 0 */ |
2057 | disable_longjmp_breakpoint (); | |
2058 | ecs->handling_longjmp = 0; /* FIXME */ | |
2059 | if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) | |
2060 | break; | |
2061 | /* else fallthrough */ | |
2062 | ||
2063 | case BPSTAT_WHAT_SINGLE: | |
2064 | if (breakpoints_inserted) | |
c5aa993b | 2065 | { |
488f131b | 2066 | remove_breakpoints (); |
c5aa993b | 2067 | } |
488f131b JB |
2068 | breakpoints_inserted = 0; |
2069 | ecs->another_trap = 1; | |
2070 | /* Still need to check other stuff, at least the case | |
2071 | where we are stepping and step out of the right range. */ | |
2072 | break; | |
c906108c | 2073 | |
488f131b JB |
2074 | case BPSTAT_WHAT_STOP_NOISY: |
2075 | stop_print_frame = 1; | |
c906108c | 2076 | |
488f131b JB |
2077 | /* We are about to nuke the step_resume_breakpoint and |
2078 | through_sigtramp_breakpoint via the cleanup chain, so | |
2079 | no need to worry about it here. */ | |
c5aa993b | 2080 | |
488f131b JB |
2081 | stop_stepping (ecs); |
2082 | return; | |
c5aa993b | 2083 | |
488f131b JB |
2084 | case BPSTAT_WHAT_STOP_SILENT: |
2085 | stop_print_frame = 0; | |
c5aa993b | 2086 | |
488f131b JB |
2087 | /* We are about to nuke the step_resume_breakpoint and |
2088 | through_sigtramp_breakpoint via the cleanup chain, so | |
2089 | no need to worry about it here. */ | |
c5aa993b | 2090 | |
488f131b | 2091 | stop_stepping (ecs); |
e441088d | 2092 | return; |
c5aa993b | 2093 | |
488f131b JB |
2094 | case BPSTAT_WHAT_STEP_RESUME: |
2095 | /* This proably demands a more elegant solution, but, yeah | |
2096 | right... | |
c5aa993b | 2097 | |
488f131b JB |
2098 | This function's use of the simple variable |
2099 | step_resume_breakpoint doesn't seem to accomodate | |
2100 | simultaneously active step-resume bp's, although the | |
2101 | breakpoint list certainly can. | |
c5aa993b | 2102 | |
488f131b JB |
2103 | If we reach here and step_resume_breakpoint is already |
2104 | NULL, then apparently we have multiple active | |
2105 | step-resume bp's. We'll just delete the breakpoint we | |
2106 | stopped at, and carry on. | |
2107 | ||
2108 | Correction: what the code currently does is delete a | |
2109 | step-resume bp, but it makes no effort to ensure that | |
2110 | the one deleted is the one currently stopped at. MVS */ | |
c5aa993b | 2111 | |
488f131b JB |
2112 | if (step_resume_breakpoint == NULL) |
2113 | { | |
2114 | step_resume_breakpoint = | |
2115 | bpstat_find_step_resume_breakpoint (stop_bpstat); | |
2116 | } | |
2117 | delete_step_resume_breakpoint (&step_resume_breakpoint); | |
2118 | break; | |
2119 | ||
2120 | case BPSTAT_WHAT_THROUGH_SIGTRAMP: | |
2121 | if (through_sigtramp_breakpoint) | |
2122 | delete_breakpoint (through_sigtramp_breakpoint); | |
2123 | through_sigtramp_breakpoint = NULL; | |
2124 | ||
2125 | /* If were waiting for a trap, hitting the step_resume_break | |
2126 | doesn't count as getting it. */ | |
2127 | if (trap_expected) | |
2128 | ecs->another_trap = 1; | |
2129 | break; | |
2130 | ||
2131 | case BPSTAT_WHAT_CHECK_SHLIBS: | |
2132 | case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: | |
2133 | #ifdef SOLIB_ADD | |
c906108c | 2134 | { |
488f131b JB |
2135 | /* Remove breakpoints, we eventually want to step over the |
2136 | shlib event breakpoint, and SOLIB_ADD might adjust | |
2137 | breakpoint addresses via breakpoint_re_set. */ | |
2138 | if (breakpoints_inserted) | |
2139 | remove_breakpoints (); | |
c5aa993b | 2140 | breakpoints_inserted = 0; |
488f131b JB |
2141 | |
2142 | /* Check for any newly added shared libraries if we're | |
2143 | supposed to be adding them automatically. Switch | |
2144 | terminal for any messages produced by | |
2145 | breakpoint_re_set. */ | |
2146 | target_terminal_ours_for_output (); | |
2147 | SOLIB_ADD (NULL, 0, NULL, auto_solib_add); | |
2148 | target_terminal_inferior (); | |
2149 | ||
2150 | /* Try to reenable shared library breakpoints, additional | |
2151 | code segments in shared libraries might be mapped in now. */ | |
2152 | re_enable_breakpoints_in_shlibs (); | |
2153 | ||
2154 | /* If requested, stop when the dynamic linker notifies | |
2155 | gdb of events. This allows the user to get control | |
2156 | and place breakpoints in initializer routines for | |
2157 | dynamically loaded objects (among other things). */ | |
2158 | if (stop_on_solib_events) | |
d4f3574e | 2159 | { |
488f131b | 2160 | stop_stepping (ecs); |
d4f3574e SS |
2161 | return; |
2162 | } | |
c5aa993b | 2163 | |
488f131b JB |
2164 | /* If we stopped due to an explicit catchpoint, then the |
2165 | (see above) call to SOLIB_ADD pulled in any symbols | |
2166 | from a newly-loaded library, if appropriate. | |
2167 | ||
2168 | We do want the inferior to stop, but not where it is | |
2169 | now, which is in the dynamic linker callback. Rather, | |
2170 | we would like it stop in the user's program, just after | |
2171 | the call that caused this catchpoint to trigger. That | |
2172 | gives the user a more useful vantage from which to | |
2173 | examine their program's state. */ | |
2174 | else if (what.main_action == | |
2175 | BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) | |
c906108c | 2176 | { |
488f131b JB |
2177 | /* ??rehrauer: If I could figure out how to get the |
2178 | right return PC from here, we could just set a temp | |
2179 | breakpoint and resume. I'm not sure we can without | |
2180 | cracking open the dld's shared libraries and sniffing | |
2181 | their unwind tables and text/data ranges, and that's | |
2182 | not a terribly portable notion. | |
2183 | ||
2184 | Until that time, we must step the inferior out of the | |
2185 | dld callback, and also out of the dld itself (and any | |
2186 | code or stubs in libdld.sl, such as "shl_load" and | |
2187 | friends) until we reach non-dld code. At that point, | |
2188 | we can stop stepping. */ | |
2189 | bpstat_get_triggered_catchpoints (stop_bpstat, | |
2190 | &ecs-> | |
2191 | stepping_through_solib_catchpoints); | |
2192 | ecs->stepping_through_solib_after_catch = 1; | |
2193 | ||
2194 | /* Be sure to lift all breakpoints, so the inferior does | |
2195 | actually step past this point... */ | |
2196 | ecs->another_trap = 1; | |
2197 | break; | |
c906108c | 2198 | } |
c5aa993b | 2199 | else |
c5aa993b | 2200 | { |
488f131b | 2201 | /* We want to step over this breakpoint, then keep going. */ |
c5aa993b | 2202 | ecs->another_trap = 1; |
488f131b | 2203 | break; |
c5aa993b | 2204 | } |
488f131b JB |
2205 | } |
2206 | #endif | |
2207 | break; | |
c906108c | 2208 | |
488f131b JB |
2209 | case BPSTAT_WHAT_LAST: |
2210 | /* Not a real code, but listed here to shut up gcc -Wall. */ | |
c906108c | 2211 | |
488f131b JB |
2212 | case BPSTAT_WHAT_KEEP_CHECKING: |
2213 | break; | |
2214 | } | |
2215 | } | |
c906108c | 2216 | |
488f131b JB |
2217 | /* We come here if we hit a breakpoint but should not |
2218 | stop for it. Possibly we also were stepping | |
2219 | and should stop for that. So fall through and | |
2220 | test for stepping. But, if not stepping, | |
2221 | do not stop. */ | |
c906108c | 2222 | |
488f131b JB |
2223 | /* Are we stepping to get the inferior out of the dynamic |
2224 | linker's hook (and possibly the dld itself) after catching | |
2225 | a shlib event? */ | |
2226 | if (ecs->stepping_through_solib_after_catch) | |
2227 | { | |
2228 | #if defined(SOLIB_ADD) | |
2229 | /* Have we reached our destination? If not, keep going. */ | |
2230 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) | |
2231 | { | |
2232 | ecs->another_trap = 1; | |
2233 | keep_going (ecs); | |
104c1213 | 2234 | return; |
488f131b JB |
2235 | } |
2236 | #endif | |
2237 | /* Else, stop and report the catchpoint(s) whose triggering | |
2238 | caused us to begin stepping. */ | |
2239 | ecs->stepping_through_solib_after_catch = 0; | |
2240 | bpstat_clear (&stop_bpstat); | |
2241 | stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); | |
2242 | bpstat_clear (&ecs->stepping_through_solib_catchpoints); | |
2243 | stop_print_frame = 1; | |
2244 | stop_stepping (ecs); | |
2245 | return; | |
2246 | } | |
c906108c | 2247 | |
488f131b JB |
2248 | if (step_resume_breakpoint) |
2249 | { | |
2250 | /* Having a step-resume breakpoint overrides anything | |
2251 | else having to do with stepping commands until | |
2252 | that breakpoint is reached. */ | |
2253 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2254 | whether it could/should be keep_going. */ | |
2255 | check_sigtramp2 (ecs); | |
2256 | keep_going (ecs); | |
2257 | return; | |
2258 | } | |
c5aa993b | 2259 | |
488f131b JB |
2260 | if (step_range_end == 0) |
2261 | { | |
2262 | /* Likewise if we aren't even stepping. */ | |
2263 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2264 | whether it could/should be keep_going. */ | |
2265 | check_sigtramp2 (ecs); | |
2266 | keep_going (ecs); | |
2267 | return; | |
2268 | } | |
c5aa993b | 2269 | |
488f131b | 2270 | /* If stepping through a line, keep going if still within it. |
c906108c | 2271 | |
488f131b JB |
2272 | Note that step_range_end is the address of the first instruction |
2273 | beyond the step range, and NOT the address of the last instruction | |
2274 | within it! */ | |
2275 | if (stop_pc >= step_range_start && stop_pc < step_range_end) | |
2276 | { | |
2277 | /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. | |
2278 | So definately need to check for sigtramp here. */ | |
2279 | check_sigtramp2 (ecs); | |
2280 | keep_going (ecs); | |
2281 | return; | |
2282 | } | |
c5aa993b | 2283 | |
488f131b | 2284 | /* We stepped out of the stepping range. */ |
c906108c | 2285 | |
488f131b JB |
2286 | /* If we are stepping at the source level and entered the runtime |
2287 | loader dynamic symbol resolution code, we keep on single stepping | |
2288 | until we exit the run time loader code and reach the callee's | |
2289 | address. */ | |
2290 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE | |
2291 | && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc)) | |
2292 | { | |
2293 | CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc); | |
c906108c | 2294 | |
488f131b JB |
2295 | if (pc_after_resolver) |
2296 | { | |
2297 | /* Set up a step-resume breakpoint at the address | |
2298 | indicated by SKIP_SOLIB_RESOLVER. */ | |
2299 | struct symtab_and_line sr_sal; | |
fe39c653 | 2300 | init_sal (&sr_sal); |
488f131b JB |
2301 | sr_sal.pc = pc_after_resolver; |
2302 | ||
2303 | check_for_old_step_resume_breakpoint (); | |
2304 | step_resume_breakpoint = | |
818dd999 | 2305 | set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); |
488f131b JB |
2306 | if (breakpoints_inserted) |
2307 | insert_breakpoints (); | |
c5aa993b | 2308 | } |
c906108c | 2309 | |
488f131b JB |
2310 | keep_going (ecs); |
2311 | return; | |
2312 | } | |
c906108c | 2313 | |
488f131b JB |
2314 | /* We can't update step_sp every time through the loop, because |
2315 | reading the stack pointer would slow down stepping too much. | |
2316 | But we can update it every time we leave the step range. */ | |
2317 | ecs->update_step_sp = 1; | |
c906108c | 2318 | |
488f131b | 2319 | /* Did we just take a signal? */ |
0ce3d317 AC |
2320 | if (pc_in_sigtramp (stop_pc) |
2321 | && !pc_in_sigtramp (prev_pc) | |
488f131b JB |
2322 | && INNER_THAN (read_sp (), step_sp)) |
2323 | { | |
2324 | /* We've just taken a signal; go until we are back to | |
2325 | the point where we took it and one more. */ | |
c906108c | 2326 | |
488f131b JB |
2327 | /* Note: The test above succeeds not only when we stepped |
2328 | into a signal handler, but also when we step past the last | |
2329 | statement of a signal handler and end up in the return stub | |
2330 | of the signal handler trampoline. To distinguish between | |
2331 | these two cases, check that the frame is INNER_THAN the | |
2332 | previous one below. pai/1997-09-11 */ | |
c5aa993b | 2333 | |
c5aa993b | 2334 | |
c5aa993b | 2335 | { |
aa0cd9c1 | 2336 | struct frame_id current_frame = get_frame_id (get_current_frame ()); |
c906108c | 2337 | |
aa0cd9c1 | 2338 | if (frame_id_inner (current_frame, step_frame_id)) |
488f131b JB |
2339 | { |
2340 | /* We have just taken a signal; go until we are back to | |
2341 | the point where we took it and one more. */ | |
c906108c | 2342 | |
488f131b JB |
2343 | /* This code is needed at least in the following case: |
2344 | The user types "next" and then a signal arrives (before | |
2345 | the "next" is done). */ | |
d4f3574e | 2346 | |
488f131b JB |
2347 | /* Note that if we are stopped at a breakpoint, then we need |
2348 | the step_resume breakpoint to override any breakpoints at | |
2349 | the same location, so that we will still step over the | |
2350 | breakpoint even though the signal happened. */ | |
d4f3574e | 2351 | struct symtab_and_line sr_sal; |
d4f3574e | 2352 | |
fe39c653 | 2353 | init_sal (&sr_sal); |
488f131b JB |
2354 | sr_sal.symtab = NULL; |
2355 | sr_sal.line = 0; | |
2356 | sr_sal.pc = prev_pc; | |
2357 | /* We could probably be setting the frame to | |
aa0cd9c1 | 2358 | step_frame_id; I don't think anyone thought to try it. */ |
d4f3574e SS |
2359 | check_for_old_step_resume_breakpoint (); |
2360 | step_resume_breakpoint = | |
818dd999 | 2361 | set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); |
d4f3574e SS |
2362 | if (breakpoints_inserted) |
2363 | insert_breakpoints (); | |
2364 | } | |
488f131b JB |
2365 | else |
2366 | { | |
2367 | /* We just stepped out of a signal handler and into | |
2368 | its calling trampoline. | |
2369 | ||
2370 | Normally, we'd call step_over_function from | |
2371 | here, but for some reason GDB can't unwind the | |
2372 | stack correctly to find the real PC for the point | |
2373 | user code where the signal trampoline will return | |
2374 | -- FRAME_SAVED_PC fails, at least on HP-UX 10.20. | |
2375 | But signal trampolines are pretty small stubs of | |
2376 | code, anyway, so it's OK instead to just | |
2377 | single-step out. Note: assuming such trampolines | |
2378 | don't exhibit recursion on any platform... */ | |
2379 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
2380 | &ecs->stop_func_start, | |
2381 | &ecs->stop_func_end); | |
2382 | /* Readjust stepping range */ | |
2383 | step_range_start = ecs->stop_func_start; | |
2384 | step_range_end = ecs->stop_func_end; | |
2385 | ecs->stepping_through_sigtramp = 1; | |
2386 | } | |
d4f3574e | 2387 | } |
c906108c | 2388 | |
c906108c | 2389 | |
488f131b JB |
2390 | /* If this is stepi or nexti, make sure that the stepping range |
2391 | gets us past that instruction. */ | |
2392 | if (step_range_end == 1) | |
2393 | /* FIXME: Does this run afoul of the code below which, if | |
2394 | we step into the middle of a line, resets the stepping | |
2395 | range? */ | |
2396 | step_range_end = (step_range_start = prev_pc) + 1; | |
2397 | ||
2398 | ecs->remove_breakpoints_on_following_step = 1; | |
2399 | keep_going (ecs); | |
2400 | return; | |
2401 | } | |
c906108c | 2402 | |
488f131b JB |
2403 | if (stop_pc == ecs->stop_func_start /* Quick test */ |
2404 | || (in_prologue (stop_pc, ecs->stop_func_start) && | |
2405 | !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) | |
2406 | || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name) | |
2407 | || ecs->stop_func_name == 0) | |
2408 | { | |
2409 | /* It's a subroutine call. */ | |
c906108c | 2410 | |
488f131b JB |
2411 | if ((step_over_calls == STEP_OVER_NONE) |
2412 | || ((step_range_end == 1) | |
2413 | && in_prologue (prev_pc, ecs->stop_func_start))) | |
2414 | { | |
2415 | /* I presume that step_over_calls is only 0 when we're | |
2416 | supposed to be stepping at the assembly language level | |
2417 | ("stepi"). Just stop. */ | |
2418 | /* Also, maybe we just did a "nexti" inside a prolog, | |
2419 | so we thought it was a subroutine call but it was not. | |
2420 | Stop as well. FENN */ | |
2421 | stop_step = 1; | |
2422 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2423 | stop_stepping (ecs); | |
2424 | return; | |
2425 | } | |
c906108c | 2426 | |
488f131b | 2427 | if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc)) |
c5aa993b | 2428 | { |
488f131b JB |
2429 | /* We're doing a "next". */ |
2430 | ||
0ce3d317 | 2431 | if (pc_in_sigtramp (stop_pc) |
aa0cd9c1 AC |
2432 | && frame_id_inner (step_frame_id, |
2433 | frame_id_build (read_sp (), 0))) | |
488f131b JB |
2434 | /* We stepped out of a signal handler, and into its |
2435 | calling trampoline. This is misdetected as a | |
2436 | subroutine call, but stepping over the signal | |
aa0cd9c1 AC |
2437 | trampoline isn't such a bad idea. In order to do that, |
2438 | we have to ignore the value in step_frame_id, since | |
2439 | that doesn't represent the frame that'll reach when we | |
2440 | return from the signal trampoline. Otherwise we'll | |
2441 | probably continue to the end of the program. */ | |
2442 | step_frame_id = null_frame_id; | |
488f131b JB |
2443 | |
2444 | step_over_function (ecs); | |
2445 | keep_going (ecs); | |
2446 | return; | |
2447 | } | |
c906108c | 2448 | |
488f131b JB |
2449 | /* If we are in a function call trampoline (a stub between |
2450 | the calling routine and the real function), locate the real | |
2451 | function. That's what tells us (a) whether we want to step | |
2452 | into it at all, and (b) what prologue we want to run to | |
2453 | the end of, if we do step into it. */ | |
f636b87d AF |
2454 | real_stop_pc = skip_language_trampoline (stop_pc); |
2455 | if (real_stop_pc == 0) | |
2456 | real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc); | |
d764a824 AF |
2457 | if (real_stop_pc != 0) |
2458 | ecs->stop_func_start = real_stop_pc; | |
c906108c | 2459 | |
488f131b JB |
2460 | /* If we have line number information for the function we |
2461 | are thinking of stepping into, step into it. | |
c906108c | 2462 | |
488f131b JB |
2463 | If there are several symtabs at that PC (e.g. with include |
2464 | files), just want to know whether *any* of them have line | |
2465 | numbers. find_pc_line handles this. */ | |
c5aa993b | 2466 | { |
488f131b | 2467 | struct symtab_and_line tmp_sal; |
c906108c | 2468 | |
488f131b JB |
2469 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
2470 | if (tmp_sal.line != 0) | |
d4f3574e | 2471 | { |
488f131b | 2472 | step_into_function (ecs); |
d4f3574e SS |
2473 | return; |
2474 | } | |
488f131b | 2475 | } |
c5aa993b | 2476 | |
488f131b JB |
2477 | /* If we have no line number and the step-stop-if-no-debug |
2478 | is set, we stop the step so that the user has a chance to | |
2479 | switch in assembly mode. */ | |
2480 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug) | |
c5aa993b | 2481 | { |
488f131b JB |
2482 | stop_step = 1; |
2483 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2484 | stop_stepping (ecs); | |
2485 | return; | |
c906108c | 2486 | } |
5fbbeb29 | 2487 | |
488f131b JB |
2488 | step_over_function (ecs); |
2489 | keep_going (ecs); | |
2490 | return; | |
c906108c | 2491 | |
488f131b | 2492 | } |
c906108c | 2493 | |
488f131b | 2494 | /* We've wandered out of the step range. */ |
c906108c | 2495 | |
488f131b | 2496 | ecs->sal = find_pc_line (stop_pc, 0); |
c906108c | 2497 | |
488f131b JB |
2498 | if (step_range_end == 1) |
2499 | { | |
2500 | /* It is stepi or nexti. We always want to stop stepping after | |
2501 | one instruction. */ | |
2502 | stop_step = 1; | |
2503 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2504 | stop_stepping (ecs); | |
2505 | return; | |
2506 | } | |
c906108c | 2507 | |
488f131b JB |
2508 | /* If we're in the return path from a shared library trampoline, |
2509 | we want to proceed through the trampoline when stepping. */ | |
2510 | if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) | |
2511 | { | |
488f131b | 2512 | /* Determine where this trampoline returns. */ |
d764a824 | 2513 | real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc); |
c906108c | 2514 | |
488f131b | 2515 | /* Only proceed through if we know where it's going. */ |
d764a824 | 2516 | if (real_stop_pc) |
488f131b JB |
2517 | { |
2518 | /* And put the step-breakpoint there and go until there. */ | |
2519 | struct symtab_and_line sr_sal; | |
2520 | ||
fe39c653 | 2521 | init_sal (&sr_sal); /* initialize to zeroes */ |
d764a824 | 2522 | sr_sal.pc = real_stop_pc; |
488f131b JB |
2523 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
2524 | /* Do not specify what the fp should be when we stop | |
2525 | since on some machines the prologue | |
2526 | is where the new fp value is established. */ | |
2527 | check_for_old_step_resume_breakpoint (); | |
2528 | step_resume_breakpoint = | |
818dd999 | 2529 | set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); |
488f131b JB |
2530 | if (breakpoints_inserted) |
2531 | insert_breakpoints (); | |
c906108c | 2532 | |
488f131b JB |
2533 | /* Restart without fiddling with the step ranges or |
2534 | other state. */ | |
2535 | keep_going (ecs); | |
2536 | return; | |
2537 | } | |
2538 | } | |
c906108c | 2539 | |
488f131b JB |
2540 | if (ecs->sal.line == 0) |
2541 | { | |
2542 | /* We have no line number information. That means to stop | |
2543 | stepping (does this always happen right after one instruction, | |
2544 | when we do "s" in a function with no line numbers, | |
2545 | or can this happen as a result of a return or longjmp?). */ | |
2546 | stop_step = 1; | |
2547 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2548 | stop_stepping (ecs); | |
2549 | return; | |
2550 | } | |
c906108c | 2551 | |
488f131b JB |
2552 | if ((stop_pc == ecs->sal.pc) |
2553 | && (ecs->current_line != ecs->sal.line | |
2554 | || ecs->current_symtab != ecs->sal.symtab)) | |
2555 | { | |
2556 | /* We are at the start of a different line. So stop. Note that | |
2557 | we don't stop if we step into the middle of a different line. | |
2558 | That is said to make things like for (;;) statements work | |
2559 | better. */ | |
2560 | stop_step = 1; | |
2561 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2562 | stop_stepping (ecs); | |
2563 | return; | |
2564 | } | |
c906108c | 2565 | |
488f131b | 2566 | /* We aren't done stepping. |
c906108c | 2567 | |
488f131b JB |
2568 | Optimize by setting the stepping range to the line. |
2569 | (We might not be in the original line, but if we entered a | |
2570 | new line in mid-statement, we continue stepping. This makes | |
2571 | things like for(;;) statements work better.) */ | |
c906108c | 2572 | |
488f131b | 2573 | if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end) |
c5aa993b | 2574 | { |
488f131b JB |
2575 | /* If this is the last line of the function, don't keep stepping |
2576 | (it would probably step us out of the function). | |
2577 | This is particularly necessary for a one-line function, | |
2578 | in which after skipping the prologue we better stop even though | |
2579 | we will be in mid-line. */ | |
2580 | stop_step = 1; | |
2581 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2582 | stop_stepping (ecs); | |
2583 | return; | |
c5aa993b | 2584 | } |
488f131b JB |
2585 | step_range_start = ecs->sal.pc; |
2586 | step_range_end = ecs->sal.end; | |
aa0cd9c1 | 2587 | step_frame_id = get_frame_id (get_current_frame ()); |
488f131b JB |
2588 | ecs->current_line = ecs->sal.line; |
2589 | ecs->current_symtab = ecs->sal.symtab; | |
2590 | ||
aa0cd9c1 AC |
2591 | /* In the case where we just stepped out of a function into the |
2592 | middle of a line of the caller, continue stepping, but | |
2593 | step_frame_id must be modified to current frame */ | |
488f131b | 2594 | { |
aa0cd9c1 AC |
2595 | struct frame_id current_frame = get_frame_id (get_current_frame ()); |
2596 | if (!(frame_id_inner (current_frame, step_frame_id))) | |
2597 | step_frame_id = current_frame; | |
488f131b | 2598 | } |
c906108c | 2599 | |
488f131b | 2600 | keep_going (ecs); |
104c1213 JM |
2601 | } |
2602 | ||
2603 | /* Are we in the middle of stepping? */ | |
2604 | ||
2605 | static int | |
2606 | currently_stepping (struct execution_control_state *ecs) | |
2607 | { | |
2608 | return ((through_sigtramp_breakpoint == NULL | |
2609 | && !ecs->handling_longjmp | |
2610 | && ((step_range_end && step_resume_breakpoint == NULL) | |
2611 | || trap_expected)) | |
2612 | || ecs->stepping_through_solib_after_catch | |
2613 | || bpstat_should_step ()); | |
2614 | } | |
c906108c | 2615 | |
104c1213 JM |
2616 | static void |
2617 | check_sigtramp2 (struct execution_control_state *ecs) | |
2618 | { | |
2619 | if (trap_expected | |
0ce3d317 AC |
2620 | && pc_in_sigtramp (stop_pc) |
2621 | && !pc_in_sigtramp (prev_pc) | |
104c1213 JM |
2622 | && INNER_THAN (read_sp (), step_sp)) |
2623 | { | |
2624 | /* What has happened here is that we have just stepped the | |
488f131b JB |
2625 | inferior with a signal (because it is a signal which |
2626 | shouldn't make us stop), thus stepping into sigtramp. | |
104c1213 | 2627 | |
488f131b JB |
2628 | So we need to set a step_resume_break_address breakpoint and |
2629 | continue until we hit it, and then step. FIXME: This should | |
2630 | be more enduring than a step_resume breakpoint; we should | |
2631 | know that we will later need to keep going rather than | |
2632 | re-hitting the breakpoint here (see the testsuite, | |
2633 | gdb.base/signals.exp where it says "exceedingly difficult"). */ | |
104c1213 JM |
2634 | |
2635 | struct symtab_and_line sr_sal; | |
2636 | ||
fe39c653 | 2637 | init_sal (&sr_sal); /* initialize to zeroes */ |
104c1213 JM |
2638 | sr_sal.pc = prev_pc; |
2639 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
2640 | /* We perhaps could set the frame if we kept track of what the | |
488f131b | 2641 | frame corresponding to prev_pc was. But we don't, so don't. */ |
104c1213 | 2642 | through_sigtramp_breakpoint = |
818dd999 | 2643 | set_momentary_breakpoint (sr_sal, null_frame_id, bp_through_sigtramp); |
104c1213 JM |
2644 | if (breakpoints_inserted) |
2645 | insert_breakpoints (); | |
cd0fc7c3 | 2646 | |
104c1213 JM |
2647 | ecs->remove_breakpoints_on_following_step = 1; |
2648 | ecs->another_trap = 1; | |
2649 | } | |
2650 | } | |
2651 | ||
c2c6d25f JM |
2652 | /* Subroutine call with source code we should not step over. Do step |
2653 | to the first line of code in it. */ | |
2654 | ||
2655 | static void | |
2656 | step_into_function (struct execution_control_state *ecs) | |
2657 | { | |
2658 | struct symtab *s; | |
2659 | struct symtab_and_line sr_sal; | |
2660 | ||
2661 | s = find_pc_symtab (stop_pc); | |
2662 | if (s && s->language != language_asm) | |
2663 | ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start); | |
2664 | ||
2665 | ecs->sal = find_pc_line (ecs->stop_func_start, 0); | |
2666 | /* Use the step_resume_break to step until the end of the prologue, | |
2667 | even if that involves jumps (as it seems to on the vax under | |
2668 | 4.2). */ | |
2669 | /* If the prologue ends in the middle of a source line, continue to | |
2670 | the end of that source line (if it is still within the function). | |
2671 | Otherwise, just go to end of prologue. */ | |
2672 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
2673 | /* no, don't either. It skips any code that's legitimately on the | |
2674 | first line. */ | |
2675 | #else | |
2676 | if (ecs->sal.end | |
2677 | && ecs->sal.pc != ecs->stop_func_start | |
2678 | && ecs->sal.end < ecs->stop_func_end) | |
2679 | ecs->stop_func_start = ecs->sal.end; | |
2680 | #endif | |
2681 | ||
2682 | if (ecs->stop_func_start == stop_pc) | |
2683 | { | |
2684 | /* We are already there: stop now. */ | |
2685 | stop_step = 1; | |
488f131b | 2686 | print_stop_reason (END_STEPPING_RANGE, 0); |
c2c6d25f JM |
2687 | stop_stepping (ecs); |
2688 | return; | |
2689 | } | |
2690 | else | |
2691 | { | |
2692 | /* Put the step-breakpoint there and go until there. */ | |
fe39c653 | 2693 | init_sal (&sr_sal); /* initialize to zeroes */ |
c2c6d25f JM |
2694 | sr_sal.pc = ecs->stop_func_start; |
2695 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
2696 | /* Do not specify what the fp should be when we stop since on | |
488f131b JB |
2697 | some machines the prologue is where the new fp value is |
2698 | established. */ | |
c2c6d25f JM |
2699 | check_for_old_step_resume_breakpoint (); |
2700 | step_resume_breakpoint = | |
818dd999 | 2701 | set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); |
c2c6d25f JM |
2702 | if (breakpoints_inserted) |
2703 | insert_breakpoints (); | |
2704 | ||
2705 | /* And make sure stepping stops right away then. */ | |
2706 | step_range_end = step_range_start; | |
2707 | } | |
2708 | keep_going (ecs); | |
2709 | } | |
d4f3574e SS |
2710 | |
2711 | /* We've just entered a callee, and we wish to resume until it returns | |
2712 | to the caller. Setting a step_resume breakpoint on the return | |
2713 | address will catch a return from the callee. | |
2714 | ||
2715 | However, if the callee is recursing, we want to be careful not to | |
2716 | catch returns of those recursive calls, but only of THIS instance | |
2717 | of the call. | |
2718 | ||
2719 | To do this, we set the step_resume bp's frame to our current | |
aa0cd9c1 | 2720 | caller's frame (step_frame_id, which is set by the "next" or |
d4f3574e SS |
2721 | "until" command, before execution begins). */ |
2722 | ||
2723 | static void | |
2724 | step_over_function (struct execution_control_state *ecs) | |
2725 | { | |
2726 | struct symtab_and_line sr_sal; | |
2727 | ||
fe39c653 | 2728 | init_sal (&sr_sal); /* initialize to zeros */ |
4443bd83 AC |
2729 | |
2730 | /* NOTE: cagney/2003-04-06: | |
2731 | ||
2732 | At this point the equality get_frame_pc() == get_frame_func() | |
2733 | should hold. This may make it possible for this code to tell the | |
2734 | frame where it's function is, instead of the reverse. This would | |
2735 | avoid the need to search for the frame's function, which can get | |
2736 | very messy when there is no debug info available (look at the | |
2737 | heuristic find pc start code found in targets like the MIPS). */ | |
2738 | ||
6913c89a | 2739 | /* NOTE: cagney/2003-04-06: |
4443bd83 | 2740 | |
6913c89a | 2741 | The intent of DEPRECATED_SAVED_PC_AFTER_CALL was to: |
4443bd83 AC |
2742 | |
2743 | - provide a very light weight equivalent to frame_unwind_pc() | |
2744 | (nee FRAME_SAVED_PC) that avoids the prologue analyzer | |
2745 | ||
2746 | - avoid handling the case where the PC hasn't been saved in the | |
2747 | prologue analyzer | |
2748 | ||
2749 | Unfortunatly, not five lines further down, is a call to | |
2750 | get_frame_id() and that is guarenteed to trigger the prologue | |
2751 | analyzer. | |
2752 | ||
2753 | The `correct fix' is for the prologe analyzer to handle the case | |
2754 | where the prologue is incomplete (PC in prologue) and, | |
2755 | consequently, the return pc has not yet been saved. It should be | |
2756 | noted that the prologue analyzer needs to handle this case | |
2757 | anyway: frameless leaf functions that don't save the return PC; | |
2758 | single stepping through a prologue. | |
2759 | ||
2760 | The d10v handles all this by bailing out of the prologue analsis | |
2761 | when it reaches the current instruction. */ | |
2762 | ||
6913c89a AC |
2763 | if (DEPRECATED_SAVED_PC_AFTER_CALL_P ()) |
2764 | sr_sal.pc = ADDR_BITS_REMOVE (DEPRECATED_SAVED_PC_AFTER_CALL (get_current_frame ())); | |
4443bd83 AC |
2765 | else |
2766 | sr_sal.pc = ADDR_BITS_REMOVE (frame_pc_unwind (get_current_frame ())); | |
d4f3574e SS |
2767 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
2768 | ||
2769 | check_for_old_step_resume_breakpoint (); | |
2770 | step_resume_breakpoint = | |
818dd999 AC |
2771 | set_momentary_breakpoint (sr_sal, get_frame_id (get_current_frame ()), |
2772 | bp_step_resume); | |
d4f3574e | 2773 | |
aa0cd9c1 AC |
2774 | if (frame_id_p (step_frame_id) |
2775 | && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc)) | |
818dd999 | 2776 | step_resume_breakpoint->frame_id = step_frame_id; |
d4f3574e SS |
2777 | |
2778 | if (breakpoints_inserted) | |
2779 | insert_breakpoints (); | |
2780 | } | |
2781 | ||
104c1213 JM |
2782 | static void |
2783 | stop_stepping (struct execution_control_state *ecs) | |
2784 | { | |
cd0fc7c3 SS |
2785 | /* Let callers know we don't want to wait for the inferior anymore. */ |
2786 | ecs->wait_some_more = 0; | |
2787 | } | |
2788 | ||
d4f3574e SS |
2789 | /* This function handles various cases where we need to continue |
2790 | waiting for the inferior. */ | |
2791 | /* (Used to be the keep_going: label in the old wait_for_inferior) */ | |
2792 | ||
2793 | static void | |
2794 | keep_going (struct execution_control_state *ecs) | |
2795 | { | |
d4f3574e | 2796 | /* Save the pc before execution, to compare with pc after stop. */ |
488f131b | 2797 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ |
d4f3574e SS |
2798 | |
2799 | if (ecs->update_step_sp) | |
2800 | step_sp = read_sp (); | |
2801 | ecs->update_step_sp = 0; | |
2802 | ||
2803 | /* If we did not do break;, it means we should keep running the | |
2804 | inferior and not return to debugger. */ | |
2805 | ||
2806 | if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) | |
2807 | { | |
2808 | /* We took a signal (which we are supposed to pass through to | |
488f131b JB |
2809 | the inferior, else we'd have done a break above) and we |
2810 | haven't yet gotten our trap. Simply continue. */ | |
d4f3574e SS |
2811 | resume (currently_stepping (ecs), stop_signal); |
2812 | } | |
2813 | else | |
2814 | { | |
2815 | /* Either the trap was not expected, but we are continuing | |
488f131b JB |
2816 | anyway (the user asked that this signal be passed to the |
2817 | child) | |
2818 | -- or -- | |
2819 | The signal was SIGTRAP, e.g. it was our signal, but we | |
2820 | decided we should resume from it. | |
d4f3574e | 2821 | |
488f131b | 2822 | We're going to run this baby now! |
d4f3574e | 2823 | |
488f131b JB |
2824 | Insert breakpoints now, unless we are trying to one-proceed |
2825 | past a breakpoint. */ | |
d4f3574e | 2826 | /* If we've just finished a special step resume and we don't |
488f131b | 2827 | want to hit a breakpoint, pull em out. */ |
d4f3574e SS |
2828 | if (step_resume_breakpoint == NULL |
2829 | && through_sigtramp_breakpoint == NULL | |
2830 | && ecs->remove_breakpoints_on_following_step) | |
2831 | { | |
2832 | ecs->remove_breakpoints_on_following_step = 0; | |
2833 | remove_breakpoints (); | |
2834 | breakpoints_inserted = 0; | |
2835 | } | |
2836 | else if (!breakpoints_inserted && | |
2837 | (through_sigtramp_breakpoint != NULL || !ecs->another_trap)) | |
2838 | { | |
2839 | breakpoints_failed = insert_breakpoints (); | |
2840 | if (breakpoints_failed) | |
2841 | { | |
2842 | stop_stepping (ecs); | |
2843 | return; | |
2844 | } | |
2845 | breakpoints_inserted = 1; | |
2846 | } | |
2847 | ||
2848 | trap_expected = ecs->another_trap; | |
2849 | ||
2850 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly | |
488f131b JB |
2851 | specifies that such a signal should be delivered to the |
2852 | target program). | |
2853 | ||
2854 | Typically, this would occure when a user is debugging a | |
2855 | target monitor on a simulator: the target monitor sets a | |
2856 | breakpoint; the simulator encounters this break-point and | |
2857 | halts the simulation handing control to GDB; GDB, noteing | |
2858 | that the break-point isn't valid, returns control back to the | |
2859 | simulator; the simulator then delivers the hardware | |
2860 | equivalent of a SIGNAL_TRAP to the program being debugged. */ | |
2861 | ||
2862 | if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal]) | |
d4f3574e SS |
2863 | stop_signal = TARGET_SIGNAL_0; |
2864 | ||
2865 | #ifdef SHIFT_INST_REGS | |
2866 | /* I'm not sure when this following segment applies. I do know, | |
488f131b JB |
2867 | now, that we shouldn't rewrite the regs when we were stopped |
2868 | by a random signal from the inferior process. */ | |
d4f3574e | 2869 | /* FIXME: Shouldn't this be based on the valid bit of the SXIP? |
488f131b | 2870 | (this is only used on the 88k). */ |
d4f3574e SS |
2871 | |
2872 | if (!bpstat_explains_signal (stop_bpstat) | |
488f131b | 2873 | && (stop_signal != TARGET_SIGNAL_CHLD) && !stopped_by_random_signal) |
d4f3574e SS |
2874 | SHIFT_INST_REGS (); |
2875 | #endif /* SHIFT_INST_REGS */ | |
2876 | ||
2877 | resume (currently_stepping (ecs), stop_signal); | |
2878 | } | |
2879 | ||
488f131b | 2880 | prepare_to_wait (ecs); |
d4f3574e SS |
2881 | } |
2882 | ||
104c1213 JM |
2883 | /* This function normally comes after a resume, before |
2884 | handle_inferior_event exits. It takes care of any last bits of | |
2885 | housekeeping, and sets the all-important wait_some_more flag. */ | |
cd0fc7c3 | 2886 | |
104c1213 JM |
2887 | static void |
2888 | prepare_to_wait (struct execution_control_state *ecs) | |
cd0fc7c3 | 2889 | { |
104c1213 JM |
2890 | if (ecs->infwait_state == infwait_normal_state) |
2891 | { | |
2892 | overlay_cache_invalid = 1; | |
2893 | ||
2894 | /* We have to invalidate the registers BEFORE calling | |
488f131b JB |
2895 | target_wait because they can be loaded from the target while |
2896 | in target_wait. This makes remote debugging a bit more | |
2897 | efficient for those targets that provide critical registers | |
2898 | as part of their normal status mechanism. */ | |
104c1213 JM |
2899 | |
2900 | registers_changed (); | |
39f77062 | 2901 | ecs->waiton_ptid = pid_to_ptid (-1); |
104c1213 JM |
2902 | ecs->wp = &(ecs->ws); |
2903 | } | |
2904 | /* This is the old end of the while loop. Let everybody know we | |
2905 | want to wait for the inferior some more and get called again | |
2906 | soon. */ | |
2907 | ecs->wait_some_more = 1; | |
c906108c | 2908 | } |
11cf8741 JM |
2909 | |
2910 | /* Print why the inferior has stopped. We always print something when | |
2911 | the inferior exits, or receives a signal. The rest of the cases are | |
2912 | dealt with later on in normal_stop() and print_it_typical(). Ideally | |
2913 | there should be a call to this function from handle_inferior_event() | |
2914 | each time stop_stepping() is called.*/ | |
2915 | static void | |
2916 | print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) | |
2917 | { | |
2918 | switch (stop_reason) | |
2919 | { | |
2920 | case STOP_UNKNOWN: | |
2921 | /* We don't deal with these cases from handle_inferior_event() | |
2922 | yet. */ | |
2923 | break; | |
2924 | case END_STEPPING_RANGE: | |
2925 | /* We are done with a step/next/si/ni command. */ | |
2926 | /* For now print nothing. */ | |
fb40c209 | 2927 | /* Print a message only if not in the middle of doing a "step n" |
488f131b | 2928 | operation for n > 1 */ |
fb40c209 | 2929 | if (!step_multi || !stop_step) |
9dc5e2a9 | 2930 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2931 | ui_out_field_string (uiout, "reason", "end-stepping-range"); |
11cf8741 JM |
2932 | break; |
2933 | case BREAKPOINT_HIT: | |
2934 | /* We found a breakpoint. */ | |
2935 | /* For now print nothing. */ | |
2936 | break; | |
2937 | case SIGNAL_EXITED: | |
2938 | /* The inferior was terminated by a signal. */ | |
8b93c638 | 2939 | annotate_signalled (); |
9dc5e2a9 | 2940 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2941 | ui_out_field_string (uiout, "reason", "exited-signalled"); |
8b93c638 JM |
2942 | ui_out_text (uiout, "\nProgram terminated with signal "); |
2943 | annotate_signal_name (); | |
488f131b JB |
2944 | ui_out_field_string (uiout, "signal-name", |
2945 | target_signal_to_name (stop_info)); | |
8b93c638 JM |
2946 | annotate_signal_name_end (); |
2947 | ui_out_text (uiout, ", "); | |
2948 | annotate_signal_string (); | |
488f131b JB |
2949 | ui_out_field_string (uiout, "signal-meaning", |
2950 | target_signal_to_string (stop_info)); | |
8b93c638 JM |
2951 | annotate_signal_string_end (); |
2952 | ui_out_text (uiout, ".\n"); | |
2953 | ui_out_text (uiout, "The program no longer exists.\n"); | |
11cf8741 JM |
2954 | break; |
2955 | case EXITED: | |
2956 | /* The inferior program is finished. */ | |
8b93c638 JM |
2957 | annotate_exited (stop_info); |
2958 | if (stop_info) | |
2959 | { | |
9dc5e2a9 | 2960 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2961 | ui_out_field_string (uiout, "reason", "exited"); |
8b93c638 | 2962 | ui_out_text (uiout, "\nProgram exited with code "); |
488f131b JB |
2963 | ui_out_field_fmt (uiout, "exit-code", "0%o", |
2964 | (unsigned int) stop_info); | |
8b93c638 JM |
2965 | ui_out_text (uiout, ".\n"); |
2966 | } | |
2967 | else | |
2968 | { | |
9dc5e2a9 | 2969 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 2970 | ui_out_field_string (uiout, "reason", "exited-normally"); |
8b93c638 JM |
2971 | ui_out_text (uiout, "\nProgram exited normally.\n"); |
2972 | } | |
11cf8741 JM |
2973 | break; |
2974 | case SIGNAL_RECEIVED: | |
2975 | /* Signal received. The signal table tells us to print about | |
2976 | it. */ | |
8b93c638 JM |
2977 | annotate_signal (); |
2978 | ui_out_text (uiout, "\nProgram received signal "); | |
2979 | annotate_signal_name (); | |
84c6c83c KS |
2980 | if (ui_out_is_mi_like_p (uiout)) |
2981 | ui_out_field_string (uiout, "reason", "signal-received"); | |
488f131b JB |
2982 | ui_out_field_string (uiout, "signal-name", |
2983 | target_signal_to_name (stop_info)); | |
8b93c638 JM |
2984 | annotate_signal_name_end (); |
2985 | ui_out_text (uiout, ", "); | |
2986 | annotate_signal_string (); | |
488f131b JB |
2987 | ui_out_field_string (uiout, "signal-meaning", |
2988 | target_signal_to_string (stop_info)); | |
8b93c638 JM |
2989 | annotate_signal_string_end (); |
2990 | ui_out_text (uiout, ".\n"); | |
11cf8741 JM |
2991 | break; |
2992 | default: | |
8e65ff28 AC |
2993 | internal_error (__FILE__, __LINE__, |
2994 | "print_stop_reason: unrecognized enum value"); | |
11cf8741 JM |
2995 | break; |
2996 | } | |
2997 | } | |
c906108c | 2998 | \f |
43ff13b4 | 2999 | |
c906108c SS |
3000 | /* Here to return control to GDB when the inferior stops for real. |
3001 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
3002 | ||
3003 | STOP_PRINT_FRAME nonzero means print the executing frame | |
3004 | (pc, function, args, file, line number and line text). | |
3005 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
3006 | attempting to insert breakpoints. */ | |
3007 | ||
3008 | void | |
96baa820 | 3009 | normal_stop (void) |
c906108c | 3010 | { |
c906108c SS |
3011 | /* As with the notification of thread events, we want to delay |
3012 | notifying the user that we've switched thread context until | |
3013 | the inferior actually stops. | |
3014 | ||
3015 | (Note that there's no point in saying anything if the inferior | |
3016 | has exited!) */ | |
488f131b | 3017 | if (!ptid_equal (previous_inferior_ptid, inferior_ptid) |
7a292a7a | 3018 | && target_has_execution) |
c906108c SS |
3019 | { |
3020 | target_terminal_ours_for_output (); | |
c3f6f71d | 3021 | printf_filtered ("[Switching to %s]\n", |
39f77062 KB |
3022 | target_pid_or_tid_to_str (inferior_ptid)); |
3023 | previous_inferior_ptid = inferior_ptid; | |
c906108c | 3024 | } |
c906108c SS |
3025 | |
3026 | /* Make sure that the current_frame's pc is correct. This | |
3027 | is a correction for setting up the frame info before doing | |
3028 | DECR_PC_AFTER_BREAK */ | |
b87efeee AC |
3029 | if (target_has_execution) |
3030 | /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to | |
3031 | DECR_PC_AFTER_BREAK, the program counter can change. Ask the | |
3032 | frame code to check for this and sort out any resultant mess. | |
3033 | DECR_PC_AFTER_BREAK needs to just go away. */ | |
2f107107 | 3034 | deprecated_update_frame_pc_hack (get_current_frame (), read_pc ()); |
c906108c | 3035 | |
c906108c SS |
3036 | if (target_has_execution && breakpoints_inserted) |
3037 | { | |
3038 | if (remove_breakpoints ()) | |
3039 | { | |
3040 | target_terminal_ours_for_output (); | |
3041 | printf_filtered ("Cannot remove breakpoints because "); | |
3042 | printf_filtered ("program is no longer writable.\n"); | |
3043 | printf_filtered ("It might be running in another process.\n"); | |
3044 | printf_filtered ("Further execution is probably impossible.\n"); | |
3045 | } | |
3046 | } | |
3047 | breakpoints_inserted = 0; | |
3048 | ||
3049 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
3050 | Delete any breakpoint that is to be deleted at the next stop. */ | |
3051 | ||
3052 | breakpoint_auto_delete (stop_bpstat); | |
3053 | ||
3054 | /* If an auto-display called a function and that got a signal, | |
3055 | delete that auto-display to avoid an infinite recursion. */ | |
3056 | ||
3057 | if (stopped_by_random_signal) | |
3058 | disable_current_display (); | |
3059 | ||
3060 | /* Don't print a message if in the middle of doing a "step n" | |
3061 | operation for n > 1 */ | |
3062 | if (step_multi && stop_step) | |
3063 | goto done; | |
3064 | ||
3065 | target_terminal_ours (); | |
3066 | ||
5913bcb0 AC |
3067 | /* Look up the hook_stop and run it (CLI internally handles problem |
3068 | of stop_command's pre-hook not existing). */ | |
3069 | if (stop_command) | |
3070 | catch_errors (hook_stop_stub, stop_command, | |
3071 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
c906108c SS |
3072 | |
3073 | if (!target_has_stack) | |
3074 | { | |
3075 | ||
3076 | goto done; | |
3077 | } | |
3078 | ||
3079 | /* Select innermost stack frame - i.e., current frame is frame 0, | |
3080 | and current location is based on that. | |
3081 | Don't do this on return from a stack dummy routine, | |
3082 | or if the program has exited. */ | |
3083 | ||
3084 | if (!stop_stack_dummy) | |
3085 | { | |
0f7d239c | 3086 | select_frame (get_current_frame ()); |
c906108c SS |
3087 | |
3088 | /* Print current location without a level number, if | |
c5aa993b JM |
3089 | we have changed functions or hit a breakpoint. |
3090 | Print source line if we have one. | |
3091 | bpstat_print() contains the logic deciding in detail | |
3092 | what to print, based on the event(s) that just occurred. */ | |
c906108c | 3093 | |
6e7f8b9c | 3094 | if (stop_print_frame && deprecated_selected_frame) |
c906108c SS |
3095 | { |
3096 | int bpstat_ret; | |
3097 | int source_flag; | |
917317f4 | 3098 | int do_frame_printing = 1; |
c906108c SS |
3099 | |
3100 | bpstat_ret = bpstat_print (stop_bpstat); | |
917317f4 JM |
3101 | switch (bpstat_ret) |
3102 | { | |
3103 | case PRINT_UNKNOWN: | |
aa0cd9c1 AC |
3104 | /* FIXME: cagney/2002-12-01: Given that a frame ID does |
3105 | (or should) carry around the function and does (or | |
3106 | should) use that when doing a frame comparison. */ | |
917317f4 | 3107 | if (stop_step |
aa0cd9c1 AC |
3108 | && frame_id_eq (step_frame_id, |
3109 | get_frame_id (get_current_frame ())) | |
917317f4 | 3110 | && step_start_function == find_pc_function (stop_pc)) |
488f131b | 3111 | source_flag = SRC_LINE; /* finished step, just print source line */ |
917317f4 | 3112 | else |
488f131b | 3113 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3114 | break; |
3115 | case PRINT_SRC_AND_LOC: | |
488f131b | 3116 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3117 | break; |
3118 | case PRINT_SRC_ONLY: | |
c5394b80 | 3119 | source_flag = SRC_LINE; |
917317f4 JM |
3120 | break; |
3121 | case PRINT_NOTHING: | |
488f131b | 3122 | source_flag = SRC_LINE; /* something bogus */ |
917317f4 JM |
3123 | do_frame_printing = 0; |
3124 | break; | |
3125 | default: | |
488f131b | 3126 | internal_error (__FILE__, __LINE__, "Unknown value."); |
917317f4 | 3127 | } |
fb40c209 | 3128 | /* For mi, have the same behavior every time we stop: |
488f131b | 3129 | print everything but the source line. */ |
9dc5e2a9 | 3130 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 3131 | source_flag = LOC_AND_ADDRESS; |
c906108c | 3132 | |
9dc5e2a9 | 3133 | if (ui_out_is_mi_like_p (uiout)) |
39f77062 | 3134 | ui_out_field_int (uiout, "thread-id", |
488f131b | 3135 | pid_to_thread_id (inferior_ptid)); |
c906108c SS |
3136 | /* The behavior of this routine with respect to the source |
3137 | flag is: | |
c5394b80 JM |
3138 | SRC_LINE: Print only source line |
3139 | LOCATION: Print only location | |
3140 | SRC_AND_LOC: Print location and source line */ | |
917317f4 | 3141 | if (do_frame_printing) |
7789c6f5 | 3142 | print_stack_frame (deprecated_selected_frame, -1, source_flag); |
c906108c SS |
3143 | |
3144 | /* Display the auto-display expressions. */ | |
3145 | do_displays (); | |
3146 | } | |
3147 | } | |
3148 | ||
3149 | /* Save the function value return registers, if we care. | |
3150 | We might be about to restore their previous contents. */ | |
3151 | if (proceed_to_finish) | |
72cec141 AC |
3152 | /* NB: The copy goes through to the target picking up the value of |
3153 | all the registers. */ | |
3154 | regcache_cpy (stop_registers, current_regcache); | |
c906108c SS |
3155 | |
3156 | if (stop_stack_dummy) | |
3157 | { | |
dbe9fe58 AC |
3158 | /* Pop the empty frame that contains the stack dummy. POP_FRAME |
3159 | ends with a setting of the current frame, so we can use that | |
3160 | next. */ | |
3161 | frame_pop (get_current_frame ()); | |
c906108c | 3162 | /* Set stop_pc to what it was before we called the function. |
c5aa993b JM |
3163 | Can't rely on restore_inferior_status because that only gets |
3164 | called if we don't stop in the called function. */ | |
c906108c | 3165 | stop_pc = read_pc (); |
0f7d239c | 3166 | select_frame (get_current_frame ()); |
c906108c SS |
3167 | } |
3168 | ||
c906108c SS |
3169 | done: |
3170 | annotate_stopped (); | |
06600e06 | 3171 | observer_notify_normal_stop (); |
c906108c SS |
3172 | } |
3173 | ||
3174 | static int | |
96baa820 | 3175 | hook_stop_stub (void *cmd) |
c906108c | 3176 | { |
5913bcb0 | 3177 | execute_cmd_pre_hook ((struct cmd_list_element *) cmd); |
c906108c SS |
3178 | return (0); |
3179 | } | |
3180 | \f | |
c5aa993b | 3181 | int |
96baa820 | 3182 | signal_stop_state (int signo) |
c906108c SS |
3183 | { |
3184 | return signal_stop[signo]; | |
3185 | } | |
3186 | ||
c5aa993b | 3187 | int |
96baa820 | 3188 | signal_print_state (int signo) |
c906108c SS |
3189 | { |
3190 | return signal_print[signo]; | |
3191 | } | |
3192 | ||
c5aa993b | 3193 | int |
96baa820 | 3194 | signal_pass_state (int signo) |
c906108c SS |
3195 | { |
3196 | return signal_program[signo]; | |
3197 | } | |
3198 | ||
488f131b | 3199 | int |
7bda5e4a | 3200 | signal_stop_update (int signo, int state) |
d4f3574e SS |
3201 | { |
3202 | int ret = signal_stop[signo]; | |
3203 | signal_stop[signo] = state; | |
3204 | return ret; | |
3205 | } | |
3206 | ||
488f131b | 3207 | int |
7bda5e4a | 3208 | signal_print_update (int signo, int state) |
d4f3574e SS |
3209 | { |
3210 | int ret = signal_print[signo]; | |
3211 | signal_print[signo] = state; | |
3212 | return ret; | |
3213 | } | |
3214 | ||
488f131b | 3215 | int |
7bda5e4a | 3216 | signal_pass_update (int signo, int state) |
d4f3574e SS |
3217 | { |
3218 | int ret = signal_program[signo]; | |
3219 | signal_program[signo] = state; | |
3220 | return ret; | |
3221 | } | |
3222 | ||
c906108c | 3223 | static void |
96baa820 | 3224 | sig_print_header (void) |
c906108c SS |
3225 | { |
3226 | printf_filtered ("\ | |
3227 | Signal Stop\tPrint\tPass to program\tDescription\n"); | |
3228 | } | |
3229 | ||
3230 | static void | |
96baa820 | 3231 | sig_print_info (enum target_signal oursig) |
c906108c SS |
3232 | { |
3233 | char *name = target_signal_to_name (oursig); | |
3234 | int name_padding = 13 - strlen (name); | |
96baa820 | 3235 | |
c906108c SS |
3236 | if (name_padding <= 0) |
3237 | name_padding = 0; | |
3238 | ||
3239 | printf_filtered ("%s", name); | |
488f131b | 3240 | printf_filtered ("%*.*s ", name_padding, name_padding, " "); |
c906108c SS |
3241 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
3242 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
3243 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
3244 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
3245 | } | |
3246 | ||
3247 | /* Specify how various signals in the inferior should be handled. */ | |
3248 | ||
3249 | static void | |
96baa820 | 3250 | handle_command (char *args, int from_tty) |
c906108c SS |
3251 | { |
3252 | char **argv; | |
3253 | int digits, wordlen; | |
3254 | int sigfirst, signum, siglast; | |
3255 | enum target_signal oursig; | |
3256 | int allsigs; | |
3257 | int nsigs; | |
3258 | unsigned char *sigs; | |
3259 | struct cleanup *old_chain; | |
3260 | ||
3261 | if (args == NULL) | |
3262 | { | |
3263 | error_no_arg ("signal to handle"); | |
3264 | } | |
3265 | ||
3266 | /* Allocate and zero an array of flags for which signals to handle. */ | |
3267 | ||
3268 | nsigs = (int) TARGET_SIGNAL_LAST; | |
3269 | sigs = (unsigned char *) alloca (nsigs); | |
3270 | memset (sigs, 0, nsigs); | |
3271 | ||
3272 | /* Break the command line up into args. */ | |
3273 | ||
3274 | argv = buildargv (args); | |
3275 | if (argv == NULL) | |
3276 | { | |
3277 | nomem (0); | |
3278 | } | |
7a292a7a | 3279 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3280 | |
3281 | /* Walk through the args, looking for signal oursigs, signal names, and | |
3282 | actions. Signal numbers and signal names may be interspersed with | |
3283 | actions, with the actions being performed for all signals cumulatively | |
3284 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
3285 | ||
3286 | while (*argv != NULL) | |
3287 | { | |
3288 | wordlen = strlen (*argv); | |
3289 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
3290 | {; | |
3291 | } | |
3292 | allsigs = 0; | |
3293 | sigfirst = siglast = -1; | |
3294 | ||
3295 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
3296 | { | |
3297 | /* Apply action to all signals except those used by the | |
3298 | debugger. Silently skip those. */ | |
3299 | allsigs = 1; | |
3300 | sigfirst = 0; | |
3301 | siglast = nsigs - 1; | |
3302 | } | |
3303 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
3304 | { | |
3305 | SET_SIGS (nsigs, sigs, signal_stop); | |
3306 | SET_SIGS (nsigs, sigs, signal_print); | |
3307 | } | |
3308 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
3309 | { | |
3310 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3311 | } | |
3312 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
3313 | { | |
3314 | SET_SIGS (nsigs, sigs, signal_print); | |
3315 | } | |
3316 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
3317 | { | |
3318 | SET_SIGS (nsigs, sigs, signal_program); | |
3319 | } | |
3320 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
3321 | { | |
3322 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3323 | } | |
3324 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
3325 | { | |
3326 | SET_SIGS (nsigs, sigs, signal_program); | |
3327 | } | |
3328 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
3329 | { | |
3330 | UNSET_SIGS (nsigs, sigs, signal_print); | |
3331 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3332 | } | |
3333 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
3334 | { | |
3335 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3336 | } | |
3337 | else if (digits > 0) | |
3338 | { | |
3339 | /* It is numeric. The numeric signal refers to our own | |
3340 | internal signal numbering from target.h, not to host/target | |
3341 | signal number. This is a feature; users really should be | |
3342 | using symbolic names anyway, and the common ones like | |
3343 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
3344 | ||
3345 | sigfirst = siglast = (int) | |
3346 | target_signal_from_command (atoi (*argv)); | |
3347 | if ((*argv)[digits] == '-') | |
3348 | { | |
3349 | siglast = (int) | |
3350 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
3351 | } | |
3352 | if (sigfirst > siglast) | |
3353 | { | |
3354 | /* Bet he didn't figure we'd think of this case... */ | |
3355 | signum = sigfirst; | |
3356 | sigfirst = siglast; | |
3357 | siglast = signum; | |
3358 | } | |
3359 | } | |
3360 | else | |
3361 | { | |
3362 | oursig = target_signal_from_name (*argv); | |
3363 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
3364 | { | |
3365 | sigfirst = siglast = (int) oursig; | |
3366 | } | |
3367 | else | |
3368 | { | |
3369 | /* Not a number and not a recognized flag word => complain. */ | |
3370 | error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); | |
3371 | } | |
3372 | } | |
3373 | ||
3374 | /* If any signal numbers or symbol names were found, set flags for | |
c5aa993b | 3375 | which signals to apply actions to. */ |
c906108c SS |
3376 | |
3377 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
3378 | { | |
3379 | switch ((enum target_signal) signum) | |
3380 | { | |
3381 | case TARGET_SIGNAL_TRAP: | |
3382 | case TARGET_SIGNAL_INT: | |
3383 | if (!allsigs && !sigs[signum]) | |
3384 | { | |
3385 | if (query ("%s is used by the debugger.\n\ | |
488f131b | 3386 | Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum))) |
c906108c SS |
3387 | { |
3388 | sigs[signum] = 1; | |
3389 | } | |
3390 | else | |
3391 | { | |
3392 | printf_unfiltered ("Not confirmed, unchanged.\n"); | |
3393 | gdb_flush (gdb_stdout); | |
3394 | } | |
3395 | } | |
3396 | break; | |
3397 | case TARGET_SIGNAL_0: | |
3398 | case TARGET_SIGNAL_DEFAULT: | |
3399 | case TARGET_SIGNAL_UNKNOWN: | |
3400 | /* Make sure that "all" doesn't print these. */ | |
3401 | break; | |
3402 | default: | |
3403 | sigs[signum] = 1; | |
3404 | break; | |
3405 | } | |
3406 | } | |
3407 | ||
3408 | argv++; | |
3409 | } | |
3410 | ||
39f77062 | 3411 | target_notice_signals (inferior_ptid); |
c906108c SS |
3412 | |
3413 | if (from_tty) | |
3414 | { | |
3415 | /* Show the results. */ | |
3416 | sig_print_header (); | |
3417 | for (signum = 0; signum < nsigs; signum++) | |
3418 | { | |
3419 | if (sigs[signum]) | |
3420 | { | |
3421 | sig_print_info (signum); | |
3422 | } | |
3423 | } | |
3424 | } | |
3425 | ||
3426 | do_cleanups (old_chain); | |
3427 | } | |
3428 | ||
3429 | static void | |
96baa820 | 3430 | xdb_handle_command (char *args, int from_tty) |
c906108c SS |
3431 | { |
3432 | char **argv; | |
3433 | struct cleanup *old_chain; | |
3434 | ||
3435 | /* Break the command line up into args. */ | |
3436 | ||
3437 | argv = buildargv (args); | |
3438 | if (argv == NULL) | |
3439 | { | |
3440 | nomem (0); | |
3441 | } | |
7a292a7a | 3442 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3443 | if (argv[1] != (char *) NULL) |
3444 | { | |
3445 | char *argBuf; | |
3446 | int bufLen; | |
3447 | ||
3448 | bufLen = strlen (argv[0]) + 20; | |
3449 | argBuf = (char *) xmalloc (bufLen); | |
3450 | if (argBuf) | |
3451 | { | |
3452 | int validFlag = 1; | |
3453 | enum target_signal oursig; | |
3454 | ||
3455 | oursig = target_signal_from_name (argv[0]); | |
3456 | memset (argBuf, 0, bufLen); | |
3457 | if (strcmp (argv[1], "Q") == 0) | |
3458 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3459 | else | |
3460 | { | |
3461 | if (strcmp (argv[1], "s") == 0) | |
3462 | { | |
3463 | if (!signal_stop[oursig]) | |
3464 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
3465 | else | |
3466 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
3467 | } | |
3468 | else if (strcmp (argv[1], "i") == 0) | |
3469 | { | |
3470 | if (!signal_program[oursig]) | |
3471 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
3472 | else | |
3473 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
3474 | } | |
3475 | else if (strcmp (argv[1], "r") == 0) | |
3476 | { | |
3477 | if (!signal_print[oursig]) | |
3478 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
3479 | else | |
3480 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3481 | } | |
3482 | else | |
3483 | validFlag = 0; | |
3484 | } | |
3485 | if (validFlag) | |
3486 | handle_command (argBuf, from_tty); | |
3487 | else | |
3488 | printf_filtered ("Invalid signal handling flag.\n"); | |
3489 | if (argBuf) | |
b8c9b27d | 3490 | xfree (argBuf); |
c906108c SS |
3491 | } |
3492 | } | |
3493 | do_cleanups (old_chain); | |
3494 | } | |
3495 | ||
3496 | /* Print current contents of the tables set by the handle command. | |
3497 | It is possible we should just be printing signals actually used | |
3498 | by the current target (but for things to work right when switching | |
3499 | targets, all signals should be in the signal tables). */ | |
3500 | ||
3501 | static void | |
96baa820 | 3502 | signals_info (char *signum_exp, int from_tty) |
c906108c SS |
3503 | { |
3504 | enum target_signal oursig; | |
3505 | sig_print_header (); | |
3506 | ||
3507 | if (signum_exp) | |
3508 | { | |
3509 | /* First see if this is a symbol name. */ | |
3510 | oursig = target_signal_from_name (signum_exp); | |
3511 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
3512 | { | |
3513 | /* No, try numeric. */ | |
3514 | oursig = | |
bb518678 | 3515 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
c906108c SS |
3516 | } |
3517 | sig_print_info (oursig); | |
3518 | return; | |
3519 | } | |
3520 | ||
3521 | printf_filtered ("\n"); | |
3522 | /* These ugly casts brought to you by the native VAX compiler. */ | |
3523 | for (oursig = TARGET_SIGNAL_FIRST; | |
3524 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
3525 | oursig = (enum target_signal) ((int) oursig + 1)) | |
3526 | { | |
3527 | QUIT; | |
3528 | ||
3529 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
488f131b | 3530 | && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) |
c906108c SS |
3531 | sig_print_info (oursig); |
3532 | } | |
3533 | ||
3534 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); | |
3535 | } | |
3536 | \f | |
7a292a7a SS |
3537 | struct inferior_status |
3538 | { | |
3539 | enum target_signal stop_signal; | |
3540 | CORE_ADDR stop_pc; | |
3541 | bpstat stop_bpstat; | |
3542 | int stop_step; | |
3543 | int stop_stack_dummy; | |
3544 | int stopped_by_random_signal; | |
3545 | int trap_expected; | |
3546 | CORE_ADDR step_range_start; | |
3547 | CORE_ADDR step_range_end; | |
aa0cd9c1 | 3548 | struct frame_id step_frame_id; |
5fbbeb29 | 3549 | enum step_over_calls_kind step_over_calls; |
7a292a7a SS |
3550 | CORE_ADDR step_resume_break_address; |
3551 | int stop_after_trap; | |
c0236d92 | 3552 | int stop_soon; |
72cec141 | 3553 | struct regcache *stop_registers; |
7a292a7a SS |
3554 | |
3555 | /* These are here because if call_function_by_hand has written some | |
3556 | registers and then decides to call error(), we better not have changed | |
3557 | any registers. */ | |
72cec141 | 3558 | struct regcache *registers; |
7a292a7a | 3559 | |
101dcfbe AC |
3560 | /* A frame unique identifier. */ |
3561 | struct frame_id selected_frame_id; | |
3562 | ||
7a292a7a SS |
3563 | int breakpoint_proceeded; |
3564 | int restore_stack_info; | |
3565 | int proceed_to_finish; | |
3566 | }; | |
3567 | ||
7a292a7a | 3568 | void |
96baa820 JM |
3569 | write_inferior_status_register (struct inferior_status *inf_status, int regno, |
3570 | LONGEST val) | |
7a292a7a | 3571 | { |
c5aa993b | 3572 | int size = REGISTER_RAW_SIZE (regno); |
7a292a7a SS |
3573 | void *buf = alloca (size); |
3574 | store_signed_integer (buf, size, val); | |
0818c12a | 3575 | regcache_raw_write (inf_status->registers, regno, buf); |
7a292a7a SS |
3576 | } |
3577 | ||
c906108c SS |
3578 | /* Save all of the information associated with the inferior<==>gdb |
3579 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
3580 | (defined in inferior.h). */ | |
3581 | ||
7a292a7a | 3582 | struct inferior_status * |
96baa820 | 3583 | save_inferior_status (int restore_stack_info) |
c906108c | 3584 | { |
72cec141 | 3585 | struct inferior_status *inf_status = XMALLOC (struct inferior_status); |
7a292a7a | 3586 | |
c906108c SS |
3587 | inf_status->stop_signal = stop_signal; |
3588 | inf_status->stop_pc = stop_pc; | |
3589 | inf_status->stop_step = stop_step; | |
3590 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
3591 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
3592 | inf_status->trap_expected = trap_expected; | |
3593 | inf_status->step_range_start = step_range_start; | |
3594 | inf_status->step_range_end = step_range_end; | |
aa0cd9c1 | 3595 | inf_status->step_frame_id = step_frame_id; |
c906108c SS |
3596 | inf_status->step_over_calls = step_over_calls; |
3597 | inf_status->stop_after_trap = stop_after_trap; | |
c0236d92 | 3598 | inf_status->stop_soon = stop_soon; |
c906108c SS |
3599 | /* Save original bpstat chain here; replace it with copy of chain. |
3600 | If caller's caller is walking the chain, they'll be happier if we | |
7a292a7a SS |
3601 | hand them back the original chain when restore_inferior_status is |
3602 | called. */ | |
c906108c SS |
3603 | inf_status->stop_bpstat = stop_bpstat; |
3604 | stop_bpstat = bpstat_copy (stop_bpstat); | |
3605 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
3606 | inf_status->restore_stack_info = restore_stack_info; | |
3607 | inf_status->proceed_to_finish = proceed_to_finish; | |
c5aa993b | 3608 | |
72cec141 | 3609 | inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers); |
c906108c | 3610 | |
72cec141 | 3611 | inf_status->registers = regcache_dup (current_regcache); |
c906108c | 3612 | |
7a424e99 | 3613 | inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame); |
7a292a7a | 3614 | return inf_status; |
c906108c SS |
3615 | } |
3616 | ||
c906108c | 3617 | static int |
96baa820 | 3618 | restore_selected_frame (void *args) |
c906108c | 3619 | { |
488f131b | 3620 | struct frame_id *fid = (struct frame_id *) args; |
c906108c | 3621 | struct frame_info *frame; |
c906108c | 3622 | |
101dcfbe | 3623 | frame = frame_find_by_id (*fid); |
c906108c | 3624 | |
aa0cd9c1 AC |
3625 | /* If inf_status->selected_frame_id is NULL, there was no previously |
3626 | selected frame. */ | |
101dcfbe | 3627 | if (frame == NULL) |
c906108c SS |
3628 | { |
3629 | warning ("Unable to restore previously selected frame.\n"); | |
3630 | return 0; | |
3631 | } | |
3632 | ||
0f7d239c | 3633 | select_frame (frame); |
c906108c SS |
3634 | |
3635 | return (1); | |
3636 | } | |
3637 | ||
3638 | void | |
96baa820 | 3639 | restore_inferior_status (struct inferior_status *inf_status) |
c906108c SS |
3640 | { |
3641 | stop_signal = inf_status->stop_signal; | |
3642 | stop_pc = inf_status->stop_pc; | |
3643 | stop_step = inf_status->stop_step; | |
3644 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
3645 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
3646 | trap_expected = inf_status->trap_expected; | |
3647 | step_range_start = inf_status->step_range_start; | |
3648 | step_range_end = inf_status->step_range_end; | |
aa0cd9c1 | 3649 | step_frame_id = inf_status->step_frame_id; |
c906108c SS |
3650 | step_over_calls = inf_status->step_over_calls; |
3651 | stop_after_trap = inf_status->stop_after_trap; | |
c0236d92 | 3652 | stop_soon = inf_status->stop_soon; |
c906108c SS |
3653 | bpstat_clear (&stop_bpstat); |
3654 | stop_bpstat = inf_status->stop_bpstat; | |
3655 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
3656 | proceed_to_finish = inf_status->proceed_to_finish; | |
3657 | ||
72cec141 AC |
3658 | /* FIXME: Is the restore of stop_registers always needed. */ |
3659 | regcache_xfree (stop_registers); | |
3660 | stop_registers = inf_status->stop_registers; | |
c906108c SS |
3661 | |
3662 | /* The inferior can be gone if the user types "print exit(0)" | |
3663 | (and perhaps other times). */ | |
3664 | if (target_has_execution) | |
72cec141 AC |
3665 | /* NB: The register write goes through to the target. */ |
3666 | regcache_cpy (current_regcache, inf_status->registers); | |
3667 | regcache_xfree (inf_status->registers); | |
c906108c | 3668 | |
c906108c SS |
3669 | /* FIXME: If we are being called after stopping in a function which |
3670 | is called from gdb, we should not be trying to restore the | |
3671 | selected frame; it just prints a spurious error message (The | |
3672 | message is useful, however, in detecting bugs in gdb (like if gdb | |
3673 | clobbers the stack)). In fact, should we be restoring the | |
3674 | inferior status at all in that case? . */ | |
3675 | ||
3676 | if (target_has_stack && inf_status->restore_stack_info) | |
3677 | { | |
c906108c | 3678 | /* The point of catch_errors is that if the stack is clobbered, |
101dcfbe AC |
3679 | walking the stack might encounter a garbage pointer and |
3680 | error() trying to dereference it. */ | |
488f131b JB |
3681 | if (catch_errors |
3682 | (restore_selected_frame, &inf_status->selected_frame_id, | |
3683 | "Unable to restore previously selected frame:\n", | |
3684 | RETURN_MASK_ERROR) == 0) | |
c906108c SS |
3685 | /* Error in restoring the selected frame. Select the innermost |
3686 | frame. */ | |
0f7d239c | 3687 | select_frame (get_current_frame ()); |
c906108c SS |
3688 | |
3689 | } | |
c906108c | 3690 | |
72cec141 | 3691 | xfree (inf_status); |
7a292a7a | 3692 | } |
c906108c | 3693 | |
74b7792f AC |
3694 | static void |
3695 | do_restore_inferior_status_cleanup (void *sts) | |
3696 | { | |
3697 | restore_inferior_status (sts); | |
3698 | } | |
3699 | ||
3700 | struct cleanup * | |
3701 | make_cleanup_restore_inferior_status (struct inferior_status *inf_status) | |
3702 | { | |
3703 | return make_cleanup (do_restore_inferior_status_cleanup, inf_status); | |
3704 | } | |
3705 | ||
c906108c | 3706 | void |
96baa820 | 3707 | discard_inferior_status (struct inferior_status *inf_status) |
7a292a7a SS |
3708 | { |
3709 | /* See save_inferior_status for info on stop_bpstat. */ | |
3710 | bpstat_clear (&inf_status->stop_bpstat); | |
72cec141 AC |
3711 | regcache_xfree (inf_status->registers); |
3712 | regcache_xfree (inf_status->stop_registers); | |
3713 | xfree (inf_status); | |
7a292a7a SS |
3714 | } |
3715 | ||
47932f85 DJ |
3716 | int |
3717 | inferior_has_forked (int pid, int *child_pid) | |
3718 | { | |
3719 | struct target_waitstatus last; | |
3720 | ptid_t last_ptid; | |
3721 | ||
3722 | get_last_target_status (&last_ptid, &last); | |
3723 | ||
3724 | if (last.kind != TARGET_WAITKIND_FORKED) | |
3725 | return 0; | |
3726 | ||
3727 | if (ptid_get_pid (last_ptid) != pid) | |
3728 | return 0; | |
3729 | ||
3730 | *child_pid = last.value.related_pid; | |
3731 | return 1; | |
3732 | } | |
3733 | ||
3734 | int | |
3735 | inferior_has_vforked (int pid, int *child_pid) | |
3736 | { | |
3737 | struct target_waitstatus last; | |
3738 | ptid_t last_ptid; | |
3739 | ||
3740 | get_last_target_status (&last_ptid, &last); | |
3741 | ||
3742 | if (last.kind != TARGET_WAITKIND_VFORKED) | |
3743 | return 0; | |
3744 | ||
3745 | if (ptid_get_pid (last_ptid) != pid) | |
3746 | return 0; | |
3747 | ||
3748 | *child_pid = last.value.related_pid; | |
3749 | return 1; | |
3750 | } | |
3751 | ||
3752 | int | |
3753 | inferior_has_execd (int pid, char **execd_pathname) | |
3754 | { | |
3755 | struct target_waitstatus last; | |
3756 | ptid_t last_ptid; | |
3757 | ||
3758 | get_last_target_status (&last_ptid, &last); | |
3759 | ||
3760 | if (last.kind != TARGET_WAITKIND_EXECD) | |
3761 | return 0; | |
3762 | ||
3763 | if (ptid_get_pid (last_ptid) != pid) | |
3764 | return 0; | |
3765 | ||
3766 | *execd_pathname = xstrdup (last.value.execd_pathname); | |
3767 | return 1; | |
3768 | } | |
3769 | ||
ca6724c1 KB |
3770 | /* Oft used ptids */ |
3771 | ptid_t null_ptid; | |
3772 | ptid_t minus_one_ptid; | |
3773 | ||
3774 | /* Create a ptid given the necessary PID, LWP, and TID components. */ | |
488f131b | 3775 | |
ca6724c1 KB |
3776 | ptid_t |
3777 | ptid_build (int pid, long lwp, long tid) | |
3778 | { | |
3779 | ptid_t ptid; | |
3780 | ||
3781 | ptid.pid = pid; | |
3782 | ptid.lwp = lwp; | |
3783 | ptid.tid = tid; | |
3784 | return ptid; | |
3785 | } | |
3786 | ||
3787 | /* Create a ptid from just a pid. */ | |
3788 | ||
3789 | ptid_t | |
3790 | pid_to_ptid (int pid) | |
3791 | { | |
3792 | return ptid_build (pid, 0, 0); | |
3793 | } | |
3794 | ||
3795 | /* Fetch the pid (process id) component from a ptid. */ | |
3796 | ||
3797 | int | |
3798 | ptid_get_pid (ptid_t ptid) | |
3799 | { | |
3800 | return ptid.pid; | |
3801 | } | |
3802 | ||
3803 | /* Fetch the lwp (lightweight process) component from a ptid. */ | |
3804 | ||
3805 | long | |
3806 | ptid_get_lwp (ptid_t ptid) | |
3807 | { | |
3808 | return ptid.lwp; | |
3809 | } | |
3810 | ||
3811 | /* Fetch the tid (thread id) component from a ptid. */ | |
3812 | ||
3813 | long | |
3814 | ptid_get_tid (ptid_t ptid) | |
3815 | { | |
3816 | return ptid.tid; | |
3817 | } | |
3818 | ||
3819 | /* ptid_equal() is used to test equality of two ptids. */ | |
3820 | ||
3821 | int | |
3822 | ptid_equal (ptid_t ptid1, ptid_t ptid2) | |
3823 | { | |
3824 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp | |
488f131b | 3825 | && ptid1.tid == ptid2.tid); |
ca6724c1 KB |
3826 | } |
3827 | ||
3828 | /* restore_inferior_ptid() will be used by the cleanup machinery | |
3829 | to restore the inferior_ptid value saved in a call to | |
3830 | save_inferior_ptid(). */ | |
ce696e05 KB |
3831 | |
3832 | static void | |
3833 | restore_inferior_ptid (void *arg) | |
3834 | { | |
3835 | ptid_t *saved_ptid_ptr = arg; | |
3836 | inferior_ptid = *saved_ptid_ptr; | |
3837 | xfree (arg); | |
3838 | } | |
3839 | ||
3840 | /* Save the value of inferior_ptid so that it may be restored by a | |
3841 | later call to do_cleanups(). Returns the struct cleanup pointer | |
3842 | needed for later doing the cleanup. */ | |
3843 | ||
3844 | struct cleanup * | |
3845 | save_inferior_ptid (void) | |
3846 | { | |
3847 | ptid_t *saved_ptid_ptr; | |
3848 | ||
3849 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); | |
3850 | *saved_ptid_ptr = inferior_ptid; | |
3851 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); | |
3852 | } | |
c5aa993b | 3853 | \f |
488f131b | 3854 | |
7a292a7a | 3855 | static void |
96baa820 | 3856 | build_infrun (void) |
7a292a7a | 3857 | { |
72cec141 | 3858 | stop_registers = regcache_xmalloc (current_gdbarch); |
7a292a7a | 3859 | } |
c906108c | 3860 | |
c906108c | 3861 | void |
96baa820 | 3862 | _initialize_infrun (void) |
c906108c SS |
3863 | { |
3864 | register int i; | |
3865 | register int numsigs; | |
3866 | struct cmd_list_element *c; | |
3867 | ||
0f71a2f6 JM |
3868 | register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL); |
3869 | register_gdbarch_swap (NULL, 0, build_infrun); | |
3870 | ||
c906108c SS |
3871 | add_info ("signals", signals_info, |
3872 | "What debugger does when program gets various signals.\n\ | |
3873 | Specify a signal as argument to print info on that signal only."); | |
3874 | add_info_alias ("handle", "signals", 0); | |
3875 | ||
3876 | add_com ("handle", class_run, handle_command, | |
3877 | concat ("Specify how to handle a signal.\n\ | |
3878 | Args are signals and actions to apply to those signals.\n\ | |
3879 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
3880 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
3881 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
3882 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
488f131b | 3883 | used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ |
c906108c SS |
3884 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
3885 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
3886 | Print means print a message if this signal happens.\n\ | |
3887 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
3888 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
3889 | Pass and Stop may be combined.", NULL)); | |
3890 | if (xdb_commands) | |
3891 | { | |
3892 | add_com ("lz", class_info, signals_info, | |
3893 | "What debugger does when program gets various signals.\n\ | |
3894 | Specify a signal as argument to print info on that signal only."); | |
3895 | add_com ("z", class_run, xdb_handle_command, | |
3896 | concat ("Specify how to handle a signal.\n\ | |
3897 | Args are signals and actions to apply to those signals.\n\ | |
3898 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
3899 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
3900 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
3901 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
488f131b | 3902 | used by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\ |
c906108c SS |
3903 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ |
3904 | nopass), \"Q\" (noprint)\n\ | |
3905 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
3906 | Print means print a message if this signal happens.\n\ | |
3907 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
3908 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
3909 | Pass and Stop may be combined.", NULL)); | |
3910 | } | |
3911 | ||
3912 | if (!dbx_commands) | |
488f131b JB |
3913 | stop_command = |
3914 | add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\ | |
c906108c SS |
3915 | This allows you to set a list of commands to be run each time execution\n\ |
3916 | of the program stops.", &cmdlist); | |
3917 | ||
3918 | numsigs = (int) TARGET_SIGNAL_LAST; | |
488f131b | 3919 | signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); |
c906108c SS |
3920 | signal_print = (unsigned char *) |
3921 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
3922 | signal_program = (unsigned char *) | |
3923 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
3924 | for (i = 0; i < numsigs; i++) | |
3925 | { | |
3926 | signal_stop[i] = 1; | |
3927 | signal_print[i] = 1; | |
3928 | signal_program[i] = 1; | |
3929 | } | |
3930 | ||
3931 | /* Signals caused by debugger's own actions | |
3932 | should not be given to the program afterwards. */ | |
3933 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
3934 | signal_program[TARGET_SIGNAL_INT] = 0; | |
3935 | ||
3936 | /* Signals that are not errors should not normally enter the debugger. */ | |
3937 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
3938 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
3939 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
3940 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
3941 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
3942 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
3943 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
3944 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
3945 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
3946 | signal_print[TARGET_SIGNAL_IO] = 0; | |
3947 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
3948 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
3949 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
3950 | signal_print[TARGET_SIGNAL_URG] = 0; | |
3951 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
3952 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
3953 | ||
cd0fc7c3 SS |
3954 | /* These signals are used internally by user-level thread |
3955 | implementations. (See signal(5) on Solaris.) Like the above | |
3956 | signals, a healthy program receives and handles them as part of | |
3957 | its normal operation. */ | |
3958 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
3959 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
3960 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
3961 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
3962 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
3963 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
3964 | ||
c906108c SS |
3965 | #ifdef SOLIB_ADD |
3966 | add_show_from_set | |
3967 | (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, | |
3968 | (char *) &stop_on_solib_events, | |
3969 | "Set stopping for shared library events.\n\ | |
3970 | If nonzero, gdb will give control to the user when the dynamic linker\n\ | |
3971 | notifies gdb of shared library events. The most common event of interest\n\ | |
488f131b | 3972 | to the user would be loading/unloading of a new library.\n", &setlist), &showlist); |
c906108c SS |
3973 | #endif |
3974 | ||
3975 | c = add_set_enum_cmd ("follow-fork-mode", | |
3976 | class_run, | |
488f131b | 3977 | follow_fork_mode_kind_names, &follow_fork_mode_string, |
c906108c SS |
3978 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 |
3979 | kernel problem. It's also not terribly useful without a GUI to | |
3980 | help the user drive two debuggers. So for now, I'm disabling | |
3981 | the "both" option. */ | |
c5aa993b JM |
3982 | /* "Set debugger response to a program call of fork \ |
3983 | or vfork.\n\ | |
3984 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
3985 | parent - the original process is debugged after a fork\n\ | |
3986 | child - the new process is debugged after a fork\n\ | |
3987 | both - both the parent and child are debugged after a fork\n\ | |
3988 | ask - the debugger will ask for one of the above choices\n\ | |
3989 | For \"both\", another copy of the debugger will be started to follow\n\ | |
3990 | the new child process. The original debugger will continue to follow\n\ | |
3991 | the original parent process. To distinguish their prompts, the\n\ | |
3992 | debugger copy's prompt will be changed.\n\ | |
3993 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
3994 | By default, the debugger will follow the parent process.", | |
3995 | */ | |
c906108c SS |
3996 | "Set debugger response to a program call of fork \ |
3997 | or vfork.\n\ | |
3998 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
3999 | parent - the original process is debugged after a fork\n\ | |
4000 | child - the new process is debugged after a fork\n\ | |
4001 | ask - the debugger will ask for one of the above choices\n\ | |
4002 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
488f131b | 4003 | By default, the debugger will follow the parent process.", &setlist); |
c906108c SS |
4004 | add_show_from_set (c, &showlist); |
4005 | ||
488f131b | 4006 | c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */ |
1ed2a135 | 4007 | &scheduler_mode, /* current mode */ |
c906108c SS |
4008 | "Set mode for locking scheduler during execution.\n\ |
4009 | off == no locking (threads may preempt at any time)\n\ | |
4010 | on == full locking (no thread except the current thread may run)\n\ | |
4011 | step == scheduler locked during every single-step operation.\n\ | |
4012 | In this mode, no other thread may run during a step command.\n\ | |
488f131b | 4013 | Other threads may run while stepping over a function call ('next').", &setlist); |
c906108c | 4014 | |
9f60d481 | 4015 | set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */ |
c906108c | 4016 | add_show_from_set (c, &showlist); |
5fbbeb29 CF |
4017 | |
4018 | c = add_set_cmd ("step-mode", class_run, | |
488f131b JB |
4019 | var_boolean, (char *) &step_stop_if_no_debug, |
4020 | "Set mode of the step operation. When set, doing a step over a\n\ | |
5fbbeb29 CF |
4021 | function without debug line information will stop at the first\n\ |
4022 | instruction of that function. Otherwise, the function is skipped and\n\ | |
488f131b | 4023 | the step command stops at a different source line.", &setlist); |
5fbbeb29 | 4024 | add_show_from_set (c, &showlist); |
ca6724c1 KB |
4025 | |
4026 | /* ptid initializations */ | |
4027 | null_ptid = ptid_build (0, 0, 0); | |
4028 | minus_one_ptid = ptid_build (-1, 0, 0); | |
4029 | inferior_ptid = null_ptid; | |
4030 | target_last_wait_ptid = minus_one_ptid; | |
c906108c | 4031 | } |