* dwarf2read.c (read_str_index): Delete arg cu. All callers updated.
[deliverable/binutils-gdb.git] / gdb / infrun.c
CommitLineData
ca557f44
AC
1/* Target-struct-independent code to start (run) and stop an inferior
2 process.
8926118c 3
ecd75fc8 4 Copyright (C) 1986-2014 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
c5aa993b 11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b 18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21#include "defs.h"
0e9f083f 22#include <string.h>
c906108c
SS
23#include <ctype.h>
24#include "symtab.h"
25#include "frame.h"
26#include "inferior.h"
60250e8b 27#include "exceptions.h"
c906108c 28#include "breakpoint.h"
03f2053f 29#include "gdb_wait.h"
c906108c
SS
30#include "gdbcore.h"
31#include "gdbcmd.h"
210661e7 32#include "cli/cli-script.h"
c906108c
SS
33#include "target.h"
34#include "gdbthread.h"
35#include "annotate.h"
1adeb98a 36#include "symfile.h"
7a292a7a 37#include "top.h"
c906108c 38#include <signal.h>
2acceee2 39#include "inf-loop.h"
4e052eda 40#include "regcache.h"
fd0407d6 41#include "value.h"
06600e06 42#include "observer.h"
f636b87d 43#include "language.h"
a77053c2 44#include "solib.h"
f17517ea 45#include "main.h"
186c406b
TT
46#include "dictionary.h"
47#include "block.h"
9f976b41 48#include "gdb_assert.h"
034dad6f 49#include "mi/mi-common.h"
4f8d22e3 50#include "event-top.h"
96429cc8 51#include "record.h"
d02ed0bb 52#include "record-full.h"
edb3359d 53#include "inline-frame.h"
4efc6507 54#include "jit.h"
06cd862c 55#include "tracepoint.h"
be34f849 56#include "continuations.h"
b4a14fd0 57#include "interps.h"
1bfeeb0f 58#include "skip.h"
28106bc2
SDJ
59#include "probe.h"
60#include "objfiles.h"
de0bea00 61#include "completer.h"
9107fc8d 62#include "target-descriptions.h"
f15cb84a 63#include "target-dcache.h"
c906108c
SS
64
65/* Prototypes for local functions */
66
96baa820 67static void signals_info (char *, int);
c906108c 68
96baa820 69static void handle_command (char *, int);
c906108c 70
2ea28649 71static void sig_print_info (enum gdb_signal);
c906108c 72
96baa820 73static void sig_print_header (void);
c906108c 74
74b7792f 75static void resume_cleanups (void *);
c906108c 76
96baa820 77static int hook_stop_stub (void *);
c906108c 78
96baa820
JM
79static int restore_selected_frame (void *);
80
4ef3f3be 81static int follow_fork (void);
96baa820
JM
82
83static void set_schedlock_func (char *args, int from_tty,
488f131b 84 struct cmd_list_element *c);
96baa820 85
a289b8f6
JK
86static int currently_stepping (struct thread_info *tp);
87
b3444185
PA
88static int currently_stepping_or_nexting_callback (struct thread_info *tp,
89 void *data);
a7212384 90
96baa820
JM
91static void xdb_handle_command (char *args, int from_tty);
92
33d62d64
JK
93static void print_exited_reason (int exitstatus);
94
2ea28649 95static void print_signal_exited_reason (enum gdb_signal siggnal);
33d62d64
JK
96
97static void print_no_history_reason (void);
98
2ea28649 99static void print_signal_received_reason (enum gdb_signal siggnal);
33d62d64
JK
100
101static void print_end_stepping_range_reason (void);
102
96baa820 103void _initialize_infrun (void);
43ff13b4 104
e58b0e63
PA
105void nullify_last_target_wait_ptid (void);
106
2c03e5be 107static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *);
2484c66b
UW
108
109static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
110
2484c66b
UW
111static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
112
5fbbeb29
CF
113/* When set, stop the 'step' command if we enter a function which has
114 no line number information. The normal behavior is that we step
115 over such function. */
116int step_stop_if_no_debug = 0;
920d2a44
AC
117static void
118show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
119 struct cmd_list_element *c, const char *value)
120{
121 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
122}
5fbbeb29 123
1777feb0 124/* In asynchronous mode, but simulating synchronous execution. */
96baa820 125
43ff13b4
JM
126int sync_execution = 0;
127
b9f437de
PA
128/* proceed and normal_stop use this to notify the user when the
129 inferior stopped in a different thread than it had been running
130 in. */
96baa820 131
39f77062 132static ptid_t previous_inferior_ptid;
7a292a7a 133
07107ca6
LM
134/* If set (default for legacy reasons), when following a fork, GDB
135 will detach from one of the fork branches, child or parent.
136 Exactly which branch is detached depends on 'set follow-fork-mode'
137 setting. */
138
139static int detach_fork = 1;
6c95b8df 140
237fc4c9
PA
141int debug_displaced = 0;
142static void
143show_debug_displaced (struct ui_file *file, int from_tty,
144 struct cmd_list_element *c, const char *value)
145{
146 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
147}
148
ccce17b0 149unsigned int debug_infrun = 0;
920d2a44
AC
150static void
151show_debug_infrun (struct ui_file *file, int from_tty,
152 struct cmd_list_element *c, const char *value)
153{
154 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
155}
527159b7 156
03583c20
UW
157
158/* Support for disabling address space randomization. */
159
160int disable_randomization = 1;
161
162static void
163show_disable_randomization (struct ui_file *file, int from_tty,
164 struct cmd_list_element *c, const char *value)
165{
166 if (target_supports_disable_randomization ())
167 fprintf_filtered (file,
168 _("Disabling randomization of debuggee's "
169 "virtual address space is %s.\n"),
170 value);
171 else
172 fputs_filtered (_("Disabling randomization of debuggee's "
173 "virtual address space is unsupported on\n"
174 "this platform.\n"), file);
175}
176
177static void
178set_disable_randomization (char *args, int from_tty,
179 struct cmd_list_element *c)
180{
181 if (!target_supports_disable_randomization ())
182 error (_("Disabling randomization of debuggee's "
183 "virtual address space is unsupported on\n"
184 "this platform."));
185}
186
d32dc48e
PA
187/* User interface for non-stop mode. */
188
189int non_stop = 0;
190static int non_stop_1 = 0;
191
192static void
193set_non_stop (char *args, int from_tty,
194 struct cmd_list_element *c)
195{
196 if (target_has_execution)
197 {
198 non_stop_1 = non_stop;
199 error (_("Cannot change this setting while the inferior is running."));
200 }
201
202 non_stop = non_stop_1;
203}
204
205static void
206show_non_stop (struct ui_file *file, int from_tty,
207 struct cmd_list_element *c, const char *value)
208{
209 fprintf_filtered (file,
210 _("Controlling the inferior in non-stop mode is %s.\n"),
211 value);
212}
213
d914c394
SS
214/* "Observer mode" is somewhat like a more extreme version of
215 non-stop, in which all GDB operations that might affect the
216 target's execution have been disabled. */
217
d914c394
SS
218int observer_mode = 0;
219static int observer_mode_1 = 0;
220
221static void
222set_observer_mode (char *args, int from_tty,
223 struct cmd_list_element *c)
224{
d914c394
SS
225 if (target_has_execution)
226 {
227 observer_mode_1 = observer_mode;
228 error (_("Cannot change this setting while the inferior is running."));
229 }
230
231 observer_mode = observer_mode_1;
232
233 may_write_registers = !observer_mode;
234 may_write_memory = !observer_mode;
235 may_insert_breakpoints = !observer_mode;
236 may_insert_tracepoints = !observer_mode;
237 /* We can insert fast tracepoints in or out of observer mode,
238 but enable them if we're going into this mode. */
239 if (observer_mode)
240 may_insert_fast_tracepoints = 1;
241 may_stop = !observer_mode;
242 update_target_permissions ();
243
244 /* Going *into* observer mode we must force non-stop, then
245 going out we leave it that way. */
246 if (observer_mode)
247 {
248 target_async_permitted = 1;
249 pagination_enabled = 0;
250 non_stop = non_stop_1 = 1;
251 }
252
253 if (from_tty)
254 printf_filtered (_("Observer mode is now %s.\n"),
255 (observer_mode ? "on" : "off"));
256}
257
258static void
259show_observer_mode (struct ui_file *file, int from_tty,
260 struct cmd_list_element *c, const char *value)
261{
262 fprintf_filtered (file, _("Observer mode is %s.\n"), value);
263}
264
265/* This updates the value of observer mode based on changes in
266 permissions. Note that we are deliberately ignoring the values of
267 may-write-registers and may-write-memory, since the user may have
268 reason to enable these during a session, for instance to turn on a
269 debugging-related global. */
270
271void
272update_observer_mode (void)
273{
274 int newval;
275
276 newval = (!may_insert_breakpoints
277 && !may_insert_tracepoints
278 && may_insert_fast_tracepoints
279 && !may_stop
280 && non_stop);
281
282 /* Let the user know if things change. */
283 if (newval != observer_mode)
284 printf_filtered (_("Observer mode is now %s.\n"),
285 (newval ? "on" : "off"));
286
287 observer_mode = observer_mode_1 = newval;
288}
c2c6d25f 289
c906108c
SS
290/* Tables of how to react to signals; the user sets them. */
291
292static unsigned char *signal_stop;
293static unsigned char *signal_print;
294static unsigned char *signal_program;
295
ab04a2af
TT
296/* Table of signals that are registered with "catch signal". A
297 non-zero entry indicates that the signal is caught by some "catch
298 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
299 signals. */
300static unsigned char *signal_catch;
301
2455069d
UW
302/* Table of signals that the target may silently handle.
303 This is automatically determined from the flags above,
304 and simply cached here. */
305static unsigned char *signal_pass;
306
c906108c
SS
307#define SET_SIGS(nsigs,sigs,flags) \
308 do { \
309 int signum = (nsigs); \
310 while (signum-- > 0) \
311 if ((sigs)[signum]) \
312 (flags)[signum] = 1; \
313 } while (0)
314
315#define UNSET_SIGS(nsigs,sigs,flags) \
316 do { \
317 int signum = (nsigs); \
318 while (signum-- > 0) \
319 if ((sigs)[signum]) \
320 (flags)[signum] = 0; \
321 } while (0)
322
9b224c5e
PA
323/* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
324 this function is to avoid exporting `signal_program'. */
325
326void
327update_signals_program_target (void)
328{
a493e3e2 329 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
9b224c5e
PA
330}
331
1777feb0 332/* Value to pass to target_resume() to cause all threads to resume. */
39f77062 333
edb3359d 334#define RESUME_ALL minus_one_ptid
c906108c
SS
335
336/* Command list pointer for the "stop" placeholder. */
337
338static struct cmd_list_element *stop_command;
339
c906108c
SS
340/* Function inferior was in as of last step command. */
341
342static struct symbol *step_start_function;
343
c906108c
SS
344/* Nonzero if we want to give control to the user when we're notified
345 of shared library events by the dynamic linker. */
628fe4e4 346int stop_on_solib_events;
f9e14852
GB
347
348/* Enable or disable optional shared library event breakpoints
349 as appropriate when the above flag is changed. */
350
351static void
352set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
353{
354 update_solib_breakpoints ();
355}
356
920d2a44
AC
357static void
358show_stop_on_solib_events (struct ui_file *file, int from_tty,
359 struct cmd_list_element *c, const char *value)
360{
361 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
362 value);
363}
c906108c 364
c906108c
SS
365/* Nonzero means expecting a trace trap
366 and should stop the inferior and return silently when it happens. */
367
368int stop_after_trap;
369
642fd101
DE
370/* Save register contents here when executing a "finish" command or are
371 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
c906108c
SS
372 Thus this contains the return value from the called function (assuming
373 values are returned in a register). */
374
72cec141 375struct regcache *stop_registers;
c906108c 376
c906108c
SS
377/* Nonzero after stop if current stack frame should be printed. */
378
379static int stop_print_frame;
380
e02bc4cc 381/* This is a cached copy of the pid/waitstatus of the last event
9a4105ab
AC
382 returned by target_wait()/deprecated_target_wait_hook(). This
383 information is returned by get_last_target_status(). */
39f77062 384static ptid_t target_last_wait_ptid;
e02bc4cc
DS
385static struct target_waitstatus target_last_waitstatus;
386
0d1e5fa7
PA
387static void context_switch (ptid_t ptid);
388
4e1c45ea 389void init_thread_stepping_state (struct thread_info *tss);
0d1e5fa7 390
7a76f5b8 391static void init_infwait_state (void);
a474d7c2 392
53904c9e
AC
393static const char follow_fork_mode_child[] = "child";
394static const char follow_fork_mode_parent[] = "parent";
395
40478521 396static const char *const follow_fork_mode_kind_names[] = {
53904c9e
AC
397 follow_fork_mode_child,
398 follow_fork_mode_parent,
399 NULL
ef346e04 400};
c906108c 401
53904c9e 402static const char *follow_fork_mode_string = follow_fork_mode_parent;
920d2a44
AC
403static void
404show_follow_fork_mode_string (struct ui_file *file, int from_tty,
405 struct cmd_list_element *c, const char *value)
406{
3e43a32a
MS
407 fprintf_filtered (file,
408 _("Debugger response to a program "
409 "call of fork or vfork is \"%s\".\n"),
920d2a44
AC
410 value);
411}
c906108c
SS
412\f
413
e58b0e63
PA
414/* Tell the target to follow the fork we're stopped at. Returns true
415 if the inferior should be resumed; false, if the target for some
416 reason decided it's best not to resume. */
417
6604731b 418static int
4ef3f3be 419follow_fork (void)
c906108c 420{
ea1dd7bc 421 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
e58b0e63
PA
422 int should_resume = 1;
423 struct thread_info *tp;
424
425 /* Copy user stepping state to the new inferior thread. FIXME: the
426 followed fork child thread should have a copy of most of the
4e3990f4
DE
427 parent thread structure's run control related fields, not just these.
428 Initialized to avoid "may be used uninitialized" warnings from gcc. */
429 struct breakpoint *step_resume_breakpoint = NULL;
186c406b 430 struct breakpoint *exception_resume_breakpoint = NULL;
4e3990f4
DE
431 CORE_ADDR step_range_start = 0;
432 CORE_ADDR step_range_end = 0;
433 struct frame_id step_frame_id = { 0 };
e58b0e63
PA
434
435 if (!non_stop)
436 {
437 ptid_t wait_ptid;
438 struct target_waitstatus wait_status;
439
440 /* Get the last target status returned by target_wait(). */
441 get_last_target_status (&wait_ptid, &wait_status);
442
443 /* If not stopped at a fork event, then there's nothing else to
444 do. */
445 if (wait_status.kind != TARGET_WAITKIND_FORKED
446 && wait_status.kind != TARGET_WAITKIND_VFORKED)
447 return 1;
448
449 /* Check if we switched over from WAIT_PTID, since the event was
450 reported. */
451 if (!ptid_equal (wait_ptid, minus_one_ptid)
452 && !ptid_equal (inferior_ptid, wait_ptid))
453 {
454 /* We did. Switch back to WAIT_PTID thread, to tell the
455 target to follow it (in either direction). We'll
456 afterwards refuse to resume, and inform the user what
457 happened. */
458 switch_to_thread (wait_ptid);
459 should_resume = 0;
460 }
461 }
462
463 tp = inferior_thread ();
464
465 /* If there were any forks/vforks that were caught and are now to be
466 followed, then do so now. */
467 switch (tp->pending_follow.kind)
468 {
469 case TARGET_WAITKIND_FORKED:
470 case TARGET_WAITKIND_VFORKED:
471 {
472 ptid_t parent, child;
473
474 /* If the user did a next/step, etc, over a fork call,
475 preserve the stepping state in the fork child. */
476 if (follow_child && should_resume)
477 {
8358c15c
JK
478 step_resume_breakpoint = clone_momentary_breakpoint
479 (tp->control.step_resume_breakpoint);
16c381f0
JK
480 step_range_start = tp->control.step_range_start;
481 step_range_end = tp->control.step_range_end;
482 step_frame_id = tp->control.step_frame_id;
186c406b
TT
483 exception_resume_breakpoint
484 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
e58b0e63
PA
485
486 /* For now, delete the parent's sr breakpoint, otherwise,
487 parent/child sr breakpoints are considered duplicates,
488 and the child version will not be installed. Remove
489 this when the breakpoints module becomes aware of
490 inferiors and address spaces. */
491 delete_step_resume_breakpoint (tp);
16c381f0
JK
492 tp->control.step_range_start = 0;
493 tp->control.step_range_end = 0;
494 tp->control.step_frame_id = null_frame_id;
186c406b 495 delete_exception_resume_breakpoint (tp);
e58b0e63
PA
496 }
497
498 parent = inferior_ptid;
499 child = tp->pending_follow.value.related_pid;
500
501 /* Tell the target to do whatever is necessary to follow
502 either parent or child. */
07107ca6 503 if (target_follow_fork (follow_child, detach_fork))
e58b0e63
PA
504 {
505 /* Target refused to follow, or there's some other reason
506 we shouldn't resume. */
507 should_resume = 0;
508 }
509 else
510 {
511 /* This pending follow fork event is now handled, one way
512 or another. The previous selected thread may be gone
513 from the lists by now, but if it is still around, need
514 to clear the pending follow request. */
e09875d4 515 tp = find_thread_ptid (parent);
e58b0e63
PA
516 if (tp)
517 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
518
519 /* This makes sure we don't try to apply the "Switched
520 over from WAIT_PID" logic above. */
521 nullify_last_target_wait_ptid ();
522
1777feb0 523 /* If we followed the child, switch to it... */
e58b0e63
PA
524 if (follow_child)
525 {
526 switch_to_thread (child);
527
528 /* ... and preserve the stepping state, in case the
529 user was stepping over the fork call. */
530 if (should_resume)
531 {
532 tp = inferior_thread ();
8358c15c
JK
533 tp->control.step_resume_breakpoint
534 = step_resume_breakpoint;
16c381f0
JK
535 tp->control.step_range_start = step_range_start;
536 tp->control.step_range_end = step_range_end;
537 tp->control.step_frame_id = step_frame_id;
186c406b
TT
538 tp->control.exception_resume_breakpoint
539 = exception_resume_breakpoint;
e58b0e63
PA
540 }
541 else
542 {
543 /* If we get here, it was because we're trying to
544 resume from a fork catchpoint, but, the user
545 has switched threads away from the thread that
546 forked. In that case, the resume command
547 issued is most likely not applicable to the
548 child, so just warn, and refuse to resume. */
3e43a32a
MS
549 warning (_("Not resuming: switched threads "
550 "before following fork child.\n"));
e58b0e63
PA
551 }
552
553 /* Reset breakpoints in the child as appropriate. */
554 follow_inferior_reset_breakpoints ();
555 }
556 else
557 switch_to_thread (parent);
558 }
559 }
560 break;
561 case TARGET_WAITKIND_SPURIOUS:
562 /* Nothing to follow. */
563 break;
564 default:
565 internal_error (__FILE__, __LINE__,
566 "Unexpected pending_follow.kind %d\n",
567 tp->pending_follow.kind);
568 break;
569 }
c906108c 570
e58b0e63 571 return should_resume;
c906108c
SS
572}
573
6604731b
DJ
574void
575follow_inferior_reset_breakpoints (void)
c906108c 576{
4e1c45ea
PA
577 struct thread_info *tp = inferior_thread ();
578
6604731b
DJ
579 /* Was there a step_resume breakpoint? (There was if the user
580 did a "next" at the fork() call.) If so, explicitly reset its
581 thread number.
582
583 step_resumes are a form of bp that are made to be per-thread.
584 Since we created the step_resume bp when the parent process
585 was being debugged, and now are switching to the child process,
586 from the breakpoint package's viewpoint, that's a switch of
587 "threads". We must update the bp's notion of which thread
588 it is for, or it'll be ignored when it triggers. */
589
8358c15c
JK
590 if (tp->control.step_resume_breakpoint)
591 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
6604731b 592
186c406b
TT
593 if (tp->control.exception_resume_breakpoint)
594 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
595
6604731b
DJ
596 /* Reinsert all breakpoints in the child. The user may have set
597 breakpoints after catching the fork, in which case those
598 were never set in the child, but only in the parent. This makes
599 sure the inserted breakpoints match the breakpoint list. */
600
601 breakpoint_re_set ();
602 insert_breakpoints ();
c906108c 603}
c906108c 604
6c95b8df
PA
605/* The child has exited or execed: resume threads of the parent the
606 user wanted to be executing. */
607
608static int
609proceed_after_vfork_done (struct thread_info *thread,
610 void *arg)
611{
612 int pid = * (int *) arg;
613
614 if (ptid_get_pid (thread->ptid) == pid
615 && is_running (thread->ptid)
616 && !is_executing (thread->ptid)
617 && !thread->stop_requested
a493e3e2 618 && thread->suspend.stop_signal == GDB_SIGNAL_0)
6c95b8df
PA
619 {
620 if (debug_infrun)
621 fprintf_unfiltered (gdb_stdlog,
622 "infrun: resuming vfork parent thread %s\n",
623 target_pid_to_str (thread->ptid));
624
625 switch_to_thread (thread->ptid);
626 clear_proceed_status ();
a493e3e2 627 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
6c95b8df
PA
628 }
629
630 return 0;
631}
632
633/* Called whenever we notice an exec or exit event, to handle
634 detaching or resuming a vfork parent. */
635
636static void
637handle_vfork_child_exec_or_exit (int exec)
638{
639 struct inferior *inf = current_inferior ();
640
641 if (inf->vfork_parent)
642 {
643 int resume_parent = -1;
644
645 /* This exec or exit marks the end of the shared memory region
646 between the parent and the child. If the user wanted to
647 detach from the parent, now is the time. */
648
649 if (inf->vfork_parent->pending_detach)
650 {
651 struct thread_info *tp;
652 struct cleanup *old_chain;
653 struct program_space *pspace;
654 struct address_space *aspace;
655
1777feb0 656 /* follow-fork child, detach-on-fork on. */
6c95b8df 657
68c9da30
PA
658 inf->vfork_parent->pending_detach = 0;
659
f50f4e56
PA
660 if (!exec)
661 {
662 /* If we're handling a child exit, then inferior_ptid
663 points at the inferior's pid, not to a thread. */
664 old_chain = save_inferior_ptid ();
665 save_current_program_space ();
666 save_current_inferior ();
667 }
668 else
669 old_chain = save_current_space_and_thread ();
6c95b8df
PA
670
671 /* We're letting loose of the parent. */
672 tp = any_live_thread_of_process (inf->vfork_parent->pid);
673 switch_to_thread (tp->ptid);
674
675 /* We're about to detach from the parent, which implicitly
676 removes breakpoints from its address space. There's a
677 catch here: we want to reuse the spaces for the child,
678 but, parent/child are still sharing the pspace at this
679 point, although the exec in reality makes the kernel give
680 the child a fresh set of new pages. The problem here is
681 that the breakpoints module being unaware of this, would
682 likely chose the child process to write to the parent
683 address space. Swapping the child temporarily away from
684 the spaces has the desired effect. Yes, this is "sort
685 of" a hack. */
686
687 pspace = inf->pspace;
688 aspace = inf->aspace;
689 inf->aspace = NULL;
690 inf->pspace = NULL;
691
692 if (debug_infrun || info_verbose)
693 {
694 target_terminal_ours ();
695
696 if (exec)
697 fprintf_filtered (gdb_stdlog,
3e43a32a
MS
698 "Detaching vfork parent process "
699 "%d after child exec.\n",
6c95b8df
PA
700 inf->vfork_parent->pid);
701 else
702 fprintf_filtered (gdb_stdlog,
3e43a32a
MS
703 "Detaching vfork parent process "
704 "%d after child exit.\n",
6c95b8df
PA
705 inf->vfork_parent->pid);
706 }
707
708 target_detach (NULL, 0);
709
710 /* Put it back. */
711 inf->pspace = pspace;
712 inf->aspace = aspace;
713
714 do_cleanups (old_chain);
715 }
716 else if (exec)
717 {
718 /* We're staying attached to the parent, so, really give the
719 child a new address space. */
720 inf->pspace = add_program_space (maybe_new_address_space ());
721 inf->aspace = inf->pspace->aspace;
722 inf->removable = 1;
723 set_current_program_space (inf->pspace);
724
725 resume_parent = inf->vfork_parent->pid;
726
727 /* Break the bonds. */
728 inf->vfork_parent->vfork_child = NULL;
729 }
730 else
731 {
732 struct cleanup *old_chain;
733 struct program_space *pspace;
734
735 /* If this is a vfork child exiting, then the pspace and
736 aspaces were shared with the parent. Since we're
737 reporting the process exit, we'll be mourning all that is
738 found in the address space, and switching to null_ptid,
739 preparing to start a new inferior. But, since we don't
740 want to clobber the parent's address/program spaces, we
741 go ahead and create a new one for this exiting
742 inferior. */
743
744 /* Switch to null_ptid, so that clone_program_space doesn't want
745 to read the selected frame of a dead process. */
746 old_chain = save_inferior_ptid ();
747 inferior_ptid = null_ptid;
748
749 /* This inferior is dead, so avoid giving the breakpoints
750 module the option to write through to it (cloning a
751 program space resets breakpoints). */
752 inf->aspace = NULL;
753 inf->pspace = NULL;
754 pspace = add_program_space (maybe_new_address_space ());
755 set_current_program_space (pspace);
756 inf->removable = 1;
7dcd53a0 757 inf->symfile_flags = SYMFILE_NO_READ;
6c95b8df
PA
758 clone_program_space (pspace, inf->vfork_parent->pspace);
759 inf->pspace = pspace;
760 inf->aspace = pspace->aspace;
761
762 /* Put back inferior_ptid. We'll continue mourning this
1777feb0 763 inferior. */
6c95b8df
PA
764 do_cleanups (old_chain);
765
766 resume_parent = inf->vfork_parent->pid;
767 /* Break the bonds. */
768 inf->vfork_parent->vfork_child = NULL;
769 }
770
771 inf->vfork_parent = NULL;
772
773 gdb_assert (current_program_space == inf->pspace);
774
775 if (non_stop && resume_parent != -1)
776 {
777 /* If the user wanted the parent to be running, let it go
778 free now. */
779 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
780
781 if (debug_infrun)
3e43a32a
MS
782 fprintf_unfiltered (gdb_stdlog,
783 "infrun: resuming vfork parent process %d\n",
6c95b8df
PA
784 resume_parent);
785
786 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
787
788 do_cleanups (old_chain);
789 }
790 }
791}
792
eb6c553b 793/* Enum strings for "set|show follow-exec-mode". */
6c95b8df
PA
794
795static const char follow_exec_mode_new[] = "new";
796static const char follow_exec_mode_same[] = "same";
40478521 797static const char *const follow_exec_mode_names[] =
6c95b8df
PA
798{
799 follow_exec_mode_new,
800 follow_exec_mode_same,
801 NULL,
802};
803
804static const char *follow_exec_mode_string = follow_exec_mode_same;
805static void
806show_follow_exec_mode_string (struct ui_file *file, int from_tty,
807 struct cmd_list_element *c, const char *value)
808{
809 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
810}
811
1777feb0 812/* EXECD_PATHNAME is assumed to be non-NULL. */
1adeb98a 813
c906108c 814static void
3a3e9ee3 815follow_exec (ptid_t pid, char *execd_pathname)
c906108c 816{
4e1c45ea 817 struct thread_info *th = inferior_thread ();
6c95b8df 818 struct inferior *inf = current_inferior ();
7a292a7a 819
c906108c
SS
820 /* This is an exec event that we actually wish to pay attention to.
821 Refresh our symbol table to the newly exec'd program, remove any
822 momentary bp's, etc.
823
824 If there are breakpoints, they aren't really inserted now,
825 since the exec() transformed our inferior into a fresh set
826 of instructions.
827
828 We want to preserve symbolic breakpoints on the list, since
829 we have hopes that they can be reset after the new a.out's
830 symbol table is read.
831
832 However, any "raw" breakpoints must be removed from the list
833 (e.g., the solib bp's), since their address is probably invalid
834 now.
835
836 And, we DON'T want to call delete_breakpoints() here, since
837 that may write the bp's "shadow contents" (the instruction
838 value that was overwritten witha TRAP instruction). Since
1777feb0 839 we now have a new a.out, those shadow contents aren't valid. */
6c95b8df
PA
840
841 mark_breakpoints_out ();
842
c906108c
SS
843 update_breakpoints_after_exec ();
844
845 /* If there was one, it's gone now. We cannot truly step-to-next
1777feb0 846 statement through an exec(). */
8358c15c 847 th->control.step_resume_breakpoint = NULL;
186c406b 848 th->control.exception_resume_breakpoint = NULL;
16c381f0
JK
849 th->control.step_range_start = 0;
850 th->control.step_range_end = 0;
c906108c 851
a75724bc
PA
852 /* The target reports the exec event to the main thread, even if
853 some other thread does the exec, and even if the main thread was
854 already stopped --- if debugging in non-stop mode, it's possible
855 the user had the main thread held stopped in the previous image
856 --- release it now. This is the same behavior as step-over-exec
857 with scheduler-locking on in all-stop mode. */
858 th->stop_requested = 0;
859
1777feb0 860 /* What is this a.out's name? */
6c95b8df
PA
861 printf_unfiltered (_("%s is executing new program: %s\n"),
862 target_pid_to_str (inferior_ptid),
863 execd_pathname);
c906108c
SS
864
865 /* We've followed the inferior through an exec. Therefore, the
1777feb0 866 inferior has essentially been killed & reborn. */
7a292a7a 867
c906108c 868 gdb_flush (gdb_stdout);
6ca15a4b
PA
869
870 breakpoint_init_inferior (inf_execd);
e85a822c
DJ
871
872 if (gdb_sysroot && *gdb_sysroot)
873 {
874 char *name = alloca (strlen (gdb_sysroot)
875 + strlen (execd_pathname)
876 + 1);
abbb1732 877
e85a822c
DJ
878 strcpy (name, gdb_sysroot);
879 strcat (name, execd_pathname);
880 execd_pathname = name;
881 }
c906108c 882
cce9b6bf
PA
883 /* Reset the shared library package. This ensures that we get a
884 shlib event when the child reaches "_start", at which point the
885 dld will have had a chance to initialize the child. */
886 /* Also, loading a symbol file below may trigger symbol lookups, and
887 we don't want those to be satisfied by the libraries of the
888 previous incarnation of this process. */
889 no_shared_libraries (NULL, 0);
890
6c95b8df
PA
891 if (follow_exec_mode_string == follow_exec_mode_new)
892 {
893 struct program_space *pspace;
6c95b8df
PA
894
895 /* The user wants to keep the old inferior and program spaces
896 around. Create a new fresh one, and switch to it. */
897
898 inf = add_inferior (current_inferior ()->pid);
899 pspace = add_program_space (maybe_new_address_space ());
900 inf->pspace = pspace;
901 inf->aspace = pspace->aspace;
902
903 exit_inferior_num_silent (current_inferior ()->num);
904
905 set_current_inferior (inf);
906 set_current_program_space (pspace);
907 }
9107fc8d
PA
908 else
909 {
910 /* The old description may no longer be fit for the new image.
911 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
912 old description; we'll read a new one below. No need to do
913 this on "follow-exec-mode new", as the old inferior stays
914 around (its description is later cleared/refetched on
915 restart). */
916 target_clear_description ();
917 }
6c95b8df
PA
918
919 gdb_assert (current_program_space == inf->pspace);
920
1777feb0 921 /* That a.out is now the one to use. */
6c95b8df
PA
922 exec_file_attach (execd_pathname, 0);
923
c1e56572
JK
924 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
925 (Position Independent Executable) main symbol file will get applied by
926 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
927 the breakpoints with the zero displacement. */
928
7dcd53a0
TT
929 symbol_file_add (execd_pathname,
930 (inf->symfile_flags
931 | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET),
c1e56572
JK
932 NULL, 0);
933
7dcd53a0
TT
934 if ((inf->symfile_flags & SYMFILE_NO_READ) == 0)
935 set_initial_language ();
c906108c 936
9107fc8d
PA
937 /* If the target can specify a description, read it. Must do this
938 after flipping to the new executable (because the target supplied
939 description must be compatible with the executable's
940 architecture, and the old executable may e.g., be 32-bit, while
941 the new one 64-bit), and before anything involving memory or
942 registers. */
943 target_find_description ();
944
268a4a75 945 solib_create_inferior_hook (0);
c906108c 946
4efc6507
DE
947 jit_inferior_created_hook ();
948
c1e56572
JK
949 breakpoint_re_set ();
950
c906108c
SS
951 /* Reinsert all breakpoints. (Those which were symbolic have
952 been reset to the proper address in the new a.out, thanks
1777feb0 953 to symbol_file_command...). */
c906108c
SS
954 insert_breakpoints ();
955
956 /* The next resume of this inferior should bring it to the shlib
957 startup breakpoints. (If the user had also set bp's on
958 "main" from the old (parent) process, then they'll auto-
1777feb0 959 matically get reset there in the new process.). */
c906108c
SS
960}
961
962/* Non-zero if we just simulating a single-step. This is needed
963 because we cannot remove the breakpoints in the inferior process
964 until after the `wait' in `wait_for_inferior'. */
965static int singlestep_breakpoints_inserted_p = 0;
9f976b41
DJ
966
967/* The thread we inserted single-step breakpoints for. */
968static ptid_t singlestep_ptid;
969
fd48f117
DJ
970/* PC when we started this single-step. */
971static CORE_ADDR singlestep_pc;
972
31e77af2
PA
973/* Info about an instruction that is being stepped over. Invalid if
974 ASPACE is NULL. */
975
976struct step_over_info
977{
978 /* The instruction's address space. */
979 struct address_space *aspace;
980
981 /* The instruction's address. */
982 CORE_ADDR address;
983};
984
985/* The step-over info of the location that is being stepped over.
986
987 Note that with async/breakpoint always-inserted mode, a user might
988 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
989 being stepped over. As setting a new breakpoint inserts all
990 breakpoints, we need to make sure the breakpoint being stepped over
991 isn't inserted then. We do that by only clearing the step-over
992 info when the step-over is actually finished (or aborted).
993
994 Presently GDB can only step over one breakpoint at any given time.
995 Given threads that can't run code in the same address space as the
996 breakpoint's can't really miss the breakpoint, GDB could be taught
997 to step-over at most one breakpoint per address space (so this info
998 could move to the address space object if/when GDB is extended).
999 The set of breakpoints being stepped over will normally be much
1000 smaller than the set of all breakpoints, so a flag in the
1001 breakpoint location structure would be wasteful. A separate list
1002 also saves complexity and run-time, as otherwise we'd have to go
1003 through all breakpoint locations clearing their flag whenever we
1004 start a new sequence. Similar considerations weigh against storing
1005 this info in the thread object. Plus, not all step overs actually
1006 have breakpoint locations -- e.g., stepping past a single-step
1007 breakpoint, or stepping to complete a non-continuable
1008 watchpoint. */
1009static struct step_over_info step_over_info;
1010
1011/* Record the address of the breakpoint/instruction we're currently
1012 stepping over. */
1013
1014static void
1015set_step_over_info (struct address_space *aspace, CORE_ADDR address)
1016{
1017 step_over_info.aspace = aspace;
1018 step_over_info.address = address;
1019}
1020
1021/* Called when we're not longer stepping over a breakpoint / an
1022 instruction, so all breakpoints are free to be (re)inserted. */
1023
1024static void
1025clear_step_over_info (void)
1026{
1027 step_over_info.aspace = NULL;
1028 step_over_info.address = 0;
1029}
1030
1031/* See inferior.h. */
1032
1033int
1034stepping_past_instruction_at (struct address_space *aspace,
1035 CORE_ADDR address)
1036{
1037 return (step_over_info.aspace != NULL
1038 && breakpoint_address_match (aspace, address,
1039 step_over_info.aspace,
1040 step_over_info.address));
1041}
1042
c906108c 1043\f
237fc4c9
PA
1044/* Displaced stepping. */
1045
1046/* In non-stop debugging mode, we must take special care to manage
1047 breakpoints properly; in particular, the traditional strategy for
1048 stepping a thread past a breakpoint it has hit is unsuitable.
1049 'Displaced stepping' is a tactic for stepping one thread past a
1050 breakpoint it has hit while ensuring that other threads running
1051 concurrently will hit the breakpoint as they should.
1052
1053 The traditional way to step a thread T off a breakpoint in a
1054 multi-threaded program in all-stop mode is as follows:
1055
1056 a0) Initially, all threads are stopped, and breakpoints are not
1057 inserted.
1058 a1) We single-step T, leaving breakpoints uninserted.
1059 a2) We insert breakpoints, and resume all threads.
1060
1061 In non-stop debugging, however, this strategy is unsuitable: we
1062 don't want to have to stop all threads in the system in order to
1063 continue or step T past a breakpoint. Instead, we use displaced
1064 stepping:
1065
1066 n0) Initially, T is stopped, other threads are running, and
1067 breakpoints are inserted.
1068 n1) We copy the instruction "under" the breakpoint to a separate
1069 location, outside the main code stream, making any adjustments
1070 to the instruction, register, and memory state as directed by
1071 T's architecture.
1072 n2) We single-step T over the instruction at its new location.
1073 n3) We adjust the resulting register and memory state as directed
1074 by T's architecture. This includes resetting T's PC to point
1075 back into the main instruction stream.
1076 n4) We resume T.
1077
1078 This approach depends on the following gdbarch methods:
1079
1080 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1081 indicate where to copy the instruction, and how much space must
1082 be reserved there. We use these in step n1.
1083
1084 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1085 address, and makes any necessary adjustments to the instruction,
1086 register contents, and memory. We use this in step n1.
1087
1088 - gdbarch_displaced_step_fixup adjusts registers and memory after
1089 we have successfuly single-stepped the instruction, to yield the
1090 same effect the instruction would have had if we had executed it
1091 at its original address. We use this in step n3.
1092
1093 - gdbarch_displaced_step_free_closure provides cleanup.
1094
1095 The gdbarch_displaced_step_copy_insn and
1096 gdbarch_displaced_step_fixup functions must be written so that
1097 copying an instruction with gdbarch_displaced_step_copy_insn,
1098 single-stepping across the copied instruction, and then applying
1099 gdbarch_displaced_insn_fixup should have the same effects on the
1100 thread's memory and registers as stepping the instruction in place
1101 would have. Exactly which responsibilities fall to the copy and
1102 which fall to the fixup is up to the author of those functions.
1103
1104 See the comments in gdbarch.sh for details.
1105
1106 Note that displaced stepping and software single-step cannot
1107 currently be used in combination, although with some care I think
1108 they could be made to. Software single-step works by placing
1109 breakpoints on all possible subsequent instructions; if the
1110 displaced instruction is a PC-relative jump, those breakpoints
1111 could fall in very strange places --- on pages that aren't
1112 executable, or at addresses that are not proper instruction
1113 boundaries. (We do generally let other threads run while we wait
1114 to hit the software single-step breakpoint, and they might
1115 encounter such a corrupted instruction.) One way to work around
1116 this would be to have gdbarch_displaced_step_copy_insn fully
1117 simulate the effect of PC-relative instructions (and return NULL)
1118 on architectures that use software single-stepping.
1119
1120 In non-stop mode, we can have independent and simultaneous step
1121 requests, so more than one thread may need to simultaneously step
1122 over a breakpoint. The current implementation assumes there is
1123 only one scratch space per process. In this case, we have to
1124 serialize access to the scratch space. If thread A wants to step
1125 over a breakpoint, but we are currently waiting for some other
1126 thread to complete a displaced step, we leave thread A stopped and
1127 place it in the displaced_step_request_queue. Whenever a displaced
1128 step finishes, we pick the next thread in the queue and start a new
1129 displaced step operation on it. See displaced_step_prepare and
1130 displaced_step_fixup for details. */
1131
237fc4c9
PA
1132struct displaced_step_request
1133{
1134 ptid_t ptid;
1135 struct displaced_step_request *next;
1136};
1137
fc1cf338
PA
1138/* Per-inferior displaced stepping state. */
1139struct displaced_step_inferior_state
1140{
1141 /* Pointer to next in linked list. */
1142 struct displaced_step_inferior_state *next;
1143
1144 /* The process this displaced step state refers to. */
1145 int pid;
1146
1147 /* A queue of pending displaced stepping requests. One entry per
1148 thread that needs to do a displaced step. */
1149 struct displaced_step_request *step_request_queue;
1150
1151 /* If this is not null_ptid, this is the thread carrying out a
1152 displaced single-step in process PID. This thread's state will
1153 require fixing up once it has completed its step. */
1154 ptid_t step_ptid;
1155
1156 /* The architecture the thread had when we stepped it. */
1157 struct gdbarch *step_gdbarch;
1158
1159 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1160 for post-step cleanup. */
1161 struct displaced_step_closure *step_closure;
1162
1163 /* The address of the original instruction, and the copy we
1164 made. */
1165 CORE_ADDR step_original, step_copy;
1166
1167 /* Saved contents of copy area. */
1168 gdb_byte *step_saved_copy;
1169};
1170
1171/* The list of states of processes involved in displaced stepping
1172 presently. */
1173static struct displaced_step_inferior_state *displaced_step_inferior_states;
1174
1175/* Get the displaced stepping state of process PID. */
1176
1177static struct displaced_step_inferior_state *
1178get_displaced_stepping_state (int pid)
1179{
1180 struct displaced_step_inferior_state *state;
1181
1182 for (state = displaced_step_inferior_states;
1183 state != NULL;
1184 state = state->next)
1185 if (state->pid == pid)
1186 return state;
1187
1188 return NULL;
1189}
1190
1191/* Add a new displaced stepping state for process PID to the displaced
1192 stepping state list, or return a pointer to an already existing
1193 entry, if it already exists. Never returns NULL. */
1194
1195static struct displaced_step_inferior_state *
1196add_displaced_stepping_state (int pid)
1197{
1198 struct displaced_step_inferior_state *state;
1199
1200 for (state = displaced_step_inferior_states;
1201 state != NULL;
1202 state = state->next)
1203 if (state->pid == pid)
1204 return state;
237fc4c9 1205
fc1cf338
PA
1206 state = xcalloc (1, sizeof (*state));
1207 state->pid = pid;
1208 state->next = displaced_step_inferior_states;
1209 displaced_step_inferior_states = state;
237fc4c9 1210
fc1cf338
PA
1211 return state;
1212}
1213
a42244db
YQ
1214/* If inferior is in displaced stepping, and ADDR equals to starting address
1215 of copy area, return corresponding displaced_step_closure. Otherwise,
1216 return NULL. */
1217
1218struct displaced_step_closure*
1219get_displaced_step_closure_by_addr (CORE_ADDR addr)
1220{
1221 struct displaced_step_inferior_state *displaced
1222 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1223
1224 /* If checking the mode of displaced instruction in copy area. */
1225 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1226 && (displaced->step_copy == addr))
1227 return displaced->step_closure;
1228
1229 return NULL;
1230}
1231
fc1cf338 1232/* Remove the displaced stepping state of process PID. */
237fc4c9 1233
fc1cf338
PA
1234static void
1235remove_displaced_stepping_state (int pid)
1236{
1237 struct displaced_step_inferior_state *it, **prev_next_p;
237fc4c9 1238
fc1cf338
PA
1239 gdb_assert (pid != 0);
1240
1241 it = displaced_step_inferior_states;
1242 prev_next_p = &displaced_step_inferior_states;
1243 while (it)
1244 {
1245 if (it->pid == pid)
1246 {
1247 *prev_next_p = it->next;
1248 xfree (it);
1249 return;
1250 }
1251
1252 prev_next_p = &it->next;
1253 it = *prev_next_p;
1254 }
1255}
1256
1257static void
1258infrun_inferior_exit (struct inferior *inf)
1259{
1260 remove_displaced_stepping_state (inf->pid);
1261}
237fc4c9 1262
fff08868
HZ
1263/* If ON, and the architecture supports it, GDB will use displaced
1264 stepping to step over breakpoints. If OFF, or if the architecture
1265 doesn't support it, GDB will instead use the traditional
1266 hold-and-step approach. If AUTO (which is the default), GDB will
1267 decide which technique to use to step over breakpoints depending on
1268 which of all-stop or non-stop mode is active --- displaced stepping
1269 in non-stop mode; hold-and-step in all-stop mode. */
1270
72d0e2c5 1271static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO;
fff08868 1272
237fc4c9
PA
1273static void
1274show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1275 struct cmd_list_element *c,
1276 const char *value)
1277{
72d0e2c5 1278 if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO)
3e43a32a
MS
1279 fprintf_filtered (file,
1280 _("Debugger's willingness to use displaced stepping "
1281 "to step over breakpoints is %s (currently %s).\n"),
fff08868
HZ
1282 value, non_stop ? "on" : "off");
1283 else
3e43a32a
MS
1284 fprintf_filtered (file,
1285 _("Debugger's willingness to use displaced stepping "
1286 "to step over breakpoints is %s.\n"), value);
237fc4c9
PA
1287}
1288
fff08868
HZ
1289/* Return non-zero if displaced stepping can/should be used to step
1290 over breakpoints. */
1291
237fc4c9
PA
1292static int
1293use_displaced_stepping (struct gdbarch *gdbarch)
1294{
72d0e2c5
YQ
1295 return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop)
1296 || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
96429cc8 1297 && gdbarch_displaced_step_copy_insn_p (gdbarch)
8213266a 1298 && find_record_target () == NULL);
237fc4c9
PA
1299}
1300
1301/* Clean out any stray displaced stepping state. */
1302static void
fc1cf338 1303displaced_step_clear (struct displaced_step_inferior_state *displaced)
237fc4c9
PA
1304{
1305 /* Indicate that there is no cleanup pending. */
fc1cf338 1306 displaced->step_ptid = null_ptid;
237fc4c9 1307
fc1cf338 1308 if (displaced->step_closure)
237fc4c9 1309 {
fc1cf338
PA
1310 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1311 displaced->step_closure);
1312 displaced->step_closure = NULL;
237fc4c9
PA
1313 }
1314}
1315
1316static void
fc1cf338 1317displaced_step_clear_cleanup (void *arg)
237fc4c9 1318{
fc1cf338
PA
1319 struct displaced_step_inferior_state *state = arg;
1320
1321 displaced_step_clear (state);
237fc4c9
PA
1322}
1323
1324/* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1325void
1326displaced_step_dump_bytes (struct ui_file *file,
1327 const gdb_byte *buf,
1328 size_t len)
1329{
1330 int i;
1331
1332 for (i = 0; i < len; i++)
1333 fprintf_unfiltered (file, "%02x ", buf[i]);
1334 fputs_unfiltered ("\n", file);
1335}
1336
1337/* Prepare to single-step, using displaced stepping.
1338
1339 Note that we cannot use displaced stepping when we have a signal to
1340 deliver. If we have a signal to deliver and an instruction to step
1341 over, then after the step, there will be no indication from the
1342 target whether the thread entered a signal handler or ignored the
1343 signal and stepped over the instruction successfully --- both cases
1344 result in a simple SIGTRAP. In the first case we mustn't do a
1345 fixup, and in the second case we must --- but we can't tell which.
1346 Comments in the code for 'random signals' in handle_inferior_event
1347 explain how we handle this case instead.
1348
1349 Returns 1 if preparing was successful -- this thread is going to be
1350 stepped now; or 0 if displaced stepping this thread got queued. */
1351static int
1352displaced_step_prepare (ptid_t ptid)
1353{
ad53cd71 1354 struct cleanup *old_cleanups, *ignore_cleanups;
c1e36e3e 1355 struct thread_info *tp = find_thread_ptid (ptid);
237fc4c9
PA
1356 struct regcache *regcache = get_thread_regcache (ptid);
1357 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1358 CORE_ADDR original, copy;
1359 ULONGEST len;
1360 struct displaced_step_closure *closure;
fc1cf338 1361 struct displaced_step_inferior_state *displaced;
9e529e1d 1362 int status;
237fc4c9
PA
1363
1364 /* We should never reach this function if the architecture does not
1365 support displaced stepping. */
1366 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1367
c1e36e3e
PA
1368 /* Disable range stepping while executing in the scratch pad. We
1369 want a single-step even if executing the displaced instruction in
1370 the scratch buffer lands within the stepping range (e.g., a
1371 jump/branch). */
1372 tp->control.may_range_step = 0;
1373
fc1cf338
PA
1374 /* We have to displaced step one thread at a time, as we only have
1375 access to a single scratch space per inferior. */
237fc4c9 1376
fc1cf338
PA
1377 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1378
1379 if (!ptid_equal (displaced->step_ptid, null_ptid))
237fc4c9
PA
1380 {
1381 /* Already waiting for a displaced step to finish. Defer this
1382 request and place in queue. */
1383 struct displaced_step_request *req, *new_req;
1384
1385 if (debug_displaced)
1386 fprintf_unfiltered (gdb_stdlog,
1387 "displaced: defering step of %s\n",
1388 target_pid_to_str (ptid));
1389
1390 new_req = xmalloc (sizeof (*new_req));
1391 new_req->ptid = ptid;
1392 new_req->next = NULL;
1393
fc1cf338 1394 if (displaced->step_request_queue)
237fc4c9 1395 {
fc1cf338 1396 for (req = displaced->step_request_queue;
237fc4c9
PA
1397 req && req->next;
1398 req = req->next)
1399 ;
1400 req->next = new_req;
1401 }
1402 else
fc1cf338 1403 displaced->step_request_queue = new_req;
237fc4c9
PA
1404
1405 return 0;
1406 }
1407 else
1408 {
1409 if (debug_displaced)
1410 fprintf_unfiltered (gdb_stdlog,
1411 "displaced: stepping %s now\n",
1412 target_pid_to_str (ptid));
1413 }
1414
fc1cf338 1415 displaced_step_clear (displaced);
237fc4c9 1416
ad53cd71
PA
1417 old_cleanups = save_inferior_ptid ();
1418 inferior_ptid = ptid;
1419
515630c5 1420 original = regcache_read_pc (regcache);
237fc4c9
PA
1421
1422 copy = gdbarch_displaced_step_location (gdbarch);
1423 len = gdbarch_max_insn_length (gdbarch);
1424
1425 /* Save the original contents of the copy area. */
fc1cf338 1426 displaced->step_saved_copy = xmalloc (len);
ad53cd71 1427 ignore_cleanups = make_cleanup (free_current_contents,
fc1cf338 1428 &displaced->step_saved_copy);
9e529e1d
JK
1429 status = target_read_memory (copy, displaced->step_saved_copy, len);
1430 if (status != 0)
1431 throw_error (MEMORY_ERROR,
1432 _("Error accessing memory address %s (%s) for "
1433 "displaced-stepping scratch space."),
1434 paddress (gdbarch, copy), safe_strerror (status));
237fc4c9
PA
1435 if (debug_displaced)
1436 {
5af949e3
UW
1437 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1438 paddress (gdbarch, copy));
fc1cf338
PA
1439 displaced_step_dump_bytes (gdb_stdlog,
1440 displaced->step_saved_copy,
1441 len);
237fc4c9
PA
1442 };
1443
1444 closure = gdbarch_displaced_step_copy_insn (gdbarch,
ad53cd71 1445 original, copy, regcache);
237fc4c9
PA
1446
1447 /* We don't support the fully-simulated case at present. */
1448 gdb_assert (closure);
1449
9f5a595d
UW
1450 /* Save the information we need to fix things up if the step
1451 succeeds. */
fc1cf338
PA
1452 displaced->step_ptid = ptid;
1453 displaced->step_gdbarch = gdbarch;
1454 displaced->step_closure = closure;
1455 displaced->step_original = original;
1456 displaced->step_copy = copy;
9f5a595d 1457
fc1cf338 1458 make_cleanup (displaced_step_clear_cleanup, displaced);
237fc4c9
PA
1459
1460 /* Resume execution at the copy. */
515630c5 1461 regcache_write_pc (regcache, copy);
237fc4c9 1462
ad53cd71
PA
1463 discard_cleanups (ignore_cleanups);
1464
1465 do_cleanups (old_cleanups);
237fc4c9
PA
1466
1467 if (debug_displaced)
5af949e3
UW
1468 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1469 paddress (gdbarch, copy));
237fc4c9 1470
237fc4c9
PA
1471 return 1;
1472}
1473
237fc4c9 1474static void
3e43a32a
MS
1475write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1476 const gdb_byte *myaddr, int len)
237fc4c9
PA
1477{
1478 struct cleanup *ptid_cleanup = save_inferior_ptid ();
abbb1732 1479
237fc4c9
PA
1480 inferior_ptid = ptid;
1481 write_memory (memaddr, myaddr, len);
1482 do_cleanups (ptid_cleanup);
1483}
1484
e2d96639
YQ
1485/* Restore the contents of the copy area for thread PTID. */
1486
1487static void
1488displaced_step_restore (struct displaced_step_inferior_state *displaced,
1489 ptid_t ptid)
1490{
1491 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1492
1493 write_memory_ptid (ptid, displaced->step_copy,
1494 displaced->step_saved_copy, len);
1495 if (debug_displaced)
1496 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n",
1497 target_pid_to_str (ptid),
1498 paddress (displaced->step_gdbarch,
1499 displaced->step_copy));
1500}
1501
237fc4c9 1502static void
2ea28649 1503displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal)
237fc4c9
PA
1504{
1505 struct cleanup *old_cleanups;
fc1cf338
PA
1506 struct displaced_step_inferior_state *displaced
1507 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1508
1509 /* Was any thread of this process doing a displaced step? */
1510 if (displaced == NULL)
1511 return;
237fc4c9
PA
1512
1513 /* Was this event for the pid we displaced? */
fc1cf338
PA
1514 if (ptid_equal (displaced->step_ptid, null_ptid)
1515 || ! ptid_equal (displaced->step_ptid, event_ptid))
237fc4c9
PA
1516 return;
1517
fc1cf338 1518 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
237fc4c9 1519
e2d96639 1520 displaced_step_restore (displaced, displaced->step_ptid);
237fc4c9
PA
1521
1522 /* Did the instruction complete successfully? */
a493e3e2 1523 if (signal == GDB_SIGNAL_TRAP)
237fc4c9
PA
1524 {
1525 /* Fix up the resulting state. */
fc1cf338
PA
1526 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1527 displaced->step_closure,
1528 displaced->step_original,
1529 displaced->step_copy,
1530 get_thread_regcache (displaced->step_ptid));
237fc4c9
PA
1531 }
1532 else
1533 {
1534 /* Since the instruction didn't complete, all we can do is
1535 relocate the PC. */
515630c5
UW
1536 struct regcache *regcache = get_thread_regcache (event_ptid);
1537 CORE_ADDR pc = regcache_read_pc (regcache);
abbb1732 1538
fc1cf338 1539 pc = displaced->step_original + (pc - displaced->step_copy);
515630c5 1540 regcache_write_pc (regcache, pc);
237fc4c9
PA
1541 }
1542
1543 do_cleanups (old_cleanups);
1544
fc1cf338 1545 displaced->step_ptid = null_ptid;
1c5cfe86 1546
237fc4c9 1547 /* Are there any pending displaced stepping requests? If so, run
fc1cf338
PA
1548 one now. Leave the state object around, since we're likely to
1549 need it again soon. */
1550 while (displaced->step_request_queue)
237fc4c9
PA
1551 {
1552 struct displaced_step_request *head;
1553 ptid_t ptid;
5af949e3 1554 struct regcache *regcache;
929dfd4f 1555 struct gdbarch *gdbarch;
1c5cfe86 1556 CORE_ADDR actual_pc;
6c95b8df 1557 struct address_space *aspace;
237fc4c9 1558
fc1cf338 1559 head = displaced->step_request_queue;
237fc4c9 1560 ptid = head->ptid;
fc1cf338 1561 displaced->step_request_queue = head->next;
237fc4c9
PA
1562 xfree (head);
1563
ad53cd71
PA
1564 context_switch (ptid);
1565
5af949e3
UW
1566 regcache = get_thread_regcache (ptid);
1567 actual_pc = regcache_read_pc (regcache);
6c95b8df 1568 aspace = get_regcache_aspace (regcache);
1c5cfe86 1569
6c95b8df 1570 if (breakpoint_here_p (aspace, actual_pc))
ad53cd71 1571 {
1c5cfe86
PA
1572 if (debug_displaced)
1573 fprintf_unfiltered (gdb_stdlog,
1574 "displaced: stepping queued %s now\n",
1575 target_pid_to_str (ptid));
1576
1577 displaced_step_prepare (ptid);
1578
929dfd4f
JB
1579 gdbarch = get_regcache_arch (regcache);
1580
1c5cfe86
PA
1581 if (debug_displaced)
1582 {
929dfd4f 1583 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1c5cfe86
PA
1584 gdb_byte buf[4];
1585
5af949e3
UW
1586 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1587 paddress (gdbarch, actual_pc));
1c5cfe86
PA
1588 read_memory (actual_pc, buf, sizeof (buf));
1589 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1590 }
1591
fc1cf338
PA
1592 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1593 displaced->step_closure))
a493e3e2 1594 target_resume (ptid, 1, GDB_SIGNAL_0);
99e40580 1595 else
a493e3e2 1596 target_resume (ptid, 0, GDB_SIGNAL_0);
1c5cfe86
PA
1597
1598 /* Done, we're stepping a thread. */
1599 break;
ad53cd71 1600 }
1c5cfe86
PA
1601 else
1602 {
1603 int step;
1604 struct thread_info *tp = inferior_thread ();
1605
1606 /* The breakpoint we were sitting under has since been
1607 removed. */
16c381f0 1608 tp->control.trap_expected = 0;
1c5cfe86
PA
1609
1610 /* Go back to what we were trying to do. */
1611 step = currently_stepping (tp);
ad53cd71 1612
1c5cfe86 1613 if (debug_displaced)
3e43a32a 1614 fprintf_unfiltered (gdb_stdlog,
27d2932e 1615 "displaced: breakpoint is gone: %s, step(%d)\n",
1c5cfe86
PA
1616 target_pid_to_str (tp->ptid), step);
1617
a493e3e2
PA
1618 target_resume (ptid, step, GDB_SIGNAL_0);
1619 tp->suspend.stop_signal = GDB_SIGNAL_0;
1c5cfe86
PA
1620
1621 /* This request was discarded. See if there's any other
1622 thread waiting for its turn. */
1623 }
237fc4c9
PA
1624 }
1625}
1626
5231c1fd
PA
1627/* Update global variables holding ptids to hold NEW_PTID if they were
1628 holding OLD_PTID. */
1629static void
1630infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1631{
1632 struct displaced_step_request *it;
fc1cf338 1633 struct displaced_step_inferior_state *displaced;
5231c1fd
PA
1634
1635 if (ptid_equal (inferior_ptid, old_ptid))
1636 inferior_ptid = new_ptid;
1637
1638 if (ptid_equal (singlestep_ptid, old_ptid))
1639 singlestep_ptid = new_ptid;
1640
fc1cf338
PA
1641 for (displaced = displaced_step_inferior_states;
1642 displaced;
1643 displaced = displaced->next)
1644 {
1645 if (ptid_equal (displaced->step_ptid, old_ptid))
1646 displaced->step_ptid = new_ptid;
1647
1648 for (it = displaced->step_request_queue; it; it = it->next)
1649 if (ptid_equal (it->ptid, old_ptid))
1650 it->ptid = new_ptid;
1651 }
5231c1fd
PA
1652}
1653
237fc4c9
PA
1654\f
1655/* Resuming. */
c906108c
SS
1656
1657/* Things to clean up if we QUIT out of resume (). */
c906108c 1658static void
74b7792f 1659resume_cleanups (void *ignore)
c906108c
SS
1660{
1661 normal_stop ();
1662}
1663
53904c9e
AC
1664static const char schedlock_off[] = "off";
1665static const char schedlock_on[] = "on";
1666static const char schedlock_step[] = "step";
40478521 1667static const char *const scheduler_enums[] = {
ef346e04
AC
1668 schedlock_off,
1669 schedlock_on,
1670 schedlock_step,
1671 NULL
1672};
920d2a44
AC
1673static const char *scheduler_mode = schedlock_off;
1674static void
1675show_scheduler_mode (struct ui_file *file, int from_tty,
1676 struct cmd_list_element *c, const char *value)
1677{
3e43a32a
MS
1678 fprintf_filtered (file,
1679 _("Mode for locking scheduler "
1680 "during execution is \"%s\".\n"),
920d2a44
AC
1681 value);
1682}
c906108c
SS
1683
1684static void
96baa820 1685set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
c906108c 1686{
eefe576e
AC
1687 if (!target_can_lock_scheduler)
1688 {
1689 scheduler_mode = schedlock_off;
1690 error (_("Target '%s' cannot support this command."), target_shortname);
1691 }
c906108c
SS
1692}
1693
d4db2f36
PA
1694/* True if execution commands resume all threads of all processes by
1695 default; otherwise, resume only threads of the current inferior
1696 process. */
1697int sched_multi = 0;
1698
2facfe5c
DD
1699/* Try to setup for software single stepping over the specified location.
1700 Return 1 if target_resume() should use hardware single step.
1701
1702 GDBARCH the current gdbarch.
1703 PC the location to step over. */
1704
1705static int
1706maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1707{
1708 int hw_step = 1;
1709
f02253f1
HZ
1710 if (execution_direction == EXEC_FORWARD
1711 && gdbarch_software_single_step_p (gdbarch)
99e40580 1712 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
2facfe5c 1713 {
99e40580
UW
1714 hw_step = 0;
1715 /* Do not pull these breakpoints until after a `wait' in
1777feb0 1716 `wait_for_inferior'. */
99e40580
UW
1717 singlestep_breakpoints_inserted_p = 1;
1718 singlestep_ptid = inferior_ptid;
1719 singlestep_pc = pc;
2facfe5c
DD
1720 }
1721 return hw_step;
1722}
c906108c 1723
09cee04b
PA
1724/* Return a ptid representing the set of threads that we will proceed,
1725 in the perspective of the user/frontend. We may actually resume
1726 fewer threads at first, e.g., if a thread is stopped at a
b136cd05
PA
1727 breakpoint that needs stepping-off, but that should not be visible
1728 to the user/frontend, and neither should the frontend/user be
1729 allowed to proceed any of the threads that happen to be stopped for
09cee04b
PA
1730 internal run control handling, if a previous command wanted them
1731 resumed. */
1732
1733ptid_t
1734user_visible_resume_ptid (int step)
1735{
1736 /* By default, resume all threads of all processes. */
1737 ptid_t resume_ptid = RESUME_ALL;
1738
1739 /* Maybe resume only all threads of the current process. */
1740 if (!sched_multi && target_supports_multi_process ())
1741 {
1742 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1743 }
1744
1745 /* Maybe resume a single thread after all. */
1746 if (non_stop)
1747 {
1748 /* With non-stop mode on, threads are always handled
1749 individually. */
1750 resume_ptid = inferior_ptid;
1751 }
1752 else if ((scheduler_mode == schedlock_on)
1753 || (scheduler_mode == schedlock_step
1754 && (step || singlestep_breakpoints_inserted_p)))
1755 {
1756 /* User-settable 'scheduler' mode requires solo thread resume. */
1757 resume_ptid = inferior_ptid;
1758 }
1759
1760 return resume_ptid;
1761}
1762
c906108c
SS
1763/* Resume the inferior, but allow a QUIT. This is useful if the user
1764 wants to interrupt some lengthy single-stepping operation
1765 (for child processes, the SIGINT goes to the inferior, and so
1766 we get a SIGINT random_signal, but for remote debugging and perhaps
1767 other targets, that's not true).
1768
1769 STEP nonzero if we should step (zero to continue instead).
1770 SIG is the signal to give the inferior (zero for none). */
1771void
2ea28649 1772resume (int step, enum gdb_signal sig)
c906108c
SS
1773{
1774 int should_resume = 1;
74b7792f 1775 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
515630c5
UW
1776 struct regcache *regcache = get_current_regcache ();
1777 struct gdbarch *gdbarch = get_regcache_arch (regcache);
4e1c45ea 1778 struct thread_info *tp = inferior_thread ();
515630c5 1779 CORE_ADDR pc = regcache_read_pc (regcache);
6c95b8df 1780 struct address_space *aspace = get_regcache_aspace (regcache);
c7e8a53c 1781
c906108c
SS
1782 QUIT;
1783
74609e71
YQ
1784 if (current_inferior ()->waiting_for_vfork_done)
1785 {
48f9886d
PA
1786 /* Don't try to single-step a vfork parent that is waiting for
1787 the child to get out of the shared memory region (by exec'ing
1788 or exiting). This is particularly important on software
1789 single-step archs, as the child process would trip on the
1790 software single step breakpoint inserted for the parent
1791 process. Since the parent will not actually execute any
1792 instruction until the child is out of the shared region (such
1793 are vfork's semantics), it is safe to simply continue it.
1794 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1795 the parent, and tell it to `keep_going', which automatically
1796 re-sets it stepping. */
74609e71
YQ
1797 if (debug_infrun)
1798 fprintf_unfiltered (gdb_stdlog,
1799 "infrun: resume : clear step\n");
1800 step = 0;
1801 }
1802
527159b7 1803 if (debug_infrun)
237fc4c9 1804 fprintf_unfiltered (gdb_stdlog,
c9737c08 1805 "infrun: resume (step=%d, signal=%s), "
0d9a9a5f 1806 "trap_expected=%d, current thread [%s] at %s\n",
c9737c08
PA
1807 step, gdb_signal_to_symbol_string (sig),
1808 tp->control.trap_expected,
0d9a9a5f
PA
1809 target_pid_to_str (inferior_ptid),
1810 paddress (gdbarch, pc));
c906108c 1811
c2c6d25f
JM
1812 /* Normally, by the time we reach `resume', the breakpoints are either
1813 removed or inserted, as appropriate. The exception is if we're sitting
1814 at a permanent breakpoint; we need to step over it, but permanent
1815 breakpoints can't be removed. So we have to test for it here. */
6c95b8df 1816 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
6d350bb5 1817 {
515630c5
UW
1818 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1819 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
6d350bb5 1820 else
ac74f770
MS
1821 error (_("\
1822The program is stopped at a permanent breakpoint, but GDB does not know\n\
1823how to step past a permanent breakpoint on this architecture. Try using\n\
1824a command like `return' or `jump' to continue execution."));
6d350bb5 1825 }
c2c6d25f 1826
c1e36e3e
PA
1827 /* If we have a breakpoint to step over, make sure to do a single
1828 step only. Same if we have software watchpoints. */
1829 if (tp->control.trap_expected || bpstat_should_step ())
1830 tp->control.may_range_step = 0;
1831
237fc4c9
PA
1832 /* If enabled, step over breakpoints by executing a copy of the
1833 instruction at a different address.
1834
1835 We can't use displaced stepping when we have a signal to deliver;
1836 the comments for displaced_step_prepare explain why. The
1837 comments in the handle_inferior event for dealing with 'random
74609e71
YQ
1838 signals' explain what we do instead.
1839
1840 We can't use displaced stepping when we are waiting for vfork_done
1841 event, displaced stepping breaks the vfork child similarly as single
1842 step software breakpoint. */
515630c5 1843 if (use_displaced_stepping (gdbarch)
16c381f0 1844 && (tp->control.trap_expected
929dfd4f 1845 || (step && gdbarch_software_single_step_p (gdbarch)))
a493e3e2 1846 && sig == GDB_SIGNAL_0
74609e71 1847 && !current_inferior ()->waiting_for_vfork_done)
237fc4c9 1848 {
fc1cf338
PA
1849 struct displaced_step_inferior_state *displaced;
1850
237fc4c9 1851 if (!displaced_step_prepare (inferior_ptid))
d56b7306
VP
1852 {
1853 /* Got placed in displaced stepping queue. Will be resumed
1854 later when all the currently queued displaced stepping
7f7efbd9
VP
1855 requests finish. The thread is not executing at this point,
1856 and the call to set_executing will be made later. But we
1857 need to call set_running here, since from frontend point of view,
1858 the thread is running. */
1859 set_running (inferior_ptid, 1);
d56b7306
VP
1860 discard_cleanups (old_cleanups);
1861 return;
1862 }
99e40580 1863
ca7781d2
LM
1864 /* Update pc to reflect the new address from which we will execute
1865 instructions due to displaced stepping. */
1866 pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
1867
fc1cf338
PA
1868 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1869 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1870 displaced->step_closure);
237fc4c9
PA
1871 }
1872
2facfe5c 1873 /* Do we need to do it the hard way, w/temp breakpoints? */
99e40580 1874 else if (step)
2facfe5c 1875 step = maybe_software_singlestep (gdbarch, pc);
c906108c 1876
30852783
UW
1877 /* Currently, our software single-step implementation leads to different
1878 results than hardware single-stepping in one situation: when stepping
1879 into delivering a signal which has an associated signal handler,
1880 hardware single-step will stop at the first instruction of the handler,
1881 while software single-step will simply skip execution of the handler.
1882
1883 For now, this difference in behavior is accepted since there is no
1884 easy way to actually implement single-stepping into a signal handler
1885 without kernel support.
1886
1887 However, there is one scenario where this difference leads to follow-on
1888 problems: if we're stepping off a breakpoint by removing all breakpoints
1889 and then single-stepping. In this case, the software single-step
1890 behavior means that even if there is a *breakpoint* in the signal
1891 handler, GDB still would not stop.
1892
1893 Fortunately, we can at least fix this particular issue. We detect
1894 here the case where we are about to deliver a signal while software
1895 single-stepping with breakpoints removed. In this situation, we
1896 revert the decisions to remove all breakpoints and insert single-
1897 step breakpoints, and instead we install a step-resume breakpoint
1898 at the current address, deliver the signal without stepping, and
1899 once we arrive back at the step-resume breakpoint, actually step
1900 over the breakpoint we originally wanted to step over. */
1901 if (singlestep_breakpoints_inserted_p
a493e3e2 1902 && tp->control.trap_expected && sig != GDB_SIGNAL_0)
30852783
UW
1903 {
1904 /* If we have nested signals or a pending signal is delivered
1905 immediately after a handler returns, might might already have
1906 a step-resume breakpoint set on the earlier handler. We cannot
1907 set another step-resume breakpoint; just continue on until the
1908 original breakpoint is hit. */
1909 if (tp->control.step_resume_breakpoint == NULL)
1910 {
2c03e5be 1911 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
30852783
UW
1912 tp->step_after_step_resume_breakpoint = 1;
1913 }
1914
1915 remove_single_step_breakpoints ();
1916 singlestep_breakpoints_inserted_p = 0;
1917
31e77af2 1918 clear_step_over_info ();
30852783 1919 tp->control.trap_expected = 0;
31e77af2
PA
1920
1921 insert_breakpoints ();
30852783
UW
1922 }
1923
c906108c
SS
1924 if (should_resume)
1925 {
39f77062 1926 ptid_t resume_ptid;
dfcd3bfb 1927
cd76b0b7
VP
1928 /* If STEP is set, it's a request to use hardware stepping
1929 facilities. But in that case, we should never
1930 use singlestep breakpoint. */
1931 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1932
d4db2f36
PA
1933 /* Decide the set of threads to ask the target to resume. Start
1934 by assuming everything will be resumed, than narrow the set
1935 by applying increasingly restricting conditions. */
09cee04b 1936 resume_ptid = user_visible_resume_ptid (step);
d4db2f36
PA
1937
1938 /* Maybe resume a single thread after all. */
2adfaa28
PA
1939 if ((step || singlestep_breakpoints_inserted_p)
1940 && tp->control.trap_expected)
cd76b0b7 1941 {
74960c60
VP
1942 /* We're allowing a thread to run past a breakpoint it has
1943 hit, by single-stepping the thread with the breakpoint
1944 removed. In which case, we need to single-step only this
1945 thread, and keep others stopped, as they can miss this
31e77af2 1946 breakpoint if allowed to run. */
ef5cf84e 1947 resume_ptid = inferior_ptid;
c906108c 1948 }
ef5cf84e 1949
515630c5 1950 if (gdbarch_cannot_step_breakpoint (gdbarch))
c4ed33b9
AC
1951 {
1952 /* Most targets can step a breakpoint instruction, thus
1953 executing it normally. But if this one cannot, just
1954 continue and we will hit it anyway. */
6c95b8df 1955 if (step && breakpoint_inserted_here_p (aspace, pc))
c4ed33b9
AC
1956 step = 0;
1957 }
237fc4c9
PA
1958
1959 if (debug_displaced
515630c5 1960 && use_displaced_stepping (gdbarch)
16c381f0 1961 && tp->control.trap_expected)
237fc4c9 1962 {
515630c5 1963 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
5af949e3 1964 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
515630c5 1965 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
237fc4c9
PA
1966 gdb_byte buf[4];
1967
5af949e3
UW
1968 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1969 paddress (resume_gdbarch, actual_pc));
237fc4c9
PA
1970 read_memory (actual_pc, buf, sizeof (buf));
1971 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1972 }
1973
c1e36e3e
PA
1974 if (tp->control.may_range_step)
1975 {
1976 /* If we're resuming a thread with the PC out of the step
1977 range, then we're doing some nested/finer run control
1978 operation, like stepping the thread out of the dynamic
1979 linker or the displaced stepping scratch pad. We
1980 shouldn't have allowed a range step then. */
1981 gdb_assert (pc_in_thread_step_range (pc, tp));
1982 }
1983
e58b0e63
PA
1984 /* Install inferior's terminal modes. */
1985 target_terminal_inferior ();
1986
2020b7ab
PA
1987 /* Avoid confusing the next resume, if the next stop/resume
1988 happens to apply to another thread. */
a493e3e2 1989 tp->suspend.stop_signal = GDB_SIGNAL_0;
607cecd2 1990
2455069d
UW
1991 /* Advise target which signals may be handled silently. If we have
1992 removed breakpoints because we are stepping over one (which can
1993 happen only if we are not using displaced stepping), we need to
1994 receive all signals to avoid accidentally skipping a breakpoint
1995 during execution of a signal handler. */
1996 if ((step || singlestep_breakpoints_inserted_p)
1997 && tp->control.trap_expected
1998 && !use_displaced_stepping (gdbarch))
1999 target_pass_signals (0, NULL);
2000 else
a493e3e2 2001 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
2455069d 2002
607cecd2 2003 target_resume (resume_ptid, step, sig);
c906108c
SS
2004 }
2005
2006 discard_cleanups (old_cleanups);
2007}
2008\f
237fc4c9 2009/* Proceeding. */
c906108c
SS
2010
2011/* Clear out all variables saying what to do when inferior is continued.
2012 First do this, then set the ones you want, then call `proceed'. */
2013
a7212384
UW
2014static void
2015clear_proceed_status_thread (struct thread_info *tp)
c906108c 2016{
a7212384
UW
2017 if (debug_infrun)
2018 fprintf_unfiltered (gdb_stdlog,
2019 "infrun: clear_proceed_status_thread (%s)\n",
2020 target_pid_to_str (tp->ptid));
d6b48e9c 2021
16c381f0
JK
2022 tp->control.trap_expected = 0;
2023 tp->control.step_range_start = 0;
2024 tp->control.step_range_end = 0;
c1e36e3e 2025 tp->control.may_range_step = 0;
16c381f0
JK
2026 tp->control.step_frame_id = null_frame_id;
2027 tp->control.step_stack_frame_id = null_frame_id;
2028 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
a7212384 2029 tp->stop_requested = 0;
4e1c45ea 2030
16c381f0 2031 tp->control.stop_step = 0;
32400beb 2032
16c381f0 2033 tp->control.proceed_to_finish = 0;
414c69f7 2034
a7212384 2035 /* Discard any remaining commands or status from previous stop. */
16c381f0 2036 bpstat_clear (&tp->control.stop_bpstat);
a7212384 2037}
32400beb 2038
a7212384
UW
2039static int
2040clear_proceed_status_callback (struct thread_info *tp, void *data)
2041{
2042 if (is_exited (tp->ptid))
2043 return 0;
d6b48e9c 2044
a7212384
UW
2045 clear_proceed_status_thread (tp);
2046 return 0;
2047}
2048
2049void
2050clear_proceed_status (void)
2051{
6c95b8df
PA
2052 if (!non_stop)
2053 {
2054 /* In all-stop mode, delete the per-thread status of all
2055 threads, even if inferior_ptid is null_ptid, there may be
2056 threads on the list. E.g., we may be launching a new
2057 process, while selecting the executable. */
2058 iterate_over_threads (clear_proceed_status_callback, NULL);
2059 }
2060
a7212384
UW
2061 if (!ptid_equal (inferior_ptid, null_ptid))
2062 {
2063 struct inferior *inferior;
2064
2065 if (non_stop)
2066 {
6c95b8df
PA
2067 /* If in non-stop mode, only delete the per-thread status of
2068 the current thread. */
a7212384
UW
2069 clear_proceed_status_thread (inferior_thread ());
2070 }
6c95b8df 2071
d6b48e9c 2072 inferior = current_inferior ();
16c381f0 2073 inferior->control.stop_soon = NO_STOP_QUIETLY;
4e1c45ea
PA
2074 }
2075
c906108c 2076 stop_after_trap = 0;
f3b1572e 2077
31e77af2
PA
2078 clear_step_over_info ();
2079
f3b1572e 2080 observer_notify_about_to_proceed ();
c906108c 2081
d5c31457
UW
2082 if (stop_registers)
2083 {
2084 regcache_xfree (stop_registers);
2085 stop_registers = NULL;
2086 }
c906108c
SS
2087}
2088
99619bea
PA
2089/* Returns true if TP is still stopped at a breakpoint that needs
2090 stepping-over in order to make progress. If the breakpoint is gone
2091 meanwhile, we can skip the whole step-over dance. */
ea67f13b
DJ
2092
2093static int
99619bea
PA
2094thread_still_needs_step_over (struct thread_info *tp)
2095{
2096 if (tp->stepping_over_breakpoint)
2097 {
2098 struct regcache *regcache = get_thread_regcache (tp->ptid);
2099
2100 if (breakpoint_here_p (get_regcache_aspace (regcache),
2101 regcache_read_pc (regcache)))
2102 return 1;
2103
2104 tp->stepping_over_breakpoint = 0;
2105 }
2106
2107 return 0;
2108}
2109
2110/* Look a thread other than EXCEPT that has previously reported a
2111 breakpoint event, and thus needs a step-over in order to make
2112 progress. Returns NULL is none is found. STEP indicates whether
2113 we're about to step the current thread, in order to decide whether
2114 "set scheduler-locking step" applies. */
2115
2116static struct thread_info *
2117find_thread_needs_step_over (int step, struct thread_info *except)
ea67f13b 2118{
5a437975 2119 int schedlock_enabled;
99619bea 2120 struct thread_info *tp, *current;
5a437975
DE
2121
2122 /* With non-stop mode on, threads are always handled individually. */
2123 gdb_assert (! non_stop);
ea67f13b 2124
5a437975
DE
2125 schedlock_enabled = (scheduler_mode == schedlock_on
2126 || (scheduler_mode == schedlock_step
2127 && step));
2128
99619bea 2129 current = inferior_thread ();
d4db2f36 2130
99619bea
PA
2131 /* If scheduler locking applies, we can avoid iterating over all
2132 threads. */
2133 if (schedlock_enabled)
ea67f13b 2134 {
99619bea
PA
2135 if (except != current
2136 && thread_still_needs_step_over (current))
2137 return current;
515630c5 2138
99619bea
PA
2139 return NULL;
2140 }
0d9a9a5f 2141
99619bea
PA
2142 ALL_THREADS (tp)
2143 {
2144 /* Ignore the EXCEPT thread. */
2145 if (tp == except)
2146 continue;
2147 /* Ignore threads of processes we're not resuming. */
2148 if (!sched_multi
2149 && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
2150 continue;
2151
2152 if (thread_still_needs_step_over (tp))
2153 return tp;
ea67f13b
DJ
2154 }
2155
99619bea 2156 return NULL;
ea67f13b 2157}
e4846b08 2158
c906108c
SS
2159/* Basic routine for continuing the program in various fashions.
2160
2161 ADDR is the address to resume at, or -1 for resume where stopped.
2162 SIGGNAL is the signal to give it, or 0 for none,
c5aa993b 2163 or -1 for act according to how it stopped.
c906108c 2164 STEP is nonzero if should trap after one instruction.
c5aa993b
JM
2165 -1 means return after that and print nothing.
2166 You should probably set various step_... variables
2167 before calling here, if you are stepping.
c906108c
SS
2168
2169 You should call clear_proceed_status before calling proceed. */
2170
2171void
2ea28649 2172proceed (CORE_ADDR addr, enum gdb_signal siggnal, int step)
c906108c 2173{
e58b0e63
PA
2174 struct regcache *regcache;
2175 struct gdbarch *gdbarch;
4e1c45ea 2176 struct thread_info *tp;
e58b0e63 2177 CORE_ADDR pc;
6c95b8df 2178 struct address_space *aspace;
c906108c 2179
e58b0e63
PA
2180 /* If we're stopped at a fork/vfork, follow the branch set by the
2181 "set follow-fork-mode" command; otherwise, we'll just proceed
2182 resuming the current thread. */
2183 if (!follow_fork ())
2184 {
2185 /* The target for some reason decided not to resume. */
2186 normal_stop ();
f148b27e
PA
2187 if (target_can_async_p ())
2188 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
e58b0e63
PA
2189 return;
2190 }
2191
842951eb
PA
2192 /* We'll update this if & when we switch to a new thread. */
2193 previous_inferior_ptid = inferior_ptid;
2194
e58b0e63
PA
2195 regcache = get_current_regcache ();
2196 gdbarch = get_regcache_arch (regcache);
6c95b8df 2197 aspace = get_regcache_aspace (regcache);
e58b0e63 2198 pc = regcache_read_pc (regcache);
2adfaa28 2199 tp = inferior_thread ();
e58b0e63 2200
c906108c 2201 if (step > 0)
515630c5 2202 step_start_function = find_pc_function (pc);
c906108c
SS
2203 if (step < 0)
2204 stop_after_trap = 1;
2205
99619bea
PA
2206 /* Fill in with reasonable starting values. */
2207 init_thread_stepping_state (tp);
2208
2acceee2 2209 if (addr == (CORE_ADDR) -1)
c906108c 2210 {
6c95b8df 2211 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
b2175913 2212 && execution_direction != EXEC_REVERSE)
3352ef37
AC
2213 /* There is a breakpoint at the address we will resume at,
2214 step one instruction before inserting breakpoints so that
2215 we do not stop right away (and report a second hit at this
b2175913
MS
2216 breakpoint).
2217
2218 Note, we don't do this in reverse, because we won't
2219 actually be executing the breakpoint insn anyway.
2220 We'll be (un-)executing the previous instruction. */
99619bea 2221 tp->stepping_over_breakpoint = 1;
515630c5
UW
2222 else if (gdbarch_single_step_through_delay_p (gdbarch)
2223 && gdbarch_single_step_through_delay (gdbarch,
2224 get_current_frame ()))
3352ef37
AC
2225 /* We stepped onto an instruction that needs to be stepped
2226 again before re-inserting the breakpoint, do so. */
99619bea 2227 tp->stepping_over_breakpoint = 1;
c906108c
SS
2228 }
2229 else
2230 {
515630c5 2231 regcache_write_pc (regcache, addr);
c906108c
SS
2232 }
2233
527159b7 2234 if (debug_infrun)
8a9de0e4 2235 fprintf_unfiltered (gdb_stdlog,
c9737c08
PA
2236 "infrun: proceed (addr=%s, signal=%s, step=%d)\n",
2237 paddress (gdbarch, addr),
2238 gdb_signal_to_symbol_string (siggnal), step);
527159b7 2239
94cc34af
PA
2240 if (non_stop)
2241 /* In non-stop, each thread is handled individually. The context
2242 must already be set to the right thread here. */
2243 ;
2244 else
2245 {
99619bea
PA
2246 struct thread_info *step_over;
2247
94cc34af
PA
2248 /* In a multi-threaded task we may select another thread and
2249 then continue or step.
c906108c 2250
94cc34af
PA
2251 But if the old thread was stopped at a breakpoint, it will
2252 immediately cause another breakpoint stop without any
2253 execution (i.e. it will report a breakpoint hit incorrectly).
2254 So we must step over it first.
c906108c 2255
99619bea
PA
2256 Look for a thread other than the current (TP) that reported a
2257 breakpoint hit and hasn't been resumed yet since. */
2258 step_over = find_thread_needs_step_over (step, tp);
2259 if (step_over != NULL)
2adfaa28 2260 {
99619bea
PA
2261 if (debug_infrun)
2262 fprintf_unfiltered (gdb_stdlog,
2263 "infrun: need to step-over [%s] first\n",
2264 target_pid_to_str (step_over->ptid));
2265
2266 /* Store the prev_pc for the stepping thread too, needed by
2267 switch_back_to_stepping thread. */
2268 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2269 switch_to_thread (step_over->ptid);
2270 tp = step_over;
2adfaa28 2271 }
94cc34af 2272 }
c906108c 2273
31e77af2
PA
2274 /* If we need to step over a breakpoint, and we're not using
2275 displaced stepping to do so, insert all breakpoints (watchpoints,
2276 etc.) but the one we're stepping over, step one instruction, and
2277 then re-insert the breakpoint when that step is finished. */
99619bea 2278 if (tp->stepping_over_breakpoint && !use_displaced_stepping (gdbarch))
30852783 2279 {
31e77af2
PA
2280 struct regcache *regcache = get_current_regcache ();
2281
2282 set_step_over_info (get_regcache_aspace (regcache),
2283 regcache_read_pc (regcache));
30852783 2284 }
31e77af2
PA
2285 else
2286 clear_step_over_info ();
30852783 2287
31e77af2 2288 insert_breakpoints ();
30852783 2289
99619bea
PA
2290 tp->control.trap_expected = tp->stepping_over_breakpoint;
2291
2020b7ab
PA
2292 if (!non_stop)
2293 {
2294 /* Pass the last stop signal to the thread we're resuming,
2295 irrespective of whether the current thread is the thread that
2296 got the last event or not. This was historically GDB's
2297 behaviour before keeping a stop_signal per thread. */
2298
2299 struct thread_info *last_thread;
2300 ptid_t last_ptid;
2301 struct target_waitstatus last_status;
2302
2303 get_last_target_status (&last_ptid, &last_status);
2304 if (!ptid_equal (inferior_ptid, last_ptid)
2305 && !ptid_equal (last_ptid, null_ptid)
2306 && !ptid_equal (last_ptid, minus_one_ptid))
2307 {
e09875d4 2308 last_thread = find_thread_ptid (last_ptid);
2020b7ab
PA
2309 if (last_thread)
2310 {
16c381f0 2311 tp->suspend.stop_signal = last_thread->suspend.stop_signal;
a493e3e2 2312 last_thread->suspend.stop_signal = GDB_SIGNAL_0;
2020b7ab
PA
2313 }
2314 }
2315 }
2316
a493e3e2 2317 if (siggnal != GDB_SIGNAL_DEFAULT)
16c381f0 2318 tp->suspend.stop_signal = siggnal;
c906108c
SS
2319 /* If this signal should not be seen by program,
2320 give it zero. Used for debugging signals. */
16c381f0 2321 else if (!signal_program[tp->suspend.stop_signal])
a493e3e2 2322 tp->suspend.stop_signal = GDB_SIGNAL_0;
c906108c
SS
2323
2324 annotate_starting ();
2325
2326 /* Make sure that output from GDB appears before output from the
2327 inferior. */
2328 gdb_flush (gdb_stdout);
2329
e4846b08
JJ
2330 /* Refresh prev_pc value just prior to resuming. This used to be
2331 done in stop_stepping, however, setting prev_pc there did not handle
2332 scenarios such as inferior function calls or returning from
2333 a function via the return command. In those cases, the prev_pc
2334 value was not set properly for subsequent commands. The prev_pc value
2335 is used to initialize the starting line number in the ecs. With an
2336 invalid value, the gdb next command ends up stopping at the position
2337 represented by the next line table entry past our start position.
2338 On platforms that generate one line table entry per line, this
2339 is not a problem. However, on the ia64, the compiler generates
2340 extraneous line table entries that do not increase the line number.
2341 When we issue the gdb next command on the ia64 after an inferior call
2342 or a return command, we often end up a few instructions forward, still
2343 within the original line we started.
2344
d5cd6034
JB
2345 An attempt was made to refresh the prev_pc at the same time the
2346 execution_control_state is initialized (for instance, just before
2347 waiting for an inferior event). But this approach did not work
2348 because of platforms that use ptrace, where the pc register cannot
2349 be read unless the inferior is stopped. At that point, we are not
2350 guaranteed the inferior is stopped and so the regcache_read_pc() call
2351 can fail. Setting the prev_pc value here ensures the value is updated
2352 correctly when the inferior is stopped. */
4e1c45ea 2353 tp->prev_pc = regcache_read_pc (get_current_regcache ());
e4846b08 2354
59f0d5d9
PA
2355 /* Reset to normal state. */
2356 init_infwait_state ();
2357
c906108c 2358 /* Resume inferior. */
99619bea 2359 resume (tp->control.trap_expected || step || bpstat_should_step (),
0de5618e 2360 tp->suspend.stop_signal);
c906108c
SS
2361
2362 /* Wait for it to stop (if not standalone)
2363 and in any case decode why it stopped, and act accordingly. */
43ff13b4 2364 /* Do this only if we are not using the event loop, or if the target
1777feb0 2365 does not support asynchronous execution. */
362646f5 2366 if (!target_can_async_p ())
43ff13b4 2367 {
e4c8541f 2368 wait_for_inferior ();
43ff13b4
JM
2369 normal_stop ();
2370 }
c906108c 2371}
c906108c
SS
2372\f
2373
2374/* Start remote-debugging of a machine over a serial link. */
96baa820 2375
c906108c 2376void
8621d6a9 2377start_remote (int from_tty)
c906108c 2378{
d6b48e9c 2379 struct inferior *inferior;
d6b48e9c
PA
2380
2381 inferior = current_inferior ();
16c381f0 2382 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
43ff13b4 2383
1777feb0 2384 /* Always go on waiting for the target, regardless of the mode. */
6426a772 2385 /* FIXME: cagney/1999-09-23: At present it isn't possible to
7e73cedf 2386 indicate to wait_for_inferior that a target should timeout if
6426a772
JM
2387 nothing is returned (instead of just blocking). Because of this,
2388 targets expecting an immediate response need to, internally, set
2389 things up so that the target_wait() is forced to eventually
1777feb0 2390 timeout. */
6426a772
JM
2391 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2392 differentiate to its caller what the state of the target is after
2393 the initial open has been performed. Here we're assuming that
2394 the target has stopped. It should be possible to eventually have
2395 target_open() return to the caller an indication that the target
2396 is currently running and GDB state should be set to the same as
1777feb0 2397 for an async run. */
e4c8541f 2398 wait_for_inferior ();
8621d6a9
DJ
2399
2400 /* Now that the inferior has stopped, do any bookkeeping like
2401 loading shared libraries. We want to do this before normal_stop,
2402 so that the displayed frame is up to date. */
2403 post_create_inferior (&current_target, from_tty);
2404
6426a772 2405 normal_stop ();
c906108c
SS
2406}
2407
2408/* Initialize static vars when a new inferior begins. */
2409
2410void
96baa820 2411init_wait_for_inferior (void)
c906108c
SS
2412{
2413 /* These are meaningless until the first time through wait_for_inferior. */
c906108c 2414
c906108c
SS
2415 breakpoint_init_inferior (inf_starting);
2416
c906108c 2417 clear_proceed_status ();
9f976b41 2418
ca005067 2419 target_last_wait_ptid = minus_one_ptid;
237fc4c9 2420
842951eb 2421 previous_inferior_ptid = inferior_ptid;
0d1e5fa7
PA
2422 init_infwait_state ();
2423
edb3359d
DJ
2424 /* Discard any skipped inlined frames. */
2425 clear_inline_frame_state (minus_one_ptid);
2adfaa28
PA
2426
2427 singlestep_ptid = null_ptid;
2428 singlestep_pc = 0;
c906108c 2429}
237fc4c9 2430
c906108c 2431\f
b83266a0
SS
2432/* This enum encodes possible reasons for doing a target_wait, so that
2433 wfi can call target_wait in one place. (Ultimately the call will be
2434 moved out of the infinite loop entirely.) */
2435
c5aa993b
JM
2436enum infwait_states
2437{
cd0fc7c3 2438 infwait_normal_state,
d983da9c 2439 infwait_step_watch_state,
cd0fc7c3 2440 infwait_nonstep_watch_state
b83266a0
SS
2441};
2442
0d1e5fa7
PA
2443/* The PTID we'll do a target_wait on.*/
2444ptid_t waiton_ptid;
2445
2446/* Current inferior wait state. */
8870954f 2447static enum infwait_states infwait_state;
cd0fc7c3 2448
0d1e5fa7
PA
2449/* Data to be passed around while handling an event. This data is
2450 discarded between events. */
c5aa993b 2451struct execution_control_state
488f131b 2452{
0d1e5fa7 2453 ptid_t ptid;
4e1c45ea
PA
2454 /* The thread that got the event, if this was a thread event; NULL
2455 otherwise. */
2456 struct thread_info *event_thread;
2457
488f131b 2458 struct target_waitstatus ws;
7e324e48 2459 int stop_func_filled_in;
488f131b
JB
2460 CORE_ADDR stop_func_start;
2461 CORE_ADDR stop_func_end;
2c02bd72 2462 const char *stop_func_name;
488f131b 2463 int wait_some_more;
4f5d7f63
PA
2464
2465 /* We were in infwait_step_watch_state or
2466 infwait_nonstep_watch_state state, and the thread reported an
2467 event. */
2468 int stepped_after_stopped_by_watchpoint;
2adfaa28
PA
2469
2470 /* True if the event thread hit the single-step breakpoint of
2471 another thread. Thus the event doesn't cause a stop, the thread
2472 needs to be single-stepped past the single-step breakpoint before
2473 we can switch back to the original stepping thread. */
2474 int hit_singlestep_breakpoint;
488f131b
JB
2475};
2476
ec9499be 2477static void handle_inferior_event (struct execution_control_state *ecs);
cd0fc7c3 2478
568d6575
UW
2479static void handle_step_into_function (struct gdbarch *gdbarch,
2480 struct execution_control_state *ecs);
2481static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2482 struct execution_control_state *ecs);
4f5d7f63 2483static void handle_signal_stop (struct execution_control_state *ecs);
186c406b 2484static void check_exception_resume (struct execution_control_state *,
28106bc2 2485 struct frame_info *);
611c83ae 2486
104c1213
JM
2487static void stop_stepping (struct execution_control_state *ecs);
2488static void prepare_to_wait (struct execution_control_state *ecs);
d4f3574e 2489static void keep_going (struct execution_control_state *ecs);
94c57d6a 2490static void process_event_stop_test (struct execution_control_state *ecs);
c447ac0b 2491static int switch_back_to_stepped_thread (struct execution_control_state *ecs);
104c1213 2492
252fbfc8
PA
2493/* Callback for iterate over threads. If the thread is stopped, but
2494 the user/frontend doesn't know about that yet, go through
2495 normal_stop, as if the thread had just stopped now. ARG points at
2496 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2497 ptid_is_pid(PTID) is true, applies to all threads of the process
2498 pointed at by PTID. Otherwise, apply only to the thread pointed by
2499 PTID. */
2500
2501static int
2502infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2503{
2504 ptid_t ptid = * (ptid_t *) arg;
2505
2506 if ((ptid_equal (info->ptid, ptid)
2507 || ptid_equal (minus_one_ptid, ptid)
2508 || (ptid_is_pid (ptid)
2509 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2510 && is_running (info->ptid)
2511 && !is_executing (info->ptid))
2512 {
2513 struct cleanup *old_chain;
2514 struct execution_control_state ecss;
2515 struct execution_control_state *ecs = &ecss;
2516
2517 memset (ecs, 0, sizeof (*ecs));
2518
2519 old_chain = make_cleanup_restore_current_thread ();
2520
f15cb84a
YQ
2521 overlay_cache_invalid = 1;
2522 /* Flush target cache before starting to handle each event.
2523 Target was running and cache could be stale. This is just a
2524 heuristic. Running threads may modify target memory, but we
2525 don't get any event. */
2526 target_dcache_invalidate ();
2527
252fbfc8
PA
2528 /* Go through handle_inferior_event/normal_stop, so we always
2529 have consistent output as if the stop event had been
2530 reported. */
2531 ecs->ptid = info->ptid;
e09875d4 2532 ecs->event_thread = find_thread_ptid (info->ptid);
252fbfc8 2533 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
a493e3e2 2534 ecs->ws.value.sig = GDB_SIGNAL_0;
252fbfc8
PA
2535
2536 handle_inferior_event (ecs);
2537
2538 if (!ecs->wait_some_more)
2539 {
2540 struct thread_info *tp;
2541
2542 normal_stop ();
2543
fa4cd53f 2544 /* Finish off the continuations. */
252fbfc8 2545 tp = inferior_thread ();
fa4cd53f
PA
2546 do_all_intermediate_continuations_thread (tp, 1);
2547 do_all_continuations_thread (tp, 1);
252fbfc8
PA
2548 }
2549
2550 do_cleanups (old_chain);
2551 }
2552
2553 return 0;
2554}
2555
2556/* This function is attached as a "thread_stop_requested" observer.
2557 Cleanup local state that assumed the PTID was to be resumed, and
2558 report the stop to the frontend. */
2559
2c0b251b 2560static void
252fbfc8
PA
2561infrun_thread_stop_requested (ptid_t ptid)
2562{
fc1cf338 2563 struct displaced_step_inferior_state *displaced;
252fbfc8
PA
2564
2565 /* PTID was requested to stop. Remove it from the displaced
2566 stepping queue, so we don't try to resume it automatically. */
fc1cf338
PA
2567
2568 for (displaced = displaced_step_inferior_states;
2569 displaced;
2570 displaced = displaced->next)
252fbfc8 2571 {
fc1cf338 2572 struct displaced_step_request *it, **prev_next_p;
252fbfc8 2573
fc1cf338
PA
2574 it = displaced->step_request_queue;
2575 prev_next_p = &displaced->step_request_queue;
2576 while (it)
252fbfc8 2577 {
fc1cf338
PA
2578 if (ptid_match (it->ptid, ptid))
2579 {
2580 *prev_next_p = it->next;
2581 it->next = NULL;
2582 xfree (it);
2583 }
252fbfc8 2584 else
fc1cf338
PA
2585 {
2586 prev_next_p = &it->next;
2587 }
252fbfc8 2588
fc1cf338 2589 it = *prev_next_p;
252fbfc8 2590 }
252fbfc8
PA
2591 }
2592
2593 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2594}
2595
a07daef3
PA
2596static void
2597infrun_thread_thread_exit (struct thread_info *tp, int silent)
2598{
2599 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2600 nullify_last_target_wait_ptid ();
2601}
2602
4e1c45ea
PA
2603/* Callback for iterate_over_threads. */
2604
2605static int
2606delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2607{
2608 if (is_exited (info->ptid))
2609 return 0;
2610
2611 delete_step_resume_breakpoint (info);
186c406b 2612 delete_exception_resume_breakpoint (info);
4e1c45ea
PA
2613 return 0;
2614}
2615
2616/* In all-stop, delete the step resume breakpoint of any thread that
2617 had one. In non-stop, delete the step resume breakpoint of the
2618 thread that just stopped. */
2619
2620static void
2621delete_step_thread_step_resume_breakpoint (void)
2622{
2623 if (!target_has_execution
2624 || ptid_equal (inferior_ptid, null_ptid))
2625 /* If the inferior has exited, we have already deleted the step
2626 resume breakpoints out of GDB's lists. */
2627 return;
2628
2629 if (non_stop)
2630 {
2631 /* If in non-stop mode, only delete the step-resume or
2632 longjmp-resume breakpoint of the thread that just stopped
2633 stepping. */
2634 struct thread_info *tp = inferior_thread ();
abbb1732 2635
4e1c45ea 2636 delete_step_resume_breakpoint (tp);
186c406b 2637 delete_exception_resume_breakpoint (tp);
4e1c45ea
PA
2638 }
2639 else
2640 /* In all-stop mode, delete all step-resume and longjmp-resume
2641 breakpoints of any thread that had them. */
2642 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2643}
2644
1777feb0 2645/* A cleanup wrapper. */
4e1c45ea
PA
2646
2647static void
2648delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2649{
2650 delete_step_thread_step_resume_breakpoint ();
2651}
2652
223698f8
DE
2653/* Pretty print the results of target_wait, for debugging purposes. */
2654
2655static void
2656print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2657 const struct target_waitstatus *ws)
2658{
2659 char *status_string = target_waitstatus_to_string (ws);
2660 struct ui_file *tmp_stream = mem_fileopen ();
2661 char *text;
223698f8
DE
2662
2663 /* The text is split over several lines because it was getting too long.
2664 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2665 output as a unit; we want only one timestamp printed if debug_timestamp
2666 is set. */
2667
2668 fprintf_unfiltered (tmp_stream,
dfd4cc63
LM
2669 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid));
2670 if (ptid_get_pid (waiton_ptid) != -1)
223698f8
DE
2671 fprintf_unfiltered (tmp_stream,
2672 " [%s]", target_pid_to_str (waiton_ptid));
2673 fprintf_unfiltered (tmp_stream, ", status) =\n");
2674 fprintf_unfiltered (tmp_stream,
2675 "infrun: %d [%s],\n",
dfd4cc63
LM
2676 ptid_get_pid (result_ptid),
2677 target_pid_to_str (result_ptid));
223698f8
DE
2678 fprintf_unfiltered (tmp_stream,
2679 "infrun: %s\n",
2680 status_string);
2681
759ef836 2682 text = ui_file_xstrdup (tmp_stream, NULL);
223698f8
DE
2683
2684 /* This uses %s in part to handle %'s in the text, but also to avoid
2685 a gcc error: the format attribute requires a string literal. */
2686 fprintf_unfiltered (gdb_stdlog, "%s", text);
2687
2688 xfree (status_string);
2689 xfree (text);
2690 ui_file_delete (tmp_stream);
2691}
2692
24291992
PA
2693/* Prepare and stabilize the inferior for detaching it. E.g.,
2694 detaching while a thread is displaced stepping is a recipe for
2695 crashing it, as nothing would readjust the PC out of the scratch
2696 pad. */
2697
2698void
2699prepare_for_detach (void)
2700{
2701 struct inferior *inf = current_inferior ();
2702 ptid_t pid_ptid = pid_to_ptid (inf->pid);
2703 struct cleanup *old_chain_1;
2704 struct displaced_step_inferior_state *displaced;
2705
2706 displaced = get_displaced_stepping_state (inf->pid);
2707
2708 /* Is any thread of this process displaced stepping? If not,
2709 there's nothing else to do. */
2710 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2711 return;
2712
2713 if (debug_infrun)
2714 fprintf_unfiltered (gdb_stdlog,
2715 "displaced-stepping in-process while detaching");
2716
2717 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2718 inf->detaching = 1;
2719
2720 while (!ptid_equal (displaced->step_ptid, null_ptid))
2721 {
2722 struct cleanup *old_chain_2;
2723 struct execution_control_state ecss;
2724 struct execution_control_state *ecs;
2725
2726 ecs = &ecss;
2727 memset (ecs, 0, sizeof (*ecs));
2728
2729 overlay_cache_invalid = 1;
f15cb84a
YQ
2730 /* Flush target cache before starting to handle each event.
2731 Target was running and cache could be stale. This is just a
2732 heuristic. Running threads may modify target memory, but we
2733 don't get any event. */
2734 target_dcache_invalidate ();
24291992 2735
24291992
PA
2736 if (deprecated_target_wait_hook)
2737 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2738 else
2739 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2740
2741 if (debug_infrun)
2742 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2743
2744 /* If an error happens while handling the event, propagate GDB's
2745 knowledge of the executing state to the frontend/user running
2746 state. */
3e43a32a
MS
2747 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
2748 &minus_one_ptid);
24291992
PA
2749
2750 /* Now figure out what to do with the result of the result. */
2751 handle_inferior_event (ecs);
2752
2753 /* No error, don't finish the state yet. */
2754 discard_cleanups (old_chain_2);
2755
2756 /* Breakpoints and watchpoints are not installed on the target
2757 at this point, and signals are passed directly to the
2758 inferior, so this must mean the process is gone. */
2759 if (!ecs->wait_some_more)
2760 {
2761 discard_cleanups (old_chain_1);
2762 error (_("Program exited while detaching"));
2763 }
2764 }
2765
2766 discard_cleanups (old_chain_1);
2767}
2768
cd0fc7c3 2769/* Wait for control to return from inferior to debugger.
ae123ec6 2770
cd0fc7c3
SS
2771 If inferior gets a signal, we may decide to start it up again
2772 instead of returning. That is why there is a loop in this function.
2773 When this function actually returns it means the inferior
2774 should be left stopped and GDB should read more commands. */
2775
2776void
e4c8541f 2777wait_for_inferior (void)
cd0fc7c3
SS
2778{
2779 struct cleanup *old_cleanups;
c906108c 2780
527159b7 2781 if (debug_infrun)
ae123ec6 2782 fprintf_unfiltered
e4c8541f 2783 (gdb_stdlog, "infrun: wait_for_inferior ()\n");
527159b7 2784
4e1c45ea
PA
2785 old_cleanups =
2786 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
cd0fc7c3 2787
c906108c
SS
2788 while (1)
2789 {
ae25568b
PA
2790 struct execution_control_state ecss;
2791 struct execution_control_state *ecs = &ecss;
29f49a6a
PA
2792 struct cleanup *old_chain;
2793
ae25568b
PA
2794 memset (ecs, 0, sizeof (*ecs));
2795
ec9499be 2796 overlay_cache_invalid = 1;
ec9499be 2797
f15cb84a
YQ
2798 /* Flush target cache before starting to handle each event.
2799 Target was running and cache could be stale. This is just a
2800 heuristic. Running threads may modify target memory, but we
2801 don't get any event. */
2802 target_dcache_invalidate ();
2803
9a4105ab 2804 if (deprecated_target_wait_hook)
47608cb1 2805 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
cd0fc7c3 2806 else
47608cb1 2807 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
c906108c 2808
f00150c9 2809 if (debug_infrun)
223698f8 2810 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
f00150c9 2811
29f49a6a
PA
2812 /* If an error happens while handling the event, propagate GDB's
2813 knowledge of the executing state to the frontend/user running
2814 state. */
2815 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2816
cd0fc7c3
SS
2817 /* Now figure out what to do with the result of the result. */
2818 handle_inferior_event (ecs);
c906108c 2819
29f49a6a
PA
2820 /* No error, don't finish the state yet. */
2821 discard_cleanups (old_chain);
2822
cd0fc7c3
SS
2823 if (!ecs->wait_some_more)
2824 break;
2825 }
4e1c45ea 2826
cd0fc7c3
SS
2827 do_cleanups (old_cleanups);
2828}
c906108c 2829
1777feb0 2830/* Asynchronous version of wait_for_inferior. It is called by the
43ff13b4 2831 event loop whenever a change of state is detected on the file
1777feb0
MS
2832 descriptor corresponding to the target. It can be called more than
2833 once to complete a single execution command. In such cases we need
2834 to keep the state in a global variable ECSS. If it is the last time
a474d7c2
PA
2835 that this function is called for a single execution command, then
2836 report to the user that the inferior has stopped, and do the
1777feb0 2837 necessary cleanups. */
43ff13b4
JM
2838
2839void
fba45db2 2840fetch_inferior_event (void *client_data)
43ff13b4 2841{
0d1e5fa7 2842 struct execution_control_state ecss;
a474d7c2 2843 struct execution_control_state *ecs = &ecss;
4f8d22e3 2844 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
29f49a6a 2845 struct cleanup *ts_old_chain;
4f8d22e3 2846 int was_sync = sync_execution;
0f641c01 2847 int cmd_done = 0;
43ff13b4 2848
0d1e5fa7
PA
2849 memset (ecs, 0, sizeof (*ecs));
2850
c5187ac6
PA
2851 /* We're handling a live event, so make sure we're doing live
2852 debugging. If we're looking at traceframes while the target is
2853 running, we're going to need to get back to that mode after
2854 handling the event. */
2855 if (non_stop)
2856 {
2857 make_cleanup_restore_current_traceframe ();
e6e4e701 2858 set_current_traceframe (-1);
c5187ac6
PA
2859 }
2860
4f8d22e3
PA
2861 if (non_stop)
2862 /* In non-stop mode, the user/frontend should not notice a thread
2863 switch due to internal events. Make sure we reverse to the
2864 user selected thread and frame after handling the event and
2865 running any breakpoint commands. */
2866 make_cleanup_restore_current_thread ();
2867
ec9499be 2868 overlay_cache_invalid = 1;
f15cb84a
YQ
2869 /* Flush target cache before starting to handle each event. Target
2870 was running and cache could be stale. This is just a heuristic.
2871 Running threads may modify target memory, but we don't get any
2872 event. */
2873 target_dcache_invalidate ();
3dd5b83d 2874
32231432
PA
2875 make_cleanup_restore_integer (&execution_direction);
2876 execution_direction = target_execution_direction ();
2877
9a4105ab 2878 if (deprecated_target_wait_hook)
a474d7c2 2879 ecs->ptid =
47608cb1 2880 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
43ff13b4 2881 else
47608cb1 2882 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
43ff13b4 2883
f00150c9 2884 if (debug_infrun)
223698f8 2885 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
f00150c9 2886
29f49a6a
PA
2887 /* If an error happens while handling the event, propagate GDB's
2888 knowledge of the executing state to the frontend/user running
2889 state. */
2890 if (!non_stop)
2891 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2892 else
2893 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2894
353d1d73
JK
2895 /* Get executed before make_cleanup_restore_current_thread above to apply
2896 still for the thread which has thrown the exception. */
2897 make_bpstat_clear_actions_cleanup ();
2898
43ff13b4 2899 /* Now figure out what to do with the result of the result. */
a474d7c2 2900 handle_inferior_event (ecs);
43ff13b4 2901
a474d7c2 2902 if (!ecs->wait_some_more)
43ff13b4 2903 {
d6b48e9c
PA
2904 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2905
4e1c45ea 2906 delete_step_thread_step_resume_breakpoint ();
f107f563 2907
d6b48e9c 2908 /* We may not find an inferior if this was a process exit. */
16c381f0 2909 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
83c265ab
PA
2910 normal_stop ();
2911
af679fd0 2912 if (target_has_execution
0e5bf2a8 2913 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
af679fd0
PA
2914 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2915 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2916 && ecs->event_thread->step_multi
16c381f0 2917 && ecs->event_thread->control.stop_step)
c2d11a7d
JM
2918 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2919 else
0f641c01
PA
2920 {
2921 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2922 cmd_done = 1;
2923 }
43ff13b4 2924 }
4f8d22e3 2925
29f49a6a
PA
2926 /* No error, don't finish the thread states yet. */
2927 discard_cleanups (ts_old_chain);
2928
4f8d22e3
PA
2929 /* Revert thread and frame. */
2930 do_cleanups (old_chain);
2931
2932 /* If the inferior was in sync execution mode, and now isn't,
0f641c01
PA
2933 restore the prompt (a synchronous execution command has finished,
2934 and we're ready for input). */
b4a14fd0 2935 if (interpreter_async && was_sync && !sync_execution)
4f8d22e3 2936 display_gdb_prompt (0);
0f641c01
PA
2937
2938 if (cmd_done
2939 && !was_sync
2940 && exec_done_display_p
2941 && (ptid_equal (inferior_ptid, null_ptid)
2942 || !is_running (inferior_ptid)))
2943 printf_unfiltered (_("completed.\n"));
43ff13b4
JM
2944}
2945
edb3359d
DJ
2946/* Record the frame and location we're currently stepping through. */
2947void
2948set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2949{
2950 struct thread_info *tp = inferior_thread ();
2951
16c381f0
JK
2952 tp->control.step_frame_id = get_frame_id (frame);
2953 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
edb3359d
DJ
2954
2955 tp->current_symtab = sal.symtab;
2956 tp->current_line = sal.line;
2957}
2958
0d1e5fa7
PA
2959/* Clear context switchable stepping state. */
2960
2961void
4e1c45ea 2962init_thread_stepping_state (struct thread_info *tss)
0d1e5fa7
PA
2963{
2964 tss->stepping_over_breakpoint = 0;
2965 tss->step_after_step_resume_breakpoint = 0;
cd0fc7c3
SS
2966}
2967
e02bc4cc 2968/* Return the cached copy of the last pid/waitstatus returned by
9a4105ab
AC
2969 target_wait()/deprecated_target_wait_hook(). The data is actually
2970 cached by handle_inferior_event(), which gets called immediately
2971 after target_wait()/deprecated_target_wait_hook(). */
e02bc4cc
DS
2972
2973void
488f131b 2974get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
e02bc4cc 2975{
39f77062 2976 *ptidp = target_last_wait_ptid;
e02bc4cc
DS
2977 *status = target_last_waitstatus;
2978}
2979
ac264b3b
MS
2980void
2981nullify_last_target_wait_ptid (void)
2982{
2983 target_last_wait_ptid = minus_one_ptid;
2984}
2985
dcf4fbde 2986/* Switch thread contexts. */
dd80620e
MS
2987
2988static void
0d1e5fa7 2989context_switch (ptid_t ptid)
dd80620e 2990{
4b51d87b 2991 if (debug_infrun && !ptid_equal (ptid, inferior_ptid))
fd48f117
DJ
2992 {
2993 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2994 target_pid_to_str (inferior_ptid));
2995 fprintf_unfiltered (gdb_stdlog, "to %s\n",
0d1e5fa7 2996 target_pid_to_str (ptid));
fd48f117
DJ
2997 }
2998
0d1e5fa7 2999 switch_to_thread (ptid);
dd80620e
MS
3000}
3001
4fa8626c
DJ
3002static void
3003adjust_pc_after_break (struct execution_control_state *ecs)
3004{
24a73cce
UW
3005 struct regcache *regcache;
3006 struct gdbarch *gdbarch;
6c95b8df 3007 struct address_space *aspace;
118e6252 3008 CORE_ADDR breakpoint_pc, decr_pc;
4fa8626c 3009
4fa8626c
DJ
3010 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3011 we aren't, just return.
9709f61c
DJ
3012
3013 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
b798847d
UW
3014 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3015 implemented by software breakpoints should be handled through the normal
3016 breakpoint layer.
8fb3e588 3017
4fa8626c
DJ
3018 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3019 different signals (SIGILL or SIGEMT for instance), but it is less
3020 clear where the PC is pointing afterwards. It may not match
b798847d
UW
3021 gdbarch_decr_pc_after_break. I don't know any specific target that
3022 generates these signals at breakpoints (the code has been in GDB since at
3023 least 1992) so I can not guess how to handle them here.
8fb3e588 3024
e6cf7916
UW
3025 In earlier versions of GDB, a target with
3026 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
b798847d
UW
3027 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3028 target with both of these set in GDB history, and it seems unlikely to be
3029 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
4fa8626c
DJ
3030
3031 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
3032 return;
3033
a493e3e2 3034 if (ecs->ws.value.sig != GDB_SIGNAL_TRAP)
4fa8626c
DJ
3035 return;
3036
4058b839
PA
3037 /* In reverse execution, when a breakpoint is hit, the instruction
3038 under it has already been de-executed. The reported PC always
3039 points at the breakpoint address, so adjusting it further would
3040 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3041 architecture:
3042
3043 B1 0x08000000 : INSN1
3044 B2 0x08000001 : INSN2
3045 0x08000002 : INSN3
3046 PC -> 0x08000003 : INSN4
3047
3048 Say you're stopped at 0x08000003 as above. Reverse continuing
3049 from that point should hit B2 as below. Reading the PC when the
3050 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3051 been de-executed already.
3052
3053 B1 0x08000000 : INSN1
3054 B2 PC -> 0x08000001 : INSN2
3055 0x08000002 : INSN3
3056 0x08000003 : INSN4
3057
3058 We can't apply the same logic as for forward execution, because
3059 we would wrongly adjust the PC to 0x08000000, since there's a
3060 breakpoint at PC - 1. We'd then report a hit on B1, although
3061 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3062 behaviour. */
3063 if (execution_direction == EXEC_REVERSE)
3064 return;
3065
24a73cce
UW
3066 /* If this target does not decrement the PC after breakpoints, then
3067 we have nothing to do. */
3068 regcache = get_thread_regcache (ecs->ptid);
3069 gdbarch = get_regcache_arch (regcache);
118e6252
MM
3070
3071 decr_pc = target_decr_pc_after_break (gdbarch);
3072 if (decr_pc == 0)
24a73cce
UW
3073 return;
3074
6c95b8df
PA
3075 aspace = get_regcache_aspace (regcache);
3076
8aad930b
AC
3077 /* Find the location where (if we've hit a breakpoint) the
3078 breakpoint would be. */
118e6252 3079 breakpoint_pc = regcache_read_pc (regcache) - decr_pc;
8aad930b 3080
1c5cfe86
PA
3081 /* Check whether there actually is a software breakpoint inserted at
3082 that location.
3083
3084 If in non-stop mode, a race condition is possible where we've
3085 removed a breakpoint, but stop events for that breakpoint were
3086 already queued and arrive later. To suppress those spurious
3087 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3088 and retire them after a number of stop events are reported. */
6c95b8df
PA
3089 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
3090 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
8aad930b 3091 {
77f9e713 3092 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
abbb1732 3093
8213266a 3094 if (record_full_is_used ())
77f9e713 3095 record_full_gdb_operation_disable_set ();
96429cc8 3096
1c0fdd0e
UW
3097 /* When using hardware single-step, a SIGTRAP is reported for both
3098 a completed single-step and a software breakpoint. Need to
3099 differentiate between the two, as the latter needs adjusting
3100 but the former does not.
3101
3102 The SIGTRAP can be due to a completed hardware single-step only if
3103 - we didn't insert software single-step breakpoints
3104 - the thread to be examined is still the current thread
3105 - this thread is currently being stepped
3106
3107 If any of these events did not occur, we must have stopped due
3108 to hitting a software breakpoint, and have to back up to the
3109 breakpoint address.
3110
3111 As a special case, we could have hardware single-stepped a
3112 software breakpoint. In this case (prev_pc == breakpoint_pc),
3113 we also need to back up to the breakpoint address. */
3114
3115 if (singlestep_breakpoints_inserted_p
3116 || !ptid_equal (ecs->ptid, inferior_ptid)
4e1c45ea
PA
3117 || !currently_stepping (ecs->event_thread)
3118 || ecs->event_thread->prev_pc == breakpoint_pc)
515630c5 3119 regcache_write_pc (regcache, breakpoint_pc);
96429cc8 3120
77f9e713 3121 do_cleanups (old_cleanups);
8aad930b 3122 }
4fa8626c
DJ
3123}
3124
7a76f5b8 3125static void
0d1e5fa7
PA
3126init_infwait_state (void)
3127{
3128 waiton_ptid = pid_to_ptid (-1);
3129 infwait_state = infwait_normal_state;
3130}
3131
edb3359d
DJ
3132static int
3133stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
3134{
3135 for (frame = get_prev_frame (frame);
3136 frame != NULL;
3137 frame = get_prev_frame (frame))
3138 {
3139 if (frame_id_eq (get_frame_id (frame), step_frame_id))
3140 return 1;
3141 if (get_frame_type (frame) != INLINE_FRAME)
3142 break;
3143 }
3144
3145 return 0;
3146}
3147
a96d9b2e
SDJ
3148/* Auxiliary function that handles syscall entry/return events.
3149 It returns 1 if the inferior should keep going (and GDB
3150 should ignore the event), or 0 if the event deserves to be
3151 processed. */
ca2163eb 3152
a96d9b2e 3153static int
ca2163eb 3154handle_syscall_event (struct execution_control_state *ecs)
a96d9b2e 3155{
ca2163eb 3156 struct regcache *regcache;
ca2163eb
PA
3157 int syscall_number;
3158
3159 if (!ptid_equal (ecs->ptid, inferior_ptid))
3160 context_switch (ecs->ptid);
3161
3162 regcache = get_thread_regcache (ecs->ptid);
f90263c1 3163 syscall_number = ecs->ws.value.syscall_number;
ca2163eb
PA
3164 stop_pc = regcache_read_pc (regcache);
3165
a96d9b2e
SDJ
3166 if (catch_syscall_enabled () > 0
3167 && catching_syscall_number (syscall_number) > 0)
3168 {
3169 if (debug_infrun)
3170 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
3171 syscall_number);
a96d9b2e 3172
16c381f0 3173 ecs->event_thread->control.stop_bpstat
6c95b8df 3174 = bpstat_stop_status (get_regcache_aspace (regcache),
09ac7c10 3175 stop_pc, ecs->ptid, &ecs->ws);
ab04a2af 3176
ce12b012 3177 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
ca2163eb
PA
3178 {
3179 /* Catchpoint hit. */
ca2163eb
PA
3180 return 0;
3181 }
a96d9b2e 3182 }
ca2163eb
PA
3183
3184 /* If no catchpoint triggered for this, then keep going. */
ca2163eb
PA
3185 keep_going (ecs);
3186 return 1;
a96d9b2e
SDJ
3187}
3188
7e324e48
GB
3189/* Lazily fill in the execution_control_state's stop_func_* fields. */
3190
3191static void
3192fill_in_stop_func (struct gdbarch *gdbarch,
3193 struct execution_control_state *ecs)
3194{
3195 if (!ecs->stop_func_filled_in)
3196 {
3197 /* Don't care about return value; stop_func_start and stop_func_name
3198 will both be 0 if it doesn't work. */
3199 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3200 &ecs->stop_func_start, &ecs->stop_func_end);
3201 ecs->stop_func_start
3202 += gdbarch_deprecated_function_start_offset (gdbarch);
3203
591a12a1
UW
3204 if (gdbarch_skip_entrypoint_p (gdbarch))
3205 ecs->stop_func_start = gdbarch_skip_entrypoint (gdbarch,
3206 ecs->stop_func_start);
3207
7e324e48
GB
3208 ecs->stop_func_filled_in = 1;
3209 }
3210}
3211
4f5d7f63
PA
3212
3213/* Return the STOP_SOON field of the inferior pointed at by PTID. */
3214
3215static enum stop_kind
3216get_inferior_stop_soon (ptid_t ptid)
3217{
3218 struct inferior *inf = find_inferior_pid (ptid_get_pid (ptid));
3219
3220 gdb_assert (inf != NULL);
3221 return inf->control.stop_soon;
3222}
3223
05ba8510
PA
3224/* Given an execution control state that has been freshly filled in by
3225 an event from the inferior, figure out what it means and take
3226 appropriate action.
3227
3228 The alternatives are:
3229
3230 1) stop_stepping and return; to really stop and return to the
3231 debugger.
3232
3233 2) keep_going and return; to wait for the next event (set
3234 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3235 once). */
c906108c 3236
ec9499be 3237static void
96baa820 3238handle_inferior_event (struct execution_control_state *ecs)
cd0fc7c3 3239{
d6b48e9c
PA
3240 enum stop_kind stop_soon;
3241
28736962
PA
3242 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3243 {
3244 /* We had an event in the inferior, but we are not interested in
3245 handling it at this level. The lower layers have already
3246 done what needs to be done, if anything.
3247
3248 One of the possible circumstances for this is when the
3249 inferior produces output for the console. The inferior has
3250 not stopped, and we are ignoring the event. Another possible
3251 circumstance is any event which the lower level knows will be
3252 reported multiple times without an intervening resume. */
3253 if (debug_infrun)
3254 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3255 prepare_to_wait (ecs);
3256 return;
3257 }
3258
0e5bf2a8
PA
3259 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED
3260 && target_can_async_p () && !sync_execution)
3261 {
3262 /* There were no unwaited-for children left in the target, but,
3263 we're not synchronously waiting for events either. Just
3264 ignore. Otherwise, if we were running a synchronous
3265 execution command, we need to cancel it and give the user
3266 back the terminal. */
3267 if (debug_infrun)
3268 fprintf_unfiltered (gdb_stdlog,
3269 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3270 prepare_to_wait (ecs);
3271 return;
3272 }
3273
1777feb0 3274 /* Cache the last pid/waitstatus. */
39f77062 3275 target_last_wait_ptid = ecs->ptid;
0d1e5fa7 3276 target_last_waitstatus = ecs->ws;
e02bc4cc 3277
ca005067 3278 /* Always clear state belonging to the previous time we stopped. */
aa7d318d 3279 stop_stack_dummy = STOP_NONE;
ca005067 3280
0e5bf2a8
PA
3281 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED)
3282 {
3283 /* No unwaited-for children left. IOW, all resumed children
3284 have exited. */
3285 if (debug_infrun)
3286 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3287
3288 stop_print_frame = 0;
3289 stop_stepping (ecs);
3290 return;
3291 }
3292
8c90c137 3293 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
64776a0b 3294 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
359f5fe6
PA
3295 {
3296 ecs->event_thread = find_thread_ptid (ecs->ptid);
3297 /* If it's a new thread, add it to the thread database. */
3298 if (ecs->event_thread == NULL)
3299 ecs->event_thread = add_thread (ecs->ptid);
c1e36e3e
PA
3300
3301 /* Disable range stepping. If the next step request could use a
3302 range, this will be end up re-enabled then. */
3303 ecs->event_thread->control.may_range_step = 0;
359f5fe6 3304 }
88ed393a
JK
3305
3306 /* Dependent on valid ECS->EVENT_THREAD. */
3307 adjust_pc_after_break (ecs);
3308
3309 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3310 reinit_frame_cache ();
3311
28736962
PA
3312 breakpoint_retire_moribund ();
3313
2b009048
DJ
3314 /* First, distinguish signals caused by the debugger from signals
3315 that have to do with the program's own actions. Note that
3316 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3317 on the operating system version. Here we detect when a SIGILL or
3318 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3319 something similar for SIGSEGV, since a SIGSEGV will be generated
3320 when we're trying to execute a breakpoint instruction on a
3321 non-executable stack. This happens for call dummy breakpoints
3322 for architectures like SPARC that place call dummies on the
3323 stack. */
2b009048 3324 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
a493e3e2
PA
3325 && (ecs->ws.value.sig == GDB_SIGNAL_ILL
3326 || ecs->ws.value.sig == GDB_SIGNAL_SEGV
3327 || ecs->ws.value.sig == GDB_SIGNAL_EMT))
2b009048 3328 {
de0a0249
UW
3329 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3330
3331 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3332 regcache_read_pc (regcache)))
3333 {
3334 if (debug_infrun)
3335 fprintf_unfiltered (gdb_stdlog,
3336 "infrun: Treating signal as SIGTRAP\n");
a493e3e2 3337 ecs->ws.value.sig = GDB_SIGNAL_TRAP;
de0a0249 3338 }
2b009048
DJ
3339 }
3340
28736962
PA
3341 /* Mark the non-executing threads accordingly. In all-stop, all
3342 threads of all processes are stopped when we get any event
3343 reported. In non-stop mode, only the event thread stops. If
3344 we're handling a process exit in non-stop mode, there's nothing
3345 to do, as threads of the dead process are gone, and threads of
3346 any other process were left running. */
3347 if (!non_stop)
3348 set_executing (minus_one_ptid, 0);
3349 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3350 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
7aee8dc2 3351 set_executing (ecs->ptid, 0);
8c90c137 3352
0d1e5fa7 3353 switch (infwait_state)
488f131b 3354 {
488f131b 3355 case infwait_normal_state:
527159b7 3356 if (debug_infrun)
8a9de0e4 3357 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
d983da9c
DJ
3358 break;
3359
3360 case infwait_step_watch_state:
3361 if (debug_infrun)
3362 fprintf_unfiltered (gdb_stdlog,
3363 "infrun: infwait_step_watch_state\n");
3364
4f5d7f63 3365 ecs->stepped_after_stopped_by_watchpoint = 1;
488f131b 3366 break;
b83266a0 3367
488f131b 3368 case infwait_nonstep_watch_state:
527159b7 3369 if (debug_infrun)
8a9de0e4
AC
3370 fprintf_unfiltered (gdb_stdlog,
3371 "infrun: infwait_nonstep_watch_state\n");
488f131b 3372 insert_breakpoints ();
c906108c 3373
488f131b
JB
3374 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3375 handle things like signals arriving and other things happening
3376 in combination correctly? */
4f5d7f63 3377 ecs->stepped_after_stopped_by_watchpoint = 1;
488f131b 3378 break;
65e82032
AC
3379
3380 default:
e2e0b3e5 3381 internal_error (__FILE__, __LINE__, _("bad switch"));
488f131b 3382 }
ec9499be 3383
0d1e5fa7 3384 infwait_state = infwait_normal_state;
ec9499be 3385 waiton_ptid = pid_to_ptid (-1);
c906108c 3386
488f131b
JB
3387 switch (ecs->ws.kind)
3388 {
3389 case TARGET_WAITKIND_LOADED:
527159b7 3390 if (debug_infrun)
8a9de0e4 3391 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
5c09a2c5
PA
3392 if (!ptid_equal (ecs->ptid, inferior_ptid))
3393 context_switch (ecs->ptid);
b0f4b84b
DJ
3394 /* Ignore gracefully during startup of the inferior, as it might
3395 be the shell which has just loaded some objects, otherwise
3396 add the symbols for the newly loaded objects. Also ignore at
3397 the beginning of an attach or remote session; we will query
3398 the full list of libraries once the connection is
3399 established. */
4f5d7f63
PA
3400
3401 stop_soon = get_inferior_stop_soon (ecs->ptid);
c0236d92 3402 if (stop_soon == NO_STOP_QUIETLY)
488f131b 3403 {
edcc5120
TT
3404 struct regcache *regcache;
3405
edcc5120
TT
3406 regcache = get_thread_regcache (ecs->ptid);
3407
3408 handle_solib_event ();
3409
3410 ecs->event_thread->control.stop_bpstat
3411 = bpstat_stop_status (get_regcache_aspace (regcache),
3412 stop_pc, ecs->ptid, &ecs->ws);
ab04a2af 3413
ce12b012 3414 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
edcc5120
TT
3415 {
3416 /* A catchpoint triggered. */
94c57d6a
PA
3417 process_event_stop_test (ecs);
3418 return;
edcc5120 3419 }
488f131b 3420
b0f4b84b
DJ
3421 /* If requested, stop when the dynamic linker notifies
3422 gdb of events. This allows the user to get control
3423 and place breakpoints in initializer routines for
3424 dynamically loaded objects (among other things). */
a493e3e2 3425 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
b0f4b84b
DJ
3426 if (stop_on_solib_events)
3427 {
55409f9d
DJ
3428 /* Make sure we print "Stopped due to solib-event" in
3429 normal_stop. */
3430 stop_print_frame = 1;
3431
b0f4b84b
DJ
3432 stop_stepping (ecs);
3433 return;
3434 }
488f131b 3435 }
b0f4b84b
DJ
3436
3437 /* If we are skipping through a shell, or through shared library
3438 loading that we aren't interested in, resume the program. If
5c09a2c5 3439 we're running the program normally, also resume. */
b0f4b84b
DJ
3440 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3441 {
74960c60
VP
3442 /* Loading of shared libraries might have changed breakpoint
3443 addresses. Make sure new breakpoints are inserted. */
0b02b92d
UW
3444 if (stop_soon == NO_STOP_QUIETLY
3445 && !breakpoints_always_inserted_mode ())
74960c60 3446 insert_breakpoints ();
a493e3e2 3447 resume (0, GDB_SIGNAL_0);
b0f4b84b
DJ
3448 prepare_to_wait (ecs);
3449 return;
3450 }
3451
5c09a2c5
PA
3452 /* But stop if we're attaching or setting up a remote
3453 connection. */
3454 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3455 || stop_soon == STOP_QUIETLY_REMOTE)
3456 {
3457 if (debug_infrun)
3458 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3459 stop_stepping (ecs);
3460 return;
3461 }
3462
3463 internal_error (__FILE__, __LINE__,
3464 _("unhandled stop_soon: %d"), (int) stop_soon);
c5aa993b 3465
488f131b 3466 case TARGET_WAITKIND_SPURIOUS:
527159b7 3467 if (debug_infrun)
8a9de0e4 3468 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
64776a0b 3469 if (!ptid_equal (ecs->ptid, inferior_ptid))
8b3ee56d 3470 context_switch (ecs->ptid);
a493e3e2 3471 resume (0, GDB_SIGNAL_0);
488f131b
JB
3472 prepare_to_wait (ecs);
3473 return;
c5aa993b 3474
488f131b 3475 case TARGET_WAITKIND_EXITED:
940c3c06 3476 case TARGET_WAITKIND_SIGNALLED:
527159b7 3477 if (debug_infrun)
940c3c06
PA
3478 {
3479 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3480 fprintf_unfiltered (gdb_stdlog,
3481 "infrun: TARGET_WAITKIND_EXITED\n");
3482 else
3483 fprintf_unfiltered (gdb_stdlog,
3484 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3485 }
3486
fb66883a 3487 inferior_ptid = ecs->ptid;
6c95b8df
PA
3488 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3489 set_current_program_space (current_inferior ()->pspace);
3490 handle_vfork_child_exec_or_exit (0);
1777feb0 3491 target_terminal_ours (); /* Must do this before mourn anyway. */
488f131b 3492
0c557179
SDJ
3493 /* Clearing any previous state of convenience variables. */
3494 clear_exit_convenience_vars ();
3495
940c3c06
PA
3496 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3497 {
3498 /* Record the exit code in the convenience variable $_exitcode, so
3499 that the user can inspect this again later. */
3500 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3501 (LONGEST) ecs->ws.value.integer);
3502
3503 /* Also record this in the inferior itself. */
3504 current_inferior ()->has_exit_code = 1;
3505 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
8cf64490 3506
940c3c06
PA
3507 print_exited_reason (ecs->ws.value.integer);
3508 }
3509 else
0c557179
SDJ
3510 {
3511 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3512 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3513
3514 if (gdbarch_gdb_signal_to_target_p (gdbarch))
3515 {
3516 /* Set the value of the internal variable $_exitsignal,
3517 which holds the signal uncaught by the inferior. */
3518 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3519 gdbarch_gdb_signal_to_target (gdbarch,
3520 ecs->ws.value.sig));
3521 }
3522 else
3523 {
3524 /* We don't have access to the target's method used for
3525 converting between signal numbers (GDB's internal
3526 representation <-> target's representation).
3527 Therefore, we cannot do a good job at displaying this
3528 information to the user. It's better to just warn
3529 her about it (if infrun debugging is enabled), and
3530 give up. */
3531 if (debug_infrun)
3532 fprintf_filtered (gdb_stdlog, _("\
3533Cannot fill $_exitsignal with the correct signal number.\n"));
3534 }
3535
3536 print_signal_exited_reason (ecs->ws.value.sig);
3537 }
8cf64490 3538
488f131b
JB
3539 gdb_flush (gdb_stdout);
3540 target_mourn_inferior ();
1c0fdd0e 3541 singlestep_breakpoints_inserted_p = 0;
d03285ec 3542 cancel_single_step_breakpoints ();
488f131b
JB
3543 stop_print_frame = 0;
3544 stop_stepping (ecs);
3545 return;
c5aa993b 3546
488f131b 3547 /* The following are the only cases in which we keep going;
1777feb0 3548 the above cases end in a continue or goto. */
488f131b 3549 case TARGET_WAITKIND_FORKED:
deb3b17b 3550 case TARGET_WAITKIND_VFORKED:
527159b7 3551 if (debug_infrun)
fed708ed
PA
3552 {
3553 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3554 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3555 else
3556 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n");
3557 }
c906108c 3558
e2d96639
YQ
3559 /* Check whether the inferior is displaced stepping. */
3560 {
3561 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3562 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3563 struct displaced_step_inferior_state *displaced
3564 = get_displaced_stepping_state (ptid_get_pid (ecs->ptid));
3565
3566 /* If checking displaced stepping is supported, and thread
3567 ecs->ptid is displaced stepping. */
3568 if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid))
3569 {
3570 struct inferior *parent_inf
3571 = find_inferior_pid (ptid_get_pid (ecs->ptid));
3572 struct regcache *child_regcache;
3573 CORE_ADDR parent_pc;
3574
3575 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3576 indicating that the displaced stepping of syscall instruction
3577 has been done. Perform cleanup for parent process here. Note
3578 that this operation also cleans up the child process for vfork,
3579 because their pages are shared. */
a493e3e2 3580 displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP);
e2d96639
YQ
3581
3582 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3583 {
3584 /* Restore scratch pad for child process. */
3585 displaced_step_restore (displaced, ecs->ws.value.related_pid);
3586 }
3587
3588 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3589 the child's PC is also within the scratchpad. Set the child's PC
3590 to the parent's PC value, which has already been fixed up.
3591 FIXME: we use the parent's aspace here, although we're touching
3592 the child, because the child hasn't been added to the inferior
3593 list yet at this point. */
3594
3595 child_regcache
3596 = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid,
3597 gdbarch,
3598 parent_inf->aspace);
3599 /* Read PC value of parent process. */
3600 parent_pc = regcache_read_pc (regcache);
3601
3602 if (debug_displaced)
3603 fprintf_unfiltered (gdb_stdlog,
3604 "displaced: write child pc from %s to %s\n",
3605 paddress (gdbarch,
3606 regcache_read_pc (child_regcache)),
3607 paddress (gdbarch, parent_pc));
3608
3609 regcache_write_pc (child_regcache, parent_pc);
3610 }
3611 }
3612
5a2901d9 3613 if (!ptid_equal (ecs->ptid, inferior_ptid))
c3a01a22 3614 context_switch (ecs->ptid);
5a2901d9 3615
b242c3c2
PA
3616 /* Immediately detach breakpoints from the child before there's
3617 any chance of letting the user delete breakpoints from the
3618 breakpoint lists. If we don't do this early, it's easy to
3619 leave left over traps in the child, vis: "break foo; catch
3620 fork; c; <fork>; del; c; <child calls foo>". We only follow
3621 the fork on the last `continue', and by that time the
3622 breakpoint at "foo" is long gone from the breakpoint table.
3623 If we vforked, then we don't need to unpatch here, since both
3624 parent and child are sharing the same memory pages; we'll
3625 need to unpatch at follow/detach time instead to be certain
3626 that new breakpoints added between catchpoint hit time and
3627 vfork follow are detached. */
3628 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3629 {
b242c3c2
PA
3630 /* This won't actually modify the breakpoint list, but will
3631 physically remove the breakpoints from the child. */
d80ee84f 3632 detach_breakpoints (ecs->ws.value.related_pid);
b242c3c2
PA
3633 }
3634
d03285ec
UW
3635 if (singlestep_breakpoints_inserted_p)
3636 {
1777feb0 3637 /* Pull the single step breakpoints out of the target. */
d03285ec
UW
3638 remove_single_step_breakpoints ();
3639 singlestep_breakpoints_inserted_p = 0;
3640 }
3641
e58b0e63
PA
3642 /* In case the event is caught by a catchpoint, remember that
3643 the event is to be followed at the next resume of the thread,
3644 and not immediately. */
3645 ecs->event_thread->pending_follow = ecs->ws;
3646
fb14de7b 3647 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
675bf4cb 3648
16c381f0 3649 ecs->event_thread->control.stop_bpstat
6c95b8df 3650 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
09ac7c10 3651 stop_pc, ecs->ptid, &ecs->ws);
675bf4cb 3652
ce12b012
PA
3653 /* If no catchpoint triggered for this, then keep going. Note
3654 that we're interested in knowing the bpstat actually causes a
3655 stop, not just if it may explain the signal. Software
3656 watchpoints, for example, always appear in the bpstat. */
3657 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
04e68871 3658 {
6c95b8df
PA
3659 ptid_t parent;
3660 ptid_t child;
e58b0e63 3661 int should_resume;
3e43a32a
MS
3662 int follow_child
3663 = (follow_fork_mode_string == follow_fork_mode_child);
e58b0e63 3664
a493e3e2 3665 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
e58b0e63
PA
3666
3667 should_resume = follow_fork ();
3668
6c95b8df
PA
3669 parent = ecs->ptid;
3670 child = ecs->ws.value.related_pid;
3671
3672 /* In non-stop mode, also resume the other branch. */
3673 if (non_stop && !detach_fork)
3674 {
3675 if (follow_child)
3676 switch_to_thread (parent);
3677 else
3678 switch_to_thread (child);
3679
3680 ecs->event_thread = inferior_thread ();
3681 ecs->ptid = inferior_ptid;
3682 keep_going (ecs);
3683 }
3684
3685 if (follow_child)
3686 switch_to_thread (child);
3687 else
3688 switch_to_thread (parent);
3689
e58b0e63
PA
3690 ecs->event_thread = inferior_thread ();
3691 ecs->ptid = inferior_ptid;
3692
3693 if (should_resume)
3694 keep_going (ecs);
3695 else
3696 stop_stepping (ecs);
04e68871
DJ
3697 return;
3698 }
94c57d6a
PA
3699 process_event_stop_test (ecs);
3700 return;
488f131b 3701
6c95b8df
PA
3702 case TARGET_WAITKIND_VFORK_DONE:
3703 /* Done with the shared memory region. Re-insert breakpoints in
3704 the parent, and keep going. */
3705
3706 if (debug_infrun)
3e43a32a
MS
3707 fprintf_unfiltered (gdb_stdlog,
3708 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
6c95b8df
PA
3709
3710 if (!ptid_equal (ecs->ptid, inferior_ptid))
3711 context_switch (ecs->ptid);
3712
3713 current_inferior ()->waiting_for_vfork_done = 0;
56710373 3714 current_inferior ()->pspace->breakpoints_not_allowed = 0;
6c95b8df
PA
3715 /* This also takes care of reinserting breakpoints in the
3716 previously locked inferior. */
3717 keep_going (ecs);
3718 return;
3719
488f131b 3720 case TARGET_WAITKIND_EXECD:
527159b7 3721 if (debug_infrun)
fc5261f2 3722 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
488f131b 3723
5a2901d9 3724 if (!ptid_equal (ecs->ptid, inferior_ptid))
c3a01a22 3725 context_switch (ecs->ptid);
5a2901d9 3726
d03285ec
UW
3727 singlestep_breakpoints_inserted_p = 0;
3728 cancel_single_step_breakpoints ();
3729
fb14de7b 3730 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
795e548f 3731
6c95b8df
PA
3732 /* Do whatever is necessary to the parent branch of the vfork. */
3733 handle_vfork_child_exec_or_exit (1);
3734
795e548f
PA
3735 /* This causes the eventpoints and symbol table to be reset.
3736 Must do this now, before trying to determine whether to
3737 stop. */
71b43ef8 3738 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
795e548f 3739
16c381f0 3740 ecs->event_thread->control.stop_bpstat
6c95b8df 3741 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
09ac7c10 3742 stop_pc, ecs->ptid, &ecs->ws);
795e548f 3743
71b43ef8
PA
3744 /* Note that this may be referenced from inside
3745 bpstat_stop_status above, through inferior_has_execd. */
3746 xfree (ecs->ws.value.execd_pathname);
3747 ecs->ws.value.execd_pathname = NULL;
3748
04e68871 3749 /* If no catchpoint triggered for this, then keep going. */
ce12b012 3750 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
04e68871 3751 {
a493e3e2 3752 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
04e68871
DJ
3753 keep_going (ecs);
3754 return;
3755 }
94c57d6a
PA
3756 process_event_stop_test (ecs);
3757 return;
488f131b 3758
b4dc5ffa
MK
3759 /* Be careful not to try to gather much state about a thread
3760 that's in a syscall. It's frequently a losing proposition. */
488f131b 3761 case TARGET_WAITKIND_SYSCALL_ENTRY:
527159b7 3762 if (debug_infrun)
3e43a32a
MS
3763 fprintf_unfiltered (gdb_stdlog,
3764 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
1777feb0 3765 /* Getting the current syscall number. */
94c57d6a
PA
3766 if (handle_syscall_event (ecs) == 0)
3767 process_event_stop_test (ecs);
3768 return;
c906108c 3769
488f131b
JB
3770 /* Before examining the threads further, step this thread to
3771 get it entirely out of the syscall. (We get notice of the
3772 event when the thread is just on the verge of exiting a
3773 syscall. Stepping one instruction seems to get it back
b4dc5ffa 3774 into user code.) */
488f131b 3775 case TARGET_WAITKIND_SYSCALL_RETURN:
527159b7 3776 if (debug_infrun)
3e43a32a
MS
3777 fprintf_unfiltered (gdb_stdlog,
3778 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
94c57d6a
PA
3779 if (handle_syscall_event (ecs) == 0)
3780 process_event_stop_test (ecs);
3781 return;
c906108c 3782
488f131b 3783 case TARGET_WAITKIND_STOPPED:
527159b7 3784 if (debug_infrun)
8a9de0e4 3785 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
16c381f0 3786 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
4f5d7f63
PA
3787 handle_signal_stop (ecs);
3788 return;
c906108c 3789
b2175913 3790 case TARGET_WAITKIND_NO_HISTORY:
4b4e080e
PA
3791 if (debug_infrun)
3792 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
b2175913 3793 /* Reverse execution: target ran out of history info. */
eab402df
PA
3794
3795 /* Pull the single step breakpoints out of the target. */
3796 if (singlestep_breakpoints_inserted_p)
3797 {
3798 if (!ptid_equal (ecs->ptid, inferior_ptid))
3799 context_switch (ecs->ptid);
3800 remove_single_step_breakpoints ();
3801 singlestep_breakpoints_inserted_p = 0;
3802 }
fb14de7b 3803 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
33d62d64 3804 print_no_history_reason ();
b2175913
MS
3805 stop_stepping (ecs);
3806 return;
488f131b 3807 }
4f5d7f63
PA
3808}
3809
3810/* Come here when the program has stopped with a signal. */
3811
3812static void
3813handle_signal_stop (struct execution_control_state *ecs)
3814{
3815 struct frame_info *frame;
3816 struct gdbarch *gdbarch;
3817 int stopped_by_watchpoint;
3818 enum stop_kind stop_soon;
3819 int random_signal;
c906108c 3820
f0407826
DE
3821 gdb_assert (ecs->ws.kind == TARGET_WAITKIND_STOPPED);
3822
3823 /* Do we need to clean up the state of a thread that has
3824 completed a displaced single-step? (Doing so usually affects
3825 the PC, so do it here, before we set stop_pc.) */
3826 displaced_step_fixup (ecs->ptid,
3827 ecs->event_thread->suspend.stop_signal);
3828
3829 /* If we either finished a single-step or hit a breakpoint, but
3830 the user wanted this thread to be stopped, pretend we got a
3831 SIG0 (generic unsignaled stop). */
3832 if (ecs->event_thread->stop_requested
3833 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
3834 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
237fc4c9 3835
515630c5 3836 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
488f131b 3837
527159b7 3838 if (debug_infrun)
237fc4c9 3839 {
5af949e3
UW
3840 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3841 struct gdbarch *gdbarch = get_regcache_arch (regcache);
7f82dfc7
JK
3842 struct cleanup *old_chain = save_inferior_ptid ();
3843
3844 inferior_ptid = ecs->ptid;
5af949e3
UW
3845
3846 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3847 paddress (gdbarch, stop_pc));
d92524f1 3848 if (target_stopped_by_watchpoint ())
237fc4c9
PA
3849 {
3850 CORE_ADDR addr;
abbb1732 3851
237fc4c9
PA
3852 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3853
3854 if (target_stopped_data_address (&current_target, &addr))
3855 fprintf_unfiltered (gdb_stdlog,
5af949e3
UW
3856 "infrun: stopped data address = %s\n",
3857 paddress (gdbarch, addr));
237fc4c9
PA
3858 else
3859 fprintf_unfiltered (gdb_stdlog,
3860 "infrun: (no data address available)\n");
3861 }
7f82dfc7
JK
3862
3863 do_cleanups (old_chain);
237fc4c9 3864 }
527159b7 3865
36fa8042
PA
3866 /* This is originated from start_remote(), start_inferior() and
3867 shared libraries hook functions. */
3868 stop_soon = get_inferior_stop_soon (ecs->ptid);
3869 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
3870 {
3871 if (!ptid_equal (ecs->ptid, inferior_ptid))
3872 context_switch (ecs->ptid);
3873 if (debug_infrun)
3874 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3875 stop_print_frame = 1;
3876 stop_stepping (ecs);
3877 return;
3878 }
3879
3880 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
3881 && stop_after_trap)
3882 {
3883 if (!ptid_equal (ecs->ptid, inferior_ptid))
3884 context_switch (ecs->ptid);
3885 if (debug_infrun)
3886 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
3887 stop_print_frame = 0;
3888 stop_stepping (ecs);
3889 return;
3890 }
3891
3892 /* This originates from attach_command(). We need to overwrite
3893 the stop_signal here, because some kernels don't ignore a
3894 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3895 See more comments in inferior.h. On the other hand, if we
3896 get a non-SIGSTOP, report it to the user - assume the backend
3897 will handle the SIGSTOP if it should show up later.
3898
3899 Also consider that the attach is complete when we see a
3900 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3901 target extended-remote report it instead of a SIGSTOP
3902 (e.g. gdbserver). We already rely on SIGTRAP being our
3903 signal, so this is no exception.
3904
3905 Also consider that the attach is complete when we see a
3906 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3907 the target to stop all threads of the inferior, in case the
3908 low level attach operation doesn't stop them implicitly. If
3909 they weren't stopped implicitly, then the stub will report a
3910 GDB_SIGNAL_0, meaning: stopped for no particular reason
3911 other than GDB's request. */
3912 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3913 && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP
3914 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
3915 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0))
3916 {
3917 stop_print_frame = 1;
3918 stop_stepping (ecs);
3919 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3920 return;
3921 }
3922
488f131b 3923 /* See if something interesting happened to the non-current thread. If
b40c7d58
DJ
3924 so, then switch to that thread. */
3925 if (!ptid_equal (ecs->ptid, inferior_ptid))
488f131b 3926 {
527159b7 3927 if (debug_infrun)
8a9de0e4 3928 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
527159b7 3929
0d1e5fa7 3930 context_switch (ecs->ptid);
c5aa993b 3931
9a4105ab
AC
3932 if (deprecated_context_hook)
3933 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
488f131b 3934 }
c906108c 3935
568d6575
UW
3936 /* At this point, get hold of the now-current thread's frame. */
3937 frame = get_current_frame ();
3938 gdbarch = get_frame_arch (frame);
3939
2adfaa28 3940 /* Pull the single step breakpoints out of the target. */
1c0fdd0e 3941 if (singlestep_breakpoints_inserted_p)
488f131b 3942 {
2adfaa28
PA
3943 /* However, before doing so, if this single-step breakpoint was
3944 actually for another thread, set this thread up for moving
3945 past it. */
3946 if (!ptid_equal (ecs->ptid, singlestep_ptid)
3947 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
3948 {
3949 struct regcache *regcache;
3950 struct address_space *aspace;
3951 CORE_ADDR pc;
3952
3953 regcache = get_thread_regcache (ecs->ptid);
3954 aspace = get_regcache_aspace (regcache);
3955 pc = regcache_read_pc (regcache);
3956 if (single_step_breakpoint_inserted_here_p (aspace, pc))
3957 {
3958 if (debug_infrun)
3959 {
3960 fprintf_unfiltered (gdb_stdlog,
3961 "infrun: [%s] hit step over single-step"
3962 " breakpoint of [%s]\n",
3963 target_pid_to_str (ecs->ptid),
3964 target_pid_to_str (singlestep_ptid));
3965 }
3966 ecs->hit_singlestep_breakpoint = 1;
3967 }
3968 }
3969
e0cd558a 3970 remove_single_step_breakpoints ();
488f131b
JB
3971 singlestep_breakpoints_inserted_p = 0;
3972 }
c906108c 3973
4f5d7f63 3974 if (ecs->stepped_after_stopped_by_watchpoint)
d983da9c
DJ
3975 stopped_by_watchpoint = 0;
3976 else
3977 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
3978
3979 /* If necessary, step over this watchpoint. We'll be back to display
3980 it in a moment. */
3981 if (stopped_by_watchpoint
d92524f1 3982 && (target_have_steppable_watchpoint
568d6575 3983 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
488f131b 3984 {
488f131b
JB
3985 /* At this point, we are stopped at an instruction which has
3986 attempted to write to a piece of memory under control of
3987 a watchpoint. The instruction hasn't actually executed
3988 yet. If we were to evaluate the watchpoint expression
3989 now, we would get the old value, and therefore no change
3990 would seem to have occurred.
3991
3992 In order to make watchpoints work `right', we really need
3993 to complete the memory write, and then evaluate the
d983da9c
DJ
3994 watchpoint expression. We do this by single-stepping the
3995 target.
3996
3997 It may not be necessary to disable the watchpoint to stop over
3998 it. For example, the PA can (with some kernel cooperation)
3999 single step over a watchpoint without disabling the watchpoint.
4000
4001 It is far more common to need to disable a watchpoint to step
4002 the inferior over it. If we have non-steppable watchpoints,
4003 we must disable the current watchpoint; it's simplest to
4004 disable all watchpoints and breakpoints. */
2facfe5c
DD
4005 int hw_step = 1;
4006
d92524f1 4007 if (!target_have_steppable_watchpoint)
2455069d
UW
4008 {
4009 remove_breakpoints ();
4010 /* See comment in resume why we need to stop bypassing signals
4011 while breakpoints have been removed. */
4012 target_pass_signals (0, NULL);
4013 }
2facfe5c 4014 /* Single step */
568d6575 4015 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
a493e3e2 4016 target_resume (ecs->ptid, hw_step, GDB_SIGNAL_0);
0d1e5fa7 4017 waiton_ptid = ecs->ptid;
d92524f1 4018 if (target_have_steppable_watchpoint)
0d1e5fa7 4019 infwait_state = infwait_step_watch_state;
d983da9c 4020 else
0d1e5fa7 4021 infwait_state = infwait_nonstep_watch_state;
488f131b
JB
4022 prepare_to_wait (ecs);
4023 return;
4024 }
4025
4e1c45ea 4026 ecs->event_thread->stepping_over_breakpoint = 0;
16c381f0
JK
4027 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4028 ecs->event_thread->control.stop_step = 0;
488f131b 4029 stop_print_frame = 1;
488f131b 4030 stopped_by_random_signal = 0;
488f131b 4031
edb3359d
DJ
4032 /* Hide inlined functions starting here, unless we just performed stepi or
4033 nexti. After stepi and nexti, always show the innermost frame (not any
4034 inline function call sites). */
16c381f0 4035 if (ecs->event_thread->control.step_range_end != 1)
0574c78f
GB
4036 {
4037 struct address_space *aspace =
4038 get_regcache_aspace (get_thread_regcache (ecs->ptid));
4039
4040 /* skip_inline_frames is expensive, so we avoid it if we can
4041 determine that the address is one where functions cannot have
4042 been inlined. This improves performance with inferiors that
4043 load a lot of shared libraries, because the solib event
4044 breakpoint is defined as the address of a function (i.e. not
4045 inline). Note that we have to check the previous PC as well
4046 as the current one to catch cases when we have just
4047 single-stepped off a breakpoint prior to reinstating it.
4048 Note that we're assuming that the code we single-step to is
4049 not inline, but that's not definitive: there's nothing
4050 preventing the event breakpoint function from containing
4051 inlined code, and the single-step ending up there. If the
4052 user had set a breakpoint on that inlined code, the missing
4053 skip_inline_frames call would break things. Fortunately
4054 that's an extremely unlikely scenario. */
09ac7c10 4055 if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws)
a210c238
MR
4056 && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4057 && ecs->event_thread->control.trap_expected
4058 && pc_at_non_inline_function (aspace,
4059 ecs->event_thread->prev_pc,
09ac7c10 4060 &ecs->ws)))
1c5a993e
MR
4061 {
4062 skip_inline_frames (ecs->ptid);
4063
4064 /* Re-fetch current thread's frame in case that invalidated
4065 the frame cache. */
4066 frame = get_current_frame ();
4067 gdbarch = get_frame_arch (frame);
4068 }
0574c78f 4069 }
edb3359d 4070
a493e3e2 4071 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
16c381f0 4072 && ecs->event_thread->control.trap_expected
568d6575 4073 && gdbarch_single_step_through_delay_p (gdbarch)
4e1c45ea 4074 && currently_stepping (ecs->event_thread))
3352ef37 4075 {
b50d7442 4076 /* We're trying to step off a breakpoint. Turns out that we're
3352ef37 4077 also on an instruction that needs to be stepped multiple
1777feb0 4078 times before it's been fully executing. E.g., architectures
3352ef37
AC
4079 with a delay slot. It needs to be stepped twice, once for
4080 the instruction and once for the delay slot. */
4081 int step_through_delay
568d6575 4082 = gdbarch_single_step_through_delay (gdbarch, frame);
abbb1732 4083
527159b7 4084 if (debug_infrun && step_through_delay)
8a9de0e4 4085 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
16c381f0
JK
4086 if (ecs->event_thread->control.step_range_end == 0
4087 && step_through_delay)
3352ef37
AC
4088 {
4089 /* The user issued a continue when stopped at a breakpoint.
4090 Set up for another trap and get out of here. */
4e1c45ea 4091 ecs->event_thread->stepping_over_breakpoint = 1;
3352ef37
AC
4092 keep_going (ecs);
4093 return;
4094 }
4095 else if (step_through_delay)
4096 {
4097 /* The user issued a step when stopped at a breakpoint.
4098 Maybe we should stop, maybe we should not - the delay
4099 slot *might* correspond to a line of source. In any
ca67fcb8
VP
4100 case, don't decide that here, just set
4101 ecs->stepping_over_breakpoint, making sure we
4102 single-step again before breakpoints are re-inserted. */
4e1c45ea 4103 ecs->event_thread->stepping_over_breakpoint = 1;
3352ef37
AC
4104 }
4105 }
4106
ab04a2af
TT
4107 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4108 handles this event. */
4109 ecs->event_thread->control.stop_bpstat
4110 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4111 stop_pc, ecs->ptid, &ecs->ws);
db82e815 4112
ab04a2af
TT
4113 /* Following in case break condition called a
4114 function. */
4115 stop_print_frame = 1;
73dd234f 4116
ab04a2af
TT
4117 /* This is where we handle "moribund" watchpoints. Unlike
4118 software breakpoints traps, hardware watchpoint traps are
4119 always distinguishable from random traps. If no high-level
4120 watchpoint is associated with the reported stop data address
4121 anymore, then the bpstat does not explain the signal ---
4122 simply make sure to ignore it if `stopped_by_watchpoint' is
4123 set. */
4124
4125 if (debug_infrun
4126 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
47591c29 4127 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
427cd150 4128 GDB_SIGNAL_TRAP)
ab04a2af
TT
4129 && stopped_by_watchpoint)
4130 fprintf_unfiltered (gdb_stdlog,
4131 "infrun: no user watchpoint explains "
4132 "watchpoint SIGTRAP, ignoring\n");
73dd234f 4133
bac7d97b 4134 /* NOTE: cagney/2003-03-29: These checks for a random signal
ab04a2af
TT
4135 at one stage in the past included checks for an inferior
4136 function call's call dummy's return breakpoint. The original
4137 comment, that went with the test, read:
03cebad2 4138
ab04a2af
TT
4139 ``End of a stack dummy. Some systems (e.g. Sony news) give
4140 another signal besides SIGTRAP, so check here as well as
4141 above.''
73dd234f 4142
ab04a2af
TT
4143 If someone ever tries to get call dummys on a
4144 non-executable stack to work (where the target would stop
4145 with something like a SIGSEGV), then those tests might need
4146 to be re-instated. Given, however, that the tests were only
4147 enabled when momentary breakpoints were not being used, I
4148 suspect that it won't be the case.
488f131b 4149
ab04a2af
TT
4150 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4151 be necessary for call dummies on a non-executable stack on
4152 SPARC. */
488f131b 4153
bac7d97b 4154 /* See if the breakpoints module can explain the signal. */
47591c29
PA
4155 random_signal
4156 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4157 ecs->event_thread->suspend.stop_signal);
bac7d97b
PA
4158
4159 /* If not, perhaps stepping/nexting can. */
4160 if (random_signal)
4161 random_signal = !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4162 && currently_stepping (ecs->event_thread));
ab04a2af 4163
2adfaa28
PA
4164 /* Perhaps the thread hit a single-step breakpoint of _another_
4165 thread. Single-step breakpoints are transparent to the
4166 breakpoints module. */
4167 if (random_signal)
4168 random_signal = !ecs->hit_singlestep_breakpoint;
4169
bac7d97b
PA
4170 /* No? Perhaps we got a moribund watchpoint. */
4171 if (random_signal)
4172 random_signal = !stopped_by_watchpoint;
ab04a2af 4173
488f131b
JB
4174 /* For the program's own signals, act according to
4175 the signal handling tables. */
4176
ce12b012 4177 if (random_signal)
488f131b
JB
4178 {
4179 /* Signal not for debugging purposes. */
4180 int printed = 0;
24291992 4181 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
c9737c08 4182 enum gdb_signal stop_signal = ecs->event_thread->suspend.stop_signal;
488f131b 4183
527159b7 4184 if (debug_infrun)
c9737c08
PA
4185 fprintf_unfiltered (gdb_stdlog, "infrun: random signal (%s)\n",
4186 gdb_signal_to_symbol_string (stop_signal));
527159b7 4187
488f131b
JB
4188 stopped_by_random_signal = 1;
4189
16c381f0 4190 if (signal_print[ecs->event_thread->suspend.stop_signal])
488f131b
JB
4191 {
4192 printed = 1;
4193 target_terminal_ours_for_output ();
16c381f0
JK
4194 print_signal_received_reason
4195 (ecs->event_thread->suspend.stop_signal);
488f131b 4196 }
252fbfc8
PA
4197 /* Always stop on signals if we're either just gaining control
4198 of the program, or the user explicitly requested this thread
4199 to remain stopped. */
d6b48e9c 4200 if (stop_soon != NO_STOP_QUIETLY
252fbfc8 4201 || ecs->event_thread->stop_requested
24291992 4202 || (!inf->detaching
16c381f0 4203 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
488f131b
JB
4204 {
4205 stop_stepping (ecs);
4206 return;
4207 }
4208 /* If not going to stop, give terminal back
4209 if we took it away. */
4210 else if (printed)
4211 target_terminal_inferior ();
4212
4213 /* Clear the signal if it should not be passed. */
16c381f0 4214 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
a493e3e2 4215 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
488f131b 4216
fb14de7b 4217 if (ecs->event_thread->prev_pc == stop_pc
16c381f0 4218 && ecs->event_thread->control.trap_expected
8358c15c 4219 && ecs->event_thread->control.step_resume_breakpoint == NULL)
68f53502
AC
4220 {
4221 /* We were just starting a new sequence, attempting to
4222 single-step off of a breakpoint and expecting a SIGTRAP.
237fc4c9 4223 Instead this signal arrives. This signal will take us out
68f53502
AC
4224 of the stepping range so GDB needs to remember to, when
4225 the signal handler returns, resume stepping off that
4226 breakpoint. */
4227 /* To simplify things, "continue" is forced to use the same
4228 code paths as single-step - set a breakpoint at the
4229 signal return address and then, once hit, step off that
4230 breakpoint. */
237fc4c9
PA
4231 if (debug_infrun)
4232 fprintf_unfiltered (gdb_stdlog,
4233 "infrun: signal arrived while stepping over "
4234 "breakpoint\n");
d3169d93 4235
2c03e5be 4236 insert_hp_step_resume_breakpoint_at_frame (frame);
4e1c45ea 4237 ecs->event_thread->step_after_step_resume_breakpoint = 1;
2455069d
UW
4238 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4239 ecs->event_thread->control.trap_expected = 0;
d137e6dc
PA
4240
4241 /* If we were nexting/stepping some other thread, switch to
4242 it, so that we don't continue it, losing control. */
4243 if (!switch_back_to_stepped_thread (ecs))
4244 keep_going (ecs);
9d799f85 4245 return;
68f53502 4246 }
9d799f85 4247
16c381f0 4248 if (ecs->event_thread->control.step_range_end != 0
a493e3e2 4249 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0
ce4c476a 4250 && pc_in_thread_step_range (stop_pc, ecs->event_thread)
edb3359d 4251 && frame_id_eq (get_stack_frame_id (frame),
16c381f0 4252 ecs->event_thread->control.step_stack_frame_id)
8358c15c 4253 && ecs->event_thread->control.step_resume_breakpoint == NULL)
d303a6c7
AC
4254 {
4255 /* The inferior is about to take a signal that will take it
4256 out of the single step range. Set a breakpoint at the
4257 current PC (which is presumably where the signal handler
4258 will eventually return) and then allow the inferior to
4259 run free.
4260
4261 Note that this is only needed for a signal delivered
4262 while in the single-step range. Nested signals aren't a
4263 problem as they eventually all return. */
237fc4c9
PA
4264 if (debug_infrun)
4265 fprintf_unfiltered (gdb_stdlog,
4266 "infrun: signal may take us out of "
4267 "single-step range\n");
4268
2c03e5be 4269 insert_hp_step_resume_breakpoint_at_frame (frame);
2455069d
UW
4270 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4271 ecs->event_thread->control.trap_expected = 0;
9d799f85
AC
4272 keep_going (ecs);
4273 return;
d303a6c7 4274 }
9d799f85
AC
4275
4276 /* Note: step_resume_breakpoint may be non-NULL. This occures
4277 when either there's a nested signal, or when there's a
4278 pending signal enabled just as the signal handler returns
4279 (leaving the inferior at the step-resume-breakpoint without
4280 actually executing it). Either way continue until the
4281 breakpoint is really hit. */
c447ac0b
PA
4282
4283 if (!switch_back_to_stepped_thread (ecs))
4284 {
4285 if (debug_infrun)
4286 fprintf_unfiltered (gdb_stdlog,
4287 "infrun: random signal, keep going\n");
4288
4289 keep_going (ecs);
4290 }
4291 return;
488f131b 4292 }
94c57d6a
PA
4293
4294 process_event_stop_test (ecs);
4295}
4296
4297/* Come here when we've got some debug event / signal we can explain
4298 (IOW, not a random signal), and test whether it should cause a
4299 stop, or whether we should resume the inferior (transparently).
4300 E.g., could be a breakpoint whose condition evaluates false; we
4301 could be still stepping within the line; etc. */
4302
4303static void
4304process_event_stop_test (struct execution_control_state *ecs)
4305{
4306 struct symtab_and_line stop_pc_sal;
4307 struct frame_info *frame;
4308 struct gdbarch *gdbarch;
cdaa5b73
PA
4309 CORE_ADDR jmp_buf_pc;
4310 struct bpstat_what what;
94c57d6a 4311
cdaa5b73 4312 /* Handle cases caused by hitting a breakpoint. */
611c83ae 4313
cdaa5b73
PA
4314 frame = get_current_frame ();
4315 gdbarch = get_frame_arch (frame);
fcf3daef 4316
cdaa5b73 4317 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
611c83ae 4318
cdaa5b73
PA
4319 if (what.call_dummy)
4320 {
4321 stop_stack_dummy = what.call_dummy;
4322 }
186c406b 4323
cdaa5b73
PA
4324 /* If we hit an internal event that triggers symbol changes, the
4325 current frame will be invalidated within bpstat_what (e.g., if we
4326 hit an internal solib event). Re-fetch it. */
4327 frame = get_current_frame ();
4328 gdbarch = get_frame_arch (frame);
e2e4d78b 4329
cdaa5b73
PA
4330 switch (what.main_action)
4331 {
4332 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4333 /* If we hit the breakpoint at longjmp while stepping, we
4334 install a momentary breakpoint at the target of the
4335 jmp_buf. */
186c406b 4336
cdaa5b73
PA
4337 if (debug_infrun)
4338 fprintf_unfiltered (gdb_stdlog,
4339 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
186c406b 4340
cdaa5b73 4341 ecs->event_thread->stepping_over_breakpoint = 1;
611c83ae 4342
cdaa5b73
PA
4343 if (what.is_longjmp)
4344 {
4345 struct value *arg_value;
4346
4347 /* If we set the longjmp breakpoint via a SystemTap probe,
4348 then use it to extract the arguments. The destination PC
4349 is the third argument to the probe. */
4350 arg_value = probe_safe_evaluate_at_pc (frame, 2);
4351 if (arg_value)
4352 jmp_buf_pc = value_as_address (arg_value);
4353 else if (!gdbarch_get_longjmp_target_p (gdbarch)
4354 || !gdbarch_get_longjmp_target (gdbarch,
4355 frame, &jmp_buf_pc))
e2e4d78b 4356 {
cdaa5b73
PA
4357 if (debug_infrun)
4358 fprintf_unfiltered (gdb_stdlog,
4359 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4360 "(!gdbarch_get_longjmp_target)\n");
4361 keep_going (ecs);
4362 return;
e2e4d78b 4363 }
e2e4d78b 4364
cdaa5b73
PA
4365 /* Insert a breakpoint at resume address. */
4366 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4367 }
4368 else
4369 check_exception_resume (ecs, frame);
4370 keep_going (ecs);
4371 return;
e81a37f7 4372
cdaa5b73
PA
4373 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4374 {
4375 struct frame_info *init_frame;
e81a37f7 4376
cdaa5b73 4377 /* There are several cases to consider.
c906108c 4378
cdaa5b73
PA
4379 1. The initiating frame no longer exists. In this case we
4380 must stop, because the exception or longjmp has gone too
4381 far.
2c03e5be 4382
cdaa5b73
PA
4383 2. The initiating frame exists, and is the same as the
4384 current frame. We stop, because the exception or longjmp
4385 has been caught.
2c03e5be 4386
cdaa5b73
PA
4387 3. The initiating frame exists and is different from the
4388 current frame. This means the exception or longjmp has
4389 been caught beneath the initiating frame, so keep going.
c906108c 4390
cdaa5b73
PA
4391 4. longjmp breakpoint has been placed just to protect
4392 against stale dummy frames and user is not interested in
4393 stopping around longjmps. */
c5aa993b 4394
cdaa5b73
PA
4395 if (debug_infrun)
4396 fprintf_unfiltered (gdb_stdlog,
4397 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
c5aa993b 4398
cdaa5b73
PA
4399 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4400 != NULL);
4401 delete_exception_resume_breakpoint (ecs->event_thread);
c5aa993b 4402
cdaa5b73
PA
4403 if (what.is_longjmp)
4404 {
4405 check_longjmp_breakpoint_for_call_dummy (ecs->event_thread->num);
c5aa993b 4406
cdaa5b73 4407 if (!frame_id_p (ecs->event_thread->initiating_frame))
e5ef252a 4408 {
cdaa5b73
PA
4409 /* Case 4. */
4410 keep_going (ecs);
4411 return;
e5ef252a 4412 }
cdaa5b73 4413 }
c5aa993b 4414
cdaa5b73 4415 init_frame = frame_find_by_id (ecs->event_thread->initiating_frame);
527159b7 4416
cdaa5b73
PA
4417 if (init_frame)
4418 {
4419 struct frame_id current_id
4420 = get_frame_id (get_current_frame ());
4421 if (frame_id_eq (current_id,
4422 ecs->event_thread->initiating_frame))
4423 {
4424 /* Case 2. Fall through. */
4425 }
4426 else
4427 {
4428 /* Case 3. */
4429 keep_going (ecs);
4430 return;
4431 }
68f53502 4432 }
488f131b 4433
cdaa5b73
PA
4434 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4435 exists. */
4436 delete_step_resume_breakpoint (ecs->event_thread);
e5ef252a 4437
cdaa5b73
PA
4438 ecs->event_thread->control.stop_step = 1;
4439 print_end_stepping_range_reason ();
4440 stop_stepping (ecs);
4441 }
4442 return;
e5ef252a 4443
cdaa5b73
PA
4444 case BPSTAT_WHAT_SINGLE:
4445 if (debug_infrun)
4446 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4447 ecs->event_thread->stepping_over_breakpoint = 1;
4448 /* Still need to check other stuff, at least the case where we
4449 are stepping and step out of the right range. */
4450 break;
e5ef252a 4451
cdaa5b73
PA
4452 case BPSTAT_WHAT_STEP_RESUME:
4453 if (debug_infrun)
4454 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
e5ef252a 4455
cdaa5b73
PA
4456 delete_step_resume_breakpoint (ecs->event_thread);
4457 if (ecs->event_thread->control.proceed_to_finish
4458 && execution_direction == EXEC_REVERSE)
4459 {
4460 struct thread_info *tp = ecs->event_thread;
4461
4462 /* We are finishing a function in reverse, and just hit the
4463 step-resume breakpoint at the start address of the
4464 function, and we're almost there -- just need to back up
4465 by one more single-step, which should take us back to the
4466 function call. */
4467 tp->control.step_range_start = tp->control.step_range_end = 1;
4468 keep_going (ecs);
e5ef252a 4469 return;
cdaa5b73
PA
4470 }
4471 fill_in_stop_func (gdbarch, ecs);
4472 if (stop_pc == ecs->stop_func_start
4473 && execution_direction == EXEC_REVERSE)
4474 {
4475 /* We are stepping over a function call in reverse, and just
4476 hit the step-resume breakpoint at the start address of
4477 the function. Go back to single-stepping, which should
4478 take us back to the function call. */
4479 ecs->event_thread->stepping_over_breakpoint = 1;
4480 keep_going (ecs);
4481 return;
4482 }
4483 break;
e5ef252a 4484
cdaa5b73
PA
4485 case BPSTAT_WHAT_STOP_NOISY:
4486 if (debug_infrun)
4487 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4488 stop_print_frame = 1;
e5ef252a 4489
99619bea
PA
4490 /* Assume the thread stopped for a breapoint. We'll still check
4491 whether a/the breakpoint is there when the thread is next
4492 resumed. */
4493 ecs->event_thread->stepping_over_breakpoint = 1;
e5ef252a 4494
cdaa5b73
PA
4495 stop_stepping (ecs);
4496 return;
e5ef252a 4497
cdaa5b73
PA
4498 case BPSTAT_WHAT_STOP_SILENT:
4499 if (debug_infrun)
4500 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4501 stop_print_frame = 0;
e5ef252a 4502
99619bea
PA
4503 /* Assume the thread stopped for a breapoint. We'll still check
4504 whether a/the breakpoint is there when the thread is next
4505 resumed. */
4506 ecs->event_thread->stepping_over_breakpoint = 1;
cdaa5b73
PA
4507 stop_stepping (ecs);
4508 return;
4509
4510 case BPSTAT_WHAT_HP_STEP_RESUME:
4511 if (debug_infrun)
4512 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4513
4514 delete_step_resume_breakpoint (ecs->event_thread);
4515 if (ecs->event_thread->step_after_step_resume_breakpoint)
4516 {
4517 /* Back when the step-resume breakpoint was inserted, we
4518 were trying to single-step off a breakpoint. Go back to
4519 doing that. */
4520 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4521 ecs->event_thread->stepping_over_breakpoint = 1;
4522 keep_going (ecs);
4523 return;
e5ef252a 4524 }
cdaa5b73
PA
4525 break;
4526
4527 case BPSTAT_WHAT_KEEP_CHECKING:
4528 break;
e5ef252a 4529 }
c906108c 4530
cdaa5b73
PA
4531 /* We come here if we hit a breakpoint but should not stop for it.
4532 Possibly we also were stepping and should stop for that. So fall
4533 through and test for stepping. But, if not stepping, do not
4534 stop. */
c906108c 4535
a7212384
UW
4536 /* In all-stop mode, if we're currently stepping but have stopped in
4537 some other thread, we need to switch back to the stepped thread. */
c447ac0b
PA
4538 if (switch_back_to_stepped_thread (ecs))
4539 return;
776f04fa 4540
8358c15c 4541 if (ecs->event_thread->control.step_resume_breakpoint)
488f131b 4542 {
527159b7 4543 if (debug_infrun)
d3169d93
DJ
4544 fprintf_unfiltered (gdb_stdlog,
4545 "infrun: step-resume breakpoint is inserted\n");
527159b7 4546
488f131b
JB
4547 /* Having a step-resume breakpoint overrides anything
4548 else having to do with stepping commands until
4549 that breakpoint is reached. */
488f131b
JB
4550 keep_going (ecs);
4551 return;
4552 }
c5aa993b 4553
16c381f0 4554 if (ecs->event_thread->control.step_range_end == 0)
488f131b 4555 {
527159b7 4556 if (debug_infrun)
8a9de0e4 4557 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
488f131b 4558 /* Likewise if we aren't even stepping. */
488f131b
JB
4559 keep_going (ecs);
4560 return;
4561 }
c5aa993b 4562
4b7703ad
JB
4563 /* Re-fetch current thread's frame in case the code above caused
4564 the frame cache to be re-initialized, making our FRAME variable
4565 a dangling pointer. */
4566 frame = get_current_frame ();
628fe4e4 4567 gdbarch = get_frame_arch (frame);
7e324e48 4568 fill_in_stop_func (gdbarch, ecs);
4b7703ad 4569
488f131b 4570 /* If stepping through a line, keep going if still within it.
c906108c 4571
488f131b
JB
4572 Note that step_range_end is the address of the first instruction
4573 beyond the step range, and NOT the address of the last instruction
31410e84
MS
4574 within it!
4575
4576 Note also that during reverse execution, we may be stepping
4577 through a function epilogue and therefore must detect when
4578 the current-frame changes in the middle of a line. */
4579
ce4c476a 4580 if (pc_in_thread_step_range (stop_pc, ecs->event_thread)
31410e84 4581 && (execution_direction != EXEC_REVERSE
388a8562 4582 || frame_id_eq (get_frame_id (frame),
16c381f0 4583 ecs->event_thread->control.step_frame_id)))
488f131b 4584 {
527159b7 4585 if (debug_infrun)
5af949e3
UW
4586 fprintf_unfiltered
4587 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
16c381f0
JK
4588 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4589 paddress (gdbarch, ecs->event_thread->control.step_range_end));
b2175913 4590
c1e36e3e
PA
4591 /* Tentatively re-enable range stepping; `resume' disables it if
4592 necessary (e.g., if we're stepping over a breakpoint or we
4593 have software watchpoints). */
4594 ecs->event_thread->control.may_range_step = 1;
4595
b2175913
MS
4596 /* When stepping backward, stop at beginning of line range
4597 (unless it's the function entry point, in which case
4598 keep going back to the call point). */
16c381f0 4599 if (stop_pc == ecs->event_thread->control.step_range_start
b2175913
MS
4600 && stop_pc != ecs->stop_func_start
4601 && execution_direction == EXEC_REVERSE)
4602 {
16c381f0 4603 ecs->event_thread->control.stop_step = 1;
33d62d64 4604 print_end_stepping_range_reason ();
b2175913
MS
4605 stop_stepping (ecs);
4606 }
4607 else
4608 keep_going (ecs);
4609
488f131b
JB
4610 return;
4611 }
c5aa993b 4612
488f131b 4613 /* We stepped out of the stepping range. */
c906108c 4614
488f131b 4615 /* If we are stepping at the source level and entered the runtime
388a8562
MS
4616 loader dynamic symbol resolution code...
4617
4618 EXEC_FORWARD: we keep on single stepping until we exit the run
4619 time loader code and reach the callee's address.
4620
4621 EXEC_REVERSE: we've already executed the callee (backward), and
4622 the runtime loader code is handled just like any other
4623 undebuggable function call. Now we need only keep stepping
4624 backward through the trampoline code, and that's handled further
4625 down, so there is nothing for us to do here. */
4626
4627 if (execution_direction != EXEC_REVERSE
16c381f0 4628 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
cfd8ab24 4629 && in_solib_dynsym_resolve_code (stop_pc))
488f131b 4630 {
4c8c40e6 4631 CORE_ADDR pc_after_resolver =
568d6575 4632 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
c906108c 4633
527159b7 4634 if (debug_infrun)
3e43a32a
MS
4635 fprintf_unfiltered (gdb_stdlog,
4636 "infrun: stepped into dynsym resolve code\n");
527159b7 4637
488f131b
JB
4638 if (pc_after_resolver)
4639 {
4640 /* Set up a step-resume breakpoint at the address
4641 indicated by SKIP_SOLIB_RESOLVER. */
4642 struct symtab_and_line sr_sal;
abbb1732 4643
fe39c653 4644 init_sal (&sr_sal);
488f131b 4645 sr_sal.pc = pc_after_resolver;
6c95b8df 4646 sr_sal.pspace = get_frame_program_space (frame);
488f131b 4647
a6d9a66e
UW
4648 insert_step_resume_breakpoint_at_sal (gdbarch,
4649 sr_sal, null_frame_id);
c5aa993b 4650 }
c906108c 4651
488f131b
JB
4652 keep_going (ecs);
4653 return;
4654 }
c906108c 4655
16c381f0
JK
4656 if (ecs->event_thread->control.step_range_end != 1
4657 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4658 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
568d6575 4659 && get_frame_type (frame) == SIGTRAMP_FRAME)
488f131b 4660 {
527159b7 4661 if (debug_infrun)
3e43a32a
MS
4662 fprintf_unfiltered (gdb_stdlog,
4663 "infrun: stepped into signal trampoline\n");
42edda50 4664 /* The inferior, while doing a "step" or "next", has ended up in
8fb3e588
AC
4665 a signal trampoline (either by a signal being delivered or by
4666 the signal handler returning). Just single-step until the
4667 inferior leaves the trampoline (either by calling the handler
4668 or returning). */
488f131b
JB
4669 keep_going (ecs);
4670 return;
4671 }
c906108c 4672
14132e89
MR
4673 /* If we're in the return path from a shared library trampoline,
4674 we want to proceed through the trampoline when stepping. */
4675 /* macro/2012-04-25: This needs to come before the subroutine
4676 call check below as on some targets return trampolines look
4677 like subroutine calls (MIPS16 return thunks). */
4678 if (gdbarch_in_solib_return_trampoline (gdbarch,
4679 stop_pc, ecs->stop_func_name)
4680 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4681 {
4682 /* Determine where this trampoline returns. */
4683 CORE_ADDR real_stop_pc;
4684
4685 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4686
4687 if (debug_infrun)
4688 fprintf_unfiltered (gdb_stdlog,
4689 "infrun: stepped into solib return tramp\n");
4690
4691 /* Only proceed through if we know where it's going. */
4692 if (real_stop_pc)
4693 {
4694 /* And put the step-breakpoint there and go until there. */
4695 struct symtab_and_line sr_sal;
4696
4697 init_sal (&sr_sal); /* initialize to zeroes */
4698 sr_sal.pc = real_stop_pc;
4699 sr_sal.section = find_pc_overlay (sr_sal.pc);
4700 sr_sal.pspace = get_frame_program_space (frame);
4701
4702 /* Do not specify what the fp should be when we stop since
4703 on some machines the prologue is where the new fp value
4704 is established. */
4705 insert_step_resume_breakpoint_at_sal (gdbarch,
4706 sr_sal, null_frame_id);
4707
4708 /* Restart without fiddling with the step ranges or
4709 other state. */
4710 keep_going (ecs);
4711 return;
4712 }
4713 }
4714
c17eaafe
DJ
4715 /* Check for subroutine calls. The check for the current frame
4716 equalling the step ID is not necessary - the check of the
4717 previous frame's ID is sufficient - but it is a common case and
4718 cheaper than checking the previous frame's ID.
14e60db5
DJ
4719
4720 NOTE: frame_id_eq will never report two invalid frame IDs as
4721 being equal, so to get into this block, both the current and
4722 previous frame must have valid frame IDs. */
005ca36a
JB
4723 /* The outer_frame_id check is a heuristic to detect stepping
4724 through startup code. If we step over an instruction which
4725 sets the stack pointer from an invalid value to a valid value,
4726 we may detect that as a subroutine call from the mythical
4727 "outermost" function. This could be fixed by marking
4728 outermost frames as !stack_p,code_p,special_p. Then the
4729 initial outermost frame, before sp was valid, would
ce6cca6d 4730 have code_addr == &_start. See the comment in frame_id_eq
005ca36a 4731 for more. */
edb3359d 4732 if (!frame_id_eq (get_stack_frame_id (frame),
16c381f0 4733 ecs->event_thread->control.step_stack_frame_id)
005ca36a 4734 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
16c381f0
JK
4735 ecs->event_thread->control.step_stack_frame_id)
4736 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
005ca36a
JB
4737 outer_frame_id)
4738 || step_start_function != find_pc_function (stop_pc))))
488f131b 4739 {
95918acb 4740 CORE_ADDR real_stop_pc;
8fb3e588 4741
527159b7 4742 if (debug_infrun)
8a9de0e4 4743 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
527159b7 4744
16c381f0
JK
4745 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4746 || ((ecs->event_thread->control.step_range_end == 1)
d80b854b 4747 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4e1c45ea 4748 ecs->stop_func_start)))
95918acb
AC
4749 {
4750 /* I presume that step_over_calls is only 0 when we're
4751 supposed to be stepping at the assembly language level
4752 ("stepi"). Just stop. */
4753 /* Also, maybe we just did a "nexti" inside a prolog, so we
4754 thought it was a subroutine call but it was not. Stop as
4755 well. FENN */
388a8562 4756 /* And this works the same backward as frontward. MVS */
16c381f0 4757 ecs->event_thread->control.stop_step = 1;
33d62d64 4758 print_end_stepping_range_reason ();
95918acb
AC
4759 stop_stepping (ecs);
4760 return;
4761 }
8fb3e588 4762
388a8562
MS
4763 /* Reverse stepping through solib trampolines. */
4764
4765 if (execution_direction == EXEC_REVERSE
16c381f0 4766 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
388a8562
MS
4767 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4768 || (ecs->stop_func_start == 0
4769 && in_solib_dynsym_resolve_code (stop_pc))))
4770 {
4771 /* Any solib trampoline code can be handled in reverse
4772 by simply continuing to single-step. We have already
4773 executed the solib function (backwards), and a few
4774 steps will take us back through the trampoline to the
4775 caller. */
4776 keep_going (ecs);
4777 return;
4778 }
4779
16c381f0 4780 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
8567c30f 4781 {
b2175913
MS
4782 /* We're doing a "next".
4783
4784 Normal (forward) execution: set a breakpoint at the
4785 callee's return address (the address at which the caller
4786 will resume).
4787
4788 Reverse (backward) execution. set the step-resume
4789 breakpoint at the start of the function that we just
4790 stepped into (backwards), and continue to there. When we
6130d0b7 4791 get there, we'll need to single-step back to the caller. */
b2175913
MS
4792
4793 if (execution_direction == EXEC_REVERSE)
4794 {
acf9414f
JK
4795 /* If we're already at the start of the function, we've either
4796 just stepped backward into a single instruction function,
4797 or stepped back out of a signal handler to the first instruction
4798 of the function. Just keep going, which will single-step back
4799 to the caller. */
58c48e72 4800 if (ecs->stop_func_start != stop_pc && ecs->stop_func_start != 0)
acf9414f
JK
4801 {
4802 struct symtab_and_line sr_sal;
4803
4804 /* Normal function call return (static or dynamic). */
4805 init_sal (&sr_sal);
4806 sr_sal.pc = ecs->stop_func_start;
4807 sr_sal.pspace = get_frame_program_space (frame);
4808 insert_step_resume_breakpoint_at_sal (gdbarch,
4809 sr_sal, null_frame_id);
4810 }
b2175913
MS
4811 }
4812 else
568d6575 4813 insert_step_resume_breakpoint_at_caller (frame);
b2175913 4814
8567c30f
AC
4815 keep_going (ecs);
4816 return;
4817 }
a53c66de 4818
95918acb 4819 /* If we are in a function call trampoline (a stub between the
8fb3e588
AC
4820 calling routine and the real function), locate the real
4821 function. That's what tells us (a) whether we want to step
4822 into it at all, and (b) what prologue we want to run to the
4823 end of, if we do step into it. */
568d6575 4824 real_stop_pc = skip_language_trampoline (frame, stop_pc);
95918acb 4825 if (real_stop_pc == 0)
568d6575 4826 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
95918acb
AC
4827 if (real_stop_pc != 0)
4828 ecs->stop_func_start = real_stop_pc;
8fb3e588 4829
db5f024e 4830 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
1b2bfbb9
RC
4831 {
4832 struct symtab_and_line sr_sal;
abbb1732 4833
1b2bfbb9
RC
4834 init_sal (&sr_sal);
4835 sr_sal.pc = ecs->stop_func_start;
6c95b8df 4836 sr_sal.pspace = get_frame_program_space (frame);
1b2bfbb9 4837
a6d9a66e
UW
4838 insert_step_resume_breakpoint_at_sal (gdbarch,
4839 sr_sal, null_frame_id);
8fb3e588
AC
4840 keep_going (ecs);
4841 return;
1b2bfbb9
RC
4842 }
4843
95918acb 4844 /* If we have line number information for the function we are
1bfeeb0f
JL
4845 thinking of stepping into and the function isn't on the skip
4846 list, step into it.
95918acb 4847
8fb3e588
AC
4848 If there are several symtabs at that PC (e.g. with include
4849 files), just want to know whether *any* of them have line
4850 numbers. find_pc_line handles this. */
95918acb
AC
4851 {
4852 struct symtab_and_line tmp_sal;
8fb3e588 4853
95918acb 4854 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2b914b52 4855 if (tmp_sal.line != 0
85817405
JK
4856 && !function_name_is_marked_for_skip (ecs->stop_func_name,
4857 &tmp_sal))
95918acb 4858 {
b2175913 4859 if (execution_direction == EXEC_REVERSE)
568d6575 4860 handle_step_into_function_backward (gdbarch, ecs);
b2175913 4861 else
568d6575 4862 handle_step_into_function (gdbarch, ecs);
95918acb
AC
4863 return;
4864 }
4865 }
4866
4867 /* If we have no line number and the step-stop-if-no-debug is
8fb3e588
AC
4868 set, we stop the step so that the user has a chance to switch
4869 in assembly mode. */
16c381f0 4870 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
078130d0 4871 && step_stop_if_no_debug)
95918acb 4872 {
16c381f0 4873 ecs->event_thread->control.stop_step = 1;
33d62d64 4874 print_end_stepping_range_reason ();
95918acb
AC
4875 stop_stepping (ecs);
4876 return;
4877 }
4878
b2175913
MS
4879 if (execution_direction == EXEC_REVERSE)
4880 {
acf9414f
JK
4881 /* If we're already at the start of the function, we've either just
4882 stepped backward into a single instruction function without line
4883 number info, or stepped back out of a signal handler to the first
4884 instruction of the function without line number info. Just keep
4885 going, which will single-step back to the caller. */
4886 if (ecs->stop_func_start != stop_pc)
4887 {
4888 /* Set a breakpoint at callee's start address.
4889 From there we can step once and be back in the caller. */
4890 struct symtab_and_line sr_sal;
abbb1732 4891
acf9414f
JK
4892 init_sal (&sr_sal);
4893 sr_sal.pc = ecs->stop_func_start;
4894 sr_sal.pspace = get_frame_program_space (frame);
4895 insert_step_resume_breakpoint_at_sal (gdbarch,
4896 sr_sal, null_frame_id);
4897 }
b2175913
MS
4898 }
4899 else
4900 /* Set a breakpoint at callee's return address (the address
4901 at which the caller will resume). */
568d6575 4902 insert_step_resume_breakpoint_at_caller (frame);
b2175913 4903
95918acb 4904 keep_going (ecs);
488f131b 4905 return;
488f131b 4906 }
c906108c 4907
fdd654f3
MS
4908 /* Reverse stepping through solib trampolines. */
4909
4910 if (execution_direction == EXEC_REVERSE
16c381f0 4911 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
fdd654f3
MS
4912 {
4913 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4914 || (ecs->stop_func_start == 0
4915 && in_solib_dynsym_resolve_code (stop_pc)))
4916 {
4917 /* Any solib trampoline code can be handled in reverse
4918 by simply continuing to single-step. We have already
4919 executed the solib function (backwards), and a few
4920 steps will take us back through the trampoline to the
4921 caller. */
4922 keep_going (ecs);
4923 return;
4924 }
4925 else if (in_solib_dynsym_resolve_code (stop_pc))
4926 {
4927 /* Stepped backward into the solib dynsym resolver.
4928 Set a breakpoint at its start and continue, then
4929 one more step will take us out. */
4930 struct symtab_and_line sr_sal;
abbb1732 4931
fdd654f3
MS
4932 init_sal (&sr_sal);
4933 sr_sal.pc = ecs->stop_func_start;
9d1807c3 4934 sr_sal.pspace = get_frame_program_space (frame);
fdd654f3
MS
4935 insert_step_resume_breakpoint_at_sal (gdbarch,
4936 sr_sal, null_frame_id);
4937 keep_going (ecs);
4938 return;
4939 }
4940 }
4941
2afb61aa 4942 stop_pc_sal = find_pc_line (stop_pc, 0);
7ed0fe66 4943
1b2bfbb9
RC
4944 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4945 the trampoline processing logic, however, there are some trampolines
4946 that have no names, so we should do trampoline handling first. */
16c381f0 4947 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
7ed0fe66 4948 && ecs->stop_func_name == NULL
2afb61aa 4949 && stop_pc_sal.line == 0)
1b2bfbb9 4950 {
527159b7 4951 if (debug_infrun)
3e43a32a
MS
4952 fprintf_unfiltered (gdb_stdlog,
4953 "infrun: stepped into undebuggable function\n");
527159b7 4954
1b2bfbb9 4955 /* The inferior just stepped into, or returned to, an
7ed0fe66
DJ
4956 undebuggable function (where there is no debugging information
4957 and no line number corresponding to the address where the
1b2bfbb9
RC
4958 inferior stopped). Since we want to skip this kind of code,
4959 we keep going until the inferior returns from this
14e60db5
DJ
4960 function - unless the user has asked us not to (via
4961 set step-mode) or we no longer know how to get back
4962 to the call site. */
4963 if (step_stop_if_no_debug
c7ce8faa 4964 || !frame_id_p (frame_unwind_caller_id (frame)))
1b2bfbb9
RC
4965 {
4966 /* If we have no line number and the step-stop-if-no-debug
4967 is set, we stop the step so that the user has a chance to
4968 switch in assembly mode. */
16c381f0 4969 ecs->event_thread->control.stop_step = 1;
33d62d64 4970 print_end_stepping_range_reason ();
1b2bfbb9
RC
4971 stop_stepping (ecs);
4972 return;
4973 }
4974 else
4975 {
4976 /* Set a breakpoint at callee's return address (the address
4977 at which the caller will resume). */
568d6575 4978 insert_step_resume_breakpoint_at_caller (frame);
1b2bfbb9
RC
4979 keep_going (ecs);
4980 return;
4981 }
4982 }
4983
16c381f0 4984 if (ecs->event_thread->control.step_range_end == 1)
1b2bfbb9
RC
4985 {
4986 /* It is stepi or nexti. We always want to stop stepping after
4987 one instruction. */
527159b7 4988 if (debug_infrun)
8a9de0e4 4989 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
16c381f0 4990 ecs->event_thread->control.stop_step = 1;
33d62d64 4991 print_end_stepping_range_reason ();
1b2bfbb9
RC
4992 stop_stepping (ecs);
4993 return;
4994 }
4995
2afb61aa 4996 if (stop_pc_sal.line == 0)
488f131b
JB
4997 {
4998 /* We have no line number information. That means to stop
4999 stepping (does this always happen right after one instruction,
5000 when we do "s" in a function with no line numbers,
5001 or can this happen as a result of a return or longjmp?). */
527159b7 5002 if (debug_infrun)
8a9de0e4 5003 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
16c381f0 5004 ecs->event_thread->control.stop_step = 1;
33d62d64 5005 print_end_stepping_range_reason ();
488f131b
JB
5006 stop_stepping (ecs);
5007 return;
5008 }
c906108c 5009
edb3359d
DJ
5010 /* Look for "calls" to inlined functions, part one. If the inline
5011 frame machinery detected some skipped call sites, we have entered
5012 a new inline function. */
5013
5014 if (frame_id_eq (get_frame_id (get_current_frame ()),
16c381f0 5015 ecs->event_thread->control.step_frame_id)
edb3359d
DJ
5016 && inline_skipped_frames (ecs->ptid))
5017 {
5018 struct symtab_and_line call_sal;
5019
5020 if (debug_infrun)
5021 fprintf_unfiltered (gdb_stdlog,
5022 "infrun: stepped into inlined function\n");
5023
5024 find_frame_sal (get_current_frame (), &call_sal);
5025
16c381f0 5026 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
edb3359d
DJ
5027 {
5028 /* For "step", we're going to stop. But if the call site
5029 for this inlined function is on the same source line as
5030 we were previously stepping, go down into the function
5031 first. Otherwise stop at the call site. */
5032
5033 if (call_sal.line == ecs->event_thread->current_line
5034 && call_sal.symtab == ecs->event_thread->current_symtab)
5035 step_into_inline_frame (ecs->ptid);
5036
16c381f0 5037 ecs->event_thread->control.stop_step = 1;
33d62d64 5038 print_end_stepping_range_reason ();
edb3359d
DJ
5039 stop_stepping (ecs);
5040 return;
5041 }
5042 else
5043 {
5044 /* For "next", we should stop at the call site if it is on a
5045 different source line. Otherwise continue through the
5046 inlined function. */
5047 if (call_sal.line == ecs->event_thread->current_line
5048 && call_sal.symtab == ecs->event_thread->current_symtab)
5049 keep_going (ecs);
5050 else
5051 {
16c381f0 5052 ecs->event_thread->control.stop_step = 1;
33d62d64 5053 print_end_stepping_range_reason ();
edb3359d
DJ
5054 stop_stepping (ecs);
5055 }
5056 return;
5057 }
5058 }
5059
5060 /* Look for "calls" to inlined functions, part two. If we are still
5061 in the same real function we were stepping through, but we have
5062 to go further up to find the exact frame ID, we are stepping
5063 through a more inlined call beyond its call site. */
5064
5065 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5066 && !frame_id_eq (get_frame_id (get_current_frame ()),
16c381f0 5067 ecs->event_thread->control.step_frame_id)
edb3359d 5068 && stepped_in_from (get_current_frame (),
16c381f0 5069 ecs->event_thread->control.step_frame_id))
edb3359d
DJ
5070 {
5071 if (debug_infrun)
5072 fprintf_unfiltered (gdb_stdlog,
5073 "infrun: stepping through inlined function\n");
5074
16c381f0 5075 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
edb3359d
DJ
5076 keep_going (ecs);
5077 else
5078 {
16c381f0 5079 ecs->event_thread->control.stop_step = 1;
33d62d64 5080 print_end_stepping_range_reason ();
edb3359d
DJ
5081 stop_stepping (ecs);
5082 }
5083 return;
5084 }
5085
2afb61aa 5086 if ((stop_pc == stop_pc_sal.pc)
4e1c45ea
PA
5087 && (ecs->event_thread->current_line != stop_pc_sal.line
5088 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
488f131b
JB
5089 {
5090 /* We are at the start of a different line. So stop. Note that
5091 we don't stop if we step into the middle of a different line.
5092 That is said to make things like for (;;) statements work
5093 better. */
527159b7 5094 if (debug_infrun)
3e43a32a
MS
5095 fprintf_unfiltered (gdb_stdlog,
5096 "infrun: stepped to a different line\n");
16c381f0 5097 ecs->event_thread->control.stop_step = 1;
33d62d64 5098 print_end_stepping_range_reason ();
488f131b
JB
5099 stop_stepping (ecs);
5100 return;
5101 }
c906108c 5102
488f131b 5103 /* We aren't done stepping.
c906108c 5104
488f131b
JB
5105 Optimize by setting the stepping range to the line.
5106 (We might not be in the original line, but if we entered a
5107 new line in mid-statement, we continue stepping. This makes
5108 things like for(;;) statements work better.) */
c906108c 5109
16c381f0
JK
5110 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5111 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
c1e36e3e 5112 ecs->event_thread->control.may_range_step = 1;
edb3359d 5113 set_step_info (frame, stop_pc_sal);
488f131b 5114
527159b7 5115 if (debug_infrun)
8a9de0e4 5116 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
488f131b 5117 keep_going (ecs);
104c1213
JM
5118}
5119
c447ac0b
PA
5120/* In all-stop mode, if we're currently stepping but have stopped in
5121 some other thread, we may need to switch back to the stepped
5122 thread. Returns true we set the inferior running, false if we left
5123 it stopped (and the event needs further processing). */
5124
5125static int
5126switch_back_to_stepped_thread (struct execution_control_state *ecs)
5127{
5128 if (!non_stop)
5129 {
5130 struct thread_info *tp;
99619bea
PA
5131 struct thread_info *stepping_thread;
5132
5133 /* If any thread is blocked on some internal breakpoint, and we
5134 simply need to step over that breakpoint to get it going
5135 again, do that first. */
5136
5137 /* However, if we see an event for the stepping thread, then we
5138 know all other threads have been moved past their breakpoints
5139 already. Let the caller check whether the step is finished,
5140 etc., before deciding to move it past a breakpoint. */
5141 if (ecs->event_thread->control.step_range_end != 0)
5142 return 0;
5143
5144 /* Check if the current thread is blocked on an incomplete
5145 step-over, interrupted by a random signal. */
5146 if (ecs->event_thread->control.trap_expected
5147 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
c447ac0b 5148 {
99619bea
PA
5149 if (debug_infrun)
5150 {
5151 fprintf_unfiltered (gdb_stdlog,
5152 "infrun: need to finish step-over of [%s]\n",
5153 target_pid_to_str (ecs->event_thread->ptid));
5154 }
5155 keep_going (ecs);
5156 return 1;
5157 }
2adfaa28 5158
99619bea
PA
5159 /* Check if the current thread is blocked by a single-step
5160 breakpoint of another thread. */
5161 if (ecs->hit_singlestep_breakpoint)
5162 {
5163 if (debug_infrun)
5164 {
5165 fprintf_unfiltered (gdb_stdlog,
5166 "infrun: need to step [%s] over single-step "
5167 "breakpoint\n",
5168 target_pid_to_str (ecs->ptid));
5169 }
5170 keep_going (ecs);
5171 return 1;
5172 }
5173
5174 stepping_thread
5175 = iterate_over_threads (currently_stepping_or_nexting_callback,
5176 ecs->event_thread);
5177
5178 /* Check if any other thread except the stepping thread that
5179 needs to start a step-over. Do that before actually
5180 proceeding with step/next/etc. */
5181 tp = find_thread_needs_step_over (stepping_thread != NULL,
5182 stepping_thread);
5183 if (tp != NULL)
5184 {
5185 if (debug_infrun)
c447ac0b 5186 {
99619bea
PA
5187 fprintf_unfiltered (gdb_stdlog,
5188 "infrun: need to step-over [%s]\n",
5189 target_pid_to_str (tp->ptid));
c447ac0b
PA
5190 }
5191
99619bea
PA
5192 gdb_assert (!tp->control.trap_expected);
5193 gdb_assert (tp->control.step_range_end == 0);
5194
5195 /* We no longer expect a trap in the current thread. Clear
5196 the trap_expected flag before switching. This is what
5197 keep_going would do as well, if we called it. */
5198 ecs->event_thread->control.trap_expected = 0;
5199
5200 ecs->ptid = tp->ptid;
5201 ecs->event_thread = tp;
5202 switch_to_thread (ecs->ptid);
5203 keep_going (ecs);
5204 return 1;
5205 }
5206
5207 tp = stepping_thread;
5208 if (tp != NULL)
5209 {
5210 struct frame_info *frame;
5211 struct gdbarch *gdbarch;
5212
c447ac0b
PA
5213 /* If the stepping thread exited, then don't try to switch
5214 back and resume it, which could fail in several different
5215 ways depending on the target. Instead, just keep going.
5216
5217 We can find a stepping dead thread in the thread list in
5218 two cases:
5219
5220 - The target supports thread exit events, and when the
5221 target tries to delete the thread from the thread list,
5222 inferior_ptid pointed at the exiting thread. In such
5223 case, calling delete_thread does not really remove the
5224 thread from the list; instead, the thread is left listed,
5225 with 'exited' state.
5226
5227 - The target's debug interface does not support thread
5228 exit events, and so we have no idea whatsoever if the
5229 previously stepping thread is still alive. For that
5230 reason, we need to synchronously query the target
5231 now. */
5232 if (is_exited (tp->ptid)
5233 || !target_thread_alive (tp->ptid))
5234 {
5235 if (debug_infrun)
5236 fprintf_unfiltered (gdb_stdlog,
5237 "infrun: not switching back to "
5238 "stepped thread, it has vanished\n");
5239
5240 delete_thread (tp->ptid);
5241 keep_going (ecs);
5242 return 1;
5243 }
5244
5245 /* Otherwise, we no longer expect a trap in the current thread.
5246 Clear the trap_expected flag before switching back -- this is
5247 what keep_going would do as well, if we called it. */
5248 ecs->event_thread->control.trap_expected = 0;
5249
5250 if (debug_infrun)
5251 fprintf_unfiltered (gdb_stdlog,
5252 "infrun: switching back to stepped thread\n");
5253
5254 ecs->event_thread = tp;
5255 ecs->ptid = tp->ptid;
5256 context_switch (ecs->ptid);
2adfaa28
PA
5257
5258 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
5259 frame = get_current_frame ();
5260 gdbarch = get_frame_arch (frame);
5261
5262 /* If the PC of the thread we were trying to single-step has
99619bea
PA
5263 changed, then that thread has trapped or been signaled,
5264 but the event has not been reported to GDB yet. Re-poll
5265 the target looking for this particular thread's event
5266 (i.e. temporarily enable schedlock) by:
2adfaa28
PA
5267
5268 - setting a break at the current PC
5269 - resuming that particular thread, only (by setting
5270 trap expected)
5271
5272 This prevents us continuously moving the single-step
5273 breakpoint forward, one instruction at a time,
5274 overstepping. */
5275
5276 if (gdbarch_software_single_step_p (gdbarch)
5277 && stop_pc != tp->prev_pc)
5278 {
5279 if (debug_infrun)
5280 fprintf_unfiltered (gdb_stdlog,
5281 "infrun: expected thread advanced also\n");
5282
5283 insert_single_step_breakpoint (get_frame_arch (frame),
5284 get_frame_address_space (frame),
5285 stop_pc);
5286 singlestep_breakpoints_inserted_p = 1;
5287 ecs->event_thread->control.trap_expected = 1;
5288 singlestep_ptid = inferior_ptid;
5289 singlestep_pc = stop_pc;
5290
5291 resume (0, GDB_SIGNAL_0);
5292 prepare_to_wait (ecs);
5293 }
5294 else
5295 {
5296 if (debug_infrun)
5297 fprintf_unfiltered (gdb_stdlog,
5298 "infrun: expected thread still "
5299 "hasn't advanced\n");
5300 keep_going (ecs);
5301 }
5302
c447ac0b
PA
5303 return 1;
5304 }
5305 }
5306 return 0;
5307}
5308
b3444185 5309/* Is thread TP in the middle of single-stepping? */
104c1213 5310
a289b8f6 5311static int
b3444185 5312currently_stepping (struct thread_info *tp)
a7212384 5313{
8358c15c
JK
5314 return ((tp->control.step_range_end
5315 && tp->control.step_resume_breakpoint == NULL)
5316 || tp->control.trap_expected
8358c15c 5317 || bpstat_should_step ());
a7212384
UW
5318}
5319
b3444185
PA
5320/* Returns true if any thread *but* the one passed in "data" is in the
5321 middle of stepping or of handling a "next". */
a7212384 5322
104c1213 5323static int
b3444185 5324currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
104c1213 5325{
b3444185
PA
5326 if (tp == data)
5327 return 0;
5328
16c381f0 5329 return (tp->control.step_range_end
ede1849f 5330 || tp->control.trap_expected);
104c1213 5331}
c906108c 5332
b2175913
MS
5333/* Inferior has stepped into a subroutine call with source code that
5334 we should not step over. Do step to the first line of code in
5335 it. */
c2c6d25f
JM
5336
5337static void
568d6575
UW
5338handle_step_into_function (struct gdbarch *gdbarch,
5339 struct execution_control_state *ecs)
c2c6d25f
JM
5340{
5341 struct symtab *s;
2afb61aa 5342 struct symtab_and_line stop_func_sal, sr_sal;
c2c6d25f 5343
7e324e48
GB
5344 fill_in_stop_func (gdbarch, ecs);
5345
c2c6d25f
JM
5346 s = find_pc_symtab (stop_pc);
5347 if (s && s->language != language_asm)
568d6575 5348 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
b2175913 5349 ecs->stop_func_start);
c2c6d25f 5350
2afb61aa 5351 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
c2c6d25f
JM
5352 /* Use the step_resume_break to step until the end of the prologue,
5353 even if that involves jumps (as it seems to on the vax under
5354 4.2). */
5355 /* If the prologue ends in the middle of a source line, continue to
5356 the end of that source line (if it is still within the function).
5357 Otherwise, just go to end of prologue. */
2afb61aa
PA
5358 if (stop_func_sal.end
5359 && stop_func_sal.pc != ecs->stop_func_start
5360 && stop_func_sal.end < ecs->stop_func_end)
5361 ecs->stop_func_start = stop_func_sal.end;
c2c6d25f 5362
2dbd5e30
KB
5363 /* Architectures which require breakpoint adjustment might not be able
5364 to place a breakpoint at the computed address. If so, the test
5365 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5366 ecs->stop_func_start to an address at which a breakpoint may be
5367 legitimately placed.
8fb3e588 5368
2dbd5e30
KB
5369 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5370 made, GDB will enter an infinite loop when stepping through
5371 optimized code consisting of VLIW instructions which contain
5372 subinstructions corresponding to different source lines. On
5373 FR-V, it's not permitted to place a breakpoint on any but the
5374 first subinstruction of a VLIW instruction. When a breakpoint is
5375 set, GDB will adjust the breakpoint address to the beginning of
5376 the VLIW instruction. Thus, we need to make the corresponding
5377 adjustment here when computing the stop address. */
8fb3e588 5378
568d6575 5379 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
2dbd5e30
KB
5380 {
5381 ecs->stop_func_start
568d6575 5382 = gdbarch_adjust_breakpoint_address (gdbarch,
8fb3e588 5383 ecs->stop_func_start);
2dbd5e30
KB
5384 }
5385
c2c6d25f
JM
5386 if (ecs->stop_func_start == stop_pc)
5387 {
5388 /* We are already there: stop now. */
16c381f0 5389 ecs->event_thread->control.stop_step = 1;
33d62d64 5390 print_end_stepping_range_reason ();
c2c6d25f
JM
5391 stop_stepping (ecs);
5392 return;
5393 }
5394 else
5395 {
5396 /* Put the step-breakpoint there and go until there. */
fe39c653 5397 init_sal (&sr_sal); /* initialize to zeroes */
c2c6d25f
JM
5398 sr_sal.pc = ecs->stop_func_start;
5399 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
6c95b8df 5400 sr_sal.pspace = get_frame_program_space (get_current_frame ());
44cbf7b5 5401
c2c6d25f 5402 /* Do not specify what the fp should be when we stop since on
488f131b
JB
5403 some machines the prologue is where the new fp value is
5404 established. */
a6d9a66e 5405 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
c2c6d25f
JM
5406
5407 /* And make sure stepping stops right away then. */
16c381f0
JK
5408 ecs->event_thread->control.step_range_end
5409 = ecs->event_thread->control.step_range_start;
c2c6d25f
JM
5410 }
5411 keep_going (ecs);
5412}
d4f3574e 5413
b2175913
MS
5414/* Inferior has stepped backward into a subroutine call with source
5415 code that we should not step over. Do step to the beginning of the
5416 last line of code in it. */
5417
5418static void
568d6575
UW
5419handle_step_into_function_backward (struct gdbarch *gdbarch,
5420 struct execution_control_state *ecs)
b2175913
MS
5421{
5422 struct symtab *s;
167e4384 5423 struct symtab_and_line stop_func_sal;
b2175913 5424
7e324e48
GB
5425 fill_in_stop_func (gdbarch, ecs);
5426
b2175913
MS
5427 s = find_pc_symtab (stop_pc);
5428 if (s && s->language != language_asm)
568d6575 5429 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
b2175913
MS
5430 ecs->stop_func_start);
5431
5432 stop_func_sal = find_pc_line (stop_pc, 0);
5433
5434 /* OK, we're just going to keep stepping here. */
5435 if (stop_func_sal.pc == stop_pc)
5436 {
5437 /* We're there already. Just stop stepping now. */
16c381f0 5438 ecs->event_thread->control.stop_step = 1;
33d62d64 5439 print_end_stepping_range_reason ();
b2175913
MS
5440 stop_stepping (ecs);
5441 }
5442 else
5443 {
5444 /* Else just reset the step range and keep going.
5445 No step-resume breakpoint, they don't work for
5446 epilogues, which can have multiple entry paths. */
16c381f0
JK
5447 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5448 ecs->event_thread->control.step_range_end = stop_func_sal.end;
b2175913
MS
5449 keep_going (ecs);
5450 }
5451 return;
5452}
5453
d3169d93 5454/* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
44cbf7b5
AC
5455 This is used to both functions and to skip over code. */
5456
5457static void
2c03e5be
PA
5458insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
5459 struct symtab_and_line sr_sal,
5460 struct frame_id sr_id,
5461 enum bptype sr_type)
44cbf7b5 5462{
611c83ae
PA
5463 /* There should never be more than one step-resume or longjmp-resume
5464 breakpoint per thread, so we should never be setting a new
44cbf7b5 5465 step_resume_breakpoint when one is already active. */
8358c15c 5466 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
2c03e5be 5467 gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume);
d3169d93
DJ
5468
5469 if (debug_infrun)
5470 fprintf_unfiltered (gdb_stdlog,
5af949e3
UW
5471 "infrun: inserting step-resume breakpoint at %s\n",
5472 paddress (gdbarch, sr_sal.pc));
d3169d93 5473
8358c15c 5474 inferior_thread ()->control.step_resume_breakpoint
2c03e5be
PA
5475 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
5476}
5477
9da8c2a0 5478void
2c03e5be
PA
5479insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5480 struct symtab_and_line sr_sal,
5481 struct frame_id sr_id)
5482{
5483 insert_step_resume_breakpoint_at_sal_1 (gdbarch,
5484 sr_sal, sr_id,
5485 bp_step_resume);
44cbf7b5 5486}
7ce450bd 5487
2c03e5be
PA
5488/* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5489 This is used to skip a potential signal handler.
7ce450bd 5490
14e60db5
DJ
5491 This is called with the interrupted function's frame. The signal
5492 handler, when it returns, will resume the interrupted function at
5493 RETURN_FRAME.pc. */
d303a6c7
AC
5494
5495static void
2c03e5be 5496insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
d303a6c7
AC
5497{
5498 struct symtab_and_line sr_sal;
a6d9a66e 5499 struct gdbarch *gdbarch;
d303a6c7 5500
f4c1edd8 5501 gdb_assert (return_frame != NULL);
d303a6c7
AC
5502 init_sal (&sr_sal); /* initialize to zeros */
5503
a6d9a66e 5504 gdbarch = get_frame_arch (return_frame);
568d6575 5505 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
d303a6c7 5506 sr_sal.section = find_pc_overlay (sr_sal.pc);
6c95b8df 5507 sr_sal.pspace = get_frame_program_space (return_frame);
d303a6c7 5508
2c03e5be
PA
5509 insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal,
5510 get_stack_frame_id (return_frame),
5511 bp_hp_step_resume);
d303a6c7
AC
5512}
5513
2c03e5be
PA
5514/* Insert a "step-resume breakpoint" at the previous frame's PC. This
5515 is used to skip a function after stepping into it (for "next" or if
5516 the called function has no debugging information).
14e60db5
DJ
5517
5518 The current function has almost always been reached by single
5519 stepping a call or return instruction. NEXT_FRAME belongs to the
5520 current function, and the breakpoint will be set at the caller's
5521 resume address.
5522
5523 This is a separate function rather than reusing
2c03e5be 5524 insert_hp_step_resume_breakpoint_at_frame in order to avoid
14e60db5 5525 get_prev_frame, which may stop prematurely (see the implementation
c7ce8faa 5526 of frame_unwind_caller_id for an example). */
14e60db5
DJ
5527
5528static void
5529insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5530{
5531 struct symtab_and_line sr_sal;
a6d9a66e 5532 struct gdbarch *gdbarch;
14e60db5
DJ
5533
5534 /* We shouldn't have gotten here if we don't know where the call site
5535 is. */
c7ce8faa 5536 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
14e60db5
DJ
5537
5538 init_sal (&sr_sal); /* initialize to zeros */
5539
a6d9a66e 5540 gdbarch = frame_unwind_caller_arch (next_frame);
c7ce8faa
DJ
5541 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5542 frame_unwind_caller_pc (next_frame));
14e60db5 5543 sr_sal.section = find_pc_overlay (sr_sal.pc);
6c95b8df 5544 sr_sal.pspace = frame_unwind_program_space (next_frame);
14e60db5 5545
a6d9a66e 5546 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
c7ce8faa 5547 frame_unwind_caller_id (next_frame));
14e60db5
DJ
5548}
5549
611c83ae
PA
5550/* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5551 new breakpoint at the target of a jmp_buf. The handling of
5552 longjmp-resume uses the same mechanisms used for handling
5553 "step-resume" breakpoints. */
5554
5555static void
a6d9a66e 5556insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
611c83ae 5557{
e81a37f7
TT
5558 /* There should never be more than one longjmp-resume breakpoint per
5559 thread, so we should never be setting a new
611c83ae 5560 longjmp_resume_breakpoint when one is already active. */
e81a37f7 5561 gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL);
611c83ae
PA
5562
5563 if (debug_infrun)
5564 fprintf_unfiltered (gdb_stdlog,
5af949e3
UW
5565 "infrun: inserting longjmp-resume breakpoint at %s\n",
5566 paddress (gdbarch, pc));
611c83ae 5567
e81a37f7 5568 inferior_thread ()->control.exception_resume_breakpoint =
a6d9a66e 5569 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
611c83ae
PA
5570}
5571
186c406b
TT
5572/* Insert an exception resume breakpoint. TP is the thread throwing
5573 the exception. The block B is the block of the unwinder debug hook
5574 function. FRAME is the frame corresponding to the call to this
5575 function. SYM is the symbol of the function argument holding the
5576 target PC of the exception. */
5577
5578static void
5579insert_exception_resume_breakpoint (struct thread_info *tp,
5580 struct block *b,
5581 struct frame_info *frame,
5582 struct symbol *sym)
5583{
bfd189b1 5584 volatile struct gdb_exception e;
186c406b
TT
5585
5586 /* We want to ignore errors here. */
5587 TRY_CATCH (e, RETURN_MASK_ERROR)
5588 {
5589 struct symbol *vsym;
5590 struct value *value;
5591 CORE_ADDR handler;
5592 struct breakpoint *bp;
5593
5594 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5595 value = read_var_value (vsym, frame);
5596 /* If the value was optimized out, revert to the old behavior. */
5597 if (! value_optimized_out (value))
5598 {
5599 handler = value_as_address (value);
5600
5601 if (debug_infrun)
5602 fprintf_unfiltered (gdb_stdlog,
5603 "infrun: exception resume at %lx\n",
5604 (unsigned long) handler);
5605
5606 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5607 handler, bp_exception_resume);
c70a6932
JK
5608
5609 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5610 frame = NULL;
5611
186c406b
TT
5612 bp->thread = tp->num;
5613 inferior_thread ()->control.exception_resume_breakpoint = bp;
5614 }
5615 }
5616}
5617
28106bc2
SDJ
5618/* A helper for check_exception_resume that sets an
5619 exception-breakpoint based on a SystemTap probe. */
5620
5621static void
5622insert_exception_resume_from_probe (struct thread_info *tp,
729662a5 5623 const struct bound_probe *probe,
28106bc2
SDJ
5624 struct frame_info *frame)
5625{
5626 struct value *arg_value;
5627 CORE_ADDR handler;
5628 struct breakpoint *bp;
5629
5630 arg_value = probe_safe_evaluate_at_pc (frame, 1);
5631 if (!arg_value)
5632 return;
5633
5634 handler = value_as_address (arg_value);
5635
5636 if (debug_infrun)
5637 fprintf_unfiltered (gdb_stdlog,
5638 "infrun: exception resume at %s\n",
6bac7473 5639 paddress (get_objfile_arch (probe->objfile),
28106bc2
SDJ
5640 handler));
5641
5642 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5643 handler, bp_exception_resume);
5644 bp->thread = tp->num;
5645 inferior_thread ()->control.exception_resume_breakpoint = bp;
5646}
5647
186c406b
TT
5648/* This is called when an exception has been intercepted. Check to
5649 see whether the exception's destination is of interest, and if so,
5650 set an exception resume breakpoint there. */
5651
5652static void
5653check_exception_resume (struct execution_control_state *ecs,
28106bc2 5654 struct frame_info *frame)
186c406b 5655{
bfd189b1 5656 volatile struct gdb_exception e;
729662a5 5657 struct bound_probe probe;
28106bc2
SDJ
5658 struct symbol *func;
5659
5660 /* First see if this exception unwinding breakpoint was set via a
5661 SystemTap probe point. If so, the probe has two arguments: the
5662 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5663 set a breakpoint there. */
6bac7473 5664 probe = find_probe_by_pc (get_frame_pc (frame));
729662a5 5665 if (probe.probe)
28106bc2 5666 {
729662a5 5667 insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
28106bc2
SDJ
5668 return;
5669 }
5670
5671 func = get_frame_function (frame);
5672 if (!func)
5673 return;
186c406b
TT
5674
5675 TRY_CATCH (e, RETURN_MASK_ERROR)
5676 {
5677 struct block *b;
8157b174 5678 struct block_iterator iter;
186c406b
TT
5679 struct symbol *sym;
5680 int argno = 0;
5681
5682 /* The exception breakpoint is a thread-specific breakpoint on
5683 the unwinder's debug hook, declared as:
5684
5685 void _Unwind_DebugHook (void *cfa, void *handler);
5686
5687 The CFA argument indicates the frame to which control is
5688 about to be transferred. HANDLER is the destination PC.
5689
5690 We ignore the CFA and set a temporary breakpoint at HANDLER.
5691 This is not extremely efficient but it avoids issues in gdb
5692 with computing the DWARF CFA, and it also works even in weird
5693 cases such as throwing an exception from inside a signal
5694 handler. */
5695
5696 b = SYMBOL_BLOCK_VALUE (func);
5697 ALL_BLOCK_SYMBOLS (b, iter, sym)
5698 {
5699 if (!SYMBOL_IS_ARGUMENT (sym))
5700 continue;
5701
5702 if (argno == 0)
5703 ++argno;
5704 else
5705 {
5706 insert_exception_resume_breakpoint (ecs->event_thread,
5707 b, frame, sym);
5708 break;
5709 }
5710 }
5711 }
5712}
5713
104c1213
JM
5714static void
5715stop_stepping (struct execution_control_state *ecs)
5716{
527159b7 5717 if (debug_infrun)
8a9de0e4 5718 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
527159b7 5719
31e77af2
PA
5720 clear_step_over_info ();
5721
cd0fc7c3
SS
5722 /* Let callers know we don't want to wait for the inferior anymore. */
5723 ecs->wait_some_more = 0;
5724}
5725
a9ba6bae
PA
5726/* Called when we should continue running the inferior, because the
5727 current event doesn't cause a user visible stop. This does the
5728 resuming part; waiting for the next event is done elsewhere. */
d4f3574e
SS
5729
5730static void
5731keep_going (struct execution_control_state *ecs)
5732{
c4dbc9af
PA
5733 /* Make sure normal_stop is called if we get a QUIT handled before
5734 reaching resume. */
5735 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5736
d4f3574e 5737 /* Save the pc before execution, to compare with pc after stop. */
fb14de7b
UW
5738 ecs->event_thread->prev_pc
5739 = regcache_read_pc (get_thread_regcache (ecs->ptid));
d4f3574e 5740
16c381f0 5741 if (ecs->event_thread->control.trap_expected
a493e3e2 5742 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
d4f3574e 5743 {
a9ba6bae
PA
5744 /* We haven't yet gotten our trap, and either: intercepted a
5745 non-signal event (e.g., a fork); or took a signal which we
5746 are supposed to pass through to the inferior. Simply
5747 continue. */
c4dbc9af 5748 discard_cleanups (old_cleanups);
2020b7ab 5749 resume (currently_stepping (ecs->event_thread),
16c381f0 5750 ecs->event_thread->suspend.stop_signal);
d4f3574e
SS
5751 }
5752 else
5753 {
31e77af2
PA
5754 volatile struct gdb_exception e;
5755 struct regcache *regcache = get_current_regcache ();
5756
d4f3574e 5757 /* Either the trap was not expected, but we are continuing
a9ba6bae
PA
5758 anyway (if we got a signal, the user asked it be passed to
5759 the child)
5760 -- or --
5761 We got our expected trap, but decided we should resume from
5762 it.
d4f3574e 5763
a9ba6bae 5764 We're going to run this baby now!
d4f3574e 5765
c36b740a
VP
5766 Note that insert_breakpoints won't try to re-insert
5767 already inserted breakpoints. Therefore, we don't
5768 care if breakpoints were already inserted, or not. */
a9ba6bae 5769
31e77af2
PA
5770 /* If we need to step over a breakpoint, and we're not using
5771 displaced stepping to do so, insert all breakpoints
5772 (watchpoints, etc.) but the one we're stepping over, step one
5773 instruction, and then re-insert the breakpoint when that step
5774 is finished. */
2adfaa28 5775 if ((ecs->hit_singlestep_breakpoint
99619bea 5776 || thread_still_needs_step_over (ecs->event_thread))
31e77af2 5777 && !use_displaced_stepping (get_regcache_arch (regcache)))
45e8c884 5778 {
31e77af2
PA
5779 set_step_over_info (get_regcache_aspace (regcache),
5780 regcache_read_pc (regcache));
45e8c884
VP
5781 }
5782 else
31e77af2 5783 clear_step_over_info ();
abbb1732 5784
31e77af2
PA
5785 /* Stop stepping if inserting breakpoints fails. */
5786 TRY_CATCH (e, RETURN_MASK_ERROR)
5787 {
5788 insert_breakpoints ();
5789 }
5790 if (e.reason < 0)
5791 {
5792 exception_print (gdb_stderr, e);
5793 stop_stepping (ecs);
5794 return;
d4f3574e
SS
5795 }
5796
16c381f0 5797 ecs->event_thread->control.trap_expected
2adfaa28
PA
5798 = (ecs->event_thread->stepping_over_breakpoint
5799 || ecs->hit_singlestep_breakpoint);
d4f3574e 5800
a9ba6bae
PA
5801 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
5802 explicitly specifies that such a signal should be delivered
5803 to the target program). Typically, that would occur when a
5804 user is debugging a target monitor on a simulator: the target
5805 monitor sets a breakpoint; the simulator encounters this
5806 breakpoint and halts the simulation handing control to GDB;
5807 GDB, noting that the stop address doesn't map to any known
5808 breakpoint, returns control back to the simulator; the
5809 simulator then delivers the hardware equivalent of a
5810 GDB_SIGNAL_TRAP to the program being debugged. */
a493e3e2 5811 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
16c381f0 5812 && !signal_program[ecs->event_thread->suspend.stop_signal])
a493e3e2 5813 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
d4f3574e 5814
c4dbc9af 5815 discard_cleanups (old_cleanups);
2020b7ab 5816 resume (currently_stepping (ecs->event_thread),
16c381f0 5817 ecs->event_thread->suspend.stop_signal);
d4f3574e
SS
5818 }
5819
488f131b 5820 prepare_to_wait (ecs);
d4f3574e
SS
5821}
5822
104c1213
JM
5823/* This function normally comes after a resume, before
5824 handle_inferior_event exits. It takes care of any last bits of
5825 housekeeping, and sets the all-important wait_some_more flag. */
cd0fc7c3 5826
104c1213
JM
5827static void
5828prepare_to_wait (struct execution_control_state *ecs)
cd0fc7c3 5829{
527159b7 5830 if (debug_infrun)
8a9de0e4 5831 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
104c1213 5832
104c1213
JM
5833 /* This is the old end of the while loop. Let everybody know we
5834 want to wait for the inferior some more and get called again
5835 soon. */
5836 ecs->wait_some_more = 1;
c906108c 5837}
11cf8741 5838
33d62d64
JK
5839/* Several print_*_reason functions to print why the inferior has stopped.
5840 We always print something when the inferior exits, or receives a signal.
5841 The rest of the cases are dealt with later on in normal_stop and
5842 print_it_typical. Ideally there should be a call to one of these
5843 print_*_reason functions functions from handle_inferior_event each time
5844 stop_stepping is called. */
5845
5846/* Print why the inferior has stopped.
5847 We are done with a step/next/si/ni command, print why the inferior has
5848 stopped. For now print nothing. Print a message only if not in the middle
5849 of doing a "step n" operation for n > 1. */
5850
5851static void
5852print_end_stepping_range_reason (void)
5853{
16c381f0
JK
5854 if ((!inferior_thread ()->step_multi
5855 || !inferior_thread ()->control.stop_step)
79a45e25
PA
5856 && ui_out_is_mi_like_p (current_uiout))
5857 ui_out_field_string (current_uiout, "reason",
33d62d64
JK
5858 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5859}
5860
5861/* The inferior was terminated by a signal, print why it stopped. */
5862
11cf8741 5863static void
2ea28649 5864print_signal_exited_reason (enum gdb_signal siggnal)
11cf8741 5865{
79a45e25
PA
5866 struct ui_out *uiout = current_uiout;
5867
33d62d64
JK
5868 annotate_signalled ();
5869 if (ui_out_is_mi_like_p (uiout))
5870 ui_out_field_string
5871 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
5872 ui_out_text (uiout, "\nProgram terminated with signal ");
5873 annotate_signal_name ();
5874 ui_out_field_string (uiout, "signal-name",
2ea28649 5875 gdb_signal_to_name (siggnal));
33d62d64
JK
5876 annotate_signal_name_end ();
5877 ui_out_text (uiout, ", ");
5878 annotate_signal_string ();
5879 ui_out_field_string (uiout, "signal-meaning",
2ea28649 5880 gdb_signal_to_string (siggnal));
33d62d64
JK
5881 annotate_signal_string_end ();
5882 ui_out_text (uiout, ".\n");
5883 ui_out_text (uiout, "The program no longer exists.\n");
5884}
5885
5886/* The inferior program is finished, print why it stopped. */
5887
5888static void
5889print_exited_reason (int exitstatus)
5890{
fda326dd
TT
5891 struct inferior *inf = current_inferior ();
5892 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
79a45e25 5893 struct ui_out *uiout = current_uiout;
fda326dd 5894
33d62d64
JK
5895 annotate_exited (exitstatus);
5896 if (exitstatus)
5897 {
5898 if (ui_out_is_mi_like_p (uiout))
5899 ui_out_field_string (uiout, "reason",
5900 async_reason_lookup (EXEC_ASYNC_EXITED));
fda326dd
TT
5901 ui_out_text (uiout, "[Inferior ");
5902 ui_out_text (uiout, plongest (inf->num));
5903 ui_out_text (uiout, " (");
5904 ui_out_text (uiout, pidstr);
5905 ui_out_text (uiout, ") exited with code ");
33d62d64 5906 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
fda326dd 5907 ui_out_text (uiout, "]\n");
33d62d64
JK
5908 }
5909 else
11cf8741 5910 {
9dc5e2a9 5911 if (ui_out_is_mi_like_p (uiout))
034dad6f 5912 ui_out_field_string
33d62d64 5913 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
fda326dd
TT
5914 ui_out_text (uiout, "[Inferior ");
5915 ui_out_text (uiout, plongest (inf->num));
5916 ui_out_text (uiout, " (");
5917 ui_out_text (uiout, pidstr);
5918 ui_out_text (uiout, ") exited normally]\n");
33d62d64
JK
5919 }
5920 /* Support the --return-child-result option. */
5921 return_child_result_value = exitstatus;
5922}
5923
5924/* Signal received, print why the inferior has stopped. The signal table
1777feb0 5925 tells us to print about it. */
33d62d64
JK
5926
5927static void
2ea28649 5928print_signal_received_reason (enum gdb_signal siggnal)
33d62d64 5929{
79a45e25
PA
5930 struct ui_out *uiout = current_uiout;
5931
33d62d64
JK
5932 annotate_signal ();
5933
a493e3e2 5934 if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
33d62d64
JK
5935 {
5936 struct thread_info *t = inferior_thread ();
5937
5938 ui_out_text (uiout, "\n[");
5939 ui_out_field_string (uiout, "thread-name",
5940 target_pid_to_str (t->ptid));
5941 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5942 ui_out_text (uiout, " stopped");
5943 }
5944 else
5945 {
5946 ui_out_text (uiout, "\nProgram received signal ");
8b93c638 5947 annotate_signal_name ();
33d62d64
JK
5948 if (ui_out_is_mi_like_p (uiout))
5949 ui_out_field_string
5950 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
488f131b 5951 ui_out_field_string (uiout, "signal-name",
2ea28649 5952 gdb_signal_to_name (siggnal));
8b93c638
JM
5953 annotate_signal_name_end ();
5954 ui_out_text (uiout, ", ");
5955 annotate_signal_string ();
488f131b 5956 ui_out_field_string (uiout, "signal-meaning",
2ea28649 5957 gdb_signal_to_string (siggnal));
8b93c638 5958 annotate_signal_string_end ();
33d62d64
JK
5959 }
5960 ui_out_text (uiout, ".\n");
5961}
252fbfc8 5962
33d62d64
JK
5963/* Reverse execution: target ran out of history info, print why the inferior
5964 has stopped. */
252fbfc8 5965
33d62d64
JK
5966static void
5967print_no_history_reason (void)
5968{
79a45e25 5969 ui_out_text (current_uiout, "\nNo more reverse-execution history.\n");
11cf8741 5970}
43ff13b4 5971
0c7e1a46
PA
5972/* Print current location without a level number, if we have changed
5973 functions or hit a breakpoint. Print source line if we have one.
5974 bpstat_print contains the logic deciding in detail what to print,
5975 based on the event(s) that just occurred. */
5976
5977void
5978print_stop_event (struct target_waitstatus *ws)
5979{
5980 int bpstat_ret;
5981 int source_flag;
5982 int do_frame_printing = 1;
5983 struct thread_info *tp = inferior_thread ();
5984
5985 bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind);
5986 switch (bpstat_ret)
5987 {
5988 case PRINT_UNKNOWN:
5989 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
5990 should) carry around the function and does (or should) use
5991 that when doing a frame comparison. */
5992 if (tp->control.stop_step
5993 && frame_id_eq (tp->control.step_frame_id,
5994 get_frame_id (get_current_frame ()))
5995 && step_start_function == find_pc_function (stop_pc))
5996 {
5997 /* Finished step, just print source line. */
5998 source_flag = SRC_LINE;
5999 }
6000 else
6001 {
6002 /* Print location and source line. */
6003 source_flag = SRC_AND_LOC;
6004 }
6005 break;
6006 case PRINT_SRC_AND_LOC:
6007 /* Print location and source line. */
6008 source_flag = SRC_AND_LOC;
6009 break;
6010 case PRINT_SRC_ONLY:
6011 source_flag = SRC_LINE;
6012 break;
6013 case PRINT_NOTHING:
6014 /* Something bogus. */
6015 source_flag = SRC_LINE;
6016 do_frame_printing = 0;
6017 break;
6018 default:
6019 internal_error (__FILE__, __LINE__, _("Unknown value."));
6020 }
6021
6022 /* The behavior of this routine with respect to the source
6023 flag is:
6024 SRC_LINE: Print only source line
6025 LOCATION: Print only location
6026 SRC_AND_LOC: Print location and source line. */
6027 if (do_frame_printing)
6028 print_stack_frame (get_selected_frame (NULL), 0, source_flag, 1);
6029
6030 /* Display the auto-display expressions. */
6031 do_displays ();
6032}
6033
c906108c
SS
6034/* Here to return control to GDB when the inferior stops for real.
6035 Print appropriate messages, remove breakpoints, give terminal our modes.
6036
6037 STOP_PRINT_FRAME nonzero means print the executing frame
6038 (pc, function, args, file, line number and line text).
6039 BREAKPOINTS_FAILED nonzero means stop was due to error
6040 attempting to insert breakpoints. */
6041
6042void
96baa820 6043normal_stop (void)
c906108c 6044{
73b65bb0
DJ
6045 struct target_waitstatus last;
6046 ptid_t last_ptid;
29f49a6a 6047 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
73b65bb0
DJ
6048
6049 get_last_target_status (&last_ptid, &last);
6050
29f49a6a
PA
6051 /* If an exception is thrown from this point on, make sure to
6052 propagate GDB's knowledge of the executing state to the
6053 frontend/user running state. A QUIT is an easy exception to see
6054 here, so do this before any filtered output. */
c35b1492
PA
6055 if (!non_stop)
6056 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
6057 else if (last.kind != TARGET_WAITKIND_SIGNALLED
0e5bf2a8
PA
6058 && last.kind != TARGET_WAITKIND_EXITED
6059 && last.kind != TARGET_WAITKIND_NO_RESUMED)
c35b1492 6060 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
29f49a6a 6061
c906108c
SS
6062 /* As with the notification of thread events, we want to delay
6063 notifying the user that we've switched thread context until
6064 the inferior actually stops.
6065
73b65bb0
DJ
6066 There's no point in saying anything if the inferior has exited.
6067 Note that SIGNALLED here means "exited with a signal", not
b65dc60b
PA
6068 "received a signal".
6069
6070 Also skip saying anything in non-stop mode. In that mode, as we
6071 don't want GDB to switch threads behind the user's back, to avoid
6072 races where the user is typing a command to apply to thread x,
6073 but GDB switches to thread y before the user finishes entering
6074 the command, fetch_inferior_event installs a cleanup to restore
6075 the current thread back to the thread the user had selected right
6076 after this event is handled, so we're not really switching, only
6077 informing of a stop. */
4f8d22e3
PA
6078 if (!non_stop
6079 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
73b65bb0
DJ
6080 && target_has_execution
6081 && last.kind != TARGET_WAITKIND_SIGNALLED
0e5bf2a8
PA
6082 && last.kind != TARGET_WAITKIND_EXITED
6083 && last.kind != TARGET_WAITKIND_NO_RESUMED)
c906108c
SS
6084 {
6085 target_terminal_ours_for_output ();
a3f17187 6086 printf_filtered (_("[Switching to %s]\n"),
c95310c6 6087 target_pid_to_str (inferior_ptid));
b8fa951a 6088 annotate_thread_changed ();
39f77062 6089 previous_inferior_ptid = inferior_ptid;
c906108c 6090 }
c906108c 6091
0e5bf2a8
PA
6092 if (last.kind == TARGET_WAITKIND_NO_RESUMED)
6093 {
6094 gdb_assert (sync_execution || !target_can_async_p ());
6095
6096 target_terminal_ours_for_output ();
6097 printf_filtered (_("No unwaited-for children left.\n"));
6098 }
6099
74960c60 6100 if (!breakpoints_always_inserted_mode () && target_has_execution)
c906108c
SS
6101 {
6102 if (remove_breakpoints ())
6103 {
6104 target_terminal_ours_for_output ();
3e43a32a
MS
6105 printf_filtered (_("Cannot remove breakpoints because "
6106 "program is no longer writable.\nFurther "
6107 "execution is probably impossible.\n"));
c906108c
SS
6108 }
6109 }
c906108c 6110
c906108c
SS
6111 /* If an auto-display called a function and that got a signal,
6112 delete that auto-display to avoid an infinite recursion. */
6113
6114 if (stopped_by_random_signal)
6115 disable_current_display ();
6116
6117 /* Don't print a message if in the middle of doing a "step n"
6118 operation for n > 1 */
af679fd0
PA
6119 if (target_has_execution
6120 && last.kind != TARGET_WAITKIND_SIGNALLED
6121 && last.kind != TARGET_WAITKIND_EXITED
6122 && inferior_thread ()->step_multi
16c381f0 6123 && inferior_thread ()->control.stop_step)
c906108c
SS
6124 goto done;
6125
6126 target_terminal_ours ();
0f641c01 6127 async_enable_stdin ();
c906108c 6128
7abfe014
DJ
6129 /* Set the current source location. This will also happen if we
6130 display the frame below, but the current SAL will be incorrect
6131 during a user hook-stop function. */
d729566a 6132 if (has_stack_frames () && !stop_stack_dummy)
7abfe014
DJ
6133 set_current_sal_from_frame (get_current_frame (), 1);
6134
dd7e2d2b
PA
6135 /* Let the user/frontend see the threads as stopped. */
6136 do_cleanups (old_chain);
6137
6138 /* Look up the hook_stop and run it (CLI internally handles problem
6139 of stop_command's pre-hook not existing). */
6140 if (stop_command)
6141 catch_errors (hook_stop_stub, stop_command,
6142 "Error while running hook_stop:\n", RETURN_MASK_ALL);
6143
d729566a 6144 if (!has_stack_frames ())
d51fd4c8 6145 goto done;
c906108c 6146
32400beb
PA
6147 if (last.kind == TARGET_WAITKIND_SIGNALLED
6148 || last.kind == TARGET_WAITKIND_EXITED)
6149 goto done;
6150
c906108c
SS
6151 /* Select innermost stack frame - i.e., current frame is frame 0,
6152 and current location is based on that.
6153 Don't do this on return from a stack dummy routine,
1777feb0 6154 or if the program has exited. */
c906108c
SS
6155
6156 if (!stop_stack_dummy)
6157 {
0f7d239c 6158 select_frame (get_current_frame ());
c906108c 6159
d01a8610
AS
6160 /* If --batch-silent is enabled then there's no need to print the current
6161 source location, and to try risks causing an error message about
6162 missing source files. */
6163 if (stop_print_frame && !batch_silent)
0c7e1a46 6164 print_stop_event (&last);
c906108c
SS
6165 }
6166
6167 /* Save the function value return registers, if we care.
6168 We might be about to restore their previous contents. */
9da8c2a0
PA
6169 if (inferior_thread ()->control.proceed_to_finish
6170 && execution_direction != EXEC_REVERSE)
d5c31457
UW
6171 {
6172 /* This should not be necessary. */
6173 if (stop_registers)
6174 regcache_xfree (stop_registers);
6175
6176 /* NB: The copy goes through to the target picking up the value of
6177 all the registers. */
6178 stop_registers = regcache_dup (get_current_regcache ());
6179 }
c906108c 6180
aa7d318d 6181 if (stop_stack_dummy == STOP_STACK_DUMMY)
c906108c 6182 {
b89667eb
DE
6183 /* Pop the empty frame that contains the stack dummy.
6184 This also restores inferior state prior to the call
16c381f0 6185 (struct infcall_suspend_state). */
b89667eb 6186 struct frame_info *frame = get_current_frame ();
abbb1732 6187
b89667eb
DE
6188 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
6189 frame_pop (frame);
3e43a32a
MS
6190 /* frame_pop() calls reinit_frame_cache as the last thing it
6191 does which means there's currently no selected frame. We
6192 don't need to re-establish a selected frame if the dummy call
6193 returns normally, that will be done by
6194 restore_infcall_control_state. However, we do have to handle
6195 the case where the dummy call is returning after being
6196 stopped (e.g. the dummy call previously hit a breakpoint).
6197 We can't know which case we have so just always re-establish
6198 a selected frame here. */
0f7d239c 6199 select_frame (get_current_frame ());
c906108c
SS
6200 }
6201
c906108c
SS
6202done:
6203 annotate_stopped ();
41d2bdb4
PA
6204
6205 /* Suppress the stop observer if we're in the middle of:
6206
6207 - a step n (n > 1), as there still more steps to be done.
6208
6209 - a "finish" command, as the observer will be called in
6210 finish_command_continuation, so it can include the inferior
6211 function's return value.
6212
6213 - calling an inferior function, as we pretend we inferior didn't
6214 run at all. The return value of the call is handled by the
6215 expression evaluator, through call_function_by_hand. */
6216
6217 if (!target_has_execution
6218 || last.kind == TARGET_WAITKIND_SIGNALLED
6219 || last.kind == TARGET_WAITKIND_EXITED
0e5bf2a8 6220 || last.kind == TARGET_WAITKIND_NO_RESUMED
2ca0b532
PA
6221 || (!(inferior_thread ()->step_multi
6222 && inferior_thread ()->control.stop_step)
16c381f0
JK
6223 && !(inferior_thread ()->control.stop_bpstat
6224 && inferior_thread ()->control.proceed_to_finish)
6225 && !inferior_thread ()->control.in_infcall))
347bddb7
PA
6226 {
6227 if (!ptid_equal (inferior_ptid, null_ptid))
16c381f0 6228 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
1d33d6ba 6229 stop_print_frame);
347bddb7 6230 else
1d33d6ba 6231 observer_notify_normal_stop (NULL, stop_print_frame);
347bddb7 6232 }
347bddb7 6233
48844aa6
PA
6234 if (target_has_execution)
6235 {
6236 if (last.kind != TARGET_WAITKIND_SIGNALLED
6237 && last.kind != TARGET_WAITKIND_EXITED)
6238 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6239 Delete any breakpoint that is to be deleted at the next stop. */
16c381f0 6240 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
94cc34af 6241 }
6c95b8df
PA
6242
6243 /* Try to get rid of automatically added inferiors that are no
6244 longer needed. Keeping those around slows down things linearly.
6245 Note that this never removes the current inferior. */
6246 prune_inferiors ();
c906108c
SS
6247}
6248
6249static int
96baa820 6250hook_stop_stub (void *cmd)
c906108c 6251{
5913bcb0 6252 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
c906108c
SS
6253 return (0);
6254}
6255\f
c5aa993b 6256int
96baa820 6257signal_stop_state (int signo)
c906108c 6258{
d6b48e9c 6259 return signal_stop[signo];
c906108c
SS
6260}
6261
c5aa993b 6262int
96baa820 6263signal_print_state (int signo)
c906108c
SS
6264{
6265 return signal_print[signo];
6266}
6267
c5aa993b 6268int
96baa820 6269signal_pass_state (int signo)
c906108c
SS
6270{
6271 return signal_program[signo];
6272}
6273
2455069d
UW
6274static void
6275signal_cache_update (int signo)
6276{
6277 if (signo == -1)
6278 {
a493e3e2 6279 for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++)
2455069d
UW
6280 signal_cache_update (signo);
6281
6282 return;
6283 }
6284
6285 signal_pass[signo] = (signal_stop[signo] == 0
6286 && signal_print[signo] == 0
ab04a2af
TT
6287 && signal_program[signo] == 1
6288 && signal_catch[signo] == 0);
2455069d
UW
6289}
6290
488f131b 6291int
7bda5e4a 6292signal_stop_update (int signo, int state)
d4f3574e
SS
6293{
6294 int ret = signal_stop[signo];
abbb1732 6295
d4f3574e 6296 signal_stop[signo] = state;
2455069d 6297 signal_cache_update (signo);
d4f3574e
SS
6298 return ret;
6299}
6300
488f131b 6301int
7bda5e4a 6302signal_print_update (int signo, int state)
d4f3574e
SS
6303{
6304 int ret = signal_print[signo];
abbb1732 6305
d4f3574e 6306 signal_print[signo] = state;
2455069d 6307 signal_cache_update (signo);
d4f3574e
SS
6308 return ret;
6309}
6310
488f131b 6311int
7bda5e4a 6312signal_pass_update (int signo, int state)
d4f3574e
SS
6313{
6314 int ret = signal_program[signo];
abbb1732 6315
d4f3574e 6316 signal_program[signo] = state;
2455069d 6317 signal_cache_update (signo);
d4f3574e
SS
6318 return ret;
6319}
6320
ab04a2af
TT
6321/* Update the global 'signal_catch' from INFO and notify the
6322 target. */
6323
6324void
6325signal_catch_update (const unsigned int *info)
6326{
6327 int i;
6328
6329 for (i = 0; i < GDB_SIGNAL_LAST; ++i)
6330 signal_catch[i] = info[i] > 0;
6331 signal_cache_update (-1);
6332 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6333}
6334
c906108c 6335static void
96baa820 6336sig_print_header (void)
c906108c 6337{
3e43a32a
MS
6338 printf_filtered (_("Signal Stop\tPrint\tPass "
6339 "to program\tDescription\n"));
c906108c
SS
6340}
6341
6342static void
2ea28649 6343sig_print_info (enum gdb_signal oursig)
c906108c 6344{
2ea28649 6345 const char *name = gdb_signal_to_name (oursig);
c906108c 6346 int name_padding = 13 - strlen (name);
96baa820 6347
c906108c
SS
6348 if (name_padding <= 0)
6349 name_padding = 0;
6350
6351 printf_filtered ("%s", name);
488f131b 6352 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
c906108c
SS
6353 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
6354 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
6355 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
2ea28649 6356 printf_filtered ("%s\n", gdb_signal_to_string (oursig));
c906108c
SS
6357}
6358
6359/* Specify how various signals in the inferior should be handled. */
6360
6361static void
96baa820 6362handle_command (char *args, int from_tty)
c906108c
SS
6363{
6364 char **argv;
6365 int digits, wordlen;
6366 int sigfirst, signum, siglast;
2ea28649 6367 enum gdb_signal oursig;
c906108c
SS
6368 int allsigs;
6369 int nsigs;
6370 unsigned char *sigs;
6371 struct cleanup *old_chain;
6372
6373 if (args == NULL)
6374 {
e2e0b3e5 6375 error_no_arg (_("signal to handle"));
c906108c
SS
6376 }
6377
1777feb0 6378 /* Allocate and zero an array of flags for which signals to handle. */
c906108c 6379
a493e3e2 6380 nsigs = (int) GDB_SIGNAL_LAST;
c906108c
SS
6381 sigs = (unsigned char *) alloca (nsigs);
6382 memset (sigs, 0, nsigs);
6383
1777feb0 6384 /* Break the command line up into args. */
c906108c 6385
d1a41061 6386 argv = gdb_buildargv (args);
7a292a7a 6387 old_chain = make_cleanup_freeargv (argv);
c906108c
SS
6388
6389 /* Walk through the args, looking for signal oursigs, signal names, and
6390 actions. Signal numbers and signal names may be interspersed with
6391 actions, with the actions being performed for all signals cumulatively
1777feb0 6392 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
c906108c
SS
6393
6394 while (*argv != NULL)
6395 {
6396 wordlen = strlen (*argv);
6397 for (digits = 0; isdigit ((*argv)[digits]); digits++)
6398 {;
6399 }
6400 allsigs = 0;
6401 sigfirst = siglast = -1;
6402
6403 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
6404 {
6405 /* Apply action to all signals except those used by the
1777feb0 6406 debugger. Silently skip those. */
c906108c
SS
6407 allsigs = 1;
6408 sigfirst = 0;
6409 siglast = nsigs - 1;
6410 }
6411 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
6412 {
6413 SET_SIGS (nsigs, sigs, signal_stop);
6414 SET_SIGS (nsigs, sigs, signal_print);
6415 }
6416 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
6417 {
6418 UNSET_SIGS (nsigs, sigs, signal_program);
6419 }
6420 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
6421 {
6422 SET_SIGS (nsigs, sigs, signal_print);
6423 }
6424 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
6425 {
6426 SET_SIGS (nsigs, sigs, signal_program);
6427 }
6428 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
6429 {
6430 UNSET_SIGS (nsigs, sigs, signal_stop);
6431 }
6432 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
6433 {
6434 SET_SIGS (nsigs, sigs, signal_program);
6435 }
6436 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
6437 {
6438 UNSET_SIGS (nsigs, sigs, signal_print);
6439 UNSET_SIGS (nsigs, sigs, signal_stop);
6440 }
6441 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
6442 {
6443 UNSET_SIGS (nsigs, sigs, signal_program);
6444 }
6445 else if (digits > 0)
6446 {
6447 /* It is numeric. The numeric signal refers to our own
6448 internal signal numbering from target.h, not to host/target
6449 signal number. This is a feature; users really should be
6450 using symbolic names anyway, and the common ones like
6451 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6452
6453 sigfirst = siglast = (int)
2ea28649 6454 gdb_signal_from_command (atoi (*argv));
c906108c
SS
6455 if ((*argv)[digits] == '-')
6456 {
6457 siglast = (int)
2ea28649 6458 gdb_signal_from_command (atoi ((*argv) + digits + 1));
c906108c
SS
6459 }
6460 if (sigfirst > siglast)
6461 {
1777feb0 6462 /* Bet he didn't figure we'd think of this case... */
c906108c
SS
6463 signum = sigfirst;
6464 sigfirst = siglast;
6465 siglast = signum;
6466 }
6467 }
6468 else
6469 {
2ea28649 6470 oursig = gdb_signal_from_name (*argv);
a493e3e2 6471 if (oursig != GDB_SIGNAL_UNKNOWN)
c906108c
SS
6472 {
6473 sigfirst = siglast = (int) oursig;
6474 }
6475 else
6476 {
6477 /* Not a number and not a recognized flag word => complain. */
8a3fe4f8 6478 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
c906108c
SS
6479 }
6480 }
6481
6482 /* If any signal numbers or symbol names were found, set flags for
1777feb0 6483 which signals to apply actions to. */
c906108c
SS
6484
6485 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6486 {
2ea28649 6487 switch ((enum gdb_signal) signum)
c906108c 6488 {
a493e3e2
PA
6489 case GDB_SIGNAL_TRAP:
6490 case GDB_SIGNAL_INT:
c906108c
SS
6491 if (!allsigs && !sigs[signum])
6492 {
9e2f0ad4 6493 if (query (_("%s is used by the debugger.\n\
3e43a32a 6494Are you sure you want to change it? "),
2ea28649 6495 gdb_signal_to_name ((enum gdb_signal) signum)))
c906108c
SS
6496 {
6497 sigs[signum] = 1;
6498 }
6499 else
6500 {
a3f17187 6501 printf_unfiltered (_("Not confirmed, unchanged.\n"));
c906108c
SS
6502 gdb_flush (gdb_stdout);
6503 }
6504 }
6505 break;
a493e3e2
PA
6506 case GDB_SIGNAL_0:
6507 case GDB_SIGNAL_DEFAULT:
6508 case GDB_SIGNAL_UNKNOWN:
c906108c
SS
6509 /* Make sure that "all" doesn't print these. */
6510 break;
6511 default:
6512 sigs[signum] = 1;
6513 break;
6514 }
6515 }
6516
6517 argv++;
6518 }
6519
3a031f65
PA
6520 for (signum = 0; signum < nsigs; signum++)
6521 if (sigs[signum])
6522 {
2455069d 6523 signal_cache_update (-1);
a493e3e2
PA
6524 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6525 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
c906108c 6526
3a031f65
PA
6527 if (from_tty)
6528 {
6529 /* Show the results. */
6530 sig_print_header ();
6531 for (; signum < nsigs; signum++)
6532 if (sigs[signum])
6533 sig_print_info (signum);
6534 }
6535
6536 break;
6537 }
c906108c
SS
6538
6539 do_cleanups (old_chain);
6540}
6541
de0bea00
MF
6542/* Complete the "handle" command. */
6543
6544static VEC (char_ptr) *
6545handle_completer (struct cmd_list_element *ignore,
6f937416 6546 const char *text, const char *word)
de0bea00
MF
6547{
6548 VEC (char_ptr) *vec_signals, *vec_keywords, *return_val;
6549 static const char * const keywords[] =
6550 {
6551 "all",
6552 "stop",
6553 "ignore",
6554 "print",
6555 "pass",
6556 "nostop",
6557 "noignore",
6558 "noprint",
6559 "nopass",
6560 NULL,
6561 };
6562
6563 vec_signals = signal_completer (ignore, text, word);
6564 vec_keywords = complete_on_enum (keywords, word, word);
6565
6566 return_val = VEC_merge (char_ptr, vec_signals, vec_keywords);
6567 VEC_free (char_ptr, vec_signals);
6568 VEC_free (char_ptr, vec_keywords);
6569 return return_val;
6570}
6571
c906108c 6572static void
96baa820 6573xdb_handle_command (char *args, int from_tty)
c906108c
SS
6574{
6575 char **argv;
6576 struct cleanup *old_chain;
6577
d1a41061
PP
6578 if (args == NULL)
6579 error_no_arg (_("xdb command"));
6580
1777feb0 6581 /* Break the command line up into args. */
c906108c 6582
d1a41061 6583 argv = gdb_buildargv (args);
7a292a7a 6584 old_chain = make_cleanup_freeargv (argv);
c906108c
SS
6585 if (argv[1] != (char *) NULL)
6586 {
6587 char *argBuf;
6588 int bufLen;
6589
6590 bufLen = strlen (argv[0]) + 20;
6591 argBuf = (char *) xmalloc (bufLen);
6592 if (argBuf)
6593 {
6594 int validFlag = 1;
2ea28649 6595 enum gdb_signal oursig;
c906108c 6596
2ea28649 6597 oursig = gdb_signal_from_name (argv[0]);
c906108c
SS
6598 memset (argBuf, 0, bufLen);
6599 if (strcmp (argv[1], "Q") == 0)
6600 sprintf (argBuf, "%s %s", argv[0], "noprint");
6601 else
6602 {
6603 if (strcmp (argv[1], "s") == 0)
6604 {
6605 if (!signal_stop[oursig])
6606 sprintf (argBuf, "%s %s", argv[0], "stop");
6607 else
6608 sprintf (argBuf, "%s %s", argv[0], "nostop");
6609 }
6610 else if (strcmp (argv[1], "i") == 0)
6611 {
6612 if (!signal_program[oursig])
6613 sprintf (argBuf, "%s %s", argv[0], "pass");
6614 else
6615 sprintf (argBuf, "%s %s", argv[0], "nopass");
6616 }
6617 else if (strcmp (argv[1], "r") == 0)
6618 {
6619 if (!signal_print[oursig])
6620 sprintf (argBuf, "%s %s", argv[0], "print");
6621 else
6622 sprintf (argBuf, "%s %s", argv[0], "noprint");
6623 }
6624 else
6625 validFlag = 0;
6626 }
6627 if (validFlag)
6628 handle_command (argBuf, from_tty);
6629 else
a3f17187 6630 printf_filtered (_("Invalid signal handling flag.\n"));
c906108c 6631 if (argBuf)
b8c9b27d 6632 xfree (argBuf);
c906108c
SS
6633 }
6634 }
6635 do_cleanups (old_chain);
6636}
6637
2ea28649
PA
6638enum gdb_signal
6639gdb_signal_from_command (int num)
ed01b82c
PA
6640{
6641 if (num >= 1 && num <= 15)
2ea28649 6642 return (enum gdb_signal) num;
ed01b82c
PA
6643 error (_("Only signals 1-15 are valid as numeric signals.\n\
6644Use \"info signals\" for a list of symbolic signals."));
6645}
6646
c906108c
SS
6647/* Print current contents of the tables set by the handle command.
6648 It is possible we should just be printing signals actually used
6649 by the current target (but for things to work right when switching
6650 targets, all signals should be in the signal tables). */
6651
6652static void
96baa820 6653signals_info (char *signum_exp, int from_tty)
c906108c 6654{
2ea28649 6655 enum gdb_signal oursig;
abbb1732 6656
c906108c
SS
6657 sig_print_header ();
6658
6659 if (signum_exp)
6660 {
6661 /* First see if this is a symbol name. */
2ea28649 6662 oursig = gdb_signal_from_name (signum_exp);
a493e3e2 6663 if (oursig == GDB_SIGNAL_UNKNOWN)
c906108c
SS
6664 {
6665 /* No, try numeric. */
6666 oursig =
2ea28649 6667 gdb_signal_from_command (parse_and_eval_long (signum_exp));
c906108c
SS
6668 }
6669 sig_print_info (oursig);
6670 return;
6671 }
6672
6673 printf_filtered ("\n");
6674 /* These ugly casts brought to you by the native VAX compiler. */
a493e3e2
PA
6675 for (oursig = GDB_SIGNAL_FIRST;
6676 (int) oursig < (int) GDB_SIGNAL_LAST;
2ea28649 6677 oursig = (enum gdb_signal) ((int) oursig + 1))
c906108c
SS
6678 {
6679 QUIT;
6680
a493e3e2
PA
6681 if (oursig != GDB_SIGNAL_UNKNOWN
6682 && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0)
c906108c
SS
6683 sig_print_info (oursig);
6684 }
6685
3e43a32a
MS
6686 printf_filtered (_("\nUse the \"handle\" command "
6687 "to change these tables.\n"));
c906108c 6688}
4aa995e1 6689
c709acd1
PA
6690/* Check if it makes sense to read $_siginfo from the current thread
6691 at this point. If not, throw an error. */
6692
6693static void
6694validate_siginfo_access (void)
6695{
6696 /* No current inferior, no siginfo. */
6697 if (ptid_equal (inferior_ptid, null_ptid))
6698 error (_("No thread selected."));
6699
6700 /* Don't try to read from a dead thread. */
6701 if (is_exited (inferior_ptid))
6702 error (_("The current thread has terminated"));
6703
6704 /* ... or from a spinning thread. */
6705 if (is_running (inferior_ptid))
6706 error (_("Selected thread is running."));
6707}
6708
4aa995e1
PA
6709/* The $_siginfo convenience variable is a bit special. We don't know
6710 for sure the type of the value until we actually have a chance to
7a9dd1b2 6711 fetch the data. The type can change depending on gdbarch, so it is
4aa995e1
PA
6712 also dependent on which thread you have selected.
6713
6714 1. making $_siginfo be an internalvar that creates a new value on
6715 access.
6716
6717 2. making the value of $_siginfo be an lval_computed value. */
6718
6719/* This function implements the lval_computed support for reading a
6720 $_siginfo value. */
6721
6722static void
6723siginfo_value_read (struct value *v)
6724{
6725 LONGEST transferred;
6726
c709acd1
PA
6727 validate_siginfo_access ();
6728
4aa995e1
PA
6729 transferred =
6730 target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO,
6731 NULL,
6732 value_contents_all_raw (v),
6733 value_offset (v),
6734 TYPE_LENGTH (value_type (v)));
6735
6736 if (transferred != TYPE_LENGTH (value_type (v)))
6737 error (_("Unable to read siginfo"));
6738}
6739
6740/* This function implements the lval_computed support for writing a
6741 $_siginfo value. */
6742
6743static void
6744siginfo_value_write (struct value *v, struct value *fromval)
6745{
6746 LONGEST transferred;
6747
c709acd1
PA
6748 validate_siginfo_access ();
6749
4aa995e1
PA
6750 transferred = target_write (&current_target,
6751 TARGET_OBJECT_SIGNAL_INFO,
6752 NULL,
6753 value_contents_all_raw (fromval),
6754 value_offset (v),
6755 TYPE_LENGTH (value_type (fromval)));
6756
6757 if (transferred != TYPE_LENGTH (value_type (fromval)))
6758 error (_("Unable to write siginfo"));
6759}
6760
c8f2448a 6761static const struct lval_funcs siginfo_value_funcs =
4aa995e1
PA
6762 {
6763 siginfo_value_read,
6764 siginfo_value_write
6765 };
6766
6767/* Return a new value with the correct type for the siginfo object of
78267919
UW
6768 the current thread using architecture GDBARCH. Return a void value
6769 if there's no object available. */
4aa995e1 6770
2c0b251b 6771static struct value *
22d2b532
SDJ
6772siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
6773 void *ignore)
4aa995e1 6774{
4aa995e1 6775 if (target_has_stack
78267919
UW
6776 && !ptid_equal (inferior_ptid, null_ptid)
6777 && gdbarch_get_siginfo_type_p (gdbarch))
4aa995e1 6778 {
78267919 6779 struct type *type = gdbarch_get_siginfo_type (gdbarch);
abbb1732 6780
78267919 6781 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
4aa995e1
PA
6782 }
6783
78267919 6784 return allocate_value (builtin_type (gdbarch)->builtin_void);
4aa995e1
PA
6785}
6786
c906108c 6787\f
16c381f0
JK
6788/* infcall_suspend_state contains state about the program itself like its
6789 registers and any signal it received when it last stopped.
6790 This state must be restored regardless of how the inferior function call
6791 ends (either successfully, or after it hits a breakpoint or signal)
6792 if the program is to properly continue where it left off. */
6793
6794struct infcall_suspend_state
7a292a7a 6795{
16c381f0 6796 struct thread_suspend_state thread_suspend;
dd80ea3c 6797#if 0 /* Currently unused and empty structures are not valid C. */
16c381f0 6798 struct inferior_suspend_state inferior_suspend;
dd80ea3c 6799#endif
16c381f0
JK
6800
6801 /* Other fields: */
7a292a7a 6802 CORE_ADDR stop_pc;
b89667eb 6803 struct regcache *registers;
1736ad11 6804
35515841 6805 /* Format of SIGINFO_DATA or NULL if it is not present. */
1736ad11
JK
6806 struct gdbarch *siginfo_gdbarch;
6807
6808 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6809 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6810 content would be invalid. */
6811 gdb_byte *siginfo_data;
b89667eb
DE
6812};
6813
16c381f0
JK
6814struct infcall_suspend_state *
6815save_infcall_suspend_state (void)
b89667eb 6816{
16c381f0 6817 struct infcall_suspend_state *inf_state;
b89667eb 6818 struct thread_info *tp = inferior_thread ();
974a734b 6819#if 0
16c381f0 6820 struct inferior *inf = current_inferior ();
974a734b 6821#endif
1736ad11
JK
6822 struct regcache *regcache = get_current_regcache ();
6823 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6824 gdb_byte *siginfo_data = NULL;
6825
6826 if (gdbarch_get_siginfo_type_p (gdbarch))
6827 {
6828 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6829 size_t len = TYPE_LENGTH (type);
6830 struct cleanup *back_to;
6831
6832 siginfo_data = xmalloc (len);
6833 back_to = make_cleanup (xfree, siginfo_data);
6834
6835 if (target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6836 siginfo_data, 0, len) == len)
6837 discard_cleanups (back_to);
6838 else
6839 {
6840 /* Errors ignored. */
6841 do_cleanups (back_to);
6842 siginfo_data = NULL;
6843 }
6844 }
6845
41bf6aca 6846 inf_state = XCNEW (struct infcall_suspend_state);
1736ad11
JK
6847
6848 if (siginfo_data)
6849 {
6850 inf_state->siginfo_gdbarch = gdbarch;
6851 inf_state->siginfo_data = siginfo_data;
6852 }
b89667eb 6853
16c381f0 6854 inf_state->thread_suspend = tp->suspend;
dd80ea3c 6855#if 0 /* Currently unused and empty structures are not valid C. */
16c381f0 6856 inf_state->inferior_suspend = inf->suspend;
dd80ea3c 6857#endif
16c381f0 6858
35515841 6859 /* run_inferior_call will not use the signal due to its `proceed' call with
a493e3e2
PA
6860 GDB_SIGNAL_0 anyway. */
6861 tp->suspend.stop_signal = GDB_SIGNAL_0;
35515841 6862
b89667eb
DE
6863 inf_state->stop_pc = stop_pc;
6864
1736ad11 6865 inf_state->registers = regcache_dup (regcache);
b89667eb
DE
6866
6867 return inf_state;
6868}
6869
6870/* Restore inferior session state to INF_STATE. */
6871
6872void
16c381f0 6873restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
b89667eb
DE
6874{
6875 struct thread_info *tp = inferior_thread ();
974a734b 6876#if 0
16c381f0 6877 struct inferior *inf = current_inferior ();
974a734b 6878#endif
1736ad11
JK
6879 struct regcache *regcache = get_current_regcache ();
6880 struct gdbarch *gdbarch = get_regcache_arch (regcache);
b89667eb 6881
16c381f0 6882 tp->suspend = inf_state->thread_suspend;
dd80ea3c 6883#if 0 /* Currently unused and empty structures are not valid C. */
16c381f0 6884 inf->suspend = inf_state->inferior_suspend;
dd80ea3c 6885#endif
16c381f0 6886
b89667eb
DE
6887 stop_pc = inf_state->stop_pc;
6888
1736ad11
JK
6889 if (inf_state->siginfo_gdbarch == gdbarch)
6890 {
6891 struct type *type = gdbarch_get_siginfo_type (gdbarch);
1736ad11
JK
6892
6893 /* Errors ignored. */
6894 target_write (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6acef6cd 6895 inf_state->siginfo_data, 0, TYPE_LENGTH (type));
1736ad11
JK
6896 }
6897
b89667eb
DE
6898 /* The inferior can be gone if the user types "print exit(0)"
6899 (and perhaps other times). */
6900 if (target_has_execution)
6901 /* NB: The register write goes through to the target. */
1736ad11 6902 regcache_cpy (regcache, inf_state->registers);
803b5f95 6903
16c381f0 6904 discard_infcall_suspend_state (inf_state);
b89667eb
DE
6905}
6906
6907static void
16c381f0 6908do_restore_infcall_suspend_state_cleanup (void *state)
b89667eb 6909{
16c381f0 6910 restore_infcall_suspend_state (state);
b89667eb
DE
6911}
6912
6913struct cleanup *
16c381f0
JK
6914make_cleanup_restore_infcall_suspend_state
6915 (struct infcall_suspend_state *inf_state)
b89667eb 6916{
16c381f0 6917 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
b89667eb
DE
6918}
6919
6920void
16c381f0 6921discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
b89667eb
DE
6922{
6923 regcache_xfree (inf_state->registers);
803b5f95 6924 xfree (inf_state->siginfo_data);
b89667eb
DE
6925 xfree (inf_state);
6926}
6927
6928struct regcache *
16c381f0 6929get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
b89667eb
DE
6930{
6931 return inf_state->registers;
6932}
6933
16c381f0
JK
6934/* infcall_control_state contains state regarding gdb's control of the
6935 inferior itself like stepping control. It also contains session state like
6936 the user's currently selected frame. */
b89667eb 6937
16c381f0 6938struct infcall_control_state
b89667eb 6939{
16c381f0
JK
6940 struct thread_control_state thread_control;
6941 struct inferior_control_state inferior_control;
d82142e2
JK
6942
6943 /* Other fields: */
6944 enum stop_stack_kind stop_stack_dummy;
6945 int stopped_by_random_signal;
7a292a7a 6946 int stop_after_trap;
7a292a7a 6947
b89667eb 6948 /* ID if the selected frame when the inferior function call was made. */
101dcfbe 6949 struct frame_id selected_frame_id;
7a292a7a
SS
6950};
6951
c906108c 6952/* Save all of the information associated with the inferior<==>gdb
b89667eb 6953 connection. */
c906108c 6954
16c381f0
JK
6955struct infcall_control_state *
6956save_infcall_control_state (void)
c906108c 6957{
16c381f0 6958 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
4e1c45ea 6959 struct thread_info *tp = inferior_thread ();
d6b48e9c 6960 struct inferior *inf = current_inferior ();
7a292a7a 6961
16c381f0
JK
6962 inf_status->thread_control = tp->control;
6963 inf_status->inferior_control = inf->control;
d82142e2 6964
8358c15c 6965 tp->control.step_resume_breakpoint = NULL;
5b79abe7 6966 tp->control.exception_resume_breakpoint = NULL;
8358c15c 6967
16c381f0
JK
6968 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6969 chain. If caller's caller is walking the chain, they'll be happier if we
6970 hand them back the original chain when restore_infcall_control_state is
6971 called. */
6972 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
d82142e2
JK
6973
6974 /* Other fields: */
6975 inf_status->stop_stack_dummy = stop_stack_dummy;
6976 inf_status->stopped_by_random_signal = stopped_by_random_signal;
6977 inf_status->stop_after_trap = stop_after_trap;
c5aa993b 6978
206415a3 6979 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
b89667eb 6980
7a292a7a 6981 return inf_status;
c906108c
SS
6982}
6983
c906108c 6984static int
96baa820 6985restore_selected_frame (void *args)
c906108c 6986{
488f131b 6987 struct frame_id *fid = (struct frame_id *) args;
c906108c 6988 struct frame_info *frame;
c906108c 6989
101dcfbe 6990 frame = frame_find_by_id (*fid);
c906108c 6991
aa0cd9c1
AC
6992 /* If inf_status->selected_frame_id is NULL, there was no previously
6993 selected frame. */
101dcfbe 6994 if (frame == NULL)
c906108c 6995 {
8a3fe4f8 6996 warning (_("Unable to restore previously selected frame."));
c906108c
SS
6997 return 0;
6998 }
6999
0f7d239c 7000 select_frame (frame);
c906108c
SS
7001
7002 return (1);
7003}
7004
b89667eb
DE
7005/* Restore inferior session state to INF_STATUS. */
7006
c906108c 7007void
16c381f0 7008restore_infcall_control_state (struct infcall_control_state *inf_status)
c906108c 7009{
4e1c45ea 7010 struct thread_info *tp = inferior_thread ();
d6b48e9c 7011 struct inferior *inf = current_inferior ();
4e1c45ea 7012
8358c15c
JK
7013 if (tp->control.step_resume_breakpoint)
7014 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
7015
5b79abe7
TT
7016 if (tp->control.exception_resume_breakpoint)
7017 tp->control.exception_resume_breakpoint->disposition
7018 = disp_del_at_next_stop;
7019
d82142e2 7020 /* Handle the bpstat_copy of the chain. */
16c381f0 7021 bpstat_clear (&tp->control.stop_bpstat);
d82142e2 7022
16c381f0
JK
7023 tp->control = inf_status->thread_control;
7024 inf->control = inf_status->inferior_control;
d82142e2
JK
7025
7026 /* Other fields: */
7027 stop_stack_dummy = inf_status->stop_stack_dummy;
7028 stopped_by_random_signal = inf_status->stopped_by_random_signal;
7029 stop_after_trap = inf_status->stop_after_trap;
c906108c 7030
b89667eb 7031 if (target_has_stack)
c906108c 7032 {
c906108c 7033 /* The point of catch_errors is that if the stack is clobbered,
101dcfbe
AC
7034 walking the stack might encounter a garbage pointer and
7035 error() trying to dereference it. */
488f131b
JB
7036 if (catch_errors
7037 (restore_selected_frame, &inf_status->selected_frame_id,
7038 "Unable to restore previously selected frame:\n",
7039 RETURN_MASK_ERROR) == 0)
c906108c
SS
7040 /* Error in restoring the selected frame. Select the innermost
7041 frame. */
0f7d239c 7042 select_frame (get_current_frame ());
c906108c 7043 }
c906108c 7044
72cec141 7045 xfree (inf_status);
7a292a7a 7046}
c906108c 7047
74b7792f 7048static void
16c381f0 7049do_restore_infcall_control_state_cleanup (void *sts)
74b7792f 7050{
16c381f0 7051 restore_infcall_control_state (sts);
74b7792f
AC
7052}
7053
7054struct cleanup *
16c381f0
JK
7055make_cleanup_restore_infcall_control_state
7056 (struct infcall_control_state *inf_status)
74b7792f 7057{
16c381f0 7058 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
74b7792f
AC
7059}
7060
c906108c 7061void
16c381f0 7062discard_infcall_control_state (struct infcall_control_state *inf_status)
7a292a7a 7063{
8358c15c
JK
7064 if (inf_status->thread_control.step_resume_breakpoint)
7065 inf_status->thread_control.step_resume_breakpoint->disposition
7066 = disp_del_at_next_stop;
7067
5b79abe7
TT
7068 if (inf_status->thread_control.exception_resume_breakpoint)
7069 inf_status->thread_control.exception_resume_breakpoint->disposition
7070 = disp_del_at_next_stop;
7071
1777feb0 7072 /* See save_infcall_control_state for info on stop_bpstat. */
16c381f0 7073 bpstat_clear (&inf_status->thread_control.stop_bpstat);
8358c15c 7074
72cec141 7075 xfree (inf_status);
7a292a7a 7076}
b89667eb 7077\f
ca6724c1
KB
7078/* restore_inferior_ptid() will be used by the cleanup machinery
7079 to restore the inferior_ptid value saved in a call to
7080 save_inferior_ptid(). */
ce696e05
KB
7081
7082static void
7083restore_inferior_ptid (void *arg)
7084{
7085 ptid_t *saved_ptid_ptr = arg;
abbb1732 7086
ce696e05
KB
7087 inferior_ptid = *saved_ptid_ptr;
7088 xfree (arg);
7089}
7090
7091/* Save the value of inferior_ptid so that it may be restored by a
7092 later call to do_cleanups(). Returns the struct cleanup pointer
7093 needed for later doing the cleanup. */
7094
7095struct cleanup *
7096save_inferior_ptid (void)
7097{
7098 ptid_t *saved_ptid_ptr;
7099
7100 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
7101 *saved_ptid_ptr = inferior_ptid;
7102 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
7103}
0c557179
SDJ
7104
7105/* See inferior.h. */
7106
7107void
7108clear_exit_convenience_vars (void)
7109{
7110 clear_internalvar (lookup_internalvar ("_exitsignal"));
7111 clear_internalvar (lookup_internalvar ("_exitcode"));
7112}
c5aa993b 7113\f
488f131b 7114
b2175913
MS
7115/* User interface for reverse debugging:
7116 Set exec-direction / show exec-direction commands
7117 (returns error unless target implements to_set_exec_direction method). */
7118
32231432 7119int execution_direction = EXEC_FORWARD;
b2175913
MS
7120static const char exec_forward[] = "forward";
7121static const char exec_reverse[] = "reverse";
7122static const char *exec_direction = exec_forward;
40478521 7123static const char *const exec_direction_names[] = {
b2175913
MS
7124 exec_forward,
7125 exec_reverse,
7126 NULL
7127};
7128
7129static void
7130set_exec_direction_func (char *args, int from_tty,
7131 struct cmd_list_element *cmd)
7132{
7133 if (target_can_execute_reverse)
7134 {
7135 if (!strcmp (exec_direction, exec_forward))
7136 execution_direction = EXEC_FORWARD;
7137 else if (!strcmp (exec_direction, exec_reverse))
7138 execution_direction = EXEC_REVERSE;
7139 }
8bbed405
MS
7140 else
7141 {
7142 exec_direction = exec_forward;
7143 error (_("Target does not support this operation."));
7144 }
b2175913
MS
7145}
7146
7147static void
7148show_exec_direction_func (struct ui_file *out, int from_tty,
7149 struct cmd_list_element *cmd, const char *value)
7150{
7151 switch (execution_direction) {
7152 case EXEC_FORWARD:
7153 fprintf_filtered (out, _("Forward.\n"));
7154 break;
7155 case EXEC_REVERSE:
7156 fprintf_filtered (out, _("Reverse.\n"));
7157 break;
b2175913 7158 default:
d8b34453
PA
7159 internal_error (__FILE__, __LINE__,
7160 _("bogus execution_direction value: %d"),
7161 (int) execution_direction);
b2175913
MS
7162 }
7163}
7164
d4db2f36
PA
7165static void
7166show_schedule_multiple (struct ui_file *file, int from_tty,
7167 struct cmd_list_element *c, const char *value)
7168{
3e43a32a
MS
7169 fprintf_filtered (file, _("Resuming the execution of threads "
7170 "of all processes is %s.\n"), value);
d4db2f36 7171}
ad52ddc6 7172
22d2b532
SDJ
7173/* Implementation of `siginfo' variable. */
7174
7175static const struct internalvar_funcs siginfo_funcs =
7176{
7177 siginfo_make_value,
7178 NULL,
7179 NULL
7180};
7181
c906108c 7182void
96baa820 7183_initialize_infrun (void)
c906108c 7184{
52f0bd74
AC
7185 int i;
7186 int numsigs;
de0bea00 7187 struct cmd_list_element *c;
c906108c 7188
1bedd215
AC
7189 add_info ("signals", signals_info, _("\
7190What debugger does when program gets various signals.\n\
7191Specify a signal as argument to print info on that signal only."));
c906108c
SS
7192 add_info_alias ("handle", "signals", 0);
7193
de0bea00 7194 c = add_com ("handle", class_run, handle_command, _("\
dfbd5e7b 7195Specify how to handle signals.\n\
486c7739 7196Usage: handle SIGNAL [ACTIONS]\n\
c906108c 7197Args are signals and actions to apply to those signals.\n\
dfbd5e7b 7198If no actions are specified, the current settings for the specified signals\n\
486c7739
MF
7199will be displayed instead.\n\
7200\n\
c906108c
SS
7201Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7202from 1-15 are allowed for compatibility with old versions of GDB.\n\
7203Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7204The special arg \"all\" is recognized to mean all signals except those\n\
1bedd215 7205used by the debugger, typically SIGTRAP and SIGINT.\n\
486c7739 7206\n\
1bedd215 7207Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
c906108c
SS
7208\"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7209Stop means reenter debugger if this signal happens (implies print).\n\
7210Print means print a message if this signal happens.\n\
7211Pass means let program see this signal; otherwise program doesn't know.\n\
7212Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
dfbd5e7b
PA
7213Pass and Stop may be combined.\n\
7214\n\
7215Multiple signals may be specified. Signal numbers and signal names\n\
7216may be interspersed with actions, with the actions being performed for\n\
7217all signals cumulatively specified."));
de0bea00 7218 set_cmd_completer (c, handle_completer);
486c7739 7219
c906108c
SS
7220 if (xdb_commands)
7221 {
1bedd215
AC
7222 add_com ("lz", class_info, signals_info, _("\
7223What debugger does when program gets various signals.\n\
7224Specify a signal as argument to print info on that signal only."));
7225 add_com ("z", class_run, xdb_handle_command, _("\
7226Specify how to handle a signal.\n\
c906108c
SS
7227Args are signals and actions to apply to those signals.\n\
7228Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7229from 1-15 are allowed for compatibility with old versions of GDB.\n\
7230Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7231The special arg \"all\" is recognized to mean all signals except those\n\
1bedd215 7232used by the debugger, typically SIGTRAP and SIGINT.\n\
cce7e648 7233Recognized actions include \"s\" (toggles between stop and nostop),\n\
c906108c
SS
7234\"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7235nopass), \"Q\" (noprint)\n\
7236Stop means reenter debugger if this signal happens (implies print).\n\
7237Print means print a message if this signal happens.\n\
7238Pass means let program see this signal; otherwise program doesn't know.\n\
7239Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
1bedd215 7240Pass and Stop may be combined."));
c906108c
SS
7241 }
7242
7243 if (!dbx_commands)
1a966eab
AC
7244 stop_command = add_cmd ("stop", class_obscure,
7245 not_just_help_class_command, _("\
7246There is no `stop' command, but you can set a hook on `stop'.\n\
c906108c 7247This allows you to set a list of commands to be run each time execution\n\
1a966eab 7248of the program stops."), &cmdlist);
c906108c 7249
ccce17b0 7250 add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
85c07804
AC
7251Set inferior debugging."), _("\
7252Show inferior debugging."), _("\
7253When non-zero, inferior specific debugging is enabled."),
ccce17b0
YQ
7254 NULL,
7255 show_debug_infrun,
7256 &setdebuglist, &showdebuglist);
527159b7 7257
3e43a32a
MS
7258 add_setshow_boolean_cmd ("displaced", class_maintenance,
7259 &debug_displaced, _("\
237fc4c9
PA
7260Set displaced stepping debugging."), _("\
7261Show displaced stepping debugging."), _("\
7262When non-zero, displaced stepping specific debugging is enabled."),
7263 NULL,
7264 show_debug_displaced,
7265 &setdebuglist, &showdebuglist);
7266
ad52ddc6
PA
7267 add_setshow_boolean_cmd ("non-stop", no_class,
7268 &non_stop_1, _("\
7269Set whether gdb controls the inferior in non-stop mode."), _("\
7270Show whether gdb controls the inferior in non-stop mode."), _("\
7271When debugging a multi-threaded program and this setting is\n\
7272off (the default, also called all-stop mode), when one thread stops\n\
7273(for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7274all other threads in the program while you interact with the thread of\n\
7275interest. When you continue or step a thread, you can allow the other\n\
7276threads to run, or have them remain stopped, but while you inspect any\n\
7277thread's state, all threads stop.\n\
7278\n\
7279In non-stop mode, when one thread stops, other threads can continue\n\
7280to run freely. You'll be able to step each thread independently,\n\
7281leave it stopped or free to run as needed."),
7282 set_non_stop,
7283 show_non_stop,
7284 &setlist,
7285 &showlist);
7286
a493e3e2 7287 numsigs = (int) GDB_SIGNAL_LAST;
488f131b 7288 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
c906108c
SS
7289 signal_print = (unsigned char *)
7290 xmalloc (sizeof (signal_print[0]) * numsigs);
7291 signal_program = (unsigned char *)
7292 xmalloc (sizeof (signal_program[0]) * numsigs);
ab04a2af
TT
7293 signal_catch = (unsigned char *)
7294 xmalloc (sizeof (signal_catch[0]) * numsigs);
2455069d
UW
7295 signal_pass = (unsigned char *)
7296 xmalloc (sizeof (signal_program[0]) * numsigs);
c906108c
SS
7297 for (i = 0; i < numsigs; i++)
7298 {
7299 signal_stop[i] = 1;
7300 signal_print[i] = 1;
7301 signal_program[i] = 1;
ab04a2af 7302 signal_catch[i] = 0;
c906108c
SS
7303 }
7304
7305 /* Signals caused by debugger's own actions
7306 should not be given to the program afterwards. */
a493e3e2
PA
7307 signal_program[GDB_SIGNAL_TRAP] = 0;
7308 signal_program[GDB_SIGNAL_INT] = 0;
c906108c
SS
7309
7310 /* Signals that are not errors should not normally enter the debugger. */
a493e3e2
PA
7311 signal_stop[GDB_SIGNAL_ALRM] = 0;
7312 signal_print[GDB_SIGNAL_ALRM] = 0;
7313 signal_stop[GDB_SIGNAL_VTALRM] = 0;
7314 signal_print[GDB_SIGNAL_VTALRM] = 0;
7315 signal_stop[GDB_SIGNAL_PROF] = 0;
7316 signal_print[GDB_SIGNAL_PROF] = 0;
7317 signal_stop[GDB_SIGNAL_CHLD] = 0;
7318 signal_print[GDB_SIGNAL_CHLD] = 0;
7319 signal_stop[GDB_SIGNAL_IO] = 0;
7320 signal_print[GDB_SIGNAL_IO] = 0;
7321 signal_stop[GDB_SIGNAL_POLL] = 0;
7322 signal_print[GDB_SIGNAL_POLL] = 0;
7323 signal_stop[GDB_SIGNAL_URG] = 0;
7324 signal_print[GDB_SIGNAL_URG] = 0;
7325 signal_stop[GDB_SIGNAL_WINCH] = 0;
7326 signal_print[GDB_SIGNAL_WINCH] = 0;
7327 signal_stop[GDB_SIGNAL_PRIO] = 0;
7328 signal_print[GDB_SIGNAL_PRIO] = 0;
c906108c 7329
cd0fc7c3
SS
7330 /* These signals are used internally by user-level thread
7331 implementations. (See signal(5) on Solaris.) Like the above
7332 signals, a healthy program receives and handles them as part of
7333 its normal operation. */
a493e3e2
PA
7334 signal_stop[GDB_SIGNAL_LWP] = 0;
7335 signal_print[GDB_SIGNAL_LWP] = 0;
7336 signal_stop[GDB_SIGNAL_WAITING] = 0;
7337 signal_print[GDB_SIGNAL_WAITING] = 0;
7338 signal_stop[GDB_SIGNAL_CANCEL] = 0;
7339 signal_print[GDB_SIGNAL_CANCEL] = 0;
cd0fc7c3 7340
2455069d
UW
7341 /* Update cached state. */
7342 signal_cache_update (-1);
7343
85c07804
AC
7344 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
7345 &stop_on_solib_events, _("\
7346Set stopping for shared library events."), _("\
7347Show stopping for shared library events."), _("\
c906108c
SS
7348If nonzero, gdb will give control to the user when the dynamic linker\n\
7349notifies gdb of shared library events. The most common event of interest\n\
85c07804 7350to the user would be loading/unloading of a new library."),
f9e14852 7351 set_stop_on_solib_events,
920d2a44 7352 show_stop_on_solib_events,
85c07804 7353 &setlist, &showlist);
c906108c 7354
7ab04401
AC
7355 add_setshow_enum_cmd ("follow-fork-mode", class_run,
7356 follow_fork_mode_kind_names,
7357 &follow_fork_mode_string, _("\
7358Set debugger response to a program call of fork or vfork."), _("\
7359Show debugger response to a program call of fork or vfork."), _("\
c906108c
SS
7360A fork or vfork creates a new process. follow-fork-mode can be:\n\
7361 parent - the original process is debugged after a fork\n\
7362 child - the new process is debugged after a fork\n\
ea1dd7bc 7363The unfollowed process will continue to run.\n\
7ab04401
AC
7364By default, the debugger will follow the parent process."),
7365 NULL,
920d2a44 7366 show_follow_fork_mode_string,
7ab04401
AC
7367 &setlist, &showlist);
7368
6c95b8df
PA
7369 add_setshow_enum_cmd ("follow-exec-mode", class_run,
7370 follow_exec_mode_names,
7371 &follow_exec_mode_string, _("\
7372Set debugger response to a program call of exec."), _("\
7373Show debugger response to a program call of exec."), _("\
7374An exec call replaces the program image of a process.\n\
7375\n\
7376follow-exec-mode can be:\n\
7377\n\
cce7e648 7378 new - the debugger creates a new inferior and rebinds the process\n\
6c95b8df
PA
7379to this new inferior. The program the process was running before\n\
7380the exec call can be restarted afterwards by restarting the original\n\
7381inferior.\n\
7382\n\
7383 same - the debugger keeps the process bound to the same inferior.\n\
7384The new executable image replaces the previous executable loaded in\n\
7385the inferior. Restarting the inferior after the exec call restarts\n\
7386the executable the process was running after the exec call.\n\
7387\n\
7388By default, the debugger will use the same inferior."),
7389 NULL,
7390 show_follow_exec_mode_string,
7391 &setlist, &showlist);
7392
7ab04401
AC
7393 add_setshow_enum_cmd ("scheduler-locking", class_run,
7394 scheduler_enums, &scheduler_mode, _("\
7395Set mode for locking scheduler during execution."), _("\
7396Show mode for locking scheduler during execution."), _("\
c906108c
SS
7397off == no locking (threads may preempt at any time)\n\
7398on == full locking (no thread except the current thread may run)\n\
7399step == scheduler locked during every single-step operation.\n\
7400 In this mode, no other thread may run during a step command.\n\
7ab04401
AC
7401 Other threads may run while stepping over a function call ('next')."),
7402 set_schedlock_func, /* traps on target vector */
920d2a44 7403 show_scheduler_mode,
7ab04401 7404 &setlist, &showlist);
5fbbeb29 7405
d4db2f36
PA
7406 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7407Set mode for resuming threads of all processes."), _("\
7408Show mode for resuming threads of all processes."), _("\
7409When on, execution commands (such as 'continue' or 'next') resume all\n\
7410threads of all processes. When off (which is the default), execution\n\
7411commands only resume the threads of the current process. The set of\n\
7412threads that are resumed is further refined by the scheduler-locking\n\
7413mode (see help set scheduler-locking)."),
7414 NULL,
7415 show_schedule_multiple,
7416 &setlist, &showlist);
7417
5bf193a2
AC
7418 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7419Set mode of the step operation."), _("\
7420Show mode of the step operation."), _("\
7421When set, doing a step over a function without debug line information\n\
7422will stop at the first instruction of that function. Otherwise, the\n\
7423function is skipped and the step command stops at a different source line."),
7424 NULL,
920d2a44 7425 show_step_stop_if_no_debug,
5bf193a2 7426 &setlist, &showlist);
ca6724c1 7427
72d0e2c5
YQ
7428 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run,
7429 &can_use_displaced_stepping, _("\
237fc4c9
PA
7430Set debugger's willingness to use displaced stepping."), _("\
7431Show debugger's willingness to use displaced stepping."), _("\
fff08868
HZ
7432If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7433supported by the target architecture. If off, gdb will not use displaced\n\
7434stepping to step over breakpoints, even if such is supported by the target\n\
7435architecture. If auto (which is the default), gdb will use displaced stepping\n\
7436if the target architecture supports it and non-stop mode is active, but will not\n\
7437use it in all-stop mode (see help set non-stop)."),
72d0e2c5
YQ
7438 NULL,
7439 show_can_use_displaced_stepping,
7440 &setlist, &showlist);
237fc4c9 7441
b2175913
MS
7442 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7443 &exec_direction, _("Set direction of execution.\n\
7444Options are 'forward' or 'reverse'."),
7445 _("Show direction of execution (forward/reverse)."),
7446 _("Tells gdb whether to execute forward or backward."),
7447 set_exec_direction_func, show_exec_direction_func,
7448 &setlist, &showlist);
7449
6c95b8df
PA
7450 /* Set/show detach-on-fork: user-settable mode. */
7451
7452 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7453Set whether gdb will detach the child of a fork."), _("\
7454Show whether gdb will detach the child of a fork."), _("\
7455Tells gdb whether to detach the child of a fork."),
7456 NULL, NULL, &setlist, &showlist);
7457
03583c20
UW
7458 /* Set/show disable address space randomization mode. */
7459
7460 add_setshow_boolean_cmd ("disable-randomization", class_support,
7461 &disable_randomization, _("\
7462Set disabling of debuggee's virtual address space randomization."), _("\
7463Show disabling of debuggee's virtual address space randomization."), _("\
7464When this mode is on (which is the default), randomization of the virtual\n\
7465address space is disabled. Standalone programs run with the randomization\n\
7466enabled by default on some platforms."),
7467 &set_disable_randomization,
7468 &show_disable_randomization,
7469 &setlist, &showlist);
7470
ca6724c1 7471 /* ptid initializations */
ca6724c1
KB
7472 inferior_ptid = null_ptid;
7473 target_last_wait_ptid = minus_one_ptid;
5231c1fd
PA
7474
7475 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
252fbfc8 7476 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
a07daef3 7477 observer_attach_thread_exit (infrun_thread_thread_exit);
fc1cf338 7478 observer_attach_inferior_exit (infrun_inferior_exit);
4aa995e1
PA
7479
7480 /* Explicitly create without lookup, since that tries to create a
7481 value with a void typed value, and when we get here, gdbarch
7482 isn't initialized yet. At this point, we're quite sure there
7483 isn't another convenience variable of the same name. */
22d2b532 7484 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL);
d914c394
SS
7485
7486 add_setshow_boolean_cmd ("observer", no_class,
7487 &observer_mode_1, _("\
7488Set whether gdb controls the inferior in observer mode."), _("\
7489Show whether gdb controls the inferior in observer mode."), _("\
7490In observer mode, GDB can get data from the inferior, but not\n\
7491affect its execution. Registers and memory may not be changed,\n\
7492breakpoints may not be set, and the program cannot be interrupted\n\
7493or signalled."),
7494 set_observer_mode,
7495 show_observer_mode,
7496 &setlist,
7497 &showlist);
c906108c 7498}
This page took 1.801525 seconds and 4 git commands to generate.