OSDN Git Service

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