]> Git Repo - binutils.git/blobdiff - gdb/breakpoint.c
* win32-nat.c (do_initial_win32_stuff): Set inferior_ptid.
[binutils.git] / gdb / breakpoint.c
index a81f40dc45fc1a42515fa9c62e2c3e563aac2d79..6e863d7f4aecfa9bd1d5a4ac62c6c6baa58d679e 100644 (file)
@@ -104,7 +104,7 @@ static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
                                             enum bptype bptype);
 
-static void describe_other_breakpoints (CORE_ADDR, asection *, int);
+static void describe_other_breakpoints (CORE_ADDR, struct obj_section *, int);
 
 static void breakpoints_info (char *, int);
 
@@ -401,7 +401,7 @@ set_breakpoint_count (int num)
 {
   breakpoint_count = num;
   set_internalvar (lookup_internalvar ("bpnum"),
-                  value_from_longest (builtin_type_int, (LONGEST) num));
+                  value_from_longest (builtin_type_int32, (LONGEST) num));
 }
 
 /* Used in run_command to zero the hit count when a new run starts. */
@@ -1285,7 +1285,7 @@ insert_breakpoints (void)
 
   update_global_location_list (1);
 
-  if (!always_inserted_mode && target_has_execution)
+  if (!breakpoints_always_inserted_mode () && target_has_execution)
     /* update_global_location_list does not insert breakpoints
        when always_inserted_mode is not enabled.  Explicitly
        insert them now.  */
@@ -1665,6 +1665,13 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
              val = 0;
            }
        }
+
+      /* In some cases, we might not be able to remove a breakpoint
+        in a shared library that has already been removed, but we
+        have not yet processed the shlib unload event.  */
+      if (val && solib_address (b->address))
+       val = 0;
+
       if (val)
        return val;
       b->inserted = (is == mark_inserted);
@@ -1743,7 +1750,8 @@ breakpoint_init_inferior (enum inf_context context)
   struct bp_location *bpt;
 
   ALL_BP_LOCATIONS (bpt)
-    bpt->inserted = 0;
+    if (bpt->owner->enable_state != bp_permanent)
+      bpt->inserted = 0;
 
   ALL_BREAKPOINTS_SAFE (b, temp)
   {
@@ -2130,31 +2138,27 @@ cleanup_executing_breakpoints (void *ignore)
 /* Execute all the commands associated with all the breakpoints at this
    location.  Any of these commands could cause the process to proceed
    beyond this point, etc.  We look out for such changes by checking
-   the global "breakpoint_proceeded" after each command.  */
+   the global "breakpoint_proceeded" after each command.
 
-void
-bpstat_do_actions (bpstat *bsp)
+   Returns true if a breakpoint command resumed the inferior.  In that
+   case, it is the caller's responsibility to recall it again with the
+   bpstat of the current thread.  */
+
+static int
+bpstat_do_actions_1 (bpstat *bsp)
 {
   bpstat bs;
   struct cleanup *old_chain;
+  int again = 0;
 
   /* Avoid endless recursion if a `source' command is contained
      in bs->commands.  */
   if (executing_breakpoint_commands)
-    return;
+    return 0;
 
   executing_breakpoint_commands = 1;
   old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
 
-top:
-  /* Note that (as of this writing), our callers all appear to
-     be passing us the address of global stop_bpstat.  And, if
-     our calls to execute_control_command cause the inferior to
-     proceed, that global (and hence, *bsp) will change.
-
-     We must be careful to not touch *bsp unless the inferior
-     has not proceeded. */
-
   /* This pointer will iterate over the list of bpstat's. */
   bs = *bsp;
 
@@ -2194,30 +2198,46 @@ top:
       if (breakpoint_proceeded)
        {
          if (target_can_async_p ())
-         /* If we are in async mode, then the target might
-            be still running, not stopped at any breakpoint,
-            so nothing for us to do here -- just return to
-            the event loop.  */
-           break;
+           /* If we are in async mode, then the target might be still
+              running, not stopped at any breakpoint, so nothing for
+              us to do here -- just return to the event loop.  */
+           ;
          else
            /* In sync mode, when execute_control_command returns
               we're already standing on the next breakpoint.
-              Breakpoint commands for that stop were not run,
-              since execute_command does not run breakpoint
-              commands -- only command_line_handler does, but
-              that one is not involved in execution of breakpoint
-              commands.  So, we can now execute breakpoint commands.
-              There's an implicit assumption that we're called with
-              stop_bpstat, so our parameter is the new bpstat to
-              handle.  
-              It should be noted that making execute_command do
-              bpstat actions is not an option -- in this case we'll
-              have recursive invocation of bpstat for each breakpoint
-              with a command, and can easily blow up GDB stack.  */
-           goto top;
+              Breakpoint commands for that stop were not run, since
+              execute_command does not run breakpoint commands --
+              only command_line_handler does, but that one is not
+              involved in execution of breakpoint commands.  So, we
+              can now execute breakpoint commands.  It should be
+              noted that making execute_command do bpstat actions is
+              not an option -- in this case we'll have recursive
+              invocation of bpstat for each breakpoint with a
+              command, and can easily blow up GDB stack.  Instead, we
+              return true, which will trigger the caller to recall us
+              with the new stop_bpstat.  */
+           again = 1;
+         break;
        }
     }
   do_cleanups (old_chain);
+  return again;
+}
+
+void
+bpstat_do_actions (void)
+{
+  /* Do any commands attached to breakpoint we are stopped at.  */
+  while (!ptid_equal (inferior_ptid, null_ptid)
+        && target_has_execution
+        && !is_exited (inferior_ptid)
+        && !is_executing (inferior_ptid))
+    /* Since in sync mode, bpstat_do_actions may resume the inferior,
+       and only return when it is stopped at the next breakpoint, we
+       keep doing breakpoint actions until it returns false to
+       indicate the inferior was not resumed.  */
+    if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
+      break;
 }
 
 /* Print out the (old or new) value associated with a watchpoint.  */
