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