* mipsread.c: Clean up some white space.
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 92419ee21902f42f9608c41238cc4c12530ce1cb..6ae795bb2b8fab3440df5754d9d29f2ca7598e1d 100644 (file)
@@ -17,9 +17,8 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-#include <stdio.h>
-#include <ctype.h>
 #include "defs.h"
+#include <ctype.h>
 #include "symtab.h"
 #include "frame.h"
 #include "breakpoint.h"
@@ -34,6 +33,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "target.h"
 #include "language.h"
 #include <string.h>
+#include "demangle.h"
 
 /* local function prototypes */
 
@@ -106,14 +106,11 @@ check_duplicates PARAMS ((CORE_ADDR));
 static void
 describe_other_breakpoints PARAMS ((CORE_ADDR));
 
-static void
-watchpoints_info PARAMS ((char *, int));
-
 static void
 breakpoints_info PARAMS ((char *, int));
 
 static void
-breakpoint_1 PARAMS ((int, enum bptype, int));
+breakpoint_1 PARAMS ((int, int));
 
 static bpstat
 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
@@ -264,18 +261,18 @@ condition_command (arg, from_tty)
       {
        if (b->cond)
          {
-           free (b->cond);
+           free ((PTR)b->cond);
            b->cond = 0;
          }
        if (b->cond_string != NULL)
-         free (b->cond_string);
+         free ((PTR)b->cond_string);
 
        if (*p == 0)
          {
            b->cond = 0;
            b->cond_string = NULL;
            if (from_tty)
-             printf ("Breakpoint %d now unconditional.\n", bnum);
+             printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
          }
        else
          {
@@ -320,11 +317,8 @@ commands_command (arg, from_tty)
     if (b->number == bnum)
       {
        if (from_tty && input_from_terminal_p ())
-         {
-           printf ("Type commands for when breakpoint %d is hit, one per line.\n\
+         printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
 End with a line saying just \"end\".\n", bnum);
-           fflush (stdout);
-         }
        l = read_command_lines ();
        free_command_lines (&b->commands);
        b->commands = l;
@@ -394,8 +388,8 @@ read_memory_nobpt (memaddr, myaddr, len)
              bptlen -= (membpt + bptlen) - (memaddr + len);
            }
 
-         bcopy (b->shadow_contents + bptoffset,
-                myaddr + membpt - memaddr, bptlen);
+         memcpy (myaddr + membpt - memaddr, 
+                 b->shadow_contents + bptoffset, bptlen);
 
          if (membpt > memaddr)
            {
@@ -557,7 +551,7 @@ bpstat_clear (bsp)
       q = p->next;
       if (p->old_val != NULL)
        value_free (p->old_val);
-      free (p);
+      free ((PTR)p);
       p = q;
     }
   *bsp = NULL;
@@ -580,7 +574,7 @@ bpstat_copy (bs)
   for (; bs != NULL; bs = bs->next)
     {
       tmp = (bpstat) xmalloc (sizeof (*tmp));
-      bcopy (bs, tmp, sizeof (*tmp));
+      memcpy (tmp, bs, sizeof (*tmp));
       if (p == NULL)
        /* This is the first thing in the chain.  */
        retval = tmp;
@@ -998,9 +992,8 @@ bpstat_should_step ()
    is nonzero, process only watchpoints.  */
 
 static void
-breakpoint_1 (bnum, type, allflag)
+breakpoint_1 (bnum, allflag)
      int bnum;
-     enum bptype type;
      int allflag;
 {
   register struct breakpoint *b;
@@ -1035,9 +1028,9 @@ breakpoint_1 (bnum, type, allflag)
 
        printf_filtered ("%-3d %-14s %-4s %-3c ",
                         b->number,
-                        bptypes[b->type],
-                        bpdisps[b->disposition],
-                        bpenables[b->enable]);
+                        bptypes[(int)b->type],
+                        bpdisps[(int)b->disposition],
+                        bpenables[(int)b->enable]);
        switch (b->type)
          {
          case bp_watchpoint:
@@ -1058,7 +1051,8 @@ breakpoint_1 (bnum, type, allflag)
                if (sym)
                  {
                    fputs_filtered ("in ", stdout);
-                   fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
+                   fputs_demangled (SYMBOL_NAME (sym), stdout, 
+                                    DMGL_ANSI | DMGL_PARAMS);
                    fputs_filtered (" at ", stdout);
                  }
                fputs_filtered (b->symtab->filename, stdout);
@@ -1112,26 +1106,14 @@ breakpoints_info (bnum_exp, from_tty)
   if (bnum_exp)
     bnum = parse_and_eval_address (bnum_exp);
 
-  breakpoint_1 (bnum, bp_breakpoint, 0);
+  breakpoint_1 (bnum, 0);
 }
 
-/* ARGSUSED */
-static void
-all_breakpoints_info (bnum_exp, from_tty)
-     char *bnum_exp;
-     int from_tty;
-{
-  int bnum = -1;
-
-  if (bnum_exp)
-    bnum = parse_and_eval_address (bnum_exp);
-
-  breakpoint_1 (bnum, bp_breakpoint, 1);
-}
+#if MAINTENANCE_CMDS
 
 /* ARGSUSED */
 static void
-watchpoints_info (bnum_exp, from_tty)
+maintenance_info_breakpoints (bnum_exp, from_tty)
      char *bnum_exp;
      int from_tty;
 {
@@ -1140,9 +1122,11 @@ watchpoints_info (bnum_exp, from_tty)
   if (bnum_exp)
     bnum = parse_and_eval_address (bnum_exp);
 
-  breakpoint_1 (bnum, bp_watchpoint, 0);
+  breakpoint_1 (bnum, 1);
 }
 
+#endif
+
 /* Print a message describing any breakpoints set at PC.  */
 
 static void
@@ -1226,7 +1210,7 @@ set_raw_breakpoint (sal)
   register struct breakpoint *b, *b1;
 
   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
-  bzero (b, sizeof *b);
+  memset (b, 0, sizeof (*b));
   b->address = sal.pc;
   b->symtab = sal.symtab;
   b->line_number = sal.line;
@@ -1260,17 +1244,10 @@ static void
 create_longjmp_breakpoint(func_name)
      char *func_name;
 {
-  int i;
   struct symtab_and_line sal;
   struct breakpoint *b;
   static int internal_breakpoint_number = -1;
 
-  if (*bpt != NULL)
-    {
-      delete_breakpoint(*bpt);
-      *bpt = NULL;
-    }
-
   if (func_name != NULL)
     {
       struct minimal_symbol *m;
@@ -1310,7 +1287,10 @@ enable_longjmp_breakpoint()
 
   ALL_BREAKPOINTS (b)
     if (b->type == bp_longjmp)
-      b->enable = enabled;
+      {
+       b->enable = enabled;
+       check_duplicates (b->address);
+      }
 }
 
 void
@@ -1319,9 +1299,12 @@ disable_longjmp_breakpoint()
   register struct breakpoint *b;
 
   ALL_BREAKPOINTS (b)
-    if (b->type == bp_longjmp
+    if (   b->type == bp_longjmp
        || b->type == bp_longjmp_resume)
-      b->enable = disabled;
+      {
+       b->enable = disabled;
+       check_duplicates (b->address);
+      }
 }
 
 /* Call this after hitting the longjmp() breakpoint.  Use this to set a new
@@ -1347,6 +1330,7 @@ set_longjmp_resume_breakpoint(pc, frame)
          b->frame = FRAME_FP(frame);
        else
          b->frame = 0;
+       check_duplicates (b->address);
        return;
       }
 }
@@ -1401,6 +1385,12 @@ mention (b)
       if (b->symtab)
        printf_filtered (": file %s, line %d.",
                         b->symtab->filename, b->line_number);
+      break;
+    case bp_until:
+    case bp_finish:
+    case bp_longjmp:
+    case bp_longjmp_resume:
+      break;
     }
   printf_filtered ("\n");
 }
@@ -1563,7 +1553,7 @@ break_command_1 (arg, tempflag, from_tty)
       printf ("Multiple breakpoints were set.\n");
       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
     }
-  free (sals.sals);
+  free ((PTR)sals.sals);
 }
 
 /* Helper function for break_command_1 and disassemble_command.  */
@@ -1668,7 +1658,7 @@ until_break_command (arg, from_tty)
     error ("Couldn't get information on specified line.");
   
   sal = sals.sals[0];
-  free (sals.sals);            /* malloc'd, so freed */
+  free ((PTR)sals.sals);               /* malloc'd, so freed */
   
   if (*arg)
     error ("Junk at end of arguments.");
@@ -1820,7 +1810,7 @@ get_catch_sals (this_level_only)
 
   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
   blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
-  bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
+  memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
 
   while (block != 0)
     {
@@ -1991,7 +1981,7 @@ catch_command_1 (arg, tempflag, from_tty)
       printf ("Multiple breakpoints were set.\n");
       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
     }
-  free (sals.sals);
+  free ((PTR)sals.sals);
 }
 
 #if 0
@@ -2106,7 +2096,7 @@ clear_command (arg, from_tty)
        }
       if (from_tty) putchar ('\n');
     }
-  free (sals.sals);
+  free ((PTR)sals.sals);
 }
 \f
 /* Delete breakpoint in BS if they are `delete' breakpoints.
@@ -2147,11 +2137,11 @@ delete_breakpoint (bpt)
 
   free_command_lines (&bpt->commands);
   if (bpt->cond)
-    free (bpt->cond);
+    free ((PTR)bpt->cond);
   if (bpt->cond_string != NULL)
-    free (bpt->cond_string);
+    free ((PTR)bpt->cond_string);
   if (bpt->addr_string != NULL)
-    free (bpt->addr_string);
+    free ((PTR)bpt->addr_string);
 
   if (xgdb_verbose && bpt->type == bp_breakpoint)
     printf ("breakpoint #%d deleted\n", bpt->number);
@@ -2161,7 +2151,7 @@ delete_breakpoint (bpt)
   for (bs = stop_bpstat; bs; bs = bs->next)
     if (bs->breakpoint_at == bpt)
       bs->breakpoint_at = NULL;
-  free (bpt);
+  free ((PTR)bpt);
 }
 
 static void
@@ -2218,22 +2208,27 @@ breakpoint_re_set_one (bint)
       for (i = 0; i < sals.nelts; i++)
        {
          resolve_sal_pc (&sals.sals[i]);
-         b->symtab = sals.sals[i].symtab;
-         b->line_number = sals.sals[i].line;
-         b->address = sals.sals[i].pc;
-
-         if (b->cond_string != NULL)
+         if (b->symtab != sals.sals[i].symtab
+             || b->line_number != sals.sals[i].line
+             || b->address != sals.sals[i].pc)
            {
-             s = b->cond_string;
-             b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
-           }
+             b->symtab = sals.sals[i].symtab;
+             b->line_number = sals.sals[i].line;
+             b->address = sals.sals[i].pc;
+
+             if (b->cond_string != NULL)
+               {
+                 s = b->cond_string;
+                 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
+               }
          
-         check_duplicates (b->address);
+             check_duplicates (b->address);
 
+             mention (b);
+           }
          b->enable = save_enable;      /* Restore it, this worked. */
