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