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