~ubuntu-branches/debian/jessie/gdb/jessie

« back to all changes in this revision

Viewing changes to gdb/infrun.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2010-03-20 01:21:29 UTC
  • mfrom: (1.3.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320012129-t7h25y8zgr8c2369
Tags: 7.1-1
* New upstream release, including:
  - PIE support (Closes: #346409).
  - C++ improvements, including static_cast<> et al, namespace imports,
    and bug fixes in printing virtual base classes.
  - Multi-program debugging.  One GDB can now debug multiple programs
    at the same time.
  - Python scripting improvements, including gdb.parse_and_eval.
  - Updated MIPS Linux signal frame layout (Closes: #570875).
  - No internal error stepping over _dl_debug_state (Closes: #569551).
* Update to Standards-Version: 3.8.4 (no changes required).
* Include more relevant (and smaller) docs in the gdbserver package
  (Closes: #571132).
* Do not duplicate documentation in gdb64, gdb-source, and libgdb-dev.
* Fix crash when switching into TUI mode (Closes: #568489).

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5
5
   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
6
 
   2008, 2009 Free Software Foundation, Inc.
 
6
   2008, 2009, 2010 Free Software Foundation, Inc.
7
7
 
8
8
   This file is part of GDB.
9
9
 
51
51
#include "record.h"
52
52
#include "inline-frame.h"
53
53
#include "jit.h"
 
54
#include "tracepoint.h"
54
55
 
55
56
/* Prototypes for local functions */
56
57
 
68
69
 
69
70
static int restore_selected_frame (void *);
70
71
 
71
 
static void build_infrun (void);
72
 
 
73
72
static int follow_fork (void);
74
73
 
75
74
static void set_schedlock_func (char *args, int from_tty,
109
108
 
110
109
static ptid_t previous_inferior_ptid;
111
110
 
 
111
/* Default behavior is to detach newly forked processes (legacy).  */
 
112
int detach_fork = 1;
 
113
 
112
114
int debug_displaced = 0;
113
115
static void
114
116
show_debug_displaced (struct ui_file *file, int from_tty,
461
463
  insert_breakpoints ();
462
464
}
463
465
 
 
466
/* The child has exited or execed: resume threads of the parent the
 
467
   user wanted to be executing.  */
 
468
 
 
469
static int
 
470
proceed_after_vfork_done (struct thread_info *thread,
 
471
                          void *arg)
 
472
{
 
473
  int pid = * (int *) arg;
 
474
 
 
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)
 
480
    {
 
481
      if (debug_infrun)
 
482
        fprintf_unfiltered (gdb_stdlog,
 
483
                            "infrun: resuming vfork parent thread %s\n",
 
484
                            target_pid_to_str (thread->ptid));
 
485
 
 
486
      switch_to_thread (thread->ptid);
 
487
      clear_proceed_status ();
 
488
      proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
 
489
    }
 
490
 
 
491
  return 0;
 
492
}
 
493
 
 
494
/* Called whenever we notice an exec or exit event, to handle
 
495
   detaching or resuming a vfork parent.  */
 
496
 
 
497
static void
 
498
handle_vfork_child_exec_or_exit (int exec)
 
499
{
 
500
  struct inferior *inf = current_inferior ();
 
501
 
 
502
  if (inf->vfork_parent)
 
503
    {
 
504
      int resume_parent = -1;
 
505
 
 
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.  */
 
509
 
 
510
      if (inf->vfork_parent->pending_detach)
 
511
        {
 
512
          struct thread_info *tp;
 
513
          struct cleanup *old_chain;
 
514
          struct program_space *pspace;
 
515
          struct address_space *aspace;
 
516
 
 
517
          /* follow-fork child, detach-on-fork on */
 
518
 
 
519
          old_chain = make_cleanup_restore_current_thread ();
 
520
 
 
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);
 
524
 
 
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
 
535
             of" a hack.  */
 
536
 
 
537
          pspace = inf->pspace;
 
538
          aspace = inf->aspace;
 
539
          inf->aspace = NULL;
 
540
          inf->pspace = NULL;
 
541
 
 
542
          if (debug_infrun || info_verbose)
 
543
            {
 
544
              target_terminal_ours ();
 
545
 
 
546
              if (exec)
 
547
                fprintf_filtered (gdb_stdlog,
 
548
                                  "Detaching vfork parent process %d after child exec.\n",
 
549
                                  inf->vfork_parent->pid);
 
550
              else
 
551
                fprintf_filtered (gdb_stdlog,
 
552
                                  "Detaching vfork parent process %d after child exit.\n",
 
553
                                  inf->vfork_parent->pid);
 
554
            }
 
555
 
 
556
          target_detach (NULL, 0);
 
557
 
 
558
          /* Put it back.  */
 
559
          inf->pspace = pspace;
 
560
          inf->aspace = aspace;
 
561
 
 
562
          do_cleanups (old_chain);
 
563
        }
 
564
      else if (exec)
 
565
        {
 
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;
 
570
          inf->removable = 1;
 
571
          set_current_program_space (inf->pspace);
 
572
 
 
573
          resume_parent = inf->vfork_parent->pid;
 
574
 
 
575
          /* Break the bonds.  */
 
576
          inf->vfork_parent->vfork_child = NULL;
 
577
        }
 
578
      else
 
579
        {
 
580
          struct cleanup *old_chain;
 
581
          struct program_space *pspace;
 
582
 
 
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
 
590
             inferior.  */
 
591
 
 
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;
 
596
 
 
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).  */
 
600
          inf->aspace = NULL;
 
601
          inf->pspace = NULL;
 
602
          pspace = add_program_space (maybe_new_address_space ());
 
603
          set_current_program_space (pspace);
 
604
          inf->removable = 1;
 
605
          clone_program_space (pspace, inf->vfork_parent->pspace);
 
606
          inf->pspace = pspace;
 
607
          inf->aspace = pspace->aspace;
 
608
 
 
609
          /* Put back inferior_ptid.  We'll continue mourning this
 
610
             inferior. */
 
611
          do_cleanups (old_chain);
 
612
 
 
613
          resume_parent = inf->vfork_parent->pid;
 
614
          /* Break the bonds.  */
 
615
          inf->vfork_parent->vfork_child = NULL;
 
616
        }
 
617
 
 
618
      inf->vfork_parent = NULL;
 
619
 
 
620
      gdb_assert (current_program_space == inf->pspace);
 
621
 
 
622
      if (non_stop && resume_parent != -1)
 
623
        {
 
624
          /* If the user wanted the parent to be running, let it go
 
625
             free now.  */
 
626
          struct cleanup *old_chain = make_cleanup_restore_current_thread ();
 
627
 
 
628
          if (debug_infrun)
 
629
            fprintf_unfiltered (gdb_stdlog, "infrun: resuming vfork parent process %d\n",
 
630
                                resume_parent);
 
631
 
 
632
          iterate_over_threads (proceed_after_vfork_done, &resume_parent);
 
633
 
 
634
          do_cleanups (old_chain);
 
635
        }
 
636
    }
 
637
}
 
638
 
 
639
/* Enum strings for "set|show displaced-stepping".  */
 
640
 
 
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[] =
 
644
{
 
645
  follow_exec_mode_new,
 
646
  follow_exec_mode_same,
 
647
  NULL,
 
648
};
 
649
 
 
650
static const char *follow_exec_mode_string = follow_exec_mode_same;
 
651
static void
 
652
show_follow_exec_mode_string (struct ui_file *file, int from_tty,
 
653
                              struct cmd_list_element *c, const char *value)
 
654
{
 
655
  fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"),  value);
 
656
}
 
657
 
464
658
/* EXECD_PATHNAME is assumed to be non-NULL. */
465
659
 
466
660
static void
468
662
{
469
663
  struct target_ops *tgt;
470
664
  struct thread_info *th = inferior_thread ();
 
665
  struct inferior *inf = current_inferior ();
471
666
 
472
667
  /* This is an exec event that we actually wish to pay attention to.
473
668
     Refresh our symbol table to the newly exec'd program, remove any
489
684
     that may write the bp's "shadow contents" (the instruction
490
685
     value that was overwritten witha TRAP instruction).  Since
491
686
     we now have a new a.out, those shadow contents aren't valid. */
 
687
 
 
688
  mark_breakpoints_out ();
 
689
 
492
690
  update_breakpoints_after_exec ();
493
691
 
494
692
  /* If there was one, it's gone now.  We cannot truly step-to-next
506
704
  th->stop_requested = 0;
507
705
 
508
706
  /* What is this a.out's name? */
509
 
  printf_unfiltered (_("Executing new program: %s\n"), execd_pathname);
 
707
  printf_unfiltered (_("%s is executing new program: %s\n"),
 
708
                     target_pid_to_str (inferior_ptid),
 
709
                     execd_pathname);
510
710
 
511
711
  /* We've followed the inferior through an exec.  Therefore, the
512
712
     inferior has essentially been killed & reborn. */
525
725
      execd_pathname = name;
526
726
    }
527
727
 
528
 
  /* That a.out is now the one to use. */
529
 
  exec_file_attach (execd_pathname, 0);
530
 
 
531
728
  /* Reset the shared library package.  This ensures that we get a
532
729
     shlib event when the child reaches "_start", at which point the
533
730
     dld will have had a chance to initialize the child.  */
536
733
     previous incarnation of this process.  */
537
734
  no_shared_libraries (NULL, 0);
538
735
 
 
736
  if (follow_exec_mode_string == follow_exec_mode_new)
 
737
    {
 
738
      struct program_space *pspace;
 
739
      struct inferior *new_inf;
 
740
 
 
741
      /* The user wants to keep the old inferior and program spaces
 
742
         around.  Create a new fresh one, and switch to it.  */
 
743
 
 
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;
 
748
 
 
749
      exit_inferior_num_silent (current_inferior ()->num);
 
750
 
 
751
      set_current_inferior (inf);
 
752
      set_current_program_space (pspace);
 
753
    }
 
754
 
 
755
  gdb_assert (current_program_space == inf->pspace);
 
756
 
 
757
  /* That a.out is now the one to use. */
 
758
  exec_file_attach (execd_pathname, 0);
 
759
 
539
760
  /* Load the main file's symbols.  */
540
761
  symbol_file_add_main (execd_pathname, 0);
541
762
 
542
763
#ifdef SOLIB_CREATE_INFERIOR_HOOK
543
764
  SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
544
765
#else
545
 
  solib_create_inferior_hook ();
 
766
  solib_create_inferior_hook (0);
546
767
#endif
547
768
 
548
769
  jit_inferior_created_hook ();
969
1190
      struct regcache *regcache;
970
1191
      struct gdbarch *gdbarch;
971
1192
      CORE_ADDR actual_pc;
 
1193
      struct address_space *aspace;
972
1194
 
973
1195
      head = displaced_step_request_queue;
974
1196
      ptid = head->ptid;
979
1201
 
980
1202
      regcache = get_thread_regcache (ptid);
981
1203
      actual_pc = regcache_read_pc (regcache);
 
1204
      aspace = get_regcache_aspace (regcache);
982
1205
 
983
 
      if (breakpoint_here_p (actual_pc))
 
1206
      if (breakpoint_here_p (aspace, actual_pc))
984
1207
        {
985
1208
          if (debug_displaced)
986
1209
            fprintf_unfiltered (gdb_stdlog,
1145
1368
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
1146
1369
  struct thread_info *tp = inferior_thread ();
1147
1370
  CORE_ADDR pc = regcache_read_pc (regcache);
 
1371
  struct address_space *aspace = get_regcache_aspace (regcache);
1148
1372
 
1149
1373
  QUIT;
1150
1374
 
1170
1394
     removed or inserted, as appropriate.  The exception is if we're sitting
1171
1395
     at a permanent breakpoint; we need to step over it, but permanent
1172
1396
     breakpoints can't be removed.  So we have to test for it here.  */
1173
 
  if (breakpoint_here_p (pc) == permanent_breakpoint_here)
 
1397
  if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1174
1398
    {
1175
1399
      if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1176
1400
        gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1287
1511
          /* Most targets can step a breakpoint instruction, thus
1288
1512
             executing it normally.  But if this one cannot, just
1289
1513
             continue and we will hit it anyway.  */
1290
 
          if (step && breakpoint_inserted_here_p (pc))
 
1514
          if (step && breakpoint_inserted_here_p (aspace, pc))
1291
1515
            step = 0;
1292
1516
        }
1293
1517
 
1361
1585
void
1362
1586
clear_proceed_status (void)
1363
1587
{
 
1588
  if (!non_stop)
 
1589
    {
 
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);
 
1595
    }
 
1596
 
1364
1597
  if (!ptid_equal (inferior_ptid, null_ptid))
1365
1598
    {
1366
1599
      struct inferior *inferior;
1367
1600
 
1368
1601
      if (non_stop)
1369
1602
        {
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 ());
1373
1606
        }
1374
 
      else
1375
 
        {
1376
 
          /* In all-stop mode, delete the per-thread status of
1377
 
             *all* threads.  */
1378
 
          iterate_over_threads (clear_proceed_status_callback, NULL);
1379
 
        }
1380
 
  
 
1607
 
1381
1608
      inferior = current_inferior ();
1382
1609
      inferior->stop_soon = NO_STOP_QUIETLY;
1383
1610
    }
1414
1641
 
1415
1642
  /* Make sure we were stopped at a breakpoint.  */
1416
1643
  if (wait_status.kind != TARGET_WAITKIND_STOPPED
1417
 
      || wait_status.value.sig != TARGET_SIGNAL_TRAP)
 
1644
      || (wait_status.value.sig != TARGET_SIGNAL_TRAP
 
1645
          && wait_status.value.sig != TARGET_SIGNAL_ILL
 
1646
          && wait_status.value.sig != TARGET_SIGNAL_SEGV
 
1647
          && wait_status.value.sig != TARGET_SIGNAL_EMT))
1418
1648
    {
1419
1649
      return 0;
1420
1650
    }
1439
1669
    {
1440
1670
      struct regcache *regcache = get_thread_regcache (wait_ptid);
1441
1671
 
1442
 
      if (breakpoint_here_p (regcache_read_pc (regcache)))
 
1672
      if (breakpoint_here_p (get_regcache_aspace (regcache),
 
1673
                             regcache_read_pc (regcache)))
1443
1674
        {
1444
1675
          /* If stepping, remember current thread to switch back to.  */
1445
1676
          if (step)
1477
1708
  struct gdbarch *gdbarch;
1478
1709
  struct thread_info *tp;
1479
1710
  CORE_ADDR pc;
 
1711
  struct address_space *aspace;
1480
1712
  int oneproc = 0;
1481
1713
 
1482
1714
  /* If we're stopped at a fork/vfork, follow the branch set by the
1491
1723
 
1492
1724
  regcache = get_current_regcache ();
1493
1725
  gdbarch = get_regcache_arch (regcache);
 
1726
  aspace = get_regcache_aspace (regcache);
1494
1727
  pc = regcache_read_pc (regcache);
1495
1728
 
1496
1729
  if (step > 0)
1500
1733
 
1501
1734
  if (addr == (CORE_ADDR) -1)
1502
1735
    {
1503
 
      if (pc == stop_pc && breakpoint_here_p (pc) 
 
1736
      if (pc == stop_pc && breakpoint_here_p (aspace, pc)
1504
1737
          && execution_direction != EXEC_REVERSE)
1505
1738
        /* There is a breakpoint at the address we will resume at,
1506
1739
           step one instruction before inserting breakpoints so that
1529
1762
                        "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
1530
1763
                        paddress (gdbarch, addr), siggnal, step);
1531
1764
 
 
1765
  /* We're handling a live event, so make sure we're doing live
 
1766
     debugging.  If we're looking at traceframes while the target is
 
1767
     running, we're going to need to get back to that mode after
 
1768
     handling the event.  */
 
1769
  if (non_stop)
 
1770
    {
 
1771
      make_cleanup_restore_current_traceframe ();
 
1772
      set_traceframe_number (-1);
 
1773
    }
 
1774
 
1532
1775
  if (non_stop)
1533
1776
    /* In non-stop, each thread is handled individually.  The context
1534
1777
       must already be set to the right thread here.  */
1625
1868
     or a return command, we often end up a few instructions forward, still 
1626
1869
     within the original line we started.
1627
1870
 
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 ());
1636
1880
 
1637
1881
  /* Fill in with reasonable starting values.  */
1768
2012
  int wait_some_more;
1769
2013
};
1770
2014
 
1771
 
static void init_execution_control_state (struct execution_control_state *ecs);
1772
 
 
1773
2015
static void handle_inferior_event (struct execution_control_state *ecs);
1774
2016
 
1775
2017
static void handle_step_into_function (struct gdbarch *gdbarch,
2172
2414
  tp->current_line = sal.line;
2173
2415
}
2174
2416
 
2175
 
/* Prepare an execution control state for looping through a
2176
 
   wait_for_inferior-type loop.  */
2177
 
 
2178
 
static void
2179
 
init_execution_control_state (struct execution_control_state *ecs)
2180
 
{
2181
 
  ecs->random_signal = 0;
2182
 
}
2183
 
 
2184
2417
/* Clear context switchable stepping state.  */
2185
2418
 
2186
2419
void
2231
2464
{
2232
2465
  struct regcache *regcache;
2233
2466
  struct gdbarch *gdbarch;
 
2467
  struct address_space *aspace;
2234
2468
  CORE_ADDR breakpoint_pc;
2235
2469
 
2236
2470
  /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP.  If
2296
2530
  if (gdbarch_decr_pc_after_break (gdbarch) == 0)
2297
2531
    return;
2298
2532
 
 
2533
  aspace = get_regcache_aspace (regcache);
 
2534
 
2299
2535
  /* Find the location where (if we've hit a breakpoint) the
2300
2536
     breakpoint would be.  */
2301
2537
  breakpoint_pc = regcache_read_pc (regcache)
2309
2545
     already queued and arrive later.  To suppress those spurious
2310
2546
     SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2311
2547
     and retire them after a number of stop events are reported.  */
2312
 
  if (software_breakpoint_inserted_here_p (breakpoint_pc)
2313
 
      || (non_stop && moribund_breakpoint_here_p (breakpoint_pc)))
 
2548
  if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
 
2549
      || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
2314
2550
    {
2315
2551
      struct cleanup *old_cleanups = NULL;
2316
2552
      if (RECORD_IS_USED)
2386
2622
   It returns 1 if the inferior should keep going (and GDB
2387
2623
   should ignore the event), or 0 if the event deserves to be
2388
2624
   processed.  */
 
2625
 
2389
2626
static int
2390
 
deal_with_syscall_event (struct execution_control_state *ecs)
 
2627
handle_syscall_event (struct execution_control_state *ecs)
2391
2628
{
2392
 
  struct regcache *regcache = get_thread_regcache (ecs->ptid);
2393
 
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
2394
 
  int syscall_number = gdbarch_get_syscall_number (gdbarch,
2395
 
                                                   ecs->ptid);
 
2629
  struct regcache *regcache;
 
2630
  struct gdbarch *gdbarch;
 
2631
  int syscall_number;
 
2632
 
 
2633
  if (!ptid_equal (ecs->ptid, inferior_ptid))
 
2634
    context_switch (ecs->ptid);
 
2635
 
 
2636
  regcache = get_thread_regcache (ecs->ptid);
 
2637
  gdbarch = get_regcache_arch (regcache);
 
2638
  syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid);
 
2639
  stop_pc = regcache_read_pc (regcache);
 
2640
 
2396
2641
  target_last_waitstatus.value.syscall_number = syscall_number;
2397
2642
 
2398
2643
  if (catch_syscall_enabled () > 0
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;
2405
 
 
2406
 
      if (!ptid_equal (ecs->ptid, inferior_ptid))
2407
 
        {
2408
 
          context_switch (ecs->ptid);
2409
 
          reinit_frame_cache ();
2410
 
        }
2411
 
 
2412
 
      stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2413
 
 
2414
 
      ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2415
 
 
 
2649
 
 
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);
2417
2654
 
2418
 
      /* If no catchpoint triggered for this, then keep going.  */
2419
 
      if (ecs->random_signal)
2420
 
        {
2421
 
          ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2422
 
          keep_going (ecs);
2423
 
          return 1;
2424
 
        }
2425
 
      return 0;
2426
 
    }
2427
 
  else
2428
 
    {
2429
 
      resume (0, TARGET_SIGNAL_0);
2430
 
      prepare_to_wait (ecs);
2431
 
      return 1;
2432
 
    }
 
2655
      if (!ecs->random_signal)
 
2656
        {
 
2657
          /* Catchpoint hit.  */
 
2658
          ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
 
2659
          return 0;
 
2660
        }
 
2661
    }
 
2662
 
 
2663
  /* If no catchpoint triggered for this, then keep going.  */
 
2664
  ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
 
2665
  keep_going (ecs);
 
2666
  return 1;
2433
2667
}
2434
2668
 
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;
2449
2683
 
 
2684
  if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
 
2685
    {
 
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.
 
2689
 
 
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.  */
 
2695
      if (debug_infrun)
 
2696
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
 
2697
      prepare_to_wait (ecs);
 
2698
      return;
 
2699
    }
 
2700
 
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)
2453
2703
    {
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 ();
2485
2735
 
2486
 
  if (ecs->ws.kind != TARGET_WAITKIND_IGNORE)
 
2736
  breakpoint_retire_moribund ();
 
2737
 
 
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
 
2747
     stack.  */
 
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))
2487
2752
    {
2488
 
      breakpoint_retire_moribund ();
 
2753
      struct regcache *regcache = get_thread_regcache (ecs->ptid);
2489
2754
 
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.  */
2496
 
      if (!non_stop)
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)))
 
