xref: /dflybsd-src/contrib/gdb-7/gdb/breakpoint.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Everything about breakpoints, for GDB.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "arch-utils.h"
225796c8dcSSimon Schubert #include <ctype.h>
235796c8dcSSimon Schubert #include "hashtab.h"
245796c8dcSSimon Schubert #include "symtab.h"
255796c8dcSSimon Schubert #include "frame.h"
265796c8dcSSimon Schubert #include "breakpoint.h"
275796c8dcSSimon Schubert #include "tracepoint.h"
285796c8dcSSimon Schubert #include "gdbtypes.h"
295796c8dcSSimon Schubert #include "expression.h"
305796c8dcSSimon Schubert #include "gdbcore.h"
315796c8dcSSimon Schubert #include "gdbcmd.h"
325796c8dcSSimon Schubert #include "value.h"
335796c8dcSSimon Schubert #include "command.h"
345796c8dcSSimon Schubert #include "inferior.h"
355796c8dcSSimon Schubert #include "gdbthread.h"
365796c8dcSSimon Schubert #include "target.h"
375796c8dcSSimon Schubert #include "language.h"
385796c8dcSSimon Schubert #include "gdb_string.h"
39a45ae5f8SJohn Marino #include "gdb-demangle.h"
40c50c785cSJohn Marino #include "filenames.h"
415796c8dcSSimon Schubert #include "annotate.h"
425796c8dcSSimon Schubert #include "symfile.h"
435796c8dcSSimon Schubert #include "objfiles.h"
445796c8dcSSimon Schubert #include "source.h"
455796c8dcSSimon Schubert #include "linespec.h"
465796c8dcSSimon Schubert #include "completer.h"
475796c8dcSSimon Schubert #include "gdb.h"
485796c8dcSSimon Schubert #include "ui-out.h"
495796c8dcSSimon Schubert #include "cli/cli-script.h"
505796c8dcSSimon Schubert #include "gdb_assert.h"
515796c8dcSSimon Schubert #include "block.h"
525796c8dcSSimon Schubert #include "solib.h"
535796c8dcSSimon Schubert #include "solist.h"
545796c8dcSSimon Schubert #include "observer.h"
555796c8dcSSimon Schubert #include "exceptions.h"
565796c8dcSSimon Schubert #include "memattr.h"
575796c8dcSSimon Schubert #include "ada-lang.h"
585796c8dcSSimon Schubert #include "top.h"
595796c8dcSSimon Schubert #include "valprint.h"
605796c8dcSSimon Schubert #include "jit.h"
615796c8dcSSimon Schubert #include "xml-syscall.h"
62cf7f2e2dSJohn Marino #include "parser-defs.h"
63*ef5ccd6cSJohn Marino #include "gdb_regex.h"
64*ef5ccd6cSJohn Marino #include "probe.h"
65c50c785cSJohn Marino #include "cli/cli-utils.h"
66a45ae5f8SJohn Marino #include "continuations.h"
67a45ae5f8SJohn Marino #include "stack.h"
68a45ae5f8SJohn Marino #include "skip.h"
69*ef5ccd6cSJohn Marino #include "gdb_regex.h"
70*ef5ccd6cSJohn Marino #include "ax-gdb.h"
71*ef5ccd6cSJohn Marino #include "dummy-frame.h"
72*ef5ccd6cSJohn Marino 
73*ef5ccd6cSJohn Marino #include "format.h"
745796c8dcSSimon Schubert 
755796c8dcSSimon Schubert /* readline include files */
765796c8dcSSimon Schubert #include "readline/readline.h"
775796c8dcSSimon Schubert #include "readline/history.h"
785796c8dcSSimon Schubert 
795796c8dcSSimon Schubert /* readline defines this.  */
805796c8dcSSimon Schubert #undef savestring
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert #include "mi/mi-common.h"
83c50c785cSJohn Marino #include "python/python.h"
845796c8dcSSimon Schubert 
85*ef5ccd6cSJohn Marino /* Enums for exception-handling support.  */
86*ef5ccd6cSJohn Marino enum exception_event_kind
87*ef5ccd6cSJohn Marino {
88*ef5ccd6cSJohn Marino   EX_EVENT_THROW,
89*ef5ccd6cSJohn Marino   EX_EVENT_CATCH
90*ef5ccd6cSJohn Marino };
91*ef5ccd6cSJohn Marino 
925796c8dcSSimon Schubert /* Prototypes for local functions.  */
935796c8dcSSimon Schubert 
945796c8dcSSimon Schubert static void enable_delete_command (char *, int);
955796c8dcSSimon Schubert 
965796c8dcSSimon Schubert static void enable_once_command (char *, int);
975796c8dcSSimon Schubert 
98*ef5ccd6cSJohn Marino static void enable_count_command (char *, int);
99*ef5ccd6cSJohn Marino 
1005796c8dcSSimon Schubert static void disable_command (char *, int);
1015796c8dcSSimon Schubert 
1025796c8dcSSimon Schubert static void enable_command (char *, int);
1035796c8dcSSimon Schubert 
104cf7f2e2dSJohn Marino static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
105cf7f2e2dSJohn Marino 						      void *),
106cf7f2e2dSJohn Marino 				    void *);
1075796c8dcSSimon Schubert 
1085796c8dcSSimon Schubert static void ignore_command (char *, int);
1095796c8dcSSimon Schubert 
1105796c8dcSSimon Schubert static int breakpoint_re_set_one (void *);
1115796c8dcSSimon Schubert 
112a45ae5f8SJohn Marino static void breakpoint_re_set_default (struct breakpoint *);
113a45ae5f8SJohn Marino 
114*ef5ccd6cSJohn Marino static void create_sals_from_address_default (char **,
115*ef5ccd6cSJohn Marino 					      struct linespec_result *,
116*ef5ccd6cSJohn Marino 					      enum bptype, char *,
117*ef5ccd6cSJohn Marino 					      char **);
118*ef5ccd6cSJohn Marino 
119*ef5ccd6cSJohn Marino static void create_breakpoints_sal_default (struct gdbarch *,
120*ef5ccd6cSJohn Marino 					    struct linespec_result *,
121*ef5ccd6cSJohn Marino 					    struct linespec_sals *,
122*ef5ccd6cSJohn Marino 					    char *, char *, enum bptype,
123*ef5ccd6cSJohn Marino 					    enum bpdisp, int, int,
124*ef5ccd6cSJohn Marino 					    int,
125*ef5ccd6cSJohn Marino 					    const struct breakpoint_ops *,
126*ef5ccd6cSJohn Marino 					    int, int, int, unsigned);
127*ef5ccd6cSJohn Marino 
128*ef5ccd6cSJohn Marino static void decode_linespec_default (struct breakpoint *, char **,
129*ef5ccd6cSJohn Marino 				     struct symtabs_and_lines *);
130*ef5ccd6cSJohn Marino 
1315796c8dcSSimon Schubert static void clear_command (char *, int);
1325796c8dcSSimon Schubert 
1335796c8dcSSimon Schubert static void catch_command (char *, int);
1345796c8dcSSimon Schubert 
135a45ae5f8SJohn Marino static int can_use_hardware_watchpoint (struct value *);
1365796c8dcSSimon Schubert 
1375796c8dcSSimon Schubert static void break_command_1 (char *, int, int);
1385796c8dcSSimon Schubert 
1395796c8dcSSimon Schubert static void mention (struct breakpoint *);
1405796c8dcSSimon Schubert 
141a45ae5f8SJohn Marino static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
142a45ae5f8SJohn Marino 							       enum bptype,
143a45ae5f8SJohn Marino 							       const struct breakpoint_ops *);
144a45ae5f8SJohn Marino static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
145a45ae5f8SJohn Marino 						       const struct symtab_and_line *);
146a45ae5f8SJohn Marino 
147c50c785cSJohn Marino /* This function is used in gdbtk sources and thus can not be made
148c50c785cSJohn Marino    static.  */
1495796c8dcSSimon Schubert struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
1505796c8dcSSimon Schubert 				       struct symtab_and_line,
151a45ae5f8SJohn Marino 				       enum bptype,
152a45ae5f8SJohn Marino 				       const struct breakpoint_ops *);
153a45ae5f8SJohn Marino 
154a45ae5f8SJohn Marino static struct breakpoint *
155a45ae5f8SJohn Marino   momentary_breakpoint_from_master (struct breakpoint *orig,
156a45ae5f8SJohn Marino 				    enum bptype type,
157a45ae5f8SJohn Marino 				    const struct breakpoint_ops *ops);
1585796c8dcSSimon Schubert 
1595796c8dcSSimon Schubert static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
1605796c8dcSSimon Schubert 
1615796c8dcSSimon Schubert static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
1625796c8dcSSimon Schubert 					    CORE_ADDR bpaddr,
1635796c8dcSSimon Schubert                                             enum bptype bptype);
1645796c8dcSSimon Schubert 
165cf7f2e2dSJohn Marino static void describe_other_breakpoints (struct gdbarch *,
166cf7f2e2dSJohn Marino 					struct program_space *, CORE_ADDR,
1675796c8dcSSimon Schubert 					struct obj_section *, int);
1685796c8dcSSimon Schubert 
169cf7f2e2dSJohn Marino static int breakpoint_address_match (struct address_space *aspace1,
170cf7f2e2dSJohn Marino 				     CORE_ADDR addr1,
171cf7f2e2dSJohn Marino 				     struct address_space *aspace2,
172cf7f2e2dSJohn Marino 				     CORE_ADDR addr2);
173cf7f2e2dSJohn Marino 
174cf7f2e2dSJohn Marino static int watchpoint_locations_match (struct bp_location *loc1,
175cf7f2e2dSJohn Marino 				       struct bp_location *loc2);
176cf7f2e2dSJohn Marino 
177c50c785cSJohn Marino static int breakpoint_location_address_match (struct bp_location *bl,
178c50c785cSJohn Marino 					      struct address_space *aspace,
179c50c785cSJohn Marino 					      CORE_ADDR addr);
180c50c785cSJohn Marino 
1815796c8dcSSimon Schubert static void breakpoints_info (char *, int);
1825796c8dcSSimon Schubert 
183cf7f2e2dSJohn Marino static void watchpoints_info (char *, int);
184cf7f2e2dSJohn Marino 
185c50c785cSJohn Marino static int breakpoint_1 (char *, int,
186c50c785cSJohn Marino 			 int (*) (const struct breakpoint *));
1875796c8dcSSimon Schubert 
1885796c8dcSSimon Schubert static int breakpoint_cond_eval (void *);
1895796c8dcSSimon Schubert 
1905796c8dcSSimon Schubert static void cleanup_executing_breakpoints (void *);
1915796c8dcSSimon Schubert 
1925796c8dcSSimon Schubert static void commands_command (char *, int);
1935796c8dcSSimon Schubert 
1945796c8dcSSimon Schubert static void condition_command (char *, int);
1955796c8dcSSimon Schubert 
1965796c8dcSSimon Schubert typedef enum
1975796c8dcSSimon Schubert   {
1985796c8dcSSimon Schubert     mark_inserted,
1995796c8dcSSimon Schubert     mark_uninserted
2005796c8dcSSimon Schubert   }
2015796c8dcSSimon Schubert insertion_state_t;
2025796c8dcSSimon Schubert 
2035796c8dcSSimon Schubert static int remove_breakpoint (struct bp_location *, insertion_state_t);
204cf7f2e2dSJohn Marino static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
2055796c8dcSSimon Schubert 
2065796c8dcSSimon Schubert static enum print_stop_action print_bp_stop_message (bpstat bs);
2075796c8dcSSimon Schubert 
2085796c8dcSSimon Schubert static int watchpoint_check (void *);
2095796c8dcSSimon Schubert 
2105796c8dcSSimon Schubert static void maintenance_info_breakpoints (char *, int);
2115796c8dcSSimon Schubert 
2125796c8dcSSimon Schubert static int hw_breakpoint_used_count (void);
2135796c8dcSSimon Schubert 
214a45ae5f8SJohn Marino static int hw_watchpoint_use_count (struct breakpoint *);
215a45ae5f8SJohn Marino 
216a45ae5f8SJohn Marino static int hw_watchpoint_used_count_others (struct breakpoint *except,
217a45ae5f8SJohn Marino 					    enum bptype type,
218a45ae5f8SJohn Marino 					    int *other_type_used);
2195796c8dcSSimon Schubert 
2205796c8dcSSimon Schubert static void hbreak_command (char *, int);
2215796c8dcSSimon Schubert 
2225796c8dcSSimon Schubert static void thbreak_command (char *, int);
2235796c8dcSSimon Schubert 
224*ef5ccd6cSJohn Marino static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
225*ef5ccd6cSJohn Marino 				    int count);
2265796c8dcSSimon Schubert 
2275796c8dcSSimon Schubert static void stop_command (char *arg, int from_tty);
2285796c8dcSSimon Schubert 
2295796c8dcSSimon Schubert static void stopin_command (char *arg, int from_tty);
2305796c8dcSSimon Schubert 
2315796c8dcSSimon Schubert static void stopat_command (char *arg, int from_tty);
2325796c8dcSSimon Schubert 
2335796c8dcSSimon Schubert static char *ep_parse_optional_if_clause (char **arg);
2345796c8dcSSimon Schubert 
2355796c8dcSSimon Schubert static void catch_exception_command_1 (enum exception_event_kind ex_event,
2365796c8dcSSimon Schubert 				       char *arg, int tempflag, int from_tty);
2375796c8dcSSimon Schubert 
2385796c8dcSSimon Schubert static void tcatch_command (char *arg, int from_tty);
2395796c8dcSSimon Schubert 
240cf7f2e2dSJohn Marino static void detach_single_step_breakpoints (void);
241cf7f2e2dSJohn Marino 
242cf7f2e2dSJohn Marino static int single_step_breakpoint_inserted_here_p (struct address_space *,
243cf7f2e2dSJohn Marino 						   CORE_ADDR pc);
2445796c8dcSSimon Schubert 
2455796c8dcSSimon Schubert static void free_bp_location (struct bp_location *loc);
246c50c785cSJohn Marino static void incref_bp_location (struct bp_location *loc);
247c50c785cSJohn Marino static void decref_bp_location (struct bp_location **loc);
2485796c8dcSSimon Schubert 
2495796c8dcSSimon Schubert static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
2505796c8dcSSimon Schubert 
2515796c8dcSSimon Schubert static void update_global_location_list (int);
2525796c8dcSSimon Schubert 
2535796c8dcSSimon Schubert static void update_global_location_list_nothrow (int);
2545796c8dcSSimon Schubert 
255cf7f2e2dSJohn Marino static int is_hardware_watchpoint (const struct breakpoint *bpt);
256cf7f2e2dSJohn Marino 
2575796c8dcSSimon Schubert static void insert_breakpoint_locations (void);
2585796c8dcSSimon Schubert 
2595796c8dcSSimon Schubert static int syscall_catchpoint_p (struct breakpoint *b);
2605796c8dcSSimon Schubert 
2615796c8dcSSimon Schubert static void tracepoints_info (char *, int);
2625796c8dcSSimon Schubert 
2635796c8dcSSimon Schubert static void delete_trace_command (char *, int);
2645796c8dcSSimon Schubert 
2655796c8dcSSimon Schubert static void enable_trace_command (char *, int);
2665796c8dcSSimon Schubert 
2675796c8dcSSimon Schubert static void disable_trace_command (char *, int);
2685796c8dcSSimon Schubert 
2695796c8dcSSimon Schubert static void trace_pass_command (char *, int);
2705796c8dcSSimon Schubert 
271*ef5ccd6cSJohn Marino static void set_tracepoint_count (int num);
272*ef5ccd6cSJohn Marino 
273a45ae5f8SJohn Marino static int is_masked_watchpoint (const struct breakpoint *b);
274a45ae5f8SJohn Marino 
275*ef5ccd6cSJohn Marino static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
276*ef5ccd6cSJohn Marino 
277*ef5ccd6cSJohn Marino /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
278*ef5ccd6cSJohn Marino    otherwise.  */
279*ef5ccd6cSJohn Marino 
280*ef5ccd6cSJohn Marino static int strace_marker_p (struct breakpoint *b);
2815796c8dcSSimon Schubert 
282a45ae5f8SJohn Marino /* The abstract base class all breakpoint_ops structures inherit
283a45ae5f8SJohn Marino    from.  */
284*ef5ccd6cSJohn Marino struct breakpoint_ops base_breakpoint_ops;
285a45ae5f8SJohn Marino 
286a45ae5f8SJohn Marino /* The breakpoint_ops structure to be inherited by all breakpoint_ops
287a45ae5f8SJohn Marino    that are implemented on top of software or hardware breakpoints
288a45ae5f8SJohn Marino    (user breakpoints, internal and momentary breakpoints, etc.).  */
289a45ae5f8SJohn Marino static struct breakpoint_ops bkpt_base_breakpoint_ops;
290a45ae5f8SJohn Marino 
291a45ae5f8SJohn Marino /* Internal breakpoints class type.  */
292a45ae5f8SJohn Marino static struct breakpoint_ops internal_breakpoint_ops;
293a45ae5f8SJohn Marino 
294a45ae5f8SJohn Marino /* Momentary breakpoints class type.  */
295a45ae5f8SJohn Marino static struct breakpoint_ops momentary_breakpoint_ops;
296a45ae5f8SJohn Marino 
297*ef5ccd6cSJohn Marino /* Momentary breakpoints for bp_longjmp and bp_exception class type.  */
298*ef5ccd6cSJohn Marino static struct breakpoint_ops longjmp_breakpoint_ops;
299*ef5ccd6cSJohn Marino 
300a45ae5f8SJohn Marino /* The breakpoint_ops structure to be used in regular user created
301a45ae5f8SJohn Marino    breakpoints.  */
302a45ae5f8SJohn Marino struct breakpoint_ops bkpt_breakpoint_ops;
303a45ae5f8SJohn Marino 
304*ef5ccd6cSJohn Marino /* Breakpoints set on probes.  */
305*ef5ccd6cSJohn Marino static struct breakpoint_ops bkpt_probe_breakpoint_ops;
306*ef5ccd6cSJohn Marino 
307*ef5ccd6cSJohn Marino /* Dynamic printf class type.  */
308*ef5ccd6cSJohn Marino static struct breakpoint_ops dprintf_breakpoint_ops;
309*ef5ccd6cSJohn Marino 
310*ef5ccd6cSJohn Marino /* The style in which to perform a dynamic printf.  This is a user
311*ef5ccd6cSJohn Marino    option because different output options have different tradeoffs;
312*ef5ccd6cSJohn Marino    if GDB does the printing, there is better error handling if there
313*ef5ccd6cSJohn Marino    is a problem with any of the arguments, but using an inferior
314*ef5ccd6cSJohn Marino    function lets you have special-purpose printers and sending of
315*ef5ccd6cSJohn Marino    output to the same place as compiled-in print functions.  */
316*ef5ccd6cSJohn Marino 
317*ef5ccd6cSJohn Marino static const char dprintf_style_gdb[] = "gdb";
318*ef5ccd6cSJohn Marino static const char dprintf_style_call[] = "call";
319*ef5ccd6cSJohn Marino static const char dprintf_style_agent[] = "agent";
320*ef5ccd6cSJohn Marino static const char *const dprintf_style_enums[] = {
321*ef5ccd6cSJohn Marino   dprintf_style_gdb,
322*ef5ccd6cSJohn Marino   dprintf_style_call,
323*ef5ccd6cSJohn Marino   dprintf_style_agent,
324*ef5ccd6cSJohn Marino   NULL
325*ef5ccd6cSJohn Marino };
326*ef5ccd6cSJohn Marino static const char *dprintf_style = dprintf_style_gdb;
327*ef5ccd6cSJohn Marino 
328*ef5ccd6cSJohn Marino /* The function to use for dynamic printf if the preferred style is to
329*ef5ccd6cSJohn Marino    call into the inferior.  The value is simply a string that is
330*ef5ccd6cSJohn Marino    copied into the command, so it can be anything that GDB can
331*ef5ccd6cSJohn Marino    evaluate to a callable address, not necessarily a function name.  */
332*ef5ccd6cSJohn Marino 
333*ef5ccd6cSJohn Marino static char *dprintf_function = "";
334*ef5ccd6cSJohn Marino 
335*ef5ccd6cSJohn Marino /* The channel to use for dynamic printf if the preferred style is to
336*ef5ccd6cSJohn Marino    call into the inferior; if a nonempty string, it will be passed to
337*ef5ccd6cSJohn Marino    the call as the first argument, with the format string as the
338*ef5ccd6cSJohn Marino    second.  As with the dprintf function, this can be anything that
339*ef5ccd6cSJohn Marino    GDB knows how to evaluate, so in addition to common choices like
340*ef5ccd6cSJohn Marino    "stderr", this could be an app-specific expression like
341*ef5ccd6cSJohn Marino    "mystreams[curlogger]".  */
342*ef5ccd6cSJohn Marino 
343*ef5ccd6cSJohn Marino static char *dprintf_channel = "";
344*ef5ccd6cSJohn Marino 
345*ef5ccd6cSJohn Marino /* True if dprintf commands should continue to operate even if GDB
346*ef5ccd6cSJohn Marino    has disconnected.  */
347*ef5ccd6cSJohn Marino static int disconnected_dprintf = 1;
348*ef5ccd6cSJohn Marino 
349cf7f2e2dSJohn Marino /* A reference-counted struct command_line.  This lets multiple
350cf7f2e2dSJohn Marino    breakpoints share a single command list.  */
351cf7f2e2dSJohn Marino struct counted_command_line
352cf7f2e2dSJohn Marino {
353cf7f2e2dSJohn Marino   /* The reference count.  */
354cf7f2e2dSJohn Marino   int refc;
355cf7f2e2dSJohn Marino 
356cf7f2e2dSJohn Marino   /* The command list.  */
357cf7f2e2dSJohn Marino   struct command_line *commands;
358cf7f2e2dSJohn Marino };
359cf7f2e2dSJohn Marino 
360cf7f2e2dSJohn Marino struct command_line *
breakpoint_commands(struct breakpoint * b)361cf7f2e2dSJohn Marino breakpoint_commands (struct breakpoint *b)
362cf7f2e2dSJohn Marino {
363cf7f2e2dSJohn Marino   return b->commands ? b->commands->commands : NULL;
364cf7f2e2dSJohn Marino }
3655796c8dcSSimon Schubert 
3665796c8dcSSimon Schubert /* Flag indicating that a command has proceeded the inferior past the
3675796c8dcSSimon Schubert    current breakpoint.  */
3685796c8dcSSimon Schubert 
3695796c8dcSSimon Schubert static int breakpoint_proceeded;
3705796c8dcSSimon Schubert 
371c50c785cSJohn Marino const char *
bpdisp_text(enum bpdisp disp)3725796c8dcSSimon Schubert bpdisp_text (enum bpdisp disp)
3735796c8dcSSimon Schubert {
374c50c785cSJohn Marino   /* NOTE: the following values are a part of MI protocol and
375c50c785cSJohn Marino      represent values of 'disp' field returned when inferior stops at
376c50c785cSJohn Marino      a breakpoint.  */
377c50c785cSJohn Marino   static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
378cf7f2e2dSJohn Marino 
3795796c8dcSSimon Schubert   return bpdisps[(int) disp];
3805796c8dcSSimon Schubert }
3815796c8dcSSimon Schubert 
3825796c8dcSSimon Schubert /* Prototypes for exported functions.  */
3835796c8dcSSimon Schubert /* If FALSE, gdb will not use hardware support for watchpoints, even
3845796c8dcSSimon Schubert    if such is available.  */
3855796c8dcSSimon Schubert static int can_use_hw_watchpoints;
3865796c8dcSSimon Schubert 
3875796c8dcSSimon Schubert static void
show_can_use_hw_watchpoints(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)3885796c8dcSSimon Schubert show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
3895796c8dcSSimon Schubert 			     struct cmd_list_element *c,
3905796c8dcSSimon Schubert 			     const char *value)
3915796c8dcSSimon Schubert {
392c50c785cSJohn Marino   fprintf_filtered (file,
393c50c785cSJohn Marino 		    _("Debugger's willingness to use "
394c50c785cSJohn Marino 		      "watchpoint hardware is %s.\n"),
3955796c8dcSSimon Schubert 		    value);
3965796c8dcSSimon Schubert }
3975796c8dcSSimon Schubert 
3985796c8dcSSimon Schubert /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
3995796c8dcSSimon Schubert    If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
4005796c8dcSSimon Schubert    for unrecognized breakpoint locations.
4015796c8dcSSimon Schubert    If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized.  */
4025796c8dcSSimon Schubert static enum auto_boolean pending_break_support;
4035796c8dcSSimon Schubert static void
show_pending_break_support(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)4045796c8dcSSimon Schubert show_pending_break_support (struct ui_file *file, int from_tty,
4055796c8dcSSimon Schubert 			    struct cmd_list_element *c,
4065796c8dcSSimon Schubert 			    const char *value)
4075796c8dcSSimon Schubert {
408c50c785cSJohn Marino   fprintf_filtered (file,
409c50c785cSJohn Marino 		    _("Debugger's behavior regarding "
410c50c785cSJohn Marino 		      "pending breakpoints is %s.\n"),
4115796c8dcSSimon Schubert 		    value);
4125796c8dcSSimon Schubert }
4135796c8dcSSimon Schubert 
4145796c8dcSSimon Schubert /* If 1, gdb will automatically use hardware breakpoints for breakpoints
4155796c8dcSSimon Schubert    set with "break" but falling in read-only memory.
4165796c8dcSSimon Schubert    If 0, gdb will warn about such breakpoints, but won't automatically
4175796c8dcSSimon Schubert    use hardware breakpoints.  */
4185796c8dcSSimon Schubert static int automatic_hardware_breakpoints;
4195796c8dcSSimon Schubert static void
show_automatic_hardware_breakpoints(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)4205796c8dcSSimon Schubert show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
4215796c8dcSSimon Schubert 				     struct cmd_list_element *c,
4225796c8dcSSimon Schubert 				     const char *value)
4235796c8dcSSimon Schubert {
424c50c785cSJohn Marino   fprintf_filtered (file,
425c50c785cSJohn Marino 		    _("Automatic usage of hardware breakpoints is %s.\n"),
4265796c8dcSSimon Schubert 		    value);
4275796c8dcSSimon Schubert }
4285796c8dcSSimon Schubert 
4295796c8dcSSimon Schubert /* If on, gdb will keep breakpoints inserted even as inferior is
4305796c8dcSSimon Schubert    stopped, and immediately insert any new breakpoints.  If off, gdb
4315796c8dcSSimon Schubert    will insert breakpoints into inferior only when resuming it, and
4325796c8dcSSimon Schubert    will remove breakpoints upon stop.  If auto, GDB will behave as ON
4335796c8dcSSimon Schubert    if in non-stop mode, and as OFF if all-stop mode.*/
4345796c8dcSSimon Schubert 
435*ef5ccd6cSJohn Marino static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO;
436*ef5ccd6cSJohn Marino 
4375796c8dcSSimon Schubert static void
show_always_inserted_mode(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)4385796c8dcSSimon Schubert show_always_inserted_mode (struct ui_file *file, int from_tty,
4395796c8dcSSimon Schubert 		     struct cmd_list_element *c, const char *value)
4405796c8dcSSimon Schubert {
441*ef5ccd6cSJohn Marino   if (always_inserted_mode == AUTO_BOOLEAN_AUTO)
442c50c785cSJohn Marino     fprintf_filtered (file,
443c50c785cSJohn Marino 		      _("Always inserted breakpoint "
444c50c785cSJohn Marino 			"mode is %s (currently %s).\n"),
4455796c8dcSSimon Schubert 		      value,
4465796c8dcSSimon Schubert 		      breakpoints_always_inserted_mode () ? "on" : "off");
4475796c8dcSSimon Schubert   else
448c50c785cSJohn Marino     fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
449c50c785cSJohn Marino 		      value);
4505796c8dcSSimon Schubert }
4515796c8dcSSimon Schubert 
4525796c8dcSSimon Schubert int
breakpoints_always_inserted_mode(void)4535796c8dcSSimon Schubert breakpoints_always_inserted_mode (void)
4545796c8dcSSimon Schubert {
455*ef5ccd6cSJohn Marino   return (always_inserted_mode == AUTO_BOOLEAN_TRUE
456*ef5ccd6cSJohn Marino 	  || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop));
457*ef5ccd6cSJohn Marino }
458*ef5ccd6cSJohn Marino 
459*ef5ccd6cSJohn Marino static const char condition_evaluation_both[] = "host or target";
460*ef5ccd6cSJohn Marino 
461*ef5ccd6cSJohn Marino /* Modes for breakpoint condition evaluation.  */
462*ef5ccd6cSJohn Marino static const char condition_evaluation_auto[] = "auto";
463*ef5ccd6cSJohn Marino static const char condition_evaluation_host[] = "host";
464*ef5ccd6cSJohn Marino static const char condition_evaluation_target[] = "target";
465*ef5ccd6cSJohn Marino static const char *const condition_evaluation_enums[] = {
466*ef5ccd6cSJohn Marino   condition_evaluation_auto,
467*ef5ccd6cSJohn Marino   condition_evaluation_host,
468*ef5ccd6cSJohn Marino   condition_evaluation_target,
469*ef5ccd6cSJohn Marino   NULL
470*ef5ccd6cSJohn Marino };
471*ef5ccd6cSJohn Marino 
472*ef5ccd6cSJohn Marino /* Global that holds the current mode for breakpoint condition evaluation.  */
473*ef5ccd6cSJohn Marino static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
474*ef5ccd6cSJohn Marino 
475*ef5ccd6cSJohn Marino /* Global that we use to display information to the user (gets its value from
476*ef5ccd6cSJohn Marino    condition_evaluation_mode_1.  */
477*ef5ccd6cSJohn Marino static const char *condition_evaluation_mode = condition_evaluation_auto;
478*ef5ccd6cSJohn Marino 
479*ef5ccd6cSJohn Marino /* Translate a condition evaluation mode MODE into either "host"
480*ef5ccd6cSJohn Marino    or "target".  This is used mostly to translate from "auto" to the
481*ef5ccd6cSJohn Marino    real setting that is being used.  It returns the translated
482*ef5ccd6cSJohn Marino    evaluation mode.  */
483*ef5ccd6cSJohn Marino 
484*ef5ccd6cSJohn Marino static const char *
translate_condition_evaluation_mode(const char * mode)485*ef5ccd6cSJohn Marino translate_condition_evaluation_mode (const char *mode)
486*ef5ccd6cSJohn Marino {
487*ef5ccd6cSJohn Marino   if (mode == condition_evaluation_auto)
488*ef5ccd6cSJohn Marino     {
489*ef5ccd6cSJohn Marino       if (target_supports_evaluation_of_breakpoint_conditions ())
490*ef5ccd6cSJohn Marino 	return condition_evaluation_target;
491*ef5ccd6cSJohn Marino       else
492*ef5ccd6cSJohn Marino 	return condition_evaluation_host;
493*ef5ccd6cSJohn Marino     }
494*ef5ccd6cSJohn Marino   else
495*ef5ccd6cSJohn Marino     return mode;
496*ef5ccd6cSJohn Marino }
497*ef5ccd6cSJohn Marino 
498*ef5ccd6cSJohn Marino /* Discovers what condition_evaluation_auto translates to.  */
499*ef5ccd6cSJohn Marino 
500*ef5ccd6cSJohn Marino static const char *
breakpoint_condition_evaluation_mode(void)501*ef5ccd6cSJohn Marino breakpoint_condition_evaluation_mode (void)
502*ef5ccd6cSJohn Marino {
503*ef5ccd6cSJohn Marino   return translate_condition_evaluation_mode (condition_evaluation_mode);
504*ef5ccd6cSJohn Marino }
505*ef5ccd6cSJohn Marino 
506*ef5ccd6cSJohn Marino /* Return true if GDB should evaluate breakpoint conditions or false
507*ef5ccd6cSJohn Marino    otherwise.  */
508*ef5ccd6cSJohn Marino 
509*ef5ccd6cSJohn Marino static int
gdb_evaluates_breakpoint_condition_p(void)510*ef5ccd6cSJohn Marino gdb_evaluates_breakpoint_condition_p (void)
511*ef5ccd6cSJohn Marino {
512*ef5ccd6cSJohn Marino   const char *mode = breakpoint_condition_evaluation_mode ();
513*ef5ccd6cSJohn Marino 
514*ef5ccd6cSJohn Marino   return (mode == condition_evaluation_host);
5155796c8dcSSimon Schubert }
5165796c8dcSSimon Schubert 
5175796c8dcSSimon Schubert void _initialize_breakpoint (void);
5185796c8dcSSimon Schubert 
5195796c8dcSSimon Schubert /* Are we executing breakpoint commands?  */
5205796c8dcSSimon Schubert static int executing_breakpoint_commands;
5215796c8dcSSimon Schubert 
5225796c8dcSSimon Schubert /* Are overlay event breakpoints enabled? */
5235796c8dcSSimon Schubert static int overlay_events_enabled;
5245796c8dcSSimon Schubert 
525c50c785cSJohn Marino /* See description in breakpoint.h. */
526c50c785cSJohn Marino int target_exact_watchpoints = 0;
527c50c785cSJohn Marino 
5285796c8dcSSimon Schubert /* Walk the following statement or block through all breakpoints.
529a45ae5f8SJohn Marino    ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
530c50c785cSJohn Marino    current breakpoint.  */
5315796c8dcSSimon Schubert 
5325796c8dcSSimon Schubert #define ALL_BREAKPOINTS(B)  for (B = breakpoint_chain; B; B = B->next)
5335796c8dcSSimon Schubert 
5345796c8dcSSimon Schubert #define ALL_BREAKPOINTS_SAFE(B,TMP)	\
5355796c8dcSSimon Schubert 	for (B = breakpoint_chain;	\
5365796c8dcSSimon Schubert 	     B ? (TMP=B->next, 1): 0;	\
5375796c8dcSSimon Schubert 	     B = TMP)
5385796c8dcSSimon Schubert 
539c50c785cSJohn Marino /* Similar iterator for the low-level breakpoints.  SAFE variant is
540c50c785cSJohn Marino    not provided so update_global_location_list must not be called
541c50c785cSJohn Marino    while executing the block of ALL_BP_LOCATIONS.  */
5425796c8dcSSimon Schubert 
543cf7f2e2dSJohn Marino #define ALL_BP_LOCATIONS(B,BP_TMP)					\
544cf7f2e2dSJohn Marino 	for (BP_TMP = bp_location;					\
545cf7f2e2dSJohn Marino 	     BP_TMP < bp_location + bp_location_count && (B = *BP_TMP);	\
546cf7f2e2dSJohn Marino 	     BP_TMP++)
5475796c8dcSSimon Schubert 
548*ef5ccd6cSJohn Marino /* Iterates through locations with address ADDRESS for the currently selected
549*ef5ccd6cSJohn Marino    program space.  BP_LOCP_TMP points to each object.  BP_LOCP_START points
550*ef5ccd6cSJohn Marino    to where the loop should start from.
551*ef5ccd6cSJohn Marino    If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
552*ef5ccd6cSJohn Marino    appropriate location to start with.  */
553*ef5ccd6cSJohn Marino 
554*ef5ccd6cSJohn Marino #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS)	\
555*ef5ccd6cSJohn Marino 	for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
556*ef5ccd6cSJohn Marino 	     BP_LOCP_TMP = BP_LOCP_START;				\
557*ef5ccd6cSJohn Marino 	     BP_LOCP_START						\
558*ef5ccd6cSJohn Marino 	     && (BP_LOCP_TMP < bp_location + bp_location_count		\
559*ef5ccd6cSJohn Marino 	     && (*BP_LOCP_TMP)->address == ADDRESS);			\
560*ef5ccd6cSJohn Marino 	     BP_LOCP_TMP++)
561*ef5ccd6cSJohn Marino 
5625796c8dcSSimon Schubert /* Iterator for tracepoints only.  */
5635796c8dcSSimon Schubert 
5645796c8dcSSimon Schubert #define ALL_TRACEPOINTS(B)  \
5655796c8dcSSimon Schubert   for (B = breakpoint_chain; B; B = B->next)  \
566cf7f2e2dSJohn Marino     if (is_tracepoint (B))
5675796c8dcSSimon Schubert 
5685796c8dcSSimon Schubert /* Chains of all breakpoints defined.  */
5695796c8dcSSimon Schubert 
5705796c8dcSSimon Schubert struct breakpoint *breakpoint_chain;
5715796c8dcSSimon Schubert 
572cf7f2e2dSJohn Marino /* Array is sorted by bp_location_compare - primarily by the ADDRESS.  */
573cf7f2e2dSJohn Marino 
574cf7f2e2dSJohn Marino static struct bp_location **bp_location;
575cf7f2e2dSJohn Marino 
576cf7f2e2dSJohn Marino /* Number of elements of BP_LOCATION.  */
577cf7f2e2dSJohn Marino 
578cf7f2e2dSJohn Marino static unsigned bp_location_count;
579cf7f2e2dSJohn Marino 
580c50c785cSJohn Marino /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
581c50c785cSJohn Marino    ADDRESS for the current elements of BP_LOCATION which get a valid
582c50c785cSJohn Marino    result from bp_location_has_shadow.  You can use it for roughly
583c50c785cSJohn Marino    limiting the subrange of BP_LOCATION to scan for shadow bytes for
584c50c785cSJohn Marino    an address you need to read.  */
585cf7f2e2dSJohn Marino 
586cf7f2e2dSJohn Marino static CORE_ADDR bp_location_placed_address_before_address_max;
587cf7f2e2dSJohn Marino 
588c50c785cSJohn Marino /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
589c50c785cSJohn Marino    + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
590c50c785cSJohn Marino    BP_LOCATION which get a valid result from bp_location_has_shadow.
591c50c785cSJohn Marino    You can use it for roughly limiting the subrange of BP_LOCATION to
592c50c785cSJohn Marino    scan for shadow bytes for an address you need to read.  */
593cf7f2e2dSJohn Marino 
594cf7f2e2dSJohn Marino static CORE_ADDR bp_location_shadow_len_after_address_max;
5955796c8dcSSimon Schubert 
596c50c785cSJohn Marino /* The locations that no longer correspond to any breakpoint, unlinked
597c50c785cSJohn Marino    from bp_location array, but for which a hit may still be reported
598c50c785cSJohn Marino    by a target.  */
5995796c8dcSSimon Schubert VEC(bp_location_p) *moribund_locations = NULL;
6005796c8dcSSimon Schubert 
6015796c8dcSSimon Schubert /* Number of last breakpoint made.  */
6025796c8dcSSimon Schubert 
603cf7f2e2dSJohn Marino static int breakpoint_count;
604cf7f2e2dSJohn Marino 
605cf7f2e2dSJohn Marino /* The value of `breakpoint_count' before the last command that
606cf7f2e2dSJohn Marino    created breakpoints.  If the last (break-like) command created more
607cf7f2e2dSJohn Marino    than one breakpoint, then the difference between BREAKPOINT_COUNT
608cf7f2e2dSJohn Marino    and PREV_BREAKPOINT_COUNT is more than one.  */
609cf7f2e2dSJohn Marino static int prev_breakpoint_count;
6105796c8dcSSimon Schubert 
6115796c8dcSSimon Schubert /* Number of last tracepoint made.  */
6125796c8dcSSimon Schubert 
613cf7f2e2dSJohn Marino static int tracepoint_count;
614cf7f2e2dSJohn Marino 
615cf7f2e2dSJohn Marino static struct cmd_list_element *breakpoint_set_cmdlist;
616cf7f2e2dSJohn Marino static struct cmd_list_element *breakpoint_show_cmdlist;
617c50c785cSJohn Marino struct cmd_list_element *save_cmdlist;
6185796c8dcSSimon Schubert 
6195796c8dcSSimon Schubert /* Return whether a breakpoint is an active enabled breakpoint.  */
6205796c8dcSSimon Schubert static int
breakpoint_enabled(struct breakpoint * b)6215796c8dcSSimon Schubert breakpoint_enabled (struct breakpoint *b)
6225796c8dcSSimon Schubert {
6235796c8dcSSimon Schubert   return (b->enable_state == bp_enabled);
6245796c8dcSSimon Schubert }
6255796c8dcSSimon Schubert 
6265796c8dcSSimon Schubert /* Set breakpoint count to NUM.  */
6275796c8dcSSimon Schubert 
628cf7f2e2dSJohn Marino static void
set_breakpoint_count(int num)6295796c8dcSSimon Schubert set_breakpoint_count (int num)
6305796c8dcSSimon Schubert {
631cf7f2e2dSJohn Marino   prev_breakpoint_count = breakpoint_count;
6325796c8dcSSimon Schubert   breakpoint_count = num;
6335796c8dcSSimon Schubert   set_internalvar_integer (lookup_internalvar ("bpnum"), num);
6345796c8dcSSimon Schubert }
6355796c8dcSSimon Schubert 
636cf7f2e2dSJohn Marino /* Used by `start_rbreak_breakpoints' below, to record the current
637cf7f2e2dSJohn Marino    breakpoint count before "rbreak" creates any breakpoint.  */
638cf7f2e2dSJohn Marino static int rbreak_start_breakpoint_count;
639cf7f2e2dSJohn Marino 
640cf7f2e2dSJohn Marino /* Called at the start an "rbreak" command to record the first
641cf7f2e2dSJohn Marino    breakpoint made.  */
642cf7f2e2dSJohn Marino 
643cf7f2e2dSJohn Marino void
start_rbreak_breakpoints(void)644cf7f2e2dSJohn Marino start_rbreak_breakpoints (void)
645cf7f2e2dSJohn Marino {
646cf7f2e2dSJohn Marino   rbreak_start_breakpoint_count = breakpoint_count;
647cf7f2e2dSJohn Marino }
648cf7f2e2dSJohn Marino 
649cf7f2e2dSJohn Marino /* Called at the end of an "rbreak" command to record the last
650cf7f2e2dSJohn Marino    breakpoint made.  */
651cf7f2e2dSJohn Marino 
652cf7f2e2dSJohn Marino void
end_rbreak_breakpoints(void)653cf7f2e2dSJohn Marino end_rbreak_breakpoints (void)
654cf7f2e2dSJohn Marino {
655cf7f2e2dSJohn Marino   prev_breakpoint_count = rbreak_start_breakpoint_count;
656cf7f2e2dSJohn Marino }
657cf7f2e2dSJohn Marino 
6585796c8dcSSimon Schubert /* Used in run_command to zero the hit count when a new run starts.  */
6595796c8dcSSimon Schubert 
6605796c8dcSSimon Schubert void
clear_breakpoint_hit_counts(void)6615796c8dcSSimon Schubert clear_breakpoint_hit_counts (void)
6625796c8dcSSimon Schubert {
6635796c8dcSSimon Schubert   struct breakpoint *b;
6645796c8dcSSimon Schubert 
6655796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
6665796c8dcSSimon Schubert     b->hit_count = 0;
6675796c8dcSSimon Schubert }
6685796c8dcSSimon Schubert 
669cf7f2e2dSJohn Marino /* Allocate a new counted_command_line with reference count of 1.
670cf7f2e2dSJohn Marino    The new structure owns COMMANDS.  */
671cf7f2e2dSJohn Marino 
672cf7f2e2dSJohn Marino static struct counted_command_line *
alloc_counted_command_line(struct command_line * commands)673cf7f2e2dSJohn Marino alloc_counted_command_line (struct command_line *commands)
674cf7f2e2dSJohn Marino {
675cf7f2e2dSJohn Marino   struct counted_command_line *result
676cf7f2e2dSJohn Marino     = xmalloc (sizeof (struct counted_command_line));
677cf7f2e2dSJohn Marino 
678cf7f2e2dSJohn Marino   result->refc = 1;
679cf7f2e2dSJohn Marino   result->commands = commands;
680cf7f2e2dSJohn Marino   return result;
681cf7f2e2dSJohn Marino }
682cf7f2e2dSJohn Marino 
683cf7f2e2dSJohn Marino /* Increment reference count.  This does nothing if CMD is NULL.  */
684cf7f2e2dSJohn Marino 
685cf7f2e2dSJohn Marino static void
incref_counted_command_line(struct counted_command_line * cmd)686cf7f2e2dSJohn Marino incref_counted_command_line (struct counted_command_line *cmd)
687cf7f2e2dSJohn Marino {
688cf7f2e2dSJohn Marino   if (cmd)
689cf7f2e2dSJohn Marino     ++cmd->refc;
690cf7f2e2dSJohn Marino }
691cf7f2e2dSJohn Marino 
692cf7f2e2dSJohn Marino /* Decrement reference count.  If the reference count reaches 0,
693cf7f2e2dSJohn Marino    destroy the counted_command_line.  Sets *CMDP to NULL.  This does
694cf7f2e2dSJohn Marino    nothing if *CMDP is NULL.  */
695cf7f2e2dSJohn Marino 
696cf7f2e2dSJohn Marino static void
decref_counted_command_line(struct counted_command_line ** cmdp)697cf7f2e2dSJohn Marino decref_counted_command_line (struct counted_command_line **cmdp)
698cf7f2e2dSJohn Marino {
699cf7f2e2dSJohn Marino   if (*cmdp)
700cf7f2e2dSJohn Marino     {
701cf7f2e2dSJohn Marino       if (--(*cmdp)->refc == 0)
702cf7f2e2dSJohn Marino 	{
703cf7f2e2dSJohn Marino 	  free_command_lines (&(*cmdp)->commands);
704cf7f2e2dSJohn Marino 	  xfree (*cmdp);
705cf7f2e2dSJohn Marino 	}
706cf7f2e2dSJohn Marino       *cmdp = NULL;
707cf7f2e2dSJohn Marino     }
708cf7f2e2dSJohn Marino }
709cf7f2e2dSJohn Marino 
710cf7f2e2dSJohn Marino /* A cleanup function that calls decref_counted_command_line.  */
711cf7f2e2dSJohn Marino 
712cf7f2e2dSJohn Marino static void
do_cleanup_counted_command_line(void * arg)713cf7f2e2dSJohn Marino do_cleanup_counted_command_line (void *arg)
714cf7f2e2dSJohn Marino {
715cf7f2e2dSJohn Marino   decref_counted_command_line (arg);
716cf7f2e2dSJohn Marino }
717cf7f2e2dSJohn Marino 
718cf7f2e2dSJohn Marino /* Create a cleanup that calls decref_counted_command_line on the
719cf7f2e2dSJohn Marino    argument.  */
720cf7f2e2dSJohn Marino 
721cf7f2e2dSJohn Marino static struct cleanup *
make_cleanup_decref_counted_command_line(struct counted_command_line ** cmdp)722cf7f2e2dSJohn Marino make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
723cf7f2e2dSJohn Marino {
724cf7f2e2dSJohn Marino   return make_cleanup (do_cleanup_counted_command_line, cmdp);
725cf7f2e2dSJohn Marino }
726cf7f2e2dSJohn Marino 
7275796c8dcSSimon Schubert 
7285796c8dcSSimon Schubert /* Return the breakpoint with the specified number, or NULL
7295796c8dcSSimon Schubert    if the number does not refer to an existing breakpoint.  */
7305796c8dcSSimon Schubert 
7315796c8dcSSimon Schubert struct breakpoint *
get_breakpoint(int num)7325796c8dcSSimon Schubert get_breakpoint (int num)
7335796c8dcSSimon Schubert {
7345796c8dcSSimon Schubert   struct breakpoint *b;
7355796c8dcSSimon Schubert 
7365796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
7375796c8dcSSimon Schubert     if (b->number == num)
7385796c8dcSSimon Schubert       return b;
7395796c8dcSSimon Schubert 
7405796c8dcSSimon Schubert   return NULL;
7415796c8dcSSimon Schubert }
7425796c8dcSSimon Schubert 
7435796c8dcSSimon Schubert 
744cf7f2e2dSJohn Marino 
745*ef5ccd6cSJohn Marino /* Mark locations as "conditions have changed" in case the target supports
746*ef5ccd6cSJohn Marino    evaluating conditions on its side.  */
747*ef5ccd6cSJohn Marino 
748*ef5ccd6cSJohn Marino static void
mark_breakpoint_modified(struct breakpoint * b)749*ef5ccd6cSJohn Marino mark_breakpoint_modified (struct breakpoint *b)
750*ef5ccd6cSJohn Marino {
751*ef5ccd6cSJohn Marino   struct bp_location *loc;
752*ef5ccd6cSJohn Marino 
753*ef5ccd6cSJohn Marino   /* This is only meaningful if the target is
754*ef5ccd6cSJohn Marino      evaluating conditions and if the user has
755*ef5ccd6cSJohn Marino      opted for condition evaluation on the target's
756*ef5ccd6cSJohn Marino      side.  */
757*ef5ccd6cSJohn Marino   if (gdb_evaluates_breakpoint_condition_p ()
758*ef5ccd6cSJohn Marino       || !target_supports_evaluation_of_breakpoint_conditions ())
759*ef5ccd6cSJohn Marino     return;
760*ef5ccd6cSJohn Marino 
761*ef5ccd6cSJohn Marino   if (!is_breakpoint (b))
762*ef5ccd6cSJohn Marino     return;
763*ef5ccd6cSJohn Marino 
764*ef5ccd6cSJohn Marino   for (loc = b->loc; loc; loc = loc->next)
765*ef5ccd6cSJohn Marino     loc->condition_changed = condition_modified;
766*ef5ccd6cSJohn Marino }
767*ef5ccd6cSJohn Marino 
768*ef5ccd6cSJohn Marino /* Mark location as "conditions have changed" in case the target supports
769*ef5ccd6cSJohn Marino    evaluating conditions on its side.  */
770*ef5ccd6cSJohn Marino 
771*ef5ccd6cSJohn Marino static void
mark_breakpoint_location_modified(struct bp_location * loc)772*ef5ccd6cSJohn Marino mark_breakpoint_location_modified (struct bp_location *loc)
773*ef5ccd6cSJohn Marino {
774*ef5ccd6cSJohn Marino   /* This is only meaningful if the target is
775*ef5ccd6cSJohn Marino      evaluating conditions and if the user has
776*ef5ccd6cSJohn Marino      opted for condition evaluation on the target's
777*ef5ccd6cSJohn Marino      side.  */
778*ef5ccd6cSJohn Marino   if (gdb_evaluates_breakpoint_condition_p ()
779*ef5ccd6cSJohn Marino       || !target_supports_evaluation_of_breakpoint_conditions ())
780*ef5ccd6cSJohn Marino 
781*ef5ccd6cSJohn Marino     return;
782*ef5ccd6cSJohn Marino 
783*ef5ccd6cSJohn Marino   if (!is_breakpoint (loc->owner))
784*ef5ccd6cSJohn Marino     return;
785*ef5ccd6cSJohn Marino 
786*ef5ccd6cSJohn Marino   loc->condition_changed = condition_modified;
787*ef5ccd6cSJohn Marino }
788*ef5ccd6cSJohn Marino 
789*ef5ccd6cSJohn Marino /* Sets the condition-evaluation mode using the static global
790*ef5ccd6cSJohn Marino    condition_evaluation_mode.  */
791*ef5ccd6cSJohn Marino 
792*ef5ccd6cSJohn Marino static void
set_condition_evaluation_mode(char * args,int from_tty,struct cmd_list_element * c)793*ef5ccd6cSJohn Marino set_condition_evaluation_mode (char *args, int from_tty,
794*ef5ccd6cSJohn Marino 			       struct cmd_list_element *c)
795*ef5ccd6cSJohn Marino {
796*ef5ccd6cSJohn Marino   const char *old_mode, *new_mode;
797*ef5ccd6cSJohn Marino 
798*ef5ccd6cSJohn Marino   if ((condition_evaluation_mode_1 == condition_evaluation_target)
799*ef5ccd6cSJohn Marino       && !target_supports_evaluation_of_breakpoint_conditions ())
800*ef5ccd6cSJohn Marino     {
801*ef5ccd6cSJohn Marino       condition_evaluation_mode_1 = condition_evaluation_mode;
802*ef5ccd6cSJohn Marino       warning (_("Target does not support breakpoint condition evaluation.\n"
803*ef5ccd6cSJohn Marino 		 "Using host evaluation mode instead."));
804*ef5ccd6cSJohn Marino       return;
805*ef5ccd6cSJohn Marino     }
806*ef5ccd6cSJohn Marino 
807*ef5ccd6cSJohn Marino   new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
808*ef5ccd6cSJohn Marino   old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
809*ef5ccd6cSJohn Marino 
810*ef5ccd6cSJohn Marino   /* Flip the switch.  Flip it even if OLD_MODE == NEW_MODE as one of the
811*ef5ccd6cSJohn Marino      settings was "auto".  */
812*ef5ccd6cSJohn Marino   condition_evaluation_mode = condition_evaluation_mode_1;
813*ef5ccd6cSJohn Marino 
814*ef5ccd6cSJohn Marino   /* Only update the mode if the user picked a different one.  */
815*ef5ccd6cSJohn Marino   if (new_mode != old_mode)
816*ef5ccd6cSJohn Marino     {
817*ef5ccd6cSJohn Marino       struct bp_location *loc, **loc_tmp;
818*ef5ccd6cSJohn Marino       /* If the user switched to a different evaluation mode, we
819*ef5ccd6cSJohn Marino 	 need to synch the changes with the target as follows:
820*ef5ccd6cSJohn Marino 
821*ef5ccd6cSJohn Marino 	 "host" -> "target": Send all (valid) conditions to the target.
822*ef5ccd6cSJohn Marino 	 "target" -> "host": Remove all the conditions from the target.
823*ef5ccd6cSJohn Marino       */
824*ef5ccd6cSJohn Marino 
825*ef5ccd6cSJohn Marino       if (new_mode == condition_evaluation_target)
826*ef5ccd6cSJohn Marino 	{
827*ef5ccd6cSJohn Marino 	  /* Mark everything modified and synch conditions with the
828*ef5ccd6cSJohn Marino 	     target.  */
829*ef5ccd6cSJohn Marino 	  ALL_BP_LOCATIONS (loc, loc_tmp)
830*ef5ccd6cSJohn Marino 	    mark_breakpoint_location_modified (loc);
831*ef5ccd6cSJohn Marino   	}
832*ef5ccd6cSJohn Marino       else
833*ef5ccd6cSJohn Marino 	{
834*ef5ccd6cSJohn Marino 	  /* Manually mark non-duplicate locations to synch conditions
835*ef5ccd6cSJohn Marino 	     with the target.  We do this to remove all the conditions the
836*ef5ccd6cSJohn Marino 	     target knows about.  */
837*ef5ccd6cSJohn Marino 	  ALL_BP_LOCATIONS (loc, loc_tmp)
838*ef5ccd6cSJohn Marino 	    if (is_breakpoint (loc->owner) && loc->inserted)
839*ef5ccd6cSJohn Marino 	      loc->needs_update = 1;
840*ef5ccd6cSJohn Marino 	}
841*ef5ccd6cSJohn Marino 
842*ef5ccd6cSJohn Marino       /* Do the update.  */
843*ef5ccd6cSJohn Marino       update_global_location_list (1);
844*ef5ccd6cSJohn Marino     }
845*ef5ccd6cSJohn Marino 
846*ef5ccd6cSJohn Marino   return;
847*ef5ccd6cSJohn Marino }
848*ef5ccd6cSJohn Marino 
849*ef5ccd6cSJohn Marino /* Shows the current mode of breakpoint condition evaluation.  Explicitly shows
850*ef5ccd6cSJohn Marino    what "auto" is translating to.  */
851*ef5ccd6cSJohn Marino 
852*ef5ccd6cSJohn Marino static void
show_condition_evaluation_mode(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)853*ef5ccd6cSJohn Marino show_condition_evaluation_mode (struct ui_file *file, int from_tty,
854*ef5ccd6cSJohn Marino 				struct cmd_list_element *c, const char *value)
855*ef5ccd6cSJohn Marino {
856*ef5ccd6cSJohn Marino   if (condition_evaluation_mode == condition_evaluation_auto)
857*ef5ccd6cSJohn Marino     fprintf_filtered (file,
858*ef5ccd6cSJohn Marino 		      _("Breakpoint condition evaluation "
859*ef5ccd6cSJohn Marino 			"mode is %s (currently %s).\n"),
860*ef5ccd6cSJohn Marino 		      value,
861*ef5ccd6cSJohn Marino 		      breakpoint_condition_evaluation_mode ());
862*ef5ccd6cSJohn Marino   else
863*ef5ccd6cSJohn Marino     fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
864*ef5ccd6cSJohn Marino 		      value);
865*ef5ccd6cSJohn Marino }
866*ef5ccd6cSJohn Marino 
867*ef5ccd6cSJohn Marino /* A comparison function for bp_location AP and BP that is used by
868*ef5ccd6cSJohn Marino    bsearch.  This comparison function only cares about addresses, unlike
869*ef5ccd6cSJohn Marino    the more general bp_location_compare function.  */
870*ef5ccd6cSJohn Marino 
871*ef5ccd6cSJohn Marino static int
bp_location_compare_addrs(const void * ap,const void * bp)872*ef5ccd6cSJohn Marino bp_location_compare_addrs (const void *ap, const void *bp)
873*ef5ccd6cSJohn Marino {
874*ef5ccd6cSJohn Marino   struct bp_location *a = *(void **) ap;
875*ef5ccd6cSJohn Marino   struct bp_location *b = *(void **) bp;
876*ef5ccd6cSJohn Marino 
877*ef5ccd6cSJohn Marino   if (a->address == b->address)
878*ef5ccd6cSJohn Marino     return 0;
879*ef5ccd6cSJohn Marino   else
880*ef5ccd6cSJohn Marino     return ((a->address > b->address) - (a->address < b->address));
881*ef5ccd6cSJohn Marino }
882*ef5ccd6cSJohn Marino 
883*ef5ccd6cSJohn Marino /* Helper function to skip all bp_locations with addresses
884*ef5ccd6cSJohn Marino    less than ADDRESS.  It returns the first bp_location that
885*ef5ccd6cSJohn Marino    is greater than or equal to ADDRESS.  If none is found, just
886*ef5ccd6cSJohn Marino    return NULL.  */
887*ef5ccd6cSJohn Marino 
888*ef5ccd6cSJohn Marino static struct bp_location **
get_first_locp_gte_addr(CORE_ADDR address)889*ef5ccd6cSJohn Marino get_first_locp_gte_addr (CORE_ADDR address)
890*ef5ccd6cSJohn Marino {
891*ef5ccd6cSJohn Marino   struct bp_location dummy_loc;
892*ef5ccd6cSJohn Marino   struct bp_location *dummy_locp = &dummy_loc;
893*ef5ccd6cSJohn Marino   struct bp_location **locp_found = NULL;
894*ef5ccd6cSJohn Marino 
895*ef5ccd6cSJohn Marino   /* Initialize the dummy location's address field.  */
896*ef5ccd6cSJohn Marino   memset (&dummy_loc, 0, sizeof (struct bp_location));
897*ef5ccd6cSJohn Marino   dummy_loc.address = address;
898*ef5ccd6cSJohn Marino 
899*ef5ccd6cSJohn Marino   /* Find a close match to the first location at ADDRESS.  */
900*ef5ccd6cSJohn Marino   locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
901*ef5ccd6cSJohn Marino 			sizeof (struct bp_location **),
902*ef5ccd6cSJohn Marino 			bp_location_compare_addrs);
903*ef5ccd6cSJohn Marino 
904*ef5ccd6cSJohn Marino   /* Nothing was found, nothing left to do.  */
905*ef5ccd6cSJohn Marino   if (locp_found == NULL)
906*ef5ccd6cSJohn Marino     return NULL;
907*ef5ccd6cSJohn Marino 
908*ef5ccd6cSJohn Marino   /* We may have found a location that is at ADDRESS but is not the first in the
909*ef5ccd6cSJohn Marino      location's list.  Go backwards (if possible) and locate the first one.  */
910*ef5ccd6cSJohn Marino   while ((locp_found - 1) >= bp_location
911*ef5ccd6cSJohn Marino 	 && (*(locp_found - 1))->address == address)
912*ef5ccd6cSJohn Marino     locp_found--;
913*ef5ccd6cSJohn Marino 
914*ef5ccd6cSJohn Marino   return locp_found;
915*ef5ccd6cSJohn Marino }
916*ef5ccd6cSJohn Marino 
917cf7f2e2dSJohn Marino void
set_breakpoint_condition(struct breakpoint * b,char * exp,int from_tty)918cf7f2e2dSJohn Marino set_breakpoint_condition (struct breakpoint *b, char *exp,
919cf7f2e2dSJohn Marino 			  int from_tty)
920cf7f2e2dSJohn Marino {
921a45ae5f8SJohn Marino   xfree (b->cond_string);
922a45ae5f8SJohn Marino   b->cond_string = NULL;
923cf7f2e2dSJohn Marino 
924a45ae5f8SJohn Marino   if (is_watchpoint (b))
925a45ae5f8SJohn Marino     {
926a45ae5f8SJohn Marino       struct watchpoint *w = (struct watchpoint *) b;
927a45ae5f8SJohn Marino 
928a45ae5f8SJohn Marino       xfree (w->cond_exp);
929a45ae5f8SJohn Marino       w->cond_exp = NULL;
930a45ae5f8SJohn Marino     }
931a45ae5f8SJohn Marino   else
932a45ae5f8SJohn Marino     {
933a45ae5f8SJohn Marino       struct bp_location *loc;
934a45ae5f8SJohn Marino 
935a45ae5f8SJohn Marino       for (loc = b->loc; loc; loc = loc->next)
936cf7f2e2dSJohn Marino 	{
937cf7f2e2dSJohn Marino 	  xfree (loc->cond);
938cf7f2e2dSJohn Marino 	  loc->cond = NULL;
939*ef5ccd6cSJohn Marino 
940*ef5ccd6cSJohn Marino 	  /* No need to free the condition agent expression
941*ef5ccd6cSJohn Marino 	     bytecode (if we have one).  We will handle this
942*ef5ccd6cSJohn Marino 	     when we go through update_global_location_list.  */
943cf7f2e2dSJohn Marino 	}
944a45ae5f8SJohn Marino     }
945cf7f2e2dSJohn Marino 
946cf7f2e2dSJohn Marino   if (*exp == 0)
947cf7f2e2dSJohn Marino     {
948cf7f2e2dSJohn Marino       if (from_tty)
949cf7f2e2dSJohn Marino 	printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
950cf7f2e2dSJohn Marino     }
951cf7f2e2dSJohn Marino   else
952cf7f2e2dSJohn Marino     {
953*ef5ccd6cSJohn Marino       const char *arg = exp;
954cf7f2e2dSJohn Marino 
955cf7f2e2dSJohn Marino       /* I don't know if it matters whether this is the string the user
956cf7f2e2dSJohn Marino 	 typed in or the decompiled expression.  */
957cf7f2e2dSJohn Marino       b->cond_string = xstrdup (arg);
958cf7f2e2dSJohn Marino       b->condition_not_parsed = 0;
959cf7f2e2dSJohn Marino 
960cf7f2e2dSJohn Marino       if (is_watchpoint (b))
961cf7f2e2dSJohn Marino 	{
962a45ae5f8SJohn Marino 	  struct watchpoint *w = (struct watchpoint *) b;
963a45ae5f8SJohn Marino 
964cf7f2e2dSJohn Marino 	  innermost_block = NULL;
965cf7f2e2dSJohn Marino 	  arg = exp;
966*ef5ccd6cSJohn Marino 	  w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
967cf7f2e2dSJohn Marino 	  if (*arg)
968cf7f2e2dSJohn Marino 	    error (_("Junk at end of expression"));
969a45ae5f8SJohn Marino 	  w->cond_exp_valid_block = innermost_block;
970cf7f2e2dSJohn Marino 	}
971cf7f2e2dSJohn Marino       else
972cf7f2e2dSJohn Marino 	{
973a45ae5f8SJohn Marino 	  struct bp_location *loc;
974a45ae5f8SJohn Marino 
975cf7f2e2dSJohn Marino 	  for (loc = b->loc; loc; loc = loc->next)
976cf7f2e2dSJohn Marino 	    {
977cf7f2e2dSJohn Marino 	      arg = exp;
978cf7f2e2dSJohn Marino 	      loc->cond =
979*ef5ccd6cSJohn Marino 		parse_exp_1 (&arg, loc->address,
980*ef5ccd6cSJohn Marino 			     block_for_pc (loc->address), 0);
981cf7f2e2dSJohn Marino 	      if (*arg)
982cf7f2e2dSJohn Marino 		error (_("Junk at end of expression"));
983cf7f2e2dSJohn Marino 	    }
984cf7f2e2dSJohn Marino 	}
985cf7f2e2dSJohn Marino     }
986*ef5ccd6cSJohn Marino   mark_breakpoint_modified (b);
987*ef5ccd6cSJohn Marino 
988a45ae5f8SJohn Marino   observer_notify_breakpoint_modified (b);
989cf7f2e2dSJohn Marino }
990cf7f2e2dSJohn Marino 
991*ef5ccd6cSJohn Marino /* Completion for the "condition" command.  */
992*ef5ccd6cSJohn Marino 
VEC(char_ptr)993*ef5ccd6cSJohn Marino static VEC (char_ptr) *
994*ef5ccd6cSJohn Marino condition_completer (struct cmd_list_element *cmd, char *text, char *word)
995*ef5ccd6cSJohn Marino {
996*ef5ccd6cSJohn Marino   char *space;
997*ef5ccd6cSJohn Marino 
998*ef5ccd6cSJohn Marino   text = skip_spaces (text);
999*ef5ccd6cSJohn Marino   space = skip_to_space (text);
1000*ef5ccd6cSJohn Marino   if (*space == '\0')
1001*ef5ccd6cSJohn Marino     {
1002*ef5ccd6cSJohn Marino       int len;
1003*ef5ccd6cSJohn Marino       struct breakpoint *b;
1004*ef5ccd6cSJohn Marino       VEC (char_ptr) *result = NULL;
1005*ef5ccd6cSJohn Marino 
1006*ef5ccd6cSJohn Marino       if (text[0] == '$')
1007*ef5ccd6cSJohn Marino 	{
1008*ef5ccd6cSJohn Marino 	  /* We don't support completion of history indices.  */
1009*ef5ccd6cSJohn Marino 	  if (isdigit (text[1]))
1010*ef5ccd6cSJohn Marino 	    return NULL;
1011*ef5ccd6cSJohn Marino 	  return complete_internalvar (&text[1]);
1012*ef5ccd6cSJohn Marino 	}
1013*ef5ccd6cSJohn Marino 
1014*ef5ccd6cSJohn Marino       /* We're completing the breakpoint number.  */
1015*ef5ccd6cSJohn Marino       len = strlen (text);
1016*ef5ccd6cSJohn Marino 
1017*ef5ccd6cSJohn Marino       ALL_BREAKPOINTS (b)
1018*ef5ccd6cSJohn Marino 	{
1019*ef5ccd6cSJohn Marino 	  char number[50];
1020*ef5ccd6cSJohn Marino 
1021*ef5ccd6cSJohn Marino 	  xsnprintf (number, sizeof (number), "%d", b->number);
1022*ef5ccd6cSJohn Marino 
1023*ef5ccd6cSJohn Marino 	  if (strncmp (number, text, len) == 0)
1024*ef5ccd6cSJohn Marino 	    VEC_safe_push (char_ptr, result, xstrdup (number));
1025*ef5ccd6cSJohn Marino 	}
1026*ef5ccd6cSJohn Marino 
1027*ef5ccd6cSJohn Marino       return result;
1028*ef5ccd6cSJohn Marino     }
1029*ef5ccd6cSJohn Marino 
1030*ef5ccd6cSJohn Marino   /* We're completing the expression part.  */
1031*ef5ccd6cSJohn Marino   text = skip_spaces (space);
1032*ef5ccd6cSJohn Marino   return expression_completer (cmd, text, word);
1033*ef5ccd6cSJohn Marino }
1034*ef5ccd6cSJohn Marino 
10355796c8dcSSimon Schubert /* condition N EXP -- set break condition of breakpoint N to EXP.  */
10365796c8dcSSimon Schubert 
10375796c8dcSSimon Schubert static void
condition_command(char * arg,int from_tty)10385796c8dcSSimon Schubert condition_command (char *arg, int from_tty)
10395796c8dcSSimon Schubert {
10405796c8dcSSimon Schubert   struct breakpoint *b;
10415796c8dcSSimon Schubert   char *p;
10425796c8dcSSimon Schubert   int bnum;
10435796c8dcSSimon Schubert 
10445796c8dcSSimon Schubert   if (arg == 0)
10455796c8dcSSimon Schubert     error_no_arg (_("breakpoint number"));
10465796c8dcSSimon Schubert 
10475796c8dcSSimon Schubert   p = arg;
10485796c8dcSSimon Schubert   bnum = get_number (&p);
10495796c8dcSSimon Schubert   if (bnum == 0)
10505796c8dcSSimon Schubert     error (_("Bad breakpoint argument: '%s'"), arg);
10515796c8dcSSimon Schubert 
10525796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
10535796c8dcSSimon Schubert     if (b->number == bnum)
10545796c8dcSSimon Schubert       {
1055c50c785cSJohn Marino 	/* Check if this breakpoint has a Python object assigned to
1056c50c785cSJohn Marino 	   it, and if it has a definition of the "stop"
1057c50c785cSJohn Marino 	   method.  This method and conditions entered into GDB from
1058c50c785cSJohn Marino 	   the CLI are mutually exclusive.  */
1059c50c785cSJohn Marino 	if (b->py_bp_object
1060c50c785cSJohn Marino 	    && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
1061c50c785cSJohn Marino 	  error (_("Cannot set a condition where a Python 'stop' "
1062c50c785cSJohn Marino 		   "method has been defined in the breakpoint."));
1063cf7f2e2dSJohn Marino 	set_breakpoint_condition (b, p, from_tty);
1064*ef5ccd6cSJohn Marino 
1065*ef5ccd6cSJohn Marino 	if (is_breakpoint (b))
1066*ef5ccd6cSJohn Marino 	  update_global_location_list (1);
1067*ef5ccd6cSJohn Marino 
10685796c8dcSSimon Schubert 	return;
10695796c8dcSSimon Schubert       }
10705796c8dcSSimon Schubert 
10715796c8dcSSimon Schubert   error (_("No breakpoint number %d."), bnum);
10725796c8dcSSimon Schubert }
10735796c8dcSSimon Schubert 
1074cf7f2e2dSJohn Marino /* Check that COMMAND do not contain commands that are suitable
1075cf7f2e2dSJohn Marino    only for tracepoints and not suitable for ordinary breakpoints.
1076c50c785cSJohn Marino    Throw if any such commands is found.  */
1077c50c785cSJohn Marino 
1078cf7f2e2dSJohn Marino static void
check_no_tracepoint_commands(struct command_line * commands)1079cf7f2e2dSJohn Marino check_no_tracepoint_commands (struct command_line *commands)
1080cf7f2e2dSJohn Marino {
1081cf7f2e2dSJohn Marino   struct command_line *c;
1082cf7f2e2dSJohn Marino 
1083cf7f2e2dSJohn Marino   for (c = commands; c; c = c->next)
1084cf7f2e2dSJohn Marino     {
1085cf7f2e2dSJohn Marino       int i;
1086cf7f2e2dSJohn Marino 
1087cf7f2e2dSJohn Marino       if (c->control_type == while_stepping_control)
1088c50c785cSJohn Marino 	error (_("The 'while-stepping' command can "
1089c50c785cSJohn Marino 		 "only be used for tracepoints"));
1090cf7f2e2dSJohn Marino 
1091cf7f2e2dSJohn Marino       for (i = 0; i < c->body_count; ++i)
1092cf7f2e2dSJohn Marino 	check_no_tracepoint_commands ((c->body_list)[i]);
1093cf7f2e2dSJohn Marino 
1094cf7f2e2dSJohn Marino       /* Not that command parsing removes leading whitespace and comment
1095cf7f2e2dSJohn Marino 	 lines and also empty lines.  So, we only need to check for
1096cf7f2e2dSJohn Marino 	 command directly.  */
1097cf7f2e2dSJohn Marino       if (strstr (c->line, "collect ") == c->line)
1098cf7f2e2dSJohn Marino 	error (_("The 'collect' command can only be used for tracepoints"));
1099cf7f2e2dSJohn Marino 
1100cf7f2e2dSJohn Marino       if (strstr (c->line, "teval ") == c->line)
1101cf7f2e2dSJohn Marino 	error (_("The 'teval' command can only be used for tracepoints"));
1102cf7f2e2dSJohn Marino     }
1103cf7f2e2dSJohn Marino }
1104cf7f2e2dSJohn Marino 
1105cf7f2e2dSJohn Marino /* Encapsulate tests for different types of tracepoints.  */
1106cf7f2e2dSJohn Marino 
1107a45ae5f8SJohn Marino static int
is_tracepoint_type(enum bptype type)1108a45ae5f8SJohn Marino is_tracepoint_type (enum bptype type)
1109a45ae5f8SJohn Marino {
1110a45ae5f8SJohn Marino   return (type == bp_tracepoint
1111a45ae5f8SJohn Marino 	  || type == bp_fast_tracepoint
1112a45ae5f8SJohn Marino 	  || type == bp_static_tracepoint);
1113a45ae5f8SJohn Marino }
1114a45ae5f8SJohn Marino 
1115cf7f2e2dSJohn Marino int
is_tracepoint(const struct breakpoint * b)1116cf7f2e2dSJohn Marino is_tracepoint (const struct breakpoint *b)
1117cf7f2e2dSJohn Marino {
1118a45ae5f8SJohn Marino   return is_tracepoint_type (b->type);
1119cf7f2e2dSJohn Marino }
1120cf7f2e2dSJohn Marino 
1121a45ae5f8SJohn Marino /* A helper function that validates that COMMANDS are valid for a
1122cf7f2e2dSJohn Marino    breakpoint.  This function will throw an exception if a problem is
1123cf7f2e2dSJohn Marino    found.  */
1124cf7f2e2dSJohn Marino 
1125cf7f2e2dSJohn Marino static void
validate_commands_for_breakpoint(struct breakpoint * b,struct command_line * commands)1126cf7f2e2dSJohn Marino validate_commands_for_breakpoint (struct breakpoint *b,
1127cf7f2e2dSJohn Marino 				  struct command_line *commands)
1128cf7f2e2dSJohn Marino {
1129cf7f2e2dSJohn Marino   if (is_tracepoint (b))
1130cf7f2e2dSJohn Marino     {
1131*ef5ccd6cSJohn Marino       struct tracepoint *t = (struct tracepoint *) b;
1132cf7f2e2dSJohn Marino       struct command_line *c;
1133cf7f2e2dSJohn Marino       struct command_line *while_stepping = 0;
1134*ef5ccd6cSJohn Marino 
1135*ef5ccd6cSJohn Marino       /* Reset the while-stepping step count.  The previous commands
1136*ef5ccd6cSJohn Marino          might have included a while-stepping action, while the new
1137*ef5ccd6cSJohn Marino          ones might not.  */
1138*ef5ccd6cSJohn Marino       t->step_count = 0;
1139*ef5ccd6cSJohn Marino 
1140*ef5ccd6cSJohn Marino       /* We need to verify that each top-level element of commands is
1141*ef5ccd6cSJohn Marino 	 valid for tracepoints, that there's at most one
1142*ef5ccd6cSJohn Marino 	 while-stepping element, and that the while-stepping's body
1143*ef5ccd6cSJohn Marino 	 has valid tracing commands excluding nested while-stepping.
1144*ef5ccd6cSJohn Marino 	 We also need to validate the tracepoint action line in the
1145*ef5ccd6cSJohn Marino 	 context of the tracepoint --- validate_actionline actually
1146*ef5ccd6cSJohn Marino 	 has side effects, like setting the tracepoint's
1147*ef5ccd6cSJohn Marino 	 while-stepping STEP_COUNT, in addition to checking if the
1148*ef5ccd6cSJohn Marino 	 collect/teval actions parse and make sense in the
1149*ef5ccd6cSJohn Marino 	 tracepoint's context.  */
1150cf7f2e2dSJohn Marino       for (c = commands; c; c = c->next)
1151cf7f2e2dSJohn Marino 	{
1152cf7f2e2dSJohn Marino 	  if (c->control_type == while_stepping_control)
1153cf7f2e2dSJohn Marino 	    {
1154cf7f2e2dSJohn Marino 	      if (b->type == bp_fast_tracepoint)
1155c50c785cSJohn Marino 		error (_("The 'while-stepping' command "
1156c50c785cSJohn Marino 			 "cannot be used for fast tracepoint"));
1157cf7f2e2dSJohn Marino 	      else if (b->type == bp_static_tracepoint)
1158c50c785cSJohn Marino 		error (_("The 'while-stepping' command "
1159c50c785cSJohn Marino 			 "cannot be used for static tracepoint"));
1160cf7f2e2dSJohn Marino 
1161cf7f2e2dSJohn Marino 	      if (while_stepping)
1162c50c785cSJohn Marino 		error (_("The 'while-stepping' command "
1163c50c785cSJohn Marino 			 "can be used only once"));
1164cf7f2e2dSJohn Marino 	      else
1165cf7f2e2dSJohn Marino 		while_stepping = c;
1166cf7f2e2dSJohn Marino 	    }
1167*ef5ccd6cSJohn Marino 
1168*ef5ccd6cSJohn Marino 	  validate_actionline (&c->line, b);
1169cf7f2e2dSJohn Marino 	}
1170cf7f2e2dSJohn Marino       if (while_stepping)
1171cf7f2e2dSJohn Marino 	{
1172cf7f2e2dSJohn Marino 	  struct command_line *c2;
1173cf7f2e2dSJohn Marino 
1174cf7f2e2dSJohn Marino 	  gdb_assert (while_stepping->body_count == 1);
1175cf7f2e2dSJohn Marino 	  c2 = while_stepping->body_list[0];
1176cf7f2e2dSJohn Marino 	  for (; c2; c2 = c2->next)
1177cf7f2e2dSJohn Marino 	    {
1178cf7f2e2dSJohn Marino 	      if (c2->control_type == while_stepping_control)
1179cf7f2e2dSJohn Marino 		error (_("The 'while-stepping' command cannot be nested"));
1180cf7f2e2dSJohn Marino 	    }
1181cf7f2e2dSJohn Marino 	}
1182cf7f2e2dSJohn Marino     }
1183cf7f2e2dSJohn Marino   else
1184cf7f2e2dSJohn Marino     {
1185cf7f2e2dSJohn Marino       check_no_tracepoint_commands (commands);
1186cf7f2e2dSJohn Marino     }
1187cf7f2e2dSJohn Marino }
1188cf7f2e2dSJohn Marino 
1189cf7f2e2dSJohn Marino /* Return a vector of all the static tracepoints set at ADDR.  The
1190cf7f2e2dSJohn Marino    caller is responsible for releasing the vector.  */
1191cf7f2e2dSJohn Marino 
VEC(breakpoint_p)1192cf7f2e2dSJohn Marino VEC(breakpoint_p) *
1193cf7f2e2dSJohn Marino static_tracepoints_here (CORE_ADDR addr)
1194cf7f2e2dSJohn Marino {
1195cf7f2e2dSJohn Marino   struct breakpoint *b;
1196cf7f2e2dSJohn Marino   VEC(breakpoint_p) *found = 0;
1197cf7f2e2dSJohn Marino   struct bp_location *loc;
1198cf7f2e2dSJohn Marino 
1199cf7f2e2dSJohn Marino   ALL_BREAKPOINTS (b)
1200cf7f2e2dSJohn Marino     if (b->type == bp_static_tracepoint)
1201cf7f2e2dSJohn Marino       {
1202cf7f2e2dSJohn Marino 	for (loc = b->loc; loc; loc = loc->next)
1203cf7f2e2dSJohn Marino 	  if (loc->address == addr)
1204cf7f2e2dSJohn Marino 	    VEC_safe_push(breakpoint_p, found, b);
1205cf7f2e2dSJohn Marino       }
1206cf7f2e2dSJohn Marino 
1207cf7f2e2dSJohn Marino   return found;
1208cf7f2e2dSJohn Marino }
1209cf7f2e2dSJohn Marino 
1210cf7f2e2dSJohn Marino /* Set the command list of B to COMMANDS.  If breakpoint is tracepoint,
1211c50c785cSJohn Marino    validate that only allowed commands are included.  */
12125796c8dcSSimon Schubert 
12135796c8dcSSimon Schubert void
breakpoint_set_commands(struct breakpoint * b,struct command_line * commands)1214c50c785cSJohn Marino breakpoint_set_commands (struct breakpoint *b,
1215c50c785cSJohn Marino 			 struct command_line *commands)
12165796c8dcSSimon Schubert {
1217cf7f2e2dSJohn Marino   validate_commands_for_breakpoint (b, commands);
1218cf7f2e2dSJohn Marino 
1219cf7f2e2dSJohn Marino   decref_counted_command_line (&b->commands);
1220cf7f2e2dSJohn Marino   b->commands = alloc_counted_command_line (commands);
1221a45ae5f8SJohn Marino   observer_notify_breakpoint_modified (b);
12225796c8dcSSimon Schubert }
12235796c8dcSSimon Schubert 
1224c50c785cSJohn Marino /* Set the internal `silent' flag on the breakpoint.  Note that this
1225c50c785cSJohn Marino    is not the same as the "silent" that may appear in the breakpoint's
1226c50c785cSJohn Marino    commands.  */
1227c50c785cSJohn Marino 
1228c50c785cSJohn Marino void
breakpoint_set_silent(struct breakpoint * b,int silent)1229c50c785cSJohn Marino breakpoint_set_silent (struct breakpoint *b, int silent)
1230c50c785cSJohn Marino {
1231c50c785cSJohn Marino   int old_silent = b->silent;
1232c50c785cSJohn Marino 
1233c50c785cSJohn Marino   b->silent = silent;
1234c50c785cSJohn Marino   if (old_silent != silent)
1235a45ae5f8SJohn Marino     observer_notify_breakpoint_modified (b);
1236c50c785cSJohn Marino }
1237c50c785cSJohn Marino 
1238c50c785cSJohn Marino /* Set the thread for this breakpoint.  If THREAD is -1, make the
1239c50c785cSJohn Marino    breakpoint work for any thread.  */
1240c50c785cSJohn Marino 
1241c50c785cSJohn Marino void
breakpoint_set_thread(struct breakpoint * b,int thread)1242c50c785cSJohn Marino breakpoint_set_thread (struct breakpoint *b, int thread)
1243c50c785cSJohn Marino {
1244c50c785cSJohn Marino   int old_thread = b->thread;
1245c50c785cSJohn Marino 
1246c50c785cSJohn Marino   b->thread = thread;
1247c50c785cSJohn Marino   if (old_thread != thread)
1248a45ae5f8SJohn Marino     observer_notify_breakpoint_modified (b);
1249c50c785cSJohn Marino }
1250c50c785cSJohn Marino 
1251c50c785cSJohn Marino /* Set the task for this breakpoint.  If TASK is 0, make the
1252c50c785cSJohn Marino    breakpoint work for any task.  */
1253c50c785cSJohn Marino 
1254c50c785cSJohn Marino void
breakpoint_set_task(struct breakpoint * b,int task)1255c50c785cSJohn Marino breakpoint_set_task (struct breakpoint *b, int task)
1256c50c785cSJohn Marino {
1257c50c785cSJohn Marino   int old_task = b->task;
1258c50c785cSJohn Marino 
1259c50c785cSJohn Marino   b->task = task;
1260c50c785cSJohn Marino   if (old_task != task)
1261a45ae5f8SJohn Marino     observer_notify_breakpoint_modified (b);
1262c50c785cSJohn Marino }
1263c50c785cSJohn Marino 
1264cf7f2e2dSJohn Marino void
check_tracepoint_command(char * line,void * closure)1265cf7f2e2dSJohn Marino check_tracepoint_command (char *line, void *closure)
1266cf7f2e2dSJohn Marino {
1267cf7f2e2dSJohn Marino   struct breakpoint *b = closure;
1268cf7f2e2dSJohn Marino 
1269cf7f2e2dSJohn Marino   validate_actionline (&line, b);
1270cf7f2e2dSJohn Marino }
1271cf7f2e2dSJohn Marino 
1272cf7f2e2dSJohn Marino /* A structure used to pass information through
1273cf7f2e2dSJohn Marino    map_breakpoint_numbers.  */
1274cf7f2e2dSJohn Marino 
1275cf7f2e2dSJohn Marino struct commands_info
1276cf7f2e2dSJohn Marino {
1277cf7f2e2dSJohn Marino   /* True if the command was typed at a tty.  */
1278cf7f2e2dSJohn Marino   int from_tty;
1279cf7f2e2dSJohn Marino 
1280cf7f2e2dSJohn Marino   /* The breakpoint range spec.  */
1281cf7f2e2dSJohn Marino   char *arg;
1282cf7f2e2dSJohn Marino 
1283cf7f2e2dSJohn Marino   /* Non-NULL if the body of the commands are being read from this
1284cf7f2e2dSJohn Marino      already-parsed command.  */
1285cf7f2e2dSJohn Marino   struct command_line *control;
1286cf7f2e2dSJohn Marino 
1287cf7f2e2dSJohn Marino   /* The command lines read from the user, or NULL if they have not
1288cf7f2e2dSJohn Marino      yet been read.  */
1289cf7f2e2dSJohn Marino   struct counted_command_line *cmd;
1290cf7f2e2dSJohn Marino };
1291cf7f2e2dSJohn Marino 
1292cf7f2e2dSJohn Marino /* A callback for map_breakpoint_numbers that sets the commands for
1293cf7f2e2dSJohn Marino    commands_command.  */
1294cf7f2e2dSJohn Marino 
1295cf7f2e2dSJohn Marino static void
do_map_commands_command(struct breakpoint * b,void * data)1296cf7f2e2dSJohn Marino do_map_commands_command (struct breakpoint *b, void *data)
1297cf7f2e2dSJohn Marino {
1298cf7f2e2dSJohn Marino   struct commands_info *info = data;
1299cf7f2e2dSJohn Marino 
1300cf7f2e2dSJohn Marino   if (info->cmd == NULL)
1301cf7f2e2dSJohn Marino     {
1302cf7f2e2dSJohn Marino       struct command_line *l;
1303cf7f2e2dSJohn Marino 
1304cf7f2e2dSJohn Marino       if (info->control != NULL)
1305cf7f2e2dSJohn Marino 	l = copy_command_lines (info->control->body_list[0]);
1306cf7f2e2dSJohn Marino       else
1307cf7f2e2dSJohn Marino 	{
1308cf7f2e2dSJohn Marino 	  struct cleanup *old_chain;
1309cf7f2e2dSJohn Marino 	  char *str;
1310cf7f2e2dSJohn Marino 
1311c50c785cSJohn Marino 	  str = xstrprintf (_("Type commands for breakpoint(s) "
1312c50c785cSJohn Marino 			      "%s, one per line."),
1313cf7f2e2dSJohn Marino 			    info->arg);
1314cf7f2e2dSJohn Marino 
1315cf7f2e2dSJohn Marino 	  old_chain = make_cleanup (xfree, str);
1316cf7f2e2dSJohn Marino 
1317cf7f2e2dSJohn Marino 	  l = read_command_lines (str,
1318cf7f2e2dSJohn Marino 				  info->from_tty, 1,
1319cf7f2e2dSJohn Marino 				  (is_tracepoint (b)
1320cf7f2e2dSJohn Marino 				   ? check_tracepoint_command : 0),
1321cf7f2e2dSJohn Marino 				  b);
1322cf7f2e2dSJohn Marino 
1323cf7f2e2dSJohn Marino 	  do_cleanups (old_chain);
1324cf7f2e2dSJohn Marino 	}
1325cf7f2e2dSJohn Marino 
1326cf7f2e2dSJohn Marino       info->cmd = alloc_counted_command_line (l);
1327cf7f2e2dSJohn Marino     }
1328cf7f2e2dSJohn Marino 
1329cf7f2e2dSJohn Marino   /* If a breakpoint was on the list more than once, we don't need to
1330cf7f2e2dSJohn Marino      do anything.  */
1331cf7f2e2dSJohn Marino   if (b->commands != info->cmd)
1332cf7f2e2dSJohn Marino     {
1333cf7f2e2dSJohn Marino       validate_commands_for_breakpoint (b, info->cmd->commands);
1334cf7f2e2dSJohn Marino       incref_counted_command_line (info->cmd);
1335cf7f2e2dSJohn Marino       decref_counted_command_line (&b->commands);
1336cf7f2e2dSJohn Marino       b->commands = info->cmd;
1337a45ae5f8SJohn Marino       observer_notify_breakpoint_modified (b);
1338cf7f2e2dSJohn Marino     }
1339cf7f2e2dSJohn Marino }
1340cf7f2e2dSJohn Marino 
1341cf7f2e2dSJohn Marino static void
commands_command_1(char * arg,int from_tty,struct command_line * control)1342c50c785cSJohn Marino commands_command_1 (char *arg, int from_tty,
1343c50c785cSJohn Marino 		    struct command_line *control)
1344cf7f2e2dSJohn Marino {
1345cf7f2e2dSJohn Marino   struct cleanup *cleanups;
1346cf7f2e2dSJohn Marino   struct commands_info info;
1347cf7f2e2dSJohn Marino 
1348cf7f2e2dSJohn Marino   info.from_tty = from_tty;
1349cf7f2e2dSJohn Marino   info.control = control;
1350cf7f2e2dSJohn Marino   info.cmd = NULL;
1351cf7f2e2dSJohn Marino   /* If we read command lines from the user, then `info' will hold an
1352cf7f2e2dSJohn Marino      extra reference to the commands that we must clean up.  */
1353cf7f2e2dSJohn Marino   cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1354cf7f2e2dSJohn Marino 
1355cf7f2e2dSJohn Marino   if (arg == NULL || !*arg)
1356cf7f2e2dSJohn Marino     {
1357cf7f2e2dSJohn Marino       if (breakpoint_count - prev_breakpoint_count > 1)
1358c50c785cSJohn Marino 	arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1359c50c785cSJohn Marino 			  breakpoint_count);
1360cf7f2e2dSJohn Marino       else if (breakpoint_count > 0)
1361cf7f2e2dSJohn Marino 	arg = xstrprintf ("%d", breakpoint_count);
1362cf7f2e2dSJohn Marino       else
1363cf7f2e2dSJohn Marino 	{
1364cf7f2e2dSJohn Marino 	  /* So that we don't try to free the incoming non-NULL
1365cf7f2e2dSJohn Marino 	     argument in the cleanup below.  Mapping breakpoint
1366cf7f2e2dSJohn Marino 	     numbers will fail in this case.  */
1367cf7f2e2dSJohn Marino 	  arg = NULL;
1368cf7f2e2dSJohn Marino 	}
1369cf7f2e2dSJohn Marino     }
1370cf7f2e2dSJohn Marino   else
1371cf7f2e2dSJohn Marino     /* The command loop has some static state, so we need to preserve
1372cf7f2e2dSJohn Marino        our argument.  */
1373cf7f2e2dSJohn Marino     arg = xstrdup (arg);
1374cf7f2e2dSJohn Marino 
1375cf7f2e2dSJohn Marino   if (arg != NULL)
1376cf7f2e2dSJohn Marino     make_cleanup (xfree, arg);
1377cf7f2e2dSJohn Marino 
1378cf7f2e2dSJohn Marino   info.arg = arg;
1379cf7f2e2dSJohn Marino 
1380cf7f2e2dSJohn Marino   map_breakpoint_numbers (arg, do_map_commands_command, &info);
1381cf7f2e2dSJohn Marino 
1382cf7f2e2dSJohn Marino   if (info.cmd == NULL)
1383cf7f2e2dSJohn Marino     error (_("No breakpoints specified."));
1384cf7f2e2dSJohn Marino 
1385cf7f2e2dSJohn Marino   do_cleanups (cleanups);
1386cf7f2e2dSJohn Marino }
1387cf7f2e2dSJohn Marino 
13885796c8dcSSimon Schubert static void
commands_command(char * arg,int from_tty)13895796c8dcSSimon Schubert commands_command (char *arg, int from_tty)
13905796c8dcSSimon Schubert {
1391cf7f2e2dSJohn Marino   commands_command_1 (arg, from_tty, NULL);
13925796c8dcSSimon Schubert }
13935796c8dcSSimon Schubert 
13945796c8dcSSimon Schubert /* Like commands_command, but instead of reading the commands from
13955796c8dcSSimon Schubert    input stream, takes them from an already parsed command structure.
13965796c8dcSSimon Schubert 
13975796c8dcSSimon Schubert    This is used by cli-script.c to DTRT with breakpoint commands
13985796c8dcSSimon Schubert    that are part of if and while bodies.  */
13995796c8dcSSimon Schubert enum command_control_type
commands_from_control_command(char * arg,struct command_line * cmd)14005796c8dcSSimon Schubert commands_from_control_command (char *arg, struct command_line *cmd)
14015796c8dcSSimon Schubert {
1402cf7f2e2dSJohn Marino   commands_command_1 (arg, 0, cmd);
14035796c8dcSSimon Schubert   return simple_control;
14045796c8dcSSimon Schubert }
1405cf7f2e2dSJohn Marino 
1406cf7f2e2dSJohn Marino /* Return non-zero if BL->TARGET_INFO contains valid information.  */
1407cf7f2e2dSJohn Marino 
1408cf7f2e2dSJohn Marino static int
bp_location_has_shadow(struct bp_location * bl)1409cf7f2e2dSJohn Marino bp_location_has_shadow (struct bp_location *bl)
1410cf7f2e2dSJohn Marino {
1411cf7f2e2dSJohn Marino   if (bl->loc_type != bp_loc_software_breakpoint)
1412cf7f2e2dSJohn Marino     return 0;
1413cf7f2e2dSJohn Marino   if (!bl->inserted)
1414cf7f2e2dSJohn Marino     return 0;
1415cf7f2e2dSJohn Marino   if (bl->target_info.shadow_len == 0)
1416a45ae5f8SJohn Marino     /* BL isn't valid, or doesn't shadow memory.  */
1417cf7f2e2dSJohn Marino     return 0;
1418cf7f2e2dSJohn Marino   return 1;
14195796c8dcSSimon Schubert }
1420cf7f2e2dSJohn Marino 
14215796c8dcSSimon Schubert /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1422cf7f2e2dSJohn Marino    by replacing any memory breakpoints with their shadowed contents.
1423cf7f2e2dSJohn Marino 
1424*ef5ccd6cSJohn Marino    If READBUF is not NULL, this buffer must not overlap with any of
1425*ef5ccd6cSJohn Marino    the breakpoint location's shadow_contents buffers.  Otherwise,
1426*ef5ccd6cSJohn Marino    a failed assertion internal error will be raised.
1427*ef5ccd6cSJohn Marino 
1428cf7f2e2dSJohn Marino    The range of shadowed area by each bp_location is:
1429c50c785cSJohn Marino      bl->address - bp_location_placed_address_before_address_max
1430c50c785cSJohn Marino      up to bl->address + bp_location_shadow_len_after_address_max
1431cf7f2e2dSJohn Marino    The range we were requested to resolve shadows for is:
1432cf7f2e2dSJohn Marino      memaddr ... memaddr + len
1433cf7f2e2dSJohn Marino    Thus the safe cutoff boundaries for performance optimization are
1434c50c785cSJohn Marino      memaddr + len <= (bl->address
1435c50c785cSJohn Marino 		       - bp_location_placed_address_before_address_max)
1436cf7f2e2dSJohn Marino    and:
1437c50c785cSJohn Marino      bl->address + bp_location_shadow_len_after_address_max <= memaddr  */
14385796c8dcSSimon Schubert 
14395796c8dcSSimon Schubert void
breakpoint_xfer_memory(gdb_byte * readbuf,gdb_byte * writebuf,const gdb_byte * writebuf_org,ULONGEST memaddr,LONGEST len)1440a45ae5f8SJohn Marino breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1441a45ae5f8SJohn Marino 			const gdb_byte *writebuf_org,
1442a45ae5f8SJohn Marino 			ULONGEST memaddr, LONGEST len)
14435796c8dcSSimon Schubert {
1444c50c785cSJohn Marino   /* Left boundary, right boundary and median element of our binary
1445c50c785cSJohn Marino      search.  */
1446cf7f2e2dSJohn Marino   unsigned bc_l, bc_r, bc;
1447cf7f2e2dSJohn Marino 
1448c50c785cSJohn Marino   /* Find BC_L which is a leftmost element which may affect BUF
1449c50c785cSJohn Marino      content.  It is safe to report lower value but a failure to
1450c50c785cSJohn Marino      report higher one.  */
1451cf7f2e2dSJohn Marino 
1452cf7f2e2dSJohn Marino   bc_l = 0;
1453cf7f2e2dSJohn Marino   bc_r = bp_location_count;
1454cf7f2e2dSJohn Marino   while (bc_l + 1 < bc_r)
1455cf7f2e2dSJohn Marino     {
1456c50c785cSJohn Marino       struct bp_location *bl;
1457cf7f2e2dSJohn Marino 
1458cf7f2e2dSJohn Marino       bc = (bc_l + bc_r) / 2;
1459c50c785cSJohn Marino       bl = bp_location[bc];
1460cf7f2e2dSJohn Marino 
1461c50c785cSJohn Marino       /* Check first BL->ADDRESS will not overflow due to the added
1462c50c785cSJohn Marino 	 constant.  Then advance the left boundary only if we are sure
1463c50c785cSJohn Marino 	 the BC element can in no way affect the BUF content (MEMADDR
1464c50c785cSJohn Marino 	 to MEMADDR + LEN range).
1465cf7f2e2dSJohn Marino 
1466c50c785cSJohn Marino 	 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1467c50c785cSJohn Marino 	 offset so that we cannot miss a breakpoint with its shadow
1468c50c785cSJohn Marino 	 range tail still reaching MEMADDR.  */
1469cf7f2e2dSJohn Marino 
1470c50c785cSJohn Marino       if ((bl->address + bp_location_shadow_len_after_address_max
1471c50c785cSJohn Marino 	   >= bl->address)
1472c50c785cSJohn Marino 	  && (bl->address + bp_location_shadow_len_after_address_max
1473c50c785cSJohn Marino 	      <= memaddr))
1474cf7f2e2dSJohn Marino 	bc_l = bc;
1475cf7f2e2dSJohn Marino       else
1476cf7f2e2dSJohn Marino 	bc_r = bc;
1477cf7f2e2dSJohn Marino     }
1478cf7f2e2dSJohn Marino 
1479c50c785cSJohn Marino   /* Due to the binary search above, we need to make sure we pick the
1480c50c785cSJohn Marino      first location that's at BC_L's address.  E.g., if there are
1481c50c785cSJohn Marino      multiple locations at the same address, BC_L may end up pointing
1482c50c785cSJohn Marino      at a duplicate location, and miss the "master"/"inserted"
1483c50c785cSJohn Marino      location.  Say, given locations L1, L2 and L3 at addresses A and
1484c50c785cSJohn Marino      B:
1485c50c785cSJohn Marino 
1486c50c785cSJohn Marino       L1@A, L2@A, L3@B, ...
1487c50c785cSJohn Marino 
1488c50c785cSJohn Marino      BC_L could end up pointing at location L2, while the "master"
1489c50c785cSJohn Marino      location could be L1.  Since the `loc->inserted' flag is only set
1490c50c785cSJohn Marino      on "master" locations, we'd forget to restore the shadow of L1
1491c50c785cSJohn Marino      and L2.  */
1492c50c785cSJohn Marino   while (bc_l > 0
1493c50c785cSJohn Marino 	 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1494c50c785cSJohn Marino     bc_l--;
1495c50c785cSJohn Marino 
1496cf7f2e2dSJohn Marino   /* Now do full processing of the found relevant range of elements.  */
1497cf7f2e2dSJohn Marino 
1498cf7f2e2dSJohn Marino   for (bc = bc_l; bc < bp_location_count; bc++)
1499cf7f2e2dSJohn Marino   {
1500c50c785cSJohn Marino     struct bp_location *bl = bp_location[bc];
15015796c8dcSSimon Schubert     CORE_ADDR bp_addr = 0;
15025796c8dcSSimon Schubert     int bp_size = 0;
15035796c8dcSSimon Schubert     int bptoffset = 0;
15045796c8dcSSimon Schubert 
1505c50c785cSJohn Marino     /* bp_location array has BL->OWNER always non-NULL.  */
1506c50c785cSJohn Marino     if (bl->owner->type == bp_none)
15075796c8dcSSimon Schubert       warning (_("reading through apparently deleted breakpoint #%d?"),
1508c50c785cSJohn Marino 	       bl->owner->number);
15095796c8dcSSimon Schubert 
1510a45ae5f8SJohn Marino     /* Performance optimization: any further element can no longer affect BUF
1511cf7f2e2dSJohn Marino        content.  */
1512cf7f2e2dSJohn Marino 
1513c50c785cSJohn Marino     if (bl->address >= bp_location_placed_address_before_address_max
1514c50c785cSJohn Marino         && memaddr + len <= (bl->address
1515c50c785cSJohn Marino 			     - bp_location_placed_address_before_address_max))
1516cf7f2e2dSJohn Marino       break;
1517cf7f2e2dSJohn Marino 
1518c50c785cSJohn Marino     if (!bp_location_has_shadow (bl))
15195796c8dcSSimon Schubert       continue;
1520c50c785cSJohn Marino     if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
1521cf7f2e2dSJohn Marino 				   current_program_space->aspace, 0))
15225796c8dcSSimon Schubert       continue;
1523cf7f2e2dSJohn Marino 
15245796c8dcSSimon Schubert     /* Addresses and length of the part of the breakpoint that
15255796c8dcSSimon Schubert        we need to copy.  */
1526c50c785cSJohn Marino     bp_addr = bl->target_info.placed_address;
1527c50c785cSJohn Marino     bp_size = bl->target_info.shadow_len;
15285796c8dcSSimon Schubert 
15295796c8dcSSimon Schubert     if (bp_addr + bp_size <= memaddr)
15305796c8dcSSimon Schubert       /* The breakpoint is entirely before the chunk of memory we
15315796c8dcSSimon Schubert          are reading.  */
15325796c8dcSSimon Schubert       continue;
15335796c8dcSSimon Schubert 
15345796c8dcSSimon Schubert     if (bp_addr >= memaddr + len)
15355796c8dcSSimon Schubert       /* The breakpoint is entirely after the chunk of memory we are
15365796c8dcSSimon Schubert          reading.  */
15375796c8dcSSimon Schubert       continue;
15385796c8dcSSimon Schubert 
15395796c8dcSSimon Schubert     /* Offset within shadow_contents.  */
15405796c8dcSSimon Schubert     if (bp_addr < memaddr)
15415796c8dcSSimon Schubert       {
15425796c8dcSSimon Schubert 	/* Only copy the second part of the breakpoint.  */
15435796c8dcSSimon Schubert 	bp_size -= memaddr - bp_addr;
15445796c8dcSSimon Schubert 	bptoffset = memaddr - bp_addr;
15455796c8dcSSimon Schubert 	bp_addr = memaddr;
15465796c8dcSSimon Schubert       }
15475796c8dcSSimon Schubert 
15485796c8dcSSimon Schubert     if (bp_addr + bp_size > memaddr + len)
15495796c8dcSSimon Schubert       {
15505796c8dcSSimon Schubert 	/* Only copy the first part of the breakpoint.  */
15515796c8dcSSimon Schubert 	bp_size -= (bp_addr + bp_size) - (memaddr + len);
15525796c8dcSSimon Schubert       }
15535796c8dcSSimon Schubert 
1554a45ae5f8SJohn Marino     if (readbuf != NULL)
1555a45ae5f8SJohn Marino       {
1556*ef5ccd6cSJohn Marino 	/* Verify that the readbuf buffer does not overlap with
1557*ef5ccd6cSJohn Marino 	   the shadow_contents buffer.  */
1558*ef5ccd6cSJohn Marino 	gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1559*ef5ccd6cSJohn Marino 		    || readbuf >= (bl->target_info.shadow_contents
1560*ef5ccd6cSJohn Marino 				   + bl->target_info.shadow_len));
1561*ef5ccd6cSJohn Marino 
1562a45ae5f8SJohn Marino 	/* Update the read buffer with this inserted breakpoint's
1563a45ae5f8SJohn Marino 	   shadow.  */
1564a45ae5f8SJohn Marino 	memcpy (readbuf + bp_addr - memaddr,
1565c50c785cSJohn Marino 		bl->target_info.shadow_contents + bptoffset, bp_size);
15665796c8dcSSimon Schubert       }
1567a45ae5f8SJohn Marino     else
1568a45ae5f8SJohn Marino       {
1569a45ae5f8SJohn Marino 	struct gdbarch *gdbarch = bl->gdbarch;
1570a45ae5f8SJohn Marino 	const unsigned char *bp;
1571a45ae5f8SJohn Marino 	CORE_ADDR placed_address = bl->target_info.placed_address;
1572*ef5ccd6cSJohn Marino 	int placed_size = bl->target_info.placed_size;
1573a45ae5f8SJohn Marino 
1574a45ae5f8SJohn Marino 	/* Update the shadow with what we want to write to memory.  */
1575a45ae5f8SJohn Marino 	memcpy (bl->target_info.shadow_contents + bptoffset,
1576a45ae5f8SJohn Marino 		writebuf_org + bp_addr - memaddr, bp_size);
1577a45ae5f8SJohn Marino 
1578a45ae5f8SJohn Marino 	/* Determine appropriate breakpoint contents and size for this
1579a45ae5f8SJohn Marino 	   address.  */
1580a45ae5f8SJohn Marino 	bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1581a45ae5f8SJohn Marino 
1582a45ae5f8SJohn Marino 	/* Update the final write buffer with this inserted
1583a45ae5f8SJohn Marino 	   breakpoint's INSN.  */
1584a45ae5f8SJohn Marino 	memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1585a45ae5f8SJohn Marino       }
1586a45ae5f8SJohn Marino   }
15875796c8dcSSimon Schubert }
15885796c8dcSSimon Schubert 
15895796c8dcSSimon Schubert 
1590*ef5ccd6cSJohn Marino /* Return true if BPT is either a software breakpoint or a hardware
1591*ef5ccd6cSJohn Marino    breakpoint.  */
1592*ef5ccd6cSJohn Marino 
1593*ef5ccd6cSJohn Marino int
is_breakpoint(const struct breakpoint * bpt)1594*ef5ccd6cSJohn Marino is_breakpoint (const struct breakpoint *bpt)
1595*ef5ccd6cSJohn Marino {
1596*ef5ccd6cSJohn Marino   return (bpt->type == bp_breakpoint
1597*ef5ccd6cSJohn Marino 	  || bpt->type == bp_hardware_breakpoint
1598*ef5ccd6cSJohn Marino 	  || bpt->type == bp_dprintf);
1599*ef5ccd6cSJohn Marino }
1600*ef5ccd6cSJohn Marino 
1601cf7f2e2dSJohn Marino /* Return true if BPT is of any hardware watchpoint kind.  */
1602cf7f2e2dSJohn Marino 
16035796c8dcSSimon Schubert static int
is_hardware_watchpoint(const struct breakpoint * bpt)1604cf7f2e2dSJohn Marino is_hardware_watchpoint (const struct breakpoint *bpt)
16055796c8dcSSimon Schubert {
16065796c8dcSSimon Schubert   return (bpt->type == bp_hardware_watchpoint
16075796c8dcSSimon Schubert 	  || bpt->type == bp_read_watchpoint
16085796c8dcSSimon Schubert 	  || bpt->type == bp_access_watchpoint);
16095796c8dcSSimon Schubert }
16105796c8dcSSimon Schubert 
1611cf7f2e2dSJohn Marino /* Return true if BPT is of any watchpoint kind, hardware or
1612cf7f2e2dSJohn Marino    software.  */
16135796c8dcSSimon Schubert 
1614a45ae5f8SJohn Marino int
is_watchpoint(const struct breakpoint * bpt)1615cf7f2e2dSJohn Marino is_watchpoint (const struct breakpoint *bpt)
16165796c8dcSSimon Schubert {
1617cf7f2e2dSJohn Marino   return (is_hardware_watchpoint (bpt)
1618cf7f2e2dSJohn Marino 	  || bpt->type == bp_watchpoint);
16195796c8dcSSimon Schubert }
16205796c8dcSSimon Schubert 
1621a45ae5f8SJohn Marino /* Returns true if the current thread and its running state are safe
1622a45ae5f8SJohn Marino    to evaluate or update watchpoint B.  Watchpoints on local
1623a45ae5f8SJohn Marino    expressions need to be evaluated in the context of the thread that
1624a45ae5f8SJohn Marino    was current when the watchpoint was created, and, that thread needs
1625a45ae5f8SJohn Marino    to be stopped to be able to select the correct frame context.
1626a45ae5f8SJohn Marino    Watchpoints on global expressions can be evaluated on any thread,
1627a45ae5f8SJohn Marino    and in any state.  It is presently left to the target allowing
1628a45ae5f8SJohn Marino    memory accesses when threads are running.  */
16295796c8dcSSimon Schubert 
1630cf7f2e2dSJohn Marino static int
watchpoint_in_thread_scope(struct watchpoint * b)1631a45ae5f8SJohn Marino watchpoint_in_thread_scope (struct watchpoint *b)
16325796c8dcSSimon Schubert {
1633*ef5ccd6cSJohn Marino   return (b->base.pspace == current_program_space
1634*ef5ccd6cSJohn Marino 	  && (ptid_equal (b->watchpoint_thread, null_ptid)
1635cf7f2e2dSJohn Marino 	      || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1636*ef5ccd6cSJohn Marino 		  && !is_executing (inferior_ptid))));
16375796c8dcSSimon Schubert }
16385796c8dcSSimon Schubert 
1639c50c785cSJohn Marino /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1640c50c785cSJohn Marino    associated bp_watchpoint_scope breakpoint.  */
1641c50c785cSJohn Marino 
1642c50c785cSJohn Marino static void
watchpoint_del_at_next_stop(struct watchpoint * w)1643a45ae5f8SJohn Marino watchpoint_del_at_next_stop (struct watchpoint *w)
1644c50c785cSJohn Marino {
1645a45ae5f8SJohn Marino   struct breakpoint *b = &w->base;
1646c50c785cSJohn Marino 
1647c50c785cSJohn Marino   if (b->related_breakpoint != b)
1648c50c785cSJohn Marino     {
1649c50c785cSJohn Marino       gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1650c50c785cSJohn Marino       gdb_assert (b->related_breakpoint->related_breakpoint == b);
1651c50c785cSJohn Marino       b->related_breakpoint->disposition = disp_del_at_next_stop;
1652c50c785cSJohn Marino       b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1653c50c785cSJohn Marino       b->related_breakpoint = b;
1654c50c785cSJohn Marino     }
1655c50c785cSJohn Marino   b->disposition = disp_del_at_next_stop;
1656c50c785cSJohn Marino }
1657c50c785cSJohn Marino 
16585796c8dcSSimon Schubert /* Assuming that B is a watchpoint:
16595796c8dcSSimon Schubert    - Reparse watchpoint expression, if REPARSE is non-zero
16605796c8dcSSimon Schubert    - Evaluate expression and store the result in B->val
16615796c8dcSSimon Schubert    - Evaluate the condition if there is one, and store the result
16625796c8dcSSimon Schubert      in b->loc->cond.
16635796c8dcSSimon Schubert    - Update the list of values that must be watched in B->loc.
16645796c8dcSSimon Schubert 
1665c50c785cSJohn Marino    If the watchpoint disposition is disp_del_at_next_stop, then do
1666c50c785cSJohn Marino    nothing.  If this is local watchpoint that is out of scope, delete
1667c50c785cSJohn Marino    it.
1668cf7f2e2dSJohn Marino 
1669c50c785cSJohn Marino    Even with `set breakpoint always-inserted on' the watchpoints are
1670c50c785cSJohn Marino    removed + inserted on each stop here.  Normal breakpoints must
1671c50c785cSJohn Marino    never be removed because they might be missed by a running thread
1672c50c785cSJohn Marino    when debugging in non-stop mode.  On the other hand, hardware
1673c50c785cSJohn Marino    watchpoints (is_hardware_watchpoint; processed here) are specific
1674c50c785cSJohn Marino    to each LWP since they are stored in each LWP's hardware debug
1675c50c785cSJohn Marino    registers.  Therefore, such LWP must be stopped first in order to
1676c50c785cSJohn Marino    be able to modify its hardware watchpoints.
1677cf7f2e2dSJohn Marino 
1678c50c785cSJohn Marino    Hardware watchpoints must be reset exactly once after being
1679c50c785cSJohn Marino    presented to the user.  It cannot be done sooner, because it would
1680c50c785cSJohn Marino    reset the data used to present the watchpoint hit to the user.  And
1681c50c785cSJohn Marino    it must not be done later because it could display the same single
1682c50c785cSJohn Marino    watchpoint hit during multiple GDB stops.  Note that the latter is
1683c50c785cSJohn Marino    relevant only to the hardware watchpoint types bp_read_watchpoint
1684c50c785cSJohn Marino    and bp_access_watchpoint.  False hit by bp_hardware_watchpoint is
1685c50c785cSJohn Marino    not user-visible - its hit is suppressed if the memory content has
1686c50c785cSJohn Marino    not changed.
1687cf7f2e2dSJohn Marino 
1688c50c785cSJohn Marino    The following constraints influence the location where we can reset
1689c50c785cSJohn Marino    hardware watchpoints:
1690cf7f2e2dSJohn Marino 
1691c50c785cSJohn Marino    * target_stopped_by_watchpoint and target_stopped_data_address are
1692c50c785cSJohn Marino      called several times when GDB stops.
1693cf7f2e2dSJohn Marino 
1694cf7f2e2dSJohn Marino    [linux]
1695c50c785cSJohn Marino    * Multiple hardware watchpoints can be hit at the same time,
1696c50c785cSJohn Marino      causing GDB to stop.  GDB only presents one hardware watchpoint
1697c50c785cSJohn Marino      hit at a time as the reason for stopping, and all the other hits
1698c50c785cSJohn Marino      are presented later, one after the other, each time the user
1699c50c785cSJohn Marino      requests the execution to be resumed.  Execution is not resumed
1700c50c785cSJohn Marino      for the threads still having pending hit event stored in
1701c50c785cSJohn Marino      LWP_INFO->STATUS.  While the watchpoint is already removed from
1702c50c785cSJohn Marino      the inferior on the first stop the thread hit event is kept being
1703c50c785cSJohn Marino      reported from its cached value by linux_nat_stopped_data_address
1704c50c785cSJohn Marino      until the real thread resume happens after the watchpoint gets
1705c50c785cSJohn Marino      presented and thus its LWP_INFO->STATUS gets reset.
1706cf7f2e2dSJohn Marino 
1707c50c785cSJohn Marino    Therefore the hardware watchpoint hit can get safely reset on the
1708c50c785cSJohn Marino    watchpoint removal from inferior.  */
1709cf7f2e2dSJohn Marino 
17105796c8dcSSimon Schubert static void
update_watchpoint(struct watchpoint * b,int reparse)1711a45ae5f8SJohn Marino update_watchpoint (struct watchpoint *b, int reparse)
17125796c8dcSSimon Schubert {
17135796c8dcSSimon Schubert   int within_current_scope;
17145796c8dcSSimon Schubert   struct frame_id saved_frame_id;
1715cf7f2e2dSJohn Marino   int frame_saved;
17165796c8dcSSimon Schubert 
1717cf7f2e2dSJohn Marino   /* If this is a local watchpoint, we only want to check if the
1718cf7f2e2dSJohn Marino      watchpoint frame is in scope if the current thread is the thread
1719cf7f2e2dSJohn Marino      that was used to create the watchpoint.  */
1720cf7f2e2dSJohn Marino   if (!watchpoint_in_thread_scope (b))
1721cf7f2e2dSJohn Marino     return;
1722cf7f2e2dSJohn Marino 
1723a45ae5f8SJohn Marino   if (b->base.disposition == disp_del_at_next_stop)
17245796c8dcSSimon Schubert     return;
17255796c8dcSSimon Schubert 
1726cf7f2e2dSJohn Marino   frame_saved = 0;
17275796c8dcSSimon Schubert 
17285796c8dcSSimon Schubert   /* Determine if the watchpoint is within scope.  */
17295796c8dcSSimon Schubert   if (b->exp_valid_block == NULL)
17305796c8dcSSimon Schubert     within_current_scope = 1;
17315796c8dcSSimon Schubert   else
17325796c8dcSSimon Schubert     {
1733c50c785cSJohn Marino       struct frame_info *fi = get_current_frame ();
1734c50c785cSJohn Marino       struct gdbarch *frame_arch = get_frame_arch (fi);
1735c50c785cSJohn Marino       CORE_ADDR frame_pc = get_frame_pc (fi);
1736c50c785cSJohn Marino 
1737c50c785cSJohn Marino       /* If we're in a function epilogue, unwinding may not work
1738c50c785cSJohn Marino 	 properly, so do not attempt to recreate locations at this
1739c50c785cSJohn Marino 	 point.  See similar comments in watchpoint_check.  */
1740c50c785cSJohn Marino       if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1741c50c785cSJohn Marino 	return;
1742cf7f2e2dSJohn Marino 
1743cf7f2e2dSJohn Marino       /* Save the current frame's ID so we can restore it after
1744cf7f2e2dSJohn Marino          evaluating the watchpoint expression on its own frame.  */
1745cf7f2e2dSJohn Marino       /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1746cf7f2e2dSJohn Marino          took a frame parameter, so that we didn't have to change the
1747cf7f2e2dSJohn Marino          selected frame.  */
1748cf7f2e2dSJohn Marino       frame_saved = 1;
1749cf7f2e2dSJohn Marino       saved_frame_id = get_frame_id (get_selected_frame (NULL));
1750cf7f2e2dSJohn Marino 
17515796c8dcSSimon Schubert       fi = frame_find_by_id (b->watchpoint_frame);
17525796c8dcSSimon Schubert       within_current_scope = (fi != NULL);
17535796c8dcSSimon Schubert       if (within_current_scope)
17545796c8dcSSimon Schubert 	select_frame (fi);
17555796c8dcSSimon Schubert     }
17565796c8dcSSimon Schubert 
1757c50c785cSJohn Marino   /* We don't free locations.  They are stored in the bp_location array
1758c50c785cSJohn Marino      and update_global_location_list will eventually delete them and
1759c50c785cSJohn Marino      remove breakpoints if needed.  */
1760a45ae5f8SJohn Marino   b->base.loc = NULL;
1761c50c785cSJohn Marino 
17625796c8dcSSimon Schubert   if (within_current_scope && reparse)
17635796c8dcSSimon Schubert     {
1764*ef5ccd6cSJohn Marino       const char *s;
1765c50c785cSJohn Marino 
17665796c8dcSSimon Schubert       if (b->exp)
17675796c8dcSSimon Schubert 	{
17685796c8dcSSimon Schubert 	  xfree (b->exp);
17695796c8dcSSimon Schubert 	  b->exp = NULL;
17705796c8dcSSimon Schubert 	}
1771c50c785cSJohn Marino       s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
1772*ef5ccd6cSJohn Marino       b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0);
17735796c8dcSSimon Schubert       /* If the meaning of expression itself changed, the old value is
17745796c8dcSSimon Schubert 	 no longer relevant.  We don't want to report a watchpoint hit
17755796c8dcSSimon Schubert 	 to the user when the old value and the new value may actually
17765796c8dcSSimon Schubert 	 be completely different objects.  */
17775796c8dcSSimon Schubert       value_free (b->val);
17785796c8dcSSimon Schubert       b->val = NULL;
17795796c8dcSSimon Schubert       b->val_valid = 0;
1780cf7f2e2dSJohn Marino 
1781cf7f2e2dSJohn Marino       /* Note that unlike with breakpoints, the watchpoint's condition
1782cf7f2e2dSJohn Marino 	 expression is stored in the breakpoint object, not in the
1783cf7f2e2dSJohn Marino 	 locations (re)created below.  */
1784a45ae5f8SJohn Marino       if (b->base.cond_string != NULL)
1785cf7f2e2dSJohn Marino 	{
1786cf7f2e2dSJohn Marino 	  if (b->cond_exp != NULL)
1787cf7f2e2dSJohn Marino 	    {
1788cf7f2e2dSJohn Marino 	      xfree (b->cond_exp);
1789cf7f2e2dSJohn Marino 	      b->cond_exp = NULL;
1790cf7f2e2dSJohn Marino 	    }
1791cf7f2e2dSJohn Marino 
1792a45ae5f8SJohn Marino 	  s = b->base.cond_string;
1793*ef5ccd6cSJohn Marino 	  b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
1794cf7f2e2dSJohn Marino 	}
17955796c8dcSSimon Schubert     }
17965796c8dcSSimon Schubert 
17975796c8dcSSimon Schubert   /* If we failed to parse the expression, for example because
17985796c8dcSSimon Schubert      it refers to a global variable in a not-yet-loaded shared library,
17995796c8dcSSimon Schubert      don't try to insert watchpoint.  We don't automatically delete
18005796c8dcSSimon Schubert      such watchpoint, though, since failure to parse expression
18015796c8dcSSimon Schubert      is different from out-of-scope watchpoint.  */
1802cf7f2e2dSJohn Marino   if ( !target_has_execution)
18035796c8dcSSimon Schubert     {
1804cf7f2e2dSJohn Marino       /* Without execution, memory can't change.  No use to try and
1805cf7f2e2dSJohn Marino 	 set watchpoint locations.  The watchpoint will be reset when
1806cf7f2e2dSJohn Marino 	 the target gains execution, through breakpoint_re_set.  */
1807cf7f2e2dSJohn Marino     }
1808cf7f2e2dSJohn Marino   else if (within_current_scope && b->exp)
1809cf7f2e2dSJohn Marino     {
1810cf7f2e2dSJohn Marino       int pc = 0;
18115796c8dcSSimon Schubert       struct value *val_chain, *v, *result, *next;
1812cf7f2e2dSJohn Marino       struct program_space *frame_pspace;
18135796c8dcSSimon Schubert 
1814cf7f2e2dSJohn Marino       fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
18155796c8dcSSimon Schubert 
18165796c8dcSSimon Schubert       /* Avoid setting b->val if it's already set.  The meaning of
18175796c8dcSSimon Schubert 	 b->val is 'the last value' user saw, and we should update
18185796c8dcSSimon Schubert 	 it only if we reported that last value to user.  As it
1819a45ae5f8SJohn Marino 	 happens, the code that reports it updates b->val directly.
1820a45ae5f8SJohn Marino 	 We don't keep track of the memory value for masked
1821a45ae5f8SJohn Marino 	 watchpoints.  */
1822a45ae5f8SJohn Marino       if (!b->val_valid && !is_masked_watchpoint (&b->base))
18235796c8dcSSimon Schubert 	{
18245796c8dcSSimon Schubert 	  b->val = v;
18255796c8dcSSimon Schubert 	  b->val_valid = 1;
18265796c8dcSSimon Schubert 	}
18275796c8dcSSimon Schubert 
1828cf7f2e2dSJohn Marino       frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1829cf7f2e2dSJohn Marino 
18305796c8dcSSimon Schubert       /* Look at each value on the value chain.  */
1831c50c785cSJohn Marino       for (v = val_chain; v; v = value_next (v))
18325796c8dcSSimon Schubert 	{
18335796c8dcSSimon Schubert 	  /* If it's a memory location, and GDB actually needed
18345796c8dcSSimon Schubert 	     its contents to evaluate the expression, then we
18355796c8dcSSimon Schubert 	     must watch it.  If the first value returned is
18365796c8dcSSimon Schubert 	     still lazy, that means an error occurred reading it;
18375796c8dcSSimon Schubert 	     watch it anyway in case it becomes readable.  */
18385796c8dcSSimon Schubert 	  if (VALUE_LVAL (v) == lval_memory
18395796c8dcSSimon Schubert 	      && (v == val_chain || ! value_lazy (v)))
18405796c8dcSSimon Schubert 	    {
18415796c8dcSSimon Schubert 	      struct type *vtype = check_typedef (value_type (v));
18425796c8dcSSimon Schubert 
18435796c8dcSSimon Schubert 	      /* We only watch structs and arrays if user asked
18445796c8dcSSimon Schubert 		 for it explicitly, never if they just happen to
18455796c8dcSSimon Schubert 		 appear in the middle of some value chain.  */
18465796c8dcSSimon Schubert 	      if (v == result
18475796c8dcSSimon Schubert 		  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
18485796c8dcSSimon Schubert 		      && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
18495796c8dcSSimon Schubert 		{
18505796c8dcSSimon Schubert 		  CORE_ADDR addr;
1851*ef5ccd6cSJohn Marino 		  int type;
18525796c8dcSSimon Schubert 		  struct bp_location *loc, **tmp;
18535796c8dcSSimon Schubert 
18545796c8dcSSimon Schubert 		  addr = value_address (v);
18555796c8dcSSimon Schubert 		  type = hw_write;
1856a45ae5f8SJohn Marino 		  if (b->base.type == bp_read_watchpoint)
18575796c8dcSSimon Schubert 		    type = hw_read;
1858a45ae5f8SJohn Marino 		  else if (b->base.type == bp_access_watchpoint)
18595796c8dcSSimon Schubert 		    type = hw_access;
18605796c8dcSSimon Schubert 
1861a45ae5f8SJohn Marino 		  loc = allocate_bp_location (&b->base);
1862a45ae5f8SJohn Marino 		  for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
18635796c8dcSSimon Schubert 		    ;
18645796c8dcSSimon Schubert 		  *tmp = loc;
18655796c8dcSSimon Schubert 		  loc->gdbarch = get_type_arch (value_type (v));
1866cf7f2e2dSJohn Marino 
1867cf7f2e2dSJohn Marino 		  loc->pspace = frame_pspace;
18685796c8dcSSimon Schubert 		  loc->address = addr;
1869*ef5ccd6cSJohn Marino 		  loc->length = TYPE_LENGTH (value_type (v));
18705796c8dcSSimon Schubert 		  loc->watchpoint_type = type;
18715796c8dcSSimon Schubert 		}
18725796c8dcSSimon Schubert 	    }
1873c50c785cSJohn Marino 	}
18745796c8dcSSimon Schubert 
1875c50c785cSJohn Marino       /* Change the type of breakpoint between hardware assisted or
1876c50c785cSJohn Marino 	 an ordinary watchpoint depending on the hardware support
1877c50c785cSJohn Marino 	 and free hardware slots.  REPARSE is set when the inferior
1878c50c785cSJohn Marino 	 is started.  */
1879a45ae5f8SJohn Marino       if (reparse)
1880c50c785cSJohn Marino 	{
1881c50c785cSJohn Marino 	  int reg_cnt;
1882c50c785cSJohn Marino 	  enum bp_loc_type loc_type;
1883c50c785cSJohn Marino 	  struct bp_location *bl;
1884c50c785cSJohn Marino 
1885a45ae5f8SJohn Marino 	  reg_cnt = can_use_hardware_watchpoint (val_chain);
1886c50c785cSJohn Marino 
1887c50c785cSJohn Marino 	  if (reg_cnt)
1888c50c785cSJohn Marino 	    {
1889c50c785cSJohn Marino 	      int i, target_resources_ok, other_type_used;
1890a45ae5f8SJohn Marino 	      enum bptype type;
1891a45ae5f8SJohn Marino 
1892a45ae5f8SJohn Marino 	      /* Use an exact watchpoint when there's only one memory region to be
1893a45ae5f8SJohn Marino 		 watched, and only one debug register is needed to watch it.  */
1894a45ae5f8SJohn Marino 	      b->exact = target_exact_watchpoints && reg_cnt == 1;
1895c50c785cSJohn Marino 
1896c50c785cSJohn Marino 	      /* We need to determine how many resources are already
1897c50c785cSJohn Marino 		 used for all other hardware watchpoints plus this one
1898c50c785cSJohn Marino 		 to see if we still have enough resources to also fit
1899a45ae5f8SJohn Marino 		 this watchpoint in as well.  */
1900c50c785cSJohn Marino 
1901a45ae5f8SJohn Marino 	      /* If this is a software watchpoint, we try to turn it
1902a45ae5f8SJohn Marino 		 to a hardware one -- count resources as if B was of
1903a45ae5f8SJohn Marino 		 hardware watchpoint type.  */
1904a45ae5f8SJohn Marino 	      type = b->base.type;
1905a45ae5f8SJohn Marino 	      if (type == bp_watchpoint)
1906a45ae5f8SJohn Marino 		type = bp_hardware_watchpoint;
1907c50c785cSJohn Marino 
1908a45ae5f8SJohn Marino 	      /* This watchpoint may or may not have been placed on
1909a45ae5f8SJohn Marino 		 the list yet at this point (it won't be in the list
1910a45ae5f8SJohn Marino 		 if we're trying to create it for the first time,
1911a45ae5f8SJohn Marino 		 through watch_command), so always account for it
1912a45ae5f8SJohn Marino 		 manually.  */
1913c50c785cSJohn Marino 
1914a45ae5f8SJohn Marino 	      /* Count resources used by all watchpoints except B.  */
1915a45ae5f8SJohn Marino 	      i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1916c50c785cSJohn Marino 
1917a45ae5f8SJohn Marino 	      /* Add in the resources needed for B.  */
1918a45ae5f8SJohn Marino 	      i += hw_watchpoint_use_count (&b->base);
1919a45ae5f8SJohn Marino 
1920a45ae5f8SJohn Marino 	      target_resources_ok
1921a45ae5f8SJohn Marino 		= target_can_use_hardware_watchpoint (type, i, other_type_used);
1922c50c785cSJohn Marino 	      if (target_resources_ok <= 0)
1923a45ae5f8SJohn Marino 		{
1924a45ae5f8SJohn Marino 		  int sw_mode = b->base.ops->works_in_software_mode (&b->base);
1925a45ae5f8SJohn Marino 
1926a45ae5f8SJohn Marino 		  if (target_resources_ok == 0 && !sw_mode)
1927a45ae5f8SJohn Marino 		    error (_("Target does not support this type of "
1928a45ae5f8SJohn Marino 			     "hardware watchpoint."));
1929a45ae5f8SJohn Marino 		  else if (target_resources_ok < 0 && !sw_mode)
1930a45ae5f8SJohn Marino 		    error (_("There are not enough available hardware "
1931a45ae5f8SJohn Marino 			     "resources for this watchpoint."));
1932a45ae5f8SJohn Marino 
1933a45ae5f8SJohn Marino 		  /* Downgrade to software watchpoint.  */
1934a45ae5f8SJohn Marino 		  b->base.type = bp_watchpoint;
1935c50c785cSJohn Marino 		}
1936c50c785cSJohn Marino 	      else
1937a45ae5f8SJohn Marino 		{
1938a45ae5f8SJohn Marino 		  /* If this was a software watchpoint, we've just
1939a45ae5f8SJohn Marino 		     found we have enough resources to turn it to a
1940a45ae5f8SJohn Marino 		     hardware watchpoint.  Otherwise, this is a
1941a45ae5f8SJohn Marino 		     nop.  */
1942a45ae5f8SJohn Marino 		  b->base.type = type;
1943a45ae5f8SJohn Marino 		}
1944a45ae5f8SJohn Marino 	    }
1945a45ae5f8SJohn Marino 	  else if (!b->base.ops->works_in_software_mode (&b->base))
1946a45ae5f8SJohn Marino 	    error (_("Expression cannot be implemented with "
1947a45ae5f8SJohn Marino 		     "read/access watchpoint."));
1948a45ae5f8SJohn Marino 	  else
1949a45ae5f8SJohn Marino 	    b->base.type = bp_watchpoint;
1950c50c785cSJohn Marino 
1951a45ae5f8SJohn Marino 	  loc_type = (b->base.type == bp_watchpoint? bp_loc_other
1952c50c785cSJohn Marino 		      : bp_loc_hardware_watchpoint);
1953a45ae5f8SJohn Marino 	  for (bl = b->base.loc; bl; bl = bl->next)
1954c50c785cSJohn Marino 	    bl->loc_type = loc_type;
1955c50c785cSJohn Marino 	}
1956c50c785cSJohn Marino 
1957c50c785cSJohn Marino       for (v = val_chain; v; v = next)
1958c50c785cSJohn Marino 	{
19595796c8dcSSimon Schubert 	  next = value_next (v);
19605796c8dcSSimon Schubert 	  if (v != b->val)
19615796c8dcSSimon Schubert 	    value_free (v);
19625796c8dcSSimon Schubert 	}
19635796c8dcSSimon Schubert 
1964cf7f2e2dSJohn Marino       /* If a software watchpoint is not watching any memory, then the
1965cf7f2e2dSJohn Marino 	 above left it without any location set up.  But,
1966cf7f2e2dSJohn Marino 	 bpstat_stop_status requires a location to be able to report
1967cf7f2e2dSJohn Marino 	 stops, so make sure there's at least a dummy one.  */
1968a45ae5f8SJohn Marino       if (b->base.type == bp_watchpoint && b->base.loc == NULL)
19695796c8dcSSimon Schubert 	{
1970a45ae5f8SJohn Marino 	  struct breakpoint *base = &b->base;
1971a45ae5f8SJohn Marino 	  base->loc = allocate_bp_location (base);
1972a45ae5f8SJohn Marino 	  base->loc->pspace = frame_pspace;
1973a45ae5f8SJohn Marino 	  base->loc->address = -1;
1974a45ae5f8SJohn Marino 	  base->loc->length = -1;
1975a45ae5f8SJohn Marino 	  base->loc->watchpoint_type = -1;
19765796c8dcSSimon Schubert 	}
19775796c8dcSSimon Schubert     }
19785796c8dcSSimon Schubert   else if (!within_current_scope)
19795796c8dcSSimon Schubert     {
19805796c8dcSSimon Schubert       printf_filtered (_("\
19815796c8dcSSimon Schubert Watchpoint %d deleted because the program has left the block\n\
19825796c8dcSSimon Schubert in which its expression is valid.\n"),
1983a45ae5f8SJohn Marino 		       b->base.number);
1984c50c785cSJohn Marino       watchpoint_del_at_next_stop (b);
19855796c8dcSSimon Schubert     }
19865796c8dcSSimon Schubert 
19875796c8dcSSimon Schubert   /* Restore the selected frame.  */
1988cf7f2e2dSJohn Marino   if (frame_saved)
19895796c8dcSSimon Schubert     select_frame (frame_find_by_id (saved_frame_id));
19905796c8dcSSimon Schubert }
19915796c8dcSSimon Schubert 
19925796c8dcSSimon Schubert 
19935796c8dcSSimon Schubert /* Returns 1 iff breakpoint location should be
1994a45ae5f8SJohn Marino    inserted in the inferior.  We don't differentiate the type of BL's owner
1995a45ae5f8SJohn Marino    (breakpoint vs. tracepoint), although insert_location in tracepoint's
1996a45ae5f8SJohn Marino    breakpoint_ops is not defined, because in insert_bp_location,
1997a45ae5f8SJohn Marino    tracepoint's insert_location will not be called.  */
19985796c8dcSSimon Schubert static int
should_be_inserted(struct bp_location * bl)1999c50c785cSJohn Marino should_be_inserted (struct bp_location *bl)
20005796c8dcSSimon Schubert {
2001c50c785cSJohn Marino   if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
20025796c8dcSSimon Schubert     return 0;
20035796c8dcSSimon Schubert 
2004c50c785cSJohn Marino   if (bl->owner->disposition == disp_del_at_next_stop)
20055796c8dcSSimon Schubert     return 0;
20065796c8dcSSimon Schubert 
2007c50c785cSJohn Marino   if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
20085796c8dcSSimon Schubert     return 0;
20095796c8dcSSimon Schubert 
2010a45ae5f8SJohn Marino   if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
2011a45ae5f8SJohn Marino     return 0;
2012a45ae5f8SJohn Marino 
2013cf7f2e2dSJohn Marino   /* This is set for example, when we're attached to the parent of a
2014cf7f2e2dSJohn Marino      vfork, and have detached from the child.  The child is running
2015cf7f2e2dSJohn Marino      free, and we expect it to do an exec or exit, at which point the
2016cf7f2e2dSJohn Marino      OS makes the parent schedulable again (and the target reports
2017cf7f2e2dSJohn Marino      that the vfork is done).  Until the child is done with the shared
2018cf7f2e2dSJohn Marino      memory region, do not insert breakpoints in the parent, otherwise
2019cf7f2e2dSJohn Marino      the child could still trip on the parent's breakpoints.  Since
2020cf7f2e2dSJohn Marino      the parent is blocked anyway, it won't miss any breakpoint.  */
2021c50c785cSJohn Marino   if (bl->pspace->breakpoints_not_allowed)
2022cf7f2e2dSJohn Marino     return 0;
2023cf7f2e2dSJohn Marino 
20245796c8dcSSimon Schubert   return 1;
20255796c8dcSSimon Schubert }
20265796c8dcSSimon Schubert 
2027a45ae5f8SJohn Marino /* Same as should_be_inserted but does the check assuming
2028a45ae5f8SJohn Marino    that the location is not duplicated.  */
2029a45ae5f8SJohn Marino 
2030a45ae5f8SJohn Marino static int
unduplicated_should_be_inserted(struct bp_location * bl)2031a45ae5f8SJohn Marino unduplicated_should_be_inserted (struct bp_location *bl)
2032a45ae5f8SJohn Marino {
2033a45ae5f8SJohn Marino   int result;
2034a45ae5f8SJohn Marino   const int save_duplicate = bl->duplicate;
2035a45ae5f8SJohn Marino 
2036a45ae5f8SJohn Marino   bl->duplicate = 0;
2037a45ae5f8SJohn Marino   result = should_be_inserted (bl);
2038a45ae5f8SJohn Marino   bl->duplicate = save_duplicate;
2039a45ae5f8SJohn Marino   return result;
2040a45ae5f8SJohn Marino }
2041a45ae5f8SJohn Marino 
2042*ef5ccd6cSJohn Marino /* Parses a conditional described by an expression COND into an
2043*ef5ccd6cSJohn Marino    agent expression bytecode suitable for evaluation
2044*ef5ccd6cSJohn Marino    by the bytecode interpreter.  Return NULL if there was
2045*ef5ccd6cSJohn Marino    any error during parsing.  */
2046*ef5ccd6cSJohn Marino 
2047*ef5ccd6cSJohn Marino static struct agent_expr *
parse_cond_to_aexpr(CORE_ADDR scope,struct expression * cond)2048*ef5ccd6cSJohn Marino parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
2049*ef5ccd6cSJohn Marino {
2050*ef5ccd6cSJohn Marino   struct agent_expr *aexpr = NULL;
2051*ef5ccd6cSJohn Marino   struct cleanup *old_chain = NULL;
2052*ef5ccd6cSJohn Marino   volatile struct gdb_exception ex;
2053*ef5ccd6cSJohn Marino 
2054*ef5ccd6cSJohn Marino   if (!cond)
2055*ef5ccd6cSJohn Marino     return NULL;
2056*ef5ccd6cSJohn Marino 
2057*ef5ccd6cSJohn Marino   /* We don't want to stop processing, so catch any errors
2058*ef5ccd6cSJohn Marino      that may show up.  */
2059*ef5ccd6cSJohn Marino   TRY_CATCH (ex, RETURN_MASK_ERROR)
2060*ef5ccd6cSJohn Marino     {
2061*ef5ccd6cSJohn Marino       aexpr = gen_eval_for_expr (scope, cond);
2062*ef5ccd6cSJohn Marino     }
2063*ef5ccd6cSJohn Marino 
2064*ef5ccd6cSJohn Marino   if (ex.reason < 0)
2065*ef5ccd6cSJohn Marino     {
2066*ef5ccd6cSJohn Marino       /* If we got here, it means the condition could not be parsed to a valid
2067*ef5ccd6cSJohn Marino 	 bytecode expression and thus can't be evaluated on the target's side.
2068*ef5ccd6cSJohn Marino 	 It's no use iterating through the conditions.  */
2069*ef5ccd6cSJohn Marino       return NULL;
2070*ef5ccd6cSJohn Marino     }
2071*ef5ccd6cSJohn Marino 
2072*ef5ccd6cSJohn Marino   /* We have a valid agent expression.  */
2073*ef5ccd6cSJohn Marino   return aexpr;
2074*ef5ccd6cSJohn Marino }
2075*ef5ccd6cSJohn Marino 
2076*ef5ccd6cSJohn Marino /* Based on location BL, create a list of breakpoint conditions to be
2077*ef5ccd6cSJohn Marino    passed on to the target.  If we have duplicated locations with different
2078*ef5ccd6cSJohn Marino    conditions, we will add such conditions to the list.  The idea is that the
2079*ef5ccd6cSJohn Marino    target will evaluate the list of conditions and will only notify GDB when
2080*ef5ccd6cSJohn Marino    one of them is true.  */
2081*ef5ccd6cSJohn Marino 
2082*ef5ccd6cSJohn Marino static void
build_target_condition_list(struct bp_location * bl)2083*ef5ccd6cSJohn Marino build_target_condition_list (struct bp_location *bl)
2084*ef5ccd6cSJohn Marino {
2085*ef5ccd6cSJohn Marino   struct bp_location **locp = NULL, **loc2p;
2086*ef5ccd6cSJohn Marino   int null_condition_or_parse_error = 0;
2087*ef5ccd6cSJohn Marino   int modified = bl->needs_update;
2088*ef5ccd6cSJohn Marino   struct bp_location *loc;
2089*ef5ccd6cSJohn Marino 
2090*ef5ccd6cSJohn Marino   /* This is only meaningful if the target is
2091*ef5ccd6cSJohn Marino      evaluating conditions and if the user has
2092*ef5ccd6cSJohn Marino      opted for condition evaluation on the target's
2093*ef5ccd6cSJohn Marino      side.  */
2094*ef5ccd6cSJohn Marino   if (gdb_evaluates_breakpoint_condition_p ()
2095*ef5ccd6cSJohn Marino       || !target_supports_evaluation_of_breakpoint_conditions ())
2096*ef5ccd6cSJohn Marino     return;
2097*ef5ccd6cSJohn Marino 
2098*ef5ccd6cSJohn Marino   /* Do a first pass to check for locations with no assigned
2099*ef5ccd6cSJohn Marino      conditions or conditions that fail to parse to a valid agent expression
2100*ef5ccd6cSJohn Marino      bytecode.  If any of these happen, then it's no use to send conditions
2101*ef5ccd6cSJohn Marino      to the target since this location will always trigger and generate a
2102*ef5ccd6cSJohn Marino      response back to GDB.  */
2103*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2104*ef5ccd6cSJohn Marino     {
2105*ef5ccd6cSJohn Marino       loc = (*loc2p);
2106*ef5ccd6cSJohn Marino       if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2107*ef5ccd6cSJohn Marino 	{
2108*ef5ccd6cSJohn Marino 	  if (modified)
2109*ef5ccd6cSJohn Marino 	    {
2110*ef5ccd6cSJohn Marino 	      struct agent_expr *aexpr;
2111*ef5ccd6cSJohn Marino 
2112*ef5ccd6cSJohn Marino 	      /* Re-parse the conditions since something changed.  In that
2113*ef5ccd6cSJohn Marino 		 case we already freed the condition bytecodes (see
2114*ef5ccd6cSJohn Marino 		 force_breakpoint_reinsertion).  We just
2115*ef5ccd6cSJohn Marino 		 need to parse the condition to bytecodes again.  */
2116*ef5ccd6cSJohn Marino 	      aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2117*ef5ccd6cSJohn Marino 	      loc->cond_bytecode = aexpr;
2118*ef5ccd6cSJohn Marino 
2119*ef5ccd6cSJohn Marino 	      /* Check if we managed to parse the conditional expression
2120*ef5ccd6cSJohn Marino 		 correctly.  If not, we will not send this condition
2121*ef5ccd6cSJohn Marino 		 to the target.  */
2122*ef5ccd6cSJohn Marino 	      if (aexpr)
2123*ef5ccd6cSJohn Marino 		continue;
2124*ef5ccd6cSJohn Marino 	    }
2125*ef5ccd6cSJohn Marino 
2126*ef5ccd6cSJohn Marino 	  /* If we have a NULL bytecode expression, it means something
2127*ef5ccd6cSJohn Marino 	     went wrong or we have a null condition expression.  */
2128*ef5ccd6cSJohn Marino 	  if (!loc->cond_bytecode)
2129*ef5ccd6cSJohn Marino 	    {
2130*ef5ccd6cSJohn Marino 	      null_condition_or_parse_error = 1;
2131*ef5ccd6cSJohn Marino 	      break;
2132*ef5ccd6cSJohn Marino 	    }
2133*ef5ccd6cSJohn Marino 	}
2134*ef5ccd6cSJohn Marino     }
2135*ef5ccd6cSJohn Marino 
2136*ef5ccd6cSJohn Marino   /* If any of these happened, it means we will have to evaluate the conditions
2137*ef5ccd6cSJohn Marino      for the location's address on gdb's side.  It is no use keeping bytecodes
2138*ef5ccd6cSJohn Marino      for all the other duplicate locations, thus we free all of them here.
2139*ef5ccd6cSJohn Marino 
2140*ef5ccd6cSJohn Marino      This is so we have a finer control over which locations' conditions are
2141*ef5ccd6cSJohn Marino      being evaluated by GDB or the remote stub.  */
2142*ef5ccd6cSJohn Marino   if (null_condition_or_parse_error)
2143*ef5ccd6cSJohn Marino     {
2144*ef5ccd6cSJohn Marino       ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2145*ef5ccd6cSJohn Marino 	{
2146*ef5ccd6cSJohn Marino 	  loc = (*loc2p);
2147*ef5ccd6cSJohn Marino 	  if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2148*ef5ccd6cSJohn Marino 	    {
2149*ef5ccd6cSJohn Marino 	      /* Only go as far as the first NULL bytecode is
2150*ef5ccd6cSJohn Marino 		 located.  */
2151*ef5ccd6cSJohn Marino 	      if (!loc->cond_bytecode)
2152*ef5ccd6cSJohn Marino 		return;
2153*ef5ccd6cSJohn Marino 
2154*ef5ccd6cSJohn Marino 	      free_agent_expr (loc->cond_bytecode);
2155*ef5ccd6cSJohn Marino 	      loc->cond_bytecode = NULL;
2156*ef5ccd6cSJohn Marino 	    }
2157*ef5ccd6cSJohn Marino 	}
2158*ef5ccd6cSJohn Marino     }
2159*ef5ccd6cSJohn Marino 
2160*ef5ccd6cSJohn Marino   /* No NULL conditions or failed bytecode generation.  Build a condition list
2161*ef5ccd6cSJohn Marino      for this location's address.  */
2162*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2163*ef5ccd6cSJohn Marino     {
2164*ef5ccd6cSJohn Marino       loc = (*loc2p);
2165*ef5ccd6cSJohn Marino       if (loc->cond
2166*ef5ccd6cSJohn Marino 	  && is_breakpoint (loc->owner)
2167*ef5ccd6cSJohn Marino 	  && loc->pspace->num == bl->pspace->num
2168*ef5ccd6cSJohn Marino 	  && loc->owner->enable_state == bp_enabled
2169*ef5ccd6cSJohn Marino 	  && loc->enabled)
2170*ef5ccd6cSJohn Marino 	/* Add the condition to the vector.  This will be used later to send the
2171*ef5ccd6cSJohn Marino 	   conditions to the target.  */
2172*ef5ccd6cSJohn Marino 	VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2173*ef5ccd6cSJohn Marino 		       loc->cond_bytecode);
2174*ef5ccd6cSJohn Marino     }
2175*ef5ccd6cSJohn Marino 
2176*ef5ccd6cSJohn Marino   return;
2177*ef5ccd6cSJohn Marino }
2178*ef5ccd6cSJohn Marino 
2179*ef5ccd6cSJohn Marino /* Parses a command described by string CMD into an agent expression
2180*ef5ccd6cSJohn Marino    bytecode suitable for evaluation by the bytecode interpreter.
2181*ef5ccd6cSJohn Marino    Return NULL if there was any error during parsing.  */
2182*ef5ccd6cSJohn Marino 
2183*ef5ccd6cSJohn Marino static struct agent_expr *
parse_cmd_to_aexpr(CORE_ADDR scope,char * cmd)2184*ef5ccd6cSJohn Marino parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
2185*ef5ccd6cSJohn Marino {
2186*ef5ccd6cSJohn Marino   struct cleanup *old_cleanups = 0;
2187*ef5ccd6cSJohn Marino   struct expression *expr, **argvec;
2188*ef5ccd6cSJohn Marino   struct agent_expr *aexpr = NULL;
2189*ef5ccd6cSJohn Marino   struct cleanup *old_chain = NULL;
2190*ef5ccd6cSJohn Marino   volatile struct gdb_exception ex;
2191*ef5ccd6cSJohn Marino   const char *cmdrest;
2192*ef5ccd6cSJohn Marino   const char *format_start, *format_end;
2193*ef5ccd6cSJohn Marino   struct format_piece *fpieces;
2194*ef5ccd6cSJohn Marino   int nargs;
2195*ef5ccd6cSJohn Marino   struct gdbarch *gdbarch = get_current_arch ();
2196*ef5ccd6cSJohn Marino 
2197*ef5ccd6cSJohn Marino   if (!cmd)
2198*ef5ccd6cSJohn Marino     return NULL;
2199*ef5ccd6cSJohn Marino 
2200*ef5ccd6cSJohn Marino   cmdrest = cmd;
2201*ef5ccd6cSJohn Marino 
2202*ef5ccd6cSJohn Marino   if (*cmdrest == ',')
2203*ef5ccd6cSJohn Marino     ++cmdrest;
2204*ef5ccd6cSJohn Marino   cmdrest = skip_spaces_const (cmdrest);
2205*ef5ccd6cSJohn Marino 
2206*ef5ccd6cSJohn Marino   if (*cmdrest++ != '"')
2207*ef5ccd6cSJohn Marino     error (_("No format string following the location"));
2208*ef5ccd6cSJohn Marino 
2209*ef5ccd6cSJohn Marino   format_start = cmdrest;
2210*ef5ccd6cSJohn Marino 
2211*ef5ccd6cSJohn Marino   fpieces = parse_format_string (&cmdrest);
2212*ef5ccd6cSJohn Marino 
2213*ef5ccd6cSJohn Marino   old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces);
2214*ef5ccd6cSJohn Marino 
2215*ef5ccd6cSJohn Marino   format_end = cmdrest;
2216*ef5ccd6cSJohn Marino 
2217*ef5ccd6cSJohn Marino   if (*cmdrest++ != '"')
2218*ef5ccd6cSJohn Marino     error (_("Bad format string, non-terminated '\"'."));
2219*ef5ccd6cSJohn Marino 
2220*ef5ccd6cSJohn Marino   cmdrest = skip_spaces_const (cmdrest);
2221*ef5ccd6cSJohn Marino 
2222*ef5ccd6cSJohn Marino   if (!(*cmdrest == ',' || *cmdrest == '\0'))
2223*ef5ccd6cSJohn Marino     error (_("Invalid argument syntax"));
2224*ef5ccd6cSJohn Marino 
2225*ef5ccd6cSJohn Marino   if (*cmdrest == ',')
2226*ef5ccd6cSJohn Marino     cmdrest++;
2227*ef5ccd6cSJohn Marino   cmdrest = skip_spaces_const (cmdrest);
2228*ef5ccd6cSJohn Marino 
2229*ef5ccd6cSJohn Marino   /* For each argument, make an expression.  */
2230*ef5ccd6cSJohn Marino 
2231*ef5ccd6cSJohn Marino   argvec = (struct expression **) alloca (strlen (cmd)
2232*ef5ccd6cSJohn Marino 					 * sizeof (struct expression *));
2233*ef5ccd6cSJohn Marino 
2234*ef5ccd6cSJohn Marino   nargs = 0;
2235*ef5ccd6cSJohn Marino   while (*cmdrest != '\0')
2236*ef5ccd6cSJohn Marino     {
2237*ef5ccd6cSJohn Marino       const char *cmd1;
2238*ef5ccd6cSJohn Marino 
2239*ef5ccd6cSJohn Marino       cmd1 = cmdrest;
2240*ef5ccd6cSJohn Marino       expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
2241*ef5ccd6cSJohn Marino       argvec[nargs++] = expr;
2242*ef5ccd6cSJohn Marino       cmdrest = cmd1;
2243*ef5ccd6cSJohn Marino       if (*cmdrest == ',')
2244*ef5ccd6cSJohn Marino 	++cmdrest;
2245*ef5ccd6cSJohn Marino     }
2246*ef5ccd6cSJohn Marino 
2247*ef5ccd6cSJohn Marino   /* We don't want to stop processing, so catch any errors
2248*ef5ccd6cSJohn Marino      that may show up.  */
2249*ef5ccd6cSJohn Marino   TRY_CATCH (ex, RETURN_MASK_ERROR)
2250*ef5ccd6cSJohn Marino     {
2251*ef5ccd6cSJohn Marino       aexpr = gen_printf (scope, gdbarch, 0, 0,
2252*ef5ccd6cSJohn Marino 			  format_start, format_end - format_start,
2253*ef5ccd6cSJohn Marino 			  fpieces, nargs, argvec);
2254*ef5ccd6cSJohn Marino     }
2255*ef5ccd6cSJohn Marino 
2256*ef5ccd6cSJohn Marino   if (ex.reason < 0)
2257*ef5ccd6cSJohn Marino     {
2258*ef5ccd6cSJohn Marino       /* If we got here, it means the command could not be parsed to a valid
2259*ef5ccd6cSJohn Marino 	 bytecode expression and thus can't be evaluated on the target's side.
2260*ef5ccd6cSJohn Marino 	 It's no use iterating through the other commands.  */
2261*ef5ccd6cSJohn Marino       return NULL;
2262*ef5ccd6cSJohn Marino     }
2263*ef5ccd6cSJohn Marino 
2264*ef5ccd6cSJohn Marino   do_cleanups (old_cleanups);
2265*ef5ccd6cSJohn Marino 
2266*ef5ccd6cSJohn Marino   /* We have a valid agent expression, return it.  */
2267*ef5ccd6cSJohn Marino   return aexpr;
2268*ef5ccd6cSJohn Marino }
2269*ef5ccd6cSJohn Marino 
2270*ef5ccd6cSJohn Marino /* Based on location BL, create a list of breakpoint commands to be
2271*ef5ccd6cSJohn Marino    passed on to the target.  If we have duplicated locations with
2272*ef5ccd6cSJohn Marino    different commands, we will add any such to the list.  */
2273*ef5ccd6cSJohn Marino 
2274*ef5ccd6cSJohn Marino static void
build_target_command_list(struct bp_location * bl)2275*ef5ccd6cSJohn Marino build_target_command_list (struct bp_location *bl)
2276*ef5ccd6cSJohn Marino {
2277*ef5ccd6cSJohn Marino   struct bp_location **locp = NULL, **loc2p;
2278*ef5ccd6cSJohn Marino   int null_command_or_parse_error = 0;
2279*ef5ccd6cSJohn Marino   int modified = bl->needs_update;
2280*ef5ccd6cSJohn Marino   struct bp_location *loc;
2281*ef5ccd6cSJohn Marino 
2282*ef5ccd6cSJohn Marino   /* For now, limit to agent-style dprintf breakpoints.  */
2283*ef5ccd6cSJohn Marino   if (bl->owner->type != bp_dprintf
2284*ef5ccd6cSJohn Marino       || strcmp (dprintf_style, dprintf_style_agent) != 0)
2285*ef5ccd6cSJohn Marino     return;
2286*ef5ccd6cSJohn Marino 
2287*ef5ccd6cSJohn Marino   if (!target_can_run_breakpoint_commands ())
2288*ef5ccd6cSJohn Marino     return;
2289*ef5ccd6cSJohn Marino 
2290*ef5ccd6cSJohn Marino   /* Do a first pass to check for locations with no assigned
2291*ef5ccd6cSJohn Marino      conditions or conditions that fail to parse to a valid agent expression
2292*ef5ccd6cSJohn Marino      bytecode.  If any of these happen, then it's no use to send conditions
2293*ef5ccd6cSJohn Marino      to the target since this location will always trigger and generate a
2294*ef5ccd6cSJohn Marino      response back to GDB.  */
2295*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2296*ef5ccd6cSJohn Marino     {
2297*ef5ccd6cSJohn Marino       loc = (*loc2p);
2298*ef5ccd6cSJohn Marino       if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2299*ef5ccd6cSJohn Marino 	{
2300*ef5ccd6cSJohn Marino 	  if (modified)
2301*ef5ccd6cSJohn Marino 	    {
2302*ef5ccd6cSJohn Marino 	      struct agent_expr *aexpr;
2303*ef5ccd6cSJohn Marino 
2304*ef5ccd6cSJohn Marino 	      /* Re-parse the commands since something changed.  In that
2305*ef5ccd6cSJohn Marino 		 case we already freed the command bytecodes (see
2306*ef5ccd6cSJohn Marino 		 force_breakpoint_reinsertion).  We just
2307*ef5ccd6cSJohn Marino 		 need to parse the command to bytecodes again.  */
2308*ef5ccd6cSJohn Marino 	      aexpr = parse_cmd_to_aexpr (bl->address,
2309*ef5ccd6cSJohn Marino 					  loc->owner->extra_string);
2310*ef5ccd6cSJohn Marino 	      loc->cmd_bytecode = aexpr;
2311*ef5ccd6cSJohn Marino 
2312*ef5ccd6cSJohn Marino 	      if (!aexpr)
2313*ef5ccd6cSJohn Marino 		continue;
2314*ef5ccd6cSJohn Marino 	    }
2315*ef5ccd6cSJohn Marino 
2316*ef5ccd6cSJohn Marino 	  /* If we have a NULL bytecode expression, it means something
2317*ef5ccd6cSJohn Marino 	     went wrong or we have a null command expression.  */
2318*ef5ccd6cSJohn Marino 	  if (!loc->cmd_bytecode)
2319*ef5ccd6cSJohn Marino 	    {
2320*ef5ccd6cSJohn Marino 	      null_command_or_parse_error = 1;
2321*ef5ccd6cSJohn Marino 	      break;
2322*ef5ccd6cSJohn Marino 	    }
2323*ef5ccd6cSJohn Marino 	}
2324*ef5ccd6cSJohn Marino     }
2325*ef5ccd6cSJohn Marino 
2326*ef5ccd6cSJohn Marino   /* If anything failed, then we're not doing target-side commands,
2327*ef5ccd6cSJohn Marino      and so clean up.  */
2328*ef5ccd6cSJohn Marino   if (null_command_or_parse_error)
2329*ef5ccd6cSJohn Marino     {
2330*ef5ccd6cSJohn Marino       ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2331*ef5ccd6cSJohn Marino 	{
2332*ef5ccd6cSJohn Marino 	  loc = (*loc2p);
2333*ef5ccd6cSJohn Marino 	  if (is_breakpoint (loc->owner)
2334*ef5ccd6cSJohn Marino 	      && loc->pspace->num == bl->pspace->num)
2335*ef5ccd6cSJohn Marino 	    {
2336*ef5ccd6cSJohn Marino 	      /* Only go as far as the first NULL bytecode is
2337*ef5ccd6cSJohn Marino 		 located.  */
2338*ef5ccd6cSJohn Marino 	      if (loc->cmd_bytecode == NULL)
2339*ef5ccd6cSJohn Marino 		return;
2340*ef5ccd6cSJohn Marino 
2341*ef5ccd6cSJohn Marino 	      free_agent_expr (loc->cmd_bytecode);
2342*ef5ccd6cSJohn Marino 	      loc->cmd_bytecode = NULL;
2343*ef5ccd6cSJohn Marino 	    }
2344*ef5ccd6cSJohn Marino 	}
2345*ef5ccd6cSJohn Marino     }
2346*ef5ccd6cSJohn Marino 
2347*ef5ccd6cSJohn Marino   /* No NULL commands or failed bytecode generation.  Build a command list
2348*ef5ccd6cSJohn Marino      for this location's address.  */
2349*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2350*ef5ccd6cSJohn Marino     {
2351*ef5ccd6cSJohn Marino       loc = (*loc2p);
2352*ef5ccd6cSJohn Marino       if (loc->owner->extra_string
2353*ef5ccd6cSJohn Marino 	  && is_breakpoint (loc->owner)
2354*ef5ccd6cSJohn Marino 	  && loc->pspace->num == bl->pspace->num
2355*ef5ccd6cSJohn Marino 	  && loc->owner->enable_state == bp_enabled
2356*ef5ccd6cSJohn Marino 	  && loc->enabled)
2357*ef5ccd6cSJohn Marino 	/* Add the command to the vector.  This will be used later
2358*ef5ccd6cSJohn Marino 	   to send the commands to the target.  */
2359*ef5ccd6cSJohn Marino 	VEC_safe_push (agent_expr_p, bl->target_info.tcommands,
2360*ef5ccd6cSJohn Marino 		       loc->cmd_bytecode);
2361*ef5ccd6cSJohn Marino     }
2362*ef5ccd6cSJohn Marino 
2363*ef5ccd6cSJohn Marino   bl->target_info.persist = 0;
2364*ef5ccd6cSJohn Marino   /* Maybe flag this location as persistent.  */
2365*ef5ccd6cSJohn Marino   if (bl->owner->type == bp_dprintf && disconnected_dprintf)
2366*ef5ccd6cSJohn Marino     bl->target_info.persist = 1;
2367*ef5ccd6cSJohn Marino }
2368*ef5ccd6cSJohn Marino 
2369c50c785cSJohn Marino /* Insert a low-level "breakpoint" of some type.  BL is the breakpoint
2370c50c785cSJohn Marino    location.  Any error messages are printed to TMP_ERROR_STREAM; and
2371c50c785cSJohn Marino    DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2372a45ae5f8SJohn Marino    Returns 0 for success, 1 if the bp_location type is not supported or
2373a45ae5f8SJohn Marino    -1 for failure.
23745796c8dcSSimon Schubert 
2375c50c785cSJohn Marino    NOTE drow/2003-09-09: This routine could be broken down to an
2376c50c785cSJohn Marino    object-style method for each breakpoint or catchpoint type.  */
23775796c8dcSSimon Schubert 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)2378c50c785cSJohn Marino insert_bp_location (struct bp_location *bl,
23795796c8dcSSimon Schubert 		    struct ui_file *tmp_error_stream,
23805796c8dcSSimon Schubert 		    int *disabled_breaks,
2381*ef5ccd6cSJohn Marino 		    int *hw_breakpoint_error,
2382*ef5ccd6cSJohn Marino 		    int *hw_bp_error_explained_already)
23835796c8dcSSimon Schubert {
23845796c8dcSSimon Schubert   int val = 0;
2385*ef5ccd6cSJohn Marino   char *hw_bp_err_string = NULL;
2386*ef5ccd6cSJohn Marino   struct gdb_exception e;
23875796c8dcSSimon Schubert 
2388*ef5ccd6cSJohn Marino   if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
23895796c8dcSSimon Schubert     return 0;
23905796c8dcSSimon Schubert 
2391*ef5ccd6cSJohn Marino   /* Note we don't initialize bl->target_info, as that wipes out
2392*ef5ccd6cSJohn Marino      the breakpoint location's shadow_contents if the breakpoint
2393*ef5ccd6cSJohn Marino      is still inserted at that location.  This in turn breaks
2394*ef5ccd6cSJohn Marino      target_read_memory which depends on these buffers when
2395*ef5ccd6cSJohn Marino      a memory read is requested at the breakpoint location:
2396*ef5ccd6cSJohn Marino      Once the target_info has been wiped, we fail to see that
2397*ef5ccd6cSJohn Marino      we have a breakpoint inserted at that address and thus
2398*ef5ccd6cSJohn Marino      read the breakpoint instead of returning the data saved in
2399*ef5ccd6cSJohn Marino      the breakpoint location's shadow contents.  */
2400c50c785cSJohn Marino   bl->target_info.placed_address = bl->address;
2401c50c785cSJohn Marino   bl->target_info.placed_address_space = bl->pspace->aspace;
2402c50c785cSJohn Marino   bl->target_info.length = bl->length;
24035796c8dcSSimon Schubert 
2404*ef5ccd6cSJohn Marino   /* When working with target-side conditions, we must pass all the conditions
2405*ef5ccd6cSJohn Marino      for the same breakpoint address down to the target since GDB will not
2406*ef5ccd6cSJohn Marino      insert those locations.  With a list of breakpoint conditions, the target
2407*ef5ccd6cSJohn Marino      can decide when to stop and notify GDB.  */
2408*ef5ccd6cSJohn Marino 
2409*ef5ccd6cSJohn Marino   if (is_breakpoint (bl->owner))
2410*ef5ccd6cSJohn Marino     {
2411*ef5ccd6cSJohn Marino       build_target_condition_list (bl);
2412*ef5ccd6cSJohn Marino       build_target_command_list (bl);
2413*ef5ccd6cSJohn Marino       /* Reset the modification marker.  */
2414*ef5ccd6cSJohn Marino       bl->needs_update = 0;
2415*ef5ccd6cSJohn Marino     }
2416*ef5ccd6cSJohn Marino 
2417c50c785cSJohn Marino   if (bl->loc_type == bp_loc_software_breakpoint
2418c50c785cSJohn Marino       || bl->loc_type == bp_loc_hardware_breakpoint)
24195796c8dcSSimon Schubert     {
2420c50c785cSJohn Marino       if (bl->owner->type != bp_hardware_breakpoint)
24215796c8dcSSimon Schubert 	{
24225796c8dcSSimon Schubert 	  /* If the explicitly specified breakpoint type
24235796c8dcSSimon Schubert 	     is not hardware breakpoint, check the memory map to see
24245796c8dcSSimon Schubert 	     if the breakpoint address is in read only memory or not.
2425c50c785cSJohn Marino 
24265796c8dcSSimon Schubert 	     Two important cases are:
24275796c8dcSSimon Schubert 	     - location type is not hardware breakpoint, memory
24285796c8dcSSimon Schubert 	     is readonly.  We change the type of the location to
24295796c8dcSSimon Schubert 	     hardware breakpoint.
2430c50c785cSJohn Marino 	     - location type is hardware breakpoint, memory is
2431c50c785cSJohn Marino 	     read-write.  This means we've previously made the
2432c50c785cSJohn Marino 	     location hardware one, but then the memory map changed,
2433c50c785cSJohn Marino 	     so we undo.
24345796c8dcSSimon Schubert 
2435c50c785cSJohn Marino 	     When breakpoints are removed, remove_breakpoints will use
2436c50c785cSJohn Marino 	     location types we've just set here, the only possible
2437c50c785cSJohn Marino 	     problem is that memory map has changed during running
2438c50c785cSJohn Marino 	     program, but it's not going to work anyway with current
2439c50c785cSJohn Marino 	     gdb.  */
24405796c8dcSSimon Schubert 	  struct mem_region *mr
2441c50c785cSJohn Marino 	    = lookup_mem_region (bl->target_info.placed_address);
24425796c8dcSSimon Schubert 
24435796c8dcSSimon Schubert 	  if (mr)
24445796c8dcSSimon Schubert 	    {
24455796c8dcSSimon Schubert 	      if (automatic_hardware_breakpoints)
24465796c8dcSSimon Schubert 		{
24475796c8dcSSimon Schubert 		  enum bp_loc_type new_type;
24485796c8dcSSimon Schubert 
24495796c8dcSSimon Schubert 		  if (mr->attrib.mode != MEM_RW)
24505796c8dcSSimon Schubert 		    new_type = bp_loc_hardware_breakpoint;
24515796c8dcSSimon Schubert 		  else
24525796c8dcSSimon Schubert 		    new_type = bp_loc_software_breakpoint;
24535796c8dcSSimon Schubert 
2454c50c785cSJohn Marino 		  if (new_type != bl->loc_type)
24555796c8dcSSimon Schubert 		    {
24565796c8dcSSimon Schubert 		      static int said = 0;
2457cf7f2e2dSJohn Marino 
2458c50c785cSJohn Marino 		      bl->loc_type = new_type;
24595796c8dcSSimon Schubert 		      if (!said)
24605796c8dcSSimon Schubert 			{
2461c50c785cSJohn Marino 			  fprintf_filtered (gdb_stdout,
2462c50c785cSJohn Marino 					    _("Note: automatically using "
2463c50c785cSJohn Marino 					      "hardware breakpoints for "
2464c50c785cSJohn Marino 					      "read-only addresses.\n"));
24655796c8dcSSimon Schubert 			  said = 1;
24665796c8dcSSimon Schubert 			}
24675796c8dcSSimon Schubert 		    }
24685796c8dcSSimon Schubert 		}
2469c50c785cSJohn Marino 	      else if (bl->loc_type == bp_loc_software_breakpoint
24705796c8dcSSimon Schubert 		       && mr->attrib.mode != MEM_RW)
2471c50c785cSJohn Marino 		warning (_("cannot set software breakpoint "
2472c50c785cSJohn Marino 			   "at readonly address %s"),
2473c50c785cSJohn Marino 			 paddress (bl->gdbarch, bl->address));
24745796c8dcSSimon Schubert 	    }
24755796c8dcSSimon Schubert 	}
24765796c8dcSSimon Schubert 
24775796c8dcSSimon Schubert       /* First check to see if we have to handle an overlay.  */
24785796c8dcSSimon Schubert       if (overlay_debugging == ovly_off
2479c50c785cSJohn Marino 	  || bl->section == NULL
2480c50c785cSJohn Marino 	  || !(section_is_overlay (bl->section)))
24815796c8dcSSimon Schubert 	{
24825796c8dcSSimon Schubert 	  /* No overlay handling: just set the breakpoint.  */
2483*ef5ccd6cSJohn Marino 	  TRY_CATCH (e, RETURN_MASK_ALL)
2484*ef5ccd6cSJohn Marino 	    {
2485a45ae5f8SJohn Marino 	      val = bl->owner->ops->insert_location (bl);
24865796c8dcSSimon Schubert 	    }
2487*ef5ccd6cSJohn Marino 	  if (e.reason < 0)
2488*ef5ccd6cSJohn Marino 	    {
2489*ef5ccd6cSJohn Marino 	      val = 1;
2490*ef5ccd6cSJohn Marino 	      hw_bp_err_string = (char *) e.message;
2491*ef5ccd6cSJohn Marino 	    }
2492*ef5ccd6cSJohn Marino 	}
24935796c8dcSSimon Schubert       else
24945796c8dcSSimon Schubert 	{
24955796c8dcSSimon Schubert 	  /* This breakpoint is in an overlay section.
24965796c8dcSSimon Schubert 	     Shall we set a breakpoint at the LMA?  */
24975796c8dcSSimon Schubert 	  if (!overlay_events_enabled)
24985796c8dcSSimon Schubert 	    {
24995796c8dcSSimon Schubert 	      /* Yes -- overlay event support is not active,
25005796c8dcSSimon Schubert 		 so we must try to set a breakpoint at the LMA.
25015796c8dcSSimon Schubert 		 This will not work for a hardware breakpoint.  */
2502c50c785cSJohn Marino 	      if (bl->loc_type == bp_loc_hardware_breakpoint)
25035796c8dcSSimon Schubert 		warning (_("hardware breakpoint %d not supported in overlay!"),
2504c50c785cSJohn Marino 			 bl->owner->number);
25055796c8dcSSimon Schubert 	      else
25065796c8dcSSimon Schubert 		{
2507c50c785cSJohn Marino 		  CORE_ADDR addr = overlay_unmapped_address (bl->address,
2508c50c785cSJohn Marino 							     bl->section);
25095796c8dcSSimon Schubert 		  /* Set a software (trap) breakpoint at the LMA.  */
2510c50c785cSJohn Marino 		  bl->overlay_target_info = bl->target_info;
2511c50c785cSJohn Marino 		  bl->overlay_target_info.placed_address = addr;
2512c50c785cSJohn Marino 		  val = target_insert_breakpoint (bl->gdbarch,
2513c50c785cSJohn Marino 						  &bl->overlay_target_info);
25145796c8dcSSimon Schubert 		  if (val != 0)
25155796c8dcSSimon Schubert 		    fprintf_unfiltered (tmp_error_stream,
2516c50c785cSJohn Marino 					"Overlay breakpoint %d "
2517c50c785cSJohn Marino 					"failed: in ROM?\n",
2518c50c785cSJohn Marino 					bl->owner->number);
25195796c8dcSSimon Schubert 		}
25205796c8dcSSimon Schubert 	    }
25215796c8dcSSimon Schubert 	  /* Shall we set a breakpoint at the VMA? */
2522c50c785cSJohn Marino 	  if (section_is_mapped (bl->section))
25235796c8dcSSimon Schubert 	    {
25245796c8dcSSimon Schubert 	      /* Yes.  This overlay section is mapped into memory.  */
2525*ef5ccd6cSJohn Marino 	      TRY_CATCH (e, RETURN_MASK_ALL)
2526*ef5ccd6cSJohn Marino 	        {
2527a45ae5f8SJohn Marino 	          val = bl->owner->ops->insert_location (bl);
25285796c8dcSSimon Schubert 	        }
2529*ef5ccd6cSJohn Marino 	      if (e.reason < 0)
2530*ef5ccd6cSJohn Marino 	        {
2531*ef5ccd6cSJohn Marino 	          val = 1;
2532*ef5ccd6cSJohn Marino 	          hw_bp_err_string = (char *) e.message;
2533*ef5ccd6cSJohn Marino 	        }
2534*ef5ccd6cSJohn Marino 	    }
25355796c8dcSSimon Schubert 	  else
25365796c8dcSSimon Schubert 	    {
25375796c8dcSSimon Schubert 	      /* No.  This breakpoint will not be inserted.
25385796c8dcSSimon Schubert 		 No error, but do not mark the bp as 'inserted'.  */
25395796c8dcSSimon Schubert 	      return 0;
25405796c8dcSSimon Schubert 	    }
25415796c8dcSSimon Schubert 	}
25425796c8dcSSimon Schubert 
25435796c8dcSSimon Schubert       if (val)
25445796c8dcSSimon Schubert 	{
25455796c8dcSSimon Schubert 	  /* Can't set the breakpoint.  */
2546c50c785cSJohn Marino 	  if (solib_name_from_address (bl->pspace, bl->address))
25475796c8dcSSimon Schubert 	    {
25485796c8dcSSimon Schubert 	      /* See also: disable_breakpoints_in_shlibs.  */
25495796c8dcSSimon Schubert 	      val = 0;
2550c50c785cSJohn Marino 	      bl->shlib_disabled = 1;
2551a45ae5f8SJohn Marino 	      observer_notify_breakpoint_modified (bl->owner);
25525796c8dcSSimon Schubert 	      if (!*disabled_breaks)
25535796c8dcSSimon Schubert 		{
25545796c8dcSSimon Schubert 		  fprintf_unfiltered (tmp_error_stream,
25555796c8dcSSimon Schubert 				      "Cannot insert breakpoint %d.\n",
2556c50c785cSJohn Marino 				      bl->owner->number);
25575796c8dcSSimon Schubert 		  fprintf_unfiltered (tmp_error_stream,
2558c50c785cSJohn Marino 				      "Temporarily disabling shared "
2559c50c785cSJohn Marino 				      "library breakpoints:\n");
25605796c8dcSSimon Schubert 		}
25615796c8dcSSimon Schubert 	      *disabled_breaks = 1;
25625796c8dcSSimon Schubert 	      fprintf_unfiltered (tmp_error_stream,
2563c50c785cSJohn Marino 				  "breakpoint #%d\n", bl->owner->number);
25645796c8dcSSimon Schubert 	    }
25655796c8dcSSimon Schubert 	  else
25665796c8dcSSimon Schubert 	    {
2567c50c785cSJohn Marino 	      if (bl->loc_type == bp_loc_hardware_breakpoint)
25685796c8dcSSimon Schubert 		{
25695796c8dcSSimon Schubert                   *hw_breakpoint_error = 1;
2570*ef5ccd6cSJohn Marino                   *hw_bp_error_explained_already = hw_bp_err_string != NULL;
25715796c8dcSSimon Schubert                   fprintf_unfiltered (tmp_error_stream,
2572*ef5ccd6cSJohn Marino                                       "Cannot insert hardware breakpoint %d%s",
2573*ef5ccd6cSJohn Marino                                       bl->owner->number, hw_bp_err_string ? ":" : ".\n");
2574*ef5ccd6cSJohn Marino                   if (hw_bp_err_string)
2575*ef5ccd6cSJohn Marino                     fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string);
25765796c8dcSSimon Schubert 		}
25775796c8dcSSimon Schubert 	      else
25785796c8dcSSimon Schubert 		{
25795796c8dcSSimon Schubert 		  fprintf_unfiltered (tmp_error_stream,
25805796c8dcSSimon Schubert 				      "Cannot insert breakpoint %d.\n",
2581c50c785cSJohn Marino 				      bl->owner->number);
25825796c8dcSSimon Schubert 		  fprintf_filtered (tmp_error_stream,
25835796c8dcSSimon Schubert 				    "Error accessing memory address ");
2584c50c785cSJohn Marino 		  fputs_filtered (paddress (bl->gdbarch, bl->address),
25855796c8dcSSimon Schubert 				  tmp_error_stream);
25865796c8dcSSimon Schubert 		  fprintf_filtered (tmp_error_stream, ": %s.\n",
25875796c8dcSSimon Schubert 				    safe_strerror (val));
25885796c8dcSSimon Schubert 		}
25895796c8dcSSimon Schubert 
25905796c8dcSSimon Schubert 	    }
25915796c8dcSSimon Schubert 	}
25925796c8dcSSimon Schubert       else
2593c50c785cSJohn Marino 	bl->inserted = 1;
25945796c8dcSSimon Schubert 
25955796c8dcSSimon Schubert       return val;
25965796c8dcSSimon Schubert     }
25975796c8dcSSimon Schubert 
2598c50c785cSJohn Marino   else if (bl->loc_type == bp_loc_hardware_watchpoint
25995796c8dcSSimon Schubert 	   /* NOTE drow/2003-09-08: This state only exists for removing
26005796c8dcSSimon Schubert 	      watchpoints.  It's not clear that it's necessary...  */
2601c50c785cSJohn Marino 	   && bl->owner->disposition != disp_del_at_next_stop)
26025796c8dcSSimon Schubert     {
2603c50c785cSJohn Marino       gdb_assert (bl->owner->ops != NULL
2604c50c785cSJohn Marino 		  && bl->owner->ops->insert_location != NULL);
2605c50c785cSJohn Marino 
2606c50c785cSJohn Marino       val = bl->owner->ops->insert_location (bl);
2607cf7f2e2dSJohn Marino 
2608cf7f2e2dSJohn Marino       /* If trying to set a read-watchpoint, and it turns out it's not
2609cf7f2e2dSJohn Marino 	 supported, try emulating one with an access watchpoint.  */
2610c50c785cSJohn Marino       if (val == 1 && bl->watchpoint_type == hw_read)
2611cf7f2e2dSJohn Marino 	{
2612cf7f2e2dSJohn Marino 	  struct bp_location *loc, **loc_temp;
2613cf7f2e2dSJohn Marino 
2614cf7f2e2dSJohn Marino 	  /* But don't try to insert it, if there's already another
2615cf7f2e2dSJohn Marino 	     hw_access location that would be considered a duplicate
2616cf7f2e2dSJohn Marino 	     of this one.  */
2617cf7f2e2dSJohn Marino 	  ALL_BP_LOCATIONS (loc, loc_temp)
2618c50c785cSJohn Marino 	    if (loc != bl
2619cf7f2e2dSJohn Marino 		&& loc->watchpoint_type == hw_access
2620c50c785cSJohn Marino 		&& watchpoint_locations_match (bl, loc))
2621cf7f2e2dSJohn Marino 	      {
2622c50c785cSJohn Marino 		bl->duplicate = 1;
2623c50c785cSJohn Marino 		bl->inserted = 1;
2624c50c785cSJohn Marino 		bl->target_info = loc->target_info;
2625c50c785cSJohn Marino 		bl->watchpoint_type = hw_access;
2626cf7f2e2dSJohn Marino 		val = 0;
2627cf7f2e2dSJohn Marino 		break;
2628cf7f2e2dSJohn Marino 	      }
2629cf7f2e2dSJohn Marino 
2630cf7f2e2dSJohn Marino 	  if (val == 1)
2631cf7f2e2dSJohn Marino 	    {
2632c50c785cSJohn Marino 	      bl->watchpoint_type = hw_access;
2633c50c785cSJohn Marino 	      val = bl->owner->ops->insert_location (bl);
2634c50c785cSJohn Marino 
2635c50c785cSJohn Marino 	      if (val)
2636c50c785cSJohn Marino 		/* Back to the original value.  */
2637c50c785cSJohn Marino 		bl->watchpoint_type = hw_read;
2638cf7f2e2dSJohn Marino 	    }
2639cf7f2e2dSJohn Marino 	}
2640cf7f2e2dSJohn Marino 
2641c50c785cSJohn Marino       bl->inserted = (val == 0);
26425796c8dcSSimon Schubert     }
26435796c8dcSSimon Schubert 
2644c50c785cSJohn Marino   else if (bl->owner->type == bp_catchpoint)
26455796c8dcSSimon Schubert     {
2646c50c785cSJohn Marino       gdb_assert (bl->owner->ops != NULL
2647c50c785cSJohn Marino 		  && bl->owner->ops->insert_location != NULL);
2648c50c785cSJohn Marino 
2649c50c785cSJohn Marino       val = bl->owner->ops->insert_location (bl);
2650c50c785cSJohn Marino       if (val)
2651c50c785cSJohn Marino 	{
2652c50c785cSJohn Marino 	  bl->owner->enable_state = bp_disabled;
2653c50c785cSJohn Marino 
2654c50c785cSJohn Marino 	  if (val == 1)
2655c50c785cSJohn Marino 	    warning (_("\
2656c50c785cSJohn Marino Error inserting catchpoint %d: Your system does not support this type\n\
2657c50c785cSJohn Marino of catchpoint."), bl->owner->number);
26585796c8dcSSimon Schubert 	  else
2659c50c785cSJohn Marino 	    warning (_("Error inserting catchpoint %d."), bl->owner->number);
2660c50c785cSJohn Marino 	}
2661c50c785cSJohn Marino 
2662c50c785cSJohn Marino       bl->inserted = (val == 0);
26635796c8dcSSimon Schubert 
26645796c8dcSSimon Schubert       /* We've already printed an error message if there was a problem
26655796c8dcSSimon Schubert 	 inserting this catchpoint, and we've disabled the catchpoint,
26665796c8dcSSimon Schubert 	 so just return success.  */
26675796c8dcSSimon Schubert       return 0;
26685796c8dcSSimon Schubert     }
26695796c8dcSSimon Schubert 
26705796c8dcSSimon Schubert   return 0;
26715796c8dcSSimon Schubert }
26725796c8dcSSimon Schubert 
2673cf7f2e2dSJohn Marino /* This function is called when program space PSPACE is about to be
2674cf7f2e2dSJohn Marino    deleted.  It takes care of updating breakpoints to not reference
2675cf7f2e2dSJohn Marino    PSPACE anymore.  */
2676cf7f2e2dSJohn Marino 
2677cf7f2e2dSJohn Marino void
breakpoint_program_space_exit(struct program_space * pspace)2678cf7f2e2dSJohn Marino breakpoint_program_space_exit (struct program_space *pspace)
2679cf7f2e2dSJohn Marino {
2680cf7f2e2dSJohn Marino   struct breakpoint *b, *b_temp;
2681cf7f2e2dSJohn Marino   struct bp_location *loc, **loc_temp;
2682cf7f2e2dSJohn Marino 
2683cf7f2e2dSJohn Marino   /* Remove any breakpoint that was set through this program space.  */
2684cf7f2e2dSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_temp)
2685cf7f2e2dSJohn Marino     {
2686cf7f2e2dSJohn Marino       if (b->pspace == pspace)
2687cf7f2e2dSJohn Marino 	delete_breakpoint (b);
2688cf7f2e2dSJohn Marino     }
2689cf7f2e2dSJohn Marino 
2690cf7f2e2dSJohn Marino   /* Breakpoints set through other program spaces could have locations
2691cf7f2e2dSJohn Marino      bound to PSPACE as well.  Remove those.  */
2692cf7f2e2dSJohn Marino   ALL_BP_LOCATIONS (loc, loc_temp)
2693cf7f2e2dSJohn Marino     {
2694cf7f2e2dSJohn Marino       struct bp_location *tmp;
2695cf7f2e2dSJohn Marino 
2696cf7f2e2dSJohn Marino       if (loc->pspace == pspace)
2697cf7f2e2dSJohn Marino 	{
2698cf7f2e2dSJohn Marino 	  /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL.  */
2699cf7f2e2dSJohn Marino 	  if (loc->owner->loc == loc)
2700cf7f2e2dSJohn Marino 	    loc->owner->loc = loc->next;
2701cf7f2e2dSJohn Marino 	  else
2702cf7f2e2dSJohn Marino 	    for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2703cf7f2e2dSJohn Marino 	      if (tmp->next == loc)
2704cf7f2e2dSJohn Marino 		{
2705cf7f2e2dSJohn Marino 		  tmp->next = loc->next;
2706cf7f2e2dSJohn Marino 		  break;
2707cf7f2e2dSJohn Marino 		}
2708cf7f2e2dSJohn Marino 	}
2709cf7f2e2dSJohn Marino     }
2710cf7f2e2dSJohn Marino 
2711cf7f2e2dSJohn Marino   /* Now update the global location list to permanently delete the
2712cf7f2e2dSJohn Marino      removed locations above.  */
2713cf7f2e2dSJohn Marino   update_global_location_list (0);
2714cf7f2e2dSJohn Marino }
2715cf7f2e2dSJohn Marino 
27165796c8dcSSimon Schubert /* Make sure all breakpoints are inserted in inferior.
27175796c8dcSSimon Schubert    Throws exception on any error.
27185796c8dcSSimon Schubert    A breakpoint that is already inserted won't be inserted
27195796c8dcSSimon Schubert    again, so calling this function twice is safe.  */
27205796c8dcSSimon Schubert void
insert_breakpoints(void)27215796c8dcSSimon Schubert insert_breakpoints (void)
27225796c8dcSSimon Schubert {
27235796c8dcSSimon Schubert   struct breakpoint *bpt;
27245796c8dcSSimon Schubert 
27255796c8dcSSimon Schubert   ALL_BREAKPOINTS (bpt)
27265796c8dcSSimon Schubert     if (is_hardware_watchpoint (bpt))
2727a45ae5f8SJohn Marino       {
2728a45ae5f8SJohn Marino 	struct watchpoint *w = (struct watchpoint *) bpt;
2729a45ae5f8SJohn Marino 
2730a45ae5f8SJohn Marino 	update_watchpoint (w, 0 /* don't reparse.  */);
2731a45ae5f8SJohn Marino       }
27325796c8dcSSimon Schubert 
27335796c8dcSSimon Schubert   update_global_location_list (1);
27345796c8dcSSimon Schubert 
27355796c8dcSSimon Schubert   /* update_global_location_list does not insert breakpoints when
27365796c8dcSSimon Schubert      always_inserted_mode is not enabled.  Explicitly insert them
27375796c8dcSSimon Schubert      now.  */
27385796c8dcSSimon Schubert   if (!breakpoints_always_inserted_mode ())
27395796c8dcSSimon Schubert     insert_breakpoint_locations ();
27405796c8dcSSimon Schubert }
27415796c8dcSSimon Schubert 
2742*ef5ccd6cSJohn Marino /* Invoke CALLBACK for each of bp_location.  */
2743*ef5ccd6cSJohn Marino 
2744*ef5ccd6cSJohn Marino void
iterate_over_bp_locations(walk_bp_location_callback callback)2745*ef5ccd6cSJohn Marino iterate_over_bp_locations (walk_bp_location_callback callback)
2746*ef5ccd6cSJohn Marino {
2747*ef5ccd6cSJohn Marino   struct bp_location *loc, **loc_tmp;
2748*ef5ccd6cSJohn Marino 
2749*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS (loc, loc_tmp)
2750*ef5ccd6cSJohn Marino     {
2751*ef5ccd6cSJohn Marino       callback (loc, NULL);
2752*ef5ccd6cSJohn Marino     }
2753*ef5ccd6cSJohn Marino }
2754*ef5ccd6cSJohn Marino 
2755*ef5ccd6cSJohn Marino /* This is used when we need to synch breakpoint conditions between GDB and the
2756*ef5ccd6cSJohn Marino    target.  It is the case with deleting and disabling of breakpoints when using
2757*ef5ccd6cSJohn Marino    always-inserted mode.  */
27585796c8dcSSimon Schubert 
27595796c8dcSSimon Schubert static void
update_inserted_breakpoint_locations(void)2760*ef5ccd6cSJohn Marino update_inserted_breakpoint_locations (void)
27615796c8dcSSimon Schubert {
2762c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
2763a45ae5f8SJohn Marino   int error_flag = 0;
27645796c8dcSSimon Schubert   int val = 0;
27655796c8dcSSimon Schubert   int disabled_breaks = 0;
27665796c8dcSSimon Schubert   int hw_breakpoint_error = 0;
2767*ef5ccd6cSJohn Marino   int hw_bp_details_reported = 0;
27685796c8dcSSimon Schubert 
27695796c8dcSSimon Schubert   struct ui_file *tmp_error_stream = mem_fileopen ();
27705796c8dcSSimon Schubert   struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
27715796c8dcSSimon Schubert 
27725796c8dcSSimon Schubert   /* Explicitly mark the warning -- this will only be printed if
27735796c8dcSSimon Schubert      there was an error.  */
27745796c8dcSSimon Schubert   fprintf_unfiltered (tmp_error_stream, "Warning:\n");
27755796c8dcSSimon Schubert 
2776cf7f2e2dSJohn Marino   save_current_space_and_thread ();
2777cf7f2e2dSJohn Marino 
2778c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
27795796c8dcSSimon Schubert     {
2780*ef5ccd6cSJohn Marino       /* We only want to update software breakpoints and hardware
2781*ef5ccd6cSJohn Marino 	 breakpoints.  */
2782*ef5ccd6cSJohn Marino       if (!is_breakpoint (bl->owner))
2783*ef5ccd6cSJohn Marino 	continue;
2784*ef5ccd6cSJohn Marino 
2785*ef5ccd6cSJohn Marino       /* We only want to update locations that are already inserted
2786*ef5ccd6cSJohn Marino 	 and need updating.  This is to avoid unwanted insertion during
2787*ef5ccd6cSJohn Marino 	 deletion of breakpoints.  */
2788*ef5ccd6cSJohn Marino       if (!bl->inserted || (bl->inserted && !bl->needs_update))
2789*ef5ccd6cSJohn Marino 	continue;
2790*ef5ccd6cSJohn Marino 
2791*ef5ccd6cSJohn Marino       switch_to_program_space_and_thread (bl->pspace);
2792*ef5ccd6cSJohn Marino 
2793*ef5ccd6cSJohn Marino       /* For targets that support global breakpoints, there's no need
2794*ef5ccd6cSJohn Marino 	 to select an inferior to insert breakpoint to.  In fact, even
2795*ef5ccd6cSJohn Marino 	 if we aren't attached to any process yet, we should still
2796*ef5ccd6cSJohn Marino 	 insert breakpoints.  */
2797*ef5ccd6cSJohn Marino       if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2798*ef5ccd6cSJohn Marino 	  && ptid_equal (inferior_ptid, null_ptid))
2799*ef5ccd6cSJohn Marino 	continue;
2800*ef5ccd6cSJohn Marino 
2801*ef5ccd6cSJohn Marino       val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2802*ef5ccd6cSJohn Marino 				    &hw_breakpoint_error, &hw_bp_details_reported);
2803*ef5ccd6cSJohn Marino       if (val)
2804*ef5ccd6cSJohn Marino 	error_flag = val;
2805*ef5ccd6cSJohn Marino     }
2806*ef5ccd6cSJohn Marino 
2807*ef5ccd6cSJohn Marino   if (error_flag)
2808*ef5ccd6cSJohn Marino     {
2809*ef5ccd6cSJohn Marino       target_terminal_ours_for_output ();
2810*ef5ccd6cSJohn Marino       error_stream (tmp_error_stream);
2811*ef5ccd6cSJohn Marino     }
2812*ef5ccd6cSJohn Marino 
2813*ef5ccd6cSJohn Marino   do_cleanups (cleanups);
2814*ef5ccd6cSJohn Marino }
2815*ef5ccd6cSJohn Marino 
2816*ef5ccd6cSJohn Marino /* Used when starting or continuing the program.  */
2817*ef5ccd6cSJohn Marino 
2818*ef5ccd6cSJohn Marino static void
insert_breakpoint_locations(void)2819*ef5ccd6cSJohn Marino insert_breakpoint_locations (void)
2820*ef5ccd6cSJohn Marino {
2821*ef5ccd6cSJohn Marino   struct breakpoint *bpt;
2822*ef5ccd6cSJohn Marino   struct bp_location *bl, **blp_tmp;
2823*ef5ccd6cSJohn Marino   int error_flag = 0;
2824*ef5ccd6cSJohn Marino   int val = 0;
2825*ef5ccd6cSJohn Marino   int disabled_breaks = 0;
2826*ef5ccd6cSJohn Marino   int hw_breakpoint_error = 0;
2827*ef5ccd6cSJohn Marino   int hw_bp_error_explained_already = 0;
2828*ef5ccd6cSJohn Marino 
2829*ef5ccd6cSJohn Marino   struct ui_file *tmp_error_stream = mem_fileopen ();
2830*ef5ccd6cSJohn Marino   struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2831*ef5ccd6cSJohn Marino 
2832*ef5ccd6cSJohn Marino   /* Explicitly mark the warning -- this will only be printed if
2833*ef5ccd6cSJohn Marino      there was an error.  */
2834*ef5ccd6cSJohn Marino   fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2835*ef5ccd6cSJohn Marino 
2836*ef5ccd6cSJohn Marino   save_current_space_and_thread ();
2837*ef5ccd6cSJohn Marino 
2838*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
2839*ef5ccd6cSJohn Marino     {
2840*ef5ccd6cSJohn Marino       if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
28415796c8dcSSimon Schubert 	continue;
28425796c8dcSSimon Schubert 
2843c50c785cSJohn Marino       /* There is no point inserting thread-specific breakpoints if
2844c50c785cSJohn Marino 	 the thread no longer exists.  ALL_BP_LOCATIONS bp_location
2845c50c785cSJohn Marino 	 has BL->OWNER always non-NULL.  */
2846c50c785cSJohn Marino       if (bl->owner->thread != -1
2847c50c785cSJohn Marino 	  && !valid_thread_id (bl->owner->thread))
28485796c8dcSSimon Schubert 	continue;
28495796c8dcSSimon Schubert 
2850c50c785cSJohn Marino       switch_to_program_space_and_thread (bl->pspace);
2851cf7f2e2dSJohn Marino 
2852cf7f2e2dSJohn Marino       /* For targets that support global breakpoints, there's no need
2853cf7f2e2dSJohn Marino 	 to select an inferior to insert breakpoint to.  In fact, even
2854cf7f2e2dSJohn Marino 	 if we aren't attached to any process yet, we should still
2855cf7f2e2dSJohn Marino 	 insert breakpoints.  */
2856*ef5ccd6cSJohn Marino       if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2857cf7f2e2dSJohn Marino 	  && ptid_equal (inferior_ptid, null_ptid))
2858cf7f2e2dSJohn Marino 	continue;
2859cf7f2e2dSJohn Marino 
2860c50c785cSJohn Marino       val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2861*ef5ccd6cSJohn Marino 				    &hw_breakpoint_error, &hw_bp_error_explained_already);
28625796c8dcSSimon Schubert       if (val)
2863a45ae5f8SJohn Marino 	error_flag = val;
28645796c8dcSSimon Schubert     }
28655796c8dcSSimon Schubert 
2866c50c785cSJohn Marino   /* If we failed to insert all locations of a watchpoint, remove
2867c50c785cSJohn Marino      them, as half-inserted watchpoint is of limited use.  */
28685796c8dcSSimon Schubert   ALL_BREAKPOINTS (bpt)
28695796c8dcSSimon Schubert     {
28705796c8dcSSimon Schubert       int some_failed = 0;
28715796c8dcSSimon Schubert       struct bp_location *loc;
28725796c8dcSSimon Schubert 
28735796c8dcSSimon Schubert       if (!is_hardware_watchpoint (bpt))
28745796c8dcSSimon Schubert 	continue;
28755796c8dcSSimon Schubert 
28765796c8dcSSimon Schubert       if (!breakpoint_enabled (bpt))
28775796c8dcSSimon Schubert 	continue;
28785796c8dcSSimon Schubert 
28795796c8dcSSimon Schubert       if (bpt->disposition == disp_del_at_next_stop)
28805796c8dcSSimon Schubert 	continue;
28815796c8dcSSimon Schubert 
28825796c8dcSSimon Schubert       for (loc = bpt->loc; loc; loc = loc->next)
2883cf7f2e2dSJohn Marino 	if (!loc->inserted && should_be_inserted (loc))
28845796c8dcSSimon Schubert 	  {
28855796c8dcSSimon Schubert 	    some_failed = 1;
28865796c8dcSSimon Schubert 	    break;
28875796c8dcSSimon Schubert 	  }
28885796c8dcSSimon Schubert       if (some_failed)
28895796c8dcSSimon Schubert 	{
28905796c8dcSSimon Schubert 	  for (loc = bpt->loc; loc; loc = loc->next)
28915796c8dcSSimon Schubert 	    if (loc->inserted)
28925796c8dcSSimon Schubert 	      remove_breakpoint (loc, mark_uninserted);
28935796c8dcSSimon Schubert 
28945796c8dcSSimon Schubert 	  hw_breakpoint_error = 1;
28955796c8dcSSimon Schubert 	  fprintf_unfiltered (tmp_error_stream,
28965796c8dcSSimon Schubert 			      "Could not insert hardware watchpoint %d.\n",
28975796c8dcSSimon Schubert 			      bpt->number);
2898a45ae5f8SJohn Marino 	  error_flag = -1;
28995796c8dcSSimon Schubert 	}
29005796c8dcSSimon Schubert     }
29015796c8dcSSimon Schubert 
2902a45ae5f8SJohn Marino   if (error_flag)
29035796c8dcSSimon Schubert     {
29045796c8dcSSimon Schubert       /* If a hardware breakpoint or watchpoint was inserted, add a
29055796c8dcSSimon Schubert          message about possibly exhausted resources.  */
2906*ef5ccd6cSJohn Marino       if (hw_breakpoint_error && !hw_bp_error_explained_already)
29075796c8dcSSimon Schubert 	{
29085796c8dcSSimon Schubert 	  fprintf_unfiltered (tmp_error_stream,
29095796c8dcSSimon Schubert 			      "Could not insert hardware breakpoints:\n\
29105796c8dcSSimon Schubert You may have requested too many hardware breakpoints/watchpoints.\n");
29115796c8dcSSimon Schubert 	}
29125796c8dcSSimon Schubert       target_terminal_ours_for_output ();
29135796c8dcSSimon Schubert       error_stream (tmp_error_stream);
29145796c8dcSSimon Schubert     }
29155796c8dcSSimon Schubert 
29165796c8dcSSimon Schubert   do_cleanups (cleanups);
29175796c8dcSSimon Schubert }
29185796c8dcSSimon Schubert 
2919a45ae5f8SJohn Marino /* Used when the program stops.
2920a45ae5f8SJohn Marino    Returns zero if successful, or non-zero if there was a problem
2921a45ae5f8SJohn Marino    removing a breakpoint location.  */
2922a45ae5f8SJohn Marino 
29235796c8dcSSimon Schubert int
remove_breakpoints(void)29245796c8dcSSimon Schubert remove_breakpoints (void)
29255796c8dcSSimon Schubert {
2926c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
29275796c8dcSSimon Schubert   int val = 0;
29285796c8dcSSimon Schubert 
2929c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
29305796c8dcSSimon Schubert   {
2931a45ae5f8SJohn Marino     if (bl->inserted && !is_tracepoint (bl->owner))
2932c50c785cSJohn Marino       val |= remove_breakpoint (bl, mark_uninserted);
29335796c8dcSSimon Schubert   }
29345796c8dcSSimon Schubert   return val;
29355796c8dcSSimon Schubert }
29365796c8dcSSimon Schubert 
2937cf7f2e2dSJohn Marino /* Remove breakpoints of process PID.  */
2938cf7f2e2dSJohn Marino 
2939cf7f2e2dSJohn Marino int
remove_breakpoints_pid(int pid)2940cf7f2e2dSJohn Marino remove_breakpoints_pid (int pid)
2941cf7f2e2dSJohn Marino {
2942c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
2943cf7f2e2dSJohn Marino   int val;
2944cf7f2e2dSJohn Marino   struct inferior *inf = find_inferior_pid (pid);
2945cf7f2e2dSJohn Marino 
2946c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
2947cf7f2e2dSJohn Marino   {
2948c50c785cSJohn Marino     if (bl->pspace != inf->pspace)
2949cf7f2e2dSJohn Marino       continue;
2950cf7f2e2dSJohn Marino 
2951*ef5ccd6cSJohn Marino     if (bl->owner->type == bp_dprintf)
2952*ef5ccd6cSJohn Marino       continue;
2953*ef5ccd6cSJohn Marino 
2954c50c785cSJohn Marino     if (bl->inserted)
2955cf7f2e2dSJohn Marino       {
2956c50c785cSJohn Marino 	val = remove_breakpoint (bl, mark_uninserted);
2957cf7f2e2dSJohn Marino 	if (val != 0)
2958cf7f2e2dSJohn Marino 	  return val;
2959cf7f2e2dSJohn Marino       }
2960cf7f2e2dSJohn Marino   }
2961cf7f2e2dSJohn Marino   return 0;
2962cf7f2e2dSJohn Marino }
2963cf7f2e2dSJohn Marino 
29645796c8dcSSimon Schubert int
reattach_breakpoints(int pid)29655796c8dcSSimon Schubert reattach_breakpoints (int pid)
29665796c8dcSSimon Schubert {
2967cf7f2e2dSJohn Marino   struct cleanup *old_chain;
2968c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
29695796c8dcSSimon Schubert   int val;
2970c50c785cSJohn Marino   struct ui_file *tmp_error_stream;
2971*ef5ccd6cSJohn Marino   int dummy1 = 0, dummy2 = 0, dummy3 = 0;
2972cf7f2e2dSJohn Marino   struct inferior *inf;
2973cf7f2e2dSJohn Marino   struct thread_info *tp;
2974cf7f2e2dSJohn Marino 
2975cf7f2e2dSJohn Marino   tp = any_live_thread_of_process (pid);
2976cf7f2e2dSJohn Marino   if (tp == NULL)
2977cf7f2e2dSJohn Marino     return 1;
2978cf7f2e2dSJohn Marino 
2979cf7f2e2dSJohn Marino   inf = find_inferior_pid (pid);
2980cf7f2e2dSJohn Marino   old_chain = save_inferior_ptid ();
2981cf7f2e2dSJohn Marino 
2982cf7f2e2dSJohn Marino   inferior_ptid = tp->ptid;
29835796c8dcSSimon Schubert 
2984c50c785cSJohn Marino   tmp_error_stream = mem_fileopen ();
29855796c8dcSSimon Schubert   make_cleanup_ui_file_delete (tmp_error_stream);
29865796c8dcSSimon Schubert 
2987c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
29885796c8dcSSimon Schubert   {
2989c50c785cSJohn Marino     if (bl->pspace != inf->pspace)
2990cf7f2e2dSJohn Marino       continue;
2991cf7f2e2dSJohn Marino 
2992c50c785cSJohn Marino     if (bl->inserted)
29935796c8dcSSimon Schubert       {
2994c50c785cSJohn Marino 	bl->inserted = 0;
2995*ef5ccd6cSJohn Marino 	val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3);
29965796c8dcSSimon Schubert 	if (val != 0)
29975796c8dcSSimon Schubert 	  {
29985796c8dcSSimon Schubert 	    do_cleanups (old_chain);
29995796c8dcSSimon Schubert 	    return val;
30005796c8dcSSimon Schubert 	  }
30015796c8dcSSimon Schubert       }
30025796c8dcSSimon Schubert   }
30035796c8dcSSimon Schubert   do_cleanups (old_chain);
30045796c8dcSSimon Schubert   return 0;
30055796c8dcSSimon Schubert }
30065796c8dcSSimon Schubert 
30075796c8dcSSimon Schubert static int internal_breakpoint_number = -1;
30085796c8dcSSimon Schubert 
3009c50c785cSJohn Marino /* Set the breakpoint number of B, depending on the value of INTERNAL.
3010c50c785cSJohn Marino    If INTERNAL is non-zero, the breakpoint number will be populated
3011c50c785cSJohn Marino    from internal_breakpoint_number and that variable decremented.
3012a45ae5f8SJohn Marino    Otherwise the breakpoint number will be populated from
3013c50c785cSJohn Marino    breakpoint_count and that value incremented.  Internal breakpoints
3014c50c785cSJohn Marino    do not set the internal var bpnum.  */
3015c50c785cSJohn Marino static void
set_breakpoint_number(int internal,struct breakpoint * b)3016c50c785cSJohn Marino set_breakpoint_number (int internal, struct breakpoint *b)
3017c50c785cSJohn Marino {
3018c50c785cSJohn Marino   if (internal)
3019c50c785cSJohn Marino     b->number = internal_breakpoint_number--;
3020c50c785cSJohn Marino   else
3021c50c785cSJohn Marino     {
3022c50c785cSJohn Marino       set_breakpoint_count (breakpoint_count + 1);
3023c50c785cSJohn Marino       b->number = breakpoint_count;
3024c50c785cSJohn Marino     }
3025c50c785cSJohn Marino }
3026c50c785cSJohn Marino 
30275796c8dcSSimon Schubert static struct breakpoint *
create_internal_breakpoint(struct gdbarch * gdbarch,CORE_ADDR address,enum bptype type,const struct breakpoint_ops * ops)30285796c8dcSSimon Schubert create_internal_breakpoint (struct gdbarch *gdbarch,
3029a45ae5f8SJohn Marino 			    CORE_ADDR address, enum bptype type,
3030a45ae5f8SJohn Marino 			    const struct breakpoint_ops *ops)
30315796c8dcSSimon Schubert {
30325796c8dcSSimon Schubert   struct symtab_and_line sal;
30335796c8dcSSimon Schubert   struct breakpoint *b;
30345796c8dcSSimon Schubert 
3035c50c785cSJohn Marino   init_sal (&sal);		/* Initialize to zeroes.  */
30365796c8dcSSimon Schubert 
30375796c8dcSSimon Schubert   sal.pc = address;
30385796c8dcSSimon Schubert   sal.section = find_pc_overlay (sal.pc);
3039cf7f2e2dSJohn Marino   sal.pspace = current_program_space;
30405796c8dcSSimon Schubert 
3041a45ae5f8SJohn Marino   b = set_raw_breakpoint (gdbarch, sal, type, ops);
30425796c8dcSSimon Schubert   b->number = internal_breakpoint_number--;
30435796c8dcSSimon Schubert   b->disposition = disp_donttouch;
30445796c8dcSSimon Schubert 
30455796c8dcSSimon Schubert   return b;
30465796c8dcSSimon Schubert }
30475796c8dcSSimon Schubert 
3048c50c785cSJohn Marino static const char *const longjmp_names[] =
3049c50c785cSJohn Marino   {
3050c50c785cSJohn Marino     "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3051c50c785cSJohn Marino   };
3052c50c785cSJohn Marino #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3053c50c785cSJohn Marino 
3054c50c785cSJohn Marino /* Per-objfile data private to breakpoint.c.  */
3055c50c785cSJohn Marino struct breakpoint_objfile_data
3056c50c785cSJohn Marino {
3057c50c785cSJohn Marino   /* Minimal symbol for "_ovly_debug_event" (if any).  */
3058c50c785cSJohn Marino   struct minimal_symbol *overlay_msym;
3059c50c785cSJohn Marino 
3060c50c785cSJohn Marino   /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any).  */
3061c50c785cSJohn Marino   struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
3062c50c785cSJohn Marino 
3063*ef5ccd6cSJohn Marino   /* True if we have looked for longjmp probes.  */
3064*ef5ccd6cSJohn Marino   int longjmp_searched;
3065*ef5ccd6cSJohn Marino 
3066*ef5ccd6cSJohn Marino   /* SystemTap probe points for longjmp (if any).  */
3067*ef5ccd6cSJohn Marino   VEC (probe_p) *longjmp_probes;
3068*ef5ccd6cSJohn Marino 
3069c50c785cSJohn Marino   /* Minimal symbol for "std::terminate()" (if any).  */
3070c50c785cSJohn Marino   struct minimal_symbol *terminate_msym;
3071c50c785cSJohn Marino 
3072c50c785cSJohn Marino   /* Minimal symbol for "_Unwind_DebugHook" (if any).  */
3073c50c785cSJohn Marino   struct minimal_symbol *exception_msym;
3074*ef5ccd6cSJohn Marino 
3075*ef5ccd6cSJohn Marino   /* True if we have looked for exception probes.  */
3076*ef5ccd6cSJohn Marino   int exception_searched;
3077*ef5ccd6cSJohn Marino 
3078*ef5ccd6cSJohn Marino   /* SystemTap probe points for unwinding (if any).  */
3079*ef5ccd6cSJohn Marino   VEC (probe_p) *exception_probes;
3080c50c785cSJohn Marino };
3081c50c785cSJohn Marino 
3082c50c785cSJohn Marino static const struct objfile_data *breakpoint_objfile_key;
3083c50c785cSJohn Marino 
3084c50c785cSJohn Marino /* Minimal symbol not found sentinel.  */
3085c50c785cSJohn Marino static struct minimal_symbol msym_not_found;
3086c50c785cSJohn Marino 
3087c50c785cSJohn Marino /* Returns TRUE if MSYM point to the "not found" sentinel.  */
3088c50c785cSJohn Marino 
3089c50c785cSJohn Marino static int
msym_not_found_p(const struct minimal_symbol * msym)3090c50c785cSJohn Marino msym_not_found_p (const struct minimal_symbol *msym)
3091c50c785cSJohn Marino {
3092c50c785cSJohn Marino   return msym == &msym_not_found;
3093c50c785cSJohn Marino }
3094c50c785cSJohn Marino 
3095c50c785cSJohn Marino /* Return per-objfile data needed by breakpoint.c.
3096c50c785cSJohn Marino    Allocate the data if necessary.  */
3097c50c785cSJohn Marino 
3098c50c785cSJohn Marino static struct breakpoint_objfile_data *
get_breakpoint_objfile_data(struct objfile * objfile)3099c50c785cSJohn Marino get_breakpoint_objfile_data (struct objfile *objfile)
3100c50c785cSJohn Marino {
3101c50c785cSJohn Marino   struct breakpoint_objfile_data *bp_objfile_data;
3102c50c785cSJohn Marino 
3103c50c785cSJohn Marino   bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
3104c50c785cSJohn Marino   if (bp_objfile_data == NULL)
3105c50c785cSJohn Marino     {
3106c50c785cSJohn Marino       bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
3107c50c785cSJohn Marino 				       sizeof (*bp_objfile_data));
3108c50c785cSJohn Marino 
3109c50c785cSJohn Marino       memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
3110c50c785cSJohn Marino       set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
3111c50c785cSJohn Marino     }
3112c50c785cSJohn Marino   return bp_objfile_data;
3113c50c785cSJohn Marino }
3114c50c785cSJohn Marino 
31155796c8dcSSimon Schubert static void
free_breakpoint_probes(struct objfile * obj,void * data)3116*ef5ccd6cSJohn Marino free_breakpoint_probes (struct objfile *obj, void *data)
3117*ef5ccd6cSJohn Marino {
3118*ef5ccd6cSJohn Marino   struct breakpoint_objfile_data *bp_objfile_data = data;
3119*ef5ccd6cSJohn Marino 
3120*ef5ccd6cSJohn Marino   VEC_free (probe_p, bp_objfile_data->longjmp_probes);
3121*ef5ccd6cSJohn Marino   VEC_free (probe_p, bp_objfile_data->exception_probes);
3122*ef5ccd6cSJohn Marino }
3123*ef5ccd6cSJohn Marino 
3124*ef5ccd6cSJohn Marino static void
create_overlay_event_breakpoint(void)3125c50c785cSJohn Marino create_overlay_event_breakpoint (void)
31265796c8dcSSimon Schubert {
31275796c8dcSSimon Schubert   struct objfile *objfile;
3128c50c785cSJohn Marino   const char *const func_name = "_ovly_debug_event";
31295796c8dcSSimon Schubert 
31305796c8dcSSimon Schubert   ALL_OBJFILES (objfile)
31315796c8dcSSimon Schubert     {
31325796c8dcSSimon Schubert       struct breakpoint *b;
3133c50c785cSJohn Marino       struct breakpoint_objfile_data *bp_objfile_data;
3134c50c785cSJohn Marino       CORE_ADDR addr;
3135c50c785cSJohn Marino 
3136c50c785cSJohn Marino       bp_objfile_data = get_breakpoint_objfile_data (objfile);
3137c50c785cSJohn Marino 
3138c50c785cSJohn Marino       if (msym_not_found_p (bp_objfile_data->overlay_msym))
3139c50c785cSJohn Marino 	continue;
3140c50c785cSJohn Marino 
3141c50c785cSJohn Marino       if (bp_objfile_data->overlay_msym == NULL)
3142c50c785cSJohn Marino 	{
31435796c8dcSSimon Schubert 	  struct minimal_symbol *m;
31445796c8dcSSimon Schubert 
31455796c8dcSSimon Schubert 	  m = lookup_minimal_symbol_text (func_name, objfile);
31465796c8dcSSimon Schubert 	  if (m == NULL)
3147c50c785cSJohn Marino 	    {
3148c50c785cSJohn Marino 	      /* Avoid future lookups in this objfile.  */
3149c50c785cSJohn Marino 	      bp_objfile_data->overlay_msym = &msym_not_found;
31505796c8dcSSimon Schubert 	      continue;
3151c50c785cSJohn Marino 	    }
3152c50c785cSJohn Marino 	  bp_objfile_data->overlay_msym = m;
3153c50c785cSJohn Marino 	}
31545796c8dcSSimon Schubert 
3155c50c785cSJohn Marino       addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
3156c50c785cSJohn Marino       b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3157a45ae5f8SJohn Marino                                       bp_overlay_event,
3158a45ae5f8SJohn Marino 				      &internal_breakpoint_ops);
31595796c8dcSSimon Schubert       b->addr_string = xstrdup (func_name);
31605796c8dcSSimon Schubert 
31615796c8dcSSimon Schubert       if (overlay_debugging == ovly_auto)
31625796c8dcSSimon Schubert         {
31635796c8dcSSimon Schubert           b->enable_state = bp_enabled;
31645796c8dcSSimon Schubert           overlay_events_enabled = 1;
31655796c8dcSSimon Schubert         }
31665796c8dcSSimon Schubert       else
31675796c8dcSSimon Schubert        {
31685796c8dcSSimon Schubert          b->enable_state = bp_disabled;
31695796c8dcSSimon Schubert          overlay_events_enabled = 0;
31705796c8dcSSimon Schubert        }
31715796c8dcSSimon Schubert     }
31725796c8dcSSimon Schubert   update_global_location_list (1);
31735796c8dcSSimon Schubert }
31745796c8dcSSimon Schubert 
31755796c8dcSSimon Schubert static void
create_longjmp_master_breakpoint(void)3176c50c785cSJohn Marino create_longjmp_master_breakpoint (void)
31775796c8dcSSimon Schubert {
3178cf7f2e2dSJohn Marino   struct program_space *pspace;
3179cf7f2e2dSJohn Marino   struct cleanup *old_chain;
31805796c8dcSSimon Schubert 
3181cf7f2e2dSJohn Marino   old_chain = save_current_program_space ();
3182cf7f2e2dSJohn Marino 
3183cf7f2e2dSJohn Marino   ALL_PSPACES (pspace)
31845796c8dcSSimon Schubert   {
3185c50c785cSJohn Marino     struct objfile *objfile;
31865796c8dcSSimon Schubert 
3187cf7f2e2dSJohn Marino     set_current_program_space (pspace);
3188cf7f2e2dSJohn Marino 
3189c50c785cSJohn Marino     ALL_OBJFILES (objfile)
3190c50c785cSJohn Marino     {
3191c50c785cSJohn Marino       int i;
3192c50c785cSJohn Marino       struct gdbarch *gdbarch;
3193c50c785cSJohn Marino       struct breakpoint_objfile_data *bp_objfile_data;
3194c50c785cSJohn Marino 
3195c50c785cSJohn Marino       gdbarch = get_objfile_arch (objfile);
3196c50c785cSJohn Marino       if (!gdbarch_get_longjmp_target_p (gdbarch))
31975796c8dcSSimon Schubert 	continue;
31985796c8dcSSimon Schubert 
3199c50c785cSJohn Marino       bp_objfile_data = get_breakpoint_objfile_data (objfile);
3200c50c785cSJohn Marino 
3201*ef5ccd6cSJohn Marino       if (!bp_objfile_data->longjmp_searched)
3202*ef5ccd6cSJohn Marino 	{
3203*ef5ccd6cSJohn Marino 	  bp_objfile_data->longjmp_probes
3204*ef5ccd6cSJohn Marino 	    = find_probes_in_objfile (objfile, "libc", "longjmp");
3205*ef5ccd6cSJohn Marino 	  bp_objfile_data->longjmp_searched = 1;
3206*ef5ccd6cSJohn Marino 	}
3207*ef5ccd6cSJohn Marino 
3208*ef5ccd6cSJohn Marino       if (bp_objfile_data->longjmp_probes != NULL)
3209*ef5ccd6cSJohn Marino 	{
3210*ef5ccd6cSJohn Marino 	  int i;
3211*ef5ccd6cSJohn Marino 	  struct probe *probe;
3212*ef5ccd6cSJohn Marino 	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
3213*ef5ccd6cSJohn Marino 
3214*ef5ccd6cSJohn Marino 	  for (i = 0;
3215*ef5ccd6cSJohn Marino 	       VEC_iterate (probe_p,
3216*ef5ccd6cSJohn Marino 			    bp_objfile_data->longjmp_probes,
3217*ef5ccd6cSJohn Marino 			    i, probe);
3218*ef5ccd6cSJohn Marino 	       ++i)
3219*ef5ccd6cSJohn Marino 	    {
3220*ef5ccd6cSJohn Marino 	      struct breakpoint *b;
3221*ef5ccd6cSJohn Marino 
3222*ef5ccd6cSJohn Marino 	      b = create_internal_breakpoint (gdbarch, probe->address,
3223*ef5ccd6cSJohn Marino 					      bp_longjmp_master,
3224*ef5ccd6cSJohn Marino 					      &internal_breakpoint_ops);
3225*ef5ccd6cSJohn Marino 	      b->addr_string = xstrdup ("-probe-stap libc:longjmp");
3226*ef5ccd6cSJohn Marino 	      b->enable_state = bp_disabled;
3227*ef5ccd6cSJohn Marino 	    }
3228*ef5ccd6cSJohn Marino 
3229*ef5ccd6cSJohn Marino 	  continue;
3230*ef5ccd6cSJohn Marino 	}
3231*ef5ccd6cSJohn Marino 
3232c50c785cSJohn Marino       for (i = 0; i < NUM_LONGJMP_NAMES; i++)
3233c50c785cSJohn Marino 	{
3234c50c785cSJohn Marino 	  struct breakpoint *b;
3235c50c785cSJohn Marino 	  const char *func_name;
3236c50c785cSJohn Marino 	  CORE_ADDR addr;
3237c50c785cSJohn Marino 
3238c50c785cSJohn Marino 	  if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
3239c50c785cSJohn Marino 	    continue;
3240c50c785cSJohn Marino 
3241c50c785cSJohn Marino 	  func_name = longjmp_names[i];
3242c50c785cSJohn Marino 	  if (bp_objfile_data->longjmp_msym[i] == NULL)
3243c50c785cSJohn Marino 	    {
3244c50c785cSJohn Marino 	      struct minimal_symbol *m;
3245c50c785cSJohn Marino 
3246c50c785cSJohn Marino 	      m = lookup_minimal_symbol_text (func_name, objfile);
3247c50c785cSJohn Marino 	      if (m == NULL)
3248c50c785cSJohn Marino 		{
3249c50c785cSJohn Marino 		  /* Prevent future lookups in this objfile.  */
3250c50c785cSJohn Marino 		  bp_objfile_data->longjmp_msym[i] = &msym_not_found;
3251c50c785cSJohn Marino 		  continue;
3252c50c785cSJohn Marino 		}
3253c50c785cSJohn Marino 	      bp_objfile_data->longjmp_msym[i] = m;
3254c50c785cSJohn Marino 	    }
3255c50c785cSJohn Marino 
3256c50c785cSJohn Marino 	  addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
3257a45ae5f8SJohn Marino 	  b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
3258a45ae5f8SJohn Marino 					  &internal_breakpoint_ops);
32595796c8dcSSimon Schubert 	  b->addr_string = xstrdup (func_name);
32605796c8dcSSimon Schubert 	  b->enable_state = bp_disabled;
32615796c8dcSSimon Schubert 	}
3262c50c785cSJohn Marino     }
3263c50c785cSJohn Marino   }
32645796c8dcSSimon Schubert   update_global_location_list (1);
3265cf7f2e2dSJohn Marino 
3266cf7f2e2dSJohn Marino   do_cleanups (old_chain);
3267cf7f2e2dSJohn Marino }
3268cf7f2e2dSJohn Marino 
3269c50c785cSJohn Marino /* Create a master std::terminate breakpoint.  */
3270cf7f2e2dSJohn Marino static void
create_std_terminate_master_breakpoint(void)3271c50c785cSJohn Marino create_std_terminate_master_breakpoint (void)
3272cf7f2e2dSJohn Marino {
3273cf7f2e2dSJohn Marino   struct program_space *pspace;
3274cf7f2e2dSJohn Marino   struct cleanup *old_chain;
3275c50c785cSJohn Marino   const char *const func_name = "std::terminate()";
3276cf7f2e2dSJohn Marino 
3277cf7f2e2dSJohn Marino   old_chain = save_current_program_space ();
3278cf7f2e2dSJohn Marino 
3279cf7f2e2dSJohn Marino   ALL_PSPACES (pspace)
3280c50c785cSJohn Marino   {
3281c50c785cSJohn Marino     struct objfile *objfile;
3282c50c785cSJohn Marino     CORE_ADDR addr;
3283c50c785cSJohn Marino 
3284c50c785cSJohn Marino     set_current_program_space (pspace);
3285c50c785cSJohn Marino 
3286cf7f2e2dSJohn Marino     ALL_OBJFILES (objfile)
3287cf7f2e2dSJohn Marino     {
3288cf7f2e2dSJohn Marino       struct breakpoint *b;
3289c50c785cSJohn Marino       struct breakpoint_objfile_data *bp_objfile_data;
3290cf7f2e2dSJohn Marino 
3291c50c785cSJohn Marino       bp_objfile_data = get_breakpoint_objfile_data (objfile);
3292c50c785cSJohn Marino 
3293c50c785cSJohn Marino       if (msym_not_found_p (bp_objfile_data->terminate_msym))
3294c50c785cSJohn Marino 	continue;
3295c50c785cSJohn Marino 
3296c50c785cSJohn Marino       if (bp_objfile_data->terminate_msym == NULL)
3297c50c785cSJohn Marino 	{
3298c50c785cSJohn Marino 	  struct minimal_symbol *m;
3299cf7f2e2dSJohn Marino 
3300cf7f2e2dSJohn Marino 	  m = lookup_minimal_symbol (func_name, NULL, objfile);
3301cf7f2e2dSJohn Marino 	  if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
3302cf7f2e2dSJohn Marino 			    && MSYMBOL_TYPE (m) != mst_file_text))
3303c50c785cSJohn Marino 	    {
3304c50c785cSJohn Marino 	      /* Prevent future lookups in this objfile.  */
3305c50c785cSJohn Marino 	      bp_objfile_data->terminate_msym = &msym_not_found;
3306cf7f2e2dSJohn Marino 	      continue;
3307c50c785cSJohn Marino 	    }
3308c50c785cSJohn Marino 	  bp_objfile_data->terminate_msym = m;
3309c50c785cSJohn Marino 	}
3310cf7f2e2dSJohn Marino 
3311c50c785cSJohn Marino       addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
3312c50c785cSJohn Marino       b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
3313a45ae5f8SJohn Marino                                       bp_std_terminate_master,
3314a45ae5f8SJohn Marino 				      &internal_breakpoint_ops);
3315cf7f2e2dSJohn Marino       b->addr_string = xstrdup (func_name);
3316cf7f2e2dSJohn Marino       b->enable_state = bp_disabled;
3317cf7f2e2dSJohn Marino     }
3318c50c785cSJohn Marino   }
3319c50c785cSJohn Marino 
3320cf7f2e2dSJohn Marino   update_global_location_list (1);
3321cf7f2e2dSJohn Marino 
3322cf7f2e2dSJohn Marino   do_cleanups (old_chain);
33235796c8dcSSimon Schubert }
33245796c8dcSSimon Schubert 
3325c50c785cSJohn Marino /* Install a master breakpoint on the unwinder's debug hook.  */
3326c50c785cSJohn Marino 
3327*ef5ccd6cSJohn Marino static void
create_exception_master_breakpoint(void)3328c50c785cSJohn Marino create_exception_master_breakpoint (void)
3329c50c785cSJohn Marino {
3330c50c785cSJohn Marino   struct objfile *objfile;
3331c50c785cSJohn Marino   const char *const func_name = "_Unwind_DebugHook";
3332c50c785cSJohn Marino 
3333c50c785cSJohn Marino   ALL_OBJFILES (objfile)
3334c50c785cSJohn Marino     {
3335c50c785cSJohn Marino       struct breakpoint *b;
3336c50c785cSJohn Marino       struct gdbarch *gdbarch;
3337c50c785cSJohn Marino       struct breakpoint_objfile_data *bp_objfile_data;
3338c50c785cSJohn Marino       CORE_ADDR addr;
3339c50c785cSJohn Marino 
3340c50c785cSJohn Marino       bp_objfile_data = get_breakpoint_objfile_data (objfile);
3341c50c785cSJohn Marino 
3342*ef5ccd6cSJohn Marino       /* We prefer the SystemTap probe point if it exists.  */
3343*ef5ccd6cSJohn Marino       if (!bp_objfile_data->exception_searched)
3344*ef5ccd6cSJohn Marino 	{
3345*ef5ccd6cSJohn Marino 	  bp_objfile_data->exception_probes
3346*ef5ccd6cSJohn Marino 	    = find_probes_in_objfile (objfile, "libgcc", "unwind");
3347*ef5ccd6cSJohn Marino 	  bp_objfile_data->exception_searched = 1;
3348*ef5ccd6cSJohn Marino 	}
3349*ef5ccd6cSJohn Marino 
3350*ef5ccd6cSJohn Marino       if (bp_objfile_data->exception_probes != NULL)
3351*ef5ccd6cSJohn Marino 	{
3352*ef5ccd6cSJohn Marino 	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
3353*ef5ccd6cSJohn Marino 	  int i;
3354*ef5ccd6cSJohn Marino 	  struct probe *probe;
3355*ef5ccd6cSJohn Marino 
3356*ef5ccd6cSJohn Marino 	  for (i = 0;
3357*ef5ccd6cSJohn Marino 	       VEC_iterate (probe_p,
3358*ef5ccd6cSJohn Marino 			    bp_objfile_data->exception_probes,
3359*ef5ccd6cSJohn Marino 			    i, probe);
3360*ef5ccd6cSJohn Marino 	       ++i)
3361*ef5ccd6cSJohn Marino 	    {
3362*ef5ccd6cSJohn Marino 	      struct breakpoint *b;
3363*ef5ccd6cSJohn Marino 
3364*ef5ccd6cSJohn Marino 	      b = create_internal_breakpoint (gdbarch, probe->address,
3365*ef5ccd6cSJohn Marino 					      bp_exception_master,
3366*ef5ccd6cSJohn Marino 					      &internal_breakpoint_ops);
3367*ef5ccd6cSJohn Marino 	      b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3368*ef5ccd6cSJohn Marino 	      b->enable_state = bp_disabled;
3369*ef5ccd6cSJohn Marino 	    }
3370*ef5ccd6cSJohn Marino 
3371*ef5ccd6cSJohn Marino 	  continue;
3372*ef5ccd6cSJohn Marino 	}
3373*ef5ccd6cSJohn Marino 
3374*ef5ccd6cSJohn Marino       /* Otherwise, try the hook function.  */
3375*ef5ccd6cSJohn Marino 
3376c50c785cSJohn Marino       if (msym_not_found_p (bp_objfile_data->exception_msym))
3377c50c785cSJohn Marino 	continue;
3378c50c785cSJohn Marino 
3379c50c785cSJohn Marino       gdbarch = get_objfile_arch (objfile);
3380c50c785cSJohn Marino 
3381c50c785cSJohn Marino       if (bp_objfile_data->exception_msym == NULL)
3382c50c785cSJohn Marino 	{
3383c50c785cSJohn Marino 	  struct minimal_symbol *debug_hook;
3384c50c785cSJohn Marino 
3385c50c785cSJohn Marino 	  debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3386c50c785cSJohn Marino 	  if (debug_hook == NULL)
3387c50c785cSJohn Marino 	    {
3388c50c785cSJohn Marino 	      bp_objfile_data->exception_msym = &msym_not_found;
3389c50c785cSJohn Marino 	      continue;
3390c50c785cSJohn Marino 	    }
3391c50c785cSJohn Marino 
3392c50c785cSJohn Marino 	  bp_objfile_data->exception_msym = debug_hook;
3393c50c785cSJohn Marino 	}
3394c50c785cSJohn Marino 
3395c50c785cSJohn Marino       addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3396c50c785cSJohn Marino       addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3397c50c785cSJohn Marino 						 &current_target);
3398a45ae5f8SJohn Marino       b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3399a45ae5f8SJohn Marino 				      &internal_breakpoint_ops);
3400c50c785cSJohn Marino       b->addr_string = xstrdup (func_name);
3401c50c785cSJohn Marino       b->enable_state = bp_disabled;
3402c50c785cSJohn Marino     }
3403c50c785cSJohn Marino 
3404c50c785cSJohn Marino   update_global_location_list (1);
3405c50c785cSJohn Marino }
3406c50c785cSJohn Marino 
34075796c8dcSSimon Schubert void
update_breakpoints_after_exec(void)34085796c8dcSSimon Schubert update_breakpoints_after_exec (void)
34095796c8dcSSimon Schubert {
3410c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
3411cf7f2e2dSJohn Marino   struct bp_location *bploc, **bplocp_tmp;
34125796c8dcSSimon Schubert 
34135796c8dcSSimon Schubert   /* We're about to delete breakpoints from GDB's lists.  If the
34145796c8dcSSimon Schubert      INSERTED flag is true, GDB will try to lift the breakpoints by
34155796c8dcSSimon Schubert      writing the breakpoints' "shadow contents" back into memory.  The
34165796c8dcSSimon Schubert      "shadow contents" are NOT valid after an exec, so GDB should not
34175796c8dcSSimon Schubert      do that.  Instead, the target is responsible from marking
34185796c8dcSSimon Schubert      breakpoints out as soon as it detects an exec.  We don't do that
34195796c8dcSSimon Schubert      here instead, because there may be other attempts to delete
34205796c8dcSSimon Schubert      breakpoints after detecting an exec and before reaching here.  */
3421cf7f2e2dSJohn Marino   ALL_BP_LOCATIONS (bploc, bplocp_tmp)
3422cf7f2e2dSJohn Marino     if (bploc->pspace == current_program_space)
34235796c8dcSSimon Schubert       gdb_assert (!bploc->inserted);
34245796c8dcSSimon Schubert 
3425c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
34265796c8dcSSimon Schubert   {
3427cf7f2e2dSJohn Marino     if (b->pspace != current_program_space)
3428cf7f2e2dSJohn Marino       continue;
3429cf7f2e2dSJohn Marino 
34305796c8dcSSimon Schubert     /* Solib breakpoints must be explicitly reset after an exec().  */
34315796c8dcSSimon Schubert     if (b->type == bp_shlib_event)
34325796c8dcSSimon Schubert       {
34335796c8dcSSimon Schubert 	delete_breakpoint (b);
34345796c8dcSSimon Schubert 	continue;
34355796c8dcSSimon Schubert       }
34365796c8dcSSimon Schubert 
34375796c8dcSSimon Schubert     /* JIT breakpoints must be explicitly reset after an exec().  */
34385796c8dcSSimon Schubert     if (b->type == bp_jit_event)
34395796c8dcSSimon Schubert       {
34405796c8dcSSimon Schubert 	delete_breakpoint (b);
34415796c8dcSSimon Schubert 	continue;
34425796c8dcSSimon Schubert       }
34435796c8dcSSimon Schubert 
34445796c8dcSSimon Schubert     /* Thread event breakpoints must be set anew after an exec(),
34455796c8dcSSimon Schubert        as must overlay event and longjmp master breakpoints.  */
34465796c8dcSSimon Schubert     if (b->type == bp_thread_event || b->type == bp_overlay_event
3447c50c785cSJohn Marino 	|| b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3448c50c785cSJohn Marino 	|| b->type == bp_exception_master)
34495796c8dcSSimon Schubert       {
34505796c8dcSSimon Schubert 	delete_breakpoint (b);
34515796c8dcSSimon Schubert 	continue;
34525796c8dcSSimon Schubert       }
34535796c8dcSSimon Schubert 
34545796c8dcSSimon Schubert     /* Step-resume breakpoints are meaningless after an exec().  */
3455a45ae5f8SJohn Marino     if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
34565796c8dcSSimon Schubert       {
34575796c8dcSSimon Schubert 	delete_breakpoint (b);
34585796c8dcSSimon Schubert 	continue;
34595796c8dcSSimon Schubert       }
34605796c8dcSSimon Schubert 
34615796c8dcSSimon Schubert     /* Longjmp and longjmp-resume breakpoints are also meaningless
34625796c8dcSSimon Schubert        after an exec.  */
3463c50c785cSJohn Marino     if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3464*ef5ccd6cSJohn Marino 	|| b->type == bp_longjmp_call_dummy
3465c50c785cSJohn Marino 	|| b->type == bp_exception || b->type == bp_exception_resume)
34665796c8dcSSimon Schubert       {
34675796c8dcSSimon Schubert 	delete_breakpoint (b);
34685796c8dcSSimon Schubert 	continue;
34695796c8dcSSimon Schubert       }
34705796c8dcSSimon Schubert 
34715796c8dcSSimon Schubert     if (b->type == bp_catchpoint)
34725796c8dcSSimon Schubert       {
34735796c8dcSSimon Schubert         /* For now, none of the bp_catchpoint breakpoints need to
34745796c8dcSSimon Schubert            do anything at this point.  In the future, if some of
34755796c8dcSSimon Schubert            the catchpoints need to something, we will need to add
34765796c8dcSSimon Schubert            a new method, and call this method from here.  */
34775796c8dcSSimon Schubert         continue;
34785796c8dcSSimon Schubert       }
34795796c8dcSSimon Schubert 
34805796c8dcSSimon Schubert     /* bp_finish is a special case.  The only way we ought to be able
34815796c8dcSSimon Schubert        to see one of these when an exec() has happened, is if the user
34825796c8dcSSimon Schubert        caught a vfork, and then said "finish".  Ordinarily a finish just
34835796c8dcSSimon Schubert        carries them to the call-site of the current callee, by setting
34845796c8dcSSimon Schubert        a temporary bp there and resuming.  But in this case, the finish
34855796c8dcSSimon Schubert        will carry them entirely through the vfork & exec.
34865796c8dcSSimon Schubert 
34875796c8dcSSimon Schubert        We don't want to allow a bp_finish to remain inserted now.  But
34885796c8dcSSimon Schubert        we can't safely delete it, 'cause finish_command has a handle to
34895796c8dcSSimon Schubert        the bp on a bpstat, and will later want to delete it.  There's a
34905796c8dcSSimon Schubert        chance (and I've seen it happen) that if we delete the bp_finish
34915796c8dcSSimon Schubert        here, that its storage will get reused by the time finish_command
34925796c8dcSSimon Schubert        gets 'round to deleting the "use to be a bp_finish" breakpoint.
34935796c8dcSSimon Schubert        We really must allow finish_command to delete a bp_finish.
34945796c8dcSSimon Schubert 
3495a45ae5f8SJohn Marino        In the absence of a general solution for the "how do we know
34965796c8dcSSimon Schubert        it's safe to delete something others may have handles to?"
34975796c8dcSSimon Schubert        problem, what we'll do here is just uninsert the bp_finish, and
34985796c8dcSSimon Schubert        let finish_command delete it.
34995796c8dcSSimon Schubert 
35005796c8dcSSimon Schubert        (We know the bp_finish is "doomed" in the sense that it's
35015796c8dcSSimon Schubert        momentary, and will be deleted as soon as finish_command sees
35025796c8dcSSimon Schubert        the inferior stopped.  So it doesn't matter that the bp's
35035796c8dcSSimon Schubert        address is probably bogus in the new a.out, unlike e.g., the
35045796c8dcSSimon Schubert        solib breakpoints.)  */
35055796c8dcSSimon Schubert 
35065796c8dcSSimon Schubert     if (b->type == bp_finish)
35075796c8dcSSimon Schubert       {
35085796c8dcSSimon Schubert 	continue;
35095796c8dcSSimon Schubert       }
35105796c8dcSSimon Schubert 
35115796c8dcSSimon Schubert     /* Without a symbolic address, we have little hope of the
35125796c8dcSSimon Schubert        pre-exec() address meaning the same thing in the post-exec()
35135796c8dcSSimon Schubert        a.out.  */
35145796c8dcSSimon Schubert     if (b->addr_string == NULL)
35155796c8dcSSimon Schubert       {
35165796c8dcSSimon Schubert 	delete_breakpoint (b);
35175796c8dcSSimon Schubert 	continue;
35185796c8dcSSimon Schubert       }
35195796c8dcSSimon Schubert   }
35205796c8dcSSimon Schubert   /* FIXME what about longjmp breakpoints?  Re-create them here?  */
3521c50c785cSJohn Marino   create_overlay_event_breakpoint ();
3522c50c785cSJohn Marino   create_longjmp_master_breakpoint ();
3523c50c785cSJohn Marino   create_std_terminate_master_breakpoint ();
3524c50c785cSJohn Marino   create_exception_master_breakpoint ();
35255796c8dcSSimon Schubert }
35265796c8dcSSimon Schubert 
35275796c8dcSSimon Schubert int
detach_breakpoints(ptid_t ptid)3528*ef5ccd6cSJohn Marino detach_breakpoints (ptid_t ptid)
35295796c8dcSSimon Schubert {
3530c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
35315796c8dcSSimon Schubert   int val = 0;
35325796c8dcSSimon Schubert   struct cleanup *old_chain = save_inferior_ptid ();
3533cf7f2e2dSJohn Marino   struct inferior *inf = current_inferior ();
35345796c8dcSSimon Schubert 
3535*ef5ccd6cSJohn Marino   if (PIDGET (ptid) == PIDGET (inferior_ptid))
35365796c8dcSSimon Schubert     error (_("Cannot detach breakpoints of inferior_ptid"));
35375796c8dcSSimon Schubert 
3538cf7f2e2dSJohn Marino   /* Set inferior_ptid; remove_breakpoint_1 uses this global.  */
3539*ef5ccd6cSJohn Marino   inferior_ptid = ptid;
3540c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
35415796c8dcSSimon Schubert   {
3542c50c785cSJohn Marino     if (bl->pspace != inf->pspace)
3543cf7f2e2dSJohn Marino       continue;
3544cf7f2e2dSJohn Marino 
3545c50c785cSJohn Marino     if (bl->inserted)
3546c50c785cSJohn Marino       val |= remove_breakpoint_1 (bl, mark_inserted);
35475796c8dcSSimon Schubert   }
3548cf7f2e2dSJohn Marino 
3549cf7f2e2dSJohn Marino   /* Detach single-step breakpoints as well.  */
3550cf7f2e2dSJohn Marino   detach_single_step_breakpoints ();
3551cf7f2e2dSJohn Marino 
35525796c8dcSSimon Schubert   do_cleanups (old_chain);
35535796c8dcSSimon Schubert   return val;
35545796c8dcSSimon Schubert }
35555796c8dcSSimon Schubert 
3556c50c785cSJohn Marino /* Remove the breakpoint location BL from the current address space.
3557cf7f2e2dSJohn Marino    Note that this is used to detach breakpoints from a child fork.
3558cf7f2e2dSJohn Marino    When we get here, the child isn't in the inferior list, and neither
3559cf7f2e2dSJohn Marino    do we have objects to represent its address space --- we should
3560c50c785cSJohn Marino    *not* look at bl->pspace->aspace here.  */
3561cf7f2e2dSJohn Marino 
35625796c8dcSSimon Schubert static int
remove_breakpoint_1(struct bp_location * bl,insertion_state_t is)3563c50c785cSJohn Marino remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
35645796c8dcSSimon Schubert {
35655796c8dcSSimon Schubert   int val;
35665796c8dcSSimon Schubert 
3567c50c785cSJohn Marino   /* BL is never in moribund_locations by our callers.  */
3568c50c785cSJohn Marino   gdb_assert (bl->owner != NULL);
3569cf7f2e2dSJohn Marino 
3570c50c785cSJohn Marino   if (bl->owner->enable_state == bp_permanent)
35715796c8dcSSimon Schubert     /* Permanent breakpoints cannot be inserted or removed.  */
35725796c8dcSSimon Schubert     return 0;
35735796c8dcSSimon Schubert 
35745796c8dcSSimon Schubert   /* The type of none suggests that owner is actually deleted.
35755796c8dcSSimon Schubert      This should not ever happen.  */
3576c50c785cSJohn Marino   gdb_assert (bl->owner->type != bp_none);
35775796c8dcSSimon Schubert 
3578c50c785cSJohn Marino   if (bl->loc_type == bp_loc_software_breakpoint
3579c50c785cSJohn Marino       || bl->loc_type == bp_loc_hardware_breakpoint)
35805796c8dcSSimon Schubert     {
35815796c8dcSSimon Schubert       /* "Normal" instruction breakpoint: either the standard
35825796c8dcSSimon Schubert 	 trap-instruction bp (bp_breakpoint), or a
35835796c8dcSSimon Schubert 	 bp_hardware_breakpoint.  */
35845796c8dcSSimon Schubert 
35855796c8dcSSimon Schubert       /* First check to see if we have to handle an overlay.  */
35865796c8dcSSimon Schubert       if (overlay_debugging == ovly_off
3587c50c785cSJohn Marino 	  || bl->section == NULL
3588c50c785cSJohn Marino 	  || !(section_is_overlay (bl->section)))
35895796c8dcSSimon Schubert 	{
35905796c8dcSSimon Schubert 	  /* No overlay handling: just remove the breakpoint.  */
3591a45ae5f8SJohn Marino 	  val = bl->owner->ops->remove_location (bl);
35925796c8dcSSimon Schubert 	}
35935796c8dcSSimon Schubert       else
35945796c8dcSSimon Schubert 	{
35955796c8dcSSimon Schubert 	  /* This breakpoint is in an overlay section.
35965796c8dcSSimon Schubert 	     Did we set a breakpoint at the LMA?  */
35975796c8dcSSimon Schubert 	  if (!overlay_events_enabled)
35985796c8dcSSimon Schubert 	      {
35995796c8dcSSimon Schubert 		/* Yes -- overlay event support is not active, so we
36005796c8dcSSimon Schubert 		   should have set a breakpoint at the LMA.  Remove it.
36015796c8dcSSimon Schubert 		*/
36025796c8dcSSimon Schubert 		/* Ignore any failures: if the LMA is in ROM, we will
36035796c8dcSSimon Schubert 		   have already warned when we failed to insert it.  */
3604c50c785cSJohn Marino 		if (bl->loc_type == bp_loc_hardware_breakpoint)
3605c50c785cSJohn Marino 		  target_remove_hw_breakpoint (bl->gdbarch,
3606c50c785cSJohn Marino 					       &bl->overlay_target_info);
36075796c8dcSSimon Schubert 		else
3608c50c785cSJohn Marino 		  target_remove_breakpoint (bl->gdbarch,
3609c50c785cSJohn Marino 					    &bl->overlay_target_info);
36105796c8dcSSimon Schubert 	      }
36115796c8dcSSimon Schubert 	  /* Did we set a breakpoint at the VMA?
36125796c8dcSSimon Schubert 	     If so, we will have marked the breakpoint 'inserted'.  */
3613c50c785cSJohn Marino 	  if (bl->inserted)
36145796c8dcSSimon Schubert 	    {
36155796c8dcSSimon Schubert 	      /* Yes -- remove it.  Previously we did not bother to
36165796c8dcSSimon Schubert 		 remove the breakpoint if the section had been
36175796c8dcSSimon Schubert 		 unmapped, but let's not rely on that being safe.  We
36185796c8dcSSimon Schubert 		 don't know what the overlay manager might do.  */
36195796c8dcSSimon Schubert 
36205796c8dcSSimon Schubert 	      /* However, we should remove *software* breakpoints only
36215796c8dcSSimon Schubert 		 if the section is still mapped, or else we overwrite
36225796c8dcSSimon Schubert 		 wrong code with the saved shadow contents.  */
3623a45ae5f8SJohn Marino 	      if (bl->loc_type == bp_loc_hardware_breakpoint
3624a45ae5f8SJohn Marino 		  || section_is_mapped (bl->section))
3625a45ae5f8SJohn Marino 		val = bl->owner->ops->remove_location (bl);
36265796c8dcSSimon Schubert 	      else
36275796c8dcSSimon Schubert 		val = 0;
36285796c8dcSSimon Schubert 	    }
36295796c8dcSSimon Schubert 	  else
36305796c8dcSSimon Schubert 	    {
36315796c8dcSSimon Schubert 	      /* No -- not inserted, so no need to remove.  No error.  */
36325796c8dcSSimon Schubert 	      val = 0;
36335796c8dcSSimon Schubert 	    }
36345796c8dcSSimon Schubert 	}
36355796c8dcSSimon Schubert 
36365796c8dcSSimon Schubert       /* In some cases, we might not be able to remove a breakpoint
36375796c8dcSSimon Schubert 	 in a shared library that has already been removed, but we
36385796c8dcSSimon Schubert 	 have not yet processed the shlib unload event.  */
3639c50c785cSJohn Marino       if (val && solib_name_from_address (bl->pspace, bl->address))
36405796c8dcSSimon Schubert 	val = 0;
36415796c8dcSSimon Schubert 
36425796c8dcSSimon Schubert       if (val)
36435796c8dcSSimon Schubert 	return val;
3644c50c785cSJohn Marino       bl->inserted = (is == mark_inserted);
36455796c8dcSSimon Schubert     }
3646c50c785cSJohn Marino   else if (bl->loc_type == bp_loc_hardware_watchpoint)
36475796c8dcSSimon Schubert     {
3648c50c785cSJohn Marino       gdb_assert (bl->owner->ops != NULL
3649c50c785cSJohn Marino 		  && bl->owner->ops->remove_location != NULL);
3650c50c785cSJohn Marino 
3651c50c785cSJohn Marino       bl->inserted = (is == mark_inserted);
3652c50c785cSJohn Marino       bl->owner->ops->remove_location (bl);
36535796c8dcSSimon Schubert 
36545796c8dcSSimon Schubert       /* Failure to remove any of the hardware watchpoints comes here.  */
3655c50c785cSJohn Marino       if ((is == mark_uninserted) && (bl->inserted))
36565796c8dcSSimon Schubert 	warning (_("Could not remove hardware watchpoint %d."),
3657c50c785cSJohn Marino 		 bl->owner->number);
36585796c8dcSSimon Schubert     }
3659c50c785cSJohn Marino   else if (bl->owner->type == bp_catchpoint
3660c50c785cSJohn Marino            && breakpoint_enabled (bl->owner)
3661c50c785cSJohn Marino            && !bl->duplicate)
36625796c8dcSSimon Schubert     {
3663c50c785cSJohn Marino       gdb_assert (bl->owner->ops != NULL
3664c50c785cSJohn Marino 		  && bl->owner->ops->remove_location != NULL);
36655796c8dcSSimon Schubert 
3666c50c785cSJohn Marino       val = bl->owner->ops->remove_location (bl);
36675796c8dcSSimon Schubert       if (val)
36685796c8dcSSimon Schubert 	return val;
3669c50c785cSJohn Marino 
3670c50c785cSJohn Marino       bl->inserted = (is == mark_inserted);
36715796c8dcSSimon Schubert     }
36725796c8dcSSimon Schubert 
36735796c8dcSSimon Schubert   return 0;
36745796c8dcSSimon Schubert }
36755796c8dcSSimon Schubert 
3676cf7f2e2dSJohn Marino static int
remove_breakpoint(struct bp_location * bl,insertion_state_t is)3677c50c785cSJohn Marino remove_breakpoint (struct bp_location *bl, insertion_state_t is)
3678cf7f2e2dSJohn Marino {
3679cf7f2e2dSJohn Marino   int ret;
3680cf7f2e2dSJohn Marino   struct cleanup *old_chain;
3681cf7f2e2dSJohn Marino 
3682c50c785cSJohn Marino   /* BL is never in moribund_locations by our callers.  */
3683c50c785cSJohn Marino   gdb_assert (bl->owner != NULL);
3684cf7f2e2dSJohn Marino 
3685c50c785cSJohn Marino   if (bl->owner->enable_state == bp_permanent)
3686cf7f2e2dSJohn Marino     /* Permanent breakpoints cannot be inserted or removed.  */
3687cf7f2e2dSJohn Marino     return 0;
3688cf7f2e2dSJohn Marino 
3689cf7f2e2dSJohn Marino   /* The type of none suggests that owner is actually deleted.
3690cf7f2e2dSJohn Marino      This should not ever happen.  */
3691c50c785cSJohn Marino   gdb_assert (bl->owner->type != bp_none);
3692cf7f2e2dSJohn Marino 
3693cf7f2e2dSJohn Marino   old_chain = save_current_space_and_thread ();
3694cf7f2e2dSJohn Marino 
3695c50c785cSJohn Marino   switch_to_program_space_and_thread (bl->pspace);
3696cf7f2e2dSJohn Marino 
3697c50c785cSJohn Marino   ret = remove_breakpoint_1 (bl, is);
3698cf7f2e2dSJohn Marino 
3699cf7f2e2dSJohn Marino   do_cleanups (old_chain);
3700cf7f2e2dSJohn Marino   return ret;
3701cf7f2e2dSJohn Marino }
3702cf7f2e2dSJohn Marino 
37035796c8dcSSimon Schubert /* Clear the "inserted" flag in all breakpoints.  */
37045796c8dcSSimon Schubert 
37055796c8dcSSimon Schubert void
mark_breakpoints_out(void)37065796c8dcSSimon Schubert mark_breakpoints_out (void)
37075796c8dcSSimon Schubert {
3708c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
37095796c8dcSSimon Schubert 
3710c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
3711c50c785cSJohn Marino     if (bl->pspace == current_program_space)
3712c50c785cSJohn Marino       bl->inserted = 0;
37135796c8dcSSimon Schubert }
37145796c8dcSSimon Schubert 
37155796c8dcSSimon Schubert /* Clear the "inserted" flag in all breakpoints and delete any
37165796c8dcSSimon Schubert    breakpoints which should go away between runs of the program.
37175796c8dcSSimon Schubert 
37185796c8dcSSimon Schubert    Plus other such housekeeping that has to be done for breakpoints
37195796c8dcSSimon Schubert    between runs.
37205796c8dcSSimon Schubert 
37215796c8dcSSimon Schubert    Note: this function gets called at the end of a run (by
37225796c8dcSSimon Schubert    generic_mourn_inferior) and when a run begins (by
37235796c8dcSSimon Schubert    init_wait_for_inferior).  */
37245796c8dcSSimon Schubert 
37255796c8dcSSimon Schubert 
37265796c8dcSSimon Schubert 
37275796c8dcSSimon Schubert void
breakpoint_init_inferior(enum inf_context context)37285796c8dcSSimon Schubert breakpoint_init_inferior (enum inf_context context)
37295796c8dcSSimon Schubert {
3730c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
3731c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
37325796c8dcSSimon Schubert   int ix;
3733cf7f2e2dSJohn Marino   struct program_space *pspace = current_program_space;
37345796c8dcSSimon Schubert 
37355796c8dcSSimon Schubert   /* If breakpoint locations are shared across processes, then there's
37365796c8dcSSimon Schubert      nothing to do.  */
3737*ef5ccd6cSJohn Marino   if (gdbarch_has_global_breakpoints (target_gdbarch ()))
37385796c8dcSSimon Schubert     return;
37395796c8dcSSimon Schubert 
3740c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
3741cf7f2e2dSJohn Marino   {
3742c50c785cSJohn Marino     /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL.  */
3743c50c785cSJohn Marino     if (bl->pspace == pspace
3744c50c785cSJohn Marino 	&& bl->owner->enable_state != bp_permanent)
3745c50c785cSJohn Marino       bl->inserted = 0;
3746cf7f2e2dSJohn Marino   }
37475796c8dcSSimon Schubert 
3748c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
37495796c8dcSSimon Schubert   {
3750cf7f2e2dSJohn Marino     if (b->loc && b->loc->pspace != pspace)
3751cf7f2e2dSJohn Marino       continue;
3752cf7f2e2dSJohn Marino 
37535796c8dcSSimon Schubert     switch (b->type)
37545796c8dcSSimon Schubert       {
37555796c8dcSSimon Schubert       case bp_call_dummy:
3756*ef5ccd6cSJohn Marino       case bp_longjmp_call_dummy:
37575796c8dcSSimon Schubert 
37585796c8dcSSimon Schubert 	/* If the call dummy breakpoint is at the entry point it will
3759cf7f2e2dSJohn Marino 	   cause problems when the inferior is rerun, so we better get
3760cf7f2e2dSJohn Marino 	   rid of it.  */
37615796c8dcSSimon Schubert 
3762cf7f2e2dSJohn Marino       case bp_watchpoint_scope:
3763cf7f2e2dSJohn Marino 
3764cf7f2e2dSJohn Marino 	/* Also get rid of scope breakpoints.  */
3765cf7f2e2dSJohn Marino 
3766cf7f2e2dSJohn Marino       case bp_shlib_event:
3767cf7f2e2dSJohn Marino 
3768cf7f2e2dSJohn Marino 	/* Also remove solib event breakpoints.  Their addresses may
3769cf7f2e2dSJohn Marino 	   have changed since the last time we ran the program.
3770cf7f2e2dSJohn Marino 	   Actually we may now be debugging against different target;
3771cf7f2e2dSJohn Marino 	   and so the solib backend that installed this breakpoint may
3772cf7f2e2dSJohn Marino 	   not be used in by the target.  E.g.,
3773cf7f2e2dSJohn Marino 
3774cf7f2e2dSJohn Marino 	   (gdb) file prog-linux
3775cf7f2e2dSJohn Marino 	   (gdb) run               # native linux target
3776cf7f2e2dSJohn Marino 	   ...
3777cf7f2e2dSJohn Marino 	   (gdb) kill
3778cf7f2e2dSJohn Marino 	   (gdb) file prog-win.exe
3779cf7f2e2dSJohn Marino 	   (gdb) tar rem :9999     # remote Windows gdbserver.
3780cf7f2e2dSJohn Marino 	*/
3781cf7f2e2dSJohn Marino 
3782*ef5ccd6cSJohn Marino       case bp_step_resume:
3783*ef5ccd6cSJohn Marino 
3784*ef5ccd6cSJohn Marino 	/* Also remove step-resume breakpoints.  */
3785*ef5ccd6cSJohn Marino 
37865796c8dcSSimon Schubert 	delete_breakpoint (b);
37875796c8dcSSimon Schubert 	break;
37885796c8dcSSimon Schubert 
37895796c8dcSSimon Schubert       case bp_watchpoint:
37905796c8dcSSimon Schubert       case bp_hardware_watchpoint:
37915796c8dcSSimon Schubert       case bp_read_watchpoint:
37925796c8dcSSimon Schubert       case bp_access_watchpoint:
3793a45ae5f8SJohn Marino 	{
3794a45ae5f8SJohn Marino 	  struct watchpoint *w = (struct watchpoint *) b;
37955796c8dcSSimon Schubert 
37965796c8dcSSimon Schubert 	  /* Likewise for watchpoints on local expressions.  */
3797a45ae5f8SJohn Marino 	  if (w->exp_valid_block != NULL)
37985796c8dcSSimon Schubert 	    delete_breakpoint (b);
37995796c8dcSSimon Schubert 	  else if (context == inf_starting)
38005796c8dcSSimon Schubert 	    {
3801c50c785cSJohn Marino 	      /* Reset val field to force reread of starting value in
3802c50c785cSJohn Marino 		 insert_breakpoints.  */
3803a45ae5f8SJohn Marino 	      if (w->val)
3804a45ae5f8SJohn Marino 		value_free (w->val);
3805a45ae5f8SJohn Marino 	      w->val = NULL;
3806a45ae5f8SJohn Marino 	      w->val_valid = 0;
3807a45ae5f8SJohn Marino 	  }
38085796c8dcSSimon Schubert 	}
38095796c8dcSSimon Schubert 	break;
38105796c8dcSSimon Schubert       default:
38115796c8dcSSimon Schubert 	break;
38125796c8dcSSimon Schubert       }
38135796c8dcSSimon Schubert   }
38145796c8dcSSimon Schubert 
38155796c8dcSSimon Schubert   /* Get rid of the moribund locations.  */
3816c50c785cSJohn Marino   for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3817c50c785cSJohn Marino     decref_bp_location (&bl);
38185796c8dcSSimon Schubert   VEC_free (bp_location_p, moribund_locations);
38195796c8dcSSimon Schubert }
38205796c8dcSSimon Schubert 
3821cf7f2e2dSJohn Marino /* These functions concern about actual breakpoints inserted in the
3822cf7f2e2dSJohn Marino    target --- to e.g. check if we need to do decr_pc adjustment or if
3823cf7f2e2dSJohn Marino    we need to hop over the bkpt --- so we check for address space
3824cf7f2e2dSJohn Marino    match, not program space.  */
3825cf7f2e2dSJohn Marino 
38265796c8dcSSimon Schubert /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
38275796c8dcSSimon Schubert    exists at PC.  It returns ordinary_breakpoint_here if it's an
38285796c8dcSSimon Schubert    ordinary breakpoint, or permanent_breakpoint_here if it's a
38295796c8dcSSimon Schubert    permanent breakpoint.
38305796c8dcSSimon Schubert    - When continuing from a location with an ordinary breakpoint, we
38315796c8dcSSimon Schubert      actually single step once before calling insert_breakpoints.
3832a45ae5f8SJohn Marino    - When continuing from a location with a permanent breakpoint, we
38335796c8dcSSimon Schubert      need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
38345796c8dcSSimon Schubert      the target, to advance the PC past the breakpoint.  */
38355796c8dcSSimon Schubert 
38365796c8dcSSimon Schubert enum breakpoint_here
breakpoint_here_p(struct address_space * aspace,CORE_ADDR pc)3837cf7f2e2dSJohn Marino breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
38385796c8dcSSimon Schubert {
3839c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
38405796c8dcSSimon Schubert   int any_breakpoint_here = 0;
38415796c8dcSSimon Schubert 
3842c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
38435796c8dcSSimon Schubert     {
3844c50c785cSJohn Marino       if (bl->loc_type != bp_loc_software_breakpoint
3845c50c785cSJohn Marino 	  && bl->loc_type != bp_loc_hardware_breakpoint)
38465796c8dcSSimon Schubert 	continue;
38475796c8dcSSimon Schubert 
3848c50c785cSJohn Marino       /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL.  */
3849c50c785cSJohn Marino       if ((breakpoint_enabled (bl->owner)
3850c50c785cSJohn Marino 	   || bl->owner->enable_state == bp_permanent)
3851c50c785cSJohn Marino 	  && breakpoint_location_address_match (bl, aspace, pc))
38525796c8dcSSimon Schubert 	{
38535796c8dcSSimon Schubert 	  if (overlay_debugging
3854c50c785cSJohn Marino 	      && section_is_overlay (bl->section)
3855c50c785cSJohn Marino 	      && !section_is_mapped (bl->section))
38565796c8dcSSimon Schubert 	    continue;		/* unmapped overlay -- can't be a match */
3857c50c785cSJohn Marino 	  else if (bl->owner->enable_state == bp_permanent)
38585796c8dcSSimon Schubert 	    return permanent_breakpoint_here;
38595796c8dcSSimon Schubert 	  else
38605796c8dcSSimon Schubert 	    any_breakpoint_here = 1;
38615796c8dcSSimon Schubert 	}
38625796c8dcSSimon Schubert     }
38635796c8dcSSimon Schubert 
38645796c8dcSSimon Schubert   return any_breakpoint_here ? ordinary_breakpoint_here : 0;
38655796c8dcSSimon Schubert }
38665796c8dcSSimon Schubert 
38675796c8dcSSimon Schubert /* Return true if there's a moribund breakpoint at PC.  */
38685796c8dcSSimon Schubert 
38695796c8dcSSimon Schubert int
moribund_breakpoint_here_p(struct address_space * aspace,CORE_ADDR pc)3870cf7f2e2dSJohn Marino moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
38715796c8dcSSimon Schubert {
38725796c8dcSSimon Schubert   struct bp_location *loc;
38735796c8dcSSimon Schubert   int ix;
38745796c8dcSSimon Schubert 
38755796c8dcSSimon Schubert   for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3876c50c785cSJohn Marino     if (breakpoint_location_address_match (loc, aspace, pc))
38775796c8dcSSimon Schubert       return 1;
38785796c8dcSSimon Schubert 
38795796c8dcSSimon Schubert   return 0;
38805796c8dcSSimon Schubert }
38815796c8dcSSimon Schubert 
38825796c8dcSSimon Schubert /* Returns non-zero if there's a breakpoint inserted at PC, which is
3883c50c785cSJohn Marino    inserted using regular breakpoint_chain / bp_location array
3884c50c785cSJohn Marino    mechanism.  This does not check for single-step breakpoints, which
3885c50c785cSJohn Marino    are inserted and removed using direct target manipulation.  */
38865796c8dcSSimon Schubert 
38875796c8dcSSimon Schubert int
regular_breakpoint_inserted_here_p(struct address_space * aspace,CORE_ADDR pc)3888c50c785cSJohn Marino regular_breakpoint_inserted_here_p (struct address_space *aspace,
3889c50c785cSJohn Marino 				    CORE_ADDR pc)
38905796c8dcSSimon Schubert {
3891c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
38925796c8dcSSimon Schubert 
3893c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
38945796c8dcSSimon Schubert     {
3895c50c785cSJohn Marino       if (bl->loc_type != bp_loc_software_breakpoint
3896c50c785cSJohn Marino 	  && bl->loc_type != bp_loc_hardware_breakpoint)
38975796c8dcSSimon Schubert 	continue;
38985796c8dcSSimon Schubert 
3899c50c785cSJohn Marino       if (bl->inserted
3900c50c785cSJohn Marino 	  && breakpoint_location_address_match (bl, aspace, pc))
39015796c8dcSSimon Schubert 	{
39025796c8dcSSimon Schubert 	  if (overlay_debugging
3903c50c785cSJohn Marino 	      && section_is_overlay (bl->section)
3904c50c785cSJohn Marino 	      && !section_is_mapped (bl->section))
39055796c8dcSSimon Schubert 	    continue;		/* unmapped overlay -- can't be a match */
39065796c8dcSSimon Schubert 	  else
39075796c8dcSSimon Schubert 	    return 1;
39085796c8dcSSimon Schubert 	}
39095796c8dcSSimon Schubert     }
39105796c8dcSSimon Schubert   return 0;
39115796c8dcSSimon Schubert }
39125796c8dcSSimon Schubert 
39135796c8dcSSimon Schubert /* Returns non-zero iff there's either regular breakpoint
39145796c8dcSSimon Schubert    or a single step breakpoint inserted at PC.  */
39155796c8dcSSimon Schubert 
39165796c8dcSSimon Schubert int
breakpoint_inserted_here_p(struct address_space * aspace,CORE_ADDR pc)3917cf7f2e2dSJohn Marino breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
39185796c8dcSSimon Schubert {
3919cf7f2e2dSJohn Marino   if (regular_breakpoint_inserted_here_p (aspace, pc))
39205796c8dcSSimon Schubert     return 1;
39215796c8dcSSimon Schubert 
3922cf7f2e2dSJohn Marino   if (single_step_breakpoint_inserted_here_p (aspace, pc))
39235796c8dcSSimon Schubert     return 1;
39245796c8dcSSimon Schubert 
39255796c8dcSSimon Schubert   return 0;
39265796c8dcSSimon Schubert }
39275796c8dcSSimon Schubert 
39285796c8dcSSimon Schubert /* This function returns non-zero iff there is a software breakpoint
39295796c8dcSSimon Schubert    inserted at PC.  */
39305796c8dcSSimon Schubert 
39315796c8dcSSimon Schubert int
software_breakpoint_inserted_here_p(struct address_space * aspace,CORE_ADDR pc)3932c50c785cSJohn Marino software_breakpoint_inserted_here_p (struct address_space *aspace,
3933c50c785cSJohn Marino 				     CORE_ADDR pc)
39345796c8dcSSimon Schubert {
3935c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
39365796c8dcSSimon Schubert 
3937c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
39385796c8dcSSimon Schubert     {
3939c50c785cSJohn Marino       if (bl->loc_type != bp_loc_software_breakpoint)
39405796c8dcSSimon Schubert 	continue;
39415796c8dcSSimon Schubert 
3942c50c785cSJohn Marino       if (bl->inserted
3943c50c785cSJohn Marino 	  && breakpoint_address_match (bl->pspace->aspace, bl->address,
3944cf7f2e2dSJohn Marino 				       aspace, pc))
39455796c8dcSSimon Schubert 	{
39465796c8dcSSimon Schubert 	  if (overlay_debugging
3947c50c785cSJohn Marino 	      && section_is_overlay (bl->section)
3948c50c785cSJohn Marino 	      && !section_is_mapped (bl->section))
39495796c8dcSSimon Schubert 	    continue;		/* unmapped overlay -- can't be a match */
39505796c8dcSSimon Schubert 	  else
39515796c8dcSSimon Schubert 	    return 1;
39525796c8dcSSimon Schubert 	}
39535796c8dcSSimon Schubert     }
39545796c8dcSSimon Schubert 
39555796c8dcSSimon Schubert   /* Also check for software single-step breakpoints.  */
3956cf7f2e2dSJohn Marino   if (single_step_breakpoint_inserted_here_p (aspace, pc))
39575796c8dcSSimon Schubert     return 1;
39585796c8dcSSimon Schubert 
39595796c8dcSSimon Schubert   return 0;
39605796c8dcSSimon Schubert }
39615796c8dcSSimon Schubert 
3962cf7f2e2dSJohn Marino int
hardware_watchpoint_inserted_in_range(struct address_space * aspace,CORE_ADDR addr,ULONGEST len)3963cf7f2e2dSJohn Marino hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3964cf7f2e2dSJohn Marino 				       CORE_ADDR addr, ULONGEST len)
3965cf7f2e2dSJohn Marino {
3966cf7f2e2dSJohn Marino   struct breakpoint *bpt;
3967cf7f2e2dSJohn Marino 
3968cf7f2e2dSJohn Marino   ALL_BREAKPOINTS (bpt)
3969cf7f2e2dSJohn Marino     {
3970cf7f2e2dSJohn Marino       struct bp_location *loc;
3971cf7f2e2dSJohn Marino 
3972cf7f2e2dSJohn Marino       if (bpt->type != bp_hardware_watchpoint
3973cf7f2e2dSJohn Marino 	  && bpt->type != bp_access_watchpoint)
3974cf7f2e2dSJohn Marino 	continue;
3975cf7f2e2dSJohn Marino 
3976cf7f2e2dSJohn Marino       if (!breakpoint_enabled (bpt))
3977cf7f2e2dSJohn Marino 	continue;
3978cf7f2e2dSJohn Marino 
3979cf7f2e2dSJohn Marino       for (loc = bpt->loc; loc; loc = loc->next)
3980cf7f2e2dSJohn Marino 	if (loc->pspace->aspace == aspace && loc->inserted)
3981cf7f2e2dSJohn Marino 	  {
3982cf7f2e2dSJohn Marino 	    CORE_ADDR l, h;
3983cf7f2e2dSJohn Marino 
3984cf7f2e2dSJohn Marino 	    /* Check for intersection.  */
3985cf7f2e2dSJohn Marino 	    l = max (loc->address, addr);
3986cf7f2e2dSJohn Marino 	    h = min (loc->address + loc->length, addr + len);
3987cf7f2e2dSJohn Marino 	    if (l < h)
3988cf7f2e2dSJohn Marino 	      return 1;
3989cf7f2e2dSJohn Marino 	  }
3990cf7f2e2dSJohn Marino     }
3991cf7f2e2dSJohn Marino   return 0;
3992cf7f2e2dSJohn Marino }
3993cf7f2e2dSJohn Marino 
39945796c8dcSSimon Schubert /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
39955796c8dcSSimon Schubert    PC is valid for process/thread PTID.  */
39965796c8dcSSimon Schubert 
39975796c8dcSSimon Schubert int
breakpoint_thread_match(struct address_space * aspace,CORE_ADDR pc,ptid_t ptid)3998cf7f2e2dSJohn Marino breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3999cf7f2e2dSJohn Marino 			 ptid_t ptid)
40005796c8dcSSimon Schubert {
4001c50c785cSJohn Marino   struct bp_location *bl, **blp_tmp;
40025796c8dcSSimon Schubert   /* The thread and task IDs associated to PTID, computed lazily.  */
40035796c8dcSSimon Schubert   int thread = -1;
40045796c8dcSSimon Schubert   int task = 0;
40055796c8dcSSimon Schubert 
4006c50c785cSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
40075796c8dcSSimon Schubert     {
4008c50c785cSJohn Marino       if (bl->loc_type != bp_loc_software_breakpoint
4009c50c785cSJohn Marino 	  && bl->loc_type != bp_loc_hardware_breakpoint)
40105796c8dcSSimon Schubert 	continue;
40115796c8dcSSimon Schubert 
4012c50c785cSJohn Marino       /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL.  */
4013c50c785cSJohn Marino       if (!breakpoint_enabled (bl->owner)
4014c50c785cSJohn Marino 	  && bl->owner->enable_state != bp_permanent)
40155796c8dcSSimon Schubert 	continue;
40165796c8dcSSimon Schubert 
4017c50c785cSJohn Marino       if (!breakpoint_location_address_match (bl, aspace, pc))
40185796c8dcSSimon Schubert 	continue;
40195796c8dcSSimon Schubert 
4020c50c785cSJohn Marino       if (bl->owner->thread != -1)
40215796c8dcSSimon Schubert 	{
40225796c8dcSSimon Schubert 	  /* This is a thread-specific breakpoint.  Check that ptid
40235796c8dcSSimon Schubert 	     matches that thread.  If thread hasn't been computed yet,
40245796c8dcSSimon Schubert 	     it is now time to do so.  */
40255796c8dcSSimon Schubert 	  if (thread == -1)
40265796c8dcSSimon Schubert 	    thread = pid_to_thread_id (ptid);
4027c50c785cSJohn Marino 	  if (bl->owner->thread != thread)
40285796c8dcSSimon Schubert 	    continue;
40295796c8dcSSimon Schubert 	}
40305796c8dcSSimon Schubert 
4031c50c785cSJohn Marino       if (bl->owner->task != 0)
40325796c8dcSSimon Schubert         {
40335796c8dcSSimon Schubert 	  /* This is a task-specific breakpoint.  Check that ptid
40345796c8dcSSimon Schubert 	     matches that task.  If task hasn't been computed yet,
40355796c8dcSSimon Schubert 	     it is now time to do so.  */
40365796c8dcSSimon Schubert 	  if (task == 0)
40375796c8dcSSimon Schubert 	    task = ada_get_task_number (ptid);
4038c50c785cSJohn Marino 	  if (bl->owner->task != task)
40395796c8dcSSimon Schubert 	    continue;
40405796c8dcSSimon Schubert         }
40415796c8dcSSimon Schubert 
40425796c8dcSSimon Schubert       if (overlay_debugging
4043c50c785cSJohn Marino 	  && section_is_overlay (bl->section)
4044c50c785cSJohn Marino 	  && !section_is_mapped (bl->section))
40455796c8dcSSimon Schubert 	continue;	    /* unmapped overlay -- can't be a match */
40465796c8dcSSimon Schubert 
40475796c8dcSSimon Schubert       return 1;
40485796c8dcSSimon Schubert     }
40495796c8dcSSimon Schubert 
40505796c8dcSSimon Schubert   return 0;
40515796c8dcSSimon Schubert }
40525796c8dcSSimon Schubert 
40535796c8dcSSimon Schubert 
40545796c8dcSSimon Schubert /* bpstat stuff.  External routines' interfaces are documented
40555796c8dcSSimon Schubert    in breakpoint.h.  */
40565796c8dcSSimon Schubert 
40575796c8dcSSimon Schubert int
is_catchpoint(struct breakpoint * ep)4058*ef5ccd6cSJohn Marino is_catchpoint (struct breakpoint *ep)
40595796c8dcSSimon Schubert {
40605796c8dcSSimon Schubert   return (ep->type == bp_catchpoint);
40615796c8dcSSimon Schubert }
40625796c8dcSSimon Schubert 
4063c50c785cSJohn Marino /* Frees any storage that is part of a bpstat.  Does not walk the
4064c50c785cSJohn Marino    'next' chain.  */
4065c50c785cSJohn Marino 
4066c50c785cSJohn Marino static void
bpstat_free(bpstat bs)40675796c8dcSSimon Schubert bpstat_free (bpstat bs)
40685796c8dcSSimon Schubert {
40695796c8dcSSimon Schubert   if (bs->old_val != NULL)
40705796c8dcSSimon Schubert     value_free (bs->old_val);
4071cf7f2e2dSJohn Marino   decref_counted_command_line (&bs->commands);
4072c50c785cSJohn Marino   decref_bp_location (&bs->bp_location_at);
40735796c8dcSSimon Schubert   xfree (bs);
40745796c8dcSSimon Schubert }
40755796c8dcSSimon Schubert 
40765796c8dcSSimon Schubert /* Clear a bpstat so that it says we are not at any breakpoint.
40775796c8dcSSimon Schubert    Also free any storage that is part of a bpstat.  */
40785796c8dcSSimon Schubert 
40795796c8dcSSimon Schubert void
bpstat_clear(bpstat * bsp)40805796c8dcSSimon Schubert bpstat_clear (bpstat *bsp)
40815796c8dcSSimon Schubert {
40825796c8dcSSimon Schubert   bpstat p;
40835796c8dcSSimon Schubert   bpstat q;
40845796c8dcSSimon Schubert 
40855796c8dcSSimon Schubert   if (bsp == 0)
40865796c8dcSSimon Schubert     return;
40875796c8dcSSimon Schubert   p = *bsp;
40885796c8dcSSimon Schubert   while (p != NULL)
40895796c8dcSSimon Schubert     {
40905796c8dcSSimon Schubert       q = p->next;
40915796c8dcSSimon Schubert       bpstat_free (p);
40925796c8dcSSimon Schubert       p = q;
40935796c8dcSSimon Schubert     }
40945796c8dcSSimon Schubert   *bsp = NULL;
40955796c8dcSSimon Schubert }
40965796c8dcSSimon Schubert 
40975796c8dcSSimon Schubert /* Return a copy of a bpstat.  Like "bs1 = bs2" but all storage that
40985796c8dcSSimon Schubert    is part of the bpstat is copied as well.  */
40995796c8dcSSimon Schubert 
41005796c8dcSSimon Schubert bpstat
bpstat_copy(bpstat bs)41015796c8dcSSimon Schubert bpstat_copy (bpstat bs)
41025796c8dcSSimon Schubert {
41035796c8dcSSimon Schubert   bpstat p = NULL;
41045796c8dcSSimon Schubert   bpstat tmp;
41055796c8dcSSimon Schubert   bpstat retval = NULL;
41065796c8dcSSimon Schubert 
41075796c8dcSSimon Schubert   if (bs == NULL)
41085796c8dcSSimon Schubert     return bs;
41095796c8dcSSimon Schubert 
41105796c8dcSSimon Schubert   for (; bs != NULL; bs = bs->next)
41115796c8dcSSimon Schubert     {
41125796c8dcSSimon Schubert       tmp = (bpstat) xmalloc (sizeof (*tmp));
41135796c8dcSSimon Schubert       memcpy (tmp, bs, sizeof (*tmp));
4114cf7f2e2dSJohn Marino       incref_counted_command_line (tmp->commands);
4115c50c785cSJohn Marino       incref_bp_location (tmp->bp_location_at);
41165796c8dcSSimon Schubert       if (bs->old_val != NULL)
41175796c8dcSSimon Schubert 	{
41185796c8dcSSimon Schubert 	  tmp->old_val = value_copy (bs->old_val);
41195796c8dcSSimon Schubert 	  release_value (tmp->old_val);
41205796c8dcSSimon Schubert 	}
41215796c8dcSSimon Schubert 
41225796c8dcSSimon Schubert       if (p == NULL)
41235796c8dcSSimon Schubert 	/* This is the first thing in the chain.  */
41245796c8dcSSimon Schubert 	retval = tmp;
41255796c8dcSSimon Schubert       else
41265796c8dcSSimon Schubert 	p->next = tmp;
41275796c8dcSSimon Schubert       p = tmp;
41285796c8dcSSimon Schubert     }
41295796c8dcSSimon Schubert   p->next = NULL;
41305796c8dcSSimon Schubert   return retval;
41315796c8dcSSimon Schubert }
41325796c8dcSSimon Schubert 
4133c50c785cSJohn Marino /* Find the bpstat associated with this breakpoint.  */
41345796c8dcSSimon Schubert 
41355796c8dcSSimon Schubert bpstat
bpstat_find_breakpoint(bpstat bsp,struct breakpoint * breakpoint)41365796c8dcSSimon Schubert bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
41375796c8dcSSimon Schubert {
41385796c8dcSSimon Schubert   if (bsp == NULL)
41395796c8dcSSimon Schubert     return NULL;
41405796c8dcSSimon Schubert 
41415796c8dcSSimon Schubert   for (; bsp != NULL; bsp = bsp->next)
41425796c8dcSSimon Schubert     {
4143c50c785cSJohn Marino       if (bsp->breakpoint_at == breakpoint)
41445796c8dcSSimon Schubert 	return bsp;
41455796c8dcSSimon Schubert     }
41465796c8dcSSimon Schubert   return NULL;
41475796c8dcSSimon Schubert }
41485796c8dcSSimon Schubert 
4149*ef5ccd6cSJohn Marino /* See breakpoint.h.  */
4150*ef5ccd6cSJohn Marino 
4151*ef5ccd6cSJohn Marino enum bpstat_signal_value
bpstat_explains_signal(bpstat bsp,enum gdb_signal sig)4152*ef5ccd6cSJohn Marino bpstat_explains_signal (bpstat bsp, enum gdb_signal sig)
4153*ef5ccd6cSJohn Marino {
4154*ef5ccd6cSJohn Marino   enum bpstat_signal_value result = BPSTAT_SIGNAL_NO;
4155*ef5ccd6cSJohn Marino 
4156*ef5ccd6cSJohn Marino   for (; bsp != NULL; bsp = bsp->next)
4157*ef5ccd6cSJohn Marino     {
4158*ef5ccd6cSJohn Marino       /* Ensure that, if we ever entered this loop, then we at least
4159*ef5ccd6cSJohn Marino 	 return BPSTAT_SIGNAL_HIDE.  */
4160*ef5ccd6cSJohn Marino       enum bpstat_signal_value newval;
4161*ef5ccd6cSJohn Marino 
4162*ef5ccd6cSJohn Marino       if (bsp->breakpoint_at == NULL)
4163*ef5ccd6cSJohn Marino 	{
4164*ef5ccd6cSJohn Marino 	  /* A moribund location can never explain a signal other than
4165*ef5ccd6cSJohn Marino 	     GDB_SIGNAL_TRAP.  */
4166*ef5ccd6cSJohn Marino 	  if (sig == GDB_SIGNAL_TRAP)
4167*ef5ccd6cSJohn Marino 	    newval = BPSTAT_SIGNAL_HIDE;
4168*ef5ccd6cSJohn Marino 	  else
4169*ef5ccd6cSJohn Marino 	    newval = BPSTAT_SIGNAL_NO;
4170*ef5ccd6cSJohn Marino 	}
4171*ef5ccd6cSJohn Marino       else
4172*ef5ccd6cSJohn Marino 	newval = bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at,
4173*ef5ccd6cSJohn Marino 							   sig);
4174*ef5ccd6cSJohn Marino 
4175*ef5ccd6cSJohn Marino       if (newval > result)
4176*ef5ccd6cSJohn Marino 	result = newval;
4177*ef5ccd6cSJohn Marino     }
4178*ef5ccd6cSJohn Marino 
4179*ef5ccd6cSJohn Marino   return result;
4180*ef5ccd6cSJohn Marino }
4181*ef5ccd6cSJohn Marino 
4182c50c785cSJohn Marino /* Put in *NUM the breakpoint number of the first breakpoint we are
4183c50c785cSJohn Marino    stopped at.  *BSP upon return is a bpstat which points to the
4184c50c785cSJohn Marino    remaining breakpoints stopped at (but which is not guaranteed to be
4185c50c785cSJohn Marino    good for anything but further calls to bpstat_num).
4186c50c785cSJohn Marino 
41875796c8dcSSimon Schubert    Return 0 if passed a bpstat which does not indicate any breakpoints.
41885796c8dcSSimon Schubert    Return -1 if stopped at a breakpoint that has been deleted since
41895796c8dcSSimon Schubert    we set it.
41905796c8dcSSimon Schubert    Return 1 otherwise.  */
41915796c8dcSSimon Schubert 
41925796c8dcSSimon Schubert int
bpstat_num(bpstat * bsp,int * num)41935796c8dcSSimon Schubert bpstat_num (bpstat *bsp, int *num)
41945796c8dcSSimon Schubert {
41955796c8dcSSimon Schubert   struct breakpoint *b;
41965796c8dcSSimon Schubert 
41975796c8dcSSimon Schubert   if ((*bsp) == NULL)
41985796c8dcSSimon Schubert     return 0;			/* No more breakpoint values */
41995796c8dcSSimon Schubert 
4200c50c785cSJohn Marino   /* We assume we'll never have several bpstats that correspond to a
4201c50c785cSJohn Marino      single breakpoint -- otherwise, this function might return the
4202c50c785cSJohn Marino      same number more than once and this will look ugly.  */
4203c50c785cSJohn Marino   b = (*bsp)->breakpoint_at;
42045796c8dcSSimon Schubert   *bsp = (*bsp)->next;
42055796c8dcSSimon Schubert   if (b == NULL)
42065796c8dcSSimon Schubert     return -1;			/* breakpoint that's been deleted since */
42075796c8dcSSimon Schubert 
42085796c8dcSSimon Schubert   *num = b->number;		/* We have its number */
42095796c8dcSSimon Schubert   return 1;
42105796c8dcSSimon Schubert }
42115796c8dcSSimon Schubert 
4212a45ae5f8SJohn Marino /* See breakpoint.h.  */
42135796c8dcSSimon Schubert 
42145796c8dcSSimon Schubert void
bpstat_clear_actions(void)4215a45ae5f8SJohn Marino bpstat_clear_actions (void)
42165796c8dcSSimon Schubert {
4217a45ae5f8SJohn Marino   struct thread_info *tp;
4218a45ae5f8SJohn Marino   bpstat bs;
4219a45ae5f8SJohn Marino 
4220a45ae5f8SJohn Marino   if (ptid_equal (inferior_ptid, null_ptid))
4221a45ae5f8SJohn Marino     return;
4222a45ae5f8SJohn Marino 
4223a45ae5f8SJohn Marino   tp = find_thread_ptid (inferior_ptid);
4224a45ae5f8SJohn Marino   if (tp == NULL)
4225a45ae5f8SJohn Marino     return;
4226a45ae5f8SJohn Marino 
4227a45ae5f8SJohn Marino   for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
42285796c8dcSSimon Schubert     {
4229cf7f2e2dSJohn Marino       decref_counted_command_line (&bs->commands);
4230a45ae5f8SJohn Marino 
42315796c8dcSSimon Schubert       if (bs->old_val != NULL)
42325796c8dcSSimon Schubert 	{
42335796c8dcSSimon Schubert 	  value_free (bs->old_val);
42345796c8dcSSimon Schubert 	  bs->old_val = NULL;
42355796c8dcSSimon Schubert 	}
42365796c8dcSSimon Schubert     }
42375796c8dcSSimon Schubert }
42385796c8dcSSimon Schubert 
42395796c8dcSSimon Schubert /* Called when a command is about to proceed the inferior.  */
42405796c8dcSSimon Schubert 
42415796c8dcSSimon Schubert static void
breakpoint_about_to_proceed(void)42425796c8dcSSimon Schubert breakpoint_about_to_proceed (void)
42435796c8dcSSimon Schubert {
42445796c8dcSSimon Schubert   if (!ptid_equal (inferior_ptid, null_ptid))
42455796c8dcSSimon Schubert     {
42465796c8dcSSimon Schubert       struct thread_info *tp = inferior_thread ();
42475796c8dcSSimon Schubert 
42485796c8dcSSimon Schubert       /* Allow inferior function calls in breakpoint commands to not
42495796c8dcSSimon Schubert 	 interrupt the command list.  When the call finishes
42505796c8dcSSimon Schubert 	 successfully, the inferior will be standing at the same
42515796c8dcSSimon Schubert 	 breakpoint as if nothing happened.  */
4252c50c785cSJohn Marino       if (tp->control.in_infcall)
42535796c8dcSSimon Schubert 	return;
42545796c8dcSSimon Schubert     }
42555796c8dcSSimon Schubert 
42565796c8dcSSimon Schubert   breakpoint_proceeded = 1;
42575796c8dcSSimon Schubert }
42585796c8dcSSimon Schubert 
4259c50c785cSJohn Marino /* Stub for cleaning up our state if we error-out of a breakpoint
4260c50c785cSJohn Marino    command.  */
42615796c8dcSSimon Schubert static void
cleanup_executing_breakpoints(void * ignore)42625796c8dcSSimon Schubert cleanup_executing_breakpoints (void *ignore)
42635796c8dcSSimon Schubert {
42645796c8dcSSimon Schubert   executing_breakpoint_commands = 0;
42655796c8dcSSimon Schubert }
42665796c8dcSSimon Schubert 
4267a45ae5f8SJohn Marino /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4268a45ae5f8SJohn Marino    or its equivalent.  */
4269a45ae5f8SJohn Marino 
4270a45ae5f8SJohn Marino static int
command_line_is_silent(struct command_line * cmd)4271a45ae5f8SJohn Marino command_line_is_silent (struct command_line *cmd)
4272a45ae5f8SJohn Marino {
4273a45ae5f8SJohn Marino   return cmd && (strcmp ("silent", cmd->line) == 0
4274a45ae5f8SJohn Marino 		 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
4275a45ae5f8SJohn Marino }
4276a45ae5f8SJohn Marino 
4277c50c785cSJohn Marino /* Execute all the commands associated with all the breakpoints at
4278c50c785cSJohn Marino    this location.  Any of these commands could cause the process to
4279c50c785cSJohn Marino    proceed beyond this point, etc.  We look out for such changes by
4280c50c785cSJohn Marino    checking the global "breakpoint_proceeded" after each command.
42815796c8dcSSimon Schubert 
42825796c8dcSSimon Schubert    Returns true if a breakpoint command resumed the inferior.  In that
42835796c8dcSSimon Schubert    case, it is the caller's responsibility to recall it again with the
42845796c8dcSSimon Schubert    bpstat of the current thread.  */
42855796c8dcSSimon Schubert 
42865796c8dcSSimon Schubert static int
bpstat_do_actions_1(bpstat * bsp)42875796c8dcSSimon Schubert bpstat_do_actions_1 (bpstat *bsp)
42885796c8dcSSimon Schubert {
42895796c8dcSSimon Schubert   bpstat bs;
42905796c8dcSSimon Schubert   struct cleanup *old_chain;
42915796c8dcSSimon Schubert   int again = 0;
42925796c8dcSSimon Schubert 
42935796c8dcSSimon Schubert   /* Avoid endless recursion if a `source' command is contained
42945796c8dcSSimon Schubert      in bs->commands.  */
42955796c8dcSSimon Schubert   if (executing_breakpoint_commands)
42965796c8dcSSimon Schubert     return 0;
42975796c8dcSSimon Schubert 
42985796c8dcSSimon Schubert   executing_breakpoint_commands = 1;
42995796c8dcSSimon Schubert   old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
43005796c8dcSSimon Schubert 
4301a45ae5f8SJohn Marino   prevent_dont_repeat ();
4302a45ae5f8SJohn Marino 
43035796c8dcSSimon Schubert   /* This pointer will iterate over the list of bpstat's.  */
43045796c8dcSSimon Schubert   bs = *bsp;
43055796c8dcSSimon Schubert 
43065796c8dcSSimon Schubert   breakpoint_proceeded = 0;
43075796c8dcSSimon Schubert   for (; bs != NULL; bs = bs->next)
43085796c8dcSSimon Schubert     {
4309cf7f2e2dSJohn Marino       struct counted_command_line *ccmd;
43105796c8dcSSimon Schubert       struct command_line *cmd;
43115796c8dcSSimon Schubert       struct cleanup *this_cmd_tree_chain;
43125796c8dcSSimon Schubert 
43135796c8dcSSimon Schubert       /* Take ownership of the BSP's command tree, if it has one.
43145796c8dcSSimon Schubert 
43155796c8dcSSimon Schubert          The command tree could legitimately contain commands like
43165796c8dcSSimon Schubert          'step' and 'next', which call clear_proceed_status, which
43175796c8dcSSimon Schubert          frees stop_bpstat's command tree.  To make sure this doesn't
43185796c8dcSSimon Schubert          free the tree we're executing out from under us, we need to
43195796c8dcSSimon Schubert          take ownership of the tree ourselves.  Since a given bpstat's
43205796c8dcSSimon Schubert          commands are only executed once, we don't need to copy it; we
43215796c8dcSSimon Schubert          can clear the pointer in the bpstat, and make sure we free
43225796c8dcSSimon Schubert          the tree when we're done.  */
4323cf7f2e2dSJohn Marino       ccmd = bs->commands;
4324cf7f2e2dSJohn Marino       bs->commands = NULL;
4325a45ae5f8SJohn Marino       this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
4326a45ae5f8SJohn Marino       cmd = ccmd ? ccmd->commands : NULL;
4327a45ae5f8SJohn Marino       if (command_line_is_silent (cmd))
4328a45ae5f8SJohn Marino 	{
4329a45ae5f8SJohn Marino 	  /* The action has been already done by bpstat_stop_status.  */
4330a45ae5f8SJohn Marino 	  cmd = cmd->next;
4331a45ae5f8SJohn Marino 	}
43325796c8dcSSimon Schubert 
43335796c8dcSSimon Schubert       while (cmd != NULL)
43345796c8dcSSimon Schubert 	{
43355796c8dcSSimon Schubert 	  execute_control_command (cmd);
43365796c8dcSSimon Schubert 
43375796c8dcSSimon Schubert 	  if (breakpoint_proceeded)
43385796c8dcSSimon Schubert 	    break;
43395796c8dcSSimon Schubert 	  else
43405796c8dcSSimon Schubert 	    cmd = cmd->next;
43415796c8dcSSimon Schubert 	}
43425796c8dcSSimon Schubert 
43435796c8dcSSimon Schubert       /* We can free this command tree now.  */
43445796c8dcSSimon Schubert       do_cleanups (this_cmd_tree_chain);
43455796c8dcSSimon Schubert 
43465796c8dcSSimon Schubert       if (breakpoint_proceeded)
43475796c8dcSSimon Schubert 	{
43485796c8dcSSimon Schubert 	  if (target_can_async_p ())
43495796c8dcSSimon Schubert 	    /* If we are in async mode, then the target might be still
43505796c8dcSSimon Schubert 	       running, not stopped at any breakpoint, so nothing for
43515796c8dcSSimon Schubert 	       us to do here -- just return to the event loop.  */
43525796c8dcSSimon Schubert 	    ;
43535796c8dcSSimon Schubert 	  else
43545796c8dcSSimon Schubert 	    /* In sync mode, when execute_control_command returns
43555796c8dcSSimon Schubert 	       we're already standing on the next breakpoint.
43565796c8dcSSimon Schubert 	       Breakpoint commands for that stop were not run, since
43575796c8dcSSimon Schubert 	       execute_command does not run breakpoint commands --
43585796c8dcSSimon Schubert 	       only command_line_handler does, but that one is not
43595796c8dcSSimon Schubert 	       involved in execution of breakpoint commands.  So, we
43605796c8dcSSimon Schubert 	       can now execute breakpoint commands.  It should be
43615796c8dcSSimon Schubert 	       noted that making execute_command do bpstat actions is
43625796c8dcSSimon Schubert 	       not an option -- in this case we'll have recursive
43635796c8dcSSimon Schubert 	       invocation of bpstat for each breakpoint with a
43645796c8dcSSimon Schubert 	       command, and can easily blow up GDB stack.  Instead, we
43655796c8dcSSimon Schubert 	       return true, which will trigger the caller to recall us
43665796c8dcSSimon Schubert 	       with the new stop_bpstat.  */
43675796c8dcSSimon Schubert 	    again = 1;
43685796c8dcSSimon Schubert 	  break;
43695796c8dcSSimon Schubert 	}
43705796c8dcSSimon Schubert     }
43715796c8dcSSimon Schubert   do_cleanups (old_chain);
43725796c8dcSSimon Schubert   return again;
43735796c8dcSSimon Schubert }
43745796c8dcSSimon Schubert 
43755796c8dcSSimon Schubert void
bpstat_do_actions(void)43765796c8dcSSimon Schubert bpstat_do_actions (void)
43775796c8dcSSimon Schubert {
4378a45ae5f8SJohn Marino   struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4379a45ae5f8SJohn Marino 
43805796c8dcSSimon Schubert   /* Do any commands attached to breakpoint we are stopped at.  */
43815796c8dcSSimon Schubert   while (!ptid_equal (inferior_ptid, null_ptid)
43825796c8dcSSimon Schubert 	 && target_has_execution
43835796c8dcSSimon Schubert 	 && !is_exited (inferior_ptid)
43845796c8dcSSimon Schubert 	 && !is_executing (inferior_ptid))
43855796c8dcSSimon Schubert     /* Since in sync mode, bpstat_do_actions may resume the inferior,
43865796c8dcSSimon Schubert        and only return when it is stopped at the next breakpoint, we
43875796c8dcSSimon Schubert        keep doing breakpoint actions until it returns false to
43885796c8dcSSimon Schubert        indicate the inferior was not resumed.  */
4389c50c785cSJohn Marino     if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
43905796c8dcSSimon Schubert       break;
4391a45ae5f8SJohn Marino 
4392a45ae5f8SJohn Marino   discard_cleanups (cleanup_if_error);
43935796c8dcSSimon Schubert }
43945796c8dcSSimon Schubert 
43955796c8dcSSimon Schubert /* Print out the (old or new) value associated with a watchpoint.  */
43965796c8dcSSimon Schubert 
43975796c8dcSSimon Schubert static void
watchpoint_value_print(struct value * val,struct ui_file * stream)43985796c8dcSSimon Schubert watchpoint_value_print (struct value *val, struct ui_file *stream)
43995796c8dcSSimon Schubert {
44005796c8dcSSimon Schubert   if (val == NULL)
44015796c8dcSSimon Schubert     fprintf_unfiltered (stream, _("<unreadable>"));
44025796c8dcSSimon Schubert   else
44035796c8dcSSimon Schubert     {
44045796c8dcSSimon Schubert       struct value_print_options opts;
44055796c8dcSSimon Schubert       get_user_print_options (&opts);
44065796c8dcSSimon Schubert       value_print (val, stream, &opts);
44075796c8dcSSimon Schubert     }
44085796c8dcSSimon Schubert }
44095796c8dcSSimon Schubert 
44105796c8dcSSimon Schubert /* Generic routine for printing messages indicating why we
44115796c8dcSSimon Schubert    stopped.  The behavior of this function depends on the value
44125796c8dcSSimon Schubert    'print_it' in the bpstat structure.  Under some circumstances we
44135796c8dcSSimon Schubert    may decide not to print anything here and delegate the task to
44145796c8dcSSimon Schubert    normal_stop().  */
44155796c8dcSSimon Schubert 
44165796c8dcSSimon Schubert static enum print_stop_action
print_bp_stop_message(bpstat bs)44175796c8dcSSimon Schubert print_bp_stop_message (bpstat bs)
44185796c8dcSSimon Schubert {
44195796c8dcSSimon Schubert   switch (bs->print_it)
44205796c8dcSSimon Schubert     {
44215796c8dcSSimon Schubert     case print_it_noop:
44225796c8dcSSimon Schubert       /* Nothing should be printed for this bpstat entry.  */
44235796c8dcSSimon Schubert       return PRINT_UNKNOWN;
44245796c8dcSSimon Schubert       break;
44255796c8dcSSimon Schubert 
44265796c8dcSSimon Schubert     case print_it_done:
44275796c8dcSSimon Schubert       /* We still want to print the frame, but we already printed the
44285796c8dcSSimon Schubert          relevant messages.  */
44295796c8dcSSimon Schubert       return PRINT_SRC_AND_LOC;
44305796c8dcSSimon Schubert       break;
44315796c8dcSSimon Schubert 
44325796c8dcSSimon Schubert     case print_it_normal:
44335796c8dcSSimon Schubert       {
4434c50c785cSJohn Marino 	struct breakpoint *b = bs->breakpoint_at;
4435c50c785cSJohn Marino 
4436c50c785cSJohn Marino 	/* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4437c50c785cSJohn Marino 	   which has since been deleted.  */
4438c50c785cSJohn Marino 	if (b == NULL)
4439c50c785cSJohn Marino 	  return PRINT_UNKNOWN;
44405796c8dcSSimon Schubert 
4441a45ae5f8SJohn Marino 	/* Normal case.  Call the breakpoint's print_it method.  */
4442a45ae5f8SJohn Marino 	return b->ops->print_it (bs);
44435796c8dcSSimon Schubert       }
44445796c8dcSSimon Schubert       break;
44455796c8dcSSimon Schubert 
44465796c8dcSSimon Schubert     default:
44475796c8dcSSimon Schubert       internal_error (__FILE__, __LINE__,
44485796c8dcSSimon Schubert 		      _("print_bp_stop_message: unrecognized enum value"));
44495796c8dcSSimon Schubert       break;
44505796c8dcSSimon Schubert     }
44515796c8dcSSimon Schubert }
44525796c8dcSSimon Schubert 
4453*ef5ccd6cSJohn Marino /* A helper function that prints a shared library stopped event.  */
4454*ef5ccd6cSJohn Marino 
4455*ef5ccd6cSJohn Marino static void
print_solib_event(int is_catchpoint)4456*ef5ccd6cSJohn Marino print_solib_event (int is_catchpoint)
4457*ef5ccd6cSJohn Marino {
4458*ef5ccd6cSJohn Marino   int any_deleted
4459*ef5ccd6cSJohn Marino     = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4460*ef5ccd6cSJohn Marino   int any_added
4461*ef5ccd6cSJohn Marino     = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4462*ef5ccd6cSJohn Marino 
4463*ef5ccd6cSJohn Marino   if (!is_catchpoint)
4464*ef5ccd6cSJohn Marino     {
4465*ef5ccd6cSJohn Marino       if (any_added || any_deleted)
4466*ef5ccd6cSJohn Marino 	ui_out_text (current_uiout,
4467*ef5ccd6cSJohn Marino 		     _("Stopped due to shared library event:\n"));
4468*ef5ccd6cSJohn Marino       else
4469*ef5ccd6cSJohn Marino 	ui_out_text (current_uiout,
4470*ef5ccd6cSJohn Marino 		     _("Stopped due to shared library event (no "
4471*ef5ccd6cSJohn Marino 		       "libraries added or removed)\n"));
4472*ef5ccd6cSJohn Marino     }
4473*ef5ccd6cSJohn Marino 
4474*ef5ccd6cSJohn Marino   if (ui_out_is_mi_like_p (current_uiout))
4475*ef5ccd6cSJohn Marino     ui_out_field_string (current_uiout, "reason",
4476*ef5ccd6cSJohn Marino 			 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4477*ef5ccd6cSJohn Marino 
4478*ef5ccd6cSJohn Marino   if (any_deleted)
4479*ef5ccd6cSJohn Marino     {
4480*ef5ccd6cSJohn Marino       struct cleanup *cleanup;
4481*ef5ccd6cSJohn Marino       char *name;
4482*ef5ccd6cSJohn Marino       int ix;
4483*ef5ccd6cSJohn Marino 
4484*ef5ccd6cSJohn Marino       ui_out_text (current_uiout, _("  Inferior unloaded "));
4485*ef5ccd6cSJohn Marino       cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4486*ef5ccd6cSJohn Marino 						    "removed");
4487*ef5ccd6cSJohn Marino       for (ix = 0;
4488*ef5ccd6cSJohn Marino 	   VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4489*ef5ccd6cSJohn Marino 			ix, name);
4490*ef5ccd6cSJohn Marino 	   ++ix)
4491*ef5ccd6cSJohn Marino 	{
4492*ef5ccd6cSJohn Marino 	  if (ix > 0)
4493*ef5ccd6cSJohn Marino 	    ui_out_text (current_uiout, "    ");
4494*ef5ccd6cSJohn Marino 	  ui_out_field_string (current_uiout, "library", name);
4495*ef5ccd6cSJohn Marino 	  ui_out_text (current_uiout, "\n");
4496*ef5ccd6cSJohn Marino 	}
4497*ef5ccd6cSJohn Marino 
4498*ef5ccd6cSJohn Marino       do_cleanups (cleanup);
4499*ef5ccd6cSJohn Marino     }
4500*ef5ccd6cSJohn Marino 
4501*ef5ccd6cSJohn Marino   if (any_added)
4502*ef5ccd6cSJohn Marino     {
4503*ef5ccd6cSJohn Marino       struct so_list *iter;
4504*ef5ccd6cSJohn Marino       int ix;
4505*ef5ccd6cSJohn Marino       struct cleanup *cleanup;
4506*ef5ccd6cSJohn Marino 
4507*ef5ccd6cSJohn Marino       ui_out_text (current_uiout, _("  Inferior loaded "));
4508*ef5ccd6cSJohn Marino       cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4509*ef5ccd6cSJohn Marino 						    "added");
4510*ef5ccd6cSJohn Marino       for (ix = 0;
4511*ef5ccd6cSJohn Marino 	   VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4512*ef5ccd6cSJohn Marino 			ix, iter);
4513*ef5ccd6cSJohn Marino 	   ++ix)
4514*ef5ccd6cSJohn Marino 	{
4515*ef5ccd6cSJohn Marino 	  if (ix > 0)
4516*ef5ccd6cSJohn Marino 	    ui_out_text (current_uiout, "    ");
4517*ef5ccd6cSJohn Marino 	  ui_out_field_string (current_uiout, "library", iter->so_name);
4518*ef5ccd6cSJohn Marino 	  ui_out_text (current_uiout, "\n");
4519*ef5ccd6cSJohn Marino 	}
4520*ef5ccd6cSJohn Marino 
4521*ef5ccd6cSJohn Marino       do_cleanups (cleanup);
4522*ef5ccd6cSJohn Marino     }
4523*ef5ccd6cSJohn Marino }
4524*ef5ccd6cSJohn Marino 
45255796c8dcSSimon Schubert /* Print a message indicating what happened.  This is called from
45265796c8dcSSimon Schubert    normal_stop().  The input to this routine is the head of the bpstat
4527a45ae5f8SJohn Marino    list - a list of the eventpoints that caused this stop.  KIND is
4528a45ae5f8SJohn Marino    the target_waitkind for the stopping event.  This
45295796c8dcSSimon Schubert    routine calls the generic print routine for printing a message
45305796c8dcSSimon Schubert    about reasons for stopping.  This will print (for example) the
45315796c8dcSSimon Schubert    "Breakpoint n," part of the output.  The return value of this
45325796c8dcSSimon Schubert    routine is one of:
45335796c8dcSSimon Schubert 
4534c50c785cSJohn Marino    PRINT_UNKNOWN: Means we printed nothing.
45355796c8dcSSimon Schubert    PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
45365796c8dcSSimon Schubert    code to print the location.  An example is
45375796c8dcSSimon Schubert    "Breakpoint 1, " which should be followed by
45385796c8dcSSimon Schubert    the location.
45395796c8dcSSimon Schubert    PRINT_SRC_ONLY: Means we printed something, but there is no need
45405796c8dcSSimon Schubert    to also print the location part of the message.
45415796c8dcSSimon Schubert    An example is the catch/throw messages, which
45425796c8dcSSimon Schubert    don't require a location appended to the end.
45435796c8dcSSimon Schubert    PRINT_NOTHING: We have done some printing and we don't need any
45445796c8dcSSimon Schubert    further info to be printed.  */
45455796c8dcSSimon Schubert 
45465796c8dcSSimon Schubert enum print_stop_action
bpstat_print(bpstat bs,int kind)4547a45ae5f8SJohn Marino bpstat_print (bpstat bs, int kind)
45485796c8dcSSimon Schubert {
45495796c8dcSSimon Schubert   int val;
45505796c8dcSSimon Schubert 
45515796c8dcSSimon Schubert   /* Maybe another breakpoint in the chain caused us to stop.
45525796c8dcSSimon Schubert      (Currently all watchpoints go on the bpstat whether hit or not.
45535796c8dcSSimon Schubert      That probably could (should) be changed, provided care is taken
45545796c8dcSSimon Schubert      with respect to bpstat_explains_signal).  */
45555796c8dcSSimon Schubert   for (; bs; bs = bs->next)
45565796c8dcSSimon Schubert     {
45575796c8dcSSimon Schubert       val = print_bp_stop_message (bs);
45585796c8dcSSimon Schubert       if (val == PRINT_SRC_ONLY
45595796c8dcSSimon Schubert 	  || val == PRINT_SRC_AND_LOC
45605796c8dcSSimon Schubert 	  || val == PRINT_NOTHING)
45615796c8dcSSimon Schubert 	return val;
45625796c8dcSSimon Schubert     }
45635796c8dcSSimon Schubert 
4564a45ae5f8SJohn Marino   /* If we had hit a shared library event breakpoint,
4565a45ae5f8SJohn Marino      print_bp_stop_message would print out this message.  If we hit an
4566a45ae5f8SJohn Marino      OS-level shared library event, do the same thing.  */
4567a45ae5f8SJohn Marino   if (kind == TARGET_WAITKIND_LOADED)
4568a45ae5f8SJohn Marino     {
4569*ef5ccd6cSJohn Marino       print_solib_event (0);
4570a45ae5f8SJohn Marino       return PRINT_NOTHING;
4571a45ae5f8SJohn Marino     }
4572a45ae5f8SJohn Marino 
45735796c8dcSSimon Schubert   /* We reached the end of the chain, or we got a null BS to start
45745796c8dcSSimon Schubert      with and nothing was printed.  */
45755796c8dcSSimon Schubert   return PRINT_UNKNOWN;
45765796c8dcSSimon Schubert }
45775796c8dcSSimon Schubert 
4578c50c785cSJohn Marino /* Evaluate the expression EXP and return 1 if value is zero.  This is
4579c50c785cSJohn Marino    used inside a catch_errors to evaluate the breakpoint condition.
4580c50c785cSJohn Marino    The argument is a "struct expression *" that has been cast to a
4581c50c785cSJohn Marino    "char *" to make it pass through catch_errors.  */
45825796c8dcSSimon Schubert 
45835796c8dcSSimon Schubert static int
breakpoint_cond_eval(void * exp)45845796c8dcSSimon Schubert breakpoint_cond_eval (void *exp)
45855796c8dcSSimon Schubert {
45865796c8dcSSimon Schubert   struct value *mark = value_mark ();
45875796c8dcSSimon Schubert   int i = !value_true (evaluate_expression ((struct expression *) exp));
4588cf7f2e2dSJohn Marino 
45895796c8dcSSimon Schubert   value_free_to_mark (mark);
45905796c8dcSSimon Schubert   return i;
45915796c8dcSSimon Schubert }
45925796c8dcSSimon Schubert 
4593c50c785cSJohn Marino /* Allocate a new bpstat.  Link it to the FIFO list by BS_LINK_POINTER.  */
45945796c8dcSSimon Schubert 
45955796c8dcSSimon Schubert static bpstat
bpstat_alloc(struct bp_location * bl,bpstat ** bs_link_pointer)4596c50c785cSJohn Marino bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
45975796c8dcSSimon Schubert {
45985796c8dcSSimon Schubert   bpstat bs;
45995796c8dcSSimon Schubert 
46005796c8dcSSimon Schubert   bs = (bpstat) xmalloc (sizeof (*bs));
4601c50c785cSJohn Marino   bs->next = NULL;
4602c50c785cSJohn Marino   **bs_link_pointer = bs;
4603c50c785cSJohn Marino   *bs_link_pointer = &bs->next;
4604c50c785cSJohn Marino   bs->breakpoint_at = bl->owner;
4605c50c785cSJohn Marino   bs->bp_location_at = bl;
4606c50c785cSJohn Marino   incref_bp_location (bl);
46075796c8dcSSimon Schubert   /* If the condition is false, etc., don't do the commands.  */
46085796c8dcSSimon Schubert   bs->commands = NULL;
46095796c8dcSSimon Schubert   bs->old_val = NULL;
46105796c8dcSSimon Schubert   bs->print_it = print_it_normal;
46115796c8dcSSimon Schubert   return bs;
46125796c8dcSSimon Schubert }
46135796c8dcSSimon Schubert 
46145796c8dcSSimon Schubert /* The target has stopped with waitstatus WS.  Check if any hardware
46155796c8dcSSimon Schubert    watchpoints have triggered, according to the target.  */
46165796c8dcSSimon Schubert 
46175796c8dcSSimon Schubert int
watchpoints_triggered(struct target_waitstatus * ws)46185796c8dcSSimon Schubert watchpoints_triggered (struct target_waitstatus *ws)
46195796c8dcSSimon Schubert {
46205796c8dcSSimon Schubert   int stopped_by_watchpoint = target_stopped_by_watchpoint ();
46215796c8dcSSimon Schubert   CORE_ADDR addr;
46225796c8dcSSimon Schubert   struct breakpoint *b;
46235796c8dcSSimon Schubert 
46245796c8dcSSimon Schubert   if (!stopped_by_watchpoint)
46255796c8dcSSimon Schubert     {
46265796c8dcSSimon Schubert       /* We were not stopped by a watchpoint.  Mark all watchpoints
46275796c8dcSSimon Schubert 	 as not triggered.  */
46285796c8dcSSimon Schubert       ALL_BREAKPOINTS (b)
4629cf7f2e2dSJohn Marino 	if (is_hardware_watchpoint (b))
4630a45ae5f8SJohn Marino 	  {
4631a45ae5f8SJohn Marino 	    struct watchpoint *w = (struct watchpoint *) b;
4632a45ae5f8SJohn Marino 
4633a45ae5f8SJohn Marino 	    w->watchpoint_triggered = watch_triggered_no;
4634a45ae5f8SJohn Marino 	  }
46355796c8dcSSimon Schubert 
46365796c8dcSSimon Schubert       return 0;
46375796c8dcSSimon Schubert     }
46385796c8dcSSimon Schubert 
46395796c8dcSSimon Schubert   if (!target_stopped_data_address (&current_target, &addr))
46405796c8dcSSimon Schubert     {
46415796c8dcSSimon Schubert       /* We were stopped by a watchpoint, but we don't know where.
46425796c8dcSSimon Schubert 	 Mark all watchpoints as unknown.  */
46435796c8dcSSimon Schubert       ALL_BREAKPOINTS (b)
4644cf7f2e2dSJohn Marino 	if (is_hardware_watchpoint (b))
4645a45ae5f8SJohn Marino 	  {
4646a45ae5f8SJohn Marino 	    struct watchpoint *w = (struct watchpoint *) b;
4647a45ae5f8SJohn Marino 
4648a45ae5f8SJohn Marino 	    w->watchpoint_triggered = watch_triggered_unknown;
4649a45ae5f8SJohn Marino 	  }
46505796c8dcSSimon Schubert 
46515796c8dcSSimon Schubert       return stopped_by_watchpoint;
46525796c8dcSSimon Schubert     }
46535796c8dcSSimon Schubert 
46545796c8dcSSimon Schubert   /* The target could report the data address.  Mark watchpoints
46555796c8dcSSimon Schubert      affected by this data address as triggered, and all others as not
46565796c8dcSSimon Schubert      triggered.  */
46575796c8dcSSimon Schubert 
46585796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
4659cf7f2e2dSJohn Marino     if (is_hardware_watchpoint (b))
46605796c8dcSSimon Schubert       {
4661a45ae5f8SJohn Marino 	struct watchpoint *w = (struct watchpoint *) b;
46625796c8dcSSimon Schubert 	struct bp_location *loc;
46635796c8dcSSimon Schubert 
4664a45ae5f8SJohn Marino 	w->watchpoint_triggered = watch_triggered_no;
46655796c8dcSSimon Schubert 	for (loc = b->loc; loc; loc = loc->next)
4666a45ae5f8SJohn Marino 	  {
4667a45ae5f8SJohn Marino 	    if (is_masked_watchpoint (b))
4668a45ae5f8SJohn Marino 	      {
4669a45ae5f8SJohn Marino 		CORE_ADDR newaddr = addr & w->hw_wp_mask;
4670a45ae5f8SJohn Marino 		CORE_ADDR start = loc->address & w->hw_wp_mask;
4671a45ae5f8SJohn Marino 
4672a45ae5f8SJohn Marino 		if (newaddr == start)
4673a45ae5f8SJohn Marino 		  {
4674a45ae5f8SJohn Marino 		    w->watchpoint_triggered = watch_triggered_yes;
4675a45ae5f8SJohn Marino 		    break;
4676a45ae5f8SJohn Marino 		  }
4677a45ae5f8SJohn Marino 	      }
4678a45ae5f8SJohn Marino 	    /* Exact match not required.  Within range is sufficient.  */
4679a45ae5f8SJohn Marino 	    else if (target_watchpoint_addr_within_range (&current_target,
46805796c8dcSSimon Schubert 							 addr, loc->address,
46815796c8dcSSimon Schubert 							 loc->length))
46825796c8dcSSimon Schubert 	      {
4683a45ae5f8SJohn Marino 		w->watchpoint_triggered = watch_triggered_yes;
46845796c8dcSSimon Schubert 		break;
46855796c8dcSSimon Schubert 	      }
46865796c8dcSSimon Schubert 	  }
4687a45ae5f8SJohn Marino       }
46885796c8dcSSimon Schubert 
46895796c8dcSSimon Schubert   return 1;
46905796c8dcSSimon Schubert }
46915796c8dcSSimon Schubert 
46925796c8dcSSimon Schubert /* Possible return values for watchpoint_check (this can't be an enum
46935796c8dcSSimon Schubert    because of check_errors).  */
46945796c8dcSSimon Schubert /* The watchpoint has been deleted.  */
46955796c8dcSSimon Schubert #define WP_DELETED 1
46965796c8dcSSimon Schubert /* The value has changed.  */
46975796c8dcSSimon Schubert #define WP_VALUE_CHANGED 2
46985796c8dcSSimon Schubert /* The value has not changed.  */
46995796c8dcSSimon Schubert #define WP_VALUE_NOT_CHANGED 3
4700cf7f2e2dSJohn Marino /* Ignore this watchpoint, no matter if the value changed or not.  */
4701cf7f2e2dSJohn Marino #define WP_IGNORE 4
47025796c8dcSSimon Schubert 
47035796c8dcSSimon Schubert #define BP_TEMPFLAG 1
47045796c8dcSSimon Schubert #define BP_HARDWAREFLAG 2
47055796c8dcSSimon Schubert 
4706c50c785cSJohn Marino /* Evaluate watchpoint condition expression and check if its value
4707c50c785cSJohn Marino    changed.
4708cf7f2e2dSJohn Marino 
4709cf7f2e2dSJohn Marino    P should be a pointer to struct bpstat, but is defined as a void *
4710cf7f2e2dSJohn Marino    in order for this function to be usable with catch_errors.  */
47115796c8dcSSimon Schubert 
47125796c8dcSSimon Schubert static int
watchpoint_check(void * p)47135796c8dcSSimon Schubert watchpoint_check (void *p)
47145796c8dcSSimon Schubert {
47155796c8dcSSimon Schubert   bpstat bs = (bpstat) p;
4716a45ae5f8SJohn Marino   struct watchpoint *b;
47175796c8dcSSimon Schubert   struct frame_info *fr;
47185796c8dcSSimon Schubert   int within_current_scope;
47195796c8dcSSimon Schubert 
4720c50c785cSJohn Marino   /* BS is built from an existing struct breakpoint.  */
4721cf7f2e2dSJohn Marino   gdb_assert (bs->breakpoint_at != NULL);
4722a45ae5f8SJohn Marino   b = (struct watchpoint *) bs->breakpoint_at;
47235796c8dcSSimon Schubert 
4724cf7f2e2dSJohn Marino   /* If this is a local watchpoint, we only want to check if the
4725cf7f2e2dSJohn Marino      watchpoint frame is in scope if the current thread is the thread
4726cf7f2e2dSJohn Marino      that was used to create the watchpoint.  */
4727cf7f2e2dSJohn Marino   if (!watchpoint_in_thread_scope (b))
4728cf7f2e2dSJohn Marino     return WP_IGNORE;
4729cf7f2e2dSJohn Marino 
47305796c8dcSSimon Schubert   if (b->exp_valid_block == NULL)
47315796c8dcSSimon Schubert     within_current_scope = 1;
47325796c8dcSSimon Schubert   else
47335796c8dcSSimon Schubert     {
47345796c8dcSSimon Schubert       struct frame_info *frame = get_current_frame ();
47355796c8dcSSimon Schubert       struct gdbarch *frame_arch = get_frame_arch (frame);
47365796c8dcSSimon Schubert       CORE_ADDR frame_pc = get_frame_pc (frame);
47375796c8dcSSimon Schubert 
4738c50c785cSJohn Marino       /* in_function_epilogue_p() returns a non-zero value if we're
4739c50c785cSJohn Marino 	 still in the function but the stack frame has already been
4740c50c785cSJohn Marino 	 invalidated.  Since we can't rely on the values of local
4741c50c785cSJohn Marino 	 variables after the stack has been destroyed, we are treating
4742c50c785cSJohn Marino 	 the watchpoint in that state as `not changed' without further
4743c50c785cSJohn Marino 	 checking.  Don't mark watchpoints as changed if the current
4744c50c785cSJohn Marino 	 frame is in an epilogue - even if they are in some other
4745c50c785cSJohn Marino 	 frame, our view of the stack is likely to be wrong and
4746c50c785cSJohn Marino 	 frame_find_by_id could error out.  */
4747cf7f2e2dSJohn Marino       if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
4748cf7f2e2dSJohn Marino 	return WP_IGNORE;
4749cf7f2e2dSJohn Marino 
47505796c8dcSSimon Schubert       fr = frame_find_by_id (b->watchpoint_frame);
47515796c8dcSSimon Schubert       within_current_scope = (fr != NULL);
47525796c8dcSSimon Schubert 
47535796c8dcSSimon Schubert       /* If we've gotten confused in the unwinder, we might have
47545796c8dcSSimon Schubert 	 returned a frame that can't describe this variable.  */
47555796c8dcSSimon Schubert       if (within_current_scope)
47565796c8dcSSimon Schubert 	{
47575796c8dcSSimon Schubert 	  struct symbol *function;
47585796c8dcSSimon Schubert 
47595796c8dcSSimon Schubert 	  function = get_frame_function (fr);
47605796c8dcSSimon Schubert 	  if (function == NULL
47615796c8dcSSimon Schubert 	      || !contained_in (b->exp_valid_block,
47625796c8dcSSimon Schubert 				SYMBOL_BLOCK_VALUE (function)))
47635796c8dcSSimon Schubert 	    within_current_scope = 0;
47645796c8dcSSimon Schubert 	}
47655796c8dcSSimon Schubert 
47665796c8dcSSimon Schubert       if (within_current_scope)
47675796c8dcSSimon Schubert 	/* If we end up stopping, the current frame will get selected
47685796c8dcSSimon Schubert 	   in normal_stop.  So this call to select_frame won't affect
47695796c8dcSSimon Schubert 	   the user.  */
47705796c8dcSSimon Schubert 	select_frame (fr);
47715796c8dcSSimon Schubert     }
47725796c8dcSSimon Schubert 
47735796c8dcSSimon Schubert   if (within_current_scope)
47745796c8dcSSimon Schubert     {
4775c50c785cSJohn Marino       /* We use value_{,free_to_}mark because it could be a *long*
4776c50c785cSJohn Marino          time before we return to the command level and call
4777c50c785cSJohn Marino          free_all_values.  We can't call free_all_values because we
4778c50c785cSJohn Marino          might be in the middle of evaluating a function call.  */
47795796c8dcSSimon Schubert 
4780cf7f2e2dSJohn Marino       int pc = 0;
4781a45ae5f8SJohn Marino       struct value *mark;
47825796c8dcSSimon Schubert       struct value *new_val;
47835796c8dcSSimon Schubert 
4784a45ae5f8SJohn Marino       if (is_masked_watchpoint (&b->base))
4785a45ae5f8SJohn Marino 	/* Since we don't know the exact trigger address (from
4786a45ae5f8SJohn Marino 	   stopped_data_address), just tell the user we've triggered
4787a45ae5f8SJohn Marino 	   a mask watchpoint.  */
4788a45ae5f8SJohn Marino 	return WP_VALUE_CHANGED;
4789a45ae5f8SJohn Marino 
4790a45ae5f8SJohn Marino       mark = value_mark ();
4791cf7f2e2dSJohn Marino       fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
4792cf7f2e2dSJohn Marino 
4793c50c785cSJohn Marino       /* We use value_equal_contents instead of value_equal because
4794c50c785cSJohn Marino 	 the latter coerces an array to a pointer, thus comparing just
4795c50c785cSJohn Marino 	 the address of the array instead of its contents.  This is
4796c50c785cSJohn Marino 	 not what we want.  */
47975796c8dcSSimon Schubert       if ((b->val != NULL) != (new_val != NULL)
4798cf7f2e2dSJohn Marino 	  || (b->val != NULL && !value_equal_contents (b->val, new_val)))
47995796c8dcSSimon Schubert 	{
48005796c8dcSSimon Schubert 	  if (new_val != NULL)
48015796c8dcSSimon Schubert 	    {
48025796c8dcSSimon Schubert 	      release_value (new_val);
48035796c8dcSSimon Schubert 	      value_free_to_mark (mark);
48045796c8dcSSimon Schubert 	    }
48055796c8dcSSimon Schubert 	  bs->old_val = b->val;
48065796c8dcSSimon Schubert 	  b->val = new_val;
48075796c8dcSSimon Schubert 	  b->val_valid = 1;
48085796c8dcSSimon Schubert 	  return WP_VALUE_CHANGED;
48095796c8dcSSimon Schubert 	}
48105796c8dcSSimon Schubert       else
48115796c8dcSSimon Schubert 	{
4812cf7f2e2dSJohn Marino 	  /* Nothing changed.  */
48135796c8dcSSimon Schubert 	  value_free_to_mark (mark);
48145796c8dcSSimon Schubert 	  return WP_VALUE_NOT_CHANGED;
48155796c8dcSSimon Schubert 	}
48165796c8dcSSimon Schubert     }
48175796c8dcSSimon Schubert   else
48185796c8dcSSimon Schubert     {
4819a45ae5f8SJohn Marino       struct ui_out *uiout = current_uiout;
4820a45ae5f8SJohn Marino 
48215796c8dcSSimon Schubert       /* This seems like the only logical thing to do because
48225796c8dcSSimon Schubert          if we temporarily ignored the watchpoint, then when
48235796c8dcSSimon Schubert          we reenter the block in which it is valid it contains
48245796c8dcSSimon Schubert          garbage (in the case of a function, it may have two
48255796c8dcSSimon Schubert          garbage values, one before and one after the prologue).
48265796c8dcSSimon Schubert          So we can't even detect the first assignment to it and
48275796c8dcSSimon Schubert          watch after that (since the garbage may or may not equal
48285796c8dcSSimon Schubert          the first value assigned).  */
4829a45ae5f8SJohn Marino       /* We print all the stop information in
4830a45ae5f8SJohn Marino 	 breakpoint_ops->print_it, but in this case, by the time we
4831a45ae5f8SJohn Marino 	 call breakpoint_ops->print_it this bp will be deleted
4832a45ae5f8SJohn Marino 	 already.  So we have no choice but print the information
4833a45ae5f8SJohn Marino 	 here.  */
48345796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
48355796c8dcSSimon Schubert 	ui_out_field_string
48365796c8dcSSimon Schubert 	  (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
48375796c8dcSSimon Schubert       ui_out_text (uiout, "\nWatchpoint ");
4838a45ae5f8SJohn Marino       ui_out_field_int (uiout, "wpnum", b->base.number);
4839c50c785cSJohn Marino       ui_out_text (uiout,
4840c50c785cSJohn Marino 		   " deleted because the program has left the block in\n\
48415796c8dcSSimon Schubert which its expression is valid.\n");
48425796c8dcSSimon Schubert 
4843a45ae5f8SJohn Marino       /* Make sure the watchpoint's commands aren't executed.  */
4844a45ae5f8SJohn Marino       decref_counted_command_line (&b->base.commands);
4845c50c785cSJohn Marino       watchpoint_del_at_next_stop (b);
48465796c8dcSSimon Schubert 
48475796c8dcSSimon Schubert       return WP_DELETED;
48485796c8dcSSimon Schubert     }
48495796c8dcSSimon Schubert }
48505796c8dcSSimon Schubert 
48515796c8dcSSimon Schubert /* Return true if it looks like target has stopped due to hitting
4852a45ae5f8SJohn Marino    breakpoint location BL.  This function does not check if we should
4853a45ae5f8SJohn Marino    stop, only if BL explains the stop.  */
4854a45ae5f8SJohn Marino 
48555796c8dcSSimon Schubert static int
bpstat_check_location(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)4856cf7f2e2dSJohn Marino bpstat_check_location (const struct bp_location *bl,
4857*ef5ccd6cSJohn Marino 		       struct address_space *aspace, CORE_ADDR bp_addr,
4858*ef5ccd6cSJohn Marino 		       const struct target_waitstatus *ws)
48595796c8dcSSimon Schubert {
48605796c8dcSSimon Schubert   struct breakpoint *b = bl->owner;
48615796c8dcSSimon Schubert 
4862a45ae5f8SJohn Marino   /* BL is from an existing breakpoint.  */
4863cf7f2e2dSJohn Marino   gdb_assert (b != NULL);
4864cf7f2e2dSJohn Marino 
4865*ef5ccd6cSJohn Marino   return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
48665796c8dcSSimon Schubert }
48675796c8dcSSimon Schubert 
4868a45ae5f8SJohn Marino /* Determine if the watched values have actually changed, and we
4869a45ae5f8SJohn Marino    should stop.  If not, set BS->stop to 0.  */
48705796c8dcSSimon Schubert 
48715796c8dcSSimon Schubert static void
bpstat_check_watchpoint(bpstat bs)48725796c8dcSSimon Schubert bpstat_check_watchpoint (bpstat bs)
48735796c8dcSSimon Schubert {
4874cf7f2e2dSJohn Marino   const struct bp_location *bl;
4875a45ae5f8SJohn Marino   struct watchpoint *b;
48765796c8dcSSimon Schubert 
4877cf7f2e2dSJohn Marino   /* BS is built for existing struct breakpoint.  */
4878c50c785cSJohn Marino   bl = bs->bp_location_at;
4879cf7f2e2dSJohn Marino   gdb_assert (bl != NULL);
4880a45ae5f8SJohn Marino   b = (struct watchpoint *) bs->breakpoint_at;
4881cf7f2e2dSJohn Marino   gdb_assert (b != NULL);
4882cf7f2e2dSJohn Marino 
48835796c8dcSSimon Schubert     {
48845796c8dcSSimon Schubert       int must_check_value = 0;
48855796c8dcSSimon Schubert 
4886a45ae5f8SJohn Marino       if (b->base.type == bp_watchpoint)
48875796c8dcSSimon Schubert 	/* For a software watchpoint, we must always check the
48885796c8dcSSimon Schubert 	   watched value.  */
48895796c8dcSSimon Schubert 	must_check_value = 1;
48905796c8dcSSimon Schubert       else if (b->watchpoint_triggered == watch_triggered_yes)
48915796c8dcSSimon Schubert 	/* We have a hardware watchpoint (read, write, or access)
48925796c8dcSSimon Schubert 	   and the target earlier reported an address watched by
48935796c8dcSSimon Schubert 	   this watchpoint.  */
48945796c8dcSSimon Schubert 	must_check_value = 1;
48955796c8dcSSimon Schubert       else if (b->watchpoint_triggered == watch_triggered_unknown
4896a45ae5f8SJohn Marino 	       && b->base.type == bp_hardware_watchpoint)
48975796c8dcSSimon Schubert 	/* We were stopped by a hardware watchpoint, but the target could
48985796c8dcSSimon Schubert 	   not report the data address.  We must check the watchpoint's
48995796c8dcSSimon Schubert 	   value.  Access and read watchpoints are out of luck; without
49005796c8dcSSimon Schubert 	   a data address, we can't figure it out.  */
49015796c8dcSSimon Schubert 	must_check_value = 1;
49025796c8dcSSimon Schubert 
49035796c8dcSSimon Schubert       if (must_check_value)
49045796c8dcSSimon Schubert 	{
4905c50c785cSJohn Marino 	  char *message
4906c50c785cSJohn Marino 	    = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4907a45ae5f8SJohn Marino 			  b->base.number);
49085796c8dcSSimon Schubert 	  struct cleanup *cleanups = make_cleanup (xfree, message);
49095796c8dcSSimon Schubert 	  int e = catch_errors (watchpoint_check, bs, message,
49105796c8dcSSimon Schubert 				RETURN_MASK_ALL);
49115796c8dcSSimon Schubert 	  do_cleanups (cleanups);
49125796c8dcSSimon Schubert 	  switch (e)
49135796c8dcSSimon Schubert 	    {
49145796c8dcSSimon Schubert 	    case WP_DELETED:
49155796c8dcSSimon Schubert 	      /* We've already printed what needs to be printed.  */
49165796c8dcSSimon Schubert 	      bs->print_it = print_it_done;
49175796c8dcSSimon Schubert 	      /* Stop.  */
49185796c8dcSSimon Schubert 	      break;
4919cf7f2e2dSJohn Marino 	    case WP_IGNORE:
4920cf7f2e2dSJohn Marino 	      bs->print_it = print_it_noop;
4921cf7f2e2dSJohn Marino 	      bs->stop = 0;
4922cf7f2e2dSJohn Marino 	      break;
49235796c8dcSSimon Schubert 	    case WP_VALUE_CHANGED:
4924a45ae5f8SJohn Marino 	      if (b->base.type == bp_read_watchpoint)
49255796c8dcSSimon Schubert 		{
4926cf7f2e2dSJohn Marino 		  /* There are two cases to consider here:
4927cf7f2e2dSJohn Marino 
4928c50c785cSJohn Marino 		     1. We're watching the triggered memory for reads.
4929cf7f2e2dSJohn Marino 		     In that case, trust the target, and always report
4930cf7f2e2dSJohn Marino 		     the watchpoint hit to the user.  Even though
4931cf7f2e2dSJohn Marino 		     reads don't cause value changes, the value may
4932cf7f2e2dSJohn Marino 		     have changed since the last time it was read, and
4933cf7f2e2dSJohn Marino 		     since we're not trapping writes, we will not see
4934cf7f2e2dSJohn Marino 		     those, and as such we should ignore our notion of
4935cf7f2e2dSJohn Marino 		     old value.
4936cf7f2e2dSJohn Marino 
4937c50c785cSJohn Marino 		     2. We're watching the triggered memory for both
4938cf7f2e2dSJohn Marino 		     reads and writes.  There are two ways this may
4939cf7f2e2dSJohn Marino 		     happen:
4940cf7f2e2dSJohn Marino 
4941c50c785cSJohn Marino 		     2.1. This is a target that can't break on data
4942cf7f2e2dSJohn Marino 		     reads only, but can break on accesses (reads or
4943cf7f2e2dSJohn Marino 		     writes), such as e.g., x86.  We detect this case
4944cf7f2e2dSJohn Marino 		     at the time we try to insert read watchpoints.
4945cf7f2e2dSJohn Marino 
4946c50c785cSJohn Marino 		     2.2. Otherwise, the target supports read
4947cf7f2e2dSJohn Marino 		     watchpoints, but, the user set an access or write
4948cf7f2e2dSJohn Marino 		     watchpoint watching the same memory as this read
4949cf7f2e2dSJohn Marino 		     watchpoint.
4950cf7f2e2dSJohn Marino 
4951cf7f2e2dSJohn Marino 		     If we're watching memory writes as well as reads,
4952cf7f2e2dSJohn Marino 		     ignore watchpoint hits when we find that the
4953cf7f2e2dSJohn Marino 		     value hasn't changed, as reads don't cause
4954cf7f2e2dSJohn Marino 		     changes.  This still gives false positives when
4955cf7f2e2dSJohn Marino 		     the program writes the same value to memory as
4956cf7f2e2dSJohn Marino 		     what there was already in memory (we will confuse
4957cf7f2e2dSJohn Marino 		     it for a read), but it's much better than
4958cf7f2e2dSJohn Marino 		     nothing.  */
4959cf7f2e2dSJohn Marino 
4960cf7f2e2dSJohn Marino 		  int other_write_watchpoint = 0;
4961cf7f2e2dSJohn Marino 
4962cf7f2e2dSJohn Marino 		  if (bl->watchpoint_type == hw_read)
4963cf7f2e2dSJohn Marino 		    {
4964cf7f2e2dSJohn Marino 		      struct breakpoint *other_b;
4965cf7f2e2dSJohn Marino 
4966cf7f2e2dSJohn Marino 		      ALL_BREAKPOINTS (other_b)
4967a45ae5f8SJohn Marino 			if (other_b->type == bp_hardware_watchpoint
4968cf7f2e2dSJohn Marino 			    || other_b->type == bp_access_watchpoint)
4969a45ae5f8SJohn Marino 			  {
4970a45ae5f8SJohn Marino 			    struct watchpoint *other_w =
4971a45ae5f8SJohn Marino 			      (struct watchpoint *) other_b;
4972a45ae5f8SJohn Marino 
4973a45ae5f8SJohn Marino 			    if (other_w->watchpoint_triggered
4974a45ae5f8SJohn Marino 				== watch_triggered_yes)
4975cf7f2e2dSJohn Marino 			      {
4976cf7f2e2dSJohn Marino 				other_write_watchpoint = 1;
4977cf7f2e2dSJohn Marino 				break;
4978cf7f2e2dSJohn Marino 			      }
4979cf7f2e2dSJohn Marino 			  }
4980a45ae5f8SJohn Marino 		    }
4981cf7f2e2dSJohn Marino 
4982cf7f2e2dSJohn Marino 		  if (other_write_watchpoint
4983cf7f2e2dSJohn Marino 		      || bl->watchpoint_type == hw_access)
4984cf7f2e2dSJohn Marino 		    {
4985cf7f2e2dSJohn Marino 		      /* We're watching the same memory for writes,
4986cf7f2e2dSJohn Marino 			 and the value changed since the last time we
4987cf7f2e2dSJohn Marino 			 updated it, so this trap must be for a write.
4988cf7f2e2dSJohn Marino 			 Ignore it.  */
49895796c8dcSSimon Schubert 		      bs->print_it = print_it_noop;
49905796c8dcSSimon Schubert 		      bs->stop = 0;
49915796c8dcSSimon Schubert 		    }
4992cf7f2e2dSJohn Marino 		}
49935796c8dcSSimon Schubert 	      break;
49945796c8dcSSimon Schubert 	    case WP_VALUE_NOT_CHANGED:
4995a45ae5f8SJohn Marino 	      if (b->base.type == bp_hardware_watchpoint
4996a45ae5f8SJohn Marino 		  || b->base.type == bp_watchpoint)
49975796c8dcSSimon Schubert 		{
49985796c8dcSSimon Schubert 		  /* Don't stop: write watchpoints shouldn't fire if
49995796c8dcSSimon Schubert 		     the value hasn't changed.  */
50005796c8dcSSimon Schubert 		  bs->print_it = print_it_noop;
50015796c8dcSSimon Schubert 		  bs->stop = 0;
50025796c8dcSSimon Schubert 		}
50035796c8dcSSimon Schubert 	      /* Stop.  */
50045796c8dcSSimon Schubert 	      break;
50055796c8dcSSimon Schubert 	    default:
50065796c8dcSSimon Schubert 	      /* Can't happen.  */
50075796c8dcSSimon Schubert 	    case 0:
50085796c8dcSSimon Schubert 	      /* Error from catch_errors.  */
5009a45ae5f8SJohn Marino 	      printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
5010c50c785cSJohn Marino 	      watchpoint_del_at_next_stop (b);
50115796c8dcSSimon Schubert 	      /* We've already printed what needs to be printed.  */
50125796c8dcSSimon Schubert 	      bs->print_it = print_it_done;
50135796c8dcSSimon Schubert 	      break;
50145796c8dcSSimon Schubert 	    }
50155796c8dcSSimon Schubert 	}
50165796c8dcSSimon Schubert       else	/* must_check_value == 0 */
50175796c8dcSSimon Schubert 	{
50185796c8dcSSimon Schubert 	  /* This is a case where some watchpoint(s) triggered, but
50195796c8dcSSimon Schubert 	     not at the address of this watchpoint, or else no
50205796c8dcSSimon Schubert 	     watchpoint triggered after all.  So don't print
50215796c8dcSSimon Schubert 	     anything for this watchpoint.  */
50225796c8dcSSimon Schubert 	  bs->print_it = print_it_noop;
50235796c8dcSSimon Schubert 	  bs->stop = 0;
50245796c8dcSSimon Schubert 	}
50255796c8dcSSimon Schubert     }
50265796c8dcSSimon Schubert }
50275796c8dcSSimon Schubert 
50285796c8dcSSimon Schubert 
50295796c8dcSSimon Schubert /* Check conditions (condition proper, frame, thread and ignore count)
50305796c8dcSSimon Schubert    of breakpoint referred to by BS.  If we should not stop for this
50315796c8dcSSimon Schubert    breakpoint, set BS->stop to 0.  */
5032c50c785cSJohn Marino 
50335796c8dcSSimon Schubert static void
bpstat_check_breakpoint_conditions(bpstat bs,ptid_t ptid)50345796c8dcSSimon Schubert bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
50355796c8dcSSimon Schubert {
50365796c8dcSSimon Schubert   int thread_id = pid_to_thread_id (ptid);
5037cf7f2e2dSJohn Marino   const struct bp_location *bl;
5038cf7f2e2dSJohn Marino   struct breakpoint *b;
5039cf7f2e2dSJohn Marino 
5040cf7f2e2dSJohn Marino   /* BS is built for existing struct breakpoint.  */
5041c50c785cSJohn Marino   bl = bs->bp_location_at;
5042cf7f2e2dSJohn Marino   gdb_assert (bl != NULL);
5043c50c785cSJohn Marino   b = bs->breakpoint_at;
5044cf7f2e2dSJohn Marino   gdb_assert (b != NULL);
50455796c8dcSSimon Schubert 
5046*ef5ccd6cSJohn Marino   /* Even if the target evaluated the condition on its end and notified GDB, we
5047*ef5ccd6cSJohn Marino      need to do so again since GDB does not know if we stopped due to a
5048*ef5ccd6cSJohn Marino      breakpoint or a single step breakpoint.  */
5049*ef5ccd6cSJohn Marino 
50505796c8dcSSimon Schubert   if (frame_id_p (b->frame_id)
50515796c8dcSSimon Schubert       && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
50525796c8dcSSimon Schubert     bs->stop = 0;
50535796c8dcSSimon Schubert   else if (bs->stop)
50545796c8dcSSimon Schubert     {
50555796c8dcSSimon Schubert       int value_is_zero = 0;
5056cf7f2e2dSJohn Marino       struct expression *cond;
50575796c8dcSSimon Schubert 
5058c50c785cSJohn Marino       /* Evaluate Python breakpoints that have a "stop"
5059c50c785cSJohn Marino 	 method implemented.  */
5060c50c785cSJohn Marino       if (b->py_bp_object)
5061c50c785cSJohn Marino 	bs->stop = gdbpy_should_stop (b->py_bp_object);
50625796c8dcSSimon Schubert 
5063cf7f2e2dSJohn Marino       if (is_watchpoint (b))
5064a45ae5f8SJohn Marino 	{
5065a45ae5f8SJohn Marino 	  struct watchpoint *w = (struct watchpoint *) b;
5066a45ae5f8SJohn Marino 
5067a45ae5f8SJohn Marino 	  cond = w->cond_exp;
5068a45ae5f8SJohn Marino 	}
5069cf7f2e2dSJohn Marino       else
5070cf7f2e2dSJohn Marino 	cond = bl->cond;
5071cf7f2e2dSJohn Marino 
5072c50c785cSJohn Marino       if (cond && b->disposition != disp_del_at_next_stop)
50735796c8dcSSimon Schubert 	{
5074cf7f2e2dSJohn Marino 	  int within_current_scope = 1;
5075a45ae5f8SJohn Marino 	  struct watchpoint * w;
5076cf7f2e2dSJohn Marino 
50775796c8dcSSimon Schubert 	  /* We use value_mark and value_free_to_mark because it could
50785796c8dcSSimon Schubert 	     be a long time before we return to the command level and
50795796c8dcSSimon Schubert 	     call free_all_values.  We can't call free_all_values
50805796c8dcSSimon Schubert 	     because we might be in the middle of evaluating a
50815796c8dcSSimon Schubert 	     function call.  */
50825796c8dcSSimon Schubert 	  struct value *mark = value_mark ();
50835796c8dcSSimon Schubert 
5084a45ae5f8SJohn Marino 	  if (is_watchpoint (b))
5085a45ae5f8SJohn Marino 	    w = (struct watchpoint *) b;
5086a45ae5f8SJohn Marino 	  else
5087a45ae5f8SJohn Marino 	    w = NULL;
5088a45ae5f8SJohn Marino 
50895796c8dcSSimon Schubert 	  /* Need to select the frame, with all that implies so that
50905796c8dcSSimon Schubert 	     the conditions will have the right context.  Because we
50915796c8dcSSimon Schubert 	     use the frame, we will not see an inlined function's
50925796c8dcSSimon Schubert 	     variables when we arrive at a breakpoint at the start
50935796c8dcSSimon Schubert 	     of the inlined function; the current frame will be the
50945796c8dcSSimon Schubert 	     call site.  */
5095a45ae5f8SJohn Marino 	  if (w == NULL || w->cond_exp_valid_block == NULL)
50965796c8dcSSimon Schubert 	    select_frame (get_current_frame ());
5097cf7f2e2dSJohn Marino 	  else
5098cf7f2e2dSJohn Marino 	    {
5099cf7f2e2dSJohn Marino 	      struct frame_info *frame;
5100cf7f2e2dSJohn Marino 
5101cf7f2e2dSJohn Marino 	      /* For local watchpoint expressions, which particular
5102cf7f2e2dSJohn Marino 		 instance of a local is being watched matters, so we
5103cf7f2e2dSJohn Marino 		 keep track of the frame to evaluate the expression
5104cf7f2e2dSJohn Marino 		 in.  To evaluate the condition however, it doesn't
5105cf7f2e2dSJohn Marino 		 really matter which instantiation of the function
5106cf7f2e2dSJohn Marino 		 where the condition makes sense triggers the
5107cf7f2e2dSJohn Marino 		 watchpoint.  This allows an expression like "watch
5108cf7f2e2dSJohn Marino 		 global if q > 10" set in `func', catch writes to
5109cf7f2e2dSJohn Marino 		 global on all threads that call `func', or catch
5110cf7f2e2dSJohn Marino 		 writes on all recursive calls of `func' by a single
5111cf7f2e2dSJohn Marino 		 thread.  We simply always evaluate the condition in
5112cf7f2e2dSJohn Marino 		 the innermost frame that's executing where it makes
5113cf7f2e2dSJohn Marino 		 sense to evaluate the condition.  It seems
5114cf7f2e2dSJohn Marino 		 intuitive.  */
5115a45ae5f8SJohn Marino 	      frame = block_innermost_frame (w->cond_exp_valid_block);
5116cf7f2e2dSJohn Marino 	      if (frame != NULL)
5117cf7f2e2dSJohn Marino 		select_frame (frame);
5118cf7f2e2dSJohn Marino 	      else
5119cf7f2e2dSJohn Marino 		within_current_scope = 0;
5120cf7f2e2dSJohn Marino 	    }
5121cf7f2e2dSJohn Marino 	  if (within_current_scope)
51225796c8dcSSimon Schubert 	    value_is_zero
5123cf7f2e2dSJohn Marino 	      = catch_errors (breakpoint_cond_eval, cond,
51245796c8dcSSimon Schubert 			      "Error in testing breakpoint condition:\n",
51255796c8dcSSimon Schubert 			      RETURN_MASK_ALL);
5126cf7f2e2dSJohn Marino 	  else
5127cf7f2e2dSJohn Marino 	    {
5128cf7f2e2dSJohn Marino 	      warning (_("Watchpoint condition cannot be tested "
5129cf7f2e2dSJohn Marino 			 "in the current scope"));
5130cf7f2e2dSJohn Marino 	      /* If we failed to set the right context for this
5131cf7f2e2dSJohn Marino 		 watchpoint, unconditionally report it.  */
5132cf7f2e2dSJohn Marino 	      value_is_zero = 0;
5133cf7f2e2dSJohn Marino 	    }
5134c50c785cSJohn Marino 	  /* FIXME-someday, should give breakpoint #.  */
51355796c8dcSSimon Schubert 	  value_free_to_mark (mark);
51365796c8dcSSimon Schubert 	}
5137cf7f2e2dSJohn Marino 
5138cf7f2e2dSJohn Marino       if (cond && value_is_zero)
51395796c8dcSSimon Schubert 	{
51405796c8dcSSimon Schubert 	  bs->stop = 0;
51415796c8dcSSimon Schubert 	}
51425796c8dcSSimon Schubert       else if (b->thread != -1 && b->thread != thread_id)
51435796c8dcSSimon Schubert 	{
51445796c8dcSSimon Schubert 	  bs->stop = 0;
51455796c8dcSSimon Schubert 	}
51465796c8dcSSimon Schubert       else if (b->ignore_count > 0)
51475796c8dcSSimon Schubert 	{
51485796c8dcSSimon Schubert 	  b->ignore_count--;
51495796c8dcSSimon Schubert 	  bs->stop = 0;
5150c50c785cSJohn Marino 	  /* Increase the hit count even though we don't stop.  */
51515796c8dcSSimon Schubert 	  ++(b->hit_count);
5152a45ae5f8SJohn Marino 	  observer_notify_breakpoint_modified (b);
51535796c8dcSSimon Schubert 	}
51545796c8dcSSimon Schubert     }
51555796c8dcSSimon Schubert }
51565796c8dcSSimon Schubert 
51575796c8dcSSimon Schubert 
51585796c8dcSSimon Schubert /* Get a bpstat associated with having just stopped at address
51595796c8dcSSimon Schubert    BP_ADDR in thread PTID.
51605796c8dcSSimon Schubert 
51615796c8dcSSimon Schubert    Determine whether we stopped at a breakpoint, etc, or whether we
5162c50c785cSJohn Marino    don't understand this stop.  Result is a chain of bpstat's such
5163c50c785cSJohn Marino    that:
51645796c8dcSSimon Schubert 
51655796c8dcSSimon Schubert    if we don't understand the stop, the result is a null pointer.
51665796c8dcSSimon Schubert 
51675796c8dcSSimon Schubert    if we understand why we stopped, the result is not null.
51685796c8dcSSimon Schubert 
51695796c8dcSSimon Schubert    Each element of the chain refers to a particular breakpoint or
51705796c8dcSSimon Schubert    watchpoint at which we have stopped.  (We may have stopped for
51715796c8dcSSimon Schubert    several reasons concurrently.)
51725796c8dcSSimon Schubert 
51735796c8dcSSimon Schubert    Each element of the chain has valid next, breakpoint_at,
51745796c8dcSSimon Schubert    commands, FIXME??? fields.  */
51755796c8dcSSimon Schubert 
51765796c8dcSSimon Schubert bpstat
bpstat_stop_status(struct address_space * aspace,CORE_ADDR bp_addr,ptid_t ptid,const struct target_waitstatus * ws)5177cf7f2e2dSJohn Marino bpstat_stop_status (struct address_space *aspace,
5178*ef5ccd6cSJohn Marino 		    CORE_ADDR bp_addr, ptid_t ptid,
5179*ef5ccd6cSJohn Marino 		    const struct target_waitstatus *ws)
51805796c8dcSSimon Schubert {
51815796c8dcSSimon Schubert   struct breakpoint *b = NULL;
5182cf7f2e2dSJohn Marino   struct bp_location *bl;
51835796c8dcSSimon Schubert   struct bp_location *loc;
5184c50c785cSJohn Marino   /* First item of allocated bpstat's.  */
5185c50c785cSJohn Marino   bpstat bs_head = NULL, *bs_link = &bs_head;
51865796c8dcSSimon Schubert   /* Pointer to the last thing in the chain currently.  */
5187c50c785cSJohn Marino   bpstat bs;
51885796c8dcSSimon Schubert   int ix;
51895796c8dcSSimon Schubert   int need_remove_insert;
5190c50c785cSJohn Marino   int removed_any;
51915796c8dcSSimon Schubert 
5192c50c785cSJohn Marino   /* First, build the bpstat chain with locations that explain a
5193c50c785cSJohn Marino      target stop, while being careful to not set the target running,
5194c50c785cSJohn Marino      as that may invalidate locations (in particular watchpoint
5195c50c785cSJohn Marino      locations are recreated).  Resuming will happen here with
5196c50c785cSJohn Marino      breakpoint conditions or watchpoint expressions that include
5197c50c785cSJohn Marino      inferior function calls.  */
5198cf7f2e2dSJohn Marino 
5199cf7f2e2dSJohn Marino   ALL_BREAKPOINTS (b)
52005796c8dcSSimon Schubert     {
52015796c8dcSSimon Schubert       if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
52025796c8dcSSimon Schubert 	continue;
52035796c8dcSSimon Schubert 
5204cf7f2e2dSJohn Marino       for (bl = b->loc; bl != NULL; bl = bl->next)
5205cf7f2e2dSJohn Marino 	{
5206c50c785cSJohn Marino 	  /* For hardware watchpoints, we look only at the first
5207c50c785cSJohn Marino 	     location.  The watchpoint_check function will work on the
5208c50c785cSJohn Marino 	     entire expression, not the individual locations.  For
5209c50c785cSJohn Marino 	     read watchpoints, the watchpoints_triggered function has
5210c50c785cSJohn Marino 	     checked all locations already.  */
52115796c8dcSSimon Schubert 	  if (b->type == bp_hardware_watchpoint && bl != b->loc)
5212cf7f2e2dSJohn Marino 	    break;
5213cf7f2e2dSJohn Marino 
5214*ef5ccd6cSJohn Marino 	  if (!bl->enabled || bl->shlib_disabled)
52155796c8dcSSimon Schubert 	    continue;
52165796c8dcSSimon Schubert 
5217*ef5ccd6cSJohn Marino 	  if (!bpstat_check_location (bl, aspace, bp_addr, ws))
52185796c8dcSSimon Schubert 	    continue;
52195796c8dcSSimon Schubert 
5220c50c785cSJohn Marino 	  /* Come here if it's a watchpoint, or if the break address
5221c50c785cSJohn Marino 	     matches.  */
52225796c8dcSSimon Schubert 
5223c50c785cSJohn Marino 	  bs = bpstat_alloc (bl, &bs_link);	/* Alloc a bpstat to
5224c50c785cSJohn Marino 						   explain stop.  */
52255796c8dcSSimon Schubert 
5226c50c785cSJohn Marino 	  /* Assume we stop.  Should we find a watchpoint that is not
5227c50c785cSJohn Marino 	     actually triggered, or if the condition of the breakpoint
5228c50c785cSJohn Marino 	     evaluates as false, we'll reset 'stop' to 0.  */
52295796c8dcSSimon Schubert 	  bs->stop = 1;
52305796c8dcSSimon Schubert 	  bs->print = 1;
52315796c8dcSSimon Schubert 
5232c50c785cSJohn Marino 	  /* If this is a scope breakpoint, mark the associated
5233c50c785cSJohn Marino 	     watchpoint as triggered so that we will handle the
5234c50c785cSJohn Marino 	     out-of-scope event.  We'll get to the watchpoint next
5235c50c785cSJohn Marino 	     iteration.  */
5236c50c785cSJohn Marino 	  if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
5237a45ae5f8SJohn Marino 	    {
5238a45ae5f8SJohn Marino 	      struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
5239a45ae5f8SJohn Marino 
5240a45ae5f8SJohn Marino 	      w->watchpoint_triggered = watch_triggered_yes;
5241a45ae5f8SJohn Marino 	    }
5242c50c785cSJohn Marino 	}
5243c50c785cSJohn Marino     }
5244c50c785cSJohn Marino 
5245c50c785cSJohn Marino   for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
5246c50c785cSJohn Marino     {
5247c50c785cSJohn Marino       if (breakpoint_location_address_match (loc, aspace, bp_addr))
5248c50c785cSJohn Marino 	{
5249c50c785cSJohn Marino 	  bs = bpstat_alloc (loc, &bs_link);
5250c50c785cSJohn Marino 	  /* For hits of moribund locations, we should just proceed.  */
5251c50c785cSJohn Marino 	  bs->stop = 0;
5252c50c785cSJohn Marino 	  bs->print = 0;
5253c50c785cSJohn Marino 	  bs->print_it = print_it_noop;
5254c50c785cSJohn Marino 	}
5255c50c785cSJohn Marino     }
5256c50c785cSJohn Marino 
5257*ef5ccd6cSJohn Marino   /* A bit of special processing for shlib breakpoints.  We need to
5258*ef5ccd6cSJohn Marino      process solib loading here, so that the lists of loaded and
5259*ef5ccd6cSJohn Marino      unloaded libraries are correct before we handle "catch load" and
5260*ef5ccd6cSJohn Marino      "catch unload".  */
5261*ef5ccd6cSJohn Marino   for (bs = bs_head; bs != NULL; bs = bs->next)
5262*ef5ccd6cSJohn Marino     {
5263*ef5ccd6cSJohn Marino       if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
5264*ef5ccd6cSJohn Marino 	{
5265*ef5ccd6cSJohn Marino 	  handle_solib_event ();
5266*ef5ccd6cSJohn Marino 	  break;
5267*ef5ccd6cSJohn Marino 	}
5268*ef5ccd6cSJohn Marino     }
5269*ef5ccd6cSJohn Marino 
5270c50c785cSJohn Marino   /* Now go through the locations that caused the target to stop, and
5271c50c785cSJohn Marino      check whether we're interested in reporting this stop to higher
5272c50c785cSJohn Marino      layers, or whether we should resume the target transparently.  */
5273c50c785cSJohn Marino 
5274c50c785cSJohn Marino   removed_any = 0;
5275c50c785cSJohn Marino 
5276c50c785cSJohn Marino   for (bs = bs_head; bs != NULL; bs = bs->next)
5277c50c785cSJohn Marino     {
5278c50c785cSJohn Marino       if (!bs->stop)
5279c50c785cSJohn Marino 	continue;
5280c50c785cSJohn Marino 
5281c50c785cSJohn Marino       b = bs->breakpoint_at;
5282a45ae5f8SJohn Marino       b->ops->check_status (bs);
5283a45ae5f8SJohn Marino       if (bs->stop)
5284a45ae5f8SJohn Marino 	{
52855796c8dcSSimon Schubert 	  bpstat_check_breakpoint_conditions (bs, ptid);
52865796c8dcSSimon Schubert 
52875796c8dcSSimon Schubert 	  if (bs->stop)
52885796c8dcSSimon Schubert 	    {
52895796c8dcSSimon Schubert 	      ++(b->hit_count);
5290a45ae5f8SJohn Marino 	      observer_notify_breakpoint_modified (b);
52915796c8dcSSimon Schubert 
5292c50c785cSJohn Marino 	      /* We will stop here.  */
52935796c8dcSSimon Schubert 	      if (b->disposition == disp_disable)
52945796c8dcSSimon Schubert 		{
5295*ef5ccd6cSJohn Marino 		  --(b->enable_count);
5296*ef5ccd6cSJohn Marino 		  if (b->enable_count <= 0
5297*ef5ccd6cSJohn Marino 		      && b->enable_state != bp_permanent)
52985796c8dcSSimon Schubert 		    b->enable_state = bp_disabled;
5299c50c785cSJohn Marino 		  removed_any = 1;
53005796c8dcSSimon Schubert 		}
53015796c8dcSSimon Schubert 	      if (b->silent)
53025796c8dcSSimon Schubert 		bs->print = 0;
53035796c8dcSSimon Schubert 	      bs->commands = b->commands;
5304cf7f2e2dSJohn Marino 	      incref_counted_command_line (bs->commands);
5305a45ae5f8SJohn Marino 	      if (command_line_is_silent (bs->commands
5306a45ae5f8SJohn Marino 					  ? bs->commands->commands : NULL))
53075796c8dcSSimon Schubert 		bs->print = 0;
5308*ef5ccd6cSJohn Marino 
5309*ef5ccd6cSJohn Marino 	      b->ops->after_condition_true (bs);
53105796c8dcSSimon Schubert 	    }
53115796c8dcSSimon Schubert 
53125796c8dcSSimon Schubert 	}
5313*ef5ccd6cSJohn Marino 
5314*ef5ccd6cSJohn Marino       /* Print nothing for this entry if we don't stop or don't
5315*ef5ccd6cSJohn Marino 	 print.  */
5316*ef5ccd6cSJohn Marino       if (!bs->stop || !bs->print)
5317*ef5ccd6cSJohn Marino 	bs->print_it = print_it_noop;
5318a45ae5f8SJohn Marino     }
53195796c8dcSSimon Schubert 
53205796c8dcSSimon Schubert   /* If we aren't stopping, the value of some hardware watchpoint may
53215796c8dcSSimon Schubert      not have changed, but the intermediate memory locations we are
53225796c8dcSSimon Schubert      watching may have.  Don't bother if we're stopping; this will get
53235796c8dcSSimon Schubert      done later.  */
53245796c8dcSSimon Schubert   need_remove_insert = 0;
5325c50c785cSJohn Marino   if (! bpstat_causes_stop (bs_head))
5326c50c785cSJohn Marino     for (bs = bs_head; bs != NULL; bs = bs->next)
53275796c8dcSSimon Schubert       if (!bs->stop
5328c50c785cSJohn Marino 	  && bs->breakpoint_at
5329c50c785cSJohn Marino 	  && is_hardware_watchpoint (bs->breakpoint_at))
53305796c8dcSSimon Schubert 	{
5331a45ae5f8SJohn Marino 	  struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
5332a45ae5f8SJohn Marino 
5333a45ae5f8SJohn Marino 	  update_watchpoint (w, 0 /* don't reparse.  */);
53345796c8dcSSimon Schubert 	  need_remove_insert = 1;
53355796c8dcSSimon Schubert 	}
53365796c8dcSSimon Schubert 
53375796c8dcSSimon Schubert   if (need_remove_insert)
5338cf7f2e2dSJohn Marino     update_global_location_list (1);
5339c50c785cSJohn Marino   else if (removed_any)
5340c50c785cSJohn Marino     update_global_location_list (0);
53415796c8dcSSimon Schubert 
5342c50c785cSJohn Marino   return bs_head;
53435796c8dcSSimon Schubert }
5344cf7f2e2dSJohn Marino 
5345cf7f2e2dSJohn Marino static void
handle_jit_event(void)5346cf7f2e2dSJohn Marino handle_jit_event (void)
5347cf7f2e2dSJohn Marino {
5348cf7f2e2dSJohn Marino   struct frame_info *frame;
5349cf7f2e2dSJohn Marino   struct gdbarch *gdbarch;
5350cf7f2e2dSJohn Marino 
5351cf7f2e2dSJohn Marino   /* Switch terminal for any messages produced by
5352cf7f2e2dSJohn Marino      breakpoint_re_set.  */
5353cf7f2e2dSJohn Marino   target_terminal_ours_for_output ();
5354cf7f2e2dSJohn Marino 
5355cf7f2e2dSJohn Marino   frame = get_current_frame ();
5356cf7f2e2dSJohn Marino   gdbarch = get_frame_arch (frame);
5357cf7f2e2dSJohn Marino 
5358cf7f2e2dSJohn Marino   jit_event_handler (gdbarch);
5359cf7f2e2dSJohn Marino 
5360cf7f2e2dSJohn Marino   target_terminal_inferior ();
5361cf7f2e2dSJohn Marino }
5362cf7f2e2dSJohn Marino 
5363*ef5ccd6cSJohn Marino /* Handle an solib event by calling solib_add.  */
5364*ef5ccd6cSJohn Marino 
5365*ef5ccd6cSJohn Marino void
handle_solib_event(void)5366*ef5ccd6cSJohn Marino handle_solib_event (void)
5367*ef5ccd6cSJohn Marino {
5368*ef5ccd6cSJohn Marino   clear_program_space_solib_cache (current_inferior ()->pspace);
5369*ef5ccd6cSJohn Marino 
5370*ef5ccd6cSJohn Marino   /* Check for any newly added shared libraries if we're supposed to
5371*ef5ccd6cSJohn Marino      be adding them automatically.  Switch terminal for any messages
5372*ef5ccd6cSJohn Marino      produced by breakpoint_re_set.  */
5373*ef5ccd6cSJohn Marino   target_terminal_ours_for_output ();
5374*ef5ccd6cSJohn Marino #ifdef SOLIB_ADD
5375*ef5ccd6cSJohn Marino   SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
5376*ef5ccd6cSJohn Marino #else
5377*ef5ccd6cSJohn Marino   solib_add (NULL, 0, &current_target, auto_solib_add);
5378*ef5ccd6cSJohn Marino #endif
5379*ef5ccd6cSJohn Marino   target_terminal_inferior ();
5380*ef5ccd6cSJohn Marino }
5381*ef5ccd6cSJohn Marino 
5382cf7f2e2dSJohn Marino /* Prepare WHAT final decision for infrun.  */
5383cf7f2e2dSJohn Marino 
5384cf7f2e2dSJohn Marino /* Decide what infrun needs to do with this bpstat.  */
5385cf7f2e2dSJohn Marino 
53865796c8dcSSimon Schubert struct bpstat_what
bpstat_what(bpstat bs_head)5387c50c785cSJohn Marino bpstat_what (bpstat bs_head)
53885796c8dcSSimon Schubert {
53895796c8dcSSimon Schubert   struct bpstat_what retval;
5390cf7f2e2dSJohn Marino   int jit_event = 0;
5391c50c785cSJohn Marino   bpstat bs;
53925796c8dcSSimon Schubert 
5393cf7f2e2dSJohn Marino   retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
5394cf7f2e2dSJohn Marino   retval.call_dummy = STOP_NONE;
5395c50c785cSJohn Marino   retval.is_longjmp = 0;
5396cf7f2e2dSJohn Marino 
5397c50c785cSJohn Marino   for (bs = bs_head; bs != NULL; bs = bs->next)
53985796c8dcSSimon Schubert     {
5399cf7f2e2dSJohn Marino       /* Extract this BS's action.  After processing each BS, we check
5400cf7f2e2dSJohn Marino 	 if its action overrides all we've seem so far.  */
5401cf7f2e2dSJohn Marino       enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5402cf7f2e2dSJohn Marino       enum bptype bptype;
5403cf7f2e2dSJohn Marino 
54045796c8dcSSimon Schubert       if (bs->breakpoint_at == NULL)
5405cf7f2e2dSJohn Marino 	{
5406cf7f2e2dSJohn Marino 	  /* I suspect this can happen if it was a momentary
5407cf7f2e2dSJohn Marino 	     breakpoint which has since been deleted.  */
5408cf7f2e2dSJohn Marino 	  bptype = bp_none;
5409cf7f2e2dSJohn Marino 	}
54105796c8dcSSimon Schubert       else
5411c50c785cSJohn Marino 	bptype = bs->breakpoint_at->type;
5412cf7f2e2dSJohn Marino 
5413cf7f2e2dSJohn Marino       switch (bptype)
54145796c8dcSSimon Schubert 	{
54155796c8dcSSimon Schubert 	case bp_none:
5416cf7f2e2dSJohn Marino 	  break;
54175796c8dcSSimon Schubert 	case bp_breakpoint:
54185796c8dcSSimon Schubert 	case bp_hardware_breakpoint:
54195796c8dcSSimon Schubert 	case bp_until:
54205796c8dcSSimon Schubert 	case bp_finish:
5421*ef5ccd6cSJohn Marino 	case bp_shlib_event:
54225796c8dcSSimon Schubert 	  if (bs->stop)
54235796c8dcSSimon Schubert 	    {
54245796c8dcSSimon Schubert 	      if (bs->print)
5425cf7f2e2dSJohn Marino 		this_action = BPSTAT_WHAT_STOP_NOISY;
54265796c8dcSSimon Schubert 	      else
5427cf7f2e2dSJohn Marino 		this_action = BPSTAT_WHAT_STOP_SILENT;
54285796c8dcSSimon Schubert 	    }
54295796c8dcSSimon Schubert 	  else
5430cf7f2e2dSJohn Marino 	    this_action = BPSTAT_WHAT_SINGLE;
54315796c8dcSSimon Schubert 	  break;
54325796c8dcSSimon Schubert 	case bp_watchpoint:
54335796c8dcSSimon Schubert 	case bp_hardware_watchpoint:
54345796c8dcSSimon Schubert 	case bp_read_watchpoint:
54355796c8dcSSimon Schubert 	case bp_access_watchpoint:
54365796c8dcSSimon Schubert 	  if (bs->stop)
54375796c8dcSSimon Schubert 	    {
54385796c8dcSSimon Schubert 	      if (bs->print)
5439cf7f2e2dSJohn Marino 		this_action = BPSTAT_WHAT_STOP_NOISY;
54405796c8dcSSimon Schubert 	      else
5441cf7f2e2dSJohn Marino 		this_action = BPSTAT_WHAT_STOP_SILENT;
54425796c8dcSSimon Schubert 	    }
54435796c8dcSSimon Schubert 	  else
5444cf7f2e2dSJohn Marino 	    {
54455796c8dcSSimon Schubert 	      /* There was a watchpoint, but we're not stopping.
54465796c8dcSSimon Schubert 		 This requires no further action.  */
5447cf7f2e2dSJohn Marino 	    }
54485796c8dcSSimon Schubert 	  break;
54495796c8dcSSimon Schubert 	case bp_longjmp:
5450*ef5ccd6cSJohn Marino 	case bp_longjmp_call_dummy:
5451c50c785cSJohn Marino 	case bp_exception:
5452cf7f2e2dSJohn Marino 	  this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
5453*ef5ccd6cSJohn Marino 	  retval.is_longjmp = bptype != bp_exception;
54545796c8dcSSimon Schubert 	  break;
54555796c8dcSSimon Schubert 	case bp_longjmp_resume:
5456c50c785cSJohn Marino 	case bp_exception_resume:
5457cf7f2e2dSJohn Marino 	  this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
5458c50c785cSJohn Marino 	  retval.is_longjmp = bptype == bp_longjmp_resume;
54595796c8dcSSimon Schubert 	  break;
54605796c8dcSSimon Schubert 	case bp_step_resume:
54615796c8dcSSimon Schubert 	  if (bs->stop)
5462cf7f2e2dSJohn Marino 	    this_action = BPSTAT_WHAT_STEP_RESUME;
54635796c8dcSSimon Schubert 	  else
5464cf7f2e2dSJohn Marino 	    {
54655796c8dcSSimon Schubert 	      /* It is for the wrong frame.  */
5466cf7f2e2dSJohn Marino 	      this_action = BPSTAT_WHAT_SINGLE;
5467cf7f2e2dSJohn Marino 	    }
54685796c8dcSSimon Schubert 	  break;
5469a45ae5f8SJohn Marino 	case bp_hp_step_resume:
5470a45ae5f8SJohn Marino 	  if (bs->stop)
5471a45ae5f8SJohn Marino 	    this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5472a45ae5f8SJohn Marino 	  else
5473a45ae5f8SJohn Marino 	    {
5474a45ae5f8SJohn Marino 	      /* It is for the wrong frame.  */
5475a45ae5f8SJohn Marino 	      this_action = BPSTAT_WHAT_SINGLE;
5476a45ae5f8SJohn Marino 	    }
5477a45ae5f8SJohn Marino 	  break;
54785796c8dcSSimon Schubert 	case bp_watchpoint_scope:
54795796c8dcSSimon Schubert 	case bp_thread_event:
54805796c8dcSSimon Schubert 	case bp_overlay_event:
54815796c8dcSSimon Schubert 	case bp_longjmp_master:
5482cf7f2e2dSJohn Marino 	case bp_std_terminate_master:
5483c50c785cSJohn Marino 	case bp_exception_master:
5484cf7f2e2dSJohn Marino 	  this_action = BPSTAT_WHAT_SINGLE;
54855796c8dcSSimon Schubert 	  break;
54865796c8dcSSimon Schubert 	case bp_catchpoint:
54875796c8dcSSimon Schubert 	  if (bs->stop)
54885796c8dcSSimon Schubert 	    {
54895796c8dcSSimon Schubert 	      if (bs->print)
5490cf7f2e2dSJohn Marino 		this_action = BPSTAT_WHAT_STOP_NOISY;
54915796c8dcSSimon Schubert 	      else
5492cf7f2e2dSJohn Marino 		this_action = BPSTAT_WHAT_STOP_SILENT;
54935796c8dcSSimon Schubert 	    }
54945796c8dcSSimon Schubert 	  else
5495cf7f2e2dSJohn Marino 	    {
54965796c8dcSSimon Schubert 	      /* There was a catchpoint, but we're not stopping.
54975796c8dcSSimon Schubert 		 This requires no further action.  */
5498cf7f2e2dSJohn Marino 	    }
5499cf7f2e2dSJohn Marino 	  break;
5500cf7f2e2dSJohn Marino 	case bp_jit_event:
5501cf7f2e2dSJohn Marino 	  jit_event = 1;
5502cf7f2e2dSJohn Marino 	  this_action = BPSTAT_WHAT_SINGLE;
55035796c8dcSSimon Schubert 	  break;
55045796c8dcSSimon Schubert 	case bp_call_dummy:
55055796c8dcSSimon Schubert 	  /* Make sure the action is stop (silent or noisy),
55065796c8dcSSimon Schubert 	     so infrun.c pops the dummy frame.  */
5507cf7f2e2dSJohn Marino 	  retval.call_dummy = STOP_STACK_DUMMY;
5508cf7f2e2dSJohn Marino 	  this_action = BPSTAT_WHAT_STOP_SILENT;
5509cf7f2e2dSJohn Marino 	  break;
5510cf7f2e2dSJohn Marino 	case bp_std_terminate:
5511cf7f2e2dSJohn Marino 	  /* Make sure the action is stop (silent or noisy),
5512cf7f2e2dSJohn Marino 	     so infrun.c pops the dummy frame.  */
5513cf7f2e2dSJohn Marino 	  retval.call_dummy = STOP_STD_TERMINATE;
5514cf7f2e2dSJohn Marino 	  this_action = BPSTAT_WHAT_STOP_SILENT;
55155796c8dcSSimon Schubert 	  break;
55165796c8dcSSimon Schubert 	case bp_tracepoint:
5517cf7f2e2dSJohn Marino 	case bp_fast_tracepoint:
5518cf7f2e2dSJohn Marino 	case bp_static_tracepoint:
55195796c8dcSSimon Schubert 	  /* Tracepoint hits should not be reported back to GDB, and
55205796c8dcSSimon Schubert 	     if one got through somehow, it should have been filtered
55215796c8dcSSimon Schubert 	     out already.  */
55225796c8dcSSimon Schubert 	  internal_error (__FILE__, __LINE__,
5523cf7f2e2dSJohn Marino 			  _("bpstat_what: tracepoint encountered"));
5524c50c785cSJohn Marino 	  break;
5525c50c785cSJohn Marino 	case bp_gnu_ifunc_resolver:
5526c50c785cSJohn Marino 	  /* Step over it (and insert bp_gnu_ifunc_resolver_return).  */
5527c50c785cSJohn Marino 	  this_action = BPSTAT_WHAT_SINGLE;
5528c50c785cSJohn Marino 	  break;
5529c50c785cSJohn Marino 	case bp_gnu_ifunc_resolver_return:
5530c50c785cSJohn Marino 	  /* The breakpoint will be removed, execution will restart from the
5531c50c785cSJohn Marino 	     PC of the former breakpoint.  */
5532c50c785cSJohn Marino 	  this_action = BPSTAT_WHAT_KEEP_CHECKING;
5533c50c785cSJohn Marino 	  break;
5534*ef5ccd6cSJohn Marino 
5535*ef5ccd6cSJohn Marino 	case bp_dprintf:
5536*ef5ccd6cSJohn Marino 	  if (bs->stop)
5537*ef5ccd6cSJohn Marino 	    this_action = BPSTAT_WHAT_STOP_SILENT;
5538*ef5ccd6cSJohn Marino 	  else
5539*ef5ccd6cSJohn Marino 	    this_action = BPSTAT_WHAT_SINGLE;
5540*ef5ccd6cSJohn Marino 	  break;
5541*ef5ccd6cSJohn Marino 
5542cf7f2e2dSJohn Marino 	default:
5543cf7f2e2dSJohn Marino 	  internal_error (__FILE__, __LINE__,
5544cf7f2e2dSJohn Marino 			  _("bpstat_what: unhandled bptype %d"), (int) bptype);
55455796c8dcSSimon Schubert 	}
5546cf7f2e2dSJohn Marino 
5547cf7f2e2dSJohn Marino       retval.main_action = max (retval.main_action, this_action);
55485796c8dcSSimon Schubert     }
5549cf7f2e2dSJohn Marino 
5550c50c785cSJohn Marino   /* These operations may affect the bs->breakpoint_at state so they are
5551c50c785cSJohn Marino      delayed after MAIN_ACTION is decided above.  */
5552c50c785cSJohn Marino 
5553cf7f2e2dSJohn Marino   if (jit_event)
5554cf7f2e2dSJohn Marino     {
5555cf7f2e2dSJohn Marino       if (debug_infrun)
5556cf7f2e2dSJohn Marino 	fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5557cf7f2e2dSJohn Marino 
5558cf7f2e2dSJohn Marino       handle_jit_event ();
5559cf7f2e2dSJohn Marino     }
5560cf7f2e2dSJohn Marino 
5561c50c785cSJohn Marino   for (bs = bs_head; bs != NULL; bs = bs->next)
5562c50c785cSJohn Marino     {
5563c50c785cSJohn Marino       struct breakpoint *b = bs->breakpoint_at;
5564c50c785cSJohn Marino 
5565c50c785cSJohn Marino       if (b == NULL)
5566c50c785cSJohn Marino 	continue;
5567c50c785cSJohn Marino       switch (b->type)
5568c50c785cSJohn Marino 	{
5569c50c785cSJohn Marino 	case bp_gnu_ifunc_resolver:
5570c50c785cSJohn Marino 	  gnu_ifunc_resolver_stop (b);
5571c50c785cSJohn Marino 	  break;
5572c50c785cSJohn Marino 	case bp_gnu_ifunc_resolver_return:
5573c50c785cSJohn Marino 	  gnu_ifunc_resolver_return_stop (b);
5574c50c785cSJohn Marino 	  break;
5575c50c785cSJohn Marino 	}
5576c50c785cSJohn Marino     }
5577c50c785cSJohn Marino 
55785796c8dcSSimon Schubert   return retval;
55795796c8dcSSimon Schubert }
55805796c8dcSSimon Schubert 
55815796c8dcSSimon Schubert /* Nonzero if we should step constantly (e.g. watchpoints on machines
55825796c8dcSSimon Schubert    without hardware support).  This isn't related to a specific bpstat,
55835796c8dcSSimon Schubert    just to things like whether watchpoints are set.  */
55845796c8dcSSimon Schubert 
55855796c8dcSSimon Schubert int
bpstat_should_step(void)55865796c8dcSSimon Schubert bpstat_should_step (void)
55875796c8dcSSimon Schubert {
55885796c8dcSSimon Schubert   struct breakpoint *b;
5589cf7f2e2dSJohn Marino 
55905796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
55915796c8dcSSimon Schubert     if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
55925796c8dcSSimon Schubert       return 1;
55935796c8dcSSimon Schubert   return 0;
55945796c8dcSSimon Schubert }
55955796c8dcSSimon Schubert 
5596cf7f2e2dSJohn Marino int
bpstat_causes_stop(bpstat bs)5597cf7f2e2dSJohn Marino bpstat_causes_stop (bpstat bs)
5598cf7f2e2dSJohn Marino {
5599cf7f2e2dSJohn Marino   for (; bs != NULL; bs = bs->next)
5600cf7f2e2dSJohn Marino     if (bs->stop)
5601cf7f2e2dSJohn Marino       return 1;
5602cf7f2e2dSJohn Marino 
5603cf7f2e2dSJohn Marino   return 0;
5604cf7f2e2dSJohn Marino }
5605cf7f2e2dSJohn Marino 
56065796c8dcSSimon Schubert 
56075796c8dcSSimon Schubert 
5608c50c785cSJohn Marino /* Compute a string of spaces suitable to indent the next line
5609c50c785cSJohn Marino    so it starts at the position corresponding to the table column
5610c50c785cSJohn Marino    named COL_NAME in the currently active table of UIOUT.  */
5611c50c785cSJohn Marino 
5612c50c785cSJohn Marino static char *
wrap_indent_at_field(struct ui_out * uiout,const char * col_name)5613c50c785cSJohn Marino wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5614c50c785cSJohn Marino {
5615c50c785cSJohn Marino   static char wrap_indent[80];
5616c50c785cSJohn Marino   int i, total_width, width, align;
5617c50c785cSJohn Marino   char *text;
5618c50c785cSJohn Marino 
5619c50c785cSJohn Marino   total_width = 0;
5620c50c785cSJohn Marino   for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5621c50c785cSJohn Marino     {
5622c50c785cSJohn Marino       if (strcmp (text, col_name) == 0)
5623c50c785cSJohn Marino 	{
5624c50c785cSJohn Marino 	  gdb_assert (total_width < sizeof wrap_indent);
5625c50c785cSJohn Marino 	  memset (wrap_indent, ' ', total_width);
5626c50c785cSJohn Marino 	  wrap_indent[total_width] = 0;
5627c50c785cSJohn Marino 
5628c50c785cSJohn Marino 	  return wrap_indent;
5629c50c785cSJohn Marino 	}
5630c50c785cSJohn Marino 
5631c50c785cSJohn Marino       total_width += width + 1;
5632c50c785cSJohn Marino     }
5633c50c785cSJohn Marino 
5634c50c785cSJohn Marino   return NULL;
5635c50c785cSJohn Marino }
5636c50c785cSJohn Marino 
5637*ef5ccd6cSJohn Marino /* Determine if the locations of this breakpoint will have their conditions
5638*ef5ccd6cSJohn Marino    evaluated by the target, host or a mix of both.  Returns the following:
5639*ef5ccd6cSJohn Marino 
5640*ef5ccd6cSJohn Marino     "host": Host evals condition.
5641*ef5ccd6cSJohn Marino     "host or target": Host or Target evals condition.
5642*ef5ccd6cSJohn Marino     "target": Target evals condition.
5643*ef5ccd6cSJohn Marino */
5644*ef5ccd6cSJohn Marino 
5645*ef5ccd6cSJohn Marino static const char *
bp_condition_evaluator(struct breakpoint * b)5646*ef5ccd6cSJohn Marino bp_condition_evaluator (struct breakpoint *b)
5647*ef5ccd6cSJohn Marino {
5648*ef5ccd6cSJohn Marino   struct bp_location *bl;
5649*ef5ccd6cSJohn Marino   char host_evals = 0;
5650*ef5ccd6cSJohn Marino   char target_evals = 0;
5651*ef5ccd6cSJohn Marino 
5652*ef5ccd6cSJohn Marino   if (!b)
5653*ef5ccd6cSJohn Marino     return NULL;
5654*ef5ccd6cSJohn Marino 
5655*ef5ccd6cSJohn Marino   if (!is_breakpoint (b))
5656*ef5ccd6cSJohn Marino     return NULL;
5657*ef5ccd6cSJohn Marino 
5658*ef5ccd6cSJohn Marino   if (gdb_evaluates_breakpoint_condition_p ()
5659*ef5ccd6cSJohn Marino       || !target_supports_evaluation_of_breakpoint_conditions ())
5660*ef5ccd6cSJohn Marino     return condition_evaluation_host;
5661*ef5ccd6cSJohn Marino 
5662*ef5ccd6cSJohn Marino   for (bl = b->loc; bl; bl = bl->next)
5663*ef5ccd6cSJohn Marino     {
5664*ef5ccd6cSJohn Marino       if (bl->cond_bytecode)
5665*ef5ccd6cSJohn Marino 	target_evals++;
5666*ef5ccd6cSJohn Marino       else
5667*ef5ccd6cSJohn Marino 	host_evals++;
5668*ef5ccd6cSJohn Marino     }
5669*ef5ccd6cSJohn Marino 
5670*ef5ccd6cSJohn Marino   if (host_evals && target_evals)
5671*ef5ccd6cSJohn Marino     return condition_evaluation_both;
5672*ef5ccd6cSJohn Marino   else if (target_evals)
5673*ef5ccd6cSJohn Marino     return condition_evaluation_target;
5674*ef5ccd6cSJohn Marino   else
5675*ef5ccd6cSJohn Marino     return condition_evaluation_host;
5676*ef5ccd6cSJohn Marino }
5677*ef5ccd6cSJohn Marino 
5678*ef5ccd6cSJohn Marino /* Determine the breakpoint location's condition evaluator.  This is
5679*ef5ccd6cSJohn Marino    similar to bp_condition_evaluator, but for locations.  */
5680*ef5ccd6cSJohn Marino 
5681*ef5ccd6cSJohn Marino static const char *
bp_location_condition_evaluator(struct bp_location * bl)5682*ef5ccd6cSJohn Marino bp_location_condition_evaluator (struct bp_location *bl)
5683*ef5ccd6cSJohn Marino {
5684*ef5ccd6cSJohn Marino   if (bl && !is_breakpoint (bl->owner))
5685*ef5ccd6cSJohn Marino     return NULL;
5686*ef5ccd6cSJohn Marino 
5687*ef5ccd6cSJohn Marino   if (gdb_evaluates_breakpoint_condition_p ()
5688*ef5ccd6cSJohn Marino       || !target_supports_evaluation_of_breakpoint_conditions ())
5689*ef5ccd6cSJohn Marino     return condition_evaluation_host;
5690*ef5ccd6cSJohn Marino 
5691*ef5ccd6cSJohn Marino   if (bl && bl->cond_bytecode)
5692*ef5ccd6cSJohn Marino     return condition_evaluation_target;
5693*ef5ccd6cSJohn Marino   else
5694*ef5ccd6cSJohn Marino     return condition_evaluation_host;
5695*ef5ccd6cSJohn Marino }
5696*ef5ccd6cSJohn Marino 
5697cf7f2e2dSJohn Marino /* Print the LOC location out of the list of B->LOC locations.  */
5698cf7f2e2dSJohn Marino 
5699c50c785cSJohn Marino static void
print_breakpoint_location(struct breakpoint * b,struct bp_location * loc)5700c50c785cSJohn Marino print_breakpoint_location (struct breakpoint *b,
5701c50c785cSJohn Marino 			   struct bp_location *loc)
57025796c8dcSSimon Schubert {
5703a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
5704cf7f2e2dSJohn Marino   struct cleanup *old_chain = save_current_program_space ();
5705cf7f2e2dSJohn Marino 
5706cf7f2e2dSJohn Marino   if (loc != NULL && loc->shlib_disabled)
5707cf7f2e2dSJohn Marino     loc = NULL;
5708cf7f2e2dSJohn Marino 
5709cf7f2e2dSJohn Marino   if (loc != NULL)
5710cf7f2e2dSJohn Marino     set_current_program_space (loc->pspace);
5711cf7f2e2dSJohn Marino 
5712c50c785cSJohn Marino   if (b->display_canonical)
5713c50c785cSJohn Marino     ui_out_field_string (uiout, "what", b->addr_string);
5714*ef5ccd6cSJohn Marino   else if (loc && loc->symtab)
57155796c8dcSSimon Schubert     {
57165796c8dcSSimon Schubert       struct symbol *sym
57175796c8dcSSimon Schubert 	= find_pc_sect_function (loc->address, loc->section);
57185796c8dcSSimon Schubert       if (sym)
57195796c8dcSSimon Schubert 	{
57205796c8dcSSimon Schubert 	  ui_out_text (uiout, "in ");
57215796c8dcSSimon Schubert 	  ui_out_field_string (uiout, "func",
57225796c8dcSSimon Schubert 			       SYMBOL_PRINT_NAME (sym));
5723c50c785cSJohn Marino 	  ui_out_text (uiout, " ");
5724c50c785cSJohn Marino 	  ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
57255796c8dcSSimon Schubert 	  ui_out_text (uiout, "at ");
57265796c8dcSSimon Schubert 	}
5727*ef5ccd6cSJohn Marino       ui_out_field_string (uiout, "file",
5728*ef5ccd6cSJohn Marino 			   symtab_to_filename_for_display (loc->symtab));
57295796c8dcSSimon Schubert       ui_out_text (uiout, ":");
57305796c8dcSSimon Schubert 
57315796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
5732*ef5ccd6cSJohn Marino 	ui_out_field_string (uiout, "fullname",
5733*ef5ccd6cSJohn Marino 			     symtab_to_fullname (loc->symtab));
57345796c8dcSSimon Schubert 
5735a45ae5f8SJohn Marino       ui_out_field_int (uiout, "line", loc->line_number);
57365796c8dcSSimon Schubert     }
5737cf7f2e2dSJohn Marino   else if (loc)
57385796c8dcSSimon Schubert     {
5739*ef5ccd6cSJohn Marino       struct ui_file *stb = mem_fileopen ();
5740*ef5ccd6cSJohn Marino       struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
5741c50c785cSJohn Marino 
5742*ef5ccd6cSJohn Marino       print_address_symbolic (loc->gdbarch, loc->address, stb,
5743cf7f2e2dSJohn Marino 			      demangle, "");
57445796c8dcSSimon Schubert       ui_out_field_stream (uiout, "at", stb);
5745c50c785cSJohn Marino 
5746c50c785cSJohn Marino       do_cleanups (stb_chain);
57475796c8dcSSimon Schubert     }
5748cf7f2e2dSJohn Marino   else
5749cf7f2e2dSJohn Marino     ui_out_field_string (uiout, "pending", b->addr_string);
5750cf7f2e2dSJohn Marino 
5751*ef5ccd6cSJohn Marino   if (loc && is_breakpoint (b)
5752*ef5ccd6cSJohn Marino       && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5753*ef5ccd6cSJohn Marino       && bp_condition_evaluator (b) == condition_evaluation_both)
5754*ef5ccd6cSJohn Marino     {
5755*ef5ccd6cSJohn Marino       ui_out_text (uiout, " (");
5756*ef5ccd6cSJohn Marino       ui_out_field_string (uiout, "evaluated-by",
5757*ef5ccd6cSJohn Marino 			   bp_location_condition_evaluator (loc));
5758*ef5ccd6cSJohn Marino       ui_out_text (uiout, ")");
5759*ef5ccd6cSJohn Marino     }
5760*ef5ccd6cSJohn Marino 
5761cf7f2e2dSJohn Marino   do_cleanups (old_chain);
57625796c8dcSSimon Schubert }
57635796c8dcSSimon Schubert 
5764c50c785cSJohn Marino static const char *
bptype_string(enum bptype type)5765c50c785cSJohn Marino bptype_string (enum bptype type)
57665796c8dcSSimon Schubert {
57675796c8dcSSimon Schubert   struct ep_type_description
57685796c8dcSSimon Schubert     {
57695796c8dcSSimon Schubert       enum bptype type;
57705796c8dcSSimon Schubert       char *description;
57715796c8dcSSimon Schubert     };
57725796c8dcSSimon Schubert   static struct ep_type_description bptypes[] =
57735796c8dcSSimon Schubert   {
57745796c8dcSSimon Schubert     {bp_none, "?deleted?"},
57755796c8dcSSimon Schubert     {bp_breakpoint, "breakpoint"},
57765796c8dcSSimon Schubert     {bp_hardware_breakpoint, "hw breakpoint"},
57775796c8dcSSimon Schubert     {bp_until, "until"},
57785796c8dcSSimon Schubert     {bp_finish, "finish"},
57795796c8dcSSimon Schubert     {bp_watchpoint, "watchpoint"},
57805796c8dcSSimon Schubert     {bp_hardware_watchpoint, "hw watchpoint"},
57815796c8dcSSimon Schubert     {bp_read_watchpoint, "read watchpoint"},
57825796c8dcSSimon Schubert     {bp_access_watchpoint, "acc watchpoint"},
57835796c8dcSSimon Schubert     {bp_longjmp, "longjmp"},
57845796c8dcSSimon Schubert     {bp_longjmp_resume, "longjmp resume"},
5785*ef5ccd6cSJohn Marino     {bp_longjmp_call_dummy, "longjmp for call dummy"},
5786c50c785cSJohn Marino     {bp_exception, "exception"},
5787c50c785cSJohn Marino     {bp_exception_resume, "exception resume"},
57885796c8dcSSimon Schubert     {bp_step_resume, "step resume"},
5789a45ae5f8SJohn Marino     {bp_hp_step_resume, "high-priority step resume"},
57905796c8dcSSimon Schubert     {bp_watchpoint_scope, "watchpoint scope"},
57915796c8dcSSimon Schubert     {bp_call_dummy, "call dummy"},
5792cf7f2e2dSJohn Marino     {bp_std_terminate, "std::terminate"},
57935796c8dcSSimon Schubert     {bp_shlib_event, "shlib events"},
57945796c8dcSSimon Schubert     {bp_thread_event, "thread events"},
57955796c8dcSSimon Schubert     {bp_overlay_event, "overlay events"},
57965796c8dcSSimon Schubert     {bp_longjmp_master, "longjmp master"},
5797cf7f2e2dSJohn Marino     {bp_std_terminate_master, "std::terminate master"},
5798c50c785cSJohn Marino     {bp_exception_master, "exception master"},
57995796c8dcSSimon Schubert     {bp_catchpoint, "catchpoint"},
58005796c8dcSSimon Schubert     {bp_tracepoint, "tracepoint"},
5801cf7f2e2dSJohn Marino     {bp_fast_tracepoint, "fast tracepoint"},
5802cf7f2e2dSJohn Marino     {bp_static_tracepoint, "static tracepoint"},
5803*ef5ccd6cSJohn Marino     {bp_dprintf, "dprintf"},
58045796c8dcSSimon Schubert     {bp_jit_event, "jit events"},
5805c50c785cSJohn Marino     {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5806c50c785cSJohn Marino     {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
58075796c8dcSSimon Schubert   };
58085796c8dcSSimon Schubert 
5809c50c785cSJohn Marino   if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5810c50c785cSJohn Marino       || ((int) type != bptypes[(int) type].type))
5811c50c785cSJohn Marino     internal_error (__FILE__, __LINE__,
5812c50c785cSJohn Marino 		    _("bptypes table does not describe type #%d."),
5813c50c785cSJohn Marino 		    (int) type);
5814c50c785cSJohn Marino 
5815c50c785cSJohn Marino   return bptypes[(int) type].description;
5816c50c785cSJohn Marino }
5817c50c785cSJohn Marino 
5818*ef5ccd6cSJohn Marino DEF_VEC_I(int);
5819*ef5ccd6cSJohn Marino 
5820*ef5ccd6cSJohn Marino /* For MI, output a field named 'thread-groups' with a list as the value.
5821*ef5ccd6cSJohn Marino    For CLI, prefix the list with the string 'inf'. */
5822*ef5ccd6cSJohn Marino 
5823*ef5ccd6cSJohn Marino static void
output_thread_groups(struct ui_out * uiout,const char * field_name,VEC (int)* inf_num,int mi_only)5824*ef5ccd6cSJohn Marino output_thread_groups (struct ui_out *uiout,
5825*ef5ccd6cSJohn Marino 		      const char *field_name,
5826*ef5ccd6cSJohn Marino 		      VEC(int) *inf_num,
5827*ef5ccd6cSJohn Marino 		      int mi_only)
5828*ef5ccd6cSJohn Marino {
5829*ef5ccd6cSJohn Marino   struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
5830*ef5ccd6cSJohn Marino 								field_name);
5831*ef5ccd6cSJohn Marino   int is_mi = ui_out_is_mi_like_p (uiout);
5832*ef5ccd6cSJohn Marino   int inf;
5833*ef5ccd6cSJohn Marino   int i;
5834*ef5ccd6cSJohn Marino 
5835*ef5ccd6cSJohn Marino   /* For backward compatibility, don't display inferiors in CLI unless
5836*ef5ccd6cSJohn Marino      there are several.  Always display them for MI. */
5837*ef5ccd6cSJohn Marino   if (!is_mi && mi_only)
5838*ef5ccd6cSJohn Marino     return;
5839*ef5ccd6cSJohn Marino 
5840*ef5ccd6cSJohn Marino   for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i)
5841*ef5ccd6cSJohn Marino     {
5842*ef5ccd6cSJohn Marino       if (is_mi)
5843*ef5ccd6cSJohn Marino 	{
5844*ef5ccd6cSJohn Marino 	  char mi_group[10];
5845*ef5ccd6cSJohn Marino 
5846*ef5ccd6cSJohn Marino 	  xsnprintf (mi_group, sizeof (mi_group), "i%d", inf);
5847*ef5ccd6cSJohn Marino 	  ui_out_field_string (uiout, NULL, mi_group);
5848*ef5ccd6cSJohn Marino 	}
5849*ef5ccd6cSJohn Marino       else
5850*ef5ccd6cSJohn Marino 	{
5851*ef5ccd6cSJohn Marino 	  if (i == 0)
5852*ef5ccd6cSJohn Marino 	    ui_out_text (uiout, " inf ");
5853*ef5ccd6cSJohn Marino 	  else
5854*ef5ccd6cSJohn Marino 	    ui_out_text (uiout, ", ");
5855*ef5ccd6cSJohn Marino 
5856*ef5ccd6cSJohn Marino 	  ui_out_text (uiout, plongest (inf));
5857*ef5ccd6cSJohn Marino 	}
5858*ef5ccd6cSJohn Marino     }
5859*ef5ccd6cSJohn Marino 
5860*ef5ccd6cSJohn Marino   do_cleanups (back_to);
5861*ef5ccd6cSJohn Marino }
5862*ef5ccd6cSJohn Marino 
5863c50c785cSJohn Marino /* Print B to gdb_stdout.  */
5864c50c785cSJohn Marino 
5865c50c785cSJohn Marino static void
print_one_breakpoint_location(struct breakpoint * b,struct bp_location * loc,int loc_number,struct bp_location ** last_loc,int allflag)5866c50c785cSJohn Marino print_one_breakpoint_location (struct breakpoint *b,
5867c50c785cSJohn Marino 			       struct bp_location *loc,
5868c50c785cSJohn Marino 			       int loc_number,
5869c50c785cSJohn Marino 			       struct bp_location **last_loc,
5870c50c785cSJohn Marino 			       int allflag)
5871c50c785cSJohn Marino {
5872c50c785cSJohn Marino   struct command_line *l;
58735796c8dcSSimon Schubert   static char bpenables[] = "nynny";
58745796c8dcSSimon Schubert 
5875a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
58765796c8dcSSimon Schubert   int header_of_multiple = 0;
58775796c8dcSSimon Schubert   int part_of_multiple = (loc != NULL);
58785796c8dcSSimon Schubert   struct value_print_options opts;
58795796c8dcSSimon Schubert 
58805796c8dcSSimon Schubert   get_user_print_options (&opts);
58815796c8dcSSimon Schubert 
58825796c8dcSSimon Schubert   gdb_assert (!loc || loc_number != 0);
5883c50c785cSJohn Marino   /* See comment in print_one_breakpoint concerning treatment of
5884c50c785cSJohn Marino      breakpoints with single disabled location.  */
58855796c8dcSSimon Schubert   if (loc == NULL
58865796c8dcSSimon Schubert       && (b->loc != NULL
58875796c8dcSSimon Schubert 	  && (b->loc->next != NULL || !b->loc->enabled)))
58885796c8dcSSimon Schubert     header_of_multiple = 1;
58895796c8dcSSimon Schubert   if (loc == NULL)
58905796c8dcSSimon Schubert     loc = b->loc;
58915796c8dcSSimon Schubert 
58925796c8dcSSimon Schubert   annotate_record ();
58935796c8dcSSimon Schubert 
58945796c8dcSSimon Schubert   /* 1 */
58955796c8dcSSimon Schubert   annotate_field (0);
58965796c8dcSSimon Schubert   if (part_of_multiple)
58975796c8dcSSimon Schubert     {
58985796c8dcSSimon Schubert       char *formatted;
58995796c8dcSSimon Schubert       formatted = xstrprintf ("%d.%d", b->number, loc_number);
59005796c8dcSSimon Schubert       ui_out_field_string (uiout, "number", formatted);
59015796c8dcSSimon Schubert       xfree (formatted);
59025796c8dcSSimon Schubert     }
59035796c8dcSSimon Schubert   else
59045796c8dcSSimon Schubert     {
59055796c8dcSSimon Schubert       ui_out_field_int (uiout, "number", b->number);
59065796c8dcSSimon Schubert     }
59075796c8dcSSimon Schubert 
59085796c8dcSSimon Schubert   /* 2 */
59095796c8dcSSimon Schubert   annotate_field (1);
59105796c8dcSSimon Schubert   if (part_of_multiple)
59115796c8dcSSimon Schubert     ui_out_field_skip (uiout, "type");
59125796c8dcSSimon Schubert   else
5913c50c785cSJohn Marino     ui_out_field_string (uiout, "type", bptype_string (b->type));
59145796c8dcSSimon Schubert 
59155796c8dcSSimon Schubert   /* 3 */
59165796c8dcSSimon Schubert   annotate_field (2);
59175796c8dcSSimon Schubert   if (part_of_multiple)
59185796c8dcSSimon Schubert     ui_out_field_skip (uiout, "disp");
59195796c8dcSSimon Schubert   else
59205796c8dcSSimon Schubert     ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
59215796c8dcSSimon Schubert 
59225796c8dcSSimon Schubert 
59235796c8dcSSimon Schubert   /* 4 */
59245796c8dcSSimon Schubert   annotate_field (3);
59255796c8dcSSimon Schubert   if (part_of_multiple)
59265796c8dcSSimon Schubert     ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
59275796c8dcSSimon Schubert   else
59285796c8dcSSimon Schubert     ui_out_field_fmt (uiout, "enabled", "%c",
59295796c8dcSSimon Schubert 		      bpenables[(int) b->enable_state]);
59305796c8dcSSimon Schubert   ui_out_spaces (uiout, 2);
59315796c8dcSSimon Schubert 
59325796c8dcSSimon Schubert 
59335796c8dcSSimon Schubert   /* 5 and 6 */
59345796c8dcSSimon Schubert   if (b->ops != NULL && b->ops->print_one != NULL)
59355796c8dcSSimon Schubert     {
5936c50c785cSJohn Marino       /* Although the print_one can possibly print all locations,
5937c50c785cSJohn Marino 	 calling it here is not likely to get any nice result.  So,
5938c50c785cSJohn Marino 	 make sure there's just one location.  */
59395796c8dcSSimon Schubert       gdb_assert (b->loc == NULL || b->loc->next == NULL);
59405796c8dcSSimon Schubert       b->ops->print_one (b, last_loc);
59415796c8dcSSimon Schubert     }
59425796c8dcSSimon Schubert   else
59435796c8dcSSimon Schubert     switch (b->type)
59445796c8dcSSimon Schubert       {
59455796c8dcSSimon Schubert       case bp_none:
59465796c8dcSSimon Schubert 	internal_error (__FILE__, __LINE__,
59475796c8dcSSimon Schubert 			_("print_one_breakpoint: bp_none encountered\n"));
59485796c8dcSSimon Schubert 	break;
59495796c8dcSSimon Schubert 
59505796c8dcSSimon Schubert       case bp_watchpoint:
59515796c8dcSSimon Schubert       case bp_hardware_watchpoint:
59525796c8dcSSimon Schubert       case bp_read_watchpoint:
59535796c8dcSSimon Schubert       case bp_access_watchpoint:
5954a45ae5f8SJohn Marino 	{
5955a45ae5f8SJohn Marino 	  struct watchpoint *w = (struct watchpoint *) b;
5956a45ae5f8SJohn Marino 
59575796c8dcSSimon Schubert 	  /* Field 4, the address, is omitted (which makes the columns
59585796c8dcSSimon Schubert 	     not line up too nicely with the headers, but the effect
59595796c8dcSSimon Schubert 	     is relatively readable).  */
59605796c8dcSSimon Schubert 	  if (opts.addressprint)
59615796c8dcSSimon Schubert 	    ui_out_field_skip (uiout, "addr");
59625796c8dcSSimon Schubert 	  annotate_field (5);
5963a45ae5f8SJohn Marino 	  ui_out_field_string (uiout, "what", w->exp_string);
5964a45ae5f8SJohn Marino 	}
59655796c8dcSSimon Schubert 	break;
59665796c8dcSSimon Schubert 
59675796c8dcSSimon Schubert       case bp_breakpoint:
59685796c8dcSSimon Schubert       case bp_hardware_breakpoint:
59695796c8dcSSimon Schubert       case bp_until:
59705796c8dcSSimon Schubert       case bp_finish:
59715796c8dcSSimon Schubert       case bp_longjmp:
59725796c8dcSSimon Schubert       case bp_longjmp_resume:
5973*ef5ccd6cSJohn Marino       case bp_longjmp_call_dummy:
5974c50c785cSJohn Marino       case bp_exception:
5975c50c785cSJohn Marino       case bp_exception_resume:
59765796c8dcSSimon Schubert       case bp_step_resume:
5977a45ae5f8SJohn Marino       case bp_hp_step_resume:
59785796c8dcSSimon Schubert       case bp_watchpoint_scope:
59795796c8dcSSimon Schubert       case bp_call_dummy:
5980cf7f2e2dSJohn Marino       case bp_std_terminate:
59815796c8dcSSimon Schubert       case bp_shlib_event:
59825796c8dcSSimon Schubert       case bp_thread_event:
59835796c8dcSSimon Schubert       case bp_overlay_event:
59845796c8dcSSimon Schubert       case bp_longjmp_master:
5985cf7f2e2dSJohn Marino       case bp_std_terminate_master:
5986c50c785cSJohn Marino       case bp_exception_master:
59875796c8dcSSimon Schubert       case bp_tracepoint:
5988cf7f2e2dSJohn Marino       case bp_fast_tracepoint:
5989cf7f2e2dSJohn Marino       case bp_static_tracepoint:
5990*ef5ccd6cSJohn Marino       case bp_dprintf:
59915796c8dcSSimon Schubert       case bp_jit_event:
5992c50c785cSJohn Marino       case bp_gnu_ifunc_resolver:
5993c50c785cSJohn Marino       case bp_gnu_ifunc_resolver_return:
59945796c8dcSSimon Schubert 	if (opts.addressprint)
59955796c8dcSSimon Schubert 	  {
59965796c8dcSSimon Schubert 	    annotate_field (4);
59975796c8dcSSimon Schubert 	    if (header_of_multiple)
59985796c8dcSSimon Schubert 	      ui_out_field_string (uiout, "addr", "<MULTIPLE>");
59995796c8dcSSimon Schubert 	    else if (b->loc == NULL || loc->shlib_disabled)
60005796c8dcSSimon Schubert 	      ui_out_field_string (uiout, "addr", "<PENDING>");
60015796c8dcSSimon Schubert 	    else
60025796c8dcSSimon Schubert 	      ui_out_field_core_addr (uiout, "addr",
60035796c8dcSSimon Schubert 				      loc->gdbarch, loc->address);
60045796c8dcSSimon Schubert 	  }
60055796c8dcSSimon Schubert 	annotate_field (5);
60065796c8dcSSimon Schubert 	if (!header_of_multiple)
6007c50c785cSJohn Marino 	  print_breakpoint_location (b, loc);
60085796c8dcSSimon Schubert 	if (b->loc)
60095796c8dcSSimon Schubert 	  *last_loc = b->loc;
60105796c8dcSSimon Schubert 	break;
60115796c8dcSSimon Schubert       }
60125796c8dcSSimon Schubert 
6013cf7f2e2dSJohn Marino 
6014*ef5ccd6cSJohn Marino   if (loc != NULL && !header_of_multiple)
6015*ef5ccd6cSJohn Marino     {
6016*ef5ccd6cSJohn Marino       struct inferior *inf;
6017*ef5ccd6cSJohn Marino       VEC(int) *inf_num = NULL;
6018*ef5ccd6cSJohn Marino       int mi_only = 1;
6019*ef5ccd6cSJohn Marino 
6020*ef5ccd6cSJohn Marino       ALL_INFERIORS (inf)
6021*ef5ccd6cSJohn Marino 	{
6022*ef5ccd6cSJohn Marino 	  if (inf->pspace == loc->pspace)
6023*ef5ccd6cSJohn Marino 	    VEC_safe_push (int, inf_num, inf->num);
6024*ef5ccd6cSJohn Marino 	}
6025*ef5ccd6cSJohn Marino 
6026*ef5ccd6cSJohn Marino         /* For backward compatibility, don't display inferiors in CLI unless
6027*ef5ccd6cSJohn Marino 	   there are several.  Always display for MI. */
6028*ef5ccd6cSJohn Marino 	if (allflag
6029*ef5ccd6cSJohn Marino 	    || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6030cf7f2e2dSJohn Marino 		&& (number_of_program_spaces () > 1
6031cf7f2e2dSJohn Marino 		    || number_of_inferiors () > 1)
6032c50c785cSJohn Marino 		/* LOC is for existing B, it cannot be in
6033c50c785cSJohn Marino 		   moribund_locations and thus having NULL OWNER.  */
6034*ef5ccd6cSJohn Marino 		&& loc->owner->type != bp_catchpoint))
6035*ef5ccd6cSJohn Marino 	mi_only = 0;
6036*ef5ccd6cSJohn Marino       output_thread_groups (uiout, "thread-groups", inf_num, mi_only);
6037*ef5ccd6cSJohn Marino       VEC_free (int, inf_num);
6038cf7f2e2dSJohn Marino     }
6039cf7f2e2dSJohn Marino 
60405796c8dcSSimon Schubert   if (!part_of_multiple)
60415796c8dcSSimon Schubert     {
60425796c8dcSSimon Schubert       if (b->thread != -1)
60435796c8dcSSimon Schubert 	{
60445796c8dcSSimon Schubert 	  /* FIXME: This seems to be redundant and lost here; see the
60455796c8dcSSimon Schubert 	     "stop only in" line a little further down.  */
60465796c8dcSSimon Schubert 	  ui_out_text (uiout, " thread ");
60475796c8dcSSimon Schubert 	  ui_out_field_int (uiout, "thread", b->thread);
60485796c8dcSSimon Schubert 	}
60495796c8dcSSimon Schubert       else if (b->task != 0)
60505796c8dcSSimon Schubert 	{
60515796c8dcSSimon Schubert 	  ui_out_text (uiout, " task ");
60525796c8dcSSimon Schubert 	  ui_out_field_int (uiout, "task", b->task);
60535796c8dcSSimon Schubert 	}
60545796c8dcSSimon Schubert     }
60555796c8dcSSimon Schubert 
60565796c8dcSSimon Schubert   ui_out_text (uiout, "\n");
60575796c8dcSSimon Schubert 
6058a45ae5f8SJohn Marino   if (!part_of_multiple)
6059c50c785cSJohn Marino     b->ops->print_one_detail (b, uiout);
6060c50c785cSJohn Marino 
60615796c8dcSSimon Schubert   if (part_of_multiple && frame_id_p (b->frame_id))
60625796c8dcSSimon Schubert     {
60635796c8dcSSimon Schubert       annotate_field (6);
60645796c8dcSSimon Schubert       ui_out_text (uiout, "\tstop only in stack frame at ");
6065a45ae5f8SJohn Marino       /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
60665796c8dcSSimon Schubert          the frame ID.  */
60675796c8dcSSimon Schubert       ui_out_field_core_addr (uiout, "frame",
60685796c8dcSSimon Schubert 			      b->gdbarch, b->frame_id.stack_addr);
60695796c8dcSSimon Schubert       ui_out_text (uiout, "\n");
60705796c8dcSSimon Schubert     }
60715796c8dcSSimon Schubert 
6072a45ae5f8SJohn Marino   if (!part_of_multiple && b->cond_string)
60735796c8dcSSimon Schubert     {
60745796c8dcSSimon Schubert       annotate_field (7);
6075cf7f2e2dSJohn Marino       if (is_tracepoint (b))
60765796c8dcSSimon Schubert 	ui_out_text (uiout, "\ttrace only if ");
60775796c8dcSSimon Schubert       else
60785796c8dcSSimon Schubert 	ui_out_text (uiout, "\tstop only if ");
60795796c8dcSSimon Schubert       ui_out_field_string (uiout, "cond", b->cond_string);
6080*ef5ccd6cSJohn Marino 
6081*ef5ccd6cSJohn Marino       /* Print whether the target is doing the breakpoint's condition
6082*ef5ccd6cSJohn Marino 	 evaluation.  If GDB is doing the evaluation, don't print anything.  */
6083*ef5ccd6cSJohn Marino       if (is_breakpoint (b)
6084*ef5ccd6cSJohn Marino 	  && breakpoint_condition_evaluation_mode ()
6085*ef5ccd6cSJohn Marino 	  == condition_evaluation_target)
6086*ef5ccd6cSJohn Marino 	{
6087*ef5ccd6cSJohn Marino 	  ui_out_text (uiout, " (");
6088*ef5ccd6cSJohn Marino 	  ui_out_field_string (uiout, "evaluated-by",
6089*ef5ccd6cSJohn Marino 			       bp_condition_evaluator (b));
6090*ef5ccd6cSJohn Marino 	  ui_out_text (uiout, " evals)");
6091*ef5ccd6cSJohn Marino 	}
60925796c8dcSSimon Schubert       ui_out_text (uiout, "\n");
60935796c8dcSSimon Schubert     }
60945796c8dcSSimon Schubert 
60955796c8dcSSimon Schubert   if (!part_of_multiple && b->thread != -1)
60965796c8dcSSimon Schubert     {
6097c50c785cSJohn Marino       /* FIXME should make an annotation for this.  */
60985796c8dcSSimon Schubert       ui_out_text (uiout, "\tstop only in thread ");
60995796c8dcSSimon Schubert       ui_out_field_int (uiout, "thread", b->thread);
61005796c8dcSSimon Schubert       ui_out_text (uiout, "\n");
61015796c8dcSSimon Schubert     }
61025796c8dcSSimon Schubert 
6103*ef5ccd6cSJohn Marino   if (!part_of_multiple)
6104*ef5ccd6cSJohn Marino     {
6105*ef5ccd6cSJohn Marino       if (b->hit_count)
61065796c8dcSSimon Schubert 	{
6107c50c785cSJohn Marino 	  /* FIXME should make an annotation for this.  */
6108*ef5ccd6cSJohn Marino 	  if (is_catchpoint (b))
61095796c8dcSSimon Schubert 	    ui_out_text (uiout, "\tcatchpoint");
6110a45ae5f8SJohn Marino 	  else if (is_tracepoint (b))
6111a45ae5f8SJohn Marino 	    ui_out_text (uiout, "\ttracepoint");
61125796c8dcSSimon Schubert 	  else
61135796c8dcSSimon Schubert 	    ui_out_text (uiout, "\tbreakpoint");
61145796c8dcSSimon Schubert 	  ui_out_text (uiout, " already hit ");
61155796c8dcSSimon Schubert 	  ui_out_field_int (uiout, "times", b->hit_count);
61165796c8dcSSimon Schubert 	  if (b->hit_count == 1)
61175796c8dcSSimon Schubert 	    ui_out_text (uiout, " time\n");
61185796c8dcSSimon Schubert 	  else
61195796c8dcSSimon Schubert 	    ui_out_text (uiout, " times\n");
61205796c8dcSSimon Schubert 	}
6121*ef5ccd6cSJohn Marino       else
6122*ef5ccd6cSJohn Marino 	{
6123*ef5ccd6cSJohn Marino 	  /* Output the count also if it is zero, but only if this is mi.  */
61245796c8dcSSimon Schubert 	  if (ui_out_is_mi_like_p (uiout))
61255796c8dcSSimon Schubert 	    ui_out_field_int (uiout, "times", b->hit_count);
6126*ef5ccd6cSJohn Marino 	}
6127*ef5ccd6cSJohn Marino     }
61285796c8dcSSimon Schubert 
61295796c8dcSSimon Schubert   if (!part_of_multiple && b->ignore_count)
61305796c8dcSSimon Schubert     {
61315796c8dcSSimon Schubert       annotate_field (8);
61325796c8dcSSimon Schubert       ui_out_text (uiout, "\tignore next ");
61335796c8dcSSimon Schubert       ui_out_field_int (uiout, "ignore", b->ignore_count);
61345796c8dcSSimon Schubert       ui_out_text (uiout, " hits\n");
61355796c8dcSSimon Schubert     }
61365796c8dcSSimon Schubert 
6137*ef5ccd6cSJohn Marino   /* Note that an enable count of 1 corresponds to "enable once"
6138*ef5ccd6cSJohn Marino      behavior, which is reported by the combination of enablement and
6139*ef5ccd6cSJohn Marino      disposition, so we don't need to mention it here.  */
6140*ef5ccd6cSJohn Marino   if (!part_of_multiple && b->enable_count > 1)
6141*ef5ccd6cSJohn Marino     {
6142*ef5ccd6cSJohn Marino       annotate_field (8);
6143*ef5ccd6cSJohn Marino       ui_out_text (uiout, "\tdisable after ");
6144*ef5ccd6cSJohn Marino       /* Tweak the wording to clarify that ignore and enable counts
6145*ef5ccd6cSJohn Marino 	 are distinct, and have additive effect.  */
6146*ef5ccd6cSJohn Marino       if (b->ignore_count)
6147*ef5ccd6cSJohn Marino 	ui_out_text (uiout, "additional ");
6148*ef5ccd6cSJohn Marino       else
6149*ef5ccd6cSJohn Marino 	ui_out_text (uiout, "next ");
6150*ef5ccd6cSJohn Marino       ui_out_field_int (uiout, "enable", b->enable_count);
6151*ef5ccd6cSJohn Marino       ui_out_text (uiout, " hits\n");
6152*ef5ccd6cSJohn Marino     }
6153*ef5ccd6cSJohn Marino 
6154a45ae5f8SJohn Marino   if (!part_of_multiple && is_tracepoint (b))
6155a45ae5f8SJohn Marino     {
6156a45ae5f8SJohn Marino       struct tracepoint *tp = (struct tracepoint *) b;
6157a45ae5f8SJohn Marino 
6158a45ae5f8SJohn Marino       if (tp->traceframe_usage)
6159a45ae5f8SJohn Marino 	{
6160a45ae5f8SJohn Marino 	  ui_out_text (uiout, "\ttrace buffer usage ");
6161a45ae5f8SJohn Marino 	  ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
6162a45ae5f8SJohn Marino 	  ui_out_text (uiout, " bytes\n");
6163a45ae5f8SJohn Marino 	}
6164a45ae5f8SJohn Marino     }
6165a45ae5f8SJohn Marino 
6166cf7f2e2dSJohn Marino   l = b->commands ? b->commands->commands : NULL;
61675796c8dcSSimon Schubert   if (!part_of_multiple && l)
61685796c8dcSSimon Schubert     {
61695796c8dcSSimon Schubert       struct cleanup *script_chain;
61705796c8dcSSimon Schubert 
61715796c8dcSSimon Schubert       annotate_field (9);
61725796c8dcSSimon Schubert       script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
61735796c8dcSSimon Schubert       print_command_lines (uiout, l, 4);
61745796c8dcSSimon Schubert       do_cleanups (script_chain);
61755796c8dcSSimon Schubert     }
61765796c8dcSSimon Schubert 
6177a45ae5f8SJohn Marino   if (is_tracepoint (b))
6178a45ae5f8SJohn Marino     {
6179a45ae5f8SJohn Marino       struct tracepoint *t = (struct tracepoint *) b;
6180a45ae5f8SJohn Marino 
6181a45ae5f8SJohn Marino       if (!part_of_multiple && t->pass_count)
61825796c8dcSSimon Schubert 	{
61835796c8dcSSimon Schubert 	  annotate_field (10);
61845796c8dcSSimon Schubert 	  ui_out_text (uiout, "\tpass count ");
6185a45ae5f8SJohn Marino 	  ui_out_field_int (uiout, "pass", t->pass_count);
61865796c8dcSSimon Schubert 	  ui_out_text (uiout, " \n");
61875796c8dcSSimon Schubert 	}
6188*ef5ccd6cSJohn Marino 
6189*ef5ccd6cSJohn Marino       /* Don't display it when tracepoint or tracepoint location is
6190*ef5ccd6cSJohn Marino 	 pending.   */
6191*ef5ccd6cSJohn Marino       if (!header_of_multiple && loc != NULL && !loc->shlib_disabled)
6192*ef5ccd6cSJohn Marino 	{
6193*ef5ccd6cSJohn Marino 	  annotate_field (11);
6194*ef5ccd6cSJohn Marino 
6195*ef5ccd6cSJohn Marino 	  if (ui_out_is_mi_like_p (uiout))
6196*ef5ccd6cSJohn Marino 	    ui_out_field_string (uiout, "installed",
6197*ef5ccd6cSJohn Marino 				 loc->inserted ? "y" : "n");
6198*ef5ccd6cSJohn Marino 	  else
6199*ef5ccd6cSJohn Marino 	    {
6200*ef5ccd6cSJohn Marino 	      if (loc->inserted)
6201*ef5ccd6cSJohn Marino 		ui_out_text (uiout, "\t");
6202*ef5ccd6cSJohn Marino 	      else
6203*ef5ccd6cSJohn Marino 		ui_out_text (uiout, "\tnot ");
6204*ef5ccd6cSJohn Marino 	      ui_out_text (uiout, "installed on target\n");
6205*ef5ccd6cSJohn Marino 	    }
6206*ef5ccd6cSJohn Marino 	}
6207a45ae5f8SJohn Marino     }
62085796c8dcSSimon Schubert 
62095796c8dcSSimon Schubert   if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
62105796c8dcSSimon Schubert     {
6211a45ae5f8SJohn Marino       if (is_watchpoint (b))
6212a45ae5f8SJohn Marino 	{
6213a45ae5f8SJohn Marino 	  struct watchpoint *w = (struct watchpoint *) b;
62145796c8dcSSimon Schubert 
6215a45ae5f8SJohn Marino 	  ui_out_field_string (uiout, "original-location", w->exp_string);
6216a45ae5f8SJohn Marino 	}
6217a45ae5f8SJohn Marino       else if (b->addr_string)
6218a45ae5f8SJohn Marino 	ui_out_field_string (uiout, "original-location", b->addr_string);
6219a45ae5f8SJohn Marino     }
62205796c8dcSSimon Schubert }
62215796c8dcSSimon Schubert 
62225796c8dcSSimon Schubert static void
print_one_breakpoint(struct breakpoint * b,struct bp_location ** last_loc,int allflag)62235796c8dcSSimon Schubert print_one_breakpoint (struct breakpoint *b,
6224c50c785cSJohn Marino 		      struct bp_location **last_loc,
6225cf7f2e2dSJohn Marino 		      int allflag)
62265796c8dcSSimon Schubert {
6227a45ae5f8SJohn Marino   struct cleanup *bkpt_chain;
6228a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
6229a45ae5f8SJohn Marino 
6230a45ae5f8SJohn Marino   bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
6231a45ae5f8SJohn Marino 
6232c50c785cSJohn Marino   print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
6233a45ae5f8SJohn Marino   do_cleanups (bkpt_chain);
62345796c8dcSSimon Schubert 
62355796c8dcSSimon Schubert   /* If this breakpoint has custom print function,
62365796c8dcSSimon Schubert      it's already printed.  Otherwise, print individual
62375796c8dcSSimon Schubert      locations, if any.  */
62385796c8dcSSimon Schubert   if (b->ops == NULL || b->ops->print_one == NULL)
62395796c8dcSSimon Schubert     {
6240c50c785cSJohn Marino       /* If breakpoint has a single location that is disabled, we
6241c50c785cSJohn Marino 	 print it as if it had several locations, since otherwise it's
6242c50c785cSJohn Marino 	 hard to represent "breakpoint enabled, location disabled"
62435796c8dcSSimon Schubert 	 situation.
6244c50c785cSJohn Marino 
6245c50c785cSJohn Marino 	 Note that while hardware watchpoints have several locations
6246c50c785cSJohn Marino 	 internally, that's not a property exposed to user.  */
62475796c8dcSSimon Schubert       if (b->loc
62485796c8dcSSimon Schubert 	  && !is_hardware_watchpoint (b)
6249a45ae5f8SJohn Marino 	  && (b->loc->next || !b->loc->enabled))
62505796c8dcSSimon Schubert 	{
62515796c8dcSSimon Schubert 	  struct bp_location *loc;
62525796c8dcSSimon Schubert 	  int n = 1;
6253a45ae5f8SJohn Marino 
62545796c8dcSSimon Schubert 	  for (loc = b->loc; loc; loc = loc->next, ++n)
6255a45ae5f8SJohn Marino 	    {
6256a45ae5f8SJohn Marino 	      struct cleanup *inner2 =
6257a45ae5f8SJohn Marino 		make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
6258c50c785cSJohn Marino 	      print_one_breakpoint_location (b, loc, n, last_loc, allflag);
6259a45ae5f8SJohn Marino 	      do_cleanups (inner2);
6260a45ae5f8SJohn Marino 	    }
62615796c8dcSSimon Schubert 	}
62625796c8dcSSimon Schubert     }
62635796c8dcSSimon Schubert }
62645796c8dcSSimon Schubert 
62655796c8dcSSimon Schubert static int
breakpoint_address_bits(struct breakpoint * b)62665796c8dcSSimon Schubert breakpoint_address_bits (struct breakpoint *b)
62675796c8dcSSimon Schubert {
62685796c8dcSSimon Schubert   int print_address_bits = 0;
62695796c8dcSSimon Schubert   struct bp_location *loc;
62705796c8dcSSimon Schubert 
62715796c8dcSSimon Schubert   for (loc = b->loc; loc; loc = loc->next)
62725796c8dcSSimon Schubert     {
6273cf7f2e2dSJohn Marino       int addr_bit;
6274cf7f2e2dSJohn Marino 
6275cf7f2e2dSJohn Marino       /* Software watchpoints that aren't watching memory don't have
6276cf7f2e2dSJohn Marino 	 an address to print.  */
6277cf7f2e2dSJohn Marino       if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
6278cf7f2e2dSJohn Marino 	continue;
6279cf7f2e2dSJohn Marino 
6280cf7f2e2dSJohn Marino       addr_bit = gdbarch_addr_bit (loc->gdbarch);
62815796c8dcSSimon Schubert       if (addr_bit > print_address_bits)
62825796c8dcSSimon Schubert 	print_address_bits = addr_bit;
62835796c8dcSSimon Schubert     }
62845796c8dcSSimon Schubert 
62855796c8dcSSimon Schubert   return print_address_bits;
62865796c8dcSSimon Schubert }
62875796c8dcSSimon Schubert 
62885796c8dcSSimon Schubert struct captured_breakpoint_query_args
62895796c8dcSSimon Schubert   {
62905796c8dcSSimon Schubert     int bnum;
62915796c8dcSSimon Schubert   };
62925796c8dcSSimon Schubert 
62935796c8dcSSimon Schubert static int
do_captured_breakpoint_query(struct ui_out * uiout,void * data)62945796c8dcSSimon Schubert do_captured_breakpoint_query (struct ui_out *uiout, void *data)
62955796c8dcSSimon Schubert {
62965796c8dcSSimon Schubert   struct captured_breakpoint_query_args *args = data;
62975796c8dcSSimon Schubert   struct breakpoint *b;
62985796c8dcSSimon Schubert   struct bp_location *dummy_loc = NULL;
6299cf7f2e2dSJohn Marino 
63005796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
63015796c8dcSSimon Schubert     {
63025796c8dcSSimon Schubert       if (args->bnum == b->number)
63035796c8dcSSimon Schubert 	{
6304c50c785cSJohn Marino 	  print_one_breakpoint (b, &dummy_loc, 0);
63055796c8dcSSimon Schubert 	  return GDB_RC_OK;
63065796c8dcSSimon Schubert 	}
63075796c8dcSSimon Schubert     }
63085796c8dcSSimon Schubert   return GDB_RC_NONE;
63095796c8dcSSimon Schubert }
63105796c8dcSSimon Schubert 
63115796c8dcSSimon Schubert enum gdb_rc
gdb_breakpoint_query(struct ui_out * uiout,int bnum,char ** error_message)6312c50c785cSJohn Marino gdb_breakpoint_query (struct ui_out *uiout, int bnum,
6313c50c785cSJohn Marino 		      char **error_message)
63145796c8dcSSimon Schubert {
63155796c8dcSSimon Schubert   struct captured_breakpoint_query_args args;
6316cf7f2e2dSJohn Marino 
63175796c8dcSSimon Schubert   args.bnum = bnum;
63185796c8dcSSimon Schubert   /* For the moment we don't trust print_one_breakpoint() to not throw
63195796c8dcSSimon Schubert      an error.  */
63205796c8dcSSimon Schubert   if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
63215796c8dcSSimon Schubert 				 error_message, RETURN_MASK_ALL) < 0)
63225796c8dcSSimon Schubert     return GDB_RC_FAIL;
63235796c8dcSSimon Schubert   else
63245796c8dcSSimon Schubert     return GDB_RC_OK;
63255796c8dcSSimon Schubert }
63265796c8dcSSimon Schubert 
6327c50c785cSJohn Marino /* Return true if this breakpoint was set by the user, false if it is
6328c50c785cSJohn Marino    internal or momentary.  */
6329c50c785cSJohn Marino 
6330c50c785cSJohn Marino int
user_breakpoint_p(struct breakpoint * b)6331c50c785cSJohn Marino user_breakpoint_p (struct breakpoint *b)
6332c50c785cSJohn Marino {
6333a45ae5f8SJohn Marino   return b->number > 0;
63345796c8dcSSimon Schubert }
63355796c8dcSSimon Schubert 
63365796c8dcSSimon Schubert /* Print information on user settable breakpoint (watchpoint, etc)
6337cf7f2e2dSJohn Marino    number BNUM.  If BNUM is -1 print all user-settable breakpoints.
6338cf7f2e2dSJohn Marino    If ALLFLAG is non-zero, include non-user-settable breakpoints.  If
6339cf7f2e2dSJohn Marino    FILTER is non-NULL, call it on each breakpoint and only include the
6340cf7f2e2dSJohn Marino    ones for which it returns non-zero.  Return the total number of
6341cf7f2e2dSJohn Marino    breakpoints listed.  */
63425796c8dcSSimon Schubert 
6343cf7f2e2dSJohn Marino static int
breakpoint_1(char * args,int allflag,int (* filter)(const struct breakpoint *))6344c50c785cSJohn Marino breakpoint_1 (char *args, int allflag,
6345c50c785cSJohn Marino 	      int (*filter) (const struct breakpoint *))
63465796c8dcSSimon Schubert {
63475796c8dcSSimon Schubert   struct breakpoint *b;
63485796c8dcSSimon Schubert   struct bp_location *last_loc = NULL;
63495796c8dcSSimon Schubert   int nr_printable_breakpoints;
63505796c8dcSSimon Schubert   struct cleanup *bkpttbl_chain;
63515796c8dcSSimon Schubert   struct value_print_options opts;
63525796c8dcSSimon Schubert   int print_address_bits = 0;
6353c50c785cSJohn Marino   int print_type_col_width = 14;
6354a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
63555796c8dcSSimon Schubert 
63565796c8dcSSimon Schubert   get_user_print_options (&opts);
63575796c8dcSSimon Schubert 
6358c50c785cSJohn Marino   /* Compute the number of rows in the table, as well as the size
6359c50c785cSJohn Marino      required for address fields.  */
63605796c8dcSSimon Schubert   nr_printable_breakpoints = 0;
63615796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
63625796c8dcSSimon Schubert     {
6363cf7f2e2dSJohn Marino       /* If we have a filter, only list the breakpoints it accepts.  */
6364cf7f2e2dSJohn Marino       if (filter && !filter (b))
6365cf7f2e2dSJohn Marino 	continue;
6366cf7f2e2dSJohn Marino 
6367c50c785cSJohn Marino       /* If we have an "args" string, it is a list of breakpoints to
6368c50c785cSJohn Marino 	 accept.  Skip the others.  */
6369c50c785cSJohn Marino       if (args != NULL && *args != '\0')
63705796c8dcSSimon Schubert 	{
6371c50c785cSJohn Marino 	  if (allflag && parse_and_eval_long (args) != b->number)
6372c50c785cSJohn Marino 	    continue;
6373c50c785cSJohn Marino 	  if (!allflag && !number_is_in_list (args, b->number))
6374c50c785cSJohn Marino 	    continue;
6375c50c785cSJohn Marino 	}
6376c50c785cSJohn Marino 
6377c50c785cSJohn Marino       if (allflag || user_breakpoint_p (b))
6378c50c785cSJohn Marino 	{
6379c50c785cSJohn Marino 	  int addr_bit, type_len;
6380c50c785cSJohn Marino 
6381c50c785cSJohn Marino 	  addr_bit = breakpoint_address_bits (b);
63825796c8dcSSimon Schubert 	  if (addr_bit > print_address_bits)
63835796c8dcSSimon Schubert 	    print_address_bits = addr_bit;
63845796c8dcSSimon Schubert 
6385c50c785cSJohn Marino 	  type_len = strlen (bptype_string (b->type));
6386c50c785cSJohn Marino 	  if (type_len > print_type_col_width)
6387c50c785cSJohn Marino 	    print_type_col_width = type_len;
6388c50c785cSJohn Marino 
63895796c8dcSSimon Schubert 	  nr_printable_breakpoints++;
63905796c8dcSSimon Schubert 	}
63915796c8dcSSimon Schubert     }
63925796c8dcSSimon Schubert 
63935796c8dcSSimon Schubert   if (opts.addressprint)
63945796c8dcSSimon Schubert     bkpttbl_chain
6395c50c785cSJohn Marino       = make_cleanup_ui_out_table_begin_end (uiout, 6,
6396c50c785cSJohn Marino 					     nr_printable_breakpoints,
63975796c8dcSSimon Schubert                                              "BreakpointTable");
63985796c8dcSSimon Schubert   else
63995796c8dcSSimon Schubert     bkpttbl_chain
6400c50c785cSJohn Marino       = make_cleanup_ui_out_table_begin_end (uiout, 5,
6401c50c785cSJohn Marino 					     nr_printable_breakpoints,
64025796c8dcSSimon Schubert                                              "BreakpointTable");
64035796c8dcSSimon Schubert 
64045796c8dcSSimon Schubert   if (nr_printable_breakpoints > 0)
64055796c8dcSSimon Schubert     annotate_breakpoints_headers ();
64065796c8dcSSimon Schubert   if (nr_printable_breakpoints > 0)
64075796c8dcSSimon Schubert     annotate_field (0);
64085796c8dcSSimon Schubert   ui_out_table_header (uiout, 7, ui_left, "number", "Num");	/* 1 */
64095796c8dcSSimon Schubert   if (nr_printable_breakpoints > 0)
64105796c8dcSSimon Schubert     annotate_field (1);
6411c50c785cSJohn Marino   ui_out_table_header (uiout, print_type_col_width, ui_left,
6412c50c785cSJohn Marino 		       "type", "Type");				/* 2 */
64135796c8dcSSimon Schubert   if (nr_printable_breakpoints > 0)
64145796c8dcSSimon Schubert     annotate_field (2);
64155796c8dcSSimon Schubert   ui_out_table_header (uiout, 4, ui_left, "disp", "Disp");	/* 3 */
64165796c8dcSSimon Schubert   if (nr_printable_breakpoints > 0)
64175796c8dcSSimon Schubert     annotate_field (3);
64185796c8dcSSimon Schubert   ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb");	/* 4 */
64195796c8dcSSimon Schubert   if (opts.addressprint)
64205796c8dcSSimon Schubert     {
64215796c8dcSSimon Schubert       if (nr_printable_breakpoints > 0)
64225796c8dcSSimon Schubert 	annotate_field (4);
64235796c8dcSSimon Schubert       if (print_address_bits <= 32)
6424c50c785cSJohn Marino 	ui_out_table_header (uiout, 10, ui_left,
6425c50c785cSJohn Marino 			     "addr", "Address");		/* 5 */
64265796c8dcSSimon Schubert       else
6427c50c785cSJohn Marino 	ui_out_table_header (uiout, 18, ui_left,
6428c50c785cSJohn Marino 			     "addr", "Address");		/* 5 */
64295796c8dcSSimon Schubert     }
64305796c8dcSSimon Schubert   if (nr_printable_breakpoints > 0)
64315796c8dcSSimon Schubert     annotate_field (5);
64325796c8dcSSimon Schubert   ui_out_table_header (uiout, 40, ui_noalign, "what", "What");	/* 6 */
64335796c8dcSSimon Schubert   ui_out_table_body (uiout);
64345796c8dcSSimon Schubert   if (nr_printable_breakpoints > 0)
64355796c8dcSSimon Schubert     annotate_breakpoints_table ();
64365796c8dcSSimon Schubert 
64375796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
6438cf7f2e2dSJohn Marino     {
6439cf7f2e2dSJohn Marino       QUIT;
6440cf7f2e2dSJohn Marino       /* If we have a filter, only list the breakpoints it accepts.  */
6441cf7f2e2dSJohn Marino       if (filter && !filter (b))
6442cf7f2e2dSJohn Marino 	continue;
6443cf7f2e2dSJohn Marino 
6444c50c785cSJohn Marino       /* If we have an "args" string, it is a list of breakpoints to
6445c50c785cSJohn Marino 	 accept.  Skip the others.  */
6446c50c785cSJohn Marino 
6447c50c785cSJohn Marino       if (args != NULL && *args != '\0')
6448c50c785cSJohn Marino 	{
6449c50c785cSJohn Marino 	  if (allflag)	/* maintenance info breakpoint */
6450c50c785cSJohn Marino 	    {
6451c50c785cSJohn Marino 	      if (parse_and_eval_long (args) != b->number)
6452c50c785cSJohn Marino 		continue;
6453c50c785cSJohn Marino 	    }
6454c50c785cSJohn Marino 	  else		/* all others */
6455c50c785cSJohn Marino 	    {
6456c50c785cSJohn Marino 	      if (!number_is_in_list (args, b->number))
6457c50c785cSJohn Marino 		continue;
6458c50c785cSJohn Marino 	    }
6459c50c785cSJohn Marino 	}
64605796c8dcSSimon Schubert       /* We only print out user settable breakpoints unless the
64615796c8dcSSimon Schubert 	 allflag is set.  */
6462c50c785cSJohn Marino       if (allflag || user_breakpoint_p (b))
6463c50c785cSJohn Marino 	print_one_breakpoint (b, &last_loc, allflag);
64645796c8dcSSimon Schubert     }
64655796c8dcSSimon Schubert 
64665796c8dcSSimon Schubert   do_cleanups (bkpttbl_chain);
64675796c8dcSSimon Schubert 
64685796c8dcSSimon Schubert   if (nr_printable_breakpoints == 0)
64695796c8dcSSimon Schubert     {
6470c50c785cSJohn Marino       /* If there's a filter, let the caller decide how to report
6471c50c785cSJohn Marino 	 empty list.  */
6472cf7f2e2dSJohn Marino       if (!filter)
6473cf7f2e2dSJohn Marino 	{
6474c50c785cSJohn Marino 	  if (args == NULL || *args == '\0')
64755796c8dcSSimon Schubert 	    ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
64765796c8dcSSimon Schubert 	  else
6477c50c785cSJohn Marino 	    ui_out_message (uiout, 0,
6478c50c785cSJohn Marino 			    "No breakpoint or watchpoint matching '%s'.\n",
6479c50c785cSJohn Marino 			    args);
64805796c8dcSSimon Schubert 	}
6481cf7f2e2dSJohn Marino     }
64825796c8dcSSimon Schubert   else
64835796c8dcSSimon Schubert     {
64845796c8dcSSimon Schubert       if (last_loc && !server_command)
64855796c8dcSSimon Schubert 	set_next_address (last_loc->gdbarch, last_loc->address);
64865796c8dcSSimon Schubert     }
64875796c8dcSSimon Schubert 
64885796c8dcSSimon Schubert   /* FIXME?  Should this be moved up so that it is only called when
64895796c8dcSSimon Schubert      there have been breakpoints? */
64905796c8dcSSimon Schubert   annotate_breakpoints_table_end ();
6491cf7f2e2dSJohn Marino 
6492cf7f2e2dSJohn Marino   return nr_printable_breakpoints;
6493cf7f2e2dSJohn Marino }
6494cf7f2e2dSJohn Marino 
6495cf7f2e2dSJohn Marino /* Display the value of default-collect in a way that is generally
6496cf7f2e2dSJohn Marino    compatible with the breakpoint list.  */
6497cf7f2e2dSJohn Marino 
6498cf7f2e2dSJohn Marino static void
default_collect_info(void)6499cf7f2e2dSJohn Marino default_collect_info (void)
6500cf7f2e2dSJohn Marino {
6501a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
6502a45ae5f8SJohn Marino 
6503cf7f2e2dSJohn Marino   /* If it has no value (which is frequently the case), say nothing; a
6504cf7f2e2dSJohn Marino      message like "No default-collect." gets in user's face when it's
6505cf7f2e2dSJohn Marino      not wanted.  */
6506cf7f2e2dSJohn Marino   if (!*default_collect)
6507cf7f2e2dSJohn Marino     return;
6508cf7f2e2dSJohn Marino 
6509cf7f2e2dSJohn Marino   /* The following phrase lines up nicely with per-tracepoint collect
6510cf7f2e2dSJohn Marino      actions.  */
6511cf7f2e2dSJohn Marino   ui_out_text (uiout, "default collect ");
6512cf7f2e2dSJohn Marino   ui_out_field_string (uiout, "default-collect", default_collect);
6513cf7f2e2dSJohn Marino   ui_out_text (uiout, " \n");
65145796c8dcSSimon Schubert }
65155796c8dcSSimon Schubert 
65165796c8dcSSimon Schubert static void
breakpoints_info(char * args,int from_tty)6517c50c785cSJohn Marino breakpoints_info (char *args, int from_tty)
65185796c8dcSSimon Schubert {
6519c50c785cSJohn Marino   breakpoint_1 (args, 0, NULL);
6520cf7f2e2dSJohn Marino 
6521cf7f2e2dSJohn Marino   default_collect_info ();
6522cf7f2e2dSJohn Marino }
6523cf7f2e2dSJohn Marino 
6524cf7f2e2dSJohn Marino static void
watchpoints_info(char * args,int from_tty)6525c50c785cSJohn Marino watchpoints_info (char *args, int from_tty)
6526cf7f2e2dSJohn Marino {
6527c50c785cSJohn Marino   int num_printed = breakpoint_1 (args, 0, is_watchpoint);
6528a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
6529cf7f2e2dSJohn Marino 
6530cf7f2e2dSJohn Marino   if (num_printed == 0)
6531cf7f2e2dSJohn Marino     {
6532c50c785cSJohn Marino       if (args == NULL || *args == '\0')
6533cf7f2e2dSJohn Marino 	ui_out_message (uiout, 0, "No watchpoints.\n");
6534cf7f2e2dSJohn Marino       else
6535c50c785cSJohn Marino 	ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
6536cf7f2e2dSJohn Marino     }
65375796c8dcSSimon Schubert }
65385796c8dcSSimon Schubert 
65395796c8dcSSimon Schubert static void
maintenance_info_breakpoints(char * args,int from_tty)6540c50c785cSJohn Marino maintenance_info_breakpoints (char *args, int from_tty)
65415796c8dcSSimon Schubert {
6542c50c785cSJohn Marino   breakpoint_1 (args, 1, NULL);
6543cf7f2e2dSJohn Marino 
6544cf7f2e2dSJohn Marino   default_collect_info ();
65455796c8dcSSimon Schubert }
65465796c8dcSSimon Schubert 
65475796c8dcSSimon Schubert static int
breakpoint_has_pc(struct breakpoint * b,struct program_space * pspace,CORE_ADDR pc,struct obj_section * section)65485796c8dcSSimon Schubert breakpoint_has_pc (struct breakpoint *b,
6549cf7f2e2dSJohn Marino 		   struct program_space *pspace,
65505796c8dcSSimon Schubert 		   CORE_ADDR pc, struct obj_section *section)
65515796c8dcSSimon Schubert {
65525796c8dcSSimon Schubert   struct bp_location *bl = b->loc;
6553cf7f2e2dSJohn Marino 
65545796c8dcSSimon Schubert   for (; bl; bl = bl->next)
65555796c8dcSSimon Schubert     {
6556cf7f2e2dSJohn Marino       if (bl->pspace == pspace
6557cf7f2e2dSJohn Marino 	  && bl->address == pc
65585796c8dcSSimon Schubert 	  && (!overlay_debugging || bl->section == section))
65595796c8dcSSimon Schubert 	return 1;
65605796c8dcSSimon Schubert     }
65615796c8dcSSimon Schubert   return 0;
65625796c8dcSSimon Schubert }
65635796c8dcSSimon Schubert 
6564a45ae5f8SJohn Marino /* Print a message describing any user-breakpoints set at PC.  This
6565cf7f2e2dSJohn Marino    concerns with logical breakpoints, so we match program spaces, not
6566cf7f2e2dSJohn Marino    address spaces.  */
65675796c8dcSSimon Schubert 
65685796c8dcSSimon Schubert static void
describe_other_breakpoints(struct gdbarch * gdbarch,struct program_space * pspace,CORE_ADDR pc,struct obj_section * section,int thread)6569cf7f2e2dSJohn Marino describe_other_breakpoints (struct gdbarch *gdbarch,
6570cf7f2e2dSJohn Marino 			    struct program_space *pspace, CORE_ADDR pc,
65715796c8dcSSimon Schubert 			    struct obj_section *section, int thread)
65725796c8dcSSimon Schubert {
65735796c8dcSSimon Schubert   int others = 0;
65745796c8dcSSimon Schubert   struct breakpoint *b;
65755796c8dcSSimon Schubert 
65765796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
6577a45ae5f8SJohn Marino     others += (user_breakpoint_p (b)
6578a45ae5f8SJohn Marino                && breakpoint_has_pc (b, pspace, pc, section));
65795796c8dcSSimon Schubert   if (others > 0)
65805796c8dcSSimon Schubert     {
65815796c8dcSSimon Schubert       if (others == 1)
65825796c8dcSSimon Schubert 	printf_filtered (_("Note: breakpoint "));
65835796c8dcSSimon Schubert       else /* if (others == ???) */
65845796c8dcSSimon Schubert 	printf_filtered (_("Note: breakpoints "));
65855796c8dcSSimon Schubert       ALL_BREAKPOINTS (b)
6586a45ae5f8SJohn Marino 	if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
65875796c8dcSSimon Schubert 	  {
65885796c8dcSSimon Schubert 	    others--;
65895796c8dcSSimon Schubert 	    printf_filtered ("%d", b->number);
65905796c8dcSSimon Schubert 	    if (b->thread == -1 && thread != -1)
65915796c8dcSSimon Schubert 	      printf_filtered (" (all threads)");
65925796c8dcSSimon Schubert 	    else if (b->thread != -1)
65935796c8dcSSimon Schubert 	      printf_filtered (" (thread %d)", b->thread);
65945796c8dcSSimon Schubert 	    printf_filtered ("%s%s ",
65955796c8dcSSimon Schubert 			     ((b->enable_state == bp_disabled
6596a45ae5f8SJohn Marino 			       || b->enable_state == bp_call_disabled)
65975796c8dcSSimon Schubert 			      ? " (disabled)"
65985796c8dcSSimon Schubert 			      : b->enable_state == bp_permanent
65995796c8dcSSimon Schubert 			      ? " (permanent)"
66005796c8dcSSimon Schubert 			      : ""),
66015796c8dcSSimon Schubert 			     (others > 1) ? ","
66025796c8dcSSimon Schubert 			     : ((others == 1) ? " and" : ""));
66035796c8dcSSimon Schubert 	  }
66045796c8dcSSimon Schubert       printf_filtered (_("also set at pc "));
66055796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
66065796c8dcSSimon Schubert       printf_filtered (".\n");
66075796c8dcSSimon Schubert     }
66085796c8dcSSimon Schubert }
66095796c8dcSSimon Schubert 
66105796c8dcSSimon Schubert 
66115796c8dcSSimon Schubert /* Return true iff it is meaningful to use the address member of
66125796c8dcSSimon Schubert    BPT.  For some breakpoint types, the address member is irrelevant
66135796c8dcSSimon Schubert    and it makes no sense to attempt to compare it to other addresses
66145796c8dcSSimon Schubert    (or use it for any other purpose either).
66155796c8dcSSimon Schubert 
6616c50c785cSJohn Marino    More specifically, each of the following breakpoint types will
6617c50c785cSJohn Marino    always have a zero valued address and we don't want to mark
6618c50c785cSJohn Marino    breakpoints of any of these types to be a duplicate of an actual
6619c50c785cSJohn Marino    breakpoint at address zero:
66205796c8dcSSimon Schubert 
66215796c8dcSSimon Schubert       bp_watchpoint
6622cf7f2e2dSJohn Marino       bp_catchpoint
6623cf7f2e2dSJohn Marino 
6624cf7f2e2dSJohn Marino */
66255796c8dcSSimon Schubert 
66265796c8dcSSimon Schubert static int
breakpoint_address_is_meaningful(struct breakpoint * bpt)66275796c8dcSSimon Schubert breakpoint_address_is_meaningful (struct breakpoint *bpt)
66285796c8dcSSimon Schubert {
66295796c8dcSSimon Schubert   enum bptype type = bpt->type;
66305796c8dcSSimon Schubert 
6631cf7f2e2dSJohn Marino   return (type != bp_watchpoint && type != bp_catchpoint);
66325796c8dcSSimon Schubert }
66335796c8dcSSimon Schubert 
6634cf7f2e2dSJohn Marino /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6635cf7f2e2dSJohn Marino    true if LOC1 and LOC2 represent the same watchpoint location.  */
66365796c8dcSSimon Schubert 
6637cf7f2e2dSJohn Marino static int
watchpoint_locations_match(struct bp_location * loc1,struct bp_location * loc2)6638c50c785cSJohn Marino watchpoint_locations_match (struct bp_location *loc1,
6639c50c785cSJohn Marino 			    struct bp_location *loc2)
66405796c8dcSSimon Schubert {
6641a45ae5f8SJohn Marino   struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6642a45ae5f8SJohn Marino   struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6643a45ae5f8SJohn Marino 
6644a45ae5f8SJohn Marino   /* Both of them must exist.  */
6645a45ae5f8SJohn Marino   gdb_assert (w1 != NULL);
6646a45ae5f8SJohn Marino   gdb_assert (w2 != NULL);
66475796c8dcSSimon Schubert 
6648c50c785cSJohn Marino   /* If the target can evaluate the condition expression in hardware,
6649c50c785cSJohn Marino      then we we need to insert both watchpoints even if they are at
6650c50c785cSJohn Marino      the same place.  Otherwise the watchpoint will only trigger when
6651c50c785cSJohn Marino      the condition of whichever watchpoint was inserted evaluates to
6652c50c785cSJohn Marino      true, not giving a chance for GDB to check the condition of the
6653c50c785cSJohn Marino      other watchpoint.  */
6654a45ae5f8SJohn Marino   if ((w1->cond_exp
6655c50c785cSJohn Marino        && target_can_accel_watchpoint_condition (loc1->address,
6656c50c785cSJohn Marino 						 loc1->length,
6657cf7f2e2dSJohn Marino 						 loc1->watchpoint_type,
6658a45ae5f8SJohn Marino 						 w1->cond_exp))
6659a45ae5f8SJohn Marino       || (w2->cond_exp
6660c50c785cSJohn Marino 	  && target_can_accel_watchpoint_condition (loc2->address,
6661c50c785cSJohn Marino 						    loc2->length,
6662cf7f2e2dSJohn Marino 						    loc2->watchpoint_type,
6663a45ae5f8SJohn Marino 						    w2->cond_exp)))
6664cf7f2e2dSJohn Marino     return 0;
6665cf7f2e2dSJohn Marino 
6666cf7f2e2dSJohn Marino   /* Note that this checks the owner's type, not the location's.  In
6667cf7f2e2dSJohn Marino      case the target does not support read watchpoints, but does
6668cf7f2e2dSJohn Marino      support access watchpoints, we'll have bp_read_watchpoint
6669cf7f2e2dSJohn Marino      watchpoints with hw_access locations.  Those should be considered
6670cf7f2e2dSJohn Marino      duplicates of hw_read locations.  The hw_read locations will
6671cf7f2e2dSJohn Marino      become hw_access locations later.  */
6672cf7f2e2dSJohn Marino   return (loc1->owner->type == loc2->owner->type
6673cf7f2e2dSJohn Marino 	  && loc1->pspace->aspace == loc2->pspace->aspace
6674cf7f2e2dSJohn Marino 	  && loc1->address == loc2->address
6675cf7f2e2dSJohn Marino 	  && loc1->length == loc2->length);
66765796c8dcSSimon Schubert }
66775796c8dcSSimon Schubert 
6678cf7f2e2dSJohn Marino /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6679cf7f2e2dSJohn Marino    same breakpoint location.  In most targets, this can only be true
6680cf7f2e2dSJohn Marino    if ASPACE1 matches ASPACE2.  On targets that have global
6681cf7f2e2dSJohn Marino    breakpoints, the address space doesn't really matter.  */
66825796c8dcSSimon Schubert 
6683cf7f2e2dSJohn Marino static int
breakpoint_address_match(struct address_space * aspace1,CORE_ADDR addr1,struct address_space * aspace2,CORE_ADDR addr2)6684cf7f2e2dSJohn Marino breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6685cf7f2e2dSJohn Marino 			  struct address_space *aspace2, CORE_ADDR addr2)
66865796c8dcSSimon Schubert {
6687*ef5ccd6cSJohn Marino   return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6688cf7f2e2dSJohn Marino 	   || aspace1 == aspace2)
6689cf7f2e2dSJohn Marino 	  && addr1 == addr2);
6690cf7f2e2dSJohn Marino }
66915796c8dcSSimon Schubert 
6692c50c785cSJohn Marino /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6693c50c785cSJohn Marino    {ASPACE1,ADDR1,LEN1}.  In most targets, this can only be true if ASPACE1
6694c50c785cSJohn Marino    matches ASPACE2.  On targets that have global breakpoints, the address
6695c50c785cSJohn Marino    space doesn't really matter.  */
6696c50c785cSJohn Marino 
6697c50c785cSJohn Marino static int
breakpoint_address_match_range(struct address_space * aspace1,CORE_ADDR addr1,int len1,struct address_space * aspace2,CORE_ADDR addr2)6698c50c785cSJohn Marino breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6699c50c785cSJohn Marino 				int len1, struct address_space *aspace2,
6700c50c785cSJohn Marino 				CORE_ADDR addr2)
6701c50c785cSJohn Marino {
6702*ef5ccd6cSJohn Marino   return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6703c50c785cSJohn Marino 	   || aspace1 == aspace2)
6704c50c785cSJohn Marino 	  && addr2 >= addr1 && addr2 < addr1 + len1);
6705c50c785cSJohn Marino }
6706c50c785cSJohn Marino 
6707c50c785cSJohn Marino /* Returns true if {ASPACE,ADDR} matches the breakpoint BL.  BL may be
6708c50c785cSJohn Marino    a ranged breakpoint.  In most targets, a match happens only if ASPACE
6709c50c785cSJohn Marino    matches the breakpoint's address space.  On targets that have global
6710c50c785cSJohn Marino    breakpoints, the address space doesn't really matter.  */
6711c50c785cSJohn Marino 
6712c50c785cSJohn Marino static int
breakpoint_location_address_match(struct bp_location * bl,struct address_space * aspace,CORE_ADDR addr)6713c50c785cSJohn Marino breakpoint_location_address_match (struct bp_location *bl,
6714c50c785cSJohn Marino 				   struct address_space *aspace,
6715c50c785cSJohn Marino 				   CORE_ADDR addr)
6716c50c785cSJohn Marino {
6717c50c785cSJohn Marino   return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6718c50c785cSJohn Marino 				    aspace, addr)
6719c50c785cSJohn Marino 	  || (bl->length
6720c50c785cSJohn Marino 	      && breakpoint_address_match_range (bl->pspace->aspace,
6721c50c785cSJohn Marino 						 bl->address, bl->length,
6722c50c785cSJohn Marino 						 aspace, addr)));
6723c50c785cSJohn Marino }
6724c50c785cSJohn Marino 
6725a45ae5f8SJohn Marino /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6726a45ae5f8SJohn Marino    Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6727a45ae5f8SJohn Marino    true, otherwise returns false.  */
6728a45ae5f8SJohn Marino 
6729a45ae5f8SJohn Marino static int
tracepoint_locations_match(struct bp_location * loc1,struct bp_location * loc2)6730a45ae5f8SJohn Marino tracepoint_locations_match (struct bp_location *loc1,
6731a45ae5f8SJohn Marino 			    struct bp_location *loc2)
6732a45ae5f8SJohn Marino {
6733a45ae5f8SJohn Marino   if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6734a45ae5f8SJohn Marino     /* Since tracepoint locations are never duplicated with others', tracepoint
6735a45ae5f8SJohn Marino        locations at the same address of different tracepoints are regarded as
6736a45ae5f8SJohn Marino        different locations.  */
6737a45ae5f8SJohn Marino     return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6738a45ae5f8SJohn Marino   else
6739a45ae5f8SJohn Marino     return 0;
6740a45ae5f8SJohn Marino }
6741a45ae5f8SJohn Marino 
6742cf7f2e2dSJohn Marino /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6743cf7f2e2dSJohn Marino    (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6744cf7f2e2dSJohn Marino    represent the same location.  */
67455796c8dcSSimon Schubert 
6746cf7f2e2dSJohn Marino static int
breakpoint_locations_match(struct bp_location * loc1,struct bp_location * loc2)6747c50c785cSJohn Marino breakpoint_locations_match (struct bp_location *loc1,
6748c50c785cSJohn Marino 			    struct bp_location *loc2)
67495796c8dcSSimon Schubert {
6750cf7f2e2dSJohn Marino   int hw_point1, hw_point2;
67515796c8dcSSimon Schubert 
6752cf7f2e2dSJohn Marino   /* Both of them must not be in moribund_locations.  */
6753cf7f2e2dSJohn Marino   gdb_assert (loc1->owner != NULL);
6754cf7f2e2dSJohn Marino   gdb_assert (loc2->owner != NULL);
67555796c8dcSSimon Schubert 
6756cf7f2e2dSJohn Marino   hw_point1 = is_hardware_watchpoint (loc1->owner);
6757cf7f2e2dSJohn Marino   hw_point2 = is_hardware_watchpoint (loc2->owner);
67585796c8dcSSimon Schubert 
6759cf7f2e2dSJohn Marino   if (hw_point1 != hw_point2)
6760cf7f2e2dSJohn Marino     return 0;
6761cf7f2e2dSJohn Marino   else if (hw_point1)
6762cf7f2e2dSJohn Marino     return watchpoint_locations_match (loc1, loc2);
6763a45ae5f8SJohn Marino   else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6764a45ae5f8SJohn Marino     return tracepoint_locations_match (loc1, loc2);
6765cf7f2e2dSJohn Marino   else
6766c50c785cSJohn Marino     /* We compare bp_location.length in order to cover ranged breakpoints.  */
6767c50c785cSJohn Marino     return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6768c50c785cSJohn Marino 				     loc2->pspace->aspace, loc2->address)
6769c50c785cSJohn Marino 	    && loc1->length == loc2->length);
67705796c8dcSSimon Schubert }
67715796c8dcSSimon Schubert 
67725796c8dcSSimon Schubert static void
breakpoint_adjustment_warning(CORE_ADDR from_addr,CORE_ADDR to_addr,int bnum,int have_bnum)67735796c8dcSSimon Schubert breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
67745796c8dcSSimon Schubert                                int bnum, int have_bnum)
67755796c8dcSSimon Schubert {
6776c50c785cSJohn Marino   /* The longest string possibly returned by hex_string_custom
6777c50c785cSJohn Marino      is 50 chars.  These must be at least that big for safety.  */
6778c50c785cSJohn Marino   char astr1[64];
6779c50c785cSJohn Marino   char astr2[64];
67805796c8dcSSimon Schubert 
67815796c8dcSSimon Schubert   strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
67825796c8dcSSimon Schubert   strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
67835796c8dcSSimon Schubert   if (have_bnum)
67845796c8dcSSimon Schubert     warning (_("Breakpoint %d address previously adjusted from %s to %s."),
67855796c8dcSSimon Schubert              bnum, astr1, astr2);
67865796c8dcSSimon Schubert   else
67875796c8dcSSimon Schubert     warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
67885796c8dcSSimon Schubert }
67895796c8dcSSimon Schubert 
6790c50c785cSJohn Marino /* Adjust a breakpoint's address to account for architectural
6791c50c785cSJohn Marino    constraints on breakpoint placement.  Return the adjusted address.
6792c50c785cSJohn Marino    Note: Very few targets require this kind of adjustment.  For most
6793c50c785cSJohn Marino    targets, this function is simply the identity function.  */
67945796c8dcSSimon Schubert 
67955796c8dcSSimon Schubert static CORE_ADDR
adjust_breakpoint_address(struct gdbarch * gdbarch,CORE_ADDR bpaddr,enum bptype bptype)67965796c8dcSSimon Schubert adjust_breakpoint_address (struct gdbarch *gdbarch,
67975796c8dcSSimon Schubert 			   CORE_ADDR bpaddr, enum bptype bptype)
67985796c8dcSSimon Schubert {
67995796c8dcSSimon Schubert   if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
68005796c8dcSSimon Schubert     {
68015796c8dcSSimon Schubert       /* Very few targets need any kind of breakpoint adjustment.  */
68025796c8dcSSimon Schubert       return bpaddr;
68035796c8dcSSimon Schubert     }
68045796c8dcSSimon Schubert   else if (bptype == bp_watchpoint
68055796c8dcSSimon Schubert            || bptype == bp_hardware_watchpoint
68065796c8dcSSimon Schubert            || bptype == bp_read_watchpoint
68075796c8dcSSimon Schubert            || bptype == bp_access_watchpoint
68085796c8dcSSimon Schubert            || bptype == bp_catchpoint)
68095796c8dcSSimon Schubert     {
68105796c8dcSSimon Schubert       /* Watchpoints and the various bp_catch_* eventpoints should not
68115796c8dcSSimon Schubert          have their addresses modified.  */
68125796c8dcSSimon Schubert       return bpaddr;
68135796c8dcSSimon Schubert     }
68145796c8dcSSimon Schubert   else
68155796c8dcSSimon Schubert     {
68165796c8dcSSimon Schubert       CORE_ADDR adjusted_bpaddr;
68175796c8dcSSimon Schubert 
68185796c8dcSSimon Schubert       /* Some targets have architectural constraints on the placement
68195796c8dcSSimon Schubert          of breakpoint instructions.  Obtain the adjusted address.  */
68205796c8dcSSimon Schubert       adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
68215796c8dcSSimon Schubert 
68225796c8dcSSimon Schubert       /* An adjusted breakpoint address can significantly alter
68235796c8dcSSimon Schubert          a user's expectations.  Print a warning if an adjustment
68245796c8dcSSimon Schubert 	 is required.  */
68255796c8dcSSimon Schubert       if (adjusted_bpaddr != bpaddr)
68265796c8dcSSimon Schubert 	breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
68275796c8dcSSimon Schubert 
68285796c8dcSSimon Schubert       return adjusted_bpaddr;
68295796c8dcSSimon Schubert     }
68305796c8dcSSimon Schubert }
68315796c8dcSSimon Schubert 
6832a45ae5f8SJohn Marino void
init_bp_location(struct bp_location * loc,const struct bp_location_ops * ops,struct breakpoint * owner)6833a45ae5f8SJohn Marino init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6834a45ae5f8SJohn Marino 		  struct breakpoint *owner)
68355796c8dcSSimon Schubert {
68365796c8dcSSimon Schubert   memset (loc, 0, sizeof (*loc));
68375796c8dcSSimon Schubert 
6838a45ae5f8SJohn Marino   gdb_assert (ops != NULL);
6839a45ae5f8SJohn Marino 
6840a45ae5f8SJohn Marino   loc->ops = ops;
6841a45ae5f8SJohn Marino   loc->owner = owner;
68425796c8dcSSimon Schubert   loc->cond = NULL;
6843*ef5ccd6cSJohn Marino   loc->cond_bytecode = NULL;
68445796c8dcSSimon Schubert   loc->shlib_disabled = 0;
68455796c8dcSSimon Schubert   loc->enabled = 1;
68465796c8dcSSimon Schubert 
6847a45ae5f8SJohn Marino   switch (owner->type)
68485796c8dcSSimon Schubert     {
68495796c8dcSSimon Schubert     case bp_breakpoint:
68505796c8dcSSimon Schubert     case bp_until:
68515796c8dcSSimon Schubert     case bp_finish:
68525796c8dcSSimon Schubert     case bp_longjmp:
68535796c8dcSSimon Schubert     case bp_longjmp_resume:
6854*ef5ccd6cSJohn Marino     case bp_longjmp_call_dummy:
6855c50c785cSJohn Marino     case bp_exception:
6856c50c785cSJohn Marino     case bp_exception_resume:
68575796c8dcSSimon Schubert     case bp_step_resume:
6858a45ae5f8SJohn Marino     case bp_hp_step_resume:
68595796c8dcSSimon Schubert     case bp_watchpoint_scope:
68605796c8dcSSimon Schubert     case bp_call_dummy:
6861cf7f2e2dSJohn Marino     case bp_std_terminate:
68625796c8dcSSimon Schubert     case bp_shlib_event:
68635796c8dcSSimon Schubert     case bp_thread_event:
68645796c8dcSSimon Schubert     case bp_overlay_event:
68655796c8dcSSimon Schubert     case bp_jit_event:
68665796c8dcSSimon Schubert     case bp_longjmp_master:
6867cf7f2e2dSJohn Marino     case bp_std_terminate_master:
6868c50c785cSJohn Marino     case bp_exception_master:
6869c50c785cSJohn Marino     case bp_gnu_ifunc_resolver:
6870c50c785cSJohn Marino     case bp_gnu_ifunc_resolver_return:
6871*ef5ccd6cSJohn Marino     case bp_dprintf:
68725796c8dcSSimon Schubert       loc->loc_type = bp_loc_software_breakpoint;
6873*ef5ccd6cSJohn Marino       mark_breakpoint_location_modified (loc);
68745796c8dcSSimon Schubert       break;
68755796c8dcSSimon Schubert     case bp_hardware_breakpoint:
68765796c8dcSSimon Schubert       loc->loc_type = bp_loc_hardware_breakpoint;
6877*ef5ccd6cSJohn Marino       mark_breakpoint_location_modified (loc);
68785796c8dcSSimon Schubert       break;
68795796c8dcSSimon Schubert     case bp_hardware_watchpoint:
68805796c8dcSSimon Schubert     case bp_read_watchpoint:
68815796c8dcSSimon Schubert     case bp_access_watchpoint:
68825796c8dcSSimon Schubert       loc->loc_type = bp_loc_hardware_watchpoint;
68835796c8dcSSimon Schubert       break;
68845796c8dcSSimon Schubert     case bp_watchpoint:
68855796c8dcSSimon Schubert     case bp_catchpoint:
6886cf7f2e2dSJohn Marino     case bp_tracepoint:
6887cf7f2e2dSJohn Marino     case bp_fast_tracepoint:
6888cf7f2e2dSJohn Marino     case bp_static_tracepoint:
68895796c8dcSSimon Schubert       loc->loc_type = bp_loc_other;
68905796c8dcSSimon Schubert       break;
68915796c8dcSSimon Schubert     default:
68925796c8dcSSimon Schubert       internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
68935796c8dcSSimon Schubert     }
68945796c8dcSSimon Schubert 
6895c50c785cSJohn Marino   loc->refc = 1;
6896a45ae5f8SJohn Marino }
6897a45ae5f8SJohn Marino 
6898a45ae5f8SJohn Marino /* Allocate a struct bp_location.  */
6899a45ae5f8SJohn Marino 
6900a45ae5f8SJohn Marino static struct bp_location *
allocate_bp_location(struct breakpoint * bpt)6901a45ae5f8SJohn Marino allocate_bp_location (struct breakpoint *bpt)
6902a45ae5f8SJohn Marino {
6903a45ae5f8SJohn Marino   return bpt->ops->allocate_location (bpt);
69045796c8dcSSimon Schubert }
69055796c8dcSSimon Schubert 
6906c50c785cSJohn Marino static void
free_bp_location(struct bp_location * loc)6907c50c785cSJohn Marino free_bp_location (struct bp_location *loc)
69085796c8dcSSimon Schubert {
6909a45ae5f8SJohn Marino   loc->ops->dtor (loc);
69105796c8dcSSimon Schubert   xfree (loc);
69115796c8dcSSimon Schubert }
69125796c8dcSSimon Schubert 
6913c50c785cSJohn Marino /* Increment reference count.  */
6914c50c785cSJohn Marino 
6915c50c785cSJohn Marino static void
incref_bp_location(struct bp_location * bl)6916c50c785cSJohn Marino incref_bp_location (struct bp_location *bl)
6917c50c785cSJohn Marino {
6918c50c785cSJohn Marino   ++bl->refc;
6919c50c785cSJohn Marino }
6920c50c785cSJohn Marino 
6921c50c785cSJohn Marino /* Decrement reference count.  If the reference count reaches 0,
6922c50c785cSJohn Marino    destroy the bp_location.  Sets *BLP to NULL.  */
6923c50c785cSJohn Marino 
6924c50c785cSJohn Marino static void
decref_bp_location(struct bp_location ** blp)6925c50c785cSJohn Marino decref_bp_location (struct bp_location **blp)
6926c50c785cSJohn Marino {
6927c50c785cSJohn Marino   gdb_assert ((*blp)->refc > 0);
6928c50c785cSJohn Marino 
6929c50c785cSJohn Marino   if (--(*blp)->refc == 0)
6930c50c785cSJohn Marino     free_bp_location (*blp);
6931c50c785cSJohn Marino   *blp = NULL;
6932c50c785cSJohn Marino }
6933c50c785cSJohn Marino 
6934a45ae5f8SJohn Marino /* Add breakpoint B at the end of the global breakpoint chain.  */
69355796c8dcSSimon Schubert 
6936a45ae5f8SJohn Marino static void
add_to_breakpoint_chain(struct breakpoint * b)6937a45ae5f8SJohn Marino add_to_breakpoint_chain (struct breakpoint *b)
69385796c8dcSSimon Schubert {
6939a45ae5f8SJohn Marino   struct breakpoint *b1;
69405796c8dcSSimon Schubert 
6941c50c785cSJohn Marino   /* Add this breakpoint to the end of the chain so that a list of
6942c50c785cSJohn Marino      breakpoints will come out in order of increasing numbers.  */
69435796c8dcSSimon Schubert 
69445796c8dcSSimon Schubert   b1 = breakpoint_chain;
69455796c8dcSSimon Schubert   if (b1 == 0)
69465796c8dcSSimon Schubert     breakpoint_chain = b;
69475796c8dcSSimon Schubert   else
69485796c8dcSSimon Schubert     {
69495796c8dcSSimon Schubert       while (b1->next)
69505796c8dcSSimon Schubert 	b1 = b1->next;
69515796c8dcSSimon Schubert       b1->next = b;
69525796c8dcSSimon Schubert     }
6953a45ae5f8SJohn Marino }
6954a45ae5f8SJohn Marino 
6955a45ae5f8SJohn Marino /* Initializes breakpoint B with type BPTYPE and no locations yet.  */
6956a45ae5f8SJohn Marino 
6957a45ae5f8SJohn Marino static void
init_raw_breakpoint_without_location(struct breakpoint * b,struct gdbarch * gdbarch,enum bptype bptype,const struct breakpoint_ops * ops)6958a45ae5f8SJohn Marino init_raw_breakpoint_without_location (struct breakpoint *b,
6959a45ae5f8SJohn Marino 				      struct gdbarch *gdbarch,
6960a45ae5f8SJohn Marino 				      enum bptype bptype,
6961a45ae5f8SJohn Marino 				      const struct breakpoint_ops *ops)
6962a45ae5f8SJohn Marino {
6963a45ae5f8SJohn Marino   memset (b, 0, sizeof (*b));
6964a45ae5f8SJohn Marino 
6965a45ae5f8SJohn Marino   gdb_assert (ops != NULL);
6966a45ae5f8SJohn Marino 
6967a45ae5f8SJohn Marino   b->ops = ops;
6968a45ae5f8SJohn Marino   b->type = bptype;
6969a45ae5f8SJohn Marino   b->gdbarch = gdbarch;
6970a45ae5f8SJohn Marino   b->language = current_language->la_language;
6971a45ae5f8SJohn Marino   b->input_radix = input_radix;
6972a45ae5f8SJohn Marino   b->thread = -1;
6973a45ae5f8SJohn Marino   b->enable_state = bp_enabled;
6974a45ae5f8SJohn Marino   b->next = 0;
6975a45ae5f8SJohn Marino   b->silent = 0;
6976a45ae5f8SJohn Marino   b->ignore_count = 0;
6977a45ae5f8SJohn Marino   b->commands = NULL;
6978a45ae5f8SJohn Marino   b->frame_id = null_frame_id;
6979a45ae5f8SJohn Marino   b->condition_not_parsed = 0;
6980a45ae5f8SJohn Marino   b->py_bp_object = NULL;
6981a45ae5f8SJohn Marino   b->related_breakpoint = b;
6982a45ae5f8SJohn Marino }
6983a45ae5f8SJohn Marino 
6984a45ae5f8SJohn Marino /* Helper to set_raw_breakpoint below.  Creates a breakpoint
6985a45ae5f8SJohn Marino    that has type BPTYPE and has no locations as yet.  */
6986a45ae5f8SJohn Marino 
6987a45ae5f8SJohn Marino static struct breakpoint *
set_raw_breakpoint_without_location(struct gdbarch * gdbarch,enum bptype bptype,const struct breakpoint_ops * ops)6988a45ae5f8SJohn Marino set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
6989a45ae5f8SJohn Marino 				     enum bptype bptype,
6990a45ae5f8SJohn Marino 				     const struct breakpoint_ops *ops)
6991a45ae5f8SJohn Marino {
6992a45ae5f8SJohn Marino   struct breakpoint *b = XNEW (struct breakpoint);
6993a45ae5f8SJohn Marino 
6994a45ae5f8SJohn Marino   init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
6995a45ae5f8SJohn Marino   add_to_breakpoint_chain (b);
69965796c8dcSSimon Schubert   return b;
69975796c8dcSSimon Schubert }
69985796c8dcSSimon Schubert 
6999c50c785cSJohn Marino /* Initialize loc->function_name.  EXPLICIT_LOC says no indirect function
7000c50c785cSJohn Marino    resolutions should be made as the user specified the location explicitly
7001c50c785cSJohn Marino    enough.  */
7002c50c785cSJohn Marino 
70035796c8dcSSimon Schubert static void
set_breakpoint_location_function(struct bp_location * loc,int explicit_loc)7004c50c785cSJohn Marino set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
70055796c8dcSSimon Schubert {
7006cf7f2e2dSJohn Marino   gdb_assert (loc->owner != NULL);
7007cf7f2e2dSJohn Marino 
70085796c8dcSSimon Schubert   if (loc->owner->type == bp_breakpoint
70095796c8dcSSimon Schubert       || loc->owner->type == bp_hardware_breakpoint
7010cf7f2e2dSJohn Marino       || is_tracepoint (loc->owner))
70115796c8dcSSimon Schubert     {
7012c50c785cSJohn Marino       int is_gnu_ifunc;
7013*ef5ccd6cSJohn Marino       const char *function_name;
7014*ef5ccd6cSJohn Marino       CORE_ADDR func_addr;
7015c50c785cSJohn Marino 
7016*ef5ccd6cSJohn Marino       find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
7017*ef5ccd6cSJohn Marino 					  &func_addr, NULL, &is_gnu_ifunc);
7018c50c785cSJohn Marino 
7019c50c785cSJohn Marino       if (is_gnu_ifunc && !explicit_loc)
7020c50c785cSJohn Marino 	{
7021c50c785cSJohn Marino 	  struct breakpoint *b = loc->owner;
7022c50c785cSJohn Marino 
7023c50c785cSJohn Marino 	  gdb_assert (loc->pspace == current_program_space);
7024*ef5ccd6cSJohn Marino 	  if (gnu_ifunc_resolve_name (function_name,
7025c50c785cSJohn Marino 				      &loc->requested_address))
7026c50c785cSJohn Marino 	    {
7027c50c785cSJohn Marino 	      /* Recalculate ADDRESS based on new REQUESTED_ADDRESS.  */
7028c50c785cSJohn Marino 	      loc->address = adjust_breakpoint_address (loc->gdbarch,
7029c50c785cSJohn Marino 							loc->requested_address,
7030c50c785cSJohn Marino 							b->type);
7031c50c785cSJohn Marino 	    }
7032c50c785cSJohn Marino 	  else if (b->type == bp_breakpoint && b->loc == loc
7033c50c785cSJohn Marino 	           && loc->next == NULL && b->related_breakpoint == b)
7034c50c785cSJohn Marino 	    {
7035c50c785cSJohn Marino 	      /* Create only the whole new breakpoint of this type but do not
7036c50c785cSJohn Marino 		 mess more complicated breakpoints with multiple locations.  */
7037c50c785cSJohn Marino 	      b->type = bp_gnu_ifunc_resolver;
7038*ef5ccd6cSJohn Marino 	      /* Remember the resolver's address for use by the return
7039*ef5ccd6cSJohn Marino 	         breakpoint.  */
7040*ef5ccd6cSJohn Marino 	      loc->related_address = func_addr;
7041c50c785cSJohn Marino 	    }
7042c50c785cSJohn Marino 	}
7043c50c785cSJohn Marino 
7044*ef5ccd6cSJohn Marino       if (function_name)
7045*ef5ccd6cSJohn Marino 	loc->function_name = xstrdup (function_name);
70465796c8dcSSimon Schubert     }
70475796c8dcSSimon Schubert }
70485796c8dcSSimon Schubert 
70495796c8dcSSimon Schubert /* Attempt to determine architecture of location identified by SAL.  */
7050a45ae5f8SJohn Marino struct gdbarch *
get_sal_arch(struct symtab_and_line sal)70515796c8dcSSimon Schubert get_sal_arch (struct symtab_and_line sal)
70525796c8dcSSimon Schubert {
70535796c8dcSSimon Schubert   if (sal.section)
70545796c8dcSSimon Schubert     return get_objfile_arch (sal.section->objfile);
70555796c8dcSSimon Schubert   if (sal.symtab)
70565796c8dcSSimon Schubert     return get_objfile_arch (sal.symtab->objfile);
70575796c8dcSSimon Schubert 
70585796c8dcSSimon Schubert   return NULL;
70595796c8dcSSimon Schubert }
70605796c8dcSSimon Schubert 
7061a45ae5f8SJohn Marino /* Low level routine for partially initializing a breakpoint of type
7062a45ae5f8SJohn Marino    BPTYPE.  The newly created breakpoint's address, section, source
7063a45ae5f8SJohn Marino    file name, and line number are provided by SAL.
7064a45ae5f8SJohn Marino 
7065a45ae5f8SJohn Marino    It is expected that the caller will complete the initialization of
7066a45ae5f8SJohn Marino    the newly created breakpoint struct as well as output any status
7067a45ae5f8SJohn Marino    information regarding the creation of a new breakpoint.  */
7068a45ae5f8SJohn Marino 
7069a45ae5f8SJohn Marino static void
init_raw_breakpoint(struct breakpoint * b,struct gdbarch * gdbarch,struct symtab_and_line sal,enum bptype bptype,const struct breakpoint_ops * ops)7070a45ae5f8SJohn Marino init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
7071a45ae5f8SJohn Marino 		     struct symtab_and_line sal, enum bptype bptype,
7072a45ae5f8SJohn Marino 		     const struct breakpoint_ops *ops)
7073a45ae5f8SJohn Marino {
7074a45ae5f8SJohn Marino   init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
7075a45ae5f8SJohn Marino 
7076a45ae5f8SJohn Marino   add_location_to_breakpoint (b, &sal);
7077a45ae5f8SJohn Marino 
7078a45ae5f8SJohn Marino   if (bptype != bp_catchpoint)
7079a45ae5f8SJohn Marino     gdb_assert (sal.pspace != NULL);
7080a45ae5f8SJohn Marino 
7081a45ae5f8SJohn Marino   /* Store the program space that was used to set the breakpoint,
7082a45ae5f8SJohn Marino      except for ordinary breakpoints, which are independent of the
7083a45ae5f8SJohn Marino      program space.  */
7084a45ae5f8SJohn Marino   if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
7085a45ae5f8SJohn Marino     b->pspace = sal.pspace;
7086a45ae5f8SJohn Marino }
7087a45ae5f8SJohn Marino 
70885796c8dcSSimon Schubert /* set_raw_breakpoint is a low level routine for allocating and
70895796c8dcSSimon Schubert    partially initializing a breakpoint of type BPTYPE.  The newly
70905796c8dcSSimon Schubert    created breakpoint's address, section, source file name, and line
70915796c8dcSSimon Schubert    number are provided by SAL.  The newly created and partially
70925796c8dcSSimon Schubert    initialized breakpoint is added to the breakpoint chain and
70935796c8dcSSimon Schubert    is also returned as the value of this function.
70945796c8dcSSimon Schubert 
70955796c8dcSSimon Schubert    It is expected that the caller will complete the initialization of
70965796c8dcSSimon Schubert    the newly created breakpoint struct as well as output any status
70975796c8dcSSimon Schubert    information regarding the creation of a new breakpoint.  In
70985796c8dcSSimon Schubert    particular, set_raw_breakpoint does NOT set the breakpoint
70995796c8dcSSimon Schubert    number!  Care should be taken to not allow an error to occur
71005796c8dcSSimon Schubert    prior to completing the initialization of the breakpoint.  If this
71015796c8dcSSimon Schubert    should happen, a bogus breakpoint will be left on the chain.  */
71025796c8dcSSimon Schubert 
71035796c8dcSSimon Schubert struct breakpoint *
set_raw_breakpoint(struct gdbarch * gdbarch,struct symtab_and_line sal,enum bptype bptype,const struct breakpoint_ops * ops)71045796c8dcSSimon Schubert set_raw_breakpoint (struct gdbarch *gdbarch,
7105a45ae5f8SJohn Marino 		    struct symtab_and_line sal, enum bptype bptype,
7106a45ae5f8SJohn Marino 		    const struct breakpoint_ops *ops)
71075796c8dcSSimon Schubert {
7108a45ae5f8SJohn Marino   struct breakpoint *b = XNEW (struct breakpoint);
71095796c8dcSSimon Schubert 
7110a45ae5f8SJohn Marino   init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
7111a45ae5f8SJohn Marino   add_to_breakpoint_chain (b);
71125796c8dcSSimon Schubert   return b;
71135796c8dcSSimon Schubert }
71145796c8dcSSimon Schubert 
71155796c8dcSSimon Schubert 
71165796c8dcSSimon Schubert /* Note that the breakpoint object B describes a permanent breakpoint
71175796c8dcSSimon Schubert    instruction, hard-wired into the inferior's code.  */
71185796c8dcSSimon Schubert void
make_breakpoint_permanent(struct breakpoint * b)71195796c8dcSSimon Schubert make_breakpoint_permanent (struct breakpoint *b)
71205796c8dcSSimon Schubert {
71215796c8dcSSimon Schubert   struct bp_location *bl;
7122cf7f2e2dSJohn Marino 
71235796c8dcSSimon Schubert   b->enable_state = bp_permanent;
71245796c8dcSSimon Schubert 
7125c50c785cSJohn Marino   /* By definition, permanent breakpoints are already present in the
7126c50c785cSJohn Marino      code.  Mark all locations as inserted.  For now,
7127c50c785cSJohn Marino      make_breakpoint_permanent is called in just one place, so it's
7128c50c785cSJohn Marino      hard to say if it's reasonable to have permanent breakpoint with
7129a45ae5f8SJohn Marino      multiple locations or not, but it's easy to implement.  */
71305796c8dcSSimon Schubert   for (bl = b->loc; bl; bl = bl->next)
71315796c8dcSSimon Schubert     bl->inserted = 1;
71325796c8dcSSimon Schubert }
71335796c8dcSSimon Schubert 
71345796c8dcSSimon Schubert /* Call this routine when stepping and nexting to enable a breakpoint
7135c50c785cSJohn Marino    if we do a longjmp() or 'throw' in TP.  FRAME is the frame which
7136c50c785cSJohn Marino    initiated the operation.  */
71375796c8dcSSimon Schubert 
71385796c8dcSSimon Schubert void
set_longjmp_breakpoint(struct thread_info * tp,struct frame_id frame)7139c50c785cSJohn Marino set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
71405796c8dcSSimon Schubert {
7141c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
7142c50c785cSJohn Marino   int thread = tp->num;
71435796c8dcSSimon Schubert 
71445796c8dcSSimon Schubert   /* To avoid having to rescan all objfile symbols at every step,
71455796c8dcSSimon Schubert      we maintain a list of continually-inserted but always disabled
71465796c8dcSSimon Schubert      longjmp "master" breakpoints.  Here, we simply create momentary
71475796c8dcSSimon Schubert      clones of those and enable them for the requested thread.  */
7148c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7149cf7f2e2dSJohn Marino     if (b->pspace == current_program_space
7150c50c785cSJohn Marino 	&& (b->type == bp_longjmp_master
7151c50c785cSJohn Marino 	    || b->type == bp_exception_master))
71525796c8dcSSimon Schubert       {
7153a45ae5f8SJohn Marino 	enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
7154a45ae5f8SJohn Marino 	struct breakpoint *clone;
7155cf7f2e2dSJohn Marino 
7156*ef5ccd6cSJohn Marino 	/* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7157*ef5ccd6cSJohn Marino 	   after their removal.  */
7158a45ae5f8SJohn Marino 	clone = momentary_breakpoint_from_master (b, type,
7159*ef5ccd6cSJohn Marino 						  &longjmp_breakpoint_ops);
71605796c8dcSSimon Schubert 	clone->thread = thread;
71615796c8dcSSimon Schubert       }
7162c50c785cSJohn Marino 
7163c50c785cSJohn Marino   tp->initiating_frame = frame;
71645796c8dcSSimon Schubert }
71655796c8dcSSimon Schubert 
71665796c8dcSSimon Schubert /* Delete all longjmp breakpoints from THREAD.  */
71675796c8dcSSimon Schubert void
delete_longjmp_breakpoint(int thread)71685796c8dcSSimon Schubert delete_longjmp_breakpoint (int thread)
71695796c8dcSSimon Schubert {
7170c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
71715796c8dcSSimon Schubert 
7172c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7173c50c785cSJohn Marino     if (b->type == bp_longjmp || b->type == bp_exception)
71745796c8dcSSimon Schubert       {
71755796c8dcSSimon Schubert 	if (b->thread == thread)
71765796c8dcSSimon Schubert 	  delete_breakpoint (b);
71775796c8dcSSimon Schubert       }
71785796c8dcSSimon Schubert }
71795796c8dcSSimon Schubert 
71805796c8dcSSimon Schubert void
delete_longjmp_breakpoint_at_next_stop(int thread)7181*ef5ccd6cSJohn Marino delete_longjmp_breakpoint_at_next_stop (int thread)
7182*ef5ccd6cSJohn Marino {
7183*ef5ccd6cSJohn Marino   struct breakpoint *b, *b_tmp;
7184*ef5ccd6cSJohn Marino 
7185*ef5ccd6cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7186*ef5ccd6cSJohn Marino     if (b->type == bp_longjmp || b->type == bp_exception)
7187*ef5ccd6cSJohn Marino       {
7188*ef5ccd6cSJohn Marino 	if (b->thread == thread)
7189*ef5ccd6cSJohn Marino 	  b->disposition = disp_del_at_next_stop;
7190*ef5ccd6cSJohn Marino       }
7191*ef5ccd6cSJohn Marino }
7192*ef5ccd6cSJohn Marino 
7193*ef5ccd6cSJohn Marino /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7194*ef5ccd6cSJohn Marino    INFERIOR_PTID thread.  Chain them all by RELATED_BREAKPOINT and return
7195*ef5ccd6cSJohn Marino    pointer to any of them.  Return NULL if this system cannot place longjmp
7196*ef5ccd6cSJohn Marino    breakpoints.  */
7197*ef5ccd6cSJohn Marino 
7198*ef5ccd6cSJohn Marino struct breakpoint *
set_longjmp_breakpoint_for_call_dummy(void)7199*ef5ccd6cSJohn Marino set_longjmp_breakpoint_for_call_dummy (void)
7200*ef5ccd6cSJohn Marino {
7201*ef5ccd6cSJohn Marino   struct breakpoint *b, *retval = NULL;
7202*ef5ccd6cSJohn Marino 
7203*ef5ccd6cSJohn Marino   ALL_BREAKPOINTS (b)
7204*ef5ccd6cSJohn Marino     if (b->pspace == current_program_space && b->type == bp_longjmp_master)
7205*ef5ccd6cSJohn Marino       {
7206*ef5ccd6cSJohn Marino 	struct breakpoint *new_b;
7207*ef5ccd6cSJohn Marino 
7208*ef5ccd6cSJohn Marino 	new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
7209*ef5ccd6cSJohn Marino 						  &momentary_breakpoint_ops);
7210*ef5ccd6cSJohn Marino 	new_b->thread = pid_to_thread_id (inferior_ptid);
7211*ef5ccd6cSJohn Marino 
7212*ef5ccd6cSJohn Marino 	/* Link NEW_B into the chain of RETVAL breakpoints.  */
7213*ef5ccd6cSJohn Marino 
7214*ef5ccd6cSJohn Marino 	gdb_assert (new_b->related_breakpoint == new_b);
7215*ef5ccd6cSJohn Marino 	if (retval == NULL)
7216*ef5ccd6cSJohn Marino 	  retval = new_b;
7217*ef5ccd6cSJohn Marino 	new_b->related_breakpoint = retval;
7218*ef5ccd6cSJohn Marino 	while (retval->related_breakpoint != new_b->related_breakpoint)
7219*ef5ccd6cSJohn Marino 	  retval = retval->related_breakpoint;
7220*ef5ccd6cSJohn Marino 	retval->related_breakpoint = new_b;
7221*ef5ccd6cSJohn Marino       }
7222*ef5ccd6cSJohn Marino 
7223*ef5ccd6cSJohn Marino   return retval;
7224*ef5ccd6cSJohn Marino }
7225*ef5ccd6cSJohn Marino 
7226*ef5ccd6cSJohn Marino /* Verify all existing dummy frames and their associated breakpoints for
7227*ef5ccd6cSJohn Marino    THREAD.  Remove those which can no longer be found in the current frame
7228*ef5ccd6cSJohn Marino    stack.
7229*ef5ccd6cSJohn Marino 
7230*ef5ccd6cSJohn Marino    You should call this function only at places where it is safe to currently
7231*ef5ccd6cSJohn Marino    unwind the whole stack.  Failed stack unwind would discard live dummy
7232*ef5ccd6cSJohn Marino    frames.  */
7233*ef5ccd6cSJohn Marino 
7234*ef5ccd6cSJohn Marino void
check_longjmp_breakpoint_for_call_dummy(int thread)7235*ef5ccd6cSJohn Marino check_longjmp_breakpoint_for_call_dummy (int thread)
7236*ef5ccd6cSJohn Marino {
7237*ef5ccd6cSJohn Marino   struct breakpoint *b, *b_tmp;
7238*ef5ccd6cSJohn Marino 
7239*ef5ccd6cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7240*ef5ccd6cSJohn Marino     if (b->type == bp_longjmp_call_dummy && b->thread == thread)
7241*ef5ccd6cSJohn Marino       {
7242*ef5ccd6cSJohn Marino 	struct breakpoint *dummy_b = b->related_breakpoint;
7243*ef5ccd6cSJohn Marino 
7244*ef5ccd6cSJohn Marino 	while (dummy_b != b && dummy_b->type != bp_call_dummy)
7245*ef5ccd6cSJohn Marino 	  dummy_b = dummy_b->related_breakpoint;
7246*ef5ccd6cSJohn Marino 	if (dummy_b->type != bp_call_dummy
7247*ef5ccd6cSJohn Marino 	    || frame_find_by_id (dummy_b->frame_id) != NULL)
7248*ef5ccd6cSJohn Marino 	  continue;
7249*ef5ccd6cSJohn Marino 
7250*ef5ccd6cSJohn Marino 	dummy_frame_discard (dummy_b->frame_id);
7251*ef5ccd6cSJohn Marino 
7252*ef5ccd6cSJohn Marino 	while (b->related_breakpoint != b)
7253*ef5ccd6cSJohn Marino 	  {
7254*ef5ccd6cSJohn Marino 	    if (b_tmp == b->related_breakpoint)
7255*ef5ccd6cSJohn Marino 	      b_tmp = b->related_breakpoint->next;
7256*ef5ccd6cSJohn Marino 	    delete_breakpoint (b->related_breakpoint);
7257*ef5ccd6cSJohn Marino 	  }
7258*ef5ccd6cSJohn Marino 	delete_breakpoint (b);
7259*ef5ccd6cSJohn Marino       }
7260*ef5ccd6cSJohn Marino }
7261*ef5ccd6cSJohn Marino 
7262*ef5ccd6cSJohn Marino void
enable_overlay_breakpoints(void)72635796c8dcSSimon Schubert enable_overlay_breakpoints (void)
72645796c8dcSSimon Schubert {
72655796c8dcSSimon Schubert   struct breakpoint *b;
72665796c8dcSSimon Schubert 
72675796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
72685796c8dcSSimon Schubert     if (b->type == bp_overlay_event)
72695796c8dcSSimon Schubert     {
72705796c8dcSSimon Schubert       b->enable_state = bp_enabled;
72715796c8dcSSimon Schubert       update_global_location_list (1);
72725796c8dcSSimon Schubert       overlay_events_enabled = 1;
72735796c8dcSSimon Schubert     }
72745796c8dcSSimon Schubert }
72755796c8dcSSimon Schubert 
72765796c8dcSSimon Schubert void
disable_overlay_breakpoints(void)72775796c8dcSSimon Schubert disable_overlay_breakpoints (void)
72785796c8dcSSimon Schubert {
72795796c8dcSSimon Schubert   struct breakpoint *b;
72805796c8dcSSimon Schubert 
72815796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
72825796c8dcSSimon Schubert     if (b->type == bp_overlay_event)
72835796c8dcSSimon Schubert     {
72845796c8dcSSimon Schubert       b->enable_state = bp_disabled;
72855796c8dcSSimon Schubert       update_global_location_list (0);
72865796c8dcSSimon Schubert       overlay_events_enabled = 0;
72875796c8dcSSimon Schubert     }
72885796c8dcSSimon Schubert }
72895796c8dcSSimon Schubert 
7290cf7f2e2dSJohn Marino /* Set an active std::terminate breakpoint for each std::terminate
7291cf7f2e2dSJohn Marino    master breakpoint.  */
7292cf7f2e2dSJohn Marino void
set_std_terminate_breakpoint(void)7293cf7f2e2dSJohn Marino set_std_terminate_breakpoint (void)
7294cf7f2e2dSJohn Marino {
7295c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
7296cf7f2e2dSJohn Marino 
7297c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7298cf7f2e2dSJohn Marino     if (b->pspace == current_program_space
7299cf7f2e2dSJohn Marino 	&& b->type == bp_std_terminate_master)
7300cf7f2e2dSJohn Marino       {
7301a45ae5f8SJohn Marino 	momentary_breakpoint_from_master (b, bp_std_terminate,
7302a45ae5f8SJohn Marino 					  &momentary_breakpoint_ops);
7303cf7f2e2dSJohn Marino       }
7304cf7f2e2dSJohn Marino }
7305cf7f2e2dSJohn Marino 
7306cf7f2e2dSJohn Marino /* Delete all the std::terminate breakpoints.  */
7307cf7f2e2dSJohn Marino void
delete_std_terminate_breakpoint(void)7308cf7f2e2dSJohn Marino delete_std_terminate_breakpoint (void)
7309cf7f2e2dSJohn Marino {
7310c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
7311cf7f2e2dSJohn Marino 
7312c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7313cf7f2e2dSJohn Marino     if (b->type == bp_std_terminate)
7314cf7f2e2dSJohn Marino       delete_breakpoint (b);
7315cf7f2e2dSJohn Marino }
7316cf7f2e2dSJohn Marino 
73175796c8dcSSimon Schubert struct breakpoint *
create_thread_event_breakpoint(struct gdbarch * gdbarch,CORE_ADDR address)73185796c8dcSSimon Schubert create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
73195796c8dcSSimon Schubert {
73205796c8dcSSimon Schubert   struct breakpoint *b;
73215796c8dcSSimon Schubert 
7322a45ae5f8SJohn Marino   b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
7323a45ae5f8SJohn Marino 				  &internal_breakpoint_ops);
73245796c8dcSSimon Schubert 
73255796c8dcSSimon Schubert   b->enable_state = bp_enabled;
73265796c8dcSSimon Schubert   /* addr_string has to be used or breakpoint_re_set will delete me.  */
73275796c8dcSSimon Schubert   b->addr_string
73285796c8dcSSimon Schubert     = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
73295796c8dcSSimon Schubert 
73305796c8dcSSimon Schubert   update_global_location_list_nothrow (1);
73315796c8dcSSimon Schubert 
73325796c8dcSSimon Schubert   return b;
73335796c8dcSSimon Schubert }
73345796c8dcSSimon Schubert 
73355796c8dcSSimon Schubert void
remove_thread_event_breakpoints(void)73365796c8dcSSimon Schubert remove_thread_event_breakpoints (void)
73375796c8dcSSimon Schubert {
7338c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
73395796c8dcSSimon Schubert 
7340c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7341cf7f2e2dSJohn Marino     if (b->type == bp_thread_event
7342cf7f2e2dSJohn Marino 	&& b->loc->pspace == current_program_space)
73435796c8dcSSimon Schubert       delete_breakpoint (b);
73445796c8dcSSimon Schubert }
73455796c8dcSSimon Schubert 
73465796c8dcSSimon Schubert struct lang_and_radix
73475796c8dcSSimon Schubert   {
73485796c8dcSSimon Schubert     enum language lang;
73495796c8dcSSimon Schubert     int radix;
73505796c8dcSSimon Schubert   };
73515796c8dcSSimon Schubert 
73525796c8dcSSimon Schubert /* Create a breakpoint for JIT code registration and unregistration.  */
73535796c8dcSSimon Schubert 
73545796c8dcSSimon Schubert struct breakpoint *
create_jit_event_breakpoint(struct gdbarch * gdbarch,CORE_ADDR address)73555796c8dcSSimon Schubert create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
73565796c8dcSSimon Schubert {
73575796c8dcSSimon Schubert   struct breakpoint *b;
73585796c8dcSSimon Schubert 
7359a45ae5f8SJohn Marino   b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
7360a45ae5f8SJohn Marino 				  &internal_breakpoint_ops);
73615796c8dcSSimon Schubert   update_global_location_list_nothrow (1);
73625796c8dcSSimon Schubert   return b;
73635796c8dcSSimon Schubert }
73645796c8dcSSimon Schubert 
7365c50c785cSJohn Marino /* Remove JIT code registration and unregistration breakpoint(s).  */
7366c50c785cSJohn Marino 
7367c50c785cSJohn Marino void
remove_jit_event_breakpoints(void)7368c50c785cSJohn Marino remove_jit_event_breakpoints (void)
7369c50c785cSJohn Marino {
7370c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
7371c50c785cSJohn Marino 
7372c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7373c50c785cSJohn Marino     if (b->type == bp_jit_event
7374c50c785cSJohn Marino 	&& b->loc->pspace == current_program_space)
7375c50c785cSJohn Marino       delete_breakpoint (b);
7376c50c785cSJohn Marino }
7377c50c785cSJohn Marino 
73785796c8dcSSimon Schubert void
remove_solib_event_breakpoints(void)73795796c8dcSSimon Schubert remove_solib_event_breakpoints (void)
73805796c8dcSSimon Schubert {
7381c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
73825796c8dcSSimon Schubert 
7383c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
7384cf7f2e2dSJohn Marino     if (b->type == bp_shlib_event
7385cf7f2e2dSJohn Marino 	&& b->loc->pspace == current_program_space)
73865796c8dcSSimon Schubert       delete_breakpoint (b);
73875796c8dcSSimon Schubert }
73885796c8dcSSimon Schubert 
73895796c8dcSSimon Schubert struct breakpoint *
create_solib_event_breakpoint(struct gdbarch * gdbarch,CORE_ADDR address)73905796c8dcSSimon Schubert create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
73915796c8dcSSimon Schubert {
73925796c8dcSSimon Schubert   struct breakpoint *b;
73935796c8dcSSimon Schubert 
7394a45ae5f8SJohn Marino   b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
7395a45ae5f8SJohn Marino 				  &internal_breakpoint_ops);
73965796c8dcSSimon Schubert   update_global_location_list_nothrow (1);
73975796c8dcSSimon Schubert   return b;
73985796c8dcSSimon Schubert }
73995796c8dcSSimon Schubert 
74005796c8dcSSimon Schubert /* Disable any breakpoints that are on code in shared libraries.  Only
74015796c8dcSSimon Schubert    apply to enabled breakpoints, disabled ones can just stay disabled.  */
74025796c8dcSSimon Schubert 
74035796c8dcSSimon Schubert void
disable_breakpoints_in_shlibs(void)74045796c8dcSSimon Schubert disable_breakpoints_in_shlibs (void)
74055796c8dcSSimon Schubert {
7406cf7f2e2dSJohn Marino   struct bp_location *loc, **locp_tmp;
74075796c8dcSSimon Schubert 
7408cf7f2e2dSJohn Marino   ALL_BP_LOCATIONS (loc, locp_tmp)
74095796c8dcSSimon Schubert   {
7410cf7f2e2dSJohn Marino     /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL.  */
74115796c8dcSSimon Schubert     struct breakpoint *b = loc->owner;
7412cf7f2e2dSJohn Marino 
7413c50c785cSJohn Marino     /* We apply the check to all breakpoints, including disabled for
7414c50c785cSJohn Marino        those with loc->duplicate set.  This is so that when breakpoint
7415c50c785cSJohn Marino        becomes enabled, or the duplicate is removed, gdb will try to
7416c50c785cSJohn Marino        insert all breakpoints.  If we don't set shlib_disabled here,
7417c50c785cSJohn Marino        we'll try to insert those breakpoints and fail.  */
74185796c8dcSSimon Schubert     if (((b->type == bp_breakpoint)
7419cf7f2e2dSJohn Marino 	 || (b->type == bp_jit_event)
74205796c8dcSSimon Schubert 	 || (b->type == bp_hardware_breakpoint)
7421cf7f2e2dSJohn Marino 	 || (is_tracepoint (b)))
7422cf7f2e2dSJohn Marino 	&& loc->pspace == current_program_space
74235796c8dcSSimon Schubert 	&& !loc->shlib_disabled
74245796c8dcSSimon Schubert #ifdef PC_SOLIB
74255796c8dcSSimon Schubert 	&& PC_SOLIB (loc->address)
74265796c8dcSSimon Schubert #else
7427cf7f2e2dSJohn Marino 	&& solib_name_from_address (loc->pspace, loc->address)
74285796c8dcSSimon Schubert #endif
74295796c8dcSSimon Schubert 	)
74305796c8dcSSimon Schubert       {
74315796c8dcSSimon Schubert 	loc->shlib_disabled = 1;
74325796c8dcSSimon Schubert       }
74335796c8dcSSimon Schubert   }
74345796c8dcSSimon Schubert }
74355796c8dcSSimon Schubert 
7436a45ae5f8SJohn Marino /* Disable any breakpoints and tracepoints that are in an unloaded shared
7437a45ae5f8SJohn Marino    library.  Only apply to enabled breakpoints, disabled ones can just stay
7438c50c785cSJohn Marino    disabled.  */
74395796c8dcSSimon Schubert 
74405796c8dcSSimon Schubert static void
disable_breakpoints_in_unloaded_shlib(struct so_list * solib)74415796c8dcSSimon Schubert disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
74425796c8dcSSimon Schubert {
7443cf7f2e2dSJohn Marino   struct bp_location *loc, **locp_tmp;
74445796c8dcSSimon Schubert   int disabled_shlib_breaks = 0;
74455796c8dcSSimon Schubert 
74465796c8dcSSimon Schubert   /* SunOS a.out shared libraries are always mapped, so do not
74475796c8dcSSimon Schubert      disable breakpoints; they will only be reported as unloaded
74485796c8dcSSimon Schubert      through clear_solib when GDB discards its shared library
74495796c8dcSSimon Schubert      list.  See clear_solib for more information.  */
74505796c8dcSSimon Schubert   if (exec_bfd != NULL
74515796c8dcSSimon Schubert       && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
74525796c8dcSSimon Schubert     return;
74535796c8dcSSimon Schubert 
7454cf7f2e2dSJohn Marino   ALL_BP_LOCATIONS (loc, locp_tmp)
74555796c8dcSSimon Schubert   {
7456cf7f2e2dSJohn Marino     /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL.  */
74575796c8dcSSimon Schubert     struct breakpoint *b = loc->owner;
7458cf7f2e2dSJohn Marino 
7459a45ae5f8SJohn Marino     if (solib->pspace == loc->pspace
74605796c8dcSSimon Schubert 	&& !loc->shlib_disabled
7461a45ae5f8SJohn Marino 	&& (((b->type == bp_breakpoint
7462cf7f2e2dSJohn Marino 	      || b->type == bp_jit_event
7463cf7f2e2dSJohn Marino 	      || b->type == bp_hardware_breakpoint)
7464a45ae5f8SJohn Marino 	     && (loc->loc_type == bp_loc_hardware_breakpoint
7465a45ae5f8SJohn Marino 		 || loc->loc_type == bp_loc_software_breakpoint))
7466a45ae5f8SJohn Marino 	    || is_tracepoint (b))
74675796c8dcSSimon Schubert 	&& solib_contains_address_p (solib, loc->address))
74685796c8dcSSimon Schubert       {
74695796c8dcSSimon Schubert 	loc->shlib_disabled = 1;
74705796c8dcSSimon Schubert 	/* At this point, we cannot rely on remove_breakpoint
74715796c8dcSSimon Schubert 	   succeeding so we must mark the breakpoint as not inserted
74725796c8dcSSimon Schubert 	   to prevent future errors occurring in remove_breakpoints.  */
74735796c8dcSSimon Schubert 	loc->inserted = 0;
7474a45ae5f8SJohn Marino 
7475a45ae5f8SJohn Marino 	/* This may cause duplicate notifications for the same breakpoint.  */
7476a45ae5f8SJohn Marino 	observer_notify_breakpoint_modified (b);
7477a45ae5f8SJohn Marino 
74785796c8dcSSimon Schubert 	if (!disabled_shlib_breaks)
74795796c8dcSSimon Schubert 	  {
74805796c8dcSSimon Schubert 	    target_terminal_ours_for_output ();
7481c50c785cSJohn Marino 	    warning (_("Temporarily disabling breakpoints "
7482c50c785cSJohn Marino 		       "for unloaded shared library \"%s\""),
74835796c8dcSSimon Schubert 		     solib->so_name);
74845796c8dcSSimon Schubert 	  }
74855796c8dcSSimon Schubert 	disabled_shlib_breaks = 1;
74865796c8dcSSimon Schubert       }
74875796c8dcSSimon Schubert   }
74885796c8dcSSimon Schubert }
74895796c8dcSSimon Schubert 
74905796c8dcSSimon Schubert /* FORK & VFORK catchpoints.  */
74915796c8dcSSimon Schubert 
7492a45ae5f8SJohn Marino /* An instance of this type is used to represent a fork or vfork
7493a45ae5f8SJohn Marino    catchpoint.  It includes a "struct breakpoint" as a kind of base
7494a45ae5f8SJohn Marino    class; users downcast to "struct breakpoint *" when needed.  A
7495a45ae5f8SJohn Marino    breakpoint is really of this type iff its ops pointer points to
7496a45ae5f8SJohn Marino    CATCH_FORK_BREAKPOINT_OPS.  */
7497a45ae5f8SJohn Marino 
7498a45ae5f8SJohn Marino struct fork_catchpoint
7499a45ae5f8SJohn Marino {
7500a45ae5f8SJohn Marino   /* The base class.  */
7501a45ae5f8SJohn Marino   struct breakpoint base;
7502a45ae5f8SJohn Marino 
7503a45ae5f8SJohn Marino   /* Process id of a child process whose forking triggered this
7504a45ae5f8SJohn Marino      catchpoint.  This field is only valid immediately after this
7505a45ae5f8SJohn Marino      catchpoint has triggered.  */
7506a45ae5f8SJohn Marino   ptid_t forked_inferior_pid;
7507a45ae5f8SJohn Marino };
7508a45ae5f8SJohn Marino 
7509c50c785cSJohn Marino /* Implement the "insert" breakpoint_ops method for fork
7510c50c785cSJohn Marino    catchpoints.  */
75115796c8dcSSimon Schubert 
75125796c8dcSSimon Schubert static int
insert_catch_fork(struct bp_location * bl)7513c50c785cSJohn Marino insert_catch_fork (struct bp_location *bl)
7514c50c785cSJohn Marino {
7515c50c785cSJohn Marino   return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
7516c50c785cSJohn Marino }
7517c50c785cSJohn Marino 
7518c50c785cSJohn Marino /* Implement the "remove" breakpoint_ops method for fork
7519c50c785cSJohn Marino    catchpoints.  */
7520c50c785cSJohn Marino 
7521c50c785cSJohn Marino static int
remove_catch_fork(struct bp_location * bl)7522c50c785cSJohn Marino remove_catch_fork (struct bp_location *bl)
75235796c8dcSSimon Schubert {
75245796c8dcSSimon Schubert   return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
75255796c8dcSSimon Schubert }
75265796c8dcSSimon Schubert 
75275796c8dcSSimon Schubert /* Implement the "breakpoint_hit" breakpoint_ops method for fork
75285796c8dcSSimon Schubert    catchpoints.  */
75295796c8dcSSimon Schubert 
75305796c8dcSSimon Schubert static int
breakpoint_hit_catch_fork(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)7531c50c785cSJohn Marino breakpoint_hit_catch_fork (const struct bp_location *bl,
7532*ef5ccd6cSJohn Marino 			   struct address_space *aspace, CORE_ADDR bp_addr,
7533*ef5ccd6cSJohn Marino 			   const struct target_waitstatus *ws)
75345796c8dcSSimon Schubert {
7535a45ae5f8SJohn Marino   struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7536a45ae5f8SJohn Marino 
7537*ef5ccd6cSJohn Marino   if (ws->kind != TARGET_WAITKIND_FORKED)
7538*ef5ccd6cSJohn Marino     return 0;
7539*ef5ccd6cSJohn Marino 
7540*ef5ccd6cSJohn Marino   c->forked_inferior_pid = ws->value.related_pid;
7541*ef5ccd6cSJohn Marino   return 1;
75425796c8dcSSimon Schubert }
75435796c8dcSSimon Schubert 
7544c50c785cSJohn Marino /* Implement the "print_it" breakpoint_ops method for fork
7545c50c785cSJohn Marino    catchpoints.  */
75465796c8dcSSimon Schubert 
75475796c8dcSSimon Schubert static enum print_stop_action
print_it_catch_fork(bpstat bs)7548a45ae5f8SJohn Marino print_it_catch_fork (bpstat bs)
75495796c8dcSSimon Schubert {
7550a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
7551a45ae5f8SJohn Marino   struct breakpoint *b = bs->breakpoint_at;
7552a45ae5f8SJohn Marino   struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
7553a45ae5f8SJohn Marino 
75545796c8dcSSimon Schubert   annotate_catchpoint (b->number);
7555a45ae5f8SJohn Marino   if (b->disposition == disp_del)
7556a45ae5f8SJohn Marino     ui_out_text (uiout, "\nTemporary catchpoint ");
7557a45ae5f8SJohn Marino   else
7558a45ae5f8SJohn Marino     ui_out_text (uiout, "\nCatchpoint ");
7559a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (uiout))
7560a45ae5f8SJohn Marino     {
7561a45ae5f8SJohn Marino       ui_out_field_string (uiout, "reason",
7562a45ae5f8SJohn Marino 			   async_reason_lookup (EXEC_ASYNC_FORK));
7563a45ae5f8SJohn Marino       ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7564a45ae5f8SJohn Marino     }
7565a45ae5f8SJohn Marino   ui_out_field_int (uiout, "bkptno", b->number);
7566a45ae5f8SJohn Marino   ui_out_text (uiout, " (forked process ");
7567a45ae5f8SJohn Marino   ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7568a45ae5f8SJohn Marino   ui_out_text (uiout, "), ");
75695796c8dcSSimon Schubert   return PRINT_SRC_AND_LOC;
75705796c8dcSSimon Schubert }
75715796c8dcSSimon Schubert 
7572c50c785cSJohn Marino /* Implement the "print_one" breakpoint_ops method for fork
7573c50c785cSJohn Marino    catchpoints.  */
75745796c8dcSSimon Schubert 
75755796c8dcSSimon Schubert static void
print_one_catch_fork(struct breakpoint * b,struct bp_location ** last_loc)75765796c8dcSSimon Schubert print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
75775796c8dcSSimon Schubert {
7578a45ae5f8SJohn Marino   struct fork_catchpoint *c = (struct fork_catchpoint *) b;
75795796c8dcSSimon Schubert   struct value_print_options opts;
7580a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
75815796c8dcSSimon Schubert 
75825796c8dcSSimon Schubert   get_user_print_options (&opts);
75835796c8dcSSimon Schubert 
7584c50c785cSJohn Marino   /* Field 4, the address, is omitted (which makes the columns not
7585c50c785cSJohn Marino      line up too nicely with the headers, but the effect is relatively
7586c50c785cSJohn Marino      readable).  */
75875796c8dcSSimon Schubert   if (opts.addressprint)
75885796c8dcSSimon Schubert     ui_out_field_skip (uiout, "addr");
75895796c8dcSSimon Schubert   annotate_field (5);
75905796c8dcSSimon Schubert   ui_out_text (uiout, "fork");
7591a45ae5f8SJohn Marino   if (!ptid_equal (c->forked_inferior_pid, null_ptid))
75925796c8dcSSimon Schubert     {
75935796c8dcSSimon Schubert       ui_out_text (uiout, ", process ");
75945796c8dcSSimon Schubert       ui_out_field_int (uiout, "what",
7595a45ae5f8SJohn Marino                         ptid_get_pid (c->forked_inferior_pid));
75965796c8dcSSimon Schubert       ui_out_spaces (uiout, 1);
75975796c8dcSSimon Schubert     }
7598*ef5ccd6cSJohn Marino 
7599*ef5ccd6cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
7600*ef5ccd6cSJohn Marino     ui_out_field_string (uiout, "catch-type", "fork");
76015796c8dcSSimon Schubert }
76025796c8dcSSimon Schubert 
76035796c8dcSSimon Schubert /* Implement the "print_mention" breakpoint_ops method for fork
76045796c8dcSSimon Schubert    catchpoints.  */
76055796c8dcSSimon Schubert 
76065796c8dcSSimon Schubert static void
print_mention_catch_fork(struct breakpoint * b)76075796c8dcSSimon Schubert print_mention_catch_fork (struct breakpoint *b)
76085796c8dcSSimon Schubert {
76095796c8dcSSimon Schubert   printf_filtered (_("Catchpoint %d (fork)"), b->number);
76105796c8dcSSimon Schubert }
76115796c8dcSSimon Schubert 
7612cf7f2e2dSJohn Marino /* Implement the "print_recreate" breakpoint_ops method for fork
7613cf7f2e2dSJohn Marino    catchpoints.  */
7614cf7f2e2dSJohn Marino 
7615cf7f2e2dSJohn Marino static void
print_recreate_catch_fork(struct breakpoint * b,struct ui_file * fp)7616cf7f2e2dSJohn Marino print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7617cf7f2e2dSJohn Marino {
7618cf7f2e2dSJohn Marino   fprintf_unfiltered (fp, "catch fork");
7619a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
7620cf7f2e2dSJohn Marino }
7621cf7f2e2dSJohn Marino 
76225796c8dcSSimon Schubert /* The breakpoint_ops structure to be used in fork catchpoints.  */
76235796c8dcSSimon Schubert 
7624a45ae5f8SJohn Marino static struct breakpoint_ops catch_fork_breakpoint_ops;
76255796c8dcSSimon Schubert 
7626c50c785cSJohn Marino /* Implement the "insert" breakpoint_ops method for vfork
7627c50c785cSJohn Marino    catchpoints.  */
76285796c8dcSSimon Schubert 
76295796c8dcSSimon Schubert static int
insert_catch_vfork(struct bp_location * bl)7630c50c785cSJohn Marino insert_catch_vfork (struct bp_location *bl)
7631c50c785cSJohn Marino {
7632c50c785cSJohn Marino   return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
7633c50c785cSJohn Marino }
7634c50c785cSJohn Marino 
7635c50c785cSJohn Marino /* Implement the "remove" breakpoint_ops method for vfork
7636c50c785cSJohn Marino    catchpoints.  */
7637c50c785cSJohn Marino 
7638c50c785cSJohn Marino static int
remove_catch_vfork(struct bp_location * bl)7639c50c785cSJohn Marino remove_catch_vfork (struct bp_location *bl)
76405796c8dcSSimon Schubert {
76415796c8dcSSimon Schubert   return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
76425796c8dcSSimon Schubert }
76435796c8dcSSimon Schubert 
76445796c8dcSSimon Schubert /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
76455796c8dcSSimon Schubert    catchpoints.  */
76465796c8dcSSimon Schubert 
76475796c8dcSSimon Schubert static int
breakpoint_hit_catch_vfork(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)7648c50c785cSJohn Marino breakpoint_hit_catch_vfork (const struct bp_location *bl,
7649*ef5ccd6cSJohn Marino 			    struct address_space *aspace, CORE_ADDR bp_addr,
7650*ef5ccd6cSJohn Marino 			    const struct target_waitstatus *ws)
76515796c8dcSSimon Schubert {
7652a45ae5f8SJohn Marino   struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7653a45ae5f8SJohn Marino 
7654*ef5ccd6cSJohn Marino   if (ws->kind != TARGET_WAITKIND_VFORKED)
7655*ef5ccd6cSJohn Marino     return 0;
7656*ef5ccd6cSJohn Marino 
7657*ef5ccd6cSJohn Marino   c->forked_inferior_pid = ws->value.related_pid;
7658*ef5ccd6cSJohn Marino   return 1;
76595796c8dcSSimon Schubert }
76605796c8dcSSimon Schubert 
7661c50c785cSJohn Marino /* Implement the "print_it" breakpoint_ops method for vfork
7662c50c785cSJohn Marino    catchpoints.  */
76635796c8dcSSimon Schubert 
76645796c8dcSSimon Schubert static enum print_stop_action
print_it_catch_vfork(bpstat bs)7665a45ae5f8SJohn Marino print_it_catch_vfork (bpstat bs)
76665796c8dcSSimon Schubert {
7667a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
7668a45ae5f8SJohn Marino   struct breakpoint *b = bs->breakpoint_at;
7669a45ae5f8SJohn Marino   struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7670a45ae5f8SJohn Marino 
76715796c8dcSSimon Schubert   annotate_catchpoint (b->number);
7672a45ae5f8SJohn Marino   if (b->disposition == disp_del)
7673a45ae5f8SJohn Marino     ui_out_text (uiout, "\nTemporary catchpoint ");
7674a45ae5f8SJohn Marino   else
7675a45ae5f8SJohn Marino     ui_out_text (uiout, "\nCatchpoint ");
7676a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (uiout))
7677a45ae5f8SJohn Marino     {
7678a45ae5f8SJohn Marino       ui_out_field_string (uiout, "reason",
7679a45ae5f8SJohn Marino 			   async_reason_lookup (EXEC_ASYNC_VFORK));
7680a45ae5f8SJohn Marino       ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7681a45ae5f8SJohn Marino     }
7682a45ae5f8SJohn Marino   ui_out_field_int (uiout, "bkptno", b->number);
7683a45ae5f8SJohn Marino   ui_out_text (uiout, " (vforked process ");
7684a45ae5f8SJohn Marino   ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7685a45ae5f8SJohn Marino   ui_out_text (uiout, "), ");
76865796c8dcSSimon Schubert   return PRINT_SRC_AND_LOC;
76875796c8dcSSimon Schubert }
76885796c8dcSSimon Schubert 
7689c50c785cSJohn Marino /* Implement the "print_one" breakpoint_ops method for vfork
7690c50c785cSJohn Marino    catchpoints.  */
76915796c8dcSSimon Schubert 
76925796c8dcSSimon Schubert static void
print_one_catch_vfork(struct breakpoint * b,struct bp_location ** last_loc)76935796c8dcSSimon Schubert print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
76945796c8dcSSimon Schubert {
7695a45ae5f8SJohn Marino   struct fork_catchpoint *c = (struct fork_catchpoint *) b;
76965796c8dcSSimon Schubert   struct value_print_options opts;
7697a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
76985796c8dcSSimon Schubert 
76995796c8dcSSimon Schubert   get_user_print_options (&opts);
7700c50c785cSJohn Marino   /* Field 4, the address, is omitted (which makes the columns not
7701c50c785cSJohn Marino      line up too nicely with the headers, but the effect is relatively
7702c50c785cSJohn Marino      readable).  */
77035796c8dcSSimon Schubert   if (opts.addressprint)
77045796c8dcSSimon Schubert     ui_out_field_skip (uiout, "addr");
77055796c8dcSSimon Schubert   annotate_field (5);
77065796c8dcSSimon Schubert   ui_out_text (uiout, "vfork");
7707a45ae5f8SJohn Marino   if (!ptid_equal (c->forked_inferior_pid, null_ptid))
77085796c8dcSSimon Schubert     {
77095796c8dcSSimon Schubert       ui_out_text (uiout, ", process ");
77105796c8dcSSimon Schubert       ui_out_field_int (uiout, "what",
7711a45ae5f8SJohn Marino                         ptid_get_pid (c->forked_inferior_pid));
77125796c8dcSSimon Schubert       ui_out_spaces (uiout, 1);
77135796c8dcSSimon Schubert     }
7714*ef5ccd6cSJohn Marino 
7715*ef5ccd6cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
7716*ef5ccd6cSJohn Marino     ui_out_field_string (uiout, "catch-type", "vfork");
77175796c8dcSSimon Schubert }
77185796c8dcSSimon Schubert 
77195796c8dcSSimon Schubert /* Implement the "print_mention" breakpoint_ops method for vfork
77205796c8dcSSimon Schubert    catchpoints.  */
77215796c8dcSSimon Schubert 
77225796c8dcSSimon Schubert static void
print_mention_catch_vfork(struct breakpoint * b)77235796c8dcSSimon Schubert print_mention_catch_vfork (struct breakpoint *b)
77245796c8dcSSimon Schubert {
77255796c8dcSSimon Schubert   printf_filtered (_("Catchpoint %d (vfork)"), b->number);
77265796c8dcSSimon Schubert }
77275796c8dcSSimon Schubert 
7728cf7f2e2dSJohn Marino /* Implement the "print_recreate" breakpoint_ops method for vfork
7729cf7f2e2dSJohn Marino    catchpoints.  */
7730cf7f2e2dSJohn Marino 
7731cf7f2e2dSJohn Marino static void
print_recreate_catch_vfork(struct breakpoint * b,struct ui_file * fp)7732cf7f2e2dSJohn Marino print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7733cf7f2e2dSJohn Marino {
7734cf7f2e2dSJohn Marino   fprintf_unfiltered (fp, "catch vfork");
7735a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
7736cf7f2e2dSJohn Marino }
7737cf7f2e2dSJohn Marino 
77385796c8dcSSimon Schubert /* The breakpoint_ops structure to be used in vfork catchpoints.  */
77395796c8dcSSimon Schubert 
7740a45ae5f8SJohn Marino static struct breakpoint_ops catch_vfork_breakpoint_ops;
7741a45ae5f8SJohn Marino 
7742*ef5ccd6cSJohn Marino /* An instance of this type is used to represent an solib catchpoint.
7743*ef5ccd6cSJohn Marino    It includes a "struct breakpoint" as a kind of base class; users
7744*ef5ccd6cSJohn Marino    downcast to "struct breakpoint *" when needed.  A breakpoint is
7745*ef5ccd6cSJohn Marino    really of this type iff its ops pointer points to
7746*ef5ccd6cSJohn Marino    CATCH_SOLIB_BREAKPOINT_OPS.  */
7747*ef5ccd6cSJohn Marino 
7748*ef5ccd6cSJohn Marino struct solib_catchpoint
7749*ef5ccd6cSJohn Marino {
7750*ef5ccd6cSJohn Marino   /* The base class.  */
7751*ef5ccd6cSJohn Marino   struct breakpoint base;
7752*ef5ccd6cSJohn Marino 
7753*ef5ccd6cSJohn Marino   /* True for "catch load", false for "catch unload".  */
7754*ef5ccd6cSJohn Marino   unsigned char is_load;
7755*ef5ccd6cSJohn Marino 
7756*ef5ccd6cSJohn Marino   /* Regular expression to match, if any.  COMPILED is only valid when
7757*ef5ccd6cSJohn Marino      REGEX is non-NULL.  */
7758*ef5ccd6cSJohn Marino   char *regex;
7759*ef5ccd6cSJohn Marino   regex_t compiled;
7760*ef5ccd6cSJohn Marino };
7761*ef5ccd6cSJohn Marino 
7762*ef5ccd6cSJohn Marino static void
dtor_catch_solib(struct breakpoint * b)7763*ef5ccd6cSJohn Marino dtor_catch_solib (struct breakpoint *b)
7764*ef5ccd6cSJohn Marino {
7765*ef5ccd6cSJohn Marino   struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7766*ef5ccd6cSJohn Marino 
7767*ef5ccd6cSJohn Marino   if (self->regex)
7768*ef5ccd6cSJohn Marino     regfree (&self->compiled);
7769*ef5ccd6cSJohn Marino   xfree (self->regex);
7770*ef5ccd6cSJohn Marino 
7771*ef5ccd6cSJohn Marino   base_breakpoint_ops.dtor (b);
7772*ef5ccd6cSJohn Marino }
7773*ef5ccd6cSJohn Marino 
7774*ef5ccd6cSJohn Marino static int
insert_catch_solib(struct bp_location * ignore)7775*ef5ccd6cSJohn Marino insert_catch_solib (struct bp_location *ignore)
7776*ef5ccd6cSJohn Marino {
7777*ef5ccd6cSJohn Marino   return 0;
7778*ef5ccd6cSJohn Marino }
7779*ef5ccd6cSJohn Marino 
7780*ef5ccd6cSJohn Marino static int
remove_catch_solib(struct bp_location * ignore)7781*ef5ccd6cSJohn Marino remove_catch_solib (struct bp_location *ignore)
7782*ef5ccd6cSJohn Marino {
7783*ef5ccd6cSJohn Marino   return 0;
7784*ef5ccd6cSJohn Marino }
7785*ef5ccd6cSJohn Marino 
7786*ef5ccd6cSJohn Marino static int
breakpoint_hit_catch_solib(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)7787*ef5ccd6cSJohn Marino breakpoint_hit_catch_solib (const struct bp_location *bl,
7788*ef5ccd6cSJohn Marino 			    struct address_space *aspace,
7789*ef5ccd6cSJohn Marino 			    CORE_ADDR bp_addr,
7790*ef5ccd6cSJohn Marino 			    const struct target_waitstatus *ws)
7791*ef5ccd6cSJohn Marino {
7792*ef5ccd6cSJohn Marino   struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7793*ef5ccd6cSJohn Marino   struct breakpoint *other;
7794*ef5ccd6cSJohn Marino 
7795*ef5ccd6cSJohn Marino   if (ws->kind == TARGET_WAITKIND_LOADED)
7796*ef5ccd6cSJohn Marino     return 1;
7797*ef5ccd6cSJohn Marino 
7798*ef5ccd6cSJohn Marino   ALL_BREAKPOINTS (other)
7799*ef5ccd6cSJohn Marino   {
7800*ef5ccd6cSJohn Marino     struct bp_location *other_bl;
7801*ef5ccd6cSJohn Marino 
7802*ef5ccd6cSJohn Marino     if (other == bl->owner)
7803*ef5ccd6cSJohn Marino       continue;
7804*ef5ccd6cSJohn Marino 
7805*ef5ccd6cSJohn Marino     if (other->type != bp_shlib_event)
7806*ef5ccd6cSJohn Marino       continue;
7807*ef5ccd6cSJohn Marino 
7808*ef5ccd6cSJohn Marino     if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7809*ef5ccd6cSJohn Marino       continue;
7810*ef5ccd6cSJohn Marino 
7811*ef5ccd6cSJohn Marino     for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7812*ef5ccd6cSJohn Marino       {
7813*ef5ccd6cSJohn Marino 	if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7814*ef5ccd6cSJohn Marino 	  return 1;
7815*ef5ccd6cSJohn Marino       }
7816*ef5ccd6cSJohn Marino   }
7817*ef5ccd6cSJohn Marino 
7818*ef5ccd6cSJohn Marino   return 0;
7819*ef5ccd6cSJohn Marino }
7820*ef5ccd6cSJohn Marino 
7821*ef5ccd6cSJohn Marino static void
check_status_catch_solib(struct bpstats * bs)7822*ef5ccd6cSJohn Marino check_status_catch_solib (struct bpstats *bs)
7823*ef5ccd6cSJohn Marino {
7824*ef5ccd6cSJohn Marino   struct solib_catchpoint *self
7825*ef5ccd6cSJohn Marino     = (struct solib_catchpoint *) bs->breakpoint_at;
7826*ef5ccd6cSJohn Marino   int ix;
7827*ef5ccd6cSJohn Marino 
7828*ef5ccd6cSJohn Marino   if (self->is_load)
7829*ef5ccd6cSJohn Marino     {
7830*ef5ccd6cSJohn Marino       struct so_list *iter;
7831*ef5ccd6cSJohn Marino 
7832*ef5ccd6cSJohn Marino       for (ix = 0;
7833*ef5ccd6cSJohn Marino 	   VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7834*ef5ccd6cSJohn Marino 			ix, iter);
7835*ef5ccd6cSJohn Marino 	   ++ix)
7836*ef5ccd6cSJohn Marino 	{
7837*ef5ccd6cSJohn Marino 	  if (!self->regex
7838*ef5ccd6cSJohn Marino 	      || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7839*ef5ccd6cSJohn Marino 	    return;
7840*ef5ccd6cSJohn Marino 	}
7841*ef5ccd6cSJohn Marino     }
7842*ef5ccd6cSJohn Marino   else
7843*ef5ccd6cSJohn Marino     {
7844*ef5ccd6cSJohn Marino       char *iter;
7845*ef5ccd6cSJohn Marino 
7846*ef5ccd6cSJohn Marino       for (ix = 0;
7847*ef5ccd6cSJohn Marino 	   VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7848*ef5ccd6cSJohn Marino 			ix, iter);
7849*ef5ccd6cSJohn Marino 	   ++ix)
7850*ef5ccd6cSJohn Marino 	{
7851*ef5ccd6cSJohn Marino 	  if (!self->regex
7852*ef5ccd6cSJohn Marino 	      || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7853*ef5ccd6cSJohn Marino 	    return;
7854*ef5ccd6cSJohn Marino 	}
7855*ef5ccd6cSJohn Marino     }
7856*ef5ccd6cSJohn Marino 
7857*ef5ccd6cSJohn Marino   bs->stop = 0;
7858*ef5ccd6cSJohn Marino   bs->print_it = print_it_noop;
7859*ef5ccd6cSJohn Marino }
7860*ef5ccd6cSJohn Marino 
7861*ef5ccd6cSJohn Marino static enum print_stop_action
print_it_catch_solib(bpstat bs)7862*ef5ccd6cSJohn Marino print_it_catch_solib (bpstat bs)
7863*ef5ccd6cSJohn Marino {
7864*ef5ccd6cSJohn Marino   struct breakpoint *b = bs->breakpoint_at;
7865*ef5ccd6cSJohn Marino   struct ui_out *uiout = current_uiout;
7866*ef5ccd6cSJohn Marino 
7867*ef5ccd6cSJohn Marino   annotate_catchpoint (b->number);
7868*ef5ccd6cSJohn Marino   if (b->disposition == disp_del)
7869*ef5ccd6cSJohn Marino     ui_out_text (uiout, "\nTemporary catchpoint ");
7870*ef5ccd6cSJohn Marino   else
7871*ef5ccd6cSJohn Marino     ui_out_text (uiout, "\nCatchpoint ");
7872*ef5ccd6cSJohn Marino   ui_out_field_int (uiout, "bkptno", b->number);
7873*ef5ccd6cSJohn Marino   ui_out_text (uiout, "\n");
7874*ef5ccd6cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
7875*ef5ccd6cSJohn Marino     ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7876*ef5ccd6cSJohn Marino   print_solib_event (1);
7877*ef5ccd6cSJohn Marino   return PRINT_SRC_AND_LOC;
7878*ef5ccd6cSJohn Marino }
7879*ef5ccd6cSJohn Marino 
7880*ef5ccd6cSJohn Marino static void
print_one_catch_solib(struct breakpoint * b,struct bp_location ** locs)7881*ef5ccd6cSJohn Marino print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7882*ef5ccd6cSJohn Marino {
7883*ef5ccd6cSJohn Marino   struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7884*ef5ccd6cSJohn Marino   struct value_print_options opts;
7885*ef5ccd6cSJohn Marino   struct ui_out *uiout = current_uiout;
7886*ef5ccd6cSJohn Marino   char *msg;
7887*ef5ccd6cSJohn Marino 
7888*ef5ccd6cSJohn Marino   get_user_print_options (&opts);
7889*ef5ccd6cSJohn Marino   /* Field 4, the address, is omitted (which makes the columns not
7890*ef5ccd6cSJohn Marino      line up too nicely with the headers, but the effect is relatively
7891*ef5ccd6cSJohn Marino      readable).  */
7892*ef5ccd6cSJohn Marino   if (opts.addressprint)
7893*ef5ccd6cSJohn Marino     {
7894*ef5ccd6cSJohn Marino       annotate_field (4);
7895*ef5ccd6cSJohn Marino       ui_out_field_skip (uiout, "addr");
7896*ef5ccd6cSJohn Marino     }
7897*ef5ccd6cSJohn Marino 
7898*ef5ccd6cSJohn Marino   annotate_field (5);
7899*ef5ccd6cSJohn Marino   if (self->is_load)
7900*ef5ccd6cSJohn Marino     {
7901*ef5ccd6cSJohn Marino       if (self->regex)
7902*ef5ccd6cSJohn Marino 	msg = xstrprintf (_("load of library matching %s"), self->regex);
7903*ef5ccd6cSJohn Marino       else
7904*ef5ccd6cSJohn Marino 	msg = xstrdup (_("load of library"));
7905*ef5ccd6cSJohn Marino     }
7906*ef5ccd6cSJohn Marino   else
7907*ef5ccd6cSJohn Marino     {
7908*ef5ccd6cSJohn Marino       if (self->regex)
7909*ef5ccd6cSJohn Marino 	msg = xstrprintf (_("unload of library matching %s"), self->regex);
7910*ef5ccd6cSJohn Marino       else
7911*ef5ccd6cSJohn Marino 	msg = xstrdup (_("unload of library"));
7912*ef5ccd6cSJohn Marino     }
7913*ef5ccd6cSJohn Marino   ui_out_field_string (uiout, "what", msg);
7914*ef5ccd6cSJohn Marino   xfree (msg);
7915*ef5ccd6cSJohn Marino 
7916*ef5ccd6cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
7917*ef5ccd6cSJohn Marino     ui_out_field_string (uiout, "catch-type",
7918*ef5ccd6cSJohn Marino 			 self->is_load ? "load" : "unload");
7919*ef5ccd6cSJohn Marino }
7920*ef5ccd6cSJohn Marino 
7921*ef5ccd6cSJohn Marino static void
print_mention_catch_solib(struct breakpoint * b)7922*ef5ccd6cSJohn Marino print_mention_catch_solib (struct breakpoint *b)
7923*ef5ccd6cSJohn Marino {
7924*ef5ccd6cSJohn Marino   struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7925*ef5ccd6cSJohn Marino 
7926*ef5ccd6cSJohn Marino   printf_filtered (_("Catchpoint %d (%s)"), b->number,
7927*ef5ccd6cSJohn Marino 		   self->is_load ? "load" : "unload");
7928*ef5ccd6cSJohn Marino }
7929*ef5ccd6cSJohn Marino 
7930*ef5ccd6cSJohn Marino static void
print_recreate_catch_solib(struct breakpoint * b,struct ui_file * fp)7931*ef5ccd6cSJohn Marino print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7932*ef5ccd6cSJohn Marino {
7933*ef5ccd6cSJohn Marino   struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7934*ef5ccd6cSJohn Marino 
7935*ef5ccd6cSJohn Marino   fprintf_unfiltered (fp, "%s %s",
7936*ef5ccd6cSJohn Marino 		      b->disposition == disp_del ? "tcatch" : "catch",
7937*ef5ccd6cSJohn Marino 		      self->is_load ? "load" : "unload");
7938*ef5ccd6cSJohn Marino   if (self->regex)
7939*ef5ccd6cSJohn Marino     fprintf_unfiltered (fp, " %s", self->regex);
7940*ef5ccd6cSJohn Marino   fprintf_unfiltered (fp, "\n");
7941*ef5ccd6cSJohn Marino }
7942*ef5ccd6cSJohn Marino 
7943*ef5ccd6cSJohn Marino static struct breakpoint_ops catch_solib_breakpoint_ops;
7944*ef5ccd6cSJohn Marino 
7945*ef5ccd6cSJohn Marino /* Shared helper function (MI and CLI) for creating and installing
7946*ef5ccd6cSJohn Marino    a shared object event catchpoint.  If IS_LOAD is non-zero then
7947*ef5ccd6cSJohn Marino    the events to be caught are load events, otherwise they are
7948*ef5ccd6cSJohn Marino    unload events.  If IS_TEMP is non-zero the catchpoint is a
7949*ef5ccd6cSJohn Marino    temporary one.  If ENABLED is non-zero the catchpoint is
7950*ef5ccd6cSJohn Marino    created in an enabled state.  */
7951*ef5ccd6cSJohn Marino 
7952*ef5ccd6cSJohn Marino void
add_solib_catchpoint(char * arg,int is_load,int is_temp,int enabled)7953*ef5ccd6cSJohn Marino add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled)
7954*ef5ccd6cSJohn Marino {
7955*ef5ccd6cSJohn Marino   struct solib_catchpoint *c;
7956*ef5ccd6cSJohn Marino   struct gdbarch *gdbarch = get_current_arch ();
7957*ef5ccd6cSJohn Marino   struct cleanup *cleanup;
7958*ef5ccd6cSJohn Marino 
7959*ef5ccd6cSJohn Marino   if (!arg)
7960*ef5ccd6cSJohn Marino     arg = "";
7961*ef5ccd6cSJohn Marino   arg = skip_spaces (arg);
7962*ef5ccd6cSJohn Marino 
7963*ef5ccd6cSJohn Marino   c = XCNEW (struct solib_catchpoint);
7964*ef5ccd6cSJohn Marino   cleanup = make_cleanup (xfree, c);
7965*ef5ccd6cSJohn Marino 
7966*ef5ccd6cSJohn Marino   if (*arg != '\0')
7967*ef5ccd6cSJohn Marino     {
7968*ef5ccd6cSJohn Marino       int errcode;
7969*ef5ccd6cSJohn Marino 
7970*ef5ccd6cSJohn Marino       errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7971*ef5ccd6cSJohn Marino       if (errcode != 0)
7972*ef5ccd6cSJohn Marino 	{
7973*ef5ccd6cSJohn Marino 	  char *err = get_regcomp_error (errcode, &c->compiled);
7974*ef5ccd6cSJohn Marino 
7975*ef5ccd6cSJohn Marino 	  make_cleanup (xfree, err);
7976*ef5ccd6cSJohn Marino 	  error (_("Invalid regexp (%s): %s"), err, arg);
7977*ef5ccd6cSJohn Marino 	}
7978*ef5ccd6cSJohn Marino       c->regex = xstrdup (arg);
7979*ef5ccd6cSJohn Marino     }
7980*ef5ccd6cSJohn Marino 
7981*ef5ccd6cSJohn Marino   c->is_load = is_load;
7982*ef5ccd6cSJohn Marino   init_catchpoint (&c->base, gdbarch, is_temp, NULL,
7983*ef5ccd6cSJohn Marino 		   &catch_solib_breakpoint_ops);
7984*ef5ccd6cSJohn Marino 
7985*ef5ccd6cSJohn Marino   c->base.enable_state = enabled ? bp_enabled : bp_disabled;
7986*ef5ccd6cSJohn Marino 
7987*ef5ccd6cSJohn Marino   discard_cleanups (cleanup);
7988*ef5ccd6cSJohn Marino   install_breakpoint (0, &c->base, 1);
7989*ef5ccd6cSJohn Marino }
7990*ef5ccd6cSJohn Marino 
7991*ef5ccd6cSJohn Marino /* A helper function that does all the work for "catch load" and
7992*ef5ccd6cSJohn Marino    "catch unload".  */
7993*ef5ccd6cSJohn Marino 
7994*ef5ccd6cSJohn Marino static void
catch_load_or_unload(char * arg,int from_tty,int is_load,struct cmd_list_element * command)7995*ef5ccd6cSJohn Marino catch_load_or_unload (char *arg, int from_tty, int is_load,
7996*ef5ccd6cSJohn Marino 		      struct cmd_list_element *command)
7997*ef5ccd6cSJohn Marino {
7998*ef5ccd6cSJohn Marino   int tempflag;
7999*ef5ccd6cSJohn Marino   const int enabled = 1;
8000*ef5ccd6cSJohn Marino 
8001*ef5ccd6cSJohn Marino   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
8002*ef5ccd6cSJohn Marino 
8003*ef5ccd6cSJohn Marino   add_solib_catchpoint (arg, is_load, tempflag, enabled);
8004*ef5ccd6cSJohn Marino }
8005*ef5ccd6cSJohn Marino 
8006*ef5ccd6cSJohn Marino static void
catch_load_command_1(char * arg,int from_tty,struct cmd_list_element * command)8007*ef5ccd6cSJohn Marino catch_load_command_1 (char *arg, int from_tty,
8008*ef5ccd6cSJohn Marino 		      struct cmd_list_element *command)
8009*ef5ccd6cSJohn Marino {
8010*ef5ccd6cSJohn Marino   catch_load_or_unload (arg, from_tty, 1, command);
8011*ef5ccd6cSJohn Marino }
8012*ef5ccd6cSJohn Marino 
8013*ef5ccd6cSJohn Marino static void
catch_unload_command_1(char * arg,int from_tty,struct cmd_list_element * command)8014*ef5ccd6cSJohn Marino catch_unload_command_1 (char *arg, int from_tty,
8015*ef5ccd6cSJohn Marino 			struct cmd_list_element *command)
8016*ef5ccd6cSJohn Marino {
8017*ef5ccd6cSJohn Marino   catch_load_or_unload (arg, from_tty, 0, command);
8018*ef5ccd6cSJohn Marino }
8019*ef5ccd6cSJohn Marino 
8020a45ae5f8SJohn Marino /* An instance of this type is used to represent a syscall catchpoint.
8021a45ae5f8SJohn Marino    It includes a "struct breakpoint" as a kind of base class; users
8022a45ae5f8SJohn Marino    downcast to "struct breakpoint *" when needed.  A breakpoint is
8023a45ae5f8SJohn Marino    really of this type iff its ops pointer points to
8024a45ae5f8SJohn Marino    CATCH_SYSCALL_BREAKPOINT_OPS.  */
8025a45ae5f8SJohn Marino 
8026a45ae5f8SJohn Marino struct syscall_catchpoint
80275796c8dcSSimon Schubert {
8028a45ae5f8SJohn Marino   /* The base class.  */
8029a45ae5f8SJohn Marino   struct breakpoint base;
8030a45ae5f8SJohn Marino 
8031a45ae5f8SJohn Marino   /* Syscall numbers used for the 'catch syscall' feature.  If no
8032a45ae5f8SJohn Marino      syscall has been specified for filtering, its value is NULL.
8033a45ae5f8SJohn Marino      Otherwise, it holds a list of all syscalls to be caught.  The
8034a45ae5f8SJohn Marino      list elements are allocated with xmalloc.  */
8035a45ae5f8SJohn Marino   VEC(int) *syscalls_to_be_caught;
80365796c8dcSSimon Schubert };
80375796c8dcSSimon Schubert 
8038a45ae5f8SJohn Marino /* Implement the "dtor" breakpoint_ops method for syscall
8039a45ae5f8SJohn Marino    catchpoints.  */
8040a45ae5f8SJohn Marino 
8041a45ae5f8SJohn Marino static void
dtor_catch_syscall(struct breakpoint * b)8042a45ae5f8SJohn Marino dtor_catch_syscall (struct breakpoint *b)
8043a45ae5f8SJohn Marino {
8044a45ae5f8SJohn Marino   struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8045a45ae5f8SJohn Marino 
8046a45ae5f8SJohn Marino   VEC_free (int, c->syscalls_to_be_caught);
8047a45ae5f8SJohn Marino 
8048a45ae5f8SJohn Marino   base_breakpoint_ops.dtor (b);
8049a45ae5f8SJohn Marino }
8050a45ae5f8SJohn Marino 
8051*ef5ccd6cSJohn Marino static const struct inferior_data *catch_syscall_inferior_data = NULL;
8052*ef5ccd6cSJohn Marino 
8053*ef5ccd6cSJohn Marino struct catch_syscall_inferior_data
8054*ef5ccd6cSJohn Marino {
8055*ef5ccd6cSJohn Marino   /* We keep a count of the number of times the user has requested a
8056*ef5ccd6cSJohn Marino      particular syscall to be tracked, and pass this information to the
8057*ef5ccd6cSJohn Marino      target.  This lets capable targets implement filtering directly.  */
8058*ef5ccd6cSJohn Marino 
8059*ef5ccd6cSJohn Marino   /* Number of times that "any" syscall is requested.  */
8060*ef5ccd6cSJohn Marino   int any_syscall_count;
8061*ef5ccd6cSJohn Marino 
8062*ef5ccd6cSJohn Marino   /* Count of each system call.  */
8063*ef5ccd6cSJohn Marino   VEC(int) *syscalls_counts;
8064*ef5ccd6cSJohn Marino 
8065*ef5ccd6cSJohn Marino   /* This counts all syscall catch requests, so we can readily determine
8066*ef5ccd6cSJohn Marino      if any catching is necessary.  */
8067*ef5ccd6cSJohn Marino   int total_syscalls_count;
8068*ef5ccd6cSJohn Marino };
8069*ef5ccd6cSJohn Marino 
8070*ef5ccd6cSJohn Marino static struct catch_syscall_inferior_data*
get_catch_syscall_inferior_data(struct inferior * inf)8071*ef5ccd6cSJohn Marino get_catch_syscall_inferior_data (struct inferior *inf)
8072*ef5ccd6cSJohn Marino {
8073*ef5ccd6cSJohn Marino   struct catch_syscall_inferior_data *inf_data;
8074*ef5ccd6cSJohn Marino 
8075*ef5ccd6cSJohn Marino   inf_data = inferior_data (inf, catch_syscall_inferior_data);
8076*ef5ccd6cSJohn Marino   if (inf_data == NULL)
8077*ef5ccd6cSJohn Marino     {
8078*ef5ccd6cSJohn Marino       inf_data = XZALLOC (struct catch_syscall_inferior_data);
8079*ef5ccd6cSJohn Marino       set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
8080*ef5ccd6cSJohn Marino     }
8081*ef5ccd6cSJohn Marino 
8082*ef5ccd6cSJohn Marino   return inf_data;
8083*ef5ccd6cSJohn Marino }
8084*ef5ccd6cSJohn Marino 
8085*ef5ccd6cSJohn Marino static void
catch_syscall_inferior_data_cleanup(struct inferior * inf,void * arg)8086*ef5ccd6cSJohn Marino catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
8087*ef5ccd6cSJohn Marino {
8088*ef5ccd6cSJohn Marino   xfree (arg);
8089*ef5ccd6cSJohn Marino }
8090*ef5ccd6cSJohn Marino 
8091*ef5ccd6cSJohn Marino 
80925796c8dcSSimon Schubert /* Implement the "insert" breakpoint_ops method for syscall
80935796c8dcSSimon Schubert    catchpoints.  */
80945796c8dcSSimon Schubert 
8095c50c785cSJohn Marino static int
insert_catch_syscall(struct bp_location * bl)8096c50c785cSJohn Marino insert_catch_syscall (struct bp_location *bl)
80975796c8dcSSimon Schubert {
8098a45ae5f8SJohn Marino   struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
80995796c8dcSSimon Schubert   struct inferior *inf = current_inferior ();
8100*ef5ccd6cSJohn Marino   struct catch_syscall_inferior_data *inf_data
8101*ef5ccd6cSJohn Marino     = get_catch_syscall_inferior_data (inf);
81025796c8dcSSimon Schubert 
8103*ef5ccd6cSJohn Marino   ++inf_data->total_syscalls_count;
8104a45ae5f8SJohn Marino   if (!c->syscalls_to_be_caught)
8105*ef5ccd6cSJohn Marino     ++inf_data->any_syscall_count;
81065796c8dcSSimon Schubert   else
81075796c8dcSSimon Schubert     {
81085796c8dcSSimon Schubert       int i, iter;
8109cf7f2e2dSJohn Marino 
81105796c8dcSSimon Schubert       for (i = 0;
8111a45ae5f8SJohn Marino            VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
81125796c8dcSSimon Schubert            i++)
81135796c8dcSSimon Schubert 	{
81145796c8dcSSimon Schubert           int elem;
8115cf7f2e2dSJohn Marino 
8116*ef5ccd6cSJohn Marino 	  if (iter >= VEC_length (int, inf_data->syscalls_counts))
81175796c8dcSSimon Schubert 	    {
8118*ef5ccd6cSJohn Marino               int old_size = VEC_length (int, inf_data->syscalls_counts);
8119c50c785cSJohn Marino               uintptr_t vec_addr_offset
8120c50c785cSJohn Marino 		= old_size * ((uintptr_t) sizeof (int));
81215796c8dcSSimon Schubert               uintptr_t vec_addr;
8122*ef5ccd6cSJohn Marino               VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
8123*ef5ccd6cSJohn Marino               vec_addr = ((uintptr_t) VEC_address (int,
8124*ef5ccd6cSJohn Marino 						  inf_data->syscalls_counts)
8125*ef5ccd6cSJohn Marino 			  + vec_addr_offset);
81265796c8dcSSimon Schubert               memset ((void *) vec_addr, 0,
81275796c8dcSSimon Schubert                       (iter + 1 - old_size) * sizeof (int));
81285796c8dcSSimon Schubert 	    }
8129*ef5ccd6cSJohn Marino           elem = VEC_index (int, inf_data->syscalls_counts, iter);
8130*ef5ccd6cSJohn Marino           VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
81315796c8dcSSimon Schubert 	}
81325796c8dcSSimon Schubert     }
81335796c8dcSSimon Schubert 
8134c50c785cSJohn Marino   return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
8135*ef5ccd6cSJohn Marino 					inf_data->total_syscalls_count != 0,
8136*ef5ccd6cSJohn Marino 					inf_data->any_syscall_count,
8137*ef5ccd6cSJohn Marino 					VEC_length (int,
8138*ef5ccd6cSJohn Marino 						    inf_data->syscalls_counts),
8139*ef5ccd6cSJohn Marino 					VEC_address (int,
8140*ef5ccd6cSJohn Marino 						     inf_data->syscalls_counts));
81415796c8dcSSimon Schubert }
81425796c8dcSSimon Schubert 
81435796c8dcSSimon Schubert /* Implement the "remove" breakpoint_ops method for syscall
81445796c8dcSSimon Schubert    catchpoints.  */
81455796c8dcSSimon Schubert 
81465796c8dcSSimon Schubert static int
remove_catch_syscall(struct bp_location * bl)8147c50c785cSJohn Marino remove_catch_syscall (struct bp_location *bl)
81485796c8dcSSimon Schubert {
8149a45ae5f8SJohn Marino   struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
81505796c8dcSSimon Schubert   struct inferior *inf = current_inferior ();
8151*ef5ccd6cSJohn Marino   struct catch_syscall_inferior_data *inf_data
8152*ef5ccd6cSJohn Marino     = get_catch_syscall_inferior_data (inf);
81535796c8dcSSimon Schubert 
8154*ef5ccd6cSJohn Marino   --inf_data->total_syscalls_count;
8155a45ae5f8SJohn Marino   if (!c->syscalls_to_be_caught)
8156*ef5ccd6cSJohn Marino     --inf_data->any_syscall_count;
81575796c8dcSSimon Schubert   else
81585796c8dcSSimon Schubert     {
81595796c8dcSSimon Schubert       int i, iter;
8160cf7f2e2dSJohn Marino 
81615796c8dcSSimon Schubert       for (i = 0;
8162a45ae5f8SJohn Marino            VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
81635796c8dcSSimon Schubert            i++)
81645796c8dcSSimon Schubert 	{
81655796c8dcSSimon Schubert           int elem;
8166*ef5ccd6cSJohn Marino 	  if (iter >= VEC_length (int, inf_data->syscalls_counts))
81675796c8dcSSimon Schubert 	    /* Shouldn't happen.  */
81685796c8dcSSimon Schubert 	    continue;
8169*ef5ccd6cSJohn Marino           elem = VEC_index (int, inf_data->syscalls_counts, iter);
8170*ef5ccd6cSJohn Marino           VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
81715796c8dcSSimon Schubert         }
81725796c8dcSSimon Schubert     }
81735796c8dcSSimon Schubert 
81745796c8dcSSimon Schubert   return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
8175*ef5ccd6cSJohn Marino 					inf_data->total_syscalls_count != 0,
8176*ef5ccd6cSJohn Marino 					inf_data->any_syscall_count,
8177*ef5ccd6cSJohn Marino 					VEC_length (int,
8178*ef5ccd6cSJohn Marino 						    inf_data->syscalls_counts),
8179c50c785cSJohn Marino 					VEC_address (int,
8180*ef5ccd6cSJohn Marino 						     inf_data->syscalls_counts));
81815796c8dcSSimon Schubert }
81825796c8dcSSimon Schubert 
81835796c8dcSSimon Schubert /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
81845796c8dcSSimon Schubert    catchpoints.  */
81855796c8dcSSimon Schubert 
81865796c8dcSSimon Schubert static int
breakpoint_hit_catch_syscall(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)8187c50c785cSJohn Marino breakpoint_hit_catch_syscall (const struct bp_location *bl,
8188*ef5ccd6cSJohn Marino 			      struct address_space *aspace, CORE_ADDR bp_addr,
8189*ef5ccd6cSJohn Marino 			      const struct target_waitstatus *ws)
81905796c8dcSSimon Schubert {
8191c50c785cSJohn Marino   /* We must check if we are catching specific syscalls in this
8192c50c785cSJohn Marino      breakpoint.  If we are, then we must guarantee that the called
8193c50c785cSJohn Marino      syscall is the same syscall we are catching.  */
81945796c8dcSSimon Schubert   int syscall_number = 0;
8195a45ae5f8SJohn Marino   const struct syscall_catchpoint *c
8196a45ae5f8SJohn Marino     = (const struct syscall_catchpoint *) bl->owner;
81975796c8dcSSimon Schubert 
8198*ef5ccd6cSJohn Marino   if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
8199*ef5ccd6cSJohn Marino       && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
82005796c8dcSSimon Schubert     return 0;
82015796c8dcSSimon Schubert 
8202*ef5ccd6cSJohn Marino   syscall_number = ws->value.syscall_number;
8203*ef5ccd6cSJohn Marino 
82045796c8dcSSimon Schubert   /* Now, checking if the syscall is the same.  */
8205a45ae5f8SJohn Marino   if (c->syscalls_to_be_caught)
82065796c8dcSSimon Schubert     {
82075796c8dcSSimon Schubert       int i, iter;
8208cf7f2e2dSJohn Marino 
82095796c8dcSSimon Schubert       for (i = 0;
8210a45ae5f8SJohn Marino            VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
82115796c8dcSSimon Schubert            i++)
82125796c8dcSSimon Schubert 	if (syscall_number == iter)
82135796c8dcSSimon Schubert 	  break;
82145796c8dcSSimon Schubert       /* Not the same.  */
82155796c8dcSSimon Schubert       if (!iter)
82165796c8dcSSimon Schubert 	return 0;
82175796c8dcSSimon Schubert     }
82185796c8dcSSimon Schubert 
82195796c8dcSSimon Schubert   return 1;
82205796c8dcSSimon Schubert }
82215796c8dcSSimon Schubert 
82225796c8dcSSimon Schubert /* Implement the "print_it" breakpoint_ops method for syscall
82235796c8dcSSimon Schubert    catchpoints.  */
82245796c8dcSSimon Schubert 
82255796c8dcSSimon Schubert static enum print_stop_action
print_it_catch_syscall(bpstat bs)8226a45ae5f8SJohn Marino print_it_catch_syscall (bpstat bs)
82275796c8dcSSimon Schubert {
8228a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
8229a45ae5f8SJohn Marino   struct breakpoint *b = bs->breakpoint_at;
82305796c8dcSSimon Schubert   /* These are needed because we want to know in which state a
82315796c8dcSSimon Schubert      syscall is.  It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
82325796c8dcSSimon Schubert      or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
82335796c8dcSSimon Schubert      must print "called syscall" or "returned from syscall".  */
82345796c8dcSSimon Schubert   ptid_t ptid;
82355796c8dcSSimon Schubert   struct target_waitstatus last;
82365796c8dcSSimon Schubert   struct syscall s;
82375796c8dcSSimon Schubert 
82385796c8dcSSimon Schubert   get_last_target_status (&ptid, &last);
82395796c8dcSSimon Schubert 
82405796c8dcSSimon Schubert   get_syscall_by_number (last.value.syscall_number, &s);
82415796c8dcSSimon Schubert 
82425796c8dcSSimon Schubert   annotate_catchpoint (b->number);
82435796c8dcSSimon Schubert 
8244a45ae5f8SJohn Marino   if (b->disposition == disp_del)
8245a45ae5f8SJohn Marino     ui_out_text (uiout, "\nTemporary catchpoint ");
82465796c8dcSSimon Schubert   else
8247a45ae5f8SJohn Marino     ui_out_text (uiout, "\nCatchpoint ");
8248a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (uiout))
8249a45ae5f8SJohn Marino     {
8250a45ae5f8SJohn Marino       ui_out_field_string (uiout, "reason",
8251a45ae5f8SJohn Marino 			   async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
8252a45ae5f8SJohn Marino 						? EXEC_ASYNC_SYSCALL_ENTRY
8253a45ae5f8SJohn Marino 						: EXEC_ASYNC_SYSCALL_RETURN));
8254a45ae5f8SJohn Marino       ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8255a45ae5f8SJohn Marino     }
8256a45ae5f8SJohn Marino   ui_out_field_int (uiout, "bkptno", b->number);
82575796c8dcSSimon Schubert 
82585796c8dcSSimon Schubert   if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
8259a45ae5f8SJohn Marino     ui_out_text (uiout, " (call to syscall ");
8260a45ae5f8SJohn Marino   else
8261a45ae5f8SJohn Marino     ui_out_text (uiout, " (returned from syscall ");
82625796c8dcSSimon Schubert 
8263a45ae5f8SJohn Marino   if (s.name == NULL || ui_out_is_mi_like_p (uiout))
8264a45ae5f8SJohn Marino     ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
8265a45ae5f8SJohn Marino   if (s.name != NULL)
8266a45ae5f8SJohn Marino     ui_out_field_string (uiout, "syscall-name", s.name);
8267a45ae5f8SJohn Marino 
8268a45ae5f8SJohn Marino   ui_out_text (uiout, "), ");
82695796c8dcSSimon Schubert 
82705796c8dcSSimon Schubert   return PRINT_SRC_AND_LOC;
82715796c8dcSSimon Schubert }
82725796c8dcSSimon Schubert 
82735796c8dcSSimon Schubert /* Implement the "print_one" breakpoint_ops method for syscall
82745796c8dcSSimon Schubert    catchpoints.  */
82755796c8dcSSimon Schubert 
82765796c8dcSSimon Schubert static void
print_one_catch_syscall(struct breakpoint * b,struct bp_location ** last_loc)82775796c8dcSSimon Schubert print_one_catch_syscall (struct breakpoint *b,
82785796c8dcSSimon Schubert 			 struct bp_location **last_loc)
82795796c8dcSSimon Schubert {
8280a45ae5f8SJohn Marino   struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
82815796c8dcSSimon Schubert   struct value_print_options opts;
8282a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
82835796c8dcSSimon Schubert 
82845796c8dcSSimon Schubert   get_user_print_options (&opts);
8285c50c785cSJohn Marino   /* Field 4, the address, is omitted (which makes the columns not
8286c50c785cSJohn Marino      line up too nicely with the headers, but the effect is relatively
8287c50c785cSJohn Marino      readable).  */
82885796c8dcSSimon Schubert   if (opts.addressprint)
82895796c8dcSSimon Schubert     ui_out_field_skip (uiout, "addr");
82905796c8dcSSimon Schubert   annotate_field (5);
82915796c8dcSSimon Schubert 
8292a45ae5f8SJohn Marino   if (c->syscalls_to_be_caught
8293a45ae5f8SJohn Marino       && VEC_length (int, c->syscalls_to_be_caught) > 1)
82945796c8dcSSimon Schubert     ui_out_text (uiout, "syscalls \"");
82955796c8dcSSimon Schubert   else
82965796c8dcSSimon Schubert     ui_out_text (uiout, "syscall \"");
82975796c8dcSSimon Schubert 
8298a45ae5f8SJohn Marino   if (c->syscalls_to_be_caught)
82995796c8dcSSimon Schubert     {
83005796c8dcSSimon Schubert       int i, iter;
83015796c8dcSSimon Schubert       char *text = xstrprintf ("%s", "");
8302cf7f2e2dSJohn Marino 
83035796c8dcSSimon Schubert       for (i = 0;
8304a45ae5f8SJohn Marino            VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
83055796c8dcSSimon Schubert            i++)
83065796c8dcSSimon Schubert         {
83075796c8dcSSimon Schubert           char *x = text;
83085796c8dcSSimon Schubert           struct syscall s;
83095796c8dcSSimon Schubert           get_syscall_by_number (iter, &s);
83105796c8dcSSimon Schubert 
83115796c8dcSSimon Schubert           if (s.name != NULL)
83125796c8dcSSimon Schubert             text = xstrprintf ("%s%s, ", text, s.name);
83135796c8dcSSimon Schubert           else
83145796c8dcSSimon Schubert             text = xstrprintf ("%s%d, ", text, iter);
83155796c8dcSSimon Schubert 
83165796c8dcSSimon Schubert           /* We have to xfree the last 'text' (now stored at 'x')
8317a45ae5f8SJohn Marino              because xstrprintf dynamically allocates new space for it
83185796c8dcSSimon Schubert              on every call.  */
83195796c8dcSSimon Schubert 	  xfree (x);
83205796c8dcSSimon Schubert         }
83215796c8dcSSimon Schubert       /* Remove the last comma.  */
83225796c8dcSSimon Schubert       text[strlen (text) - 2] = '\0';
83235796c8dcSSimon Schubert       ui_out_field_string (uiout, "what", text);
83245796c8dcSSimon Schubert     }
83255796c8dcSSimon Schubert   else
83265796c8dcSSimon Schubert     ui_out_field_string (uiout, "what", "<any syscall>");
83275796c8dcSSimon Schubert   ui_out_text (uiout, "\" ");
8328*ef5ccd6cSJohn Marino 
8329*ef5ccd6cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
8330*ef5ccd6cSJohn Marino     ui_out_field_string (uiout, "catch-type", "syscall");
83315796c8dcSSimon Schubert }
83325796c8dcSSimon Schubert 
83335796c8dcSSimon Schubert /* Implement the "print_mention" breakpoint_ops method for syscall
83345796c8dcSSimon Schubert    catchpoints.  */
83355796c8dcSSimon Schubert 
83365796c8dcSSimon Schubert static void
print_mention_catch_syscall(struct breakpoint * b)83375796c8dcSSimon Schubert print_mention_catch_syscall (struct breakpoint *b)
83385796c8dcSSimon Schubert {
8339a45ae5f8SJohn Marino   struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8340a45ae5f8SJohn Marino 
8341a45ae5f8SJohn Marino   if (c->syscalls_to_be_caught)
83425796c8dcSSimon Schubert     {
83435796c8dcSSimon Schubert       int i, iter;
83445796c8dcSSimon Schubert 
8345a45ae5f8SJohn Marino       if (VEC_length (int, c->syscalls_to_be_caught) > 1)
83465796c8dcSSimon Schubert         printf_filtered (_("Catchpoint %d (syscalls"), b->number);
83475796c8dcSSimon Schubert       else
83485796c8dcSSimon Schubert         printf_filtered (_("Catchpoint %d (syscall"), b->number);
83495796c8dcSSimon Schubert 
83505796c8dcSSimon Schubert       for (i = 0;
8351a45ae5f8SJohn Marino            VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
83525796c8dcSSimon Schubert            i++)
83535796c8dcSSimon Schubert         {
83545796c8dcSSimon Schubert           struct syscall s;
83555796c8dcSSimon Schubert           get_syscall_by_number (iter, &s);
83565796c8dcSSimon Schubert 
83575796c8dcSSimon Schubert           if (s.name)
83585796c8dcSSimon Schubert             printf_filtered (" '%s' [%d]", s.name, s.number);
83595796c8dcSSimon Schubert           else
83605796c8dcSSimon Schubert             printf_filtered (" %d", s.number);
83615796c8dcSSimon Schubert         }
83625796c8dcSSimon Schubert       printf_filtered (")");
83635796c8dcSSimon Schubert     }
83645796c8dcSSimon Schubert   else
83655796c8dcSSimon Schubert     printf_filtered (_("Catchpoint %d (any syscall)"),
83665796c8dcSSimon Schubert                      b->number);
83675796c8dcSSimon Schubert }
83685796c8dcSSimon Schubert 
8369cf7f2e2dSJohn Marino /* Implement the "print_recreate" breakpoint_ops method for syscall
8370cf7f2e2dSJohn Marino    catchpoints.  */
8371cf7f2e2dSJohn Marino 
8372cf7f2e2dSJohn Marino static void
print_recreate_catch_syscall(struct breakpoint * b,struct ui_file * fp)8373cf7f2e2dSJohn Marino print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
8374cf7f2e2dSJohn Marino {
8375a45ae5f8SJohn Marino   struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
8376a45ae5f8SJohn Marino 
8377cf7f2e2dSJohn Marino   fprintf_unfiltered (fp, "catch syscall");
8378cf7f2e2dSJohn Marino 
8379a45ae5f8SJohn Marino   if (c->syscalls_to_be_caught)
8380cf7f2e2dSJohn Marino     {
8381cf7f2e2dSJohn Marino       int i, iter;
8382cf7f2e2dSJohn Marino 
8383cf7f2e2dSJohn Marino       for (i = 0;
8384a45ae5f8SJohn Marino            VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
8385cf7f2e2dSJohn Marino            i++)
8386cf7f2e2dSJohn Marino         {
8387cf7f2e2dSJohn Marino           struct syscall s;
8388cf7f2e2dSJohn Marino 
8389cf7f2e2dSJohn Marino           get_syscall_by_number (iter, &s);
8390cf7f2e2dSJohn Marino           if (s.name)
8391cf7f2e2dSJohn Marino             fprintf_unfiltered (fp, " %s", s.name);
8392cf7f2e2dSJohn Marino           else
8393cf7f2e2dSJohn Marino             fprintf_unfiltered (fp, " %d", s.number);
8394cf7f2e2dSJohn Marino         }
8395cf7f2e2dSJohn Marino     }
8396a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
8397cf7f2e2dSJohn Marino }
8398cf7f2e2dSJohn Marino 
83995796c8dcSSimon Schubert /* The breakpoint_ops structure to be used in syscall catchpoints.  */
84005796c8dcSSimon Schubert 
8401a45ae5f8SJohn Marino static struct breakpoint_ops catch_syscall_breakpoint_ops;
84025796c8dcSSimon Schubert 
84035796c8dcSSimon Schubert /* Returns non-zero if 'b' is a syscall catchpoint.  */
84045796c8dcSSimon Schubert 
84055796c8dcSSimon Schubert static int
syscall_catchpoint_p(struct breakpoint * b)84065796c8dcSSimon Schubert syscall_catchpoint_p (struct breakpoint *b)
84075796c8dcSSimon Schubert {
84085796c8dcSSimon Schubert   return (b->ops == &catch_syscall_breakpoint_ops);
84095796c8dcSSimon Schubert }
84105796c8dcSSimon Schubert 
8411a45ae5f8SJohn Marino /* Initialize a new breakpoint of the bp_catchpoint kind.  If TEMPFLAG
8412a45ae5f8SJohn Marino    is non-zero, then make the breakpoint temporary.  If COND_STRING is
8413a45ae5f8SJohn Marino    not NULL, then store it in the breakpoint.  OPS, if not NULL, is
8414a45ae5f8SJohn Marino    the breakpoint_ops structure associated to the catchpoint.  */
84155796c8dcSSimon Schubert 
8416*ef5ccd6cSJohn Marino void
init_catchpoint(struct breakpoint * b,struct gdbarch * gdbarch,int tempflag,char * cond_string,const struct breakpoint_ops * ops)8417a45ae5f8SJohn Marino init_catchpoint (struct breakpoint *b,
8418a45ae5f8SJohn Marino 		 struct gdbarch *gdbarch, int tempflag,
84195796c8dcSSimon Schubert 		 char *cond_string,
8420a45ae5f8SJohn Marino 		 const struct breakpoint_ops *ops)
84215796c8dcSSimon Schubert {
84225796c8dcSSimon Schubert   struct symtab_and_line sal;
84235796c8dcSSimon Schubert 
84245796c8dcSSimon Schubert   init_sal (&sal);
8425cf7f2e2dSJohn Marino   sal.pspace = current_program_space;
84265796c8dcSSimon Schubert 
8427a45ae5f8SJohn Marino   init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
84285796c8dcSSimon Schubert 
84295796c8dcSSimon Schubert   b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
84305796c8dcSSimon Schubert   b->disposition = tempflag ? disp_del : disp_donttouch;
84315796c8dcSSimon Schubert }
84325796c8dcSSimon Schubert 
8433a45ae5f8SJohn Marino void
install_breakpoint(int internal,struct breakpoint * b,int update_gll)8434a45ae5f8SJohn Marino install_breakpoint (int internal, struct breakpoint *b, int update_gll)
84355796c8dcSSimon Schubert {
8436a45ae5f8SJohn Marino   add_to_breakpoint_chain (b);
8437a45ae5f8SJohn Marino   set_breakpoint_number (internal, b);
8438*ef5ccd6cSJohn Marino   if (is_tracepoint (b))
8439*ef5ccd6cSJohn Marino     set_tracepoint_count (breakpoint_count);
8440a45ae5f8SJohn Marino   if (!internal)
84415796c8dcSSimon Schubert     mention (b);
8442a45ae5f8SJohn Marino   observer_notify_breakpoint_created (b);
84435796c8dcSSimon Schubert 
8444a45ae5f8SJohn Marino   if (update_gll)
8445a45ae5f8SJohn Marino     update_global_location_list (1);
84465796c8dcSSimon Schubert }
84475796c8dcSSimon Schubert 
84485796c8dcSSimon Schubert static void
create_fork_vfork_event_catchpoint(struct gdbarch * gdbarch,int tempflag,char * cond_string,const struct breakpoint_ops * ops)84495796c8dcSSimon Schubert create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
84505796c8dcSSimon Schubert 				    int tempflag, char *cond_string,
8451a45ae5f8SJohn Marino                                     const struct breakpoint_ops *ops)
84525796c8dcSSimon Schubert {
8453a45ae5f8SJohn Marino   struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
84545796c8dcSSimon Schubert 
8455a45ae5f8SJohn Marino   init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
8456a45ae5f8SJohn Marino 
8457a45ae5f8SJohn Marino   c->forked_inferior_pid = null_ptid;
8458a45ae5f8SJohn Marino 
8459a45ae5f8SJohn Marino   install_breakpoint (0, &c->base, 1);
84605796c8dcSSimon Schubert }
84615796c8dcSSimon Schubert 
84625796c8dcSSimon Schubert /* Exec catchpoints.  */
84635796c8dcSSimon Schubert 
8464a45ae5f8SJohn Marino /* An instance of this type is used to represent an exec catchpoint.
8465a45ae5f8SJohn Marino    It includes a "struct breakpoint" as a kind of base class; users
8466a45ae5f8SJohn Marino    downcast to "struct breakpoint *" when needed.  A breakpoint is
8467a45ae5f8SJohn Marino    really of this type iff its ops pointer points to
8468a45ae5f8SJohn Marino    CATCH_EXEC_BREAKPOINT_OPS.  */
8469a45ae5f8SJohn Marino 
8470a45ae5f8SJohn Marino struct exec_catchpoint
8471a45ae5f8SJohn Marino {
8472a45ae5f8SJohn Marino   /* The base class.  */
8473a45ae5f8SJohn Marino   struct breakpoint base;
8474a45ae5f8SJohn Marino 
8475a45ae5f8SJohn Marino   /* Filename of a program whose exec triggered this catchpoint.
8476a45ae5f8SJohn Marino      This field is only valid immediately after this catchpoint has
8477a45ae5f8SJohn Marino      triggered.  */
8478a45ae5f8SJohn Marino   char *exec_pathname;
8479a45ae5f8SJohn Marino };
8480a45ae5f8SJohn Marino 
8481a45ae5f8SJohn Marino /* Implement the "dtor" breakpoint_ops method for exec
8482a45ae5f8SJohn Marino    catchpoints.  */
8483a45ae5f8SJohn Marino 
8484a45ae5f8SJohn Marino static void
dtor_catch_exec(struct breakpoint * b)8485a45ae5f8SJohn Marino dtor_catch_exec (struct breakpoint *b)
8486a45ae5f8SJohn Marino {
8487a45ae5f8SJohn Marino   struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8488a45ae5f8SJohn Marino 
8489a45ae5f8SJohn Marino   xfree (c->exec_pathname);
8490a45ae5f8SJohn Marino 
8491a45ae5f8SJohn Marino   base_breakpoint_ops.dtor (b);
8492a45ae5f8SJohn Marino }
8493a45ae5f8SJohn Marino 
8494c50c785cSJohn Marino static int
insert_catch_exec(struct bp_location * bl)8495c50c785cSJohn Marino insert_catch_exec (struct bp_location *bl)
84965796c8dcSSimon Schubert {
8497c50c785cSJohn Marino   return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
84985796c8dcSSimon Schubert }
84995796c8dcSSimon Schubert 
85005796c8dcSSimon Schubert static int
remove_catch_exec(struct bp_location * bl)8501c50c785cSJohn Marino remove_catch_exec (struct bp_location *bl)
85025796c8dcSSimon Schubert {
85035796c8dcSSimon Schubert   return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
85045796c8dcSSimon Schubert }
85055796c8dcSSimon Schubert 
85065796c8dcSSimon Schubert static int
breakpoint_hit_catch_exec(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)8507c50c785cSJohn Marino breakpoint_hit_catch_exec (const struct bp_location *bl,
8508*ef5ccd6cSJohn Marino 			   struct address_space *aspace, CORE_ADDR bp_addr,
8509*ef5ccd6cSJohn Marino 			   const struct target_waitstatus *ws)
85105796c8dcSSimon Schubert {
8511a45ae5f8SJohn Marino   struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
8512a45ae5f8SJohn Marino 
8513*ef5ccd6cSJohn Marino   if (ws->kind != TARGET_WAITKIND_EXECD)
8514*ef5ccd6cSJohn Marino     return 0;
8515*ef5ccd6cSJohn Marino 
8516*ef5ccd6cSJohn Marino   c->exec_pathname = xstrdup (ws->value.execd_pathname);
8517*ef5ccd6cSJohn Marino   return 1;
85185796c8dcSSimon Schubert }
85195796c8dcSSimon Schubert 
85205796c8dcSSimon Schubert static enum print_stop_action
print_it_catch_exec(bpstat bs)8521a45ae5f8SJohn Marino print_it_catch_exec (bpstat bs)
85225796c8dcSSimon Schubert {
8523a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
8524a45ae5f8SJohn Marino   struct breakpoint *b = bs->breakpoint_at;
8525a45ae5f8SJohn Marino   struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8526a45ae5f8SJohn Marino 
85275796c8dcSSimon Schubert   annotate_catchpoint (b->number);
8528a45ae5f8SJohn Marino   if (b->disposition == disp_del)
8529a45ae5f8SJohn Marino     ui_out_text (uiout, "\nTemporary catchpoint ");
8530a45ae5f8SJohn Marino   else
8531a45ae5f8SJohn Marino     ui_out_text (uiout, "\nCatchpoint ");
8532a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (uiout))
8533a45ae5f8SJohn Marino     {
8534a45ae5f8SJohn Marino       ui_out_field_string (uiout, "reason",
8535a45ae5f8SJohn Marino 			   async_reason_lookup (EXEC_ASYNC_EXEC));
8536a45ae5f8SJohn Marino       ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8537a45ae5f8SJohn Marino     }
8538a45ae5f8SJohn Marino   ui_out_field_int (uiout, "bkptno", b->number);
8539a45ae5f8SJohn Marino   ui_out_text (uiout, " (exec'd ");
8540a45ae5f8SJohn Marino   ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8541a45ae5f8SJohn Marino   ui_out_text (uiout, "), ");
8542a45ae5f8SJohn Marino 
85435796c8dcSSimon Schubert   return PRINT_SRC_AND_LOC;
85445796c8dcSSimon Schubert }
85455796c8dcSSimon Schubert 
85465796c8dcSSimon Schubert static void
print_one_catch_exec(struct breakpoint * b,struct bp_location ** last_loc)85475796c8dcSSimon Schubert print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
85485796c8dcSSimon Schubert {
8549a45ae5f8SJohn Marino   struct exec_catchpoint *c = (struct exec_catchpoint *) b;
85505796c8dcSSimon Schubert   struct value_print_options opts;
8551a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
85525796c8dcSSimon Schubert 
85535796c8dcSSimon Schubert   get_user_print_options (&opts);
85545796c8dcSSimon Schubert 
85555796c8dcSSimon Schubert   /* Field 4, the address, is omitted (which makes the columns
85565796c8dcSSimon Schubert      not line up too nicely with the headers, but the effect
85575796c8dcSSimon Schubert      is relatively readable).  */
85585796c8dcSSimon Schubert   if (opts.addressprint)
85595796c8dcSSimon Schubert     ui_out_field_skip (uiout, "addr");
85605796c8dcSSimon Schubert   annotate_field (5);
85615796c8dcSSimon Schubert   ui_out_text (uiout, "exec");
8562a45ae5f8SJohn Marino   if (c->exec_pathname != NULL)
85635796c8dcSSimon Schubert     {
85645796c8dcSSimon Schubert       ui_out_text (uiout, ", program \"");
8565a45ae5f8SJohn Marino       ui_out_field_string (uiout, "what", c->exec_pathname);
85665796c8dcSSimon Schubert       ui_out_text (uiout, "\" ");
85675796c8dcSSimon Schubert     }
8568*ef5ccd6cSJohn Marino 
8569*ef5ccd6cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
8570*ef5ccd6cSJohn Marino     ui_out_field_string (uiout, "catch-type", "exec");
85715796c8dcSSimon Schubert }
85725796c8dcSSimon Schubert 
85735796c8dcSSimon Schubert static void
print_mention_catch_exec(struct breakpoint * b)85745796c8dcSSimon Schubert print_mention_catch_exec (struct breakpoint *b)
85755796c8dcSSimon Schubert {
85765796c8dcSSimon Schubert   printf_filtered (_("Catchpoint %d (exec)"), b->number);
85775796c8dcSSimon Schubert }
85785796c8dcSSimon Schubert 
8579cf7f2e2dSJohn Marino /* Implement the "print_recreate" breakpoint_ops method for exec
8580cf7f2e2dSJohn Marino    catchpoints.  */
8581cf7f2e2dSJohn Marino 
8582cf7f2e2dSJohn Marino static void
print_recreate_catch_exec(struct breakpoint * b,struct ui_file * fp)8583cf7f2e2dSJohn Marino print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8584cf7f2e2dSJohn Marino {
8585cf7f2e2dSJohn Marino   fprintf_unfiltered (fp, "catch exec");
8586a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
8587cf7f2e2dSJohn Marino }
8588cf7f2e2dSJohn Marino 
8589a45ae5f8SJohn Marino static struct breakpoint_ops catch_exec_breakpoint_ops;
85905796c8dcSSimon Schubert 
85915796c8dcSSimon Schubert static void
create_syscall_event_catchpoint(int tempflag,VEC (int)* filter,const struct breakpoint_ops * ops)85925796c8dcSSimon Schubert create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
8593a45ae5f8SJohn Marino                                  const struct breakpoint_ops *ops)
85945796c8dcSSimon Schubert {
8595a45ae5f8SJohn Marino   struct syscall_catchpoint *c;
85965796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_current_arch ();
85975796c8dcSSimon Schubert 
8598a45ae5f8SJohn Marino   c = XNEW (struct syscall_catchpoint);
8599a45ae5f8SJohn Marino   init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8600a45ae5f8SJohn Marino   c->syscalls_to_be_caught = filter;
86015796c8dcSSimon Schubert 
8602a45ae5f8SJohn Marino   install_breakpoint (0, &c->base, 1);
86035796c8dcSSimon Schubert }
86045796c8dcSSimon Schubert 
86055796c8dcSSimon Schubert static int
hw_breakpoint_used_count(void)86065796c8dcSSimon Schubert hw_breakpoint_used_count (void)
86075796c8dcSSimon Schubert {
86085796c8dcSSimon Schubert   int i = 0;
8609c50c785cSJohn Marino   struct breakpoint *b;
8610c50c785cSJohn Marino   struct bp_location *bl;
86115796c8dcSSimon Schubert 
86125796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
86135796c8dcSSimon Schubert   {
86145796c8dcSSimon Schubert     if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
8615c50c785cSJohn Marino       for (bl = b->loc; bl; bl = bl->next)
8616c50c785cSJohn Marino 	{
8617c50c785cSJohn Marino 	  /* Special types of hardware breakpoints may use more than
8618c50c785cSJohn Marino 	     one register.  */
8619c50c785cSJohn Marino 	  i += b->ops->resources_needed (bl);
86205796c8dcSSimon Schubert 	}
8621c50c785cSJohn Marino   }
86225796c8dcSSimon Schubert 
86235796c8dcSSimon Schubert   return i;
86245796c8dcSSimon Schubert }
86255796c8dcSSimon Schubert 
8626a45ae5f8SJohn Marino /* Returns the resources B would use if it were a hardware
8627a45ae5f8SJohn Marino    watchpoint.  */
8628a45ae5f8SJohn Marino 
86295796c8dcSSimon Schubert static int
hw_watchpoint_use_count(struct breakpoint * b)8630a45ae5f8SJohn Marino hw_watchpoint_use_count (struct breakpoint *b)
86315796c8dcSSimon Schubert {
86325796c8dcSSimon Schubert   int i = 0;
8633c50c785cSJohn Marino   struct bp_location *bl;
86345796c8dcSSimon Schubert 
8635c50c785cSJohn Marino   if (!breakpoint_enabled (b))
8636a45ae5f8SJohn Marino     return 0;
8637c50c785cSJohn Marino 
8638c50c785cSJohn Marino   for (bl = b->loc; bl; bl = bl->next)
8639c50c785cSJohn Marino     {
8640c50c785cSJohn Marino       /* Special types of hardware watchpoints may use more than
8641c50c785cSJohn Marino 	 one register.  */
8642c50c785cSJohn Marino       i += b->ops->resources_needed (bl);
8643c50c785cSJohn Marino     }
8644a45ae5f8SJohn Marino 
8645a45ae5f8SJohn Marino   return i;
8646a45ae5f8SJohn Marino }
8647a45ae5f8SJohn Marino 
8648a45ae5f8SJohn Marino /* Returns the sum the used resources of all hardware watchpoints of
8649a45ae5f8SJohn Marino    type TYPE in the breakpoints list.  Also returns in OTHER_TYPE_USED
8650a45ae5f8SJohn Marino    the sum of the used resources of all hardware watchpoints of other
8651a45ae5f8SJohn Marino    types _not_ TYPE.  */
8652a45ae5f8SJohn Marino 
8653a45ae5f8SJohn Marino static int
hw_watchpoint_used_count_others(struct breakpoint * except,enum bptype type,int * other_type_used)8654a45ae5f8SJohn Marino hw_watchpoint_used_count_others (struct breakpoint *except,
8655a45ae5f8SJohn Marino 				 enum bptype type, int *other_type_used)
8656a45ae5f8SJohn Marino {
8657a45ae5f8SJohn Marino   int i = 0;
8658a45ae5f8SJohn Marino   struct breakpoint *b;
8659a45ae5f8SJohn Marino 
8660a45ae5f8SJohn Marino   *other_type_used = 0;
8661a45ae5f8SJohn Marino   ALL_BREAKPOINTS (b)
8662a45ae5f8SJohn Marino     {
8663a45ae5f8SJohn Marino       if (b == except)
8664a45ae5f8SJohn Marino 	continue;
8665a45ae5f8SJohn Marino       if (!breakpoint_enabled (b))
8666a45ae5f8SJohn Marino 	continue;
8667a45ae5f8SJohn Marino 
8668a45ae5f8SJohn Marino       if (b->type == type)
8669a45ae5f8SJohn Marino 	i += hw_watchpoint_use_count (b);
8670cf7f2e2dSJohn Marino       else if (is_hardware_watchpoint (b))
86715796c8dcSSimon Schubert 	*other_type_used = 1;
86725796c8dcSSimon Schubert     }
8673c50c785cSJohn Marino 
86745796c8dcSSimon Schubert   return i;
86755796c8dcSSimon Schubert }
86765796c8dcSSimon Schubert 
86775796c8dcSSimon Schubert void
disable_watchpoints_before_interactive_call_start(void)86785796c8dcSSimon Schubert disable_watchpoints_before_interactive_call_start (void)
86795796c8dcSSimon Schubert {
86805796c8dcSSimon Schubert   struct breakpoint *b;
86815796c8dcSSimon Schubert 
86825796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
86835796c8dcSSimon Schubert   {
8684cf7f2e2dSJohn Marino     if (is_watchpoint (b) && breakpoint_enabled (b))
86855796c8dcSSimon Schubert       {
86865796c8dcSSimon Schubert 	b->enable_state = bp_call_disabled;
86875796c8dcSSimon Schubert 	update_global_location_list (0);
86885796c8dcSSimon Schubert       }
86895796c8dcSSimon Schubert   }
86905796c8dcSSimon Schubert }
86915796c8dcSSimon Schubert 
86925796c8dcSSimon Schubert void
enable_watchpoints_after_interactive_call_stop(void)86935796c8dcSSimon Schubert enable_watchpoints_after_interactive_call_stop (void)
86945796c8dcSSimon Schubert {
86955796c8dcSSimon Schubert   struct breakpoint *b;
86965796c8dcSSimon Schubert 
86975796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
86985796c8dcSSimon Schubert   {
8699cf7f2e2dSJohn Marino     if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
87005796c8dcSSimon Schubert       {
87015796c8dcSSimon Schubert 	b->enable_state = bp_enabled;
87025796c8dcSSimon Schubert 	update_global_location_list (1);
87035796c8dcSSimon Schubert       }
87045796c8dcSSimon Schubert   }
87055796c8dcSSimon Schubert }
87065796c8dcSSimon Schubert 
87075796c8dcSSimon Schubert void
disable_breakpoints_before_startup(void)87085796c8dcSSimon Schubert disable_breakpoints_before_startup (void)
87095796c8dcSSimon Schubert {
8710cf7f2e2dSJohn Marino   current_program_space->executing_startup = 1;
8711a45ae5f8SJohn Marino   update_global_location_list (0);
87125796c8dcSSimon Schubert }
87135796c8dcSSimon Schubert 
87145796c8dcSSimon Schubert void
enable_breakpoints_after_startup(void)87155796c8dcSSimon Schubert enable_breakpoints_after_startup (void)
87165796c8dcSSimon Schubert {
8717cf7f2e2dSJohn Marino   current_program_space->executing_startup = 0;
87185796c8dcSSimon Schubert   breakpoint_re_set ();
87195796c8dcSSimon Schubert }
87205796c8dcSSimon Schubert 
87215796c8dcSSimon Schubert 
87225796c8dcSSimon Schubert /* Set a breakpoint that will evaporate an end of command
87235796c8dcSSimon Schubert    at address specified by SAL.
87245796c8dcSSimon Schubert    Restrict it to frame FRAME if FRAME is nonzero.  */
87255796c8dcSSimon Schubert 
87265796c8dcSSimon Schubert struct breakpoint *
set_momentary_breakpoint(struct gdbarch * gdbarch,struct symtab_and_line sal,struct frame_id frame_id,enum bptype type)87275796c8dcSSimon Schubert set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
87285796c8dcSSimon Schubert 			  struct frame_id frame_id, enum bptype type)
87295796c8dcSSimon Schubert {
87305796c8dcSSimon Schubert   struct breakpoint *b;
87315796c8dcSSimon Schubert 
8732*ef5ccd6cSJohn Marino   /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8733*ef5ccd6cSJohn Marino      tail-called one.  */
8734*ef5ccd6cSJohn Marino   gdb_assert (!frame_id_artificial_p (frame_id));
87355796c8dcSSimon Schubert 
8736a45ae5f8SJohn Marino   b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
87375796c8dcSSimon Schubert   b->enable_state = bp_enabled;
87385796c8dcSSimon Schubert   b->disposition = disp_donttouch;
87395796c8dcSSimon Schubert   b->frame_id = frame_id;
87405796c8dcSSimon Schubert 
8741c50c785cSJohn Marino   /* If we're debugging a multi-threaded program, then we want
8742c50c785cSJohn Marino      momentary breakpoints to be active in only a single thread of
8743c50c785cSJohn Marino      control.  */
87445796c8dcSSimon Schubert   if (in_thread_list (inferior_ptid))
87455796c8dcSSimon Schubert     b->thread = pid_to_thread_id (inferior_ptid);
87465796c8dcSSimon Schubert 
87475796c8dcSSimon Schubert   update_global_location_list_nothrow (1);
87485796c8dcSSimon Schubert 
87495796c8dcSSimon Schubert   return b;
87505796c8dcSSimon Schubert }
87515796c8dcSSimon Schubert 
8752a45ae5f8SJohn Marino /* Make a momentary breakpoint based on the master breakpoint ORIG.
8753a45ae5f8SJohn Marino    The new breakpoint will have type TYPE, and use OPS as it
8754a45ae5f8SJohn Marino    breakpoint_ops.  */
87555796c8dcSSimon Schubert 
8756a45ae5f8SJohn Marino static struct breakpoint *
momentary_breakpoint_from_master(struct breakpoint * orig,enum bptype type,const struct breakpoint_ops * ops)8757a45ae5f8SJohn Marino momentary_breakpoint_from_master (struct breakpoint *orig,
8758a45ae5f8SJohn Marino 				  enum bptype type,
8759a45ae5f8SJohn Marino 				  const struct breakpoint_ops *ops)
87605796c8dcSSimon Schubert {
87615796c8dcSSimon Schubert   struct breakpoint *copy;
87625796c8dcSSimon Schubert 
8763a45ae5f8SJohn Marino   copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
87645796c8dcSSimon Schubert   copy->loc = allocate_bp_location (copy);
8765c50c785cSJohn Marino   set_breakpoint_location_function (copy->loc, 1);
87665796c8dcSSimon Schubert 
87675796c8dcSSimon Schubert   copy->loc->gdbarch = orig->loc->gdbarch;
87685796c8dcSSimon Schubert   copy->loc->requested_address = orig->loc->requested_address;
87695796c8dcSSimon Schubert   copy->loc->address = orig->loc->address;
87705796c8dcSSimon Schubert   copy->loc->section = orig->loc->section;
8771cf7f2e2dSJohn Marino   copy->loc->pspace = orig->loc->pspace;
8772*ef5ccd6cSJohn Marino   copy->loc->probe = orig->loc->probe;
8773a45ae5f8SJohn Marino   copy->loc->line_number = orig->loc->line_number;
8774*ef5ccd6cSJohn Marino   copy->loc->symtab = orig->loc->symtab;
87755796c8dcSSimon Schubert   copy->frame_id = orig->frame_id;
87765796c8dcSSimon Schubert   copy->thread = orig->thread;
8777cf7f2e2dSJohn Marino   copy->pspace = orig->pspace;
87785796c8dcSSimon Schubert 
87795796c8dcSSimon Schubert   copy->enable_state = bp_enabled;
87805796c8dcSSimon Schubert   copy->disposition = disp_donttouch;
87815796c8dcSSimon Schubert   copy->number = internal_breakpoint_number--;
87825796c8dcSSimon Schubert 
87835796c8dcSSimon Schubert   update_global_location_list_nothrow (0);
87845796c8dcSSimon Schubert   return copy;
87855796c8dcSSimon Schubert }
87865796c8dcSSimon Schubert 
8787a45ae5f8SJohn Marino /* Make a deep copy of momentary breakpoint ORIG.  Returns NULL if
8788a45ae5f8SJohn Marino    ORIG is NULL.  */
8789a45ae5f8SJohn Marino 
8790a45ae5f8SJohn Marino struct breakpoint *
clone_momentary_breakpoint(struct breakpoint * orig)8791a45ae5f8SJohn Marino clone_momentary_breakpoint (struct breakpoint *orig)
8792a45ae5f8SJohn Marino {
8793a45ae5f8SJohn Marino   /* If there's nothing to clone, then return nothing.  */
8794a45ae5f8SJohn Marino   if (orig == NULL)
8795a45ae5f8SJohn Marino     return NULL;
8796a45ae5f8SJohn Marino 
8797a45ae5f8SJohn Marino   return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8798a45ae5f8SJohn Marino }
8799a45ae5f8SJohn Marino 
88005796c8dcSSimon Schubert struct breakpoint *
set_momentary_breakpoint_at_pc(struct gdbarch * gdbarch,CORE_ADDR pc,enum bptype type)88015796c8dcSSimon Schubert set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
88025796c8dcSSimon Schubert 				enum bptype type)
88035796c8dcSSimon Schubert {
88045796c8dcSSimon Schubert   struct symtab_and_line sal;
88055796c8dcSSimon Schubert 
88065796c8dcSSimon Schubert   sal = find_pc_line (pc, 0);
88075796c8dcSSimon Schubert   sal.pc = pc;
88085796c8dcSSimon Schubert   sal.section = find_pc_overlay (pc);
88095796c8dcSSimon Schubert   sal.explicit_pc = 1;
88105796c8dcSSimon Schubert 
88115796c8dcSSimon Schubert   return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
88125796c8dcSSimon Schubert }
88135796c8dcSSimon Schubert 
88145796c8dcSSimon Schubert 
88155796c8dcSSimon Schubert /* Tell the user we have just set a breakpoint B.  */
88165796c8dcSSimon Schubert 
88175796c8dcSSimon Schubert static void
mention(struct breakpoint * b)88185796c8dcSSimon Schubert mention (struct breakpoint *b)
88195796c8dcSSimon Schubert {
88205796c8dcSSimon Schubert   b->ops->print_mention (b);
8821a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (current_uiout))
88225796c8dcSSimon Schubert     return;
88235796c8dcSSimon Schubert   printf_filtered ("\n");
88245796c8dcSSimon Schubert }
88255796c8dcSSimon Schubert 
88265796c8dcSSimon Schubert 
88275796c8dcSSimon Schubert static struct bp_location *
add_location_to_breakpoint(struct breakpoint * b,const struct symtab_and_line * sal)88285796c8dcSSimon Schubert add_location_to_breakpoint (struct breakpoint *b,
88295796c8dcSSimon Schubert 			    const struct symtab_and_line *sal)
88305796c8dcSSimon Schubert {
88315796c8dcSSimon Schubert   struct bp_location *loc, **tmp;
8832a45ae5f8SJohn Marino   CORE_ADDR adjusted_address;
8833a45ae5f8SJohn Marino   struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8834a45ae5f8SJohn Marino 
8835a45ae5f8SJohn Marino   if (loc_gdbarch == NULL)
8836a45ae5f8SJohn Marino     loc_gdbarch = b->gdbarch;
8837a45ae5f8SJohn Marino 
8838a45ae5f8SJohn Marino   /* Adjust the breakpoint's address prior to allocating a location.
8839a45ae5f8SJohn Marino      Once we call allocate_bp_location(), that mostly uninitialized
8840a45ae5f8SJohn Marino      location will be placed on the location chain.  Adjustment of the
8841a45ae5f8SJohn Marino      breakpoint may cause target_read_memory() to be called and we do
8842a45ae5f8SJohn Marino      not want its scan of the location chain to find a breakpoint and
8843a45ae5f8SJohn Marino      location that's only been partially initialized.  */
8844a45ae5f8SJohn Marino   adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8845a45ae5f8SJohn Marino 						sal->pc, b->type);
88465796c8dcSSimon Schubert 
8847*ef5ccd6cSJohn Marino   /* Sort the locations by their ADDRESS.  */
88485796c8dcSSimon Schubert   loc = allocate_bp_location (b);
8849*ef5ccd6cSJohn Marino   for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address;
8850*ef5ccd6cSJohn Marino        tmp = &((*tmp)->next))
88515796c8dcSSimon Schubert     ;
8852*ef5ccd6cSJohn Marino   loc->next = *tmp;
88535796c8dcSSimon Schubert   *tmp = loc;
8854a45ae5f8SJohn Marino 
88555796c8dcSSimon Schubert   loc->requested_address = sal->pc;
8856a45ae5f8SJohn Marino   loc->address = adjusted_address;
8857cf7f2e2dSJohn Marino   loc->pspace = sal->pspace;
8858*ef5ccd6cSJohn Marino   loc->probe = sal->probe;
8859cf7f2e2dSJohn Marino   gdb_assert (loc->pspace != NULL);
88605796c8dcSSimon Schubert   loc->section = sal->section;
8861a45ae5f8SJohn Marino   loc->gdbarch = loc_gdbarch;
8862a45ae5f8SJohn Marino   loc->line_number = sal->line;
8863*ef5ccd6cSJohn Marino   loc->symtab = sal->symtab;
88645796c8dcSSimon Schubert 
8865c50c785cSJohn Marino   set_breakpoint_location_function (loc,
8866c50c785cSJohn Marino 				    sal->explicit_pc || sal->explicit_line);
88675796c8dcSSimon Schubert   return loc;
88685796c8dcSSimon Schubert }
88695796c8dcSSimon Schubert 
88705796c8dcSSimon Schubert 
88715796c8dcSSimon Schubert /* Return 1 if LOC is pointing to a permanent breakpoint,
88725796c8dcSSimon Schubert    return 0 otherwise.  */
88735796c8dcSSimon Schubert 
88745796c8dcSSimon Schubert static int
bp_loc_is_permanent(struct bp_location * loc)88755796c8dcSSimon Schubert bp_loc_is_permanent (struct bp_location *loc)
88765796c8dcSSimon Schubert {
88775796c8dcSSimon Schubert   int len;
88785796c8dcSSimon Schubert   CORE_ADDR addr;
8879a45ae5f8SJohn Marino   const gdb_byte *bpoint;
88805796c8dcSSimon Schubert   gdb_byte *target_mem;
88815796c8dcSSimon Schubert   struct cleanup *cleanup;
88825796c8dcSSimon Schubert   int retval = 0;
88835796c8dcSSimon Schubert 
88845796c8dcSSimon Schubert   gdb_assert (loc != NULL);
88855796c8dcSSimon Schubert 
88865796c8dcSSimon Schubert   addr = loc->address;
8887a45ae5f8SJohn Marino   bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
88885796c8dcSSimon Schubert 
88895796c8dcSSimon Schubert   /* Software breakpoints unsupported?  */
8890a45ae5f8SJohn Marino   if (bpoint == NULL)
88915796c8dcSSimon Schubert     return 0;
88925796c8dcSSimon Schubert 
88935796c8dcSSimon Schubert   target_mem = alloca (len);
88945796c8dcSSimon Schubert 
88955796c8dcSSimon Schubert   /* Enable the automatic memory restoration from breakpoints while
88965796c8dcSSimon Schubert      we read the memory.  Otherwise we could say about our temporary
88975796c8dcSSimon Schubert      breakpoints they are permanent.  */
8898cf7f2e2dSJohn Marino   cleanup = save_current_space_and_thread ();
8899cf7f2e2dSJohn Marino 
8900cf7f2e2dSJohn Marino   switch_to_program_space_and_thread (loc->pspace);
8901cf7f2e2dSJohn Marino   make_show_memory_breakpoints_cleanup (0);
89025796c8dcSSimon Schubert 
89035796c8dcSSimon Schubert   if (target_read_memory (loc->address, target_mem, len) == 0
8904a45ae5f8SJohn Marino       && memcmp (target_mem, bpoint, len) == 0)
89055796c8dcSSimon Schubert     retval = 1;
89065796c8dcSSimon Schubert 
89075796c8dcSSimon Schubert   do_cleanups (cleanup);
89085796c8dcSSimon Schubert 
89095796c8dcSSimon Schubert   return retval;
89105796c8dcSSimon Schubert }
89115796c8dcSSimon Schubert 
8912*ef5ccd6cSJohn Marino /* Build a command list for the dprintf corresponding to the current
8913*ef5ccd6cSJohn Marino    settings of the dprintf style options.  */
89145796c8dcSSimon Schubert 
8915*ef5ccd6cSJohn Marino static void
update_dprintf_command_list(struct breakpoint * b)8916*ef5ccd6cSJohn Marino update_dprintf_command_list (struct breakpoint *b)
8917*ef5ccd6cSJohn Marino {
8918*ef5ccd6cSJohn Marino   char *dprintf_args = b->extra_string;
8919*ef5ccd6cSJohn Marino   char *printf_line = NULL;
8920*ef5ccd6cSJohn Marino 
8921*ef5ccd6cSJohn Marino   if (!dprintf_args)
8922*ef5ccd6cSJohn Marino     return;
8923*ef5ccd6cSJohn Marino 
8924*ef5ccd6cSJohn Marino   dprintf_args = skip_spaces (dprintf_args);
8925*ef5ccd6cSJohn Marino 
8926*ef5ccd6cSJohn Marino   /* Allow a comma, as it may have terminated a location, but don't
8927*ef5ccd6cSJohn Marino      insist on it.  */
8928*ef5ccd6cSJohn Marino   if (*dprintf_args == ',')
8929*ef5ccd6cSJohn Marino     ++dprintf_args;
8930*ef5ccd6cSJohn Marino   dprintf_args = skip_spaces (dprintf_args);
8931*ef5ccd6cSJohn Marino 
8932*ef5ccd6cSJohn Marino   if (*dprintf_args != '"')
8933*ef5ccd6cSJohn Marino     error (_("Bad format string, missing '\"'."));
8934*ef5ccd6cSJohn Marino 
8935*ef5ccd6cSJohn Marino   if (strcmp (dprintf_style, dprintf_style_gdb) == 0)
8936*ef5ccd6cSJohn Marino     printf_line = xstrprintf ("printf %s", dprintf_args);
8937*ef5ccd6cSJohn Marino   else if (strcmp (dprintf_style, dprintf_style_call) == 0)
8938*ef5ccd6cSJohn Marino     {
8939*ef5ccd6cSJohn Marino       if (!dprintf_function)
8940*ef5ccd6cSJohn Marino 	error (_("No function supplied for dprintf call"));
8941*ef5ccd6cSJohn Marino 
8942*ef5ccd6cSJohn Marino       if (dprintf_channel && strlen (dprintf_channel) > 0)
8943*ef5ccd6cSJohn Marino 	printf_line = xstrprintf ("call (void) %s (%s,%s)",
8944*ef5ccd6cSJohn Marino 				  dprintf_function,
8945*ef5ccd6cSJohn Marino 				  dprintf_channel,
8946*ef5ccd6cSJohn Marino 				  dprintf_args);
8947*ef5ccd6cSJohn Marino       else
8948*ef5ccd6cSJohn Marino 	printf_line = xstrprintf ("call (void) %s (%s)",
8949*ef5ccd6cSJohn Marino 				  dprintf_function,
8950*ef5ccd6cSJohn Marino 				  dprintf_args);
8951*ef5ccd6cSJohn Marino     }
8952*ef5ccd6cSJohn Marino   else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
8953*ef5ccd6cSJohn Marino     {
8954*ef5ccd6cSJohn Marino       if (target_can_run_breakpoint_commands ())
8955*ef5ccd6cSJohn Marino 	printf_line = xstrprintf ("agent-printf %s", dprintf_args);
8956*ef5ccd6cSJohn Marino       else
8957*ef5ccd6cSJohn Marino 	{
8958*ef5ccd6cSJohn Marino 	  warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8959*ef5ccd6cSJohn Marino 	  printf_line = xstrprintf ("printf %s", dprintf_args);
8960*ef5ccd6cSJohn Marino 	}
8961*ef5ccd6cSJohn Marino     }
8962*ef5ccd6cSJohn Marino   else
8963*ef5ccd6cSJohn Marino     internal_error (__FILE__, __LINE__,
8964*ef5ccd6cSJohn Marino 		    _("Invalid dprintf style."));
8965*ef5ccd6cSJohn Marino 
8966*ef5ccd6cSJohn Marino   gdb_assert (printf_line != NULL);
8967*ef5ccd6cSJohn Marino   /* Manufacture a printf sequence.  */
8968*ef5ccd6cSJohn Marino   {
8969*ef5ccd6cSJohn Marino     struct command_line *printf_cmd_line
8970*ef5ccd6cSJohn Marino       = xmalloc (sizeof (struct command_line));
8971*ef5ccd6cSJohn Marino 
8972*ef5ccd6cSJohn Marino     printf_cmd_line = xmalloc (sizeof (struct command_line));
8973*ef5ccd6cSJohn Marino     printf_cmd_line->control_type = simple_control;
8974*ef5ccd6cSJohn Marino     printf_cmd_line->body_count = 0;
8975*ef5ccd6cSJohn Marino     printf_cmd_line->body_list = NULL;
8976*ef5ccd6cSJohn Marino     printf_cmd_line->next = NULL;
8977*ef5ccd6cSJohn Marino     printf_cmd_line->line = printf_line;
8978*ef5ccd6cSJohn Marino 
8979*ef5ccd6cSJohn Marino     breakpoint_set_commands (b, printf_cmd_line);
8980*ef5ccd6cSJohn Marino   }
8981*ef5ccd6cSJohn Marino }
8982*ef5ccd6cSJohn Marino 
8983*ef5ccd6cSJohn Marino /* Update all dprintf commands, making their command lists reflect
8984*ef5ccd6cSJohn Marino    current style settings.  */
8985*ef5ccd6cSJohn Marino 
8986*ef5ccd6cSJohn Marino static void
update_dprintf_commands(char * args,int from_tty,struct cmd_list_element * c)8987*ef5ccd6cSJohn Marino update_dprintf_commands (char *args, int from_tty,
8988*ef5ccd6cSJohn Marino 			 struct cmd_list_element *c)
8989*ef5ccd6cSJohn Marino {
8990*ef5ccd6cSJohn Marino   struct breakpoint *b;
8991*ef5ccd6cSJohn Marino 
8992*ef5ccd6cSJohn Marino   ALL_BREAKPOINTS (b)
8993*ef5ccd6cSJohn Marino     {
8994*ef5ccd6cSJohn Marino       if (b->type == bp_dprintf)
8995*ef5ccd6cSJohn Marino 	update_dprintf_command_list (b);
8996*ef5ccd6cSJohn Marino     }
8997*ef5ccd6cSJohn Marino }
89985796c8dcSSimon Schubert 
89995796c8dcSSimon Schubert /* Create a breakpoint with SAL as location.  Use ADDR_STRING
90005796c8dcSSimon Schubert    as textual description of the location, and COND_STRING
90015796c8dcSSimon Schubert    as condition expression.  */
90025796c8dcSSimon Schubert 
90035796c8dcSSimon Schubert 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)9004a45ae5f8SJohn Marino init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
90055796c8dcSSimon Schubert 		     struct symtabs_and_lines sals, char *addr_string,
9006a45ae5f8SJohn Marino 		     char *filter, char *cond_string,
9007*ef5ccd6cSJohn Marino 		     char *extra_string,
90085796c8dcSSimon Schubert 		     enum bptype type, enum bpdisp disposition,
90095796c8dcSSimon Schubert 		     int thread, int task, int ignore_count,
9010a45ae5f8SJohn Marino 		     const struct breakpoint_ops *ops, int from_tty,
9011a45ae5f8SJohn Marino 		     int enabled, int internal, unsigned flags,
9012a45ae5f8SJohn Marino 		     int display_canonical)
90135796c8dcSSimon Schubert {
90145796c8dcSSimon Schubert   int i;
90155796c8dcSSimon Schubert 
90165796c8dcSSimon Schubert   if (type == bp_hardware_breakpoint)
90175796c8dcSSimon Schubert     {
9018a45ae5f8SJohn Marino       int target_resources_ok;
9019a45ae5f8SJohn Marino 
9020a45ae5f8SJohn Marino       i = hw_breakpoint_used_count ();
9021a45ae5f8SJohn Marino       target_resources_ok =
90225796c8dcSSimon Schubert 	target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
90235796c8dcSSimon Schubert 					    i + 1, 0);
90245796c8dcSSimon Schubert       if (target_resources_ok == 0)
90255796c8dcSSimon Schubert 	error (_("No hardware breakpoint support in the target."));
90265796c8dcSSimon Schubert       else if (target_resources_ok < 0)
90275796c8dcSSimon Schubert 	error (_("Hardware breakpoints used exceeds limit."));
90285796c8dcSSimon Schubert     }
90295796c8dcSSimon Schubert 
9030cf7f2e2dSJohn Marino   gdb_assert (sals.nelts > 0);
9031cf7f2e2dSJohn Marino 
90325796c8dcSSimon Schubert   for (i = 0; i < sals.nelts; ++i)
90335796c8dcSSimon Schubert     {
90345796c8dcSSimon Schubert       struct symtab_and_line sal = sals.sals[i];
90355796c8dcSSimon Schubert       struct bp_location *loc;
90365796c8dcSSimon Schubert 
90375796c8dcSSimon Schubert       if (from_tty)
90385796c8dcSSimon Schubert 	{
90395796c8dcSSimon Schubert 	  struct gdbarch *loc_gdbarch = get_sal_arch (sal);
90405796c8dcSSimon Schubert 	  if (!loc_gdbarch)
90415796c8dcSSimon Schubert 	    loc_gdbarch = gdbarch;
90425796c8dcSSimon Schubert 
90435796c8dcSSimon Schubert 	  describe_other_breakpoints (loc_gdbarch,
9044cf7f2e2dSJohn Marino 				      sal.pspace, sal.pc, sal.section, thread);
90455796c8dcSSimon Schubert 	}
90465796c8dcSSimon Schubert 
90475796c8dcSSimon Schubert       if (i == 0)
90485796c8dcSSimon Schubert 	{
9049a45ae5f8SJohn Marino 	  init_raw_breakpoint (b, gdbarch, sal, type, ops);
90505796c8dcSSimon Schubert 	  b->thread = thread;
90515796c8dcSSimon Schubert 	  b->task = task;
90525796c8dcSSimon Schubert 
90535796c8dcSSimon Schubert 	  b->cond_string = cond_string;
9054*ef5ccd6cSJohn Marino 	  b->extra_string = extra_string;
90555796c8dcSSimon Schubert 	  b->ignore_count = ignore_count;
90565796c8dcSSimon Schubert 	  b->enable_state = enabled ? bp_enabled : bp_disabled;
90575796c8dcSSimon Schubert 	  b->disposition = disposition;
9058a45ae5f8SJohn Marino 
9059a45ae5f8SJohn Marino 	  if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9060a45ae5f8SJohn Marino 	    b->loc->inserted = 1;
90615796c8dcSSimon Schubert 
9062cf7f2e2dSJohn Marino 	  if (type == bp_static_tracepoint)
9063cf7f2e2dSJohn Marino 	    {
9064a45ae5f8SJohn Marino 	      struct tracepoint *t = (struct tracepoint *) b;
9065cf7f2e2dSJohn Marino 	      struct static_tracepoint_marker marker;
9066cf7f2e2dSJohn Marino 
9067*ef5ccd6cSJohn Marino 	      if (strace_marker_p (b))
9068cf7f2e2dSJohn Marino 		{
9069cf7f2e2dSJohn Marino 		  /* We already know the marker exists, otherwise, we
9070cf7f2e2dSJohn Marino 		     wouldn't see a sal for it.  */
9071cf7f2e2dSJohn Marino 		  char *p = &addr_string[3];
9072cf7f2e2dSJohn Marino 		  char *endp;
9073cf7f2e2dSJohn Marino 		  char *marker_str;
9074cf7f2e2dSJohn Marino 
9075c50c785cSJohn Marino 		  p = skip_spaces (p);
9076cf7f2e2dSJohn Marino 
9077c50c785cSJohn Marino 		  endp = skip_to_space (p);
9078cf7f2e2dSJohn Marino 
9079cf7f2e2dSJohn Marino 		  marker_str = savestring (p, endp - p);
9080a45ae5f8SJohn Marino 		  t->static_trace_marker_id = marker_str;
9081cf7f2e2dSJohn Marino 
9082c50c785cSJohn Marino 		  printf_filtered (_("Probed static tracepoint "
9083c50c785cSJohn Marino 				     "marker \"%s\"\n"),
9084a45ae5f8SJohn Marino 				   t->static_trace_marker_id);
9085cf7f2e2dSJohn Marino 		}
9086cf7f2e2dSJohn Marino 	      else if (target_static_tracepoint_marker_at (sal.pc, &marker))
9087cf7f2e2dSJohn Marino 		{
9088a45ae5f8SJohn Marino 		  t->static_trace_marker_id = xstrdup (marker.str_id);
9089cf7f2e2dSJohn Marino 		  release_static_tracepoint_marker (&marker);
9090cf7f2e2dSJohn Marino 
9091c50c785cSJohn Marino 		  printf_filtered (_("Probed static tracepoint "
9092c50c785cSJohn Marino 				     "marker \"%s\"\n"),
9093a45ae5f8SJohn Marino 				   t->static_trace_marker_id);
9094cf7f2e2dSJohn Marino 		}
9095cf7f2e2dSJohn Marino 	      else
9096c50c785cSJohn Marino 		warning (_("Couldn't determine the static "
9097c50c785cSJohn Marino 			   "tracepoint marker to probe"));
9098cf7f2e2dSJohn Marino 	    }
9099cf7f2e2dSJohn Marino 
91005796c8dcSSimon Schubert 	  loc = b->loc;
91015796c8dcSSimon Schubert 	}
91025796c8dcSSimon Schubert       else
91035796c8dcSSimon Schubert 	{
91045796c8dcSSimon Schubert 	  loc = add_location_to_breakpoint (b, &sal);
9105a45ae5f8SJohn Marino 	  if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
9106a45ae5f8SJohn Marino 	    loc->inserted = 1;
91075796c8dcSSimon Schubert 	}
91085796c8dcSSimon Schubert 
91095796c8dcSSimon Schubert       if (bp_loc_is_permanent (loc))
91105796c8dcSSimon Schubert 	make_breakpoint_permanent (b);
91115796c8dcSSimon Schubert 
91125796c8dcSSimon Schubert       if (b->cond_string)
91135796c8dcSSimon Schubert 	{
9114*ef5ccd6cSJohn Marino 	  const char *arg = b->cond_string;
9115*ef5ccd6cSJohn Marino 
9116*ef5ccd6cSJohn Marino 	  loc->cond = parse_exp_1 (&arg, loc->address,
9117*ef5ccd6cSJohn Marino 				   block_for_pc (loc->address), 0);
91185796c8dcSSimon Schubert 	  if (*arg)
9119*ef5ccd6cSJohn Marino               error (_("Garbage '%s' follows condition"), arg);
91205796c8dcSSimon Schubert 	}
9121*ef5ccd6cSJohn Marino 
9122*ef5ccd6cSJohn Marino       /* Dynamic printf requires and uses additional arguments on the
9123*ef5ccd6cSJohn Marino 	 command line, otherwise it's an error.  */
9124*ef5ccd6cSJohn Marino       if (type == bp_dprintf)
9125*ef5ccd6cSJohn Marino 	{
9126*ef5ccd6cSJohn Marino 	  if (b->extra_string)
9127*ef5ccd6cSJohn Marino 	    update_dprintf_command_list (b);
9128*ef5ccd6cSJohn Marino 	  else
9129*ef5ccd6cSJohn Marino 	    error (_("Format string required"));
9130*ef5ccd6cSJohn Marino 	}
9131*ef5ccd6cSJohn Marino       else if (b->extra_string)
9132*ef5ccd6cSJohn Marino 	error (_("Garbage '%s' at end of command"), b->extra_string);
91335796c8dcSSimon Schubert     }
91345796c8dcSSimon Schubert 
9135c50c785cSJohn Marino   b->display_canonical = display_canonical;
91365796c8dcSSimon Schubert   if (addr_string)
91375796c8dcSSimon Schubert     b->addr_string = addr_string;
91385796c8dcSSimon Schubert   else
91395796c8dcSSimon Schubert     /* addr_string has to be used or breakpoint_re_set will delete
91405796c8dcSSimon Schubert        me.  */
91415796c8dcSSimon Schubert     b->addr_string
91425796c8dcSSimon Schubert       = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
9143a45ae5f8SJohn Marino   b->filter = filter;
91445796c8dcSSimon Schubert }
91455796c8dcSSimon Schubert 
91465796c8dcSSimon Schubert 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)9147a45ae5f8SJohn Marino create_breakpoint_sal (struct gdbarch *gdbarch,
9148a45ae5f8SJohn Marino 		       struct symtabs_and_lines sals, char *addr_string,
9149a45ae5f8SJohn Marino 		       char *filter, char *cond_string,
9150*ef5ccd6cSJohn Marino 		       char *extra_string,
9151a45ae5f8SJohn Marino 		       enum bptype type, enum bpdisp disposition,
9152a45ae5f8SJohn Marino 		       int thread, int task, int ignore_count,
9153a45ae5f8SJohn Marino 		       const struct breakpoint_ops *ops, int from_tty,
9154a45ae5f8SJohn Marino 		       int enabled, int internal, unsigned flags,
9155a45ae5f8SJohn Marino 		       int display_canonical)
91565796c8dcSSimon Schubert {
9157a45ae5f8SJohn Marino   struct breakpoint *b;
9158cf7f2e2dSJohn Marino   struct cleanup *old_chain;
91595796c8dcSSimon Schubert 
9160a45ae5f8SJohn Marino   if (is_tracepoint_type (type))
91615796c8dcSSimon Schubert     {
9162a45ae5f8SJohn Marino       struct tracepoint *t;
9163a45ae5f8SJohn Marino 
9164a45ae5f8SJohn Marino       t = XCNEW (struct tracepoint);
9165a45ae5f8SJohn Marino       b = &t->base;
91665796c8dcSSimon Schubert     }
9167a45ae5f8SJohn Marino   else
9168a45ae5f8SJohn Marino     b = XNEW (struct breakpoint);
91695796c8dcSSimon Schubert 
9170a45ae5f8SJohn Marino   old_chain = make_cleanup (xfree, b);
9171cf7f2e2dSJohn Marino 
9172a45ae5f8SJohn Marino   init_breakpoint_sal (b, gdbarch,
9173a45ae5f8SJohn Marino 		       sals, addr_string,
9174*ef5ccd6cSJohn Marino 		       filter, cond_string, extra_string,
9175a45ae5f8SJohn Marino 		       type, disposition,
9176a45ae5f8SJohn Marino 		       thread, task, ignore_count,
9177a45ae5f8SJohn Marino 		       ops, from_tty,
9178a45ae5f8SJohn Marino 		       enabled, internal, flags,
9179a45ae5f8SJohn Marino 		       display_canonical);
9180a45ae5f8SJohn Marino   discard_cleanups (old_chain);
9181cf7f2e2dSJohn Marino 
9182a45ae5f8SJohn Marino   install_breakpoint (internal, b, 0);
91835796c8dcSSimon Schubert }
91845796c8dcSSimon Schubert 
91855796c8dcSSimon Schubert /* Add SALS.nelts breakpoints to the breakpoint table.  For each
91865796c8dcSSimon Schubert    SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
91875796c8dcSSimon Schubert    value.  COND_STRING, if not NULL, specified the condition to be
91885796c8dcSSimon Schubert    used for all breakpoints.  Essentially the only case where
91895796c8dcSSimon Schubert    SALS.nelts is not 1 is when we set a breakpoint on an overloaded
91905796c8dcSSimon Schubert    function.  In that case, it's still not possible to specify
91915796c8dcSSimon Schubert    separate conditions for different overloaded functions, so
91925796c8dcSSimon Schubert    we take just a single condition string.
91935796c8dcSSimon Schubert 
91945796c8dcSSimon Schubert    NOTE: If the function succeeds, the caller is expected to cleanup
91955796c8dcSSimon Schubert    the arrays ADDR_STRING, COND_STRING, and SALS (but not the
91965796c8dcSSimon Schubert    array contents).  If the function fails (error() is called), the
91975796c8dcSSimon Schubert    caller is expected to cleanups both the ADDR_STRING, COND_STRING,
91985796c8dcSSimon Schubert    COND and SALS arrays and each of those arrays contents.  */
91995796c8dcSSimon Schubert 
92005796c8dcSSimon Schubert 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)9201cf7f2e2dSJohn Marino create_breakpoints_sal (struct gdbarch *gdbarch,
9202c50c785cSJohn Marino 			struct linespec_result *canonical,
9203*ef5ccd6cSJohn Marino 			char *cond_string, char *extra_string,
92045796c8dcSSimon Schubert 			enum bptype type, enum bpdisp disposition,
92055796c8dcSSimon Schubert 			int thread, int task, int ignore_count,
9206a45ae5f8SJohn Marino 			const struct breakpoint_ops *ops, int from_tty,
9207a45ae5f8SJohn Marino 			int enabled, int internal, unsigned flags)
92085796c8dcSSimon Schubert {
92095796c8dcSSimon Schubert   int i;
9210a45ae5f8SJohn Marino   struct linespec_sals *lsal;
9211cf7f2e2dSJohn Marino 
9212a45ae5f8SJohn Marino   if (canonical->pre_expanded)
9213a45ae5f8SJohn Marino     gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
9214a45ae5f8SJohn Marino 
9215a45ae5f8SJohn Marino   for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
92165796c8dcSSimon Schubert     {
9217a45ae5f8SJohn Marino       /* Note that 'addr_string' can be NULL in the case of a plain
9218a45ae5f8SJohn Marino 	 'break', without arguments.  */
9219a45ae5f8SJohn Marino       char *addr_string = (canonical->addr_string
9220a45ae5f8SJohn Marino 			   ? xstrdup (canonical->addr_string)
9221a45ae5f8SJohn Marino 			   : NULL);
9222a45ae5f8SJohn Marino       char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
9223a45ae5f8SJohn Marino       struct cleanup *inner = make_cleanup (xfree, addr_string);
92245796c8dcSSimon Schubert 
9225a45ae5f8SJohn Marino       make_cleanup (xfree, filter_string);
9226a45ae5f8SJohn Marino       create_breakpoint_sal (gdbarch, lsal->sals,
9227a45ae5f8SJohn Marino 			     addr_string,
9228a45ae5f8SJohn Marino 			     filter_string,
9229*ef5ccd6cSJohn Marino 			     cond_string, extra_string,
9230*ef5ccd6cSJohn Marino 			     type, disposition,
9231c50c785cSJohn Marino 			     thread, task, ignore_count, ops,
9232a45ae5f8SJohn Marino 			     from_tty, enabled, internal, flags,
9233c50c785cSJohn Marino 			     canonical->special_display);
9234a45ae5f8SJohn Marino       discard_cleanups (inner);
92355796c8dcSSimon Schubert     }
92365796c8dcSSimon Schubert }
92375796c8dcSSimon Schubert 
9238c50c785cSJohn Marino /* Parse ADDRESS which is assumed to be a SAL specification possibly
92395796c8dcSSimon Schubert    followed by conditionals.  On return, SALS contains an array of SAL
92405796c8dcSSimon Schubert    addresses found.  ADDR_STRING contains a vector of (canonical)
9241c50c785cSJohn Marino    address strings.  ADDRESS points to the end of the SAL.
9242c50c785cSJohn Marino 
9243c50c785cSJohn Marino    The array and the line spec strings are allocated on the heap, it is
9244c50c785cSJohn Marino    the caller's responsibility to free them.  */
92455796c8dcSSimon Schubert 
92465796c8dcSSimon Schubert static void
parse_breakpoint_sals(char ** address,struct linespec_result * canonical)92475796c8dcSSimon Schubert parse_breakpoint_sals (char **address,
9248c50c785cSJohn Marino 		       struct linespec_result *canonical)
92495796c8dcSSimon Schubert {
92505796c8dcSSimon Schubert   /* If no arg given, or if first arg is 'if ', use the default
92515796c8dcSSimon Schubert      breakpoint.  */
92525796c8dcSSimon Schubert   if ((*address) == NULL
92535796c8dcSSimon Schubert       || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
92545796c8dcSSimon Schubert     {
9255a45ae5f8SJohn Marino       /* The last displayed codepoint, if it's valid, is our default breakpoint
9256a45ae5f8SJohn Marino          address.  */
9257a45ae5f8SJohn Marino       if (last_displayed_sal_is_valid ())
92585796c8dcSSimon Schubert 	{
9259a45ae5f8SJohn Marino 	  struct linespec_sals lsal;
92605796c8dcSSimon Schubert 	  struct symtab_and_line sal;
9261*ef5ccd6cSJohn Marino 	  CORE_ADDR pc;
9262cf7f2e2dSJohn Marino 
9263c50c785cSJohn Marino 	  init_sal (&sal);		/* Initialize to zeroes.  */
9264a45ae5f8SJohn Marino 	  lsal.sals.sals = (struct symtab_and_line *)
92655796c8dcSSimon Schubert 	    xmalloc (sizeof (struct symtab_and_line));
9266a45ae5f8SJohn Marino 
9267a45ae5f8SJohn Marino 	  /* Set sal's pspace, pc, symtab, and line to the values
9268*ef5ccd6cSJohn Marino 	     corresponding to the last call to print_frame_info.
9269*ef5ccd6cSJohn Marino 	     Be sure to reinitialize LINE with NOTCURRENT == 0
9270*ef5ccd6cSJohn Marino 	     as the breakpoint line number is inappropriate otherwise.
9271*ef5ccd6cSJohn Marino 	     find_pc_line would adjust PC, re-set it back.  */
9272a45ae5f8SJohn Marino 	  get_last_displayed_sal (&sal);
9273*ef5ccd6cSJohn Marino 	  pc = sal.pc;
9274*ef5ccd6cSJohn Marino 	  sal = find_pc_line (pc, 0);
92755796c8dcSSimon Schubert 
9276c50c785cSJohn Marino 	  /* "break" without arguments is equivalent to "break *PC"
9277a45ae5f8SJohn Marino 	     where PC is the last displayed codepoint's address.  So
9278a45ae5f8SJohn Marino 	     make sure to set sal.explicit_pc to prevent GDB from
9279a45ae5f8SJohn Marino 	     trying to expand the list of sals to include all other
9280a45ae5f8SJohn Marino 	     instances with the same symtab and line.  */
9281*ef5ccd6cSJohn Marino 	  sal.pc = pc;
92825796c8dcSSimon Schubert 	  sal.explicit_pc = 1;
92835796c8dcSSimon Schubert 
9284a45ae5f8SJohn Marino 	  lsal.sals.sals[0] = sal;
9285a45ae5f8SJohn Marino 	  lsal.sals.nelts = 1;
9286a45ae5f8SJohn Marino 	  lsal.canonical = NULL;
9287a45ae5f8SJohn Marino 
9288a45ae5f8SJohn Marino 	  VEC_safe_push (linespec_sals, canonical->sals, &lsal);
92895796c8dcSSimon Schubert 	}
92905796c8dcSSimon Schubert       else
92915796c8dcSSimon Schubert 	error (_("No default breakpoint address now."));
92925796c8dcSSimon Schubert     }
92935796c8dcSSimon Schubert   else
92945796c8dcSSimon Schubert     {
9295*ef5ccd6cSJohn Marino       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
9296*ef5ccd6cSJohn Marino 
92975796c8dcSSimon Schubert       /* Force almost all breakpoints to be in terms of the
9298c50c785cSJohn Marino          current_source_symtab (which is decode_line_1's default).
9299c50c785cSJohn Marino          This should produce the results we want almost all of the
9300*ef5ccd6cSJohn Marino          time while leaving default_breakpoint_* alone.
9301*ef5ccd6cSJohn Marino 
9302*ef5ccd6cSJohn Marino 	 ObjC: However, don't match an Objective-C method name which
9303*ef5ccd6cSJohn Marino 	 may have a '+' or '-' succeeded by a '['.  */
9304*ef5ccd6cSJohn Marino       if (last_displayed_sal_is_valid ()
9305*ef5ccd6cSJohn Marino 	  && (!cursal.symtab
9306*ef5ccd6cSJohn Marino 	      || ((strchr ("+-", (*address)[0]) != NULL)
9307*ef5ccd6cSJohn Marino 		  && ((*address)[1] != '['))))
9308a45ae5f8SJohn Marino 	decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9309a45ae5f8SJohn Marino 			  get_last_displayed_symtab (),
9310a45ae5f8SJohn Marino 			  get_last_displayed_line (),
9311a45ae5f8SJohn Marino 			  canonical, NULL, NULL);
93125796c8dcSSimon Schubert       else
9313a45ae5f8SJohn Marino 	decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
9314*ef5ccd6cSJohn Marino 			  cursal.symtab, cursal.line, canonical, NULL, NULL);
93155796c8dcSSimon Schubert     }
93165796c8dcSSimon Schubert }
93175796c8dcSSimon Schubert 
93185796c8dcSSimon Schubert 
93195796c8dcSSimon Schubert /* Convert each SAL into a real PC.  Verify that the PC can be
93205796c8dcSSimon Schubert    inserted as a breakpoint.  If it can't throw an error.  */
93215796c8dcSSimon Schubert 
93225796c8dcSSimon Schubert static void
breakpoint_sals_to_pc(struct symtabs_and_lines * sals)9323cf7f2e2dSJohn Marino breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
93245796c8dcSSimon Schubert {
93255796c8dcSSimon Schubert   int i;
9326cf7f2e2dSJohn Marino 
93275796c8dcSSimon Schubert   for (i = 0; i < sals->nelts; i++)
93285796c8dcSSimon Schubert     resolve_sal_pc (&sals->sals[i]);
93295796c8dcSSimon Schubert }
93305796c8dcSSimon Schubert 
9331cf7f2e2dSJohn Marino /* Fast tracepoints may have restrictions on valid locations.  For
9332cf7f2e2dSJohn Marino    instance, a fast tracepoint using a jump instead of a trap will
9333cf7f2e2dSJohn Marino    likely have to overwrite more bytes than a trap would, and so can
9334cf7f2e2dSJohn Marino    only be placed where the instruction is longer than the jump, or a
9335cf7f2e2dSJohn Marino    multi-instruction sequence does not have a jump into the middle of
9336cf7f2e2dSJohn Marino    it, etc.  */
9337cf7f2e2dSJohn Marino 
9338cf7f2e2dSJohn Marino static void
check_fast_tracepoint_sals(struct gdbarch * gdbarch,struct symtabs_and_lines * sals)9339cf7f2e2dSJohn Marino check_fast_tracepoint_sals (struct gdbarch *gdbarch,
9340cf7f2e2dSJohn Marino 			    struct symtabs_and_lines *sals)
9341cf7f2e2dSJohn Marino {
9342cf7f2e2dSJohn Marino   int i, rslt;
9343cf7f2e2dSJohn Marino   struct symtab_and_line *sal;
9344cf7f2e2dSJohn Marino   char *msg;
9345cf7f2e2dSJohn Marino   struct cleanup *old_chain;
9346cf7f2e2dSJohn Marino 
9347cf7f2e2dSJohn Marino   for (i = 0; i < sals->nelts; i++)
9348cf7f2e2dSJohn Marino     {
9349a45ae5f8SJohn Marino       struct gdbarch *sarch;
9350a45ae5f8SJohn Marino 
9351cf7f2e2dSJohn Marino       sal = &sals->sals[i];
9352cf7f2e2dSJohn Marino 
9353a45ae5f8SJohn Marino       sarch = get_sal_arch (*sal);
9354a45ae5f8SJohn Marino       /* We fall back to GDBARCH if there is no architecture
9355a45ae5f8SJohn Marino 	 associated with SAL.  */
9356a45ae5f8SJohn Marino       if (sarch == NULL)
9357a45ae5f8SJohn Marino 	sarch = gdbarch;
9358a45ae5f8SJohn Marino       rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
9359cf7f2e2dSJohn Marino 					       NULL, &msg);
9360cf7f2e2dSJohn Marino       old_chain = make_cleanup (xfree, msg);
9361cf7f2e2dSJohn Marino 
9362cf7f2e2dSJohn Marino       if (!rslt)
9363cf7f2e2dSJohn Marino 	error (_("May not have a fast tracepoint at 0x%s%s"),
9364a45ae5f8SJohn Marino 	       paddress (sarch, sal->pc), (msg ? msg : ""));
9365cf7f2e2dSJohn Marino 
9366cf7f2e2dSJohn Marino       do_cleanups (old_chain);
9367cf7f2e2dSJohn Marino     }
9368cf7f2e2dSJohn Marino }
9369cf7f2e2dSJohn Marino 
9370*ef5ccd6cSJohn Marino /* Issue an invalid thread ID error.  */
9371*ef5ccd6cSJohn Marino 
9372*ef5ccd6cSJohn Marino static void ATTRIBUTE_NORETURN
invalid_thread_id_error(int id)9373*ef5ccd6cSJohn Marino invalid_thread_id_error (int id)
9374*ef5ccd6cSJohn Marino {
9375*ef5ccd6cSJohn Marino   error (_("Unknown thread %d."), id);
9376*ef5ccd6cSJohn Marino }
9377*ef5ccd6cSJohn Marino 
93785796c8dcSSimon Schubert /* Given TOK, a string specification of condition and thread, as
93795796c8dcSSimon Schubert    accepted by the 'break' command, extract the condition
93805796c8dcSSimon Schubert    string and thread number and set *COND_STRING and *THREAD.
93815796c8dcSSimon Schubert    PC identifies the context at which the condition should be parsed.
93825796c8dcSSimon Schubert    If no condition is found, *COND_STRING is set to NULL.
93835796c8dcSSimon Schubert    If no thread is found, *THREAD is set to -1.  */
9384*ef5ccd6cSJohn Marino 
93855796c8dcSSimon Schubert static void
find_condition_and_thread(const char * tok,CORE_ADDR pc,char ** cond_string,int * thread,int * task,char ** rest)9386*ef5ccd6cSJohn Marino find_condition_and_thread (const char *tok, CORE_ADDR pc,
9387*ef5ccd6cSJohn Marino 			   char **cond_string, int *thread, int *task,
9388*ef5ccd6cSJohn Marino 			   char **rest)
93895796c8dcSSimon Schubert {
93905796c8dcSSimon Schubert   *cond_string = NULL;
93915796c8dcSSimon Schubert   *thread = -1;
9392*ef5ccd6cSJohn Marino   *task = 0;
9393*ef5ccd6cSJohn Marino   *rest = NULL;
9394*ef5ccd6cSJohn Marino 
93955796c8dcSSimon Schubert   while (tok && *tok)
93965796c8dcSSimon Schubert     {
9397*ef5ccd6cSJohn Marino       const char *end_tok;
93985796c8dcSSimon Schubert       int toklen;
9399*ef5ccd6cSJohn Marino       const char *cond_start = NULL;
9400*ef5ccd6cSJohn Marino       const char *cond_end = NULL;
9401cf7f2e2dSJohn Marino 
9402*ef5ccd6cSJohn Marino       tok = skip_spaces_const (tok);
94035796c8dcSSimon Schubert 
9404*ef5ccd6cSJohn Marino       if ((*tok == '"' || *tok == ',') && rest)
9405*ef5ccd6cSJohn Marino 	{
9406*ef5ccd6cSJohn Marino 	  *rest = savestring (tok, strlen (tok));
9407*ef5ccd6cSJohn Marino 	  return;
9408*ef5ccd6cSJohn Marino 	}
9409*ef5ccd6cSJohn Marino 
9410*ef5ccd6cSJohn Marino       end_tok = skip_to_space_const (tok);
94115796c8dcSSimon Schubert 
94125796c8dcSSimon Schubert       toklen = end_tok - tok;
94135796c8dcSSimon Schubert 
94145796c8dcSSimon Schubert       if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
94155796c8dcSSimon Schubert 	{
94165796c8dcSSimon Schubert 	  struct expression *expr;
94175796c8dcSSimon Schubert 
94185796c8dcSSimon Schubert 	  tok = cond_start = end_tok + 1;
9419*ef5ccd6cSJohn Marino 	  expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
94205796c8dcSSimon Schubert 	  xfree (expr);
94215796c8dcSSimon Schubert 	  cond_end = tok;
9422*ef5ccd6cSJohn Marino 	  *cond_string = savestring (cond_start, cond_end - cond_start);
94235796c8dcSSimon Schubert 	}
94245796c8dcSSimon Schubert       else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
94255796c8dcSSimon Schubert 	{
94265796c8dcSSimon Schubert 	  char *tmptok;
94275796c8dcSSimon Schubert 
94285796c8dcSSimon Schubert 	  tok = end_tok + 1;
9429*ef5ccd6cSJohn Marino 	  *thread = strtol (tok, &tmptok, 0);
94305796c8dcSSimon Schubert 	  if (tok == tmptok)
94315796c8dcSSimon Schubert 	    error (_("Junk after thread keyword."));
94325796c8dcSSimon Schubert 	  if (!valid_thread_id (*thread))
9433*ef5ccd6cSJohn Marino 	    invalid_thread_id_error (*thread);
9434*ef5ccd6cSJohn Marino 	  tok = tmptok;
94355796c8dcSSimon Schubert 	}
94365796c8dcSSimon Schubert       else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
94375796c8dcSSimon Schubert 	{
94385796c8dcSSimon Schubert 	  char *tmptok;
94395796c8dcSSimon Schubert 
94405796c8dcSSimon Schubert 	  tok = end_tok + 1;
9441*ef5ccd6cSJohn Marino 	  *task = strtol (tok, &tmptok, 0);
94425796c8dcSSimon Schubert 	  if (tok == tmptok)
94435796c8dcSSimon Schubert 	    error (_("Junk after task keyword."));
94445796c8dcSSimon Schubert 	  if (!valid_task_id (*task))
9445cf7f2e2dSJohn Marino 	    error (_("Unknown task %d."), *task);
9446*ef5ccd6cSJohn Marino 	  tok = tmptok;
9447*ef5ccd6cSJohn Marino 	}
9448*ef5ccd6cSJohn Marino       else if (rest)
9449*ef5ccd6cSJohn Marino 	{
9450*ef5ccd6cSJohn Marino 	  *rest = savestring (tok, strlen (tok));
9451*ef5ccd6cSJohn Marino 	  return;
94525796c8dcSSimon Schubert 	}
94535796c8dcSSimon Schubert       else
94545796c8dcSSimon Schubert 	error (_("Junk at end of arguments."));
94555796c8dcSSimon Schubert     }
94565796c8dcSSimon Schubert }
94575796c8dcSSimon Schubert 
9458cf7f2e2dSJohn Marino /* Decode a static tracepoint marker spec.  */
94595796c8dcSSimon Schubert 
9460cf7f2e2dSJohn Marino static struct symtabs_and_lines
decode_static_tracepoint_spec(char ** arg_p)9461cf7f2e2dSJohn Marino decode_static_tracepoint_spec (char **arg_p)
9462cf7f2e2dSJohn Marino {
9463cf7f2e2dSJohn Marino   VEC(static_tracepoint_marker_p) *markers = NULL;
9464cf7f2e2dSJohn Marino   struct symtabs_and_lines sals;
9465cf7f2e2dSJohn Marino   struct cleanup *old_chain;
9466cf7f2e2dSJohn Marino   char *p = &(*arg_p)[3];
9467cf7f2e2dSJohn Marino   char *endp;
9468cf7f2e2dSJohn Marino   char *marker_str;
9469cf7f2e2dSJohn Marino   int i;
9470cf7f2e2dSJohn Marino 
9471c50c785cSJohn Marino   p = skip_spaces (p);
9472cf7f2e2dSJohn Marino 
9473c50c785cSJohn Marino   endp = skip_to_space (p);
9474cf7f2e2dSJohn Marino 
9475cf7f2e2dSJohn Marino   marker_str = savestring (p, endp - p);
9476cf7f2e2dSJohn Marino   old_chain = make_cleanup (xfree, marker_str);
9477cf7f2e2dSJohn Marino 
9478cf7f2e2dSJohn Marino   markers = target_static_tracepoint_markers_by_strid (marker_str);
9479cf7f2e2dSJohn Marino   if (VEC_empty(static_tracepoint_marker_p, markers))
9480cf7f2e2dSJohn Marino     error (_("No known static tracepoint marker named %s"), marker_str);
9481cf7f2e2dSJohn Marino 
9482cf7f2e2dSJohn Marino   sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
9483cf7f2e2dSJohn Marino   sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
9484cf7f2e2dSJohn Marino 
9485cf7f2e2dSJohn Marino   for (i = 0; i < sals.nelts; i++)
9486cf7f2e2dSJohn Marino     {
9487cf7f2e2dSJohn Marino       struct static_tracepoint_marker *marker;
9488cf7f2e2dSJohn Marino 
9489cf7f2e2dSJohn Marino       marker = VEC_index (static_tracepoint_marker_p, markers, i);
9490cf7f2e2dSJohn Marino 
9491cf7f2e2dSJohn Marino       init_sal (&sals.sals[i]);
9492cf7f2e2dSJohn Marino 
9493cf7f2e2dSJohn Marino       sals.sals[i] = find_pc_line (marker->address, 0);
9494cf7f2e2dSJohn Marino       sals.sals[i].pc = marker->address;
9495cf7f2e2dSJohn Marino 
9496cf7f2e2dSJohn Marino       release_static_tracepoint_marker (marker);
9497cf7f2e2dSJohn Marino     }
9498cf7f2e2dSJohn Marino 
9499cf7f2e2dSJohn Marino   do_cleanups (old_chain);
9500cf7f2e2dSJohn Marino 
9501cf7f2e2dSJohn Marino   *arg_p = endp;
9502cf7f2e2dSJohn Marino   return sals;
9503cf7f2e2dSJohn Marino }
9504cf7f2e2dSJohn Marino 
9505cf7f2e2dSJohn Marino /* Set a breakpoint.  This function is shared between CLI and MI
9506cf7f2e2dSJohn Marino    functions for setting a breakpoint.  This function has two major
9507cf7f2e2dSJohn Marino    modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9508cf7f2e2dSJohn Marino    parameter.  If non-zero, the function will parse arg, extracting
9509c50c785cSJohn Marino    breakpoint location, address and thread.  Otherwise, ARG is just
9510c50c785cSJohn Marino    the location of breakpoint, with condition and thread specified by
9511c50c785cSJohn Marino    the COND_STRING and THREAD parameters.  If INTERNAL is non-zero,
9512c50c785cSJohn Marino    the breakpoint number will be allocated from the internal
9513c50c785cSJohn Marino    breakpoint count.  Returns true if any breakpoint was created;
9514c50c785cSJohn Marino    false otherwise.  */
9515cf7f2e2dSJohn Marino 
9516cf7f2e2dSJohn Marino int
create_breakpoint(struct gdbarch * gdbarch,char * arg,char * cond_string,int thread,char * extra_string,int parse_condition_and_thread,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)9517cf7f2e2dSJohn Marino create_breakpoint (struct gdbarch *gdbarch,
9518*ef5ccd6cSJohn Marino 		   char *arg, char *cond_string,
9519*ef5ccd6cSJohn Marino 		   int thread, char *extra_string,
95205796c8dcSSimon Schubert 		   int parse_condition_and_thread,
9521cf7f2e2dSJohn Marino 		   int tempflag, enum bptype type_wanted,
95225796c8dcSSimon Schubert 		   int ignore_count,
95235796c8dcSSimon Schubert 		   enum auto_boolean pending_break_support,
9524a45ae5f8SJohn Marino 		   const struct breakpoint_ops *ops,
9525a45ae5f8SJohn Marino 		   int from_tty, int enabled, int internal,
9526a45ae5f8SJohn Marino 		   unsigned flags)
95275796c8dcSSimon Schubert {
9528a45ae5f8SJohn Marino   volatile struct gdb_exception e;
9529a45ae5f8SJohn Marino   char *copy_arg = NULL;
95305796c8dcSSimon Schubert   char *addr_start = arg;
9531c50c785cSJohn Marino   struct linespec_result canonical;
95325796c8dcSSimon Schubert   struct cleanup *old_chain;
95335796c8dcSSimon Schubert   struct cleanup *bkpt_chain = NULL;
95345796c8dcSSimon Schubert   int pending = 0;
95355796c8dcSSimon Schubert   int task = 0;
9536cf7f2e2dSJohn Marino   int prev_bkpt_count = breakpoint_count;
95375796c8dcSSimon Schubert 
9538a45ae5f8SJohn Marino   gdb_assert (ops != NULL);
95395796c8dcSSimon Schubert 
9540a45ae5f8SJohn Marino   init_linespec_result (&canonical);
95415796c8dcSSimon Schubert 
9542a45ae5f8SJohn Marino   TRY_CATCH (e, RETURN_MASK_ALL)
9543a45ae5f8SJohn Marino     {
9544*ef5ccd6cSJohn Marino       ops->create_sals_from_address (&arg, &canonical, type_wanted,
9545*ef5ccd6cSJohn Marino 				     addr_start, &copy_arg);
9546a45ae5f8SJohn Marino     }
95475796c8dcSSimon Schubert 
95485796c8dcSSimon Schubert   /* If caller is interested in rc value from parse, set value.  */
95495796c8dcSSimon Schubert   switch (e.reason)
95505796c8dcSSimon Schubert     {
9551*ef5ccd6cSJohn Marino     case GDB_NO_ERROR:
9552*ef5ccd6cSJohn Marino       if (VEC_empty (linespec_sals, canonical.sals))
9553*ef5ccd6cSJohn Marino 	return 0;
9554*ef5ccd6cSJohn Marino       break;
95555796c8dcSSimon Schubert     case RETURN_ERROR:
95565796c8dcSSimon Schubert       switch (e.error)
95575796c8dcSSimon Schubert 	{
95585796c8dcSSimon Schubert 	case NOT_FOUND_ERROR:
95595796c8dcSSimon Schubert 
95605796c8dcSSimon Schubert 	  /* If pending breakpoint support is turned off, throw
95615796c8dcSSimon Schubert 	     error.  */
95625796c8dcSSimon Schubert 
95635796c8dcSSimon Schubert 	  if (pending_break_support == AUTO_BOOLEAN_FALSE)
95645796c8dcSSimon Schubert 	    throw_exception (e);
95655796c8dcSSimon Schubert 
95665796c8dcSSimon Schubert 	  exception_print (gdb_stderr, e);
95675796c8dcSSimon Schubert 
95685796c8dcSSimon Schubert           /* If pending breakpoint support is auto query and the user
95695796c8dcSSimon Schubert 	     selects no, then simply return the error code.  */
95705796c8dcSSimon Schubert 	  if (pending_break_support == AUTO_BOOLEAN_AUTO
9571a45ae5f8SJohn Marino 	      && !nquery (_("Make %s pending on future shared library load? "),
9572a45ae5f8SJohn Marino 			  bptype_string (type_wanted)))
9573cf7f2e2dSJohn Marino 	    return 0;
95745796c8dcSSimon Schubert 
95755796c8dcSSimon Schubert 	  /* At this point, either the user was queried about setting
95765796c8dcSSimon Schubert 	     a pending breakpoint and selected yes, or pending
95775796c8dcSSimon Schubert 	     breakpoint behavior is on and thus a pending breakpoint
95785796c8dcSSimon Schubert 	     is defaulted on behalf of the user.  */
9579a45ae5f8SJohn Marino 	  {
9580a45ae5f8SJohn Marino 	    struct linespec_sals lsal;
9581a45ae5f8SJohn Marino 
95825796c8dcSSimon Schubert 	    copy_arg = xstrdup (addr_start);
9583a45ae5f8SJohn Marino 	    lsal.canonical = xstrdup (copy_arg);
9584a45ae5f8SJohn Marino 	    lsal.sals.nelts = 1;
9585a45ae5f8SJohn Marino 	    lsal.sals.sals = XNEW (struct symtab_and_line);
9586a45ae5f8SJohn Marino 	    init_sal (&lsal.sals.sals[0]);
95875796c8dcSSimon Schubert 	    pending = 1;
9588a45ae5f8SJohn Marino 	    VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9589a45ae5f8SJohn Marino 	  }
95905796c8dcSSimon Schubert 	  break;
95915796c8dcSSimon Schubert 	default:
95925796c8dcSSimon Schubert 	  throw_exception (e);
95935796c8dcSSimon Schubert 	}
9594c50c785cSJohn Marino       break;
95955796c8dcSSimon Schubert     default:
9596*ef5ccd6cSJohn Marino       throw_exception (e);
95975796c8dcSSimon Schubert     }
95985796c8dcSSimon Schubert 
95995796c8dcSSimon Schubert   /* Create a chain of things that always need to be cleaned up.  */
9600a45ae5f8SJohn Marino   old_chain = make_cleanup_destroy_linespec_result (&canonical);
96015796c8dcSSimon Schubert 
96025796c8dcSSimon Schubert   /* ----------------------------- SNIP -----------------------------
96035796c8dcSSimon Schubert      Anything added to the cleanup chain beyond this point is assumed
96045796c8dcSSimon Schubert      to be part of a breakpoint.  If the breakpoint create succeeds
96055796c8dcSSimon Schubert      then the memory is not reclaimed.  */
96065796c8dcSSimon Schubert   bkpt_chain = make_cleanup (null_cleanup, 0);
96075796c8dcSSimon Schubert 
96085796c8dcSSimon Schubert   /* Resolve all line numbers to PC's and verify that the addresses
96095796c8dcSSimon Schubert      are ok for the target.  */
96105796c8dcSSimon Schubert   if (!pending)
9611a45ae5f8SJohn Marino     {
9612a45ae5f8SJohn Marino       int ix;
9613a45ae5f8SJohn Marino       struct linespec_sals *iter;
9614a45ae5f8SJohn Marino 
9615a45ae5f8SJohn Marino       for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9616a45ae5f8SJohn Marino 	breakpoint_sals_to_pc (&iter->sals);
9617a45ae5f8SJohn Marino     }
96185796c8dcSSimon Schubert 
9619cf7f2e2dSJohn Marino   /* Fast tracepoints may have additional restrictions on location.  */
9620a45ae5f8SJohn Marino   if (!pending && type_wanted == bp_fast_tracepoint)
9621a45ae5f8SJohn Marino     {
9622a45ae5f8SJohn Marino       int ix;
9623a45ae5f8SJohn Marino       struct linespec_sals *iter;
9624a45ae5f8SJohn Marino 
9625a45ae5f8SJohn Marino       for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9626a45ae5f8SJohn Marino 	check_fast_tracepoint_sals (gdbarch, &iter->sals);
9627a45ae5f8SJohn Marino     }
96285796c8dcSSimon Schubert 
96295796c8dcSSimon Schubert   /* Verify that condition can be parsed, before setting any
96305796c8dcSSimon Schubert      breakpoints.  Allocate a separate condition expression for each
96315796c8dcSSimon Schubert      breakpoint.  */
96325796c8dcSSimon Schubert   if (!pending)
96335796c8dcSSimon Schubert     {
9634a45ae5f8SJohn Marino       struct linespec_sals *lsal;
9635a45ae5f8SJohn Marino 
9636a45ae5f8SJohn Marino       lsal = VEC_index (linespec_sals, canonical.sals, 0);
9637a45ae5f8SJohn Marino 
96385796c8dcSSimon Schubert       if (parse_condition_and_thread)
96395796c8dcSSimon Schubert         {
9640*ef5ccd6cSJohn Marino 	    char *rest;
96415796c8dcSSimon Schubert             /* Here we only parse 'arg' to separate condition
96425796c8dcSSimon Schubert                from thread number, so parsing in context of first
96435796c8dcSSimon Schubert                sal is OK.  When setting the breakpoint we'll
96445796c8dcSSimon Schubert                re-parse it in context of each sal.  */
9645*ef5ccd6cSJohn Marino 
9646a45ae5f8SJohn Marino             find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
9647*ef5ccd6cSJohn Marino                                        &thread, &task, &rest);
96485796c8dcSSimon Schubert             if (cond_string)
96495796c8dcSSimon Schubert                 make_cleanup (xfree, cond_string);
9650*ef5ccd6cSJohn Marino 	    if (rest)
9651*ef5ccd6cSJohn Marino 	      make_cleanup (xfree, rest);
9652*ef5ccd6cSJohn Marino 	    if (rest)
9653*ef5ccd6cSJohn Marino 	      extra_string = rest;
96545796c8dcSSimon Schubert         }
96555796c8dcSSimon Schubert       else
96565796c8dcSSimon Schubert         {
96575796c8dcSSimon Schubert             /* Create a private copy of condition string.  */
96585796c8dcSSimon Schubert             if (cond_string)
96595796c8dcSSimon Schubert             {
96605796c8dcSSimon Schubert                 cond_string = xstrdup (cond_string);
96615796c8dcSSimon Schubert                 make_cleanup (xfree, cond_string);
96625796c8dcSSimon Schubert             }
9663*ef5ccd6cSJohn Marino             /* Create a private copy of any extra string.  */
9664*ef5ccd6cSJohn Marino             if (extra_string)
9665*ef5ccd6cSJohn Marino 	      {
9666*ef5ccd6cSJohn Marino                 extra_string = xstrdup (extra_string);
9667*ef5ccd6cSJohn Marino                 make_cleanup (xfree, extra_string);
9668*ef5ccd6cSJohn Marino 	      }
96695796c8dcSSimon Schubert         }
9670cf7f2e2dSJohn Marino 
9671*ef5ccd6cSJohn Marino       ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
9672*ef5ccd6cSJohn Marino 				   cond_string, extra_string, type_wanted,
96735796c8dcSSimon Schubert 				   tempflag ? disp_del : disp_donttouch,
9674cf7f2e2dSJohn Marino 				   thread, task, ignore_count, ops,
9675*ef5ccd6cSJohn Marino 				   from_tty, enabled, internal, flags);
96765796c8dcSSimon Schubert     }
96775796c8dcSSimon Schubert   else
96785796c8dcSSimon Schubert     {
96795796c8dcSSimon Schubert       struct breakpoint *b;
96805796c8dcSSimon Schubert 
96815796c8dcSSimon Schubert       make_cleanup (xfree, copy_arg);
96825796c8dcSSimon Schubert 
9683a45ae5f8SJohn Marino       if (is_tracepoint_type (type_wanted))
9684a45ae5f8SJohn Marino 	{
9685a45ae5f8SJohn Marino 	  struct tracepoint *t;
9686a45ae5f8SJohn Marino 
9687a45ae5f8SJohn Marino 	  t = XCNEW (struct tracepoint);
9688a45ae5f8SJohn Marino 	  b = &t->base;
9689a45ae5f8SJohn Marino 	}
9690a45ae5f8SJohn Marino       else
9691a45ae5f8SJohn Marino 	b = XNEW (struct breakpoint);
9692a45ae5f8SJohn Marino 
9693a45ae5f8SJohn Marino       init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9694a45ae5f8SJohn Marino 
9695a45ae5f8SJohn Marino       b->addr_string = copy_arg;
9696*ef5ccd6cSJohn Marino       if (parse_condition_and_thread)
96975796c8dcSSimon Schubert 	b->cond_string = NULL;
9698*ef5ccd6cSJohn Marino       else
9699*ef5ccd6cSJohn Marino 	{
9700*ef5ccd6cSJohn Marino 	  /* Create a private copy of condition string.  */
9701*ef5ccd6cSJohn Marino 	  if (cond_string)
9702*ef5ccd6cSJohn Marino 	    {
9703*ef5ccd6cSJohn Marino 	      cond_string = xstrdup (cond_string);
9704*ef5ccd6cSJohn Marino 	      make_cleanup (xfree, cond_string);
9705*ef5ccd6cSJohn Marino 	    }
9706*ef5ccd6cSJohn Marino 	  b->cond_string = cond_string;
9707*ef5ccd6cSJohn Marino 	}
9708*ef5ccd6cSJohn Marino       b->extra_string = NULL;
97095796c8dcSSimon Schubert       b->ignore_count = ignore_count;
97105796c8dcSSimon Schubert       b->disposition = tempflag ? disp_del : disp_donttouch;
97115796c8dcSSimon Schubert       b->condition_not_parsed = 1;
97125796c8dcSSimon Schubert       b->enable_state = enabled ? bp_enabled : bp_disabled;
9713a45ae5f8SJohn Marino       if ((type_wanted != bp_breakpoint
9714a45ae5f8SJohn Marino            && type_wanted != bp_hardware_breakpoint) || thread != -1)
9715cf7f2e2dSJohn Marino 	b->pspace = current_program_space;
97165796c8dcSSimon Schubert 
9717a45ae5f8SJohn Marino       install_breakpoint (internal, b, 0);
97185796c8dcSSimon Schubert     }
97195796c8dcSSimon Schubert 
9720a45ae5f8SJohn Marino   if (VEC_length (linespec_sals, canonical.sals) > 1)
9721cf7f2e2dSJohn Marino     {
9722c50c785cSJohn Marino       warning (_("Multiple breakpoints were set.\nUse the "
9723c50c785cSJohn Marino 		 "\"delete\" command to delete unwanted breakpoints."));
9724cf7f2e2dSJohn Marino       prev_breakpoint_count = prev_bkpt_count;
9725cf7f2e2dSJohn Marino     }
9726cf7f2e2dSJohn Marino 
97275796c8dcSSimon Schubert   /* That's it.  Discard the cleanups for data inserted into the
97285796c8dcSSimon Schubert      breakpoint.  */
97295796c8dcSSimon Schubert   discard_cleanups (bkpt_chain);
97305796c8dcSSimon Schubert   /* But cleanup everything else.  */
97315796c8dcSSimon Schubert   do_cleanups (old_chain);
97325796c8dcSSimon Schubert 
97335796c8dcSSimon Schubert   /* error call may happen here - have BKPT_CHAIN already discarded.  */
97345796c8dcSSimon Schubert   update_global_location_list (1);
9735cf7f2e2dSJohn Marino 
9736cf7f2e2dSJohn Marino   return 1;
97375796c8dcSSimon Schubert }
97385796c8dcSSimon Schubert 
97395796c8dcSSimon Schubert /* Set a breakpoint.
97405796c8dcSSimon Schubert    ARG is a string describing breakpoint address,
97415796c8dcSSimon Schubert    condition, and thread.
97425796c8dcSSimon Schubert    FLAG specifies if a breakpoint is hardware on,
97435796c8dcSSimon Schubert    and if breakpoint is temporary, using BP_HARDWARE_FLAG
97445796c8dcSSimon Schubert    and BP_TEMPFLAG.  */
97455796c8dcSSimon Schubert 
97465796c8dcSSimon Schubert static void
break_command_1(char * arg,int flag,int from_tty)97475796c8dcSSimon Schubert break_command_1 (char *arg, int flag, int from_tty)
97485796c8dcSSimon Schubert {
97495796c8dcSSimon Schubert   int tempflag = flag & BP_TEMPFLAG;
9750cf7f2e2dSJohn Marino   enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9751cf7f2e2dSJohn Marino 			     ? bp_hardware_breakpoint
9752cf7f2e2dSJohn Marino 			     : bp_breakpoint);
9753*ef5ccd6cSJohn Marino   struct breakpoint_ops *ops;
9754*ef5ccd6cSJohn Marino   const char *arg_cp = arg;
9755*ef5ccd6cSJohn Marino 
9756*ef5ccd6cSJohn Marino   /* Matching breakpoints on probes.  */
9757*ef5ccd6cSJohn Marino   if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9758*ef5ccd6cSJohn Marino     ops = &bkpt_probe_breakpoint_ops;
9759*ef5ccd6cSJohn Marino   else
9760*ef5ccd6cSJohn Marino     ops = &bkpt_breakpoint_ops;
97615796c8dcSSimon Schubert 
9762cf7f2e2dSJohn Marino   create_breakpoint (get_current_arch (),
97635796c8dcSSimon Schubert 		     arg,
9764*ef5ccd6cSJohn Marino 		     NULL, 0, NULL, 1 /* parse arg */,
9765cf7f2e2dSJohn Marino 		     tempflag, type_wanted,
97665796c8dcSSimon Schubert 		     0 /* Ignore count */,
97675796c8dcSSimon Schubert 		     pending_break_support,
9768*ef5ccd6cSJohn Marino 		     ops,
97695796c8dcSSimon Schubert 		     from_tty,
9770c50c785cSJohn Marino 		     1 /* enabled */,
9771a45ae5f8SJohn Marino 		     0 /* internal */,
9772a45ae5f8SJohn Marino 		     0);
97735796c8dcSSimon Schubert }
97745796c8dcSSimon Schubert 
97755796c8dcSSimon Schubert /* Helper function for break_command_1 and disassemble_command.  */
97765796c8dcSSimon Schubert 
97775796c8dcSSimon Schubert void
resolve_sal_pc(struct symtab_and_line * sal)97785796c8dcSSimon Schubert resolve_sal_pc (struct symtab_and_line *sal)
97795796c8dcSSimon Schubert {
97805796c8dcSSimon Schubert   CORE_ADDR pc;
97815796c8dcSSimon Schubert 
97825796c8dcSSimon Schubert   if (sal->pc == 0 && sal->symtab != NULL)
97835796c8dcSSimon Schubert     {
97845796c8dcSSimon Schubert       if (!find_line_pc (sal->symtab, sal->line, &pc))
97855796c8dcSSimon Schubert 	error (_("No line %d in file \"%s\"."),
9786*ef5ccd6cSJohn Marino 	       sal->line, symtab_to_filename_for_display (sal->symtab));
97875796c8dcSSimon Schubert       sal->pc = pc;
97885796c8dcSSimon Schubert 
9789c50c785cSJohn Marino       /* If this SAL corresponds to a breakpoint inserted using a line
9790c50c785cSJohn Marino          number, then skip the function prologue if necessary.  */
97915796c8dcSSimon Schubert       if (sal->explicit_line)
97925796c8dcSSimon Schubert 	skip_prologue_sal (sal);
97935796c8dcSSimon Schubert     }
97945796c8dcSSimon Schubert 
97955796c8dcSSimon Schubert   if (sal->section == 0 && sal->symtab != NULL)
97965796c8dcSSimon Schubert     {
97975796c8dcSSimon Schubert       struct blockvector *bv;
97985796c8dcSSimon Schubert       struct block *b;
97995796c8dcSSimon Schubert       struct symbol *sym;
98005796c8dcSSimon Schubert 
98015796c8dcSSimon Schubert       bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
98025796c8dcSSimon Schubert       if (bv != NULL)
98035796c8dcSSimon Schubert 	{
98045796c8dcSSimon Schubert 	  sym = block_linkage_function (b);
98055796c8dcSSimon Schubert 	  if (sym != NULL)
98065796c8dcSSimon Schubert 	    {
98075796c8dcSSimon Schubert 	      fixup_symbol_section (sym, sal->symtab->objfile);
98085796c8dcSSimon Schubert 	      sal->section = SYMBOL_OBJ_SECTION (sym);
98095796c8dcSSimon Schubert 	    }
98105796c8dcSSimon Schubert 	  else
98115796c8dcSSimon Schubert 	    {
9812c50c785cSJohn Marino 	      /* It really is worthwhile to have the section, so we'll
9813c50c785cSJohn Marino 	         just have to look harder. This case can be executed
9814c50c785cSJohn Marino 	         if we have line numbers but no functions (as can
9815c50c785cSJohn Marino 	         happen in assembly source).  */
98165796c8dcSSimon Schubert 
98175796c8dcSSimon Schubert 	      struct minimal_symbol *msym;
9818cf7f2e2dSJohn Marino 	      struct cleanup *old_chain = save_current_space_and_thread ();
9819cf7f2e2dSJohn Marino 
9820cf7f2e2dSJohn Marino 	      switch_to_program_space_and_thread (sal->pspace);
98215796c8dcSSimon Schubert 
98225796c8dcSSimon Schubert 	      msym = lookup_minimal_symbol_by_pc (sal->pc);
98235796c8dcSSimon Schubert 	      if (msym)
98245796c8dcSSimon Schubert 		sal->section = SYMBOL_OBJ_SECTION (msym);
9825cf7f2e2dSJohn Marino 
9826cf7f2e2dSJohn Marino 	      do_cleanups (old_chain);
98275796c8dcSSimon Schubert 	    }
98285796c8dcSSimon Schubert 	}
98295796c8dcSSimon Schubert     }
98305796c8dcSSimon Schubert }
98315796c8dcSSimon Schubert 
98325796c8dcSSimon Schubert void
break_command(char * arg,int from_tty)98335796c8dcSSimon Schubert break_command (char *arg, int from_tty)
98345796c8dcSSimon Schubert {
98355796c8dcSSimon Schubert   break_command_1 (arg, 0, from_tty);
98365796c8dcSSimon Schubert }
98375796c8dcSSimon Schubert 
98385796c8dcSSimon Schubert void
tbreak_command(char * arg,int from_tty)98395796c8dcSSimon Schubert tbreak_command (char *arg, int from_tty)
98405796c8dcSSimon Schubert {
98415796c8dcSSimon Schubert   break_command_1 (arg, BP_TEMPFLAG, from_tty);
98425796c8dcSSimon Schubert }
98435796c8dcSSimon Schubert 
98445796c8dcSSimon Schubert static void
hbreak_command(char * arg,int from_tty)98455796c8dcSSimon Schubert hbreak_command (char *arg, int from_tty)
98465796c8dcSSimon Schubert {
98475796c8dcSSimon Schubert   break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
98485796c8dcSSimon Schubert }
98495796c8dcSSimon Schubert 
98505796c8dcSSimon Schubert static void
thbreak_command(char * arg,int from_tty)98515796c8dcSSimon Schubert thbreak_command (char *arg, int from_tty)
98525796c8dcSSimon Schubert {
98535796c8dcSSimon Schubert   break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
98545796c8dcSSimon Schubert }
98555796c8dcSSimon Schubert 
98565796c8dcSSimon Schubert static void
stop_command(char * arg,int from_tty)98575796c8dcSSimon Schubert stop_command (char *arg, int from_tty)
98585796c8dcSSimon Schubert {
98595796c8dcSSimon Schubert   printf_filtered (_("Specify the type of breakpoint to set.\n\
98605796c8dcSSimon Schubert Usage: stop in <function | address>\n\
98615796c8dcSSimon Schubert        stop at <line>\n"));
98625796c8dcSSimon Schubert }
98635796c8dcSSimon Schubert 
98645796c8dcSSimon Schubert static void
stopin_command(char * arg,int from_tty)98655796c8dcSSimon Schubert stopin_command (char *arg, int from_tty)
98665796c8dcSSimon Schubert {
98675796c8dcSSimon Schubert   int badInput = 0;
98685796c8dcSSimon Schubert 
98695796c8dcSSimon Schubert   if (arg == (char *) NULL)
98705796c8dcSSimon Schubert     badInput = 1;
98715796c8dcSSimon Schubert   else if (*arg != '*')
98725796c8dcSSimon Schubert     {
98735796c8dcSSimon Schubert       char *argptr = arg;
98745796c8dcSSimon Schubert       int hasColon = 0;
98755796c8dcSSimon Schubert 
9876c50c785cSJohn Marino       /* Look for a ':'.  If this is a line number specification, then
98775796c8dcSSimon Schubert          say it is bad, otherwise, it should be an address or
9878c50c785cSJohn Marino          function/method name.  */
98795796c8dcSSimon Schubert       while (*argptr && !hasColon)
98805796c8dcSSimon Schubert 	{
98815796c8dcSSimon Schubert 	  hasColon = (*argptr == ':');
98825796c8dcSSimon Schubert 	  argptr++;
98835796c8dcSSimon Schubert 	}
98845796c8dcSSimon Schubert 
98855796c8dcSSimon Schubert       if (hasColon)
98865796c8dcSSimon Schubert 	badInput = (*argptr != ':');	/* Not a class::method */
98875796c8dcSSimon Schubert       else
98885796c8dcSSimon Schubert 	badInput = isdigit (*arg);	/* a simple line number */
98895796c8dcSSimon Schubert     }
98905796c8dcSSimon Schubert 
98915796c8dcSSimon Schubert   if (badInput)
98925796c8dcSSimon Schubert     printf_filtered (_("Usage: stop in <function | address>\n"));
98935796c8dcSSimon Schubert   else
98945796c8dcSSimon Schubert     break_command_1 (arg, 0, from_tty);
98955796c8dcSSimon Schubert }
98965796c8dcSSimon Schubert 
98975796c8dcSSimon Schubert static void
stopat_command(char * arg,int from_tty)98985796c8dcSSimon Schubert stopat_command (char *arg, int from_tty)
98995796c8dcSSimon Schubert {
99005796c8dcSSimon Schubert   int badInput = 0;
99015796c8dcSSimon Schubert 
99025796c8dcSSimon Schubert   if (arg == (char *) NULL || *arg == '*')	/* no line number */
99035796c8dcSSimon Schubert     badInput = 1;
99045796c8dcSSimon Schubert   else
99055796c8dcSSimon Schubert     {
99065796c8dcSSimon Schubert       char *argptr = arg;
99075796c8dcSSimon Schubert       int hasColon = 0;
99085796c8dcSSimon Schubert 
9909c50c785cSJohn Marino       /* Look for a ':'.  If there is a '::' then get out, otherwise
99105796c8dcSSimon Schubert          it is probably a line number.  */
99115796c8dcSSimon Schubert       while (*argptr && !hasColon)
99125796c8dcSSimon Schubert 	{
99135796c8dcSSimon Schubert 	  hasColon = (*argptr == ':');
99145796c8dcSSimon Schubert 	  argptr++;
99155796c8dcSSimon Schubert 	}
99165796c8dcSSimon Schubert 
99175796c8dcSSimon Schubert       if (hasColon)
99185796c8dcSSimon Schubert 	badInput = (*argptr == ':');	/* we have class::method */
99195796c8dcSSimon Schubert       else
99205796c8dcSSimon Schubert 	badInput = !isdigit (*arg);	/* not a line number */
99215796c8dcSSimon Schubert     }
99225796c8dcSSimon Schubert 
99235796c8dcSSimon Schubert   if (badInput)
99245796c8dcSSimon Schubert     printf_filtered (_("Usage: stop at <line>\n"));
99255796c8dcSSimon Schubert   else
99265796c8dcSSimon Schubert     break_command_1 (arg, 0, from_tty);
99275796c8dcSSimon Schubert }
99285796c8dcSSimon Schubert 
9929*ef5ccd6cSJohn Marino /* The dynamic printf command is mostly like a regular breakpoint, but
9930*ef5ccd6cSJohn Marino    with a prewired command list consisting of a single output command,
9931*ef5ccd6cSJohn Marino    built from extra arguments supplied on the dprintf command
9932*ef5ccd6cSJohn Marino    line.  */
9933*ef5ccd6cSJohn Marino 
9934*ef5ccd6cSJohn Marino static void
dprintf_command(char * arg,int from_tty)9935*ef5ccd6cSJohn Marino dprintf_command (char *arg, int from_tty)
9936*ef5ccd6cSJohn Marino {
9937*ef5ccd6cSJohn Marino   create_breakpoint (get_current_arch (),
9938*ef5ccd6cSJohn Marino 		     arg,
9939*ef5ccd6cSJohn Marino 		     NULL, 0, NULL, 1 /* parse arg */,
9940*ef5ccd6cSJohn Marino 		     0, bp_dprintf,
9941*ef5ccd6cSJohn Marino 		     0 /* Ignore count */,
9942*ef5ccd6cSJohn Marino 		     pending_break_support,
9943*ef5ccd6cSJohn Marino 		     &dprintf_breakpoint_ops,
9944*ef5ccd6cSJohn Marino 		     from_tty,
9945*ef5ccd6cSJohn Marino 		     1 /* enabled */,
9946*ef5ccd6cSJohn Marino 		     0 /* internal */,
9947*ef5ccd6cSJohn Marino 		     0);
9948*ef5ccd6cSJohn Marino }
9949*ef5ccd6cSJohn Marino 
9950*ef5ccd6cSJohn Marino static void
agent_printf_command(char * arg,int from_tty)9951*ef5ccd6cSJohn Marino agent_printf_command (char *arg, int from_tty)
9952*ef5ccd6cSJohn Marino {
9953*ef5ccd6cSJohn Marino   error (_("May only run agent-printf on the target"));
9954*ef5ccd6cSJohn Marino }
9955*ef5ccd6cSJohn Marino 
9956c50c785cSJohn Marino /* Implement the "breakpoint_hit" breakpoint_ops method for
9957c50c785cSJohn Marino    ranged breakpoints.  */
9958c50c785cSJohn Marino 
9959c50c785cSJohn Marino static int
breakpoint_hit_ranged_breakpoint(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)9960c50c785cSJohn Marino breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9961c50c785cSJohn Marino 				  struct address_space *aspace,
9962*ef5ccd6cSJohn Marino 				  CORE_ADDR bp_addr,
9963*ef5ccd6cSJohn Marino 				  const struct target_waitstatus *ws)
9964c50c785cSJohn Marino {
9965*ef5ccd6cSJohn Marino   if (ws->kind != TARGET_WAITKIND_STOPPED
9966*ef5ccd6cSJohn Marino       || ws->value.sig != GDB_SIGNAL_TRAP)
9967*ef5ccd6cSJohn Marino     return 0;
9968*ef5ccd6cSJohn Marino 
9969c50c785cSJohn Marino   return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9970c50c785cSJohn Marino 					 bl->length, aspace, bp_addr);
9971c50c785cSJohn Marino }
9972c50c785cSJohn Marino 
9973c50c785cSJohn Marino /* Implement the "resources_needed" breakpoint_ops method for
9974c50c785cSJohn Marino    ranged breakpoints.  */
9975c50c785cSJohn Marino 
9976c50c785cSJohn Marino static int
resources_needed_ranged_breakpoint(const struct bp_location * bl)9977c50c785cSJohn Marino resources_needed_ranged_breakpoint (const struct bp_location *bl)
9978c50c785cSJohn Marino {
9979c50c785cSJohn Marino   return target_ranged_break_num_registers ();
9980c50c785cSJohn Marino }
9981c50c785cSJohn Marino 
9982c50c785cSJohn Marino /* Implement the "print_it" breakpoint_ops method for
9983c50c785cSJohn Marino    ranged breakpoints.  */
9984c50c785cSJohn Marino 
9985c50c785cSJohn Marino static enum print_stop_action
print_it_ranged_breakpoint(bpstat bs)9986a45ae5f8SJohn Marino print_it_ranged_breakpoint (bpstat bs)
9987c50c785cSJohn Marino {
9988a45ae5f8SJohn Marino   struct breakpoint *b = bs->breakpoint_at;
9989c50c785cSJohn Marino   struct bp_location *bl = b->loc;
9990a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
9991c50c785cSJohn Marino 
9992c50c785cSJohn Marino   gdb_assert (b->type == bp_hardware_breakpoint);
9993c50c785cSJohn Marino 
9994c50c785cSJohn Marino   /* Ranged breakpoints have only one location.  */
9995c50c785cSJohn Marino   gdb_assert (bl && bl->next == NULL);
9996c50c785cSJohn Marino 
9997c50c785cSJohn Marino   annotate_breakpoint (b->number);
9998c50c785cSJohn Marino   if (b->disposition == disp_del)
9999c50c785cSJohn Marino     ui_out_text (uiout, "\nTemporary ranged breakpoint ");
10000c50c785cSJohn Marino   else
10001c50c785cSJohn Marino     ui_out_text (uiout, "\nRanged breakpoint ");
10002c50c785cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
10003c50c785cSJohn Marino     {
10004c50c785cSJohn Marino       ui_out_field_string (uiout, "reason",
10005c50c785cSJohn Marino 		      async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10006c50c785cSJohn Marino       ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10007c50c785cSJohn Marino     }
10008c50c785cSJohn Marino   ui_out_field_int (uiout, "bkptno", b->number);
10009c50c785cSJohn Marino   ui_out_text (uiout, ", ");
10010c50c785cSJohn Marino 
10011c50c785cSJohn Marino   return PRINT_SRC_AND_LOC;
10012c50c785cSJohn Marino }
10013c50c785cSJohn Marino 
10014c50c785cSJohn Marino /* Implement the "print_one" breakpoint_ops method for
10015c50c785cSJohn Marino    ranged breakpoints.  */
10016c50c785cSJohn Marino 
10017c50c785cSJohn Marino static void
print_one_ranged_breakpoint(struct breakpoint * b,struct bp_location ** last_loc)10018c50c785cSJohn Marino print_one_ranged_breakpoint (struct breakpoint *b,
10019c50c785cSJohn Marino 			     struct bp_location **last_loc)
10020c50c785cSJohn Marino {
10021c50c785cSJohn Marino   struct bp_location *bl = b->loc;
10022c50c785cSJohn Marino   struct value_print_options opts;
10023a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
10024c50c785cSJohn Marino 
10025c50c785cSJohn Marino   /* Ranged breakpoints have only one location.  */
10026c50c785cSJohn Marino   gdb_assert (bl && bl->next == NULL);
10027c50c785cSJohn Marino 
10028c50c785cSJohn Marino   get_user_print_options (&opts);
10029c50c785cSJohn Marino 
10030c50c785cSJohn Marino   if (opts.addressprint)
10031c50c785cSJohn Marino     /* We don't print the address range here, it will be printed later
10032c50c785cSJohn Marino        by print_one_detail_ranged_breakpoint.  */
10033c50c785cSJohn Marino     ui_out_field_skip (uiout, "addr");
10034c50c785cSJohn Marino   annotate_field (5);
10035c50c785cSJohn Marino   print_breakpoint_location (b, bl);
10036c50c785cSJohn Marino   *last_loc = bl;
10037c50c785cSJohn Marino }
10038c50c785cSJohn Marino 
10039c50c785cSJohn Marino /* Implement the "print_one_detail" breakpoint_ops method for
10040c50c785cSJohn Marino    ranged breakpoints.  */
10041c50c785cSJohn Marino 
10042c50c785cSJohn Marino static void
print_one_detail_ranged_breakpoint(const struct breakpoint * b,struct ui_out * uiout)10043c50c785cSJohn Marino print_one_detail_ranged_breakpoint (const struct breakpoint *b,
10044c50c785cSJohn Marino 				    struct ui_out *uiout)
10045c50c785cSJohn Marino {
10046c50c785cSJohn Marino   CORE_ADDR address_start, address_end;
10047c50c785cSJohn Marino   struct bp_location *bl = b->loc;
10048*ef5ccd6cSJohn Marino   struct ui_file *stb = mem_fileopen ();
10049*ef5ccd6cSJohn Marino   struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
10050c50c785cSJohn Marino 
10051c50c785cSJohn Marino   gdb_assert (bl);
10052c50c785cSJohn Marino 
10053c50c785cSJohn Marino   address_start = bl->address;
10054c50c785cSJohn Marino   address_end = address_start + bl->length - 1;
10055c50c785cSJohn Marino 
10056c50c785cSJohn Marino   ui_out_text (uiout, "\taddress range: ");
10057*ef5ccd6cSJohn Marino   fprintf_unfiltered (stb, "[%s, %s]",
10058c50c785cSJohn Marino 		      print_core_address (bl->gdbarch, address_start),
10059c50c785cSJohn Marino 		      print_core_address (bl->gdbarch, address_end));
10060c50c785cSJohn Marino   ui_out_field_stream (uiout, "addr", stb);
10061c50c785cSJohn Marino   ui_out_text (uiout, "\n");
10062c50c785cSJohn Marino 
10063c50c785cSJohn Marino   do_cleanups (cleanup);
10064c50c785cSJohn Marino }
10065c50c785cSJohn Marino 
10066c50c785cSJohn Marino /* Implement the "print_mention" breakpoint_ops method for
10067c50c785cSJohn Marino    ranged breakpoints.  */
10068c50c785cSJohn Marino 
10069c50c785cSJohn Marino static void
print_mention_ranged_breakpoint(struct breakpoint * b)10070c50c785cSJohn Marino print_mention_ranged_breakpoint (struct breakpoint *b)
10071c50c785cSJohn Marino {
10072c50c785cSJohn Marino   struct bp_location *bl = b->loc;
10073a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
10074c50c785cSJohn Marino 
10075c50c785cSJohn Marino   gdb_assert (bl);
10076c50c785cSJohn Marino   gdb_assert (b->type == bp_hardware_breakpoint);
10077c50c785cSJohn Marino 
10078c50c785cSJohn Marino   if (ui_out_is_mi_like_p (uiout))
10079c50c785cSJohn Marino     return;
10080c50c785cSJohn Marino 
10081c50c785cSJohn Marino   printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10082c50c785cSJohn Marino 		   b->number, paddress (bl->gdbarch, bl->address),
10083c50c785cSJohn Marino 		   paddress (bl->gdbarch, bl->address + bl->length - 1));
10084c50c785cSJohn Marino }
10085c50c785cSJohn Marino 
10086c50c785cSJohn Marino /* Implement the "print_recreate" breakpoint_ops method for
10087c50c785cSJohn Marino    ranged breakpoints.  */
10088c50c785cSJohn Marino 
10089c50c785cSJohn Marino static void
print_recreate_ranged_breakpoint(struct breakpoint * b,struct ui_file * fp)10090c50c785cSJohn Marino print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
10091c50c785cSJohn Marino {
10092c50c785cSJohn Marino   fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
10093c50c785cSJohn Marino 		      b->addr_string_range_end);
10094a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
10095c50c785cSJohn Marino }
10096c50c785cSJohn Marino 
10097c50c785cSJohn Marino /* The breakpoint_ops structure to be used in ranged breakpoints.  */
10098c50c785cSJohn Marino 
10099a45ae5f8SJohn Marino static struct breakpoint_ops ranged_breakpoint_ops;
10100c50c785cSJohn Marino 
10101c50c785cSJohn Marino /* Find the address where the end of the breakpoint range should be
10102c50c785cSJohn Marino    placed, given the SAL of the end of the range.  This is so that if
10103c50c785cSJohn Marino    the user provides a line number, the end of the range is set to the
10104c50c785cSJohn Marino    last instruction of the given line.  */
10105c50c785cSJohn Marino 
10106c50c785cSJohn Marino static CORE_ADDR
find_breakpoint_range_end(struct symtab_and_line sal)10107c50c785cSJohn Marino find_breakpoint_range_end (struct symtab_and_line sal)
10108c50c785cSJohn Marino {
10109c50c785cSJohn Marino   CORE_ADDR end;
10110c50c785cSJohn Marino 
10111c50c785cSJohn Marino   /* If the user provided a PC value, use it.  Otherwise,
10112c50c785cSJohn Marino      find the address of the end of the given location.  */
10113c50c785cSJohn Marino   if (sal.explicit_pc)
10114c50c785cSJohn Marino     end = sal.pc;
10115c50c785cSJohn Marino   else
10116c50c785cSJohn Marino     {
10117c50c785cSJohn Marino       int ret;
10118c50c785cSJohn Marino       CORE_ADDR start;
10119c50c785cSJohn Marino 
10120c50c785cSJohn Marino       ret = find_line_pc_range (sal, &start, &end);
10121c50c785cSJohn Marino       if (!ret)
10122c50c785cSJohn Marino 	error (_("Could not find location of the end of the range."));
10123c50c785cSJohn Marino 
10124c50c785cSJohn Marino       /* find_line_pc_range returns the start of the next line.  */
10125c50c785cSJohn Marino       end--;
10126c50c785cSJohn Marino     }
10127c50c785cSJohn Marino 
10128c50c785cSJohn Marino   return end;
10129c50c785cSJohn Marino }
10130c50c785cSJohn Marino 
10131c50c785cSJohn Marino /* Implement the "break-range" CLI command.  */
10132c50c785cSJohn Marino 
10133c50c785cSJohn Marino static void
break_range_command(char * arg,int from_tty)10134c50c785cSJohn Marino break_range_command (char *arg, int from_tty)
10135c50c785cSJohn Marino {
10136c50c785cSJohn Marino   char *arg_start, *addr_string_start, *addr_string_end;
10137c50c785cSJohn Marino   struct linespec_result canonical_start, canonical_end;
10138c50c785cSJohn Marino   int bp_count, can_use_bp, length;
10139c50c785cSJohn Marino   CORE_ADDR end;
10140c50c785cSJohn Marino   struct breakpoint *b;
10141c50c785cSJohn Marino   struct symtab_and_line sal_start, sal_end;
10142c50c785cSJohn Marino   struct cleanup *cleanup_bkpt;
10143a45ae5f8SJohn Marino   struct linespec_sals *lsal_start, *lsal_end;
10144c50c785cSJohn Marino 
10145c50c785cSJohn Marino   /* We don't support software ranged breakpoints.  */
10146c50c785cSJohn Marino   if (target_ranged_break_num_registers () < 0)
10147c50c785cSJohn Marino     error (_("This target does not support hardware ranged breakpoints."));
10148c50c785cSJohn Marino 
10149c50c785cSJohn Marino   bp_count = hw_breakpoint_used_count ();
10150c50c785cSJohn Marino   bp_count += target_ranged_break_num_registers ();
10151c50c785cSJohn Marino   can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
10152c50c785cSJohn Marino 						   bp_count, 0);
10153c50c785cSJohn Marino   if (can_use_bp < 0)
10154c50c785cSJohn Marino     error (_("Hardware breakpoints used exceeds limit."));
10155c50c785cSJohn Marino 
10156a45ae5f8SJohn Marino   arg = skip_spaces (arg);
10157c50c785cSJohn Marino   if (arg == NULL || arg[0] == '\0')
10158c50c785cSJohn Marino     error(_("No address range specified."));
10159c50c785cSJohn Marino 
10160c50c785cSJohn Marino   init_linespec_result (&canonical_start);
10161c50c785cSJohn Marino 
10162a45ae5f8SJohn Marino   arg_start = arg;
10163a45ae5f8SJohn Marino   parse_breakpoint_sals (&arg, &canonical_start);
10164c50c785cSJohn Marino 
10165a45ae5f8SJohn Marino   cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
10166c50c785cSJohn Marino 
10167c50c785cSJohn Marino   if (arg[0] != ',')
10168c50c785cSJohn Marino     error (_("Too few arguments."));
10169a45ae5f8SJohn Marino   else if (VEC_empty (linespec_sals, canonical_start.sals))
10170c50c785cSJohn Marino     error (_("Could not find location of the beginning of the range."));
10171a45ae5f8SJohn Marino 
10172a45ae5f8SJohn Marino   lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
10173a45ae5f8SJohn Marino 
10174a45ae5f8SJohn Marino   if (VEC_length (linespec_sals, canonical_start.sals) > 1
10175a45ae5f8SJohn Marino       || lsal_start->sals.nelts != 1)
10176c50c785cSJohn Marino     error (_("Cannot create a ranged breakpoint with multiple locations."));
10177c50c785cSJohn Marino 
10178a45ae5f8SJohn Marino   sal_start = lsal_start->sals.sals[0];
10179a45ae5f8SJohn Marino   addr_string_start = savestring (arg_start, arg - arg_start);
10180a45ae5f8SJohn Marino   make_cleanup (xfree, addr_string_start);
10181c50c785cSJohn Marino 
10182c50c785cSJohn Marino   arg++;	/* Skip the comma.  */
10183a45ae5f8SJohn Marino   arg = skip_spaces (arg);
10184c50c785cSJohn Marino 
10185c50c785cSJohn Marino   /* Parse the end location.  */
10186c50c785cSJohn Marino 
10187c50c785cSJohn Marino   init_linespec_result (&canonical_end);
10188c50c785cSJohn Marino   arg_start = arg;
10189c50c785cSJohn Marino 
10190a45ae5f8SJohn Marino   /* We call decode_line_full directly here instead of using
10191c50c785cSJohn Marino      parse_breakpoint_sals because we need to specify the start location's
10192c50c785cSJohn Marino      symtab and line as the default symtab and line for the end of the
10193c50c785cSJohn Marino      range.  This makes it possible to have ranges like "foo.c:27, +14",
10194c50c785cSJohn Marino      where +14 means 14 lines from the start location.  */
10195a45ae5f8SJohn Marino   decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
10196a45ae5f8SJohn Marino 		    sal_start.symtab, sal_start.line,
10197a45ae5f8SJohn Marino 		    &canonical_end, NULL, NULL);
10198c50c785cSJohn Marino 
10199a45ae5f8SJohn Marino   make_cleanup_destroy_linespec_result (&canonical_end);
10200c50c785cSJohn Marino 
10201a45ae5f8SJohn Marino   if (VEC_empty (linespec_sals, canonical_end.sals))
10202c50c785cSJohn Marino     error (_("Could not find location of the end of the range."));
10203a45ae5f8SJohn Marino 
10204a45ae5f8SJohn Marino   lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
10205a45ae5f8SJohn Marino   if (VEC_length (linespec_sals, canonical_end.sals) > 1
10206a45ae5f8SJohn Marino       || lsal_end->sals.nelts != 1)
10207c50c785cSJohn Marino     error (_("Cannot create a ranged breakpoint with multiple locations."));
10208c50c785cSJohn Marino 
10209a45ae5f8SJohn Marino   sal_end = lsal_end->sals.sals[0];
10210a45ae5f8SJohn Marino   addr_string_end = savestring (arg_start, arg - arg_start);
10211a45ae5f8SJohn Marino   make_cleanup (xfree, addr_string_end);
10212c50c785cSJohn Marino 
10213c50c785cSJohn Marino   end = find_breakpoint_range_end (sal_end);
10214c50c785cSJohn Marino   if (sal_start.pc > end)
10215a45ae5f8SJohn Marino     error (_("Invalid address range, end precedes start."));
10216c50c785cSJohn Marino 
10217c50c785cSJohn Marino   length = end - sal_start.pc + 1;
10218c50c785cSJohn Marino   if (length < 0)
10219c50c785cSJohn Marino     /* Length overflowed.  */
10220c50c785cSJohn Marino     error (_("Address range too large."));
10221c50c785cSJohn Marino   else if (length == 1)
10222c50c785cSJohn Marino     {
10223c50c785cSJohn Marino       /* This range is simple enough to be handled by
10224c50c785cSJohn Marino 	 the `hbreak' command.  */
10225c50c785cSJohn Marino       hbreak_command (addr_string_start, 1);
10226c50c785cSJohn Marino 
10227c50c785cSJohn Marino       do_cleanups (cleanup_bkpt);
10228c50c785cSJohn Marino 
10229c50c785cSJohn Marino       return;
10230c50c785cSJohn Marino     }
10231c50c785cSJohn Marino 
10232c50c785cSJohn Marino   /* Now set up the breakpoint.  */
10233c50c785cSJohn Marino   b = set_raw_breakpoint (get_current_arch (), sal_start,
10234a45ae5f8SJohn Marino 			  bp_hardware_breakpoint, &ranged_breakpoint_ops);
10235c50c785cSJohn Marino   set_breakpoint_count (breakpoint_count + 1);
10236c50c785cSJohn Marino   b->number = breakpoint_count;
10237c50c785cSJohn Marino   b->disposition = disp_donttouch;
10238a45ae5f8SJohn Marino   b->addr_string = xstrdup (addr_string_start);
10239a45ae5f8SJohn Marino   b->addr_string_range_end = xstrdup (addr_string_end);
10240c50c785cSJohn Marino   b->loc->length = length;
10241c50c785cSJohn Marino 
10242a45ae5f8SJohn Marino   do_cleanups (cleanup_bkpt);
10243c50c785cSJohn Marino 
10244c50c785cSJohn Marino   mention (b);
10245a45ae5f8SJohn Marino   observer_notify_breakpoint_created (b);
10246c50c785cSJohn Marino   update_global_location_list (1);
10247c50c785cSJohn Marino }
10248c50c785cSJohn Marino 
10249c50c785cSJohn Marino /*  Return non-zero if EXP is verified as constant.  Returned zero
10250c50c785cSJohn Marino     means EXP is variable.  Also the constant detection may fail for
10251c50c785cSJohn Marino     some constant expressions and in such case still falsely return
10252c50c785cSJohn Marino     zero.  */
10253*ef5ccd6cSJohn Marino 
10254cf7f2e2dSJohn Marino static int
watchpoint_exp_is_const(const struct expression * exp)10255cf7f2e2dSJohn Marino watchpoint_exp_is_const (const struct expression *exp)
10256cf7f2e2dSJohn Marino {
10257cf7f2e2dSJohn Marino   int i = exp->nelts;
10258cf7f2e2dSJohn Marino 
10259cf7f2e2dSJohn Marino   while (i > 0)
10260cf7f2e2dSJohn Marino     {
10261cf7f2e2dSJohn Marino       int oplenp, argsp;
10262cf7f2e2dSJohn Marino 
10263cf7f2e2dSJohn Marino       /* We are only interested in the descriptor of each element.  */
10264cf7f2e2dSJohn Marino       operator_length (exp, i, &oplenp, &argsp);
10265cf7f2e2dSJohn Marino       i -= oplenp;
10266cf7f2e2dSJohn Marino 
10267cf7f2e2dSJohn Marino       switch (exp->elts[i].opcode)
10268cf7f2e2dSJohn Marino 	{
10269cf7f2e2dSJohn Marino 	case BINOP_ADD:
10270cf7f2e2dSJohn Marino 	case BINOP_SUB:
10271cf7f2e2dSJohn Marino 	case BINOP_MUL:
10272cf7f2e2dSJohn Marino 	case BINOP_DIV:
10273cf7f2e2dSJohn Marino 	case BINOP_REM:
10274cf7f2e2dSJohn Marino 	case BINOP_MOD:
10275cf7f2e2dSJohn Marino 	case BINOP_LSH:
10276cf7f2e2dSJohn Marino 	case BINOP_RSH:
10277cf7f2e2dSJohn Marino 	case BINOP_LOGICAL_AND:
10278cf7f2e2dSJohn Marino 	case BINOP_LOGICAL_OR:
10279cf7f2e2dSJohn Marino 	case BINOP_BITWISE_AND:
10280cf7f2e2dSJohn Marino 	case BINOP_BITWISE_IOR:
10281cf7f2e2dSJohn Marino 	case BINOP_BITWISE_XOR:
10282cf7f2e2dSJohn Marino 	case BINOP_EQUAL:
10283cf7f2e2dSJohn Marino 	case BINOP_NOTEQUAL:
10284cf7f2e2dSJohn Marino 	case BINOP_LESS:
10285cf7f2e2dSJohn Marino 	case BINOP_GTR:
10286cf7f2e2dSJohn Marino 	case BINOP_LEQ:
10287cf7f2e2dSJohn Marino 	case BINOP_GEQ:
10288cf7f2e2dSJohn Marino 	case BINOP_REPEAT:
10289cf7f2e2dSJohn Marino 	case BINOP_COMMA:
10290cf7f2e2dSJohn Marino 	case BINOP_EXP:
10291cf7f2e2dSJohn Marino 	case BINOP_MIN:
10292cf7f2e2dSJohn Marino 	case BINOP_MAX:
10293cf7f2e2dSJohn Marino 	case BINOP_INTDIV:
10294cf7f2e2dSJohn Marino 	case BINOP_CONCAT:
10295cf7f2e2dSJohn Marino 	case BINOP_IN:
10296cf7f2e2dSJohn Marino 	case BINOP_RANGE:
10297cf7f2e2dSJohn Marino 	case TERNOP_COND:
10298cf7f2e2dSJohn Marino 	case TERNOP_SLICE:
10299cf7f2e2dSJohn Marino 
10300cf7f2e2dSJohn Marino 	case OP_LONG:
10301cf7f2e2dSJohn Marino 	case OP_DOUBLE:
10302cf7f2e2dSJohn Marino 	case OP_DECFLOAT:
10303cf7f2e2dSJohn Marino 	case OP_LAST:
10304cf7f2e2dSJohn Marino 	case OP_COMPLEX:
10305cf7f2e2dSJohn Marino 	case OP_STRING:
10306cf7f2e2dSJohn Marino 	case OP_ARRAY:
10307cf7f2e2dSJohn Marino 	case OP_TYPE:
10308*ef5ccd6cSJohn Marino 	case OP_TYPEOF:
10309*ef5ccd6cSJohn Marino 	case OP_DECLTYPE:
10310cf7f2e2dSJohn Marino 	case OP_NAME:
10311cf7f2e2dSJohn Marino 	case OP_OBJC_NSSTRING:
10312cf7f2e2dSJohn Marino 
10313cf7f2e2dSJohn Marino 	case UNOP_NEG:
10314cf7f2e2dSJohn Marino 	case UNOP_LOGICAL_NOT:
10315cf7f2e2dSJohn Marino 	case UNOP_COMPLEMENT:
10316cf7f2e2dSJohn Marino 	case UNOP_ADDR:
10317cf7f2e2dSJohn Marino 	case UNOP_HIGH:
10318*ef5ccd6cSJohn Marino 	case UNOP_CAST:
10319*ef5ccd6cSJohn Marino 
10320*ef5ccd6cSJohn Marino 	case UNOP_CAST_TYPE:
10321*ef5ccd6cSJohn Marino 	case UNOP_REINTERPRET_CAST:
10322*ef5ccd6cSJohn Marino 	case UNOP_DYNAMIC_CAST:
10323c50c785cSJohn Marino 	  /* Unary, binary and ternary operators: We have to check
10324c50c785cSJohn Marino 	     their operands.  If they are constant, then so is the
10325c50c785cSJohn Marino 	     result of that operation.  For instance, if A and B are
10326c50c785cSJohn Marino 	     determined to be constants, then so is "A + B".
10327cf7f2e2dSJohn Marino 
10328c50c785cSJohn Marino 	     UNOP_IND is one exception to the rule above, because the
10329c50c785cSJohn Marino 	     value of *ADDR is not necessarily a constant, even when
10330c50c785cSJohn Marino 	     ADDR is.  */
10331cf7f2e2dSJohn Marino 	  break;
10332cf7f2e2dSJohn Marino 
10333cf7f2e2dSJohn Marino 	case OP_VAR_VALUE:
10334cf7f2e2dSJohn Marino 	  /* Check whether the associated symbol is a constant.
10335c50c785cSJohn Marino 
10336cf7f2e2dSJohn Marino 	     We use SYMBOL_CLASS rather than TYPE_CONST because it's
10337c50c785cSJohn Marino 	     possible that a buggy compiler could mark a variable as
10338c50c785cSJohn Marino 	     constant even when it is not, and TYPE_CONST would return
10339c50c785cSJohn Marino 	     true in this case, while SYMBOL_CLASS wouldn't.
10340c50c785cSJohn Marino 
10341c50c785cSJohn Marino 	     We also have to check for function symbols because they
10342c50c785cSJohn Marino 	     are always constant.  */
10343cf7f2e2dSJohn Marino 	  {
10344cf7f2e2dSJohn Marino 	    struct symbol *s = exp->elts[i + 2].symbol;
10345cf7f2e2dSJohn Marino 
10346cf7f2e2dSJohn Marino 	    if (SYMBOL_CLASS (s) != LOC_BLOCK
10347cf7f2e2dSJohn Marino 		&& SYMBOL_CLASS (s) != LOC_CONST
10348cf7f2e2dSJohn Marino 		&& SYMBOL_CLASS (s) != LOC_CONST_BYTES)
10349cf7f2e2dSJohn Marino 	      return 0;
10350cf7f2e2dSJohn Marino 	    break;
10351cf7f2e2dSJohn Marino 	  }
10352cf7f2e2dSJohn Marino 
10353cf7f2e2dSJohn Marino 	/* The default action is to return 0 because we are using
10354cf7f2e2dSJohn Marino 	   the optimistic approach here: If we don't know something,
10355cf7f2e2dSJohn Marino 	   then it is not a constant.  */
10356cf7f2e2dSJohn Marino 	default:
10357cf7f2e2dSJohn Marino 	  return 0;
10358cf7f2e2dSJohn Marino 	}
10359cf7f2e2dSJohn Marino     }
10360cf7f2e2dSJohn Marino 
10361cf7f2e2dSJohn Marino   return 1;
10362cf7f2e2dSJohn Marino }
10363cf7f2e2dSJohn Marino 
10364a45ae5f8SJohn Marino /* Implement the "dtor" breakpoint_ops method for watchpoints.  */
10365a45ae5f8SJohn Marino 
10366a45ae5f8SJohn Marino static void
dtor_watchpoint(struct breakpoint * self)10367a45ae5f8SJohn Marino dtor_watchpoint (struct breakpoint *self)
10368a45ae5f8SJohn Marino {
10369a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) self;
10370a45ae5f8SJohn Marino 
10371a45ae5f8SJohn Marino   xfree (w->cond_exp);
10372a45ae5f8SJohn Marino   xfree (w->exp);
10373a45ae5f8SJohn Marino   xfree (w->exp_string);
10374a45ae5f8SJohn Marino   xfree (w->exp_string_reparse);
10375a45ae5f8SJohn Marino   value_free (w->val);
10376a45ae5f8SJohn Marino 
10377a45ae5f8SJohn Marino   base_breakpoint_ops.dtor (self);
10378a45ae5f8SJohn Marino }
10379a45ae5f8SJohn Marino 
10380a45ae5f8SJohn Marino /* Implement the "re_set" breakpoint_ops method for watchpoints.  */
10381a45ae5f8SJohn Marino 
10382a45ae5f8SJohn Marino static void
re_set_watchpoint(struct breakpoint * b)10383a45ae5f8SJohn Marino re_set_watchpoint (struct breakpoint *b)
10384a45ae5f8SJohn Marino {
10385a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) b;
10386a45ae5f8SJohn Marino 
10387a45ae5f8SJohn Marino   /* Watchpoint can be either on expression using entirely global
10388a45ae5f8SJohn Marino      variables, or it can be on local variables.
10389a45ae5f8SJohn Marino 
10390a45ae5f8SJohn Marino      Watchpoints of the first kind are never auto-deleted, and even
10391a45ae5f8SJohn Marino      persist across program restarts.  Since they can use variables
10392a45ae5f8SJohn Marino      from shared libraries, we need to reparse expression as libraries
10393a45ae5f8SJohn Marino      are loaded and unloaded.
10394a45ae5f8SJohn Marino 
10395a45ae5f8SJohn Marino      Watchpoints on local variables can also change meaning as result
10396a45ae5f8SJohn Marino      of solib event.  For example, if a watchpoint uses both a local
10397a45ae5f8SJohn Marino      and a global variables in expression, it's a local watchpoint,
10398a45ae5f8SJohn Marino      but unloading of a shared library will make the expression
10399a45ae5f8SJohn Marino      invalid.  This is not a very common use case, but we still
10400a45ae5f8SJohn Marino      re-evaluate expression, to avoid surprises to the user.
10401a45ae5f8SJohn Marino 
10402a45ae5f8SJohn Marino      Note that for local watchpoints, we re-evaluate it only if
10403a45ae5f8SJohn Marino      watchpoints frame id is still valid.  If it's not, it means the
10404a45ae5f8SJohn Marino      watchpoint is out of scope and will be deleted soon.  In fact,
10405a45ae5f8SJohn Marino      I'm not sure we'll ever be called in this case.
10406a45ae5f8SJohn Marino 
10407a45ae5f8SJohn Marino      If a local watchpoint's frame id is still valid, then
10408a45ae5f8SJohn Marino      w->exp_valid_block is likewise valid, and we can safely use it.
10409a45ae5f8SJohn Marino 
10410a45ae5f8SJohn Marino      Don't do anything about disabled watchpoints, since they will be
10411a45ae5f8SJohn Marino      reevaluated again when enabled.  */
10412a45ae5f8SJohn Marino   update_watchpoint (w, 1 /* reparse */);
10413a45ae5f8SJohn Marino }
10414a45ae5f8SJohn Marino 
10415c50c785cSJohn Marino /* Implement the "insert" breakpoint_ops method for hardware watchpoints.  */
10416c50c785cSJohn Marino 
10417c50c785cSJohn Marino static int
insert_watchpoint(struct bp_location * bl)10418c50c785cSJohn Marino insert_watchpoint (struct bp_location *bl)
10419c50c785cSJohn Marino {
10420a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) bl->owner;
10421a45ae5f8SJohn Marino   int length = w->exact ? 1 : bl->length;
10422c50c785cSJohn Marino 
10423c50c785cSJohn Marino   return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
10424a45ae5f8SJohn Marino 				   w->cond_exp);
10425c50c785cSJohn Marino }
10426c50c785cSJohn Marino 
10427c50c785cSJohn Marino /* Implement the "remove" breakpoint_ops method for hardware watchpoints.  */
10428c50c785cSJohn Marino 
10429c50c785cSJohn Marino static int
remove_watchpoint(struct bp_location * bl)10430c50c785cSJohn Marino remove_watchpoint (struct bp_location *bl)
10431c50c785cSJohn Marino {
10432a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) bl->owner;
10433a45ae5f8SJohn Marino   int length = w->exact ? 1 : bl->length;
10434c50c785cSJohn Marino 
10435c50c785cSJohn Marino   return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
10436a45ae5f8SJohn Marino 				   w->cond_exp);
10437a45ae5f8SJohn Marino }
10438a45ae5f8SJohn Marino 
10439a45ae5f8SJohn Marino static int
breakpoint_hit_watchpoint(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)10440a45ae5f8SJohn Marino breakpoint_hit_watchpoint (const struct bp_location *bl,
10441*ef5ccd6cSJohn Marino 			   struct address_space *aspace, CORE_ADDR bp_addr,
10442*ef5ccd6cSJohn Marino 			   const struct target_waitstatus *ws)
10443a45ae5f8SJohn Marino {
10444a45ae5f8SJohn Marino   struct breakpoint *b = bl->owner;
10445a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) b;
10446a45ae5f8SJohn Marino 
10447a45ae5f8SJohn Marino   /* Continuable hardware watchpoints are treated as non-existent if the
10448a45ae5f8SJohn Marino      reason we stopped wasn't a hardware watchpoint (we didn't stop on
10449a45ae5f8SJohn Marino      some data address).  Otherwise gdb won't stop on a break instruction
10450a45ae5f8SJohn Marino      in the code (not from a breakpoint) when a hardware watchpoint has
10451a45ae5f8SJohn Marino      been defined.  Also skip watchpoints which we know did not trigger
10452a45ae5f8SJohn Marino      (did not match the data address).  */
10453a45ae5f8SJohn Marino   if (is_hardware_watchpoint (b)
10454a45ae5f8SJohn Marino       && w->watchpoint_triggered == watch_triggered_no)
10455a45ae5f8SJohn Marino     return 0;
10456a45ae5f8SJohn Marino 
10457a45ae5f8SJohn Marino   return 1;
10458a45ae5f8SJohn Marino }
10459a45ae5f8SJohn Marino 
10460a45ae5f8SJohn Marino static void
check_status_watchpoint(bpstat bs)10461a45ae5f8SJohn Marino check_status_watchpoint (bpstat bs)
10462a45ae5f8SJohn Marino {
10463a45ae5f8SJohn Marino   gdb_assert (is_watchpoint (bs->breakpoint_at));
10464a45ae5f8SJohn Marino 
10465a45ae5f8SJohn Marino   bpstat_check_watchpoint (bs);
10466c50c785cSJohn Marino }
10467c50c785cSJohn Marino 
10468c50c785cSJohn Marino /* Implement the "resources_needed" breakpoint_ops method for
10469c50c785cSJohn Marino    hardware watchpoints.  */
10470c50c785cSJohn Marino 
10471c50c785cSJohn Marino static int
resources_needed_watchpoint(const struct bp_location * bl)10472c50c785cSJohn Marino resources_needed_watchpoint (const struct bp_location *bl)
10473c50c785cSJohn Marino {
10474a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) bl->owner;
10475a45ae5f8SJohn Marino   int length = w->exact? 1 : bl->length;
10476c50c785cSJohn Marino 
10477c50c785cSJohn Marino   return target_region_ok_for_hw_watchpoint (bl->address, length);
10478c50c785cSJohn Marino }
10479c50c785cSJohn Marino 
10480a45ae5f8SJohn Marino /* Implement the "works_in_software_mode" breakpoint_ops method for
10481a45ae5f8SJohn Marino    hardware watchpoints.  */
10482a45ae5f8SJohn Marino 
10483a45ae5f8SJohn Marino static int
works_in_software_mode_watchpoint(const struct breakpoint * b)10484a45ae5f8SJohn Marino works_in_software_mode_watchpoint (const struct breakpoint *b)
10485a45ae5f8SJohn Marino {
10486a45ae5f8SJohn Marino   /* Read and access watchpoints only work with hardware support.  */
10487a45ae5f8SJohn Marino   return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
10488a45ae5f8SJohn Marino }
10489a45ae5f8SJohn Marino 
10490a45ae5f8SJohn Marino static enum print_stop_action
print_it_watchpoint(bpstat bs)10491a45ae5f8SJohn Marino print_it_watchpoint (bpstat bs)
10492a45ae5f8SJohn Marino {
10493a45ae5f8SJohn Marino   struct cleanup *old_chain;
10494a45ae5f8SJohn Marino   struct breakpoint *b;
10495a45ae5f8SJohn Marino   const struct bp_location *bl;
10496*ef5ccd6cSJohn Marino   struct ui_file *stb;
10497a45ae5f8SJohn Marino   enum print_stop_action result;
10498a45ae5f8SJohn Marino   struct watchpoint *w;
10499a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
10500a45ae5f8SJohn Marino 
10501a45ae5f8SJohn Marino   gdb_assert (bs->bp_location_at != NULL);
10502a45ae5f8SJohn Marino 
10503a45ae5f8SJohn Marino   bl = bs->bp_location_at;
10504a45ae5f8SJohn Marino   b = bs->breakpoint_at;
10505a45ae5f8SJohn Marino   w = (struct watchpoint *) b;
10506a45ae5f8SJohn Marino 
10507*ef5ccd6cSJohn Marino   stb = mem_fileopen ();
10508*ef5ccd6cSJohn Marino   old_chain = make_cleanup_ui_file_delete (stb);
10509a45ae5f8SJohn Marino 
10510a45ae5f8SJohn Marino   switch (b->type)
10511a45ae5f8SJohn Marino     {
10512a45ae5f8SJohn Marino     case bp_watchpoint:
10513a45ae5f8SJohn Marino     case bp_hardware_watchpoint:
10514a45ae5f8SJohn Marino       annotate_watchpoint (b->number);
10515a45ae5f8SJohn Marino       if (ui_out_is_mi_like_p (uiout))
10516a45ae5f8SJohn Marino 	ui_out_field_string
10517a45ae5f8SJohn Marino 	  (uiout, "reason",
10518a45ae5f8SJohn Marino 	   async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10519a45ae5f8SJohn Marino       mention (b);
10520a45ae5f8SJohn Marino       make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10521a45ae5f8SJohn Marino       ui_out_text (uiout, "\nOld value = ");
10522*ef5ccd6cSJohn Marino       watchpoint_value_print (bs->old_val, stb);
10523a45ae5f8SJohn Marino       ui_out_field_stream (uiout, "old", stb);
10524a45ae5f8SJohn Marino       ui_out_text (uiout, "\nNew value = ");
10525*ef5ccd6cSJohn Marino       watchpoint_value_print (w->val, stb);
10526a45ae5f8SJohn Marino       ui_out_field_stream (uiout, "new", stb);
10527a45ae5f8SJohn Marino       ui_out_text (uiout, "\n");
10528a45ae5f8SJohn Marino       /* More than one watchpoint may have been triggered.  */
10529a45ae5f8SJohn Marino       result = PRINT_UNKNOWN;
10530a45ae5f8SJohn Marino       break;
10531a45ae5f8SJohn Marino 
10532a45ae5f8SJohn Marino     case bp_read_watchpoint:
10533a45ae5f8SJohn Marino       if (ui_out_is_mi_like_p (uiout))
10534a45ae5f8SJohn Marino 	ui_out_field_string
10535a45ae5f8SJohn Marino 	  (uiout, "reason",
10536a45ae5f8SJohn Marino 	   async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10537a45ae5f8SJohn Marino       mention (b);
10538a45ae5f8SJohn Marino       make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10539a45ae5f8SJohn Marino       ui_out_text (uiout, "\nValue = ");
10540*ef5ccd6cSJohn Marino       watchpoint_value_print (w->val, stb);
10541a45ae5f8SJohn Marino       ui_out_field_stream (uiout, "value", stb);
10542a45ae5f8SJohn Marino       ui_out_text (uiout, "\n");
10543a45ae5f8SJohn Marino       result = PRINT_UNKNOWN;
10544a45ae5f8SJohn Marino       break;
10545a45ae5f8SJohn Marino 
10546a45ae5f8SJohn Marino     case bp_access_watchpoint:
10547a45ae5f8SJohn Marino       if (bs->old_val != NULL)
10548a45ae5f8SJohn Marino 	{
10549a45ae5f8SJohn Marino 	  annotate_watchpoint (b->number);
10550a45ae5f8SJohn Marino 	  if (ui_out_is_mi_like_p (uiout))
10551a45ae5f8SJohn Marino 	    ui_out_field_string
10552a45ae5f8SJohn Marino 	      (uiout, "reason",
10553a45ae5f8SJohn Marino 	       async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10554a45ae5f8SJohn Marino 	  mention (b);
10555a45ae5f8SJohn Marino 	  make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10556a45ae5f8SJohn Marino 	  ui_out_text (uiout, "\nOld value = ");
10557*ef5ccd6cSJohn Marino 	  watchpoint_value_print (bs->old_val, stb);
10558a45ae5f8SJohn Marino 	  ui_out_field_stream (uiout, "old", stb);
10559a45ae5f8SJohn Marino 	  ui_out_text (uiout, "\nNew value = ");
10560a45ae5f8SJohn Marino 	}
10561a45ae5f8SJohn Marino       else
10562a45ae5f8SJohn Marino 	{
10563a45ae5f8SJohn Marino 	  mention (b);
10564a45ae5f8SJohn Marino 	  if (ui_out_is_mi_like_p (uiout))
10565a45ae5f8SJohn Marino 	    ui_out_field_string
10566a45ae5f8SJohn Marino 	      (uiout, "reason",
10567a45ae5f8SJohn Marino 	       async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10568a45ae5f8SJohn Marino 	  make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10569a45ae5f8SJohn Marino 	  ui_out_text (uiout, "\nValue = ");
10570a45ae5f8SJohn Marino 	}
10571*ef5ccd6cSJohn Marino       watchpoint_value_print (w->val, stb);
10572a45ae5f8SJohn Marino       ui_out_field_stream (uiout, "new", stb);
10573a45ae5f8SJohn Marino       ui_out_text (uiout, "\n");
10574a45ae5f8SJohn Marino       result = PRINT_UNKNOWN;
10575a45ae5f8SJohn Marino       break;
10576a45ae5f8SJohn Marino     default:
10577a45ae5f8SJohn Marino       result = PRINT_UNKNOWN;
10578a45ae5f8SJohn Marino     }
10579a45ae5f8SJohn Marino 
10580a45ae5f8SJohn Marino   do_cleanups (old_chain);
10581a45ae5f8SJohn Marino   return result;
10582a45ae5f8SJohn Marino }
10583a45ae5f8SJohn Marino 
10584a45ae5f8SJohn Marino /* Implement the "print_mention" breakpoint_ops method for hardware
10585a45ae5f8SJohn Marino    watchpoints.  */
10586a45ae5f8SJohn Marino 
10587a45ae5f8SJohn Marino static void
print_mention_watchpoint(struct breakpoint * b)10588a45ae5f8SJohn Marino print_mention_watchpoint (struct breakpoint *b)
10589a45ae5f8SJohn Marino {
10590a45ae5f8SJohn Marino   struct cleanup *ui_out_chain;
10591a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) b;
10592a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
10593a45ae5f8SJohn Marino 
10594a45ae5f8SJohn Marino   switch (b->type)
10595a45ae5f8SJohn Marino     {
10596a45ae5f8SJohn Marino     case bp_watchpoint:
10597a45ae5f8SJohn Marino       ui_out_text (uiout, "Watchpoint ");
10598a45ae5f8SJohn Marino       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10599a45ae5f8SJohn Marino       break;
10600a45ae5f8SJohn Marino     case bp_hardware_watchpoint:
10601a45ae5f8SJohn Marino       ui_out_text (uiout, "Hardware watchpoint ");
10602a45ae5f8SJohn Marino       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10603a45ae5f8SJohn Marino       break;
10604a45ae5f8SJohn Marino     case bp_read_watchpoint:
10605a45ae5f8SJohn Marino       ui_out_text (uiout, "Hardware read watchpoint ");
10606a45ae5f8SJohn Marino       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10607a45ae5f8SJohn Marino       break;
10608a45ae5f8SJohn Marino     case bp_access_watchpoint:
10609a45ae5f8SJohn Marino       ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10610a45ae5f8SJohn Marino       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10611a45ae5f8SJohn Marino       break;
10612a45ae5f8SJohn Marino     default:
10613a45ae5f8SJohn Marino       internal_error (__FILE__, __LINE__,
10614a45ae5f8SJohn Marino 		      _("Invalid hardware watchpoint type."));
10615a45ae5f8SJohn Marino     }
10616a45ae5f8SJohn Marino 
10617a45ae5f8SJohn Marino   ui_out_field_int (uiout, "number", b->number);
10618a45ae5f8SJohn Marino   ui_out_text (uiout, ": ");
10619a45ae5f8SJohn Marino   ui_out_field_string (uiout, "exp", w->exp_string);
10620a45ae5f8SJohn Marino   do_cleanups (ui_out_chain);
10621a45ae5f8SJohn Marino }
10622a45ae5f8SJohn Marino 
10623a45ae5f8SJohn Marino /* Implement the "print_recreate" breakpoint_ops method for
10624a45ae5f8SJohn Marino    watchpoints.  */
10625a45ae5f8SJohn Marino 
10626a45ae5f8SJohn Marino static void
print_recreate_watchpoint(struct breakpoint * b,struct ui_file * fp)10627a45ae5f8SJohn Marino print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10628a45ae5f8SJohn Marino {
10629a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) b;
10630a45ae5f8SJohn Marino 
10631a45ae5f8SJohn Marino   switch (b->type)
10632a45ae5f8SJohn Marino     {
10633a45ae5f8SJohn Marino     case bp_watchpoint:
10634a45ae5f8SJohn Marino     case bp_hardware_watchpoint:
10635a45ae5f8SJohn Marino       fprintf_unfiltered (fp, "watch");
10636a45ae5f8SJohn Marino       break;
10637a45ae5f8SJohn Marino     case bp_read_watchpoint:
10638a45ae5f8SJohn Marino       fprintf_unfiltered (fp, "rwatch");
10639a45ae5f8SJohn Marino       break;
10640a45ae5f8SJohn Marino     case bp_access_watchpoint:
10641a45ae5f8SJohn Marino       fprintf_unfiltered (fp, "awatch");
10642a45ae5f8SJohn Marino       break;
10643a45ae5f8SJohn Marino     default:
10644a45ae5f8SJohn Marino       internal_error (__FILE__, __LINE__,
10645a45ae5f8SJohn Marino 		      _("Invalid watchpoint type."));
10646a45ae5f8SJohn Marino     }
10647a45ae5f8SJohn Marino 
10648a45ae5f8SJohn Marino   fprintf_unfiltered (fp, " %s", w->exp_string);
10649a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
10650a45ae5f8SJohn Marino }
10651a45ae5f8SJohn Marino 
10652*ef5ccd6cSJohn Marino /* Implement the "explains_signal" breakpoint_ops method for
10653*ef5ccd6cSJohn Marino    watchpoints.  */
10654*ef5ccd6cSJohn Marino 
10655*ef5ccd6cSJohn Marino static enum bpstat_signal_value
explains_signal_watchpoint(struct breakpoint * b,enum gdb_signal sig)10656*ef5ccd6cSJohn Marino explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig)
10657*ef5ccd6cSJohn Marino {
10658*ef5ccd6cSJohn Marino   /* A software watchpoint cannot cause a signal other than
10659*ef5ccd6cSJohn Marino      GDB_SIGNAL_TRAP.  */
10660*ef5ccd6cSJohn Marino   if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP)
10661*ef5ccd6cSJohn Marino     return BPSTAT_SIGNAL_NO;
10662*ef5ccd6cSJohn Marino 
10663*ef5ccd6cSJohn Marino   return BPSTAT_SIGNAL_HIDE;
10664*ef5ccd6cSJohn Marino }
10665*ef5ccd6cSJohn Marino 
10666c50c785cSJohn Marino /* The breakpoint_ops structure to be used in hardware watchpoints.  */
10667c50c785cSJohn Marino 
10668a45ae5f8SJohn Marino static struct breakpoint_ops watchpoint_breakpoint_ops;
10669a45ae5f8SJohn Marino 
10670a45ae5f8SJohn Marino /* Implement the "insert" breakpoint_ops method for
10671a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10672a45ae5f8SJohn Marino 
10673a45ae5f8SJohn Marino static int
insert_masked_watchpoint(struct bp_location * bl)10674a45ae5f8SJohn Marino insert_masked_watchpoint (struct bp_location *bl)
10675c50c785cSJohn Marino {
10676a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) bl->owner;
10677a45ae5f8SJohn Marino 
10678a45ae5f8SJohn Marino   return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
10679a45ae5f8SJohn Marino 					bl->watchpoint_type);
10680a45ae5f8SJohn Marino }
10681a45ae5f8SJohn Marino 
10682a45ae5f8SJohn Marino /* Implement the "remove" breakpoint_ops method for
10683a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10684a45ae5f8SJohn Marino 
10685a45ae5f8SJohn Marino static int
remove_masked_watchpoint(struct bp_location * bl)10686a45ae5f8SJohn Marino remove_masked_watchpoint (struct bp_location *bl)
10687a45ae5f8SJohn Marino {
10688a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) bl->owner;
10689a45ae5f8SJohn Marino 
10690a45ae5f8SJohn Marino   return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
10691a45ae5f8SJohn Marino 				        bl->watchpoint_type);
10692a45ae5f8SJohn Marino }
10693a45ae5f8SJohn Marino 
10694a45ae5f8SJohn Marino /* Implement the "resources_needed" breakpoint_ops method for
10695a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10696a45ae5f8SJohn Marino 
10697a45ae5f8SJohn Marino static int
resources_needed_masked_watchpoint(const struct bp_location * bl)10698a45ae5f8SJohn Marino resources_needed_masked_watchpoint (const struct bp_location *bl)
10699a45ae5f8SJohn Marino {
10700a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) bl->owner;
10701a45ae5f8SJohn Marino 
10702a45ae5f8SJohn Marino   return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
10703a45ae5f8SJohn Marino }
10704a45ae5f8SJohn Marino 
10705a45ae5f8SJohn Marino /* Implement the "works_in_software_mode" breakpoint_ops method for
10706a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10707a45ae5f8SJohn Marino 
10708a45ae5f8SJohn Marino static int
works_in_software_mode_masked_watchpoint(const struct breakpoint * b)10709a45ae5f8SJohn Marino works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10710a45ae5f8SJohn Marino {
10711a45ae5f8SJohn Marino   return 0;
10712a45ae5f8SJohn Marino }
10713a45ae5f8SJohn Marino 
10714a45ae5f8SJohn Marino /* Implement the "print_it" breakpoint_ops method for
10715a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10716a45ae5f8SJohn Marino 
10717a45ae5f8SJohn Marino static enum print_stop_action
print_it_masked_watchpoint(bpstat bs)10718a45ae5f8SJohn Marino print_it_masked_watchpoint (bpstat bs)
10719a45ae5f8SJohn Marino {
10720a45ae5f8SJohn Marino   struct breakpoint *b = bs->breakpoint_at;
10721a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
10722a45ae5f8SJohn Marino 
10723a45ae5f8SJohn Marino   /* Masked watchpoints have only one location.  */
10724a45ae5f8SJohn Marino   gdb_assert (b->loc && b->loc->next == NULL);
10725a45ae5f8SJohn Marino 
10726a45ae5f8SJohn Marino   switch (b->type)
10727a45ae5f8SJohn Marino     {
10728a45ae5f8SJohn Marino     case bp_hardware_watchpoint:
10729a45ae5f8SJohn Marino       annotate_watchpoint (b->number);
10730a45ae5f8SJohn Marino       if (ui_out_is_mi_like_p (uiout))
10731a45ae5f8SJohn Marino 	ui_out_field_string
10732a45ae5f8SJohn Marino 	  (uiout, "reason",
10733a45ae5f8SJohn Marino 	   async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10734a45ae5f8SJohn Marino       break;
10735a45ae5f8SJohn Marino 
10736a45ae5f8SJohn Marino     case bp_read_watchpoint:
10737a45ae5f8SJohn Marino       if (ui_out_is_mi_like_p (uiout))
10738a45ae5f8SJohn Marino 	ui_out_field_string
10739a45ae5f8SJohn Marino 	  (uiout, "reason",
10740a45ae5f8SJohn Marino 	   async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10741a45ae5f8SJohn Marino       break;
10742a45ae5f8SJohn Marino 
10743a45ae5f8SJohn Marino     case bp_access_watchpoint:
10744a45ae5f8SJohn Marino       if (ui_out_is_mi_like_p (uiout))
10745a45ae5f8SJohn Marino 	ui_out_field_string
10746a45ae5f8SJohn Marino 	  (uiout, "reason",
10747a45ae5f8SJohn Marino 	   async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10748a45ae5f8SJohn Marino       break;
10749a45ae5f8SJohn Marino     default:
10750a45ae5f8SJohn Marino       internal_error (__FILE__, __LINE__,
10751a45ae5f8SJohn Marino 		      _("Invalid hardware watchpoint type."));
10752a45ae5f8SJohn Marino     }
10753a45ae5f8SJohn Marino 
10754a45ae5f8SJohn Marino   mention (b);
10755a45ae5f8SJohn Marino   ui_out_text (uiout, _("\n\
10756a45ae5f8SJohn Marino Check the underlying instruction at PC for the memory\n\
10757a45ae5f8SJohn Marino address and value which triggered this watchpoint.\n"));
10758a45ae5f8SJohn Marino   ui_out_text (uiout, "\n");
10759a45ae5f8SJohn Marino 
10760a45ae5f8SJohn Marino   /* More than one watchpoint may have been triggered.  */
10761a45ae5f8SJohn Marino   return PRINT_UNKNOWN;
10762a45ae5f8SJohn Marino }
10763a45ae5f8SJohn Marino 
10764a45ae5f8SJohn Marino /* Implement the "print_one_detail" breakpoint_ops method for
10765a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10766a45ae5f8SJohn Marino 
10767a45ae5f8SJohn Marino static void
print_one_detail_masked_watchpoint(const struct breakpoint * b,struct ui_out * uiout)10768a45ae5f8SJohn Marino print_one_detail_masked_watchpoint (const struct breakpoint *b,
10769a45ae5f8SJohn Marino 				    struct ui_out *uiout)
10770a45ae5f8SJohn Marino {
10771a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) b;
10772a45ae5f8SJohn Marino 
10773a45ae5f8SJohn Marino   /* Masked watchpoints have only one location.  */
10774a45ae5f8SJohn Marino   gdb_assert (b->loc && b->loc->next == NULL);
10775a45ae5f8SJohn Marino 
10776a45ae5f8SJohn Marino   ui_out_text (uiout, "\tmask ");
10777a45ae5f8SJohn Marino   ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
10778a45ae5f8SJohn Marino   ui_out_text (uiout, "\n");
10779a45ae5f8SJohn Marino }
10780a45ae5f8SJohn Marino 
10781a45ae5f8SJohn Marino /* Implement the "print_mention" breakpoint_ops method for
10782a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10783a45ae5f8SJohn Marino 
10784a45ae5f8SJohn Marino static void
print_mention_masked_watchpoint(struct breakpoint * b)10785a45ae5f8SJohn Marino print_mention_masked_watchpoint (struct breakpoint *b)
10786a45ae5f8SJohn Marino {
10787a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) b;
10788a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
10789a45ae5f8SJohn Marino   struct cleanup *ui_out_chain;
10790a45ae5f8SJohn Marino 
10791a45ae5f8SJohn Marino   switch (b->type)
10792a45ae5f8SJohn Marino     {
10793a45ae5f8SJohn Marino     case bp_hardware_watchpoint:
10794a45ae5f8SJohn Marino       ui_out_text (uiout, "Masked hardware watchpoint ");
10795a45ae5f8SJohn Marino       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10796a45ae5f8SJohn Marino       break;
10797a45ae5f8SJohn Marino     case bp_read_watchpoint:
10798a45ae5f8SJohn Marino       ui_out_text (uiout, "Masked hardware read watchpoint ");
10799a45ae5f8SJohn Marino       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10800a45ae5f8SJohn Marino       break;
10801a45ae5f8SJohn Marino     case bp_access_watchpoint:
10802a45ae5f8SJohn Marino       ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10803a45ae5f8SJohn Marino       ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10804a45ae5f8SJohn Marino       break;
10805a45ae5f8SJohn Marino     default:
10806a45ae5f8SJohn Marino       internal_error (__FILE__, __LINE__,
10807a45ae5f8SJohn Marino 		      _("Invalid hardware watchpoint type."));
10808a45ae5f8SJohn Marino     }
10809a45ae5f8SJohn Marino 
10810a45ae5f8SJohn Marino   ui_out_field_int (uiout, "number", b->number);
10811a45ae5f8SJohn Marino   ui_out_text (uiout, ": ");
10812a45ae5f8SJohn Marino   ui_out_field_string (uiout, "exp", w->exp_string);
10813a45ae5f8SJohn Marino   do_cleanups (ui_out_chain);
10814a45ae5f8SJohn Marino }
10815a45ae5f8SJohn Marino 
10816a45ae5f8SJohn Marino /* Implement the "print_recreate" breakpoint_ops method for
10817a45ae5f8SJohn Marino    masked hardware watchpoints.  */
10818a45ae5f8SJohn Marino 
10819a45ae5f8SJohn Marino static void
print_recreate_masked_watchpoint(struct breakpoint * b,struct ui_file * fp)10820a45ae5f8SJohn Marino print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10821a45ae5f8SJohn Marino {
10822a45ae5f8SJohn Marino   struct watchpoint *w = (struct watchpoint *) b;
10823a45ae5f8SJohn Marino   char tmp[40];
10824a45ae5f8SJohn Marino 
10825a45ae5f8SJohn Marino   switch (b->type)
10826a45ae5f8SJohn Marino     {
10827a45ae5f8SJohn Marino     case bp_hardware_watchpoint:
10828a45ae5f8SJohn Marino       fprintf_unfiltered (fp, "watch");
10829a45ae5f8SJohn Marino       break;
10830a45ae5f8SJohn Marino     case bp_read_watchpoint:
10831a45ae5f8SJohn Marino       fprintf_unfiltered (fp, "rwatch");
10832a45ae5f8SJohn Marino       break;
10833a45ae5f8SJohn Marino     case bp_access_watchpoint:
10834a45ae5f8SJohn Marino       fprintf_unfiltered (fp, "awatch");
10835a45ae5f8SJohn Marino       break;
10836a45ae5f8SJohn Marino     default:
10837a45ae5f8SJohn Marino       internal_error (__FILE__, __LINE__,
10838a45ae5f8SJohn Marino 		      _("Invalid hardware watchpoint type."));
10839a45ae5f8SJohn Marino     }
10840a45ae5f8SJohn Marino 
10841a45ae5f8SJohn Marino   sprintf_vma (tmp, w->hw_wp_mask);
10842a45ae5f8SJohn Marino   fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
10843a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
10844a45ae5f8SJohn Marino }
10845a45ae5f8SJohn Marino 
10846a45ae5f8SJohn Marino /* The breakpoint_ops structure to be used in masked hardware watchpoints.  */
10847a45ae5f8SJohn Marino 
10848a45ae5f8SJohn Marino static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
10849a45ae5f8SJohn Marino 
10850a45ae5f8SJohn Marino /* Tell whether the given watchpoint is a masked hardware watchpoint.  */
10851a45ae5f8SJohn Marino 
10852a45ae5f8SJohn Marino static int
is_masked_watchpoint(const struct breakpoint * b)10853a45ae5f8SJohn Marino is_masked_watchpoint (const struct breakpoint *b)
10854a45ae5f8SJohn Marino {
10855a45ae5f8SJohn Marino   return b->ops == &masked_watchpoint_breakpoint_ops;
10856a45ae5f8SJohn Marino }
10857c50c785cSJohn Marino 
108585796c8dcSSimon Schubert /* accessflag:  hw_write:  watch write,
108595796c8dcSSimon Schubert                 hw_read:   watch read,
108605796c8dcSSimon Schubert 		hw_access: watch access (read or write) */
108615796c8dcSSimon Schubert static void
watch_command_1(const char * arg,int accessflag,int from_tty,int just_location,int internal)10862*ef5ccd6cSJohn Marino watch_command_1 (const char *arg, int accessflag, int from_tty,
10863c50c785cSJohn Marino 		 int just_location, int internal)
108645796c8dcSSimon Schubert {
10865a45ae5f8SJohn Marino   volatile struct gdb_exception e;
108665796c8dcSSimon Schubert   struct breakpoint *b, *scope_breakpoint = NULL;
108675796c8dcSSimon Schubert   struct expression *exp;
10868*ef5ccd6cSJohn Marino   const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
10869c50c785cSJohn Marino   struct value *val, *mark, *result;
108705796c8dcSSimon Schubert   struct frame_info *frame;
10871*ef5ccd6cSJohn Marino   const char *exp_start = NULL;
10872*ef5ccd6cSJohn Marino   const char *exp_end = NULL;
10873*ef5ccd6cSJohn Marino   const char *tok, *end_tok;
10874a45ae5f8SJohn Marino   int toklen = -1;
10875*ef5ccd6cSJohn Marino   const char *cond_start = NULL;
10876*ef5ccd6cSJohn Marino   const char *cond_end = NULL;
108775796c8dcSSimon Schubert   enum bptype bp_type;
108785796c8dcSSimon Schubert   int thread = -1;
10879cf7f2e2dSJohn Marino   int pc = 0;
10880a45ae5f8SJohn Marino   /* Flag to indicate whether we are going to use masks for
10881a45ae5f8SJohn Marino      the hardware watchpoint.  */
10882a45ae5f8SJohn Marino   int use_mask = 0;
10883a45ae5f8SJohn Marino   CORE_ADDR mask = 0;
10884a45ae5f8SJohn Marino   struct watchpoint *w;
10885*ef5ccd6cSJohn Marino   char *expression;
10886*ef5ccd6cSJohn Marino   struct cleanup *back_to;
108875796c8dcSSimon Schubert 
108885796c8dcSSimon Schubert   /* Make sure that we actually have parameters to parse.  */
108895796c8dcSSimon Schubert   if (arg != NULL && arg[0] != '\0')
108905796c8dcSSimon Schubert     {
10891*ef5ccd6cSJohn Marino       const char *value_start;
10892*ef5ccd6cSJohn Marino 
10893*ef5ccd6cSJohn Marino       exp_end = arg + strlen (arg);
108945796c8dcSSimon Schubert 
10895a45ae5f8SJohn Marino       /* Look for "parameter value" pairs at the end
10896a45ae5f8SJohn Marino 	 of the arguments string.  */
10897*ef5ccd6cSJohn Marino       for (tok = exp_end - 1; tok > arg; tok--)
10898a45ae5f8SJohn Marino 	{
10899a45ae5f8SJohn Marino 	  /* Skip whitespace at the end of the argument list.  */
109005796c8dcSSimon Schubert 	  while (tok > arg && (*tok == ' ' || *tok == '\t'))
109015796c8dcSSimon Schubert 	    tok--;
10902a45ae5f8SJohn Marino 
10903a45ae5f8SJohn Marino 	  /* Find the beginning of the last token.
10904a45ae5f8SJohn Marino 	     This is the value of the parameter.  */
109055796c8dcSSimon Schubert 	  while (tok > arg && (*tok != ' ' && *tok != '\t'))
109065796c8dcSSimon Schubert 	    tok--;
10907a45ae5f8SJohn Marino 	  value_start = tok + 1;
109085796c8dcSSimon Schubert 
10909a45ae5f8SJohn Marino 	  /* Skip whitespace.  */
109105796c8dcSSimon Schubert 	  while (tok > arg && (*tok == ' ' || *tok == '\t'))
109115796c8dcSSimon Schubert 	    tok--;
109125796c8dcSSimon Schubert 
109135796c8dcSSimon Schubert 	  end_tok = tok;
109145796c8dcSSimon Schubert 
10915a45ae5f8SJohn Marino 	  /* Find the beginning of the second to last token.
10916a45ae5f8SJohn Marino 	     This is the parameter itself.  */
109175796c8dcSSimon Schubert 	  while (tok > arg && (*tok != ' ' && *tok != '\t'))
109185796c8dcSSimon Schubert 	    tok--;
109195796c8dcSSimon Schubert 	  tok++;
10920a45ae5f8SJohn Marino 	  toklen = end_tok - tok + 1;
109215796c8dcSSimon Schubert 
10922a45ae5f8SJohn Marino 	  if (toklen == 6 && !strncmp (tok, "thread", 6))
109235796c8dcSSimon Schubert 	    {
109245796c8dcSSimon Schubert 	      /* At this point we've found a "thread" token, which means
109255796c8dcSSimon Schubert 		 the user is trying to set a watchpoint that triggers
109265796c8dcSSimon Schubert 		 only in a specific thread.  */
109275796c8dcSSimon Schubert 	      char *endp;
109285796c8dcSSimon Schubert 
10929a45ae5f8SJohn Marino 	      if (thread != -1)
10930a45ae5f8SJohn Marino 		error(_("You can specify only one thread."));
10931a45ae5f8SJohn Marino 
109325796c8dcSSimon Schubert 	      /* Extract the thread ID from the next token.  */
10933a45ae5f8SJohn Marino 	      thread = strtol (value_start, &endp, 0);
109345796c8dcSSimon Schubert 
109355796c8dcSSimon Schubert 	      /* Check if the user provided a valid numeric value for the
109365796c8dcSSimon Schubert 		 thread ID.  */
109375796c8dcSSimon Schubert 	      if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10938a45ae5f8SJohn Marino 		error (_("Invalid thread ID specification %s."), value_start);
109395796c8dcSSimon Schubert 
109405796c8dcSSimon Schubert 	      /* Check if the thread actually exists.  */
109415796c8dcSSimon Schubert 	      if (!valid_thread_id (thread))
10942*ef5ccd6cSJohn Marino 		invalid_thread_id_error (thread);
10943a45ae5f8SJohn Marino 	    }
10944a45ae5f8SJohn Marino 	  else if (toklen == 4 && !strncmp (tok, "mask", 4))
10945a45ae5f8SJohn Marino 	    {
10946a45ae5f8SJohn Marino 	      /* We've found a "mask" token, which means the user wants to
10947a45ae5f8SJohn Marino 		 create a hardware watchpoint that is going to have the mask
10948a45ae5f8SJohn Marino 		 facility.  */
10949a45ae5f8SJohn Marino 	      struct value *mask_value, *mark;
109505796c8dcSSimon Schubert 
10951a45ae5f8SJohn Marino 	      if (use_mask)
10952a45ae5f8SJohn Marino 		error(_("You can specify only one mask."));
10953a45ae5f8SJohn Marino 
10954a45ae5f8SJohn Marino 	      use_mask = just_location = 1;
10955a45ae5f8SJohn Marino 
10956a45ae5f8SJohn Marino 	      mark = value_mark ();
10957a45ae5f8SJohn Marino 	      mask_value = parse_to_comma_and_eval (&value_start);
10958a45ae5f8SJohn Marino 	      mask = value_as_address (mask_value);
10959a45ae5f8SJohn Marino 	      value_free_to_mark (mark);
10960a45ae5f8SJohn Marino 	    }
10961a45ae5f8SJohn Marino 	  else
10962a45ae5f8SJohn Marino 	    /* We didn't recognize what we found.  We should stop here.  */
10963a45ae5f8SJohn Marino 	    break;
10964a45ae5f8SJohn Marino 
10965a45ae5f8SJohn Marino 	  /* Truncate the string and get rid of the "parameter value" pair before
10966a45ae5f8SJohn Marino 	     the arguments string is parsed by the parse_exp_1 function.  */
10967*ef5ccd6cSJohn Marino 	  exp_end = tok;
109685796c8dcSSimon Schubert 	}
109695796c8dcSSimon Schubert     }
10970*ef5ccd6cSJohn Marino   else
10971*ef5ccd6cSJohn Marino     exp_end = arg;
109725796c8dcSSimon Schubert 
10973*ef5ccd6cSJohn Marino   /* Parse the rest of the arguments.  From here on out, everything
10974*ef5ccd6cSJohn Marino      is in terms of a newly allocated string instead of the original
10975*ef5ccd6cSJohn Marino      ARG.  */
109765796c8dcSSimon Schubert   innermost_block = NULL;
10977*ef5ccd6cSJohn Marino   expression = savestring (arg, exp_end - arg);
10978*ef5ccd6cSJohn Marino   back_to = make_cleanup (xfree, expression);
10979*ef5ccd6cSJohn Marino   exp_start = arg = expression;
10980*ef5ccd6cSJohn Marino   exp = parse_exp_1 (&arg, 0, 0, 0);
109815796c8dcSSimon Schubert   exp_end = arg;
109825796c8dcSSimon Schubert   /* Remove trailing whitespace from the expression before saving it.
109835796c8dcSSimon Schubert      This makes the eventual display of the expression string a bit
109845796c8dcSSimon Schubert      prettier.  */
109855796c8dcSSimon Schubert   while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
109865796c8dcSSimon Schubert     --exp_end;
109875796c8dcSSimon Schubert 
10988cf7f2e2dSJohn Marino   /* Checking if the expression is not constant.  */
10989cf7f2e2dSJohn Marino   if (watchpoint_exp_is_const (exp))
10990cf7f2e2dSJohn Marino     {
10991cf7f2e2dSJohn Marino       int len;
10992cf7f2e2dSJohn Marino 
10993cf7f2e2dSJohn Marino       len = exp_end - exp_start;
10994cf7f2e2dSJohn Marino       while (len > 0 && isspace (exp_start[len - 1]))
10995cf7f2e2dSJohn Marino 	len--;
10996cf7f2e2dSJohn Marino       error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10997cf7f2e2dSJohn Marino     }
10998cf7f2e2dSJohn Marino 
109995796c8dcSSimon Schubert   exp_valid_block = innermost_block;
110005796c8dcSSimon Schubert   mark = value_mark ();
11001c50c785cSJohn Marino   fetch_subexp_value (exp, &pc, &val, &result, NULL);
11002c50c785cSJohn Marino 
11003c50c785cSJohn Marino   if (just_location)
11004c50c785cSJohn Marino     {
11005a45ae5f8SJohn Marino       int ret;
11006a45ae5f8SJohn Marino 
11007c50c785cSJohn Marino       exp_valid_block = NULL;
11008c50c785cSJohn Marino       val = value_addr (result);
11009c50c785cSJohn Marino       release_value (val);
11010c50c785cSJohn Marino       value_free_to_mark (mark);
11011a45ae5f8SJohn Marino 
11012a45ae5f8SJohn Marino       if (use_mask)
11013a45ae5f8SJohn Marino 	{
11014a45ae5f8SJohn Marino 	  ret = target_masked_watch_num_registers (value_as_address (val),
11015a45ae5f8SJohn Marino 						   mask);
11016a45ae5f8SJohn Marino 	  if (ret == -1)
11017a45ae5f8SJohn Marino 	    error (_("This target does not support masked watchpoints."));
11018a45ae5f8SJohn Marino 	  else if (ret == -2)
11019a45ae5f8SJohn Marino 	    error (_("Invalid mask or memory region."));
11020a45ae5f8SJohn Marino 	}
11021c50c785cSJohn Marino     }
11022c50c785cSJohn Marino   else if (val != NULL)
110235796c8dcSSimon Schubert     release_value (val);
110245796c8dcSSimon Schubert 
11025*ef5ccd6cSJohn Marino   tok = skip_spaces_const (arg);
11026*ef5ccd6cSJohn Marino   end_tok = skip_to_space_const (tok);
110275796c8dcSSimon Schubert 
110285796c8dcSSimon Schubert   toklen = end_tok - tok;
110295796c8dcSSimon Schubert   if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
110305796c8dcSSimon Schubert     {
11031cf7f2e2dSJohn Marino       struct expression *cond;
11032cf7f2e2dSJohn Marino 
11033cf7f2e2dSJohn Marino       innermost_block = NULL;
110345796c8dcSSimon Schubert       tok = cond_start = end_tok + 1;
11035*ef5ccd6cSJohn Marino       cond = parse_exp_1 (&tok, 0, 0, 0);
11036cf7f2e2dSJohn Marino 
11037cf7f2e2dSJohn Marino       /* The watchpoint expression may not be local, but the condition
11038cf7f2e2dSJohn Marino 	 may still be.  E.g.: `watch global if local > 0'.  */
11039cf7f2e2dSJohn Marino       cond_exp_valid_block = innermost_block;
11040cf7f2e2dSJohn Marino 
11041cf7f2e2dSJohn Marino       xfree (cond);
110425796c8dcSSimon Schubert       cond_end = tok;
110435796c8dcSSimon Schubert     }
110445796c8dcSSimon Schubert   if (*tok)
110455796c8dcSSimon Schubert     error (_("Junk at end of command."));
110465796c8dcSSimon Schubert 
110475796c8dcSSimon Schubert   if (accessflag == hw_read)
110485796c8dcSSimon Schubert     bp_type = bp_read_watchpoint;
110495796c8dcSSimon Schubert   else if (accessflag == hw_access)
110505796c8dcSSimon Schubert     bp_type = bp_access_watchpoint;
110515796c8dcSSimon Schubert   else
110525796c8dcSSimon Schubert     bp_type = bp_hardware_watchpoint;
110535796c8dcSSimon Schubert 
110545796c8dcSSimon Schubert   frame = block_innermost_frame (exp_valid_block);
110555796c8dcSSimon Schubert 
110565796c8dcSSimon Schubert   /* If the expression is "local", then set up a "watchpoint scope"
110575796c8dcSSimon Schubert      breakpoint at the point where we've left the scope of the watchpoint
110585796c8dcSSimon Schubert      expression.  Create the scope breakpoint before the watchpoint, so
110595796c8dcSSimon Schubert      that we will encounter it first in bpstat_stop_status.  */
11060cf7f2e2dSJohn Marino   if (exp_valid_block && frame)
110615796c8dcSSimon Schubert     {
110625796c8dcSSimon Schubert       if (frame_id_p (frame_unwind_caller_id (frame)))
110635796c8dcSSimon Schubert 	{
110645796c8dcSSimon Schubert  	  scope_breakpoint
110655796c8dcSSimon Schubert 	    = create_internal_breakpoint (frame_unwind_caller_arch (frame),
110665796c8dcSSimon Schubert 					  frame_unwind_caller_pc (frame),
11067a45ae5f8SJohn Marino 					  bp_watchpoint_scope,
11068a45ae5f8SJohn Marino 					  &momentary_breakpoint_ops);
110695796c8dcSSimon Schubert 
110705796c8dcSSimon Schubert 	  scope_breakpoint->enable_state = bp_enabled;
110715796c8dcSSimon Schubert 
110725796c8dcSSimon Schubert 	  /* Automatically delete the breakpoint when it hits.  */
110735796c8dcSSimon Schubert 	  scope_breakpoint->disposition = disp_del;
110745796c8dcSSimon Schubert 
110755796c8dcSSimon Schubert 	  /* Only break in the proper frame (help with recursion).  */
110765796c8dcSSimon Schubert 	  scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
110775796c8dcSSimon Schubert 
110785796c8dcSSimon Schubert 	  /* Set the address at which we will stop.  */
110795796c8dcSSimon Schubert 	  scope_breakpoint->loc->gdbarch
110805796c8dcSSimon Schubert 	    = frame_unwind_caller_arch (frame);
110815796c8dcSSimon Schubert 	  scope_breakpoint->loc->requested_address
110825796c8dcSSimon Schubert 	    = frame_unwind_caller_pc (frame);
110835796c8dcSSimon Schubert 	  scope_breakpoint->loc->address
110845796c8dcSSimon Schubert 	    = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
110855796c8dcSSimon Schubert 					 scope_breakpoint->loc->requested_address,
110865796c8dcSSimon Schubert 					 scope_breakpoint->type);
110875796c8dcSSimon Schubert 	}
110885796c8dcSSimon Schubert     }
110895796c8dcSSimon Schubert 
110905796c8dcSSimon Schubert   /* Now set up the breakpoint.  */
11091a45ae5f8SJohn Marino 
11092a45ae5f8SJohn Marino   w = XCNEW (struct watchpoint);
11093a45ae5f8SJohn Marino   b = &w->base;
11094a45ae5f8SJohn Marino   if (use_mask)
11095a45ae5f8SJohn Marino     init_raw_breakpoint_without_location (b, NULL, bp_type,
11096a45ae5f8SJohn Marino 					  &masked_watchpoint_breakpoint_ops);
11097a45ae5f8SJohn Marino   else
11098a45ae5f8SJohn Marino     init_raw_breakpoint_without_location (b, NULL, bp_type,
11099a45ae5f8SJohn Marino 					  &watchpoint_breakpoint_ops);
111005796c8dcSSimon Schubert   b->thread = thread;
111015796c8dcSSimon Schubert   b->disposition = disp_donttouch;
11102a45ae5f8SJohn Marino   b->pspace = current_program_space;
11103a45ae5f8SJohn Marino   w->exp = exp;
11104a45ae5f8SJohn Marino   w->exp_valid_block = exp_valid_block;
11105a45ae5f8SJohn Marino   w->cond_exp_valid_block = cond_exp_valid_block;
11106c50c785cSJohn Marino   if (just_location)
11107c50c785cSJohn Marino     {
11108c50c785cSJohn Marino       struct type *t = value_type (val);
11109c50c785cSJohn Marino       CORE_ADDR addr = value_as_address (val);
11110c50c785cSJohn Marino       char *name;
11111c50c785cSJohn Marino 
11112c50c785cSJohn Marino       t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
11113c50c785cSJohn Marino       name = type_to_string (t);
11114c50c785cSJohn Marino 
11115a45ae5f8SJohn Marino       w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
11116c50c785cSJohn Marino 					  core_addr_to_string (addr));
11117c50c785cSJohn Marino       xfree (name);
11118c50c785cSJohn Marino 
11119a45ae5f8SJohn Marino       w->exp_string = xstrprintf ("-location %.*s",
11120c50c785cSJohn Marino 				  (int) (exp_end - exp_start), exp_start);
11121c50c785cSJohn Marino 
11122c50c785cSJohn Marino       /* The above expression is in C.  */
11123c50c785cSJohn Marino       b->language = language_c;
11124c50c785cSJohn Marino     }
11125c50c785cSJohn Marino   else
11126a45ae5f8SJohn Marino     w->exp_string = savestring (exp_start, exp_end - exp_start);
11127c50c785cSJohn Marino 
11128a45ae5f8SJohn Marino   if (use_mask)
11129a45ae5f8SJohn Marino     {
11130a45ae5f8SJohn Marino       w->hw_wp_mask = mask;
11131a45ae5f8SJohn Marino     }
11132a45ae5f8SJohn Marino   else
11133a45ae5f8SJohn Marino     {
11134a45ae5f8SJohn Marino       w->val = val;
11135a45ae5f8SJohn Marino       w->val_valid = 1;
11136a45ae5f8SJohn Marino     }
11137c50c785cSJohn Marino 
111385796c8dcSSimon Schubert   if (cond_start)
111395796c8dcSSimon Schubert     b->cond_string = savestring (cond_start, cond_end - cond_start);
111405796c8dcSSimon Schubert   else
111415796c8dcSSimon Schubert     b->cond_string = 0;
111425796c8dcSSimon Schubert 
111435796c8dcSSimon Schubert   if (frame)
11144cf7f2e2dSJohn Marino     {
11145a45ae5f8SJohn Marino       w->watchpoint_frame = get_frame_id (frame);
11146a45ae5f8SJohn Marino       w->watchpoint_thread = inferior_ptid;
11147cf7f2e2dSJohn Marino     }
111485796c8dcSSimon Schubert   else
11149cf7f2e2dSJohn Marino     {
11150a45ae5f8SJohn Marino       w->watchpoint_frame = null_frame_id;
11151a45ae5f8SJohn Marino       w->watchpoint_thread = null_ptid;
11152cf7f2e2dSJohn Marino     }
111535796c8dcSSimon Schubert 
111545796c8dcSSimon Schubert   if (scope_breakpoint != NULL)
111555796c8dcSSimon Schubert     {
111565796c8dcSSimon Schubert       /* The scope breakpoint is related to the watchpoint.  We will
111575796c8dcSSimon Schubert 	 need to act on them together.  */
111585796c8dcSSimon Schubert       b->related_breakpoint = scope_breakpoint;
111595796c8dcSSimon Schubert       scope_breakpoint->related_breakpoint = b;
111605796c8dcSSimon Schubert     }
111615796c8dcSSimon Schubert 
11162c50c785cSJohn Marino   if (!just_location)
111635796c8dcSSimon Schubert     value_free_to_mark (mark);
11164cf7f2e2dSJohn Marino 
11165a45ae5f8SJohn Marino   TRY_CATCH (e, RETURN_MASK_ALL)
11166a45ae5f8SJohn Marino     {
11167cf7f2e2dSJohn Marino       /* Finally update the new watchpoint.  This creates the locations
11168cf7f2e2dSJohn Marino 	 that should be inserted.  */
11169a45ae5f8SJohn Marino       update_watchpoint (w, 1);
11170a45ae5f8SJohn Marino     }
11171a45ae5f8SJohn Marino   if (e.reason < 0)
11172a45ae5f8SJohn Marino     {
11173a45ae5f8SJohn Marino       delete_breakpoint (b);
11174a45ae5f8SJohn Marino       throw_exception (e);
11175a45ae5f8SJohn Marino     }
11176a45ae5f8SJohn Marino 
11177a45ae5f8SJohn Marino   install_breakpoint (internal, b, 1);
11178*ef5ccd6cSJohn Marino   do_cleanups (back_to);
111795796c8dcSSimon Schubert }
111805796c8dcSSimon Schubert 
11181c50c785cSJohn Marino /* Return count of debug registers needed to watch the given expression.
11182c50c785cSJohn Marino    If the watchpoint cannot be handled in hardware return zero.  */
111835796c8dcSSimon Schubert 
111845796c8dcSSimon Schubert static int
can_use_hardware_watchpoint(struct value * v)11185a45ae5f8SJohn Marino can_use_hardware_watchpoint (struct value *v)
111865796c8dcSSimon Schubert {
111875796c8dcSSimon Schubert   int found_memory_cnt = 0;
111885796c8dcSSimon Schubert   struct value *head = v;
111895796c8dcSSimon Schubert 
111905796c8dcSSimon Schubert   /* Did the user specifically forbid us to use hardware watchpoints? */
111915796c8dcSSimon Schubert   if (!can_use_hw_watchpoints)
111925796c8dcSSimon Schubert     return 0;
111935796c8dcSSimon Schubert 
111945796c8dcSSimon Schubert   /* Make sure that the value of the expression depends only upon
111955796c8dcSSimon Schubert      memory contents, and values computed from them within GDB.  If we
111965796c8dcSSimon Schubert      find any register references or function calls, we can't use a
111975796c8dcSSimon Schubert      hardware watchpoint.
111985796c8dcSSimon Schubert 
111995796c8dcSSimon Schubert      The idea here is that evaluating an expression generates a series
112005796c8dcSSimon Schubert      of values, one holding the value of every subexpression.  (The
112015796c8dcSSimon Schubert      expression a*b+c has five subexpressions: a, b, a*b, c, and
112025796c8dcSSimon Schubert      a*b+c.)  GDB's values hold almost enough information to establish
112035796c8dcSSimon Schubert      the criteria given above --- they identify memory lvalues,
112045796c8dcSSimon Schubert      register lvalues, computed values, etcetera.  So we can evaluate
112055796c8dcSSimon Schubert      the expression, and then scan the chain of values that leaves
112065796c8dcSSimon Schubert      behind to decide whether we can detect any possible change to the
112075796c8dcSSimon Schubert      expression's final value using only hardware watchpoints.
112085796c8dcSSimon Schubert 
112095796c8dcSSimon Schubert      However, I don't think that the values returned by inferior
112105796c8dcSSimon Schubert      function calls are special in any way.  So this function may not
112115796c8dcSSimon Schubert      notice that an expression involving an inferior function call
112125796c8dcSSimon Schubert      can't be watched with hardware watchpoints.  FIXME.  */
112135796c8dcSSimon Schubert   for (; v; v = value_next (v))
112145796c8dcSSimon Schubert     {
112155796c8dcSSimon Schubert       if (VALUE_LVAL (v) == lval_memory)
112165796c8dcSSimon Schubert 	{
11217c50c785cSJohn Marino 	  if (v != head && value_lazy (v))
11218c50c785cSJohn Marino 	    /* A lazy memory lvalue in the chain is one that GDB never
11219c50c785cSJohn Marino 	       needed to fetch; we either just used its address (e.g.,
11220c50c785cSJohn Marino 	       `a' in `a.b') or we never needed it at all (e.g., `a'
11221c50c785cSJohn Marino 	       in `a,b').  This doesn't apply to HEAD; if that is
11222c50c785cSJohn Marino 	       lazy then it was not readable, but watch it anyway.  */
112235796c8dcSSimon Schubert 	    ;
112245796c8dcSSimon Schubert 	  else
112255796c8dcSSimon Schubert 	    {
112265796c8dcSSimon Schubert 	      /* Ahh, memory we actually used!  Check if we can cover
112275796c8dcSSimon Schubert                  it with hardware watchpoints.  */
112285796c8dcSSimon Schubert 	      struct type *vtype = check_typedef (value_type (v));
112295796c8dcSSimon Schubert 
112305796c8dcSSimon Schubert 	      /* We only watch structs and arrays if user asked for it
112315796c8dcSSimon Schubert 		 explicitly, never if they just happen to appear in a
112325796c8dcSSimon Schubert 		 middle of some value chain.  */
112335796c8dcSSimon Schubert 	      if (v == head
112345796c8dcSSimon Schubert 		  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
112355796c8dcSSimon Schubert 		      && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
112365796c8dcSSimon Schubert 		{
112375796c8dcSSimon Schubert 		  CORE_ADDR vaddr = value_address (v);
11238c50c785cSJohn Marino 		  int len;
11239c50c785cSJohn Marino 		  int num_regs;
112405796c8dcSSimon Schubert 
11241a45ae5f8SJohn Marino 		  len = (target_exact_watchpoints
11242c50c785cSJohn Marino 			 && is_scalar_type_recursive (vtype))?
11243c50c785cSJohn Marino 		    1 : TYPE_LENGTH (value_type (v));
11244c50c785cSJohn Marino 
11245c50c785cSJohn Marino 		  num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
11246c50c785cSJohn Marino 		  if (!num_regs)
112475796c8dcSSimon Schubert 		    return 0;
112485796c8dcSSimon Schubert 		  else
11249c50c785cSJohn Marino 		    found_memory_cnt += num_regs;
112505796c8dcSSimon Schubert 		}
112515796c8dcSSimon Schubert 	    }
112525796c8dcSSimon Schubert 	}
112535796c8dcSSimon Schubert       else if (VALUE_LVAL (v) != not_lval
112545796c8dcSSimon Schubert 	       && deprecated_value_modifiable (v) == 0)
11255cf7f2e2dSJohn Marino 	return 0;	/* These are values from the history (e.g., $1).  */
112565796c8dcSSimon Schubert       else if (VALUE_LVAL (v) == lval_register)
11257cf7f2e2dSJohn Marino 	return 0;	/* Cannot watch a register with a HW watchpoint.  */
112585796c8dcSSimon Schubert     }
112595796c8dcSSimon Schubert 
112605796c8dcSSimon Schubert   /* The expression itself looks suitable for using a hardware
112615796c8dcSSimon Schubert      watchpoint, but give the target machine a chance to reject it.  */
112625796c8dcSSimon Schubert   return found_memory_cnt;
112635796c8dcSSimon Schubert }
112645796c8dcSSimon Schubert 
112655796c8dcSSimon Schubert void
watch_command_wrapper(char * arg,int from_tty,int internal)11266c50c785cSJohn Marino watch_command_wrapper (char *arg, int from_tty, int internal)
112675796c8dcSSimon Schubert {
11268c50c785cSJohn Marino   watch_command_1 (arg, hw_write, from_tty, 0, internal);
11269c50c785cSJohn Marino }
11270c50c785cSJohn Marino 
11271c50c785cSJohn Marino /* A helper function that looks for the "-location" argument and then
11272c50c785cSJohn Marino    calls watch_command_1.  */
11273c50c785cSJohn Marino 
11274c50c785cSJohn Marino static void
watch_maybe_just_location(char * arg,int accessflag,int from_tty)11275c50c785cSJohn Marino watch_maybe_just_location (char *arg, int accessflag, int from_tty)
11276c50c785cSJohn Marino {
11277c50c785cSJohn Marino   int just_location = 0;
11278c50c785cSJohn Marino 
11279c50c785cSJohn Marino   if (arg
11280c50c785cSJohn Marino       && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
11281c50c785cSJohn Marino 	  || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
11282c50c785cSJohn Marino     {
11283c50c785cSJohn Marino       arg = skip_spaces (arg);
11284c50c785cSJohn Marino       just_location = 1;
11285c50c785cSJohn Marino     }
11286c50c785cSJohn Marino 
11287c50c785cSJohn Marino   watch_command_1 (arg, accessflag, from_tty, just_location, 0);
112885796c8dcSSimon Schubert }
112895796c8dcSSimon Schubert 
112905796c8dcSSimon Schubert static void
watch_command(char * arg,int from_tty)112915796c8dcSSimon Schubert watch_command (char *arg, int from_tty)
112925796c8dcSSimon Schubert {
11293c50c785cSJohn Marino   watch_maybe_just_location (arg, hw_write, from_tty);
112945796c8dcSSimon Schubert }
112955796c8dcSSimon Schubert 
112965796c8dcSSimon Schubert void
rwatch_command_wrapper(char * arg,int from_tty,int internal)11297c50c785cSJohn Marino rwatch_command_wrapper (char *arg, int from_tty, int internal)
112985796c8dcSSimon Schubert {
11299c50c785cSJohn Marino   watch_command_1 (arg, hw_read, from_tty, 0, internal);
113005796c8dcSSimon Schubert }
113015796c8dcSSimon Schubert 
113025796c8dcSSimon Schubert static void
rwatch_command(char * arg,int from_tty)113035796c8dcSSimon Schubert rwatch_command (char *arg, int from_tty)
113045796c8dcSSimon Schubert {
11305c50c785cSJohn Marino   watch_maybe_just_location (arg, hw_read, from_tty);
113065796c8dcSSimon Schubert }
113075796c8dcSSimon Schubert 
113085796c8dcSSimon Schubert void
awatch_command_wrapper(char * arg,int from_tty,int internal)11309c50c785cSJohn Marino awatch_command_wrapper (char *arg, int from_tty, int internal)
113105796c8dcSSimon Schubert {
11311c50c785cSJohn Marino   watch_command_1 (arg, hw_access, from_tty, 0, internal);
113125796c8dcSSimon Schubert }
113135796c8dcSSimon Schubert 
113145796c8dcSSimon Schubert static void
awatch_command(char * arg,int from_tty)113155796c8dcSSimon Schubert awatch_command (char *arg, int from_tty)
113165796c8dcSSimon Schubert {
11317c50c785cSJohn Marino   watch_maybe_just_location (arg, hw_access, from_tty);
113185796c8dcSSimon Schubert }
113195796c8dcSSimon Schubert 
113205796c8dcSSimon Schubert 
113215796c8dcSSimon Schubert /* Helper routines for the until_command routine in infcmd.c.  Here
113225796c8dcSSimon Schubert    because it uses the mechanisms of breakpoints.  */
113235796c8dcSSimon Schubert 
113245796c8dcSSimon Schubert struct until_break_command_continuation_args
113255796c8dcSSimon Schubert {
113265796c8dcSSimon Schubert   struct breakpoint *breakpoint;
113275796c8dcSSimon Schubert   struct breakpoint *breakpoint2;
11328c50c785cSJohn Marino   int thread_num;
113295796c8dcSSimon Schubert };
113305796c8dcSSimon Schubert 
113315796c8dcSSimon Schubert /* This function is called by fetch_inferior_event via the
113325796c8dcSSimon Schubert    cmd_continuation pointer, to complete the until command.  It takes
113335796c8dcSSimon Schubert    care of cleaning up the temporary breakpoints set up by the until
113345796c8dcSSimon Schubert    command.  */
113355796c8dcSSimon Schubert static void
until_break_command_continuation(void * arg,int err)11336a45ae5f8SJohn Marino until_break_command_continuation (void *arg, int err)
113375796c8dcSSimon Schubert {
113385796c8dcSSimon Schubert   struct until_break_command_continuation_args *a = arg;
113395796c8dcSSimon Schubert 
113405796c8dcSSimon Schubert   delete_breakpoint (a->breakpoint);
113415796c8dcSSimon Schubert   if (a->breakpoint2)
113425796c8dcSSimon Schubert     delete_breakpoint (a->breakpoint2);
11343c50c785cSJohn Marino   delete_longjmp_breakpoint (a->thread_num);
113445796c8dcSSimon Schubert }
113455796c8dcSSimon Schubert 
113465796c8dcSSimon Schubert void
until_break_command(char * arg,int from_tty,int anywhere)113475796c8dcSSimon Schubert until_break_command (char *arg, int from_tty, int anywhere)
113485796c8dcSSimon Schubert {
113495796c8dcSSimon Schubert   struct symtabs_and_lines sals;
113505796c8dcSSimon Schubert   struct symtab_and_line sal;
11351*ef5ccd6cSJohn Marino   struct frame_info *frame;
11352*ef5ccd6cSJohn Marino   struct gdbarch *frame_gdbarch;
11353*ef5ccd6cSJohn Marino   struct frame_id stack_frame_id;
11354*ef5ccd6cSJohn Marino   struct frame_id caller_frame_id;
113555796c8dcSSimon Schubert   struct breakpoint *breakpoint;
113565796c8dcSSimon Schubert   struct breakpoint *breakpoint2 = NULL;
113575796c8dcSSimon Schubert   struct cleanup *old_chain;
11358c50c785cSJohn Marino   int thread;
11359c50c785cSJohn Marino   struct thread_info *tp;
113605796c8dcSSimon Schubert 
113615796c8dcSSimon Schubert   clear_proceed_status ();
113625796c8dcSSimon Schubert 
113635796c8dcSSimon Schubert   /* Set a breakpoint where the user wants it and at return from
11364c50c785cSJohn Marino      this function.  */
113655796c8dcSSimon Schubert 
11366a45ae5f8SJohn Marino   if (last_displayed_sal_is_valid ())
11367a45ae5f8SJohn Marino     sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11368a45ae5f8SJohn Marino 			  get_last_displayed_symtab (),
11369a45ae5f8SJohn Marino 			  get_last_displayed_line ());
113705796c8dcSSimon Schubert   else
11371a45ae5f8SJohn Marino     sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
11372a45ae5f8SJohn Marino 			  (struct symtab *) NULL, 0);
113735796c8dcSSimon Schubert 
113745796c8dcSSimon Schubert   if (sals.nelts != 1)
113755796c8dcSSimon Schubert     error (_("Couldn't get information on specified line."));
113765796c8dcSSimon Schubert 
113775796c8dcSSimon Schubert   sal = sals.sals[0];
11378c50c785cSJohn Marino   xfree (sals.sals);	/* malloc'd, so freed.  */
113795796c8dcSSimon Schubert 
113805796c8dcSSimon Schubert   if (*arg)
113815796c8dcSSimon Schubert     error (_("Junk at end of arguments."));
113825796c8dcSSimon Schubert 
113835796c8dcSSimon Schubert   resolve_sal_pc (&sal);
113845796c8dcSSimon Schubert 
11385c50c785cSJohn Marino   tp = inferior_thread ();
11386c50c785cSJohn Marino   thread = tp->num;
11387c50c785cSJohn Marino 
11388*ef5ccd6cSJohn Marino   old_chain = make_cleanup (null_cleanup, NULL);
11389*ef5ccd6cSJohn Marino 
11390*ef5ccd6cSJohn Marino   /* Note linespec handling above invalidates the frame chain.
11391*ef5ccd6cSJohn Marino      Installing a breakpoint also invalidates the frame chain (as it
11392*ef5ccd6cSJohn Marino      may need to switch threads), so do any frame handling before
11393*ef5ccd6cSJohn Marino      that.  */
11394*ef5ccd6cSJohn Marino 
11395*ef5ccd6cSJohn Marino   frame = get_selected_frame (NULL);
11396*ef5ccd6cSJohn Marino   frame_gdbarch = get_frame_arch (frame);
11397*ef5ccd6cSJohn Marino   stack_frame_id = get_stack_frame_id (frame);
11398*ef5ccd6cSJohn Marino   caller_frame_id = frame_unwind_caller_id (frame);
11399*ef5ccd6cSJohn Marino 
114005796c8dcSSimon Schubert   /* Keep within the current frame, or in frames called by the current
114015796c8dcSSimon Schubert      one.  */
114025796c8dcSSimon Schubert 
11403*ef5ccd6cSJohn Marino   if (frame_id_p (caller_frame_id))
114045796c8dcSSimon Schubert     {
11405*ef5ccd6cSJohn Marino       struct symtab_and_line sal2;
11406*ef5ccd6cSJohn Marino 
11407*ef5ccd6cSJohn Marino       sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
11408*ef5ccd6cSJohn Marino       sal2.pc = frame_unwind_caller_pc (frame);
114095796c8dcSSimon Schubert       breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
11410*ef5ccd6cSJohn Marino 					      sal2,
11411*ef5ccd6cSJohn Marino 					      caller_frame_id,
114125796c8dcSSimon Schubert 					      bp_until);
114135796c8dcSSimon Schubert       make_cleanup_delete_breakpoint (breakpoint2);
11414c50c785cSJohn Marino 
11415*ef5ccd6cSJohn Marino       set_longjmp_breakpoint (tp, caller_frame_id);
11416c50c785cSJohn Marino       make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
114175796c8dcSSimon Schubert     }
114185796c8dcSSimon Schubert 
11419*ef5ccd6cSJohn Marino   /* set_momentary_breakpoint could invalidate FRAME.  */
11420*ef5ccd6cSJohn Marino   frame = NULL;
11421*ef5ccd6cSJohn Marino 
11422*ef5ccd6cSJohn Marino   if (anywhere)
11423*ef5ccd6cSJohn Marino     /* If the user told us to continue until a specified location,
11424*ef5ccd6cSJohn Marino        we don't specify a frame at which we need to stop.  */
11425*ef5ccd6cSJohn Marino     breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11426*ef5ccd6cSJohn Marino 					   null_frame_id, bp_until);
11427*ef5ccd6cSJohn Marino   else
11428*ef5ccd6cSJohn Marino     /* Otherwise, specify the selected frame, because we want to stop
11429*ef5ccd6cSJohn Marino        only at the very same frame.  */
11430*ef5ccd6cSJohn Marino     breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
11431*ef5ccd6cSJohn Marino 					   stack_frame_id, bp_until);
11432*ef5ccd6cSJohn Marino   make_cleanup_delete_breakpoint (breakpoint);
11433*ef5ccd6cSJohn Marino 
11434*ef5ccd6cSJohn Marino   proceed (-1, GDB_SIGNAL_DEFAULT, 0);
114355796c8dcSSimon Schubert 
11436c50c785cSJohn Marino   /* If we are running asynchronously, and proceed call above has
11437c50c785cSJohn Marino      actually managed to start the target, arrange for breakpoints to
11438c50c785cSJohn Marino      be deleted when the target stops.  Otherwise, we're already
11439c50c785cSJohn Marino      stopped and delete breakpoints via cleanup chain.  */
114405796c8dcSSimon Schubert 
114415796c8dcSSimon Schubert   if (target_can_async_p () && is_running (inferior_ptid))
114425796c8dcSSimon Schubert     {
114435796c8dcSSimon Schubert       struct until_break_command_continuation_args *args;
114445796c8dcSSimon Schubert       args = xmalloc (sizeof (*args));
114455796c8dcSSimon Schubert 
114465796c8dcSSimon Schubert       args->breakpoint = breakpoint;
114475796c8dcSSimon Schubert       args->breakpoint2 = breakpoint2;
11448c50c785cSJohn Marino       args->thread_num = thread;
114495796c8dcSSimon Schubert 
114505796c8dcSSimon Schubert       discard_cleanups (old_chain);
114515796c8dcSSimon Schubert       add_continuation (inferior_thread (),
114525796c8dcSSimon Schubert 			until_break_command_continuation, args,
114535796c8dcSSimon Schubert 			xfree);
114545796c8dcSSimon Schubert     }
114555796c8dcSSimon Schubert   else
114565796c8dcSSimon Schubert     do_cleanups (old_chain);
114575796c8dcSSimon Schubert }
114585796c8dcSSimon Schubert 
114595796c8dcSSimon Schubert /* This function attempts to parse an optional "if <cond>" clause
114605796c8dcSSimon Schubert    from the arg string.  If one is not found, it returns NULL.
114615796c8dcSSimon Schubert 
114625796c8dcSSimon Schubert    Else, it returns a pointer to the condition string.  (It does not
114635796c8dcSSimon Schubert    attempt to evaluate the string against a particular block.)  And,
114645796c8dcSSimon Schubert    it updates arg to point to the first character following the parsed
114655796c8dcSSimon Schubert    if clause in the arg string.  */
114665796c8dcSSimon Schubert 
114675796c8dcSSimon Schubert static char *
ep_parse_optional_if_clause(char ** arg)114685796c8dcSSimon Schubert ep_parse_optional_if_clause (char **arg)
114695796c8dcSSimon Schubert {
114705796c8dcSSimon Schubert   char *cond_string;
114715796c8dcSSimon Schubert 
114725796c8dcSSimon Schubert   if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
114735796c8dcSSimon Schubert     return NULL;
114745796c8dcSSimon Schubert 
114755796c8dcSSimon Schubert   /* Skip the "if" keyword.  */
114765796c8dcSSimon Schubert   (*arg) += 2;
114775796c8dcSSimon Schubert 
114785796c8dcSSimon Schubert   /* Skip any extra leading whitespace, and record the start of the
114795796c8dcSSimon Schubert      condition string.  */
11480c50c785cSJohn Marino   *arg = skip_spaces (*arg);
114815796c8dcSSimon Schubert   cond_string = *arg;
114825796c8dcSSimon Schubert 
11483c50c785cSJohn Marino   /* Assume that the condition occupies the remainder of the arg
11484c50c785cSJohn Marino      string.  */
114855796c8dcSSimon Schubert   (*arg) += strlen (cond_string);
114865796c8dcSSimon Schubert 
114875796c8dcSSimon Schubert   return cond_string;
114885796c8dcSSimon Schubert }
114895796c8dcSSimon Schubert 
114905796c8dcSSimon Schubert /* Commands to deal with catching events, such as signals, exceptions,
114915796c8dcSSimon Schubert    process start/exit, etc.  */
114925796c8dcSSimon Schubert 
114935796c8dcSSimon Schubert typedef enum
114945796c8dcSSimon Schubert {
114955796c8dcSSimon Schubert   catch_fork_temporary, catch_vfork_temporary,
114965796c8dcSSimon Schubert   catch_fork_permanent, catch_vfork_permanent
114975796c8dcSSimon Schubert }
114985796c8dcSSimon Schubert catch_fork_kind;
114995796c8dcSSimon Schubert 
115005796c8dcSSimon Schubert static void
catch_fork_command_1(char * arg,int from_tty,struct cmd_list_element * command)11501cf7f2e2dSJohn Marino catch_fork_command_1 (char *arg, int from_tty,
11502cf7f2e2dSJohn Marino 		      struct cmd_list_element *command)
115035796c8dcSSimon Schubert {
115045796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_current_arch ();
115055796c8dcSSimon Schubert   char *cond_string = NULL;
115065796c8dcSSimon Schubert   catch_fork_kind fork_kind;
115075796c8dcSSimon Schubert   int tempflag;
115085796c8dcSSimon Schubert 
115095796c8dcSSimon Schubert   fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
115105796c8dcSSimon Schubert   tempflag = (fork_kind == catch_fork_temporary
115115796c8dcSSimon Schubert 	      || fork_kind == catch_vfork_temporary);
115125796c8dcSSimon Schubert 
115135796c8dcSSimon Schubert   if (!arg)
115145796c8dcSSimon Schubert     arg = "";
11515c50c785cSJohn Marino   arg = skip_spaces (arg);
115165796c8dcSSimon Schubert 
115175796c8dcSSimon Schubert   /* The allowed syntax is:
115185796c8dcSSimon Schubert      catch [v]fork
115195796c8dcSSimon Schubert      catch [v]fork if <cond>
115205796c8dcSSimon Schubert 
115215796c8dcSSimon Schubert      First, check if there's an if clause.  */
115225796c8dcSSimon Schubert   cond_string = ep_parse_optional_if_clause (&arg);
115235796c8dcSSimon Schubert 
115245796c8dcSSimon Schubert   if ((*arg != '\0') && !isspace (*arg))
115255796c8dcSSimon Schubert     error (_("Junk at end of arguments."));
115265796c8dcSSimon Schubert 
115275796c8dcSSimon Schubert   /* If this target supports it, create a fork or vfork catchpoint
115285796c8dcSSimon Schubert      and enable reporting of such events.  */
115295796c8dcSSimon Schubert   switch (fork_kind)
115305796c8dcSSimon Schubert     {
115315796c8dcSSimon Schubert     case catch_fork_temporary:
115325796c8dcSSimon Schubert     case catch_fork_permanent:
115335796c8dcSSimon Schubert       create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
115345796c8dcSSimon Schubert                                           &catch_fork_breakpoint_ops);
115355796c8dcSSimon Schubert       break;
115365796c8dcSSimon Schubert     case catch_vfork_temporary:
115375796c8dcSSimon Schubert     case catch_vfork_permanent:
115385796c8dcSSimon Schubert       create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
115395796c8dcSSimon Schubert                                           &catch_vfork_breakpoint_ops);
115405796c8dcSSimon Schubert       break;
115415796c8dcSSimon Schubert     default:
115425796c8dcSSimon Schubert       error (_("unsupported or unknown fork kind; cannot catch it"));
115435796c8dcSSimon Schubert       break;
115445796c8dcSSimon Schubert     }
115455796c8dcSSimon Schubert }
115465796c8dcSSimon Schubert 
115475796c8dcSSimon Schubert static void
catch_exec_command_1(char * arg,int from_tty,struct cmd_list_element * command)11548cf7f2e2dSJohn Marino catch_exec_command_1 (char *arg, int from_tty,
11549cf7f2e2dSJohn Marino 		      struct cmd_list_element *command)
115505796c8dcSSimon Schubert {
11551a45ae5f8SJohn Marino   struct exec_catchpoint *c;
115525796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_current_arch ();
115535796c8dcSSimon Schubert   int tempflag;
115545796c8dcSSimon Schubert   char *cond_string = NULL;
115555796c8dcSSimon Schubert 
115565796c8dcSSimon Schubert   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
115575796c8dcSSimon Schubert 
115585796c8dcSSimon Schubert   if (!arg)
115595796c8dcSSimon Schubert     arg = "";
11560c50c785cSJohn Marino   arg = skip_spaces (arg);
115615796c8dcSSimon Schubert 
115625796c8dcSSimon Schubert   /* The allowed syntax is:
115635796c8dcSSimon Schubert      catch exec
115645796c8dcSSimon Schubert      catch exec if <cond>
115655796c8dcSSimon Schubert 
115665796c8dcSSimon Schubert      First, check if there's an if clause.  */
115675796c8dcSSimon Schubert   cond_string = ep_parse_optional_if_clause (&arg);
115685796c8dcSSimon Schubert 
115695796c8dcSSimon Schubert   if ((*arg != '\0') && !isspace (*arg))
115705796c8dcSSimon Schubert     error (_("Junk at end of arguments."));
115715796c8dcSSimon Schubert 
11572a45ae5f8SJohn Marino   c = XNEW (struct exec_catchpoint);
11573a45ae5f8SJohn Marino   init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
115745796c8dcSSimon Schubert 		   &catch_exec_breakpoint_ops);
11575a45ae5f8SJohn Marino   c->exec_pathname = NULL;
11576a45ae5f8SJohn Marino 
11577a45ae5f8SJohn Marino   install_breakpoint (0, &c->base, 1);
115785796c8dcSSimon Schubert }
115795796c8dcSSimon Schubert 
115805796c8dcSSimon Schubert static enum print_stop_action
print_it_exception_catchpoint(bpstat bs)11581a45ae5f8SJohn Marino print_it_exception_catchpoint (bpstat bs)
115825796c8dcSSimon Schubert {
11583a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
11584a45ae5f8SJohn Marino   struct breakpoint *b = bs->breakpoint_at;
115855796c8dcSSimon Schubert   int bp_temp, bp_throw;
115865796c8dcSSimon Schubert 
115875796c8dcSSimon Schubert   annotate_catchpoint (b->number);
115885796c8dcSSimon Schubert 
115895796c8dcSSimon Schubert   bp_throw = strstr (b->addr_string, "throw") != NULL;
115905796c8dcSSimon Schubert   if (b->loc->address != b->loc->requested_address)
115915796c8dcSSimon Schubert     breakpoint_adjustment_warning (b->loc->requested_address,
115925796c8dcSSimon Schubert 	                           b->loc->address,
115935796c8dcSSimon Schubert 				   b->number, 1);
115945796c8dcSSimon Schubert   bp_temp = b->disposition == disp_del;
115955796c8dcSSimon Schubert   ui_out_text (uiout,
115965796c8dcSSimon Schubert 	       bp_temp ? "Temporary catchpoint "
115975796c8dcSSimon Schubert 		       : "Catchpoint ");
115985796c8dcSSimon Schubert   if (!ui_out_is_mi_like_p (uiout))
115995796c8dcSSimon Schubert     ui_out_field_int (uiout, "bkptno", b->number);
116005796c8dcSSimon Schubert   ui_out_text (uiout,
116015796c8dcSSimon Schubert 	       bp_throw ? " (exception thrown), "
116025796c8dcSSimon Schubert 		        : " (exception caught), ");
116035796c8dcSSimon Schubert   if (ui_out_is_mi_like_p (uiout))
116045796c8dcSSimon Schubert     {
116055796c8dcSSimon Schubert       ui_out_field_string (uiout, "reason",
116065796c8dcSSimon Schubert 			   async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
116075796c8dcSSimon Schubert       ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
116085796c8dcSSimon Schubert       ui_out_field_int (uiout, "bkptno", b->number);
116095796c8dcSSimon Schubert     }
116105796c8dcSSimon Schubert   return PRINT_SRC_AND_LOC;
116115796c8dcSSimon Schubert }
116125796c8dcSSimon Schubert 
116135796c8dcSSimon Schubert static void
print_one_exception_catchpoint(struct breakpoint * b,struct bp_location ** last_loc)11614cf7f2e2dSJohn Marino print_one_exception_catchpoint (struct breakpoint *b,
11615cf7f2e2dSJohn Marino 				struct bp_location **last_loc)
116165796c8dcSSimon Schubert {
116175796c8dcSSimon Schubert   struct value_print_options opts;
11618a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
11619cf7f2e2dSJohn Marino 
116205796c8dcSSimon Schubert   get_user_print_options (&opts);
116215796c8dcSSimon Schubert   if (opts.addressprint)
116225796c8dcSSimon Schubert     {
116235796c8dcSSimon Schubert       annotate_field (4);
116245796c8dcSSimon Schubert       if (b->loc == NULL || b->loc->shlib_disabled)
116255796c8dcSSimon Schubert 	ui_out_field_string (uiout, "addr", "<PENDING>");
116265796c8dcSSimon Schubert       else
116275796c8dcSSimon Schubert 	ui_out_field_core_addr (uiout, "addr",
116285796c8dcSSimon Schubert 				b->loc->gdbarch, b->loc->address);
116295796c8dcSSimon Schubert     }
116305796c8dcSSimon Schubert   annotate_field (5);
116315796c8dcSSimon Schubert   if (b->loc)
116325796c8dcSSimon Schubert     *last_loc = b->loc;
116335796c8dcSSimon Schubert   if (strstr (b->addr_string, "throw") != NULL)
11634*ef5ccd6cSJohn Marino     {
116355796c8dcSSimon Schubert       ui_out_field_string (uiout, "what", "exception throw");
11636*ef5ccd6cSJohn Marino       if (ui_out_is_mi_like_p (uiout))
11637*ef5ccd6cSJohn Marino 	ui_out_field_string (uiout, "catch-type", "throw");
11638*ef5ccd6cSJohn Marino     }
116395796c8dcSSimon Schubert   else
11640*ef5ccd6cSJohn Marino     {
116415796c8dcSSimon Schubert       ui_out_field_string (uiout, "what", "exception catch");
11642*ef5ccd6cSJohn Marino       if (ui_out_is_mi_like_p (uiout))
11643*ef5ccd6cSJohn Marino 	ui_out_field_string (uiout, "catch-type", "catch");
11644*ef5ccd6cSJohn Marino     }
116455796c8dcSSimon Schubert }
116465796c8dcSSimon Schubert 
116475796c8dcSSimon Schubert static void
print_mention_exception_catchpoint(struct breakpoint * b)116485796c8dcSSimon Schubert print_mention_exception_catchpoint (struct breakpoint *b)
116495796c8dcSSimon Schubert {
11650a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
116515796c8dcSSimon Schubert   int bp_temp;
116525796c8dcSSimon Schubert   int bp_throw;
116535796c8dcSSimon Schubert 
116545796c8dcSSimon Schubert   bp_temp = b->disposition == disp_del;
116555796c8dcSSimon Schubert   bp_throw = strstr (b->addr_string, "throw") != NULL;
116565796c8dcSSimon Schubert   ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
116575796c8dcSSimon Schubert 			      : _("Catchpoint "));
116585796c8dcSSimon Schubert   ui_out_field_int (uiout, "bkptno", b->number);
116595796c8dcSSimon Schubert   ui_out_text (uiout, bp_throw ? _(" (throw)")
116605796c8dcSSimon Schubert 			       : _(" (catch)"));
116615796c8dcSSimon Schubert }
116625796c8dcSSimon Schubert 
11663cf7f2e2dSJohn Marino /* Implement the "print_recreate" breakpoint_ops method for throw and
11664cf7f2e2dSJohn Marino    catch catchpoints.  */
11665cf7f2e2dSJohn Marino 
11666cf7f2e2dSJohn Marino static void
print_recreate_exception_catchpoint(struct breakpoint * b,struct ui_file * fp)11667c50c785cSJohn Marino print_recreate_exception_catchpoint (struct breakpoint *b,
11668c50c785cSJohn Marino 				     struct ui_file *fp)
11669cf7f2e2dSJohn Marino {
11670cf7f2e2dSJohn Marino   int bp_temp;
11671cf7f2e2dSJohn Marino   int bp_throw;
11672cf7f2e2dSJohn Marino 
11673cf7f2e2dSJohn Marino   bp_temp = b->disposition == disp_del;
11674cf7f2e2dSJohn Marino   bp_throw = strstr (b->addr_string, "throw") != NULL;
11675cf7f2e2dSJohn Marino   fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11676cf7f2e2dSJohn Marino   fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
11677a45ae5f8SJohn Marino   print_recreate_thread (b, fp);
11678cf7f2e2dSJohn Marino }
11679cf7f2e2dSJohn Marino 
11680a45ae5f8SJohn Marino static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
116815796c8dcSSimon Schubert 
116825796c8dcSSimon Schubert static int
handle_gnu_v3_exceptions(int tempflag,char * cond_string,enum exception_event_kind ex_event,int from_tty)116835796c8dcSSimon Schubert handle_gnu_v3_exceptions (int tempflag, char *cond_string,
116845796c8dcSSimon Schubert 			  enum exception_event_kind ex_event, int from_tty)
116855796c8dcSSimon Schubert {
116865796c8dcSSimon Schubert   char *trigger_func_name;
116875796c8dcSSimon Schubert 
116885796c8dcSSimon Schubert   if (ex_event == EX_EVENT_CATCH)
116895796c8dcSSimon Schubert     trigger_func_name = "__cxa_begin_catch";
116905796c8dcSSimon Schubert   else
116915796c8dcSSimon Schubert     trigger_func_name = "__cxa_throw";
116925796c8dcSSimon Schubert 
11693cf7f2e2dSJohn Marino   create_breakpoint (get_current_arch (),
11694*ef5ccd6cSJohn Marino 		     trigger_func_name, cond_string, -1, NULL,
116955796c8dcSSimon Schubert 		     0 /* condition and thread are valid.  */,
11696cf7f2e2dSJohn Marino 		     tempflag, bp_breakpoint,
116975796c8dcSSimon Schubert 		     0,
116985796c8dcSSimon Schubert 		     AUTO_BOOLEAN_TRUE /* pending */,
116995796c8dcSSimon Schubert 		     &gnu_v3_exception_catchpoint_ops, from_tty,
11700c50c785cSJohn Marino 		     1 /* enabled */,
11701a45ae5f8SJohn Marino 		     0 /* internal */,
11702a45ae5f8SJohn Marino 		     0);
117035796c8dcSSimon Schubert 
117045796c8dcSSimon Schubert   return 1;
117055796c8dcSSimon Schubert }
117065796c8dcSSimon Schubert 
11707c50c785cSJohn Marino /* Deal with "catch catch" and "catch throw" commands.  */
117085796c8dcSSimon Schubert 
117095796c8dcSSimon Schubert static void
catch_exception_command_1(enum exception_event_kind ex_event,char * arg,int tempflag,int from_tty)117105796c8dcSSimon Schubert catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
117115796c8dcSSimon Schubert 			   int tempflag, int from_tty)
117125796c8dcSSimon Schubert {
117135796c8dcSSimon Schubert   char *cond_string = NULL;
117145796c8dcSSimon Schubert 
117155796c8dcSSimon Schubert   if (!arg)
117165796c8dcSSimon Schubert     arg = "";
11717c50c785cSJohn Marino   arg = skip_spaces (arg);
117185796c8dcSSimon Schubert 
117195796c8dcSSimon Schubert   cond_string = ep_parse_optional_if_clause (&arg);
117205796c8dcSSimon Schubert 
117215796c8dcSSimon Schubert   if ((*arg != '\0') && !isspace (*arg))
117225796c8dcSSimon Schubert     error (_("Junk at end of arguments."));
117235796c8dcSSimon Schubert 
117245796c8dcSSimon Schubert   if (ex_event != EX_EVENT_THROW
117255796c8dcSSimon Schubert       && ex_event != EX_EVENT_CATCH)
117265796c8dcSSimon Schubert     error (_("Unsupported or unknown exception event; cannot catch it"));
117275796c8dcSSimon Schubert 
117285796c8dcSSimon Schubert   if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
117295796c8dcSSimon Schubert     return;
117305796c8dcSSimon Schubert 
117315796c8dcSSimon Schubert   warning (_("Unsupported with this platform/compiler combination."));
117325796c8dcSSimon Schubert }
117335796c8dcSSimon Schubert 
117345796c8dcSSimon Schubert /* Implementation of "catch catch" command.  */
117355796c8dcSSimon Schubert 
117365796c8dcSSimon Schubert static void
catch_catch_command(char * arg,int from_tty,struct cmd_list_element * command)117375796c8dcSSimon Schubert catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
117385796c8dcSSimon Schubert {
117395796c8dcSSimon Schubert   int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11740cf7f2e2dSJohn Marino 
117415796c8dcSSimon Schubert   catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
117425796c8dcSSimon Schubert }
117435796c8dcSSimon Schubert 
117445796c8dcSSimon Schubert /* Implementation of "catch throw" command.  */
117455796c8dcSSimon Schubert 
117465796c8dcSSimon Schubert static void
catch_throw_command(char * arg,int from_tty,struct cmd_list_element * command)117475796c8dcSSimon Schubert catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
117485796c8dcSSimon Schubert {
117495796c8dcSSimon Schubert   int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11750cf7f2e2dSJohn Marino 
117515796c8dcSSimon Schubert   catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
117525796c8dcSSimon Schubert }
117535796c8dcSSimon Schubert 
11754a45ae5f8SJohn Marino 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 from_tty)11755a45ae5f8SJohn Marino init_ada_exception_breakpoint (struct breakpoint *b,
11756a45ae5f8SJohn Marino 			       struct gdbarch *gdbarch,
117575796c8dcSSimon Schubert 			       struct symtab_and_line sal,
117585796c8dcSSimon Schubert 			       char *addr_string,
11759a45ae5f8SJohn Marino 			       const struct breakpoint_ops *ops,
117605796c8dcSSimon Schubert 			       int tempflag,
117615796c8dcSSimon Schubert 			       int from_tty)
117625796c8dcSSimon Schubert {
117635796c8dcSSimon Schubert   if (from_tty)
117645796c8dcSSimon Schubert     {
117655796c8dcSSimon Schubert       struct gdbarch *loc_gdbarch = get_sal_arch (sal);
117665796c8dcSSimon Schubert       if (!loc_gdbarch)
117675796c8dcSSimon Schubert 	loc_gdbarch = gdbarch;
117685796c8dcSSimon Schubert 
11769cf7f2e2dSJohn Marino       describe_other_breakpoints (loc_gdbarch,
11770cf7f2e2dSJohn Marino 				  sal.pspace, sal.pc, sal.section, -1);
117715796c8dcSSimon Schubert       /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
117725796c8dcSSimon Schubert          version for exception catchpoints, because two catchpoints
117735796c8dcSSimon Schubert          used for different exception names will use the same address.
117745796c8dcSSimon Schubert          In this case, a "breakpoint ... also set at..." warning is
11775c50c785cSJohn Marino          unproductive.  Besides, the warning phrasing is also a bit
11776a45ae5f8SJohn Marino          inappropriate, we should use the word catchpoint, and tell
117775796c8dcSSimon Schubert          the user what type of catchpoint it is.  The above is good
117785796c8dcSSimon Schubert          enough for now, though.  */
117795796c8dcSSimon Schubert     }
117805796c8dcSSimon Schubert 
11781a45ae5f8SJohn Marino   init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
117825796c8dcSSimon Schubert 
117835796c8dcSSimon Schubert   b->enable_state = bp_enabled;
117845796c8dcSSimon Schubert   b->disposition = tempflag ? disp_del : disp_donttouch;
117855796c8dcSSimon Schubert   b->addr_string = addr_string;
117865796c8dcSSimon Schubert   b->language = language_ada;
117875796c8dcSSimon Schubert }
117885796c8dcSSimon Schubert 
117895796c8dcSSimon Schubert /* Splits the argument using space as delimiter.  Returns an xmalloc'd
117905796c8dcSSimon Schubert    filter list, or NULL if no filtering is required.  */
VEC(int)117915796c8dcSSimon Schubert static VEC(int) *
117925796c8dcSSimon Schubert catch_syscall_split_args (char *arg)
117935796c8dcSSimon Schubert {
117945796c8dcSSimon Schubert   VEC(int) *result = NULL;
11795a45ae5f8SJohn Marino   struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
117965796c8dcSSimon Schubert 
117975796c8dcSSimon Schubert   while (*arg != '\0')
117985796c8dcSSimon Schubert     {
117995796c8dcSSimon Schubert       int i, syscall_number;
118005796c8dcSSimon Schubert       char *endptr;
118015796c8dcSSimon Schubert       char cur_name[128];
118025796c8dcSSimon Schubert       struct syscall s;
118035796c8dcSSimon Schubert 
118045796c8dcSSimon Schubert       /* Skip whitespace.  */
11805*ef5ccd6cSJohn Marino       arg = skip_spaces (arg);
118065796c8dcSSimon Schubert 
118075796c8dcSSimon Schubert       for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
118085796c8dcSSimon Schubert 	cur_name[i] = arg[i];
118095796c8dcSSimon Schubert       cur_name[i] = '\0';
118105796c8dcSSimon Schubert       arg += i;
118115796c8dcSSimon Schubert 
118125796c8dcSSimon Schubert       /* Check if the user provided a syscall name or a number.  */
118135796c8dcSSimon Schubert       syscall_number = (int) strtol (cur_name, &endptr, 0);
118145796c8dcSSimon Schubert       if (*endptr == '\0')
118155796c8dcSSimon Schubert 	get_syscall_by_number (syscall_number, &s);
118165796c8dcSSimon Schubert       else
118175796c8dcSSimon Schubert 	{
118185796c8dcSSimon Schubert 	  /* We have a name.  Let's check if it's valid and convert it
118195796c8dcSSimon Schubert 	     to a number.  */
118205796c8dcSSimon Schubert 	  get_syscall_by_name (cur_name, &s);
118215796c8dcSSimon Schubert 
118225796c8dcSSimon Schubert 	  if (s.number == UNKNOWN_SYSCALL)
11823c50c785cSJohn Marino 	    /* Here we have to issue an error instead of a warning,
11824c50c785cSJohn Marino 	       because GDB cannot do anything useful if there's no
11825c50c785cSJohn Marino 	       syscall number to be caught.  */
118265796c8dcSSimon Schubert 	    error (_("Unknown syscall name '%s'."), cur_name);
118275796c8dcSSimon Schubert 	}
118285796c8dcSSimon Schubert 
118295796c8dcSSimon Schubert       /* Ok, it's valid.  */
118305796c8dcSSimon Schubert       VEC_safe_push (int, result, s.number);
118315796c8dcSSimon Schubert     }
118325796c8dcSSimon Schubert 
118335796c8dcSSimon Schubert   discard_cleanups (cleanup);
118345796c8dcSSimon Schubert   return result;
118355796c8dcSSimon Schubert }
118365796c8dcSSimon Schubert 
118375796c8dcSSimon Schubert /* Implement the "catch syscall" command.  */
118385796c8dcSSimon Schubert 
118395796c8dcSSimon Schubert static void
catch_syscall_command_1(char * arg,int from_tty,struct cmd_list_element * command)11840cf7f2e2dSJohn Marino catch_syscall_command_1 (char *arg, int from_tty,
11841cf7f2e2dSJohn Marino 			 struct cmd_list_element *command)
118425796c8dcSSimon Schubert {
118435796c8dcSSimon Schubert   int tempflag;
118445796c8dcSSimon Schubert   VEC(int) *filter;
118455796c8dcSSimon Schubert   struct syscall s;
118465796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_current_arch ();
118475796c8dcSSimon Schubert 
118485796c8dcSSimon Schubert   /* Checking if the feature if supported.  */
118495796c8dcSSimon Schubert   if (gdbarch_get_syscall_number_p (gdbarch) == 0)
118505796c8dcSSimon Schubert     error (_("The feature 'catch syscall' is not supported on \
11851c50c785cSJohn Marino this architecture yet."));
118525796c8dcSSimon Schubert 
118535796c8dcSSimon Schubert   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
118545796c8dcSSimon Schubert 
11855c50c785cSJohn Marino   arg = skip_spaces (arg);
118565796c8dcSSimon Schubert 
118575796c8dcSSimon Schubert   /* We need to do this first "dummy" translation in order
118585796c8dcSSimon Schubert      to get the syscall XML file loaded or, most important,
118595796c8dcSSimon Schubert      to display a warning to the user if there's no XML file
118605796c8dcSSimon Schubert      for his/her architecture.  */
118615796c8dcSSimon Schubert   get_syscall_by_number (0, &s);
118625796c8dcSSimon Schubert 
118635796c8dcSSimon Schubert   /* The allowed syntax is:
118645796c8dcSSimon Schubert      catch syscall
118655796c8dcSSimon Schubert      catch syscall <name | number> [<name | number> ... <name | number>]
118665796c8dcSSimon Schubert 
118675796c8dcSSimon Schubert      Let's check if there's a syscall name.  */
118685796c8dcSSimon Schubert 
118695796c8dcSSimon Schubert   if (arg != NULL)
118705796c8dcSSimon Schubert     filter = catch_syscall_split_args (arg);
118715796c8dcSSimon Schubert   else
118725796c8dcSSimon Schubert     filter = NULL;
118735796c8dcSSimon Schubert 
118745796c8dcSSimon Schubert   create_syscall_event_catchpoint (tempflag, filter,
118755796c8dcSSimon Schubert 				   &catch_syscall_breakpoint_ops);
118765796c8dcSSimon Schubert }
118775796c8dcSSimon Schubert 
118785796c8dcSSimon Schubert static void
catch_command(char * arg,int from_tty)118795796c8dcSSimon Schubert catch_command (char *arg, int from_tty)
118805796c8dcSSimon Schubert {
118815796c8dcSSimon Schubert   error (_("Catch requires an event name."));
118825796c8dcSSimon Schubert }
118835796c8dcSSimon Schubert 
118845796c8dcSSimon Schubert 
118855796c8dcSSimon Schubert static void
tcatch_command(char * arg,int from_tty)118865796c8dcSSimon Schubert tcatch_command (char *arg, int from_tty)
118875796c8dcSSimon Schubert {
118885796c8dcSSimon Schubert   error (_("Catch requires an event name."));
118895796c8dcSSimon Schubert }
118905796c8dcSSimon Schubert 
11891a45ae5f8SJohn Marino /* A qsort comparison function that sorts breakpoints in order.  */
11892a45ae5f8SJohn Marino 
11893a45ae5f8SJohn Marino static int
compare_breakpoints(const void * a,const void * b)11894a45ae5f8SJohn Marino compare_breakpoints (const void *a, const void *b)
11895a45ae5f8SJohn Marino {
11896a45ae5f8SJohn Marino   const breakpoint_p *ba = a;
11897a45ae5f8SJohn Marino   uintptr_t ua = (uintptr_t) *ba;
11898a45ae5f8SJohn Marino   const breakpoint_p *bb = b;
11899a45ae5f8SJohn Marino   uintptr_t ub = (uintptr_t) *bb;
11900a45ae5f8SJohn Marino 
11901a45ae5f8SJohn Marino   if ((*ba)->number < (*bb)->number)
11902a45ae5f8SJohn Marino     return -1;
11903a45ae5f8SJohn Marino   else if ((*ba)->number > (*bb)->number)
11904a45ae5f8SJohn Marino     return 1;
11905a45ae5f8SJohn Marino 
11906a45ae5f8SJohn Marino   /* Now sort by address, in case we see, e..g, two breakpoints with
11907a45ae5f8SJohn Marino      the number 0.  */
11908a45ae5f8SJohn Marino   if (ua < ub)
11909a45ae5f8SJohn Marino     return -1;
11910*ef5ccd6cSJohn Marino   return ua > ub ? 1 : 0;
11911a45ae5f8SJohn Marino }
11912a45ae5f8SJohn Marino 
119135796c8dcSSimon Schubert /* Delete breakpoints by address or line.  */
119145796c8dcSSimon Schubert 
119155796c8dcSSimon Schubert static void
clear_command(char * arg,int from_tty)119165796c8dcSSimon Schubert clear_command (char *arg, int from_tty)
119175796c8dcSSimon Schubert {
11918a45ae5f8SJohn Marino   struct breakpoint *b, *prev;
119195796c8dcSSimon Schubert   VEC(breakpoint_p) *found = 0;
119205796c8dcSSimon Schubert   int ix;
119215796c8dcSSimon Schubert   int default_match;
119225796c8dcSSimon Schubert   struct symtabs_and_lines sals;
119235796c8dcSSimon Schubert   struct symtab_and_line sal;
119245796c8dcSSimon Schubert   int i;
11925a45ae5f8SJohn Marino   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
119265796c8dcSSimon Schubert 
119275796c8dcSSimon Schubert   if (arg)
119285796c8dcSSimon Schubert     {
11929*ef5ccd6cSJohn Marino       sals = decode_line_with_current_source (arg,
11930*ef5ccd6cSJohn Marino 					      (DECODE_LINE_FUNFIRSTLINE
11931a45ae5f8SJohn Marino 					       | DECODE_LINE_LIST_MODE));
11932*ef5ccd6cSJohn Marino       make_cleanup (xfree, sals.sals);
119335796c8dcSSimon Schubert       default_match = 0;
119345796c8dcSSimon Schubert     }
119355796c8dcSSimon Schubert   else
119365796c8dcSSimon Schubert     {
119375796c8dcSSimon Schubert       sals.sals = (struct symtab_and_line *)
119385796c8dcSSimon Schubert 	xmalloc (sizeof (struct symtab_and_line));
119395796c8dcSSimon Schubert       make_cleanup (xfree, sals.sals);
11940c50c785cSJohn Marino       init_sal (&sal);		/* Initialize to zeroes.  */
11941a45ae5f8SJohn Marino 
11942a45ae5f8SJohn Marino       /* Set sal's line, symtab, pc, and pspace to the values
11943a45ae5f8SJohn Marino 	 corresponding to the last call to print_frame_info.  If the
11944a45ae5f8SJohn Marino 	 codepoint is not valid, this will set all the fields to 0.  */
11945a45ae5f8SJohn Marino       get_last_displayed_sal (&sal);
119465796c8dcSSimon Schubert       if (sal.symtab == 0)
119475796c8dcSSimon Schubert 	error (_("No source file specified."));
119485796c8dcSSimon Schubert 
119495796c8dcSSimon Schubert       sals.sals[0] = sal;
119505796c8dcSSimon Schubert       sals.nelts = 1;
119515796c8dcSSimon Schubert 
119525796c8dcSSimon Schubert       default_match = 1;
119535796c8dcSSimon Schubert     }
119545796c8dcSSimon Schubert 
11955c50c785cSJohn Marino   /* We don't call resolve_sal_pc here.  That's not as bad as it
11956c50c785cSJohn Marino      seems, because all existing breakpoints typically have both
11957c50c785cSJohn Marino      file/line and pc set.  So, if clear is given file/line, we can
11958c50c785cSJohn Marino      match this to existing breakpoint without obtaining pc at all.
119595796c8dcSSimon Schubert 
119605796c8dcSSimon Schubert      We only support clearing given the address explicitly
119615796c8dcSSimon Schubert      present in breakpoint table.  Say, we've set breakpoint
119625796c8dcSSimon Schubert      at file:line.  There were several PC values for that file:line,
119635796c8dcSSimon Schubert      due to optimization, all in one block.
11964c50c785cSJohn Marino 
119655796c8dcSSimon Schubert      We've picked one PC value.  If "clear" is issued with another
119665796c8dcSSimon Schubert      PC corresponding to the same file:line, the breakpoint won't
119675796c8dcSSimon Schubert      be cleared.  We probably can still clear the breakpoint, but
119685796c8dcSSimon Schubert      since the other PC value is never presented to user, user
119695796c8dcSSimon Schubert      can only find it by guessing, and it does not seem important
119705796c8dcSSimon Schubert      to support that.  */
119715796c8dcSSimon Schubert 
11972c50c785cSJohn Marino   /* For each line spec given, delete bps which correspond to it.  Do
11973c50c785cSJohn Marino      it in two passes, solely to preserve the current behavior that
11974c50c785cSJohn Marino      from_tty is forced true if we delete more than one
11975c50c785cSJohn Marino      breakpoint.  */
119765796c8dcSSimon Schubert 
119775796c8dcSSimon Schubert   found = NULL;
11978a45ae5f8SJohn Marino   make_cleanup (VEC_cleanup (breakpoint_p), &found);
119795796c8dcSSimon Schubert   for (i = 0; i < sals.nelts; i++)
119805796c8dcSSimon Schubert     {
11981*ef5ccd6cSJohn Marino       const char *sal_fullname;
11982*ef5ccd6cSJohn Marino 
119835796c8dcSSimon Schubert       /* If exact pc given, clear bpts at that pc.
119845796c8dcSSimon Schubert          If line given (pc == 0), clear all bpts on specified line.
119855796c8dcSSimon Schubert          If defaulting, clear all bpts on default line
119865796c8dcSSimon Schubert          or at default pc.
119875796c8dcSSimon Schubert 
119885796c8dcSSimon Schubert          defaulting    sal.pc != 0    tests to do
119895796c8dcSSimon Schubert 
119905796c8dcSSimon Schubert          0              1             pc
119915796c8dcSSimon Schubert          1              1             pc _and_ line
119925796c8dcSSimon Schubert          0              0             line
119935796c8dcSSimon Schubert          1              0             <can't happen> */
119945796c8dcSSimon Schubert 
119955796c8dcSSimon Schubert       sal = sals.sals[i];
11996*ef5ccd6cSJohn Marino       sal_fullname = (sal.symtab == NULL
11997*ef5ccd6cSJohn Marino 		      ? NULL : symtab_to_fullname (sal.symtab));
119985796c8dcSSimon Schubert 
11999c50c785cSJohn Marino       /* Find all matching breakpoints and add them to 'found'.  */
120005796c8dcSSimon Schubert       ALL_BREAKPOINTS (b)
120015796c8dcSSimon Schubert 	{
120025796c8dcSSimon Schubert 	  int match = 0;
120035796c8dcSSimon Schubert 	  /* Are we going to delete b?  */
12004cf7f2e2dSJohn Marino 	  if (b->type != bp_none && !is_watchpoint (b))
120055796c8dcSSimon Schubert 	    {
120065796c8dcSSimon Schubert 	      struct bp_location *loc = b->loc;
120075796c8dcSSimon Schubert 	      for (; loc; loc = loc->next)
120085796c8dcSSimon Schubert 		{
12009a45ae5f8SJohn Marino 		  /* If the user specified file:line, don't allow a PC
12010a45ae5f8SJohn Marino 		     match.  This matches historical gdb behavior.  */
12011a45ae5f8SJohn Marino 		  int pc_match = (!sal.explicit_line
12012a45ae5f8SJohn Marino 				  && sal.pc
12013cf7f2e2dSJohn Marino 				  && (loc->pspace == sal.pspace)
120145796c8dcSSimon Schubert 				  && (loc->address == sal.pc)
120155796c8dcSSimon Schubert 				  && (!section_is_overlay (loc->section)
12016a45ae5f8SJohn Marino 				      || loc->section == sal.section));
12017*ef5ccd6cSJohn Marino 		  int line_match = 0;
12018*ef5ccd6cSJohn Marino 
12019*ef5ccd6cSJohn Marino 		  if ((default_match || sal.explicit_line)
12020*ef5ccd6cSJohn Marino 		      && loc->symtab != NULL
12021*ef5ccd6cSJohn Marino 		      && sal_fullname != NULL
12022cf7f2e2dSJohn Marino 		      && sal.pspace == loc->pspace
12023*ef5ccd6cSJohn Marino 		      && loc->line_number == sal.line
12024*ef5ccd6cSJohn Marino 		      && filename_cmp (symtab_to_fullname (loc->symtab),
12025*ef5ccd6cSJohn Marino 				       sal_fullname) == 0)
12026*ef5ccd6cSJohn Marino 		    line_match = 1;
12027*ef5ccd6cSJohn Marino 
120285796c8dcSSimon Schubert 		  if (pc_match || line_match)
120295796c8dcSSimon Schubert 		    {
120305796c8dcSSimon Schubert 		      match = 1;
120315796c8dcSSimon Schubert 		      break;
120325796c8dcSSimon Schubert 		    }
120335796c8dcSSimon Schubert 		}
120345796c8dcSSimon Schubert 	    }
120355796c8dcSSimon Schubert 
120365796c8dcSSimon Schubert 	  if (match)
120375796c8dcSSimon Schubert 	    VEC_safe_push(breakpoint_p, found, b);
120385796c8dcSSimon Schubert 	}
120395796c8dcSSimon Schubert     }
12040a45ae5f8SJohn Marino 
120415796c8dcSSimon Schubert   /* Now go thru the 'found' chain and delete them.  */
120425796c8dcSSimon Schubert   if (VEC_empty(breakpoint_p, found))
120435796c8dcSSimon Schubert     {
120445796c8dcSSimon Schubert       if (arg)
120455796c8dcSSimon Schubert 	error (_("No breakpoint at %s."), arg);
120465796c8dcSSimon Schubert       else
120475796c8dcSSimon Schubert 	error (_("No breakpoint at this line."));
120485796c8dcSSimon Schubert     }
120495796c8dcSSimon Schubert 
12050a45ae5f8SJohn Marino   /* Remove duplicates from the vec.  */
12051a45ae5f8SJohn Marino   qsort (VEC_address (breakpoint_p, found),
12052a45ae5f8SJohn Marino 	 VEC_length (breakpoint_p, found),
12053a45ae5f8SJohn Marino 	 sizeof (breakpoint_p),
12054a45ae5f8SJohn Marino 	 compare_breakpoints);
12055a45ae5f8SJohn Marino   prev = VEC_index (breakpoint_p, found, 0);
12056a45ae5f8SJohn Marino   for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
12057a45ae5f8SJohn Marino     {
12058a45ae5f8SJohn Marino       if (b == prev)
12059a45ae5f8SJohn Marino 	{
12060a45ae5f8SJohn Marino 	  VEC_ordered_remove (breakpoint_p, found, ix);
12061a45ae5f8SJohn Marino 	  --ix;
12062a45ae5f8SJohn Marino 	}
12063a45ae5f8SJohn Marino     }
12064a45ae5f8SJohn Marino 
120655796c8dcSSimon Schubert   if (VEC_length(breakpoint_p, found) > 1)
12066c50c785cSJohn Marino     from_tty = 1;	/* Always report if deleted more than one.  */
120675796c8dcSSimon Schubert   if (from_tty)
120685796c8dcSSimon Schubert     {
120695796c8dcSSimon Schubert       if (VEC_length(breakpoint_p, found) == 1)
120705796c8dcSSimon Schubert 	printf_unfiltered (_("Deleted breakpoint "));
120715796c8dcSSimon Schubert       else
120725796c8dcSSimon Schubert 	printf_unfiltered (_("Deleted breakpoints "));
120735796c8dcSSimon Schubert     }
120745796c8dcSSimon Schubert 
120755796c8dcSSimon Schubert   for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
120765796c8dcSSimon Schubert     {
120775796c8dcSSimon Schubert       if (from_tty)
120785796c8dcSSimon Schubert 	printf_unfiltered ("%d ", b->number);
120795796c8dcSSimon Schubert       delete_breakpoint (b);
120805796c8dcSSimon Schubert     }
120815796c8dcSSimon Schubert   if (from_tty)
120825796c8dcSSimon Schubert     putchar_unfiltered ('\n');
12083a45ae5f8SJohn Marino 
12084a45ae5f8SJohn Marino   do_cleanups (cleanups);
120855796c8dcSSimon Schubert }
120865796c8dcSSimon Schubert 
120875796c8dcSSimon Schubert /* Delete breakpoint in BS if they are `delete' breakpoints and
120885796c8dcSSimon Schubert    all breakpoints that are marked for deletion, whether hit or not.
120895796c8dcSSimon Schubert    This is called after any breakpoint is hit, or after errors.  */
120905796c8dcSSimon Schubert 
120915796c8dcSSimon Schubert void
breakpoint_auto_delete(bpstat bs)120925796c8dcSSimon Schubert breakpoint_auto_delete (bpstat bs)
120935796c8dcSSimon Schubert {
12094c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
120955796c8dcSSimon Schubert 
120965796c8dcSSimon Schubert   for (; bs; bs = bs->next)
120975796c8dcSSimon Schubert     if (bs->breakpoint_at
12098c50c785cSJohn Marino 	&& bs->breakpoint_at->disposition == disp_del
120995796c8dcSSimon Schubert 	&& bs->stop)
12100c50c785cSJohn Marino       delete_breakpoint (bs->breakpoint_at);
121015796c8dcSSimon Schubert 
12102c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
121035796c8dcSSimon Schubert   {
121045796c8dcSSimon Schubert     if (b->disposition == disp_del_at_next_stop)
121055796c8dcSSimon Schubert       delete_breakpoint (b);
121065796c8dcSSimon Schubert   }
121075796c8dcSSimon Schubert }
121085796c8dcSSimon Schubert 
12109c50c785cSJohn Marino /* A comparison function for bp_location AP and BP being interfaced to
12110c50c785cSJohn Marino    qsort.  Sort elements primarily by their ADDRESS (no matter what
12111c50c785cSJohn Marino    does breakpoint_address_is_meaningful say for its OWNER),
12112c50c785cSJohn Marino    secondarily by ordering first bp_permanent OWNERed elements and
12113c50c785cSJohn Marino    terciarily just ensuring the array is sorted stable way despite
12114a45ae5f8SJohn Marino    qsort being an unstable algorithm.  */
12115cf7f2e2dSJohn Marino 
12116cf7f2e2dSJohn Marino static int
bp_location_compare(const void * ap,const void * bp)12117cf7f2e2dSJohn Marino bp_location_compare (const void *ap, const void *bp)
12118cf7f2e2dSJohn Marino {
12119cf7f2e2dSJohn Marino   struct bp_location *a = *(void **) ap;
12120cf7f2e2dSJohn Marino   struct bp_location *b = *(void **) bp;
12121cf7f2e2dSJohn Marino   /* A and B come from existing breakpoints having non-NULL OWNER.  */
12122cf7f2e2dSJohn Marino   int a_perm = a->owner->enable_state == bp_permanent;
12123cf7f2e2dSJohn Marino   int b_perm = b->owner->enable_state == bp_permanent;
12124cf7f2e2dSJohn Marino 
12125cf7f2e2dSJohn Marino   if (a->address != b->address)
12126cf7f2e2dSJohn Marino     return (a->address > b->address) - (a->address < b->address);
12127cf7f2e2dSJohn Marino 
12128*ef5ccd6cSJohn Marino   /* Sort locations at the same address by their pspace number, keeping
12129*ef5ccd6cSJohn Marino      locations of the same inferior (in a multi-inferior environment)
12130*ef5ccd6cSJohn Marino      grouped.  */
12131*ef5ccd6cSJohn Marino 
12132*ef5ccd6cSJohn Marino   if (a->pspace->num != b->pspace->num)
12133*ef5ccd6cSJohn Marino     return ((a->pspace->num > b->pspace->num)
12134*ef5ccd6cSJohn Marino 	    - (a->pspace->num < b->pspace->num));
12135*ef5ccd6cSJohn Marino 
12136cf7f2e2dSJohn Marino   /* Sort permanent breakpoints first.  */
12137cf7f2e2dSJohn Marino   if (a_perm != b_perm)
12138cf7f2e2dSJohn Marino     return (a_perm < b_perm) - (a_perm > b_perm);
12139cf7f2e2dSJohn Marino 
12140*ef5ccd6cSJohn Marino   /* Make the internal GDB representation stable across GDB runs
12141*ef5ccd6cSJohn Marino      where A and B memory inside GDB can differ.  Breakpoint locations of
12142*ef5ccd6cSJohn Marino      the same type at the same address can be sorted in arbitrary order.  */
12143cf7f2e2dSJohn Marino 
12144cf7f2e2dSJohn Marino   if (a->owner->number != b->owner->number)
12145*ef5ccd6cSJohn Marino     return ((a->owner->number > b->owner->number)
12146*ef5ccd6cSJohn Marino 	    - (a->owner->number < b->owner->number));
12147cf7f2e2dSJohn Marino 
12148cf7f2e2dSJohn Marino   return (a > b) - (a < b);
12149cf7f2e2dSJohn Marino }
12150cf7f2e2dSJohn Marino 
12151cf7f2e2dSJohn Marino /* Set bp_location_placed_address_before_address_max and
12152c50c785cSJohn Marino    bp_location_shadow_len_after_address_max according to the current
12153c50c785cSJohn Marino    content of the bp_location array.  */
121545796c8dcSSimon Schubert 
121555796c8dcSSimon Schubert static void
bp_location_target_extensions_update(void)12156cf7f2e2dSJohn Marino bp_location_target_extensions_update (void)
121575796c8dcSSimon Schubert {
12158cf7f2e2dSJohn Marino   struct bp_location *bl, **blp_tmp;
12159cf7f2e2dSJohn Marino 
12160cf7f2e2dSJohn Marino   bp_location_placed_address_before_address_max = 0;
12161cf7f2e2dSJohn Marino   bp_location_shadow_len_after_address_max = 0;
12162cf7f2e2dSJohn Marino 
12163cf7f2e2dSJohn Marino   ALL_BP_LOCATIONS (bl, blp_tmp)
12164cf7f2e2dSJohn Marino     {
12165cf7f2e2dSJohn Marino       CORE_ADDR start, end, addr;
12166cf7f2e2dSJohn Marino 
12167cf7f2e2dSJohn Marino       if (!bp_location_has_shadow (bl))
12168cf7f2e2dSJohn Marino 	continue;
12169cf7f2e2dSJohn Marino 
12170cf7f2e2dSJohn Marino       start = bl->target_info.placed_address;
12171cf7f2e2dSJohn Marino       end = start + bl->target_info.shadow_len;
12172cf7f2e2dSJohn Marino 
12173cf7f2e2dSJohn Marino       gdb_assert (bl->address >= start);
12174cf7f2e2dSJohn Marino       addr = bl->address - start;
12175cf7f2e2dSJohn Marino       if (addr > bp_location_placed_address_before_address_max)
12176cf7f2e2dSJohn Marino 	bp_location_placed_address_before_address_max = addr;
12177cf7f2e2dSJohn Marino 
12178cf7f2e2dSJohn Marino       /* Zero SHADOW_LEN would not pass bp_location_has_shadow.  */
12179cf7f2e2dSJohn Marino 
12180cf7f2e2dSJohn Marino       gdb_assert (bl->address < end);
12181cf7f2e2dSJohn Marino       addr = end - bl->address;
12182cf7f2e2dSJohn Marino       if (addr > bp_location_shadow_len_after_address_max)
12183cf7f2e2dSJohn Marino 	bp_location_shadow_len_after_address_max = addr;
12184cf7f2e2dSJohn Marino     }
121855796c8dcSSimon Schubert }
121865796c8dcSSimon Schubert 
12187a45ae5f8SJohn Marino /* Download tracepoint locations if they haven't been.  */
12188a45ae5f8SJohn Marino 
12189a45ae5f8SJohn Marino static void
download_tracepoint_locations(void)12190a45ae5f8SJohn Marino download_tracepoint_locations (void)
12191a45ae5f8SJohn Marino {
12192*ef5ccd6cSJohn Marino   struct breakpoint *b;
12193a45ae5f8SJohn Marino   struct cleanup *old_chain;
12194a45ae5f8SJohn Marino 
12195a45ae5f8SJohn Marino   if (!target_can_download_tracepoint ())
12196a45ae5f8SJohn Marino     return;
12197a45ae5f8SJohn Marino 
12198a45ae5f8SJohn Marino   old_chain = save_current_space_and_thread ();
12199a45ae5f8SJohn Marino 
12200*ef5ccd6cSJohn Marino   ALL_TRACEPOINTS (b)
12201a45ae5f8SJohn Marino     {
12202*ef5ccd6cSJohn Marino       struct bp_location *bl;
12203a45ae5f8SJohn Marino       struct tracepoint *t;
12204*ef5ccd6cSJohn Marino       int bp_location_downloaded = 0;
12205a45ae5f8SJohn Marino 
12206*ef5ccd6cSJohn Marino       if ((b->type == bp_fast_tracepoint
12207a45ae5f8SJohn Marino 	   ? !may_insert_fast_tracepoints
12208a45ae5f8SJohn Marino 	   : !may_insert_tracepoints))
12209a45ae5f8SJohn Marino 	continue;
12210a45ae5f8SJohn Marino 
12211*ef5ccd6cSJohn Marino       for (bl = b->loc; bl; bl = bl->next)
12212*ef5ccd6cSJohn Marino 	{
12213a45ae5f8SJohn Marino 	  /* In tracepoint, locations are _never_ duplicated, so
12214a45ae5f8SJohn Marino 	     should_be_inserted is equivalent to
12215a45ae5f8SJohn Marino 	     unduplicated_should_be_inserted.  */
12216a45ae5f8SJohn Marino 	  if (!should_be_inserted (bl) || bl->inserted)
12217a45ae5f8SJohn Marino 	    continue;
12218a45ae5f8SJohn Marino 
12219a45ae5f8SJohn Marino 	  switch_to_program_space_and_thread (bl->pspace);
12220a45ae5f8SJohn Marino 
12221a45ae5f8SJohn Marino 	  target_download_tracepoint (bl);
12222a45ae5f8SJohn Marino 
12223a45ae5f8SJohn Marino 	  bl->inserted = 1;
12224*ef5ccd6cSJohn Marino 	  bp_location_downloaded = 1;
12225*ef5ccd6cSJohn Marino 	}
12226*ef5ccd6cSJohn Marino       t = (struct tracepoint *) b;
12227*ef5ccd6cSJohn Marino       t->number_on_target = b->number;
12228*ef5ccd6cSJohn Marino       if (bp_location_downloaded)
12229*ef5ccd6cSJohn Marino 	observer_notify_breakpoint_modified (b);
12230a45ae5f8SJohn Marino     }
12231a45ae5f8SJohn Marino 
12232a45ae5f8SJohn Marino   do_cleanups (old_chain);
12233a45ae5f8SJohn Marino }
12234a45ae5f8SJohn Marino 
12235a45ae5f8SJohn Marino /* Swap the insertion/duplication state between two locations.  */
12236a45ae5f8SJohn Marino 
12237a45ae5f8SJohn Marino static void
swap_insertion(struct bp_location * left,struct bp_location * right)12238a45ae5f8SJohn Marino swap_insertion (struct bp_location *left, struct bp_location *right)
12239a45ae5f8SJohn Marino {
12240a45ae5f8SJohn Marino   const int left_inserted = left->inserted;
12241a45ae5f8SJohn Marino   const int left_duplicate = left->duplicate;
12242*ef5ccd6cSJohn Marino   const int left_needs_update = left->needs_update;
12243a45ae5f8SJohn Marino   const struct bp_target_info left_target_info = left->target_info;
12244a45ae5f8SJohn Marino 
12245a45ae5f8SJohn Marino   /* Locations of tracepoints can never be duplicated.  */
12246a45ae5f8SJohn Marino   if (is_tracepoint (left->owner))
12247a45ae5f8SJohn Marino     gdb_assert (!left->duplicate);
12248a45ae5f8SJohn Marino   if (is_tracepoint (right->owner))
12249a45ae5f8SJohn Marino     gdb_assert (!right->duplicate);
12250a45ae5f8SJohn Marino 
12251a45ae5f8SJohn Marino   left->inserted = right->inserted;
12252a45ae5f8SJohn Marino   left->duplicate = right->duplicate;
12253*ef5ccd6cSJohn Marino   left->needs_update = right->needs_update;
12254a45ae5f8SJohn Marino   left->target_info = right->target_info;
12255a45ae5f8SJohn Marino   right->inserted = left_inserted;
12256a45ae5f8SJohn Marino   right->duplicate = left_duplicate;
12257*ef5ccd6cSJohn Marino   right->needs_update = left_needs_update;
12258a45ae5f8SJohn Marino   right->target_info = left_target_info;
12259a45ae5f8SJohn Marino }
12260a45ae5f8SJohn Marino 
12261*ef5ccd6cSJohn Marino /* Force the re-insertion of the locations at ADDRESS.  This is called
12262*ef5ccd6cSJohn Marino    once a new/deleted/modified duplicate location is found and we are evaluating
12263*ef5ccd6cSJohn Marino    conditions on the target's side.  Such conditions need to be updated on
12264*ef5ccd6cSJohn Marino    the target.  */
12265*ef5ccd6cSJohn Marino 
12266*ef5ccd6cSJohn Marino static void
force_breakpoint_reinsertion(struct bp_location * bl)12267*ef5ccd6cSJohn Marino force_breakpoint_reinsertion (struct bp_location *bl)
12268*ef5ccd6cSJohn Marino {
12269*ef5ccd6cSJohn Marino   struct bp_location **locp = NULL, **loc2p;
12270*ef5ccd6cSJohn Marino   struct bp_location *loc;
12271*ef5ccd6cSJohn Marino   CORE_ADDR address = 0;
12272*ef5ccd6cSJohn Marino   int pspace_num;
12273*ef5ccd6cSJohn Marino 
12274*ef5ccd6cSJohn Marino   address = bl->address;
12275*ef5ccd6cSJohn Marino   pspace_num = bl->pspace->num;
12276*ef5ccd6cSJohn Marino 
12277*ef5ccd6cSJohn Marino   /* This is only meaningful if the target is
12278*ef5ccd6cSJohn Marino      evaluating conditions and if the user has
12279*ef5ccd6cSJohn Marino      opted for condition evaluation on the target's
12280*ef5ccd6cSJohn Marino      side.  */
12281*ef5ccd6cSJohn Marino   if (gdb_evaluates_breakpoint_condition_p ()
12282*ef5ccd6cSJohn Marino       || !target_supports_evaluation_of_breakpoint_conditions ())
12283*ef5ccd6cSJohn Marino     return;
12284*ef5ccd6cSJohn Marino 
12285*ef5ccd6cSJohn Marino   /* Flag all breakpoint locations with this address and
12286*ef5ccd6cSJohn Marino      the same program space as the location
12287*ef5ccd6cSJohn Marino      as "its condition has changed".  We need to
12288*ef5ccd6cSJohn Marino      update the conditions on the target's side.  */
12289*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
12290*ef5ccd6cSJohn Marino     {
12291*ef5ccd6cSJohn Marino       loc = *loc2p;
12292*ef5ccd6cSJohn Marino 
12293*ef5ccd6cSJohn Marino       if (!is_breakpoint (loc->owner)
12294*ef5ccd6cSJohn Marino 	  || pspace_num != loc->pspace->num)
12295*ef5ccd6cSJohn Marino 	continue;
12296*ef5ccd6cSJohn Marino 
12297*ef5ccd6cSJohn Marino       /* Flag the location appropriately.  We use a different state to
12298*ef5ccd6cSJohn Marino 	 let everyone know that we already updated the set of locations
12299*ef5ccd6cSJohn Marino 	 with addr bl->address and program space bl->pspace.  This is so
12300*ef5ccd6cSJohn Marino 	 we don't have to keep calling these functions just to mark locations
12301*ef5ccd6cSJohn Marino 	 that have already been marked.  */
12302*ef5ccd6cSJohn Marino       loc->condition_changed = condition_updated;
12303*ef5ccd6cSJohn Marino 
12304*ef5ccd6cSJohn Marino       /* Free the agent expression bytecode as well.  We will compute
12305*ef5ccd6cSJohn Marino 	 it later on.  */
12306*ef5ccd6cSJohn Marino       if (loc->cond_bytecode)
12307*ef5ccd6cSJohn Marino 	{
12308*ef5ccd6cSJohn Marino 	  free_agent_expr (loc->cond_bytecode);
12309*ef5ccd6cSJohn Marino 	  loc->cond_bytecode = NULL;
12310*ef5ccd6cSJohn Marino 	}
12311*ef5ccd6cSJohn Marino     }
12312*ef5ccd6cSJohn Marino }
12313*ef5ccd6cSJohn Marino 
123145796c8dcSSimon Schubert /* If SHOULD_INSERT is false, do not insert any breakpoint locations
123155796c8dcSSimon Schubert    into the inferior, only remove already-inserted locations that no
123165796c8dcSSimon Schubert    longer should be inserted.  Functions that delete a breakpoint or
123175796c8dcSSimon Schubert    breakpoints should pass false, so that deleting a breakpoint
123185796c8dcSSimon Schubert    doesn't have the side effect of inserting the locations of other
123195796c8dcSSimon Schubert    breakpoints that are marked not-inserted, but should_be_inserted
123205796c8dcSSimon Schubert    returns true on them.
123215796c8dcSSimon Schubert 
123225796c8dcSSimon Schubert    This behaviour is useful is situations close to tear-down -- e.g.,
123235796c8dcSSimon Schubert    after an exec, while the target still has execution, but breakpoint
123245796c8dcSSimon Schubert    shadows of the previous executable image should *NOT* be restored
123255796c8dcSSimon Schubert    to the new image; or before detaching, where the target still has
123265796c8dcSSimon Schubert    execution and wants to delete breakpoints from GDB's lists, and all
123275796c8dcSSimon Schubert    breakpoints had already been removed from the inferior.  */
123285796c8dcSSimon Schubert 
123295796c8dcSSimon Schubert static void
update_global_location_list(int should_insert)123305796c8dcSSimon Schubert update_global_location_list (int should_insert)
123315796c8dcSSimon Schubert {
123325796c8dcSSimon Schubert   struct breakpoint *b;
12333cf7f2e2dSJohn Marino   struct bp_location **locp, *loc;
123345796c8dcSSimon Schubert   struct cleanup *cleanups;
12335*ef5ccd6cSJohn Marino   /* Last breakpoint location address that was marked for update.  */
12336*ef5ccd6cSJohn Marino   CORE_ADDR last_addr = 0;
12337*ef5ccd6cSJohn Marino   /* Last breakpoint location program space that was marked for update.  */
12338*ef5ccd6cSJohn Marino   int last_pspace_num = -1;
123395796c8dcSSimon Schubert 
12340cf7f2e2dSJohn Marino   /* Used in the duplicates detection below.  When iterating over all
12341cf7f2e2dSJohn Marino      bp_locations, points to the first bp_location of a given address.
12342cf7f2e2dSJohn Marino      Breakpoints and watchpoints of different types are never
12343cf7f2e2dSJohn Marino      duplicates of each other.  Keep one pointer for each type of
12344cf7f2e2dSJohn Marino      breakpoint/watchpoint, so we only need to loop over all locations
12345cf7f2e2dSJohn Marino      once.  */
12346cf7f2e2dSJohn Marino   struct bp_location *bp_loc_first;  /* breakpoint */
12347cf7f2e2dSJohn Marino   struct bp_location *wp_loc_first;  /* hardware watchpoint */
12348cf7f2e2dSJohn Marino   struct bp_location *awp_loc_first; /* access watchpoint */
12349cf7f2e2dSJohn Marino   struct bp_location *rwp_loc_first; /* read watchpoint */
123505796c8dcSSimon Schubert 
12351c50c785cSJohn Marino   /* Saved former bp_location array which we compare against the newly
12352c50c785cSJohn Marino      built bp_location from the current state of ALL_BREAKPOINTS.  */
12353cf7f2e2dSJohn Marino   struct bp_location **old_location, **old_locp;
12354cf7f2e2dSJohn Marino   unsigned old_location_count;
12355cf7f2e2dSJohn Marino 
12356cf7f2e2dSJohn Marino   old_location = bp_location;
12357cf7f2e2dSJohn Marino   old_location_count = bp_location_count;
12358cf7f2e2dSJohn Marino   bp_location = NULL;
12359cf7f2e2dSJohn Marino   bp_location_count = 0;
12360cf7f2e2dSJohn Marino   cleanups = make_cleanup (xfree, old_location);
12361cf7f2e2dSJohn Marino 
123625796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
123635796c8dcSSimon Schubert     for (loc = b->loc; loc; loc = loc->next)
12364cf7f2e2dSJohn Marino       bp_location_count++;
12365cf7f2e2dSJohn Marino 
12366cf7f2e2dSJohn Marino   bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
12367cf7f2e2dSJohn Marino   locp = bp_location;
12368cf7f2e2dSJohn Marino   ALL_BREAKPOINTS (b)
12369cf7f2e2dSJohn Marino     for (loc = b->loc; loc; loc = loc->next)
12370cf7f2e2dSJohn Marino       *locp++ = loc;
12371cf7f2e2dSJohn Marino   qsort (bp_location, bp_location_count, sizeof (*bp_location),
12372cf7f2e2dSJohn Marino 	 bp_location_compare);
12373cf7f2e2dSJohn Marino 
12374cf7f2e2dSJohn Marino   bp_location_target_extensions_update ();
123755796c8dcSSimon Schubert 
12376c50c785cSJohn Marino   /* Identify bp_location instances that are no longer present in the
12377c50c785cSJohn Marino      new list, and therefore should be freed.  Note that it's not
12378c50c785cSJohn Marino      necessary that those locations should be removed from inferior --
12379c50c785cSJohn Marino      if there's another location at the same address (previously
12380c50c785cSJohn Marino      marked as duplicate), we don't need to remove/insert the
12381c50c785cSJohn Marino      location.
12382cf7f2e2dSJohn Marino 
12383c50c785cSJohn Marino      LOCP is kept in sync with OLD_LOCP, each pointing to the current
12384c50c785cSJohn Marino      and former bp_location array state respectively.  */
12385cf7f2e2dSJohn Marino 
12386cf7f2e2dSJohn Marino   locp = bp_location;
12387cf7f2e2dSJohn Marino   for (old_locp = old_location; old_locp < old_location + old_location_count;
12388cf7f2e2dSJohn Marino        old_locp++)
123895796c8dcSSimon Schubert     {
12390cf7f2e2dSJohn Marino       struct bp_location *old_loc = *old_locp;
12391cf7f2e2dSJohn Marino       struct bp_location **loc2p;
12392cf7f2e2dSJohn Marino 
12393a45ae5f8SJohn Marino       /* Tells if 'old_loc' is found among the new locations.  If
12394c50c785cSJohn Marino 	 not, we have to free it.  */
123955796c8dcSSimon Schubert       int found_object = 0;
123965796c8dcSSimon Schubert       /* Tells if the location should remain inserted in the target.  */
123975796c8dcSSimon Schubert       int keep_in_target = 0;
123985796c8dcSSimon Schubert       int removed = 0;
12399cf7f2e2dSJohn Marino 
12400c50c785cSJohn Marino       /* Skip LOCP entries which will definitely never be needed.
12401c50c785cSJohn Marino 	 Stop either at or being the one matching OLD_LOC.  */
12402cf7f2e2dSJohn Marino       while (locp < bp_location + bp_location_count
12403cf7f2e2dSJohn Marino 	     && (*locp)->address < old_loc->address)
12404cf7f2e2dSJohn Marino 	locp++;
12405cf7f2e2dSJohn Marino 
12406cf7f2e2dSJohn Marino       for (loc2p = locp;
12407cf7f2e2dSJohn Marino 	   (loc2p < bp_location + bp_location_count
12408cf7f2e2dSJohn Marino 	    && (*loc2p)->address == old_loc->address);
12409cf7f2e2dSJohn Marino 	   loc2p++)
12410cf7f2e2dSJohn Marino 	{
12411*ef5ccd6cSJohn Marino 	  /* Check if this is a new/duplicated location or a duplicated
12412*ef5ccd6cSJohn Marino 	     location that had its condition modified.  If so, we want to send
12413*ef5ccd6cSJohn Marino 	     its condition to the target if evaluation of conditions is taking
12414*ef5ccd6cSJohn Marino 	     place there.  */
12415*ef5ccd6cSJohn Marino 	  if ((*loc2p)->condition_changed == condition_modified
12416*ef5ccd6cSJohn Marino 	      && (last_addr != old_loc->address
12417*ef5ccd6cSJohn Marino 		  || last_pspace_num != old_loc->pspace->num))
124185796c8dcSSimon Schubert 	    {
12419*ef5ccd6cSJohn Marino 	      force_breakpoint_reinsertion (*loc2p);
12420*ef5ccd6cSJohn Marino 	      last_pspace_num = old_loc->pspace->num;
12421*ef5ccd6cSJohn Marino 	    }
12422*ef5ccd6cSJohn Marino 
12423*ef5ccd6cSJohn Marino 	  if (*loc2p == old_loc)
124245796c8dcSSimon Schubert 	    found_object = 1;
124255796c8dcSSimon Schubert 	}
12426*ef5ccd6cSJohn Marino 
12427*ef5ccd6cSJohn Marino       /* We have already handled this address, update it so that we don't
12428*ef5ccd6cSJohn Marino 	 have to go through updates again.  */
12429*ef5ccd6cSJohn Marino       last_addr = old_loc->address;
12430*ef5ccd6cSJohn Marino 
12431*ef5ccd6cSJohn Marino       /* Target-side condition evaluation: Handle deleted locations.  */
12432*ef5ccd6cSJohn Marino       if (!found_object)
12433*ef5ccd6cSJohn Marino 	force_breakpoint_reinsertion (old_loc);
124345796c8dcSSimon Schubert 
12435c50c785cSJohn Marino       /* If this location is no longer present, and inserted, look if
12436c50c785cSJohn Marino 	 there's maybe a new location at the same address.  If so,
12437c50c785cSJohn Marino 	 mark that one inserted, and don't remove this one.  This is
12438c50c785cSJohn Marino 	 needed so that we don't have a time window where a breakpoint
12439c50c785cSJohn Marino 	 at certain location is not inserted.  */
124405796c8dcSSimon Schubert 
12441cf7f2e2dSJohn Marino       if (old_loc->inserted)
124425796c8dcSSimon Schubert 	{
12443c50c785cSJohn Marino 	  /* If the location is inserted now, we might have to remove
12444c50c785cSJohn Marino 	     it.  */
124455796c8dcSSimon Schubert 
12446cf7f2e2dSJohn Marino 	  if (found_object && should_be_inserted (old_loc))
124475796c8dcSSimon Schubert 	    {
12448c50c785cSJohn Marino 	      /* The location is still present in the location list,
12449c50c785cSJohn Marino 		 and still should be inserted.  Don't do anything.  */
124505796c8dcSSimon Schubert 	      keep_in_target = 1;
124515796c8dcSSimon Schubert 	    }
124525796c8dcSSimon Schubert 	  else
124535796c8dcSSimon Schubert 	    {
12454*ef5ccd6cSJohn Marino 	      /* This location still exists, but it won't be kept in the
12455*ef5ccd6cSJohn Marino 		 target since it may have been disabled.  We proceed to
12456*ef5ccd6cSJohn Marino 		 remove its target-side condition.  */
12457*ef5ccd6cSJohn Marino 
12458c50c785cSJohn Marino 	      /* The location is either no longer present, or got
12459c50c785cSJohn Marino 		 disabled.  See if there's another location at the
12460c50c785cSJohn Marino 		 same address, in which case we don't need to remove
12461c50c785cSJohn Marino 		 this one from the target.  */
12462cf7f2e2dSJohn Marino 
12463cf7f2e2dSJohn Marino 	      /* OLD_LOC comes from existing struct breakpoint.  */
12464cf7f2e2dSJohn Marino 	      if (breakpoint_address_is_meaningful (old_loc->owner))
124655796c8dcSSimon Schubert 		{
12466cf7f2e2dSJohn Marino 		  for (loc2p = locp;
12467cf7f2e2dSJohn Marino 		       (loc2p < bp_location + bp_location_count
12468cf7f2e2dSJohn Marino 			&& (*loc2p)->address == old_loc->address);
12469cf7f2e2dSJohn Marino 		       loc2p++)
12470cf7f2e2dSJohn Marino 		    {
12471cf7f2e2dSJohn Marino 		      struct bp_location *loc2 = *loc2p;
12472cf7f2e2dSJohn Marino 
12473cf7f2e2dSJohn Marino 		      if (breakpoint_locations_match (loc2, old_loc))
12474cf7f2e2dSJohn Marino 			{
12475cf7f2e2dSJohn Marino 			  /* Read watchpoint locations are switched to
12476cf7f2e2dSJohn Marino 			     access watchpoints, if the former are not
12477cf7f2e2dSJohn Marino 			     supported, but the latter are.  */
12478cf7f2e2dSJohn Marino 			  if (is_hardware_watchpoint (old_loc->owner))
12479cf7f2e2dSJohn Marino 			    {
12480cf7f2e2dSJohn Marino 			      gdb_assert (is_hardware_watchpoint (loc2->owner));
12481cf7f2e2dSJohn Marino 			      loc2->watchpoint_type = old_loc->watchpoint_type;
12482cf7f2e2dSJohn Marino 			    }
12483cf7f2e2dSJohn Marino 
12484a45ae5f8SJohn Marino 			  /* loc2 is a duplicated location. We need to check
12485a45ae5f8SJohn Marino 			     if it should be inserted in case it will be
12486a45ae5f8SJohn Marino 			     unduplicated.  */
12487a45ae5f8SJohn Marino 			  if (loc2 != old_loc
12488a45ae5f8SJohn Marino 			      && unduplicated_should_be_inserted (loc2))
124895796c8dcSSimon Schubert 			    {
12490a45ae5f8SJohn Marino 			      swap_insertion (old_loc, loc2);
124915796c8dcSSimon Schubert 			      keep_in_target = 1;
124925796c8dcSSimon Schubert 			      break;
124935796c8dcSSimon Schubert 			    }
124945796c8dcSSimon Schubert 			}
124955796c8dcSSimon Schubert 		    }
12496cf7f2e2dSJohn Marino 		}
12497cf7f2e2dSJohn Marino 	    }
124985796c8dcSSimon Schubert 
124995796c8dcSSimon Schubert 	  if (!keep_in_target)
125005796c8dcSSimon Schubert 	    {
12501cf7f2e2dSJohn Marino 	      if (remove_breakpoint (old_loc, mark_uninserted))
125025796c8dcSSimon Schubert 		{
12503c50c785cSJohn Marino 		  /* This is just about all we can do.  We could keep
12504c50c785cSJohn Marino 		     this location on the global list, and try to
12505c50c785cSJohn Marino 		     remove it next time, but there's no particular
12506c50c785cSJohn Marino 		     reason why we will succeed next time.
125075796c8dcSSimon Schubert 
12508c50c785cSJohn Marino 		     Note that at this point, old_loc->owner is still
12509c50c785cSJohn Marino 		     valid, as delete_breakpoint frees the breakpoint
12510c50c785cSJohn Marino 		     only after calling us.  */
12511c50c785cSJohn Marino 		  printf_filtered (_("warning: Error removing "
12512c50c785cSJohn Marino 				     "breakpoint %d\n"),
12513cf7f2e2dSJohn Marino 				   old_loc->owner->number);
125145796c8dcSSimon Schubert 		}
125155796c8dcSSimon Schubert 	      removed = 1;
125165796c8dcSSimon Schubert 	    }
125175796c8dcSSimon Schubert 	}
125185796c8dcSSimon Schubert 
125195796c8dcSSimon Schubert       if (!found_object)
125205796c8dcSSimon Schubert 	{
12521cf7f2e2dSJohn Marino 	  if (removed && non_stop
12522cf7f2e2dSJohn Marino 	      && breakpoint_address_is_meaningful (old_loc->owner)
12523cf7f2e2dSJohn Marino 	      && !is_hardware_watchpoint (old_loc->owner))
125245796c8dcSSimon Schubert 	    {
12525cf7f2e2dSJohn Marino 	      /* This location was removed from the target.  In
12526cf7f2e2dSJohn Marino 		 non-stop mode, a race condition is possible where
12527cf7f2e2dSJohn Marino 		 we've removed a breakpoint, but stop events for that
12528cf7f2e2dSJohn Marino 		 breakpoint are already queued and will arrive later.
12529cf7f2e2dSJohn Marino 		 We apply an heuristic to be able to distinguish such
12530cf7f2e2dSJohn Marino 		 SIGTRAPs from other random SIGTRAPs: we keep this
12531cf7f2e2dSJohn Marino 		 breakpoint location for a bit, and will retire it
12532cf7f2e2dSJohn Marino 		 after we see some number of events.  The theory here
12533cf7f2e2dSJohn Marino 		 is that reporting of events should, "on the average",
12534cf7f2e2dSJohn Marino 		 be fair, so after a while we'll see events from all
12535cf7f2e2dSJohn Marino 		 threads that have anything of interest, and no longer
12536cf7f2e2dSJohn Marino 		 need to keep this breakpoint location around.  We
12537cf7f2e2dSJohn Marino 		 don't hold locations forever so to reduce chances of
12538cf7f2e2dSJohn Marino 		 mistaking a non-breakpoint SIGTRAP for a breakpoint
12539cf7f2e2dSJohn Marino 		 SIGTRAP.
125405796c8dcSSimon Schubert 
12541cf7f2e2dSJohn Marino 		 The heuristic failing can be disastrous on
12542cf7f2e2dSJohn Marino 		 decr_pc_after_break targets.
12543cf7f2e2dSJohn Marino 
12544cf7f2e2dSJohn Marino 		 On decr_pc_after_break targets, like e.g., x86-linux,
12545cf7f2e2dSJohn Marino 		 if we fail to recognize a late breakpoint SIGTRAP,
12546cf7f2e2dSJohn Marino 		 because events_till_retirement has reached 0 too
12547cf7f2e2dSJohn Marino 		 soon, we'll fail to do the PC adjustment, and report
12548cf7f2e2dSJohn Marino 		 a random SIGTRAP to the user.  When the user resumes
12549cf7f2e2dSJohn Marino 		 the inferior, it will most likely immediately crash
12550cf7f2e2dSJohn Marino 		 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12551cf7f2e2dSJohn Marino 		 corrupted, because of being resumed e.g., in the
12552cf7f2e2dSJohn Marino 		 middle of a multi-byte instruction, or skipped a
12553cf7f2e2dSJohn Marino 		 one-byte instruction.  This was actually seen happen
12554cf7f2e2dSJohn Marino 		 on native x86-linux, and should be less rare on
12555cf7f2e2dSJohn Marino 		 targets that do not support new thread events, like
12556cf7f2e2dSJohn Marino 		 remote, due to the heuristic depending on
12557cf7f2e2dSJohn Marino 		 thread_count.
12558cf7f2e2dSJohn Marino 
12559cf7f2e2dSJohn Marino 		 Mistaking a random SIGTRAP for a breakpoint trap
12560cf7f2e2dSJohn Marino 		 causes similar symptoms (PC adjustment applied when
12561cf7f2e2dSJohn Marino 		 it shouldn't), but then again, playing with SIGTRAPs
12562cf7f2e2dSJohn Marino 		 behind the debugger's back is asking for trouble.
12563cf7f2e2dSJohn Marino 
12564cf7f2e2dSJohn Marino 		 Since hardware watchpoint traps are always
12565cf7f2e2dSJohn Marino 		 distinguishable from other traps, so we don't need to
12566cf7f2e2dSJohn Marino 		 apply keep hardware watchpoint moribund locations
12567cf7f2e2dSJohn Marino 		 around.  We simply always ignore hardware watchpoint
12568cf7f2e2dSJohn Marino 		 traps we can no longer explain.  */
12569cf7f2e2dSJohn Marino 
12570cf7f2e2dSJohn Marino 	      old_loc->events_till_retirement = 3 * (thread_count () + 1);
12571cf7f2e2dSJohn Marino 	      old_loc->owner = NULL;
12572cf7f2e2dSJohn Marino 
12573cf7f2e2dSJohn Marino 	      VEC_safe_push (bp_location_p, moribund_locations, old_loc);
125745796c8dcSSimon Schubert 	    }
125755796c8dcSSimon Schubert 	  else
12576c50c785cSJohn Marino 	    {
12577c50c785cSJohn Marino 	      old_loc->owner = NULL;
12578c50c785cSJohn Marino 	      decref_bp_location (&old_loc);
12579c50c785cSJohn Marino 	    }
125805796c8dcSSimon Schubert 	}
125815796c8dcSSimon Schubert     }
125825796c8dcSSimon Schubert 
12583cf7f2e2dSJohn Marino   /* Rescan breakpoints at the same address and section, marking the
12584cf7f2e2dSJohn Marino      first one as "first" and any others as "duplicates".  This is so
12585cf7f2e2dSJohn Marino      that the bpt instruction is only inserted once.  If we have a
12586cf7f2e2dSJohn Marino      permanent breakpoint at the same place as BPT, make that one the
12587cf7f2e2dSJohn Marino      official one, and the rest as duplicates.  Permanent breakpoints
12588cf7f2e2dSJohn Marino      are sorted first for the same address.
12589cf7f2e2dSJohn Marino 
12590cf7f2e2dSJohn Marino      Do the same for hardware watchpoints, but also considering the
12591cf7f2e2dSJohn Marino      watchpoint's type (regular/access/read) and length.  */
12592cf7f2e2dSJohn Marino 
12593cf7f2e2dSJohn Marino   bp_loc_first = NULL;
12594cf7f2e2dSJohn Marino   wp_loc_first = NULL;
12595cf7f2e2dSJohn Marino   awp_loc_first = NULL;
12596cf7f2e2dSJohn Marino   rwp_loc_first = NULL;
12597cf7f2e2dSJohn Marino   ALL_BP_LOCATIONS (loc, locp)
125985796c8dcSSimon Schubert     {
12599c50c785cSJohn Marino       /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12600c50c785cSJohn Marino 	 non-NULL.  */
12601cf7f2e2dSJohn Marino       struct bp_location **loc_first_p;
12602a45ae5f8SJohn Marino       b = loc->owner;
12603cf7f2e2dSJohn Marino 
12604*ef5ccd6cSJohn Marino       if (!unduplicated_should_be_inserted (loc)
12605cf7f2e2dSJohn Marino 	  || !breakpoint_address_is_meaningful (b)
12606a45ae5f8SJohn Marino 	  /* Don't detect duplicate for tracepoint locations because they are
12607a45ae5f8SJohn Marino 	   never duplicated.  See the comments in field `duplicate' of
12608a45ae5f8SJohn Marino 	   `struct bp_location'.  */
12609cf7f2e2dSJohn Marino 	  || is_tracepoint (b))
12610*ef5ccd6cSJohn Marino 	{
12611*ef5ccd6cSJohn Marino 	  /* Clear the condition modification flag.  */
12612*ef5ccd6cSJohn Marino 	  loc->condition_changed = condition_unchanged;
12613cf7f2e2dSJohn Marino 	  continue;
12614*ef5ccd6cSJohn Marino 	}
12615cf7f2e2dSJohn Marino 
12616cf7f2e2dSJohn Marino       /* Permanent breakpoint should always be inserted.  */
12617cf7f2e2dSJohn Marino       if (b->enable_state == bp_permanent && ! loc->inserted)
12618cf7f2e2dSJohn Marino 	internal_error (__FILE__, __LINE__,
12619cf7f2e2dSJohn Marino 			_("allegedly permanent breakpoint is not "
12620cf7f2e2dSJohn Marino 			"actually inserted"));
12621cf7f2e2dSJohn Marino 
12622cf7f2e2dSJohn Marino       if (b->type == bp_hardware_watchpoint)
12623cf7f2e2dSJohn Marino 	loc_first_p = &wp_loc_first;
12624cf7f2e2dSJohn Marino       else if (b->type == bp_read_watchpoint)
12625cf7f2e2dSJohn Marino 	loc_first_p = &rwp_loc_first;
12626cf7f2e2dSJohn Marino       else if (b->type == bp_access_watchpoint)
12627cf7f2e2dSJohn Marino 	loc_first_p = &awp_loc_first;
12628cf7f2e2dSJohn Marino       else
12629cf7f2e2dSJohn Marino 	loc_first_p = &bp_loc_first;
12630cf7f2e2dSJohn Marino 
12631cf7f2e2dSJohn Marino       if (*loc_first_p == NULL
12632cf7f2e2dSJohn Marino 	  || (overlay_debugging && loc->section != (*loc_first_p)->section)
12633cf7f2e2dSJohn Marino 	  || !breakpoint_locations_match (loc, *loc_first_p))
12634cf7f2e2dSJohn Marino 	{
12635cf7f2e2dSJohn Marino 	  *loc_first_p = loc;
12636cf7f2e2dSJohn Marino 	  loc->duplicate = 0;
12637*ef5ccd6cSJohn Marino 
12638*ef5ccd6cSJohn Marino 	  if (is_breakpoint (loc->owner) && loc->condition_changed)
12639*ef5ccd6cSJohn Marino 	    {
12640*ef5ccd6cSJohn Marino 	      loc->needs_update = 1;
12641*ef5ccd6cSJohn Marino 	      /* Clear the condition modification flag.  */
12642*ef5ccd6cSJohn Marino 	      loc->condition_changed = condition_unchanged;
12643*ef5ccd6cSJohn Marino 	    }
12644cf7f2e2dSJohn Marino 	  continue;
12645cf7f2e2dSJohn Marino 	}
12646cf7f2e2dSJohn Marino 
12647a45ae5f8SJohn Marino 
12648a45ae5f8SJohn Marino       /* This and the above ensure the invariant that the first location
12649a45ae5f8SJohn Marino 	 is not duplicated, and is the inserted one.
12650a45ae5f8SJohn Marino 	 All following are marked as duplicated, and are not inserted.  */
12651a45ae5f8SJohn Marino       if (loc->inserted)
12652a45ae5f8SJohn Marino 	swap_insertion (loc, *loc_first_p);
12653cf7f2e2dSJohn Marino       loc->duplicate = 1;
12654cf7f2e2dSJohn Marino 
12655*ef5ccd6cSJohn Marino       /* Clear the condition modification flag.  */
12656*ef5ccd6cSJohn Marino       loc->condition_changed = condition_unchanged;
12657*ef5ccd6cSJohn Marino 
12658cf7f2e2dSJohn Marino       if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12659cf7f2e2dSJohn Marino 	  && b->enable_state != bp_permanent)
12660cf7f2e2dSJohn Marino 	internal_error (__FILE__, __LINE__,
12661cf7f2e2dSJohn Marino 			_("another breakpoint was inserted on top of "
12662cf7f2e2dSJohn Marino 			"a permanent breakpoint"));
126635796c8dcSSimon Schubert     }
126645796c8dcSSimon Schubert 
12665*ef5ccd6cSJohn Marino   if (breakpoints_always_inserted_mode ()
126665796c8dcSSimon Schubert       && (have_live_inferiors ()
12667*ef5ccd6cSJohn Marino 	  || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12668*ef5ccd6cSJohn Marino     {
12669*ef5ccd6cSJohn Marino       if (should_insert)
126705796c8dcSSimon Schubert 	insert_breakpoint_locations ();
12671*ef5ccd6cSJohn Marino       else
12672*ef5ccd6cSJohn Marino 	{
12673*ef5ccd6cSJohn Marino 	  /* Though should_insert is false, we may need to update conditions
12674*ef5ccd6cSJohn Marino 	     on the target's side if it is evaluating such conditions.  We
12675*ef5ccd6cSJohn Marino 	     only update conditions for locations that are marked
12676*ef5ccd6cSJohn Marino 	     "needs_update".  */
12677*ef5ccd6cSJohn Marino 	  update_inserted_breakpoint_locations ();
12678*ef5ccd6cSJohn Marino 	}
12679*ef5ccd6cSJohn Marino     }
126805796c8dcSSimon Schubert 
12681a45ae5f8SJohn Marino   if (should_insert)
12682a45ae5f8SJohn Marino     download_tracepoint_locations ();
12683a45ae5f8SJohn Marino 
126845796c8dcSSimon Schubert   do_cleanups (cleanups);
126855796c8dcSSimon Schubert }
126865796c8dcSSimon Schubert 
126875796c8dcSSimon Schubert void
breakpoint_retire_moribund(void)126885796c8dcSSimon Schubert breakpoint_retire_moribund (void)
126895796c8dcSSimon Schubert {
126905796c8dcSSimon Schubert   struct bp_location *loc;
126915796c8dcSSimon Schubert   int ix;
126925796c8dcSSimon Schubert 
126935796c8dcSSimon Schubert   for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
126945796c8dcSSimon Schubert     if (--(loc->events_till_retirement) == 0)
126955796c8dcSSimon Schubert       {
12696c50c785cSJohn Marino 	decref_bp_location (&loc);
126975796c8dcSSimon Schubert 	VEC_unordered_remove (bp_location_p, moribund_locations, ix);
126985796c8dcSSimon Schubert 	--ix;
126995796c8dcSSimon Schubert       }
127005796c8dcSSimon Schubert }
127015796c8dcSSimon Schubert 
127025796c8dcSSimon Schubert static void
update_global_location_list_nothrow(int inserting)127035796c8dcSSimon Schubert update_global_location_list_nothrow (int inserting)
127045796c8dcSSimon Schubert {
12705*ef5ccd6cSJohn Marino   volatile struct gdb_exception e;
12706cf7f2e2dSJohn Marino 
127075796c8dcSSimon Schubert   TRY_CATCH (e, RETURN_MASK_ERROR)
127085796c8dcSSimon Schubert     update_global_location_list (inserting);
127095796c8dcSSimon Schubert }
127105796c8dcSSimon Schubert 
12711c50c785cSJohn Marino /* Clear BKP from a BPS.  */
12712c50c785cSJohn Marino 
127135796c8dcSSimon Schubert static void
bpstat_remove_bp_location(bpstat bps,struct breakpoint * bpt)12714c50c785cSJohn Marino bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
127155796c8dcSSimon Schubert {
127165796c8dcSSimon Schubert   bpstat bs;
12717cf7f2e2dSJohn Marino 
127185796c8dcSSimon Schubert   for (bs = bps; bs; bs = bs->next)
12719c50c785cSJohn Marino     if (bs->breakpoint_at == bpt)
127205796c8dcSSimon Schubert       {
127215796c8dcSSimon Schubert 	bs->breakpoint_at = NULL;
127225796c8dcSSimon Schubert 	bs->old_val = NULL;
127235796c8dcSSimon Schubert 	/* bs->commands will be freed later.  */
127245796c8dcSSimon Schubert       }
127255796c8dcSSimon Schubert }
127265796c8dcSSimon Schubert 
127275796c8dcSSimon Schubert /* Callback for iterate_over_threads.  */
127285796c8dcSSimon Schubert static int
bpstat_remove_breakpoint_callback(struct thread_info * th,void * data)12729c50c785cSJohn Marino bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
127305796c8dcSSimon Schubert {
12731c50c785cSJohn Marino   struct breakpoint *bpt = data;
12732cf7f2e2dSJohn Marino 
12733c50c785cSJohn Marino   bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
127345796c8dcSSimon Schubert   return 0;
127355796c8dcSSimon Schubert }
127365796c8dcSSimon Schubert 
12737a45ae5f8SJohn Marino /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12738a45ae5f8SJohn Marino    callbacks.  */
12739a45ae5f8SJohn Marino 
12740a45ae5f8SJohn Marino static void
say_where(struct breakpoint * b)12741a45ae5f8SJohn Marino say_where (struct breakpoint *b)
12742a45ae5f8SJohn Marino {
12743a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
12744a45ae5f8SJohn Marino   struct value_print_options opts;
12745a45ae5f8SJohn Marino 
12746a45ae5f8SJohn Marino   get_user_print_options (&opts);
12747a45ae5f8SJohn Marino 
12748a45ae5f8SJohn Marino   /* i18n: cagney/2005-02-11: Below needs to be merged into a
12749a45ae5f8SJohn Marino      single string.  */
12750a45ae5f8SJohn Marino   if (b->loc == NULL)
12751a45ae5f8SJohn Marino     {
12752a45ae5f8SJohn Marino       printf_filtered (_(" (%s) pending."), b->addr_string);
12753a45ae5f8SJohn Marino     }
12754a45ae5f8SJohn Marino   else
12755a45ae5f8SJohn Marino     {
12756*ef5ccd6cSJohn Marino       if (opts.addressprint || b->loc->symtab == NULL)
12757a45ae5f8SJohn Marino 	{
12758a45ae5f8SJohn Marino 	  printf_filtered (" at ");
12759a45ae5f8SJohn Marino 	  fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12760a45ae5f8SJohn Marino 			  gdb_stdout);
12761a45ae5f8SJohn Marino 	}
12762*ef5ccd6cSJohn Marino       if (b->loc->symtab != NULL)
12763a45ae5f8SJohn Marino 	{
12764a45ae5f8SJohn Marino 	  /* If there is a single location, we can print the location
12765a45ae5f8SJohn Marino 	     more nicely.  */
12766a45ae5f8SJohn Marino 	  if (b->loc->next == NULL)
12767a45ae5f8SJohn Marino 	    printf_filtered (": file %s, line %d.",
12768*ef5ccd6cSJohn Marino 			     symtab_to_filename_for_display (b->loc->symtab),
12769*ef5ccd6cSJohn Marino 			     b->loc->line_number);
12770a45ae5f8SJohn Marino 	  else
12771a45ae5f8SJohn Marino 	    /* This is not ideal, but each location may have a
12772a45ae5f8SJohn Marino 	       different file name, and this at least reflects the
12773a45ae5f8SJohn Marino 	       real situation somewhat.  */
12774a45ae5f8SJohn Marino 	    printf_filtered (": %s.", b->addr_string);
12775a45ae5f8SJohn Marino 	}
12776a45ae5f8SJohn Marino 
12777a45ae5f8SJohn Marino       if (b->loc->next)
12778a45ae5f8SJohn Marino 	{
12779a45ae5f8SJohn Marino 	  struct bp_location *loc = b->loc;
12780a45ae5f8SJohn Marino 	  int n = 0;
12781a45ae5f8SJohn Marino 	  for (; loc; loc = loc->next)
12782a45ae5f8SJohn Marino 	    ++n;
12783a45ae5f8SJohn Marino 	  printf_filtered (" (%d locations)", n);
12784a45ae5f8SJohn Marino 	}
12785a45ae5f8SJohn Marino     }
12786a45ae5f8SJohn Marino }
12787a45ae5f8SJohn Marino 
12788a45ae5f8SJohn Marino /* Default bp_location_ops methods.  */
12789a45ae5f8SJohn Marino 
12790a45ae5f8SJohn Marino static void
bp_location_dtor(struct bp_location * self)12791a45ae5f8SJohn Marino bp_location_dtor (struct bp_location *self)
12792a45ae5f8SJohn Marino {
12793a45ae5f8SJohn Marino   xfree (self->cond);
12794*ef5ccd6cSJohn Marino   if (self->cond_bytecode)
12795*ef5ccd6cSJohn Marino     free_agent_expr (self->cond_bytecode);
12796a45ae5f8SJohn Marino   xfree (self->function_name);
12797a45ae5f8SJohn Marino }
12798a45ae5f8SJohn Marino 
12799a45ae5f8SJohn Marino static const struct bp_location_ops bp_location_ops =
12800a45ae5f8SJohn Marino {
12801a45ae5f8SJohn Marino   bp_location_dtor
12802a45ae5f8SJohn Marino };
12803a45ae5f8SJohn Marino 
12804a45ae5f8SJohn Marino /* Default breakpoint_ops methods all breakpoint_ops ultimately
12805a45ae5f8SJohn Marino    inherit from.  */
12806a45ae5f8SJohn Marino 
12807a45ae5f8SJohn Marino static void
base_breakpoint_dtor(struct breakpoint * self)12808a45ae5f8SJohn Marino base_breakpoint_dtor (struct breakpoint *self)
12809a45ae5f8SJohn Marino {
12810a45ae5f8SJohn Marino   decref_counted_command_line (&self->commands);
12811a45ae5f8SJohn Marino   xfree (self->cond_string);
12812a45ae5f8SJohn Marino   xfree (self->addr_string);
12813a45ae5f8SJohn Marino   xfree (self->filter);
12814a45ae5f8SJohn Marino   xfree (self->addr_string_range_end);
12815a45ae5f8SJohn Marino }
12816a45ae5f8SJohn Marino 
12817a45ae5f8SJohn Marino static struct bp_location *
base_breakpoint_allocate_location(struct breakpoint * self)12818a45ae5f8SJohn Marino base_breakpoint_allocate_location (struct breakpoint *self)
12819a45ae5f8SJohn Marino {
12820a45ae5f8SJohn Marino   struct bp_location *loc;
12821a45ae5f8SJohn Marino 
12822a45ae5f8SJohn Marino   loc = XNEW (struct bp_location);
12823a45ae5f8SJohn Marino   init_bp_location (loc, &bp_location_ops, self);
12824a45ae5f8SJohn Marino   return loc;
12825a45ae5f8SJohn Marino }
12826a45ae5f8SJohn Marino 
12827a45ae5f8SJohn Marino static void
base_breakpoint_re_set(struct breakpoint * b)12828a45ae5f8SJohn Marino base_breakpoint_re_set (struct breakpoint *b)
12829a45ae5f8SJohn Marino {
12830a45ae5f8SJohn Marino   /* Nothing to re-set. */
12831a45ae5f8SJohn Marino }
12832a45ae5f8SJohn Marino 
12833a45ae5f8SJohn Marino #define internal_error_pure_virtual_called() \
12834a45ae5f8SJohn Marino   gdb_assert_not_reached ("pure virtual function called")
12835a45ae5f8SJohn Marino 
12836a45ae5f8SJohn Marino static int
base_breakpoint_insert_location(struct bp_location * bl)12837a45ae5f8SJohn Marino base_breakpoint_insert_location (struct bp_location *bl)
12838a45ae5f8SJohn Marino {
12839a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12840a45ae5f8SJohn Marino }
12841a45ae5f8SJohn Marino 
12842a45ae5f8SJohn Marino static int
base_breakpoint_remove_location(struct bp_location * bl)12843a45ae5f8SJohn Marino base_breakpoint_remove_location (struct bp_location *bl)
12844a45ae5f8SJohn Marino {
12845a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12846a45ae5f8SJohn Marino }
12847a45ae5f8SJohn Marino 
12848a45ae5f8SJohn Marino static int
base_breakpoint_breakpoint_hit(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)12849a45ae5f8SJohn Marino base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12850a45ae5f8SJohn Marino 				struct address_space *aspace,
12851*ef5ccd6cSJohn Marino 				CORE_ADDR bp_addr,
12852*ef5ccd6cSJohn Marino 				const struct target_waitstatus *ws)
12853a45ae5f8SJohn Marino {
12854a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12855a45ae5f8SJohn Marino }
12856a45ae5f8SJohn Marino 
12857a45ae5f8SJohn Marino static void
base_breakpoint_check_status(bpstat bs)12858a45ae5f8SJohn Marino base_breakpoint_check_status (bpstat bs)
12859a45ae5f8SJohn Marino {
12860a45ae5f8SJohn Marino   /* Always stop.   */
12861a45ae5f8SJohn Marino }
12862a45ae5f8SJohn Marino 
12863a45ae5f8SJohn Marino /* A "works_in_software_mode" breakpoint_ops method that just internal
12864a45ae5f8SJohn Marino    errors.  */
12865a45ae5f8SJohn Marino 
12866a45ae5f8SJohn Marino static int
base_breakpoint_works_in_software_mode(const struct breakpoint * b)12867a45ae5f8SJohn Marino base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12868a45ae5f8SJohn Marino {
12869a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12870a45ae5f8SJohn Marino }
12871a45ae5f8SJohn Marino 
12872a45ae5f8SJohn Marino /* A "resources_needed" breakpoint_ops method that just internal
12873a45ae5f8SJohn Marino    errors.  */
12874a45ae5f8SJohn Marino 
12875a45ae5f8SJohn Marino static int
base_breakpoint_resources_needed(const struct bp_location * bl)12876a45ae5f8SJohn Marino base_breakpoint_resources_needed (const struct bp_location *bl)
12877a45ae5f8SJohn Marino {
12878a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12879a45ae5f8SJohn Marino }
12880a45ae5f8SJohn Marino 
12881a45ae5f8SJohn Marino static enum print_stop_action
base_breakpoint_print_it(bpstat bs)12882a45ae5f8SJohn Marino base_breakpoint_print_it (bpstat bs)
12883a45ae5f8SJohn Marino {
12884a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12885a45ae5f8SJohn Marino }
12886a45ae5f8SJohn Marino 
12887a45ae5f8SJohn Marino static void
base_breakpoint_print_one_detail(const struct breakpoint * self,struct ui_out * uiout)12888a45ae5f8SJohn Marino base_breakpoint_print_one_detail (const struct breakpoint *self,
12889a45ae5f8SJohn Marino 				  struct ui_out *uiout)
12890a45ae5f8SJohn Marino {
12891a45ae5f8SJohn Marino   /* nothing */
12892a45ae5f8SJohn Marino }
12893a45ae5f8SJohn Marino 
12894a45ae5f8SJohn Marino static void
base_breakpoint_print_mention(struct breakpoint * b)12895a45ae5f8SJohn Marino base_breakpoint_print_mention (struct breakpoint *b)
12896a45ae5f8SJohn Marino {
12897a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12898a45ae5f8SJohn Marino }
12899a45ae5f8SJohn Marino 
12900a45ae5f8SJohn Marino static void
base_breakpoint_print_recreate(struct breakpoint * b,struct ui_file * fp)12901a45ae5f8SJohn Marino base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12902a45ae5f8SJohn Marino {
12903a45ae5f8SJohn Marino   internal_error_pure_virtual_called ();
12904a45ae5f8SJohn Marino }
12905a45ae5f8SJohn Marino 
12906*ef5ccd6cSJohn Marino static void
base_breakpoint_create_sals_from_address(char ** arg,struct linespec_result * canonical,enum bptype type_wanted,char * addr_start,char ** copy_arg)12907*ef5ccd6cSJohn Marino base_breakpoint_create_sals_from_address (char **arg,
12908*ef5ccd6cSJohn Marino 					  struct linespec_result *canonical,
12909*ef5ccd6cSJohn Marino 					  enum bptype type_wanted,
12910*ef5ccd6cSJohn Marino 					  char *addr_start,
12911*ef5ccd6cSJohn Marino 					  char **copy_arg)
12912*ef5ccd6cSJohn Marino {
12913*ef5ccd6cSJohn Marino   internal_error_pure_virtual_called ();
12914*ef5ccd6cSJohn Marino }
12915*ef5ccd6cSJohn Marino 
12916*ef5ccd6cSJohn Marino static void
base_breakpoint_create_breakpoints_sal(struct gdbarch * gdbarch,struct linespec_result * c,struct linespec_sals * lsal,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)12917*ef5ccd6cSJohn Marino base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12918*ef5ccd6cSJohn Marino 					struct linespec_result *c,
12919*ef5ccd6cSJohn Marino 					struct linespec_sals *lsal,
12920*ef5ccd6cSJohn Marino 					char *cond_string,
12921*ef5ccd6cSJohn Marino 					char *extra_string,
12922*ef5ccd6cSJohn Marino 					enum bptype type_wanted,
12923*ef5ccd6cSJohn Marino 					enum bpdisp disposition,
12924*ef5ccd6cSJohn Marino 					int thread,
12925*ef5ccd6cSJohn Marino 					int task, int ignore_count,
12926*ef5ccd6cSJohn Marino 					const struct breakpoint_ops *o,
12927*ef5ccd6cSJohn Marino 					int from_tty, int enabled,
12928*ef5ccd6cSJohn Marino 					int internal, unsigned flags)
12929*ef5ccd6cSJohn Marino {
12930*ef5ccd6cSJohn Marino   internal_error_pure_virtual_called ();
12931*ef5ccd6cSJohn Marino }
12932*ef5ccd6cSJohn Marino 
12933*ef5ccd6cSJohn Marino static void
base_breakpoint_decode_linespec(struct breakpoint * b,char ** s,struct symtabs_and_lines * sals)12934*ef5ccd6cSJohn Marino base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12935*ef5ccd6cSJohn Marino 				 struct symtabs_and_lines *sals)
12936*ef5ccd6cSJohn Marino {
12937*ef5ccd6cSJohn Marino   internal_error_pure_virtual_called ();
12938*ef5ccd6cSJohn Marino }
12939*ef5ccd6cSJohn Marino 
12940*ef5ccd6cSJohn Marino /* The default 'explains_signal' method.  */
12941*ef5ccd6cSJohn Marino 
12942*ef5ccd6cSJohn Marino static enum bpstat_signal_value
base_breakpoint_explains_signal(struct breakpoint * b,enum gdb_signal sig)12943*ef5ccd6cSJohn Marino base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig)
12944*ef5ccd6cSJohn Marino {
12945*ef5ccd6cSJohn Marino   return BPSTAT_SIGNAL_HIDE;
12946*ef5ccd6cSJohn Marino }
12947*ef5ccd6cSJohn Marino 
12948*ef5ccd6cSJohn Marino /* The default "after_condition_true" method.  */
12949*ef5ccd6cSJohn Marino 
12950*ef5ccd6cSJohn Marino static void
base_breakpoint_after_condition_true(struct bpstats * bs)12951*ef5ccd6cSJohn Marino base_breakpoint_after_condition_true (struct bpstats *bs)
12952*ef5ccd6cSJohn Marino {
12953*ef5ccd6cSJohn Marino   /* Nothing to do.   */
12954*ef5ccd6cSJohn Marino }
12955*ef5ccd6cSJohn Marino 
12956*ef5ccd6cSJohn Marino struct breakpoint_ops base_breakpoint_ops =
12957a45ae5f8SJohn Marino {
12958a45ae5f8SJohn Marino   base_breakpoint_dtor,
12959a45ae5f8SJohn Marino   base_breakpoint_allocate_location,
12960a45ae5f8SJohn Marino   base_breakpoint_re_set,
12961a45ae5f8SJohn Marino   base_breakpoint_insert_location,
12962a45ae5f8SJohn Marino   base_breakpoint_remove_location,
12963a45ae5f8SJohn Marino   base_breakpoint_breakpoint_hit,
12964a45ae5f8SJohn Marino   base_breakpoint_check_status,
12965a45ae5f8SJohn Marino   base_breakpoint_resources_needed,
12966a45ae5f8SJohn Marino   base_breakpoint_works_in_software_mode,
12967a45ae5f8SJohn Marino   base_breakpoint_print_it,
12968a45ae5f8SJohn Marino   NULL,
12969a45ae5f8SJohn Marino   base_breakpoint_print_one_detail,
12970a45ae5f8SJohn Marino   base_breakpoint_print_mention,
12971*ef5ccd6cSJohn Marino   base_breakpoint_print_recreate,
12972*ef5ccd6cSJohn Marino   base_breakpoint_create_sals_from_address,
12973*ef5ccd6cSJohn Marino   base_breakpoint_create_breakpoints_sal,
12974*ef5ccd6cSJohn Marino   base_breakpoint_decode_linespec,
12975*ef5ccd6cSJohn Marino   base_breakpoint_explains_signal,
12976*ef5ccd6cSJohn Marino   base_breakpoint_after_condition_true,
12977a45ae5f8SJohn Marino };
12978a45ae5f8SJohn Marino 
12979a45ae5f8SJohn Marino /* Default breakpoint_ops methods.  */
12980a45ae5f8SJohn Marino 
12981a45ae5f8SJohn Marino static void
bkpt_re_set(struct breakpoint * b)12982a45ae5f8SJohn Marino bkpt_re_set (struct breakpoint *b)
12983a45ae5f8SJohn Marino {
12984a45ae5f8SJohn Marino   /* FIXME: is this still reachable?  */
12985a45ae5f8SJohn Marino   if (b->addr_string == NULL)
12986a45ae5f8SJohn Marino     {
12987a45ae5f8SJohn Marino       /* Anything without a string can't be re-set.  */
12988a45ae5f8SJohn Marino       delete_breakpoint (b);
12989a45ae5f8SJohn Marino       return;
12990a45ae5f8SJohn Marino     }
12991a45ae5f8SJohn Marino 
12992a45ae5f8SJohn Marino   breakpoint_re_set_default (b);
12993a45ae5f8SJohn Marino }
12994a45ae5f8SJohn Marino 
12995a45ae5f8SJohn Marino static int
bkpt_insert_location(struct bp_location * bl)12996a45ae5f8SJohn Marino bkpt_insert_location (struct bp_location *bl)
12997a45ae5f8SJohn Marino {
12998a45ae5f8SJohn Marino   if (bl->loc_type == bp_loc_hardware_breakpoint)
12999a45ae5f8SJohn Marino     return target_insert_hw_breakpoint (bl->gdbarch,
13000a45ae5f8SJohn Marino 					&bl->target_info);
13001a45ae5f8SJohn Marino   else
13002a45ae5f8SJohn Marino     return target_insert_breakpoint (bl->gdbarch,
13003a45ae5f8SJohn Marino 				     &bl->target_info);
13004a45ae5f8SJohn Marino }
13005a45ae5f8SJohn Marino 
13006a45ae5f8SJohn Marino static int
bkpt_remove_location(struct bp_location * bl)13007a45ae5f8SJohn Marino bkpt_remove_location (struct bp_location *bl)
13008a45ae5f8SJohn Marino {
13009a45ae5f8SJohn Marino   if (bl->loc_type == bp_loc_hardware_breakpoint)
13010a45ae5f8SJohn Marino     return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
13011a45ae5f8SJohn Marino   else
13012a45ae5f8SJohn Marino     return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
13013a45ae5f8SJohn Marino }
13014a45ae5f8SJohn Marino 
13015a45ae5f8SJohn Marino static int
bkpt_breakpoint_hit(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)13016a45ae5f8SJohn Marino bkpt_breakpoint_hit (const struct bp_location *bl,
13017*ef5ccd6cSJohn Marino 		     struct address_space *aspace, CORE_ADDR bp_addr,
13018*ef5ccd6cSJohn Marino 		     const struct target_waitstatus *ws)
13019a45ae5f8SJohn Marino {
13020a45ae5f8SJohn Marino   struct breakpoint *b = bl->owner;
13021a45ae5f8SJohn Marino 
13022*ef5ccd6cSJohn Marino   if (ws->kind != TARGET_WAITKIND_STOPPED
13023*ef5ccd6cSJohn Marino       || ws->value.sig != GDB_SIGNAL_TRAP)
13024*ef5ccd6cSJohn Marino     return 0;
13025*ef5ccd6cSJohn Marino 
13026a45ae5f8SJohn Marino   if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
13027a45ae5f8SJohn Marino 				 aspace, bp_addr))
13028a45ae5f8SJohn Marino     return 0;
13029a45ae5f8SJohn Marino 
13030a45ae5f8SJohn Marino   if (overlay_debugging		/* unmapped overlay section */
13031a45ae5f8SJohn Marino       && section_is_overlay (bl->section)
13032a45ae5f8SJohn Marino       && !section_is_mapped (bl->section))
13033a45ae5f8SJohn Marino     return 0;
13034a45ae5f8SJohn Marino 
13035a45ae5f8SJohn Marino   return 1;
13036a45ae5f8SJohn Marino }
13037a45ae5f8SJohn Marino 
13038a45ae5f8SJohn Marino static int
bkpt_resources_needed(const struct bp_location * bl)13039a45ae5f8SJohn Marino bkpt_resources_needed (const struct bp_location *bl)
13040a45ae5f8SJohn Marino {
13041a45ae5f8SJohn Marino   gdb_assert (bl->owner->type == bp_hardware_breakpoint);
13042a45ae5f8SJohn Marino 
13043a45ae5f8SJohn Marino   return 1;
13044a45ae5f8SJohn Marino }
13045a45ae5f8SJohn Marino 
13046a45ae5f8SJohn Marino static enum print_stop_action
bkpt_print_it(bpstat bs)13047a45ae5f8SJohn Marino bkpt_print_it (bpstat bs)
13048a45ae5f8SJohn Marino {
13049a45ae5f8SJohn Marino   struct breakpoint *b;
13050a45ae5f8SJohn Marino   const struct bp_location *bl;
13051a45ae5f8SJohn Marino   int bp_temp;
13052a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
13053a45ae5f8SJohn Marino 
13054a45ae5f8SJohn Marino   gdb_assert (bs->bp_location_at != NULL);
13055a45ae5f8SJohn Marino 
13056a45ae5f8SJohn Marino   bl = bs->bp_location_at;
13057a45ae5f8SJohn Marino   b = bs->breakpoint_at;
13058a45ae5f8SJohn Marino 
13059a45ae5f8SJohn Marino   bp_temp = b->disposition == disp_del;
13060a45ae5f8SJohn Marino   if (bl->address != bl->requested_address)
13061a45ae5f8SJohn Marino     breakpoint_adjustment_warning (bl->requested_address,
13062a45ae5f8SJohn Marino 				   bl->address,
13063a45ae5f8SJohn Marino 				   b->number, 1);
13064a45ae5f8SJohn Marino   annotate_breakpoint (b->number);
13065a45ae5f8SJohn Marino   if (bp_temp)
13066a45ae5f8SJohn Marino     ui_out_text (uiout, "\nTemporary breakpoint ");
13067a45ae5f8SJohn Marino   else
13068a45ae5f8SJohn Marino     ui_out_text (uiout, "\nBreakpoint ");
13069a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (uiout))
13070a45ae5f8SJohn Marino     {
13071a45ae5f8SJohn Marino       ui_out_field_string (uiout, "reason",
13072a45ae5f8SJohn Marino 			   async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
13073a45ae5f8SJohn Marino       ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
13074a45ae5f8SJohn Marino     }
13075a45ae5f8SJohn Marino   ui_out_field_int (uiout, "bkptno", b->number);
13076a45ae5f8SJohn Marino   ui_out_text (uiout, ", ");
13077a45ae5f8SJohn Marino 
13078a45ae5f8SJohn Marino   return PRINT_SRC_AND_LOC;
13079a45ae5f8SJohn Marino }
13080a45ae5f8SJohn Marino 
13081a45ae5f8SJohn Marino static void
bkpt_print_mention(struct breakpoint * b)13082a45ae5f8SJohn Marino bkpt_print_mention (struct breakpoint *b)
13083a45ae5f8SJohn Marino {
13084a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (current_uiout))
13085a45ae5f8SJohn Marino     return;
13086a45ae5f8SJohn Marino 
13087a45ae5f8SJohn Marino   switch (b->type)
13088a45ae5f8SJohn Marino     {
13089a45ae5f8SJohn Marino     case bp_breakpoint:
13090a45ae5f8SJohn Marino     case bp_gnu_ifunc_resolver:
13091a45ae5f8SJohn Marino       if (b->disposition == disp_del)
13092a45ae5f8SJohn Marino 	printf_filtered (_("Temporary breakpoint"));
13093a45ae5f8SJohn Marino       else
13094a45ae5f8SJohn Marino 	printf_filtered (_("Breakpoint"));
13095a45ae5f8SJohn Marino       printf_filtered (_(" %d"), b->number);
13096a45ae5f8SJohn Marino       if (b->type == bp_gnu_ifunc_resolver)
13097a45ae5f8SJohn Marino 	printf_filtered (_(" at gnu-indirect-function resolver"));
13098a45ae5f8SJohn Marino       break;
13099a45ae5f8SJohn Marino     case bp_hardware_breakpoint:
13100a45ae5f8SJohn Marino       printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
13101a45ae5f8SJohn Marino       break;
13102*ef5ccd6cSJohn Marino     case bp_dprintf:
13103*ef5ccd6cSJohn Marino       printf_filtered (_("Dprintf %d"), b->number);
13104*ef5ccd6cSJohn Marino       break;
13105a45ae5f8SJohn Marino     }
13106a45ae5f8SJohn Marino 
13107a45ae5f8SJohn Marino   say_where (b);
13108a45ae5f8SJohn Marino }
13109a45ae5f8SJohn Marino 
13110a45ae5f8SJohn Marino static void
bkpt_print_recreate(struct breakpoint * tp,struct ui_file * fp)13111a45ae5f8SJohn Marino bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13112a45ae5f8SJohn Marino {
13113a45ae5f8SJohn Marino   if (tp->type == bp_breakpoint && tp->disposition == disp_del)
13114a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "tbreak");
13115a45ae5f8SJohn Marino   else if (tp->type == bp_breakpoint)
13116a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "break");
13117a45ae5f8SJohn Marino   else if (tp->type == bp_hardware_breakpoint
13118a45ae5f8SJohn Marino 	   && tp->disposition == disp_del)
13119a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "thbreak");
13120a45ae5f8SJohn Marino   else if (tp->type == bp_hardware_breakpoint)
13121a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "hbreak");
13122a45ae5f8SJohn Marino   else
13123a45ae5f8SJohn Marino     internal_error (__FILE__, __LINE__,
13124a45ae5f8SJohn Marino 		    _("unhandled breakpoint type %d"), (int) tp->type);
13125a45ae5f8SJohn Marino 
13126a45ae5f8SJohn Marino   fprintf_unfiltered (fp, " %s", tp->addr_string);
13127a45ae5f8SJohn Marino   print_recreate_thread (tp, fp);
13128a45ae5f8SJohn Marino }
13129a45ae5f8SJohn Marino 
13130*ef5ccd6cSJohn Marino static void
bkpt_create_sals_from_address(char ** arg,struct linespec_result * canonical,enum bptype type_wanted,char * addr_start,char ** copy_arg)13131*ef5ccd6cSJohn Marino bkpt_create_sals_from_address (char **arg,
13132*ef5ccd6cSJohn Marino 			       struct linespec_result *canonical,
13133*ef5ccd6cSJohn Marino 			       enum bptype type_wanted,
13134*ef5ccd6cSJohn Marino 			       char *addr_start, char **copy_arg)
13135*ef5ccd6cSJohn Marino {
13136*ef5ccd6cSJohn Marino   create_sals_from_address_default (arg, canonical, type_wanted,
13137*ef5ccd6cSJohn Marino 				    addr_start, copy_arg);
13138*ef5ccd6cSJohn Marino }
13139*ef5ccd6cSJohn Marino 
13140*ef5ccd6cSJohn Marino static void
bkpt_create_breakpoints_sal(struct gdbarch * gdbarch,struct linespec_result * canonical,struct linespec_sals * lsal,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)13141*ef5ccd6cSJohn Marino bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
13142*ef5ccd6cSJohn Marino 			     struct linespec_result *canonical,
13143*ef5ccd6cSJohn Marino 			     struct linespec_sals *lsal,
13144*ef5ccd6cSJohn Marino 			     char *cond_string,
13145*ef5ccd6cSJohn Marino 			     char *extra_string,
13146*ef5ccd6cSJohn Marino 			     enum bptype type_wanted,
13147*ef5ccd6cSJohn Marino 			     enum bpdisp disposition,
13148*ef5ccd6cSJohn Marino 			     int thread,
13149*ef5ccd6cSJohn Marino 			     int task, int ignore_count,
13150*ef5ccd6cSJohn Marino 			     const struct breakpoint_ops *ops,
13151*ef5ccd6cSJohn Marino 			     int from_tty, int enabled,
13152*ef5ccd6cSJohn Marino 			     int internal, unsigned flags)
13153*ef5ccd6cSJohn Marino {
13154*ef5ccd6cSJohn Marino   create_breakpoints_sal_default (gdbarch, canonical, lsal,
13155*ef5ccd6cSJohn Marino 				  cond_string, extra_string,
13156*ef5ccd6cSJohn Marino 				  type_wanted,
13157*ef5ccd6cSJohn Marino 				  disposition, thread, task,
13158*ef5ccd6cSJohn Marino 				  ignore_count, ops, from_tty,
13159*ef5ccd6cSJohn Marino 				  enabled, internal, flags);
13160*ef5ccd6cSJohn Marino }
13161*ef5ccd6cSJohn Marino 
13162*ef5ccd6cSJohn Marino static void
bkpt_decode_linespec(struct breakpoint * b,char ** s,struct symtabs_and_lines * sals)13163*ef5ccd6cSJohn Marino bkpt_decode_linespec (struct breakpoint *b, char **s,
13164*ef5ccd6cSJohn Marino 		      struct symtabs_and_lines *sals)
13165*ef5ccd6cSJohn Marino {
13166*ef5ccd6cSJohn Marino   decode_linespec_default (b, s, sals);
13167*ef5ccd6cSJohn Marino }
13168*ef5ccd6cSJohn Marino 
13169a45ae5f8SJohn Marino /* Virtual table for internal breakpoints.  */
13170a45ae5f8SJohn Marino 
13171a45ae5f8SJohn Marino static void
internal_bkpt_re_set(struct breakpoint * b)13172a45ae5f8SJohn Marino internal_bkpt_re_set (struct breakpoint *b)
13173a45ae5f8SJohn Marino {
13174a45ae5f8SJohn Marino   switch (b->type)
13175a45ae5f8SJohn Marino     {
13176a45ae5f8SJohn Marino       /* Delete overlay event and longjmp master breakpoints; they
13177a45ae5f8SJohn Marino 	 will be reset later by breakpoint_re_set.  */
13178a45ae5f8SJohn Marino     case bp_overlay_event:
13179a45ae5f8SJohn Marino     case bp_longjmp_master:
13180a45ae5f8SJohn Marino     case bp_std_terminate_master:
13181a45ae5f8SJohn Marino     case bp_exception_master:
13182a45ae5f8SJohn Marino       delete_breakpoint (b);
13183a45ae5f8SJohn Marino       break;
13184a45ae5f8SJohn Marino 
13185a45ae5f8SJohn Marino       /* This breakpoint is special, it's set up when the inferior
13186a45ae5f8SJohn Marino          starts and we really don't want to touch it.  */
13187a45ae5f8SJohn Marino     case bp_shlib_event:
13188a45ae5f8SJohn Marino 
13189a45ae5f8SJohn Marino       /* Like bp_shlib_event, this breakpoint type is special.  Once
13190a45ae5f8SJohn Marino 	 it is set up, we do not want to touch it.  */
13191a45ae5f8SJohn Marino     case bp_thread_event:
13192a45ae5f8SJohn Marino       break;
13193a45ae5f8SJohn Marino     }
13194a45ae5f8SJohn Marino }
13195a45ae5f8SJohn Marino 
13196a45ae5f8SJohn Marino static void
internal_bkpt_check_status(bpstat bs)13197a45ae5f8SJohn Marino internal_bkpt_check_status (bpstat bs)
13198a45ae5f8SJohn Marino {
13199*ef5ccd6cSJohn Marino   if (bs->breakpoint_at->type == bp_shlib_event)
13200*ef5ccd6cSJohn Marino     {
13201*ef5ccd6cSJohn Marino       /* If requested, stop when the dynamic linker notifies GDB of
13202*ef5ccd6cSJohn Marino 	 events.  This allows the user to get control and place
13203*ef5ccd6cSJohn Marino 	 breakpoints in initializer routines for dynamically loaded
13204*ef5ccd6cSJohn Marino 	 objects (among other things).  */
13205*ef5ccd6cSJohn Marino       bs->stop = stop_on_solib_events;
13206*ef5ccd6cSJohn Marino       bs->print = stop_on_solib_events;
13207*ef5ccd6cSJohn Marino     }
13208*ef5ccd6cSJohn Marino   else
13209a45ae5f8SJohn Marino     bs->stop = 0;
13210a45ae5f8SJohn Marino }
13211a45ae5f8SJohn Marino 
13212a45ae5f8SJohn Marino static enum print_stop_action
internal_bkpt_print_it(bpstat bs)13213a45ae5f8SJohn Marino internal_bkpt_print_it (bpstat bs)
13214a45ae5f8SJohn Marino {
13215a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
13216a45ae5f8SJohn Marino   struct breakpoint *b;
13217a45ae5f8SJohn Marino 
13218a45ae5f8SJohn Marino   b = bs->breakpoint_at;
13219a45ae5f8SJohn Marino 
13220a45ae5f8SJohn Marino   switch (b->type)
13221a45ae5f8SJohn Marino     {
13222a45ae5f8SJohn Marino     case bp_shlib_event:
13223a45ae5f8SJohn Marino       /* Did we stop because the user set the stop_on_solib_events
13224a45ae5f8SJohn Marino 	 variable?  (If so, we report this as a generic, "Stopped due
13225a45ae5f8SJohn Marino 	 to shlib event" message.) */
13226*ef5ccd6cSJohn Marino       print_solib_event (0);
13227a45ae5f8SJohn Marino       break;
13228a45ae5f8SJohn Marino 
13229a45ae5f8SJohn Marino     case bp_thread_event:
13230a45ae5f8SJohn Marino       /* Not sure how we will get here.
13231a45ae5f8SJohn Marino 	 GDB should not stop for these breakpoints.  */
13232a45ae5f8SJohn Marino       printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13233a45ae5f8SJohn Marino       break;
13234a45ae5f8SJohn Marino 
13235a45ae5f8SJohn Marino     case bp_overlay_event:
13236a45ae5f8SJohn Marino       /* By analogy with the thread event, GDB should not stop for these.  */
13237a45ae5f8SJohn Marino       printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13238a45ae5f8SJohn Marino       break;
13239a45ae5f8SJohn Marino 
13240a45ae5f8SJohn Marino     case bp_longjmp_master:
13241a45ae5f8SJohn Marino       /* These should never be enabled.  */
13242a45ae5f8SJohn Marino       printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13243a45ae5f8SJohn Marino       break;
13244a45ae5f8SJohn Marino 
13245a45ae5f8SJohn Marino     case bp_std_terminate_master:
13246a45ae5f8SJohn Marino       /* These should never be enabled.  */
13247a45ae5f8SJohn Marino       printf_filtered (_("std::terminate Master Breakpoint: "
13248a45ae5f8SJohn Marino 			 "gdb should not stop!\n"));
13249a45ae5f8SJohn Marino       break;
13250a45ae5f8SJohn Marino 
13251a45ae5f8SJohn Marino     case bp_exception_master:
13252a45ae5f8SJohn Marino       /* These should never be enabled.  */
13253a45ae5f8SJohn Marino       printf_filtered (_("Exception Master Breakpoint: "
13254a45ae5f8SJohn Marino 			 "gdb should not stop!\n"));
13255a45ae5f8SJohn Marino       break;
13256a45ae5f8SJohn Marino     }
13257a45ae5f8SJohn Marino 
13258a45ae5f8SJohn Marino   return PRINT_NOTHING;
13259a45ae5f8SJohn Marino }
13260a45ae5f8SJohn Marino 
13261a45ae5f8SJohn Marino static void
internal_bkpt_print_mention(struct breakpoint * b)13262a45ae5f8SJohn Marino internal_bkpt_print_mention (struct breakpoint *b)
13263a45ae5f8SJohn Marino {
13264a45ae5f8SJohn Marino   /* Nothing to mention.  These breakpoints are internal.  */
13265a45ae5f8SJohn Marino }
13266a45ae5f8SJohn Marino 
13267a45ae5f8SJohn Marino /* Virtual table for momentary breakpoints  */
13268a45ae5f8SJohn Marino 
13269a45ae5f8SJohn Marino static void
momentary_bkpt_re_set(struct breakpoint * b)13270a45ae5f8SJohn Marino momentary_bkpt_re_set (struct breakpoint *b)
13271a45ae5f8SJohn Marino {
13272a45ae5f8SJohn Marino   /* Keep temporary breakpoints, which can be encountered when we step
13273a45ae5f8SJohn Marino      over a dlopen call and SOLIB_ADD is resetting the breakpoints.
13274a45ae5f8SJohn Marino      Otherwise these should have been blown away via the cleanup chain
13275a45ae5f8SJohn Marino      or by breakpoint_init_inferior when we rerun the executable.  */
13276a45ae5f8SJohn Marino }
13277a45ae5f8SJohn Marino 
13278a45ae5f8SJohn Marino static void
momentary_bkpt_check_status(bpstat bs)13279a45ae5f8SJohn Marino momentary_bkpt_check_status (bpstat bs)
13280a45ae5f8SJohn Marino {
13281a45ae5f8SJohn Marino   /* Nothing.  The point of these breakpoints is causing a stop.  */
13282a45ae5f8SJohn Marino }
13283a45ae5f8SJohn Marino 
13284a45ae5f8SJohn Marino static enum print_stop_action
momentary_bkpt_print_it(bpstat bs)13285a45ae5f8SJohn Marino momentary_bkpt_print_it (bpstat bs)
13286a45ae5f8SJohn Marino {
13287a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
13288a45ae5f8SJohn Marino 
13289a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (uiout))
13290a45ae5f8SJohn Marino     {
13291a45ae5f8SJohn Marino       struct breakpoint *b = bs->breakpoint_at;
13292a45ae5f8SJohn Marino 
13293a45ae5f8SJohn Marino       switch (b->type)
13294a45ae5f8SJohn Marino 	{
13295a45ae5f8SJohn Marino 	case bp_finish:
13296a45ae5f8SJohn Marino 	  ui_out_field_string
13297a45ae5f8SJohn Marino 	    (uiout, "reason",
13298a45ae5f8SJohn Marino 	     async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
13299a45ae5f8SJohn Marino 	  break;
13300a45ae5f8SJohn Marino 
13301a45ae5f8SJohn Marino 	case bp_until:
13302a45ae5f8SJohn Marino 	  ui_out_field_string
13303a45ae5f8SJohn Marino 	    (uiout, "reason",
13304a45ae5f8SJohn Marino 	     async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
13305a45ae5f8SJohn Marino 	  break;
13306a45ae5f8SJohn Marino 	}
13307a45ae5f8SJohn Marino     }
13308a45ae5f8SJohn Marino 
13309a45ae5f8SJohn Marino   return PRINT_UNKNOWN;
13310a45ae5f8SJohn Marino }
13311a45ae5f8SJohn Marino 
13312a45ae5f8SJohn Marino static void
momentary_bkpt_print_mention(struct breakpoint * b)13313a45ae5f8SJohn Marino momentary_bkpt_print_mention (struct breakpoint *b)
13314a45ae5f8SJohn Marino {
13315a45ae5f8SJohn Marino   /* Nothing to mention.  These breakpoints are internal.  */
13316a45ae5f8SJohn Marino }
13317a45ae5f8SJohn Marino 
13318*ef5ccd6cSJohn Marino /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13319*ef5ccd6cSJohn Marino 
13320*ef5ccd6cSJohn Marino    It gets cleared already on the removal of the first one of such placed
13321*ef5ccd6cSJohn Marino    breakpoints.  This is OK as they get all removed altogether.  */
13322*ef5ccd6cSJohn Marino 
13323*ef5ccd6cSJohn Marino static void
longjmp_bkpt_dtor(struct breakpoint * self)13324*ef5ccd6cSJohn Marino longjmp_bkpt_dtor (struct breakpoint *self)
13325*ef5ccd6cSJohn Marino {
13326*ef5ccd6cSJohn Marino   struct thread_info *tp = find_thread_id (self->thread);
13327*ef5ccd6cSJohn Marino 
13328*ef5ccd6cSJohn Marino   if (tp)
13329*ef5ccd6cSJohn Marino     tp->initiating_frame = null_frame_id;
13330*ef5ccd6cSJohn Marino 
13331*ef5ccd6cSJohn Marino   momentary_breakpoint_ops.dtor (self);
13332*ef5ccd6cSJohn Marino }
13333*ef5ccd6cSJohn Marino 
13334*ef5ccd6cSJohn Marino /* Specific methods for probe breakpoints.  */
13335*ef5ccd6cSJohn Marino 
13336*ef5ccd6cSJohn Marino static int
bkpt_probe_insert_location(struct bp_location * bl)13337*ef5ccd6cSJohn Marino bkpt_probe_insert_location (struct bp_location *bl)
13338*ef5ccd6cSJohn Marino {
13339*ef5ccd6cSJohn Marino   int v = bkpt_insert_location (bl);
13340*ef5ccd6cSJohn Marino 
13341*ef5ccd6cSJohn Marino   if (v == 0)
13342*ef5ccd6cSJohn Marino     {
13343*ef5ccd6cSJohn Marino       /* The insertion was successful, now let's set the probe's semaphore
13344*ef5ccd6cSJohn Marino 	 if needed.  */
13345*ef5ccd6cSJohn Marino       bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
13346*ef5ccd6cSJohn Marino     }
13347*ef5ccd6cSJohn Marino 
13348*ef5ccd6cSJohn Marino   return v;
13349*ef5ccd6cSJohn Marino }
13350*ef5ccd6cSJohn Marino 
13351*ef5ccd6cSJohn Marino static int
bkpt_probe_remove_location(struct bp_location * bl)13352*ef5ccd6cSJohn Marino bkpt_probe_remove_location (struct bp_location *bl)
13353*ef5ccd6cSJohn Marino {
13354*ef5ccd6cSJohn Marino   /* Let's clear the semaphore before removing the location.  */
13355*ef5ccd6cSJohn Marino   bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
13356*ef5ccd6cSJohn Marino 
13357*ef5ccd6cSJohn Marino   return bkpt_remove_location (bl);
13358*ef5ccd6cSJohn Marino }
13359*ef5ccd6cSJohn Marino 
13360*ef5ccd6cSJohn Marino static void
bkpt_probe_create_sals_from_address(char ** arg,struct linespec_result * canonical,enum bptype type_wanted,char * addr_start,char ** copy_arg)13361*ef5ccd6cSJohn Marino bkpt_probe_create_sals_from_address (char **arg,
13362*ef5ccd6cSJohn Marino 				     struct linespec_result *canonical,
13363*ef5ccd6cSJohn Marino 				     enum bptype type_wanted,
13364*ef5ccd6cSJohn Marino 				     char *addr_start, char **copy_arg)
13365*ef5ccd6cSJohn Marino {
13366*ef5ccd6cSJohn Marino   struct linespec_sals lsal;
13367*ef5ccd6cSJohn Marino 
13368*ef5ccd6cSJohn Marino   lsal.sals = parse_probes (arg, canonical);
13369*ef5ccd6cSJohn Marino 
13370*ef5ccd6cSJohn Marino   *copy_arg = xstrdup (canonical->addr_string);
13371*ef5ccd6cSJohn Marino   lsal.canonical = xstrdup (*copy_arg);
13372*ef5ccd6cSJohn Marino 
13373*ef5ccd6cSJohn Marino   VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13374*ef5ccd6cSJohn Marino }
13375*ef5ccd6cSJohn Marino 
13376*ef5ccd6cSJohn Marino static void
bkpt_probe_decode_linespec(struct breakpoint * b,char ** s,struct symtabs_and_lines * sals)13377*ef5ccd6cSJohn Marino bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
13378*ef5ccd6cSJohn Marino 			    struct symtabs_and_lines *sals)
13379*ef5ccd6cSJohn Marino {
13380*ef5ccd6cSJohn Marino   *sals = parse_probes (s, NULL);
13381*ef5ccd6cSJohn Marino   if (!sals->sals)
13382*ef5ccd6cSJohn Marino     error (_("probe not found"));
13383*ef5ccd6cSJohn Marino }
13384*ef5ccd6cSJohn Marino 
13385a45ae5f8SJohn Marino /* The breakpoint_ops structure to be used in tracepoints.  */
13386a45ae5f8SJohn Marino 
13387a45ae5f8SJohn Marino static void
tracepoint_re_set(struct breakpoint * b)13388a45ae5f8SJohn Marino tracepoint_re_set (struct breakpoint *b)
13389a45ae5f8SJohn Marino {
13390a45ae5f8SJohn Marino   breakpoint_re_set_default (b);
13391a45ae5f8SJohn Marino }
13392a45ae5f8SJohn Marino 
13393a45ae5f8SJohn Marino static int
tracepoint_breakpoint_hit(const struct bp_location * bl,struct address_space * aspace,CORE_ADDR bp_addr,const struct target_waitstatus * ws)13394a45ae5f8SJohn Marino tracepoint_breakpoint_hit (const struct bp_location *bl,
13395*ef5ccd6cSJohn Marino 			   struct address_space *aspace, CORE_ADDR bp_addr,
13396*ef5ccd6cSJohn Marino 			   const struct target_waitstatus *ws)
13397a45ae5f8SJohn Marino {
13398a45ae5f8SJohn Marino   /* By definition, the inferior does not report stops at
13399a45ae5f8SJohn Marino      tracepoints.  */
13400a45ae5f8SJohn Marino   return 0;
13401a45ae5f8SJohn Marino }
13402a45ae5f8SJohn Marino 
13403a45ae5f8SJohn Marino static void
tracepoint_print_one_detail(const struct breakpoint * self,struct ui_out * uiout)13404a45ae5f8SJohn Marino tracepoint_print_one_detail (const struct breakpoint *self,
13405a45ae5f8SJohn Marino 			     struct ui_out *uiout)
13406a45ae5f8SJohn Marino {
13407a45ae5f8SJohn Marino   struct tracepoint *tp = (struct tracepoint *) self;
13408a45ae5f8SJohn Marino   if (tp->static_trace_marker_id)
13409a45ae5f8SJohn Marino     {
13410a45ae5f8SJohn Marino       gdb_assert (self->type == bp_static_tracepoint);
13411a45ae5f8SJohn Marino 
13412a45ae5f8SJohn Marino       ui_out_text (uiout, "\tmarker id is ");
13413a45ae5f8SJohn Marino       ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
13414a45ae5f8SJohn Marino 			   tp->static_trace_marker_id);
13415a45ae5f8SJohn Marino       ui_out_text (uiout, "\n");
13416a45ae5f8SJohn Marino     }
13417a45ae5f8SJohn Marino }
13418a45ae5f8SJohn Marino 
13419a45ae5f8SJohn Marino static void
tracepoint_print_mention(struct breakpoint * b)13420a45ae5f8SJohn Marino tracepoint_print_mention (struct breakpoint *b)
13421a45ae5f8SJohn Marino {
13422a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (current_uiout))
13423a45ae5f8SJohn Marino     return;
13424a45ae5f8SJohn Marino 
13425a45ae5f8SJohn Marino   switch (b->type)
13426a45ae5f8SJohn Marino     {
13427a45ae5f8SJohn Marino     case bp_tracepoint:
13428a45ae5f8SJohn Marino       printf_filtered (_("Tracepoint"));
13429a45ae5f8SJohn Marino       printf_filtered (_(" %d"), b->number);
13430a45ae5f8SJohn Marino       break;
13431a45ae5f8SJohn Marino     case bp_fast_tracepoint:
13432a45ae5f8SJohn Marino       printf_filtered (_("Fast tracepoint"));
13433a45ae5f8SJohn Marino       printf_filtered (_(" %d"), b->number);
13434a45ae5f8SJohn Marino       break;
13435a45ae5f8SJohn Marino     case bp_static_tracepoint:
13436a45ae5f8SJohn Marino       printf_filtered (_("Static tracepoint"));
13437a45ae5f8SJohn Marino       printf_filtered (_(" %d"), b->number);
13438a45ae5f8SJohn Marino       break;
13439a45ae5f8SJohn Marino     default:
13440a45ae5f8SJohn Marino       internal_error (__FILE__, __LINE__,
13441a45ae5f8SJohn Marino 		      _("unhandled tracepoint type %d"), (int) b->type);
13442a45ae5f8SJohn Marino     }
13443a45ae5f8SJohn Marino 
13444a45ae5f8SJohn Marino   say_where (b);
13445a45ae5f8SJohn Marino }
13446a45ae5f8SJohn Marino 
13447a45ae5f8SJohn Marino static void
tracepoint_print_recreate(struct breakpoint * self,struct ui_file * fp)13448a45ae5f8SJohn Marino tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
13449a45ae5f8SJohn Marino {
13450a45ae5f8SJohn Marino   struct tracepoint *tp = (struct tracepoint *) self;
13451a45ae5f8SJohn Marino 
13452a45ae5f8SJohn Marino   if (self->type == bp_fast_tracepoint)
13453a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "ftrace");
13454a45ae5f8SJohn Marino   if (self->type == bp_static_tracepoint)
13455a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "strace");
13456a45ae5f8SJohn Marino   else if (self->type == bp_tracepoint)
13457a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "trace");
13458a45ae5f8SJohn Marino   else
13459a45ae5f8SJohn Marino     internal_error (__FILE__, __LINE__,
13460a45ae5f8SJohn Marino 		    _("unhandled tracepoint type %d"), (int) self->type);
13461a45ae5f8SJohn Marino 
13462a45ae5f8SJohn Marino   fprintf_unfiltered (fp, " %s", self->addr_string);
13463a45ae5f8SJohn Marino   print_recreate_thread (self, fp);
13464a45ae5f8SJohn Marino 
13465a45ae5f8SJohn Marino   if (tp->pass_count)
13466a45ae5f8SJohn Marino     fprintf_unfiltered (fp, "  passcount %d\n", tp->pass_count);
13467a45ae5f8SJohn Marino }
13468a45ae5f8SJohn Marino 
13469*ef5ccd6cSJohn Marino static void
tracepoint_create_sals_from_address(char ** arg,struct linespec_result * canonical,enum bptype type_wanted,char * addr_start,char ** copy_arg)13470*ef5ccd6cSJohn Marino tracepoint_create_sals_from_address (char **arg,
13471*ef5ccd6cSJohn Marino 				     struct linespec_result *canonical,
13472*ef5ccd6cSJohn Marino 				     enum bptype type_wanted,
13473*ef5ccd6cSJohn Marino 				     char *addr_start, char **copy_arg)
13474*ef5ccd6cSJohn Marino {
13475*ef5ccd6cSJohn Marino   create_sals_from_address_default (arg, canonical, type_wanted,
13476*ef5ccd6cSJohn Marino 				    addr_start, copy_arg);
13477*ef5ccd6cSJohn Marino }
13478*ef5ccd6cSJohn Marino 
13479*ef5ccd6cSJohn Marino static void
tracepoint_create_breakpoints_sal(struct gdbarch * gdbarch,struct linespec_result * canonical,struct linespec_sals * lsal,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)13480*ef5ccd6cSJohn Marino tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
13481*ef5ccd6cSJohn Marino 				   struct linespec_result *canonical,
13482*ef5ccd6cSJohn Marino 				   struct linespec_sals *lsal,
13483*ef5ccd6cSJohn Marino 				   char *cond_string,
13484*ef5ccd6cSJohn Marino 				   char *extra_string,
13485*ef5ccd6cSJohn Marino 				   enum bptype type_wanted,
13486*ef5ccd6cSJohn Marino 				   enum bpdisp disposition,
13487*ef5ccd6cSJohn Marino 				   int thread,
13488*ef5ccd6cSJohn Marino 				   int task, int ignore_count,
13489*ef5ccd6cSJohn Marino 				   const struct breakpoint_ops *ops,
13490*ef5ccd6cSJohn Marino 				   int from_tty, int enabled,
13491*ef5ccd6cSJohn Marino 				   int internal, unsigned flags)
13492*ef5ccd6cSJohn Marino {
13493*ef5ccd6cSJohn Marino   create_breakpoints_sal_default (gdbarch, canonical, lsal,
13494*ef5ccd6cSJohn Marino 				  cond_string, extra_string,
13495*ef5ccd6cSJohn Marino 				  type_wanted,
13496*ef5ccd6cSJohn Marino 				  disposition, thread, task,
13497*ef5ccd6cSJohn Marino 				  ignore_count, ops, from_tty,
13498*ef5ccd6cSJohn Marino 				  enabled, internal, flags);
13499*ef5ccd6cSJohn Marino }
13500*ef5ccd6cSJohn Marino 
13501*ef5ccd6cSJohn Marino static void
tracepoint_decode_linespec(struct breakpoint * b,char ** s,struct symtabs_and_lines * sals)13502*ef5ccd6cSJohn Marino tracepoint_decode_linespec (struct breakpoint *b, char **s,
13503*ef5ccd6cSJohn Marino 			    struct symtabs_and_lines *sals)
13504*ef5ccd6cSJohn Marino {
13505*ef5ccd6cSJohn Marino   decode_linespec_default (b, s, sals);
13506*ef5ccd6cSJohn Marino }
13507*ef5ccd6cSJohn Marino 
13508a45ae5f8SJohn Marino struct breakpoint_ops tracepoint_breakpoint_ops;
13509a45ae5f8SJohn Marino 
13510*ef5ccd6cSJohn Marino /* The breakpoint_ops structure to be use on tracepoints placed in a
13511*ef5ccd6cSJohn Marino    static probe.  */
13512*ef5ccd6cSJohn Marino 
13513*ef5ccd6cSJohn Marino static void
tracepoint_probe_create_sals_from_address(char ** arg,struct linespec_result * canonical,enum bptype type_wanted,char * addr_start,char ** copy_arg)13514*ef5ccd6cSJohn Marino tracepoint_probe_create_sals_from_address (char **arg,
13515*ef5ccd6cSJohn Marino 					   struct linespec_result *canonical,
13516*ef5ccd6cSJohn Marino 					   enum bptype type_wanted,
13517*ef5ccd6cSJohn Marino 					   char *addr_start, char **copy_arg)
13518*ef5ccd6cSJohn Marino {
13519*ef5ccd6cSJohn Marino   /* We use the same method for breakpoint on probes.  */
13520*ef5ccd6cSJohn Marino   bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
13521*ef5ccd6cSJohn Marino 				       addr_start, copy_arg);
13522*ef5ccd6cSJohn Marino }
13523*ef5ccd6cSJohn Marino 
13524*ef5ccd6cSJohn Marino static void
tracepoint_probe_decode_linespec(struct breakpoint * b,char ** s,struct symtabs_and_lines * sals)13525*ef5ccd6cSJohn Marino tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
13526*ef5ccd6cSJohn Marino 				  struct symtabs_and_lines *sals)
13527*ef5ccd6cSJohn Marino {
13528*ef5ccd6cSJohn Marino   /* We use the same method for breakpoint on probes.  */
13529*ef5ccd6cSJohn Marino   bkpt_probe_decode_linespec (b, s, sals);
13530*ef5ccd6cSJohn Marino }
13531*ef5ccd6cSJohn Marino 
13532*ef5ccd6cSJohn Marino static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
13533*ef5ccd6cSJohn Marino 
13534*ef5ccd6cSJohn Marino /* Dprintf breakpoint_ops methods.  */
13535*ef5ccd6cSJohn Marino 
13536*ef5ccd6cSJohn Marino static void
dprintf_re_set(struct breakpoint * b)13537*ef5ccd6cSJohn Marino dprintf_re_set (struct breakpoint *b)
13538*ef5ccd6cSJohn Marino {
13539*ef5ccd6cSJohn Marino   breakpoint_re_set_default (b);
13540*ef5ccd6cSJohn Marino 
13541*ef5ccd6cSJohn Marino   /* This breakpoint could have been pending, and be resolved now, and
13542*ef5ccd6cSJohn Marino      if so, we should now have the extra string.  If we don't, the
13543*ef5ccd6cSJohn Marino      dprintf was malformed when created, but we couldn't tell because
13544*ef5ccd6cSJohn Marino      we can't extract the extra string until the location is
13545*ef5ccd6cSJohn Marino      resolved.  */
13546*ef5ccd6cSJohn Marino   if (b->loc != NULL && b->extra_string == NULL)
13547*ef5ccd6cSJohn Marino     error (_("Format string required"));
13548*ef5ccd6cSJohn Marino 
13549*ef5ccd6cSJohn Marino   /* 1 - connect to target 1, that can run breakpoint commands.
13550*ef5ccd6cSJohn Marino      2 - create a dprintf, which resolves fine.
13551*ef5ccd6cSJohn Marino      3 - disconnect from target 1
13552*ef5ccd6cSJohn Marino      4 - connect to target 2, that can NOT run breakpoint commands.
13553*ef5ccd6cSJohn Marino 
13554*ef5ccd6cSJohn Marino      After steps #3/#4, you'll want the dprintf command list to
13555*ef5ccd6cSJohn Marino      be updated, because target 1 and 2 may well return different
13556*ef5ccd6cSJohn Marino      answers for target_can_run_breakpoint_commands().
13557*ef5ccd6cSJohn Marino      Given absence of finer grained resetting, we get to do
13558*ef5ccd6cSJohn Marino      it all the time.  */
13559*ef5ccd6cSJohn Marino   if (b->extra_string != NULL)
13560*ef5ccd6cSJohn Marino     update_dprintf_command_list (b);
13561*ef5ccd6cSJohn Marino }
13562*ef5ccd6cSJohn Marino 
13563*ef5ccd6cSJohn Marino /* Implement the "print_recreate" breakpoint_ops method for dprintf.  */
13564*ef5ccd6cSJohn Marino 
13565*ef5ccd6cSJohn Marino static void
dprintf_print_recreate(struct breakpoint * tp,struct ui_file * fp)13566*ef5ccd6cSJohn Marino dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
13567*ef5ccd6cSJohn Marino {
13568*ef5ccd6cSJohn Marino   fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
13569*ef5ccd6cSJohn Marino 		      tp->extra_string);
13570*ef5ccd6cSJohn Marino   print_recreate_thread (tp, fp);
13571*ef5ccd6cSJohn Marino }
13572*ef5ccd6cSJohn Marino 
13573*ef5ccd6cSJohn Marino /* Implement the "after_condition_true" breakpoint_ops method for
13574*ef5ccd6cSJohn Marino    dprintf.
13575*ef5ccd6cSJohn Marino 
13576*ef5ccd6cSJohn Marino    dprintf's are implemented with regular commands in their command
13577*ef5ccd6cSJohn Marino    list, but we run the commands here instead of before presenting the
13578*ef5ccd6cSJohn Marino    stop to the user, as dprintf's don't actually cause a stop.  This
13579*ef5ccd6cSJohn Marino    also makes it so that the commands of multiple dprintfs at the same
13580*ef5ccd6cSJohn Marino    address are all handled.  */
13581*ef5ccd6cSJohn Marino 
13582*ef5ccd6cSJohn Marino static void
dprintf_after_condition_true(struct bpstats * bs)13583*ef5ccd6cSJohn Marino dprintf_after_condition_true (struct bpstats *bs)
13584*ef5ccd6cSJohn Marino {
13585*ef5ccd6cSJohn Marino   struct cleanup *old_chain;
13586*ef5ccd6cSJohn Marino   struct bpstats tmp_bs = { NULL };
13587*ef5ccd6cSJohn Marino   struct bpstats *tmp_bs_p = &tmp_bs;
13588*ef5ccd6cSJohn Marino 
13589*ef5ccd6cSJohn Marino   /* dprintf's never cause a stop.  This wasn't set in the
13590*ef5ccd6cSJohn Marino      check_status hook instead because that would make the dprintf's
13591*ef5ccd6cSJohn Marino      condition not be evaluated.  */
13592*ef5ccd6cSJohn Marino   bs->stop = 0;
13593*ef5ccd6cSJohn Marino 
13594*ef5ccd6cSJohn Marino   /* Run the command list here.  Take ownership of it instead of
13595*ef5ccd6cSJohn Marino      copying.  We never want these commands to run later in
13596*ef5ccd6cSJohn Marino      bpstat_do_actions, if a breakpoint that causes a stop happens to
13597*ef5ccd6cSJohn Marino      be set at same address as this dprintf, or even if running the
13598*ef5ccd6cSJohn Marino      commands here throws.  */
13599*ef5ccd6cSJohn Marino   tmp_bs.commands = bs->commands;
13600*ef5ccd6cSJohn Marino   bs->commands = NULL;
13601*ef5ccd6cSJohn Marino   old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands);
13602*ef5ccd6cSJohn Marino 
13603*ef5ccd6cSJohn Marino   bpstat_do_actions_1 (&tmp_bs_p);
13604*ef5ccd6cSJohn Marino 
13605*ef5ccd6cSJohn Marino   /* 'tmp_bs.commands' will usually be NULL by now, but
13606*ef5ccd6cSJohn Marino      bpstat_do_actions_1 may return early without processing the whole
13607*ef5ccd6cSJohn Marino      list.  */
13608*ef5ccd6cSJohn Marino   do_cleanups (old_chain);
13609*ef5ccd6cSJohn Marino }
13610*ef5ccd6cSJohn Marino 
13611*ef5ccd6cSJohn Marino /* The breakpoint_ops structure to be used on static tracepoints with
13612*ef5ccd6cSJohn Marino    markers (`-m').  */
13613*ef5ccd6cSJohn Marino 
13614*ef5ccd6cSJohn Marino static void
strace_marker_create_sals_from_address(char ** arg,struct linespec_result * canonical,enum bptype type_wanted,char * addr_start,char ** copy_arg)13615*ef5ccd6cSJohn Marino strace_marker_create_sals_from_address (char **arg,
13616*ef5ccd6cSJohn Marino 					struct linespec_result *canonical,
13617*ef5ccd6cSJohn Marino 					enum bptype type_wanted,
13618*ef5ccd6cSJohn Marino 					char *addr_start, char **copy_arg)
13619*ef5ccd6cSJohn Marino {
13620*ef5ccd6cSJohn Marino   struct linespec_sals lsal;
13621*ef5ccd6cSJohn Marino 
13622*ef5ccd6cSJohn Marino   lsal.sals = decode_static_tracepoint_spec (arg);
13623*ef5ccd6cSJohn Marino 
13624*ef5ccd6cSJohn Marino   *copy_arg = savestring (addr_start, *arg - addr_start);
13625*ef5ccd6cSJohn Marino 
13626*ef5ccd6cSJohn Marino   canonical->addr_string = xstrdup (*copy_arg);
13627*ef5ccd6cSJohn Marino   lsal.canonical = xstrdup (*copy_arg);
13628*ef5ccd6cSJohn Marino   VEC_safe_push (linespec_sals, canonical->sals, &lsal);
13629*ef5ccd6cSJohn Marino }
13630*ef5ccd6cSJohn Marino 
13631*ef5ccd6cSJohn Marino static void
strace_marker_create_breakpoints_sal(struct gdbarch * gdbarch,struct linespec_result * canonical,struct linespec_sals * lsal,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)13632*ef5ccd6cSJohn Marino strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
13633*ef5ccd6cSJohn Marino 				      struct linespec_result *canonical,
13634*ef5ccd6cSJohn Marino 				      struct linespec_sals *lsal,
13635*ef5ccd6cSJohn Marino 				      char *cond_string,
13636*ef5ccd6cSJohn Marino 				      char *extra_string,
13637*ef5ccd6cSJohn Marino 				      enum bptype type_wanted,
13638*ef5ccd6cSJohn Marino 				      enum bpdisp disposition,
13639*ef5ccd6cSJohn Marino 				      int thread,
13640*ef5ccd6cSJohn Marino 				      int task, int ignore_count,
13641*ef5ccd6cSJohn Marino 				      const struct breakpoint_ops *ops,
13642*ef5ccd6cSJohn Marino 				      int from_tty, int enabled,
13643*ef5ccd6cSJohn Marino 				      int internal, unsigned flags)
13644*ef5ccd6cSJohn Marino {
13645*ef5ccd6cSJohn Marino   int i;
13646*ef5ccd6cSJohn Marino 
13647*ef5ccd6cSJohn Marino   /* If the user is creating a static tracepoint by marker id
13648*ef5ccd6cSJohn Marino      (strace -m MARKER_ID), then store the sals index, so that
13649*ef5ccd6cSJohn Marino      breakpoint_re_set can try to match up which of the newly
13650*ef5ccd6cSJohn Marino      found markers corresponds to this one, and, don't try to
13651*ef5ccd6cSJohn Marino      expand multiple locations for each sal, given than SALS
13652*ef5ccd6cSJohn Marino      already should contain all sals for MARKER_ID.  */
13653*ef5ccd6cSJohn Marino 
13654*ef5ccd6cSJohn Marino   for (i = 0; i < lsal->sals.nelts; ++i)
13655*ef5ccd6cSJohn Marino     {
13656*ef5ccd6cSJohn Marino       struct symtabs_and_lines expanded;
13657*ef5ccd6cSJohn Marino       struct tracepoint *tp;
13658*ef5ccd6cSJohn Marino       struct cleanup *old_chain;
13659*ef5ccd6cSJohn Marino       char *addr_string;
13660*ef5ccd6cSJohn Marino 
13661*ef5ccd6cSJohn Marino       expanded.nelts = 1;
13662*ef5ccd6cSJohn Marino       expanded.sals = &lsal->sals.sals[i];
13663*ef5ccd6cSJohn Marino 
13664*ef5ccd6cSJohn Marino       addr_string = xstrdup (canonical->addr_string);
13665*ef5ccd6cSJohn Marino       old_chain = make_cleanup (xfree, addr_string);
13666*ef5ccd6cSJohn Marino 
13667*ef5ccd6cSJohn Marino       tp = XCNEW (struct tracepoint);
13668*ef5ccd6cSJohn Marino       init_breakpoint_sal (&tp->base, gdbarch, expanded,
13669*ef5ccd6cSJohn Marino 			   addr_string, NULL,
13670*ef5ccd6cSJohn Marino 			   cond_string, extra_string,
13671*ef5ccd6cSJohn Marino 			   type_wanted, disposition,
13672*ef5ccd6cSJohn Marino 			   thread, task, ignore_count, ops,
13673*ef5ccd6cSJohn Marino 			   from_tty, enabled, internal, flags,
13674*ef5ccd6cSJohn Marino 			   canonical->special_display);
13675*ef5ccd6cSJohn Marino       /* Given that its possible to have multiple markers with
13676*ef5ccd6cSJohn Marino 	 the same string id, if the user is creating a static
13677*ef5ccd6cSJohn Marino 	 tracepoint by marker id ("strace -m MARKER_ID"), then
13678*ef5ccd6cSJohn Marino 	 store the sals index, so that breakpoint_re_set can
13679*ef5ccd6cSJohn Marino 	 try to match up which of the newly found markers
13680*ef5ccd6cSJohn Marino 	 corresponds to this one  */
13681*ef5ccd6cSJohn Marino       tp->static_trace_marker_id_idx = i;
13682*ef5ccd6cSJohn Marino 
13683*ef5ccd6cSJohn Marino       install_breakpoint (internal, &tp->base, 0);
13684*ef5ccd6cSJohn Marino 
13685*ef5ccd6cSJohn Marino       discard_cleanups (old_chain);
13686*ef5ccd6cSJohn Marino     }
13687*ef5ccd6cSJohn Marino }
13688*ef5ccd6cSJohn Marino 
13689*ef5ccd6cSJohn Marino static void
strace_marker_decode_linespec(struct breakpoint * b,char ** s,struct symtabs_and_lines * sals)13690*ef5ccd6cSJohn Marino strace_marker_decode_linespec (struct breakpoint *b, char **s,
13691*ef5ccd6cSJohn Marino 			       struct symtabs_and_lines *sals)
13692*ef5ccd6cSJohn Marino {
13693*ef5ccd6cSJohn Marino   struct tracepoint *tp = (struct tracepoint *) b;
13694*ef5ccd6cSJohn Marino 
13695*ef5ccd6cSJohn Marino   *sals = decode_static_tracepoint_spec (s);
13696*ef5ccd6cSJohn Marino   if (sals->nelts > tp->static_trace_marker_id_idx)
13697*ef5ccd6cSJohn Marino     {
13698*ef5ccd6cSJohn Marino       sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13699*ef5ccd6cSJohn Marino       sals->nelts = 1;
13700*ef5ccd6cSJohn Marino     }
13701*ef5ccd6cSJohn Marino   else
13702*ef5ccd6cSJohn Marino     error (_("marker %s not found"), tp->static_trace_marker_id);
13703*ef5ccd6cSJohn Marino }
13704*ef5ccd6cSJohn Marino 
13705*ef5ccd6cSJohn Marino static struct breakpoint_ops strace_marker_breakpoint_ops;
13706*ef5ccd6cSJohn Marino 
13707*ef5ccd6cSJohn Marino static int
strace_marker_p(struct breakpoint * b)13708*ef5ccd6cSJohn Marino strace_marker_p (struct breakpoint *b)
13709*ef5ccd6cSJohn Marino {
13710*ef5ccd6cSJohn Marino   return b->ops == &strace_marker_breakpoint_ops;
13711*ef5ccd6cSJohn Marino }
13712*ef5ccd6cSJohn Marino 
137135796c8dcSSimon Schubert /* Delete a breakpoint and clean up all traces of it in the data
137145796c8dcSSimon Schubert    structures.  */
137155796c8dcSSimon Schubert 
137165796c8dcSSimon Schubert void
delete_breakpoint(struct breakpoint * bpt)137175796c8dcSSimon Schubert delete_breakpoint (struct breakpoint *bpt)
137185796c8dcSSimon Schubert {
137195796c8dcSSimon Schubert   struct breakpoint *b;
137205796c8dcSSimon Schubert 
137215796c8dcSSimon Schubert   gdb_assert (bpt != NULL);
137225796c8dcSSimon Schubert 
13723c50c785cSJohn Marino   /* Has this bp already been deleted?  This can happen because
13724c50c785cSJohn Marino      multiple lists can hold pointers to bp's.  bpstat lists are
13725c50c785cSJohn Marino      especial culprits.
137265796c8dcSSimon Schubert 
13727c50c785cSJohn Marino      One example of this happening is a watchpoint's scope bp.  When
13728c50c785cSJohn Marino      the scope bp triggers, we notice that the watchpoint is out of
13729c50c785cSJohn Marino      scope, and delete it.  We also delete its scope bp.  But the
13730c50c785cSJohn Marino      scope bp is marked "auto-deleting", and is already on a bpstat.
13731c50c785cSJohn Marino      That bpstat is then checked for auto-deleting bp's, which are
13732c50c785cSJohn Marino      deleted.
137335796c8dcSSimon Schubert 
13734c50c785cSJohn Marino      A real solution to this problem might involve reference counts in
13735c50c785cSJohn Marino      bp's, and/or giving them pointers back to their referencing
13736c50c785cSJohn Marino      bpstat's, and teaching delete_breakpoint to only free a bp's
13737c50c785cSJohn Marino      storage when no more references were extent.  A cheaper bandaid
13738c50c785cSJohn Marino      was chosen.  */
137395796c8dcSSimon Schubert   if (bpt->type == bp_none)
137405796c8dcSSimon Schubert     return;
137415796c8dcSSimon Schubert 
13742c50c785cSJohn Marino   /* At least avoid this stale reference until the reference counting
13743c50c785cSJohn Marino      of breakpoints gets resolved.  */
13744c50c785cSJohn Marino   if (bpt->related_breakpoint != bpt)
13745cf7f2e2dSJohn Marino     {
13746c50c785cSJohn Marino       struct breakpoint *related;
13747a45ae5f8SJohn Marino       struct watchpoint *w;
13748c50c785cSJohn Marino 
13749c50c785cSJohn Marino       if (bpt->type == bp_watchpoint_scope)
13750a45ae5f8SJohn Marino 	w = (struct watchpoint *) bpt->related_breakpoint;
13751c50c785cSJohn Marino       else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
13752a45ae5f8SJohn Marino 	w = (struct watchpoint *) bpt;
13753a45ae5f8SJohn Marino       else
13754a45ae5f8SJohn Marino 	w = NULL;
13755a45ae5f8SJohn Marino       if (w != NULL)
13756a45ae5f8SJohn Marino 	watchpoint_del_at_next_stop (w);
13757c50c785cSJohn Marino 
13758c50c785cSJohn Marino       /* Unlink bpt from the bpt->related_breakpoint ring.  */
13759c50c785cSJohn Marino       for (related = bpt; related->related_breakpoint != bpt;
13760c50c785cSJohn Marino 	   related = related->related_breakpoint);
13761c50c785cSJohn Marino       related->related_breakpoint = bpt->related_breakpoint;
13762c50c785cSJohn Marino       bpt->related_breakpoint = bpt;
13763cf7f2e2dSJohn Marino     }
13764cf7f2e2dSJohn Marino 
13765a45ae5f8SJohn Marino   /* watch_command_1 creates a watchpoint but only sets its number if
13766a45ae5f8SJohn Marino      update_watchpoint succeeds in creating its bp_locations.  If there's
13767a45ae5f8SJohn Marino      a problem in that process, we'll be asked to delete the half-created
13768a45ae5f8SJohn Marino      watchpoint.  In that case, don't announce the deletion.  */
13769a45ae5f8SJohn Marino   if (bpt->number)
13770a45ae5f8SJohn Marino     observer_notify_breakpoint_deleted (bpt);
137715796c8dcSSimon Schubert 
137725796c8dcSSimon Schubert   if (breakpoint_chain == bpt)
137735796c8dcSSimon Schubert     breakpoint_chain = bpt->next;
137745796c8dcSSimon Schubert 
137755796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
137765796c8dcSSimon Schubert     if (b->next == bpt)
137775796c8dcSSimon Schubert     {
137785796c8dcSSimon Schubert       b->next = bpt->next;
137795796c8dcSSimon Schubert       break;
137805796c8dcSSimon Schubert     }
137815796c8dcSSimon Schubert 
13782c50c785cSJohn Marino   /* Be sure no bpstat's are pointing at the breakpoint after it's
13783c50c785cSJohn Marino      been freed.  */
13784c50c785cSJohn Marino   /* FIXME, how can we find all bpstat's?  We just check stop_bpstat
13785a45ae5f8SJohn Marino      in all threads for now.  Note that we cannot just remove bpstats
13786c50c785cSJohn Marino      pointing at bpt from the stop_bpstat list entirely, as breakpoint
13787c50c785cSJohn Marino      commands are associated with the bpstat; if we remove it here,
13788c50c785cSJohn Marino      then the later call to bpstat_do_actions (&stop_bpstat); in
13789c50c785cSJohn Marino      event-top.c won't do anything, and temporary breakpoints with
13790c50c785cSJohn Marino      commands won't work.  */
13791c50c785cSJohn Marino 
13792c50c785cSJohn Marino   iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13793c50c785cSJohn Marino 
13794c50c785cSJohn Marino   /* Now that breakpoint is removed from breakpoint list, update the
13795c50c785cSJohn Marino      global location list.  This will remove locations that used to
13796c50c785cSJohn Marino      belong to this breakpoint.  Do this before freeing the breakpoint
13797c50c785cSJohn Marino      itself, since remove_breakpoint looks at location's owner.  It
13798c50c785cSJohn Marino      might be better design to have location completely
13799c50c785cSJohn Marino      self-contained, but it's not the case now.  */
138005796c8dcSSimon Schubert   update_global_location_list (0);
138015796c8dcSSimon Schubert 
13802a45ae5f8SJohn Marino   bpt->ops->dtor (bpt);
13803c50c785cSJohn Marino   /* On the chance that someone will soon try again to delete this
13804c50c785cSJohn Marino      same bp, we mark it as deleted before freeing its storage.  */
138055796c8dcSSimon Schubert   bpt->type = bp_none;
138065796c8dcSSimon Schubert   xfree (bpt);
138075796c8dcSSimon Schubert }
138085796c8dcSSimon Schubert 
138095796c8dcSSimon Schubert static void
do_delete_breakpoint_cleanup(void * b)138105796c8dcSSimon Schubert do_delete_breakpoint_cleanup (void *b)
138115796c8dcSSimon Schubert {
138125796c8dcSSimon Schubert   delete_breakpoint (b);
138135796c8dcSSimon Schubert }
138145796c8dcSSimon Schubert 
138155796c8dcSSimon Schubert struct cleanup *
make_cleanup_delete_breakpoint(struct breakpoint * b)138165796c8dcSSimon Schubert make_cleanup_delete_breakpoint (struct breakpoint *b)
138175796c8dcSSimon Schubert {
138185796c8dcSSimon Schubert   return make_cleanup (do_delete_breakpoint_cleanup, b);
138195796c8dcSSimon Schubert }
138205796c8dcSSimon Schubert 
13821a45ae5f8SJohn Marino /* Iterator function to call a user-provided callback function once
13822a45ae5f8SJohn Marino    for each of B and its related breakpoints.  */
13823a45ae5f8SJohn Marino 
13824a45ae5f8SJohn Marino static void
iterate_over_related_breakpoints(struct breakpoint * b,void (* function)(struct breakpoint *,void *),void * data)13825a45ae5f8SJohn Marino iterate_over_related_breakpoints (struct breakpoint *b,
13826a45ae5f8SJohn Marino 				  void (*function) (struct breakpoint *,
13827a45ae5f8SJohn Marino 						    void *),
13828a45ae5f8SJohn Marino 				  void *data)
13829a45ae5f8SJohn Marino {
13830a45ae5f8SJohn Marino   struct breakpoint *related;
13831a45ae5f8SJohn Marino 
13832a45ae5f8SJohn Marino   related = b;
13833a45ae5f8SJohn Marino   do
13834a45ae5f8SJohn Marino     {
13835a45ae5f8SJohn Marino       struct breakpoint *next;
13836a45ae5f8SJohn Marino 
13837a45ae5f8SJohn Marino       /* FUNCTION may delete RELATED.  */
13838a45ae5f8SJohn Marino       next = related->related_breakpoint;
13839a45ae5f8SJohn Marino 
13840a45ae5f8SJohn Marino       if (next == related)
13841a45ae5f8SJohn Marino 	{
13842a45ae5f8SJohn Marino 	  /* RELATED is the last ring entry.  */
13843a45ae5f8SJohn Marino 	  function (related, data);
13844a45ae5f8SJohn Marino 
13845a45ae5f8SJohn Marino 	  /* FUNCTION may have deleted it, so we'd never reach back to
13846a45ae5f8SJohn Marino 	     B.  There's nothing left to do anyway, so just break
13847a45ae5f8SJohn Marino 	     out.  */
13848a45ae5f8SJohn Marino 	  break;
13849a45ae5f8SJohn Marino 	}
13850a45ae5f8SJohn Marino       else
13851a45ae5f8SJohn Marino 	function (related, data);
13852a45ae5f8SJohn Marino 
13853a45ae5f8SJohn Marino       related = next;
13854a45ae5f8SJohn Marino     }
13855a45ae5f8SJohn Marino   while (related != b);
13856a45ae5f8SJohn Marino }
13857cf7f2e2dSJohn Marino 
13858cf7f2e2dSJohn Marino static void
do_delete_breakpoint(struct breakpoint * b,void * ignore)13859cf7f2e2dSJohn Marino do_delete_breakpoint (struct breakpoint *b, void *ignore)
13860cf7f2e2dSJohn Marino {
13861cf7f2e2dSJohn Marino   delete_breakpoint (b);
13862cf7f2e2dSJohn Marino }
13863cf7f2e2dSJohn Marino 
13864a45ae5f8SJohn Marino /* A callback for map_breakpoint_numbers that calls
13865a45ae5f8SJohn Marino    delete_breakpoint.  */
13866a45ae5f8SJohn Marino 
13867a45ae5f8SJohn Marino static void
do_map_delete_breakpoint(struct breakpoint * b,void * ignore)13868a45ae5f8SJohn Marino do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13869a45ae5f8SJohn Marino {
13870a45ae5f8SJohn Marino   iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13871a45ae5f8SJohn Marino }
13872a45ae5f8SJohn Marino 
138735796c8dcSSimon Schubert void
delete_command(char * arg,int from_tty)138745796c8dcSSimon Schubert delete_command (char *arg, int from_tty)
138755796c8dcSSimon Schubert {
13876c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
138775796c8dcSSimon Schubert 
138785796c8dcSSimon Schubert   dont_repeat ();
138795796c8dcSSimon Schubert 
138805796c8dcSSimon Schubert   if (arg == 0)
138815796c8dcSSimon Schubert     {
138825796c8dcSSimon Schubert       int breaks_to_delete = 0;
138835796c8dcSSimon Schubert 
13884a45ae5f8SJohn Marino       /* Delete all breakpoints if no argument.  Do not delete
13885a45ae5f8SJohn Marino          internal breakpoints, these have to be deleted with an
13886a45ae5f8SJohn Marino          explicit breakpoint number argument.  */
138875796c8dcSSimon Schubert       ALL_BREAKPOINTS (b)
13888a45ae5f8SJohn Marino 	if (user_breakpoint_p (b))
138895796c8dcSSimon Schubert 	  {
138905796c8dcSSimon Schubert 	    breaks_to_delete = 1;
138915796c8dcSSimon Schubert 	    break;
138925796c8dcSSimon Schubert 	  }
138935796c8dcSSimon Schubert 
138945796c8dcSSimon Schubert       /* Ask user only if there are some breakpoints to delete.  */
138955796c8dcSSimon Schubert       if (!from_tty
138965796c8dcSSimon Schubert 	  || (breaks_to_delete && query (_("Delete all breakpoints? "))))
138975796c8dcSSimon Schubert 	{
13898c50c785cSJohn Marino 	  ALL_BREAKPOINTS_SAFE (b, b_tmp)
13899a45ae5f8SJohn Marino 	    if (user_breakpoint_p (b))
139005796c8dcSSimon Schubert 	      delete_breakpoint (b);
139015796c8dcSSimon Schubert 	}
139025796c8dcSSimon Schubert     }
139035796c8dcSSimon Schubert   else
13904a45ae5f8SJohn Marino     map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
139055796c8dcSSimon Schubert }
139065796c8dcSSimon Schubert 
139075796c8dcSSimon Schubert static int
all_locations_are_pending(struct bp_location * loc)139085796c8dcSSimon Schubert all_locations_are_pending (struct bp_location *loc)
139095796c8dcSSimon Schubert {
139105796c8dcSSimon Schubert   for (; loc; loc = loc->next)
13911a45ae5f8SJohn Marino     if (!loc->shlib_disabled
13912a45ae5f8SJohn Marino 	&& !loc->pspace->executing_startup)
139135796c8dcSSimon Schubert       return 0;
139145796c8dcSSimon Schubert   return 1;
139155796c8dcSSimon Schubert }
139165796c8dcSSimon Schubert 
139175796c8dcSSimon Schubert /* Subroutine of update_breakpoint_locations to simplify it.
139185796c8dcSSimon Schubert    Return non-zero if multiple fns in list LOC have the same name.
139195796c8dcSSimon Schubert    Null names are ignored.  */
139205796c8dcSSimon Schubert 
139215796c8dcSSimon Schubert static int
ambiguous_names_p(struct bp_location * loc)139225796c8dcSSimon Schubert ambiguous_names_p (struct bp_location *loc)
139235796c8dcSSimon Schubert {
139245796c8dcSSimon Schubert   struct bp_location *l;
139255796c8dcSSimon Schubert   htab_t htab = htab_create_alloc (13, htab_hash_string,
13926cf7f2e2dSJohn Marino 				   (int (*) (const void *,
13927cf7f2e2dSJohn Marino 					     const void *)) streq,
139285796c8dcSSimon Schubert 				   NULL, xcalloc, xfree);
139295796c8dcSSimon Schubert 
139305796c8dcSSimon Schubert   for (l = loc; l != NULL; l = l->next)
139315796c8dcSSimon Schubert     {
139325796c8dcSSimon Schubert       const char **slot;
139335796c8dcSSimon Schubert       const char *name = l->function_name;
139345796c8dcSSimon Schubert 
139355796c8dcSSimon Schubert       /* Allow for some names to be NULL, ignore them.  */
139365796c8dcSSimon Schubert       if (name == NULL)
139375796c8dcSSimon Schubert 	continue;
139385796c8dcSSimon Schubert 
139395796c8dcSSimon Schubert       slot = (const char **) htab_find_slot (htab, (const void *) name,
139405796c8dcSSimon Schubert 					     INSERT);
13941c50c785cSJohn Marino       /* NOTE: We can assume slot != NULL here because xcalloc never
13942c50c785cSJohn Marino 	 returns NULL.  */
139435796c8dcSSimon Schubert       if (*slot != NULL)
139445796c8dcSSimon Schubert 	{
139455796c8dcSSimon Schubert 	  htab_delete (htab);
139465796c8dcSSimon Schubert 	  return 1;
139475796c8dcSSimon Schubert 	}
139485796c8dcSSimon Schubert       *slot = name;
139495796c8dcSSimon Schubert     }
139505796c8dcSSimon Schubert 
139515796c8dcSSimon Schubert   htab_delete (htab);
139525796c8dcSSimon Schubert   return 0;
139535796c8dcSSimon Schubert }
139545796c8dcSSimon Schubert 
13955cf7f2e2dSJohn Marino /* When symbols change, it probably means the sources changed as well,
13956cf7f2e2dSJohn Marino    and it might mean the static tracepoint markers are no longer at
13957cf7f2e2dSJohn Marino    the same address or line numbers they used to be at last we
13958cf7f2e2dSJohn Marino    checked.  Losing your static tracepoints whenever you rebuild is
13959cf7f2e2dSJohn Marino    undesirable.  This function tries to resync/rematch gdb static
13960cf7f2e2dSJohn Marino    tracepoints with the markers on the target, for static tracepoints
13961cf7f2e2dSJohn Marino    that have not been set by marker id.  Static tracepoint that have
13962cf7f2e2dSJohn Marino    been set by marker id are reset by marker id in breakpoint_re_set.
13963cf7f2e2dSJohn Marino    The heuristic is:
13964cf7f2e2dSJohn Marino 
13965cf7f2e2dSJohn Marino    1) For a tracepoint set at a specific address, look for a marker at
13966cf7f2e2dSJohn Marino    the old PC.  If one is found there, assume to be the same marker.
13967cf7f2e2dSJohn Marino    If the name / string id of the marker found is different from the
13968cf7f2e2dSJohn Marino    previous known name, assume that means the user renamed the marker
13969cf7f2e2dSJohn Marino    in the sources, and output a warning.
13970cf7f2e2dSJohn Marino 
13971cf7f2e2dSJohn Marino    2) For a tracepoint set at a given line number, look for a marker
13972cf7f2e2dSJohn Marino    at the new address of the old line number.  If one is found there,
13973cf7f2e2dSJohn Marino    assume to be the same marker.  If the name / string id of the
13974cf7f2e2dSJohn Marino    marker found is different from the previous known name, assume that
13975cf7f2e2dSJohn Marino    means the user renamed the marker in the sources, and output a
13976cf7f2e2dSJohn Marino    warning.
13977cf7f2e2dSJohn Marino 
13978cf7f2e2dSJohn Marino    3) If a marker is no longer found at the same address or line, it
13979cf7f2e2dSJohn Marino    may mean the marker no longer exists.  But it may also just mean
13980cf7f2e2dSJohn Marino    the code changed a bit.  Maybe the user added a few lines of code
13981cf7f2e2dSJohn Marino    that made the marker move up or down (in line number terms).  Ask
13982cf7f2e2dSJohn Marino    the target for info about the marker with the string id as we knew
13983cf7f2e2dSJohn Marino    it.  If found, update line number and address in the matching
13984cf7f2e2dSJohn Marino    static tracepoint.  This will get confused if there's more than one
13985cf7f2e2dSJohn Marino    marker with the same ID (possible in UST, although unadvised
13986cf7f2e2dSJohn Marino    precisely because it confuses tools).  */
13987cf7f2e2dSJohn Marino 
13988cf7f2e2dSJohn Marino static struct symtab_and_line
update_static_tracepoint(struct breakpoint * b,struct symtab_and_line sal)13989cf7f2e2dSJohn Marino update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13990cf7f2e2dSJohn Marino {
13991a45ae5f8SJohn Marino   struct tracepoint *tp = (struct tracepoint *) b;
13992cf7f2e2dSJohn Marino   struct static_tracepoint_marker marker;
13993cf7f2e2dSJohn Marino   CORE_ADDR pc;
13994cf7f2e2dSJohn Marino 
13995cf7f2e2dSJohn Marino   pc = sal.pc;
13996cf7f2e2dSJohn Marino   if (sal.line)
13997cf7f2e2dSJohn Marino     find_line_pc (sal.symtab, sal.line, &pc);
13998cf7f2e2dSJohn Marino 
13999cf7f2e2dSJohn Marino   if (target_static_tracepoint_marker_at (pc, &marker))
14000cf7f2e2dSJohn Marino     {
14001a45ae5f8SJohn Marino       if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
14002cf7f2e2dSJohn Marino 	warning (_("static tracepoint %d changed probed marker from %s to %s"),
14003cf7f2e2dSJohn Marino 		 b->number,
14004a45ae5f8SJohn Marino 		 tp->static_trace_marker_id, marker.str_id);
14005cf7f2e2dSJohn Marino 
14006a45ae5f8SJohn Marino       xfree (tp->static_trace_marker_id);
14007a45ae5f8SJohn Marino       tp->static_trace_marker_id = xstrdup (marker.str_id);
14008cf7f2e2dSJohn Marino       release_static_tracepoint_marker (&marker);
14009cf7f2e2dSJohn Marino 
14010cf7f2e2dSJohn Marino       return sal;
14011cf7f2e2dSJohn Marino     }
14012cf7f2e2dSJohn Marino 
14013cf7f2e2dSJohn Marino   /* Old marker wasn't found on target at lineno.  Try looking it up
14014cf7f2e2dSJohn Marino      by string ID.  */
14015cf7f2e2dSJohn Marino   if (!sal.explicit_pc
14016cf7f2e2dSJohn Marino       && sal.line != 0
14017cf7f2e2dSJohn Marino       && sal.symtab != NULL
14018a45ae5f8SJohn Marino       && tp->static_trace_marker_id != NULL)
14019cf7f2e2dSJohn Marino     {
14020cf7f2e2dSJohn Marino       VEC(static_tracepoint_marker_p) *markers;
14021cf7f2e2dSJohn Marino 
14022cf7f2e2dSJohn Marino       markers
14023a45ae5f8SJohn Marino 	= target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
14024cf7f2e2dSJohn Marino 
14025cf7f2e2dSJohn Marino       if (!VEC_empty(static_tracepoint_marker_p, markers))
14026cf7f2e2dSJohn Marino 	{
14027a45ae5f8SJohn Marino 	  struct symtab_and_line sal2;
14028cf7f2e2dSJohn Marino 	  struct symbol *sym;
14029a45ae5f8SJohn Marino 	  struct static_tracepoint_marker *tpmarker;
14030a45ae5f8SJohn Marino 	  struct ui_out *uiout = current_uiout;
14031cf7f2e2dSJohn Marino 
14032a45ae5f8SJohn Marino 	  tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
14033cf7f2e2dSJohn Marino 
14034a45ae5f8SJohn Marino 	  xfree (tp->static_trace_marker_id);
14035a45ae5f8SJohn Marino 	  tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
14036cf7f2e2dSJohn Marino 
14037cf7f2e2dSJohn Marino 	  warning (_("marker for static tracepoint %d (%s) not "
14038cf7f2e2dSJohn Marino 		     "found at previous line number"),
14039a45ae5f8SJohn Marino 		   b->number, tp->static_trace_marker_id);
14040cf7f2e2dSJohn Marino 
14041a45ae5f8SJohn Marino 	  init_sal (&sal2);
14042cf7f2e2dSJohn Marino 
14043a45ae5f8SJohn Marino 	  sal2.pc = tpmarker->address;
14044cf7f2e2dSJohn Marino 
14045a45ae5f8SJohn Marino 	  sal2 = find_pc_line (tpmarker->address, 0);
14046a45ae5f8SJohn Marino 	  sym = find_pc_sect_function (tpmarker->address, NULL);
14047cf7f2e2dSJohn Marino 	  ui_out_text (uiout, "Now in ");
14048cf7f2e2dSJohn Marino 	  if (sym)
14049cf7f2e2dSJohn Marino 	    {
14050cf7f2e2dSJohn Marino 	      ui_out_field_string (uiout, "func",
14051cf7f2e2dSJohn Marino 				   SYMBOL_PRINT_NAME (sym));
14052cf7f2e2dSJohn Marino 	      ui_out_text (uiout, " at ");
14053cf7f2e2dSJohn Marino 	    }
14054*ef5ccd6cSJohn Marino 	  ui_out_field_string (uiout, "file",
14055*ef5ccd6cSJohn Marino 			       symtab_to_filename_for_display (sal2.symtab));
14056cf7f2e2dSJohn Marino 	  ui_out_text (uiout, ":");
14057cf7f2e2dSJohn Marino 
14058cf7f2e2dSJohn Marino 	  if (ui_out_is_mi_like_p (uiout))
14059cf7f2e2dSJohn Marino 	    {
14060*ef5ccd6cSJohn Marino 	      const char *fullname = symtab_to_fullname (sal2.symtab);
14061cf7f2e2dSJohn Marino 
14062cf7f2e2dSJohn Marino 	      ui_out_field_string (uiout, "fullname", fullname);
14063cf7f2e2dSJohn Marino 	    }
14064cf7f2e2dSJohn Marino 
14065a45ae5f8SJohn Marino 	  ui_out_field_int (uiout, "line", sal2.line);
14066cf7f2e2dSJohn Marino 	  ui_out_text (uiout, "\n");
14067cf7f2e2dSJohn Marino 
14068a45ae5f8SJohn Marino 	  b->loc->line_number = sal2.line;
14069*ef5ccd6cSJohn Marino 	  b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
14070cf7f2e2dSJohn Marino 
14071cf7f2e2dSJohn Marino 	  xfree (b->addr_string);
14072cf7f2e2dSJohn Marino 	  b->addr_string = xstrprintf ("%s:%d",
14073*ef5ccd6cSJohn Marino 				   symtab_to_filename_for_display (sal2.symtab),
14074a45ae5f8SJohn Marino 				       b->loc->line_number);
14075cf7f2e2dSJohn Marino 
14076cf7f2e2dSJohn Marino 	  /* Might be nice to check if function changed, and warn if
14077cf7f2e2dSJohn Marino 	     so.  */
14078cf7f2e2dSJohn Marino 
14079a45ae5f8SJohn Marino 	  release_static_tracepoint_marker (tpmarker);
14080cf7f2e2dSJohn Marino 	}
14081cf7f2e2dSJohn Marino     }
14082cf7f2e2dSJohn Marino   return sal;
14083cf7f2e2dSJohn Marino }
14084cf7f2e2dSJohn Marino 
14085a45ae5f8SJohn Marino /* Returns 1 iff locations A and B are sufficiently same that
14086a45ae5f8SJohn Marino    we don't need to report breakpoint as changed.  */
14087a45ae5f8SJohn Marino 
14088a45ae5f8SJohn Marino static int
locations_are_equal(struct bp_location * a,struct bp_location * b)14089a45ae5f8SJohn Marino locations_are_equal (struct bp_location *a, struct bp_location *b)
14090a45ae5f8SJohn Marino {
14091a45ae5f8SJohn Marino   while (a && b)
14092a45ae5f8SJohn Marino     {
14093a45ae5f8SJohn Marino       if (a->address != b->address)
14094a45ae5f8SJohn Marino 	return 0;
14095a45ae5f8SJohn Marino 
14096a45ae5f8SJohn Marino       if (a->shlib_disabled != b->shlib_disabled)
14097a45ae5f8SJohn Marino 	return 0;
14098a45ae5f8SJohn Marino 
14099a45ae5f8SJohn Marino       if (a->enabled != b->enabled)
14100a45ae5f8SJohn Marino 	return 0;
14101a45ae5f8SJohn Marino 
14102a45ae5f8SJohn Marino       a = a->next;
14103a45ae5f8SJohn Marino       b = b->next;
14104a45ae5f8SJohn Marino     }
14105a45ae5f8SJohn Marino 
14106a45ae5f8SJohn Marino   if ((a == NULL) != (b == NULL))
14107a45ae5f8SJohn Marino     return 0;
14108a45ae5f8SJohn Marino 
14109a45ae5f8SJohn Marino   return 1;
14110a45ae5f8SJohn Marino }
14111a45ae5f8SJohn Marino 
14112c50c785cSJohn Marino /* Create new breakpoint locations for B (a hardware or software breakpoint)
14113c50c785cSJohn Marino    based on SALS and SALS_END.  If SALS_END.NELTS is not zero, then B is
14114c50c785cSJohn Marino    a ranged breakpoint.  */
14115c50c785cSJohn Marino 
14116c50c785cSJohn Marino void
update_breakpoint_locations(struct breakpoint * b,struct symtabs_and_lines sals,struct symtabs_and_lines sals_end)141175796c8dcSSimon Schubert update_breakpoint_locations (struct breakpoint *b,
14118c50c785cSJohn Marino 			     struct symtabs_and_lines sals,
14119c50c785cSJohn Marino 			     struct symtabs_and_lines sals_end)
141205796c8dcSSimon Schubert {
141215796c8dcSSimon Schubert   int i;
141225796c8dcSSimon Schubert   struct bp_location *existing_locations = b->loc;
141235796c8dcSSimon Schubert 
14124a45ae5f8SJohn Marino   if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
14125a45ae5f8SJohn Marino     {
14126a45ae5f8SJohn Marino       /* Ranged breakpoints have only one start location and one end
14127a45ae5f8SJohn Marino 	 location.  */
14128a45ae5f8SJohn Marino       b->enable_state = bp_disabled;
14129a45ae5f8SJohn Marino       update_global_location_list (1);
14130a45ae5f8SJohn Marino       printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14131a45ae5f8SJohn Marino 			   "multiple locations found\n"),
14132a45ae5f8SJohn Marino 			 b->number);
14133a45ae5f8SJohn Marino       return;
14134a45ae5f8SJohn Marino     }
14135c50c785cSJohn Marino 
14136c50c785cSJohn Marino   /* If there's no new locations, and all existing locations are
14137c50c785cSJohn Marino      pending, don't do anything.  This optimizes the common case where
14138c50c785cSJohn Marino      all locations are in the same shared library, that was unloaded.
14139c50c785cSJohn Marino      We'd like to retain the location, so that when the library is
14140c50c785cSJohn Marino      loaded again, we don't loose the enabled/disabled status of the
14141c50c785cSJohn Marino      individual locations.  */
141425796c8dcSSimon Schubert   if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
141435796c8dcSSimon Schubert     return;
141445796c8dcSSimon Schubert 
141455796c8dcSSimon Schubert   b->loc = NULL;
141465796c8dcSSimon Schubert 
141475796c8dcSSimon Schubert   for (i = 0; i < sals.nelts; ++i)
141485796c8dcSSimon Schubert     {
14149a45ae5f8SJohn Marino       struct bp_location *new_loc;
14150a45ae5f8SJohn Marino 
14151a45ae5f8SJohn Marino       switch_to_program_space_and_thread (sals.sals[i].pspace);
14152a45ae5f8SJohn Marino 
14153a45ae5f8SJohn Marino       new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
141545796c8dcSSimon Schubert 
141555796c8dcSSimon Schubert       /* Reparse conditions, they might contain references to the
141565796c8dcSSimon Schubert 	 old symtab.  */
141575796c8dcSSimon Schubert       if (b->cond_string != NULL)
141585796c8dcSSimon Schubert 	{
14159*ef5ccd6cSJohn Marino 	  const char *s;
14160*ef5ccd6cSJohn Marino 	  volatile struct gdb_exception e;
141615796c8dcSSimon Schubert 
141625796c8dcSSimon Schubert 	  s = b->cond_string;
141635796c8dcSSimon Schubert 	  TRY_CATCH (e, RETURN_MASK_ERROR)
141645796c8dcSSimon Schubert 	    {
14165*ef5ccd6cSJohn Marino 	      new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
14166*ef5ccd6cSJohn Marino 					   block_for_pc (sals.sals[i].pc),
141675796c8dcSSimon Schubert 					   0);
141685796c8dcSSimon Schubert 	    }
141695796c8dcSSimon Schubert 	  if (e.reason < 0)
141705796c8dcSSimon Schubert 	    {
14171c50c785cSJohn Marino 	      warning (_("failed to reevaluate condition "
14172c50c785cSJohn Marino 			 "for breakpoint %d: %s"),
141735796c8dcSSimon Schubert 		       b->number, e.message);
141745796c8dcSSimon Schubert 	      new_loc->enabled = 0;
141755796c8dcSSimon Schubert 	    }
141765796c8dcSSimon Schubert 	}
141775796c8dcSSimon Schubert 
14178c50c785cSJohn Marino       if (sals_end.nelts)
14179c50c785cSJohn Marino 	{
14180c50c785cSJohn Marino 	  CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
14181c50c785cSJohn Marino 
14182c50c785cSJohn Marino 	  new_loc->length = end - sals.sals[0].pc + 1;
14183c50c785cSJohn Marino 	}
141845796c8dcSSimon Schubert     }
141855796c8dcSSimon Schubert 
141865796c8dcSSimon Schubert   /* Update locations of permanent breakpoints.  */
141875796c8dcSSimon Schubert   if (b->enable_state == bp_permanent)
141885796c8dcSSimon Schubert     make_breakpoint_permanent (b);
141895796c8dcSSimon Schubert 
14190c50c785cSJohn Marino   /* If possible, carry over 'disable' status from existing
14191c50c785cSJohn Marino      breakpoints.  */
141925796c8dcSSimon Schubert   {
141935796c8dcSSimon Schubert     struct bp_location *e = existing_locations;
141945796c8dcSSimon Schubert     /* If there are multiple breakpoints with the same function name,
141955796c8dcSSimon Schubert        e.g. for inline functions, comparing function names won't work.
141965796c8dcSSimon Schubert        Instead compare pc addresses; this is just a heuristic as things
141975796c8dcSSimon Schubert        may have moved, but in practice it gives the correct answer
141985796c8dcSSimon Schubert        often enough until a better solution is found.  */
141995796c8dcSSimon Schubert     int have_ambiguous_names = ambiguous_names_p (b->loc);
142005796c8dcSSimon Schubert 
142015796c8dcSSimon Schubert     for (; e; e = e->next)
142025796c8dcSSimon Schubert       {
142035796c8dcSSimon Schubert 	if (!e->enabled && e->function_name)
142045796c8dcSSimon Schubert 	  {
142055796c8dcSSimon Schubert 	    struct bp_location *l = b->loc;
142065796c8dcSSimon Schubert 	    if (have_ambiguous_names)
142075796c8dcSSimon Schubert 	      {
142085796c8dcSSimon Schubert 		for (; l; l = l->next)
14209c50c785cSJohn Marino 		  if (breakpoint_locations_match (e, l))
142105796c8dcSSimon Schubert 		    {
142115796c8dcSSimon Schubert 		      l->enabled = 0;
142125796c8dcSSimon Schubert 		      break;
142135796c8dcSSimon Schubert 		    }
142145796c8dcSSimon Schubert 	      }
142155796c8dcSSimon Schubert 	    else
142165796c8dcSSimon Schubert 	      {
142175796c8dcSSimon Schubert 		for (; l; l = l->next)
142185796c8dcSSimon Schubert 		  if (l->function_name
142195796c8dcSSimon Schubert 		      && strcmp (e->function_name, l->function_name) == 0)
142205796c8dcSSimon Schubert 		    {
142215796c8dcSSimon Schubert 		      l->enabled = 0;
142225796c8dcSSimon Schubert 		      break;
142235796c8dcSSimon Schubert 		    }
142245796c8dcSSimon Schubert 	      }
142255796c8dcSSimon Schubert 	  }
142265796c8dcSSimon Schubert       }
142275796c8dcSSimon Schubert   }
142285796c8dcSSimon Schubert 
14229a45ae5f8SJohn Marino   if (!locations_are_equal (existing_locations, b->loc))
14230a45ae5f8SJohn Marino     observer_notify_breakpoint_modified (b);
14231a45ae5f8SJohn Marino 
142325796c8dcSSimon Schubert   update_global_location_list (1);
142335796c8dcSSimon Schubert }
142345796c8dcSSimon Schubert 
14235c50c785cSJohn Marino /* Find the SaL locations corresponding to the given ADDR_STRING.
14236c50c785cSJohn Marino    On return, FOUND will be 1 if any SaL was found, zero otherwise.  */
142375796c8dcSSimon Schubert 
14238c50c785cSJohn Marino static struct symtabs_and_lines
addr_string_to_sals(struct breakpoint * b,char * addr_string,int * found)14239c50c785cSJohn Marino addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
142405796c8dcSSimon Schubert {
142415796c8dcSSimon Schubert   char *s;
14242c50c785cSJohn Marino   struct symtabs_and_lines sals = {0};
14243a45ae5f8SJohn Marino   volatile struct gdb_exception e;
142445796c8dcSSimon Schubert 
14245*ef5ccd6cSJohn Marino   gdb_assert (b->ops != NULL);
14246c50c785cSJohn Marino   s = addr_string;
14247cf7f2e2dSJohn Marino 
142485796c8dcSSimon Schubert   TRY_CATCH (e, RETURN_MASK_ERROR)
142495796c8dcSSimon Schubert     {
14250*ef5ccd6cSJohn Marino       b->ops->decode_linespec (b, &s, &sals);
142515796c8dcSSimon Schubert     }
142525796c8dcSSimon Schubert   if (e.reason < 0)
142535796c8dcSSimon Schubert     {
142545796c8dcSSimon Schubert       int not_found_and_ok = 0;
14255c50c785cSJohn Marino       /* For pending breakpoints, it's expected that parsing will
14256c50c785cSJohn Marino 	 fail until the right shared library is loaded.  User has
14257c50c785cSJohn Marino 	 already told to create pending breakpoints and don't need
14258c50c785cSJohn Marino 	 extra messages.  If breakpoint is in bp_shlib_disabled
14259c50c785cSJohn Marino 	 state, then user already saw the message about that
14260c50c785cSJohn Marino 	 breakpoint being disabled, and don't want to see more
14261c50c785cSJohn Marino 	 errors.  */
14262c50c785cSJohn Marino       if (e.error == NOT_FOUND_ERROR
142635796c8dcSSimon Schubert 	  && (b->condition_not_parsed
142645796c8dcSSimon Schubert 	      || (b->loc && b->loc->shlib_disabled)
14265a45ae5f8SJohn Marino 	      || (b->loc && b->loc->pspace->executing_startup)
142665796c8dcSSimon Schubert 	      || b->enable_state == bp_disabled))
142675796c8dcSSimon Schubert 	not_found_and_ok = 1;
142685796c8dcSSimon Schubert 
142695796c8dcSSimon Schubert       if (!not_found_and_ok)
142705796c8dcSSimon Schubert 	{
142715796c8dcSSimon Schubert 	  /* We surely don't want to warn about the same breakpoint
142725796c8dcSSimon Schubert 	     10 times.  One solution, implemented here, is disable
142735796c8dcSSimon Schubert 	     the breakpoint on error.  Another solution would be to
142745796c8dcSSimon Schubert 	     have separate 'warning emitted' flag.  Since this
142755796c8dcSSimon Schubert 	     happens only when a binary has changed, I don't know
142765796c8dcSSimon Schubert 	     which approach is better.  */
142775796c8dcSSimon Schubert 	  b->enable_state = bp_disabled;
142785796c8dcSSimon Schubert 	  throw_exception (e);
142795796c8dcSSimon Schubert 	}
142805796c8dcSSimon Schubert     }
142815796c8dcSSimon Schubert 
14282c50c785cSJohn Marino   if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
14283cf7f2e2dSJohn Marino     {
14284a45ae5f8SJohn Marino       int i;
14285cf7f2e2dSJohn Marino 
14286a45ae5f8SJohn Marino       for (i = 0; i < sals.nelts; ++i)
14287a45ae5f8SJohn Marino 	resolve_sal_pc (&sals.sals[i]);
142885796c8dcSSimon Schubert       if (b->condition_not_parsed && s && s[0])
142895796c8dcSSimon Schubert 	{
14290*ef5ccd6cSJohn Marino 	  char *cond_string, *extra_string;
14291*ef5ccd6cSJohn Marino 	  int thread, task;
142925796c8dcSSimon Schubert 
142935796c8dcSSimon Schubert 	  find_condition_and_thread (s, sals.sals[0].pc,
14294*ef5ccd6cSJohn Marino 				     &cond_string, &thread, &task,
14295*ef5ccd6cSJohn Marino 				     &extra_string);
142965796c8dcSSimon Schubert 	  if (cond_string)
142975796c8dcSSimon Schubert 	    b->cond_string = cond_string;
142985796c8dcSSimon Schubert 	  b->thread = thread;
142995796c8dcSSimon Schubert 	  b->task = task;
14300*ef5ccd6cSJohn Marino 	  if (extra_string)
14301*ef5ccd6cSJohn Marino 	    b->extra_string = extra_string;
143025796c8dcSSimon Schubert 	  b->condition_not_parsed = 0;
143035796c8dcSSimon Schubert 	}
14304cf7f2e2dSJohn Marino 
14305*ef5ccd6cSJohn Marino       if (b->type == bp_static_tracepoint && !strace_marker_p (b))
14306cf7f2e2dSJohn Marino 	sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
14307cf7f2e2dSJohn Marino 
14308c50c785cSJohn Marino       *found = 1;
14309c50c785cSJohn Marino     }
14310c50c785cSJohn Marino   else
14311c50c785cSJohn Marino     *found = 0;
14312c50c785cSJohn Marino 
14313c50c785cSJohn Marino   return sals;
14314c50c785cSJohn Marino }
14315c50c785cSJohn Marino 
14316a45ae5f8SJohn Marino /* The default re_set method, for typical hardware or software
14317a45ae5f8SJohn Marino    breakpoints.  Reevaluate the breakpoint and recreate its
14318a45ae5f8SJohn Marino    locations.  */
14319c50c785cSJohn Marino 
14320c50c785cSJohn Marino static void
breakpoint_re_set_default(struct breakpoint * b)14321a45ae5f8SJohn Marino breakpoint_re_set_default (struct breakpoint *b)
14322c50c785cSJohn Marino {
14323c50c785cSJohn Marino   int found;
14324c50c785cSJohn Marino   struct symtabs_and_lines sals, sals_end;
14325c50c785cSJohn Marino   struct symtabs_and_lines expanded = {0};
14326c50c785cSJohn Marino   struct symtabs_and_lines expanded_end = {0};
14327c50c785cSJohn Marino 
14328c50c785cSJohn Marino   sals = addr_string_to_sals (b, b->addr_string, &found);
14329c50c785cSJohn Marino   if (found)
14330c50c785cSJohn Marino     {
14331c50c785cSJohn Marino       make_cleanup (xfree, sals.sals);
14332a45ae5f8SJohn Marino       expanded = sals;
14333cf7f2e2dSJohn Marino     }
14334cf7f2e2dSJohn Marino 
14335c50c785cSJohn Marino   if (b->addr_string_range_end)
14336c50c785cSJohn Marino     {
14337c50c785cSJohn Marino       sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
14338c50c785cSJohn Marino       if (found)
14339c50c785cSJohn Marino 	{
14340c50c785cSJohn Marino 	  make_cleanup (xfree, sals_end.sals);
14341a45ae5f8SJohn Marino 	  expanded_end = sals_end;
14342c50c785cSJohn Marino 	}
14343c50c785cSJohn Marino     }
14344c50c785cSJohn Marino 
14345c50c785cSJohn Marino   update_breakpoint_locations (b, expanded, expanded_end);
14346a45ae5f8SJohn Marino }
14347a45ae5f8SJohn Marino 
14348*ef5ccd6cSJohn Marino /* Default method for creating SALs from an address string.  It basically
14349*ef5ccd6cSJohn Marino    calls parse_breakpoint_sals.  Return 1 for success, zero for failure.  */
14350*ef5ccd6cSJohn Marino 
14351*ef5ccd6cSJohn Marino static void
create_sals_from_address_default(char ** arg,struct linespec_result * canonical,enum bptype type_wanted,char * addr_start,char ** copy_arg)14352*ef5ccd6cSJohn Marino create_sals_from_address_default (char **arg,
14353*ef5ccd6cSJohn Marino 				  struct linespec_result *canonical,
14354*ef5ccd6cSJohn Marino 				  enum bptype type_wanted,
14355*ef5ccd6cSJohn Marino 				  char *addr_start, char **copy_arg)
14356*ef5ccd6cSJohn Marino {
14357*ef5ccd6cSJohn Marino   parse_breakpoint_sals (arg, canonical);
14358*ef5ccd6cSJohn Marino }
14359*ef5ccd6cSJohn Marino 
14360*ef5ccd6cSJohn Marino /* Call create_breakpoints_sal for the given arguments.  This is the default
14361*ef5ccd6cSJohn Marino    function for the `create_breakpoints_sal' method of
14362*ef5ccd6cSJohn Marino    breakpoint_ops.  */
14363*ef5ccd6cSJohn Marino 
14364*ef5ccd6cSJohn Marino static void
create_breakpoints_sal_default(struct gdbarch * gdbarch,struct linespec_result * canonical,struct linespec_sals * lsal,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)14365*ef5ccd6cSJohn Marino create_breakpoints_sal_default (struct gdbarch *gdbarch,
14366*ef5ccd6cSJohn Marino 				struct linespec_result *canonical,
14367*ef5ccd6cSJohn Marino 				struct linespec_sals *lsal,
14368*ef5ccd6cSJohn Marino 				char *cond_string,
14369*ef5ccd6cSJohn Marino 				char *extra_string,
14370*ef5ccd6cSJohn Marino 				enum bptype type_wanted,
14371*ef5ccd6cSJohn Marino 				enum bpdisp disposition,
14372*ef5ccd6cSJohn Marino 				int thread,
14373*ef5ccd6cSJohn Marino 				int task, int ignore_count,
14374*ef5ccd6cSJohn Marino 				const struct breakpoint_ops *ops,
14375*ef5ccd6cSJohn Marino 				int from_tty, int enabled,
14376*ef5ccd6cSJohn Marino 				int internal, unsigned flags)
14377*ef5ccd6cSJohn Marino {
14378*ef5ccd6cSJohn Marino   create_breakpoints_sal (gdbarch, canonical, cond_string,
14379*ef5ccd6cSJohn Marino 			  extra_string,
14380*ef5ccd6cSJohn Marino 			  type_wanted, disposition,
14381*ef5ccd6cSJohn Marino 			  thread, task, ignore_count, ops, from_tty,
14382*ef5ccd6cSJohn Marino 			  enabled, internal, flags);
14383*ef5ccd6cSJohn Marino }
14384*ef5ccd6cSJohn Marino 
14385*ef5ccd6cSJohn Marino /* Decode the line represented by S by calling decode_line_full.  This is the
14386*ef5ccd6cSJohn Marino    default function for the `decode_linespec' method of breakpoint_ops.  */
14387*ef5ccd6cSJohn Marino 
14388*ef5ccd6cSJohn Marino static void
decode_linespec_default(struct breakpoint * b,char ** s,struct symtabs_and_lines * sals)14389*ef5ccd6cSJohn Marino decode_linespec_default (struct breakpoint *b, char **s,
14390*ef5ccd6cSJohn Marino 			 struct symtabs_and_lines *sals)
14391*ef5ccd6cSJohn Marino {
14392*ef5ccd6cSJohn Marino   struct linespec_result canonical;
14393*ef5ccd6cSJohn Marino 
14394*ef5ccd6cSJohn Marino   init_linespec_result (&canonical);
14395*ef5ccd6cSJohn Marino   decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
14396*ef5ccd6cSJohn Marino 		    (struct symtab *) NULL, 0,
14397*ef5ccd6cSJohn Marino 		    &canonical, multiple_symbols_all,
14398*ef5ccd6cSJohn Marino 		    b->filter);
14399*ef5ccd6cSJohn Marino 
14400*ef5ccd6cSJohn Marino   /* We should get 0 or 1 resulting SALs.  */
14401*ef5ccd6cSJohn Marino   gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
14402*ef5ccd6cSJohn Marino 
14403*ef5ccd6cSJohn Marino   if (VEC_length (linespec_sals, canonical.sals) > 0)
14404*ef5ccd6cSJohn Marino     {
14405*ef5ccd6cSJohn Marino       struct linespec_sals *lsal;
14406*ef5ccd6cSJohn Marino 
14407*ef5ccd6cSJohn Marino       lsal = VEC_index (linespec_sals, canonical.sals, 0);
14408*ef5ccd6cSJohn Marino       *sals = lsal->sals;
14409*ef5ccd6cSJohn Marino       /* Arrange it so the destructor does not free the
14410*ef5ccd6cSJohn Marino 	 contents.  */
14411*ef5ccd6cSJohn Marino       lsal->sals.sals = NULL;
14412*ef5ccd6cSJohn Marino     }
14413*ef5ccd6cSJohn Marino 
14414*ef5ccd6cSJohn Marino   destroy_linespec_result (&canonical);
14415*ef5ccd6cSJohn Marino }
14416*ef5ccd6cSJohn Marino 
14417a45ae5f8SJohn Marino /* Prepare the global context for a re-set of breakpoint B.  */
14418a45ae5f8SJohn Marino 
14419a45ae5f8SJohn Marino static struct cleanup *
prepare_re_set_context(struct breakpoint * b)14420a45ae5f8SJohn Marino prepare_re_set_context (struct breakpoint *b)
14421a45ae5f8SJohn Marino {
14422a45ae5f8SJohn Marino   struct cleanup *cleanups;
14423a45ae5f8SJohn Marino 
14424a45ae5f8SJohn Marino   input_radix = b->input_radix;
14425a45ae5f8SJohn Marino   cleanups = save_current_space_and_thread ();
14426a45ae5f8SJohn Marino   if (b->pspace != NULL)
14427a45ae5f8SJohn Marino     switch_to_program_space_and_thread (b->pspace);
14428a45ae5f8SJohn Marino   set_language (b->language);
14429a45ae5f8SJohn Marino 
14430a45ae5f8SJohn Marino   return cleanups;
14431c50c785cSJohn Marino }
14432c50c785cSJohn Marino 
14433c50c785cSJohn Marino /* Reset a breakpoint given it's struct breakpoint * BINT.
14434c50c785cSJohn Marino    The value we return ends up being the return value from catch_errors.
14435c50c785cSJohn Marino    Unused in this case.  */
14436c50c785cSJohn Marino 
14437c50c785cSJohn Marino static int
breakpoint_re_set_one(void * bint)14438c50c785cSJohn Marino breakpoint_re_set_one (void *bint)
14439c50c785cSJohn Marino {
14440c50c785cSJohn Marino   /* Get past catch_errs.  */
14441c50c785cSJohn Marino   struct breakpoint *b = (struct breakpoint *) bint;
14442a45ae5f8SJohn Marino   struct cleanup *cleanups;
14443c50c785cSJohn Marino 
14444a45ae5f8SJohn Marino   cleanups = prepare_re_set_context (b);
14445a45ae5f8SJohn Marino   b->ops->re_set (b);
14446a45ae5f8SJohn Marino   do_cleanups (cleanups);
144475796c8dcSSimon Schubert   return 0;
144485796c8dcSSimon Schubert }
144495796c8dcSSimon Schubert 
144505796c8dcSSimon Schubert /* Re-set all breakpoints after symbols have been re-loaded.  */
144515796c8dcSSimon Schubert void
breakpoint_re_set(void)144525796c8dcSSimon Schubert breakpoint_re_set (void)
144535796c8dcSSimon Schubert {
14454c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
144555796c8dcSSimon Schubert   enum language save_language;
144565796c8dcSSimon Schubert   int save_input_radix;
14457cf7f2e2dSJohn Marino   struct cleanup *old_chain;
144585796c8dcSSimon Schubert 
144595796c8dcSSimon Schubert   save_language = current_language->la_language;
144605796c8dcSSimon Schubert   save_input_radix = input_radix;
14461cf7f2e2dSJohn Marino   old_chain = save_current_program_space ();
14462cf7f2e2dSJohn Marino 
14463c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
144645796c8dcSSimon Schubert   {
14465c50c785cSJohn Marino     /* Format possible error msg.  */
144665796c8dcSSimon Schubert     char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
144675796c8dcSSimon Schubert 				b->number);
144685796c8dcSSimon Schubert     struct cleanup *cleanups = make_cleanup (xfree, message);
144695796c8dcSSimon Schubert     catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
144705796c8dcSSimon Schubert     do_cleanups (cleanups);
144715796c8dcSSimon Schubert   }
144725796c8dcSSimon Schubert   set_language (save_language);
144735796c8dcSSimon Schubert   input_radix = save_input_radix;
144745796c8dcSSimon Schubert 
144755796c8dcSSimon Schubert   jit_breakpoint_re_set ();
144765796c8dcSSimon Schubert 
14477cf7f2e2dSJohn Marino   do_cleanups (old_chain);
14478cf7f2e2dSJohn Marino 
14479c50c785cSJohn Marino   create_overlay_event_breakpoint ();
14480c50c785cSJohn Marino   create_longjmp_master_breakpoint ();
14481c50c785cSJohn Marino   create_std_terminate_master_breakpoint ();
14482c50c785cSJohn Marino   create_exception_master_breakpoint ();
144835796c8dcSSimon Schubert }
144845796c8dcSSimon Schubert 
144855796c8dcSSimon Schubert /* Reset the thread number of this breakpoint:
144865796c8dcSSimon Schubert 
144875796c8dcSSimon Schubert    - If the breakpoint is for all threads, leave it as-is.
144885796c8dcSSimon Schubert    - Else, reset it to the current thread for inferior_ptid.  */
144895796c8dcSSimon Schubert void
breakpoint_re_set_thread(struct breakpoint * b)144905796c8dcSSimon Schubert breakpoint_re_set_thread (struct breakpoint *b)
144915796c8dcSSimon Schubert {
144925796c8dcSSimon Schubert   if (b->thread != -1)
144935796c8dcSSimon Schubert     {
144945796c8dcSSimon Schubert       if (in_thread_list (inferior_ptid))
144955796c8dcSSimon Schubert 	b->thread = pid_to_thread_id (inferior_ptid);
14496cf7f2e2dSJohn Marino 
14497cf7f2e2dSJohn Marino       /* We're being called after following a fork.  The new fork is
14498cf7f2e2dSJohn Marino 	 selected as current, and unless this was a vfork will have a
14499cf7f2e2dSJohn Marino 	 different program space from the original thread.  Reset that
14500cf7f2e2dSJohn Marino 	 as well.  */
14501cf7f2e2dSJohn Marino       b->loc->pspace = current_program_space;
145025796c8dcSSimon Schubert     }
145035796c8dcSSimon Schubert }
145045796c8dcSSimon Schubert 
145055796c8dcSSimon Schubert /* Set ignore-count of breakpoint number BPTNUM to COUNT.
145065796c8dcSSimon Schubert    If from_tty is nonzero, it prints a message to that effect,
145075796c8dcSSimon Schubert    which ends with a period (no newline).  */
145085796c8dcSSimon Schubert 
145095796c8dcSSimon Schubert void
set_ignore_count(int bptnum,int count,int from_tty)145105796c8dcSSimon Schubert set_ignore_count (int bptnum, int count, int from_tty)
145115796c8dcSSimon Schubert {
145125796c8dcSSimon Schubert   struct breakpoint *b;
145135796c8dcSSimon Schubert 
145145796c8dcSSimon Schubert   if (count < 0)
145155796c8dcSSimon Schubert     count = 0;
145165796c8dcSSimon Schubert 
145175796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
145185796c8dcSSimon Schubert     if (b->number == bptnum)
145195796c8dcSSimon Schubert     {
14520cf7f2e2dSJohn Marino       if (is_tracepoint (b))
14521cf7f2e2dSJohn Marino 	{
14522cf7f2e2dSJohn Marino 	  if (from_tty && count != 0)
14523cf7f2e2dSJohn Marino 	    printf_filtered (_("Ignore count ignored for tracepoint %d."),
14524cf7f2e2dSJohn Marino 			     bptnum);
14525cf7f2e2dSJohn Marino 	  return;
14526cf7f2e2dSJohn Marino 	}
14527cf7f2e2dSJohn Marino 
145285796c8dcSSimon Schubert       b->ignore_count = count;
145295796c8dcSSimon Schubert       if (from_tty)
145305796c8dcSSimon Schubert 	{
145315796c8dcSSimon Schubert 	  if (count == 0)
14532c50c785cSJohn Marino 	    printf_filtered (_("Will stop next time "
14533c50c785cSJohn Marino 			       "breakpoint %d is reached."),
145345796c8dcSSimon Schubert 			     bptnum);
145355796c8dcSSimon Schubert 	  else if (count == 1)
145365796c8dcSSimon Schubert 	    printf_filtered (_("Will ignore next crossing of breakpoint %d."),
145375796c8dcSSimon Schubert 			     bptnum);
145385796c8dcSSimon Schubert 	  else
14539c50c785cSJohn Marino 	    printf_filtered (_("Will ignore next %d "
14540c50c785cSJohn Marino 			       "crossings of breakpoint %d."),
145415796c8dcSSimon Schubert 			     count, bptnum);
145425796c8dcSSimon Schubert 	}
14543a45ae5f8SJohn Marino       observer_notify_breakpoint_modified (b);
145445796c8dcSSimon Schubert       return;
145455796c8dcSSimon Schubert     }
145465796c8dcSSimon Schubert 
145475796c8dcSSimon Schubert   error (_("No breakpoint number %d."), bptnum);
145485796c8dcSSimon Schubert }
145495796c8dcSSimon Schubert 
145505796c8dcSSimon Schubert /* Command to set ignore-count of breakpoint N to COUNT.  */
145515796c8dcSSimon Schubert 
145525796c8dcSSimon Schubert static void
ignore_command(char * args,int from_tty)145535796c8dcSSimon Schubert ignore_command (char *args, int from_tty)
145545796c8dcSSimon Schubert {
145555796c8dcSSimon Schubert   char *p = args;
145565796c8dcSSimon Schubert   int num;
145575796c8dcSSimon Schubert 
145585796c8dcSSimon Schubert   if (p == 0)
145595796c8dcSSimon Schubert     error_no_arg (_("a breakpoint number"));
145605796c8dcSSimon Schubert 
145615796c8dcSSimon Schubert   num = get_number (&p);
145625796c8dcSSimon Schubert   if (num == 0)
145635796c8dcSSimon Schubert     error (_("bad breakpoint number: '%s'"), args);
145645796c8dcSSimon Schubert   if (*p == 0)
145655796c8dcSSimon Schubert     error (_("Second argument (specified ignore-count) is missing."));
145665796c8dcSSimon Schubert 
145675796c8dcSSimon Schubert   set_ignore_count (num,
145685796c8dcSSimon Schubert 		    longest_to_int (value_as_long (parse_and_eval (p))),
145695796c8dcSSimon Schubert 		    from_tty);
145705796c8dcSSimon Schubert   if (from_tty)
145715796c8dcSSimon Schubert     printf_filtered ("\n");
145725796c8dcSSimon Schubert }
145735796c8dcSSimon Schubert 
145745796c8dcSSimon Schubert /* Call FUNCTION on each of the breakpoints
145755796c8dcSSimon Schubert    whose numbers are given in ARGS.  */
145765796c8dcSSimon Schubert 
145775796c8dcSSimon Schubert static void
map_breakpoint_numbers(char * args,void (* function)(struct breakpoint *,void *),void * data)14578cf7f2e2dSJohn Marino map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
14579cf7f2e2dSJohn Marino 						      void *),
14580cf7f2e2dSJohn Marino 			void *data)
145815796c8dcSSimon Schubert {
145825796c8dcSSimon Schubert   int num;
145835796c8dcSSimon Schubert   struct breakpoint *b, *tmp;
145845796c8dcSSimon Schubert   int match;
14585c50c785cSJohn Marino   struct get_number_or_range_state state;
145865796c8dcSSimon Schubert 
14587c50c785cSJohn Marino   if (args == 0)
145885796c8dcSSimon Schubert     error_no_arg (_("one or more breakpoint numbers"));
145895796c8dcSSimon Schubert 
14590c50c785cSJohn Marino   init_number_or_range (&state, args);
145915796c8dcSSimon Schubert 
14592c50c785cSJohn Marino   while (!state.finished)
14593c50c785cSJohn Marino     {
14594c50c785cSJohn Marino       char *p = state.string;
14595c50c785cSJohn Marino 
14596c50c785cSJohn Marino       match = 0;
14597c50c785cSJohn Marino 
14598c50c785cSJohn Marino       num = get_number_or_range (&state);
145995796c8dcSSimon Schubert       if (num == 0)
146005796c8dcSSimon Schubert 	{
146015796c8dcSSimon Schubert 	  warning (_("bad breakpoint number at or near '%s'"), p);
146025796c8dcSSimon Schubert 	}
146035796c8dcSSimon Schubert       else
146045796c8dcSSimon Schubert 	{
146055796c8dcSSimon Schubert 	  ALL_BREAKPOINTS_SAFE (b, tmp)
146065796c8dcSSimon Schubert 	    if (b->number == num)
146075796c8dcSSimon Schubert 	      {
146085796c8dcSSimon Schubert 		match = 1;
14609a45ae5f8SJohn Marino 		function (b, data);
146105796c8dcSSimon Schubert 		break;
146115796c8dcSSimon Schubert 	      }
146125796c8dcSSimon Schubert 	  if (match == 0)
146135796c8dcSSimon Schubert 	    printf_unfiltered (_("No breakpoint number %d.\n"), num);
146145796c8dcSSimon Schubert 	}
146155796c8dcSSimon Schubert     }
146165796c8dcSSimon Schubert }
146175796c8dcSSimon Schubert 
146185796c8dcSSimon Schubert static struct bp_location *
find_location_by_number(char * number)146195796c8dcSSimon Schubert find_location_by_number (char *number)
146205796c8dcSSimon Schubert {
146215796c8dcSSimon Schubert   char *dot = strchr (number, '.');
146225796c8dcSSimon Schubert   char *p1;
146235796c8dcSSimon Schubert   int bp_num;
146245796c8dcSSimon Schubert   int loc_num;
146255796c8dcSSimon Schubert   struct breakpoint *b;
146265796c8dcSSimon Schubert   struct bp_location *loc;
146275796c8dcSSimon Schubert 
146285796c8dcSSimon Schubert   *dot = '\0';
146295796c8dcSSimon Schubert 
146305796c8dcSSimon Schubert   p1 = number;
14631c50c785cSJohn Marino   bp_num = get_number (&p1);
146325796c8dcSSimon Schubert   if (bp_num == 0)
146335796c8dcSSimon Schubert     error (_("Bad breakpoint number '%s'"), number);
146345796c8dcSSimon Schubert 
146355796c8dcSSimon Schubert   ALL_BREAKPOINTS (b)
146365796c8dcSSimon Schubert     if (b->number == bp_num)
146375796c8dcSSimon Schubert       {
146385796c8dcSSimon Schubert 	break;
146395796c8dcSSimon Schubert       }
146405796c8dcSSimon Schubert 
146415796c8dcSSimon Schubert   if (!b || b->number != bp_num)
146425796c8dcSSimon Schubert     error (_("Bad breakpoint number '%s'"), number);
146435796c8dcSSimon Schubert 
146445796c8dcSSimon Schubert   p1 = dot+1;
14645c50c785cSJohn Marino   loc_num = get_number (&p1);
146465796c8dcSSimon Schubert   if (loc_num == 0)
146475796c8dcSSimon Schubert     error (_("Bad breakpoint location number '%s'"), number);
146485796c8dcSSimon Schubert 
146495796c8dcSSimon Schubert   --loc_num;
146505796c8dcSSimon Schubert   loc = b->loc;
146515796c8dcSSimon Schubert   for (;loc_num && loc; --loc_num, loc = loc->next)
146525796c8dcSSimon Schubert     ;
146535796c8dcSSimon Schubert   if (!loc)
146545796c8dcSSimon Schubert     error (_("Bad breakpoint location number '%s'"), dot+1);
146555796c8dcSSimon Schubert 
146565796c8dcSSimon Schubert   return loc;
146575796c8dcSSimon Schubert }
146585796c8dcSSimon Schubert 
146595796c8dcSSimon Schubert 
146605796c8dcSSimon Schubert /* Set ignore-count of breakpoint number BPTNUM to COUNT.
146615796c8dcSSimon Schubert    If from_tty is nonzero, it prints a message to that effect,
146625796c8dcSSimon Schubert    which ends with a period (no newline).  */
146635796c8dcSSimon Schubert 
146645796c8dcSSimon Schubert void
disable_breakpoint(struct breakpoint * bpt)146655796c8dcSSimon Schubert disable_breakpoint (struct breakpoint *bpt)
146665796c8dcSSimon Schubert {
146675796c8dcSSimon Schubert   /* Never disable a watchpoint scope breakpoint; we want to
146685796c8dcSSimon Schubert      hit them when we leave scope so we can delete both the
146695796c8dcSSimon Schubert      watchpoint and its scope breakpoint at that time.  */
146705796c8dcSSimon Schubert   if (bpt->type == bp_watchpoint_scope)
146715796c8dcSSimon Schubert     return;
146725796c8dcSSimon Schubert 
146735796c8dcSSimon Schubert   /* You can't disable permanent breakpoints.  */
146745796c8dcSSimon Schubert   if (bpt->enable_state == bp_permanent)
146755796c8dcSSimon Schubert     return;
146765796c8dcSSimon Schubert 
146775796c8dcSSimon Schubert   bpt->enable_state = bp_disabled;
146785796c8dcSSimon Schubert 
14679*ef5ccd6cSJohn Marino   /* Mark breakpoint locations modified.  */
14680*ef5ccd6cSJohn Marino   mark_breakpoint_modified (bpt);
14681*ef5ccd6cSJohn Marino 
14682a45ae5f8SJohn Marino   if (target_supports_enable_disable_tracepoint ()
14683a45ae5f8SJohn Marino       && current_trace_status ()->running && is_tracepoint (bpt))
14684a45ae5f8SJohn Marino     {
14685a45ae5f8SJohn Marino       struct bp_location *location;
14686a45ae5f8SJohn Marino 
14687a45ae5f8SJohn Marino       for (location = bpt->loc; location; location = location->next)
14688a45ae5f8SJohn Marino 	target_disable_tracepoint (location);
14689a45ae5f8SJohn Marino     }
14690a45ae5f8SJohn Marino 
146915796c8dcSSimon Schubert   update_global_location_list (0);
146925796c8dcSSimon Schubert 
14693a45ae5f8SJohn Marino   observer_notify_breakpoint_modified (bpt);
14694a45ae5f8SJohn Marino }
14695a45ae5f8SJohn Marino 
14696a45ae5f8SJohn Marino /* A callback for iterate_over_related_breakpoints.  */
14697a45ae5f8SJohn Marino 
14698a45ae5f8SJohn Marino static void
do_disable_breakpoint(struct breakpoint * b,void * ignore)14699a45ae5f8SJohn Marino do_disable_breakpoint (struct breakpoint *b, void *ignore)
14700a45ae5f8SJohn Marino {
14701a45ae5f8SJohn Marino   disable_breakpoint (b);
147025796c8dcSSimon Schubert }
147035796c8dcSSimon Schubert 
14704cf7f2e2dSJohn Marino /* A callback for map_breakpoint_numbers that calls
14705cf7f2e2dSJohn Marino    disable_breakpoint.  */
14706cf7f2e2dSJohn Marino 
14707cf7f2e2dSJohn Marino static void
do_map_disable_breakpoint(struct breakpoint * b,void * ignore)14708cf7f2e2dSJohn Marino do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14709cf7f2e2dSJohn Marino {
14710a45ae5f8SJohn Marino   iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
14711cf7f2e2dSJohn Marino }
14712cf7f2e2dSJohn Marino 
147135796c8dcSSimon Schubert static void
disable_command(char * args,int from_tty)147145796c8dcSSimon Schubert disable_command (char *args, int from_tty)
147155796c8dcSSimon Schubert {
14716a45ae5f8SJohn Marino   if (args == 0)
14717a45ae5f8SJohn Marino     {
147185796c8dcSSimon Schubert       struct breakpoint *bpt;
14719cf7f2e2dSJohn Marino 
147205796c8dcSSimon Schubert       ALL_BREAKPOINTS (bpt)
14721a45ae5f8SJohn Marino 	if (user_breakpoint_p (bpt))
147225796c8dcSSimon Schubert 	  disable_breakpoint (bpt);
147235796c8dcSSimon Schubert     }
147245796c8dcSSimon Schubert   else if (strchr (args, '.'))
147255796c8dcSSimon Schubert     {
147265796c8dcSSimon Schubert       struct bp_location *loc = find_location_by_number (args);
147275796c8dcSSimon Schubert       if (loc)
14728a45ae5f8SJohn Marino 	{
14729*ef5ccd6cSJohn Marino 	  if (loc->enabled)
14730*ef5ccd6cSJohn Marino 	    {
147315796c8dcSSimon Schubert 	      loc->enabled = 0;
14732*ef5ccd6cSJohn Marino 	      mark_breakpoint_location_modified (loc);
14733*ef5ccd6cSJohn Marino 	    }
14734a45ae5f8SJohn Marino 	  if (target_supports_enable_disable_tracepoint ()
14735a45ae5f8SJohn Marino 	      && current_trace_status ()->running && loc->owner
14736a45ae5f8SJohn Marino 	      && is_tracepoint (loc->owner))
14737a45ae5f8SJohn Marino 	    target_disable_tracepoint (loc);
14738a45ae5f8SJohn Marino 	}
147395796c8dcSSimon Schubert       update_global_location_list (0);
147405796c8dcSSimon Schubert     }
147415796c8dcSSimon Schubert   else
14742cf7f2e2dSJohn Marino     map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
147435796c8dcSSimon Schubert }
147445796c8dcSSimon Schubert 
147455796c8dcSSimon Schubert static void
enable_breakpoint_disp(struct breakpoint * bpt,enum bpdisp disposition,int count)14746*ef5ccd6cSJohn Marino enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14747*ef5ccd6cSJohn Marino 			int count)
147485796c8dcSSimon Schubert {
14749cf7f2e2dSJohn Marino   int target_resources_ok;
147505796c8dcSSimon Schubert 
147515796c8dcSSimon Schubert   if (bpt->type == bp_hardware_breakpoint)
147525796c8dcSSimon Schubert     {
147535796c8dcSSimon Schubert       int i;
147545796c8dcSSimon Schubert       i = hw_breakpoint_used_count ();
147555796c8dcSSimon Schubert       target_resources_ok =
147565796c8dcSSimon Schubert 	target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
147575796c8dcSSimon Schubert 					    i + 1, 0);
147585796c8dcSSimon Schubert       if (target_resources_ok == 0)
147595796c8dcSSimon Schubert 	error (_("No hardware breakpoint support in the target."));
147605796c8dcSSimon Schubert       else if (target_resources_ok < 0)
147615796c8dcSSimon Schubert 	error (_("Hardware breakpoints used exceeds limit."));
147625796c8dcSSimon Schubert     }
147635796c8dcSSimon Schubert 
14764cf7f2e2dSJohn Marino   if (is_watchpoint (bpt))
147655796c8dcSSimon Schubert     {
14766a45ae5f8SJohn Marino       /* Initialize it just to avoid a GCC false warning.  */
14767a45ae5f8SJohn Marino       enum enable_state orig_enable_state = 0;
14768*ef5ccd6cSJohn Marino       volatile struct gdb_exception e;
147695796c8dcSSimon Schubert 
147705796c8dcSSimon Schubert       TRY_CATCH (e, RETURN_MASK_ALL)
147715796c8dcSSimon Schubert 	{
14772a45ae5f8SJohn Marino 	  struct watchpoint *w = (struct watchpoint *) bpt;
14773a45ae5f8SJohn Marino 
14774a45ae5f8SJohn Marino 	  orig_enable_state = bpt->enable_state;
14775a45ae5f8SJohn Marino 	  bpt->enable_state = bp_enabled;
14776a45ae5f8SJohn Marino 	  update_watchpoint (w, 1 /* reparse */);
147775796c8dcSSimon Schubert 	}
147785796c8dcSSimon Schubert       if (e.reason < 0)
147795796c8dcSSimon Schubert 	{
14780a45ae5f8SJohn Marino 	  bpt->enable_state = orig_enable_state;
147815796c8dcSSimon Schubert 	  exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
147825796c8dcSSimon Schubert 			     bpt->number);
147835796c8dcSSimon Schubert 	  return;
147845796c8dcSSimon Schubert 	}
147855796c8dcSSimon Schubert     }
147865796c8dcSSimon Schubert 
147875796c8dcSSimon Schubert   if (bpt->enable_state != bp_permanent)
147885796c8dcSSimon Schubert     bpt->enable_state = bp_enabled;
14789a45ae5f8SJohn Marino 
14790*ef5ccd6cSJohn Marino   bpt->enable_state = bp_enabled;
14791*ef5ccd6cSJohn Marino 
14792*ef5ccd6cSJohn Marino   /* Mark breakpoint locations modified.  */
14793*ef5ccd6cSJohn Marino   mark_breakpoint_modified (bpt);
14794*ef5ccd6cSJohn Marino 
14795a45ae5f8SJohn Marino   if (target_supports_enable_disable_tracepoint ()
14796a45ae5f8SJohn Marino       && current_trace_status ()->running && is_tracepoint (bpt))
14797a45ae5f8SJohn Marino     {
14798a45ae5f8SJohn Marino       struct bp_location *location;
14799a45ae5f8SJohn Marino 
14800a45ae5f8SJohn Marino       for (location = bpt->loc; location; location = location->next)
14801a45ae5f8SJohn Marino 	target_enable_tracepoint (location);
14802a45ae5f8SJohn Marino     }
14803a45ae5f8SJohn Marino 
148045796c8dcSSimon Schubert   bpt->disposition = disposition;
14805*ef5ccd6cSJohn Marino   bpt->enable_count = count;
148065796c8dcSSimon Schubert   update_global_location_list (1);
148075796c8dcSSimon Schubert 
14808a45ae5f8SJohn Marino   observer_notify_breakpoint_modified (bpt);
148095796c8dcSSimon Schubert }
148105796c8dcSSimon Schubert 
148115796c8dcSSimon Schubert 
148125796c8dcSSimon Schubert void
enable_breakpoint(struct breakpoint * bpt)148135796c8dcSSimon Schubert enable_breakpoint (struct breakpoint *bpt)
148145796c8dcSSimon Schubert {
14815*ef5ccd6cSJohn Marino   enable_breakpoint_disp (bpt, bpt->disposition, 0);
14816a45ae5f8SJohn Marino }
14817a45ae5f8SJohn Marino 
14818a45ae5f8SJohn Marino static void
do_enable_breakpoint(struct breakpoint * bpt,void * arg)14819a45ae5f8SJohn Marino do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14820a45ae5f8SJohn Marino {
14821a45ae5f8SJohn Marino   enable_breakpoint (bpt);
148225796c8dcSSimon Schubert }
148235796c8dcSSimon Schubert 
14824cf7f2e2dSJohn Marino /* A callback for map_breakpoint_numbers that calls
14825cf7f2e2dSJohn Marino    enable_breakpoint.  */
14826cf7f2e2dSJohn Marino 
14827cf7f2e2dSJohn Marino static void
do_map_enable_breakpoint(struct breakpoint * b,void * ignore)14828cf7f2e2dSJohn Marino do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14829cf7f2e2dSJohn Marino {
14830a45ae5f8SJohn Marino   iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
14831cf7f2e2dSJohn Marino }
14832cf7f2e2dSJohn Marino 
148335796c8dcSSimon Schubert /* The enable command enables the specified breakpoints (or all defined
148345796c8dcSSimon Schubert    breakpoints) so they once again become (or continue to be) effective
148355796c8dcSSimon Schubert    in stopping the inferior.  */
148365796c8dcSSimon Schubert 
148375796c8dcSSimon Schubert static void
enable_command(char * args,int from_tty)148385796c8dcSSimon Schubert enable_command (char *args, int from_tty)
148395796c8dcSSimon Schubert {
14840a45ae5f8SJohn Marino   if (args == 0)
14841a45ae5f8SJohn Marino     {
148425796c8dcSSimon Schubert       struct breakpoint *bpt;
14843cf7f2e2dSJohn Marino 
148445796c8dcSSimon Schubert       ALL_BREAKPOINTS (bpt)
14845a45ae5f8SJohn Marino 	if (user_breakpoint_p (bpt))
148465796c8dcSSimon Schubert 	  enable_breakpoint (bpt);
148475796c8dcSSimon Schubert     }
148485796c8dcSSimon Schubert   else if (strchr (args, '.'))
148495796c8dcSSimon Schubert     {
148505796c8dcSSimon Schubert       struct bp_location *loc = find_location_by_number (args);
148515796c8dcSSimon Schubert       if (loc)
14852a45ae5f8SJohn Marino 	{
14853*ef5ccd6cSJohn Marino 	  if (!loc->enabled)
14854*ef5ccd6cSJohn Marino 	    {
148555796c8dcSSimon Schubert 	      loc->enabled = 1;
14856*ef5ccd6cSJohn Marino 	      mark_breakpoint_location_modified (loc);
14857*ef5ccd6cSJohn Marino 	    }
14858a45ae5f8SJohn Marino 	  if (target_supports_enable_disable_tracepoint ()
14859a45ae5f8SJohn Marino 	      && current_trace_status ()->running && loc->owner
14860a45ae5f8SJohn Marino 	      && is_tracepoint (loc->owner))
14861a45ae5f8SJohn Marino 	    target_enable_tracepoint (loc);
14862a45ae5f8SJohn Marino 	}
148635796c8dcSSimon Schubert       update_global_location_list (1);
148645796c8dcSSimon Schubert     }
148655796c8dcSSimon Schubert   else
14866cf7f2e2dSJohn Marino     map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
148675796c8dcSSimon Schubert }
148685796c8dcSSimon Schubert 
14869*ef5ccd6cSJohn Marino /* This struct packages up disposition data for application to multiple
14870*ef5ccd6cSJohn Marino    breakpoints.  */
14871*ef5ccd6cSJohn Marino 
14872*ef5ccd6cSJohn Marino struct disp_data
14873*ef5ccd6cSJohn Marino {
14874*ef5ccd6cSJohn Marino   enum bpdisp disp;
14875*ef5ccd6cSJohn Marino   int count;
14876*ef5ccd6cSJohn Marino };
14877*ef5ccd6cSJohn Marino 
148785796c8dcSSimon Schubert static void
do_enable_breakpoint_disp(struct breakpoint * bpt,void * arg)14879a45ae5f8SJohn Marino do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
148805796c8dcSSimon Schubert {
14881*ef5ccd6cSJohn Marino   struct disp_data disp_data = *(struct disp_data *) arg;
14882a45ae5f8SJohn Marino 
14883*ef5ccd6cSJohn Marino   enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
14884a45ae5f8SJohn Marino }
14885a45ae5f8SJohn Marino 
14886a45ae5f8SJohn Marino static void
do_map_enable_once_breakpoint(struct breakpoint * bpt,void * ignore)14887a45ae5f8SJohn Marino do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
14888a45ae5f8SJohn Marino {
14889*ef5ccd6cSJohn Marino   struct disp_data disp = { disp_disable, 1 };
14890a45ae5f8SJohn Marino 
14891a45ae5f8SJohn Marino   iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
148925796c8dcSSimon Schubert }
148935796c8dcSSimon Schubert 
148945796c8dcSSimon Schubert static void
enable_once_command(char * args,int from_tty)148955796c8dcSSimon Schubert enable_once_command (char *args, int from_tty)
148965796c8dcSSimon Schubert {
14897a45ae5f8SJohn Marino   map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
148985796c8dcSSimon Schubert }
148995796c8dcSSimon Schubert 
149005796c8dcSSimon Schubert static void
do_map_enable_count_breakpoint(struct breakpoint * bpt,void * countptr)14901*ef5ccd6cSJohn Marino do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14902*ef5ccd6cSJohn Marino {
14903*ef5ccd6cSJohn Marino   struct disp_data disp = { disp_disable, *(int *) countptr };
14904*ef5ccd6cSJohn Marino 
14905*ef5ccd6cSJohn Marino   iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14906*ef5ccd6cSJohn Marino }
14907*ef5ccd6cSJohn Marino 
14908*ef5ccd6cSJohn Marino static void
enable_count_command(char * args,int from_tty)14909*ef5ccd6cSJohn Marino enable_count_command (char *args, int from_tty)
14910*ef5ccd6cSJohn Marino {
14911*ef5ccd6cSJohn Marino   int count = get_number (&args);
14912*ef5ccd6cSJohn Marino 
14913*ef5ccd6cSJohn Marino   map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14914*ef5ccd6cSJohn Marino }
14915*ef5ccd6cSJohn Marino 
14916*ef5ccd6cSJohn Marino static void
do_map_enable_delete_breakpoint(struct breakpoint * bpt,void * ignore)14917a45ae5f8SJohn Marino do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
149185796c8dcSSimon Schubert {
14919*ef5ccd6cSJohn Marino   struct disp_data disp = { disp_del, 1 };
14920a45ae5f8SJohn Marino 
14921a45ae5f8SJohn Marino   iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
149225796c8dcSSimon Schubert }
149235796c8dcSSimon Schubert 
149245796c8dcSSimon Schubert static void
enable_delete_command(char * args,int from_tty)149255796c8dcSSimon Schubert enable_delete_command (char *args, int from_tty)
149265796c8dcSSimon Schubert {
14927a45ae5f8SJohn Marino   map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
149285796c8dcSSimon Schubert }
149295796c8dcSSimon Schubert 
149305796c8dcSSimon Schubert static void
set_breakpoint_cmd(char * args,int from_tty)149315796c8dcSSimon Schubert set_breakpoint_cmd (char *args, int from_tty)
149325796c8dcSSimon Schubert {
149335796c8dcSSimon Schubert }
149345796c8dcSSimon Schubert 
149355796c8dcSSimon Schubert static void
show_breakpoint_cmd(char * args,int from_tty)149365796c8dcSSimon Schubert show_breakpoint_cmd (char *args, int from_tty)
149375796c8dcSSimon Schubert {
149385796c8dcSSimon Schubert }
149395796c8dcSSimon Schubert 
14940cf7f2e2dSJohn Marino /* Invalidate last known value of any hardware watchpoint if
14941cf7f2e2dSJohn Marino    the memory which that value represents has been written to by
14942cf7f2e2dSJohn Marino    GDB itself.  */
14943cf7f2e2dSJohn Marino 
14944cf7f2e2dSJohn Marino static void
invalidate_bp_value_on_memory_change(struct inferior * inferior,CORE_ADDR addr,ssize_t len,const bfd_byte * data)14945*ef5ccd6cSJohn Marino invalidate_bp_value_on_memory_change (struct inferior *inferior,
14946*ef5ccd6cSJohn Marino 				      CORE_ADDR addr, ssize_t len,
14947cf7f2e2dSJohn Marino 				      const bfd_byte *data)
14948cf7f2e2dSJohn Marino {
14949cf7f2e2dSJohn Marino   struct breakpoint *bp;
14950cf7f2e2dSJohn Marino 
14951cf7f2e2dSJohn Marino   ALL_BREAKPOINTS (bp)
14952cf7f2e2dSJohn Marino     if (bp->enable_state == bp_enabled
14953a45ae5f8SJohn Marino 	&& bp->type == bp_hardware_watchpoint)
14954a45ae5f8SJohn Marino       {
14955a45ae5f8SJohn Marino 	struct watchpoint *wp = (struct watchpoint *) bp;
14956a45ae5f8SJohn Marino 
14957a45ae5f8SJohn Marino 	if (wp->val_valid && wp->val)
14958cf7f2e2dSJohn Marino 	  {
14959cf7f2e2dSJohn Marino 	    struct bp_location *loc;
14960cf7f2e2dSJohn Marino 
14961cf7f2e2dSJohn Marino 	    for (loc = bp->loc; loc != NULL; loc = loc->next)
14962cf7f2e2dSJohn Marino 	      if (loc->loc_type == bp_loc_hardware_watchpoint
14963cf7f2e2dSJohn Marino 		  && loc->address + loc->length > addr
14964cf7f2e2dSJohn Marino 		  && addr + len > loc->address)
14965cf7f2e2dSJohn Marino 		{
14966a45ae5f8SJohn Marino 		  value_free (wp->val);
14967a45ae5f8SJohn Marino 		  wp->val = NULL;
14968a45ae5f8SJohn Marino 		  wp->val_valid = 0;
14969a45ae5f8SJohn Marino 		}
14970cf7f2e2dSJohn Marino 	  }
14971cf7f2e2dSJohn Marino       }
14972cf7f2e2dSJohn Marino }
14973cf7f2e2dSJohn Marino 
149745796c8dcSSimon Schubert /* Create and insert a raw software breakpoint at PC.  Return an
149755796c8dcSSimon Schubert    identifier, which should be used to remove the breakpoint later.
149765796c8dcSSimon Schubert    In general, places which call this should be using something on the
149775796c8dcSSimon Schubert    breakpoint chain instead; this function should be eliminated
149785796c8dcSSimon Schubert    someday.  */
149795796c8dcSSimon Schubert 
149805796c8dcSSimon Schubert void *
deprecated_insert_raw_breakpoint(struct gdbarch * gdbarch,struct address_space * aspace,CORE_ADDR pc)14981cf7f2e2dSJohn Marino deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14982cf7f2e2dSJohn Marino 				  struct address_space *aspace, CORE_ADDR pc)
149835796c8dcSSimon Schubert {
149845796c8dcSSimon Schubert   struct bp_target_info *bp_tgt;
149855796c8dcSSimon Schubert 
14986cf7f2e2dSJohn Marino   bp_tgt = XZALLOC (struct bp_target_info);
149875796c8dcSSimon Schubert 
14988cf7f2e2dSJohn Marino   bp_tgt->placed_address_space = aspace;
149895796c8dcSSimon Schubert   bp_tgt->placed_address = pc;
14990cf7f2e2dSJohn Marino 
149915796c8dcSSimon Schubert   if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
149925796c8dcSSimon Schubert     {
149935796c8dcSSimon Schubert       /* Could not insert the breakpoint.  */
149945796c8dcSSimon Schubert       xfree (bp_tgt);
149955796c8dcSSimon Schubert       return NULL;
149965796c8dcSSimon Schubert     }
149975796c8dcSSimon Schubert 
149985796c8dcSSimon Schubert   return bp_tgt;
149995796c8dcSSimon Schubert }
150005796c8dcSSimon Schubert 
15001c50c785cSJohn Marino /* Remove a breakpoint BP inserted by
15002c50c785cSJohn Marino    deprecated_insert_raw_breakpoint.  */
150035796c8dcSSimon Schubert 
150045796c8dcSSimon Schubert int
deprecated_remove_raw_breakpoint(struct gdbarch * gdbarch,void * bp)150055796c8dcSSimon Schubert deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
150065796c8dcSSimon Schubert {
150075796c8dcSSimon Schubert   struct bp_target_info *bp_tgt = bp;
150085796c8dcSSimon Schubert   int ret;
150095796c8dcSSimon Schubert 
150105796c8dcSSimon Schubert   ret = target_remove_breakpoint (gdbarch, bp_tgt);
150115796c8dcSSimon Schubert   xfree (bp_tgt);
150125796c8dcSSimon Schubert 
150135796c8dcSSimon Schubert   return ret;
150145796c8dcSSimon Schubert }
150155796c8dcSSimon Schubert 
15016c50c785cSJohn Marino /* One (or perhaps two) breakpoints used for software single
15017c50c785cSJohn Marino    stepping.  */
150185796c8dcSSimon Schubert 
150195796c8dcSSimon Schubert static void *single_step_breakpoints[2];
150205796c8dcSSimon Schubert static struct gdbarch *single_step_gdbarch[2];
150215796c8dcSSimon Schubert 
150225796c8dcSSimon Schubert /* Create and insert a breakpoint for software single step.  */
150235796c8dcSSimon Schubert 
150245796c8dcSSimon Schubert void
insert_single_step_breakpoint(struct gdbarch * gdbarch,struct address_space * aspace,CORE_ADDR next_pc)15025cf7f2e2dSJohn Marino insert_single_step_breakpoint (struct gdbarch *gdbarch,
15026c50c785cSJohn Marino 			       struct address_space *aspace,
15027c50c785cSJohn Marino 			       CORE_ADDR next_pc)
150285796c8dcSSimon Schubert {
150295796c8dcSSimon Schubert   void **bpt_p;
150305796c8dcSSimon Schubert 
150315796c8dcSSimon Schubert   if (single_step_breakpoints[0] == NULL)
150325796c8dcSSimon Schubert     {
150335796c8dcSSimon Schubert       bpt_p = &single_step_breakpoints[0];
150345796c8dcSSimon Schubert       single_step_gdbarch[0] = gdbarch;
150355796c8dcSSimon Schubert     }
150365796c8dcSSimon Schubert   else
150375796c8dcSSimon Schubert     {
150385796c8dcSSimon Schubert       gdb_assert (single_step_breakpoints[1] == NULL);
150395796c8dcSSimon Schubert       bpt_p = &single_step_breakpoints[1];
150405796c8dcSSimon Schubert       single_step_gdbarch[1] = gdbarch;
150415796c8dcSSimon Schubert     }
150425796c8dcSSimon Schubert 
15043c50c785cSJohn Marino   /* NOTE drow/2006-04-11: A future improvement to this function would
15044c50c785cSJohn Marino      be to only create the breakpoints once, and actually put them on
15045c50c785cSJohn Marino      the breakpoint chain.  That would let us use set_raw_breakpoint.
15046c50c785cSJohn Marino      We could adjust the addresses each time they were needed.  Doing
15047c50c785cSJohn Marino      this requires corresponding changes elsewhere where single step
15048c50c785cSJohn Marino      breakpoints are handled, however.  So, for now, we use this.  */
150495796c8dcSSimon Schubert 
15050cf7f2e2dSJohn Marino   *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
150515796c8dcSSimon Schubert   if (*bpt_p == NULL)
150525796c8dcSSimon Schubert     error (_("Could not insert single-step breakpoint at %s"),
150535796c8dcSSimon Schubert 	     paddress (gdbarch, next_pc));
150545796c8dcSSimon Schubert }
150555796c8dcSSimon Schubert 
15056c50c785cSJohn Marino /* Check if the breakpoints used for software single stepping
15057c50c785cSJohn Marino    were inserted or not.  */
15058c50c785cSJohn Marino 
15059c50c785cSJohn Marino int
single_step_breakpoints_inserted(void)15060c50c785cSJohn Marino single_step_breakpoints_inserted (void)
15061c50c785cSJohn Marino {
15062c50c785cSJohn Marino   return (single_step_breakpoints[0] != NULL
15063c50c785cSJohn Marino           || single_step_breakpoints[1] != NULL);
15064c50c785cSJohn Marino }
15065c50c785cSJohn Marino 
150665796c8dcSSimon Schubert /* Remove and delete any breakpoints used for software single step.  */
150675796c8dcSSimon Schubert 
150685796c8dcSSimon Schubert void
remove_single_step_breakpoints(void)150695796c8dcSSimon Schubert remove_single_step_breakpoints (void)
150705796c8dcSSimon Schubert {
150715796c8dcSSimon Schubert   gdb_assert (single_step_breakpoints[0] != NULL);
150725796c8dcSSimon Schubert 
150735796c8dcSSimon Schubert   /* See insert_single_step_breakpoint for more about this deprecated
150745796c8dcSSimon Schubert      call.  */
150755796c8dcSSimon Schubert   deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
150765796c8dcSSimon Schubert 				    single_step_breakpoints[0]);
150775796c8dcSSimon Schubert   single_step_gdbarch[0] = NULL;
150785796c8dcSSimon Schubert   single_step_breakpoints[0] = NULL;
150795796c8dcSSimon Schubert 
150805796c8dcSSimon Schubert   if (single_step_breakpoints[1] != NULL)
150815796c8dcSSimon Schubert     {
150825796c8dcSSimon Schubert       deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
150835796c8dcSSimon Schubert 					single_step_breakpoints[1]);
150845796c8dcSSimon Schubert       single_step_gdbarch[1] = NULL;
150855796c8dcSSimon Schubert       single_step_breakpoints[1] = NULL;
150865796c8dcSSimon Schubert     }
150875796c8dcSSimon Schubert }
150885796c8dcSSimon Schubert 
15089cf7f2e2dSJohn Marino /* Delete software single step breakpoints without removing them from
15090cf7f2e2dSJohn Marino    the inferior.  This is intended to be used if the inferior's address
15091cf7f2e2dSJohn Marino    space where they were inserted is already gone, e.g. after exit or
15092cf7f2e2dSJohn Marino    exec.  */
15093cf7f2e2dSJohn Marino 
15094cf7f2e2dSJohn Marino void
cancel_single_step_breakpoints(void)15095cf7f2e2dSJohn Marino cancel_single_step_breakpoints (void)
15096cf7f2e2dSJohn Marino {
15097cf7f2e2dSJohn Marino   int i;
15098cf7f2e2dSJohn Marino 
15099cf7f2e2dSJohn Marino   for (i = 0; i < 2; i++)
15100cf7f2e2dSJohn Marino     if (single_step_breakpoints[i])
15101cf7f2e2dSJohn Marino       {
15102cf7f2e2dSJohn Marino 	xfree (single_step_breakpoints[i]);
15103cf7f2e2dSJohn Marino 	single_step_breakpoints[i] = NULL;
15104cf7f2e2dSJohn Marino 	single_step_gdbarch[i] = NULL;
15105cf7f2e2dSJohn Marino       }
15106cf7f2e2dSJohn Marino }
15107cf7f2e2dSJohn Marino 
15108cf7f2e2dSJohn Marino /* Detach software single-step breakpoints from INFERIOR_PTID without
15109cf7f2e2dSJohn Marino    removing them.  */
15110cf7f2e2dSJohn Marino 
15111cf7f2e2dSJohn Marino static void
detach_single_step_breakpoints(void)15112cf7f2e2dSJohn Marino detach_single_step_breakpoints (void)
15113cf7f2e2dSJohn Marino {
15114cf7f2e2dSJohn Marino   int i;
15115cf7f2e2dSJohn Marino 
15116cf7f2e2dSJohn Marino   for (i = 0; i < 2; i++)
15117cf7f2e2dSJohn Marino     if (single_step_breakpoints[i])
15118cf7f2e2dSJohn Marino       target_remove_breakpoint (single_step_gdbarch[i],
15119cf7f2e2dSJohn Marino 				single_step_breakpoints[i]);
15120cf7f2e2dSJohn Marino }
15121cf7f2e2dSJohn Marino 
15122c50c785cSJohn Marino /* Check whether a software single-step breakpoint is inserted at
15123c50c785cSJohn Marino    PC.  */
151245796c8dcSSimon Schubert 
151255796c8dcSSimon Schubert static int
single_step_breakpoint_inserted_here_p(struct address_space * aspace,CORE_ADDR pc)15126cf7f2e2dSJohn Marino single_step_breakpoint_inserted_here_p (struct address_space *aspace,
15127cf7f2e2dSJohn Marino 					CORE_ADDR pc)
151285796c8dcSSimon Schubert {
151295796c8dcSSimon Schubert   int i;
151305796c8dcSSimon Schubert 
151315796c8dcSSimon Schubert   for (i = 0; i < 2; i++)
151325796c8dcSSimon Schubert     {
151335796c8dcSSimon Schubert       struct bp_target_info *bp_tgt = single_step_breakpoints[i];
15134cf7f2e2dSJohn Marino       if (bp_tgt
15135cf7f2e2dSJohn Marino 	  && breakpoint_address_match (bp_tgt->placed_address_space,
15136cf7f2e2dSJohn Marino 				       bp_tgt->placed_address,
15137cf7f2e2dSJohn Marino 				       aspace, pc))
151385796c8dcSSimon Schubert 	return 1;
151395796c8dcSSimon Schubert     }
151405796c8dcSSimon Schubert 
151415796c8dcSSimon Schubert   return 0;
151425796c8dcSSimon Schubert }
151435796c8dcSSimon Schubert 
151445796c8dcSSimon Schubert /* Returns 0 if 'bp' is NOT a syscall catchpoint,
151455796c8dcSSimon Schubert    non-zero otherwise.  */
151465796c8dcSSimon Schubert static int
is_syscall_catchpoint_enabled(struct breakpoint * bp)151475796c8dcSSimon Schubert is_syscall_catchpoint_enabled (struct breakpoint *bp)
151485796c8dcSSimon Schubert {
151495796c8dcSSimon Schubert   if (syscall_catchpoint_p (bp)
151505796c8dcSSimon Schubert       && bp->enable_state != bp_disabled
151515796c8dcSSimon Schubert       && bp->enable_state != bp_call_disabled)
151525796c8dcSSimon Schubert     return 1;
151535796c8dcSSimon Schubert   else
151545796c8dcSSimon Schubert     return 0;
151555796c8dcSSimon Schubert }
151565796c8dcSSimon Schubert 
151575796c8dcSSimon Schubert int
catch_syscall_enabled(void)151585796c8dcSSimon Schubert catch_syscall_enabled (void)
151595796c8dcSSimon Schubert {
15160*ef5ccd6cSJohn Marino   struct catch_syscall_inferior_data *inf_data
15161*ef5ccd6cSJohn Marino     = get_catch_syscall_inferior_data (current_inferior ());
151625796c8dcSSimon Schubert 
15163*ef5ccd6cSJohn Marino   return inf_data->total_syscalls_count != 0;
151645796c8dcSSimon Schubert }
151655796c8dcSSimon Schubert 
151665796c8dcSSimon Schubert int
catching_syscall_number(int syscall_number)151675796c8dcSSimon Schubert catching_syscall_number (int syscall_number)
151685796c8dcSSimon Schubert {
151695796c8dcSSimon Schubert   struct breakpoint *bp;
151705796c8dcSSimon Schubert 
151715796c8dcSSimon Schubert   ALL_BREAKPOINTS (bp)
151725796c8dcSSimon Schubert     if (is_syscall_catchpoint_enabled (bp))
151735796c8dcSSimon Schubert       {
15174a45ae5f8SJohn Marino 	struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
15175a45ae5f8SJohn Marino 
15176a45ae5f8SJohn Marino 	if (c->syscalls_to_be_caught)
151775796c8dcSSimon Schubert 	  {
151785796c8dcSSimon Schubert             int i, iter;
151795796c8dcSSimon Schubert             for (i = 0;
15180a45ae5f8SJohn Marino                  VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
151815796c8dcSSimon Schubert                  i++)
151825796c8dcSSimon Schubert 	      if (syscall_number == iter)
151835796c8dcSSimon Schubert 		return 1;
151845796c8dcSSimon Schubert 	  }
151855796c8dcSSimon Schubert 	else
151865796c8dcSSimon Schubert 	  return 1;
151875796c8dcSSimon Schubert       }
151885796c8dcSSimon Schubert 
151895796c8dcSSimon Schubert   return 0;
151905796c8dcSSimon Schubert }
151915796c8dcSSimon Schubert 
151925796c8dcSSimon Schubert /* Complete syscall names.  Used by "catch syscall".  */
VEC(char_ptr)15193*ef5ccd6cSJohn Marino static VEC (char_ptr) *
151945796c8dcSSimon Schubert catch_syscall_completer (struct cmd_list_element *cmd,
151955796c8dcSSimon Schubert                          char *text, char *word)
151965796c8dcSSimon Schubert {
151975796c8dcSSimon Schubert   const char **list = get_syscall_names ();
15198*ef5ccd6cSJohn Marino   VEC (char_ptr) *retlist
15199*ef5ccd6cSJohn Marino     = (list == NULL) ? NULL : complete_on_enum (list, word, word);
15200cf7f2e2dSJohn Marino 
15201c50c785cSJohn Marino   xfree (list);
15202c50c785cSJohn Marino   return retlist;
152035796c8dcSSimon Schubert }
152045796c8dcSSimon Schubert 
152055796c8dcSSimon Schubert /* Tracepoint-specific operations.  */
152065796c8dcSSimon Schubert 
152075796c8dcSSimon Schubert /* Set tracepoint count to NUM.  */
152085796c8dcSSimon Schubert static void
set_tracepoint_count(int num)152095796c8dcSSimon Schubert set_tracepoint_count (int num)
152105796c8dcSSimon Schubert {
152115796c8dcSSimon Schubert   tracepoint_count = num;
152125796c8dcSSimon Schubert   set_internalvar_integer (lookup_internalvar ("tpnum"), num);
152135796c8dcSSimon Schubert }
152145796c8dcSSimon Schubert 
15215*ef5ccd6cSJohn Marino static void
trace_command(char * arg,int from_tty)152165796c8dcSSimon Schubert trace_command (char *arg, int from_tty)
152175796c8dcSSimon Schubert {
15218*ef5ccd6cSJohn Marino   struct breakpoint_ops *ops;
15219*ef5ccd6cSJohn Marino   const char *arg_cp = arg;
15220*ef5ccd6cSJohn Marino 
15221*ef5ccd6cSJohn Marino   if (arg && probe_linespec_to_ops (&arg_cp))
15222*ef5ccd6cSJohn Marino     ops = &tracepoint_probe_breakpoint_ops;
15223*ef5ccd6cSJohn Marino   else
15224*ef5ccd6cSJohn Marino     ops = &tracepoint_breakpoint_ops;
15225*ef5ccd6cSJohn Marino 
15226*ef5ccd6cSJohn Marino   create_breakpoint (get_current_arch (),
152275796c8dcSSimon Schubert 		     arg,
15228*ef5ccd6cSJohn Marino 		     NULL, 0, NULL, 1 /* parse arg */,
15229cf7f2e2dSJohn Marino 		     0 /* tempflag */,
15230cf7f2e2dSJohn Marino 		     bp_tracepoint /* type_wanted */,
152315796c8dcSSimon Schubert 		     0 /* Ignore count */,
152325796c8dcSSimon Schubert 		     pending_break_support,
15233*ef5ccd6cSJohn Marino 		     ops,
152345796c8dcSSimon Schubert 		     from_tty,
15235c50c785cSJohn Marino 		     1 /* enabled */,
15236*ef5ccd6cSJohn Marino 		     0 /* internal */, 0);
152375796c8dcSSimon Schubert }
152385796c8dcSSimon Schubert 
15239*ef5ccd6cSJohn Marino static void
ftrace_command(char * arg,int from_tty)15240cf7f2e2dSJohn Marino ftrace_command (char *arg, int from_tty)
15241cf7f2e2dSJohn Marino {
15242*ef5ccd6cSJohn Marino   create_breakpoint (get_current_arch (),
15243cf7f2e2dSJohn Marino 		     arg,
15244*ef5ccd6cSJohn Marino 		     NULL, 0, NULL, 1 /* parse arg */,
15245cf7f2e2dSJohn Marino 		     0 /* tempflag */,
15246cf7f2e2dSJohn Marino 		     bp_fast_tracepoint /* type_wanted */,
15247cf7f2e2dSJohn Marino 		     0 /* Ignore count */,
15248cf7f2e2dSJohn Marino 		     pending_break_support,
15249a45ae5f8SJohn Marino 		     &tracepoint_breakpoint_ops,
15250cf7f2e2dSJohn Marino 		     from_tty,
15251c50c785cSJohn Marino 		     1 /* enabled */,
15252*ef5ccd6cSJohn Marino 		     0 /* internal */, 0);
15253cf7f2e2dSJohn Marino }
15254cf7f2e2dSJohn Marino 
15255cf7f2e2dSJohn Marino /* strace command implementation.  Creates a static tracepoint.  */
15256cf7f2e2dSJohn Marino 
15257*ef5ccd6cSJohn Marino static void
strace_command(char * arg,int from_tty)15258cf7f2e2dSJohn Marino strace_command (char *arg, int from_tty)
15259cf7f2e2dSJohn Marino {
15260*ef5ccd6cSJohn Marino   struct breakpoint_ops *ops;
15261*ef5ccd6cSJohn Marino 
15262*ef5ccd6cSJohn Marino   /* Decide if we are dealing with a static tracepoint marker (`-m'),
15263*ef5ccd6cSJohn Marino      or with a normal static tracepoint.  */
15264*ef5ccd6cSJohn Marino   if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
15265*ef5ccd6cSJohn Marino     ops = &strace_marker_breakpoint_ops;
15266*ef5ccd6cSJohn Marino   else
15267*ef5ccd6cSJohn Marino     ops = &tracepoint_breakpoint_ops;
15268*ef5ccd6cSJohn Marino 
15269*ef5ccd6cSJohn Marino   create_breakpoint (get_current_arch (),
15270cf7f2e2dSJohn Marino 		     arg,
15271*ef5ccd6cSJohn Marino 		     NULL, 0, NULL, 1 /* parse arg */,
15272cf7f2e2dSJohn Marino 		     0 /* tempflag */,
15273cf7f2e2dSJohn Marino 		     bp_static_tracepoint /* type_wanted */,
15274cf7f2e2dSJohn Marino 		     0 /* Ignore count */,
15275cf7f2e2dSJohn Marino 		     pending_break_support,
15276*ef5ccd6cSJohn Marino 		     ops,
15277cf7f2e2dSJohn Marino 		     from_tty,
15278c50c785cSJohn Marino 		     1 /* enabled */,
15279*ef5ccd6cSJohn Marino 		     0 /* internal */, 0);
15280cf7f2e2dSJohn Marino }
15281cf7f2e2dSJohn Marino 
15282cf7f2e2dSJohn Marino /* Set up a fake reader function that gets command lines from a linked
15283cf7f2e2dSJohn Marino    list that was acquired during tracepoint uploading.  */
15284cf7f2e2dSJohn Marino 
15285cf7f2e2dSJohn Marino static struct uploaded_tp *this_utp;
15286cf7f2e2dSJohn Marino static int next_cmd;
15287cf7f2e2dSJohn Marino 
15288cf7f2e2dSJohn Marino static char *
read_uploaded_action(void)15289cf7f2e2dSJohn Marino read_uploaded_action (void)
15290cf7f2e2dSJohn Marino {
15291cf7f2e2dSJohn Marino   char *rslt;
15292cf7f2e2dSJohn Marino 
15293cf7f2e2dSJohn Marino   VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
15294cf7f2e2dSJohn Marino 
15295cf7f2e2dSJohn Marino   next_cmd++;
15296cf7f2e2dSJohn Marino 
15297cf7f2e2dSJohn Marino   return rslt;
15298cf7f2e2dSJohn Marino }
15299cf7f2e2dSJohn Marino 
15300cf7f2e2dSJohn Marino /* Given information about a tracepoint as recorded on a target (which
15301cf7f2e2dSJohn Marino    can be either a live system or a trace file), attempt to create an
15302cf7f2e2dSJohn Marino    equivalent GDB tracepoint.  This is not a reliable process, since
15303cf7f2e2dSJohn Marino    the target does not necessarily have all the information used when
15304cf7f2e2dSJohn Marino    the tracepoint was originally defined.  */
15305cf7f2e2dSJohn Marino 
15306a45ae5f8SJohn Marino struct tracepoint *
create_tracepoint_from_upload(struct uploaded_tp * utp)15307cf7f2e2dSJohn Marino create_tracepoint_from_upload (struct uploaded_tp *utp)
15308cf7f2e2dSJohn Marino {
15309cf7f2e2dSJohn Marino   char *addr_str, small_buf[100];
15310a45ae5f8SJohn Marino   struct tracepoint *tp;
15311cf7f2e2dSJohn Marino 
15312cf7f2e2dSJohn Marino   if (utp->at_string)
15313cf7f2e2dSJohn Marino     addr_str = utp->at_string;
15314cf7f2e2dSJohn Marino   else
15315cf7f2e2dSJohn Marino     {
15316cf7f2e2dSJohn Marino       /* In the absence of a source location, fall back to raw
15317cf7f2e2dSJohn Marino 	 address.  Since there is no way to confirm that the address
15318cf7f2e2dSJohn Marino 	 means the same thing as when the trace was started, warn the
15319cf7f2e2dSJohn Marino 	 user.  */
15320c50c785cSJohn Marino       warning (_("Uploaded tracepoint %d has no "
15321c50c785cSJohn Marino 		 "source location, using raw address"),
15322cf7f2e2dSJohn Marino 	       utp->number);
15323*ef5ccd6cSJohn Marino       xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr));
15324cf7f2e2dSJohn Marino       addr_str = small_buf;
15325cf7f2e2dSJohn Marino     }
15326cf7f2e2dSJohn Marino 
15327cf7f2e2dSJohn Marino   /* There's not much we can do with a sequence of bytecodes.  */
15328cf7f2e2dSJohn Marino   if (utp->cond && !utp->cond_string)
15329c50c785cSJohn Marino     warning (_("Uploaded tracepoint %d condition "
15330c50c785cSJohn Marino 	       "has no source form, ignoring it"),
15331cf7f2e2dSJohn Marino 	     utp->number);
15332cf7f2e2dSJohn Marino 
15333cf7f2e2dSJohn Marino   if (!create_breakpoint (get_current_arch (),
15334cf7f2e2dSJohn Marino 			  addr_str,
15335*ef5ccd6cSJohn Marino 			  utp->cond_string, -1, NULL,
15336*ef5ccd6cSJohn Marino 			  0 /* parse cond/thread */,
15337cf7f2e2dSJohn Marino 			  0 /* tempflag */,
15338cf7f2e2dSJohn Marino 			  utp->type /* type_wanted */,
15339cf7f2e2dSJohn Marino 			  0 /* Ignore count */,
15340cf7f2e2dSJohn Marino 			  pending_break_support,
15341a45ae5f8SJohn Marino 			  &tracepoint_breakpoint_ops,
15342cf7f2e2dSJohn Marino 			  0 /* from_tty */,
15343c50c785cSJohn Marino 			  utp->enabled /* enabled */,
15344a45ae5f8SJohn Marino 			  0 /* internal */,
15345a45ae5f8SJohn Marino 			  CREATE_BREAKPOINT_FLAGS_INSERTED))
15346cf7f2e2dSJohn Marino     return NULL;
15347cf7f2e2dSJohn Marino 
15348cf7f2e2dSJohn Marino   /* Get the tracepoint we just created.  */
15349cf7f2e2dSJohn Marino   tp = get_tracepoint (tracepoint_count);
15350cf7f2e2dSJohn Marino   gdb_assert (tp != NULL);
15351cf7f2e2dSJohn Marino 
15352cf7f2e2dSJohn Marino   if (utp->pass > 0)
15353cf7f2e2dSJohn Marino     {
15354*ef5ccd6cSJohn Marino       xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass,
15355*ef5ccd6cSJohn Marino 		 tp->base.number);
15356cf7f2e2dSJohn Marino 
15357cf7f2e2dSJohn Marino       trace_pass_command (small_buf, 0);
15358cf7f2e2dSJohn Marino     }
15359cf7f2e2dSJohn Marino 
15360cf7f2e2dSJohn Marino   /* If we have uploaded versions of the original commands, set up a
15361cf7f2e2dSJohn Marino      special-purpose "reader" function and call the usual command line
15362cf7f2e2dSJohn Marino      reader, then pass the result to the breakpoint command-setting
15363cf7f2e2dSJohn Marino      function.  */
15364cf7f2e2dSJohn Marino   if (!VEC_empty (char_ptr, utp->cmd_strings))
15365cf7f2e2dSJohn Marino     {
15366cf7f2e2dSJohn Marino       struct command_line *cmd_list;
15367cf7f2e2dSJohn Marino 
15368cf7f2e2dSJohn Marino       this_utp = utp;
15369cf7f2e2dSJohn Marino       next_cmd = 0;
15370cf7f2e2dSJohn Marino 
15371cf7f2e2dSJohn Marino       cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
15372cf7f2e2dSJohn Marino 
15373a45ae5f8SJohn Marino       breakpoint_set_commands (&tp->base, cmd_list);
15374cf7f2e2dSJohn Marino     }
15375cf7f2e2dSJohn Marino   else if (!VEC_empty (char_ptr, utp->actions)
15376cf7f2e2dSJohn Marino 	   || !VEC_empty (char_ptr, utp->step_actions))
15377c50c785cSJohn Marino     warning (_("Uploaded tracepoint %d actions "
15378c50c785cSJohn Marino 	       "have no source form, ignoring them"),
15379cf7f2e2dSJohn Marino 	     utp->number);
15380cf7f2e2dSJohn Marino 
15381a45ae5f8SJohn Marino   /* Copy any status information that might be available.  */
15382a45ae5f8SJohn Marino   tp->base.hit_count = utp->hit_count;
15383a45ae5f8SJohn Marino   tp->traceframe_usage = utp->traceframe_usage;
15384a45ae5f8SJohn Marino 
15385cf7f2e2dSJohn Marino   return tp;
15386cf7f2e2dSJohn Marino }
15387cf7f2e2dSJohn Marino 
153885796c8dcSSimon Schubert /* Print information on tracepoint number TPNUM_EXP, or all if
153895796c8dcSSimon Schubert    omitted.  */
153905796c8dcSSimon Schubert 
153915796c8dcSSimon Schubert static void
tracepoints_info(char * args,int from_tty)15392c50c785cSJohn Marino tracepoints_info (char *args, int from_tty)
153935796c8dcSSimon Schubert {
15394a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
15395c50c785cSJohn Marino   int num_printed;
153965796c8dcSSimon Schubert 
15397c50c785cSJohn Marino   num_printed = breakpoint_1 (args, 0, is_tracepoint);
15398cf7f2e2dSJohn Marino 
15399cf7f2e2dSJohn Marino   if (num_printed == 0)
154005796c8dcSSimon Schubert     {
15401c50c785cSJohn Marino       if (args == NULL || *args == '\0')
154025796c8dcSSimon Schubert 	ui_out_message (uiout, 0, "No tracepoints.\n");
15403cf7f2e2dSJohn Marino       else
15404c50c785cSJohn Marino 	ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
154055796c8dcSSimon Schubert     }
154065796c8dcSSimon Schubert 
15407cf7f2e2dSJohn Marino   default_collect_info ();
154085796c8dcSSimon Schubert }
154095796c8dcSSimon Schubert 
154105796c8dcSSimon Schubert /* The 'enable trace' command enables tracepoints.
154115796c8dcSSimon Schubert    Not supported by all targets.  */
154125796c8dcSSimon Schubert static void
enable_trace_command(char * args,int from_tty)154135796c8dcSSimon Schubert enable_trace_command (char *args, int from_tty)
154145796c8dcSSimon Schubert {
154155796c8dcSSimon Schubert   enable_command (args, from_tty);
154165796c8dcSSimon Schubert }
154175796c8dcSSimon Schubert 
154185796c8dcSSimon Schubert /* The 'disable trace' command disables tracepoints.
154195796c8dcSSimon Schubert    Not supported by all targets.  */
154205796c8dcSSimon Schubert static void
disable_trace_command(char * args,int from_tty)154215796c8dcSSimon Schubert disable_trace_command (char *args, int from_tty)
154225796c8dcSSimon Schubert {
154235796c8dcSSimon Schubert   disable_command (args, from_tty);
154245796c8dcSSimon Schubert }
154255796c8dcSSimon Schubert 
15426c50c785cSJohn Marino /* Remove a tracepoint (or all if no argument).  */
154275796c8dcSSimon Schubert static void
delete_trace_command(char * arg,int from_tty)154285796c8dcSSimon Schubert delete_trace_command (char *arg, int from_tty)
154295796c8dcSSimon Schubert {
15430c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
154315796c8dcSSimon Schubert 
154325796c8dcSSimon Schubert   dont_repeat ();
154335796c8dcSSimon Schubert 
154345796c8dcSSimon Schubert   if (arg == 0)
154355796c8dcSSimon Schubert     {
154365796c8dcSSimon Schubert       int breaks_to_delete = 0;
154375796c8dcSSimon Schubert 
154385796c8dcSSimon Schubert       /* Delete all breakpoints if no argument.
154395796c8dcSSimon Schubert          Do not delete internal or call-dummy breakpoints, these
15440c50c785cSJohn Marino          have to be deleted with an explicit breakpoint number
15441c50c785cSJohn Marino 	 argument.  */
154425796c8dcSSimon Schubert       ALL_TRACEPOINTS (b)
15443a45ae5f8SJohn Marino 	if (is_tracepoint (b) && user_breakpoint_p (b))
154445796c8dcSSimon Schubert 	  {
154455796c8dcSSimon Schubert 	    breaks_to_delete = 1;
154465796c8dcSSimon Schubert 	    break;
154475796c8dcSSimon Schubert 	  }
154485796c8dcSSimon Schubert 
154495796c8dcSSimon Schubert       /* Ask user only if there are some breakpoints to delete.  */
154505796c8dcSSimon Schubert       if (!from_tty
154515796c8dcSSimon Schubert 	  || (breaks_to_delete && query (_("Delete all tracepoints? "))))
154525796c8dcSSimon Schubert 	{
15453c50c785cSJohn Marino 	  ALL_BREAKPOINTS_SAFE (b, b_tmp)
15454a45ae5f8SJohn Marino 	    if (is_tracepoint (b) && user_breakpoint_p (b))
154555796c8dcSSimon Schubert 	      delete_breakpoint (b);
154565796c8dcSSimon Schubert 	}
154575796c8dcSSimon Schubert     }
154585796c8dcSSimon Schubert   else
15459a45ae5f8SJohn Marino     map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
154605796c8dcSSimon Schubert }
154615796c8dcSSimon Schubert 
15462c50c785cSJohn Marino /* Helper function for trace_pass_command.  */
15463c50c785cSJohn Marino 
15464c50c785cSJohn Marino static void
trace_pass_set_count(struct tracepoint * tp,int count,int from_tty)15465a45ae5f8SJohn Marino trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
15466c50c785cSJohn Marino {
15467a45ae5f8SJohn Marino   tp->pass_count = count;
15468*ef5ccd6cSJohn Marino   observer_notify_breakpoint_modified (&tp->base);
15469c50c785cSJohn Marino   if (from_tty)
15470c50c785cSJohn Marino     printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15471a45ae5f8SJohn Marino 		     tp->base.number, count);
15472c50c785cSJohn Marino }
15473c50c785cSJohn Marino 
154745796c8dcSSimon Schubert /* Set passcount for tracepoint.
154755796c8dcSSimon Schubert 
154765796c8dcSSimon Schubert    First command argument is passcount, second is tracepoint number.
154775796c8dcSSimon Schubert    If tracepoint number omitted, apply to most recently defined.
154785796c8dcSSimon Schubert    Also accepts special argument "all".  */
154795796c8dcSSimon Schubert 
154805796c8dcSSimon Schubert static void
trace_pass_command(char * args,int from_tty)154815796c8dcSSimon Schubert trace_pass_command (char *args, int from_tty)
154825796c8dcSSimon Schubert {
15483a45ae5f8SJohn Marino   struct tracepoint *t1;
154845796c8dcSSimon Schubert   unsigned int count;
154855796c8dcSSimon Schubert 
154865796c8dcSSimon Schubert   if (args == 0 || *args == 0)
15487c50c785cSJohn Marino     error (_("passcount command requires an "
15488c50c785cSJohn Marino 	     "argument (count + optional TP num)"));
154895796c8dcSSimon Schubert 
154905796c8dcSSimon Schubert   count = strtoul (args, &args, 10);	/* Count comes first, then TP num.  */
154915796c8dcSSimon Schubert 
15492*ef5ccd6cSJohn Marino   args = skip_spaces (args);
154935796c8dcSSimon Schubert   if (*args && strncasecmp (args, "all", 3) == 0)
154945796c8dcSSimon Schubert     {
15495a45ae5f8SJohn Marino       struct breakpoint *b;
15496a45ae5f8SJohn Marino 
154975796c8dcSSimon Schubert       args += 3;			/* Skip special argument "all".  */
154985796c8dcSSimon Schubert       if (*args)
154995796c8dcSSimon Schubert 	error (_("Junk at end of arguments."));
15500c50c785cSJohn Marino 
15501a45ae5f8SJohn Marino       ALL_TRACEPOINTS (b)
15502c50c785cSJohn Marino       {
15503a45ae5f8SJohn Marino 	t1 = (struct tracepoint *) b;
15504c50c785cSJohn Marino 	trace_pass_set_count (t1, count, from_tty);
15505c50c785cSJohn Marino       }
15506c50c785cSJohn Marino     }
15507c50c785cSJohn Marino   else if (*args == '\0')
15508c50c785cSJohn Marino     {
15509c50c785cSJohn Marino       t1 = get_tracepoint_by_number (&args, NULL, 1);
15510c50c785cSJohn Marino       if (t1)
15511c50c785cSJohn Marino 	trace_pass_set_count (t1, count, from_tty);
155125796c8dcSSimon Schubert     }
155135796c8dcSSimon Schubert   else
15514c50c785cSJohn Marino     {
15515c50c785cSJohn Marino       struct get_number_or_range_state state;
155165796c8dcSSimon Schubert 
15517c50c785cSJohn Marino       init_number_or_range (&state, args);
15518c50c785cSJohn Marino       while (!state.finished)
155195796c8dcSSimon Schubert 	{
15520c50c785cSJohn Marino 	  t1 = get_tracepoint_by_number (&args, &state, 1);
155215796c8dcSSimon Schubert 	  if (t1)
15522c50c785cSJohn Marino 	    trace_pass_set_count (t1, count, from_tty);
155235796c8dcSSimon Schubert 	}
155245796c8dcSSimon Schubert     }
155255796c8dcSSimon Schubert }
155265796c8dcSSimon Schubert 
15527a45ae5f8SJohn Marino struct tracepoint *
get_tracepoint(int num)155285796c8dcSSimon Schubert get_tracepoint (int num)
155295796c8dcSSimon Schubert {
155305796c8dcSSimon Schubert   struct breakpoint *t;
155315796c8dcSSimon Schubert 
155325796c8dcSSimon Schubert   ALL_TRACEPOINTS (t)
155335796c8dcSSimon Schubert     if (t->number == num)
15534a45ae5f8SJohn Marino       return (struct tracepoint *) t;
155355796c8dcSSimon Schubert 
155365796c8dcSSimon Schubert   return NULL;
155375796c8dcSSimon Schubert }
155385796c8dcSSimon Schubert 
15539cf7f2e2dSJohn Marino /* Find the tracepoint with the given target-side number (which may be
15540cf7f2e2dSJohn Marino    different from the tracepoint number after disconnecting and
15541cf7f2e2dSJohn Marino    reconnecting).  */
15542cf7f2e2dSJohn Marino 
15543a45ae5f8SJohn Marino struct tracepoint *
get_tracepoint_by_number_on_target(int num)15544cf7f2e2dSJohn Marino get_tracepoint_by_number_on_target (int num)
15545cf7f2e2dSJohn Marino {
15546a45ae5f8SJohn Marino   struct breakpoint *b;
15547cf7f2e2dSJohn Marino 
15548a45ae5f8SJohn Marino   ALL_TRACEPOINTS (b)
15549a45ae5f8SJohn Marino     {
15550a45ae5f8SJohn Marino       struct tracepoint *t = (struct tracepoint *) b;
15551a45ae5f8SJohn Marino 
15552cf7f2e2dSJohn Marino       if (t->number_on_target == num)
15553cf7f2e2dSJohn Marino 	return t;
15554a45ae5f8SJohn Marino     }
15555cf7f2e2dSJohn Marino 
15556cf7f2e2dSJohn Marino   return NULL;
15557cf7f2e2dSJohn Marino }
15558cf7f2e2dSJohn Marino 
155595796c8dcSSimon Schubert /* Utility: parse a tracepoint number and look it up in the list.
15560c50c785cSJohn Marino    If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15561c50c785cSJohn Marino    If OPTIONAL_P is true, then if the argument is missing, the most
155625796c8dcSSimon Schubert    recent tracepoint (tracepoint_count) is returned.  */
15563a45ae5f8SJohn Marino struct tracepoint *
get_tracepoint_by_number(char ** arg,struct get_number_or_range_state * state,int optional_p)15564c50c785cSJohn Marino get_tracepoint_by_number (char **arg,
15565c50c785cSJohn Marino 			  struct get_number_or_range_state *state,
15566c50c785cSJohn Marino 			  int optional_p)
155675796c8dcSSimon Schubert {
155685796c8dcSSimon Schubert   struct breakpoint *t;
155695796c8dcSSimon Schubert   int tpnum;
155705796c8dcSSimon Schubert   char *instring = arg == NULL ? NULL : *arg;
155715796c8dcSSimon Schubert 
15572c50c785cSJohn Marino   if (state)
15573c50c785cSJohn Marino     {
15574c50c785cSJohn Marino       gdb_assert (!state->finished);
15575c50c785cSJohn Marino       tpnum = get_number_or_range (state);
15576c50c785cSJohn Marino     }
15577c50c785cSJohn Marino   else if (arg == NULL || *arg == NULL || ! **arg)
155785796c8dcSSimon Schubert     {
155795796c8dcSSimon Schubert       if (optional_p)
155805796c8dcSSimon Schubert 	tpnum = tracepoint_count;
155815796c8dcSSimon Schubert       else
155825796c8dcSSimon Schubert 	error_no_arg (_("tracepoint number"));
155835796c8dcSSimon Schubert     }
155845796c8dcSSimon Schubert   else
15585c50c785cSJohn Marino     tpnum = get_number (arg);
155865796c8dcSSimon Schubert 
155875796c8dcSSimon Schubert   if (tpnum <= 0)
155885796c8dcSSimon Schubert     {
155895796c8dcSSimon Schubert       if (instring && *instring)
155905796c8dcSSimon Schubert 	printf_filtered (_("bad tracepoint number at or near '%s'\n"),
155915796c8dcSSimon Schubert 			 instring);
155925796c8dcSSimon Schubert       else
15593c50c785cSJohn Marino 	printf_filtered (_("Tracepoint argument missing "
15594c50c785cSJohn Marino 			   "and no previous tracepoint\n"));
155955796c8dcSSimon Schubert       return NULL;
155965796c8dcSSimon Schubert     }
155975796c8dcSSimon Schubert 
155985796c8dcSSimon Schubert   ALL_TRACEPOINTS (t)
155995796c8dcSSimon Schubert     if (t->number == tpnum)
156005796c8dcSSimon Schubert     {
15601a45ae5f8SJohn Marino       return (struct tracepoint *) t;
156025796c8dcSSimon Schubert     }
156035796c8dcSSimon Schubert 
156045796c8dcSSimon Schubert   printf_unfiltered ("No tracepoint number %d.\n", tpnum);
156055796c8dcSSimon Schubert   return NULL;
156065796c8dcSSimon Schubert }
156075796c8dcSSimon Schubert 
15608a45ae5f8SJohn Marino void
print_recreate_thread(struct breakpoint * b,struct ui_file * fp)15609a45ae5f8SJohn Marino print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15610a45ae5f8SJohn Marino {
15611a45ae5f8SJohn Marino   if (b->thread != -1)
15612a45ae5f8SJohn Marino     fprintf_unfiltered (fp, " thread %d", b->thread);
15613a45ae5f8SJohn Marino 
15614a45ae5f8SJohn Marino   if (b->task != 0)
15615a45ae5f8SJohn Marino     fprintf_unfiltered (fp, " task %d", b->task);
15616a45ae5f8SJohn Marino 
15617a45ae5f8SJohn Marino   fprintf_unfiltered (fp, "\n");
15618a45ae5f8SJohn Marino }
15619a45ae5f8SJohn Marino 
15620cf7f2e2dSJohn Marino /* Save information on user settable breakpoints (watchpoints, etc) to
15621cf7f2e2dSJohn Marino    a new script file named FILENAME.  If FILTER is non-NULL, call it
15622cf7f2e2dSJohn Marino    on each breakpoint and only include the ones for which it returns
15623cf7f2e2dSJohn Marino    non-zero.  */
15624cf7f2e2dSJohn Marino 
156255796c8dcSSimon Schubert static void
save_breakpoints(char * filename,int from_tty,int (* filter)(const struct breakpoint *))15626cf7f2e2dSJohn Marino save_breakpoints (char *filename, int from_tty,
15627cf7f2e2dSJohn Marino 		  int (*filter) (const struct breakpoint *))
156285796c8dcSSimon Schubert {
156295796c8dcSSimon Schubert   struct breakpoint *tp;
15630cf7f2e2dSJohn Marino   int any = 0;
15631cf7f2e2dSJohn Marino   char *pathname;
156325796c8dcSSimon Schubert   struct cleanup *cleanup;
15633cf7f2e2dSJohn Marino   struct ui_file *fp;
15634cf7f2e2dSJohn Marino   int extra_trace_bits = 0;
156355796c8dcSSimon Schubert 
15636cf7f2e2dSJohn Marino   if (filename == 0 || *filename == 0)
15637cf7f2e2dSJohn Marino     error (_("Argument required (file name in which to save)"));
156385796c8dcSSimon Schubert 
156395796c8dcSSimon Schubert   /* See if we have anything to save.  */
15640cf7f2e2dSJohn Marino   ALL_BREAKPOINTS (tp)
156415796c8dcSSimon Schubert   {
15642cf7f2e2dSJohn Marino     /* Skip internal and momentary breakpoints.  */
15643c50c785cSJohn Marino     if (!user_breakpoint_p (tp))
15644cf7f2e2dSJohn Marino       continue;
15645cf7f2e2dSJohn Marino 
15646cf7f2e2dSJohn Marino     /* If we have a filter, only save the breakpoints it accepts.  */
15647cf7f2e2dSJohn Marino     if (filter && !filter (tp))
15648cf7f2e2dSJohn Marino       continue;
15649cf7f2e2dSJohn Marino 
15650cf7f2e2dSJohn Marino     any = 1;
15651cf7f2e2dSJohn Marino 
15652cf7f2e2dSJohn Marino     if (is_tracepoint (tp))
15653cf7f2e2dSJohn Marino       {
15654cf7f2e2dSJohn Marino 	extra_trace_bits = 1;
15655cf7f2e2dSJohn Marino 
15656cf7f2e2dSJohn Marino 	/* We can stop searching.  */
156575796c8dcSSimon Schubert 	break;
156585796c8dcSSimon Schubert       }
15659cf7f2e2dSJohn Marino   }
15660cf7f2e2dSJohn Marino 
15661cf7f2e2dSJohn Marino   if (!any)
156625796c8dcSSimon Schubert     {
15663cf7f2e2dSJohn Marino       warning (_("Nothing to save."));
156645796c8dcSSimon Schubert       return;
156655796c8dcSSimon Schubert     }
156665796c8dcSSimon Schubert 
15667cf7f2e2dSJohn Marino   pathname = tilde_expand (filename);
156685796c8dcSSimon Schubert   cleanup = make_cleanup (xfree, pathname);
15669cf7f2e2dSJohn Marino   fp = gdb_fopen (pathname, "w");
156705796c8dcSSimon Schubert   if (!fp)
15671cf7f2e2dSJohn Marino     error (_("Unable to open file '%s' for saving (%s)"),
15672cf7f2e2dSJohn Marino 	   filename, safe_strerror (errno));
15673cf7f2e2dSJohn Marino   make_cleanup_ui_file_delete (fp);
156745796c8dcSSimon Schubert 
15675cf7f2e2dSJohn Marino   if (extra_trace_bits)
15676cf7f2e2dSJohn Marino     save_trace_state_variables (fp);
15677cf7f2e2dSJohn Marino 
15678cf7f2e2dSJohn Marino   ALL_BREAKPOINTS (tp)
156795796c8dcSSimon Schubert   {
15680cf7f2e2dSJohn Marino     /* Skip internal and momentary breakpoints.  */
15681c50c785cSJohn Marino     if (!user_breakpoint_p (tp))
15682cf7f2e2dSJohn Marino       continue;
15683cf7f2e2dSJohn Marino 
15684cf7f2e2dSJohn Marino     /* If we have a filter, only save the breakpoints it accepts.  */
15685cf7f2e2dSJohn Marino     if (filter && !filter (tp))
15686cf7f2e2dSJohn Marino       continue;
15687cf7f2e2dSJohn Marino 
15688a45ae5f8SJohn Marino     tp->ops->print_recreate (tp, fp);
15689cf7f2e2dSJohn Marino 
15690cf7f2e2dSJohn Marino     /* Note, we can't rely on tp->number for anything, as we can't
15691cf7f2e2dSJohn Marino        assume the recreated breakpoint numbers will match.  Use $bpnum
15692cf7f2e2dSJohn Marino        instead.  */
15693cf7f2e2dSJohn Marino 
15694cf7f2e2dSJohn Marino     if (tp->cond_string)
15695cf7f2e2dSJohn Marino       fprintf_unfiltered (fp, "  condition $bpnum %s\n", tp->cond_string);
15696cf7f2e2dSJohn Marino 
15697cf7f2e2dSJohn Marino     if (tp->ignore_count)
15698cf7f2e2dSJohn Marino       fprintf_unfiltered (fp, "  ignore $bpnum %d\n", tp->ignore_count);
156995796c8dcSSimon Schubert 
15700*ef5ccd6cSJohn Marino     if (tp->type != bp_dprintf && tp->commands)
157015796c8dcSSimon Schubert       {
15702cf7f2e2dSJohn Marino 	volatile struct gdb_exception ex;
157035796c8dcSSimon Schubert 
15704cf7f2e2dSJohn Marino 	fprintf_unfiltered (fp, "  commands\n");
157055796c8dcSSimon Schubert 
15706a45ae5f8SJohn Marino 	ui_out_redirect (current_uiout, fp);
15707c50c785cSJohn Marino 	TRY_CATCH (ex, RETURN_MASK_ALL)
157085796c8dcSSimon Schubert 	  {
15709a45ae5f8SJohn Marino 	    print_command_lines (current_uiout, tp->commands->commands, 2);
15710cf7f2e2dSJohn Marino 	  }
15711a45ae5f8SJohn Marino 	ui_out_redirect (current_uiout, NULL);
15712cf7f2e2dSJohn Marino 
15713cf7f2e2dSJohn Marino 	if (ex.reason < 0)
15714cf7f2e2dSJohn Marino 	  throw_exception (ex);
15715cf7f2e2dSJohn Marino 
15716cf7f2e2dSJohn Marino 	fprintf_unfiltered (fp, "  end\n");
15717cf7f2e2dSJohn Marino       }
15718cf7f2e2dSJohn Marino 
15719cf7f2e2dSJohn Marino     if (tp->enable_state == bp_disabled)
15720cf7f2e2dSJohn Marino       fprintf_unfiltered (fp, "disable\n");
15721cf7f2e2dSJohn Marino 
15722cf7f2e2dSJohn Marino     /* If this is a multi-location breakpoint, check if the locations
15723cf7f2e2dSJohn Marino        should be individually disabled.  Watchpoint locations are
15724cf7f2e2dSJohn Marino        special, and not user visible.  */
15725cf7f2e2dSJohn Marino     if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15726cf7f2e2dSJohn Marino       {
15727cf7f2e2dSJohn Marino 	struct bp_location *loc;
15728cf7f2e2dSJohn Marino 	int n = 1;
15729cf7f2e2dSJohn Marino 
15730cf7f2e2dSJohn Marino 	for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15731cf7f2e2dSJohn Marino 	  if (!loc->enabled)
15732cf7f2e2dSJohn Marino 	    fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
157335796c8dcSSimon Schubert       }
157345796c8dcSSimon Schubert   }
15735cf7f2e2dSJohn Marino 
15736cf7f2e2dSJohn Marino   if (extra_trace_bits && *default_collect)
15737cf7f2e2dSJohn Marino     fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15738cf7f2e2dSJohn Marino 
157395796c8dcSSimon Schubert   do_cleanups (cleanup);
157405796c8dcSSimon Schubert   if (from_tty)
15741cf7f2e2dSJohn Marino     printf_filtered (_("Saved to file '%s'.\n"), filename);
15742cf7f2e2dSJohn Marino }
15743cf7f2e2dSJohn Marino 
15744cf7f2e2dSJohn Marino /* The `save breakpoints' command.  */
15745cf7f2e2dSJohn Marino 
15746cf7f2e2dSJohn Marino static void
save_breakpoints_command(char * args,int from_tty)15747cf7f2e2dSJohn Marino save_breakpoints_command (char *args, int from_tty)
15748cf7f2e2dSJohn Marino {
15749cf7f2e2dSJohn Marino   save_breakpoints (args, from_tty, NULL);
15750cf7f2e2dSJohn Marino }
15751cf7f2e2dSJohn Marino 
15752cf7f2e2dSJohn Marino /* The `save tracepoints' command.  */
15753cf7f2e2dSJohn Marino 
15754cf7f2e2dSJohn Marino static void
save_tracepoints_command(char * args,int from_tty)15755cf7f2e2dSJohn Marino save_tracepoints_command (char *args, int from_tty)
15756cf7f2e2dSJohn Marino {
15757cf7f2e2dSJohn Marino   save_breakpoints (args, from_tty, is_tracepoint);
157585796c8dcSSimon Schubert }
157595796c8dcSSimon Schubert 
157605796c8dcSSimon Schubert /* Create a vector of all tracepoints.  */
157615796c8dcSSimon Schubert 
VEC(breakpoint_p)157625796c8dcSSimon Schubert VEC(breakpoint_p) *
15763c50c785cSJohn Marino all_tracepoints (void)
157645796c8dcSSimon Schubert {
157655796c8dcSSimon Schubert   VEC(breakpoint_p) *tp_vec = 0;
157665796c8dcSSimon Schubert   struct breakpoint *tp;
157675796c8dcSSimon Schubert 
157685796c8dcSSimon Schubert   ALL_TRACEPOINTS (tp)
157695796c8dcSSimon Schubert   {
157705796c8dcSSimon Schubert     VEC_safe_push (breakpoint_p, tp_vec, tp);
157715796c8dcSSimon Schubert   }
157725796c8dcSSimon Schubert 
157735796c8dcSSimon Schubert   return tp_vec;
157745796c8dcSSimon Schubert }
157755796c8dcSSimon Schubert 
157765796c8dcSSimon Schubert 
15777c50c785cSJohn Marino /* This help string is used for the break, hbreak, tbreak and thbreak
15778c50c785cSJohn Marino    commands.  It is defined as a macro to prevent duplication.
15779c50c785cSJohn Marino    COMMAND should be a string constant containing the name of the
15780c50c785cSJohn Marino    command.  */
157815796c8dcSSimon Schubert #define BREAK_ARGS_HELP(command) \
15782*ef5ccd6cSJohn Marino command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15783*ef5ccd6cSJohn Marino PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15784*ef5ccd6cSJohn Marino probe point.  Accepted values are `-probe' (for a generic, automatically\n\
15785*ef5ccd6cSJohn Marino guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
157865796c8dcSSimon Schubert LOCATION may be a line number, function name, or \"*\" and an address.\n\
157875796c8dcSSimon Schubert If a line number is specified, break at start of code for that line.\n\
157885796c8dcSSimon Schubert If a function is specified, break at start of code for that function.\n\
157895796c8dcSSimon Schubert If an address is specified, break at that exact address.\n\
15790cf7f2e2dSJohn Marino With no LOCATION, uses current execution address of the selected\n\
15791cf7f2e2dSJohn Marino stack frame.  This is useful for breaking on return to a stack frame.\n\
157925796c8dcSSimon Schubert \n\
157935796c8dcSSimon Schubert THREADNUM is the number from \"info threads\".\n\
157945796c8dcSSimon Schubert CONDITION is a boolean expression.\n\
157955796c8dcSSimon Schubert \n\
15796cf7f2e2dSJohn Marino Multiple breakpoints at one place are permitted, and useful if their\n\
15797cf7f2e2dSJohn Marino conditions are different.\n\
157985796c8dcSSimon Schubert \n\
157995796c8dcSSimon Schubert Do \"help breakpoints\" for info on other commands dealing with breakpoints."
158005796c8dcSSimon Schubert 
158015796c8dcSSimon Schubert /* List of subcommands for "catch".  */
158025796c8dcSSimon Schubert static struct cmd_list_element *catch_cmdlist;
158035796c8dcSSimon Schubert 
158045796c8dcSSimon Schubert /* List of subcommands for "tcatch".  */
158055796c8dcSSimon Schubert static struct cmd_list_element *tcatch_cmdlist;
158065796c8dcSSimon Schubert 
15807a45ae5f8SJohn Marino void
add_catch_command(char * name,char * docstring,void (* sfunc)(char * args,int from_tty,struct cmd_list_element * command),completer_ftype * completer,void * user_data_catch,void * user_data_tcatch)158085796c8dcSSimon Schubert add_catch_command (char *name, char *docstring,
158095796c8dcSSimon Schubert 		   void (*sfunc) (char *args, int from_tty,
158105796c8dcSSimon Schubert 				  struct cmd_list_element *command),
15811*ef5ccd6cSJohn Marino 		   completer_ftype *completer,
158125796c8dcSSimon Schubert 		   void *user_data_catch,
158135796c8dcSSimon Schubert 		   void *user_data_tcatch)
158145796c8dcSSimon Schubert {
158155796c8dcSSimon Schubert   struct cmd_list_element *command;
158165796c8dcSSimon Schubert 
158175796c8dcSSimon Schubert   command = add_cmd (name, class_breakpoint, NULL, docstring,
158185796c8dcSSimon Schubert 		     &catch_cmdlist);
158195796c8dcSSimon Schubert   set_cmd_sfunc (command, sfunc);
158205796c8dcSSimon Schubert   set_cmd_context (command, user_data_catch);
158215796c8dcSSimon Schubert   set_cmd_completer (command, completer);
158225796c8dcSSimon Schubert 
158235796c8dcSSimon Schubert   command = add_cmd (name, class_breakpoint, NULL, docstring,
158245796c8dcSSimon Schubert 		     &tcatch_cmdlist);
158255796c8dcSSimon Schubert   set_cmd_sfunc (command, sfunc);
158265796c8dcSSimon Schubert   set_cmd_context (command, user_data_tcatch);
158275796c8dcSSimon Schubert   set_cmd_completer (command, completer);
158285796c8dcSSimon Schubert }
158295796c8dcSSimon Schubert 
15830cf7f2e2dSJohn Marino static void
clear_syscall_counts(struct inferior * inf)15831cf7f2e2dSJohn Marino clear_syscall_counts (struct inferior *inf)
15832cf7f2e2dSJohn Marino {
15833*ef5ccd6cSJohn Marino   struct catch_syscall_inferior_data *inf_data
15834*ef5ccd6cSJohn Marino     = get_catch_syscall_inferior_data (inf);
15835*ef5ccd6cSJohn Marino 
15836*ef5ccd6cSJohn Marino   inf_data->total_syscalls_count = 0;
15837*ef5ccd6cSJohn Marino   inf_data->any_syscall_count = 0;
15838*ef5ccd6cSJohn Marino   VEC_free (int, inf_data->syscalls_counts);
15839cf7f2e2dSJohn Marino }
15840cf7f2e2dSJohn Marino 
15841cf7f2e2dSJohn Marino static void
save_command(char * arg,int from_tty)15842cf7f2e2dSJohn Marino save_command (char *arg, int from_tty)
15843cf7f2e2dSJohn Marino {
15844c50c785cSJohn Marino   printf_unfiltered (_("\"save\" must be followed by "
15845c50c785cSJohn Marino 		       "the name of a save subcommand.\n"));
15846cf7f2e2dSJohn Marino   help_list (save_cmdlist, "save ", -1, gdb_stdout);
15847cf7f2e2dSJohn Marino }
15848cf7f2e2dSJohn Marino 
15849c50c785cSJohn Marino struct breakpoint *
iterate_over_breakpoints(int (* callback)(struct breakpoint *,void *),void * data)15850c50c785cSJohn Marino iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15851c50c785cSJohn Marino 			  void *data)
15852c50c785cSJohn Marino {
15853c50c785cSJohn Marino   struct breakpoint *b, *b_tmp;
15854c50c785cSJohn Marino 
15855c50c785cSJohn Marino   ALL_BREAKPOINTS_SAFE (b, b_tmp)
15856c50c785cSJohn Marino     {
15857c50c785cSJohn Marino       if ((*callback) (b, data))
15858c50c785cSJohn Marino 	return b;
15859c50c785cSJohn Marino     }
15860c50c785cSJohn Marino 
15861c50c785cSJohn Marino   return NULL;
15862c50c785cSJohn Marino }
15863c50c785cSJohn Marino 
15864a45ae5f8SJohn Marino /* Zero if any of the breakpoint's locations could be a location where
15865a45ae5f8SJohn Marino    functions have been inlined, nonzero otherwise.  */
15866a45ae5f8SJohn Marino 
15867a45ae5f8SJohn Marino static int
is_non_inline_function(struct breakpoint * b)15868a45ae5f8SJohn Marino is_non_inline_function (struct breakpoint *b)
15869a45ae5f8SJohn Marino {
15870a45ae5f8SJohn Marino   /* The shared library event breakpoint is set on the address of a
15871a45ae5f8SJohn Marino      non-inline function.  */
15872a45ae5f8SJohn Marino   if (b->type == bp_shlib_event)
15873a45ae5f8SJohn Marino     return 1;
15874a45ae5f8SJohn Marino 
15875a45ae5f8SJohn Marino   return 0;
15876a45ae5f8SJohn Marino }
15877a45ae5f8SJohn Marino 
15878a45ae5f8SJohn Marino /* Nonzero if the specified PC cannot be a location where functions
15879a45ae5f8SJohn Marino    have been inlined.  */
15880a45ae5f8SJohn Marino 
15881a45ae5f8SJohn Marino int
pc_at_non_inline_function(struct address_space * aspace,CORE_ADDR pc,const struct target_waitstatus * ws)15882*ef5ccd6cSJohn Marino pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15883*ef5ccd6cSJohn Marino 			   const struct target_waitstatus *ws)
15884a45ae5f8SJohn Marino {
15885a45ae5f8SJohn Marino   struct breakpoint *b;
15886a45ae5f8SJohn Marino   struct bp_location *bl;
15887a45ae5f8SJohn Marino 
15888a45ae5f8SJohn Marino   ALL_BREAKPOINTS (b)
15889a45ae5f8SJohn Marino     {
15890a45ae5f8SJohn Marino       if (!is_non_inline_function (b))
15891a45ae5f8SJohn Marino 	continue;
15892a45ae5f8SJohn Marino 
15893a45ae5f8SJohn Marino       for (bl = b->loc; bl != NULL; bl = bl->next)
15894a45ae5f8SJohn Marino 	{
15895a45ae5f8SJohn Marino 	  if (!bl->shlib_disabled
15896*ef5ccd6cSJohn Marino 	      && bpstat_check_location (bl, aspace, pc, ws))
15897a45ae5f8SJohn Marino 	    return 1;
15898a45ae5f8SJohn Marino 	}
15899a45ae5f8SJohn Marino     }
15900a45ae5f8SJohn Marino 
15901a45ae5f8SJohn Marino   return 0;
15902a45ae5f8SJohn Marino }
15903a45ae5f8SJohn Marino 
15904*ef5ccd6cSJohn Marino /* Remove any references to OBJFILE which is going to be freed.  */
15905*ef5ccd6cSJohn Marino 
15906*ef5ccd6cSJohn Marino void
breakpoint_free_objfile(struct objfile * objfile)15907*ef5ccd6cSJohn Marino breakpoint_free_objfile (struct objfile *objfile)
15908*ef5ccd6cSJohn Marino {
15909*ef5ccd6cSJohn Marino   struct bp_location **locp, *loc;
15910*ef5ccd6cSJohn Marino 
15911*ef5ccd6cSJohn Marino   ALL_BP_LOCATIONS (loc, locp)
15912*ef5ccd6cSJohn Marino     if (loc->symtab != NULL && loc->symtab->objfile == objfile)
15913*ef5ccd6cSJohn Marino       loc->symtab = NULL;
15914*ef5ccd6cSJohn Marino }
15915*ef5ccd6cSJohn Marino 
15916a45ae5f8SJohn Marino void
initialize_breakpoint_ops(void)15917a45ae5f8SJohn Marino initialize_breakpoint_ops (void)
15918a45ae5f8SJohn Marino {
15919a45ae5f8SJohn Marino   static int initialized = 0;
15920a45ae5f8SJohn Marino 
15921a45ae5f8SJohn Marino   struct breakpoint_ops *ops;
15922a45ae5f8SJohn Marino 
15923a45ae5f8SJohn Marino   if (initialized)
15924a45ae5f8SJohn Marino     return;
15925a45ae5f8SJohn Marino   initialized = 1;
15926a45ae5f8SJohn Marino 
15927a45ae5f8SJohn Marino   /* The breakpoint_ops structure to be inherit by all kinds of
15928a45ae5f8SJohn Marino      breakpoints (real breakpoints, i.e., user "break" breakpoints,
15929a45ae5f8SJohn Marino      internal and momentary breakpoints, etc.).  */
15930a45ae5f8SJohn Marino   ops = &bkpt_base_breakpoint_ops;
15931a45ae5f8SJohn Marino   *ops = base_breakpoint_ops;
15932a45ae5f8SJohn Marino   ops->re_set = bkpt_re_set;
15933a45ae5f8SJohn Marino   ops->insert_location = bkpt_insert_location;
15934a45ae5f8SJohn Marino   ops->remove_location = bkpt_remove_location;
15935a45ae5f8SJohn Marino   ops->breakpoint_hit = bkpt_breakpoint_hit;
15936*ef5ccd6cSJohn Marino   ops->create_sals_from_address = bkpt_create_sals_from_address;
15937*ef5ccd6cSJohn Marino   ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15938*ef5ccd6cSJohn Marino   ops->decode_linespec = bkpt_decode_linespec;
15939a45ae5f8SJohn Marino 
15940a45ae5f8SJohn Marino   /* The breakpoint_ops structure to be used in regular breakpoints.  */
15941a45ae5f8SJohn Marino   ops = &bkpt_breakpoint_ops;
15942a45ae5f8SJohn Marino   *ops = bkpt_base_breakpoint_ops;
15943a45ae5f8SJohn Marino   ops->re_set = bkpt_re_set;
15944a45ae5f8SJohn Marino   ops->resources_needed = bkpt_resources_needed;
15945a45ae5f8SJohn Marino   ops->print_it = bkpt_print_it;
15946a45ae5f8SJohn Marino   ops->print_mention = bkpt_print_mention;
15947a45ae5f8SJohn Marino   ops->print_recreate = bkpt_print_recreate;
15948a45ae5f8SJohn Marino 
15949a45ae5f8SJohn Marino   /* Ranged breakpoints.  */
15950a45ae5f8SJohn Marino   ops = &ranged_breakpoint_ops;
15951a45ae5f8SJohn Marino   *ops = bkpt_breakpoint_ops;
15952a45ae5f8SJohn Marino   ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15953a45ae5f8SJohn Marino   ops->resources_needed = resources_needed_ranged_breakpoint;
15954a45ae5f8SJohn Marino   ops->print_it = print_it_ranged_breakpoint;
15955a45ae5f8SJohn Marino   ops->print_one = print_one_ranged_breakpoint;
15956a45ae5f8SJohn Marino   ops->print_one_detail = print_one_detail_ranged_breakpoint;
15957a45ae5f8SJohn Marino   ops->print_mention = print_mention_ranged_breakpoint;
15958a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_ranged_breakpoint;
15959a45ae5f8SJohn Marino 
15960a45ae5f8SJohn Marino   /* Internal breakpoints.  */
15961a45ae5f8SJohn Marino   ops = &internal_breakpoint_ops;
15962a45ae5f8SJohn Marino   *ops = bkpt_base_breakpoint_ops;
15963a45ae5f8SJohn Marino   ops->re_set = internal_bkpt_re_set;
15964a45ae5f8SJohn Marino   ops->check_status = internal_bkpt_check_status;
15965a45ae5f8SJohn Marino   ops->print_it = internal_bkpt_print_it;
15966a45ae5f8SJohn Marino   ops->print_mention = internal_bkpt_print_mention;
15967a45ae5f8SJohn Marino 
15968a45ae5f8SJohn Marino   /* Momentary breakpoints.  */
15969a45ae5f8SJohn Marino   ops = &momentary_breakpoint_ops;
15970a45ae5f8SJohn Marino   *ops = bkpt_base_breakpoint_ops;
15971a45ae5f8SJohn Marino   ops->re_set = momentary_bkpt_re_set;
15972a45ae5f8SJohn Marino   ops->check_status = momentary_bkpt_check_status;
15973a45ae5f8SJohn Marino   ops->print_it = momentary_bkpt_print_it;
15974a45ae5f8SJohn Marino   ops->print_mention = momentary_bkpt_print_mention;
15975a45ae5f8SJohn Marino 
15976*ef5ccd6cSJohn Marino   /* Momentary breakpoints for bp_longjmp and bp_exception.  */
15977*ef5ccd6cSJohn Marino   ops = &longjmp_breakpoint_ops;
15978*ef5ccd6cSJohn Marino   *ops = momentary_breakpoint_ops;
15979*ef5ccd6cSJohn Marino   ops->dtor = longjmp_bkpt_dtor;
15980*ef5ccd6cSJohn Marino 
15981*ef5ccd6cSJohn Marino   /* Probe breakpoints.  */
15982*ef5ccd6cSJohn Marino   ops = &bkpt_probe_breakpoint_ops;
15983*ef5ccd6cSJohn Marino   *ops = bkpt_breakpoint_ops;
15984*ef5ccd6cSJohn Marino   ops->insert_location = bkpt_probe_insert_location;
15985*ef5ccd6cSJohn Marino   ops->remove_location = bkpt_probe_remove_location;
15986*ef5ccd6cSJohn Marino   ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15987*ef5ccd6cSJohn Marino   ops->decode_linespec = bkpt_probe_decode_linespec;
15988*ef5ccd6cSJohn Marino 
15989a45ae5f8SJohn Marino   /* GNU v3 exception catchpoints.  */
15990a45ae5f8SJohn Marino   ops = &gnu_v3_exception_catchpoint_ops;
15991a45ae5f8SJohn Marino   *ops = bkpt_breakpoint_ops;
15992a45ae5f8SJohn Marino   ops->print_it = print_it_exception_catchpoint;
15993a45ae5f8SJohn Marino   ops->print_one = print_one_exception_catchpoint;
15994a45ae5f8SJohn Marino   ops->print_mention = print_mention_exception_catchpoint;
15995a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_exception_catchpoint;
15996a45ae5f8SJohn Marino 
15997a45ae5f8SJohn Marino   /* Watchpoints.  */
15998a45ae5f8SJohn Marino   ops = &watchpoint_breakpoint_ops;
15999a45ae5f8SJohn Marino   *ops = base_breakpoint_ops;
16000a45ae5f8SJohn Marino   ops->dtor = dtor_watchpoint;
16001a45ae5f8SJohn Marino   ops->re_set = re_set_watchpoint;
16002a45ae5f8SJohn Marino   ops->insert_location = insert_watchpoint;
16003a45ae5f8SJohn Marino   ops->remove_location = remove_watchpoint;
16004a45ae5f8SJohn Marino   ops->breakpoint_hit = breakpoint_hit_watchpoint;
16005a45ae5f8SJohn Marino   ops->check_status = check_status_watchpoint;
16006a45ae5f8SJohn Marino   ops->resources_needed = resources_needed_watchpoint;
16007a45ae5f8SJohn Marino   ops->works_in_software_mode = works_in_software_mode_watchpoint;
16008a45ae5f8SJohn Marino   ops->print_it = print_it_watchpoint;
16009a45ae5f8SJohn Marino   ops->print_mention = print_mention_watchpoint;
16010a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_watchpoint;
16011*ef5ccd6cSJohn Marino   ops->explains_signal = explains_signal_watchpoint;
16012a45ae5f8SJohn Marino 
16013a45ae5f8SJohn Marino   /* Masked watchpoints.  */
16014a45ae5f8SJohn Marino   ops = &masked_watchpoint_breakpoint_ops;
16015a45ae5f8SJohn Marino   *ops = watchpoint_breakpoint_ops;
16016a45ae5f8SJohn Marino   ops->insert_location = insert_masked_watchpoint;
16017a45ae5f8SJohn Marino   ops->remove_location = remove_masked_watchpoint;
16018a45ae5f8SJohn Marino   ops->resources_needed = resources_needed_masked_watchpoint;
16019a45ae5f8SJohn Marino   ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
16020a45ae5f8SJohn Marino   ops->print_it = print_it_masked_watchpoint;
16021a45ae5f8SJohn Marino   ops->print_one_detail = print_one_detail_masked_watchpoint;
16022a45ae5f8SJohn Marino   ops->print_mention = print_mention_masked_watchpoint;
16023a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_masked_watchpoint;
16024a45ae5f8SJohn Marino 
16025a45ae5f8SJohn Marino   /* Tracepoints.  */
16026a45ae5f8SJohn Marino   ops = &tracepoint_breakpoint_ops;
16027a45ae5f8SJohn Marino   *ops = base_breakpoint_ops;
16028a45ae5f8SJohn Marino   ops->re_set = tracepoint_re_set;
16029a45ae5f8SJohn Marino   ops->breakpoint_hit = tracepoint_breakpoint_hit;
16030a45ae5f8SJohn Marino   ops->print_one_detail = tracepoint_print_one_detail;
16031a45ae5f8SJohn Marino   ops->print_mention = tracepoint_print_mention;
16032a45ae5f8SJohn Marino   ops->print_recreate = tracepoint_print_recreate;
16033*ef5ccd6cSJohn Marino   ops->create_sals_from_address = tracepoint_create_sals_from_address;
16034*ef5ccd6cSJohn Marino   ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
16035*ef5ccd6cSJohn Marino   ops->decode_linespec = tracepoint_decode_linespec;
16036*ef5ccd6cSJohn Marino 
16037*ef5ccd6cSJohn Marino   /* Probe tracepoints.  */
16038*ef5ccd6cSJohn Marino   ops = &tracepoint_probe_breakpoint_ops;
16039*ef5ccd6cSJohn Marino   *ops = tracepoint_breakpoint_ops;
16040*ef5ccd6cSJohn Marino   ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
16041*ef5ccd6cSJohn Marino   ops->decode_linespec = tracepoint_probe_decode_linespec;
16042*ef5ccd6cSJohn Marino 
16043*ef5ccd6cSJohn Marino   /* Static tracepoints with marker (`-m').  */
16044*ef5ccd6cSJohn Marino   ops = &strace_marker_breakpoint_ops;
16045*ef5ccd6cSJohn Marino   *ops = tracepoint_breakpoint_ops;
16046*ef5ccd6cSJohn Marino   ops->create_sals_from_address = strace_marker_create_sals_from_address;
16047*ef5ccd6cSJohn Marino   ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
16048*ef5ccd6cSJohn Marino   ops->decode_linespec = strace_marker_decode_linespec;
16049a45ae5f8SJohn Marino 
16050a45ae5f8SJohn Marino   /* Fork catchpoints.  */
16051a45ae5f8SJohn Marino   ops = &catch_fork_breakpoint_ops;
16052a45ae5f8SJohn Marino   *ops = base_breakpoint_ops;
16053a45ae5f8SJohn Marino   ops->insert_location = insert_catch_fork;
16054a45ae5f8SJohn Marino   ops->remove_location = remove_catch_fork;
16055a45ae5f8SJohn Marino   ops->breakpoint_hit = breakpoint_hit_catch_fork;
16056a45ae5f8SJohn Marino   ops->print_it = print_it_catch_fork;
16057a45ae5f8SJohn Marino   ops->print_one = print_one_catch_fork;
16058a45ae5f8SJohn Marino   ops->print_mention = print_mention_catch_fork;
16059a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_catch_fork;
16060a45ae5f8SJohn Marino 
16061a45ae5f8SJohn Marino   /* Vfork catchpoints.  */
16062a45ae5f8SJohn Marino   ops = &catch_vfork_breakpoint_ops;
16063a45ae5f8SJohn Marino   *ops = base_breakpoint_ops;
16064a45ae5f8SJohn Marino   ops->insert_location = insert_catch_vfork;
16065a45ae5f8SJohn Marino   ops->remove_location = remove_catch_vfork;
16066a45ae5f8SJohn Marino   ops->breakpoint_hit = breakpoint_hit_catch_vfork;
16067a45ae5f8SJohn Marino   ops->print_it = print_it_catch_vfork;
16068a45ae5f8SJohn Marino   ops->print_one = print_one_catch_vfork;
16069a45ae5f8SJohn Marino   ops->print_mention = print_mention_catch_vfork;
16070a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_catch_vfork;
16071a45ae5f8SJohn Marino 
16072a45ae5f8SJohn Marino   /* Exec catchpoints.  */
16073a45ae5f8SJohn Marino   ops = &catch_exec_breakpoint_ops;
16074a45ae5f8SJohn Marino   *ops = base_breakpoint_ops;
16075a45ae5f8SJohn Marino   ops->dtor = dtor_catch_exec;
16076a45ae5f8SJohn Marino   ops->insert_location = insert_catch_exec;
16077a45ae5f8SJohn Marino   ops->remove_location = remove_catch_exec;
16078a45ae5f8SJohn Marino   ops->breakpoint_hit = breakpoint_hit_catch_exec;
16079a45ae5f8SJohn Marino   ops->print_it = print_it_catch_exec;
16080a45ae5f8SJohn Marino   ops->print_one = print_one_catch_exec;
16081a45ae5f8SJohn Marino   ops->print_mention = print_mention_catch_exec;
16082a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_catch_exec;
16083a45ae5f8SJohn Marino 
16084a45ae5f8SJohn Marino   /* Syscall catchpoints.  */
16085a45ae5f8SJohn Marino   ops = &catch_syscall_breakpoint_ops;
16086a45ae5f8SJohn Marino   *ops = base_breakpoint_ops;
16087a45ae5f8SJohn Marino   ops->dtor = dtor_catch_syscall;
16088a45ae5f8SJohn Marino   ops->insert_location = insert_catch_syscall;
16089a45ae5f8SJohn Marino   ops->remove_location = remove_catch_syscall;
16090a45ae5f8SJohn Marino   ops->breakpoint_hit = breakpoint_hit_catch_syscall;
16091a45ae5f8SJohn Marino   ops->print_it = print_it_catch_syscall;
16092a45ae5f8SJohn Marino   ops->print_one = print_one_catch_syscall;
16093a45ae5f8SJohn Marino   ops->print_mention = print_mention_catch_syscall;
16094a45ae5f8SJohn Marino   ops->print_recreate = print_recreate_catch_syscall;
16095*ef5ccd6cSJohn Marino 
16096*ef5ccd6cSJohn Marino   /* Solib-related catchpoints.  */
16097*ef5ccd6cSJohn Marino   ops = &catch_solib_breakpoint_ops;
16098*ef5ccd6cSJohn Marino   *ops = base_breakpoint_ops;
16099*ef5ccd6cSJohn Marino   ops->dtor = dtor_catch_solib;
16100*ef5ccd6cSJohn Marino   ops->insert_location = insert_catch_solib;
16101*ef5ccd6cSJohn Marino   ops->remove_location = remove_catch_solib;
16102*ef5ccd6cSJohn Marino   ops->breakpoint_hit = breakpoint_hit_catch_solib;
16103*ef5ccd6cSJohn Marino   ops->check_status = check_status_catch_solib;
16104*ef5ccd6cSJohn Marino   ops->print_it = print_it_catch_solib;
16105*ef5ccd6cSJohn Marino   ops->print_one = print_one_catch_solib;
16106*ef5ccd6cSJohn Marino   ops->print_mention = print_mention_catch_solib;
16107*ef5ccd6cSJohn Marino   ops->print_recreate = print_recreate_catch_solib;
16108*ef5ccd6cSJohn Marino 
16109*ef5ccd6cSJohn Marino   ops = &dprintf_breakpoint_ops;
16110*ef5ccd6cSJohn Marino   *ops = bkpt_base_breakpoint_ops;
16111*ef5ccd6cSJohn Marino   ops->re_set = dprintf_re_set;
16112*ef5ccd6cSJohn Marino   ops->resources_needed = bkpt_resources_needed;
16113*ef5ccd6cSJohn Marino   ops->print_it = bkpt_print_it;
16114*ef5ccd6cSJohn Marino   ops->print_mention = bkpt_print_mention;
16115*ef5ccd6cSJohn Marino   ops->print_recreate = dprintf_print_recreate;
16116*ef5ccd6cSJohn Marino   ops->after_condition_true = dprintf_after_condition_true;
16117a45ae5f8SJohn Marino }
16118a45ae5f8SJohn Marino 
16119*ef5ccd6cSJohn Marino /* Chain containing all defined "enable breakpoint" subcommands.  */
16120*ef5ccd6cSJohn Marino 
16121*ef5ccd6cSJohn Marino static struct cmd_list_element *enablebreaklist = NULL;
16122*ef5ccd6cSJohn Marino 
161235796c8dcSSimon Schubert void
_initialize_breakpoint(void)161245796c8dcSSimon Schubert _initialize_breakpoint (void)
161255796c8dcSSimon Schubert {
161265796c8dcSSimon Schubert   struct cmd_list_element *c;
161275796c8dcSSimon Schubert 
16128a45ae5f8SJohn Marino   initialize_breakpoint_ops ();
16129a45ae5f8SJohn Marino 
161305796c8dcSSimon Schubert   observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
16131cf7f2e2dSJohn Marino   observer_attach_inferior_exit (clear_syscall_counts);
16132cf7f2e2dSJohn Marino   observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
161335796c8dcSSimon Schubert 
16134*ef5ccd6cSJohn Marino   breakpoint_objfile_key
16135*ef5ccd6cSJohn Marino     = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
16136*ef5ccd6cSJohn Marino 
16137*ef5ccd6cSJohn Marino   catch_syscall_inferior_data
16138*ef5ccd6cSJohn Marino     = register_inferior_data_with_cleanup (NULL,
16139*ef5ccd6cSJohn Marino 					   catch_syscall_inferior_data_cleanup);
16140c50c785cSJohn Marino 
161415796c8dcSSimon Schubert   breakpoint_chain = 0;
161425796c8dcSSimon Schubert   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
161435796c8dcSSimon Schubert      before a breakpoint is set.  */
161445796c8dcSSimon Schubert   breakpoint_count = 0;
161455796c8dcSSimon Schubert 
161465796c8dcSSimon Schubert   tracepoint_count = 0;
161475796c8dcSSimon Schubert 
161485796c8dcSSimon Schubert   add_com ("ignore", class_breakpoint, ignore_command, _("\
161495796c8dcSSimon Schubert Set ignore-count of breakpoint number N to COUNT.\n\
161505796c8dcSSimon Schubert Usage is `ignore N COUNT'."));
161515796c8dcSSimon Schubert   if (xdb_commands)
161525796c8dcSSimon Schubert     add_com_alias ("bc", "ignore", class_breakpoint, 1);
161535796c8dcSSimon Schubert 
161545796c8dcSSimon Schubert   add_com ("commands", class_breakpoint, commands_command, _("\
161555796c8dcSSimon Schubert Set commands to be executed when a breakpoint is hit.\n\
161565796c8dcSSimon Schubert Give breakpoint number as argument after \"commands\".\n\
161575796c8dcSSimon Schubert With no argument, the targeted breakpoint is the last one set.\n\
161585796c8dcSSimon Schubert The commands themselves follow starting on the next line.\n\
161595796c8dcSSimon Schubert Type a line containing \"end\" to indicate the end of them.\n\
161605796c8dcSSimon Schubert Give \"silent\" as the first line to make the breakpoint silent;\n\
161615796c8dcSSimon Schubert then no output is printed when it is hit, except what the commands print."));
161625796c8dcSSimon Schubert 
16163*ef5ccd6cSJohn Marino   c = add_com ("condition", class_breakpoint, condition_command, _("\
161645796c8dcSSimon Schubert Specify breakpoint number N to break only if COND is true.\n\
161655796c8dcSSimon Schubert Usage is `condition N COND', where N is an integer and COND is an\n\
161665796c8dcSSimon Schubert expression to be evaluated whenever breakpoint N is reached."));
16167*ef5ccd6cSJohn Marino   set_cmd_completer (c, condition_completer);
161685796c8dcSSimon Schubert 
161695796c8dcSSimon Schubert   c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
161705796c8dcSSimon Schubert Set a temporary breakpoint.\n\
161715796c8dcSSimon Schubert Like \"break\" except the breakpoint is only temporary,\n\
161725796c8dcSSimon Schubert so it will be deleted when hit.  Equivalent to \"break\" followed\n\
161735796c8dcSSimon Schubert by using \"enable delete\" on the breakpoint number.\n\
161745796c8dcSSimon Schubert \n"
161755796c8dcSSimon Schubert BREAK_ARGS_HELP ("tbreak")));
161765796c8dcSSimon Schubert   set_cmd_completer (c, location_completer);
161775796c8dcSSimon Schubert 
161785796c8dcSSimon Schubert   c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
161795796c8dcSSimon Schubert Set a hardware assisted breakpoint.\n\
161805796c8dcSSimon Schubert Like \"break\" except the breakpoint requires hardware support,\n\
161815796c8dcSSimon Schubert some target hardware may not have this support.\n\
161825796c8dcSSimon Schubert \n"
161835796c8dcSSimon Schubert BREAK_ARGS_HELP ("hbreak")));
161845796c8dcSSimon Schubert   set_cmd_completer (c, location_completer);
161855796c8dcSSimon Schubert 
161865796c8dcSSimon Schubert   c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
161875796c8dcSSimon Schubert Set a temporary hardware assisted breakpoint.\n\
161885796c8dcSSimon Schubert Like \"hbreak\" except the breakpoint is only temporary,\n\
161895796c8dcSSimon Schubert so it will be deleted when hit.\n\
161905796c8dcSSimon Schubert \n"
161915796c8dcSSimon Schubert BREAK_ARGS_HELP ("thbreak")));
161925796c8dcSSimon Schubert   set_cmd_completer (c, location_completer);
161935796c8dcSSimon Schubert 
161945796c8dcSSimon Schubert   add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
161955796c8dcSSimon Schubert Enable some breakpoints.\n\
161965796c8dcSSimon Schubert Give breakpoint numbers (separated by spaces) as arguments.\n\
161975796c8dcSSimon Schubert With no subcommand, breakpoints are enabled until you command otherwise.\n\
161985796c8dcSSimon Schubert This is used to cancel the effect of the \"disable\" command.\n\
161995796c8dcSSimon Schubert With a subcommand you can enable temporarily."),
162005796c8dcSSimon Schubert 		  &enablelist, "enable ", 1, &cmdlist);
162015796c8dcSSimon Schubert   if (xdb_commands)
162025796c8dcSSimon Schubert     add_com ("ab", class_breakpoint, enable_command, _("\
162035796c8dcSSimon Schubert Enable some breakpoints.\n\
162045796c8dcSSimon Schubert Give breakpoint numbers (separated by spaces) as arguments.\n\
162055796c8dcSSimon Schubert With no subcommand, breakpoints are enabled until you command otherwise.\n\
162065796c8dcSSimon Schubert This is used to cancel the effect of the \"disable\" command.\n\
162075796c8dcSSimon Schubert With a subcommand you can enable temporarily."));
162085796c8dcSSimon Schubert 
162095796c8dcSSimon Schubert   add_com_alias ("en", "enable", class_breakpoint, 1);
162105796c8dcSSimon Schubert 
16211cf7f2e2dSJohn Marino   add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
162125796c8dcSSimon Schubert Enable some breakpoints.\n\
162135796c8dcSSimon Schubert Give breakpoint numbers (separated by spaces) as arguments.\n\
162145796c8dcSSimon Schubert This is used to cancel the effect of the \"disable\" command.\n\
162155796c8dcSSimon Schubert May be abbreviated to simply \"enable\".\n"),
162165796c8dcSSimon Schubert 		   &enablebreaklist, "enable breakpoints ", 1, &enablelist);
162175796c8dcSSimon Schubert 
162185796c8dcSSimon Schubert   add_cmd ("once", no_class, enable_once_command, _("\
162195796c8dcSSimon Schubert Enable breakpoints for one hit.  Give breakpoint numbers.\n\
162205796c8dcSSimon Schubert If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
162215796c8dcSSimon Schubert 	   &enablebreaklist);
162225796c8dcSSimon Schubert 
162235796c8dcSSimon Schubert   add_cmd ("delete", no_class, enable_delete_command, _("\
162245796c8dcSSimon Schubert Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
162255796c8dcSSimon Schubert If a breakpoint is hit while enabled in this fashion, it is deleted."),
162265796c8dcSSimon Schubert 	   &enablebreaklist);
162275796c8dcSSimon Schubert 
16228*ef5ccd6cSJohn Marino   add_cmd ("count", no_class, enable_count_command, _("\
16229*ef5ccd6cSJohn Marino Enable breakpoints for COUNT hits.  Give count and then breakpoint numbers.\n\
16230*ef5ccd6cSJohn Marino If a breakpoint is hit while enabled in this fashion,\n\
16231*ef5ccd6cSJohn Marino the count is decremented; when it reaches zero, the breakpoint is disabled."),
16232*ef5ccd6cSJohn Marino 	   &enablebreaklist);
16233*ef5ccd6cSJohn Marino 
162345796c8dcSSimon Schubert   add_cmd ("delete", no_class, enable_delete_command, _("\
162355796c8dcSSimon Schubert Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
162365796c8dcSSimon Schubert If a breakpoint is hit while enabled in this fashion, it is deleted."),
162375796c8dcSSimon Schubert 	   &enablelist);
162385796c8dcSSimon Schubert 
162395796c8dcSSimon Schubert   add_cmd ("once", no_class, enable_once_command, _("\
162405796c8dcSSimon Schubert Enable breakpoints for one hit.  Give breakpoint numbers.\n\
162415796c8dcSSimon Schubert If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
162425796c8dcSSimon Schubert 	   &enablelist);
162435796c8dcSSimon Schubert 
16244*ef5ccd6cSJohn Marino   add_cmd ("count", no_class, enable_count_command, _("\
16245*ef5ccd6cSJohn Marino Enable breakpoints for COUNT hits.  Give count and then breakpoint numbers.\n\
16246*ef5ccd6cSJohn Marino If a breakpoint is hit while enabled in this fashion,\n\
16247*ef5ccd6cSJohn Marino the count is decremented; when it reaches zero, the breakpoint is disabled."),
16248*ef5ccd6cSJohn Marino 	   &enablelist);
16249*ef5ccd6cSJohn Marino 
162505796c8dcSSimon Schubert   add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
162515796c8dcSSimon Schubert Disable some breakpoints.\n\
162525796c8dcSSimon Schubert Arguments are breakpoint numbers with spaces in between.\n\
162535796c8dcSSimon Schubert To disable all breakpoints, give no argument.\n\
16254a45ae5f8SJohn Marino A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
162555796c8dcSSimon Schubert 		  &disablelist, "disable ", 1, &cmdlist);
162565796c8dcSSimon Schubert   add_com_alias ("dis", "disable", class_breakpoint, 1);
162575796c8dcSSimon Schubert   add_com_alias ("disa", "disable", class_breakpoint, 1);
162585796c8dcSSimon Schubert   if (xdb_commands)
162595796c8dcSSimon Schubert     add_com ("sb", class_breakpoint, disable_command, _("\
162605796c8dcSSimon Schubert Disable some breakpoints.\n\
162615796c8dcSSimon Schubert Arguments are breakpoint numbers with spaces in between.\n\
162625796c8dcSSimon Schubert To disable all breakpoints, give no argument.\n\
16263a45ae5f8SJohn Marino A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
162645796c8dcSSimon Schubert 
162655796c8dcSSimon Schubert   add_cmd ("breakpoints", class_alias, disable_command, _("\
162665796c8dcSSimon Schubert Disable some breakpoints.\n\
162675796c8dcSSimon Schubert Arguments are breakpoint numbers with spaces in between.\n\
162685796c8dcSSimon Schubert To disable all breakpoints, give no argument.\n\
16269a45ae5f8SJohn Marino A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
162705796c8dcSSimon Schubert This command may be abbreviated \"disable\"."),
162715796c8dcSSimon Schubert 	   &disablelist);
162725796c8dcSSimon Schubert 
162735796c8dcSSimon Schubert   add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
162745796c8dcSSimon Schubert Delete some breakpoints or auto-display expressions.\n\
162755796c8dcSSimon Schubert Arguments are breakpoint numbers with spaces in between.\n\
162765796c8dcSSimon Schubert To delete all breakpoints, give no argument.\n\
162775796c8dcSSimon Schubert \n\
162785796c8dcSSimon Schubert Also a prefix command for deletion of other GDB objects.\n\
162795796c8dcSSimon Schubert The \"unset\" command is also an alias for \"delete\"."),
162805796c8dcSSimon Schubert 		  &deletelist, "delete ", 1, &cmdlist);
162815796c8dcSSimon Schubert   add_com_alias ("d", "delete", class_breakpoint, 1);
162825796c8dcSSimon Schubert   add_com_alias ("del", "delete", class_breakpoint, 1);
162835796c8dcSSimon Schubert   if (xdb_commands)
162845796c8dcSSimon Schubert     add_com ("db", class_breakpoint, delete_command, _("\
162855796c8dcSSimon Schubert Delete some breakpoints.\n\
162865796c8dcSSimon Schubert Arguments are breakpoint numbers with spaces in between.\n\
162875796c8dcSSimon Schubert To delete all breakpoints, give no argument.\n"));
162885796c8dcSSimon Schubert 
162895796c8dcSSimon Schubert   add_cmd ("breakpoints", class_alias, delete_command, _("\
162905796c8dcSSimon Schubert Delete some breakpoints or auto-display expressions.\n\
162915796c8dcSSimon Schubert Arguments are breakpoint numbers with spaces in between.\n\
162925796c8dcSSimon Schubert To delete all breakpoints, give no argument.\n\
162935796c8dcSSimon Schubert This command may be abbreviated \"delete\"."),
162945796c8dcSSimon Schubert 	   &deletelist);
162955796c8dcSSimon Schubert 
162965796c8dcSSimon Schubert   add_com ("clear", class_breakpoint, clear_command, _("\
162975796c8dcSSimon Schubert Clear breakpoint at specified line or function.\n\
162985796c8dcSSimon Schubert Argument may be line number, function name, or \"*\" and an address.\n\
162995796c8dcSSimon Schubert If line number is specified, all breakpoints in that line are cleared.\n\
163005796c8dcSSimon Schubert If function is specified, breakpoints at beginning of function are cleared.\n\
163015796c8dcSSimon Schubert If an address is specified, breakpoints at that address are cleared.\n\
163025796c8dcSSimon Schubert \n\
163035796c8dcSSimon Schubert With no argument, clears all breakpoints in the line that the selected frame\n\
163045796c8dcSSimon Schubert is executing in.\n\
163055796c8dcSSimon Schubert \n\
163065796c8dcSSimon Schubert See also the \"delete\" command which clears breakpoints by number."));
16307cf7f2e2dSJohn Marino   add_com_alias ("cl", "clear", class_breakpoint, 1);
163085796c8dcSSimon Schubert 
163095796c8dcSSimon Schubert   c = add_com ("break", class_breakpoint, break_command, _("\
163105796c8dcSSimon Schubert Set breakpoint at specified line or function.\n"
163115796c8dcSSimon Schubert BREAK_ARGS_HELP ("break")));
163125796c8dcSSimon Schubert   set_cmd_completer (c, location_completer);
163135796c8dcSSimon Schubert 
163145796c8dcSSimon Schubert   add_com_alias ("b", "break", class_run, 1);
163155796c8dcSSimon Schubert   add_com_alias ("br", "break", class_run, 1);
163165796c8dcSSimon Schubert   add_com_alias ("bre", "break", class_run, 1);
163175796c8dcSSimon Schubert   add_com_alias ("brea", "break", class_run, 1);
163185796c8dcSSimon Schubert 
163195796c8dcSSimon Schubert   if (xdb_commands)
163205796c8dcSSimon Schubert    add_com_alias ("ba", "break", class_breakpoint, 1);
163215796c8dcSSimon Schubert 
163225796c8dcSSimon Schubert   if (dbx_commands)
163235796c8dcSSimon Schubert     {
163245796c8dcSSimon Schubert       add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
163255796c8dcSSimon Schubert Break in function/address or break at a line in the current file."),
163265796c8dcSSimon Schubert 			     &stoplist, "stop ", 1, &cmdlist);
163275796c8dcSSimon Schubert       add_cmd ("in", class_breakpoint, stopin_command,
163285796c8dcSSimon Schubert 	       _("Break in function or address."), &stoplist);
163295796c8dcSSimon Schubert       add_cmd ("at", class_breakpoint, stopat_command,
163305796c8dcSSimon Schubert 	       _("Break at a line in the current file."), &stoplist);
163315796c8dcSSimon Schubert       add_com ("status", class_info, breakpoints_info, _("\
163325796c8dcSSimon Schubert Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
163335796c8dcSSimon Schubert The \"Type\" column indicates one of:\n\
163345796c8dcSSimon Schubert \tbreakpoint     - normal breakpoint\n\
163355796c8dcSSimon Schubert \twatchpoint     - watchpoint\n\
163365796c8dcSSimon Schubert The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
163375796c8dcSSimon Schubert the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
163385796c8dcSSimon Schubert breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
163395796c8dcSSimon Schubert address and file/line number respectively.\n\
163405796c8dcSSimon Schubert \n\
163415796c8dcSSimon Schubert Convenience variable \"$_\" and default examine address for \"x\"\n\
163425796c8dcSSimon Schubert are set to the address of the last breakpoint listed unless the command\n\
163435796c8dcSSimon Schubert is prefixed with \"server \".\n\n\
163445796c8dcSSimon Schubert Convenience variable \"$bpnum\" contains the number of the last\n\
163455796c8dcSSimon Schubert breakpoint set."));
163465796c8dcSSimon Schubert     }
163475796c8dcSSimon Schubert 
163485796c8dcSSimon Schubert   add_info ("breakpoints", breakpoints_info, _("\
16349c50c785cSJohn Marino Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
163505796c8dcSSimon Schubert The \"Type\" column indicates one of:\n\
163515796c8dcSSimon Schubert \tbreakpoint     - normal breakpoint\n\
163525796c8dcSSimon Schubert \twatchpoint     - watchpoint\n\
163535796c8dcSSimon Schubert The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
163545796c8dcSSimon Schubert the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
163555796c8dcSSimon Schubert breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
163565796c8dcSSimon Schubert address and file/line number respectively.\n\
163575796c8dcSSimon Schubert \n\
163585796c8dcSSimon Schubert Convenience variable \"$_\" and default examine address for \"x\"\n\
163595796c8dcSSimon Schubert are set to the address of the last breakpoint listed unless the command\n\
163605796c8dcSSimon Schubert is prefixed with \"server \".\n\n\
163615796c8dcSSimon Schubert Convenience variable \"$bpnum\" contains the number of the last\n\
163625796c8dcSSimon Schubert breakpoint set."));
163635796c8dcSSimon Schubert 
16364cf7f2e2dSJohn Marino   add_info_alias ("b", "breakpoints", 1);
16365cf7f2e2dSJohn Marino 
163665796c8dcSSimon Schubert   if (xdb_commands)
163675796c8dcSSimon Schubert     add_com ("lb", class_breakpoint, breakpoints_info, _("\
163685796c8dcSSimon Schubert Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
163695796c8dcSSimon Schubert The \"Type\" column indicates one of:\n\
163705796c8dcSSimon Schubert \tbreakpoint     - normal breakpoint\n\
163715796c8dcSSimon Schubert \twatchpoint     - watchpoint\n\
163725796c8dcSSimon Schubert The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
163735796c8dcSSimon Schubert the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
163745796c8dcSSimon Schubert breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
163755796c8dcSSimon Schubert address and file/line number respectively.\n\
163765796c8dcSSimon Schubert \n\
163775796c8dcSSimon Schubert Convenience variable \"$_\" and default examine address for \"x\"\n\
163785796c8dcSSimon Schubert are set to the address of the last breakpoint listed unless the command\n\
163795796c8dcSSimon Schubert is prefixed with \"server \".\n\n\
163805796c8dcSSimon Schubert Convenience variable \"$bpnum\" contains the number of the last\n\
163815796c8dcSSimon Schubert breakpoint set."));
163825796c8dcSSimon Schubert 
163835796c8dcSSimon Schubert   add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
163845796c8dcSSimon Schubert Status of all breakpoints, or breakpoint number NUMBER.\n\
163855796c8dcSSimon Schubert The \"Type\" column indicates one of:\n\
163865796c8dcSSimon Schubert \tbreakpoint     - normal breakpoint\n\
163875796c8dcSSimon Schubert \twatchpoint     - watchpoint\n\
163885796c8dcSSimon Schubert \tlongjmp        - internal breakpoint used to step through longjmp()\n\
163895796c8dcSSimon Schubert \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
163905796c8dcSSimon Schubert \tuntil          - internal breakpoint used by the \"until\" command\n\
163915796c8dcSSimon Schubert \tfinish         - internal breakpoint used by the \"finish\" command\n\
163925796c8dcSSimon Schubert The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
163935796c8dcSSimon Schubert the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
163945796c8dcSSimon Schubert breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
163955796c8dcSSimon Schubert address and file/line number respectively.\n\
163965796c8dcSSimon Schubert \n\
163975796c8dcSSimon Schubert Convenience variable \"$_\" and default examine address for \"x\"\n\
163985796c8dcSSimon Schubert are set to the address of the last breakpoint listed unless the command\n\
163995796c8dcSSimon Schubert is prefixed with \"server \".\n\n\
164005796c8dcSSimon Schubert Convenience variable \"$bpnum\" contains the number of the last\n\
164015796c8dcSSimon Schubert breakpoint set."),
164025796c8dcSSimon Schubert 	   &maintenanceinfolist);
164035796c8dcSSimon Schubert 
164045796c8dcSSimon Schubert   add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
164055796c8dcSSimon Schubert Set catchpoints to catch events."),
164065796c8dcSSimon Schubert 		  &catch_cmdlist, "catch ",
164075796c8dcSSimon Schubert 		  0/*allow-unknown*/, &cmdlist);
164085796c8dcSSimon Schubert 
164095796c8dcSSimon Schubert   add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
164105796c8dcSSimon Schubert Set temporary catchpoints to catch events."),
164115796c8dcSSimon Schubert 		  &tcatch_cmdlist, "tcatch ",
164125796c8dcSSimon Schubert 		  0/*allow-unknown*/, &cmdlist);
164135796c8dcSSimon Schubert 
164145796c8dcSSimon Schubert   /* Add catch and tcatch sub-commands.  */
164155796c8dcSSimon Schubert   add_catch_command ("catch", _("\
16416*ef5ccd6cSJohn Marino Catch an exception, when caught."),
164175796c8dcSSimon Schubert 		     catch_catch_command,
164185796c8dcSSimon Schubert                      NULL,
164195796c8dcSSimon Schubert 		     CATCH_PERMANENT,
164205796c8dcSSimon Schubert 		     CATCH_TEMPORARY);
164215796c8dcSSimon Schubert   add_catch_command ("throw", _("\
16422*ef5ccd6cSJohn Marino Catch an exception, when thrown."),
164235796c8dcSSimon Schubert 		     catch_throw_command,
164245796c8dcSSimon Schubert                      NULL,
164255796c8dcSSimon Schubert 		     CATCH_PERMANENT,
164265796c8dcSSimon Schubert 		     CATCH_TEMPORARY);
164275796c8dcSSimon Schubert   add_catch_command ("fork", _("Catch calls to fork."),
164285796c8dcSSimon Schubert 		     catch_fork_command_1,
164295796c8dcSSimon Schubert                      NULL,
164305796c8dcSSimon Schubert 		     (void *) (uintptr_t) catch_fork_permanent,
164315796c8dcSSimon Schubert 		     (void *) (uintptr_t) catch_fork_temporary);
164325796c8dcSSimon Schubert   add_catch_command ("vfork", _("Catch calls to vfork."),
164335796c8dcSSimon Schubert 		     catch_fork_command_1,
164345796c8dcSSimon Schubert                      NULL,
164355796c8dcSSimon Schubert 		     (void *) (uintptr_t) catch_vfork_permanent,
164365796c8dcSSimon Schubert 		     (void *) (uintptr_t) catch_vfork_temporary);
164375796c8dcSSimon Schubert   add_catch_command ("exec", _("Catch calls to exec."),
164385796c8dcSSimon Schubert 		     catch_exec_command_1,
164395796c8dcSSimon Schubert                      NULL,
164405796c8dcSSimon Schubert 		     CATCH_PERMANENT,
164415796c8dcSSimon Schubert 		     CATCH_TEMPORARY);
16442*ef5ccd6cSJohn Marino   add_catch_command ("load", _("Catch loads of shared libraries.\n\
16443*ef5ccd6cSJohn Marino Usage: catch load [REGEX]\n\
16444*ef5ccd6cSJohn Marino If REGEX is given, only stop for libraries matching the regular expression."),
16445*ef5ccd6cSJohn Marino 		     catch_load_command_1,
16446*ef5ccd6cSJohn Marino 		     NULL,
16447*ef5ccd6cSJohn Marino 		     CATCH_PERMANENT,
16448*ef5ccd6cSJohn Marino 		     CATCH_TEMPORARY);
16449*ef5ccd6cSJohn Marino   add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16450*ef5ccd6cSJohn Marino Usage: catch unload [REGEX]\n\
16451*ef5ccd6cSJohn Marino If REGEX is given, only stop for libraries matching the regular expression."),
16452*ef5ccd6cSJohn Marino 		     catch_unload_command_1,
16453*ef5ccd6cSJohn Marino 		     NULL,
16454*ef5ccd6cSJohn Marino 		     CATCH_PERMANENT,
16455*ef5ccd6cSJohn Marino 		     CATCH_TEMPORARY);
164565796c8dcSSimon Schubert   add_catch_command ("syscall", _("\
164575796c8dcSSimon Schubert Catch system calls by their names and/or numbers.\n\
164585796c8dcSSimon Schubert Arguments say which system calls to catch.  If no arguments\n\
164595796c8dcSSimon Schubert are given, every system call will be caught.\n\
164605796c8dcSSimon Schubert Arguments, if given, should be one or more system call names\n\
164615796c8dcSSimon Schubert (if your system supports that), or system call numbers."),
164625796c8dcSSimon Schubert 		     catch_syscall_command_1,
164635796c8dcSSimon Schubert 		     catch_syscall_completer,
164645796c8dcSSimon Schubert 		     CATCH_PERMANENT,
164655796c8dcSSimon Schubert 		     CATCH_TEMPORARY);
164665796c8dcSSimon Schubert 
164675796c8dcSSimon Schubert   c = add_com ("watch", class_breakpoint, watch_command, _("\
164685796c8dcSSimon Schubert Set a watchpoint for an expression.\n\
16469c50c785cSJohn Marino Usage: watch [-l|-location] EXPRESSION\n\
164705796c8dcSSimon Schubert A watchpoint stops execution of your program whenever the value of\n\
16471c50c785cSJohn Marino an expression changes.\n\
16472c50c785cSJohn Marino If -l or -location is given, this evaluates EXPRESSION and watches\n\
16473c50c785cSJohn Marino the memory to which it refers."));
164745796c8dcSSimon Schubert   set_cmd_completer (c, expression_completer);
164755796c8dcSSimon Schubert 
164765796c8dcSSimon Schubert   c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
164775796c8dcSSimon Schubert Set a read watchpoint for an expression.\n\
16478c50c785cSJohn Marino Usage: rwatch [-l|-location] EXPRESSION\n\
164795796c8dcSSimon Schubert A watchpoint stops execution of your program whenever the value of\n\
16480c50c785cSJohn Marino an expression is read.\n\
16481c50c785cSJohn Marino If -l or -location is given, this evaluates EXPRESSION and watches\n\
16482c50c785cSJohn Marino the memory to which it refers."));
164835796c8dcSSimon Schubert   set_cmd_completer (c, expression_completer);
164845796c8dcSSimon Schubert 
164855796c8dcSSimon Schubert   c = add_com ("awatch", class_breakpoint, awatch_command, _("\
164865796c8dcSSimon Schubert Set a watchpoint for an expression.\n\
16487c50c785cSJohn Marino Usage: awatch [-l|-location] EXPRESSION\n\
164885796c8dcSSimon Schubert A watchpoint stops execution of your program whenever the value of\n\
16489c50c785cSJohn Marino an expression is either read or written.\n\
16490c50c785cSJohn Marino If -l or -location is given, this evaluates EXPRESSION and watches\n\
16491c50c785cSJohn Marino the memory to which it refers."));
164925796c8dcSSimon Schubert   set_cmd_completer (c, expression_completer);
164935796c8dcSSimon Schubert 
16494cf7f2e2dSJohn Marino   add_info ("watchpoints", watchpoints_info, _("\
16495c50c785cSJohn Marino Status of specified watchpoints (all watchpoints if no argument)."));
164965796c8dcSSimon Schubert 
164975796c8dcSSimon Schubert   /* XXX: cagney/2005-02-23: This should be a boolean, and should
164985796c8dcSSimon Schubert      respond to changes - contrary to the description.  */
164995796c8dcSSimon Schubert   add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
165005796c8dcSSimon Schubert 			    &can_use_hw_watchpoints, _("\
165015796c8dcSSimon Schubert Set debugger's willingness to use watchpoint hardware."), _("\
165025796c8dcSSimon Schubert Show debugger's willingness to use watchpoint hardware."), _("\
165035796c8dcSSimon Schubert If zero, gdb will not use hardware for new watchpoints, even if\n\
165045796c8dcSSimon Schubert such is available.  (However, any hardware watchpoints that were\n\
165055796c8dcSSimon Schubert created before setting this to nonzero, will continue to use watchpoint\n\
165065796c8dcSSimon Schubert hardware.)"),
165075796c8dcSSimon Schubert 			    NULL,
165085796c8dcSSimon Schubert 			    show_can_use_hw_watchpoints,
165095796c8dcSSimon Schubert 			    &setlist, &showlist);
165105796c8dcSSimon Schubert 
165115796c8dcSSimon Schubert   can_use_hw_watchpoints = 1;
165125796c8dcSSimon Schubert 
165135796c8dcSSimon Schubert   /* Tracepoint manipulation commands.  */
165145796c8dcSSimon Schubert 
165155796c8dcSSimon Schubert   c = add_com ("trace", class_breakpoint, trace_command, _("\
165165796c8dcSSimon Schubert Set a tracepoint at specified line or function.\n\
165175796c8dcSSimon Schubert \n"
165185796c8dcSSimon Schubert BREAK_ARGS_HELP ("trace") "\n\
165195796c8dcSSimon Schubert Do \"help tracepoints\" for info on other tracepoint commands."));
165205796c8dcSSimon Schubert   set_cmd_completer (c, location_completer);
165215796c8dcSSimon Schubert 
165225796c8dcSSimon Schubert   add_com_alias ("tp", "trace", class_alias, 0);
165235796c8dcSSimon Schubert   add_com_alias ("tr", "trace", class_alias, 1);
165245796c8dcSSimon Schubert   add_com_alias ("tra", "trace", class_alias, 1);
165255796c8dcSSimon Schubert   add_com_alias ("trac", "trace", class_alias, 1);
165265796c8dcSSimon Schubert 
16527cf7f2e2dSJohn Marino   c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
16528cf7f2e2dSJohn Marino Set a fast tracepoint at specified line or function.\n\
16529cf7f2e2dSJohn Marino \n"
16530cf7f2e2dSJohn Marino BREAK_ARGS_HELP ("ftrace") "\n\
16531cf7f2e2dSJohn Marino Do \"help tracepoints\" for info on other tracepoint commands."));
16532cf7f2e2dSJohn Marino   set_cmd_completer (c, location_completer);
16533cf7f2e2dSJohn Marino 
16534cf7f2e2dSJohn Marino   c = add_com ("strace", class_breakpoint, strace_command, _("\
16535cf7f2e2dSJohn Marino Set a static tracepoint at specified line, function or marker.\n\
16536cf7f2e2dSJohn Marino \n\
16537cf7f2e2dSJohn Marino strace [LOCATION] [if CONDITION]\n\
16538cf7f2e2dSJohn Marino LOCATION may be a line number, function name, \"*\" and an address,\n\
16539cf7f2e2dSJohn Marino or -m MARKER_ID.\n\
16540cf7f2e2dSJohn Marino If a line number is specified, probe the marker at start of code\n\
16541cf7f2e2dSJohn Marino for that line.  If a function is specified, probe the marker at start\n\
16542cf7f2e2dSJohn Marino of code for that function.  If an address is specified, probe the marker\n\
16543cf7f2e2dSJohn Marino at that exact address.  If a marker id is specified, probe the marker\n\
16544cf7f2e2dSJohn Marino with that name.  With no LOCATION, uses current execution address of\n\
16545cf7f2e2dSJohn Marino the selected stack frame.\n\
16546cf7f2e2dSJohn Marino Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16547cf7f2e2dSJohn Marino This collects arbitrary user data passed in the probe point call to the\n\
16548cf7f2e2dSJohn Marino tracing library.  You can inspect it when analyzing the trace buffer,\n\
16549cf7f2e2dSJohn Marino by printing the $_sdata variable like any other convenience variable.\n\
16550cf7f2e2dSJohn Marino \n\
16551cf7f2e2dSJohn Marino CONDITION is a boolean expression.\n\
16552cf7f2e2dSJohn Marino \n\
16553cf7f2e2dSJohn Marino Multiple tracepoints at one place are permitted, and useful if their\n\
16554cf7f2e2dSJohn Marino conditions are different.\n\
16555cf7f2e2dSJohn Marino \n\
16556cf7f2e2dSJohn Marino Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16557cf7f2e2dSJohn Marino Do \"help tracepoints\" for info on other tracepoint commands."));
16558cf7f2e2dSJohn Marino   set_cmd_completer (c, location_completer);
16559cf7f2e2dSJohn Marino 
165605796c8dcSSimon Schubert   add_info ("tracepoints", tracepoints_info, _("\
16561c50c785cSJohn Marino Status of specified tracepoints (all tracepoints if no argument).\n\
165625796c8dcSSimon Schubert Convenience variable \"$tpnum\" contains the number of the\n\
165635796c8dcSSimon Schubert last tracepoint set."));
165645796c8dcSSimon Schubert 
165655796c8dcSSimon Schubert   add_info_alias ("tp", "tracepoints", 1);
165665796c8dcSSimon Schubert 
165675796c8dcSSimon Schubert   add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
165685796c8dcSSimon Schubert Delete specified tracepoints.\n\
165695796c8dcSSimon Schubert Arguments are tracepoint numbers, separated by spaces.\n\
165705796c8dcSSimon Schubert No argument means delete all tracepoints."),
165715796c8dcSSimon Schubert 	   &deletelist);
16572*ef5ccd6cSJohn Marino   add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
165735796c8dcSSimon Schubert 
165745796c8dcSSimon Schubert   c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
165755796c8dcSSimon Schubert Disable specified tracepoints.\n\
165765796c8dcSSimon Schubert Arguments are tracepoint numbers, separated by spaces.\n\
165775796c8dcSSimon Schubert No argument means disable all tracepoints."),
165785796c8dcSSimon Schubert 	   &disablelist);
165795796c8dcSSimon Schubert   deprecate_cmd (c, "disable");
165805796c8dcSSimon Schubert 
165815796c8dcSSimon Schubert   c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
165825796c8dcSSimon Schubert Enable specified tracepoints.\n\
165835796c8dcSSimon Schubert Arguments are tracepoint numbers, separated by spaces.\n\
165845796c8dcSSimon Schubert No argument means enable all tracepoints."),
165855796c8dcSSimon Schubert 	   &enablelist);
165865796c8dcSSimon Schubert   deprecate_cmd (c, "enable");
165875796c8dcSSimon Schubert 
165885796c8dcSSimon Schubert   add_com ("passcount", class_trace, trace_pass_command, _("\
165895796c8dcSSimon Schubert Set the passcount for a tracepoint.\n\
165905796c8dcSSimon Schubert The trace will end when the tracepoint has been passed 'count' times.\n\
165915796c8dcSSimon Schubert Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
165925796c8dcSSimon Schubert if TPNUM is omitted, passcount refers to the last tracepoint defined."));
165935796c8dcSSimon Schubert 
16594cf7f2e2dSJohn Marino   add_prefix_cmd ("save", class_breakpoint, save_command,
16595cf7f2e2dSJohn Marino 		  _("Save breakpoint definitions as a script."),
16596cf7f2e2dSJohn Marino 		  &save_cmdlist, "save ",
16597cf7f2e2dSJohn Marino 		  0/*allow-unknown*/, &cmdlist);
16598cf7f2e2dSJohn Marino 
16599cf7f2e2dSJohn Marino   c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
16600cf7f2e2dSJohn Marino Save current breakpoint definitions as a script.\n\
16601cf7f2e2dSJohn Marino This includes all types of breakpoints (breakpoints, watchpoints,\n\
16602cf7f2e2dSJohn Marino catchpoints, tracepoints).  Use the 'source' command in another debug\n\
16603cf7f2e2dSJohn Marino session to restore them."),
16604cf7f2e2dSJohn Marino 	       &save_cmdlist);
166055796c8dcSSimon Schubert   set_cmd_completer (c, filename_completer);
166065796c8dcSSimon Schubert 
16607cf7f2e2dSJohn Marino   c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
16608cf7f2e2dSJohn Marino Save current tracepoint definitions as a script.\n\
16609cf7f2e2dSJohn Marino Use the 'source' command in another debug session to restore them."),
16610cf7f2e2dSJohn Marino 	       &save_cmdlist);
16611cf7f2e2dSJohn Marino   set_cmd_completer (c, filename_completer);
16612cf7f2e2dSJohn Marino 
16613cf7f2e2dSJohn Marino   c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
16614cf7f2e2dSJohn Marino   deprecate_cmd (c, "save tracepoints");
16615cf7f2e2dSJohn Marino 
166165796c8dcSSimon Schubert   add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
166175796c8dcSSimon Schubert Breakpoint specific settings\n\
166185796c8dcSSimon Schubert Configure various breakpoint-specific variables such as\n\
166195796c8dcSSimon Schubert pending breakpoint behavior"),
166205796c8dcSSimon Schubert 		  &breakpoint_set_cmdlist, "set breakpoint ",
166215796c8dcSSimon Schubert 		  0/*allow-unknown*/, &setlist);
166225796c8dcSSimon Schubert   add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
166235796c8dcSSimon Schubert Breakpoint specific settings\n\
166245796c8dcSSimon Schubert Configure various breakpoint-specific variables such as\n\
166255796c8dcSSimon Schubert pending breakpoint behavior"),
166265796c8dcSSimon Schubert 		  &breakpoint_show_cmdlist, "show breakpoint ",
166275796c8dcSSimon Schubert 		  0/*allow-unknown*/, &showlist);
166285796c8dcSSimon Schubert 
166295796c8dcSSimon Schubert   add_setshow_auto_boolean_cmd ("pending", no_class,
166305796c8dcSSimon Schubert 				&pending_break_support, _("\
166315796c8dcSSimon Schubert Set debugger's behavior regarding pending breakpoints."), _("\
166325796c8dcSSimon Schubert Show debugger's behavior regarding pending breakpoints."), _("\
166335796c8dcSSimon Schubert If on, an unrecognized breakpoint location will cause gdb to create a\n\
166345796c8dcSSimon Schubert pending breakpoint.  If off, an unrecognized breakpoint location results in\n\
166355796c8dcSSimon Schubert an error.  If auto, an unrecognized breakpoint location results in a\n\
166365796c8dcSSimon Schubert user-query to see if a pending breakpoint should be created."),
166375796c8dcSSimon Schubert 				NULL,
166385796c8dcSSimon Schubert 				show_pending_break_support,
166395796c8dcSSimon Schubert 				&breakpoint_set_cmdlist,
166405796c8dcSSimon Schubert 				&breakpoint_show_cmdlist);
166415796c8dcSSimon Schubert 
166425796c8dcSSimon Schubert   pending_break_support = AUTO_BOOLEAN_AUTO;
166435796c8dcSSimon Schubert 
166445796c8dcSSimon Schubert   add_setshow_boolean_cmd ("auto-hw", no_class,
166455796c8dcSSimon Schubert 			   &automatic_hardware_breakpoints, _("\
166465796c8dcSSimon Schubert Set automatic usage of hardware breakpoints."), _("\
166475796c8dcSSimon Schubert Show automatic usage of hardware breakpoints."), _("\
166485796c8dcSSimon Schubert If set, the debugger will automatically use hardware breakpoints for\n\
166495796c8dcSSimon Schubert breakpoints set with \"break\" but falling in read-only memory.  If not set,\n\
166505796c8dcSSimon Schubert a warning will be emitted for such breakpoints."),
166515796c8dcSSimon Schubert 			   NULL,
166525796c8dcSSimon Schubert 			   show_automatic_hardware_breakpoints,
166535796c8dcSSimon Schubert 			   &breakpoint_set_cmdlist,
166545796c8dcSSimon Schubert 			   &breakpoint_show_cmdlist);
166555796c8dcSSimon Schubert 
16656*ef5ccd6cSJohn Marino   add_setshow_auto_boolean_cmd ("always-inserted", class_support,
16657*ef5ccd6cSJohn Marino 				&always_inserted_mode, _("\
166585796c8dcSSimon Schubert Set mode for inserting breakpoints."), _("\
166595796c8dcSSimon Schubert Show mode for inserting breakpoints."), _("\
166605796c8dcSSimon Schubert When this mode is off, breakpoints are inserted in inferior when it is\n\
166615796c8dcSSimon Schubert resumed, and removed when execution stops.  When this mode is on,\n\
166625796c8dcSSimon Schubert breakpoints are inserted immediately and removed only when the user\n\
166635796c8dcSSimon Schubert deletes the breakpoint.  When this mode is auto (which is the default),\n\
166645796c8dcSSimon Schubert the behaviour depends on the non-stop setting (see help set non-stop).\n\
166655796c8dcSSimon Schubert In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
166665796c8dcSSimon Schubert behaves as if always-inserted mode is on; if gdb is controlling the\n\
166675796c8dcSSimon Schubert inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
166685796c8dcSSimon Schubert 				NULL,
166695796c8dcSSimon Schubert 				&show_always_inserted_mode,
166705796c8dcSSimon Schubert 				&breakpoint_set_cmdlist,
166715796c8dcSSimon Schubert 				&breakpoint_show_cmdlist);
166725796c8dcSSimon Schubert 
16673*ef5ccd6cSJohn Marino   add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16674*ef5ccd6cSJohn Marino 			condition_evaluation_enums,
16675*ef5ccd6cSJohn Marino 			&condition_evaluation_mode_1, _("\
16676*ef5ccd6cSJohn Marino Set mode of breakpoint condition evaluation."), _("\
16677*ef5ccd6cSJohn Marino Show mode of breakpoint condition evaluation."), _("\
16678*ef5ccd6cSJohn Marino When this is set to \"host\", breakpoint conditions will be\n\
16679*ef5ccd6cSJohn Marino evaluated on the host's side by GDB.  When it is set to \"target\",\n\
16680*ef5ccd6cSJohn Marino breakpoint conditions will be downloaded to the target (if the target\n\
16681*ef5ccd6cSJohn Marino supports such feature) and conditions will be evaluated on the target's side.\n\
16682*ef5ccd6cSJohn Marino If this is set to \"auto\" (default), this will be automatically set to\n\
16683*ef5ccd6cSJohn Marino \"target\" if it supports condition evaluation, otherwise it will\n\
16684*ef5ccd6cSJohn Marino be set to \"gdb\""),
16685*ef5ccd6cSJohn Marino 			   &set_condition_evaluation_mode,
16686*ef5ccd6cSJohn Marino 			   &show_condition_evaluation_mode,
16687*ef5ccd6cSJohn Marino 			   &breakpoint_set_cmdlist,
16688*ef5ccd6cSJohn Marino 			   &breakpoint_show_cmdlist);
16689*ef5ccd6cSJohn Marino 
16690c50c785cSJohn Marino   add_com ("break-range", class_breakpoint, break_range_command, _("\
16691c50c785cSJohn Marino Set a breakpoint for an address range.\n\
16692c50c785cSJohn Marino break-range START-LOCATION, END-LOCATION\n\
16693c50c785cSJohn Marino where START-LOCATION and END-LOCATION can be one of the following:\n\
16694c50c785cSJohn Marino   LINENUM, for that line in the current file,\n\
16695c50c785cSJohn Marino   FILE:LINENUM, for that line in that file,\n\
16696c50c785cSJohn Marino   +OFFSET, for that number of lines after the current line\n\
16697c50c785cSJohn Marino            or the start of the range\n\
16698c50c785cSJohn Marino   FUNCTION, for the first line in that function,\n\
16699c50c785cSJohn Marino   FILE:FUNCTION, to distinguish among like-named static functions.\n\
16700c50c785cSJohn Marino   *ADDRESS, for the instruction at that address.\n\
16701c50c785cSJohn Marino \n\
16702c50c785cSJohn Marino The breakpoint will stop execution of the inferior whenever it executes\n\
16703c50c785cSJohn Marino an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16704c50c785cSJohn Marino range (including START-LOCATION and END-LOCATION)."));
16705c50c785cSJohn Marino 
16706*ef5ccd6cSJohn Marino   c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16707*ef5ccd6cSJohn Marino Set a dynamic printf at specified line or function.\n\
16708*ef5ccd6cSJohn Marino dprintf location,format string,arg1,arg2,...\n\
16709*ef5ccd6cSJohn Marino location may be a line number, function name, or \"*\" and an address.\n\
16710*ef5ccd6cSJohn Marino If a line number is specified, break at start of code for that line.\n\
16711*ef5ccd6cSJohn Marino If a function is specified, break at start of code for that function.\n\
16712*ef5ccd6cSJohn Marino "));
16713*ef5ccd6cSJohn Marino   set_cmd_completer (c, location_completer);
16714*ef5ccd6cSJohn Marino 
16715*ef5ccd6cSJohn Marino   add_setshow_enum_cmd ("dprintf-style", class_support,
16716*ef5ccd6cSJohn Marino 			dprintf_style_enums, &dprintf_style, _("\
16717*ef5ccd6cSJohn Marino Set the style of usage for dynamic printf."), _("\
16718*ef5ccd6cSJohn Marino Show the style of usage for dynamic printf."), _("\
16719*ef5ccd6cSJohn Marino This setting chooses how GDB will do a dynamic printf.\n\
16720*ef5ccd6cSJohn Marino If the value is \"gdb\", then the printing is done by GDB to its own\n\
16721*ef5ccd6cSJohn Marino console, as with the \"printf\" command.\n\
16722*ef5ccd6cSJohn Marino If the value is \"call\", the print is done by calling a function in your\n\
16723*ef5ccd6cSJohn Marino program; by default printf(), but you can choose a different function or\n\
16724*ef5ccd6cSJohn Marino output stream by setting dprintf-function and dprintf-channel."),
16725*ef5ccd6cSJohn Marino 			update_dprintf_commands, NULL,
16726*ef5ccd6cSJohn Marino 			&setlist, &showlist);
16727*ef5ccd6cSJohn Marino 
16728*ef5ccd6cSJohn Marino   dprintf_function = xstrdup ("printf");
16729*ef5ccd6cSJohn Marino   add_setshow_string_cmd ("dprintf-function", class_support,
16730*ef5ccd6cSJohn Marino 			  &dprintf_function, _("\
16731*ef5ccd6cSJohn Marino Set the function to use for dynamic printf"), _("\
16732*ef5ccd6cSJohn Marino Show the function to use for dynamic printf"), NULL,
16733*ef5ccd6cSJohn Marino 			  update_dprintf_commands, NULL,
16734*ef5ccd6cSJohn Marino 			  &setlist, &showlist);
16735*ef5ccd6cSJohn Marino 
16736*ef5ccd6cSJohn Marino   dprintf_channel = xstrdup ("");
16737*ef5ccd6cSJohn Marino   add_setshow_string_cmd ("dprintf-channel", class_support,
16738*ef5ccd6cSJohn Marino 			  &dprintf_channel, _("\
16739*ef5ccd6cSJohn Marino Set the channel to use for dynamic printf"), _("\
16740*ef5ccd6cSJohn Marino Show the channel to use for dynamic printf"), NULL,
16741*ef5ccd6cSJohn Marino 			  update_dprintf_commands, NULL,
16742*ef5ccd6cSJohn Marino 			  &setlist, &showlist);
16743*ef5ccd6cSJohn Marino 
16744*ef5ccd6cSJohn Marino   add_setshow_boolean_cmd ("disconnected-dprintf", no_class,
16745*ef5ccd6cSJohn Marino 			   &disconnected_dprintf, _("\
16746*ef5ccd6cSJohn Marino Set whether dprintf continues after GDB disconnects."), _("\
16747*ef5ccd6cSJohn Marino Show whether dprintf continues after GDB disconnects."), _("\
16748*ef5ccd6cSJohn Marino Use this to let dprintf commands continue to hit and produce output\n\
16749*ef5ccd6cSJohn Marino even if GDB disconnects or detaches from the target."),
16750*ef5ccd6cSJohn Marino 			   NULL,
16751*ef5ccd6cSJohn Marino 			   NULL,
16752*ef5ccd6cSJohn Marino 			   &setlist, &showlist);
16753*ef5ccd6cSJohn Marino 
16754*ef5ccd6cSJohn Marino   add_com ("agent-printf", class_vars, agent_printf_command, _("\
16755*ef5ccd6cSJohn Marino agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16756*ef5ccd6cSJohn Marino (target agent only) This is useful for formatted output in user-defined commands."));
16757*ef5ccd6cSJohn Marino 
167585796c8dcSSimon Schubert   automatic_hardware_breakpoints = 1;
167595796c8dcSSimon Schubert 
167605796c8dcSSimon Schubert   observer_attach_about_to_proceed (breakpoint_about_to_proceed);
167615796c8dcSSimon Schubert }
16762