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