2757
        {
 
2758
          if (debug_infrun)
 
2759
            fprintf_unfiltered (gdb_stdlog,
 
2760
                                "infrun: Treating signal as SIGTRAP\n");
 
2761
          ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
 
2762
        }
2501
2763
    }
2502
2764
 
 
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.  */
 
2771
  if (!non_stop)
 
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);
 
2776
 
2503
2777
  switch (infwait_state)
2504
2778
    {
2505
2779
    case infwait_thread_hop_state:
2576
2850
             dynamically loaded objects (among other things).  */
2577
2851
          if (stop_on_solib_events)
2578
2852
            {
 
2853
              /* Make sure we print "Stopped due to solib-event" in
 
2854
                 normal_stop.  */
 
2855
              stop_print_frame = 1;
 
2856
 
2579
2857
              stop_stepping (ecs);
2580
2858
              return;
2581
2859
            }
2613
2891
      if (debug_infrun)
2614
2892
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
2615
2893
      inferior_ptid = ecs->ptid;
 
2894
      set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
 
2895
      set_current_program_space (current_inferior ()->pspace);
 
2896
      handle_vfork_child_exec_or_exit (0);
2616
2897
      target_terminal_ours ();  /* Must do this before mourn anyway */
2617
2898
      print_stop_reason (EXITED, ecs->ws.value.integer);
2618
2899
 
2631
2912
      if (debug_infrun)
2632
2913
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2633
2914
      inferior_ptid = ecs->ptid;
 
2915
      set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
 
2916
      set_current_program_space (current_inferior ()->pspace);
 
2917
      handle_vfork_child_exec_or_exit (0);
2634
2918
      stop_print_frame = 0;
2635
2919
      target_terminal_ours ();  /* Must do this before mourn anyway */
2636
2920
 
2687
2971
 
2688
2972
      stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2689
2973
 
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);
2691
2977
 
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
 
