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