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