2981
         bpstat.  */
 
2982
      ecs->random_signal = !bpstat_causes_stop (ecs->event_thread->stop_bpstat);
2693
2983
 
2694
2984
      /* If no catchpoint triggered for this, then keep going.  */
2695
2985
      if (ecs->random_signal)
2696
2986
        {
 
2987
          ptid_t parent;
 
2988
          ptid_t child;
2697
2989
          int should_resume;
 
2990
          int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
2698
2991
 
2699
2992
          ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2700
2993
 
2701
2994
          should_resume = follow_fork ();
2702
2995
 
 
2996
          parent = ecs->ptid;
 
2997
          child = ecs->ws.value.related_pid;
 
2998
 
 
2999
          /* In non-stop mode, also resume the other branch.  */
 
3000
          if (non_stop && !detach_fork)
 
3001
            {
 
3002
              if (follow_child)
 
3003
                switch_to_thread (parent);
 
3004
              else
 
3005
                switch_to_thread (child);
 
3006
 
 
3007
              ecs->event_thread = inferior_thread ();
 
3008
              ecs->ptid = inferior_ptid;
 
3009
              keep_going (ecs);
 
3010
            }
 
3011
 
 
3012
          if (follow_child)
 
3013
            switch_to_thread (child);
 
3014
          else
 
3015
            switch_to_thread (parent);
 
3016
 
2703
3017
          ecs->event_thread = inferior_thread ();
2704
3018
          ecs->ptid = inferior_ptid;
2705
3019
 
2712
3026
      ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2713
3027
      goto process_event_stop_test;
2714
3028
 
 
3029
    case TARGET_WAITKIND_VFORK_DONE:
 
3030
      /* Done with the shared memory region.  Re-insert breakpoints in
 
3031
         the parent, and keep going.  */
 
3032
 
 
3033
      if (debug_infrun)
 
3034
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORK_DONE\n");
 
3035
 
 
3036
      if (!ptid_equal (ecs->ptid, inferior_ptid))
 
3037
        context_switch (ecs->ptid);
 
3038
 
 
3039
      current_inferior ()->waiting_for_vfork_done = 0;
 
3040
      current_inferior ()->pspace->breakpoints_not_allowed = 0;
 
3041
      /* This also takes care of reinserting breakpoints in the
 
3042
         previously locked inferior.  */
 
3043
      keep_going (ecs);
 
3044
      return;
 
3045
 
2715
3046
    case TARGET_WAITKIND_EXECD:
2716
3047
      if (debug_infrun)
2717
3048
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
2724
3055
 
2725
3056
      stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2726
3057
 
 
3058
      /* Do whatever is necessary to the parent branch of the vfork.  */
 
3059
      handle_vfork_child_exec_or_exit (1);
 
3060
 
2727
3061
      /* This causes the eventpoints and symbol table to be reset.
2728
3062
         Must do this now, before trying to determine whether to
2729
3063
         stop.  */
2730
3064
      follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
2731
3065
 
2732
 
      ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
 
3066
      ecs->event_thread->stop_bpstat
 
3067
        = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
 
3068
                              stop_pc, ecs->ptid);
