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