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