2733
3069
      ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2734
3070
 
2735
3071
      /* Note that this may be referenced from inside
2753
3089
      if (debug_infrun)
2754
3090
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2755
3091
      /* Getting the current syscall number */
2756
 
      if (deal_with_syscall_event (ecs) != 0)
 
3092
      if (handle_syscall_event (ecs) != 0)
2757
3093
        return;
2758
3094
      goto process_event_stop_test;
2759
 
      break;
2760
3095
 
2761
3096
      /* Before examining the threads further, step this thread to
2762
3097
         get it entirely out of the syscall.  (We get notice of the
2766
3101
    case TARGET_WAITKIND_SYSCALL_RETURN:
2767
3102
      if (debug_infrun)
2768
3103
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2769
 
      if (deal_with_syscall_event (ecs) != 0)
 
3104
      if (handle_syscall_event (ecs) != 0)
2770
3105
        return;
2771
3106
      goto process_event_stop_test;
2772
 
      break;
2773
3107
 
2774
3108
    case TARGET_WAITKIND_STOPPED:
2775
3109
      if (debug_infrun)
2783
3117
      print_stop_reason (NO_HISTORY, 0);
2784
3118
      stop_stepping (ecs);
2785
3119
      return;
2786
 
 
2787
 
      /* We had an event in the inferior, but we are not interested
2788
 
         in handling it at this level. The lower layers have already
2789
 
         done what needs to be done, if anything.
2790
 
 
2791
 
         One of the possible circumstances for this is when the
2792
 
         inferior produces output for the console. The inferior has
2793
 
         not stopped, and we are ignoring the event.  Another possible
2794
 
         circumstance is any event which the lower level knows will be
2795
 
         reported multiple times without an intervening resume.  */
