home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / breakpoint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-10  |  108.2 KB  |  4,075 lines

  1. /* Everything about breakpoints, for GDB.
  2.    Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995
  3.              Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include <ctype.h>
  23. #include "symtab.h"
  24. #include "frame.h"
  25. #include "breakpoint.h"
  26. #include "gdbtypes.h"
  27. #include "expression.h"
  28. #include "gdbcore.h"
  29. #include "gdbcmd.h"
  30. #include "value.h"
  31. #include "ctype.h"
  32. #include "command.h"
  33. #include "inferior.h"
  34. #include "thread.h"
  35. #include "target.h"
  36. #include "language.h"
  37. #include <string.h>
  38. #include "demangle.h"
  39. #include "annotate.h"
  40.  
  41. /* local function prototypes */
  42.  
  43. static void
  44. catch_command_1 PARAMS ((char *, int, int));
  45.  
  46. static void
  47. enable_delete_command PARAMS ((char *, int));
  48.  
  49. static void
  50. enable_delete_breakpoint PARAMS ((struct breakpoint *));
  51.  
  52. static void
  53. enable_once_command PARAMS ((char *, int));
  54.  
  55. static void
  56. enable_once_breakpoint PARAMS ((struct breakpoint *));
  57.  
  58. static void
  59. disable_command PARAMS ((char *, int));
  60.  
  61. static void
  62. enable_command PARAMS ((char *, int));
  63.  
  64. static void
  65. map_breakpoint_numbers PARAMS ((char *,    void (*)(struct breakpoint *)));
  66.  
  67. static void
  68. ignore_command PARAMS ((char *, int));
  69.  
  70. static int
  71. breakpoint_re_set_one PARAMS ((char *));
  72.  
  73. static void
  74. delete_command PARAMS ((char *, int));
  75.  
  76. static void
  77. clear_command PARAMS ((char *, int));
  78.  
  79. static void
  80. catch_command PARAMS ((char *, int));
  81.  
  82. static struct symtabs_and_lines
  83. get_catch_sals PARAMS ((int));
  84.  
  85. static void
  86. watch_command PARAMS ((char *, int));
  87.  
  88. static int
  89. can_use_hardware_watchpoint PARAMS ((struct value *));
  90.  
  91. static void
  92. tbreak_command PARAMS ((char *, int));
  93.  
  94. static void
  95. break_command_1 PARAMS ((char *, int, int));
  96.  
  97. static void
  98. mention PARAMS ((struct breakpoint *));
  99.  
  100. static struct breakpoint *
  101. set_raw_breakpoint PARAMS ((struct symtab_and_line));
  102.  
  103. static void
  104. check_duplicates PARAMS ((CORE_ADDR));
  105.  
  106. static void
  107. describe_other_breakpoints PARAMS ((CORE_ADDR));
  108.  
  109. static void
  110. breakpoints_info PARAMS ((char *, int));
  111.  
  112. static void
  113. breakpoint_1 PARAMS ((int, int));
  114.  
  115. static bpstat
  116. bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
  117.  
  118. static int
  119. breakpoint_cond_eval PARAMS ((char *));
  120.  
  121. static void
  122. cleanup_executing_breakpoints PARAMS ((int));
  123.  
  124. static void
  125. commands_command PARAMS ((char *, int));
  126.  
  127. static void
  128. condition_command PARAMS ((char *, int));
  129.  
  130. static int
  131. get_number PARAMS ((char **));
  132.  
  133. static void
  134. set_breakpoint_count PARAMS ((int));
  135.  
  136. static int
  137. remove_breakpoint PARAMS ((struct breakpoint *));
  138.  
  139. extern int addressprint;        /* Print machine addresses? */
  140.  
  141. /* Are we executing breakpoint commands?  */
  142. static int executing_breakpoint_commands;
  143.  
  144. /* Walk the following statement or block through all breakpoints.
  145.    ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
  146.    breakpoint.  */
  147.  
  148. #define ALL_BREAKPOINTS(b)  for (b = breakpoint_chain; b; b = b->next)
  149.  
  150. #define ALL_BREAKPOINTS_SAFE(b,tmp)    \
  151.     for (b = breakpoint_chain;    \
  152.          b? (tmp=b->next, 1): 0;    \
  153.          b = tmp)
  154.  
  155. /* By default no support for hardware watchpoints is assumed.  */
  156. #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT
  157. #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) 0
  158. #define target_remove_watchpoint(ADDR,LEN,TYPE) -1
  159. #define target_insert_watchpoint(ADDR,LEN,TYPE) -1
  160. #endif
  161.  
  162. #ifndef target_insert_hw_breakpoint
  163. #define target_remove_hw_breakpoint(ADDR,SHADOW) -1
  164. #define target_insert_hw_breakpoint(ADDR,SHADOW) -1
  165. #endif
  166.  
  167. #ifndef target_stopped_data_address
  168. #define target_stopped_data_address() 0
  169. #endif
  170.  
  171. /* True if breakpoint hit counts should be displayed in breakpoint info.  */
  172.  
  173. int show_breakpoint_hit_counts = 1;
  174.  
  175. /* Chain of all breakpoints defined.  */
  176.  
  177. struct breakpoint *breakpoint_chain;
  178.  
  179. /* Number of last breakpoint made.  */
  180.  
  181. static int breakpoint_count;
  182.  
  183. /* Set breakpoint count to NUM.  */
  184.  
  185. static void
  186. set_breakpoint_count (num)
  187.      int num;
  188. {
  189.   breakpoint_count = num;
  190.   set_internalvar (lookup_internalvar ("bpnum"),
  191.            value_from_longest (builtin_type_int, (LONGEST) num));
  192. }
  193.  
  194. /* Used in run_command to zero the hit count when a new run starts. */
  195.  
  196. void
  197. clear_breakpoint_hit_counts ()
  198. {
  199.   struct breakpoint *b;
  200.  
  201.   ALL_BREAKPOINTS (b)
  202.     b->hit_count = 0;
  203. }
  204.  
  205. /* Default address, symtab and line to put a breakpoint at
  206.    for "break" command with no arg.
  207.    if default_breakpoint_valid is zero, the other three are
  208.    not valid, and "break" with no arg is an error.
  209.  
  210.    This set by print_stack_frame, which calls set_default_breakpoint.  */
  211.  
  212. int default_breakpoint_valid;
  213. CORE_ADDR default_breakpoint_address;
  214. struct symtab *default_breakpoint_symtab;
  215. int default_breakpoint_line;
  216.  
  217. /* *PP is a string denoting a breakpoint.  Get the number of the breakpoint.
  218.    Advance *PP after the string and any trailing whitespace.
  219.  
  220.    Currently the string can either be a number or "$" followed by the name
  221.    of a convenience variable.  Making it an expression wouldn't work well
  222.    for map_breakpoint_numbers (e.g. "4 + 5 + 6").  */
  223. static int
  224. get_number (pp)
  225.      char **pp;
  226. {
  227.   int retval;
  228.   char *p = *pp;
  229.  
  230.   if (p == NULL)
  231.     /* Empty line means refer to the last breakpoint.  */
  232.     return breakpoint_count;
  233.   else if (*p == '$')
  234.     {
  235.       /* Make a copy of the name, so we can null-terminate it
  236.      to pass to lookup_internalvar().  */
  237.       char *varname;
  238.       char *start = ++p;
  239.       value_ptr val;
  240.  
  241.       while (isalnum (*p) || *p == '_')
  242.     p++;
  243.       varname = (char *) alloca (p - start + 1);
  244.       strncpy (varname, start, p - start);
  245.       varname[p - start] = '\0';
  246.       val = value_of_internalvar (lookup_internalvar (varname));
  247.       if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
  248.     error (
  249. "Convenience variables used to specify breakpoints must have integer values."
  250.            );
  251.       retval = (int) value_as_long (val);
  252.     }
  253.   else
  254.     {
  255.       if (*p == '-')
  256.     ++p;
  257.       while (*p >= '0' && *p <= '9')
  258.     ++p;
  259.       if (p == *pp)
  260.     /* There is no number here.  (e.g. "cond a == b").  */
  261.     error_no_arg ("breakpoint number");
  262.       retval = atoi (*pp);
  263.     }
  264.   if (!(isspace (*p) || *p == '\0'))
  265.     error ("breakpoint number expected");
  266.   while (isspace (*p))
  267.     p++;
  268.   *pp = p;
  269.   return retval;
  270. }
  271.  
  272. /* condition N EXP -- set break condition of breakpoint N to EXP.  */
  273.  
  274. static void
  275. condition_command (arg, from_tty)
  276.      char *arg;
  277.      int from_tty;
  278. {
  279.   register struct breakpoint *b;
  280.   char *p;
  281.   register int bnum;
  282.  
  283.   if (arg == 0)
  284.     error_no_arg ("breakpoint number");
  285.  
  286.   p = arg;
  287.   bnum = get_number (&p);
  288.  
  289.   ALL_BREAKPOINTS (b)
  290.     if (b->number == bnum)
  291.       {
  292.     if (b->cond)
  293.       {
  294.         free ((PTR)b->cond);
  295.         b->cond = 0;
  296.       }
  297.     if (b->cond_string != NULL)
  298.       free ((PTR)b->cond_string);
  299.  
  300.     if (*p == 0)
  301.       {
  302.         b->cond = 0;
  303.         b->cond_string = NULL;
  304.         if (from_tty)
  305.           printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
  306.       }
  307.     else
  308.       {
  309.         arg = p;
  310.         /* I don't know if it matters whether this is the string the user
  311.            typed in or the decompiled expression.  */
  312.         b->cond_string = savestring (arg, strlen (arg));
  313.         b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
  314.         if (*arg)
  315.           error ("Junk at end of expression");
  316.       }
  317.     breakpoints_changed ();
  318.     return;
  319.       }
  320.  
  321.   error ("No breakpoint number %d.", bnum);
  322. }
  323.  
  324. /* ARGSUSED */
  325. static void
  326. commands_command (arg, from_tty)
  327.      char *arg;
  328.      int from_tty;
  329. {
  330.   register struct breakpoint *b;
  331.   char *p;
  332.   register int bnum;
  333.   struct command_line *l;
  334.  
  335.   /* If we allowed this, we would have problems with when to
  336.      free the storage, if we change the commands currently
  337.      being read from.  */
  338.  
  339.   if (executing_breakpoint_commands)
  340.     error ("Can't use the \"commands\" command among a breakpoint's commands.");
  341.  
  342.   p = arg;
  343.   bnum = get_number (&p);
  344.   if (p && *p)
  345.     error ("Unexpected extra arguments following breakpoint number.");
  346.       
  347.   ALL_BREAKPOINTS (b)
  348.     if (b->number == bnum)
  349.       {
  350.     if (from_tty && input_from_terminal_p ())
  351.       printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
  352. End with a line saying just \"end\".\n", bnum);
  353.     l = read_command_lines ();
  354.     free_command_lines (&b->commands);
  355.     b->commands = l;
  356.     breakpoints_changed ();
  357.     return;
  358.       }
  359.   error ("No breakpoint number %d.", bnum);
  360. }
  361.  
  362. extern int memory_breakpoint_size; /* from mem-break.c */
  363.  
  364. /* Like target_read_memory() but if breakpoints are inserted, return
  365.    the shadow contents instead of the breakpoints themselves.
  366.  
  367.    Read "memory data" from whatever target or inferior we have. 
  368.    Returns zero if successful, errno value if not.  EIO is used
  369.    for address out of bounds.  If breakpoints are inserted, returns
  370.    shadow contents, not the breakpoints themselves.  From breakpoint.c.  */
  371.  
  372. int
  373. read_memory_nobpt (memaddr, myaddr, len)
  374.      CORE_ADDR memaddr;
  375.      char *myaddr;
  376.      unsigned len;
  377. {
  378.   int status;
  379.   struct breakpoint *b;
  380.  
  381.   if (memory_breakpoint_size < 0)
  382.     /* No breakpoints on this machine.  FIXME: This should be
  383.        dependent on the debugging target.  Probably want
  384.        target_insert_breakpoint to return a size, saying how many
  385.        bytes of the shadow contents are used, or perhaps have
  386.        something like target_xfer_shadow.  */
  387.     return target_read_memory (memaddr, myaddr, len);
  388.   
  389.   ALL_BREAKPOINTS (b)
  390.     {
  391.       if (b->type == bp_watchpoint
  392.       || b->type == bp_hardware_watchpoint
  393.       || b->type == bp_read_watchpoint
  394.       || b->type == bp_access_watchpoint
  395.       || !b->inserted)
  396.     continue;
  397.       else if (b->address + memory_breakpoint_size <= memaddr)
  398.     /* The breakpoint is entirely before the chunk of memory
  399.        we are reading.  */
  400.     continue;
  401.       else if (b->address >= memaddr + len)
  402.     /* The breakpoint is entirely after the chunk of memory we
  403.        are reading.  */
  404.     continue;
  405.       else
  406.     {
  407.       /* Copy the breakpoint from the shadow contents, and recurse
  408.          for the things before and after.  */
  409.       
  410.       /* Addresses and length of the part of the breakpoint that
  411.          we need to copy.  */
  412.       CORE_ADDR membpt = b->address;
  413.       unsigned int bptlen = memory_breakpoint_size;
  414.       /* Offset within shadow_contents.  */
  415.       int bptoffset = 0;
  416.       
  417.       if (membpt < memaddr)
  418.         {
  419.           /* Only copy the second part of the breakpoint.  */
  420.           bptlen -= memaddr - membpt;
  421.           bptoffset = memaddr - membpt;
  422.           membpt = memaddr;
  423.         }
  424.  
  425.       if (membpt + bptlen > memaddr + len)
  426.         {
  427.           /* Only copy the first part of the breakpoint.  */
  428.           bptlen -= (membpt + bptlen) - (memaddr + len);
  429.         }
  430.  
  431.       memcpy (myaddr + membpt - memaddr, 
  432.           b->shadow_contents + bptoffset, bptlen);
  433.  
  434.       if (membpt > memaddr)
  435.         {
  436.           /* Copy the section of memory before the breakpoint.  */
  437.           status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
  438.           if (status != 0)
  439.         return status;
  440.         }
  441.  
  442.       if (membpt + bptlen < memaddr + len)
  443.         {
  444.           /* Copy the section of memory after the breakpoint.  */
  445.           status = read_memory_nobpt
  446.         (membpt + bptlen,
  447.          myaddr + membpt + bptlen - memaddr,
  448.          memaddr + len - (membpt + bptlen));
  449.           if (status != 0)
  450.         return status;
  451.         }
  452.       return 0;
  453.     }
  454.     }
  455.   /* Nothing overlaps.  Just call read_memory_noerr.  */
  456.   return target_read_memory (memaddr, myaddr, len);
  457. }
  458.  
  459. /* insert_breakpoints is used when starting or continuing the program.
  460.    remove_breakpoints is used when the program stops.
  461.    Both return zero if successful,
  462.    or an `errno' value if could not write the inferior.  */
  463.  
  464. int
  465. insert_breakpoints ()
  466. {
  467.   register struct breakpoint *b;
  468.   int val = 0;
  469.   int disabled_breaks = 0;
  470.  
  471.   ALL_BREAKPOINTS (b)
  472.     if (b->type != bp_watchpoint
  473.     && b->type != bp_hardware_watchpoint
  474.     && b->type != bp_read_watchpoint
  475.     && b->type != bp_access_watchpoint
  476.     && b->enable != disabled
  477.     && ! b->inserted
  478.     && ! b->duplicate)
  479.       {
  480.     if (b->type == bp_hardware_breakpoint)
  481.       val = target_insert_hw_breakpoint(b->address, b->shadow_contents);
  482.     else
  483.       val = target_insert_breakpoint(b->address, b->shadow_contents);
  484.     if (val)
  485.       {
  486.         /* Can't set the breakpoint.  */
  487. #if defined (DISABLE_UNSETTABLE_BREAK)
  488.         if (DISABLE_UNSETTABLE_BREAK (b->address))
  489.           {
  490.         val = 0;
  491.         b->enable = disabled;
  492.         if (!disabled_breaks)
  493.           {
  494.             target_terminal_ours_for_output ();
  495.             fprintf_unfiltered (gdb_stderr,
  496.              "Cannot insert breakpoint %d:\n", b->number);
  497.             printf_filtered ("Disabling shared library breakpoints:\n");
  498.           }
  499.         disabled_breaks = 1;
  500.         printf_filtered ("%d ", b->number);
  501.           }
  502.         else
  503. #endif
  504.           {
  505.         target_terminal_ours_for_output ();
  506.         fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
  507. #ifdef ONE_PROCESS_WRITETEXT
  508.         fprintf_unfiltered (gdb_stderr,
  509.           "The same program may be running in another process.\n");
  510. #endif
  511.         memory_error (val, b->address);    /* which bombs us out */
  512.           }
  513.       }
  514.     else
  515.       b->inserted = 1;
  516.       }
  517.     else if ((b->type == bp_hardware_watchpoint ||
  518.           b->type == bp_read_watchpoint ||
  519.           b->type == bp_access_watchpoint)
  520.          && b->enable == enabled
  521.          && ! b->inserted
  522.          && ! b->duplicate)
  523.       {
  524.     struct frame_info *saved_frame;
  525.     int saved_level, within_current_scope;
  526.     value_ptr mark = value_mark ();
  527.     value_ptr v;
  528.  
  529.     /* Save the current frame and level so we can restore it after
  530.        evaluating the watchpoint expression on its own frame.  */
  531.     saved_frame = selected_frame;
  532.     saved_level = selected_frame_level;
  533.  
  534.     /* Determine if the watchpoint is within scope.  */
  535.     if (b->exp_valid_block == NULL)
  536.       within_current_scope = 1;
  537.     else
  538.       {
  539.         struct frame_info *fi =
  540.           find_frame_addr_in_frame_chain (b->watchpoint_frame);
  541.         within_current_scope = (fi != NULL);
  542.         if (within_current_scope)
  543.           select_frame (fi, -1);
  544.       }
  545.     
  546.     if (within_current_scope)
  547.       {
  548.         /* Evaluate the expression and cut the chain of values
  549.            produced off from the value chain.  */
  550.         v = evaluate_expression (b->exp);
  551.         value_release_to_mark (mark);
  552.         
  553.         b->val_chain = v;
  554.         b->inserted = 1;
  555.  
  556.         /* Look at each value on the value chain.  */
  557.         for ( ; v; v=v->next)
  558.           {
  559.         /* If it's a memory location, then we must watch it.  */
  560.         if (v->lval == lval_memory)
  561.           {
  562.             int addr, len, type;
  563.             
  564.             addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
  565.             len = TYPE_LENGTH (VALUE_TYPE (v));
  566.             type = 0;
  567.                     if (b->type == bp_read_watchpoint)
  568.               type = 1;
  569.             else if (b->type == bp_access_watchpoint)
  570.               type = 2;
  571.  
  572.             val = target_insert_watchpoint (addr, len, type);
  573.             if (val == -1)
  574.               {
  575.             b->inserted = 0;
  576.             break;
  577.               }
  578.             val = 0;
  579.           }
  580.           }
  581.         /* Failure to insert a watchpoint on any memory value in the
  582.            value chain brings us here.  */
  583.         if (!b->inserted)
  584.           warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
  585.                b->number);
  586.       }
  587.     else
  588.       {
  589.         printf_filtered ("\
  590. Hardware watchpoint %d deleted because the program has left the block in\n\
  591. which its expression is valid.\n", b->number);
  592.         if (b->related_breakpoint)
  593.           delete_breakpoint (b->related_breakpoint);
  594.         delete_breakpoint (b);
  595.       }
  596.  
  597.     /* Restore the frame and level.  */
  598.         select_frame (saved_frame, saved_level);
  599.       }
  600.   if (disabled_breaks)
  601.     printf_filtered ("\n");
  602.   return val;
  603. }
  604.  
  605.  
  606. int
  607. remove_breakpoints ()
  608. {
  609.   register struct breakpoint *b;
  610.   int val;
  611.  
  612.   ALL_BREAKPOINTS (b)
  613.     {
  614.       if (b->inserted)
  615.     {
  616.       val = remove_breakpoint (b);
  617.       if (val != 0)
  618.         return val;
  619.     }
  620.     }
  621.   return 0;
  622. }
  623.  
  624.  
  625. static int
  626. remove_breakpoint (b)
  627.      struct breakpoint *b;
  628. {
  629.   int val;
  630.   
  631.   if (b->type != bp_watchpoint
  632.       && b->type != bp_hardware_watchpoint
  633.       && b->type != bp_read_watchpoint
  634.       && b->type != bp_access_watchpoint)
  635.     {
  636.       if (b->type == bp_hardware_breakpoint)
  637.         val = target_remove_hw_breakpoint(b->address, b->shadow_contents);
  638.       else
  639.         val = target_remove_breakpoint(b->address, b->shadow_contents);
  640.       if (val)
  641.     return val;
  642.       b->inserted = 0;
  643.     }
  644.   else if ((b->type == bp_hardware_watchpoint ||
  645.             b->type == bp_read_watchpoint ||
  646.           b->type == bp_access_watchpoint)
  647.        && b->enable == enabled
  648.        && ! b->duplicate)
  649.     {
  650.       value_ptr v, n;
  651.       
  652.       b->inserted = 0;
  653.       /* Walk down the saved value chain.  */
  654.       for (v = b->val_chain; v; v = v->next)
  655.     {
  656.       /* For each memory reference remove the watchpoint
  657.          at that address.  */
  658.       if (v->lval == lval_memory)
  659.         {
  660.           int addr, len;
  661.           
  662.           addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
  663.           len = TYPE_LENGTH (VALUE_TYPE (v));
  664.           val = target_remove_watchpoint (addr, len, b->type);
  665.           if (val == -1)
  666.         b->inserted = 1;
  667.           val = 0;
  668.         }
  669.     }
  670.       /* Failure to remove any of the hardware watchpoints comes here.  */
  671.       if (b->inserted)
  672.     error ("Hardware watchpoint %d: Could not remove watchpoint\n",
  673.            b->number);
  674.       
  675.       /* Free the saved value chain.  We will construct a new one
  676.      the next time the watchpoint is inserted.  */
  677.       for (v = b->val_chain; v; v = n)
  678.     {
  679.       n = v->next;
  680.       value_free (v);
  681.     }
  682.       b->val_chain = NULL;
  683.     }
  684.   return 0;
  685. }
  686.  
  687. /* Clear the "inserted" flag in all breakpoints.  */
  688.  
  689. void
  690. mark_breakpoints_out ()
  691. {
  692.   register struct breakpoint *b;
  693.  
  694.   ALL_BREAKPOINTS (b)
  695.     b->inserted = 0;
  696. }
  697.  
  698. /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
  699.    which should go away between runs of the program.  */
  700.  
  701. void
  702. breakpoint_init_inferior ()
  703. {
  704.   register struct breakpoint *b, *temp;
  705.  
  706.   ALL_BREAKPOINTS_SAFE (b, temp)
  707.     {
  708.       b->inserted = 0;
  709.  
  710.       /* If the call dummy breakpoint is at the entry point it will
  711.      cause problems when the inferior is rerun, so we better
  712.      get rid of it.  */
  713.       if (b->type == bp_call_dummy)
  714.     delete_breakpoint (b);
  715.  
  716.       /* Likewise for scope breakpoints.  */
  717.       if (b->type == bp_watchpoint_scope)
  718.     delete_breakpoint (b);
  719.  
  720.       /* Likewise for watchpoints on local expressions.  */
  721.       if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint ||
  722.            b->type == bp_read_watchpoint || b->type == bp_access_watchpoint)
  723.       && b->exp_valid_block != NULL)
  724.     delete_breakpoint (b);
  725.     }
  726. }
  727.  
  728. /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
  729.    When continuing from a location with a breakpoint,
  730.    we actually single step once before calling insert_breakpoints.  */
  731.  
  732. int
  733. breakpoint_here_p (pc)
  734.      CORE_ADDR pc;
  735. {
  736.   register struct breakpoint *b;
  737.  
  738.   ALL_BREAKPOINTS (b)
  739.     if (b->enable != disabled && b->address == pc)
  740.       return 1;
  741.  
  742.   return 0;
  743. }
  744.  
  745. /* Return nonzero if FRAME is a dummy frame.  We can't use PC_IN_CALL_DUMMY
  746.    because figuring out the saved SP would take too much time, at least using
  747.    get_saved_register on the 68k.  This means that for this function to
  748.    work right a port must use the bp_call_dummy breakpoint.  */
  749.  
  750. int
  751. frame_in_dummy (frame)
  752.      struct frame_info *frame;
  753. {
  754.   struct breakpoint *b;
  755.  
  756. #ifdef CALL_DUMMY
  757.   ALL_BREAKPOINTS (b)
  758.     {
  759.       static unsigned LONGEST dummy[] = CALL_DUMMY;
  760.  
  761.       if (b->type == bp_call_dummy
  762.       && b->frame == frame->frame
  763.  
  764.       /* We need to check the PC as well as the frame on the sparc,
  765.          for signals.exp in the testsuite.  */
  766.       && (frame->pc
  767.           >= (b->address
  768.           - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE))
  769.       && frame->pc <= b->address)
  770.     return 1;
  771.     }
  772. #endif /* CALL_DUMMY */
  773.   return 0;
  774. }
  775.  
  776. /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
  777.    is valid for process/thread PID.  */
  778.  
  779. int
  780. breakpoint_thread_match (pc, pid)
  781.      CORE_ADDR pc;
  782.      int pid;
  783. {
  784.   struct breakpoint *b;
  785.   int thread;
  786.  
  787.   thread = pid_to_thread_id (pid);
  788.  
  789.   ALL_BREAKPOINTS (b)
  790.     if (b->enable != disabled
  791.     && b->address == pc
  792.     && (b->thread == -1 || b->thread == thread))
  793.       return 1;
  794.  
  795.   return 0;
  796. }
  797.  
  798.  
  799. /* bpstat stuff.  External routines' interfaces are documented
  800.    in breakpoint.h.  */
  801.  
  802. /* Clear a bpstat so that it says we are not at any breakpoint.
  803.    Also free any storage that is part of a bpstat.  */
  804.  
  805. void
  806. bpstat_clear (bsp)
  807.      bpstat *bsp;
  808. {
  809.   bpstat p;
  810.   bpstat q;
  811.  
  812.   if (bsp == 0)
  813.     return;
  814.   p = *bsp;
  815.   while (p != NULL)
  816.     {
  817.       q = p->next;
  818.       if (p->old_val != NULL)
  819.     value_free (p->old_val);
  820.       free ((PTR)p);
  821.       p = q;
  822.     }
  823.   *bsp = NULL;
  824. }
  825.  
  826. /* Return a copy of a bpstat.  Like "bs1 = bs2" but all storage that
  827.    is part of the bpstat is copied as well.  */
  828.  
  829. bpstat
  830. bpstat_copy (bs)
  831.      bpstat bs;
  832. {
  833.   bpstat p = NULL;
  834.   bpstat tmp;
  835.   bpstat retval = NULL;
  836.  
  837.   if (bs == NULL)
  838.     return bs;
  839.  
  840.   for (; bs != NULL; bs = bs->next)
  841.     {
  842.       tmp = (bpstat) xmalloc (sizeof (*tmp));
  843.       memcpy (tmp, bs, sizeof (*tmp));
  844.       if (p == NULL)
  845.     /* This is the first thing in the chain.  */
  846.     retval = tmp;
  847.       else
  848.     p->next = tmp;
  849.       p = tmp;
  850.     }
  851.   p->next = NULL;
  852.   return retval;
  853. }
  854.  
  855. /* Find the bpstat associated with this breakpoint */
  856.  
  857. bpstat
  858. bpstat_find_breakpoint(bsp, breakpoint)
  859.      bpstat bsp;
  860.      struct breakpoint *breakpoint;
  861. {
  862.   if (bsp == NULL) return NULL;
  863.  
  864.   for (;bsp != NULL; bsp = bsp->next) {
  865.     if (bsp->breakpoint_at == breakpoint) return bsp;
  866.   }
  867.   return NULL;
  868. }
  869.  
  870. /* Return the breakpoint number of the first breakpoint we are stopped
  871.    at.  *BSP upon return is a bpstat which points to the remaining
  872.    breakpoints stopped at (but which is not guaranteed to be good for
  873.    anything but further calls to bpstat_num).
  874.    Return 0 if passed a bpstat which does not indicate any breakpoints.  */
  875.  
  876. int
  877. bpstat_num (bsp)
  878.      bpstat *bsp;
  879. {
  880.   struct breakpoint *b;
  881.  
  882.   if ((*bsp) == NULL)
  883.     return 0;            /* No more breakpoint values */
  884.   else
  885.     {
  886.       b = (*bsp)->breakpoint_at;
  887.       *bsp = (*bsp)->next;
  888.       if (b == NULL)
  889.     return -1;        /* breakpoint that's been deleted since */
  890.       else
  891.         return b->number;    /* We have its number */
  892.     }
  893. }
  894.  
  895. /* Modify BS so that the actions will not be performed.  */
  896.  
  897. void
  898. bpstat_clear_actions (bs)
  899.      bpstat bs;
  900. {
  901.   for (; bs != NULL; bs = bs->next)
  902.     {
  903.       bs->commands = NULL;
  904.       if (bs->old_val != NULL)
  905.     {
  906.       value_free (bs->old_val);
  907.       bs->old_val = NULL;
  908.     }
  909.     }
  910. }
  911.  
  912. /* Stub for cleaning up our state if we error-out of a breakpoint command */
  913. /* ARGSUSED */
  914. static void
  915. cleanup_executing_breakpoints (ignore)
  916.      int ignore;
  917. {
  918.   executing_breakpoint_commands = 0;
  919. }
  920.  
  921. /* Execute all the commands associated with all the breakpoints at this
  922.    location.  Any of these commands could cause the process to proceed
  923.    beyond this point, etc.  We look out for such changes by checking
  924.    the global "breakpoint_proceeded" after each command.  */
  925.  
  926. void
  927. bpstat_do_actions (bsp)
  928.      bpstat *bsp;
  929. {
  930.   bpstat bs;
  931.   struct cleanup *old_chain;
  932.  
  933.   executing_breakpoint_commands = 1;
  934.   old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
  935.  
  936. top:
  937.   bs = *bsp;
  938.  
  939.   breakpoint_proceeded = 0;
  940.   for (; bs != NULL; bs = bs->next)
  941.     {
  942.       while (bs->commands)
  943.     {
  944.       struct command_line *cmd = bs->commands;
  945.       bs->commands = bs->commands->next;
  946.       execute_control_command (cmd);
  947.       /* If the inferior is proceeded by the command, bomb out now.
  948.          The bpstat chain has been blown away by wait_for_inferior.
  949.          But since execution has stopped again, there is a new bpstat
  950.          to look at, so start over.  */
  951.       if (breakpoint_proceeded)
  952.         goto top;
  953.     }
  954.     }
  955.  
  956.   executing_breakpoint_commands = 0;
  957.   discard_cleanups (old_chain);
  958. }
  959.  
  960. /* This is the normal print_it function for a bpstat.  In the future,
  961.    much of this logic could (should?) be moved to bpstat_stop_status,
  962.    by having it set different print_it functions.  */
  963.  
  964. static int
  965. print_it_normal (bs)
  966.      bpstat bs;
  967. {
  968.   /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
  969.      which has since been deleted.  */
  970.   if (bs->breakpoint_at == NULL
  971.       || (bs->breakpoint_at->type != bp_breakpoint
  972.       && bs->breakpoint_at->type != bp_hardware_breakpoint
  973.       && bs->breakpoint_at->type != bp_watchpoint
  974.       && bs->breakpoint_at->type != bp_read_watchpoint
  975.       && bs->breakpoint_at->type != bp_access_watchpoint
  976.       && bs->breakpoint_at->type != bp_hardware_watchpoint))
  977.     return 0;
  978.  
  979.   if (bs->breakpoint_at->type == bp_breakpoint ||
  980.       bs->breakpoint_at->type == bp_hardware_breakpoint)
  981.     {
  982.       /* I think the user probably only wants to see one breakpoint
  983.      number, not all of them.  */
  984.       annotate_breakpoint (bs->breakpoint_at->number);
  985.       printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
  986.       return 0;
  987.     }
  988.   else if ((bs->old_val != NULL) &&
  989.     (bs->breakpoint_at->type == bp_watchpoint ||
  990.      bs->breakpoint_at->type == bp_access_watchpoint ||
  991.      bs->breakpoint_at->type == bp_hardware_watchpoint))
  992.     {
  993.       annotate_watchpoint (bs->breakpoint_at->number);
  994.       mention (bs->breakpoint_at);
  995.       printf_filtered ("\nOld value = ");
  996.       value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
  997.       printf_filtered ("\nNew value = ");
  998.       value_print (bs->breakpoint_at->val, gdb_stdout, 0,
  999.            Val_pretty_default);
  1000.       printf_filtered ("\n");
  1001.       value_free (bs->old_val);
  1002.       bs->old_val = NULL;
  1003.       /* More than one watchpoint may have been triggered.  */
  1004.       return -1;
  1005.     }
  1006.   else if (bs->breakpoint_at->type == bp_access_watchpoint ||
  1007.        bs->breakpoint_at->type == bp_read_watchpoint)
  1008.     {
  1009.       mention (bs->breakpoint_at);
  1010.       printf_filtered ("\nValue = ");
  1011.       value_print (bs->breakpoint_at->val, gdb_stdout, 0,
  1012.                    Val_pretty_default);
  1013.       printf_filtered ("\n");
  1014.       return -1;
  1015.     }
  1016.   /* We can't deal with it.  Maybe another member of the bpstat chain can.  */
  1017.   return -1;
  1018. }
  1019.  
  1020. /* Print a message indicating what happened.  Returns nonzero to
  1021.    say that only the source line should be printed after this (zero
  1022.    return means print the frame as well as the source line).  */
  1023. /* Currently we always return zero.  */
  1024. int
  1025. bpstat_print (bs)
  1026.      bpstat bs;
  1027. {
  1028.   int val;
  1029.   
  1030.   if (bs == NULL)
  1031.     return 0;
  1032.  
  1033.   val = (*bs->print_it) (bs);
  1034.   if (val >= 0)
  1035.     return val;
  1036.   
  1037.   /* Maybe another breakpoint in the chain caused us to stop.
  1038.      (Currently all watchpoints go on the bpstat whether hit or
  1039.      not.  That probably could (should) be changed, provided care is taken
  1040.      with respect to bpstat_explains_signal).  */
  1041.   if (bs->next)
  1042.     return bpstat_print (bs->next);
  1043.  
  1044.   /* We reached the end of the chain without printing anything.  */
  1045.   return 0;
  1046. }
  1047.  
  1048. /* Evaluate the expression EXP and return 1 if value is zero.
  1049.    This is used inside a catch_errors to evaluate the breakpoint condition. 
  1050.    The argument is a "struct expression *" that has been cast to char * to 
  1051.    make it pass through catch_errors.  */
  1052.  
  1053. static int
  1054. breakpoint_cond_eval (exp)
  1055.      char *exp;
  1056. {
  1057.   value_ptr mark = value_mark ();
  1058.   int i = !value_true (evaluate_expression ((struct expression *)exp));
  1059.   value_free_to_mark (mark);
  1060.   return i;
  1061. }
  1062.  
  1063. /* Allocate a new bpstat and chain it to the current one.  */
  1064.  
  1065. static bpstat
  1066. bpstat_alloc (b, cbs)
  1067.      register struct breakpoint *b;
  1068.      bpstat cbs;            /* Current "bs" value */
  1069. {
  1070.   bpstat bs;
  1071.  
  1072.   bs = (bpstat) xmalloc (sizeof (*bs));
  1073.   cbs->next = bs;
  1074.   bs->breakpoint_at = b;
  1075.   /* If the condition is false, etc., don't do the commands.  */
  1076.   bs->commands = NULL;
  1077.   bs->old_val = NULL;
  1078.   bs->print_it = print_it_normal;
  1079.   return bs;
  1080. }
  1081.  
  1082. /* Possible return values for watchpoint_check (this can't be an enum
  1083.    because of check_errors).  */
  1084. /* The watchpoint has been deleted.  */
  1085. #define WP_DELETED 1
  1086. /* The value has changed.  */
  1087. #define WP_VALUE_CHANGED 2
  1088. /* The value has not changed.  */
  1089. #define WP_VALUE_NOT_CHANGED 3
  1090.  
  1091. /* Check watchpoint condition.  */
  1092.  
  1093. static int
  1094. watchpoint_check (p)
  1095.      char *p;
  1096. {
  1097.   bpstat bs = (bpstat) p;
  1098.   struct breakpoint *b;
  1099.   struct frame_info *saved_frame, *fr;
  1100.   int within_current_scope, saved_level;
  1101.  
  1102.   b = bs->breakpoint_at;
  1103.  
  1104.   if (b->exp_valid_block == NULL)
  1105.     within_current_scope = 1;
  1106.   else
  1107.     {
  1108.       /* There is no current frame at this moment.  If we're going to have
  1109.      any chance of handling watchpoints on local variables, we'll need
  1110.      the frame chain (so we can determine if we're in scope).  */
  1111.       reinit_frame_cache();
  1112.       fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
  1113.       within_current_scope = (fr != NULL);
  1114.       if (within_current_scope)
  1115.     /* If we end up stopping, the current frame will get selected
  1116.        in normal_stop.  So this call to select_frame won't affect
  1117.        the user.  */
  1118.     select_frame (fr, -1);
  1119.     }
  1120.       
  1121.   if (within_current_scope)
  1122.     {
  1123.       /* We use value_{,free_to_}mark because it could be a
  1124.          *long* time before we return to the command level and
  1125.      call free_all_values.  We can't call free_all_values because
  1126.      we might be in the middle of evaluating a function call.  */
  1127.  
  1128.       value_ptr mark = value_mark ();
  1129.       value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
  1130.       if (!value_equal (b->val, new_val))
  1131.     {
  1132.       release_value (new_val);
  1133.       value_free_to_mark (mark);
  1134.       bs->old_val = b->val;
  1135.       b->val = new_val;
  1136.       /* We will stop here */
  1137.       return WP_VALUE_CHANGED;
  1138.     }
  1139.       else
  1140.     {
  1141.       /* Nothing changed, don't do anything.  */
  1142.       value_free_to_mark (mark);
  1143.       /* We won't stop here */
  1144.       return WP_VALUE_NOT_CHANGED;
  1145.     }
  1146.     }
  1147.   else
  1148.     {
  1149.       /* This seems like the only logical thing to do because
  1150.      if we temporarily ignored the watchpoint, then when
  1151.      we reenter the block in which it is valid it contains
  1152.      garbage (in the case of a function, it may have two
  1153.      garbage values, one before and one after the prologue).
  1154.      So we can't even detect the first assignment to it and
  1155.      watch after that (since the garbage may or may not equal
  1156.      the first value assigned).  */
  1157.       printf_filtered ("\
  1158. Watchpoint %d deleted because the program has left the block in\n\
  1159. which its expression is valid.\n", bs->breakpoint_at->number);
  1160.       if (b->related_breakpoint)
  1161.     delete_breakpoint (b->related_breakpoint);
  1162.       delete_breakpoint (b);
  1163.  
  1164.       return WP_DELETED;
  1165.     }
  1166. }
  1167.  
  1168. /* This is used when everything which needs to be printed has
  1169.    already been printed.  But we still want to print the frame.  */
  1170. static int
  1171. print_it_done (bs)
  1172.      bpstat bs;
  1173. {
  1174.   return 0;
  1175. }
  1176.  
  1177. /* This is used when nothing should be printed for this bpstat entry.  */
  1178.  
  1179. static int
  1180. print_it_noop (bs)
  1181.      bpstat bs;
  1182. {
  1183.   return -1;
  1184. }
  1185.  
  1186. /* Get a bpstat associated with having just stopped at address *PC
  1187.    and frame address CORE_ADDRESS.  Update *PC to point at the
  1188.    breakpoint (if we hit a breakpoint).  NOT_A_BREAKPOINT is nonzero
  1189.    if this is known to not be a real breakpoint (it could still be a
  1190.    watchpoint, though).  */
  1191.  
  1192. /* Determine whether we stopped at a breakpoint, etc, or whether we
  1193.    don't understand this stop.  Result is a chain of bpstat's such that:
  1194.  
  1195.     if we don't understand the stop, the result is a null pointer.
  1196.  
  1197.     if we understand why we stopped, the result is not null.
  1198.  
  1199.     Each element of the chain refers to a particular breakpoint or
  1200.     watchpoint at which we have stopped.  (We may have stopped for
  1201.     several reasons concurrently.)
  1202.  
  1203.     Each element of the chain has valid next, breakpoint_at,
  1204.     commands, FIXME??? fields.
  1205.  
  1206.  */
  1207.  
  1208. bpstat
  1209. bpstat_stop_status (pc, not_a_breakpoint)
  1210.      CORE_ADDR *pc;
  1211.      int not_a_breakpoint;
  1212. {
  1213.   register struct breakpoint *b;
  1214.   CORE_ADDR bp_addr;
  1215. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  1216.   /* True if we've hit a breakpoint (as opposed to a watchpoint).  */
  1217.   int real_breakpoint = 0;
  1218. #endif
  1219.   /* Root of the chain of bpstat's */
  1220.   struct bpstats root_bs[1];
  1221.   /* Pointer to the last thing in the chain currently.  */
  1222.   bpstat bs = root_bs;
  1223.   static char message1[] =
  1224.             "Error evaluating expression for watchpoint %d\n";
  1225.   char message[sizeof (message1) + 30 /* slop */];
  1226.  
  1227.   /* Get the address where the breakpoint would have been.  */
  1228.   bp_addr = *pc - DECR_PC_AFTER_BREAK;
  1229.  
  1230.   ALL_BREAKPOINTS (b)
  1231.     {
  1232.       if (b->enable == disabled)
  1233.     continue;
  1234.  
  1235.       if (b->type != bp_watchpoint
  1236.       && b->type != bp_hardware_watchpoint
  1237.           && b->type != bp_read_watchpoint
  1238.           && b->type != bp_access_watchpoint
  1239.       && b->type != bp_hardware_breakpoint
  1240.       && b->address != bp_addr)
  1241.     continue;
  1242.  
  1243. #ifndef DECR_PC_AFTER_HW_BREAK
  1244. #define DECR_PC_AFTER_HW_BREAK 0
  1245. #endif
  1246.       if (b->type == bp_hardware_breakpoint
  1247.       && b->address != (bp_addr - DECR_PC_AFTER_HW_BREAK))
  1248.     continue;
  1249.  
  1250.       if (b->type != bp_watchpoint
  1251.       && b->type != bp_hardware_watchpoint
  1252.       && b->type != bp_read_watchpoint
  1253.       && b->type != bp_access_watchpoint
  1254.       && not_a_breakpoint)
  1255.     continue;
  1256.  
  1257.       /* Come here if it's a watchpoint, or if the break address matches */
  1258.  
  1259.       ++(b->hit_count);
  1260.  
  1261.       bs = bpstat_alloc (b, bs);    /* Alloc a bpstat to explain stop */
  1262.  
  1263.       bs->stop = 1;
  1264.       bs->print = 1;
  1265.  
  1266.       sprintf (message, message1, b->number);
  1267.       if (b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
  1268.     {
  1269.       switch (catch_errors (watchpoint_check, (char *) bs, message,
  1270.                 RETURN_MASK_ALL))
  1271.         {
  1272.         case WP_DELETED:
  1273.           /* We've already printed what needs to be printed.  */
  1274.           bs->print_it = print_it_done;
  1275.           /* Stop.  */
  1276.           break;
  1277.         case WP_VALUE_CHANGED:
  1278.           /* Stop.  */
  1279.           break;
  1280.         case WP_VALUE_NOT_CHANGED:
  1281.           /* Don't stop.  */
  1282.           bs->print_it = print_it_noop;
  1283.           bs->stop = 0;
  1284.           continue;
  1285.         default:
  1286.           /* Can't happen.  */
  1287.           /* FALLTHROUGH */
  1288.         case 0:
  1289.           /* Error from catch_errors.  */
  1290.           printf_filtered ("Watchpoint %d deleted.\n", b->number);
  1291.           if (b->related_breakpoint)
  1292.         delete_breakpoint (b->related_breakpoint);
  1293.           delete_breakpoint (b);
  1294.           /* We've already printed what needs to be printed.  */
  1295.           bs->print_it = print_it_done;
  1296.  
  1297.           /* Stop.  */
  1298.           break;
  1299.         }
  1300.     }
  1301.       else if (b->type == bp_read_watchpoint || b->type == bp_access_watchpoint)
  1302.         {
  1303.       CORE_ADDR addr;
  1304.       value_ptr v;
  1305.           int found = 0;
  1306.  
  1307.       addr = target_stopped_data_address();
  1308.       if (addr == 0) continue;
  1309.           for (v = b->val_chain; v; v = v->next)
  1310.             {
  1311.               if (v->lval == lval_memory)
  1312.                 {
  1313.                   CORE_ADDR vaddr;
  1314.  
  1315.                   vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
  1316.               if (addr == vaddr)
  1317.                 found = 1;
  1318.                 }
  1319.             }
  1320.       if (found) 
  1321.         switch (catch_errors (watchpoint_check, (char *) bs, message,
  1322.              RETURN_MASK_ALL))
  1323.              {
  1324.                 case WP_DELETED:
  1325.                   /* We've already printed what needs to be printed.  */
  1326.                   bs->print_it = print_it_done;
  1327.                   /* Stop.  */
  1328.                   break;
  1329.                 case WP_VALUE_CHANGED:
  1330.                 case WP_VALUE_NOT_CHANGED:
  1331.                   /* Stop.  */
  1332.                   break;
  1333.                 default:
  1334.                   /* Can't happen.  */
  1335.                 case 0:
  1336.                   /* Error from catch_errors.  */
  1337.                   printf_filtered ("Watchpoint %d deleted.\n", b->number);
  1338.                   if (b->related_breakpoint)
  1339.                     delete_breakpoint (b->related_breakpoint);
  1340.                   delete_breakpoint (b);
  1341.                   /* We've already printed what needs to be printed.  */
  1342.                   bs->print_it = print_it_done;
  1343.                   break;
  1344.           }
  1345.         }
  1346. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  1347.       else
  1348.     real_breakpoint = 1;
  1349. #endif
  1350.  
  1351.       if (b->frame && b->frame != (get_current_frame ())->frame)
  1352.     bs->stop = 0;
  1353.       else
  1354.     {
  1355.       int value_is_zero = 0;
  1356.  
  1357.       if (b->cond)
  1358.         {
  1359.           /* Need to select the frame, with all that implies
  1360.          so that the conditions will have the right context.  */
  1361.           select_frame (get_current_frame (), 0);
  1362.           value_is_zero
  1363.         = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
  1364.                 "Error in testing breakpoint condition:\n",
  1365.                 RETURN_MASK_ALL);
  1366.                 /* FIXME-someday, should give breakpoint # */
  1367.           free_all_values ();
  1368.         }
  1369.       if (b->cond && value_is_zero)
  1370.         {
  1371.           bs->stop = 0;
  1372.         }
  1373.       else if (b->ignore_count > 0)
  1374.         {
  1375.           b->ignore_count--;
  1376.           bs->stop = 0;
  1377.         }
  1378.       else
  1379.         {
  1380.           /* We will stop here */
  1381.           if (b->disposition == disable)
  1382.         b->enable = disabled;
  1383.           bs->commands = b->commands;
  1384.           if (b->silent)
  1385.         bs->print = 0;
  1386.           if (bs->commands && STREQ ("silent", bs->commands->line))
  1387.         {
  1388.           bs->commands = bs->commands->next;
  1389.           bs->print = 0;
  1390.         }
  1391.         }
  1392.     }
  1393.       /* Print nothing for this entry if we dont stop or if we dont print.  */
  1394.       if (bs->stop == 0 || bs->print == 0)
  1395.     bs->print_it = print_it_noop;
  1396.     }
  1397.  
  1398.   bs->next = NULL;        /* Terminate the chain */
  1399.   bs = root_bs->next;        /* Re-grab the head of the chain */
  1400. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  1401.   if (bs)
  1402.     {
  1403.       if (real_breakpoint)
  1404.     {
  1405.       *pc = bp_addr;
  1406. #if defined (SHIFT_INST_REGS)
  1407.       SHIFT_INST_REGS();
  1408. #else /* No SHIFT_INST_REGS.  */
  1409.       write_pc (bp_addr);
  1410. #endif /* No SHIFT_INST_REGS.  */
  1411.     }
  1412.     }
  1413. #endif /* DECR_PC_AFTER_BREAK != 0.  */
  1414.  
  1415.   /* The value of a hardware watchpoint hasn't changed, but the
  1416.      intermediate memory locations we are watching may have.  */
  1417.   if (bs && ! bs->stop &&
  1418.       (bs->breakpoint_at->type == bp_hardware_watchpoint ||
  1419.        bs->breakpoint_at->type == bp_read_watchpoint ||
  1420.        bs->breakpoint_at->type == bp_access_watchpoint))
  1421.     {
  1422.       remove_breakpoints ();
  1423.       insert_breakpoints ();
  1424.     }
  1425.   return bs;
  1426. }
  1427.  
  1428. /* Tell what to do about this bpstat.  */
  1429. struct bpstat_what
  1430. bpstat_what (bs)
  1431.      bpstat bs;
  1432. {
  1433.   /* Classify each bpstat as one of the following.  */
  1434.   enum class {
  1435.     /* This bpstat element has no effect on the main_action.  */
  1436.     no_effect = 0,
  1437.  
  1438.     /* There was a watchpoint, stop but don't print.  */
  1439.     wp_silent,
  1440.  
  1441.     /* There was a watchpoint, stop and print.  */
  1442.     wp_noisy,
  1443.  
  1444.     /* There was a breakpoint but we're not stopping.  */
  1445.     bp_nostop,
  1446.  
  1447.     /* There was a breakpoint, stop but don't print.  */
  1448.     bp_silent,
  1449.  
  1450.     /* There was a breakpoint, stop and print.  */
  1451.     bp_noisy,
  1452.  
  1453.     /* We hit the longjmp breakpoint.  */
  1454.     long_jump,
  1455.  
  1456.     /* We hit the longjmp_resume breakpoint.  */
  1457.     long_resume,
  1458.  
  1459.     /* We hit the step_resume breakpoint.  */
  1460.     step_resume,
  1461.  
  1462.     /* We hit the through_sigtramp breakpoint.  */
  1463.     through_sig,
  1464.  
  1465.     /* This is just used to count how many enums there are.  */
  1466.     class_last
  1467.     };
  1468.  
  1469.   /* Here is the table which drives this routine.  So that we can
  1470.      format it pretty, we define some abbreviations for the
  1471.      enum bpstat_what codes.  */
  1472. #define keep_c BPSTAT_WHAT_KEEP_CHECKING
  1473. #define stop_s BPSTAT_WHAT_STOP_SILENT
  1474. #define stop_n BPSTAT_WHAT_STOP_NOISY
  1475. #define single BPSTAT_WHAT_SINGLE
  1476. #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
  1477. #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
  1478. #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
  1479. #define sr BPSTAT_WHAT_STEP_RESUME
  1480. #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
  1481.  
  1482. /* "Can't happen."  Might want to print an error message.
  1483.    abort() is not out of the question, but chances are GDB is just
  1484.    a bit confused, not unusable.  */
  1485. #define err BPSTAT_WHAT_STOP_NOISY
  1486.  
  1487.   /* Given an old action and a class, come up with a new action.  */
  1488.   /* One interesting property of this table is that wp_silent is the same
  1489.      as bp_silent and wp_noisy is the same as bp_noisy.  That is because
  1490.      after stopping, the check for whether to step over a breakpoint
  1491.      (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
  1492.      reference to how we stopped.  We retain separate wp_silent and bp_silent
  1493.      codes in case we want to change that someday.  */
  1494.  
  1495.   /* step_resume entries: a step resume breakpoint overrides another
  1496.      breakpoint of signal handling (see comment in wait_for_inferior
  1497.      at first IN_SIGTRAMP where we set the step_resume breakpoint).  */
  1498.   /* We handle the through_sigtramp_breakpoint the same way; having both
  1499.      one of those and a step_resume_breakpoint is probably very rare (?).  */
  1500.  
  1501.   static const enum bpstat_what_main_action
  1502.     table[(int)class_last][(int)BPSTAT_WHAT_LAST] =
  1503.       {
  1504.     /*                              old action */
  1505.     /*       keep_c stop_s stop_n single  setlr   clrlr   clrlrs  sr  ts
  1506.      */
  1507. /*no_effect*/    {keep_c,stop_s,stop_n,single, setlr , clrlr , clrlrs, sr, ts},
  1508. /*wp_silent*/    {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts},
  1509. /*wp_noisy*/    {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts},
  1510. /*bp_nostop*/    {single,stop_s,stop_n,single, setlr , clrlrs, clrlrs, sr, ts},
  1511. /*bp_silent*/    {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts},
  1512. /*bp_noisy*/    {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts},
  1513. /*long_jump*/    {setlr ,stop_s,stop_n,setlr , err   , err   , err   , sr, ts},
  1514. /*long_resume*/    {clrlr ,stop_s,stop_n,clrlrs, err   , err   , err   , sr, ts},
  1515. /*step_resume*/    {sr    ,sr    ,sr    ,sr    , sr    , sr    , sr    , sr, ts},
  1516. /*through_sig*/ {ts    ,ts    ,ts    ,ts    , ts    , ts    , ts    , ts, ts}
  1517.           };
  1518. #undef keep_c
  1519. #undef stop_s
  1520. #undef stop_n
  1521. #undef single
  1522. #undef setlr
  1523. #undef clrlr
  1524. #undef clrlrs
  1525. #undef err
  1526. #undef sr
  1527. #undef ts
  1528.   enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
  1529.   struct bpstat_what retval;
  1530.  
  1531.   retval.call_dummy = 0;
  1532.   for (; bs != NULL; bs = bs->next)
  1533.     {
  1534.       enum class bs_class = no_effect;
  1535.       if (bs->breakpoint_at == NULL)
  1536.     /* I suspect this can happen if it was a momentary breakpoint
  1537.        which has since been deleted.  */
  1538.     continue;
  1539.       switch (bs->breakpoint_at->type)
  1540.     {
  1541.     case bp_breakpoint:
  1542.     case bp_hardware_breakpoint:
  1543.     case bp_until:
  1544.     case bp_finish:
  1545.       if (bs->stop)
  1546.         {
  1547.           if (bs->print)
  1548.         bs_class = bp_noisy;
  1549.           else
  1550.         bs_class = bp_silent;
  1551.         }
  1552.       else
  1553.         bs_class = bp_nostop;
  1554.       break;
  1555.     case bp_watchpoint:
  1556.     case bp_hardware_watchpoint:
  1557.     case bp_read_watchpoint:
  1558.     case bp_access_watchpoint:
  1559.       if (bs->stop)
  1560.         {
  1561.           if (bs->print)
  1562.         bs_class = wp_noisy;
  1563.           else
  1564.         bs_class = wp_silent;
  1565.         }
  1566.       else
  1567.         /* There was a watchpoint, but we're not stopping.  This requires
  1568.            no further action.  */
  1569.         bs_class = no_effect;
  1570.       break;
  1571.     case bp_longjmp:
  1572.       bs_class = long_jump;
  1573.       break;
  1574.     case bp_longjmp_resume:
  1575.       bs_class = long_resume;
  1576.       break;
  1577.     case bp_step_resume:
  1578.       if (bs->stop)
  1579.         {
  1580.           bs_class = step_resume;
  1581.         }
  1582.       else
  1583.         /* It is for the wrong frame.  */
  1584.         bs_class = bp_nostop;
  1585.       break;
  1586.     case bp_through_sigtramp:
  1587.       bs_class = through_sig;
  1588.       break;
  1589.     case bp_watchpoint_scope:
  1590.       bs_class = bp_nostop;
  1591.       break;
  1592.  
  1593.     case bp_call_dummy:
  1594.       /* Make sure the action is stop (silent or noisy), so infrun.c
  1595.          pops the dummy frame.  */
  1596.       bs_class = bp_silent;
  1597.       retval.call_dummy = 1;
  1598.       break;
  1599.     }
  1600.       current_action = table[(int)bs_class][(int)current_action];
  1601.     }
  1602.   retval.main_action = current_action;
  1603.   return retval;
  1604. }
  1605.  
  1606. /* Nonzero if we should step constantly (e.g. watchpoints on machines
  1607.    without hardware support).  This isn't related to a specific bpstat,
  1608.    just to things like whether watchpoints are set.  */
  1609.  
  1610. int 
  1611. bpstat_should_step ()
  1612. {
  1613.   struct breakpoint *b;
  1614.   ALL_BREAKPOINTS (b)
  1615.     if (b->enable == enabled && b->type == bp_watchpoint)
  1616.       return 1;
  1617.   return 0;
  1618. }
  1619.  
  1620. /* Print information on breakpoint number BNUM, or -1 if all.
  1621.    If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
  1622.    is nonzero, process only watchpoints.  */
  1623.  
  1624. static void
  1625. breakpoint_1 (bnum, allflag)
  1626.      int bnum;
  1627.      int allflag;
  1628. {
  1629.   register struct breakpoint *b;
  1630.   register struct command_line *l;
  1631.   register struct symbol *sym;
  1632.   CORE_ADDR last_addr = (CORE_ADDR)-1;
  1633.   int found_a_breakpoint = 0;
  1634.   static char *bptypes[] = {"breakpoint", "hw breakpoint",
  1635.                       "until", "finish", "watchpoint",
  1636.                   "hw watchpoint", "read watchpoint",
  1637.                   "acc watchpoint", "longjmp",
  1638.                   "longjmp resume", "step resume",
  1639.                   "watchpoint scope", "call dummy" };
  1640.   static char *bpdisps[] = {"del", "dis", "keep"};
  1641.   static char bpenables[] = "ny";
  1642.   char wrap_indent[80];
  1643.  
  1644.   ALL_BREAKPOINTS (b)
  1645.     if (bnum == -1
  1646.     || bnum == b->number)
  1647.       {
  1648. /*  We only print out user settable breakpoints unless the allflag is set. */
  1649.     if (!allflag
  1650.         && b->type != bp_breakpoint
  1651.         && b->type != bp_hardware_breakpoint
  1652.         && b->type != bp_watchpoint
  1653.         && b->type != bp_read_watchpoint
  1654.         && b->type != bp_access_watchpoint
  1655.         && b->type != bp_hardware_watchpoint)
  1656.       continue;
  1657.  
  1658.     if (!found_a_breakpoint++)
  1659.       {
  1660.             annotate_breakpoints_headers ();
  1661.   
  1662.             annotate_field (0);
  1663.             printf_filtered ("Num ");
  1664.             annotate_field (1);
  1665.             printf_filtered ("Type           ");
  1666.             annotate_field (2);
  1667.             printf_filtered ("Disp ");
  1668.             annotate_field (3);
  1669.             printf_filtered ("Enb ");
  1670.             if (addressprint)
  1671.               {
  1672.                 annotate_field (4);
  1673.                 printf_filtered ("Address    ");
  1674.               }
  1675.             annotate_field (5);
  1676.             printf_filtered ("What\n");
  1677.   
  1678.             annotate_breakpoints_table ();
  1679.           }
  1680.   
  1681.         annotate_record ();
  1682.         annotate_field (0);
  1683.         printf_filtered ("%-3d ", b->number);
  1684.         annotate_field (1);
  1685.         printf_filtered ("%-14s ", bptypes[(int)b->type]);
  1686.         annotate_field (2);
  1687.         printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
  1688.         annotate_field (3);
  1689.     printf_filtered ("%-3c ", bpenables[(int)b->enable]);
  1690.  
  1691.     strcpy (wrap_indent, "                           ");
  1692.     if (addressprint)
  1693.       strcat (wrap_indent, "           ");
  1694.     switch (b->type)
  1695.       {
  1696.       case bp_watchpoint:
  1697.       case bp_hardware_watchpoint:
  1698.       case bp_read_watchpoint:
  1699.       case bp_access_watchpoint:
  1700.         /* Field 4, the address, is omitted (which makes the columns
  1701.            not line up too nicely with the headers, but the effect
  1702.            is relatively readable).  */
  1703.         annotate_field (5);
  1704.         print_expression (b->exp, gdb_stdout);
  1705.         break;
  1706.  
  1707.       case bp_breakpoint:
  1708.       case bp_hardware_breakpoint:
  1709.       case bp_until:
  1710.       case bp_finish:
  1711.       case bp_longjmp:
  1712.       case bp_longjmp_resume:
  1713.       case bp_step_resume:
  1714.       case bp_through_sigtramp:
  1715.       case bp_watchpoint_scope:
  1716.       case bp_call_dummy:
  1717.         if (addressprint)
  1718.           {
  1719.             annotate_field (4);
  1720.         /* FIXME-32x64: need a print_address_numeric with
  1721.                    field width */
  1722.         printf_filtered
  1723.           ("%s ",
  1724.            local_hex_string_custom
  1725.            ((unsigned long) b->address, "08l"));
  1726.           }
  1727.  
  1728.         annotate_field (5);
  1729.  
  1730.         last_addr = b->address;
  1731.         if (b->source_file)
  1732.           {
  1733.         sym = find_pc_function (b->address);
  1734.         if (sym)
  1735.           {
  1736.             fputs_filtered ("in ", gdb_stdout);
  1737.             fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
  1738.             wrap_here (wrap_indent);
  1739.             fputs_filtered (" at ", gdb_stdout);
  1740.           }
  1741.         fputs_filtered (b->source_file, gdb_stdout);
  1742.         printf_filtered (":%d", b->line_number);
  1743.           }
  1744.         else
  1745.           print_address_symbolic (b->address, gdb_stdout, demangle, " ");
  1746.         break;
  1747.       }
  1748.  
  1749.     printf_filtered ("\n");
  1750.  
  1751.     if (b->frame)
  1752.       {
  1753.             annotate_field (6);
  1754.  
  1755.         printf_filtered ("\tstop only in stack frame at ");
  1756.         print_address_numeric (b->frame, 1, gdb_stdout);
  1757.         printf_filtered ("\n");
  1758.       }
  1759.  
  1760.     if (b->cond)
  1761.       {
  1762.             annotate_field (7);
  1763.  
  1764.         printf_filtered ("\tstop only if ");
  1765.         print_expression (b->cond, gdb_stdout);
  1766.         printf_filtered ("\n");
  1767.       }
  1768.  
  1769.         if (show_breakpoint_hit_counts && b->hit_count)
  1770.       {
  1771.         /* FIXME should make an annotation for this */
  1772.  
  1773.         printf_filtered ("\tbreakpoint already hit %d time%s\n",
  1774.                  b->hit_count, (b->hit_count == 1 ? "" : "s"));
  1775.       }
  1776.  
  1777.     if (b->ignore_count)
  1778.       {
  1779.             annotate_field (8);
  1780.  
  1781.         printf_filtered ("\tignore next %d hits\n", b->ignore_count);
  1782.       }
  1783.  
  1784.     if ((l = b->commands))
  1785.       {
  1786.             annotate_field (9);
  1787.  
  1788.         while (l)
  1789.           {
  1790.         print_command_line (l, 4);
  1791.         l = l->next;
  1792.           }
  1793.       }
  1794.       }
  1795.  
  1796.   if (!found_a_breakpoint)
  1797.     {
  1798.       if (bnum == -1)
  1799.         printf_filtered ("No breakpoints or watchpoints.\n");
  1800.       else
  1801.         printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
  1802.     }
  1803.   else
  1804.     /* Compare against (CORE_ADDR)-1 in case some compiler decides
  1805.        that a comparison of an unsigned with -1 is always false.  */
  1806.     if (last_addr != (CORE_ADDR)-1)
  1807.       set_next_address (last_addr);
  1808.  
  1809.   annotate_breakpoints_table_end ();
  1810. }
  1811.  
  1812. /* ARGSUSED */
  1813. static void
  1814. breakpoints_info (bnum_exp, from_tty)
  1815.      char *bnum_exp;
  1816.      int from_tty;
  1817. {
  1818.   int bnum = -1;
  1819.  
  1820.   if (bnum_exp)
  1821.     bnum = parse_and_eval_address (bnum_exp);
  1822.  
  1823.   breakpoint_1 (bnum, 0);
  1824. }
  1825.  
  1826. #if MAINTENANCE_CMDS
  1827.  
  1828. /* ARGSUSED */
  1829. static void
  1830. maintenance_info_breakpoints (bnum_exp, from_tty)
  1831.      char *bnum_exp;
  1832.      int from_tty;
  1833. {
  1834.   int bnum = -1;
  1835.  
  1836.   if (bnum_exp)
  1837.     bnum = parse_and_eval_address (bnum_exp);
  1838.  
  1839.   breakpoint_1 (bnum, 1);
  1840. }
  1841.  
  1842. #endif
  1843.  
  1844. /* Print a message describing any breakpoints set at PC.  */
  1845.  
  1846. static void
  1847. describe_other_breakpoints (pc)
  1848.      register CORE_ADDR pc;
  1849. {
  1850.   register int others = 0;
  1851.   register struct breakpoint *b;
  1852.  
  1853.   ALL_BREAKPOINTS (b)
  1854.     if (b->address == pc)
  1855.       others++;
  1856.   if (others > 0)
  1857.     {
  1858.       printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
  1859.       ALL_BREAKPOINTS (b)
  1860.     if (b->address == pc)
  1861.       {
  1862.         others--;
  1863.         printf_filtered
  1864.           ("%d%s%s ",
  1865.            b->number,
  1866.            (b->enable == disabled) ? " (disabled)" : "",
  1867.            (others > 1) ? "," : ((others == 1) ? " and" : ""));
  1868.       }
  1869.       printf_filtered ("also set at pc ");
  1870.       print_address_numeric (pc, 1, gdb_stdout);
  1871.       printf_filtered (".\n");
  1872.     }
  1873. }
  1874.  
  1875. /* Set the default place to put a breakpoint
  1876.    for the `break' command with no arguments.  */
  1877.  
  1878. void
  1879. set_default_breakpoint (valid, addr, symtab, line)
  1880.      int valid;
  1881.      CORE_ADDR addr;
  1882.      struct symtab *symtab;
  1883.      int line;
  1884. {
  1885.   default_breakpoint_valid = valid;
  1886.   default_breakpoint_address = addr;
  1887.   default_breakpoint_symtab = symtab;
  1888.   default_breakpoint_line = line;
  1889. }
  1890.  
  1891. /* Rescan breakpoints at address ADDRESS,
  1892.    marking the first one as "first" and any others as "duplicates".
  1893.    This is so that the bpt instruction is only inserted once.  */
  1894.  
  1895. static void
  1896. check_duplicates (address)
  1897.      CORE_ADDR address;
  1898. {
  1899.   register struct breakpoint *b;
  1900.   register int count = 0;
  1901.  
  1902.   if (address == 0)        /* Watchpoints are uninteresting */
  1903.     return;
  1904.  
  1905.   ALL_BREAKPOINTS (b)
  1906.     if (b->enable != disabled && b->address == address)
  1907.       {
  1908.     count++;
  1909.     b->duplicate = count > 1;
  1910.       }
  1911. }
  1912.  
  1913. /* Low level routine to set a breakpoint.
  1914.    Takes as args the three things that every breakpoint must have.
  1915.    Returns the breakpoint object so caller can set other things.
  1916.    Does not set the breakpoint number!
  1917.    Does not print anything.
  1918.  
  1919.    ==> This routine should not be called if there is a chance of later
  1920.    error(); otherwise it leaves a bogus breakpoint on the chain.  Validate
  1921.    your arguments BEFORE calling this routine!  */
  1922.  
  1923. static struct breakpoint *
  1924. set_raw_breakpoint (sal)
  1925.      struct symtab_and_line sal;
  1926. {
  1927.   register struct breakpoint *b, *b1;
  1928.  
  1929.   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
  1930.   memset (b, 0, sizeof (*b));
  1931.   b->address = sal.pc;
  1932.   if (sal.symtab == NULL)
  1933.     b->source_file = NULL;
  1934.   else
  1935.     b->source_file = savestring (sal.symtab->filename,
  1936.                  strlen (sal.symtab->filename));
  1937.   b->language = current_language->la_language;
  1938.   b->input_radix = input_radix;
  1939.   b->thread = -1;
  1940.   b->line_number = sal.line;
  1941.   b->enable = enabled;
  1942.   b->next = 0;
  1943.   b->silent = 0;
  1944.   b->ignore_count = 0;
  1945.   b->commands = NULL;
  1946.   b->frame = 0;
  1947.  
  1948.   /* Add this breakpoint to the end of the chain
  1949.      so that a list of breakpoints will come out in order
  1950.      of increasing numbers.  */
  1951.  
  1952.   b1 = breakpoint_chain;
  1953.   if (b1 == 0)
  1954.     breakpoint_chain = b;
  1955.   else
  1956.     {
  1957.       while (b1->next)
  1958.     b1 = b1->next;
  1959.       b1->next = b;
  1960.     }
  1961.  
  1962.   check_duplicates (sal.pc);
  1963.   breakpoints_changed ();
  1964.  
  1965.   return b;
  1966. }
  1967.  
  1968. static void
  1969. create_longjmp_breakpoint(func_name)
  1970.      char *func_name;
  1971. {
  1972.   struct symtab_and_line sal;
  1973.   struct breakpoint *b;
  1974.   static int internal_breakpoint_number = -1;
  1975.  
  1976.   if (func_name != NULL)
  1977.     {
  1978.       struct minimal_symbol *m;
  1979.  
  1980.       m = lookup_minimal_symbol (func_name, NULL, (struct objfile *)NULL);
  1981.       if (m)
  1982.     sal.pc = SYMBOL_VALUE_ADDRESS (m);
  1983.       else
  1984.     return;
  1985.     }
  1986.   else
  1987.     sal.pc = 0;
  1988.  
  1989.   sal.symtab = NULL;
  1990.   sal.line = 0;
  1991.  
  1992.   b = set_raw_breakpoint(sal);
  1993.   if (!b) return;
  1994.  
  1995.   b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
  1996.   b->disposition = donttouch;
  1997.   b->enable = disabled;
  1998.   b->silent = 1;
  1999.   if (func_name)
  2000.     b->addr_string = strsave(func_name);
  2001.   b->number = internal_breakpoint_number--;
  2002. }
  2003.  
  2004. /* Call this routine when stepping and nexting to enable a breakpoint if we do
  2005.    a longjmp().  When we hit that breakpoint, call
  2006.    set_longjmp_resume_breakpoint() to figure out where we are going. */
  2007.  
  2008. void
  2009. enable_longjmp_breakpoint()
  2010. {
  2011.   register struct breakpoint *b;
  2012.  
  2013.   ALL_BREAKPOINTS (b)
  2014.     if (b->type == bp_longjmp)
  2015.       {
  2016.     b->enable = enabled;
  2017.     check_duplicates (b->address);
  2018.       }
  2019. }
  2020.  
  2021. void
  2022. disable_longjmp_breakpoint()
  2023. {
  2024.   register struct breakpoint *b;
  2025.  
  2026.   ALL_BREAKPOINTS (b)
  2027.     if (   b->type == bp_longjmp
  2028.     || b->type == bp_longjmp_resume)
  2029.       {
  2030.     b->enable = disabled;
  2031.     check_duplicates (b->address);
  2032.       }
  2033. }
  2034.  
  2035. int
  2036. hw_breakpoint_used_count()
  2037. {
  2038.   register struct breakpoint *b;
  2039.   int i = 0;
  2040.  
  2041.   ALL_BREAKPOINTS (b)
  2042.     {
  2043.       if (b->type == bp_hardware_breakpoint && b->enable == enabled)
  2044.     i++;
  2045.     }
  2046.  
  2047.   return i;
  2048. }
  2049.  
  2050. int
  2051. hw_watchpoint_used_count(type, other_type_used)
  2052.     enum bptype type;
  2053.     int *other_type_used;
  2054. {
  2055.   register struct breakpoint *b;
  2056.   int i = 0;
  2057.  
  2058.   *other_type_used = 0;
  2059.   ALL_BREAKPOINTS (b)
  2060.     {
  2061.       if (b->enable == enabled)
  2062.     {
  2063.           if (b->type == type) i++;
  2064.           else if ((b->type == bp_hardware_watchpoint ||
  2065.            b->type == bp_read_watchpoint ||
  2066.            b->type == bp_access_watchpoint)
  2067.            && b->enable == enabled)
  2068.         *other_type_used = 1;
  2069.         }
  2070.     }
  2071.   return i;
  2072. }
  2073.  
  2074. /* Call this after hitting the longjmp() breakpoint.  Use this to set a new
  2075.    breakpoint at the target of the jmp_buf.
  2076.  
  2077.    FIXME - This ought to be done by setting a temporary breakpoint that gets
  2078.    deleted automatically...
  2079. */
  2080.  
  2081. void
  2082. set_longjmp_resume_breakpoint(pc, frame)
  2083.      CORE_ADDR pc;
  2084.      struct frame_info *frame;
  2085. {
  2086.   register struct breakpoint *b;
  2087.  
  2088.   ALL_BREAKPOINTS (b)
  2089.     if (b->type == bp_longjmp_resume)
  2090.       {
  2091.     b->address = pc;
  2092.     b->enable = enabled;
  2093.     if (frame != NULL)
  2094.       b->frame = frame->frame;
  2095.     else
  2096.       b->frame = 0;
  2097.     check_duplicates (b->address);
  2098.     return;
  2099.       }
  2100. }
  2101.  
  2102. /* Set a breakpoint that will evaporate an end of command
  2103.    at address specified by SAL.
  2104.    Restrict it to frame FRAME if FRAME is nonzero.  */
  2105.  
  2106. struct breakpoint *
  2107. set_momentary_breakpoint (sal, frame, type)
  2108.      struct symtab_and_line sal;
  2109.      struct frame_info *frame;
  2110.      enum bptype type;
  2111. {
  2112.   register struct breakpoint *b;
  2113.   b = set_raw_breakpoint (sal);
  2114.   b->type = type;
  2115.   b->enable = enabled;
  2116.   b->disposition = donttouch;
  2117.   b->frame = (frame ? frame->frame : 0);
  2118.   return b;
  2119. }
  2120.  
  2121. #if 0
  2122. void
  2123. clear_momentary_breakpoints ()
  2124. {
  2125.   register struct breakpoint *b;
  2126.   ALL_BREAKPOINTS (b)
  2127.     if (b->disposition == delete)
  2128.       {
  2129.     delete_breakpoint (b);
  2130.     break;
  2131.       }
  2132. }
  2133. #endif
  2134.  
  2135. /* Tell the user we have just set a breakpoint B.  */
  2136.  
  2137. static void
  2138. mention (b)
  2139.      struct breakpoint *b;
  2140. {
  2141.   int say_where = 0;
  2142.  
  2143.   /* FIXME: This is misplaced; mention() is called by things (like hitting a
  2144.      watchpoint) other than breakpoint creation.  It should be possible to
  2145.      clean this up and at the same time replace the random calls to
  2146.      breakpoint_changed with this hook, as has already been done for
  2147.      delete_breakpoint_hook and so on.  */
  2148.   if (create_breakpoint_hook)
  2149.     create_breakpoint_hook (b);
  2150.  
  2151.   switch (b->type)
  2152.     {
  2153.     case bp_watchpoint:
  2154.       printf_filtered ("Watchpoint %d: ", b->number);
  2155.       print_expression (b->exp, gdb_stdout);
  2156.       break;
  2157.     case bp_hardware_watchpoint:
  2158.       printf_filtered ("Hardware watchpoint %d: ", b->number);
  2159.       print_expression (b->exp, gdb_stdout);
  2160.       break;
  2161.     case bp_read_watchpoint:
  2162.       printf_filtered ("Hardware read watchpoint %d: ", b->number);
  2163.       print_expression (b->exp, gdb_stdout);
  2164.       break;
  2165.     case bp_access_watchpoint:
  2166.       printf_filtered ("Hardware access(read/write) watchpoint %d: ",b->number);
  2167.       print_expression (b->exp, gdb_stdout);
  2168.       break;
  2169.     case bp_breakpoint:
  2170.       printf_filtered ("Breakpoint %d", b->number);
  2171.       say_where = 1;
  2172.       break;
  2173.     case bp_hardware_breakpoint:
  2174.       printf_filtered ("Hardware assisted breakpoint %d", b->number);
  2175.       say_where = 1;
  2176.       break;
  2177.     case bp_until:
  2178.     case bp_finish:
  2179.     case bp_longjmp:
  2180.     case bp_longjmp_resume:
  2181.     case bp_step_resume:
  2182.     case bp_through_sigtramp:
  2183.     case bp_call_dummy:
  2184.     case bp_watchpoint_scope:
  2185.       break;
  2186.     }
  2187.   if (say_where)
  2188.     {
  2189.       if (addressprint || b->source_file == NULL)
  2190.     {
  2191.       printf_filtered (" at ");
  2192.       print_address_numeric (b->address, 1, gdb_stdout);
  2193.     }
  2194.       if (b->source_file)
  2195.     printf_filtered (": file %s, line %d.",
  2196.              b->source_file, b->line_number);
  2197.     }
  2198.   printf_filtered ("\n");
  2199. }
  2200.  
  2201. #if 0
  2202. /* Nobody calls this currently. */
  2203. /* Set a breakpoint from a symtab and line.
  2204.    If TEMPFLAG is nonzero, it is a temporary breakpoint.
  2205.    ADDR_STRING is a malloc'd string holding the name of where we are
  2206.    setting the breakpoint.  This is used later to re-set it after the
  2207.    program is relinked and symbols are reloaded.
  2208.    Print the same confirmation messages that the breakpoint command prints.  */
  2209.  
  2210. void
  2211. set_breakpoint (s, line, tempflag, addr_string)
  2212.      struct symtab *s;
  2213.      int line;
  2214.      int tempflag;
  2215.      char *addr_string;
  2216. {
  2217.   register struct breakpoint *b;
  2218.   struct symtab_and_line sal;
  2219.   
  2220.   sal.symtab = s;
  2221.   sal.line = line;
  2222.   sal.pc = 0;
  2223.   resolve_sal_pc (&sal);            /* Might error out */
  2224.   describe_other_breakpoints (sal.pc);
  2225.  
  2226.   b = set_raw_breakpoint (sal);
  2227.   set_breakpoint_count (breakpoint_count + 1);
  2228.   b->number = breakpoint_count;
  2229.   b->type = bp_breakpoint;
  2230.   b->cond = 0;
  2231.   b->addr_string = addr_string;
  2232.   b->enable = enabled;
  2233.   b->disposition = tempflag ? delete : donttouch;
  2234.  
  2235.   mention (b);
  2236. }
  2237. #endif /* 0 */
  2238.  
  2239. /* Set a breakpoint according to ARG (function, linenum or *address)
  2240.    flag: first bit  : 0 non-temporary, 1 temporary.
  2241.      second bit : 0 normal breakpoint, 1 hardware breakpoint. */
  2242.  
  2243. static void
  2244. break_command_1 (arg, flag, from_tty)
  2245.      char *arg;
  2246.      int flag, from_tty;
  2247. {
  2248.   int tempflag, hardwareflag;
  2249.   struct symtabs_and_lines sals;
  2250.   struct symtab_and_line sal;
  2251.   register struct expression *cond = 0;
  2252.   register struct breakpoint *b;
  2253.  
  2254.   /* Pointers in arg to the start, and one past the end, of the condition.  */
  2255.   char *cond_start = NULL;
  2256.   char *cond_end = NULL;
  2257.   /* Pointers in arg to the start, and one past the end,
  2258.      of the address part.  */
  2259.   char *addr_start = NULL;
  2260.   char *addr_end = NULL;
  2261.   struct cleanup *old_chain;
  2262.   struct cleanup *canonical_strings_chain = NULL;
  2263.   char **canonical = (char **)NULL;
  2264.   int i;
  2265.   int thread;
  2266.  
  2267.   hardwareflag = flag & 2;
  2268.   tempflag = flag & 1;
  2269.  
  2270.   sals.sals = NULL;
  2271.   sals.nelts = 0;
  2272.  
  2273.   sal.line = sal.pc = sal.end = 0;
  2274.   sal.symtab = 0;
  2275.  
  2276.   /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
  2277.  
  2278.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  2279.            && (arg[2] == ' ' || arg[2] == '\t')))
  2280.     {
  2281.       if (default_breakpoint_valid)
  2282.     {
  2283.       sals.sals = (struct symtab_and_line *) 
  2284.         xmalloc (sizeof (struct symtab_and_line));
  2285.       sal.pc = default_breakpoint_address;
  2286.       sal.line = default_breakpoint_line;
  2287.       sal.symtab = default_breakpoint_symtab;
  2288.       sals.sals[0] = sal;
  2289.       sals.nelts = 1;
  2290.     }
  2291.       else
  2292.     error ("No default breakpoint address now.");
  2293.     }
  2294.   else
  2295.     {
  2296.       addr_start = arg;
  2297.  
  2298.       /* Force almost all breakpoints to be in terms of the
  2299.      current_source_symtab (which is decode_line_1's default).  This
  2300.      should produce the results we want almost all of the time while
  2301.      leaving default_breakpoint_* alone.  */
  2302.       if (default_breakpoint_valid
  2303.       && (!current_source_symtab
  2304.           || (arg && (*arg == '+' || *arg == '-'))))
  2305.     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  2306.                   default_breakpoint_line, &canonical);
  2307.       else
  2308.     sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
  2309.  
  2310.       addr_end = arg;
  2311.     }
  2312.   
  2313.   if (! sals.nelts) 
  2314.     return;
  2315.  
  2316.   /* Make sure that all storage allocated in decode_line_1 gets freed in case
  2317.      the following `for' loop errors out.  */
  2318.   old_chain = make_cleanup (free, sals.sals);
  2319.   if (canonical != (char **)NULL)
  2320.     {
  2321.       make_cleanup (free, canonical);
  2322.       canonical_strings_chain = make_cleanup (null_cleanup, 0);
  2323.       for (i = 0; i < sals.nelts; i++)
  2324.     {
  2325.       if (canonical[i] != NULL)
  2326.         make_cleanup (free, canonical[i]);
  2327.     }
  2328.     }
  2329.  
  2330.   thread = -1;            /* No specific thread yet */
  2331.  
  2332.   /* Resolve all line numbers to PC's, and verify that conditions
  2333.      can be parsed, before setting any breakpoints.  */
  2334.   for (i = 0; i < sals.nelts; i++)
  2335.     {
  2336.       char *tok, *end_tok;
  2337.       int toklen;
  2338.  
  2339.       resolve_sal_pc (&sals.sals[i]);
  2340.       
  2341.       tok = arg;
  2342.  
  2343.       while (tok && *tok)
  2344.     {
  2345.       while (*tok == ' ' || *tok == '\t')
  2346.         tok++;
  2347.  
  2348.       end_tok = tok;
  2349.  
  2350.       while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
  2351.         end_tok++;
  2352.  
  2353.       toklen = end_tok - tok;
  2354.  
  2355.       if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
  2356.         {
  2357.           tok = cond_start = end_tok + 1;
  2358.           cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
  2359.           cond_end = tok;
  2360.         }
  2361.       else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
  2362.         {
  2363.           char *tmptok;
  2364.  
  2365.           tok = end_tok + 1;
  2366.           tmptok = tok;
  2367.           thread = strtol (tok, &tok, 0);
  2368.           if (tok == tmptok)
  2369.         error ("Junk after thread keyword.");
  2370.           if (!valid_thread_id (thread))
  2371.         error ("Unknown thread %d\n", thread);
  2372.         }
  2373.       else
  2374.         error ("Junk at end of arguments.");
  2375.     }
  2376.     }
  2377.   if (hardwareflag)
  2378.     {
  2379.       int i, target_resources_ok;
  2380.  
  2381.       i = hw_breakpoint_used_count ();  
  2382.       target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
  2383.         bp_hardware_breakpoint, i + sals.nelts, 0);
  2384.       if (target_resources_ok == 0)
  2385.     error ("No hardware breakpoint support in the target.");
  2386.       else if (target_resources_ok < 0)
  2387.         error ("Hardware breakpoints used exceeds limit.");
  2388.     }
  2389.  
  2390.   /* Remove the canonical strings from the cleanup, they are needed below.  */
  2391.   if (canonical != (char **)NULL)
  2392.     discard_cleanups (canonical_strings_chain);
  2393.  
  2394.   /* Now set all the breakpoints.  */
  2395.   for (i = 0; i < sals.nelts; i++)
  2396.     {
  2397.       sal = sals.sals[i];
  2398.  
  2399.       if (from_tty)
  2400.     describe_other_breakpoints (sal.pc);
  2401.  
  2402.       b = set_raw_breakpoint (sal);
  2403.       set_breakpoint_count (breakpoint_count + 1);
  2404.       b->number = breakpoint_count;
  2405.       b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
  2406.       b->cond = cond;
  2407.       b->thread = thread;
  2408.  
  2409.       /* If a canonical line spec is needed use that instead of the
  2410.      command string.  */
  2411.       if (canonical != (char **)NULL && canonical[i] != NULL)
  2412.     b->addr_string = canonical[i];
  2413.       else if (addr_start)
  2414.     b->addr_string = savestring (addr_start, addr_end - addr_start);
  2415.       if (cond_start)
  2416.     b->cond_string = savestring (cond_start, cond_end - cond_start);
  2417.                      
  2418.       b->enable = enabled;
  2419.       b->disposition = tempflag ? del : donttouch;
  2420.  
  2421.       mention (b);
  2422.     }
  2423.  
  2424.   if (sals.nelts > 1)
  2425.     {
  2426.       printf_filtered ("Multiple breakpoints were set.\n");
  2427.       printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  2428.     }
  2429.   do_cleanups (old_chain);
  2430. }
  2431.  
  2432. /* Helper function for break_command_1 and disassemble_command.  */
  2433.  
  2434. void
  2435. resolve_sal_pc (sal)
  2436.      struct symtab_and_line *sal;
  2437. {
  2438.   CORE_ADDR pc;
  2439.  
  2440.   if (sal->pc == 0 && sal->symtab != 0)
  2441.     {
  2442.       pc = find_line_pc (sal->symtab, sal->line);
  2443.       if (pc == 0)
  2444.     error ("No line %d in file \"%s\".",
  2445.            sal->line, sal->symtab->filename);
  2446.       sal->pc = pc;
  2447.     }
  2448. }
  2449.  
  2450. #define BP_TEMPFLAG 1
  2451. #define BP_HARDWAREFLAG 2
  2452. void
  2453. break_command (arg, from_tty)
  2454.      char *arg;
  2455.      int from_tty;
  2456. {
  2457.   break_command_1 (arg, 0, from_tty);
  2458. }
  2459.  
  2460. static void
  2461. tbreak_command (arg, from_tty)
  2462.      char *arg;
  2463.      int from_tty;
  2464. {
  2465.   break_command_1 (arg, BP_TEMPFLAG, from_tty);
  2466. }
  2467.  
  2468. static void
  2469. hbreak_command (arg, from_tty)
  2470.      char *arg;
  2471.      int from_tty;
  2472. {
  2473.   break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
  2474. }
  2475.  
  2476. static void
  2477. thbreak_command (arg, from_tty)
  2478.      char *arg;
  2479.      int from_tty;
  2480. {
  2481.   break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
  2482. }
  2483.  
  2484. /* ARGSUSED */
  2485. /* accessflag:  0: watch write, 1: watch read, 2: watch access(read or write)
  2486. */
  2487. static void
  2488. watch_command_1 (arg, accessflag, from_tty)
  2489.      char *arg;
  2490.      int accessflag;
  2491.      int from_tty;
  2492. {
  2493.   struct breakpoint *b;
  2494.   struct symtab_and_line sal;
  2495.   struct expression *exp;
  2496.   struct block *exp_valid_block;
  2497.   struct value *val, *mark;
  2498.   struct frame_info *frame, *prev_frame;
  2499.   char *exp_start = NULL;
  2500.   char *exp_end = NULL;
  2501.   char *tok, *end_tok;
  2502.   int toklen;
  2503.   char *cond_start = NULL;
  2504.   char *cond_end = NULL;
  2505.   struct expression *cond = NULL;
  2506.   int i, other_type_used, target_resources_ok;
  2507.   enum bptype bp_type;
  2508.   int mem_cnt = 0;
  2509.  
  2510.   sal.pc = 0;
  2511.   sal.symtab = NULL;
  2512.   sal.line = 0;
  2513.   
  2514.   /* Parse arguments.  */
  2515.   innermost_block = NULL;
  2516.   exp_start = arg;
  2517.   exp = parse_exp_1 (&arg, 0, 0);
  2518.   exp_end = arg;
  2519.   exp_valid_block = innermost_block;
  2520.   mark = value_mark ();
  2521.   val = evaluate_expression (exp);
  2522.   release_value (val);
  2523.   if (VALUE_LAZY (val))
  2524.     value_fetch_lazy (val);
  2525.  
  2526.   tok = arg;
  2527.   while (*tok == ' ' || *tok == '\t')
  2528.     tok++;
  2529.   end_tok = tok;
  2530.  
  2531.   while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
  2532.     end_tok++;
  2533.  
  2534.   toklen = end_tok - tok;
  2535.   if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
  2536.     {
  2537.       tok = cond_start = end_tok + 1;
  2538.       cond = parse_exp_1 (&tok, 0, 0);
  2539.       cond_end = tok;
  2540.     }
  2541.   if (*tok)
  2542.     error("Junk at end of command.");
  2543.  
  2544.   if (accessflag == 1) bp_type = bp_read_watchpoint;
  2545.   else if (accessflag == 2) bp_type = bp_access_watchpoint;
  2546.   else bp_type = bp_hardware_watchpoint;
  2547.  
  2548.   mem_cnt = can_use_hardware_watchpoint (val);
  2549.   if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
  2550.     error ("Expression cannot be implemented with read/access watchpoint.");
  2551.   if (mem_cnt != 0) { 
  2552.     i = hw_watchpoint_used_count (bp_type, &other_type_used);
  2553.     target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
  2554.         bp_type, i + mem_cnt, other_type_used);
  2555.     if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
  2556.       error ("Target does not have this type of hardware watchpoint support.");
  2557.     if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
  2558.       error ("Target resources have been allocated for other types of watchpoints.");
  2559.   }
  2560.   
  2561.   /* Now set up the breakpoint.  */
  2562.   b = set_raw_breakpoint (sal);
  2563.   set_breakpoint_count (breakpoint_count + 1);
  2564.   b->number = breakpoint_count;
  2565.   b->disposition = donttouch;
  2566.   b->exp = exp;
  2567.   b->exp_valid_block = exp_valid_block;
  2568.   b->exp_string = savestring (exp_start, exp_end - exp_start);
  2569.   b->val = val;
  2570.   b->cond = cond;
  2571.   if (cond_start)
  2572.     b->cond_string = savestring (cond_start, cond_end - cond_start);
  2573.   else
  2574.     b->cond_string = 0;
  2575.          
  2576.   frame = block_innermost_frame (exp_valid_block);
  2577.   if (frame)
  2578.     {
  2579.       prev_frame = get_prev_frame (frame);
  2580.       b->watchpoint_frame = frame->frame;
  2581.     }
  2582.   else
  2583.     b->watchpoint_frame = (CORE_ADDR)0;
  2584.  
  2585.   if (mem_cnt && target_resources_ok > 0)
  2586.     b->type = bp_type;
  2587.   else
  2588.     b->type = bp_watchpoint;
  2589.  
  2590.   /* If the expression is "local", then set up a "watchpoint scope"
  2591.      breakpoint at the point where we've left the scope of the watchpoint
  2592.      expression.  */
  2593.   if (innermost_block)
  2594.     {
  2595.       struct breakpoint *scope_breakpoint;
  2596.       struct symtab_and_line scope_sal;
  2597.  
  2598.       if (prev_frame)
  2599.     {
  2600.       scope_sal.pc = get_frame_pc (prev_frame);
  2601.       scope_sal.symtab = NULL;
  2602.       scope_sal.line = 0;
  2603.       
  2604.       scope_breakpoint = set_raw_breakpoint (scope_sal);
  2605.       set_breakpoint_count (breakpoint_count + 1);
  2606.       scope_breakpoint->number = breakpoint_count;
  2607.  
  2608.       scope_breakpoint->type = bp_watchpoint_scope;
  2609.       scope_breakpoint->enable = enabled;
  2610.  
  2611.       /* Automatically delete the breakpoint when it hits.  */
  2612.       scope_breakpoint->disposition = del;
  2613.  
  2614.       /* Only break in the proper frame (help with recursion).  */
  2615.       scope_breakpoint->frame = prev_frame->frame;
  2616.  
  2617.       /* Set the address at which we will stop.  */
  2618.       scope_breakpoint->address = get_frame_pc (prev_frame);
  2619.  
  2620.       /* The scope breakpoint is related to the watchpoint.  We
  2621.          will need to act on them together.  */
  2622.       b->related_breakpoint = scope_breakpoint;
  2623.     }
  2624.     }
  2625.   value_free_to_mark (mark);
  2626.   mention (b);
  2627. }
  2628.  
  2629. /* Return count of locations need to be watched and can be handled
  2630.    in hardware.  If the watchpoint can not be handled
  2631.    in hardware return zero.  */
  2632.  
  2633. static int
  2634. can_use_hardware_watchpoint (v)
  2635.      struct value *v;
  2636. {
  2637.   int found_memory_cnt = 0;
  2638.     
  2639.   /* Make sure all the intermediate values are in memory.  Also make sure
  2640.      we found at least one memory expression.  Guards against watch 0x12345,
  2641.      which is meaningless, but could cause errors if one tries to insert a 
  2642.      hardware watchpoint for the constant expression.  */
  2643.   for ( ; v; v = v->next)
  2644.     {
  2645.       if (v->lval == lval_memory)
  2646.     {
  2647.       if (TYPE_LENGTH (VALUE_TYPE (v)) <= REGISTER_SIZE)
  2648.         found_memory_cnt++;
  2649.         }
  2650.       else if (v->lval != not_lval && v->modifiable == 0)
  2651.     return 0;
  2652.     }
  2653.  
  2654.   /* The expression itself looks suitable for using a hardware
  2655.      watchpoint, but give the target machine a chance to reject it.  */
  2656.   return found_memory_cnt;
  2657. }
  2658.  
  2659. static void watch_command (arg, from_tty)
  2660.      char *arg;
  2661.      int from_tty;
  2662. {
  2663.   watch_command_1 (arg, 0, from_tty);
  2664. }
  2665.  
  2666. static void rwatch_command (arg, from_tty)
  2667.      char *arg;
  2668.      int from_tty;
  2669. {
  2670.   watch_command_1 (arg, 1, from_tty);
  2671. }
  2672.  
  2673. static void awatch_command (arg, from_tty)
  2674.      char *arg;
  2675.      int from_tty;
  2676. {
  2677.   watch_command_1 (arg, 2, from_tty);
  2678. }
  2679.  
  2680.  
  2681. /* Helper routine for the until_command routine in infcmd.c.  Here
  2682.    because it uses the mechanisms of breakpoints.  */
  2683.  
  2684. /* ARGSUSED */
  2685. void
  2686. until_break_command (arg, from_tty)
  2687.      char *arg;
  2688.      int from_tty;
  2689. {
  2690.   struct symtabs_and_lines sals;
  2691.   struct symtab_and_line sal;
  2692.   struct frame_info *prev_frame = get_prev_frame (selected_frame);
  2693.   struct breakpoint *breakpoint;
  2694.   struct cleanup *old_chain;
  2695.  
  2696.   clear_proceed_status ();
  2697.  
  2698.   /* Set a breakpoint where the user wants it and at return from
  2699.      this function */
  2700.   
  2701.   if (default_breakpoint_valid)
  2702.     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  2703.               default_breakpoint_line, (char ***)NULL);
  2704.   else
  2705.     sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL);
  2706.   
  2707.   if (sals.nelts != 1)
  2708.     error ("Couldn't get information on specified line.");
  2709.   
  2710.   sal = sals.sals[0];
  2711.   free ((PTR)sals.sals);        /* malloc'd, so freed */
  2712.   
  2713.   if (*arg)
  2714.     error ("Junk at end of arguments.");
  2715.   
  2716.   resolve_sal_pc (&sal);
  2717.   
  2718.   breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
  2719.   
  2720.   old_chain = make_cleanup(delete_breakpoint, breakpoint);
  2721.  
  2722.   /* Keep within the current frame */
  2723.   
  2724.   if (prev_frame)
  2725.     {
  2726.       sal = find_pc_line (prev_frame->pc, 0);
  2727.       sal.pc = prev_frame->pc;
  2728.       breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
  2729.       make_cleanup(delete_breakpoint, breakpoint);
  2730.     }
  2731.   
  2732.   proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
  2733.   do_cleanups(old_chain);
  2734. }
  2735.  
  2736. #if 0
  2737. /* These aren't used; I don't konw what they were for.  */
  2738. /* Set a breakpoint at the catch clause for NAME.  */
  2739. static int
  2740. catch_breakpoint (name)
  2741.      char *name;
  2742. {
  2743. }
  2744.  
  2745. static int
  2746. disable_catch_breakpoint ()
  2747. {
  2748. }
  2749.  
  2750. static int
  2751. delete_catch_breakpoint ()
  2752. {
  2753. }
  2754.  
  2755. static int
  2756. enable_catch_breakpoint ()
  2757. {
  2758. }
  2759. #endif /* 0 */
  2760.  
  2761. struct sal_chain
  2762. {
  2763.   struct sal_chain *next;
  2764.   struct symtab_and_line sal;
  2765. };
  2766.  
  2767. #if 0
  2768. /* This isn't used; I don't know what it was for.  */
  2769. /* For each catch clause identified in ARGS, run FUNCTION
  2770.    with that clause as an argument.  */
  2771. static struct symtabs_and_lines
  2772. map_catch_names (args, function)
  2773.      char *args;
  2774.      int (*function)();
  2775. {
  2776.   register char *p = args;
  2777.   register char *p1;
  2778.   struct symtabs_and_lines sals;
  2779. #if 0
  2780.   struct sal_chain *sal_chain = 0;
  2781. #endif
  2782.  
  2783.   if (p == 0)
  2784.     error_no_arg ("one or more catch names");
  2785.  
  2786.   sals.nelts = 0;
  2787.   sals.sals = NULL;
  2788.  
  2789.   while (*p)
  2790.     {
  2791.       p1 = p;
  2792.       /* Don't swallow conditional part.  */
  2793.       if (p1[0] == 'i' && p1[1] == 'f'
  2794.       && (p1[2] == ' ' || p1[2] == '\t'))
  2795.     break;
  2796.  
  2797.       if (isalpha (*p1))
  2798.     {
  2799.       p1++;
  2800.       while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
  2801.         p1++;
  2802.     }
  2803.  
  2804.       if (*p1 && *p1 != ' ' && *p1 != '\t')
  2805.     error ("Arguments must be catch names.");
  2806.  
  2807.       *p1 = 0;
  2808. #if 0
  2809.       if (function (p))
  2810.     {
  2811.       struct sal_chain *next
  2812.         = (struct sal_chain *)alloca (sizeof (struct sal_chain));
  2813.       next->next = sal_chain;
  2814.       next->sal = get_catch_sal (p);
  2815.       sal_chain = next;
  2816.       goto win;
  2817.     }
  2818. #endif
  2819.       printf_unfiltered ("No catch clause for exception %s.\n", p);
  2820. #if 0
  2821.     win:
  2822. #endif
  2823.       p = p1;
  2824.       while (*p == ' ' || *p == '\t') p++;
  2825.     }
  2826. }
  2827. #endif /* 0 */
  2828.  
  2829. /* This shares a lot of code with `print_frame_label_vars' from stack.c.  */
  2830.  
  2831. static struct symtabs_and_lines
  2832. get_catch_sals (this_level_only)
  2833.      int this_level_only;
  2834. {
  2835.   register struct blockvector *bl;
  2836.   register struct block *block;
  2837.   int index, have_default = 0;
  2838.   CORE_ADDR pc;
  2839.   struct symtabs_and_lines sals;
  2840.   struct sal_chain *sal_chain = 0;
  2841.   char *blocks_searched;
  2842.  
  2843.   /* Not sure whether an error message is always the correct response,
  2844.      but it's better than a core dump.  */
  2845.   if (selected_frame == NULL)
  2846.     error ("No selected frame.");
  2847.   block = get_frame_block (selected_frame);
  2848.   pc = selected_frame->pc;
  2849.  
  2850.   sals.nelts = 0;
  2851.   sals.sals = NULL;
  2852.  
  2853.   if (block == 0)
  2854.     error ("No symbol table info available.\n");
  2855.  
  2856.   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
  2857.   blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  2858.   memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  2859.  
  2860.   while (block != 0)
  2861.     {
  2862.       CORE_ADDR end = BLOCK_END (block) - 4;
  2863.       int last_index;
  2864.  
  2865.       if (bl != blockvector_for_pc (end, &index))
  2866.     error ("blockvector blotch");
  2867.       if (BLOCKVECTOR_BLOCK (bl, index) != block)
  2868.     error ("blockvector botch");
  2869.       last_index = BLOCKVECTOR_NBLOCKS (bl);
  2870.       index += 1;
  2871.  
  2872.       /* Don't print out blocks that have gone by.  */
  2873.       while (index < last_index
  2874.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
  2875.     index++;
  2876.  
  2877.       while (index < last_index
  2878.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
  2879.     {
  2880.       if (blocks_searched[index] == 0)
  2881.         {
  2882.           struct block *b = BLOCKVECTOR_BLOCK (bl, index);
  2883.           int nsyms;
  2884.           register int i;
  2885.           register struct symbol *sym;
  2886.  
  2887.           nsyms = BLOCK_NSYMS (b);
  2888.  
  2889.           for (i = 0; i < nsyms; i++)
  2890.         {
  2891.           sym = BLOCK_SYM (b, i);
  2892.           if (STREQ (SYMBOL_NAME (sym), "default"))
  2893.             {
  2894.               if (have_default)
  2895.             continue;
  2896.               have_default = 1;
  2897.             }
  2898.           if (SYMBOL_CLASS (sym) == LOC_LABEL)
  2899.             {
  2900.               struct sal_chain *next = (struct sal_chain *)
  2901.             alloca (sizeof (struct sal_chain));
  2902.               next->next = sal_chain;
  2903.               next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
  2904.               sal_chain = next;
  2905.             }
  2906.         }
  2907.           blocks_searched[index] = 1;
  2908.         }
  2909.       index++;
  2910.     }
  2911.       if (have_default)
  2912.     break;
  2913.       if (sal_chain && this_level_only)
  2914.     break;
  2915.  
  2916.       /* After handling the function's top-level block, stop.
  2917.      Don't continue to its superblock, the block of
  2918.      per-file symbols.  */
  2919.       if (BLOCK_FUNCTION (block))
  2920.     break;
  2921.       block = BLOCK_SUPERBLOCK (block);
  2922.     }
  2923.  
  2924.   if (sal_chain)
  2925.     {
  2926.       struct sal_chain *tmp_chain;
  2927.  
  2928.       /* Count the number of entries.  */
  2929.       for (index = 0, tmp_chain = sal_chain; tmp_chain;
  2930.        tmp_chain = tmp_chain->next)
  2931.     index++;
  2932.  
  2933.       sals.nelts = index;
  2934.       sals.sals = (struct symtab_and_line *)
  2935.     xmalloc (index * sizeof (struct symtab_and_line));
  2936.       for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
  2937.     sals.sals[index] = sal_chain->sal;
  2938.     }
  2939.  
  2940.   return sals;
  2941. }
  2942.  
  2943. /* Commands to deal with catching exceptions.  */
  2944.  
  2945. static void
  2946. catch_command_1 (arg, tempflag, from_tty)
  2947.      char *arg;
  2948.      int tempflag;
  2949.      int from_tty;
  2950. {
  2951.   /* First, translate ARG into something we can deal with in terms
  2952.      of breakpoints.  */
  2953.  
  2954.   struct symtabs_and_lines sals;
  2955.   struct symtab_and_line sal;
  2956.   register struct expression *cond = 0;
  2957.   register struct breakpoint *b;
  2958.   char *save_arg;
  2959.   int i;
  2960.  
  2961.   sal.line = sal.pc = sal.end = 0;
  2962.   sal.symtab = 0;
  2963.  
  2964.   /* If no arg given, or if first arg is 'if ', all active catch clauses
  2965.      are breakpointed. */
  2966.  
  2967.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  2968.            && (arg[2] == ' ' || arg[2] == '\t')))
  2969.     {
  2970.       /* Grab all active catch clauses.  */
  2971.       sals = get_catch_sals (0);
  2972.     }
  2973.   else
  2974.     {
  2975.       /* Grab selected catch clauses.  */
  2976.       error ("catch NAME not implemented");
  2977. #if 0
  2978.       /* This isn't used; I don't know what it was for.  */
  2979.       sals = map_catch_names (arg, catch_breakpoint);
  2980. #endif
  2981.     }
  2982.  
  2983.   if (! sals.nelts) 
  2984.     return;
  2985.  
  2986.   save_arg = arg;
  2987.   for (i = 0; i < sals.nelts; i++)
  2988.     {
  2989.       resolve_sal_pc (&sals.sals[i]);
  2990.       
  2991.       while (arg && *arg)
  2992.     {
  2993.       if (arg[0] == 'i' && arg[1] == 'f'
  2994.           && (arg[2] == ' ' || arg[2] == '\t'))
  2995.         cond = parse_exp_1 ((arg += 2, &arg), 
  2996.                 block_for_pc (sals.sals[i].pc), 0);
  2997.       else
  2998.         error ("Junk at end of arguments.");
  2999.     }
  3000.       arg = save_arg;
  3001.     }
  3002.  
  3003.   for (i = 0; i < sals.nelts; i++)
  3004.     {
  3005.       sal = sals.sals[i];
  3006.  
  3007.       if (from_tty)
  3008.     describe_other_breakpoints (sal.pc);
  3009.  
  3010.       b = set_raw_breakpoint (sal);
  3011.       set_breakpoint_count (breakpoint_count + 1);
  3012.       b->number = breakpoint_count;
  3013.       b->type = bp_breakpoint;
  3014.       b->cond = cond;
  3015.       b->enable = enabled;
  3016.       b->disposition = tempflag ? del : donttouch;
  3017.  
  3018.       mention (b);
  3019.     }
  3020.  
  3021.   if (sals.nelts > 1)
  3022.     {
  3023.       printf_unfiltered ("Multiple breakpoints were set.\n");
  3024.       printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  3025.     }
  3026.   free ((PTR)sals.sals);
  3027. }
  3028.  
  3029. /* Used by the gui, could be made a worker for other things. */
  3030.  
  3031. struct breakpoint *
  3032. set_breakpoint_sal (sal)
  3033. struct symtab_and_line sal;
  3034. {
  3035.   struct breakpoint *b;
  3036.   b = set_raw_breakpoint (sal);
  3037.   set_breakpoint_count (breakpoint_count + 1);
  3038.   b->number = breakpoint_count;
  3039.   b->type = bp_breakpoint;
  3040.   b->cond = 0;
  3041.   b->thread = -1;
  3042.   return b;
  3043. }
  3044.  
  3045. #if 0
  3046. /* These aren't used; I don't know what they were for.  */
  3047. /* Disable breakpoints on all catch clauses described in ARGS.  */
  3048. static void
  3049. disable_catch (args)
  3050.      char *args;
  3051. {
  3052.   /* Map the disable command to catch clauses described in ARGS.  */
  3053. }
  3054.  
  3055. /* Enable breakpoints on all catch clauses described in ARGS.  */
  3056. static void
  3057. enable_catch (args)
  3058.      char *args;
  3059. {
  3060.   /* Map the disable command to catch clauses described in ARGS.  */
  3061. }
  3062.  
  3063. /* Delete breakpoints on all catch clauses in the active scope.  */
  3064. static void
  3065. delete_catch (args)
  3066.      char *args;
  3067. {
  3068.   /* Map the delete command to catch clauses described in ARGS.  */
  3069. }
  3070. #endif /* 0 */
  3071.  
  3072. static void
  3073. catch_command (arg, from_tty)
  3074.      char *arg;
  3075.      int from_tty;
  3076. {
  3077.   catch_command_1 (arg, 0, from_tty);
  3078. }
  3079.  
  3080. static void
  3081. clear_command (arg, from_tty)
  3082.      char *arg;
  3083.      int from_tty;
  3084. {
  3085.   register struct breakpoint *b, *b1;
  3086.   struct symtabs_and_lines sals;
  3087.   struct symtab_and_line sal;
  3088.   register struct breakpoint *found;
  3089.   int i;
  3090.  
  3091.   if (arg)
  3092.     {
  3093.       sals = decode_line_spec (arg, 1);
  3094.     }
  3095.   else
  3096.     {
  3097.       sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
  3098.       sal.line = default_breakpoint_line;
  3099.       sal.symtab = default_breakpoint_symtab;
  3100.       sal.pc = 0;
  3101.       if (sal.symtab == 0)
  3102.     error ("No source file specified.");
  3103.  
  3104.       sals.sals[0] = sal;
  3105.       sals.nelts = 1;
  3106.     }
  3107.  
  3108.   for (i = 0; i < sals.nelts; i++)
  3109.     {
  3110.       /* If exact pc given, clear bpts at that pc.
  3111.      But if sal.pc is zero, clear all bpts on specified line.  */
  3112.       sal = sals.sals[i];
  3113.       found = (struct breakpoint *) 0;
  3114.       while (breakpoint_chain
  3115.          && (sal.pc
  3116.          ? breakpoint_chain->address == sal.pc
  3117.          : (breakpoint_chain->source_file != NULL
  3118.             && sal.symtab != NULL
  3119.             && STREQ (breakpoint_chain->source_file,
  3120.                   sal.symtab->filename)
  3121.             && breakpoint_chain->line_number == sal.line)))
  3122.     {
  3123.       b1 = breakpoint_chain;
  3124.       breakpoint_chain = b1->next;
  3125.       b1->next = found;
  3126.       found = b1;
  3127.     }
  3128.  
  3129.       ALL_BREAKPOINTS (b)
  3130.     while (b->next
  3131.            && b->next->type != bp_watchpoint
  3132.            && b->next->type != bp_hardware_watchpoint
  3133.            && b->next->type != bp_read_watchpoint
  3134.            && b->next->type != bp_access_watchpoint
  3135.            && (sal.pc
  3136.            ? b->next->address == sal.pc
  3137.            : (b->next->source_file != NULL
  3138.               && sal.symtab != NULL
  3139.               && STREQ (b->next->source_file, sal.symtab->filename)
  3140.               && b->next->line_number == sal.line)))
  3141.       {
  3142.         b1 = b->next;
  3143.         b->next = b1->next;
  3144.         b1->next = found;
  3145.         found = b1;
  3146.       }
  3147.  
  3148.       if (found == 0)
  3149.     {
  3150.       if (arg)
  3151.         error ("No breakpoint at %s.", arg);
  3152.       else
  3153.         error ("No breakpoint at this line.");
  3154.     }
  3155.  
  3156.       if (found->next) from_tty = 1; /* Always report if deleted more than one */
  3157.       if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
  3158.       breakpoints_changed ();
  3159.       while (found)
  3160.     {
  3161.       if (from_tty) printf_unfiltered ("%d ", found->number);
  3162.       b1 = found->next;
  3163.       delete_breakpoint (found);
  3164.       found = b1;
  3165.     }
  3166.       if (from_tty) putchar_unfiltered ('\n');
  3167.     }
  3168.   free ((PTR)sals.sals);
  3169. }
  3170.  
  3171. /* Delete breakpoint in BS if they are `delete' breakpoints.
  3172.    This is called after any breakpoint is hit, or after errors.  */
  3173.  
  3174. void
  3175. breakpoint_auto_delete (bs)
  3176.      bpstat bs;
  3177. {
  3178.   for (; bs; bs = bs->next)
  3179.     if (bs->breakpoint_at && bs->breakpoint_at->disposition == del 
  3180.     && bs->stop)
  3181.       delete_breakpoint (bs->breakpoint_at);
  3182. }
  3183.  
  3184. /* Delete a breakpoint and clean up all traces of it in the data structures. */
  3185.  
  3186. void
  3187. delete_breakpoint (bpt)
  3188.      struct breakpoint *bpt;
  3189. {
  3190.   register struct breakpoint *b;
  3191.   register bpstat bs;
  3192.  
  3193.   if (delete_breakpoint_hook)
  3194.     delete_breakpoint_hook (bpt);
  3195.  
  3196.   if (bpt->inserted)
  3197.     remove_breakpoint (bpt);
  3198.       
  3199.   if (breakpoint_chain == bpt)
  3200.     breakpoint_chain = bpt->next;
  3201.  
  3202.   ALL_BREAKPOINTS (b)
  3203.     if (b->next == bpt)
  3204.       {
  3205.     b->next = bpt->next;
  3206.     break;
  3207.       }
  3208.  
  3209.   check_duplicates (bpt->address);
  3210.   /* If this breakpoint was inserted, and there is another breakpoint
  3211.      at the same address, we need to insert the other breakpoint.  */
  3212.   if (bpt->inserted
  3213.       && bpt->type != bp_hardware_watchpoint
  3214.       && bpt->type != bp_read_watchpoint
  3215.       && bpt->type != bp_access_watchpoint)
  3216.     {
  3217.       ALL_BREAKPOINTS (b)
  3218.     if (b->address == bpt->address
  3219.         && !b->duplicate
  3220.         && b->enable != disabled)
  3221.       {
  3222.         int val;
  3223.         val = target_insert_breakpoint (b->address, b->shadow_contents);
  3224.         if (val != 0)
  3225.           {
  3226.         target_terminal_ours_for_output ();
  3227.         fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
  3228.         memory_error (val, b->address);    /* which bombs us out */
  3229.           }
  3230.         else
  3231.           b->inserted = 1;
  3232.       }
  3233.     }
  3234.  
  3235.   free_command_lines (&bpt->commands);
  3236.   if (bpt->cond)
  3237.     free (bpt->cond);
  3238.   if (bpt->cond_string != NULL)
  3239.     free (bpt->cond_string);
  3240.   if (bpt->addr_string != NULL)
  3241.     free (bpt->addr_string);
  3242.   if (bpt->exp_string != NULL)
  3243.     free (bpt->exp_string);
  3244.   if (bpt->source_file != NULL)
  3245.     free (bpt->source_file);
  3246.  
  3247.   /* Be sure no bpstat's are pointing at it after it's been freed.  */
  3248.   /* FIXME, how can we find all bpstat's?
  3249.      We just check stop_bpstat for now.  */
  3250.   for (bs = stop_bpstat; bs; bs = bs->next)
  3251.     if (bs->breakpoint_at == bpt)
  3252.       bs->breakpoint_at = NULL;
  3253.   free ((PTR)bpt);
  3254. }
  3255.  
  3256. static void
  3257. delete_command (arg, from_tty)
  3258.      char *arg;
  3259.      int from_tty;
  3260. {
  3261.  
  3262.   if (arg == 0)
  3263.     {
  3264.       /* Ask user only if there are some breakpoints to delete.  */
  3265.       if (!from_tty
  3266.       || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
  3267.     {
  3268.       /* No arg; clear all breakpoints.  */
  3269.       while (breakpoint_chain)
  3270.         delete_breakpoint (breakpoint_chain);
  3271.     }
  3272.     }
  3273.   else
  3274.     map_breakpoint_numbers (arg, delete_breakpoint);
  3275. }
  3276.  
  3277. /* Reset a breakpoint given it's struct breakpoint * BINT.
  3278.    The value we return ends up being the return value from catch_errors.
  3279.    Unused in this case.  */
  3280.  
  3281. static int
  3282. breakpoint_re_set_one (bint)
  3283.      char *bint;
  3284. {
  3285.   struct breakpoint *b = (struct breakpoint *)bint;  /* get past catch_errs */
  3286.   struct value *mark;
  3287.   int i;
  3288.   struct symtabs_and_lines sals;
  3289.   char *s;
  3290.   enum enable save_enable;
  3291.  
  3292.   switch (b->type)
  3293.     {
  3294.     case bp_breakpoint:
  3295.     case bp_hardware_breakpoint:
  3296.       if (b->addr_string == NULL)
  3297.     {
  3298.       /* Anything without a string can't be re-set. */
  3299.       delete_breakpoint (b);
  3300.       return 0;
  3301.     }
  3302.       /* In case we have a problem, disable this breakpoint.  We'll restore
  3303.      its status if we succeed.  */
  3304.       save_enable = b->enable;
  3305.       b->enable = disabled;
  3306.  
  3307.       set_language (b->language);
  3308.       input_radix = b->input_radix;
  3309.       s = b->addr_string;
  3310.       sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL);
  3311.       for (i = 0; i < sals.nelts; i++)
  3312.     {
  3313.       resolve_sal_pc (&sals.sals[i]);
  3314.  
  3315.       /* Reparse conditions, they might contain references to the
  3316.          old symtab.  */
  3317.       if (b->cond_string != NULL)
  3318.         {
  3319.           s = b->cond_string;
  3320.           if (b->cond)
  3321.         free ((PTR)b->cond);
  3322.           b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
  3323.         }
  3324.  
  3325.       /* We need to re-set the breakpoint if the address changes...*/
  3326.       if (b->address != sals.sals[i].pc
  3327.           /* ...or new and old breakpoints both have source files, and
  3328.          the source file name or the line number changes...  */
  3329.           || (b->source_file != NULL
  3330.           && sals.sals[i].symtab != NULL
  3331.           && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
  3332.               || b->line_number != sals.sals[i].line)
  3333.           )
  3334.           /* ...or we switch between having a source file and not having
  3335.          one.  */
  3336.           || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
  3337.           )
  3338.         {
  3339.           if (b->source_file != NULL)
  3340.         free (b->source_file);
  3341.           if (sals.sals[i].symtab == NULL)
  3342.         b->source_file = NULL;
  3343.           else
  3344.         b->source_file =
  3345.           savestring (sals.sals[i].symtab->filename,
  3346.                   strlen (sals.sals[i].symtab->filename));
  3347.           b->line_number = sals.sals[i].line;
  3348.           b->address = sals.sals[i].pc;
  3349.       
  3350.           check_duplicates (b->address);
  3351.  
  3352.           mention (b);
  3353.  
  3354.           /* Might be better to do this just once per breakpoint_re_set,
  3355.          rather than once for every breakpoint.  */
  3356.           breakpoints_changed ();
  3357.         }
  3358.       b->enable = save_enable;    /* Restore it, this worked. */
  3359.     }
  3360.       free ((PTR)sals.sals);
  3361.       break;
  3362.  
  3363.     case bp_watchpoint:
  3364.     case bp_hardware_watchpoint:
  3365.     case bp_read_watchpoint:
  3366.     case bp_access_watchpoint:
  3367.       innermost_block = NULL;
  3368.       /* The issue arises of what context to evaluate this in.  The same
  3369.      one as when it was set, but what does that mean when symbols have
  3370.      been re-read?  We could save the filename and functionname, but
  3371.      if the context is more local than that, the best we could do would
  3372.      be something like how many levels deep and which index at that
  3373.      particular level, but that's going to be less stable than filenames
  3374.      or functionnames.  */
  3375.       /* So for now, just use a global context.  */
  3376.       b->exp = parse_expression (b->exp_string);
  3377.       b->exp_valid_block = innermost_block;
  3378.       mark = value_mark ();
  3379.       b->val = evaluate_expression (b->exp);
  3380.       release_value (b->val);
  3381.       if (VALUE_LAZY (b->val))
  3382.     value_fetch_lazy (b->val);
  3383.  
  3384.       if (b->cond_string != NULL)
  3385.     {
  3386.       s = b->cond_string;
  3387.       b->cond = parse_exp_1 (&s, (struct block *)0, 0);
  3388.     }
  3389.       if (b->enable == enabled)
  3390.     mention (b);
  3391.       value_free_to_mark (mark);
  3392.       break;
  3393.  
  3394.     default:
  3395.       printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
  3396.       /* fall through */
  3397.     case bp_until:
  3398.     case bp_finish:
  3399.     case bp_longjmp:
  3400.     case bp_longjmp_resume:
  3401.     case bp_watchpoint_scope:
  3402.     case bp_call_dummy:
  3403.       delete_breakpoint (b);
  3404.       break;
  3405.     }
  3406.  
  3407.   return 0;
  3408. }
  3409.  
  3410. /* Re-set all breakpoints after symbols have been re-loaded.  */
  3411. void
  3412. breakpoint_re_set ()
  3413. {
  3414.   struct breakpoint *b, *temp;
  3415.   enum language save_language;
  3416.   int save_input_radix;
  3417.   static char message1[] = "Error in re-setting breakpoint %d:\n";
  3418.   char message[sizeof (message1) + 30 /* slop */];
  3419.   
  3420.   save_language = current_language->la_language;
  3421.   save_input_radix = input_radix;
  3422.   ALL_BREAKPOINTS_SAFE (b, temp)
  3423.     {
  3424.       sprintf (message, message1, b->number);    /* Format possible error msg */
  3425.       catch_errors (breakpoint_re_set_one, (char *) b, message,
  3426.             RETURN_MASK_ALL);
  3427.     }
  3428.   set_language (save_language);
  3429.   input_radix = save_input_radix;
  3430.  
  3431.   create_longjmp_breakpoint("longjmp");
  3432.   create_longjmp_breakpoint("_longjmp");
  3433.   create_longjmp_breakpoint("siglongjmp");
  3434.   create_longjmp_breakpoint(NULL);
  3435.  
  3436. #if 0
  3437.   /* Took this out (temporaliy at least), since it produces an extra 
  3438.      blank line at startup. This messes up the gdbtests. -PB */
  3439.   /* Blank line to finish off all those mention() messages we just printed.  */
  3440.   printf_filtered ("\n");
  3441. #endif
  3442. }
  3443.  
  3444. /* Set ignore-count of breakpoint number BPTNUM to COUNT.
  3445.    If from_tty is nonzero, it prints a message to that effect,
  3446.    which ends with a period (no newline).  */
  3447.  
  3448. void
  3449. set_ignore_count (bptnum, count, from_tty)
  3450.      int bptnum, count, from_tty;
  3451. {
  3452.   register struct breakpoint *b;
  3453.  
  3454.   if (count < 0)
  3455.     count = 0;
  3456.  
  3457.   ALL_BREAKPOINTS (b)
  3458.     if (b->number == bptnum)
  3459.       {
  3460.     b->ignore_count = count;
  3461.     if (!from_tty)
  3462.       return;
  3463.     else if (count == 0)
  3464.       printf_filtered ("Will stop next time breakpoint %d is reached.",
  3465.                bptnum);
  3466.     else if (count == 1)
  3467.       printf_filtered ("Will ignore next crossing of breakpoint %d.",
  3468.                bptnum);
  3469.     else
  3470.       printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
  3471.           count, bptnum);
  3472.     breakpoints_changed ();
  3473.     return;
  3474.       }
  3475.  
  3476.   error ("No breakpoint number %d.", bptnum);
  3477. }
  3478.  
  3479. /* Clear the ignore counts of all breakpoints.  */
  3480. void
  3481. breakpoint_clear_ignore_counts ()
  3482. {
  3483.   struct breakpoint *b;
  3484.  
  3485.   ALL_BREAKPOINTS (b)
  3486.     b->ignore_count = 0;
  3487. }
  3488.  
  3489. /* Command to set ignore-count of breakpoint N to COUNT.  */
  3490.  
  3491. static void
  3492. ignore_command (args, from_tty)
  3493.      char *args;
  3494.      int from_tty;
  3495. {
  3496.   char *p = args;
  3497.   register int num;
  3498.  
  3499.   if (p == 0)
  3500.     error_no_arg ("a breakpoint number");
  3501.   
  3502.   num = get_number (&p);
  3503.  
  3504.   if (*p == 0)
  3505.     error ("Second argument (specified ignore-count) is missing.");
  3506.  
  3507.   set_ignore_count (num,
  3508.             longest_to_int (value_as_long (parse_and_eval (p))),
  3509.             from_tty);
  3510.   printf_filtered ("\n");
  3511.   breakpoints_changed ();
  3512. }
  3513.  
  3514. /* Call FUNCTION on each of the breakpoints
  3515.    whose numbers are given in ARGS.  */
  3516.  
  3517. static void
  3518. map_breakpoint_numbers (args, function)
  3519.      char *args;
  3520.      void (*function) PARAMS ((struct breakpoint *));
  3521. {
  3522.   register char *p = args;
  3523.   char *p1;
  3524.   register int num;
  3525.   register struct breakpoint *b;
  3526.  
  3527.   if (p == 0)
  3528.     error_no_arg ("one or more breakpoint numbers");
  3529.  
  3530.   while (*p)
  3531.     {
  3532.       p1 = p;
  3533.       
  3534.       num = get_number (&p1);
  3535.  
  3536.       ALL_BREAKPOINTS (b)
  3537.     if (b->number == num)
  3538.       {
  3539.         struct breakpoint *related_breakpoint = b->related_breakpoint;
  3540.         function (b);
  3541.         if (related_breakpoint)
  3542.           function (related_breakpoint);
  3543.         goto win;
  3544.       }
  3545.       printf_unfiltered ("No breakpoint number %d.\n", num);
  3546.     win:
  3547.       p = p1;
  3548.     }
  3549. }
  3550.  
  3551. void
  3552. enable_breakpoint (bpt)
  3553.      struct breakpoint *bpt;
  3554. {
  3555.   struct frame_info *save_selected_frame = NULL;
  3556.   int save_selected_frame_level = -1;
  3557.   int target_resources_ok, other_type_used;
  3558.   struct value *mark;
  3559.   
  3560.   if (enable_breakpoint_hook)
  3561.     enable_breakpoint_hook (bpt);
  3562.  
  3563.   if (bpt->type == bp_hardware_breakpoint)
  3564.     {
  3565.       int i;
  3566.       i = hw_breakpoint_used_count();
  3567.       target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( 
  3568.         bp_hardware_breakpoint, i+1, 0);
  3569.       if (target_resources_ok == 0)
  3570.         error ("No hardware breakpoint support in the target.");
  3571.       else if (target_resources_ok < 0)
  3572.         error ("Hardware breakpoints used exceeds limit.");
  3573.     }
  3574.   bpt->enable = enabled;
  3575.   check_duplicates (bpt->address);
  3576.  
  3577.   if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint ||
  3578.       bpt->type == bp_read_watchpoint || bpt->type == bp_access_watchpoint)
  3579.     {
  3580.       if (bpt->exp_valid_block != NULL)
  3581.     {
  3582.       struct frame_info *fr =
  3583.         find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
  3584.       if (fr == NULL)
  3585.         {
  3586.           printf_filtered ("\
  3587. Cannot enable watchpoint %d because the block in which its expression\n\
  3588. is valid is not currently in scope.\n", bpt->number);
  3589.           bpt->enable = disabled;
  3590.           return;
  3591.         }
  3592.  
  3593.       save_selected_frame = selected_frame;
  3594.       save_selected_frame_level = selected_frame_level;
  3595.       select_frame (fr, -1);
  3596.     }
  3597.  
  3598.       value_free (bpt->val);
  3599.       mark = value_mark ();
  3600.       bpt->val = evaluate_expression (bpt->exp);
  3601.       release_value (bpt->val);
  3602.       if (VALUE_LAZY (bpt->val))
  3603.     value_fetch_lazy (bpt->val);
  3604.  
  3605.       if (bpt->type == bp_hardware_watchpoint ||
  3606.            bpt->type == bp_read_watchpoint ||
  3607.            bpt->type == bp_access_watchpoint)
  3608.       {
  3609.         int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
  3610.         int mem_cnt = can_use_hardware_watchpoint (bpt->val);
  3611.  
  3612.         target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
  3613.                 bpt->type, i + mem_cnt, other_type_used);
  3614.         /* we can consider of type is bp_hardware_watchpoint, convert to 
  3615.        bp_watchpoint in the following condition */
  3616.         if (target_resources_ok < 0)
  3617.       {
  3618.              printf_filtered("\
  3619. Cannot enable watchpoint %d because target watch resources\n\
  3620. have been allocated for other watchpoints.\n", bpt->number);
  3621.         bpt->enable = disabled;
  3622.         value_free_to_mark (mark);
  3623.           return;
  3624.           }
  3625.       }
  3626.  
  3627.       if (save_selected_frame_level >= 0)
  3628.     select_frame (save_selected_frame, save_selected_frame_level);
  3629.       value_free_to_mark (mark);
  3630.     }
  3631. }
  3632.  
  3633. /* ARGSUSED */
  3634. static void
  3635. enable_command (args, from_tty)
  3636.      char *args;
  3637.      int from_tty;
  3638. {
  3639.   struct breakpoint *bpt;
  3640.   if (args == 0)
  3641.     ALL_BREAKPOINTS (bpt)
  3642.       switch (bpt->type)
  3643.     {
  3644.     case bp_breakpoint:
  3645.     case bp_hardware_breakpoint:
  3646.     case bp_watchpoint:
  3647.     case bp_hardware_watchpoint:
  3648.     case bp_read_watchpoint:
  3649.     case bp_access_watchpoint:
  3650.       enable_breakpoint (bpt);
  3651.     default:
  3652.       continue;
  3653.     }
  3654.   else
  3655.     map_breakpoint_numbers (args, enable_breakpoint);
  3656. }
  3657.  
  3658. void
  3659. disable_breakpoint (bpt)
  3660.      struct breakpoint *bpt;
  3661. {
  3662.   /* Never disable a watchpoint scope breakpoint; we want to
  3663.      hit them when we leave scope so we can delete both the
  3664.      watchpoint and its scope breakpoint at that time.  */
  3665.   if (bpt->type == bp_watchpoint_scope)
  3666.     return;
  3667.  
  3668.   if (disable_breakpoint_hook)
  3669.     disable_breakpoint_hook (bpt);
  3670.  
  3671.   bpt->enable = disabled;
  3672.  
  3673.   check_duplicates (bpt->address);
  3674. }
  3675.  
  3676. /* ARGSUSED */
  3677. static void
  3678. disable_command (args, from_tty)
  3679.      char *args;
  3680.      int from_tty;
  3681. {
  3682.   register struct breakpoint *bpt;
  3683.   if (args == 0)
  3684.     ALL_BREAKPOINTS (bpt)
  3685.       switch (bpt->type)
  3686.     {
  3687.     case bp_breakpoint:
  3688.         case bp_hardware_breakpoint:
  3689.         case bp_watchpoint:
  3690.         case bp_hardware_watchpoint:
  3691.         case bp_read_watchpoint:
  3692.         case bp_access_watchpoint:
  3693.       disable_breakpoint (bpt);
  3694.     default:
  3695.       continue;
  3696.     }
  3697.   else
  3698.     map_breakpoint_numbers (args, disable_breakpoint);
  3699. }
  3700.  
  3701. static void
  3702. enable_once_breakpoint (bpt)
  3703.      struct breakpoint *bpt;
  3704. {
  3705.   struct frame_info *save_selected_frame = NULL;
  3706.   int save_selected_frame_level = -1;
  3707.   int target_resources_ok, other_type_used;
  3708.   struct value *mark;
  3709.  
  3710.   if (bpt->type == bp_hardware_breakpoint) 
  3711.     {   
  3712.       int i;
  3713.       i = hw_breakpoint_used_count();
  3714.       target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
  3715.         bp_hardware_breakpoint, i+1, 0);
  3716.       if (target_resources_ok == 0)
  3717.         error ("No hardware breakpoint support in the target.");
  3718.       else if (target_resources_ok < 0)
  3719.         error ("Hardware breakpoints used exceeds limit.");
  3720.     }
  3721.  
  3722.   bpt->enable = enabled;
  3723.   bpt->disposition = disable;
  3724.   check_duplicates (bpt->address);
  3725.   breakpoints_changed ();
  3726.  
  3727.   if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint ||
  3728.       bpt->type == bp_read_watchpoint || bpt->type == bp_access_watchpoint)
  3729.     {
  3730.       if (bpt->exp_valid_block != NULL)
  3731.     {
  3732.       struct frame_info *fr =
  3733.         find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
  3734.       if (fr == NULL)
  3735.         {
  3736.           printf_filtered ("\
  3737. Cannot enable watchpoint %d because the block in which its expression\n\
  3738. is valid is not currently in scope.\n", bpt->number);
  3739.           bpt->enable = disabled;
  3740.           return;
  3741.         }
  3742.  
  3743.       save_selected_frame = selected_frame;
  3744.       save_selected_frame_level = selected_frame_level;
  3745.       select_frame (fr, -1);
  3746.     }
  3747.  
  3748.       value_free (bpt->val);
  3749.       mark = value_mark ();
  3750.       bpt->val = evaluate_expression (bpt->exp);
  3751.       release_value (bpt->val);
  3752.       if (VALUE_LAZY (bpt->val))
  3753.     value_fetch_lazy (bpt->val);
  3754.  
  3755.       if (bpt->type == bp_hardware_watchpoint ||
  3756.            bpt->type == bp_read_watchpoint ||
  3757.            bpt->type == bp_access_watchpoint)
  3758.       {
  3759.         int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
  3760.         int mem_cnt = can_use_hardware_watchpoint(bpt->val);
  3761.         target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
  3762.                 bpt->type, i+mem_cnt, other_type_used);
  3763.         /* we can consider of type is bp_hardware_watchpoint, convert to 
  3764.        bp_watchpoint in the following condition */
  3765.         if (target_resources_ok < 0)
  3766.       {
  3767.              printf_filtered("\
  3768. Cannot enable watchpoint %d because target watch resources\n\
  3769. have been allocated for other watchpoints.\n", bpt->number);
  3770.         bpt->enable = disabled;
  3771.         value_free_to_mark (mark);
  3772.           }
  3773.       }
  3774.  
  3775.       if (save_selected_frame_level >= 0)
  3776.     select_frame (save_selected_frame, save_selected_frame_level);
  3777.       value_free_to_mark (mark);
  3778.     }
  3779. }
  3780.  
  3781. /* ARGSUSED */
  3782. static void
  3783. enable_once_command (args, from_tty)
  3784.      char *args;
  3785.      int from_tty;
  3786. {
  3787.   map_breakpoint_numbers (args, enable_once_breakpoint);
  3788. }
  3789.  
  3790. static void
  3791. enable_delete_breakpoint (bpt)
  3792.      struct breakpoint *bpt;
  3793. {
  3794.   bpt->enable = enabled;
  3795.   bpt->disposition = del;
  3796.  
  3797.   check_duplicates (bpt->address);
  3798.   breakpoints_changed ();
  3799. }
  3800.  
  3801. /* ARGSUSED */
  3802. static void
  3803. enable_delete_command (args, from_tty)
  3804.      char *args;
  3805.      int from_tty;
  3806. {
  3807.   map_breakpoint_numbers (args, enable_delete_breakpoint);
  3808. }
  3809.  
  3810. /* Use default_breakpoint_'s, or nothing if they aren't valid.  */
  3811.  
  3812. struct symtabs_and_lines
  3813. decode_line_spec_1 (string, funfirstline)
  3814.      char *string;
  3815.      int funfirstline;
  3816. {
  3817.   struct symtabs_and_lines sals;
  3818.   if (string == 0)
  3819.     error ("Empty line specification.");
  3820.   if (default_breakpoint_valid)
  3821.     sals = decode_line_1 (&string, funfirstline,
  3822.               default_breakpoint_symtab, default_breakpoint_line,
  3823.               (char ***)NULL);
  3824.   else
  3825.     sals = decode_line_1 (&string, funfirstline,
  3826.               (struct symtab *)NULL, 0, (char ***)NULL);
  3827.   if (*string)
  3828.     error ("Junk at end of line specification: %s", string);
  3829.   return sals;
  3830. }
  3831.  
  3832. void
  3833. _initialize_breakpoint ()
  3834. {
  3835.   breakpoint_chain = 0;
  3836.   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
  3837.      before a breakpoint is set.  */
  3838.   breakpoint_count = 0;
  3839.  
  3840.   add_com ("ignore", class_breakpoint, ignore_command,
  3841.        "Set ignore-count of breakpoint number N to COUNT.\n\
  3842. Usage is `ignore N COUNT'.");
  3843.  
  3844.   add_com ("commands", class_breakpoint, commands_command,
  3845.        "Set commands to be executed when a breakpoint is hit.\n\
  3846. Give breakpoint number as argument after \"commands\".\n\
  3847. With no argument, the targeted breakpoint is the last one set.\n\
  3848. The commands themselves follow starting on the next line.\n\
  3849. Type a line containing \"end\" to indicate the end of them.\n\
  3850. Give \"silent\" as the first line to make the breakpoint silent;\n\
  3851. then no output is printed when it is hit, except what the commands print.");
  3852.  
  3853.   add_com ("condition", class_breakpoint, condition_command,
  3854.        "Specify breakpoint number N to break only if COND is true.\n\
  3855. Usage is `condition N COND', where N is an integer and COND is an\n\
  3856. expression to be evaluated whenever breakpoint N is reached.  ");
  3857.  
  3858.   add_com ("tbreak", class_breakpoint, tbreak_command,
  3859.        "Set a temporary breakpoint.  Args like \"break\" command.\n\
  3860. Like \"break\" except the breakpoint is only temporary,\n\
  3861. so it will be deleted when hit.  Equivalent to \"break\" followed\n\
  3862. by using \"enable delete\" on the breakpoint number.");
  3863.  
  3864.   add_com ("hbreak", class_breakpoint, hbreak_command,
  3865.        "Set a hardware assisted  breakpoint. Args like \"break\" command.\n\
  3866. Like \"break\" except the breakpoint requires hardware support,\n\
  3867. some target hardware may not have this support.");
  3868.  
  3869.   add_com ("thbreak", class_breakpoint, thbreak_command,
  3870.        "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
  3871. Like \"hbreak\" except the breakpoint is only temporary,\n\
  3872. so it will be deleted when hit.");
  3873.  
  3874.   add_prefix_cmd ("enable", class_breakpoint, enable_command,
  3875.           "Enable some breakpoints.\n\
  3876. Give breakpoint numbers (separated by spaces) as arguments.\n\
  3877. With no subcommand, breakpoints are enabled until you command otherwise.\n\
  3878. This is used to cancel the effect of the \"disable\" command.\n\
  3879. With a subcommand you can enable temporarily.",
  3880.           &enablelist, "enable ", 1, &cmdlist);
  3881.  
  3882.   add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
  3883.           "Enable some breakpoints.\n\
  3884. Give breakpoint numbers (separated by spaces) as arguments.\n\
  3885. This is used to cancel the effect of the \"disable\" command.\n\
  3886. May be abbreviated to simply \"enable\".\n",
  3887.           &enablebreaklist, "enable breakpoints ", 1, &enablelist);
  3888.  
  3889.   add_cmd ("once", no_class, enable_once_command,
  3890.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  3891. If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
  3892.        &enablebreaklist);
  3893.  
  3894.   add_cmd ("delete", no_class, enable_delete_command,
  3895.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  3896. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  3897.        &enablebreaklist);
  3898.  
  3899.   add_cmd ("delete", no_class, enable_delete_command,
  3900.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  3901. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  3902.        &enablelist);
  3903.  
  3904.   add_cmd ("once", no_class, enable_once_command,
  3905.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  3906. If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
  3907.        &enablelist);
  3908.  
  3909.   add_prefix_cmd ("disable", class_breakpoint, disable_command,
  3910.        "Disable some breakpoints.\n\
  3911. Arguments are breakpoint numbers with spaces in between.\n\
  3912. To disable all breakpoints, give no argument.\n\
  3913. A disabled breakpoint is not forgotten, but has no effect until reenabled.",
  3914.           &disablelist, "disable ", 1, &cmdlist);
  3915.   add_com_alias ("dis", "disable", class_breakpoint, 1);
  3916.   add_com_alias ("disa", "disable", class_breakpoint, 1);
  3917.  
  3918.   add_cmd ("breakpoints", class_alias, disable_command,
  3919.        "Disable some breakpoints.\n\
  3920. Arguments are breakpoint numbers with spaces in between.\n\
  3921. To disable all breakpoints, give no argument.\n\
  3922. A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
  3923. This command may be abbreviated \"disable\".",
  3924.        &disablelist);
  3925.  
  3926.   add_prefix_cmd ("delete", class_breakpoint, delete_command,
  3927.        "Delete some breakpoints or auto-display expressions.\n\
  3928. Arguments are breakpoint numbers with spaces in between.\n\
  3929. To delete all breakpoints, give no argument.\n\
  3930. \n\
  3931. Also a prefix command for deletion of other GDB objects.\n\
  3932. The \"unset\" command is also an alias for \"delete\".",
  3933.           &deletelist, "delete ", 1, &cmdlist);
  3934.   add_com_alias ("d", "delete", class_breakpoint, 1);
  3935.  
  3936.   add_cmd ("breakpoints", class_alias, delete_command,
  3937.        "Delete some breakpoints or auto-display expressions.\n\
  3938. Arguments are breakpoint numbers with spaces in between.\n\
  3939. To delete all breakpoints, give no argument.\n\
  3940. This command may be abbreviated \"delete\".",
  3941.        &deletelist);
  3942.  
  3943.   add_com ("clear", class_breakpoint, clear_command,
  3944.        concat ("Clear breakpoint at specified line or function.\n\
  3945. Argument may be line number, function name, or \"*\" and an address.\n\
  3946. If line number is specified, all breakpoints in that line are cleared.\n\
  3947. If function is specified, breakpoints at beginning of function are cleared.\n\
  3948. If an address is specified, breakpoints at that address are cleared.\n\n",
  3949. "With no argument, clears all breakpoints in the line that the selected frame\n\
  3950. is executing in.\n\
  3951. \n\
  3952. See also the \"delete\" command which clears breakpoints by number.", NULL));
  3953.  
  3954.   add_com ("break", class_breakpoint, break_command,
  3955.        concat ("Set breakpoint at specified line or function.\n\
  3956. Argument may be line number, function name, or \"*\" and an address.\n\
  3957. If line number is specified, break at start of code for that line.\n\
  3958. If function is specified, break at start of code for that function.\n\
  3959. If an address is specified, break at that exact address.\n",
  3960. "With no arg, uses current execution address of selected stack frame.\n\
  3961. This is useful for breaking on return to a stack frame.\n\
  3962. \n\
  3963. Multiple breakpoints at one place are permitted, and useful if conditional.\n\
  3964. \n\
  3965. Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
  3966.   add_com_alias ("b", "break", class_run, 1);
  3967.   add_com_alias ("br", "break", class_run, 1);
  3968.   add_com_alias ("bre", "break", class_run, 1);
  3969.   add_com_alias ("brea", "break", class_run, 1);
  3970.  
  3971.   add_info ("breakpoints", breakpoints_info,
  3972.         concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
  3973. The \"Type\" column indicates one of:\n\
  3974. \tbreakpoint     - normal breakpoint\n\
  3975. \twatchpoint     - watchpoint\n\
  3976. The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
  3977. the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
  3978. breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
  3979. address and file/line number respectively.\n\n",
  3980. "Convenience variable \"$_\" and default examine address for \"x\"\n\
  3981. are set to the address of the last breakpoint listed.\n\n\
  3982. Convenience variable \"$bpnum\" contains the number of the last\n\
  3983. breakpoint set.", NULL));
  3984.  
  3985. #if MAINTENANCE_CMDS
  3986.  
  3987.   add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
  3988.         concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
  3989. The \"Type\" column indicates one of:\n\
  3990. \tbreakpoint     - normal breakpoint\n\
  3991. \twatchpoint     - watchpoint\n\
  3992. \tlongjmp        - internal breakpoint used to step through longjmp()\n\
  3993. \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
  3994. \tuntil          - internal breakpoint used by the \"until\" command\n\
  3995. \tfinish         - internal breakpoint used by the \"finish\" command\n",
  3996. "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
  3997. the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
  3998. breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
  3999. address and file/line number respectively.\n\n",
  4000. "Convenience variable \"$_\" and default examine address for \"x\"\n\
  4001. are set to the address of the last breakpoint listed.\n\n\
  4002. Convenience variable \"$bpnum\" contains the number of the last\n\
  4003. breakpoint set.", NULL),
  4004.        &maintenanceinfolist);
  4005.  
  4006. #endif    /* MAINTENANCE_CMDS */
  4007.  
  4008.   add_com ("catch", class_breakpoint, catch_command,
  4009.          "Set breakpoints to catch exceptions that are raised.\n\
  4010. Argument may be a single exception to catch, multiple exceptions\n\
  4011. to catch, or the default exception \"default\".  If no arguments\n\
  4012. are given, breakpoints are set at all exception handlers catch clauses\n\
  4013. within the current scope.\n\
  4014. \n\
  4015. A condition specified for the catch applies to all breakpoints set\n\
  4016. with this command\n\
  4017. \n\
  4018. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  4019.  
  4020.   add_com ("watch", class_breakpoint, watch_command,
  4021.        "Set a watchpoint for an expression.\n\
  4022. A watchpoint stops execution of your program whenever the value of\n\
  4023. an expression changes.");
  4024.  
  4025.   add_com ("rwatch", class_breakpoint, rwatch_command,
  4026.        "Set a read watchpoint for an expression.\n\
  4027. A watchpoint stops execution of your program whenever the value of\n\
  4028. an expression is read.");
  4029.  
  4030.   add_com ("awatch", class_breakpoint, awatch_command,
  4031.        "Set a watchpoint for an expression.\n\
  4032. A watchpoint stops execution of your program whenever the value of\n\
  4033. an expression is either read or written.");
  4034.  
  4035.   add_info ("watchpoints", breakpoints_info,
  4036.         "Synonym for ``info breakpoints''.");
  4037.  
  4038. }
  4039.  
  4040. /* OK, when we call objfile_relocate, we need to relocate breakpoints
  4041.    too.  breakpoint_re_set is not a good choice--for example, if
  4042.    addr_string contains just a line number without a file name the
  4043.    breakpoint might get set in a different file.  In general, there is
  4044.    no need to go all the way back to the user's string (though this might
  4045.    work if some effort were made to canonicalize it), since symtabs and
  4046.    everything except addresses are still valid.
  4047.  
  4048.    Probably the best way to solve this is to have each breakpoint save
  4049.    the objfile and the section number that was used to set it (if set
  4050.    by "*addr", probably it is best to use find_pc_line to get a symtab
  4051.    and use the objfile and block_line_section for that symtab).  Then
  4052.    objfile_relocate can call fixup_breakpoints with the objfile and
  4053.    the new_offsets, and it can relocate only the appropriate breakpoints.  */
  4054.  
  4055. #ifdef IBM6000_TARGET
  4056. /* But for now, just kludge it based on the concept that before an
  4057.    objfile is relocated the breakpoint is below 0x10000000, and afterwards
  4058.    it is higher, so that way we only relocate each breakpoint once.  */
  4059.  
  4060. void
  4061. fixup_breakpoints (low, high, delta)
  4062.   CORE_ADDR low;
  4063.   CORE_ADDR high;
  4064.   CORE_ADDR delta;
  4065. {
  4066.   struct breakpoint *b;
  4067.  
  4068.   ALL_BREAKPOINTS (b)
  4069.     {
  4070.      if (b->address >= low && b->address <= high)
  4071.        b->address += delta;
  4072.     }
  4073. }
  4074. #endif
  4075.