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