]> Git Repo - binutils.git/blob - gdb/breakpoint.c
ansi name abuse changes
[binutils.git] / gdb / breakpoint.c
1 /* Everything about breakpoints, for GDB.
2    Copyright (C) 1986, 1987, 1989, 1990 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program 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 2 of the License, or
9 (at your option) any later version.
10
11 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include <stdio.h>
21 #include <ctype.h>
22 #include "defs.h"
23 #include "param.h"
24 #include "symtab.h"
25 #include "frame.h"
26 #include "breakpoint.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 "target.h"
35 #include "language.h"
36 #include <string.h>
37
38 extern int addressprint;                /* Print machine addresses? */
39 extern int demangle;                    /* Print de-mangled symbol names? */
40
41 extern int catch_errors ();
42 extern void set_next_address ();        /* ...for x/ command */
43
44 /* Are we executing breakpoint commands?  */
45 static int executing_breakpoint_commands;
46
47 /* States of enablement of breakpoint.
48    `temporary' means disable when hit.
49    `delete' means delete when hit.  */
50
51 enum enable { disabled, enabled, temporary, delete};
52
53 /* Not that the ->silent field is not currently used by any commands
54    (though the code is in there if it was to be, and set_raw_breakpoint
55    does set it to 0).  I implemented it because I thought it would be
56    useful for a hack I had to put in; I'm going to leave it in because
57    I can see how there might be times when it would indeed be useful */
58
59 /* This is for a breakpoint or a watchpoint.  */
60
61 struct breakpoint
62 {
63   struct breakpoint *next;
64   /* Number assigned to distinguish breakpoints.  */
65   int number;
66   /* Address to break at, or NULL if not a breakpoint.  */
67   CORE_ADDR address;
68   /* Line number of this address.  Redundant.  Only matters if address
69      is non-NULL.  */
70   int line_number;
71   /* Symtab of file of this address.  Redundant.  Only matters if address
72      is non-NULL.  */
73   struct symtab *symtab;
74   /* Zero means disabled; remember the info but don't break here.  */
75   enum enable enable;
76   /* Non-zero means a silent breakpoint (don't print frame info
77      if we stop here). */
78   unsigned char silent;
79   /* Number of stops at this breakpoint that should
80      be continued automatically before really stopping.  */
81   int ignore_count;
82   /* "Real" contents of byte where breakpoint has been inserted.
83      Valid only when breakpoints are in the program.  Under the complete
84      control of the target insert_breakpoint and remove_breakpoint routines.
85      No other code should assume anything about the value(s) here.  */
86   char shadow_contents[BREAKPOINT_MAX];
87   /* Nonzero if this breakpoint is now inserted.  Only matters if address
88      is non-NULL.  */
89   char inserted;
90   /* Nonzero if this is not the first breakpoint in the list
91      for the given address.  Only matters if address is non-NULL.  */
92   char duplicate;
93   /* Chain of command lines to execute when this breakpoint is hit.  */
94   struct command_line *commands;
95   /* Stack depth (address of frame).  If nonzero, break only if fp
96      equals this.  */
97   FRAME_ADDR frame;
98   /* Conditional.  Break only if this expression's value is nonzero.  */
99   struct expression *cond;
100
101   /* String we used to set the breakpoint (malloc'd).  Only matters if
102      address is non-NULL.  */
103   char *addr_string;
104   /* String form of the breakpoint condition (malloc'd), or NULL if there
105      is no condition.  */
106   char *cond_string;
107
108   /* The expression we are watching, or NULL if not a watchpoint.  */
109   struct expression *exp;
110   /* The largest block within which it is valid, or NULL if it is
111      valid anywhere (e.g. consists just of global symbols).  */
112   struct block *exp_valid_block;
113   /* Value of the watchpoint the last time we checked it.  */
114   value val;
115 };
116
117 #define ALL_BREAKPOINTS(b)  for (b = breakpoint_chain; b; b = b->next)
118
119 /* Chain of all breakpoints defined.  */
120
121 struct breakpoint *breakpoint_chain;
122
123 /* Number of last breakpoint made.  */
124
125 static int breakpoint_count;
126
127 /* Set breakpoint count to NUM.  */
128 static void
129 set_breakpoint_count (num)
130      int num;
131 {
132   breakpoint_count = num;
133   set_internalvar (lookup_internalvar ("bpnum"),
134                    value_from_longest (builtin_type_int, (LONGEST) num));
135 }
136
137 /* Default address, symtab and line to put a breakpoint at
138    for "break" command with no arg.
139    if default_breakpoint_valid is zero, the other three are
140    not valid, and "break" with no arg is an error.
141
142    This set by print_stack_frame, which calls set_default_breakpoint.  */
143
144 int default_breakpoint_valid;
145 CORE_ADDR default_breakpoint_address;
146 struct symtab *default_breakpoint_symtab;
147 int default_breakpoint_line;
148
149 static void delete_breakpoint ();
150 void breakpoint_auto_delete ();
151
152 /* Flag indicating extra verbosity for xgdb.  */
153 extern int xgdb_verbose;
154 \f
155 /* *PP is a string denoting a breakpoint.  Get the number of the breakpoint.
156    Advance *PP after the string and any trailing whitespace.
157
158    Currently the string can either be a number or "$" followed by the name
159    of a convenience variable.  Making it an expression wouldn't work well
160    for map_breakpoint_numbers (e.g. "4 + 5 + 6").  */
161 static int
162 get_number (pp)
163      char **pp;
164 {
165   int retval;
166   char *p = *pp;
167
168   if (p == NULL)
169     /* Empty line means refer to the last breakpoint.  */
170     return breakpoint_count;
171   else if (*p == '$')
172     {
173       /* Make a copy of the name, so we can null-terminate it
174          to pass to lookup_internalvar().  */
175       char *varname;
176       char *start = ++p;
177       value val;
178
179       while (isalnum (*p) || *p == '_')
180         p++;
181       varname = (char *) alloca (p - start + 1);
182       strncpy (varname, start, p - start);
183       varname[p - start] = '\0';
184       val = value_of_internalvar (lookup_internalvar (varname));
185       if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
186         error (
187 "Convenience variables used to specify breakpoints must have integer values."
188                );
189       retval = (int) value_as_long (val);
190     }
191   else
192     {
193       while (*p >= '0' && *p <= '9')
194         ++p;
195       if (p == *pp)
196         /* There is no number here.  (e.g. "cond a == b").  */
197         error_no_arg ("breakpoint number");
198       retval = atoi (*pp);
199     }
200   if (!(isspace (*p) || *p == '\0'))
201     error ("breakpoint number expected");
202   while (isspace (*p))
203     p++;
204   *pp = p;
205   return retval;
206 }
207 \f
208 /* condition N EXP -- set break condition of breakpoint N to EXP.  */
209
210 static void
211 condition_command (arg, from_tty)
212      char *arg;
213      int from_tty;
214 {
215   register struct breakpoint *b;
216   char *p;
217   register int bnum;
218
219   if (arg == 0)
220     error_no_arg ("breakpoint number");
221
222   p = arg;
223   bnum = get_number (&p);
224
225   ALL_BREAKPOINTS (b)
226     if (b->number == bnum)
227       {
228         if (b->cond)
229           {
230             free (b->cond);
231             b->cond = 0;
232           }
233         if (b->cond_string != NULL)
234           free (b->cond_string);
235
236         if (*p == 0)
237           {
238             b->cond = 0;
239             b->cond_string = NULL;
240             if (from_tty)
241               printf ("Breakpoint %d now unconditional.\n", bnum);
242           }
243         else
244           {
245             arg = p;
246             /* I don't know if it matters whether this is the string the user
247                typed in or the decompiled expression.  */
248             b->cond_string = savestring (arg, strlen (arg));
249             b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
250             if (*arg)
251               error ("Junk at end of expression");
252           }
253         return;
254       }
255
256   error ("No breakpoint number %d.", bnum);
257 }
258
259 /* ARGSUSED */
260 static void
261 commands_command (arg, from_tty)
262      char *arg;
263      int from_tty;
264 {
265   register struct breakpoint *b;
266   char *p;
267   register int bnum;
268   struct command_line *l;
269
270   /* If we allowed this, we would have problems with when to
271      free the storage, if we change the commands currently
272      being read from.  */
273
274   if (executing_breakpoint_commands)
275     error ("Can't use the \"commands\" command among a breakpoint's commands.");
276
277   p = arg;
278   bnum = get_number (&p);
279   if (p && *p)
280     error ("Unexpected extra arguments following breakpoint number.");
281       
282   ALL_BREAKPOINTS (b)
283     if (b->number == bnum)
284       {
285         if (from_tty && input_from_terminal_p ())
286           {
287             printf ("Type commands for when breakpoint %d is hit, one per line.\n\
288 End with a line saying just \"end\".\n", bnum);
289             fflush (stdout);
290           }
291         l = read_command_lines ();
292         free_command_lines (&b->commands);
293         b->commands = l;
294         return;
295       }
296   error ("No breakpoint number %d.", bnum);
297 }
298 \f
299 extern int memory_breakpoint_size; /* from mem-break.c */
300
301 /* Like target_read_memory() but if breakpoints are inserted, return
302    the shadow contents instead of the breakpoints themselves.  */
303 int
304 read_memory_nobpt (memaddr, myaddr, len)
305      CORE_ADDR memaddr;
306      char *myaddr;
307      unsigned len;
308 {
309   int status;
310   struct breakpoint *b;
311
312   if (memory_breakpoint_size < 0)
313     /* No breakpoints on this machine.  */
314     return target_read_memory (memaddr, myaddr, len);
315   
316   ALL_BREAKPOINTS (b)
317     {
318       if (b->address == NULL || !b->inserted)
319         continue;
320       else if (b->address + memory_breakpoint_size <= memaddr)
321         /* The breakpoint is entirely before the chunk of memory
322            we are reading.  */
323         continue;
324       else if (b->address >= memaddr + len)
325         /* The breakpoint is entirely after the chunk of memory we
326            are reading.  */
327         continue;
328       else
329         {
330           /* Copy the breakpoint from the shadow contents, and recurse
331              for the things before and after.  */
332           
333           /* Addresses and length of the part of the breakpoint that
334              we need to copy.  */
335           CORE_ADDR membpt = b->address;
336           unsigned int bptlen = memory_breakpoint_size;
337           /* Offset within shadow_contents.  */
338           int bptoffset = 0;
339           
340           if (membpt < memaddr)
341             {
342               /* Only copy the second part of the breakpoint.  */
343               bptlen -= memaddr - membpt;
344               bptoffset = memaddr - membpt;
345               membpt = memaddr;
346             }
347
348           if (membpt + bptlen > memaddr + len)
349             {
350               /* Only copy the first part of the breakpoint.  */
351               bptlen -= (membpt + bptlen) - (memaddr + len);
352             }
353
354           bcopy (b->shadow_contents + bptoffset,
355                  myaddr + membpt - memaddr, bptlen);
356
357           if (membpt > memaddr)
358             {
359               /* Copy the section of memory before the breakpoint.  */
360               status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
361               if (status != 0)
362                 return status;
363             }
364
365           if (membpt + bptlen < memaddr + len)
366             {
367               /* Copy the section of memory after the breakpoint.  */
368               status = read_memory_nobpt
369                 (membpt + bptlen,
370                  myaddr + membpt + bptlen - memaddr,
371                  memaddr + len - (membpt + bptlen));
372               if (status != 0)
373                 return status;
374             }
375           return 0;
376         }
377     }
378   /* Nothing overlaps.  Just call read_memory_noerr.  */
379   return target_read_memory (memaddr, myaddr, len);
380 }
381 \f
382 /* insert_breakpoints is used when starting or continuing the program.
383    remove_breakpoints is used when the program stops.
384    Both return zero if successful,
385    or an `errno' value if could not write the inferior.  */
386
387 int
388 insert_breakpoints ()
389 {
390   register struct breakpoint *b;
391   int val = 0;
392   int disabled_breaks = 0;
393
394   ALL_BREAKPOINTS (b)
395     if (b->address != NULL
396         && b->enable != disabled
397         && ! b->inserted
398         && ! b->duplicate)
399       {
400         val = target_insert_breakpoint(b->address, b->shadow_contents);
401         if (val)
402           {
403             /* Can't set the breakpoint.  */
404 #if defined (DISABLE_UNSETTABLE_BREAK)
405             if (DISABLE_UNSETTABLE_BREAK (b->address))
406               {
407                 val = 0;
408                 b->enable = disabled;
409                 if (!disabled_breaks)
410                   {
411                     fprintf (stderr,
412                          "Cannot insert breakpoint %d:\n", b->number);
413                     printf_filtered ("Disabling shared library breakpoints:\n");
414                   }
415                 disabled_breaks = 1;
416                 printf_filtered ("%d ", b->number);
417               }
418             else
419 #endif
420               {
421                 fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
422 #ifdef ONE_PROCESS_WRITETEXT
423                 fprintf (stderr,
424                   "The same program may be running in another process.\n");
425 #endif
426                 memory_error (val, b->address); /* which bombs us out */
427               }
428           }
429         else
430           b->inserted = 1;
431       }
432   if (disabled_breaks)
433     printf_filtered ("\n");
434   return val;
435 }
436
437 int
438 remove_breakpoints ()
439 {
440   register struct breakpoint *b;
441   int val;
442
443 #ifdef BREAKPOINT_DEBUG
444   printf ("Removing breakpoints.\n");
445 #endif /* BREAKPOINT_DEBUG */
446
447   ALL_BREAKPOINTS (b)
448     if (b->address != NULL && b->inserted)
449       {
450         val = target_remove_breakpoint(b->address, b->shadow_contents);
451         if (val)
452           return val;
453         b->inserted = 0;
454 #ifdef BREAKPOINT_DEBUG
455         printf ("Removed breakpoint at %s",
456                 local_hex_string(b->address));
457         printf (", shadow %s",
458                 local_hex_string(b->shadow_contents[0]));
459         printf (", %s.\n",
460                 local_hex_string(b->shadow_contents[1]));
461 #endif /* BREAKPOINT_DEBUG */
462       }
463
464   return 0;
465 }
466
467 /* Clear the "inserted" flag in all breakpoints.
468    This is done when the inferior is loaded.  */
469
470 void
471 mark_breakpoints_out ()
472 {
473   register struct breakpoint *b;
474
475   ALL_BREAKPOINTS (b)
476     b->inserted = 0;
477 }
478
479 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
480    When continuing from a location with a breakpoint,
481    we actually single step once before calling insert_breakpoints.  */
482
483 int
484 breakpoint_here_p (pc)
485      CORE_ADDR pc;
486 {
487   register struct breakpoint *b;
488
489   ALL_BREAKPOINTS (b)
490     if (b->enable != disabled && b->address == pc)
491       return 1;
492
493   return 0;
494 }
495 \f
496 /* bpstat stuff.  External routines' interfaces are documented
497    in breakpoint.h.  */
498 void
499 bpstat_clear (bsp)
500      bpstat *bsp;
501 {
502   bpstat p;
503   bpstat q;
504
505   if (bsp == 0)
506     return;
507   p = *bsp;
508   while (p != NULL)
509     {
510       q = p->next;
511       if (p->old_val != NULL)
512         value_free (p->old_val);
513       free (p);
514       p = q;
515     }
516   *bsp = NULL;
517 }
518
519 bpstat
520 bpstat_copy (bs)
521      bpstat bs;
522 {
523   bpstat p = NULL;
524   bpstat tmp;
525   bpstat retval;
526
527   if (bs == NULL)
528     return bs;
529
530   for (; bs != NULL; bs = bs->next)
531     {
532       tmp = (bpstat) xmalloc (sizeof (*tmp));
533       bcopy (bs, tmp, sizeof (*tmp));
534       if (p == NULL)
535         /* This is the first thing in the chain.  */
536         retval = tmp;
537       else
538         p->next = tmp;
539       p = tmp;
540     }
541   p->next = NULL;
542   return retval;
543 }
544
545 int
546 bpstat_num (bsp)
547      bpstat *bsp;
548 {
549   struct breakpoint *b;
550
551   if ((*bsp) == NULL)
552     return 0;                   /* No more breakpoint values */
553   else
554     {
555       b = (*bsp)->breakpoint_at;
556       *bsp = (*bsp)->next;
557       if (b == NULL)
558         return -1;              /* breakpoint that's been deleted since */
559       else
560         return b->number;       /* We have its number */
561     }
562 }
563
564 void
565 bpstat_clear_actions (bs)
566      bpstat bs;
567 {
568   for (; bs != NULL; bs = bs->next)
569     {
570       bs->commands = NULL;
571       if (bs->old_val != NULL)
572         {
573           value_free (bs->old_val);
574           bs->old_val = NULL;
575         }
576     }
577 }
578
579 /* Stub for cleaning up our state if we error-out of a breakpoint command */
580 /* ARGSUSED */
581 static void
582 cleanup_executing_breakpoints (ignore)
583      int ignore;
584 {
585   executing_breakpoint_commands = 0;
586 }
587
588 /* Execute all the commands associated with all the breakpoints at this
589    location.  Any of these commands could cause the process to proceed
590    beyond this point, etc.  We look out for such changes by checking
591    the global "breakpoint_proceeded" after each command.  */
592 void
593 bpstat_do_actions (bsp)
594      bpstat *bsp;
595 {
596   bpstat bs;
597   struct cleanup *old_chain;
598
599   executing_breakpoint_commands = 1;
600   old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
601
602 top:
603   bs = *bsp;
604
605   breakpoint_proceeded = 0;
606   for (; bs != NULL; bs = bs->next)
607     {
608       while (bs->commands)
609         {
610           char *line = bs->commands->line;
611           bs->commands = bs->commands->next;
612           execute_command (line, 0);
613           /* If the inferior is proceeded by the command, bomb out now.
614              The bpstat chain has been blown away by wait_for_inferior.
615              But since execution has stopped again, there is a new bpstat
616              to look at, so start over.  */
617           if (breakpoint_proceeded)
618             goto top;
619         }
620     }
621   clear_momentary_breakpoints ();
622
623   executing_breakpoint_commands = 0;
624   discard_cleanups (old_chain);
625 }
626
627 int
628 bpstat_print (bs)
629      bpstat bs;
630 {
631   /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
632      which has since been deleted.  */
633   if (bs == NULL || bs->breakpoint_at == NULL)
634     return 0;
635   
636   /* If bpstat_stop_status says don't print, OK, we won't.  An example
637      circumstance is when we single-stepped for both a watchpoint and
638      for a "stepi" instruction.  The bpstat says that the watchpoint
639      explains the stop, but we shouldn't print because the watchpoint's
640      value didn't change -- and the real reason we are stopping here
641      rather than continuing to step (as the watchpoint would've had us do)
642      is because of the "stepi".  */
643   if (!bs->print)
644     return 0;
645
646   if (bs->breakpoint_at->address != NULL)
647     {
648       /* I think the user probably only wants to see one breakpoint
649          number, not all of them.  */
650       printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
651       return 0;
652     }
653       
654   if (bs->old_val != NULL)
655     {
656       printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
657       print_expression (bs->breakpoint_at->exp, stdout);
658       printf_filtered ("\nOld value = ");
659       value_print (bs->old_val, stdout, 0, Val_pretty_default);
660       printf_filtered ("\nNew value = ");
661       value_print (bs->breakpoint_at->val, stdout, 0,
662                    Val_pretty_default);
663       printf_filtered ("\n");
664       value_free (bs->old_val);
665       bs->old_val = NULL;
666       return 1;
667     }
668
669   /* Maybe another breakpoint in the chain caused us to stop.
670      (Currently all watchpoints go on the bpstat whether hit or
671      not.  That probably could (should) be changed, provided care is taken
672      with respect to bpstat_explains_signal).  */
673   if (bs->next)
674     return bpstat_print (bs->next);
675
676   fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
677   return 0;
678 }
679
680 /* Evaluate the expression EXP and return 1 if value is zero.
681    This is used inside a catch_errors to evaluate the breakpoint condition. 
682    The argument is a "struct expression *" that has been cast to char * to 
683    make it pass through catch_errors.  */
684
685 static int
686 breakpoint_cond_eval (exp)
687      char *exp;
688 {
689   return !value_true (evaluate_expression ((struct expression *)exp));
690 }
691
692 /* Allocate a new bpstat and chain it to the current one.  */
693
694 static bpstat
695 bpstat_alloc (b, cbs)
696      register struct breakpoint *b;
697      bpstat cbs;                        /* Current "bs" value */
698 {
699   bpstat bs;
700
701   bs = (bpstat) xmalloc (sizeof (*bs));
702   cbs->next = bs;
703   bs->breakpoint_at = b;
704   /* If the condition is false, etc., don't do the commands.  */
705   bs->commands = NULL;
706   bs->momentary = b->number == -3;
707   bs->old_val = NULL;
708   return bs;
709 }
710
711 /* Determine whether we stopped at a breakpoint, etc, or whether we
712    don't understand this stop.  Result is a chain of bpstat's such that:
713
714         if we don't understand the stop, the result is a null pointer.
715
716         if we understand why we stopped, the result is not null, and
717         the first element of the chain contains summary "stop" and
718         "print" flags for the whole chain.
719
720         Each element of the chain refers to a particular breakpoint or
721         watchpoint at which we have stopped.  (We may have stopped for
722         several reasons.)
723
724         Each element of the chain has valid next, breakpoint_at,
725         commands, FIXME??? fields.
726
727  */
728
729         
730 bpstat
731 bpstat_stop_status (pc, frame_address)
732      CORE_ADDR *pc;
733      FRAME_ADDR frame_address;
734 {
735   register struct breakpoint *b;
736   int stop = 0;
737   int print = 0;
738   CORE_ADDR bp_addr;
739 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
740   /* True if we've hit a breakpoint (as opposed to a watchpoint).  */
741   int real_breakpoint = 0;
742 #endif
743   /* Root of the chain of bpstat's */
744   struct bpstat__struct root_bs[1];
745   /* Pointer to the last thing in the chain currently.  */
746   bpstat bs = root_bs;
747
748   /* Get the address where the breakpoint would have been.  */
749   bp_addr = *pc - DECR_PC_AFTER_BREAK;
750
751   ALL_BREAKPOINTS (b)
752     {
753       int this_bp_stop;
754       int this_bp_print;
755
756       if (b->enable == disabled)
757         continue;
758       if (b->address != NULL && b->address != bp_addr)
759         continue;
760
761       bs = bpstat_alloc (b, bs);        /* Alloc a bpstat to explain stop */
762
763       this_bp_stop = 1;
764       this_bp_print = 1;
765
766       if (b->exp != NULL)               /* Watchpoint */
767         {
768           int within_current_scope;
769           if (b->exp_valid_block != NULL)
770             within_current_scope =
771               contained_in (get_selected_block (), b->exp_valid_block);
772           else
773             within_current_scope = 1;
774
775           if (within_current_scope)
776             {
777               /* We use value_{,free_to_}mark because it could be a
778                  *long* time before we return to the command level and
779                  call free_all_values.  */
780
781               value mark = value_mark ();
782               value new_val = evaluate_expression (b->exp);
783               if (!value_equal (b->val, new_val))
784                 {
785                   release_value (new_val);
786                   value_free_to_mark (mark);
787                   bs->old_val = b->val;
788                   b->val = new_val;
789                   /* We will stop here */
790                 }
791               else
792                 {
793                   /* Nothing changed, don't do anything.  */
794                   value_free_to_mark (mark);
795                   continue;
796                   /* We won't stop here */
797                 }
798             }
799           else
800             {
801               /* This seems like the only logical thing to do because
802                  if we temporarily ignored the watchpoint, then when
803                  we reenter the block in which it is valid it contains
804                  garbage (in the case of a function, it may have two
805                  garbage values, one before and one after the prologue).
806                  So we can't even detect the first assignment to it and
807                  watch after that (since the garbage may or may not equal
808                  the first value assigned).  */
809               b->enable = disabled;
810               printf_filtered ("\
811 Watchpoint %d disabled because the program has left the block in\n\
812 which its expression is valid.\n", b->number);
813               /* We won't stop here */
814               /* FIXME, maybe we should stop here!!! */
815               continue;
816             }
817         }
818 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
819       else
820         real_breakpoint = 1;
821 #endif
822
823       if (b->frame && b->frame != frame_address)
824         this_bp_stop = 0;
825       else
826         {
827           int value_is_zero;
828
829           if (b->cond)
830             {
831               /* Need to select the frame, with all that implies
832                  so that the conditions will have the right context.  */
833               select_frame (get_current_frame (), 0);
834               value_is_zero
835                 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
836                                 "Error in testing breakpoint condition:\n");
837                                 /* FIXME-someday, should give breakpoint # */
838               free_all_values ();
839             }
840           if (b->cond && value_is_zero)
841             {
842               this_bp_stop = 0;
843             }
844           else if (b->ignore_count > 0)
845             {
846               b->ignore_count--;
847               this_bp_stop = 0;
848             }
849           else
850             {
851               /* We will stop here */
852               if (b->enable == temporary)
853                 b->enable = disabled;
854               bs->commands = b->commands;
855               if (b->silent)
856                 this_bp_print = 0;
857               if (bs->commands && !strcmp ("silent", bs->commands->line))
858                 {
859                   bs->commands = bs->commands->next;
860                   this_bp_print = 0;
861                 }
862             }
863         }
864       if (this_bp_stop)
865         stop = 1;
866       if (this_bp_print)
867         print = 1;
868     }
869
870   bs->next = NULL;              /* Terminate the chain */
871   bs = root_bs->next;           /* Re-grab the head of the chain */
872   if (bs)
873     {
874       bs->stop = stop;
875       bs->print = print;
876 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
877       if (real_breakpoint)
878         {
879           *pc = bp_addr;
880 #if defined (SHIFT_INST_REGS)
881           {
882             CORE_ADDR pc = read_register (PC_REGNUM);
883             CORE_ADDR npc = read_register (NPC_REGNUM);
884             if (pc != npc)
885               {
886                 write_register (NNPC_REGNUM, npc);
887                 write_register (NPC_REGNUM, pc);
888               }
889           }
890 #else /* No SHIFT_INST_REGS.  */
891           write_pc (bp_addr);
892 #endif /* No SHIFT_INST_REGS.  */
893         }
894 #endif /* DECR_PC_AFTER_BREAK != 0.  */
895     }
896   return bs;
897 }
898
899 int 
900 bpstat_should_step ()
901 {
902   struct breakpoint *b;
903   ALL_BREAKPOINTS (b)
904     if (b->enable != disabled && b->exp != NULL)
905       return 1;
906   return 0;
907 }
908 \f
909 /* Print information on breakpoint number BNUM, or -1 if all.
910    If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
911    is nonzero, process only watchpoints.  */
912
913 static void
914 breakpoint_1 (bnum, watchpoints)
915      int bnum;
916      int watchpoints;
917 {
918   register struct breakpoint *b;
919   register struct command_line *l;
920   register struct symbol *sym;
921   CORE_ADDR last_addr = (CORE_ADDR)-1;
922   int header_printed = 0;
923   
924   ALL_BREAKPOINTS (b)
925     if (bnum == -1 || bnum == b->number)
926       {
927         if (b->address == NULL && !watchpoints)
928           {
929             if (bnum == -1)
930               continue;
931             error ("That is a watchpoint, not a breakpoint.");
932           }
933         if (b->address != NULL && watchpoints)
934           {
935             if (bnum == -1)
936               continue;
937             error ("That is a breakpoint, not a watchpoint.");
938           }
939
940         if (!header_printed)
941           {
942             if (watchpoints)
943               printf_filtered ("    Enb   Expression\n");
944             else if (addressprint)
945               printf_filtered ("    Enb   Address    Where\n");
946             else
947               printf_filtered ("    Enb   Where\n");
948             header_printed = 1;
949           }
950
951         printf_filtered ("#%-3d %c ", b->number, "nyod"[(int) b->enable]);
952         if (b->address == NULL) {
953           printf_filtered (" ");
954           print_expression (b->exp, stdout);
955         } else {
956             if (addressprint)
957               printf_filtered (" %s ", local_hex_string_custom(b->address, "08"));
958
959             last_addr = b->address;
960             if (b->symtab)
961               {
962                 sym = find_pc_function (b->address);
963                 if (sym)
964                   {
965                     fputs_filtered (" in ", stdout);
966                     fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
967                     fputs_filtered (" at ", stdout);
968                   }
969                 fputs_filtered (b->symtab->filename, stdout);
970                 printf_filtered (":%d", b->line_number);
971               }
972             else
973               print_address_symbolic (b->address, stdout, demangle, " ");
974           }
975
976         printf_filtered ("\n");
977
978         if (b->frame)
979           printf_filtered ("\tstop only in stack frame at %s\n",
980                            local_hex_string(b->frame));
981         if (b->cond)
982           {
983             printf_filtered ("\tstop only if ");
984             print_expression (b->cond, stdout);
985             printf_filtered ("\n");
986           }
987         if (b->ignore_count)
988           printf_filtered ("\tignore next %d hits\n", b->ignore_count);
989         if ((l = b->commands))
990           while (l)
991             {
992               fputs_filtered ("\t", stdout);
993               fputs_filtered (l->line, stdout);
994               fputs_filtered ("\n", stdout);
995               l = l->next;
996             }
997       }
998
999   if (!header_printed)
1000     {
1001       char *which = watchpoints ? "watch" : "break";
1002       if (bnum == -1)
1003         printf_filtered ("No %spoints.\n", which);
1004       else
1005         printf_filtered ("No %spoint numbered %d.\n", which, bnum);
1006     }
1007
1008   /* Compare against (CORE_ADDR)-1 in case some compiler decides
1009      that a comparison of an unsigned with -1 is always false.  */
1010   if (last_addr != (CORE_ADDR)-1)
1011     set_next_address (last_addr);
1012 }
1013
1014 /* ARGSUSED */
1015 static void
1016 breakpoints_info (bnum_exp, from_tty)
1017      char *bnum_exp;
1018      int from_tty;
1019 {
1020   int bnum = -1;
1021
1022   if (bnum_exp)
1023     bnum = parse_and_eval_address (bnum_exp);
1024
1025   breakpoint_1 (bnum, 0);
1026 }
1027
1028 /* ARGSUSED */
1029 static void
1030 watchpoints_info (bnum_exp, from_tty)
1031      char *bnum_exp;
1032      int from_tty;
1033 {
1034   int bnum = -1;
1035
1036   if (bnum_exp)
1037     bnum = parse_and_eval_address (bnum_exp);
1038
1039   breakpoint_1 (bnum, 1);
1040 }
1041
1042 /* Print a message describing any breakpoints set at PC.  */
1043
1044 static void
1045 describe_other_breakpoints (pc)
1046      register CORE_ADDR pc;
1047 {
1048   register int others = 0;
1049   register struct breakpoint *b;
1050
1051   ALL_BREAKPOINTS (b)
1052     if (b->address == pc)
1053       others++;
1054   if (others > 0)
1055     {
1056       printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
1057       ALL_BREAKPOINTS (b)
1058         if (b->address == pc)
1059           {
1060             others--;
1061             printf ("%d%s%s ",
1062                     b->number,
1063                     (b->enable == disabled) ? " (disabled)" : "",
1064                     (others > 1) ? "," : ((others == 1) ? " and" : ""));
1065           }
1066       printf ("also set at pc %s.\n", local_hex_string(pc));
1067     }
1068 }
1069 \f
1070 /* Set the default place to put a breakpoint
1071    for the `break' command with no arguments.  */
1072
1073 void
1074 set_default_breakpoint (valid, addr, symtab, line)
1075      int valid;
1076      CORE_ADDR addr;
1077      struct symtab *symtab;
1078      int line;
1079 {
1080   default_breakpoint_valid = valid;
1081   default_breakpoint_address = addr;
1082   default_breakpoint_symtab = symtab;
1083   default_breakpoint_line = line;
1084 }
1085
1086 /* Rescan breakpoints at address ADDRESS,
1087    marking the first one as "first" and any others as "duplicates".
1088    This is so that the bpt instruction is only inserted once.  */
1089
1090 static void
1091 check_duplicates (address)
1092      CORE_ADDR address;
1093 {
1094   register struct breakpoint *b;
1095   register int count = 0;
1096
1097   if (address == NULL)          /* Watchpoints are uninteresting */
1098     return;
1099
1100   ALL_BREAKPOINTS (b)
1101     if (b->enable != disabled && b->address == address)
1102       {
1103         count++;
1104         b->duplicate = count > 1;
1105       }
1106 }
1107
1108 /* Low level routine to set a breakpoint.
1109    Takes as args the three things that every breakpoint must have.
1110    Returns the breakpoint object so caller can set other things.
1111    Does not set the breakpoint number!
1112    Does not print anything.
1113
1114    ==> This routine should not be called if there is a chance of later
1115    error(); otherwise it leaves a bogus breakpoint on the chain.  Validate
1116    your arguments BEFORE calling this routine!  */
1117
1118 static struct breakpoint *
1119 set_raw_breakpoint (sal)
1120      struct symtab_and_line sal;
1121 {
1122   register struct breakpoint *b, *b1;
1123
1124   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
1125   bzero (b, sizeof *b);
1126   b->address = sal.pc;
1127   b->symtab = sal.symtab;
1128   b->line_number = sal.line;
1129   b->enable = enabled;
1130   b->next = 0;
1131   b->silent = 0;
1132   b->ignore_count = 0;
1133   b->commands = NULL;
1134   b->frame = NULL;
1135
1136   /* Add this breakpoint to the end of the chain
1137      so that a list of breakpoints will come out in order
1138      of increasing numbers.  */
1139
1140   b1 = breakpoint_chain;
1141   if (b1 == 0)
1142     breakpoint_chain = b;
1143   else
1144     {
1145       while (b1->next)
1146         b1 = b1->next;
1147       b1->next = b;
1148     }
1149
1150   check_duplicates (sal.pc);
1151
1152   return b;
1153 }
1154
1155 /* Set a breakpoint that will evaporate an end of command
1156    at address specified by SAL.
1157    Restrict it to frame FRAME if FRAME is nonzero.  */
1158
1159 void
1160 set_momentary_breakpoint (sal, frame)
1161      struct symtab_and_line sal;
1162      FRAME frame;
1163 {
1164   register struct breakpoint *b;
1165   b = set_raw_breakpoint (sal);
1166   b->number = -3;
1167   b->enable = delete;
1168   b->frame = (frame ? FRAME_FP (frame) : 0);
1169 }
1170
1171 void
1172 clear_momentary_breakpoints ()
1173 {
1174   register struct breakpoint *b;
1175   ALL_BREAKPOINTS (b)
1176     if (b->number == -3)
1177       {
1178         delete_breakpoint (b);
1179         break;
1180       }
1181 }
1182 \f
1183 /* Tell the user we have just set a breakpoint B.  */
1184 static void
1185 mention (b)
1186      struct breakpoint *b;
1187 {
1188   if (b->exp)
1189     {
1190       printf_filtered ("Watchpoint %d: ", b->number);
1191       print_expression (b->exp, stdout);
1192     }
1193   else
1194     {
1195       printf_filtered ("Breakpoint %d at %s", b->number,
1196                        local_hex_string(b->address));
1197       if (b->symtab)
1198         printf_filtered (": file %s, line %d.",
1199                          b->symtab->filename, b->line_number);
1200     }
1201   printf_filtered ("\n");
1202 }
1203
1204 #if 0
1205 /* Nobody calls this currently. */
1206 /* Set a breakpoint from a symtab and line.
1207    If TEMPFLAG is nonzero, it is a temporary breakpoint.
1208    ADDR_STRING is a malloc'd string holding the name of where we are
1209    setting the breakpoint.  This is used later to re-set it after the
1210    program is relinked and symbols are reloaded.
1211    Print the same confirmation messages that the breakpoint command prints.  */
1212
1213 void
1214 set_breakpoint (s, line, tempflag, addr_string)
1215      struct symtab *s;
1216      int line;
1217      int tempflag;
1218      char *addr_string;
1219 {
1220   register struct breakpoint *b;
1221   struct symtab_and_line sal;
1222   
1223   sal.symtab = s;
1224   sal.line = line;
1225   sal.pc = find_line_pc (sal.symtab, sal.line);
1226   if (sal.pc == 0)
1227     error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename);
1228   else
1229     {
1230       describe_other_breakpoints (sal.pc);
1231
1232       b = set_raw_breakpoint (sal);
1233       set_breakpoint_count (breakpoint_count + 1);
1234       b->number = breakpoint_count;
1235       b->cond = 0;
1236       b->addr_string = addr_string;
1237       if (tempflag)
1238         b->enable = temporary;
1239
1240       mention (b);
1241     }
1242 }
1243 #endif
1244 \f
1245 /* Set a breakpoint according to ARG (function, linenum or *address)
1246    and make it temporary if TEMPFLAG is nonzero. */
1247
1248 static void
1249 break_command_1 (arg, tempflag, from_tty)
1250      char *arg;
1251      int tempflag, from_tty;
1252 {
1253   struct symtabs_and_lines sals;
1254   struct symtab_and_line sal;
1255   register struct expression *cond = 0;
1256   register struct breakpoint *b;
1257
1258   /* Pointers in arg to the start, and one past the end, of the condition.  */
1259   char *cond_start = NULL;
1260   char *cond_end;
1261   /* Pointers in arg to the start, and one past the end,
1262      of the address part.  */
1263   char *addr_start = NULL;
1264   char *addr_end;
1265   
1266   int i;
1267   CORE_ADDR pc;
1268
1269   sals.sals = NULL;
1270   sals.nelts = 0;
1271
1272   sal.line = sal.pc = sal.end = 0;
1273   sal.symtab = 0;
1274
1275   /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
1276
1277   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
1278                && (arg[2] == ' ' || arg[2] == '\t')))
1279     {
1280       if (default_breakpoint_valid)
1281         {
1282           sals.sals = (struct symtab_and_line *) 
1283             xmalloc (sizeof (struct symtab_and_line));
1284           sal.pc = default_breakpoint_address;
1285           sal.line = default_breakpoint_line;
1286           sal.symtab = default_breakpoint_symtab;
1287           sals.sals[0] = sal;
1288           sals.nelts = 1;
1289         }
1290       else
1291         error ("No default breakpoint address now.");
1292     }
1293   else
1294     {
1295       addr_start = arg;
1296
1297       /* Force almost all breakpoints to be in terms of the
1298          current_source_symtab (which is decode_line_1's default).  This
1299          should produce the results we want almost all of the time while
1300          leaving default_breakpoint_* alone.  */
1301       if (default_breakpoint_valid
1302           && (!current_source_symtab
1303               || (arg && (*arg == '+' || *arg == '-'))))
1304         sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1305                               default_breakpoint_line);
1306       else
1307         sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1308
1309       addr_end = arg;
1310     }
1311   
1312   if (! sals.nelts) 
1313     return;
1314
1315   for (i = 0; i < sals.nelts; i++)
1316     {
1317       sal = sals.sals[i];
1318       if (sal.pc == 0 && sal.symtab != 0)
1319         {
1320           pc = find_line_pc (sal.symtab, sal.line);
1321           if (pc == 0)
1322             error ("No line %d in file \"%s\".",
1323                    sal.line, sal.symtab->filename);
1324         }
1325       else 
1326         pc = sal.pc;
1327       
1328       while (arg && *arg)
1329         {
1330           if (arg[0] == 'i' && arg[1] == 'f'
1331               && (arg[2] == ' ' || arg[2] == '\t'))
1332             {
1333               arg += 2;
1334               cond_start = arg;
1335               cond = parse_exp_1 (&arg, block_for_pc (pc), 0);
1336               cond_end = arg;
1337             }
1338           else
1339             error ("Junk at end of arguments.");
1340         }
1341       sals.sals[i].pc = pc;
1342     }
1343
1344   for (i = 0; i < sals.nelts; i++)
1345     {
1346       sal = sals.sals[i];
1347
1348       if (from_tty)
1349         describe_other_breakpoints (sal.pc);
1350
1351       b = set_raw_breakpoint (sal);
1352       set_breakpoint_count (breakpoint_count + 1);
1353       b->number = breakpoint_count;
1354       b->cond = cond;
1355       
1356       if (addr_start)
1357         b->addr_string = savestring (addr_start, addr_end - addr_start);
1358       if (cond_start)
1359         b->cond_string = savestring (cond_start, cond_end - cond_start);
1360                                      
1361       if (tempflag)
1362         b->enable = temporary;
1363
1364       mention (b);
1365     }
1366
1367   if (sals.nelts > 1)
1368     {
1369       printf ("Multiple breakpoints were set.\n");
1370       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1371     }
1372   free (sals.sals);
1373 }
1374
1375 void
1376 break_command (arg, from_tty)
1377      char *arg;
1378      int from_tty;
1379 {
1380   break_command_1 (arg, 0, from_tty);
1381 }
1382
1383 static void
1384 tbreak_command (arg, from_tty)
1385      char *arg;
1386      int from_tty;
1387 {
1388   break_command_1 (arg, 1, from_tty);
1389 }
1390
1391 /* ARGSUSED */
1392 static void
1393 watch_command (arg, from_tty)
1394      char *arg;
1395      int from_tty;
1396 {
1397   struct breakpoint *b;
1398   struct symtab_and_line sal;
1399   struct expression *exp;
1400   struct block *exp_valid_block;
1401   struct value *val;
1402
1403   sal.pc = NULL;
1404   sal.symtab = NULL;
1405   sal.line = 0;
1406   
1407   /* Parse arguments.  */
1408   innermost_block = NULL;
1409   exp = parse_expression (arg);
1410   exp_valid_block = innermost_block;
1411   val = evaluate_expression (exp);
1412   release_value (val);
1413
1414   /* Now set up the breakpoint.  */
1415   b = set_raw_breakpoint (sal);
1416   set_breakpoint_count (breakpoint_count + 1);
1417   b->number = breakpoint_count;
1418   b->exp = exp;
1419   b->exp_valid_block = exp_valid_block;
1420   b->val = val;
1421   b->cond = 0;
1422   b->cond_string = NULL;
1423   mention (b);
1424 }
1425 \f
1426 /*
1427  * Helper routine for the until_command routine in infcmd.c.  Here
1428  * because it uses the mechanisms of breakpoints.
1429  */
1430 /* ARGSUSED */
1431 void
1432 until_break_command (arg, from_tty)
1433      char *arg;
1434      int from_tty;
1435 {
1436   struct symtabs_and_lines sals;
1437   struct symtab_and_line sal;
1438   FRAME prev_frame = get_prev_frame (selected_frame);
1439
1440   clear_proceed_status ();
1441
1442   /* Set a breakpoint where the user wants it and at return from
1443      this function */
1444   
1445   if (default_breakpoint_valid)
1446     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
1447                           default_breakpoint_line);
1448   else
1449     sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
1450   
1451   if (sals.nelts != 1)
1452     error ("Couldn't get information on specified line.");
1453   
1454   sal = sals.sals[0];
1455   free (sals.sals);             /* malloc'd, so freed */
1456   
1457   if (*arg)
1458     error ("Junk at end of arguments.");
1459   
1460   if (sal.pc == 0 && sal.symtab != 0)
1461     sal.pc = find_line_pc (sal.symtab, sal.line);
1462   
1463   if (sal.pc == 0)
1464     error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename);
1465   
1466   set_momentary_breakpoint (sal, selected_frame);
1467   
1468   /* Keep within the current frame */
1469   
1470   if (prev_frame)
1471     {
1472       struct frame_info *fi;
1473       
1474       fi = get_frame_info (prev_frame);
1475       sal = find_pc_line (fi->pc, 0);
1476       sal.pc = fi->pc;
1477       set_momentary_breakpoint (sal, prev_frame);
1478     }
1479   
1480   proceed (-1, -1, 0);
1481 }
1482 \f
1483 #if 0
1484 /* These aren't used; I don't konw what they were for.  */
1485 /* Set a breakpoint at the catch clause for NAME.  */
1486 static int
1487 catch_breakpoint (name)
1488      char *name;
1489 {
1490 }
1491
1492 static int
1493 disable_catch_breakpoint ()
1494 {
1495 }
1496
1497 static int
1498 delete_catch_breakpoint ()
1499 {
1500 }
1501
1502 static int
1503 enable_catch_breakpoint ()
1504 {
1505 }
1506 #endif /* 0 */
1507
1508 struct sal_chain
1509 {
1510   struct sal_chain *next;
1511   struct symtab_and_line sal;
1512 };
1513
1514 #if 0
1515 /* This isn't used; I don't know what it was for.  */
1516 /* For each catch clause identified in ARGS, run FUNCTION
1517    with that clause as an argument.  */
1518 static struct symtabs_and_lines
1519 map_catch_names (args, function)
1520      char *args;
1521      int (*function)();
1522 {
1523   register char *p = args;
1524   register char *p1;
1525   struct symtabs_and_lines sals;
1526 #if 0
1527   struct sal_chain *sal_chain = 0;
1528 #endif
1529
1530   if (p == 0)
1531     error_no_arg ("one or more catch names");
1532
1533   sals.nelts = 0;
1534   sals.sals = NULL;
1535
1536   while (*p)
1537     {
1538       p1 = p;
1539       /* Don't swallow conditional part.  */
1540       if (p1[0] == 'i' && p1[1] == 'f'
1541           && (p1[2] == ' ' || p1[2] == '\t'))
1542         break;
1543
1544       if (isalpha (*p1))
1545         {
1546           p1++;
1547           while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
1548             p1++;
1549         }
1550
1551       if (*p1 && *p1 != ' ' && *p1 != '\t')
1552         error ("Arguments must be catch names.");
1553
1554       *p1 = 0;
1555 #if 0
1556       if (function (p))
1557         {
1558           struct sal_chain *next
1559             = (struct sal_chain *)alloca (sizeof (struct sal_chain));
1560           next->next = sal_chain;
1561           next->sal = get_catch_sal (p);
1562           sal_chain = next;
1563           goto win;
1564         }
1565 #endif
1566       printf ("No catch clause for exception %s.\n", p);
1567 #if 0
1568     win:
1569 #endif
1570       p = p1;
1571       while (*p == ' ' || *p == '\t') p++;
1572     }
1573 }
1574 #endif /* 0 */
1575
1576 /* This shares a lot of code with `print_frame_label_vars' from stack.c.  */
1577
1578 static struct symtabs_and_lines
1579 get_catch_sals (this_level_only)
1580      int this_level_only;
1581 {
1582   extern struct blockvector *blockvector_for_pc ();
1583   register struct blockvector *bl;
1584   register struct block *block;
1585   int index, have_default = 0;
1586   struct frame_info *fi;
1587   CORE_ADDR pc;
1588   struct symtabs_and_lines sals;
1589   struct sal_chain *sal_chain = 0;
1590   char *blocks_searched;
1591
1592   /* Not sure whether an error message is always the correct response,
1593      but it's better than a core dump.  */
1594   if (selected_frame == NULL)
1595     error ("No selected frame.");
1596   block = get_frame_block (selected_frame);
1597   fi = get_frame_info (selected_frame);
1598   pc = fi->pc;
1599
1600   sals.nelts = 0;
1601   sals.sals = NULL;
1602
1603   if (block == 0)
1604     error ("No symbol table info available.\n");
1605
1606   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1607   blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1608   bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1609
1610   while (block != 0)
1611     {
1612       CORE_ADDR end = BLOCK_END (block) - 4;
1613       int last_index;
1614
1615       if (bl != blockvector_for_pc (end, &index))
1616         error ("blockvector blotch");
1617       if (BLOCKVECTOR_BLOCK (bl, index) != block)
1618         error ("blockvector botch");
1619       last_index = BLOCKVECTOR_NBLOCKS (bl);
1620       index += 1;
1621
1622       /* Don't print out blocks that have gone by.  */
1623       while (index < last_index
1624              && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1625         index++;
1626
1627       while (index < last_index
1628              && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1629         {
1630           if (blocks_searched[index] == 0)
1631             {
1632               struct block *b = BLOCKVECTOR_BLOCK (bl, index);
1633               int nsyms;
1634               register int i;
1635               register struct symbol *sym;
1636
1637               nsyms = BLOCK_NSYMS (b);
1638
1639               for (i = 0; i < nsyms; i++)
1640                 {
1641                   sym = BLOCK_SYM (b, i);
1642                   if (! strcmp (SYMBOL_NAME (sym), "default"))
1643                     {
1644                       if (have_default)
1645                         continue;
1646                       have_default = 1;
1647                     }
1648                   if (SYMBOL_CLASS (sym) == LOC_LABEL)
1649                     {
1650                       struct sal_chain *next = (struct sal_chain *)
1651                         alloca (sizeof (struct sal_chain));
1652                       next->next = sal_chain;
1653                       next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1654                       sal_chain = next;
1655                     }
1656                 }
1657               blocks_searched[index] = 1;
1658             }
1659           index++;
1660         }
1661       if (have_default)
1662         break;
1663       if (sal_chain && this_level_only)
1664         break;
1665
1666       /* After handling the function's top-level block, stop.
1667          Don't continue to its superblock, the block of
1668          per-file symbols.  */
1669       if (BLOCK_FUNCTION (block))
1670         break;
1671       block = BLOCK_SUPERBLOCK (block);
1672     }
1673
1674   if (sal_chain)
1675     {
1676       struct sal_chain *tmp_chain;
1677
1678       /* Count the number of entries.  */
1679       for (index = 0, tmp_chain = sal_chain; tmp_chain;
1680            tmp_chain = tmp_chain->next)
1681         index++;
1682
1683       sals.nelts = index;
1684       sals.sals = (struct symtab_and_line *)
1685         xmalloc (index * sizeof (struct symtab_and_line));
1686       for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
1687         sals.sals[index] = sal_chain->sal;
1688     }
1689
1690   return sals;
1691 }
1692
1693 /* Commands to deal with catching exceptions.  */
1694
1695 void
1696 catch_command_1 (arg, tempflag, from_tty)
1697      char *arg;
1698      int tempflag;
1699      int from_tty;
1700 {
1701   /* First, translate ARG into something we can deal with in terms
1702      of breakpoints.  */
1703
1704   struct symtabs_and_lines sals;
1705   struct symtab_and_line sal;
1706   register struct expression *cond = 0;
1707   register struct breakpoint *b;
1708   char *save_arg;
1709   int i;
1710   CORE_ADDR pc;
1711
1712   sal.line = sal.pc = sal.end = 0;
1713   sal.symtab = 0;
1714
1715   /* If no arg given, or if first arg is 'if ', all active catch clauses
1716      are breakpointed. */
1717
1718   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
1719                && (arg[2] == ' ' || arg[2] == '\t')))
1720     {
1721       /* Grab all active catch clauses.  */
1722       sals = get_catch_sals (0);
1723     }
1724   else
1725     {
1726       /* Grab selected catch clauses.  */
1727       error ("catch NAME not implemeneted");
1728 #if 0
1729       /* This isn't used; I don't know what it was for.  */
1730       sals = map_catch_names (arg, catch_breakpoint);
1731 #endif
1732     }
1733
1734   if (! sals.nelts) 
1735     return;
1736
1737   save_arg = arg;
1738   for (i = 0; i < sals.nelts; i++)
1739     {
1740       sal = sals.sals[i];
1741       if (sal.pc == 0 && sal.symtab != 0)
1742         {
1743           pc = find_line_pc (sal.symtab, sal.line);
1744           if (pc == 0)
1745             error ("No line %d in file \"%s\".",
1746                    sal.line, sal.symtab->filename);
1747         }
1748       else 
1749         pc = sal.pc;
1750       
1751       while (arg && *arg)
1752         {
1753           if (arg[0] == 'i' && arg[1] == 'f'
1754               && (arg[2] == ' ' || arg[2] == '\t'))
1755             cond = (struct expression *) parse_exp_1 ((arg += 2, &arg),
1756                                                     block_for_pc (pc), 0);
1757           else
1758             error ("Junk at end of arguments.");
1759         }
1760       arg = save_arg;
1761       sals.sals[i].pc = pc;
1762     }
1763
1764   for (i = 0; i < sals.nelts; i++)
1765     {
1766       sal = sals.sals[i];
1767
1768       if (from_tty)
1769         describe_other_breakpoints (sal.pc);
1770
1771       b = set_raw_breakpoint (sal);
1772       b->number = ++breakpoint_count;
1773       b->cond = cond;
1774       if (tempflag)
1775         b->enable = temporary;
1776
1777       printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
1778       if (b->symtab)
1779         printf (": file %s, line %d.", b->symtab->filename, b->line_number);
1780       printf ("\n");
1781     }
1782
1783   if (sals.nelts > 1)
1784     {
1785       printf ("Multiple breakpoints were set.\n");
1786       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
1787     }
1788   free (sals.sals);
1789 }
1790
1791 #if 0
1792 /* These aren't used; I don't know what they were for.  */
1793 /* Disable breakpoints on all catch clauses described in ARGS.  */
1794 static void
1795 disable_catch (args)
1796      char *args;
1797 {
1798   /* Map the disable command to catch clauses described in ARGS.  */
1799 }
1800
1801 /* Enable breakpoints on all catch clauses described in ARGS.  */
1802 static void
1803 enable_catch (args)
1804      char *args;
1805 {
1806   /* Map the disable command to catch clauses described in ARGS.  */
1807 }
1808
1809 /* Delete breakpoints on all catch clauses in the active scope.  */
1810 static void
1811 delete_catch (args)
1812      char *args;
1813 {
1814   /* Map the delete command to catch clauses described in ARGS.  */
1815 }
1816 #endif /* 0 */
1817
1818 static void
1819 catch_command (arg, from_tty)
1820      char *arg;
1821      int from_tty;
1822 {
1823   catch_command_1 (arg, 0, from_tty);
1824 }
1825 \f
1826 static void
1827 clear_command (arg, from_tty)
1828      char *arg;
1829      int from_tty;
1830 {
1831   register struct breakpoint *b, *b1;
1832   struct symtabs_and_lines sals;
1833   struct symtab_and_line sal;
1834   register struct breakpoint *found;
1835   int i;
1836
1837   if (arg)
1838     {
1839       sals = decode_line_spec (arg, 1);
1840     }
1841   else
1842     {
1843       sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
1844       sal.line = default_breakpoint_line;
1845       sal.symtab = default_breakpoint_symtab;
1846       sal.pc = 0;
1847       if (sal.symtab == 0)
1848         error ("No source file specified.");
1849
1850       sals.sals[0] = sal;
1851       sals.nelts = 1;
1852     }
1853
1854   for (i = 0; i < sals.nelts; i++)
1855     {
1856       /* If exact pc given, clear bpts at that pc.
1857          But if sal.pc is zero, clear all bpts on specified line.  */
1858       sal = sals.sals[i];
1859       found = (struct breakpoint *) 0;
1860       while (breakpoint_chain
1861              && (sal.pc ? breakpoint_chain->address == sal.pc
1862                  : (breakpoint_chain->symtab == sal.symtab
1863                     && breakpoint_chain->line_number == sal.line)))
1864         {
1865           b1 = breakpoint_chain;
1866           breakpoint_chain = b1->next;
1867           b1->next = found;
1868           found = b1;
1869         }
1870
1871       ALL_BREAKPOINTS (b)
1872         while (b->next
1873                && b->next->address != NULL
1874                && (sal.pc ? b->next->address == sal.pc
1875                    : (b->next->symtab == sal.symtab
1876                       && b->next->line_number == sal.line)))
1877           {
1878             b1 = b->next;
1879             b->next = b1->next;
1880             b1->next = found;
1881             found = b1;
1882           }
1883
1884       if (found == 0)
1885         {
1886           if (arg)
1887             error ("No breakpoint at %s.", arg);
1888           else
1889             error ("No breakpoint at this line.");
1890         }
1891
1892       if (found->next) from_tty = 1; /* Always report if deleted more than one */
1893       if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
1894       while (found)
1895         {
1896           if (from_tty) printf ("%d ", found->number);
1897           b1 = found->next;
1898           delete_breakpoint (found);
1899           found = b1;
1900         }
1901       if (from_tty) putchar ('\n');
1902     }
1903   free (sals.sals);
1904 }
1905 \f
1906 /* Delete breakpoint in BS if they are `delete' breakpoints.
1907    This is called after any breakpoint is hit, or after errors.  */
1908
1909 void
1910 breakpoint_auto_delete (bs)
1911      bpstat bs;
1912 {
1913   for (; bs; bs = bs->next)
1914     if (bs->breakpoint_at && bs->breakpoint_at->enable == delete)
1915       delete_breakpoint (bs->breakpoint_at);
1916 }
1917
1918 /* Delete a breakpoint and clean up all traces of it in the data structures. */
1919
1920 static void
1921 delete_breakpoint (bpt)
1922      struct breakpoint *bpt;
1923 {
1924   register struct breakpoint *b;
1925   register bpstat bs;
1926
1927   if (bpt->inserted)
1928       target_remove_breakpoint(bpt->address, bpt->shadow_contents);
1929
1930   if (breakpoint_chain == bpt)
1931     breakpoint_chain = bpt->next;
1932
1933   ALL_BREAKPOINTS (b)
1934     if (b->next == bpt)
1935       {
1936         b->next = bpt->next;
1937         break;
1938       }
1939
1940   check_duplicates (bpt->address);
1941
1942   free_command_lines (&bpt->commands);
1943   if (bpt->cond)
1944     free (bpt->cond);
1945   if (bpt->cond_string != NULL)
1946     free (bpt->cond_string);
1947   if (bpt->addr_string != NULL)
1948     free (bpt->addr_string);
1949
1950   if (xgdb_verbose && bpt->number >=0)
1951     printf ("breakpoint #%d deleted\n", bpt->number);
1952
1953   /* Be sure no bpstat's are pointing at it after it's been freed.  */
1954   /* FIXME, how can we find all bpstat's?  We just check stop_bpstat for now. */
1955   for (bs = stop_bpstat; bs; bs = bs->next)
1956     if (bs->breakpoint_at == bpt)
1957       bs->breakpoint_at = NULL;
1958   free (bpt);
1959 }
1960
1961 static void map_breakpoint_numbers ();
1962
1963 static void
1964 delete_command (arg, from_tty)
1965      char *arg;
1966      int from_tty;
1967 {
1968
1969   if (arg == 0)
1970     {
1971       /* Ask user only if there are some breakpoints to delete.  */
1972       if (!from_tty
1973           || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
1974         {
1975           /* No arg; clear all breakpoints.  */
1976           while (breakpoint_chain)
1977             delete_breakpoint (breakpoint_chain);
1978         }
1979     }
1980   else
1981     map_breakpoint_numbers (arg, delete_breakpoint);
1982 }
1983
1984 /* Reset a breakpoint given it's struct breakpoint * BINT.
1985    The value we return ends up being the return value from catch_errors.
1986    Unused in this case.  */
1987
1988 static int
1989 breakpoint_re_set_one (bint)
1990      char *bint;
1991 {
1992   struct breakpoint *b = (struct breakpoint *)bint;  /* get past catch_errs */
1993   int i;
1994   struct symtabs_and_lines sals;
1995   struct symtab_and_line sal;
1996   char *s;
1997
1998   if (b->address != NULL && b->addr_string != NULL)
1999     {
2000       s = b->addr_string;
2001       sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
2002       for (i = 0; i < sals.nelts; i++)
2003         {
2004           sal = sals.sals[i];
2005           
2006           b->symtab = sal.symtab;
2007           b->line_number = sal.line;
2008           if (sal.pc == 0 && sal.symtab != 0)
2009             {
2010               sal.pc = find_line_pc (sal.symtab, sal.line);
2011               if (sal.pc == 0)
2012                 error ("No line %d in file \"%s\".",
2013                        sal.line, sal.symtab->filename);
2014             }
2015           b->address = sal.pc;
2016
2017           if (b->cond_string != NULL)
2018             {
2019               s = b->cond_string;
2020               b->cond = parse_exp_1 (&s, block_for_pc (sal.pc), 0);
2021             }
2022           
2023           check_duplicates (b->address);
2024
2025           mention (b);
2026         }
2027       free (sals.sals);
2028     }
2029   else
2030     {
2031       /* Anything without a string can't be re-set. */
2032       delete_breakpoint (b);
2033     }
2034   return 0;
2035 }
2036
2037 /* Re-set all breakpoints after symbols have been re-loaded.  */
2038 void
2039 breakpoint_re_set ()
2040 {
2041   struct breakpoint *b;
2042   
2043   ALL_BREAKPOINTS (b)
2044     {
2045       b->symtab = 0;            /* Be sure we don't point to old dead symtab */
2046       (void) catch_errors (breakpoint_re_set_one, (char *) b, 
2047                            "Error in re-setting breakpoint:\n");
2048     }
2049
2050   /* Blank line to finish off all those mention() messages we just printed.  */
2051   printf_filtered ("\n");
2052 }
2053 \f
2054 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
2055    If from_tty is nonzero, it prints a message to that effect,
2056    which ends with a period (no newline).  */
2057
2058 void
2059 set_ignore_count (bptnum, count, from_tty)
2060      int bptnum, count, from_tty;
2061 {
2062   register struct breakpoint *b;
2063
2064   if (count < 0)
2065     count = 0;
2066
2067   ALL_BREAKPOINTS (b)
2068     if (b->number == bptnum)
2069       {
2070         b->ignore_count = count;
2071         if (!from_tty)
2072           return;
2073         else if (count == 0)
2074           printf ("Will stop next time breakpoint %d is reached.", bptnum);
2075         else if (count == 1)
2076           printf ("Will ignore next crossing of breakpoint %d.", bptnum);
2077         else
2078           printf ("Will ignore next %d crossings of breakpoint %d.",
2079                   count, bptnum);
2080         return;
2081       }
2082
2083   error ("No breakpoint number %d.", bptnum);
2084 }
2085
2086 /* Clear the ignore counts of all breakpoints.  */
2087 void
2088 breakpoint_clear_ignore_counts ()
2089 {
2090   struct breakpoint *b;
2091
2092   ALL_BREAKPOINTS (b)
2093     b->ignore_count = 0;
2094 }
2095
2096 /* Command to set ignore-count of breakpoint N to COUNT.  */
2097
2098 static void
2099 ignore_command (args, from_tty)
2100      char *args;
2101      int from_tty;
2102 {
2103   char *p = args;
2104   register int num;
2105
2106   if (p == 0)
2107     error_no_arg ("a breakpoint number");
2108   
2109   num = get_number (&p);
2110
2111   if (*p == 0)
2112     error ("Second argument (specified ignore-count) is missing.");
2113
2114   set_ignore_count (num,
2115                     longest_to_int (value_as_long (parse_and_eval (p))),
2116                     from_tty);
2117   printf ("\n");
2118 }
2119 \f
2120 /* Call FUNCTION on each of the breakpoints
2121    whose numbers are given in ARGS.  */
2122
2123 static void
2124 map_breakpoint_numbers (args, function)
2125      char *args;
2126      void (*function) ();
2127 {
2128   register char *p = args;
2129   char *p1;
2130   register int num;
2131   register struct breakpoint *b;
2132
2133   if (p == 0)
2134     error_no_arg ("one or more breakpoint numbers");
2135
2136   while (*p)
2137     {
2138       p1 = p;
2139       
2140       num = get_number (&p1);
2141
2142       ALL_BREAKPOINTS (b)
2143         if (b->number == num)
2144           {
2145             function (b);
2146             goto win;
2147           }
2148       printf ("No breakpoint number %d.\n", num);
2149     win:
2150       p = p1;
2151     }
2152 }
2153
2154 static void
2155 enable_breakpoint (bpt)
2156      struct breakpoint *bpt;
2157 {
2158   bpt->enable = enabled;
2159
2160   if (xgdb_verbose && bpt->number >= 0)
2161     printf ("breakpoint #%d enabled\n", bpt->number);
2162
2163   check_duplicates (bpt->address);
2164   if (bpt->val != NULL)
2165     {
2166       if (bpt->exp_valid_block != NULL
2167        && !contained_in (get_selected_block (), bpt->exp_valid_block))
2168         {
2169           printf_filtered ("\
2170 Cannot enable watchpoint %d because the block in which its expression\n\
2171 is valid is not currently in scope.\n", bpt->number);
2172           return;
2173         }
2174
2175       value_free (bpt->val);
2176
2177       bpt->val = evaluate_expression (bpt->exp);
2178       release_value (bpt->val);
2179     }
2180 }
2181
2182 /* ARGSUSED */
2183 static void
2184 enable_command (args, from_tty)
2185      char *args;
2186      int from_tty;
2187 {
2188   struct breakpoint *bpt;
2189   if (args == 0)
2190     ALL_BREAKPOINTS (bpt)
2191       enable_breakpoint (bpt);
2192   else
2193     map_breakpoint_numbers (args, enable_breakpoint);
2194 }
2195
2196 static void
2197 disable_breakpoint (bpt)
2198      struct breakpoint *bpt;
2199 {
2200   bpt->enable = disabled;
2201
2202   if (xgdb_verbose && bpt->number >= 0)
2203     printf ("breakpoint #%d disabled\n", bpt->number);
2204
2205   check_duplicates (bpt->address);
2206 }
2207
2208 /* ARGSUSED */
2209 static void
2210 disable_command (args, from_tty)
2211      char *args;
2212      int from_tty;
2213 {
2214   register struct breakpoint *bpt;
2215   if (args == 0)
2216     ALL_BREAKPOINTS (bpt)
2217       disable_breakpoint (bpt);
2218   else
2219     map_breakpoint_numbers (args, disable_breakpoint);
2220 }
2221
2222 static void
2223 enable_once_breakpoint (bpt)
2224      struct breakpoint *bpt;
2225 {
2226   bpt->enable = temporary;
2227
2228   check_duplicates (bpt->address);
2229 }
2230
2231 /* ARGSUSED */
2232 static void
2233 enable_once_command (args, from_tty)
2234      char *args;
2235      int from_tty;
2236 {
2237   map_breakpoint_numbers (args, enable_once_breakpoint);
2238 }
2239
2240 static void
2241 enable_delete_breakpoint (bpt)
2242      struct breakpoint *bpt;
2243 {
2244   bpt->enable = delete;
2245
2246   check_duplicates (bpt->address);
2247 }
2248
2249 /* ARGSUSED */
2250 static void
2251 enable_delete_command (args, from_tty)
2252      char *args;
2253      int from_tty;
2254 {
2255   map_breakpoint_numbers (args, enable_delete_breakpoint);
2256 }
2257 \f
2258 /*
2259  * Use default_breakpoint_'s, or nothing if they aren't valid.
2260  */
2261 struct symtabs_and_lines
2262 decode_line_spec_1 (string, funfirstline)
2263      char *string;
2264      int funfirstline;
2265 {
2266   struct symtabs_and_lines sals;
2267   if (string == 0)
2268     error ("Empty line specification.");
2269   if (default_breakpoint_valid)
2270     sals = decode_line_1 (&string, funfirstline,
2271                           default_breakpoint_symtab, default_breakpoint_line);
2272   else
2273     sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
2274   if (*string)
2275     error ("Junk at end of line specification: %s", string);
2276   return sals;
2277 }
2278 \f
2279
2280 /* Chain containing all defined enable commands.  */
2281
2282 extern struct cmd_list_element 
2283   *enablelist, *disablelist,
2284   *deletelist, *enablebreaklist;
2285
2286 extern struct cmd_list_element *cmdlist;
2287
2288 void
2289 _initialize_breakpoint ()
2290 {
2291   breakpoint_chain = 0;
2292   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
2293      before a breakpoint is set.  */
2294   breakpoint_count = 0;
2295
2296   add_com ("ignore", class_breakpoint, ignore_command,
2297            "Set ignore-count of breakpoint number N to COUNT.");
2298
2299   add_com ("commands", class_breakpoint, commands_command,
2300            "Set commands to be executed when a breakpoint is hit.\n\
2301 Give breakpoint number as argument after \"commands\".\n\
2302 With no argument, the targeted breakpoint is the last one set.\n\
2303 The commands themselves follow starting on the next line.\n\
2304 Type a line containing \"end\" to indicate the end of them.\n\
2305 Give \"silent\" as the first line to make the breakpoint silent;\n\
2306 then no output is printed when it is hit, except what the commands print.");
2307
2308   add_com ("condition", class_breakpoint, condition_command,
2309            "Specify breakpoint number N to break only if COND is true.\n\
2310 N is an integer; COND is an expression to be evaluated whenever\n\
2311 breakpoint N is reached.  ");
2312
2313   add_com ("tbreak", class_breakpoint, tbreak_command,
2314            "Set a temporary breakpoint.  Args like \"break\" command.\n\
2315 Like \"break\" except the breakpoint is only enabled temporarily,\n\
2316 so it will be disabled when hit.  Equivalent to \"break\" followed\n\
2317 by using \"enable once\" on the breakpoint number.");
2318
2319   add_prefix_cmd ("enable", class_breakpoint, enable_command,
2320                   "Enable some breakpoints.\n\
2321 Give breakpoint numbers (separated by spaces) as arguments.\n\
2322 With no subcommand, breakpoints are enabled until you command otherwise.\n\
2323 This is used to cancel the effect of the \"disable\" command.\n\
2324 With a subcommand you can enable temporarily.",
2325                   &enablelist, "enable ", 1, &cmdlist);
2326
2327   add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
2328                   "Enable some breakpoints.\n\
2329 Give breakpoint numbers (separated by spaces) as arguments.\n\
2330 This is used to cancel the effect of the \"disable\" command.\n\
2331 May be abbreviated to simply \"enable\".\n",
2332                   &enablebreaklist, "enable breakpoints ", 1, &enablelist);
2333
2334   add_cmd ("once", no_class, enable_once_command,
2335            "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
2336 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2337 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2338            &enablebreaklist);
2339
2340   add_cmd ("delete", no_class, enable_delete_command,
2341            "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
2342 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2343            &enablebreaklist);
2344
2345   add_cmd ("delete", no_class, enable_delete_command,
2346            "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
2347 If a breakpoint is hit while enabled in this fashion, it is deleted.",
2348            &enablelist);
2349
2350   add_cmd ("once", no_class, enable_once_command,
2351            "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
2352 If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
2353 See the \"tbreak\" command which sets a breakpoint and enables it once.",
2354            &enablelist);
2355
2356   add_prefix_cmd ("disable", class_breakpoint, disable_command,
2357            "Disable some breakpoints.\n\
2358 Arguments are breakpoint numbers with spaces in between.\n\
2359 To disable all breakpoints, give no argument.\n\
2360 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
2361                   &disablelist, "disable ", 1, &cmdlist);
2362   add_com_alias ("dis", "disable", class_breakpoint, 1);
2363   add_com_alias ("disa", "disable", class_breakpoint, 1);
2364
2365   add_cmd ("breakpoints", class_alias, disable_command,
2366            "Disable some breakpoints.\n\
2367 Arguments are breakpoint numbers with spaces in between.\n\
2368 To disable all breakpoints, give no argument.\n\
2369 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
2370 This command may be abbreviated \"disable\".",
2371            &disablelist);
2372
2373   add_prefix_cmd ("delete", class_breakpoint, delete_command,
2374            "Delete some breakpoints or auto-display expressions.\n\
2375 Arguments are breakpoint numbers with spaces in between.\n\
2376 To delete all breakpoints, give no argument.\n\
2377 \n\
2378 Also a prefix command for deletion of other GDB objects.\n\
2379 The \"unset\" command is also an alias for \"delete\".",
2380                   &deletelist, "delete ", 1, &cmdlist);
2381   add_com_alias ("d", "delete", class_breakpoint, 1);
2382
2383   add_cmd ("breakpoints", class_alias, delete_command,
2384            "Delete some breakpoints or auto-display expressions.\n\
2385 Arguments are breakpoint numbers with spaces in between.\n\
2386 To delete all breakpoints, give no argument.\n\
2387 This command may be abbreviated \"delete\".",
2388            &deletelist);
2389
2390   add_com ("clear", class_breakpoint, clear_command,
2391            "Clear breakpoint at specified line or function.\n\
2392 Argument may be line number, function name, or \"*\" and an address.\n\
2393 If line number is specified, all breakpoints in that line are cleared.\n\
2394 If function is specified, breakpoints at beginning of function are cleared.\n\
2395 If an address is specified, breakpoints at that address are cleared.\n\n\
2396 With no argument, clears all breakpoints in the line that the selected frame\n\
2397 is executing in.\n\
2398 \n\
2399 See also the \"delete\" command which clears breakpoints by number.");
2400
2401   add_com ("break", class_breakpoint, break_command,
2402            "Set breakpoint at specified line or function.\n\
2403 Argument may be line number, function name, or \"*\" and an address.\n\
2404 If line number is specified, break at start of code for that line.\n\
2405 If function is specified, break at start of code for that function.\n\
2406 If an address is specified, break at that exact address.\n\
2407 With no arg, uses current execution address of selected stack frame.\n\
2408 This is useful for breaking on return to a stack frame.\n\
2409 \n\
2410 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
2411 \n\
2412 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2413   add_com_alias ("b", "break", class_run, 1);
2414   add_com_alias ("br", "break", class_run, 1);
2415   add_com_alias ("bre", "break", class_run, 1);
2416   add_com_alias ("brea", "break", class_run, 1);
2417
2418   add_info ("breakpoints", breakpoints_info,
2419             "Status of all breakpoints, or breakpoint number NUMBER.\n\
2420 Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
2421 \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
2422 Then come the address and the file/line number.\n\n\
2423 Convenience variable \"$_\" and default examine address for \"x\"\n\
2424 are set to the address of the last breakpoint listed.\n\n\
2425 Convenience variable \"$bpnum\" contains the number of the last\n\
2426 breakpoint set.");
2427
2428   add_com ("catch", class_breakpoint, catch_command,
2429          "Set breakpoints to catch exceptions that are raised.\n\
2430 Argument may be a single exception to catch, multiple exceptions\n\
2431 to catch, or the default exception \"default\".  If no arguments\n\
2432 are given, breakpoints are set at all exception handlers catch clauses\n\
2433 within the current scope.\n\
2434 \n\
2435 A condition specified for the catch applies to all breakpoints set\n\
2436 with this command\n\
2437 \n\
2438 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
2439
2440   add_com ("watch", class_breakpoint, watch_command,
2441            "Set a watchpoint for an expression.\n\
2442 A watchpoint stops execution of your program whenever the value of\n\
2443 an expression changes.");
2444
2445   add_info ("watchpoints", watchpoints_info,
2446             "Status of all watchpoints, or watchpoint number NUMBER.\n\
2447 Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");
2448 }
This page took 0.167028 seconds and 4 git commands to generate.