461
463
insert_breakpoints ();
466
/* The child has exited or execed: resume threads of the parent the
467
user wanted to be executing. */
470
proceed_after_vfork_done (struct thread_info *thread,
473
int pid = * (int *) arg;
475
if (ptid_get_pid (thread->ptid) == pid
476
&& is_running (thread->ptid)
477
&& !is_executing (thread->ptid)
478
&& !thread->stop_requested
479
&& thread->stop_signal == TARGET_SIGNAL_0)
482
fprintf_unfiltered (gdb_stdlog,
483
"infrun: resuming vfork parent thread %s\n",
484
target_pid_to_str (thread->ptid));
486
switch_to_thread (thread->ptid);
487
clear_proceed_status ();
488
proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
494
/* Called whenever we notice an exec or exit event, to handle
495
detaching or resuming a vfork parent. */
498
handle_vfork_child_exec_or_exit (int exec)
500
struct inferior *inf = current_inferior ();
502
if (inf->vfork_parent)
504
int resume_parent = -1;
506
/* This exec or exit marks the end of the shared memory region
507
between the parent and the child. If the user wanted to
508
detach from the parent, now is the time. */
510
if (inf->vfork_parent->pending_detach)
512
struct thread_info *tp;
513
struct cleanup *old_chain;
514
struct program_space *pspace;
515
struct address_space *aspace;
517
/* follow-fork child, detach-on-fork on */
519
old_chain = make_cleanup_restore_current_thread ();
521
/* We're letting loose of the parent. */
522
tp = any_live_thread_of_process (inf->vfork_parent->pid);
523
switch_to_thread (tp->ptid);
525
/* We're about to detach from the parent, which implicitly
526
removes breakpoints from its address space. There's a
527
catch here: we want to reuse the spaces for the child,
528
but, parent/child are still sharing the pspace at this
529
point, although the exec in reality makes the kernel give
530
the child a fresh set of new pages. The problem here is
531
that the breakpoints module being unaware of this, would
532
likely chose the child process to write to the parent
533
address space. Swapping the child temporarily away from
534
the spaces has the desired effect. Yes, this is "sort
537
pspace = inf->pspace;
538
aspace = inf->aspace;
542
if (debug_infrun || info_verbose)
544
target_terminal_ours ();
547
fprintf_filtered (gdb_stdlog,
548
"Detaching vfork parent process %d after child exec.\n",
549
inf->vfork_parent->pid);
551
fprintf_filtered (gdb_stdlog,
552
"Detaching vfork parent process %d after child exit.\n",
553
inf->vfork_parent->pid);
556
target_detach (NULL, 0);
559
inf->pspace = pspace;
560
inf->aspace = aspace;
562
do_cleanups (old_chain);
566
/* We're staying attached to the parent, so, really give the
567
child a new address space. */
568
inf->pspace = add_program_space (maybe_new_address_space ());
569
inf->aspace = inf->pspace->aspace;
571
set_current_program_space (inf->pspace);
573
resume_parent = inf->vfork_parent->pid;
575
/* Break the bonds. */
576
inf->vfork_parent->vfork_child = NULL;
580
struct cleanup *old_chain;
581
struct program_space *pspace;
583
/* If this is a vfork child exiting, then the pspace and
584
aspaces were shared with the parent. Since we're
585
reporting the process exit, we'll be mourning all that is
586
found in the address space, and switching to null_ptid,
587
preparing to start a new inferior. But, since we don't
588
want to clobber the parent's address/program spaces, we
589
go ahead and create a new one for this exiting
592
/* Switch to null_ptid, so that clone_program_space doesn't want
593
to read the selected frame of a dead process. */
594
old_chain = save_inferior_ptid ();
595
inferior_ptid = null_ptid;
597
/* This inferior is dead, so avoid giving the breakpoints
598
module the option to write through to it (cloning a
599
program space resets breakpoints). */
602
pspace = add_program_space (maybe_new_address_space ());
603
set_current_program_space (pspace);
605
clone_program_space (pspace, inf->vfork_parent->pspace);
606
inf->pspace = pspace;
607
inf->aspace = pspace->aspace;
609
/* Put back inferior_ptid. We'll continue mourning this
611
do_cleanups (old_chain);
613
resume_parent = inf->vfork_parent->pid;
614
/* Break the bonds. */
615
inf->vfork_parent->vfork_child = NULL;
618
inf->vfork_parent = NULL;
620
gdb_assert (current_program_space == inf->pspace);
622
if (non_stop && resume_parent != -1)
624
/* If the user wanted the parent to be running, let it go
626
struct cleanup *old_chain = make_cleanup_restore_current_thread ();
629
fprintf_unfiltered (gdb_stdlog, "infrun: resuming vfork parent process %d\n",
632
iterate_over_threads (proceed_after_vfork_done, &resume_parent);
634
do_cleanups (old_chain);
639
/* Enum strings for "set|show displaced-stepping". */
641
static const char follow_exec_mode_new[] = "new";
642
static const char follow_exec_mode_same[] = "same";
643
static const char *follow_exec_mode_names[] =
645
follow_exec_mode_new,
646
follow_exec_mode_same,
650
static const char *follow_exec_mode_string = follow_exec_mode_same;
652
show_follow_exec_mode_string (struct ui_file *file, int from_tty,
653
struct cmd_list_element *c, const char *value)
655
fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
464
658
/* EXECD_PATHNAME is assumed to be non-NULL. */
536
733
previous incarnation of this process. */
537
734
no_shared_libraries (NULL, 0);
736
if (follow_exec_mode_string == follow_exec_mode_new)
738
struct program_space *pspace;
739
struct inferior *new_inf;
741
/* The user wants to keep the old inferior and program spaces
742
around. Create a new fresh one, and switch to it. */
744
inf = add_inferior (current_inferior ()->pid);
745
pspace = add_program_space (maybe_new_address_space ());
746
inf->pspace = pspace;
747
inf->aspace = pspace->aspace;
749
exit_inferior_num_silent (current_inferior ()->num);
751
set_current_inferior (inf);
752
set_current_program_space (pspace);
755
gdb_assert (current_program_space == inf->pspace);
757
/* That a.out is now the one to use. */
758
exec_file_attach (execd_pathname, 0);
539
760
/* Load the main file's symbols. */
540
761
symbol_file_add_main (execd_pathname, 0);
542
763
#ifdef SOLIB_CREATE_INFERIOR_HOOK
543
764
SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
545
solib_create_inferior_hook ();
766
solib_create_inferior_hook (0);
548
769
jit_inferior_created_hook ();
1362
1586
clear_proceed_status (void)
1590
/* In all-stop mode, delete the per-thread status of all
1591
threads, even if inferior_ptid is null_ptid, there may be
1592
threads on the list. E.g., we may be launching a new
1593
process, while selecting the executable. */
1594
iterate_over_threads (clear_proceed_status_callback, NULL);
1364
1597
if (!ptid_equal (inferior_ptid, null_ptid))
1366
1599
struct inferior *inferior;
1370
/* If in non-stop mode, only delete the per-thread status
1371
of the current thread. */
1603
/* If in non-stop mode, only delete the per-thread status of
1604
the current thread. */
1372
1605
clear_proceed_status_thread (inferior_thread ());
1376
/* In all-stop mode, delete the per-thread status of
1378
iterate_over_threads (clear_proceed_status_callback, NULL);
1381
1608
inferior = current_inferior ();
1382
1609
inferior->stop_soon = NO_STOP_QUIETLY;
1625
1868
or a return command, we often end up a few instructions forward, still
1626
1869
within the original line we started.
1628
An attempt was made to have init_execution_control_state () refresh
1629
the prev_pc value before calculating the line number. This approach
1630
did not work because on platforms that use ptrace, the pc register
1631
cannot be read unless the inferior is stopped. At that point, we
1632
are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1633
call can fail. Setting the prev_pc value here ensures the value is
1634
updated correctly when the inferior is stopped. */
1871
An attempt was made to refresh the prev_pc at the same time the
1872
execution_control_state is initialized (for instance, just before
1873
waiting for an inferior event). But this approach did not work
1874
because of platforms that use ptrace, where the pc register cannot
1875
be read unless the inferior is stopped. At that point, we are not
1876
guaranteed the inferior is stopped and so the regcache_read_pc() call
1877
can fail. Setting the prev_pc value here ensures the value is updated
1878
correctly when the inferior is stopped. */
1635
1879
tp->prev_pc = regcache_read_pc (get_current_regcache ());
1637
1881
/* Fill in with reasonable starting values. */
2401
2646
if (debug_infrun)
2402
2647
fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
2403
2648
syscall_number);
2404
ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2406
if (!ptid_equal (ecs->ptid, inferior_ptid))
2408
context_switch (ecs->ptid);
2409
reinit_frame_cache ();
2412
stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2414
ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2650
ecs->event_thread->stop_bpstat
2651
= bpstat_stop_status (get_regcache_aspace (regcache),
2652
stop_pc, ecs->ptid);
2416
2653
ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2418
/* If no catchpoint triggered for this, then keep going. */
2419
if (ecs->random_signal)
2421
ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2429
resume (0, TARGET_SIGNAL_0);
2430
prepare_to_wait (ecs);
2655
if (!ecs->random_signal)
2657
/* Catchpoint hit. */
2658
ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2663
/* If no catchpoint triggered for this, then keep going. */
2664
ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2435
2669
/* Given an execution control state that has been freshly filled in
2447
2681
struct symtab_and_line stop_pc_sal;
2448
2682
enum stop_kind stop_soon;
2684
if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
2686
/* We had an event in the inferior, but we are not interested in
2687
handling it at this level. The lower layers have already
2688
done what needs to be done, if anything.
2690
One of the possible circumstances for this is when the
2691
inferior produces output for the console. The inferior has
2692
not stopped, and we are ignoring the event. Another possible
2693
circumstance is any event which the lower level knows will be
2694
reported multiple times without an intervening resume. */
2696
fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
2697
prepare_to_wait (ecs);
2450
2701
if (ecs->ws.kind != TARGET_WAITKIND_EXITED
2451
&& ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2452
&& ecs->ws.kind != TARGET_WAITKIND_IGNORE)
2702
&& ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2454
2704
struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2455
2705
gdb_assert (inf);
2483
2733
/* Dependent on the current PC value modified by adjust_pc_after_break. */
2484
2734
reinit_frame_cache ();
2486
if (ecs->ws.kind != TARGET_WAITKIND_IGNORE)
2736
breakpoint_retire_moribund ();
2738
/* First, distinguish signals caused by the debugger from signals
2739
that have to do with the program's own actions. Note that
2740
breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2741
on the operating system version. Here we detect when a SIGILL or
2742
SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2743
something similar for SIGSEGV, since a SIGSEGV will be generated
2744
when we're trying to execute a breakpoint instruction on a
2745
non-executable stack. This happens for call dummy breakpoints
2746
for architectures like SPARC that place call dummies on the
2748
if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
2749
&& (ecs->ws.value.sig == TARGET_SIGNAL_ILL
2750
|| ecs->ws.value.sig == TARGET_SIGNAL_SEGV
2751
|| ecs->ws.value.sig == TARGET_SIGNAL_EMT))
2488
breakpoint_retire_moribund ();
2753
struct regcache *regcache = get_thread_regcache (ecs->ptid);
2490
/* Mark the non-executing threads accordingly. In all-stop, all
2491
threads of all processes are stopped when we get any event
2492
reported. In non-stop mode, only the event thread stops. If
2493
we're handling a process exit in non-stop mode, there's
2494
nothing to do, as threads of the dead process are gone, and
2495
threads of any other process were left running. */
2497
set_executing (minus_one_ptid, 0);
2498
else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2499
&& ecs->ws.kind != TARGET_WAITKIND_EXITED)
2500
set_executing (inferior_ptid, 0);
2755
if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
2756
regcache_read_pc (regcache)))
2759
fprintf_unfiltered (gdb_stdlog,
2760
"infrun: Treating signal as SIGTRAP\n");
2761
ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
2765
/* Mark the non-executing threads accordingly. In all-stop, all
2766
threads of all processes are stopped when we get any event
2767
reported. In non-stop mode, only the event thread stops. If
2768
we're handling a process exit in non-stop mode, there's nothing
2769
to do, as threads of the dead process are gone, and threads of
2770
any other process were left running. */
2772
set_executing (minus_one_ptid, 0);
2773
else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2774
&& ecs->ws.kind != TARGET_WAITKIND_EXITED)
2775
set_executing (inferior_ptid, 0);
2503
2777
switch (infwait_state)
2505
2779
case infwait_thread_hop_state:
2688
2972
stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2690
ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2974
ecs->event_thread->stop_bpstat
2975
= bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
2976
stop_pc, ecs->ptid);
2692
ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2978
/* Note that we're interested in knowing the bpstat actually
2979
causes a stop, not just if it may explain the signal.
2980
Software watchpoints, for example, always appear in the
2982
ecs->random_signal = !bpstat_causes_stop (ecs->event_thread->stop_bpstat);
2694
2984
/* If no catchpoint triggered for this, then keep going. */
2695
2985
if (ecs->random_signal)
2697
2989
int should_resume;
2990
int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
2699
2992
ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2701
2994
should_resume = follow_fork ();
2997
child = ecs->ws.value.related_pid;
2999
/* In non-stop mode, also resume the other branch. */
3000
if (non_stop && !detach_fork)
3003
switch_to_thread (parent);
3005
switch_to_thread (child);
3007
ecs->event_thread = inferior_thread ();
3008
ecs->ptid = inferior_ptid;
3013
switch_to_thread (child);
3015
switch_to_thread (parent);
2703
3017
ecs->event_thread = inferior_thread ();
2704
3018
ecs->ptid = inferior_ptid;
3215
3541
3) set ecs->random_signal to 1, and the decision between 1 and 2
3216
3542
will be made according to the signal handling tables. */
3218
/* First, distinguish signals caused by the debugger from signals
3219
that have to do with the program's own actions. Note that
3220
breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3221
on the operating system version. Here we detect when a SIGILL or
3222
SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3223
something similar for SIGSEGV, since a SIGSEGV will be generated
3224
when we're trying to execute a breakpoint instruction on a
3225
non-executable stack. This happens for call dummy breakpoints
3226
for architectures like SPARC that place call dummies on the
3229
If we're doing a displaced step past a breakpoint, then the
3230
breakpoint is always inserted at the original instruction;
3231
non-standard signals can't be explained by the breakpoint. */
3232
3544
if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3233
|| (! ecs->event_thread->trap_expected
3234
&& breakpoint_inserted_here_p (stop_pc)
3235
&& (ecs->event_thread->stop_signal == TARGET_SIGNAL_ILL
3236
|| ecs->event_thread->stop_signal == TARGET_SIGNAL_SEGV
3237
|| ecs->event_thread->stop_signal == TARGET_SIGNAL_EMT))
3238
3545
|| stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
3239
3546
|| stop_soon == STOP_QUIETLY_REMOTE)
3290
3597
/* See if there is a breakpoint at the current PC. */
3291
ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
3598
ecs->event_thread->stop_bpstat
3599
= bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3600
stop_pc, ecs->ptid);
3293
3602
/* Following in case break condition called a
3295
3604
stop_print_frame = 1;
3606
/* This is where we handle "moribund" watchpoints. Unlike
3607
software breakpoints traps, hardware watchpoint traps are
3608
always distinguishable from random traps. If no high-level
3609
watchpoint is associated with the reported stop data address
3610
anymore, then the bpstat does not explain the signal ---
3611
simply make sure to ignore it if `stopped_by_watchpoint' is
3615
&& ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3616
&& !bpstat_explains_signal (ecs->event_thread->stop_bpstat)
3617
&& stopped_by_watchpoint)
3618
fprintf_unfiltered (gdb_stdlog, "\
3619
infrun: no user watchpoint explains watchpoint SIGTRAP, ignoring\n");
3297
3621
/* NOTE: cagney/2003-03-29: These two checks for a random signal
3298
3622
at one stage in the past included checks for an inferior
3299
3623
function call's call dummy's return breakpoint. The original
6047
6400
show_follow_fork_mode_string,
6048
6401
&setlist, &showlist);
6403
add_setshow_enum_cmd ("follow-exec-mode", class_run,
6404
follow_exec_mode_names,
6405
&follow_exec_mode_string, _("\
6406
Set debugger response to a program call of exec."), _("\
6407
Show debugger response to a program call of exec."), _("\
6408
An exec call replaces the program image of a process.\n\
6410
follow-exec-mode can be:\n\
6412
new - the debugger creates a new inferior and rebinds the process \n\
6413
to this new inferior. The program the process was running before\n\
6414
the exec call can be restarted afterwards by restarting the original\n\
6417
same - the debugger keeps the process bound to the same inferior.\n\
6418
The new executable image replaces the previous executable loaded in\n\
6419
the inferior. Restarting the inferior after the exec call restarts\n\
6420
the executable the process was running after the exec call.\n\
6422
By default, the debugger will use the same inferior."),
6424
show_follow_exec_mode_string,
6425
&setlist, &showlist);
6050
6427
add_setshow_enum_cmd ("scheduler-locking", class_run,
6051
6428
scheduler_enums, &scheduler_mode, _("\
6052
6429
Set mode for locking scheduler during execution."), _("\