@@ -3034,6 +3054,7 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
   /* Pointer to the last thing in the chain currently.  */
   bpstat bs = root_bs;
   int ix;
+  int need_remove_insert;
 
   ALL_BP_LOCATIONS (bl)
   {
@@ -3081,7 +3102,8 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
        /* We will stop here */
        if (b->disposition == disp_disable)
          {
-           b->enable_state = bp_disabled;
+           if (b->enable_state != bp_permanent)
+             b->enable_state = bp_disabled;
            update_global_location_list (0);
          }
        if (b->silent)
@@ -3125,6 +3147,7 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
     if (bs->stop)
       break;
 
+  need_remove_insert = 0;
   if (bs == NULL)
     for (bs = root_bs->next; bs != NULL; bs = bs->next)
       if (!bs->stop
@@ -3137,11 +3160,15 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
             location is no longer used by the watchpoint.  Prevent
             further code from trying to use it.  */
          bs->breakpoint_at = NULL;
-         remove_breakpoints ();
-         insert_breakpoints ();
-         break;
+         need_remove_insert = 1;
        }
 
+  if (need_remove_insert)
+    {
+      remove_breakpoints ();
+      insert_breakpoints ();
+    }
+
   return root_bs->next;
 }
 \f
@@ -4010,7 +4037,7 @@ breakpoint_1 (int bnum, int allflag)
       /* Compare against (CORE_ADDR)-1 in case some compiler decides
         that a comparison of an unsigned with -1 is always false.  */
       if (last_addr != (CORE_ADDR) -1 && !server_command)
-       set_next_address (last_addr);
+       set_next_address (current_gdbarch, last_addr);
     }
 
   /* FIXME? Should this be moved up so that it is only called when
@@ -4041,7 +4068,8 @@ maintenance_info_breakpoints (char *bnum_exp, int from_tty)
 }
 
 static int
-breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
+breakpoint_has_pc (struct breakpoint *b,
+                  CORE_ADDR pc, struct obj_section *section)
 {
   struct bp_location *bl = b->loc;
   for (; bl; bl = bl->next)
@@ -4056,7 +4084,8 @@ breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
 /* Print a message describing any breakpoints set at PC.  */
 
 static void
-describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
+describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
+                           int thread)
 {
   int others = 0;
   struct breakpoint *b;
@@ -4146,7 +4175,7 @@ breakpoint_address_is_meaningful (struct breakpoint *bpt)
    that one the official one, and the rest as duplicates.  */
 
 static void
-check_duplicates_for (CORE_ADDR address, asection *section)
+check_duplicates_for (CORE_ADDR address, struct obj_section *section)
 {
   struct bp_location *b;
   int count = 0;
@@ -4528,12 +4557,12 @@ delete_longjmp_breakpoint (int thread)
 }
 
 static void
-create_overlay_event_breakpoint (char *func_name)
+create_overlay_event_breakpoint_1 (char *func_name, struct objfile *objfile)
 {
   struct breakpoint *b;
   struct minimal_symbol *m;
 
-  if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
+  if ((m = lookup_minimal_symbol_text (func_name, objfile)) == NULL)
     return;
  
   b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), 
@@ -4553,6 +4582,14 @@ create_overlay_event_breakpoint (char *func_name)
   update_global_location_list (1);
 }
 
+static void
+create_overlay_event_breakpoint (char *func_name)
+{
+  struct objfile *objfile;
+  ALL_OBJFILES (objfile)
+    create_overlay_event_breakpoint_1 (func_name, objfile);
+}
+
 void
 enable_overlay_breakpoints (void)
 {
@@ -5066,6 +5103,34 @@ add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
   set_breakpoint_location_function (loc);
   return loc;
 }
+\f
+
+/* Return 1 if LOC is pointing to a permanent breakpoint, 
+   return 0 otherwise.  */
+
+static int
+bp_loc_is_permanent (struct bp_location *loc)
+{
+  int len;
+  CORE_ADDR addr;
+  const gdb_byte *brk;
+  gdb_byte *target_mem;
+
+  gdb_assert (loc != NULL);
+
+  addr = loc->address;
+  brk = gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &len);
+
+  target_mem = alloca (len);
+
+  if (target_read_memory (loc->address, target_mem, len) == 0
+      && memcmp (target_mem, brk, len) == 0)
+    return 1;
+
+  return 0;
+}
+
+
 
 /* Create a breakpoint with SAL as location.  Use ADDR_STRING
    as textual description of the location, and COND_STRING
@@ -5120,6 +5185,9 @@ create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
          loc = add_location_to_breakpoint (b, type, &sal);
        }
 
+      if (bp_loc_is_permanent (loc))
+       make_breakpoint_permanent (b);
+
       if (b->cond_string)
        {
          char *arg = b->cond_string;
@@ -5721,7 +5789,7 @@ resolve_sal_pc (struct symtab_and_line *sal)
          if (sym != NULL)
            {
              fixup_symbol_section (sym, sal->symtab->objfile);
-             sal->section = SYMBOL_BFD_SECTION (sym);
+             sal->section = SYMBOL_OBJ_SECTION (sym);
            }
          else
            {
@@ -5734,7 +5802,7 @@ resolve_sal_pc (struct symtab_and_line *sal)
 
              msym = lookup_minimal_symbol_by_pc (sal->pc);
              if (msym)
-               sal->section = SYMBOL_BFD_SECTION (msym);
+               sal->section = SYMBOL_OBJ_SECTION (msym);
            }
        }
     }
@@ -6258,7 +6326,8 @@ until_break_command (char *arg, int from_tty, int anywhere)
       args->breakpoint2 = breakpoint2;
 
       discard_cleanups (old_chain);
-      add_continuation (until_break_command_continuation, args,
+      add_continuation (inferior_thread (),
+                       until_break_command_continuation, args,
                        xfree);
     }
   else
@@ -7070,7 +7139,9 @@ update_global_location_list (int should_insert)
       check_duplicates (b);
     }
 
-  if (always_inserted_mode && should_insert && target_has_execution)
+  if (breakpoints_always_inserted_mode ()
+      && should_insert
+      && target_has_execution)
     insert_breakpoint_locations ();
 }
 
@@ -7189,9 +7260,6 @@ delete_breakpoint (struct breakpoint *bpt)
      in event-top.c won't do anything, and temporary breakpoints
      with commands won't work.  */
 
-  /* Clear the current context.  */
-  bpstat_remove_breakpoint (stop_bpstat, bpt);
-  /* And from all threads.  */
   iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
 
   /* Now that breakpoint is removed from breakpoint
@@ -7374,6 +7442,10 @@ update_breakpoint_locations (struct breakpoint *b,
        b->line_number = sals.sals[i].line;
     }
 
+  /* Update locations of permanent breakpoints.  */
+  if (b->enable_state == bp_permanent)
+    make_breakpoint_permanent (b);
+
   /* If possible, carry over 'disable' status from existing breakpoints.  */
   {
     struct bp_location *e = existing_locations;
This page took 0.037931 seconds and 4 git commands to generate.