import gdb-1999-12-13 snapshot
[platform/upstream/binutils.git] / gdb / breakpoint.c
1 /* Everything about breakpoints, for GDB.
2    Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
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,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23 #include <ctype.h>
24 #include "symtab.h"
25 #include "frame.h"
26 #include "breakpoint.h"
27 #include "gdbtypes.h"
28 #include "expression.h"
29 #include "gdbcore.h"
30 #include "gdbcmd.h"
31 #include "value.h"
32 #include "command.h"
33 #include "inferior.h"
34 #include "gdbthread.h"
35 #include "target.h"
36 #include "language.h"
37 #include "gdb_string.h"
38 #include "demangle.h"
39 #include "annotate.h"
40 #include "symfile.h"
41 #include "objfiles.h"
42
43 #include "gdb-events.h"
44
45 /* Prototypes for local functions. */
46
47 static void until_break_command_continuation (struct continuation_arg *arg);
48
49 static void
50 catch_command_1 PARAMS ((char *, int, int));
51
52 static void
53 enable_delete_command PARAMS ((char *, int));
54
55 static void
56 enable_delete_breakpoint PARAMS ((struct breakpoint *));
57
58 static void
59 enable_once_command PARAMS ((char *, int));
60
61 static void
62 enable_once_breakpoint PARAMS ((struct breakpoint *));
63
64 static void
65 disable_command PARAMS ((char *, int));
66
67 static void
68 enable_command PARAMS ((char *, int));
69
70 static void
71 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
72
73 static void
74 ignore_command PARAMS ((char *, int));
75
76 static int breakpoint_re_set_one PARAMS ((PTR));
77
78 static void
79 clear_command PARAMS ((char *, int));
80
81 static void
82 catch_command PARAMS ((char *, int));
83
84 static void
85 handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
86
87 static struct symtabs_and_lines
88 get_catch_sals PARAMS ((int));
89
90 static void
91 watch_command PARAMS ((char *, int));
92
93 static int
94 can_use_hardware_watchpoint PARAMS ((struct value *));
95
96 static void break_at_finish_command PARAMS ((char *, int));
97 static void break_at_finish_at_depth_command PARAMS ((char *, int));
98
99 void
100 tbreak_command PARAMS ((char *, int));
101
102 static void tbreak_at_finish_command PARAMS ((char *, int));
103
104 static void
105 break_command_1 PARAMS ((char *, int, int));
106
107 static void
108 mention PARAMS ((struct breakpoint *));
109
110 struct breakpoint *
111   set_raw_breakpoint PARAMS ((struct symtab_and_line));
112
113 static void
114 check_duplicates PARAMS ((CORE_ADDR, asection *));
115
116 static void
117 describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
118
119 static void
120 breakpoints_info PARAMS ((char *, int));
121
122 static void
123 breakpoint_1 PARAMS ((int, int));
124
125 static bpstat
126   bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
127
128 static int breakpoint_cond_eval PARAMS ((PTR));
129
130 static void
131 cleanup_executing_breakpoints PARAMS ((PTR));
132
133 static void
134 commands_command PARAMS ((char *, int));
135
136 static void
137 condition_command PARAMS ((char *, int));
138
139 static int
140 get_number_trailer PARAMS ((char **, int));
141
142 void
143 set_breakpoint_count PARAMS ((int));
144
145 #if 0
146 static struct breakpoint *
147   create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
148 #endif
149
150 typedef enum
151   {
152     mark_inserted,
153     mark_uninserted
154   }
155 insertion_state_t;
156
157 static int
158 remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
159
160 static enum print_stop_action print_it_typical PARAMS ((bpstat));
161
162 static enum print_stop_action print_bp_stop_message (bpstat bs);
163
164 typedef struct
165   {
166     enum exception_event_kind kind;
167     int enable;
168   }
169 args_for_catchpoint_enable;
170
171 static int watchpoint_check PARAMS ((PTR));
172
173 static int cover_target_enable_exception_callback PARAMS ((PTR));
174
175 static void maintenance_info_breakpoints PARAMS ((char *, int));
176
177 #ifdef GET_LONGJMP_TARGET
178 static void create_longjmp_breakpoint PARAMS ((char *));
179 #endif
180
181 static int hw_breakpoint_used_count PARAMS ((void));
182
183 static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
184
185 static void hbreak_command PARAMS ((char *, int));
186
187 static void thbreak_command PARAMS ((char *, int));
188
189 static void watch_command_1 PARAMS ((char *, int, int));
190
191 static void rwatch_command PARAMS ((char *, int));
192
193 static void awatch_command PARAMS ((char *, int));
194
195 static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
196
197 static void solib_load_unload_1 PARAMS ((char *hookname,
198                                          int tempflag,
199                                          char *dll_pathname,
200                                          char *cond_string,
201                                          enum bptype bp_kind));
202
203 static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag, 
204                                                         char *cond_string,
205                                                         enum bptype bp_kind));
206
207 static void break_at_finish_at_depth_command_1 PARAMS ((char *arg, 
208                                                         int flag, 
209                                                         int from_tty));
210
211 static void break_at_finish_command_1 PARAMS ((char *arg, 
212                                                int flag, 
213                                                int from_tty));
214
215 static void stop_command PARAMS ((char *arg, int from_tty));
216
217 static void stopin_command PARAMS ((char *arg, int from_tty));
218
219 static void stopat_command PARAMS ((char *arg, int from_tty));
220
221 static char *ep_find_event_name_end PARAMS ((char *arg));
222
223 static char *ep_parse_optional_if_clause PARAMS ((char **arg));
224
225 static char *ep_parse_optional_filename PARAMS ((char **arg));
226
227 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
228 static void catch_exec_command_1 PARAMS ((char *arg, int tempflag, 
229                                           int from_tty));
230 #endif
231
232 static void create_exception_catchpoint 
233   PARAMS ((int tempflag, char *cond_string,
234            enum exception_event_kind ex_event,
235            struct symtab_and_line * sal));
236
237 static void catch_exception_command_1 
238   PARAMS ((enum exception_event_kind ex_event,
239            char *arg, int tempflag, int from_tty));
240
241 static void tcatch_command PARAMS ((char *arg, int from_tty));
242
243 static void ep_skip_leading_whitespace PARAMS ((char **s));
244
245 /* Prototypes for exported functions. */
246
247 static void
248 awatch_command PARAMS ((char *, int));
249
250 static void
251 do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
252
253 /* If FALSE, gdb will not use hardware support for watchpoints, even
254    if such is available. */
255 static int can_use_hw_watchpoints;
256
257 void _initialize_breakpoint PARAMS ((void));
258
259 void set_breakpoint_count PARAMS ((int));
260
261 extern int addressprint;        /* Print machine addresses? */
262
263 static int internal_breakpoint_number = -1;
264
265 /* Are we executing breakpoint commands?  */
266 static int executing_breakpoint_commands;
267
268 /* Walk the following statement or block through all breakpoints.
269    ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
270    breakpoint.  */
271
272 #define ALL_BREAKPOINTS(B)  for (B = breakpoint_chain; B; B = B->next)
273
274 #define ALL_BREAKPOINTS_SAFE(B,TMP)     \
275         for (B = breakpoint_chain;      \
276              B ? (TMP=B->next, 1): 0;   \
277              B = TMP)
278
279 /* True if SHIFT_INST_REGS defined, false otherwise.  */
280
281 int must_shift_inst_regs =
282 #if defined(SHIFT_INST_REGS)
283 1
284 #else
285 0
286 #endif
287  ;
288
289 /* True if breakpoint hit counts should be displayed in breakpoint info.  */
290
291 int show_breakpoint_hit_counts = 1;
292
293 /* Chain of all breakpoints defined.  */
294
295 struct breakpoint *breakpoint_chain;
296
297 /* Number of last breakpoint made.  */
298
299 int breakpoint_count;
300
301 /* Pointer to current exception event record */
302 static struct exception_event_record *current_exception_event;
303
304 /* Indicator of whether exception catchpoints should be nuked
305    between runs of a program */
306 int exception_catchpoints_are_fragile = 0;
307
308 /* Indicator of when exception catchpoints set-up should be
309    reinitialized -- e.g. when program is re-run */
310 int exception_support_initialized = 0;
311
312 /* This function returns a pointer to the string representation of the
313    pathname of the dynamically-linked library that has just been
314    loaded.
315
316    This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
317    or undefined results are guaranteed.
318
319    This string's contents are only valid immediately after the
320    inferior has stopped in the dynamic linker hook, and becomes
321    invalid as soon as the inferior is continued.  Clients should make
322    a copy of this string if they wish to continue the inferior and
323    then access the string.  */
324
325 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
326 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
327 #endif
328
329 /* This function returns a pointer to the string representation of the
330    pathname of the dynamically-linked library that has just been
331    unloaded.
332
333    This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
334    TRUE, or undefined results are guaranteed.
335
336    This string's contents are only valid immediately after the
337    inferior has stopped in the dynamic linker hook, and becomes
338    invalid as soon as the inferior is continued.  Clients should make
339    a copy of this string if they wish to continue the inferior and
340    then access the string.  */
341
342 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
343 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
344 #endif
345
346 /* This function is called by the "catch load" command.  It allows the
347    debugger to be notified by the dynamic linker when a specified
348    library file (or any library file, if filename is NULL) is loaded.  */
349
350 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
351 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
352    error ("catch of library loads not yet implemented on this platform")
353 #endif
354
355 /* This function is called by the "catch unload" command.  It allows
356    the debugger to be notified by the dynamic linker when a specified
357    library file (or any library file, if filename is NULL) is
358    unloaded.  */
359
360 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
361 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
362    error ("catch of library unloads not yet implemented on this platform")
363 #endif
364
365 /* Set breakpoint count to NUM.  */
366
367 void
368 set_breakpoint_count (num)
369      int num;
370 {
371   breakpoint_count = num;
372   set_internalvar (lookup_internalvar ("bpnum"),
373                    value_from_longest (builtin_type_int, (LONGEST) num));
374 }
375
376 /* Used in run_command to zero the hit count when a new run starts. */
377
378 void
379 clear_breakpoint_hit_counts ()
380 {
381   struct breakpoint *b;
382
383   ALL_BREAKPOINTS (b)
384     b->hit_count = 0;
385 }
386
387 /* Default address, symtab and line to put a breakpoint at
388    for "break" command with no arg.
389    if default_breakpoint_valid is zero, the other three are
390    not valid, and "break" with no arg is an error.
391
392    This set by print_stack_frame, which calls set_default_breakpoint.  */
393
394 int default_breakpoint_valid;
395 CORE_ADDR default_breakpoint_address;
396 struct symtab *default_breakpoint_symtab;
397 int default_breakpoint_line;
398 \f
399 /* *PP is a string denoting a breakpoint.  Get the number of the breakpoint.
400    Advance *PP after the string and any trailing whitespace.
401
402    Currently the string can either be a number or "$" followed by the name
403    of a convenience variable.  Making it an expression wouldn't work well
404    for map_breakpoint_numbers (e.g. "4 + 5 + 6").
405    
406    TRAILER is a character which can be found after the number; most
407    commonly this is `-'.  If you don't want a trailer, use \0.  */ 
408 static int
409 get_number_trailer (pp, trailer)
410      char **pp;
411      int trailer;
412 {
413   int retval = 0;       /* default */
414   char *p = *pp;
415
416   if (p == NULL)
417     /* Empty line means refer to the last breakpoint.  */
418     return breakpoint_count;
419   else if (*p == '$')
420     {
421       /* Make a copy of the name, so we can null-terminate it
422          to pass to lookup_internalvar().  */
423       char *varname;
424       char *start = ++p;
425       value_ptr val;
426
427       while (isalnum (*p) || *p == '_')
428         p++;
429       varname = (char *) alloca (p - start + 1);
430       strncpy (varname, start, p - start);
431       varname[p - start] = '\0';
432       val = value_of_internalvar (lookup_internalvar (varname));
433       if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
434         retval = (int) value_as_long (val);
435       else
436         {
437           printf_filtered ("Convenience variable must have integer value.\n");
438           retval = 0;
439         }
440     }
441   else
442     {
443       if (*p == '-')
444         ++p;
445       while (*p >= '0' && *p <= '9')
446         ++p;
447       if (p == *pp)
448         /* There is no number here.  (e.g. "cond a == b").  */
449         {
450           /* Skip non-numeric token */
451           while (*p && !isspace((int) *p))
452             ++p;
453           /* Return zero, which caller must interpret as error. */
454           retval = 0;
455         }
456       else
457         retval = atoi (*pp);
458     }
459   if (!(isspace (*p) || *p == '\0' || *p == trailer))
460     {
461       /* Trailing junk: return 0 and let caller print error msg. */
462       while (!(isspace (*p) || *p == '\0' || *p == trailer))
463         ++p;
464       retval = 0;
465     }
466   while (isspace (*p))
467     p++;
468   *pp = p;
469   return retval;
470 }
471
472
473 /* Like get_number_trailer, but don't allow a trailer.  */
474 int
475 get_number (pp)
476      char **pp;
477 {
478   return get_number_trailer (pp, '\0');
479 }
480
481 /* Parse a number or a range.
482  * A number will be of the form handled by get_number.
483  * A range will be of the form <number1> - <number2>, and 
484  * will represent all the integers between number1 and number2,
485  * inclusive.
486  *
487  * While processing a range, this fuction is called iteratively;
488  * At each call it will return the next value in the range.
489  *
490  * At the beginning of parsing a range, the char pointer PP will
491  * be advanced past <number1> and left pointing at the '-' token.
492  * Subsequent calls will not advance the pointer until the range
493  * is completed.  The call that completes the range will advance
494  * pointer PP past <number2>.
495  */
496
497 int 
498 get_number_or_range (pp)
499      char **pp;
500 {
501   static int last_retval, end_value;
502   static char *end_ptr;
503   static int in_range = 0;
504
505   if (**pp != '-')
506     {
507       /* Default case: pp is pointing either to a solo number, 
508          or to the first number of a range.  */
509       last_retval = get_number_trailer (pp, '-');
510       if (**pp == '-')
511         {
512           char **temp;
513
514           /* This is the start of a range (<number1> - <number2>).
515              Skip the '-', parse and remember the second number,
516              and also remember the end of the final token.  */
517
518           temp = &end_ptr; 
519           end_ptr = *pp + 1; 
520           while (isspace ((int) *end_ptr))
521             end_ptr++;  /* skip white space */
522           end_value = get_number (temp);
523           if (end_value < last_retval) 
524             {
525               error ("inverted range");
526             }
527           else if (end_value == last_retval)
528             {
529               /* degenerate range (number1 == number2).  Advance the
530                  token pointer so that the range will be treated as a
531                  single number.  */ 
532               *pp = end_ptr;
533             }
534           else
535             in_range = 1;
536         }
537     }
538   else if (! in_range)
539     error ("negative value");
540   else
541     {
542       /* pp points to the '-' that betokens a range.  All
543          number-parsing has already been done.  Return the next
544          integer value (one greater than the saved previous value).
545          Do not advance the token pointer 'pp' until the end of range
546          is reached.  */
547
548       if (++last_retval == end_value)
549         {
550           /* End of range reached; advance token pointer.  */
551           *pp = end_ptr;
552           in_range = 0;
553         }
554     }
555   return last_retval;
556 }
557
558
559 \f
560 /* condition N EXP -- set break condition of breakpoint N to EXP.  */
561
562 static void
563 condition_command (arg, from_tty)
564      char *arg;
565      int from_tty;
566 {
567   register struct breakpoint *b;
568   char *p;
569   register int bnum;
570
571   if (arg == 0)
572     error_no_arg ("breakpoint number");
573
574   p = arg;
575   bnum = get_number (&p);
576   if (bnum == 0)
577     error ("Bad breakpoint argument: '%s'", arg);
578
579   ALL_BREAKPOINTS (b)
580     if (b->number == bnum)
581     {
582       if (b->cond)
583         {
584           free ((PTR) b->cond);
585           b->cond = 0;
586         }
587       if (b->cond_string != NULL)
588         free ((PTR) b->cond_string);
589
590       if (*p == 0)
591         {
592           b->cond = 0;
593           b->cond_string = NULL;
594           if (from_tty)
595             printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
596         }
597       else
598         {
599           arg = p;
600           /* I don't know if it matters whether this is the string the user
601              typed in or the decompiled expression.  */
602           b->cond_string = savestring (arg, strlen (arg));
603           b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
604           if (*arg)
605             error ("Junk at end of expression");
606         }
607       breakpoints_changed ();
608       return;
609     }
610
611   error ("No breakpoint number %d.", bnum);
612 }
613
614 /* ARGSUSED */
615 static void
616 commands_command (arg, from_tty)
617      char *arg;
618      int from_tty;
619 {
620   register struct breakpoint *b;
621   char *p;
622   register int bnum;
623   struct command_line *l;
624
625   /* If we allowed this, we would have problems with when to
626      free the storage, if we change the commands currently
627      being read from.  */
628
629   if (executing_breakpoint_commands)
630     error ("Can't use the \"commands\" command among a breakpoint's commands.");
631
632   p = arg;
633   bnum = get_number (&p);
634
635   if (p && *p)
636     error ("Unexpected extra arguments following breakpoint number.");
637
638   ALL_BREAKPOINTS (b)
639     if (b->number == bnum)
640     {
641       char tmpbuf[128];
642       sprintf (tmpbuf, 
643                "Type commands for when breakpoint %d is hit, one per line.", 
644                bnum);
645       l = read_command_lines (tmpbuf, from_tty);
646       free_command_lines (&b->commands);
647       b->commands = l;
648       breakpoints_changed ();
649       return;
650     }
651   error ("No breakpoint number %d.", bnum);
652 }
653 \f
654 /* Like target_read_memory() but if breakpoints are inserted, return
655    the shadow contents instead of the breakpoints themselves.
656
657    Read "memory data" from whatever target or inferior we have. 
658    Returns zero if successful, errno value if not.  EIO is used
659    for address out of bounds.  If breakpoints are inserted, returns
660    shadow contents, not the breakpoints themselves.  From breakpoint.c.  */
661
662 int
663 read_memory_nobpt (memaddr, myaddr, len)
664      CORE_ADDR memaddr;
665      char *myaddr;
666      unsigned len;
667 {
668   int status;
669   struct breakpoint *b;
670   CORE_ADDR bp_addr = 0;
671   int bp_size = 0;
672
673   if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
674     /* No breakpoints on this machine. */
675     return target_read_memory (memaddr, myaddr, len);
676
677   ALL_BREAKPOINTS (b)
678   {
679     if (b->type == bp_none)
680       warning ("reading through apparently deleted breakpoint #%d?", 
681                b->number);
682
683     /* memory breakpoint? */
684     if (b->type == bp_watchpoint
685         || b->type == bp_hardware_watchpoint
686         || b->type == bp_read_watchpoint
687         || b->type == bp_access_watchpoint)
688       continue;
689     /* bp in memory? */
690     if (!b->inserted)
691       continue;
692     /* Addresses and length of the part of the breakpoint that
693        we need to copy.  */
694     /* XXXX The m68k, sh and h8300 have different local and remote
695        breakpoint values.  BREAKPOINT_FROM_PC still manages to
696        correctly determine the breakpoints memory address and size
697        for these targets. */
698     bp_addr = b->address;
699     bp_size = 0;
700     if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
701       continue;
702     if (bp_size == 0)
703       /* bp isn't valid */
704       continue;
705     if (bp_addr + bp_size <= memaddr)
706       /* The breakpoint is entirely before the chunk of memory we
707          are reading.  */
708       continue;
709     if (bp_addr >= memaddr + len)
710       /* The breakpoint is entirely after the chunk of memory we are
711          reading. */
712       continue;
713     /* Copy the breakpoint from the shadow contents, and recurse for
714        the things before and after.  */
715     {
716       /* Offset within shadow_contents.  */
717       int bptoffset = 0;
718
719       if (bp_addr < memaddr)
720         {
721           /* Only copy the second part of the breakpoint.  */
722           bp_size -= memaddr - bp_addr;
723           bptoffset = memaddr - bp_addr;
724           bp_addr = memaddr;
725         }
726
727       if (bp_addr + bp_size > memaddr + len)
728         {
729           /* Only copy the first part of the breakpoint.  */
730           bp_size -= (bp_addr + bp_size) - (memaddr + len);
731         }
732
733       memcpy (myaddr + bp_addr - memaddr,
734               b->shadow_contents + bptoffset, bp_size);
735
736       if (bp_addr > memaddr)
737         {
738           /* Copy the section of memory before the breakpoint.  */
739           status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
740           if (status != 0)
741             return status;
742         }
743
744       if (bp_addr + bp_size < memaddr + len)
745         {
746           /* Copy the section of memory after the breakpoint.  */
747           status = read_memory_nobpt
748             (bp_addr + bp_size,
749              myaddr + bp_addr + bp_size - memaddr,
750              memaddr + len - (bp_addr + bp_size));
751           if (status != 0)
752             return status;
753         }
754       return 0;
755     }
756   }
757   /* Nothing overlaps.  Just call read_memory_noerr.  */
758   return target_read_memory (memaddr, myaddr, len);
759 }
760 \f
761
762 /* insert_breakpoints is used when starting or continuing the program.
763    remove_breakpoints is used when the program stops.
764    Both return zero if successful,
765    or an `errno' value if could not write the inferior.  */
766
767 int
768 insert_breakpoints ()
769 {
770   register struct breakpoint *b, *temp;
771   int return_val = 0;   /* return success code. */
772   int val = 0;
773   int disabled_breaks = 0;
774
775   static char message1[] = "Error inserting catchpoint %d:\n";
776   static char message[sizeof (message1) + 30];
777
778
779   ALL_BREAKPOINTS_SAFE (b, temp)
780   {
781     if (b->enable == permanent)
782       /* Permanent breakpoints cannot be inserted or removed.  */
783       continue;
784     else if (b->type != bp_watchpoint
785         && b->type != bp_hardware_watchpoint
786         && b->type != bp_read_watchpoint
787         && b->type != bp_access_watchpoint
788         && b->type != bp_catch_fork
789         && b->type != bp_catch_vfork
790         && b->type != bp_catch_exec
791         && b->type != bp_catch_throw
792         && b->type != bp_catch_catch
793         && b->enable != disabled
794         && b->enable != shlib_disabled
795         && b->enable != call_disabled
796         && !b->inserted
797         && !b->duplicate)
798       {
799         if (b->type == bp_hardware_breakpoint)
800           val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
801         else
802           {
803             /* Check to see if breakpoint is in an overlay section;
804                if so, we should set the breakpoint at the LMA address.
805                Only if the section is currently mapped should we ALSO
806                set a break at the VMA address. */
807             if (overlay_debugging && b->section &&
808                 section_is_overlay (b->section))
809               {
810                 CORE_ADDR addr;
811
812                 addr = overlay_unmapped_address (b->address, b->section);
813                 val = target_insert_breakpoint (addr, b->shadow_contents);
814                 /* This would be the time to check val, to see if the
815                    breakpoint write to the load address succeeded.  
816                    However, this might be an ordinary occurrance, eg. if 
817                    the unmapped overlay is in ROM.  */
818                 val = 0;        /* in case unmapped address failed */
819                 if (section_is_mapped (b->section))
820                   val = target_insert_breakpoint (b->address,
821                                                   b->shadow_contents);
822               }
823             else                /* ordinary (non-overlay) address */
824               val = target_insert_breakpoint (b->address, b->shadow_contents);
825           }
826         if (val)
827           {
828             /* Can't set the breakpoint.  */
829 #if defined (DISABLE_UNSETTABLE_BREAK)
830             if (DISABLE_UNSETTABLE_BREAK (b->address))
831               {
832                 /* See also: disable_breakpoints_in_shlibs. */
833                 val = 0;
834                 b->enable = shlib_disabled;
835                 if (!disabled_breaks)
836                   {
837                     target_terminal_ours_for_output ();
838                     warning ("Cannot insert breakpoint %d:", b->number);
839                     warning ("Temporarily disabling shared library breakpoints:");
840                   }
841                 disabled_breaks = 1;
842                 warning ("breakpoint #%d ", b->number);
843               }
844             else
845 #endif
846               {
847                 target_terminal_ours_for_output ();
848                 warning ("Cannot insert breakpoint %d:", b->number);
849 #ifdef ONE_PROCESS_WRITETEXT
850                 warning ("The same program may be running in another process.");
851 #endif
852                 memory_error (val, b->address);    /* which bombs us out */
853               }
854           }
855         else
856           b->inserted = 1;
857
858         if (val)
859           return_val = val;     /* remember failure */
860       }
861     else if (ep_is_exception_catchpoint (b)
862              && b->enable != disabled
863              && b->enable != shlib_disabled
864              && b->enable != call_disabled
865              && !b->inserted
866              && !b->duplicate)
867
868       {
869         /* If we get here, we must have a callback mechanism for exception
870            events -- with g++ style embedded label support, we insert
871            ordinary breakpoints and not catchpoints. */
872         /* Format possible error message */
873         sprintf (message, message1, b->number);
874
875         val = target_insert_breakpoint (b->address, b->shadow_contents);
876         if (val)
877           {
878             /* Couldn't set breakpoint for some reason */
879             target_terminal_ours_for_output ();
880             warning ("Cannot insert catchpoint %d; disabling it.",
881                      b->number);
882             b->enable = disabled;
883           }
884         else
885           {
886             /* Bp set, now make sure callbacks are enabled */
887             int val;
888             args_for_catchpoint_enable args;
889             args.kind = b->type == bp_catch_catch ? 
890               EX_EVENT_CATCH : EX_EVENT_THROW;
891             args.enable = 1;
892             val = catch_errors (cover_target_enable_exception_callback,
893                                 &args,
894                                 message, RETURN_MASK_ALL);
895             if (val != 0 && val != -1)
896               {
897                 b->inserted = 1;
898               }
899             /* Check if something went wrong; val == 0 can be ignored */
900             if (val == -1)
901               {
902                 /* something went wrong */
903                 target_terminal_ours_for_output ();
904                 warning ("Cannot insert catchpoint %d; disabling it.",
905                          b->number);
906                 b->enable = disabled;
907               }
908           }
909
910         if (val)
911           return_val = val;     /* remember failure */
912       }
913
914     else if ((b->type == bp_hardware_watchpoint ||
915               b->type == bp_read_watchpoint ||
916               b->type == bp_access_watchpoint)
917              && b->enable == enabled
918              && !b->inserted
919              && !b->duplicate)
920       {
921         struct frame_info *saved_frame;
922         int saved_level, within_current_scope;
923         value_ptr mark = value_mark ();
924         value_ptr v;
925
926         /* Save the current frame and level so we can restore it after
927            evaluating the watchpoint expression on its own frame.  */
928         saved_frame = selected_frame;
929         saved_level = selected_frame_level;
930
931         /* Determine if the watchpoint is within scope.  */
932         if (b->exp_valid_block == NULL)
933           within_current_scope = 1;
934         else
935           {
936             struct frame_info *fi;
937
938             /* There might be no current frame at this moment if we are
939                resuming from a step over a breakpoint.
940                Set up current frame before trying to find the watchpoint
941                frame.  */
942             get_current_frame ();
943             fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
944             within_current_scope = (fi != NULL);
945             if (within_current_scope)
946               select_frame (fi, -1);
947           }
948
949         if (within_current_scope)
950           {
951             /* Evaluate the expression and cut the chain of values
952                produced off from the value chain.
953
954                Make sure the value returned isn't lazy; we use
955                laziness to determine what memory GDB actually needed
956                in order to compute the value of the expression.  */
957             v = evaluate_expression (b->exp);
958             VALUE_CONTENTS(v);
959             value_release_to_mark (mark);
960
961             b->val_chain = v;
962             b->inserted = 1;
963
964             /* Look at each value on the value chain.  */
965             for (; v; v = v->next)
966               {
967                 /* If it's a memory location, and GDB actually needed
968                    its contents to evaluate the expression, then we
969                    must watch it.  */
970                 if (VALUE_LVAL (v) == lval_memory
971                     && ! VALUE_LAZY (v))
972                   {
973                     CORE_ADDR addr;
974                     int len, type;
975
976                     addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
977                     len = TYPE_LENGTH (VALUE_TYPE (v));
978                     type   = hw_write;
979                     if (b->type == bp_read_watchpoint)
980                       type = hw_read;
981                     else if (b->type == bp_access_watchpoint)
982                       type = hw_access;
983
984                     val = target_insert_watchpoint (addr, len, type);
985                     if (val == -1)
986                       {
987                         b->inserted = 0;
988                         break;
989                       }
990                     val = 0;
991                   }
992               }
993             /* Failure to insert a watchpoint on any memory value in the
994                value chain brings us here.  */
995             if (!b->inserted)
996               {
997                 remove_breakpoint (b, mark_uninserted);
998                 warning ("Could not insert hardware watchpoint %d.",
999                          b->number);
1000                 val = -1;
1001               }               
1002           }
1003         else
1004           {
1005             printf_filtered ("Hardware watchpoint %d deleted", b->number);
1006             printf_filtered ("because the program has left the block \n");
1007             printf_filtered ("in which its expression is valid.\n");
1008             if (b->related_breakpoint)
1009               b->related_breakpoint->disposition = del_at_next_stop;
1010             b->disposition = del_at_next_stop;
1011           }
1012
1013         /* Restore the frame and level.  */
1014         if ((saved_frame != selected_frame) ||
1015             (saved_level != selected_frame_level))
1016           select_and_print_frame (saved_frame, saved_level);
1017
1018         if (val)
1019           return_val = val;     /* remember failure */
1020       }
1021     else if ((b->type == bp_catch_fork
1022               || b->type == bp_catch_vfork
1023               || b->type == bp_catch_exec)
1024              && b->enable == enabled
1025              && !b->inserted
1026              && !b->duplicate)
1027       {
1028         val = -1;
1029         switch (b->type)
1030           {
1031           case bp_catch_fork:
1032             val = target_insert_fork_catchpoint (inferior_pid);
1033             break;
1034           case bp_catch_vfork:
1035             val = target_insert_vfork_catchpoint (inferior_pid);
1036             break;
1037           case bp_catch_exec:
1038             val = target_insert_exec_catchpoint (inferior_pid);
1039             break;
1040           default:
1041             warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1042             break;
1043           }
1044         if (val < 0)
1045           {
1046             target_terminal_ours_for_output ();
1047             warning ("Cannot insert catchpoint %d.", b->number);
1048           }
1049         else
1050           b->inserted = 1;
1051
1052         if (val)
1053           return_val = val;     /* remember failure */
1054       }
1055   }
1056
1057   return return_val;
1058 }
1059
1060
1061 int
1062 remove_breakpoints ()
1063 {
1064   register struct breakpoint *b;
1065   int val;
1066
1067   ALL_BREAKPOINTS (b)
1068   {
1069     if (b->inserted)
1070       {
1071         val = remove_breakpoint (b, mark_uninserted);
1072         if (val != 0)
1073           return val;
1074       }
1075   }
1076   return 0;
1077 }
1078
1079 int
1080 reattach_breakpoints (pid)
1081      int pid;
1082 {
1083   register struct breakpoint *b;
1084   int val;
1085   int saved_inferior_pid = inferior_pid;
1086
1087   /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1088   inferior_pid = pid;   /* Because remove_breakpoint will use this global. */
1089   ALL_BREAKPOINTS (b)
1090   {
1091     if (b->inserted)
1092       {
1093         remove_breakpoint (b, mark_inserted);
1094         if (b->type == bp_hardware_breakpoint)
1095           val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1096         else
1097           val = target_insert_breakpoint (b->address, b->shadow_contents);
1098         if (val != 0)
1099           {
1100             inferior_pid = saved_inferior_pid;
1101             return val;
1102           }
1103       }
1104   }
1105   inferior_pid = saved_inferior_pid;
1106   return 0;
1107 }
1108
1109 void
1110 update_breakpoints_after_exec ()
1111 {
1112   struct breakpoint *b;
1113   struct breakpoint *temp;
1114
1115   /* Doing this first prevents the badness of having delete_breakpoint()
1116      write a breakpoint's current "shadow contents" to lift the bp.  That
1117      shadow is NOT valid after an exec()! */
1118   mark_breakpoints_out ();
1119
1120   ALL_BREAKPOINTS_SAFE (b, temp)
1121   {
1122     /* Solib breakpoints must be explicitly reset after an exec(). */
1123     if (b->type == bp_shlib_event)
1124       {
1125         delete_breakpoint (b);
1126         continue;
1127       }
1128
1129     /* Thread event breakpoints must be set anew after an exec().  */
1130     if (b->type == bp_thread_event)
1131       {
1132         delete_breakpoint (b);
1133         continue;
1134       }
1135
1136     /* Step-resume breakpoints are meaningless after an exec(). */
1137     if (b->type == bp_step_resume)
1138       {
1139         delete_breakpoint (b);
1140         continue;
1141       }
1142
1143     /* Ditto the sigtramp handler breakpoints. */
1144     if (b->type == bp_through_sigtramp)
1145       {
1146         delete_breakpoint (b);
1147         continue;
1148       }
1149
1150     /* Ditto the exception-handling catchpoints. */
1151     if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1152       {
1153         delete_breakpoint (b);
1154         continue;
1155       }
1156
1157     /* Don't delete an exec catchpoint, because else the inferior
1158        won't stop when it ought!
1159
1160        Similarly, we probably ought to keep vfork catchpoints, 'cause
1161        on this target, we may not be able to stop when the vfork is
1162        seen, but only when the subsequent exec is seen.  (And because
1163        deleting fork catchpoints here but not vfork catchpoints will
1164        seem mysterious to users, keep those too.)
1165
1166        ??rehrauer: Let's hope that merely clearing out this catchpoint's
1167        target address field, if any, is sufficient to have it be reset
1168        automagically.  Certainly on HP-UX that's true. */
1169     if ((b->type == bp_catch_exec) ||
1170         (b->type == bp_catch_vfork) ||
1171         (b->type == bp_catch_fork))
1172       {
1173         b->address = (CORE_ADDR) NULL;
1174         continue;
1175       }
1176
1177     /* bp_finish is a special case.  The only way we ought to be able
1178        to see one of these when an exec() has happened, is if the user
1179        caught a vfork, and then said "finish".  Ordinarily a finish just
1180        carries them to the call-site of the current callee, by setting
1181        a temporary bp there and resuming.  But in this case, the finish
1182        will carry them entirely through the vfork & exec.
1183
1184        We don't want to allow a bp_finish to remain inserted now.  But
1185        we can't safely delete it, 'cause finish_command has a handle to
1186        the bp on a bpstat, and will later want to delete it.  There's a
1187        chance (and I've seen it happen) that if we delete the bp_finish
1188        here, that its storage will get reused by the time finish_command
1189        gets 'round to deleting the "use to be a bp_finish" breakpoint.
1190        We really must allow finish_command to delete a bp_finish.
1191
1192        In the absense of a general solution for the "how do we know
1193        it's safe to delete something others may have handles to?"
1194        problem, what we'll do here is just uninsert the bp_finish, and
1195        let finish_command delete it.
1196
1197        (We know the bp_finish is "doomed" in the sense that it's
1198        momentary, and will be deleted as soon as finish_command sees
1199        the inferior stopped.  So it doesn't matter that the bp's
1200        address is probably bogus in the new a.out, unlike e.g., the
1201        solib breakpoints.)  */
1202
1203     if (b->type == bp_finish)
1204       {
1205         continue;
1206       }
1207
1208     /* Without a symbolic address, we have little hope of the
1209        pre-exec() address meaning the same thing in the post-exec()
1210        a.out. */
1211     if (b->addr_string == NULL)
1212       {
1213         delete_breakpoint (b);
1214         continue;
1215       }
1216
1217     /* If this breakpoint has survived the above battery of checks, then
1218        it must have a symbolic address.  Be sure that it gets reevaluated
1219        to a target address, rather than reusing the old evaluation.  */
1220     b->address = (CORE_ADDR) NULL;
1221   }
1222 }
1223
1224 int
1225 detach_breakpoints (pid)
1226      int pid;
1227 {
1228   register struct breakpoint *b;
1229   int val;
1230   int saved_inferior_pid = inferior_pid;
1231
1232   if (pid == inferior_pid)
1233     error ("Cannot detach breakpoints of inferior_pid");
1234
1235   /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1236   inferior_pid = pid;   /* Because remove_breakpoint will use this global. */
1237   ALL_BREAKPOINTS (b)
1238   {
1239     if (b->inserted)
1240       {
1241         val = remove_breakpoint (b, mark_inserted);
1242         if (val != 0)
1243           {
1244             inferior_pid = saved_inferior_pid;
1245             return val;
1246           }
1247       }
1248   }
1249   inferior_pid = saved_inferior_pid;
1250   return 0;
1251 }
1252
1253 static int
1254 remove_breakpoint (b, is)
1255      struct breakpoint *b;
1256      insertion_state_t is;
1257 {
1258   int val;
1259
1260   if (b->enable == permanent)
1261     /* Permanent breakpoints cannot be inserted or removed.  */
1262     return 0;
1263
1264   if (b->type == bp_none)
1265     warning ("attempted to remove apparently deleted breakpoint #%d?", 
1266              b->number);
1267
1268   if (b->type != bp_watchpoint
1269       && b->type != bp_hardware_watchpoint
1270       && b->type != bp_read_watchpoint
1271       && b->type != bp_access_watchpoint
1272       && b->type != bp_catch_fork
1273       && b->type != bp_catch_vfork
1274       && b->type != bp_catch_exec
1275       && b->type != bp_catch_catch
1276       && b->type != bp_catch_throw)
1277     {
1278       if (b->type == bp_hardware_breakpoint)
1279         val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1280       else
1281         {
1282           /* Check to see if breakpoint is in an overlay section;
1283              if so, we should remove the breakpoint at the LMA address.
1284              If that is not equal to the raw address, then we should 
1285              presumable remove the breakpoint there as well.  */
1286           if (overlay_debugging && b->section &&
1287               section_is_overlay (b->section))
1288             {
1289               CORE_ADDR addr;
1290
1291               addr = overlay_unmapped_address (b->address, b->section);
1292               val = target_remove_breakpoint (addr, b->shadow_contents);
1293               /* This would be the time to check val, to see if the
1294                  shadow breakpoint write to the load address succeeded.  
1295                  However, this might be an ordinary occurrance, eg. if 
1296                  the unmapped overlay is in ROM.  */
1297               val = 0;          /* in case unmapped address failed */
1298               if (section_is_mapped (b->section))
1299                 val = target_remove_breakpoint (b->address,
1300                                                 b->shadow_contents);
1301             }
1302           else                  /* ordinary (non-overlay) address */
1303             val = target_remove_breakpoint (b->address, b->shadow_contents);
1304         }
1305       if (val)
1306         return val;
1307       b->inserted = (is == mark_inserted);
1308     }
1309   else if ((b->type == bp_hardware_watchpoint ||
1310             b->type == bp_read_watchpoint ||
1311             b->type == bp_access_watchpoint)
1312            && b->enable == enabled
1313            && !b->duplicate)
1314     {
1315       value_ptr v, n;
1316
1317       b->inserted = (is == mark_inserted);
1318       /* Walk down the saved value chain.  */
1319       for (v = b->val_chain; v; v = v->next)
1320         {
1321           /* For each memory reference remove the watchpoint
1322              at that address.  */
1323           if (VALUE_LVAL (v) == lval_memory
1324               && ! VALUE_LAZY (v))
1325             {
1326               CORE_ADDR addr;
1327               int len, type;
1328
1329               addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1330               len = TYPE_LENGTH (VALUE_TYPE (v));
1331               type   = hw_write;
1332               if (b->type == bp_read_watchpoint)
1333                 type = hw_read;
1334               else if (b->type == bp_access_watchpoint)
1335                 type = hw_access;
1336
1337               val = target_remove_watchpoint (addr, len, type);
1338               if (val == -1)
1339                 b->inserted = 1;
1340               val = 0;
1341             }
1342         }
1343       /* Failure to remove any of the hardware watchpoints comes here.  */
1344       if ((is == mark_uninserted) && (b->inserted))
1345         warning ("Could not remove hardware watchpoint %d.",
1346                  b->number);
1347
1348       /* Free the saved value chain.  We will construct a new one
1349          the next time the watchpoint is inserted.  */
1350       for (v = b->val_chain; v; v = n)
1351         {
1352           n = v->next;
1353           value_free (v);
1354         }
1355       b->val_chain = NULL;
1356     }
1357   else if ((b->type == bp_catch_fork ||
1358             b->type == bp_catch_vfork ||
1359             b->type == bp_catch_exec)
1360            && b->enable == enabled
1361            && !b->duplicate)
1362     {
1363       val = -1;
1364       switch (b->type)
1365         {
1366         case bp_catch_fork:
1367           val = target_remove_fork_catchpoint (inferior_pid);
1368           break;
1369         case bp_catch_vfork:
1370           val = target_remove_vfork_catchpoint (inferior_pid);
1371           break;
1372         case bp_catch_exec:
1373           val = target_remove_exec_catchpoint (inferior_pid);
1374           break;
1375         default:
1376           warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1377           break;
1378         }
1379       if (val)
1380         return val;
1381       b->inserted = (is == mark_inserted);
1382     }
1383   else if ((b->type == bp_catch_catch ||
1384             b->type == bp_catch_throw)
1385            && b->enable == enabled
1386            && !b->duplicate)
1387     {
1388
1389       val = target_remove_breakpoint (b->address, b->shadow_contents);
1390       if (val)
1391         return val;
1392       b->inserted = (is == mark_inserted);
1393     }
1394   else if (ep_is_exception_catchpoint (b)
1395            && b->inserted       /* sometimes previous insert doesn't happen */
1396            && b->enable == enabled
1397            && !b->duplicate)
1398     {
1399
1400       val = target_remove_breakpoint (b->address, b->shadow_contents);
1401       if (val)
1402         return val;
1403
1404       b->inserted = (is == mark_inserted);
1405     }
1406
1407   return 0;
1408 }
1409
1410 /* Clear the "inserted" flag in all breakpoints.  */
1411
1412 void
1413 mark_breakpoints_out ()
1414 {
1415   register struct breakpoint *b;
1416
1417   ALL_BREAKPOINTS (b)
1418     b->inserted = 0;
1419 }
1420
1421 /* Clear the "inserted" flag in all breakpoints and delete any
1422    breakpoints which should go away between runs of the program.
1423
1424    Plus other such housekeeping that has to be done for breakpoints
1425    between runs.
1426
1427    Note: this function gets called at the end of a run (by
1428    generic_mourn_inferior) and when a run begins (by
1429    init_wait_for_inferior). */
1430
1431
1432
1433 void
1434 breakpoint_init_inferior (context)
1435      enum inf_context context;
1436 {
1437   register struct breakpoint *b, *temp;
1438   static int warning_needed = 0;
1439
1440   ALL_BREAKPOINTS_SAFE (b, temp)
1441   {
1442     b->inserted = 0;
1443
1444     switch (b->type)
1445       {
1446       case bp_call_dummy:
1447       case bp_watchpoint_scope:
1448
1449         /* If the call dummy breakpoint is at the entry point it will
1450            cause problems when the inferior is rerun, so we better
1451            get rid of it. 
1452
1453            Also get rid of scope breakpoints.  */
1454         delete_breakpoint (b);
1455         break;
1456
1457       case bp_watchpoint:
1458       case bp_hardware_watchpoint:
1459       case bp_read_watchpoint:
1460       case bp_access_watchpoint:
1461
1462         /* Likewise for watchpoints on local expressions.  */
1463         if (b->exp_valid_block != NULL)
1464           delete_breakpoint (b);
1465         break;
1466       default:
1467         /* Likewise for exception catchpoints in dynamic-linked
1468            executables where required */
1469         if (ep_is_exception_catchpoint (b) &&
1470             exception_catchpoints_are_fragile)
1471           {
1472             warning_needed = 1;
1473             delete_breakpoint (b);
1474           }
1475         break;
1476       }
1477   }
1478
1479   if (exception_catchpoints_are_fragile)
1480     exception_support_initialized = 0;
1481
1482   /* Don't issue the warning unless it's really needed... */
1483   if (warning_needed && (context != inf_exited))
1484     {
1485       warning ("Exception catchpoints from last run were deleted.");
1486       warning ("You must reinsert them explicitly.");
1487       warning_needed = 0;
1488     }
1489 }
1490
1491 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1492    exists at PC.  It returns ordinary_breakpoint_here if it's an
1493    ordinary breakpoint, or permanent_breakpoint_here if it's a
1494    permanent breakpoint.
1495    - When continuing from a location with an ordinary breakpoint, we
1496      actually single step once before calling insert_breakpoints.
1497    - When continuing from a localion with a permanent breakpoint, we
1498      need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1499      the target, to advance the PC past the breakpoint.  */
1500
1501 enum breakpoint_here
1502 breakpoint_here_p (pc)
1503      CORE_ADDR pc;
1504 {
1505   register struct breakpoint *b;
1506   int any_breakpoint_here = 0;
1507
1508   ALL_BREAKPOINTS (b)
1509     if ((b->enable == enabled
1510          || b->enable == permanent)
1511         && b->address == pc)    /* bp is enabled and matches pc */
1512       {
1513         if (overlay_debugging &&
1514             section_is_overlay (b->section) &&
1515             !section_is_mapped (b->section))
1516           continue;             /* unmapped overlay -- can't be a match */
1517         else if (b->enable == permanent)
1518           return permanent_breakpoint_here;
1519         else
1520           any_breakpoint_here = 1;
1521       }
1522
1523   return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1524 }
1525
1526
1527 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1528    but it only returns true if there is actually a breakpoint inserted
1529    at PC.  */
1530
1531 int
1532 breakpoint_inserted_here_p (pc)
1533      CORE_ADDR pc;
1534 {
1535   register struct breakpoint *b;
1536
1537   ALL_BREAKPOINTS (b)
1538     if (b->inserted
1539         && b->address == pc)    /* bp is inserted and matches pc */
1540     {
1541       if (overlay_debugging &&
1542           section_is_overlay (b->section) &&
1543           !section_is_mapped (b->section))
1544         continue;               /* unmapped overlay -- can't be a match */
1545       else
1546         return 1;
1547     }
1548
1549   return 0;
1550 }
1551
1552 /* Return nonzero if FRAME is a dummy frame.  We can't use
1553    PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1554    much time, at least using get_saved_register on the 68k.  This
1555    means that for this function to work right a port must use the
1556    bp_call_dummy breakpoint.  */
1557
1558 int
1559 frame_in_dummy (frame)
1560      struct frame_info *frame;
1561 {
1562   struct breakpoint *b;
1563
1564   if (!CALL_DUMMY_P)
1565     return 0;
1566
1567   if (USE_GENERIC_DUMMY_FRAMES)
1568     return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1569
1570   ALL_BREAKPOINTS (b)
1571   {
1572     if (b->type == bp_call_dummy
1573         && b->frame == frame->frame
1574     /* We need to check the PC as well as the frame on the sparc,
1575        for signals.exp in the testsuite.  */
1576         && (frame->pc
1577             >= (b->address
1578               - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1579         && frame->pc <= b->address)
1580       return 1;
1581   }
1582   return 0;
1583 }
1584
1585 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1586    is valid for process/thread PID.  */
1587
1588 int
1589 breakpoint_thread_match (pc, pid)
1590      CORE_ADDR pc;
1591      int pid;
1592 {
1593   struct breakpoint *b;
1594   int thread;
1595
1596   thread = pid_to_thread_id (pid);
1597
1598   ALL_BREAKPOINTS (b)
1599     if (b->enable != disabled
1600         && b->enable != shlib_disabled
1601         && b->enable != call_disabled
1602         && b->address == pc
1603         && (b->thread == -1 || b->thread == thread))
1604     {
1605       if (overlay_debugging &&
1606           section_is_overlay (b->section) &&
1607           !section_is_mapped (b->section))
1608         continue;               /* unmapped overlay -- can't be a match */
1609       else
1610         return 1;
1611     }
1612
1613   return 0;
1614 }
1615 \f
1616
1617 /* bpstat stuff.  External routines' interfaces are documented
1618    in breakpoint.h.  */
1619
1620 int
1621 ep_is_catchpoint (ep)
1622      struct breakpoint *ep;
1623 {
1624   return
1625     (ep->type == bp_catch_load)
1626     || (ep->type == bp_catch_unload)
1627     || (ep->type == bp_catch_fork)
1628     || (ep->type == bp_catch_vfork)
1629     || (ep->type == bp_catch_exec)
1630     || (ep->type == bp_catch_catch)
1631     || (ep->type == bp_catch_throw)
1632
1633
1634   /* ??rehrauer: Add more kinds here, as are implemented... */
1635     ;
1636 }
1637
1638 int
1639 ep_is_shlib_catchpoint (ep)
1640      struct breakpoint *ep;
1641 {
1642   return
1643     (ep->type == bp_catch_load)
1644     || (ep->type == bp_catch_unload)
1645     ;
1646 }
1647
1648 int
1649 ep_is_exception_catchpoint (ep)
1650      struct breakpoint *ep;
1651 {
1652   return
1653     (ep->type == bp_catch_catch)
1654     || (ep->type == bp_catch_throw)
1655     ;
1656 }
1657
1658 /* Clear a bpstat so that it says we are not at any breakpoint.
1659    Also free any storage that is part of a bpstat.  */
1660
1661 void
1662 bpstat_clear (bsp)
1663      bpstat *bsp;
1664 {
1665   bpstat p;
1666   bpstat q;
1667
1668   if (bsp == 0)
1669     return;
1670   p = *bsp;
1671   while (p != NULL)
1672     {
1673       q = p->next;
1674       if (p->old_val != NULL)
1675         value_free (p->old_val);
1676       free ((PTR) p);
1677       p = q;
1678     }
1679   *bsp = NULL;
1680 }
1681
1682 /* Return a copy of a bpstat.  Like "bs1 = bs2" but all storage that
1683    is part of the bpstat is copied as well.  */
1684
1685 bpstat
1686 bpstat_copy (bs)
1687      bpstat bs;
1688 {
1689   bpstat p = NULL;
1690   bpstat tmp;
1691   bpstat retval = NULL;
1692
1693   if (bs == NULL)
1694     return bs;
1695
1696   for (; bs != NULL; bs = bs->next)
1697     {
1698       tmp = (bpstat) xmalloc (sizeof (*tmp));
1699       memcpy (tmp, bs, sizeof (*tmp));
1700       if (p == NULL)
1701         /* This is the first thing in the chain.  */
1702         retval = tmp;
1703       else
1704         p->next = tmp;
1705       p = tmp;
1706     }
1707   p->next = NULL;
1708   return retval;
1709 }
1710
1711 /* Find the bpstat associated with this breakpoint */
1712
1713 bpstat
1714 bpstat_find_breakpoint (bsp, breakpoint)
1715      bpstat bsp;
1716      struct breakpoint *breakpoint;
1717 {
1718   if (bsp == NULL)
1719     return NULL;
1720
1721   for (; bsp != NULL; bsp = bsp->next)
1722     {
1723       if (bsp->breakpoint_at == breakpoint)
1724         return bsp;
1725     }
1726   return NULL;
1727 }
1728
1729 /* Find a step_resume breakpoint associated with this bpstat.
1730    (If there are multiple step_resume bp's on the list, this function
1731    will arbitrarily pick one.)
1732
1733    It is an error to use this function if BPSTAT doesn't contain a
1734    step_resume breakpoint.
1735
1736    See wait_for_inferior's use of this function.  */
1737 struct breakpoint *
1738 bpstat_find_step_resume_breakpoint (bsp)
1739      bpstat bsp;
1740 {
1741   if (bsp == NULL)
1742     error ("Internal error (bpstat_find_step_resume_breakpoint)");
1743
1744   for (; bsp != NULL; bsp = bsp->next)
1745     {
1746       if ((bsp->breakpoint_at != NULL) &&
1747           (bsp->breakpoint_at->type == bp_step_resume))
1748         return bsp->breakpoint_at;
1749     }
1750
1751   error ("Internal error (no step_resume breakpoint found)");
1752 }
1753
1754
1755 /* Return the breakpoint number of the first breakpoint we are stopped
1756    at.  *BSP upon return is a bpstat which points to the remaining
1757    breakpoints stopped at (but which is not guaranteed to be good for
1758    anything but further calls to bpstat_num).
1759    Return 0 if passed a bpstat which does not indicate any breakpoints.  */
1760
1761 int
1762 bpstat_num (bsp)
1763      bpstat *bsp;
1764 {
1765   struct breakpoint *b;
1766
1767   if ((*bsp) == NULL)
1768     return 0;                   /* No more breakpoint values */
1769   else
1770     {
1771       b = (*bsp)->breakpoint_at;
1772       *bsp = (*bsp)->next;
1773       if (b == NULL)
1774         return -1;              /* breakpoint that's been deleted since */
1775       else
1776         return b->number;       /* We have its number */
1777     }
1778 }
1779
1780 /* Modify BS so that the actions will not be performed.  */
1781
1782 void
1783 bpstat_clear_actions (bs)
1784      bpstat bs;
1785 {
1786   for (; bs != NULL; bs = bs->next)
1787     {
1788       bs->commands = NULL;
1789       if (bs->old_val != NULL)
1790         {
1791           value_free (bs->old_val);
1792           bs->old_val = NULL;
1793         }
1794     }
1795 }
1796
1797 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1798 /* ARGSUSED */
1799 static void
1800 cleanup_executing_breakpoints (ignore)
1801      PTR ignore;
1802 {
1803   executing_breakpoint_commands = 0;
1804 }
1805
1806 /* Execute all the commands associated with all the breakpoints at this
1807    location.  Any of these commands could cause the process to proceed
1808    beyond this point, etc.  We look out for such changes by checking
1809    the global "breakpoint_proceeded" after each command.  */
1810
1811 void
1812 bpstat_do_actions (bsp)
1813      bpstat *bsp;
1814 {
1815   bpstat bs;
1816   struct cleanup *old_chain;
1817   struct command_line *cmd;
1818
1819   /* Avoid endless recursion if a `source' command is contained
1820      in bs->commands.  */
1821   if (executing_breakpoint_commands)
1822     return;
1823
1824   executing_breakpoint_commands = 1;
1825   old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1826
1827 top:
1828   /* Note that (as of this writing), our callers all appear to
1829      be passing us the address of global stop_bpstat.  And, if
1830      our calls to execute_control_command cause the inferior to
1831      proceed, that global (and hence, *bsp) will change.
1832
1833      We must be careful to not touch *bsp unless the inferior
1834      has not proceeded. */
1835
1836   /* This pointer will iterate over the list of bpstat's. */
1837   bs = *bsp;
1838
1839   breakpoint_proceeded = 0;
1840   for (; bs != NULL; bs = bs->next)
1841     {
1842       cmd = bs->commands;
1843       while (cmd != NULL)
1844         {
1845           execute_control_command (cmd);
1846
1847           if (breakpoint_proceeded)
1848             break;
1849           else
1850             cmd = cmd->next;
1851         }
1852       if (breakpoint_proceeded)
1853         /* The inferior is proceeded by the command; bomb out now.
1854            The bpstat chain has been blown away by wait_for_inferior.
1855            But since execution has stopped again, there is a new bpstat
1856            to look at, so start over.  */
1857         goto top;
1858       else
1859         bs->commands = NULL;
1860     }
1861
1862   executing_breakpoint_commands = 0;
1863   discard_cleanups (old_chain);
1864 }
1865
1866 /* This is the normal print function for a bpstat.  In the future,
1867    much of this logic could (should?) be moved to bpstat_stop_status,
1868    by having it set different print_it values.
1869
1870    Current scheme: When we stop, bpstat_print() is called.  It loops
1871    through the bpstat list of things causing this stop, calling the
1872    print_bp_stop_message function on each one. The behavior of the
1873    print_bp_stop_message function depends on the print_it field of
1874    bpstat. If such field so indicates, call this function here.
1875
1876    Return values from this routine (ultimately used by bpstat_print()
1877    and normal_stop() to decide what to do): 
1878    PRINT_NOTHING: Means we already printed all we needed to print,
1879    don't print anything else.
1880    PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1881    that something to be followed by a location.
1882    PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1883    that something to be followed by a location.
1884    PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1885    analysis.  */
1886
1887 static enum print_stop_action
1888 print_it_typical (bs)
1889      bpstat bs;
1890 {
1891   /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1892      which has since been deleted.  */
1893   if (bs->breakpoint_at == NULL)
1894     return PRINT_UNKNOWN;
1895
1896   switch (bs->breakpoint_at->type)
1897     {
1898     case bp_breakpoint:
1899     case bp_hardware_breakpoint:
1900       /* I think the user probably only wants to see one breakpoint
1901          number, not all of them.  */
1902       annotate_breakpoint (bs->breakpoint_at->number);
1903       printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1904       return PRINT_SRC_AND_LOC;
1905       break;
1906
1907     case bp_shlib_event:
1908       /* Did we stop because the user set the stop_on_solib_events
1909          variable?  (If so, we report this as a generic, "Stopped due
1910          to shlib event" message.) */
1911       printf_filtered ("Stopped due to shared library event\n");
1912       return PRINT_NOTHING;
1913       break;
1914
1915     case bp_thread_event:
1916       /* Not sure how we will get here. 
1917          GDB should not stop for these breakpoints.  */
1918       printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1919       return PRINT_NOTHING;
1920       break;
1921
1922     case bp_catch_load:
1923       annotate_catchpoint (bs->breakpoint_at->number);
1924       printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1925       printf_filtered ("loaded");
1926       printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1927       return PRINT_SRC_AND_LOC;
1928       break;
1929
1930     case bp_catch_unload:
1931       annotate_catchpoint (bs->breakpoint_at->number);
1932       printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1933       printf_filtered ("unloaded");
1934       printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1935       return PRINT_SRC_AND_LOC;
1936       break;
1937
1938     case bp_catch_fork:
1939       annotate_catchpoint (bs->breakpoint_at->number);
1940       printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1941       printf_filtered ("forked");
1942       printf_filtered (" process %d), ", 
1943                        bs->breakpoint_at->forked_inferior_pid);
1944       return PRINT_SRC_AND_LOC;
1945       break;
1946
1947     case bp_catch_vfork:
1948       annotate_catchpoint (bs->breakpoint_at->number);
1949       printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1950       printf_filtered ("vforked");
1951       printf_filtered (" process %d), ", 
1952                        bs->breakpoint_at->forked_inferior_pid);
1953       return PRINT_SRC_AND_LOC;
1954       break;
1955
1956     case bp_catch_exec:
1957       annotate_catchpoint (bs->breakpoint_at->number);
1958       printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1959                        bs->breakpoint_at->number,
1960                        bs->breakpoint_at->exec_pathname);
1961       return PRINT_SRC_AND_LOC;
1962       break;
1963
1964     case bp_catch_catch:
1965       if (current_exception_event && 
1966           (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1967         {
1968           annotate_catchpoint (bs->breakpoint_at->number);
1969           printf_filtered ("\nCatchpoint %d (exception caught), ", 
1970                            bs->breakpoint_at->number);
1971           printf_filtered ("throw location ");
1972           if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1973             printf_filtered ("%s:%d",
1974                              CURRENT_EXCEPTION_THROW_FILE,
1975                              CURRENT_EXCEPTION_THROW_LINE);
1976           else
1977             printf_filtered ("unknown");
1978
1979           printf_filtered (", catch location ");
1980           if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1981             printf_filtered ("%s:%d",
1982                              CURRENT_EXCEPTION_CATCH_FILE,
1983                              CURRENT_EXCEPTION_CATCH_LINE);
1984           else
1985             printf_filtered ("unknown");
1986
1987           printf_filtered ("\n");
1988           /* don't bother to print location frame info */
1989           return PRINT_SRC_ONLY;
1990         }
1991       else
1992         {
1993           /* really throw, some other bpstat will handle it */
1994           return PRINT_UNKNOWN; 
1995         }
1996       break;
1997
1998     case bp_catch_throw:
1999       if (current_exception_event && 
2000           (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2001         {
2002           annotate_catchpoint (bs->breakpoint_at->number);
2003           printf_filtered ("\nCatchpoint %d (exception thrown), ",
2004                            bs->breakpoint_at->number);
2005           printf_filtered ("throw location ");
2006           if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2007             printf_filtered ("%s:%d",
2008                              CURRENT_EXCEPTION_THROW_FILE,
2009                              CURRENT_EXCEPTION_THROW_LINE);
2010           else
2011             printf_filtered ("unknown");
2012
2013           printf_filtered (", catch location ");
2014           if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2015             printf_filtered ("%s:%d",
2016                              CURRENT_EXCEPTION_CATCH_FILE,
2017                              CURRENT_EXCEPTION_CATCH_LINE);
2018           else
2019             printf_filtered ("unknown");
2020
2021           printf_filtered ("\n");
2022           /* don't bother to print location frame info */
2023           return PRINT_SRC_ONLY; 
2024         }
2025       else
2026         {
2027           /* really catch, some other bpstat will handle it */
2028           return PRINT_UNKNOWN; 
2029         }
2030       break;
2031
2032     case bp_watchpoint:
2033     case bp_hardware_watchpoint:
2034       if (bs->old_val != NULL)
2035         {
2036           annotate_watchpoint (bs->breakpoint_at->number);
2037           mention (bs->breakpoint_at);
2038           printf_filtered ("\nOld value = ");
2039           value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2040           printf_filtered ("\nNew value = ");
2041           value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2042                        Val_pretty_default);
2043           printf_filtered ("\n");
2044           value_free (bs->old_val);
2045           bs->old_val = NULL;
2046         }
2047       /* More than one watchpoint may have been triggered.  */
2048       return PRINT_UNKNOWN;
2049       break;
2050
2051     case bp_read_watchpoint:
2052       mention (bs->breakpoint_at);
2053       printf_filtered ("\nValue = ");
2054       value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2055                    Val_pretty_default);
2056       printf_filtered ("\n");
2057       return PRINT_UNKNOWN;
2058       break;
2059
2060     case bp_access_watchpoint:
2061       if (bs->old_val != NULL)     
2062         {
2063           annotate_watchpoint (bs->breakpoint_at->number);
2064           mention (bs->breakpoint_at);
2065           printf_filtered ("\nOld value = ");
2066           value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2067           value_free (bs->old_val);
2068           bs->old_val = NULL;
2069           printf_filtered ("\nNew value = ");
2070         }
2071       else 
2072         {
2073           mention (bs->breakpoint_at);
2074           printf_filtered ("\nValue = ");
2075         }
2076       value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2077                    Val_pretty_default);
2078       printf_filtered ("\n");
2079       return PRINT_UNKNOWN;
2080       break;
2081
2082     /* Fall through, we don't deal with these types of breakpoints
2083        here. */
2084
2085     case bp_finish:
2086     case bp_until:
2087     case bp_none:
2088     case bp_longjmp:
2089     case bp_longjmp_resume:
2090     case bp_step_resume:
2091     case bp_through_sigtramp:
2092     case bp_watchpoint_scope:
2093     case bp_call_dummy:
2094     default:
2095       return PRINT_UNKNOWN;
2096     }
2097 }
2098
2099 /* Generic routine for printing messages indicating why we
2100    stopped. The behavior of this function depends on the value
2101    'print_it' in the bpstat structure.  Under some circumstances we
2102    may decide not to print anything here and delegate the task to
2103    normal_stop(). */
2104
2105 static enum print_stop_action
2106 print_bp_stop_message (bpstat bs)
2107 {
2108   switch (bs->print_it)
2109     {
2110     case print_it_noop:
2111       /* Nothing should be printed for this bpstat entry. */
2112       return PRINT_UNKNOWN;
2113       break;
2114
2115     case print_it_done:
2116       /* We still want to print the frame, but we already printed the
2117          relevant messages. */
2118       return PRINT_SRC_AND_LOC;
2119       break;
2120
2121     case print_it_normal:
2122       /* Normal case, we handle everything in print_it_typical. */
2123       return print_it_typical (bs);
2124       break;
2125     default:
2126       internal_error ("print_bp_stop_message: unrecognized enum value");
2127       break;
2128     }
2129 }
2130
2131 /* Print a message indicating what happened.  This is called from
2132    normal_stop().  The input to this routine is the head of the bpstat
2133    list - a list of the eventpoints that caused this stop.  This
2134    routine calls the generic print routine for printing a message
2135    about reasons for stopping.  This will print (for example) the
2136    "Breakpoint n," part of the output.  The return value of this
2137    routine is one of:
2138
2139    PRINT_UNKNOWN: Means we printed nothing
2140    PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2141    code to print the location. An example is 
2142    "Breakpoint 1, " which should be followed by
2143    the location.
2144    PRINT_SRC_ONLY: Means we printed something, but there is no need
2145    to also print the location part of the message.
2146    An example is the catch/throw messages, which
2147    don't require a location appended to the end.  
2148    PRINT_NOTHING: We have done some printing and we don't need any 
2149    further info to be printed.*/
2150
2151 enum print_stop_action
2152 bpstat_print (bs)
2153      bpstat bs;
2154 {
2155   int val;
2156
2157   /* Maybe another breakpoint in the chain caused us to stop.
2158      (Currently all watchpoints go on the bpstat whether hit or not.
2159      That probably could (should) be changed, provided care is taken
2160      with respect to bpstat_explains_signal).  */
2161   for (; bs; bs = bs->next)
2162     {
2163       val = print_bp_stop_message (bs);
2164       if (val == PRINT_SRC_ONLY 
2165           || val == PRINT_SRC_AND_LOC 
2166           || val == PRINT_NOTHING)
2167         return val;
2168     }
2169
2170   /* We reached the end of the chain, or we got a null BS to start
2171      with and nothing was printed. */
2172   return PRINT_UNKNOWN;
2173 }
2174
2175 /* Evaluate the expression EXP and return 1 if value is zero.
2176    This is used inside a catch_errors to evaluate the breakpoint condition. 
2177    The argument is a "struct expression *" that has been cast to char * to 
2178    make it pass through catch_errors.  */
2179
2180 static int
2181 breakpoint_cond_eval (exp)
2182      PTR exp;
2183 {
2184   value_ptr mark = value_mark ();
2185   int i = !value_true (evaluate_expression ((struct expression *) exp));
2186   value_free_to_mark (mark);
2187   return i;
2188 }
2189
2190 /* Allocate a new bpstat and chain it to the current one.  */
2191
2192 static bpstat
2193 bpstat_alloc (b, cbs)
2194      register struct breakpoint *b;
2195      bpstat cbs;                /* Current "bs" value */
2196 {
2197   bpstat bs;
2198
2199   bs = (bpstat) xmalloc (sizeof (*bs));
2200   cbs->next = bs;
2201   bs->breakpoint_at = b;
2202   /* If the condition is false, etc., don't do the commands.  */
2203   bs->commands = NULL;
2204   bs->old_val = NULL;
2205   bs->print_it = print_it_normal;
2206   return bs;
2207 }
2208 \f
2209 /* Possible return values for watchpoint_check (this can't be an enum
2210    because of check_errors).  */
2211 /* The watchpoint has been deleted.  */
2212 #define WP_DELETED 1
2213 /* The value has changed.  */
2214 #define WP_VALUE_CHANGED 2
2215 /* The value has not changed.  */
2216 #define WP_VALUE_NOT_CHANGED 3
2217
2218 #define BP_TEMPFLAG 1
2219 #define BP_HARDWAREFLAG 2
2220
2221 /* Check watchpoint condition.  */
2222
2223 static int
2224 watchpoint_check (p)
2225      PTR p;
2226 {
2227   bpstat bs = (bpstat) p;
2228   struct breakpoint *b;
2229   struct frame_info *fr;
2230   int within_current_scope;
2231
2232   b = bs->breakpoint_at;
2233
2234   if (b->exp_valid_block == NULL)
2235     within_current_scope = 1;
2236   else
2237     {
2238       /* There is no current frame at this moment.  If we're going to have
2239          any chance of handling watchpoints on local variables, we'll need
2240          the frame chain (so we can determine if we're in scope).  */
2241       reinit_frame_cache ();
2242       fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2243       within_current_scope = (fr != NULL);
2244       if (within_current_scope)
2245         /* If we end up stopping, the current frame will get selected
2246            in normal_stop.  So this call to select_frame won't affect
2247            the user.  */
2248         select_frame (fr, -1);
2249     }
2250
2251   if (within_current_scope)
2252     {
2253       /* We use value_{,free_to_}mark because it could be a
2254          *long* time before we return to the command level and
2255          call free_all_values.  We can't call free_all_values because
2256          we might be in the middle of evaluating a function call.  */
2257
2258       value_ptr mark = value_mark ();
2259       value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2260       if (!value_equal (b->val, new_val))
2261         {
2262           release_value (new_val);
2263           value_free_to_mark (mark);
2264           bs->old_val = b->val;
2265           b->val = new_val;
2266           /* We will stop here */
2267           return WP_VALUE_CHANGED;
2268         }
2269       else
2270         {
2271           /* Nothing changed, don't do anything.  */
2272           value_free_to_mark (mark);
2273           /* We won't stop here */
2274           return WP_VALUE_NOT_CHANGED;
2275         }
2276     }
2277   else
2278     {
2279       /* This seems like the only logical thing to do because
2280          if we temporarily ignored the watchpoint, then when
2281          we reenter the block in which it is valid it contains
2282          garbage (in the case of a function, it may have two
2283          garbage values, one before and one after the prologue).
2284          So we can't even detect the first assignment to it and
2285          watch after that (since the garbage may or may not equal
2286          the first value assigned).  */
2287       /* We print all the stop information in print_it_typical(), but
2288          in this case, by the time we call print_it_typical() this bp
2289          will be deleted already. So we have no choice but print the
2290          information here. */
2291       printf_filtered ("\
2292 Watchpoint %d deleted because the program has left the block in\n\
2293 which its expression is valid.\n", bs->breakpoint_at->number);
2294
2295       if (b->related_breakpoint)
2296         b->related_breakpoint->disposition = del_at_next_stop;
2297       b->disposition = del_at_next_stop;
2298
2299       return WP_DELETED;
2300     }
2301 }
2302
2303 /* Get a bpstat associated with having just stopped at address *PC
2304    and frame address CORE_ADDRESS.  Update *PC to point at the
2305    breakpoint (if we hit a breakpoint).  NOT_A_BREAKPOINT is nonzero
2306    if this is known to not be a real breakpoint (it could still be a
2307    watchpoint, though).  */
2308
2309 /* Determine whether we stopped at a breakpoint, etc, or whether we
2310    don't understand this stop.  Result is a chain of bpstat's such that:
2311
2312    if we don't understand the stop, the result is a null pointer.
2313
2314    if we understand why we stopped, the result is not null.
2315
2316    Each element of the chain refers to a particular breakpoint or
2317    watchpoint at which we have stopped.  (We may have stopped for
2318    several reasons concurrently.)
2319
2320    Each element of the chain has valid next, breakpoint_at,
2321    commands, FIXME??? fields.  */
2322
2323 bpstat
2324 bpstat_stop_status (pc, not_a_breakpoint)
2325      CORE_ADDR *pc;
2326      int not_a_breakpoint;
2327 {
2328   register struct breakpoint *b, *temp;
2329   CORE_ADDR bp_addr;
2330   /* True if we've hit a breakpoint (as opposed to a watchpoint).  */
2331   int real_breakpoint = 0;
2332   /* Root of the chain of bpstat's */
2333   struct bpstats root_bs[1];
2334   /* Pointer to the last thing in the chain currently.  */
2335   bpstat bs = root_bs;
2336   static char message1[] =
2337   "Error evaluating expression for watchpoint %d\n";
2338   char message[sizeof (message1) + 30 /* slop */ ];
2339
2340   /* Get the address where the breakpoint would have been.  */
2341   bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ? 
2342                    0 : DECR_PC_AFTER_BREAK);
2343
2344   ALL_BREAKPOINTS_SAFE (b, temp)
2345   {
2346     if (b->enable == disabled
2347         || b->enable == shlib_disabled
2348         || b->enable == call_disabled)
2349       continue;
2350
2351     if (b->type != bp_watchpoint
2352         && b->type != bp_hardware_watchpoint
2353         && b->type != bp_read_watchpoint
2354         && b->type != bp_access_watchpoint
2355         && b->type != bp_hardware_breakpoint
2356         && b->type != bp_catch_fork
2357         && b->type != bp_catch_vfork
2358         && b->type != bp_catch_exec
2359         && b->type != bp_catch_catch
2360         && b->type != bp_catch_throw)   /* a non-watchpoint bp */
2361       if (b->address != bp_addr ||      /* address doesn't match or */
2362           (overlay_debugging && /* overlay doesn't match */
2363            section_is_overlay (b->section) &&
2364            !section_is_mapped (b->section)))
2365         continue;
2366
2367     if (b->type == bp_hardware_breakpoint
2368         && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2369       continue;
2370
2371     /* Is this a catchpoint of a load or unload?  If so, did we
2372        get a load or unload of the specified library?  If not,
2373        ignore it. */
2374     if ((b->type == bp_catch_load)
2375 #if defined(SOLIB_HAVE_LOAD_EVENT)
2376         && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2377             || ((b->dll_pathname != NULL)
2378                 && (strcmp (b->dll_pathname, 
2379                             SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid)) 
2380                     != 0)))
2381 #endif
2382       )
2383       continue;
2384
2385     if ((b->type == bp_catch_unload)
2386 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2387         && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2388             || ((b->dll_pathname != NULL)
2389                 && (strcmp (b->dll_pathname, 
2390                             SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid)) 
2391                     != 0)))
2392 #endif
2393       )
2394       continue;
2395
2396     if ((b->type == bp_catch_fork)
2397         && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2398       continue;
2399
2400     if ((b->type == bp_catch_vfork)
2401         && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2402       continue;
2403
2404     if ((b->type == bp_catch_exec)
2405         && !target_has_execd (inferior_pid, &b->exec_pathname))
2406       continue;
2407
2408     if (ep_is_exception_catchpoint (b) &&
2409         !(current_exception_event = target_get_current_exception_event ()))
2410       continue;
2411
2412     /* Come here if it's a watchpoint, or if the break address matches */
2413
2414     bs = bpstat_alloc (b, bs);  /* Alloc a bpstat to explain stop */
2415
2416     /* Watchpoints may change this, if not found to have triggered. */
2417     bs->stop = 1;
2418     bs->print = 1;
2419
2420     sprintf (message, message1, b->number);
2421     if (b->type == bp_watchpoint ||
2422         b->type == bp_hardware_watchpoint)
2423       {
2424         switch (catch_errors (watchpoint_check, bs, message, 
2425                               RETURN_MASK_ALL))
2426           {
2427           case WP_DELETED:
2428             /* We've already printed what needs to be printed.  */
2429             /* Actually this is superfluous, because by the time we
2430                call print_it_typical() the wp will be already deleted,
2431                and the function will return immediately. */
2432             bs->print_it = print_it_done;
2433             /* Stop.  */
2434             break;
2435           case WP_VALUE_CHANGED:
2436             /* Stop.  */
2437             ++(b->hit_count);
2438             break;
2439           case WP_VALUE_NOT_CHANGED:
2440             /* Don't stop.  */
2441             bs->print_it = print_it_noop;
2442             bs->stop = 0;
2443             continue;
2444           default:
2445             /* Can't happen.  */
2446             /* FALLTHROUGH */
2447           case 0:
2448             /* Error from catch_errors.  */
2449             printf_filtered ("Watchpoint %d deleted.\n", b->number);
2450             if (b->related_breakpoint)
2451               b->related_breakpoint->disposition = del_at_next_stop;
2452             b->disposition = del_at_next_stop;
2453             /* We've already printed what needs to be printed.  */
2454             bs->print_it = print_it_done;
2455
2456             /* Stop.  */
2457             break;
2458           }
2459       }
2460     else if (b->type == bp_read_watchpoint || 
2461              b->type == bp_access_watchpoint)
2462       {
2463         CORE_ADDR addr;
2464         value_ptr v;
2465         int found = 0;
2466
2467         addr = target_stopped_data_address ();
2468         if (addr == 0)
2469           continue;
2470         for (v = b->val_chain; v; v = v->next)
2471           {
2472             if (VALUE_LVAL (v) == lval_memory
2473                 && ! VALUE_LAZY (v))
2474               {
2475                 CORE_ADDR vaddr;
2476
2477                 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2478                 /* Exact match not required.  Within range is sufficient.  
2479                  */
2480                 if (addr >= vaddr &&
2481                     addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2482                   found = 1;
2483               }
2484           }
2485         if (found)
2486           switch (catch_errors (watchpoint_check, bs, message,
2487                                 RETURN_MASK_ALL))
2488             {
2489             case WP_DELETED:
2490               /* We've already printed what needs to be printed.  */
2491               bs->print_it = print_it_done;
2492               /* Stop.  */
2493               break;
2494             case WP_VALUE_CHANGED:
2495             case WP_VALUE_NOT_CHANGED:
2496               /* Stop.  */
2497               ++(b->hit_count);
2498               break;
2499             default:
2500               /* Can't happen.  */
2501             case 0:
2502               /* Error from catch_errors.  */
2503               printf_filtered ("Watchpoint %d deleted.\n", b->number);
2504               if (b->related_breakpoint)
2505                 b->related_breakpoint->disposition = del_at_next_stop;
2506               b->disposition = del_at_next_stop;
2507               /* We've already printed what needs to be printed.  */
2508               bs->print_it = print_it_done;
2509               break;
2510             }
2511         else    /* found == 0 */
2512           {
2513             /* This is a case where some watchpoint(s) triggered,
2514                but not at the address of this watchpoint (FOUND
2515                was left zero).  So don't print anything for this
2516                watchpoint.  */
2517             bs->print_it = print_it_noop;
2518             bs->stop = 0;
2519             continue;
2520           }
2521       }
2522     else
2523       {
2524         /* By definition, an encountered breakpoint is a triggered
2525            breakpoint. */
2526         ++(b->hit_count);
2527
2528         real_breakpoint = 1;
2529       }
2530
2531     if (b->frame && b->frame != (get_current_frame ())->frame &&
2532         (b->type == bp_step_resume &&
2533          (INNER_THAN (get_current_frame ()->frame, b->frame))))
2534       bs->stop = 0;
2535     else
2536       {
2537         int value_is_zero = 0;
2538
2539         if (b->cond)
2540           {
2541             /* Need to select the frame, with all that implies
2542                so that the conditions will have the right context.  */
2543             select_frame (get_current_frame (), 0);
2544             value_is_zero
2545               = catch_errors (breakpoint_cond_eval, (b->cond),
2546                               "Error in testing breakpoint condition:\n",
2547                               RETURN_MASK_ALL);
2548             /* FIXME-someday, should give breakpoint # */
2549             free_all_values ();
2550           }
2551         if (b->cond && value_is_zero)
2552           {
2553             bs->stop = 0;
2554             /* Don't consider this a hit.  */
2555             --(b->hit_count);
2556           }
2557         else if (b->ignore_count > 0)
2558           {
2559             b->ignore_count--;
2560             annotate_ignore_count_change ();
2561             bs->stop = 0;
2562           }
2563         else
2564           {
2565             /* We will stop here */
2566             if (b->disposition == disable)
2567               b->enable = disabled;
2568             bs->commands = b->commands;
2569             if (b->silent)
2570               bs->print = 0;
2571             if (bs->commands &&
2572                 (STREQ ("silent", bs->commands->line) ||
2573                  (xdb_commands && STREQ ("Q", bs->commands->line))))
2574               {
2575                 bs->commands = bs->commands->next;
2576                 bs->print = 0;
2577               }
2578           }
2579       }
2580     /* Print nothing for this entry if we dont stop or if we dont print.  */
2581     if (bs->stop == 0 || bs->print == 0)
2582       bs->print_it = print_it_noop;
2583   }
2584
2585   bs->next = NULL;              /* Terminate the chain */
2586   bs = root_bs->next;           /* Re-grab the head of the chain */
2587
2588   if (real_breakpoint && bs)
2589     {
2590       if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2591         {
2592           if (DECR_PC_AFTER_HW_BREAK != 0)
2593             {
2594               *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2595               write_pc (*pc);
2596             }
2597         }
2598       else
2599         {
2600           if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2601             {
2602               *pc = bp_addr;
2603 #if defined (SHIFT_INST_REGS)
2604               SHIFT_INST_REGS ();
2605 #else /* No SHIFT_INST_REGS.  */
2606               write_pc (bp_addr);
2607 #endif /* No SHIFT_INST_REGS.  */
2608             }
2609         }
2610     }
2611
2612   /* The value of a hardware watchpoint hasn't changed, but the
2613      intermediate memory locations we are watching may have.  */
2614   if (bs && !bs->stop &&
2615       (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2616        bs->breakpoint_at->type == bp_read_watchpoint ||
2617        bs->breakpoint_at->type == bp_access_watchpoint))
2618     {
2619       remove_breakpoints ();
2620       insert_breakpoints ();
2621     }
2622   return bs;
2623 }
2624 \f
2625 /* Tell what to do about this bpstat.  */
2626 struct bpstat_what
2627 bpstat_what (bs)
2628      bpstat bs;
2629 {
2630   /* Classify each bpstat as one of the following.  */
2631   enum class
2632     {
2633       /* This bpstat element has no effect on the main_action.  */
2634       no_effect = 0,
2635
2636       /* There was a watchpoint, stop but don't print.  */
2637       wp_silent,
2638
2639       /* There was a watchpoint, stop and print.  */
2640       wp_noisy,
2641
2642       /* There was a breakpoint but we're not stopping.  */
2643       bp_nostop,
2644
2645       /* There was a breakpoint, stop but don't print.  */
2646       bp_silent,
2647
2648       /* There was a breakpoint, stop and print.  */
2649       bp_noisy,
2650
2651       /* We hit the longjmp breakpoint.  */
2652       long_jump,
2653
2654       /* We hit the longjmp_resume breakpoint.  */
2655       long_resume,
2656
2657       /* We hit the step_resume breakpoint.  */
2658       step_resume,
2659
2660       /* We hit the through_sigtramp breakpoint.  */
2661       through_sig,
2662
2663       /* We hit the shared library event breakpoint.  */
2664       shlib_event,
2665
2666       /* We caught a shared library event.  */
2667       catch_shlib_event,
2668
2669       /* This is just used to count how many enums there are.  */
2670       class_last
2671     };
2672
2673   /* Here is the table which drives this routine.  So that we can
2674      format it pretty, we define some abbreviations for the
2675      enum bpstat_what codes.  */
2676 #define kc BPSTAT_WHAT_KEEP_CHECKING
2677 #define ss BPSTAT_WHAT_STOP_SILENT
2678 #define sn BPSTAT_WHAT_STOP_NOISY
2679 #define sgl BPSTAT_WHAT_SINGLE
2680 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2681 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2682 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2683 #define sr BPSTAT_WHAT_STEP_RESUME
2684 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2685 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2686 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2687
2688 /* "Can't happen."  Might want to print an error message.
2689    abort() is not out of the question, but chances are GDB is just
2690    a bit confused, not unusable.  */
2691 #define err BPSTAT_WHAT_STOP_NOISY
2692
2693   /* Given an old action and a class, come up with a new action.  */
2694   /* One interesting property of this table is that wp_silent is the same
2695      as bp_silent and wp_noisy is the same as bp_noisy.  That is because
2696      after stopping, the check for whether to step over a breakpoint
2697      (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2698      reference to how we stopped.  We retain separate wp_silent and
2699      bp_silent codes in case we want to change that someday. 
2700
2701      Another possibly interesting property of this table is that
2702      there's a partial ordering, priority-like, of the actions.  Once
2703      you've decided that some action is appropriate, you'll never go
2704      back and decide something of a lower priority is better.  The
2705      ordering is:
2706
2707      kc   < clr sgl shl slr sn sr ss ts
2708      sgl  < clrs shl shlr slr sn sr ss ts
2709      slr  < err shl shlr sn sr ss ts
2710      clr  < clrs err shl shlr sn sr ss ts
2711      clrs < err shl shlr sn sr ss ts
2712      ss   < shl shlr sn sr ts
2713      sn   < shl shlr sr ts
2714      sr   < shl shlr ts
2715      shl  < shlr
2716      ts   < 
2717      shlr <
2718
2719      What I think this means is that we don't need a damned table
2720      here.  If you just put the rows and columns in the right order,
2721      it'd look awfully regular.  We could simply walk the bpstat list
2722      and choose the highest priority action we find, with a little
2723      logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2724      CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2725      is messy anyway).  */
2726
2727   /* step_resume entries: a step resume breakpoint overrides another
2728      breakpoint of signal handling (see comment in wait_for_inferior
2729      at first IN_SIGTRAMP where we set the step_resume breakpoint).  */
2730   /* We handle the through_sigtramp_breakpoint the same way; having both
2731      one of those and a step_resume_breakpoint is probably very rare (?).  */
2732
2733   static const enum bpstat_what_main_action
2734     table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2735   {
2736   /*                              old action */
2737   /*       kc    ss    sn    sgl    slr   clr    clrs   sr    ts   shl   shlr
2738    */
2739 /*no_effect */
2740     {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2741 /*wp_silent */
2742     {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2743 /*wp_noisy */
2744     {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2745 /*bp_nostop */
2746     {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2747 /*bp_silent */
2748     {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2749 /*bp_noisy */
2750     {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2751 /*long_jump */
2752     {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2753 /*long_resume */
2754     {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2755 /*step_resume */
2756     {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2757 /*through_sig */
2758     {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2759 /*shlib */
2760     {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2761 /*catch_shlib */
2762     {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2763   };
2764
2765 #undef kc
2766 #undef ss
2767 #undef sn
2768 #undef sgl
2769 #undef slr
2770 #undef clr
2771 #undef clrs
2772 #undef err
2773 #undef sr
2774 #undef ts
2775 #undef shl
2776 #undef shlr
2777   enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2778   struct bpstat_what retval;
2779
2780   retval.call_dummy = 0;
2781   for (; bs != NULL; bs = bs->next)
2782     {
2783       enum class bs_class = no_effect;
2784       if (bs->breakpoint_at == NULL)
2785         /* I suspect this can happen if it was a momentary breakpoint
2786            which has since been deleted.  */
2787         continue;
2788       switch (bs->breakpoint_at->type)
2789         {
2790         case bp_none:
2791           continue;
2792
2793         case bp_breakpoint:
2794         case bp_hardware_breakpoint:
2795         case bp_until:
2796         case bp_finish:
2797           if (bs->stop)
2798             {
2799               if (bs->print)
2800                 bs_class = bp_noisy;
2801               else
2802                 bs_class = bp_silent;
2803             }
2804           else
2805             bs_class = bp_nostop;
2806           break;
2807         case bp_watchpoint:
2808         case bp_hardware_watchpoint:
2809         case bp_read_watchpoint:
2810         case bp_access_watchpoint:
2811           if (bs->stop)
2812             {
2813               if (bs->print)
2814                 bs_class = wp_noisy;
2815               else
2816                 bs_class = wp_silent;
2817             }
2818           else
2819             /* There was a watchpoint, but we're not stopping. 
2820                This requires no further action.  */
2821             bs_class = no_effect;
2822           break;
2823         case bp_longjmp:
2824           bs_class = long_jump;
2825           break;
2826         case bp_longjmp_resume:
2827           bs_class = long_resume;
2828           break;
2829         case bp_step_resume:
2830           if (bs->stop)
2831             {
2832               bs_class = step_resume;
2833             }
2834           else
2835             /* It is for the wrong frame.  */
2836             bs_class = bp_nostop;
2837           break;
2838         case bp_through_sigtramp:
2839           bs_class = through_sig;
2840           break;
2841         case bp_watchpoint_scope:
2842           bs_class = bp_nostop;
2843           break;
2844         case bp_shlib_event:
2845           bs_class = shlib_event;
2846           break;
2847         case bp_thread_event:
2848           bs_class = bp_nostop;
2849           break;
2850         case bp_catch_load:
2851         case bp_catch_unload:
2852           /* Only if this catchpoint triggered should we cause the
2853              step-out-of-dld behaviour.  Otherwise, we ignore this
2854              catchpoint.  */
2855           if (bs->stop)
2856             bs_class = catch_shlib_event;
2857           else
2858             bs_class = no_effect;
2859           break;
2860         case bp_catch_fork:
2861         case bp_catch_vfork:
2862         case bp_catch_exec:
2863           if (bs->stop)
2864             {
2865               if (bs->print)
2866                 bs_class = bp_noisy;
2867               else
2868                 bs_class = bp_silent;
2869             }
2870           else
2871             /* There was a catchpoint, but we're not stopping.  
2872                This requires no further action.  */
2873             bs_class = no_effect;
2874           break;
2875         case bp_catch_catch:
2876           if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2877             bs_class = bp_nostop;
2878           else if (bs->stop)
2879             bs_class = bs->print ? bp_noisy : bp_silent;
2880           break;
2881         case bp_catch_throw:
2882           if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2883             bs_class = bp_nostop;
2884           else if (bs->stop)
2885             bs_class = bs->print ? bp_noisy : bp_silent;
2886           break;
2887         case bp_call_dummy:
2888           /* Make sure the action is stop (silent or noisy),
2889              so infrun.c pops the dummy frame.  */
2890           bs_class = bp_silent;
2891           retval.call_dummy = 1;
2892           break;
2893         }
2894       current_action = table[(int) bs_class][(int) current_action];
2895     }
2896   retval.main_action = current_action;
2897   return retval;
2898 }
2899
2900 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2901    without hardware support).  This isn't related to a specific bpstat,
2902    just to things like whether watchpoints are set.  */
2903
2904 int
2905 bpstat_should_step ()
2906 {
2907   struct breakpoint *b;
2908   ALL_BREAKPOINTS (b)
2909     if (b->enable == enabled && b->type == bp_watchpoint)
2910     return 1;
2911   return 0;
2912 }
2913
2914 /* Nonzero if there are enabled hardware watchpoints. */
2915 int
2916 bpstat_have_active_hw_watchpoints ()
2917 {
2918   struct breakpoint *b;
2919   ALL_BREAKPOINTS (b)
2920     if ((b->enable == enabled) &&
2921         (b->inserted) &&
2922         ((b->type == bp_hardware_watchpoint) ||
2923          (b->type == bp_read_watchpoint) ||
2924          (b->type == bp_access_watchpoint)))
2925     return 1;
2926   return 0;
2927 }
2928 \f
2929
2930 /* Given a bpstat that records zero or more triggered eventpoints, this
2931    function returns another bpstat which contains only the catchpoints
2932    on that first list, if any. */
2933 void
2934 bpstat_get_triggered_catchpoints (ep_list, cp_list)
2935      bpstat ep_list;
2936      bpstat *cp_list;
2937 {
2938   struct bpstats root_bs[1];
2939   bpstat bs = root_bs;
2940   struct breakpoint *ep;
2941   char *dll_pathname;
2942
2943   bpstat_clear (cp_list);
2944   root_bs->next = NULL;
2945
2946   for (; ep_list != NULL; ep_list = ep_list->next)
2947     {
2948       /* Is this eventpoint a catchpoint?  If not, ignore it. */
2949       ep = ep_list->breakpoint_at;
2950       if (ep == NULL)
2951         break;
2952       if ((ep->type != bp_catch_load) &&
2953           (ep->type != bp_catch_unload) &&
2954           (ep->type != bp_catch_catch) &&
2955           (ep->type != bp_catch_throw))         
2956         /* pai: (temp) ADD fork/vfork here!!  */
2957         continue;
2958
2959       /* Yes; add it to the list. */
2960       bs = bpstat_alloc (ep, bs);
2961       *bs = *ep_list;
2962       bs->next = NULL;
2963       bs = root_bs->next;
2964
2965 #if defined(SOLIB_ADD)
2966       /* Also, for each triggered catchpoint, tag it with the name of
2967          the library that caused this trigger.  (We copy the name now,
2968          because it's only guaranteed to be available NOW, when the
2969          catchpoint triggers.  Clients who may wish to know the name
2970          later must get it from the catchpoint itself.) */
2971       if (ep->triggered_dll_pathname != NULL)
2972         free (ep->triggered_dll_pathname);
2973       if (ep->type == bp_catch_load)
2974         dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
2975       else
2976         dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
2977 #else
2978       dll_pathname = NULL;
2979 #endif
2980       if (dll_pathname)
2981         {
2982           ep->triggered_dll_pathname = (char *) 
2983             xmalloc (strlen (dll_pathname) + 1);
2984           strcpy (ep->triggered_dll_pathname, dll_pathname);
2985         }
2986       else
2987         ep->triggered_dll_pathname = NULL;
2988     }
2989
2990   *cp_list = bs;
2991 }
2992
2993 /* Print B to gdb_stdout. */
2994 static void
2995 print_one_breakpoint (struct breakpoint *b,
2996                       CORE_ADDR *last_addr)
2997 {
2998   register struct command_line *l;
2999   register struct symbol *sym;
3000   struct ep_type_description
3001     {
3002       enum bptype type;
3003       char *description;
3004     };
3005   static struct ep_type_description bptypes[] =
3006   {
3007     {bp_none, "?deleted?"},
3008     {bp_breakpoint, "breakpoint"},
3009     {bp_hardware_breakpoint, "hw breakpoint"},
3010     {bp_until, "until"},
3011     {bp_finish, "finish"},
3012     {bp_watchpoint, "watchpoint"},
3013     {bp_hardware_watchpoint, "hw watchpoint"},
3014     {bp_read_watchpoint, "read watchpoint"},
3015     {bp_access_watchpoint, "acc watchpoint"},
3016     {bp_longjmp, "longjmp"},
3017     {bp_longjmp_resume, "longjmp resume"},
3018     {bp_step_resume, "step resume"},
3019     {bp_through_sigtramp, "sigtramp"},
3020     {bp_watchpoint_scope, "watchpoint scope"},
3021     {bp_call_dummy, "call dummy"},
3022     {bp_shlib_event, "shlib events"},
3023     {bp_thread_event, "thread events"},
3024     {bp_catch_load, "catch load"},
3025     {bp_catch_unload, "catch unload"},
3026     {bp_catch_fork, "catch fork"},
3027     {bp_catch_vfork, "catch vfork"},
3028     {bp_catch_exec, "catch exec"},
3029     {bp_catch_catch, "catch catch"},
3030     {bp_catch_throw, "catch throw"}
3031   };
3032   
3033   static char *bpdisps[] =
3034   {"del", "dstp", "dis", "keep"};
3035   static char bpenables[] = "nynny";
3036   char wrap_indent[80];
3037
3038   annotate_record ();
3039
3040   /* 1 */
3041   annotate_field (0);
3042   printf_filtered ("%-3d ", b->number);
3043
3044   /* 2 */
3045   annotate_field (1);
3046   if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3047       || ((int) b->type != bptypes[(int) b->type].type))
3048     internal_error ("bptypes table does not describe type #%d.",
3049                     (int) b->type);
3050   printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3051
3052   /* 3 */
3053   annotate_field (2);
3054   printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3055
3056   /* 4 */
3057   annotate_field (3);
3058   printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3059   
3060   /* 5 and 6 */
3061   strcpy (wrap_indent, "                           ");
3062   if (addressprint)
3063     strcat (wrap_indent, "           ");
3064   switch (b->type)
3065     {
3066     case bp_none:
3067       internal_error ("print_one_breakpoint: bp_none encountered\n");
3068       break;
3069
3070     case bp_watchpoint:
3071     case bp_hardware_watchpoint:
3072     case bp_read_watchpoint:
3073     case bp_access_watchpoint:
3074       /* Field 4, the address, is omitted (which makes the columns
3075          not line up too nicely with the headers, but the effect
3076          is relatively readable).  */
3077       annotate_field (5);
3078       print_expression (b->exp, gdb_stdout);
3079       break;
3080       
3081     case bp_catch_load:
3082     case bp_catch_unload:
3083       /* Field 4, the address, is omitted (which makes the columns
3084          not line up too nicely with the headers, but the effect
3085          is relatively readable).  */
3086       annotate_field (5);
3087       if (b->dll_pathname == NULL)
3088         printf_filtered ("<any library> ");
3089       else
3090         printf_filtered ("library \"%s\" ", b->dll_pathname);
3091       break;
3092       
3093     case bp_catch_fork:
3094     case bp_catch_vfork:
3095       /* Field 4, the address, is omitted (which makes the columns
3096          not line up too nicely with the headers, but the effect
3097          is relatively readable).  */
3098       annotate_field (5);
3099       if (b->forked_inferior_pid != 0)
3100         printf_filtered ("process %d ", b->forked_inferior_pid);
3101       break;
3102       
3103     case bp_catch_exec:
3104       /* Field 4, the address, is omitted (which makes the columns
3105          not line up too nicely with the headers, but the effect
3106          is relatively readable).  */
3107       annotate_field (5);
3108       if (b->exec_pathname != NULL)
3109         printf_filtered ("program \"%s\" ", b->exec_pathname);
3110       break;
3111
3112     case bp_catch_catch:
3113       /* Field 4, the address, is omitted (which makes the columns
3114          not line up too nicely with the headers, but the effect
3115          is relatively readable).  */
3116       annotate_field (5);
3117       printf_filtered ("exception catch ");
3118       break;
3119
3120     case bp_catch_throw:
3121       /* Field 4, the address, is omitted (which makes the columns
3122          not line up too nicely with the headers, but the effect
3123          is relatively readable).  */
3124       annotate_field (5);
3125       printf_filtered ("exception throw ");
3126       break;
3127       
3128     case bp_breakpoint:
3129     case bp_hardware_breakpoint:
3130     case bp_until:
3131     case bp_finish:
3132     case bp_longjmp:
3133     case bp_longjmp_resume:
3134     case bp_step_resume:
3135     case bp_through_sigtramp:
3136     case bp_watchpoint_scope:
3137     case bp_call_dummy:
3138     case bp_shlib_event:
3139     case bp_thread_event:
3140       if (addressprint)
3141         {
3142           annotate_field (4);
3143           /* FIXME-32x64: need a print_address_numeric with
3144              field width */
3145           printf_filtered
3146             ("%s ",
3147              local_hex_string_custom
3148              ((unsigned long) b->address, "08l"));
3149         }
3150       annotate_field (5);
3151       *last_addr = b->address;
3152       if (b->source_file)
3153         {
3154           sym = find_pc_sect_function (b->address, b->section);
3155           if (sym)
3156             {
3157               fputs_filtered ("in ", gdb_stdout);
3158               fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3159               wrap_here (wrap_indent);
3160               fputs_filtered (" at ", gdb_stdout);
3161             }
3162           fputs_filtered (b->source_file, gdb_stdout);
3163           printf_filtered (":%d", b->line_number);
3164         }
3165       else
3166         print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3167       break;
3168     }
3169   
3170   if (b->thread != -1)
3171     {
3172       printf_filtered (" thread %d", b->thread);
3173     }
3174   
3175   printf_filtered ("\n");
3176   
3177   if (b->frame)
3178     {
3179       annotate_field (6);
3180       printf_filtered ("\tstop only in stack frame at ");
3181       print_address_numeric (b->frame, 1, gdb_stdout);
3182       printf_filtered ("\n");
3183     }
3184   
3185   if (b->cond)
3186     {
3187       annotate_field (7);
3188       printf_filtered ("\tstop only if ");
3189       print_expression (b->cond, gdb_stdout);
3190       printf_filtered ("\n");
3191     }
3192   
3193   if (b->thread != -1)
3194     {
3195       /* FIXME should make an annotation for this */
3196       printf_filtered ("\tstop only in thread %d\n", b->thread);
3197     }
3198   
3199   if (show_breakpoint_hit_counts && b->hit_count)
3200     {
3201       /* FIXME should make an annotation for this */
3202       if (ep_is_catchpoint (b))
3203         printf_filtered ("\tcatchpoint");
3204       else
3205         printf_filtered ("\tbreakpoint");
3206       printf_filtered (" already hit %d time%s\n",
3207                        b->hit_count, (b->hit_count == 1 ? "" : "s"));
3208     }
3209   
3210   if (b->ignore_count)
3211     {
3212       annotate_field (8);
3213       printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3214     }
3215   
3216   if ((l = b->commands))
3217     {
3218       annotate_field (9);
3219       while (l)
3220         {
3221           print_command_line (l, 4, gdb_stdout);
3222           l = l->next;
3223         }
3224     }
3225 }
3226
3227 struct captured_breakpoint_query_args
3228   {
3229     int bnum;
3230   };
3231
3232 static int
3233 do_captured_breakpoint_query (void *data)
3234 {
3235   struct captured_breakpoint_query_args *args = data;
3236   register struct breakpoint *b;
3237   CORE_ADDR dummy_addr = 0;
3238   ALL_BREAKPOINTS (b)
3239     {
3240       if (args->bnum == b->number)
3241         {
3242           print_one_breakpoint (b, &dummy_addr);
3243           return GDB_RC_OK;
3244         }
3245     }
3246   return GDB_RC_NONE;
3247 }
3248
3249 enum gdb_rc
3250 gdb_breakpoint_query (/* output object, */ int bnum)
3251 {
3252   struct captured_breakpoint_query_args args;
3253   args.bnum = bnum;
3254   /* For the moment we don't trust print_one_breakpoint() to not throw
3255      an error. */
3256   return catch_errors (do_captured_breakpoint_query, &args,
3257                        NULL, RETURN_MASK_ALL);
3258 }
3259
3260 /* Print information on breakpoint number BNUM, or -1 if all.
3261    If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3262    is nonzero, process only watchpoints.  */
3263
3264 static void
3265 breakpoint_1 (bnum, allflag)
3266      int bnum;
3267      int allflag;
3268 {
3269   register struct breakpoint *b;
3270   CORE_ADDR last_addr = (CORE_ADDR) -1;
3271   int found_a_breakpoint = 0;
3272   
3273   ALL_BREAKPOINTS (b)
3274     if (bnum == -1
3275         || bnum == b->number)
3276       {
3277         /* We only print out user settable breakpoints unless the
3278            allflag is set. */
3279         if (!allflag
3280             && b->type != bp_breakpoint
3281             && b->type != bp_catch_load
3282             && b->type != bp_catch_unload
3283             && b->type != bp_catch_fork
3284             && b->type != bp_catch_vfork
3285             && b->type != bp_catch_exec
3286             && b->type != bp_catch_catch
3287             && b->type != bp_catch_throw
3288             && b->type != bp_hardware_breakpoint
3289             && b->type != bp_watchpoint
3290             && b->type != bp_read_watchpoint
3291             && b->type != bp_access_watchpoint
3292             && b->type != bp_hardware_watchpoint)
3293           continue;
3294         
3295         if (!found_a_breakpoint++)
3296           {
3297             annotate_breakpoints_headers ();
3298             annotate_field (0);
3299             printf_filtered ("Num ");
3300             annotate_field (1);
3301             printf_filtered ("Type           ");
3302             annotate_field (2);
3303             printf_filtered ("Disp ");
3304             annotate_field (3);
3305             printf_filtered ("Enb ");
3306             if (addressprint)
3307               {
3308                 annotate_field (4);
3309                 printf_filtered ("Address    ");
3310               }
3311             annotate_field (5);
3312             printf_filtered ("What\n");
3313             annotate_breakpoints_table ();
3314           }
3315         
3316         print_one_breakpoint (b, &last_addr);
3317       }
3318   
3319   if (!found_a_breakpoint)
3320     {
3321       if (bnum == -1)
3322         printf_filtered ("No breakpoints or watchpoints.\n");
3323       else
3324         printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3325     }
3326   else
3327     {
3328       /* Compare against (CORE_ADDR)-1 in case some compiler decides
3329          that a comparison of an unsigned with -1 is always false.  */
3330       if (last_addr != (CORE_ADDR) -1)
3331         set_next_address (last_addr);
3332     }
3333
3334   /* FIXME? Should this be moved up so that it is only called when
3335      there have been breakpoints? */
3336   annotate_breakpoints_table_end ();
3337 }
3338
3339 /* ARGSUSED */
3340 static void
3341 breakpoints_info (bnum_exp, from_tty)
3342      char *bnum_exp;
3343      int from_tty;
3344 {
3345   int bnum = -1;
3346
3347   if (bnum_exp)
3348     bnum = parse_and_eval_address (bnum_exp);
3349
3350   breakpoint_1 (bnum, 0);
3351 }
3352
3353 /* ARGSUSED */
3354 static void
3355 maintenance_info_breakpoints (bnum_exp, from_tty)
3356      char *bnum_exp;
3357      int from_tty;
3358 {
3359   int bnum = -1;
3360
3361   if (bnum_exp)
3362     bnum = parse_and_eval_address (bnum_exp);
3363
3364   breakpoint_1 (bnum, 1);
3365 }
3366
3367 /* Print a message describing any breakpoints set at PC.  */
3368
3369 static void
3370 describe_other_breakpoints (pc, section)
3371      CORE_ADDR pc;
3372      asection *section;
3373 {
3374   register int others = 0;
3375   register struct breakpoint *b;
3376
3377   ALL_BREAKPOINTS (b)
3378     if (b->address == pc)
3379     if (overlay_debugging == 0 ||
3380         b->section == section)
3381       others++;
3382   if (others > 0)
3383     {
3384       printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3385       ALL_BREAKPOINTS (b)
3386         if (b->address == pc)
3387         if (overlay_debugging == 0 ||
3388             b->section == section)
3389           {
3390             others--;
3391             printf_filtered
3392               ("%d%s%s ",
3393                b->number,
3394                ((b->enable == disabled || 
3395                  b->enable == shlib_disabled || 
3396                  b->enable == call_disabled) ? " (disabled)" 
3397                 : b->enable == permanent ? " (permanent)"
3398                 : ""),
3399                (others > 1) ? "," : ((others == 1) ? " and" : ""));
3400           }
3401       printf_filtered ("also set at pc ");
3402       print_address_numeric (pc, 1, gdb_stdout);
3403       printf_filtered (".\n");
3404     }
3405 }
3406 \f
3407 /* Set the default place to put a breakpoint
3408    for the `break' command with no arguments.  */
3409
3410 void
3411 set_default_breakpoint (valid, addr, symtab, line)
3412      int valid;
3413      CORE_ADDR addr;
3414      struct symtab *symtab;
3415      int line;
3416 {
3417   default_breakpoint_valid = valid;
3418   default_breakpoint_address = addr;
3419   default_breakpoint_symtab = symtab;
3420   default_breakpoint_line = line;
3421 }
3422
3423 /* Rescan breakpoints at address ADDRESS,
3424    marking the first one as "first" and any others as "duplicates".
3425    This is so that the bpt instruction is only inserted once.
3426    If we have a permanent breakpoint at ADDRESS, make that one
3427    the official one, and the rest as duplicates.  */
3428
3429 static void
3430 check_duplicates (address, section)
3431      CORE_ADDR address;
3432      asection *section;
3433 {
3434   register struct breakpoint *b;
3435   register int count = 0;
3436   struct breakpoint *perm_bp = 0;
3437
3438   if (address == 0)             /* Watchpoints are uninteresting */
3439     return;
3440
3441   ALL_BREAKPOINTS (b)
3442     if (b->enable != disabled
3443         && b->enable != shlib_disabled
3444         && b->enable != call_disabled
3445         && b->address == address
3446         && (overlay_debugging == 0 || b->section == section))
3447     {
3448       /* Have we found a permanent breakpoint?  */
3449       if (b->enable == permanent)
3450         {
3451           perm_bp = b;
3452           break;
3453         }
3454         
3455       count++;
3456       b->duplicate = count > 1;
3457     }
3458
3459   /* If we found a permanent breakpoint at this address, go over the
3460      list again and declare all the other breakpoints there to be the
3461      duplicates.  */
3462   if (perm_bp)
3463     {
3464       perm_bp->duplicate = 0;
3465
3466       /* Permanent breakpoint should always be inserted.  */
3467       if (! perm_bp->inserted)
3468         internal_error ("allegedly permanent breakpoint is not "
3469                         "actually inserted");
3470
3471       ALL_BREAKPOINTS (b)
3472         if (b != perm_bp)
3473           {
3474             if (b->inserted)
3475               internal_error ("another breakpoint was inserted on top of "
3476                               "a permanent breakpoint");
3477
3478             if (b->enable != disabled
3479                 && b->enable != shlib_disabled
3480                 && b->enable != call_disabled
3481                 && b->address == address
3482                 && (overlay_debugging == 0 || b->section == section))
3483               b->duplicate = 1;
3484           }
3485     }
3486 }
3487
3488 /* Low level routine to set a breakpoint.
3489    Takes as args the three things that every breakpoint must have.
3490    Returns the breakpoint object so caller can set other things.
3491    Does not set the breakpoint number!
3492    Does not print anything.
3493
3494    ==> This routine should not be called if there is a chance of later
3495    error(); otherwise it leaves a bogus breakpoint on the chain.  Validate
3496    your arguments BEFORE calling this routine!  */
3497
3498 struct breakpoint *
3499 set_raw_breakpoint (sal)
3500      struct symtab_and_line sal;
3501 {
3502   register struct breakpoint *b, *b1;
3503
3504   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3505   memset (b, 0, sizeof (*b));
3506   b->address = sal.pc;
3507   if (sal.symtab == NULL)
3508     b->source_file = NULL;
3509   else
3510     b->source_file = savestring (sal.symtab->filename,
3511                                  strlen (sal.symtab->filename));
3512   b->section = sal.section;
3513   b->language = current_language->la_language;
3514   b->input_radix = input_radix;
3515   b->thread = -1;
3516   b->line_number = sal.line;
3517   b->enable = enabled;
3518   b->next = 0;
3519   b->silent = 0;
3520   b->ignore_count = 0;
3521   b->commands = NULL;
3522   b->frame = 0;
3523   b->dll_pathname = NULL;
3524   b->triggered_dll_pathname = NULL;
3525   b->forked_inferior_pid = 0;
3526   b->exec_pathname = NULL;
3527
3528   /* Add this breakpoint to the end of the chain
3529      so that a list of breakpoints will come out in order
3530      of increasing numbers.  */
3531
3532   b1 = breakpoint_chain;
3533   if (b1 == 0)
3534     breakpoint_chain = b;
3535   else
3536     {
3537       while (b1->next)
3538         b1 = b1->next;
3539       b1->next = b;
3540     }
3541
3542   check_duplicates (sal.pc, sal.section);
3543   breakpoints_changed ();
3544
3545   return b;
3546 }
3547
3548
3549 /* Note that the breakpoint object B describes a permanent breakpoint
3550    instruction, hard-wired into the inferior's code.  */
3551 void
3552 make_breakpoint_permanent (struct breakpoint *b)
3553 {
3554   b->enable = permanent;
3555
3556   /* By definition, permanent breakpoints are already present in the code.  */
3557   b->inserted = 1;
3558 }
3559
3560 #ifdef GET_LONGJMP_TARGET
3561
3562 static void
3563 create_longjmp_breakpoint (func_name)
3564      char *func_name;
3565 {
3566   struct symtab_and_line sal;
3567   struct breakpoint *b;
3568
3569   INIT_SAL (&sal);              /* initialize to zeroes */
3570   if (func_name != NULL)
3571     {
3572       struct minimal_symbol *m;
3573
3574       m = lookup_minimal_symbol_text (func_name, NULL, 
3575                                       (struct objfile *) NULL);
3576       if (m)
3577         sal.pc = SYMBOL_VALUE_ADDRESS (m);
3578       else
3579         return;
3580     }
3581   sal.section = find_pc_overlay (sal.pc);
3582   b = set_raw_breakpoint (sal);
3583   if (!b)
3584     return;
3585
3586   b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3587   b->disposition = donttouch;
3588   b->enable = disabled;
3589   b->silent = 1;
3590   if (func_name)
3591     b->addr_string = strsave (func_name);
3592   b->number = internal_breakpoint_number--;
3593 }
3594
3595 #endif /* #ifdef GET_LONGJMP_TARGET */
3596
3597 /* Call this routine when stepping and nexting to enable a breakpoint
3598    if we do a longjmp().  When we hit that breakpoint, call
3599    set_longjmp_resume_breakpoint() to figure out where we are going. */
3600
3601 void
3602 enable_longjmp_breakpoint ()
3603 {
3604   register struct breakpoint *b;
3605
3606   ALL_BREAKPOINTS (b)
3607     if (b->type == bp_longjmp)
3608     {
3609       b->enable = enabled;
3610       check_duplicates (b->address, b->section);
3611     }
3612 }
3613
3614 void
3615 disable_longjmp_breakpoint ()
3616 {
3617   register struct breakpoint *b;
3618
3619   ALL_BREAKPOINTS (b)
3620     if (b->type == bp_longjmp
3621         || b->type == bp_longjmp_resume)
3622     {
3623       b->enable = disabled;
3624       check_duplicates (b->address, b->section);
3625     }
3626 }
3627
3628 struct breakpoint *
3629 create_thread_event_breakpoint (address)
3630      CORE_ADDR address;
3631 {
3632   struct breakpoint *b;
3633   struct symtab_and_line sal;
3634   char addr_string[80];         /* Surely an addr can't be longer than that. */
3635
3636   INIT_SAL (&sal);              /* initialize to zeroes */
3637   sal.pc = address;
3638   sal.section = find_pc_overlay (sal.pc);
3639   if ((b = set_raw_breakpoint (sal)) == NULL)
3640     return NULL;
3641   
3642   b->number = internal_breakpoint_number--;
3643   b->disposition = donttouch;
3644   b->type = bp_thread_event;    /* XXX: do we need a new type? 
3645                                    bp_thread_event */
3646   b->enable = enabled;
3647   /* addr_string has to be used or breakpoint_re_set will delete me.  */
3648   sprintf (addr_string, "*0x%s", paddr (b->address));
3649   b->addr_string = strsave (addr_string);
3650
3651   return b;
3652 }
3653
3654 void
3655 remove_thread_event_breakpoints (void)
3656 {
3657   struct breakpoint *b, *temp;
3658
3659   ALL_BREAKPOINTS_SAFE (b, temp)
3660     if (b->type == bp_thread_event)
3661       delete_breakpoint (b);
3662 }
3663
3664 #ifdef SOLIB_ADD
3665 void
3666 remove_solib_event_breakpoints ()
3667 {
3668   register struct breakpoint *b, *temp;
3669
3670   ALL_BREAKPOINTS_SAFE (b, temp)
3671     if (b->type == bp_shlib_event)
3672     delete_breakpoint (b);
3673 }
3674
3675 struct breakpoint *
3676 create_solib_event_breakpoint (address)
3677      CORE_ADDR address;
3678 {
3679   struct breakpoint *b;
3680   struct symtab_and_line sal;
3681
3682   INIT_SAL (&sal);              /* initialize to zeroes */
3683   sal.pc = address;
3684   sal.section = find_pc_overlay (sal.pc);
3685   b = set_raw_breakpoint (sal);
3686   b->number = internal_breakpoint_number--;
3687   b->disposition = donttouch;
3688   b->type = bp_shlib_event;
3689
3690   return b;
3691 }
3692
3693 /* Disable any breakpoints that are on code in shared libraries.  Only
3694    apply to enabled breakpoints, disabled ones can just stay disabled.  */
3695
3696 void
3697 disable_breakpoints_in_shlibs (silent)
3698      int silent;
3699 {
3700   struct breakpoint *b;
3701   int disabled_shlib_breaks = 0;
3702
3703   /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3704   ALL_BREAKPOINTS (b)
3705   {
3706 #if defined (PC_SOLIB)
3707     if (((b->type == bp_breakpoint) ||
3708          (b->type == bp_hardware_breakpoint)) &&
3709         b->enable == enabled &&
3710         !b->duplicate &&
3711         PC_SOLIB (b->address))
3712       {
3713         b->enable = shlib_disabled;
3714         if (!silent)
3715           {
3716             if (!disabled_shlib_breaks)
3717               {
3718                 target_terminal_ours_for_output ();
3719                 warning ("Temporarily disabling shared library breakpoints:");
3720               }
3721             disabled_shlib_breaks = 1;
3722             warning ("breakpoint #%d ", b->number);
3723           }
3724       }
3725 #endif
3726   }
3727 }
3728
3729 /* Try to reenable any breakpoints in shared libraries.  */
3730 void
3731 re_enable_breakpoints_in_shlibs ()
3732 {
3733   struct breakpoint *b;
3734
3735   ALL_BREAKPOINTS (b)
3736     if (b->enable == shlib_disabled)
3737     {
3738       char buf[1];
3739
3740       /* Do not reenable the breakpoint if the shared library
3741          is still not mapped in.  */
3742       if (target_read_memory (b->address, buf, 1) == 0)
3743         b->enable = enabled;
3744     }
3745 }
3746
3747 #endif
3748
3749 static void
3750 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
3751      char *hookname;
3752      int tempflag;
3753      char *dll_pathname;
3754      char *cond_string;
3755      enum bptype bp_kind;
3756 {
3757   struct breakpoint *b;
3758   struct symtabs_and_lines sals;
3759   struct cleanup *old_chain;
3760   struct cleanup *canonical_strings_chain = NULL;
3761   char *addr_start = hookname;
3762   char *addr_end = NULL;
3763   char **canonical = (char **) NULL;
3764   int thread = -1;              /* All threads. */
3765
3766   /* Set a breakpoint on the specified hook. */
3767   sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3768   addr_end = hookname;
3769
3770   if (sals.nelts == 0)
3771     {
3772       warning ("Unable to set a breakpoint on dynamic linker callback.");
3773       warning ("Suggest linking with /opt/langtools/lib/end.o.");
3774       warning ("GDB will be unable to track shl_load/shl_unload calls");
3775       return;
3776     }
3777   if (sals.nelts != 1)
3778     {
3779       warning ("Unable to set unique breakpoint on dynamic linker callback.");
3780       warning ("GDB will be unable to track shl_load/shl_unload calls");
3781       return;
3782     }
3783
3784   /* Make sure that all storage allocated in decode_line_1 gets freed
3785      in case the following errors out.  */
3786   old_chain = make_cleanup (free, sals.sals);
3787   if (canonical != (char **) NULL)
3788     {
3789       make_cleanup (free, canonical);
3790       canonical_strings_chain = make_cleanup (null_cleanup, 0);
3791       if (canonical[0] != NULL)
3792         make_cleanup (free, canonical[0]);
3793     }
3794
3795   resolve_sal_pc (&sals.sals[0]);
3796
3797   /* Remove the canonical strings from the cleanup, they are needed below.  */
3798   if (canonical != (char **) NULL)
3799     discard_cleanups (canonical_strings_chain);
3800
3801   b = set_raw_breakpoint (sals.sals[0]);
3802   set_breakpoint_count (breakpoint_count + 1);
3803   b->number = breakpoint_count;
3804   b->cond = NULL;
3805   b->cond_string = (cond_string == NULL) ? 
3806     NULL : savestring (cond_string, strlen (cond_string));
3807   b->thread = thread;
3808
3809   if (canonical != (char **) NULL && canonical[0] != NULL)
3810     b->addr_string = canonical[0];
3811   else if (addr_start)
3812     b->addr_string = savestring (addr_start, addr_end - addr_start);
3813
3814   b->enable = enabled;
3815   b->disposition = tempflag ? del : donttouch;
3816
3817   if (dll_pathname == NULL)
3818     b->dll_pathname = NULL;
3819   else
3820     {
3821       b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3822       strcpy (b->dll_pathname, dll_pathname);
3823     }
3824   b->type = bp_kind;
3825
3826   mention (b);
3827   do_cleanups (old_chain);
3828 }
3829
3830 void
3831 create_solib_load_event_breakpoint (hookname, tempflag, 
3832                                     dll_pathname, cond_string)
3833      char *hookname;
3834      int tempflag;
3835      char *dll_pathname;
3836      char *cond_string;
3837 {
3838   solib_load_unload_1 (hookname, tempflag, dll_pathname, 
3839                        cond_string, bp_catch_load);
3840 }
3841
3842 void
3843 create_solib_unload_event_breakpoint (hookname, tempflag, 
3844                                       dll_pathname, cond_string)
3845      char *hookname;
3846      int tempflag;
3847      char *dll_pathname;
3848      char *cond_string;
3849 {
3850   solib_load_unload_1 (hookname,tempflag, dll_pathname, 
3851                        cond_string, bp_catch_unload);
3852 }
3853
3854 static void
3855 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
3856      int tempflag;
3857      char *cond_string;
3858      enum bptype bp_kind;
3859 {
3860   struct symtab_and_line sal;
3861   struct breakpoint *b;
3862   int thread = -1;              /* All threads. */
3863
3864   INIT_SAL (&sal);
3865   sal.pc = 0;
3866   sal.symtab = NULL;
3867   sal.line = 0;
3868
3869   b = set_raw_breakpoint (sal);
3870   set_breakpoint_count (breakpoint_count + 1);
3871   b->number = breakpoint_count;
3872   b->cond = NULL;
3873   b->cond_string = (cond_string == NULL) ? 
3874     NULL : savestring (cond_string, strlen (cond_string));
3875   b->thread = thread;
3876   b->addr_string = NULL;
3877   b->enable = enabled;
3878   b->disposition = tempflag ? del : donttouch;
3879   b->forked_inferior_pid = 0;
3880
3881   b->type = bp_kind;
3882
3883   mention (b);
3884 }
3885
3886 void
3887 create_fork_event_catchpoint (tempflag, cond_string)
3888      int tempflag;
3889      char *cond_string;
3890 {
3891   create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3892 }
3893
3894 void
3895 create_vfork_event_catchpoint (tempflag, cond_string)
3896      int tempflag;
3897      char *cond_string;
3898 {
3899   create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3900 }
3901
3902 void
3903 create_exec_event_catchpoint (tempflag, cond_string)
3904      int tempflag;
3905      char *cond_string;
3906 {
3907   struct symtab_and_line sal;
3908   struct breakpoint *b;
3909   int thread = -1;              /* All threads. */
3910
3911   INIT_SAL (&sal);
3912   sal.pc = 0;
3913   sal.symtab = NULL;
3914   sal.line = 0;
3915
3916   b = set_raw_breakpoint (sal);
3917   set_breakpoint_count (breakpoint_count + 1);
3918   b->number = breakpoint_count;
3919   b->cond = NULL;
3920   b->cond_string = (cond_string == NULL) ?
3921     NULL : savestring (cond_string, strlen (cond_string));
3922   b->thread = thread;
3923   b->addr_string = NULL;
3924   b->enable = enabled;
3925   b->disposition = tempflag ? del : donttouch;
3926
3927   b->type = bp_catch_exec;
3928
3929   mention (b);
3930 }
3931
3932 static int
3933 hw_breakpoint_used_count ()
3934 {
3935   register struct breakpoint *b;
3936   int i = 0;
3937
3938   ALL_BREAKPOINTS (b)
3939   {
3940     if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3941       i++;
3942   }
3943
3944   return i;
3945 }
3946
3947 static int
3948 hw_watchpoint_used_count (type, other_type_used)
3949      enum bptype type;
3950      int *other_type_used;
3951 {
3952   register struct breakpoint *b;
3953   int i = 0;
3954
3955   *other_type_used = 0;
3956   ALL_BREAKPOINTS (b)
3957   {
3958     if (b->enable == enabled)
3959       {
3960         if (b->type == type)
3961           i++;
3962         else if ((b->type == bp_hardware_watchpoint ||
3963                   b->type == bp_read_watchpoint ||
3964                   b->type == bp_access_watchpoint)
3965                  && b->enable == enabled)
3966           *other_type_used = 1;
3967       }
3968   }
3969   return i;
3970 }
3971
3972 /* Call this after hitting the longjmp() breakpoint.  Use this to set
3973    a new breakpoint at the target of the jmp_buf.
3974
3975    FIXME - This ought to be done by setting a temporary breakpoint
3976    that gets deleted automatically... */
3977
3978 void
3979 set_longjmp_resume_breakpoint (pc, frame)
3980      CORE_ADDR pc;
3981      struct frame_info *frame;
3982 {
3983   register struct breakpoint *b;
3984
3985   ALL_BREAKPOINTS (b)
3986     if (b->type == bp_longjmp_resume)
3987     {
3988       b->address = pc;
3989       b->enable = enabled;
3990       if (frame != NULL)
3991         b->frame = frame->frame;
3992       else
3993         b->frame = 0;
3994       check_duplicates (b->address, b->section);
3995       return;
3996     }
3997 }
3998
3999 void
4000 disable_watchpoints_before_interactive_call_start ()
4001 {
4002   struct breakpoint *b;
4003
4004   ALL_BREAKPOINTS (b)
4005   {
4006     if (((b->type == bp_watchpoint)
4007          || (b->type == bp_hardware_watchpoint)
4008          || (b->type == bp_read_watchpoint)
4009          || (b->type == bp_access_watchpoint)
4010          || ep_is_exception_catchpoint (b))
4011         && (b->enable == enabled))
4012       {
4013         b->enable = call_disabled;
4014         check_duplicates (b->address, b->section);
4015       }
4016   }
4017 }
4018
4019 void
4020 enable_watchpoints_after_interactive_call_stop ()
4021 {
4022   struct breakpoint *b;
4023
4024   ALL_BREAKPOINTS (b)
4025   {
4026     if (((b->type == bp_watchpoint)
4027          || (b->type == bp_hardware_watchpoint)
4028          || (b->type == bp_read_watchpoint)
4029          || (b->type == bp_access_watchpoint)
4030          || ep_is_exception_catchpoint (b))
4031         && (b->enable == call_disabled))
4032       {
4033         b->enable = enabled;
4034         check_duplicates (b->address, b->section);
4035       }
4036   }
4037 }
4038
4039
4040 /* Set a breakpoint that will evaporate an end of command
4041    at address specified by SAL.
4042    Restrict it to frame FRAME if FRAME is nonzero.  */
4043
4044 struct breakpoint *
4045 set_momentary_breakpoint (sal, frame, type)
4046      struct symtab_and_line sal;
4047      struct frame_info *frame;
4048      enum bptype type;
4049 {
4050   register struct breakpoint *b;
4051   b = set_raw_breakpoint (sal);
4052   b->type = type;
4053   b->enable = enabled;
4054   b->disposition = donttouch;
4055   b->frame = (frame ? frame->frame : 0);
4056
4057   /* If we're debugging a multi-threaded program, then we
4058      want momentary breakpoints to be active in only a 
4059      single thread of control.  */
4060   if (in_thread_list (inferior_pid))
4061     b->thread = pid_to_thread_id (inferior_pid);
4062
4063   return b;
4064 }
4065 \f
4066
4067 /* Tell the user we have just set a breakpoint B.  */
4068
4069 static void
4070 mention (b)
4071      struct breakpoint *b;
4072 {
4073   int say_where = 0;
4074
4075   /* FIXME: This is misplaced; mention() is called by things (like hitting a
4076      watchpoint) other than breakpoint creation.  It should be possible to
4077      clean this up and at the same time replace the random calls to
4078      breakpoint_changed with this hook, as has already been done for
4079      delete_breakpoint_hook and so on.  */
4080   if (create_breakpoint_hook)
4081     create_breakpoint_hook (b);
4082   breakpoint_create_event (b->number);
4083
4084   switch (b->type)
4085     {
4086     case bp_none:
4087       printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4088       break;
4089     case bp_watchpoint:
4090       printf_filtered ("Watchpoint %d: ", b->number);
4091       print_expression (b->exp, gdb_stdout);
4092       break;
4093     case bp_hardware_watchpoint:
4094       printf_filtered ("Hardware watchpoint %d: ", b->number);
4095       print_expression (b->exp, gdb_stdout);
4096       break;
4097     case bp_read_watchpoint:
4098       printf_filtered ("Hardware read watchpoint %d: ", b->number);
4099       print_expression (b->exp, gdb_stdout);
4100       break;
4101     case bp_access_watchpoint:
4102       printf_filtered ("Hardware access (read/write) watchpoint %d: ", 
4103                        b->number);
4104       print_expression (b->exp, gdb_stdout);
4105       break;
4106     case bp_breakpoint:
4107       printf_filtered ("Breakpoint %d", b->number);
4108       say_where = 1;
4109       break;
4110     case bp_hardware_breakpoint:
4111       printf_filtered ("Hardware assisted breakpoint %d", b->number);
4112       say_where = 1;
4113       break;
4114     case bp_catch_load:
4115     case bp_catch_unload:
4116       printf_filtered ("Catchpoint %d (%s %s)",
4117                        b->number,
4118                        (b->type == bp_catch_load) ? "load" : "unload",
4119                        (b->dll_pathname != NULL) ? 
4120                        b->dll_pathname : "<any library>");
4121       break;
4122     case bp_catch_fork:
4123     case bp_catch_vfork:
4124       printf_filtered ("Catchpoint %d (%s)",
4125                        b->number,
4126                        (b->type == bp_catch_fork) ? "fork" : "vfork");
4127       break;
4128     case bp_catch_exec:
4129       printf_filtered ("Catchpoint %d (exec)",
4130                        b->number);
4131       break;
4132     case bp_catch_catch:
4133     case bp_catch_throw:
4134       printf_filtered ("Catchpoint %d (%s)",
4135                        b->number,
4136                        (b->type == bp_catch_catch) ? "catch" : "throw");
4137       break;
4138
4139     case bp_until:
4140     case bp_finish:
4141     case bp_longjmp:
4142     case bp_longjmp_resume:
4143     case bp_step_resume:
4144     case bp_through_sigtramp:
4145     case bp_call_dummy:
4146     case bp_watchpoint_scope:
4147     case bp_shlib_event:
4148     case bp_thread_event:
4149       break;
4150     }
4151   if (say_where)
4152     {
4153       if (addressprint || b->source_file == NULL)
4154         {
4155           printf_filtered (" at ");
4156           print_address_numeric (b->address, 1, gdb_stdout);
4157         }
4158       if (b->source_file)
4159         printf_filtered (": file %s, line %d.",
4160                          b->source_file, b->line_number);
4161       TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4162       TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4163     }
4164   printf_filtered ("\n");
4165 }
4166 \f
4167
4168 /* Set a breakpoint according to ARG (function, linenum or *address)
4169    flag: first bit  : 0 non-temporary, 1 temporary.
4170    second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4171
4172 static void
4173 break_command_1 (arg, flag, from_tty)
4174      char *arg;
4175      int flag, from_tty;
4176 {
4177   int tempflag, hardwareflag;
4178   struct symtabs_and_lines sals;
4179   struct symtab_and_line sal;
4180   register struct expression *cond = 0;
4181   register struct breakpoint *b;
4182
4183   /* Pointers in arg to the start, and one past the end, of the condition.  */
4184   char *cond_start = NULL;
4185   char *cond_end = NULL;
4186   /* Pointers in arg to the start, and one past the end,
4187      of the address part.  */
4188   char *addr_start = NULL;
4189   char *addr_end = NULL;
4190   struct cleanup *old_chain;
4191   struct cleanup *canonical_strings_chain = NULL;
4192   char **canonical = (char **) NULL;
4193   int i;
4194   int thread;
4195
4196   hardwareflag = flag & BP_HARDWAREFLAG;
4197   tempflag = flag & BP_TEMPFLAG;
4198
4199   sals.sals = NULL;
4200   sals.nelts = 0;
4201
4202   INIT_SAL (&sal);              /* initialize to zeroes */
4203
4204   /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
4205
4206   if (!arg || (arg[0] == 'i' && arg[1] == 'f'
4207                && (arg[2] == ' ' || arg[2] == '\t')))
4208     {
4209       if (default_breakpoint_valid)
4210         {
4211           sals.sals = (struct symtab_and_line *)
4212             xmalloc (sizeof (struct symtab_and_line));
4213           sal.pc = default_breakpoint_address;
4214           sal.line = default_breakpoint_line;
4215           sal.symtab = default_breakpoint_symtab;
4216           sal.section = find_pc_overlay (sal.pc);
4217           sals.sals[0] = sal;
4218           sals.nelts = 1;
4219         }
4220       else
4221         error ("No default breakpoint address now.");
4222     }
4223   else
4224     {
4225       addr_start = arg;
4226
4227       /* Force almost all breakpoints to be in terms of the
4228          current_source_symtab (which is decode_line_1's default).  This
4229          should produce the results we want almost all of the time while
4230          leaving default_breakpoint_* alone.  */
4231       if (default_breakpoint_valid
4232           && (!current_source_symtab
4233               || (arg && (*arg == '+' || *arg == '-'))))
4234         sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
4235                               default_breakpoint_line, &canonical);
4236       else
4237         sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical);
4238
4239       addr_end = arg;
4240     }
4241
4242   if (!sals.nelts)
4243     return;
4244
4245   /* Make sure that all storage allocated in decode_line_1 gets freed
4246      in case the following `for' loop errors out.  */
4247   old_chain = make_cleanup (free, sals.sals);
4248   if (canonical != (char **) NULL)
4249     {
4250       make_cleanup (free, canonical);
4251       canonical_strings_chain = make_cleanup (null_cleanup, 0);
4252       for (i = 0; i < sals.nelts; i++)
4253         {
4254           if (canonical[i] != NULL)
4255             make_cleanup (free, canonical[i]);
4256         }
4257     }
4258
4259   thread = -1;                  /* No specific thread yet */
4260
4261   /* Resolve all line numbers to PC's, and verify that conditions
4262      can be parsed, before setting any breakpoints.  */
4263   for (i = 0; i < sals.nelts; i++)
4264     {
4265       char *tok, *end_tok;
4266       int toklen;
4267
4268       resolve_sal_pc (&sals.sals[i]);
4269
4270       /* It's possible for the PC to be nonzero, but still an illegal
4271          value on some targets.
4272
4273          For example, on HP-UX if you start gdb, and before running the
4274          inferior you try to set a breakpoint on a shared library function
4275          "foo" where the inferior doesn't call "foo" directly but does
4276          pass its address to another function call, then we do find a
4277          minimal symbol for the "foo", but it's address is invalid.
4278          (Appears to be an index into a table that the loader sets up
4279          when the inferior is run.)
4280
4281          Give the target a chance to bless sals.sals[i].pc before we
4282          try to make a breakpoint for it. */
4283       if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc))
4284         {
4285           error ("Cannot break on %s without a running program.", 
4286                  addr_start);
4287         }
4288
4289       tok = arg;
4290
4291       while (tok && *tok)
4292         {
4293           while (*tok == ' ' || *tok == '\t')
4294             tok++;
4295
4296           end_tok = tok;
4297
4298           while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4299             end_tok++;
4300
4301           toklen = end_tok - tok;
4302
4303           if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4304             {
4305               tok = cond_start = end_tok + 1;
4306               cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4307               cond_end = tok;
4308             }
4309           else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4310             {
4311               char *tmptok;
4312
4313               tok = end_tok + 1;
4314               tmptok = tok;
4315               thread = strtol (tok, &tok, 0);
4316               if (tok == tmptok)
4317                 error ("Junk after thread keyword.");
4318               if (!valid_thread_id (thread))
4319                 error ("Unknown thread %d\n", thread);
4320             }
4321           else
4322             error ("Junk at end of arguments.");
4323         }
4324     }
4325   if (hardwareflag)
4326     {
4327       int i, target_resources_ok;
4328
4329       i = hw_breakpoint_used_count ();
4330       target_resources_ok = 
4331         TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, 
4332                                             i + sals.nelts, 0);
4333       if (target_resources_ok == 0)
4334         error ("No hardware breakpoint support in the target.");
4335       else if (target_resources_ok < 0)
4336         error ("Hardware breakpoints used exceeds limit.");
4337     }
4338
4339   /* Remove the canonical strings from the cleanup, they are needed below.  */
4340   if (canonical != (char **) NULL)
4341     discard_cleanups (canonical_strings_chain);
4342
4343   /* Now set all the breakpoints.  */
4344   for (i = 0; i < sals.nelts; i++)
4345     {
4346       sal = sals.sals[i];
4347
4348       if (from_tty)
4349         describe_other_breakpoints (sal.pc, sal.section);
4350
4351       b = set_raw_breakpoint (sal);
4352       set_breakpoint_count (breakpoint_count + 1);
4353       b->number = breakpoint_count;
4354       b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
4355       b->cond = cond;
4356       b->thread = thread;
4357
4358       /* If a canonical line spec is needed use that instead of the
4359          command string.  */
4360       if (canonical != (char **) NULL && canonical[i] != NULL)
4361         b->addr_string = canonical[i];
4362       else if (addr_start)
4363         b->addr_string = savestring (addr_start, addr_end - addr_start);
4364       if (cond_start)
4365         b->cond_string = savestring (cond_start, cond_end - cond_start);
4366
4367       b->enable = enabled;
4368       b->disposition = tempflag ? del : donttouch;
4369       mention (b);
4370     }
4371
4372   if (sals.nelts > 1)
4373     {
4374       warning ("Multiple breakpoints were set.");
4375       warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4376     }
4377   do_cleanups (old_chain);
4378 }
4379
4380 static void
4381 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4382      char *arg;
4383      int flag;
4384      int from_tty;
4385 {
4386   struct frame_info *frame;
4387   CORE_ADDR low, high, selected_pc = 0;
4388   char *extra_args, *level_arg, *addr_string;
4389   int extra_args_len = 0, if_arg = 0;
4390
4391   if (!arg ||
4392       (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4393     {
4394
4395       if (default_breakpoint_valid)
4396         {
4397           if (selected_frame)
4398             {
4399               selected_pc = selected_frame->pc;
4400               if (arg)
4401                 if_arg = 1;
4402             }
4403           else
4404             error ("No selected frame.");
4405         }
4406       else
4407         error ("No default breakpoint address now.");
4408     }
4409   else
4410     {
4411       extra_args = strchr (arg, ' ');
4412       if (extra_args)
4413         {
4414           extra_args++;
4415           extra_args_len = strlen (extra_args);
4416           level_arg = (char *) xmalloc (extra_args - arg);
4417           strncpy (level_arg, arg, extra_args - arg - 1);
4418           level_arg[extra_args - arg - 1] = '\0';
4419         }
4420       else
4421         {
4422           level_arg = (char *) xmalloc (strlen (arg) + 1);
4423           strcpy (level_arg, arg);
4424         }
4425
4426       frame = parse_frame_specification (level_arg);
4427       if (frame)
4428         selected_pc = frame->pc;
4429       else
4430         selected_pc = 0;
4431     }
4432   if (if_arg)
4433     {
4434       extra_args = arg;
4435       extra_args_len = strlen (arg);
4436     }
4437
4438   if (selected_pc)
4439     {
4440       if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4441         {
4442           addr_string = (char *) xmalloc (26 + extra_args_len);
4443           if (extra_args_len)
4444             sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4445           else
4446             sprintf (addr_string, "*0x%s", paddr_nz (high));
4447           break_command_1 (addr_string, flag, from_tty);
4448           free (addr_string);
4449         }
4450       else
4451         error ("No function contains the specified address");
4452     }
4453   else
4454     error ("Unable to set breakpoint at procedure exit");
4455 }
4456
4457
4458 static void
4459 break_at_finish_command_1 (arg, flag, from_tty)
4460      char *arg;
4461      int flag;
4462      int from_tty;
4463 {
4464   char *addr_string, *break_string, *beg_addr_string;
4465   CORE_ADDR low, high;
4466   struct symtabs_and_lines sals;
4467   struct symtab_and_line sal;
4468   struct cleanup *old_chain;
4469   char *extra_args;
4470   int extra_args_len = 0;
4471   int i, if_arg = 0;
4472
4473   if (!arg ||
4474       (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4475     {
4476       if (default_breakpoint_valid)
4477         {
4478           if (selected_frame)
4479             {
4480               addr_string = (char *) xmalloc (15);
4481               sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
4482               if (arg)
4483                 if_arg = 1;
4484             }
4485           else
4486             error ("No selected frame.");
4487         }
4488       else
4489         error ("No default breakpoint address now.");
4490     }
4491   else
4492     {
4493       addr_string = (char *) xmalloc (strlen (arg) + 1);
4494       strcpy (addr_string, arg);
4495     }
4496
4497   if (if_arg)
4498     {
4499       extra_args = arg;
4500       extra_args_len = strlen (arg);
4501     }
4502   else if (arg)
4503     {
4504       /* get the stuff after the function name or address */
4505       extra_args = strchr (arg, ' ');
4506       if (extra_args)
4507         {
4508           extra_args++;
4509           extra_args_len = strlen (extra_args);
4510         }
4511     }
4512
4513   sals.sals = NULL;
4514   sals.nelts = 0;
4515
4516   beg_addr_string = addr_string;
4517   sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4518                         (char ***) NULL);
4519
4520   free (beg_addr_string);
4521   old_chain = make_cleanup (free, sals.sals);
4522   for (i = 0; (i < sals.nelts); i++)
4523     {
4524       sal = sals.sals[i];
4525       if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
4526         {
4527           break_string = (char *) xmalloc (extra_args_len + 26);
4528           if (extra_args_len)
4529             sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
4530           else
4531             sprintf (break_string, "*0x%s", paddr_nz (high));
4532           break_command_1 (break_string, flag, from_tty);
4533           free (break_string);
4534         }
4535       else
4536         error ("No function contains the specified address");
4537     }
4538   if (sals.nelts > 1)
4539     {
4540       warning ("Multiple breakpoints were set.\n");
4541       warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4542     }
4543   do_cleanups (old_chain);
4544 }
4545
4546
4547 /* Helper function for break_command_1 and disassemble_command.  */
4548
4549 void
4550 resolve_sal_pc (sal)
4551      struct symtab_and_line *sal;
4552 {
4553   CORE_ADDR pc;
4554
4555   if (sal->pc == 0 && sal->symtab != NULL)
4556     {
4557       if (!find_line_pc (sal->symtab, sal->line, &pc))
4558         error ("No line %d in file \"%s\".",
4559                sal->line, sal->symtab->filename);
4560       sal->pc = pc;
4561     }
4562
4563   if (sal->section == 0 && sal->symtab != NULL)
4564     {
4565       struct blockvector *bv;
4566       struct block *b;
4567       struct symbol *sym;
4568       int index;
4569
4570       bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4571       if (bv != NULL)
4572         {
4573           b = BLOCKVECTOR_BLOCK (bv, index);
4574           sym = block_function (b);
4575           if (sym != NULL)
4576             {
4577               fixup_symbol_section (sym, sal->symtab->objfile);
4578               sal->section = SYMBOL_BFD_SECTION (sym);
4579             }
4580           else
4581             {
4582               /* It really is worthwhile to have the section, so we'll just
4583                  have to look harder. This case can be executed if we have 
4584                  line numbers but no functions (as can happen in assembly 
4585                  source).  */
4586
4587               struct minimal_symbol *msym;
4588
4589               msym = lookup_minimal_symbol_by_pc (sal->pc);
4590               if (msym)
4591                 sal->section = SYMBOL_BFD_SECTION (msym);
4592             }
4593         }
4594     }
4595 }
4596
4597 void
4598 break_command (arg, from_tty)
4599      char *arg;
4600      int from_tty;
4601 {
4602   break_command_1 (arg, 0, from_tty);
4603 }
4604
4605 static void
4606 break_at_finish_command (arg, from_tty)
4607      char *arg;
4608      int from_tty;
4609 {
4610   break_at_finish_command_1 (arg, 0, from_tty);
4611 }
4612
4613 static void
4614 break_at_finish_at_depth_command (arg, from_tty)
4615      char *arg;
4616      int from_tty;
4617 {
4618   break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4619 }
4620
4621 void
4622 tbreak_command (arg, from_tty)
4623      char *arg;
4624      int from_tty;
4625 {
4626   break_command_1 (arg, BP_TEMPFLAG, from_tty);
4627 }
4628
4629 static void
4630 tbreak_at_finish_command (arg, from_tty)
4631      char *arg;
4632      int from_tty;
4633 {
4634   break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4635 }
4636
4637 static void
4638 hbreak_command (arg, from_tty)
4639      char *arg;
4640      int from_tty;
4641 {
4642   break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4643 }
4644
4645 static void
4646 thbreak_command (arg, from_tty)
4647      char *arg;
4648      int from_tty;
4649 {
4650   break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4651 }
4652
4653 static void
4654 stop_command (arg, from_tty)
4655      char *arg;
4656      int from_tty;
4657 {
4658   printf_filtered ("Specify the type of breakpoint to set.\n\
4659 Usage: stop in <function | address>\n\
4660        stop at <line>\n");
4661 }
4662
4663 static void
4664 stopin_command (arg, from_tty)
4665      char *arg;
4666      int from_tty;
4667 {
4668   int badInput = 0;
4669
4670   if (arg == (char *) NULL)
4671     badInput = 1;
4672   else if (*arg != '*')
4673     {
4674       char *argptr = arg;
4675       int hasColon = 0;
4676
4677       /* look for a ':'.  If this is a line number specification, then
4678          say it is bad, otherwise, it should be an address or
4679          function/method name */
4680       while (*argptr && !hasColon)
4681         {
4682           hasColon = (*argptr == ':');
4683           argptr++;
4684         }
4685
4686       if (hasColon)
4687         badInput = (*argptr != ':');    /* Not a class::method */
4688       else
4689         badInput = isdigit (*arg);      /* a simple line number */
4690     }
4691
4692   if (badInput)
4693     printf_filtered ("Usage: stop in <function | address>\n");
4694   else
4695     break_command_1 (arg, 0, from_tty);
4696 }
4697
4698 static void
4699 stopat_command (arg, from_tty)
4700      char *arg;
4701      int from_tty;
4702 {
4703   int badInput = 0;
4704
4705   if (arg == (char *) NULL || *arg == '*')      /* no line number */
4706     badInput = 1;
4707   else
4708     {
4709       char *argptr = arg;
4710       int hasColon = 0;
4711
4712       /* look for a ':'.  If there is a '::' then get out, otherwise
4713          it is probably a line number. */
4714       while (*argptr && !hasColon)
4715         {
4716           hasColon = (*argptr == ':');
4717           argptr++;
4718         }
4719
4720       if (hasColon)
4721         badInput = (*argptr == ':');    /* we have class::method */
4722       else
4723         badInput = !isdigit (*arg);     /* not a line number */
4724     }
4725
4726   if (badInput)
4727     printf_filtered ("Usage: stop at <line>\n");
4728   else
4729     break_command_1 (arg, 0, from_tty);
4730 }
4731
4732 /* ARGSUSED */
4733 /* accessflag:  hw_write:  watch write, 
4734                 hw_read:   watch read, 
4735                 hw_access: watch access (read or write) */
4736 static void
4737 watch_command_1 (arg, accessflag, from_tty)
4738      char *arg;
4739      int accessflag;
4740      int from_tty;
4741 {
4742   struct breakpoint *b;
4743   struct symtab_and_line sal;
4744   struct expression *exp;
4745   struct block *exp_valid_block;
4746   struct value *val, *mark;
4747   struct frame_info *frame;
4748   struct frame_info *prev_frame = NULL;
4749   char *exp_start = NULL;
4750   char *exp_end = NULL;
4751   char *tok, *end_tok;
4752   int toklen;
4753   char *cond_start = NULL;
4754   char *cond_end = NULL;
4755   struct expression *cond = NULL;
4756   int i, other_type_used, target_resources_ok = 0;
4757   enum bptype bp_type;
4758   int mem_cnt = 0;
4759
4760   INIT_SAL (&sal);              /* initialize to zeroes */
4761
4762   /* Parse arguments.  */
4763   innermost_block = NULL;
4764   exp_start = arg;
4765   exp = parse_exp_1 (&arg, 0, 0);
4766   exp_end = arg;
4767   exp_valid_block = innermost_block;
4768   mark = value_mark ();
4769   val = evaluate_expression (exp);
4770   release_value (val);
4771   if (VALUE_LAZY (val))
4772     value_fetch_lazy (val);
4773
4774   tok = arg;
4775   while (*tok == ' ' || *tok == '\t')
4776     tok++;
4777   end_tok = tok;
4778
4779   while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4780     end_tok++;
4781
4782   toklen = end_tok - tok;
4783   if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4784     {
4785       tok = cond_start = end_tok + 1;
4786       cond = parse_exp_1 (&tok, 0, 0);
4787       cond_end = tok;
4788     }
4789   if (*tok)
4790     error ("Junk at end of command.");
4791
4792   if (accessflag == hw_read)
4793     bp_type = bp_read_watchpoint;
4794   else if (accessflag == hw_access)
4795     bp_type = bp_access_watchpoint;
4796   else
4797     bp_type = bp_hardware_watchpoint;
4798
4799   mem_cnt = can_use_hardware_watchpoint (val);
4800   if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4801     error ("Expression cannot be implemented with read/access watchpoint.");
4802   if (mem_cnt != 0)
4803     {
4804       i = hw_watchpoint_used_count (bp_type, &other_type_used);
4805       target_resources_ok = 
4806         TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt, 
4807                                             other_type_used);
4808       if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
4809         error ("Target does not support this type of hardware watchpoint.");
4810
4811       if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
4812         error ("Target can only support one kind of HW watchpoint at a time.");
4813     }
4814
4815 #if defined(HPUXHPPA)
4816   /*  On HP-UX if you set a h/w
4817      watchpoint before the "run" command, the inferior dies with a e.g.,
4818      SIGILL once you start it.  I initially believed this was due to a
4819      bad interaction between page protection traps and the initial
4820      startup sequence by the dynamic linker.
4821
4822      However, I tried avoiding that by having HP-UX's implementation of
4823      TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4824      yet, which forced slow watches before a "run" or "attach", and it
4825      still fails somewhere in the startup code.
4826
4827      Until I figure out what's happening, I'm disallowing watches altogether
4828      before the "run" or "attach" command.  We'll tell the user they must
4829      set watches after getting the program started. */
4830   if (!target_has_execution)
4831     {
4832       warning ("can't do that without a running program; try \"break main\", \"run\" first");
4833       return;
4834     }
4835 #endif /* HPUXHPPA */
4836
4837   /* Now set up the breakpoint.  */
4838   b = set_raw_breakpoint (sal);
4839   set_breakpoint_count (breakpoint_count + 1);
4840   b->number = breakpoint_count;
4841   b->disposition = donttouch;
4842   b->exp = exp;
4843   b->exp_valid_block = exp_valid_block;
4844   b->exp_string = savestring (exp_start, exp_end - exp_start);
4845   b->val = val;
4846   b->cond = cond;
4847   if (cond_start)
4848     b->cond_string = savestring (cond_start, cond_end - cond_start);
4849   else
4850     b->cond_string = 0;
4851
4852   frame = block_innermost_frame (exp_valid_block);
4853   if (frame)
4854     {
4855       prev_frame = get_prev_frame (frame);
4856       b->watchpoint_frame = frame->frame;
4857     }
4858   else
4859     b->watchpoint_frame = (CORE_ADDR) 0;
4860
4861   if (mem_cnt && target_resources_ok > 0)
4862     b->type = bp_type;
4863   else
4864     b->type = bp_watchpoint;
4865
4866   /* If the expression is "local", then set up a "watchpoint scope"
4867      breakpoint at the point where we've left the scope of the watchpoint
4868      expression.  */
4869   if (innermost_block)
4870     {
4871       if (prev_frame)
4872         {
4873           struct breakpoint *scope_breakpoint;
4874           struct symtab_and_line scope_sal;
4875
4876           INIT_SAL (&scope_sal);        /* initialize to zeroes */
4877           scope_sal.pc = get_frame_pc (prev_frame);
4878           scope_sal.section = find_pc_overlay (scope_sal.pc);
4879
4880           scope_breakpoint = set_raw_breakpoint (scope_sal);
4881           set_breakpoint_count (breakpoint_count + 1);
4882           scope_breakpoint->number = breakpoint_count;
4883
4884           scope_breakpoint->type = bp_watchpoint_scope;
4885           scope_breakpoint->enable = enabled;
4886
4887           /* Automatically delete the breakpoint when it hits.  */
4888           scope_breakpoint->disposition = del;
4889
4890           /* Only break in the proper frame (help with recursion).  */
4891           scope_breakpoint->frame = prev_frame->frame;
4892
4893           /* Set the address at which we will stop.  */
4894           scope_breakpoint->address = get_frame_pc (prev_frame);
4895
4896           /* The scope breakpoint is related to the watchpoint.  We
4897              will need to act on them together.  */
4898           b->related_breakpoint = scope_breakpoint;
4899         }
4900     }
4901   value_free_to_mark (mark);
4902   mention (b);
4903 }
4904
4905 /* Return count of locations need to be watched and can be handled
4906    in hardware.  If the watchpoint can not be handled
4907    in hardware return zero.  */
4908
4909 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
4910 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
4911     ((BYTE_SIZE) <= (REGISTER_SIZE))
4912 #endif
4913
4914 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
4915 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
4916      TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
4917 #endif
4918
4919 static int
4920 can_use_hardware_watchpoint (v)
4921      struct value *v;
4922 {
4923   int found_memory_cnt = 0;
4924
4925   /* Did the user specifically forbid us to use hardware watchpoints? */
4926   if (!can_use_hw_watchpoints)
4927     return 0;
4928
4929   /* Make sure that the value of the expression depends only upon
4930      memory contents, and values computed from them within GDB.  If we
4931      find any register references or function calls, we can't use a
4932      hardware watchpoint.
4933
4934      The idea here is that evaluating an expression generates a series
4935      of values, one holding the value of every subexpression.  (The
4936      expression a*b+c has five subexpressions: a, b, a*b, c, and
4937      a*b+c.)  GDB's values hold almost enough information to establish
4938      the criteria given above --- they identify memory lvalues,
4939      register lvalues, computed values, etcetera.  So we can evaluate
4940      the expression, and then scan the chain of values that leaves
4941      behind to decide whether we can detect any possible change to the
4942      expression's final value using only hardware watchpoints.
4943
4944      However, I don't think that the values returned by inferior
4945      function calls are special in any way.  So this function may not
4946      notice that an expression involving an inferior function call
4947      can't be watched with hardware watchpoints.  FIXME.  */
4948   for (; v; v = v->next)
4949     {
4950       if (VALUE_LVAL (v) == lval_memory)
4951         {
4952           if (VALUE_LAZY (v))
4953             /* A lazy memory lvalue is one that GDB never needed to fetch;
4954                we either just used its address (e.g., `a' in `a.b') or
4955                we never needed it at all (e.g., `a' in `a,b').  */
4956             ;
4957           else
4958             {
4959               /* Ahh, memory we actually used!  Check if we can cover
4960                  it with hardware watchpoints.  */
4961               CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
4962               int       len   = TYPE_LENGTH (VALUE_TYPE (v));
4963
4964               if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
4965                 return 0;
4966               else
4967                 found_memory_cnt++;
4968             }
4969         }
4970       else if (v->lval != not_lval && v->modifiable == 0)
4971         return 0;       /* ??? What does this represent? */
4972       else if (v->lval == lval_register)
4973         return 0;       /* cannot watch a register with a HW watchpoint */
4974     }
4975
4976   /* The expression itself looks suitable for using a hardware
4977      watchpoint, but give the target machine a chance to reject it.  */
4978   return found_memory_cnt;
4979 }
4980
4981 static void
4982 watch_command (arg, from_tty)
4983      char *arg;
4984      int from_tty;
4985 {
4986   watch_command_1 (arg, hw_write, from_tty);
4987 }
4988
4989 static void
4990 rwatch_command (arg, from_tty)
4991      char *arg;
4992      int from_tty;
4993 {
4994   watch_command_1 (arg, hw_read, from_tty);
4995 }
4996
4997 static void
4998 awatch_command (arg, from_tty)
4999      char *arg;
5000      int from_tty;
5001 {
5002   watch_command_1 (arg, hw_access, from_tty);
5003 }
5004 \f
5005
5006 /* Helper routines for the until_command routine in infcmd.c.  Here
5007    because it uses the mechanisms of breakpoints.  */
5008
5009 /* This function is called by fetch_inferior_event via the
5010    cmd_continuation pointer, to complete the until command. It takes
5011    care of cleaning up the temporary breakpoints set up by the until
5012    command. */
5013 static void
5014 until_break_command_continuation (struct continuation_arg *arg)
5015 {
5016   /* Do all the exec cleanups, which at this point should only be the
5017      one set up in the first part of the until_break_command
5018      function. */
5019   do_exec_cleanups (ALL_CLEANUPS);
5020 }
5021
5022 /* ARGSUSED */
5023 void
5024 until_break_command (arg, from_tty)
5025      char *arg;
5026      int from_tty;
5027 {
5028   struct symtabs_and_lines sals;
5029   struct symtab_and_line sal;
5030   struct frame_info *prev_frame = get_prev_frame (selected_frame);
5031   struct breakpoint *breakpoint;
5032   struct cleanup *old_chain;
5033
5034   clear_proceed_status ();
5035
5036   /* Set a breakpoint where the user wants it and at return from
5037      this function */
5038
5039   if (default_breakpoint_valid)
5040     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5041                           default_breakpoint_line, (char ***) NULL);
5042   else
5043     sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 
5044                           0, (char ***) NULL);
5045
5046   if (sals.nelts != 1)
5047     error ("Couldn't get information on specified line.");
5048
5049   sal = sals.sals[0];
5050   free ((PTR) sals.sals);       /* malloc'd, so freed */
5051
5052   if (*arg)
5053     error ("Junk at end of arguments.");
5054
5055   resolve_sal_pc (&sal);
5056
5057   breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5058
5059   if (!event_loop_p || !target_can_async_p ())
5060     old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, 
5061                               breakpoint);
5062   else
5063     make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5064
5065   /* If we are running asynchronously, and the target supports async
5066      execution, we are not waiting for the target to stop, in the call
5067      tp proceed, below. This means that we cannot delete the
5068      brekpoints until the target has actually stopped. The only place
5069      where we get a chance to do that is in fetch_inferior_event, so
5070      we must set things up for that. */
5071
5072   if (event_loop_p && target_can_async_p ())
5073     {
5074       /* In this case we don't need args for the continuation, because
5075          all it needs to do is do the cleanups in the
5076          exec_cleanup_chain, which will be only those inserted by this
5077          function. We can get away by using ALL_CLEANUPS. */
5078       add_continuation (until_break_command_continuation, NULL);
5079     }
5080
5081   /* Keep within the current frame */
5082
5083   if (prev_frame)
5084     {
5085       sal = find_pc_line (prev_frame->pc, 0);
5086       sal.pc = prev_frame->pc;
5087       breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5088       if (!event_loop_p || !target_can_async_p ())
5089         make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5090       else
5091         make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5092     }
5093
5094   proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5095   /* Do the cleanups now, anly if we are not running asynchronously,
5096      of if we are, but the target is still synchronous. */
5097   if (!event_loop_p || !target_can_async_p ())
5098     do_cleanups (old_chain);
5099 }
5100 \f
5101 #if 0
5102 /* These aren't used; I don't konw what they were for.  */
5103 /* Set a breakpoint at the catch clause for NAME.  */
5104 static int
5105 catch_breakpoint (name)
5106      char *name;
5107 {
5108 }
5109
5110 static int
5111 disable_catch_breakpoint ()
5112 {
5113 }
5114
5115 static int
5116 delete_catch_breakpoint ()
5117 {
5118 }
5119
5120 static int
5121 enable_catch_breakpoint ()
5122 {
5123 }
5124 #endif /* 0 */
5125
5126 struct sal_chain
5127 {
5128   struct sal_chain *next;
5129   struct symtab_and_line sal;
5130 };
5131
5132 #if 0
5133 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5134    had been commented out in the v.4.16 sources, and stays
5135    disabled there now because "catch NAME" syntax isn't allowed.
5136    pai/1997-07-11 */
5137 /* This isn't used; I don't know what it was for.  */
5138 /* For each catch clause identified in ARGS, run FUNCTION
5139    with that clause as an argument.  */
5140 static struct symtabs_and_lines
5141 map_catch_names (args, function)
5142      char *args;
5143      int (*function) ();
5144 {
5145   register char *p = args;
5146   register char *p1;
5147   struct symtabs_and_lines sals;
5148 #if 0
5149   struct sal_chain *sal_chain = 0;
5150 #endif
5151
5152   if (p == 0)
5153     error_no_arg ("one or more catch names");
5154
5155   sals.nelts = 0;
5156   sals.sals = NULL;
5157
5158   while (*p)
5159     {
5160       p1 = p;
5161       /* Don't swallow conditional part.  */
5162       if (p1[0] == 'i' && p1[1] == 'f'
5163           && (p1[2] == ' ' || p1[2] == '\t'))
5164         break;
5165
5166       if (isalpha (*p1))
5167         {
5168           p1++;
5169           while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5170             p1++;
5171         }
5172
5173       if (*p1 && *p1 != ' ' && *p1 != '\t')
5174         error ("Arguments must be catch names.");
5175
5176       *p1 = 0;
5177 #if 0
5178       if (function (p))
5179         {
5180           struct sal_chain *next = (struct sal_chain *)
5181           alloca (sizeof (struct sal_chain));
5182           next->next = sal_chain;
5183           next->sal = get_catch_sal (p);
5184           sal_chain = next;
5185           goto win;
5186         }
5187 #endif
5188       printf_unfiltered ("No catch clause for exception %s.\n", p);
5189 #if 0
5190     win:
5191 #endif
5192       p = p1;
5193       while (*p == ' ' || *p == '\t')
5194         p++;
5195     }
5196 }
5197 #endif
5198
5199 /* This shares a lot of code with `print_frame_label_vars' from stack.c.  */
5200
5201 static struct symtabs_and_lines
5202 get_catch_sals (this_level_only)
5203      int this_level_only;
5204 {
5205   register struct blockvector *bl;
5206   register struct block *block;
5207   int index, have_default = 0;
5208   CORE_ADDR pc;
5209   struct symtabs_and_lines sals;
5210   struct sal_chain *sal_chain = 0;
5211   char *blocks_searched;
5212
5213   /* Not sure whether an error message is always the correct response,
5214      but it's better than a core dump.  */
5215   if (selected_frame == NULL)
5216     error ("No selected frame.");
5217   block = get_frame_block (selected_frame);
5218   pc = selected_frame->pc;
5219
5220   sals.nelts = 0;
5221   sals.sals = NULL;
5222
5223   if (block == 0)
5224     error ("No symbol table info available.\n");
5225
5226   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5227   blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5228   memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5229
5230   while (block != 0)
5231     {
5232       CORE_ADDR end = BLOCK_END (block) - 4;
5233       int last_index;
5234
5235       if (bl != blockvector_for_pc (end, &index))
5236         error ("blockvector blotch");
5237       if (BLOCKVECTOR_BLOCK (bl, index) != block)
5238         error ("blockvector botch");
5239       last_index = BLOCKVECTOR_NBLOCKS (bl);
5240       index += 1;
5241
5242       /* Don't print out blocks that have gone by.  */
5243       while (index < last_index
5244              && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5245         index++;
5246
5247       while (index < last_index
5248              && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5249         {
5250           if (blocks_searched[index] == 0)
5251             {
5252               struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5253               int nsyms;
5254               register int i;
5255               register struct symbol *sym;
5256
5257               nsyms = BLOCK_NSYMS (b);
5258
5259               for (i = 0; i < nsyms; i++)
5260                 {
5261                   sym = BLOCK_SYM (b, i);
5262                   if (STREQ (SYMBOL_NAME (sym), "default"))
5263                     {
5264                       if (have_default)
5265                         continue;
5266                       have_default = 1;
5267                     }
5268                   if (SYMBOL_CLASS (sym) == LOC_LABEL)
5269                     {
5270                       struct sal_chain *next = (struct sal_chain *)
5271                       alloca (sizeof (struct sal_chain));
5272                       next->next = sal_chain;
5273                       next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 
5274                                                 0);
5275                       sal_chain = next;
5276                     }
5277                 }
5278               blocks_searched[index] = 1;
5279             }
5280           index++;
5281         }
5282       if (have_default)
5283         break;
5284       if (sal_chain && this_level_only)
5285         break;
5286
5287       /* After handling the function's top-level block, stop.
5288          Don't continue to its superblock, the block of
5289          per-file symbols.  */
5290       if (BLOCK_FUNCTION (block))
5291         break;
5292       block = BLOCK_SUPERBLOCK (block);
5293     }
5294
5295   if (sal_chain)
5296     {
5297       struct sal_chain *tmp_chain;
5298
5299       /* Count the number of entries.  */
5300       for (index = 0, tmp_chain = sal_chain; tmp_chain;
5301            tmp_chain = tmp_chain->next)
5302         index++;
5303
5304       sals.nelts = index;
5305       sals.sals = (struct symtab_and_line *)
5306         xmalloc (index * sizeof (struct symtab_and_line));
5307       for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5308         sals.sals[index] = sal_chain->sal;
5309     }
5310
5311   return sals;
5312 }
5313
5314 static void
5315 ep_skip_leading_whitespace (s)
5316      char **s;
5317 {
5318   if ((s == NULL) || (*s == NULL))
5319     return;
5320   while (isspace (**s))
5321     *s += 1;
5322 }
5323
5324 /* This function examines a string, and attempts to find a token
5325    that might be an event name in the leading characters.  If a
5326    possible match is found, a pointer to the last character of
5327    the token is returned.  Else, NULL is returned. */
5328
5329 static char *
5330 ep_find_event_name_end (arg)
5331      char *arg;
5332 {
5333   char *s = arg;
5334   char *event_name_end = NULL;
5335
5336   /* If we could depend upon the presense of strrpbrk, we'd use that... */
5337   if (arg == NULL)
5338     return NULL;
5339
5340   /* We break out of the loop when we find a token delimiter.
5341      Basically, we're looking for alphanumerics and underscores;
5342      anything else delimites the token. */
5343   while (*s != '\0')
5344     {
5345       if (!isalnum (*s) && (*s != '_'))
5346         break;
5347       event_name_end = s;
5348       s++;
5349     }
5350
5351   return event_name_end;
5352 }
5353
5354
5355 /* This function attempts to parse an optional "if <cond>" clause
5356    from the arg string.  If one is not found, it returns NULL.
5357
5358    Else, it returns a pointer to the condition string.  (It does not
5359    attempt to evaluate the string against a particular block.)  And,
5360    it updates arg to point to the first character following the parsed
5361    if clause in the arg string. */
5362
5363 static char *
5364 ep_parse_optional_if_clause (arg)
5365      char **arg;
5366 {
5367   char *cond_string;
5368
5369   if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5370     return NULL;
5371
5372   /* Skip the "if" keyword. */
5373   (*arg) += 2;
5374
5375   /* Skip any extra leading whitespace, and record the start of the
5376      condition string. */
5377   ep_skip_leading_whitespace (arg);
5378   cond_string = *arg;
5379
5380   /* Assume that the condition occupies the remainder of the arg string. */
5381   (*arg) += strlen (cond_string);
5382
5383   return cond_string;
5384 }
5385
5386 /* This function attempts to parse an optional filename from the arg
5387    string.  If one is not found, it returns NULL.
5388
5389    Else, it returns a pointer to the parsed filename.  (This function
5390    makes no attempt to verify that a file of that name exists, or is
5391    accessible.)  And, it updates arg to point to the first character
5392    following the parsed filename in the arg string.
5393
5394    Note that clients needing to preserve the returned filename for
5395    future access should copy it to their own buffers. */
5396 static char *
5397 ep_parse_optional_filename (arg)
5398      char **arg;
5399 {
5400   static char filename[1024];
5401   char *arg_p = *arg;
5402   int i;
5403   char c;
5404
5405   if ((*arg_p == '\0') || isspace (*arg_p))
5406     return NULL;
5407
5408   for (i = 0;; i++)
5409     {
5410       c = *arg_p;
5411       if (isspace (c))
5412         c = '\0';
5413       filename[i] = c;
5414       if (c == '\0')
5415         break;
5416       arg_p++;
5417     }
5418   *arg = arg_p;
5419
5420   return filename;
5421 }
5422
5423 /* Commands to deal with catching events, such as signals, exceptions,
5424    process start/exit, etc.  */
5425
5426 typedef enum
5427 {
5428   catch_fork, catch_vfork
5429 }
5430 catch_fork_kind;
5431
5432 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5433 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind, 
5434                                           char *arg, 
5435                                           int tempflag, 
5436                                           int from_tty));
5437
5438 static void
5439 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
5440      catch_fork_kind fork_kind;
5441      char *arg;
5442      int tempflag;
5443      int from_tty;
5444 {
5445   char *cond_string = NULL;
5446
5447   ep_skip_leading_whitespace (&arg);
5448
5449   /* The allowed syntax is:
5450      catch [v]fork
5451      catch [v]fork if <cond>
5452
5453      First, check if there's an if clause. */
5454   cond_string = ep_parse_optional_if_clause (&arg);
5455
5456   if ((*arg != '\0') && !isspace (*arg))
5457     error ("Junk at end of arguments.");
5458
5459   /* If this target supports it, create a fork or vfork catchpoint
5460      and enable reporting of such events. */
5461   switch (fork_kind)
5462     {
5463     case catch_fork:
5464       create_fork_event_catchpoint (tempflag, cond_string);
5465       break;
5466     case catch_vfork:
5467       create_vfork_event_catchpoint (tempflag, cond_string);
5468       break;
5469     default:
5470       error ("unsupported or unknown fork kind; cannot catch it");
5471       break;
5472     }
5473 }
5474 #endif
5475
5476 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5477 static void
5478 catch_exec_command_1 (arg, tempflag, from_tty)
5479      char *arg;
5480      int tempflag;
5481      int from_tty;
5482 {
5483   char *cond_string = NULL;
5484
5485   ep_skip_leading_whitespace (&arg);
5486
5487   /* The allowed syntax is:
5488      catch exec
5489      catch exec if <cond>
5490
5491      First, check if there's an if clause. */
5492   cond_string = ep_parse_optional_if_clause (&arg);
5493
5494   if ((*arg != '\0') && !isspace (*arg))
5495     error ("Junk at end of arguments.");
5496
5497   /* If this target supports it, create an exec catchpoint
5498      and enable reporting of such events. */
5499   create_exec_event_catchpoint (tempflag, cond_string);
5500 }
5501 #endif
5502
5503 #if defined(SOLIB_ADD)
5504 static void
5505 catch_load_command_1 (arg, tempflag, from_tty)
5506      char *arg;
5507      int tempflag;
5508      int from_tty;
5509 {
5510   char *dll_pathname = NULL;
5511   char *cond_string = NULL;
5512
5513   ep_skip_leading_whitespace (&arg);
5514
5515   /* The allowed syntax is:
5516      catch load
5517      catch load if <cond>
5518      catch load <filename>
5519      catch load <filename> if <cond>
5520
5521      The user is not allowed to specify the <filename> after an
5522      if clause.
5523
5524      We'll ignore the pathological case of a file named "if".
5525
5526      First, check if there's an if clause.  If so, then there
5527      cannot be a filename. */
5528   cond_string = ep_parse_optional_if_clause (&arg);
5529
5530   /* If there was an if clause, then there cannot be a filename.
5531      Else, there might be a filename and an if clause. */
5532   if (cond_string == NULL)
5533     {
5534       dll_pathname = ep_parse_optional_filename (&arg);
5535       ep_skip_leading_whitespace (&arg);
5536       cond_string = ep_parse_optional_if_clause (&arg);
5537     }
5538
5539   if ((*arg != '\0') && !isspace (*arg))
5540     error ("Junk at end of arguments.");
5541
5542   /* Create a load breakpoint that only triggers when a load of
5543      the specified dll (or any dll, if no pathname was specified)
5544      occurs. */
5545   SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag, 
5546                                 dll_pathname, cond_string);
5547 }
5548
5549 static void
5550 catch_unload_command_1 (arg, tempflag, from_tty)
5551      char *arg;
5552      int tempflag;
5553      int from_tty;
5554 {
5555   char *dll_pathname = NULL;
5556   char *cond_string = NULL;
5557
5558   ep_skip_leading_whitespace (&arg);
5559
5560   /* The allowed syntax is:
5561      catch unload
5562      catch unload if <cond>
5563      catch unload <filename>
5564      catch unload <filename> if <cond>
5565
5566      The user is not allowed to specify the <filename> after an
5567      if clause.
5568
5569      We'll ignore the pathological case of a file named "if".
5570
5571      First, check if there's an if clause.  If so, then there
5572      cannot be a filename. */
5573   cond_string = ep_parse_optional_if_clause (&arg);
5574
5575   /* If there was an if clause, then there cannot be a filename.
5576      Else, there might be a filename and an if clause. */
5577   if (cond_string == NULL)
5578     {
5579       dll_pathname = ep_parse_optional_filename (&arg);
5580       ep_skip_leading_whitespace (&arg);
5581       cond_string = ep_parse_optional_if_clause (&arg);
5582     }
5583
5584   if ((*arg != '\0') && !isspace (*arg))
5585     error ("Junk at end of arguments.");
5586
5587   /* Create an unload breakpoint that only triggers when an unload of
5588      the specified dll (or any dll, if no pathname was specified)
5589      occurs. */
5590   SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag, 
5591                                   dll_pathname, cond_string);
5592 }
5593 #endif /* SOLIB_ADD */
5594
5595 /* Commands to deal with catching exceptions.  */
5596
5597 /* Set a breakpoint at the specified callback routine for an
5598    exception event callback */
5599
5600 static void
5601 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
5602      int tempflag;
5603      char *cond_string;
5604      enum exception_event_kind ex_event;
5605      struct symtab_and_line *sal;
5606 {
5607   struct breakpoint *b;
5608   int thread = -1;              /* All threads. */
5609
5610   if (!sal)                     /* no exception support? */
5611     return;
5612
5613   b = set_raw_breakpoint (*sal);
5614   set_breakpoint_count (breakpoint_count + 1);
5615   b->number = breakpoint_count;
5616   b->cond = NULL;
5617   b->cond_string = (cond_string == NULL) ? 
5618     NULL : savestring (cond_string, strlen (cond_string));
5619   b->thread = thread;
5620   b->addr_string = NULL;
5621   b->enable = enabled;
5622   b->disposition = tempflag ? del : donttouch;
5623   switch (ex_event)
5624     {
5625     case EX_EVENT_THROW:
5626       b->type = bp_catch_throw;
5627       break;
5628     case EX_EVENT_CATCH:
5629       b->type = bp_catch_catch;
5630       break;
5631     default:                    /* error condition */
5632       b->type = bp_none;
5633       b->enable = disabled;
5634       error ("Internal error -- invalid catchpoint kind");
5635     }
5636   mention (b);
5637 }
5638
5639 /* Deal with "catch catch" and "catch throw" commands */
5640
5641 static void
5642 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
5643      enum exception_event_kind ex_event;
5644      char *arg;
5645      int tempflag;
5646      int from_tty;
5647 {
5648   char *cond_string = NULL;
5649   struct symtab_and_line *sal = NULL;
5650
5651   ep_skip_leading_whitespace (&arg);
5652
5653   cond_string = ep_parse_optional_if_clause (&arg);
5654
5655   if ((*arg != '\0') && !isspace (*arg))
5656     error ("Junk at end of arguments.");
5657
5658   if ((ex_event != EX_EVENT_THROW) &&
5659       (ex_event != EX_EVENT_CATCH))
5660     error ("Unsupported or unknown exception event; cannot catch it");
5661
5662   /* See if we can find a callback routine */
5663   sal = target_enable_exception_callback (ex_event, 1);
5664
5665   if (sal)
5666     {
5667       /* We have callbacks from the runtime system for exceptions.
5668          Set a breakpoint on the sal found, if no errors */
5669       if (sal != (struct symtab_and_line *) -1)
5670         create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
5671       else
5672         return;         /* something went wrong with setting up callbacks */
5673     }
5674   else
5675     {
5676       /* No callbacks from runtime system for exceptions.
5677          Try GNU C++ exception breakpoints using labels in debug info. */
5678       if (ex_event == EX_EVENT_CATCH)
5679         {
5680           handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5681         }
5682       else if (ex_event == EX_EVENT_THROW)
5683         {
5684           /* Set a breakpoint on __raise_exception () */
5685
5686           warning ("Unsupported with this platform/compiler combination.");
5687           warning ("Perhaps you can achieve the effect you want by setting");
5688           warning ("a breakpoint on __raise_exception().");
5689         }
5690     }
5691 }
5692
5693 /* Cover routine to allow wrapping target_enable_exception_catchpoints
5694    inside a catch_errors */
5695
5696 static int
5697 cover_target_enable_exception_callback (arg)
5698      PTR arg;
5699 {
5700   args_for_catchpoint_enable *args = arg;
5701   struct symtab_and_line *sal;
5702   sal = target_enable_exception_callback (args->kind, args->enable);
5703   if (sal == NULL)
5704     return 0;
5705   else if (sal == (struct symtab_and_line *) -1)
5706     return -1;
5707   else
5708     return 1;                   /*is valid */
5709 }
5710
5711
5712
5713 /* This is the original v.4.16 and earlier version of the
5714    catch_command_1() function.  Now that other flavours of "catch"
5715    have been introduced, and since exception handling can be handled
5716    in other ways (through target ops) also, this is used only for the
5717    GNU C++ exception handling system.
5718    Note: Only the "catch" flavour of GDB 4.16 is handled here.  The
5719    "catch NAME" is now no longer allowed in catch_command_1().  Also,
5720    there was no code in GDB 4.16 for "catch throw". 
5721
5722    Called from catch_exception_command_1 () */
5723
5724
5725 static void
5726 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5727      char *arg;
5728      int tempflag;
5729      int from_tty;
5730 {
5731   /* First, translate ARG into something we can deal with in terms
5732      of breakpoints.  */
5733
5734   struct symtabs_and_lines sals;
5735   struct symtab_and_line sal;
5736   register struct expression *cond = 0;
5737   register struct breakpoint *b;
5738   char *save_arg;
5739   int i;
5740
5741   INIT_SAL (&sal);              /* initialize to zeroes */
5742
5743   /* If no arg given, or if first arg is 'if ', all active catch clauses
5744      are breakpointed. */
5745
5746   if (!arg || (arg[0] == 'i' && arg[1] == 'f'
5747                && (arg[2] == ' ' || arg[2] == '\t')))
5748     {
5749       /* Grab all active catch clauses.  */
5750       sals = get_catch_sals (0);
5751     }
5752   else
5753     {
5754       /* Grab selected catch clauses.  */
5755       error ("catch NAME not implemented");
5756
5757 #if 0
5758       /* Not sure why this code has been disabled. I'm leaving
5759          it disabled.  We can never come here now anyway
5760          since we don't allow the "catch NAME" syntax.
5761          pai/1997-07-11 */
5762
5763       /* This isn't used; I don't know what it was for.  */
5764       sals = map_catch_names (arg, catch_breakpoint);
5765 #endif
5766     }
5767
5768   if (!sals.nelts)
5769     return;
5770
5771   save_arg = arg;
5772   for (i = 0; i < sals.nelts; i++)
5773     {
5774       resolve_sal_pc (&sals.sals[i]);
5775
5776       while (arg && *arg)
5777         {
5778           if (arg[0] == 'i' && arg[1] == 'f'
5779               && (arg[2] == ' ' || arg[2] == '\t'))
5780             cond = parse_exp_1 ((arg += 2, &arg),
5781                                 block_for_pc (sals.sals[i].pc), 0);
5782           else
5783             error ("Junk at end of arguments.");
5784         }
5785       arg = save_arg;
5786     }
5787
5788   for (i = 0; i < sals.nelts; i++)
5789     {
5790       sal = sals.sals[i];
5791
5792       if (from_tty)
5793         describe_other_breakpoints (sal.pc, sal.section);
5794
5795       b = set_raw_breakpoint (sal);
5796       set_breakpoint_count (breakpoint_count + 1);
5797       b->number = breakpoint_count;
5798
5799       /* Important -- this is an ordinary breakpoint.  For platforms
5800          with callback support for exceptions,
5801          create_exception_catchpoint() will create special bp types
5802          (bp_catch_catch and bp_catch_throw), and there is code in
5803          insert_breakpoints() and elsewhere that depends on that. */
5804       b->type = bp_breakpoint;  
5805
5806       b->cond = cond;
5807       b->enable = enabled;
5808       b->disposition = tempflag ? del : donttouch;
5809
5810       mention (b);
5811     }
5812
5813   if (sals.nelts > 1)
5814     {
5815       warning ("Multiple breakpoints were set.");
5816       warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5817     }
5818   free ((PTR) sals.sals);
5819 }
5820
5821 #if 0
5822 /* This creates a temporary internal breakpoint
5823    just to placate infrun */
5824 static struct breakpoint *
5825 create_temp_exception_breakpoint (pc)
5826      CORE_ADDR pc;
5827 {
5828   struct symtab_and_line sal;
5829   struct breakpoint *b;
5830
5831   INIT_SAL (&sal);
5832   sal.pc = pc;
5833   sal.symtab = NULL;
5834   sal.line = 0;
5835
5836   b = set_raw_breakpoint (sal);
5837   if (!b)
5838     error ("Internal error -- couldn't set temp exception breakpoint");
5839
5840   b->type = bp_breakpoint;
5841   b->disposition = del;
5842   b->enable = enabled;
5843   b->silent = 1;
5844   b->number = internal_breakpoint_number--;
5845   return b;
5846 }
5847 #endif
5848
5849 static void
5850 catch_command_1 (arg, tempflag, from_tty)
5851      char *arg;
5852      int tempflag;
5853      int from_tty;
5854 {
5855
5856   /* The first argument may be an event name, such as "start" or "load".
5857      If so, then handle it as such.  If it doesn't match an event name,
5858      then attempt to interpret it as an exception name.  (This latter is
5859      the v4.16-and-earlier GDB meaning of the "catch" command.)
5860
5861      First, try to find the bounds of what might be an event name. */
5862   char *arg1_start = arg;
5863   char *arg1_end;
5864   int arg1_length;
5865
5866   if (arg1_start == NULL)
5867     {
5868       /* Old behaviour was to use pre-v-4.16 syntax */
5869       /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5870       /* return; */
5871       /* Now, this is not allowed */
5872       error ("Catch requires an event name.");
5873
5874     }
5875   arg1_end = ep_find_event_name_end (arg1_start);
5876   if (arg1_end == NULL)
5877     error ("catch requires an event");
5878   arg1_length = arg1_end + 1 - arg1_start;
5879
5880   /* Try to match what we found against known event names. */
5881   if (strncmp (arg1_start, "signal", arg1_length) == 0)
5882     {
5883       error ("Catch of signal not yet implemented");
5884     }
5885   else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5886     {
5887       catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1, 
5888                                  tempflag, from_tty);
5889     }
5890   else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5891     {
5892       catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1, 
5893                                  tempflag, from_tty);
5894     }
5895   else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5896     {
5897       error ("Catch of thread_start not yet implemented");
5898     }
5899   else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5900     {
5901       error ("Catch of thread_exit not yet implemented");
5902     }
5903   else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5904     {
5905       error ("Catch of thread_join not yet implemented");
5906     }
5907   else if (strncmp (arg1_start, "start", arg1_length) == 0)
5908     {
5909       error ("Catch of start not yet implemented");
5910     }
5911   else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5912     {
5913       error ("Catch of exit not yet implemented");
5914     }
5915   else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5916     {
5917 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
5918       catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
5919 #else
5920       error ("Catch of fork not yet implemented");
5921 #endif
5922     }
5923   else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5924     {
5925 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
5926       catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
5927 #else
5928       error ("Catch of vfork not yet implemented");
5929 #endif
5930     }
5931   else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5932     {
5933 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5934       catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
5935 #else
5936       error ("Catch of exec not yet implemented");
5937 #endif
5938     }
5939   else if (strncmp (arg1_start, "load", arg1_length) == 0)
5940     {
5941 #if defined(SOLIB_ADD)
5942       catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
5943 #else
5944       error ("Catch of load not implemented");
5945 #endif
5946     }
5947   else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5948     {
5949 #if defined(SOLIB_ADD)
5950       catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
5951 #else
5952       error ("Catch of load not implemented");
5953 #endif
5954     }
5955   else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5956     {
5957       error ("Catch of stop not yet implemented");
5958     }
5959
5960   /* This doesn't appear to be an event name */
5961
5962   else
5963     {
5964       /* Pre-v.4.16 behaviour was to treat the argument
5965          as the name of an exception */
5966       /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5967       /* Now this is not allowed */
5968       error ("Unknown event kind specified for catch");
5969
5970     }
5971 }
5972
5973 /* Used by the gui, could be made a worker for other things. */
5974
5975 struct breakpoint *
5976 set_breakpoint_sal (sal)
5977      struct symtab_and_line sal;
5978 {
5979   struct breakpoint *b;
5980   b = set_raw_breakpoint (sal);
5981   set_breakpoint_count (breakpoint_count + 1);
5982   b->number = breakpoint_count;
5983   b->type = bp_breakpoint;
5984   b->cond = 0;
5985   b->thread = -1;
5986   return b;
5987 }
5988
5989 #if 0
5990 /* These aren't used; I don't know what they were for.  */
5991 /* Disable breakpoints on all catch clauses described in ARGS.  */
5992 static void
5993 disable_catch (args)
5994      char *args;
5995 {
5996   /* Map the disable command to catch clauses described in ARGS.  */
5997 }
5998
5999 /* Enable breakpoints on all catch clauses described in ARGS.  */
6000 static void
6001 enable_catch (args)
6002      char *args;
6003 {
6004   /* Map the disable command to catch clauses described in ARGS.  */
6005 }
6006
6007 /* Delete breakpoints on all catch clauses in the active scope.  */
6008 static void
6009 delete_catch (args)
6010      char *args;
6011 {
6012   /* Map the delete command to catch clauses described in ARGS.  */
6013 }
6014 #endif /* 0 */
6015
6016 static void
6017 catch_command (arg, from_tty)
6018      char *arg;
6019      int from_tty;
6020 {
6021   catch_command_1 (arg, 0, from_tty);
6022 }
6023 \f
6024
6025 static void
6026 tcatch_command (arg, from_tty)
6027      char *arg;
6028      int from_tty;
6029 {
6030   catch_command_1 (arg, 1, from_tty);
6031 }
6032
6033
6034 static void
6035 clear_command (arg, from_tty)
6036      char *arg;
6037      int from_tty;
6038 {
6039   register struct breakpoint *b, *b1;
6040   int default_match;
6041   struct symtabs_and_lines sals;
6042   struct symtab_and_line sal;
6043   register struct breakpoint *found;
6044   int i;
6045
6046   if (arg)
6047     {
6048       sals = decode_line_spec (arg, 1);
6049       default_match = 0;
6050     }
6051   else
6052     {
6053       sals.sals = (struct symtab_and_line *)
6054         xmalloc (sizeof (struct symtab_and_line));
6055       INIT_SAL (&sal);          /* initialize to zeroes */
6056       sal.line = default_breakpoint_line;
6057       sal.symtab = default_breakpoint_symtab;
6058       sal.pc = default_breakpoint_address;
6059       if (sal.symtab == 0)
6060         error ("No source file specified.");
6061
6062       sals.sals[0] = sal;
6063       sals.nelts = 1;
6064
6065       default_match = 1;
6066     }
6067
6068   /* For each line spec given, delete bps which correspond
6069      to it.  We do this in two loops: the first loop looks at
6070      the initial bp(s) in the chain which should be deleted,
6071      the second goes down the rest of the chain looking ahead
6072      one so it can take those bps off the chain without messing
6073      up the chain. */
6074
6075
6076   for (i = 0; i < sals.nelts; i++)
6077     {
6078       /* If exact pc given, clear bpts at that pc.
6079          If line given (pc == 0), clear all bpts on specified line.
6080          If defaulting, clear all bpts on default line
6081          or at default pc.
6082
6083          defaulting    sal.pc != 0    tests to do
6084
6085          0              1             pc
6086          1              1             pc _and_ line
6087          0              0             line
6088          1              0             <can't happen> */
6089
6090       sal = sals.sals[i];
6091       found = (struct breakpoint *) 0;
6092
6093
6094       while (breakpoint_chain
6095       /* Why don't we check here that this is not
6096          a watchpoint, etc., as we do below?
6097          I can't make it fail, but don't know
6098          what's stopping the failure: a watchpoint
6099          of the same address as "sal.pc" should
6100          wind up being deleted. */
6101
6102              && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6103                   (overlay_debugging == 0 ||
6104                    breakpoint_chain->section == sal.section))
6105                  || ((default_match || (0 == sal.pc))
6106                      && breakpoint_chain->source_file != NULL
6107                      && sal.symtab != NULL
6108               && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6109                      && breakpoint_chain->line_number == sal.line)))
6110
6111         {
6112           b1 = breakpoint_chain;
6113           breakpoint_chain = b1->next;
6114           b1->next = found;
6115           found = b1;
6116         }
6117
6118       ALL_BREAKPOINTS (b)
6119
6120         while (b->next
6121                && b->next->type != bp_none
6122                && b->next->type != bp_watchpoint
6123                && b->next->type != bp_hardware_watchpoint
6124                && b->next->type != bp_read_watchpoint
6125                && b->next->type != bp_access_watchpoint
6126                && (((sal.pc && (b->next->address == sal.pc)) &&
6127                     (overlay_debugging == 0 ||
6128                      b->next->section == sal.section))
6129                    || ((default_match || (0 == sal.pc))
6130                        && b->next->source_file != NULL
6131                        && sal.symtab != NULL
6132                        && STREQ (b->next->source_file, sal.symtab->filename)
6133                        && b->next->line_number == sal.line)))
6134
6135
6136         {
6137           b1 = b->next;
6138           b->next = b1->next;
6139           b1->next = found;
6140           found = b1;
6141         }
6142
6143       if (found == 0)
6144         {
6145           if (arg)
6146             error ("No breakpoint at %s.", arg);
6147           else
6148             error ("No breakpoint at this line.");
6149         }
6150
6151       if (found->next)
6152         from_tty = 1;           /* Always report if deleted more than one */
6153       if (from_tty)
6154         printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6155       breakpoints_changed ();
6156       while (found)
6157         {
6158           if (from_tty)
6159             printf_unfiltered ("%d ", found->number);
6160           b1 = found->next;
6161           delete_breakpoint (found);
6162           found = b1;
6163         }
6164       if (from_tty)
6165         putchar_unfiltered ('\n');
6166     }
6167   free ((PTR) sals.sals);
6168 }
6169 \f
6170 /* Delete breakpoint in BS if they are `delete' breakpoints and
6171    all breakpoints that are marked for deletion, whether hit or not.
6172    This is called after any breakpoint is hit, or after errors.  */
6173
6174 void
6175 breakpoint_auto_delete (bs)
6176      bpstat bs;
6177 {
6178   struct breakpoint *b, *temp;
6179
6180   for (; bs; bs = bs->next)
6181     if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6182         && bs->stop)
6183       delete_breakpoint (bs->breakpoint_at);
6184
6185   ALL_BREAKPOINTS_SAFE (b, temp)
6186   {
6187     if (b->disposition == del_at_next_stop)
6188       delete_breakpoint (b);
6189   }
6190 }
6191
6192 /* Delete a breakpoint and clean up all traces of it in the data
6193    structures. */
6194
6195 void
6196 delete_breakpoint (bpt)
6197      struct breakpoint *bpt;
6198 {
6199   register struct breakpoint *b;
6200   register bpstat bs;
6201
6202   if (bpt == NULL)
6203     error ("Internal error (attempted to delete a NULL breakpoint)");
6204
6205
6206   /* Has this bp already been deleted?  This can happen because multiple
6207      lists can hold pointers to bp's.  bpstat lists are especial culprits.
6208
6209      One example of this happening is a watchpoint's scope bp.  When the
6210      scope bp triggers, we notice that the watchpoint is out of scope, and
6211      delete it.  We also delete its scope bp.  But the scope bp is marked
6212      "auto-deleting", and is already on a bpstat.  That bpstat is then
6213      checked for auto-deleting bp's, which are deleted.
6214
6215      A real solution to this problem might involve reference counts in bp's,
6216      and/or giving them pointers back to their referencing bpstat's, and
6217      teaching delete_breakpoint to only free a bp's storage when no more
6218      references were extent.  A cheaper bandaid was chosen. */
6219   if (bpt->type == bp_none)
6220     return;
6221
6222   if (delete_breakpoint_hook)
6223     delete_breakpoint_hook (bpt);
6224   breakpoint_delete_event (bpt->number);
6225
6226   if (bpt->inserted)
6227     remove_breakpoint (bpt, mark_uninserted);
6228
6229   if (breakpoint_chain == bpt)
6230     breakpoint_chain = bpt->next;
6231
6232   /* If we have callback-style exception catchpoints, don't go through
6233      the adjustments to the C++ runtime library etc. if the inferior
6234      isn't actually running.  target_enable_exception_callback for a
6235      null target ops vector gives an undesirable error message, so we
6236      check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6237      exceptions are supported in this way, it's OK for now. FIXME */
6238   if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6239     {
6240       static char message1[] = "Error in deleting catchpoint %d:\n";
6241       static char message[sizeof (message1) + 30];
6242       args_for_catchpoint_enable args;
6243
6244       /* Format possible error msg */
6245       sprintf (message, message1, bpt->number);
6246       args.kind = bpt->type == bp_catch_catch ? 
6247         EX_EVENT_CATCH : EX_EVENT_THROW;
6248       args.enable = 0;
6249       catch_errors (cover_target_enable_exception_callback, &args,
6250                     message, RETURN_MASK_ALL);
6251     }
6252
6253
6254   ALL_BREAKPOINTS (b)
6255     if (b->next == bpt)
6256     {
6257       b->next = bpt->next;
6258       break;
6259     }
6260
6261   /* Before turning off the visuals for the bp, check to see that
6262      there are no other bps at the same address. */
6263   if (tui_version)
6264     {
6265       int clearIt;
6266
6267       ALL_BREAKPOINTS (b)
6268       {
6269         clearIt = (b->address != bpt->address);
6270         if (!clearIt)
6271           break;
6272       }
6273
6274       if (clearIt)
6275         {
6276           TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6277           TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6278         }
6279     }
6280
6281   check_duplicates (bpt->address, bpt->section);
6282   /* If this breakpoint was inserted, and there is another breakpoint
6283      at the same address, we need to insert the other breakpoint.  */
6284   if (bpt->inserted
6285       && bpt->type != bp_hardware_watchpoint
6286       && bpt->type != bp_read_watchpoint
6287       && bpt->type != bp_access_watchpoint
6288       && bpt->type != bp_catch_fork
6289       && bpt->type != bp_catch_vfork
6290       && bpt->type != bp_catch_exec)
6291     {
6292       ALL_BREAKPOINTS (b)
6293         if (b->address == bpt->address
6294             && b->section == bpt->section
6295             && !b->duplicate
6296             && b->enable != disabled
6297             && b->enable != shlib_disabled
6298             && b->enable != call_disabled)
6299         {
6300           int val;
6301
6302           /* We should never reach this point if there is a permanent
6303              breakpoint at the same address as the one being deleted.
6304              If there is a permanent breakpoint somewhere, it should
6305              always be the only one inserted.  */
6306           if (b->enable == permanent)
6307             internal_error ("another breakpoint was inserted on top of "
6308                             "a permanent breakpoint");
6309
6310           if (b->type == bp_hardware_breakpoint)
6311             val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6312           else
6313             val = target_insert_breakpoint (b->address, b->shadow_contents);
6314
6315           if (val != 0)
6316             {
6317               target_terminal_ours_for_output ();
6318               warning ("Cannot insert breakpoint %d:", b->number);
6319               memory_error (val, b->address);   /* which bombs us out */
6320             }
6321           else
6322             b->inserted = 1;
6323         }
6324     }
6325
6326   free_command_lines (&bpt->commands);
6327   if (bpt->cond)
6328     free (bpt->cond);
6329   if (bpt->cond_string != NULL)
6330     free (bpt->cond_string);
6331   if (bpt->addr_string != NULL)
6332     free (bpt->addr_string);
6333   if (bpt->exp != NULL)
6334     free (bpt->exp);
6335   if (bpt->exp_string != NULL)
6336     free (bpt->exp_string);
6337   if (bpt->val != NULL)
6338     value_free (bpt->val);
6339   if (bpt->source_file != NULL)
6340     free (bpt->source_file);
6341   if (bpt->dll_pathname != NULL)
6342     free (bpt->dll_pathname);
6343   if (bpt->triggered_dll_pathname != NULL)
6344     free (bpt->triggered_dll_pathname);
6345   if (bpt->exec_pathname != NULL)
6346     free (bpt->exec_pathname);
6347
6348   /* Be sure no bpstat's are pointing at it after it's been freed.  */
6349   /* FIXME, how can we find all bpstat's?
6350      We just check stop_bpstat for now.  */
6351   for (bs = stop_bpstat; bs; bs = bs->next)
6352     if (bs->breakpoint_at == bpt)
6353       {
6354         bs->breakpoint_at = NULL;
6355
6356         /* we'd call bpstat_clear_actions, but that free's stuff and due
6357            to the multiple pointers pointing to one item with no
6358            reference counts found anywhere through out the bpstat's (how
6359            do you spell fragile?), we don't want to free things twice --
6360            better a memory leak than a corrupt malloc pool! */
6361         bs->commands = NULL;
6362         bs->old_val = NULL;
6363       }
6364   /* On the chance that someone will soon try again to delete this same
6365      bp, we mark it as deleted before freeing its storage. */
6366   bpt->type = bp_none;
6367
6368   free ((PTR) bpt);
6369 }
6370
6371 void
6372 delete_command (arg, from_tty)
6373      char *arg;
6374      int from_tty;
6375 {
6376   struct breakpoint *b, *temp;
6377
6378   if (arg == 0)
6379     {
6380       int breaks_to_delete = 0;
6381
6382       /* Delete all breakpoints if no argument.
6383          Do not delete internal or call-dummy breakpoints, these
6384          have to be deleted with an explicit breakpoint number argument.  */
6385       ALL_BREAKPOINTS (b)
6386       {
6387         if (b->type != bp_call_dummy &&
6388             b->type != bp_shlib_event &&
6389             b->type != bp_thread_event &&
6390             b->number >= 0)
6391           breaks_to_delete = 1;
6392       }
6393
6394       /* Ask user only if there are some breakpoints to delete.  */
6395       if (!from_tty
6396           || (breaks_to_delete && query ("Delete all breakpoints? ")))
6397         {
6398           ALL_BREAKPOINTS_SAFE (b, temp)
6399           {
6400             if (b->type != bp_call_dummy &&
6401                 b->type != bp_shlib_event &&
6402                 b->type != bp_thread_event &&
6403                 b->number >= 0)
6404               delete_breakpoint (b);
6405           }
6406         }
6407     }
6408   else
6409     map_breakpoint_numbers (arg, delete_breakpoint);
6410 }
6411
6412 /* Reset a breakpoint given it's struct breakpoint * BINT.
6413    The value we return ends up being the return value from catch_errors.
6414    Unused in this case.  */
6415
6416 static int
6417 breakpoint_re_set_one (bint)
6418      PTR bint;
6419 {
6420   /* get past catch_errs */
6421   struct breakpoint *b = (struct breakpoint *) bint;
6422   struct value *mark;
6423   int i;
6424   struct symtabs_and_lines sals;
6425   char *s;
6426   enum enable save_enable;
6427
6428   switch (b->type)
6429     {
6430     case bp_none:
6431       warning ("attempted to reset apparently deleted breakpoint #%d?",
6432                b->number);
6433       return 0;
6434     case bp_breakpoint:
6435     case bp_hardware_breakpoint:
6436     case bp_catch_load:
6437     case bp_catch_unload:
6438       if (b->addr_string == NULL)
6439         {
6440           /* Anything without a string can't be re-set. */
6441           delete_breakpoint (b);
6442           return 0;
6443         }
6444       /* In case we have a problem, disable this breakpoint.  We'll restore
6445          its status if we succeed.  */
6446       save_enable = b->enable;
6447       b->enable = disabled;
6448
6449       set_language (b->language);
6450       input_radix = b->input_radix;
6451       s = b->addr_string;
6452       sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6453       for (i = 0; i < sals.nelts; i++)
6454         {
6455           resolve_sal_pc (&sals.sals[i]);
6456
6457           /* Reparse conditions, they might contain references to the
6458              old symtab.  */
6459           if (b->cond_string != NULL)
6460             {
6461               s = b->cond_string;
6462               if (b->cond)
6463                 free ((PTR) b->cond);
6464               b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6465             }
6466
6467           /* We need to re-set the breakpoint if the address changes... */
6468           if (b->address != sals.sals[i].pc
6469           /* ...or new and old breakpoints both have source files, and
6470              the source file name or the line number changes...  */
6471               || (b->source_file != NULL
6472                   && sals.sals[i].symtab != NULL
6473                   && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6474                       || b->line_number != sals.sals[i].line)
6475               )
6476           /* ...or we switch between having a source file and not having
6477              one.  */
6478               || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6479             )
6480             {
6481               if (b->source_file != NULL)
6482                 free (b->source_file);
6483               if (sals.sals[i].symtab == NULL)
6484                 b->source_file = NULL;
6485               else
6486                 b->source_file =
6487                   savestring (sals.sals[i].symtab->filename,
6488                               strlen (sals.sals[i].symtab->filename));
6489               b->line_number = sals.sals[i].line;
6490               b->address = sals.sals[i].pc;
6491
6492               /* Used to check for duplicates here, but that can
6493                  cause trouble, as it doesn't check for disable
6494                  breakpoints. */
6495
6496               mention (b);
6497
6498               /* Might be better to do this just once per breakpoint_re_set,
6499                  rather than once for every breakpoint.  */
6500               breakpoints_changed ();
6501             }
6502           b->section = sals.sals[i].section;
6503           b->enable = save_enable;      /* Restore it, this worked. */
6504
6505
6506           /* Now that this is re-enabled, check_duplicates
6507              can be used. */
6508           check_duplicates (b->address, b->section);
6509
6510         }
6511       free ((PTR) sals.sals);
6512       break;
6513
6514     case bp_watchpoint:
6515     case bp_hardware_watchpoint:
6516     case bp_read_watchpoint:
6517     case bp_access_watchpoint:
6518       innermost_block = NULL;
6519       /* The issue arises of what context to evaluate this in.  The
6520          same one as when it was set, but what does that mean when
6521          symbols have been re-read?  We could save the filename and
6522          functionname, but if the context is more local than that, the
6523          best we could do would be something like how many levels deep
6524          and which index at that particular level, but that's going to
6525          be less stable than filenames or function names.  */
6526
6527       /* So for now, just use a global context.  */
6528       if (b->exp)
6529         free ((PTR) b->exp);
6530       b->exp = parse_expression (b->exp_string);
6531       b->exp_valid_block = innermost_block;
6532       mark = value_mark ();
6533       if (b->val)
6534         value_free (b->val);
6535       b->val = evaluate_expression (b->exp);
6536       release_value (b->val);
6537       if (VALUE_LAZY (b->val))
6538         value_fetch_lazy (b->val);
6539
6540       if (b->cond_string != NULL)
6541         {
6542           s = b->cond_string;
6543           if (b->cond)
6544             free ((PTR) b->cond);
6545           b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6546         }
6547       if (b->enable == enabled)
6548         mention (b);
6549       value_free_to_mark (mark);
6550       break;
6551     case bp_catch_catch:
6552     case bp_catch_throw:
6553       break;
6554       /* We needn't really do anything to reset these, since the mask
6555          that requests them is unaffected by e.g., new libraries being
6556          loaded. */
6557     case bp_catch_fork:
6558     case bp_catch_vfork:
6559     case bp_catch_exec:
6560       break;
6561
6562     default:
6563       printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6564       /* fall through */
6565       /* Delete longjmp breakpoints, they will be reset later by
6566          breakpoint_re_set.  */
6567     case bp_longjmp:
6568     case bp_longjmp_resume:
6569       delete_breakpoint (b);
6570       break;
6571
6572       /* This breakpoint is special, it's set up when the inferior
6573          starts and we really don't want to touch it.  */
6574     case bp_shlib_event:
6575
6576       /* Like bp_shlib_event, this breakpoint type is special.
6577          Once it is set up, we do not want to touch it.  */
6578     case bp_thread_event:
6579
6580       /* Keep temporary breakpoints, which can be encountered when we step
6581          over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6582          Otherwise these should have been blown away via the cleanup chain
6583          or by breakpoint_init_inferior when we rerun the executable.  */
6584     case bp_until:
6585     case bp_finish:
6586     case bp_watchpoint_scope:
6587     case bp_call_dummy:
6588     case bp_step_resume:
6589       break;
6590     }
6591
6592   return 0;
6593 }
6594
6595 /* Re-set all breakpoints after symbols have been re-loaded.  */
6596 void
6597 breakpoint_re_set ()
6598 {
6599   struct breakpoint *b, *temp;
6600   enum language save_language;
6601   int save_input_radix;
6602   static char message1[] = "Error in re-setting breakpoint %d:\n";
6603   char message[sizeof (message1) + 30 /* slop */ ];
6604
6605   save_language = current_language->la_language;
6606   save_input_radix = input_radix;
6607   ALL_BREAKPOINTS_SAFE (b, temp)
6608   {
6609     /* Format possible error msg */
6610     sprintf (message, message1, b->number);
6611     catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6612   }
6613   set_language (save_language);
6614   input_radix = save_input_radix;
6615
6616 #ifdef GET_LONGJMP_TARGET
6617   create_longjmp_breakpoint ("longjmp");
6618   create_longjmp_breakpoint ("_longjmp");
6619   create_longjmp_breakpoint ("siglongjmp");
6620   create_longjmp_breakpoint ("_siglongjmp");
6621   create_longjmp_breakpoint (NULL);
6622 #endif
6623
6624 #if 0
6625   /* Took this out (temporarily at least), since it produces an extra 
6626      blank line at startup. This messes up the gdbtests. -PB */
6627   /* Blank line to finish off all those mention() messages we just printed.  */
6628   printf_filtered ("\n");
6629 #endif
6630 }
6631 \f
6632 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6633    If from_tty is nonzero, it prints a message to that effect,
6634    which ends with a period (no newline).  */
6635
6636 /* Reset the thread number of this breakpoint:
6637
6638    - If the breakpoint is for all threads, leave it as-is.
6639    - Else, reset it to the current thread for inferior_pid. */
6640 void
6641 breakpoint_re_set_thread (b)
6642      struct breakpoint *b;
6643 {
6644   if (b->thread != -1)
6645     {
6646       if (in_thread_list (inferior_pid))
6647         b->thread = pid_to_thread_id (inferior_pid);
6648     }
6649 }
6650
6651 void
6652 set_ignore_count (bptnum, count, from_tty)
6653      int bptnum, count, from_tty;
6654 {
6655   register struct breakpoint *b;
6656
6657   if (count < 0)
6658     count = 0;
6659
6660   ALL_BREAKPOINTS (b)
6661     if (b->number == bptnum)
6662     {
6663       b->ignore_count = count;
6664       if (!from_tty)
6665         return;
6666       else if (count == 0)
6667         printf_filtered ("Will stop next time breakpoint %d is reached.",
6668                          bptnum);
6669       else if (count == 1)
6670         printf_filtered ("Will ignore next crossing of breakpoint %d.",
6671                          bptnum);
6672       else
6673         printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6674                          count, bptnum);
6675       breakpoints_changed ();
6676       return;
6677     }
6678
6679   error ("No breakpoint number %d.", bptnum);
6680 }
6681
6682 /* Clear the ignore counts of all breakpoints.  */
6683 void
6684 breakpoint_clear_ignore_counts ()
6685 {
6686   struct breakpoint *b;
6687
6688   ALL_BREAKPOINTS (b)
6689     b->ignore_count = 0;
6690 }
6691
6692 /* Command to set ignore-count of breakpoint N to COUNT.  */
6693
6694 static void
6695 ignore_command (args, from_tty)
6696      char *args;
6697      int from_tty;
6698 {
6699   char *p = args;
6700   register int num;
6701
6702   if (p == 0)
6703     error_no_arg ("a breakpoint number");
6704
6705   num = get_number (&p);
6706   if (num == 0)
6707     error ("bad breakpoint number: '%s'", args);
6708   if (*p == 0)
6709     error ("Second argument (specified ignore-count) is missing.");
6710
6711   set_ignore_count (num,
6712                     longest_to_int (value_as_long (parse_and_eval (p))),
6713                     from_tty);
6714   printf_filtered ("\n");
6715   breakpoints_changed ();
6716 }
6717 \f
6718 /* Call FUNCTION on each of the breakpoints
6719    whose numbers are given in ARGS.  */
6720
6721 static void
6722 map_breakpoint_numbers (args, function)
6723      char *args;
6724      void (*function) PARAMS ((struct breakpoint *));
6725 {
6726   register char *p = args;
6727   char *p1;
6728   register int num;
6729   register struct breakpoint *b, *tmp;
6730   int match;
6731
6732   if (p == 0)
6733     error_no_arg ("one or more breakpoint numbers");
6734
6735   while (*p)
6736     {
6737       match = 0;
6738       p1 = p;
6739
6740       num = get_number_or_range (&p1);
6741       if (num == 0)
6742         {
6743           warning ("bad breakpoint number at or near '%s'", p);
6744         }
6745       else
6746         {
6747           ALL_BREAKPOINTS_SAFE (b, tmp)
6748             if (b->number == num)
6749               {
6750                 struct breakpoint *related_breakpoint = b->related_breakpoint;
6751                 match = 1;
6752                 function (b);
6753                 if (related_breakpoint)
6754                   function (related_breakpoint);
6755                 break;
6756               }
6757           if (match == 0)
6758             printf_unfiltered ("No breakpoint number %d.\n", num);
6759         }
6760       p = p1;
6761     }
6762 }
6763
6764 void
6765 disable_breakpoint (bpt)
6766      struct breakpoint *bpt;
6767 {
6768   /* Never disable a watchpoint scope breakpoint; we want to
6769      hit them when we leave scope so we can delete both the
6770      watchpoint and its scope breakpoint at that time.  */
6771   if (bpt->type == bp_watchpoint_scope)
6772     return;
6773
6774   /* You can't disable permanent breakpoints.  */
6775   if (bpt->enable == permanent)
6776     return;
6777
6778   bpt->enable = disabled;
6779
6780   check_duplicates (bpt->address, bpt->section);
6781
6782   if (modify_breakpoint_hook)
6783     modify_breakpoint_hook (bpt);
6784   breakpoint_modify_event (bpt->number);
6785 }
6786
6787 /* ARGSUSED */
6788 static void
6789 disable_command (args, from_tty)
6790      char *args;
6791      int from_tty;
6792 {
6793   register struct breakpoint *bpt;
6794   if (args == 0)
6795     ALL_BREAKPOINTS (bpt)
6796       switch (bpt->type)
6797       {
6798       case bp_none:
6799         warning ("attempted to disable apparently deleted breakpoint #%d?",
6800                  bpt->number);
6801         continue;
6802       case bp_breakpoint:
6803       case bp_catch_load:
6804       case bp_catch_unload:
6805       case bp_catch_fork:
6806       case bp_catch_vfork:
6807       case bp_catch_exec:
6808       case bp_catch_catch:
6809       case bp_catch_throw:
6810       case bp_hardware_breakpoint:
6811       case bp_watchpoint:
6812       case bp_hardware_watchpoint:
6813       case bp_read_watchpoint:
6814       case bp_access_watchpoint:
6815         disable_breakpoint (bpt);
6816       default:
6817         continue;
6818       }
6819   else
6820     map_breakpoint_numbers (args, disable_breakpoint);
6821 }
6822
6823 static void
6824 do_enable_breakpoint (bpt, disposition)
6825      struct breakpoint *bpt;
6826      enum bpdisp disposition;
6827 {
6828   struct frame_info *save_selected_frame = NULL;
6829   int save_selected_frame_level = -1;
6830   int target_resources_ok, other_type_used;
6831   struct value *mark;
6832
6833   if (bpt->type == bp_hardware_breakpoint)
6834     {
6835       int i;
6836       i = hw_breakpoint_used_count ();
6837       target_resources_ok = 
6838         TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, 
6839                                             i + 1, 0);
6840       if (target_resources_ok == 0)
6841         error ("No hardware breakpoint support in the target.");
6842       else if (target_resources_ok < 0)
6843         error ("Hardware breakpoints used exceeds limit.");
6844     }
6845
6846   if (bpt->enable != permanent)
6847     bpt->enable = enabled;
6848   bpt->disposition = disposition;
6849   check_duplicates (bpt->address, bpt->section);
6850   breakpoints_changed ();
6851
6852   if (bpt->type == bp_watchpoint || 
6853       bpt->type == bp_hardware_watchpoint ||
6854       bpt->type == bp_read_watchpoint || 
6855       bpt->type == bp_access_watchpoint)
6856     {
6857       if (bpt->exp_valid_block != NULL)
6858         {
6859           struct frame_info *fr =
6860
6861           /* Ensure that we have the current frame.  Else, this
6862              next query may pessimistically be answered as, "No,
6863              not within current scope". */
6864           get_current_frame ();
6865           fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
6866           if (fr == NULL)
6867             {
6868               printf_filtered ("\
6869 Cannot enable watchpoint %d because the block in which its expression\n\
6870 is valid is not currently in scope.\n", bpt->number);
6871               bpt->enable = disabled;
6872               return;
6873             }
6874
6875           save_selected_frame = selected_frame;
6876           save_selected_frame_level = selected_frame_level;
6877           select_frame (fr, -1);
6878         }
6879
6880       value_free (bpt->val);
6881       mark = value_mark ();
6882       bpt->val = evaluate_expression (bpt->exp);
6883       release_value (bpt->val);
6884       if (VALUE_LAZY (bpt->val))
6885         value_fetch_lazy (bpt->val);
6886
6887       if (bpt->type == bp_hardware_watchpoint ||
6888           bpt->type == bp_read_watchpoint ||
6889           bpt->type == bp_access_watchpoint)
6890         {
6891           int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6892           int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6893
6894           /* Hack around 'unused var' error for some targets here */
6895           (void) mem_cnt, i;
6896           target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
6897                                    bpt->type, i + mem_cnt, other_type_used);
6898           /* we can consider of type is bp_hardware_watchpoint, convert to 
6899              bp_watchpoint in the following condition */
6900           if (target_resources_ok < 0)
6901             {
6902               printf_filtered ("\
6903 Cannot enable watchpoint %d because target watch resources\n\
6904 have been allocated for other watchpoints.\n", bpt->number);
6905               bpt->enable = disabled;
6906               value_free_to_mark (mark);
6907               return;
6908             }
6909         }
6910
6911       if (save_selected_frame_level >= 0)
6912         select_and_print_frame (save_selected_frame,
6913                                 save_selected_frame_level);
6914       value_free_to_mark (mark);
6915     }
6916   if (modify_breakpoint_hook)
6917     modify_breakpoint_hook (bpt);
6918   breakpoint_modify_event (bpt->number);
6919 }
6920
6921 void
6922 enable_breakpoint (bpt)
6923      struct breakpoint *bpt;
6924 {
6925   do_enable_breakpoint (bpt, bpt->disposition);
6926 }
6927
6928 /* The enable command enables the specified breakpoints (or all defined
6929    breakpoints) so they once again become (or continue to be) effective
6930    in stopping the inferior. */
6931
6932 /* ARGSUSED */
6933 static void
6934 enable_command (args, from_tty)
6935      char *args;
6936      int from_tty;
6937 {
6938   register struct breakpoint *bpt;
6939   if (args == 0)
6940     ALL_BREAKPOINTS (bpt)
6941       switch (bpt->type)
6942       {
6943       case bp_none:
6944         warning ("attempted to enable apparently deleted breakpoint #%d?",
6945                  bpt->number);
6946         continue;
6947       case bp_breakpoint:
6948       case bp_catch_load:
6949       case bp_catch_unload:
6950       case bp_catch_fork:
6951       case bp_catch_vfork:
6952       case bp_catch_exec:
6953       case bp_catch_catch:
6954       case bp_catch_throw:
6955       case bp_hardware_breakpoint:
6956       case bp_watchpoint:
6957       case bp_hardware_watchpoint:
6958       case bp_read_watchpoint:
6959       case bp_access_watchpoint:
6960         enable_breakpoint (bpt);
6961       default:
6962         continue;
6963       }
6964   else
6965     map_breakpoint_numbers (args, enable_breakpoint);
6966 }
6967
6968 static void
6969 enable_once_breakpoint (bpt)
6970      struct breakpoint *bpt;
6971 {
6972   do_enable_breakpoint (bpt, disable);
6973 }
6974
6975 /* ARGSUSED */
6976 static void
6977 enable_once_command (args, from_tty)
6978      char *args;
6979      int from_tty;
6980 {
6981   map_breakpoint_numbers (args, enable_once_breakpoint);
6982 }
6983
6984 static void
6985 enable_delete_breakpoint (bpt)
6986      struct breakpoint *bpt;
6987 {
6988   do_enable_breakpoint (bpt, del);
6989 }
6990
6991 /* ARGSUSED */
6992 static void
6993 enable_delete_command (args, from_tty)
6994      char *args;
6995      int from_tty;
6996 {
6997   map_breakpoint_numbers (args, enable_delete_breakpoint);
6998 }
6999 \f
7000 /* Use default_breakpoint_'s, or nothing if they aren't valid.  */
7001
7002 struct symtabs_and_lines
7003 decode_line_spec_1 (string, funfirstline)
7004      char *string;
7005      int funfirstline;
7006 {
7007   struct symtabs_and_lines sals;
7008   if (string == 0)
7009     error ("Empty line specification.");
7010   if (default_breakpoint_valid)
7011     sals = decode_line_1 (&string, funfirstline,
7012                           default_breakpoint_symtab,
7013                           default_breakpoint_line,
7014                           (char ***) NULL);
7015   else
7016     sals = decode_line_1 (&string, funfirstline,
7017                           (struct symtab *) NULL, 0, (char ***) NULL);
7018   if (*string)
7019     error ("Junk at end of line specification: %s", string);
7020   return sals;
7021 }
7022 \f
7023 void
7024 _initialize_breakpoint ()
7025 {
7026   struct cmd_list_element *c;
7027
7028   breakpoint_chain = 0;
7029   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
7030      before a breakpoint is set.  */
7031   breakpoint_count = 0;
7032
7033   add_com ("ignore", class_breakpoint, ignore_command,
7034            "Set ignore-count of breakpoint number N to COUNT.\n\
7035 Usage is `ignore N COUNT'.");
7036   if (xdb_commands)
7037     add_com_alias ("bc", "ignore", class_breakpoint, 1);
7038
7039   add_com ("commands", class_breakpoint, commands_command,
7040            "Set commands to be executed when a breakpoint is hit.\n\
7041 Give breakpoint number as argument after \"commands\".\n\
7042 With no argument, the targeted breakpoint is the last one set.\n\
7043 The commands themselves follow starting on the next line.\n\
7044 Type a line containing \"end\" to indicate the end of them.\n\
7045 Give \"silent\" as the first line to make the breakpoint silent;\n\
7046 then no output is printed when it is hit, except what the commands print.");
7047
7048   add_com ("condition", class_breakpoint, condition_command,
7049            "Specify breakpoint number N to break only if COND is true.\n\
7050 Usage is `condition N COND', where N is an integer and COND is an\n\
7051 expression to be evaluated whenever breakpoint N is reached.  ");
7052
7053   add_com ("tbreak", class_breakpoint, tbreak_command,
7054            "Set a temporary breakpoint.  Args like \"break\" command.\n\
7055 Like \"break\" except the breakpoint is only temporary,\n\
7056 so it will be deleted when hit.  Equivalent to \"break\" followed\n\
7057 by using \"enable delete\" on the breakpoint number.");
7058   add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7059            "Set temporary breakpoint at procedure exit.  Either there should\n\
7060 be no argument or the argument must be a depth.\n");
7061
7062   add_com ("hbreak", class_breakpoint, hbreak_command,
7063            "Set a hardware assisted  breakpoint. Args like \"break\" command.\n\
7064 Like \"break\" except the breakpoint requires hardware support,\n\
7065 some target hardware may not have this support.");
7066
7067   add_com ("thbreak", class_breakpoint, thbreak_command,
7068            "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7069 Like \"hbreak\" except the breakpoint is only temporary,\n\
7070 so it will be deleted when hit.");
7071
7072   add_prefix_cmd ("enable", class_breakpoint, enable_command,
7073                   "Enable some breakpoints.\n\
7074 Give breakpoint numbers (separated by spaces) as arguments.\n\
7075 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7076 This is used to cancel the effect of the \"disable\" command.\n\
7077 With a subcommand you can enable temporarily.",
7078                   &enablelist, "enable ", 1, &cmdlist);
7079   if (xdb_commands)
7080     add_com ("ab", class_breakpoint, enable_command,
7081              "Enable some breakpoints.\n\
7082 Give breakpoint numbers (separated by spaces) as arguments.\n\
7083 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7084 This is used to cancel the effect of the \"disable\" command.\n\
7085 With a subcommand you can enable temporarily.");
7086
7087   add_com_alias ("en", "enable", class_breakpoint, 1);
7088
7089   add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7090                          "Enable some breakpoints.\n\
7091 Give breakpoint numbers (separated by spaces) as arguments.\n\
7092 This is used to cancel the effect of the \"disable\" command.\n\
7093 May be abbreviated to simply \"enable\".\n",
7094                    &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7095
7096   add_cmd ("once", no_class, enable_once_command,
7097            "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
7098 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7099            &enablebreaklist);
7100
7101   add_cmd ("delete", no_class, enable_delete_command,
7102            "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
7103 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7104            &enablebreaklist);
7105
7106   add_cmd ("delete", no_class, enable_delete_command,
7107            "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
7108 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7109            &enablelist);
7110
7111   add_cmd ("once", no_class, enable_once_command,
7112            "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
7113 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7114            &enablelist);
7115
7116   add_prefix_cmd ("disable", class_breakpoint, disable_command,
7117                   "Disable some breakpoints.\n\
7118 Arguments are breakpoint numbers with spaces in between.\n\
7119 To disable all breakpoints, give no argument.\n\
7120 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7121                   &disablelist, "disable ", 1, &cmdlist);
7122   add_com_alias ("dis", "disable", class_breakpoint, 1);
7123   add_com_alias ("disa", "disable", class_breakpoint, 1);
7124   if (xdb_commands)
7125     add_com ("sb", class_breakpoint, disable_command,
7126              "Disable some breakpoints.\n\
7127 Arguments are breakpoint numbers with spaces in between.\n\
7128 To disable all breakpoints, give no argument.\n\
7129 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7130
7131   add_cmd ("breakpoints", class_alias, disable_command,
7132            "Disable some breakpoints.\n\
7133 Arguments are breakpoint numbers with spaces in between.\n\
7134 To disable all breakpoints, give no argument.\n\
7135 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7136 This command may be abbreviated \"disable\".",
7137            &disablelist);
7138
7139   add_prefix_cmd ("delete", class_breakpoint, delete_command,
7140                   "Delete some breakpoints or auto-display expressions.\n\
7141 Arguments are breakpoint numbers with spaces in between.\n\
7142 To delete all breakpoints, give no argument.\n\
7143 \n\
7144 Also a prefix command for deletion of other GDB objects.\n\
7145 The \"unset\" command is also an alias for \"delete\".",
7146                   &deletelist, "delete ", 1, &cmdlist);
7147   add_com_alias ("d", "delete", class_breakpoint, 1);
7148   if (xdb_commands)
7149     add_com ("db", class_breakpoint, delete_command,
7150              "Delete some breakpoints.\n\
7151 Arguments are breakpoint numbers with spaces in between.\n\
7152 To delete all breakpoints, give no argument.\n");
7153
7154   add_cmd ("breakpoints", class_alias, delete_command,
7155            "Delete some breakpoints or auto-display expressions.\n\
7156 Arguments are breakpoint numbers with spaces in between.\n\
7157 To delete all breakpoints, give no argument.\n\
7158 This command may be abbreviated \"delete\".",
7159            &deletelist);
7160
7161   add_com ("clear", class_breakpoint, clear_command,
7162            concat ("Clear breakpoint at specified line or function.\n\
7163 Argument may be line number, function name, or \"*\" and an address.\n\
7164 If line number is specified, all breakpoints in that line are cleared.\n\
7165 If function is specified, breakpoints at beginning of function are cleared.\n\
7166 If an address is specified, breakpoints at that address are cleared.\n\n",
7167                    "With no argument, clears all breakpoints in the line that the selected frame\n\
7168 is executing in.\n\
7169 \n\
7170 See also the \"delete\" command which clears breakpoints by number.", NULL));
7171
7172   add_com ("break", class_breakpoint, break_command,
7173            concat ("Set breakpoint at specified line or function.\n\
7174 Argument may be line number, function name, or \"*\" and an address.\n\
7175 If line number is specified, break at start of code for that line.\n\
7176 If function is specified, break at start of code for that function.\n\
7177 If an address is specified, break at that exact address.\n",
7178                    "With no arg, uses current execution address of selected stack frame.\n\
7179 This is useful for breaking on return to a stack frame.\n\
7180 \n\
7181 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7182 \n\
7183 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7184   add_com_alias ("b", "break", class_run, 1);
7185   add_com_alias ("br", "break", class_run, 1);
7186   add_com_alias ("bre", "break", class_run, 1);
7187   add_com_alias ("brea", "break", class_run, 1);
7188
7189   add_com ("xbreak", class_breakpoint, break_at_finish_command,
7190            concat ("Set breakpoint at procedure exit. \n\
7191 Argument may be function name, or \"*\" and an address.\n\
7192 If function is specified, break at end of code for that function.\n\
7193 If an address is specified, break at the end of the function that contains \n\
7194 that exact address.\n",
7195                    "With no arg, uses current execution address of selected stack frame.\n\
7196 This is useful for breaking on return to a stack frame.\n\
7197 \n\
7198 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7199 \n\
7200 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7201   add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7202   add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7203   add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7204   add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7205
7206   if (xdb_commands)
7207     {
7208       add_com_alias ("ba", "break", class_breakpoint, 1);
7209       add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7210       add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7211                "Set breakpoint at procedure exit.  Either there should\n\
7212 be no argument or the argument must be a depth.\n");
7213     }
7214
7215   if (dbx_commands)
7216     {
7217       add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7218         "Break in function/address or break at a line in the current file.",
7219                              &stoplist, "stop ", 1, &cmdlist);
7220       add_cmd ("in", class_breakpoint, stopin_command,
7221                "Break in function or address.\n", &stoplist);
7222       add_cmd ("at", class_breakpoint, stopat_command,
7223                "Break at a line in the current file.\n", &stoplist);
7224       add_com ("status", class_info, breakpoints_info,
7225                concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7226 The \"Type\" column indicates one of:\n\
7227 \tbreakpoint     - normal breakpoint\n\
7228 \twatchpoint     - watchpoint\n\
7229 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7230 the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
7231 breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
7232 address and file/line number respectively.\n\n",
7233                        "Convenience variable \"$_\" and default examine address for \"x\"\n\
7234 are set to the address of the last breakpoint listed.\n\n\
7235 Convenience variable \"$bpnum\" contains the number of the last\n\
7236 breakpoint set.", NULL));
7237     }
7238
7239   add_info ("breakpoints", breakpoints_info,
7240             concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7241 The \"Type\" column indicates one of:\n\
7242 \tbreakpoint     - normal breakpoint\n\
7243 \twatchpoint     - watchpoint\n\
7244 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7245 the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
7246 breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
7247 address and file/line number respectively.\n\n",
7248                     "Convenience variable \"$_\" and default examine address for \"x\"\n\
7249 are set to the address of the last breakpoint listed.\n\n\
7250 Convenience variable \"$bpnum\" contains the number of the last\n\
7251 breakpoint set.", NULL));
7252
7253   if (xdb_commands)
7254     add_com ("lb", class_breakpoint, breakpoints_info,
7255              concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7256 The \"Type\" column indicates one of:\n\
7257 \tbreakpoint     - normal breakpoint\n\
7258 \twatchpoint     - watchpoint\n\
7259 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7260 the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
7261 breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
7262 address and file/line number respectively.\n\n",
7263                      "Convenience variable \"$_\" and default examine address for \"x\"\n\
7264 are set to the address of the last breakpoint listed.\n\n\
7265 Convenience variable \"$bpnum\" contains the number of the last\n\
7266 breakpoint set.", NULL));
7267
7268   add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7269            concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7270 The \"Type\" column indicates one of:\n\
7271 \tbreakpoint     - normal breakpoint\n\
7272 \twatchpoint     - watchpoint\n\
7273 \tlongjmp        - internal breakpoint used to step through longjmp()\n\
7274 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7275 \tuntil          - internal breakpoint used by the \"until\" command\n\
7276 \tfinish         - internal breakpoint used by the \"finish\" command\n",
7277                    "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7278 the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
7279 breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
7280 address and file/line number respectively.\n\n",
7281                    "Convenience variable \"$_\" and default examine address for \"x\"\n\
7282 are set to the address of the last breakpoint listed.\n\n\
7283 Convenience variable \"$bpnum\" contains the number of the last\n\
7284 breakpoint set.", NULL),
7285            &maintenanceinfolist);
7286
7287   add_com ("catch", class_breakpoint, catch_command,
7288            "Set catchpoints to catch events.\n\
7289 Raised signals may be caught:\n\
7290 \tcatch signal              - all signals\n\
7291 \tcatch signal <signame>    - a particular signal\n\
7292 Raised exceptions may be caught:\n\
7293 \tcatch throw               - all exceptions, when thrown\n\
7294 \tcatch throw <exceptname>  - a particular exception, when thrown\n\
7295 \tcatch catch               - all exceptions, when caught\n\
7296 \tcatch catch <exceptname>  - a particular exception, when caught\n\
7297 Thread or process events may be caught:\n\
7298 \tcatch thread_start        - any threads, just after creation\n\
7299 \tcatch thread_exit         - any threads, just before expiration\n\
7300 \tcatch thread_join         - any threads, just after joins\n\
7301 Process events may be caught:\n\
7302 \tcatch start               - any processes, just after creation\n\
7303 \tcatch exit                - any processes, just before expiration\n\
7304 \tcatch fork                - calls to fork()\n\
7305 \tcatch vfork               - calls to vfork()\n\
7306 \tcatch exec                - calls to exec()\n\
7307 Dynamically-linked library events may be caught:\n\
7308 \tcatch load                - loads of any library\n\
7309 \tcatch load <libname>      - loads of a particular library\n\
7310 \tcatch unload              - unloads of any library\n\
7311 \tcatch unload <libname>    - unloads of a particular library\n\
7312 The act of your program's execution stopping may also be caught:\n\
7313 \tcatch stop\n\n\
7314 C++ exceptions may be caught:\n\
7315 \tcatch throw               - all exceptions, when thrown\n\
7316 \tcatch catch               - all exceptions, when caught\n\
7317 \n\
7318 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7319 after a fork or vfork is caught.\n\n\
7320 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7321
7322   add_com ("tcatch", class_breakpoint, tcatch_command,
7323            "Set temporary catchpoints to catch events.\n\
7324 Args like \"catch\" command.\n\
7325 Like \"catch\" except the catchpoint is only temporary,\n\
7326 so it will be deleted when hit.  Equivalent to \"catch\" followed\n\
7327 by using \"enable delete\" on the catchpoint number.");
7328
7329   add_com ("watch", class_breakpoint, watch_command,
7330            "Set a watchpoint for an expression.\n\
7331 A watchpoint stops execution of your program whenever the value of\n\
7332 an expression changes.");
7333
7334   add_com ("rwatch", class_breakpoint, rwatch_command,
7335            "Set a read watchpoint for an expression.\n\
7336 A watchpoint stops execution of your program whenever the value of\n\
7337 an expression is read.");
7338
7339   add_com ("awatch", class_breakpoint, awatch_command,
7340            "Set a watchpoint for an expression.\n\
7341 A watchpoint stops execution of your program whenever the value of\n\
7342 an expression is either read or written.");
7343
7344   add_info ("watchpoints", breakpoints_info,
7345             "Synonym for ``info breakpoints''.");
7346
7347
7348   c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7349                    (char *) &can_use_hw_watchpoints,
7350                    "Set debugger's willingness to use watchpoint hardware.\n\
7351 If zero, gdb will not use hardware for new watchpoints, even if\n\
7352 such is available.  (However, any hardware watchpoints that were\n\
7353 created before setting this to nonzero, will continue to use watchpoint\n\
7354 hardware.)",
7355                    &setlist);
7356   add_show_from_set (c, &showlist);
7357
7358   can_use_hw_watchpoints = 1;
7359 }