2796
 
    case TARGET_WAITKIND_IGNORE:
2797
 
      if (debug_infrun)
2798
 
        fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
2799
 
      prepare_to_wait (ecs);
2800
 
      return;
2801
3120
    }
2802
3121
 
2803
3122
  if (ecs->new_thread_event)
2845
3164
    {
2846
3165
      struct regcache *regcache = get_thread_regcache (ecs->ptid);
2847
3166
      struct gdbarch *gdbarch = get_regcache_arch (regcache);
 
3167
      struct cleanup *old_chain = save_inferior_ptid ();
 
3168
 
 
3169
      inferior_ptid = ecs->ptid;
2848
3170
 
2849
3171
      fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
2850
3172
                          paddress (gdbarch, stop_pc));
2861
3183
            fprintf_unfiltered (gdb_stdlog,
2862
3184
                                "infrun: (no data address available)\n");
2863
3185
        }
 
3186
 
 
3187
      do_cleanups (old_chain);
2864
3188
    }
2865
3189
 
2866
3190
  if (stepping_past_singlestep_breakpoint)
2937
3261
  if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2938
3262
    {
2939
3263
      int thread_hop_needed = 0;
 
3264
      struct address_space *aspace = 
 
3265
        get_regcache_aspace (get_thread_regcache (ecs->ptid));
2940
3266
 
2941
3267
      /* Check if a regular breakpoint has been hit before checking
2942
3268
         for a potential single step breakpoint. Otherwise, GDB will
2943
3269
         not see this breakpoint hit when stepping onto breakpoints.  */
2944
 
      if (regular_breakpoint_inserted_here_p (stop_pc))
 
3270
      if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
2945
3271
        {
2946
3272
          ecs->random_signal = 0;
2947
 
          if (!breakpoint_thread_match (stop_pc, ecs->ptid))
 
3273
          if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
2948
3274
            thread_hop_needed = 1;
2949
3275
        }
2950
3276
      else if (singlestep_breakpoints_inserted_p)
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.  */
3217
3543
 
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
3227
 
     stack.
3228
 
 
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)
3240
3547
    {
3288
3595
        }
