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