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