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