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