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