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