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