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