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