GDB (xrefs)
/tmp/gdb-7.10/gdb/breakpoint.c
Go to the documentation of this file.
1 /* Everything about breakpoints, for GDB.
2 
3  Copyright (C) 1986-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include <ctype.h>
23 #include "hashtab.h"
24 #include "symtab.h"
25 #include "frame.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
28 #include "gdbtypes.h"
29 #include "expression.h"
30 #include "gdbcore.h"
31 #include "gdbcmd.h"
32 #include "value.h"
33 #include "command.h"
34 #include "inferior.h"
35 #include "infrun.h"
36 #include "gdbthread.h"
37 #include "target.h"
38 #include "language.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
41 #include "annotate.h"
42 #include "symfile.h"
43 #include "objfiles.h"
44 #include "source.h"
45 #include "linespec.h"
46 #include "completer.h"
47 #include "gdb.h"
48 #include "ui-out.h"
49 #include "cli/cli-script.h"
50 #include "block.h"
51 #include "solib.h"
52 #include "solist.h"
53 #include "observer.h"
54 #include "memattr.h"
55 #include "ada-lang.h"
56 #include "top.h"
57 #include "valprint.h"
58 #include "jit.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
61 #include "probe.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
64 #include "stack.h"
65 #include "skip.h"
66 #include "ax-gdb.h"
67 #include "dummy-frame.h"
68 #include "interps.h"
69 #include "format.h"
70 
71 /* readline include files */
72 #include "readline/readline.h"
73 #include "readline/history.h"
74 
75 /* readline defines this. */
76 #undef savestring
77 
78 #include "mi/mi-common.h"
79 #include "extension.h"
80 
81 /* Enums for exception-handling support. */
83 {
87 };
88 
89 /* Prototypes for local functions. */
90 
91 static void enable_delete_command (char *, int);
92 
93 static void enable_once_command (char *, int);
94 
95 static void enable_count_command (char *, int);
96 
97 static void disable_command (char *, int);
98 
99 static void enable_command (char *, int);
100 
101 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
102  void *),
103  void *);
104 
105 static void ignore_command (char *, int);
106 
107 static int breakpoint_re_set_one (void *);
108 
109 static void breakpoint_re_set_default (struct breakpoint *);
110 
111 static void create_sals_from_address_default (char **,
112  struct linespec_result *,
113  enum bptype, char *,
114  char **);
115 
116 static void create_breakpoints_sal_default (struct gdbarch *,
117  struct linespec_result *,
118  char *, char *, enum bptype,
119  enum bpdisp, int, int,
120  int,
121  const struct breakpoint_ops *,
122  int, int, int, unsigned);
123 
124 static void decode_linespec_default (struct breakpoint *, char **,
125  struct symtabs_and_lines *);
126 
127 static void clear_command (char *, int);
128 
129 static void catch_command (char *, int);
130 
131 static int can_use_hardware_watchpoint (struct value *);
132 
133 static void break_command_1 (char *, int, int);
134 
135 static void mention (struct breakpoint *);
136 
138  enum bptype,
139  const struct breakpoint_ops *);
140 static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
141  const struct symtab_and_line *);
142 
143 /* This function is used in gdbtk sources and thus can not be made
144  static. */
146  struct symtab_and_line,
147  enum bptype,
148  const struct breakpoint_ops *);
149 
150 static struct breakpoint *
152  enum bptype type,
153  const struct breakpoint_ops *ops,
154  int loc_enabled);
155 
156 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
157 
159  CORE_ADDR bpaddr,
160  enum bptype bptype);
161 
162 static void describe_other_breakpoints (struct gdbarch *,
163  struct program_space *, CORE_ADDR,
164  struct obj_section *, int);
165 
166 static int watchpoint_locations_match (struct bp_location *loc1,
167  struct bp_location *loc2);
168 
169 static int breakpoint_location_address_match (struct bp_location *bl,
170  struct address_space *aspace,
171  CORE_ADDR addr);
172 
173 static void breakpoints_info (char *, int);
174 
175 static void watchpoints_info (char *, int);
176 
177 static int breakpoint_1 (char *, int,
178  int (*) (const struct breakpoint *));
179 
180 static int breakpoint_cond_eval (void *);
181 
182 static void cleanup_executing_breakpoints (void *);
183 
184 static void commands_command (char *, int);
185 
186 static void condition_command (char *, int);
187 
188 typedef enum
189  {
192  }
194 
195 static int remove_breakpoint (struct bp_location *, insertion_state_t);
196 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
197 
199 
200 static int watchpoint_check (void *);
201 
202 static void maintenance_info_breakpoints (char *, int);
203 
204 static int hw_breakpoint_used_count (void);
205 
206 static int hw_watchpoint_use_count (struct breakpoint *);
207 
208 static int hw_watchpoint_used_count_others (struct breakpoint *except,
209  enum bptype type,
210  int *other_type_used);
211 
212 static void hbreak_command (char *, int);
213 
214 static void thbreak_command (char *, int);
215 
216 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
217  int count);
218 
219 static void stop_command (char *arg, int from_tty);
220 
221 static void stopin_command (char *arg, int from_tty);
222 
223 static void stopat_command (char *arg, int from_tty);
224 
225 static void tcatch_command (char *arg, int from_tty);
226 
227 static void free_bp_location (struct bp_location *loc);
228 static void incref_bp_location (struct bp_location *loc);
229 static void decref_bp_location (struct bp_location **loc);
230 
231 static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
232 
233 /* update_global_location_list's modes of operation wrt to whether to
234  insert locations now. */
236 {
237  /* Don't insert any breakpoint locations into the inferior, only
238  remove already-inserted locations that no longer should be
239  inserted. Functions that delete a breakpoint or breakpoints
240  should specify this mode, so that deleting a breakpoint doesn't
241  have the side effect of inserting the locations of other
242  breakpoints that are marked not-inserted, but should_be_inserted
243  returns true on them.
244 
245  This behavior is useful is situations close to tear-down -- e.g.,
246  after an exec, while the target still has execution, but
247  breakpoint shadows of the previous executable image should *NOT*
248  be restored to the new image; or before detaching, where the
249  target still has execution and wants to delete breakpoints from
250  GDB's lists, and all breakpoints had already been removed from
251  the inferior. */
253 
254  /* May insert breakpoints iff breakpoints_should_be_inserted_now
255  claims breakpoints should be inserted now. */
257 
258  /* Insert locations now, irrespective of
259  breakpoints_should_be_inserted_now. E.g., say all threads are
260  stopped right now, and the user did "continue". We need to
261  insert breakpoints _before_ resuming the target, but
262  UGLL_MAY_INSERT wouldn't insert them, because
263  breakpoints_should_be_inserted_now returns false at that point,
264  as no thread is running yet. */
266 };
267 
269 
271 
272 static int is_hardware_watchpoint (const struct breakpoint *bpt);
273 
274 static void insert_breakpoint_locations (void);
275 
276 static void tracepoints_info (char *, int);
277 
278 static void delete_trace_command (char *, int);
279 
280 static void enable_trace_command (char *, int);
281 
282 static void disable_trace_command (char *, int);
283 
284 static void trace_pass_command (char *, int);
285 
286 static void set_tracepoint_count (int num);
287 
288 static int is_masked_watchpoint (const struct breakpoint *b);
289 
290 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
291 
292 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
293  otherwise. */
294 
295 static int strace_marker_p (struct breakpoint *b);
296 
297 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
298  that are implemented on top of software or hardware breakpoints
299  (user breakpoints, internal and momentary breakpoints, etc.). */
301 
302 /* Internal breakpoints class type. */
304 
305 /* Momentary breakpoints class type. */
307 
308 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
310 
311 /* The breakpoint_ops structure to be used in regular user created
312  breakpoints. */
314 
315 /* Breakpoints set on probes. */
317 
318 /* Dynamic printf class type. */
320 
321 /* The style in which to perform a dynamic printf. This is a user
322  option because different output options have different tradeoffs;
323  if GDB does the printing, there is better error handling if there
324  is a problem with any of the arguments, but using an inferior
325  function lets you have special-purpose printers and sending of
326  output to the same place as compiled-in print functions. */
327 
328 static const char dprintf_style_gdb[] = "gdb";
329 static const char dprintf_style_call[] = "call";
330 static const char dprintf_style_agent[] = "agent";
331 static const char *const dprintf_style_enums[] = {
335  NULL
336 };
337 static const char *dprintf_style = dprintf_style_gdb;
338 
339 /* The function to use for dynamic printf if the preferred style is to
340  call into the inferior. The value is simply a string that is
341  copied into the command, so it can be anything that GDB can
342  evaluate to a callable address, not necessarily a function name. */
343 
344 static char *dprintf_function = "";
345 
346 /* The channel to use for dynamic printf if the preferred style is to
347  call into the inferior; if a nonempty string, it will be passed to
348  the call as the first argument, with the format string as the
349  second. As with the dprintf function, this can be anything that
350  GDB knows how to evaluate, so in addition to common choices like
351  "stderr", this could be an app-specific expression like
352  "mystreams[curlogger]". */
353 
354 static char *dprintf_channel = "";
355 
356 /* True if dprintf commands should continue to operate even if GDB
357  has disconnected. */
358 static int disconnected_dprintf = 1;
359 
360 /* A reference-counted struct command_line. This lets multiple
361  breakpoints share a single command list. */
363 {
364  /* The reference count. */
365  int refc;
366 
367  /* The command list. */
369 };
370 
371 struct command_line *
373 {
374  return b->commands ? b->commands->commands : NULL;
375 }
376 
377 /* Flag indicating that a command has proceeded the inferior past the
378  current breakpoint. */
379 
381 
382 const char *
383 bpdisp_text (enum bpdisp disp)
384 {
385  /* NOTE: the following values are a part of MI protocol and
386  represent values of 'disp' field returned when inferior stops at
387  a breakpoint. */
388  static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
389 
390  return bpdisps[(int) disp];
391 }
392 
393 /* Prototypes for exported functions. */
394 /* If FALSE, gdb will not use hardware support for watchpoints, even
395  if such is available. */
397 
398 static void
399 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
400  struct cmd_list_element *c,
401  const char *value)
402 {
403  fprintf_filtered (file,
404  _("Debugger's willingness to use "
405  "watchpoint hardware is %s.\n"),
406  value);
407 }
408 
409 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
410  If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
411  for unrecognized breakpoint locations.
412  If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
414 static void
415 show_pending_break_support (struct ui_file *file, int from_tty,
416  struct cmd_list_element *c,
417  const char *value)
418 {
419  fprintf_filtered (file,
420  _("Debugger's behavior regarding "
421  "pending breakpoints is %s.\n"),
422  value);
423 }
424 
425 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
426  set with "break" but falling in read-only memory.
427  If 0, gdb will warn about such breakpoints, but won't automatically
428  use hardware breakpoints. */
430 static void
431 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
432  struct cmd_list_element *c,
433  const char *value)
434 {
435  fprintf_filtered (file,
436  _("Automatic usage of hardware breakpoints is %s.\n"),
437  value);
438 }
439 
440 /* If on, GDB keeps breakpoints inserted even if the inferior is
441  stopped, and immediately inserts any new breakpoints as soon as
442  they're created. If off (default), GDB keeps breakpoints off of
443  the target as long as possible. That is, it delays inserting
444  breakpoints until the next resume, and removes them again when the
445  target fully stops. This is a bit safer in case GDB crashes while
446  processing user input. */
447 static int always_inserted_mode = 0;
448 
449 static void
450 show_always_inserted_mode (struct ui_file *file, int from_tty,
451  struct cmd_list_element *c, const char *value)
452 {
453  fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
454  value);
455 }
456 
457 /* See breakpoint.h. */
458 
459 int
461 {
463  {
464  /* If breakpoints are global, they should be inserted even if no
465  thread under gdb's control is running, or even if there are
466  no threads under GDB's control yet. */
467  return 1;
468  }
469  else if (target_has_execution)
470  {
471  if (always_inserted_mode)
472  {
473  /* The user wants breakpoints inserted even if all threads
474  are stopped. */
475  return 1;
476  }
477 
478  if (threads_are_executing ())
479  return 1;
480  }
481  return 0;
482 }
483 
484 static const char condition_evaluation_both[] = "host or target";
485 
486 /* Modes for breakpoint condition evaluation. */
487 static const char condition_evaluation_auto[] = "auto";
488 static const char condition_evaluation_host[] = "host";
489 static const char condition_evaluation_target[] = "target";
490 static const char *const condition_evaluation_enums[] = {
494  NULL
495 };
496 
497 /* Global that holds the current mode for breakpoint condition evaluation. */
498 static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
499 
500 /* Global that we use to display information to the user (gets its value from
501  condition_evaluation_mode_1. */
502 static const char *condition_evaluation_mode = condition_evaluation_auto;
503 
504 /* Translate a condition evaluation mode MODE into either "host"
505  or "target". This is used mostly to translate from "auto" to the
506  real setting that is being used. It returns the translated
507  evaluation mode. */
508 
509 static const char *
511 {
512  if (mode == condition_evaluation_auto)
513  {
516  else
518  }
519  else
520  return mode;
521 }
522 
523 /* Discovers what condition_evaluation_auto translates to. */
524 
525 static const char *
527 {
528  return translate_condition_evaluation_mode (condition_evaluation_mode);
529 }
530 
531 /* Return true if GDB should evaluate breakpoint conditions or false
532  otherwise. */
533 
534 static int
536 {
537  const char *mode = breakpoint_condition_evaluation_mode ();
538 
539  return (mode == condition_evaluation_host);
540 }
541 
542 void _initialize_breakpoint (void);
543 
544 /* Are we executing breakpoint commands? */
546 
547 /* Are overlay event breakpoints enabled? */
549 
550 /* See description in breakpoint.h. */
551 int target_exact_watchpoints = 0;
552 
553 /* Walk the following statement or block through all breakpoints.
554  ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
555  current breakpoint. */
556 
557 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
558 
559 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
560  for (B = breakpoint_chain; \
561  B ? (TMP=B->next, 1): 0; \
562  B = TMP)
563 
564 /* Similar iterator for the low-level breakpoints. SAFE variant is
565  not provided so update_global_location_list must not be called
566  while executing the block of ALL_BP_LOCATIONS. */
567 
568 #define ALL_BP_LOCATIONS(B,BP_TMP) \
569  for (BP_TMP = bp_location; \
570  BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
571  BP_TMP++)
572 
573 /* Iterates through locations with address ADDRESS for the currently selected
574  program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
575  to where the loop should start from.
576  If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
577  appropriate location to start with. */
578 
579 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
580  for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
581  BP_LOCP_TMP = BP_LOCP_START; \
582  BP_LOCP_START \
583  && (BP_LOCP_TMP < bp_location + bp_location_count \
584  && (*BP_LOCP_TMP)->address == ADDRESS); \
585  BP_LOCP_TMP++)
586 
587 /* Iterator for tracepoints only. */
588 
589 #define ALL_TRACEPOINTS(B) \
590  for (B = breakpoint_chain; B; B = B->next) \
591  if (is_tracepoint (B))
592 
593 /* Chains of all breakpoints defined. */
594 
596 
597 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
598 
599 static struct bp_location **bp_location;
600 
601 /* Number of elements of BP_LOCATION. */
602 
603 static unsigned bp_location_count;
604 
605 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
606  ADDRESS for the current elements of BP_LOCATION which get a valid
607  result from bp_location_has_shadow. You can use it for roughly
608  limiting the subrange of BP_LOCATION to scan for shadow bytes for
609  an address you need to read. */
610 
612 
613 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
614  + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
615  BP_LOCATION which get a valid result from bp_location_has_shadow.
616  You can use it for roughly limiting the subrange of BP_LOCATION to
617  scan for shadow bytes for an address you need to read. */
618 
620 
621 /* The locations that no longer correspond to any breakpoint, unlinked
622  from bp_location array, but for which a hit may still be reported
623  by a target. */
624 VEC(bp_location_p) *moribund_locations = NULL;
625 
626 /* Number of last breakpoint made. */
627 
628 static int breakpoint_count;
629 
630 /* The value of `breakpoint_count' before the last command that
631  created breakpoints. If the last (break-like) command created more
632  than one breakpoint, then the difference between BREAKPOINT_COUNT
633  and PREV_BREAKPOINT_COUNT is more than one. */
634 static int prev_breakpoint_count;
635 
636 /* Number of last tracepoint made. */
637 
638 static int tracepoint_count;
639 
640 static struct cmd_list_element *breakpoint_set_cmdlist;
641 static struct cmd_list_element *breakpoint_show_cmdlist;
643 
644 /* See declaration at breakpoint.h. */
645 
646 struct breakpoint *
647 breakpoint_find_if (int (*func) (struct breakpoint *b, void *d),
648  void *user_data)
649 {
650  struct breakpoint *b = NULL;
651 
652  ALL_BREAKPOINTS (b)
653  {
654  if (func (b, user_data) != 0)
655  break;
656  }
657 
658  return b;
659 }
660 
661 /* Return whether a breakpoint is an active enabled breakpoint. */
662 static int
664 {
665  return (b->enable_state == bp_enabled);
666 }
667 
668 /* Set breakpoint count to NUM. */
669 
670 static void
672 {
673  prev_breakpoint_count = breakpoint_count;
674  breakpoint_count = num;
676 }
677 
678 /* Used by `start_rbreak_breakpoints' below, to record the current
679  breakpoint count before "rbreak" creates any breakpoint. */
681 
682 /* Called at the start an "rbreak" command to record the first
683  breakpoint made. */
684 
685 void
687 {
688  rbreak_start_breakpoint_count = breakpoint_count;
689 }
690 
691 /* Called at the end of an "rbreak" command to record the last
692  breakpoint made. */
693 
694 void
696 {
697  prev_breakpoint_count = rbreak_start_breakpoint_count;
698 }
699 
700 /* Used in run_command to zero the hit count when a new run starts. */
701 
702 void
704 {
705  struct breakpoint *b;
706 
707  ALL_BREAKPOINTS (b)
708  b->hit_count = 0;
709 }
710 
711 /* Allocate a new counted_command_line with reference count of 1.
712  The new structure owns COMMANDS. */
713 
714 static struct counted_command_line *
716 {
717  struct counted_command_line *result
718  = xmalloc (sizeof (struct counted_command_line));
719 
720  result->refc = 1;
721  result->commands = commands;
722  return result;
723 }
724 
725 /* Increment reference count. This does nothing if CMD is NULL. */
726 
727 static void
729 {
730  if (cmd)
731  ++cmd->refc;
732 }
733 
734 /* Decrement reference count. If the reference count reaches 0,
735  destroy the counted_command_line. Sets *CMDP to NULL. This does
736  nothing if *CMDP is NULL. */
737 
738 static void
740 {
741  if (*cmdp)
742  {
743  if (--(*cmdp)->refc == 0)
744  {
745  free_command_lines (&(*cmdp)->commands);
746  xfree (*cmdp);
747  }
748  *cmdp = NULL;
749  }
750 }
751 
752 /* A cleanup function that calls decref_counted_command_line. */
753 
754 static void
756 {
758 }
759 
760 /* Create a cleanup that calls decref_counted_command_line on the
761  argument. */
762 
763 static struct cleanup *
765 {
767 }
768 
769 
770 /* Return the breakpoint with the specified number, or NULL
771  if the number does not refer to an existing breakpoint. */
772 
773 struct breakpoint *
774 get_breakpoint (int num)
775 {
776  struct breakpoint *b;
777 
778  ALL_BREAKPOINTS (b)
779  if (b->number == num)
780  return b;
781 
782  return NULL;
783 }
784 
785 
786 
787 /* Mark locations as "conditions have changed" in case the target supports
788  evaluating conditions on its side. */
789 
790 static void
792 {
793  struct bp_location *loc;
794 
795  /* This is only meaningful if the target is
796  evaluating conditions and if the user has
797  opted for condition evaluation on the target's
798  side. */
801  return;
802 
803  if (!is_breakpoint (b))
804  return;
805 
806  for (loc = b->loc; loc; loc = loc->next)
808 }
809 
810 /* Mark location as "conditions have changed" in case the target supports
811  evaluating conditions on its side. */
812 
813 static void
814 mark_breakpoint_location_modified (struct bp_location *loc)
815 {
816  /* This is only meaningful if the target is
817  evaluating conditions and if the user has
818  opted for condition evaluation on the target's
819  side. */
822 
823  return;
824 
825  if (!is_breakpoint (loc->owner))
826  return;
827 
829 }
830 
831 /* Sets the condition-evaluation mode using the static global
832  condition_evaluation_mode. */
833 
834 static void
835 set_condition_evaluation_mode (char *args, int from_tty,
836  struct cmd_list_element *c)
837 {
838  const char *old_mode, *new_mode;
839 
840  if ((condition_evaluation_mode_1 == condition_evaluation_target)
842  {
843  condition_evaluation_mode_1 = condition_evaluation_mode;
844  warning (_("Target does not support breakpoint condition evaluation.\n"
845  "Using host evaluation mode instead."));
846  return;
847  }
848 
849  new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
850  old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
851 
852  /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
853  settings was "auto". */
854  condition_evaluation_mode = condition_evaluation_mode_1;
855 
856  /* Only update the mode if the user picked a different one. */
857  if (new_mode != old_mode)
858  {
859  struct bp_location *loc, **loc_tmp;
860  /* If the user switched to a different evaluation mode, we
861  need to synch the changes with the target as follows:
862 
863  "host" -> "target": Send all (valid) conditions to the target.
864  "target" -> "host": Remove all the conditions from the target.
865  */
866 
867  if (new_mode == condition_evaluation_target)
868  {
869  /* Mark everything modified and synch conditions with the
870  target. */
871  ALL_BP_LOCATIONS (loc, loc_tmp)
873  }
874  else
875  {
876  /* Manually mark non-duplicate locations to synch conditions
877  with the target. We do this to remove all the conditions the
878  target knows about. */
879  ALL_BP_LOCATIONS (loc, loc_tmp)
880  if (is_breakpoint (loc->owner) && loc->inserted)
881  loc->needs_update = 1;
882  }
883 
884  /* Do the update. */
886  }
887 
888  return;
889 }
890 
891 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
892  what "auto" is translating to. */
893 
894 static void
895 show_condition_evaluation_mode (struct ui_file *file, int from_tty,
896  struct cmd_list_element *c, const char *value)
897 {
898  if (condition_evaluation_mode == condition_evaluation_auto)
899  fprintf_filtered (file,
900  _("Breakpoint condition evaluation "
901  "mode is %s (currently %s).\n"),
902  value,
904  else
905  fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
906  value);
907 }
908 
909 /* A comparison function for bp_location AP and BP that is used by
910  bsearch. This comparison function only cares about addresses, unlike
911  the more general bp_location_compare function. */
912 
913 static int
914 bp_location_compare_addrs (const void *ap, const void *bp)
915 {
916  struct bp_location *a = *(void **) ap;
917  struct bp_location *b = *(void **) bp;
918 
919  if (a->address == b->address)
920  return 0;
921  else
922  return ((a->address > b->address) - (a->address < b->address));
923 }
924 
925 /* Helper function to skip all bp_locations with addresses
926  less than ADDRESS. It returns the first bp_location that
927  is greater than or equal to ADDRESS. If none is found, just
928  return NULL. */
929 
930 static struct bp_location **
932 {
933  struct bp_location dummy_loc;
934  struct bp_location *dummy_locp = &dummy_loc;
935  struct bp_location **locp_found = NULL;
936 
937  /* Initialize the dummy location's address field. */
938  memset (&dummy_loc, 0, sizeof (struct bp_location));
939  dummy_loc.address = address;
940 
941  /* Find a close match to the first location at ADDRESS. */
942  locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
943  sizeof (struct bp_location **),
945 
946  /* Nothing was found, nothing left to do. */
947  if (locp_found == NULL)
948  return NULL;
949 
950  /* We may have found a location that is at ADDRESS but is not the first in the
951  location's list. Go backwards (if possible) and locate the first one. */
952  while ((locp_found - 1) >= bp_location
953  && (*(locp_found - 1))->address == address)
954  locp_found--;
955 
956  return locp_found;
957 }
958 
959 void
960 set_breakpoint_condition (struct breakpoint *b, const char *exp,
961  int from_tty)
962 {
963  xfree (b->cond_string);
964  b->cond_string = NULL;
965 
966  if (is_watchpoint (b))
967  {
968  struct watchpoint *w = (struct watchpoint *) b;
969 
970  xfree (w->cond_exp);
971  w->cond_exp = NULL;
972  }
973  else
974  {
975  struct bp_location *loc;
976 
977  for (loc = b->loc; loc; loc = loc->next)
978  {
979  xfree (loc->cond);
980  loc->cond = NULL;
981 
982  /* No need to free the condition agent expression
983  bytecode (if we have one). We will handle this
984  when we go through update_global_location_list. */
985  }
986  }
987 
988  if (*exp == 0)
989  {
990  if (from_tty)
991  printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
992  }
993  else
994  {
995  const char *arg = exp;
996 
997  /* I don't know if it matters whether this is the string the user
998  typed in or the decompiled expression. */
999  b->cond_string = xstrdup (arg);
1000  b->condition_not_parsed = 0;
1001 
1002  if (is_watchpoint (b))
1003  {
1004  struct watchpoint *w = (struct watchpoint *) b;
1005 
1006  innermost_block = NULL;
1007  arg = exp;
1008  w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
1009  if (*arg)
1010  error (_("Junk at end of expression"));
1012  }
1013  else
1014  {
1015  struct bp_location *loc;
1016 
1017  for (loc = b->loc; loc; loc = loc->next)
1018  {
1019  arg = exp;
1020  loc->cond =
1021  parse_exp_1 (&arg, loc->address,
1022  block_for_pc (loc->address), 0);
1023  if (*arg)
1024  error (_("Junk at end of expression"));
1025  }
1026  }
1027  }
1029 
1031 }
1032 
1033 /* Completion for the "condition" command. */
1034 
1035 static VEC (char_ptr) *
1036 condition_completer (struct cmd_list_element *cmd,
1037  const char *text, const char *word)
1038 {
1039  const char *space;
1040 
1041  text = skip_spaces_const (text);
1042  space = skip_to_space_const (text);
1043  if (*space == '\0')
1044  {
1045  int len;
1046  struct breakpoint *b;
1047  VEC (char_ptr) *result = NULL;
1048 
1049  if (text[0] == '$')
1050  {
1051  /* We don't support completion of history indices. */
1052  if (isdigit (text[1]))
1053  return NULL;
1054  return complete_internalvar (&text[1]);
1055  }
1056 
1057  /* We're completing the breakpoint number. */
1058  len = strlen (text);
1059 
1060  ALL_BREAKPOINTS (b)
1061  {
1062  char number[50];
1063 
1064  xsnprintf (number, sizeof (number), "%d", b->number);
1065 
1066  if (strncmp (number, text, len) == 0)
1067  VEC_safe_push (char_ptr, result, xstrdup (number));
1068  }
1069 
1070  return result;
1071  }
1072 
1073  /* We're completing the expression part. */
1074  text = skip_spaces_const (space);
1075  return expression_completer (cmd, text, word);
1076 }
1077 
1078 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1079 
1080 static void
1081 condition_command (char *arg, int from_tty)
1082 {
1083  struct breakpoint *b;
1084  char *p;
1085  int bnum;
1086 
1087  if (arg == 0)
1088  error_no_arg (_("breakpoint number"));
1089 
1090  p = arg;
1091  bnum = get_number (&p);
1092  if (bnum == 0)
1093  error (_("Bad breakpoint argument: '%s'"), arg);
1094 
1095  ALL_BREAKPOINTS (b)
1096  if (b->number == bnum)
1097  {
1098  /* Check if this breakpoint has a "stop" method implemented in an
1099  extension language. This method and conditions entered into GDB
1100  from the CLI are mutually exclusive. */
1101  const struct extension_language_defn *extlang
1103 
1104  if (extlang != NULL)
1105  {
1106  error (_("Only one stop condition allowed. There is currently"
1107  " a %s stop condition defined for this breakpoint."),
1108  ext_lang_capitalized_name (extlang));
1109  }
1110  set_breakpoint_condition (b, p, from_tty);
1111 
1112  if (is_breakpoint (b))
1114 
1115  return;
1116  }
1117 
1118  error (_("No breakpoint number %d."), bnum);
1119 }
1120 
1121 /* Check that COMMAND do not contain commands that are suitable
1122  only for tracepoints and not suitable for ordinary breakpoints.
1123  Throw if any such commands is found. */
1124 
1125 static void
1127 {
1128  struct command_line *c;
1129 
1130  for (c = commands; c; c = c->next)
1131  {
1132  int i;
1133 
1135  error (_("The 'while-stepping' command can "
1136  "only be used for tracepoints"));
1137 
1138  for (i = 0; i < c->body_count; ++i)
1140 
1141  /* Not that command parsing removes leading whitespace and comment
1142  lines and also empty lines. So, we only need to check for
1143  command directly. */
1144  if (strstr (c->line, "collect ") == c->line)
1145  error (_("The 'collect' command can only be used for tracepoints"));
1146 
1147  if (strstr (c->line, "teval ") == c->line)
1148  error (_("The 'teval' command can only be used for tracepoints"));
1149  }
1150 }
1151 
1152 /* Encapsulate tests for different types of tracepoints. */
1153 
1154 static int
1156 {
1157  return (type == bp_tracepoint
1158  || type == bp_fast_tracepoint
1159  || type == bp_static_tracepoint);
1160 }
1161 
1162 int
1163 is_tracepoint (const struct breakpoint *b)
1164 {
1165  return is_tracepoint_type (b->type);
1166 }
1167 
1168 /* A helper function that validates that COMMANDS are valid for a
1169  breakpoint. This function will throw an exception if a problem is
1170  found. */
1171 
1172 static void
1174  struct command_line *commands)
1175 {
1176  if (is_tracepoint (b))
1177  {
1178  struct tracepoint *t = (struct tracepoint *) b;
1179  struct command_line *c;
1180  struct command_line *while_stepping = 0;
1181 
1182  /* Reset the while-stepping step count. The previous commands
1183  might have included a while-stepping action, while the new
1184  ones might not. */
1185  t->step_count = 0;
1186 
1187  /* We need to verify that each top-level element of commands is
1188  valid for tracepoints, that there's at most one
1189  while-stepping element, and that the while-stepping's body
1190  has valid tracing commands excluding nested while-stepping.
1191  We also need to validate the tracepoint action line in the
1192  context of the tracepoint --- validate_actionline actually
1193  has side effects, like setting the tracepoint's
1194  while-stepping STEP_COUNT, in addition to checking if the
1195  collect/teval actions parse and make sense in the
1196  tracepoint's context. */
1197  for (c = commands; c; c = c->next)
1198  {
1200  {
1201  if (b->type == bp_fast_tracepoint)
1202  error (_("The 'while-stepping' command "
1203  "cannot be used for fast tracepoint"));
1204  else if (b->type == bp_static_tracepoint)
1205  error (_("The 'while-stepping' command "
1206  "cannot be used for static tracepoint"));
1207 
1208  if (while_stepping)
1209  error (_("The 'while-stepping' command "
1210  "can be used only once"));
1211  else
1212  while_stepping = c;
1213  }
1214 
1215  validate_actionline (c->line, b);
1216  }
1217  if (while_stepping)
1218  {
1219  struct command_line *c2;
1220 
1221  gdb_assert (while_stepping->body_count == 1);
1222  c2 = while_stepping->body_list[0];
1223  for (; c2; c2 = c2->next)
1224  {
1226  error (_("The 'while-stepping' command cannot be nested"));
1227  }
1228  }
1229  }
1230  else
1231  {
1232  check_no_tracepoint_commands (commands);
1233  }
1234 }
1235 
1236 /* Return a vector of all the static tracepoints set at ADDR. The
1237  caller is responsible for releasing the vector. */
1238 
1240 static_tracepoints_here (CORE_ADDR addr)
1241 {
1242  struct breakpoint *b;
1243  VEC(breakpoint_p) *found = 0;
1244  struct bp_location *loc;
1245 
1246  ALL_BREAKPOINTS (b)
1247  if (b->type == bp_static_tracepoint)
1248  {
1249  for (loc = b->loc; loc; loc = loc->next)
1250  if (loc->address == addr)
1251  VEC_safe_push(breakpoint_p, found, b);
1252  }
1253 
1254  return found;
1255 }
1256 
1257 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1258  validate that only allowed commands are included. */
1259 
1260 void
1262  struct command_line *commands)
1263 {
1264  validate_commands_for_breakpoint (b, commands);
1265 
1267  b->commands = alloc_counted_command_line (commands);
1269 }
1270 
1271 /* Set the internal `silent' flag on the breakpoint. Note that this
1272  is not the same as the "silent" that may appear in the breakpoint's
1273  commands. */
1274 
1275 void
1276 breakpoint_set_silent (struct breakpoint *b, int silent)
1277 {
1278  int old_silent = b->silent;
1279 
1280  b->silent = silent;
1281  if (old_silent != silent)
1283 }
1284 
1285 /* Set the thread for this breakpoint. If THREAD is -1, make the
1286  breakpoint work for any thread. */
1287 
1288 void
1289 breakpoint_set_thread (struct breakpoint *b, int thread)
1290 {
1291  int old_thread = b->thread;
1292 
1293  b->thread = thread;
1294  if (old_thread != thread)
1296 }
1297 
1298 /* Set the task for this breakpoint. If TASK is 0, make the
1299  breakpoint work for any task. */
1300 
1301 void
1302 breakpoint_set_task (struct breakpoint *b, int task)
1303 {
1304  int old_task = b->task;
1305 
1306  b->task = task;
1307  if (old_task != task)
1309 }
1310 
1311 void
1312 check_tracepoint_command (char *line, void *closure)
1313 {
1314  struct breakpoint *b = closure;
1315 
1316  validate_actionline (line, b);
1317 }
1318 
1319 /* A structure used to pass information through
1320  map_breakpoint_numbers. */
1321 
1323 {
1324  /* True if the command was typed at a tty. */
1326 
1327  /* The breakpoint range spec. */
1328  char *arg;
1329 
1330  /* Non-NULL if the body of the commands are being read from this
1331  already-parsed command. */
1333 
1334  /* The command lines read from the user, or NULL if they have not
1335  yet been read. */
1337 };
1338 
1339 /* A callback for map_breakpoint_numbers that sets the commands for
1340  commands_command. */
1341 
1342 static void
1343 do_map_commands_command (struct breakpoint *b, void *data)
1344 {
1345  struct commands_info *info = data;
1346 
1347  if (info->cmd == NULL)
1348  {
1349  struct command_line *l;
1350 
1351  if (info->control != NULL)
1352  l = copy_command_lines (info->control->body_list[0]);
1353  else
1354  {
1355  struct cleanup *old_chain;
1356  char *str;
1357 
1358  str = xstrprintf (_("Type commands for breakpoint(s) "
1359  "%s, one per line."),
1360  info->arg);
1361 
1362  old_chain = make_cleanup (xfree, str);
1363 
1364  l = read_command_lines (str,
1365  info->from_tty, 1,
1366  (is_tracepoint (b)
1367  ? check_tracepoint_command : 0),
1368  b);
1369 
1370  do_cleanups (old_chain);
1371  }
1372 
1373  info->cmd = alloc_counted_command_line (l);
1374  }
1375 
1376  /* If a breakpoint was on the list more than once, we don't need to
1377  do anything. */
1378  if (b->commands != info->cmd)
1379  {
1383  b->commands = info->cmd;
1385  }
1386 }
1387 
1388 static void
1389 commands_command_1 (char *arg, int from_tty,
1390  struct command_line *control)
1391 {
1392  struct cleanup *cleanups;
1393  struct commands_info info;
1394 
1395  info.from_tty = from_tty;
1396  info.control = control;
1397  info.cmd = NULL;
1398  /* If we read command lines from the user, then `info' will hold an
1399  extra reference to the commands that we must clean up. */
1400  cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1401 
1402  if (arg == NULL || !*arg)
1403  {
1404  if (breakpoint_count - prev_breakpoint_count > 1)
1405  arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1406  breakpoint_count);
1407  else if (breakpoint_count > 0)
1408  arg = xstrprintf ("%d", breakpoint_count);
1409  else
1410  {
1411  /* So that we don't try to free the incoming non-NULL
1412  argument in the cleanup below. Mapping breakpoint
1413  numbers will fail in this case. */
1414  arg = NULL;
1415  }
1416  }
1417  else
1418  /* The command loop has some static state, so we need to preserve
1419  our argument. */
1420  arg = xstrdup (arg);
1421 
1422  if (arg != NULL)
1423  make_cleanup (xfree, arg);
1424 
1425  info.arg = arg;
1426 
1428 
1429  if (info.cmd == NULL)
1430  error (_("No breakpoints specified."));
1431 
1432  do_cleanups (cleanups);
1433 }
1434 
1435 static void
1436 commands_command (char *arg, int from_tty)
1437 {
1438  commands_command_1 (arg, from_tty, NULL);
1439 }
1440 
1441 /* Like commands_command, but instead of reading the commands from
1442  input stream, takes them from an already parsed command structure.
1443 
1444  This is used by cli-script.c to DTRT with breakpoint commands
1445  that are part of if and while bodies. */
1448 {
1449  commands_command_1 (arg, 0, cmd);
1450  return simple_control;
1451 }
1452 
1453 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1454 
1455 static int
1456 bp_location_has_shadow (struct bp_location *bl)
1457 {
1459  return 0;
1460  if (!bl->inserted)
1461  return 0;
1462  if (bl->target_info.shadow_len == 0)
1463  /* BL isn't valid, or doesn't shadow memory. */
1464  return 0;
1465  return 1;
1466 }
1467 
1468 /* Update BUF, which is LEN bytes read from the target address
1469  MEMADDR, by replacing a memory breakpoint with its shadowed
1470  contents.
1471 
1472  If READBUF is not NULL, this buffer must not overlap with the of
1473  the breakpoint location's shadow_contents buffer. Otherwise, a
1474  failed assertion internal error will be raised. */
1475 
1476 static void
1478  const gdb_byte *writebuf_org,
1479  ULONGEST memaddr, LONGEST len,
1480  struct bp_target_info *target_info,
1481  struct gdbarch *gdbarch)
1482 {
1483  /* Now do full processing of the found relevant range of elements. */
1484  CORE_ADDR bp_addr = 0;
1485  int bp_size = 0;
1486  int bptoffset = 0;
1487 
1488  if (!breakpoint_address_match (target_info->placed_address_space, 0,
1490  {
1491  /* The breakpoint is inserted in a different address space. */
1492  return;
1493  }
1494 
1495  /* Addresses and length of the part of the breakpoint that
1496  we need to copy. */
1497  bp_addr = target_info->placed_address;
1498  bp_size = target_info->shadow_len;
1499 
1500  if (bp_addr + bp_size <= memaddr)
1501  {
1502  /* The breakpoint is entirely before the chunk of memory we are
1503  reading. */
1504  return;
1505  }
1506 
1507  if (bp_addr >= memaddr + len)
1508  {
1509  /* The breakpoint is entirely after the chunk of memory we are
1510  reading. */
1511  return;
1512  }
1513 
1514  /* Offset within shadow_contents. */
1515  if (bp_addr < memaddr)
1516  {
1517  /* Only copy the second part of the breakpoint. */
1518  bp_size -= memaddr - bp_addr;
1519  bptoffset = memaddr - bp_addr;
1520  bp_addr = memaddr;
1521  }
1522 
1523  if (bp_addr + bp_size > memaddr + len)
1524  {
1525  /* Only copy the first part of the breakpoint. */
1526  bp_size -= (bp_addr + bp_size) - (memaddr + len);
1527  }
1528 
1529  if (readbuf != NULL)
1530  {
1531  /* Verify that the readbuf buffer does not overlap with the
1532  shadow_contents buffer. */
1533  gdb_assert (target_info->shadow_contents >= readbuf + len
1534  || readbuf >= (target_info->shadow_contents
1535  + target_info->shadow_len));
1536 
1537  /* Update the read buffer with this inserted breakpoint's
1538  shadow. */
1539  memcpy (readbuf + bp_addr - memaddr,
1540  target_info->shadow_contents + bptoffset, bp_size);
1541  }
1542  else
1543  {
1544  const unsigned char *bp;
1545  CORE_ADDR addr = target_info->reqstd_address;
1546  int placed_size;
1547 
1548  /* Update the shadow with what we want to write to memory. */
1549  memcpy (target_info->shadow_contents + bptoffset,
1550  writebuf_org + bp_addr - memaddr, bp_size);
1551 
1552  /* Determine appropriate breakpoint contents and size for this
1553  address. */
1554  bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size);
1555 
1556  /* Update the final write buffer with this inserted
1557  breakpoint's INSN. */
1558  memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1559  }
1560 }
1561 
1562 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1563  by replacing any memory breakpoints with their shadowed contents.
1564 
1565  If READBUF is not NULL, this buffer must not overlap with any of
1566  the breakpoint location's shadow_contents buffers. Otherwise,
1567  a failed assertion internal error will be raised.
1568 
1569  The range of shadowed area by each bp_location is:
1570  bl->address - bp_location_placed_address_before_address_max
1571  up to bl->address + bp_location_shadow_len_after_address_max
1572  The range we were requested to resolve shadows for is:
1573  memaddr ... memaddr + len
1574  Thus the safe cutoff boundaries for performance optimization are
1575  memaddr + len <= (bl->address
1576  - bp_location_placed_address_before_address_max)
1577  and:
1578  bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1579 
1580 void
1582  const gdb_byte *writebuf_org,
1583  ULONGEST memaddr, LONGEST len)
1584 {
1585  /* Left boundary, right boundary and median element of our binary
1586  search. */
1587  unsigned bc_l, bc_r, bc;
1588  size_t i;
1589 
1590  /* Find BC_L which is a leftmost element which may affect BUF
1591  content. It is safe to report lower value but a failure to
1592  report higher one. */
1593 
1594  bc_l = 0;
1595  bc_r = bp_location_count;
1596  while (bc_l + 1 < bc_r)
1597  {
1598  struct bp_location *bl;
1599 
1600  bc = (bc_l + bc_r) / 2;
1601  bl = bp_location[bc];
1602 
1603  /* Check first BL->ADDRESS will not overflow due to the added
1604  constant. Then advance the left boundary only if we are sure
1605  the BC element can in no way affect the BUF content (MEMADDR
1606  to MEMADDR + LEN range).
1607 
1608  Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1609  offset so that we cannot miss a breakpoint with its shadow
1610  range tail still reaching MEMADDR. */
1611 
1612  if ((bl->address + bp_location_shadow_len_after_address_max
1613  >= bl->address)
1614  && (bl->address + bp_location_shadow_len_after_address_max
1615  <= memaddr))
1616  bc_l = bc;
1617  else
1618  bc_r = bc;
1619  }
1620 
1621  /* Due to the binary search above, we need to make sure we pick the
1622  first location that's at BC_L's address. E.g., if there are
1623  multiple locations at the same address, BC_L may end up pointing
1624  at a duplicate location, and miss the "master"/"inserted"
1625  location. Say, given locations L1, L2 and L3 at addresses A and
1626  B:
1627 
1628  L1@A, L2@A, L3@B, ...
1629 
1630  BC_L could end up pointing at location L2, while the "master"
1631  location could be L1. Since the `loc->inserted' flag is only set
1632  on "master" locations, we'd forget to restore the shadow of L1
1633  and L2. */
1634  while (bc_l > 0
1635  && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1636  bc_l--;
1637 
1638  /* Now do full processing of the found relevant range of elements. */
1639 
1640  for (bc = bc_l; bc < bp_location_count; bc++)
1641  {
1642  struct bp_location *bl = bp_location[bc];
1643  CORE_ADDR bp_addr = 0;
1644  int bp_size = 0;
1645  int bptoffset = 0;
1646 
1647  /* bp_location array has BL->OWNER always non-NULL. */
1648  if (bl->owner->type == bp_none)
1649  warning (_("reading through apparently deleted breakpoint #%d?"),
1650  bl->owner->number);
1651 
1652  /* Performance optimization: any further element can no longer affect BUF
1653  content. */
1654 
1655  if (bl->address >= bp_location_placed_address_before_address_max
1656  && memaddr + len <= (bl->address
1657  - bp_location_placed_address_before_address_max))
1658  break;
1659 
1660  if (!bp_location_has_shadow (bl))
1661  continue;
1662 
1663  one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org,
1664  memaddr, len, &bl->target_info, bl->gdbarch);
1665  }
1666 }
1667 
1668 
1669 
1670 /* Return true if BPT is either a software breakpoint or a hardware
1671  breakpoint. */
1672 
1673 int
1674 is_breakpoint (const struct breakpoint *bpt)
1675 {
1676  return (bpt->type == bp_breakpoint
1677  || bpt->type == bp_hardware_breakpoint
1678  || bpt->type == bp_dprintf);
1679 }
1680 
1681 /* Return true if BPT is of any hardware watchpoint kind. */
1682 
1683 static int
1685 {
1686  return (bpt->type == bp_hardware_watchpoint
1687  || bpt->type == bp_read_watchpoint
1688  || bpt->type == bp_access_watchpoint);
1689 }
1690 
1691 /* Return true if BPT is of any watchpoint kind, hardware or
1692  software. */
1693 
1694 int
1695 is_watchpoint (const struct breakpoint *bpt)
1696 {
1697  return (is_hardware_watchpoint (bpt)
1698  || bpt->type == bp_watchpoint);
1699 }
1700 
1701 /* Returns true if the current thread and its running state are safe
1702  to evaluate or update watchpoint B. Watchpoints on local
1703  expressions need to be evaluated in the context of the thread that
1704  was current when the watchpoint was created, and, that thread needs
1705  to be stopped to be able to select the correct frame context.
1706  Watchpoints on global expressions can be evaluated on any thread,
1707  and in any state. It is presently left to the target allowing
1708  memory accesses when threads are running. */
1709 
1710 static int
1712 {
1713  return (b->base.pspace == current_program_space
1716  && !is_executing (inferior_ptid))));
1717 }
1718 
1719 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1720  associated bp_watchpoint_scope breakpoint. */
1721 
1722 static void
1724 {
1725  struct breakpoint *b = &w->base;
1726 
1727  if (b->related_breakpoint != b)
1728  {
1733  b->related_breakpoint = b;
1734  }
1736 }
1737 
1738 /* Extract a bitfield value from value VAL using the bit parameters contained in
1739  watchpoint W. */
1740 
1741 static struct value *
1743 {
1744  struct value *bit_val;
1745 
1746  if (val == NULL)
1747  return NULL;
1748 
1749  bit_val = allocate_value (value_type (val));
1750 
1751  unpack_value_bitfield (bit_val,
1752  w->val_bitpos,
1753  w->val_bitsize,
1755  value_offset (val),
1756  val);
1757 
1758  return bit_val;
1759 }
1760 
1761 /* Assuming that B is a watchpoint:
1762  - Reparse watchpoint expression, if REPARSE is non-zero
1763  - Evaluate expression and store the result in B->val
1764  - Evaluate the condition if there is one, and store the result
1765  in b->loc->cond.
1766  - Update the list of values that must be watched in B->loc.
1767 
1768  If the watchpoint disposition is disp_del_at_next_stop, then do
1769  nothing. If this is local watchpoint that is out of scope, delete
1770  it.
1771 
1772  Even with `set breakpoint always-inserted on' the watchpoints are
1773  removed + inserted on each stop here. Normal breakpoints must
1774  never be removed because they might be missed by a running thread
1775  when debugging in non-stop mode. On the other hand, hardware
1776  watchpoints (is_hardware_watchpoint; processed here) are specific
1777  to each LWP since they are stored in each LWP's hardware debug
1778  registers. Therefore, such LWP must be stopped first in order to
1779  be able to modify its hardware watchpoints.
1780 
1781  Hardware watchpoints must be reset exactly once after being
1782  presented to the user. It cannot be done sooner, because it would
1783  reset the data used to present the watchpoint hit to the user. And
1784  it must not be done later because it could display the same single
1785  watchpoint hit during multiple GDB stops. Note that the latter is
1786  relevant only to the hardware watchpoint types bp_read_watchpoint
1787  and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1788  not user-visible - its hit is suppressed if the memory content has
1789  not changed.
1790 
1791  The following constraints influence the location where we can reset
1792  hardware watchpoints:
1793 
1794  * target_stopped_by_watchpoint and target_stopped_data_address are
1795  called several times when GDB stops.
1796 
1797  [linux]
1798  * Multiple hardware watchpoints can be hit at the same time,
1799  causing GDB to stop. GDB only presents one hardware watchpoint
1800  hit at a time as the reason for stopping, and all the other hits
1801  are presented later, one after the other, each time the user
1802  requests the execution to be resumed. Execution is not resumed
1803  for the threads still having pending hit event stored in
1804  LWP_INFO->STATUS. While the watchpoint is already removed from
1805  the inferior on the first stop the thread hit event is kept being
1806  reported from its cached value by linux_nat_stopped_data_address
1807  until the real thread resume happens after the watchpoint gets
1808  presented and thus its LWP_INFO->STATUS gets reset.
1809 
1810  Therefore the hardware watchpoint hit can get safely reset on the
1811  watchpoint removal from inferior. */
1812 
1813 static void
1814 update_watchpoint (struct watchpoint *b, int reparse)
1815 {
1816  int within_current_scope;
1817  struct frame_id saved_frame_id;
1818  int frame_saved;
1819 
1820  /* If this is a local watchpoint, we only want to check if the
1821  watchpoint frame is in scope if the current thread is the thread
1822  that was used to create the watchpoint. */
1823  if (!watchpoint_in_thread_scope (b))
1824  return;
1825 
1827  return;
1828 
1829  frame_saved = 0;
1830 
1831  /* Determine if the watchpoint is within scope. */
1832  if (b->exp_valid_block == NULL)
1833  within_current_scope = 1;
1834  else
1835  {
1836  struct frame_info *fi = get_current_frame ();
1837  struct gdbarch *frame_arch = get_frame_arch (fi);
1838  CORE_ADDR frame_pc = get_frame_pc (fi);
1839 
1840  /* If we're at a point where the stack has been destroyed
1841  (e.g. in a function epilogue), unwinding may not work
1842  properly. Do not attempt to recreate locations at this
1843  point. See similar comments in watchpoint_check. */
1844  if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
1845  return;
1846 
1847  /* Save the current frame's ID so we can restore it after
1848  evaluating the watchpoint expression on its own frame. */
1849  /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1850  took a frame parameter, so that we didn't have to change the
1851  selected frame. */
1852  frame_saved = 1;
1853  saved_frame_id = get_frame_id (get_selected_frame (NULL));
1854 
1856  within_current_scope = (fi != NULL);
1857  if (within_current_scope)
1858  select_frame (fi);
1859  }
1860 
1861  /* We don't free locations. They are stored in the bp_location array
1862  and update_global_location_list will eventually delete them and
1863  remove breakpoints if needed. */
1864  b->base.loc = NULL;
1865 
1866  if (within_current_scope && reparse)
1867  {
1868  const char *s;
1869 
1870  if (b->exp)
1871  {
1872  xfree (b->exp);
1873  b->exp = NULL;
1874  }
1876  b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
1877  /* If the meaning of expression itself changed, the old value is
1878  no longer relevant. We don't want to report a watchpoint hit
1879  to the user when the old value and the new value may actually
1880  be completely different objects. */
1881  value_free (b->val);
1882  b->val = NULL;
1883  b->val_valid = 0;
1884 
1885  /* Note that unlike with breakpoints, the watchpoint's condition
1886  expression is stored in the breakpoint object, not in the
1887  locations (re)created below. */
1888  if (b->base.cond_string != NULL)
1889  {
1890  if (b->cond_exp != NULL)
1891  {
1892  xfree (b->cond_exp);
1893  b->cond_exp = NULL;
1894  }
1895 
1896  s = b->base.cond_string;
1897  b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1898  }
1899  }
1900 
1901  /* If we failed to parse the expression, for example because
1902  it refers to a global variable in a not-yet-loaded shared library,
1903  don't try to insert watchpoint. We don't automatically delete
1904  such watchpoint, though, since failure to parse expression
1905  is different from out-of-scope watchpoint. */
1906  if (!target_has_execution)
1907  {
1908  /* Without execution, memory can't change. No use to try and
1909  set watchpoint locations. The watchpoint will be reset when
1910  the target gains execution, through breakpoint_re_set. */
1911  if (!can_use_hw_watchpoints)
1912  {
1913  if (b->base.ops->works_in_software_mode (&b->base))
1914  b->base.type = bp_watchpoint;
1915  else
1916  error (_("Can't set read/access watchpoint when "
1917  "hardware watchpoints are disabled."));
1918  }
1919  }
1920  else if (within_current_scope && b->exp)
1921  {
1922  int pc = 0;
1923  struct value *val_chain, *v, *result, *next;
1924  struct program_space *frame_pspace;
1925 
1926  fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0);
1927 
1928  /* Avoid setting b->val if it's already set. The meaning of
1929  b->val is 'the last value' user saw, and we should update
1930  it only if we reported that last value to user. As it
1931  happens, the code that reports it updates b->val directly.
1932  We don't keep track of the memory value for masked
1933  watchpoints. */
1934  if (!b->val_valid && !is_masked_watchpoint (&b->base))
1935  {
1936  if (b->val_bitsize != 0)
1937  {
1939  if (v != NULL)
1940  release_value (v);
1941  }
1942  b->val = v;
1943  b->val_valid = 1;
1944  }
1945 
1946  frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1947 
1948  /* Look at each value on the value chain. */
1949  for (v = val_chain; v; v = value_next (v))
1950  {
1951  /* If it's a memory location, and GDB actually needed
1952  its contents to evaluate the expression, then we
1953  must watch it. If the first value returned is
1954  still lazy, that means an error occurred reading it;
1955  watch it anyway in case it becomes readable. */
1956  if (VALUE_LVAL (v) == lval_memory
1957  && (v == val_chain || ! value_lazy (v)))
1958  {
1959  struct type *vtype = check_typedef (value_type (v));
1960 
1961  /* We only watch structs and arrays if user asked
1962  for it explicitly, never if they just happen to
1963  appear in the middle of some value chain. */
1964  if (v == result
1965  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1966  && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1967  {
1968  CORE_ADDR addr;
1969  int type;
1970  struct bp_location *loc, **tmp;
1971  int bitpos = 0, bitsize = 0;
1972 
1973  if (value_bitsize (v) != 0)
1974  {
1975  /* Extract the bit parameters out from the bitfield
1976  sub-expression. */
1977  bitpos = value_bitpos (v);
1978  bitsize = value_bitsize (v);
1979  }
1980  else if (v == result && b->val_bitsize != 0)
1981  {
1982  /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1983  lvalue whose bit parameters are saved in the fields
1984  VAL_BITPOS and VAL_BITSIZE. */
1985  bitpos = b->val_bitpos;
1986  bitsize = b->val_bitsize;
1987  }
1988 
1989  addr = value_address (v);
1990  if (bitsize != 0)
1991  {
1992  /* Skip the bytes that don't contain the bitfield. */
1993  addr += bitpos / 8;
1994  }
1995 
1996  type = hw_write;
1997  if (b->base.type == bp_read_watchpoint)
1998  type = hw_read;
1999  else if (b->base.type == bp_access_watchpoint)
2000  type = hw_access;
2001 
2002  loc = allocate_bp_location (&b->base);
2003  for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
2004  ;
2005  *tmp = loc;
2006  loc->gdbarch = get_type_arch (value_type (v));
2007 
2008  loc->pspace = frame_pspace;
2009  loc->address = addr;
2010 
2011  if (bitsize != 0)
2012  {
2013  /* Just cover the bytes that make up the bitfield. */
2014  loc->length = ((bitpos % 8) + bitsize + 7) / 8;
2015  }
2016  else
2017  loc->length = TYPE_LENGTH (value_type (v));
2018 
2019  loc->watchpoint_type = type;
2020  }
2021  }
2022  }
2023 
2024  /* Change the type of breakpoint between hardware assisted or
2025  an ordinary watchpoint depending on the hardware support
2026  and free hardware slots. REPARSE is set when the inferior
2027  is started. */
2028  if (reparse)
2029  {
2030  int reg_cnt;
2031  enum bp_loc_type loc_type;
2032  struct bp_location *bl;
2033 
2034  reg_cnt = can_use_hardware_watchpoint (val_chain);
2035 
2036  if (reg_cnt)
2037  {
2038  int i, target_resources_ok, other_type_used;
2039  enum bptype type;
2040 
2041  /* Use an exact watchpoint when there's only one memory region to be
2042  watched, and only one debug register is needed to watch it. */
2043  b->exact = target_exact_watchpoints && reg_cnt == 1;
2044 
2045  /* We need to determine how many resources are already
2046  used for all other hardware watchpoints plus this one
2047  to see if we still have enough resources to also fit
2048  this watchpoint in as well. */
2049 
2050  /* If this is a software watchpoint, we try to turn it
2051  to a hardware one -- count resources as if B was of
2052  hardware watchpoint type. */
2053  type = b->base.type;
2054  if (type == bp_watchpoint)
2055  type = bp_hardware_watchpoint;
2056 
2057  /* This watchpoint may or may not have been placed on
2058  the list yet at this point (it won't be in the list
2059  if we're trying to create it for the first time,
2060  through watch_command), so always account for it
2061  manually. */
2062 
2063  /* Count resources used by all watchpoints except B. */
2064  i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
2065 
2066  /* Add in the resources needed for B. */
2067  i += hw_watchpoint_use_count (&b->base);
2068 
2069  target_resources_ok
2070  = target_can_use_hardware_watchpoint (type, i, other_type_used);
2071  if (target_resources_ok <= 0)
2072  {
2073  int sw_mode = b->base.ops->works_in_software_mode (&b->base);
2074 
2075  if (target_resources_ok == 0 && !sw_mode)
2076  error (_("Target does not support this type of "
2077  "hardware watchpoint."));
2078  else if (target_resources_ok < 0 && !sw_mode)
2079  error (_("There are not enough available hardware "
2080  "resources for this watchpoint."));
2081 
2082  /* Downgrade to software watchpoint. */
2083  b->base.type = bp_watchpoint;
2084  }
2085  else
2086  {
2087  /* If this was a software watchpoint, we've just
2088  found we have enough resources to turn it to a
2089  hardware watchpoint. Otherwise, this is a
2090  nop. */
2091  b->base.type = type;
2092  }
2093  }
2094  else if (!b->base.ops->works_in_software_mode (&b->base))
2095  {
2096  if (!can_use_hw_watchpoints)
2097  error (_("Can't set read/access watchpoint when "
2098  "hardware watchpoints are disabled."));
2099  else
2100  error (_("Expression cannot be implemented with "
2101  "read/access watchpoint."));
2102  }
2103  else
2104  b->base.type = bp_watchpoint;
2105 
2106  loc_type = (b->base.type == bp_watchpoint? bp_loc_other
2108  for (bl = b->base.loc; bl; bl = bl->next)
2109  bl->loc_type = loc_type;
2110  }
2111 
2112  for (v = val_chain; v; v = next)
2113  {
2114  next = value_next (v);
2115  if (v != b->val)
2116  value_free (v);
2117  }
2118 
2119  /* If a software watchpoint is not watching any memory, then the
2120  above left it without any location set up. But,
2121  bpstat_stop_status requires a location to be able to report
2122  stops, so make sure there's at least a dummy one. */
2123  if (b->base.type == bp_watchpoint && b->base.loc == NULL)
2124  {
2125  struct breakpoint *base = &b->base;
2126  base->loc = allocate_bp_location (base);
2127  base->loc->pspace = frame_pspace;
2128  base->loc->address = -1;
2129  base->loc->length = -1;
2130  base->loc->watchpoint_type = -1;
2131  }
2132  }
2133  else if (!within_current_scope)
2134  {
2135  printf_filtered (_("\
2136 Watchpoint %d deleted because the program has left the block\n\
2137 in which its expression is valid.\n"),
2138  b->base.number);
2140  }
2141 
2142  /* Restore the selected frame. */
2143  if (frame_saved)
2144  select_frame (frame_find_by_id (saved_frame_id));
2145 }
2146 
2147 
2148 /* Returns 1 iff breakpoint location should be
2149  inserted in the inferior. We don't differentiate the type of BL's owner
2150  (breakpoint vs. tracepoint), although insert_location in tracepoint's
2151  breakpoint_ops is not defined, because in insert_bp_location,
2152  tracepoint's insert_location will not be called. */
2153 static int
2154 should_be_inserted (struct bp_location *bl)
2155 {
2156  if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
2157  return 0;
2158 
2160  return 0;
2161 
2162  if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
2163  return 0;
2164 
2165  if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2166  return 0;
2167 
2168  /* This is set for example, when we're attached to the parent of a
2169  vfork, and have detached from the child. The child is running
2170  free, and we expect it to do an exec or exit, at which point the
2171  OS makes the parent schedulable again (and the target reports
2172  that the vfork is done). Until the child is done with the shared
2173  memory region, do not insert breakpoints in the parent, otherwise
2174  the child could still trip on the parent's breakpoints. Since
2175  the parent is blocked anyway, it won't miss any breakpoint. */
2177  return 0;
2178 
2179  /* Don't insert a breakpoint if we're trying to step past its
2180  location. */
2184  bl->address))
2185  {
2186  if (debug_infrun)
2187  {
2189  "infrun: skipping breakpoint: "
2190  "stepping past insn at: %s\n",
2191  paddress (bl->gdbarch, bl->address));
2192  }
2193  return 0;
2194  }
2195 
2196  /* Don't insert watchpoints if we're trying to step past the
2197  instruction that triggered one. */
2200  {
2201  if (debug_infrun)
2202  {
2204  "infrun: stepping past non-steppable watchpoint. "
2205  "skipping watchpoint at %s:%d\n",
2206  paddress (bl->gdbarch, bl->address),
2207  bl->length);
2208  }
2209  return 0;
2210  }
2211 
2212  return 1;
2213 }
2214 
2215 /* Same as should_be_inserted but does the check assuming
2216  that the location is not duplicated. */
2217 
2218 static int
2219 unduplicated_should_be_inserted (struct bp_location *bl)
2220 {
2221  int result;
2222  const int save_duplicate = bl->duplicate;
2223 
2224  bl->duplicate = 0;
2225  result = should_be_inserted (bl);
2226  bl->duplicate = save_duplicate;
2227  return result;
2228 }
2229 
2230 /* Parses a conditional described by an expression COND into an
2231  agent expression bytecode suitable for evaluation
2232  by the bytecode interpreter. Return NULL if there was
2233  any error during parsing. */
2234 
2235 static struct agent_expr *
2237 {
2238  struct agent_expr *aexpr = NULL;
2239 
2240  if (!cond)
2241  return NULL;
2242 
2243  /* We don't want to stop processing, so catch any errors
2244  that may show up. */
2245  TRY
2246  {
2247  aexpr = gen_eval_for_expr (scope, cond);
2248  }
2249 
2250  CATCH (ex, RETURN_MASK_ERROR)
2251  {
2252  /* If we got here, it means the condition could not be parsed to a valid
2253  bytecode expression and thus can't be evaluated on the target's side.
2254  It's no use iterating through the conditions. */
2255  return NULL;
2256  }
2257  END_CATCH
2258 
2259  /* We have a valid agent expression. */
2260  return aexpr;
2261 }
2262 
2263 /* Based on location BL, create a list of breakpoint conditions to be
2264  passed on to the target. If we have duplicated locations with different
2265  conditions, we will add such conditions to the list. The idea is that the
2266  target will evaluate the list of conditions and will only notify GDB when
2267  one of them is true. */
2268 
2269 static void
2270 build_target_condition_list (struct bp_location *bl)
2271 {
2272  struct bp_location **locp = NULL, **loc2p;
2273  int null_condition_or_parse_error = 0;
2274  int modified = bl->needs_update;
2275  struct bp_location *loc;
2276 
2277  /* Release conditions left over from a previous insert. */
2278  VEC_free (agent_expr_p, bl->target_info.conditions);
2279 
2280  /* This is only meaningful if the target is
2281  evaluating conditions and if the user has
2282  opted for condition evaluation on the target's
2283  side. */
2286  return;
2287 
2288  /* Do a first pass to check for locations with no assigned
2289  conditions or conditions that fail to parse to a valid agent expression
2290  bytecode. If any of these happen, then it's no use to send conditions
2291  to the target since this location will always trigger and generate a
2292  response back to GDB. */
2293  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2294  {
2295  loc = (*loc2p);
2296  if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2297  {
2298  if (modified)
2299  {
2300  struct agent_expr *aexpr;
2301 
2302  /* Re-parse the conditions since something changed. In that
2303  case we already freed the condition bytecodes (see
2304  force_breakpoint_reinsertion). We just
2305  need to parse the condition to bytecodes again. */
2306  aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2307  loc->cond_bytecode = aexpr;
2308 
2309  /* Check if we managed to parse the conditional expression
2310  correctly. If not, we will not send this condition
2311  to the target. */
2312  if (aexpr)
2313  continue;
2314  }
2315 
2316  /* If we have a NULL bytecode expression, it means something
2317  went wrong or we have a null condition expression. */
2318  if (!loc->cond_bytecode)
2319  {
2320  null_condition_or_parse_error = 1;
2321  break;
2322  }
2323  }
2324  }
2325 
2326  /* If any of these happened, it means we will have to evaluate the conditions
2327  for the location's address on gdb's side. It is no use keeping bytecodes
2328  for all the other duplicate locations, thus we free all of them here.
2329 
2330  This is so we have a finer control over which locations' conditions are
2331  being evaluated by GDB or the remote stub. */
2332  if (null_condition_or_parse_error)
2333  {
2334  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2335  {
2336  loc = (*loc2p);
2337  if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2338  {
2339  /* Only go as far as the first NULL bytecode is
2340  located. */
2341  if (!loc->cond_bytecode)
2342  return;
2343 
2345  loc->cond_bytecode = NULL;
2346  }
2347  }
2348  }
2349 
2350  /* No NULL conditions or failed bytecode generation. Build a condition list
2351  for this location's address. */
2352  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2353  {
2354  loc = (*loc2p);
2355  if (loc->cond
2356  && is_breakpoint (loc->owner)
2357  && loc->pspace->num == bl->pspace->num
2358  && loc->owner->enable_state == bp_enabled
2359  && loc->enabled)
2360  /* Add the condition to the vector. This will be used later to send the
2361  conditions to the target. */
2362  VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2363  loc->cond_bytecode);
2364  }
2365 
2366  return;
2367 }
2368 
2369 /* Parses a command described by string CMD into an agent expression
2370  bytecode suitable for evaluation by the bytecode interpreter.
2371  Return NULL if there was any error during parsing. */
2372 
2373 static struct agent_expr *
2375 {
2376  struct cleanup *old_cleanups = 0;
2377  struct expression *expr, **argvec;
2378  struct agent_expr *aexpr = NULL;
2379  const char *cmdrest;
2380  const char *format_start, *format_end;
2381  struct format_piece *fpieces;
2382  int nargs;
2383  struct gdbarch *gdbarch = get_current_arch ();
2384 
2385  if (!cmd)
2386  return NULL;
2387 
2388  cmdrest = cmd;
2389 
2390  if (*cmdrest == ',')
2391  ++cmdrest;
2392  cmdrest = skip_spaces_const (cmdrest);
2393 
2394  if (*cmdrest++ != '"')
2395  error (_("No format string following the location"));
2396 
2397  format_start = cmdrest;
2398 
2399  fpieces = parse_format_string (&cmdrest);
2400 
2401  old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2402 
2403  format_end = cmdrest;
2404 
2405  if (*cmdrest++ != '"')
2406  error (_("Bad format string, non-terminated '\"'."));
2407 
2408  cmdrest = skip_spaces_const (cmdrest);
2409 
2410  if (!(*cmdrest == ',' || *cmdrest == '\0'))
2411  error (_("Invalid argument syntax"));
2412 
2413  if (*cmdrest == ',')
2414  cmdrest++;
2415  cmdrest = skip_spaces_const (cmdrest);
2416 
2417  /* For each argument, make an expression. */
2418 
2419  argvec = (struct expression **) alloca (strlen (cmd)
2420  * sizeof (struct expression *));
2421 
2422  nargs = 0;
2423  while (*cmdrest != '\0')
2424  {
2425  const char *cmd1;
2426 
2427  cmd1 = cmdrest;
2428  expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2429  argvec[nargs++] = expr;
2430  cmdrest = cmd1;
2431  if (*cmdrest == ',')
2432  ++cmdrest;
2433  }
2434 
2435  /* We don't want to stop processing, so catch any errors
2436  that may show up. */
2437  TRY
2438  {
2439  aexpr = gen_printf (scope, gdbarch, 0, 0,
2440  format_start, format_end - format_start,
2441  fpieces, nargs, argvec);
2442  }
2443  CATCH (ex, RETURN_MASK_ERROR)
2444  {
2445  /* If we got here, it means the command could not be parsed to a valid
2446  bytecode expression and thus can't be evaluated on the target's side.
2447  It's no use iterating through the other commands. */
2448  aexpr = NULL;
2449  }
2450  END_CATCH
2451 
2452  do_cleanups (old_cleanups);
2453 
2454  /* We have a valid agent expression, return it. */
2455  return aexpr;
2456 }
2457 
2458 /* Based on location BL, create a list of breakpoint commands to be
2459  passed on to the target. If we have duplicated locations with
2460  different commands, we will add any such to the list. */
2461 
2462 static void
2463 build_target_command_list (struct bp_location *bl)
2464 {
2465  struct bp_location **locp = NULL, **loc2p;
2466  int null_command_or_parse_error = 0;
2467  int modified = bl->needs_update;
2468  struct bp_location *loc;
2469 
2470  /* Release commands left over from a previous insert. */
2471  VEC_free (agent_expr_p, bl->target_info.tcommands);
2472 
2474  return;
2475 
2476  /* For now, limit to agent-style dprintf breakpoints. */
2477  if (dprintf_style != dprintf_style_agent)
2478  return;
2479 
2480  /* For now, if we have any duplicate location that isn't a dprintf,
2481  don't install the target-side commands, as that would make the
2482  breakpoint not be reported to the core, and we'd lose
2483  control. */
2484  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2485  {
2486  loc = (*loc2p);
2487  if (is_breakpoint (loc->owner)
2488  && loc->pspace->num == bl->pspace->num
2489  && loc->owner->type != bp_dprintf)
2490  return;
2491  }
2492 
2493  /* Do a first pass to check for locations with no assigned
2494  conditions or conditions that fail to parse to a valid agent expression
2495  bytecode. If any of these happen, then it's no use to send conditions
2496  to the target since this location will always trigger and generate a
2497  response back to GDB. */
2498  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2499  {
2500  loc = (*loc2p);
2501  if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2502  {
2503  if (modified)
2504  {
2505  struct agent_expr *aexpr;
2506 
2507  /* Re-parse the commands since something changed. In that
2508  case we already freed the command bytecodes (see
2509  force_breakpoint_reinsertion). We just
2510  need to parse the command to bytecodes again. */
2511  aexpr = parse_cmd_to_aexpr (bl->address,
2512  loc->owner->extra_string);
2513  loc->cmd_bytecode = aexpr;
2514 
2515  if (!aexpr)
2516  continue;
2517  }
2518 
2519  /* If we have a NULL bytecode expression, it means something
2520  went wrong or we have a null command expression. */
2521  if (!loc->cmd_bytecode)
2522  {
2523  null_command_or_parse_error = 1;
2524  break;
2525  }
2526  }
2527  }
2528 
2529  /* If anything failed, then we're not doing target-side commands,
2530  and so clean up. */
2531  if (null_command_or_parse_error)
2532  {
2533  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2534  {
2535  loc = (*loc2p);
2536  if (is_breakpoint (loc->owner)
2537  && loc->pspace->num == bl->pspace->num)
2538  {
2539  /* Only go as far as the first NULL bytecode is
2540  located. */
2541  if (loc->cmd_bytecode == NULL)
2542  return;
2543 
2545  loc->cmd_bytecode = NULL;
2546  }
2547  }
2548  }
2549 
2550  /* No NULL commands or failed bytecode generation. Build a command list
2551  for this location's address. */
2552  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2553  {
2554  loc = (*loc2p);
2555  if (loc->owner->extra_string
2556  && is_breakpoint (loc->owner)
2557  && loc->pspace->num == bl->pspace->num
2558  && loc->owner->enable_state == bp_enabled
2559  && loc->enabled)
2560  /* Add the command to the vector. This will be used later
2561  to send the commands to the target. */
2562  VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2563  loc->cmd_bytecode);
2564  }
2565 
2566  bl->target_info.persist = 0;
2567  /* Maybe flag this location as persistent. */
2568  if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2569  bl->target_info.persist = 1;
2570 }
2571 
2572 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2573  location. Any error messages are printed to TMP_ERROR_STREAM; and
2574  DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2575  Returns 0 for success, 1 if the bp_location type is not supported or
2576  -1 for failure.
2577 
2578  NOTE drow/2003-09-09: This routine could be broken down to an
2579  object-style method for each breakpoint or catchpoint type. */
2580 static int
2581 insert_bp_location (struct bp_location *bl,
2582  struct ui_file *tmp_error_stream,
2583  int *disabled_breaks,
2584  int *hw_breakpoint_error,
2585  int *hw_bp_error_explained_already)
2586 {
2587  enum errors bp_err = GDB_NO_ERROR;
2588  const char *bp_err_message = NULL;
2589 
2590  if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
2591  return 0;
2592 
2593  /* Note we don't initialize bl->target_info, as that wipes out
2594  the breakpoint location's shadow_contents if the breakpoint
2595  is still inserted at that location. This in turn breaks
2596  target_read_memory which depends on these buffers when
2597  a memory read is requested at the breakpoint location:
2598  Once the target_info has been wiped, we fail to see that
2599  we have a breakpoint inserted at that address and thus
2600  read the breakpoint instead of returning the data saved in
2601  the breakpoint location's shadow contents. */
2604  bl->target_info.length = bl->length;
2605 
2606  /* When working with target-side conditions, we must pass all the conditions
2607  for the same breakpoint address down to the target since GDB will not
2608  insert those locations. With a list of breakpoint conditions, the target
2609  can decide when to stop and notify GDB. */
2610 
2611  if (is_breakpoint (bl->owner))
2612  {
2615  /* Reset the modification marker. */
2616  bl->needs_update = 0;
2617  }
2618 
2621  {
2622  if (bl->owner->type != bp_hardware_breakpoint)
2623  {
2624  /* If the explicitly specified breakpoint type
2625  is not hardware breakpoint, check the memory map to see
2626  if the breakpoint address is in read only memory or not.
2627 
2628  Two important cases are:
2629  - location type is not hardware breakpoint, memory
2630  is readonly. We change the type of the location to
2631  hardware breakpoint.
2632  - location type is hardware breakpoint, memory is
2633  read-write. This means we've previously made the
2634  location hardware one, but then the memory map changed,
2635  so we undo.
2636 
2637  When breakpoints are removed, remove_breakpoints will use
2638  location types we've just set here, the only possible
2639  problem is that memory map has changed during running
2640  program, but it's not going to work anyway with current
2641  gdb. */
2642  struct mem_region *mr
2644 
2645  if (mr)
2646  {
2647  if (automatic_hardware_breakpoints)
2648  {
2649  enum bp_loc_type new_type;
2650 
2651  if (mr->attrib.mode != MEM_RW)
2652  new_type = bp_loc_hardware_breakpoint;
2653  else
2654  new_type = bp_loc_software_breakpoint;
2655 
2656  if (new_type != bl->loc_type)
2657  {
2658  static int said = 0;
2659 
2660  bl->loc_type = new_type;
2661  if (!said)
2662  {
2664  _("Note: automatically using "
2665  "hardware breakpoints for "
2666  "read-only addresses.\n"));
2667  said = 1;
2668  }
2669  }
2670  }
2671  else if (bl->loc_type == bp_loc_software_breakpoint
2672  && mr->attrib.mode != MEM_RW)
2673  {
2674  fprintf_unfiltered (tmp_error_stream,
2675  _("Cannot insert breakpoint %d.\n"
2676  "Cannot set software breakpoint "
2677  "at read-only address %s\n"),
2678  bl->owner->number,
2679  paddress (bl->gdbarch, bl->address));
2680  return 1;
2681  }
2682  }
2683  }
2684 
2685  /* First check to see if we have to handle an overlay. */
2687  || bl->section == NULL
2688  || !(section_is_overlay (bl->section)))
2689  {
2690  /* No overlay handling: just set the breakpoint. */
2691  TRY
2692  {
2693  int val;
2694 
2695  val = bl->owner->ops->insert_location (bl);
2696  if (val)
2697  bp_err = GENERIC_ERROR;
2698  }
2699  CATCH (e, RETURN_MASK_ALL)
2700  {
2701  bp_err = e.error;
2702  bp_err_message = e.message;
2703  }
2704  END_CATCH
2705  }
2706  else
2707  {
2708  /* This breakpoint is in an overlay section.
2709  Shall we set a breakpoint at the LMA? */
2710  if (!overlay_events_enabled)
2711  {
2712  /* Yes -- overlay event support is not active,
2713  so we must try to set a breakpoint at the LMA.
2714  This will not work for a hardware breakpoint. */
2716  warning (_("hardware breakpoint %d not supported in overlay!"),
2717  bl->owner->number);
2718  else
2719  {
2721  bl->section);
2722  /* Set a software (trap) breakpoint at the LMA. */
2723  bl->overlay_target_info = bl->target_info;
2725 
2726  /* No overlay handling: just set the breakpoint. */
2727  TRY
2728  {
2729  int val;
2730 
2731  val = target_insert_breakpoint (bl->gdbarch,
2732  &bl->overlay_target_info);
2733  if (val)
2734  bp_err = GENERIC_ERROR;
2735  }
2736  CATCH (e, RETURN_MASK_ALL)
2737  {
2738  bp_err = e.error;
2739  bp_err_message = e.message;
2740  }
2741  END_CATCH
2742 
2743  if (bp_err != GDB_NO_ERROR)
2744  fprintf_unfiltered (tmp_error_stream,
2745  "Overlay breakpoint %d "
2746  "failed: in ROM?\n",
2747  bl->owner->number);
2748  }
2749  }
2750  /* Shall we set a breakpoint at the VMA? */
2751  if (section_is_mapped (bl->section))
2752  {
2753  /* Yes. This overlay section is mapped into memory. */
2754  TRY
2755  {
2756  int val;
2757 
2758  val = bl->owner->ops->insert_location (bl);
2759  if (val)
2760  bp_err = GENERIC_ERROR;
2761  }
2762  CATCH (e, RETURN_MASK_ALL)
2763  {
2764  bp_err = e.error;
2765  bp_err_message = e.message;
2766  }
2767  END_CATCH
2768  }
2769  else
2770  {
2771  /* No. This breakpoint will not be inserted.
2772  No error, but do not mark the bp as 'inserted'. */
2773  return 0;
2774  }
2775  }
2776 
2777  if (bp_err != GDB_NO_ERROR)
2778  {
2779  /* Can't set the breakpoint. */
2780 
2781  /* In some cases, we might not be able to insert a
2782  breakpoint in a shared library that has already been
2783  removed, but we have not yet processed the shlib unload
2784  event. Unfortunately, some targets that implement
2785  breakpoint insertion themselves can't tell why the
2786  breakpoint insertion failed (e.g., the remote target
2787  doesn't define error codes), so we must treat generic
2788  errors as memory errors. */
2789  if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR)
2791  && (solib_name_from_address (bl->pspace, bl->address)
2793  bl->address)))
2794  {
2795  /* See also: disable_breakpoints_in_shlibs. */
2796  bl->shlib_disabled = 1;
2798  if (!*disabled_breaks)
2799  {
2800  fprintf_unfiltered (tmp_error_stream,
2801  "Cannot insert breakpoint %d.\n",
2802  bl->owner->number);
2803  fprintf_unfiltered (tmp_error_stream,
2804  "Temporarily disabling shared "
2805  "library breakpoints:\n");
2806  }
2807  *disabled_breaks = 1;
2808  fprintf_unfiltered (tmp_error_stream,
2809  "breakpoint #%d\n", bl->owner->number);
2810  return 0;
2811  }
2812  else
2813  {
2815  {
2816  *hw_breakpoint_error = 1;
2817  *hw_bp_error_explained_already = bp_err_message != NULL;
2818  fprintf_unfiltered (tmp_error_stream,
2819  "Cannot insert hardware breakpoint %d%s",
2820  bl->owner->number, bp_err_message ? ":" : ".\n");
2821  if (bp_err_message != NULL)
2822  fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message);
2823  }
2824  else
2825  {
2826  if (bp_err_message == NULL)
2827  {
2828  char *message
2830  bl->gdbarch, bl->address);
2831  struct cleanup *old_chain = make_cleanup (xfree, message);
2832 
2833  fprintf_unfiltered (tmp_error_stream,
2834  "Cannot insert breakpoint %d.\n"
2835  "%s\n",
2836  bl->owner->number, message);
2837  do_cleanups (old_chain);
2838  }
2839  else
2840  {
2841  fprintf_unfiltered (tmp_error_stream,
2842  "Cannot insert breakpoint %d: %s\n",
2843  bl->owner->number,
2844  bp_err_message);
2845  }
2846  }
2847  return 1;
2848 
2849  }
2850  }
2851  else
2852  bl->inserted = 1;
2853 
2854  return 0;
2855  }
2856 
2857  else if (bl->loc_type == bp_loc_hardware_watchpoint
2858  /* NOTE drow/2003-09-08: This state only exists for removing
2859  watchpoints. It's not clear that it's necessary... */
2861  {
2862  int val;
2863 
2864  gdb_assert (bl->owner->ops != NULL
2865  && bl->owner->ops->insert_location != NULL);
2866 
2867  val = bl->owner->ops->insert_location (bl);
2868 
2869  /* If trying to set a read-watchpoint, and it turns out it's not
2870  supported, try emulating one with an access watchpoint. */
2871  if (val == 1 && bl->watchpoint_type == hw_read)
2872  {
2873  struct bp_location *loc, **loc_temp;
2874 
2875  /* But don't try to insert it, if there's already another
2876  hw_access location that would be considered a duplicate
2877  of this one. */
2878  ALL_BP_LOCATIONS (loc, loc_temp)
2879  if (loc != bl
2880  && loc->watchpoint_type == hw_access
2881  && watchpoint_locations_match (bl, loc))
2882  {
2883  bl->duplicate = 1;
2884  bl->inserted = 1;
2885  bl->target_info = loc->target_info;
2886  bl->watchpoint_type = hw_access;
2887  val = 0;
2888  break;
2889  }
2890 
2891  if (val == 1)
2892  {
2893  bl->watchpoint_type = hw_access;
2894  val = bl->owner->ops->insert_location (bl);
2895 
2896  if (val)
2897  /* Back to the original value. */
2898  bl->watchpoint_type = hw_read;
2899  }
2900  }
2901 
2902  bl->inserted = (val == 0);
2903  }
2904 
2905  else if (bl->owner->type == bp_catchpoint)
2906  {
2907  int val;
2908 
2909  gdb_assert (bl->owner->ops != NULL
2910  && bl->owner->ops->insert_location != NULL);
2911 
2912  val = bl->owner->ops->insert_location (bl);
2913  if (val)
2914  {
2916 
2917  if (val == 1)
2918  warning (_("\
2919 Error inserting catchpoint %d: Your system does not support this type\n\
2920 of catchpoint."), bl->owner->number);
2921  else
2922  warning (_("Error inserting catchpoint %d."), bl->owner->number);
2923  }
2924 
2925  bl->inserted = (val == 0);
2926 
2927  /* We've already printed an error message if there was a problem
2928  inserting this catchpoint, and we've disabled the catchpoint,
2929  so just return success. */
2930  return 0;
2931  }
2932 
2933  return 0;
2934 }
2935 
2936 /* This function is called when program space PSPACE is about to be
2937  deleted. It takes care of updating breakpoints to not reference
2938  PSPACE anymore. */
2939 
2940 void
2942 {
2943  struct breakpoint *b, *b_temp;
2944  struct bp_location *loc, **loc_temp;
2945 
2946  /* Remove any breakpoint that was set through this program space. */
2947  ALL_BREAKPOINTS_SAFE (b, b_temp)
2948  {
2949  if (b->pspace == pspace)
2950  delete_breakpoint (b);
2951  }
2952 
2953  /* Breakpoints set through other program spaces could have locations
2954  bound to PSPACE as well. Remove those. */
2955  ALL_BP_LOCATIONS (loc, loc_temp)
2956  {
2957  struct bp_location *tmp;
2958 
2959  if (loc->pspace == pspace)
2960  {
2961  /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2962  if (loc->owner->loc == loc)
2963  loc->owner->loc = loc->next;
2964  else
2965  for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2966  if (tmp->next == loc)
2967  {
2968  tmp->next = loc->next;
2969  break;
2970  }
2971  }
2972  }
2973 
2974  /* Now update the global location list to permanently delete the
2975  removed locations above. */
2977 }
2978 
2979 /* Make sure all breakpoints are inserted in inferior.
2980  Throws exception on any error.
2981  A breakpoint that is already inserted won't be inserted
2982  again, so calling this function twice is safe. */
2983 void
2985 {
2986  struct breakpoint *bpt;
2987 
2988  ALL_BREAKPOINTS (bpt)
2989  if (is_hardware_watchpoint (bpt))
2990  {
2991  struct watchpoint *w = (struct watchpoint *) bpt;
2992 
2993  update_watchpoint (w, 0 /* don't reparse. */);
2994  }
2995 
2996  /* Updating watchpoints creates new locations, so update the global
2997  location list. Explicitly tell ugll to insert locations and
2998  ignore breakpoints_always_inserted_mode. */
3000 }
3001 
3002 /* Invoke CALLBACK for each of bp_location. */
3003 
3004 void
3006 {
3007  struct bp_location *loc, **loc_tmp;
3008 
3009  ALL_BP_LOCATIONS (loc, loc_tmp)
3010  {
3011  callback (loc, NULL);
3012  }
3013 }
3014 
3015 /* This is used when we need to synch breakpoint conditions between GDB and the
3016  target. It is the case with deleting and disabling of breakpoints when using
3017  always-inserted mode. */
3018 
3019 static void
3021 {
3022  struct bp_location *bl, **blp_tmp;
3023  int error_flag = 0;
3024  int val = 0;
3025  int disabled_breaks = 0;
3026  int hw_breakpoint_error = 0;
3027  int hw_bp_details_reported = 0;
3028 
3029  struct ui_file *tmp_error_stream = mem_fileopen ();
3030  struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3031 
3032  /* Explicitly mark the warning -- this will only be printed if
3033  there was an error. */
3034  fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3035 
3037 
3038  ALL_BP_LOCATIONS (bl, blp_tmp)
3039  {
3040  /* We only want to update software breakpoints and hardware
3041  breakpoints. */
3042  if (!is_breakpoint (bl->owner))
3043  continue;
3044 
3045  /* We only want to update locations that are already inserted
3046  and need updating. This is to avoid unwanted insertion during
3047  deletion of breakpoints. */
3048  if (!bl->inserted || (bl->inserted && !bl->needs_update))
3049  continue;
3050 
3052 
3053  /* For targets that support global breakpoints, there's no need
3054  to select an inferior to insert breakpoint to. In fact, even
3055  if we aren't attached to any process yet, we should still
3056  insert breakpoints. */
3059  continue;
3060 
3061  val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3062  &hw_breakpoint_error, &hw_bp_details_reported);
3063  if (val)
3064  error_flag = val;
3065  }
3066 
3067  if (error_flag)
3068  {
3070  error_stream (tmp_error_stream);
3071  }
3072 
3073  do_cleanups (cleanups);
3074 }
3075 
3076 /* Used when starting or continuing the program. */
3077 
3078 static void
3080 {
3081  struct breakpoint *bpt;
3082  struct bp_location *bl, **blp_tmp;
3083  int error_flag = 0;
3084  int val = 0;
3085  int disabled_breaks = 0;
3086  int hw_breakpoint_error = 0;
3087  int hw_bp_error_explained_already = 0;
3088 
3089  struct ui_file *tmp_error_stream = mem_fileopen ();
3090  struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
3091 
3092  /* Explicitly mark the warning -- this will only be printed if
3093  there was an error. */
3094  fprintf_unfiltered (tmp_error_stream, "Warning:\n");
3095 
3097 
3098  ALL_BP_LOCATIONS (bl, blp_tmp)
3099  {
3100  if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
3101  continue;
3102 
3103  /* There is no point inserting thread-specific breakpoints if
3104  the thread no longer exists. ALL_BP_LOCATIONS bp_location
3105  has BL->OWNER always non-NULL. */
3106  if (bl->owner->thread != -1
3107  && !valid_thread_id (bl->owner->thread))
3108  continue;
3109 
3111 
3112  /* For targets that support global breakpoints, there's no need
3113  to select an inferior to insert breakpoint to. In fact, even
3114  if we aren't attached to any process yet, we should still
3115  insert breakpoints. */
3118  continue;
3119 
3120  val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
3121  &hw_breakpoint_error, &hw_bp_error_explained_already);
3122  if (val)
3123  error_flag = val;
3124  }
3125 
3126  /* If we failed to insert all locations of a watchpoint, remove
3127  them, as half-inserted watchpoint is of limited use. */
3128  ALL_BREAKPOINTS (bpt)
3129  {
3130  int some_failed = 0;
3131  struct bp_location *loc;
3132 
3133  if (!is_hardware_watchpoint (bpt))
3134  continue;
3135 
3136  if (!breakpoint_enabled (bpt))
3137  continue;
3138 
3139  if (bpt->disposition == disp_del_at_next_stop)
3140  continue;
3141 
3142  for (loc = bpt->loc; loc; loc = loc->next)
3143  if (!loc->inserted && should_be_inserted (loc))
3144  {
3145  some_failed = 1;
3146  break;
3147  }
3148  if (some_failed)
3149  {
3150  for (loc = bpt->loc; loc; loc = loc->next)
3151  if (loc->inserted)
3153 
3154  hw_breakpoint_error = 1;
3155  fprintf_unfiltered (tmp_error_stream,
3156  "Could not insert hardware watchpoint %d.\n",
3157  bpt->number);
3158  error_flag = -1;
3159  }
3160  }
3161 
3162  if (error_flag)
3163  {
3164  /* If a hardware breakpoint or watchpoint was inserted, add a
3165  message about possibly exhausted resources. */
3166  if (hw_breakpoint_error && !hw_bp_error_explained_already)
3167  {
3168  fprintf_unfiltered (tmp_error_stream,
3169  "Could not insert hardware breakpoints:\n\
3170 You may have requested too many hardware breakpoints/watchpoints.\n");
3171  }
3173  error_stream (tmp_error_stream);
3174  }
3175 
3176  do_cleanups (cleanups);
3177 }
3178 
3179 /* Used when the program stops.
3180  Returns zero if successful, or non-zero if there was a problem
3181  removing a breakpoint location. */
3182 
3183 int
3185 {
3186  struct bp_location *bl, **blp_tmp;
3187  int val = 0;
3188 
3189  ALL_BP_LOCATIONS (bl, blp_tmp)
3190  {
3191  if (bl->inserted && !is_tracepoint (bl->owner))
3192  val |= remove_breakpoint (bl, mark_uninserted);
3193  }
3194  return val;
3195 }
3196 
3197 /* When a thread exits, remove breakpoints that are related to
3198  that thread. */
3199 
3200 static void
3202 {
3203  struct breakpoint *b, *b_tmp;
3204 
3205  ALL_BREAKPOINTS_SAFE (b, b_tmp)
3206  {
3207  if (b->thread == tp->num && user_breakpoint_p (b))
3208  {
3210 
3211  printf_filtered (_("\
3212 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3213  b->number, tp->num);
3214 
3215  /* Hide it from the user. */
3216  b->number = 0;
3217  }
3218  }
3219 }
3220 
3221 /* Remove breakpoints of process PID. */
3222 
3223 int
3225 {
3226  struct bp_location *bl, **blp_tmp;
3227  int val;
3228  struct inferior *inf = find_inferior_pid (pid);
3229 
3230  ALL_BP_LOCATIONS (bl, blp_tmp)
3231  {
3232  if (bl->pspace != inf->pspace)
3233  continue;
3234 
3235  if (bl->inserted && !bl->target_info.persist)
3236  {
3237  val = remove_breakpoint (bl, mark_uninserted);
3238  if (val != 0)
3239  return val;
3240  }
3241  }
3242  return 0;
3243 }
3244 
3245 int
3247 {
3248  struct cleanup *old_chain;
3249  struct bp_location *bl, **blp_tmp;
3250  int val;
3251  struct ui_file *tmp_error_stream;
3252  int dummy1 = 0, dummy2 = 0, dummy3 = 0;
3253  struct inferior *inf;
3254  struct thread_info *tp;
3255 
3256  tp = any_live_thread_of_process (pid);
3257  if (tp == NULL)
3258  return 1;
3259 
3260  inf = find_inferior_pid (pid);
3261  old_chain = save_inferior_ptid ();
3262 
3263  inferior_ptid = tp->ptid;
3264 
3265  tmp_error_stream = mem_fileopen ();
3266  make_cleanup_ui_file_delete (tmp_error_stream);
3267 
3268  ALL_BP_LOCATIONS (bl, blp_tmp)
3269  {
3270  if (bl->pspace != inf->pspace)
3271  continue;
3272 
3273  if (bl->inserted)
3274  {
3275  bl->inserted = 0;
3276  val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
3277  if (val != 0)
3278  {
3279  do_cleanups (old_chain);
3280  return val;
3281  }
3282  }
3283  }
3284  do_cleanups (old_chain);
3285  return 0;
3286 }
3287 
3288 static int internal_breakpoint_number = -1;
3289 
3290 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3291  If INTERNAL is non-zero, the breakpoint number will be populated
3292  from internal_breakpoint_number and that variable decremented.
3293  Otherwise the breakpoint number will be populated from
3294  breakpoint_count and that value incremented. Internal breakpoints
3295  do not set the internal var bpnum. */
3296 static void
3297 set_breakpoint_number (int internal, struct breakpoint *b)
3298 {
3299  if (internal)
3300  b->number = internal_breakpoint_number--;
3301  else
3302  {
3303  set_breakpoint_count (breakpoint_count + 1);
3304  b->number = breakpoint_count;
3305  }
3306 }
3307 
3308 static struct breakpoint *
3310  CORE_ADDR address, enum bptype type,
3311  const struct breakpoint_ops *ops)
3312 {
3313  struct symtab_and_line sal;
3314  struct breakpoint *b;
3315 
3316  init_sal (&sal); /* Initialize to zeroes. */
3317 
3318  sal.pc = address;
3319  sal.section = find_pc_overlay (sal.pc);
3321 
3322  b = set_raw_breakpoint (gdbarch, sal, type, ops);
3323  b->number = internal_breakpoint_number--;
3325 
3326  return b;
3327 }
3328 
3329 static const char *const longjmp_names[] =
3330  {
3331  "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3332  };
3333 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3334 
3335 /* Per-objfile data private to breakpoint.c. */
3337 {
3338  /* Minimal symbol for "_ovly_debug_event" (if any). */
3340 
3341  /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3343 
3344  /* True if we have looked for longjmp probes. */
3346 
3347  /* SystemTap probe points for longjmp (if any). */
3348  VEC (probe_p) *longjmp_probes;
3349 
3350  /* Minimal symbol for "std::terminate()" (if any). */
3351  struct bound_minimal_symbol terminate_msym;
3352 
3353  /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3354  struct bound_minimal_symbol exception_msym;
3355 
3356  /* True if we have looked for exception probes. */
3357  int exception_searched;
3358 
3359  /* SystemTap probe points for unwinding (if any). */
3360  VEC (probe_p) *exception_probes;
3361 };
3362 
3363 static const struct objfile_data *breakpoint_objfile_key;
3364 
3365 /* Minimal symbol not found sentinel. */
3367 
3368 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3369 
3370 static int
3371 msym_not_found_p (const struct minimal_symbol *msym)
3372 {
3373  return msym == &msym_not_found;
3374 }
3375 
3376 /* Return per-objfile data needed by breakpoint.c.
3377  Allocate the data if necessary. */
3378 
3379 static struct breakpoint_objfile_data *
3381 {
3382  struct breakpoint_objfile_data *bp_objfile_data;
3383 
3384  bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3385  if (bp_objfile_data == NULL)
3386  {
3387  bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3388  sizeof (*bp_objfile_data));
3389 
3390  memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3391  set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3392  }
3393  return bp_objfile_data;
3394 }
3395 
3396 static void
3397 free_breakpoint_probes (struct objfile *obj, void *data)
3398 {
3399  struct breakpoint_objfile_data *bp_objfile_data = data;
3400 
3401  VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3402  VEC_free (probe_p, bp_objfile_data->exception_probes);
3403 }
3404 
3405 static void
3407 {
3408  struct objfile *objfile;
3409  const char *const func_name = "_ovly_debug_event";
3410 
3411  ALL_OBJFILES (objfile)
3412  {
3413  struct breakpoint *b;
3414  struct breakpoint_objfile_data *bp_objfile_data;
3415  CORE_ADDR addr;
3416 
3417  bp_objfile_data = get_breakpoint_objfile_data (objfile);
3418 
3419  if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym))
3420  continue;
3421 
3422  if (bp_objfile_data->overlay_msym.minsym == NULL)
3423  {
3424  struct bound_minimal_symbol m;
3425 
3426  m = lookup_minimal_symbol_text (func_name, objfile);
3427  if (m.minsym == NULL)
3428  {
3429  /* Avoid future lookups in this objfile. */
3430  bp_objfile_data->overlay_msym.minsym = &msym_not_found;
3431  continue;
3432  }
3433  bp_objfile_data->overlay_msym = m;
3434  }
3435 
3436  addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3437  b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3440  b->addr_string = xstrdup (func_name);
3441 
3443  {
3444  b->enable_state = bp_enabled;
3445  overlay_events_enabled = 1;
3446  }
3447  else
3448  {
3450  overlay_events_enabled = 0;
3451  }
3452  }
3454 }
3455 
3456 static void
3458 {
3459  struct program_space *pspace;
3460  struct cleanup *old_chain;
3461 
3462  old_chain = save_current_program_space ();
3463 
3464  ALL_PSPACES (pspace)
3465  {
3466  struct objfile *objfile;
3467 
3468  set_current_program_space (pspace);
3469 
3470  ALL_OBJFILES (objfile)
3471  {
3472  int i;
3473  struct gdbarch *gdbarch;
3474  struct breakpoint_objfile_data *bp_objfile_data;
3475 
3476  gdbarch = get_objfile_arch (objfile);
3477 
3478  bp_objfile_data = get_breakpoint_objfile_data (objfile);
3479 
3480  if (!bp_objfile_data->longjmp_searched)
3481  {
3482  VEC (probe_p) *ret;
3483 
3484  ret = find_probes_in_objfile (objfile, "libc", "longjmp");
3485  if (ret != NULL)
3486  {
3487  /* We are only interested in checking one element. */
3488  struct probe *p = VEC_index (probe_p, ret, 0);
3489 
3491  {
3492  /* We cannot use the probe interface here, because it does
3493  not know how to evaluate arguments. */
3494  VEC_free (probe_p, ret);
3495  ret = NULL;
3496  }
3497  }
3498  bp_objfile_data->longjmp_probes = ret;
3499  bp_objfile_data->longjmp_searched = 1;
3500  }
3501 
3502  if (bp_objfile_data->longjmp_probes != NULL)
3503  {
3504  int i;
3505  struct probe *probe;
3506  struct gdbarch *gdbarch = get_objfile_arch (objfile);
3507 
3508  for (i = 0;
3510  bp_objfile_data->longjmp_probes,
3511  i, probe);
3512  ++i)
3513  {
3514  struct breakpoint *b;
3515 
3516  b = create_internal_breakpoint (gdbarch,
3517  get_probe_address (probe,
3518  objfile),
3521  b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3523  }
3524 
3525  continue;
3526  }
3527 
3528  if (!gdbarch_get_longjmp_target_p (gdbarch))
3529  continue;
3530 
3531  for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3532  {
3533  struct breakpoint *b;
3534  const char *func_name;
3535  CORE_ADDR addr;
3536 
3537  if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
3538  continue;
3539 
3540  func_name = longjmp_names[i];
3541  if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
3542  {
3543  struct bound_minimal_symbol m;
3544 
3545  m = lookup_minimal_symbol_text (func_name, objfile);
3546  if (m.minsym == NULL)
3547  {
3548  /* Prevent future lookups in this objfile. */
3549  bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
3550  continue;
3551  }
3552  bp_objfile_data->longjmp_msym[i] = m;
3553  }
3554 
3555  addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3556  b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3558  b->addr_string = xstrdup (func_name);
3560  }
3561  }
3562  }
3564 
3565  do_cleanups (old_chain);
3566 }
3567 
3568 /* Create a master std::terminate breakpoint. */
3569 static void
3571 {
3572  struct program_space *pspace;
3573  struct cleanup *old_chain;
3574  const char *const func_name = "std::terminate()";
3575 
3576  old_chain = save_current_program_space ();
3577 
3578  ALL_PSPACES (pspace)
3579  {
3580  struct objfile *objfile;
3581  CORE_ADDR addr;
3582 
3583  set_current_program_space (pspace);
3584 
3585  ALL_OBJFILES (objfile)
3586  {
3587  struct breakpoint *b;
3588  struct breakpoint_objfile_data *bp_objfile_data;
3589 
3590  bp_objfile_data = get_breakpoint_objfile_data (objfile);
3591 
3592  if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
3593  continue;
3594 
3595  if (bp_objfile_data->terminate_msym.minsym == NULL)
3596  {
3597  struct bound_minimal_symbol m;
3598 
3599  m = lookup_minimal_symbol (func_name, NULL, objfile);
3600  if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
3601  && MSYMBOL_TYPE (m.minsym) != mst_file_text))
3602  {
3603  /* Prevent future lookups in this objfile. */
3604  bp_objfile_data->terminate_msym.minsym = &msym_not_found;
3605  continue;
3606  }
3607  bp_objfile_data->terminate_msym = m;
3608  }
3609 
3610  addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3611  b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3614  b->addr_string = xstrdup (func_name);
3616  }
3617  }
3618 
3620 
3621  do_cleanups (old_chain);
3622 }
3623 
3624 /* Install a master breakpoint on the unwinder's debug hook. */
3625 
3626 static void
3628 {
3629  struct objfile *objfile;
3630  const char *const func_name = "_Unwind_DebugHook";
3631 
3632  ALL_OBJFILES (objfile)
3633  {
3634  struct breakpoint *b;
3635  struct gdbarch *gdbarch;
3636  struct breakpoint_objfile_data *bp_objfile_data;
3637  CORE_ADDR addr;
3638 
3639  bp_objfile_data = get_breakpoint_objfile_data (objfile);
3640 
3641  /* We prefer the SystemTap probe point if it exists. */
3642  if (!bp_objfile_data->exception_searched)
3643  {
3644  VEC (probe_p) *ret;
3645 
3646  ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
3647 
3648  if (ret != NULL)
3649  {
3650  /* We are only interested in checking one element. */
3651  struct probe *p = VEC_index (probe_p, ret, 0);
3652 
3654  {
3655  /* We cannot use the probe interface here, because it does
3656  not know how to evaluate arguments. */
3657  VEC_free (probe_p, ret);
3658  ret = NULL;
3659  }
3660  }
3661  bp_objfile_data->exception_probes = ret;
3662  bp_objfile_data->exception_searched = 1;
3663  }
3664 
3665  if (bp_objfile_data->exception_probes != NULL)
3666  {
3667  struct gdbarch *gdbarch = get_objfile_arch (objfile);
3668  int i;
3669  struct probe *probe;
3670 
3671  for (i = 0;
3673  bp_objfile_data->exception_probes,
3674  i, probe);
3675  ++i)
3676  {
3677  struct breakpoint *b;
3678 
3679  b = create_internal_breakpoint (gdbarch,
3680  get_probe_address (probe,
3681  objfile),
3684  b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3686  }
3687 
3688  continue;
3689  }
3690 
3691  /* Otherwise, try the hook function. */
3692 
3693  if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
3694  continue;
3695 
3696  gdbarch = get_objfile_arch (objfile);
3697 
3698  if (bp_objfile_data->exception_msym.minsym == NULL)
3699  {
3700  struct bound_minimal_symbol debug_hook;
3701 
3702  debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3703  if (debug_hook.minsym == NULL)
3704  {
3705  bp_objfile_data->exception_msym.minsym = &msym_not_found;
3706  continue;
3707  }
3708 
3709  bp_objfile_data->exception_msym = debug_hook;
3710  }
3711 
3712  addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3713  addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3714  &current_target);
3715  b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3717  b->addr_string = xstrdup (func_name);
3719  }
3720 
3722 }
3723 
3724 void
3726 {
3727  struct breakpoint *b, *b_tmp;
3728  struct bp_location *bploc, **bplocp_tmp;
3729 
3730  /* We're about to delete breakpoints from GDB's lists. If the
3731  INSERTED flag is true, GDB will try to lift the breakpoints by
3732  writing the breakpoints' "shadow contents" back into memory. The
3733  "shadow contents" are NOT valid after an exec, so GDB should not
3734  do that. Instead, the target is responsible from marking
3735  breakpoints out as soon as it detects an exec. We don't do that
3736  here instead, because there may be other attempts to delete
3737  breakpoints after detecting an exec and before reaching here. */
3738  ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3739  if (bploc->pspace == current_program_space)
3740  gdb_assert (!bploc->inserted);
3741 
3742  ALL_BREAKPOINTS_SAFE (b, b_tmp)
3743  {
3744  if (b->pspace != current_program_space)
3745  continue;
3746 
3747  /* Solib breakpoints must be explicitly reset after an exec(). */
3748  if (b->type == bp_shlib_event)
3749  {
3750  delete_breakpoint (b);
3751  continue;
3752  }
3753 
3754  /* JIT breakpoints must be explicitly reset after an exec(). */
3755  if (b->type == bp_jit_event)
3756  {
3757  delete_breakpoint (b);
3758  continue;
3759  }
3760 
3761  /* Thread event breakpoints must be set anew after an exec(),
3762  as must overlay event and longjmp master breakpoints. */
3763  if (b->type == bp_thread_event || b->type == bp_overlay_event
3765  || b->type == bp_exception_master)
3766  {
3767  delete_breakpoint (b);
3768  continue;
3769  }
3770 
3771  /* Step-resume breakpoints are meaningless after an exec(). */
3772  if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
3773  {
3774  delete_breakpoint (b);
3775  continue;
3776  }
3777 
3778  /* Just like single-step breakpoints. */
3779  if (b->type == bp_single_step)
3780  {
3781  delete_breakpoint (b);
3782  continue;
3783  }
3784 
3785  /* Longjmp and longjmp-resume breakpoints are also meaningless
3786  after an exec. */
3787  if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3788  || b->type == bp_longjmp_call_dummy
3789  || b->type == bp_exception || b->type == bp_exception_resume)
3790  {
3791  delete_breakpoint (b);
3792  continue;
3793  }
3794 
3795  if (b->type == bp_catchpoint)
3796  {
3797  /* For now, none of the bp_catchpoint breakpoints need to
3798  do anything at this point. In the future, if some of
3799  the catchpoints need to something, we will need to add
3800  a new method, and call this method from here. */
3801  continue;
3802  }
3803 
3804  /* bp_finish is a special case. The only way we ought to be able
3805  to see one of these when an exec() has happened, is if the user
3806  caught a vfork, and then said "finish". Ordinarily a finish just
3807  carries them to the call-site of the current callee, by setting
3808  a temporary bp there and resuming. But in this case, the finish
3809  will carry them entirely through the vfork & exec.
3810 
3811  We don't want to allow a bp_finish to remain inserted now. But
3812  we can't safely delete it, 'cause finish_command has a handle to
3813  the bp on a bpstat, and will later want to delete it. There's a
3814  chance (and I've seen it happen) that if we delete the bp_finish
3815  here, that its storage will get reused by the time finish_command
3816  gets 'round to deleting the "use to be a bp_finish" breakpoint.
3817  We really must allow finish_command to delete a bp_finish.
3818 
3819  In the absence of a general solution for the "how do we know
3820  it's safe to delete something others may have handles to?"
3821  problem, what we'll do here is just uninsert the bp_finish, and
3822  let finish_command delete it.
3823 
3824  (We know the bp_finish is "doomed" in the sense that it's
3825  momentary, and will be deleted as soon as finish_command sees
3826  the inferior stopped. So it doesn't matter that the bp's
3827  address is probably bogus in the new a.out, unlike e.g., the
3828  solib breakpoints.) */
3829 
3830  if (b->type == bp_finish)
3831  {
3832  continue;
3833  }
3834 
3835  /* Without a symbolic address, we have little hope of the
3836  pre-exec() address meaning the same thing in the post-exec()
3837  a.out. */
3838  if (b->addr_string == NULL)
3839  {
3840  delete_breakpoint (b);
3841  continue;
3842  }
3843  }
3844 }
3845 
3846 int
3848 {
3849  struct bp_location *bl, **blp_tmp;
3850  int val = 0;
3851  struct cleanup *old_chain = save_inferior_ptid ();
3852  struct inferior *inf = current_inferior ();
3853 
3854  if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid))
3855  error (_("Cannot detach breakpoints of inferior_ptid"));
3856 
3857  /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3858  inferior_ptid = ptid;
3859  ALL_BP_LOCATIONS (bl, blp_tmp)
3860  {
3861  if (bl->pspace != inf->pspace)
3862  continue;
3863 
3864  /* This function must physically remove breakpoints locations
3865  from the specified ptid, without modifying the breakpoint
3866  package's state. Locations of type bp_loc_other are only
3867  maintained at GDB side. So, there is no need to remove
3868  these bp_loc_other locations. Moreover, removing these
3869  would modify the breakpoint package's state. */
3870  if (bl->loc_type == bp_loc_other)
3871  continue;
3872 
3873  if (bl->inserted)
3874  val |= remove_breakpoint_1 (bl, mark_inserted);
3875  }
3876 
3877  do_cleanups (old_chain);
3878  return val;
3879 }
3880 
3881 /* Remove the breakpoint location BL from the current address space.
3882  Note that this is used to detach breakpoints from a child fork.
3883  When we get here, the child isn't in the inferior list, and neither
3884  do we have objects to represent its address space --- we should
3885  *not* look at bl->pspace->aspace here. */
3886 
3887 static int
3888 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
3889 {
3890  int val;
3891 
3892  /* BL is never in moribund_locations by our callers. */
3893  gdb_assert (bl->owner != NULL);
3894 
3895  /* The type of none suggests that owner is actually deleted.
3896  This should not ever happen. */
3897  gdb_assert (bl->owner->type != bp_none);
3898 
3901  {
3902  /* "Normal" instruction breakpoint: either the standard
3903  trap-instruction bp (bp_breakpoint), or a
3904  bp_hardware_breakpoint. */
3905 
3906  /* First check to see if we have to handle an overlay. */
3908  || bl->section == NULL
3909  || !(section_is_overlay (bl->section)))
3910  {
3911  /* No overlay handling: just remove the breakpoint. */
3912 
3913  /* If we're trying to uninsert a memory breakpoint that we
3914  know is set in a dynamic object that is marked
3915  shlib_disabled, then either the dynamic object was
3916  removed with "remove-symbol-file" or with
3917  "nosharedlibrary". In the former case, we don't know
3918  whether another dynamic object might have loaded over the
3919  breakpoint's address -- the user might well let us know
3920  about it next with add-symbol-file (the whole point of
3921  add-symbol-file is letting the user manually maintain a
3922  list of dynamically loaded objects). If we have the
3923  breakpoint's shadow memory, that is, this is a software
3924  breakpoint managed by GDB, check whether the breakpoint
3925  is still inserted in memory, to avoid overwriting wrong
3926  code with stale saved shadow contents. Note that HW
3927  breakpoints don't have shadow memory, as they're
3928  implemented using a mechanism that is not dependent on
3929  being able to modify the target's memory, and as such
3930  they should always be removed. */
3931  if (bl->shlib_disabled
3932  && bl->target_info.shadow_len != 0
3934  val = 0;
3935  else
3936  val = bl->owner->ops->remove_location (bl);
3937  }
3938  else
3939  {
3940  /* This breakpoint is in an overlay section.
3941  Did we set a breakpoint at the LMA? */
3942  if (!overlay_events_enabled)
3943  {
3944  /* Yes -- overlay event support is not active, so we
3945  should have set a breakpoint at the LMA. Remove it.
3946  */
3947  /* Ignore any failures: if the LMA is in ROM, we will
3948  have already warned when we failed to insert it. */
3951  &bl->overlay_target_info);
3952  else
3954  &bl->overlay_target_info);
3955  }
3956  /* Did we set a breakpoint at the VMA?
3957  If so, we will have marked the breakpoint 'inserted'. */
3958  if (bl->inserted)
3959  {
3960  /* Yes -- remove it. Previously we did not bother to
3961  remove the breakpoint if the section had been
3962  unmapped, but let's not rely on that being safe. We
3963  don't know what the overlay manager might do. */
3964 
3965  /* However, we should remove *software* breakpoints only
3966  if the section is still mapped, or else we overwrite
3967  wrong code with the saved shadow contents. */
3969  || section_is_mapped (bl->section))
3970  val = bl->owner->ops->remove_location (bl);
3971  else
3972  val = 0;
3973  }
3974  else
3975  {
3976  /* No -- not inserted, so no need to remove. No error. */
3977  val = 0;
3978  }
3979  }
3980 
3981  /* In some cases, we might not be able to remove a breakpoint in
3982  a shared library that has already been removed, but we have
3983  not yet processed the shlib unload event. Similarly for an
3984  unloaded add-symbol-file object - the user might not yet have
3985  had the chance to remove-symbol-file it. shlib_disabled will
3986  be set if the library/object has already been removed, but
3987  the breakpoint hasn't been uninserted yet, e.g., after
3988  "nosharedlibrary" or "remove-symbol-file" with breakpoints
3989  always-inserted mode. */
3990  if (val
3992  && (bl->shlib_disabled
3993  || solib_name_from_address (bl->pspace, bl->address)
3995  bl->address))))
3996  val = 0;
3997 
3998  if (val)
3999  return val;
4000  bl->inserted = (is == mark_inserted);
4001  }
4002  else if (bl->loc_type == bp_loc_hardware_watchpoint)
4003  {
4004  gdb_assert (bl->owner->ops != NULL
4005  && bl->owner->ops->remove_location != NULL);
4006 
4007  bl->inserted = (is == mark_inserted);
4008  bl->owner->ops->remove_location (bl);
4009 
4010  /* Failure to remove any of the hardware watchpoints comes here. */
4011  if ((is == mark_uninserted) && (bl->inserted))
4012  warning (_("Could not remove hardware watchpoint %d."),
4013  bl->owner->number);
4014  }
4015  else if (bl->owner->type == bp_catchpoint
4016  && breakpoint_enabled (bl->owner)
4017  && !bl->duplicate)
4018  {
4019  gdb_assert (bl->owner->ops != NULL
4020  && bl->owner->ops->remove_location != NULL);
4021 
4022  val = bl->owner->ops->remove_location (bl);
4023  if (val)
4024  return val;
4025 
4026  bl->inserted = (is == mark_inserted);
4027  }
4028 
4029  return 0;
4030 }
4031 
4032 static int
4033 remove_breakpoint (struct bp_location *bl, insertion_state_t is)
4034 {
4035  int ret;
4036  struct cleanup *old_chain;
4037 
4038  /* BL is never in moribund_locations by our callers. */
4039  gdb_assert (bl->owner != NULL);
4040 
4041  /* The type of none suggests that owner is actually deleted.
4042  This should not ever happen. */
4043  gdb_assert (bl->owner->type != bp_none);
4044 
4045  old_chain = save_current_space_and_thread ();
4046 
4048 
4049  ret = remove_breakpoint_1 (bl, is);
4050 
4051  do_cleanups (old_chain);
4052  return ret;
4053 }
4054 
4055 /* Clear the "inserted" flag in all breakpoints. */
4056 
4057 void
4059 {
4060  struct bp_location *bl, **blp_tmp;
4061 
4062  ALL_BP_LOCATIONS (bl, blp_tmp)
4063  if (bl->pspace == current_program_space)
4064  bl->inserted = 0;
4065 }
4066 
4067 /* Clear the "inserted" flag in all breakpoints and delete any
4068  breakpoints which should go away between runs of the program.
4069 
4070  Plus other such housekeeping that has to be done for breakpoints
4071  between runs.
4072 
4073  Note: this function gets called at the end of a run (by
4074  generic_mourn_inferior) and when a run begins (by
4075  init_wait_for_inferior). */
4076 
4077 
4078 
4079 void
4081 {
4082  struct breakpoint *b, *b_tmp;
4083  struct bp_location *bl, **blp_tmp;
4084  int ix;
4085  struct program_space *pspace = current_program_space;
4086 
4087  /* If breakpoint locations are shared across processes, then there's
4088  nothing to do. */
4090  return;
4091 
4093 
4094  ALL_BREAKPOINTS_SAFE (b, b_tmp)
4095  {
4096  if (b->loc && b->loc->pspace != pspace)
4097  continue;
4098 
4099  switch (b->type)
4100  {
4101  case bp_call_dummy:
4102  case bp_longjmp_call_dummy:
4103 
4104  /* If the call dummy breakpoint is at the entry point it will
4105  cause problems when the inferior is rerun, so we better get
4106  rid of it. */
4107 
4108  case bp_watchpoint_scope:
4109 
4110  /* Also get rid of scope breakpoints. */
4111 
4112  case bp_shlib_event:
4113 
4114  /* Also remove solib event breakpoints. Their addresses may
4115  have changed since the last time we ran the program.
4116  Actually we may now be debugging against different target;
4117  and so the solib backend that installed this breakpoint may
4118  not be used in by the target. E.g.,
4119 
4120  (gdb) file prog-linux
4121  (gdb) run # native linux target
4122  ...
4123  (gdb) kill
4124  (gdb) file prog-win.exe
4125  (gdb) tar rem :9999 # remote Windows gdbserver.
4126  */
4127 
4128  case bp_step_resume:
4129 
4130  /* Also remove step-resume breakpoints. */
4131 
4132  case bp_single_step:
4133 
4134  /* Also remove single-step breakpoints. */
4135 
4136  delete_breakpoint (b);
4137  break;
4138 
4139  case bp_watchpoint:
4141  case bp_read_watchpoint:
4142  case bp_access_watchpoint:
4143  {
4144  struct watchpoint *w = (struct watchpoint *) b;
4145 
4146  /* Likewise for watchpoints on local expressions. */
4147  if (w->exp_valid_block != NULL)
4148  delete_breakpoint (b);
4149  else if (context == inf_starting)
4150  {
4151  /* Reset val field to force reread of starting value in
4152  insert_breakpoints. */
4153  if (w->val)
4154  value_free (w->val);
4155  w->val = NULL;
4156  w->val_valid = 0;
4157  }
4158  }
4159  break;
4160  default:
4161  break;
4162  }
4163  }
4164 
4165  /* Get rid of the moribund locations. */
4166  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
4167  decref_bp_location (&bl);
4168  VEC_free (bp_location_p, moribund_locations);
4169 }
4170 
4171 /* These functions concern about actual breakpoints inserted in the
4172  target --- to e.g. check if we need to do decr_pc adjustment or if
4173  we need to hop over the bkpt --- so we check for address space
4174  match, not program space. */
4175 
4176 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4177  exists at PC. It returns ordinary_breakpoint_here if it's an
4178  ordinary breakpoint, or permanent_breakpoint_here if it's a
4179  permanent breakpoint.
4180  - When continuing from a location with an ordinary breakpoint, we
4181  actually single step once before calling insert_breakpoints.
4182  - When continuing from a location with a permanent breakpoint, we
4183  need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4184  the target, to advance the PC past the breakpoint. */
4185 
4186 enum breakpoint_here
4188 {
4189  struct bp_location *bl, **blp_tmp;
4190  int any_breakpoint_here = 0;
4191 
4192  ALL_BP_LOCATIONS (bl, blp_tmp)
4193  {
4196  continue;
4197 
4198  /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4199  if ((breakpoint_enabled (bl->owner)
4200  || bl->permanent)
4201  && breakpoint_location_address_match (bl, aspace, pc))
4202  {
4203  if (overlay_debugging
4204  && section_is_overlay (bl->section)
4205  && !section_is_mapped (bl->section))
4206  continue; /* unmapped overlay -- can't be a match */
4207  else if (bl->permanent)
4209  else
4210  any_breakpoint_here = 1;
4211  }
4212  }
4213 
4214  return any_breakpoint_here ? ordinary_breakpoint_here : 0;
4215 }
4216 
4217 /* Return true if there's a moribund breakpoint at PC. */
4218 
4219 int
4221 {
4222  struct bp_location *loc;
4223  int ix;
4224 
4225  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4226  if (breakpoint_location_address_match (loc, aspace, pc))
4227  return 1;
4228 
4229  return 0;
4230 }
4231 
4232 /* Returns non-zero iff BL is inserted at PC, in address space
4233  ASPACE. */
4234 
4235 static int
4236 bp_location_inserted_here_p (struct bp_location *bl,
4237  struct address_space *aspace, CORE_ADDR pc)
4238 {
4239  if (bl->inserted
4241  aspace, pc))
4242  {
4243  if (overlay_debugging
4244  && section_is_overlay (bl->section)
4245  && !section_is_mapped (bl->section))
4246  return 0; /* unmapped overlay -- can't be a match */
4247  else
4248  return 1;
4249  }
4250  return 0;
4251 }
4252 
4253 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4254 
4255 int
4257 {
4258  struct bp_location **blp, **blp_tmp = NULL;
4259  struct bp_location *bl;
4260 
4261  ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4262  {
4263  struct bp_location *bl = *blp;
4264 
4267  continue;
4268 
4269  if (bp_location_inserted_here_p (bl, aspace, pc))
4270  return 1;
4271  }
4272  return 0;
4273 }
4274 
4275 /* This function returns non-zero iff there is a software breakpoint
4276  inserted at PC. */
4277 
4278 int
4280  CORE_ADDR pc)
4281 {
4282  struct bp_location **blp, **blp_tmp = NULL;
4283  struct bp_location *bl;
4284 
4285  ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4286  {
4287  struct bp_location *bl = *blp;
4288 
4290  continue;
4291 
4292  if (bp_location_inserted_here_p (bl, aspace, pc))
4293  return 1;
4294  }
4295 
4296  return 0;
4297 }
4298 
4299 /* See breakpoint.h. */
4300 
4301 int
4303  CORE_ADDR pc)
4304 {
4305  struct bp_location **blp, **blp_tmp = NULL;
4306  struct bp_location *bl;
4307 
4308  ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc)
4309  {
4310  struct bp_location *bl = *blp;
4311 
4313  continue;
4314 
4315  if (bp_location_inserted_here_p (bl, aspace, pc))
4316  return 1;
4317  }
4318 
4319  return 0;
4320 }
4321 
4322 int
4324  CORE_ADDR addr, ULONGEST len)
4325 {
4326  struct breakpoint *bpt;
4327 
4328  ALL_BREAKPOINTS (bpt)
4329  {
4330  struct bp_location *loc;
4331 
4332  if (bpt->type != bp_hardware_watchpoint
4333  && bpt->type != bp_access_watchpoint)
4334  continue;
4335 
4336  if (!breakpoint_enabled (bpt))
4337  continue;
4338 
4339  for (loc = bpt->loc; loc; loc = loc->next)
4340  if (loc->pspace->aspace == aspace && loc->inserted)
4341  {
4342  CORE_ADDR l, h;
4343 
4344  /* Check for intersection. */
4345  l = max (loc->address, addr);
4346  h = min (loc->address + loc->length, addr + len);
4347  if (l < h)
4348  return 1;
4349  }
4350  }
4351  return 0;
4352 }
4353 
4354 
4355 /* bpstat stuff. External routines' interfaces are documented
4356  in breakpoint.h. */
4357 
4358 int
4360 {
4361  return (ep->type == bp_catchpoint);
4362 }
4363 
4364 /* Frees any storage that is part of a bpstat. Does not walk the
4365  'next' chain. */
4366 
4367 static void
4369 {
4370  if (bs->old_val != NULL)
4371  value_free (bs->old_val);
4374  xfree (bs);
4375 }
4376 
4377 /* Clear a bpstat so that it says we are not at any breakpoint.
4378  Also free any storage that is part of a bpstat. */
4379 
4380 void
4382 {
4383  bpstat p;
4384  bpstat q;
4385 
4386  if (bsp == 0)
4387  return;
4388  p = *bsp;
4389  while (p != NULL)
4390  {
4391  q = p->next;
4392  bpstat_free (p);
4393  p = q;
4394  }
4395  *bsp = NULL;
4396 }
4397 
4398 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4399  is part of the bpstat is copied as well. */
4400 
4401 bpstat
4403 {
4404  bpstat p = NULL;
4405  bpstat tmp;
4406  bpstat retval = NULL;
4407 
4408  if (bs == NULL)
4409  return bs;
4410 
4411  for (; bs != NULL; bs = bs->next)
4412  {
4413  tmp = (bpstat) xmalloc (sizeof (*tmp));
4414  memcpy (tmp, bs, sizeof (*tmp));
4417  if (bs->old_val != NULL)
4418  {
4419  tmp->old_val = value_copy (bs->old_val);
4420  release_value (tmp->old_val);
4421  }
4422 
4423  if (p == NULL)
4424  /* This is the first thing in the chain. */
4425  retval = tmp;
4426  else
4427  p->next = tmp;
4428  p = tmp;
4429  }
4430  p->next = NULL;
4431  return retval;
4432 }
4433 
4434 /* Find the bpstat associated with this breakpoint. */
4435 
4436 bpstat
4438 {
4439  if (bsp == NULL)
4440  return NULL;
4441 
4442  for (; bsp != NULL; bsp = bsp->next)
4443  {
4444  if (bsp->breakpoint_at == breakpoint)
4445  return bsp;
4446  }
4447  return NULL;
4448 }
4449 
4450 /* See breakpoint.h. */
4451 
4452 int
4453 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4454 {
4455  for (; bsp != NULL; bsp = bsp->next)
4456  {
4457  if (bsp->breakpoint_at == NULL)
4458  {
4459  /* A moribund location can never explain a signal other than
4460  GDB_SIGNAL_TRAP. */
4461  if (sig == GDB_SIGNAL_TRAP)
4462  return 1;
4463  }
4464  else
4465  {
4467  sig))
4468  return 1;
4469  }
4470  }
4471 
4472  return 0;
4473 }
4474 
4475 /* Put in *NUM the breakpoint number of the first breakpoint we are
4476  stopped at. *BSP upon return is a bpstat which points to the
4477  remaining breakpoints stopped at (but which is not guaranteed to be
4478  good for anything but further calls to bpstat_num).
4479 
4480  Return 0 if passed a bpstat which does not indicate any breakpoints.
4481  Return -1 if stopped at a breakpoint that has been deleted since
4482  we set it.
4483  Return 1 otherwise. */
4484 
4485 int
4486 bpstat_num (bpstat *bsp, int *num)
4487 {
4488  struct breakpoint *b;
4489 
4490  if ((*bsp) == NULL)
4491  return 0; /* No more breakpoint values */
4492 
4493  /* We assume we'll never have several bpstats that correspond to a
4494  single breakpoint -- otherwise, this function might return the
4495  same number more than once and this will look ugly. */
4496  b = (*bsp)->breakpoint_at;
4497  *bsp = (*bsp)->next;
4498  if (b == NULL)
4499  return -1; /* breakpoint that's been deleted since */
4500 
4501  *num = b->number; /* We have its number */
4502  return 1;
4503 }
4504 
4505 /* See breakpoint.h. */
4506 
4507 void
4509 {
4510  struct thread_info *tp;
4511  bpstat bs;
4512 
4514  return;
4515 
4517  if (tp == NULL)
4518  return;
4519 
4520  for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
4521  {
4523 
4524  if (bs->old_val != NULL)
4525  {
4526  value_free (bs->old_val);
4527  bs->old_val = NULL;
4528  }
4529  }
4530 }
4531 
4532 /* Called when a command is about to proceed the inferior. */
4533 
4534 static void
4536 {
4538  {
4539  struct thread_info *tp = inferior_thread ();
4540 
4541  /* Allow inferior function calls in breakpoint commands to not
4542  interrupt the command list. When the call finishes
4543  successfully, the inferior will be standing at the same
4544  breakpoint as if nothing happened. */
4545  if (tp->control.in_infcall)
4546  return;
4547  }
4548 
4549  breakpoint_proceeded = 1;
4550 }
4551 
4552 /* Stub for cleaning up our state if we error-out of a breakpoint
4553  command. */
4554 static void
4556 {
4557  executing_breakpoint_commands = 0;
4558 }
4559 
4560 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4561  or its equivalent. */
4562 
4563 static int
4565 {
4566  return cmd && (strcmp ("silent", cmd->line) == 0);
4567 }
4568 
4569 /* Execute all the commands associated with all the breakpoints at
4570  this location. Any of these commands could cause the process to
4571  proceed beyond this point, etc. We look out for such changes by
4572  checking the global "breakpoint_proceeded" after each command.
4573 
4574  Returns true if a breakpoint command resumed the inferior. In that
4575  case, it is the caller's responsibility to recall it again with the
4576  bpstat of the current thread. */
4577 
4578 static int
4580 {
4581  bpstat bs;
4582  struct cleanup *old_chain;
4583  int again = 0;
4584 
4585  /* Avoid endless recursion if a `source' command is contained
4586  in bs->commands. */
4587  if (executing_breakpoint_commands)
4588  return 0;
4589 
4590  executing_breakpoint_commands = 1;
4592 
4594 
4595  /* This pointer will iterate over the list of bpstat's. */
4596  bs = *bsp;
4597 
4598  breakpoint_proceeded = 0;
4599  for (; bs != NULL; bs = bs->next)
4600  {
4601  struct counted_command_line *ccmd;
4602  struct command_line *cmd;
4603  struct cleanup *this_cmd_tree_chain;
4604 
4605  /* Take ownership of the BSP's command tree, if it has one.
4606 
4607  The command tree could legitimately contain commands like
4608  'step' and 'next', which call clear_proceed_status, which
4609  frees stop_bpstat's command tree. To make sure this doesn't
4610  free the tree we're executing out from under us, we need to
4611  take ownership of the tree ourselves. Since a given bpstat's
4612  commands are only executed once, we don't need to copy it; we
4613  can clear the pointer in the bpstat, and make sure we free
4614  the tree when we're done. */
4615  ccmd = bs->commands;
4616  bs->commands = NULL;
4617  this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4618  cmd = ccmd ? ccmd->commands : NULL;
4619  if (command_line_is_silent (cmd))
4620  {
4621  /* The action has been already done by bpstat_stop_status. */
4622  cmd = cmd->next;
4623  }
4624 
4625  while (cmd != NULL)
4626  {
4628 
4629  if (breakpoint_proceeded)
4630  break;
4631  else
4632  cmd = cmd->next;
4633  }
4634 
4635  /* We can free this command tree now. */
4636  do_cleanups (this_cmd_tree_chain);
4637 
4638  if (breakpoint_proceeded)
4639  {
4641  /* If we are in async mode, then the target might be still
4642  running, not stopped at any breakpoint, so nothing for
4643  us to do here -- just return to the event loop. */
4644  ;
4645  else
4646  /* In sync mode, when execute_control_command returns
4647  we're already standing on the next breakpoint.
4648  Breakpoint commands for that stop were not run, since
4649  execute_command does not run breakpoint commands --
4650  only command_line_handler does, but that one is not
4651  involved in execution of breakpoint commands. So, we
4652  can now execute breakpoint commands. It should be
4653  noted that making execute_command do bpstat actions is
4654  not an option -- in this case we'll have recursive
4655  invocation of bpstat for each breakpoint with a
4656  command, and can easily blow up GDB stack. Instead, we
4657  return true, which will trigger the caller to recall us
4658  with the new stop_bpstat. */
4659  again = 1;
4660  break;
4661  }
4662  }
4663  do_cleanups (old_chain);
4664  return again;
4665 }
4666 
4667 void
4669 {
4670  struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4671 
4672  /* Do any commands attached to breakpoint we are stopped at. */
4675  && !is_exited (inferior_ptid)
4677  /* Since in sync mode, bpstat_do_actions may resume the inferior,
4678  and only return when it is stopped at the next breakpoint, we
4679  keep doing breakpoint actions until it returns false to
4680  indicate the inferior was not resumed. */
4681  if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
4682  break;
4683 
4684  discard_cleanups (cleanup_if_error);
4685 }
4686 
4687 /* Print out the (old or new) value associated with a watchpoint. */
4688 
4689 static void
4690 watchpoint_value_print (struct value *val, struct ui_file *stream)
4691 {
4692  if (val == NULL)
4693  fprintf_unfiltered (stream, _("<unreadable>"));
4694  else
4695  {
4696  struct value_print_options opts;
4697  get_user_print_options (&opts);
4698  value_print (val, stream, &opts);
4699  }
4700 }
4701 
4702 /* Generic routine for printing messages indicating why we
4703  stopped. The behavior of this function depends on the value
4704  'print_it' in the bpstat structure. Under some circumstances we
4705  may decide not to print anything here and delegate the task to
4706  normal_stop(). */
4707 
4708 static enum print_stop_action
4710 {
4711  switch (bs->print_it)
4712  {
4713  case print_it_noop:
4714  /* Nothing should be printed for this bpstat entry. */
4715  return PRINT_UNKNOWN;
4716  break;
4717 
4718  case print_it_done:
4719  /* We still want to print the frame, but we already printed the
4720  relevant messages. */
4721  return PRINT_SRC_AND_LOC;
4722  break;
4723 
4724  case print_it_normal:
4725  {
4726  struct breakpoint *b = bs->breakpoint_at;
4727 
4728  /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4729  which has since been deleted. */
4730  if (b == NULL)
4731  return PRINT_UNKNOWN;
4732 
4733  /* Normal case. Call the breakpoint's print_it method. */
4734  return b->ops->print_it (bs);
4735  }
4736  break;
4737 
4738  default:
4739  internal_error (__FILE__, __LINE__,
4740  _("print_bp_stop_message: unrecognized enum value"));
4741  break;
4742  }
4743 }
4744 
4745 /* A helper function that prints a shared library stopped event. */
4746 
4747 static void
4749 {
4750  int any_deleted
4751  = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4752  int any_added
4753  = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4754 
4755  if (!is_catchpoint)
4756  {
4757  if (any_added || any_deleted)
4759  _("Stopped due to shared library event:\n"));
4760  else
4762  _("Stopped due to shared library event (no "
4763  "libraries added or removed)\n"));
4764  }
4765 
4769 
4770  if (any_deleted)
4771  {
4772  struct cleanup *cleanup;
4773  char *name;
4774  int ix;
4775 
4776  ui_out_text (current_uiout, _(" Inferior unloaded "));
4778  "removed");
4779  for (ix = 0;
4780  VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4781  ix, name);
4782  ++ix)
4783  {
4784  if (ix > 0)
4785  ui_out_text (current_uiout, " ");
4786  ui_out_field_string (current_uiout, "library", name);
4787  ui_out_text (current_uiout, "\n");
4788  }
4789 
4790  do_cleanups (cleanup);
4791  }
4792 
4793  if (any_added)
4794  {
4795  struct so_list *iter;
4796  int ix;
4797  struct cleanup *cleanup;
4798 
4799  ui_out_text (current_uiout, _(" Inferior loaded "));
4801  "added");
4802  for (ix = 0;
4804  ix, iter);
4805  ++ix)
4806  {
4807  if (ix > 0)
4808  ui_out_text (current_uiout, " ");
4809  ui_out_field_string (current_uiout, "library", iter->so_name);
4810  ui_out_text (current_uiout, "\n");
4811  }
4812 
4813  do_cleanups (cleanup);
4814  }
4815 }
4816 
4817 /* Print a message indicating what happened. This is called from
4818  normal_stop(). The input to this routine is the head of the bpstat
4819  list - a list of the eventpoints that caused this stop. KIND is
4820  the target_waitkind for the stopping event. This
4821  routine calls the generic print routine for printing a message
4822  about reasons for stopping. This will print (for example) the
4823  "Breakpoint n," part of the output. The return value of this
4824  routine is one of:
4825 
4826  PRINT_UNKNOWN: Means we printed nothing.
4827  PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4828  code to print the location. An example is
4829  "Breakpoint 1, " which should be followed by
4830  the location.
4831  PRINT_SRC_ONLY: Means we printed something, but there is no need
4832  to also print the location part of the message.
4833  An example is the catch/throw messages, which
4834  don't require a location appended to the end.
4835  PRINT_NOTHING: We have done some printing and we don't need any
4836  further info to be printed. */
4837 
4838 enum print_stop_action
4839 bpstat_print (bpstat bs, int kind)
4840 {
4841  int val;
4842 
4843  /* Maybe another breakpoint in the chain caused us to stop.
4844  (Currently all watchpoints go on the bpstat whether hit or not.
4845  That probably could (should) be changed, provided care is taken
4846  with respect to bpstat_explains_signal). */
4847  for (; bs; bs = bs->next)
4848  {
4849  val = print_bp_stop_message (bs);
4850  if (val == PRINT_SRC_ONLY
4851  || val == PRINT_SRC_AND_LOC
4852  || val == PRINT_NOTHING)
4853  return val;
4854  }
4855 
4856  /* If we had hit a shared library event breakpoint,
4857  print_bp_stop_message would print out this message. If we hit an
4858  OS-level shared library event, do the same thing. */
4859  if (kind == TARGET_WAITKIND_LOADED)
4860  {
4861  print_solib_event (0);
4862  return PRINT_NOTHING;
4863  }
4864 
4865  /* We reached the end of the chain, or we got a null BS to start
4866  with and nothing was printed. */
4867  return PRINT_UNKNOWN;
4868 }
4869 
4870 /* Evaluate the expression EXP and return 1 if value is zero.
4871  This returns the inverse of the condition because it is called
4872  from catch_errors which returns 0 if an exception happened, and if an
4873  exception happens we want execution to stop.
4874  The argument is a "struct expression *" that has been cast to a
4875  "void *" to make it pass through catch_errors. */
4876 
4877 static int
4879 {
4880  struct value *mark = value_mark ();
4881  int i = !value_true (evaluate_expression ((struct expression *) exp));
4882 
4883  value_free_to_mark (mark);
4884  return i;
4885 }
4886 
4887 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4888 
4889 static bpstat
4890 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
4891 {
4892  bpstat bs;
4893 
4894  bs = (bpstat) xmalloc (sizeof (*bs));
4895  bs->next = NULL;
4896  **bs_link_pointer = bs;
4897  *bs_link_pointer = &bs->next;
4898  bs->breakpoint_at = bl->owner;
4899  bs->bp_location_at = bl;
4900  incref_bp_location (bl);
4901  /* If the condition is false, etc., don't do the commands. */
4902  bs->commands = NULL;
4903  bs->old_val = NULL;
4904  bs->print_it = print_it_normal;
4905  return bs;
4906 }
4907 
4908 /* The target has stopped with waitstatus WS. Check if any hardware
4909  watchpoints have triggered, according to the target. */
4910 
4911 int
4913 {
4914  int stopped_by_watchpoint = target_stopped_by_watchpoint ();
4915  CORE_ADDR addr;
4916  struct breakpoint *b;
4917 
4918  if (!stopped_by_watchpoint)
4919  {
4920  /* We were not stopped by a watchpoint. Mark all watchpoints
4921  as not triggered. */
4922  ALL_BREAKPOINTS (b)
4923  if (is_hardware_watchpoint (b))
4924  {
4925  struct watchpoint *w = (struct watchpoint *) b;
4926 
4928  }
4929 
4930  return 0;
4931  }
4932 
4934  {
4935  /* We were stopped by a watchpoint, but we don't know where.
4936  Mark all watchpoints as unknown. */
4937  ALL_BREAKPOINTS (b)
4938  if (is_hardware_watchpoint (b))
4939  {
4940  struct watchpoint *w = (struct watchpoint *) b;
4941 
4943  }
4944 
4945  return 1;
4946  }
4947 
4948  /* The target could report the data address. Mark watchpoints
4949  affected by this data address as triggered, and all others as not
4950  triggered. */
4951 
4952  ALL_BREAKPOINTS (b)
4953  if (is_hardware_watchpoint (b))
4954  {
4955  struct watchpoint *w = (struct watchpoint *) b;
4956  struct bp_location *loc;
4957 
4959  for (loc = b->loc; loc; loc = loc->next)
4960  {
4961  if (is_masked_watchpoint (b))
4962  {
4963  CORE_ADDR newaddr = addr & w->hw_wp_mask;
4964  CORE_ADDR start = loc->address & w->hw_wp_mask;
4965 
4966  if (newaddr == start)
4967  {
4969  break;
4970  }
4971  }
4972  /* Exact match not required. Within range is sufficient. */
4974  addr, loc->address,
4975  loc->length))
4976  {
4978  break;
4979  }
4980  }
4981  }
4982 
4983  return 1;
4984 }
4985 
4986 /* Possible return values for watchpoint_check (this can't be an enum
4987  because of check_errors). */
4988 /* The watchpoint has been deleted. */
4989 #define WP_DELETED 1
4990 /* The value has changed. */
4991 #define WP_VALUE_CHANGED 2
4992 /* The value has not changed. */
4993 #define WP_VALUE_NOT_CHANGED 3
4994 /* Ignore this watchpoint, no matter if the value changed or not. */
4995 #define WP_IGNORE 4
4996 
4997 #define BP_TEMPFLAG 1
4998 #define BP_HARDWAREFLAG 2
4999 
5000 /* Evaluate watchpoint condition expression and check if its value
5001  changed.
5002 
5003  P should be a pointer to struct bpstat, but is defined as a void *
5004  in order for this function to be usable with catch_errors. */
5005 
5006 static int
5008 {
5009  bpstat bs = (bpstat) p;
5010  struct watchpoint *b;
5011  struct frame_info *fr;
5012  int within_current_scope;
5013 
5014  /* BS is built from an existing struct breakpoint. */
5015  gdb_assert (bs->breakpoint_at != NULL);
5016  b = (struct watchpoint *) bs->breakpoint_at;
5017 
5018  /* If this is a local watchpoint, we only want to check if the
5019  watchpoint frame is in scope if the current thread is the thread
5020  that was used to create the watchpoint. */
5022  return WP_IGNORE;
5023 
5024  if (b->exp_valid_block == NULL)
5025  within_current_scope = 1;
5026  else
5027  {
5028  struct frame_info *frame = get_current_frame ();
5029  struct gdbarch *frame_arch = get_frame_arch (frame);
5030  CORE_ADDR frame_pc = get_frame_pc (frame);
5031 
5032  /* stack_frame_destroyed_p() returns a non-zero value if we're
5033  still in the function but the stack frame has already been
5034  invalidated. Since we can't rely on the values of local
5035  variables after the stack has been destroyed, we are treating
5036  the watchpoint in that state as `not changed' without further
5037  checking. Don't mark watchpoints as changed if the current
5038  frame is in an epilogue - even if they are in some other
5039  frame, our view of the stack is likely to be wrong and
5040  frame_find_by_id could error out. */
5041  if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc))
5042  return WP_IGNORE;
5043 
5045  within_current_scope = (fr != NULL);
5046 
5047  /* If we've gotten confused in the unwinder, we might have
5048  returned a frame that can't describe this variable. */
5049  if (within_current_scope)
5050  {
5051  struct symbol *function;
5052 
5053  function = get_frame_function (fr);
5054  if (function == NULL
5055  || !contained_in (b->exp_valid_block,
5056  SYMBOL_BLOCK_VALUE (function)))
5057  within_current_scope = 0;
5058  }
5059 
5060  if (within_current_scope)
5061  /* If we end up stopping, the current frame will get selected
5062  in normal_stop. So this call to select_frame won't affect
5063  the user. */
5064  select_frame (fr);
5065  }
5066 
5067  if (within_current_scope)
5068  {
5069  /* We use value_{,free_to_}mark because it could be a *long*
5070  time before we return to the command level and call
5071  free_all_values. We can't call free_all_values because we
5072  might be in the middle of evaluating a function call. */
5073 
5074  int pc = 0;
5075  struct value *mark;
5076  struct value *new_val;
5077 
5078  if (is_masked_watchpoint (&b->base))
5079  /* Since we don't know the exact trigger address (from
5080  stopped_data_address), just tell the user we've triggered
5081  a mask watchpoint. */
5082  return WP_VALUE_CHANGED;
5083 
5084  mark = value_mark ();
5085  fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0);
5086 
5087  if (b->val_bitsize != 0)
5088  new_val = extract_bitfield_from_watchpoint_value (b, new_val);
5089 
5090  /* We use value_equal_contents instead of value_equal because
5091  the latter coerces an array to a pointer, thus comparing just
5092  the address of the array instead of its contents. This is
5093  not what we want. */
5094  if ((b->val != NULL) != (new_val != NULL)
5095  || (b->val != NULL && !value_equal_contents (b->val, new_val)))
5096  {
5097  if (new_val != NULL)
5098  {
5099  release_value (new_val);
5100  value_free_to_mark (mark);
5101  }
5102  bs->old_val = b->val;
5103  b->val = new_val;
5104  b->val_valid = 1;
5105  return WP_VALUE_CHANGED;
5106  }
5107  else
5108  {
5109  /* Nothing changed. */
5110  value_free_to_mark (mark);
5111  return WP_VALUE_NOT_CHANGED;
5112  }
5113  }
5114  else
5115  {
5116  struct ui_out *uiout = current_uiout;
5117 
5118  /* This seems like the only logical thing to do because
5119  if we temporarily ignored the watchpoint, then when
5120  we reenter the block in which it is valid it contains
5121  garbage (in the case of a function, it may have two
5122  garbage values, one before and one after the prologue).
5123  So we can't even detect the first assignment to it and
5124  watch after that (since the garbage may or may not equal
5125  the first value assigned). */
5126  /* We print all the stop information in
5127  breakpoint_ops->print_it, but in this case, by the time we
5128  call breakpoint_ops->print_it this bp will be deleted
5129  already. So we have no choice but print the information
5130  here. */
5131  if (ui_out_is_mi_like_p (uiout))
5133  (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
5134  ui_out_text (uiout, "\nWatchpoint ");
5135  ui_out_field_int (uiout, "wpnum", b->base.number);
5136  ui_out_text (uiout,
5137  " deleted because the program has left the block in\n\
5138 which its expression is valid.\n");
5139 
5140  /* Make sure the watchpoint's commands aren't executed. */
5143 
5144  return WP_DELETED;
5145  }
5146 }
5147 
5148 /* Return true if it looks like target has stopped due to hitting
5149  breakpoint location BL. This function does not check if we should
5150  stop, only if BL explains the stop. */
5151 
5152 static int
5153 bpstat_check_location (const struct bp_location *bl,
5154  struct address_space *aspace, CORE_ADDR bp_addr,
5155  const struct target_waitstatus *ws)
5156 {
5157  struct breakpoint *b = bl->owner;
5158 
5159  /* BL is from an existing breakpoint. */
5160  gdb_assert (b != NULL);
5161 
5162  return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
5163 }
5164 
5165 /* Determine if the watched values have actually changed, and we
5166  should stop. If not, set BS->stop to 0. */
5167 
5168 static void
5170 {
5171  const struct bp_location *bl;
5172  struct watchpoint *b;
5173 
5174  /* BS is built for existing struct breakpoint. */
5175  bl = bs->bp_location_at;
5176  gdb_assert (bl != NULL);
5177  b = (struct watchpoint *) bs->breakpoint_at;
5178  gdb_assert (b != NULL);
5179 
5180  {
5181  int must_check_value = 0;
5182 
5183  if (b->base.type == bp_watchpoint)
5184  /* For a software watchpoint, we must always check the
5185  watched value. */
5186  must_check_value = 1;
5188  /* We have a hardware watchpoint (read, write, or access)
5189  and the target earlier reported an address watched by
5190  this watchpoint. */
5191  must_check_value = 1;
5193  && b->base.type == bp_hardware_watchpoint)
5194  /* We were stopped by a hardware watchpoint, but the target could
5195  not report the data address. We must check the watchpoint's
5196  value. Access and read watchpoints are out of luck; without
5197  a data address, we can't figure it out. */
5198  must_check_value = 1;
5199 
5200  if (must_check_value)
5201  {
5202  char *message
5203  = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5204  b->base.number);
5205  struct cleanup *cleanups = make_cleanup (xfree, message);
5206  int e = catch_errors (watchpoint_check, bs, message,
5207  RETURN_MASK_ALL);
5208  do_cleanups (cleanups);
5209  switch (e)
5210  {
5211  case WP_DELETED:
5212  /* We've already printed what needs to be printed. */
5213  bs->print_it = print_it_done;
5214  /* Stop. */
5215  break;
5216  case WP_IGNORE:
5217  bs->print_it = print_it_noop;
5218  bs->stop = 0;
5219  break;
5220  case WP_VALUE_CHANGED:
5221  if (b->base.type == bp_read_watchpoint)
5222  {
5223  /* There are two cases to consider here:
5224 
5225  1. We're watching the triggered memory for reads.
5226  In that case, trust the target, and always report
5227  the watchpoint hit to the user. Even though
5228  reads don't cause value changes, the value may
5229  have changed since the last time it was read, and
5230  since we're not trapping writes, we will not see
5231  those, and as such we should ignore our notion of
5232  old value.
5233 
5234  2. We're watching the triggered memory for both
5235  reads and writes. There are two ways this may
5236  happen:
5237 
5238  2.1. This is a target that can't break on data
5239  reads only, but can break on accesses (reads or
5240  writes), such as e.g., x86. We detect this case
5241  at the time we try to insert read watchpoints.
5242 
5243  2.2. Otherwise, the target supports read
5244  watchpoints, but, the user set an access or write
5245  watchpoint watching the same memory as this read
5246  watchpoint.
5247 
5248  If we're watching memory writes as well as reads,
5249  ignore watchpoint hits when we find that the
5250  value hasn't changed, as reads don't cause
5251  changes. This still gives false positives when
5252  the program writes the same value to memory as
5253  what there was already in memory (we will confuse
5254  it for a read), but it's much better than
5255  nothing. */
5256 
5257  int other_write_watchpoint = 0;
5258 
5259  if (bl->watchpoint_type == hw_read)
5260  {
5261  struct breakpoint *other_b;
5262 
5263  ALL_BREAKPOINTS (other_b)
5264  if (other_b->type == bp_hardware_watchpoint
5265  || other_b->type == bp_access_watchpoint)
5266  {
5267  struct watchpoint *other_w =
5268  (struct watchpoint *) other_b;
5269 
5270  if (other_w->watchpoint_triggered
5272  {
5273  other_write_watchpoint = 1;
5274  break;
5275  }
5276  }
5277  }
5278 
5279  if (other_write_watchpoint
5280  || bl->watchpoint_type == hw_access)
5281  {
5282  /* We're watching the same memory for writes,
5283  and the value changed since the last time we
5284  updated it, so this trap must be for a write.
5285  Ignore it. */
5286  bs->print_it = print_it_noop;
5287  bs->stop = 0;
5288  }
5289  }
5290  break;
5291  case WP_VALUE_NOT_CHANGED:
5292  if (b->base.type == bp_hardware_watchpoint
5293  || b->base.type == bp_watchpoint)
5294  {
5295  /* Don't stop: write watchpoints shouldn't fire if
5296  the value hasn't changed. */
5297  bs->print_it = print_it_noop;
5298  bs->stop = 0;
5299  }
5300  /* Stop. */
5301  break;
5302  default:
5303  /* Can't happen. */
5304  case 0:
5305  /* Error from catch_errors. */
5306  printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5308  /* We've already printed what needs to be printed. */
5309  bs->print_it = print_it_done;
5310  break;
5311  }
5312  }
5313  else /* must_check_value == 0 */
5314  {
5315  /* This is a case where some watchpoint(s) triggered, but
5316  not at the address of this watchpoint, or else no
5317  watchpoint triggered after all. So don't print
5318  anything for this watchpoint. */
5319  bs->print_it = print_it_noop;
5320  bs->stop = 0;
5321  }
5322  }
5323 }
5324 
5325 /* For breakpoints that are currently marked as telling gdb to stop,
5326  check conditions (condition proper, frame, thread and ignore count)
5327  of breakpoint referred to by BS. If we should not stop for this
5328  breakpoint, set BS->stop to 0. */
5329 
5330 static void
5332 {
5333  const struct bp_location *bl;
5334  struct breakpoint *b;
5335  int value_is_zero = 0;
5336  struct expression *cond;
5337 
5338  gdb_assert (bs->stop);
5339 
5340  /* BS is built for existing struct breakpoint. */
5341  bl = bs->bp_location_at;
5342  gdb_assert (bl != NULL);
5343  b = bs->breakpoint_at;
5344  gdb_assert (b != NULL);
5345 
5346  /* Even if the target evaluated the condition on its end and notified GDB, we
5347  need to do so again since GDB does not know if we stopped due to a
5348  breakpoint or a single step breakpoint. */
5349 
5350  if (frame_id_p (b->frame_id)
5352  {
5353  bs->stop = 0;
5354  return;
5355  }
5356 
5357  /* If this is a thread/task-specific breakpoint, don't waste cpu
5358  evaluating the condition if this isn't the specified
5359  thread/task. */
5360  if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid))
5361  || (b->task != 0 && b->task != ada_get_task_number (ptid)))
5362 
5363  {
5364  bs->stop = 0;
5365  return;
5366  }
5367 
5368  /* Evaluate extension language breakpoints that have a "stop" method
5369  implemented. */
5371 
5372  if (is_watchpoint (b))
5373  {
5374  struct watchpoint *w = (struct watchpoint *) b;
5375 
5376  cond = w->cond_exp;
5377  }
5378  else
5379  cond = bl->cond;
5380 
5381  if (cond && b->disposition != disp_del_at_next_stop)
5382  {
5383  int within_current_scope = 1;
5384  struct watchpoint * w;
5385 
5386  /* We use value_mark and value_free_to_mark because it could
5387  be a long time before we return to the command level and
5388  call free_all_values. We can't call free_all_values
5389  because we might be in the middle of evaluating a
5390  function call. */
5391  struct value *mark = value_mark ();
5392 
5393  if (is_watchpoint (b))
5394  w = (struct watchpoint *) b;
5395  else
5396  w = NULL;
5397 
5398  /* Need to select the frame, with all that implies so that
5399  the conditions will have the right context. Because we
5400  use the frame, we will not see an inlined function's
5401  variables when we arrive at a breakpoint at the start
5402  of the inlined function; the current frame will be the
5403  call site. */
5404  if (w == NULL || w->cond_exp_valid_block == NULL)
5406  else
5407  {
5408  struct frame_info *frame;
5409 
5410  /* For local watchpoint expressions, which particular
5411  instance of a local is being watched matters, so we
5412  keep track of the frame to evaluate the expression
5413  in. To evaluate the condition however, it doesn't
5414  really matter which instantiation of the function
5415  where the condition makes sense triggers the
5416  watchpoint. This allows an expression like "watch
5417  global if q > 10" set in `func', catch writes to
5418  global on all threads that call `func', or catch
5419  writes on all recursive calls of `func' by a single
5420  thread. We simply always evaluate the condition in
5421  the innermost frame that's executing where it makes
5422  sense to evaluate the condition. It seems
5423  intuitive. */
5425  if (frame != NULL)
5426  select_frame (frame);
5427  else
5428  within_current_scope = 0;
5429  }
5430  if (within_current_scope)
5431  value_is_zero
5433  "Error in testing breakpoint condition:\n",
5434  RETURN_MASK_ALL);
5435  else
5436  {
5437  warning (_("Watchpoint condition cannot be tested "
5438  "in the current scope"));
5439  /* If we failed to set the right context for this
5440  watchpoint, unconditionally report it. */
5441  value_is_zero = 0;
5442  }
5443  /* FIXME-someday, should give breakpoint #. */
5444  value_free_to_mark (mark);
5445  }
5446 
5447  if (cond && value_is_zero)
5448  {
5449  bs->stop = 0;
5450  }
5451  else if (b->ignore_count > 0)
5452  {
5453  b->ignore_count--;
5454  bs->stop = 0;
5455  /* Increase the hit count even though we don't stop. */
5456  ++(b->hit_count);
5458  }
5459 }
5460 
5461 /* Returns true if we need to track moribund locations of LOC's type
5462  on the current target. */
5463 
5464 static int
5465 need_moribund_for_location_type (struct bp_location *loc)
5466 {
5467  return ((loc->loc_type == bp_loc_software_breakpoint
5471 }
5472 
5473 
5474 /* Get a bpstat associated with having just stopped at address
5475  BP_ADDR in thread PTID.
5476 
5477  Determine whether we stopped at a breakpoint, etc, or whether we
5478  don't understand this stop. Result is a chain of bpstat's such
5479  that:
5480 
5481  if we don't understand the stop, the result is a null pointer.
5482 
5483  if we understand why we stopped, the result is not null.
5484 
5485  Each element of the chain refers to a particular breakpoint or
5486  watchpoint at which we have stopped. (We may have stopped for
5487  several reasons concurrently.)
5488 
5489  Each element of the chain has valid next, breakpoint_at,
5490  commands, FIXME??? fields. */
5491 
5492 bpstat
5494  CORE_ADDR bp_addr, ptid_t ptid,
5495  const struct target_waitstatus *ws)
5496 {
5497  struct breakpoint *b = NULL;
5498  struct bp_location *bl;
5499  struct bp_location *loc;
5500  /* First item of allocated bpstat's. */
5501  bpstat bs_head = NULL, *bs_link = &bs_head;
5502  /* Pointer to the last thing in the chain currently. */
5503  bpstat bs;
5504  int ix;
5505  int need_remove_insert;
5506  int removed_any;
5507 
5508  /* First, build the bpstat chain with locations that explain a
5509  target stop, while being careful to not set the target running,
5510  as that may invalidate locations (in particular watchpoint
5511  locations are recreated). Resuming will happen here with
5512  breakpoint conditions or watchpoint expressions that include
5513  inferior function calls. */
5514 
5515  ALL_BREAKPOINTS (b)
5516  {
5517  if (!breakpoint_enabled (b))
5518  continue;
5519 
5520  for (bl = b->loc; bl != NULL; bl = bl->next)
5521  {
5522  /* For hardware watchpoints, we look only at the first
5523  location. The watchpoint_check function will work on the
5524  entire expression, not the individual locations. For
5525  read watchpoints, the watchpoints_triggered function has
5526  checked all locations already. */
5527  if (b->type == bp_hardware_watchpoint && bl != b->loc)
5528  break;
5529 
5530  if (!bl->enabled || bl->shlib_disabled)
5531  continue;
5532 
5533  if (!bpstat_check_location (bl, aspace, bp_addr, ws))
5534  continue;
5535 
5536  /* Come here if it's a watchpoint, or if the break address
5537  matches. */
5538 
5539  bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
5540  explain stop. */
5541 
5542  /* Assume we stop. Should we find a watchpoint that is not
5543  actually triggered, or if the condition of the breakpoint
5544  evaluates as false, we'll reset 'stop' to 0. */
5545  bs->stop = 1;
5546  bs->print = 1;
5547 
5548  /* If this is a scope breakpoint, mark the associated
5549  watchpoint as triggered so that we will handle the
5550  out-of-scope event. We'll get to the watchpoint next
5551  iteration. */
5552  if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5553  {
5554  struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5555 
5557  }
5558  }
5559  }
5560 
5561  /* Check if a moribund breakpoint explains the stop. */
5564  {
5565  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5566  {
5567  if (breakpoint_location_address_match (loc, aspace, bp_addr)
5569  {
5570  bs = bpstat_alloc (loc, &bs_link);
5571  /* For hits of moribund locations, we should just proceed. */
5572  bs->stop = 0;
5573  bs->print = 0;
5574  bs->print_it = print_it_noop;
5575  }
5576  }
5577  }
5578 
5579  /* A bit of special processing for shlib breakpoints. We need to
5580  process solib loading here, so that the lists of loaded and
5581  unloaded libraries are correct before we handle "catch load" and
5582  "catch unload". */
5583  for (bs = bs_head; bs != NULL; bs = bs->next)
5584  {
5585  if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5586  {
5587  handle_solib_event ();
5588  break;
5589  }
5590  }
5591 
5592  /* Now go through the locations that caused the target to stop, and
5593  check whether we're interested in reporting this stop to higher
5594  layers, or whether we should resume the target transparently. */
5595 
5596  removed_any = 0;
5597 
5598  for (bs = bs_head; bs != NULL; bs = bs->next)
5599  {
5600  if (!bs->stop)
5601  continue;
5602 
5603  b = bs->breakpoint_at;
5604  b->ops->check_status (bs);
5605  if (bs->stop)
5606  {
5608 
5609  if (bs->stop)
5610  {
5611  ++(b->hit_count);
5613 
5614  /* We will stop here. */
5615  if (b->disposition == disp_disable)
5616  {
5617  --(b->enable_count);
5618  if (b->enable_count <= 0)
5620  removed_any = 1;
5621  }
5622  if (b->silent)
5623  bs->print = 0;
5624  bs->commands = b->commands;
5627  ? bs->commands->commands : NULL))
5628  bs->print = 0;
5629 
5630  b->ops->after_condition_true (bs);
5631  }
5632 
5633  }
5634 
5635  /* Print nothing for this entry if we don't stop or don't
5636  print. */
5637  if (!bs->stop || !bs->print)
5638  bs->print_it = print_it_noop;
5639  }
5640 
5641  /* If we aren't stopping, the value of some hardware watchpoint may
5642  not have changed, but the intermediate memory locations we are
5643  watching may have. Don't bother if we're stopping; this will get
5644  done later. */
5645  need_remove_insert = 0;
5646  if (! bpstat_causes_stop (bs_head))
5647  for (bs = bs_head; bs != NULL; bs = bs->next)
5648  if (!bs->stop
5649  && bs->breakpoint_at
5651  {
5652  struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5653 
5654  update_watchpoint (w, 0 /* don't reparse. */);
5655  need_remove_insert = 1;
5656  }
5657 
5658  if (need_remove_insert)
5660  else if (removed_any)
5662 
5663  return bs_head;
5664 }
5665 
5666 static void
5668 {
5669  struct frame_info *frame;
5670  struct gdbarch *gdbarch;
5671 
5672  /* Switch terminal for any messages produced by
5673  breakpoint_re_set. */
5675 
5676  frame = get_current_frame ();
5677  gdbarch = get_frame_arch (frame);
5678 
5679  jit_event_handler (gdbarch);
5680 
5682 }
5683 
5684 /* Prepare WHAT final decision for infrun. */
5685 
5686 /* Decide what infrun needs to do with this bpstat. */
5687 
5688 struct bpstat_what
5690 {
5691  struct bpstat_what retval;
5692  int jit_event = 0;
5693  bpstat bs;
5694 
5696  retval.call_dummy = STOP_NONE;
5697  retval.is_longjmp = 0;
5698 
5699  for (bs = bs_head; bs != NULL; bs = bs->next)
5700  {
5701  /* Extract this BS's action. After processing each BS, we check
5702  if its action overrides all we've seem so far. */
5704  enum bptype bptype;
5705 
5706  if (bs->breakpoint_at == NULL)
5707  {
5708  /* I suspect this can happen if it was a momentary
5709  breakpoint which has since been deleted. */
5710  bptype = bp_none;
5711  }
5712  else
5713  bptype = bs->breakpoint_at->type;
5714 
5715  switch (bptype)
5716  {
5717  case bp_none:
5718  break;
5719  case bp_breakpoint:
5721  case bp_single_step:
5722  case bp_until:
5723  case bp_finish:
5724  case bp_shlib_event:
5725  if (bs->stop)
5726  {
5727  if (bs->print)
5728  this_action = BPSTAT_WHAT_STOP_NOISY;
5729  else
5730  this_action = BPSTAT_WHAT_STOP_SILENT;
5731  }
5732  else
5733  this_action = BPSTAT_WHAT_SINGLE;
5734  break;
5735  case bp_watchpoint:
5737  case bp_read_watchpoint:
5738  case bp_access_watchpoint:
5739  if (bs->stop)
5740  {
5741  if (bs->print)
5742  this_action = BPSTAT_WHAT_STOP_NOISY;
5743  else
5744  this_action = BPSTAT_WHAT_STOP_SILENT;
5745  }
5746  else
5747  {
5748  /* There was a watchpoint, but we're not stopping.
5749  This requires no further action. */
5750  }
5751  break;
5752  case bp_longjmp:
5753  case bp_longjmp_call_dummy:
5754  case bp_exception:
5755  if (bs->stop)
5756  {
5757  this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5758  retval.is_longjmp = bptype != bp_exception;
5759  }
5760  else
5761  this_action = BPSTAT_WHAT_SINGLE;
5762  break;
5763  case bp_longjmp_resume:
5764  case bp_exception_resume:
5765  if (bs->stop)
5766  {
5767  this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5768  retval.is_longjmp = bptype == bp_longjmp_resume;
5769  }
5770  else
5771  this_action = BPSTAT_WHAT_SINGLE;
5772  break;
5773  case bp_step_resume:
5774  if (bs->stop)
5775  this_action = BPSTAT_WHAT_STEP_RESUME;
5776  else
5777  {
5778  /* It is for the wrong frame. */
5779  this_action = BPSTAT_WHAT_SINGLE;
5780  }
5781  break;
5782  case bp_hp_step_resume:
5783  if (bs->stop)
5784  this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5785  else
5786  {
5787  /* It is for the wrong frame. */
5788  this_action = BPSTAT_WHAT_SINGLE;
5789  }
5790  break;
5791  case bp_watchpoint_scope:
5792  case bp_thread_event:
5793  case bp_overlay_event:
5794  case bp_longjmp_master:
5796  case bp_exception_master:
5797  this_action = BPSTAT_WHAT_SINGLE;
5798  break;
5799  case bp_catchpoint:
5800  if (bs->stop)
5801  {
5802  if (bs->print)
5803  this_action = BPSTAT_WHAT_STOP_NOISY;
5804  else
5805  this_action = BPSTAT_WHAT_STOP_SILENT;
5806  }
5807  else
5808  {
5809  /* There was a catchpoint, but we're not stopping.
5810  This requires no further action. */
5811  }
5812  break;
5813  case bp_jit_event:
5814  jit_event = 1;
5815  this_action = BPSTAT_WHAT_SINGLE;
5816  break;
5817  case bp_call_dummy:
5818  /* Make sure the action is stop (silent or noisy),
5819  so infrun.c pops the dummy frame. */
5820  retval.call_dummy = STOP_STACK_DUMMY;
5821  this_action = BPSTAT_WHAT_STOP_SILENT;
5822  break;
5823  case bp_std_terminate:
5824  /* Make sure the action is stop (silent or noisy),
5825  so infrun.c pops the dummy frame. */
5826  retval.call_dummy = STOP_STD_TERMINATE;
5827  this_action = BPSTAT_WHAT_STOP_SILENT;
5828  break;
5829  case bp_tracepoint:
5830  case bp_fast_tracepoint:
5831  case bp_static_tracepoint:
5832  /* Tracepoint hits should not be reported back to GDB, and
5833  if one got through somehow, it should have been filtered
5834  out already. */
5835  internal_error (__FILE__, __LINE__,
5836  _("bpstat_what: tracepoint encountered"));
5837  break;
5838  case bp_gnu_ifunc_resolver:
5839  /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5840  this_action = BPSTAT_WHAT_SINGLE;
5841  break;
5843  /* The breakpoint will be removed, execution will restart from the
5844  PC of the former breakpoint. */
5845  this_action = BPSTAT_WHAT_KEEP_CHECKING;
5846  break;
5847 
5848  case bp_dprintf:
5849  if (bs->stop)
5850  this_action = BPSTAT_WHAT_STOP_SILENT;
5851  else
5852  this_action = BPSTAT_WHAT_SINGLE;
5853  break;
5854 
5855  default:
5856  internal_error (__FILE__, __LINE__,
5857  _("bpstat_what: unhandled bptype %d"), (int) bptype);
5858  }
5859 
5860  retval.main_action = max (retval.main_action, this_action);
5861  }
5862 
5863  /* These operations may affect the bs->breakpoint_at state so they are
5864  delayed after MAIN_ACTION is decided above. */
5865 
5866  if (jit_event)
5867  {
5868  if (debug_infrun)
5869  fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5870 
5871  handle_jit_event ();
5872  }
5873 
5874  for (bs = bs_head; bs != NULL; bs = bs->next)
5875  {
5876  struct breakpoint *b = bs->breakpoint_at;
5877 
5878  if (b == NULL)
5879  continue;
5880  switch (b->type)
5881  {
5882  case bp_gnu_ifunc_resolver:
5884  break;
5887  break;
5888  }
5889  }
5890 
5891  return retval;
5892 }
5893 
5894 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5895  without hardware support). This isn't related to a specific bpstat,
5896  just to things like whether watchpoints are set. */
5897 
5898 int
5900 {
5901  struct breakpoint *b;
5902 
5903  ALL_BREAKPOINTS (b)
5904  if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
5905  return 1;
5906  return 0;
5907 }
5908 
5909 int
5911 {
5912  for (; bs != NULL; bs = bs->next)
5913  if (bs->stop)
5914  return 1;
5915 
5916  return 0;
5917 }
5918 
5919 
5920 
5921 /* Compute a string of spaces suitable to indent the next line
5922  so it starts at the position corresponding to the table column
5923  named COL_NAME in the currently active table of UIOUT. */
5924 
5925 static char *
5926 wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5927 {
5928  static char wrap_indent[80];
5929  int i, total_width, width, align;
5930  char *text;
5931 
5932  total_width = 0;
5933  for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5934  {
5935  if (strcmp (text, col_name) == 0)
5936  {
5937  gdb_assert (total_width < sizeof wrap_indent);
5938  memset (wrap_indent, ' ', total_width);
5939  wrap_indent[total_width] = 0;
5940 
5941  return wrap_indent;
5942  }
5943 
5944  total_width += width + 1;
5945  }
5946 
5947  return NULL;
5948 }
5949 
5950 /* Determine if the locations of this breakpoint will have their conditions
5951  evaluated by the target, host or a mix of both. Returns the following:
5952 
5953  "host": Host evals condition.
5954  "host or target": Host or Target evals condition.
5955  "target": Target evals condition.
5956 */
5957 
5958 static const char *
5960 {
5961  struct bp_location *bl;
5962  char host_evals = 0;
5963  char target_evals = 0;
5964 
5965  if (!b)
5966  return NULL;
5967 
5968  if (!is_breakpoint (b))
5969  return NULL;
5970 
5974 
5975  for (bl = b->loc; bl; bl = bl->next)
5976  {
5977  if (bl->cond_bytecode)
5978  target_evals++;
5979  else
5980  host_evals++;
5981  }
5982 
5983  if (host_evals && target_evals)
5985  else if (target_evals)
5987  else
5989 }
5990 
5991 /* Determine the breakpoint location's condition evaluator. This is
5992  similar to bp_condition_evaluator, but for locations. */
5993 
5994 static const char *
5995 bp_location_condition_evaluator (struct bp_location *bl)
5996 {
5997  if (bl && !is_breakpoint (bl->owner))
5998  return NULL;
5999 
6003 
6004  if (bl && bl->cond_bytecode)
6006  else
6008 }
6009 
6010 /* Print the LOC location out of the list of B->LOC locations. */
6011 
6012 static void
6014  struct bp_location *loc)
6015 {
6016  struct ui_out *uiout = current_uiout;
6017  struct cleanup *old_chain = save_current_program_space ();
6018 
6019  if (loc != NULL && loc->shlib_disabled)
6020  loc = NULL;
6021 
6022  if (loc != NULL)
6024 
6025  if (b->display_canonical)
6026  ui_out_field_string (uiout, "what", b->addr_string);
6027  else if (loc && loc->symtab)
6028  {
6029  struct symbol *sym
6030  = find_pc_sect_function (loc->address, loc->section);
6031  if (sym)
6032  {
6033  ui_out_text (uiout, "in ");
6034  ui_out_field_string (uiout, "func",
6035  SYMBOL_PRINT_NAME (sym));
6036  ui_out_text (uiout, " ");
6037  ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
6038  ui_out_text (uiout, "at ");
6039  }
6040  ui_out_field_string (uiout, "file",
6042  ui_out_text (uiout, ":");
6043 
6044  if (ui_out_is_mi_like_p (uiout))
6045  ui_out_field_string (uiout, "fullname",
6046  symtab_to_fullname (loc->symtab));
6047 
6048  ui_out_field_int (uiout, "line", loc->line_number);
6049  }
6050  else if (loc)
6051  {
6052  struct ui_file *stb = mem_fileopen ();
6053  struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
6054 
6055  print_address_symbolic (loc->gdbarch, loc->address, stb,
6056  demangle, "");
6057  ui_out_field_stream (uiout, "at", stb);
6058 
6059  do_cleanups (stb_chain);
6060  }
6061  else
6062  ui_out_field_string (uiout, "pending", b->addr_string);
6063 
6064  if (loc && is_breakpoint (b)
6065  && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6066  && bp_condition_evaluator (b) == condition_evaluation_both)
6067  {
6068  ui_out_text (uiout, " (");
6069  ui_out_field_string (uiout, "evaluated-by",
6071  ui_out_text (uiout, ")");
6072  }
6073 
6074  do_cleanups (old_chain);
6075 }
6076 
6077 static const char *
6079 {
6080  struct ep_type_description
6081  {
6082  enum bptype type;
6083  char *description;
6084  };
6085  static struct ep_type_description bptypes[] =
6086  {
6087  {bp_none, "?deleted?"},
6088  {bp_breakpoint, "breakpoint"},
6089  {bp_hardware_breakpoint, "hw breakpoint"},
6090  {bp_single_step, "sw single-step"},
6091  {bp_until, "until"},
6092  {bp_finish, "finish"},
6093  {bp_watchpoint, "watchpoint"},
6094  {bp_hardware_watchpoint, "hw watchpoint"},
6095  {bp_read_watchpoint, "read watchpoint"},
6096  {bp_access_watchpoint, "acc watchpoint"},
6097  {bp_longjmp, "longjmp"},
6098  {bp_longjmp_resume, "longjmp resume"},
6099  {bp_longjmp_call_dummy, "longjmp for call dummy"},
6100  {bp_exception, "exception"},
6101  {bp_exception_resume, "exception resume"},
6102  {bp_step_resume, "step resume"},
6103  {bp_hp_step_resume, "high-priority step resume"},
6104  {bp_watchpoint_scope, "watchpoint scope"},
6105  {bp_call_dummy, "call dummy"},
6106  {bp_std_terminate, "std::terminate"},
6107  {bp_shlib_event, "shlib events"},
6108  {bp_thread_event, "thread events"},
6109  {bp_overlay_event, "overlay events"},
6110  {bp_longjmp_master, "longjmp master"},
6111  {bp_std_terminate_master, "std::terminate master"},
6112  {bp_exception_master, "exception master"},
6113  {bp_catchpoint, "catchpoint"},
6114  {bp_tracepoint, "tracepoint"},
6115  {bp_fast_tracepoint, "fast tracepoint"},
6116  {bp_static_tracepoint, "static tracepoint"},
6117  {bp_dprintf, "dprintf"},
6118  {bp_jit_event, "jit events"},
6119  {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
6120  {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
6121  };
6122 
6123  if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
6124  || ((int) type != bptypes[(int) type].type))
6125  internal_error (__FILE__, __LINE__,
6126  _("bptypes table does not describe type #%d."),
6127  (int) type);
6128 
6129  return bptypes[(int) type].description;
6130 }
6131 
6132 /* For MI, output a field named 'thread-groups' with a list as the value.
6133  For CLI, prefix the list with the string 'inf'. */
6134 
6135 static void
6137  const char *field_name,
6138  VEC(int) *inf_num,
6139  int mi_only)
6140 {
6141  struct cleanup *back_to;
6142  int is_mi = ui_out_is_mi_like_p (uiout);
6143  int inf;
6144  int i;
6145 
6146  /* For backward compatibility, don't display inferiors in CLI unless
6147  there are several. Always display them for MI. */
6148  if (!is_mi && mi_only)
6149  return;
6150 
6151  back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name);
6152 
6153  for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
6154  {
6155  if (is_mi)
6156  {
6157  char mi_group[10];
6158 
6159  xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
6160  ui_out_field_string (uiout, NULL, mi_group);
6161  }
6162  else
6163  {
6164  if (i == 0)
6165  ui_out_text (uiout, " inf ");
6166  else
6167  ui_out_text (uiout, ", ");
6168 
6169  ui_out_text (uiout, plongest (inf));
6170  }
6171  }
6172 
6173  do_cleanups (back_to);
6174 }
6175 
6176 /* Print B to gdb_stdout. */
6177 
6178 static void
6180  struct bp_location *loc,
6181  int loc_number,
6182  struct bp_location **last_loc,
6183  int allflag)
6184 {
6185  struct command_line *l;
6186  static char bpenables[] = "nynny";
6187 
6188  struct ui_out *uiout = current_uiout;
6189  int header_of_multiple = 0;
6190  int part_of_multiple = (loc != NULL);
6191  struct value_print_options opts;
6192 
6193  get_user_print_options (&opts);
6194 
6195  gdb_assert (!loc || loc_number != 0);
6196  /* See comment in print_one_breakpoint concerning treatment of
6197  breakpoints with single disabled location. */
6198  if (loc == NULL
6199  && (b->loc != NULL
6200  && (b->loc->next != NULL || !b->loc->enabled)))
6201  header_of_multiple = 1;
6202  if (loc == NULL)
6203  loc = b->loc;
6204 
6205  annotate_record ();
6206 
6207  /* 1 */
6208  annotate_field (0);
6209  if (part_of_multiple)
6210  {
6211  char *formatted;
6212  formatted = xstrprintf ("%d.%d", b->number, loc_number);
6213  ui_out_field_string (uiout, "number", formatted);
6214  xfree (formatted);
6215  }
6216  else
6217  {
6218  ui_out_field_int (uiout, "number", b->number);
6219  }
6220 
6221  /* 2 */
6222  annotate_field (1);
6223  if (part_of_multiple)
6224  ui_out_field_skip (uiout, "type");
6225  else
6226  ui_out_field_string (uiout, "type", bptype_string (b->type));
6227 
6228  /* 3 */
6229  annotate_field (2);
6230  if (part_of_multiple)
6231  ui_out_field_skip (uiout, "disp");
6232  else
6233  ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6234 
6235 
6236  /* 4 */
6237  annotate_field (3);
6238  if (part_of_multiple)
6239  ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
6240  else
6241  ui_out_field_fmt (uiout, "enabled", "%c",
6242  bpenables[(int) b->enable_state]);
6243  ui_out_spaces (uiout, 2);
6244 
6245 
6246  /* 5 and 6 */
6247  if (b->ops != NULL && b->ops->print_one != NULL)
6248  {
6249  /* Although the print_one can possibly print all locations,
6250  calling it here is not likely to get any nice result. So,
6251  make sure there's just one location. */
6252  gdb_assert (b->loc == NULL || b->loc->next == NULL);
6253  b->ops->print_one (b, last_loc);
6254  }
6255  else
6256  switch (b->type)
6257  {
6258  case bp_none:
6259  internal_error (__FILE__, __LINE__,
6260  _("print_one_breakpoint: bp_none encountered\n"));
6261  break;
6262 
6263  case bp_watchpoint:
6265  case bp_read_watchpoint:
6266  case bp_access_watchpoint:
6267  {
6268  struct watchpoint *w = (struct watchpoint *) b;
6269 
6270  /* Field 4, the address, is omitted (which makes the columns
6271  not line up too nicely with the headers, but the effect
6272  is relatively readable). */
6273  if (opts.addressprint)
6274  ui_out_field_skip (uiout, "addr");
6275  annotate_field (5);
6276  ui_out_field_string (uiout, "what", w->exp_string);
6277  }
6278  break;
6279 
6280  case bp_breakpoint:
6282  case bp_single_step:
6283  case bp_until:
6284  case bp_finish:
6285  case bp_longjmp:
6286  case bp_longjmp_resume:
6287  case bp_longjmp_call_dummy:
6288  case bp_exception:
6289  case bp_exception_resume:
6290  case bp_step_resume:
6291  case bp_hp_step_resume:
6292  case bp_watchpoint_scope:
6293  case bp_call_dummy:
6294  case bp_std_terminate:
6295  case bp_shlib_event:
6296  case bp_thread_event:
6297  case bp_overlay_event:
6298  case bp_longjmp_master:
6300  case bp_exception_master:
6301  case bp_tracepoint:
6302  case bp_fast_tracepoint:
6303  case bp_static_tracepoint:
6304  case bp_dprintf:
6305  case bp_jit_event:
6306  case bp_gnu_ifunc_resolver:
6308  if (opts.addressprint)
6309  {
6310  annotate_field (4);
6311  if (header_of_multiple)
6312  ui_out_field_string (uiout, "addr", "<MULTIPLE>");
6313  else if (b->loc == NULL || loc->shlib_disabled)
6314  ui_out_field_string (uiout, "addr", "<PENDING>");
6315  else
6316  ui_out_field_core_addr (uiout, "addr",
6317  loc->gdbarch, loc->address);
6318  }
6319  annotate_field (5);
6320  if (!header_of_multiple)
6321  print_breakpoint_location (b, loc);
6322  if (b->loc)
6323  *last_loc = b->loc;
6324  break;
6325  }
6326 
6327 
6328  if (loc != NULL && !header_of_multiple)
6329  {
6330  struct inferior *inf;
6331  VEC(int) *inf_num = NULL;
6332  int mi_only = 1;
6333 
6334  ALL_INFERIORS (inf)
6335  {
6336  if (inf->pspace == loc->pspace)
6337  VEC_safe_push (int, inf_num, inf->num);
6338  }
6339 
6340  /* For backward compatibility, don't display inferiors in CLI unless
6341  there are several. Always display for MI. */
6342  if (allflag
6344  && (number_of_program_spaces () > 1
6345  || number_of_inferiors () > 1)
6346  /* LOC is for existing B, it cannot be in
6347  moribund_locations and thus having NULL OWNER. */
6348  && loc->owner->type != bp_catchpoint))
6349  mi_only = 0;
6350  output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6351  VEC_free (int, inf_num);
6352  }
6353 
6354  if (!part_of_multiple)
6355  {
6356  if (b->thread != -1)
6357  {
6358  /* FIXME: This seems to be redundant and lost here; see the
6359  "stop only in" line a little further down. */
6360  ui_out_text (uiout, " thread ");
6361  ui_out_field_int (uiout, "thread", b->thread);
6362  }
6363  else if (b->task != 0)
6364  {
6365  ui_out_text (uiout, " task ");
6366  ui_out_field_int (uiout, "task", b->task);
6367  }
6368  }
6369 
6370  ui_out_text (uiout, "\n");
6371 
6372  if (!part_of_multiple)
6373  b->ops->print_one_detail (b, uiout);
6374 
6375  if (part_of_multiple && frame_id_p (b->frame_id))
6376  {
6377  annotate_field (6);
6378  ui_out_text (uiout, "\tstop only in stack frame at ");
6379  /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6380  the frame ID. */
6381  ui_out_field_core_addr (uiout, "frame",
6382  b->gdbarch, b->frame_id.stack_addr);
6383  ui_out_text (uiout, "\n");
6384  }
6385 
6386  if (!part_of_multiple && b->cond_string)
6387  {
6388  annotate_field (7);
6389  if (is_tracepoint (b))
6390  ui_out_text (uiout, "\ttrace only if ");
6391  else
6392  ui_out_text (uiout, "\tstop only if ");
6393  ui_out_field_string (uiout, "cond", b->cond_string);
6394 
6395  /* Print whether the target is doing the breakpoint's condition
6396  evaluation. If GDB is doing the evaluation, don't print anything. */
6397  if (is_breakpoint (b)
6399  == condition_evaluation_target)
6400  {
6401  ui_out_text (uiout, " (");
6402  ui_out_field_string (uiout, "evaluated-by",
6404  ui_out_text (uiout, " evals)");
6405  }
6406  ui_out_text (uiout, "\n");
6407  }
6408 
6409  if (!part_of_multiple && b->thread != -1)
6410  {
6411  /* FIXME should make an annotation for this. */
6412  ui_out_text (uiout, "\tstop only in thread ");
6413  ui_out_field_int (uiout, "thread", b->thread);
6414  ui_out_text (uiout, "\n");
6415  }
6416 
6417  if (!part_of_multiple)
6418  {
6419  if (b->hit_count)
6420  {
6421  /* FIXME should make an annotation for this. */
6422  if (is_catchpoint (b))
6423  ui_out_text (uiout, "\tcatchpoint");
6424  else if (is_tracepoint (b))
6425  ui_out_text (uiout, "\ttracepoint");
6426  else
6427  ui_out_text (uiout, "\tbreakpoint");
6428  ui_out_text (uiout, " already hit ");
6429  ui_out_field_int (uiout, "times", b->hit_count);
6430  if (b->hit_count == 1)
6431  ui_out_text (uiout, " time\n");
6432  else
6433  ui_out_text (uiout, " times\n");
6434  }
6435  else
6436  {
6437  /* Output the count also if it is zero, but only if this is mi. */
6438  if (ui_out_is_mi_like_p (uiout))
6439  ui_out_field_int (uiout, "times", b->hit_count);
6440  }
6441  }
6442 
6443  if (!part_of_multiple && b->ignore_count)
6444  {
6445  annotate_field (8);
6446  ui_out_text (uiout, "\tignore next ");
6447  ui_out_field_int (uiout, "ignore", b->ignore_count);
6448  ui_out_text (uiout, " hits\n");
6449  }
6450 
6451  /* Note that an enable count of 1 corresponds to "enable once"
6452  behavior, which is reported by the combination of enablement and
6453  disposition, so we don't need to mention it here. */
6454  if (!part_of_multiple && b->enable_count > 1)
6455  {
6456  annotate_field (8);
6457  ui_out_text (uiout, "\tdisable after ");
6458  /* Tweak the wording to clarify that ignore and enable counts
6459  are distinct, and have additive effect. */
6460  if (b->ignore_count)
6461  ui_out_text (uiout, "additional ");
6462  else
6463  ui_out_text (uiout, "next ");
6464  ui_out_field_int (uiout, "enable", b->enable_count);
6465  ui_out_text (uiout, " hits\n");
6466  }
6467 
6468  if (!part_of_multiple && is_tracepoint (b))
6469  {
6470  struct tracepoint *tp = (struct tracepoint *) b;
6471 
6472  if (tp->traceframe_usage)
6473  {
6474  ui_out_text (uiout, "\ttrace buffer usage ");
6475  ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6476  ui_out_text (uiout, " bytes\n");
6477  }
6478  }
6479 
6480  l = b->commands ? b->commands->commands : NULL;
6481  if (!part_of_multiple && l)
6482  {
6483  struct cleanup *script_chain;
6484 
6485  annotate_field (9);
6486  script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
6487  print_command_lines (uiout, l, 4);
6488  do_cleanups (script_chain);
6489  }
6490 
6491  if (is_tracepoint (b))
6492  {
6493  struct tracepoint *t = (struct tracepoint *) b;
6494 
6495  if (!part_of_multiple && t->pass_count)
6496  {
6497  annotate_field (10);
6498  ui_out_text (uiout, "\tpass count ");
6499  ui_out_field_int (uiout, "pass", t->pass_count);
6500  ui_out_text (uiout, " \n");
6501  }
6502 
6503  /* Don't display it when tracepoint or tracepoint location is
6504  pending. */
6505  if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6506  {
6507  annotate_field (11);
6508 
6509  if (ui_out_is_mi_like_p (uiout))
6510  ui_out_field_string (uiout, "installed",
6511  loc->inserted ? "y" : "n");
6512  else
6513  {
6514  if (loc->inserted)
6515  ui_out_text (uiout, "\t");
6516  else
6517  ui_out_text (uiout, "\tnot ");
6518  ui_out_text (uiout, "installed on target\n");
6519  }
6520  }
6521  }
6522 
6523  if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
6524  {
6525  if (is_watchpoint (b))
6526  {
6527  struct watchpoint *w = (struct watchpoint *) b;
6528 
6529  ui_out_field_string (uiout, "original-location", w->exp_string);
6530  }
6531  else if (b->addr_string)
6532  ui_out_field_string (uiout, "original-location", b->addr_string);
6533  }
6534 }
6535 
6536 static void
6538  struct bp_location **last_loc,
6539  int allflag)
6540 {
6541  struct cleanup *bkpt_chain;
6542  struct ui_out *uiout = current_uiout;
6543 
6544  bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6545 
6546  print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6547  do_cleanups (bkpt_chain);
6548 
6549  /* If this breakpoint has custom print function,
6550  it's already printed. Otherwise, print individual
6551  locations, if any. */
6552  if (b->ops == NULL || b->ops->print_one == NULL)
6553  {
6554  /* If breakpoint has a single location that is disabled, we
6555  print it as if it had several locations, since otherwise it's
6556  hard to represent "breakpoint enabled, location disabled"
6557  situation.
6558 
6559  Note that while hardware watchpoints have several locations
6560  internally, that's not a property exposed to user. */
6561  if (b->loc
6562  && !is_hardware_watchpoint (b)
6563  && (b->loc->next || !b->loc->enabled))
6564  {
6565  struct bp_location *loc;
6566  int n = 1;
6567 
6568  for (loc = b->loc; loc; loc = loc->next, ++n)
6569  {
6570  struct cleanup *inner2 =
6572  print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6573  do_cleanups (inner2);
6574  }
6575  }
6576  }
6577 }
6578 
6579 static int
6581 {
6582  int print_address_bits = 0;
6583  struct bp_location *loc;
6584 
6585  for (loc = b->loc; loc; loc = loc->next)
6586  {
6587  int addr_bit;
6588 
6589  /* Software watchpoints that aren't watching memory don't have
6590  an address to print. */
6591  if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6592  continue;
6593 
6594  addr_bit = gdbarch_addr_bit (loc->gdbarch);
6595  if (addr_bit > print_address_bits)
6596  print_address_bits = addr_bit;
6597  }
6598 
6599  return print_address_bits;
6600 }
6601 
6603  {
6604  int bnum;
6605  };
6606 
6607 static int
6608 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
6609 {
6610  struct captured_breakpoint_query_args *args = data;
6611  struct breakpoint *b;
6612  struct bp_location *dummy_loc = NULL;
6613 
6614  ALL_BREAKPOINTS (b)
6615  {
6616  if (args->bnum == b->number)
6617  {
6618  print_one_breakpoint (b, &dummy_loc, 0);
6619  return GDB_RC_OK;
6620  }
6621  }
6622  return GDB_RC_NONE;
6623 }
6624 
6625 enum gdb_rc
6626 gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6627  char **error_message)
6628 {
6629  struct captured_breakpoint_query_args args;
6630 
6631  args.bnum = bnum;
6632  /* For the moment we don't trust print_one_breakpoint() to not throw
6633  an error. */
6635  error_message, RETURN_MASK_ALL) < 0)
6636  return GDB_RC_FAIL;
6637  else
6638  return GDB_RC_OK;
6639 }
6640 
6641 /* Return true if this breakpoint was set by the user, false if it is
6642  internal or momentary. */
6643 
6644 int
6646 {
6647  return b->number > 0;
6648 }
6649 
6650 /* Print information on user settable breakpoint (watchpoint, etc)
6651  number BNUM. If BNUM is -1 print all user-settable breakpoints.
6652  If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6653  FILTER is non-NULL, call it on each breakpoint and only include the
6654  ones for which it returns non-zero. Return the total number of
6655  breakpoints listed. */
6656 
6657 static int
6658 breakpoint_1 (char *args, int allflag,
6659  int (*filter) (const struct breakpoint *))
6660 {
6661  struct breakpoint *b;
6662  struct bp_location *last_loc = NULL;
6663  int nr_printable_breakpoints;
6664  struct cleanup *bkpttbl_chain;
6665  struct value_print_options opts;
6666  int print_address_bits = 0;
6667  int print_type_col_width = 14;
6668  struct ui_out *uiout = current_uiout;
6669 
6670  get_user_print_options (&opts);
6671 
6672  /* Compute the number of rows in the table, as well as the size
6673  required for address fields. */
6674  nr_printable_breakpoints = 0;
6675  ALL_BREAKPOINTS (b)
6676  {
6677  /* If we have a filter, only list the breakpoints it accepts. */
6678  if (filter && !filter (b))
6679  continue;
6680 
6681  /* If we have an "args" string, it is a list of breakpoints to
6682  accept. Skip the others. */
6683  if (args != NULL && *args != '\0')
6684  {
6685  if (allflag && parse_and_eval_long (args) != b->number)
6686  continue;
6687  if (!allflag && !number_is_in_list (args, b->number))
6688  continue;
6689  }
6690 
6691  if (allflag || user_breakpoint_p (b))
6692  {
6693  int addr_bit, type_len;
6694 
6695  addr_bit = breakpoint_address_bits (b);
6696  if (addr_bit > print_address_bits)
6697  print_address_bits = addr_bit;
6698 
6699  type_len = strlen (bptype_string (b->type));
6700  if (type_len > print_type_col_width)
6701  print_type_col_width = type_len;
6702 
6703  nr_printable_breakpoints++;
6704  }
6705  }
6706 
6707  if (opts.addressprint)
6708  bkpttbl_chain
6710  nr_printable_breakpoints,
6711  "BreakpointTable");
6712  else
6713  bkpttbl_chain
6715  nr_printable_breakpoints,
6716  "BreakpointTable");
6717 
6718  if (nr_printable_breakpoints > 0)
6720  if (nr_printable_breakpoints > 0)
6721  annotate_field (0);
6722  ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
6723  if (nr_printable_breakpoints > 0)
6724  annotate_field (1);
6725  ui_out_table_header (uiout, print_type_col_width, ui_left,
6726  "type", "Type"); /* 2 */
6727  if (nr_printable_breakpoints > 0)
6728  annotate_field (2);
6729  ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
6730  if (nr_printable_breakpoints > 0)
6731  annotate_field (3);
6732  ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
6733  if (opts.addressprint)
6734  {
6735  if (nr_printable_breakpoints > 0)
6736  annotate_field (4);
6737  if (print_address_bits <= 32)
6738  ui_out_table_header (uiout, 10, ui_left,
6739  "addr", "Address"); /* 5 */
6740  else
6741  ui_out_table_header (uiout, 18, ui_left,
6742  "addr", "Address"); /* 5 */
6743  }
6744  if (nr_printable_breakpoints > 0)
6745  annotate_field (5);
6746  ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6747  ui_out_table_body (uiout);
6748  if (nr_printable_breakpoints > 0)
6750 
6751  ALL_BREAKPOINTS (b)
6752  {
6753  QUIT;
6754  /* If we have a filter, only list the breakpoints it accepts. */
6755  if (filter && !filter (b))
6756  continue;
6757 
6758  /* If we have an "args" string, it is a list of breakpoints to
6759  accept. Skip the others. */
6760 
6761  if (args != NULL && *args != '\0')
6762  {
6763  if (allflag) /* maintenance info breakpoint */
6764  {
6765  if (parse_and_eval_long (args) != b->number)
6766  continue;
6767  }
6768  else /* all others */
6769  {
6770  if (!number_is_in_list (args, b->number))
6771  continue;
6772  }
6773  }
6774  /* We only print out user settable breakpoints unless the
6775  allflag is set. */
6776  if (allflag || user_breakpoint_p (b))
6777  print_one_breakpoint (b, &last_loc, allflag);
6778  }
6779 
6780  do_cleanups (bkpttbl_chain);
6781 
6782  if (nr_printable_breakpoints == 0)
6783  {
6784  /* If there's a filter, let the caller decide how to report
6785  empty list. */
6786  if (!filter)
6787  {
6788  if (args == NULL || *args == '\0')
6789  ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6790  else
6791  ui_out_message (uiout, 0,
6792  "No breakpoint or watchpoint matching '%s'.\n",
6793  args);
6794  }
6795  }
6796  else
6797  {
6798  if (last_loc && !server_command)
6799  set_next_address (last_loc->gdbarch, last_loc->address);
6800  }
6801 
6802  /* FIXME? Should this be moved up so that it is only called when
6803  there have been breakpoints? */
6805 
6806  return nr_printable_breakpoints;
6807 }
6808 
6809 /* Display the value of default-collect in a way that is generally
6810  compatible with the breakpoint list. */
6811 
6812 static void
6814 {
6815  struct ui_out *uiout = current_uiout;
6816 
6817  /* If it has no value (which is frequently the case), say nothing; a
6818  message like "No default-collect." gets in user's face when it's
6819  not wanted. */
6820  if (!*default_collect)
6821  return;
6822 
6823  /* The following phrase lines up nicely with per-tracepoint collect
6824  actions. */
6825  ui_out_text (uiout, "default collect ");
6826  ui_out_field_string (uiout, "default-collect", default_collect);
6827  ui_out_text (uiout, " \n");
6828 }
6829 
6830 static void
6831 breakpoints_info (char *args, int from_tty)
6832 {
6833  breakpoint_1 (args, 0, NULL);
6834 
6836 }
6837 
6838 static void
6839 watchpoints_info (char *args, int from_tty)
6840 {
6841  int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6842  struct ui_out *uiout = current_uiout;
6843 
6844  if (num_printed == 0)
6845  {
6846  if (args == NULL || *args == '\0')
6847  ui_out_message (uiout, 0, "No watchpoints.\n");
6848  else
6849  ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6850  }
6851 }
6852 
6853 static void
6854 maintenance_info_breakpoints (char *args, int from_tty)
6855 {
6856  breakpoint_1 (args, 1, NULL);
6857 
6859 }
6860 
6861 static int
6863  struct program_space *pspace,
6864  CORE_ADDR pc, struct obj_section *section)
6865 {
6866  struct bp_location *bl = b->loc;
6867 
6868  for (; bl; bl = bl->next)
6869  {
6870  if (bl->pspace == pspace
6871  && bl->address == pc
6872  && (!overlay_debugging || bl->section == section))
6873  return 1;
6874  }
6875  return 0;
6876 }
6877 
6878 /* Print a message describing any user-breakpoints set at PC. This
6879  concerns with logical breakpoints, so we match program spaces, not
6880  address spaces. */
6881 
6882 static void
6884  struct program_space *pspace, CORE_ADDR pc,
6885  struct obj_section *section, int thread)
6886 {
6887  int others = 0;
6888  struct breakpoint *b;
6889 
6890  ALL_BREAKPOINTS (b)
6891  others += (user_breakpoint_p (b)
6892  && breakpoint_has_pc (b, pspace, pc, section));
6893  if (others > 0)
6894  {
6895  if (others == 1)
6896  printf_filtered (_("Note: breakpoint "));
6897  else /* if (others == ???) */
6898  printf_filtered (_("Note: breakpoints "));
6899  ALL_BREAKPOINTS (b)
6900  if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
6901  {
6902  others--;
6903  printf_filtered ("%d", b->number);
6904  if (b->thread == -1 && thread != -1)
6905  printf_filtered (" (all threads)");
6906  else if (b->thread != -1)
6907  printf_filtered (" (thread %d)", b->thread);
6908  printf_filtered ("%s%s ",
6909  ((b->enable_state == bp_disabled
6910  || b->enable_state == bp_call_disabled)
6911  ? " (disabled)"
6912  : ""),
6913  (others > 1) ? ","
6914  : ((others == 1) ? " and" : ""));
6915  }
6916  printf_filtered (_("also set at pc "));
6917  fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
6918  printf_filtered (".\n");
6919  }
6920 }
6921 
6922 
6923 /* Return true iff it is meaningful to use the address member of
6924  BPT locations. For some breakpoint types, the locations' address members
6925  are irrelevant and it makes no sense to attempt to compare them to other
6926  addresses (or use them for any other purpose either).
6927 
6928  More specifically, each of the following breakpoint types will
6929  always have a zero valued location address and we don't want to mark
6930  breakpoints of any of these types to be a duplicate of an actual
6931  breakpoint location at address zero:
6932 
6933  bp_watchpoint
6934  bp_catchpoint
6935 
6936 */
6937 
6938 static int
6940 {
6941  enum bptype type = bpt->type;
6942 
6943  return (type != bp_watchpoint && type != bp_catchpoint);
6944 }
6945 
6946 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6947  true if LOC1 and LOC2 represent the same watchpoint location. */
6948 
6949 static int
6950 watchpoint_locations_match (struct bp_location *loc1,
6951  struct bp_location *loc2)
6952 {
6953  struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6954  struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6955 
6956  /* Both of them must exist. */
6957  gdb_assert (w1 != NULL);
6958  gdb_assert (w2 != NULL);
6959 
6960  /* If the target can evaluate the condition expression in hardware,
6961  then we we need to insert both watchpoints even if they are at
6962  the same place. Otherwise the watchpoint will only trigger when
6963  the condition of whichever watchpoint was inserted evaluates to
6964  true, not giving a chance for GDB to check the condition of the
6965  other watchpoint. */
6966  if ((w1->cond_exp
6968  loc1->length,
6969  loc1->watchpoint_type,
6970  w1->cond_exp))
6971  || (w2->cond_exp
6973  loc2->length,
6974  loc2->watchpoint_type,
6975  w2->cond_exp)))
6976  return 0;
6977 
6978  /* Note that this checks the owner's type, not the location's. In
6979  case the target does not support read watchpoints, but does
6980  support access watchpoints, we'll have bp_read_watchpoint
6981  watchpoints with hw_access locations. Those should be considered
6982  duplicates of hw_read locations. The hw_read locations will
6983  become hw_access locations later. */
6984  return (loc1->owner->type == loc2->owner->type
6985  && loc1->pspace->aspace == loc2->pspace->aspace
6986  && loc1->address == loc2->address
6987  && loc1->length == loc2->length);
6988 }
6989 
6990 /* See breakpoint.h. */
6991 
6992 int
6994  struct address_space *aspace2, CORE_ADDR addr2)
6995 {
6997  || aspace1 == aspace2)
6998  && addr1 == addr2);
6999 }
7000 
7001 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7002  {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7003  matches ASPACE2. On targets that have global breakpoints, the address
7004  space doesn't really matter. */
7005 
7006 static int
7008  int len1, struct address_space *aspace2,
7009  CORE_ADDR addr2)
7010 {
7012  || aspace1 == aspace2)
7013  && addr2 >= addr1 && addr2 < addr1 + len1);
7014 }
7015 
7016 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7017  a ranged breakpoint. In most targets, a match happens only if ASPACE
7018  matches the breakpoint's address space. On targets that have global
7019  breakpoints, the address space doesn't really matter. */
7020 
7021 static int
7022 breakpoint_location_address_match (struct bp_location *bl,
7023  struct address_space *aspace,
7024  CORE_ADDR addr)
7025 {
7026  return (breakpoint_address_match (bl->pspace->aspace, bl->address,
7027  aspace, addr)
7028  || (bl->length
7030  bl->address, bl->length,
7031  aspace, addr)));
7032 }
7033 
7034 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7035  Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7036  true, otherwise returns false. */
7037 
7038 static int
7039 tracepoint_locations_match (struct bp_location *loc1,
7040  struct bp_location *loc2)
7041 {
7042  if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
7043  /* Since tracepoint locations are never duplicated with others', tracepoint
7044  locations at the same address of different tracepoints are regarded as
7045  different locations. */
7046  return (loc1->address == loc2->address && loc1->owner == loc2->owner);
7047  else
7048  return 0;
7049 }
7050 
7051 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7052  (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7053  represent the same location. */
7054 
7055 static int
7056 breakpoint_locations_match (struct bp_location *loc1,
7057  struct bp_location *loc2)
7058 {
7059  int hw_point1, hw_point2;
7060 
7061  /* Both of them must not be in moribund_locations. */
7062  gdb_assert (loc1->owner != NULL);
7063  gdb_assert (loc2->owner != NULL);
7064 
7065  hw_point1 = is_hardware_watchpoint (loc1->owner);
7066  hw_point2 = is_hardware_watchpoint (loc2->owner);
7067 
7068  if (hw_point1 != hw_point2)
7069  return 0;
7070  else if (hw_point1)
7071  return watchpoint_locations_match (loc1, loc2);
7072  else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
7073  return tracepoint_locations_match (loc1, loc2);
7074  else
7075  /* We compare bp_location.length in order to cover ranged breakpoints. */
7076  return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
7077  loc2->pspace->aspace, loc2->address)
7078  && loc1->length == loc2->length);
7079 }
7080 
7081 static void
7083  int bnum, int have_bnum)
7084 {
7085  /* The longest string possibly returned by hex_string_custom
7086  is 50 chars. These must be at least that big for safety. */
7087  char astr1[64];
7088  char astr2[64];
7089 
7090  strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
7091  strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
7092  if (have_bnum)
7093  warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7094  bnum, astr1, astr2);
7095  else
7096  warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
7097 }
7098 
7099 /* Adjust a breakpoint's address to account for architectural
7100  constraints on breakpoint placement. Return the adjusted address.
7101  Note: Very few targets require this kind of adjustment. For most
7102  targets, this function is simply the identity function. */
7103 
7104 static CORE_ADDR
7106  CORE_ADDR bpaddr, enum bptype bptype)
7107 {
7108  if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
7109  {
7110  /* Very few targets need any kind of breakpoint adjustment. */
7111  return bpaddr;
7112  }
7113  else if (bptype == bp_watchpoint
7114  || bptype == bp_hardware_watchpoint
7115  || bptype == bp_read_watchpoint
7116  || bptype == bp_access_watchpoint
7117  || bptype == bp_catchpoint)
7118  {
7119  /* Watchpoints and the various bp_catch_* eventpoints should not
7120  have their addresses modified. */
7121  return bpaddr;
7122  }
7123  else if (bptype == bp_single_step)
7124  {
7125  /* Single-step breakpoints should not have their addresses
7126  modified. If there's any architectural constrain that
7127  applies to this address, then it should have already been
7128  taken into account when the breakpoint was created in the
7129  first place. If we didn't do this, stepping through e.g.,
7130  Thumb-2 IT blocks would break. */
7131  return bpaddr;
7132  }
7133  else
7134  {
7135  CORE_ADDR adjusted_bpaddr;
7136 
7137  /* Some targets have architectural constraints on the placement
7138  of breakpoint instructions. Obtain the adjusted address. */
7139  adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
7140 
7141  /* An adjusted breakpoint address can significantly alter
7142  a user's expectations. Print a warning if an adjustment
7143  is required. */
7144  if (adjusted_bpaddr != bpaddr)
7145  breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
7146 
7147  return adjusted_bpaddr;
7148  }
7149 }
7150 
7151 void
7152 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
7153  struct breakpoint *owner)
7154 {
7155  memset (loc, 0, sizeof (*loc));
7156 
7157  gdb_assert (ops != NULL);
7158 
7159  loc->ops = ops;
7160  loc->owner = owner;
7161  loc->cond = NULL;
7162  loc->cond_bytecode = NULL;
7163  loc->shlib_disabled = 0;
7164  loc->enabled = 1;
7165 
7166  switch (owner->type)
7167  {
7168  case bp_breakpoint:
7169  case bp_single_step:
7170  case bp_until:
7171  case bp_finish:
7172  case bp_longjmp:
7173  case bp_longjmp_resume:
7174  case bp_longjmp_call_dummy:
7175  case bp_exception:
7176  case bp_exception_resume:
7177  case bp_step_resume:
7178  case bp_hp_step_resume:
7179  case bp_watchpoint_scope:
7180  case bp_call_dummy:
7181  case bp_std_terminate:
7182  case bp_shlib_event:
7183  case bp_thread_event:
7184  case bp_overlay_event:
7185  case bp_jit_event:
7186  case bp_longjmp_master:
7188  case bp_exception_master:
7189  case bp_gnu_ifunc_resolver:
7191  case bp_dprintf:
7194  break;
7198  break;
7200  case bp_read_watchpoint:
7201  case bp_access_watchpoint:
7203  break;
7204  case bp_watchpoint:
7205  case bp_catchpoint:
7206  case bp_tracepoint:
7207  case bp_fast_tracepoint:
7208  case bp_static_tracepoint:
7209  loc->loc_type = bp_loc_other;
7210  break;
7211  default:
7212  internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
7213  }
7214 
7215  loc->refc = 1;
7216 }
7217 
7218 /* Allocate a struct bp_location. */
7219 
7220 static struct bp_location *
7222 {
7223  return bpt->ops->allocate_location (bpt);
7224 }
7225 
7226 static void
7227 free_bp_location (struct bp_location *loc)
7228 {
7229  loc->ops->dtor (loc);
7230  xfree (loc);
7231 }
7232 
7233 /* Increment reference count. */
7234 
7235 static void
7236 incref_bp_location (struct bp_location *bl)
7237 {
7238  ++bl->refc;
7239 }
7240 
7241 /* Decrement reference count. If the reference count reaches 0,
7242  destroy the bp_location. Sets *BLP to NULL. */
7243 
7244 static void
7245 decref_bp_location (struct bp_location **blp)
7246 {
7247  gdb_assert ((*blp)->refc > 0);
7248 
7249  if (--(*blp)->refc == 0)
7250  free_bp_location (*blp);
7251  *blp = NULL;
7252 }
7253 
7254 /* Add breakpoint B at the end of the global breakpoint chain. */
7255 
7256 static void
7258 {
7259  struct breakpoint *b1;
7260 
7261  /* Add this breakpoint to the end of the chain so that a list of
7262  breakpoints will come out in order of increasing numbers. */
7263 
7264  b1 = breakpoint_chain;
7265  if (b1 == 0)
7266  breakpoint_chain = b;
7267  else
7268  {
7269  while (b1->next)
7270  b1 = b1->next;
7271  b1->next = b;
7272  }
7273 }
7274 
7275 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7276 
7277 static void
7279  struct gdbarch *gdbarch,
7280  enum bptype bptype,
7281  const struct breakpoint_ops *ops)
7282 {
7283  memset (b, 0, sizeof (*b));
7284 
7285  gdb_assert (ops != NULL);
7286 
7287  b->ops = ops;
7288  b->type = bptype;
7289  b->gdbarch = gdbarch;
7291  b->input_radix = input_radix;
7292  b->thread = -1;
7293  b->enable_state = bp_enabled;
7294  b->next = 0;
7295  b->silent = 0;
7296  b->ignore_count = 0;
7297  b->commands = NULL;
7298  b->frame_id = null_frame_id;
7299  b->condition_not_parsed = 0;
7300  b->py_bp_object = NULL;
7301  b->related_breakpoint = b;
7302 }
7303 
7304 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7305  that has type BPTYPE and has no locations as yet. */
7306 
7307 static struct breakpoint *
7309  enum bptype bptype,
7310  const struct breakpoint_ops *ops)
7311 {
7312  struct breakpoint *b = XNEW (struct breakpoint);
7313 
7314  init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7316  return b;
7317 }
7318 
7319 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7320  resolutions should be made as the user specified the location explicitly
7321  enough. */
7322 
7323 static void
7324 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
7325 {
7326  gdb_assert (loc->owner != NULL);
7327 
7328  if (loc->owner->type == bp_breakpoint
7329  || loc->owner->type == bp_hardware_breakpoint
7330  || is_tracepoint (loc->owner))
7331  {
7332  int is_gnu_ifunc;
7333  const char *function_name;
7334  CORE_ADDR func_addr;
7335 
7336  find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7337  &func_addr, NULL, &is_gnu_ifunc);
7338 
7339  if (is_gnu_ifunc && !explicit_loc)
7340  {
7341  struct breakpoint *b = loc->owner;
7342 
7344  if (gnu_ifunc_resolve_name (function_name,
7345  &loc->requested_address))
7346  {
7347  /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7349  loc->requested_address,
7350  b->type);
7351  }
7352  else if (b->type == bp_breakpoint && b->loc == loc
7353  && loc->next == NULL && b->related_breakpoint == b)
7354  {
7355  /* Create only the whole new breakpoint of this type but do not
7356  mess more complicated breakpoints with multiple locations. */
7358  /* Remember the resolver's address for use by the return
7359  breakpoint. */
7360  loc->related_address = func_addr;
7361  }
7362  }
7363 
7364  if (function_name)
7365  loc->function_name = xstrdup (function_name);
7366  }
7367 }
7368 
7369 /* Attempt to determine architecture of location identified by SAL. */
7370 struct gdbarch *
7372 {
7373  if (sal.section)
7374  return get_objfile_arch (sal.section->objfile);
7375  if (sal.symtab)
7376  return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
7377 
7378  return NULL;
7379 }
7380 
7381 /* Low level routine for partially initializing a breakpoint of type
7382  BPTYPE. The newly created breakpoint's address, section, source
7383  file name, and line number are provided by SAL.
7384 
7385  It is expected that the caller will complete the initialization of
7386  the newly created breakpoint struct as well as output any status
7387  information regarding the creation of a new breakpoint. */
7388 
7389 static void
7391  struct symtab_and_line sal, enum bptype bptype,
7392  const struct breakpoint_ops *ops)
7393 {
7394  init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7395 
7396  add_location_to_breakpoint (b, &sal);
7397 
7398  if (bptype != bp_catchpoint)
7399  gdb_assert (sal.pspace != NULL);
7400 
7401  /* Store the program space that was used to set the breakpoint,
7402  except for ordinary breakpoints, which are independent of the
7403  program space. */
7404  if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7405  b->pspace = sal.pspace;
7406 }
7407 
7408 /* set_raw_breakpoint is a low level routine for allocating and
7409  partially initializing a breakpoint of type BPTYPE. The newly
7410  created breakpoint's address, section, source file name, and line
7411  number are provided by SAL. The newly created and partially
7412  initialized breakpoint is added to the breakpoint chain and
7413  is also returned as the value of this function.
7414 
7415  It is expected that the caller will complete the initialization of
7416  the newly created breakpoint struct as well as output any status
7417  information regarding the creation of a new breakpoint. In
7418  particular, set_raw_breakpoint does NOT set the breakpoint
7419  number! Care should be taken to not allow an error to occur
7420  prior to completing the initialization of the breakpoint. If this
7421  should happen, a bogus breakpoint will be left on the chain. */
7422 
7423 struct breakpoint *
7425  struct symtab_and_line sal, enum bptype bptype,
7426  const struct breakpoint_ops *ops)
7427 {
7428  struct breakpoint *b = XNEW (struct breakpoint);
7429 
7430  init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7432  return b;
7433 }
7434 
7435 /* Call this routine when stepping and nexting to enable a breakpoint
7436  if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7437  initiated the operation. */
7438 
7439 void
7440 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
7441 {
7442  struct breakpoint *b, *b_tmp;
7443  int thread = tp->num;
7444 
7445  /* To avoid having to rescan all objfile symbols at every step,
7446  we maintain a list of continually-inserted but always disabled
7447  longjmp "master" breakpoints. Here, we simply create momentary
7448  clones of those and enable them for the requested thread. */
7449  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7450  if (b->pspace == current_program_space
7451  && (b->type == bp_longjmp_master
7452  || b->type == bp_exception_master))
7453  {
7455  struct breakpoint *clone;
7456 
7457  /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7458  after their removal. */
7459  clone = momentary_breakpoint_from_master (b, type,
7461  clone->thread = thread;
7462  }
7463 
7464  tp->initiating_frame = frame;
7465 }
7466 
7467 /* Delete all longjmp breakpoints from THREAD. */
7468 void
7470 {
7471  struct breakpoint *b, *b_tmp;
7472 
7473  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7474  if (b->type == bp_longjmp || b->type == bp_exception)
7475  {
7476  if (b->thread == thread)
7477  delete_breakpoint (b);
7478  }
7479 }
7480 
7481 void
7483 {
7484  struct breakpoint *b, *b_tmp;
7485 
7486  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7487  if (b->type == bp_longjmp || b->type == bp_exception)
7488  {
7489  if (b->thread == thread)
7491  }
7492 }
7493 
7494 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7495  INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7496  pointer to any of them. Return NULL if this system cannot place longjmp
7497  breakpoints. */
7498 
7499 struct breakpoint *
7501 {
7502  struct breakpoint *b, *retval = NULL;
7503 
7504  ALL_BREAKPOINTS (b)
7506  {
7507  struct breakpoint *new_b;
7508 
7511  1);
7513 
7514  /* Link NEW_B into the chain of RETVAL breakpoints. */
7515 
7516  gdb_assert (new_b->related_breakpoint == new_b);
7517  if (retval == NULL)
7518  retval = new_b;
7519  new_b->related_breakpoint = retval;
7520  while (retval->related_breakpoint != new_b->related_breakpoint)
7521  retval = retval->related_breakpoint;
7522  retval->related_breakpoint = new_b;
7523  }
7524 
7525  return retval;
7526 }
7527 
7528 /* Verify all existing dummy frames and their associated breakpoints for
7529  TP. Remove those which can no longer be found in the current frame
7530  stack.
7531 
7532  You should call this function only at places where it is safe to currently
7533  unwind the whole stack. Failed stack unwind would discard live dummy
7534  frames. */
7535 
7536 void
7538 {
7539  struct breakpoint *b, *b_tmp;
7540 
7541  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7542  if (b->type == bp_longjmp_call_dummy && b->thread == tp->num)
7543  {
7544  struct breakpoint *dummy_b = b->related_breakpoint;
7545 
7546  while (dummy_b != b && dummy_b->type != bp_call_dummy)
7547  dummy_b = dummy_b->related_breakpoint;
7548  if (dummy_b->type != bp_call_dummy
7549  || frame_find_by_id (dummy_b->frame_id) != NULL)
7550  continue;
7551 
7552  dummy_frame_discard (dummy_b->frame_id, tp->ptid);
7553 
7554  while (b->related_breakpoint != b)
7555  {
7556  if (b_tmp == b->related_breakpoint)
7557  b_tmp = b->related_breakpoint->next;
7559  }
7560  delete_breakpoint (b);
7561  }
7562 }
7563 
7564 void
7566 {
7567  struct breakpoint *b;
7568 
7569  ALL_BREAKPOINTS (b)
7570  if (b->type == bp_overlay_event)
7571  {
7572  b->enable_state = bp_enabled;
7574  overlay_events_enabled = 1;
7575  }
7576 }
7577 
7578 void
7580 {
7581  struct breakpoint *b;
7582 
7583  ALL_BREAKPOINTS (b)
7584  if (b->type == bp_overlay_event)
7585  {
7588  overlay_events_enabled = 0;
7589  }
7590 }
7591 
7592 /* Set an active std::terminate breakpoint for each std::terminate
7593  master breakpoint. */
7594 void
7596 {
7597  struct breakpoint *b, *b_tmp;
7598 
7599  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7600  if (b->pspace == current_program_space
7601  && b->type == bp_std_terminate_master)
7602  {
7605  }
7606 }
7607 
7608 /* Delete all the std::terminate breakpoints. */
7609 void
7611 {
7612  struct breakpoint *b, *b_tmp;
7613 
7614  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7615  if (b->type == bp_std_terminate)
7616  delete_breakpoint (b);
7617 }
7618 
7619 struct breakpoint *
7621 {
7622  struct breakpoint *b;
7623 
7624  b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7626 
7627  b->enable_state = bp_enabled;
7628  /* addr_string has to be used or breakpoint_re_set will delete me. */
7629  b->addr_string
7630  = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
7631 
7633 
7634  return b;
7635 }
7636 
7637 void
7639 {
7640  struct breakpoint *b, *b_tmp;
7641 
7642  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7643  if (b->type == bp_thread_event
7644  && b->loc->pspace == current_program_space)
7645  delete_breakpoint (b);
7646 }
7647 
7649  {
7651  int radix;
7652  };
7653 
7654 /* Create a breakpoint for JIT code registration and unregistration. */
7655 
7656 struct breakpoint *
7658 {
7659  struct breakpoint *b;
7660 
7661  b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7664  return b;
7665 }
7666 
7667 /* Remove JIT code registration and unregistration breakpoint(s). */
7668 
7669 void
7671 {
7672  struct breakpoint *b, *b_tmp;
7673 
7674  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7675  if (b->type == bp_jit_event
7676  && b->loc->pspace == current_program_space)
7677  delete_breakpoint (b);
7678 }
7679 
7680 void
7682 {
7683  struct breakpoint *b, *b_tmp;
7684 
7685  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7686  if (b->type == bp_shlib_event
7687  && b->loc->pspace == current_program_space)
7688  delete_breakpoint (b);
7689 }
7690 
7691 /* See breakpoint.h. */
7692 
7693 void
7695 {
7696  struct breakpoint *b, *b_tmp;
7697 
7698  ALL_BREAKPOINTS_SAFE (b, b_tmp)
7699  if (b->type == bp_shlib_event
7700  && b->loc->pspace == current_program_space)
7702 }
7703 
7704 /* Helper for create_solib_event_breakpoint /
7705  create_and_insert_solib_event_breakpoint. Allows specifying which
7706  INSERT_MODE to pass through to update_global_location_list. */
7707 
7708 static struct breakpoint *
7710  enum ugll_insert_mode insert_mode)
7711 {
7712  struct breakpoint *b;
7713 
7714  b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7717  return b;
7718 }
7719 
7720 struct breakpoint *
7722 {
7723  return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT);
7724 }
7725 
7726 /* See breakpoint.h. */
7727 
7728 struct breakpoint *
7730 {
7731  struct breakpoint *b;
7732 
7733  /* Explicitly tell update_global_location_list to insert
7734  locations. */
7735  b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT);
7736  if (!b->loc->inserted)
7737  {
7738  delete_breakpoint (b);
7739  return NULL;
7740  }
7741  return b;
7742 }
7743 
7744 /* Disable any breakpoints that are on code in shared libraries. Only
7745  apply to enabled breakpoints, disabled ones can just stay disabled. */
7746 
7747 void
7749 {
7750  struct bp_location *loc, **locp_tmp;
7751 
7752  ALL_BP_LOCATIONS (loc, locp_tmp)
7753  {
7754  /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7755  struct breakpoint *b = loc->owner;
7756 
7757  /* We apply the check to all breakpoints, including disabled for
7758  those with loc->duplicate set. This is so that when breakpoint
7759  becomes enabled, or the duplicate is removed, gdb will try to
7760  insert all breakpoints. If we don't set shlib_disabled here,
7761  we'll try to insert those breakpoints and fail. */
7762  if (((b->type == bp_breakpoint)
7763  || (b->type == bp_jit_event)
7764  || (b->type == bp_hardware_breakpoint)
7765  || (is_tracepoint (b)))
7766  && loc->pspace == current_program_space
7767  && !loc->shlib_disabled
7768  && solib_name_from_address (loc->pspace, loc->address)
7769  )
7770  {
7771  loc->shlib_disabled = 1;
7772  }
7773  }
7774 }
7775 
7776 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7777  notification of unloaded_shlib. Only apply to enabled breakpoints,
7778  disabled ones can just stay disabled. */
7779 
7780 static void
7782 {
7783  struct bp_location *loc, **locp_tmp;
7784  int disabled_shlib_breaks = 0;
7785 
7786  /* SunOS a.out shared libraries are always mapped, so do not
7787  disable breakpoints; they will only be reported as unloaded
7788  through clear_solib when GDB discards its shared library
7789  list. See clear_solib for more information. */
7790  if (exec_bfd != NULL
7791  && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
7792  return;
7793 
7794  ALL_BP_LOCATIONS (loc, locp_tmp)
7795  {
7796  /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7797  struct breakpoint *b = loc->owner;
7798 
7799  if (solib->pspace == loc->pspace
7800  && !loc->shlib_disabled
7801  && (((b->type == bp_breakpoint
7802  || b->type == bp_jit_event
7803  || b->type == bp_hardware_breakpoint)
7806  || is_tracepoint (b))
7807  && solib_contains_address_p (solib, loc->address))
7808  {
7809  loc->shlib_disabled = 1;
7810  /* At this point, we cannot rely on remove_breakpoint
7811  succeeding so we must mark the breakpoint as not inserted
7812  to prevent future errors occurring in remove_breakpoints. */
7813  loc->inserted = 0;
7814 
7815  /* This may cause duplicate notifications for the same breakpoint. */
7817 
7818  if (!disabled_shlib_breaks)
7819  {
7821  warning (_("Temporarily disabling breakpoints "
7822  "for unloaded shared library \"%s\""),
7823  solib->so_name);
7824  }
7825  disabled_shlib_breaks = 1;
7826  }
7827  }
7828 }
7829 
7830 /* Disable any breakpoints and tracepoints in OBJFILE upon
7831  notification of free_objfile. Only apply to enabled breakpoints,
7832  disabled ones can just stay disabled. */
7833 
7834 static void
7836 {
7837  struct breakpoint *b;
7838 
7839  if (objfile == NULL)
7840  return;
7841 
7842  /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7843  managed by the user with add-symbol-file/remove-symbol-file.
7844  Similarly to how breakpoints in shared libraries are handled in
7845  response to "nosharedlibrary", mark breakpoints in such modules
7846  shlib_disabled so they end up uninserted on the next global
7847  location list update. Shared libraries not loaded by the user
7848  aren't handled here -- they're already handled in
7849  disable_breakpoints_in_unloaded_shlib, called by solib.c's
7850  solib_unloaded observer. We skip objfiles that are not
7851  OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7852  main objfile). */
7853  if ((objfile->flags & OBJF_SHARED) == 0
7854  || (objfile->flags & OBJF_USERLOADED) == 0)
7855  return;
7856 
7857  ALL_BREAKPOINTS (b)
7858  {
7859  struct bp_location *loc;
7860  int bp_modified = 0;
7861 
7862  if (!is_breakpoint (b) && !is_tracepoint (b))
7863  continue;
7864 
7865  for (loc = b->loc; loc != NULL; loc = loc->next)
7866  {
7867  CORE_ADDR loc_addr = loc->address;
7868 
7871  continue;
7872 
7873  if (loc->shlib_disabled != 0)
7874  continue;
7875 
7876  if (objfile->pspace != loc->pspace)
7877  continue;
7878 
7881  continue;
7882 
7883  if (is_addr_in_objfile (loc_addr, objfile))
7884  {
7885  loc->shlib_disabled = 1;
7886  /* At this point, we don't know whether the object was
7887  unmapped from the inferior or not, so leave the
7888  inserted flag alone. We'll handle failure to
7889  uninsert quietly, in case the object was indeed
7890  unmapped. */
7891 
7893 
7894  bp_modified = 1;
7895  }
7896  }
7897 
7898  if (bp_modified)
7900  }
7901 }
7902 
7903 /* FORK & VFORK catchpoints. */
7904 
7905 /* An instance of this type is used to represent a fork or vfork
7906  catchpoint. It includes a "struct breakpoint" as a kind of base
7907  class; users downcast to "struct breakpoint *" when needed. A
7908  breakpoint is really of this type iff its ops pointer points to
7909  CATCH_FORK_BREAKPOINT_OPS. */
7910 
7912 {
7913  /* The base class. */
7915 
7916  /* Process id of a child process whose forking triggered this
7917  catchpoint. This field is only valid immediately after this
7918  catchpoint has triggered. */
7920 };
7921 
7922 /* Implement the "insert" breakpoint_ops method for fork
7923  catchpoints. */
7924 
7925 static int
7926 insert_catch_fork (struct bp_location *bl)
7927 {
7929 }
7930 
7931 /* Implement the "remove" breakpoint_ops method for fork
7932  catchpoints. */
7933 
7934 static int
7935 remove_catch_fork (struct bp_location *bl)
7936 {
7938 }
7939 
7940 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7941  catchpoints. */
7942 
7943 static int
7944 breakpoint_hit_catch_fork (const struct bp_location *bl,
7945  struct address_space *aspace, CORE_ADDR bp_addr,
7946  const struct target_waitstatus *ws)
7947 {
7948  struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7949 
7950  if (ws->kind != TARGET_WAITKIND_FORKED)
7951  return 0;
7952 
7954  return 1;
7955 }
7956 
7957 /* Implement the "print_it" breakpoint_ops method for fork
7958  catchpoints. */
7959 
7960 static enum print_stop_action
7962 {
7963  struct ui_out *uiout = current_uiout;
7964  struct breakpoint *b = bs->breakpoint_at;
7965  struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7966 
7968  if (b->disposition == disp_del)
7969  ui_out_text (uiout, "\nTemporary catchpoint ");
7970  else
7971  ui_out_text (uiout, "\nCatchpoint ");
7972  if (ui_out_is_mi_like_p (uiout))
7973  {
7974  ui_out_field_string (uiout, "reason",
7976  ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7977  }
7978  ui_out_field_int (uiout, "bkptno", b->number);
7979  ui_out_text (uiout, " (forked process ");
7980  ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7981  ui_out_text (uiout, "), ");
7982  return PRINT_SRC_AND_LOC;
7983 }
7984 
7985 /* Implement the "print_one" breakpoint_ops method for fork
7986  catchpoints. */
7987 
7988 static void
7989 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
7990 {
7991  struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7992  struct value_print_options opts;
7993  struct ui_out *uiout = current_uiout;
7994 
7995  get_user_print_options (&opts);
7996 
7997  /* Field 4, the address, is omitted (which makes the columns not
7998  line up too nicely with the headers, but the effect is relatively
7999  readable). */
8000  if (opts.addressprint)
8001  ui_out_field_skip (uiout, "addr");
8002  annotate_field (5);
8003  ui_out_text (uiout, "fork");
8005  {
8006  ui_out_text (uiout, ", process ");
8007  ui_out_field_int (uiout, "what",
8009  ui_out_spaces (uiout, 1);
8010  }
8011 
8012  if (ui_out_is_mi_like_p (uiout))
8013  ui_out_field_string (uiout, "catch-type", "fork");
8014 }
8015 
8016 /* Implement the "print_mention" breakpoint_ops method for fork
8017  catchpoints. */
8018 
8019 static void
8021 {
8022  printf_filtered (_("Catchpoint %d (fork)"), b->number);
8023 }
8024 
8025 /* Implement the "print_recreate" breakpoint_ops method for fork
8026  catchpoints. */
8027 
8028 static void
8030 {
8031  fprintf_unfiltered (fp, "catch fork");
8032  print_recreate_thread (b, fp);
8033 }
8034 
8035 /* The breakpoint_ops structure to be used in fork catchpoints. */
8036 
8038 
8039 /* Implement the "insert" breakpoint_ops method for vfork
8040  catchpoints. */
8041 
8042 static int
8043 insert_catch_vfork (struct bp_location *bl)
8044 {
8046 }
8047 
8048 /* Implement the "remove" breakpoint_ops method for vfork
8049  catchpoints. */
8050 
8051 static int
8052 remove_catch_vfork (struct bp_location *bl)
8053 {
8055 }
8056 
8057 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8058  catchpoints. */
8059 
8060 static int
8061 breakpoint_hit_catch_vfork (const struct bp_location *bl,
8062  struct address_space *aspace, CORE_ADDR bp_addr,
8063  const struct target_waitstatus *ws)
8064 {
8065  struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
8066 
8068  return 0;
8069 
8071  return 1;
8072 }
8073 
8074 /* Implement the "print_it" breakpoint_ops method for vfork
8075  catchpoints. */
8076 
8077 static enum print_stop_action
8079 {
8080  struct ui_out *uiout = current_uiout;
8081  struct breakpoint *b = bs->breakpoint_at;
8082  struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8083 
8085  if (b->disposition == disp_del)
8086  ui_out_text (uiout, "\nTemporary catchpoint ");
8087  else
8088  ui_out_text (uiout, "\nCatchpoint ");
8089  if (ui_out_is_mi_like_p (uiout))
8090  {
8091  ui_out_field_string (uiout, "reason",
8093  ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8094  }
8095  ui_out_field_int (uiout, "bkptno", b->number);
8096  ui_out_text (uiout, " (vforked process ");
8097  ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
8098  ui_out_text (uiout, "), ");
8099  return PRINT_SRC_AND_LOC;
8100 }
8101 
8102 /* Implement the "print_one" breakpoint_ops method for vfork
8103  catchpoints. */
8104 
8105 static void
8106 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
8107 {
8108  struct fork_catchpoint *c = (struct fork_catchpoint *) b;
8109  struct value_print_options opts;
8110  struct ui_out *uiout = current_uiout;
8111 
8112  get_user_print_options (&opts);
8113  /* Field 4, the address, is omitted (which makes the columns not
8114  line up too nicely with the headers, but the effect is relatively
8115  readable). */
8116  if (opts.addressprint)
8117  ui_out_field_skip (uiout, "addr");
8118  annotate_field (5);
8119  ui_out_text (uiout, "vfork");
8121  {
8122  ui_out_text (uiout, ", process ");
8123  ui_out_field_int (uiout, "what",
8125  ui_out_spaces (uiout, 1);
8126  }
8127 
8128  if (ui_out_is_mi_like_p (uiout))
8129  ui_out_field_string (uiout, "catch-type", "vfork");
8130 }
8131 
8132 /* Implement the "print_mention" breakpoint_ops method for vfork
8133  catchpoints. */
8134 
8135 static void
8137 {
8138  printf_filtered (_("Catchpoint %d (vfork)"), b->number);
8139 }
8140 
8141 /* Implement the "print_recreate" breakpoint_ops method for vfork
8142  catchpoints. */
8143 
8144 static void
8146 {
8147  fprintf_unfiltered (fp, "catch vfork");
8148  print_recreate_thread (b, fp);
8149 }
8150 
8151 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8152 
8154 
8155 /* An instance of this type is used to represent an solib catchpoint.
8156  It includes a "struct breakpoint" as a kind of base class; users
8157  downcast to "struct breakpoint *" when needed. A breakpoint is
8158  really of this type iff its ops pointer points to
8159  CATCH_SOLIB_BREAKPOINT_OPS. */
8160 
8162 {
8163  /* The base class. */
8165 
8166  /* True for "catch load", false for "catch unload". */
8167  unsigned char is_load;
8168 
8169  /* Regular expression to match, if any. COMPILED is only valid when
8170  REGEX is non-NULL. */
8171  char *regex;
8172  regex_t compiled;
8173 };
8174 
8175 static void
8177 {
8178  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8179 
8180  if (self->regex)
8181  regfree (&self->compiled);
8182  xfree (self->regex);
8183 
8184  base_breakpoint_ops.dtor (b);
8185 }
8186 
8187 static int
8188 insert_catch_solib (struct bp_location *ignore)
8189 {
8190  return 0;
8191 }
8192 
8193 static int
8194 remove_catch_solib (struct bp_location *ignore)
8195 {
8196  return 0;
8197 }
8198 
8199 static int
8200 breakpoint_hit_catch_solib (const struct bp_location *bl,
8201  struct address_space *aspace,
8202  CORE_ADDR bp_addr,
8203  const struct target_waitstatus *ws)
8204 {
8205  struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
8206  struct breakpoint *other;
8207 
8208  if (ws->kind == TARGET_WAITKIND_LOADED)
8209  return 1;
8210 
8211  ALL_BREAKPOINTS (other)
8212  {
8213  struct bp_location *other_bl;
8214 
8215  if (other == bl->owner)
8216  continue;
8217 
8218  if (other->type != bp_shlib_event)
8219  continue;
8220 
8221  if (self->base.pspace != NULL && other->pspace != self->base.pspace)
8222  continue;
8223 
8224  for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
8225  {
8226  if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
8227  return 1;
8228  }
8229  }
8230 
8231  return 0;
8232 }
8233 
8234 static void
8236 {
8237  struct solib_catchpoint *self
8238  = (struct solib_catchpoint *) bs->breakpoint_at;
8239  int ix;
8240 
8241  if (self->is_load)
8242  {
8243  struct so_list *iter;
8244 
8245  for (ix = 0;
8247  ix, iter);
8248  ++ix)
8249  {
8250  if (!self->regex
8251  || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
8252  return;
8253  }
8254  }
8255  else
8256  {
8257  char *iter;
8258 
8259  for (ix = 0;
8260  VEC_iterate (char_ptr, current_program_space->deleted_solibs,
8261  ix, iter);
8262  ++ix)
8263  {
8264  if (!self->regex
8265  || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
8266  return;
8267  }
8268  }
8269 
8270  bs->stop = 0;
8271  bs->print_it = print_it_noop;
8272 }
8273 
8274 static enum print_stop_action
8276 {
8277  struct breakpoint *b = bs->breakpoint_at;
8278  struct ui_out *uiout = current_uiout;
8279 
8281  if (b->disposition == disp_del)
8282  ui_out_text (uiout, "\nTemporary catchpoint ");
8283  else
8284  ui_out_text (uiout, "\nCatchpoint ");
8285  ui_out_field_int (uiout, "bkptno", b->number);
8286  ui_out_text (uiout, "\n");
8287  if (ui_out_is_mi_like_p (uiout))
8288  ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8289  print_solib_event (1);
8290  return PRINT_SRC_AND_LOC;
8291 }
8292 
8293 static void
8294 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
8295 {
8296  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8297  struct value_print_options opts;
8298  struct ui_out *uiout = current_uiout;
8299  char *msg;
8300 
8301  get_user_print_options (&opts);
8302  /* Field 4, the address, is omitted (which makes the columns not
8303  line up too nicely with the headers, but the effect is relatively
8304  readable). */
8305  if (opts.addressprint)
8306  {
8307  annotate_field (4);
8308  ui_out_field_skip (uiout, "addr");
8309  }
8310 
8311  annotate_field (5);
8312  if (self->is_load)
8313  {
8314  if (self->regex)
8315  msg = xstrprintf (_("load of library matching %s"), self->regex);
8316  else
8317  msg = xstrdup (_("load of library"));
8318  }
8319  else
8320  {
8321  if (self->regex)
8322  msg = xstrprintf (_("unload of library matching %s"), self->regex);
8323  else
8324  msg = xstrdup (_("unload of library"));
8325  }
8326  ui_out_field_string (uiout, "what", msg);
8327  xfree (msg);
8328 
8329  if (ui_out_is_mi_like_p (uiout))
8330  ui_out_field_string (uiout, "catch-type",
8331  self->is_load ? "load" : "unload");
8332 }
8333 
8334 static void
8336 {
8337  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8338 
8339  printf_filtered (_("Catchpoint %d (%s)"), b->number,
8340  self->is_load ? "load" : "unload");
8341 }
8342 
8343 static void
8345 {
8346  struct solib_catchpoint *self = (struct solib_catchpoint *) b;
8347 
8348  fprintf_unfiltered (fp, "%s %s",
8349  b->disposition == disp_del ? "tcatch" : "catch",
8350  self->is_load ? "load" : "unload");
8351  if (self->regex)
8352  fprintf_unfiltered (fp, " %s", self->regex);
8353  fprintf_unfiltered (fp, "\n");
8354 }
8355 
8357 
8358 /* Shared helper function (MI and CLI) for creating and installing
8359  a shared object event catchpoint. If IS_LOAD is non-zero then
8360  the events to be caught are load events, otherwise they are
8361  unload events. If IS_TEMP is non-zero the catchpoint is a
8362  temporary one. If ENABLED is non-zero the catchpoint is
8363  created in an enabled state. */
8364 
8365 void
8366 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
8367 {
8368  struct solib_catchpoint *c;
8369  struct gdbarch *gdbarch = get_current_arch ();
8370  struct cleanup *cleanup;
8371 
8372  if (!arg)
8373  arg = "";
8374  arg = skip_spaces (arg);
8375 
8376  c = XCNEW (struct solib_catchpoint);
8377  cleanup = make_cleanup (xfree, c);
8378 
8379  if (*arg != '\0')
8380  {
8381  int errcode;
8382 
8383  errcode = regcomp (&c->compiled, arg, REG_NOSUB);
8384  if (errcode != 0)
8385  {
8386  char *err = get_regcomp_error (errcode, &c->compiled);
8387 
8388  make_cleanup (xfree, err);
8389  error (_("Invalid regexp (%s): %s"), err, arg);
8390  }
8391  c->regex = xstrdup (arg);
8392  }
8393 
8394  c->is_load = is_load;
8395  init_catchpoint (&c->base, gdbarch, is_temp, NULL,
8397 
8398  c->base.enable_state = enabled ? bp_enabled : bp_disabled;
8399 
8400  discard_cleanups (cleanup);
8401  install_breakpoint (0, &c->base, 1);
8402 }
8403 
8404 /* A helper function that does all the work for "catch load" and
8405  "catch unload". */
8406 
8407 static void
8408 catch_load_or_unload (char *arg, int from_tty, int is_load,
8409  struct cmd_list_element *command)
8410 {
8411  int tempflag;
8412  const int enabled = 1;
8413 
8414  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8415 
8416  add_solib_catchpoint (arg, is_load, tempflag, enabled);
8417 }
8418 
8419 static void
8420 catch_load_command_1 (char *arg, int from_tty,
8421  struct cmd_list_element *command)
8422 {
8423  catch_load_or_unload (arg, from_tty, 1, command);
8424 }
8425 
8426 static void
8427 catch_unload_command_1 (char *arg, int from_tty,
8428  struct cmd_list_element *command)
8429 {
8430  catch_load_or_unload (arg, from_tty, 0, command);
8431 }
8432 
8433 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8434  is non-zero, then make the breakpoint temporary. If COND_STRING is
8435  not NULL, then store it in the breakpoint. OPS, if not NULL, is
8436  the breakpoint_ops structure associated to the catchpoint. */
8437 
8438 void
8440  struct gdbarch *gdbarch, int tempflag,
8441  char *cond_string,
8442  const struct breakpoint_ops *ops)
8443 {
8444  struct symtab_and_line sal;
8445 
8446  init_sal (&sal);
8448 
8449  init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
8450 
8451  b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
8452  b->disposition = tempflag ? disp_del : disp_donttouch;
8453 }
8454 
8455 void
8456 install_breakpoint (int internal, struct breakpoint *b, int update_gll)
8457 {
8459  set_breakpoint_number (internal, b);
8460  if (is_tracepoint (b))
8461  set_tracepoint_count (breakpoint_count);
8462  if (!internal)
8463  mention (b);
8465 
8466  if (update_gll)
8468 }
8469 
8470 static void
8472  int tempflag, char *cond_string,
8473  const struct breakpoint_ops *ops)
8474 {
8475  struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
8476 
8477  init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8478 
8480 
8481  install_breakpoint (0, &c->base, 1);
8482 }
8483 
8484 /* Exec catchpoints. */
8485 
8486 /* An instance of this type is used to represent an exec catchpoint.
8487  It includes a "struct breakpoint" as a kind of base class; users
8488  downcast to "struct breakpoint *" when needed. A breakpoint is
8489  really of this type iff its ops pointer points to
8490  CATCH_EXEC_BREAKPOINT_OPS. */
8491 
8493 {
8494  /* The base class. */
8496 
8497  /* Filename of a program whose exec triggered this catchpoint.
8498  This field is only valid immediately after this catchpoint has
8499  triggered. */
8501 };
8502 
8503 /* Implement the "dtor" breakpoint_ops method for exec
8504  catchpoints. */
8505 
8506 static void
8508 {
8509  struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8510 
8511  xfree (c->exec_pathname);
8512 
8513  base_breakpoint_ops.dtor (b);
8514 }
8515 
8516 static int
8517 insert_catch_exec (struct bp_location *bl)
8518 {
8520 }
8521 
8522 static int
8523 remove_catch_exec (struct bp_location *bl)
8524 {
8526 }
8527 
8528 static int
8529 breakpoint_hit_catch_exec (const struct bp_location *bl,
8530  struct address_space *aspace, CORE_ADDR bp_addr,
8531  const struct target_waitstatus *ws)
8532 {
8533  struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8534 
8535  if (ws->kind != TARGET_WAITKIND_EXECD)
8536  return 0;
8537 
8538  c->exec_pathname = xstrdup (ws->value.execd_pathname);
8539  return 1;
8540 }
8541 
8542 static enum print_stop_action
8544 {
8545  struct ui_out *uiout = current_uiout;
8546  struct breakpoint *b = bs->breakpoint_at;
8547  struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8548 
8550  if (b->disposition == disp_del)
8551  ui_out_text (uiout, "\nTemporary catchpoint ");
8552  else
8553  ui_out_text (uiout, "\nCatchpoint ");
8554  if (ui_out_is_mi_like_p (uiout))
8555  {
8556  ui_out_field_string (uiout, "reason",
8558  ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8559  }
8560  ui_out_field_int (uiout, "bkptno", b->number);
8561  ui_out_text (uiout, " (exec'd ");
8562  ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8563  ui_out_text (uiout, "), ");
8564 
8565  return PRINT_SRC_AND_LOC;
8566 }
8567 
8568 static void
8569 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
8570 {
8571  struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8572  struct value_print_options opts;
8573  struct ui_out *uiout = current_uiout;
8574 
8575  get_user_print_options (&opts);
8576 
8577  /* Field 4, the address, is omitted (which makes the columns
8578  not line up too nicely with the headers, but the effect
8579  is relatively readable). */
8580  if (opts.addressprint)
8581  ui_out_field_skip (uiout, "addr");
8582  annotate_field (5);
8583  ui_out_text (uiout, "exec");
8584  if (c->exec_pathname != NULL)
8585  {
8586  ui_out_text (uiout, ", program \"");
8587  ui_out_field_string (uiout, "what", c->exec_pathname);
8588  ui_out_text (uiout, "\" ");
8589  }
8590 
8591  if (ui_out_is_mi_like_p (uiout))
8592  ui_out_field_string (uiout, "catch-type", "exec");
8593 }
8594 
8595 static void
8597 {
8598  printf_filtered (_("Catchpoint %d (exec)"), b->number);
8599 }
8600 
8601 /* Implement the "print_recreate" breakpoint_ops method for exec
8602  catchpoints. */
8603 
8604 static void
8606 {
8607  fprintf_unfiltered (fp, "catch exec");
8608  print_recreate_thread (b, fp);
8609 }
8610 
8612 
8613 static int
8615 {
8616  int i = 0;
8617  struct breakpoint *b;
8618  struct bp_location *bl;
8619 
8620  ALL_BREAKPOINTS (b)
8621  {
8623  for (bl = b->loc; bl; bl = bl->next)
8624  {
8625  /* Special types of hardware breakpoints may use more than
8626  one register. */
8627  i += b->ops->resources_needed (bl);
8628  }
8629  }
8630 
8631  return i;
8632 }
8633 
8634 /* Returns the resources B would use if it were a hardware
8635  watchpoint. */
8636 
8637 static int
8639 {
8640  int i = 0;
8641  struct bp_location *bl;
8642 
8643  if (!breakpoint_enabled (b))
8644  return 0;
8645 
8646  for (bl = b->loc; bl; bl = bl->next)
8647  {
8648  /* Special types of hardware watchpoints may use more than
8649  one register. */
8650  i += b->ops->resources_needed (bl);
8651  }
8652 
8653  return i;
8654 }
8655 
8656 /* Returns the sum the used resources of all hardware watchpoints of
8657  type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8658  the sum of the used resources of all hardware watchpoints of other
8659  types _not_ TYPE. */
8660 
8661 static int
8663  enum bptype type, int *other_type_used)
8664 {
8665  int i = 0;
8666  struct breakpoint *b;
8667 
8668  *other_type_used = 0;
8669  ALL_BREAKPOINTS (b)
8670  {
8671  if (b == except)
8672  continue;
8673  if (!breakpoint_enabled (b))
8674  continue;
8675 
8676  if (b->type == type)
8677  i += hw_watchpoint_use_count (b);
8678  else if (is_hardware_watchpoint (b))
8679  *other_type_used = 1;
8680  }
8681 
8682  return i;
8683 }
8684 
8685 void
8687 {
8688  struct breakpoint *b;
8689 
8690  ALL_BREAKPOINTS (b)
8691  {
8692  if (is_watchpoint (b) && breakpoint_enabled (b))
8693  {
8696  }
8697  }
8698 }
8699 
8700 void
8702 {
8703  struct breakpoint *b;
8704 
8705  ALL_BREAKPOINTS (b)
8706  {
8707  if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
8708  {
8709  b->enable_state = bp_enabled;
8711  }
8712  }
8713 }
8714 
8715 void
8717 {
8720 }
8721 
8722 void
8724 {
8726  breakpoint_re_set ();
8727 }
8728 
8729 /* Create a new single-step breakpoint for thread THREAD, with no
8730  locations. */
8731 
8732 static struct breakpoint *
8734 {
8735  struct breakpoint *b = XNEW (struct breakpoint);
8736 
8739 
8741  b->frame_id = null_frame_id;
8742 
8743  b->thread = thread;
8744  gdb_assert (b->thread != 0);
8745 
8747 
8748  return b;
8749 }
8750 
8751 /* Set a momentary breakpoint of type TYPE at address specified by
8752  SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8753  frame. */
8754 
8755 struct breakpoint *
8757  struct frame_id frame_id, enum bptype type)
8758 {
8759  struct breakpoint *b;
8760 
8761  /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8762  tail-called one. */
8763  gdb_assert (!frame_id_artificial_p (frame_id));
8764 
8765  b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
8766  b->enable_state = bp_enabled;
8768  b->frame_id = frame_id;
8769 
8770  /* If we're debugging a multi-threaded program, then we want
8771  momentary breakpoints to be active in only a single thread of
8772  control. */
8775 
8777 
8778  return b;
8779 }
8780 
8781 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8782  The new breakpoint will have type TYPE, use OPS as its
8783  breakpoint_ops, and will set enabled to LOC_ENABLED. */
8784 
8785 static struct breakpoint *
8787  enum bptype type,
8788  const struct breakpoint_ops *ops,
8789  int loc_enabled)
8790 {
8791  struct breakpoint *copy;
8792 
8793  copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
8794  copy->loc = allocate_bp_location (copy);
8796 
8797  copy->loc->gdbarch = orig->loc->gdbarch;
8798  copy->loc->requested_address = orig->loc->requested_address;
8799  copy->loc->address = orig->loc->address;
8800  copy->loc->section = orig->loc->section;
8801  copy->loc->pspace = orig->loc->pspace;
8802  copy->loc->probe = orig->loc->probe;
8803  copy->loc->line_number = orig->loc->line_number;
8804  copy->loc->symtab = orig->loc->symtab;
8805  copy->loc->enabled = loc_enabled;
8806  copy->frame_id = orig->frame_id;
8807  copy->thread = orig->thread;
8808  copy->pspace = orig->pspace;
8809 
8810  copy->enable_state = bp_enabled;
8811  copy->disposition = disp_donttouch;
8812  copy->number = internal_breakpoint_number--;
8813 
8815  return copy;
8816 }
8817 
8818 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8819  ORIG is NULL. */
8820 
8821 struct breakpoint *
8823 {
8824  /* If there's nothing to clone, then return nothing. */
8825  if (orig == NULL)
8826  return NULL;
8827 
8828  return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
8829 }
8830 
8831 struct breakpoint *
8833  enum bptype type)
8834 {
8835  struct symtab_and_line sal;
8836 
8837  sal = find_pc_line (pc, 0);
8838  sal.pc = pc;
8839  sal.section = find_pc_overlay (pc);
8840  sal.explicit_pc = 1;
8841 
8842  return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
8843 }
8844 
8845 
8846 /* Tell the user we have just set a breakpoint B. */
8847 
8848 static void
8849 mention (struct breakpoint *b)
8850 {
8851  b->ops->print_mention (b);
8853  return;
8854  printf_filtered ("\n");
8855 }
8856 
8857 
8858 static int bp_loc_is_permanent (struct bp_location *loc);
8859 
8860 static struct bp_location *
8862  const struct symtab_and_line *sal)
8863 {
8864  struct bp_location *loc, **tmp;
8865  CORE_ADDR adjusted_address;
8866  struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8867 
8868  if (loc_gdbarch == NULL)
8869  loc_gdbarch = b->gdbarch;
8870 
8871  /* Adjust the breakpoint's address prior to allocating a location.
8872  Once we call allocate_bp_location(), that mostly uninitialized
8873  location will be placed on the location chain. Adjustment of the
8874  breakpoint may cause target_read_memory() to be called and we do
8875  not want its scan of the location chain to find a breakpoint and
8876  location that's only been partially initialized. */
8877  adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8878  sal->pc, b->type);
8879 
8880  /* Sort the locations by their ADDRESS. */
8881  loc = allocate_bp_location (b);
8882  for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8883  tmp = &((*tmp)->next))
8884  ;
8885  loc->next = *tmp;
8886  *tmp = loc;
8887 
8888  loc->requested_address = sal->pc;
8889  loc->address = adjusted_address;
8890  loc->pspace = sal->pspace;
8891  loc->probe.probe = sal->probe;
8892  loc->probe.objfile = sal->objfile;
8893  gdb_assert (loc->pspace != NULL);
8894  loc->section = sal->section;
8895  loc->gdbarch = loc_gdbarch;
8896  loc->line_number = sal->line;
8897  loc->symtab = sal->symtab;
8898 
8900  sal->explicit_pc || sal->explicit_line);
8901 
8902  /* While by definition, permanent breakpoints are already present in the
8903  code, we don't mark the location as inserted. Normally one would expect
8904  that GDB could rely on that breakpoint instruction to stop the program,
8905  thus removing the need to insert its own breakpoint, except that executing
8906  the breakpoint instruction can kill the target instead of reporting a
8907  SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8908  instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8909  with "Trap 0x02 while interrupts disabled, Error state". Letting the
8910  breakpoint be inserted normally results in QEMU knowing about the GDB
8911  breakpoint, and thus trap before the breakpoint instruction is executed.
8912  (If GDB later needs to continue execution past the permanent breakpoint,
8913  it manually increments the PC, thus avoiding executing the breakpoint
8914  instruction.) */
8915  if (bp_loc_is_permanent (loc))
8916  loc->permanent = 1;
8917 
8918  return loc;
8919 }
8920 
8921 
8922 /* See breakpoint.h. */
8923 
8924 int
8926 {
8927  int len;
8928  CORE_ADDR addr;
8929  const gdb_byte *bpoint;
8930  gdb_byte *target_mem;
8931  struct cleanup *cleanup;
8932  int retval = 0;
8933 
8934  addr = address;
8935  bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
8936 
8937  /* Software breakpoints unsupported? */
8938  if (bpoint == NULL)
8939  return 0;
8940 
8941  target_mem = alloca (len);
8942 
8943  /* Enable the automatic memory restoration from breakpoints while
8944  we read the memory. Otherwise we could say about our temporary
8945  breakpoints they are permanent. */
8947 
8948  if (target_read_memory (address, target_mem, len) == 0
8949  && memcmp (target_mem, bpoint, len) == 0)
8950  retval = 1;
8951 
8952  do_cleanups (cleanup);
8953 
8954  return retval;
8955 }
8956 
8957 /* Return 1 if LOC is pointing to a permanent breakpoint,
8958  return 0 otherwise. */
8959 
8960 static int
8961 bp_loc_is_permanent (struct bp_location *loc)
8962 {
8963  struct cleanup *cleanup;
8964  int retval;
8965 
8966  gdb_assert (loc != NULL);
8967 
8968  /* If we have a catchpoint or a watchpoint, just return 0. We should not
8969  attempt to read from the addresses the locations of these breakpoint types
8970  point to. program_breakpoint_here_p, below, will attempt to read
8971  memory. */
8973  return 0;
8974 
8975  cleanup = save_current_space_and_thread ();
8977 
8978  retval = program_breakpoint_here_p (loc->gdbarch, loc->address);
8979 
8980  do_cleanups (cleanup);
8981 
8982  return retval;
8983 }
8984 
8985 /* Build a command list for the dprintf corresponding to the current
8986  settings of the dprintf style options. */
8987 
8988 static void
8990 {
8991  char *dprintf_args = b->extra_string;
8992  char *printf_line = NULL;
8993 
8994  if (!dprintf_args)
8995  return;
8996 
8997  dprintf_args = skip_spaces (dprintf_args);
8998 
8999  /* Allow a comma, as it may have terminated a location, but don't
9000  insist on it. */
9001  if (*dprintf_args == ',')
9002  ++dprintf_args;
9003  dprintf_args = skip_spaces (dprintf_args);
9004 
9005  if (*dprintf_args != '"')
9006  error (_("Bad format string, missing '\"'."));
9007 
9008  if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
9009  printf_line = xstrprintf ("printf %s", dprintf_args);
9010  else if (strcmp (dprintf_style, dprintf_style_call) == 0)
9011  {
9012  if (!dprintf_function)
9013  error (_("No function supplied for dprintf call"));
9014 
9015  if (dprintf_channel && strlen (dprintf_channel) > 0)
9016  printf_line = xstrprintf ("call (void) %s (%s,%s)",
9017  dprintf_function,
9018  dprintf_channel,
9019  dprintf_args);
9020  else
9021  printf_line = xstrprintf ("call (void) %s (%s)",
9022  dprintf_function,
9023  dprintf_args);
9024  }
9025  else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
9026  {
9028  printf_line = xstrprintf ("agent-printf %s", dprintf_args);
9029  else
9030  {
9031  warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9032  printf_line = xstrprintf ("printf %s", dprintf_args);
9033  }
9034  }
9035  else
9036  internal_error (__FILE__, __LINE__,
9037  _("Invalid dprintf style."));
9038 
9039  gdb_assert (printf_line != NULL);
9040  /* Manufacture a printf sequence. */
9041  {
9042  struct command_line *printf_cmd_line
9043  = xmalloc (sizeof (struct command_line));
9044 
9045  printf_cmd_line->control_type = simple_control;
9046  printf_cmd_line->body_count = 0;
9047  printf_cmd_line->body_list = NULL;
9048  printf_cmd_line->next = NULL;
9049  printf_cmd_line->line = printf_line;
9050 
9051  breakpoint_set_commands (b, printf_cmd_line);
9052  }
9053 }
9054 
9055 /* Update all dprintf commands, making their command lists reflect
9056  current style settings. */
9057 
9058 static void
9059 update_dprintf_commands (char *args, int from_tty,
9060  struct cmd_list_element *c)
9061 {
9062  struct breakpoint *b;
9063 
9064  ALL_BREAKPOINTS (b)
9065  {
9066  if (b->type == bp_dprintf)
9068  }
9069 }
9070 
9071 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9072  as textual description of the location, and COND_STRING
9073  as condition expression. */
9074 
9075 static void
9077  struct symtabs_and_lines sals, char *addr_string,
9078  char *filter, char *cond_string,
9079  char *extra_string,
9080  enum bptype type, enum bpdisp disposition,
9081  int thread, int task, int ignore_count,
9082  const struct breakpoint_ops *ops, int from_tty,
9083  int enabled, int internal, unsigned flags,
9084  int display_canonical)
9085 {
9086  int i;
9087 
9088  if (type == bp_hardware_breakpoint)
9089  {
9090  int target_resources_ok;
9091 
9092  i = hw_breakpoint_used_count ();
9093  target_resources_ok =
9095  i + 1, 0);
9096  if (target_resources_ok == 0)
9097  error (_("No hardware breakpoint support in the target."));
9098  else if (target_resources_ok < 0)
9099  error (_("Hardware breakpoints used exceeds limit."));
9100  }
9101 
9102  gdb_assert (sals.nelts > 0);
9103 
9104  for (i = 0; i < sals.nelts; ++i)
9105  {
9106  struct symtab_and_line sal = sals.sals[i];
9107  struct bp_location *loc;
9108 
9109  if (from_tty)
9110  {
9111  struct gdbarch *loc_gdbarch = get_sal_arch (sal);
9112  if (!loc_gdbarch)
9113  loc_gdbarch = gdbarch;
9114 
9115  describe_other_breakpoints (loc_gdbarch,
9116  sal.pspace, sal.pc, sal.section, thread);
9117  }
9118 
9119  if (i == 0)
9120  {
9121  init_raw_breakpoint (b, gdbarch, sal, type, ops);
9122  b->thread = thread;
9123  b->task = task;
9124 
9125  b->cond_string = cond_string;
9126  b->extra_string = extra_string;
9127  b->ignore_count = ignore_count;
9128  b->enable_state = enabled ? bp_enabled : bp_disabled;
9129  b->disposition = disposition;
9130 
9131  if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9132  b->loc->inserted = 1;
9133 
9134  if (type == bp_static_tracepoint)
9135  {
9136  struct tracepoint *t = (struct tracepoint *) b;
9137  struct static_tracepoint_marker marker;
9138 
9139  if (strace_marker_p (b))
9140  {
9141  /* We already know the marker exists, otherwise, we
9142  wouldn't see a sal for it. */
9143  char *p = &addr_string[3];
9144  char *endp;
9145  char *marker_str;
9146 
9147  p = skip_spaces (p);
9148 
9149  endp = skip_to_space (p);
9150 
9151  marker_str = savestring (p, endp - p);
9152  t->static_trace_marker_id = marker_str;
9153 
9154  printf_filtered (_("Probed static tracepoint "
9155  "marker \"%s\"\n"),
9157  }
9158  else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9159  {
9160  t->static_trace_marker_id = xstrdup (marker.str_id);
9162 
9163  printf_filtered (_("Probed static tracepoint "
9164  "marker \"%s\"\n"),
9166  }
9167  else
9168  warning (_("Couldn't determine the static "
9169  "tracepoint marker to probe"));
9170  }
9171 
9172  loc = b->loc;
9173  }
9174  else
9175  {
9176  loc = add_location_to_breakpoint (b, &sal);
9177  if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9178  loc->inserted = 1;
9179  }
9180 
9181  if (b->cond_string)
9182  {
9183  const char *arg = b->cond_string;
9184 
9185  loc->cond = parse_exp_1 (&arg, loc->address,
9186  block_for_pc (loc->address), 0);
9187  if (*arg)
9188  error (_("Garbage '%s' follows condition"), arg);
9189  }
9190 
9191  /* Dynamic printf requires and uses additional arguments on the
9192  command line, otherwise it's an error. */
9193  if (type == bp_dprintf)
9194  {
9195  if (b->extra_string)
9197  else
9198  error (_("Format string required"));
9199  }
9200  else if (b->extra_string)
9201  error (_("Garbage '%s' at end of command"), b->extra_string);
9202  }
9203 
9204  b->display_canonical = display_canonical;
9205  if (addr_string)
9206  b->addr_string = addr_string;
9207  else
9208  /* addr_string has to be used or breakpoint_re_set will delete
9209  me. */
9210  b->addr_string
9211  = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9212  b->filter = filter;
9213 }
9214 
9215 static void
9217  struct symtabs_and_lines sals, char *addr_string,
9218  char *filter, char *cond_string,
9219  char *extra_string,
9220  enum bptype type, enum bpdisp disposition,
9221  int thread, int task, int ignore_count,
9222  const struct breakpoint_ops *ops, int from_tty,
9223  int enabled, int internal, unsigned flags,
9224  int display_canonical)
9225 {
9226  struct breakpoint *b;
9227  struct cleanup *old_chain;
9228 
9229  if (is_tracepoint_type (type))
9230  {
9231  struct tracepoint *t;
9232 
9233  t = XCNEW (struct tracepoint);
9234  b = &t->base;
9235  }
9236  else
9237  b = XNEW (struct breakpoint);
9238 
9239  old_chain = make_cleanup (xfree, b);
9240 
9241  init_breakpoint_sal (b, gdbarch,
9242  sals, addr_string,
9243  filter, cond_string, extra_string,
9244  type, disposition,
9245  thread, task, ignore_count,
9246  ops, from_tty,
9247  enabled, internal, flags,
9248  display_canonical);
9249  discard_cleanups (old_chain);
9250 
9251  install_breakpoint (internal, b, 0);
9252 }
9253 
9254 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9255  SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9256  value. COND_STRING, if not NULL, specified the condition to be
9257  used for all breakpoints. Essentially the only case where
9258  SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9259  function. In that case, it's still not possible to specify
9260  separate conditions for different overloaded functions, so
9261  we take just a single condition string.
9262 
9263  NOTE: If the function succeeds, the caller is expected to cleanup
9264  the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9265  array contents). If the function fails (error() is called), the
9266  caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9267  COND and SALS arrays and each of those arrays contents. */
9268 
9269 static void
9271  struct linespec_result *canonical,
9272  char *cond_string, char *extra_string,
9273  enum bptype type, enum bpdisp disposition,
9274  int thread, int task, int ignore_count,
9275  const struct breakpoint_ops *ops, int from_tty,
9276  int enabled, int internal, unsigned flags)
9277 {
9278  int i;
9279  struct linespec_sals *lsal;
9280 
9281  if (canonical->pre_expanded)
9282  gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9283 
9284  for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
9285  {
9286  /* Note that 'addr_string' can be NULL in the case of a plain
9287  'break', without arguments. */
9288  char *addr_string = (canonical->addr_string
9289  ? xstrdup (canonical->addr_string)
9290  : NULL);
9291  char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9292  struct cleanup *inner = make_cleanup (xfree, addr_string);
9293 
9294  make_cleanup (xfree, filter_string);
9295  create_breakpoint_sal (gdbarch, lsal->sals,
9296  addr_string,
9297  filter_string,
9298  cond_string, extra_string,
9299  type, disposition,
9300  thread, task, ignore_count, ops,
9301  from_tty, enabled, internal, flags,
9302  canonical->special_display);
9303  discard_cleanups (inner);
9304  }
9305 }
9306 
9307 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9308  followed by conditionals. On return, SALS contains an array of SAL
9309  addresses found. ADDR_STRING contains a vector of (canonical)
9310  address strings. ADDRESS points to the end of the SAL.
9311 
9312  The array and the line spec strings are allocated on the heap, it is
9313  the caller's responsibility to free them. */
9314 
9315 static void
9316 parse_breakpoint_sals (char **address,
9317  struct linespec_result *canonical)
9318 {
9319  /* If no arg given, or if first arg is 'if ', use the default
9320  breakpoint. */
9321  if ((*address) == NULL || linespec_lexer_lex_keyword (*address))
9322  {
9323  /* The last displayed codepoint, if it's valid, is our default breakpoint
9324  address. */
9326  {
9327  struct linespec_sals lsal;
9328  struct symtab_and_line sal;
9329  CORE_ADDR pc;
9330 
9331  init_sal (&sal); /* Initialize to zeroes. */
9332  lsal.sals.sals = (struct symtab_and_line *)
9333  xmalloc (sizeof (struct symtab_and_line));
9334 
9335  /* Set sal's pspace, pc, symtab, and line to the values
9336  corresponding to the last call to print_frame_info.
9337  Be sure to reinitialize LINE with NOTCURRENT == 0
9338  as the breakpoint line number is inappropriate otherwise.
9339  find_pc_line would adjust PC, re-set it back. */
9340  get_last_displayed_sal (&sal);
9341  pc = sal.pc;
9342  sal = find_pc_line (pc, 0);
9343 
9344  /* "break" without arguments is equivalent to "break *PC"
9345  where PC is the last displayed codepoint's address. So
9346  make sure to set sal.explicit_pc to prevent GDB from
9347  trying to expand the list of sals to include all other
9348  instances with the same symtab and line. */
9349  sal.pc = pc;
9350  sal.explicit_pc = 1;
9351 
9352  lsal.sals.sals[0] = sal;
9353  lsal.sals.nelts = 1;
9354  lsal.canonical = NULL;
9355 
9356  VEC_safe_push (linespec_sals, canonical->sals, &lsal);
9357  }
9358  else
9359  error (_("No default breakpoint address now."));
9360  }
9361  else
9362  {
9364 
9365  /* Force almost all breakpoints to be in terms of the
9366  current_source_symtab (which is decode_line_1's default).
9367  This should produce the results we want almost all of the
9368  time while leaving default_breakpoint_* alone.
9369 
9370  ObjC: However, don't match an Objective-C method name which
9371  may have a '+' or '-' succeeded by a '['. */
9373  && (!cursal.symtab
9374  || ((strchr ("+-", (*address)[0]) != NULL)
9375  && ((*address)[1] != '['))))
9379  canonical, NULL, NULL);
9380  else
9382  cursal.symtab, cursal.line, canonical, NULL, NULL);
9383  }
9384 }
9385 
9386 
9387 /* Convert each SAL into a real PC. Verify that the PC can be
9388  inserted as a breakpoint. If it can't throw an error. */
9389 
9390 static void
9392 {
9393  int i;
9394 
9395  for (i = 0; i < sals->nelts; i++)
9396  resolve_sal_pc (&sals->sals[i]);
9397 }
9398 
9399 /* Fast tracepoints may have restrictions on valid locations. For
9400  instance, a fast tracepoint using a jump instead of a trap will
9401  likely have to overwrite more bytes than a trap would, and so can
9402  only be placed where the instruction is longer than the jump, or a
9403  multi-instruction sequence does not have a jump into the middle of
9404  it, etc. */
9405 
9406 static void
9408  struct symtabs_and_lines *sals)
9409 {
9410  int i, rslt;
9411  struct symtab_and_line *sal;
9412  char *msg;
9413  struct cleanup *old_chain;
9414 
9415  for (i = 0; i < sals->nelts; i++)
9416  {
9417  struct gdbarch *sarch;
9418 
9419  sal = &sals->sals[i];
9420 
9421  sarch = get_sal_arch (*sal);
9422  /* We fall back to GDBARCH if there is no architecture
9423  associated with SAL. */
9424  if (sarch == NULL)
9425  sarch = gdbarch;
9426  rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9427  NULL, &msg);
9428  old_chain = make_cleanup (xfree, msg);
9429 
9430  if (!rslt)
9431  error (_("May not have a fast tracepoint at 0x%s%s"),
9432  paddress (sarch, sal->pc), (msg ? msg : ""));
9433 
9434  do_cleanups (old_chain);
9435  }
9436 }
9437 
9438 /* Issue an invalid thread ID error. */
9439 
9440 static void ATTRIBUTE_NORETURN
9442 {
9443  error (_("Unknown thread %d."), id);
9444 }
9445 
9446 /* Given TOK, a string specification of condition and thread, as
9447  accepted by the 'break' command, extract the condition
9448  string and thread number and set *COND_STRING and *THREAD.
9449  PC identifies the context at which the condition should be parsed.
9450  If no condition is found, *COND_STRING is set to NULL.
9451  If no thread is found, *THREAD is set to -1. */
9452 
9453 static void
9455  char **cond_string, int *thread, int *task,
9456  char **rest)
9457 {
9458  *cond_string = NULL;
9459  *thread = -1;
9460  *task = 0;
9461  *rest = NULL;
9462 
9463  while (tok && *tok)
9464  {
9465  const char *end_tok;
9466  int toklen;
9467  const char *cond_start = NULL;
9468  const char *cond_end = NULL;
9469 
9470  tok = skip_spaces_const (tok);
9471 
9472  if ((*tok == '"' || *tok == ',') && rest)
9473  {
9474  *rest = savestring (tok, strlen (tok));
9475  return;
9476  }
9477 
9478  end_tok = skip_to_space_const (tok);
9479 
9480  toklen = end_tok - tok;
9481 
9482  if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
9483  {
9484  struct expression *expr;
9485 
9486  tok = cond_start = end_tok + 1;
9487  expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
9488  xfree (expr);
9489  cond_end = tok;
9490  *cond_string = savestring (cond_start, cond_end - cond_start);
9491  }
9492  else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
9493  {
9494  char *tmptok;
9495 
9496  tok = end_tok + 1;
9497  *thread = strtol (tok, &tmptok, 0);
9498  if (tok == tmptok)
9499  error (_("Junk after thread keyword."));
9500  if (!valid_thread_id (*thread))
9501  invalid_thread_id_error (*thread);
9502  tok = tmptok;
9503  }
9504  else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
9505  {
9506  char *tmptok;
9507 
9508  tok = end_tok + 1;
9509  *task = strtol (tok, &tmptok, 0);
9510  if (tok == tmptok)
9511  error (_("Junk after task keyword."));
9512  if (!valid_task_id (*task))
9513  error (_("Unknown task %d."), *task);
9514  tok = tmptok;
9515  }
9516  else if (rest)
9517  {
9518  *rest = savestring (tok, strlen (tok));
9519  return;
9520  }
9521  else
9522  error (_("Junk at end of arguments."));
9523  }
9524 }
9525 
9526 /* Decode a static tracepoint marker spec. */
9527 
9528 static struct symtabs_and_lines
9530 {
9531  VEC(static_tracepoint_marker_p) *markers = NULL;
9532  struct symtabs_and_lines sals;
9533  struct cleanup *old_chain;
9534  char *p = &(*arg_p)[3];
9535  char *endp;
9536  char *marker_str;
9537  int i;
9538 
9539  p = skip_spaces (p);
9540 
9541  endp = skip_to_space (p);
9542 
9543  marker_str = savestring (p, endp - p);
9544  old_chain = make_cleanup (xfree, marker_str);
9545 
9546  markers = target_static_tracepoint_markers_by_strid (marker_str);
9547  if (VEC_empty(static_tracepoint_marker_p, markers))
9548  error (_("No known static tracepoint marker named %s"), marker_str);
9549 
9550  sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9551  sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9552 
9553  for (i = 0; i < sals.nelts; i++)
9554  {
9555  struct static_tracepoint_marker *marker;
9556 
9557  marker = VEC_index (static_tracepoint_marker_p, markers, i);
9558 
9559  init_sal (&sals.sals[i]);
9560 
9561  sals.sals[i] = find_pc_line (marker->address, 0);
9562  sals.sals[i].pc = marker->address;
9563 
9565  }
9566 
9567  do_cleanups (old_chain);
9568 
9569  *arg_p = endp;
9570  return sals;
9571 }
9572 
9573 /* Set a breakpoint. This function is shared between CLI and MI
9574  functions for setting a breakpoint. This function has two major
9575  modes of operations, selected by the PARSE_ARG parameter. If
9576  non-zero, the function will parse ARG, extracting location,
9577  condition, thread and extra string. Otherwise, ARG is just the
9578  breakpoint's location, with condition, thread, and extra string
9579  specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9580  If INTERNAL is non-zero, the breakpoint number will be allocated
9581  from the internal breakpoint count. Returns true if any breakpoint
9582  was created; false otherwise. */
9583 
9584 int
9586  char *arg, char *cond_string,
9587  int thread, char *extra_string,
9588  int parse_arg,
9589  int tempflag, enum bptype type_wanted,
9590  int ignore_count,
9591  enum auto_boolean pending_break_support,
9592  const struct breakpoint_ops *ops,
9593  int from_tty, int enabled, int internal,
9594  unsigned flags)
9595 {
9596  char *copy_arg = NULL;
9597  char *addr_start = arg;
9598  struct linespec_result canonical;
9599  struct cleanup *old_chain;
9600  struct cleanup *bkpt_chain = NULL;
9601  int pending = 0;
9602  int task = 0;
9603  int prev_bkpt_count = breakpoint_count;
9604 
9605  gdb_assert (ops != NULL);
9606 
9607  init_linespec_result (&canonical);
9608 
9609  TRY
9610  {
9611  ops->create_sals_from_address (&arg, &canonical, type_wanted,
9612  addr_start, &copy_arg);
9613  }
9615  {
9616  /* If caller is interested in rc value from parse, set
9617  value. */
9618  if (e.error == NOT_FOUND_ERROR)
9619  {
9620  /* If pending breakpoint support is turned off, throw
9621  error. */
9622 
9623  if (pending_break_support == AUTO_BOOLEAN_FALSE)
9624  throw_exception (e);
9625 
9627 
9628  /* If pending breakpoint support is auto query and the user
9629  selects no, then simply return the error code. */
9630  if (pending_break_support == AUTO_BOOLEAN_AUTO
9631  && !nquery (_("Make %s pending on future shared library load? "),
9632  bptype_string (type_wanted)))
9633  return 0;
9634 
9635  /* At this point, either the user was queried about setting
9636  a pending breakpoint and selected yes, or pending
9637  breakpoint behavior is on and thus a pending breakpoint
9638  is defaulted on behalf of the user. */
9639  {
9640  struct linespec_sals lsal;
9641 
9642  copy_arg = xstrdup (addr_start);
9643  lsal.canonical = xstrdup (copy_arg);
9644  lsal.sals.nelts = 1;
9645  lsal.sals.sals = XNEW (struct symtab_and_line);
9646  init_sal (&lsal.sals.sals[0]);
9647  pending = 1;
9648  VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9649  }
9650  }
9651  else
9652  throw_exception (e);
9653  }
9654  END_CATCH
9655 
9656  if (VEC_empty (linespec_sals, canonical.sals))
9657  return 0;
9658 
9659  /* Create a chain of things that always need to be cleaned up. */
9660  old_chain = make_cleanup_destroy_linespec_result (&canonical);
9661 
9662  /* ----------------------------- SNIP -----------------------------
9663  Anything added to the cleanup chain beyond this point is assumed
9664  to be part of a breakpoint. If the breakpoint create succeeds
9665  then the memory is not reclaimed. */
9666  bkpt_chain = make_cleanup (null_cleanup, 0);
9667 
9668  /* Resolve all line numbers to PC's and verify that the addresses
9669  are ok for the target. */
9670  if (!pending)
9671  {
9672  int ix;
9673  struct linespec_sals *iter;
9674 
9675  for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9676  breakpoint_sals_to_pc (&iter->sals);
9677  }
9678 
9679  /* Fast tracepoints may have additional restrictions on location. */
9680  if (!pending && type_wanted == bp_fast_tracepoint)
9681  {
9682  int ix;
9683  struct linespec_sals *iter;
9684 
9685  for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9686  check_fast_tracepoint_sals (gdbarch, &iter->sals);
9687  }
9688 
9689  /* Verify that condition can be parsed, before setting any
9690  breakpoints. Allocate a separate condition expression for each
9691  breakpoint. */
9692  if (!pending)
9693  {
9694  if (parse_arg)
9695  {
9696  char *rest;
9697  struct linespec_sals *lsal;
9698 
9699  lsal = VEC_index (linespec_sals, canonical.sals, 0);
9700 
9701  /* Here we only parse 'arg' to separate condition
9702  from thread number, so parsing in context of first
9703  sal is OK. When setting the breakpoint we'll
9704  re-parse it in context of each sal. */
9705 
9706  find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9707  &thread, &task, &rest);
9708  if (cond_string)
9709  make_cleanup (xfree, cond_string);
9710  if (rest)
9711  make_cleanup (xfree, rest);
9712  if (rest)
9713  extra_string = rest;
9714  }
9715  else
9716  {
9717  if (*arg != '\0')
9718  error (_("Garbage '%s' at end of location"), arg);
9719 
9720  /* Create a private copy of condition string. */
9721  if (cond_string)
9722  {
9723  cond_string = xstrdup (cond_string);
9724  make_cleanup (xfree, cond_string);
9725  }
9726  /* Create a private copy of any extra string. */
9727  if (extra_string)
9728  {
9729  extra_string = xstrdup (extra_string);
9730  make_cleanup (xfree, extra_string);
9731  }
9732  }
9733 
9734  ops->create_breakpoints_sal (gdbarch, &canonical,
9735  cond_string, extra_string, type_wanted,
9736  tempflag ? disp_del : disp_donttouch,
9737  thread, task, ignore_count, ops,
9738  from_tty, enabled, internal, flags);
9739  }
9740  else
9741  {
9742  struct breakpoint *b;
9743 
9744  make_cleanup (xfree, copy_arg);
9745 
9746  if (is_tracepoint_type (type_wanted))
9747  {
9748  struct tracepoint *t;
9749 
9750  t = XCNEW (struct tracepoint);
9751  b = &t->base;
9752  }
9753  else
9754  b = XNEW (struct breakpoint);
9755 
9756  init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9757 
9758  b->addr_string = copy_arg;
9759  if (parse_arg)
9760  {
9761  b->cond_string = NULL;
9762  b->extra_string = NULL;
9763  }
9764  else
9765  {
9766  /* Create a private copy of condition string. */
9767  if (cond_string)
9768  {
9769  cond_string = xstrdup (cond_string);
9770  make_cleanup (xfree, cond_string);
9771  }
9772  /* Create a private copy of any extra string. */
9773  if (extra_string != NULL)
9774  {
9775  extra_string = xstrdup (extra_string);
9776  make_cleanup (xfree, extra_string);
9777  }
9778  b->cond_string = cond_string;
9779  b->extra_string = extra_string;
9780  b->thread = thread;
9781  }
9782  b->ignore_count = ignore_count;
9783  b->disposition = tempflag ? disp_del : disp_donttouch;
9784  b->condition_not_parsed = 1;
9785  b->enable_state = enabled ? bp_enabled : bp_disabled;
9786  if ((type_wanted != bp_breakpoint
9787  && type_wanted != bp_hardware_breakpoint) || thread != -1)
9789 
9790  install_breakpoint (internal, b, 0);
9791  }
9792 
9793  if (VEC_length (linespec_sals, canonical.sals) > 1)
9794  {
9795  warning (_("Multiple breakpoints were set.\nUse the "
9796  "\"delete\" command to delete unwanted breakpoints."));
9797  prev_breakpoint_count = prev_bkpt_count;
9798  }
9799 
9800  /* That's it. Discard the cleanups for data inserted into the
9801  breakpoint. */
9802  discard_cleanups (bkpt_chain);
9803  /* But cleanup everything else. */
9804  do_cleanups (old_chain);
9805 
9806  /* error call may happen here - have BKPT_CHAIN already discarded. */
9808 
9809  return 1;
9810 }
9811 
9812 /* Set a breakpoint.
9813  ARG is a string describing breakpoint address,
9814  condition, and thread.
9815  FLAG specifies if a breakpoint is hardware on,
9816  and if breakpoint is temporary, using BP_HARDWARE_FLAG
9817  and BP_TEMPFLAG. */
9818 
9819 static void
9820 break_command_1 (char *arg, int flag, int from_tty)
9821 {
9822  int tempflag = flag & BP_TEMPFLAG;
9823  enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9825  : bp_breakpoint);
9826  struct breakpoint_ops *ops;
9827  const char *arg_cp = arg;
9828 
9829  /* Matching breakpoints on probes. */
9830  if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9832  else
9833  ops = &bkpt_breakpoint_ops;
9834 
9836  arg,
9837  NULL, 0, NULL, 1 /* parse arg */,
9838  tempflag, type_wanted,
9839  0 /* Ignore count */,
9840  pending_break_support,
9841  ops,
9842  from_tty,
9843  1 /* enabled */,
9844  0 /* internal */,
9845  0);
9846 }
9847 
9848 /* Helper function for break_command_1 and disassemble_command. */
9849 
9850 void
9852 {
9853  CORE_ADDR pc;
9854 
9855  if (sal->pc == 0 && sal->symtab != NULL)
9856  {
9857  if (!find_line_pc (sal->symtab, sal->line, &pc))
9858  error (_("No line %d in file \"%s\"."),
9860  sal->pc = pc;
9861 
9862  /* If this SAL corresponds to a breakpoint inserted using a line
9863  number, then skip the function prologue if necessary. */
9864  if (sal->explicit_line)
9865  skip_prologue_sal (sal);
9866  }
9867 
9868  if (sal->section == 0 && sal->symtab != NULL)
9869  {
9870  const struct blockvector *bv;
9871  const struct block *b;
9872  struct symbol *sym;
9873 
9874  bv = blockvector_for_pc_sect (sal->pc, 0, &b,
9875  SYMTAB_COMPUNIT (sal->symtab));
9876  if (bv != NULL)
9877  {
9878  sym = block_linkage_function (b);
9879  if (sym != NULL)
9880  {
9883  sym);
9884  }
9885  else
9886  {
9887  /* It really is worthwhile to have the section, so we'll
9888  just have to look harder. This case can be executed
9889  if we have line numbers but no functions (as can
9890  happen in assembly source). */
9891 
9892  struct bound_minimal_symbol msym;
9893  struct cleanup *old_chain = save_current_space_and_thread ();
9894 
9896 
9897  msym = lookup_minimal_symbol_by_pc (sal->pc);
9898  if (msym.minsym)
9899  sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym);
9900 
9901  do_cleanups (old_chain);
9902  }
9903  }
9904  }
9905 }
9906 
9907 void
9908 break_command (char *arg, int from_tty)
9909 {
9910  break_command_1 (arg, 0, from_tty);
9911 }
9912 
9913 void
9914 tbreak_command (char *arg, int from_tty)
9915 {
9916  break_command_1 (arg, BP_TEMPFLAG, from_tty);
9917 }
9918 
9919 static void
9920 hbreak_command (char *arg, int from_tty)
9921 {
9922  break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
9923 }
9924 
9925 static void
9926 thbreak_command (char *arg, int from_tty)
9927 {
9928  break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
9929 }
9930 
9931 static void
9932 stop_command (char *arg, int from_tty)
9933 {
9934  printf_filtered (_("Specify the type of breakpoint to set.\n\
9935 Usage: stop in <function | address>\n\
9936  stop at <line>\n"));
9937 }
9938 
9939 static void
9940 stopin_command (char *arg, int from_tty)
9941 {
9942  int badInput = 0;
9943 
9944  if (arg == (char *) NULL)
9945  badInput = 1;
9946  else if (*arg != '*')
9947  {
9948  char *argptr = arg;
9949  int hasColon = 0;
9950 
9951  /* Look for a ':'. If this is a line number specification, then
9952  say it is bad, otherwise, it should be an address or
9953  function/method name. */
9954  while (*argptr && !hasColon)
9955  {
9956  hasColon = (*argptr == ':');
9957  argptr++;
9958  }
9959 
9960  if (hasColon)
9961  badInput = (*argptr != ':'); /* Not a class::method */
9962  else
9963  badInput = isdigit (*arg); /* a simple line number */
9964  }
9965 
9966  if (badInput)
9967  printf_filtered (_("Usage: stop in <function | address>\n"));
9968  else
9969  break_command_1 (arg, 0, from_tty);
9970 }
9971 
9972 static void
9973 stopat_command (char *arg, int from_tty)
9974 {
9975  int badInput = 0;
9976 
9977  if (arg == (char *) NULL || *arg == '*') /* no line number */
9978  badInput = 1;
9979  else
9980  {
9981  char *argptr = arg;
9982  int hasColon = 0;
9983 
9984  /* Look for a ':'. If there is a '::' then get out, otherwise
9985  it is probably a line number. */
9986  while (*argptr && !hasColon)
9987  {
9988  hasColon = (*argptr == ':');
9989  argptr++;
9990  }
9991 
9992  if (hasColon)
9993  badInput = (*argptr == ':'); /* we have class::method */
9994  else
9995  badInput = !isdigit (*arg); /* not a line number */
9996  }
9997 
9998  if (badInput)
9999  printf_filtered (_("Usage: stop at <line>\n"));
10000  else
10001  break_command_1 (arg, 0, from_tty);
10002 }
10003 
10004 /* The dynamic printf command is mostly like a regular breakpoint, but
10005  with a prewired command list consisting of a single output command,
10006  built from extra arguments supplied on the dprintf command
10007  line. */
10008 
10009 static void
10010 dprintf_command (char *arg, int from_tty)
10011 {
10013  arg,
10014  NULL, 0, NULL, 1 /* parse arg */,
10015  0, bp_dprintf,
10016  0 /* Ignore count */,
10017  pending_break_support,
10019  from_tty,
10020  1 /* enabled */,
10021  0 /* internal */,
10022  0);
10023 }
10024 
10025 static void
10026 agent_printf_command (char *arg, int from_tty)
10027 {
10028  error (_("May only run agent-printf on the target"));
10029 }
10030 
10031 /* Implement the "breakpoint_hit" breakpoint_ops method for
10032  ranged breakpoints. */
10033 
10034 static int
10035 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
10036  struct address_space *aspace,
10037  CORE_ADDR bp_addr,
10038  const struct target_waitstatus *ws)
10039 {
10040  if (ws->kind != TARGET_WAITKIND_STOPPED
10041  || ws->value.sig != GDB_SIGNAL_TRAP)
10042  return 0;
10043 
10045  bl->length, aspace, bp_addr);
10046 }
10047 
10048 /* Implement the "resources_needed" breakpoint_ops method for
10049  ranged breakpoints. */
10050 
10051 static int
10052 resources_needed_ranged_breakpoint (const struct bp_location *bl)
10053 {
10055 }
10056 
10057 /* Implement the "print_it" breakpoint_ops method for
10058  ranged breakpoints. */
10059 
10060 static enum print_stop_action
10062 {
10063  struct breakpoint *b = bs->breakpoint_at;
10064  struct bp_location *bl = b->loc;
10065  struct ui_out *uiout = current_uiout;
10066 
10068 
10069  /* Ranged breakpoints have only one location. */
10070  gdb_assert (bl && bl->next == NULL);
10071 
10073  if (b->disposition == disp_del)
10074  ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10075  else
10076  ui_out_text (uiout, "\nRanged breakpoint ");
10077  if (ui_out_is_mi_like_p (uiout))
10078  {
10079  ui_out_field_string (uiout, "reason",
10081  ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10082  }
10083  ui_out_field_int (uiout, "bkptno", b->number);
10084  ui_out_text (uiout, ", ");
10085 
10086  return PRINT_SRC_AND_LOC;
10087 }
10088 
10089 /* Implement the "print_one" breakpoint_ops method for
10090  ranged breakpoints. */
10091 
10092 static void
10094  struct bp_location **last_loc)
10095 {
10096  struct bp_location *bl = b->loc;
10097  struct value_print_options opts;
10098  struct ui_out *uiout = current_uiout;
10099 
10100  /* Ranged breakpoints have only one location. */
10101  gdb_assert (bl && bl->next == NULL);
10102 
10103  get_user_print_options (&opts);
10104 
10105  if (opts.addressprint)
10106  /* We don't print the address range here, it will be printed later
10107  by print_one_detail_ranged_breakpoint. */
10108  ui_out_field_skip (uiout, "addr");
10109  annotate_field (5);
10110  print_breakpoint_location (b, bl);
10111  *last_loc = bl;
10112 }
10113 
10114 /* Implement the "print_one_detail" breakpoint_ops method for
10115  ranged breakpoints. */
10116 
10117 static void
10119  struct ui_out *uiout)
10120 {
10121  CORE_ADDR address_start, address_end;
10122  struct bp_location *bl = b->loc;
10123  struct ui_file *stb = mem_fileopen ();
10125 
10126  gdb_assert (bl);
10127 
10128  address_start = bl->address;
10129  address_end = address_start + bl->length - 1;
10130 
10131  ui_out_text (uiout, "\taddress range: ");
10132  fprintf_unfiltered (stb, "[%s, %s]",
10133  print_core_address (bl->gdbarch, address_start),
10134  print_core_address (bl->gdbarch, address_end));
10135  ui_out_field_stream (uiout, "addr", stb);
10136  ui_out_text (uiout, "\n");
10137 
10138  do_cleanups (cleanup);
10139 }
10140 
10141 /* Implement the "print_mention" breakpoint_ops method for
10142  ranged breakpoints. */
10143 
10144 static void
10146 {
10147  struct bp_location *bl = b->loc;
10148  struct ui_out *uiout = current_uiout;
10149 
10150  gdb_assert (bl);
10152 
10153  if (ui_out_is_mi_like_p (uiout))
10154  return;
10155 
10156  printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10157  b->number, paddress (bl->gdbarch, bl->address),
10158  paddress (bl->gdbarch, bl->address + bl->length - 1));
10159 }
10160 
10161 /* Implement the "print_recreate" breakpoint_ops method for
10162  ranged breakpoints. */
10163 
10164 static void
10166 {
10167  fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10169  print_recreate_thread (b, fp);
10170 }
10171 
10172 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10173 
10175 
10176 /* Find the address where the end of the breakpoint range should be
10177  placed, given the SAL of the end of the range. This is so that if
10178  the user provides a line number, the end of the range is set to the
10179  last instruction of the given line. */
10180 
10181 static CORE_ADDR
10183 {
10184  CORE_ADDR end;
10185 
10186  /* If the user provided a PC value, use it. Otherwise,
10187  find the address of the end of the given location. */
10188  if (sal.explicit_pc)
10189  end = sal.pc;
10190  else
10191  {
10192  int ret;
10193  CORE_ADDR start;
10194 
10195  ret = find_line_pc_range (sal, &start, &end);
10196  if (!ret)
10197  error (_("Could not find location of the end of the range."));
10198 
10199  /* find_line_pc_range returns the start of the next line. */
10200  end--;
10201  }
10202 
10203  return end;
10204 }
10205 
10206 /* Implement the "break-range" CLI command. */
10207 
10208 static void
10209 break_range_command (char *arg, int from_tty)
10210 {
10211  char *arg_start, *addr_string_start, *addr_string_end;
10212  struct linespec_result canonical_start, canonical_end;
10213  int bp_count, can_use_bp, length;
10214  CORE_ADDR end;
10215  struct breakpoint *b;
10216  struct symtab_and_line sal_start, sal_end;
10217  struct cleanup *cleanup_bkpt;
10218  struct linespec_sals *lsal_start, *lsal_end;
10219 
10220  /* We don't support software ranged breakpoints. */
10222  error (_("This target does not support hardware ranged breakpoints."));
10223 
10224  bp_count = hw_breakpoint_used_count ();
10225  bp_count += target_ranged_break_num_registers ();
10227  bp_count, 0);
10228  if (can_use_bp < 0)
10229  error (_("Hardware breakpoints used exceeds limit."));
10230 
10231  arg = skip_spaces (arg);
10232  if (arg == NULL || arg[0] == '\0')
10233  error(_("No address range specified."));
10234 
10235  init_linespec_result (&canonical_start);
10236 
10237  arg_start = arg;
10238  parse_breakpoint_sals (&arg, &canonical_start);
10239 
10240  cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10241 
10242  if (arg[0] != ',')
10243  error (_("Too few arguments."));
10244  else if (VEC_empty (linespec_sals, canonical_start.sals))
10245  error (_("Could not find location of the beginning of the range."));
10246 
10247  lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10248 
10249  if (VEC_length (linespec_sals, canonical_start.sals) > 1
10250  || lsal_start->sals.nelts != 1)
10251  error (_("Cannot create a ranged breakpoint with multiple locations."));
10252 
10253  sal_start = lsal_start->sals.sals[0];
10254  addr_string_start = savestring (arg_start, arg - arg_start);
10255  make_cleanup (xfree, addr_string_start);
10256 
10257  arg++; /* Skip the comma. */
10258  arg = skip_spaces (arg);
10259 
10260  /* Parse the end location. */
10261 
10262  init_linespec_result (&canonical_end);
10263  arg_start = arg;
10264 
10265  /* We call decode_line_full directly here instead of using
10266  parse_breakpoint_sals because we need to specify the start location's
10267  symtab and line as the default symtab and line for the end of the
10268  range. This makes it possible to have ranges like "foo.c:27, +14",
10269  where +14 means 14 lines from the start location. */
10271  sal_start.symtab, sal_start.line,
10272  &canonical_end, NULL, NULL);
10273 
10274  make_cleanup_destroy_linespec_result (&canonical_end);
10275 
10276  if (VEC_empty (linespec_sals, canonical_end.sals))
10277  error (_("Could not find location of the end of the range."));
10278 
10279  lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10280  if (VEC_length (linespec_sals, canonical_end.sals) > 1
10281  || lsal_end->sals.nelts != 1)
10282  error (_("Cannot create a ranged breakpoint with multiple locations."));
10283 
10284  sal_end = lsal_end->sals.sals[0];
10285  addr_string_end = savestring (arg_start, arg - arg_start);
10286  make_cleanup (xfree, addr_string_end);
10287 
10288  end = find_breakpoint_range_end (sal_end);
10289  if (sal_start.pc > end)
10290  error (_("Invalid address range, end precedes start."));
10291 
10292  length = end - sal_start.pc + 1;
10293  if (length < 0)
10294  /* Length overflowed. */
10295  error (_("Address range too large."));
10296  else if (length == 1)
10297  {
10298  /* This range is simple enough to be handled by
10299  the `hbreak' command. */
10300  hbreak_command (addr_string_start, 1);
10301 
10302  do_cleanups (cleanup_bkpt);
10303 
10304  return;
10305  }
10306 
10307  /* Now set up the breakpoint. */
10308  b = set_raw_breakpoint (get_current_arch (), sal_start,
10310  set_breakpoint_count (breakpoint_count + 1);
10311  b->number = breakpoint_count;
10313  b->addr_string = xstrdup (addr_string_start);
10314  b->addr_string_range_end = xstrdup (addr_string_end);
10315  b->loc->length = length;
10316 
10317  do_cleanups (cleanup_bkpt);
10318 
10319  mention (b);
10322 }
10323 
10324 /* Return non-zero if EXP is verified as constant. Returned zero
10325  means EXP is variable. Also the constant detection may fail for
10326  some constant expressions and in such case still falsely return
10327  zero. */
10328 
10329 static int
10331 {
10332  int i = exp->nelts;
10333 
10334  while (i > 0)
10335  {
10336  int oplenp, argsp;
10337 
10338  /* We are only interested in the descriptor of each element. */
10339  operator_length (exp, i, &oplenp, &argsp);
10340  i -= oplenp;
10341 
10342  switch (exp->elts[i].opcode)
10343  {
10344  case BINOP_ADD:
10345  case BINOP_SUB:
10346  case BINOP_MUL:
10347  case BINOP_DIV:
10348  case BINOP_REM:
10349  case BINOP_MOD:
10350  case BINOP_LSH:
10351  case BINOP_RSH:
10352  case BINOP_LOGICAL_AND:
10353  case BINOP_LOGICAL_OR:
10354  case BINOP_BITWISE_AND:
10355  case BINOP_BITWISE_IOR:
10356  case BINOP_BITWISE_XOR:
10357  case BINOP_EQUAL:
10358  case BINOP_NOTEQUAL:
10359  case BINOP_LESS:
10360  case BINOP_GTR:
10361  case BINOP_LEQ:
10362  case BINOP_GEQ:
10363  case BINOP_REPEAT:
10364  case BINOP_COMMA:
10365  case BINOP_EXP:
10366  case BINOP_MIN:
10367  case BINOP_MAX:
10368  case BINOP_INTDIV:
10369  case BINOP_CONCAT:
10370  case TERNOP_COND:
10371  case TERNOP_SLICE:
10372 
10373  case OP_LONG:
10374  case OP_DOUBLE:
10375  case OP_DECFLOAT:
10376  case OP_LAST:
10377  case OP_COMPLEX:
10378  case OP_STRING:
10379  case OP_ARRAY:
10380  case OP_TYPE:
10381  case OP_TYPEOF:
10382  case OP_DECLTYPE:
10383  case OP_TYPEID:
10384  case OP_NAME:
10385  case OP_OBJC_NSSTRING:
10386 
10387  case UNOP_NEG:
10388  case UNOP_LOGICAL_NOT:
10389  case UNOP_COMPLEMENT:
10390  case UNOP_ADDR:
10391  case UNOP_HIGH:
10392  case UNOP_CAST:
10393 
10394  case UNOP_CAST_TYPE:
10395  case UNOP_REINTERPRET_CAST:
10396  case UNOP_DYNAMIC_CAST:
10397  /* Unary, binary and ternary operators: We have to check
10398  their operands. If they are constant, then so is the
10399  result of that operation. For instance, if A and B are
10400  determined to be constants, then so is "A + B".
10401 
10402  UNOP_IND is one exception to the rule above, because the
10403  value of *ADDR is not necessarily a constant, even when
10404  ADDR is. */
10405  break;
10406 
10407  case OP_VAR_VALUE:
10408  /* Check whether the associated symbol is a constant.
10409 
10410  We use SYMBOL_CLASS rather than TYPE_CONST because it's
10411  possible that a buggy compiler could mark a variable as
10412  constant even when it is not, and TYPE_CONST would return
10413  true in this case, while SYMBOL_CLASS wouldn't.
10414 
10415  We also have to check for function symbols because they
10416  are always constant. */
10417  {
10418  struct symbol *s = exp->elts[i + 2].symbol;
10419 
10420  if (SYMBOL_CLASS (s) != LOC_BLOCK
10421  && SYMBOL_CLASS (s) != LOC_CONST
10422  && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10423  return 0;
10424  break;
10425  }
10426 
10427  /* The default action is to return 0 because we are using
10428  the optimistic approach here: If we don't know something,
10429  then it is not a constant. */
10430  default:
10431  return 0;
10432  }
10433  }
10434 
10435  return 1;
10436 }
10437 
10438 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10439 
10440 static void
10442 {
10443  struct watchpoint *w = (struct watchpoint *) self;
10444 
10445  xfree (w->cond_exp);
10446  xfree (w->exp);
10447  xfree (w->exp_string);
10449  value_free (w->val);
10450 
10451  base_breakpoint_ops.dtor (self);
10452 }
10453 
10454 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10455 
10456 static void
10458 {
10459  struct watchpoint *w = (struct watchpoint *) b;
10460 
10461  /* Watchpoint can be either on expression using entirely global
10462  variables, or it can be on local variables.
10463 
10464  Watchpoints of the first kind are never auto-deleted, and even
10465  persist across program restarts. Since they can use variables
10466  from shared libraries, we need to reparse expression as libraries
10467  are loaded and unloaded.
10468 
10469  Watchpoints on local variables can also change meaning as result
10470  of solib event. For example, if a watchpoint uses both a local
10471  and a global variables in expression, it's a local watchpoint,
10472  but unloading of a shared library will make the expression
10473  invalid. This is not a very common use case, but we still
10474  re-evaluate expression, to avoid surprises to the user.
10475 
10476  Note that for local watchpoints, we re-evaluate it only if
10477  watchpoints frame id is still valid. If it's not, it means the
10478  watchpoint is out of scope and will be deleted soon. In fact,
10479  I'm not sure we'll ever be called in this case.
10480 
10481  If a local watchpoint's frame id is still valid, then
10482  w->exp_valid_block is likewise valid, and we can safely use it.
10483 
10484  Don't do anything about disabled watchpoints, since they will be
10485  reevaluated again when enabled. */
10486  update_watchpoint (w, 1 /* reparse */);
10487 }
10488 
10489 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10490 
10491 static int
10492 insert_watchpoint (struct bp_location *bl)
10493 {
10494  struct watchpoint *w = (struct watchpoint *) bl->owner;
10495  int length = w->exact ? 1 : bl->length;
10496 
10497  return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10498  w->cond_exp);
10499 }
10500 
10501 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10502 
10503 static int
10504 remove_watchpoint (struct bp_location *bl)
10505 {
10506  struct watchpoint *w = (struct watchpoint *) bl->owner;
10507  int length = w->exact ? 1 : bl->length;
10508 
10509  return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10510  w->cond_exp);
10511 }
10512 
10513 static int
10514 breakpoint_hit_watchpoint (const struct bp_location *bl,
10515  struct address_space *aspace, CORE_ADDR bp_addr,
10516  const struct target_waitstatus *ws)
10517 {
10518  struct breakpoint *b = bl->owner;
10519  struct watchpoint *w = (struct watchpoint *) b;
10520 
10521  /* Continuable hardware watchpoints are treated as non-existent if the
10522  reason we stopped wasn't a hardware watchpoint (we didn't stop on
10523  some data address). Otherwise gdb won't stop on a break instruction
10524  in the code (not from a breakpoint) when a hardware watchpoint has
10525  been defined. Also skip watchpoints which we know did not trigger
10526  (did not match the data address). */
10527  if (is_hardware_watchpoint (b)
10529  return 0;
10530 
10531  return 1;
10532 }
10533 
10534 static void
10536 {
10538 
10540 }
10541 
10542 /* Implement the "resources_needed" breakpoint_ops method for
10543  hardware watchpoints. */
10544 
10545 static int
10546 resources_needed_watchpoint (const struct bp_location *bl)
10547 {
10548  struct watchpoint *w = (struct watchpoint *) bl->owner;
10549  int length = w->exact? 1 : bl->length;
10550 
10551  return target_region_ok_for_hw_watchpoint (bl->address, length);
10552 }
10553 
10554 /* Implement the "works_in_software_mode" breakpoint_ops method for
10555  hardware watchpoints. */
10556 
10557 static int
10559 {
10560  /* Read and access watchpoints only work with hardware support. */
10561  return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10562 }
10563 
10564 static enum print_stop_action
10566 {
10567  struct cleanup *old_chain;
10568  struct breakpoint *b;
10569  struct ui_file *stb;
10570  enum print_stop_action result;
10571  struct watchpoint *w;
10572  struct ui_out *uiout = current_uiout;
10573 
10574  gdb_assert (bs->bp_location_at != NULL);
10575 
10576  b = bs->breakpoint_at;
10577  w = (struct watchpoint *) b;
10578 
10579  stb = mem_fileopen ();
10580  old_chain = make_cleanup_ui_file_delete (stb);
10581 
10582  switch (b->type)
10583  {
10584  case bp_watchpoint:
10587  if (ui_out_is_mi_like_p (uiout))
10589  (uiout, "reason",
10591  mention (b);
10592  make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10593  ui_out_text (uiout, "\nOld value = ");
10594  watchpoint_value_print (bs->old_val, stb);
10595  ui_out_field_stream (uiout, "old", stb);
10596  ui_out_text (uiout, "\nNew value = ");
10597  watchpoint_value_print (w->val, stb);
10598  ui_out_field_stream (uiout, "new", stb);
10599  ui_out_text (uiout, "\n");
10600  /* More than one watchpoint may have been triggered. */
10601  result = PRINT_UNKNOWN;
10602  break;
10603 
10604  case bp_read_watchpoint:
10605  if (ui_out_is_mi_like_p (uiout))
10607  (uiout, "reason",
10609  mention (b);
10610  make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10611  ui_out_text (uiout, "\nValue = ");
10612  watchpoint_value_print (w->val, stb);
10613  ui_out_field_stream (uiout, "value", stb);
10614  ui_out_text (uiout, "\n");
10615  result = PRINT_UNKNOWN;
10616  break;
10617 
10618  case bp_access_watchpoint:
10619  if (bs->old_val != NULL)
10620  {
10622  if (ui_out_is_mi_like_p (uiout))
10624  (uiout, "reason",
10626  mention (b);
10627  make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10628  ui_out_text (uiout, "\nOld value = ");
10629  watchpoint_value_print (bs->old_val, stb);
10630  ui_out_field_stream (uiout, "old", stb);
10631  ui_out_text (uiout, "\nNew value = ");
10632  }
10633  else
10634  {
10635  mention (b);
10636  if (ui_out_is_mi_like_p (uiout))
10638  (uiout, "reason",
10640  make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10641  ui_out_text (uiout, "\nValue = ");
10642  }
10643  watchpoint_value_print (w->val, stb);
10644  ui_out_field_stream (uiout, "new", stb);
10645  ui_out_text (uiout, "\n");
10646  result = PRINT_UNKNOWN;
10647  break;
10648  default:
10649  result = PRINT_UNKNOWN;
10650  }
10651 
10652  do_cleanups (old_chain);
10653  return result;
10654 }
10655 
10656 /* Implement the "print_mention" breakpoint_ops method for hardware
10657  watchpoints. */
10658 
10659 static void
10661 {
10662  struct cleanup *ui_out_chain;
10663  struct watchpoint *w = (struct watchpoint *) b;
10664  struct ui_out *uiout = current_uiout;
10665 
10666  switch (b->type)
10667  {
10668  case bp_watchpoint:
10669  ui_out_text (uiout, "Watchpoint ");
10670  ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10671  break;
10673  ui_out_text (uiout, "Hardware watchpoint ");
10674  ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10675  break;
10676  case bp_read_watchpoint:
10677  ui_out_text (uiout, "Hardware read watchpoint ");
10678  ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10679  break;
10680  case bp_access_watchpoint:
10681  ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10682  ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10683  break;
10684  default:
10685  internal_error (__FILE__, __LINE__,
10686  _("Invalid hardware watchpoint type."));
10687  }
10688 
10689  ui_out_field_int (uiout, "number", b->number);
10690  ui_out_text (uiout, ": ");
10691  ui_out_field_string (uiout, "exp", w->exp_string);
10692  do_cleanups (ui_out_chain);
10693 }
10694 
10695 /* Implement the "print_recreate" breakpoint_ops method for
10696  watchpoints. */
10697 
10698 static void
10700 {
10701  struct watchpoint *w = (struct watchpoint *) b;
10702 
10703  switch (b->type)
10704  {
10705  case bp_watchpoint:
10707  fprintf_unfiltered (fp, "watch");
10708  break;
10709  case bp_read_watchpoint:
10710  fprintf_unfiltered (fp, "rwatch");
10711  break;
10712  case bp_access_watchpoint:
10713  fprintf_unfiltered (fp, "awatch");
10714  break;
10715  default:
10716  internal_error (__FILE__, __LINE__,
10717  _("Invalid watchpoint type."));
10718  }
10719 
10720  fprintf_unfiltered (fp, " %s", w->exp_string);
10721  print_recreate_thread (b, fp);
10722 }
10723 
10724 /* Implement the "explains_signal" breakpoint_ops method for
10725  watchpoints. */
10726 
10727 static int
10728 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10729 {
10730  /* A software watchpoint cannot cause a signal other than
10731  GDB_SIGNAL_TRAP. */
10732  if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10733  return 0;
10734 
10735  return 1;
10736 }
10737 
10738 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10739 
10741 
10742 /* Implement the "insert" breakpoint_ops method for
10743  masked hardware watchpoints. */
10744 
10745 static int
10746 insert_masked_watchpoint (struct bp_location *bl)
10747 {
10748  struct watchpoint *w = (struct watchpoint *) bl->owner;
10749 
10751  bl->watchpoint_type);
10752 }
10753 
10754 /* Implement the "remove" breakpoint_ops method for
10755  masked hardware watchpoints. */
10756 
10757 static int
10758 remove_masked_watchpoint (struct bp_location *bl)
10759 {
10760  struct watchpoint *w = (struct watchpoint *) bl->owner;
10761 
10763  bl->watchpoint_type);
10764 }
10765 
10766 /* Implement the "resources_needed" breakpoint_ops method for
10767  masked hardware watchpoints. */
10768 
10769 static int
10770 resources_needed_masked_watchpoint (const struct bp_location *bl)
10771 {
10772  struct watchpoint *w = (struct watchpoint *) bl->owner;
10773 
10775 }
10776 
10777 /* Implement the "works_in_software_mode" breakpoint_ops method for
10778  masked hardware watchpoints. */
10779 
10780 static int
10782 {
10783  return 0;
10784 }
10785 
10786 /* Implement the "print_it" breakpoint_ops method for
10787  masked hardware watchpoints. */
10788 
10789 static enum print_stop_action
10791 {
10792  struct breakpoint *b = bs->breakpoint_at;
10793  struct ui_out *uiout = current_uiout;
10794 
10795  /* Masked watchpoints have only one location. */
10796  gdb_assert (b->loc && b->loc->next == NULL);
10797 
10798  switch (b->type)
10799  {
10802  if (ui_out_is_mi_like_p (uiout))
10804  (uiout, "reason",
10806  break;
10807 
10808  case bp_read_watchpoint:
10809  if (ui_out_is_mi_like_p (uiout))
10811  (uiout, "reason",
10813  break;
10814 
10815  case bp_access_watchpoint:
10816  if (ui_out_is_mi_like_p (uiout))
10818  (uiout, "reason",
10820  break;
10821  default:
10822  internal_error (__FILE__, __LINE__,
10823  _("Invalid hardware watchpoint type."));
10824  }
10825 
10826  mention (b);
10827  ui_out_text (uiout, _("\n\
10828 Check the underlying instruction at PC for the memory\n\
10829 address and value which triggered this watchpoint.\n"));
10830  ui_out_text (uiout, "\n");
10831 
10832  /* More than one watchpoint may have been triggered. */
10833  return PRINT_UNKNOWN;
10834 }
10835 
10836 /* Implement the "print_one_detail" breakpoint_ops method for
10837  masked hardware watchpoints. */
10838 
10839 static void
10841  struct ui_out *uiout)
10842 {
10843  struct watchpoint *w = (struct watchpoint *) b;
10844 
10845  /* Masked watchpoints have only one location. */
10846  gdb_assert (b->loc && b->loc->next == NULL);
10847 
10848  ui_out_text (uiout, "\tmask ");
10849  ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10850  ui_out_text (uiout, "\n");
10851 }
10852 
10853 /* Implement the "print_mention" breakpoint_ops method for
10854  masked hardware watchpoints. */
10855 
10856 static void
10858 {
10859  struct watchpoint *w = (struct watchpoint *) b;
10860  struct ui_out *uiout = current_uiout;
10861  struct cleanup *ui_out_chain;
10862 
10863  switch (b->type)
10864  {
10866  ui_out_text (uiout, "Masked hardware watchpoint ");
10867  ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10868  break;
10869  case bp_read_watchpoint:
10870  ui_out_text (uiout, "Masked hardware read watchpoint ");
10871  ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10872  break;
10873  case bp_access_watchpoint:
10874  ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10875  ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10876  break;
10877  default:
10878  internal_error (__FILE__, __LINE__,
10879  _("Invalid hardware watchpoint type."));
10880  }
10881 
10882  ui_out_field_int (uiout, "number", b->number);
10883  ui_out_text (uiout, ": ");
10884  ui_out_field_string (uiout, "exp", w->exp_string);
10885  do_cleanups (ui_out_chain);
10886 }
10887 
10888 /* Implement the "print_recreate" breakpoint_ops method for
10889  masked hardware watchpoints. */
10890 
10891 static void
10893 {
10894  struct watchpoint *w = (struct watchpoint *) b;
10895  char tmp[40];
10896 
10897  switch (b->type)
10898  {
10900  fprintf_unfiltered (fp, "watch");
10901  break;
10902  case bp_read_watchpoint:
10903  fprintf_unfiltered (fp, "rwatch");
10904  break;
10905  case bp_access_watchpoint:
10906  fprintf_unfiltered (fp, "awatch");
10907  break;
10908  default:
10909  internal_error (__FILE__, __LINE__,
10910  _("Invalid hardware watchpoint type."));
10911  }
10912 
10913  sprintf_vma (tmp, w->hw_wp_mask);
10914  fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10915  print_recreate_thread (b, fp);
10916 }
10917 
10918 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10919 
10921 
10922 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10923 
10924 static int
10926 {
10927  return b->ops == &masked_watchpoint_breakpoint_ops;
10928 }
10929 
10930 /* accessflag: hw_write: watch write,
10931  hw_read: watch read,
10932  hw_access: watch access (read or write) */
10933 static void
10934 watch_command_1 (const char *arg, int accessflag, int from_tty,
10935  int just_location, int internal)
10936 {
10937  struct breakpoint *b, *scope_breakpoint = NULL;
10938  struct expression *exp;
10939  const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10940  struct value *val, *mark, *result;
10941  int saved_bitpos = 0, saved_bitsize = 0;
10942  struct frame_info *frame;
10943  const char *exp_start = NULL;
10944  const char *exp_end = NULL;
10945  const char *tok, *end_tok;
10946  int toklen = -1;
10947  const char *cond_start = NULL;
10948  const char *cond_end = NULL;
10949  enum bptype bp_type;
10950  int thread = -1;
10951  int pc = 0;
10952  /* Flag to indicate whether we are going to use masks for
10953  the hardware watchpoint. */
10954  int use_mask = 0;
10955  CORE_ADDR mask = 0;
10956  struct watchpoint *w;
10957  char *expression;
10958  struct cleanup *back_to;
10959 
10960  /* Make sure that we actually have parameters to parse. */
10961  if (arg != NULL && arg[0] != '\0')
10962  {
10963  const char *value_start;
10964 
10965  exp_end = arg + strlen (arg);
10966 
10967  /* Look for "parameter value" pairs at the end
10968  of the arguments string. */
10969  for (tok = exp_end - 1; tok > arg; tok--)
10970  {
10971  /* Skip whitespace at the end of the argument list. */
10972  while (tok > arg && (*tok == ' ' || *tok == '\t'))
10973  tok--;
10974 
10975  /* Find the beginning of the last token.
10976  This is the value of the parameter. */
10977  while (tok > arg && (*tok != ' ' && *tok != '\t'))
10978  tok--;
10979  value_start = tok + 1;
10980 
10981  /* Skip whitespace. */
10982  while (tok > arg && (*tok == ' ' || *tok == '\t'))
10983  tok--;
10984 
10985  end_tok = tok;
10986 
10987  /* Find the beginning of the second to last token.
10988  This is the parameter itself. */
10989  while (tok > arg && (*tok != ' ' && *tok != '\t'))
10990  tok--;
10991  tok++;
10992  toklen = end_tok - tok + 1;
10993 
10994  if (toklen == 6 && startswith (tok, "thread"))
10995  {
10996  /* At this point we've found a "thread" token, which means
10997  the user is trying to set a watchpoint that triggers
10998  only in a specific thread. */
10999  char *endp;
11000 
11001  if (thread != -1)
11002  error(_("You can specify only one thread."));
11003 
11004  /* Extract the thread ID from the next token. */
11005  thread = strtol (value_start, &endp, 0);
11006 
11007  /* Check if the user provided a valid numeric value for the
11008  thread ID. */
11009  if (*endp != ' ' && *endp != '\t' && *endp != '\0')
11010  error (_("Invalid thread ID specification %s."), value_start);
11011 
11012  /* Check if the thread actually exists. */
11013  if (!valid_thread_id (thread))
11014  invalid_thread_id_error (thread);
11015  }
11016  else if (toklen == 4 && startswith (tok, "mask"))
11017  {
11018  /* We've found a "mask" token, which means the user wants to
11019  create a hardware watchpoint that is going to have the mask
11020  facility. */
11021  struct value *mask_value, *mark;
11022 
11023  if (use_mask)
11024  error(_("You can specify only one mask."));
11025 
11026  use_mask = just_location = 1;
11027 
11028  mark = value_mark ();
11029  mask_value = parse_to_comma_and_eval (&value_start);
11030  mask = value_as_address (mask_value);
11031  value_free_to_mark (mark);
11032  }
11033  else
11034  /* We didn't recognize what we found. We should stop here. */
11035  break;
11036 
11037  /* Truncate the string and get rid of the "parameter value" pair before
11038  the arguments string is parsed by the parse_exp_1 function. */
11039  exp_end = tok;
11040  }
11041  }
11042  else
11043  exp_end = arg;
11044 
11045  /* Parse the rest of the arguments. From here on out, everything
11046  is in terms of a newly allocated string instead of the original
11047  ARG. */
11048  innermost_block = NULL;
11049  expression = savestring (arg, exp_end - arg);
11050  back_to = make_cleanup (xfree, expression);
11051  exp_start = arg = expression;
11052  exp = parse_exp_1 (&arg, 0, 0, 0);
11053  exp_end = arg;
11054  /* Remove trailing whitespace from the expression before saving it.
11055  This makes the eventual display of the expression string a bit
11056  prettier. */
11057  while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
11058  --exp_end;
11059 
11060  /* Checking if the expression is not constant. */
11061  if (watchpoint_exp_is_const (exp))
11062  {
11063  int len;
11064 
11065  len = exp_end - exp_start;
11066  while (len > 0 && isspace (exp_start[len - 1]))
11067  len--;
11068  error (_("Cannot watch constant value `%.*s'."), len, exp_start);
11069  }
11070 
11071  exp_valid_block = innermost_block;
11072  mark = value_mark ();
11073  fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location);
11074 
11075  if (val != NULL && just_location)
11076  {
11077  saved_bitpos = value_bitpos (val);
11078  saved_bitsize = value_bitsize (val);
11079  }
11080 
11081  if (just_location)
11082  {
11083  int ret;
11084 
11085  exp_valid_block = NULL;
11086  val = value_addr (result);
11087  release_value (val);
11088  value_free_to_mark (mark);
11089 
11090  if (use_mask)
11091  {
11093  mask);
11094  if (ret == -1)
11095  error (_("This target does not support masked watchpoints."));
11096  else if (ret == -2)
11097  error (_("Invalid mask or memory region."));
11098  }
11099  }
11100  else if (val != NULL)
11101  release_value (val);
11102 
11103  tok = skip_spaces_const (arg);
11104  end_tok = skip_to_space_const (tok);
11105 
11106  toklen = end_tok - tok;
11107  if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
11108  {
11109  struct expression *cond;
11110 
11111  innermost_block = NULL;
11112  tok = cond_start = end_tok + 1;
11113  cond = parse_exp_1 (&tok, 0, 0, 0);
11114 
11115  /* The watchpoint expression may not be local, but the condition
11116  may still be. E.g.: `watch global if local > 0'. */
11117  cond_exp_valid_block = innermost_block;
11118 
11119  xfree (cond);
11120  cond_end = tok;
11121  }
11122  if (*tok)
11123  error (_("Junk at end of command."));
11124 
11125  frame = block_innermost_frame (exp_valid_block);
11126 
11127  /* If the expression is "local", then set up a "watchpoint scope"
11128  breakpoint at the point where we've left the scope of the watchpoint
11129  expression. Create the scope breakpoint before the watchpoint, so
11130  that we will encounter it first in bpstat_stop_status. */
11131  if (exp_valid_block && frame)
11132  {
11133  if (frame_id_p (frame_unwind_caller_id (frame)))
11134  {
11135  scope_breakpoint
11137  frame_unwind_caller_pc (frame),
11140 
11141  scope_breakpoint->enable_state = bp_enabled;
11142 
11143  /* Automatically delete the breakpoint when it hits. */
11144  scope_breakpoint->disposition = disp_del;
11145 
11146  /* Only break in the proper frame (help with recursion). */
11147  scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
11148 
11149  /* Set the address at which we will stop. */
11150  scope_breakpoint->loc->gdbarch
11151  = frame_unwind_caller_arch (frame);
11152  scope_breakpoint->loc->requested_address
11153  = frame_unwind_caller_pc (frame);
11154  scope_breakpoint->loc->address
11155  = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
11156  scope_breakpoint->loc->requested_address,
11157  scope_breakpoint->type);
11158  }
11159  }
11160 
11161  /* Now set up the breakpoint. We create all watchpoints as hardware
11162  watchpoints here even if hardware watchpoints are turned off, a call
11163  to update_watchpoint later in this function will cause the type to
11164  drop back to bp_watchpoint (software watchpoint) if required. */
11165 
11166  if (accessflag == hw_read)
11167  bp_type = bp_read_watchpoint;
11168  else if (accessflag == hw_access)
11169  bp_type = bp_access_watchpoint;
11170  else
11171  bp_type = bp_hardware_watchpoint;
11172 
11173  w = XCNEW (struct watchpoint);
11174  b = &w->base;
11175  if (use_mask)
11176  init_raw_breakpoint_without_location (b, NULL, bp_type,
11178  else
11179  init_raw_breakpoint_without_location (b, NULL, bp_type,
11181  b->thread = thread;
11184  w->exp = exp;
11185  w->exp_valid_block = exp_valid_block;
11186  w->cond_exp_valid_block = cond_exp_valid_block;
11187  if (just_location)
11188  {
11189  struct type *t = value_type (val);
11190  CORE_ADDR addr = value_as_address (val);
11191  char *name;
11192 
11194  name = type_to_string (t);
11195 
11196  w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11197  core_addr_to_string (addr));
11198  xfree (name);
11199 
11200  w->exp_string = xstrprintf ("-location %.*s",
11201  (int) (exp_end - exp_start), exp_start);
11202 
11203  /* The above expression is in C. */
11204  b->language = language_c;
11205  }
11206  else
11207  w->exp_string = savestring (exp_start, exp_end - exp_start);
11208 
11209  if (use_mask)
11210  {
11211  w->hw_wp_mask = mask;
11212  }
11213  else
11214  {
11215  w->val = val;
11216  w->val_bitpos = saved_bitpos;
11217  w->val_bitsize = saved_bitsize;
11218  w->val_valid = 1;
11219  }
11220 
11221  if (cond_start)
11222  b->cond_string = savestring (cond_start, cond_end - cond_start);
11223  else
11224  b->cond_string = 0;
11225 
11226  if (frame)
11227  {
11228  w->watchpoint_frame = get_frame_id (frame);
11230  }
11231  else
11232  {
11235  }
11236 
11237  if (scope_breakpoint != NULL)
11238  {
11239  /* The scope breakpoint is related to the watchpoint. We will
11240  need to act on them together. */
11241  b->related_breakpoint = scope_breakpoint;
11242  scope_breakpoint->related_breakpoint = b;
11243  }
11244 
11245  if (!just_location)
11246  value_free_to_mark (mark);
11247 
11248  TRY
11249  {
11250  /* Finally update the new watchpoint. This creates the locations
11251  that should be inserted. */
11252  update_watchpoint (w, 1);
11253  }
11254  CATCH (e, RETURN_MASK_ALL)
11255  {
11256  delete_breakpoint (b);
11257  throw_exception (e);
11258  }
11259  END_CATCH
11260 
11261  install_breakpoint (internal, b, 1);
11262  do_cleanups (back_to);
11263 }
11264 
11265 /* Return count of debug registers needed to watch the given expression.
11266  If the watchpoint cannot be handled in hardware return zero. */
11267 
11268 static int
11270 {
11271  int found_memory_cnt = 0;
11272  struct value *head = v;
11273 
11274  /* Did the user specifically forbid us to use hardware watchpoints? */
11275  if (!can_use_hw_watchpoints)
11276  return 0;
11277 
11278  /* Make sure that the value of the expression depends only upon
11279  memory contents, and values computed from them within GDB. If we
11280  find any register references or function calls, we can't use a
11281  hardware watchpoint.
11282 
11283  The idea here is that evaluating an expression generates a series
11284  of values, one holding the value of every subexpression. (The
11285  expression a*b+c has five subexpressions: a, b, a*b, c, and
11286  a*b+c.) GDB's values hold almost enough information to establish
11287  the criteria given above --- they identify memory lvalues,
11288  register lvalues, computed values, etcetera. So we can evaluate
11289  the expression, and then scan the chain of values that leaves
11290  behind to decide whether we can detect any possible change to the
11291  expression's final value using only hardware watchpoints.
11292 
11293  However, I don't think that the values returned by inferior
11294  function calls are special in any way. So this function may not
11295  notice that an expression involving an inferior function call
11296  can't be watched with hardware watchpoints. FIXME. */
11297  for (; v; v = value_next (v))
11298  {
11299  if (VALUE_LVAL (v) == lval_memory)
11300  {
11301  if (v != head && value_lazy (v))
11302  /* A lazy memory lvalue in the chain is one that GDB never
11303  needed to fetch; we either just used its address (e.g.,
11304  `a' in `a.b') or we never needed it at all (e.g., `a'
11305  in `a,b'). This doesn't apply to HEAD; if that is
11306  lazy then it was not readable, but watch it anyway. */
11307  ;
11308  else
11309  {
11310  /* Ahh, memory we actually used! Check if we can cover
11311  it with hardware watchpoints. */
11312  struct type *vtype = check_typedef (value_type (v));
11313 
11314  /* We only watch structs and arrays if user asked for it
11315  explicitly, never if they just happen to appear in a
11316  middle of some value chain. */
11317  if (v == head
11318  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
11319  && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
11320  {
11321  CORE_ADDR vaddr = value_address (v);
11322  int len;
11323  int num_regs;
11324 
11325  len = (target_exact_watchpoints
11326  && is_scalar_type_recursive (vtype))?
11327  1 : TYPE_LENGTH (value_type (v));
11328 
11329  num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11330  if (!num_regs)
11331  return 0;
11332  else
11333  found_memory_cnt += num_regs;
11334  }
11335  }
11336  }
11337  else if (VALUE_LVAL (v) != not_lval
11338  && deprecated_value_modifiable (v) == 0)
11339  return 0; /* These are values from the history (e.g., $1). */
11340  else if (VALUE_LVAL (v) == lval_register)
11341  return 0; /* Cannot watch a register with a HW watchpoint. */
11342  }
11343 
11344  /* The expression itself looks suitable for using a hardware
11345  watchpoint, but give the target machine a chance to reject it. */
11346  return found_memory_cnt;
11347 }
11348 
11349 void
11350 watch_command_wrapper (char *arg, int from_tty, int internal)
11351 {
11352  watch_command_1 (arg, hw_write, from_tty, 0, internal);
11353 }
11354 
11355 /* A helper function that looks for the "-location" argument and then
11356  calls watch_command_1. */
11357 
11358 static void
11359 watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11360 {
11361  int just_location = 0;
11362 
11363  if (arg
11364  && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11365  || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11366  {
11367  arg = skip_spaces (arg);
11368  just_location = 1;
11369  }
11370 
11371  watch_command_1 (arg, accessflag, from_tty, just_location, 0);
11372 }
11373 
11374 static void
11375 watch_command (char *arg, int from_tty)
11376 {
11377  watch_maybe_just_location (arg, hw_write, from_tty);
11378 }
11379 
11380 void
11381 rwatch_command_wrapper (char *arg, int from_tty, int internal)
11382 {
11383  watch_command_1 (arg, hw_read, from_tty, 0, internal);
11384 }
11385 
11386 static void
11387 rwatch_command (char *arg, int from_tty)
11388 {
11389  watch_maybe_just_location (arg, hw_read, from_tty);
11390 }
11391 
11392 void
11393 awatch_command_wrapper (char *arg, int from_tty, int internal)
11394 {
11395  watch_command_1 (arg, hw_access, from_tty, 0, internal);
11396 }
11397 
11398 static void
11399 awatch_command (char *arg, int from_tty)
11400 {
11401  watch_maybe_just_location (arg, hw_access, from_tty);
11402 }
11403 
11404 
11405 /* Helper routines for the until_command routine in infcmd.c. Here
11406  because it uses the mechanisms of breakpoints. */
11407 
11409 {
11411  struct breakpoint *breakpoint2;
11413 };
11414 
11415 /* This function is called by fetch_inferior_event via the
11416  cmd_continuation pointer, to complete the until command. It takes
11417  care of cleaning up the temporary breakpoints set up by the until
11418  command. */
11419 static void
11421 {
11422  struct until_break_command_continuation_args *a = arg;
11423 
11425  if (a->breakpoint2)
11428 }
11429 
11430 void
11431 until_break_command (char *arg, int from_tty, int anywhere)
11432 {
11433  struct symtabs_and_lines sals;
11434  struct symtab_and_line sal;
11435  struct frame_info *frame;
11436  struct gdbarch *frame_gdbarch;
11437  struct frame_id stack_frame_id;
11438  struct frame_id caller_frame_id;
11439  struct breakpoint *breakpoint;
11440  struct breakpoint *breakpoint2 = NULL;
11441  struct cleanup *old_chain;
11442  int thread;
11443  struct thread_info *tp;
11444 
11446 
11447  /* Set a breakpoint where the user wants it and at return from
11448  this function. */
11449 
11454  else
11456  (struct symtab *) NULL, 0);
11457 
11458  if (sals.nelts != 1)
11459  error (_("Couldn't get information on specified line."));
11460 
11461  sal = sals.sals[0];
11462  xfree (sals.sals); /* malloc'd, so freed. */
11463 
11464  if (*arg)
11465  error (_("Junk at end of arguments."));
11466 
11467  resolve_sal_pc (&sal);
11468 
11469  tp = inferior_thread ();
11470  thread = tp->num;
11471 
11472  old_chain = make_cleanup (null_cleanup, NULL);
11473 
11474  /* Note linespec handling above invalidates the frame chain.
11475  Installing a breakpoint also invalidates the frame chain (as it
11476  may need to switch threads), so do any frame handling before
11477  that. */
11478 
11479  frame = get_selected_frame (NULL);
11480  frame_gdbarch = get_frame_arch (frame);
11481  stack_frame_id = get_stack_frame_id (frame);
11482  caller_frame_id = frame_unwind_caller_id (frame);
11483 
11484  /* Keep within the current frame, or in frames called by the current
11485  one. */
11486 
11487  if (frame_id_p (caller_frame_id))
11488  {
11489  struct symtab_and_line sal2;
11490 
11491  sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11492  sal2.pc = frame_unwind_caller_pc (frame);
11493  breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11494  sal2,
11495  caller_frame_id,
11496  bp_until);
11497  make_cleanup_delete_breakpoint (breakpoint2);
11498 
11499  set_longjmp_breakpoint (tp, caller_frame_id);
11501  }
11502 
11503  /* set_momentary_breakpoint could invalidate FRAME. */
11504  frame = NULL;
11505 
11506  if (anywhere)
11507  /* If the user told us to continue until a specified location,
11508  we don't specify a frame at which we need to stop. */
11509  breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11511  else
11512  /* Otherwise, specify the selected frame, because we want to stop
11513  only at the very same frame. */
11514  breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11515  stack_frame_id, bp_until);
11516  make_cleanup_delete_breakpoint (breakpoint);
11517 
11518  proceed (-1, GDB_SIGNAL_DEFAULT);
11519 
11520  /* If we are running asynchronously, and proceed call above has
11521  actually managed to start the target, arrange for breakpoints to
11522  be deleted when the target stops. Otherwise, we're already
11523  stopped and delete breakpoints via cleanup chain. */
11524 
11526  {
11528  args = xmalloc (sizeof (*args));
11529 
11530  args->breakpoint = breakpoint;
11531  args->breakpoint2 = breakpoint2;
11532  args->thread_num = thread;
11533 
11534  discard_cleanups (old_chain);
11537  xfree);
11538  }
11539  else
11540  do_cleanups (old_chain);
11541 }
11542 
11543 /* This function attempts to parse an optional "if <cond>" clause
11544  from the arg string. If one is not found, it returns NULL.
11545 
11546  Else, it returns a pointer to the condition string. (It does not
11547  attempt to evaluate the string against a particular block.) And,
11548  it updates arg to point to the first character following the parsed
11549  if clause in the arg string. */
11550 
11551 char *
11553 {
11554  char *cond_string;
11555 
11556  if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
11557  return NULL;
11558 
11559  /* Skip the "if" keyword. */
11560  (*arg) += 2;
11561 
11562  /* Skip any extra leading whitespace, and record the start of the
11563  condition string. */
11564  *arg = skip_spaces (*arg);
11565  cond_string = *arg;
11566 
11567  /* Assume that the condition occupies the remainder of the arg
11568  string. */
11569  (*arg) += strlen (cond_string);
11570 
11571  return cond_string;
11572 }
11573 
11574 /* Commands to deal with catching events, such as signals, exceptions,
11575  process start/exit, etc. */
11576 
11577 typedef enum
11578 {
11581 }
11583 
11584 static void
11585 catch_fork_command_1 (char *arg, int from_tty,
11586  struct cmd_list_element *command)
11587 {
11588  struct gdbarch *gdbarch = get_current_arch ();
11589  char *cond_string = NULL;
11590  catch_fork_kind fork_kind;
11591  int tempflag;
11592 
11593  fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
11594  tempflag = (fork_kind == catch_fork_temporary
11595  || fork_kind == catch_vfork_temporary);
11596 
11597  if (!arg)
11598  arg = "";
11599  arg = skip_spaces (arg);
11600 
11601  /* The allowed syntax is:
11602  catch [v]fork
11603  catch [v]fork if <cond>
11604 
11605  First, check if there's an if clause. */
11606  cond_string = ep_parse_optional_if_clause (&arg);
11607 
11608  if ((*arg != '\0') && !isspace (*arg))
11609  error (_("Junk at end of arguments."));
11610 
11611  /* If this target supports it, create a fork or vfork catchpoint
11612  and enable reporting of such events. */
11613  switch (fork_kind)
11614  {
11615  case catch_fork_temporary:
11616  case catch_fork_permanent:
11617  create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11619  break;
11620  case catch_vfork_temporary:
11621  case catch_vfork_permanent:
11622  create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
11624  break;
11625  default:
11626  error (_("unsupported or unknown fork kind; cannot catch it"));
11627  break;
11628  }
11629 }
11630 
11631 static void
11632 catch_exec_command_1 (char *arg, int from_tty,
11633  struct cmd_list_element *command)
11634 {
11635  struct exec_catchpoint *c;
11636  struct gdbarch *gdbarch = get_current_arch ();
11637  int tempflag;
11638  char *cond_string = NULL;
11639 
11640  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11641 
11642  if (!arg)
11643  arg = "";
11644  arg = skip_spaces (arg);
11645 
11646  /* The allowed syntax is:
11647  catch exec
11648  catch exec if <cond>
11649 
11650  First, check if there's an if clause. */
11651  cond_string = ep_parse_optional_if_clause (&arg);
11652 
11653  if ((*arg != '\0') && !isspace (*arg))
11654  error (_("Junk at end of arguments."));
11655 
11656  c = XNEW (struct exec_catchpoint);
11657  init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11659  c->exec_pathname = NULL;
11660 
11661  install_breakpoint (0, &c->base, 1);
11662 }
11663 
11664 void
11666  struct gdbarch *gdbarch,
11667  struct symtab_and_line sal,
11668  char *addr_string,
11669  const struct breakpoint_ops *ops,
11670  int tempflag,
11671  int enabled,
11672  int from_tty)
11673 {
11674  if (from_tty)
11675  {
11676  struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11677  if (!loc_gdbarch)
11678  loc_gdbarch = gdbarch;
11679 
11680  describe_other_breakpoints (loc_gdbarch,
11681  sal.pspace, sal.pc, sal.section, -1);
11682  /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11683  version for exception catchpoints, because two catchpoints
11684  used for different exception names will use the same address.
11685  In this case, a "breakpoint ... also set at..." warning is
11686  unproductive. Besides, the warning phrasing is also a bit
11687  inappropriate, we should use the word catchpoint, and tell
11688  the user what type of catchpoint it is. The above is good
11689  enough for now, though. */
11690  }
11691 
11692  init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
11693 
11694  b->enable_state = enabled ? bp_enabled : bp_disabled;
11695  b->disposition = tempflag ? disp_del : disp_donttouch;
11696  b->addr_string = addr_string;
11697  b->language = language_ada;
11698 }
11699 
11700 static void
11701 catch_command (char *arg, int from_tty)
11702 {
11703  error (_("Catch requires an event name."));
11704 }
11705 
11706 
11707 static void
11708 tcatch_command (char *arg, int from_tty)
11709 {
11710  error (_("Catch requires an event name."));
11711 }
11712 
11713 /* A qsort comparison function that sorts breakpoints in order. */
11714 
11715 static int
11716 compare_breakpoints (const void *a, const void *b)
11717 {
11718  const breakpoint_p *ba = a;
11719  uintptr_t ua = (uintptr_t) *ba;
11720  const breakpoint_p *bb = b;
11721  uintptr_t ub = (uintptr_t) *bb;
11722 
11723  if ((*ba)->number < (*bb)->number)
11724  return -1;
11725  else if ((*ba)->number > (*bb)->number)
11726  return 1;
11727 
11728  /* Now sort by address, in case we see, e..g, two breakpoints with
11729  the number 0. */
11730  if (ua < ub)
11731  return -1;
11732  return ua > ub ? 1 : 0;
11733 }
11734 
11735 /* Delete breakpoints by address or line. */
11736 
11737 static void
11738 clear_command (char *arg, int from_tty)
11739 {
11740  struct breakpoint *b, *prev;
11741  VEC(breakpoint_p) *found = 0;
11742  int ix;
11743  int default_match;
11744  struct symtabs_and_lines sals;
11745  struct symtab_and_line sal;
11746  int i;
11747  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
11748 
11749  if (arg)
11750  {
11751  sals = decode_line_with_current_source (arg,
11754  make_cleanup (xfree, sals.sals);
11755  default_match = 0;
11756  }
11757  else
11758  {
11759  sals.sals = (struct symtab_and_line *)
11760  xmalloc (sizeof (struct symtab_and_line));
11761  make_cleanup (xfree, sals.sals);
11762  init_sal (&sal); /* Initialize to zeroes. */
11763 
11764  /* Set sal's line, symtab, pc, and pspace to the values
11765  corresponding to the last call to print_frame_info. If the
11766  codepoint is not valid, this will set all the fields to 0. */
11767  get_last_displayed_sal (&sal);
11768  if (sal.symtab == 0)
11769  error (_("No source file specified."));
11770 
11771  sals.sals[0] = sal;
11772  sals.nelts = 1;
11773 
11774  default_match = 1;
11775  }
11776 
11777  /* We don't call resolve_sal_pc here. That's not as bad as it
11778  seems, because all existing breakpoints typically have both
11779  file/line and pc set. So, if clear is given file/line, we can
11780  match this to existing breakpoint without obtaining pc at all.
11781 
11782  We only support clearing given the address explicitly
11783  present in breakpoint table. Say, we've set breakpoint
11784  at file:line. There were several PC values for that file:line,
11785  due to optimization, all in one block.
11786 
11787  We've picked one PC value. If "clear" is issued with another
11788  PC corresponding to the same file:line, the breakpoint won't
11789  be cleared. We probably can still clear the breakpoint, but
11790  since the other PC value is never presented to user, user
11791  can only find it by guessing, and it does not seem important
11792  to support that. */
11793 
11794  /* For each line spec given, delete bps which correspond to it. Do
11795  it in two passes, solely to preserve the current behavior that
11796  from_tty is forced true if we delete more than one
11797  breakpoint. */
11798 
11799  found = NULL;
11801  for (i = 0; i < sals.nelts; i++)
11802  {
11803  const char *sal_fullname;
11804 
11805  /* If exact pc given, clear bpts at that pc.
11806  If line given (pc == 0), clear all bpts on specified line.
11807  If defaulting, clear all bpts on default line
11808  or at default pc.
11809 
11810  defaulting sal.pc != 0 tests to do
11811 
11812  0 1 pc
11813  1 1 pc _and_ line
11814  0 0 line
11815  1 0 <can't happen> */
11816 
11817  sal = sals.sals[i];
11818  sal_fullname = (sal.symtab == NULL
11819  ? NULL : symtab_to_fullname (sal.symtab));
11820 
11821  /* Find all matching breakpoints and add them to 'found'. */
11822  ALL_BREAKPOINTS (b)
11823  {
11824  int match = 0;
11825  /* Are we going to delete b? */
11826  if (b->type != bp_none && !is_watchpoint (b))
11827  {
11828  struct bp_location *loc = b->loc;
11829  for (; loc; loc = loc->next)
11830  {
11831  /* If the user specified file:line, don't allow a PC
11832  match. This matches historical gdb behavior. */
11833  int pc_match = (!sal.explicit_line
11834  && sal.pc
11835  && (loc->pspace == sal.pspace)
11836  && (loc->address == sal.pc)
11837  && (!section_is_overlay (loc->section)
11838  || loc->section == sal.section));
11839  int line_match = 0;
11840 
11841  if ((default_match || sal.explicit_line)
11842  && loc->symtab != NULL
11843  && sal_fullname != NULL
11844  && sal.pspace == loc->pspace
11845  && loc->line_number == sal.line
11846  && filename_cmp (symtab_to_fullname (loc->symtab),
11847  sal_fullname) == 0)
11848  line_match = 1;
11849 
11850  if (pc_match || line_match)
11851  {
11852  match = 1;
11853  break;
11854  }
11855  }
11856  }
11857 
11858  if (match)
11859  VEC_safe_push(breakpoint_p, found, b);
11860  }
11861  }
11862 
11863  /* Now go thru the 'found' chain and delete them. */
11864  if (VEC_empty(breakpoint_p, found))
11865  {
11866  if (arg)
11867  error (_("No breakpoint at %s."), arg);
11868  else
11869  error (_("No breakpoint at this line."));
11870  }
11871 
11872  /* Remove duplicates from the vec. */
11873  qsort (VEC_address (breakpoint_p, found),
11874  VEC_length (breakpoint_p, found),
11875  sizeof (breakpoint_p),
11877  prev = VEC_index (breakpoint_p, found, 0);
11878  for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11879  {
11880  if (b == prev)
11881  {
11882  VEC_ordered_remove (breakpoint_p, found, ix);
11883  --ix;
11884  }
11885  }
11886 
11887  if (VEC_length(breakpoint_p, found) > 1)
11888  from_tty = 1; /* Always report if deleted more than one. */
11889  if (from_tty)
11890  {
11891  if (VEC_length(breakpoint_p, found) == 1)
11892  printf_unfiltered (_("Deleted breakpoint "));
11893  else
11894  printf_unfiltered (_("Deleted breakpoints "));
11895  }
11896 
11897  for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
11898  {
11899  if (from_tty)
11900  printf_unfiltered ("%d ", b->number);
11901  delete_breakpoint (b);
11902  }
11903  if (from_tty)
11904  putchar_unfiltered ('\n');
11905 
11906  do_cleanups (cleanups);
11907 }
11908 
11909 /* Delete breakpoint in BS if they are `delete' breakpoints and
11910  all breakpoints that are marked for deletion, whether hit or not.
11911  This is called after any breakpoint is hit, or after errors. */
11912 
11913 void
11915 {
11916  struct breakpoint *b, *b_tmp;
11917 
11918  for (; bs; bs = bs->next)
11919  if (bs->breakpoint_at
11921  && bs->stop)
11923 
11924  ALL_BREAKPOINTS_SAFE (b, b_tmp)
11925  {
11927  delete_breakpoint (b);
11928  }
11929 }
11930 
11931 /* A comparison function for bp_location AP and BP being interfaced to
11932  qsort. Sort elements primarily by their ADDRESS (no matter what
11933  does breakpoint_address_is_meaningful say for its OWNER),
11934  secondarily by ordering first permanent elements and
11935  terciarily just ensuring the array is sorted stable way despite
11936  qsort being an unstable algorithm. */
11937 
11938 static int
11939 bp_location_compare (const void *ap, const void *bp)
11940 {
11941  struct bp_location *a = *(void **) ap;
11942  struct bp_location *b = *(void **) bp;
11943 
11944  if (a->address != b->address)
11945  return (a->address > b->address) - (a->address < b->address);
11946 
11947  /* Sort locations at the same address by their pspace number, keeping
11948  locations of the same inferior (in a multi-inferior environment)
11949  grouped. */
11950 
11951  if (a->pspace->num != b->pspace->num)
11952  return ((a->pspace->num > b->pspace->num)
11953  - (a->pspace->num < b->pspace->num));
11954 
11955  /* Sort permanent breakpoints first. */
11956  if (a->permanent != b->permanent)
11957  return (a->permanent < b->permanent) - (a->permanent > b->permanent);
11958 
11959  /* Make the internal GDB representation stable across GDB runs
11960  where A and B memory inside GDB can differ. Breakpoint locations of
11961  the same type at the same address can be sorted in arbitrary order. */
11962 
11963  if (a->owner->number != b->owner->number)
11964  return ((a->owner->number > b->owner->number)
11965  - (a->owner->number < b->owner->number));
11966 
11967  return (a > b) - (a < b);
11968 }
11969 
11970 /* Set bp_location_placed_address_before_address_max and
11971  bp_location_shadow_len_after_address_max according to the current
11972  content of the bp_location array. */
11973 
11974 static void
11976 {
11977  struct bp_location *bl, **blp_tmp;
11978 
11979  bp_location_placed_address_before_address_max = 0;
11980  bp_location_shadow_len_after_address_max = 0;
11981 
11982  ALL_BP_LOCATIONS (bl, blp_tmp)
11983  {
11984  CORE_ADDR start, end, addr;
11985 
11986  if (!bp_location_has_shadow (bl))
11987  continue;
11988 
11989  start = bl->target_info.placed_address;
11990  end = start + bl->target_info.shadow_len;
11991 
11992  gdb_assert (bl->address >= start);
11993  addr = bl->address - start;
11994  if (addr > bp_location_placed_address_before_address_max)
11995  bp_location_placed_address_before_address_max = addr;
11996 
11997  /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11998 
11999  gdb_assert (bl->address < end);
12000  addr = end - bl->address;
12001  if (addr > bp_location_shadow_len_after_address_max)
12002  bp_location_shadow_len_after_address_max = addr;
12003  }
12004 }
12005 
12006 /* Download tracepoint locations if they haven't been. */
12007 
12008 static void
12010 {
12011  struct breakpoint *b;
12012  struct cleanup *old_chain;
12013 
12015  return;
12016 
12017  old_chain = save_current_space_and_thread ();
12018 
12019  ALL_TRACEPOINTS (b)
12020  {
12021  struct bp_location *bl;
12022  struct tracepoint *t;
12023  int bp_location_downloaded = 0;
12024 
12025  if ((b->type == bp_fast_tracepoint
12028  continue;
12029 
12030  for (bl = b->loc; bl; bl = bl->next)
12031  {
12032  /* In tracepoint, locations are _never_ duplicated, so
12033  should_be_inserted is equivalent to
12034  unduplicated_should_be_inserted. */
12035  if (!should_be_inserted (bl) || bl->inserted)
12036  continue;
12037 
12039 
12041 
12042  bl->inserted = 1;
12043  bp_location_downloaded = 1;
12044  }
12045  t = (struct tracepoint *) b;
12046  t->number_on_target = b->number;
12047  if (bp_location_downloaded)
12049  }
12050 
12051  do_cleanups (old_chain);
12052 }
12053 
12054 /* Swap the insertion/duplication state between two locations. */
12055 
12056 static void
12057 swap_insertion (struct bp_location *left, struct bp_location *right)
12058 {
12059  const int left_inserted = left->inserted;
12060  const int left_duplicate = left->duplicate;
12061  const int left_needs_update = left->needs_update;
12062  const struct bp_target_info left_target_info = left->target_info;
12063 
12064  /* Locations of tracepoints can never be duplicated. */
12065  if (is_tracepoint (left->owner))
12066  gdb_assert (!left->duplicate);
12067  if (is_tracepoint (right->owner))
12068  gdb_assert (!right->duplicate);
12069 
12070  left->inserted = right->inserted;
12071  left->duplicate = right->duplicate;
12072  left->needs_update = right->needs_update;
12073  left->target_info = right->target_info;
12074  right->inserted = left_inserted;
12075  right->duplicate = left_duplicate;
12076  right->needs_update = left_needs_update;
12077  right->target_info = left_target_info;
12078 }
12079 
12080 /* Force the re-insertion of the locations at ADDRESS. This is called
12081  once a new/deleted/modified duplicate location is found and we are evaluating
12082  conditions on the target's side. Such conditions need to be updated on
12083  the target. */
12084 
12085 static void
12086 force_breakpoint_reinsertion (struct bp_location *bl)
12087 {
12088  struct bp_location **locp = NULL, **loc2p;
12089  struct bp_location *loc;
12090  CORE_ADDR address = 0;
12091  int pspace_num;
12092 
12093  address = bl->address;
12094  pspace_num = bl->pspace->num;
12095 
12096  /* This is only meaningful if the target is
12097  evaluating conditions and if the user has
12098  opted for condition evaluation on the target's
12099  side. */
12102  return;
12103 
12104  /* Flag all breakpoint locations with this address and
12105  the same program space as the location
12106  as "its condition has changed". We need to
12107  update the conditions on the target's side. */
12108  ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12109  {
12110  loc = *loc2p;
12111 
12112  if (!is_breakpoint (loc->owner)
12113  || pspace_num != loc->pspace->num)
12114  continue;
12115 
12116  /* Flag the location appropriately. We use a different state to
12117  let everyone know that we already updated the set of locations
12118  with addr bl->address and program space bl->pspace. This is so
12119  we don't have to keep calling these functions just to mark locations
12120  that have already been marked. */
12122 
12123  /* Free the agent expression bytecode as well. We will compute
12124  it later on. */
12125  if (loc->cond_bytecode)
12126  {
12128  loc->cond_bytecode = NULL;
12129  }
12130  }
12131 }
12132 /* Called whether new breakpoints are created, or existing breakpoints
12133  deleted, to update the global location list and recompute which
12134  locations are duplicate of which.
12135 
12136  The INSERT_MODE flag determines whether locations may not, may, or
12137  shall be inserted now. See 'enum ugll_insert_mode' for more
12138  info. */
12139 
12140 static void
12142 {
12143  struct breakpoint *b;
12144  struct bp_location **locp, *loc;
12145  struct cleanup *cleanups;
12146  /* Last breakpoint location address that was marked for update. */
12147  CORE_ADDR last_addr = 0;
12148  /* Last breakpoint location program space that was marked for update. */
12149  int last_pspace_num = -1;
12150 
12151  /* Used in the duplicates detection below. When iterating over all
12152  bp_locations, points to the first bp_location of a given address.
12153  Breakpoints and watchpoints of different types are never
12154  duplicates of each other. Keep one pointer for each type of
12155  breakpoint/watchpoint, so we only need to loop over all locations
12156  once. */
12157  struct bp_location *bp_loc_first; /* breakpoint */
12158  struct bp_location *wp_loc_first; /* hardware watchpoint */
12159  struct bp_location *awp_loc_first; /* access watchpoint */
12160  struct bp_location *rwp_loc_first; /* read watchpoint */
12161 
12162  /* Saved former bp_location array which we compare against the newly
12163  built bp_location from the current state of ALL_BREAKPOINTS. */
12164  struct bp_location **old_location, **old_locp;
12165  unsigned old_location_count;
12166 
12167  old_location = bp_location;
12168  old_location_count = bp_location_count;
12169  bp_location = NULL;
12170  bp_location_count = 0;
12171  cleanups = make_cleanup (xfree, old_location);
12172 
12173  ALL_BREAKPOINTS (b)
12174  for (loc = b->loc; loc; loc = loc->next)
12175  bp_location_count++;
12176 
12177  bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12178  locp = bp_location;
12179  ALL_BREAKPOINTS (b)
12180  for (loc = b->loc; loc; loc = loc->next)
12181  *locp++ = loc;
12182  qsort (bp_location, bp_location_count, sizeof (*bp_location),
12184 
12186 
12187  /* Identify bp_location instances that are no longer present in the
12188  new list, and therefore should be freed. Note that it's not
12189  necessary that those locations should be removed from inferior --
12190  if there's another location at the same address (previously
12191  marked as duplicate), we don't need to remove/insert the
12192  location.
12193 
12194  LOCP is kept in sync with OLD_LOCP, each pointing to the current
12195  and former bp_location array state respectively. */
12196 
12197  locp = bp_location;
12198  for (old_locp = old_location; old_locp < old_location + old_location_count;
12199  old_locp++)
12200  {
12201  struct bp_location *old_loc = *old_locp;
12202  struct bp_location **loc2p;
12203 
12204  /* Tells if 'old_loc' is found among the new locations. If
12205  not, we have to free it. */
12206  int found_object = 0;
12207  /* Tells if the location should remain inserted in the target. */
12208  int keep_in_target = 0;
12209  int removed = 0;
12210 
12211  /* Skip LOCP entries which will definitely never be needed.
12212  Stop either at or being the one matching OLD_LOC. */
12213  while (locp < bp_location + bp_location_count
12214  && (*locp)->address < old_loc->address)
12215  locp++;
12216 
12217  for (loc2p = locp;
12218  (loc2p < bp_location + bp_location_count
12219  && (*loc2p)->address == old_loc->address);
12220  loc2p++)
12221  {
12222  /* Check if this is a new/duplicated location or a duplicated
12223  location that had its condition modified. If so, we want to send
12224  its condition to the target if evaluation of conditions is taking
12225  place there. */
12226  if ((*loc2p)->condition_changed == condition_modified
12227  && (last_addr != old_loc->address
12228  || last_pspace_num != old_loc->pspace->num))
12229  {
12231  last_pspace_num = old_loc->pspace->num;
12232  }
12233 
12234  if (*loc2p == old_loc)
12235  found_object = 1;
12236  }
12237 
12238  /* We have already handled this address, update it so that we don't
12239  have to go through updates again. */
12240  last_addr = old_loc->address;
12241 
12242  /* Target-side condition evaluation: Handle deleted locations. */
12243  if (!found_object)
12244  force_breakpoint_reinsertion (old_loc);
12245 
12246  /* If this location is no longer present, and inserted, look if
12247  there's maybe a new location at the same address. If so,
12248  mark that one inserted, and don't remove this one. This is
12249  needed so that we don't have a time window where a breakpoint
12250  at certain location is not inserted. */
12251 
12252  if (old_loc->inserted)
12253  {
12254  /* If the location is inserted now, we might have to remove
12255  it. */
12256 
12257  if (found_object && should_be_inserted (old_loc))
12258  {
12259  /* The location is still present in the location list,
12260  and still should be inserted. Don't do anything. */
12261  keep_in_target = 1;
12262  }
12263  else
12264  {
12265  /* This location still exists, but it won't be kept in the
12266  target since it may have been disabled. We proceed to
12267  remove its target-side condition. */
12268 
12269  /* The location is either no longer present, or got
12270  disabled. See if there's another location at the
12271  same address, in which case we don't need to remove
12272  this one from the target. */
12273 
12274  /* OLD_LOC comes from existing struct breakpoint. */
12275  if (breakpoint_address_is_meaningful (old_loc->owner))
12276  {
12277  for (loc2p = locp;
12278  (loc2p < bp_location + bp_location_count
12279  && (*loc2p)->address == old_loc->address);
12280  loc2p++)
12281  {
12282  struct bp_location *loc2 = *loc2p;
12283 
12284  if (breakpoint_locations_match (loc2, old_loc))
12285  {
12286  /* Read watchpoint locations are switched to
12287  access watchpoints, if the former are not
12288  supported, but the latter are. */
12289  if (is_hardware_watchpoint (old_loc->owner))
12290  {
12292  loc2->watchpoint_type = old_loc->watchpoint_type;
12293  }
12294 
12295  /* loc2 is a duplicated location. We need to check
12296  if it should be inserted in case it will be
12297  unduplicated. */
12298  if (loc2 != old_loc
12300  {
12301  swap_insertion (old_loc, loc2);
12302  keep_in_target = 1;
12303  break;
12304  }
12305  }
12306  }
12307  }
12308  }
12309 
12310  if (!keep_in_target)
12311  {
12312  if (remove_breakpoint (old_loc, mark_uninserted))
12313  {
12314  /* This is just about all we can do. We could keep
12315  this location on the global list, and try to
12316  remove it next time, but there's no particular
12317  reason why we will succeed next time.
12318 
12319  Note that at this point, old_loc->owner is still
12320  valid, as delete_breakpoint frees the breakpoint
12321  only after calling us. */
12322  printf_filtered (_("warning: Error removing "
12323  "breakpoint %d\n"),
12324  old_loc->owner->number);
12325  }
12326  removed = 1;
12327  }
12328  }
12329 
12330  if (!found_object)
12331  {
12332  if (removed && non_stop
12333  && need_moribund_for_location_type (old_loc))
12334  {
12335  /* This location was removed from the target. In
12336  non-stop mode, a race condition is possible where
12337  we've removed a breakpoint, but stop events for that
12338  breakpoint are already queued and will arrive later.
12339  We apply an heuristic to be able to distinguish such
12340  SIGTRAPs from other random SIGTRAPs: we keep this
12341  breakpoint location for a bit, and will retire it
12342  after we see some number of events. The theory here
12343  is that reporting of events should, "on the average",
12344  be fair, so after a while we'll see events from all
12345  threads that have anything of interest, and no longer
12346  need to keep this breakpoint location around. We
12347  don't hold locations forever so to reduce chances of
12348  mistaking a non-breakpoint SIGTRAP for a breakpoint
12349  SIGTRAP.
12350 
12351  The heuristic failing can be disastrous on
12352  decr_pc_after_break targets.
12353 
12354  On decr_pc_after_break targets, like e.g., x86-linux,
12355  if we fail to recognize a late breakpoint SIGTRAP,
12356  because events_till_retirement has reached 0 too
12357  soon, we'll fail to do the PC adjustment, and report
12358  a random SIGTRAP to the user. When the user resumes
12359  the inferior, it will most likely immediately crash
12360  with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12361  corrupted, because of being resumed e.g., in the
12362  middle of a multi-byte instruction, or skipped a
12363  one-byte instruction. This was actually seen happen
12364  on native x86-linux, and should be less rare on
12365  targets that do not support new thread events, like
12366  remote, due to the heuristic depending on
12367  thread_count.
12368 
12369  Mistaking a random SIGTRAP for a breakpoint trap
12370  causes similar symptoms (PC adjustment applied when
12371  it shouldn't), but then again, playing with SIGTRAPs
12372  behind the debugger's back is asking for trouble.
12373 
12374  Since hardware watchpoint traps are always
12375  distinguishable from other traps, so we don't need to
12376  apply keep hardware watchpoint moribund locations
12377  around. We simply always ignore hardware watchpoint
12378  traps we can no longer explain. */
12379 
12380  old_loc->events_till_retirement = 3 * (thread_count () + 1);
12381  old_loc->owner = NULL;
12382 
12383  VEC_safe_push (bp_location_p, moribund_locations, old_loc);
12384  }
12385  else
12386  {
12387  old_loc->owner = NULL;
12388  decref_bp_location (&old_loc);
12389  }
12390  }
12391  }
12392 
12393  /* Rescan breakpoints at the same address and section, marking the
12394  first one as "first" and any others as "duplicates". This is so
12395  that the bpt instruction is only inserted once. If we have a
12396  permanent breakpoint at the same place as BPT, make that one the
12397  official one, and the rest as duplicates. Permanent breakpoints
12398  are sorted first for the same address.
12399 
12400  Do the same for hardware watchpoints, but also considering the
12401  watchpoint's type (regular/access/read) and length. */
12402 
12403  bp_loc_first = NULL;
12404  wp_loc_first = NULL;
12405  awp_loc_first = NULL;
12406  rwp_loc_first = NULL;
12407  ALL_BP_LOCATIONS (loc, locp)
12408  {
12409  /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12410  non-NULL. */
12411  struct bp_location **loc_first_p;
12412  b = loc->owner;
12413 
12416  /* Don't detect duplicate for tracepoint locations because they are
12417  never duplicated. See the comments in field `duplicate' of
12418  `struct bp_location'. */
12419  || is_tracepoint (b))
12420  {
12421  /* Clear the condition modification flag. */
12423  continue;
12424  }
12425 
12426  if (b->type == bp_hardware_watchpoint)
12427  loc_first_p = &wp_loc_first;
12428  else if (b->type == bp_read_watchpoint)
12429  loc_first_p = &rwp_loc_first;
12430  else if (b->type == bp_access_watchpoint)
12431  loc_first_p = &awp_loc_first;
12432  else
12433  loc_first_p = &bp_loc_first;
12434 
12435  if (*loc_first_p == NULL
12436  || (overlay_debugging && loc->section != (*loc_first_p)->section)
12437  || !breakpoint_locations_match (loc, *loc_first_p))
12438  {
12439  *loc_first_p = loc;
12440  loc->duplicate = 0;
12441 
12442  if (is_breakpoint (loc->owner) && loc->condition_changed)
12443  {
12444  loc->needs_update = 1;
12445  /* Clear the condition modification flag. */
12447  }
12448  continue;
12449  }
12450 
12451 
12452  /* This and the above ensure the invariant that the first location
12453  is not duplicated, and is the inserted one.
12454  All following are marked as duplicated, and are not inserted. */
12455  if (loc->inserted)
12456  swap_insertion (loc, *loc_first_p);
12457  loc->duplicate = 1;
12458 
12459  /* Clear the condition modification flag. */
12461  }
12462 
12463  if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ())
12464  {
12465  if (insert_mode != UGLL_DONT_INSERT)
12467  else
12468  {
12469  /* Even though the caller told us to not insert new
12470  locations, we may still need to update conditions on the
12471  target's side of breakpoints that were already inserted
12472  if the target is evaluating breakpoint conditions. We
12473  only update conditions for locations that are marked
12474  "needs_update". */
12476  }
12477  }
12478 
12479  if (insert_mode != UGLL_DONT_INSERT)
12481 
12482  do_cleanups (cleanups);
12483 }
12484 
12485 void
12487 {
12488  struct bp_location *loc;
12489  int ix;
12490 
12491  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12492  if (--(loc->events_till_retirement) == 0)
12493  {
12494  decref_bp_location (&loc);
12495  VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12496  --ix;
12497  }
12498 }
12499 
12500 static void
12502 {
12503 
12504  TRY
12505  {
12506  update_global_location_list (insert_mode);
12507  }
12509  {
12510  }
12511  END_CATCH
12512 }
12513 
12514 /* Clear BKP from a BPS. */
12515 
12516 static void
12518 {
12519  bpstat bs;
12520 
12521  for (bs = bps; bs; bs = bs->next)
12522  if (bs->breakpoint_at == bpt)
12523  {
12524  bs->breakpoint_at = NULL;
12525  bs->old_val = NULL;
12526  /* bs->commands will be freed later. */
12527  }
12528 }
12529 
12530 /* Callback for iterate_over_threads. */
12531 static int
12533 {
12534  struct breakpoint *bpt = data;
12535 
12537  return 0;
12538 }
12539 
12540 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12541  callbacks. */
12542 
12543 static void
12545 {
12546  struct value_print_options opts;
12547 
12548  get_user_print_options (&opts);
12549 
12550  /* i18n: cagney/2005-02-11: Below needs to be merged into a
12551  single string. */
12552  if (b->loc == NULL)
12553  {
12554  printf_filtered (_(" (%s) pending."), b->addr_string);
12555  }
12556  else
12557  {
12558  if (opts.addressprint || b->loc->symtab == NULL)
12559  {
12560  printf_filtered (" at ");
12562  gdb_stdout);
12563  }
12564  if (b->loc->symtab != NULL)
12565  {
12566  /* If there is a single location, we can print the location
12567  more nicely. */
12568  if (b->loc->next == NULL)
12569  printf_filtered (": file %s, line %d.",
12571  b->loc->line_number);
12572  else
12573  /* This is not ideal, but each location may have a
12574  different file name, and this at least reflects the
12575  real situation somewhat. */
12576  printf_filtered (": %s.", b->addr_string);
12577  }
12578 
12579  if (b->loc->next)
12580  {
12581  struct bp_location *loc = b->loc;
12582  int n = 0;
12583  for (; loc; loc = loc->next)
12584  ++n;
12585  printf_filtered (" (%d locations)", n);
12586  }
12587  }
12588 }
12589 
12590 /* Default bp_location_ops methods. */
12591 
12592 static void
12593 bp_location_dtor (struct bp_location *self)
12594 {
12595  xfree (self->cond);
12596  if (self->cond_bytecode)
12597  free_agent_expr (self->cond_bytecode);
12598  xfree (self->function_name);
12599 
12600  VEC_free (agent_expr_p, self->target_info.conditions);
12601  VEC_free (agent_expr_p, self->target_info.tcommands);
12602 }
12603 
12604 static const struct bp_location_ops bp_location_ops =
12605 {
12607 };
12608 
12609 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12610  inherit from. */
12611 
12612 static void
12614 {
12615  decref_counted_command_line (&self->commands);
12616  xfree (self->cond_string);
12617  xfree (self->extra_string);
12618  xfree (self->addr_string);
12619  xfree (self->filter);
12620  xfree (self->addr_string_range_end);
12621 }
12622 
12623 static struct bp_location *
12625 {
12626  struct bp_location *loc;
12627 
12628  loc = XNEW (struct bp_location);
12629  init_bp_location (loc, &bp_location_ops, self);
12630  return loc;
12631 }
12632 
12633 static void
12635 {
12636  /* Nothing to re-set. */
12637 }
12638 
12639 #define internal_error_pure_virtual_called() \
12640  gdb_assert_not_reached ("pure virtual function called")
12641 
12642 static int
12643 base_breakpoint_insert_location (struct bp_location *bl)
12644 {
12646 }
12647 
12648 static int
12649 base_breakpoint_remove_location (struct bp_location *bl)
12650 {
12652 }
12653 
12654 static int
12655 base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12656  struct address_space *aspace,
12657  CORE_ADDR bp_addr,
12658  const struct target_waitstatus *ws)
12659 {
12661 }
12662 
12663 static void
12665 {
12666  /* Always stop. */
12667 }
12668 
12669 /* A "works_in_software_mode" breakpoint_ops method that just internal
12670  errors. */
12671 
12672 static int
12674 {
12676 }
12677 
12678 /* A "resources_needed" breakpoint_ops method that just internal
12679  errors. */
12680 
12681 static int
12682 base_breakpoint_resources_needed (const struct bp_location *bl)
12683 {
12685 }
12686 
12687 static enum print_stop_action
12689 {
12691 }
12692 
12693 static void
12695  struct ui_out *uiout)
12696 {
12697  /* nothing */
12698 }
12699 
12700 static void
12702 {
12704 }
12705 
12706 static void
12708 {
12710 }
12711 
12712 static void
12714  struct linespec_result *canonical,
12715  enum bptype type_wanted,
12716  char *addr_start,
12717  char **copy_arg)
12718 {
12720 }
12721 
12722 static void
12724  struct linespec_result *c,
12725  char *cond_string,
12726  char *extra_string,
12727  enum bptype type_wanted,
12728  enum bpdisp disposition,
12729  int thread,
12730  int task, int ignore_count,
12731  const struct breakpoint_ops *o,
12732  int from_tty, int enabled,
12733  int internal, unsigned flags)
12734 {
12736 }
12737 
12738 static void
12740  struct symtabs_and_lines *sals)
12741 {
12743 }
12744 
12745 /* The default 'explains_signal' method. */
12746 
12747 static int
12748 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
12749 {
12750  return 1;
12751 }
12752 
12753 /* The default "after_condition_true" method. */
12754 
12755 static void
12757 {
12758  /* Nothing to do. */
12759 }
12760 
12761 struct breakpoint_ops base_breakpoint_ops =
12762 {
12773  NULL,
12782 };
12783 
12784 /* Default breakpoint_ops methods. */
12785 
12786 static void
12788 {
12789  /* FIXME: is this still reachable? */
12790  if (b->addr_string == NULL)
12791  {
12792  /* Anything without a string can't be re-set. */
12793  delete_breakpoint (b);
12794  return;
12795  }
12796 
12798 }
12799 
12800 static int
12801 bkpt_insert_location (struct bp_location *bl)
12802 {
12804  return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
12805  else
12806  return target_insert_breakpoint (bl->gdbarch, &bl->target_info);
12807 }
12808 
12809 static int
12810 bkpt_remove_location (struct bp_location *bl)
12811 {
12813  return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12814  else
12815  return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12816 }
12817 
12818 static int
12819 bkpt_breakpoint_hit (const struct bp_location *bl,
12820  struct address_space *aspace, CORE_ADDR bp_addr,
12821  const struct target_waitstatus *ws)
12822 {
12823  if (ws->kind != TARGET_WAITKIND_STOPPED
12824  || ws->value.sig != GDB_SIGNAL_TRAP)
12825  return 0;
12826 
12828  aspace, bp_addr))
12829  return 0;
12830 
12831  if (overlay_debugging /* unmapped overlay section */
12832  && section_is_overlay (bl->section)
12833  && !section_is_mapped (bl->section))
12834  return 0;
12835 
12836  return 1;
12837 }
12838 
12839 static int
12840 dprintf_breakpoint_hit (const struct bp_location *bl,
12841  struct address_space *aspace, CORE_ADDR bp_addr,
12842  const struct target_waitstatus *ws)
12843 {
12844  if (dprintf_style == dprintf_style_agent
12846  {
12847  /* An agent-style dprintf never causes a stop. If we see a trap
12848  for this address it must be for a breakpoint that happens to
12849  be set at the same address. */
12850  return 0;
12851  }
12852 
12853  return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws);
12854 }
12855 
12856 static int
12857 bkpt_resources_needed (const struct bp_location *bl)
12858 {
12860 
12861  return 1;
12862 }
12863 
12864 static enum print_stop_action
12866 {
12867  struct breakpoint *b;
12868  const struct bp_location *bl;
12869  int bp_temp;
12870  struct ui_out *uiout = current_uiout;
12871 
12872  gdb_assert (bs->bp_location_at != NULL);
12873 
12874  bl = bs->bp_location_at;
12875  b = bs->breakpoint_at;
12876 
12877  bp_temp = b->disposition == disp_del;
12878  if (bl->address != bl->requested_address)
12880  bl->address,
12881  b->number, 1);
12883  if (bp_temp)
12884  ui_out_text (uiout, "\nTemporary breakpoint ");
12885  else
12886  ui_out_text (uiout, "\nBreakpoint ");
12887  if (ui_out_is_mi_like_p (uiout))
12888  {
12889  ui_out_field_string (uiout, "reason",
12891  ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
12892  }
12893  ui_out_field_int (uiout, "bkptno", b->number);
12894  ui_out_text (uiout, ", ");
12895 
12896  return PRINT_SRC_AND_LOC;
12897 }
12898 
12899 static void
12901 {
12903  return;
12904 
12905  switch (b->type)
12906  {
12907  case bp_breakpoint:
12908  case bp_gnu_ifunc_resolver:
12909  if (b->disposition == disp_del)
12910  printf_filtered (_("Temporary breakpoint"));
12911  else
12912  printf_filtered (_("Breakpoint"));
12913  printf_filtered (_(" %d"), b->number);
12914  if (b->type == bp_gnu_ifunc_resolver)
12915  printf_filtered (_(" at gnu-indirect-function resolver"));
12916  break;
12918  printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12919  break;
12920  case bp_dprintf:
12921  printf_filtered (_("Dprintf %d"), b->number);
12922  break;
12923  }
12924 
12925  say_where (b);
12926 }
12927 
12928 static void
12929 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12930 {
12931  if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12932  fprintf_unfiltered (fp, "tbreak");
12933  else if (tp->type == bp_breakpoint)
12934  fprintf_unfiltered (fp, "break");
12935  else if (tp->type == bp_hardware_breakpoint
12936  && tp->disposition == disp_del)
12937  fprintf_unfiltered (fp, "thbreak");
12938  else if (tp->type == bp_hardware_breakpoint)
12939  fprintf_unfiltered (fp, "hbreak");
12940  else
12941  internal_error (__FILE__, __LINE__,
12942  _("unhandled breakpoint type %d"), (int) tp->type);
12943 
12944  fprintf_unfiltered (fp, " %s", tp->addr_string);
12945  print_recreate_thread (tp, fp);
12946 }
12947 
12948 static void
12950  struct linespec_result *canonical,
12951  enum bptype type_wanted,
12952  char *addr_start, char **copy_arg)
12953 {
12954  create_sals_from_address_default (arg, canonical, type_wanted,
12955  addr_start, copy_arg);
12956 }
12957 
12958 static void
12960  struct linespec_result *canonical,
12961  char *cond_string,
12962  char *extra_string,
12963  enum bptype type_wanted,
12964  enum bpdisp disposition,
12965  int thread,
12966  int task, int ignore_count,
12967  const struct breakpoint_ops *ops,
12968  int from_tty, int enabled,
12969  int internal, unsigned flags)
12970 {
12971  create_breakpoints_sal_default (gdbarch, canonical,
12972  cond_string, extra_string,
12973  type_wanted,
12974  disposition, thread, task,
12975  ignore_count, ops, from_tty,
12976  enabled, internal, flags);
12977 }
12978 
12979 static void
12980 bkpt_decode_linespec (struct breakpoint *b, char **s,
12981  struct symtabs_and_lines *sals)
12982 {
12983  decode_linespec_default (b, s, sals);
12984 }
12985 
12986 /* Virtual table for internal breakpoints. */
12987 
12988 static void
12990 {
12991  switch (b->type)
12992  {
12993  /* Delete overlay event and longjmp master breakpoints; they
12994  will be reset later by breakpoint_re_set. */
12995  case bp_overlay_event:
12996  case bp_longjmp_master:
12998  case bp_exception_master:
12999  delete_breakpoint (b);
13000  break;
13001 
13002  /* This breakpoint is special, it's set up when the inferior
13003  starts and we really don't want to touch it. */
13004  case bp_shlib_event:
13005 
13006  /* Like bp_shlib_event, this breakpoint type is special. Once
13007  it is set up, we do not want to touch it. */
13008  case bp_thread_event:
13009  break;
13010  }
13011 }
13012 
13013 static void
13015 {
13016  if (bs->breakpoint_at->type == bp_shlib_event)
13017  {
13018  /* If requested, stop when the dynamic linker notifies GDB of
13019  events. This allows the user to get control and place
13020  breakpoints in initializer routines for dynamically loaded
13021  objects (among other things). */
13022  bs->stop = stop_on_solib_events;
13024  }
13025  else
13026  bs->stop = 0;
13027 }
13028 
13029 static enum print_stop_action
13031 {
13032  struct breakpoint *b;
13033 
13034  b = bs->breakpoint_at;
13035 
13036  switch (b->type)
13037  {
13038  case bp_shlib_event:
13039  /* Did we stop because the user set the stop_on_solib_events
13040  variable? (If so, we report this as a generic, "Stopped due
13041  to shlib event" message.) */
13042  print_solib_event (0);
13043  break;
13044 
13045  case bp_thread_event:
13046  /* Not sure how we will get here.
13047  GDB should not stop for these breakpoints. */
13048  printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13049  break;
13050 
13051  case bp_overlay_event:
13052  /* By analogy with the thread event, GDB should not stop for these. */
13053  printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13054  break;
13055 
13056  case bp_longjmp_master:
13057  /* These should never be enabled. */
13058  printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13059  break;
13060 
13062  /* These should never be enabled. */
13063  printf_filtered (_("std::terminate Master Breakpoint: "
13064  "gdb should not stop!\n"));
13065  break;
13066 
13067  case bp_exception_master:
13068  /* These should never be enabled. */
13069  printf_filtered (_("Exception Master Breakpoint: "
13070  "gdb should not stop!\n"));
13071  break;
13072  }
13073 
13074  return PRINT_NOTHING;
13075 }
13076 
13077 static void
13079 {
13080  /* Nothing to mention. These breakpoints are internal. */
13081 }
13082 
13083 /* Virtual table for momentary breakpoints */
13084 
13085 static void
13087 {
13088  /* Keep temporary breakpoints, which can be encountered when we step
13089  over a dlopen call and solib_add is resetting the breakpoints.
13090  Otherwise these should have been blown away via the cleanup chain
13091  or by breakpoint_init_inferior when we rerun the executable. */
13092 }
13093 
13094 static void
13096 {
13097  /* Nothing. The point of these breakpoints is causing a stop. */
13098 }
13099 
13100 static enum print_stop_action
13102 {
13103  struct ui_out *uiout = current_uiout;
13104 
13105  if (ui_out_is_mi_like_p (uiout))
13106  {
13107  struct breakpoint *b = bs->breakpoint_at;
13108 
13109  switch (b->type)
13110  {
13111  case bp_finish:
13113  (uiout, "reason",
13115  break;
13116 
13117  case bp_until:
13119  (uiout, "reason",
13121  break;
13122  }
13123  }
13124 
13125  return PRINT_UNKNOWN;
13126 }
13127 
13128 static void
13130 {
13131  /* Nothing to mention. These breakpoints are internal. */
13132 }
13133 
13134 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13135 
13136  It gets cleared already on the removal of the first one of such placed
13137  breakpoints. This is OK as they get all removed altogether. */
13138 
13139 static void
13141 {
13142  struct thread_info *tp = find_thread_id (self->thread);
13143 
13144  if (tp)
13146 
13148 }
13149 
13150 /* Specific methods for probe breakpoints. */
13151 
13152 static int
13153 bkpt_probe_insert_location (struct bp_location *bl)
13154 {
13155  int v = bkpt_insert_location (bl);
13156 
13157  if (v == 0)
13158  {
13159  /* The insertion was successful, now let's set the probe's semaphore
13160  if needed. */
13161  if (bl->probe.probe->pops->set_semaphore != NULL)
13162  bl->probe.probe->pops->set_semaphore (bl->probe.probe,
13163  bl->probe.objfile,
13164  bl->gdbarch);
13165  }
13166 
13167  return v;
13168 }
13169 
13170 static int
13171 bkpt_probe_remove_location (struct bp_location *bl)
13172 {
13173  /* Let's clear the semaphore before removing the location. */
13174  if (bl->probe.probe->pops->clear_semaphore != NULL)
13176  bl->probe.objfile,
13177  bl->gdbarch);
13178 
13179  return bkpt_remove_location (bl);
13180 }
13181 
13182 static void
13184  struct linespec_result *canonical,
13185  enum bptype type_wanted,
13186  char *addr_start, char **copy_arg)
13187 {
13188  struct linespec_sals lsal;
13189 
13190  lsal.sals = parse_probes (arg, canonical);
13191 
13192  *copy_arg = xstrdup (canonical->addr_string);
13193  lsal.canonical = xstrdup (*copy_arg);
13194 
13195  VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13196 }
13197 
13198 static void
13200  struct symtabs_and_lines *sals)
13201 {
13202  *sals = parse_probes (s, NULL);
13203  if (!sals->sals)
13204  error (_("probe not found"));
13205 }
13206 
13207 /* The breakpoint_ops structure to be used in tracepoints. */
13208 
13209 static void
13211 {
13213 }
13214 
13215 static int
13216 tracepoint_breakpoint_hit (const struct bp_location *bl,
13217  struct address_space *aspace, CORE_ADDR bp_addr,
13218  const struct target_waitstatus *ws)
13219 {
13220  /* By definition, the inferior does not report stops at
13221  tracepoints. */
13222  return 0;
13223 }
13224 
13225 static void
13227  struct ui_out *uiout)
13228 {
13229  struct tracepoint *tp = (struct tracepoint *) self;
13230  if (tp->static_trace_marker_id)
13231  {
13232  gdb_assert (self->type == bp_static_tracepoint);
13233 
13234  ui_out_text (uiout, "\tmarker id is ");
13235  ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13237  ui_out_text (uiout, "\n");
13238  }
13239 }
13240 
13241 static void
13243 {
13245  return;
13246 
13247  switch (b->type)
13248  {
13249  case bp_tracepoint:
13250  printf_filtered (_("Tracepoint"));
13251  printf_filtered (_(" %d"), b->number);
13252  break;
13253  case bp_fast_tracepoint:
13254  printf_filtered (_("Fast tracepoint"));
13255  printf_filtered (_(" %d"), b->number);
13256  break;
13257  case bp_static_tracepoint:
13258  printf_filtered (_("Static tracepoint"));
13259  printf_filtered (_(" %d"), b->number);
13260  break;
13261  default:
13262  internal_error (__FILE__, __LINE__,
13263  _("unhandled tracepoint type %d"), (int) b->type);
13264  }
13265 
13266  say_where (b);
13267 }
13268 
13269 static void
13271 {
13272  struct tracepoint *tp = (struct tracepoint *) self;
13273 
13274  if (self->type == bp_fast_tracepoint)
13275  fprintf_unfiltered (fp, "ftrace");
13276  if (self->type == bp_static_tracepoint)
13277  fprintf_unfiltered (fp, "strace");
13278  else if (self->type == bp_tracepoint)
13279  fprintf_unfiltered (fp, "trace");
13280  else
13281  internal_error (__FILE__, __LINE__,
13282  _("unhandled tracepoint type %d"), (int) self->type);
13283 
13284  fprintf_unfiltered (fp, " %s", self->addr_string);
13285  print_recreate_thread (self, fp);
13286 
13287  if (tp->pass_count)
13288  fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
13289 }
13290 
13291 static void
13293  struct linespec_result *canonical,
13294  enum bptype type_wanted,
13295  char *addr_start, char **copy_arg)
13296 {
13297  create_sals_from_address_default (arg, canonical, type_wanted,
13298  addr_start, copy_arg);
13299 }
13300 
13301 static void
13303  struct linespec_result *canonical,
13304  char *cond_string,
13305  char *extra_string,
13306  enum bptype type_wanted,
13307  enum bpdisp disposition,
13308  int thread,
13309  int task, int ignore_count,
13310  const struct breakpoint_ops *ops,
13311  int from_tty, int enabled,
13312  int internal, unsigned flags)
13313 {
13314  create_breakpoints_sal_default (gdbarch, canonical,
13315  cond_string, extra_string,
13316  type_wanted,
13317  disposition, thread, task,
13318  ignore_count, ops, from_tty,
13319  enabled, internal, flags);
13320 }
13321 
13322 static void
13324  struct symtabs_and_lines *sals)
13325 {
13326  decode_linespec_default (b, s, sals);
13327 }
13328 
13330 
13331 /* The breakpoint_ops structure to be use on tracepoints placed in a
13332  static probe. */
13333 
13334 static void
13336  struct linespec_result *canonical,
13337  enum bptype type_wanted,
13338  char *addr_start, char **copy_arg)
13339 {
13340  /* We use the same method for breakpoint on probes. */
13341  bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13342  addr_start, copy_arg);
13343 }
13344 
13345 static void
13347  struct symtabs_and_lines *sals)
13348 {
13349  /* We use the same method for breakpoint on probes. */
13350  bkpt_probe_decode_linespec (b, s, sals);
13351 }
13352 
13354 
13355 /* Dprintf breakpoint_ops methods. */
13356 
13357 static void
13359 {
13361 
13362  /* This breakpoint could have been pending, and be resolved now, and
13363  if so, we should now have the extra string. If we don't, the
13364  dprintf was malformed when created, but we couldn't tell because
13365  we can't extract the extra string until the location is
13366  resolved. */
13367  if (b->loc != NULL && b->extra_string == NULL)
13368  error (_("Format string required"));
13369 
13370  /* 1 - connect to target 1, that can run breakpoint commands.
13371  2 - create a dprintf, which resolves fine.
13372  3 - disconnect from target 1
13373  4 - connect to target 2, that can NOT run breakpoint commands.
13374 
13375  After steps #3/#4, you'll want the dprintf command list to
13376  be updated, because target 1 and 2 may well return different
13377  answers for target_can_run_breakpoint_commands().
13378  Given absence of finer grained resetting, we get to do
13379  it all the time. */
13380  if (b->extra_string != NULL)
13382 }
13383 
13384 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13385 
13386 static void
13388 {
13389  fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
13390  tp->extra_string);
13391  print_recreate_thread (tp, fp);
13392 }
13393 
13394 /* Implement the "after_condition_true" breakpoint_ops method for
13395  dprintf.
13396 
13397  dprintf's are implemented with regular commands in their command
13398  list, but we run the commands here instead of before presenting the
13399  stop to the user, as dprintf's don't actually cause a stop. This
13400  also makes it so that the commands of multiple dprintfs at the same
13401  address are all handled. */
13402 
13403 static void
13405 {
13406  struct cleanup *old_chain;
13407  struct bpstats tmp_bs = { NULL };
13408  struct bpstats *tmp_bs_p = &tmp_bs;
13409 
13410  /* dprintf's never cause a stop. This wasn't set in the
13411  check_status hook instead because that would make the dprintf's
13412  condition not be evaluated. */
13413  bs->stop = 0;
13414 
13415  /* Run the command list here. Take ownership of it instead of
13416  copying. We never want these commands to run later in
13417  bpstat_do_actions, if a breakpoint that causes a stop happens to
13418  be set at same address as this dprintf, or even if running the
13419  commands here throws. */
13420  tmp_bs.commands = bs->commands;
13421  bs->commands = NULL;
13422  old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13423 
13424  bpstat_do_actions_1 (&tmp_bs_p);
13425 
13426  /* 'tmp_bs.commands' will usually be NULL by now, but
13427  bpstat_do_actions_1 may return early without processing the whole
13428  list. */
13429  do_cleanups (old_chain);
13430 }
13431 
13432 /* The breakpoint_ops structure to be used on static tracepoints with
13433  markers (`-m'). */
13434 
13435 static void
13437  struct linespec_result *canonical,
13438  enum bptype type_wanted,
13439  char *addr_start, char **copy_arg)
13440 {
13441  struct linespec_sals lsal;
13442 
13443  lsal.sals = decode_static_tracepoint_spec (arg);
13444 
13445  *copy_arg = savestring (addr_start, *arg - addr_start);
13446 
13447  canonical->addr_string = xstrdup (*copy_arg);
13448  lsal.canonical = xstrdup (*copy_arg);
13449  VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13450 }
13451 
13452 static void
13454  struct linespec_result *canonical,
13455  char *cond_string,
13456  char *extra_string,
13457  enum bptype type_wanted,
13458  enum bpdisp disposition,
13459  int thread,
13460  int task, int ignore_count,
13461  const struct breakpoint_ops *ops,
13462  int from_tty, int enabled,
13463  int internal, unsigned flags)
13464 {
13465  int i;
13466  struct linespec_sals *lsal = VEC_index (linespec_sals,
13467  canonical->sals, 0);
13468 
13469  /* If the user is creating a static tracepoint by marker id
13470  (strace -m MARKER_ID), then store the sals index, so that
13471  breakpoint_re_set can try to match up which of the newly
13472  found markers corresponds to this one, and, don't try to
13473  expand multiple locations for each sal, given than SALS
13474  already should contain all sals for MARKER_ID. */
13475 
13476  for (i = 0; i < lsal->sals.nelts; ++i)
13477  {
13478  struct symtabs_and_lines expanded;
13479  struct tracepoint *tp;
13480  struct cleanup *old_chain;
13481  char *addr_string;
13482 
13483  expanded.nelts = 1;
13484  expanded.sals = &lsal->sals.sals[i];
13485 
13486  addr_string = xstrdup (canonical->addr_string);
13487  old_chain = make_cleanup (xfree, addr_string);
13488 
13489  tp = XCNEW (struct tracepoint);
13490  init_breakpoint_sal (&tp->base, gdbarch, expanded,
13491  addr_string, NULL,
13492  cond_string, extra_string,
13493  type_wanted, disposition,
13494  thread, task, ignore_count, ops,
13495  from_tty, enabled, internal, flags,
13496  canonical->special_display);
13497  /* Given that its possible to have multiple markers with
13498  the same string id, if the user is creating a static
13499  tracepoint by marker id ("strace -m MARKER_ID"), then
13500  store the sals index, so that breakpoint_re_set can
13501  try to match up which of the newly found markers
13502  corresponds to this one */
13504 
13505  install_breakpoint (internal, &tp->base, 0);
13506 
13507  discard_cleanups (old_chain);
13508  }
13509 }
13510 
13511 static void
13513  struct symtabs_and_lines *sals)
13514 {
13515  struct tracepoint *tp = (struct tracepoint *) b;
13516 
13517  *sals = decode_static_tracepoint_spec (s);
13518  if (sals->nelts > tp->static_trace_marker_id_idx)
13519  {
13520  sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13521  sals->nelts = 1;
13522  }
13523  else
13524  error (_("marker %s not found"), tp->static_trace_marker_id);
13525 }
13526 
13528 
13529 static int
13531 {
13532  return b->ops == &strace_marker_breakpoint_ops;
13533 }
13534 
13535 /* Delete a breakpoint and clean up all traces of it in the data
13536  structures. */
13537 
13538 void
13540 {
13541  struct breakpoint *b;
13542 
13543  gdb_assert (bpt != NULL);
13544 
13545  /* Has this bp already been deleted? This can happen because
13546  multiple lists can hold pointers to bp's. bpstat lists are
13547  especial culprits.
13548 
13549  One example of this happening is a watchpoint's scope bp. When
13550  the scope bp triggers, we notice that the watchpoint is out of
13551  scope, and delete it. We also delete its scope bp. But the
13552  scope bp is marked "auto-deleting", and is already on a bpstat.
13553  That bpstat is then checked for auto-deleting bp's, which are
13554  deleted.
13555 
13556  A real solution to this problem might involve reference counts in
13557  bp's, and/or giving them pointers back to their referencing
13558  bpstat's, and teaching delete_breakpoint to only free a bp's
13559  storage when no more references were extent. A cheaper bandaid
13560  was chosen. */
13561  if (bpt->type == bp_none)
13562  return;
13563 
13564  /* At least avoid this stale reference until the reference counting
13565  of breakpoints gets resolved. */
13566  if (bpt->related_breakpoint != bpt)
13567  {
13568  struct breakpoint *related;
13569  struct watchpoint *w;
13570 
13571  if (bpt->type == bp_watchpoint_scope)
13572  w = (struct watchpoint *) bpt->related_breakpoint;
13574  w = (struct watchpoint *) bpt;
13575  else
13576  w = NULL;
13577  if (w != NULL)
13579 
13580  /* Unlink bpt from the bpt->related_breakpoint ring. */
13581  for (related = bpt; related->related_breakpoint != bpt;
13582  related = related->related_breakpoint);
13583  related->related_breakpoint = bpt->related_breakpoint;
13584  bpt->related_breakpoint = bpt;
13585  }
13586 
13587  /* watch_command_1 creates a watchpoint but only sets its number if
13588  update_watchpoint succeeds in creating its bp_locations. If there's
13589  a problem in that process, we'll be asked to delete the half-created
13590  watchpoint. In that case, don't announce the deletion. */
13591  if (bpt->number)
13593 
13594  if (breakpoint_chain == bpt)
13595  breakpoint_chain = bpt->next;
13596 
13597  ALL_BREAKPOINTS (b)
13598  if (b->next == bpt)
13599  {
13600  b->next = bpt->next;
13601  break;
13602  }
13603 
13604  /* Be sure no bpstat's are pointing at the breakpoint after it's
13605  been freed. */
13606  /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13607  in all threads for now. Note that we cannot just remove bpstats
13608  pointing at bpt from the stop_bpstat list entirely, as breakpoint
13609  commands are associated with the bpstat; if we remove it here,
13610  then the later call to bpstat_do_actions (&stop_bpstat); in
13611  event-top.c won't do anything, and temporary breakpoints with
13612  commands won't work. */
13613 
13615 
13616  /* Now that breakpoint is removed from breakpoint list, update the
13617  global location list. This will remove locations that used to
13618  belong to this breakpoint. Do this before freeing the breakpoint
13619  itself, since remove_breakpoint looks at location's owner. It
13620  might be better design to have location completely
13621  self-contained, but it's not the case now. */
13623 
13624  bpt->ops->dtor (bpt);
13625  /* On the chance that someone will soon try again to delete this
13626  same bp, we mark it as deleted before freeing its storage. */
13627  bpt->type = bp_none;
13628  xfree (bpt);
13629 }
13630 
13631 static void
13633 {
13634  delete_breakpoint (b);
13635 }
13636 
13637 struct cleanup *
13639 {
13641 }
13642 
13643 /* Iterator function to call a user-provided callback function once
13644  for each of B and its related breakpoints. */
13645 
13646 static void
13648  void (*function) (struct breakpoint *,
13649  void *),
13650  void *data)
13651 {
13652  struct breakpoint *related;
13653 
13654  related = b;
13655  do
13656  {
13657  struct breakpoint *next;
13658 
13659  /* FUNCTION may delete RELATED. */
13660  next = related->related_breakpoint;
13661 
13662  if (next == related)
13663  {
13664  /* RELATED is the last ring entry. */
13665  function (related, data);
13666 
13667  /* FUNCTION may have deleted it, so we'd never reach back to
13668  B. There's nothing left to do anyway, so just break
13669  out. */
13670  break;
13671  }
13672  else
13673  function (related, data);
13674 
13675  related = next;
13676  }
13677  while (related != b);
13678 }
13679 
13680 static void
13682 {
13683  delete_breakpoint (b);
13684 }
13685 
13686 /* A callback for map_breakpoint_numbers that calls
13687  delete_breakpoint. */
13688 
13689 static void
13691 {
13693 }
13694 
13695 void
13696 delete_command (char *arg, int from_tty)
13697 {
13698  struct breakpoint *b, *b_tmp;
13699 
13700  dont_repeat ();
13701 
13702  if (arg == 0)
13703  {
13704  int breaks_to_delete = 0;
13705 
13706  /* Delete all breakpoints if no argument. Do not delete
13707  internal breakpoints, these have to be deleted with an
13708  explicit breakpoint number argument. */
13709  ALL_BREAKPOINTS (b)
13710  if (user_breakpoint_p (b))
13711  {
13712  breaks_to_delete = 1;
13713  break;
13714  }
13715 
13716  /* Ask user only if there are some breakpoints to delete. */
13717  if (!from_tty
13718  || (breaks_to_delete && query (_("Delete all breakpoints? "))))
13719  {
13720  ALL_BREAKPOINTS_SAFE (b, b_tmp)
13721  if (user_breakpoint_p (b))
13722  delete_breakpoint (b);
13723  }
13724  }
13725  else
13727 }
13728 
13729 static int
13730 all_locations_are_pending (struct bp_location *loc)
13731 {
13732  for (; loc; loc = loc->next)
13733  if (!loc->shlib_disabled
13734  && !loc->pspace->executing_startup)
13735  return 0;
13736  return 1;
13737 }
13738 
13739 /* Subroutine of update_breakpoint_locations to simplify it.
13740  Return non-zero if multiple fns in list LOC have the same name.
13741  Null names are ignored. */
13742 
13743 static int
13744 ambiguous_names_p (struct bp_location *loc)
13745 {
13746  struct bp_location *l;
13747  htab_t htab = htab_create_alloc (13, htab_hash_string,
13748  (int (*) (const void *,
13749  const void *)) streq,
13750  NULL, xcalloc, xfree);
13751 
13752  for (l = loc; l != NULL; l = l->next)
13753  {
13754  const char **slot;
13755  const char *name = l->function_name;
13756 
13757  /* Allow for some names to be NULL, ignore them. */
13758  if (name == NULL)
13759  continue;
13760 
13761  slot = (const char **) htab_find_slot (htab, (const void *) name,
13762  INSERT);
13763  /* NOTE: We can assume slot != NULL here because xcalloc never
13764  returns NULL. */
13765  if (*slot != NULL)
13766  {
13767  htab_delete (htab);
13768  return 1;
13769  }
13770  *slot = name;
13771  }
13772 
13773  htab_delete (htab);
13774  return 0;
13775 }
13776 
13777 /* When symbols change, it probably means the sources changed as well,
13778  and it might mean the static tracepoint markers are no longer at
13779  the same address or line numbers they used to be at last we
13780  checked. Losing your static tracepoints whenever you rebuild is
13781  undesirable. This function tries to resync/rematch gdb static
13782  tracepoints with the markers on the target, for static tracepoints
13783  that have not been set by marker id. Static tracepoint that have
13784  been set by marker id are reset by marker id in breakpoint_re_set.
13785  The heuristic is:
13786 
13787  1) For a tracepoint set at a specific address, look for a marker at
13788  the old PC. If one is found there, assume to be the same marker.
13789  If the name / string id of the marker found is different from the
13790  previous known name, assume that means the user renamed the marker
13791  in the sources, and output a warning.
13792 
13793  2) For a tracepoint set at a given line number, look for a marker
13794  at the new address of the old line number. If one is found there,
13795  assume to be the same marker. If the name / string id of the
13796  marker found is different from the previous known name, assume that
13797  means the user renamed the marker in the sources, and output a
13798  warning.
13799 
13800  3) If a marker is no longer found at the same address or line, it
13801  may mean the marker no longer exists. But it may also just mean
13802  the code changed a bit. Maybe the user added a few lines of code
13803  that made the marker move up or down (in line number terms). Ask
13804  the target for info about the marker with the string id as we knew
13805  it. If found, update line number and address in the matching
13806  static tracepoint. This will get confused if there's more than one
13807  marker with the same ID (possible in UST, although unadvised
13808  precisely because it confuses tools). */
13809 
13810 static struct symtab_and_line
13812 {
13813  struct tracepoint *tp = (struct tracepoint *) b;
13814  struct static_tracepoint_marker marker;
13815  CORE_ADDR pc;
13816 
13817  pc = sal.pc;
13818  if (sal.line)
13819  find_line_pc (sal.symtab, sal.line, &pc);
13820 
13821  if (target_static_tracepoint_marker_at (pc, &marker))
13822  {
13823  if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
13824  warning (_("static tracepoint %d changed probed marker from %s to %s"),
13825  b->number,
13826  tp->static_trace_marker_id, marker.str_id);
13827 
13829  tp->static_trace_marker_id = xstrdup (marker.str_id);
13831 
13832  return sal;
13833  }
13834 
13835  /* Old marker wasn't found on target at lineno. Try looking it up
13836  by string ID. */
13837  if (!sal.explicit_pc
13838  && sal.line != 0
13839  && sal.symtab != NULL
13840  && tp->static_trace_marker_id != NULL)
13841  {
13842  VEC(static_tracepoint_marker_p) *markers;
13843 
13844  markers
13846 
13847  if (!VEC_empty(static_tracepoint_marker_p, markers))
13848  {
13849  struct symtab_and_line sal2;
13850  struct symbol *sym;
13851  struct static_tracepoint_marker *tpmarker;
13852  struct ui_out *uiout = current_uiout;
13853 
13854  tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
13855 
13857  tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
13858 
13859  warning (_("marker for static tracepoint %d (%s) not "
13860  "found at previous line number"),
13861  b->number, tp->static_trace_marker_id);
13862 
13863  init_sal (&sal2);
13864 
13865  sal2.pc = tpmarker->address;
13866 
13867  sal2 = find_pc_line (tpmarker->address, 0);
13868  sym = find_pc_sect_function (tpmarker->address, NULL);
13869  ui_out_text (uiout, "Now in ");
13870  if (sym)
13871  {
13872  ui_out_field_string (uiout, "func",
13873  SYMBOL_PRINT_NAME (sym));
13874  ui_out_text (uiout, " at ");
13875  }
13876  ui_out_field_string (uiout, "file",
13878  ui_out_text (uiout, ":");
13879 
13880  if (ui_out_is_mi_like_p (uiout))
13881  {
13882  const char *fullname = symtab_to_fullname (sal2.symtab);
13883 
13884  ui_out_field_string (uiout, "fullname", fullname);
13885  }
13886 
13887  ui_out_field_int (uiout, "line", sal2.line);
13888  ui_out_text (uiout, "\n");
13889 
13890  b->loc->line_number = sal2.line;
13891  b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
13892 
13893  xfree (b->addr_string);
13894  b->addr_string = xstrprintf ("%s:%d",
13896  b->loc->line_number);
13897 
13898  /* Might be nice to check if function changed, and warn if
13899  so. */
13900 
13902  }
13903  }
13904  return sal;
13905 }
13906 
13907 /* Returns 1 iff locations A and B are sufficiently same that
13908  we don't need to report breakpoint as changed. */
13909 
13910 static int
13911 locations_are_equal (struct bp_location *a, struct bp_location *b)
13912 {
13913  while (a && b)
13914  {
13915  if (a->address != b->address)
13916  return 0;
13917 
13918  if (a->shlib_disabled != b->shlib_disabled)
13919  return 0;
13920 
13921  if (a->enabled != b->enabled)
13922  return 0;
13923 
13924  a = a->next;
13925  b = b->next;
13926  }
13927 
13928  if ((a == NULL) != (b == NULL))
13929  return 0;
13930 
13931  return 1;
13932 }
13933 
13934 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13935  based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13936  a ranged breakpoint. */
13937 
13938 void
13940  struct symtabs_and_lines sals,
13941  struct symtabs_and_lines sals_end)
13942 {
13943  int i;
13944  struct bp_location *existing_locations = b->loc;
13945 
13946  if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
13947  {
13948  /* Ranged breakpoints have only one start location and one end
13949  location. */
13952  printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13953  "multiple locations found\n"),
13954  b->number);
13955  return;
13956  }
13957 
13958  /* If there's no new locations, and all existing locations are
13959  pending, don't do anything. This optimizes the common case where
13960  all locations are in the same shared library, that was unloaded.
13961  We'd like to retain the location, so that when the library is
13962  loaded again, we don't loose the enabled/disabled status of the
13963  individual locations. */
13964  if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
13965  return;
13966 
13967  b->loc = NULL;
13968 
13969  for (i = 0; i < sals.nelts; ++i)
13970  {
13971  struct bp_location *new_loc;
13972 
13974 
13975  new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
13976 
13977  /* Reparse conditions, they might contain references to the
13978  old symtab. */
13979  if (b->cond_string != NULL)
13980  {
13981  const char *s;
13982 
13983  s = b->cond_string;
13984  TRY
13985  {
13986  new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
13987  block_for_pc (sals.sals[i].pc),
13988  0);
13989  }
13991  {
13992  warning (_("failed to reevaluate condition "
13993  "for breakpoint %d: %s"),
13994  b->number, e.message);
13995  new_loc->enabled = 0;
13996  }
13997  END_CATCH
13998  }
13999 
14000  if (sals_end.nelts)
14001  {
14002  CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14003 
14004  new_loc->length = end - sals.sals[0].pc + 1;
14005  }
14006  }
14007 
14008  /* If possible, carry over 'disable' status from existing
14009  breakpoints. */
14010  {
14011  struct bp_location *e = existing_locations;
14012  /* If there are multiple breakpoints with the same function name,
14013  e.g. for inline functions, comparing function names won't work.
14014  Instead compare pc addresses; this is just a heuristic as things
14015  may have moved, but in practice it gives the correct answer
14016  often enough until a better solution is found. */
14017  int have_ambiguous_names = ambiguous_names_p (b->loc);
14018 
14019  for (; e; e = e->next)
14020  {
14021  if (!e->enabled && e->function_name)
14022  {
14023  struct bp_location *l = b->loc;
14024  if (have_ambiguous_names)
14025  {
14026  for (; l; l = l->next)
14027  if (breakpoint_locations_match (e, l))
14028  {
14029  l->enabled = 0;
14030  break;
14031  }
14032  }
14033  else
14034  {
14035  for (; l; l = l->next)
14036  if (l->function_name
14037  && strcmp (e->function_name, l->function_name) == 0)
14038  {
14039  l->enabled = 0;
14040  break;
14041  }
14042  }
14043  }
14044  }
14045  }
14046 
14047  if (!locations_are_equal (existing_locations, b->loc))
14049 
14051 }
14052 
14053 /* Find the SaL locations corresponding to the given ADDR_STRING.
14054  On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14055 
14056 static struct symtabs_and_lines
14057 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
14058 {
14059  char *s;
14060  struct symtabs_and_lines sals = {0};
14061  struct gdb_exception exception = exception_none;
14062 
14063  gdb_assert (b->ops != NULL);
14064  s = addr_string;
14065 
14066  TRY
14067  {
14068  b->ops->decode_linespec (b, &s, &sals);
14069  }
14071  {
14072  int not_found_and_ok = 0;
14073 
14074  exception = e;
14075 
14076  /* For pending breakpoints, it's expected that parsing will
14077  fail until the right shared library is loaded. User has
14078  already told to create pending breakpoints and don't need
14079  extra messages. If breakpoint is in bp_shlib_disabled
14080  state, then user already saw the message about that
14081  breakpoint being disabled, and don't want to see more
14082  errors. */
14083  if (e.error == NOT_FOUND_ERROR
14084  && (b->condition_not_parsed
14085  || (b->loc && b->loc->shlib_disabled)
14086  || (b->loc && b->loc->pspace->executing_startup)
14087  || b->enable_state == bp_disabled))
14088  not_found_and_ok = 1;
14089 
14090  if (!not_found_and_ok)
14091  {
14092  /* We surely don't want to warn about the same breakpoint
14093  10 times. One solution, implemented here, is disable
14094  the breakpoint on error. Another solution would be to
14095  have separate 'warning emitted' flag. Since this
14096  happens only when a binary has changed, I don't know
14097  which approach is better. */
14098  b->enable_state = bp_disabled;
14099  throw_exception (e);
14100  }
14101  }
14102  END_CATCH
14103 
14104  if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
14105  {
14106  int i;
14107 
14108  for (i = 0; i < sals.nelts; ++i)
14109  resolve_sal_pc (&sals.sals[i]);
14110  if (b->condition_not_parsed && s && s[0])
14111  {
14112  char *cond_string, *extra_string;
14113  int thread, task;
14114 
14115  find_condition_and_thread (s, sals.sals[0].pc,
14116  &cond_string, &thread, &task,
14117  &extra_string);
14118  if (cond_string)
14119  b->cond_string = cond_string;
14120  b->thread = thread;
14121  b->task = task;
14122  if (extra_string)
14123  b->extra_string = extra_string;
14124  b->condition_not_parsed = 0;
14125  }
14126 
14127  if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14128  sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14129 
14130  *found = 1;
14131  }
14132  else
14133  *found = 0;
14134 
14135  return sals;
14136 }
14137 
14138 /* The default re_set method, for typical hardware or software
14139  breakpoints. Reevaluate the breakpoint and recreate its
14140  locations. */
14141 
14142 static void
14144 {
14145  int found;
14146  struct symtabs_and_lines sals, sals_end;
14147  struct symtabs_and_lines expanded = {0};
14148  struct symtabs_and_lines expanded_end = {0};
14149 
14150  sals = addr_string_to_sals (b, b->addr_string, &found);
14151  if (found)
14152  {
14153  make_cleanup (xfree, sals.sals);
14154  expanded = sals;
14155  }
14156 
14157  if (b->addr_string_range_end)
14158  {
14159  sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14160  if (found)
14161  {
14162  make_cleanup (xfree, sals_end.sals);
14163  expanded_end = sals_end;
14164  }
14165  }
14166 
14167  update_breakpoint_locations (b, expanded, expanded_end);
14168 }
14169 
14170 /* Default method for creating SALs from an address string. It basically
14171  calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14172 
14173 static void
14175  struct linespec_result *canonical,
14176  enum bptype type_wanted,
14177  char *addr_start, char **copy_arg)
14178 {
14179  parse_breakpoint_sals (arg, canonical);
14180 }
14181 
14182 /* Call create_breakpoints_sal for the given arguments. This is the default
14183  function for the `create_breakpoints_sal' method of
14184  breakpoint_ops. */
14185 
14186 static void
14188  struct linespec_result *canonical,
14189  char *cond_string,
14190  char *extra_string,
14191  enum bptype type_wanted,
14192  enum bpdisp disposition,
14193  int thread,
14194  int task, int ignore_count,
14195  const struct breakpoint_ops *ops,
14196  int from_tty, int enabled,
14197  int internal, unsigned flags)
14198 {
14199  create_breakpoints_sal (gdbarch, canonical, cond_string,
14200  extra_string,
14201  type_wanted, disposition,
14202  thread, task, ignore_count, ops, from_tty,
14203  enabled, internal, flags);
14204 }
14205 
14206 /* Decode the line represented by S by calling decode_line_full. This is the
14207  default function for the `decode_linespec' method of breakpoint_ops. */
14208 
14209 static void
14211  struct symtabs_and_lines *sals)
14212 {
14213  struct linespec_result canonical;
14214 
14215  init_linespec_result (&canonical);
14217  (struct symtab *) NULL, 0,
14218  &canonical, multiple_symbols_all,
14219  b->filter);
14220 
14221  /* We should get 0 or 1 resulting SALs. */
14222  gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14223 
14224  if (VEC_length (linespec_sals, canonical.sals) > 0)
14225  {
14226  struct linespec_sals *lsal;
14227 
14228  lsal = VEC_index (linespec_sals, canonical.sals, 0);
14229  *sals = lsal->sals;
14230  /* Arrange it so the destructor does not free the
14231  contents. */
14232  lsal->sals.sals = NULL;
14233  }
14234 
14235  destroy_linespec_result (&canonical);
14236 }
14237 
14238 /* Prepare the global context for a re-set of breakpoint B. */
14239 
14240 static struct cleanup *
14242 {
14243  struct cleanup *cleanups;
14244 
14245  input_radix = b->input_radix;
14246  cleanups = save_current_space_and_thread ();
14247  if (b->pspace != NULL)
14249  set_language (b->language);
14250 
14251  return cleanups;
14252 }
14253 
14254 /* Reset a breakpoint given it's struct breakpoint * BINT.
14255  The value we return ends up being the return value from catch_errors.
14256  Unused in this case. */
14257 
14258 static int
14260 {
14261  /* Get past catch_errs. */
14262  struct breakpoint *b = (struct breakpoint *) bint;
14263  struct cleanup *cleanups;
14264 
14265  cleanups = prepare_re_set_context (b);
14266  b->ops->re_set (b);
14267  do_cleanups (cleanups);
14268  return 0;
14269 }
14270 
14271 /* Re-set all breakpoints after symbols have been re-loaded. */
14272 void
14274 {
14275  struct breakpoint *b, *b_tmp;
14276  enum language save_language;
14277  int save_input_radix;
14278  struct cleanup *old_chain;
14279 
14280  save_language = current_language->la_language;
14281  save_input_radix = input_radix;
14282  old_chain = save_current_program_space ();
14283 
14284  ALL_BREAKPOINTS_SAFE (b, b_tmp)
14285  {
14286  /* Format possible error msg. */
14287  char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14288  b->number);
14289  struct cleanup *cleanups = make_cleanup (xfree, message);
14291  do_cleanups (cleanups);
14292  }
14293  set_language (save_language);
14294  input_radix = save_input_radix;
14295 
14297 
14298  do_cleanups (old_chain);
14299 
14304 }
14305 
14306 /* Reset the thread number of this breakpoint:
14307 
14308  - If the breakpoint is for all threads, leave it as-is.
14309  - Else, reset it to the current thread for inferior_ptid. */
14310 void
14312 {
14313  if (b->thread != -1)
14314  {
14317 
14318  /* We're being called after following a fork. The new fork is
14319  selected as current, and unless this was a vfork will have a
14320  different program space from the original thread. Reset that
14321  as well. */
14323  }
14324 }
14325 
14326 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14327  If from_tty is nonzero, it prints a message to that effect,
14328  which ends with a period (no newline). */
14329 
14330 void
14331 set_ignore_count (int bptnum, int count, int from_tty)
14332 {
14333  struct breakpoint *b;
14334 
14335  if (count < 0)
14336  count = 0;
14337 
14338  ALL_BREAKPOINTS (b)
14339  if (b->number == bptnum)
14340  {
14341  if (is_tracepoint (b))
14342  {
14343  if (from_tty && count != 0)
14344  printf_filtered (_("Ignore count ignored for tracepoint %d."),
14345  bptnum);
14346  return;
14347  }
14348 
14349  b->ignore_count = count;
14350  if (from_tty)
14351  {
14352  if (count == 0)
14353  printf_filtered (_("Will stop next time "
14354  "breakpoint %d is reached."),
14355  bptnum);
14356  else if (count == 1)
14357  printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14358  bptnum);
14359  else
14360  printf_filtered (_("Will ignore next %d "
14361  "crossings of breakpoint %d."),
14362  count, bptnum);
14363  }
14365  return;
14366  }
14367 
14368  error (_("No breakpoint number %d."), bptnum);
14369 }
14370 
14371 /* Command to set ignore-count of breakpoint N to COUNT. */
14372 
14373 static void
14374 ignore_command (char *args, int from_tty)
14375 {
14376  char *p = args;
14377  int num;
14378 
14379  if (p == 0)
14380  error_no_arg (_("a breakpoint number"));
14381 
14382  num = get_number (&p);
14383  if (num == 0)
14384  error (_("bad breakpoint number: '%s'"), args);
14385  if (*p == 0)
14386  error (_("Second argument (specified ignore-count) is missing."));
14387 
14388  set_ignore_count (num,
14390  from_tty);
14391  if (from_tty)
14392  printf_filtered ("\n");
14393 }
14394 
14395 /* Call FUNCTION on each of the breakpoints
14396  whose numbers are given in ARGS. */
14397 
14398 static void
14399 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14400  void *),
14401  void *data)
14402 {
14403  int num;
14404  struct breakpoint *b, *tmp;
14405  int match;
14406  struct get_number_or_range_state state;
14407 
14408  if (args == 0 || *args == '\0')
14409  error_no_arg (_("one or more breakpoint numbers"));
14410 
14411  init_number_or_range (&state, args);
14412 
14413  while (!state.finished)
14414  {
14415  const char *p = state.string;
14416 
14417  match = 0;
14418 
14419  num = get_number_or_range (&state);
14420  if (num == 0)
14421  {
14422  warning (_("bad breakpoint number at or near '%s'"), p);
14423  }
14424  else
14425  {
14426  ALL_BREAKPOINTS_SAFE (b, tmp)
14427  if (b->number == num)
14428  {
14429  match = 1;
14430  function (b, data);
14431  break;
14432  }
14433  if (match == 0)
14434  printf_unfiltered (_("No breakpoint number %d.\n"), num);
14435  }
14436  }
14437 }
14438 
14439 static struct bp_location *
14441 {
14442  char *dot = strchr (number, '.');
14443  char *p1;
14444  int bp_num;
14445  int loc_num;
14446  struct breakpoint *b;
14447  struct bp_location *loc;
14448 
14449  *dot = '\0';
14450 
14451  p1 = number;
14452  bp_num = get_number (&p1);
14453  if (bp_num == 0)
14454  error (_("Bad breakpoint number '%s'"), number);
14455 
14456  ALL_BREAKPOINTS (b)
14457  if (b->number == bp_num)
14458  {
14459  break;
14460  }
14461 
14462  if (!b || b->number != bp_num)
14463  error (_("Bad breakpoint number '%s'"), number);
14464 
14465  p1 = dot+1;
14466  loc_num = get_number (&p1);
14467  if (loc_num == 0)
14468  error (_("Bad breakpoint location number '%s'"), number);
14469 
14470  --loc_num;
14471  loc = b->loc;
14472  for (;loc_num && loc; --loc_num, loc = loc->next)
14473  ;
14474  if (!loc)
14475  error (_("Bad breakpoint location number '%s'"), dot+1);
14476 
14477  return loc;
14478 }
14479 
14480 
14481 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14482  If from_tty is nonzero, it prints a message to that effect,
14483  which ends with a period (no newline). */
14484 
14485 void
14487 {
14488  /* Never disable a watchpoint scope breakpoint; we want to
14489  hit them when we leave scope so we can delete both the
14490  watchpoint and its scope breakpoint at that time. */
14491  if (bpt->type == bp_watchpoint_scope)
14492  return;
14493 
14494  bpt->enable_state = bp_disabled;
14495 
14496  /* Mark breakpoint locations modified. */
14498 
14500  && current_trace_status ()->running && is_tracepoint (bpt))
14501  {
14502  struct bp_location *location;
14503 
14504  for (location = bpt->loc; location; location = location->next)
14505  target_disable_tracepoint (location);
14506  }
14507 
14509 
14511 }
14512 
14513 /* A callback for iterate_over_related_breakpoints. */
14514 
14515 static void
14517 {
14518  disable_breakpoint (b);
14519 }
14520 
14521 /* A callback for map_breakpoint_numbers that calls
14522  disable_breakpoint. */
14523 
14524 static void
14526 {
14528 }
14529 
14530 static void
14531 disable_command (char *args, int from_tty)
14532 {
14533  if (args == 0)
14534  {
14535  struct breakpoint *bpt;
14536 
14537  ALL_BREAKPOINTS (bpt)
14538  if (user_breakpoint_p (bpt))
14539  disable_breakpoint (bpt);
14540  }
14541  else
14542  {
14543  char *num = extract_arg (&args);
14544 
14545  while (num)
14546  {
14547  if (strchr (num, '.'))
14548  {
14549  struct bp_location *loc = find_location_by_number (num);
14550 
14551  if (loc)
14552  {
14553  if (loc->enabled)
14554  {
14555  loc->enabled = 0;
14557  }
14559  && current_trace_status ()->running && loc->owner
14560  && is_tracepoint (loc->owner))
14562  }
14564  }
14565  else
14567  num = extract_arg (&args);
14568  }
14569  }
14570 }
14571 
14572 static void
14573 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14574  int count)
14575 {
14576  int target_resources_ok;
14577 
14578  if (bpt->type == bp_hardware_breakpoint)
14579  {
14580  int i;
14581  i = hw_breakpoint_used_count ();
14582  target_resources_ok =
14584  i + 1, 0);
14585  if (target_resources_ok == 0)
14586  error (_("No hardware breakpoint support in the target."));
14587  else if (target_resources_ok < 0)
14588  error (_("Hardware breakpoints used exceeds limit."));
14589  }
14590 
14591  if (is_watchpoint (bpt))
14592  {
14593  /* Initialize it just to avoid a GCC false warning. */
14594  enum enable_state orig_enable_state = 0;
14595 
14596  TRY
14597  {
14598  struct watchpoint *w = (struct watchpoint *) bpt;
14599 
14600  orig_enable_state = bpt->enable_state;
14601  bpt->enable_state = bp_enabled;
14602  update_watchpoint (w, 1 /* reparse */);
14603  }
14604  CATCH (e, RETURN_MASK_ALL)
14605  {
14606  bpt->enable_state = orig_enable_state;
14607  exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14608  bpt->number);
14609  return;
14610  }
14611  END_CATCH
14612  }
14613 
14614  bpt->enable_state = bp_enabled;
14615 
14616  /* Mark breakpoint locations modified. */
14618 
14620  && current_trace_status ()->running && is_tracepoint (bpt))
14621  {
14622  struct bp_location *location;
14623 
14624  for (location = bpt->loc; location; location = location->next)
14625  target_enable_tracepoint (location);
14626  }
14627 
14628  bpt->disposition = disposition;
14629  bpt->enable_count = count;
14631 
14633 }
14634 
14635 
14636 void
14638 {
14639  enable_breakpoint_disp (bpt, bpt->disposition, 0);
14640 }
14641 
14642 static void
14643 do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14644 {
14645  enable_breakpoint (bpt);
14646 }
14647 
14648 /* A callback for map_breakpoint_numbers that calls
14649  enable_breakpoint. */
14650 
14651 static void
14653 {
14655 }
14656 
14657 /* The enable command enables the specified breakpoints (or all defined
14658  breakpoints) so they once again become (or continue to be) effective
14659  in stopping the inferior. */
14660 
14661 static void
14662 enable_command (char *args, int from_tty)
14663 {
14664  if (args == 0)
14665  {
14666  struct breakpoint *bpt;
14667 
14668  ALL_BREAKPOINTS (bpt)
14669  if (user_breakpoint_p (bpt))
14670  enable_breakpoint (bpt);
14671  }
14672  else
14673  {
14674  char *num = extract_arg (&args);
14675 
14676  while (num)
14677  {
14678  if (strchr (num, '.'))
14679  {
14680  struct bp_location *loc = find_location_by_number (num);
14681 
14682  if (loc)
14683  {
14684  if (!loc->enabled)
14685  {
14686  loc->enabled = 1;
14688  }
14690  && current_trace_status ()->running && loc->owner
14691  && is_tracepoint (loc->owner))
14693  }
14695  }
14696  else
14698  num = extract_arg (&args);
14699  }
14700  }
14701 }
14702 
14703 /* This struct packages up disposition data for application to multiple
14704  breakpoints. */
14705 
14707 {
14708  enum bpdisp disp;
14709  int count;
14710 };
14711 
14712 static void
14713 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14714 {
14715  struct disp_data disp_data = *(struct disp_data *) arg;
14716 
14717  enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14718 }
14719 
14720 static void
14722 {
14723  struct disp_data disp = { disp_disable, 1 };
14724 
14726 }
14727 
14728 static void
14729 enable_once_command (char *args, int from_tty)
14730 {
14732 }
14733 
14734 static void
14735 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14736 {
14737  struct disp_data disp = { disp_disable, *(int *) countptr };
14738 
14740 }
14741 
14742 static void
14743 enable_count_command (char *args, int from_tty)
14744 {
14745  int count;
14746 
14747  if (args == NULL)
14748  error_no_arg (_("hit count"));
14749 
14750  count = get_number (&args);
14751 
14753 }
14754 
14755 static void
14757 {
14758  struct disp_data disp = { disp_del, 1 };
14759 
14761 }
14762 
14763 static void
14764 enable_delete_command (char *args, int from_tty)
14765 {
14767 }
14768 
14769 static void
14770 set_breakpoint_cmd (char *args, int from_tty)
14771 {
14772 }
14773 
14774 static void
14775 show_breakpoint_cmd (char *args, int from_tty)
14776 {
14777 }
14778 
14779 /* Invalidate last known value of any hardware watchpoint if
14780  the memory which that value represents has been written to by
14781  GDB itself. */
14782 
14783 static void
14785  CORE_ADDR addr, ssize_t len,
14786  const bfd_byte *data)
14787 {
14788  struct breakpoint *bp;
14789 
14790  ALL_BREAKPOINTS (bp)
14791  if (bp->enable_state == bp_enabled
14792  && bp->type == bp_hardware_watchpoint)
14793  {
14794  struct watchpoint *wp = (struct watchpoint *) bp;
14795 
14796  if (wp->val_valid && wp->val)
14797  {
14798  struct bp_location *loc;
14799 
14800  for (loc = bp->loc; loc != NULL; loc = loc->next)
14802  && loc->address + loc->length > addr
14803  && addr + len > loc->address)
14804  {
14805  value_free (wp->val);
14806  wp->val = NULL;
14807  wp->val_valid = 0;
14808  }
14809  }
14810  }
14811 }
14812 
14813 /* Create and insert a breakpoint for software single step. */
14814 
14815 void
14817  struct address_space *aspace,
14818  CORE_ADDR next_pc)
14819 {
14820  struct thread_info *tp = inferior_thread ();
14821  struct symtab_and_line sal;
14822  CORE_ADDR pc = next_pc;
14823 
14824  if (tp->control.single_step_breakpoints == NULL)
14825  {
14827  = new_single_step_breakpoint (tp->num, gdbarch);
14828  }
14829 
14830  sal = find_pc_line (pc, 0);
14831  sal.pc = pc;
14832  sal.section = find_pc_overlay (pc);
14833  sal.explicit_pc = 1;
14835 
14837 }
14838 
14839 /* See breakpoint.h. */
14840 
14841 int
14843  struct address_space *aspace,
14844  CORE_ADDR pc)
14845 {
14846  struct bp_location *loc;
14847 
14848  for (loc = bp->loc; loc != NULL; loc = loc->next)
14849  if (loc->inserted
14850  && breakpoint_location_address_match (loc, aspace, pc))
14851  return 1;
14852 
14853  return 0;
14854 }
14855 
14856 /* Check whether a software single-step breakpoint is inserted at
14857  PC. */
14858 
14859 int
14861  CORE_ADDR pc)
14862 {
14863  struct breakpoint *bpt;
14864 
14865  ALL_BREAKPOINTS (bpt)
14866  {
14867  if (bpt->type == bp_single_step
14868  && breakpoint_has_location_inserted_here (bpt, aspace, pc))
14869  return 1;
14870  }
14871  return 0;
14872 }
14873 
14874 /* Tracepoint-specific operations. */
14875 
14876 /* Set tracepoint count to NUM. */
14877 static void
14879 {
14880  tracepoint_count = num;
14882 }
14883 
14884 static void
14885 trace_command (char *arg, int from_tty)
14886 {
14887  struct breakpoint_ops *ops;
14888  const char *arg_cp = arg;
14889 
14890  if (arg && probe_linespec_to_ops (&arg_cp))
14892  else
14894 
14896  arg,
14897  NULL, 0, NULL, 1 /* parse arg */,
14898  0 /* tempflag */,
14899  bp_tracepoint /* type_wanted */,
14900  0 /* Ignore count */,
14901  pending_break_support,
14902  ops,
14903  from_tty,
14904  1 /* enabled */,
14905  0 /* internal */, 0);
14906 }
14907 
14908 static void
14909 ftrace_command (char *arg, int from_tty)
14910 {
14912  arg,
14913  NULL, 0, NULL, 1 /* parse arg */,
14914  0 /* tempflag */,
14915  bp_fast_tracepoint /* type_wanted */,
14916  0 /* Ignore count */,
14917  pending_break_support,
14919  from_tty,
14920  1 /* enabled */,
14921  0 /* internal */, 0);
14922 }
14923 
14924 /* strace command implementation. Creates a static tracepoint. */
14925 
14926 static void
14927 strace_command (char *arg, int from_tty)
14928 {
14929  struct breakpoint_ops *ops;
14930 
14931  /* Decide if we are dealing with a static tracepoint marker (`-m'),
14932  or with a normal static tracepoint. */
14933  if (arg && startswith (arg, "-m") && isspace (arg[2]))
14935  else
14937 
14939  arg,
14940  NULL, 0, NULL, 1 /* parse arg */,
14941  0 /* tempflag */,
14942  bp_static_tracepoint /* type_wanted */,
14943  0 /* Ignore count */,
14944  pending_break_support,
14945  ops,
14946  from_tty,
14947  1 /* enabled */,
14948  0 /* internal */, 0);
14949 }
14950 
14951 /* Set up a fake reader function that gets command lines from a linked
14952  list that was acquired during tracepoint uploading. */
14953 
14954 static struct uploaded_tp *this_utp;
14955 static int next_cmd;
14956 
14957 static char *
14959 {
14960  char *rslt;
14961 
14962  VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
14963 
14964  next_cmd++;
14965 
14966  return rslt;
14967 }
14968 
14969 /* Given information about a tracepoint as recorded on a target (which
14970  can be either a live system or a trace file), attempt to create an
14971  equivalent GDB tracepoint. This is not a reliable process, since
14972  the target does not necessarily have all the information used when
14973  the tracepoint was originally defined. */
14974 
14975 struct tracepoint *
14977 {
14978  char *addr_str, small_buf[100];
14979  struct tracepoint *tp;
14980 
14981  if (utp->at_string)
14982  addr_str = utp->at_string;
14983  else
14984  {
14985  /* In the absence of a source location, fall back to raw
14986  address. Since there is no way to confirm that the address
14987  means the same thing as when the trace was started, warn the
14988  user. */
14989  warning (_("Uploaded tracepoint %d has no "
14990  "source location, using raw address"),
14991  utp->number);
14992  xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
14993  addr_str = small_buf;
14994  }
14995 
14996  /* There's not much we can do with a sequence of bytecodes. */
14997  if (utp->cond && !utp->cond_string)
14998  warning (_("Uploaded tracepoint %d condition "
14999  "has no source form, ignoring it"),
15000  utp->number);
15001 
15003  addr_str,
15004  utp->cond_string, -1, NULL,
15005  0 /* parse cond/thread */,
15006  0 /* tempflag */,
15007  utp->type /* type_wanted */,
15008  0 /* Ignore count */,
15009  pending_break_support,
15011  0 /* from_tty */,
15012  utp->enabled /* enabled */,
15013  0 /* internal */,
15015  return NULL;
15016 
15017  /* Get the tracepoint we just created. */
15018  tp = get_tracepoint (tracepoint_count);
15019  gdb_assert (tp != NULL);
15020 
15021  if (utp->pass > 0)
15022  {
15023  xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15024  tp->base.number);
15025 
15026  trace_pass_command (small_buf, 0);
15027  }
15028 
15029  /* If we have uploaded versions of the original commands, set up a
15030  special-purpose "reader" function and call the usual command line
15031  reader, then pass the result to the breakpoint command-setting
15032  function. */
15033  if (!VEC_empty (char_ptr, utp->cmd_strings))
15034  {
15035  struct command_line *cmd_list;
15036 
15037  this_utp = utp;
15038  next_cmd = 0;
15039 
15040  cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15041 
15042  breakpoint_set_commands (&tp->base, cmd_list);
15043  }
15044  else if (!VEC_empty (char_ptr, utp->actions)
15045  || !VEC_empty (char_ptr, utp->step_actions))
15046  warning (_("Uploaded tracepoint %d actions "
15047  "have no source form, ignoring them"),
15048  utp->number);
15049 
15050  /* Copy any status information that might be available. */
15051  tp->base.hit_count = utp->hit_count;
15053 
15054  return tp;
15055 }
15056 
15057 /* Print information on tracepoint number TPNUM_EXP, or all if
15058  omitted. */
15059 
15060 static void
15061 tracepoints_info (char *args, int from_tty)
15062 {
15063  struct ui_out *uiout = current_uiout;
15064  int num_printed;
15065 
15066  num_printed = breakpoint_1 (args, 0, is_tracepoint);
15067 
15068  if (num_printed == 0)
15069  {
15070  if (args == NULL || *args == '\0')
15071  ui_out_message (uiout, 0, "No tracepoints.\n");
15072  else
15073  ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
15074  }
15075 
15077 }
15078 
15079 /* The 'enable trace' command enables tracepoints.
15080  Not supported by all targets. */
15081 static void
15082 enable_trace_command (char *args, int from_tty)
15083 {
15084  enable_command (args, from_tty);
15085 }
15086 
15087 /* The 'disable trace' command disables tracepoints.
15088  Not supported by all targets. */
15089 static void
15090 disable_trace_command (char *args, int from_tty)
15091 {
15092  disable_command (args, from_tty);
15093 }
15094 
15095 /* Remove a tracepoint (or all if no argument). */
15096 static void
15097 delete_trace_command (char *arg, int from_tty)
15098 {
15099  struct breakpoint *b, *b_tmp;
15100 
15101  dont_repeat ();
15102 
15103  if (arg == 0)
15104  {
15105  int breaks_to_delete = 0;
15106 
15107  /* Delete all breakpoints if no argument.
15108  Do not delete internal or call-dummy breakpoints, these
15109  have to be deleted with an explicit breakpoint number
15110  argument. */
15111  ALL_TRACEPOINTS (b)
15112  if (is_tracepoint (b) && user_breakpoint_p (b))
15113  {
15114  breaks_to_delete = 1;
15115  break;
15116  }
15117 
15118  /* Ask user only if there are some breakpoints to delete. */
15119  if (!from_tty
15120  || (breaks_to_delete && query (_("Delete all tracepoints? "))))
15121  {
15122  ALL_BREAKPOINTS_SAFE (b, b_tmp)
15123  if (is_tracepoint (b) && user_breakpoint_p (b))
15124  delete_breakpoint (b);
15125  }
15126  }
15127  else
15129 }
15130 
15131 /* Helper function for trace_pass_command. */
15132 
15133 static void
15134 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15135 {
15136  tp->pass_count = count;
15138  if (from_tty)
15139  printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15140  tp->base.number, count);
15141 }
15142 
15143 /* Set passcount for tracepoint.
15144 
15145  First command argument is passcount, second is tracepoint number.
15146  If tracepoint number omitted, apply to most recently defined.
15147  Also accepts special argument "all". */
15148 
15149 static void
15150 trace_pass_command (char *args, int from_tty)
15151 {
15152  struct tracepoint *t1;
15153  unsigned int count;
15154 
15155  if (args == 0 || *args == 0)
15156  error (_("passcount command requires an "
15157  "argument (count + optional TP num)"));
15158 
15159  count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
15160 
15161  args = skip_spaces (args);
15162  if (*args && strncasecmp (args, "all", 3) == 0)
15163  {
15164  struct breakpoint *b;
15165 
15166  args += 3; /* Skip special argument "all". */
15167  if (*args)
15168  error (_("Junk at end of arguments."));
15169 
15170  ALL_TRACEPOINTS (b)
15171  {
15172  t1 = (struct tracepoint *) b;
15173  trace_pass_set_count (t1, count, from_tty);
15174  }
15175  }
15176  else if (*args == '\0')
15177  {
15178  t1 = get_tracepoint_by_number (&args, NULL);
15179  if (t1)
15180  trace_pass_set_count (t1, count, from_tty);
15181  }
15182  else
15183  {
15184  struct get_number_or_range_state state;
15185 
15186  init_number_or_range (&state, args);
15187  while (!state.finished)
15188  {
15189  t1 = get_tracepoint_by_number (&args, &state);
15190  if (t1)
15191  trace_pass_set_count (t1, count, from_tty);
15192  }
15193  }
15194 }
15195 
15196 struct tracepoint *
15198 {
15199  struct breakpoint *t;
15200 
15201  ALL_TRACEPOINTS (t)
15202  if (t->number == num)
15203  return (struct tracepoint *) t;
15204 
15205  return NULL;
15206 }
15207 
15208 /* Find the tracepoint with the given target-side number (which may be
15209  different from the tracepoint number after disconnecting and
15210  reconnecting). */
15211 
15212 struct tracepoint *
15214 {
15215  struct breakpoint *b;
15216 
15217  ALL_TRACEPOINTS (b)
15218  {
15219  struct tracepoint *t = (struct tracepoint *) b;
15220 
15221  if (t->number_on_target == num)
15222  return t;
15223  }
15224 
15225  return NULL;
15226 }
15227 
15228 /* Utility: parse a tracepoint number and look it up in the list.
15229  If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15230  If the argument is missing, the most recent tracepoint
15231  (tracepoint_count) is returned. */
15232 
15233 struct tracepoint *
15235  struct get_number_or_range_state *state)
15236 {
15237  struct breakpoint *t;
15238  int tpnum;
15239  char *instring = arg == NULL ? NULL : *arg;
15240 
15241  if (state)
15242  {
15243  gdb_assert (!state->finished);
15244  tpnum = get_number_or_range (state);
15245  }
15246  else if (arg == NULL || *arg == NULL || ! **arg)
15247  tpnum = tracepoint_count;
15248  else
15249  tpnum = get_number (arg);
15250 
15251  if (tpnum <= 0)
15252  {
15253  if (instring && *instring)
15254  printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15255  instring);
15256  else
15257  printf_filtered (_("No previous tracepoint\n"));
15258  return NULL;
15259  }
15260 
15261  ALL_TRACEPOINTS (t)
15262  if (t->number == tpnum)
15263  {
15264  return (struct tracepoint *) t;
15265  }
15266 
15267  printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15268  return NULL;
15269 }
15270 
15271 void
15273 {
15274  if (b->thread != -1)
15275  fprintf_unfiltered (fp, " thread %d", b->thread);
15276 
15277  if (b->task != 0)
15278  fprintf_unfiltered (fp, " task %d", b->task);
15279 
15280  fprintf_unfiltered (fp, "\n");
15281 }
15282 
15283 /* Save information on user settable breakpoints (watchpoints, etc) to
15284  a new script file named FILENAME. If FILTER is non-NULL, call it
15285  on each breakpoint and only include the ones for which it returns
15286  non-zero. */
15287 
15288 static void
15289 save_breakpoints (char *filename, int from_tty,
15290  int (*filter) (const struct breakpoint *))
15291 {
15292  struct breakpoint *tp;
15293  int any = 0;
15294  struct cleanup *cleanup;
15295  struct ui_file *fp;
15296  int extra_trace_bits = 0;
15297 
15298  if (filename == 0 || *filename == 0)
15299  error (_("Argument required (file name in which to save)"));
15300 
15301  /* See if we have anything to save. */
15302  ALL_BREAKPOINTS (tp)
15303  {
15304  /* Skip internal and momentary breakpoints. */
15305  if (!user_breakpoint_p (tp))
15306  continue;
15307 
15308  /* If we have a filter, only save the breakpoints it accepts. */
15309  if (filter && !filter (tp))
15310  continue;
15311 
15312  any = 1;
15313 
15314  if (is_tracepoint (tp))
15315  {
15316  extra_trace_bits = 1;
15317 
15318  /* We can stop searching. */
15319  break;
15320  }
15321  }
15322 
15323  if (!any)
15324  {
15325  warning (_("Nothing to save."));
15326  return;
15327  }
15328 
15329  filename = tilde_expand (filename);
15330  cleanup = make_cleanup (xfree, filename);
15331  fp = gdb_fopen (filename, "w");
15332  if (!fp)
15333  error (_("Unable to open file '%s' for saving (%s)"),
15334  filename, safe_strerror (errno));
15336 
15337  if (extra_trace_bits)
15339 
15340  ALL_BREAKPOINTS (tp)
15341  {
15342  /* Skip internal and momentary breakpoints. */
15343  if (!user_breakpoint_p (tp))
15344  continue;
15345 
15346  /* If we have a filter, only save the breakpoints it accepts. */
15347  if (filter && !filter (tp))
15348  continue;
15349 
15350  tp->ops->print_recreate (tp, fp);
15351 
15352  /* Note, we can't rely on tp->number for anything, as we can't
15353  assume the recreated breakpoint numbers will match. Use $bpnum
15354  instead. */
15355 
15356  if (tp->cond_string)
15357  fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15358 
15359  if (tp->ignore_count)
15360  fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15361 
15362  if (tp->type != bp_dprintf && tp->commands)
15363  {
15364  struct gdb_exception exception;
15365 
15366  fprintf_unfiltered (fp, " commands\n");
15367 
15369  TRY
15370  {
15372  }
15373  CATCH (ex, RETURN_MASK_ALL)
15374  {
15376  throw_exception (ex);
15377  }
15378  END_CATCH
15379 
15381  fprintf_unfiltered (fp, " end\n");
15382  }
15383 
15384  if (tp->enable_state == bp_disabled)
15385  fprintf_unfiltered (fp, "disable $bpnum\n");
15386 
15387  /* If this is a multi-location breakpoint, check if the locations
15388  should be individually disabled. Watchpoint locations are
15389  special, and not user visible. */
15390  if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15391  {
15392  struct bp_location *loc;
15393  int n = 1;
15394 
15395  for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15396  if (!loc->enabled)
15397  fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15398  }
15399  }
15400 
15401  if (extra_trace_bits && *default_collect)
15402  fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15403 
15404  if (from_tty)
15405  printf_filtered (_("Saved to file '%s'.\n"), filename);
15406  do_cleanups (cleanup);
15407 }
15408 
15409 /* The `save breakpoints' command. */
15410 
15411 static void
15412 save_breakpoints_command (char *args, int from_tty)
15413 {
15414  save_breakpoints (args, from_tty, NULL);
15415 }
15416 
15417 /* The `save tracepoints' command. */
15418 
15419 static void
15420 save_tracepoints_command (char *args, int from_tty)
15421 {
15422  save_breakpoints (args, from_tty, is_tracepoint);
15423 }
15424 
15425 /* Create a vector of all tracepoints. */
15426 
15427 VEC(breakpoint_p) *
15428 all_tracepoints (void)
15429 {
15430  VEC(breakpoint_p) *tp_vec = 0;
15431  struct breakpoint *tp;
15432 
15433  ALL_TRACEPOINTS (tp)
15434  {
15435  VEC_safe_push (breakpoint_p, tp_vec, tp);
15436  }
15437 
15438  return tp_vec;
15439 }
15440 
15441 
15442 /* This help string is used for the break, hbreak, tbreak and thbreak
15443  commands. It is defined as a macro to prevent duplication.
15444  COMMAND should be a string constant containing the name of the
15445  command. */
15446 #define BREAK_ARGS_HELP(command) \
15447 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15448 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15449 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15450 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15451 `-probe-dtrace' (for a DTrace probe).\n\
15452 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15453 If a line number is specified, break at start of code for that line.\n\
15454 If a function is specified, break at start of code for that function.\n\
15455 If an address is specified, break at that exact address.\n\
15456 With no LOCATION, uses current execution address of the selected\n\
15457 stack frame. This is useful for breaking on return to a stack frame.\n\
15458 \n\
15459 THREADNUM is the number from \"info threads\".\n\
15460 CONDITION is a boolean expression.\n\
15461 \n\
15462 Multiple breakpoints at one place are permitted, and useful if their\n\
15463 conditions are different.\n\
15464 \n\
15465 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15466 
15467 /* List of subcommands for "catch". */
15469 
15470 /* List of subcommands for "tcatch". */
15472 
15473 void
15474 add_catch_command (char *name, char *docstring,
15476  completer_ftype *completer,
15477  void *user_data_catch,
15478  void *user_data_tcatch)
15479 {
15480  struct cmd_list_element *command;
15481 
15482  command = add_cmd (name, class_breakpoint, NULL, docstring,
15483  &catch_cmdlist);
15484  set_cmd_sfunc (command, sfunc);
15485  set_cmd_context (command, user_data_catch);
15486  set_cmd_completer (command, completer);
15487 
15488  command = add_cmd (name, class_breakpoint, NULL, docstring,
15489  &tcatch_cmdlist);
15490  set_cmd_sfunc (command, sfunc);
15491  set_cmd_context (command, user_data_tcatch);
15492  set_cmd_completer (command, completer);
15493 }
15494 
15495 static void
15496 save_command (char *arg, int from_tty)
15497 {
15498  printf_unfiltered (_("\"save\" must be followed by "
15499  "the name of a save subcommand.\n"));
15500  help_list (save_cmdlist, "save ", all_commands, gdb_stdout);
15501 }
15502 
15503 struct breakpoint *
15504 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15505  void *data)
15506 {
15507  struct breakpoint *b, *b_tmp;
15508 
15509  ALL_BREAKPOINTS_SAFE (b, b_tmp)
15510  {
15511  if ((*callback) (b, data))
15512  return b;
15513  }
15514 
15515  return NULL;
15516 }
15517 
15518 /* Zero if any of the breakpoint's locations could be a location where
15519  functions have been inlined, nonzero otherwise. */
15520 
15521 static int
15523 {
15524  /* The shared library event breakpoint is set on the address of a
15525  non-inline function. */
15526  if (b->type == bp_shlib_event)
15527  return 1;
15528 
15529  return 0;
15530 }
15531 
15532 /* Nonzero if the specified PC cannot be a location where functions
15533  have been inlined. */
15534 
15535 int
15537  const struct target_waitstatus *ws)
15538 {
15539  struct breakpoint *b;
15540  struct bp_location *bl;
15541 
15542  ALL_BREAKPOINTS (b)
15543  {
15544  if (!is_non_inline_function (b))
15545  continue;
15546 
15547  for (bl = b->loc; bl != NULL; bl = bl->next)
15548  {
15549  if (!bl->shlib_disabled
15550  && bpstat_check_location (bl, aspace, pc, ws))
15551  return 1;
15552  }
15553  }
15554 
15555  return 0;
15556 }
15557 
15558 /* Remove any references to OBJFILE which is going to be freed. */
15559 
15560 void
15562 {
15563  struct bp_location **locp, *loc;
15564 
15565  ALL_BP_LOCATIONS (loc, locp)
15566  if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile)
15567  loc->symtab = NULL;
15568 }
15569 
15570 void
15572 {
15573  static int initialized = 0;
15574 
15575  struct breakpoint_ops *ops;
15576 
15577  if (initialized)
15578  return;
15579  initialized = 1;
15580 
15581  /* The breakpoint_ops structure to be inherit by all kinds of
15582  breakpoints (real breakpoints, i.e., user "break" breakpoints,
15583  internal and momentary breakpoints, etc.). */
15584  ops = &bkpt_base_breakpoint_ops;
15585  *ops = base_breakpoint_ops;
15586  ops->re_set = bkpt_re_set;
15593 
15594  /* The breakpoint_ops structure to be used in regular breakpoints. */
15595  ops = &bkpt_breakpoint_ops;
15596  *ops = bkpt_base_breakpoint_ops;
15597  ops->re_set = bkpt_re_set;
15599  ops->print_it = bkpt_print_it;
15602 
15603  /* Ranged breakpoints. */
15604  ops = &ranged_breakpoint_ops;
15605  *ops = bkpt_breakpoint_ops;
15613 
15614  /* Internal breakpoints. */
15615  ops = &internal_breakpoint_ops;
15616  *ops = bkpt_base_breakpoint_ops;
15621 
15622  /* Momentary breakpoints. */
15623  ops = &momentary_breakpoint_ops;
15624  *ops = bkpt_base_breakpoint_ops;
15629 
15630  /* Momentary breakpoints for bp_longjmp and bp_exception. */
15631  ops = &longjmp_breakpoint_ops;
15632  *ops = momentary_breakpoint_ops;
15633  ops->dtor = longjmp_bkpt_dtor;
15634 
15635  /* Probe breakpoints. */
15637  *ops = bkpt_breakpoint_ops;
15642 
15643  /* Watchpoints. */
15645  *ops = base_breakpoint_ops;
15646  ops->dtor = dtor_watchpoint;
15647  ops->re_set = re_set_watchpoint;
15658 
15659  /* Masked watchpoints. */
15670 
15671  /* Tracepoints. */
15673  *ops = base_breakpoint_ops;
15674  ops->re_set = tracepoint_re_set;
15682 
15683  /* Probe tracepoints. */
15688 
15689  /* Static tracepoints with marker (`-m'). */
15695 
15696  /* Fork catchpoints. */
15698  *ops = base_breakpoint_ops;
15706 
15707  /* Vfork catchpoints. */
15709  *ops = base_breakpoint_ops;
15717 
15718  /* Exec catchpoints. */
15720  *ops = base_breakpoint_ops;
15721  ops->dtor = dtor_catch_exec;
15729 
15730  /* Solib-related catchpoints. */
15732  *ops = base_breakpoint_ops;
15733  ops->dtor = dtor_catch_solib;
15742 
15743  ops = &dprintf_breakpoint_ops;
15744  *ops = bkpt_base_breakpoint_ops;
15745  ops->re_set = dprintf_re_set;
15747  ops->print_it = bkpt_print_it;
15752 }
15753 
15754 /* Chain containing all defined "enable breakpoint" subcommands. */
15755 
15756 static struct cmd_list_element *enablebreaklist = NULL;
15757 
15758 void
15760 {
15761  struct cmd_list_element *c;
15762 
15764 
15768 
15769  breakpoint_objfile_key
15770  = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
15771 
15772  breakpoint_chain = 0;
15773  /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15774  before a breakpoint is set. */
15775  breakpoint_count = 0;
15776 
15777  tracepoint_count = 0;
15778 
15779  add_com ("ignore", class_breakpoint, ignore_command, _("\
15780 Set ignore-count of breakpoint number N to COUNT.\n\
15781 Usage is `ignore N COUNT'."));
15782 
15783  add_com ("commands", class_breakpoint, commands_command, _("\
15784 Set commands to be executed when a breakpoint is hit.\n\
15785 Give breakpoint number as argument after \"commands\".\n\
15786 With no argument, the targeted breakpoint is the last one set.\n\
15787 The commands themselves follow starting on the next line.\n\
15788 Type a line containing \"end\" to indicate the end of them.\n\
15789 Give \"silent\" as the first line to make the breakpoint silent;\n\
15790 then no output is printed when it is hit, except what the commands print."));
15791 
15792  c = add_com ("condition", class_breakpoint, condition_command, _("\
15793 Specify breakpoint number N to break only if COND is true.\n\
15794 Usage is `condition N COND', where N is an integer and COND is an\n\
15795 expression to be evaluated whenever breakpoint N is reached."));
15796  set_cmd_completer (c, condition_completer);
15797 
15798  c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
15799 Set a temporary breakpoint.\n\
15800 Like \"break\" except the breakpoint is only temporary,\n\
15801 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15802 by using \"enable delete\" on the breakpoint number.\n\
15803 \n"
15804 BREAK_ARGS_HELP ("tbreak")));
15805  set_cmd_completer (c, location_completer);
15806 
15807  c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
15808 Set a hardware assisted breakpoint.\n\
15809 Like \"break\" except the breakpoint requires hardware support,\n\
15810 some target hardware may not have this support.\n\
15811 \n"
15812 BREAK_ARGS_HELP ("hbreak")));
15813  set_cmd_completer (c, location_completer);
15814 
15815  c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
15816 Set a temporary hardware assisted breakpoint.\n\
15817 Like \"hbreak\" except the breakpoint is only temporary,\n\
15818 so it will be deleted when hit.\n\
15819 \n"
15820 BREAK_ARGS_HELP ("thbreak")));
15821  set_cmd_completer (c, location_completer);
15822 
15824 Enable some breakpoints.\n\
15825 Give breakpoint numbers (separated by spaces) as arguments.\n\
15826 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15827 This is used to cancel the effect of the \"disable\" command.\n\
15828 With a subcommand you can enable temporarily."),
15829  &enablelist, "enable ", 1, &cmdlist);
15830 
15831  add_com_alias ("en", "enable", class_breakpoint, 1);
15832 
15833  add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
15834 Enable some breakpoints.\n\
15835 Give breakpoint numbers (separated by spaces) as arguments.\n\
15836 This is used to cancel the effect of the \"disable\" command.\n\
15837 May be abbreviated to simply \"enable\".\n"),
15838  &enablebreaklist, "enable breakpoints ", 1, &enablelist);
15839 
15840  add_cmd ("once", no_class, enable_once_command, _("\
15841 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15842 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15843  &enablebreaklist);
15844 
15845  add_cmd ("delete", no_class, enable_delete_command, _("\
15846 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15847 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15848  &enablebreaklist);
15849 
15850  add_cmd ("count", no_class, enable_count_command, _("\
15851 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15852 If a breakpoint is hit while enabled in this fashion,\n\
15853 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15854  &enablebreaklist);
15855 
15856  add_cmd ("delete", no_class, enable_delete_command, _("\
15857 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15858 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15859  &enablelist);
15860 
15861  add_cmd ("once", no_class, enable_once_command, _("\
15862 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15863 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15864  &enablelist);
15865 
15866  add_cmd ("count", no_class, enable_count_command, _("\
15867 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15868 If a breakpoint is hit while enabled in this fashion,\n\
15869 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15870  &enablelist);
15871 
15873 Disable some breakpoints.\n\
15874 Arguments are breakpoint numbers with spaces in between.\n\
15875 To disable all breakpoints, give no argument.\n\
15876 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15877  &disablelist, "disable ", 1, &cmdlist);
15878  add_com_alias ("dis", "disable", class_breakpoint, 1);
15879  add_com_alias ("disa", "disable", class_breakpoint, 1);
15880 
15881  add_cmd ("breakpoints", class_alias, disable_command, _("\
15882 Disable some breakpoints.\n\
15883 Arguments are breakpoint numbers with spaces in between.\n\
15884 To disable all breakpoints, give no argument.\n\
15885 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15886 This command may be abbreviated \"disable\"."),
15887  &disablelist);
15888 
15890 Delete some breakpoints or auto-display expressions.\n\
15891 Arguments are breakpoint numbers with spaces in between.\n\
15892 To delete all breakpoints, give no argument.\n\
15893 \n\
15894 Also a prefix command for deletion of other GDB objects.\n\
15895 The \"unset\" command is also an alias for \"delete\"."),
15896  &deletelist, "delete ", 1, &cmdlist);
15897  add_com_alias ("d", "delete", class_breakpoint, 1);
15898  add_com_alias ("del", "delete", class_breakpoint, 1);
15899 
15900  add_cmd ("breakpoints", class_alias, delete_command, _("\
15901 Delete some breakpoints or auto-display expressions.\n\
15902 Arguments are breakpoint numbers with spaces in between.\n\
15903 To delete all breakpoints, give no argument.\n\
15904 This command may be abbreviated \"delete\"."),
15905  &deletelist);
15906 
15907  add_com ("clear", class_breakpoint, clear_command, _("\
15908 Clear breakpoint at specified line or function.\n\
15909 Argument may be line number, function name, or \"*\" and an address.\n\
15910 If line number is specified, all breakpoints in that line are cleared.\n\
15911 If function is specified, breakpoints at beginning of function are cleared.\n\
15912 If an address is specified, breakpoints at that address are cleared.\n\
15913 \n\
15914 With no argument, clears all breakpoints in the line that the selected frame\n\
15915 is executing in.\n\
15916 \n\
15917 See also the \"delete\" command which clears breakpoints by number."));
15918  add_com_alias ("cl", "clear", class_breakpoint, 1);
15919 
15920  c = add_com ("break", class_breakpoint, break_command, _("\
15921 Set breakpoint at specified line or function.\n"
15922 BREAK_ARGS_HELP ("break")));
15923  set_cmd_completer (c, location_completer);
15924 
15925  add_com_alias ("b", "break", class_run, 1);
15926  add_com_alias ("br", "break", class_run, 1);
15927  add_com_alias ("bre", "break", class_run, 1);
15928  add_com_alias ("brea", "break", class_run, 1);
15929 
15930  if (dbx_commands)
15931  {
15933 Break in function/address or break at a line in the current file."),
15934  &stoplist, "stop ", 1, &cmdlist);
15936  _("Break in function or address."), &stoplist);
15938  _("Break at a line in the current file."), &stoplist);
15939  add_com ("status", class_info, breakpoints_info, _("\
15940 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15941 The \"Type\" column indicates one of:\n\
15942 \tbreakpoint - normal breakpoint\n\
15943 \twatchpoint - watchpoint\n\
15944 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15945 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15946 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15947 address and file/line number respectively.\n\
15948 \n\
15949 Convenience variable \"$_\" and default examine address for \"x\"\n\
15950 are set to the address of the last breakpoint listed unless the command\n\
15951 is prefixed with \"server \".\n\n\
15952 Convenience variable \"$bpnum\" contains the number of the last\n\
15953 breakpoint set."));
15954  }
15955 
15956  add_info ("breakpoints", breakpoints_info, _("\
15957 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15958 The \"Type\" column indicates one of:\n\
15959 \tbreakpoint - normal breakpoint\n\
15960 \twatchpoint - watchpoint\n\
15961 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15962 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15963 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15964 address and file/line number respectively.\n\
15965 \n\
15966 Convenience variable \"$_\" and default examine address for \"x\"\n\
15967 are set to the address of the last breakpoint listed unless the command\n\
15968 is prefixed with \"server \".\n\n\
15969 Convenience variable \"$bpnum\" contains the number of the last\n\
15970 breakpoint set."));
15971 
15972  add_info_alias ("b", "breakpoints", 1);
15973 
15975 Status of all breakpoints, or breakpoint number NUMBER.\n\
15976 The \"Type\" column indicates one of:\n\
15977 \tbreakpoint - normal breakpoint\n\
15978 \twatchpoint - watchpoint\n\
15979 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15980 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15981 \tuntil - internal breakpoint used by the \"until\" command\n\
15982 \tfinish - internal breakpoint used by the \"finish\" command\n\
15983 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15984 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15985 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15986 address and file/line number respectively.\n\
15987 \n\
15988 Convenience variable \"$_\" and default examine address for \"x\"\n\
15989 are set to the address of the last breakpoint listed unless the command\n\
15990 is prefixed with \"server \".\n\n\
15991 Convenience variable \"$bpnum\" contains the number of the last\n\
15992 breakpoint set."),
15994 
15996 Set catchpoints to catch events."),
15997  &catch_cmdlist, "catch ",
15998  0/*allow-unknown*/, &cmdlist);
15999 
16001 Set temporary catchpoints to catch events."),
16002  &tcatch_cmdlist, "tcatch ",
16003  0/*allow-unknown*/, &cmdlist);
16004 
16005  add_catch_command ("fork", _("Catch calls to fork."),
16007  NULL,
16008  (void *) (uintptr_t) catch_fork_permanent,
16009  (void *) (uintptr_t) catch_fork_temporary);
16010  add_catch_command ("vfork", _("Catch calls to vfork."),
16012  NULL,
16013  (void *) (uintptr_t) catch_vfork_permanent,
16014  (void *) (uintptr_t) catch_vfork_temporary);
16015  add_catch_command ("exec", _("Catch calls to exec."),
16017  NULL,
16019  CATCH_TEMPORARY);
16020  add_catch_command ("load", _("Catch loads of shared libraries.\n\
16021 Usage: catch load [REGEX]\n\
16022 If REGEX is given, only stop for libraries matching the regular expression."),
16024  NULL,
16026  CATCH_TEMPORARY);
16027  add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16028 Usage: catch unload [REGEX]\n\
16029 If REGEX is given, only stop for libraries matching the regular expression."),
16031  NULL,
16033  CATCH_TEMPORARY);
16034 
16035  c = add_com ("watch", class_breakpoint, watch_command, _("\
16036 Set a watchpoint for an expression.\n\
16037 Usage: watch [-l|-location] EXPRESSION\n\
16038 A watchpoint stops execution of your program whenever the value of\n\
16039 an expression changes.\n\
16040 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16041 the memory to which it refers."));
16042  set_cmd_completer (c, expression_completer);
16043 
16044  c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
16045 Set a read watchpoint for an expression.\n\
16046 Usage: rwatch [-l|-location] EXPRESSION\n\
16047 A watchpoint stops execution of your program whenever the value of\n\
16048 an expression is read.\n\
16049 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16050 the memory to which it refers."));
16051  set_cmd_completer (c, expression_completer);
16052 
16053  c = add_com ("awatch", class_breakpoint, awatch_command, _("\
16054 Set a watchpoint for an expression.\n\
16055 Usage: awatch [-l|-location] EXPRESSION\n\
16056 A watchpoint stops execution of your program whenever the value of\n\
16057 an expression is either read or written.\n\
16058 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16059 the memory to which it refers."));
16060  set_cmd_completer (c, expression_completer);
16061 
16062  add_info ("watchpoints", watchpoints_info, _("\
16063 Status of specified watchpoints (all watchpoints if no argument)."));
16064 
16065  /* XXX: cagney/2005-02-23: This should be a boolean, and should
16066  respond to changes - contrary to the description. */
16067  add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
16068  &can_use_hw_watchpoints, _("\
16069 Set debugger's willingness to use watchpoint hardware."), _("\
16070 Show debugger's willingness to use watchpoint hardware."), _("\
16071 If zero, gdb will not use hardware for new watchpoints, even if\n\
16072 such is available. (However, any hardware watchpoints that were\n\
16073 created before setting this to nonzero, will continue to use watchpoint\n\
16074 hardware.)"),
16075  NULL,
16077  &setlist, &showlist);
16078 
16079  can_use_hw_watchpoints = 1;
16080 
16081  /* Tracepoint manipulation commands. */
16082 
16083  c = add_com ("trace", class_breakpoint, trace_command, _("\
16084 Set a tracepoint at specified line or function.\n\
16085 \n"
16086 BREAK_ARGS_HELP ("trace") "\n\
16087 Do \"help tracepoints\" for info on other tracepoint commands."));
16088  set_cmd_completer (c, location_completer);
16089 
16090  add_com_alias ("tp", "trace", class_alias, 0);
16091  add_com_alias ("tr", "trace", class_alias, 1);
16092  add_com_alias ("tra", "trace", class_alias, 1);
16093  add_com_alias ("trac", "trace", class_alias, 1);
16094 
16095  c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16096 Set a fast tracepoint at specified line or function.\n\
16097 \n"
16098 BREAK_ARGS_HELP ("ftrace") "\n\
16099 Do \"help tracepoints\" for info on other tracepoint commands."));
16100  set_cmd_completer (c, location_completer);
16101 
16102  c = add_com ("strace", class_breakpoint, strace_command, _("\
16103 Set a static tracepoint at specified line, function or marker.\n\
16104 \n\
16105 strace [LOCATION] [if CONDITION]\n\
16106 LOCATION may be a line number, function name, \"*\" and an address,\n\
16107 or -m MARKER_ID.\n\
16108 If a line number is specified, probe the marker at start of code\n\
16109 for that line. If a function is specified, probe the marker at start\n\
16110 of code for that function. If an address is specified, probe the marker\n\
16111 at that exact address. If a marker id is specified, probe the marker\n\
16112 with that name. With no LOCATION, uses current execution address of\n\
16113 the selected stack frame.\n\
16114 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16115 This collects arbitrary user data passed in the probe point call to the\n\
16116 tracing library. You can inspect it when analyzing the trace buffer,\n\
16117 by printing the $_sdata variable like any other convenience variable.\n\
16118 \n\
16119 CONDITION is a boolean expression.\n\
16120 \n\
16121 Multiple tracepoints at one place are permitted, and useful if their\n\
16122 conditions are different.\n\
16123 \n\
16124 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16125 Do \"help tracepoints\" for info on other tracepoint commands."));
16126  set_cmd_completer (c, location_completer);
16127 
16128  add_info ("tracepoints", tracepoints_info, _("\
16129 Status of specified tracepoints (all tracepoints if no argument).\n\
16130 Convenience variable \"$tpnum\" contains the number of the\n\
16131 last tracepoint set."));
16132 
16133  add_info_alias ("tp", "tracepoints", 1);
16134 
16135  add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
16136 Delete specified tracepoints.\n\
16137 Arguments are tracepoint numbers, separated by spaces.\n\
16138 No argument means delete all tracepoints."),
16139  &deletelist);
16140  add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
16141 
16142  c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
16143 Disable specified tracepoints.\n\
16144 Arguments are tracepoint numbers, separated by spaces.\n\
16145 No argument means disable all tracepoints."),
16146  &disablelist);
16147  deprecate_cmd (c, "disable");
16148 
16149  c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
16150 Enable specified tracepoints.\n\
16151 Arguments are tracepoint numbers, separated by spaces.\n\
16152 No argument means enable all tracepoints."),
16153  &enablelist);
16154  deprecate_cmd (c, "enable");
16155 
16156  add_com ("passcount", class_trace, trace_pass_command, _("\
16157 Set the passcount for a tracepoint.\n\
16158 The trace will end when the tracepoint has been passed 'count' times.\n\
16159 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16160 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16161 
16163  _("Save breakpoint definitions as a script."),
16164  &save_cmdlist, "save ",
16165  0/*allow-unknown*/, &cmdlist);
16166 
16167  c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16168 Save current breakpoint definitions as a script.\n\
16169 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16170 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16171 session to restore them."),
16172  &save_cmdlist);
16173  set_cmd_completer (c, filename_completer);
16174 
16175  c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16176 Save current tracepoint definitions as a script.\n\
16177 Use the 'source' command in another debug session to restore them."),
16178  &save_cmdlist);
16179  set_cmd_completer (c, filename_completer);
16180 
16181  c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16182  deprecate_cmd (c, "save tracepoints");
16183 
16185 Breakpoint specific settings\n\
16186 Configure various breakpoint-specific variables such as\n\
16187 pending breakpoint behavior"),
16188  &breakpoint_set_cmdlist, "set breakpoint ",
16189  0/*allow-unknown*/, &setlist);
16191 Breakpoint specific settings\n\
16192 Configure various breakpoint-specific variables such as\n\
16193 pending breakpoint behavior"),
16194  &breakpoint_show_cmdlist, "show breakpoint ",
16195  0/*allow-unknown*/, &showlist);
16196 
16198  &pending_break_support, _("\
16199 Set debugger's behavior regarding pending breakpoints."), _("\
16200 Show debugger's behavior regarding pending breakpoints."), _("\
16201 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16202 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16203 an error. If auto, an unrecognized breakpoint location results in a\n\
16204 user-query to see if a pending breakpoint should be created."),
16205  NULL,
16207  &breakpoint_set_cmdlist,
16208  &breakpoint_show_cmdlist);
16209 
16210  pending_break_support = AUTO_BOOLEAN_AUTO;
16211 
16212  add_setshow_boolean_cmd ("auto-hw", no_class,
16213  &automatic_hardware_breakpoints, _("\
16214 Set automatic usage of hardware breakpoints."), _("\
16215 Show automatic usage of hardware breakpoints."), _("\
16216 If set, the debugger will automatically use hardware breakpoints for\n\
16217 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16218 a warning will be emitted for such breakpoints."),
16219  NULL,
16221  &breakpoint_set_cmdlist,
16222  &breakpoint_show_cmdlist);
16223 
16224  add_setshow_boolean_cmd ("always-inserted", class_support,
16225  &always_inserted_mode, _("\
16226 Set mode for inserting breakpoints."), _("\
16227 Show mode for inserting breakpoints."), _("\
16228 When this mode is on, breakpoints are inserted immediately as soon as\n\
16229 they're created, kept inserted even when execution stops, and removed\n\
16230 only when the user deletes them. When this mode is off (the default),\n\
16231 breakpoints are inserted only when execution continues, and removed\n\
16232 when execution stops."),
16233  NULL,
16235  &breakpoint_set_cmdlist,
16236  &breakpoint_show_cmdlist);
16237 
16238  add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16239  condition_evaluation_enums,
16240  &condition_evaluation_mode_1, _("\
16241 Set mode of breakpoint condition evaluation."), _("\
16242 Show mode of breakpoint condition evaluation."), _("\
16243 When this is set to \"host\", breakpoint conditions will be\n\
16244 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16245 breakpoint conditions will be downloaded to the target (if the target\n\
16246 supports such feature) and conditions will be evaluated on the target's side.\n\
16247 If this is set to \"auto\" (default), this will be automatically set to\n\
16248 \"target\" if it supports condition evaluation, otherwise it will\n\
16249 be set to \"gdb\""),
16252  &breakpoint_set_cmdlist,
16253  &breakpoint_show_cmdlist);
16254 
16255  add_com ("break-range", class_breakpoint, break_range_command, _("\
16256 Set a breakpoint for an address range.\n\
16257 break-range START-LOCATION, END-LOCATION\n\
16258 where START-LOCATION and END-LOCATION can be one of the following:\n\
16259  LINENUM, for that line in the current file,\n\
16260  FILE:LINENUM, for that line in that file,\n\
16261  +OFFSET, for that number of lines after the current line\n\
16262  or the start of the range\n\
16263  FUNCTION, for the first line in that function,\n\
16264  FILE:FUNCTION, to distinguish among like-named static functions.\n\
16265  *ADDRESS, for the instruction at that address.\n\
16266 \n\
16267 The breakpoint will stop execution of the inferior whenever it executes\n\
16268 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16269 range (including START-LOCATION and END-LOCATION)."));
16270 
16271  c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16272 Set a dynamic printf at specified line or function.\n\
16273 dprintf location,format string,arg1,arg2,...\n\
16274 location may be a line number, function name, or \"*\" and an address.\n\
16275 If a line number is specified, break at start of code for that line.\n\
16276 If a function is specified, break at start of code for that function."));
16277  set_cmd_completer (c, location_completer);
16278 
16279  add_setshow_enum_cmd ("dprintf-style", class_support,
16280  dprintf_style_enums, &dprintf_style, _("\
16281 Set the style of usage for dynamic printf."), _("\
16282 Show the style of usage for dynamic printf."), _("\
16283 This setting chooses how GDB will do a dynamic printf.\n\
16284 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16285 console, as with the \"printf\" command.\n\
16286 If the value is \"call\", the print is done by calling a function in your\n\
16287 program; by default printf(), but you can choose a different function or\n\
16288 output stream by setting dprintf-function and dprintf-channel."),
16290  &setlist, &showlist);
16291 
16292  dprintf_function = xstrdup ("printf");
16293  add_setshow_string_cmd ("dprintf-function", class_support,
16294  &dprintf_function, _("\
16295 Set the function to use for dynamic printf"), _("\
16296 Show the function to use for dynamic printf"), NULL,
16298  &setlist, &showlist);
16299 
16300  dprintf_channel = xstrdup ("");
16301  add_setshow_string_cmd ("dprintf-channel", class_support,
16302  &dprintf_channel, _("\
16303 Set the channel to use for dynamic printf"), _("\
16304 Show the channel to use for dynamic printf"), NULL,
16306  &setlist, &showlist);
16307 
16308  add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16309  &disconnected_dprintf, _("\
16310 Set whether dprintf continues after GDB disconnects."), _("\
16311 Show whether dprintf continues after GDB disconnects."), _("\
16312 Use this to let dprintf commands continue to hit and produce output\n\
16313 even if GDB disconnects or detaches from the target."),
16314  NULL,
16315  NULL,
16316  &setlist, &showlist);
16317 
16318  add_com ("agent-printf", class_vars, agent_printf_command, _("\
16319 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16320 (target agent only) This is useful for formatted output in user-defined commands."));
16321 
16322  automatic_hardware_breakpoints = 1;
16323 
16326 }
int threads_are_executing(void)
Definition: thread.c:880
void error_no_arg(const char *why)
Definition: cli-cmds.c:205
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5143
int frame_id_p(struct frame_id l)
Definition: frame.c:576
static int watchpoint_locations_match(struct bp_location *loc1, struct bp_location *loc2)
Definition: breakpoint.c:6950
static struct breakpoint_ops catch_exec_breakpoint_ops
Definition: breakpoint.c:8611
static void watch_maybe_just_location(char *arg, int accessflag, int from_tty)
Definition: breakpoint.c:11359
char enabled
Definition: breakpoint.h:368
struct frame_info * frame_find_by_id(struct frame_id id)
Definition: frame.c:733
#define OBJF_USERLOADED
Definition: objfiles.h:445
static struct breakpoint_ops tracepoint_probe_breakpoint_ops
Definition: breakpoint.c:13353
static void strace_command(char *arg, int from_tty)
Definition: breakpoint.c:14927
#define target_can_async_p()
Definition: target.h:1748
static int breakpoint_1(char *, int, int(*)(const struct breakpoint *))
Definition: breakpoint.c:6658
void annotate_watchpoint(int num)
Definition: annotate.c:105
struct agent_expr * cond_bytecode
Definition: breakpoint.h:338
void set_cmd_context(struct cmd_list_element *cmd, void *context)
Definition: cli-decode.c:141
int body_count
Definition: defs.h:413
void free_agent_expr(struct agent_expr *x)
Definition: ax-general.c:67
static int remove_catch_exec(struct bp_location *bl)
Definition: breakpoint.c:8523
CORE_ADDR reqstd_address
Definition: breakpoint.h:235
static struct bp_location * find_location_by_number(char *number)
Definition: breakpoint.c:14440
static struct breakpoint_ops bkpt_probe_breakpoint_ops
Definition: breakpoint.c:316
#define target_remove_fork_catchpoint(pid)
Definition: target.h:1551
static int all_locations_are_pending(struct bp_location *loc)
Definition: breakpoint.c:13730
union exp_element elts[1]
Definition: expression.h:85
enum condition_status condition_changed
Definition: breakpoint.h:353
struct value * value_mark(void)
Definition: value.c:1499
void(* walk_bp_location_callback)(struct bp_location *, void *)
Definition: breakpoint.h:1216
int input_radix
Definition: breakpoint.h:722
int moribund_breakpoint_here_p(struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:4220
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:338
static const struct objfile_data * breakpoint_objfile_key
Definition: breakpoint.c:3363
void release_static_tracepoint_marker(struct static_tracepoint_marker *marker)
Definition: tracepoint.c:3941
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition: source.c:1171
static const char * bp_location_condition_evaluator(struct bp_location *bl)
Definition: breakpoint.c:5995
void annotate_breakpoints_table(void)
Definition: annotate.c:195
#define SYMTAB_COMPUNIT(symtab)
Definition: symtab.h:965
int line_number
Definition: breakpoint.h:466
struct command_line * breakpoint_commands(struct breakpoint *b)
Definition: breakpoint.c:372
CORE_ADDR hw_wp_mask
Definition: breakpoint.h:825
static void init_raw_breakpoint_without_location(struct breakpoint *b, struct gdbarch *gdbarch, enum bptype bptype, const struct breakpoint_ops *ops)
Definition: breakpoint.c:7278
int demangle
Definition: demangle.c:49
void(* print_recreate)(struct breakpoint *, struct ui_file *fp)
Definition: breakpoint.h:575
static int command_line_is_silent(struct command_line *cmd)
Definition: breakpoint.c:4564
static void show_can_use_hw_watchpoints(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: breakpoint.c:399
struct breakpoint * create_jit_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
Definition: breakpoint.c:7657
struct cleanup * make_show_memory_breakpoints_cleanup(int show)
Definition: target.c:1269
#define OBJF_SHARED
Definition: objfiles.h:432
static void output_thread_groups(struct ui_out *uiout, const char *field_name, VEC(int)*inf_num, int mi_only)
Definition: breakpoint.c:6136
static int base_breakpoint_explains_signal(struct breakpoint *b, enum gdb_signal sig)
Definition: breakpoint.c:12748
int number_of_program_spaces(void)
Definition: progspace.c:390
breakpoint_here
Definition: breakpoint.h:1124
static struct agent_expr * parse_cond_to_aexpr(CORE_ADDR scope, struct expression *cond)
Definition: breakpoint.c:2236
#define target_can_run_breakpoint_commands()
Definition: target.h:1378
void observer_notify_breakpoint_created(struct breakpoint *b)
void handle_solib_event(void)
Definition: solib.c:1327
struct thread_info * find_thread_ptid(ptid_t ptid)
Definition: thread.c:393
void awatch_command_wrapper(char *arg, int from_tty, int internal)
Definition: breakpoint.c:11393
struct thread_info * find_thread_id(int num)
Definition: thread.c:380
static struct bp_location * allocate_bp_location(struct breakpoint *bpt)
Definition: breakpoint.c:7221
static void clear_command(char *, int)
Definition: breakpoint.c:11738
static void base_breakpoint_re_set(struct breakpoint *b)
Definition: breakpoint.c:12634
void set_ignore_count(int bptnum, int count, int from_tty)
Definition: breakpoint.c:14331
static void enable_count_command(char *, int)
Definition: breakpoint.c:14743
#define target_remove_watchpoint(addr, len, type, cond)
Definition: target.h:1892
static void insert_breakpoint_locations(void)
Definition: breakpoint.c:3079
struct observer * observer_attach_thread_exit(observer_thread_exit_ftype *f)
struct value * value_addr(struct value *arg1)
Definition: valops.c:1472
void enable_breakpoints_after_startup(void)
Definition: breakpoint.c:8723
void enable_overlay_breakpoints(void)
Definition: breakpoint.c:7565
static void free_bp_location(struct bp_location *loc)
Definition: breakpoint.c:7227
int putchar_unfiltered(int c)
Definition: utils.c:2151
static void tracepoint_decode_linespec(struct breakpoint *b, char **s, struct symtabs_and_lines *sals)
Definition: breakpoint.c:13323
int dbx_commands
Definition: main.c:54
static void print_one_catch_vfork(struct breakpoint *b, struct bp_location **last_loc)
Definition: breakpoint.c:8106
void remove_solib_event_breakpoints(void)
Definition: breakpoint.c:7681
command_control_type
Definition: defs.h:379
const struct blockvector * blockvector_for_pc_sect(CORE_ADDR pc, struct obj_section *section, const struct block **pblock, struct compunit_symtab *cust)
Definition: block.c:184
struct frame_info * get_selected_frame(const char *message)
Definition: frame.c:1535
void init_bp_location(struct bp_location *loc, const struct bp_location_ops *ops, struct breakpoint *owner)
Definition: breakpoint.c:7152
static void bkpt_decode_linespec(struct breakpoint *b, char **s, struct symtabs_and_lines *sals)
Definition: breakpoint.c:12980
void * get_cmd_context(struct cmd_list_element *cmd)
Definition: cli-decode.c:147
enum language language
Definition: breakpoint.h:720
void delete_longjmp_breakpoint_cleanup(void *arg)
Definition: infcmd.c:898
#define BP_TEMPFLAG
Definition: breakpoint.c:4997
static void iterate_over_related_breakpoints(struct breakpoint *b, void(*function)(struct breakpoint *, void *), void *data)
Definition: breakpoint.c:13647
struct observer * observer_attach_free_objfile(observer_free_objfile_ftype *f)
static void print_one_catch_exec(struct breakpoint *b, struct bp_location **last_loc)
Definition: breakpoint.c:8569
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2217
static const char * breakpoint_condition_evaluation_mode(void)
Definition: breakpoint.c:526
#define SYMBOL_PRINT_NAME(symbol)
Definition: symtab.h:260
void value_free_to_mark(struct value *mark)
Definition: value.c:1551
static void remove_threaded_breakpoints(struct thread_info *tp, int silent)
Definition: breakpoint.c:3201
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition: valprint.c:870
static struct counted_command_line * alloc_counted_command_line(struct command_line *commands)
Definition: breakpoint.c:715
void ui_out_wrap_hint(struct ui_out *uiout, char *identstring)
Definition: ui-out.c:600
void add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:719
void check_tracepoint_command(char *line, void *closure)
Definition: breakpoint.c:1312
int single_step_breakpoint_inserted_here_p(struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:14860
enum exp_opcode opcode
Definition: expression.h:65
static void handle_jit_event(void)
Definition: breakpoint.c:5667
static void show_automatic_hardware_breakpoints(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: breakpoint.c:431
void ui_out_field_stream(struct ui_out *uiout, const char *fldname, struct ui_file *stream)
Definition: ui-out.c:509
int value_equal_contents(struct value *arg1, struct value *arg2)
Definition: valarith.c:1656
void ui_out_field_int(struct ui_out *uiout, const char *fldname, int value)
Definition: ui-out.c:467
static void stopin_command(char *arg, int from_tty)
Definition: breakpoint.c:9940
static void bpstat_remove_bp_location(bpstat bps, struct breakpoint *bpt)
Definition: breakpoint.c:12517
struct frame_info * get_current_frame(void)
Definition: frame.c:1461
static void internal_bkpt_re_set(struct breakpoint *b)
Definition: breakpoint.c:12989
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
Definition: ptid.c:76
bfd_vma CORE_ADDR
Definition: common-types.h:41
static void base_breakpoint_print_mention(struct breakpoint *b)
Definition: breakpoint.c:12701
static struct uploaded_tp * this_utp
Definition: breakpoint.c:14954
void disable_breakpoints_before_startup(void)
Definition: breakpoint.c:8716
enum target_hw_bp_type watchpoint_type
Definition: breakpoint.h:418
struct address_space * aspace
Definition: progspace.h:166
void insert_breakpoints(void)
Definition: breakpoint.c:2984
static struct breakpoint_ops catch_vfork_breakpoint_ops
Definition: breakpoint.c:8153
int target_remove_breakpoint(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: target.c:2060
int is_breakpoint(const struct breakpoint *bpt)
Definition: breakpoint.c:1674
#define BREAK_ARGS_HELP(command)
Definition: breakpoint.c:15446
void ui_out_spaces(struct ui_out *uiout, int numspaces)
Definition: ui-out.c:576
int(* works_in_software_mode)(const struct breakpoint *)
Definition: breakpoint.h:546
static int breakpoint_locations_match(struct bp_location *loc1, struct bp_location *loc2)
Definition: breakpoint.c:7056
static void catch_exec_command_1(char *arg, int from_tty, struct cmd_list_element *command)
Definition: breakpoint.c:11632
void bpstat_clear(bpstat *bsp)
Definition: breakpoint.c:4381
static void print_one_breakpoint_location(struct breakpoint *b, struct bp_location *loc, int loc_number, struct bp_location **last_loc, int allflag)
Definition: breakpoint.c:6179
void xfree(void *)
Definition: common-utils.c:97
void bpstat_clear_actions(void)
Definition: breakpoint.c:4508
static void check_fast_tracepoint_sals(struct gdbarch *gdbarch, struct symtabs_and_lines *sals)
Definition: breakpoint.c:9407
static void do_disable_breakpoint(struct breakpoint *b, void *ignore)
Definition: breakpoint.c:14516
void annotate_record(void)
Definition: annotate.c:202
int may_insert_fast_tracepoints
struct breakpoint * create_solib_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
Definition: breakpoint.c:7721
int value_offset(const struct value *value)
Definition: value.c:1032
static int works_in_software_mode_watchpoint(const struct breakpoint *b)
Definition: breakpoint.c:10558
struct cmd_list_element * enablelist
Definition: cli-cmds.c:111
static void print_recreate_catch_fork(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:8029
static void print_recreate_masked_watchpoint(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:10892
#define gnu_ifunc_resolver_stop
Definition: symtab.h:1356
static void enable_delete_command(char *, int)
Definition: breakpoint.c:14764
enum print_stop_action bpstat_print(bpstat bs, int kind)
Definition: breakpoint.c:4839
static int remove_masked_watchpoint(struct bp_location *bl)
Definition: breakpoint.c:10758
int section_is_overlay(struct obj_section *section)
Definition: symfile.c:3089
LONGEST value_as_long(struct value *val)
Definition: value.c:2654
static void momentary_bkpt_check_status(bpstat bs)
Definition: breakpoint.c:13095
CORE_ADDR frame_unwind_caller_pc(struct frame_info *this_frame)
Definition: frame.c:870
int number_is_in_list(const char *list, int number)
Definition: cli-utils.c:205
static void break_command_1(char *, int, int)
Definition: breakpoint.c:9820
void(* func)(char *)
int events_till_retirement
Definition: breakpoint.h:459
if(!(yy_init))
Definition: ada-lex.c:1072
static void base_breakpoint_print_recreate(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:12707
static void thbreak_command(char *, int)
Definition: breakpoint.c:9926
void add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:487
static int breakpoint_address_is_meaningful(struct breakpoint *bpt)
Definition: breakpoint.c:6939
struct gdbarch * frame_unwind_caller_arch(struct frame_info *next_frame)
Definition: frame.c:2569
int hardware_breakpoint_inserted_here_p(struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:4302
#define BMSYMBOL_VALUE_ADDRESS(symbol)
Definition: symtab.h:393
struct breakpoint base
Definition: breakpoint.c:7914
void warning(const char *fmt,...)
Definition: errors.c:26
#define CATCH_TEMPORARY
Definition: breakpoint.h:1247
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition: cli-decode.c:272
struct counted_command_line * commands
Definition: breakpoint.h:695
#define target_enable_tracepoint(loc)
Definition: target.h:2087
struct breakpoint * set_momentary_breakpoint_at_pc(struct gdbarch *gdbarch, CORE_ADDR pc, enum bptype type)
Definition: breakpoint.c:8832
struct bpstats * bpstat
Definition: breakpoint.h:894
static void do_enable_breakpoint_disp(struct breakpoint *bpt, void *arg)
Definition: breakpoint.c:14713
static int next_cmd
Definition: breakpoint.c:14955
int query(const char *ctlstr,...)
Definition: utils.c:1364
static void print_mention_catch_fork(struct breakpoint *b)
Definition: breakpoint.c:8020
static void set_breakpoint_cmd(char *args, int from_tty)
Definition: breakpoint.c:14770
void jit_breakpoint_re_set(void)
Definition: jit.c:1371
struct program_space * pspace
Definition: objfiles.h:286
static void map_breakpoint_numbers(char *, void(*)(struct breakpoint *, void *), void *)
bpdisp
Definition: breakpoint.h:201
struct command_line * read_command_lines_1(char *(*read_next_line_func)(void), int parse_commands, void(*validator)(char *, void *), void *closure)
Definition: cli-script.c:1306
static void print_mention_watchpoint(struct breakpoint *b)
Definition: breakpoint.c:10660
enum print_stop_action(* print_it)(struct bpstats *bs)
Definition: breakpoint.h:550
static void disable_command(char *, int)
Definition: breakpoint.c:14531
struct bound_minimal_symbol overlay_msym
Definition: breakpoint.c:3339
#define target_supports_enable_disable_tracepoint()
Definition: target.h:1363
int value_bitpos(const struct value *value)
Definition: value.c:1043
tuple inf
Definition: arm-linux.py:13
void breakpoint_auto_delete(bpstat bs)
Definition: breakpoint.c:11914
static void rwatch_command(char *arg, int from_tty)
Definition: breakpoint.c:11387
static void show_always_inserted_mode(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: breakpoint.c:450
static int bp_location_has_shadow(struct bp_location *bl)
Definition: breakpoint.c:1456
struct symbol * find_pc_sect_function(CORE_ADDR pc, struct obj_section *section)
Definition: blockframe.c:136
enum language set_language(enum language lang)
Definition: language.c:346
struct cleanup * make_cleanup_ui_out_table_begin_end(struct ui_out *ui_out, int nr_cols, int nr_rows, const char *tblid)
Definition: ui-out.c:369
void destroy_linespec_result(struct linespec_result *ls)
Definition: linespec.c:3780
struct counted_command_line * commands
Definition: breakpoint.h:1098
static struct breakpoint_ops ranged_breakpoint_ops
Definition: breakpoint.c:10174
static enum auto_boolean pending_break_support
Definition: breakpoint.c:413
static struct cmd_list_element * catch_cmdlist
Definition: breakpoint.c:15468
struct cmd_list_element * maintenanceinfolist
Definition: cli-cmds.c:163
static void base_breakpoint_create_sals_from_address(char **arg, struct linespec_result *canonical, enum bptype type_wanted, char *addr_start, char **copy_arg)
Definition: breakpoint.c:12713
struct symtab * symtab
Definition: breakpoint.h:471
const char * skip_to_space_const(const char *chp)
Definition: common-utils.c:283
static void show_breakpoint_cmd(char *args, int from_tty)
Definition: breakpoint.c:14775
struct symtab_and_line get_current_source_symtab_and_line(void)
Definition: source.c:181
void annotate_field(int num)
Definition: annotate.c:188
static enum print_stop_action momentary_bkpt_print_it(bpstat bs)
Definition: breakpoint.c:13101
struct ui_file * gdb_stdout
Definition: main.c:71
int(* resources_needed)(const struct bp_location *)
Definition: breakpoint.h:541
static void enable_trace_command(char *, int)
Definition: breakpoint.c:15082
static void print_mention_ranged_breakpoint(struct breakpoint *b)
Definition: breakpoint.c:10145
#define internal_error_pure_virtual_called()
Definition: breakpoint.c:12639
static void print_recreate_catch_solib(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:8344
char duplicate
Definition: breakpoint.h:386
static const char * condition_evaluation_mode
Definition: breakpoint.c:502
void(* dtor)(struct bp_location *self)
Definition: breakpoint.h:300
static int need_moribund_for_location_type(struct bp_location *loc)
Definition: breakpoint.c:5465
struct obj_section * section
Definition: breakpoint.h:423
static int bp_location_inserted_here_p(struct bp_location *bl, struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:4236
void select_frame(struct frame_info *fi)
Definition: frame.c:1574
#define target_supports_stopped_by_sw_breakpoint()
Definition: target.h:1838
struct ui_file * gdb_fopen(const char *name, const char *mode)
Definition: ui-file.c:723
bp_type
Definition: mi-cmd-break.c:56
struct frame_id get_stack_frame_id(struct frame_info *next_frame)
Definition: frame.c:483
enum errors error
bpstat next
Definition: breakpoint.h:1072
#define SYMBOL_CLASS(symbol)
Definition: symtab.h:793
static int automatic_hardware_breakpoints
Definition: breakpoint.c:429
enum breakpoint_here breakpoint_here_p(struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:4187
catch_fork_kind
Definition: breakpoint.c:11577
void internal_error(const char *file, int line, const char *fmt,...)
Definition: errors.c:50
const struct frame_id null_frame_id
Definition: frame.c:506
int num
Definition: inferior.h:295
struct thread_info * inferior_thread(void)
Definition: thread.c:85
static void update_global_location_list_nothrow(enum ugll_insert_mode)
Definition: breakpoint.c:12501
static void set_condition_evaluation_mode(char *args, int from_tty, struct cmd_list_element *c)
Definition: breakpoint.c:835
struct breakpoint base
Definition: breakpoint.h:858
void init_sal(struct symtab_and_line *sal)
Definition: symtab.c:1064
static int breakpoint_hit_ranged_breakpoint(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:10035
static void bp_location_target_extensions_update(void)
Definition: breakpoint.c:11975
void unpack_value_bitfield(struct value *dest_val, int bitpos, int bitsize, const gdb_byte *valaddr, int embedded_offset, const struct value *val)
Definition: value.c:3285
int ui_out_is_mi_like_p(struct ui_out *uiout)
Definition: ui-out.c:655
static void print_one_catch_fork(struct breakpoint *b, struct bp_location **last_loc)
Definition: breakpoint.c:7989
struct cmd_list_element * deletelist
Definition: cli-cmds.c:123
#define VEC_unordered_remove(T, V, I)
Definition: vec.h:351
static void dprintf_re_set(struct breakpoint *b)
Definition: breakpoint.c:13358
struct value * val
Definition: breakpoint.h:796
struct symtabs_and_lines parse_probes(char **argptr, struct linespec_result *canonical)
Definition: probe.c:46
void(* print_mention)(struct breakpoint *)
Definition: breakpoint.h:572
const struct gdb_exception exception_none
static void bpstat_check_breakpoint_conditions(bpstat bs, ptid_t ptid)
Definition: breakpoint.c:5331
static void dtor_watchpoint(struct breakpoint *self)
Definition: breakpoint.c:10441
char * get_regcomp_error(int, regex_t *)
Definition: utils.c:1149
enum bpdisp disp
Definition: breakpoint.c:14708
int(* breakpoint_hit)(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.h:529
void(* set_semaphore)(struct probe *probe, struct objfile *objfile, struct gdbarch *gdbarch)
Definition: probe.h:101
static void update_dprintf_commands(char *args, int from_tty, struct cmd_list_element *c)
Definition: breakpoint.c:9059
void value_free(struct value *val)
Definition: value.c:1518
struct symbol * block_linkage_function(const struct block *bl)
Definition: block.c:100
static void do_delete_breakpoint(struct breakpoint *b, void *ignore)
Definition: breakpoint.c:13681
int breakpoints_not_allowed
Definition: progspace.h:180
static int bkpt_insert_location(struct bp_location *bl)
Definition: breakpoint.c:12801
#define target_insert_watchpoint(addr, len, type, cond)
Definition: target.h:1888
Definition: ax.h:95
int catch_errors(catch_errors_ftype *func, void *func_args, char *errstring, return_mask mask)
Definition: exceptions.c:228
#define target_insert_fork_catchpoint(pid)
Definition: target.h:1548
struct value * value_copy(struct value *arg)
Definition: value.c:1667
struct breakpoint_ops dprintf_breakpoint_ops
Definition: breakpoint.c:319
static int overlay_events_enabled
Definition: breakpoint.c:548
const struct block * innermost_block
Definition: parse.c:69
static void print_mention_catch_solib(struct breakpoint *b)
Definition: breakpoint.c:8335
static int ambiguous_names_p(struct bp_location *loc)
Definition: breakpoint.c:13744
static int breakpoint_hit_watchpoint(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:10514
enum command_control_type commands_from_control_command(char *arg, struct command_line *cmd)
Definition: breakpoint.c:1447
static struct bp_location * base_breakpoint_allocate_location(struct breakpoint *self)
Definition: breakpoint.c:12624
char * memory_error_message(enum target_xfer_status err, struct gdbarch *gdbarch, CORE_ADDR memaddr)
Definition: corefile.c:193
enum language la_language
Definition: language.h:152
Definition: solist.h:30
void validate_actionline(const char *line, struct breakpoint *b)
Definition: tracepoint.c:699
static void trace_command(char *arg, int from_tty)
Definition: breakpoint.c:14885
struct bp_location *(* allocate_location)(struct breakpoint *)
Definition: breakpoint.h:505
const struct block * cond_exp_valid_block
Definition: breakpoint.h:792
static int is_masked_watchpoint(const struct breakpoint *b)
Definition: breakpoint.c:10925
int can_evaluate_probe_arguments(struct probe *probe)
Definition: probe.c:809
struct breakpoint * create_thread_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
Definition: breakpoint.c:7620
static enum print_stop_action print_bp_stop_message(bpstat bs)
Definition: breakpoint.c:4709
#define VEC_safe_push(T, V, O)
Definition: vec.h:260
void set_cmd_sfunc(struct cmd_list_element *cmd, cmd_sfunc_ftype *sfunc)
Definition: cli-decode.c:125
static void bkpt_probe_create_sals_from_address(char **arg, struct linespec_result *canonical, enum bptype type_wanted, char *addr_start, char **copy_arg)
Definition: breakpoint.c:13183
static int breakpoint_hit_catch_exec(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:8529
struct obj_section * section
Definition: symtab.h:1370
struct cmd_list_element * cmdlist
Definition: cli-cmds.c:103
void set_next_address(struct gdbarch *, CORE_ADDR)
Definition: printcmd.c:534
int reattach_breakpoints(int pid)
Definition: breakpoint.c:3246
void save_trace_state_variables(struct ui_file *fp)
Definition: tracepoint.c:556
struct gdbpy_breakpoint_object * py_bp_object
Definition: breakpoint.h:762
struct tracepoint * get_tracepoint(int num)
Definition: breakpoint.c:15197
struct breakpoint * set_raw_breakpoint(struct gdbarch *gdbarch, struct symtab_and_line, enum bptype, const struct breakpoint_ops *)
Definition: breakpoint.c:7424
static void set_breakpoint_number(int internal, struct breakpoint *b)
Definition: breakpoint.c:3297
struct internalvar * lookup_internalvar(const char *name)
Definition: value.c:2131
static void bpstat_free(bpstat bs)
Definition: breakpoint.c:4368
void rwatch_command_wrapper(char *arg, int from_tty, int internal)
Definition: breakpoint.c:11381
char * skip_spaces(char *chp)
Definition: common-utils.c:259
#define _(String)
Definition: gdb_locale.h:40
static void print_breakpoint_location(struct breakpoint *b, struct bp_location *loc)
Definition: breakpoint.c:6013
const gdb_byte * value_contents_for_printing(struct value *value)
Definition: value.c:1173
void set_longjmp_breakpoint(struct thread_info *tp, struct frame_id frame)
Definition: breakpoint.c:7440
static void find_condition_and_thread(const char *tok, CORE_ADDR pc, char **cond_string, int *thread, int *task, char **rest)
Definition: breakpoint.c:9454
static int breakpoint_proceeded
Definition: breakpoint.c:380
ULONGEST traceframe_usage
Definition: tracepoint.h:193
static char * read_uploaded_action(void)
Definition: breakpoint.c:14958
int bpstat_causes_stop(bpstat bs)
Definition: breakpoint.c:5910
int number_of_inferiors(void)
Definition: inferior.c:522
static int hw_breakpoint_used_count(void)
Definition: breakpoint.c:8614
static void decref_bp_location(struct bp_location **loc)
Definition: breakpoint.c:7245
static int breakpoint_enabled(struct breakpoint *b)
Definition: breakpoint.c:663
static void create_sals_from_address_default(char **, struct linespec_result *, enum bptype, char *, char **)
Definition: breakpoint.c:14174
Definition: ui-out.h:40
insertion_state_t
Definition: breakpoint.c:188
static struct bp_location * add_location_to_breakpoint(struct breakpoint *, const struct symtab_and_line *)
Definition: breakpoint.c:8861
char * char_ptr
Definition: gdb_vecs.h:25
static void create_exception_master_breakpoint(void)
Definition: breakpoint.c:3627
void add_catch_command(char *name, char *docstring, cmd_sfunc_ftype *sfunc, completer_ftype *completer, void *user_data_catch, void *user_data_tcatch)
Definition: breakpoint.c:15474
static void breakpoint_re_set_default(struct breakpoint *)
Definition: breakpoint.c:14143
int program_breakpoint_here_p(struct gdbarch *gdbarch, CORE_ADDR address)
Definition: breakpoint.c:8925
void init_ada_exception_breakpoint(struct breakpoint *b, struct gdbarch *gdbarch, struct symtab_and_line sal, char *addr_string, const struct breakpoint_ops *ops, int tempflag, int enabled, int from_tty)
Definition: breakpoint.c:11665
static void build_target_command_list(struct bp_location *bl)
Definition: breakpoint.c:2463
static void create_breakpoint_sal(struct gdbarch *gdbarch, struct symtabs_and_lines sals, char *addr_string, char *filter, char *cond_string, char *extra_string, enum bptype type, enum bpdisp disposition, int thread, int task, int ignore_count, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags, int display_canonical)
Definition: breakpoint.c:9216
#define ALL_BREAKPOINTS_SAFE(B, TMP)
Definition: breakpoint.c:559
#define target_stopped_by_watchpoint()
Definition: target.h:1829
struct symtabs_and_lines sals
Definition: linespec.h:50
int get_number(char **pp)
Definition: cli-utils.c:119
struct breakpoint_ops tracepoint_breakpoint_ops
Definition: breakpoint.c:13329
void breakpoint_program_space_exit(struct program_space *pspace)
Definition: breakpoint.c:2941
static struct breakpoint * momentary_breakpoint_from_master(struct breakpoint *orig, enum bptype type, const struct breakpoint_ops *ops, int loc_enabled)
Definition: breakpoint.c:8786
#define END_CATCH
int stepping_past_instruction_at(struct address_space *aspace, CORE_ADDR address)
Definition: infrun.c:1292
static struct breakpoint_ops longjmp_breakpoint_ops
Definition: breakpoint.c:309
static void trace_pass_command(char *, int)
Definition: breakpoint.c:15150
void ui_out_field_fmt(struct ui_out *uiout, const char *fldname, const char *format,...)
Definition: ui-out.c:556
#define VALUE_LVAL(val)
Definition: value.h:411
void enable_breakpoint(struct breakpoint *bpt)
Definition: breakpoint.c:14637
static void stop_command(char *arg, int from_tty)
Definition: breakpoint.c:9932
struct value * allocate_value(struct type *type)
Definition: value.c:962
static int insert_catch_exec(struct bp_location *bl)
Definition: breakpoint.c:8517
Definition: ui-out.c:99
void free_format_pieces_cleanup(void *ptr)
Definition: format.c:383
void delete_longjmp_breakpoint(int thread)
Definition: breakpoint.c:7469
static void ignore_command(char *, int)
Definition: breakpoint.c:14374
struct bound_minimal_symbol lookup_minimal_symbol_text(const char *name, struct objfile *objf)
Definition: minsyms.c:392
tuple m
Definition: arm-linux.py:44
static int remove_breakpoint_1(struct bp_location *, insertion_state_t)
Definition: breakpoint.c:3888
void get_last_displayed_sal(struct symtab_and_line *sal)
Definition: stack.c:1030
static CORE_ADDR bp_location_shadow_len_after_address_max
Definition: breakpoint.c:619
#define target_stopped_data_address(target, addr_p)
Definition: target.h:1931
static int works_in_software_mode_masked_watchpoint(const struct breakpoint *b)
Definition: breakpoint.c:10781
void ui_out_text(struct ui_out *uiout, const char *string)
Definition: ui-out.c:582
const struct block * block_for_pc(CORE_ADDR pc)
Definition: block.c:282
int is_addr_in_objfile(CORE_ADDR addr, const struct objfile *objfile)
Definition: objfiles.c:1436
void _initialize_breakpoint(void)
Definition: breakpoint.c:15759
struct gdbarch * gdbarch
Definition: breakpoint.h:718
int may_insert_tracepoints
void printf_filtered(const char *format,...)
Definition: utils.c:2388
char * exp_string
Definition: breakpoint.h:779
int longest_to_int(LONGEST)
Definition: valprint.c:1054
void dummy_frame_discard(struct frame_id dummy_id, ptid_t ptid)
Definition: dummy-frame.c:221
int breakpoint_inserted_here_p(struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:4256
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2743
Definition: ptid.h:35
static struct type * new_type(char *)
Definition: mdebugread.c:4864
void breakpoint_set_task(struct breakpoint *b, int task)
Definition: breakpoint.c:1302
static struct breakpoint_ops bkpt_base_breakpoint_ops
Definition: breakpoint.c:300
#define SYMBOL_OBJ_SECTION(objfile, symbol)
Definition: symtab.h:189
static void catch_load_command_1(char *arg, int from_tty, struct cmd_list_element *command)
Definition: breakpoint.c:8420
static struct symtabs_and_lines addr_string_to_sals(struct breakpoint *b, char *addr_string, int *found)
Definition: breakpoint.c:14057
struct bound_probe probe
Definition: breakpoint.h:440
struct obj_section * find_pc_overlay(CORE_ADDR pc)
Definition: symfile.c:3287
struct program_space * pspace
Definition: breakpoint.h:703
struct symbol * symbol
Definition: expression.h:66
long step_count
Definition: breakpoint.h:862
void set_current_program_space(struct program_space *pspace)
Definition: progspace.c:199
unsigned input_radix
Definition: valprint.c:166
const char * symtab_to_fullname(struct symtab *s)
Definition: source.c:1131
static struct agent_expr * parse_cmd_to_aexpr(CORE_ADDR scope, char *cmd)
Definition: breakpoint.c:2374
int bpstat_should_step(void)
Definition: breakpoint.c:5899
static void create_breakpoints_sal(struct gdbarch *gdbarch, struct linespec_result *canonical, char *cond_string, char *extra_string, enum bptype type, enum bpdisp disposition, int thread, int task, int ignore_count, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags)
Definition: breakpoint.c:9270
#define target_insert_vfork_catchpoint(pid)
Definition: target.h:1554
void breakpoint_free_objfile(struct objfile *objfile)
Definition: breakpoint.c:15561
static void base_breakpoint_print_one_detail(const struct breakpoint *self, struct ui_out *uiout)
Definition: breakpoint.c:12694
struct trace_status * current_trace_status(void)
Definition: tracepoint.c:205
static int breakpoint_address_match_range(struct address_space *aspace1, CORE_ADDR addr1, int len1, struct address_space *aspace2, CORE_ADDR addr2)
Definition: breakpoint.c:7007
struct counted_command_line * cmd
Definition: breakpoint.c:1336
#define ALL_INFERIORS(I)
Definition: inferior.h:504
static CORE_ADDR adjust_breakpoint_address(struct gdbarch *gdbarch, CORE_ADDR bpaddr, enum bptype bptype)
int hit_count
Definition: breakpoint.h:750
#define MSYMBOL_OBJ_SECTION(objfile, symbol)
Definition: symtab.h:402
struct obstack objfile_obstack
Definition: objfiles.h:328
static enum print_stop_action bkpt_print_it(bpstat bs)
Definition: breakpoint.c:12865
static int breakpoint_location_address_match(struct bp_location *bl, struct address_space *aspace, CORE_ADDR addr)
Definition: breakpoint.c:7022
char * at_string
Definition: tracepoint.h:181
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition: gnu-nat.c:1885
struct cleanup * make_cleanup_delete_breakpoint(struct breakpoint *b)
Definition: breakpoint.c:13638
void null_cleanup(void *arg)
Definition: cleanups.c:295
enum bpdisp disposition
Definition: breakpoint.h:673
struct value * evaluate_expression(struct expression *exp)
Definition: eval.c:159
#define TRY
int valid_thread_id(int thread)
Definition: thread.c:447
int in_thread_list(ptid_t ptid)
Definition: thread.c:482
static void dtor_catch_exec(struct breakpoint *b)
Definition: breakpoint.c:8507
int thread_count(void)
Definition: thread.c:435
static int breakpoint_address_bits(struct breakpoint *b)
Definition: breakpoint.c:6580
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition: thread.c:419
void until_break_command(char *arg, int from_tty, int anywhere)
Definition: breakpoint.c:11431
int frame_id_eq(struct frame_id l, struct frame_id r)
Definition: frame.c:604
static int bpstat_do_actions_1(bpstat *bsp)
Definition: breakpoint.c:4579
char * line
Definition: defs.h:400
int(* insert_location)(struct bp_location *)
Definition: breakpoint.h:515
int gdbarch_fast_tracepoint_valid_at(struct gdbarch *gdbarch, CORE_ADDR addr, int *isize, char **msg)
Definition: gdbarch.c:4397
static int remove_watchpoint(struct bp_location *bl)
Definition: breakpoint.c:10504
static void add_to_breakpoint_chain(struct breakpoint *b)
Definition: breakpoint.c:7257
void(* clear_semaphore)(struct probe *probe, struct objfile *objfile, struct gdbarch *gdbarch)
Definition: probe.h:108
static struct breakpoint * set_raw_breakpoint_without_location(struct gdbarch *, enum bptype, const struct breakpoint_ops *)
Definition: breakpoint.c:7308
struct cmd_list_element * setlist
Definition: cli-cmds.c:135
enum stop_stack_kind call_dummy
Definition: breakpoint.h:995
const char *const name
Definition: aarch64-tdep.c:68
void add_setshow_auto_boolean_cmd(const char *name, enum command_class theclass, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:516
struct format_piece * parse_format_string(const char **arg)
Definition: format.c:24
#define ALL_OBJFILES(obj)
Definition: objfiles.h:579
static CORE_ADDR find_breakpoint_range_end(struct symtab_and_line sal)
Definition: breakpoint.c:10182
static int remove_catch_fork(struct bp_location *bl)
Definition: breakpoint.c:7935
static void re_set_watchpoint(struct breakpoint *b)
Definition: breakpoint.c:10457
static int compare_breakpoints(const void *a, const void *b)
Definition: breakpoint.c:11716
int check_for_argument(char **str, char *arg, int arg_len)
Definition: cli-utils.c:277
char * exec_pathname
Definition: breakpoint.c:8500
static enum print_stop_action internal_bkpt_print_it(bpstat bs)
Definition: breakpoint.c:13030
int shared_objfile_contains_address_p(struct program_space *pspace, CORE_ADDR address)
Definition: objfiles.c:1456
static char * wrap_indent_at_field(struct ui_out *uiout, const char *col_name)
Definition: breakpoint.c:5926
struct expression * cond_exp
Definition: breakpoint.h:789
#define VEC_iterate(T, V, I, P)
Definition: vec.h:165
struct cleanup * save_inferior_ptid(void)
Definition: infrun.c:7538
void tbreak_command(char *arg, int from_tty)
Definition: breakpoint.c:9914
char inserted
Definition: breakpoint.h:371
struct objfile * objfile
Definition: probe.h:218
struct tracepoint * get_tracepoint_by_number_on_target(int num)
Definition: breakpoint.c:15213
enum bptype type
Definition: tracepoint.h:165
void breakpoint_set_commands(struct breakpoint *b, struct command_line *commands)
Definition: breakpoint.c:1261
struct frame_id get_frame_id(struct frame_info *fi)
Definition: frame.c:473
static void do_cleanup_counted_command_line(void *arg)
Definition: breakpoint.c:755
static int do_captured_breakpoint_query(struct ui_out *uiout, void *data)
Definition: breakpoint.c:6608
static void default_collect_info(void)
Definition: breakpoint.c:6813
struct bp_location * next
Definition: breakpoint.h:307
static void set_breakpoint_count(int num)
Definition: breakpoint.c:671
struct probe * probe
Definition: probe.h:214
struct bp_target_info overlay_target_info
Definition: breakpoint.h:448
void breakpoint_re_set(void)
Definition: breakpoint.c:14273
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:2217
struct gdbarch * get_sal_arch(struct symtab_and_line sal)
Definition: breakpoint.c:7371
static void update_inserted_breakpoint_locations(void)
Definition: breakpoint.c:3020
struct frame_info * block_innermost_frame(const struct block *block)
Definition: blockframe.c:332
#define CATCH(EXCEPTION, MASK)
static enum print_stop_action print_it_masked_watchpoint(bpstat bs)
Definition: breakpoint.c:10790
int contained_in(const struct block *a, const struct block *b)
Definition: block.c:73
static void print_mention_catch_vfork(struct breakpoint *b)
Definition: breakpoint.c:8136
int solib_contains_address_p(const struct so_list *const solib, CORE_ADDR address)
Definition: solib.c:1167
ptid_t watchpoint_thread
Definition: breakpoint.h:814
int hardware_watchpoint_inserted_in_range(struct address_space *aspace, CORE_ADDR addr, ULONGEST len)
Definition: breakpoint.c:4323
exception_event_kind
static struct cmd_list_element * tcatch_cmdlist
Definition: breakpoint.c:15471
char * extra_string
Definition: breakpoint.h:729
static int unduplicated_should_be_inserted(struct bp_location *bl)
Definition: breakpoint.c:2219
static void tracepoint_re_set(struct breakpoint *b)
Definition: breakpoint.c:13210
#define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS)
Definition: breakpoint.c:579
static int breakpoint_hit_catch_vfork(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:8061
void ui_out_field_skip(struct ui_out *uiout, const char *fldname)
Definition: ui-out.c:528
static void create_overlay_event_breakpoint(void)
Definition: breakpoint.c:3406
struct tracepoint * create_tracepoint_from_upload(struct uploaded_tp *utp)
Definition: breakpoint.c:14976
static void incref_counted_command_line(struct counted_command_line *cmd)
Definition: breakpoint.c:728
static void validate_commands_for_breakpoint(struct breakpoint *b, struct command_line *commands)
Definition: breakpoint.c:1173
char * function_name
Definition: breakpoint.h:442
struct target_ops current_target
int detach_breakpoints(ptid_t ptid)
Definition: breakpoint.c:3847
static void breakpoint_sals_to_pc(struct symtabs_and_lines *sals)
Definition: breakpoint.c:9391
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
Definition: symtab.c:3315
#define target_watchpoint_addr_within_range(target, addr, start, length)
Definition: target.h:1936
struct cleanup * make_cleanup_ui_out_list_begin_end(struct ui_out *uiout, const char *id)
Definition: ui-out.c:459
static void save_tracepoints_command(char *args, int from_tty)
Definition: breakpoint.c:15420
int value_lazy(struct value *value)
Definition: value.c:1305
struct bp_location * bp_location_at
Definition: breakpoint.h:1089
char * cond_string
Definition: tracepoint.h:184
struct cleanup * make_cleanup_ui_out_tuple_begin_end(struct ui_out *uiout, const char *id)
Definition: ui-out.c:451
static void tracepoint_print_recreate(struct breakpoint *self, struct ui_file *fp)
Definition: breakpoint.c:13270
void remove_thread_event_breakpoints(void)
Definition: breakpoint.c:7638
static void awatch_command(char *arg, int from_tty)
Definition: breakpoint.c:11399
struct program_space * pspace
Definition: breakpoint.h:404
void init_catchpoint(struct breakpoint *b, struct gdbarch *gdbarch, int tempflag, char *cond_string, const struct breakpoint_ops *ops)
Definition: breakpoint.c:8439
static const char dprintf_style_call[]
Definition: breakpoint.c:329
struct program_space * pspace
Definition: inferior.h:317
static void check_status_catch_solib(struct bpstats *bs)
Definition: breakpoint.c:8235
#define exec_bfd
Definition: exec.h:32
static void bkpt_create_sals_from_address(char **arg, struct linespec_result *canonical, enum bptype type_wanted, char *addr_start, char **copy_arg)
Definition: breakpoint.c:12949
static void print_one_ranged_breakpoint(struct breakpoint *b, struct bp_location **last_loc)
Definition: breakpoint.c:10093
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2351
int value_bitsize(const struct value *value)
Definition: value.c:1054
struct breakpoint * iterate_over_breakpoints(int(*callback)(struct breakpoint *, void *), void *data)
Definition: breakpoint.c:15504
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
Definition: gnu-nat.c:1816
#define SYMTAB_OBJFILE(symtab)
Definition: symtab.h:970
static void bpstat_check_watchpoint(bpstat bs)
Definition: breakpoint.c:5169
static void longjmp_bkpt_dtor(struct breakpoint *self)
Definition: breakpoint.c:13140
const char * skip_spaces_const(const char *chp)
Definition: common-utils.c:271
int static_trace_marker_id_idx
Definition: breakpoint.h:884
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
Definition: cli-decode.c:159
ugll_insert_mode
Definition: breakpoint.c:235
enum gdb_signal sig
Definition: waitstatus.h:108
char print
Definition: breakpoint.h:1104
#define WP_DELETED
Definition: breakpoint.c:4989
static void print_mention_catch_exec(struct breakpoint *b)
Definition: breakpoint.c:8596
struct mem_region * lookup_mem_region(CORE_ADDR addr)
Definition: memattr.c:226
struct thread_info * any_live_thread_of_process(int pid)
Definition: thread.c:528
struct mem_attrib attrib
Definition: memattr.h:92
int stepping_past_nonsteppable_watchpoint(void)
Definition: infrun.c:1304
static int explains_signal_watchpoint(struct breakpoint *b, enum gdb_signal sig)
Definition: breakpoint.c:10728
static void decref_counted_command_line(struct counted_command_line **cmdp)
Definition: breakpoint.c:739
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
Definition: gdbarch.c:2975
static void momentary_bkpt_print_mention(struct breakpoint *b)
Definition: breakpoint.c:13129
int is_watchpoint(const struct breakpoint *bpt)
Definition: breakpoint.c:1695
void target_terminal_inferior(void)
Definition: target.c:470
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2361
static void watchpoint_value_print(struct value *val, struct ui_file *stream)
Definition: breakpoint.c:4690
char * cond_string
Definition: breakpoint.h:725
struct cmd_list_element * showlist
Definition: cli-cmds.c:143
void exception_print(struct ui_file *file, struct gdb_exception e)
Definition: exceptions.c:109
void ui_out_message(struct ui_out *uiout, int verbosity, const char *format,...)
Definition: ui-out.c:589
struct cmd_list_element * add_com_alias(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag)
Definition: cli-decode.c:882
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:2145
struct expression * parse_exp_1(const char **, CORE_ADDR pc, const struct block *, int)
Definition: parse.c:1109
struct breakpoint * clone_momentary_breakpoint(struct breakpoint *orig)
Definition: breakpoint.c:8822
struct observer * observer_attach_solib_unloaded(observer_solib_unloaded_ftype *f)
int streq(const char *lhs, const char *rhs)
Definition: utils.c:2656
static void set_breakpoint_location_function(struct bp_location *loc, int explicit_loc)
Definition: breakpoint.c:7324
static void print_one_catch_solib(struct breakpoint *b, struct bp_location **locs)
Definition: breakpoint.c:8294
const struct block * exp_valid_block
Definition: breakpoint.h:787
void insert_single_step_breakpoint(struct gdbarch *gdbarch, struct address_space *aspace, CORE_ADDR next_pc)
Definition: breakpoint.c:14816
static void tracepoint_create_breakpoints_sal(struct gdbarch *gdbarch, struct linespec_result *canonical, char *cond_string, char *extra_string, enum bptype type_wanted, enum bpdisp disposition, int thread, int task, int ignore_count, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags)
Definition: breakpoint.c:13302
struct symtabs_and_lines decode_line_1(char **argptr, int flags, struct symtab *default_symtab, int default_line)
Definition: linespec.c:2518
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:192
gdb_byte shadow_contents[BREAKPOINT_MAX]
Definition: breakpoint.h:245
static void build_target_condition_list(struct bp_location *bl)
Definition: breakpoint.c:2270
struct symbol * get_frame_function(struct frame_info *frame)
Definition: blockframe.c:118
static enum print_stop_action base_breakpoint_print_it(bpstat bs)
Definition: breakpoint.c:12688
static void watchpoint_del_at_next_stop(struct watchpoint *w)
Definition: breakpoint.c:1723
static void mark_breakpoint_location_modified(struct bp_location *loc)
Definition: breakpoint.c:814
int gdbarch_stack_frame_destroyed_p(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: gdbarch.c:3125
#define VEC_length(T, V)
Definition: vec.h:124
int valid_task_id(int)
Definition: ada-tasks.c:334
static void stopat_command(char *arg, int from_tty)
Definition: breakpoint.c:9973
static struct cleanup * make_cleanup_decref_counted_command_line(struct counted_command_line **cmdp)
Definition: breakpoint.c:764
static int msym_not_found_p(const struct minimal_symbol *msym)
Definition: breakpoint.c:3371
int frame_id_artificial_p(struct frame_id l)
Definition: frame.c:595
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:117
static const char dprintf_style_agent[]
Definition: breakpoint.c:330
static int tracepoint_locations_match(struct bp_location *loc1, struct bp_location *loc2)
Definition: breakpoint.c:7039
gdb_rc
Definition: gdb.h:27
static void tracepoint_probe_decode_linespec(struct breakpoint *b, char **s, struct symtabs_and_lines *sals)
Definition: breakpoint.c:13346
union target_waitstatus::@161 value
static void invalidate_bp_value_on_memory_change(struct inferior *inferior, CORE_ADDR addr, ssize_t len, const bfd_byte *data)
Definition: breakpoint.c:14784
enum bp_print_how print_it
Definition: breakpoint.h:1111
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
Definition: objfiles.c:368
void cmd_sfunc_ftype(char *args, int from_tty, struct cmd_list_element *c)
Definition: command.h:154
#define CATCH_PERMANENT
Definition: breakpoint.h:1246
static void tracepoints_info(char *, int)
Definition: breakpoint.c:15061
char * solib_name_from_address(struct program_space *pspace, CORE_ADDR address)
Definition: solib.c:1191
static enum print_stop_action print_it_catch_fork(bpstat bs)
Definition: breakpoint.c:7961
int gdbarch_has_global_breakpoints(struct gdbarch *gdbarch)
Definition: gdbarch.c:4363
void disable_breakpoint(struct breakpoint *bpt)
Definition: breakpoint.c:14486
static void do_enable_breakpoint(struct breakpoint *bpt, void *arg)
Definition: breakpoint.c:14643
static void print_recreate_ranged_breakpoint(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:10165
static void tracepoint_print_one_detail(const struct breakpoint *self, struct ui_out *uiout)
Definition: breakpoint.c:13226
struct inferior * find_inferior_pid(int pid)
Definition: inferior.c:354
static int gdb_evaluates_breakpoint_condition_p(void)
Definition: breakpoint.c:535
Definition: gdbtypes.h:749
void init_linespec_result(struct linespec_result *lr)
Definition: linespec.c:3772
static void free_breakpoint_probes(struct objfile *obj, void *data)
Definition: breakpoint.c:3397
#define target_supports_evaluation_of_breakpoint_conditions()
Definition: target.h:1372
const char * word
Definition: symtab.h:1448
int target_remove_mask_watchpoint(CORE_ADDR addr, CORE_ADDR mask, int rw)
Definition: target.c:3507
void iterate_over_bp_locations(walk_bp_location_callback callback)
Definition: breakpoint.c:3005
char so_name[SO_NAME_MAX_PATH_SIZE]
Definition: solist.h:52
struct thread_control_state control
Definition: gdbthread.h:198
struct breakpoint * breakpoint_find_if(int(*func)(struct breakpoint *b, void *d), void *user_data)
static int insert_masked_watchpoint(struct bp_location *bl)
Definition: breakpoint.c:10746
char * default_collect
void add_solib_catchpoint(char *arg, int is_load, int is_temp, int enabled)
Definition: breakpoint.c:8366
void decode_line_full(char **argptr, int flags, struct symtab *default_symtab, int default_line, struct linespec_result *canonical, const char *select_mode, const char *filter)
Definition: linespec.c:2441
char * extract_arg(char **arg)
Definition: cli-utils.c:264
#define VEC_index(T, V, I)
Definition: vec.h:151
static void do_map_enable_once_breakpoint(struct breakpoint *bpt, void *ignore)
Definition: breakpoint.c:14721
#define target_disable_tracepoint(loc)
Definition: target.h:2090
void(* decode_linespec)(struct breakpoint *, char **, struct symtabs_and_lines *)
Definition: breakpoint.h:605
void start_rbreak_breakpoints(void)
Definition: breakpoint.c:686
static void dtor_catch_solib(struct breakpoint *b)
Definition: breakpoint.c:8176
struct objfile * objfile
Definition: symtab.h:1385
static const char condition_evaluation_both[]
Definition: breakpoint.c:484
int interpreter_async
Definition: interps.c:46
static void print_one_detail_ranged_breakpoint(const struct breakpoint *b, struct ui_out *uiout)
Definition: breakpoint.c:10118
#define ALL_BREAKPOINTS(B)
Definition: breakpoint.c:557
static struct symtab_and_line update_static_tracepoint(struct breakpoint *b, struct symtab_and_line sal)
Definition: breakpoint.c:13811
static struct symtabs_and_lines decode_static_tracepoint_spec(char **arg_p)
Definition: breakpoint.c:9529
struct gdbarch * get_type_arch(const struct type *type)
Definition: gdbtypes.c:232
void add_setshow_string_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:585
#define ALL_TRACEPOINTS(B)
Definition: breakpoint.c:589
struct cleanup * make_cleanup_destroy_linespec_result(struct linespec_result *ls)
Definition: linespec.c:3805
struct cmd_list_element * add_info(const char *name, cmd_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:857
Definition: gnu-nat.c:163
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:781
int pass_count
Definition: breakpoint.h:866
static const char * type
Definition: language.c:103
void error_stream(struct ui_file *stream)
Definition: utils.c:528
#define gdb_assert(expr)
Definition: gdb_assert.h:33
struct agent_expr * gen_printf(CORE_ADDR scope, struct gdbarch *gdbarch, CORE_ADDR function, LONGEST channel, const char *format, int fmtlen, struct format_piece *frags, int nargs, struct expression **exprs)
Definition: ax-gdb.c:2533
struct expression * exp
Definition: breakpoint.h:784
int number_on_target
Definition: breakpoint.h:869
struct breakpoint * get_breakpoint(int num)
Definition: breakpoint.c:774
struct cleanup * prevent_dont_repeat(void)
Definition: top.c:598
void exception_fprintf(struct ui_file *file, struct gdb_exception e, const char *prefix,...)
Definition: exceptions.c:119
const struct bp_location_ops * ops
Definition: breakpoint.h:310
#define min(a, b)
Definition: defs.h:106
#define target_static_tracepoint_markers_by_strid(marker_id)
Definition: target.h:2155
#define target_download_tracepoint(t)
Definition: target.h:2078
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:75
const char * linespec_lexer_lex_keyword(const char *p)
Definition: linespec.c:420
static void do_map_enable_breakpoint(struct breakpoint *b, void *ignore)
Definition: breakpoint.c:14652
static struct breakpoint_ops watchpoint_breakpoint_ops
Definition: breakpoint.c:10740
#define WP_VALUE_NOT_CHANGED
Definition: breakpoint.c:4993
static int bp_loc_is_permanent(struct bp_location *loc)
Definition: breakpoint.c:8961
int nquery(const char *ctlstr,...)
Definition: utils.c:1329
struct cmd_list_element * stoplist
Definition: cli-cmds.c:119
int bpstat_num(bpstat *bsp, int *num)
Definition: breakpoint.c:4486
struct cmd_list_element * add_alias_cmd(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition: cli-decode.c:286
static struct breakpoint_ops catch_solib_breakpoint_ops
Definition: breakpoint.c:8356
void disable_breakpoints_in_shlibs(void)
Definition: breakpoint.c:7748
static struct breakpoint_ops momentary_breakpoint_ops
Definition: breakpoint.c:306
static void base_breakpoint_dtor(struct breakpoint *self)
Definition: breakpoint.c:12613
struct value * value_next(struct value *value)
Definition: value.c:1015
static struct cleanup * prepare_re_set_context(struct breakpoint *b)
Definition: breakpoint.c:14241
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1707
int ada_get_task_number(ptid_t)
Definition: ada-tasks.c:292
char * addr_string
Definition: linespec.h:76
#define target_has_execution
Definition: target.h:1726
struct agent_expr * gen_eval_for_expr(CORE_ADDR scope, struct expression *expr)
Definition: ax-gdb.c:2474
CORE_ADDR stack_addr
Definition: frame.h:120
static void parse_breakpoint_sals(char **address, struct linespec_result *canonical)
Definition: breakpoint.c:9316
int(* explains_signal)(struct breakpoint *, enum gdb_signal)
Definition: breakpoint.h:610
enum watchpoint_triggered watchpoint_triggered
Definition: breakpoint.h:818
char * xstrprintf(const char *format,...)
Definition: common-utils.c:107
static enum print_stop_action print_it_catch_exec(bpstat bs)
Definition: breakpoint.c:8543
int deprecated_value_modifiable(struct value *value)
Definition: value.c:1490
#define BP_HARDWAREFLAG
Definition: breakpoint.c:4998
void printf_unfiltered(const char *format,...)
Definition: utils.c:2399
int section_is_mapped(struct obj_section *osect)
Definition: symfile.c:3129
CORE_ADDR placed_address
Definition: breakpoint.h:232
void print_command_lines(struct ui_out *uiout, struct command_line *cmd, unsigned int depth)
Definition: cli-script.c:156
static const char dprintf_style_gdb[]
Definition: breakpoint.c:328
int get_last_displayed_line(void)
Definition: stack.c:1020
struct frame_id frame_unwind_caller_id(struct frame_info *next_frame)
Definition: frame.c:489
int pre_expanded
Definition: linespec.h:72
int find_pc_partial_function_gnu_ifunc(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, int *is_gnu_ifunc_p)
Definition: blockframe.c:191
static void print_solib_event(int is_catchpoint)
Definition: breakpoint.c:4748
Definition: symtab.h:925
static struct breakpoint * create_internal_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address, enum bptype type, const struct breakpoint_ops *ops)
Definition: breakpoint.c:3309
struct breakpoint * breakpoint_chain
Definition: breakpoint.c:595
static int bp_location_compare_addrs(const void *ap, const void *bp)
Definition: breakpoint.c:914
int software_breakpoint_inserted_here_p(struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:4279
static int bp_location_compare(const void *ap, const void *bp)
Definition: breakpoint.c:11939
static void condition_command(char *, int)
Definition: breakpoint.c:1081
static enum print_stop_action print_it_catch_vfork(bpstat bs)
Definition: breakpoint.c:8078
struct breakpoint_ops bkpt_breakpoint_ops
Definition: breakpoint.c:313
struct program_space * pspace
Definition: solist.h:55
static void internal_bkpt_check_status(bpstat bs)
Definition: breakpoint.c:13014
void * xmalloc(YYSIZE_T)
static int bkpt_probe_insert_location(struct bp_location *bl)
Definition: breakpoint.c:13153
struct symtab * symtab
Definition: symtab.h:1369
CORE_ADDR requested_address
Definition: breakpoint.h:431
void skip_prologue_sal(struct symtab_and_line *sal)
Definition: symtab.c:3694
static int is_hardware_watchpoint(const struct breakpoint *bpt)
Definition: breakpoint.c:1684
static void ftrace_command(char *arg, int from_tty)
Definition: breakpoint.c:14909
struct ui_file * gdb_stdlog
Definition: main.c:73
static int breakpoint_hit_catch_solib(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:8200
CORE_ADDR gdbarch_adjust_breakpoint_address(struct gdbarch *gdbarch, CORE_ADDR bpaddr)
Definition: gdbarch.c:2703
Definition: probe.h:185
static int base_breakpoint_works_in_software_mode(const struct breakpoint *b)
Definition: breakpoint.c:12673
struct ui_file * mem_fileopen(void)
Definition: ui-file.c:427
cmd_sfunc_ftype * sfunc
Definition: cli-decode.h:120
struct command_line * copy_command_lines(struct command_line *cmds)
Definition: cli-script.c:1411
bpstat_what_main_action
Definition: breakpoint.h:924
int breakpoint_ext_lang_cond_says_stop(struct breakpoint *b)
Definition: extension.c:634
static int bpstat_check_location(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:5153
static void swap_insertion(struct bp_location *left, struct bp_location *right)
Definition: breakpoint.c:12057
static void check_no_tracepoint_commands(struct command_line *commands)
Definition: breakpoint.c:1126
unsigned char display_canonical
Definition: breakpoint.h:684
static void enable_once_command(char *, int)
Definition: breakpoint.c:14729
bptype
Definition: breakpoint.h:51
void(* check_status)(struct bpstats *bs)
Definition: breakpoint.h:536
bp_loc_type
Definition: breakpoint.h:284
static void disable_trace_command(char *, int)
Definition: breakpoint.c:15090
struct breakpoint * set_momentary_breakpoint(struct gdbarch *gdbarch, struct symtab_and_line sal, struct frame_id frame_id, enum bptype type)
Definition: breakpoint.c:8756
int ui_out_query_field(struct ui_out *uiout, int colno, int *width, int *alignment, char **col_name)
Definition: ui-out.c:1073
static void watch_command_1(const char *arg, int accessflag, int from_tty, int just_location, int internal)
Definition: breakpoint.c:10934
static void strace_marker_create_breakpoints_sal(struct gdbarch *gdbarch, struct linespec_result *canonical, char *cond_string, char *extra_string, enum bptype type_wanted, enum bpdisp disposition, int thread, int task, int ignore_count, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags)
Definition: breakpoint.c:13453
struct cmd_list_element * add_abbrev_prefix_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:366
static int can_use_hw_watchpoints
Definition: breakpoint.c:396
void observer_notify_breakpoint_deleted(struct breakpoint *b)
static int remove_catch_vfork(struct bp_location *bl)
Definition: breakpoint.c:8052
static int watchpoint_exp_is_const(const struct expression *exp)
Definition: breakpoint.c:10330
static void print_one_breakpoint(struct breakpoint *b, struct bp_location **last_loc, int allflag)
Definition: breakpoint.c:6537
static void bkpt_print_recreate(struct breakpoint *tp, struct ui_file *fp)
Definition: breakpoint.c:12929
Definition: block.h:60
#define VEC_empty(T, V)
Definition: vec.h:132
struct value * next
Definition: value.c:319
struct symtab * get_last_displayed_symtab(void)
Definition: stack.c:1010
static const char * translate_condition_evaluation_mode(const char *mode)
Definition: breakpoint.c:510
Definition: value.c:172
void breakpoint_xfer_memory(gdb_byte *readbuf, gdb_byte *writebuf, const gdb_byte *writebuf_org, ULONGEST memaddr, LONGEST len)
Definition: breakpoint.c:1581
int stop_on_solib_events
Definition: infrun.c:332
void annotate_breakpoints_headers(void)
Definition: annotate.c:181
static int resources_needed_masked_watchpoint(const struct bp_location *bl)
Definition: breakpoint.c:10770
void disable_watchpoints_before_interactive_call_start(void)
Definition: breakpoint.c:8686
int val_valid
Definition: breakpoint.h:799
int find_line_pc(struct symtab *symtab, int line, CORE_ADDR *pc)
Definition: symtab.c:3484
enum bptype type
Definition: breakpoint.h:669
static void mark_breakpoint_modified(struct breakpoint *b)
Definition: breakpoint.c:791
int ptid_get_pid(ptid_t ptid)
Definition: ptid.c:52
struct value * parse_to_comma_and_eval(const char **expp)
Definition: eval.c:141
struct cmd_list_element * disablelist
Definition: cli-cmds.c:115
static void create_longjmp_master_breakpoint(void)
Definition: breakpoint.c:3457
void print_recreate_thread(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:15272
static void show_pending_break_support(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: breakpoint.c:415
static void create_std_terminate_master_breakpoint(void)
Definition: breakpoint.c:3570
struct breakpoint * breakpoint_at
Definition: breakpoint.h:1095
static int breakpoint_has_pc(struct breakpoint *b, struct program_space *pspace, CORE_ADDR pc, struct obj_section *section)
Definition: breakpoint.c:6862
static int remove_catch_solib(struct bp_location *ignore)
Definition: breakpoint.c:8194
bpstat bpstat_copy(bpstat bs)
Definition: breakpoint.c:4402
static int insert_watchpoint(struct bp_location *bl)
Definition: breakpoint.c:10492
static void base_breakpoint_check_status(bpstat bs)
Definition: breakpoint.c:12664
struct tracepoint * get_tracepoint_by_number(char **arg, struct get_number_or_range_state *state)
Definition: breakpoint.c:15234
void(* create_sals_from_address)(char **, struct linespec_result *, enum bptype, char *, char **)
Definition: breakpoint.h:583
print_stop_action
Definition: breakpoint.h:476
static int breakpoint_hit_catch_fork(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:7944
CORE_ADDR get_probe_address(struct probe *probe, struct objfile *objfile)
Definition: probe.c:793
static int insert_catch_solib(struct bp_location *ignore)
Definition: breakpoint.c:8188
static void catch_command(char *, int)
Definition: breakpoint.c:11701
static void breakpoint_adjustment_warning(CORE_ADDR, CORE_ADDR, int, int)
Definition: breakpoint.c:7082
void throw_exception(struct gdb_exception exception)
struct symbol * fixup_symbol_section(struct symbol *sym, struct objfile *objfile)
Definition: symtab.c:1809
int catch_exceptions_with_msg(struct ui_out *func_uiout, catch_exceptions_ftype *func, void *func_args, char **gdberrmsg, return_mask mask)
Definition: exceptions.c:171
struct command_line * next
Definition: defs.h:399
static unsigned bp_location_count
Definition: breakpoint.c:603
char * execd_pathname
Definition: waitstatus.h:112
const char const char int
Definition: command.h:229
bfd_byte gdb_byte
Definition: common-types.h:38
#define WP_IGNORE
Definition: breakpoint.c:4995
void fetch_subexp_value(struct expression *exp, int *pc, struct value **valp, struct value **resultp, struct value **val_chain, int preserve_errors)
Definition: eval.c:210
enum command_control_type control_type
Definition: defs.h:401
int find_line_pc_range(struct symtab_and_line sal, CORE_ADDR *startptr, CORE_ADDR *endptr)
Definition: symtab.c:3511
static int bpstat_remove_breakpoint_callback(struct thread_info *th, void *data)
Definition: breakpoint.c:12532
static int locations_are_equal(struct bp_location *a, struct bp_location *b)
Definition: breakpoint.c:13911
static void enable_command(char *, int)
Definition: breakpoint.c:14662
int print_address_symbolic(struct gdbarch *, CORE_ADDR, struct ui_file *, int, char *)
Definition: printcmd.c:556
static void set_tracepoint_count(int num)
Definition: breakpoint.c:14878
#define MSYMBOL_TYPE(msymbol)
Definition: symtab.h:382
char * canonical
Definition: linespec.h:46
const struct extension_language_defn * get_breakpoint_cond_ext_lang(struct breakpoint *b, enum extension_language skip_lang)
Definition: extension.c:613
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
Definition: cli-decode.c:1023
static void strace_marker_decode_linespec(struct breakpoint *b, char **s, struct symtabs_and_lines *sals)
Definition: breakpoint.c:13512
void discard_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:213
int non_stop
Definition: infrun.c:180
int target_insert_breakpoint(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: target.c:2044
const struct language_defn * current_language
Definition: language.c:85
ptid_t null_ptid
Definition: ptid.c:25
int create_breakpoint(struct gdbarch *gdbarch, char *arg, char *cond_string, int thread, char *extra_string, int parse_arg, int tempflag, enum bptype type_wanted, int ignore_count, enum auto_boolean pending_break_support, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags)
Definition: breakpoint.c:9585
int last_displayed_sal_is_valid(void)
Definition: stack.c:982
#define TYPE_TARGET_TYPE(thistype)
Definition: gdbtypes.h:1229
char * static_trace_marker_id
Definition: breakpoint.h:876
enum bp_loc_type loc_type
Definition: breakpoint.h:316
enable_state
Definition: breakpoint.h:182
CORE_ADDR overlay_unmapped_address(CORE_ADDR pc, struct obj_section *section)
Definition: symfile.c:3219
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
Definition: minsyms.c:801
static void incref_bp_location(struct bp_location *loc)
Definition: breakpoint.c:7236
Definition: gdb.h:41
#define max(a, b)
Definition: defs.h:109
static void update_dprintf_command_list(struct breakpoint *b)
Definition: breakpoint.c:8989
static void tcatch_command(char *arg, int from_tty)
Definition: breakpoint.c:11708
void break_command(char *arg, int from_tty)
Definition: breakpoint.c:9908
bpstat bpstat_find_breakpoint(bpstat bsp, struct breakpoint *breakpoint)
Definition: breakpoint.c:4437
static void print_recreate_catch_vfork(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:8145
#define ALL_PSPACES(pspace)
Definition: progspace.h:232
const char * ext_lang_capitalized_name(const struct extension_language_defn *extlang)
Definition: extension.c:234
void install_breakpoint(int internal, struct breakpoint *b, int update_gll)
Definition: breakpoint.c:8456
void operator_length(const struct expression *expr, int endpos, int *oplenp, int *argsp)
Definition: parse.c:849
static int insert_catch_vfork(struct bp_location *bl)
Definition: breakpoint.c:8043
static void commands_command_1(char *arg, int from_tty, struct command_line *control)
Definition: breakpoint.c:1389
#define target_can_download_tracepoint()
Definition: target.h:2081
static int base_breakpoint_resources_needed(const struct bp_location *bl)
Definition: breakpoint.c:12682
static void update_global_location_list(enum ugll_insert_mode)
Definition: breakpoint.c:12141
struct cleanup * make_bpstat_clear_actions_cleanup(void)
Definition: utils.c:3137
void proceed(CORE_ADDR addr, enum gdb_signal siggnal)
Definition: infrun.c:2592
struct cleanup * make_cleanup_ui_file_delete(struct ui_file *arg)
Definition: utils.c:237
int executing_startup
Definition: progspace.h:176
void remove_solib_event_breakpoints_at_next_stop(void)
Definition: breakpoint.c:7694
const char * async_reason_lookup(enum async_reply_reason reason)
Definition: mi-common.c:49
struct address_space * aspace
Definition: frame.c:93
static CORE_ADDR bp_location_placed_address_before_address_max
Definition: breakpoint.c:611
ptid_t ptid
Definition: gdbthread.h:169
ULONGEST traceframe_usage
Definition: breakpoint.h:873
static int watchpoint_check(void *)
Definition: breakpoint.c:5007
static void say_where(struct breakpoint *b)
Definition: breakpoint.c:12544
int xsnprintf(char *str, size_t size, const char *format,...)
Definition: common-utils.c:134
#define SYMBOL_BLOCK_VALUE(symbol)
Definition: symtab.h:185
struct breakpoint * set_longjmp_breakpoint_for_call_dummy(void)
Definition: breakpoint.c:7500
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1240
void clear_proceed_status(int step)
Definition: infrun.c:2463
static int bkpt_breakpoint_hit(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:12819
enum target_waitkind kind
Definition: waitstatus.h:100
#define target_insert_exec_catchpoint(pid)
Definition: target.h:1575
static void describe_other_breakpoints(struct gdbarch *, struct program_space *, CORE_ADDR, struct obj_section *, int)
Definition: breakpoint.c:6883
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1393
static void do_delete_breakpoint_cleanup(void *b)
Definition: breakpoint.c:13632
static void show_condition_evaluation_mode(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: breakpoint.c:895
unsigned char silent
Definition: breakpoint.h:682
const gdb_byte * gdbarch_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
Definition: gdbarch.c:2662
static int base_breakpoint_remove_location(struct bp_location *bl)
Definition: breakpoint.c:12649
CORE_ADDR related_address
Definition: breakpoint.h:436
struct ui_file * gdb_stderr
Definition: main.c:72
void breakpoint_init_inferior(enum inf_context context)
Definition: breakpoint.c:4080
#define target_region_ok_for_hw_watchpoint(addr, len)
Definition: target.h:1877
ptid_t inferior_ptid
Definition: infcmd.c:124
static int breakpoint_re_set_one(void *)
Definition: breakpoint.c:14259
char * cond
Definition: tracepoint.h:173
int val_bitpos
Definition: breakpoint.h:803
struct minimal_symbol * minsym
Definition: minsyms.h:32
Definition: memattr.h:28
static void watch_command(char *arg, int from_tty)
Definition: breakpoint.c:11375
char * safe_strerror(int)
void set_internalvar_integer(struct internalvar *var, LONGEST l)
Definition: value.c:2347
static void trace_pass_set_count(struct tracepoint *tp, int count, int from_tty)
Definition: breakpoint.c:15134
void watch_command_wrapper(char *arg, int from_tty, int internal)
Definition: breakpoint.c:11350
void update_breakpoint_locations(struct breakpoint *b, struct symtabs_and_lines sals, struct symtabs_and_lines sals_end)
Definition: breakpoint.c:13939
static void disable_breakpoints_in_freed_objfile(struct objfile *objfile)
Definition: breakpoint.c:7835
struct bp_location * loc
Definition: breakpoint.h:678
void delete_command(char *arg, int from_tty)
Definition: breakpoint.c:13696
int remove_breakpoints(void)
Definition: breakpoint.c:3184
static void tracepoint_create_sals_from_address(char **arg, struct linespec_result *canonical, enum bptype type_wanted, char *addr_start, char **copy_arg)
Definition: breakpoint.c:13292
struct program_space * pspace
Definition: symtab.h:1367
#define gnu_ifunc_resolve_name
Definition: symtab.h:1355
static void ATTRIBUTE_NORETURN invalid_thread_id_error(int id)
Definition: breakpoint.c:9441
void get_user_print_options(struct value_print_options *opts)
Definition: valprint.c:129
void clear_breakpoint_hit_counts(void)
Definition: breakpoint.c:703
static int hw_watchpoint_use_count(struct breakpoint *)
Definition: breakpoint.c:8638
static void catch_load_or_unload(char *arg, int from_tty, int is_load, struct cmd_list_element *command)
Definition: breakpoint.c:8408
struct breakpoint base
Definition: breakpoint.c:8495
int(* remove_location)(struct bp_location *)
Definition: breakpoint.h:521
static void do_map_enable_delete_breakpoint(struct breakpoint *bpt, void *ignore)
Definition: breakpoint.c:14756
static int can_use_hardware_watchpoint(struct value *)
Definition: breakpoint.c:11269
static struct breakpoint * create_solib_event_breakpoint_1(struct gdbarch *gdbarch, CORE_ADDR address, enum ugll_insert_mode insert_mode)
Definition: breakpoint.c:7709
struct objfile * objfile
Definition: objfiles.h:124
static int resources_needed_watchpoint(const struct bp_location *bl)
Definition: breakpoint.c:10546
static const char * bptype_string(enum bptype type)
Definition: breakpoint.c:6078
int bpstat_explains_signal(bpstat bsp, enum gdb_signal sig)
Definition: breakpoint.c:4453
#define target_insert_hw_breakpoint(gdbarch, bp_tgt)
Definition: target.h:1915
int user_breakpoint_p(struct breakpoint *b)
Definition: breakpoint.c:6645
#define VEC_free(T, V)
Definition: vec.h:180
#define qsort
Definition: ada-exp.c:2747
static void disable_breakpoints_in_unloaded_shlib(struct so_list *solib)
Definition: breakpoint.c:7781
char * addr_string
Definition: breakpoint.h:706
struct frame_id initiating_frame
Definition: gdbthread.h:267
void set_std_terminate_breakpoint(void)
Definition: breakpoint.c:7595
void ui_out_table_header(struct ui_out *uiout, int width, enum ui_align alignment, const char *col_name, const char *colhdr)
Definition: ui-out.c:346
static void decode_linespec_default(struct breakpoint *, char **, struct symtabs_and_lines *)
Definition: breakpoint.c:14210
static struct breakpoint_objfile_data * get_breakpoint_objfile_data(struct objfile *objfile)
Definition: breakpoint.c:3380
static void watchpoints_info(char *, int)
Definition: breakpoint.c:6839
static void base_breakpoint_decode_linespec(struct breakpoint *b, char **s, struct symtabs_and_lines *sals)
Definition: breakpoint.c:12739
int line
Definition: symtab.h:1570
int gdbarch_adjust_breakpoint_address_p(struct gdbarch *gdbarch)
Definition: gdbarch.c:2696
CORE_ADDR pc
Definition: symtab.h:1376
#define VEC_address(T, V)
Definition: vec.h:369
static void internal_bkpt_print_mention(struct breakpoint *b)
Definition: breakpoint.c:13078
int enable_count
Definition: breakpoint.h:691
VEC(bp_location_p)
Definition: breakpoint.c:624
static const char condition_evaluation_auto[]
Definition: breakpoint.c:487
void(* print_one_detail)(const struct breakpoint *, struct ui_out *)
Definition: breakpoint.h:568
struct breakpoint_ops base_breakpoint_ops
Definition: breakpoint.c:12761
static void print_recreate_catch_exec(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:8605
enum language lang
Definition: breakpoint.c:7650
ULONGEST addr
Definition: tracepoint.h:166
struct breakpoint * single_step_breakpoints
Definition: gdbthread.h:61
char permanent
Definition: breakpoint.h:378
static void base_breakpoint_after_condition_true(struct bpstats *bs)
Definition: breakpoint.c:12756
struct probe * probe
Definition: symtab.h:1382
static void force_breakpoint_reinsertion(struct bp_location *bl)
Definition: breakpoint.c:12086
#define target_can_accel_watchpoint_condition(addr, len, type, cond)
Definition: target.h:1949
void disable_overlay_breakpoints(void)
Definition: breakpoint.c:7579
static enum print_stop_action print_it_watchpoint(bpstat bs)
Definition: breakpoint.c:10565
static void print_one_detail_masked_watchpoint(const struct breakpoint *b, struct ui_out *uiout)
Definition: breakpoint.c:10840
int special_display
Definition: linespec.h:66
void breakpoint_set_silent(struct breakpoint *b, int silent)
Definition: breakpoint.c:1276
static int insert_catch_fork(struct bp_location *bl)
Definition: breakpoint.c:7926
struct command_line * commands
Definition: breakpoint.c:368
static int rbreak_start_breakpoint_count
Definition: breakpoint.c:680
static void strace_marker_create_sals_from_address(char **arg, struct linespec_result *canonical, enum bptype type_wanted, char *addr_start, char **copy_arg)
Definition: breakpoint.c:13436
struct breakpoint * related_breakpoint
Definition: breakpoint.h:736
struct cmd_list_element * save_cmdlist
struct agent_expr * cmd_bytecode
Definition: breakpoint.h:355
int target_ranged_break_num_registers(void)
Definition: target.c:3527
enum gdb_rc gdb_breakpoint_query(struct ui_out *uiout, int bnum, char **error_message)
Definition: breakpoint.c:6626
char * ep_parse_optional_if_clause(char **arg)
Definition: breakpoint.c:11552
static void breakpoint_about_to_proceed(void)
Definition: breakpoint.c:4535
struct inferior * current_inferior(void)
Definition: inferior.c:57
struct cmd_list_element * add_info_alias(const char *name, const char *oldname, int abbrev_flag)
Definition: cli-decode.c:865
const char * print_core_address(struct gdbarch *gdbarch, CORE_ADDR address)
Definition: utils.c:2764
int is_exited(ptid_t ptid)
Definition: thread.c:828
int memory_validate_breakpoint(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: mem-break.c:102
int explicit_line
Definition: symtab.h:1379
int breakpoints_should_be_inserted_now(void)
Definition: breakpoint.c:460
auto_boolean
Definition: defs.h:196
void(* after_condition_true)(struct bpstats *bs)
Definition: breakpoint.h:614
enum overlay_debugging_state overlay_debugging
Definition: symfile.c:3081
char shlib_disabled
Definition: breakpoint.h:365
const struct probe_ops * pops
Definition: probe.h:188
static void catch_fork_command_1(char *arg, int from_tty, struct cmd_list_element *command)
Definition: breakpoint.c:11585
static void bkpt_re_set(struct breakpoint *b)
Definition: breakpoint.c:12787
struct program_space * current_program_space
Definition: progspace.c:35
static const char * bp_condition_evaluator(struct breakpoint *b)
Definition: breakpoint.c:5959
struct symtabs_and_lines decode_line_with_current_source(char *string, int flags)
Definition: linespec.c:2543
int ui_out_redirect(struct ui_out *uiout, struct ui_file *outstream)
Definition: ui-out.c:612
void ui_out_field_core_addr(struct ui_out *uiout, const char *fldname, struct gdbarch *gdbarch, CORE_ADDR address)
Definition: ui-out.c:499
void breakpoint_set_thread(struct breakpoint *b, int thread)
Definition: breakpoint.c:1289
static struct value * extract_bitfield_from_watchpoint_value(struct watchpoint *w, struct value *val)
Definition: breakpoint.c:1742
static void tracepoint_probe_create_sals_from_address(char **arg, struct linespec_result *canonical, enum bptype type_wanted, char *addr_start, char **copy_arg)
Definition: breakpoint.c:13335
struct value * parse_and_eval(const char *exp)
Definition: eval.c:124
static int executing_breakpoint_commands
Definition: breakpoint.c:545
static void do_map_commands_command(struct breakpoint *b, void *data)
Definition: breakpoint.c:1343
unsigned long long ULONGEST
Definition: common-types.h:53
void end_rbreak_breakpoints(void)
Definition: breakpoint.c:695
#define target_can_use_hardware_watchpoint(TYPE, CNT, OTHERTYPE)
Definition: target.h:1870
static void commands_command(char *, int)
Definition: breakpoint.c:1436
static enum print_stop_action print_it_catch_solib(bpstat bs)
Definition: breakpoint.c:8275
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: corelow.c:917
static int tracepoint_breakpoint_hit(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:13216
struct cleanup * save_current_program_space(void)
Definition: progspace.c:228
static const char * condition_evaluation_mode_1
Definition: breakpoint.c:498
language
Definition: defs.h:167
void release_value(struct value *val)
Definition: value.c:1603
void initialize_breakpoint_ops(void)
Definition: breakpoint.c:15571
char * savestring(const char *ptr, size_t len)
Definition: common-utils.c:148
static void maintenance_info_breakpoints(char *, int)
Definition: breakpoint.c:6854
#define target_remove_vfork_catchpoint(pid)
Definition: target.h:1557
int pid_to_thread_id(ptid_t ptid)
Definition: thread.c:459
int condition_not_parsed
Definition: breakpoint.h:755
int ignore_count
Definition: breakpoint.h:687
static void bkpt_print_mention(struct breakpoint *b)
Definition: breakpoint.c:12900
static struct breakpoint_ops strace_marker_breakpoint_ops
Definition: breakpoint.c:13527
void annotate_breakpoints_table_end(void)
Definition: annotate.c:209
#define target_remove_exec_catchpoint(pid)
Definition: target.h:1578
#define VEC_cleanup(T)
Definition: vec.h:187
void(* dtor)(struct breakpoint *self)
Definition: breakpoint.h:502
inf_context
Definition: breakpoint.h:1114
struct cleanup * save_current_space_and_thread(void)
Definition: progspace.c:448
void update_breakpoints_after_exec(void)
Definition: breakpoint.c:3725
static void breakpoints_info(char *, int)
Definition: breakpoint.c:6831
char stop
Definition: breakpoint.h:1107
struct type * value_type(const struct value *value)
Definition: value.c:1021
int watchpoints_triggered(struct target_waitstatus *ws)
Definition: breakpoint.c:4912
static enum print_stop_action print_it_ranged_breakpoint(bpstat bs)
Definition: breakpoint.c:10061
void annotate_breakpoint(int num)
Definition: annotate.c:91
static void one_breakpoint_xfer_memory(gdb_byte *readbuf, gdb_byte *writebuf, const gdb_byte *writebuf_org, ULONGEST memaddr, LONGEST len, struct bp_target_info *target_info, struct gdbarch *gdbarch)
Definition: breakpoint.c:1477
static void delete_trace_command(char *, int)
Definition: breakpoint.c:15097
int target_insert_mask_watchpoint(CORE_ADDR addr, CORE_ADDR mask, int rw)
Definition: target.c:3497
int server_command
Definition: top.c:140
static void enable_breakpoint_disp(struct breakpoint *, enum bpdisp, int count)
Definition: breakpoint.c:14573
unsigned int debug_infrun
Definition: infrun.c:140
static void init_breakpoint_sal(struct breakpoint *b, struct gdbarch *gdbarch, struct symtabs_and_lines sals, char *addr_string, char *filter, char *cond_string, char *extra_string, enum bptype type, enum bpdisp disposition, int thread, int task, int ignore_count, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags, int display_canonical)
Definition: breakpoint.c:9076
Definition: symtab.h:703
void bpstat_do_actions(void)
Definition: breakpoint.c:4668
struct breakpoint base
Definition: breakpoint.c:8164
struct bp_target_info target_info
Definition: breakpoint.h:445
static const char condition_evaluation_host[]
Definition: breakpoint.c:488
CORE_ADDR value_as_address(struct value *val)
Definition: value.c:2679
#define NUM_LONGJMP_NAMES
Definition: breakpoint.c:3333
static struct bp_location ** get_first_locp_gte_addr(CORE_ADDR address)
Definition: breakpoint.c:931
void ui_out_field_string(struct ui_out *uiout, const char *fldname, const char *string)
Definition: ui-out.c:541
void target_terminal_ours_for_output(void)
Definition: target.c:503
static bpstat bpstat_alloc(struct bp_location *bl, bpstat **bs_link_pointer)
Definition: breakpoint.c:4890
static int bkpt_remove_location(struct bp_location *bl)
Definition: breakpoint.c:12810
int pc_at_non_inline_function(struct address_space *aspace, CORE_ADDR pc, const struct target_waitstatus *ws)
Definition: breakpoint.c:15536
unsigned short flags
Definition: objfiles.h:282
struct symtab_and_line * sals
Definition: symtab.h:1392
#define gnu_ifunc_resolver_return_stop
Definition: symtab.h:1357
static struct minimal_symbol msym_not_found
Definition: breakpoint.c:3366
char * addr_string_range_end
Definition: breakpoint.h:715
static void mention(struct breakpoint *)
Definition: breakpoint.c:8849
static int insert_bp_location(struct bp_location *bl, struct ui_file *tmp_error_stream, int *disabled_breaks, int *hw_breakpoint_error, int *hw_bp_error_explained_already)
Definition: breakpoint.c:2581
void annotate_catchpoint(int num)
Definition: annotate.c:98
void delete_std_terminate_breakpoint(void)
Definition: breakpoint.c:7610
CORE_ADDR address
Definition: breakpoint.h:410
int val_bitsize
Definition: breakpoint.h:804
void breakpoint_retire_moribund(void)
Definition: breakpoint.c:12486
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1237
static int is_tracepoint_type(enum bptype type)
Definition: breakpoint.c:1155
ptid_t forked_inferior_pid
Definition: breakpoint.c:7919
static void break_range_command(char *arg, int from_tty)
Definition: breakpoint.c:10209
void ui_out_table_body(struct ui_out *uiout)
Definition: ui-out.c:309
struct objfile * objfile
Definition: minsyms.h:37
void switch_to_program_space_and_thread(struct program_space *pspace)
Definition: progspace.c:465
static struct breakpoint * new_single_step_breakpoint(int thread, struct gdbarch *gdbarch)
Definition: breakpoint.c:8733
#define target_remove_hw_breakpoint(gdbarch, bp_tgt)
Definition: target.h:1919
void * arg
Definition: cleanups.c:43
void dont_repeat(void)
Definition: top.c:582
static int base_breakpoint_breakpoint_hit(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:12655
static void dprintf_after_condition_true(struct bpstats *bs)
Definition: breakpoint.c:13404
int remove_breakpoints_pid(int pid)
Definition: breakpoint.c:3224
void remove_jit_event_breakpoints(void)
Definition: breakpoint.c:7670
static struct breakpoint_ops masked_watchpoint_breakpoint_ops
Definition: breakpoint.c:10920
static void tracepoint_print_mention(struct breakpoint *b)
Definition: breakpoint.c:13242
static void save_command(char *arg, int from_tty)
Definition: breakpoint.c:15496
unsigned char is_load
Definition: breakpoint.c:8167
struct ui_out * current_uiout
Definition: ui-out.c:233
struct address_space * placed_address_space
Definition: breakpoint.h:225
int value_true(struct value *val)
Definition: language.c:404
#define QUIT
Definition: defs.h:160
void resolve_sal_pc(struct symtab_and_line *sal)
Definition: breakpoint.c:9851
static int hw_watchpoint_used_count_others(struct breakpoint *except, enum bptype type, int *other_type_used)
Definition: breakpoint.c:8662
int is_running(ptid_t ptid)
Definition: thread.c:834
static void bkpt_create_breakpoints_sal(struct gdbarch *gdbarch, struct linespec_result *canonical, char *cond_string, char *extra_string, enum bptype type_wanted, enum bpdisp disposition, int thread, int task, int ignore_count, const struct breakpoint_ops *ops, int from_tty, int enabled, int internal, unsigned flags)
Definition: breakpoint.c:12959
static struct breakpoint_ops catch_fork_breakpoint_ops
Definition: breakpoint.c:8037
static char * wrap_indent
Definition: utils.c:1637
enum enable_state enable_state
Definition: breakpoint.h:671
#define WP_VALUE_CHANGED
Definition: breakpoint.c:4991
static int is_non_inline_function(struct breakpoint *b)
Definition: breakpoint.c:15522
static void do_map_enable_count_breakpoint(struct breakpoint *bpt, void *countptr)
Definition: breakpoint.c:14735
completer_ftype * completer
Definition: cli-decode.h:177
static void do_map_delete_breakpoint(struct breakpoint *b, void *ignore)
Definition: breakpoint.c:13690
struct gdbarch * gdbarch
Definition: breakpoint.h:396
bpstat bpstat_stop_status(struct address_space *aspace, CORE_ADDR bp_addr, ptid_t ptid, const struct target_waitstatus *ws)
Definition: breakpoint.c:5493
char * type_to_string(struct type *type)
Definition: typeprint.c:370
static int breakpoint_cond_eval(void *)
Definition: breakpoint.c:4878
int get_number_or_range(struct get_number_or_range_state *state)
Definition: cli-utils.c:142
struct observer * observer_attach_memory_changed(observer_memory_changed_ftype *f)
CORE_ADDR value_address(const struct value *value)
Definition: value.c:1440
int is_catchpoint(struct breakpoint *ep)
Definition: breakpoint.c:4359
struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]
Definition: breakpoint.c:3342
static void bkpt_probe_decode_linespec(struct breakpoint *b, char **s, struct symtabs_and_lines *sals)
Definition: breakpoint.c:13199
void enable_watchpoints_after_interactive_call_stop(void)
Definition: breakpoint.c:8701
static void momentary_bkpt_re_set(struct breakpoint *b)
Definition: breakpoint.c:13086
Definition: defs.h:353
static void hbreak_command(char *, int)
Definition: breakpoint.c:9920
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition: minsyms.c:163
PTR xcalloc(size_t number, size_t size)
Definition: common-utils.c:71
static void catch_unload_command_1(char *arg, int from_tty, struct cmd_list_element *command)
Definition: breakpoint.c:8427
static int resources_needed_ranged_breakpoint(const struct bp_location *bl)
Definition: breakpoint.c:10052
struct command_line ** body_list
Definition: defs.h:417
struct command_line * control
Definition: breakpoint.c:1332
#define ALL_BP_LOCATIONS(B, BP_TMP)
Definition: breakpoint.c:568
struct breakpoint * owner
Definition: breakpoint.h:324
void delete_longjmp_breakpoint_at_next_stop(int thread)
Definition: breakpoint.c:7482
int is_scalar_type_recursive(struct type *t)
Definition: gdbtypes.c:2728
void delete_breakpoint(struct breakpoint *bpt)
Definition: breakpoint.c:13539
struct program_space * get_frame_program_space(struct frame_info *frame)
Definition: frame.c:2473
static int base_breakpoint_insert_location(struct bp_location *bl)
Definition: breakpoint.c:12643
static struct bp_location ** bp_location
Definition: breakpoint.c:599
void(* print_one)(struct breakpoint *, struct bp_location **)
Definition: breakpoint.h:554
static const char condition_evaluation_target[]
Definition: breakpoint.c:489
void breakpoint_re_set_thread(struct breakpoint *b)
Definition: breakpoint.c:14311
static void save_breakpoints_command(char *args, int from_tty)
Definition: breakpoint.c:15412
static void print_mention_masked_watchpoint(struct breakpoint *b)
Definition: breakpoint.c:10857
static void until_break_command_continuation(void *arg, int err)
Definition: breakpoint.c:11420
static int should_be_inserted(struct bp_location *bl)
Definition: breakpoint.c:2154
static void cleanup_executing_breakpoints(void *)
Definition: breakpoint.c:4555
int is_tracepoint(const struct breakpoint *b)
Definition: breakpoint.c:1163
void(* create_breakpoints_sal)(struct gdbarch *, struct linespec_result *, char *, char *, enum bptype, enum bpdisp, int, int, int, const struct breakpoint_ops *, int, int, int, unsigned)
Definition: breakpoint.h:593
static void base_breakpoint_create_breakpoints_sal(struct gdbarch *gdbarch, struct linespec_result *c, char *cond_string, char *extra_string, enum bptype type_wanted, enum bpdisp disposition, int thread, int task, int ignore_count, const struct breakpoint_ops *o, int from_tty, int enabled, int internal, unsigned flags)
Definition: breakpoint.c:12723
#define target_supports_stopped_by_hw_breakpoint()
Definition: target.h:1844
const char multiple_symbols_all[]
Definition: symtab.c:227
static int strace_marker_p(struct breakpoint *b)
Definition: breakpoint.c:13530
struct breakpoint base
Definition: breakpoint.h:775
struct frame_id watchpoint_frame
Definition: breakpoint.h:809
void error(const char *fmt,...)
Definition: errors.c:38
void jit_event_handler(struct gdbarch *gdbarch)
Definition: jit.c:1398
static void agent_printf_command(char *arg, int from_tty)
Definition: breakpoint.c:10026
static void dprintf_print_recreate(struct breakpoint *tp, struct ui_file *fp)
Definition: breakpoint.c:13387
static struct breakpoint_ops internal_breakpoint_ops
Definition: breakpoint.c:303
static int remove_breakpoint(struct bp_location *, insertion_state_t)
Definition: breakpoint.c:4033
void(* re_set)(struct breakpoint *self)
Definition: breakpoint.h:510
char needs_update
Definition: breakpoint.h:360
char * exp_string_reparse
Definition: breakpoint.h:781
#define target_static_tracepoint_marker_at(addr, marker)
Definition: target.h:2151
struct breakpoint * create_and_insert_solib_event_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
Definition: breakpoint.c:7729
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:873
int breakpoint_address_match(struct address_space *aspace1, CORE_ADDR addr1, struct address_space *aspace2, CORE_ADDR addr2)
Definition: breakpoint.c:6993
static void save_breakpoints(char *filename, int from_tty, int(*filter)(const struct breakpoint *))
Definition: breakpoint.c:15289
void set_breakpoint_condition(struct breakpoint *b, const char *exp, int from_tty)
Definition: breakpoint.c:960
int breakpoint_has_location_inserted_here(struct breakpoint *bp, struct address_space *aspace, CORE_ADDR pc)
Definition: breakpoint.c:14842
#define skip_to_space(INP)
Definition: common-utils.h:94
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
Definition: gnu-nat.c:1818
static void bp_location_dtor(struct bp_location *self)
Definition: breakpoint.c:12593
static void create_breakpoints_sal_default(struct gdbarch *, struct linespec_result *, char *, char *, enum bptype, enum bpdisp, int, int, int, const struct breakpoint_ops *, int, int, int, unsigned)
Definition: breakpoint.c:14187
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2535
static int bkpt_resources_needed(const struct bp_location *bl)
Definition: breakpoint.c:12857
static void create_fork_vfork_event_catchpoint(struct gdbarch *gdbarch, int tempflag, char *cond_string, const struct breakpoint_ops *ops)
Definition: breakpoint.c:8471
long long LONGEST
Definition: common-types.h:52
void free_command_lines(struct command_line **lptr)
Definition: cli-script.c:1375
int target_masked_watch_num_registers(CORE_ADDR addr, CORE_ADDR mask)
Definition: target.c:3517
static void target_info(char *, int)
Definition: target.c:2078
enum command_control_type execute_control_command(struct command_line *cmd)
Definition: cli-script.c:444
static void do_map_disable_breakpoint(struct breakpoint *b, void *ignore)
Definition: breakpoint.c:14525
void init_number_or_range(struct get_number_or_range_state *state, const char *string)
Definition: cli-utils.c:132
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
struct expression * cond
Definition: breakpoint.h:333
static int watchpoint_in_thread_scope(struct watchpoint *b)
Definition: breakpoint.c:1711
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:541
int is_executing(ptid_t ptid)
Definition: thread.c:840
static void update_watchpoint(struct watchpoint *b, int reparse)
Definition: breakpoint.c:1814
static void print_recreate_watchpoint(struct breakpoint *b, struct ui_file *fp)
Definition: breakpoint.c:10699
static void init_raw_breakpoint(struct breakpoint *b, struct gdbarch *gdbarch, struct symtab_and_line sal, enum bptype bptype, const struct breakpoint_ops *ops)
Definition: breakpoint.c:7390
struct command_line * read_command_lines(char *prompt_arg, int from_tty, int parse_commands, void(*validator)(char *, void *), void *closure)
Definition: cli-script.c:1259
enum return_reason reason
const char * bpdisp_text(enum bpdisp disp)
Definition: breakpoint.c:383
static void check_status_watchpoint(bpstat bs)
Definition: breakpoint.c:10535
struct frame_id frame_id
Definition: breakpoint.h:698
static void download_tracepoint_locations(void)
Definition: breakpoint.c:12009
static int dprintf_breakpoint_hit(const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr, const struct target_waitstatus *ws)
Definition: breakpoint.c:12840
CORE_ADDR scope
Definition: ax.h:110
static int bkpt_probe_remove_location(struct bp_location *bl)
Definition: breakpoint.c:13171
void observer_notify_breakpoint_modified(struct breakpoint *b)
struct observer * observer_attach_about_to_proceed(observer_about_to_proceed_ftype *f)
void add_continuation(struct thread_info *thread, continuation_ftype *hook, void *args, continuation_free_arg_ftype *free_arg)
char * filter
Definition: breakpoint.h:711
void check_longjmp_breakpoint_for_call_dummy(struct thread_info *tp)
Definition: breakpoint.c:7537
const struct probe_ops * probe_linespec_to_ops(const char **linespecp)
Definition: probe.c:845
enum mem_access_mode mode
Definition: memattr.h:58
void mark_breakpoints_out(void)
Definition: breakpoint.c:4058
const struct breakpoint_ops * ops
Definition: breakpoint.h:665
#define VEC_ordered_remove(T, V, I)
Definition: vec.h:339
const ULONGEST const LONGEST len
Definition: target.h:309
int gdbarch_get_longjmp_target_p(struct gdbarch *gdbarch)
Definition: gdbarch.c:2373
static void dprintf_command(char *arg, int from_tty)
Definition: breakpoint.c:10010
struct value * old_val
Definition: breakpoint.h:1101
enum bpstat_what_main_action main_action
Definition: breakpoint.h:989
LONGEST parse_and_eval_long(const char *exp)
Definition: eval.c:111
struct breakpoint * next
Definition: breakpoint.h:667