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