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