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