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