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