3289
3596
 
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);
3292
 
      
 
3598
      ecs->event_thread->stop_bpstat
 
3599
        = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
 
3600
                              stop_pc, ecs->ptid);
 
3601
 
3293
3602
      /* Following in case break condition called a
3294
3603
         function.  */
3295
3604
      stop_print_frame = 1;
3296
3605
 
 
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
 
3612
         set.  */
 
3613
 
 
3614
      if (debug_infrun
 
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");
 
3620
 
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
3317
3641
      if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
3318
3642
        ecs->random_signal
3319
3643
          = !(bpstat_explains_signal (ecs->event_thread->stop_bpstat)
 
3644
              || stopped_by_watchpoint
3320
3645
              || ecs->event_thread->trap_expected
3321
3646
              || (ecs->event_thread->step_range_end
3322
3647
                  && ecs->event_thread->step_resume_breakpoint == NULL));
3750
4075
      return;
3751
4076
    }
3752
4077
 
 
4078
  /* Re-fetch current thread's frame in case the code above caused
 
4079
     the frame cache to be re-initialized, making our FRAME variable
 
4080
     a dangling pointer.  */
 
4081
  frame = get_current_frame ();
 
4082
 
3753
4083
  /* If stepping through a line, keep going if still within it.
3754
4084
 
3755
4085
     Note that step_range_end is the address of the first instruction
3820
4150
          struct symtab_and_line sr_sal;
3821
4151
          init_sal (&sr_sal);
3822
4152
          sr_sal.pc = pc_after_resolver;
 
4153
          sr_sal.pspace = get_frame_program_space (frame);
3823
4154
 
3824
4155
          insert_step_resume_breakpoint_at_sal (gdbarch,
3825
4156
                                                sr_sal, null_frame_id);
3860
4191
     "outermost" function.  This could be fixed by marking
3861
4192
     outermost frames as !stack_p,code_p,special_p.  Then the
3862
4193
     initial outermost frame, before sp was valid, would
3863
 
     have code_addr == &_start.  See the commend in frame_id_eq
 
4194
     have code_addr == &_start.  See the comment in frame_id_eq
3864
4195
     for more.  */