-         mention (b);
        }
-      free (sals.sals);
+      free ((PTR)sals.sals);
       break;
     case bp_watchpoint:
       /* FIXME!  This is the wrong thing to do.... */
@@ -2260,11 +2255,22 @@ breakpoint_re_set ()
   static char message1[] = "Error in re-setting breakpoint %d:\n";
   char message[sizeof (message1) + 30 /* slop */];
   
+  /* If we have no current source symtab, and we have any breakpoints,
+     go through the work of making a source context.  */
+  if (current_source_symtab == NULL)
+    {
+      ALL_BREAKPOINTS (b)
+      {
+       select_source_symtab (NULL);
+       break;                          /* We only care if there are any, and
+                                          don't need to do it N times.  */
+      }
+    }
+
   ALL_BREAKPOINTS_SAFE (b, temp)
     {
-      b->symtab = 0;           /* Be sure we don't point to old dead symtab */
       sprintf (message, message1, b->number);  /* Format possible error msg */
-      (void) catch_errors (breakpoint_re_set_one, (char *) b, message);
+      catch_errors (breakpoint_re_set_one, (char *) b, message);
     }
 
   create_longjmp_breakpoint("longjmp");
@@ -2272,8 +2278,12 @@ breakpoint_re_set ()
   create_longjmp_breakpoint("siglongjmp");
   create_longjmp_breakpoint(NULL);
 
