home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Atari / Gnu / gdb36p4s.zoo / breakpoint.c < prev    next >
C/C++ Source or Header  |  1993-04-03  |  45KB  |  1,724 lines

  1. /* Everything about breakpoints, for GDB.
  2.    Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include "defs.h"
  22. #include "param.h"
  23. #include "symtab.h"
  24. #include "frame.h"
  25. #include "ctype.h"
  26.  
  27. /* This is the sequence of bytes we insert for a breakpoint.  */
  28.  
  29. static char break_insn[] = BREAKPOINT;
  30.  
  31. /* States of enablement of breakpoint.
  32.    `temporary' means disable when hit.
  33.    `delete' means delete when hit.  */
  34.  
  35. enum enable { disabled, enabled, temporary, delete};
  36.  
  37. /* Not that the ->silent field is not currently used by any commands
  38.    (though the code is in there if it was to be and set_raw_breakpoint
  39.    does set it to 0).  I implemented it because I thought it would be
  40.    useful for a hack I had to put in; I'm going to leave it in because
  41.    I can see how there might be times when it would indeed be useful */
  42.  
  43. struct breakpoint
  44. {
  45.   struct breakpoint *next;
  46.   /* Number assigned to distinguish breakpoints.  */
  47.   int number;
  48.   /* Address to break at.  */
  49.   CORE_ADDR address;
  50.   /* Line number of this address.  Redundant.  */
  51.   int line_number;
  52.   /* Symtab of file of this address.  Redundant.  */
  53.   struct symtab *symtab;
  54.   /* Zero means disabled; remember the info but don't break here.  */
  55.   enum enable enable;
  56.   /* Non-zero means a silent breakpoint (don't print frame info
  57.      if we stop here). */
  58.   unsigned char silent;
  59.   /* Number of stops at this breakpoint that should
  60.      be continued automatically before really stopping.  */
  61.   int ignore_count;
  62.   /* "Real" contents of byte where breakpoint has been inserted.
  63.      Valid only when breakpoints are in the program.  */
  64.   char shadow_contents[sizeof break_insn];
  65.   /* Nonzero if this breakpoint is now inserted.  */
  66.   char inserted;
  67.   /* Nonzero if this is not the first breakpoint in the list
  68.      for the given address.  */
  69.   char duplicate;
  70.   /* Chain of command lines to execute when this breakpoint is hit.  */
  71.   struct command_line *commands;
  72.   /* Stack depth (address of frame).  If nonzero, break only if fp
  73.      equals this.  */
  74.   FRAME_ADDR frame;
  75.   /* Conditional.  Break only if this expression's value is nonzero.  */
  76.   struct expression *cond;
  77. };
  78.  
  79. #define ALL_BREAKPOINTS(b)  for (b = breakpoint_chain; b; b = b->next)
  80.  
  81. /* Chain of all breakpoints defined.  */
  82.  
  83. struct breakpoint *breakpoint_chain;
  84.  
  85. /* Number of last breakpoint made.  */
  86.  
  87. static int breakpoint_count;
  88.  
  89. /* Default address, symtab and line to put a breakpoint at
  90.    for "break" command with no arg.
  91.    if default_breakpoint_valid is zero, the other three are
  92.    not valid, and "break" with no arg is an error.
  93.  
  94.    This set by print_stack_frame, which calls set_default_breakpoint.  */
  95.  
  96. int default_breakpoint_valid;
  97. CORE_ADDR default_breakpoint_address;
  98. struct symtab *default_breakpoint_symtab;
  99. int default_breakpoint_line;
  100.  
  101. /* Remaining commands (not yet executed)
  102.    of last breakpoint hit.  */
  103.  
  104. struct command_line *breakpoint_commands;
  105.  
  106. static void delete_breakpoint ();
  107. void clear_momentary_breakpoints ();
  108. void breakpoint_auto_delete ();
  109.  
  110. /* Flag indicating extra verbosity for xgdb.  */
  111. extern int xgdb_verbose;
  112.  
  113. /* condition N EXP -- set break condition of breakpoint N to EXP.  */
  114.  
  115. static void
  116. condition_command (arg, from_tty)
  117.      char *arg;
  118.      int from_tty;
  119. {
  120.   register struct breakpoint *b;
  121.   register char *p;
  122.   register int bnum;
  123.   register struct expression *expr;
  124.  
  125.   if (arg == 0)
  126.     error_no_arg ("breakpoint number");
  127.  
  128.   p = arg;
  129.   while (*p >= '0' && *p <= '9') p++;
  130.   if (p == arg)
  131.     /* There is no number here.  (e.g. "cond a == b").  */
  132.     error_no_arg ("breakpoint number");
  133.   bnum = atoi (arg);
  134.  
  135.   ALL_BREAKPOINTS (b)
  136.     if (b->number == bnum)
  137.       {
  138.     if (b->cond)
  139.       {
  140.         free (b->cond);
  141.         b->cond = 0;
  142.       }
  143.     if (*p == 0)
  144.       {
  145.         b->cond = 0;
  146.         if (from_tty)
  147.           printf ("Breakpoint %d now unconditional.\n", bnum);
  148.       }
  149.     else
  150.       {
  151.         if (*p != ' ' && *p != '\t')
  152.           error ("Arguments must be an integer (breakpoint number) and an expression.");
  153.  
  154.         /* Find start of expression */
  155.         while (*p == ' ' || *p == '\t') p++;
  156.  
  157.         arg = p;
  158.         b->cond = (struct expression *) parse_c_1 (&arg, block_for_pc (b->address), 0);
  159.         if (*arg)
  160.           error ("Junk at end of expression");
  161.       }
  162.     return;
  163.       }
  164.  
  165.   error ("No breakpoint number %d.", bnum);
  166. }
  167.  
  168. static void
  169. commands_command (arg)
  170.      char *arg;
  171. {
  172.   register struct breakpoint *b;
  173.   register char *p, *p1;
  174.   register int bnum;
  175.   struct command_line *l;
  176.  
  177.   /* If we allowed this, we would have problems with when to
  178.      free the storage, if we change the commands currently
  179.      being read from.  */
  180.  
  181.   if (breakpoint_commands)
  182.     error ("Can't use the \"commands\" command among a breakpoint's commands.");
  183.  
  184.   /* Allow commands by itself to refer to the last breakpoint.  */
  185.   if (arg == 0)
  186.     bnum = breakpoint_count;
  187.   else
  188.     {
  189.       p = arg;
  190.       if (! (*p >= '0' && *p <= '9'))
  191.     error ("Argument must be integer (a breakpoint number).");
  192.       
  193.       while (*p >= '0' && *p <= '9') p++;
  194.       if (*p)
  195.     error ("Unexpected extra arguments following breakpoint number.");
  196.       
  197.       bnum = atoi (arg);
  198.     }
  199.  
  200.   ALL_BREAKPOINTS (b)
  201.     if (b->number == bnum)
  202.       {
  203.     if (input_from_terminal_p ())
  204.       {
  205.         printf ("Type commands for when breakpoint %d is hit, one per line.\n\
  206. End with a line saying just \"end\".\n", bnum);
  207.         fflush (stdout);
  208.       }
  209.     l = read_command_lines ();
  210.     free_command_lines (&b->commands);
  211.     b->commands = l;
  212.     return;
  213.       }
  214.   error ("No breakpoint number %d.", bnum);
  215. }
  216.  
  217. /* Called from command loop to execute the commands
  218.    associated with the breakpoint we just stopped at.  */
  219.  
  220. void
  221. do_breakpoint_commands ()
  222. {
  223.   while (breakpoint_commands)
  224.     {
  225.       char *line = breakpoint_commands->line;
  226.       breakpoint_commands = breakpoint_commands->next;
  227.       execute_command (line, 0);
  228.       /* If command was "cont", breakpoint_commands is now 0,
  229.      of if we stopped at yet another breakpoint which has commands,
  230.      it is now the commands for the new breakpoint.  */
  231.     }
  232.   clear_momentary_breakpoints ();
  233. }
  234.  
  235. /* Used when the program is proceeded, to eliminate any remaining
  236.    commands attached to the previous breakpoint we stopped at.  */
  237.  
  238. void
  239. clear_breakpoint_commands ()
  240. {
  241.   breakpoint_commands = 0;
  242.   breakpoint_auto_delete (0);
  243. }
  244.  
  245. /* Functions to get and set the current list of pending
  246.    breakpoint commands.  These are used by run_stack_dummy
  247.    to preserve the commands around a function call.  */
  248.  
  249. struct command_line *
  250. get_breakpoint_commands ()
  251. {
  252.   return breakpoint_commands;
  253. }
  254.  
  255. void
  256. set_breakpoint_commands (cmds)
  257.      struct command_line *cmds;
  258. {
  259.   breakpoint_commands = cmds;
  260. }
  261.  
  262. /* insert_breakpoints is used when starting or continuing the program.
  263.    remove_breakpoints is used when the program stops.
  264.    Both return zero if successful,
  265.    or an `errno' value if could not write the inferior.  */
  266.  
  267. int
  268. insert_breakpoints ()
  269. {
  270.   register struct breakpoint *b;
  271.   int val;
  272.  
  273. #ifdef BREAKPOINT_DEBUG
  274.   printf ("Inserting breakpoints.\n");
  275. #endif /* BREAKPOINT_DEBUG */
  276.  
  277.   ALL_BREAKPOINTS (b)
  278.     if (b->enable != disabled && ! b->inserted && ! b->duplicate)
  279.       {
  280.     read_memory (b->address, b->shadow_contents, sizeof break_insn);
  281.     val = write_memory (b->address, break_insn, sizeof break_insn);
  282.     if (val)
  283.      return val;
  284. #ifdef BREAKPOINT_DEBUG
  285.     printf ("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
  286.         b->address, b->shadow_contents[0], b->shadow_contents[1]);
  287. #endif /* BREAKPOINT_DEBUG */
  288.     b->inserted = 1;
  289.       }
  290.   return 0;
  291. }
  292.  
  293. int
  294. remove_breakpoints ()
  295. {
  296.   register struct breakpoint *b;
  297.   int val;
  298.  
  299. #ifdef BREAKPOINT_DEBUG
  300.   printf ("Removing breakpoints.\n");
  301. #endif /* BREAKPOINT_DEBUG */
  302.  
  303.   ALL_BREAKPOINTS (b)
  304.     if (b->inserted)
  305.       {
  306.     val = write_memory (b->address, b->shadow_contents, sizeof break_insn);
  307.     if (val)
  308.       return val;
  309.     b->inserted = 0;
  310. #ifdef BREAKPOINT_DEBUG
  311.     printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
  312.         b->address, b->shadow_contents[0], b->shadow_contents[1]);
  313. #endif /* BREAKPOINT_DEBUG */
  314.       }
  315.  
  316.   return 0;
  317. }
  318.  
  319. /* Clear the "inserted" flag in all breakpoints.
  320.    This is done when the inferior is loaded.  */
  321.  
  322. void
  323. mark_breakpoints_out ()
  324. {
  325.   register struct breakpoint *b;
  326.  
  327.   ALL_BREAKPOINTS (b)
  328.     b->inserted = 0;
  329. }
  330.  
  331. /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
  332.    When continuing from a location with a breakpoint,
  333.    we actually single step once before calling insert_breakpoints.  */
  334.  
  335. int
  336. breakpoint_here_p (pc)
  337.      CORE_ADDR pc;
  338. {
  339.   register struct breakpoint *b;
  340.  
  341.   ALL_BREAKPOINTS (b)
  342.     if (b->enable != disabled && b->address == pc)
  343.       return 1;
  344.  
  345.   return 0;
  346. }
  347.  
  348. /* Evaluate the expression EXP and return 1 if value is zero.
  349.    This is used inside a catch_errors to evaluate the breakpoint condition.  */
  350.  
  351. int
  352. breakpoint_cond_eval (exp)
  353.      struct expression *exp;
  354. {
  355.   return value_zerop (evaluate_expression (exp));
  356. }
  357.  
  358. /* Return 0 if PC is not the address just after a breakpoint,
  359.    or -1 if breakpoint says do not stop now,
  360.    or -2 if breakpoint says it has deleted itself and don't stop,
  361.    or -3 if hit a breakpoint number -3 (delete when program stops),
  362.    or else the number of the breakpoint,
  363.    with 0x1000000 added (or subtracted, for a negative return value) for
  364.    a silent breakpoint.  */
  365.  
  366. int
  367. breakpoint_stop_status (pc, frame_address)
  368.      CORE_ADDR pc;
  369.      FRAME_ADDR frame_address;
  370. {
  371.   register struct breakpoint *b;
  372.   register int cont = 0;
  373.  
  374.   /* Get the address where the breakpoint would have been.  */
  375.   pc -= DECR_PC_AFTER_BREAK;
  376.  
  377.   ALL_BREAKPOINTS (b)
  378.     if (b->enable != disabled && b->address == pc)
  379.       {
  380.     if (b->frame && b->frame != frame_address)
  381.       cont = -1;
  382.     else
  383.       {
  384.         int value_zero;
  385.         if (b->cond)
  386.           {
  387.         /* Need to select the frame, with all that implies
  388.            so that the conditions will have the right context.  */
  389.         select_frame (get_current_frame (), 0);
  390.         value_zero
  391.           = catch_errors (breakpoint_cond_eval, b->cond,
  392.                   "Error occurred in testing breakpoint condition.");
  393.         free_all_values ();
  394.           }
  395.         if (b->cond && value_zero)
  396.           {
  397.         cont = -1;
  398.           }
  399.         else if (b->ignore_count > 0)
  400.           {
  401.         b->ignore_count--;
  402.         cont = -1;
  403.           }
  404.         else
  405.           {
  406.         if (b->enable == temporary)
  407.           b->enable = disabled;
  408.         breakpoint_commands = b->commands;
  409.         if (b->silent
  410.             || (breakpoint_commands
  411.             && !strcmp ("silent", breakpoint_commands->line)))
  412.           {
  413.             if (breakpoint_commands)
  414.               breakpoint_commands = breakpoint_commands->next;
  415.             return (b->number > 0 ?
  416.                 0x1000000 + b->number :
  417.                 b->number - 0x1000000);
  418.           }
  419.         return b->number;
  420.           }
  421.       }
  422.       }
  423.  
  424.   return cont;
  425. }
  426.  
  427. static void
  428. breakpoint_1 (bnum)
  429.      int bnum;
  430. {
  431.   register struct breakpoint *b;
  432.   register struct command_line *l;
  433.   register struct symbol *sym;
  434.   CORE_ADDR last_addr = (CORE_ADDR)-1;
  435.  
  436.   ALL_BREAKPOINTS (b)
  437.     if (bnum == -1 || bnum == b->number)
  438.       {
  439.     printf_filtered ("#%-3d %c  0x%08x ", b->number,
  440.         "nyod"[(int) b->enable],
  441.         b->address);
  442.     last_addr = b->address;
  443.     if (b->symtab)
  444.       {
  445.         sym = find_pc_function (b->address);
  446.         if (sym)
  447.           {
  448.         printf_filtered (" in ");
  449.         print_demangled (SYMBOL_NAME (sym), stdout);
  450.         printf_filtered (" (%s line %d)",
  451.                  b->symtab->filename, b->line_number);
  452.           }
  453.         else
  454.           printf_filtered ("%s line %d", b->symtab->filename, b->line_number);
  455.       }
  456.     else
  457.       {
  458.         char *name;
  459.         int addr;
  460.  
  461.         if (find_pc_partial_function (b->address, &name, &addr))
  462.           {
  463.         if (b->address - addr)
  464.           printf_filtered ("<%s+%d>", name, b->address - addr);
  465.         else
  466.           printf_filtered ("<%s>", name);
  467.           }
  468.       }
  469.           
  470.     printf_filtered ("\n");
  471.  
  472.     if (b->ignore_count)
  473.       printf_filtered ("\tignore next %d hits\n", b->ignore_count);
  474.     if (b->frame)
  475.       printf_filtered ("\tstop only in stack frame at 0x%x\n", b->frame);
  476.     if (b->cond)
  477.       {
  478.         printf_filtered ("\tbreak only if ");
  479.         print_expression (b->cond, stdout);
  480.         printf_filtered ("\n");
  481.       }
  482.     if (l = b->commands)
  483.       while (l)
  484.         {
  485.           printf_filtered ("\t%s\n", l->line);
  486.           l = l->next;
  487.         }
  488.       }
  489.  
  490.   /* Compare against (CORE_ADDR)-1 in case some compiler decides
  491.      that a comparison of an unsigned with -1 is always false.  */
  492.   if (last_addr != (CORE_ADDR)-1)
  493.     set_next_address (last_addr);
  494. }
  495.  
  496. static void
  497. breakpoints_info (bnum_exp)
  498.      char *bnum_exp;
  499. {
  500.   int bnum = -1;
  501.  
  502.   if (bnum_exp)
  503.     bnum = parse_and_eval_address (bnum_exp);
  504.   else if (breakpoint_chain == 0)
  505.     printf_filtered ("No breakpoints.\n");
  506.   else
  507.     printf_filtered ("Breakpoints:\n\
  508. Num Enb   Address    Where\n");
  509.  
  510.   breakpoint_1 (bnum);
  511. }
  512.  
  513. /* Print a message describing any breakpoints set at PC.  */
  514.  
  515. static void
  516. describe_other_breakpoints (pc)
  517.      register CORE_ADDR pc;
  518. {
  519.   register int others = 0;
  520.   register struct breakpoint *b;
  521.  
  522.   ALL_BREAKPOINTS (b)
  523.     if (b->address == pc)
  524.       others++;
  525.   if (others > 0)
  526.     {
  527.       printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
  528.       ALL_BREAKPOINTS (b)
  529.     if (b->address == pc)
  530.       {
  531.         others--;
  532.         printf ("%d%s%s ",
  533.             b->number,
  534.             (b->enable == disabled) ? " (disabled)" : "",
  535.             (others > 1) ? "," : ((others == 1) ? " and" : ""));
  536.       }
  537.       printf ("also set at pc 0x%x.\n", pc);
  538.     }
  539. }
  540.  
  541. /* Set the default place to put a breakpoint
  542.    for the `break' command with no arguments.  */
  543.  
  544. void
  545. set_default_breakpoint (valid, addr, symtab, line)
  546.      int valid;
  547.      CORE_ADDR addr;
  548.      struct symtab *symtab;
  549.      int line;
  550. {
  551.   default_breakpoint_valid = valid;
  552.   default_breakpoint_address = addr;
  553.   default_breakpoint_symtab = symtab;
  554.   default_breakpoint_line = line;
  555. }
  556.  
  557. /* Rescan breakpoints at address ADDRESS,
  558.    marking the first one as "first" and any others as "duplicates".
  559.    This is so that the bpt instruction is only inserted once.  */
  560.  
  561. static void
  562. check_duplicates (address)
  563.      CORE_ADDR address;
  564. {
  565.   register struct breakpoint *b;
  566.   register int count = 0;
  567.  
  568.   ALL_BREAKPOINTS (b)
  569.     if (b->enable != disabled && b->address == address)
  570.       {
  571.     count++;
  572.     b->duplicate = count > 1;
  573.       }
  574. }
  575.  
  576. /* Low level routine to set a breakpoint.
  577.    Takes as args the three things that every breakpoint must have.
  578.    Returns the breakpoint object so caller can set other things.
  579.    Does not set the breakpoint number!
  580.    Does not print anything.  */
  581.  
  582. static struct breakpoint *
  583. set_raw_breakpoint (sal)
  584.      struct symtab_and_line sal;
  585. {
  586.   register struct breakpoint *b, *b1;
  587.  
  588.   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
  589.   bzero (b, sizeof *b);
  590.   b->address = sal.pc;
  591.   b->symtab = sal.symtab;
  592.   b->line_number = sal.line;
  593.   b->enable = enabled;
  594.   b->next = 0;
  595.   b->silent = 0;
  596.  
  597.   /* Add this breakpoint to the end of the chain
  598.      so that a list of breakpoints will come out in order
  599.      of increasing numbers.  */
  600.  
  601.   b1 = breakpoint_chain;
  602.   if (b1 == 0)
  603.     breakpoint_chain = b;
  604.   else
  605.     {
  606.       while (b1->next)
  607.     b1 = b1->next;
  608.       b1->next = b;
  609.     }
  610.  
  611.   check_duplicates (sal.pc);
  612.  
  613.   return b;
  614. }
  615.  
  616. /* Set a breakpoint that will evaporate an end of command
  617.    at address specified by SAL.
  618.    Restrict it to frame FRAME if FRAME is nonzero.  */
  619.  
  620. void
  621. set_momentary_breakpoint (sal, frame)
  622.      struct symtab_and_line sal;
  623.      FRAME frame;
  624. {
  625.   register struct breakpoint *b;
  626.   b = set_raw_breakpoint (sal);
  627.   b->number = -3;
  628.   b->enable = delete;
  629.   b->frame = (frame ? FRAME_FP (frame) : 0);
  630. }
  631.  
  632. void
  633. clear_momentary_breakpoints ()
  634. {
  635.   register struct breakpoint *b;
  636.   ALL_BREAKPOINTS (b)
  637.     if (b->number == -3)
  638.       {
  639.     delete_breakpoint (b);
  640.     break;
  641.       }
  642. }
  643.  
  644. /* Set a breakpoint from a symtab and line.
  645.    If TEMPFLAG is nonzero, it is a temporary breakpoint.
  646.    Print the same confirmation messages that the breakpoint command prints.  */
  647.  
  648. void
  649. set_breakpoint (s, line, tempflag)
  650.      struct symtab *s;
  651.      int line;
  652.      int tempflag;
  653. {
  654.   register struct breakpoint *b;
  655.   struct symtab_and_line sal;
  656.   
  657.   sal.symtab = s;
  658.   sal.line = line;
  659.   sal.pc = find_line_pc (sal.symtab, sal.line);
  660.   if (sal.pc == 0)
  661.     error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename);
  662.   else
  663.     {
  664.       describe_other_breakpoints (sal.pc);
  665.  
  666.       b = set_raw_breakpoint (sal);
  667.       b->number = ++breakpoint_count;
  668.       b->cond = 0;
  669.       if (tempflag)
  670.     b->enable = temporary;
  671.  
  672.       printf ("Breakpoint %d at 0x%x", b->number, b->address);
  673.       if (b->symtab)
  674.     printf (": file %s, line %d.", b->symtab->filename, b->line_number);
  675.       printf ("\n");
  676.     }
  677. }
  678.  
  679. /* Set a breakpoint according to ARG (function, linenum or *address)
  680.    and make it temporary if TEMPFLAG is nonzero. */
  681.  
  682. static void
  683. break_command_1 (arg, tempflag, from_tty)
  684.      char *arg;
  685.      int tempflag, from_tty;
  686. {
  687.   struct symtabs_and_lines sals;
  688.   struct symtab_and_line sal;
  689.   register struct expression *cond = 0;
  690.   register struct breakpoint *b;
  691.   char *save_arg;
  692.   int i;
  693.   CORE_ADDR pc;
  694.  
  695.   sals.sals = NULL;
  696.   sals.nelts = 0;
  697.  
  698.   sal.line = sal.pc = sal.end = 0;
  699.   sal.symtab = 0;
  700.  
  701.   /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
  702.  
  703.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  704.            && (arg[2] == ' ' || arg[2] == '\t')))
  705.     {
  706.       if (default_breakpoint_valid)
  707.     {
  708.       sals.sals = (struct symtab_and_line *) 
  709.         malloc (sizeof (struct symtab_and_line));
  710.       sal.pc = default_breakpoint_address;
  711.       sal.line = default_breakpoint_line;
  712.       sal.symtab = default_breakpoint_symtab;
  713.       sals.sals[0] = sal;
  714.       sals.nelts = 1;
  715.     }
  716.       else
  717.     error ("No default breakpoint address now.");
  718.     }
  719.   else
  720.     /* Force almost all breakpoints to be in terms of the
  721.        current_source_symtab (which is decode_line_1's default).  This
  722.        should produce the results we want almost all of the time while
  723.        leaving default_breakpoint_* alone.  */
  724.     if (default_breakpoint_valid
  725.     && (!current_source_symtab
  726.         || (arg && (*arg == '+' || *arg == '-'))))
  727.       sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  728.                 default_breakpoint_line);
  729.     else
  730.       sals = decode_line_1 (&arg, 1, 0, 0);
  731.   
  732.   if (! sals.nelts) 
  733.     return;
  734.  
  735.   save_arg = arg;
  736.   for (i = 0; i < sals.nelts; i++)
  737.     {
  738.       sal = sals.sals[i];
  739.       if (sal.pc == 0 && sal.symtab != 0)
  740.     {
  741.       pc = find_line_pc (sal.symtab, sal.line);
  742.       if (pc == 0)
  743.         error ("No line %d in file \"%s\".",
  744.            sal.line, sal.symtab->filename);
  745.     }
  746.       else 
  747.     pc = sal.pc;
  748.       
  749.       while (arg && *arg)
  750.     {
  751.       if (arg[0] == 'i' && arg[1] == 'f'
  752.           && (arg[2] == ' ' || arg[2] == '\t'))
  753.         cond = (struct expression *) parse_c_1 ((arg += 2, &arg),
  754.                             block_for_pc (pc), 0);
  755.       else
  756.         error ("Junk at end of arguments.");
  757.     }
  758.       arg = save_arg;
  759.       sals.sals[i].pc = pc;
  760.     }
  761.  
  762.   for (i = 0; i < sals.nelts; i++)
  763.     {
  764.       sal = sals.sals[i];
  765.  
  766.       if (from_tty)
  767.     describe_other_breakpoints (sal.pc);
  768.  
  769.       b = set_raw_breakpoint (sal);
  770.       b->number = ++breakpoint_count;
  771.       b->cond = cond;
  772.       if (tempflag)
  773.     b->enable = temporary;
  774.  
  775.       printf ("Breakpoint %d at 0x%x", b->number, b->address);
  776.       if (b->symtab)
  777.     printf (": file %s, line %d.", b->symtab->filename, b->line_number);
  778.       printf ("\n");
  779.     }
  780.  
  781.   if (sals.nelts > 1)
  782.     {
  783.       printf ("Multiple breakpoints were set.\n");
  784.       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  785.     }
  786.   free (sals.sals);
  787. }
  788.  
  789. static void
  790. break_command (arg, from_tty)
  791.      char *arg;
  792.      int from_tty;
  793. {
  794.   break_command_1 (arg, 0, from_tty);
  795. }
  796.  
  797. static void
  798. tbreak_command (arg, from_tty)
  799.      char *arg;
  800.      int from_tty;
  801. {
  802.   break_command_1 (arg, 1, from_tty);
  803. }
  804.  
  805. /*
  806.  * Helper routine for the until_command routine in infcmd.c.  Here
  807.  * because it uses the mechanisms of breakpoints.
  808.  */
  809. void
  810. until_break_command (arg, from_tty)
  811.      char *arg;
  812.      int from_tty;
  813. {
  814.   struct symtabs_and_lines sals;
  815.   struct symtab_and_line sal;
  816.   FRAME prev_frame = get_prev_frame (selected_frame);
  817.  
  818.   clear_proceed_status ();
  819.  
  820.   /* Set a breakpoint where the user wants it and at return from
  821.      this function */
  822.   
  823.   if (default_breakpoint_valid)
  824.     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  825.               default_breakpoint_line);
  826.   else
  827.     sals = decode_line_1 (&arg, 1, 0, 0);
  828.   
  829.   if (sals.nelts != 1)
  830.     error ("Couldn't get information on specified line.");
  831.   
  832.   sal = sals.sals[0];
  833.   free (sals.sals);        /* malloc'd, so freed */
  834.   
  835.   if (*arg)
  836.     error ("Junk at end of arguments.");
  837.   
  838.   if (sal.pc == 0 && sal.symtab != 0)
  839.     sal.pc = find_line_pc (sal.symtab, sal.line);
  840.   
  841.   if (sal.pc == 0)
  842.     error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename);
  843.   
  844.   set_momentary_breakpoint (sal, selected_frame);
  845.   
  846.   /* Keep within the current frame */
  847.   
  848.   if (prev_frame)
  849.     {
  850.       struct frame_info *fi;
  851.       
  852.       fi = get_frame_info (prev_frame);
  853.       sal = find_pc_line (fi->pc, 0);
  854.       sal.pc = fi->pc;
  855.       set_momentary_breakpoint (sal, prev_frame);
  856.     }
  857.   
  858.   proceed (-1, -1, 0);
  859. }
  860.  
  861. /* Set a breakpoint at the catch clause for NAME.  */
  862. static int
  863. catch_breakpoint (name)
  864.      char *name;
  865. {
  866. }
  867.  
  868. static int
  869. disable_catch_breakpoint ()
  870. {
  871. }
  872.  
  873. static int
  874. delete_catch_breakpoint ()
  875. {
  876. }
  877.  
  878. static int
  879. enable_catch_breakpoint ()
  880. {
  881. }
  882.  
  883. struct sal_chain
  884. {
  885.   struct sal_chain *next;
  886.   struct symtab_and_line sal;
  887. };
  888.  
  889. /* For each catch clause identified in ARGS, run FUNCTION
  890.    with that clause as an argument.  */
  891. static struct symtabs_and_lines
  892. map_catch_names (args, function)
  893.      char *args;
  894.      int (*function)();
  895. {
  896.   register char *p = args;
  897.   register char *p1;
  898.   register int num;
  899.   register struct breakpoint *b;
  900.   struct symtabs_and_lines sals;
  901.   struct sal_chain *sal_chain = 0;
  902.  
  903.   if (p == 0)
  904.     error_no_arg ("one or more catch names");
  905.  
  906.   sals.nelts = 0;
  907.   sals.sals = NULL;
  908.  
  909.   while (*p)
  910.     {
  911.       p1 = p;
  912.       /* Don't swallow conditional part.  */
  913.       if (p1[0] == 'i' && p1[1] == 'f'
  914.       && (p1[2] == ' ' || p1[2] == '\t'))
  915.     break;
  916.  
  917.       if (isalpha (*p1))
  918.     {
  919.       p1++;
  920.       while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
  921.         p1++;
  922.     }
  923.  
  924.       if (*p1 && *p1 != ' ' && *p1 != '\t')
  925.     error ("Arguments must be catch names.");
  926.  
  927.       *p1 = 0;
  928. #if 0
  929.       if (function (p))
  930.     {
  931.       struct sal_chain *next
  932.         = (struct sal_chain *)alloca (sizeof (struct sal_chain));
  933.       next->next = sal_chain;
  934.       next->sal = get_catch_sal (p);
  935.       sal_chain = next;
  936.       goto win;
  937.     }
  938. #endif
  939.       printf ("No catch clause for exception %s.\n", p);
  940.     win:
  941.       p = p1;
  942.       while (*p == ' ' || *p == '\t') p++;
  943.     }
  944. }
  945.  
  946. /* This shares a lot of code with `print_frame_label_vars' from stack.c.  */
  947.  
  948. static struct symtabs_and_lines
  949. get_catch_sals (this_level_only)
  950. {
  951.   extern struct blockvector *blockvector_for_pc ();
  952.   register struct blockvector *bl;
  953.   register struct block *block = get_frame_block (selected_frame);
  954.   int index, have_default = 0;
  955.   struct frame_info *fi = get_frame_info (selected_frame);
  956.   CORE_ADDR pc = fi->pc;
  957.   struct symtabs_and_lines sals;
  958.   struct sal_chain *sal_chain = 0;
  959.   char *blocks_searched;
  960.  
  961.   sals.nelts = 0;
  962.   sals.sals = NULL;
  963.  
  964.   if (block == 0)
  965.     error ("No symbol table info available.\n");
  966.  
  967.   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
  968.   blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  969.   bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  970.  
  971.   while (block != 0)
  972.     {
  973.       CORE_ADDR end = BLOCK_END (block) - 4;
  974.       int last_index;
  975.  
  976.       if (bl != blockvector_for_pc (end, &index))
  977.     error ("blockvector blotch");
  978.       if (BLOCKVECTOR_BLOCK (bl, index) != block)
  979.     error ("blockvector botch");
  980.       last_index = BLOCKVECTOR_NBLOCKS (bl);
  981.       index += 1;
  982.  
  983.       /* Don't print out blocks that have gone by.  */
  984.       while (index < last_index
  985.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
  986.     index++;
  987.  
  988.       while (index < last_index
  989.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
  990.     {
  991.       if (blocks_searched[index] == 0)
  992.         {
  993.           struct block *b = BLOCKVECTOR_BLOCK (bl, index);
  994.           int nsyms;
  995.           register int i;
  996.           register struct symbol *sym;
  997.  
  998.           nsyms = BLOCK_NSYMS (b);
  999.  
  1000.           for (i = 0; i < nsyms; i++)
  1001.         {
  1002.           sym = BLOCK_SYM (b, i);
  1003.           if (! strcmp (SYMBOL_NAME (sym), "default"))
  1004.             {
  1005.               if (have_default)
  1006.             continue;
  1007.               have_default = 1;
  1008.             }
  1009.           if (SYMBOL_CLASS (sym) == LOC_LABEL)
  1010.             {
  1011.               struct sal_chain *next = (struct sal_chain *)
  1012.             alloca (sizeof (struct sal_chain));
  1013.               next->next = sal_chain;
  1014.               next->sal = find_pc_line (SYMBOL_VALUE (sym), 0);
  1015.               sal_chain = next;
  1016.             }
  1017.         }
  1018.           blocks_searched[index] = 1;
  1019.         }
  1020.       index++;
  1021.     }
  1022.       if (have_default)
  1023.     break;
  1024.       if (sal_chain && this_level_only)
  1025.     break;
  1026.  
  1027.       /* After handling the function's top-level block, stop.
  1028.      Don't continue to its superblock, the block of
  1029.      per-file symbols.  */
  1030.       if (BLOCK_FUNCTION (block))
  1031.     break;
  1032.       block = BLOCK_SUPERBLOCK (block);
  1033.     }
  1034.  
  1035.   if (sal_chain)
  1036.     {
  1037.       struct sal_chain *tmp_chain;
  1038.  
  1039.       /* Count the number of entries.  */
  1040.       for (index = 0, tmp_chain = sal_chain; tmp_chain;
  1041.        tmp_chain = tmp_chain->next)
  1042.     index++;
  1043.  
  1044.       sals.nelts = index;
  1045.       sals.sals = (struct symtab_and_line *)
  1046.     xmalloc (index * sizeof (struct symtab_and_line));
  1047.       for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
  1048.     sals.sals[index] = sal_chain->sal;
  1049.     }
  1050.  
  1051.   return sals;
  1052. }
  1053.  
  1054. /* Commands to deal with catching exceptions.  */
  1055.  
  1056. catch_command_1 (arg, tempflag, from_tty)
  1057.      char *arg;
  1058.      int tempflag;
  1059.      int from_tty;
  1060. {
  1061.   /* First, translate ARG into something we can deal with in terms
  1062.      of breakpoints.  */
  1063.  
  1064.   struct symtabs_and_lines sals;
  1065.   struct symtab_and_line sal;
  1066.   register struct expression *cond = 0;
  1067.   register struct breakpoint *b;
  1068.   char *save_arg;
  1069.   int i;
  1070.   CORE_ADDR pc;
  1071.  
  1072.   sal.line = sal.pc = sal.end = 0;
  1073.   sal.symtab = 0;
  1074.  
  1075.   /* If no arg given, or if first arg is 'if ', all active catch clauses
  1076.      are breakpointed. */
  1077.  
  1078.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  1079.            && (arg[2] == ' ' || arg[2] == '\t')))
  1080.     {
  1081.       /* Grab all active catch clauses.  */
  1082.       sals = get_catch_sals (0);
  1083.     }
  1084.   else
  1085.     {
  1086.       /* Grab selected catch clauses.  */
  1087.       error ("catch NAME not implemeneted");
  1088.       sals = map_catch_names (arg, catch_breakpoint);
  1089.     }
  1090.  
  1091.   if (! sals.nelts) 
  1092.     return;
  1093.  
  1094.   save_arg = arg;
  1095.   for (i = 0; i < sals.nelts; i++)
  1096.     {
  1097.       sal = sals.sals[i];
  1098.       if (sal.pc == 0 && sal.symtab != 0)
  1099.     {
  1100.       pc = find_line_pc (sal.symtab, sal.line);
  1101.       if (pc == 0)
  1102.         error ("No line %d in file \"%s\".",
  1103.            sal.line, sal.symtab->filename);
  1104.     }
  1105.       else 
  1106.     pc = sal.pc;
  1107.       
  1108.       while (arg && *arg)
  1109.     {
  1110.       if (arg[0] == 'i' && arg[1] == 'f'
  1111.           && (arg[2] == ' ' || arg[2] == '\t'))
  1112.         cond = (struct expression *) parse_c_1 ((arg += 2, &arg),
  1113.                             block_for_pc (pc), 0);
  1114.       else
  1115.         error ("Junk at end of arguments.");
  1116.     }
  1117.       arg = save_arg;
  1118.       sals.sals[i].pc = pc;
  1119.     }
  1120.  
  1121.   for (i = 0; i < sals.nelts; i++)
  1122.     {
  1123.       sal = sals.sals[i];
  1124.  
  1125.       if (from_tty)
  1126.     describe_other_breakpoints (sal.pc);
  1127.  
  1128.       b = set_raw_breakpoint (sal);
  1129.       b->number = ++breakpoint_count;
  1130.       b->cond = cond;
  1131.       if (tempflag)
  1132.     b->enable = temporary;
  1133.  
  1134.       printf ("Breakpoint %d at 0x%x", b->number, b->address);
  1135.       if (b->symtab)
  1136.     printf (": file %s, line %d.", b->symtab->filename, b->line_number);
  1137.       printf ("\n");
  1138.     }
  1139.  
  1140.   if (sals.nelts > 1)
  1141.     {
  1142.       printf ("Multiple breakpoints were set.\n");
  1143.       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  1144.     }
  1145.   free (sals.sals);
  1146. }
  1147.  
  1148. /* Disable breakpoints on all catch clauses described in ARGS.  */
  1149. static void
  1150. disable_catch (args)
  1151.      char *args;
  1152. {
  1153.   /* Map the disable command to catch clauses described in ARGS.  */
  1154. }
  1155.  
  1156. /* Enable breakpoints on all catch clauses described in ARGS.  */
  1157. static void
  1158. enable_catch (args)
  1159.      char *args;
  1160. {
  1161.   /* Map the disable command to catch clauses described in ARGS.  */
  1162. }
  1163.  
  1164. /* Delete breakpoints on all catch clauses in the active scope.  */
  1165. static void
  1166. delete_catch (args)
  1167.      char *args;
  1168. {
  1169.   /* Map the delete command to catch clauses described in ARGS.  */
  1170. }
  1171.  
  1172. static void
  1173. catch_command (arg, from_tty)
  1174.      char *arg;
  1175.      int from_tty;
  1176. {
  1177.   catch_command_1 (arg, 0, from_tty);
  1178. }
  1179.  
  1180. static void
  1181. clear_command (arg, from_tty)
  1182.      char *arg;
  1183.      int from_tty;
  1184. {
  1185.   register struct breakpoint *b, *b1;
  1186.   struct symtabs_and_lines sals;
  1187.   struct symtab_and_line sal;
  1188.   register struct breakpoint *found;
  1189.   int i;
  1190.  
  1191.   if (arg)
  1192.     {
  1193.       sals = decode_line_spec (arg, 1);
  1194.     }
  1195.   else
  1196.     {
  1197.       sals.sals = (struct symtab_and_line *) malloc (sizeof (struct symtab_and_line));
  1198.       sal.line = default_breakpoint_line;
  1199.       sal.symtab = default_breakpoint_symtab;
  1200.       sal.pc = 0;
  1201.       if (sal.symtab == 0)
  1202.     error ("No source file specified.");
  1203.  
  1204.       sals.sals[0] = sal;
  1205.       sals.nelts = 1;
  1206.     }
  1207.  
  1208.   for (i = 0; i < sals.nelts; i++)
  1209.     {
  1210.       /* If exact pc given, clear bpts at that pc.
  1211.      But if sal.pc is zero, clear all bpts on specified line.  */
  1212.       sal = sals.sals[i];
  1213.       found = (struct breakpoint *) 0;
  1214.       while (breakpoint_chain
  1215.          && (sal.pc ? breakpoint_chain->address == sal.pc
  1216.          : (breakpoint_chain->symtab == sal.symtab
  1217.             && breakpoint_chain->line_number == sal.line)))
  1218.     {
  1219.       b1 = breakpoint_chain;
  1220.       breakpoint_chain = b1->next;
  1221.       b1->next = found;
  1222.       found = b1;
  1223.     }
  1224.  
  1225.       ALL_BREAKPOINTS (b)
  1226.     while (b->next
  1227.            && (sal.pc ? b->next->address == sal.pc
  1228.            : (b->next->symtab == sal.symtab
  1229.               && b->next->line_number == sal.line)))
  1230.       {
  1231.         b1 = b->next;
  1232.         b->next = b1->next;
  1233.         b1->next = found;
  1234.         found = b1;
  1235.       }
  1236.  
  1237.       if (found == 0)
  1238.     error ("No breakpoint at %s.", arg);
  1239.  
  1240.       if (found->next) from_tty = 1; /* Always report if deleted more than one */
  1241.       if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
  1242.       while (found)
  1243.     {
  1244.       if (from_tty) printf ("%d ", found->number);
  1245.       b1 = found->next;
  1246.       delete_breakpoint (found);
  1247.       found = b1;
  1248.     }
  1249.       if (from_tty) putchar ('\n');
  1250.     }
  1251.   free (sals.sals);
  1252. }
  1253.  
  1254. /* Delete breakpoint number BNUM if it is a `delete' breakpoint.
  1255.    This is called after breakpoint BNUM has been hit.
  1256.    Also delete any breakpoint numbered -3 unless there are breakpoint
  1257.    commands to be executed.  */
  1258.  
  1259. void
  1260. breakpoint_auto_delete (bnum)
  1261.      int bnum;
  1262. {
  1263.   register struct breakpoint *b;
  1264.   if (bnum != 0)
  1265.     ALL_BREAKPOINTS (b)
  1266.       if (b->number == bnum)
  1267.     {
  1268.       if (b->enable == delete)
  1269.         delete_breakpoint (b);
  1270.       break;
  1271.     }
  1272.   if (breakpoint_commands == 0)
  1273.     clear_momentary_breakpoints ();
  1274. }
  1275.  
  1276. static void
  1277. delete_breakpoint (bpt)
  1278.      struct breakpoint *bpt;
  1279. {
  1280.   register struct breakpoint *b;
  1281.  
  1282.   if (bpt->inserted)
  1283.     write_memory (bpt->address, bpt->shadow_contents, sizeof break_insn);
  1284.  
  1285.   if (breakpoint_chain == bpt)
  1286.     breakpoint_chain = bpt->next;
  1287.  
  1288.   ALL_BREAKPOINTS (b)
  1289.     if (b->next == bpt)
  1290.       {
  1291.     b->next = bpt->next;
  1292.     break;
  1293.       }
  1294.  
  1295.   check_duplicates (bpt->address);
  1296.  
  1297.   free_command_lines (&bpt->commands);
  1298.   if (bpt->cond)
  1299.     free (bpt->cond);
  1300.  
  1301.   if (xgdb_verbose && bpt->number >=0)
  1302.     printf ("breakpoint #%d deleted\n", bpt->number);
  1303.  
  1304.   free (bpt);
  1305. }
  1306.  
  1307. static void map_breakpoint_numbers ();
  1308.  
  1309. static void
  1310. delete_command (arg, from_tty)
  1311.      char *arg;
  1312.      int from_tty;
  1313. {
  1314.   register struct breakpoint *b, *b1;
  1315.  
  1316.   if (arg == 0)
  1317.     {
  1318.       /* Ask user only if there are some breakpoints to delete.  */
  1319.       if (!from_tty
  1320.       || breakpoint_chain && query ("Delete all breakpoints? "))
  1321.     {
  1322.       /* No arg; clear all breakpoints.  */
  1323.       while (breakpoint_chain)
  1324.         delete_breakpoint (breakpoint_chain);
  1325.     }
  1326.     }
  1327.   else
  1328.     map_breakpoint_numbers (arg, delete_breakpoint);
  1329. }
  1330.  
  1331. /* Delete all breakpoints.
  1332.    Done when new symtabs are loaded, since the break condition expressions
  1333.    may become invalid, and the breakpoints are probably wrong anyway.  */
  1334.  
  1335. void
  1336. clear_breakpoints ()
  1337. {
  1338.   delete_command (0, 0);
  1339. }
  1340.  
  1341. #ifdef atarist
  1342. void
  1343. relocate_breakpoints (offset)
  1344.      long offset;
  1345. {
  1346.   register struct breakpoint *b;
  1347.  
  1348.   ALL_BREAKPOINTS (b)
  1349.     b->address += offset;
  1350. }
  1351. #endif
  1352.  
  1353. /* Set ignore-count of breakpoint number BPTNUM to COUNT.
  1354.    If from_tty is nonzero, it prints a message to that effect,
  1355.    which ends with a period (no newline).  */
  1356.  
  1357. void
  1358. set_ignore_count (bptnum, count, from_tty)
  1359.      int bptnum, count, from_tty;
  1360. {
  1361.   register struct breakpoint *b;
  1362.  
  1363.   if (count < 0)
  1364.     count = 0;
  1365.  
  1366.   ALL_BREAKPOINTS (b)
  1367.     if (b->number == bptnum)
  1368.       {
  1369.     b->ignore_count = count;
  1370.     if (!from_tty)
  1371.       return;
  1372.     else if (count == 0)
  1373.       printf ("Will stop next time breakpoint %d is reached.", bptnum);
  1374.     else if (count == 1)
  1375.       printf ("Will ignore next crossing of breakpoint %d.", bptnum);
  1376.     else
  1377.       printf ("Will ignore next %d crossings of breakpoint %d.",
  1378.           count, bptnum);
  1379.     return;
  1380.       }
  1381.  
  1382.   error ("No breakpoint number %d.", bptnum);
  1383. }
  1384.  
  1385. /* Clear the ignore counts of all breakpoints.  */
  1386. void
  1387. breakpoint_clear_ignore_counts ()
  1388. {
  1389.   struct breakpoint *b;
  1390.  
  1391.   ALL_BREAKPOINTS (b)
  1392.     b->ignore_count = 0;
  1393. }
  1394.  
  1395. /* Command to set ignore-count of breakpoint N to COUNT.  */
  1396.  
  1397. static void
  1398. ignore_command (args, from_tty)
  1399.      char *args;
  1400.      int from_tty;
  1401. {
  1402.   register char *p = args;
  1403.   register int num;
  1404.  
  1405.   if (p == 0)
  1406.     error_no_arg ("a breakpoint number");
  1407.   
  1408.   while (*p >= '0' && *p <= '9') p++;
  1409.   if (*p && *p != ' ' && *p != '\t')
  1410.     error ("First argument must be a breakpoint number.");
  1411.  
  1412.   num = atoi (args);
  1413.  
  1414.   if (*p == 0)
  1415.     error ("Second argument (specified ignore-count) is missing.");
  1416.  
  1417.   set_ignore_count (num, parse_and_eval_address (p), from_tty);
  1418.   printf ("\n");
  1419. }
  1420.  
  1421. /* Call FUNCTION on each of the breakpoints
  1422.    whose numbers are given in ARGS.  */
  1423.  
  1424. static void
  1425. map_breakpoint_numbers (args, function)
  1426.      char *args;
  1427.      void (*function) ();
  1428. {
  1429.   register char *p = args;
  1430.   register char *p1;
  1431.   register int num;
  1432.   register struct breakpoint *b;
  1433.  
  1434.   if (p == 0)
  1435.     error_no_arg ("one or more breakpoint numbers");
  1436.  
  1437.   while (*p)
  1438.     {
  1439.       p1 = p;
  1440.       while (*p1 >= '0' && *p1 <= '9') p1++;
  1441.       if (*p1 && *p1 != ' ' && *p1 != '\t')
  1442.     error ("Arguments must be breakpoint numbers.");
  1443.  
  1444.       num = atoi (p);
  1445.  
  1446.       ALL_BREAKPOINTS (b)
  1447.     if (b->number == num)
  1448.       {
  1449.         function (b);
  1450.         goto win;
  1451.       }
  1452.       printf ("No breakpoint number %d.\n", num);
  1453.     win:
  1454.       p = p1;
  1455.       while (*p == ' ' || *p == '\t') p++;
  1456.     }
  1457. }
  1458.  
  1459. static void
  1460. enable_breakpoint (bpt)
  1461.      struct breakpoint *bpt;
  1462. {
  1463.   bpt->enable = enabled;
  1464.  
  1465.   if (xgdb_verbose && bpt->number >= 0)
  1466.     printf ("breakpoint #%d enabled\n", bpt->number);
  1467.  
  1468.   check_duplicates (bpt->address);
  1469. }
  1470.  
  1471. static void
  1472. enable_command (args)
  1473.      char *args;
  1474. {
  1475.   struct breakpoint *bpt;
  1476.   if (args == 0)
  1477.     ALL_BREAKPOINTS (bpt)
  1478.       enable_breakpoint (bpt);
  1479.   else
  1480.     map_breakpoint_numbers (args, enable_breakpoint);
  1481. }
  1482.  
  1483. static void
  1484. disable_breakpoint (bpt)
  1485.      struct breakpoint *bpt;
  1486. {
  1487.   bpt->enable = disabled;
  1488.  
  1489.   if (xgdb_verbose && bpt->number >= 0)
  1490.     printf ("breakpoint #%d disabled\n", bpt->number);
  1491.  
  1492.   check_duplicates (bpt->address);
  1493. }
  1494.  
  1495. static void
  1496. disable_command (args)
  1497.      char *args;
  1498. {
  1499.   register struct breakpoint *bpt;
  1500.   if (args == 0)
  1501.     ALL_BREAKPOINTS (bpt)
  1502.       disable_breakpoint (bpt);
  1503.   else
  1504.     map_breakpoint_numbers (args, disable_breakpoint);
  1505. }
  1506.  
  1507. static void
  1508. enable_once_breakpoint (bpt)
  1509.      struct breakpoint *bpt;
  1510. {
  1511.   bpt->enable = temporary;
  1512.  
  1513.   check_duplicates (bpt->address);
  1514. }
  1515.  
  1516. static void
  1517. enable_once_command (args)
  1518.      char *args;
  1519. {
  1520.   map_breakpoint_numbers (args, enable_once_breakpoint);
  1521. }
  1522.  
  1523. static void
  1524. enable_delete_breakpoint (bpt)
  1525.      struct breakpoint *bpt;
  1526. {
  1527.   bpt->enable = delete;
  1528.  
  1529.   check_duplicates (bpt->address);
  1530. }
  1531.  
  1532. static void
  1533. enable_delete_command (args)
  1534.      char *args;
  1535. {
  1536.   map_breakpoint_numbers (args, enable_delete_breakpoint);
  1537. }
  1538.  
  1539. /*
  1540.  * Use default_breakpoint_'s, or nothing if they aren't valid.
  1541.  */
  1542. struct symtabs_and_lines
  1543. decode_line_spec_1 (string, funfirstline)
  1544.      char *string;
  1545.      int funfirstline;
  1546. {
  1547.   struct symtabs_and_lines sals;
  1548.   if (string == 0)
  1549.     error ("Empty line specification.");
  1550.   if (default_breakpoint_valid)
  1551.     sals = decode_line_1 (&string, funfirstline,
  1552.               default_breakpoint_symtab, default_breakpoint_line);
  1553.   else
  1554.     sals = decode_line_1 (&string, funfirstline, 0, 0);
  1555.   if (*string)
  1556.     error ("Junk at end of line specification: %s", string);
  1557.   return sals;
  1558. }
  1559.  
  1560.  
  1561. /* Chain containing all defined enable commands.  */
  1562.  
  1563. extern struct cmd_list_element 
  1564.   *enablelist, *disablelist,
  1565.   *deletelist, *enablebreaklist;
  1566.  
  1567. extern struct cmd_list_element *cmdlist;
  1568.  
  1569. void
  1570. _initialize_breakpoint ()
  1571. {
  1572.   breakpoint_chain = 0;
  1573.   breakpoint_count = 0;
  1574.  
  1575.   add_com ("ignore", class_breakpoint, ignore_command,
  1576.        "Set ignore-count of breakpoint number N to COUNT.");
  1577.  
  1578.   add_com ("commands", class_breakpoint, commands_command,
  1579.        "Set commands to be executed when a breakpoint is hit.\n\
  1580. Give breakpoint number as argument after \"commands\".\n\
  1581. With no argument, the targeted breakpoint is the last one set.\n\
  1582. The commands themselves follow starting on the next line.\n\
  1583. Type a line containing \"end\" to indicate the end of them.\n\
  1584. Give \"silent\" as the first line to make the breakpoint silent;\n\
  1585. then no output is printed when it is hit, except what the commands print.");
  1586.  
  1587.   add_com ("condition", class_breakpoint, condition_command,
  1588.        "Specify breakpoint number N to break only if COND is true.\n\
  1589. N is an integer; COND is a C expression to be evaluated whenever\n\
  1590. breakpoint N is reached.  Actually break only when COND is nonzero.");
  1591.  
  1592.   add_com ("tbreak", class_breakpoint, tbreak_command,
  1593.        "Set a temporary breakpoint.  Args like \"break\" command.\n\
  1594. Like \"break\" except the breakpoint is only enabled temporarily,\n\
  1595. so it will be disabled when hit.  Equivalent to \"break\" followed\n\
  1596. by using \"enable once\" on the breakpoint number.");
  1597.  
  1598.   add_prefix_cmd ("enable", class_breakpoint, enable_command,
  1599.           "Enable some breakpoints or auto-display expressions.\n\
  1600. Give breakpoint numbers (separated by spaces) as arguments.\n\
  1601. With no subcommand, breakpoints are enabled until you command otherwise.\n\
  1602. This is used to cancel the effect of the \"disable\" command.\n\
  1603. With a subcommand you can enable temporarily.\n\
  1604. \n\
  1605. The \"display\" subcommand applies to auto-displays instead of breakpoints.",
  1606.           &enablelist, "enable ", 1, &cmdlist);
  1607.  
  1608.   add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
  1609.           "Enable some breakpoints or auto-display expressions.\n\
  1610. Give breakpoint numbers (separated by spaces) as arguments.\n\
  1611. With no subcommand, breakpoints are enabled until you command otherwise.\n\
  1612. This is used to cancel the effect of the \"disable\" command.\n\
  1613. May be abbreviates to simply \"enable\".\n\
  1614. With a subcommand you can enable temporarily.",
  1615.           &enablebreaklist, "enable breakpoints ", 1, &enablelist);
  1616.  
  1617.   add_cmd ("once", no_class, enable_once_command,
  1618.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  1619. If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
  1620. See the \"tbreak\" command which sets a breakpoint and enables it once.",
  1621.        &enablebreaklist);
  1622.  
  1623.   add_cmd ("delete", no_class, enable_delete_command,
  1624.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  1625. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  1626.        &enablebreaklist);
  1627.  
  1628.   add_cmd ("delete", no_class, enable_delete_command,
  1629.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  1630. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  1631.        &enablelist);
  1632.  
  1633.   add_cmd ("once", no_class, enable_once_command,
  1634.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  1635. If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
  1636. See the \"tbreak\" command which sets a breakpoint and enables it once.",
  1637.        &enablelist);
  1638.  
  1639.   add_prefix_cmd ("disable", class_breakpoint, disable_command,
  1640.        "Disable some breakpoints or auto-display expressions.\n\
  1641. Arguments are breakpoint numbers with spaces in between.\n\
  1642. To disable all breakpoints, give no argument.\n\
  1643. A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
  1644. \n\
  1645. The \"display\" subcommand applies to auto-displays instead of breakpoints.",
  1646.           &disablelist, "disable ", 1, &cmdlist);
  1647.   add_com_alias ("dis", "disable", class_breakpoint, 1);
  1648.   add_com_alias ("disa", "disable", class_breakpoint, 1);
  1649.  
  1650.   add_abbrev_cmd ("breakpoints", class_breakpoint, disable_command,
  1651.        "Disable some breakpoints or auto-display expressions.\n\
  1652. Arguments are breakpoint numbers with spaces in between.\n\
  1653. To disable all breakpoints, give no argument.\n\
  1654. A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
  1655. This command may be abbreviated \"disable\".",
  1656.        &disablelist);
  1657.  
  1658.   add_prefix_cmd ("delete", class_breakpoint, delete_command,
  1659.        "Delete some breakpoints or auto-display expressions.\n\
  1660. Arguments are breakpoint numbers with spaces in between.\n\
  1661. To delete all breakpoints, give no argument.\n\
  1662. \n\
  1663. Also a prefix command for deletion of other GDB objects.\n\
  1664. The \"unset\" command is also an alias for \"delete\".",
  1665.           &deletelist, "delete ", 1, &cmdlist);
  1666.   add_com_alias ("d", "delete", class_breakpoint, 1);
  1667.   add_com_alias ("unset", "delete", class_alias, 1);
  1668.  
  1669.   add_cmd ("breakpoints", class_alias, delete_command,
  1670.        "Delete some breakpoints or auto-display expressions.\n\
  1671. Arguments are breakpoint numbers with spaces in between.\n\
  1672. To delete all breakpoints, give no argument.\n\
  1673. This command may be abbreviated \"delete\".",
  1674.        &deletelist);
  1675.  
  1676.   add_com ("clear", class_breakpoint, clear_command,
  1677.        "Clear breakpoint at specified line or function.\n\
  1678. Argument may be line number, function name, or \"*\" and an address.\n\
  1679. If line number is specified, all breakpoints in that line are cleared.\n\
  1680. If function is specified, breakpoints at beginning of function are cleared.\n\
  1681. If an address is specified, breakpoints at that address are cleared.\n\n\
  1682. With no argument, clears all breakpoints in the line that the selected frame\n\
  1683. is executing in.\n\
  1684. \n\
  1685. See also the \"delete\" command which clears breakpoints by number.");
  1686.  
  1687.   add_com ("break", class_breakpoint, break_command,
  1688.        "Set breakpoint at specified line or function.\n\
  1689. Argument may be line number, function name, or \"*\" and an address.\n\
  1690. If line number is specified, break at start of code for that line.\n\
  1691. If function is specified, break at start of code for that function.\n\
  1692. If an address is specified, break at that exact address.\n\
  1693. With no arg, uses current execution address of selected stack frame.\n\
  1694. This is useful for breaking on return to a stack frame.\n\
  1695. \n\
  1696. Multiple breakpoints at one place are permitted, and useful if conditional.\n\
  1697. \n\
  1698. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  1699.   add_com_alias ("b", "break", class_run, 1);
  1700.   add_com_alias ("br", "break", class_run, 1);
  1701.   add_com_alias ("bre", "break", class_run, 1);
  1702.   add_com_alias ("brea", "break", class_run, 1);
  1703.  
  1704.   add_info ("breakpoints", breakpoints_info,
  1705.         "Status of all breakpoints, or breakpoint number NUMBER.\n\
  1706. Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
  1707. \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
  1708. Then come the address and the file/line number.\n\n\
  1709. Convenience variable \"$_\" and default examine address for \"x\"\n\
  1710. are set to the address of the last breakpoint listed.");
  1711.  
  1712.   add_com ("catch", class_breakpoint, catch_command,
  1713.        "Set breakpoints to catch exceptions that are raised.\n\
  1714. Argument may be a single exception to catch, multiple exceptions\n\
  1715. to catch, or the default exception \"default\".  If no arguments\n\
  1716. are given, breakpoints are set at all exception handlers catch clauses\n\
  1717. within the current scope.\n\
  1718. \n\
  1719. A condition specified for the catch applies to all breakpoints set\n\
  1720. with this command\n\
  1721. \n\
  1722. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  1723. }
  1724.