3865
4196
  if (!frame_id_eq (get_stack_frame_id (frame),
3866
4197
                    ecs->event_thread->step_stack_frame_id)
3930
4261
              /* Normal function call return (static or dynamic).  */
3931
4262
              init_sal (&sr_sal);
3932
4263
              sr_sal.pc = ecs->stop_func_start;
3933
 
                  insert_step_resume_breakpoint_at_sal (gdbarch,
3934
 
                                                        sr_sal, null_frame_id);
 
4264
              sr_sal.pspace = get_frame_program_space (frame);
 
4265
              insert_step_resume_breakpoint_at_sal (gdbarch,
 
4266
                                                    sr_sal, null_frame_id);
3935
4267
            }
3936
4268
          else
3937
4269
            insert_step_resume_breakpoint_at_caller (frame);
3956
4288
          struct symtab_and_line sr_sal;
3957
4289
          init_sal (&sr_sal);
3958
4290
          sr_sal.pc = ecs->stop_func_start;
 
4291
          sr_sal.pspace = get_frame_program_space (frame);
3959
4292
 
3960
4293
          insert_step_resume_breakpoint_at_sal (gdbarch,
3961
4294
                                                sr_sal, null_frame_id);
3973
4306
        struct symtab_and_line tmp_sal;
3974
4307
 
3975
4308
        tmp_sal = find_pc_line (ecs->stop_func_start, 0);
 
4309
        tmp_sal.pspace = get_frame_program_space (frame);
3976
4310
        if (tmp_sal.line != 0)
3977
4311
          {
3978
4312
            if (execution_direction == EXEC_REVERSE)
4002
4336
          struct symtab_and_line sr_sal;
4003
4337
          init_sal (&sr_sal);
4004
4338
          sr_sal.pc = ecs->stop_func_start;
 
4339
          sr_sal.pspace = get_frame_program_space (frame);
4005
4340
          insert_step_resume_breakpoint_at_sal (gdbarch,
4006
4341
                                                sr_sal, null_frame_id);
4007
4342
        }
4039
4374
          struct symtab_and_line sr_sal;
4040
4375
          init_sal (&sr_sal);
4041
4376
          sr_sal.pc = ecs->stop_func_start;
 
4377
          sr_sal.pspace = get_frame_program_space (frame);
