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