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