4042
4378
          insert_step_resume_breakpoint_at_sal (gdbarch, 
4043
4379
                                                sr_sal, null_frame_id);
4044
4380
          keep_going (ecs);
4067
4403
          init_sal (&sr_sal);   /* initialize to zeroes */
4068
4404
          sr_sal.pc = real_stop_pc;
4069
4405
          sr_sal.section = find_pc_overlay (sr_sal.pc);
 
4406
          sr_sal.pspace = get_frame_program_space (frame);
4070
4407
 
4071
4408
          /* Do not specify what the fp should be when we stop since
4072
4409
             on some machines the prologue is where the new fp value
4346
4683
      init_sal (&sr_sal);       /* initialize to zeroes */
4347
4684
      sr_sal.pc = ecs->stop_func_start;
4348
4685
      sr_sal.section = find_pc_overlay (ecs->stop_func_start);
 
4686
      sr_sal.pspace = get_frame_program_space (get_current_frame ());
4349
4687
 
4350
4688
      /* Do not specify what the fp should be when we stop since on
4351
4689
         some machines the prologue is where the new fp value is
4437
4775
  gdbarch = get_frame_arch (return_frame);
4438
4776
  sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
4439
4777
  sr_sal.section = find_pc_overlay (sr_sal.pc);
 
4778
  sr_sal.pspace = get_frame_program_space (return_frame);
4440
4779
 
4441
4780
  insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
4442
4781
                                        get_stack_frame_id (return_frame));
4473
4812
  sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
4474
4813
                                        frame_unwind_caller_pc (next_frame));
4475
4814
  sr_sal.section = find_pc_overlay (sr_sal.pc);
 
4815
  sr_sal.pspace = frame_unwind_program_space (next_frame);
4476
4816
 
4477
4817
  insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
4478
4818
                                        frame_unwind_caller_id (next_frame));
4517
4857
static void
4518
4858
keep_going (struct execution_control_state *ecs)
4519
4859
{
 
4860
  /* Make sure normal_stop is called if we get a QUIT handled before
 
4861
     reaching resume.  */
 
4862
  struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
 
4863
 
4520
4864
  /* Save the pc before execution, to compare with pc after stop.  */
4521
4865
  ecs->event_thread->prev_pc
4522
4866
    = regcache_read_pc (get_thread_regcache (ecs->ptid));
4530
4874
      /* We took a signal (which we are supposed to pass through to
4531
4875
         the inferior, else we'd not get here) and we haven't yet
4532
4876
         gotten our trap.  Simply continue.  */
 
4877
 
 
4878
      discard_cleanups (old_cleanups);
4533
4879
      resume (currently_stepping (ecs->event_thread),
4534
4880
              ecs->event_thread->stop_signal);
4535
4881
    }
4568
4914
            }
4569
4915
          if (e.reason < 0)
4570
4916
            {
 
4917
              exception_print (gdb_stderr, e);
4571
4918
              stop_stepping (ecs);
4572
4919
              return;
4573
4920
            }
4591
4938
          && !signal_program[ecs->event_thread->stop_signal])
4592
4939
        ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
4593
4940
 
 
4941
      discard_cleanups (old_cleanups);
4594
4942
      resume (currently_stepping (ecs->event_thread),
4595
4943
              ecs->event_thread->stop_signal);
4596
4944
    }
4976
5324
           Delete any breakpoint that is to be deleted at the next stop.  */
4977
5325
        breakpoint_auto_delete (inferior_thread ()->stop_bpstat);
4978
5326
    }
 
5327
 
 
5328
  /* Try to get rid of automatically added inferiors that are no
 
5329
     longer needed.  Keeping those around slows down things linearly.
 
5330
     Note that this never removes the current inferior.  */
 
5331
  prune_inferiors ();
4979
5332
}
4980
5333
 
4981
5334
static int
6047
6400
                        show_follow_fork_mode_string,
6048
6401
                        &setlist, &showlist);
6049
6402
 
 
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\
 
6409
\n\
 
6410
follow-exec-mode can be:\n\
 
6411
\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\
 
6415
inferior.\n\
 
6416
\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\
 
6421
\n\
 
6422
By default, the debugger will use the same inferior."),
 
6423
                        NULL,
 
6424
                        show_follow_exec_mode_string,
 
6425
                        &setlist, &showlist);
 
6426
 
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."), _("\
6105
6482
                        set_exec_direction_func, show_exec_direction_func,
6106
6483
                        &setlist, &showlist);
6107
6484
 
 
6485
  /* Set/show detach-on-fork: user-settable mode.  */
 
6486
 
 
6487
  add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
 
6488
Set whether gdb will detach the child of a fork."), _("\
 
6489
Show whether gdb will detach the child of a fork."), _("\
 
6490
Tells gdb whether to detach the child of a fork."),
 
6491
                           NULL, NULL, &setlist, &showlist);
 
6492
 
6108
6493
  /* ptid initializations */
6109
6494
  null_ptid = ptid_build (0, 0, 0);
6110
6495
  minus_one_ptid = ptid_build (-1, 0, 0);