+#if 0
+  /* Took this out (temporaliy at least), since it produces an extra 
+     blank line at startup. This messes up the gdbtests. -PB */
   /* Blank line to finish off all those mention() messages we just printed.  */
   printf_filtered ("\n");
+#endif
 }
 \f
 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
@@ -2296,11 +2306,13 @@ set_ignore_count (bptnum, count, from_tty)
        if (!from_tty)
          return;
        else if (count == 0)
-         printf ("Will stop next time breakpoint %d is reached.", bptnum);
+         printf_filtered ("Will stop next time breakpoint %d is reached.",
+                          bptnum);
        else if (count == 1)
-         printf ("Will ignore next crossing of breakpoint %d.", bptnum);
+         printf_filtered ("Will ignore next crossing of breakpoint %d.",
+                          bptnum);
        else
-         printf ("Will ignore next %d crossings of breakpoint %d.",
+         printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
                  count, bptnum);
        return;
       }
@@ -2339,7 +2351,7 @@ ignore_command (args, from_tty)
   set_ignore_count (num,
                    longest_to_int (value_as_long (parse_and_eval (p))),
                    from_tty);
-  printf ("\n");
+  printf_filtered ("\n");
 }
 \f
 /* Call FUNCTION on each of the breakpoints
@@ -2413,7 +2425,14 @@ enable_command (args, from_tty)
   struct breakpoint *bpt;
   if (args == 0)
     ALL_BREAKPOINTS (bpt)
-      enable_breakpoint (bpt);
+      switch (bpt->type)
+       {
+       case bp_breakpoint:
+       case bp_watchpoint:
+         enable_breakpoint (bpt);
+       default:
+         continue;
+       }
   else
     map_breakpoint_numbers (args, enable_breakpoint);
 }
@@ -2425,7 +2444,7 @@ disable_breakpoint (bpt)
   bpt->enable = disabled;
 
   if (xgdb_verbose && bpt->type == bp_breakpoint)
-    printf ("breakpoint #%d disabled\n", bpt->number);
+    printf_filtered ("breakpoint #%d disabled\n", bpt->number);
 
   check_duplicates (bpt->address);
 }
@@ -2439,7 +2458,14 @@ disable_command (args, from_tty)
   register struct breakpoint *bpt;
   if (args == 0)
     ALL_BREAKPOINTS (bpt)
-      disable_breakpoint (bpt);
+      switch (bpt->type)
+       {
+       case bp_breakpoint:
+       case bp_watchpoint:
+         disable_breakpoint (bpt);
+       default:
+         continue;
+       }
   else
     map_breakpoint_numbers (args, disable_breakpoint);
 }
@@ -2503,15 +2529,6 @@ decode_line_spec_1 (string, funfirstline)
   return sals;
 }
 \f
-
-/* Chain containing all defined enable commands.  */
-
-extern struct cmd_list_element 
-  *enablelist, *disablelist,
-  *deletelist, *enablebreaklist;
-
-extern struct cmd_list_element *cmdlist;
-
 void
 _initialize_breakpoint ()
 {
@@ -2645,8 +2662,8 @@ Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
   add_info ("breakpoints", breakpoints_info,
            "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
 The \"Type\" column indicates one of:\n\
-\tbreakpoint     - for normal breakpoints\n\
-\twatchpoint     - for watchpoints\n\
+\tbreakpoint     - normal breakpoint\n\
+\twatchpoint     - watchpoint\n\
 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
 the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
 breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
@@ -2656,15 +2673,17 @@ are set to the address of the last breakpoint listed.\n\n\
 Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set.");
 
-  add_info ("all-breakpoints", all_breakpoints_info,
+#if MAINTENANCE_CMDS
+
+  add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
            "Status of all breakpoints, or breakpoint number NUMBER.\n\
 The \"Type\" column indicates one of:\n\
-\tbreakpoint     - for normal breakpoints\n\
-\twatchpoint     - for watchpoints\n\
-\tlongjmp        - for internal breakpoints to handle stepping through longjmp()\n\
-\tlongjmp resume - for internal breakpoints at the target of longjmp()\n\
-\tuntil          - for internal breakpoints used by the \"until\" command\n\
-\tfinish         - for internal breakpoints used by the \"finish\" command\n\
+\tbreakpoint     - normal breakpoint\n\
+\twatchpoint     - watchpoint\n\
+\tlongjmp        - internal breakpoint used to step through longjmp()\n\
+\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
+\tuntil          - internal breakpoint used by the \"until\" command\n\
+\tfinish         - internal breakpoint used by the \"finish\" command\n\
 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
 the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
 breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
@@ -2672,7 +2691,10 @@ address and file/line number respectively.\n\n\
 Convenience variable \"$_\" and default examine address for \"x\"\n\
 are set to the address of the last breakpoint listed.\n\n\
 Convenience variable \"$bpnum\" contains the number of the last\n\
-breakpoint set.");
+breakpoint set.",
+          &maintenanceinfolist);
+
+#endif /* MAINTENANCE_CMDS */
 
   add_com ("catch", class_breakpoint, catch_command,
          "Set breakpoints to catch exceptions that are raised.\n\
@@ -2691,7 +2713,37 @@ Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
 A watchpoint stops execution of your program whenever the value of\n\
 an expression changes.");
 
-  add_info ("watchpoints", watchpoints_info,
-           "Status of all watchpoints, or watchpoint number NUMBER.\n\
-Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");
+  add_info ("watchpoints", breakpoints_info,
+           "Synonym for ``info breakpoints''.");
 }
+
+#ifdef IBM6000_TARGET
+/* Where should this function go? It is used by AIX only. FIXME. */
+
+/* Breakpoint address relocation used to be done in breakpoint_re_set(). That
+   approach the following problem:
+
+     before running the program, if a file is list, then a breakpoint is
+     set (just the line number), then if we switch into another file and run
+     the program, just a line number as a breakpoint address was not
+     descriptive enough and breakpoint was ending up in a different file's
+     similar line. 
+
+  I don't think any other platform has this breakpoint relocation problem, so this
+  is not an issue for other platforms. */
+   
+void
+fixup_breakpoints (low, high, delta)
+  CORE_ADDR low;
+  CORE_ADDR high;
+  CORE_ADDR delta;
+{
+  struct breakpoint *b;
+
+  ALL_BREAKPOINTS (b)
+    {
+     if (b->address >= low && b->address <= high)
+       b->address += delta;
+    }
+}
+#endif
This page took 0.030997 seconds and 4 git commands to generate.