* ada-lang.c (ada_make_symbol_completion_list): Return a VEC.
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
CommitLineData
c906108c 1/* Everything about breakpoints, for GDB.
8926118c 2
0b302171 3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
a6d9a66e 21#include "arch-utils.h"
c906108c 22#include <ctype.h>
776592bf 23#include "hashtab.h"
c906108c
SS
24#include "symtab.h"
25#include "frame.h"
26#include "breakpoint.h"
1042e4c0 27#include "tracepoint.h"
c906108c
SS
28#include "gdbtypes.h"
29#include "expression.h"
30#include "gdbcore.h"
31#include "gdbcmd.h"
32#include "value.h"
33#include "command.h"
34#include "inferior.h"
35#include "gdbthread.h"
36#include "target.h"
37#include "language.h"
38#include "gdb_string.h"
50f182aa 39#include "gdb-demangle.h"
0ba1096a 40#include "filenames.h"
c906108c
SS
41#include "annotate.h"
42#include "symfile.h"
43#include "objfiles.h"
0378c332 44#include "source.h"
c5f0f3d0 45#include "linespec.h"
c94fdfd0 46#include "completer.h"
5b7f31a4 47#include "gdb.h"
8b93c638 48#include "ui-out.h"
e1507482 49#include "cli/cli-script.h"
0225421b 50#include "gdb_assert.h"
fe898f56 51#include "block.h"
a77053c2 52#include "solib.h"
84acb35a
JJ
53#include "solist.h"
54#include "observer.h"
60250e8b 55#include "exceptions.h"
765dc015 56#include "memattr.h"
f7f9143b 57#include "ada-lang.h"
d1aa2f50 58#include "top.h"
79a45b7d 59#include "valprint.h"
4efc6507 60#include "jit.h"
a96d9b2e 61#include "xml-syscall.h"
65d79d4b 62#include "parser-defs.h"
55aa24fb
SDJ
63#include "gdb_regex.h"
64#include "probe.h"
e9cafbcc 65#include "cli/cli-utils.h"
be34f849 66#include "continuations.h"
1bfeeb0f
JL
67#include "stack.h"
68#include "skip.h"
edcc5120 69#include "gdb_regex.h"
b775012e 70#include "ax-gdb.h"
c906108c 71
1042e4c0
SS
72/* readline include files */
73#include "readline/readline.h"
74#include "readline/history.h"
75
76/* readline defines this. */
77#undef savestring
78
034dad6f 79#include "mi/mi-common.h"
7371cf6d 80#include "python/python.h"
104c1213 81
4a64f543 82/* Prototypes for local functions. */
c906108c 83
a14ed312 84static void enable_delete_command (char *, int);
c906108c 85
a14ed312 86static void enable_once_command (char *, int);
c906108c 87
816338b5
SS
88static void enable_count_command (char *, int);
89
a14ed312 90static void disable_command (char *, int);
c906108c 91
a14ed312 92static void enable_command (char *, int);
c906108c 93
95a42b64
TT
94static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
95 void *),
96 void *);
c906108c 97
a14ed312 98static void ignore_command (char *, int);
c906108c 99
4efb68b1 100static int breakpoint_re_set_one (void *);
c906108c 101
348d480f
PA
102static void breakpoint_re_set_default (struct breakpoint *);
103
983af33b
SDJ
104static void create_sals_from_address_default (char **,
105 struct linespec_result *,
106 enum bptype, char *,
107 char **);
108
109static void create_breakpoints_sal_default (struct gdbarch *,
110 struct linespec_result *,
111 struct linespec_sals *,
e7e0cddf 112 char *, char *, enum bptype,
983af33b
SDJ
113 enum bpdisp, int, int,
114 int,
115 const struct breakpoint_ops *,
44f238bb 116 int, int, int, unsigned);
983af33b
SDJ
117
118static void decode_linespec_default (struct breakpoint *, char **,
119 struct symtabs_and_lines *);
120
a14ed312 121static void clear_command (char *, int);
c906108c 122
a14ed312 123static void catch_command (char *, int);
c906108c 124
a9634178 125static int can_use_hardware_watchpoint (struct value *);
c906108c 126
98deb0da 127static void break_command_1 (char *, int, int);
c906108c 128
a14ed312 129static void mention (struct breakpoint *);
c906108c 130
348d480f
PA
131static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
132 enum bptype,
c0a91b2b 133 const struct breakpoint_ops *);
3742cc8b
YQ
134static struct bp_location *add_location_to_breakpoint (struct breakpoint *,
135 const struct symtab_and_line *);
136
4a64f543
MS
137/* This function is used in gdbtk sources and thus can not be made
138 static. */
63c252f8 139struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
348d480f 140 struct symtab_and_line,
c0a91b2b
TT
141 enum bptype,
142 const struct breakpoint_ops *);
c906108c 143
06edf0c0
PA
144static struct breakpoint *
145 momentary_breakpoint_from_master (struct breakpoint *orig,
146 enum bptype type,
c0a91b2b 147 const struct breakpoint_ops *ops);
06edf0c0 148
76897487
KB
149static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
150
a6d9a66e
UW
151static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
152 CORE_ADDR bpaddr,
88f7da05 153 enum bptype bptype);
76897487 154
6c95b8df
PA
155static void describe_other_breakpoints (struct gdbarch *,
156 struct program_space *, CORE_ADDR,
5af949e3 157 struct obj_section *, int);
c906108c 158
6c95b8df
PA
159static int breakpoint_address_match (struct address_space *aspace1,
160 CORE_ADDR addr1,
161 struct address_space *aspace2,
162 CORE_ADDR addr2);
163
85d721b8
PA
164static int watchpoint_locations_match (struct bp_location *loc1,
165 struct bp_location *loc2);
166
f1310107
TJB
167static int breakpoint_location_address_match (struct bp_location *bl,
168 struct address_space *aspace,
169 CORE_ADDR addr);
170
a14ed312 171static void breakpoints_info (char *, int);
c906108c 172
d77f58be
SS
173static void watchpoints_info (char *, int);
174
e5a67952
MS
175static int breakpoint_1 (char *, int,
176 int (*) (const struct breakpoint *));
c906108c 177
4efb68b1 178static int breakpoint_cond_eval (void *);
c906108c 179
4efb68b1 180static void cleanup_executing_breakpoints (void *);
c906108c 181
a14ed312 182static void commands_command (char *, int);
c906108c 183
a14ed312 184static void condition_command (char *, int);
c906108c 185
c5aa993b
JM
186typedef enum
187 {
188 mark_inserted,
189 mark_uninserted
190 }
191insertion_state_t;
c906108c 192
0bde7532 193static int remove_breakpoint (struct bp_location *, insertion_state_t);
6c95b8df 194static int remove_breakpoint_1 (struct bp_location *, insertion_state_t);
c906108c 195
e514a9d6 196static enum print_stop_action print_bp_stop_message (bpstat bs);
c906108c 197
4efb68b1 198static int watchpoint_check (void *);
c906108c 199
a14ed312 200static void maintenance_info_breakpoints (char *, int);
c906108c 201
a14ed312 202static int hw_breakpoint_used_count (void);
c906108c 203
a1398e0c
PA
204static int hw_watchpoint_use_count (struct breakpoint *);
205
206static int hw_watchpoint_used_count_others (struct breakpoint *except,
207 enum bptype type,
208 int *other_type_used);
c906108c 209
a14ed312 210static void hbreak_command (char *, int);
c906108c 211
a14ed312 212static void thbreak_command (char *, int);
c906108c 213
816338b5
SS
214static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
215 int count);
c906108c 216
a14ed312 217static void stop_command (char *arg, int from_tty);
7a292a7a 218
a14ed312 219static void stopin_command (char *arg, int from_tty);
7a292a7a 220
a14ed312 221static void stopat_command (char *arg, int from_tty);
7a292a7a 222
a14ed312 223static char *ep_parse_optional_if_clause (char **arg);
7a292a7a 224
d85310f7
MS
225static void catch_exception_command_1 (enum exception_event_kind ex_event,
226 char *arg, int tempflag, int from_tty);
7a292a7a 227
a14ed312 228static void tcatch_command (char *arg, int from_tty);
7a292a7a 229
d03285ec
UW
230static void detach_single_step_breakpoints (void);
231
6c95b8df
PA
232static int single_step_breakpoint_inserted_here_p (struct address_space *,
233 CORE_ADDR pc);
1aafd4da 234
fe3f5fa8 235static void free_bp_location (struct bp_location *loc);
f431efe5
PA
236static void incref_bp_location (struct bp_location *loc);
237static void decref_bp_location (struct bp_location **loc);
fe3f5fa8 238
39d61571 239static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
a5606eee 240
b60e7edf 241static void update_global_location_list (int);
a5606eee 242
b60e7edf 243static void update_global_location_list_nothrow (int);
74960c60 244
d77f58be 245static int is_hardware_watchpoint (const struct breakpoint *bpt);
74960c60
VP
246
247static void insert_breakpoint_locations (void);
a5606eee 248
a96d9b2e
SDJ
249static int syscall_catchpoint_p (struct breakpoint *b);
250
1042e4c0
SS
251static void tracepoints_info (char *, int);
252
253static void delete_trace_command (char *, int);
254
255static void enable_trace_command (char *, int);
256
257static void disable_trace_command (char *, int);
258
259static void trace_pass_command (char *, int);
260
9c06b0b4
TJB
261static int is_masked_watchpoint (const struct breakpoint *b);
262
b775012e
LM
263static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
264
983af33b
SDJ
265/* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
266 otherwise. */
267
268static int strace_marker_p (struct breakpoint *b);
0fb4aa4b 269
edcc5120
TT
270static void init_catchpoint (struct breakpoint *b,
271 struct gdbarch *gdbarch, int tempflag,
272 char *cond_string,
273 const struct breakpoint_ops *ops);
274
2060206e
PA
275/* The abstract base class all breakpoint_ops structures inherit
276 from. */
277static struct breakpoint_ops base_breakpoint_ops;
278
279/* The breakpoint_ops structure to be inherited by all breakpoint_ops
280 that are implemented on top of software or hardware breakpoints
281 (user breakpoints, internal and momentary breakpoints, etc.). */
282static struct breakpoint_ops bkpt_base_breakpoint_ops;
283
284/* Internal breakpoints class type. */
06edf0c0 285static struct breakpoint_ops internal_breakpoint_ops;
2060206e
PA
286
287/* Momentary breakpoints class type. */
06edf0c0
PA
288static struct breakpoint_ops momentary_breakpoint_ops;
289
2060206e
PA
290/* The breakpoint_ops structure to be used in regular user created
291 breakpoints. */
292struct breakpoint_ops bkpt_breakpoint_ops;
293
55aa24fb
SDJ
294/* Breakpoints set on probes. */
295static struct breakpoint_ops bkpt_probe_breakpoint_ops;
296
e7e0cddf
SS
297/* Dynamic printf class type. */
298static struct breakpoint_ops dprintf_breakpoint_ops;
299
5cea2a26
PA
300/* A reference-counted struct command_line. This lets multiple
301 breakpoints share a single command list. */
302struct counted_command_line
303{
304 /* The reference count. */
305 int refc;
306
307 /* The command list. */
308 struct command_line *commands;
309};
310
311struct command_line *
312breakpoint_commands (struct breakpoint *b)
313{
314 return b->commands ? b->commands->commands : NULL;
315}
3daf8fe5 316
f3b1572e
PA
317/* Flag indicating that a command has proceeded the inferior past the
318 current breakpoint. */
319
320static int breakpoint_proceeded;
321
956a9fb9 322const char *
2cec12e5
AR
323bpdisp_text (enum bpdisp disp)
324{
4a64f543
MS
325 /* NOTE: the following values are a part of MI protocol and
326 represent values of 'disp' field returned when inferior stops at
327 a breakpoint. */
bc043ef3 328 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"};
cc59ec59 329
2cec12e5
AR
330 return bpdisps[(int) disp];
331}
c906108c 332
4a64f543 333/* Prototypes for exported functions. */
c906108c 334/* If FALSE, gdb will not use hardware support for watchpoints, even
4a64f543 335 if such is available. */
c906108c
SS
336static int can_use_hw_watchpoints;
337
920d2a44
AC
338static void
339show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
340 struct cmd_list_element *c,
341 const char *value)
342{
3e43a32a
MS
343 fprintf_filtered (file,
344 _("Debugger's willingness to use "
345 "watchpoint hardware is %s.\n"),
920d2a44
AC
346 value);
347}
348
fa8d40ab
JJ
349/* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
350 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
4a64f543 351 for unrecognized breakpoint locations.
fa8d40ab
JJ
352 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
353static enum auto_boolean pending_break_support;
920d2a44
AC
354static void
355show_pending_break_support (struct ui_file *file, int from_tty,
356 struct cmd_list_element *c,
357 const char *value)
358{
3e43a32a
MS
359 fprintf_filtered (file,
360 _("Debugger's behavior regarding "
361 "pending breakpoints is %s.\n"),
920d2a44
AC
362 value);
363}
fa8d40ab 364
765dc015 365/* If 1, gdb will automatically use hardware breakpoints for breakpoints
4a64f543 366 set with "break" but falling in read-only memory.
765dc015
VP
367 If 0, gdb will warn about such breakpoints, but won't automatically
368 use hardware breakpoints. */
369static int automatic_hardware_breakpoints;
370static void
371show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
372 struct cmd_list_element *c,
373 const char *value)
374{
3e43a32a
MS
375 fprintf_filtered (file,
376 _("Automatic usage of hardware breakpoints is %s.\n"),
765dc015
VP
377 value);
378}
379
33e5cbd6
PA
380/* If on, gdb will keep breakpoints inserted even as inferior is
381 stopped, and immediately insert any new breakpoints. If off, gdb
382 will insert breakpoints into inferior only when resuming it, and
383 will remove breakpoints upon stop. If auto, GDB will behave as ON
384 if in non-stop mode, and as OFF if all-stop mode.*/
385
386static const char always_inserted_auto[] = "auto";
387static const char always_inserted_on[] = "on";
388static const char always_inserted_off[] = "off";
40478521 389static const char *const always_inserted_enums[] = {
33e5cbd6
PA
390 always_inserted_auto,
391 always_inserted_off,
392 always_inserted_on,
393 NULL
394};
395static const char *always_inserted_mode = always_inserted_auto;
396static void
74960c60 397show_always_inserted_mode (struct ui_file *file, int from_tty,
33e5cbd6 398 struct cmd_list_element *c, const char *value)
74960c60 399{
33e5cbd6 400 if (always_inserted_mode == always_inserted_auto)
3e43a32a
MS
401 fprintf_filtered (file,
402 _("Always inserted breakpoint "
403 "mode is %s (currently %s).\n"),
33e5cbd6
PA
404 value,
405 breakpoints_always_inserted_mode () ? "on" : "off");
406 else
3e43a32a
MS
407 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"),
408 value);
74960c60
VP
409}
410
33e5cbd6
PA
411int
412breakpoints_always_inserted_mode (void)
413{
20388dd6
YQ
414 return (always_inserted_mode == always_inserted_on
415 || (always_inserted_mode == always_inserted_auto && non_stop));
33e5cbd6 416}
765dc015 417
b775012e
LM
418static const char condition_evaluation_both[] = "host or target";
419
420/* Modes for breakpoint condition evaluation. */
421static const char condition_evaluation_auto[] = "auto";
422static const char condition_evaluation_host[] = "host";
423static const char condition_evaluation_target[] = "target";
424static const char *const condition_evaluation_enums[] = {
425 condition_evaluation_auto,
426 condition_evaluation_host,
427 condition_evaluation_target,
428 NULL
429};
430
431/* Global that holds the current mode for breakpoint condition evaluation. */
432static const char *condition_evaluation_mode_1 = condition_evaluation_auto;
433
434/* Global that we use to display information to the user (gets its value from
435 condition_evaluation_mode_1. */
436static const char *condition_evaluation_mode = condition_evaluation_auto;
437
438/* Translate a condition evaluation mode MODE into either "host"
439 or "target". This is used mostly to translate from "auto" to the
440 real setting that is being used. It returns the translated
441 evaluation mode. */
442
443static const char *
444translate_condition_evaluation_mode (const char *mode)
445{
446 if (mode == condition_evaluation_auto)
447 {
448 if (target_supports_evaluation_of_breakpoint_conditions ())
449 return condition_evaluation_target;
450 else
451 return condition_evaluation_host;
452 }
453 else
454 return mode;
455}
456
457/* Discovers what condition_evaluation_auto translates to. */
458
459static const char *
460breakpoint_condition_evaluation_mode (void)
461{
462 return translate_condition_evaluation_mode (condition_evaluation_mode);
463}
464
465/* Return true if GDB should evaluate breakpoint conditions or false
466 otherwise. */
467
468static int
469gdb_evaluates_breakpoint_condition_p (void)
470{
471 const char *mode = breakpoint_condition_evaluation_mode ();
472
473 return (mode == condition_evaluation_host);
474}
475
a14ed312 476void _initialize_breakpoint (void);
c906108c 477
c906108c
SS
478/* Are we executing breakpoint commands? */
479static int executing_breakpoint_commands;
480
c02f5703
MS
481/* Are overlay event breakpoints enabled? */
482static int overlay_events_enabled;
483
e09342b5
TJB
484/* See description in breakpoint.h. */
485int target_exact_watchpoints = 0;
486
c906108c 487/* Walk the following statement or block through all breakpoints.
e5dd4106 488 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
4a64f543 489 current breakpoint. */
c906108c 490
5c44784c 491#define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
c906108c 492
5c44784c
JM
493#define ALL_BREAKPOINTS_SAFE(B,TMP) \
494 for (B = breakpoint_chain; \
495 B ? (TMP=B->next, 1): 0; \
496 B = TMP)
c906108c 497
4a64f543
MS
498/* Similar iterator for the low-level breakpoints. SAFE variant is
499 not provided so update_global_location_list must not be called
500 while executing the block of ALL_BP_LOCATIONS. */
7cc221ef 501
876fa593
JK
502#define ALL_BP_LOCATIONS(B,BP_TMP) \
503 for (BP_TMP = bp_location; \
504 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
505 BP_TMP++)
7cc221ef 506
b775012e
LM
507/* Iterates through locations with address ADDRESS for the currently selected
508 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
509 to where the loop should start from.
510 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
511 appropriate location to start with. */
512
513#define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
514 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
515 BP_LOCP_TMP = BP_LOCP_START; \
516 BP_LOCP_START \
517 && (BP_LOCP_TMP < bp_location + bp_location_count \
518 && (*BP_LOCP_TMP)->address == ADDRESS); \
519 BP_LOCP_TMP++)
520
1042e4c0
SS
521/* Iterator for tracepoints only. */
522
523#define ALL_TRACEPOINTS(B) \
524 for (B = breakpoint_chain; B; B = B->next) \
d77f58be 525 if (is_tracepoint (B))
1042e4c0 526
7cc221ef 527/* Chains of all breakpoints defined. */
c906108c
SS
528
529struct breakpoint *breakpoint_chain;
530
876fa593
JK
531/* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
532
533static struct bp_location **bp_location;
534
535/* Number of elements of BP_LOCATION. */
536
537static unsigned bp_location_count;
538
4a64f543
MS
539/* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
540 ADDRESS for the current elements of BP_LOCATION which get a valid
541 result from bp_location_has_shadow. You can use it for roughly
542 limiting the subrange of BP_LOCATION to scan for shadow bytes for
543 an address you need to read. */
876fa593
JK
544
545static CORE_ADDR bp_location_placed_address_before_address_max;
546
4a64f543
MS
547/* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
548 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
549 BP_LOCATION which get a valid result from bp_location_has_shadow.
550 You can use it for roughly limiting the subrange of BP_LOCATION to
551 scan for shadow bytes for an address you need to read. */
876fa593
JK
552
553static CORE_ADDR bp_location_shadow_len_after_address_max;
7cc221ef 554
4a64f543
MS
555/* The locations that no longer correspond to any breakpoint, unlinked
556 from bp_location array, but for which a hit may still be reported
557 by a target. */
20874c92
VP
558VEC(bp_location_p) *moribund_locations = NULL;
559
c906108c
SS
560/* Number of last breakpoint made. */
561
95a42b64
TT
562static int breakpoint_count;
563
86b17b60
PA
564/* The value of `breakpoint_count' before the last command that
565 created breakpoints. If the last (break-like) command created more
566 than one breakpoint, then the difference between BREAKPOINT_COUNT
567 and PREV_BREAKPOINT_COUNT is more than one. */
568static int prev_breakpoint_count;
c906108c 569
1042e4c0
SS
570/* Number of last tracepoint made. */
571
95a42b64 572static int tracepoint_count;
1042e4c0 573
6149aea9
PA
574static struct cmd_list_element *breakpoint_set_cmdlist;
575static struct cmd_list_element *breakpoint_show_cmdlist;
9291a0cd 576struct cmd_list_element *save_cmdlist;
6149aea9 577
468d015d
JJ
578/* Return whether a breakpoint is an active enabled breakpoint. */
579static int
580breakpoint_enabled (struct breakpoint *b)
581{
0d381245 582 return (b->enable_state == bp_enabled);
468d015d
JJ
583}
584
c906108c
SS
585/* Set breakpoint count to NUM. */
586
95a42b64 587static void
fba45db2 588set_breakpoint_count (int num)
c906108c 589{
86b17b60 590 prev_breakpoint_count = breakpoint_count;
c906108c 591 breakpoint_count = num;
4fa62494 592 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
c906108c
SS
593}
594
86b17b60
PA
595/* Used by `start_rbreak_breakpoints' below, to record the current
596 breakpoint count before "rbreak" creates any breakpoint. */
597static int rbreak_start_breakpoint_count;
598
95a42b64
TT
599/* Called at the start an "rbreak" command to record the first
600 breakpoint made. */
86b17b60 601
95a42b64
TT
602void
603start_rbreak_breakpoints (void)
604{
86b17b60 605 rbreak_start_breakpoint_count = breakpoint_count;
95a42b64
TT
606}
607
608/* Called at the end of an "rbreak" command to record the last
609 breakpoint made. */
86b17b60 610
95a42b64
TT
611void
612end_rbreak_breakpoints (void)
613{
86b17b60 614 prev_breakpoint_count = rbreak_start_breakpoint_count;
95a42b64
TT
615}
616
4a64f543 617/* Used in run_command to zero the hit count when a new run starts. */
c906108c
SS
618
619void
fba45db2 620clear_breakpoint_hit_counts (void)
c906108c
SS
621{
622 struct breakpoint *b;
623
624 ALL_BREAKPOINTS (b)
625 b->hit_count = 0;
626}
627
9add0f1b
TT
628/* Allocate a new counted_command_line with reference count of 1.
629 The new structure owns COMMANDS. */
630
631static struct counted_command_line *
632alloc_counted_command_line (struct command_line *commands)
633{
634 struct counted_command_line *result
635 = xmalloc (sizeof (struct counted_command_line));
cc59ec59 636
9add0f1b
TT
637 result->refc = 1;
638 result->commands = commands;
639 return result;
640}
641
642/* Increment reference count. This does nothing if CMD is NULL. */
643
644static void
645incref_counted_command_line (struct counted_command_line *cmd)
646{
647 if (cmd)
648 ++cmd->refc;
649}
650
651/* Decrement reference count. If the reference count reaches 0,
652 destroy the counted_command_line. Sets *CMDP to NULL. This does
653 nothing if *CMDP is NULL. */
654
655static void
656decref_counted_command_line (struct counted_command_line **cmdp)
657{
658 if (*cmdp)
659 {
660 if (--(*cmdp)->refc == 0)
661 {
662 free_command_lines (&(*cmdp)->commands);
663 xfree (*cmdp);
664 }
665 *cmdp = NULL;
666 }
667}
668
669/* A cleanup function that calls decref_counted_command_line. */
670
671static void
672do_cleanup_counted_command_line (void *arg)
673{
674 decref_counted_command_line (arg);
675}
676
677/* Create a cleanup that calls decref_counted_command_line on the
678 argument. */
679
680static struct cleanup *
681make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp)
682{
683 return make_cleanup (do_cleanup_counted_command_line, cmdp);
684}
685
c906108c 686\f
48cb2d85
VP
687/* Return the breakpoint with the specified number, or NULL
688 if the number does not refer to an existing breakpoint. */
689
690struct breakpoint *
691get_breakpoint (int num)
692{
693 struct breakpoint *b;
694
695 ALL_BREAKPOINTS (b)
696 if (b->number == num)
697 return b;
698
699 return NULL;
700}
5c44784c 701
c906108c 702\f
adc36818 703
b775012e
LM
704/* Mark locations as "conditions have changed" in case the target supports
705 evaluating conditions on its side. */
706
707static void
708mark_breakpoint_modified (struct breakpoint *b)
709{
710 struct bp_location *loc;
711
712 /* This is only meaningful if the target is
713 evaluating conditions and if the user has
714 opted for condition evaluation on the target's
715 side. */
716 if (gdb_evaluates_breakpoint_condition_p ()
717 || !target_supports_evaluation_of_breakpoint_conditions ())
718 return;
719
720 if (!is_breakpoint (b))
721 return;
722
723 for (loc = b->loc; loc; loc = loc->next)
724 loc->condition_changed = condition_modified;
725}
726
727/* Mark location as "conditions have changed" in case the target supports
728 evaluating conditions on its side. */
729
730static void
731mark_breakpoint_location_modified (struct bp_location *loc)
732{
733 /* This is only meaningful if the target is
734 evaluating conditions and if the user has
735 opted for condition evaluation on the target's
736 side. */
737 if (gdb_evaluates_breakpoint_condition_p ()
738 || !target_supports_evaluation_of_breakpoint_conditions ())
739
740 return;
741
742 if (!is_breakpoint (loc->owner))
743 return;
744
745 loc->condition_changed = condition_modified;
746}
747
748/* Sets the condition-evaluation mode using the static global
749 condition_evaluation_mode. */
750
751static void
752set_condition_evaluation_mode (char *args, int from_tty,
753 struct cmd_list_element *c)
754{
b775012e
LM
755 const char *old_mode, *new_mode;
756
757 if ((condition_evaluation_mode_1 == condition_evaluation_target)
758 && !target_supports_evaluation_of_breakpoint_conditions ())
759 {
760 condition_evaluation_mode_1 = condition_evaluation_mode;
761 warning (_("Target does not support breakpoint condition evaluation.\n"
762 "Using host evaluation mode instead."));
763 return;
764 }
765
766 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1);
767 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode);
768
abf1152a
JK
769 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
770 settings was "auto". */
771 condition_evaluation_mode = condition_evaluation_mode_1;
772
b775012e
LM
773 /* Only update the mode if the user picked a different one. */
774 if (new_mode != old_mode)
775 {
776 struct bp_location *loc, **loc_tmp;
777 /* If the user switched to a different evaluation mode, we
778 need to synch the changes with the target as follows:
779
780 "host" -> "target": Send all (valid) conditions to the target.
781 "target" -> "host": Remove all the conditions from the target.
782 */
783
b775012e
LM
784 if (new_mode == condition_evaluation_target)
785 {
786 /* Mark everything modified and synch conditions with the
787 target. */
788 ALL_BP_LOCATIONS (loc, loc_tmp)
789 mark_breakpoint_location_modified (loc);
790 }
791 else
792 {
793 /* Manually mark non-duplicate locations to synch conditions
794 with the target. We do this to remove all the conditions the
795 target knows about. */
796 ALL_BP_LOCATIONS (loc, loc_tmp)
797 if (is_breakpoint (loc->owner) && loc->inserted)
798 loc->needs_update = 1;
799 }
800
801 /* Do the update. */
802 update_global_location_list (1);
803 }
804
805 return;
806}
807
808/* Shows the current mode of breakpoint condition evaluation. Explicitly shows
809 what "auto" is translating to. */
810
811static void
812show_condition_evaluation_mode (struct ui_file *file, int from_tty,
813 struct cmd_list_element *c, const char *value)
814{
815 if (condition_evaluation_mode == condition_evaluation_auto)
816 fprintf_filtered (file,
817 _("Breakpoint condition evaluation "
818 "mode is %s (currently %s).\n"),
819 value,
820 breakpoint_condition_evaluation_mode ());
821 else
822 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"),
823 value);
824}
825
826/* A comparison function for bp_location AP and BP that is used by
827 bsearch. This comparison function only cares about addresses, unlike
828 the more general bp_location_compare function. */
829
830static int
831bp_location_compare_addrs (const void *ap, const void *bp)
832{
833 struct bp_location *a = *(void **) ap;
834 struct bp_location *b = *(void **) bp;
835
836 if (a->address == b->address)
837 return 0;
838 else
839 return ((a->address > b->address) - (a->address < b->address));
840}
841
842/* Helper function to skip all bp_locations with addresses
843 less than ADDRESS. It returns the first bp_location that
844 is greater than or equal to ADDRESS. If none is found, just
845 return NULL. */
846
847static struct bp_location **
848get_first_locp_gte_addr (CORE_ADDR address)
849{
850 struct bp_location dummy_loc;
851 struct bp_location *dummy_locp = &dummy_loc;
852 struct bp_location **locp_found = NULL;
853
854 /* Initialize the dummy location's address field. */
855 memset (&dummy_loc, 0, sizeof (struct bp_location));
856 dummy_loc.address = address;
857
858 /* Find a close match to the first location at ADDRESS. */
859 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count,
860 sizeof (struct bp_location **),
861 bp_location_compare_addrs);
862
863 /* Nothing was found, nothing left to do. */
864 if (locp_found == NULL)
865 return NULL;
866
867 /* We may have found a location that is at ADDRESS but is not the first in the
868 location's list. Go backwards (if possible) and locate the first one. */
869 while ((locp_found - 1) >= bp_location
870 && (*(locp_found - 1))->address == address)
871 locp_found--;
872
873 return locp_found;
874}
875
adc36818
PM
876void
877set_breakpoint_condition (struct breakpoint *b, char *exp,
878 int from_tty)
879{
3a5c3e22
PA
880 xfree (b->cond_string);
881 b->cond_string = NULL;
adc36818 882
3a5c3e22 883 if (is_watchpoint (b))
adc36818 884 {
3a5c3e22
PA
885 struct watchpoint *w = (struct watchpoint *) b;
886
887 xfree (w->cond_exp);
888 w->cond_exp = NULL;
889 }
890 else
891 {
892 struct bp_location *loc;
893
894 for (loc = b->loc; loc; loc = loc->next)
895 {
896 xfree (loc->cond);
897 loc->cond = NULL;
b775012e
LM
898
899 /* No need to free the condition agent expression
900 bytecode (if we have one). We will handle this
901 when we go through update_global_location_list. */
3a5c3e22 902 }
adc36818 903 }
adc36818
PM
904
905 if (*exp == 0)
906 {
907 if (from_tty)
908 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
909 }
910 else
911 {
912 char *arg = exp;
cc59ec59 913
adc36818
PM
914 /* I don't know if it matters whether this is the string the user
915 typed in or the decompiled expression. */
916 b->cond_string = xstrdup (arg);
917 b->condition_not_parsed = 0;
918
919 if (is_watchpoint (b))
920 {
3a5c3e22
PA
921 struct watchpoint *w = (struct watchpoint *) b;
922
adc36818
PM
923 innermost_block = NULL;
924 arg = exp;
3a5c3e22 925 w->cond_exp = parse_exp_1 (&arg, 0, 0);
adc36818
PM
926 if (*arg)
927 error (_("Junk at end of expression"));
3a5c3e22 928 w->cond_exp_valid_block = innermost_block;
adc36818
PM
929 }
930 else
931 {
3a5c3e22
PA
932 struct bp_location *loc;
933
adc36818
PM
934 for (loc = b->loc; loc; loc = loc->next)
935 {
936 arg = exp;
937 loc->cond =
938 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
939 if (*arg)
940 error (_("Junk at end of expression"));
941 }
942 }
943 }
b775012e
LM
944 mark_breakpoint_modified (b);
945
adc36818 946 breakpoints_changed ();
8d3788bd 947 observer_notify_breakpoint_modified (b);
adc36818
PM
948}
949
c906108c
SS
950/* condition N EXP -- set break condition of breakpoint N to EXP. */
951
952static void
fba45db2 953condition_command (char *arg, int from_tty)
c906108c 954{
52f0bd74 955 struct breakpoint *b;
c906108c 956 char *p;
52f0bd74 957 int bnum;
c906108c
SS
958
959 if (arg == 0)
e2e0b3e5 960 error_no_arg (_("breakpoint number"));
c906108c
SS
961
962 p = arg;
963 bnum = get_number (&p);
5c44784c 964 if (bnum == 0)
8a3fe4f8 965 error (_("Bad breakpoint argument: '%s'"), arg);
c906108c
SS
966
967 ALL_BREAKPOINTS (b)
968 if (b->number == bnum)
2f069f6f 969 {
7371cf6d
PM
970 /* Check if this breakpoint has a Python object assigned to
971 it, and if it has a definition of the "stop"
972 method. This method and conditions entered into GDB from
973 the CLI are mutually exclusive. */
974 if (b->py_bp_object
975 && gdbpy_breakpoint_has_py_cond (b->py_bp_object))
976 error (_("Cannot set a condition where a Python 'stop' "
977 "method has been defined in the breakpoint."));
2566ad2d 978 set_breakpoint_condition (b, p, from_tty);
b775012e
LM
979
980 if (is_breakpoint (b))
981 update_global_location_list (1);
982
2f069f6f
JB
983 return;
984 }
c906108c 985
8a3fe4f8 986 error (_("No breakpoint number %d."), bnum);
c906108c
SS
987}
988
a7bdde9e
VP
989/* Check that COMMAND do not contain commands that are suitable
990 only for tracepoints and not suitable for ordinary breakpoints.
4a64f543
MS
991 Throw if any such commands is found. */
992
a7bdde9e
VP
993static void
994check_no_tracepoint_commands (struct command_line *commands)
995{
996 struct command_line *c;
cc59ec59 997
a7bdde9e
VP
998 for (c = commands; c; c = c->next)
999 {
1000 int i;
1001
1002 if (c->control_type == while_stepping_control)
3e43a32a
MS
1003 error (_("The 'while-stepping' command can "
1004 "only be used for tracepoints"));
a7bdde9e
VP
1005
1006 for (i = 0; i < c->body_count; ++i)
1007 check_no_tracepoint_commands ((c->body_list)[i]);
1008
1009 /* Not that command parsing removes leading whitespace and comment
4a64f543 1010 lines and also empty lines. So, we only need to check for
a7bdde9e
VP
1011 command directly. */
1012 if (strstr (c->line, "collect ") == c->line)
1013 error (_("The 'collect' command can only be used for tracepoints"));
1014
51661e93
VP
1015 if (strstr (c->line, "teval ") == c->line)
1016 error (_("The 'teval' command can only be used for tracepoints"));
a7bdde9e
VP
1017 }
1018}
1019
d77f58be
SS
1020/* Encapsulate tests for different types of tracepoints. */
1021
d9b3f62e
PA
1022static int
1023is_tracepoint_type (enum bptype type)
1024{
1025 return (type == bp_tracepoint
1026 || type == bp_fast_tracepoint
1027 || type == bp_static_tracepoint);
1028}
1029
a7bdde9e 1030int
d77f58be 1031is_tracepoint (const struct breakpoint *b)
a7bdde9e 1032{
d9b3f62e 1033 return is_tracepoint_type (b->type);
a7bdde9e 1034}
d9b3f62e 1035
e5dd4106 1036/* A helper function that validates that COMMANDS are valid for a
95a42b64
TT
1037 breakpoint. This function will throw an exception if a problem is
1038 found. */
48cb2d85 1039
95a42b64
TT
1040static void
1041validate_commands_for_breakpoint (struct breakpoint *b,
1042 struct command_line *commands)
48cb2d85 1043{
d77f58be 1044 if (is_tracepoint (b))
a7bdde9e 1045 {
4a64f543
MS
1046 /* We need to verify that each top-level element of commands is
1047 valid for tracepoints, that there's at most one
1048 while-stepping element, and that while-stepping's body has
1049 valid tracing commands excluding nested while-stepping. */
a7bdde9e
VP
1050 struct command_line *c;
1051 struct command_line *while_stepping = 0;
1052 for (c = commands; c; c = c->next)
1053 {
a7bdde9e
VP
1054 if (c->control_type == while_stepping_control)
1055 {
1056 if (b->type == bp_fast_tracepoint)
3e43a32a
MS
1057 error (_("The 'while-stepping' command "
1058 "cannot be used for fast tracepoint"));
0fb4aa4b 1059 else if (b->type == bp_static_tracepoint)
3e43a32a
MS
1060 error (_("The 'while-stepping' command "
1061 "cannot be used for static tracepoint"));
a7bdde9e
VP
1062
1063 if (while_stepping)
3e43a32a
MS
1064 error (_("The 'while-stepping' command "
1065 "can be used only once"));
a7bdde9e
VP
1066 else
1067 while_stepping = c;
1068 }
1069 }
1070 if (while_stepping)
1071 {
1072 struct command_line *c2;
1073
1074 gdb_assert (while_stepping->body_count == 1);
1075 c2 = while_stepping->body_list[0];
1076 for (; c2; c2 = c2->next)
1077 {
a7bdde9e
VP
1078 if (c2->control_type == while_stepping_control)
1079 error (_("The 'while-stepping' command cannot be nested"));
1080 }
1081 }
1082 }
1083 else
1084 {
1085 check_no_tracepoint_commands (commands);
1086 }
95a42b64
TT
1087}
1088
0fb4aa4b
PA
1089/* Return a vector of all the static tracepoints set at ADDR. The
1090 caller is responsible for releasing the vector. */
1091
1092VEC(breakpoint_p) *
1093static_tracepoints_here (CORE_ADDR addr)
1094{
1095 struct breakpoint *b;
1096 VEC(breakpoint_p) *found = 0;
1097 struct bp_location *loc;
1098
1099 ALL_BREAKPOINTS (b)
1100 if (b->type == bp_static_tracepoint)
1101 {
1102 for (loc = b->loc; loc; loc = loc->next)
1103 if (loc->address == addr)
1104 VEC_safe_push(breakpoint_p, found, b);
1105 }
1106
1107 return found;
1108}
1109
95a42b64 1110/* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
4a64f543 1111 validate that only allowed commands are included. */
95a42b64
TT
1112
1113void
4a64f543
MS
1114breakpoint_set_commands (struct breakpoint *b,
1115 struct command_line *commands)
95a42b64
TT
1116{
1117 validate_commands_for_breakpoint (b, commands);
a7bdde9e 1118
9add0f1b
TT
1119 decref_counted_command_line (&b->commands);
1120 b->commands = alloc_counted_command_line (commands);
48cb2d85 1121 breakpoints_changed ();
8d3788bd 1122 observer_notify_breakpoint_modified (b);
48cb2d85
VP
1123}
1124
45a43567
TT
1125/* Set the internal `silent' flag on the breakpoint. Note that this
1126 is not the same as the "silent" that may appear in the breakpoint's
1127 commands. */
1128
1129void
1130breakpoint_set_silent (struct breakpoint *b, int silent)
1131{
1132 int old_silent = b->silent;
1133
1134 b->silent = silent;
1135 if (old_silent != silent)
8d3788bd 1136 observer_notify_breakpoint_modified (b);
45a43567
TT
1137}
1138
1139/* Set the thread for this breakpoint. If THREAD is -1, make the
1140 breakpoint work for any thread. */
1141
1142void
1143breakpoint_set_thread (struct breakpoint *b, int thread)
1144{
1145 int old_thread = b->thread;
1146
1147 b->thread = thread;
1148 if (old_thread != thread)
8d3788bd 1149 observer_notify_breakpoint_modified (b);
45a43567
TT
1150}
1151
1152/* Set the task for this breakpoint. If TASK is 0, make the
1153 breakpoint work for any task. */
1154
1155void
1156breakpoint_set_task (struct breakpoint *b, int task)
1157{
1158 int old_task = b->task;
1159
1160 b->task = task;
1161 if (old_task != task)
8d3788bd 1162 observer_notify_breakpoint_modified (b);
45a43567
TT
1163}
1164
95a42b64
TT
1165void
1166check_tracepoint_command (char *line, void *closure)
a7bdde9e
VP
1167{
1168 struct breakpoint *b = closure;
cc59ec59 1169
a7bdde9e
VP
1170 validate_actionline (&line, b);
1171}
1172
95a42b64
TT
1173/* A structure used to pass information through
1174 map_breakpoint_numbers. */
1175
1176struct commands_info
1177{
1178 /* True if the command was typed at a tty. */
1179 int from_tty;
86b17b60
PA
1180
1181 /* The breakpoint range spec. */
1182 char *arg;
1183
95a42b64
TT
1184 /* Non-NULL if the body of the commands are being read from this
1185 already-parsed command. */
1186 struct command_line *control;
86b17b60 1187
95a42b64
TT
1188 /* The command lines read from the user, or NULL if they have not
1189 yet been read. */
1190 struct counted_command_line *cmd;
1191};
1192
1193/* A callback for map_breakpoint_numbers that sets the commands for
1194 commands_command. */
1195
c906108c 1196static void
95a42b64 1197do_map_commands_command (struct breakpoint *b, void *data)
c906108c 1198{
95a42b64 1199 struct commands_info *info = data;
c906108c 1200
95a42b64
TT
1201 if (info->cmd == NULL)
1202 {
1203 struct command_line *l;
5c44784c 1204
95a42b64
TT
1205 if (info->control != NULL)
1206 l = copy_command_lines (info->control->body_list[0]);
1207 else
86b17b60
PA
1208 {
1209 struct cleanup *old_chain;
1210 char *str;
c5aa993b 1211
3e43a32a
MS
1212 str = xstrprintf (_("Type commands for breakpoint(s) "
1213 "%s, one per line."),
86b17b60
PA
1214 info->arg);
1215
1216 old_chain = make_cleanup (xfree, str);
1217
1218 l = read_command_lines (str,
1219 info->from_tty, 1,
d77f58be 1220 (is_tracepoint (b)
86b17b60
PA
1221 ? check_tracepoint_command : 0),
1222 b);
1223
1224 do_cleanups (old_chain);
1225 }
a7bdde9e 1226
95a42b64
TT
1227 info->cmd = alloc_counted_command_line (l);
1228 }
1229
1230 /* If a breakpoint was on the list more than once, we don't need to
1231 do anything. */
1232 if (b->commands != info->cmd)
1233 {
1234 validate_commands_for_breakpoint (b, info->cmd->commands);
1235 incref_counted_command_line (info->cmd);
1236 decref_counted_command_line (&b->commands);
1237 b->commands = info->cmd;
1238 breakpoints_changed ();
8d3788bd 1239 observer_notify_breakpoint_modified (b);
c5aa993b 1240 }
95a42b64
TT
1241}
1242
1243static void
4a64f543
MS
1244commands_command_1 (char *arg, int from_tty,
1245 struct command_line *control)
95a42b64
TT
1246{
1247 struct cleanup *cleanups;
1248 struct commands_info info;
1249
1250 info.from_tty = from_tty;
1251 info.control = control;
1252 info.cmd = NULL;
1253 /* If we read command lines from the user, then `info' will hold an
1254 extra reference to the commands that we must clean up. */
1255 cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
1256
1257 if (arg == NULL || !*arg)
1258 {
86b17b60 1259 if (breakpoint_count - prev_breakpoint_count > 1)
4a64f543
MS
1260 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1,
1261 breakpoint_count);
95a42b64
TT
1262 else if (breakpoint_count > 0)
1263 arg = xstrprintf ("%d", breakpoint_count);
86b17b60
PA
1264 else
1265 {
1266 /* So that we don't try to free the incoming non-NULL
1267 argument in the cleanup below. Mapping breakpoint
1268 numbers will fail in this case. */
1269 arg = NULL;
1270 }
95a42b64 1271 }
9766ced4
SS
1272 else
1273 /* The command loop has some static state, so we need to preserve
1274 our argument. */
1275 arg = xstrdup (arg);
86b17b60
PA
1276
1277 if (arg != NULL)
1278 make_cleanup (xfree, arg);
1279
1280 info.arg = arg;
95a42b64
TT
1281
1282 map_breakpoint_numbers (arg, do_map_commands_command, &info);
1283
1284 if (info.cmd == NULL)
1285 error (_("No breakpoints specified."));
1286
1287 do_cleanups (cleanups);
1288}
1289
1290static void
1291commands_command (char *arg, int from_tty)
1292{
1293 commands_command_1 (arg, from_tty, NULL);
c906108c 1294}
40c03ae8
EZ
1295
1296/* Like commands_command, but instead of reading the commands from
1297 input stream, takes them from an already parsed command structure.
1298
1299 This is used by cli-script.c to DTRT with breakpoint commands
1300 that are part of if and while bodies. */
1301enum command_control_type
1302commands_from_control_command (char *arg, struct command_line *cmd)
1303{
95a42b64
TT
1304 commands_command_1 (arg, 0, cmd);
1305 return simple_control;
40c03ae8 1306}
876fa593
JK
1307
1308/* Return non-zero if BL->TARGET_INFO contains valid information. */
1309
1310static int
1311bp_location_has_shadow (struct bp_location *bl)
1312{
1313 if (bl->loc_type != bp_loc_software_breakpoint)
1314 return 0;
1315 if (!bl->inserted)
1316 return 0;
1317 if (bl->target_info.shadow_len == 0)
e5dd4106 1318 /* BL isn't valid, or doesn't shadow memory. */
876fa593
JK
1319 return 0;
1320 return 1;
1321}
1322
8defab1a 1323/* Update BUF, which is LEN bytes read from the target address MEMADDR,
876fa593
JK
1324 by replacing any memory breakpoints with their shadowed contents.
1325
35c63cd8
JB
1326 If READBUF is not NULL, this buffer must not overlap with any of
1327 the breakpoint location's shadow_contents buffers. Otherwise,
1328 a failed assertion internal error will be raised.
1329
876fa593 1330 The range of shadowed area by each bp_location is:
35df4500
TJB
1331 bl->address - bp_location_placed_address_before_address_max
1332 up to bl->address + bp_location_shadow_len_after_address_max
876fa593
JK
1333 The range we were requested to resolve shadows for is:
1334 memaddr ... memaddr + len
1335 Thus the safe cutoff boundaries for performance optimization are
35df4500
TJB
1336 memaddr + len <= (bl->address
1337 - bp_location_placed_address_before_address_max)
876fa593 1338 and:
35df4500 1339 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
c906108c 1340
8defab1a 1341void
f0ba3972
PA
1342breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
1343 const gdb_byte *writebuf_org,
1344 ULONGEST memaddr, LONGEST len)
c906108c 1345{
4a64f543
MS
1346 /* Left boundary, right boundary and median element of our binary
1347 search. */
876fa593
JK
1348 unsigned bc_l, bc_r, bc;
1349
4a64f543
MS
1350 /* Find BC_L which is a leftmost element which may affect BUF
1351 content. It is safe to report lower value but a failure to
1352 report higher one. */
876fa593
JK
1353
1354 bc_l = 0;
1355 bc_r = bp_location_count;
1356 while (bc_l + 1 < bc_r)
1357 {
35df4500 1358 struct bp_location *bl;
876fa593
JK
1359
1360 bc = (bc_l + bc_r) / 2;
35df4500 1361 bl = bp_location[bc];
876fa593 1362
4a64f543
MS
1363 /* Check first BL->ADDRESS will not overflow due to the added
1364 constant. Then advance the left boundary only if we are sure
1365 the BC element can in no way affect the BUF content (MEMADDR
1366 to MEMADDR + LEN range).
876fa593 1367
4a64f543
MS
1368 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1369 offset so that we cannot miss a breakpoint with its shadow
1370 range tail still reaching MEMADDR. */
c5aa993b 1371
35df4500
TJB
1372 if ((bl->address + bp_location_shadow_len_after_address_max
1373 >= bl->address)
1374 && (bl->address + bp_location_shadow_len_after_address_max
1375 <= memaddr))
876fa593
JK
1376 bc_l = bc;
1377 else
1378 bc_r = bc;
1379 }
1380
128070bb
PA
1381 /* Due to the binary search above, we need to make sure we pick the
1382 first location that's at BC_L's address. E.g., if there are
1383 multiple locations at the same address, BC_L may end up pointing
1384 at a duplicate location, and miss the "master"/"inserted"
1385 location. Say, given locations L1, L2 and L3 at addresses A and
1386 B:
1387
1388 L1@A, L2@A, L3@B, ...
1389
1390 BC_L could end up pointing at location L2, while the "master"
1391 location could be L1. Since the `loc->inserted' flag is only set
1392 on "master" locations, we'd forget to restore the shadow of L1
1393 and L2. */
1394 while (bc_l > 0
1395 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address)
1396 bc_l--;
1397
876fa593
JK
1398 /* Now do full processing of the found relevant range of elements. */
1399
1400 for (bc = bc_l; bc < bp_location_count; bc++)
c5aa993b 1401 {
35df4500 1402 struct bp_location *bl = bp_location[bc];
876fa593
JK
1403 CORE_ADDR bp_addr = 0;
1404 int bp_size = 0;
1405 int bptoffset = 0;
1406
35df4500
TJB
1407 /* bp_location array has BL->OWNER always non-NULL. */
1408 if (bl->owner->type == bp_none)
8a3fe4f8 1409 warning (_("reading through apparently deleted breakpoint #%d?"),
35df4500 1410 bl->owner->number);
ffce0d52 1411
e5dd4106 1412 /* Performance optimization: any further element can no longer affect BUF
876fa593
JK
1413 content. */
1414
35df4500
TJB
1415 if (bl->address >= bp_location_placed_address_before_address_max
1416 && memaddr + len <= (bl->address
1417 - bp_location_placed_address_before_address_max))
876fa593
JK
1418 break;
1419
35df4500 1420 if (!bp_location_has_shadow (bl))
c5aa993b 1421 continue;
35df4500 1422 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0,
6c95b8df
PA
1423 current_program_space->aspace, 0))
1424 continue;
1425
c5aa993b
JM
1426 /* Addresses and length of the part of the breakpoint that
1427 we need to copy. */
35df4500
TJB
1428 bp_addr = bl->target_info.placed_address;
1429 bp_size = bl->target_info.shadow_len;
8defab1a 1430
c5aa993b
JM
1431 if (bp_addr + bp_size <= memaddr)
1432 /* The breakpoint is entirely before the chunk of memory we
1433 are reading. */
1434 continue;
8defab1a 1435
c5aa993b
JM
1436 if (bp_addr >= memaddr + len)
1437 /* The breakpoint is entirely after the chunk of memory we are
4a64f543 1438 reading. */
c5aa993b 1439 continue;
c5aa993b 1440
8defab1a
DJ
1441 /* Offset within shadow_contents. */
1442 if (bp_addr < memaddr)
1443 {
1444 /* Only copy the second part of the breakpoint. */
1445 bp_size -= memaddr - bp_addr;
1446 bptoffset = memaddr - bp_addr;
1447 bp_addr = memaddr;
1448 }
c5aa993b 1449
8defab1a
DJ
1450 if (bp_addr + bp_size > memaddr + len)
1451 {
1452 /* Only copy the first part of the breakpoint. */
1453 bp_size -= (bp_addr + bp_size) - (memaddr + len);
1454 }
c5aa993b 1455
f0ba3972
PA
1456 if (readbuf != NULL)
1457 {
35c63cd8
JB
1458 /* Verify that the readbuf buffer does not overlap with
1459 the shadow_contents buffer. */
1460 gdb_assert (bl->target_info.shadow_contents >= readbuf + len
1461 || readbuf >= (bl->target_info.shadow_contents
1462 + bl->target_info.shadow_len));
1463
f0ba3972
PA
1464 /* Update the read buffer with this inserted breakpoint's
1465 shadow. */
1466 memcpy (readbuf + bp_addr - memaddr,
1467 bl->target_info.shadow_contents + bptoffset, bp_size);
1468 }
1469 else
1470 {
1471 struct gdbarch *gdbarch = bl->gdbarch;
1472 const unsigned char *bp;
1473 CORE_ADDR placed_address = bl->target_info.placed_address;
1474 unsigned placed_size = bl->target_info.placed_size;
1475
1476 /* Update the shadow with what we want to write to memory. */
1477 memcpy (bl->target_info.shadow_contents + bptoffset,
1478 writebuf_org + bp_addr - memaddr, bp_size);
1479
1480 /* Determine appropriate breakpoint contents and size for this
1481 address. */
1482 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size);
1483
1484 /* Update the final write buffer with this inserted
1485 breakpoint's INSN. */
1486 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size);
1487 }
c5aa993b 1488 }
c906108c 1489}
c906108c 1490\f
c5aa993b 1491
b775012e
LM
1492/* Return true if BPT is either a software breakpoint or a hardware
1493 breakpoint. */
1494
1495int
1496is_breakpoint (const struct breakpoint *bpt)
1497{
1498 return (bpt->type == bp_breakpoint
e7e0cddf
SS
1499 || bpt->type == bp_hardware_breakpoint
1500 || bpt->type == bp_dprintf);
b775012e
LM
1501}
1502
60e1c644
PA
1503/* Return true if BPT is of any hardware watchpoint kind. */
1504
a5606eee 1505static int
d77f58be 1506is_hardware_watchpoint (const struct breakpoint *bpt)
a5606eee
VP
1507{
1508 return (bpt->type == bp_hardware_watchpoint
1509 || bpt->type == bp_read_watchpoint
1510 || bpt->type == bp_access_watchpoint);
1511}
7270d8f2 1512
60e1c644
PA
1513/* Return true if BPT is of any watchpoint kind, hardware or
1514 software. */
1515
3a5c3e22 1516int
d77f58be 1517is_watchpoint (const struct breakpoint *bpt)
60e1c644
PA
1518{
1519 return (is_hardware_watchpoint (bpt)
1520 || bpt->type == bp_watchpoint);
1521}
1522
3a5c3e22
PA
1523/* Returns true if the current thread and its running state are safe
1524 to evaluate or update watchpoint B. Watchpoints on local
1525 expressions need to be evaluated in the context of the thread that
1526 was current when the watchpoint was created, and, that thread needs
1527 to be stopped to be able to select the correct frame context.
1528 Watchpoints on global expressions can be evaluated on any thread,
1529 and in any state. It is presently left to the target allowing
1530 memory accesses when threads are running. */
f6bc2008
PA
1531
1532static int
3a5c3e22 1533watchpoint_in_thread_scope (struct watchpoint *b)
f6bc2008 1534{
d0d8b0c6
JK
1535 return (b->base.pspace == current_program_space
1536 && (ptid_equal (b->watchpoint_thread, null_ptid)
1537 || (ptid_equal (inferior_ptid, b->watchpoint_thread)
1538 && !is_executing (inferior_ptid))));
f6bc2008
PA
1539}
1540
d0fb5eae
JK
1541/* Set watchpoint B to disp_del_at_next_stop, even including its possible
1542 associated bp_watchpoint_scope breakpoint. */
1543
1544static void
3a5c3e22 1545watchpoint_del_at_next_stop (struct watchpoint *w)
d0fb5eae 1546{
3a5c3e22 1547 struct breakpoint *b = &w->base;
d0fb5eae
JK
1548
1549 if (b->related_breakpoint != b)
1550 {
1551 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
1552 gdb_assert (b->related_breakpoint->related_breakpoint == b);
1553 b->related_breakpoint->disposition = disp_del_at_next_stop;
1554 b->related_breakpoint->related_breakpoint = b->related_breakpoint;
1555 b->related_breakpoint = b;
1556 }
1557 b->disposition = disp_del_at_next_stop;
1558}
1559
567e1b4e
JB
1560/* Assuming that B is a watchpoint:
1561 - Reparse watchpoint expression, if REPARSE is non-zero
a5606eee 1562 - Evaluate expression and store the result in B->val
567e1b4e
JB
1563 - Evaluate the condition if there is one, and store the result
1564 in b->loc->cond.
a5606eee
VP
1565 - Update the list of values that must be watched in B->loc.
1566
4a64f543
MS
1567 If the watchpoint disposition is disp_del_at_next_stop, then do
1568 nothing. If this is local watchpoint that is out of scope, delete
1569 it.
1570
1571 Even with `set breakpoint always-inserted on' the watchpoints are
1572 removed + inserted on each stop here. Normal breakpoints must
1573 never be removed because they might be missed by a running thread
1574 when debugging in non-stop mode. On the other hand, hardware
1575 watchpoints (is_hardware_watchpoint; processed here) are specific
1576 to each LWP since they are stored in each LWP's hardware debug
1577 registers. Therefore, such LWP must be stopped first in order to
1578 be able to modify its hardware watchpoints.
1579
1580 Hardware watchpoints must be reset exactly once after being
1581 presented to the user. It cannot be done sooner, because it would
1582 reset the data used to present the watchpoint hit to the user. And
1583 it must not be done later because it could display the same single
1584 watchpoint hit during multiple GDB stops. Note that the latter is
1585 relevant only to the hardware watchpoint types bp_read_watchpoint
1586 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1587 not user-visible - its hit is suppressed if the memory content has
1588 not changed.
1589
1590 The following constraints influence the location where we can reset
1591 hardware watchpoints:
1592
1593 * target_stopped_by_watchpoint and target_stopped_data_address are
1594 called several times when GDB stops.
1595
1596 [linux]
1597 * Multiple hardware watchpoints can be hit at the same time,
1598 causing GDB to stop. GDB only presents one hardware watchpoint
1599 hit at a time as the reason for stopping, and all the other hits
1600 are presented later, one after the other, each time the user
1601 requests the execution to be resumed. Execution is not resumed
1602 for the threads still having pending hit event stored in
1603 LWP_INFO->STATUS. While the watchpoint is already removed from
1604 the inferior on the first stop the thread hit event is kept being
1605 reported from its cached value by linux_nat_stopped_data_address
1606 until the real thread resume happens after the watchpoint gets
1607 presented and thus its LWP_INFO->STATUS gets reset.
1608
1609 Therefore the hardware watchpoint hit can get safely reset on the
1610 watchpoint removal from inferior. */
a79d3c27 1611
b40ce68a 1612static void
3a5c3e22 1613update_watchpoint (struct watchpoint *b, int reparse)
7270d8f2 1614{
a5606eee 1615 int within_current_scope;
a5606eee 1616 struct frame_id saved_frame_id;
66076460 1617 int frame_saved;
a5606eee 1618
f6bc2008
PA
1619 /* If this is a local watchpoint, we only want to check if the
1620 watchpoint frame is in scope if the current thread is the thread
1621 that was used to create the watchpoint. */
1622 if (!watchpoint_in_thread_scope (b))
1623 return;
1624
3a5c3e22 1625 if (b->base.disposition == disp_del_at_next_stop)
a5606eee
VP
1626 return;
1627
66076460 1628 frame_saved = 0;
a5606eee
VP
1629
1630 /* Determine if the watchpoint is within scope. */
1631 if (b->exp_valid_block == NULL)
1632 within_current_scope = 1;
1633 else
1634 {
b5db5dfc
UW
1635 struct frame_info *fi = get_current_frame ();
1636 struct gdbarch *frame_arch = get_frame_arch (fi);
1637 CORE_ADDR frame_pc = get_frame_pc (fi);
1638
1639 /* If we're in a function epilogue, unwinding may not work
1640 properly, so do not attempt to recreate locations at this
1641 point. See similar comments in watchpoint_check. */
1642 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
1643 return;
66076460
DJ
1644
1645 /* Save the current frame's ID so we can restore it after
1646 evaluating the watchpoint expression on its own frame. */
1647 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1648 took a frame parameter, so that we didn't have to change the
1649 selected frame. */
1650 frame_saved = 1;
1651 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1652
a5606eee
VP
1653 fi = frame_find_by_id (b->watchpoint_frame);
1654 within_current_scope = (fi != NULL);
1655 if (within_current_scope)
1656 select_frame (fi);
1657 }
1658
b5db5dfc
UW
1659 /* We don't free locations. They are stored in the bp_location array
1660 and update_global_location_list will eventually delete them and
1661 remove breakpoints if needed. */
3a5c3e22 1662 b->base.loc = NULL;
b5db5dfc 1663
a5606eee
VP
1664 if (within_current_scope && reparse)
1665 {
1666 char *s;
d63d0675 1667
a5606eee
VP
1668 if (b->exp)
1669 {
1670 xfree (b->exp);
1671 b->exp = NULL;
1672 }
d63d0675 1673 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string;
a5606eee
VP
1674 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
1675 /* If the meaning of expression itself changed, the old value is
1676 no longer relevant. We don't want to report a watchpoint hit
1677 to the user when the old value and the new value may actually
1678 be completely different objects. */
1679 value_free (b->val);
fa4727a6
DJ
1680 b->val = NULL;
1681 b->val_valid = 0;
60e1c644
PA
1682
1683 /* Note that unlike with breakpoints, the watchpoint's condition
1684 expression is stored in the breakpoint object, not in the
1685 locations (re)created below. */
3a5c3e22 1686 if (b->base.cond_string != NULL)
60e1c644
PA
1687 {
1688 if (b->cond_exp != NULL)
1689 {
1690 xfree (b->cond_exp);
1691 b->cond_exp = NULL;
1692 }
1693
3a5c3e22 1694 s = b->base.cond_string;
60e1c644
PA
1695 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0);
1696 }
a5606eee 1697 }
a5606eee
VP
1698
1699 /* If we failed to parse the expression, for example because
1700 it refers to a global variable in a not-yet-loaded shared library,
1701 don't try to insert watchpoint. We don't automatically delete
1702 such watchpoint, though, since failure to parse expression
1703 is different from out-of-scope watchpoint. */
2d134ed3
PA
1704 if ( !target_has_execution)
1705 {
1706 /* Without execution, memory can't change. No use to try and
1707 set watchpoint locations. The watchpoint will be reset when
1708 the target gains execution, through breakpoint_re_set. */
1709 }
1710 else if (within_current_scope && b->exp)
a5606eee 1711 {
0cf6dd15 1712 int pc = 0;
fa4727a6 1713 struct value *val_chain, *v, *result, *next;
2d134ed3 1714 struct program_space *frame_pspace;
a5606eee 1715
0cf6dd15 1716 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain);
a5606eee 1717
a5606eee
VP
1718 /* Avoid setting b->val if it's already set. The meaning of
1719 b->val is 'the last value' user saw, and we should update
1720 it only if we reported that last value to user. As it
9c06b0b4
TJB
1721 happens, the code that reports it updates b->val directly.
1722 We don't keep track of the memory value for masked
1723 watchpoints. */
3a5c3e22 1724 if (!b->val_valid && !is_masked_watchpoint (&b->base))
fa4727a6
DJ
1725 {
1726 b->val = v;
1727 b->val_valid = 1;
1728 }
a5606eee 1729
2d134ed3
PA
1730 frame_pspace = get_frame_program_space (get_selected_frame (NULL));
1731
a5606eee 1732 /* Look at each value on the value chain. */
9fa40276 1733 for (v = val_chain; v; v = value_next (v))
a5606eee
VP
1734 {
1735 /* If it's a memory location, and GDB actually needed
1736 its contents to evaluate the expression, then we
fa4727a6
DJ
1737 must watch it. If the first value returned is
1738 still lazy, that means an error occurred reading it;
1739 watch it anyway in case it becomes readable. */
a5606eee 1740 if (VALUE_LVAL (v) == lval_memory
fa4727a6 1741 && (v == val_chain || ! value_lazy (v)))
a5606eee
VP
1742 {
1743 struct type *vtype = check_typedef (value_type (v));
7270d8f2 1744
a5606eee
VP
1745 /* We only watch structs and arrays if user asked
1746 for it explicitly, never if they just happen to
1747 appear in the middle of some value chain. */
fa4727a6 1748 if (v == result
a5606eee
VP
1749 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1750 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1751 {
1752 CORE_ADDR addr;
1753 int len, type;
1754 struct bp_location *loc, **tmp;
1755
42ae5230 1756 addr = value_address (v);
a5606eee
VP
1757 len = TYPE_LENGTH (value_type (v));
1758 type = hw_write;
3a5c3e22 1759 if (b->base.type == bp_read_watchpoint)
a5606eee 1760 type = hw_read;
3a5c3e22 1761 else if (b->base.type == bp_access_watchpoint)
a5606eee 1762 type = hw_access;
3a5c3e22
PA
1763
1764 loc = allocate_bp_location (&b->base);
1765 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next))
a5606eee
VP
1766 ;
1767 *tmp = loc;
a6d9a66e 1768 loc->gdbarch = get_type_arch (value_type (v));
6c95b8df
PA
1769
1770 loc->pspace = frame_pspace;
a5606eee
VP
1771 loc->address = addr;
1772 loc->length = len;
1773 loc->watchpoint_type = type;
1774 }
1775 }
9fa40276
TJB
1776 }
1777
1778 /* Change the type of breakpoint between hardware assisted or
1779 an ordinary watchpoint depending on the hardware support
1780 and free hardware slots. REPARSE is set when the inferior
1781 is started. */
a9634178 1782 if (reparse)
9fa40276 1783 {
e09342b5 1784 int reg_cnt;
9fa40276
TJB
1785 enum bp_loc_type loc_type;
1786 struct bp_location *bl;
a5606eee 1787
a9634178 1788 reg_cnt = can_use_hardware_watchpoint (val_chain);
e09342b5
TJB
1789
1790 if (reg_cnt)
9fa40276
TJB
1791 {
1792 int i, target_resources_ok, other_type_used;
a1398e0c 1793 enum bptype type;
9fa40276 1794
a9634178
TJB
1795 /* Use an exact watchpoint when there's only one memory region to be
1796 watched, and only one debug register is needed to watch it. */
1797 b->exact = target_exact_watchpoints && reg_cnt == 1;
1798
9fa40276 1799 /* We need to determine how many resources are already
e09342b5
TJB
1800 used for all other hardware watchpoints plus this one
1801 to see if we still have enough resources to also fit
a1398e0c
PA
1802 this watchpoint in as well. */
1803
1804 /* If this is a software watchpoint, we try to turn it
1805 to a hardware one -- count resources as if B was of
1806 hardware watchpoint type. */
1807 type = b->base.type;
1808 if (type == bp_watchpoint)
1809 type = bp_hardware_watchpoint;
1810
1811 /* This watchpoint may or may not have been placed on
1812 the list yet at this point (it won't be in the list
1813 if we're trying to create it for the first time,
1814 through watch_command), so always account for it
1815 manually. */
1816
1817 /* Count resources used by all watchpoints except B. */
1818 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used);
1819
1820 /* Add in the resources needed for B. */
1821 i += hw_watchpoint_use_count (&b->base);
1822
1823 target_resources_ok
1824 = target_can_use_hardware_watchpoint (type, i, other_type_used);
e09342b5 1825 if (target_resources_ok <= 0)
a9634178 1826 {
3a5c3e22 1827 int sw_mode = b->base.ops->works_in_software_mode (&b->base);
9c06b0b4
TJB
1828
1829 if (target_resources_ok == 0 && !sw_mode)
a9634178
TJB
1830 error (_("Target does not support this type of "
1831 "hardware watchpoint."));
9c06b0b4
TJB
1832 else if (target_resources_ok < 0 && !sw_mode)
1833 error (_("There are not enough available hardware "
1834 "resources for this watchpoint."));
a1398e0c
PA
1835
1836 /* Downgrade to software watchpoint. */
1837 b->base.type = bp_watchpoint;
1838 }
1839 else
1840 {
1841 /* If this was a software watchpoint, we've just
1842 found we have enough resources to turn it to a
1843 hardware watchpoint. Otherwise, this is a
1844 nop. */
1845 b->base.type = type;
a9634178 1846 }
9fa40276 1847 }
3a5c3e22 1848 else if (!b->base.ops->works_in_software_mode (&b->base))
a9634178
TJB
1849 error (_("Expression cannot be implemented with "
1850 "read/access watchpoint."));
9fa40276 1851 else
3a5c3e22 1852 b->base.type = bp_watchpoint;
9fa40276 1853
3a5c3e22 1854 loc_type = (b->base.type == bp_watchpoint? bp_loc_other
9fa40276 1855 : bp_loc_hardware_watchpoint);
3a5c3e22 1856 for (bl = b->base.loc; bl; bl = bl->next)
9fa40276
TJB
1857 bl->loc_type = loc_type;
1858 }
1859
1860 for (v = val_chain; v; v = next)
1861 {
a5606eee
VP
1862 next = value_next (v);
1863 if (v != b->val)
1864 value_free (v);
1865 }
1866
c7437ca6
PA
1867 /* If a software watchpoint is not watching any memory, then the
1868 above left it without any location set up. But,
1869 bpstat_stop_status requires a location to be able to report
1870 stops, so make sure there's at least a dummy one. */
3a5c3e22 1871 if (b->base.type == bp_watchpoint && b->base.loc == NULL)
c7437ca6 1872 {
3a5c3e22
PA
1873 struct breakpoint *base = &b->base;
1874 base->loc = allocate_bp_location (base);
1875 base->loc->pspace = frame_pspace;
1876 base->loc->address = -1;
1877 base->loc->length = -1;
1878 base->loc->watchpoint_type = -1;
c7437ca6 1879 }
a5606eee
VP
1880 }
1881 else if (!within_current_scope)
7270d8f2 1882 {
ac74f770
MS
1883 printf_filtered (_("\
1884Watchpoint %d deleted because the program has left the block\n\
1885in which its expression is valid.\n"),
3a5c3e22 1886 b->base.number);
d0fb5eae 1887 watchpoint_del_at_next_stop (b);
7270d8f2 1888 }
a5606eee
VP
1889
1890 /* Restore the selected frame. */
66076460
DJ
1891 if (frame_saved)
1892 select_frame (frame_find_by_id (saved_frame_id));
7270d8f2
OF
1893}
1894
a5606eee 1895
74960c60 1896/* Returns 1 iff breakpoint location should be
1e4d1764
YQ
1897 inserted in the inferior. We don't differentiate the type of BL's owner
1898 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1899 breakpoint_ops is not defined, because in insert_bp_location,
1900 tracepoint's insert_location will not be called. */
74960c60 1901static int
35df4500 1902should_be_inserted (struct bp_location *bl)
74960c60 1903{
35df4500 1904 if (bl->owner == NULL || !breakpoint_enabled (bl->owner))
74960c60
VP
1905 return 0;
1906
35df4500 1907 if (bl->owner->disposition == disp_del_at_next_stop)
74960c60
VP
1908 return 0;
1909
35df4500 1910 if (!bl->enabled || bl->shlib_disabled || bl->duplicate)
74960c60
VP
1911 return 0;
1912
f8eba3c6
TT
1913 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup)
1914 return 0;
1915
56710373
PA
1916 /* This is set for example, when we're attached to the parent of a
1917 vfork, and have detached from the child. The child is running
1918 free, and we expect it to do an exec or exit, at which point the
1919 OS makes the parent schedulable again (and the target reports
1920 that the vfork is done). Until the child is done with the shared
1921 memory region, do not insert breakpoints in the parent, otherwise
1922 the child could still trip on the parent's breakpoints. Since
1923 the parent is blocked anyway, it won't miss any breakpoint. */
35df4500 1924 if (bl->pspace->breakpoints_not_allowed)
56710373
PA
1925 return 0;
1926
74960c60
VP
1927 return 1;
1928}
1929
934709f0
PW
1930/* Same as should_be_inserted but does the check assuming
1931 that the location is not duplicated. */
1932
1933static int
1934unduplicated_should_be_inserted (struct bp_location *bl)
1935{
1936 int result;
1937 const int save_duplicate = bl->duplicate;
1938
1939 bl->duplicate = 0;
1940 result = should_be_inserted (bl);
1941 bl->duplicate = save_duplicate;
1942 return result;
1943}
1944
b775012e
LM
1945/* Parses a conditional described by an expression COND into an
1946 agent expression bytecode suitable for evaluation
1947 by the bytecode interpreter. Return NULL if there was
1948 any error during parsing. */
1949
1950static struct agent_expr *
1951parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
1952{
1953 struct agent_expr *aexpr = NULL;
1954 struct cleanup *old_chain = NULL;
1955 volatile struct gdb_exception ex;
1956
1957 if (!cond)
1958 return NULL;
1959
1960 /* We don't want to stop processing, so catch any errors
1961 that may show up. */
1962 TRY_CATCH (ex, RETURN_MASK_ERROR)
1963 {
1964 aexpr = gen_eval_for_expr (scope, cond);
1965 }
1966
1967 if (ex.reason < 0)
1968 {
1969 /* If we got here, it means the condition could not be parsed to a valid
1970 bytecode expression and thus can't be evaluated on the target's side.
1971 It's no use iterating through the conditions. */
1972 return NULL;
1973 }
1974
1975 /* We have a valid agent expression. */
1976 return aexpr;
1977}
1978
1979/* Based on location BL, create a list of breakpoint conditions to be
1980 passed on to the target. If we have duplicated locations with different
1981 conditions, we will add such conditions to the list. The idea is that the
1982 target will evaluate the list of conditions and will only notify GDB when
1983 one of them is true. */
1984
1985static void
1986build_target_condition_list (struct bp_location *bl)
1987{
1988 struct bp_location **locp = NULL, **loc2p;
1989 int null_condition_or_parse_error = 0;
1990 int modified = bl->needs_update;
1991 struct bp_location *loc;
1992
1993 /* This is only meaningful if the target is
1994 evaluating conditions and if the user has
1995 opted for condition evaluation on the target's
1996 side. */
1997 if (gdb_evaluates_breakpoint_condition_p ()
1998 || !target_supports_evaluation_of_breakpoint_conditions ())
1999 return;
2000
2001 /* Do a first pass to check for locations with no assigned
2002 conditions or conditions that fail to parse to a valid agent expression
2003 bytecode. If any of these happen, then it's no use to send conditions
2004 to the target since this location will always trigger and generate a
2005 response back to GDB. */
2006 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2007 {
2008 loc = (*loc2p);
2009 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2010 {
2011 if (modified)
2012 {
2013 struct agent_expr *aexpr;
2014
2015 /* Re-parse the conditions since something changed. In that
2016 case we already freed the condition bytecodes (see
2017 force_breakpoint_reinsertion). We just
2018 need to parse the condition to bytecodes again. */
2019 aexpr = parse_cond_to_aexpr (bl->address, loc->cond);
2020 loc->cond_bytecode = aexpr;
2021
2022 /* Check if we managed to parse the conditional expression
2023 correctly. If not, we will not send this condition
2024 to the target. */
2025 if (aexpr)
2026 continue;
2027 }
2028
2029 /* If we have a NULL bytecode expression, it means something
2030 went wrong or we have a null condition expression. */
2031 if (!loc->cond_bytecode)
2032 {
2033 null_condition_or_parse_error = 1;
2034 break;
2035 }
2036 }
2037 }
2038
2039 /* If any of these happened, it means we will have to evaluate the conditions
2040 for the location's address on gdb's side. It is no use keeping bytecodes
2041 for all the other duplicate locations, thus we free all of them here.
2042
2043 This is so we have a finer control over which locations' conditions are
2044 being evaluated by GDB or the remote stub. */
2045 if (null_condition_or_parse_error)
2046 {
2047 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2048 {
2049 loc = (*loc2p);
2050 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num)
2051 {
2052 /* Only go as far as the first NULL bytecode is
2053 located. */
2054 if (!loc->cond_bytecode)
2055 return;
2056
2057 free_agent_expr (loc->cond_bytecode);
2058 loc->cond_bytecode = NULL;
2059 }
2060 }
2061 }
2062
2063 /* No NULL conditions or failed bytecode generation. Build a condition list
2064 for this location's address. */
2065 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address)
2066 {
2067 loc = (*loc2p);
2068 if (loc->cond
2069 && is_breakpoint (loc->owner)
2070 && loc->pspace->num == bl->pspace->num
2071 && loc->owner->enable_state == bp_enabled
2072 && loc->enabled)
2073 /* Add the condition to the vector. This will be used later to send the
2074 conditions to the target. */
2075 VEC_safe_push (agent_expr_p, bl->target_info.conditions,
2076 loc->cond_bytecode);
2077 }
2078
2079 return;
2080}
2081
35df4500
TJB
2082/* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2083 location. Any error messages are printed to TMP_ERROR_STREAM; and
3fbb6ffa 2084 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
c30eee59
TJB
2085 Returns 0 for success, 1 if the bp_location type is not supported or
2086 -1 for failure.
879bfdc2 2087
4a64f543
MS
2088 NOTE drow/2003-09-09: This routine could be broken down to an
2089 object-style method for each breakpoint or catchpoint type. */
26bb91f3 2090static int
35df4500 2091insert_bp_location (struct bp_location *bl,
26bb91f3 2092 struct ui_file *tmp_error_stream,
3fbb6ffa 2093 int *disabled_breaks,
26bb91f3 2094 int *hw_breakpoint_error)
879bfdc2
DJ
2095{
2096 int val = 0;
2097
b775012e 2098 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
879bfdc2
DJ
2099 return 0;
2100
35c63cd8
JB
2101 /* Note we don't initialize bl->target_info, as that wipes out
2102 the breakpoint location's shadow_contents if the breakpoint
2103 is still inserted at that location. This in turn breaks
2104 target_read_memory which depends on these buffers when
2105 a memory read is requested at the breakpoint location:
2106 Once the target_info has been wiped, we fail to see that
2107 we have a breakpoint inserted at that address and thus
2108 read the breakpoint instead of returning the data saved in
2109 the breakpoint location's shadow contents. */
35df4500
TJB
2110 bl->target_info.placed_address = bl->address;
2111 bl->target_info.placed_address_space = bl->pspace->aspace;
f1310107 2112 bl->target_info.length = bl->length;
8181d85f 2113
b775012e
LM
2114 /* When working with target-side conditions, we must pass all the conditions
2115 for the same breakpoint address down to the target since GDB will not
2116 insert those locations. With a list of breakpoint conditions, the target
2117 can decide when to stop and notify GDB. */
2118
2119 if (is_breakpoint (bl->owner))
2120 {
2121 build_target_condition_list (bl);
2122 /* Reset the condition modification marker. */
2123 bl->needs_update = 0;
2124 }
2125
35df4500
TJB
2126 if (bl->loc_type == bp_loc_software_breakpoint
2127 || bl->loc_type == bp_loc_hardware_breakpoint)
879bfdc2 2128 {
35df4500 2129 if (bl->owner->type != bp_hardware_breakpoint)
765dc015
VP
2130 {
2131 /* If the explicitly specified breakpoint type
2132 is not hardware breakpoint, check the memory map to see
2133 if the breakpoint address is in read only memory or not.
4a64f543 2134
765dc015
VP
2135 Two important cases are:
2136 - location type is not hardware breakpoint, memory
2137 is readonly. We change the type of the location to
2138 hardware breakpoint.
4a64f543
MS
2139 - location type is hardware breakpoint, memory is
2140 read-write. This means we've previously made the
2141 location hardware one, but then the memory map changed,
2142 so we undo.
765dc015 2143
4a64f543
MS
2144 When breakpoints are removed, remove_breakpoints will use
2145 location types we've just set here, the only possible
2146 problem is that memory map has changed during running
2147 program, but it's not going to work anyway with current
2148 gdb. */
765dc015 2149 struct mem_region *mr
35df4500 2150 = lookup_mem_region (bl->target_info.placed_address);
765dc015
VP
2151
2152 if (mr)
2153 {
2154 if (automatic_hardware_breakpoints)
2155 {
765dc015
VP
2156 enum bp_loc_type new_type;
2157
2158 if (mr->attrib.mode != MEM_RW)
2159 new_type = bp_loc_hardware_breakpoint;
2160 else
2161 new_type = bp_loc_software_breakpoint;
2162
35df4500 2163 if (new_type != bl->loc_type)
765dc015
VP
2164 {
2165 static int said = 0;
cc59ec59 2166
35df4500 2167 bl->loc_type = new_type;
765dc015
VP
2168 if (!said)
2169 {
3e43a32a
MS
2170 fprintf_filtered (gdb_stdout,
2171 _("Note: automatically using "
2172 "hardware breakpoints for "
2173 "read-only addresses.\n"));
765dc015
VP
2174 said = 1;
2175 }
2176 }
2177 }
35df4500 2178 else if (bl->loc_type == bp_loc_software_breakpoint
765dc015 2179 && mr->attrib.mode != MEM_RW)
3e43a32a
MS
2180 warning (_("cannot set software breakpoint "
2181 "at readonly address %s"),
35df4500 2182 paddress (bl->gdbarch, bl->address));
765dc015
VP
2183 }
2184 }
2185
879bfdc2
DJ
2186 /* First check to see if we have to handle an overlay. */
2187 if (overlay_debugging == ovly_off
35df4500
TJB
2188 || bl->section == NULL
2189 || !(section_is_overlay (bl->section)))
879bfdc2
DJ
2190 {
2191 /* No overlay handling: just set the breakpoint. */
2192
348d480f 2193 val = bl->owner->ops->insert_location (bl);
879bfdc2
DJ
2194 }
2195 else
2196 {
4a64f543 2197 /* This breakpoint is in an overlay section.
879bfdc2
DJ
2198 Shall we set a breakpoint at the LMA? */
2199 if (!overlay_events_enabled)
2200 {
2201 /* Yes -- overlay event support is not active,
2202 so we must try to set a breakpoint at the LMA.
2203 This will not work for a hardware breakpoint. */
35df4500 2204 if (bl->loc_type == bp_loc_hardware_breakpoint)
8a3fe4f8 2205 warning (_("hardware breakpoint %d not supported in overlay!"),
35df4500 2206 bl->owner->number);
879bfdc2
DJ
2207 else
2208 {
35df4500
TJB
2209 CORE_ADDR addr = overlay_unmapped_address (bl->address,
2210 bl->section);
879bfdc2 2211 /* Set a software (trap) breakpoint at the LMA. */
35df4500
TJB
2212 bl->overlay_target_info = bl->target_info;
2213 bl->overlay_target_info.placed_address = addr;
2214 val = target_insert_breakpoint (bl->gdbarch,
2215 &bl->overlay_target_info);
879bfdc2 2216 if (val != 0)
99361f52 2217 fprintf_unfiltered (tmp_error_stream,
3e43a32a
MS
2218 "Overlay breakpoint %d "
2219 "failed: in ROM?\n",
35df4500 2220 bl->owner->number);
879bfdc2
DJ
2221 }
2222 }
2223 /* Shall we set a breakpoint at the VMA? */
35df4500 2224 if (section_is_mapped (bl->section))
879bfdc2
DJ
2225 {
2226 /* Yes. This overlay section is mapped into memory. */
348d480f 2227 val = bl->owner->ops->insert_location (bl);
879bfdc2
DJ
2228 }
2229 else
2230 {
2231 /* No. This breakpoint will not be inserted.
2232 No error, but do not mark the bp as 'inserted'. */
2233 return 0;
2234 }
2235 }
2236
2237 if (val)
2238 {
2239 /* Can't set the breakpoint. */
35df4500 2240 if (solib_name_from_address (bl->pspace, bl->address))
879bfdc2 2241 {
4a64f543 2242 /* See also: disable_breakpoints_in_shlibs. */
879bfdc2 2243 val = 0;
35df4500 2244 bl->shlib_disabled = 1;
8d3788bd 2245 observer_notify_breakpoint_modified (bl->owner);
3fbb6ffa
TJB
2246 if (!*disabled_breaks)
2247 {
2248 fprintf_unfiltered (tmp_error_stream,
2249 "Cannot insert breakpoint %d.\n",
2250 bl->owner->number);
2251 fprintf_unfiltered (tmp_error_stream,
2252 "Temporarily disabling shared "
2253 "library breakpoints:\n");
2254 }
2255 *disabled_breaks = 1;
879bfdc2 2256 fprintf_unfiltered (tmp_error_stream,
35df4500 2257 "breakpoint #%d\n", bl->owner->number);
879bfdc2
DJ
2258 }
2259 else
879bfdc2 2260 {
35df4500 2261 if (bl->loc_type == bp_loc_hardware_breakpoint)
879bfdc2
DJ
2262 {
2263 *hw_breakpoint_error = 1;
3e43a32a
MS
2264 fprintf_unfiltered (tmp_error_stream,
2265 "Cannot insert hardware "
2266 "breakpoint %d.\n",
35df4500 2267 bl->owner->number);
879bfdc2
DJ
2268 }
2269 else
2270 {
2271 fprintf_unfiltered (tmp_error_stream,
2272 "Cannot insert breakpoint %d.\n",
35df4500 2273 bl->owner->number);
879bfdc2
DJ
2274 fprintf_filtered (tmp_error_stream,
2275 "Error accessing memory address ");
35df4500 2276 fputs_filtered (paddress (bl->gdbarch, bl->address),
5af949e3 2277 tmp_error_stream);
879bfdc2
DJ
2278 fprintf_filtered (tmp_error_stream, ": %s.\n",
2279 safe_strerror (val));
2280 }
2281
2282 }
2283 }
2284 else
35df4500 2285 bl->inserted = 1;
879bfdc2
DJ
2286
2287 return val;
2288 }
2289
35df4500 2290 else if (bl->loc_type == bp_loc_hardware_watchpoint
879bfdc2 2291 /* NOTE drow/2003-09-08: This state only exists for removing
4a64f543 2292 watchpoints. It's not clear that it's necessary... */
35df4500 2293 && bl->owner->disposition != disp_del_at_next_stop)
879bfdc2 2294 {
77b06cd7
TJB
2295 gdb_assert (bl->owner->ops != NULL
2296 && bl->owner->ops->insert_location != NULL);
2297
2298 val = bl->owner->ops->insert_location (bl);
85d721b8
PA
2299
2300 /* If trying to set a read-watchpoint, and it turns out it's not
2301 supported, try emulating one with an access watchpoint. */
35df4500 2302 if (val == 1 && bl->watchpoint_type == hw_read)
85d721b8
PA
2303 {
2304 struct bp_location *loc, **loc_temp;
2305
2306 /* But don't try to insert it, if there's already another
2307 hw_access location that would be considered a duplicate
2308 of this one. */
2309 ALL_BP_LOCATIONS (loc, loc_temp)
35df4500 2310 if (loc != bl
85d721b8 2311 && loc->watchpoint_type == hw_access
35df4500 2312 && watchpoint_locations_match (bl, loc))
85d721b8 2313 {
35df4500
TJB
2314 bl->duplicate = 1;
2315 bl->inserted = 1;
2316 bl->target_info = loc->target_info;
2317 bl->watchpoint_type = hw_access;
85d721b8
PA
2318 val = 0;
2319 break;
2320 }
2321
2322 if (val == 1)
2323 {
77b06cd7
TJB
2324 bl->watchpoint_type = hw_access;
2325 val = bl->owner->ops->insert_location (bl);
2326
2327 if (val)
2328 /* Back to the original value. */
2329 bl->watchpoint_type = hw_read;
85d721b8
PA
2330 }
2331 }
2332
35df4500 2333 bl->inserted = (val == 0);
879bfdc2
DJ
2334 }
2335
35df4500 2336 else if (bl->owner->type == bp_catchpoint)
879bfdc2 2337 {
77b06cd7
TJB
2338 gdb_assert (bl->owner->ops != NULL
2339 && bl->owner->ops->insert_location != NULL);
2340
2341 val = bl->owner->ops->insert_location (bl);
2342 if (val)
2343 {
2344 bl->owner->enable_state = bp_disabled;
2345
2346 if (val == 1)
2347 warning (_("\
2348Error inserting catchpoint %d: Your system does not support this type\n\
2349of catchpoint."), bl->owner->number);
2350 else
2351 warning (_("Error inserting catchpoint %d."), bl->owner->number);
2352 }
2353
2354 bl->inserted = (val == 0);
1640b821
DJ
2355
2356 /* We've already printed an error message if there was a problem
2357 inserting this catchpoint, and we've disabled the catchpoint,
2358 so just return success. */
2359 return 0;
879bfdc2
DJ
2360 }
2361
2362 return 0;
2363}
2364
6c95b8df
PA
2365/* This function is called when program space PSPACE is about to be
2366 deleted. It takes care of updating breakpoints to not reference
2367 PSPACE anymore. */
2368
2369void
2370breakpoint_program_space_exit (struct program_space *pspace)
2371{
2372 struct breakpoint *b, *b_temp;
876fa593 2373 struct bp_location *loc, **loc_temp;
6c95b8df
PA
2374
2375 /* Remove any breakpoint that was set through this program space. */
2376 ALL_BREAKPOINTS_SAFE (b, b_temp)
2377 {
2378 if (b->pspace == pspace)
2379 delete_breakpoint (b);
2380 }
2381
2382 /* Breakpoints set through other program spaces could have locations
2383 bound to PSPACE as well. Remove those. */
876fa593 2384 ALL_BP_LOCATIONS (loc, loc_temp)
6c95b8df
PA
2385 {
2386 struct bp_location *tmp;
2387
2388 if (loc->pspace == pspace)
2389 {
2bdf28a0 2390 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6c95b8df
PA
2391 if (loc->owner->loc == loc)
2392 loc->owner->loc = loc->next;
2393 else
2394 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next)
2395 if (tmp->next == loc)
2396 {
2397 tmp->next = loc->next;
2398 break;
2399 }
2400 }
2401 }
2402
2403 /* Now update the global location list to permanently delete the
2404 removed locations above. */
2405 update_global_location_list (0);
2406}
2407
74960c60
VP
2408/* Make sure all breakpoints are inserted in inferior.
2409 Throws exception on any error.
2410 A breakpoint that is already inserted won't be inserted
2411 again, so calling this function twice is safe. */
2412void
2413insert_breakpoints (void)
2414{
2415 struct breakpoint *bpt;
2416
2417 ALL_BREAKPOINTS (bpt)
2418 if (is_hardware_watchpoint (bpt))
3a5c3e22
PA
2419 {
2420 struct watchpoint *w = (struct watchpoint *) bpt;
2421
2422 update_watchpoint (w, 0 /* don't reparse. */);
2423 }
74960c60 2424
b60e7edf 2425 update_global_location_list (1);
74960c60 2426
c35b1492
PA
2427 /* update_global_location_list does not insert breakpoints when
2428 always_inserted_mode is not enabled. Explicitly insert them
2429 now. */
2430 if (!breakpoints_always_inserted_mode ())
74960c60
VP
2431 insert_breakpoint_locations ();
2432}
2433
20388dd6
YQ
2434/* Invoke CALLBACK for each of bp_location. */
2435
2436void
2437iterate_over_bp_locations (walk_bp_location_callback callback)
2438{
2439 struct bp_location *loc, **loc_tmp;
2440
2441 ALL_BP_LOCATIONS (loc, loc_tmp)
2442 {
2443 callback (loc, NULL);
2444 }
2445}
2446
b775012e
LM
2447/* This is used when we need to synch breakpoint conditions between GDB and the
2448 target. It is the case with deleting and disabling of breakpoints when using
2449 always-inserted mode. */
2450
2451static void
2452update_inserted_breakpoint_locations (void)
2453{
2454 struct bp_location *bl, **blp_tmp;
2455 int error_flag = 0;
2456 int val = 0;
2457 int disabled_breaks = 0;
2458 int hw_breakpoint_error = 0;
2459
2460 struct ui_file *tmp_error_stream = mem_fileopen ();
2461 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
2462
2463 /* Explicitly mark the warning -- this will only be printed if
2464 there was an error. */
2465 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
2466
2467 save_current_space_and_thread ();
2468
2469 ALL_BP_LOCATIONS (bl, blp_tmp)
2470 {
2471 /* We only want to update software breakpoints and hardware
2472 breakpoints. */
2473 if (!is_breakpoint (bl->owner))
2474 continue;
2475
2476 /* We only want to update locations that are already inserted
2477 and need updating. This is to avoid unwanted insertion during
2478 deletion of breakpoints. */
2479 if (!bl->inserted || (bl->inserted && !bl->needs_update))
2480 continue;
2481
2482 switch_to_program_space_and_thread (bl->pspace);
2483
2484 /* For targets that support global breakpoints, there's no need
2485 to select an inferior to insert breakpoint to. In fact, even
2486 if we aren't attached to any process yet, we should still
2487 insert breakpoints. */
2488 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2489 && ptid_equal (inferior_ptid, null_ptid))
2490 continue;
2491
2492 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2493 &hw_breakpoint_error);
2494 if (val)
2495 error_flag = val;
2496 }
2497
2498 if (error_flag)
2499 {
2500 target_terminal_ours_for_output ();
2501 error_stream (tmp_error_stream);
2502 }
2503
2504 do_cleanups (cleanups);
2505}
2506
c30eee59 2507/* Used when starting or continuing the program. */
c906108c 2508
74960c60
VP
2509static void
2510insert_breakpoint_locations (void)
c906108c 2511{
a5606eee 2512 struct breakpoint *bpt;
35df4500 2513 struct bp_location *bl, **blp_tmp;
eacd795a 2514 int error_flag = 0;
c906108c 2515 int val = 0;
3fbb6ffa 2516 int disabled_breaks = 0;
81d0cc19 2517 int hw_breakpoint_error = 0;
c906108c 2518
81d0cc19 2519 struct ui_file *tmp_error_stream = mem_fileopen ();
f7545552 2520 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
74960c60 2521
81d0cc19
GS
2522 /* Explicitly mark the warning -- this will only be printed if
2523 there was an error. */
2524 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
6c95b8df
PA
2525
2526 save_current_space_and_thread ();
2527
35df4500 2528 ALL_BP_LOCATIONS (bl, blp_tmp)
879bfdc2 2529 {
b775012e 2530 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
879bfdc2
DJ
2531 continue;
2532
4a64f543
MS
2533 /* There is no point inserting thread-specific breakpoints if
2534 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2535 has BL->OWNER always non-NULL. */
35df4500
TJB
2536 if (bl->owner->thread != -1
2537 && !valid_thread_id (bl->owner->thread))
f365de73
AS
2538 continue;
2539
35df4500 2540 switch_to_program_space_and_thread (bl->pspace);
6c95b8df
PA
2541
2542 /* For targets that support global breakpoints, there's no need
2543 to select an inferior to insert breakpoint to. In fact, even
2544 if we aren't attached to any process yet, we should still
2545 insert breakpoints. */
2546 if (!gdbarch_has_global_breakpoints (target_gdbarch)
2547 && ptid_equal (inferior_ptid, null_ptid))
2548 continue;
2549
3fbb6ffa
TJB
2550 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks,
2551 &hw_breakpoint_error);
879bfdc2 2552 if (val)
eacd795a 2553 error_flag = val;
879bfdc2 2554 }
c906108c 2555
4a64f543
MS
2556 /* If we failed to insert all locations of a watchpoint, remove
2557 them, as half-inserted watchpoint is of limited use. */
a5606eee
VP
2558 ALL_BREAKPOINTS (bpt)
2559 {
2560 int some_failed = 0;
2561 struct bp_location *loc;
2562
2563 if (!is_hardware_watchpoint (bpt))
2564 continue;
2565
d6b74ac4 2566 if (!breakpoint_enabled (bpt))
a5606eee 2567 continue;
74960c60
VP
2568
2569 if (bpt->disposition == disp_del_at_next_stop)
2570 continue;
a5606eee
VP
2571
2572 for (loc = bpt->loc; loc; loc = loc->next)
56710373 2573 if (!loc->inserted && should_be_inserted (loc))
a5606eee
VP
2574 {
2575 some_failed = 1;
2576 break;
2577 }
2578 if (some_failed)
2579 {
2580 for (loc = bpt->loc; loc; loc = loc->next)
2581 if (loc->inserted)
2582 remove_breakpoint (loc, mark_uninserted);
2583
2584 hw_breakpoint_error = 1;
2585 fprintf_unfiltered (tmp_error_stream,
2586 "Could not insert hardware watchpoint %d.\n",
2587 bpt->number);
eacd795a 2588 error_flag = -1;
a5606eee
VP
2589 }
2590 }
2591
eacd795a 2592 if (error_flag)
81d0cc19
GS
2593 {
2594 /* If a hardware breakpoint or watchpoint was inserted, add a
2595 message about possibly exhausted resources. */
879bfdc2 2596 if (hw_breakpoint_error)
81d0cc19 2597 {
c6510018
MS
2598 fprintf_unfiltered (tmp_error_stream,
2599 "Could not insert hardware breakpoints:\n\
2600You may have requested too many hardware breakpoints/watchpoints.\n");
81d0cc19 2601 }
81d0cc19
GS
2602 target_terminal_ours_for_output ();
2603 error_stream (tmp_error_stream);
2604 }
f7545552
TT
2605
2606 do_cleanups (cleanups);
c906108c
SS
2607}
2608
c30eee59
TJB
2609/* Used when the program stops.
2610 Returns zero if successful, or non-zero if there was a problem
2611 removing a breakpoint location. */
2612
c906108c 2613int
fba45db2 2614remove_breakpoints (void)
c906108c 2615{
35df4500 2616 struct bp_location *bl, **blp_tmp;
3a1bae8e 2617 int val = 0;
c906108c 2618
35df4500 2619 ALL_BP_LOCATIONS (bl, blp_tmp)
c5aa993b 2620 {
1e4d1764 2621 if (bl->inserted && !is_tracepoint (bl->owner))
35df4500 2622 val |= remove_breakpoint (bl, mark_uninserted);
c5aa993b 2623 }
3a1bae8e 2624 return val;
c906108c
SS
2625}
2626
6c95b8df
PA
2627/* Remove breakpoints of process PID. */
2628
2629int
2630remove_breakpoints_pid (int pid)
2631{
35df4500 2632 struct bp_location *bl, **blp_tmp;
6c95b8df
PA
2633 int val;
2634 struct inferior *inf = find_inferior_pid (pid);
2635
35df4500 2636 ALL_BP_LOCATIONS (bl, blp_tmp)
6c95b8df 2637 {
35df4500 2638 if (bl->pspace != inf->pspace)
6c95b8df
PA
2639 continue;
2640
35df4500 2641 if (bl->inserted)
6c95b8df 2642 {
35df4500 2643 val = remove_breakpoint (bl, mark_uninserted);
6c95b8df
PA
2644 if (val != 0)
2645 return val;
2646 }
2647 }
2648 return 0;
2649}
2650
c906108c 2651int
fba45db2 2652reattach_breakpoints (int pid)
c906108c 2653{
6c95b8df 2654 struct cleanup *old_chain;
35df4500 2655 struct bp_location *bl, **blp_tmp;
c906108c 2656 int val;
86b887df 2657 struct ui_file *tmp_error_stream;
3fbb6ffa 2658 int dummy1 = 0, dummy2 = 0;
6c95b8df
PA
2659 struct inferior *inf;
2660 struct thread_info *tp;
2661
2662 tp = any_live_thread_of_process (pid);
2663 if (tp == NULL)
2664 return 1;
2665
2666 inf = find_inferior_pid (pid);
2667 old_chain = save_inferior_ptid ();
2668
2669 inferior_ptid = tp->ptid;
a4954f26 2670
86b887df 2671 tmp_error_stream = mem_fileopen ();
a4954f26 2672 make_cleanup_ui_file_delete (tmp_error_stream);
c906108c 2673
35df4500 2674 ALL_BP_LOCATIONS (bl, blp_tmp)
c5aa993b 2675 {
35df4500 2676 if (bl->pspace != inf->pspace)
6c95b8df
PA
2677 continue;
2678
35df4500 2679 if (bl->inserted)
c5aa993b 2680 {
35df4500 2681 bl->inserted = 0;
3fbb6ffa 2682 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2);
c5aa993b
JM
2683 if (val != 0)
2684 {
ce696e05 2685 do_cleanups (old_chain);
c5aa993b
JM
2686 return val;
2687 }
2688 }
2689 }
ce696e05 2690 do_cleanups (old_chain);
c906108c
SS
2691 return 0;
2692}
2693
e58b0e63
PA
2694static int internal_breakpoint_number = -1;
2695
84f4c1fe
PM
2696/* Set the breakpoint number of B, depending on the value of INTERNAL.
2697 If INTERNAL is non-zero, the breakpoint number will be populated
2698 from internal_breakpoint_number and that variable decremented.
e5dd4106 2699 Otherwise the breakpoint number will be populated from
84f4c1fe
PM
2700 breakpoint_count and that value incremented. Internal breakpoints
2701 do not set the internal var bpnum. */
2702static void
2703set_breakpoint_number (int internal, struct breakpoint *b)
2704{
2705 if (internal)
2706 b->number = internal_breakpoint_number--;
2707 else
2708 {
2709 set_breakpoint_count (breakpoint_count + 1);
2710 b->number = breakpoint_count;
2711 }
2712}
2713
e62c965a 2714static struct breakpoint *
a6d9a66e 2715create_internal_breakpoint (struct gdbarch *gdbarch,
06edf0c0 2716 CORE_ADDR address, enum bptype type,
c0a91b2b 2717 const struct breakpoint_ops *ops)
e62c965a 2718{
e62c965a
PP
2719 struct symtab_and_line sal;
2720 struct breakpoint *b;
2721
4a64f543 2722 init_sal (&sal); /* Initialize to zeroes. */
e62c965a
PP
2723
2724 sal.pc = address;
2725 sal.section = find_pc_overlay (sal.pc);
6c95b8df 2726 sal.pspace = current_program_space;
e62c965a 2727
06edf0c0 2728 b = set_raw_breakpoint (gdbarch, sal, type, ops);
e62c965a
PP
2729 b->number = internal_breakpoint_number--;
2730 b->disposition = disp_donttouch;
2731
2732 return b;
2733}
2734
17450429
PP
2735static const char *const longjmp_names[] =
2736 {
2737 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2738 };
2739#define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2740
2741/* Per-objfile data private to breakpoint.c. */
2742struct breakpoint_objfile_data
2743{
2744 /* Minimal symbol for "_ovly_debug_event" (if any). */
2745 struct minimal_symbol *overlay_msym;
2746
2747 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2748 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES];
2749
28106bc2
SDJ
2750 /* True if we have looked for longjmp probes. */
2751 int longjmp_searched;
2752
2753 /* SystemTap probe points for longjmp (if any). */
2754 VEC (probe_p) *longjmp_probes;
2755
17450429
PP
2756 /* Minimal symbol for "std::terminate()" (if any). */
2757 struct minimal_symbol *terminate_msym;
2758
2759 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2760 struct minimal_symbol *exception_msym;
28106bc2
SDJ
2761
2762 /* True if we have looked for exception probes. */
2763 int exception_searched;
2764
2765 /* SystemTap probe points for unwinding (if any). */
2766 VEC (probe_p) *exception_probes;
17450429
PP
2767};
2768
2769static const struct objfile_data *breakpoint_objfile_key;
2770
2771/* Minimal symbol not found sentinel. */
2772static struct minimal_symbol msym_not_found;
2773
2774/* Returns TRUE if MSYM point to the "not found" sentinel. */
2775
2776static int
2777msym_not_found_p (const struct minimal_symbol *msym)
2778{
2779 return msym == &msym_not_found;
2780}
2781
2782/* Return per-objfile data needed by breakpoint.c.
2783 Allocate the data if necessary. */
2784
2785static struct breakpoint_objfile_data *
2786get_breakpoint_objfile_data (struct objfile *objfile)
2787{
2788 struct breakpoint_objfile_data *bp_objfile_data;
2789
2790 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key);
2791 if (bp_objfile_data == NULL)
2792 {
2793 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack,
2794 sizeof (*bp_objfile_data));
2795
2796 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
2797 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
2798 }
2799 return bp_objfile_data;
2800}
2801
28106bc2
SDJ
2802static void
2803free_breakpoint_probes (struct objfile *obj, void *data)
2804{
2805 struct breakpoint_objfile_data *bp_objfile_data = data;
2806
2807 VEC_free (probe_p, bp_objfile_data->longjmp_probes);
2808 VEC_free (probe_p, bp_objfile_data->exception_probes);
2809}
2810
e62c965a 2811static void
af02033e 2812create_overlay_event_breakpoint (void)
e62c965a 2813{
69de3c6a 2814 struct objfile *objfile;
af02033e 2815 const char *const func_name = "_ovly_debug_event";
e62c965a 2816
69de3c6a
PP
2817 ALL_OBJFILES (objfile)
2818 {
2819 struct breakpoint *b;
17450429
PP
2820 struct breakpoint_objfile_data *bp_objfile_data;
2821 CORE_ADDR addr;
69de3c6a 2822
17450429
PP
2823 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2824
2825 if (msym_not_found_p (bp_objfile_data->overlay_msym))
2826 continue;
2827
2828 if (bp_objfile_data->overlay_msym == NULL)
2829 {
2830 struct minimal_symbol *m;
2831
2832 m = lookup_minimal_symbol_text (func_name, objfile);
2833 if (m == NULL)
2834 {
2835 /* Avoid future lookups in this objfile. */
2836 bp_objfile_data->overlay_msym = &msym_not_found;
2837 continue;
2838 }
2839 bp_objfile_data->overlay_msym = m;
2840 }
e62c965a 2841
17450429
PP
2842 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
2843 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
06edf0c0
PA
2844 bp_overlay_event,
2845 &internal_breakpoint_ops);
69de3c6a 2846 b->addr_string = xstrdup (func_name);
e62c965a 2847
69de3c6a
PP
2848 if (overlay_debugging == ovly_auto)
2849 {
2850 b->enable_state = bp_enabled;
2851 overlay_events_enabled = 1;
2852 }
2853 else
2854 {
2855 b->enable_state = bp_disabled;
2856 overlay_events_enabled = 0;
2857 }
e62c965a
PP
2858 }
2859 update_global_location_list (1);
2860}
2861
0fd8e87f 2862static void
af02033e 2863create_longjmp_master_breakpoint (void)
0fd8e87f 2864{
6c95b8df 2865 struct program_space *pspace;
6c95b8df
PA
2866 struct cleanup *old_chain;
2867
2868 old_chain = save_current_program_space ();
0fd8e87f 2869
6c95b8df 2870 ALL_PSPACES (pspace)
af02033e
PP
2871 {
2872 struct objfile *objfile;
2873
2874 set_current_program_space (pspace);
2875
2876 ALL_OBJFILES (objfile)
0fd8e87f 2877 {
af02033e
PP
2878 int i;
2879 struct gdbarch *gdbarch;
17450429 2880 struct breakpoint_objfile_data *bp_objfile_data;
0fd8e87f 2881
af02033e
PP
2882 gdbarch = get_objfile_arch (objfile);
2883 if (!gdbarch_get_longjmp_target_p (gdbarch))
0fd8e87f
UW
2884 continue;
2885
17450429
PP
2886 bp_objfile_data = get_breakpoint_objfile_data (objfile);
2887
28106bc2
SDJ
2888 if (!bp_objfile_data->longjmp_searched)
2889 {
2890 bp_objfile_data->longjmp_probes
2891 = find_probes_in_objfile (objfile, "libc", "longjmp");
2892 bp_objfile_data->longjmp_searched = 1;
2893 }
2894
2895 if (bp_objfile_data->longjmp_probes != NULL)
2896 {
2897 int i;
2898 struct probe *probe;
2899 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2900
2901 for (i = 0;
2902 VEC_iterate (probe_p,
2903 bp_objfile_data->longjmp_probes,
2904 i, probe);
2905 ++i)
2906 {
2907 struct breakpoint *b;
2908
2909 b = create_internal_breakpoint (gdbarch, probe->address,
2910 bp_longjmp_master,
2911 &internal_breakpoint_ops);
2912 b->addr_string = xstrdup ("-probe-stap libc:longjmp");
2913 b->enable_state = bp_disabled;
2914 }
2915
2916 continue;
2917 }
2918
17450429 2919 for (i = 0; i < NUM_LONGJMP_NAMES; i++)
af02033e
PP
2920 {
2921 struct breakpoint *b;
af02033e 2922 const char *func_name;
17450429 2923 CORE_ADDR addr;
6c95b8df 2924
17450429 2925 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i]))
af02033e 2926 continue;
0fd8e87f 2927
17450429
PP
2928 func_name = longjmp_names[i];
2929 if (bp_objfile_data->longjmp_msym[i] == NULL)
2930 {
2931 struct minimal_symbol *m;
2932
2933 m = lookup_minimal_symbol_text (func_name, objfile);
2934 if (m == NULL)
2935 {
2936 /* Prevent future lookups in this objfile. */
2937 bp_objfile_data->longjmp_msym[i] = &msym_not_found;
2938 continue;
2939 }
2940 bp_objfile_data->longjmp_msym[i] = m;
2941 }
2942
2943 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
06edf0c0
PA
2944 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
2945 &internal_breakpoint_ops);
af02033e
PP
2946 b->addr_string = xstrdup (func_name);
2947 b->enable_state = bp_disabled;
2948 }
0fd8e87f 2949 }
af02033e 2950 }
0fd8e87f 2951 update_global_location_list (1);
6c95b8df
PA
2952
2953 do_cleanups (old_chain);
0fd8e87f
UW
2954}
2955
af02033e 2956/* Create a master std::terminate breakpoint. */
aa7d318d 2957static void
af02033e 2958create_std_terminate_master_breakpoint (void)
aa7d318d
TT
2959{
2960 struct program_space *pspace;
aa7d318d 2961 struct cleanup *old_chain;
af02033e 2962 const char *const func_name = "std::terminate()";
aa7d318d
TT
2963
2964 old_chain = save_current_program_space ();
2965
2966 ALL_PSPACES (pspace)
17450429
PP
2967 {
2968 struct objfile *objfile;
2969 CORE_ADDR addr;
2970
2971 set_current_program_space (pspace);
2972
aa7d318d
TT
2973 ALL_OBJFILES (objfile)
2974 {
2975 struct breakpoint *b;
17450429 2976 struct breakpoint_objfile_data *bp_objfile_data;
aa7d318d 2977
17450429 2978 bp_objfile_data = get_breakpoint_objfile_data (objfile);
aa7d318d 2979
17450429
PP
2980 if (msym_not_found_p (bp_objfile_data->terminate_msym))
2981 continue;
2982
2983 if (bp_objfile_data->terminate_msym == NULL)
2984 {
2985 struct minimal_symbol *m;
2986
2987 m = lookup_minimal_symbol (func_name, NULL, objfile);
2988 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text
2989 && MSYMBOL_TYPE (m) != mst_file_text))
2990 {
2991 /* Prevent future lookups in this objfile. */
2992 bp_objfile_data->terminate_msym = &msym_not_found;
2993 continue;
2994 }
2995 bp_objfile_data->terminate_msym = m;
2996 }
aa7d318d 2997
17450429
PP
2998 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
2999 b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
06edf0c0
PA
3000 bp_std_terminate_master,
3001 &internal_breakpoint_ops);
aa7d318d
TT
3002 b->addr_string = xstrdup (func_name);
3003 b->enable_state = bp_disabled;
3004 }
17450429
PP
3005 }
3006
aa7d318d
TT
3007 update_global_location_list (1);
3008
3009 do_cleanups (old_chain);
3010}
3011
186c406b
TT
3012/* Install a master breakpoint on the unwinder's debug hook. */
3013
70221824 3014static void
186c406b
TT
3015create_exception_master_breakpoint (void)
3016{
3017 struct objfile *objfile;
17450429 3018 const char *const func_name = "_Unwind_DebugHook";
186c406b
TT
3019
3020 ALL_OBJFILES (objfile)
3021 {
17450429
PP
3022 struct breakpoint *b;
3023 struct gdbarch *gdbarch;
3024 struct breakpoint_objfile_data *bp_objfile_data;
3025 CORE_ADDR addr;
3026
3027 bp_objfile_data = get_breakpoint_objfile_data (objfile);
3028
28106bc2
SDJ
3029 /* We prefer the SystemTap probe point if it exists. */
3030 if (!bp_objfile_data->exception_searched)
3031 {
3032 bp_objfile_data->exception_probes
3033 = find_probes_in_objfile (objfile, "libgcc", "unwind");
3034 bp_objfile_data->exception_searched = 1;
3035 }
3036
3037 if (bp_objfile_data->exception_probes != NULL)
3038 {
3039 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3040 int i;
3041 struct probe *probe;
3042
3043 for (i = 0;
3044 VEC_iterate (probe_p,
3045 bp_objfile_data->exception_probes,
3046 i, probe);
3047 ++i)
3048 {
3049 struct breakpoint *b;
3050
3051 b = create_internal_breakpoint (gdbarch, probe->address,
3052 bp_exception_master,
3053 &internal_breakpoint_ops);
3054 b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
3055 b->enable_state = bp_disabled;
3056 }
3057
3058 continue;
3059 }
3060
3061 /* Otherwise, try the hook function. */
3062
17450429
PP
3063 if (msym_not_found_p (bp_objfile_data->exception_msym))
3064 continue;
3065
3066 gdbarch = get_objfile_arch (objfile);
186c406b 3067
17450429 3068 if (bp_objfile_data->exception_msym == NULL)
186c406b 3069 {
17450429 3070 struct minimal_symbol *debug_hook;
186c406b 3071
17450429
PP
3072 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile);
3073 if (debug_hook == NULL)
3074 {
3075 bp_objfile_data->exception_msym = &msym_not_found;
3076 continue;
3077 }
3078
3079 bp_objfile_data->exception_msym = debug_hook;
186c406b 3080 }
17450429
PP
3081
3082 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym);
3083 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
3084 &current_target);
06edf0c0
PA
3085 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
3086 &internal_breakpoint_ops);
17450429
PP
3087 b->addr_string = xstrdup (func_name);
3088 b->enable_state = bp_disabled;
186c406b
TT
3089 }
3090
3091 update_global_location_list (1);
3092}
3093
c906108c 3094void
fba45db2 3095update_breakpoints_after_exec (void)
c906108c 3096{
35df4500 3097 struct breakpoint *b, *b_tmp;
876fa593 3098 struct bp_location *bploc, **bplocp_tmp;
c906108c 3099
25b22b0a
PA
3100 /* We're about to delete breakpoints from GDB's lists. If the
3101 INSERTED flag is true, GDB will try to lift the breakpoints by
3102 writing the breakpoints' "shadow contents" back into memory. The
3103 "shadow contents" are NOT valid after an exec, so GDB should not
3104 do that. Instead, the target is responsible from marking
3105 breakpoints out as soon as it detects an exec. We don't do that
3106 here instead, because there may be other attempts to delete
3107 breakpoints after detecting an exec and before reaching here. */
876fa593 3108 ALL_BP_LOCATIONS (bploc, bplocp_tmp)
6c95b8df
PA
3109 if (bploc->pspace == current_program_space)
3110 gdb_assert (!bploc->inserted);
c906108c 3111
35df4500 3112 ALL_BREAKPOINTS_SAFE (b, b_tmp)
c5aa993b 3113 {
6c95b8df
PA
3114 if (b->pspace != current_program_space)
3115 continue;
3116
4a64f543 3117 /* Solib breakpoints must be explicitly reset after an exec(). */
c5aa993b
JM
3118 if (b->type == bp_shlib_event)
3119 {
3120 delete_breakpoint (b);
3121 continue;
3122 }
c906108c 3123
4a64f543 3124 /* JIT breakpoints must be explicitly reset after an exec(). */
4efc6507
DE
3125 if (b->type == bp_jit_event)
3126 {
3127 delete_breakpoint (b);
3128 continue;
3129 }
3130
1900040c 3131 /* Thread event breakpoints must be set anew after an exec(),
0fd8e87f
UW
3132 as must overlay event and longjmp master breakpoints. */
3133 if (b->type == bp_thread_event || b->type == bp_overlay_event
186c406b
TT
3134 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
3135 || b->type == bp_exception_master)
c4093a6a
JM
3136 {
3137 delete_breakpoint (b);
3138 continue;
3139 }
3140
4a64f543 3141 /* Step-resume breakpoints are meaningless after an exec(). */
2c03e5be 3142 if (b->type == bp_step_resume || b->type == bp_hp_step_resume)
c5aa993b
JM
3143 {
3144 delete_breakpoint (b);
3145 continue;
3146 }
3147
611c83ae
PA
3148 /* Longjmp and longjmp-resume breakpoints are also meaningless
3149 after an exec. */
186c406b
TT
3150 if (b->type == bp_longjmp || b->type == bp_longjmp_resume
3151 || b->type == bp_exception || b->type == bp_exception_resume)
611c83ae
PA
3152 {
3153 delete_breakpoint (b);
3154 continue;
3155 }
3156
ce78b96d
JB
3157 if (b->type == bp_catchpoint)
3158 {
3159 /* For now, none of the bp_catchpoint breakpoints need to
3160 do anything at this point. In the future, if some of
3161 the catchpoints need to something, we will need to add
3162 a new method, and call this method from here. */
3163 continue;
3164 }
3165
c5aa993b
JM
3166 /* bp_finish is a special case. The only way we ought to be able
3167 to see one of these when an exec() has happened, is if the user
3168 caught a vfork, and then said "finish". Ordinarily a finish just
3169 carries them to the call-site of the current callee, by setting
3170 a temporary bp there and resuming. But in this case, the finish
3171 will carry them entirely through the vfork & exec.
3172
3173 We don't want to allow a bp_finish to remain inserted now. But
3174 we can't safely delete it, 'cause finish_command has a handle to
3175 the bp on a bpstat, and will later want to delete it. There's a
3176 chance (and I've seen it happen) that if we delete the bp_finish
3177 here, that its storage will get reused by the time finish_command
3178 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3179 We really must allow finish_command to delete a bp_finish.
3180
e5dd4106 3181 In the absence of a general solution for the "how do we know
53a5351d
JM
3182 it's safe to delete something others may have handles to?"
3183 problem, what we'll do here is just uninsert the bp_finish, and
3184 let finish_command delete it.
3185
3186 (We know the bp_finish is "doomed" in the sense that it's
3187 momentary, and will be deleted as soon as finish_command sees
3188 the inferior stopped. So it doesn't matter that the bp's
3189 address is probably bogus in the new a.out, unlike e.g., the
3190 solib breakpoints.) */
c5aa993b 3191
c5aa993b
JM
3192 if (b->type == bp_finish)
3193 {
3194 continue;
3195 }
3196
3197 /* Without a symbolic address, we have little hope of the
3198 pre-exec() address meaning the same thing in the post-exec()
4a64f543 3199 a.out. */
c5aa993b
JM
3200 if (b->addr_string == NULL)
3201 {
3202 delete_breakpoint (b);
3203 continue;
3204 }
c5aa993b 3205 }
1900040c 3206 /* FIXME what about longjmp breakpoints? Re-create them here? */
af02033e
PP
3207 create_overlay_event_breakpoint ();
3208 create_longjmp_master_breakpoint ();
3209 create_std_terminate_master_breakpoint ();
186c406b 3210 create_exception_master_breakpoint ();
c906108c
SS
3211}
3212
3213int
fba45db2 3214detach_breakpoints (int pid)
c906108c 3215{
35df4500 3216 struct bp_location *bl, **blp_tmp;
3a1bae8e 3217 int val = 0;
ce696e05 3218 struct cleanup *old_chain = save_inferior_ptid ();
6c95b8df 3219 struct inferior *inf = current_inferior ();
c5aa993b 3220
39f77062 3221 if (pid == PIDGET (inferior_ptid))
8a3fe4f8 3222 error (_("Cannot detach breakpoints of inferior_ptid"));
c5aa993b 3223
6c95b8df 3224 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
ce696e05 3225 inferior_ptid = pid_to_ptid (pid);
35df4500 3226 ALL_BP_LOCATIONS (bl, blp_tmp)
c5aa993b 3227 {
35df4500 3228 if (bl->pspace != inf->pspace)
6c95b8df
PA
3229 continue;
3230
35df4500
TJB
3231 if (bl->inserted)
3232 val |= remove_breakpoint_1 (bl, mark_inserted);
c5aa993b 3233 }
d03285ec
UW
3234
3235 /* Detach single-step breakpoints as well. */
3236 detach_single_step_breakpoints ();
3237
ce696e05 3238 do_cleanups (old_chain);
3a1bae8e 3239 return val;
c906108c
SS
3240}
3241
35df4500 3242/* Remove the breakpoint location BL from the current address space.
6c95b8df
PA
3243 Note that this is used to detach breakpoints from a child fork.
3244 When we get here, the child isn't in the inferior list, and neither
3245 do we have objects to represent its address space --- we should
35df4500 3246 *not* look at bl->pspace->aspace here. */
6c95b8df 3247
c906108c 3248static int
35df4500 3249remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is)
c906108c
SS
3250{
3251 int val;
c5aa993b 3252
35df4500
TJB
3253 /* BL is never in moribund_locations by our callers. */
3254 gdb_assert (bl->owner != NULL);
2bdf28a0 3255
35df4500 3256 if (bl->owner->enable_state == bp_permanent)
c2c6d25f
JM
3257 /* Permanent breakpoints cannot be inserted or removed. */
3258 return 0;
3259
74960c60
VP
3260 /* The type of none suggests that owner is actually deleted.
3261 This should not ever happen. */
35df4500 3262 gdb_assert (bl->owner->type != bp_none);
0bde7532 3263
35df4500
TJB
3264 if (bl->loc_type == bp_loc_software_breakpoint
3265 || bl->loc_type == bp_loc_hardware_breakpoint)
c906108c 3266 {
c02f5703
MS
3267 /* "Normal" instruction breakpoint: either the standard
3268 trap-instruction bp (bp_breakpoint), or a
3269 bp_hardware_breakpoint. */
3270
3271 /* First check to see if we have to handle an overlay. */
3272 if (overlay_debugging == ovly_off
35df4500
TJB
3273 || bl->section == NULL
3274 || !(section_is_overlay (bl->section)))
c02f5703
MS
3275 {
3276 /* No overlay handling: just remove the breakpoint. */
348d480f 3277 val = bl->owner->ops->remove_location (bl);
c02f5703 3278 }
c906108c
SS
3279 else
3280 {
4a64f543 3281 /* This breakpoint is in an overlay section.
c02f5703
MS
3282 Did we set a breakpoint at the LMA? */
3283 if (!overlay_events_enabled)
3284 {
3285 /* Yes -- overlay event support is not active, so we
3286 should have set a breakpoint at the LMA. Remove it.
3287 */
c02f5703
MS
3288 /* Ignore any failures: if the LMA is in ROM, we will
3289 have already warned when we failed to insert it. */
35df4500
TJB
3290 if (bl->loc_type == bp_loc_hardware_breakpoint)
3291 target_remove_hw_breakpoint (bl->gdbarch,
3292 &bl->overlay_target_info);
c02f5703 3293 else
35df4500
TJB
3294 target_remove_breakpoint (bl->gdbarch,
3295 &bl->overlay_target_info);
c02f5703
MS
3296 }
3297 /* Did we set a breakpoint at the VMA?
3298 If so, we will have marked the breakpoint 'inserted'. */
35df4500 3299 if (bl->inserted)
c906108c 3300 {
c02f5703
MS
3301 /* Yes -- remove it. Previously we did not bother to
3302 remove the breakpoint if the section had been
3303 unmapped, but let's not rely on that being safe. We
3304 don't know what the overlay manager might do. */
aa67235e
UW
3305
3306 /* However, we should remove *software* breakpoints only
3307 if the section is still mapped, or else we overwrite
3308 wrong code with the saved shadow contents. */
348d480f
PA
3309 if (bl->loc_type == bp_loc_hardware_breakpoint
3310 || section_is_mapped (bl->section))
3311 val = bl->owner->ops->remove_location (bl);
aa67235e
UW
3312 else
3313 val = 0;
c906108c 3314 }
c02f5703
MS
3315 else
3316 {
3317 /* No -- not inserted, so no need to remove. No error. */
3318 val = 0;
3319 }
c906108c 3320 }
879d1e6b
UW
3321
3322 /* In some cases, we might not be able to remove a breakpoint
3323 in a shared library that has already been removed, but we
3324 have not yet processed the shlib unload event. */
35df4500 3325 if (val && solib_name_from_address (bl->pspace, bl->address))
879d1e6b
UW
3326 val = 0;
3327
c906108c
SS
3328 if (val)
3329 return val;
35df4500 3330 bl->inserted = (is == mark_inserted);
c906108c 3331 }
35df4500 3332 else if (bl->loc_type == bp_loc_hardware_watchpoint)
c906108c 3333 {
77b06cd7
TJB
3334 gdb_assert (bl->owner->ops != NULL
3335 && bl->owner->ops->remove_location != NULL);
3336
35df4500 3337 bl->inserted = (is == mark_inserted);
77b06cd7 3338 bl->owner->ops->remove_location (bl);
2e70b7b9 3339
c906108c 3340 /* Failure to remove any of the hardware watchpoints comes here. */
35df4500 3341 if ((is == mark_uninserted) && (bl->inserted))
8a3fe4f8 3342 warning (_("Could not remove hardware watchpoint %d."),
35df4500 3343 bl->owner->number);
c906108c 3344 }
35df4500
TJB
3345 else if (bl->owner->type == bp_catchpoint
3346 && breakpoint_enabled (bl->owner)
3347 && !bl->duplicate)
ce78b96d 3348 {
77b06cd7
TJB
3349 gdb_assert (bl->owner->ops != NULL
3350 && bl->owner->ops->remove_location != NULL);
ce78b96d 3351
77b06cd7 3352 val = bl->owner->ops->remove_location (bl);
ce78b96d
JB
3353 if (val)
3354 return val;
77b06cd7 3355
35df4500 3356 bl->inserted = (is == mark_inserted);
ce78b96d 3357 }
c906108c
SS
3358
3359 return 0;
3360}
3361
6c95b8df 3362static int
35df4500 3363remove_breakpoint (struct bp_location *bl, insertion_state_t is)
6c95b8df
PA
3364{
3365 int ret;
3366 struct cleanup *old_chain;
3367
35df4500
TJB
3368 /* BL is never in moribund_locations by our callers. */
3369 gdb_assert (bl->owner != NULL);
2bdf28a0 3370
35df4500 3371 if (bl->owner->enable_state == bp_permanent)
6c95b8df
PA
3372 /* Permanent breakpoints cannot be inserted or removed. */
3373 return 0;
3374
3375 /* The type of none suggests that owner is actually deleted.
3376 This should not ever happen. */
35df4500 3377 gdb_assert (bl->owner->type != bp_none);
6c95b8df
PA
3378
3379 old_chain = save_current_space_and_thread ();
3380
35df4500 3381 switch_to_program_space_and_thread (bl->pspace);
6c95b8df 3382
35df4500 3383 ret = remove_breakpoint_1 (bl, is);
6c95b8df
PA
3384
3385 do_cleanups (old_chain);
3386 return ret;
3387}
3388
c906108c
SS
3389/* Clear the "inserted" flag in all breakpoints. */
3390
25b22b0a 3391void
fba45db2 3392mark_breakpoints_out (void)
c906108c 3393{
35df4500 3394 struct bp_location *bl, **blp_tmp;
c906108c 3395
35df4500
TJB
3396 ALL_BP_LOCATIONS (bl, blp_tmp)
3397 if (bl->pspace == current_program_space)
3398 bl->inserted = 0;
c906108c
SS
3399}
3400
53a5351d
JM
3401/* Clear the "inserted" flag in all breakpoints and delete any
3402 breakpoints which should go away between runs of the program.
c906108c
SS
3403
3404 Plus other such housekeeping that has to be done for breakpoints
3405 between runs.
3406
53a5351d
JM
3407 Note: this function gets called at the end of a run (by
3408 generic_mourn_inferior) and when a run begins (by
4a64f543 3409 init_wait_for_inferior). */
c906108c
SS
3410
3411
3412
3413void
fba45db2 3414breakpoint_init_inferior (enum inf_context context)
c906108c 3415{
35df4500
TJB
3416 struct breakpoint *b, *b_tmp;
3417 struct bp_location *bl, **blp_tmp;
1c5cfe86 3418 int ix;
6c95b8df 3419 struct program_space *pspace = current_program_space;
c906108c 3420
50c71eaf
PA
3421 /* If breakpoint locations are shared across processes, then there's
3422 nothing to do. */
2567c7d9 3423 if (gdbarch_has_global_breakpoints (target_gdbarch))
50c71eaf
PA
3424 return;
3425
35df4500 3426 ALL_BP_LOCATIONS (bl, blp_tmp)
6c95b8df 3427 {
35df4500
TJB
3428 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3429 if (bl->pspace == pspace
3430 && bl->owner->enable_state != bp_permanent)
3431 bl->inserted = 0;
6c95b8df 3432 }
075f6582 3433
35df4500 3434 ALL_BREAKPOINTS_SAFE (b, b_tmp)
c5aa993b 3435 {
6c95b8df
PA
3436 if (b->loc && b->loc->pspace != pspace)
3437 continue;
3438
c5aa993b
JM
3439 switch (b->type)
3440 {
3441 case bp_call_dummy:
c906108c 3442
c5aa993b 3443 /* If the call dummy breakpoint is at the entry point it will
ab92d69b
PA
3444 cause problems when the inferior is rerun, so we better get
3445 rid of it. */
3446
3447 case bp_watchpoint_scope:
3448
3449 /* Also get rid of scope breakpoints. */
3450
3451 case bp_shlib_event:
3452
3453 /* Also remove solib event breakpoints. Their addresses may
3454 have changed since the last time we ran the program.
3455 Actually we may now be debugging against different target;
3456 and so the solib backend that installed this breakpoint may
3457 not be used in by the target. E.g.,
3458
3459 (gdb) file prog-linux
3460 (gdb) run # native linux target
3461 ...
3462 (gdb) kill
3463 (gdb) file prog-win.exe
3464 (gdb) tar rem :9999 # remote Windows gdbserver.
3465 */
c906108c 3466
f59f708a
PA
3467 case bp_step_resume:
3468
3469 /* Also remove step-resume breakpoints. */
3470
c5aa993b
JM
3471 delete_breakpoint (b);
3472 break;
c906108c 3473
c5aa993b
JM
3474 case bp_watchpoint:
3475 case bp_hardware_watchpoint:
3476 case bp_read_watchpoint:
3477 case bp_access_watchpoint:
3a5c3e22
PA
3478 {
3479 struct watchpoint *w = (struct watchpoint *) b;
c906108c 3480
3a5c3e22
PA
3481 /* Likewise for watchpoints on local expressions. */
3482 if (w->exp_valid_block != NULL)
3483 delete_breakpoint (b);
3484 else if (context == inf_starting)
3485 {
3486 /* Reset val field to force reread of starting value in
3487 insert_breakpoints. */
3488 if (w->val)
3489 value_free (w->val);
3490 w->val = NULL;
3491 w->val_valid = 0;
c860120c 3492 }
3a5c3e22 3493 }
c5aa993b
JM
3494 break;
3495 default:
c5aa993b
JM
3496 break;
3497 }
3498 }
1c5cfe86
PA
3499
3500 /* Get rid of the moribund locations. */
35df4500
TJB
3501 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix)
3502 decref_bp_location (&bl);
1c5cfe86 3503 VEC_free (bp_location_p, moribund_locations);
c906108c
SS
3504}
3505
6c95b8df
PA
3506/* These functions concern about actual breakpoints inserted in the
3507 target --- to e.g. check if we need to do decr_pc adjustment or if
3508 we need to hop over the bkpt --- so we check for address space
3509 match, not program space. */
3510
c2c6d25f
JM
3511/* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3512 exists at PC. It returns ordinary_breakpoint_here if it's an
3513 ordinary breakpoint, or permanent_breakpoint_here if it's a
3514 permanent breakpoint.
3515 - When continuing from a location with an ordinary breakpoint, we
3516 actually single step once before calling insert_breakpoints.
e5dd4106 3517 - When continuing from a location with a permanent breakpoint, we
c2c6d25f
JM
3518 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3519 the target, to advance the PC past the breakpoint. */
c906108c 3520
c2c6d25f 3521enum breakpoint_here
6c95b8df 3522breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
c906108c 3523{
35df4500 3524 struct bp_location *bl, **blp_tmp;
c2c6d25f 3525 int any_breakpoint_here = 0;
c906108c 3526
35df4500 3527 ALL_BP_LOCATIONS (bl, blp_tmp)
075f6582 3528 {
35df4500
TJB
3529 if (bl->loc_type != bp_loc_software_breakpoint
3530 && bl->loc_type != bp_loc_hardware_breakpoint)
075f6582
DJ
3531 continue;
3532
f1310107 3533 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
35df4500
TJB
3534 if ((breakpoint_enabled (bl->owner)
3535 || bl->owner->enable_state == bp_permanent)
f1310107 3536 && breakpoint_location_address_match (bl, aspace, pc))
075f6582
DJ
3537 {
3538 if (overlay_debugging
35df4500
TJB
3539 && section_is_overlay (bl->section)
3540 && !section_is_mapped (bl->section))
075f6582 3541 continue; /* unmapped overlay -- can't be a match */
35df4500 3542 else if (bl->owner->enable_state == bp_permanent)
075f6582
DJ
3543 return permanent_breakpoint_here;
3544 else
3545 any_breakpoint_here = 1;
3546 }
3547 }
c906108c 3548
c2c6d25f 3549 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
c906108c
SS
3550}
3551
1c5cfe86
PA
3552/* Return true if there's a moribund breakpoint at PC. */
3553
3554int
6c95b8df 3555moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
1c5cfe86
PA
3556{
3557 struct bp_location *loc;
3558 int ix;
3559
3560 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
f1310107 3561 if (breakpoint_location_address_match (loc, aspace, pc))
1c5cfe86
PA
3562 return 1;
3563
3564 return 0;
3565}
c2c6d25f 3566
c36b740a 3567/* Returns non-zero if there's a breakpoint inserted at PC, which is
4a64f543
MS
3568 inserted using regular breakpoint_chain / bp_location array
3569 mechanism. This does not check for single-step breakpoints, which
3570 are inserted and removed using direct target manipulation. */
c906108c
SS
3571
3572int
4a64f543
MS
3573regular_breakpoint_inserted_here_p (struct address_space *aspace,
3574 CORE_ADDR pc)
c906108c 3575{
35df4500 3576 struct bp_location *bl, **blp_tmp;
c906108c 3577
35df4500 3578 ALL_BP_LOCATIONS (bl, blp_tmp)
c5aa993b 3579 {
35df4500
TJB
3580 if (bl->loc_type != bp_loc_software_breakpoint
3581 && bl->loc_type != bp_loc_hardware_breakpoint)
075f6582
DJ
3582 continue;
3583
35df4500 3584 if (bl->inserted
f1310107 3585 && breakpoint_location_address_match (bl, aspace, pc))
075f6582
DJ
3586 {
3587 if (overlay_debugging
35df4500
TJB
3588 && section_is_overlay (bl->section)
3589 && !section_is_mapped (bl->section))
075f6582
DJ
3590 continue; /* unmapped overlay -- can't be a match */
3591 else
3592 return 1;
3593 }
c5aa993b 3594 }
c36b740a
VP
3595 return 0;
3596}
3597
3598/* Returns non-zero iff there's either regular breakpoint
3599 or a single step breakpoint inserted at PC. */
3600
3601int
6c95b8df 3602breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
c36b740a 3603{
6c95b8df 3604 if (regular_breakpoint_inserted_here_p (aspace, pc))
c36b740a 3605 return 1;
c906108c 3606
6c95b8df 3607 if (single_step_breakpoint_inserted_here_p (aspace, pc))
1aafd4da
UW
3608 return 1;
3609
c906108c
SS
3610 return 0;
3611}
3612
4fa8626c
DJ
3613/* This function returns non-zero iff there is a software breakpoint
3614 inserted at PC. */
3615
3616int
3e43a32a
MS
3617software_breakpoint_inserted_here_p (struct address_space *aspace,
3618 CORE_ADDR pc)
4fa8626c 3619{
35df4500 3620 struct bp_location *bl, **blp_tmp;
4fa8626c 3621
35df4500 3622 ALL_BP_LOCATIONS (bl, blp_tmp)
4fa8626c 3623 {
35df4500 3624 if (bl->loc_type != bp_loc_software_breakpoint)
4fa8626c
DJ
3625 continue;
3626
35df4500
TJB
3627 if (bl->inserted
3628 && breakpoint_address_match (bl->pspace->aspace, bl->address,
6c95b8df 3629 aspace, pc))
4fa8626c
DJ
3630 {
3631 if (overlay_debugging
35df4500
TJB
3632 && section_is_overlay (bl->section)
3633 && !section_is_mapped (bl->section))
4fa8626c
DJ
3634 continue; /* unmapped overlay -- can't be a match */
3635 else
3636 return 1;
3637 }
3638 }
3639
1aafd4da 3640 /* Also check for software single-step breakpoints. */
6c95b8df 3641 if (single_step_breakpoint_inserted_here_p (aspace, pc))
1aafd4da
UW
3642 return 1;
3643
4fa8626c
DJ
3644 return 0;
3645}
3646
9093389c
PA
3647int
3648hardware_watchpoint_inserted_in_range (struct address_space *aspace,
3649 CORE_ADDR addr, ULONGEST len)
3650{
3651 struct breakpoint *bpt;
3652
3653 ALL_BREAKPOINTS (bpt)
3654 {
3655 struct bp_location *loc;
3656
3657 if (bpt->type != bp_hardware_watchpoint
3658 && bpt->type != bp_access_watchpoint)
3659 continue;
3660
3661 if (!breakpoint_enabled (bpt))
3662 continue;
3663
3664 for (loc = bpt->loc; loc; loc = loc->next)
3665 if (loc->pspace->aspace == aspace && loc->inserted)
3666 {
3667 CORE_ADDR l, h;
3668
3669 /* Check for intersection. */
3670 l = max (loc->address, addr);
3671 h = min (loc->address + loc->length, addr + len);
3672 if (l < h)
3673 return 1;
3674 }
3675 }
3676 return 0;
3677}
3678
075f6582
DJ
3679/* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3680 PC is valid for process/thread PTID. */
c906108c
SS
3681
3682int
6c95b8df
PA
3683breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc,
3684 ptid_t ptid)
c906108c 3685{
35df4500 3686 struct bp_location *bl, **blp_tmp;
4a306c9a 3687 /* The thread and task IDs associated to PTID, computed lazily. */
a6f1cd96 3688 int thread = -1;
4a306c9a 3689 int task = 0;
a6f1cd96 3690
35df4500 3691 ALL_BP_LOCATIONS (bl, blp_tmp)
c5aa993b 3692 {
35df4500
TJB
3693 if (bl->loc_type != bp_loc_software_breakpoint
3694 && bl->loc_type != bp_loc_hardware_breakpoint)
075f6582
DJ
3695 continue;
3696
35df4500
TJB
3697 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3698 if (!breakpoint_enabled (bl->owner)
3699 && bl->owner->enable_state != bp_permanent)
a6f1cd96
JB
3700 continue;
3701
f1310107 3702 if (!breakpoint_location_address_match (bl, aspace, pc))
a6f1cd96
JB
3703 continue;
3704
35df4500 3705 if (bl->owner->thread != -1)
075f6582 3706 {
a6f1cd96
JB
3707 /* This is a thread-specific breakpoint. Check that ptid
3708 matches that thread. If thread hasn't been computed yet,
3709 it is now time to do so. */
3710 if (thread == -1)
3711 thread = pid_to_thread_id (ptid);
35df4500 3712 if (bl->owner->thread != thread)
a6f1cd96 3713 continue;
075f6582 3714 }
a6f1cd96 3715
35df4500 3716 if (bl->owner->task != 0)
4a306c9a
JB
3717 {
3718 /* This is a task-specific breakpoint. Check that ptid
3719 matches that task. If task hasn't been computed yet,
3720 it is now time to do so. */
3721 if (task == 0)
3722 task = ada_get_task_number (ptid);
35df4500 3723 if (bl->owner->task != task)
4a306c9a
JB
3724 continue;
3725 }
3726
a6f1cd96 3727 if (overlay_debugging
35df4500
TJB
3728 && section_is_overlay (bl->section)
3729 && !section_is_mapped (bl->section))
a6f1cd96
JB
3730 continue; /* unmapped overlay -- can't be a match */
3731
3732 return 1;
c5aa993b 3733 }
c906108c
SS
3734
3735 return 0;
3736}
c906108c 3737\f
c5aa993b 3738
c906108c
SS
3739/* bpstat stuff. External routines' interfaces are documented
3740 in breakpoint.h. */
3741
3742int
c326b90e 3743is_catchpoint (struct breakpoint *ep)
c906108c 3744{
533be4dd 3745 return (ep->type == bp_catchpoint);
c906108c
SS
3746}
3747
f431efe5
PA
3748/* Frees any storage that is part of a bpstat. Does not walk the
3749 'next' chain. */
3750
3751static void
198757a8
VP
3752bpstat_free (bpstat bs)
3753{
3754 if (bs->old_val != NULL)
3755 value_free (bs->old_val);
9add0f1b 3756 decref_counted_command_line (&bs->commands);
f431efe5 3757 decref_bp_location (&bs->bp_location_at);
198757a8
VP
3758 xfree (bs);
3759}
3760
c906108c
SS
3761/* Clear a bpstat so that it says we are not at any breakpoint.
3762 Also free any storage that is part of a bpstat. */
3763
3764void
fba45db2 3765bpstat_clear (bpstat *bsp)
c906108c
SS
3766{
3767 bpstat p;
3768 bpstat q;
3769
3770 if (bsp == 0)
3771 return;
3772 p = *bsp;
3773 while (p != NULL)
3774 {
3775 q = p->next;
198757a8 3776 bpstat_free (p);
c906108c
SS
3777 p = q;
3778 }
3779 *bsp = NULL;
3780}
3781
3782/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3783 is part of the bpstat is copied as well. */
3784
3785bpstat
fba45db2 3786bpstat_copy (bpstat bs)
c906108c
SS
3787{
3788 bpstat p = NULL;
3789 bpstat tmp;
3790 bpstat retval = NULL;
3791
3792 if (bs == NULL)
3793 return bs;
3794
3795 for (; bs != NULL; bs = bs->next)
3796 {
3797 tmp = (bpstat) xmalloc (sizeof (*tmp));
3798 memcpy (tmp, bs, sizeof (*tmp));
9add0f1b 3799 incref_counted_command_line (tmp->commands);
f431efe5 3800 incref_bp_location (tmp->bp_location_at);
31cc81e9 3801 if (bs->old_val != NULL)
3c3185ac
JK
3802 {
3803 tmp->old_val = value_copy (bs->old_val);
3804 release_value (tmp->old_val);
3805 }
31cc81e9 3806
c906108c
SS
3807 if (p == NULL)
3808 /* This is the first thing in the chain. */
3809 retval = tmp;
3810 else
3811 p->next = tmp;
3812 p = tmp;
3813 }
3814 p->next = NULL;
3815 return retval;
3816}
3817
4a64f543 3818/* Find the bpstat associated with this breakpoint. */
c906108c
SS
3819
3820bpstat
fba45db2 3821bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
c906108c 3822{
c5aa993b
JM
3823 if (bsp == NULL)
3824 return NULL;
c906108c 3825
c5aa993b
JM
3826 for (; bsp != NULL; bsp = bsp->next)
3827 {
f431efe5 3828 if (bsp->breakpoint_at == breakpoint)
c5aa993b
JM
3829 return bsp;
3830 }
c906108c
SS
3831 return NULL;
3832}
3833
4a64f543
MS
3834/* Put in *NUM the breakpoint number of the first breakpoint we are
3835 stopped at. *BSP upon return is a bpstat which points to the
3836 remaining breakpoints stopped at (but which is not guaranteed to be
3837 good for anything but further calls to bpstat_num).
3838
8671a17b
PA
3839 Return 0 if passed a bpstat which does not indicate any breakpoints.
3840 Return -1 if stopped at a breakpoint that has been deleted since
3841 we set it.
3842 Return 1 otherwise. */
c906108c
SS
3843
3844int
8671a17b 3845bpstat_num (bpstat *bsp, int *num)
c906108c
SS
3846{
3847 struct breakpoint *b;
3848
3849 if ((*bsp) == NULL)
3850 return 0; /* No more breakpoint values */
8671a17b 3851
4a64f543
MS
3852 /* We assume we'll never have several bpstats that correspond to a
3853 single breakpoint -- otherwise, this function might return the
3854 same number more than once and this will look ugly. */
f431efe5 3855 b = (*bsp)->breakpoint_at;
8671a17b
PA
3856 *bsp = (*bsp)->next;
3857 if (b == NULL)
3858 return -1; /* breakpoint that's been deleted since */
3859
3860 *num = b->number; /* We have its number */
3861 return 1;
c906108c
SS
3862}
3863
e93ca019 3864/* See breakpoint.h. */
c906108c
SS
3865
3866void
e93ca019 3867bpstat_clear_actions (void)
c906108c 3868{
e93ca019
JK
3869 struct thread_info *tp;
3870 bpstat bs;
3871
3872 if (ptid_equal (inferior_ptid, null_ptid))
3873 return;
3874
3875 tp = find_thread_ptid (inferior_ptid);
3876 if (tp == NULL)
3877 return;
3878
3879 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
c906108c 3880 {
9add0f1b 3881 decref_counted_command_line (&bs->commands);
abf85f46 3882
c906108c
SS
3883 if (bs->old_val != NULL)
3884 {
3885 value_free (bs->old_val);
3886 bs->old_val = NULL;
3887 }
3888 }
3889}
3890
f3b1572e
PA
3891/* Called when a command is about to proceed the inferior. */
3892
3893static void
3894breakpoint_about_to_proceed (void)
3895{
3896 if (!ptid_equal (inferior_ptid, null_ptid))
3897 {
3898 struct thread_info *tp = inferior_thread ();
3899
3900 /* Allow inferior function calls in breakpoint commands to not
3901 interrupt the command list. When the call finishes
3902 successfully, the inferior will be standing at the same
3903 breakpoint as if nothing happened. */
16c381f0 3904 if (tp->control.in_infcall)
f3b1572e
PA
3905 return;
3906 }
3907
3908 breakpoint_proceeded = 1;
3909}
3910
4a64f543
MS
3911/* Stub for cleaning up our state if we error-out of a breakpoint
3912 command. */
c906108c 3913static void
4efb68b1 3914cleanup_executing_breakpoints (void *ignore)
c906108c
SS
3915{
3916 executing_breakpoint_commands = 0;
3917}
3918
abf85f46
JK
3919/* Return non-zero iff CMD as the first line of a command sequence is `silent'
3920 or its equivalent. */
3921
3922static int
3923command_line_is_silent (struct command_line *cmd)
3924{
3925 return cmd && (strcmp ("silent", cmd->line) == 0
3926 || (xdb_commands && strcmp ("Q", cmd->line) == 0));
3927}
3928
4a64f543
MS
3929/* Execute all the commands associated with all the breakpoints at
3930 this location. Any of these commands could cause the process to
3931 proceed beyond this point, etc. We look out for such changes by
3932 checking the global "breakpoint_proceeded" after each command.
c906108c 3933
347bddb7
PA
3934 Returns true if a breakpoint command resumed the inferior. In that
3935 case, it is the caller's responsibility to recall it again with the
3936 bpstat of the current thread. */
3937
3938static int
3939bpstat_do_actions_1 (bpstat *bsp)
c906108c
SS
3940{
3941 bpstat bs;
3942 struct cleanup *old_chain;
347bddb7 3943 int again = 0;
c906108c
SS
3944
3945 /* Avoid endless recursion if a `source' command is contained
3946 in bs->commands. */
3947 if (executing_breakpoint_commands)
347bddb7 3948 return 0;
c906108c
SS
3949
3950 executing_breakpoint_commands = 1;
3951 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
3952
cf6c5ffb
TT
3953 prevent_dont_repeat ();
3954
4a64f543 3955 /* This pointer will iterate over the list of bpstat's. */
c906108c
SS
3956 bs = *bsp;
3957
3958 breakpoint_proceeded = 0;
3959 for (; bs != NULL; bs = bs->next)
3960 {
9add0f1b 3961 struct counted_command_line *ccmd;
6c50ab1c
JB
3962 struct command_line *cmd;
3963 struct cleanup *this_cmd_tree_chain;
3964
3965 /* Take ownership of the BSP's command tree, if it has one.
3966
3967 The command tree could legitimately contain commands like
3968 'step' and 'next', which call clear_proceed_status, which
3969 frees stop_bpstat's command tree. To make sure this doesn't
3970 free the tree we're executing out from under us, we need to
3971 take ownership of the tree ourselves. Since a given bpstat's
3972 commands are only executed once, we don't need to copy it; we
3973 can clear the pointer in the bpstat, and make sure we free
3974 the tree when we're done. */
9add0f1b
TT
3975 ccmd = bs->commands;
3976 bs->commands = NULL;
abf85f46
JK
3977 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd);
3978 cmd = ccmd ? ccmd->commands : NULL;
3979 if (command_line_is_silent (cmd))
3980 {
3981 /* The action has been already done by bpstat_stop_status. */
3982 cmd = cmd->next;
3983 }
6c50ab1c 3984
c906108c
SS
3985 while (cmd != NULL)
3986 {
3987 execute_control_command (cmd);
3988
3989 if (breakpoint_proceeded)
3990 break;
3991 else
3992 cmd = cmd->next;
3993 }
6c50ab1c
JB
3994
3995 /* We can free this command tree now. */
3996 do_cleanups (this_cmd_tree_chain);
3997
c906108c 3998 if (breakpoint_proceeded)
32c1e744
VP
3999 {
4000 if (target_can_async_p ())
347bddb7
PA
4001 /* If we are in async mode, then the target might be still
4002 running, not stopped at any breakpoint, so nothing for
4003 us to do here -- just return to the event loop. */
4004 ;
32c1e744
VP
4005 else
4006 /* In sync mode, when execute_control_command returns
4007 we're already standing on the next breakpoint.
347bddb7
PA
4008 Breakpoint commands for that stop were not run, since
4009 execute_command does not run breakpoint commands --
4010 only command_line_handler does, but that one is not
4011 involved in execution of breakpoint commands. So, we
4012 can now execute breakpoint commands. It should be
4013 noted that making execute_command do bpstat actions is
4014 not an option -- in this case we'll have recursive
4015 invocation of bpstat for each breakpoint with a
4016 command, and can easily blow up GDB stack. Instead, we
4017 return true, which will trigger the caller to recall us
4018 with the new stop_bpstat. */
4019 again = 1;
4020 break;
32c1e744 4021 }
c906108c 4022 }
c2b8ed2c 4023 do_cleanups (old_chain);
347bddb7
PA
4024 return again;
4025}
4026
4027void
4028bpstat_do_actions (void)
4029{
353d1d73
JK
4030 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
4031
347bddb7
PA
4032 /* Do any commands attached to breakpoint we are stopped at. */
4033 while (!ptid_equal (inferior_ptid, null_ptid)
4034 && target_has_execution
4035 && !is_exited (inferior_ptid)
4036 && !is_executing (inferior_ptid))
4037 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4038 and only return when it is stopped at the next breakpoint, we
4039 keep doing breakpoint actions until it returns false to
4040 indicate the inferior was not resumed. */
16c381f0 4041 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
347bddb7 4042 break;
353d1d73
JK
4043
4044 discard_cleanups (cleanup_if_error);
c906108c
SS
4045}
4046
fa4727a6
DJ
4047/* Print out the (old or new) value associated with a watchpoint. */
4048
4049static void
4050watchpoint_value_print (struct value *val, struct ui_file *stream)
4051{
4052 if (val == NULL)
4053 fprintf_unfiltered (stream, _("<unreadable>"));
4054 else
79a45b7d
TT
4055 {
4056 struct value_print_options opts;
4057 get_user_print_options (&opts);
4058 value_print (val, stream, &opts);
4059 }
fa4727a6
DJ
4060}
4061
e514a9d6 4062/* Generic routine for printing messages indicating why we
4a64f543 4063 stopped. The behavior of this function depends on the value
e514a9d6
JM
4064 'print_it' in the bpstat structure. Under some circumstances we
4065 may decide not to print anything here and delegate the task to
4a64f543 4066 normal_stop(). */
e514a9d6
JM
4067
4068static enum print_stop_action
4069print_bp_stop_message (bpstat bs)
4070{
4071 switch (bs->print_it)
4072 {
4073 case print_it_noop:
4a64f543 4074 /* Nothing should be printed for this bpstat entry. */
e514a9d6
JM
4075 return PRINT_UNKNOWN;
4076 break;
4077
4078 case print_it_done:
4079 /* We still want to print the frame, but we already printed the
4a64f543 4080 relevant messages. */
e514a9d6
JM
4081 return PRINT_SRC_AND_LOC;
4082 break;
4083
4084 case print_it_normal:
4f8d1dc6 4085 {
f431efe5
PA
4086 struct breakpoint *b = bs->breakpoint_at;
4087
1a6a67de
TJB
4088 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4089 which has since been deleted. */
4090 if (b == NULL)
4091 return PRINT_UNKNOWN;
4092
348d480f
PA
4093 /* Normal case. Call the breakpoint's print_it method. */
4094 return b->ops->print_it (bs);
4f8d1dc6 4095 }
348d480f 4096 break;
3086aeae 4097
e514a9d6 4098 default:
8e65ff28 4099 internal_error (__FILE__, __LINE__,
e2e0b3e5 4100 _("print_bp_stop_message: unrecognized enum value"));
e514a9d6 4101 break;
c906108c 4102 }
c906108c
SS
4103}
4104
edcc5120
TT
4105/* A helper function that prints a shared library stopped event. */
4106
4107static void
4108print_solib_event (int is_catchpoint)
4109{
4110 int any_deleted
4111 = !VEC_empty (char_ptr, current_program_space->deleted_solibs);
4112 int any_added
4113 = !VEC_empty (so_list_ptr, current_program_space->added_solibs);
4114
4115 if (!is_catchpoint)
4116 {
4117 if (any_added || any_deleted)
4118 ui_out_text (current_uiout,
4119 _("Stopped due to shared library event:\n"));
4120 else
4121 ui_out_text (current_uiout,
4122 _("Stopped due to shared library event (no "
4123 "libraries added or removed)\n"));
4124 }
4125
4126 if (ui_out_is_mi_like_p (current_uiout))
4127 ui_out_field_string (current_uiout, "reason",
4128 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
4129
4130 if (any_deleted)
4131 {
4132 struct cleanup *cleanup;
4133 char *name;
4134 int ix;
4135
4136 ui_out_text (current_uiout, _(" Inferior unloaded "));
4137 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4138 "removed");
4139 for (ix = 0;
4140 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
4141 ix, name);
4142 ++ix)
4143 {
4144 if (ix > 0)
4145 ui_out_text (current_uiout, " ");
4146 ui_out_field_string (current_uiout, "library", name);
4147 ui_out_text (current_uiout, "\n");
4148 }
4149
4150 do_cleanups (cleanup);
4151 }
4152
4153 if (any_added)
4154 {
4155 struct so_list *iter;
4156 int ix;
4157 struct cleanup *cleanup;
4158
4159 ui_out_text (current_uiout, _(" Inferior loaded "));
4160 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout,
4161 "added");
4162 for (ix = 0;
4163 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
4164 ix, iter);
4165 ++ix)
4166 {
4167 if (ix > 0)
4168 ui_out_text (current_uiout, " ");
4169 ui_out_field_string (current_uiout, "library", iter->so_name);
4170 ui_out_text (current_uiout, "\n");
4171 }
4172
4173 do_cleanups (cleanup);
4174 }
4175}
4176
e514a9d6
JM
4177/* Print a message indicating what happened. This is called from
4178 normal_stop(). The input to this routine is the head of the bpstat
36dfb11c
TT
4179 list - a list of the eventpoints that caused this stop. KIND is
4180 the target_waitkind for the stopping event. This
e514a9d6
JM
4181 routine calls the generic print routine for printing a message
4182 about reasons for stopping. This will print (for example) the
4183 "Breakpoint n," part of the output. The return value of this
4184 routine is one of:
c906108c 4185
4a64f543 4186 PRINT_UNKNOWN: Means we printed nothing.
917317f4 4187 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4a64f543 4188 code to print the location. An example is
c5aa993b
JM
4189 "Breakpoint 1, " which should be followed by
4190 the location.
917317f4 4191 PRINT_SRC_ONLY: Means we printed something, but there is no need
c5aa993b
JM
4192 to also print the location part of the message.
4193 An example is the catch/throw messages, which
4a64f543 4194 don't require a location appended to the end.
917317f4 4195 PRINT_NOTHING: We have done some printing and we don't need any
4a64f543 4196 further info to be printed. */
c906108c 4197
917317f4 4198enum print_stop_action
36dfb11c 4199bpstat_print (bpstat bs, int kind)
c906108c
SS
4200{
4201 int val;
c5aa993b 4202
c906108c 4203 /* Maybe another breakpoint in the chain caused us to stop.
53a5351d
JM
4204 (Currently all watchpoints go on the bpstat whether hit or not.
4205 That probably could (should) be changed, provided care is taken
c906108c 4206 with respect to bpstat_explains_signal). */
e514a9d6
JM
4207 for (; bs; bs = bs->next)
4208 {
4209 val = print_bp_stop_message (bs);
4210 if (val == PRINT_SRC_ONLY
4211 || val == PRINT_SRC_AND_LOC
4212 || val == PRINT_NOTHING)
4213 return val;
4214 }
c906108c 4215
36dfb11c
TT
4216 /* If we had hit a shared library event breakpoint,
4217 print_bp_stop_message would print out this message. If we hit an
4218 OS-level shared library event, do the same thing. */
4219 if (kind == TARGET_WAITKIND_LOADED)
4220 {
edcc5120 4221 print_solib_event (0);
36dfb11c
TT
4222 return PRINT_NOTHING;
4223 }
4224
e514a9d6 4225 /* We reached the end of the chain, or we got a null BS to start
4a64f543 4226 with and nothing was printed. */
917317f4 4227 return PRINT_UNKNOWN;
c906108c
SS
4228}
4229
4a64f543
MS
4230/* Evaluate the expression EXP and return 1 if value is zero. This is
4231 used inside a catch_errors to evaluate the breakpoint condition.
4232 The argument is a "struct expression *" that has been cast to a
4233 "char *" to make it pass through catch_errors. */
c906108c
SS
4234
4235static int
4efb68b1 4236breakpoint_cond_eval (void *exp)
c906108c 4237{
278cd55f 4238 struct value *mark = value_mark ();
c5aa993b 4239 int i = !value_true (evaluate_expression ((struct expression *) exp));
cc59ec59 4240
c906108c
SS
4241 value_free_to_mark (mark);
4242 return i;
4243}
4244
5760d0ab 4245/* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
c906108c
SS
4246
4247static bpstat
5760d0ab 4248bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer)
c906108c
SS
4249{
4250 bpstat bs;
4251
4252 bs = (bpstat) xmalloc (sizeof (*bs));
5760d0ab
JK
4253 bs->next = NULL;
4254 **bs_link_pointer = bs;
4255 *bs_link_pointer = &bs->next;
f431efe5
PA
4256 bs->breakpoint_at = bl->owner;
4257 bs->bp_location_at = bl;
4258 incref_bp_location (bl);
c906108c
SS
4259 /* If the condition is false, etc., don't do the commands. */
4260 bs->commands = NULL;
4261 bs->old_val = NULL;
4262 bs->print_it = print_it_normal;
4263 return bs;
4264}
4265\f
d983da9c
DJ
4266/* The target has stopped with waitstatus WS. Check if any hardware
4267 watchpoints have triggered, according to the target. */
4268
4269int
4270watchpoints_triggered (struct target_waitstatus *ws)
4271{
d92524f1 4272 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
d983da9c
DJ
4273 CORE_ADDR addr;
4274 struct breakpoint *b;
4275
4276 if (!stopped_by_watchpoint)
4277 {
4278 /* We were not stopped by a watchpoint. Mark all watchpoints
4279 as not triggered. */
4280 ALL_BREAKPOINTS (b)
cc60f2e3 4281 if (is_hardware_watchpoint (b))
3a5c3e22
PA
4282 {
4283 struct watchpoint *w = (struct watchpoint *) b;
4284
4285 w->watchpoint_triggered = watch_triggered_no;
4286 }
d983da9c
DJ
4287
4288 return 0;
4289 }
4290
4291 if (!target_stopped_data_address (&current_target, &addr))
4292 {
4293 /* We were stopped by a watchpoint, but we don't know where.
4294 Mark all watchpoints as unknown. */
4295 ALL_BREAKPOINTS (b)
cc60f2e3 4296 if (is_hardware_watchpoint (b))
3a5c3e22
PA
4297 {
4298 struct watchpoint *w = (struct watchpoint *) b;
4299
4300 w->watchpoint_triggered = watch_triggered_unknown;
4301 }
d983da9c
DJ
4302
4303 return stopped_by_watchpoint;
4304 }
4305
4306 /* The target could report the data address. Mark watchpoints
4307 affected by this data address as triggered, and all others as not
4308 triggered. */
4309
4310 ALL_BREAKPOINTS (b)
cc60f2e3 4311 if (is_hardware_watchpoint (b))
d983da9c 4312 {
3a5c3e22 4313 struct watchpoint *w = (struct watchpoint *) b;
a5606eee 4314 struct bp_location *loc;
d983da9c 4315
3a5c3e22 4316 w->watchpoint_triggered = watch_triggered_no;
a5606eee 4317 for (loc = b->loc; loc; loc = loc->next)
9c06b0b4 4318 {
3a5c3e22 4319 if (is_masked_watchpoint (b))
9c06b0b4 4320 {
3a5c3e22
PA
4321 CORE_ADDR newaddr = addr & w->hw_wp_mask;
4322 CORE_ADDR start = loc->address & w->hw_wp_mask;
9c06b0b4
TJB
4323
4324 if (newaddr == start)
4325 {
3a5c3e22 4326 w->watchpoint_triggered = watch_triggered_yes;
9c06b0b4
TJB
4327 break;
4328 }
4329 }
4330 /* Exact match not required. Within range is sufficient. */
4331 else if (target_watchpoint_addr_within_range (&current_target,
4332 addr, loc->address,
4333 loc->length))
4334 {
3a5c3e22 4335 w->watchpoint_triggered = watch_triggered_yes;
9c06b0b4
TJB
4336 break;
4337 }
4338 }
d983da9c
DJ
4339 }
4340
4341 return 1;
4342}
4343
c906108c
SS
4344/* Possible return values for watchpoint_check (this can't be an enum
4345 because of check_errors). */
4346/* The watchpoint has been deleted. */
4347#define WP_DELETED 1
4348/* The value has changed. */
4349#define WP_VALUE_CHANGED 2
4350/* The value has not changed. */
4351#define WP_VALUE_NOT_CHANGED 3
60e1c644
PA
4352/* Ignore this watchpoint, no matter if the value changed or not. */
4353#define WP_IGNORE 4
c906108c
SS
4354
4355#define BP_TEMPFLAG 1
4356#define BP_HARDWAREFLAG 2
4357
4a64f543
MS
4358/* Evaluate watchpoint condition expression and check if its value
4359 changed.
553e4c11
JB
4360
4361 P should be a pointer to struct bpstat, but is defined as a void *
4362 in order for this function to be usable with catch_errors. */
c906108c
SS
4363
4364static int
4efb68b1 4365watchpoint_check (void *p)
c906108c
SS
4366{
4367 bpstat bs = (bpstat) p;
3a5c3e22 4368 struct watchpoint *b;
c906108c
SS
4369 struct frame_info *fr;
4370 int within_current_scope;
4371
f431efe5 4372 /* BS is built from an existing struct breakpoint. */
2bdf28a0 4373 gdb_assert (bs->breakpoint_at != NULL);
3a5c3e22 4374 b = (struct watchpoint *) bs->breakpoint_at;
d0fb5eae 4375
f6bc2008
PA
4376 /* If this is a local watchpoint, we only want to check if the
4377 watchpoint frame is in scope if the current thread is the thread
4378 that was used to create the watchpoint. */
4379 if (!watchpoint_in_thread_scope (b))
60e1c644 4380 return WP_IGNORE;
f6bc2008 4381
c906108c
SS
4382 if (b->exp_valid_block == NULL)
4383 within_current_scope = 1;
4384 else
4385 {
edb3359d
DJ
4386 struct frame_info *frame = get_current_frame ();
4387 struct gdbarch *frame_arch = get_frame_arch (frame);
4388 CORE_ADDR frame_pc = get_frame_pc (frame);
4389
4a64f543
MS
4390 /* in_function_epilogue_p() returns a non-zero value if we're
4391 still in the function but the stack frame has already been
4392 invalidated. Since we can't rely on the values of local
4393 variables after the stack has been destroyed, we are treating
4394 the watchpoint in that state as `not changed' without further
4395 checking. Don't mark watchpoints as changed if the current
4396 frame is in an epilogue - even if they are in some other
4397 frame, our view of the stack is likely to be wrong and
4398 frame_find_by_id could error out. */
a0f49112 4399 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
60e1c644 4400 return WP_IGNORE;
a0f49112 4401
101dcfbe 4402 fr = frame_find_by_id (b->watchpoint_frame);
c906108c 4403 within_current_scope = (fr != NULL);
69fbadd5
DJ
4404
4405 /* If we've gotten confused in the unwinder, we might have
4406 returned a frame that can't describe this variable. */
edb3359d
DJ
4407 if (within_current_scope)
4408 {
4409 struct symbol *function;
4410
4411 function = get_frame_function (fr);
4412 if (function == NULL
4413 || !contained_in (b->exp_valid_block,
4414 SYMBOL_BLOCK_VALUE (function)))
4415 within_current_scope = 0;
4416 }
69fbadd5 4417
edb3359d 4418 if (within_current_scope)
c906108c
SS
4419 /* If we end up stopping, the current frame will get selected
4420 in normal_stop. So this call to select_frame won't affect
4421 the user. */
0f7d239c 4422 select_frame (fr);
c906108c 4423 }
c5aa993b 4424
c906108c
SS
4425 if (within_current_scope)
4426 {
4a64f543
MS
4427 /* We use value_{,free_to_}mark because it could be a *long*
4428 time before we return to the command level and call
4429 free_all_values. We can't call free_all_values because we
4430 might be in the middle of evaluating a function call. */
c906108c 4431
0cf6dd15 4432 int pc = 0;
9c06b0b4 4433 struct value *mark;
fa4727a6
DJ
4434 struct value *new_val;
4435
3a5c3e22 4436 if (is_masked_watchpoint (&b->base))
9c06b0b4
TJB
4437 /* Since we don't know the exact trigger address (from
4438 stopped_data_address), just tell the user we've triggered
4439 a mask watchpoint. */
4440 return WP_VALUE_CHANGED;
4441
4442 mark = value_mark ();
0cf6dd15 4443 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL);
218d2fc6 4444
4a64f543
MS
4445 /* We use value_equal_contents instead of value_equal because
4446 the latter coerces an array to a pointer, thus comparing just
4447 the address of the array instead of its contents. This is
4448 not what we want. */
fa4727a6 4449 if ((b->val != NULL) != (new_val != NULL)
218d2fc6 4450 || (b->val != NULL && !value_equal_contents (b->val, new_val)))
c906108c 4451 {
fa4727a6
DJ
4452 if (new_val != NULL)
4453 {
4454 release_value (new_val);
4455 value_free_to_mark (mark);
4456 }
c906108c
SS
4457 bs->old_val = b->val;
4458 b->val = new_val;
fa4727a6 4459 b->val_valid = 1;
c906108c
SS
4460 return WP_VALUE_CHANGED;
4461 }
4462 else
4463 {
60e1c644 4464 /* Nothing changed. */
c906108c 4465 value_free_to_mark (mark);
c906108c
SS
4466 return WP_VALUE_NOT_CHANGED;
4467 }
4468 }
4469 else
4470 {
79a45e25
PA
4471 struct ui_out *uiout = current_uiout;
4472
c906108c 4473 /* This seems like the only logical thing to do because
c5aa993b
JM
4474 if we temporarily ignored the watchpoint, then when
4475 we reenter the block in which it is valid it contains
4476 garbage (in the case of a function, it may have two
4477 garbage values, one before and one after the prologue).
4478 So we can't even detect the first assignment to it and
4479 watch after that (since the garbage may or may not equal
4480 the first value assigned). */
348d480f
PA
4481 /* We print all the stop information in
4482 breakpoint_ops->print_it, but in this case, by the time we
4483 call breakpoint_ops->print_it this bp will be deleted
4484 already. So we have no choice but print the information
4485 here. */
9dc5e2a9 4486 if (ui_out_is_mi_like_p (uiout))
034dad6f
BR
4487 ui_out_field_string
4488 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
8b93c638 4489 ui_out_text (uiout, "\nWatchpoint ");
3a5c3e22 4490 ui_out_field_int (uiout, "wpnum", b->base.number);
3e43a32a
MS
4491 ui_out_text (uiout,
4492 " deleted because the program has left the block in\n\
8b93c638 4493which its expression is valid.\n");
4ce44c66 4494
cdac0397 4495 /* Make sure the watchpoint's commands aren't executed. */
3a5c3e22 4496 decref_counted_command_line (&b->base.commands);
d0fb5eae 4497 watchpoint_del_at_next_stop (b);
c906108c
SS
4498
4499 return WP_DELETED;
4500 }
4501}
4502
18a18393 4503/* Return true if it looks like target has stopped due to hitting
348d480f
PA
4504 breakpoint location BL. This function does not check if we should
4505 stop, only if BL explains the stop. */
4506
18a18393 4507static int
6c95b8df 4508bpstat_check_location (const struct bp_location *bl,
09ac7c10
TT
4509 struct address_space *aspace, CORE_ADDR bp_addr,
4510 const struct target_waitstatus *ws)
18a18393
VP
4511{
4512 struct breakpoint *b = bl->owner;
4513
348d480f 4514 /* BL is from an existing breakpoint. */
2bdf28a0
JK
4515 gdb_assert (b != NULL);
4516
09ac7c10 4517 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws);
18a18393
VP
4518}
4519
3a5c3e22
PA
4520/* Determine if the watched values have actually changed, and we
4521 should stop. If not, set BS->stop to 0. */
4522
18a18393
VP
4523static void
4524bpstat_check_watchpoint (bpstat bs)
4525{
2bdf28a0 4526 const struct bp_location *bl;
3a5c3e22 4527 struct watchpoint *b;
2bdf28a0
JK
4528
4529 /* BS is built for existing struct breakpoint. */
f431efe5 4530 bl = bs->bp_location_at;
2bdf28a0 4531 gdb_assert (bl != NULL);
3a5c3e22 4532 b = (struct watchpoint *) bs->breakpoint_at;
2bdf28a0 4533 gdb_assert (b != NULL);
18a18393 4534
18a18393 4535 {
18a18393
VP
4536 int must_check_value = 0;
4537
3a5c3e22 4538 if (b->base.type == bp_watchpoint)
18a18393
VP
4539 /* For a software watchpoint, we must always check the
4540 watched value. */
4541 must_check_value = 1;
4542 else if (b->watchpoint_triggered == watch_triggered_yes)
4543 /* We have a hardware watchpoint (read, write, or access)
4544 and the target earlier reported an address watched by
4545 this watchpoint. */
4546 must_check_value = 1;
4547 else if (b->watchpoint_triggered == watch_triggered_unknown
3a5c3e22 4548 && b->base.type == bp_hardware_watchpoint)
18a18393
VP
4549 /* We were stopped by a hardware watchpoint, but the target could
4550 not report the data address. We must check the watchpoint's
4551 value. Access and read watchpoints are out of luck; without
4552 a data address, we can't figure it out. */
4553 must_check_value = 1;
3a5c3e22 4554
18a18393
VP
4555 if (must_check_value)
4556 {
3e43a32a
MS
4557 char *message
4558 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3a5c3e22 4559 b->base.number);
18a18393
VP
4560 struct cleanup *cleanups = make_cleanup (xfree, message);
4561 int e = catch_errors (watchpoint_check, bs, message,
4562 RETURN_MASK_ALL);
4563 do_cleanups (cleanups);
4564 switch (e)
4565 {
4566 case WP_DELETED:
4567 /* We've already printed what needs to be printed. */
4568 bs->print_it = print_it_done;
4569 /* Stop. */
4570 break;
60e1c644
PA
4571 case WP_IGNORE:
4572 bs->print_it = print_it_noop;
4573 bs->stop = 0;
4574 break;
18a18393 4575 case WP_VALUE_CHANGED:
3a5c3e22 4576 if (b->base.type == bp_read_watchpoint)
18a18393 4577 {
85d721b8
PA
4578 /* There are two cases to consider here:
4579
4a64f543 4580 1. We're watching the triggered memory for reads.
85d721b8
PA
4581 In that case, trust the target, and always report
4582 the watchpoint hit to the user. Even though
4583 reads don't cause value changes, the value may
4584 have changed since the last time it was read, and
4585 since we're not trapping writes, we will not see
4586 those, and as such we should ignore our notion of
4587 old value.
4588
4a64f543 4589 2. We're watching the triggered memory for both
85d721b8
PA
4590 reads and writes. There are two ways this may
4591 happen:
4592
4a64f543 4593 2.1. This is a target that can't break on data
85d721b8
PA
4594 reads only, but can break on accesses (reads or
4595 writes), such as e.g., x86. We detect this case
4596 at the time we try to insert read watchpoints.
4597
4a64f543 4598 2.2. Otherwise, the target supports read
85d721b8
PA
4599 watchpoints, but, the user set an access or write
4600 watchpoint watching the same memory as this read
4601 watchpoint.
4602
4603 If we're watching memory writes as well as reads,
4604 ignore watchpoint hits when we find that the
4605 value hasn't changed, as reads don't cause
4606 changes. This still gives false positives when
4607 the program writes the same value to memory as
4608 what there was already in memory (we will confuse
4609 it for a read), but it's much better than
4610 nothing. */
4611
4612 int other_write_watchpoint = 0;
4613
4614 if (bl->watchpoint_type == hw_read)
4615 {
4616 struct breakpoint *other_b;
4617
4618 ALL_BREAKPOINTS (other_b)
3a5c3e22
PA
4619 if (other_b->type == bp_hardware_watchpoint
4620 || other_b->type == bp_access_watchpoint)
85d721b8 4621 {
3a5c3e22
PA
4622 struct watchpoint *other_w =
4623 (struct watchpoint *) other_b;
4624
4625 if (other_w->watchpoint_triggered
4626 == watch_triggered_yes)
4627 {
4628 other_write_watchpoint = 1;
4629 break;
4630 }
85d721b8
PA
4631 }
4632 }
4633
4634 if (other_write_watchpoint
4635 || bl->watchpoint_type == hw_access)
4636 {
4637 /* We're watching the same memory for writes,
4638 and the value changed since the last time we
4639 updated it, so this trap must be for a write.
4640 Ignore it. */
4641 bs->print_it = print_it_noop;
4642 bs->stop = 0;
4643 }
18a18393
VP
4644 }
4645 break;
4646 case WP_VALUE_NOT_CHANGED:
3a5c3e22
PA
4647 if (b->base.type == bp_hardware_watchpoint
4648 || b->base.type == bp_watchpoint)
18a18393
VP
4649 {
4650 /* Don't stop: write watchpoints shouldn't fire if
4651 the value hasn't changed. */
4652 bs->print_it = print_it_noop;
4653 bs->stop = 0;
4654 }
4655 /* Stop. */
4656 break;
4657 default:
4658 /* Can't happen. */
4659 case 0:
4660 /* Error from catch_errors. */
3a5c3e22 4661 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number);
d0fb5eae 4662 watchpoint_del_at_next_stop (b);
18a18393
VP
4663 /* We've already printed what needs to be printed. */
4664 bs->print_it = print_it_done;
4665 break;
4666 }
4667 }
4668 else /* must_check_value == 0 */
4669 {
4670 /* This is a case where some watchpoint(s) triggered, but
4671 not at the address of this watchpoint, or else no
4672 watchpoint triggered after all. So don't print
4673 anything for this watchpoint. */
4674 bs->print_it = print_it_noop;
4675 bs->stop = 0;
4676 }
4677 }
4678}
4679
4680
4681/* Check conditions (condition proper, frame, thread and ignore count)
4682 of breakpoint referred to by BS. If we should not stop for this
4683 breakpoint, set BS->stop to 0. */
f431efe5 4684
18a18393
VP
4685static void
4686bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
4687{
4688 int thread_id = pid_to_thread_id (ptid);
2bdf28a0
JK
4689 const struct bp_location *bl;
4690 struct breakpoint *b;
4691
4692 /* BS is built for existing struct breakpoint. */
f431efe5 4693 bl = bs->bp_location_at;
2bdf28a0 4694 gdb_assert (bl != NULL);
f431efe5 4695 b = bs->breakpoint_at;
2bdf28a0 4696 gdb_assert (b != NULL);
18a18393 4697
b775012e
LM
4698 /* Even if the target evaluated the condition on its end and notified GDB, we
4699 need to do so again since GDB does not know if we stopped due to a
4700 breakpoint or a single step breakpoint. */
4701
18a18393 4702 if (frame_id_p (b->frame_id)
edb3359d 4703 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ())))
18a18393
VP
4704 bs->stop = 0;
4705 else if (bs->stop)
4706 {
4707 int value_is_zero = 0;
60e1c644
PA
4708 struct expression *cond;
4709
7371cf6d
PM
4710 /* Evaluate Python breakpoints that have a "stop"
4711 method implemented. */
4712 if (b->py_bp_object)
4713 bs->stop = gdbpy_should_stop (b->py_bp_object);
4714
60e1c644 4715 if (is_watchpoint (b))
3a5c3e22
PA
4716 {
4717 struct watchpoint *w = (struct watchpoint *) b;
4718
4719 cond = w->cond_exp;
4720 }
60e1c644
PA
4721 else
4722 cond = bl->cond;
4723
f431efe5 4724 if (cond && b->disposition != disp_del_at_next_stop)
18a18393 4725 {
60e1c644 4726 int within_current_scope = 1;
3a5c3e22 4727 struct watchpoint * w;
60e1c644 4728
c5bc3a77
DJ
4729 /* We use value_mark and value_free_to_mark because it could
4730 be a long time before we return to the command level and
4731 call free_all_values. We can't call free_all_values
4732 because we might be in the middle of evaluating a
4733 function call. */
4734 struct value *mark = value_mark ();
4735
3a5c3e22
PA
4736 if (is_watchpoint (b))
4737 w = (struct watchpoint *) b;
4738 else
4739 w = NULL;
4740
edb3359d
DJ
4741 /* Need to select the frame, with all that implies so that
4742 the conditions will have the right context. Because we
4743 use the frame, we will not see an inlined function's
4744 variables when we arrive at a breakpoint at the start
4745 of the inlined function; the current frame will be the
4746 call site. */
3a5c3e22 4747 if (w == NULL || w->cond_exp_valid_block == NULL)
60e1c644
PA
4748 select_frame (get_current_frame ());
4749 else
4750 {
4751 struct frame_info *frame;
4752
4753 /* For local watchpoint expressions, which particular
4754 instance of a local is being watched matters, so we
4755 keep track of the frame to evaluate the expression
4756 in. To evaluate the condition however, it doesn't
4757 really matter which instantiation of the function
4758 where the condition makes sense triggers the
4759 watchpoint. This allows an expression like "watch
4760 global if q > 10" set in `func', catch writes to
4761 global on all threads that call `func', or catch
4762 writes on all recursive calls of `func' by a single
4763 thread. We simply always evaluate the condition in
4764 the innermost frame that's executing where it makes
4765 sense to evaluate the condition. It seems
4766 intuitive. */
3a5c3e22 4767 frame = block_innermost_frame (w->cond_exp_valid_block);
60e1c644
PA
4768 if (frame != NULL)
4769 select_frame (frame);
4770 else
4771 within_current_scope = 0;
4772 }
4773 if (within_current_scope)
4774 value_is_zero
4775 = catch_errors (breakpoint_cond_eval, cond,
4776 "Error in testing breakpoint condition:\n",
4777 RETURN_MASK_ALL);
4778 else
4779 {
4780 warning (_("Watchpoint condition cannot be tested "
4781 "in the current scope"));
4782 /* If we failed to set the right context for this
4783 watchpoint, unconditionally report it. */
4784 value_is_zero = 0;
4785 }
4a64f543 4786 /* FIXME-someday, should give breakpoint #. */
c5bc3a77 4787 value_free_to_mark (mark);
18a18393 4788 }
60e1c644
PA
4789
4790 if (cond && value_is_zero)
18a18393
VP
4791 {
4792 bs->stop = 0;
4793 }
4794 else if (b->thread != -1 && b->thread != thread_id)
4795 {
4796 bs->stop = 0;
4797 }
4798 else if (b->ignore_count > 0)
4799 {
4800 b->ignore_count--;
4801 annotate_ignore_count_change ();
4802 bs->stop = 0;
4a64f543 4803 /* Increase the hit count even though we don't stop. */
18a18393 4804 ++(b->hit_count);
8d3788bd 4805 observer_notify_breakpoint_modified (b);
18a18393
VP
4806 }
4807 }
4808}
4809
4810
9709f61c 4811/* Get a bpstat associated with having just stopped at address
d983da9c 4812 BP_ADDR in thread PTID.
c906108c 4813
d983da9c 4814 Determine whether we stopped at a breakpoint, etc, or whether we
4a64f543
MS
4815 don't understand this stop. Result is a chain of bpstat's such
4816 that:
c906108c 4817
c5aa993b 4818 if we don't understand the stop, the result is a null pointer.
c906108c 4819
c5aa993b 4820 if we understand why we stopped, the result is not null.
c906108c 4821
c5aa993b
JM
4822 Each element of the chain refers to a particular breakpoint or
4823 watchpoint at which we have stopped. (We may have stopped for
4824 several reasons concurrently.)
c906108c 4825
c5aa993b
JM
4826 Each element of the chain has valid next, breakpoint_at,
4827 commands, FIXME??? fields. */
c906108c
SS
4828
4829bpstat
6c95b8df 4830bpstat_stop_status (struct address_space *aspace,
09ac7c10
TT
4831 CORE_ADDR bp_addr, ptid_t ptid,
4832 const struct target_waitstatus *ws)
c906108c 4833{
0d381245 4834 struct breakpoint *b = NULL;
afe38095 4835 struct bp_location *bl;
20874c92 4836 struct bp_location *loc;
5760d0ab
JK
4837 /* First item of allocated bpstat's. */
4838 bpstat bs_head = NULL, *bs_link = &bs_head;
c906108c 4839 /* Pointer to the last thing in the chain currently. */
5760d0ab 4840 bpstat bs;
20874c92 4841 int ix;
429374b8 4842 int need_remove_insert;
f431efe5 4843 int removed_any;
c906108c 4844
f431efe5
PA
4845 /* First, build the bpstat chain with locations that explain a
4846 target stop, while being careful to not set the target running,
4847 as that may invalidate locations (in particular watchpoint
4848 locations are recreated). Resuming will happen here with
4849 breakpoint conditions or watchpoint expressions that include
4850 inferior function calls. */
c5aa993b 4851
429374b8
JK
4852 ALL_BREAKPOINTS (b)
4853 {
4854 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
4855 continue;
a5606eee 4856
429374b8
JK
4857 for (bl = b->loc; bl != NULL; bl = bl->next)
4858 {
4a64f543
MS
4859 /* For hardware watchpoints, we look only at the first
4860 location. The watchpoint_check function will work on the
4861 entire expression, not the individual locations. For
4862 read watchpoints, the watchpoints_triggered function has
4863 checked all locations already. */
429374b8
JK
4864 if (b->type == bp_hardware_watchpoint && bl != b->loc)
4865 break;
18a18393 4866
429374b8
JK
4867 if (bl->shlib_disabled)
4868 continue;
c5aa993b 4869
09ac7c10 4870 if (!bpstat_check_location (bl, aspace, bp_addr, ws))
429374b8 4871 continue;
c5aa993b 4872
4a64f543
MS
4873 /* Come here if it's a watchpoint, or if the break address
4874 matches. */
c5aa993b 4875
4a64f543
MS
4876 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to
4877 explain stop. */
c5aa993b 4878
f431efe5
PA
4879 /* Assume we stop. Should we find a watchpoint that is not
4880 actually triggered, or if the condition of the breakpoint
4881 evaluates as false, we'll reset 'stop' to 0. */
429374b8
JK
4882 bs->stop = 1;
4883 bs->print = 1;
d983da9c 4884
f431efe5
PA
4885 /* If this is a scope breakpoint, mark the associated
4886 watchpoint as triggered so that we will handle the
4887 out-of-scope event. We'll get to the watchpoint next
4888 iteration. */
d0fb5eae 4889 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
3a5c3e22
PA
4890 {
4891 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint;
4892
4893 w->watchpoint_triggered = watch_triggered_yes;
4894 }
f431efe5
PA
4895 }
4896 }
4897
4898 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
4899 {
f1310107 4900 if (breakpoint_location_address_match (loc, aspace, bp_addr))
f431efe5 4901 {
5760d0ab 4902 bs = bpstat_alloc (loc, &bs_link);
f431efe5
PA
4903 /* For hits of moribund locations, we should just proceed. */
4904 bs->stop = 0;
4905 bs->print = 0;
4906 bs->print_it = print_it_noop;
4907 }
4908 }
4909
edcc5120
TT
4910 /* A bit of special processing for shlib breakpoints. We need to
4911 process solib loading here, so that the lists of loaded and
4912 unloaded libraries are correct before we handle "catch load" and
4913 "catch unload". */
4914 for (bs = bs_head; bs != NULL; bs = bs->next)
4915 {
5d268276 4916 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
edcc5120
TT
4917 {
4918 handle_solib_event ();
4919 break;
4920 }
4921 }
4922
f431efe5
PA
4923 /* Now go through the locations that caused the target to stop, and
4924 check whether we're interested in reporting this stop to higher
4925 layers, or whether we should resume the target transparently. */
4926
4927 removed_any = 0;
4928
5760d0ab 4929 for (bs = bs_head; bs != NULL; bs = bs->next)
f431efe5
PA
4930 {
4931 if (!bs->stop)
4932 continue;
4933
f431efe5 4934 b = bs->breakpoint_at;
348d480f
PA
4935 b->ops->check_status (bs);
4936 if (bs->stop)
28010a5d 4937 {
348d480f 4938 bpstat_check_breakpoint_conditions (bs, ptid);
f431efe5 4939
429374b8
JK
4940 if (bs->stop)
4941 {
4942 ++(b->hit_count);
8d3788bd 4943 observer_notify_breakpoint_modified (b);
c906108c 4944
4a64f543 4945 /* We will stop here. */
429374b8
JK
4946 if (b->disposition == disp_disable)
4947 {
816338b5
SS
4948 --(b->enable_count);
4949 if (b->enable_count <= 0
4950 && b->enable_state != bp_permanent)
429374b8 4951 b->enable_state = bp_disabled;
f431efe5 4952 removed_any = 1;
429374b8
JK
4953 }
4954 if (b->silent)
4955 bs->print = 0;
4956 bs->commands = b->commands;
9add0f1b 4957 incref_counted_command_line (bs->commands);
abf85f46
JK
4958 if (command_line_is_silent (bs->commands
4959 ? bs->commands->commands : NULL))
4960 bs->print = 0;
429374b8
JK
4961 }
4962
348d480f 4963 }
a9b3a50f
PA
4964
4965 /* Print nothing for this entry if we don't stop or don't
4966 print. */
4967 if (!bs->stop || !bs->print)
4968 bs->print_it = print_it_noop;
429374b8 4969 }
876fa593 4970
d983da9c
DJ
4971 /* If we aren't stopping, the value of some hardware watchpoint may
4972 not have changed, but the intermediate memory locations we are
4973 watching may have. Don't bother if we're stopping; this will get
4974 done later. */
d832cb68 4975 need_remove_insert = 0;
5760d0ab
JK
4976 if (! bpstat_causes_stop (bs_head))
4977 for (bs = bs_head; bs != NULL; bs = bs->next)
d983da9c 4978 if (!bs->stop
f431efe5
PA
4979 && bs->breakpoint_at
4980 && is_hardware_watchpoint (bs->breakpoint_at))
d983da9c 4981 {
3a5c3e22
PA
4982 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at;
4983
4984 update_watchpoint (w, 0 /* don't reparse. */);
d832cb68 4985 need_remove_insert = 1;
d983da9c
DJ
4986 }
4987
d832cb68 4988 if (need_remove_insert)
2d134ed3 4989 update_global_location_list (1);
f431efe5
PA
4990 else if (removed_any)
4991 update_global_location_list (0);
d832cb68 4992
5760d0ab 4993 return bs_head;
c906108c 4994}
628fe4e4
JK
4995
4996static void
4997handle_jit_event (void)
4998{
4999 struct frame_info *frame;
5000 struct gdbarch *gdbarch;
5001
5002 /* Switch terminal for any messages produced by
5003 breakpoint_re_set. */
5004 target_terminal_ours_for_output ();
5005
5006 frame = get_current_frame ();
5007 gdbarch = get_frame_arch (frame);
5008
5009 jit_event_handler (gdbarch);
5010
5011 target_terminal_inferior ();
5012}
5013
edcc5120
TT
5014/* Handle an solib event by calling solib_add. */
5015
5016void
5017handle_solib_event (void)
5018{
5019 clear_program_space_solib_cache (current_inferior ()->pspace);
5020
5021 /* Check for any newly added shared libraries if we're supposed to
5022 be adding them automatically. Switch terminal for any messages
5023 produced by breakpoint_re_set. */
5024 target_terminal_ours_for_output ();
5025#ifdef SOLIB_ADD
5026 SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
5027#else
5028 solib_add (NULL, 0, &current_target, auto_solib_add);
5029#endif
5030 target_terminal_inferior ();
5031}
5032
628fe4e4
JK
5033/* Prepare WHAT final decision for infrun. */
5034
5035/* Decide what infrun needs to do with this bpstat. */
5036
c906108c 5037struct bpstat_what
0e30163f 5038bpstat_what (bpstat bs_head)
c906108c 5039{
c906108c 5040 struct bpstat_what retval;
628fe4e4 5041 int jit_event = 0;
0e30163f 5042 bpstat bs;
c906108c 5043
628fe4e4 5044 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
aa7d318d 5045 retval.call_dummy = STOP_NONE;
186c406b 5046 retval.is_longjmp = 0;
628fe4e4 5047
0e30163f 5048 for (bs = bs_head; bs != NULL; bs = bs->next)
c906108c 5049 {
628fe4e4
JK
5050 /* Extract this BS's action. After processing each BS, we check
5051 if its action overrides all we've seem so far. */
5052 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING;
5053 enum bptype bptype;
5054
c906108c 5055 if (bs->breakpoint_at == NULL)
628fe4e4
JK
5056 {
5057 /* I suspect this can happen if it was a momentary
5058 breakpoint which has since been deleted. */
5059 bptype = bp_none;
5060 }
20874c92 5061 else
f431efe5 5062 bptype = bs->breakpoint_at->type;
628fe4e4
JK
5063
5064 switch (bptype)
c906108c
SS
5065 {
5066 case bp_none:
628fe4e4 5067 break;
c906108c
SS
5068 case bp_breakpoint:
5069 case bp_hardware_breakpoint:
5070 case bp_until:
5071 case bp_finish:
a9b3a50f 5072 case bp_shlib_event:
c906108c
SS
5073 if (bs->stop)
5074 {
5075 if (bs->print)
628fe4e4 5076 this_action = BPSTAT_WHAT_STOP_NOISY;
c906108c 5077 else
628fe4e4 5078 this_action = BPSTAT_WHAT_STOP_SILENT;
c906108c
SS
5079 }
5080 else
628fe4e4 5081 this_action = BPSTAT_WHAT_SINGLE;
c906108c
SS
5082 break;
5083 case bp_watchpoint:
5084 case bp_hardware_watchpoint:
5085 case bp_read_watchpoint:
5086 case bp_access_watchpoint:
5087 if (bs->stop)
5088 {
5089 if (bs->print)
628fe4e4 5090 this_action = BPSTAT_WHAT_STOP_NOISY;
c906108c 5091 else
628fe4e4 5092 this_action = BPSTAT_WHAT_STOP_SILENT;
c906108c
SS
5093 }
5094 else
628fe4e4
JK
5095 {
5096 /* There was a watchpoint, but we're not stopping.
5097 This requires no further action. */
5098 }
c906108c
SS
5099 break;
5100 case bp_longjmp:
186c406b 5101 case bp_exception:
628fe4e4 5102 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
186c406b 5103 retval.is_longjmp = bptype == bp_longjmp;
c906108c
SS
5104 break;
5105 case bp_longjmp_resume:
186c406b 5106 case bp_exception_resume:
628fe4e4 5107 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
186c406b 5108 retval.is_longjmp = bptype == bp_longjmp_resume;
c906108c
SS
5109 break;
5110 case bp_step_resume:
5111 if (bs->stop)
628fe4e4
JK
5112 this_action = BPSTAT_WHAT_STEP_RESUME;
5113 else
c906108c 5114 {
628fe4e4
JK
5115 /* It is for the wrong frame. */
5116 this_action = BPSTAT_WHAT_SINGLE;
c906108c 5117 }
c906108c 5118 break;
2c03e5be
PA
5119 case bp_hp_step_resume:
5120 if (bs->stop)
5121 this_action = BPSTAT_WHAT_HP_STEP_RESUME;
5122 else
5123 {
5124 /* It is for the wrong frame. */
5125 this_action = BPSTAT_WHAT_SINGLE;
5126 }
5127 break;
c906108c 5128 case bp_watchpoint_scope:
c4093a6a 5129 case bp_thread_event:
1900040c 5130 case bp_overlay_event:
0fd8e87f 5131 case bp_longjmp_master:
aa7d318d 5132 case bp_std_terminate_master:
186c406b 5133 case bp_exception_master:
628fe4e4 5134 this_action = BPSTAT_WHAT_SINGLE;
c4093a6a 5135 break;
ce78b96d 5136 case bp_catchpoint:
c5aa993b
JM
5137 if (bs->stop)
5138 {
5139 if (bs->print)
628fe4e4 5140 this_action = BPSTAT_WHAT_STOP_NOISY;
c5aa993b 5141 else
628fe4e4 5142 this_action = BPSTAT_WHAT_STOP_SILENT;
c5aa993b
JM
5143 }
5144 else
628fe4e4
JK
5145 {
5146 /* There was a catchpoint, but we're not stopping.
5147 This requires no further action. */
5148 }
5149 break;
628fe4e4
JK
5150 case bp_jit_event:
5151 jit_event = 1;
5152 this_action = BPSTAT_WHAT_SINGLE;
c5aa993b 5153 break;
c906108c 5154 case bp_call_dummy:
53a5351d
JM
5155 /* Make sure the action is stop (silent or noisy),
5156 so infrun.c pops the dummy frame. */
aa7d318d 5157 retval.call_dummy = STOP_STACK_DUMMY;
628fe4e4 5158 this_action = BPSTAT_WHAT_STOP_SILENT;
aa7d318d
TT
5159 break;
5160 case bp_std_terminate:
5161 /* Make sure the action is stop (silent or noisy),
5162 so infrun.c pops the dummy frame. */
aa7d318d 5163 retval.call_dummy = STOP_STD_TERMINATE;
628fe4e4 5164 this_action = BPSTAT_WHAT_STOP_SILENT;
c906108c 5165 break;
1042e4c0 5166 case bp_tracepoint:
7a697b8d 5167 case bp_fast_tracepoint:
0fb4aa4b 5168 case bp_static_tracepoint:
1042e4c0
SS
5169 /* Tracepoint hits should not be reported back to GDB, and
5170 if one got through somehow, it should have been filtered
5171 out already. */
5172 internal_error (__FILE__, __LINE__,
7a697b8d 5173 _("bpstat_what: tracepoint encountered"));
0e30163f
JK
5174 break;
5175 case bp_gnu_ifunc_resolver:
5176 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5177 this_action = BPSTAT_WHAT_SINGLE;
5178 break;
5179 case bp_gnu_ifunc_resolver_return:
5180 /* The breakpoint will be removed, execution will restart from the
5181 PC of the former breakpoint. */
5182 this_action = BPSTAT_WHAT_KEEP_CHECKING;
5183 break;
e7e0cddf
SS
5184
5185 case bp_dprintf:
5186 this_action = BPSTAT_WHAT_STOP_SILENT;
5187 break;
5188
628fe4e4
JK
5189 default:
5190 internal_error (__FILE__, __LINE__,
5191 _("bpstat_what: unhandled bptype %d"), (int) bptype);
c906108c 5192 }
628fe4e4
JK
5193
5194 retval.main_action = max (retval.main_action, this_action);
c906108c 5195 }
628fe4e4 5196
0e30163f
JK
5197 /* These operations may affect the bs->breakpoint_at state so they are
5198 delayed after MAIN_ACTION is decided above. */
5199
628fe4e4
JK
5200 if (jit_event)
5201 {
5202 if (debug_infrun)
5203 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n");
5204
5205 handle_jit_event ();
5206 }
5207
0e30163f
JK
5208 for (bs = bs_head; bs != NULL; bs = bs->next)
5209 {
5210 struct breakpoint *b = bs->breakpoint_at;
5211
5212 if (b == NULL)
5213 continue;
5214 switch (b->type)
5215 {
5216 case bp_gnu_ifunc_resolver:
5217 gnu_ifunc_resolver_stop (b);
5218 break;
5219 case bp_gnu_ifunc_resolver_return:
5220 gnu_ifunc_resolver_return_stop (b);
5221 break;
5222 }
5223 }
5224
c906108c
SS
5225 return retval;
5226}
5227
5228/* Nonzero if we should step constantly (e.g. watchpoints on machines
5229 without hardware support). This isn't related to a specific bpstat,
5230 just to things like whether watchpoints are set. */
5231
c5aa993b 5232int
fba45db2 5233bpstat_should_step (void)
c906108c
SS
5234{
5235 struct breakpoint *b;
cc59ec59 5236
c906108c 5237 ALL_BREAKPOINTS (b)
717a8278 5238 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
3172dc30 5239 return 1;
c906108c
SS
5240 return 0;
5241}
5242
67822962
PA
5243int
5244bpstat_causes_stop (bpstat bs)
5245{
5246 for (; bs != NULL; bs = bs->next)
5247 if (bs->stop)
5248 return 1;
5249
5250 return 0;
5251}
5252
c906108c 5253\f
c5aa993b 5254
170b53b2
UW
5255/* Compute a string of spaces suitable to indent the next line
5256 so it starts at the position corresponding to the table column
5257 named COL_NAME in the currently active table of UIOUT. */
5258
5259static char *
5260wrap_indent_at_field (struct ui_out *uiout, const char *col_name)
5261{
5262 static char wrap_indent[80];
5263 int i, total_width, width, align;
5264 char *text;
5265
5266 total_width = 0;
5267 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
5268 {
5269 if (strcmp (text, col_name) == 0)
5270 {
5271 gdb_assert (total_width < sizeof wrap_indent);
5272 memset (wrap_indent, ' ', total_width);
5273 wrap_indent[total_width] = 0;
5274
5275 return wrap_indent;
5276 }
5277
5278 total_width += width + 1;
5279 }
5280
5281 return NULL;
5282}
5283
b775012e
LM
5284/* Determine if the locations of this breakpoint will have their conditions
5285 evaluated by the target, host or a mix of both. Returns the following:
5286
5287 "host": Host evals condition.
5288 "host or target": Host or Target evals condition.
5289 "target": Target evals condition.
5290*/
5291
5292static const char *
5293bp_condition_evaluator (struct breakpoint *b)
5294{
5295 struct bp_location *bl;
5296 char host_evals = 0;
5297 char target_evals = 0;
5298
5299 if (!b)
5300 return NULL;
5301
5302 if (!is_breakpoint (b))
5303 return NULL;
5304
5305 if (gdb_evaluates_breakpoint_condition_p ()
5306 || !target_supports_evaluation_of_breakpoint_conditions ())
5307 return condition_evaluation_host;
5308
5309 for (bl = b->loc; bl; bl = bl->next)
5310 {
5311 if (bl->cond_bytecode)
5312 target_evals++;
5313 else
5314 host_evals++;
5315 }
5316
5317 if (host_evals && target_evals)
5318 return condition_evaluation_both;
5319 else if (target_evals)
5320 return condition_evaluation_target;
5321 else
5322 return condition_evaluation_host;
5323}
5324
5325/* Determine the breakpoint location's condition evaluator. This is
5326 similar to bp_condition_evaluator, but for locations. */
5327
5328static const char *
5329bp_location_condition_evaluator (struct bp_location *bl)
5330{
5331 if (bl && !is_breakpoint (bl->owner))
5332 return NULL;
5333
5334 if (gdb_evaluates_breakpoint_condition_p ()
5335 || !target_supports_evaluation_of_breakpoint_conditions ())
5336 return condition_evaluation_host;
5337
5338 if (bl && bl->cond_bytecode)
5339 return condition_evaluation_target;
5340 else
5341 return condition_evaluation_host;
5342}
5343
859825b8
JK
5344/* Print the LOC location out of the list of B->LOC locations. */
5345
170b53b2
UW
5346static void
5347print_breakpoint_location (struct breakpoint *b,
5348 struct bp_location *loc)
0d381245 5349{
79a45e25 5350 struct ui_out *uiout = current_uiout;
6c95b8df
PA
5351 struct cleanup *old_chain = save_current_program_space ();
5352
859825b8
JK
5353 if (loc != NULL && loc->shlib_disabled)
5354 loc = NULL;
5355
6c95b8df
PA
5356 if (loc != NULL)
5357 set_current_program_space (loc->pspace);
5358
56435ebe
TT
5359 if (b->display_canonical)
5360 ui_out_field_string (uiout, "what", b->addr_string);
f8eba3c6 5361 else if (loc && loc->source_file)
0d381245
VP
5362 {
5363 struct symbol *sym
5364 = find_pc_sect_function (loc->address, loc->section);
5365 if (sym)
5366 {
5367 ui_out_text (uiout, "in ");
5368 ui_out_field_string (uiout, "func",
5369 SYMBOL_PRINT_NAME (sym));
170b53b2
UW
5370 ui_out_text (uiout, " ");
5371 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
5372 ui_out_text (uiout, "at ");
0d381245 5373 }
f8eba3c6 5374 ui_out_field_string (uiout, "file", loc->source_file);
0d381245
VP
5375 ui_out_text (uiout, ":");
5376
5377 if (ui_out_is_mi_like_p (uiout))
5378 {
5379 struct symtab_and_line sal = find_pc_line (loc->address, 0);
5380 char *fullname = symtab_to_fullname (sal.symtab);
5381
5382 if (fullname)
5383 ui_out_field_string (uiout, "fullname", fullname);
5384 }
5385
f8eba3c6 5386 ui_out_field_int (uiout, "line", loc->line_number);
0d381245 5387 }
859825b8 5388 else if (loc)
0d381245 5389 {
f99d8bf4
PA
5390 struct ui_file *stb = mem_fileopen ();
5391 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb);
170b53b2 5392
f99d8bf4 5393 print_address_symbolic (loc->gdbarch, loc->address, stb,
22e722e1 5394 demangle, "");
0d381245 5395 ui_out_field_stream (uiout, "at", stb);
170b53b2
UW
5396
5397 do_cleanups (stb_chain);
0d381245 5398 }
859825b8
JK
5399 else
5400 ui_out_field_string (uiout, "pending", b->addr_string);
6c95b8df 5401
b775012e
LM
5402 if (loc && is_breakpoint (b)
5403 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5404 && bp_condition_evaluator (b) == condition_evaluation_both)
5405 {
5406 ui_out_text (uiout, " (");
5407 ui_out_field_string (uiout, "evaluated-by",
5408 bp_location_condition_evaluator (loc));
5409 ui_out_text (uiout, ")");
5410 }
5411
6c95b8df 5412 do_cleanups (old_chain);
0d381245
VP
5413}
5414
269b11a2
PA
5415static const char *
5416bptype_string (enum bptype type)
c906108c 5417{
c4093a6a
JM
5418 struct ep_type_description
5419 {
5420 enum bptype type;
5421 char *description;
5422 };
5423 static struct ep_type_description bptypes[] =
c906108c 5424 {
c5aa993b
JM
5425 {bp_none, "?deleted?"},
5426 {bp_breakpoint, "breakpoint"},
c906108c 5427 {bp_hardware_breakpoint, "hw breakpoint"},
c5aa993b
JM
5428 {bp_until, "until"},
5429 {bp_finish, "finish"},
5430 {bp_watchpoint, "watchpoint"},
c906108c 5431 {bp_hardware_watchpoint, "hw watchpoint"},
c5aa993b
JM
5432 {bp_read_watchpoint, "read watchpoint"},
5433 {bp_access_watchpoint, "acc watchpoint"},
5434 {bp_longjmp, "longjmp"},
5435 {bp_longjmp_resume, "longjmp resume"},
186c406b
TT
5436 {bp_exception, "exception"},
5437 {bp_exception_resume, "exception resume"},
c5aa993b 5438 {bp_step_resume, "step resume"},
2c03e5be 5439 {bp_hp_step_resume, "high-priority step resume"},
c5aa993b
JM
5440 {bp_watchpoint_scope, "watchpoint scope"},
5441 {bp_call_dummy, "call dummy"},
aa7d318d 5442 {bp_std_terminate, "std::terminate"},
c5aa993b 5443 {bp_shlib_event, "shlib events"},
c4093a6a 5444 {bp_thread_event, "thread events"},
1900040c 5445 {bp_overlay_event, "overlay events"},
0fd8e87f 5446 {bp_longjmp_master, "longjmp master"},
aa7d318d 5447 {bp_std_terminate_master, "std::terminate master"},
186c406b 5448 {bp_exception_master, "exception master"},
ce78b96d 5449 {bp_catchpoint, "catchpoint"},
1042e4c0 5450 {bp_tracepoint, "tracepoint"},
7a697b8d 5451 {bp_fast_tracepoint, "fast tracepoint"},
0fb4aa4b 5452 {bp_static_tracepoint, "static tracepoint"},
e7e0cddf 5453 {bp_dprintf, "dprintf"},
4efc6507 5454 {bp_jit_event, "jit events"},
0e30163f
JK
5455 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"},
5456 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"},
c5aa993b 5457 };
269b11a2
PA
5458
5459 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0])))
5460 || ((int) type != bptypes[(int) type].type))
5461 internal_error (__FILE__, __LINE__,
5462 _("bptypes table does not describe type #%d."),
5463 (int) type);
5464
5465 return bptypes[(int) type].description;
5466}
5467
5468/* Print B to gdb_stdout. */
5469
5470static void
5471print_one_breakpoint_location (struct breakpoint *b,
5472 struct bp_location *loc,
5473 int loc_number,
5474 struct bp_location **last_loc,
269b11a2
PA
5475 int allflag)
5476{
5477 struct command_line *l;
c2c6d25f 5478 static char bpenables[] = "nynny";
c906108c 5479
79a45e25 5480 struct ui_out *uiout = current_uiout;
0d381245
VP
5481 int header_of_multiple = 0;
5482 int part_of_multiple = (loc != NULL);
79a45b7d
TT
5483 struct value_print_options opts;
5484
5485 get_user_print_options (&opts);
0d381245
VP
5486
5487 gdb_assert (!loc || loc_number != 0);
4a64f543
MS
5488 /* See comment in print_one_breakpoint concerning treatment of
5489 breakpoints with single disabled location. */
0d381245
VP
5490 if (loc == NULL
5491 && (b->loc != NULL
5492 && (b->loc->next != NULL || !b->loc->enabled)))
5493 header_of_multiple = 1;
5494 if (loc == NULL)
5495 loc = b->loc;
5496
c4093a6a
JM
5497 annotate_record ();
5498
5499 /* 1 */
5500 annotate_field (0);
0d381245
VP
5501 if (part_of_multiple)
5502 {
5503 char *formatted;
0c6773c1 5504 formatted = xstrprintf ("%d.%d", b->number, loc_number);
0d381245
VP
5505 ui_out_field_string (uiout, "number", formatted);
5506 xfree (formatted);
5507 }
5508 else
5509 {
5510 ui_out_field_int (uiout, "number", b->number);
5511 }
c4093a6a
JM
5512
5513 /* 2 */
5514 annotate_field (1);
0d381245
VP
5515 if (part_of_multiple)
5516 ui_out_field_skip (uiout, "type");
269b11a2
PA
5517 else
5518 ui_out_field_string (uiout, "type", bptype_string (b->type));
c4093a6a
JM
5519
5520 /* 3 */
5521 annotate_field (2);
0d381245
VP
5522 if (part_of_multiple)
5523 ui_out_field_skip (uiout, "disp");
5524 else
2cec12e5 5525 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
0d381245 5526
c4093a6a
JM
5527
5528 /* 4 */
5529 annotate_field (3);
0d381245 5530 if (part_of_multiple)
54e52265 5531 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
0d381245 5532 else
4a64f543
MS
5533 ui_out_field_fmt (uiout, "enabled", "%c",
5534 bpenables[(int) b->enable_state]);
54e52265 5535 ui_out_spaces (uiout, 2);
0d381245 5536
c4093a6a
JM
5537
5538 /* 5 and 6 */
3086aeae 5539 if (b->ops != NULL && b->ops->print_one != NULL)
0d381245 5540 {
4a64f543
MS
5541 /* Although the print_one can possibly print all locations,
5542 calling it here is not likely to get any nice result. So,
5543 make sure there's just one location. */
0d381245 5544 gdb_assert (b->loc == NULL || b->loc->next == NULL);
a6d9a66e 5545 b->ops->print_one (b, last_loc);
0d381245 5546 }
3086aeae
DJ
5547 else
5548 switch (b->type)
5549 {
5550 case bp_none:
5551 internal_error (__FILE__, __LINE__,
e2e0b3e5 5552 _("print_one_breakpoint: bp_none encountered\n"));
3086aeae 5553 break;
c906108c 5554
3086aeae
DJ
5555 case bp_watchpoint:
5556 case bp_hardware_watchpoint:
5557 case bp_read_watchpoint:
5558 case bp_access_watchpoint:
3a5c3e22
PA
5559 {
5560 struct watchpoint *w = (struct watchpoint *) b;
5561
5562 /* Field 4, the address, is omitted (which makes the columns
5563 not line up too nicely with the headers, but the effect
5564 is relatively readable). */
5565 if (opts.addressprint)
5566 ui_out_field_skip (uiout, "addr");
5567 annotate_field (5);
5568 ui_out_field_string (uiout, "what", w->exp_string);
5569 }
3086aeae
DJ
5570 break;
5571
3086aeae
DJ
5572 case bp_breakpoint:
5573 case bp_hardware_breakpoint:
5574 case bp_until:
5575 case bp_finish:
5576 case bp_longjmp:
5577 case bp_longjmp_resume:
186c406b
TT
5578 case bp_exception:
5579 case bp_exception_resume:
3086aeae 5580 case bp_step_resume:
2c03e5be 5581 case bp_hp_step_resume:
3086aeae
DJ
5582 case bp_watchpoint_scope:
5583 case bp_call_dummy:
aa7d318d 5584 case bp_std_terminate:
3086aeae
DJ
5585 case bp_shlib_event:
5586 case bp_thread_event:
5587 case bp_overlay_event:
0fd8e87f 5588 case bp_longjmp_master:
aa7d318d 5589 case bp_std_terminate_master:
186c406b 5590 case bp_exception_master:
1042e4c0 5591 case bp_tracepoint:
7a697b8d 5592 case bp_fast_tracepoint:
0fb4aa4b 5593 case bp_static_tracepoint:
e7e0cddf 5594 case bp_dprintf:
4efc6507 5595 case bp_jit_event:
0e30163f
JK
5596 case bp_gnu_ifunc_resolver:
5597 case bp_gnu_ifunc_resolver_return:
79a45b7d 5598 if (opts.addressprint)
3086aeae
DJ
5599 {
5600 annotate_field (4);
54e52265 5601 if (header_of_multiple)
0d381245 5602 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
e9bbd7c5 5603 else if (b->loc == NULL || loc->shlib_disabled)
54e52265 5604 ui_out_field_string (uiout, "addr", "<PENDING>");
0101ce28 5605 else
5af949e3
UW
5606 ui_out_field_core_addr (uiout, "addr",
5607 loc->gdbarch, loc->address);
3086aeae
DJ
5608 }
5609 annotate_field (5);
0d381245 5610 if (!header_of_multiple)
170b53b2 5611 print_breakpoint_location (b, loc);
0d381245 5612 if (b->loc)
a6d9a66e 5613 *last_loc = b->loc;
3086aeae
DJ
5614 break;
5615 }
c906108c 5616
6c95b8df
PA
5617
5618 /* For backward compatibility, don't display inferiors unless there
5619 are several. */
5620 if (loc != NULL
5621 && !header_of_multiple
5622 && (allflag
5623 || (!gdbarch_has_global_breakpoints (target_gdbarch)
5624 && (number_of_program_spaces () > 1
5625 || number_of_inferiors () > 1)
4a64f543
MS
5626 /* LOC is for existing B, it cannot be in
5627 moribund_locations and thus having NULL OWNER. */
6c95b8df
PA
5628 && loc->owner->type != bp_catchpoint)))
5629 {
5630 struct inferior *inf;
5631 int first = 1;
5632
5633 for (inf = inferior_list; inf != NULL; inf = inf->next)
5634 {
5635 if (inf->pspace == loc->pspace)
5636 {
5637 if (first)
5638 {
5639 first = 0;
5640 ui_out_text (uiout, " inf ");
5641 }
5642 else
5643 ui_out_text (uiout, ", ");
5644 ui_out_text (uiout, plongest (inf->num));
5645 }
5646 }
5647 }
5648
4a306c9a 5649 if (!part_of_multiple)
c4093a6a 5650 {
4a306c9a
JB
5651 if (b->thread != -1)
5652 {
5653 /* FIXME: This seems to be redundant and lost here; see the
4a64f543 5654 "stop only in" line a little further down. */
4a306c9a
JB
5655 ui_out_text (uiout, " thread ");
5656 ui_out_field_int (uiout, "thread", b->thread);
5657 }
5658 else if (b->task != 0)
5659 {
5660 ui_out_text (uiout, " task ");
5661 ui_out_field_int (uiout, "task", b->task);
5662 }
c4093a6a 5663 }
f1310107 5664
8b93c638 5665 ui_out_text (uiout, "\n");
f1310107 5666
348d480f 5667 if (!part_of_multiple)
f1310107
TJB
5668 b->ops->print_one_detail (b, uiout);
5669
0d381245 5670 if (part_of_multiple && frame_id_p (b->frame_id))
c4093a6a
JM
5671 {
5672 annotate_field (6);
8b93c638 5673 ui_out_text (uiout, "\tstop only in stack frame at ");
e5dd4106 5674 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
818dd999 5675 the frame ID. */
5af949e3
UW
5676 ui_out_field_core_addr (uiout, "frame",
5677 b->gdbarch, b->frame_id.stack_addr);
8b93c638 5678 ui_out_text (uiout, "\n");
c4093a6a
JM
5679 }
5680
28010a5d 5681 if (!part_of_multiple && b->cond_string)
c4093a6a
JM
5682 {
5683 annotate_field (7);
d77f58be 5684 if (is_tracepoint (b))
1042e4c0
SS
5685 ui_out_text (uiout, "\ttrace only if ");
5686 else
5687 ui_out_text (uiout, "\tstop only if ");
0101ce28 5688 ui_out_field_string (uiout, "cond", b->cond_string);
b775012e
LM
5689
5690 /* Print whether the target is doing the breakpoint's condition
5691 evaluation. If GDB is doing the evaluation, don't print anything. */
5692 if (is_breakpoint (b)
5693 && breakpoint_condition_evaluation_mode ()
5694 == condition_evaluation_target)
5695 {
5696 ui_out_text (uiout, " (");
5697 ui_out_field_string (uiout, "evaluated-by",
5698 bp_condition_evaluator (b));
5699 ui_out_text (uiout, " evals)");
5700 }
0101ce28
JJ
5701 ui_out_text (uiout, "\n");
5702 }
5703
0d381245 5704 if (!part_of_multiple && b->thread != -1)
c4093a6a 5705 {
4a64f543 5706 /* FIXME should make an annotation for this. */
8b93c638
JM
5707 ui_out_text (uiout, "\tstop only in thread ");
5708 ui_out_field_int (uiout, "thread", b->thread);
5709 ui_out_text (uiout, "\n");
c4093a6a
JM
5710 }
5711
63c715c6 5712 if (!part_of_multiple && b->hit_count)
c4093a6a 5713 {
4a64f543 5714 /* FIXME should make an annotation for this. */
c326b90e 5715 if (is_catchpoint (b))
8b93c638 5716 ui_out_text (uiout, "\tcatchpoint");
f196051f
SS
5717 else if (is_tracepoint (b))
5718 ui_out_text (uiout, "\ttracepoint");
8b93c638
JM
5719 else
5720 ui_out_text (uiout, "\tbreakpoint");
5721 ui_out_text (uiout, " already hit ");
5722 ui_out_field_int (uiout, "times", b->hit_count);
5723 if (b->hit_count == 1)
5724 ui_out_text (uiout, " time\n");
5725 else
5726 ui_out_text (uiout, " times\n");
c4093a6a
JM
5727 }
5728
4a64f543
MS
5729 /* Output the count also if it is zero, but only if this is mi.
5730 FIXME: Should have a better test for this. */
9dc5e2a9 5731 if (ui_out_is_mi_like_p (uiout))
63c715c6 5732 if (!part_of_multiple && b->hit_count == 0)
fb40c209 5733 ui_out_field_int (uiout, "times", b->hit_count);
8b93c638 5734
0d381245 5735 if (!part_of_multiple && b->ignore_count)
c4093a6a
JM
5736 {
5737 annotate_field (8);
8b93c638
JM
5738 ui_out_text (uiout, "\tignore next ");
5739 ui_out_field_int (uiout, "ignore", b->ignore_count);
5740 ui_out_text (uiout, " hits\n");
c4093a6a 5741 }
059fb39f 5742
816338b5
SS
5743 /* Note that an enable count of 1 corresponds to "enable once"
5744 behavior, which is reported by the combination of enablement and
5745 disposition, so we don't need to mention it here. */
5746 if (!part_of_multiple && b->enable_count > 1)
5747 {
5748 annotate_field (8);
5749 ui_out_text (uiout, "\tdisable after ");
5750 /* Tweak the wording to clarify that ignore and enable counts
5751 are distinct, and have additive effect. */
5752 if (b->ignore_count)
5753 ui_out_text (uiout, "additional ");
5754 else
5755 ui_out_text (uiout, "next ");
5756 ui_out_field_int (uiout, "enable", b->enable_count);
5757 ui_out_text (uiout, " hits\n");
5758 }
5759
f196051f
SS
5760 if (!part_of_multiple && is_tracepoint (b))
5761 {
5762 struct tracepoint *tp = (struct tracepoint *) b;
5763
5764 if (tp->traceframe_usage)
5765 {
5766 ui_out_text (uiout, "\ttrace buffer usage ");
5767 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage);
5768 ui_out_text (uiout, " bytes\n");
5769 }
5770 }
5771
9add0f1b 5772 l = b->commands ? b->commands->commands : NULL;
059fb39f 5773 if (!part_of_multiple && l)
c4093a6a 5774 {
3b31d625
EZ
5775 struct cleanup *script_chain;
5776
c4093a6a 5777 annotate_field (9);
3b31d625 5778 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
8b93c638 5779 print_command_lines (uiout, l, 4);
3b31d625 5780 do_cleanups (script_chain);
c4093a6a 5781 }
d24317b4 5782
d9b3f62e 5783 if (is_tracepoint (b))
1042e4c0 5784 {
d9b3f62e
PA
5785 struct tracepoint *t = (struct tracepoint *) b;
5786
5787 if (!part_of_multiple && t->pass_count)
5788 {
5789 annotate_field (10);
5790 ui_out_text (uiout, "\tpass count ");
5791 ui_out_field_int (uiout, "pass", t->pass_count);
5792 ui_out_text (uiout, " \n");
5793 }
1042e4c0
SS
5794 }
5795
d24317b4
VP
5796 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
5797 {
3a5c3e22
PA
5798 if (is_watchpoint (b))
5799 {
5800 struct watchpoint *w = (struct watchpoint *) b;
5801
5802 ui_out_field_string (uiout, "original-location", w->exp_string);
5803 }
5804 else if (b->addr_string)
d24317b4 5805 ui_out_field_string (uiout, "original-location", b->addr_string);
d24317b4 5806 }
c4093a6a 5807}
c5aa993b 5808
0d381245
VP
5809static void
5810print_one_breakpoint (struct breakpoint *b,
4a64f543 5811 struct bp_location **last_loc,
6c95b8df 5812 int allflag)
0d381245 5813{
8d3788bd 5814 struct cleanup *bkpt_chain;
79a45e25 5815 struct ui_out *uiout = current_uiout;
8d3788bd
VP
5816
5817 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
5818
12c5a436 5819 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag);
8d3788bd 5820 do_cleanups (bkpt_chain);
0d381245
VP
5821
5822 /* If this breakpoint has custom print function,
5823 it's already printed. Otherwise, print individual
5824 locations, if any. */
5825 if (b->ops == NULL || b->ops->print_one == NULL)
5826 {
4a64f543
MS
5827 /* If breakpoint has a single location that is disabled, we
5828 print it as if it had several locations, since otherwise it's
5829 hard to represent "breakpoint enabled, location disabled"
5830 situation.
5831
5832 Note that while hardware watchpoints have several locations
a3be7890 5833 internally, that's not a property exposed to user. */
0d381245 5834 if (b->loc
a5606eee 5835 && !is_hardware_watchpoint (b)
8d3788bd 5836 && (b->loc->next || !b->loc->enabled))
0d381245
VP
5837 {
5838 struct bp_location *loc;
5839 int n = 1;
8d3788bd 5840
0d381245 5841 for (loc = b->loc; loc; loc = loc->next, ++n)
8d3788bd
VP
5842 {
5843 struct cleanup *inner2 =
5844 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5845 print_one_breakpoint_location (b, loc, n, last_loc, allflag);
5846 do_cleanups (inner2);
5847 }
0d381245
VP
5848 }
5849 }
5850}
5851
a6d9a66e
UW
5852static int
5853breakpoint_address_bits (struct breakpoint *b)
5854{
5855 int print_address_bits = 0;
5856 struct bp_location *loc;
5857
5858 for (loc = b->loc; loc; loc = loc->next)
5859 {
c7437ca6
PA
5860 int addr_bit;
5861
5862 /* Software watchpoints that aren't watching memory don't have
5863 an address to print. */
5864 if (b->type == bp_watchpoint && loc->watchpoint_type == -1)
5865 continue;
5866
5867 addr_bit = gdbarch_addr_bit (loc->gdbarch);
a6d9a66e
UW
5868 if (addr_bit > print_address_bits)
5869 print_address_bits = addr_bit;
5870 }
5871
5872 return print_address_bits;
5873}
0d381245 5874
c4093a6a
JM
5875struct captured_breakpoint_query_args
5876 {
5877 int bnum;
5878 };
c5aa993b 5879
c4093a6a 5880static int
2b65245e 5881do_captured_breakpoint_query (struct ui_out *uiout, void *data)
c4093a6a
JM
5882{
5883 struct captured_breakpoint_query_args *args = data;
52f0bd74 5884 struct breakpoint *b;
a6d9a66e 5885 struct bp_location *dummy_loc = NULL;
cc59ec59 5886
c4093a6a
JM
5887 ALL_BREAKPOINTS (b)
5888 {
5889 if (args->bnum == b->number)
c5aa993b 5890 {
12c5a436 5891 print_one_breakpoint (b, &dummy_loc, 0);
c4093a6a 5892 return GDB_RC_OK;
c5aa993b 5893 }
c4093a6a
JM
5894 }
5895 return GDB_RC_NONE;
5896}
c5aa993b 5897
c4093a6a 5898enum gdb_rc
4a64f543
MS
5899gdb_breakpoint_query (struct ui_out *uiout, int bnum,
5900 char **error_message)
c4093a6a
JM
5901{
5902 struct captured_breakpoint_query_args args;
cc59ec59 5903
c4093a6a
JM
5904 args.bnum = bnum;
5905 /* For the moment we don't trust print_one_breakpoint() to not throw
4a64f543 5906 an error. */
b0b13bb4
DJ
5907 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
5908 error_message, RETURN_MASK_ALL) < 0)
5909 return GDB_RC_FAIL;
5910 else
5911 return GDB_RC_OK;
c4093a6a 5912}
c5aa993b 5913
09d682a4
TT
5914/* Return true if this breakpoint was set by the user, false if it is
5915 internal or momentary. */
5916
5917int
5918user_breakpoint_p (struct breakpoint *b)
5919{
46c6471b 5920 return b->number > 0;
09d682a4
TT
5921}
5922
7f3b0473 5923/* Print information on user settable breakpoint (watchpoint, etc)
d77f58be
SS
5924 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5925 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5926 FILTER is non-NULL, call it on each breakpoint and only include the
5927 ones for which it returns non-zero. Return the total number of
5928 breakpoints listed. */
c906108c 5929
d77f58be 5930static int
e5a67952 5931breakpoint_1 (char *args, int allflag,
4a64f543 5932 int (*filter) (const struct breakpoint *))
c4093a6a 5933{
52f0bd74 5934 struct breakpoint *b;
a6d9a66e 5935 struct bp_location *last_loc = NULL;
7f3b0473 5936 int nr_printable_breakpoints;
3b31d625 5937 struct cleanup *bkpttbl_chain;
79a45b7d 5938 struct value_print_options opts;
a6d9a66e 5939 int print_address_bits = 0;
269b11a2 5940 int print_type_col_width = 14;
79a45e25 5941 struct ui_out *uiout = current_uiout;
269b11a2 5942
79a45b7d
TT
5943 get_user_print_options (&opts);
5944
4a64f543
MS
5945 /* Compute the number of rows in the table, as well as the size
5946 required for address fields. */
7f3b0473
AC
5947 nr_printable_breakpoints = 0;
5948 ALL_BREAKPOINTS (b)
e5a67952
MS
5949 {
5950 /* If we have a filter, only list the breakpoints it accepts. */
5951 if (filter && !filter (b))
5952 continue;
5953
5954 /* If we have an "args" string, it is a list of breakpoints to
5955 accept. Skip the others. */
5956 if (args != NULL && *args != '\0')
5957 {
5958 if (allflag && parse_and_eval_long (args) != b->number)
5959 continue;
5960 if (!allflag && !number_is_in_list (args, b->number))
5961 continue;
5962 }
269b11a2 5963
e5a67952
MS
5964 if (allflag || user_breakpoint_p (b))
5965 {
5966 int addr_bit, type_len;
a6d9a66e 5967
e5a67952
MS
5968 addr_bit = breakpoint_address_bits (b);
5969 if (addr_bit > print_address_bits)
5970 print_address_bits = addr_bit;
269b11a2 5971
e5a67952
MS
5972 type_len = strlen (bptype_string (b->type));
5973 if (type_len > print_type_col_width)
5974 print_type_col_width = type_len;
5975
5976 nr_printable_breakpoints++;
5977 }
5978 }
7f3b0473 5979
79a45b7d 5980 if (opts.addressprint)
3b31d625 5981 bkpttbl_chain
3e43a32a
MS
5982 = make_cleanup_ui_out_table_begin_end (uiout, 6,
5983 nr_printable_breakpoints,
3b31d625 5984 "BreakpointTable");
8b93c638 5985 else
3b31d625 5986 bkpttbl_chain
3e43a32a
MS
5987 = make_cleanup_ui_out_table_begin_end (uiout, 5,
5988 nr_printable_breakpoints,
3b31d625 5989 "BreakpointTable");
8b93c638 5990
7f3b0473 5991 if (nr_printable_breakpoints > 0)
d7faa9e7
AC
5992 annotate_breakpoints_headers ();
5993 if (nr_printable_breakpoints > 0)
5994 annotate_field (0);
4a64f543 5995 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
d7faa9e7
AC
5996 if (nr_printable_breakpoints > 0)
5997 annotate_field (1);
269b11a2 5998 ui_out_table_header (uiout, print_type_col_width, ui_left,
4a64f543 5999 "type", "Type"); /* 2 */
d7faa9e7
AC
6000 if (nr_printable_breakpoints > 0)
6001 annotate_field (2);
4a64f543 6002 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
d7faa9e7
AC
6003 if (nr_printable_breakpoints > 0)
6004 annotate_field (3);
54e52265 6005 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
79a45b7d 6006 if (opts.addressprint)
e5a67952
MS
6007 {
6008 if (nr_printable_breakpoints > 0)
6009 annotate_field (4);
6010 if (print_address_bits <= 32)
6011 ui_out_table_header (uiout, 10, ui_left,
6012 "addr", "Address"); /* 5 */
6013 else
6014 ui_out_table_header (uiout, 18, ui_left,
6015 "addr", "Address"); /* 5 */
6016 }
d7faa9e7
AC
6017 if (nr_printable_breakpoints > 0)
6018 annotate_field (5);
6019 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
6020 ui_out_table_body (uiout);
6021 if (nr_printable_breakpoints > 0)
6022 annotate_breakpoints_table ();
7f3b0473 6023
c4093a6a 6024 ALL_BREAKPOINTS (b)
e5a67952
MS
6025 {
6026 QUIT;
6027 /* If we have a filter, only list the breakpoints it accepts. */
6028 if (filter && !filter (b))
6029 continue;
6030
6031 /* If we have an "args" string, it is a list of breakpoints to
6032 accept. Skip the others. */
6033
6034 if (args != NULL && *args != '\0')
6035 {
6036 if (allflag) /* maintenance info breakpoint */
6037 {
6038 if (parse_and_eval_long (args) != b->number)
6039 continue;
6040 }
6041 else /* all others */
6042 {
6043 if (!number_is_in_list (args, b->number))
6044 continue;
6045 }
6046 }
6047 /* We only print out user settable breakpoints unless the
6048 allflag is set. */
6049 if (allflag || user_breakpoint_p (b))
12c5a436 6050 print_one_breakpoint (b, &last_loc, allflag);
e5a67952
MS
6051 }
6052
3b31d625 6053 do_cleanups (bkpttbl_chain);
698384cd 6054
7f3b0473 6055 if (nr_printable_breakpoints == 0)
c906108c 6056 {
4a64f543
MS
6057 /* If there's a filter, let the caller decide how to report
6058 empty list. */
d77f58be
SS
6059 if (!filter)
6060 {
e5a67952 6061 if (args == NULL || *args == '\0')
d77f58be
SS
6062 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
6063 else
4a64f543 6064 ui_out_message (uiout, 0,
e5a67952
MS
6065 "No breakpoint or watchpoint matching '%s'.\n",
6066 args);
d77f58be 6067 }
c906108c
SS
6068 }
6069 else
c4093a6a 6070 {
a6d9a66e
UW
6071 if (last_loc && !server_command)
6072 set_next_address (last_loc->gdbarch, last_loc->address);
c4093a6a 6073 }
c906108c 6074
4a64f543 6075 /* FIXME? Should this be moved up so that it is only called when
c4093a6a 6076 there have been breakpoints? */
c906108c 6077 annotate_breakpoints_table_end ();
d77f58be
SS
6078
6079 return nr_printable_breakpoints;
c906108c
SS
6080}
6081
ad443146
SS
6082/* Display the value of default-collect in a way that is generally
6083 compatible with the breakpoint list. */
6084
6085static void
6086default_collect_info (void)
6087{
79a45e25
PA
6088 struct ui_out *uiout = current_uiout;
6089
ad443146
SS
6090 /* If it has no value (which is frequently the case), say nothing; a
6091 message like "No default-collect." gets in user's face when it's
6092 not wanted. */
6093 if (!*default_collect)
6094 return;
6095
6096 /* The following phrase lines up nicely with per-tracepoint collect
6097 actions. */
6098 ui_out_text (uiout, "default collect ");
6099 ui_out_field_string (uiout, "default-collect", default_collect);
6100 ui_out_text (uiout, " \n");
6101}
6102
c906108c 6103static void
e5a67952 6104breakpoints_info (char *args, int from_tty)
c906108c 6105{
e5a67952 6106 breakpoint_1 (args, 0, NULL);
ad443146
SS
6107
6108 default_collect_info ();
d77f58be
SS
6109}
6110
6111static void
e5a67952 6112watchpoints_info (char *args, int from_tty)
d77f58be 6113{
e5a67952 6114 int num_printed = breakpoint_1 (args, 0, is_watchpoint);
79a45e25 6115 struct ui_out *uiout = current_uiout;
d77f58be
SS
6116
6117 if (num_printed == 0)
6118 {
e5a67952 6119 if (args == NULL || *args == '\0')
d77f58be
SS
6120 ui_out_message (uiout, 0, "No watchpoints.\n");
6121 else
e5a67952 6122 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args);
d77f58be 6123 }
c906108c
SS
6124}
6125
7a292a7a 6126static void
e5a67952 6127maintenance_info_breakpoints (char *args, int from_tty)
c906108c 6128{
e5a67952 6129 breakpoint_1 (args, 1, NULL);
ad443146
SS
6130
6131 default_collect_info ();
c906108c
SS
6132}
6133
0d381245 6134static int
714835d5 6135breakpoint_has_pc (struct breakpoint *b,
6c95b8df 6136 struct program_space *pspace,
714835d5 6137 CORE_ADDR pc, struct obj_section *section)
0d381245
VP
6138{
6139 struct bp_location *bl = b->loc;
cc59ec59 6140
0d381245
VP
6141 for (; bl; bl = bl->next)
6142 {
6c95b8df
PA
6143 if (bl->pspace == pspace
6144 && bl->address == pc
0d381245
VP
6145 && (!overlay_debugging || bl->section == section))
6146 return 1;
6147 }
6148 return 0;
6149}
6150
672f9b60 6151/* Print a message describing any user-breakpoints set at PC. This
6c95b8df
PA
6152 concerns with logical breakpoints, so we match program spaces, not
6153 address spaces. */
c906108c
SS
6154
6155static void
6c95b8df
PA
6156describe_other_breakpoints (struct gdbarch *gdbarch,
6157 struct program_space *pspace, CORE_ADDR pc,
5af949e3 6158 struct obj_section *section, int thread)
c906108c 6159{
52f0bd74
AC
6160 int others = 0;
6161 struct breakpoint *b;
c906108c
SS
6162
6163 ALL_BREAKPOINTS (b)
672f9b60
KP
6164 others += (user_breakpoint_p (b)
6165 && breakpoint_has_pc (b, pspace, pc, section));
c906108c
SS
6166 if (others > 0)
6167 {
a3f17187
AC
6168 if (others == 1)
6169 printf_filtered (_("Note: breakpoint "));
6170 else /* if (others == ???) */
6171 printf_filtered (_("Note: breakpoints "));
c906108c 6172 ALL_BREAKPOINTS (b)
672f9b60 6173 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section))
0d381245
VP
6174 {
6175 others--;
6176 printf_filtered ("%d", b->number);
6177 if (b->thread == -1 && thread != -1)
6178 printf_filtered (" (all threads)");
6179 else if (b->thread != -1)
6180 printf_filtered (" (thread %d)", b->thread);
6181 printf_filtered ("%s%s ",
059fb39f 6182 ((b->enable_state == bp_disabled
f8eba3c6 6183 || b->enable_state == bp_call_disabled)
0d381245
VP
6184 ? " (disabled)"
6185 : b->enable_state == bp_permanent
6186 ? " (permanent)"
6187 : ""),
6188 (others > 1) ? ","
6189 : ((others == 1) ? " and" : ""));
6190 }
a3f17187 6191 printf_filtered (_("also set at pc "));
5af949e3 6192 fputs_filtered (paddress (gdbarch, pc), gdb_stdout);
c906108c
SS
6193 printf_filtered (".\n");
6194 }
6195}
6196\f
c906108c 6197
e4f237da
KB
6198/* Return true iff it is meaningful to use the address member of
6199 BPT. For some breakpoint types, the address member is irrelevant
6200 and it makes no sense to attempt to compare it to other addresses
6201 (or use it for any other purpose either).
6202
4a64f543
MS
6203 More specifically, each of the following breakpoint types will
6204 always have a zero valued address and we don't want to mark
6205 breakpoints of any of these types to be a duplicate of an actual
6206 breakpoint at address zero:
e4f237da
KB
6207
6208 bp_watchpoint
2d134ed3
PA
6209 bp_catchpoint
6210
6211*/
e4f237da
KB
6212
6213static int
6214breakpoint_address_is_meaningful (struct breakpoint *bpt)
6215{
6216 enum bptype type = bpt->type;
6217
2d134ed3
PA
6218 return (type != bp_watchpoint && type != bp_catchpoint);
6219}
6220
6221/* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6222 true if LOC1 and LOC2 represent the same watchpoint location. */
6223
6224static int
4a64f543
MS
6225watchpoint_locations_match (struct bp_location *loc1,
6226 struct bp_location *loc2)
2d134ed3 6227{
3a5c3e22
PA
6228 struct watchpoint *w1 = (struct watchpoint *) loc1->owner;
6229 struct watchpoint *w2 = (struct watchpoint *) loc2->owner;
6230
6231 /* Both of them must exist. */
6232 gdb_assert (w1 != NULL);
6233 gdb_assert (w2 != NULL);
2bdf28a0 6234
4a64f543
MS
6235 /* If the target can evaluate the condition expression in hardware,
6236 then we we need to insert both watchpoints even if they are at
6237 the same place. Otherwise the watchpoint will only trigger when
6238 the condition of whichever watchpoint was inserted evaluates to
6239 true, not giving a chance for GDB to check the condition of the
6240 other watchpoint. */
3a5c3e22 6241 if ((w1->cond_exp
4a64f543
MS
6242 && target_can_accel_watchpoint_condition (loc1->address,
6243 loc1->length,
0cf6dd15 6244 loc1->watchpoint_type,
3a5c3e22
PA
6245 w1->cond_exp))
6246 || (w2->cond_exp
4a64f543
MS
6247 && target_can_accel_watchpoint_condition (loc2->address,
6248 loc2->length,
0cf6dd15 6249 loc2->watchpoint_type,
3a5c3e22 6250 w2->cond_exp)))
0cf6dd15
TJB
6251 return 0;
6252
85d721b8
PA
6253 /* Note that this checks the owner's type, not the location's. In
6254 case the target does not support read watchpoints, but does
6255 support access watchpoints, we'll have bp_read_watchpoint
6256 watchpoints with hw_access locations. Those should be considered
6257 duplicates of hw_read locations. The hw_read locations will
6258 become hw_access locations later. */
2d134ed3
PA
6259 return (loc1->owner->type == loc2->owner->type
6260 && loc1->pspace->aspace == loc2->pspace->aspace
6261 && loc1->address == loc2->address
6262 && loc1->length == loc2->length);
e4f237da
KB
6263}
6264
6c95b8df
PA
6265/* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6266 same breakpoint location. In most targets, this can only be true
6267 if ASPACE1 matches ASPACE2. On targets that have global
6268 breakpoints, the address space doesn't really matter. */
6269
6270static int
6271breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
6272 struct address_space *aspace2, CORE_ADDR addr2)
6273{
6274 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6275 || aspace1 == aspace2)
6276 && addr1 == addr2);
6277}
6278
f1310107
TJB
6279/* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6280 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6281 matches ASPACE2. On targets that have global breakpoints, the address
6282 space doesn't really matter. */
6283
6284static int
6285breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
6286 int len1, struct address_space *aspace2,
6287 CORE_ADDR addr2)
6288{
6289 return ((gdbarch_has_global_breakpoints (target_gdbarch)
6290 || aspace1 == aspace2)
6291 && addr2 >= addr1 && addr2 < addr1 + len1);
6292}
6293
6294/* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6295 a ranged breakpoint. In most targets, a match happens only if ASPACE
6296 matches the breakpoint's address space. On targets that have global
6297 breakpoints, the address space doesn't really matter. */
6298
6299static int
6300breakpoint_location_address_match (struct bp_location *bl,
6301 struct address_space *aspace,
6302 CORE_ADDR addr)
6303{
6304 return (breakpoint_address_match (bl->pspace->aspace, bl->address,
6305 aspace, addr)
6306 || (bl->length
6307 && breakpoint_address_match_range (bl->pspace->aspace,
6308 bl->address, bl->length,
6309 aspace, addr)));
6310}
6311
1e4d1764
YQ
6312/* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6313 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6314 true, otherwise returns false. */
6315
6316static int
6317tracepoint_locations_match (struct bp_location *loc1,
6318 struct bp_location *loc2)
6319{
6320 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner))
6321 /* Since tracepoint locations are never duplicated with others', tracepoint
6322 locations at the same address of different tracepoints are regarded as
6323 different locations. */
6324 return (loc1->address == loc2->address && loc1->owner == loc2->owner);
6325 else
6326 return 0;
6327}
6328
2d134ed3
PA
6329/* Assuming LOC1 and LOC2's types' have meaningful target addresses
6330 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6331 represent the same location. */
6332
6333static int
4a64f543
MS
6334breakpoint_locations_match (struct bp_location *loc1,
6335 struct bp_location *loc2)
2d134ed3 6336{
2bdf28a0
JK
6337 int hw_point1, hw_point2;
6338
6339 /* Both of them must not be in moribund_locations. */
6340 gdb_assert (loc1->owner != NULL);
6341 gdb_assert (loc2->owner != NULL);
6342
6343 hw_point1 = is_hardware_watchpoint (loc1->owner);
6344 hw_point2 = is_hardware_watchpoint (loc2->owner);
2d134ed3
PA
6345
6346 if (hw_point1 != hw_point2)
6347 return 0;
6348 else if (hw_point1)
6349 return watchpoint_locations_match (loc1, loc2);
1e4d1764
YQ
6350 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner))
6351 return tracepoint_locations_match (loc1, loc2);
2d134ed3 6352 else
f1310107
TJB
6353 /* We compare bp_location.length in order to cover ranged breakpoints. */
6354 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
6355 loc2->pspace->aspace, loc2->address)
6356 && loc1->length == loc2->length);
2d134ed3
PA
6357}
6358
76897487
KB
6359static void
6360breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
6361 int bnum, int have_bnum)
6362{
f63fbe86
MS
6363 /* The longest string possibly returned by hex_string_custom
6364 is 50 chars. These must be at least that big for safety. */
6365 char astr1[64];
6366 char astr2[64];
76897487 6367
bb599908
PH
6368 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
6369 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
76897487 6370 if (have_bnum)
8a3fe4f8 6371 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
76897487
KB
6372 bnum, astr1, astr2);
6373 else
8a3fe4f8 6374 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
76897487
KB
6375}
6376
4a64f543
MS
6377/* Adjust a breakpoint's address to account for architectural
6378 constraints on breakpoint placement. Return the adjusted address.
6379 Note: Very few targets require this kind of adjustment. For most
6380 targets, this function is simply the identity function. */
76897487
KB
6381
6382static CORE_ADDR
a6d9a66e
UW
6383adjust_breakpoint_address (struct gdbarch *gdbarch,
6384 CORE_ADDR bpaddr, enum bptype bptype)
76897487 6385{
a6d9a66e 6386 if (!gdbarch_adjust_breakpoint_address_p (gdbarch))
76897487
KB
6387 {
6388 /* Very few targets need any kind of breakpoint adjustment. */
6389 return bpaddr;
6390 }
88f7da05
KB
6391 else if (bptype == bp_watchpoint
6392 || bptype == bp_hardware_watchpoint
6393 || bptype == bp_read_watchpoint
6394 || bptype == bp_access_watchpoint
fe798b75 6395 || bptype == bp_catchpoint)
88f7da05
KB
6396 {
6397 /* Watchpoints and the various bp_catch_* eventpoints should not
6398 have their addresses modified. */
6399 return bpaddr;
6400 }
76897487
KB
6401 else
6402 {
6403 CORE_ADDR adjusted_bpaddr;
6404
6405 /* Some targets have architectural constraints on the placement
6406 of breakpoint instructions. Obtain the adjusted address. */
a6d9a66e 6407 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
76897487
KB
6408
6409 /* An adjusted breakpoint address can significantly alter
6410 a user's expectations. Print a warning if an adjustment
6411 is required. */
6412 if (adjusted_bpaddr != bpaddr)
6413 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
6414
6415 return adjusted_bpaddr;
6416 }
6417}
6418
28010a5d
PA
6419void
6420init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops,
6421 struct breakpoint *owner)
7cc221ef 6422{
7cc221ef
DJ
6423 memset (loc, 0, sizeof (*loc));
6424
348d480f
PA
6425 gdb_assert (ops != NULL);
6426
28010a5d
PA
6427 loc->ops = ops;
6428 loc->owner = owner;
511a6cd4 6429 loc->cond = NULL;
b775012e 6430 loc->cond_bytecode = NULL;
0d381245
VP
6431 loc->shlib_disabled = 0;
6432 loc->enabled = 1;
e049a4b5 6433
28010a5d 6434 switch (owner->type)
e049a4b5
DJ
6435 {
6436 case bp_breakpoint:
6437 case bp_until:
6438 case bp_finish:
6439 case bp_longjmp:
6440 case bp_longjmp_resume:
186c406b
TT
6441 case bp_exception:
6442 case bp_exception_resume:
e049a4b5 6443 case bp_step_resume:
2c03e5be 6444 case bp_hp_step_resume:
e049a4b5
DJ
6445 case bp_watchpoint_scope:
6446 case bp_call_dummy:
aa7d318d 6447 case bp_std_terminate:
e049a4b5
DJ
6448 case bp_shlib_event:
6449 case bp_thread_event:
6450 case bp_overlay_event:
4efc6507 6451 case bp_jit_event:
0fd8e87f 6452 case bp_longjmp_master:
aa7d318d 6453 case bp_std_terminate_master:
186c406b 6454 case bp_exception_master:
0e30163f
JK
6455 case bp_gnu_ifunc_resolver:
6456 case bp_gnu_ifunc_resolver_return:
e7e0cddf 6457 case bp_dprintf:
e049a4b5 6458 loc->loc_type = bp_loc_software_breakpoint;
b775012e 6459 mark_breakpoint_location_modified (loc);
e049a4b5
DJ
6460 break;
6461 case bp_hardware_breakpoint:
6462 loc->loc_type = bp_loc_hardware_breakpoint;
b775012e 6463 mark_breakpoint_location_modified (loc);
e049a4b5
DJ
6464 break;
6465 case bp_hardware_watchpoint:
6466 case bp_read_watchpoint:
6467 case bp_access_watchpoint:
6468 loc->loc_type = bp_loc_hardware_watchpoint;
6469 break;
6470 case bp_watchpoint:
ce78b96d 6471 case bp_catchpoint:
15c3d785
PA
6472 case bp_tracepoint:
6473 case bp_fast_tracepoint:
0fb4aa4b 6474 case bp_static_tracepoint:
e049a4b5
DJ
6475 loc->loc_type = bp_loc_other;
6476 break;
6477 default:
e2e0b3e5 6478 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
e049a4b5
DJ
6479 }
6480
f431efe5 6481 loc->refc = 1;
28010a5d
PA
6482}
6483
6484/* Allocate a struct bp_location. */
6485
6486static struct bp_location *
6487allocate_bp_location (struct breakpoint *bpt)
6488{
348d480f
PA
6489 return bpt->ops->allocate_location (bpt);
6490}
7cc221ef 6491
f431efe5
PA
6492static void
6493free_bp_location (struct bp_location *loc)
fe3f5fa8 6494{
348d480f 6495 loc->ops->dtor (loc);
fe3f5fa8
VP
6496 xfree (loc);
6497}
6498
f431efe5
PA
6499/* Increment reference count. */
6500
6501static void
6502incref_bp_location (struct bp_location *bl)
6503{
6504 ++bl->refc;
6505}
6506
6507/* Decrement reference count. If the reference count reaches 0,
6508 destroy the bp_location. Sets *BLP to NULL. */
6509
6510static void
6511decref_bp_location (struct bp_location **blp)
6512{
0807b50c
PA
6513 gdb_assert ((*blp)->refc > 0);
6514
f431efe5
PA
6515 if (--(*blp)->refc == 0)
6516 free_bp_location (*blp);
6517 *blp = NULL;
6518}
6519
346774a9 6520/* Add breakpoint B at the end of the global breakpoint chain. */
c906108c 6521
346774a9
PA
6522static void
6523add_to_breakpoint_chain (struct breakpoint *b)
c906108c 6524{
346774a9 6525 struct breakpoint *b1;
c906108c 6526
346774a9
PA
6527 /* Add this breakpoint to the end of the chain so that a list of
6528 breakpoints will come out in order of increasing numbers. */
6529
6530 b1 = breakpoint_chain;
6531 if (b1 == 0)
6532 breakpoint_chain = b;
6533 else
6534 {
6535 while (b1->next)
6536 b1 = b1->next;
6537 b1->next = b;
6538 }
6539}
6540
6541/* Initializes breakpoint B with type BPTYPE and no locations yet. */
6542
6543static void
6544init_raw_breakpoint_without_location (struct breakpoint *b,
6545 struct gdbarch *gdbarch,
28010a5d 6546 enum bptype bptype,
c0a91b2b 6547 const struct breakpoint_ops *ops)
346774a9 6548{
c906108c 6549 memset (b, 0, sizeof (*b));
2219d63c 6550
348d480f
PA
6551 gdb_assert (ops != NULL);
6552
28010a5d 6553 b->ops = ops;
4d28f7a8 6554 b->type = bptype;
a6d9a66e 6555 b->gdbarch = gdbarch;
c906108c
SS
6556 b->language = current_language->la_language;
6557 b->input_radix = input_radix;
6558 b->thread = -1;
b5de0fa7 6559 b->enable_state = bp_enabled;
c906108c
SS
6560 b->next = 0;
6561 b->silent = 0;
6562 b->ignore_count = 0;
6563 b->commands = NULL;
818dd999 6564 b->frame_id = null_frame_id;
0d381245 6565 b->condition_not_parsed = 0;
84f4c1fe 6566 b->py_bp_object = NULL;
d0fb5eae 6567 b->related_breakpoint = b;
346774a9
PA
6568}
6569
6570/* Helper to set_raw_breakpoint below. Creates a breakpoint
6571 that has type BPTYPE and has no locations as yet. */
346774a9
PA
6572
6573static struct breakpoint *
6574set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
348d480f 6575 enum bptype bptype,
c0a91b2b 6576 const struct breakpoint_ops *ops)
346774a9
PA
6577{
6578 struct breakpoint *b = XNEW (struct breakpoint);
6579
348d480f 6580 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
c56053d2 6581 add_to_breakpoint_chain (b);
0d381245
VP
6582 return b;
6583}
6584
0e30163f
JK
6585/* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6586 resolutions should be made as the user specified the location explicitly
6587 enough. */
6588
0d381245 6589static void
0e30163f 6590set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
0d381245 6591{
2bdf28a0
JK
6592 gdb_assert (loc->owner != NULL);
6593
0d381245 6594 if (loc->owner->type == bp_breakpoint
1042e4c0 6595 || loc->owner->type == bp_hardware_breakpoint
d77f58be 6596 || is_tracepoint (loc->owner))
0d381245 6597 {
0e30163f 6598 int is_gnu_ifunc;
2c02bd72 6599 const char *function_name;
6a3a010b 6600 CORE_ADDR func_addr;
0e30163f 6601
2c02bd72 6602 find_pc_partial_function_gnu_ifunc (loc->address, &function_name,
6a3a010b 6603 &func_addr, NULL, &is_gnu_ifunc);
0e30163f
JK
6604
6605 if (is_gnu_ifunc && !explicit_loc)
6606 {
6607 struct breakpoint *b = loc->owner;
6608
6609 gdb_assert (loc->pspace == current_program_space);
2c02bd72 6610 if (gnu_ifunc_resolve_name (function_name,
0e30163f
JK
6611 &loc->requested_address))
6612 {
6613 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6614 loc->address = adjust_breakpoint_address (loc->gdbarch,
6615 loc->requested_address,
6616 b->type);
6617 }
6618 else if (b->type == bp_breakpoint && b->loc == loc
6619 && loc->next == NULL && b->related_breakpoint == b)
6620 {
6621 /* Create only the whole new breakpoint of this type but do not
6622 mess more complicated breakpoints with multiple locations. */
6623 b->type = bp_gnu_ifunc_resolver;
6a3a010b
MR
6624 /* Remember the resolver's address for use by the return
6625 breakpoint. */
6626 loc->related_address = func_addr;
0e30163f
JK
6627 }
6628 }
6629
2c02bd72
DE
6630 if (function_name)
6631 loc->function_name = xstrdup (function_name);
0d381245
VP
6632 }
6633}
6634
a6d9a66e 6635/* Attempt to determine architecture of location identified by SAL. */
1bfeeb0f 6636struct gdbarch *
a6d9a66e
UW
6637get_sal_arch (struct symtab_and_line sal)
6638{
6639 if (sal.section)
6640 return get_objfile_arch (sal.section->objfile);
6641 if (sal.symtab)
6642 return get_objfile_arch (sal.symtab->objfile);
6643
6644 return NULL;
6645}
6646
346774a9
PA
6647/* Low level routine for partially initializing a breakpoint of type
6648 BPTYPE. The newly created breakpoint's address, section, source
c56053d2 6649 file name, and line number are provided by SAL.
0d381245
VP
6650
6651 It is expected that the caller will complete the initialization of
6652 the newly created breakpoint struct as well as output any status
c56053d2 6653 information regarding the creation of a new breakpoint. */
0d381245 6654
346774a9
PA
6655static void
6656init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch,
28010a5d 6657 struct symtab_and_line sal, enum bptype bptype,
c0a91b2b 6658 const struct breakpoint_ops *ops)
0d381245 6659{
28010a5d 6660 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops);
346774a9 6661
3742cc8b 6662 add_location_to_breakpoint (b, &sal);
0d381245 6663
6c95b8df
PA
6664 if (bptype != bp_catchpoint)
6665 gdb_assert (sal.pspace != NULL);
6666
f8eba3c6
TT
6667 /* Store the program space that was used to set the breakpoint,
6668 except for ordinary breakpoints, which are independent of the
6669 program space. */
6670 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint)
6671 b->pspace = sal.pspace;
0d381245 6672
c906108c 6673 breakpoints_changed ();
346774a9 6674}
c906108c 6675
346774a9
PA
6676/* set_raw_breakpoint is a low level routine for allocating and
6677 partially initializing a breakpoint of type BPTYPE. The newly
6678 created breakpoint's address, section, source file name, and line
6679 number are provided by SAL. The newly created and partially
6680 initialized breakpoint is added to the breakpoint chain and
6681 is also returned as the value of this function.
6682
6683 It is expected that the caller will complete the initialization of
6684 the newly created breakpoint struct as well as output any status
6685 information regarding the creation of a new breakpoint. In
6686 particular, set_raw_breakpoint does NOT set the breakpoint
6687 number! Care should be taken to not allow an error to occur
6688 prior to completing the initialization of the breakpoint. If this
6689 should happen, a bogus breakpoint will be left on the chain. */
6690
6691struct breakpoint *
6692set_raw_breakpoint (struct gdbarch *gdbarch,
348d480f 6693 struct symtab_and_line sal, enum bptype bptype,
c0a91b2b 6694 const struct breakpoint_ops *ops)
346774a9
PA
6695{
6696 struct breakpoint *b = XNEW (struct breakpoint);
6697
348d480f 6698 init_raw_breakpoint (b, gdbarch, sal, bptype, ops);
c56053d2 6699 add_to_breakpoint_chain (b);
c906108c
SS
6700 return b;
6701}
6702
c2c6d25f
JM
6703
6704/* Note that the breakpoint object B describes a permanent breakpoint
6705 instruction, hard-wired into the inferior's code. */
6706void
6707make_breakpoint_permanent (struct breakpoint *b)
6708{
0d381245 6709 struct bp_location *bl;
cc59ec59 6710
b5de0fa7 6711 b->enable_state = bp_permanent;
c2c6d25f 6712
4a64f543
MS
6713 /* By definition, permanent breakpoints are already present in the
6714 code. Mark all locations as inserted. For now,
6715 make_breakpoint_permanent is called in just one place, so it's
6716 hard to say if it's reasonable to have permanent breakpoint with
e5dd4106 6717 multiple locations or not, but it's easy to implement. */
0d381245
VP
6718 for (bl = b->loc; bl; bl = bl->next)
6719 bl->inserted = 1;
c2c6d25f
JM
6720}
6721
53a5351d 6722/* Call this routine when stepping and nexting to enable a breakpoint
186c406b
TT
6723 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6724 initiated the operation. */
c906108c
SS
6725
6726void
186c406b 6727set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame)
c906108c 6728{
35df4500 6729 struct breakpoint *b, *b_tmp;
186c406b 6730 int thread = tp->num;
0fd8e87f
UW
6731
6732 /* To avoid having to rescan all objfile symbols at every step,
6733 we maintain a list of continually-inserted but always disabled
6734 longjmp "master" breakpoints. Here, we simply create momentary
6735 clones of those and enable them for the requested thread. */
35df4500 6736 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6c95b8df 6737 if (b->pspace == current_program_space
186c406b
TT
6738 && (b->type == bp_longjmp_master
6739 || b->type == bp_exception_master))
0fd8e87f 6740 {
06edf0c0
PA
6741 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
6742 struct breakpoint *clone;
cc59ec59 6743
06edf0c0
PA
6744 clone = momentary_breakpoint_from_master (b, type,
6745 &momentary_breakpoint_ops);
0fd8e87f
UW
6746 clone->thread = thread;
6747 }
186c406b
TT
6748
6749 tp->initiating_frame = frame;
c906108c
SS
6750}
6751
611c83ae 6752/* Delete all longjmp breakpoints from THREAD. */
c906108c 6753void
611c83ae 6754delete_longjmp_breakpoint (int thread)
c906108c 6755{
35df4500 6756 struct breakpoint *b, *b_tmp;
c906108c 6757
35df4500 6758 ALL_BREAKPOINTS_SAFE (b, b_tmp)
186c406b 6759 if (b->type == bp_longjmp || b->type == bp_exception)
611c83ae
PA
6760 {
6761 if (b->thread == thread)
6762 delete_breakpoint (b);
6763 }
c906108c
SS
6764}
6765
f59f708a
PA
6766void
6767delete_longjmp_breakpoint_at_next_stop (int thread)
6768{
6769 struct breakpoint *b, *b_tmp;
6770
6771 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6772 if (b->type == bp_longjmp || b->type == bp_exception)
6773 {
6774 if (b->thread == thread)
6775 b->disposition = disp_del_at_next_stop;
6776 }
6777}
6778
1900040c
MS
6779void
6780enable_overlay_breakpoints (void)
6781{
52f0bd74 6782 struct breakpoint *b;
1900040c
MS
6783
6784 ALL_BREAKPOINTS (b)
6785 if (b->type == bp_overlay_event)
6786 {
6787 b->enable_state = bp_enabled;
b60e7edf 6788 update_global_location_list (1);
c02f5703 6789 overlay_events_enabled = 1;
1900040c
MS
6790 }
6791}
6792
6793void
6794disable_overlay_breakpoints (void)
6795{
52f0bd74 6796 struct breakpoint *b;
1900040c
MS
6797
6798 ALL_BREAKPOINTS (b)
6799 if (b->type == bp_overlay_event)
6800 {
6801 b->enable_state = bp_disabled;
b60e7edf 6802 update_global_location_list (0);
c02f5703 6803 overlay_events_enabled = 0;
1900040c
MS
6804 }
6805}
6806
aa7d318d
TT
6807/* Set an active std::terminate breakpoint for each std::terminate
6808 master breakpoint. */
6809void
6810set_std_terminate_breakpoint (void)
6811{
35df4500 6812 struct breakpoint *b, *b_tmp;
aa7d318d 6813
35df4500 6814 ALL_BREAKPOINTS_SAFE (b, b_tmp)
aa7d318d
TT
6815 if (b->pspace == current_program_space
6816 && b->type == bp_std_terminate_master)
6817 {
06edf0c0
PA
6818 momentary_breakpoint_from_master (b, bp_std_terminate,
6819 &momentary_breakpoint_ops);
aa7d318d
TT
6820 }
6821}
6822
6823/* Delete all the std::terminate breakpoints. */
6824void
6825delete_std_terminate_breakpoint (void)
6826{
35df4500 6827 struct breakpoint *b, *b_tmp;
aa7d318d 6828
35df4500 6829 ALL_BREAKPOINTS_SAFE (b, b_tmp)
aa7d318d
TT
6830 if (b->type == bp_std_terminate)
6831 delete_breakpoint (b);
6832}
6833
c4093a6a 6834struct breakpoint *
a6d9a66e 6835create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
c4093a6a
JM
6836{
6837 struct breakpoint *b;
c4093a6a 6838
06edf0c0
PA
6839 b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
6840 &internal_breakpoint_ops);
6841
b5de0fa7 6842 b->enable_state = bp_enabled;
c4093a6a 6843 /* addr_string has to be used or breakpoint_re_set will delete me. */
5af949e3
UW
6844 b->addr_string
6845 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
c4093a6a 6846
b60e7edf 6847 update_global_location_list_nothrow (1);
74960c60 6848
c4093a6a
JM
6849 return b;
6850}
6851
6852void
6853remove_thread_event_breakpoints (void)
6854{
35df4500 6855 struct breakpoint *b, *b_tmp;
c4093a6a 6856
35df4500 6857 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6c95b8df
PA
6858 if (b->type == bp_thread_event
6859 && b->loc->pspace == current_program_space)
c4093a6a
JM
6860 delete_breakpoint (b);
6861}
6862
0101ce28
JJ
6863struct lang_and_radix
6864 {
6865 enum language lang;
6866 int radix;
6867 };
6868
4efc6507
DE
6869/* Create a breakpoint for JIT code registration and unregistration. */
6870
6871struct breakpoint *
6872create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
6873{
6874 struct breakpoint *b;
6875
06edf0c0
PA
6876 b = create_internal_breakpoint (gdbarch, address, bp_jit_event,
6877 &internal_breakpoint_ops);
4efc6507
DE
6878 update_global_location_list_nothrow (1);
6879 return b;
6880}
0101ce28 6881
03673fc7
PP
6882/* Remove JIT code registration and unregistration breakpoint(s). */
6883
6884void
6885remove_jit_event_breakpoints (void)
6886{
6887 struct breakpoint *b, *b_tmp;
6888
6889 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6890 if (b->type == bp_jit_event
6891 && b->loc->pspace == current_program_space)
6892 delete_breakpoint (b);
6893}
6894
cae688ec
JJ
6895void
6896remove_solib_event_breakpoints (void)
6897{
35df4500 6898 struct breakpoint *b, *b_tmp;
cae688ec 6899
35df4500 6900 ALL_BREAKPOINTS_SAFE (b, b_tmp)
6c95b8df
PA
6901 if (b->type == bp_shlib_event
6902 && b->loc->pspace == current_program_space)
cae688ec
JJ
6903 delete_breakpoint (b);
6904}
6905
6906struct breakpoint *
a6d9a66e 6907create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
cae688ec
JJ
6908{
6909 struct breakpoint *b;
6910
06edf0c0
PA
6911 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event,
6912 &internal_breakpoint_ops);
b60e7edf 6913 update_global_location_list_nothrow (1);
cae688ec
JJ
6914 return b;
6915}
6916
6917/* Disable any breakpoints that are on code in shared libraries. Only
6918 apply to enabled breakpoints, disabled ones can just stay disabled. */
6919
6920void
cb851954 6921disable_breakpoints_in_shlibs (void)
cae688ec 6922{
876fa593 6923 struct bp_location *loc, **locp_tmp;
cae688ec 6924
876fa593 6925 ALL_BP_LOCATIONS (loc, locp_tmp)
cae688ec 6926 {
2bdf28a0 6927 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
0d381245 6928 struct breakpoint *b = loc->owner;
2bdf28a0 6929
4a64f543
MS
6930 /* We apply the check to all breakpoints, including disabled for
6931 those with loc->duplicate set. This is so that when breakpoint
6932 becomes enabled, or the duplicate is removed, gdb will try to
6933 insert all breakpoints. If we don't set shlib_disabled here,
6934 we'll try to insert those breakpoints and fail. */
1042e4c0 6935 if (((b->type == bp_breakpoint)
508ccb1f 6936 || (b->type == bp_jit_event)
1042e4c0 6937 || (b->type == bp_hardware_breakpoint)
d77f58be 6938 || (is_tracepoint (b)))
6c95b8df 6939 && loc->pspace == current_program_space
0d381245 6940 && !loc->shlib_disabled
a77053c2 6941#ifdef PC_SOLIB
0d381245 6942 && PC_SOLIB (loc->address)
a77053c2 6943#else
6c95b8df 6944 && solib_name_from_address (loc->pspace, loc->address)
a77053c2
MK
6945#endif
6946 )
0d381245
VP
6947 {
6948 loc->shlib_disabled = 1;
6949 }
cae688ec
JJ
6950 }
6951}
6952
1e4d1764
YQ
6953/* Disable any breakpoints and tracepoints that are in an unloaded shared
6954 library. Only apply to enabled breakpoints, disabled ones can just stay
4a64f543 6955 disabled. */
84acb35a 6956
75149521 6957static void
84acb35a
JJ
6958disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
6959{
876fa593 6960 struct bp_location *loc, **locp_tmp;
84acb35a
JJ
6961 int disabled_shlib_breaks = 0;
6962
c86cf029
VP
6963 /* SunOS a.out shared libraries are always mapped, so do not
6964 disable breakpoints; they will only be reported as unloaded
6965 through clear_solib when GDB discards its shared library
6966 list. See clear_solib for more information. */
6967 if (exec_bfd != NULL
6968 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
6969 return;
6970
876fa593 6971 ALL_BP_LOCATIONS (loc, locp_tmp)
84acb35a 6972 {
2bdf28a0 6973 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
0d381245 6974 struct breakpoint *b = loc->owner;
cc59ec59 6975
1e4d1764 6976 if (solib->pspace == loc->pspace
e2dd7057 6977 && !loc->shlib_disabled
1e4d1764
YQ
6978 && (((b->type == bp_breakpoint
6979 || b->type == bp_jit_event
6980 || b->type == bp_hardware_breakpoint)
6981 && (loc->loc_type == bp_loc_hardware_breakpoint
6982 || loc->loc_type == bp_loc_software_breakpoint))
6983 || is_tracepoint (b))
e2dd7057 6984 && solib_contains_address_p (solib, loc->address))
84acb35a 6985 {
e2dd7057
PP
6986 loc->shlib_disabled = 1;
6987 /* At this point, we cannot rely on remove_breakpoint
6988 succeeding so we must mark the breakpoint as not inserted
6989 to prevent future errors occurring in remove_breakpoints. */
6990 loc->inserted = 0;
8d3788bd
VP
6991
6992 /* This may cause duplicate notifications for the same breakpoint. */
6993 observer_notify_breakpoint_modified (b);
6994
e2dd7057
PP
6995 if (!disabled_shlib_breaks)
6996 {
6997 target_terminal_ours_for_output ();
3e43a32a
MS
6998 warning (_("Temporarily disabling breakpoints "
6999 "for unloaded shared library \"%s\""),
e2dd7057 7000 solib->so_name);
84acb35a 7001 }
e2dd7057 7002 disabled_shlib_breaks = 1;
84acb35a
JJ
7003 }
7004 }
84acb35a
JJ
7005}
7006
ce78b96d
JB
7007/* FORK & VFORK catchpoints. */
7008
e29a4733
PA
7009/* An instance of this type is used to represent a fork or vfork
7010 catchpoint. It includes a "struct breakpoint" as a kind of base
7011 class; users downcast to "struct breakpoint *" when needed. A
7012 breakpoint is really of this type iff its ops pointer points to
7013 CATCH_FORK_BREAKPOINT_OPS. */
7014
7015struct fork_catchpoint
7016{
7017 /* The base class. */
7018 struct breakpoint base;
7019
7020 /* Process id of a child process whose forking triggered this
7021 catchpoint. This field is only valid immediately after this
7022 catchpoint has triggered. */
7023 ptid_t forked_inferior_pid;
7024};
7025
4a64f543
MS
7026/* Implement the "insert" breakpoint_ops method for fork
7027 catchpoints. */
ce78b96d 7028
77b06cd7
TJB
7029static int
7030insert_catch_fork (struct bp_location *bl)
ce78b96d 7031{
77b06cd7 7032 return target_insert_fork_catchpoint (PIDGET (inferior_ptid));
ce78b96d
JB
7033}
7034
4a64f543
MS
7035/* Implement the "remove" breakpoint_ops method for fork
7036 catchpoints. */
ce78b96d
JB
7037
7038static int
77b06cd7 7039remove_catch_fork (struct bp_location *bl)
ce78b96d
JB
7040{
7041 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
7042}
7043
7044/* Implement the "breakpoint_hit" breakpoint_ops method for fork
7045 catchpoints. */
7046
7047static int
f1310107 7048breakpoint_hit_catch_fork (const struct bp_location *bl,
09ac7c10
TT
7049 struct address_space *aspace, CORE_ADDR bp_addr,
7050 const struct target_waitstatus *ws)
ce78b96d 7051{
e29a4733
PA
7052 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7053
f90263c1
TT
7054 if (ws->kind != TARGET_WAITKIND_FORKED)
7055 return 0;
7056
7057 c->forked_inferior_pid = ws->value.related_pid;
7058 return 1;
ce78b96d
JB
7059}
7060
4a64f543
MS
7061/* Implement the "print_it" breakpoint_ops method for fork
7062 catchpoints. */
ce78b96d
JB
7063
7064static enum print_stop_action
348d480f 7065print_it_catch_fork (bpstat bs)
ce78b96d 7066{
36dfb11c 7067 struct ui_out *uiout = current_uiout;
348d480f
PA
7068 struct breakpoint *b = bs->breakpoint_at;
7069 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
e29a4733 7070
ce78b96d 7071 annotate_catchpoint (b->number);
36dfb11c
TT
7072 if (b->disposition == disp_del)
7073 ui_out_text (uiout, "\nTemporary catchpoint ");
7074 else
7075 ui_out_text (uiout, "\nCatchpoint ");
7076 if (ui_out_is_mi_like_p (uiout))
7077 {
7078 ui_out_field_string (uiout, "reason",
7079 async_reason_lookup (EXEC_ASYNC_FORK));
7080 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7081 }
7082 ui_out_field_int (uiout, "bkptno", b->number);
7083 ui_out_text (uiout, " (forked process ");
7084 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7085 ui_out_text (uiout, "), ");
ce78b96d
JB
7086 return PRINT_SRC_AND_LOC;
7087}
7088
4a64f543
MS
7089/* Implement the "print_one" breakpoint_ops method for fork
7090 catchpoints. */
ce78b96d
JB
7091
7092static void
a6d9a66e 7093print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc)
ce78b96d 7094{
e29a4733 7095 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
79a45b7d 7096 struct value_print_options opts;
79a45e25 7097 struct ui_out *uiout = current_uiout;
79a45b7d
TT
7098
7099 get_user_print_options (&opts);
7100
4a64f543
MS
7101 /* Field 4, the address, is omitted (which makes the columns not
7102 line up too nicely with the headers, but the effect is relatively
7103 readable). */
79a45b7d 7104 if (opts.addressprint)
ce78b96d
JB
7105 ui_out_field_skip (uiout, "addr");
7106 annotate_field (5);
7107 ui_out_text (uiout, "fork");
e29a4733 7108 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
ce78b96d
JB
7109 {
7110 ui_out_text (uiout, ", process ");
7111 ui_out_field_int (uiout, "what",
e29a4733 7112 ptid_get_pid (c->forked_inferior_pid));
ce78b96d
JB
7113 ui_out_spaces (uiout, 1);
7114 }
7115}
7116
7117/* Implement the "print_mention" breakpoint_ops method for fork
7118 catchpoints. */
7119
7120static void
7121print_mention_catch_fork (struct breakpoint *b)
7122{
7123 printf_filtered (_("Catchpoint %d (fork)"), b->number);
7124}
7125
6149aea9
PA
7126/* Implement the "print_recreate" breakpoint_ops method for fork
7127 catchpoints. */
7128
7129static void
7130print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp)
7131{
7132 fprintf_unfiltered (fp, "catch fork");
d9b3f62e 7133 print_recreate_thread (b, fp);
6149aea9
PA
7134}
7135
ce78b96d
JB
7136/* The breakpoint_ops structure to be used in fork catchpoints. */
7137
2060206e 7138static struct breakpoint_ops catch_fork_breakpoint_ops;
ce78b96d 7139
4a64f543
MS
7140/* Implement the "insert" breakpoint_ops method for vfork
7141 catchpoints. */
ce78b96d 7142
77b06cd7
TJB
7143static int
7144insert_catch_vfork (struct bp_location *bl)
ce78b96d 7145{
77b06cd7 7146 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
ce78b96d
JB
7147}
7148
4a64f543
MS
7149/* Implement the "remove" breakpoint_ops method for vfork
7150 catchpoints. */
ce78b96d
JB
7151
7152static int
77b06cd7 7153remove_catch_vfork (struct bp_location *bl)
ce78b96d
JB
7154{
7155 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
7156}
7157
7158/* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7159 catchpoints. */
7160
7161static int
f1310107 7162breakpoint_hit_catch_vfork (const struct bp_location *bl,
09ac7c10
TT
7163 struct address_space *aspace, CORE_ADDR bp_addr,
7164 const struct target_waitstatus *ws)
ce78b96d 7165{
e29a4733
PA
7166 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
7167
f90263c1
TT
7168 if (ws->kind != TARGET_WAITKIND_VFORKED)
7169 return 0;
7170
7171 c->forked_inferior_pid = ws->value.related_pid;
7172 return 1;
ce78b96d
JB
7173}
7174
4a64f543
MS
7175/* Implement the "print_it" breakpoint_ops method for vfork
7176 catchpoints. */
ce78b96d
JB
7177
7178static enum print_stop_action
348d480f 7179print_it_catch_vfork (bpstat bs)
ce78b96d 7180{
36dfb11c 7181 struct ui_out *uiout = current_uiout;
348d480f 7182 struct breakpoint *b = bs->breakpoint_at;
e29a4733
PA
7183 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
7184
ce78b96d 7185 annotate_catchpoint (b->number);
36dfb11c
TT
7186 if (b->disposition == disp_del)
7187 ui_out_text (uiout, "\nTemporary catchpoint ");
7188 else
7189 ui_out_text (uiout, "\nCatchpoint ");
7190 if (ui_out_is_mi_like_p (uiout))
7191 {
7192 ui_out_field_string (uiout, "reason",
7193 async_reason_lookup (EXEC_ASYNC_VFORK));
7194 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7195 }
7196 ui_out_field_int (uiout, "bkptno", b->number);
7197 ui_out_text (uiout, " (vforked process ");
7198 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
7199 ui_out_text (uiout, "), ");
ce78b96d
JB
7200 return PRINT_SRC_AND_LOC;
7201}
7202
4a64f543
MS
7203/* Implement the "print_one" breakpoint_ops method for vfork
7204 catchpoints. */
ce78b96d
JB
7205
7206static void
a6d9a66e 7207print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc)
ce78b96d 7208{
e29a4733 7209 struct fork_catchpoint *c = (struct fork_catchpoint *) b;
79a45b7d 7210 struct value_print_options opts;
79a45e25 7211 struct ui_out *uiout = current_uiout;
79a45b7d
TT
7212
7213 get_user_print_options (&opts);
4a64f543
MS
7214 /* Field 4, the address, is omitted (which makes the columns not
7215 line up too nicely with the headers, but the effect is relatively
7216 readable). */
79a45b7d 7217 if (opts.addressprint)
ce78b96d
JB
7218 ui_out_field_skip (uiout, "addr");
7219 annotate_field (5);
7220 ui_out_text (uiout, "vfork");
e29a4733 7221 if (!ptid_equal (c->forked_inferior_pid, null_ptid))
ce78b96d
JB
7222 {
7223 ui_out_text (uiout, ", process ");
7224 ui_out_field_int (uiout, "what",
e29a4733 7225 ptid_get_pid (c->forked_inferior_pid));
ce78b96d
JB
7226 ui_out_spaces (uiout, 1);
7227 }
7228}
7229
7230/* Implement the "print_mention" breakpoint_ops method for vfork
7231 catchpoints. */
7232
7233static void
7234print_mention_catch_vfork (struct breakpoint *b)
7235{
7236 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
7237}
7238
6149aea9
PA
7239/* Implement the "print_recreate" breakpoint_ops method for vfork
7240 catchpoints. */
7241
7242static void
7243print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp)
7244{
7245 fprintf_unfiltered (fp, "catch vfork");
d9b3f62e 7246 print_recreate_thread (b, fp);
6149aea9
PA
7247}
7248
ce78b96d
JB
7249/* The breakpoint_ops structure to be used in vfork catchpoints. */
7250
2060206e 7251static struct breakpoint_ops catch_vfork_breakpoint_ops;
ce78b96d 7252
edcc5120
TT
7253/* An instance of this type is used to represent an solib catchpoint.
7254 It includes a "struct breakpoint" as a kind of base class; users
7255 downcast to "struct breakpoint *" when needed. A breakpoint is
7256 really of this type iff its ops pointer points to
7257 CATCH_SOLIB_BREAKPOINT_OPS. */
7258
7259struct solib_catchpoint
7260{
7261 /* The base class. */
7262 struct breakpoint base;
7263
7264 /* True for "catch load", false for "catch unload". */
7265 unsigned char is_load;
7266
7267 /* Regular expression to match, if any. COMPILED is only valid when
7268 REGEX is non-NULL. */
7269 char *regex;
7270 regex_t compiled;
7271};
7272
7273static void
7274dtor_catch_solib (struct breakpoint *b)
7275{
7276 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7277
7278 if (self->regex)
7279 regfree (&self->compiled);
7280 xfree (self->regex);
7281
7282 base_breakpoint_ops.dtor (b);
7283}
7284
7285static int
7286insert_catch_solib (struct bp_location *ignore)
7287{
7288 return 0;
7289}
7290
7291static int
7292remove_catch_solib (struct bp_location *ignore)
7293{
7294 return 0;
7295}
7296
7297static int
7298breakpoint_hit_catch_solib (const struct bp_location *bl,
7299 struct address_space *aspace,
7300 CORE_ADDR bp_addr,
7301 const struct target_waitstatus *ws)
7302{
7303 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner;
7304 struct breakpoint *other;
7305
7306 if (ws->kind == TARGET_WAITKIND_LOADED)
7307 return 1;
7308
7309 ALL_BREAKPOINTS (other)
7310 {
7311 struct bp_location *other_bl;
7312
7313 if (other == bl->owner)
7314 continue;
7315
7316 if (other->type != bp_shlib_event)
7317 continue;
7318
7319 if (self->base.pspace != NULL && other->pspace != self->base.pspace)
7320 continue;
7321
7322 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next)
7323 {
7324 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws))
7325 return 1;
7326 }
7327 }
7328
7329 return 0;
7330}
7331
7332static void
7333check_status_catch_solib (struct bpstats *bs)
7334{
7335 struct solib_catchpoint *self
7336 = (struct solib_catchpoint *) bs->breakpoint_at;
7337 int ix;
7338
7339 if (self->is_load)
7340 {
7341 struct so_list *iter;
7342
7343 for (ix = 0;
7344 VEC_iterate (so_list_ptr, current_program_space->added_solibs,
7345 ix, iter);
7346 ++ix)
7347 {
7348 if (!self->regex
7349 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0)
7350 return;
7351 }
7352 }
7353 else
7354 {
7355 char *iter;
7356
7357 for (ix = 0;
7358 VEC_iterate (char_ptr, current_program_space->deleted_solibs,
7359 ix, iter);
7360 ++ix)
7361 {
7362 if (!self->regex
7363 || regexec (&self->compiled, iter, 0, NULL, 0) == 0)
7364 return;
7365 }
7366 }
7367
7368 bs->stop = 0;
7369 bs->print_it = print_it_noop;
7370}
7371
7372static enum print_stop_action
7373print_it_catch_solib (bpstat bs)
7374{
7375 struct breakpoint *b = bs->breakpoint_at;
7376 struct ui_out *uiout = current_uiout;
7377
7378 annotate_catchpoint (b->number);
7379 if (b->disposition == disp_del)
7380 ui_out_text (uiout, "\nTemporary catchpoint ");
7381 else
7382 ui_out_text (uiout, "\nCatchpoint ");
7383 ui_out_field_int (uiout, "bkptno", b->number);
7384 ui_out_text (uiout, "\n");
7385 if (ui_out_is_mi_like_p (uiout))
7386 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7387 print_solib_event (1);
7388 return PRINT_SRC_AND_LOC;
7389}
7390
7391static void
7392print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
7393{
7394 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7395 struct value_print_options opts;
7396 struct ui_out *uiout = current_uiout;
7397 char *msg;
7398
7399 get_user_print_options (&opts);
7400 /* Field 4, the address, is omitted (which makes the columns not
7401 line up too nicely with the headers, but the effect is relatively
7402 readable). */
7403 if (opts.addressprint)
7404 {
7405 annotate_field (4);
7406 ui_out_field_skip (uiout, "addr");
7407 }
7408
7409 annotate_field (5);
7410 if (self->is_load)
7411 {
7412 if (self->regex)
7413 msg = xstrprintf (_("load of library matching %s"), self->regex);
7414 else
7415 msg = xstrdup (_("load of library"));
7416 }
7417 else
7418 {
7419 if (self->regex)
7420 msg = xstrprintf (_("unload of library matching %s"), self->regex);
7421 else
7422 msg = xstrdup (_("unload of library"));
7423 }
7424 ui_out_field_string (uiout, "what", msg);
7425 xfree (msg);
7426}
7427
7428static void
7429print_mention_catch_solib (struct breakpoint *b)
7430{
7431 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7432
7433 printf_filtered (_("Catchpoint %d (%s)"), b->number,
7434 self->is_load ? "load" : "unload");
7435}
7436
7437static void
7438print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
7439{
7440 struct solib_catchpoint *self = (struct solib_catchpoint *) b;
7441
7442 fprintf_unfiltered (fp, "%s %s",
7443 b->disposition == disp_del ? "tcatch" : "catch",
7444 self->is_load ? "load" : "unload");
7445 if (self->regex)
7446 fprintf_unfiltered (fp, " %s", self->regex);
7447 fprintf_unfiltered (fp, "\n");
7448}
7449
7450static struct breakpoint_ops catch_solib_breakpoint_ops;
7451
7452/* A helper function that does all the work for "catch load" and
7453 "catch unload". */
7454
7455static void
7456catch_load_or_unload (char *arg, int from_tty, int is_load,
7457 struct cmd_list_element *command)
7458{
7459 struct solib_catchpoint *c;
7460 struct gdbarch *gdbarch = get_current_arch ();
7461 int tempflag;
edcc5120
TT
7462 struct cleanup *cleanup;
7463
7464 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
7465
7466 if (!arg)
7467 arg = "";
7468 arg = skip_spaces (arg);
7469
7470 c = XCNEW (struct solib_catchpoint);
7471 cleanup = make_cleanup (xfree, c);
7472
7473 if (*arg != '\0')
7474 {
7475 int errcode;
7476
7477 errcode = regcomp (&c->compiled, arg, REG_NOSUB);
7478 if (errcode != 0)
7479 {
7480 char *err = get_regcomp_error (errcode, &c->compiled);
7481
7482 make_cleanup (xfree, err);
7483 error (_("Invalid regexp (%s): %s"), err, arg);
7484 }
7485 c->regex = xstrdup (arg);
7486 }
7487
7488 c->is_load = is_load;
7489 init_catchpoint (&c->base, gdbarch, tempflag, NULL,
7490 &catch_solib_breakpoint_ops);
7491
7492 discard_cleanups (cleanup);
7493 install_breakpoint (0, &c->base, 1);
7494}
7495
7496static void
7497catch_load_command_1 (char *arg, int from_tty,
7498 struct cmd_list_element *command)
7499{
7500 catch_load_or_unload (arg, from_tty, 1, command);
7501}
7502
7503static void
7504catch_unload_command_1 (char *arg, int from_tty,
7505 struct cmd_list_element *command)
7506{
7507 catch_load_or_unload (arg, from_tty, 0, command);
7508}
7509
fa3064dd
YQ
7510DEF_VEC_I(int);
7511
be5c67c1
PA
7512/* An instance of this type is used to represent a syscall catchpoint.
7513 It includes a "struct breakpoint" as a kind of base class; users
7514 downcast to "struct breakpoint *" when needed. A breakpoint is
7515 really of this type iff its ops pointer points to
7516 CATCH_SYSCALL_BREAKPOINT_OPS. */
7517
7518struct syscall_catchpoint
7519{
7520 /* The base class. */
7521 struct breakpoint base;
7522
7523 /* Syscall numbers used for the 'catch syscall' feature. If no
7524 syscall has been specified for filtering, its value is NULL.
7525 Otherwise, it holds a list of all syscalls to be caught. The
7526 list elements are allocated with xmalloc. */
7527 VEC(int) *syscalls_to_be_caught;
7528};
7529
7530/* Implement the "dtor" breakpoint_ops method for syscall
7531 catchpoints. */
7532
7533static void
7534dtor_catch_syscall (struct breakpoint *b)
7535{
7536 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7537
7538 VEC_free (int, c->syscalls_to_be_caught);
348d480f 7539
2060206e 7540 base_breakpoint_ops.dtor (b);
be5c67c1
PA
7541}
7542
fa3064dd
YQ
7543static const struct inferior_data *catch_syscall_inferior_data = NULL;
7544
7545struct catch_syscall_inferior_data
7546{
7547 /* We keep a count of the number of times the user has requested a
7548 particular syscall to be tracked, and pass this information to the
7549 target. This lets capable targets implement filtering directly. */
7550
7551 /* Number of times that "any" syscall is requested. */
7552 int any_syscall_count;
7553
7554 /* Count of each system call. */
7555 VEC(int) *syscalls_counts;
7556
7557 /* This counts all syscall catch requests, so we can readily determine
7558 if any catching is necessary. */
7559 int total_syscalls_count;
7560};
7561
7562static struct catch_syscall_inferior_data*
7563get_catch_syscall_inferior_data (struct inferior *inf)
7564{
7565 struct catch_syscall_inferior_data *inf_data;
7566
7567 inf_data = inferior_data (inf, catch_syscall_inferior_data);
7568 if (inf_data == NULL)
7569 {
7570 inf_data = XZALLOC (struct catch_syscall_inferior_data);
7571 set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
7572 }
7573
7574 return inf_data;
7575}
7576
7577static void
7578catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
7579{
7580 xfree (arg);
7581}
7582
7583
a96d9b2e
SDJ
7584/* Implement the "insert" breakpoint_ops method for syscall
7585 catchpoints. */
7586
77b06cd7
TJB
7587static int
7588insert_catch_syscall (struct bp_location *bl)
a96d9b2e 7589{
be5c67c1 7590 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
a96d9b2e 7591 struct inferior *inf = current_inferior ();
fa3064dd
YQ
7592 struct catch_syscall_inferior_data *inf_data
7593 = get_catch_syscall_inferior_data (inf);
a96d9b2e 7594
fa3064dd 7595 ++inf_data->total_syscalls_count;
be5c67c1 7596 if (!c->syscalls_to_be_caught)
fa3064dd 7597 ++inf_data->any_syscall_count;
a96d9b2e
SDJ
7598 else
7599 {
7600 int i, iter;
cc59ec59 7601
a96d9b2e 7602 for (i = 0;
be5c67c1 7603 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
a96d9b2e
SDJ
7604 i++)
7605 {
7606 int elem;
cc59ec59 7607
fa3064dd 7608 if (iter >= VEC_length (int, inf_data->syscalls_counts))
a96d9b2e 7609 {
fa3064dd 7610 int old_size = VEC_length (int, inf_data->syscalls_counts);
3e43a32a
MS
7611 uintptr_t vec_addr_offset
7612 = old_size * ((uintptr_t) sizeof (int));
a96d9b2e 7613 uintptr_t vec_addr;
fa3064dd
YQ
7614 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1);
7615 vec_addr = ((uintptr_t) VEC_address (int,
7616 inf_data->syscalls_counts)
7617 + vec_addr_offset);
a96d9b2e
SDJ
7618 memset ((void *) vec_addr, 0,
7619 (iter + 1 - old_size) * sizeof (int));
7620 }
fa3064dd
YQ
7621 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7622 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem);
a96d9b2e
SDJ
7623 }
7624 }
7625
77b06cd7 7626 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
fa3064dd
YQ
7627 inf_data->total_syscalls_count != 0,
7628 inf_data->any_syscall_count,
7629 VEC_length (int,
7630 inf_data->syscalls_counts),
7631 VEC_address (int,
7632 inf_data->syscalls_counts));
a96d9b2e
SDJ
7633}
7634
7635/* Implement the "remove" breakpoint_ops method for syscall
7636 catchpoints. */
7637
7638static int
77b06cd7 7639remove_catch_syscall (struct bp_location *bl)
a96d9b2e 7640{
be5c67c1 7641 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner;
a96d9b2e 7642 struct inferior *inf = current_inferior ();
fa3064dd
YQ
7643 struct catch_syscall_inferior_data *inf_data
7644 = get_catch_syscall_inferior_data (inf);
a96d9b2e 7645
fa3064dd 7646 --inf_data->total_syscalls_count;
be5c67c1 7647 if (!c->syscalls_to_be_caught)
fa3064dd 7648 --inf_data->any_syscall_count;
a96d9b2e
SDJ
7649 else
7650 {
7651 int i, iter;
cc59ec59 7652
a96d9b2e 7653 for (i = 0;
be5c67c1 7654 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
a96d9b2e
SDJ
7655 i++)
7656 {
7657 int elem;
fa3064dd 7658 if (iter >= VEC_length (int, inf_data->syscalls_counts))
a96d9b2e
SDJ
7659 /* Shouldn't happen. */
7660 continue;
fa3064dd
YQ
7661 elem = VEC_index (int, inf_data->syscalls_counts, iter);
7662 VEC_replace (int, inf_data->syscalls_counts, iter, --elem);
a96d9b2e
SDJ
7663 }
7664 }
7665
7666 return target_set_syscall_catchpoint (PIDGET (inferior_ptid),
fa3064dd
YQ
7667 inf_data->total_syscalls_count != 0,
7668 inf_data->any_syscall_count,
7669 VEC_length (int,
7670 inf_data->syscalls_counts),
3e43a32a 7671 VEC_address (int,
fa3064dd 7672 inf_data->syscalls_counts));
a96d9b2e
SDJ
7673}
7674
7675/* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7676 catchpoints. */
7677
7678static int
f1310107 7679breakpoint_hit_catch_syscall (const struct bp_location *bl,
09ac7c10
TT
7680 struct address_space *aspace, CORE_ADDR bp_addr,
7681 const struct target_waitstatus *ws)
a96d9b2e 7682{
4a64f543
MS
7683 /* We must check if we are catching specific syscalls in this
7684 breakpoint. If we are, then we must guarantee that the called
7685 syscall is the same syscall we are catching. */
a96d9b2e 7686 int syscall_number = 0;
be5c67c1
PA
7687 const struct syscall_catchpoint *c
7688 = (const struct syscall_catchpoint *) bl->owner;
a96d9b2e 7689
f90263c1
TT
7690 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY
7691 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN)
a96d9b2e
SDJ
7692 return 0;
7693
f90263c1
TT
7694 syscall_number = ws->value.syscall_number;
7695
a96d9b2e 7696 /* Now, checking if the syscall is the same. */
be5c67c1 7697 if (c->syscalls_to_be_caught)
a96d9b2e
SDJ
7698 {
7699 int i, iter;
cc59ec59 7700
a96d9b2e 7701 for (i = 0;
be5c67c1 7702 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
a96d9b2e
SDJ
7703 i++)
7704 if (syscall_number == iter)
7705 break;
7706 /* Not the same. */
7707 if (!iter)
7708 return 0;
7709 }
7710
7711 return 1;
7712}
7713
7714/* Implement the "print_it" breakpoint_ops method for syscall
7715 catchpoints. */
7716
7717static enum print_stop_action
348d480f 7718print_it_catch_syscall (bpstat bs)
a96d9b2e 7719{
36dfb11c 7720 struct ui_out *uiout = current_uiout;
348d480f 7721 struct breakpoint *b = bs->breakpoint_at;
a96d9b2e
SDJ
7722 /* These are needed because we want to know in which state a
7723 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7724 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7725 must print "called syscall" or "returned from syscall". */
7726 ptid_t ptid;
7727 struct target_waitstatus last;
7728 struct syscall s;
a96d9b2e
SDJ
7729
7730 get_last_target_status (&ptid, &last);
7731
7732 get_syscall_by_number (last.value.syscall_number, &s);
7733
7734 annotate_catchpoint (b->number);
7735
36dfb11c
TT
7736 if (b->disposition == disp_del)
7737 ui_out_text (uiout, "\nTemporary catchpoint ");
a96d9b2e 7738 else
36dfb11c
TT
7739 ui_out_text (uiout, "\nCatchpoint ");
7740 if (ui_out_is_mi_like_p (uiout))
7741 {
7742 ui_out_field_string (uiout, "reason",
7743 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
7744 ? EXEC_ASYNC_SYSCALL_ENTRY
7745 : EXEC_ASYNC_SYSCALL_RETURN));
7746 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
7747 }
7748 ui_out_field_int (uiout, "bkptno", b->number);
a96d9b2e
SDJ
7749
7750 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
36dfb11c
TT
7751 ui_out_text (uiout, " (call to syscall ");
7752 else
7753 ui_out_text (uiout, " (returned from syscall ");
a96d9b2e 7754
36dfb11c
TT
7755 if (s.name == NULL || ui_out_is_mi_like_p (uiout))
7756 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
7757 if (s.name != NULL)
7758 ui_out_field_string (uiout, "syscall-name", s.name);
7759
7760 ui_out_text (uiout, "), ");
a96d9b2e
SDJ
7761
7762 return PRINT_SRC_AND_LOC;
7763}
7764
7765/* Implement the "print_one" breakpoint_ops method for syscall
7766 catchpoints. */
7767
7768static void
7769print_one_catch_syscall (struct breakpoint *b,
f1310107 7770 struct bp_location **last_loc)
a96d9b2e 7771{
be5c67c1 7772 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
a96d9b2e 7773 struct value_print_options opts;
79a45e25 7774 struct ui_out *uiout = current_uiout;
a96d9b2e
SDJ
7775
7776 get_user_print_options (&opts);
4a64f543
MS
7777 /* Field 4, the address, is omitted (which makes the columns not
7778 line up too nicely with the headers, but the effect is relatively
7779 readable). */
a96d9b2e
SDJ
7780 if (opts.addressprint)
7781 ui_out_field_skip (uiout, "addr");
7782 annotate_field (5);
7783
be5c67c1
PA
7784 if (c->syscalls_to_be_caught
7785 && VEC_length (int, c->syscalls_to_be_caught) > 1)
a96d9b2e
SDJ
7786 ui_out_text (uiout, "syscalls \"");
7787 else
7788 ui_out_text (uiout, "syscall \"");
7789
be5c67c1 7790 if (c->syscalls_to_be_caught)
a96d9b2e
SDJ
7791 {
7792 int i, iter;
7793 char *text = xstrprintf ("%s", "");
cc59ec59 7794
a96d9b2e 7795 for (i = 0;
be5c67c1 7796 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
a96d9b2e
SDJ
7797 i++)
7798 {
7799 char *x = text;
7800 struct syscall s;
7801 get_syscall_by_number (iter, &s);
7802
7803 if (s.name != NULL)
7804 text = xstrprintf ("%s%s, ", text, s.name);
7805 else
7806 text = xstrprintf ("%s%d, ", text, iter);
7807
7808 /* We have to xfree the last 'text' (now stored at 'x')
e5dd4106 7809 because xstrprintf dynamically allocates new space for it
a96d9b2e
SDJ
7810 on every call. */
7811 xfree (x);
7812 }
7813 /* Remove the last comma. */
7814 text[strlen (text) - 2] = '\0';
7815 ui_out_field_string (uiout, "what", text);
7816 }
7817 else
7818 ui_out_field_string (uiout, "what", "<any syscall>");
7819 ui_out_text (uiout, "\" ");
7820}
7821
7822/* Implement the "print_mention" breakpoint_ops method for syscall
7823 catchpoints. */
7824
7825static void
7826print_mention_catch_syscall (struct breakpoint *b)
7827{
be5c67c1
PA
7828 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7829
7830 if (c->syscalls_to_be_caught)
a96d9b2e
SDJ
7831 {
7832 int i, iter;
7833
be5c67c1 7834 if (VEC_length (int, c->syscalls_to_be_caught) > 1)
a96d9b2e
SDJ
7835 printf_filtered (_("Catchpoint %d (syscalls"), b->number);
7836 else
7837 printf_filtered (_("Catchpoint %d (syscall"), b->number);
7838
7839 for (i = 0;
be5c67c1 7840 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
a96d9b2e
SDJ
7841 i++)
7842 {
7843 struct syscall s;
7844 get_syscall_by_number (iter, &s);
7845
7846 if (s.name)
7847 printf_filtered (" '%s' [%d]", s.name, s.number);
7848 else
7849 printf_filtered (" %d", s.number);
7850 }
7851 printf_filtered (")");
7852 }
7853 else
7854 printf_filtered (_("Catchpoint %d (any syscall)"),
7855 b->number);
7856}
7857
6149aea9
PA
7858/* Implement the "print_recreate" breakpoint_ops method for syscall
7859 catchpoints. */
7860
7861static void
7862print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
7863{
be5c67c1
PA
7864 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
7865
6149aea9
PA
7866 fprintf_unfiltered (fp, "catch syscall");
7867
be5c67c1 7868 if (c->syscalls_to_be_caught)
6149aea9
PA
7869 {
7870 int i, iter;
7871
7872 for (i = 0;
be5c67c1 7873 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
6149aea9
PA
7874 i++)
7875 {
7876 struct syscall s;
7877
7878 get_syscall_by_number (iter, &s);
7879 if (s.name)
7880 fprintf_unfiltered (fp, " %s", s.name);
7881 else
7882 fprintf_unfiltered (fp, " %d", s.number);
7883 }
7884 }
d9b3f62e 7885 print_recreate_thread (b, fp);
6149aea9
PA
7886}
7887
a96d9b2e
SDJ
7888/* The breakpoint_ops structure to be used in syscall catchpoints. */
7889
2060206e 7890static struct breakpoint_ops catch_syscall_breakpoint_ops;
a96d9b2e
SDJ
7891
7892/* Returns non-zero if 'b' is a syscall catchpoint. */
7893
7894static int
7895syscall_catchpoint_p (struct breakpoint *b)
7896{
7897 return (b->ops == &catch_syscall_breakpoint_ops);
7898}
7899
346774a9
PA
7900/* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7901 is non-zero, then make the breakpoint temporary. If COND_STRING is
7902 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7903 the breakpoint_ops structure associated to the catchpoint. */
ce78b96d 7904
346774a9
PA
7905static void
7906init_catchpoint (struct breakpoint *b,
7907 struct gdbarch *gdbarch, int tempflag,
7908 char *cond_string,
c0a91b2b 7909 const struct breakpoint_ops *ops)
c906108c 7910{
c5aa993b 7911 struct symtab_and_line sal;
346774a9 7912
fe39c653 7913 init_sal (&sal);
6c95b8df 7914 sal.pspace = current_program_space;
c5aa993b 7915
28010a5d 7916 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
ce78b96d 7917
1b36a34b 7918 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
b5de0fa7 7919 b->disposition = tempflag ? disp_del : disp_donttouch;
346774a9
PA
7920}
7921
28010a5d 7922void
3ea46bff 7923install_breakpoint (int internal, struct breakpoint *b, int update_gll)
c56053d2
PA
7924{
7925 add_to_breakpoint_chain (b);
3a5c3e22
PA
7926 set_breakpoint_number (internal, b);
7927 if (!internal)
7928 mention (b);
c56053d2 7929 observer_notify_breakpoint_created (b);
3ea46bff
YQ
7930
7931 if (update_gll)
7932 update_global_location_list (1);
c56053d2
PA
7933}
7934
9b70b993 7935static void
a6d9a66e
UW
7936create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
7937 int tempflag, char *cond_string,
c0a91b2b 7938 const struct breakpoint_ops *ops)
c906108c 7939{
e29a4733 7940 struct fork_catchpoint *c = XNEW (struct fork_catchpoint);
ce78b96d 7941
e29a4733
PA
7942 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops);
7943
7944 c->forked_inferior_pid = null_ptid;
7945
3ea46bff 7946 install_breakpoint (0, &c->base, 1);
c906108c
SS
7947}
7948
fe798b75
JB
7949/* Exec catchpoints. */
7950
b4d90040
PA
7951/* An instance of this type is used to represent an exec catchpoint.
7952 It includes a "struct breakpoint" as a kind of base class; users
7953 downcast to "struct breakpoint *" when needed. A breakpoint is
7954 really of this type iff its ops pointer points to
7955 CATCH_EXEC_BREAKPOINT_OPS. */
7956
7957struct exec_catchpoint
7958{
7959 /* The base class. */
7960 struct breakpoint base;
7961
7962 /* Filename of a program whose exec triggered this catchpoint.
7963 This field is only valid immediately after this catchpoint has
7964 triggered. */
7965 char *exec_pathname;
7966};
7967
7968/* Implement the "dtor" breakpoint_ops method for exec
7969 catchpoints. */
7970
7971static void
7972dtor_catch_exec (struct breakpoint *b)
7973{
7974 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
7975
7976 xfree (c->exec_pathname);
348d480f 7977
2060206e 7978 base_breakpoint_ops.dtor (b);
b4d90040
PA
7979}
7980
77b06cd7
TJB
7981static int
7982insert_catch_exec (struct bp_location *bl)
c906108c 7983{
77b06cd7 7984 return target_insert_exec_catchpoint (PIDGET (inferior_ptid));
fe798b75 7985}
c906108c 7986
fe798b75 7987static int
77b06cd7 7988remove_catch_exec (struct bp_location *bl)
fe798b75
JB
7989{
7990 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
7991}
c906108c 7992
fe798b75 7993static int
f1310107 7994breakpoint_hit_catch_exec (const struct bp_location *bl,
09ac7c10
TT
7995 struct address_space *aspace, CORE_ADDR bp_addr,
7996 const struct target_waitstatus *ws)
fe798b75 7997{
b4d90040
PA
7998 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
7999
f90263c1
TT
8000 if (ws->kind != TARGET_WAITKIND_EXECD)
8001 return 0;
8002
8003 c->exec_pathname = xstrdup (ws->value.execd_pathname);
8004 return 1;
fe798b75 8005}
c906108c 8006
fe798b75 8007static enum print_stop_action
348d480f 8008print_it_catch_exec (bpstat bs)
fe798b75 8009{
36dfb11c 8010 struct ui_out *uiout = current_uiout;
348d480f 8011 struct breakpoint *b = bs->breakpoint_at;
b4d90040
PA
8012 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
8013
fe798b75 8014 annotate_catchpoint (b->number);
36dfb11c
TT
8015 if (b->disposition == disp_del)
8016 ui_out_text (uiout, "\nTemporary catchpoint ");
8017 else
8018 ui_out_text (uiout, "\nCatchpoint ");
8019 if (ui_out_is_mi_like_p (uiout))
8020 {
8021 ui_out_field_string (uiout, "reason",
8022 async_reason_lookup (EXEC_ASYNC_EXEC));
8023 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
8024 }
8025 ui_out_field_int (uiout, "bkptno", b->number);
8026 ui_out_text (uiout, " (exec'd ");
8027 ui_out_field_string (uiout, "new-exec", c->exec_pathname);
8028 ui_out_text (uiout, "), ");
8029
fe798b75 8030 return PRINT_SRC_AND_LOC;
c906108c
SS
8031}
8032
fe798b75 8033static void
a6d9a66e 8034print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc)
fe798b75 8035{
b4d90040 8036 struct exec_catchpoint *c = (struct exec_catchpoint *) b;
fe798b75 8037 struct value_print_options opts;
79a45e25 8038 struct ui_out *uiout = current_uiout;
fe798b75
JB
8039
8040 get_user_print_options (&opts);
8041
8042 /* Field 4, the address, is omitted (which makes the columns
8043 not line up too nicely with the headers, but the effect
8044 is relatively readable). */
8045 if (opts.addressprint)
8046 ui_out_field_skip (uiout, "addr");
8047 annotate_field (5);
8048 ui_out_text (uiout, "exec");
b4d90040 8049 if (c->exec_pathname != NULL)
fe798b75
JB
8050 {
8051 ui_out_text (uiout, ", program \"");
b4d90040 8052 ui_out_field_string (uiout, "what", c->exec_pathname);
fe798b75
JB
8053 ui_out_text (uiout, "\" ");
8054 }
8055}
8056
8057static void
8058print_mention_catch_exec (struct breakpoint *b)
8059{
8060 printf_filtered (_("Catchpoint %d (exec)"), b->number);
8061}
8062
6149aea9
PA
8063/* Implement the "print_recreate" breakpoint_ops method for exec
8064 catchpoints. */
8065
8066static void
8067print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp)
8068{
8069 fprintf_unfiltered (fp, "catch exec");
d9b3f62e 8070 print_recreate_thread (b, fp);
6149aea9
PA
8071}
8072
2060206e 8073static struct breakpoint_ops catch_exec_breakpoint_ops;
fe798b75 8074
a96d9b2e
SDJ
8075static void
8076create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
c0a91b2b 8077 const struct breakpoint_ops *ops)
a96d9b2e 8078{
be5c67c1 8079 struct syscall_catchpoint *c;
a96d9b2e 8080 struct gdbarch *gdbarch = get_current_arch ();
a96d9b2e 8081
be5c67c1
PA
8082 c = XNEW (struct syscall_catchpoint);
8083 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops);
8084 c->syscalls_to_be_caught = filter;
a96d9b2e 8085
3ea46bff 8086 install_breakpoint (0, &c->base, 1);
a96d9b2e
SDJ
8087}
8088
c906108c 8089static int
fba45db2 8090hw_breakpoint_used_count (void)
c906108c 8091{
c906108c 8092 int i = 0;
f1310107
TJB
8093 struct breakpoint *b;
8094 struct bp_location *bl;
c906108c
SS
8095
8096 ALL_BREAKPOINTS (b)
c5aa993b 8097 {
d6b74ac4 8098 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
f1310107
TJB
8099 for (bl = b->loc; bl; bl = bl->next)
8100 {
8101 /* Special types of hardware breakpoints may use more than
8102 one register. */
348d480f 8103 i += b->ops->resources_needed (bl);
f1310107 8104 }
c5aa993b 8105 }
c906108c
SS
8106
8107 return i;
8108}
8109
a1398e0c
PA
8110/* Returns the resources B would use if it were a hardware
8111 watchpoint. */
8112
c906108c 8113static int
a1398e0c 8114hw_watchpoint_use_count (struct breakpoint *b)
c906108c 8115{
c906108c 8116 int i = 0;
e09342b5 8117 struct bp_location *bl;
c906108c 8118
a1398e0c
PA
8119 if (!breakpoint_enabled (b))
8120 return 0;
8121
8122 for (bl = b->loc; bl; bl = bl->next)
8123 {
8124 /* Special types of hardware watchpoints may use more than
8125 one register. */
8126 i += b->ops->resources_needed (bl);
8127 }
8128
8129 return i;
8130}
8131
8132/* Returns the sum the used resources of all hardware watchpoints of
8133 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8134 the sum of the used resources of all hardware watchpoints of other
8135 types _not_ TYPE. */
8136
8137static int
8138hw_watchpoint_used_count_others (struct breakpoint *except,
8139 enum bptype type, int *other_type_used)
8140{
8141 int i = 0;
8142 struct breakpoint *b;
8143
c906108c
SS
8144 *other_type_used = 0;
8145 ALL_BREAKPOINTS (b)
e09342b5 8146 {
a1398e0c
PA
8147 if (b == except)
8148 continue;
e09342b5
TJB
8149 if (!breakpoint_enabled (b))
8150 continue;
8151
a1398e0c
PA
8152 if (b->type == type)
8153 i += hw_watchpoint_use_count (b);
8154 else if (is_hardware_watchpoint (b))
8155 *other_type_used = 1;
e09342b5
TJB
8156 }
8157
c906108c
SS
8158 return i;
8159}
8160
c906108c 8161void
fba45db2 8162disable_watchpoints_before_interactive_call_start (void)
c906108c 8163{
c5aa993b 8164 struct breakpoint *b;
c906108c
SS
8165
8166 ALL_BREAKPOINTS (b)
c5aa993b 8167 {
cc60f2e3 8168 if (is_watchpoint (b) && breakpoint_enabled (b))
c5aa993b 8169 {
b5de0fa7 8170 b->enable_state = bp_call_disabled;
b60e7edf 8171 update_global_location_list (0);
c5aa993b
JM
8172 }
8173 }
c906108c
SS
8174}
8175
8176void
fba45db2 8177enable_watchpoints_after_interactive_call_stop (void)
c906108c 8178{
c5aa993b 8179 struct breakpoint *b;
c906108c
SS
8180
8181 ALL_BREAKPOINTS (b)
c5aa993b 8182 {
cc60f2e3 8183 if (is_watchpoint (b) && b->enable_state == bp_call_disabled)
c5aa993b 8184 {
b5de0fa7 8185 b->enable_state = bp_enabled;
b60e7edf 8186 update_global_location_list (1);
c5aa993b
JM
8187 }
8188 }
c906108c
SS
8189}
8190
8bea4e01
UW
8191void
8192disable_breakpoints_before_startup (void)
8193{
6c95b8df 8194 current_program_space->executing_startup = 1;
f8eba3c6 8195 update_global_location_list (0);
8bea4e01
UW
8196}
8197
8198void
8199enable_breakpoints_after_startup (void)
8200{
6c95b8df 8201 current_program_space->executing_startup = 0;
f8eba3c6 8202 breakpoint_re_set ();
8bea4e01
UW
8203}
8204
c906108c
SS
8205
8206/* Set a breakpoint that will evaporate an end of command
8207 at address specified by SAL.
8208 Restrict it to frame FRAME if FRAME is nonzero. */
8209
8210struct breakpoint *
a6d9a66e
UW
8211set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
8212 struct frame_id frame_id, enum bptype type)
c906108c 8213{
52f0bd74 8214 struct breakpoint *b;
edb3359d
DJ
8215
8216 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8217 one. */
8218 gdb_assert (!frame_id_inlined_p (frame_id));
8219
06edf0c0 8220 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops);
b5de0fa7
EZ
8221 b->enable_state = bp_enabled;
8222 b->disposition = disp_donttouch;
818dd999 8223 b->frame_id = frame_id;
c906108c 8224
4a64f543
MS
8225 /* If we're debugging a multi-threaded program, then we want
8226 momentary breakpoints to be active in only a single thread of
8227 control. */
39f77062
KB
8228 if (in_thread_list (inferior_ptid))
8229 b->thread = pid_to_thread_id (inferior_ptid);
c906108c 8230
b60e7edf 8231 update_global_location_list_nothrow (1);
74960c60 8232
c906108c
SS
8233 return b;
8234}
611c83ae 8235
06edf0c0
PA
8236/* Make a momentary breakpoint based on the master breakpoint ORIG.
8237 The new breakpoint will have type TYPE, and use OPS as it
8238 breakpoint_ops. */
e58b0e63 8239
06edf0c0
PA
8240static struct breakpoint *
8241momentary_breakpoint_from_master (struct breakpoint *orig,
8242 enum bptype type,
c0a91b2b 8243 const struct breakpoint_ops *ops)
e58b0e63
PA
8244{
8245 struct breakpoint *copy;
8246
06edf0c0 8247 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops);
e58b0e63 8248 copy->loc = allocate_bp_location (copy);
0e30163f 8249 set_breakpoint_location_function (copy->loc, 1);
e58b0e63 8250
a6d9a66e 8251 copy->loc->gdbarch = orig->loc->gdbarch;
e58b0e63
PA
8252 copy->loc->requested_address = orig->loc->requested_address;
8253 copy->loc->address = orig->loc->address;
8254 copy->loc->section = orig->loc->section;
6c95b8df 8255 copy->loc->pspace = orig->loc->pspace;
55aa24fb 8256 copy->loc->probe = orig->loc->probe;
e58b0e63 8257
f8eba3c6
TT
8258 if (orig->loc->source_file != NULL)
8259 copy->loc->source_file = xstrdup (orig->loc->source_file);
e58b0e63 8260
f8eba3c6 8261 copy->loc->line_number = orig->loc->line_number;
e58b0e63
PA
8262 copy->frame_id = orig->frame_id;
8263 copy->thread = orig->thread;
6c95b8df 8264 copy->pspace = orig->pspace;
e58b0e63
PA
8265
8266 copy->enable_state = bp_enabled;
8267 copy->disposition = disp_donttouch;
8268 copy->number = internal_breakpoint_number--;
8269
8270 update_global_location_list_nothrow (0);
8271 return copy;
8272}
8273
06edf0c0
PA
8274/* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8275 ORIG is NULL. */
8276
8277struct breakpoint *
8278clone_momentary_breakpoint (struct breakpoint *orig)
8279{
8280 /* If there's nothing to clone, then return nothing. */
8281 if (orig == NULL)
8282 return NULL;
8283
8284 return momentary_breakpoint_from_master (orig, orig->type, orig->ops);
8285}
8286
611c83ae 8287struct breakpoint *
a6d9a66e
UW
8288set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
8289 enum bptype type)
611c83ae
PA
8290{
8291 struct symtab_and_line sal;
8292
8293 sal = find_pc_line (pc, 0);
8294 sal.pc = pc;
8295 sal.section = find_pc_overlay (pc);
8296 sal.explicit_pc = 1;
8297
a6d9a66e 8298 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type);
611c83ae 8299}
c906108c 8300\f
c5aa993b 8301
c906108c
SS
8302/* Tell the user we have just set a breakpoint B. */
8303
8304static void
fba45db2 8305mention (struct breakpoint *b)
c906108c 8306{
348d480f 8307 b->ops->print_mention (b);
79a45e25 8308 if (ui_out_is_mi_like_p (current_uiout))
fb40c209 8309 return;
c906108c
SS
8310 printf_filtered ("\n");
8311}
c906108c 8312\f
c5aa993b 8313
0d381245 8314static struct bp_location *
39d61571 8315add_location_to_breakpoint (struct breakpoint *b,
0d381245
VP
8316 const struct symtab_and_line *sal)
8317{
8318 struct bp_location *loc, **tmp;
3742cc8b
YQ
8319 CORE_ADDR adjusted_address;
8320 struct gdbarch *loc_gdbarch = get_sal_arch (*sal);
8321
8322 if (loc_gdbarch == NULL)
8323 loc_gdbarch = b->gdbarch;
8324
8325 /* Adjust the breakpoint's address prior to allocating a location.
8326 Once we call allocate_bp_location(), that mostly uninitialized
8327 location will be placed on the location chain. Adjustment of the
8328 breakpoint may cause target_read_memory() to be called and we do
8329 not want its scan of the location chain to find a breakpoint and
8330 location that's only been partially initialized. */
8331 adjusted_address = adjust_breakpoint_address (loc_gdbarch,
8332 sal->pc, b->type);
0d381245 8333
39d61571 8334 loc = allocate_bp_location (b);
0d381245
VP
8335 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
8336 ;
8337 *tmp = loc;
3742cc8b 8338
0d381245 8339 loc->requested_address = sal->pc;
3742cc8b 8340 loc->address = adjusted_address;
6c95b8df 8341 loc->pspace = sal->pspace;
55aa24fb 8342 loc->probe = sal->probe;
6c95b8df 8343 gdb_assert (loc->pspace != NULL);
0d381245 8344 loc->section = sal->section;
3742cc8b 8345 loc->gdbarch = loc_gdbarch;
f8eba3c6
TT
8346
8347 if (sal->symtab != NULL)
8348 loc->source_file = xstrdup (sal->symtab->filename);
8349 loc->line_number = sal->line;
8350
0e30163f
JK
8351 set_breakpoint_location_function (loc,
8352 sal->explicit_pc || sal->explicit_line);
0d381245
VP
8353 return loc;
8354}
514f746b
AR
8355\f
8356
8357/* Return 1 if LOC is pointing to a permanent breakpoint,
8358 return 0 otherwise. */
8359
8360static int
8361bp_loc_is_permanent (struct bp_location *loc)
8362{
8363 int len;
8364 CORE_ADDR addr;
1afeeb75 8365 const gdb_byte *bpoint;
514f746b 8366 gdb_byte *target_mem;
939c61fa
JK
8367 struct cleanup *cleanup;
8368 int retval = 0;
514f746b
AR
8369
8370 gdb_assert (loc != NULL);
8371
8372 addr = loc->address;
1afeeb75 8373 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
514f746b 8374
939c61fa 8375 /* Software breakpoints unsupported? */
1afeeb75 8376 if (bpoint == NULL)
939c61fa
JK
8377 return 0;
8378
514f746b
AR
8379 target_mem = alloca (len);
8380
939c61fa
JK
8381 /* Enable the automatic memory restoration from breakpoints while
8382 we read the memory. Otherwise we could say about our temporary
8383 breakpoints they are permanent. */
6c95b8df
PA
8384 cleanup = save_current_space_and_thread ();
8385
8386 switch_to_program_space_and_thread (loc->pspace);
8387 make_show_memory_breakpoints_cleanup (0);
939c61fa 8388
514f746b 8389 if (target_read_memory (loc->address, target_mem, len) == 0
1afeeb75 8390 && memcmp (target_mem, bpoint, len) == 0)
939c61fa 8391 retval = 1;
514f746b 8392
939c61fa
JK
8393 do_cleanups (cleanup);
8394
8395 return retval;
514f746b
AR
8396}
8397
e7e0cddf
SS
8398/* The style in which to perform a dynamic printf. This is a user
8399 option because different output options have different tradeoffs;
8400 if GDB does the printing, there is better error handling if there
8401 is a problem with any of the arguments, but using an inferior
8402 function lets you have special-purpose printers and sending of
8403 output to the same place as compiled-in print functions. (Future
8404 styles may include the ability to do a target-side printf.) */
8405
8406static const char dprintf_style_gdb[] = "gdb";
8407static const char dprintf_style_call[] = "call";
8408static const char *const dprintf_style_enums[] = {
8409 dprintf_style_gdb,
8410 dprintf_style_call,
8411 NULL
8412};
8413static const char *dprintf_style = dprintf_style_gdb;
8414
8415/* The function to use for dynamic printf if the preferred style is to
8416 call into the inferior. The value is simply a string that is
8417 copied into the command, so it can be anything that GDB can
8418 evaluate to a callable address, not necessarily a function name. */
8419
8420static char *dprintf_function = "";
8421
8422/* The channel to use for dynamic printf if the preferred style is to
8423 call into the inferior; if a nonempty string, it will be passed to
8424 the call as the first argument, with the format string as the
8425 second. As with the dprintf function, this can be anything that
8426 GDB knows how to evaluate, so in addition to common choices like
8427 "stderr", this could be an app-specific expression like
8428 "mystreams[curlogger]". */
514f746b 8429
e7e0cddf
SS
8430static char *dprintf_channel = "";
8431
8432/* Build a command list for the dprintf corresponding to the current
8433 settings of the dprintf style options. */
8434
8435static void
8436update_dprintf_command_list (struct breakpoint *b)
8437{
8438 char *dprintf_args = b->extra_string;
8439 char *printf_line = NULL;
8440
8441 if (!dprintf_args)
8442 return;
8443
8444 dprintf_args = skip_spaces (dprintf_args);
8445
8446 /* Allow a comma, as it may have terminated a location, but don't
8447 insist on it. */
8448 if (*dprintf_args == ',')
8449 ++dprintf_args;
8450 dprintf_args = skip_spaces (dprintf_args);
8451
8452 if (*dprintf_args != '"')
8453 error (_("Bad format string, missing '\"'."));
8454
8455 if (strcmp (dprintf_style, "gdb") == 0)
8456 printf_line = xstrprintf ("printf %s", dprintf_args);
8457 else if (strcmp (dprintf_style, "call") == 0)
8458 {
8459 if (!dprintf_function)
8460 error (_("No function supplied for dprintf call"));
8461
8462 if (dprintf_channel && strlen (dprintf_channel) > 0)
8463 printf_line = xstrprintf ("call (void) %s (%s,%s)",
8464 dprintf_function,
8465 dprintf_channel,
8466 dprintf_args);
8467 else
8468 printf_line = xstrprintf ("call (void) %s (%s)",
8469 dprintf_function,
8470 dprintf_args);
8471 }
8472 else
8473 internal_error (__FILE__, __LINE__,
8474 _("Invalid dprintf style."));
8475
8476 /* Manufacture a printf/continue sequence. */
8477 if (printf_line)
8478 {
8479 struct command_line *printf_cmd_line, *cont_cmd_line = NULL;
8480
8481 cont_cmd_line = xmalloc (sizeof (struct command_line));
8482 cont_cmd_line->control_type = simple_control;
8483 cont_cmd_line->body_count = 0;
8484 cont_cmd_line->body_list = NULL;
8485 cont_cmd_line->next = NULL;
8486 cont_cmd_line->line = xstrdup ("continue");
8487
8488 printf_cmd_line = xmalloc (sizeof (struct command_line));
8489 printf_cmd_line->control_type = simple_control;
8490 printf_cmd_line->body_count = 0;
8491 printf_cmd_line->body_list = NULL;
8492 printf_cmd_line->next = cont_cmd_line;
8493 printf_cmd_line->line = printf_line;
8494
8495 breakpoint_set_commands (b, printf_cmd_line);
8496 }
8497}
8498
8499/* Update all dprintf commands, making their command lists reflect
8500 current style settings. */
8501
8502static void
8503update_dprintf_commands (char *args, int from_tty,
8504 struct cmd_list_element *c)
8505{
8506 struct breakpoint *b;
8507
8508 ALL_BREAKPOINTS (b)
8509 {
8510 if (b->type == bp_dprintf)
8511 update_dprintf_command_list (b);
8512 }
8513}
c3f6f71d 8514
018d34a4
VP
8515/* Create a breakpoint with SAL as location. Use ADDR_STRING
8516 as textual description of the location, and COND_STRING
db107f19 8517 as condition expression. */
018d34a4
VP
8518
8519static void
d9b3f62e
PA
8520init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
8521 struct symtabs_and_lines sals, char *addr_string,
f8eba3c6 8522 char *filter, char *cond_string,
e7e0cddf 8523 char *extra_string,
d9b3f62e
PA
8524 enum bptype type, enum bpdisp disposition,
8525 int thread, int task, int ignore_count,
c0a91b2b 8526 const struct breakpoint_ops *ops, int from_tty,
44f238bb
PA
8527 int enabled, int internal, unsigned flags,
8528 int display_canonical)
018d34a4 8529{
0d381245 8530 int i;
018d34a4
VP
8531
8532 if (type == bp_hardware_breakpoint)
8533 {
fbbd034e
AS
8534 int target_resources_ok;
8535
8536 i = hw_breakpoint_used_count ();
8537 target_resources_ok =
8538 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
018d34a4
VP
8539 i + 1, 0);
8540 if (target_resources_ok == 0)
8541 error (_("No hardware breakpoint support in the target."));
8542 else if (target_resources_ok < 0)
8543 error (_("Hardware breakpoints used exceeds limit."));
8544 }
8545
6c95b8df
PA
8546 gdb_assert (sals.nelts > 0);
8547
0d381245
VP
8548 for (i = 0; i < sals.nelts; ++i)
8549 {
8550 struct symtab_and_line sal = sals.sals[i];
8551 struct bp_location *loc;
8552
8553 if (from_tty)
5af949e3
UW
8554 {
8555 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
8556 if (!loc_gdbarch)
8557 loc_gdbarch = gdbarch;
8558
8559 describe_other_breakpoints (loc_gdbarch,
6c95b8df 8560 sal.pspace, sal.pc, sal.section, thread);
5af949e3 8561 }
0d381245
VP
8562
8563 if (i == 0)
8564 {
d9b3f62e 8565 init_raw_breakpoint (b, gdbarch, sal, type, ops);
0d381245 8566 b->thread = thread;
4a306c9a 8567 b->task = task;
855a6e68 8568
0d381245 8569 b->cond_string = cond_string;
e7e0cddf 8570 b->extra_string = extra_string;
0d381245 8571 b->ignore_count = ignore_count;
41447f92 8572 b->enable_state = enabled ? bp_enabled : bp_disabled;
0d381245 8573 b->disposition = disposition;
6c95b8df 8574
44f238bb
PA
8575 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8576 b->loc->inserted = 1;
8577
0fb4aa4b
PA
8578 if (type == bp_static_tracepoint)
8579 {
d9b3f62e 8580 struct tracepoint *t = (struct tracepoint *) b;
0fb4aa4b
PA
8581 struct static_tracepoint_marker marker;
8582
983af33b 8583 if (strace_marker_p (b))
0fb4aa4b
PA
8584 {
8585 /* We already know the marker exists, otherwise, we
8586 wouldn't see a sal for it. */
8587 char *p = &addr_string[3];
8588 char *endp;
8589 char *marker_str;
0fb4aa4b 8590
e9cafbcc 8591 p = skip_spaces (p);
0fb4aa4b 8592
e9cafbcc 8593 endp = skip_to_space (p);
0fb4aa4b
PA
8594
8595 marker_str = savestring (p, endp - p);
d9b3f62e 8596 t->static_trace_marker_id = marker_str;
0fb4aa4b 8597
3e43a32a
MS
8598 printf_filtered (_("Probed static tracepoint "
8599 "marker \"%s\"\n"),
d9b3f62e 8600 t->static_trace_marker_id);
0fb4aa4b
PA
8601 }
8602 else if (target_static_tracepoint_marker_at (sal.pc, &marker))
8603 {
d9b3f62e 8604 t->static_trace_marker_id = xstrdup (marker.str_id);
0fb4aa4b
PA
8605 release_static_tracepoint_marker (&marker);
8606
3e43a32a
MS
8607 printf_filtered (_("Probed static tracepoint "
8608 "marker \"%s\"\n"),
d9b3f62e 8609 t->static_trace_marker_id);
0fb4aa4b
PA
8610 }
8611 else
3e43a32a
MS
8612 warning (_("Couldn't determine the static "
8613 "tracepoint marker to probe"));
0fb4aa4b
PA
8614 }
8615
0d381245
VP
8616 loc = b->loc;
8617 }
8618 else
018d34a4 8619 {
39d61571 8620 loc = add_location_to_breakpoint (b, &sal);
44f238bb
PA
8621 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0)
8622 loc->inserted = 1;
0d381245
VP
8623 }
8624
514f746b
AR
8625 if (bp_loc_is_permanent (loc))
8626 make_breakpoint_permanent (b);
8627
0d381245
VP
8628 if (b->cond_string)
8629 {
8630 char *arg = b->cond_string;
d32a6982 8631 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
0d381245 8632 if (*arg)
588ae58c 8633 error (_("Garbage '%s' follows condition"), arg);
018d34a4 8634 }
e7e0cddf
SS
8635
8636 /* Dynamic printf requires and uses additional arguments on the
8637 command line, otherwise it's an error. */
8638 if (type == bp_dprintf)
8639 {
8640 if (b->extra_string)
8641 update_dprintf_command_list (b);
8642 else
8643 error (_("Format string required"));
8644 }
8645 else if (b->extra_string)
588ae58c 8646 error (_("Garbage '%s' at end of command"), b->extra_string);
855a6e68 8647 }
018d34a4 8648
56435ebe 8649 b->display_canonical = display_canonical;
018d34a4
VP
8650 if (addr_string)
8651 b->addr_string = addr_string;
8652 else
8653 /* addr_string has to be used or breakpoint_re_set will delete
8654 me. */
5af949e3
UW
8655 b->addr_string
8656 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
f8eba3c6 8657 b->filter = filter;
d9b3f62e 8658}
018d34a4 8659
d9b3f62e
PA
8660static void
8661create_breakpoint_sal (struct gdbarch *gdbarch,
8662 struct symtabs_and_lines sals, char *addr_string,
f8eba3c6 8663 char *filter, char *cond_string,
e7e0cddf 8664 char *extra_string,
d9b3f62e
PA
8665 enum bptype type, enum bpdisp disposition,
8666 int thread, int task, int ignore_count,
c0a91b2b 8667 const struct breakpoint_ops *ops, int from_tty,
44f238bb
PA
8668 int enabled, int internal, unsigned flags,
8669 int display_canonical)
d9b3f62e
PA
8670{
8671 struct breakpoint *b;
8672 struct cleanup *old_chain;
8673
8674 if (is_tracepoint_type (type))
8675 {
8676 struct tracepoint *t;
8677
8678 t = XCNEW (struct tracepoint);
8679 b = &t->base;
8680 }
8681 else
8682 b = XNEW (struct breakpoint);
8683
8684 old_chain = make_cleanup (xfree, b);
8685
8686 init_breakpoint_sal (b, gdbarch,
8687 sals, addr_string,
e7e0cddf 8688 filter, cond_string, extra_string,
d9b3f62e
PA
8689 type, disposition,
8690 thread, task, ignore_count,
8691 ops, from_tty,
44f238bb
PA
8692 enabled, internal, flags,
8693 display_canonical);
d9b3f62e
PA
8694 discard_cleanups (old_chain);
8695
3ea46bff 8696 install_breakpoint (internal, b, 0);
018d34a4
VP
8697}
8698
8699/* Add SALS.nelts breakpoints to the breakpoint table. For each
8700 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8701 value. COND_STRING, if not NULL, specified the condition to be
8702 used for all breakpoints. Essentially the only case where
8703 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8704 function. In that case, it's still not possible to specify
8705 separate conditions for different overloaded functions, so
8706 we take just a single condition string.
8707
c3f6f71d 8708 NOTE: If the function succeeds, the caller is expected to cleanup
018d34a4 8709 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
c3f6f71d
JM
8710 array contents). If the function fails (error() is called), the
8711 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4a64f543 8712 COND and SALS arrays and each of those arrays contents. */
c906108c
SS
8713
8714static void
8cdf0e15 8715create_breakpoints_sal (struct gdbarch *gdbarch,
7efd8fc2 8716 struct linespec_result *canonical,
e7e0cddf 8717 char *cond_string, char *extra_string,
8cdf0e15
VP
8718 enum bptype type, enum bpdisp disposition,
8719 int thread, int task, int ignore_count,
c0a91b2b 8720 const struct breakpoint_ops *ops, int from_tty,
44f238bb 8721 int enabled, int internal, unsigned flags)
c906108c 8722{
018d34a4 8723 int i;
f8eba3c6 8724 struct linespec_sals *lsal;
cc59ec59 8725
f8eba3c6
TT
8726 if (canonical->pre_expanded)
8727 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1);
8728
8729 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
c3f6f71d 8730 {
f8eba3c6
TT
8731 /* Note that 'addr_string' can be NULL in the case of a plain
8732 'break', without arguments. */
8733 char *addr_string = (canonical->addr_string
8734 ? xstrdup (canonical->addr_string)
8735 : NULL);
8736 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
8737 struct cleanup *inner = make_cleanup (xfree, addr_string);
0d381245 8738
f8eba3c6
TT
8739 make_cleanup (xfree, filter_string);
8740 create_breakpoint_sal (gdbarch, lsal->sals,
8741 addr_string,
8742 filter_string,
e7e0cddf
SS
8743 cond_string, extra_string,
8744 type, disposition,
84f4c1fe 8745 thread, task, ignore_count, ops,
44f238bb 8746 from_tty, enabled, internal, flags,
56435ebe 8747 canonical->special_display);
f8eba3c6 8748 discard_cleanups (inner);
c3f6f71d 8749 }
c3f6f71d 8750}
c906108c 8751
9998af43 8752/* Parse ADDRESS which is assumed to be a SAL specification possibly
c3f6f71d 8753 followed by conditionals. On return, SALS contains an array of SAL
4a64f543 8754 addresses found. ADDR_STRING contains a vector of (canonical)
9998af43
TJB
8755 address strings. ADDRESS points to the end of the SAL.
8756
8757 The array and the line spec strings are allocated on the heap, it is
8758 the caller's responsibility to free them. */
c906108c 8759
b9362cc7 8760static void
c3f6f71d 8761parse_breakpoint_sals (char **address,
58438ac1 8762 struct linespec_result *canonical)
c3f6f71d
JM
8763{
8764 char *addr_start = *address;
cc59ec59 8765
c3f6f71d 8766 /* If no arg given, or if first arg is 'if ', use the default
4a64f543 8767 breakpoint. */
c3f6f71d
JM
8768 if ((*address) == NULL
8769 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
c906108c 8770 {
1bfeeb0f
JL
8771 /* The last displayed codepoint, if it's valid, is our default breakpoint
8772 address. */
8773 if (last_displayed_sal_is_valid ())
c906108c 8774 {
f8eba3c6 8775 struct linespec_sals lsal;
c3f6f71d 8776 struct symtab_and_line sal;
cc59ec59 8777
4a64f543 8778 init_sal (&sal); /* Initialize to zeroes. */
f8eba3c6 8779 lsal.sals.sals = (struct symtab_and_line *)
c906108c 8780 xmalloc (sizeof (struct symtab_and_line));
1bfeeb0f
JL
8781
8782 /* Set sal's pspace, pc, symtab, and line to the values
8783 corresponding to the last call to print_frame_info. */
8784 get_last_displayed_sal (&sal);
8785 sal.section = find_pc_overlay (sal.pc);
00903456 8786
4a64f543 8787 /* "break" without arguments is equivalent to "break *PC"
1bfeeb0f
JL
8788 where PC is the last displayed codepoint's address. So
8789 make sure to set sal.explicit_pc to prevent GDB from
8790 trying to expand the list of sals to include all other
8791 instances with the same symtab and line. */
00903456
JK
8792 sal.explicit_pc = 1;
8793
f8eba3c6
TT
8794 lsal.sals.sals[0] = sal;
8795 lsal.sals.nelts = 1;
8796 lsal.canonical = NULL;
8797
8798 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
c906108c
SS
8799 }
8800 else
8a3fe4f8 8801 error (_("No default breakpoint address now."));
c906108c
SS
8802 }
8803 else
8804 {
cc80f267
JK
8805 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
8806
c906108c 8807 /* Force almost all breakpoints to be in terms of the
4a64f543
MS
8808 current_source_symtab (which is decode_line_1's default).
8809 This should produce the results we want almost all of the
cc80f267
JK
8810 time while leaving default_breakpoint_* alone.
8811
8812 ObjC: However, don't match an Objective-C method name which
8813 may have a '+' or '-' succeeded by a '['. */
8814 if (last_displayed_sal_is_valid ()
8815 && (!cursal.symtab
8816 || ((strchr ("+-", (*address)[0]) != NULL)
8817 && ((*address)[1] != '['))))
f8eba3c6
TT
8818 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
8819 get_last_displayed_symtab (),
8820 get_last_displayed_line (),
8821 canonical, NULL, NULL);
c906108c 8822 else
f8eba3c6 8823 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
cc80f267 8824 cursal.symtab, cursal.line, canonical, NULL, NULL);
c906108c 8825 }
c3f6f71d 8826}
c906108c 8827
c906108c 8828
c3f6f71d 8829/* Convert each SAL into a real PC. Verify that the PC can be
4a64f543 8830 inserted as a breakpoint. If it can't throw an error. */
c906108c 8831
b9362cc7 8832static void
23e7acfb 8833breakpoint_sals_to_pc (struct symtabs_and_lines *sals)
c3f6f71d
JM
8834{
8835 int i;
cc59ec59 8836
c3f6f71d 8837 for (i = 0; i < sals->nelts; i++)
ee53e872 8838 resolve_sal_pc (&sals->sals[i]);
c3f6f71d
JM
8839}
8840
7a697b8d
SS
8841/* Fast tracepoints may have restrictions on valid locations. For
8842 instance, a fast tracepoint using a jump instead of a trap will
8843 likely have to overwrite more bytes than a trap would, and so can
8844 only be placed where the instruction is longer than the jump, or a
8845 multi-instruction sequence does not have a jump into the middle of
8846 it, etc. */
8847
8848static void
8849check_fast_tracepoint_sals (struct gdbarch *gdbarch,
8850 struct symtabs_and_lines *sals)
8851{
8852 int i, rslt;
8853 struct symtab_and_line *sal;
8854 char *msg;
8855 struct cleanup *old_chain;
8856
8857 for (i = 0; i < sals->nelts; i++)
8858 {
f8eba3c6
TT
8859 struct gdbarch *sarch;
8860
7a697b8d
SS
8861 sal = &sals->sals[i];
8862
f8eba3c6
TT
8863 sarch = get_sal_arch (*sal);
8864 /* We fall back to GDBARCH if there is no architecture
8865 associated with SAL. */
8866 if (sarch == NULL)
8867 sarch = gdbarch;
8868 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc,
7a697b8d
SS
8869 NULL, &msg);
8870 old_chain = make_cleanup (xfree, msg);
8871
8872 if (!rslt)
8873 error (_("May not have a fast tracepoint at 0x%s%s"),
f8eba3c6 8874 paddress (sarch, sal->pc), (msg ? msg : ""));
7a697b8d
SS
8875
8876 do_cleanups (old_chain);
8877 }
8878}
8879
018d34a4
VP
8880/* Given TOK, a string specification of condition and thread, as
8881 accepted by the 'break' command, extract the condition
8882 string and thread number and set *COND_STRING and *THREAD.
4a64f543 8883 PC identifies the context at which the condition should be parsed.
018d34a4
VP
8884 If no condition is found, *COND_STRING is set to NULL.
8885 If no thread is found, *THREAD is set to -1. */
d634f2de
JB
8886
8887static void
8888find_condition_and_thread (char *tok, CORE_ADDR pc,
e7e0cddf
SS
8889 char **cond_string, int *thread, int *task,
8890 char **rest)
018d34a4
VP
8891{
8892 *cond_string = NULL;
8893 *thread = -1;
8894 while (tok && *tok)
8895 {
8896 char *end_tok;
8897 int toklen;
8898 char *cond_start = NULL;
8899 char *cond_end = NULL;
cc59ec59 8900
e9cafbcc 8901 tok = skip_spaces (tok);
e7e0cddf
SS
8902
8903 if ((*tok == '"' || *tok == ',') && rest)
8904 {
8905 *rest = savestring (tok, strlen (tok));
8906 return;
8907 }
8908
e9cafbcc 8909 end_tok = skip_to_space (tok);
d634f2de 8910
018d34a4 8911 toklen = end_tok - tok;
d634f2de 8912
018d34a4
VP
8913 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
8914 {
f7545552
TT
8915 struct expression *expr;
8916
018d34a4 8917 tok = cond_start = end_tok + 1;
f7545552
TT
8918 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
8919 xfree (expr);
018d34a4 8920 cond_end = tok;
d634f2de 8921 *cond_string = savestring (cond_start, cond_end - cond_start);
018d34a4
VP
8922 }
8923 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
8924 {
8925 char *tmptok;
d634f2de 8926
018d34a4
VP
8927 tok = end_tok + 1;
8928 tmptok = tok;
8929 *thread = strtol (tok, &tok, 0);
8930 if (tok == tmptok)
8931 error (_("Junk after thread keyword."));
8932 if (!valid_thread_id (*thread))
8933 error (_("Unknown thread %d."), *thread);
8934 }
4a306c9a
JB
8935 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
8936 {
8937 char *tmptok;
8938
8939 tok = end_tok + 1;
8940 tmptok = tok;
8941 *task = strtol (tok, &tok, 0);
8942 if (tok == tmptok)
8943 error (_("Junk after task keyword."));
8944 if (!valid_task_id (*task))
b6199126 8945 error (_("Unknown task %d."), *task);
4a306c9a 8946 }
e7e0cddf
SS
8947 else if (rest)
8948 {
8949 *rest = savestring (tok, strlen (tok));
ccab2054 8950 return;
e7e0cddf 8951 }
018d34a4
VP
8952 else
8953 error (_("Junk at end of arguments."));
8954 }
8955}
8956
0fb4aa4b
PA
8957/* Decode a static tracepoint marker spec. */
8958
8959static struct symtabs_and_lines
8960decode_static_tracepoint_spec (char **arg_p)
8961{
8962 VEC(static_tracepoint_marker_p) *markers = NULL;
8963 struct symtabs_and_lines sals;
0fb4aa4b
PA
8964 struct cleanup *old_chain;
8965 char *p = &(*arg_p)[3];
8966 char *endp;
8967 char *marker_str;
8968 int i;
8969
e9cafbcc 8970 p = skip_spaces (p);
0fb4aa4b 8971
e9cafbcc 8972 endp = skip_to_space (p);
0fb4aa4b
PA
8973
8974 marker_str = savestring (p, endp - p);
8975 old_chain = make_cleanup (xfree, marker_str);
8976
8977 markers = target_static_tracepoint_markers_by_strid (marker_str);
8978 if (VEC_empty(static_tracepoint_marker_p, markers))
8979 error (_("No known static tracepoint marker named %s"), marker_str);
8980
8981 sals.nelts = VEC_length(static_tracepoint_marker_p, markers);
8982 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts);
8983
8984 for (i = 0; i < sals.nelts; i++)
8985 {
8986 struct static_tracepoint_marker *marker;
8987
8988 marker = VEC_index (static_tracepoint_marker_p, markers, i);
8989
8990 init_sal (&sals.sals[i]);
8991
8992 sals.sals[i] = find_pc_line (marker->address, 0);
8993 sals.sals[i].pc = marker->address;
8994
8995 release_static_tracepoint_marker (marker);
8996 }
8997
8998 do_cleanups (old_chain);
8999
9000 *arg_p = endp;
9001 return sals;
9002}
9003
fd9b8c24
PA
9004/* Set a breakpoint. This function is shared between CLI and MI
9005 functions for setting a breakpoint. This function has two major
9006 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9007 parameter. If non-zero, the function will parse arg, extracting
4a64f543
MS
9008 breakpoint location, address and thread. Otherwise, ARG is just
9009 the location of breakpoint, with condition and thread specified by
9010 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9011 the breakpoint number will be allocated from the internal
9012 breakpoint count. Returns true if any breakpoint was created;
9013 false otherwise. */
0101ce28 9014
8cdf0e15
VP
9015int
9016create_breakpoint (struct gdbarch *gdbarch,
e7e0cddf
SS
9017 char *arg, char *cond_string,
9018 int thread, char *extra_string,
8cdf0e15 9019 int parse_condition_and_thread,
0fb4aa4b 9020 int tempflag, enum bptype type_wanted,
8cdf0e15
VP
9021 int ignore_count,
9022 enum auto_boolean pending_break_support,
c0a91b2b 9023 const struct breakpoint_ops *ops,
44f238bb
PA
9024 int from_tty, int enabled, int internal,
9025 unsigned flags)
c3f6f71d 9026{
b78a6381 9027 volatile struct gdb_exception e;
f8eba3c6 9028 char *copy_arg = NULL;
c3f6f71d 9029 char *addr_start = arg;
7efd8fc2 9030 struct linespec_result canonical;
c3f6f71d 9031 struct cleanup *old_chain;
80c99de1 9032 struct cleanup *bkpt_chain = NULL;
0101ce28 9033 int pending = 0;
4a306c9a 9034 int task = 0;
86b17b60 9035 int prev_bkpt_count = breakpoint_count;
c3f6f71d 9036
348d480f
PA
9037 gdb_assert (ops != NULL);
9038
7efd8fc2 9039 init_linespec_result (&canonical);
c3f6f71d 9040
b78a6381
TT
9041 TRY_CATCH (e, RETURN_MASK_ALL)
9042 {
983af33b
SDJ
9043 ops->create_sals_from_address (&arg, &canonical, type_wanted,
9044 addr_start, &copy_arg);
b78a6381 9045 }
0101ce28
JJ
9046
9047 /* If caller is interested in rc value from parse, set value. */
05ff989b 9048 switch (e.reason)
0101ce28 9049 {
983af33b
SDJ
9050 case GDB_NO_ERROR:
9051 if (VEC_empty (linespec_sals, canonical.sals))
9052 return 0;
9053 break;
05ff989b
AC
9054 case RETURN_ERROR:
9055 switch (e.error)
0101ce28 9056 {
05ff989b 9057 case NOT_FOUND_ERROR:
0101ce28 9058
05ff989b
AC
9059 /* If pending breakpoint support is turned off, throw
9060 error. */
fa8d40ab
JJ
9061
9062 if (pending_break_support == AUTO_BOOLEAN_FALSE)
723a2275
VP
9063 throw_exception (e);
9064
9065 exception_print (gdb_stderr, e);
fa8d40ab 9066
05ff989b
AC
9067 /* If pending breakpoint support is auto query and the user
9068 selects no, then simply return the error code. */
059fb39f 9069 if (pending_break_support == AUTO_BOOLEAN_AUTO
bfccc43c
YQ
9070 && !nquery (_("Make %s pending on future shared library load? "),
9071 bptype_string (type_wanted)))
fd9b8c24 9072 return 0;
fa8d40ab 9073
05ff989b
AC
9074 /* At this point, either the user was queried about setting
9075 a pending breakpoint and selected yes, or pending
9076 breakpoint behavior is on and thus a pending breakpoint
9077 is defaulted on behalf of the user. */
f8eba3c6
TT
9078 {
9079 struct linespec_sals lsal;
9080
9081 copy_arg = xstrdup (addr_start);
9082 lsal.canonical = xstrdup (copy_arg);
9083 lsal.sals.nelts = 1;
9084 lsal.sals.sals = XNEW (struct symtab_and_line);
9085 init_sal (&lsal.sals.sals[0]);
9086 pending = 1;
9087 VEC_safe_push (linespec_sals, canonical.sals, &lsal);
9088 }
05ff989b
AC
9089 break;
9090 default:
98deb0da 9091 throw_exception (e);
0101ce28 9092 }
2abae994 9093 break;
05ff989b 9094 default:
983af33b 9095 throw_exception (e);
0101ce28 9096 }
c3f6f71d 9097
4a64f543 9098 /* Create a chain of things that always need to be cleaned up. */
f8eba3c6 9099 old_chain = make_cleanup_destroy_linespec_result (&canonical);
c3f6f71d 9100
c3f6f71d
JM
9101 /* ----------------------------- SNIP -----------------------------
9102 Anything added to the cleanup chain beyond this point is assumed
9103 to be part of a breakpoint. If the breakpoint create succeeds
80c99de1
PA
9104 then the memory is not reclaimed. */
9105 bkpt_chain = make_cleanup (null_cleanup, 0);
c3f6f71d 9106
c3f6f71d
JM
9107 /* Resolve all line numbers to PC's and verify that the addresses
9108 are ok for the target. */
0101ce28 9109 if (!pending)
f8eba3c6
TT
9110 {
9111 int ix;
9112 struct linespec_sals *iter;
9113
9114 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9115 breakpoint_sals_to_pc (&iter->sals);
9116 }
c3f6f71d 9117
7a697b8d 9118 /* Fast tracepoints may have additional restrictions on location. */
bfccc43c 9119 if (!pending && type_wanted == bp_fast_tracepoint)
f8eba3c6
TT
9120 {
9121 int ix;
9122 struct linespec_sals *iter;
9123
9124 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix)
9125 check_fast_tracepoint_sals (gdbarch, &iter->sals);
9126 }
7a697b8d 9127
c3f6f71d
JM
9128 /* Verify that condition can be parsed, before setting any
9129 breakpoints. Allocate a separate condition expression for each
4a64f543 9130 breakpoint. */
0101ce28 9131 if (!pending)
c3f6f71d 9132 {
f8eba3c6
TT
9133 struct linespec_sals *lsal;
9134
9135 lsal = VEC_index (linespec_sals, canonical.sals, 0);
9136
2f069f6f 9137 if (parse_condition_and_thread)
72b2ff0e 9138 {
e7e0cddf 9139 char *rest;
72b2ff0e
VP
9140 /* Here we only parse 'arg' to separate condition
9141 from thread number, so parsing in context of first
9142 sal is OK. When setting the breakpoint we'll
9143 re-parse it in context of each sal. */
9144 cond_string = NULL;
9145 thread = -1;
e7e0cddf 9146 rest = NULL;
f8eba3c6 9147 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string,
e7e0cddf 9148 &thread, &task, &rest);
72b2ff0e
VP
9149 if (cond_string)
9150 make_cleanup (xfree, cond_string);
e7e0cddf
SS
9151 if (rest)
9152 make_cleanup (xfree, rest);
9153 if (rest)
9154 extra_string = rest;
72b2ff0e 9155 }
2f069f6f 9156 else
72b2ff0e
VP
9157 {
9158 /* Create a private copy of condition string. */
9159 if (cond_string)
9160 {
9161 cond_string = xstrdup (cond_string);
9162 make_cleanup (xfree, cond_string);
9163 }
e7e0cddf
SS
9164 /* Create a private copy of any extra string. */
9165 if (extra_string)
9166 {
9167 extra_string = xstrdup (extra_string);
9168 make_cleanup (xfree, extra_string);
9169 }
72b2ff0e 9170 }
0fb4aa4b 9171
983af33b 9172 ops->create_breakpoints_sal (gdbarch, &canonical, lsal,
e7e0cddf 9173 cond_string, extra_string, type_wanted,
d9b3f62e
PA
9174 tempflag ? disp_del : disp_donttouch,
9175 thread, task, ignore_count, ops,
44f238bb 9176 from_tty, enabled, internal, flags);
c906108c 9177 }
0101ce28
JJ
9178 else
9179 {
0101ce28
JJ
9180 struct breakpoint *b;
9181
0101ce28
JJ
9182 make_cleanup (xfree, copy_arg);
9183
bfccc43c
YQ
9184 if (is_tracepoint_type (type_wanted))
9185 {
9186 struct tracepoint *t;
9187
9188 t = XCNEW (struct tracepoint);
9189 b = &t->base;
9190 }
9191 else
9192 b = XNEW (struct breakpoint);
9193
9194 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
9195
f8eba3c6 9196 b->addr_string = copy_arg;
72b2ff0e 9197 b->cond_string = NULL;
e7e0cddf 9198 b->extra_string = NULL;
0101ce28 9199 b->ignore_count = ignore_count;
0101ce28 9200 b->disposition = tempflag ? disp_del : disp_donttouch;
0d381245 9201 b->condition_not_parsed = 1;
41447f92 9202 b->enable_state = enabled ? bp_enabled : bp_disabled;
cc72b2a2
KP
9203 if ((type_wanted != bp_breakpoint
9204 && type_wanted != bp_hardware_breakpoint) || thread != -1)
f8eba3c6 9205 b->pspace = current_program_space;
8bea4e01 9206
bfccc43c 9207 install_breakpoint (internal, b, 0);
0101ce28
JJ
9208 }
9209
f8eba3c6 9210 if (VEC_length (linespec_sals, canonical.sals) > 1)
95a42b64 9211 {
3e43a32a
MS
9212 warning (_("Multiple breakpoints were set.\nUse the "
9213 "\"delete\" command to delete unwanted breakpoints."));
86b17b60 9214 prev_breakpoint_count = prev_bkpt_count;
95a42b64
TT
9215 }
9216
80c99de1
PA
9217 /* That's it. Discard the cleanups for data inserted into the
9218 breakpoint. */
9219 discard_cleanups (bkpt_chain);
9220 /* But cleanup everything else. */
c3f6f71d 9221 do_cleanups (old_chain);
217dc9e2 9222
80c99de1 9223 /* error call may happen here - have BKPT_CHAIN already discarded. */
217dc9e2 9224 update_global_location_list (1);
fd9b8c24
PA
9225
9226 return 1;
c3f6f71d 9227}
c906108c 9228
348d480f 9229/* Set a breakpoint.
72b2ff0e
VP
9230 ARG is a string describing breakpoint address,
9231 condition, and thread.
9232 FLAG specifies if a breakpoint is hardware on,
9233 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9234 and BP_TEMPFLAG. */
348d480f 9235
98deb0da 9236static void
72b2ff0e 9237break_command_1 (char *arg, int flag, int from_tty)
c3f6f71d 9238{
72b2ff0e 9239 int tempflag = flag & BP_TEMPFLAG;
0fb4aa4b
PA
9240 enum bptype type_wanted = (flag & BP_HARDWAREFLAG
9241 ? bp_hardware_breakpoint
9242 : bp_breakpoint);
55aa24fb
SDJ
9243 struct breakpoint_ops *ops;
9244 const char *arg_cp = arg;
9245
9246 /* Matching breakpoints on probes. */
9247 if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
9248 ops = &bkpt_probe_breakpoint_ops;
9249 else
9250 ops = &bkpt_breakpoint_ops;
c3f6f71d 9251
8cdf0e15
VP
9252 create_breakpoint (get_current_arch (),
9253 arg,
e7e0cddf 9254 NULL, 0, NULL, 1 /* parse arg */,
0fb4aa4b 9255 tempflag, type_wanted,
8cdf0e15
VP
9256 0 /* Ignore count */,
9257 pending_break_support,
55aa24fb 9258 ops,
8cdf0e15 9259 from_tty,
84f4c1fe 9260 1 /* enabled */,
44f238bb
PA
9261 0 /* internal */,
9262 0);
c906108c
SS
9263}
9264
c906108c
SS
9265/* Helper function for break_command_1 and disassemble_command. */
9266
9267void
fba45db2 9268resolve_sal_pc (struct symtab_and_line *sal)
c906108c
SS
9269{
9270 CORE_ADDR pc;
9271
9272 if (sal->pc == 0 && sal->symtab != NULL)
9273 {
9274 if (!find_line_pc (sal->symtab, sal->line, &pc))
8a3fe4f8 9275 error (_("No line %d in file \"%s\"."),
c906108c
SS
9276 sal->line, sal->symtab->filename);
9277 sal->pc = pc;
6a048695 9278
4a64f543
MS
9279 /* If this SAL corresponds to a breakpoint inserted using a line
9280 number, then skip the function prologue if necessary. */
6a048695 9281 if (sal->explicit_line)
059acae7 9282 skip_prologue_sal (sal);
c906108c
SS
9283 }
9284
9285 if (sal->section == 0 && sal->symtab != NULL)
9286 {
9287 struct blockvector *bv;
c5aa993b
JM
9288 struct block *b;
9289 struct symbol *sym;
c906108c 9290
801e3a5b 9291 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
c906108c
SS
9292 if (bv != NULL)
9293 {
7f0df278 9294 sym = block_linkage_function (b);
c906108c
SS
9295 if (sym != NULL)
9296 {
9297 fixup_symbol_section (sym, sal->symtab->objfile);
714835d5 9298 sal->section = SYMBOL_OBJ_SECTION (sym);
c906108c
SS
9299 }
9300 else
9301 {
4a64f543
MS
9302 /* It really is worthwhile to have the section, so we'll
9303 just have to look harder. This case can be executed
9304 if we have line numbers but no functions (as can
9305 happen in assembly source). */
c906108c 9306
c5aa993b 9307 struct minimal_symbol *msym;
6c95b8df
PA
9308 struct cleanup *old_chain = save_current_space_and_thread ();
9309
9310 switch_to_program_space_and_thread (sal->pspace);
c906108c
SS
9311
9312 msym = lookup_minimal_symbol_by_pc (sal->pc);
9313 if (msym)
714835d5 9314 sal->section = SYMBOL_OBJ_SECTION (msym);
6c95b8df
PA
9315
9316 do_cleanups (old_chain);
c906108c
SS
9317 }
9318 }
9319 }
9320}
9321
9322void
fba45db2 9323break_command (char *arg, int from_tty)
c906108c 9324{
db107f19 9325 break_command_1 (arg, 0, from_tty);
c906108c
SS
9326}
9327
c906108c 9328void
fba45db2 9329tbreak_command (char *arg, int from_tty)
c906108c 9330{
db107f19 9331 break_command_1 (arg, BP_TEMPFLAG, from_tty);
c906108c
SS
9332}
9333
c906108c 9334static void
fba45db2 9335hbreak_command (char *arg, int from_tty)
c906108c 9336{
db107f19 9337 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
c906108c
SS
9338}
9339
9340static void
fba45db2 9341thbreak_command (char *arg, int from_tty)
c906108c 9342{
db107f19 9343 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
c906108c
SS
9344}
9345
9346static void
fba45db2 9347stop_command (char *arg, int from_tty)
c906108c 9348{
a3f17187 9349 printf_filtered (_("Specify the type of breakpoint to set.\n\
c906108c 9350Usage: stop in <function | address>\n\
a3f17187 9351 stop at <line>\n"));
c906108c
SS
9352}
9353
9354static void
fba45db2 9355stopin_command (char *arg, int from_tty)
c906108c
SS
9356{
9357 int badInput = 0;
9358
c5aa993b 9359 if (arg == (char *) NULL)
c906108c
SS
9360 badInput = 1;
9361 else if (*arg != '*')
9362 {
9363 char *argptr = arg;
9364 int hasColon = 0;
9365
4a64f543 9366 /* Look for a ':'. If this is a line number specification, then
53a5351d 9367 say it is bad, otherwise, it should be an address or
4a64f543 9368 function/method name. */
c906108c 9369 while (*argptr && !hasColon)
c5aa993b
JM
9370 {
9371 hasColon = (*argptr == ':');
9372 argptr++;
9373 }
c906108c
SS
9374
9375 if (hasColon)
c5aa993b 9376 badInput = (*argptr != ':'); /* Not a class::method */
c906108c 9377 else
c5aa993b 9378 badInput = isdigit (*arg); /* a simple line number */
c906108c
SS
9379 }
9380
9381 if (badInput)
a3f17187 9382 printf_filtered (_("Usage: stop in <function | address>\n"));
c906108c 9383 else
db107f19 9384 break_command_1 (arg, 0, from_tty);
c906108c
SS
9385}
9386
9387static void
fba45db2 9388stopat_command (char *arg, int from_tty)
c906108c
SS
9389{
9390 int badInput = 0;
9391
c5aa993b 9392 if (arg == (char *) NULL || *arg == '*') /* no line number */
c906108c
SS
9393 badInput = 1;
9394 else
9395 {
9396 char *argptr = arg;
9397 int hasColon = 0;
9398
4a64f543
MS
9399 /* Look for a ':'. If there is a '::' then get out, otherwise
9400 it is probably a line number. */
c906108c 9401 while (*argptr && !hasColon)
c5aa993b
JM
9402 {
9403 hasColon = (*argptr == ':');
9404 argptr++;
9405 }
c906108c
SS
9406
9407 if (hasColon)
c5aa993b 9408 badInput = (*argptr == ':'); /* we have class::method */
c906108c 9409 else
c5aa993b 9410 badInput = !isdigit (*arg); /* not a line number */
c906108c
SS
9411 }
9412
9413 if (badInput)
a3f17187 9414 printf_filtered (_("Usage: stop at <line>\n"));
c906108c 9415 else
db107f19 9416 break_command_1 (arg, 0, from_tty);
c906108c
SS
9417}
9418
e7e0cddf
SS
9419void dprintf_command (char *arg, int from_tty);
9420
9421/* The dynamic printf command is mostly like a regular breakpoint, but
9422 with a prewired command list consisting of a single output command,
9423 built from extra arguments supplied on the dprintf command
9424 line. */
9425
9426void
9427dprintf_command (char *arg, int from_tty)
9428{
9429 create_breakpoint (get_current_arch (),
9430 arg,
9431 NULL, 0, NULL, 1 /* parse arg */,
9432 0, bp_dprintf,
9433 0 /* Ignore count */,
9434 pending_break_support,
9435 &dprintf_breakpoint_ops,
9436 from_tty,
9437 1 /* enabled */,
9438 0 /* internal */,
9439 0);
9440}
9441
f1310107
TJB
9442/* Implement the "breakpoint_hit" breakpoint_ops method for
9443 ranged breakpoints. */
9444
9445static int
9446breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
9447 struct address_space *aspace,
09ac7c10
TT
9448 CORE_ADDR bp_addr,
9449 const struct target_waitstatus *ws)
f1310107 9450{
09ac7c10 9451 if (ws->kind != TARGET_WAITKIND_STOPPED
a493e3e2 9452 || ws->value.sig != GDB_SIGNAL_TRAP)
09ac7c10
TT
9453 return 0;
9454
f1310107
TJB
9455 return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
9456 bl->length, aspace, bp_addr);
9457}
9458
9459/* Implement the "resources_needed" breakpoint_ops method for
9460 ranged breakpoints. */
9461
9462static int
9463resources_needed_ranged_breakpoint (const struct bp_location *bl)
9464{
9465 return target_ranged_break_num_registers ();
9466}
9467
9468/* Implement the "print_it" breakpoint_ops method for
9469 ranged breakpoints. */
9470
9471static enum print_stop_action
348d480f 9472print_it_ranged_breakpoint (bpstat bs)
f1310107 9473{
348d480f 9474 struct breakpoint *b = bs->breakpoint_at;
f1310107 9475 struct bp_location *bl = b->loc;
79a45e25 9476 struct ui_out *uiout = current_uiout;
f1310107
TJB
9477
9478 gdb_assert (b->type == bp_hardware_breakpoint);
9479
9480 /* Ranged breakpoints have only one location. */
9481 gdb_assert (bl && bl->next == NULL);
9482
9483 annotate_breakpoint (b->number);
9484 if (b->disposition == disp_del)
9485 ui_out_text (uiout, "\nTemporary ranged breakpoint ");
9486 else
9487 ui_out_text (uiout, "\nRanged breakpoint ");
9488 if (ui_out_is_mi_like_p (uiout))
9489 {
9490 ui_out_field_string (uiout, "reason",
9491 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
9492 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
9493 }
9494 ui_out_field_int (uiout, "bkptno", b->number);
9495 ui_out_text (uiout, ", ");
9496
9497 return PRINT_SRC_AND_LOC;
9498}
9499
9500/* Implement the "print_one" breakpoint_ops method for
9501 ranged breakpoints. */
9502
9503static void
9504print_one_ranged_breakpoint (struct breakpoint *b,
9505 struct bp_location **last_loc)
9506{
9507 struct bp_location *bl = b->loc;
9508 struct value_print_options opts;
79a45e25 9509 struct ui_out *uiout = current_uiout;
f1310107
TJB
9510
9511 /* Ranged breakpoints have only one location. */
9512 gdb_assert (bl && bl->next == NULL);
9513
9514 get_user_print_options (&opts);
9515
9516 if (opts.addressprint)
9517 /* We don't print the address range here, it will be printed later
9518 by print_one_detail_ranged_breakpoint. */
9519 ui_out_field_skip (uiout, "addr");
9520 annotate_field (5);
9521 print_breakpoint_location (b, bl);
9522 *last_loc = bl;
9523}
9524
9525/* Implement the "print_one_detail" breakpoint_ops method for
9526 ranged breakpoints. */
9527
9528static void
9529print_one_detail_ranged_breakpoint (const struct breakpoint *b,
9530 struct ui_out *uiout)
9531{
9532 CORE_ADDR address_start, address_end;
9533 struct bp_location *bl = b->loc;
f99d8bf4
PA
9534 struct ui_file *stb = mem_fileopen ();
9535 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb);
f1310107
TJB
9536
9537 gdb_assert (bl);
9538
9539 address_start = bl->address;
9540 address_end = address_start + bl->length - 1;
9541
9542 ui_out_text (uiout, "\taddress range: ");
f99d8bf4 9543 fprintf_unfiltered (stb, "[%s, %s]",
f1310107
TJB
9544 print_core_address (bl->gdbarch, address_start),
9545 print_core_address (bl->gdbarch, address_end));
9546 ui_out_field_stream (uiout, "addr", stb);
9547 ui_out_text (uiout, "\n");
9548
9549 do_cleanups (cleanup);
9550}
9551
9552/* Implement the "print_mention" breakpoint_ops method for
9553 ranged breakpoints. */
9554
9555static void
9556print_mention_ranged_breakpoint (struct breakpoint *b)
9557{
9558 struct bp_location *bl = b->loc;
79a45e25 9559 struct ui_out *uiout = current_uiout;
f1310107
TJB
9560
9561 gdb_assert (bl);
9562 gdb_assert (b->type == bp_hardware_breakpoint);
9563
9564 if (ui_out_is_mi_like_p (uiout))
9565 return;
9566
9567 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9568 b->number, paddress (bl->gdbarch, bl->address),
9569 paddress (bl->gdbarch, bl->address + bl->length - 1));
9570}
9571
9572/* Implement the "print_recreate" breakpoint_ops method for
9573 ranged breakpoints. */
9574
9575static void
9576print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
9577{
9578 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
9579 b->addr_string_range_end);
d9b3f62e 9580 print_recreate_thread (b, fp);
f1310107
TJB
9581}
9582
9583/* The breakpoint_ops structure to be used in ranged breakpoints. */
9584
2060206e 9585static struct breakpoint_ops ranged_breakpoint_ops;
f1310107
TJB
9586
9587/* Find the address where the end of the breakpoint range should be
9588 placed, given the SAL of the end of the range. This is so that if
9589 the user provides a line number, the end of the range is set to the
9590 last instruction of the given line. */
9591
9592static CORE_ADDR
9593find_breakpoint_range_end (struct symtab_and_line sal)
9594{
9595 CORE_ADDR end;
9596
9597 /* If the user provided a PC value, use it. Otherwise,
9598 find the address of the end of the given location. */
9599 if (sal.explicit_pc)
9600 end = sal.pc;
9601 else
9602 {
9603 int ret;
9604 CORE_ADDR start;
9605
9606 ret = find_line_pc_range (sal, &start, &end);
9607 if (!ret)
9608 error (_("Could not find location of the end of the range."));
9609
9610 /* find_line_pc_range returns the start of the next line. */
9611 end--;
9612 }
9613
9614 return end;
9615}
9616
9617/* Implement the "break-range" CLI command. */
9618
9619static void
9620break_range_command (char *arg, int from_tty)
9621{
9622 char *arg_start, *addr_string_start, *addr_string_end;
9623 struct linespec_result canonical_start, canonical_end;
9624 int bp_count, can_use_bp, length;
9625 CORE_ADDR end;
9626 struct breakpoint *b;
9627 struct symtab_and_line sal_start, sal_end;
f1310107 9628 struct cleanup *cleanup_bkpt;
f8eba3c6 9629 struct linespec_sals *lsal_start, *lsal_end;
f1310107
TJB
9630
9631 /* We don't support software ranged breakpoints. */
9632 if (target_ranged_break_num_registers () < 0)
9633 error (_("This target does not support hardware ranged breakpoints."));
9634
9635 bp_count = hw_breakpoint_used_count ();
9636 bp_count += target_ranged_break_num_registers ();
9637 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
9638 bp_count, 0);
9639 if (can_use_bp < 0)
9640 error (_("Hardware breakpoints used exceeds limit."));
9641
f8eba3c6 9642 arg = skip_spaces (arg);
f1310107
TJB
9643 if (arg == NULL || arg[0] == '\0')
9644 error(_("No address range specified."));
9645
f1310107
TJB
9646 init_linespec_result (&canonical_start);
9647
f8eba3c6
TT
9648 arg_start = arg;
9649 parse_breakpoint_sals (&arg, &canonical_start);
f1310107 9650
f8eba3c6 9651 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
f1310107
TJB
9652
9653 if (arg[0] != ',')
9654 error (_("Too few arguments."));
f8eba3c6 9655 else if (VEC_empty (linespec_sals, canonical_start.sals))
f1310107 9656 error (_("Could not find location of the beginning of the range."));
f8eba3c6
TT
9657
9658 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0);
9659
9660 if (VEC_length (linespec_sals, canonical_start.sals) > 1
9661 || lsal_start->sals.nelts != 1)
f1310107
TJB
9662 error (_("Cannot create a ranged breakpoint with multiple locations."));
9663
f8eba3c6
TT
9664 sal_start = lsal_start->sals.sals[0];
9665 addr_string_start = savestring (arg_start, arg - arg_start);
9666 make_cleanup (xfree, addr_string_start);
f1310107
TJB
9667
9668 arg++; /* Skip the comma. */
f8eba3c6 9669 arg = skip_spaces (arg);
f1310107
TJB
9670
9671 /* Parse the end location. */
9672
f1310107
TJB
9673 init_linespec_result (&canonical_end);
9674 arg_start = arg;
9675
f8eba3c6 9676 /* We call decode_line_full directly here instead of using
f1310107
TJB
9677 parse_breakpoint_sals because we need to specify the start location's
9678 symtab and line as the default symtab and line for the end of the
9679 range. This makes it possible to have ranges like "foo.c:27, +14",
9680 where +14 means 14 lines from the start location. */
f8eba3c6
TT
9681 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
9682 sal_start.symtab, sal_start.line,
9683 &canonical_end, NULL, NULL);
9684
9685 make_cleanup_destroy_linespec_result (&canonical_end);
f1310107 9686
f8eba3c6 9687 if (VEC_empty (linespec_sals, canonical_end.sals))
f1310107 9688 error (_("Could not find location of the end of the range."));
f8eba3c6
TT
9689
9690 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0);
9691 if (VEC_length (linespec_sals, canonical_end.sals) > 1
9692 || lsal_end->sals.nelts != 1)
f1310107
TJB
9693 error (_("Cannot create a ranged breakpoint with multiple locations."));
9694
f8eba3c6
TT
9695 sal_end = lsal_end->sals.sals[0];
9696 addr_string_end = savestring (arg_start, arg - arg_start);
9697 make_cleanup (xfree, addr_string_end);
f1310107
TJB
9698
9699 end = find_breakpoint_range_end (sal_end);
9700 if (sal_start.pc > end)
177b42fe 9701 error (_("Invalid address range, end precedes start."));
f1310107
TJB
9702
9703 length = end - sal_start.pc + 1;
9704 if (length < 0)
9705 /* Length overflowed. */
9706 error (_("Address range too large."));
9707 else if (length == 1)
9708 {
9709 /* This range is simple enough to be handled by
9710 the `hbreak' command. */
9711 hbreak_command (addr_string_start, 1);
9712
9713 do_cleanups (cleanup_bkpt);
9714
9715 return;
9716 }
9717
9718 /* Now set up the breakpoint. */
9719 b = set_raw_breakpoint (get_current_arch (), sal_start,
348d480f 9720 bp_hardware_breakpoint, &ranged_breakpoint_ops);
f1310107
TJB
9721 set_breakpoint_count (breakpoint_count + 1);
9722 b->number = breakpoint_count;
9723 b->disposition = disp_donttouch;
f8eba3c6
TT
9724 b->addr_string = xstrdup (addr_string_start);
9725 b->addr_string_range_end = xstrdup (addr_string_end);
f1310107
TJB
9726 b->loc->length = length;
9727
f8eba3c6 9728 do_cleanups (cleanup_bkpt);
f1310107
TJB
9729
9730 mention (b);
8d3788bd 9731 observer_notify_breakpoint_created (b);
f1310107
TJB
9732 update_global_location_list (1);
9733}
9734
4a64f543
MS
9735/* Return non-zero if EXP is verified as constant. Returned zero
9736 means EXP is variable. Also the constant detection may fail for
9737 some constant expressions and in such case still falsely return
9738 zero. */
2e6e3d9c 9739
65d79d4b
SDJ
9740static int
9741watchpoint_exp_is_const (const struct expression *exp)
9742{
9743 int i = exp->nelts;
9744
9745 while (i > 0)
9746 {
9747 int oplenp, argsp;
9748
9749 /* We are only interested in the descriptor of each element. */
9750 operator_length (exp, i, &oplenp, &argsp);
9751 i -= oplenp;
9752
9753 switch (exp->elts[i].opcode)
9754 {
9755 case BINOP_ADD:
9756 case BINOP_SUB:
9757 case BINOP_MUL:
9758 case BINOP_DIV:
9759 case BINOP_REM:
9760 case BINOP_MOD:
9761 case BINOP_LSH:
9762 case BINOP_RSH:
9763 case BINOP_LOGICAL_AND:
9764 case BINOP_LOGICAL_OR:
9765 case BINOP_BITWISE_AND:
9766 case BINOP_BITWISE_IOR:
9767 case BINOP_BITWISE_XOR:
9768 case BINOP_EQUAL:
9769 case BINOP_NOTEQUAL:
9770 case BINOP_LESS:
9771 case BINOP_GTR:
9772 case BINOP_LEQ:
9773 case BINOP_GEQ:
9774 case BINOP_REPEAT:
9775 case BINOP_COMMA:
9776 case BINOP_EXP:
9777 case BINOP_MIN:
9778 case BINOP_MAX:
9779 case BINOP_INTDIV:
9780 case BINOP_CONCAT:
9781 case BINOP_IN:
9782 case BINOP_RANGE:
9783 case TERNOP_COND:
9784 case TERNOP_SLICE:
9785 case TERNOP_SLICE_COUNT:
9786
9787 case OP_LONG:
9788 case OP_DOUBLE:
9789 case OP_DECFLOAT:
9790 case OP_LAST:
9791 case OP_COMPLEX:
9792 case OP_STRING:
9793 case OP_BITSTRING:
9794 case OP_ARRAY:
9795 case OP_TYPE:
9796 case OP_NAME:
9797 case OP_OBJC_NSSTRING:
9798
9799 case UNOP_NEG:
9800 case UNOP_LOGICAL_NOT:
9801 case UNOP_COMPLEMENT:
9802 case UNOP_ADDR:
9803 case UNOP_HIGH:
aeaa2474 9804 case UNOP_CAST:
4a64f543
MS
9805 /* Unary, binary and ternary operators: We have to check
9806 their operands. If they are constant, then so is the
9807 result of that operation. For instance, if A and B are
9808 determined to be constants, then so is "A + B".
9809
9810 UNOP_IND is one exception to the rule above, because the
9811 value of *ADDR is not necessarily a constant, even when
9812 ADDR is. */
65d79d4b
SDJ
9813 break;
9814
9815 case OP_VAR_VALUE:
9816 /* Check whether the associated symbol is a constant.
4a64f543 9817
65d79d4b 9818 We use SYMBOL_CLASS rather than TYPE_CONST because it's
4a64f543
MS
9819 possible that a buggy compiler could mark a variable as
9820 constant even when it is not, and TYPE_CONST would return
9821 true in this case, while SYMBOL_CLASS wouldn't.
9822
9823 We also have to check for function symbols because they
9824 are always constant. */
65d79d4b
SDJ
9825 {
9826 struct symbol *s = exp->elts[i + 2].symbol;
9827
9828 if (SYMBOL_CLASS (s) != LOC_BLOCK
9829 && SYMBOL_CLASS (s) != LOC_CONST
9830 && SYMBOL_CLASS (s) != LOC_CONST_BYTES)
9831 return 0;
9832 break;
9833 }
9834
9835 /* The default action is to return 0 because we are using
9836 the optimistic approach here: If we don't know something,
9837 then it is not a constant. */
9838 default:
9839 return 0;
9840 }
9841 }
9842
9843 return 1;
9844}
9845
3a5c3e22
PA
9846/* Implement the "dtor" breakpoint_ops method for watchpoints. */
9847
9848static void
9849dtor_watchpoint (struct breakpoint *self)
9850{
9851 struct watchpoint *w = (struct watchpoint *) self;
9852
9853 xfree (w->cond_exp);
9854 xfree (w->exp);
9855 xfree (w->exp_string);
9856 xfree (w->exp_string_reparse);
9857 value_free (w->val);
9858
9859 base_breakpoint_ops.dtor (self);
9860}
9861
348d480f
PA
9862/* Implement the "re_set" breakpoint_ops method for watchpoints. */
9863
9864static void
9865re_set_watchpoint (struct breakpoint *b)
9866{
3a5c3e22
PA
9867 struct watchpoint *w = (struct watchpoint *) b;
9868
348d480f
PA
9869 /* Watchpoint can be either on expression using entirely global
9870 variables, or it can be on local variables.
9871
9872 Watchpoints of the first kind are never auto-deleted, and even
9873 persist across program restarts. Since they can use variables
9874 from shared libraries, we need to reparse expression as libraries
9875 are loaded and unloaded.
9876
9877 Watchpoints on local variables can also change meaning as result
9878 of solib event. For example, if a watchpoint uses both a local
9879 and a global variables in expression, it's a local watchpoint,
9880 but unloading of a shared library will make the expression
9881 invalid. This is not a very common use case, but we still
9882 re-evaluate expression, to avoid surprises to the user.
9883
9884 Note that for local watchpoints, we re-evaluate it only if
9885 watchpoints frame id is still valid. If it's not, it means the
9886 watchpoint is out of scope and will be deleted soon. In fact,
9887 I'm not sure we'll ever be called in this case.
9888
9889 If a local watchpoint's frame id is still valid, then
3a5c3e22 9890 w->exp_valid_block is likewise valid, and we can safely use it.
348d480f 9891
3a5c3e22
PA
9892 Don't do anything about disabled watchpoints, since they will be
9893 reevaluated again when enabled. */
9894 update_watchpoint (w, 1 /* reparse */);
348d480f
PA
9895}
9896
77b06cd7
TJB
9897/* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9898
9899static int
9900insert_watchpoint (struct bp_location *bl)
9901{
3a5c3e22
PA
9902 struct watchpoint *w = (struct watchpoint *) bl->owner;
9903 int length = w->exact ? 1 : bl->length;
e09342b5
TJB
9904
9905 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type,
3a5c3e22 9906 w->cond_exp);
77b06cd7
TJB
9907}
9908
9909/* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9910
9911static int
9912remove_watchpoint (struct bp_location *bl)
9913{
3a5c3e22
PA
9914 struct watchpoint *w = (struct watchpoint *) bl->owner;
9915 int length = w->exact ? 1 : bl->length;
e09342b5
TJB
9916
9917 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type,
3a5c3e22 9918 w->cond_exp);
e09342b5
TJB
9919}
9920
e09342b5 9921static int
348d480f 9922breakpoint_hit_watchpoint (const struct bp_location *bl,
09ac7c10
TT
9923 struct address_space *aspace, CORE_ADDR bp_addr,
9924 const struct target_waitstatus *ws)
e09342b5 9925{
348d480f 9926 struct breakpoint *b = bl->owner;
3a5c3e22 9927 struct watchpoint *w = (struct watchpoint *) b;
77b06cd7 9928
348d480f
PA
9929 /* Continuable hardware watchpoints are treated as non-existent if the
9930 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9931 some data address). Otherwise gdb won't stop on a break instruction
9932 in the code (not from a breakpoint) when a hardware watchpoint has
9933 been defined. Also skip watchpoints which we know did not trigger
9934 (did not match the data address). */
9935 if (is_hardware_watchpoint (b)
3a5c3e22 9936 && w->watchpoint_triggered == watch_triggered_no)
348d480f 9937 return 0;
9c06b0b4 9938
348d480f 9939 return 1;
9c06b0b4
TJB
9940}
9941
348d480f
PA
9942static void
9943check_status_watchpoint (bpstat bs)
9c06b0b4 9944{
348d480f 9945 gdb_assert (is_watchpoint (bs->breakpoint_at));
9c06b0b4 9946
348d480f 9947 bpstat_check_watchpoint (bs);
9c06b0b4
TJB
9948}
9949
9950/* Implement the "resources_needed" breakpoint_ops method for
348d480f 9951 hardware watchpoints. */
9c06b0b4
TJB
9952
9953static int
348d480f 9954resources_needed_watchpoint (const struct bp_location *bl)
9c06b0b4 9955{
3a5c3e22
PA
9956 struct watchpoint *w = (struct watchpoint *) bl->owner;
9957 int length = w->exact? 1 : bl->length;
348d480f
PA
9958
9959 return target_region_ok_for_hw_watchpoint (bl->address, length);
9c06b0b4
TJB
9960}
9961
9962/* Implement the "works_in_software_mode" breakpoint_ops method for
348d480f 9963 hardware watchpoints. */
9c06b0b4
TJB
9964
9965static int
348d480f 9966works_in_software_mode_watchpoint (const struct breakpoint *b)
9c06b0b4 9967{
efa80663
PA
9968 /* Read and access watchpoints only work with hardware support. */
9969 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint;
9c06b0b4
TJB
9970}
9971
9c06b0b4 9972static enum print_stop_action
348d480f 9973print_it_watchpoint (bpstat bs)
9c06b0b4 9974{
348d480f
PA
9975 struct cleanup *old_chain;
9976 struct breakpoint *b;
9977 const struct bp_location *bl;
f99d8bf4 9978 struct ui_file *stb;
348d480f 9979 enum print_stop_action result;
3a5c3e22 9980 struct watchpoint *w;
79a45e25 9981 struct ui_out *uiout = current_uiout;
348d480f
PA
9982
9983 gdb_assert (bs->bp_location_at != NULL);
9984
9985 bl = bs->bp_location_at;
9986 b = bs->breakpoint_at;
3a5c3e22 9987 w = (struct watchpoint *) b;
348d480f 9988
f99d8bf4
PA
9989 stb = mem_fileopen ();
9990 old_chain = make_cleanup_ui_file_delete (stb);
9c06b0b4
TJB
9991
9992 switch (b->type)
9993 {
348d480f 9994 case bp_watchpoint:
9c06b0b4
TJB
9995 case bp_hardware_watchpoint:
9996 annotate_watchpoint (b->number);
9997 if (ui_out_is_mi_like_p (uiout))
9998 ui_out_field_string
9999 (uiout, "reason",
10000 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
348d480f
PA
10001 mention (b);
10002 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10003 ui_out_text (uiout, "\nOld value = ");
f99d8bf4 10004 watchpoint_value_print (bs->old_val, stb);
348d480f
PA
10005 ui_out_field_stream (uiout, "old", stb);
10006 ui_out_text (uiout, "\nNew value = ");
f99d8bf4 10007 watchpoint_value_print (w->val, stb);
348d480f
PA
10008 ui_out_field_stream (uiout, "new", stb);
10009 ui_out_text (uiout, "\n");
10010 /* More than one watchpoint may have been triggered. */
10011 result = PRINT_UNKNOWN;
9c06b0b4
TJB
10012 break;
10013
10014 case bp_read_watchpoint:
10015 if (ui_out_is_mi_like_p (uiout))
10016 ui_out_field_string
10017 (uiout, "reason",
10018 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
348d480f
PA
10019 mention (b);
10020 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10021 ui_out_text (uiout, "\nValue = ");
f99d8bf4 10022 watchpoint_value_print (w->val, stb);
348d480f
PA
10023 ui_out_field_stream (uiout, "value", stb);
10024 ui_out_text (uiout, "\n");
10025 result = PRINT_UNKNOWN;
9c06b0b4
TJB
10026 break;
10027
10028 case bp_access_watchpoint:
348d480f
PA
10029 if (bs->old_val != NULL)
10030 {
10031 annotate_watchpoint (b->number);
10032 if (ui_out_is_mi_like_p (uiout))
10033 ui_out_field_string
10034 (uiout, "reason",
10035 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10036 mention (b);
10037 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10038 ui_out_text (uiout, "\nOld value = ");
f99d8bf4 10039 watchpoint_value_print (bs->old_val, stb);
348d480f
PA
10040 ui_out_field_stream (uiout, "old", stb);
10041 ui_out_text (uiout, "\nNew value = ");
10042 }
10043 else
10044 {
10045 mention (b);
10046 if (ui_out_is_mi_like_p (uiout))
10047 ui_out_field_string
10048 (uiout, "reason",
10049 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10050 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
10051 ui_out_text (uiout, "\nValue = ");
10052 }
f99d8bf4 10053 watchpoint_value_print (w->val, stb);
348d480f
PA
10054 ui_out_field_stream (uiout, "new", stb);
10055 ui_out_text (uiout, "\n");
10056 result = PRINT_UNKNOWN;
9c06b0b4
TJB
10057 break;
10058 default:
348d480f 10059 result = PRINT_UNKNOWN;
9c06b0b4
TJB
10060 }
10061
348d480f
PA
10062 do_cleanups (old_chain);
10063 return result;
10064}
10065
10066/* Implement the "print_mention" breakpoint_ops method for hardware
10067 watchpoints. */
10068
10069static void
10070print_mention_watchpoint (struct breakpoint *b)
10071{
10072 struct cleanup *ui_out_chain;
3a5c3e22 10073 struct watchpoint *w = (struct watchpoint *) b;
79a45e25 10074 struct ui_out *uiout = current_uiout;
348d480f
PA
10075
10076 switch (b->type)
10077 {
10078 case bp_watchpoint:
10079 ui_out_text (uiout, "Watchpoint ");
10080 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10081 break;
10082 case bp_hardware_watchpoint:
10083 ui_out_text (uiout, "Hardware watchpoint ");
10084 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10085 break;
10086 case bp_read_watchpoint:
10087 ui_out_text (uiout, "Hardware read watchpoint ");
10088 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10089 break;
10090 case bp_access_watchpoint:
10091 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
10092 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10093 break;
10094 default:
10095 internal_error (__FILE__, __LINE__,
10096 _("Invalid hardware watchpoint type."));
10097 }
10098
10099 ui_out_field_int (uiout, "number", b->number);
10100 ui_out_text (uiout, ": ");
3a5c3e22 10101 ui_out_field_string (uiout, "exp", w->exp_string);
348d480f
PA
10102 do_cleanups (ui_out_chain);
10103}
10104
10105/* Implement the "print_recreate" breakpoint_ops method for
10106 watchpoints. */
10107
10108static void
10109print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp)
10110{
3a5c3e22
PA
10111 struct watchpoint *w = (struct watchpoint *) b;
10112
348d480f
PA
10113 switch (b->type)
10114 {
10115 case bp_watchpoint:
10116 case bp_hardware_watchpoint:
10117 fprintf_unfiltered (fp, "watch");
10118 break;
10119 case bp_read_watchpoint:
10120 fprintf_unfiltered (fp, "rwatch");
10121 break;
10122 case bp_access_watchpoint:
10123 fprintf_unfiltered (fp, "awatch");
10124 break;
10125 default:
10126 internal_error (__FILE__, __LINE__,
10127 _("Invalid watchpoint type."));
10128 }
10129
3a5c3e22 10130 fprintf_unfiltered (fp, " %s", w->exp_string);
d9b3f62e 10131 print_recreate_thread (b, fp);
348d480f
PA
10132}
10133
10134/* The breakpoint_ops structure to be used in hardware watchpoints. */
10135
2060206e 10136static struct breakpoint_ops watchpoint_breakpoint_ops;
348d480f
PA
10137
10138/* Implement the "insert" breakpoint_ops method for
10139 masked hardware watchpoints. */
10140
10141static int
10142insert_masked_watchpoint (struct bp_location *bl)
10143{
3a5c3e22
PA
10144 struct watchpoint *w = (struct watchpoint *) bl->owner;
10145
10146 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask,
348d480f
PA
10147 bl->watchpoint_type);
10148}
10149
10150/* Implement the "remove" breakpoint_ops method for
10151 masked hardware watchpoints. */
10152
10153static int
10154remove_masked_watchpoint (struct bp_location *bl)
10155{
3a5c3e22
PA
10156 struct watchpoint *w = (struct watchpoint *) bl->owner;
10157
10158 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask,
348d480f
PA
10159 bl->watchpoint_type);
10160}
10161
10162/* Implement the "resources_needed" breakpoint_ops method for
10163 masked hardware watchpoints. */
10164
10165static int
10166resources_needed_masked_watchpoint (const struct bp_location *bl)
10167{
3a5c3e22
PA
10168 struct watchpoint *w = (struct watchpoint *) bl->owner;
10169
10170 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask);
348d480f
PA
10171}
10172
10173/* Implement the "works_in_software_mode" breakpoint_ops method for
10174 masked hardware watchpoints. */
10175
10176static int
10177works_in_software_mode_masked_watchpoint (const struct breakpoint *b)
10178{
10179 return 0;
10180}
10181
10182/* Implement the "print_it" breakpoint_ops method for
10183 masked hardware watchpoints. */
10184
10185static enum print_stop_action
10186print_it_masked_watchpoint (bpstat bs)
10187{
10188 struct breakpoint *b = bs->breakpoint_at;
79a45e25 10189 struct ui_out *uiout = current_uiout;
348d480f
PA
10190
10191 /* Masked watchpoints have only one location. */
10192 gdb_assert (b->loc && b->loc->next == NULL);
10193
10194 switch (b->type)
10195 {
10196 case bp_hardware_watchpoint:
10197 annotate_watchpoint (b->number);
10198 if (ui_out_is_mi_like_p (uiout))
10199 ui_out_field_string
10200 (uiout, "reason",
10201 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
10202 break;
10203
10204 case bp_read_watchpoint:
10205 if (ui_out_is_mi_like_p (uiout))
10206 ui_out_field_string
10207 (uiout, "reason",
10208 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
10209 break;
10210
10211 case bp_access_watchpoint:
10212 if (ui_out_is_mi_like_p (uiout))
10213 ui_out_field_string
10214 (uiout, "reason",
10215 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
10216 break;
10217 default:
10218 internal_error (__FILE__, __LINE__,
10219 _("Invalid hardware watchpoint type."));
10220 }
10221
10222 mention (b);
9c06b0b4
TJB
10223 ui_out_text (uiout, _("\n\
10224Check the underlying instruction at PC for the memory\n\
10225address and value which triggered this watchpoint.\n"));
10226 ui_out_text (uiout, "\n");
10227
10228 /* More than one watchpoint may have been triggered. */
10229 return PRINT_UNKNOWN;
10230}
10231
10232/* Implement the "print_one_detail" breakpoint_ops method for
10233 masked hardware watchpoints. */
10234
10235static void
10236print_one_detail_masked_watchpoint (const struct breakpoint *b,
10237 struct ui_out *uiout)
10238{
3a5c3e22
PA
10239 struct watchpoint *w = (struct watchpoint *) b;
10240
9c06b0b4
TJB
10241 /* Masked watchpoints have only one location. */
10242 gdb_assert (b->loc && b->loc->next == NULL);
10243
10244 ui_out_text (uiout, "\tmask ");
3a5c3e22 10245 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask);
9c06b0b4
TJB
10246 ui_out_text (uiout, "\n");
10247}
10248
10249/* Implement the "print_mention" breakpoint_ops method for
10250 masked hardware watchpoints. */
10251
10252static void
10253print_mention_masked_watchpoint (struct breakpoint *b)
10254{
3a5c3e22 10255 struct watchpoint *w = (struct watchpoint *) b;
79a45e25 10256 struct ui_out *uiout = current_uiout;
9c06b0b4
TJB
10257 struct cleanup *ui_out_chain;
10258
10259 switch (b->type)
10260 {
10261 case bp_hardware_watchpoint:
10262 ui_out_text (uiout, "Masked hardware watchpoint ");
10263 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
10264 break;
10265 case bp_read_watchpoint:
10266 ui_out_text (uiout, "Masked hardware read watchpoint ");
10267 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
10268 break;
10269 case bp_access_watchpoint:
10270 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint ");
10271 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
10272 break;
10273 default:
10274 internal_error (__FILE__, __LINE__,
10275 _("Invalid hardware watchpoint type."));
10276 }
10277
10278 ui_out_field_int (uiout, "number", b->number);
10279 ui_out_text (uiout, ": ");
3a5c3e22 10280 ui_out_field_string (uiout, "exp", w->exp_string);
9c06b0b4
TJB
10281 do_cleanups (ui_out_chain);
10282}
10283
10284/* Implement the "print_recreate" breakpoint_ops method for
10285 masked hardware watchpoints. */
10286
10287static void
10288print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp)
10289{
3a5c3e22 10290 struct watchpoint *w = (struct watchpoint *) b;
9c06b0b4
TJB
10291 char tmp[40];
10292
10293 switch (b->type)
10294 {
10295 case bp_hardware_watchpoint:
10296 fprintf_unfiltered (fp, "watch");
10297 break;
10298 case bp_read_watchpoint:
10299 fprintf_unfiltered (fp, "rwatch");
10300 break;
10301 case bp_access_watchpoint:
10302 fprintf_unfiltered (fp, "awatch");
10303 break;
10304 default:
10305 internal_error (__FILE__, __LINE__,
10306 _("Invalid hardware watchpoint type."));
10307 }
10308
3a5c3e22
PA
10309 sprintf_vma (tmp, w->hw_wp_mask);
10310 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp);
d9b3f62e 10311 print_recreate_thread (b, fp);
9c06b0b4
TJB
10312}
10313
10314/* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10315
2060206e 10316static struct breakpoint_ops masked_watchpoint_breakpoint_ops;
9c06b0b4
TJB
10317
10318/* Tell whether the given watchpoint is a masked hardware watchpoint. */
10319
10320static int
10321is_masked_watchpoint (const struct breakpoint *b)
10322{
10323 return b->ops == &masked_watchpoint_breakpoint_ops;
10324}
10325
53a5351d
JM
10326/* accessflag: hw_write: watch write,
10327 hw_read: watch read,
10328 hw_access: watch access (read or write) */
c906108c 10329static void
84f4c1fe
PM
10330watch_command_1 (char *arg, int accessflag, int from_tty,
10331 int just_location, int internal)
c906108c 10332{
a9634178 10333 volatile struct gdb_exception e;
d983da9c 10334 struct breakpoint *b, *scope_breakpoint = NULL;
c906108c 10335 struct expression *exp;
60e1c644 10336 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
a1442452 10337 struct value *val, *mark, *result;
c906108c 10338 struct frame_info *frame;
c906108c
SS
10339 char *exp_start = NULL;
10340 char *exp_end = NULL;
9c06b0b4
TJB
10341 char *tok, *end_tok;
10342 int toklen = -1;
c906108c
SS
10343 char *cond_start = NULL;
10344 char *cond_end = NULL;
c906108c 10345 enum bptype bp_type;
37e4754d 10346 int thread = -1;
0cf6dd15 10347 int pc = 0;
9c06b0b4
TJB
10348 /* Flag to indicate whether we are going to use masks for
10349 the hardware watchpoint. */
10350 int use_mask = 0;
10351 CORE_ADDR mask = 0;
3a5c3e22 10352 struct watchpoint *w;
c906108c 10353
37e4754d
LM
10354 /* Make sure that we actually have parameters to parse. */
10355 if (arg != NULL && arg[0] != '\0')
10356 {
9c06b0b4 10357 char *value_start;
37e4754d 10358
9c06b0b4
TJB
10359 /* Look for "parameter value" pairs at the end
10360 of the arguments string. */
10361 for (tok = arg + strlen (arg) - 1; tok > arg; tok--)
10362 {
10363 /* Skip whitespace at the end of the argument list. */
10364 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10365 tok--;
10366
10367 /* Find the beginning of the last token.
10368 This is the value of the parameter. */
10369 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10370 tok--;
10371 value_start = tok + 1;
10372
10373 /* Skip whitespace. */
10374 while (tok > arg && (*tok == ' ' || *tok == '\t'))
10375 tok--;
10376
10377 end_tok = tok;
10378
10379 /* Find the beginning of the second to last token.
10380 This is the parameter itself. */
10381 while (tok > arg && (*tok != ' ' && *tok != '\t'))
10382 tok--;
10383 tok++;
10384 toklen = end_tok - tok + 1;
10385
10386 if (toklen == 6 && !strncmp (tok, "thread", 6))
10387 {
10388 /* At this point we've found a "thread" token, which means
10389 the user is trying to set a watchpoint that triggers
10390 only in a specific thread. */
10391 char *endp;
37e4754d 10392
9c06b0b4
TJB
10393 if (thread != -1)
10394 error(_("You can specify only one thread."));
37e4754d 10395
9c06b0b4
TJB
10396 /* Extract the thread ID from the next token. */
10397 thread = strtol (value_start, &endp, 0);
37e4754d 10398
9c06b0b4
TJB
10399 /* Check if the user provided a valid numeric value for the
10400 thread ID. */
10401 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
10402 error (_("Invalid thread ID specification %s."), value_start);
10403
10404 /* Check if the thread actually exists. */
10405 if (!valid_thread_id (thread))
10406 error (_("Unknown thread %d."), thread);
10407 }
10408 else if (toklen == 4 && !strncmp (tok, "mask", 4))
10409 {
10410 /* We've found a "mask" token, which means the user wants to
10411 create a hardware watchpoint that is going to have the mask
10412 facility. */
10413 struct value *mask_value, *mark;
37e4754d 10414
9c06b0b4
TJB
10415 if (use_mask)
10416 error(_("You can specify only one mask."));
37e4754d 10417
9c06b0b4 10418 use_mask = just_location = 1;
37e4754d 10419
9c06b0b4
TJB
10420 mark = value_mark ();
10421 mask_value = parse_to_comma_and_eval (&value_start);
10422 mask = value_as_address (mask_value);
10423 value_free_to_mark (mark);
10424 }
10425 else
10426 /* We didn't recognize what we found. We should stop here. */
10427 break;
37e4754d 10428
9c06b0b4
TJB
10429 /* Truncate the string and get rid of the "parameter value" pair before
10430 the arguments string is parsed by the parse_exp_1 function. */
10431 *tok = '\0';
10432 }
37e4754d
LM
10433 }
10434
10435 /* Parse the rest of the arguments. */
c906108c
SS
10436 innermost_block = NULL;
10437 exp_start = arg;
10438 exp = parse_exp_1 (&arg, 0, 0);
10439 exp_end = arg;
fa8a61dc
TT
10440 /* Remove trailing whitespace from the expression before saving it.
10441 This makes the eventual display of the expression string a bit
10442 prettier. */
10443 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
10444 --exp_end;
10445
65d79d4b
SDJ
10446 /* Checking if the expression is not constant. */
10447 if (watchpoint_exp_is_const (exp))
10448 {
10449 int len;
10450
10451 len = exp_end - exp_start;
10452 while (len > 0 && isspace (exp_start[len - 1]))
10453 len--;
10454 error (_("Cannot watch constant value `%.*s'."), len, exp_start);
10455 }
10456
c906108c
SS
10457 exp_valid_block = innermost_block;
10458 mark = value_mark ();
a1442452 10459 fetch_subexp_value (exp, &pc, &val, &result, NULL);
06a64a0b
TT
10460
10461 if (just_location)
10462 {
9c06b0b4
TJB
10463 int ret;
10464
06a64a0b 10465 exp_valid_block = NULL;
a1442452 10466 val = value_addr (result);
06a64a0b
TT
10467 release_value (val);
10468 value_free_to_mark (mark);
9c06b0b4
TJB
10469
10470 if (use_mask)
10471 {
10472 ret = target_masked_watch_num_registers (value_as_address (val),
10473 mask);
10474 if (ret == -1)
10475 error (_("This target does not support masked watchpoints."));
10476 else if (ret == -2)
10477 error (_("Invalid mask or memory region."));
10478 }
06a64a0b
TT
10479 }
10480 else if (val != NULL)
fa4727a6 10481 release_value (val);
c906108c 10482
e9cafbcc
TT
10483 tok = skip_spaces (arg);
10484 end_tok = skip_to_space (tok);
c906108c
SS
10485
10486 toklen = end_tok - tok;
10487 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
10488 {
2d134ed3
PA
10489 struct expression *cond;
10490
60e1c644 10491 innermost_block = NULL;
c906108c
SS
10492 tok = cond_start = end_tok + 1;
10493 cond = parse_exp_1 (&tok, 0, 0);
60e1c644
PA
10494
10495 /* The watchpoint expression may not be local, but the condition
10496 may still be. E.g.: `watch global if local > 0'. */
10497 cond_exp_valid_block = innermost_block;
10498
2d134ed3 10499 xfree (cond);
c906108c
SS
10500 cond_end = tok;
10501 }
10502 if (*tok)
8a3fe4f8 10503 error (_("Junk at end of command."));
c906108c 10504
53a5351d 10505 if (accessflag == hw_read)
c5aa993b 10506 bp_type = bp_read_watchpoint;
53a5351d 10507 else if (accessflag == hw_access)
c5aa993b
JM
10508 bp_type = bp_access_watchpoint;
10509 else
10510 bp_type = bp_hardware_watchpoint;
c906108c 10511
d983da9c 10512 frame = block_innermost_frame (exp_valid_block);
d983da9c
DJ
10513
10514 /* If the expression is "local", then set up a "watchpoint scope"
10515 breakpoint at the point where we've left the scope of the watchpoint
10516 expression. Create the scope breakpoint before the watchpoint, so
10517 that we will encounter it first in bpstat_stop_status. */
60e1c644 10518 if (exp_valid_block && frame)
d983da9c 10519 {
edb3359d
DJ
10520 if (frame_id_p (frame_unwind_caller_id (frame)))
10521 {
10522 scope_breakpoint
a6d9a66e
UW
10523 = create_internal_breakpoint (frame_unwind_caller_arch (frame),
10524 frame_unwind_caller_pc (frame),
06edf0c0
PA
10525 bp_watchpoint_scope,
10526 &momentary_breakpoint_ops);
d983da9c 10527
edb3359d 10528 scope_breakpoint->enable_state = bp_enabled;
d983da9c 10529
edb3359d
DJ
10530 /* Automatically delete the breakpoint when it hits. */
10531 scope_breakpoint->disposition = disp_del;
d983da9c 10532
edb3359d
DJ
10533 /* Only break in the proper frame (help with recursion). */
10534 scope_breakpoint->frame_id = frame_unwind_caller_id (frame);
d983da9c 10535
edb3359d 10536 /* Set the address at which we will stop. */
a6d9a66e
UW
10537 scope_breakpoint->loc->gdbarch
10538 = frame_unwind_caller_arch (frame);
edb3359d
DJ
10539 scope_breakpoint->loc->requested_address
10540 = frame_unwind_caller_pc (frame);
10541 scope_breakpoint->loc->address
a6d9a66e
UW
10542 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
10543 scope_breakpoint->loc->requested_address,
edb3359d
DJ
10544 scope_breakpoint->type);
10545 }
d983da9c
DJ
10546 }
10547
c906108c 10548 /* Now set up the breakpoint. */
3a5c3e22
PA
10549
10550 w = XCNEW (struct watchpoint);
10551 b = &w->base;
348d480f 10552 if (use_mask)
3a5c3e22
PA
10553 init_raw_breakpoint_without_location (b, NULL, bp_type,
10554 &masked_watchpoint_breakpoint_ops);
348d480f 10555 else
3a5c3e22
PA
10556 init_raw_breakpoint_without_location (b, NULL, bp_type,
10557 &watchpoint_breakpoint_ops);
37e4754d 10558 b->thread = thread;
b5de0fa7 10559 b->disposition = disp_donttouch;
348d480f 10560 b->pspace = current_program_space;
3a5c3e22
PA
10561 w->exp = exp;
10562 w->exp_valid_block = exp_valid_block;
10563 w->cond_exp_valid_block = cond_exp_valid_block;
06a64a0b
TT
10564 if (just_location)
10565 {
10566 struct type *t = value_type (val);
10567 CORE_ADDR addr = value_as_address (val);
10568 char *name;
10569
10570 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t)));
10571 name = type_to_string (t);
10572
3a5c3e22 10573 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name,
d63d0675 10574 core_addr_to_string (addr));
06a64a0b
TT
10575 xfree (name);
10576
3a5c3e22 10577 w->exp_string = xstrprintf ("-location %.*s",
d63d0675
JK
10578 (int) (exp_end - exp_start), exp_start);
10579
06a64a0b
TT
10580 /* The above expression is in C. */
10581 b->language = language_c;
10582 }
10583 else
3a5c3e22 10584 w->exp_string = savestring (exp_start, exp_end - exp_start);
9c06b0b4
TJB
10585
10586 if (use_mask)
10587 {
3a5c3e22 10588 w->hw_wp_mask = mask;
9c06b0b4
TJB
10589 }
10590 else
10591 {
3a5c3e22
PA
10592 w->val = val;
10593 w->val_valid = 1;
9c06b0b4 10594 }
77b06cd7 10595
c906108c
SS
10596 if (cond_start)
10597 b->cond_string = savestring (cond_start, cond_end - cond_start);
10598 else
10599 b->cond_string = 0;
c5aa993b 10600
c906108c 10601 if (frame)
f6bc2008 10602 {
3a5c3e22
PA
10603 w->watchpoint_frame = get_frame_id (frame);
10604 w->watchpoint_thread = inferior_ptid;
f6bc2008 10605 }
c906108c 10606 else
f6bc2008 10607 {
3a5c3e22
PA
10608 w->watchpoint_frame = null_frame_id;
10609 w->watchpoint_thread = null_ptid;
f6bc2008 10610 }
c906108c 10611
d983da9c 10612 if (scope_breakpoint != NULL)
c906108c 10613 {
d983da9c
DJ
10614 /* The scope breakpoint is related to the watchpoint. We will
10615 need to act on them together. */
10616 b->related_breakpoint = scope_breakpoint;
10617 scope_breakpoint->related_breakpoint = b;
c906108c 10618 }
d983da9c 10619
06a64a0b
TT
10620 if (!just_location)
10621 value_free_to_mark (mark);
2d134ed3 10622
a9634178
TJB
10623 TRY_CATCH (e, RETURN_MASK_ALL)
10624 {
10625 /* Finally update the new watchpoint. This creates the locations
10626 that should be inserted. */
3a5c3e22 10627 update_watchpoint (w, 1);
a9634178
TJB
10628 }
10629 if (e.reason < 0)
10630 {
10631 delete_breakpoint (b);
10632 throw_exception (e);
10633 }
10634
3ea46bff 10635 install_breakpoint (internal, b, 1);
c906108c
SS
10636}
10637
e09342b5 10638/* Return count of debug registers needed to watch the given expression.
e09342b5 10639 If the watchpoint cannot be handled in hardware return zero. */
c906108c 10640
c906108c 10641static int
a9634178 10642can_use_hardware_watchpoint (struct value *v)
c906108c
SS
10643{
10644 int found_memory_cnt = 0;
2e70b7b9 10645 struct value *head = v;
c906108c
SS
10646
10647 /* Did the user specifically forbid us to use hardware watchpoints? */
c5aa993b 10648 if (!can_use_hw_watchpoints)
c906108c 10649 return 0;
c5aa993b 10650
5c44784c
JM
10651 /* Make sure that the value of the expression depends only upon
10652 memory contents, and values computed from them within GDB. If we
10653 find any register references or function calls, we can't use a
10654 hardware watchpoint.
10655
10656 The idea here is that evaluating an expression generates a series
10657 of values, one holding the value of every subexpression. (The
10658 expression a*b+c has five subexpressions: a, b, a*b, c, and
10659 a*b+c.) GDB's values hold almost enough information to establish
10660 the criteria given above --- they identify memory lvalues,
10661 register lvalues, computed values, etcetera. So we can evaluate
10662 the expression, and then scan the chain of values that leaves
10663 behind to decide whether we can detect any possible change to the
10664 expression's final value using only hardware watchpoints.
10665
10666 However, I don't think that the values returned by inferior
10667 function calls are special in any way. So this function may not
10668 notice that an expression involving an inferior function call
10669 can't be watched with hardware watchpoints. FIXME. */
17cf0ecd 10670 for (; v; v = value_next (v))
c906108c 10671 {
5c44784c 10672 if (VALUE_LVAL (v) == lval_memory)
c906108c 10673 {
8464be76
DJ
10674 if (v != head && value_lazy (v))
10675 /* A lazy memory lvalue in the chain is one that GDB never
10676 needed to fetch; we either just used its address (e.g.,
10677 `a' in `a.b') or we never needed it at all (e.g., `a'
10678 in `a,b'). This doesn't apply to HEAD; if that is
10679 lazy then it was not readable, but watch it anyway. */
5c44784c 10680 ;
53a5351d 10681 else
5c44784c
JM
10682 {
10683 /* Ahh, memory we actually used! Check if we can cover
10684 it with hardware watchpoints. */
df407dfe 10685 struct type *vtype = check_typedef (value_type (v));
2e70b7b9
MS
10686
10687 /* We only watch structs and arrays if user asked for it
10688 explicitly, never if they just happen to appear in a
10689 middle of some value chain. */
10690 if (v == head
10691 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
10692 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
10693 {
42ae5230 10694 CORE_ADDR vaddr = value_address (v);
e09342b5
TJB
10695 int len;
10696 int num_regs;
10697
a9634178 10698 len = (target_exact_watchpoints
e09342b5
TJB
10699 && is_scalar_type_recursive (vtype))?
10700 1 : TYPE_LENGTH (value_type (v));
2e70b7b9 10701
e09342b5
TJB
10702 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len);
10703 if (!num_regs)
2e70b7b9
MS
10704 return 0;
10705 else
e09342b5 10706 found_memory_cnt += num_regs;
2e70b7b9 10707 }
5c44784c 10708 }
c5aa993b 10709 }
5086187c
AC
10710 else if (VALUE_LVAL (v) != not_lval
10711 && deprecated_value_modifiable (v) == 0)
38b6c3b3 10712 return 0; /* These are values from the history (e.g., $1). */
5086187c 10713 else if (VALUE_LVAL (v) == lval_register)
38b6c3b3 10714 return 0; /* Cannot watch a register with a HW watchpoint. */
c906108c
SS
10715 }
10716
10717 /* The expression itself looks suitable for using a hardware
10718 watchpoint, but give the target machine a chance to reject it. */
10719 return found_memory_cnt;
10720}
10721
8b93c638 10722void
84f4c1fe 10723watch_command_wrapper (char *arg, int from_tty, int internal)
8b93c638 10724{
84f4c1fe 10725 watch_command_1 (arg, hw_write, from_tty, 0, internal);
06a64a0b
TT
10726}
10727
10728/* A helper function that looks for an argument at the start of a
10729 string. The argument must also either be at the end of the string,
10730 or be followed by whitespace. Returns 1 if it finds the argument,
10731 0 otherwise. If the argument is found, it updates *STR. */
10732
10733static int
10734check_for_argument (char **str, char *arg, int arg_len)
10735{
10736 if (strncmp (*str, arg, arg_len) == 0
10737 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
10738 {
10739 *str += arg_len;
10740 return 1;
10741 }
10742 return 0;
10743}
10744
10745/* A helper function that looks for the "-location" argument and then
10746 calls watch_command_1. */
10747
10748static void
10749watch_maybe_just_location (char *arg, int accessflag, int from_tty)
10750{
10751 int just_location = 0;
10752
10753 if (arg
10754 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1)
10755 || check_for_argument (&arg, "-l", sizeof ("-l") - 1)))
10756 {
e9cafbcc 10757 arg = skip_spaces (arg);
06a64a0b
TT
10758 just_location = 1;
10759 }
10760
84f4c1fe 10761 watch_command_1 (arg, accessflag, from_tty, just_location, 0);
8b93c638 10762}
8926118c 10763
c5aa993b 10764static void
fba45db2 10765watch_command (char *arg, int from_tty)
c906108c 10766{
06a64a0b 10767 watch_maybe_just_location (arg, hw_write, from_tty);
c906108c
SS
10768}
10769
8b93c638 10770void
84f4c1fe 10771rwatch_command_wrapper (char *arg, int from_tty, int internal)
8b93c638 10772{
84f4c1fe 10773 watch_command_1 (arg, hw_read, from_tty, 0, internal);
8b93c638 10774}
8926118c 10775
c5aa993b 10776static void
fba45db2 10777rwatch_command (char *arg, int from_tty)
c906108c 10778{
06a64a0b 10779 watch_maybe_just_location (arg, hw_read, from_tty);
c906108c
SS
10780}
10781
8b93c638 10782void
84f4c1fe 10783awatch_command_wrapper (char *arg, int from_tty, int internal)
8b93c638 10784{
84f4c1fe 10785 watch_command_1 (arg, hw_access, from_tty, 0, internal);
8b93c638 10786}
8926118c 10787
c5aa993b 10788static void
fba45db2 10789awatch_command (char *arg, int from_tty)
c906108c 10790{
06a64a0b 10791 watch_maybe_just_location (arg, hw_access, from_tty);
c906108c 10792}
c906108c 10793\f
c5aa993b 10794
43ff13b4 10795/* Helper routines for the until_command routine in infcmd.c. Here
c906108c
SS
10796 because it uses the mechanisms of breakpoints. */
10797
bfec99b2
PA
10798struct until_break_command_continuation_args
10799{
10800 struct breakpoint *breakpoint;
10801 struct breakpoint *breakpoint2;
186c406b 10802 int thread_num;
bfec99b2
PA
10803};
10804
43ff13b4 10805/* This function is called by fetch_inferior_event via the
4a64f543 10806 cmd_continuation pointer, to complete the until command. It takes
43ff13b4 10807 care of cleaning up the temporary breakpoints set up by the until
4a64f543 10808 command. */
c2c6d25f 10809static void
fa4cd53f 10810until_break_command_continuation (void *arg, int err)
43ff13b4 10811{
bfec99b2
PA
10812 struct until_break_command_continuation_args *a = arg;
10813
10814 delete_breakpoint (a->breakpoint);
10815 if (a->breakpoint2)
10816 delete_breakpoint (a->breakpoint2);
186c406b 10817 delete_longjmp_breakpoint (a->thread_num);
43ff13b4
JM
10818}
10819
c906108c 10820void
ae66c1fc 10821until_break_command (char *arg, int from_tty, int anywhere)
c906108c
SS
10822{
10823 struct symtabs_and_lines sals;
10824 struct symtab_and_line sal;
8556afb4
PA
10825 struct frame_info *frame;
10826 struct gdbarch *frame_gdbarch;
10827 struct frame_id stack_frame_id;
10828 struct frame_id caller_frame_id;
c906108c 10829 struct breakpoint *breakpoint;
f107f563 10830 struct breakpoint *breakpoint2 = NULL;
c906108c 10831 struct cleanup *old_chain;
186c406b
TT
10832 int thread;
10833 struct thread_info *tp;
c906108c
SS
10834
10835 clear_proceed_status ();
10836
10837 /* Set a breakpoint where the user wants it and at return from
4a64f543 10838 this function. */
c5aa993b 10839
1bfeeb0f 10840 if (last_displayed_sal_is_valid ())
f8eba3c6 10841 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
1bfeeb0f 10842 get_last_displayed_symtab (),
f8eba3c6 10843 get_last_displayed_line ());
c906108c 10844 else
f8eba3c6
TT
10845 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
10846 (struct symtab *) NULL, 0);
c5aa993b 10847
c906108c 10848 if (sals.nelts != 1)
8a3fe4f8 10849 error (_("Couldn't get information on specified line."));
c5aa993b 10850
c906108c 10851 sal = sals.sals[0];
4a64f543 10852 xfree (sals.sals); /* malloc'd, so freed. */
c5aa993b 10853
c906108c 10854 if (*arg)
8a3fe4f8 10855 error (_("Junk at end of arguments."));
c5aa993b 10856
c906108c 10857 resolve_sal_pc (&sal);
c5aa993b 10858
186c406b
TT
10859 tp = inferior_thread ();
10860 thread = tp->num;
10861
883bc8d1
PA
10862 old_chain = make_cleanup (null_cleanup, NULL);
10863
8556afb4
PA
10864 /* Note linespec handling above invalidates the frame chain.
10865 Installing a breakpoint also invalidates the frame chain (as it
10866 may need to switch threads), so do any frame handling before
10867 that. */
10868
10869 frame = get_selected_frame (NULL);
10870 frame_gdbarch = get_frame_arch (frame);
10871 stack_frame_id = get_stack_frame_id (frame);
10872 caller_frame_id = frame_unwind_caller_id (frame);
883bc8d1 10873
ae66c1fc
EZ
10874 /* Keep within the current frame, or in frames called by the current
10875 one. */
edb3359d 10876
883bc8d1 10877 if (frame_id_p (caller_frame_id))
c906108c 10878 {
883bc8d1
PA
10879 struct symtab_and_line sal2;
10880
10881 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0);
10882 sal2.pc = frame_unwind_caller_pc (frame);
a6d9a66e 10883 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame),
883bc8d1
PA
10884 sal2,
10885 caller_frame_id,
f107f563
VP
10886 bp_until);
10887 make_cleanup_delete_breakpoint (breakpoint2);
186c406b 10888
883bc8d1 10889 set_longjmp_breakpoint (tp, caller_frame_id);
186c406b 10890 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
c906108c 10891 }
c5aa993b 10892
c70a6932
JK
10893 /* set_momentary_breakpoint could invalidate FRAME. */
10894 frame = NULL;
10895
883bc8d1
PA
10896 if (anywhere)
10897 /* If the user told us to continue until a specified location,
10898 we don't specify a frame at which we need to stop. */
10899 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10900 null_frame_id, bp_until);
10901 else
10902 /* Otherwise, specify the selected frame, because we want to stop
10903 only at the very same frame. */
10904 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
10905 stack_frame_id, bp_until);
10906 make_cleanup_delete_breakpoint (breakpoint);
10907
a493e3e2 10908 proceed (-1, GDB_SIGNAL_DEFAULT, 0);
f107f563 10909
4a64f543
MS
10910 /* If we are running asynchronously, and proceed call above has
10911 actually managed to start the target, arrange for breakpoints to
10912 be deleted when the target stops. Otherwise, we're already
10913 stopped and delete breakpoints via cleanup chain. */
f107f563 10914
8ea051c5 10915 if (target_can_async_p () && is_running (inferior_ptid))
f107f563 10916 {
bfec99b2
PA
10917 struct until_break_command_continuation_args *args;
10918 args = xmalloc (sizeof (*args));
f107f563 10919
bfec99b2
PA
10920 args->breakpoint = breakpoint;
10921 args->breakpoint2 = breakpoint2;
186c406b 10922 args->thread_num = thread;
f107f563
VP
10923
10924 discard_cleanups (old_chain);
95e54da7
PA
10925 add_continuation (inferior_thread (),
10926 until_break_command_continuation, args,
604ead4a 10927 xfree);
f107f563
VP
10928 }
10929 else
c5aa993b 10930 do_cleanups (old_chain);
c906108c 10931}
ae66c1fc 10932
c906108c
SS
10933/* This function attempts to parse an optional "if <cond>" clause
10934 from the arg string. If one is not found, it returns NULL.
c5aa993b 10935
c906108c
SS
10936 Else, it returns a pointer to the condition string. (It does not
10937 attempt to evaluate the string against a particular block.) And,
10938 it updates arg to point to the first character following the parsed
4a64f543 10939 if clause in the arg string. */
53a5351d 10940
c906108c 10941static char *
fba45db2 10942ep_parse_optional_if_clause (char **arg)
c906108c 10943{
c5aa993b
JM
10944 char *cond_string;
10945
10946 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
c906108c 10947 return NULL;
c5aa993b 10948
4a64f543 10949 /* Skip the "if" keyword. */
c906108c 10950 (*arg) += 2;
c5aa993b 10951
c906108c 10952 /* Skip any extra leading whitespace, and record the start of the
4a64f543 10953 condition string. */
e9cafbcc 10954 *arg = skip_spaces (*arg);
c906108c 10955 cond_string = *arg;
c5aa993b 10956
4a64f543
MS
10957 /* Assume that the condition occupies the remainder of the arg
10958 string. */
c906108c 10959 (*arg) += strlen (cond_string);
c5aa993b 10960
c906108c
SS
10961 return cond_string;
10962}
c5aa993b 10963
c906108c
SS
10964/* Commands to deal with catching events, such as signals, exceptions,
10965 process start/exit, etc. */
c5aa993b
JM
10966
10967typedef enum
10968{
44feb3ce
TT
10969 catch_fork_temporary, catch_vfork_temporary,
10970 catch_fork_permanent, catch_vfork_permanent
c5aa993b
JM
10971}
10972catch_fork_kind;
10973
c906108c 10974static void
cc59ec59
MS
10975catch_fork_command_1 (char *arg, int from_tty,
10976 struct cmd_list_element *command)
c906108c 10977{
a6d9a66e 10978 struct gdbarch *gdbarch = get_current_arch ();
c5aa993b 10979 char *cond_string = NULL;
44feb3ce
TT
10980 catch_fork_kind fork_kind;
10981 int tempflag;
10982
10983 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
10984 tempflag = (fork_kind == catch_fork_temporary
10985 || fork_kind == catch_vfork_temporary);
c5aa993b 10986
44feb3ce
TT
10987 if (!arg)
10988 arg = "";
e9cafbcc 10989 arg = skip_spaces (arg);
c5aa993b 10990
c906108c 10991 /* The allowed syntax is:
c5aa993b
JM
10992 catch [v]fork
10993 catch [v]fork if <cond>
10994
4a64f543 10995 First, check if there's an if clause. */
c906108c 10996 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 10997
c906108c 10998 if ((*arg != '\0') && !isspace (*arg))
8a3fe4f8 10999 error (_("Junk at end of arguments."));
c5aa993b 11000
c906108c 11001 /* If this target supports it, create a fork or vfork catchpoint
4a64f543 11002 and enable reporting of such events. */
c5aa993b
JM
11003 switch (fork_kind)
11004 {
44feb3ce
TT
11005 case catch_fork_temporary:
11006 case catch_fork_permanent:
a6d9a66e 11007 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
ce78b96d 11008 &catch_fork_breakpoint_ops);
c906108c 11009 break;
44feb3ce
TT
11010 case catch_vfork_temporary:
11011 case catch_vfork_permanent:
a6d9a66e 11012 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string,
ce78b96d 11013 &catch_vfork_breakpoint_ops);
c906108c 11014 break;
c5aa993b 11015 default:
8a3fe4f8 11016 error (_("unsupported or unknown fork kind; cannot catch it"));
c906108c 11017 break;
c5aa993b 11018 }
c906108c
SS
11019}
11020
11021static void
cc59ec59
MS
11022catch_exec_command_1 (char *arg, int from_tty,
11023 struct cmd_list_element *command)
c906108c 11024{
b4d90040 11025 struct exec_catchpoint *c;
a6d9a66e 11026 struct gdbarch *gdbarch = get_current_arch ();
44feb3ce 11027 int tempflag;
c5aa993b 11028 char *cond_string = NULL;
c906108c 11029
44feb3ce
TT
11030 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11031
11032 if (!arg)
11033 arg = "";
e9cafbcc 11034 arg = skip_spaces (arg);
c906108c
SS
11035
11036 /* The allowed syntax is:
c5aa993b
JM
11037 catch exec
11038 catch exec if <cond>
c906108c 11039
4a64f543 11040 First, check if there's an if clause. */
c906108c
SS
11041 cond_string = ep_parse_optional_if_clause (&arg);
11042
11043 if ((*arg != '\0') && !isspace (*arg))
8a3fe4f8 11044 error (_("Junk at end of arguments."));
c906108c 11045
b4d90040
PA
11046 c = XNEW (struct exec_catchpoint);
11047 init_catchpoint (&c->base, gdbarch, tempflag, cond_string,
11048 &catch_exec_breakpoint_ops);
11049 c->exec_pathname = NULL;
11050
3ea46bff 11051 install_breakpoint (0, &c->base, 1);
c906108c 11052}
c5aa993b 11053
3086aeae 11054static enum print_stop_action
348d480f 11055print_it_exception_catchpoint (bpstat bs)
3086aeae 11056{
79a45e25 11057 struct ui_out *uiout = current_uiout;
348d480f 11058 struct breakpoint *b = bs->breakpoint_at;
ade92717 11059 int bp_temp, bp_throw;
3086aeae 11060
ade92717 11061 annotate_catchpoint (b->number);
3086aeae 11062
ade92717
AR
11063 bp_throw = strstr (b->addr_string, "throw") != NULL;
11064 if (b->loc->address != b->loc->requested_address)
11065 breakpoint_adjustment_warning (b->loc->requested_address,
11066 b->loc->address,
11067 b->number, 1);
df2b6d2d 11068 bp_temp = b->disposition == disp_del;
ade92717
AR
11069 ui_out_text (uiout,
11070 bp_temp ? "Temporary catchpoint "
11071 : "Catchpoint ");
11072 if (!ui_out_is_mi_like_p (uiout))
11073 ui_out_field_int (uiout, "bkptno", b->number);
11074 ui_out_text (uiout,
c0b37c48
AR
11075 bp_throw ? " (exception thrown), "
11076 : " (exception caught), ");
ade92717
AR
11077 if (ui_out_is_mi_like_p (uiout))
11078 {
11079 ui_out_field_string (uiout, "reason",
11080 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11081 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11082 ui_out_field_int (uiout, "bkptno", b->number);
11083 }
3086aeae
DJ
11084 return PRINT_SRC_AND_LOC;
11085}
11086
11087static void
cc59ec59
MS
11088print_one_exception_catchpoint (struct breakpoint *b,
11089 struct bp_location **last_loc)
3086aeae 11090{
79a45b7d 11091 struct value_print_options opts;
79a45e25 11092 struct ui_out *uiout = current_uiout;
cc59ec59 11093
79a45b7d
TT
11094 get_user_print_options (&opts);
11095 if (opts.addressprint)
3086aeae
DJ
11096 {
11097 annotate_field (4);
604133b5
AR
11098 if (b->loc == NULL || b->loc->shlib_disabled)
11099 ui_out_field_string (uiout, "addr", "<PENDING>");
11100 else
5af949e3
UW
11101 ui_out_field_core_addr (uiout, "addr",
11102 b->loc->gdbarch, b->loc->address);
3086aeae
DJ
11103 }
11104 annotate_field (5);
604133b5 11105 if (b->loc)
a6d9a66e 11106 *last_loc = b->loc;
3086aeae
DJ
11107 if (strstr (b->addr_string, "throw") != NULL)
11108 ui_out_field_string (uiout, "what", "exception throw");
11109 else
11110 ui_out_field_string (uiout, "what", "exception catch");
11111}
11112
11113static void
11114print_mention_exception_catchpoint (struct breakpoint *b)
11115{
79a45e25 11116 struct ui_out *uiout = current_uiout;
ade92717
AR
11117 int bp_temp;
11118 int bp_throw;
11119
df2b6d2d 11120 bp_temp = b->disposition == disp_del;
ade92717
AR
11121 bp_throw = strstr (b->addr_string, "throw") != NULL;
11122 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
11123 : _("Catchpoint "));
11124 ui_out_field_int (uiout, "bkptno", b->number);
11125 ui_out_text (uiout, bp_throw ? _(" (throw)")
11126 : _(" (catch)"));
3086aeae
DJ
11127}
11128
6149aea9
PA
11129/* Implement the "print_recreate" breakpoint_ops method for throw and
11130 catch catchpoints. */
11131
11132static void
4a64f543
MS
11133print_recreate_exception_catchpoint (struct breakpoint *b,
11134 struct ui_file *fp)
6149aea9
PA
11135{
11136 int bp_temp;
11137 int bp_throw;
11138
11139 bp_temp = b->disposition == disp_del;
11140 bp_throw = strstr (b->addr_string, "throw") != NULL;
11141 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch ");
11142 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch");
d9b3f62e 11143 print_recreate_thread (b, fp);
6149aea9
PA
11144}
11145
2060206e 11146static struct breakpoint_ops gnu_v3_exception_catchpoint_ops;
3086aeae
DJ
11147
11148static int
11149handle_gnu_v3_exceptions (int tempflag, char *cond_string,
11150 enum exception_event_kind ex_event, int from_tty)
11151{
604133b5
AR
11152 char *trigger_func_name;
11153
3086aeae 11154 if (ex_event == EX_EVENT_CATCH)
604133b5 11155 trigger_func_name = "__cxa_begin_catch";
3086aeae 11156 else
604133b5 11157 trigger_func_name = "__cxa_throw";
3086aeae 11158
8cdf0e15 11159 create_breakpoint (get_current_arch (),
e7e0cddf 11160 trigger_func_name, cond_string, -1, NULL,
8cdf0e15 11161 0 /* condition and thread are valid. */,
0fb4aa4b 11162 tempflag, bp_breakpoint,
8cdf0e15
VP
11163 0,
11164 AUTO_BOOLEAN_TRUE /* pending */,
11165 &gnu_v3_exception_catchpoint_ops, from_tty,
84f4c1fe 11166 1 /* enabled */,
44f238bb
PA
11167 0 /* internal */,
11168 0);
3086aeae 11169
3086aeae
DJ
11170 return 1;
11171}
11172
4a64f543 11173/* Deal with "catch catch" and "catch throw" commands. */
c906108c
SS
11174
11175static void
fba45db2
KB
11176catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
11177 int tempflag, int from_tty)
c906108c 11178{
c5aa993b 11179 char *cond_string = NULL;
c5aa993b 11180
44feb3ce
TT
11181 if (!arg)
11182 arg = "";
e9cafbcc 11183 arg = skip_spaces (arg);
c5aa993b 11184
c906108c
SS
11185 cond_string = ep_parse_optional_if_clause (&arg);
11186
11187 if ((*arg != '\0') && !isspace (*arg))
8a3fe4f8 11188 error (_("Junk at end of arguments."));
c906108c 11189
059fb39f
PM
11190 if (ex_event != EX_EVENT_THROW
11191 && ex_event != EX_EVENT_CATCH)
8a3fe4f8 11192 error (_("Unsupported or unknown exception event; cannot catch it"));
c906108c 11193
3086aeae
DJ
11194 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
11195 return;
11196
8a3fe4f8 11197 warning (_("Unsupported with this platform/compiler combination."));
c906108c
SS
11198}
11199
44feb3ce
TT
11200/* Implementation of "catch catch" command. */
11201
11202static void
11203catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
11204{
11205 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
cc59ec59 11206
44feb3ce
TT
11207 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
11208}
11209
11210/* Implementation of "catch throw" command. */
11211
11212static void
11213catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
11214{
11215 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
cc59ec59 11216
44feb3ce
TT
11217 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
11218}
11219
9ac4176b 11220void
28010a5d
PA
11221init_ada_exception_breakpoint (struct breakpoint *b,
11222 struct gdbarch *gdbarch,
11223 struct symtab_and_line sal,
11224 char *addr_string,
c0a91b2b 11225 const struct breakpoint_ops *ops,
28010a5d
PA
11226 int tempflag,
11227 int from_tty)
f7f9143b 11228{
f7f9143b
JB
11229 if (from_tty)
11230 {
5af949e3
UW
11231 struct gdbarch *loc_gdbarch = get_sal_arch (sal);
11232 if (!loc_gdbarch)
11233 loc_gdbarch = gdbarch;
11234
6c95b8df
PA
11235 describe_other_breakpoints (loc_gdbarch,
11236 sal.pspace, sal.pc, sal.section, -1);
f7f9143b
JB
11237 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11238 version for exception catchpoints, because two catchpoints
11239 used for different exception names will use the same address.
11240 In this case, a "breakpoint ... also set at..." warning is
4a64f543 11241 unproductive. Besides, the warning phrasing is also a bit
e5dd4106 11242 inappropriate, we should use the word catchpoint, and tell
f7f9143b
JB
11243 the user what type of catchpoint it is. The above is good
11244 enough for now, though. */
11245 }
11246
28010a5d 11247 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops);
f7f9143b
JB
11248
11249 b->enable_state = bp_enabled;
11250 b->disposition = tempflag ? disp_del : disp_donttouch;
f7f9143b
JB
11251 b->addr_string = addr_string;
11252 b->language = language_ada;
f7f9143b
JB
11253}
11254
a96d9b2e
SDJ
11255/* Splits the argument using space as delimiter. Returns an xmalloc'd
11256 filter list, or NULL if no filtering is required. */
11257static VEC(int) *
11258catch_syscall_split_args (char *arg)
11259{
11260 VEC(int) *result = NULL;
29d0bb3d 11261 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
a96d9b2e
SDJ
11262
11263 while (*arg != '\0')
11264 {
11265 int i, syscall_number;
11266 char *endptr;
11267 char cur_name[128];
11268 struct syscall s;
11269
11270 /* Skip whitespace. */
11271 while (isspace (*arg))
11272 arg++;
11273
11274 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i)
11275 cur_name[i] = arg[i];
11276 cur_name[i] = '\0';
11277 arg += i;
11278
11279 /* Check if the user provided a syscall name or a number. */
11280 syscall_number = (int) strtol (cur_name, &endptr, 0);
11281 if (*endptr == '\0')
bccd0dd2 11282 get_syscall_by_number (syscall_number, &s);
a96d9b2e
SDJ
11283 else
11284 {
11285 /* We have a name. Let's check if it's valid and convert it
11286 to a number. */
11287 get_syscall_by_name (cur_name, &s);
11288
11289 if (s.number == UNKNOWN_SYSCALL)
4a64f543
MS
11290 /* Here we have to issue an error instead of a warning,
11291 because GDB cannot do anything useful if there's no
11292 syscall number to be caught. */
a96d9b2e
SDJ
11293 error (_("Unknown syscall name '%s'."), cur_name);
11294 }
11295
11296 /* Ok, it's valid. */
11297 VEC_safe_push (int, result, s.number);
11298 }
11299
11300 discard_cleanups (cleanup);
11301 return result;
11302}
11303
11304/* Implement the "catch syscall" command. */
11305
11306static void
cc59ec59
MS
11307catch_syscall_command_1 (char *arg, int from_tty,
11308 struct cmd_list_element *command)
a96d9b2e
SDJ
11309{
11310 int tempflag;
11311 VEC(int) *filter;
11312 struct syscall s;
11313 struct gdbarch *gdbarch = get_current_arch ();
11314
11315 /* Checking if the feature if supported. */
11316 if (gdbarch_get_syscall_number_p (gdbarch) == 0)
11317 error (_("The feature 'catch syscall' is not supported on \
ea666128 11318this architecture yet."));
a96d9b2e
SDJ
11319
11320 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
11321
e9cafbcc 11322 arg = skip_spaces (arg);
a96d9b2e
SDJ
11323
11324 /* We need to do this first "dummy" translation in order
11325 to get the syscall XML file loaded or, most important,
11326 to display a warning to the user if there's no XML file
11327 for his/her architecture. */
11328 get_syscall_by_number (0, &s);
11329
11330 /* The allowed syntax is:
11331 catch syscall
11332 catch syscall <name | number> [<name | number> ... <name | number>]
11333
11334 Let's check if there's a syscall name. */
11335
11336 if (arg != NULL)
11337 filter = catch_syscall_split_args (arg);
11338 else
11339 filter = NULL;
11340
11341 create_syscall_event_catchpoint (tempflag, filter,
11342 &catch_syscall_breakpoint_ops);
11343}
11344
c906108c 11345static void
fba45db2 11346catch_command (char *arg, int from_tty)
c906108c 11347{
44feb3ce 11348 error (_("Catch requires an event name."));
c906108c
SS
11349}
11350\f
11351
11352static void
fba45db2 11353tcatch_command (char *arg, int from_tty)
c906108c 11354{
44feb3ce 11355 error (_("Catch requires an event name."));
c906108c
SS
11356}
11357
8a2c437b
TT
11358/* A qsort comparison function that sorts breakpoints in order. */
11359
11360static int
11361compare_breakpoints (const void *a, const void *b)
11362{
11363 const breakpoint_p *ba = a;
11364 uintptr_t ua = (uintptr_t) *ba;
11365 const breakpoint_p *bb = b;
11366 uintptr_t ub = (uintptr_t) *bb;
11367
11368 if ((*ba)->number < (*bb)->number)
11369 return -1;
11370 else if ((*ba)->number > (*bb)->number)
11371 return 1;
11372
11373 /* Now sort by address, in case we see, e..g, two breakpoints with
11374 the number 0. */
11375 if (ua < ub)
11376 return -1;
11377 return ub > ub ? 1 : 0;
11378}
11379
80f8a6eb 11380/* Delete breakpoints by address or line. */
c906108c
SS
11381
11382static void
fba45db2 11383clear_command (char *arg, int from_tty)
c906108c 11384{
8a2c437b 11385 struct breakpoint *b, *prev;
d6e956e5
VP
11386 VEC(breakpoint_p) *found = 0;
11387 int ix;
c906108c
SS
11388 int default_match;
11389 struct symtabs_and_lines sals;
11390 struct symtab_and_line sal;
c906108c 11391 int i;
8a2c437b 11392 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
c906108c
SS
11393
11394 if (arg)
11395 {
f8eba3c6
TT
11396 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE
11397 | DECODE_LINE_LIST_MODE));
c906108c
SS
11398 default_match = 0;
11399 }
11400 else
11401 {
c5aa993b 11402 sals.sals = (struct symtab_and_line *)
c906108c 11403 xmalloc (sizeof (struct symtab_and_line));
80f8a6eb 11404 make_cleanup (xfree, sals.sals);
4a64f543 11405 init_sal (&sal); /* Initialize to zeroes. */
1bfeeb0f
JL
11406
11407 /* Set sal's line, symtab, pc, and pspace to the values
11408 corresponding to the last call to print_frame_info. If the
11409 codepoint is not valid, this will set all the fields to 0. */
11410 get_last_displayed_sal (&sal);
c906108c 11411 if (sal.symtab == 0)
8a3fe4f8 11412 error (_("No source file specified."));
c906108c
SS
11413
11414 sals.sals[0] = sal;
11415 sals.nelts = 1;
11416
11417 default_match = 1;
11418 }
11419
4a64f543
MS
11420 /* We don't call resolve_sal_pc here. That's not as bad as it
11421 seems, because all existing breakpoints typically have both
11422 file/line and pc set. So, if clear is given file/line, we can
11423 match this to existing breakpoint without obtaining pc at all.
ed0616c6
VP
11424
11425 We only support clearing given the address explicitly
11426 present in breakpoint table. Say, we've set breakpoint
4a64f543 11427 at file:line. There were several PC values for that file:line,
ed0616c6 11428 due to optimization, all in one block.
4a64f543
MS
11429
11430 We've picked one PC value. If "clear" is issued with another
ed0616c6
VP
11431 PC corresponding to the same file:line, the breakpoint won't
11432 be cleared. We probably can still clear the breakpoint, but
11433 since the other PC value is never presented to user, user
11434 can only find it by guessing, and it does not seem important
11435 to support that. */
11436
4a64f543
MS
11437 /* For each line spec given, delete bps which correspond to it. Do
11438 it in two passes, solely to preserve the current behavior that
11439 from_tty is forced true if we delete more than one
11440 breakpoint. */
c906108c 11441
80f8a6eb 11442 found = NULL;
8a2c437b 11443 make_cleanup (VEC_cleanup (breakpoint_p), &found);
c906108c
SS
11444 for (i = 0; i < sals.nelts; i++)
11445 {
4aac40c8
TT
11446 int is_abs, sal_name_len;
11447
c906108c 11448 /* If exact pc given, clear bpts at that pc.
c5aa993b
JM
11449 If line given (pc == 0), clear all bpts on specified line.
11450 If defaulting, clear all bpts on default line
c906108c 11451 or at default pc.
c5aa993b
JM
11452
11453 defaulting sal.pc != 0 tests to do
11454
11455 0 1 pc
11456 1 1 pc _and_ line
11457 0 0 line
11458 1 0 <can't happen> */
c906108c
SS
11459
11460 sal = sals.sals[i];
4aac40c8
TT
11461 is_abs = sal.symtab == NULL ? 1 : IS_ABSOLUTE_PATH (sal.symtab->filename);
11462 sal_name_len = is_abs ? 0 : strlen (sal.symtab->filename);
c906108c 11463
4a64f543 11464 /* Find all matching breakpoints and add them to 'found'. */
d6e956e5 11465 ALL_BREAKPOINTS (b)
c5aa993b 11466 {
0d381245 11467 int match = 0;
4a64f543 11468 /* Are we going to delete b? */
cc60f2e3 11469 if (b->type != bp_none && !is_watchpoint (b))
0d381245
VP
11470 {
11471 struct bp_location *loc = b->loc;
11472 for (; loc; loc = loc->next)
11473 {
f8eba3c6
TT
11474 /* If the user specified file:line, don't allow a PC
11475 match. This matches historical gdb behavior. */
11476 int pc_match = (!sal.explicit_line
11477 && sal.pc
11478 && (loc->pspace == sal.pspace)
11479 && (loc->address == sal.pc)
11480 && (!section_is_overlay (loc->section)
11481 || loc->section == sal.section));
4aac40c8
TT
11482 int line_match = 0;
11483
11484 if ((default_match || sal.explicit_line)
11485 && loc->source_file != NULL
11486 && sal.symtab != NULL
11487 && sal.pspace == loc->pspace
11488 && loc->line_number == sal.line)
11489 {
11490 if (filename_cmp (loc->source_file,
11491 sal.symtab->filename) == 0)
11492 line_match = 1;
11493 else if (!IS_ABSOLUTE_PATH (sal.symtab->filename)
11494 && compare_filenames_for_search (loc->source_file,
11495 sal.symtab->filename,
11496 sal_name_len))
11497 line_match = 1;
11498 }
11499
0d381245
VP
11500 if (pc_match || line_match)
11501 {
11502 match = 1;
11503 break;
11504 }
11505 }
11506 }
11507
11508 if (match)
d6e956e5 11509 VEC_safe_push(breakpoint_p, found, b);
c906108c 11510 }
80f8a6eb 11511 }
8a2c437b 11512
80f8a6eb 11513 /* Now go thru the 'found' chain and delete them. */
d6e956e5 11514 if (VEC_empty(breakpoint_p, found))
80f8a6eb
MS
11515 {
11516 if (arg)
8a3fe4f8 11517 error (_("No breakpoint at %s."), arg);
80f8a6eb 11518 else
8a3fe4f8 11519 error (_("No breakpoint at this line."));
80f8a6eb 11520 }
c906108c 11521
8a2c437b
TT
11522 /* Remove duplicates from the vec. */
11523 qsort (VEC_address (breakpoint_p, found),
11524 VEC_length (breakpoint_p, found),
11525 sizeof (breakpoint_p),
11526 compare_breakpoints);
11527 prev = VEC_index (breakpoint_p, found, 0);
11528 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
11529 {
11530 if (b == prev)
11531 {
11532 VEC_ordered_remove (breakpoint_p, found, ix);
11533 --ix;
11534 }
11535 }
11536
d6e956e5 11537 if (VEC_length(breakpoint_p, found) > 1)
4a64f543 11538 from_tty = 1; /* Always report if deleted more than one. */
80f8a6eb 11539 if (from_tty)
a3f17187 11540 {
d6e956e5 11541 if (VEC_length(breakpoint_p, found) == 1)
a3f17187
AC
11542 printf_unfiltered (_("Deleted breakpoint "));
11543 else
11544 printf_unfiltered (_("Deleted breakpoints "));
11545 }
80f8a6eb 11546 breakpoints_changed ();
d6e956e5
VP
11547
11548 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
80f8a6eb 11549 {
c5aa993b 11550 if (from_tty)
d6e956e5
VP
11551 printf_unfiltered ("%d ", b->number);
11552 delete_breakpoint (b);
c906108c 11553 }
80f8a6eb
MS
11554 if (from_tty)
11555 putchar_unfiltered ('\n');
8a2c437b
TT
11556
11557 do_cleanups (cleanups);
c906108c
SS
11558}
11559\f
11560/* Delete breakpoint in BS if they are `delete' breakpoints and
11561 all breakpoints that are marked for deletion, whether hit or not.
11562 This is called after any breakpoint is hit, or after errors. */
11563
11564void
fba45db2 11565breakpoint_auto_delete (bpstat bs)
c906108c 11566{
35df4500 11567 struct breakpoint *b, *b_tmp;
c906108c
SS
11568
11569 for (; bs; bs = bs->next)
f431efe5
PA
11570 if (bs->breakpoint_at
11571 && bs->breakpoint_at->disposition == disp_del
c906108c 11572 && bs->stop)
f431efe5 11573 delete_breakpoint (bs->breakpoint_at);
c906108c 11574
35df4500 11575 ALL_BREAKPOINTS_SAFE (b, b_tmp)
c5aa993b 11576 {
b5de0fa7 11577 if (b->disposition == disp_del_at_next_stop)
c5aa993b
JM
11578 delete_breakpoint (b);
11579 }
c906108c
SS
11580}
11581
4a64f543
MS
11582/* A comparison function for bp_location AP and BP being interfaced to
11583 qsort. Sort elements primarily by their ADDRESS (no matter what
11584 does breakpoint_address_is_meaningful say for its OWNER),
11585 secondarily by ordering first bp_permanent OWNERed elements and
11586 terciarily just ensuring the array is sorted stable way despite
e5dd4106 11587 qsort being an unstable algorithm. */
876fa593
JK
11588
11589static int
494cfb0f 11590bp_location_compare (const void *ap, const void *bp)
876fa593 11591{
494cfb0f
JK
11592 struct bp_location *a = *(void **) ap;
11593 struct bp_location *b = *(void **) bp;
2bdf28a0 11594 /* A and B come from existing breakpoints having non-NULL OWNER. */
876fa593
JK
11595 int a_perm = a->owner->enable_state == bp_permanent;
11596 int b_perm = b->owner->enable_state == bp_permanent;
11597
11598 if (a->address != b->address)
11599 return (a->address > b->address) - (a->address < b->address);
11600
dea2aa5f
LM
11601 /* Sort locations at the same address by their pspace number, keeping
11602 locations of the same inferior (in a multi-inferior environment)
11603 grouped. */
11604
11605 if (a->pspace->num != b->pspace->num)
11606 return ((a->pspace->num > b->pspace->num)
11607 - (a->pspace->num < b->pspace->num));
11608
876fa593
JK
11609 /* Sort permanent breakpoints first. */
11610 if (a_perm != b_perm)
11611 return (a_perm < b_perm) - (a_perm > b_perm);
11612
c56a97f9
JK
11613 /* Make the internal GDB representation stable across GDB runs
11614 where A and B memory inside GDB can differ. Breakpoint locations of
11615 the same type at the same address can be sorted in arbitrary order. */
876fa593
JK
11616
11617 if (a->owner->number != b->owner->number)
c56a97f9
JK
11618 return ((a->owner->number > b->owner->number)
11619 - (a->owner->number < b->owner->number));
876fa593
JK
11620
11621 return (a > b) - (a < b);
11622}
11623
876fa593 11624/* Set bp_location_placed_address_before_address_max and
4a64f543
MS
11625 bp_location_shadow_len_after_address_max according to the current
11626 content of the bp_location array. */
f7545552
TT
11627
11628static void
876fa593 11629bp_location_target_extensions_update (void)
f7545552 11630{
876fa593
JK
11631 struct bp_location *bl, **blp_tmp;
11632
11633 bp_location_placed_address_before_address_max = 0;
11634 bp_location_shadow_len_after_address_max = 0;
11635
11636 ALL_BP_LOCATIONS (bl, blp_tmp)
11637 {
11638 CORE_ADDR start, end, addr;
11639
11640 if (!bp_location_has_shadow (bl))
11641 continue;
11642
11643 start = bl->target_info.placed_address;
11644 end = start + bl->target_info.shadow_len;
11645
11646 gdb_assert (bl->address >= start);
11647 addr = bl->address - start;
11648 if (addr > bp_location_placed_address_before_address_max)
11649 bp_location_placed_address_before_address_max = addr;
11650
11651 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11652
11653 gdb_assert (bl->address < end);
11654 addr = end - bl->address;
11655 if (addr > bp_location_shadow_len_after_address_max)
11656 bp_location_shadow_len_after_address_max = addr;
11657 }
f7545552
TT
11658}
11659
1e4d1764
YQ
11660/* Download tracepoint locations if they haven't been. */
11661
11662static void
11663download_tracepoint_locations (void)
11664{
11665 struct bp_location *bl, **blp_tmp;
11666 struct cleanup *old_chain;
11667
11668 if (!target_can_download_tracepoint ())
11669 return;
11670
11671 old_chain = save_current_space_and_thread ();
11672
11673 ALL_BP_LOCATIONS (bl, blp_tmp)
11674 {
11675 struct tracepoint *t;
11676
11677 if (!is_tracepoint (bl->owner))
11678 continue;
11679
11680 if ((bl->owner->type == bp_fast_tracepoint
11681 ? !may_insert_fast_tracepoints
11682 : !may_insert_tracepoints))
11683 continue;
11684
11685 /* In tracepoint, locations are _never_ duplicated, so
11686 should_be_inserted is equivalent to
11687 unduplicated_should_be_inserted. */
11688 if (!should_be_inserted (bl) || bl->inserted)
11689 continue;
11690
11691 switch_to_program_space_and_thread (bl->pspace);
11692
11693 target_download_tracepoint (bl);
11694
11695 bl->inserted = 1;
11696 t = (struct tracepoint *) bl->owner;
11697 t->number_on_target = bl->owner->number;
11698 }
11699
11700 do_cleanups (old_chain);
11701}
11702
934709f0
PW
11703/* Swap the insertion/duplication state between two locations. */
11704
11705static void
11706swap_insertion (struct bp_location *left, struct bp_location *right)
11707{
11708 const int left_inserted = left->inserted;
11709 const int left_duplicate = left->duplicate;
b775012e 11710 const int left_needs_update = left->needs_update;
934709f0
PW
11711 const struct bp_target_info left_target_info = left->target_info;
11712
1e4d1764
YQ
11713 /* Locations of tracepoints can never be duplicated. */
11714 if (is_tracepoint (left->owner))
11715 gdb_assert (!left->duplicate);
11716 if (is_tracepoint (right->owner))
11717 gdb_assert (!right->duplicate);
11718
934709f0
PW
11719 left->inserted = right->inserted;
11720 left->duplicate = right->duplicate;
b775012e 11721 left->needs_update = right->needs_update;
934709f0
PW
11722 left->target_info = right->target_info;
11723 right->inserted = left_inserted;
11724 right->duplicate = left_duplicate;
b775012e 11725 right->needs_update = left_needs_update;
934709f0
PW
11726 right->target_info = left_target_info;
11727}
11728
b775012e
LM
11729/* Force the re-insertion of the locations at ADDRESS. This is called
11730 once a new/deleted/modified duplicate location is found and we are evaluating
11731 conditions on the target's side. Such conditions need to be updated on
11732 the target. */
11733
11734static void
11735force_breakpoint_reinsertion (struct bp_location *bl)
11736{
11737 struct bp_location **locp = NULL, **loc2p;
11738 struct bp_location *loc;
11739 CORE_ADDR address = 0;
11740 int pspace_num;
11741
11742 address = bl->address;
11743 pspace_num = bl->pspace->num;
11744
11745 /* This is only meaningful if the target is
11746 evaluating conditions and if the user has
11747 opted for condition evaluation on the target's
11748 side. */
11749 if (gdb_evaluates_breakpoint_condition_p ()
11750 || !target_supports_evaluation_of_breakpoint_conditions ())
11751 return;
11752
11753 /* Flag all breakpoint locations with this address and
11754 the same program space as the location
11755 as "its condition has changed". We need to
11756 update the conditions on the target's side. */
11757 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address)
11758 {
11759 loc = *loc2p;
11760
11761 if (!is_breakpoint (loc->owner)
11762 || pspace_num != loc->pspace->num)
11763 continue;
11764
11765 /* Flag the location appropriately. We use a different state to
11766 let everyone know that we already updated the set of locations
11767 with addr bl->address and program space bl->pspace. This is so
11768 we don't have to keep calling these functions just to mark locations
11769 that have already been marked. */
11770 loc->condition_changed = condition_updated;
11771
11772 /* Free the agent expression bytecode as well. We will compute
11773 it later on. */
11774 if (loc->cond_bytecode)
11775 {
11776 free_agent_expr (loc->cond_bytecode);
11777 loc->cond_bytecode = NULL;
11778 }
11779 }
11780}
11781
4cd9bd08 11782/* If SHOULD_INSERT is false, do not insert any breakpoint locations
b60e7edf
PA
11783 into the inferior, only remove already-inserted locations that no
11784 longer should be inserted. Functions that delete a breakpoint or
11785 breakpoints should pass false, so that deleting a breakpoint
11786 doesn't have the side effect of inserting the locations of other
11787 breakpoints that are marked not-inserted, but should_be_inserted
11788 returns true on them.
11789
11790 This behaviour is useful is situations close to tear-down -- e.g.,
11791 after an exec, while the target still has execution, but breakpoint
11792 shadows of the previous executable image should *NOT* be restored
11793 to the new image; or before detaching, where the target still has
11794 execution and wants to delete breakpoints from GDB's lists, and all
11795 breakpoints had already been removed from the inferior. */
11796
0d381245 11797static void
b60e7edf 11798update_global_location_list (int should_insert)
0d381245 11799{
74960c60 11800 struct breakpoint *b;
876fa593 11801 struct bp_location **locp, *loc;
f7545552 11802 struct cleanup *cleanups;
b775012e
LM
11803 /* Last breakpoint location address that was marked for update. */
11804 CORE_ADDR last_addr = 0;
11805 /* Last breakpoint location program space that was marked for update. */
11806 int last_pspace_num = -1;
f7545552 11807
2d134ed3
PA
11808 /* Used in the duplicates detection below. When iterating over all
11809 bp_locations, points to the first bp_location of a given address.
11810 Breakpoints and watchpoints of different types are never
11811 duplicates of each other. Keep one pointer for each type of
11812 breakpoint/watchpoint, so we only need to loop over all locations
11813 once. */
11814 struct bp_location *bp_loc_first; /* breakpoint */
11815 struct bp_location *wp_loc_first; /* hardware watchpoint */
11816 struct bp_location *awp_loc_first; /* access watchpoint */
11817 struct bp_location *rwp_loc_first; /* read watchpoint */
876fa593 11818
4a64f543
MS
11819 /* Saved former bp_location array which we compare against the newly
11820 built bp_location from the current state of ALL_BREAKPOINTS. */
876fa593
JK
11821 struct bp_location **old_location, **old_locp;
11822 unsigned old_location_count;
11823
11824 old_location = bp_location;
11825 old_location_count = bp_location_count;
11826 bp_location = NULL;
11827 bp_location_count = 0;
11828 cleanups = make_cleanup (xfree, old_location);
0d381245 11829
74960c60 11830 ALL_BREAKPOINTS (b)
876fa593
JK
11831 for (loc = b->loc; loc; loc = loc->next)
11832 bp_location_count++;
11833
11834 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
11835 locp = bp_location;
11836 ALL_BREAKPOINTS (b)
11837 for (loc = b->loc; loc; loc = loc->next)
11838 *locp++ = loc;
11839 qsort (bp_location, bp_location_count, sizeof (*bp_location),
494cfb0f 11840 bp_location_compare);
876fa593
JK
11841
11842 bp_location_target_extensions_update ();
74960c60 11843
4a64f543
MS
11844 /* Identify bp_location instances that are no longer present in the
11845 new list, and therefore should be freed. Note that it's not
11846 necessary that those locations should be removed from inferior --
11847 if there's another location at the same address (previously
11848 marked as duplicate), we don't need to remove/insert the
11849 location.
876fa593 11850
4a64f543
MS
11851 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11852 and former bp_location array state respectively. */
876fa593
JK
11853
11854 locp = bp_location;
11855 for (old_locp = old_location; old_locp < old_location + old_location_count;
11856 old_locp++)
74960c60 11857 {
876fa593 11858 struct bp_location *old_loc = *old_locp;
c7d46a38 11859 struct bp_location **loc2p;
876fa593 11860
e5dd4106 11861 /* Tells if 'old_loc' is found among the new locations. If
4a64f543 11862 not, we have to free it. */
c7d46a38 11863 int found_object = 0;
20874c92
VP
11864 /* Tells if the location should remain inserted in the target. */
11865 int keep_in_target = 0;
11866 int removed = 0;
876fa593 11867
4a64f543
MS
11868 /* Skip LOCP entries which will definitely never be needed.
11869 Stop either at or being the one matching OLD_LOC. */
876fa593 11870 while (locp < bp_location + bp_location_count
c7d46a38 11871 && (*locp)->address < old_loc->address)
876fa593 11872 locp++;
c7d46a38
PA
11873
11874 for (loc2p = locp;
11875 (loc2p < bp_location + bp_location_count
11876 && (*loc2p)->address == old_loc->address);
11877 loc2p++)
11878 {
b775012e
LM
11879 /* Check if this is a new/duplicated location or a duplicated
11880 location that had its condition modified. If so, we want to send
11881 its condition to the target if evaluation of conditions is taking
11882 place there. */
11883 if ((*loc2p)->condition_changed == condition_modified
11884 && (last_addr != old_loc->address
11885 || last_pspace_num != old_loc->pspace->num))
c7d46a38 11886 {
b775012e
LM
11887 force_breakpoint_reinsertion (*loc2p);
11888 last_pspace_num = old_loc->pspace->num;
c7d46a38 11889 }
b775012e
LM
11890
11891 if (*loc2p == old_loc)
11892 found_object = 1;
c7d46a38 11893 }
74960c60 11894
b775012e
LM
11895 /* We have already handled this address, update it so that we don't
11896 have to go through updates again. */
11897 last_addr = old_loc->address;
11898
11899 /* Target-side condition evaluation: Handle deleted locations. */
11900 if (!found_object)
11901 force_breakpoint_reinsertion (old_loc);
11902
4a64f543
MS
11903 /* If this location is no longer present, and inserted, look if
11904 there's maybe a new location at the same address. If so,
11905 mark that one inserted, and don't remove this one. This is
11906 needed so that we don't have a time window where a breakpoint
11907 at certain location is not inserted. */
74960c60 11908
876fa593 11909 if (old_loc->inserted)
0d381245 11910 {
4a64f543
MS
11911 /* If the location is inserted now, we might have to remove
11912 it. */
74960c60 11913
876fa593 11914 if (found_object && should_be_inserted (old_loc))
74960c60 11915 {
4a64f543
MS
11916 /* The location is still present in the location list,
11917 and still should be inserted. Don't do anything. */
20874c92 11918 keep_in_target = 1;
74960c60
VP
11919 }
11920 else
11921 {
b775012e
LM
11922 /* This location still exists, but it won't be kept in the
11923 target since it may have been disabled. We proceed to
11924 remove its target-side condition. */
11925
4a64f543
MS
11926 /* The location is either no longer present, or got
11927 disabled. See if there's another location at the
11928 same address, in which case we don't need to remove
11929 this one from the target. */
876fa593 11930
2bdf28a0 11931 /* OLD_LOC comes from existing struct breakpoint. */
876fa593
JK
11932 if (breakpoint_address_is_meaningful (old_loc->owner))
11933 {
876fa593 11934 for (loc2p = locp;
c7d46a38
PA
11935 (loc2p < bp_location + bp_location_count
11936 && (*loc2p)->address == old_loc->address);
876fa593
JK
11937 loc2p++)
11938 {
11939 struct bp_location *loc2 = *loc2p;
11940
2d134ed3 11941 if (breakpoint_locations_match (loc2, old_loc))
c7d46a38 11942 {
85d721b8
PA
11943 /* Read watchpoint locations are switched to
11944 access watchpoints, if the former are not
11945 supported, but the latter are. */
11946 if (is_hardware_watchpoint (old_loc->owner))
11947 {
11948 gdb_assert (is_hardware_watchpoint (loc2->owner));
11949 loc2->watchpoint_type = old_loc->watchpoint_type;
11950 }
11951
934709f0
PW
11952 /* loc2 is a duplicated location. We need to check
11953 if it should be inserted in case it will be
11954 unduplicated. */
11955 if (loc2 != old_loc
11956 && unduplicated_should_be_inserted (loc2))
c7d46a38 11957 {
934709f0 11958 swap_insertion (old_loc, loc2);
c7d46a38
PA
11959 keep_in_target = 1;
11960 break;
11961 }
876fa593
JK
11962 }
11963 }
11964 }
74960c60
VP
11965 }
11966
20874c92
VP
11967 if (!keep_in_target)
11968 {
876fa593 11969 if (remove_breakpoint (old_loc, mark_uninserted))
20874c92 11970 {
4a64f543
MS
11971 /* This is just about all we can do. We could keep
11972 this location on the global list, and try to
11973 remove it next time, but there's no particular
11974 reason why we will succeed next time.
20874c92 11975
4a64f543
MS
11976 Note that at this point, old_loc->owner is still
11977 valid, as delete_breakpoint frees the breakpoint
11978 only after calling us. */
3e43a32a
MS
11979 printf_filtered (_("warning: Error removing "
11980 "breakpoint %d\n"),
876fa593 11981 old_loc->owner->number);
20874c92
VP
11982 }
11983 removed = 1;
11984 }
0d381245 11985 }
74960c60
VP
11986
11987 if (!found_object)
1c5cfe86 11988 {
db82e815
PA
11989 if (removed && non_stop
11990 && breakpoint_address_is_meaningful (old_loc->owner)
11991 && !is_hardware_watchpoint (old_loc->owner))
20874c92 11992 {
db82e815
PA
11993 /* This location was removed from the target. In
11994 non-stop mode, a race condition is possible where
11995 we've removed a breakpoint, but stop events for that
11996 breakpoint are already queued and will arrive later.
11997 We apply an heuristic to be able to distinguish such
11998 SIGTRAPs from other random SIGTRAPs: we keep this
11999 breakpoint location for a bit, and will retire it
12000 after we see some number of events. The theory here
12001 is that reporting of events should, "on the average",
12002 be fair, so after a while we'll see events from all
12003 threads that have anything of interest, and no longer
12004 need to keep this breakpoint location around. We
12005 don't hold locations forever so to reduce chances of
12006 mistaking a non-breakpoint SIGTRAP for a breakpoint
12007 SIGTRAP.
12008
12009 The heuristic failing can be disastrous on
12010 decr_pc_after_break targets.
12011
12012 On decr_pc_after_break targets, like e.g., x86-linux,
12013 if we fail to recognize a late breakpoint SIGTRAP,
12014 because events_till_retirement has reached 0 too
12015 soon, we'll fail to do the PC adjustment, and report
12016 a random SIGTRAP to the user. When the user resumes
12017 the inferior, it will most likely immediately crash
2dec564e 12018 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
db82e815
PA
12019 corrupted, because of being resumed e.g., in the
12020 middle of a multi-byte instruction, or skipped a
12021 one-byte instruction. This was actually seen happen
12022 on native x86-linux, and should be less rare on
12023 targets that do not support new thread events, like
12024 remote, due to the heuristic depending on
12025 thread_count.
12026
12027 Mistaking a random SIGTRAP for a breakpoint trap
12028 causes similar symptoms (PC adjustment applied when
12029 it shouldn't), but then again, playing with SIGTRAPs
12030 behind the debugger's back is asking for trouble.
12031
12032 Since hardware watchpoint traps are always
12033 distinguishable from other traps, so we don't need to
12034 apply keep hardware watchpoint moribund locations
12035 around. We simply always ignore hardware watchpoint
12036 traps we can no longer explain. */
12037
876fa593
JK
12038 old_loc->events_till_retirement = 3 * (thread_count () + 1);
12039 old_loc->owner = NULL;
20874c92 12040
876fa593 12041 VEC_safe_push (bp_location_p, moribund_locations, old_loc);
1c5cfe86
PA
12042 }
12043 else
f431efe5
PA
12044 {
12045 old_loc->owner = NULL;
12046 decref_bp_location (&old_loc);
12047 }
20874c92 12048 }
74960c60 12049 }
1c5cfe86 12050
348d480f
PA
12051 /* Rescan breakpoints at the same address and section, marking the
12052 first one as "first" and any others as "duplicates". This is so
12053 that the bpt instruction is only inserted once. If we have a
12054 permanent breakpoint at the same place as BPT, make that one the
12055 official one, and the rest as duplicates. Permanent breakpoints
12056 are sorted first for the same address.
12057
12058 Do the same for hardware watchpoints, but also considering the
12059 watchpoint's type (regular/access/read) and length. */
12060
12061 bp_loc_first = NULL;
12062 wp_loc_first = NULL;
12063 awp_loc_first = NULL;
12064 rwp_loc_first = NULL;
12065 ALL_BP_LOCATIONS (loc, locp)
12066 {
12067 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12068 non-NULL. */
348d480f 12069 struct bp_location **loc_first_p;
d3fbdd86 12070 b = loc->owner;
348d480f 12071
f8eba3c6 12072 if (!should_be_inserted (loc)
348d480f 12073 || !breakpoint_address_is_meaningful (b)
1e4d1764
YQ
12074 /* Don't detect duplicate for tracepoint locations because they are
12075 never duplicated. See the comments in field `duplicate' of
12076 `struct bp_location'. */
348d480f 12077 || is_tracepoint (b))
b775012e
LM
12078 {
12079 /* Clear the condition modification flag. */
12080 loc->condition_changed = condition_unchanged;
12081 continue;
12082 }
348d480f
PA
12083
12084 /* Permanent breakpoint should always be inserted. */
12085 if (b->enable_state == bp_permanent && ! loc->inserted)
12086 internal_error (__FILE__, __LINE__,
12087 _("allegedly permanent breakpoint is not "
12088 "actually inserted"));
12089
12090 if (b->type == bp_hardware_watchpoint)
12091 loc_first_p = &wp_loc_first;
12092 else if (b->type == bp_read_watchpoint)
12093 loc_first_p = &rwp_loc_first;
12094 else if (b->type == bp_access_watchpoint)
12095 loc_first_p = &awp_loc_first;
12096 else
12097 loc_first_p = &bp_loc_first;
12098
12099 if (*loc_first_p == NULL
12100 || (overlay_debugging && loc->section != (*loc_first_p)->section)
12101 || !breakpoint_locations_match (loc, *loc_first_p))
12102 {
12103 *loc_first_p = loc;
12104 loc->duplicate = 0;
b775012e
LM
12105
12106 if (is_breakpoint (loc->owner) && loc->condition_changed)
12107 {
12108 loc->needs_update = 1;
12109 /* Clear the condition modification flag. */
12110 loc->condition_changed = condition_unchanged;
12111 }
348d480f
PA
12112 continue;
12113 }
12114
934709f0
PW
12115
12116 /* This and the above ensure the invariant that the first location
12117 is not duplicated, and is the inserted one.
12118 All following are marked as duplicated, and are not inserted. */
12119 if (loc->inserted)
12120 swap_insertion (loc, *loc_first_p);
348d480f
PA
12121 loc->duplicate = 1;
12122
b775012e
LM
12123 /* Clear the condition modification flag. */
12124 loc->condition_changed = condition_unchanged;
12125
348d480f
PA
12126 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted
12127 && b->enable_state != bp_permanent)
12128 internal_error (__FILE__, __LINE__,
12129 _("another breakpoint was inserted on top of "
12130 "a permanent breakpoint"));
12131 }
12132
b775012e 12133 if (breakpoints_always_inserted_mode ()
348d480f
PA
12134 && (have_live_inferiors ()
12135 || (gdbarch_has_global_breakpoints (target_gdbarch))))
b775012e
LM
12136 {
12137 if (should_insert)
12138 insert_breakpoint_locations ();
12139 else
12140 {
12141 /* Though should_insert is false, we may need to update conditions
12142 on the target's side if it is evaluating such conditions. We
12143 only update conditions for locations that are marked
12144 "needs_update". */
12145 update_inserted_breakpoint_locations ();
12146 }
12147 }
348d480f 12148
1e4d1764
YQ
12149 if (should_insert)
12150 download_tracepoint_locations ();
12151
348d480f
PA
12152 do_cleanups (cleanups);
12153}
12154
12155void
12156breakpoint_retire_moribund (void)
12157{
12158 struct bp_location *loc;
12159 int ix;
12160
12161 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
12162 if (--(loc->events_till_retirement) == 0)
12163 {
12164 decref_bp_location (&loc);
12165 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
12166 --ix;
12167 }
12168}
12169
12170static void
12171update_global_location_list_nothrow (int inserting)
12172{
bfd189b1 12173 volatile struct gdb_exception e;
348d480f
PA
12174
12175 TRY_CATCH (e, RETURN_MASK_ERROR)
12176 update_global_location_list (inserting);
12177}
12178
12179/* Clear BKP from a BPS. */
12180
12181static void
12182bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt)
12183{
12184 bpstat bs;
12185
12186 for (bs = bps; bs; bs = bs->next)
12187 if (bs->breakpoint_at == bpt)
12188 {
12189 bs->breakpoint_at = NULL;
12190 bs->old_val = NULL;
12191 /* bs->commands will be freed later. */
12192 }
12193}
12194
12195/* Callback for iterate_over_threads. */
12196static int
12197bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
12198{
12199 struct breakpoint *bpt = data;
12200
12201 bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
12202 return 0;
12203}
12204
12205/* Helper for breakpoint and tracepoint breakpoint_ops->mention
12206 callbacks. */
12207
12208static void
12209say_where (struct breakpoint *b)
12210{
79a45e25 12211 struct ui_out *uiout = current_uiout;
348d480f
PA
12212 struct value_print_options opts;
12213
12214 get_user_print_options (&opts);
12215
12216 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12217 single string. */
12218 if (b->loc == NULL)
12219 {
12220 printf_filtered (_(" (%s) pending."), b->addr_string);
12221 }
12222 else
12223 {
f8eba3c6 12224 if (opts.addressprint || b->loc->source_file == NULL)
348d480f
PA
12225 {
12226 printf_filtered (" at ");
12227 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address),
12228 gdb_stdout);
12229 }
f8eba3c6
TT
12230 if (b->loc->source_file)
12231 {
12232 /* If there is a single location, we can print the location
12233 more nicely. */
12234 if (b->loc->next == NULL)
12235 printf_filtered (": file %s, line %d.",
12236 b->loc->source_file, b->loc->line_number);
12237 else
12238 /* This is not ideal, but each location may have a
12239 different file name, and this at least reflects the
12240 real situation somewhat. */
12241 printf_filtered (": %s.", b->addr_string);
12242 }
348d480f
PA
12243
12244 if (b->loc->next)
12245 {
12246 struct bp_location *loc = b->loc;
12247 int n = 0;
12248 for (; loc; loc = loc->next)
12249 ++n;
12250 printf_filtered (" (%d locations)", n);
12251 }
12252 }
12253}
12254
348d480f
PA
12255/* Default bp_location_ops methods. */
12256
12257static void
12258bp_location_dtor (struct bp_location *self)
12259{
12260 xfree (self->cond);
b775012e
LM
12261 if (self->cond_bytecode)
12262 free_agent_expr (self->cond_bytecode);
348d480f 12263 xfree (self->function_name);
f8eba3c6 12264 xfree (self->source_file);
348d480f
PA
12265}
12266
12267static const struct bp_location_ops bp_location_ops =
12268{
12269 bp_location_dtor
12270};
12271
2060206e
PA
12272/* Default breakpoint_ops methods all breakpoint_ops ultimately
12273 inherit from. */
348d480f 12274
2060206e
PA
12275static void
12276base_breakpoint_dtor (struct breakpoint *self)
348d480f
PA
12277{
12278 decref_counted_command_line (&self->commands);
12279 xfree (self->cond_string);
348d480f 12280 xfree (self->addr_string);
f8eba3c6 12281 xfree (self->filter);
348d480f 12282 xfree (self->addr_string_range_end);
348d480f
PA
12283}
12284
2060206e
PA
12285static struct bp_location *
12286base_breakpoint_allocate_location (struct breakpoint *self)
348d480f
PA
12287{
12288 struct bp_location *loc;
12289
12290 loc = XNEW (struct bp_location);
12291 init_bp_location (loc, &bp_location_ops, self);
12292 return loc;
12293}
12294
2060206e
PA
12295static void
12296base_breakpoint_re_set (struct breakpoint *b)
12297{
12298 /* Nothing to re-set. */
12299}
12300
12301#define internal_error_pure_virtual_called() \
12302 gdb_assert_not_reached ("pure virtual function called")
12303
12304static int
12305base_breakpoint_insert_location (struct bp_location *bl)
12306{
12307 internal_error_pure_virtual_called ();
12308}
12309
12310static int
12311base_breakpoint_remove_location (struct bp_location *bl)
12312{
12313 internal_error_pure_virtual_called ();
12314}
12315
12316static int
12317base_breakpoint_breakpoint_hit (const struct bp_location *bl,
12318 struct address_space *aspace,
09ac7c10
TT
12319 CORE_ADDR bp_addr,
12320 const struct target_waitstatus *ws)
2060206e
PA
12321{
12322 internal_error_pure_virtual_called ();
12323}
12324
12325static void
12326base_breakpoint_check_status (bpstat bs)
12327{
12328 /* Always stop. */
12329}
12330
12331/* A "works_in_software_mode" breakpoint_ops method that just internal
12332 errors. */
12333
12334static int
12335base_breakpoint_works_in_software_mode (const struct breakpoint *b)
12336{
12337 internal_error_pure_virtual_called ();
12338}
12339
12340/* A "resources_needed" breakpoint_ops method that just internal
12341 errors. */
12342
12343static int
12344base_breakpoint_resources_needed (const struct bp_location *bl)
12345{
12346 internal_error_pure_virtual_called ();
12347}
12348
12349static enum print_stop_action
12350base_breakpoint_print_it (bpstat bs)
12351{
12352 internal_error_pure_virtual_called ();
12353}
12354
12355static void
12356base_breakpoint_print_one_detail (const struct breakpoint *self,
12357 struct ui_out *uiout)
12358{
12359 /* nothing */
12360}
12361
12362static void
12363base_breakpoint_print_mention (struct breakpoint *b)
12364{
12365 internal_error_pure_virtual_called ();
12366}
12367
12368static void
12369base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
12370{
12371 internal_error_pure_virtual_called ();
12372}
12373
983af33b
SDJ
12374static void
12375base_breakpoint_create_sals_from_address (char **arg,
12376 struct linespec_result *canonical,
12377 enum bptype type_wanted,
12378 char *addr_start,
12379 char **copy_arg)
12380{
12381 internal_error_pure_virtual_called ();
12382}
12383
12384static void
12385base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12386 struct linespec_result *c,
12387 struct linespec_sals *lsal,
12388 char *cond_string,
e7e0cddf 12389 char *extra_string,
983af33b
SDJ
12390 enum bptype type_wanted,
12391 enum bpdisp disposition,
12392 int thread,
12393 int task, int ignore_count,
12394 const struct breakpoint_ops *o,
12395 int from_tty, int enabled,
44f238bb 12396 int internal, unsigned flags)
983af33b
SDJ
12397{
12398 internal_error_pure_virtual_called ();
12399}
12400
12401static void
12402base_breakpoint_decode_linespec (struct breakpoint *b, char **s,
12403 struct symtabs_and_lines *sals)
12404{
12405 internal_error_pure_virtual_called ();
12406}
12407
2060206e
PA
12408static struct breakpoint_ops base_breakpoint_ops =
12409{
12410 base_breakpoint_dtor,
12411 base_breakpoint_allocate_location,
12412 base_breakpoint_re_set,
12413 base_breakpoint_insert_location,
12414 base_breakpoint_remove_location,
12415 base_breakpoint_breakpoint_hit,
12416 base_breakpoint_check_status,
12417 base_breakpoint_resources_needed,
12418 base_breakpoint_works_in_software_mode,
12419 base_breakpoint_print_it,
12420 NULL,
12421 base_breakpoint_print_one_detail,
12422 base_breakpoint_print_mention,
983af33b
SDJ
12423 base_breakpoint_print_recreate,
12424 base_breakpoint_create_sals_from_address,
12425 base_breakpoint_create_breakpoints_sal,
12426 base_breakpoint_decode_linespec,
2060206e
PA
12427};
12428
12429/* Default breakpoint_ops methods. */
12430
12431static void
348d480f
PA
12432bkpt_re_set (struct breakpoint *b)
12433{
06edf0c0
PA
12434 /* FIXME: is this still reachable? */
12435 if (b->addr_string == NULL)
12436 {
12437 /* Anything without a string can't be re-set. */
348d480f 12438 delete_breakpoint (b);
06edf0c0 12439 return;
348d480f 12440 }
06edf0c0
PA
12441
12442 breakpoint_re_set_default (b);
348d480f
PA
12443}
12444
2060206e 12445static int
348d480f
PA
12446bkpt_insert_location (struct bp_location *bl)
12447{
12448 if (bl->loc_type == bp_loc_hardware_breakpoint)
12449 return target_insert_hw_breakpoint (bl->gdbarch,
12450 &bl->target_info);
12451 else
12452 return target_insert_breakpoint (bl->gdbarch,
12453 &bl->target_info);
12454}
12455
2060206e 12456static int
348d480f
PA
12457bkpt_remove_location (struct bp_location *bl)
12458{
12459 if (bl->loc_type == bp_loc_hardware_breakpoint)
12460 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info);
12461 else
12462 return target_remove_breakpoint (bl->gdbarch, &bl->target_info);
12463}
12464
2060206e 12465static int
348d480f 12466bkpt_breakpoint_hit (const struct bp_location *bl,
09ac7c10
TT
12467 struct address_space *aspace, CORE_ADDR bp_addr,
12468 const struct target_waitstatus *ws)
348d480f
PA
12469{
12470 struct breakpoint *b = bl->owner;
12471
09ac7c10 12472 if (ws->kind != TARGET_WAITKIND_STOPPED
a493e3e2 12473 || ws->value.sig != GDB_SIGNAL_TRAP)
09ac7c10
TT
12474 return 0;
12475
348d480f
PA
12476 if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
12477 aspace, bp_addr))
12478 return 0;
12479
12480 if (overlay_debugging /* unmapped overlay section */
12481 && section_is_overlay (bl->section)
12482 && !section_is_mapped (bl->section))
12483 return 0;
12484
12485 return 1;
12486}
12487
2060206e 12488static int
348d480f
PA
12489bkpt_resources_needed (const struct bp_location *bl)
12490{
12491 gdb_assert (bl->owner->type == bp_hardware_breakpoint);
12492
12493 return 1;
12494}
12495
2060206e 12496static enum print_stop_action
348d480f
PA
12497bkpt_print_it (bpstat bs)
12498{
348d480f
PA
12499 struct breakpoint *b;
12500 const struct bp_location *bl;
001c8c33 12501 int bp_temp;
79a45e25 12502 struct ui_out *uiout = current_uiout;
348d480f
PA
12503
12504 gdb_assert (bs->bp_location_at != NULL);
12505
12506 bl = bs->bp_location_at;
12507 b = bs->breakpoint_at;
12508
001c8c33
PA
12509 bp_temp = b->disposition == disp_del;
12510 if (bl->address != bl->requested_address)
12511 breakpoint_adjustment_warning (bl->requested_address,
12512 bl->address,
12513 b->number, 1);
12514 annotate_breakpoint (b->number);
12515 if (bp_temp)
12516 ui_out_text (uiout, "\nTemporary breakpoint ");
12517 else
12518 ui_out_text (uiout, "\nBreakpoint ");
12519 if (ui_out_is_mi_like_p (uiout))
348d480f 12520 {
001c8c33
PA
12521 ui_out_field_string (uiout, "reason",
12522 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
12523 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
06edf0c0 12524 }
001c8c33
PA
12525 ui_out_field_int (uiout, "bkptno", b->number);
12526 ui_out_text (uiout, ", ");
06edf0c0 12527
001c8c33 12528 return PRINT_SRC_AND_LOC;
06edf0c0
PA
12529}
12530
2060206e 12531static void
06edf0c0
PA
12532bkpt_print_mention (struct breakpoint *b)
12533{
79a45e25 12534 if (ui_out_is_mi_like_p (current_uiout))
06edf0c0
PA
12535 return;
12536
12537 switch (b->type)
12538 {
12539 case bp_breakpoint:
12540 case bp_gnu_ifunc_resolver:
12541 if (b->disposition == disp_del)
12542 printf_filtered (_("Temporary breakpoint"));
12543 else
12544 printf_filtered (_("Breakpoint"));
12545 printf_filtered (_(" %d"), b->number);
12546 if (b->type == bp_gnu_ifunc_resolver)
12547 printf_filtered (_(" at gnu-indirect-function resolver"));
12548 break;
12549 case bp_hardware_breakpoint:
12550 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
12551 break;
e7e0cddf
SS
12552 case bp_dprintf:
12553 printf_filtered (_("Dprintf %d"), b->number);
12554 break;
06edf0c0
PA
12555 }
12556
12557 say_where (b);
12558}
12559
2060206e 12560static void
06edf0c0
PA
12561bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
12562{
12563 if (tp->type == bp_breakpoint && tp->disposition == disp_del)
12564 fprintf_unfiltered (fp, "tbreak");
12565 else if (tp->type == bp_breakpoint)
12566 fprintf_unfiltered (fp, "break");
12567 else if (tp->type == bp_hardware_breakpoint
12568 && tp->disposition == disp_del)
12569 fprintf_unfiltered (fp, "thbreak");
12570 else if (tp->type == bp_hardware_breakpoint)
12571 fprintf_unfiltered (fp, "hbreak");
12572 else
12573 internal_error (__FILE__, __LINE__,
12574 _("unhandled breakpoint type %d"), (int) tp->type);
12575
2060206e 12576 fprintf_unfiltered (fp, " %s", tp->addr_string);
dd11a36c 12577 print_recreate_thread (tp, fp);
06edf0c0
PA
12578}
12579
983af33b
SDJ
12580static void
12581bkpt_create_sals_from_address (char **arg,
12582 struct linespec_result *canonical,
12583 enum bptype type_wanted,
12584 char *addr_start, char **copy_arg)
12585{
12586 create_sals_from_address_default (arg, canonical, type_wanted,
12587 addr_start, copy_arg);
12588}
12589
12590static void
12591bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
12592 struct linespec_result *canonical,
12593 struct linespec_sals *lsal,
12594 char *cond_string,
e7e0cddf 12595 char *extra_string,
983af33b
SDJ
12596 enum bptype type_wanted,
12597 enum bpdisp disposition,
12598 int thread,
12599 int task, int ignore_count,
12600 const struct breakpoint_ops *ops,
12601 int from_tty, int enabled,
44f238bb 12602 int internal, unsigned flags)
983af33b
SDJ
12603{
12604 create_breakpoints_sal_default (gdbarch, canonical, lsal,
e7e0cddf
SS
12605 cond_string, extra_string,
12606 type_wanted,
983af33b
SDJ
12607 disposition, thread, task,
12608 ignore_count, ops, from_tty,
44f238bb 12609 enabled, internal, flags);
983af33b
SDJ
12610}
12611
12612static void
12613bkpt_decode_linespec (struct breakpoint *b, char **s,
12614 struct symtabs_and_lines *sals)
12615{
12616 decode_linespec_default (b, s, sals);
12617}
12618
06edf0c0
PA
12619/* Virtual table for internal breakpoints. */
12620
12621static void
12622internal_bkpt_re_set (struct breakpoint *b)
12623{
12624 switch (b->type)
12625 {
12626 /* Delete overlay event and longjmp master breakpoints; they
12627 will be reset later by breakpoint_re_set. */
12628 case bp_overlay_event:
12629 case bp_longjmp_master:
12630 case bp_std_terminate_master:
12631 case bp_exception_master:
12632 delete_breakpoint (b);
12633 break;
12634
12635 /* This breakpoint is special, it's set up when the inferior
12636 starts and we really don't want to touch it. */
12637 case bp_shlib_event:
12638
12639 /* Like bp_shlib_event, this breakpoint type is special. Once
12640 it is set up, we do not want to touch it. */
12641 case bp_thread_event:
12642 break;
12643 }
12644}
12645
12646static void
12647internal_bkpt_check_status (bpstat bs)
12648{
a9b3a50f
PA
12649 if (bs->breakpoint_at->type == bp_shlib_event)
12650 {
12651 /* If requested, stop when the dynamic linker notifies GDB of
12652 events. This allows the user to get control and place
12653 breakpoints in initializer routines for dynamically loaded
12654 objects (among other things). */
12655 bs->stop = stop_on_solib_events;
12656 bs->print = stop_on_solib_events;
12657 }
12658 else
12659 bs->stop = 0;
06edf0c0
PA
12660}
12661
12662static enum print_stop_action
12663internal_bkpt_print_it (bpstat bs)
12664{
36dfb11c 12665 struct ui_out *uiout = current_uiout;
06edf0c0 12666 struct breakpoint *b;
06edf0c0 12667
06edf0c0
PA
12668 b = bs->breakpoint_at;
12669
06edf0c0
PA
12670 switch (b->type)
12671 {
348d480f
PA
12672 case bp_shlib_event:
12673 /* Did we stop because the user set the stop_on_solib_events
12674 variable? (If so, we report this as a generic, "Stopped due
12675 to shlib event" message.) */
edcc5120 12676 print_solib_event (0);
348d480f
PA
12677 break;
12678
12679 case bp_thread_event:
12680 /* Not sure how we will get here.
12681 GDB should not stop for these breakpoints. */
12682 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
348d480f
PA
12683 break;
12684
12685 case bp_overlay_event:
12686 /* By analogy with the thread event, GDB should not stop for these. */
12687 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
348d480f
PA
12688 break;
12689
12690 case bp_longjmp_master:
12691 /* These should never be enabled. */
12692 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
348d480f
PA
12693 break;
12694
12695 case bp_std_terminate_master:
12696 /* These should never be enabled. */
12697 printf_filtered (_("std::terminate Master Breakpoint: "
12698 "gdb should not stop!\n"));
348d480f
PA
12699 break;
12700
12701 case bp_exception_master:
12702 /* These should never be enabled. */
12703 printf_filtered (_("Exception Master Breakpoint: "
12704 "gdb should not stop!\n"));
06edf0c0
PA
12705 break;
12706 }
12707
001c8c33 12708 return PRINT_NOTHING;
06edf0c0
PA
12709}
12710
12711static void
12712internal_bkpt_print_mention (struct breakpoint *b)
12713{
12714 /* Nothing to mention. These breakpoints are internal. */
12715}
12716
06edf0c0
PA
12717/* Virtual table for momentary breakpoints */
12718
12719static void
12720momentary_bkpt_re_set (struct breakpoint *b)
12721{
12722 /* Keep temporary breakpoints, which can be encountered when we step
12723 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12724 Otherwise these should have been blown away via the cleanup chain
12725 or by breakpoint_init_inferior when we rerun the executable. */
12726}
12727
12728static void
12729momentary_bkpt_check_status (bpstat bs)
12730{
12731 /* Nothing. The point of these breakpoints is causing a stop. */
12732}
12733
12734static enum print_stop_action
12735momentary_bkpt_print_it (bpstat bs)
12736{
79a45e25
PA
12737 struct ui_out *uiout = current_uiout;
12738
001c8c33 12739 if (ui_out_is_mi_like_p (uiout))
06edf0c0 12740 {
001c8c33 12741 struct breakpoint *b = bs->breakpoint_at;
348d480f 12742
001c8c33
PA
12743 switch (b->type)
12744 {
12745 case bp_finish:
12746 ui_out_field_string
12747 (uiout, "reason",
12748 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
12749 break;
348d480f 12750
001c8c33
PA
12751 case bp_until:
12752 ui_out_field_string
12753 (uiout, "reason",
12754 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
12755 break;
12756 }
348d480f
PA
12757 }
12758
001c8c33 12759 return PRINT_UNKNOWN;
348d480f
PA
12760}
12761
06edf0c0
PA
12762static void
12763momentary_bkpt_print_mention (struct breakpoint *b)
348d480f 12764{
06edf0c0 12765 /* Nothing to mention. These breakpoints are internal. */
348d480f
PA
12766}
12767
55aa24fb
SDJ
12768/* Specific methods for probe breakpoints. */
12769
12770static int
12771bkpt_probe_insert_location (struct bp_location *bl)
12772{
12773 int v = bkpt_insert_location (bl);
12774
12775 if (v == 0)
12776 {
12777 /* The insertion was successful, now let's set the probe's semaphore
12778 if needed. */
12779 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch);
12780 }
12781
12782 return v;
12783}
12784
12785static int
12786bkpt_probe_remove_location (struct bp_location *bl)
12787{
12788 /* Let's clear the semaphore before removing the location. */
12789 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch);
12790
12791 return bkpt_remove_location (bl);
12792}
12793
12794static void
12795bkpt_probe_create_sals_from_address (char **arg,
12796 struct linespec_result *canonical,
12797 enum bptype type_wanted,
12798 char *addr_start, char **copy_arg)
12799{
12800 struct linespec_sals lsal;
12801
12802 lsal.sals = parse_probes (arg, canonical);
12803
12804 *copy_arg = xstrdup (canonical->addr_string);
12805 lsal.canonical = xstrdup (*copy_arg);
12806
12807 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12808}
12809
12810static void
12811bkpt_probe_decode_linespec (struct breakpoint *b, char **s,
12812 struct symtabs_and_lines *sals)
12813{
12814 *sals = parse_probes (s, NULL);
12815 if (!sals->sals)
12816 error (_("probe not found"));
12817}
12818
348d480f 12819/* The breakpoint_ops structure to be used in tracepoints. */
876fa593 12820
348d480f
PA
12821static void
12822tracepoint_re_set (struct breakpoint *b)
12823{
12824 breakpoint_re_set_default (b);
12825}
876fa593 12826
348d480f
PA
12827static int
12828tracepoint_breakpoint_hit (const struct bp_location *bl,
09ac7c10
TT
12829 struct address_space *aspace, CORE_ADDR bp_addr,
12830 const struct target_waitstatus *ws)
348d480f
PA
12831{
12832 /* By definition, the inferior does not report stops at
12833 tracepoints. */
12834 return 0;
74960c60
VP
12835}
12836
12837static void
348d480f
PA
12838tracepoint_print_one_detail (const struct breakpoint *self,
12839 struct ui_out *uiout)
74960c60 12840{
d9b3f62e
PA
12841 struct tracepoint *tp = (struct tracepoint *) self;
12842 if (tp->static_trace_marker_id)
348d480f
PA
12843 {
12844 gdb_assert (self->type == bp_static_tracepoint);
cc59ec59 12845
348d480f
PA
12846 ui_out_text (uiout, "\tmarker id is ");
12847 ui_out_field_string (uiout, "static-tracepoint-marker-string-id",
d9b3f62e 12848 tp->static_trace_marker_id);
348d480f
PA
12849 ui_out_text (uiout, "\n");
12850 }
0d381245
VP
12851}
12852
a474d7c2 12853static void
348d480f 12854tracepoint_print_mention (struct breakpoint *b)
a474d7c2 12855{
79a45e25 12856 if (ui_out_is_mi_like_p (current_uiout))
348d480f 12857 return;
cc59ec59 12858
348d480f
PA
12859 switch (b->type)
12860 {
12861 case bp_tracepoint:
12862 printf_filtered (_("Tracepoint"));
12863 printf_filtered (_(" %d"), b->number);
12864 break;
12865 case bp_fast_tracepoint:
12866 printf_filtered (_("Fast tracepoint"));
12867 printf_filtered (_(" %d"), b->number);
12868 break;
12869 case bp_static_tracepoint:
12870 printf_filtered (_("Static tracepoint"));
12871 printf_filtered (_(" %d"), b->number);
12872 break;
12873 default:
12874 internal_error (__FILE__, __LINE__,
12875 _("unhandled tracepoint type %d"), (int) b->type);
12876 }
12877
12878 say_where (b);
a474d7c2
PA
12879}
12880
348d480f 12881static void
d9b3f62e 12882tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
a474d7c2 12883{
d9b3f62e
PA
12884 struct tracepoint *tp = (struct tracepoint *) self;
12885
12886 if (self->type == bp_fast_tracepoint)
348d480f 12887 fprintf_unfiltered (fp, "ftrace");
d9b3f62e 12888 if (self->type == bp_static_tracepoint)
348d480f 12889 fprintf_unfiltered (fp, "strace");
d9b3f62e 12890 else if (self->type == bp_tracepoint)
348d480f
PA
12891 fprintf_unfiltered (fp, "trace");
12892 else
12893 internal_error (__FILE__, __LINE__,
d9b3f62e 12894 _("unhandled tracepoint type %d"), (int) self->type);
cc59ec59 12895
d9b3f62e
PA
12896 fprintf_unfiltered (fp, " %s", self->addr_string);
12897 print_recreate_thread (self, fp);
12898
12899 if (tp->pass_count)
12900 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count);
a474d7c2
PA
12901}
12902
983af33b
SDJ
12903static void
12904tracepoint_create_sals_from_address (char **arg,
12905 struct linespec_result *canonical,
12906 enum bptype type_wanted,
12907 char *addr_start, char **copy_arg)
12908{
12909 create_sals_from_address_default (arg, canonical, type_wanted,
12910 addr_start, copy_arg);
12911}
12912
12913static void
12914tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
12915 struct linespec_result *canonical,
12916 struct linespec_sals *lsal,
12917 char *cond_string,
e7e0cddf 12918 char *extra_string,
983af33b
SDJ
12919 enum bptype type_wanted,
12920 enum bpdisp disposition,
12921 int thread,
12922 int task, int ignore_count,
12923 const struct breakpoint_ops *ops,
12924 int from_tty, int enabled,
44f238bb 12925 int internal, unsigned flags)
983af33b
SDJ
12926{
12927 create_breakpoints_sal_default (gdbarch, canonical, lsal,
e7e0cddf
SS
12928 cond_string, extra_string,
12929 type_wanted,
983af33b
SDJ
12930 disposition, thread, task,
12931 ignore_count, ops, from_tty,
44f238bb 12932 enabled, internal, flags);
983af33b
SDJ
12933}
12934
12935static void
12936tracepoint_decode_linespec (struct breakpoint *b, char **s,
12937 struct symtabs_and_lines *sals)
12938{
12939 decode_linespec_default (b, s, sals);
12940}
12941
2060206e 12942struct breakpoint_ops tracepoint_breakpoint_ops;
348d480f 12943
55aa24fb
SDJ
12944/* The breakpoint_ops structure to be use on tracepoints placed in a
12945 static probe. */
12946
12947static void
12948tracepoint_probe_create_sals_from_address (char **arg,
12949 struct linespec_result *canonical,
12950 enum bptype type_wanted,
12951 char *addr_start, char **copy_arg)
12952{
12953 /* We use the same method for breakpoint on probes. */
12954 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted,
12955 addr_start, copy_arg);
12956}
12957
12958static void
12959tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
12960 struct symtabs_and_lines *sals)
12961{
12962 /* We use the same method for breakpoint on probes. */
12963 bkpt_probe_decode_linespec (b, s, sals);
12964}
12965
12966static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
12967
983af33b
SDJ
12968/* The breakpoint_ops structure to be used on static tracepoints with
12969 markers (`-m'). */
12970
12971static void
12972strace_marker_create_sals_from_address (char **arg,
12973 struct linespec_result *canonical,
12974 enum bptype type_wanted,
12975 char *addr_start, char **copy_arg)
12976{
12977 struct linespec_sals lsal;
12978
12979 lsal.sals = decode_static_tracepoint_spec (arg);
12980
12981 *copy_arg = savestring (addr_start, *arg - addr_start);
12982
12983 canonical->addr_string = xstrdup (*copy_arg);
12984 lsal.canonical = xstrdup (*copy_arg);
12985 VEC_safe_push (linespec_sals, canonical->sals, &lsal);
12986}
12987
12988static void
12989strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
12990 struct linespec_result *canonical,
12991 struct linespec_sals *lsal,
12992 char *cond_string,
e7e0cddf 12993 char *extra_string,
983af33b
SDJ
12994 enum bptype type_wanted,
12995 enum bpdisp disposition,
12996 int thread,
12997 int task, int ignore_count,
12998 const struct breakpoint_ops *ops,
12999 int from_tty, int enabled,
44f238bb 13000 int internal, unsigned flags)
983af33b
SDJ
13001{
13002 int i;
13003
13004 /* If the user is creating a static tracepoint by marker id
13005 (strace -m MARKER_ID), then store the sals index, so that
13006 breakpoint_re_set can try to match up which of the newly
13007 found markers corresponds to this one, and, don't try to
13008 expand multiple locations for each sal, given than SALS
13009 already should contain all sals for MARKER_ID. */
13010
13011 for (i = 0; i < lsal->sals.nelts; ++i)
13012 {
13013 struct symtabs_and_lines expanded;
13014 struct tracepoint *tp;
13015 struct cleanup *old_chain;
13016 char *addr_string;
13017
13018 expanded.nelts = 1;
13019 expanded.sals = &lsal->sals.sals[i];
13020
13021 addr_string = xstrdup (canonical->addr_string);
13022 old_chain = make_cleanup (xfree, addr_string);
13023
13024 tp = XCNEW (struct tracepoint);
13025 init_breakpoint_sal (&tp->base, gdbarch, expanded,
13026 addr_string, NULL,
e7e0cddf
SS
13027 cond_string, extra_string,
13028 type_wanted, disposition,
983af33b 13029 thread, task, ignore_count, ops,
44f238bb 13030 from_tty, enabled, internal, flags,
983af33b
SDJ
13031 canonical->special_display);
13032 /* Given that its possible to have multiple markers with
13033 the same string id, if the user is creating a static
13034 tracepoint by marker id ("strace -m MARKER_ID"), then
13035 store the sals index, so that breakpoint_re_set can
13036 try to match up which of the newly found markers
13037 corresponds to this one */
13038 tp->static_trace_marker_id_idx = i;
13039
13040 install_breakpoint (internal, &tp->base, 0);
13041
13042 discard_cleanups (old_chain);
13043 }
13044}
13045
13046static void
13047strace_marker_decode_linespec (struct breakpoint *b, char **s,
13048 struct symtabs_and_lines *sals)
13049{
13050 struct tracepoint *tp = (struct tracepoint *) b;
13051
13052 *sals = decode_static_tracepoint_spec (s);
13053 if (sals->nelts > tp->static_trace_marker_id_idx)
13054 {
13055 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
13056 sals->nelts = 1;
13057 }
13058 else
13059 error (_("marker %s not found"), tp->static_trace_marker_id);
13060}
13061
13062static struct breakpoint_ops strace_marker_breakpoint_ops;
13063
13064static int
13065strace_marker_p (struct breakpoint *b)
13066{
13067 return b->ops == &strace_marker_breakpoint_ops;
13068}
13069
53a5351d 13070/* Delete a breakpoint and clean up all traces of it in the data
f431efe5 13071 structures. */
c906108c
SS
13072
13073void
fba45db2 13074delete_breakpoint (struct breakpoint *bpt)
c906108c 13075{
52f0bd74 13076 struct breakpoint *b;
c906108c 13077
8a3fe4f8 13078 gdb_assert (bpt != NULL);
c906108c 13079
4a64f543
MS
13080 /* Has this bp already been deleted? This can happen because
13081 multiple lists can hold pointers to bp's. bpstat lists are
13082 especial culprits.
13083
13084 One example of this happening is a watchpoint's scope bp. When
13085 the scope bp triggers, we notice that the watchpoint is out of
13086 scope, and delete it. We also delete its scope bp. But the
13087 scope bp is marked "auto-deleting", and is already on a bpstat.
13088 That bpstat is then checked for auto-deleting bp's, which are
13089 deleted.
13090
13091 A real solution to this problem might involve reference counts in
13092 bp's, and/or giving them pointers back to their referencing
13093 bpstat's, and teaching delete_breakpoint to only free a bp's
13094 storage when no more references were extent. A cheaper bandaid
13095 was chosen. */
c906108c
SS
13096 if (bpt->type == bp_none)
13097 return;
13098
4a64f543
MS
13099 /* At least avoid this stale reference until the reference counting
13100 of breakpoints gets resolved. */
d0fb5eae 13101 if (bpt->related_breakpoint != bpt)
e5a0a904 13102 {
d0fb5eae 13103 struct breakpoint *related;
3a5c3e22 13104 struct watchpoint *w;
d0fb5eae
JK
13105
13106 if (bpt->type == bp_watchpoint_scope)
3a5c3e22 13107 w = (struct watchpoint *) bpt->related_breakpoint;
d0fb5eae 13108 else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
3a5c3e22
PA
13109 w = (struct watchpoint *) bpt;
13110 else
13111 w = NULL;
13112 if (w != NULL)
13113 watchpoint_del_at_next_stop (w);
d0fb5eae
JK
13114
13115 /* Unlink bpt from the bpt->related_breakpoint ring. */
13116 for (related = bpt; related->related_breakpoint != bpt;
13117 related = related->related_breakpoint);
13118 related->related_breakpoint = bpt->related_breakpoint;
13119 bpt->related_breakpoint = bpt;
e5a0a904
JK
13120 }
13121
a9634178
TJB
13122 /* watch_command_1 creates a watchpoint but only sets its number if
13123 update_watchpoint succeeds in creating its bp_locations. If there's
13124 a problem in that process, we'll be asked to delete the half-created
13125 watchpoint. In that case, don't announce the deletion. */
13126 if (bpt->number)
13127 observer_notify_breakpoint_deleted (bpt);
c906108c 13128
c906108c
SS
13129 if (breakpoint_chain == bpt)
13130 breakpoint_chain = bpt->next;
13131
c906108c
SS
13132 ALL_BREAKPOINTS (b)
13133 if (b->next == bpt)
c5aa993b
JM
13134 {
13135 b->next = bpt->next;
13136 break;
13137 }
c906108c 13138
f431efe5
PA
13139 /* Be sure no bpstat's are pointing at the breakpoint after it's
13140 been freed. */
13141 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
e5dd4106 13142 in all threads for now. Note that we cannot just remove bpstats
f431efe5
PA
13143 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13144 commands are associated with the bpstat; if we remove it here,
13145 then the later call to bpstat_do_actions (&stop_bpstat); in
13146 event-top.c won't do anything, and temporary breakpoints with
13147 commands won't work. */
13148
13149 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
13150
4a64f543
MS
13151 /* Now that breakpoint is removed from breakpoint list, update the
13152 global location list. This will remove locations that used to
13153 belong to this breakpoint. Do this before freeing the breakpoint
13154 itself, since remove_breakpoint looks at location's owner. It
13155 might be better design to have location completely
13156 self-contained, but it's not the case now. */
b60e7edf 13157 update_global_location_list (0);
74960c60 13158
348d480f 13159 bpt->ops->dtor (bpt);
4a64f543
MS
13160 /* On the chance that someone will soon try again to delete this
13161 same bp, we mark it as deleted before freeing its storage. */
c906108c 13162 bpt->type = bp_none;
b8c9b27d 13163 xfree (bpt);
c906108c
SS
13164}
13165
4d6140d9
AC
13166static void
13167do_delete_breakpoint_cleanup (void *b)
13168{
13169 delete_breakpoint (b);
13170}
13171
13172struct cleanup *
13173make_cleanup_delete_breakpoint (struct breakpoint *b)
13174{
13175 return make_cleanup (do_delete_breakpoint_cleanup, b);
13176}
13177
51be5b68
PA
13178/* Iterator function to call a user-provided callback function once
13179 for each of B and its related breakpoints. */
13180
13181static void
13182iterate_over_related_breakpoints (struct breakpoint *b,
13183 void (*function) (struct breakpoint *,
13184 void *),
13185 void *data)
13186{
13187 struct breakpoint *related;
13188
13189 related = b;
13190 do
13191 {
13192 struct breakpoint *next;
13193
13194 /* FUNCTION may delete RELATED. */
13195 next = related->related_breakpoint;
13196
13197 if (next == related)
13198 {
13199 /* RELATED is the last ring entry. */
13200 function (related, data);
13201
13202 /* FUNCTION may have deleted it, so we'd never reach back to
13203 B. There's nothing left to do anyway, so just break
13204 out. */
13205 break;
13206 }
13207 else
13208 function (related, data);
13209
13210 related = next;
13211 }
13212 while (related != b);
13213}
95a42b64
TT
13214
13215static void
13216do_delete_breakpoint (struct breakpoint *b, void *ignore)
13217{
13218 delete_breakpoint (b);
13219}
13220
51be5b68
PA
13221/* A callback for map_breakpoint_numbers that calls
13222 delete_breakpoint. */
13223
13224static void
13225do_map_delete_breakpoint (struct breakpoint *b, void *ignore)
13226{
13227 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL);
13228}
13229
c906108c 13230void
fba45db2 13231delete_command (char *arg, int from_tty)
c906108c 13232{
35df4500 13233 struct breakpoint *b, *b_tmp;
c906108c 13234
ea9365bb
TT
13235 dont_repeat ();
13236
c906108c
SS
13237 if (arg == 0)
13238 {
13239 int breaks_to_delete = 0;
13240
46c6471b
PA
13241 /* Delete all breakpoints if no argument. Do not delete
13242 internal breakpoints, these have to be deleted with an
13243 explicit breakpoint number argument. */
c5aa993b 13244 ALL_BREAKPOINTS (b)
46c6471b 13245 if (user_breakpoint_p (b))
973d738b
DJ
13246 {
13247 breaks_to_delete = 1;
13248 break;
13249 }
c906108c
SS
13250
13251 /* Ask user only if there are some breakpoints to delete. */
13252 if (!from_tty
e2e0b3e5 13253 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
c906108c 13254 {
35df4500 13255 ALL_BREAKPOINTS_SAFE (b, b_tmp)
46c6471b 13256 if (user_breakpoint_p (b))
c5aa993b 13257 delete_breakpoint (b);
c906108c
SS
13258 }
13259 }
13260 else
51be5b68 13261 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
c906108c
SS
13262}
13263
0d381245
VP
13264static int
13265all_locations_are_pending (struct bp_location *loc)
fe3f5fa8 13266{
0d381245 13267 for (; loc; loc = loc->next)
8645ff69
UW
13268 if (!loc->shlib_disabled
13269 && !loc->pspace->executing_startup)
0d381245
VP
13270 return 0;
13271 return 1;
fe3f5fa8
VP
13272}
13273
776592bf
DE
13274/* Subroutine of update_breakpoint_locations to simplify it.
13275 Return non-zero if multiple fns in list LOC have the same name.
13276 Null names are ignored. */
13277
13278static int
13279ambiguous_names_p (struct bp_location *loc)
13280{
13281 struct bp_location *l;
13282 htab_t htab = htab_create_alloc (13, htab_hash_string,
cc59ec59
MS
13283 (int (*) (const void *,
13284 const void *)) streq,
776592bf
DE
13285 NULL, xcalloc, xfree);
13286
13287 for (l = loc; l != NULL; l = l->next)
13288 {
13289 const char **slot;
13290 const char *name = l->function_name;
13291
13292 /* Allow for some names to be NULL, ignore them. */
13293 if (name == NULL)
13294 continue;
13295
13296 slot = (const char **) htab_find_slot (htab, (const void *) name,
13297 INSERT);
4a64f543
MS
13298 /* NOTE: We can assume slot != NULL here because xcalloc never
13299 returns NULL. */
776592bf
DE
13300 if (*slot != NULL)
13301 {
13302 htab_delete (htab);
13303 return 1;
13304 }
13305 *slot = name;
13306 }
13307
13308 htab_delete (htab);
13309 return 0;
13310}
13311
0fb4aa4b
PA
13312/* When symbols change, it probably means the sources changed as well,
13313 and it might mean the static tracepoint markers are no longer at
13314 the same address or line numbers they used to be at last we
13315 checked. Losing your static tracepoints whenever you rebuild is
13316 undesirable. This function tries to resync/rematch gdb static
13317 tracepoints with the markers on the target, for static tracepoints
13318 that have not been set by marker id. Static tracepoint that have
13319 been set by marker id are reset by marker id in breakpoint_re_set.
13320 The heuristic is:
13321
13322 1) For a tracepoint set at a specific address, look for a marker at
13323 the old PC. If one is found there, assume to be the same marker.
13324 If the name / string id of the marker found is different from the
13325 previous known name, assume that means the user renamed the marker
13326 in the sources, and output a warning.
13327
13328 2) For a tracepoint set at a given line number, look for a marker
13329 at the new address of the old line number. If one is found there,
13330 assume to be the same marker. If the name / string id of the
13331 marker found is different from the previous known name, assume that
13332 means the user renamed the marker in the sources, and output a
13333 warning.
13334
13335 3) If a marker is no longer found at the same address or line, it
13336 may mean the marker no longer exists. But it may also just mean
13337 the code changed a bit. Maybe the user added a few lines of code
13338 that made the marker move up or down (in line number terms). Ask
13339 the target for info about the marker with the string id as we knew
13340 it. If found, update line number and address in the matching
13341 static tracepoint. This will get confused if there's more than one
13342 marker with the same ID (possible in UST, although unadvised
13343 precisely because it confuses tools). */
13344
13345static struct symtab_and_line
13346update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
13347{
d9b3f62e 13348 struct tracepoint *tp = (struct tracepoint *) b;
0fb4aa4b
PA
13349 struct static_tracepoint_marker marker;
13350 CORE_ADDR pc;
0fb4aa4b
PA
13351
13352 pc = sal.pc;
13353 if (sal.line)
13354 find_line_pc (sal.symtab, sal.line, &pc);
13355
13356 if (target_static_tracepoint_marker_at (pc, &marker))
13357 {
d9b3f62e 13358 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0)
0fb4aa4b
PA
13359 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13360 b->number,
d9b3f62e 13361 tp->static_trace_marker_id, marker.str_id);
0fb4aa4b 13362
d9b3f62e
PA
13363 xfree (tp->static_trace_marker_id);
13364 tp->static_trace_marker_id = xstrdup (marker.str_id);
0fb4aa4b
PA
13365 release_static_tracepoint_marker (&marker);
13366
13367 return sal;
13368 }
13369
13370 /* Old marker wasn't found on target at lineno. Try looking it up
13371 by string ID. */
13372 if (!sal.explicit_pc
13373 && sal.line != 0
13374 && sal.symtab != NULL
d9b3f62e 13375 && tp->static_trace_marker_id != NULL)
0fb4aa4b
PA
13376 {
13377 VEC(static_tracepoint_marker_p) *markers;
13378
13379 markers
d9b3f62e 13380 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id);
0fb4aa4b
PA
13381
13382 if (!VEC_empty(static_tracepoint_marker_p, markers))
13383 {
80e1d417 13384 struct symtab_and_line sal2;
0fb4aa4b 13385 struct symbol *sym;
80e1d417 13386 struct static_tracepoint_marker *tpmarker;
79a45e25 13387 struct ui_out *uiout = current_uiout;
0fb4aa4b 13388
80e1d417 13389 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
0fb4aa4b 13390
d9b3f62e 13391 xfree (tp->static_trace_marker_id);
80e1d417 13392 tp->static_trace_marker_id = xstrdup (tpmarker->str_id);
0fb4aa4b
PA
13393
13394 warning (_("marker for static tracepoint %d (%s) not "
13395 "found at previous line number"),
d9b3f62e 13396 b->number, tp->static_trace_marker_id);
0fb4aa4b 13397
80e1d417 13398 init_sal (&sal2);
0fb4aa4b 13399
80e1d417 13400 sal2.pc = tpmarker->address;
0fb4aa4b 13401
80e1d417
AS
13402 sal2 = find_pc_line (tpmarker->address, 0);
13403 sym = find_pc_sect_function (tpmarker->address, NULL);
0fb4aa4b
PA
13404 ui_out_text (uiout, "Now in ");
13405 if (sym)
13406 {
13407 ui_out_field_string (uiout, "func",
13408 SYMBOL_PRINT_NAME (sym));
13409 ui_out_text (uiout, " at ");
13410 }
80e1d417 13411 ui_out_field_string (uiout, "file", sal2.symtab->filename);
0fb4aa4b
PA
13412 ui_out_text (uiout, ":");
13413
13414 if (ui_out_is_mi_like_p (uiout))
13415 {
80e1d417 13416 char *fullname = symtab_to_fullname (sal2.symtab);
0fb4aa4b
PA
13417
13418 if (fullname)
13419 ui_out_field_string (uiout, "fullname", fullname);
13420 }
13421
80e1d417 13422 ui_out_field_int (uiout, "line", sal2.line);
0fb4aa4b
PA
13423 ui_out_text (uiout, "\n");
13424
80e1d417 13425 b->loc->line_number = sal2.line;
0fb4aa4b 13426
f8eba3c6 13427 xfree (b->loc->source_file);
0fb4aa4b 13428 if (sym)
80e1d417 13429 b->loc->source_file = xstrdup (sal2.symtab->filename);
0fb4aa4b 13430 else
f8eba3c6 13431 b->loc->source_file = NULL;
0fb4aa4b
PA
13432
13433 xfree (b->addr_string);
13434 b->addr_string = xstrprintf ("%s:%d",
80e1d417 13435 sal2.symtab->filename,
f8eba3c6 13436 b->loc->line_number);
0fb4aa4b
PA
13437
13438 /* Might be nice to check if function changed, and warn if
13439 so. */
13440
80e1d417 13441 release_static_tracepoint_marker (tpmarker);
0fb4aa4b
PA
13442 }
13443 }
13444 return sal;
13445}
13446
8d3788bd
VP
13447/* Returns 1 iff locations A and B are sufficiently same that
13448 we don't need to report breakpoint as changed. */
13449
13450static int
13451locations_are_equal (struct bp_location *a, struct bp_location *b)
13452{
13453 while (a && b)
13454 {
13455 if (a->address != b->address)
13456 return 0;
13457
13458 if (a->shlib_disabled != b->shlib_disabled)
13459 return 0;
13460
13461 if (a->enabled != b->enabled)
13462 return 0;
13463
13464 a = a->next;
13465 b = b->next;
13466 }
13467
13468 if ((a == NULL) != (b == NULL))
13469 return 0;
13470
13471 return 1;
13472}
13473
f1310107
TJB
13474/* Create new breakpoint locations for B (a hardware or software breakpoint)
13475 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13476 a ranged breakpoint. */
13477
0e30163f 13478void
0d381245 13479update_breakpoint_locations (struct breakpoint *b,
f1310107
TJB
13480 struct symtabs_and_lines sals,
13481 struct symtabs_and_lines sals_end)
fe3f5fa8
VP
13482{
13483 int i;
0d381245
VP
13484 struct bp_location *existing_locations = b->loc;
13485
f8eba3c6
TT
13486 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1))
13487 {
13488 /* Ranged breakpoints have only one start location and one end
13489 location. */
13490 b->enable_state = bp_disabled;
13491 update_global_location_list (1);
13492 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13493 "multiple locations found\n"),
13494 b->number);
13495 return;
13496 }
f1310107 13497
4a64f543
MS
13498 /* If there's no new locations, and all existing locations are
13499 pending, don't do anything. This optimizes the common case where
13500 all locations are in the same shared library, that was unloaded.
13501 We'd like to retain the location, so that when the library is
13502 loaded again, we don't loose the enabled/disabled status of the
13503 individual locations. */
0d381245 13504 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
fe3f5fa8
VP
13505 return;
13506
fe3f5fa8
VP
13507 b->loc = NULL;
13508
0d381245 13509 for (i = 0; i < sals.nelts; ++i)
fe3f5fa8 13510 {
f8eba3c6
TT
13511 struct bp_location *new_loc;
13512
13513 switch_to_program_space_and_thread (sals.sals[i].pspace);
13514
13515 new_loc = add_location_to_breakpoint (b, &(sals.sals[i]));
fe3f5fa8 13516
0d381245
VP
13517 /* Reparse conditions, they might contain references to the
13518 old symtab. */
13519 if (b->cond_string != NULL)
13520 {
f1310107 13521 char *s;
bfd189b1 13522 volatile struct gdb_exception e;
fe3f5fa8 13523
0d381245
VP
13524 s = b->cond_string;
13525 TRY_CATCH (e, RETURN_MASK_ERROR)
13526 {
13527 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
13528 0);
13529 }
13530 if (e.reason < 0)
13531 {
3e43a32a
MS
13532 warning (_("failed to reevaluate condition "
13533 "for breakpoint %d: %s"),
0d381245
VP
13534 b->number, e.message);
13535 new_loc->enabled = 0;
13536 }
13537 }
fe3f5fa8 13538
f1310107
TJB
13539 if (sals_end.nelts)
13540 {
13541 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]);
13542
13543 new_loc->length = end - sals.sals[0].pc + 1;
13544 }
0d381245 13545 }
fe3f5fa8 13546
514f746b
AR
13547 /* Update locations of permanent breakpoints. */
13548 if (b->enable_state == bp_permanent)
13549 make_breakpoint_permanent (b);
13550
4a64f543
MS
13551 /* If possible, carry over 'disable' status from existing
13552 breakpoints. */
0d381245
VP
13553 {
13554 struct bp_location *e = existing_locations;
776592bf
DE
13555 /* If there are multiple breakpoints with the same function name,
13556 e.g. for inline functions, comparing function names won't work.
13557 Instead compare pc addresses; this is just a heuristic as things
13558 may have moved, but in practice it gives the correct answer
13559 often enough until a better solution is found. */
13560 int have_ambiguous_names = ambiguous_names_p (b->loc);
13561
0d381245
VP
13562 for (; e; e = e->next)
13563 {
13564 if (!e->enabled && e->function_name)
13565 {
13566 struct bp_location *l = b->loc;
776592bf
DE
13567 if (have_ambiguous_names)
13568 {
13569 for (; l; l = l->next)
f1310107 13570 if (breakpoint_locations_match (e, l))
776592bf
DE
13571 {
13572 l->enabled = 0;
13573 break;
13574 }
13575 }
13576 else
13577 {
13578 for (; l; l = l->next)
13579 if (l->function_name
13580 && strcmp (e->function_name, l->function_name) == 0)
13581 {
13582 l->enabled = 0;
13583 break;
13584 }
13585 }
0d381245
VP
13586 }
13587 }
13588 }
fe3f5fa8 13589
8d3788bd
VP
13590 if (!locations_are_equal (existing_locations, b->loc))
13591 observer_notify_breakpoint_modified (b);
13592
b60e7edf 13593 update_global_location_list (1);
fe3f5fa8
VP
13594}
13595
ef23e705
TJB
13596/* Find the SaL locations corresponding to the given ADDR_STRING.
13597 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13598
13599static struct symtabs_and_lines
13600addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
13601{
13602 char *s;
02d20e4a 13603 struct symtabs_and_lines sals = {0};
f8eba3c6 13604 volatile struct gdb_exception e;
ef23e705 13605
983af33b 13606 gdb_assert (b->ops != NULL);
ef23e705 13607 s = addr_string;
ef23e705
TJB
13608
13609 TRY_CATCH (e, RETURN_MASK_ERROR)
13610 {
983af33b 13611 b->ops->decode_linespec (b, &s, &sals);
ef23e705
TJB
13612 }
13613 if (e.reason < 0)
13614 {
13615 int not_found_and_ok = 0;
13616 /* For pending breakpoints, it's expected that parsing will
13617 fail until the right shared library is loaded. User has
13618 already told to create pending breakpoints and don't need
13619 extra messages. If breakpoint is in bp_shlib_disabled
13620 state, then user already saw the message about that
13621 breakpoint being disabled, and don't want to see more
13622 errors. */
58438ac1 13623 if (e.error == NOT_FOUND_ERROR
ef23e705
TJB
13624 && (b->condition_not_parsed
13625 || (b->loc && b->loc->shlib_disabled)
f8eba3c6 13626 || (b->loc && b->loc->pspace->executing_startup)
ef23e705
TJB
13627 || b->enable_state == bp_disabled))
13628 not_found_and_ok = 1;
13629
13630 if (!not_found_and_ok)
13631 {
13632 /* We surely don't want to warn about the same breakpoint
13633 10 times. One solution, implemented here, is disable
13634 the breakpoint on error. Another solution would be to
13635 have separate 'warning emitted' flag. Since this
13636 happens only when a binary has changed, I don't know
13637 which approach is better. */
13638 b->enable_state = bp_disabled;
13639 throw_exception (e);
13640 }
13641 }
13642
58438ac1 13643 if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
ef23e705 13644 {
f8eba3c6 13645 int i;
ef23e705 13646
f8eba3c6
TT
13647 for (i = 0; i < sals.nelts; ++i)
13648 resolve_sal_pc (&sals.sals[i]);
ef23e705
TJB
13649 if (b->condition_not_parsed && s && s[0])
13650 {
13651 char *cond_string = 0;
13652 int thread = -1;
13653 int task = 0;
e7e0cddf 13654 char *extra_string = NULL;
ef23e705
TJB
13655
13656 find_condition_and_thread (s, sals.sals[0].pc,
e7e0cddf
SS
13657 &cond_string, &thread, &task,
13658 &extra_string);
ef23e705
TJB
13659 if (cond_string)
13660 b->cond_string = cond_string;
13661 b->thread = thread;
13662 b->task = task;
e7e0cddf
SS
13663 if (extra_string)
13664 b->extra_string = extra_string;
ef23e705
TJB
13665 b->condition_not_parsed = 0;
13666 }
13667
983af33b 13668 if (b->type == bp_static_tracepoint && !strace_marker_p (b))
ef23e705 13669 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]);
ef23e705 13670
58438ac1
TT
13671 *found = 1;
13672 }
13673 else
13674 *found = 0;
ef23e705
TJB
13675
13676 return sals;
13677}
13678
348d480f
PA
13679/* The default re_set method, for typical hardware or software
13680 breakpoints. Reevaluate the breakpoint and recreate its
13681 locations. */
13682
13683static void
28010a5d 13684breakpoint_re_set_default (struct breakpoint *b)
ef23e705
TJB
13685{
13686 int found;
f1310107 13687 struct symtabs_and_lines sals, sals_end;
ef23e705 13688 struct symtabs_and_lines expanded = {0};
f1310107 13689 struct symtabs_and_lines expanded_end = {0};
ef23e705
TJB
13690
13691 sals = addr_string_to_sals (b, b->addr_string, &found);
13692 if (found)
13693 {
13694 make_cleanup (xfree, sals.sals);
f8eba3c6 13695 expanded = sals;
ef23e705
TJB
13696 }
13697
f1310107
TJB
13698 if (b->addr_string_range_end)
13699 {
13700 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found);
13701 if (found)
13702 {
13703 make_cleanup (xfree, sals_end.sals);
f8eba3c6 13704 expanded_end = sals_end;
f1310107
TJB
13705 }
13706 }
13707
13708 update_breakpoint_locations (b, expanded, expanded_end);
28010a5d
PA
13709}
13710
983af33b
SDJ
13711/* Default method for creating SALs from an address string. It basically
13712 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13713
13714static void
13715create_sals_from_address_default (char **arg,
13716 struct linespec_result *canonical,
13717 enum bptype type_wanted,
13718 char *addr_start, char **copy_arg)
13719{
13720 parse_breakpoint_sals (arg, canonical);
13721}
13722
13723/* Call create_breakpoints_sal for the given arguments. This is the default
13724 function for the `create_breakpoints_sal' method of
13725 breakpoint_ops. */
13726
13727static void
13728create_breakpoints_sal_default (struct gdbarch *gdbarch,
13729 struct linespec_result *canonical,
13730 struct linespec_sals *lsal,
13731 char *cond_string,
e7e0cddf 13732 char *extra_string,
983af33b
SDJ
13733 enum bptype type_wanted,
13734 enum bpdisp disposition,
13735 int thread,
13736 int task, int ignore_count,
13737 const struct breakpoint_ops *ops,
13738 int from_tty, int enabled,
44f238bb 13739 int internal, unsigned flags)
983af33b
SDJ
13740{
13741 create_breakpoints_sal (gdbarch, canonical, cond_string,
e7e0cddf 13742 extra_string,
983af33b
SDJ
13743 type_wanted, disposition,
13744 thread, task, ignore_count, ops, from_tty,
44f238bb 13745 enabled, internal, flags);
983af33b
SDJ
13746}
13747
13748/* Decode the line represented by S by calling decode_line_full. This is the
13749 default function for the `decode_linespec' method of breakpoint_ops. */
13750
13751static void
13752decode_linespec_default (struct breakpoint *b, char **s,
13753 struct symtabs_and_lines *sals)
13754{
13755 struct linespec_result canonical;
13756
13757 init_linespec_result (&canonical);
13758 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
13759 (struct symtab *) NULL, 0,
13760 &canonical, multiple_symbols_all,
13761 b->filter);
13762
13763 /* We should get 0 or 1 resulting SALs. */
13764 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2);
13765
13766 if (VEC_length (linespec_sals, canonical.sals) > 0)
13767 {
13768 struct linespec_sals *lsal;
13769
13770 lsal = VEC_index (linespec_sals, canonical.sals, 0);
13771 *sals = lsal->sals;
13772 /* Arrange it so the destructor does not free the
13773 contents. */
13774 lsal->sals.sals = NULL;
13775 }
13776
13777 destroy_linespec_result (&canonical);
13778}
13779
28010a5d
PA
13780/* Prepare the global context for a re-set of breakpoint B. */
13781
13782static struct cleanup *
13783prepare_re_set_context (struct breakpoint *b)
13784{
13785 struct cleanup *cleanups;
13786
13787 input_radix = b->input_radix;
13788 cleanups = save_current_space_and_thread ();
f8eba3c6
TT
13789 if (b->pspace != NULL)
13790 switch_to_program_space_and_thread (b->pspace);
28010a5d
PA
13791 set_language (b->language);
13792
13793 return cleanups;
ef23e705
TJB
13794}
13795
c906108c
SS
13796/* Reset a breakpoint given it's struct breakpoint * BINT.
13797 The value we return ends up being the return value from catch_errors.
13798 Unused in this case. */
13799
13800static int
4efb68b1 13801breakpoint_re_set_one (void *bint)
c906108c 13802{
4a64f543 13803 /* Get past catch_errs. */
53a5351d 13804 struct breakpoint *b = (struct breakpoint *) bint;
348d480f 13805 struct cleanup *cleanups;
c906108c 13806
348d480f
PA
13807 cleanups = prepare_re_set_context (b);
13808 b->ops->re_set (b);
13809 do_cleanups (cleanups);
c906108c
SS
13810 return 0;
13811}
13812
69de3c6a 13813/* Re-set all breakpoints after symbols have been re-loaded. */
c906108c 13814void
69de3c6a 13815breakpoint_re_set (void)
c906108c 13816{
35df4500 13817 struct breakpoint *b, *b_tmp;
c906108c
SS
13818 enum language save_language;
13819 int save_input_radix;
6c95b8df 13820 struct cleanup *old_chain;
c5aa993b 13821
c906108c
SS
13822 save_language = current_language->la_language;
13823 save_input_radix = input_radix;
6c95b8df
PA
13824 old_chain = save_current_program_space ();
13825
35df4500 13826 ALL_BREAKPOINTS_SAFE (b, b_tmp)
c5aa993b 13827 {
4a64f543 13828 /* Format possible error msg. */
fe3f5fa8 13829 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
9ebf4acf
AC
13830 b->number);
13831 struct cleanup *cleanups = make_cleanup (xfree, message);
c5aa993b 13832 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
9ebf4acf 13833 do_cleanups (cleanups);
c5aa993b 13834 }
c906108c
SS
13835 set_language (save_language);
13836 input_radix = save_input_radix;
e62c965a 13837
0756c555 13838 jit_breakpoint_re_set ();
4efc6507 13839
6c95b8df
PA
13840 do_cleanups (old_chain);
13841
af02033e
PP
13842 create_overlay_event_breakpoint ();
13843 create_longjmp_master_breakpoint ();
13844 create_std_terminate_master_breakpoint ();
186c406b 13845 create_exception_master_breakpoint ();
1bfeeb0f
JL
13846
13847 /* While we're at it, reset the skip list too. */
13848 skip_re_set ();
c906108c
SS
13849}
13850\f
c906108c
SS
13851/* Reset the thread number of this breakpoint:
13852
13853 - If the breakpoint is for all threads, leave it as-is.
4a64f543 13854 - Else, reset it to the current thread for inferior_ptid. */
c906108c 13855void
fba45db2 13856breakpoint_re_set_thread (struct breakpoint *b)
c906108c
SS
13857{
13858 if (b->thread != -1)
13859 {
39f77062
KB
13860 if (in_thread_list (inferior_ptid))
13861 b->thread = pid_to_thread_id (inferior_ptid);
6c95b8df
PA
13862
13863 /* We're being called after following a fork. The new fork is
13864 selected as current, and unless this was a vfork will have a
13865 different program space from the original thread. Reset that
13866 as well. */
13867 b->loc->pspace = current_program_space;
c906108c
SS
13868 }
13869}
13870
03ac34d5
MS
13871/* Set ignore-count of breakpoint number BPTNUM to COUNT.
13872 If from_tty is nonzero, it prints a message to that effect,
13873 which ends with a period (no newline). */
13874
c906108c 13875void
fba45db2 13876set_ignore_count (int bptnum, int count, int from_tty)
c906108c 13877{
52f0bd74 13878 struct breakpoint *b;
c906108c
SS
13879
13880 if (count < 0)
13881 count = 0;
13882
13883 ALL_BREAKPOINTS (b)
13884 if (b->number == bptnum)
c5aa993b 13885 {
d77f58be
SS
13886 if (is_tracepoint (b))
13887 {
13888 if (from_tty && count != 0)
13889 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13890 bptnum);
13891 return;
13892 }
13893
c5aa993b 13894 b->ignore_count = count;
221ea385
KS
13895 if (from_tty)
13896 {
13897 if (count == 0)
3e43a32a
MS
13898 printf_filtered (_("Will stop next time "
13899 "breakpoint %d is reached."),
221ea385
KS
13900 bptnum);
13901 else if (count == 1)
a3f17187 13902 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
221ea385
KS
13903 bptnum);
13904 else
3e43a32a
MS
13905 printf_filtered (_("Will ignore next %d "
13906 "crossings of breakpoint %d."),
221ea385
KS
13907 count, bptnum);
13908 }
c5aa993b 13909 breakpoints_changed ();
8d3788bd 13910 observer_notify_breakpoint_modified (b);
c5aa993b
JM
13911 return;
13912 }
c906108c 13913
8a3fe4f8 13914 error (_("No breakpoint number %d."), bptnum);
c906108c
SS
13915}
13916
c906108c
SS
13917/* Command to set ignore-count of breakpoint N to COUNT. */
13918
13919static void
fba45db2 13920ignore_command (char *args, int from_tty)
c906108c
SS
13921{
13922 char *p = args;
52f0bd74 13923 int num;
c906108c
SS
13924
13925 if (p == 0)
e2e0b3e5 13926 error_no_arg (_("a breakpoint number"));
c5aa993b 13927
c906108c 13928 num = get_number (&p);
5c44784c 13929 if (num == 0)
8a3fe4f8 13930 error (_("bad breakpoint number: '%s'"), args);
c906108c 13931 if (*p == 0)
8a3fe4f8 13932 error (_("Second argument (specified ignore-count) is missing."));
c906108c
SS
13933
13934 set_ignore_count (num,
13935 longest_to_int (value_as_long (parse_and_eval (p))),
13936 from_tty);
221ea385
KS
13937 if (from_tty)
13938 printf_filtered ("\n");
c906108c
SS
13939}
13940\f
13941/* Call FUNCTION on each of the breakpoints
13942 whose numbers are given in ARGS. */
13943
13944static void
95a42b64
TT
13945map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
13946 void *),
13947 void *data)
c906108c 13948{
52f0bd74
AC
13949 int num;
13950 struct breakpoint *b, *tmp;
11cf8741 13951 int match;
197f0a60 13952 struct get_number_or_range_state state;
c906108c 13953
197f0a60 13954 if (args == 0)
e2e0b3e5 13955 error_no_arg (_("one or more breakpoint numbers"));
c906108c 13956
197f0a60
TT
13957 init_number_or_range (&state, args);
13958
13959 while (!state.finished)
c906108c 13960 {
197f0a60
TT
13961 char *p = state.string;
13962
11cf8741 13963 match = 0;
c5aa993b 13964
197f0a60 13965 num = get_number_or_range (&state);
5c44784c 13966 if (num == 0)
c5aa993b 13967 {
8a3fe4f8 13968 warning (_("bad breakpoint number at or near '%s'"), p);
5c44784c
JM
13969 }
13970 else
13971 {
13972 ALL_BREAKPOINTS_SAFE (b, tmp)
13973 if (b->number == num)
13974 {
11cf8741 13975 match = 1;
cdac0397 13976 function (b, data);
11cf8741 13977 break;
5c44784c 13978 }
11cf8741 13979 if (match == 0)
a3f17187 13980 printf_unfiltered (_("No breakpoint number %d.\n"), num);
c5aa993b 13981 }
c906108c
SS
13982 }
13983}
13984
0d381245
VP
13985static struct bp_location *
13986find_location_by_number (char *number)
13987{
13988 char *dot = strchr (number, '.');
13989 char *p1;
13990 int bp_num;
13991 int loc_num;
13992 struct breakpoint *b;
13993 struct bp_location *loc;
13994
13995 *dot = '\0';
13996
13997 p1 = number;
197f0a60 13998 bp_num = get_number (&p1);
0d381245
VP
13999 if (bp_num == 0)
14000 error (_("Bad breakpoint number '%s'"), number);
14001
14002 ALL_BREAKPOINTS (b)
14003 if (b->number == bp_num)
14004 {
14005 break;
14006 }
14007
14008 if (!b || b->number != bp_num)
14009 error (_("Bad breakpoint number '%s'"), number);
14010
14011 p1 = dot+1;
197f0a60 14012 loc_num = get_number (&p1);
0d381245
VP
14013 if (loc_num == 0)
14014 error (_("Bad breakpoint location number '%s'"), number);
14015
14016 --loc_num;
14017 loc = b->loc;
14018 for (;loc_num && loc; --loc_num, loc = loc->next)
14019 ;
14020 if (!loc)
14021 error (_("Bad breakpoint location number '%s'"), dot+1);
14022
14023 return loc;
14024}
14025
14026
1900040c
MS
14027/* Set ignore-count of breakpoint number BPTNUM to COUNT.
14028 If from_tty is nonzero, it prints a message to that effect,
14029 which ends with a period (no newline). */
14030
c906108c 14031void
fba45db2 14032disable_breakpoint (struct breakpoint *bpt)
c906108c
SS
14033{
14034 /* Never disable a watchpoint scope breakpoint; we want to
14035 hit them when we leave scope so we can delete both the
14036 watchpoint and its scope breakpoint at that time. */
14037 if (bpt->type == bp_watchpoint_scope)
14038 return;
14039
c2c6d25f 14040 /* You can't disable permanent breakpoints. */
b5de0fa7 14041 if (bpt->enable_state == bp_permanent)
c2c6d25f
JM
14042 return;
14043
b5de0fa7 14044 bpt->enable_state = bp_disabled;
c906108c 14045
b775012e
LM
14046 /* Mark breakpoint locations modified. */
14047 mark_breakpoint_modified (bpt);
14048
d248b706
KY
14049 if (target_supports_enable_disable_tracepoint ()
14050 && current_trace_status ()->running && is_tracepoint (bpt))
14051 {
14052 struct bp_location *location;
14053
14054 for (location = bpt->loc; location; location = location->next)
14055 target_disable_tracepoint (location);
14056 }
14057
b60e7edf 14058 update_global_location_list (0);
c906108c 14059
8d3788bd 14060 observer_notify_breakpoint_modified (bpt);
c906108c
SS
14061}
14062
51be5b68
PA
14063/* A callback for iterate_over_related_breakpoints. */
14064
14065static void
14066do_disable_breakpoint (struct breakpoint *b, void *ignore)
14067{
14068 disable_breakpoint (b);
14069}
14070
95a42b64
TT
14071/* A callback for map_breakpoint_numbers that calls
14072 disable_breakpoint. */
14073
14074static void
14075do_map_disable_breakpoint (struct breakpoint *b, void *ignore)
14076{
51be5b68 14077 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL);
95a42b64
TT
14078}
14079
c906108c 14080static void
fba45db2 14081disable_command (char *args, int from_tty)
c906108c 14082{
c906108c 14083 if (args == 0)
46c6471b
PA
14084 {
14085 struct breakpoint *bpt;
14086
14087 ALL_BREAKPOINTS (bpt)
14088 if (user_breakpoint_p (bpt))
14089 disable_breakpoint (bpt);
14090 }
0d381245
VP
14091 else if (strchr (args, '.'))
14092 {
14093 struct bp_location *loc = find_location_by_number (args);
14094 if (loc)
d248b706 14095 {
b775012e
LM
14096 if (loc->enabled)
14097 {
14098 loc->enabled = 0;
14099 mark_breakpoint_location_modified (loc);
14100 }
d248b706
KY
14101 if (target_supports_enable_disable_tracepoint ()
14102 && current_trace_status ()->running && loc->owner
14103 && is_tracepoint (loc->owner))
14104 target_disable_tracepoint (loc);
14105 }
b60e7edf 14106 update_global_location_list (0);
0d381245 14107 }
c906108c 14108 else
95a42b64 14109 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL);
c906108c
SS
14110}
14111
14112static void
816338b5
SS
14113enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
14114 int count)
c906108c 14115{
afe38095 14116 int target_resources_ok;
c906108c
SS
14117
14118 if (bpt->type == bp_hardware_breakpoint)
14119 {
14120 int i;
c5aa993b 14121 i = hw_breakpoint_used_count ();
53a5351d 14122 target_resources_ok =
d92524f1 14123 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
53a5351d 14124 i + 1, 0);
c906108c 14125 if (target_resources_ok == 0)
8a3fe4f8 14126 error (_("No hardware breakpoint support in the target."));
c906108c 14127 else if (target_resources_ok < 0)
8a3fe4f8 14128 error (_("Hardware breakpoints used exceeds limit."));
c906108c
SS
14129 }
14130
cc60f2e3 14131 if (is_watchpoint (bpt))
c906108c 14132 {
d07205c2
JK
14133 /* Initialize it just to avoid a GCC false warning. */
14134 enum enable_state orig_enable_state = 0;
bfd189b1 14135 volatile struct gdb_exception e;
dde02812
ES
14136
14137 TRY_CATCH (e, RETURN_MASK_ALL)
c906108c 14138 {
3a5c3e22
PA
14139 struct watchpoint *w = (struct watchpoint *) bpt;
14140
1e718ff1
TJB
14141 orig_enable_state = bpt->enable_state;
14142 bpt->enable_state = bp_enabled;
3a5c3e22 14143 update_watchpoint (w, 1 /* reparse */);
c906108c 14144 }
dde02812 14145 if (e.reason < 0)
c5aa993b 14146 {
1e718ff1 14147 bpt->enable_state = orig_enable_state;
dde02812
ES
14148 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
14149 bpt->number);
14150 return;
c5aa993b 14151 }
c906108c 14152 }
0101ce28 14153
b4c291bb
KH
14154 if (bpt->enable_state != bp_permanent)
14155 bpt->enable_state = bp_enabled;
d248b706 14156
b775012e
LM
14157 bpt->enable_state = bp_enabled;
14158
14159 /* Mark breakpoint locations modified. */
14160 mark_breakpoint_modified (bpt);
14161
d248b706
KY
14162 if (target_supports_enable_disable_tracepoint ()
14163 && current_trace_status ()->running && is_tracepoint (bpt))
14164 {
14165 struct bp_location *location;
14166
14167 for (location = bpt->loc; location; location = location->next)
14168 target_enable_tracepoint (location);
14169 }
14170
b4c291bb 14171 bpt->disposition = disposition;
816338b5 14172 bpt->enable_count = count;
b60e7edf 14173 update_global_location_list (1);
b4c291bb
KH
14174 breakpoints_changed ();
14175
8d3788bd 14176 observer_notify_breakpoint_modified (bpt);
c906108c
SS
14177}
14178
fe3f5fa8 14179
c906108c 14180void
fba45db2 14181enable_breakpoint (struct breakpoint *bpt)
c906108c 14182{
816338b5 14183 enable_breakpoint_disp (bpt, bpt->disposition, 0);
51be5b68
PA
14184}
14185
14186static void
14187do_enable_breakpoint (struct breakpoint *bpt, void *arg)
14188{
14189 enable_breakpoint (bpt);
c906108c
SS
14190}
14191
95a42b64
TT
14192/* A callback for map_breakpoint_numbers that calls
14193 enable_breakpoint. */
14194
14195static void
14196do_map_enable_breakpoint (struct breakpoint *b, void *ignore)
14197{
51be5b68 14198 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL);
95a42b64
TT
14199}
14200
c906108c
SS
14201/* The enable command enables the specified breakpoints (or all defined
14202 breakpoints) so they once again become (or continue to be) effective
1272ad14 14203 in stopping the inferior. */
c906108c 14204
c906108c 14205static void
fba45db2 14206enable_command (char *args, int from_tty)
c906108c 14207{
c906108c 14208 if (args == 0)
46c6471b
PA
14209 {
14210 struct breakpoint *bpt;
14211
14212 ALL_BREAKPOINTS (bpt)
14213 if (user_breakpoint_p (bpt))
14214 enable_breakpoint (bpt);
14215 }
0d381245
VP
14216 else if (strchr (args, '.'))
14217 {
14218 struct bp_location *loc = find_location_by_number (args);
14219 if (loc)
d248b706 14220 {
b775012e
LM
14221 if (!loc->enabled)
14222 {
14223 loc->enabled = 1;
14224 mark_breakpoint_location_modified (loc);
14225 }
d248b706
KY
14226 if (target_supports_enable_disable_tracepoint ()
14227 && current_trace_status ()->running && loc->owner
14228 && is_tracepoint (loc->owner))
14229 target_enable_tracepoint (loc);
14230 }
b60e7edf 14231 update_global_location_list (1);
0d381245 14232 }
c906108c 14233 else
95a42b64 14234 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL);
c906108c
SS
14235}
14236
816338b5
SS
14237/* This struct packages up disposition data for application to multiple
14238 breakpoints. */
14239
14240struct disp_data
14241{
14242 enum bpdisp disp;
14243 int count;
14244};
14245
c906108c 14246static void
51be5b68
PA
14247do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg)
14248{
816338b5 14249 struct disp_data disp_data = *(struct disp_data *) arg;
51be5b68 14250
816338b5 14251 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count);
51be5b68
PA
14252}
14253
14254static void
14255do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore)
c906108c 14256{
816338b5 14257 struct disp_data disp = { disp_disable, 1 };
51be5b68
PA
14258
14259 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
c906108c
SS
14260}
14261
c906108c 14262static void
fba45db2 14263enable_once_command (char *args, int from_tty)
c906108c 14264{
51be5b68 14265 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL);
c906108c
SS
14266}
14267
816338b5
SS
14268static void
14269do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
14270{
14271 struct disp_data disp = { disp_disable, *(int *) countptr };
14272
14273 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
14274}
14275
14276static void
14277enable_count_command (char *args, int from_tty)
14278{
14279 int count = get_number (&args);
14280
14281 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
14282}
14283
c906108c 14284static void
51be5b68 14285do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore)
c906108c 14286{
816338b5 14287 struct disp_data disp = { disp_del, 1 };
51be5b68
PA
14288
14289 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp);
c906108c
SS
14290}
14291
c906108c 14292static void
fba45db2 14293enable_delete_command (char *args, int from_tty)
c906108c 14294{
51be5b68 14295 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL);
c906108c
SS
14296}
14297\f
fa8d40ab
JJ
14298static void
14299set_breakpoint_cmd (char *args, int from_tty)
14300{
14301}
14302
14303static void
14304show_breakpoint_cmd (char *args, int from_tty)
14305{
14306}
14307
1f3b5d1b
PP
14308/* Invalidate last known value of any hardware watchpoint if
14309 the memory which that value represents has been written to by
14310 GDB itself. */
14311
14312static void
14313invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len,
14314 const bfd_byte *data)
14315{
14316 struct breakpoint *bp;
14317
14318 ALL_BREAKPOINTS (bp)
14319 if (bp->enable_state == bp_enabled
3a5c3e22 14320 && bp->type == bp_hardware_watchpoint)
1f3b5d1b 14321 {
3a5c3e22 14322 struct watchpoint *wp = (struct watchpoint *) bp;
1f3b5d1b 14323
3a5c3e22
PA
14324 if (wp->val_valid && wp->val)
14325 {
14326 struct bp_location *loc;
14327
14328 for (loc = bp->loc; loc != NULL; loc = loc->next)
14329 if (loc->loc_type == bp_loc_hardware_watchpoint
14330 && loc->address + loc->length > addr
14331 && addr + len > loc->address)
14332 {
14333 value_free (wp->val);
14334 wp->val = NULL;
14335 wp->val_valid = 0;
14336 }
14337 }
1f3b5d1b
PP
14338 }
14339}
14340
1bfeeb0f
JL
14341/* Use the last displayed codepoint's values, or nothing
14342 if they aren't valid. */
c906108c
SS
14343
14344struct symtabs_and_lines
f8eba3c6 14345decode_line_spec_1 (char *string, int flags)
c906108c
SS
14346{
14347 struct symtabs_and_lines sals;
cc59ec59 14348
c906108c 14349 if (string == 0)
8a3fe4f8 14350 error (_("Empty line specification."));
1bfeeb0f 14351 if (last_displayed_sal_is_valid ())
f8eba3c6 14352 sals = decode_line_1 (&string, flags,
1bfeeb0f 14353 get_last_displayed_symtab (),
f8eba3c6 14354 get_last_displayed_line ());
c906108c 14355 else
f8eba3c6 14356 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
c906108c 14357 if (*string)
8a3fe4f8 14358 error (_("Junk at end of line specification: %s"), string);
c906108c
SS
14359 return sals;
14360}
8181d85f
DJ
14361
14362/* Create and insert a raw software breakpoint at PC. Return an
14363 identifier, which should be used to remove the breakpoint later.
14364 In general, places which call this should be using something on the
14365 breakpoint chain instead; this function should be eliminated
14366 someday. */
14367
14368void *
6c95b8df
PA
14369deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch,
14370 struct address_space *aspace, CORE_ADDR pc)
8181d85f
DJ
14371{
14372 struct bp_target_info *bp_tgt;
14373
6c95b8df 14374 bp_tgt = XZALLOC (struct bp_target_info);
8181d85f 14375
6c95b8df 14376 bp_tgt->placed_address_space = aspace;
8181d85f 14377 bp_tgt->placed_address = pc;
6c95b8df 14378
a6d9a66e 14379 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0)
8181d85f
DJ
14380 {
14381 /* Could not insert the breakpoint. */
14382 xfree (bp_tgt);
14383 return NULL;
14384 }
14385
14386 return bp_tgt;
14387}
14388
4a64f543
MS
14389/* Remove a breakpoint BP inserted by
14390 deprecated_insert_raw_breakpoint. */
8181d85f
DJ
14391
14392int
a6d9a66e 14393deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp)
8181d85f
DJ
14394{
14395 struct bp_target_info *bp_tgt = bp;
14396 int ret;
14397
a6d9a66e 14398 ret = target_remove_breakpoint (gdbarch, bp_tgt);
8181d85f
DJ
14399 xfree (bp_tgt);
14400
14401 return ret;
14402}
14403
4a64f543
MS
14404/* One (or perhaps two) breakpoints used for software single
14405 stepping. */
8181d85f
DJ
14406
14407static void *single_step_breakpoints[2];
a6d9a66e 14408static struct gdbarch *single_step_gdbarch[2];
8181d85f
DJ
14409
14410/* Create and insert a breakpoint for software single step. */
14411
14412void
6c95b8df 14413insert_single_step_breakpoint (struct gdbarch *gdbarch,
4a64f543
MS
14414 struct address_space *aspace,
14415 CORE_ADDR next_pc)
8181d85f
DJ
14416{
14417 void **bpt_p;
14418
14419 if (single_step_breakpoints[0] == NULL)
a6d9a66e
UW
14420 {
14421 bpt_p = &single_step_breakpoints[0];
14422 single_step_gdbarch[0] = gdbarch;
14423 }
8181d85f
DJ
14424 else
14425 {
14426 gdb_assert (single_step_breakpoints[1] == NULL);
14427 bpt_p = &single_step_breakpoints[1];
a6d9a66e 14428 single_step_gdbarch[1] = gdbarch;
8181d85f
DJ
14429 }
14430
4a64f543
MS
14431 /* NOTE drow/2006-04-11: A future improvement to this function would
14432 be to only create the breakpoints once, and actually put them on
14433 the breakpoint chain. That would let us use set_raw_breakpoint.
14434 We could adjust the addresses each time they were needed. Doing
14435 this requires corresponding changes elsewhere where single step
14436 breakpoints are handled, however. So, for now, we use this. */
8181d85f 14437
6c95b8df 14438 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc);
8181d85f 14439 if (*bpt_p == NULL)
5af949e3
UW
14440 error (_("Could not insert single-step breakpoint at %s"),
14441 paddress (gdbarch, next_pc));
8181d85f
DJ
14442}
14443
f02253f1
HZ
14444/* Check if the breakpoints used for software single stepping
14445 were inserted or not. */
14446
14447int
14448single_step_breakpoints_inserted (void)
14449{
14450 return (single_step_breakpoints[0] != NULL
14451 || single_step_breakpoints[1] != NULL);
14452}
14453
8181d85f
DJ
14454/* Remove and delete any breakpoints used for software single step. */
14455
14456void
14457remove_single_step_breakpoints (void)
14458{
14459 gdb_assert (single_step_breakpoints[0] != NULL);
14460
14461 /* See insert_single_step_breakpoint for more about this deprecated
14462 call. */
a6d9a66e
UW
14463 deprecated_remove_raw_breakpoint (single_step_gdbarch[0],
14464 single_step_breakpoints[0]);
14465 single_step_gdbarch[0] = NULL;
8181d85f
DJ
14466 single_step_breakpoints[0] = NULL;
14467
14468 if (single_step_breakpoints[1] != NULL)
14469 {
a6d9a66e
UW
14470 deprecated_remove_raw_breakpoint (single_step_gdbarch[1],
14471 single_step_breakpoints[1]);
14472 single_step_gdbarch[1] = NULL;
8181d85f
DJ
14473 single_step_breakpoints[1] = NULL;
14474 }
14475}
14476
d03285ec
UW
14477/* Delete software single step breakpoints without removing them from
14478 the inferior. This is intended to be used if the inferior's address
14479 space where they were inserted is already gone, e.g. after exit or
14480 exec. */
14481
14482void
14483cancel_single_step_breakpoints (void)
14484{
14485 int i;
14486
14487 for (i = 0; i < 2; i++)
14488 if (single_step_breakpoints[i])
14489 {
14490 xfree (single_step_breakpoints[i]);
14491 single_step_breakpoints[i] = NULL;
14492 single_step_gdbarch[i] = NULL;
14493 }
14494}
14495
14496/* Detach software single-step breakpoints from INFERIOR_PTID without
14497 removing them. */
14498
14499static void
14500detach_single_step_breakpoints (void)
14501{
14502 int i;
14503
14504 for (i = 0; i < 2; i++)
14505 if (single_step_breakpoints[i])
14506 target_remove_breakpoint (single_step_gdbarch[i],
14507 single_step_breakpoints[i]);
14508}
14509
4a64f543
MS
14510/* Check whether a software single-step breakpoint is inserted at
14511 PC. */
1aafd4da
UW
14512
14513static int
cc59ec59
MS
14514single_step_breakpoint_inserted_here_p (struct address_space *aspace,
14515 CORE_ADDR pc)
1aafd4da
UW
14516{
14517 int i;
14518
14519 for (i = 0; i < 2; i++)
14520 {
14521 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
6c95b8df
PA
14522 if (bp_tgt
14523 && breakpoint_address_match (bp_tgt->placed_address_space,
14524 bp_tgt->placed_address,
14525 aspace, pc))
1aafd4da
UW
14526 return 1;
14527 }
14528
14529 return 0;
14530}
14531
a96d9b2e
SDJ
14532/* Returns 0 if 'bp' is NOT a syscall catchpoint,
14533 non-zero otherwise. */
14534static int
14535is_syscall_catchpoint_enabled (struct breakpoint *bp)
14536{
14537 if (syscall_catchpoint_p (bp)
14538 && bp->enable_state != bp_disabled
14539 && bp->enable_state != bp_call_disabled)
14540 return 1;
14541 else
14542 return 0;
14543}
14544
14545int
14546catch_syscall_enabled (void)
14547{
fa3064dd
YQ
14548 struct catch_syscall_inferior_data *inf_data
14549 = get_catch_syscall_inferior_data (current_inferior ());
a96d9b2e 14550
fa3064dd 14551 return inf_data->total_syscalls_count != 0;
a96d9b2e
SDJ
14552}
14553
14554int
14555catching_syscall_number (int syscall_number)
14556{
14557 struct breakpoint *bp;
14558
14559 ALL_BREAKPOINTS (bp)
14560 if (is_syscall_catchpoint_enabled (bp))
14561 {
be5c67c1
PA
14562 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp;
14563
14564 if (c->syscalls_to_be_caught)
a96d9b2e
SDJ
14565 {
14566 int i, iter;
14567 for (i = 0;
be5c67c1 14568 VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
a96d9b2e
SDJ
14569 i++)
14570 if (syscall_number == iter)
14571 return 1;
14572 }
14573 else
14574 return 1;
14575 }
14576
14577 return 0;
14578}
14579
14580/* Complete syscall names. Used by "catch syscall". */
49c4e619 14581static VEC (char_ptr) *
a96d9b2e
SDJ
14582catch_syscall_completer (struct cmd_list_element *cmd,
14583 char *text, char *word)
14584{
14585 const char **list = get_syscall_names ();
49c4e619 14586 VEC (char_ptr) *retlist
c38eea1a 14587 = (list == NULL) ? NULL : complete_on_enum (list, text, word);
cc59ec59 14588
c38eea1a
MS
14589 xfree (list);
14590 return retlist;
a96d9b2e
SDJ
14591}
14592
1042e4c0
SS
14593/* Tracepoint-specific operations. */
14594
14595/* Set tracepoint count to NUM. */
14596static void
14597set_tracepoint_count (int num)
14598{
14599 tracepoint_count = num;
4fa62494 14600 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
1042e4c0
SS
14601}
14602
70221824 14603static void
1042e4c0
SS
14604trace_command (char *arg, int from_tty)
14605{
55aa24fb
SDJ
14606 struct breakpoint_ops *ops;
14607 const char *arg_cp = arg;
14608
14609 if (arg && probe_linespec_to_ops (&arg_cp))
14610 ops = &tracepoint_probe_breakpoint_ops;
14611 else
14612 ops = &tracepoint_breakpoint_ops;
14613
8cdf0e15
VP
14614 if (create_breakpoint (get_current_arch (),
14615 arg,
e7e0cddf 14616 NULL, 0, NULL, 1 /* parse arg */,
0fb4aa4b
PA
14617 0 /* tempflag */,
14618 bp_tracepoint /* type_wanted */,
8cdf0e15
VP
14619 0 /* Ignore count */,
14620 pending_break_support,
55aa24fb 14621 ops,
8cdf0e15 14622 from_tty,
84f4c1fe 14623 1 /* enabled */,
44f238bb 14624 0 /* internal */, 0))
fd9b8c24 14625 set_tracepoint_count (breakpoint_count);
1042e4c0
SS
14626}
14627
70221824 14628static void
7a697b8d
SS
14629ftrace_command (char *arg, int from_tty)
14630{
8cdf0e15
VP
14631 if (create_breakpoint (get_current_arch (),
14632 arg,
e7e0cddf 14633 NULL, 0, NULL, 1 /* parse arg */,
0fb4aa4b
PA
14634 0 /* tempflag */,
14635 bp_fast_tracepoint /* type_wanted */,
14636 0 /* Ignore count */,
14637 pending_break_support,
348d480f 14638 &tracepoint_breakpoint_ops,
0fb4aa4b 14639 from_tty,
84f4c1fe 14640 1 /* enabled */,
44f238bb 14641 0 /* internal */, 0))
0fb4aa4b
PA
14642 set_tracepoint_count (breakpoint_count);
14643}
14644
14645/* strace command implementation. Creates a static tracepoint. */
14646
70221824 14647static void
0fb4aa4b
PA
14648strace_command (char *arg, int from_tty)
14649{
983af33b
SDJ
14650 struct breakpoint_ops *ops;
14651
14652 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14653 or with a normal static tracepoint. */
14654 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
14655 ops = &strace_marker_breakpoint_ops;
14656 else
14657 ops = &tracepoint_breakpoint_ops;
14658
0fb4aa4b
PA
14659 if (create_breakpoint (get_current_arch (),
14660 arg,
e7e0cddf 14661 NULL, 0, NULL, 1 /* parse arg */,
0fb4aa4b
PA
14662 0 /* tempflag */,
14663 bp_static_tracepoint /* type_wanted */,
8cdf0e15
VP
14664 0 /* Ignore count */,
14665 pending_break_support,
983af33b 14666 ops,
8cdf0e15 14667 from_tty,
84f4c1fe 14668 1 /* enabled */,
44f238bb 14669 0 /* internal */, 0))
fd9b8c24 14670 set_tracepoint_count (breakpoint_count);
7a697b8d
SS
14671}
14672
409873ef
SS
14673/* Set up a fake reader function that gets command lines from a linked
14674 list that was acquired during tracepoint uploading. */
14675
14676static struct uploaded_tp *this_utp;
3149d8c1 14677static int next_cmd;
409873ef
SS
14678
14679static char *
14680read_uploaded_action (void)
14681{
14682 char *rslt;
14683
3149d8c1 14684 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt);
409873ef 14685
3149d8c1 14686 next_cmd++;
409873ef
SS
14687
14688 return rslt;
14689}
14690
00bf0b85
SS
14691/* Given information about a tracepoint as recorded on a target (which
14692 can be either a live system or a trace file), attempt to create an
14693 equivalent GDB tracepoint. This is not a reliable process, since
14694 the target does not necessarily have all the information used when
14695 the tracepoint was originally defined. */
14696
d9b3f62e 14697struct tracepoint *
00bf0b85 14698create_tracepoint_from_upload (struct uploaded_tp *utp)
d5551862 14699{
409873ef 14700 char *addr_str, small_buf[100];
d9b3f62e 14701 struct tracepoint *tp;
fd9b8c24 14702
409873ef
SS
14703 if (utp->at_string)
14704 addr_str = utp->at_string;
14705 else
14706 {
14707 /* In the absence of a source location, fall back to raw
14708 address. Since there is no way to confirm that the address
14709 means the same thing as when the trace was started, warn the
14710 user. */
3e43a32a
MS
14711 warning (_("Uploaded tracepoint %d has no "
14712 "source location, using raw address"),
409873ef
SS
14713 utp->number);
14714 sprintf (small_buf, "*%s", hex_string (utp->addr));
14715 addr_str = small_buf;
14716 }
14717
14718 /* There's not much we can do with a sequence of bytecodes. */
14719 if (utp->cond && !utp->cond_string)
3e43a32a
MS
14720 warning (_("Uploaded tracepoint %d condition "
14721 "has no source form, ignoring it"),
409873ef 14722 utp->number);
d5551862 14723
8cdf0e15 14724 if (!create_breakpoint (get_current_arch (),
409873ef 14725 addr_str,
e7e0cddf
SS
14726 utp->cond_string, -1, NULL,
14727 0 /* parse cond/thread */,
8cdf0e15 14728 0 /* tempflag */,
0fb4aa4b 14729 utp->type /* type_wanted */,
8cdf0e15
VP
14730 0 /* Ignore count */,
14731 pending_break_support,
348d480f 14732 &tracepoint_breakpoint_ops,
8cdf0e15 14733 0 /* from_tty */,
84f4c1fe 14734 utp->enabled /* enabled */,
44f238bb
PA
14735 0 /* internal */,
14736 CREATE_BREAKPOINT_FLAGS_INSERTED))
fd9b8c24
PA
14737 return NULL;
14738
00bf0b85
SS
14739 set_tracepoint_count (breakpoint_count);
14740
409873ef 14741 /* Get the tracepoint we just created. */
fd9b8c24
PA
14742 tp = get_tracepoint (tracepoint_count);
14743 gdb_assert (tp != NULL);
d5551862 14744
00bf0b85
SS
14745 if (utp->pass > 0)
14746 {
d9b3f62e 14747 sprintf (small_buf, "%d %d", utp->pass, tp->base.number);
00bf0b85 14748
409873ef 14749 trace_pass_command (small_buf, 0);
00bf0b85
SS
14750 }
14751
409873ef
SS
14752 /* If we have uploaded versions of the original commands, set up a
14753 special-purpose "reader" function and call the usual command line
14754 reader, then pass the result to the breakpoint command-setting
14755 function. */
3149d8c1 14756 if (!VEC_empty (char_ptr, utp->cmd_strings))
00bf0b85 14757 {
409873ef 14758 struct command_line *cmd_list;
00bf0b85 14759
409873ef 14760 this_utp = utp;
3149d8c1 14761 next_cmd = 0;
d5551862 14762
409873ef
SS
14763 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
14764
d9b3f62e 14765 breakpoint_set_commands (&tp->base, cmd_list);
00bf0b85 14766 }
3149d8c1
SS
14767 else if (!VEC_empty (char_ptr, utp->actions)
14768 || !VEC_empty (char_ptr, utp->step_actions))
3e43a32a
MS
14769 warning (_("Uploaded tracepoint %d actions "
14770 "have no source form, ignoring them"),
409873ef 14771 utp->number);
00bf0b85 14772
f196051f
SS
14773 /* Copy any status information that might be available. */
14774 tp->base.hit_count = utp->hit_count;
14775 tp->traceframe_usage = utp->traceframe_usage;
14776
00bf0b85 14777 return tp;
d9b3f62e 14778}
00bf0b85 14779
1042e4c0
SS
14780/* Print information on tracepoint number TPNUM_EXP, or all if
14781 omitted. */
14782
14783static void
e5a67952 14784tracepoints_info (char *args, int from_tty)
1042e4c0 14785{
79a45e25 14786 struct ui_out *uiout = current_uiout;
e5a67952 14787 int num_printed;
1042e4c0 14788
e5a67952 14789 num_printed = breakpoint_1 (args, 0, is_tracepoint);
d77f58be
SS
14790
14791 if (num_printed == 0)
1042e4c0 14792 {
e5a67952 14793 if (args == NULL || *args == '\0')
d77f58be
SS
14794 ui_out_message (uiout, 0, "No tracepoints.\n");
14795 else
e5a67952 14796 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args);
1042e4c0 14797 }
ad443146
SS
14798
14799 default_collect_info ();
1042e4c0
SS
14800}
14801
4a64f543 14802/* The 'enable trace' command enables tracepoints.
1042e4c0
SS
14803 Not supported by all targets. */
14804static void
14805enable_trace_command (char *args, int from_tty)
14806{
14807 enable_command (args, from_tty);
14808}
14809
4a64f543 14810/* The 'disable trace' command disables tracepoints.
1042e4c0
SS
14811 Not supported by all targets. */
14812static void
14813disable_trace_command (char *args, int from_tty)
14814{
14815 disable_command (args, from_tty);
14816}
14817
4a64f543 14818/* Remove a tracepoint (or all if no argument). */
1042e4c0
SS
14819static void
14820delete_trace_command (char *arg, int from_tty)
14821{
35df4500 14822 struct breakpoint *b, *b_tmp;
1042e4c0
SS
14823
14824 dont_repeat ();
14825
14826 if (arg == 0)
14827 {
14828 int breaks_to_delete = 0;
14829
14830 /* Delete all breakpoints if no argument.
14831 Do not delete internal or call-dummy breakpoints, these
4a64f543
MS
14832 have to be deleted with an explicit breakpoint number
14833 argument. */
1042e4c0 14834 ALL_TRACEPOINTS (b)
46c6471b 14835 if (is_tracepoint (b) && user_breakpoint_p (b))
1042e4c0
SS
14836 {
14837 breaks_to_delete = 1;
14838 break;
14839 }
1042e4c0
SS
14840
14841 /* Ask user only if there are some breakpoints to delete. */
14842 if (!from_tty
14843 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
14844 {
35df4500 14845 ALL_BREAKPOINTS_SAFE (b, b_tmp)
46c6471b 14846 if (is_tracepoint (b) && user_breakpoint_p (b))
1042e4c0 14847 delete_breakpoint (b);
1042e4c0
SS
14848 }
14849 }
14850 else
51be5b68 14851 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL);
1042e4c0
SS
14852}
14853
197f0a60
TT
14854/* Helper function for trace_pass_command. */
14855
14856static void
d9b3f62e 14857trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
197f0a60 14858{
d9b3f62e
PA
14859 tp->pass_count = count;
14860 observer_notify_tracepoint_modified (tp->base.number);
197f0a60
TT
14861 if (from_tty)
14862 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
d9b3f62e 14863 tp->base.number, count);
197f0a60
TT
14864}
14865
1042e4c0
SS
14866/* Set passcount for tracepoint.
14867
14868 First command argument is passcount, second is tracepoint number.
14869 If tracepoint number omitted, apply to most recently defined.
14870 Also accepts special argument "all". */
14871
14872static void
14873trace_pass_command (char *args, int from_tty)
14874{
d9b3f62e 14875 struct tracepoint *t1;
1042e4c0 14876 unsigned int count;
1042e4c0
SS
14877
14878 if (args == 0 || *args == 0)
3e43a32a
MS
14879 error (_("passcount command requires an "
14880 "argument (count + optional TP num)"));
1042e4c0 14881
4a64f543 14882 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
1042e4c0
SS
14883
14884 while (*args && isspace ((int) *args))
14885 args++;
14886
14887 if (*args && strncasecmp (args, "all", 3) == 0)
14888 {
d9b3f62e
PA
14889 struct breakpoint *b;
14890
1042e4c0 14891 args += 3; /* Skip special argument "all". */
1042e4c0
SS
14892 if (*args)
14893 error (_("Junk at end of arguments."));
1042e4c0 14894
d9b3f62e 14895 ALL_TRACEPOINTS (b)
197f0a60 14896 {
d9b3f62e 14897 t1 = (struct tracepoint *) b;
197f0a60
TT
14898 trace_pass_set_count (t1, count, from_tty);
14899 }
14900 }
14901 else if (*args == '\0')
1042e4c0 14902 {
197f0a60 14903 t1 = get_tracepoint_by_number (&args, NULL, 1);
1042e4c0 14904 if (t1)
197f0a60
TT
14905 trace_pass_set_count (t1, count, from_tty);
14906 }
14907 else
14908 {
14909 struct get_number_or_range_state state;
14910
14911 init_number_or_range (&state, args);
14912 while (!state.finished)
1042e4c0 14913 {
197f0a60
TT
14914 t1 = get_tracepoint_by_number (&args, &state, 1);
14915 if (t1)
14916 trace_pass_set_count (t1, count, from_tty);
1042e4c0
SS
14917 }
14918 }
1042e4c0
SS
14919}
14920
d9b3f62e 14921struct tracepoint *
1042e4c0
SS
14922get_tracepoint (int num)
14923{
14924 struct breakpoint *t;
14925
14926 ALL_TRACEPOINTS (t)
14927 if (t->number == num)
d9b3f62e 14928 return (struct tracepoint *) t;
1042e4c0
SS
14929
14930 return NULL;
14931}
14932
d5551862
SS
14933/* Find the tracepoint with the given target-side number (which may be
14934 different from the tracepoint number after disconnecting and
14935 reconnecting). */
14936
d9b3f62e 14937struct tracepoint *
d5551862
SS
14938get_tracepoint_by_number_on_target (int num)
14939{
d9b3f62e 14940 struct breakpoint *b;
d5551862 14941
d9b3f62e
PA
14942 ALL_TRACEPOINTS (b)
14943 {
14944 struct tracepoint *t = (struct tracepoint *) b;
14945
14946 if (t->number_on_target == num)
14947 return t;
14948 }
d5551862
SS
14949
14950 return NULL;
14951}
14952
1042e4c0 14953/* Utility: parse a tracepoint number and look it up in the list.
197f0a60
TT
14954 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14955 If OPTIONAL_P is true, then if the argument is missing, the most
1042e4c0 14956 recent tracepoint (tracepoint_count) is returned. */
d9b3f62e 14957struct tracepoint *
197f0a60
TT
14958get_tracepoint_by_number (char **arg,
14959 struct get_number_or_range_state *state,
14960 int optional_p)
1042e4c0
SS
14961{
14962 extern int tracepoint_count;
14963 struct breakpoint *t;
14964 int tpnum;
14965 char *instring = arg == NULL ? NULL : *arg;
14966
197f0a60
TT
14967 if (state)
14968 {
14969 gdb_assert (!state->finished);
14970 tpnum = get_number_or_range (state);
14971 }
14972 else if (arg == NULL || *arg == NULL || ! **arg)
1042e4c0
SS
14973 {
14974 if (optional_p)
14975 tpnum = tracepoint_count;
14976 else
14977 error_no_arg (_("tracepoint number"));
14978 }
14979 else
197f0a60 14980 tpnum = get_number (arg);
1042e4c0
SS
14981
14982 if (tpnum <= 0)
14983 {
14984 if (instring && *instring)
14985 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14986 instring);
14987 else
3e43a32a
MS
14988 printf_filtered (_("Tracepoint argument missing "
14989 "and no previous tracepoint\n"));
1042e4c0
SS
14990 return NULL;
14991 }
14992
14993 ALL_TRACEPOINTS (t)
14994 if (t->number == tpnum)
14995 {
d9b3f62e 14996 return (struct tracepoint *) t;
1042e4c0
SS
14997 }
14998
1042e4c0
SS
14999 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
15000 return NULL;
15001}
15002
d9b3f62e
PA
15003void
15004print_recreate_thread (struct breakpoint *b, struct ui_file *fp)
15005{
15006 if (b->thread != -1)
15007 fprintf_unfiltered (fp, " thread %d", b->thread);
15008
15009 if (b->task != 0)
15010 fprintf_unfiltered (fp, " task %d", b->task);
15011
15012 fprintf_unfiltered (fp, "\n");
15013}
15014
6149aea9
PA
15015/* Save information on user settable breakpoints (watchpoints, etc) to
15016 a new script file named FILENAME. If FILTER is non-NULL, call it
15017 on each breakpoint and only include the ones for which it returns
15018 non-zero. */
15019
1042e4c0 15020static void
6149aea9
PA
15021save_breakpoints (char *filename, int from_tty,
15022 int (*filter) (const struct breakpoint *))
1042e4c0
SS
15023{
15024 struct breakpoint *tp;
6149aea9 15025 int any = 0;
a7bdde9e 15026 char *pathname;
1042e4c0 15027 struct cleanup *cleanup;
a7bdde9e 15028 struct ui_file *fp;
6149aea9 15029 int extra_trace_bits = 0;
1042e4c0 15030
6149aea9
PA
15031 if (filename == 0 || *filename == 0)
15032 error (_("Argument required (file name in which to save)"));
1042e4c0
SS
15033
15034 /* See if we have anything to save. */
6149aea9 15035 ALL_BREAKPOINTS (tp)
1042e4c0 15036 {
6149aea9 15037 /* Skip internal and momentary breakpoints. */
09d682a4 15038 if (!user_breakpoint_p (tp))
6149aea9
PA
15039 continue;
15040
15041 /* If we have a filter, only save the breakpoints it accepts. */
15042 if (filter && !filter (tp))
15043 continue;
15044
15045 any = 1;
15046
15047 if (is_tracepoint (tp))
15048 {
15049 extra_trace_bits = 1;
15050
15051 /* We can stop searching. */
15052 break;
15053 }
1042e4c0 15054 }
6149aea9
PA
15055
15056 if (!any)
1042e4c0 15057 {
6149aea9 15058 warning (_("Nothing to save."));
1042e4c0
SS
15059 return;
15060 }
15061
6149aea9 15062 pathname = tilde_expand (filename);
1042e4c0 15063 cleanup = make_cleanup (xfree, pathname);
a7bdde9e 15064 fp = gdb_fopen (pathname, "w");
059fb39f 15065 if (!fp)
6149aea9
PA
15066 error (_("Unable to open file '%s' for saving (%s)"),
15067 filename, safe_strerror (errno));
a7bdde9e 15068 make_cleanup_ui_file_delete (fp);
8bf6485c 15069
6149aea9
PA
15070 if (extra_trace_bits)
15071 save_trace_state_variables (fp);
8bf6485c 15072
6149aea9 15073 ALL_BREAKPOINTS (tp)
1042e4c0 15074 {
6149aea9 15075 /* Skip internal and momentary breakpoints. */
09d682a4 15076 if (!user_breakpoint_p (tp))
6149aea9 15077 continue;
8bf6485c 15078
6149aea9
PA
15079 /* If we have a filter, only save the breakpoints it accepts. */
15080 if (filter && !filter (tp))
15081 continue;
15082
348d480f 15083 tp->ops->print_recreate (tp, fp);
1042e4c0 15084
6149aea9
PA
15085 /* Note, we can't rely on tp->number for anything, as we can't
15086 assume the recreated breakpoint numbers will match. Use $bpnum
15087 instead. */
15088
15089 if (tp->cond_string)
15090 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string);
15091
15092 if (tp->ignore_count)
15093 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count);
15094
a7bdde9e 15095 if (tp->commands)
1042e4c0 15096 {
a7bdde9e
VP
15097 volatile struct gdb_exception ex;
15098
6149aea9 15099 fprintf_unfiltered (fp, " commands\n");
a7bdde9e 15100
79a45e25 15101 ui_out_redirect (current_uiout, fp);
14dba4b4 15102 TRY_CATCH (ex, RETURN_MASK_ALL)
1042e4c0 15103 {
79a45e25 15104 print_command_lines (current_uiout, tp->commands->commands, 2);
a7bdde9e 15105 }
79a45e25 15106 ui_out_redirect (current_uiout, NULL);
1042e4c0 15107
a7bdde9e
VP
15108 if (ex.reason < 0)
15109 throw_exception (ex);
1042e4c0 15110
a7bdde9e 15111 fprintf_unfiltered (fp, " end\n");
1042e4c0 15112 }
6149aea9
PA
15113
15114 if (tp->enable_state == bp_disabled)
15115 fprintf_unfiltered (fp, "disable\n");
15116
15117 /* If this is a multi-location breakpoint, check if the locations
15118 should be individually disabled. Watchpoint locations are
15119 special, and not user visible. */
15120 if (!is_watchpoint (tp) && tp->loc && tp->loc->next)
15121 {
15122 struct bp_location *loc;
15123 int n = 1;
15124
15125 for (loc = tp->loc; loc != NULL; loc = loc->next, n++)
15126 if (!loc->enabled)
15127 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n);
15128 }
1042e4c0 15129 }
8bf6485c 15130
6149aea9 15131 if (extra_trace_bits && *default_collect)
8bf6485c
SS
15132 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect);
15133
1042e4c0
SS
15134 do_cleanups (cleanup);
15135 if (from_tty)
6149aea9
PA
15136 printf_filtered (_("Saved to file '%s'.\n"), filename);
15137}
15138
15139/* The `save breakpoints' command. */
15140
15141static void
15142save_breakpoints_command (char *args, int from_tty)
15143{
15144 save_breakpoints (args, from_tty, NULL);
15145}
15146
15147/* The `save tracepoints' command. */
15148
15149static void
15150save_tracepoints_command (char *args, int from_tty)
15151{
15152 save_breakpoints (args, from_tty, is_tracepoint);
1042e4c0
SS
15153}
15154
15155/* Create a vector of all tracepoints. */
15156
15157VEC(breakpoint_p) *
eeae04df 15158all_tracepoints (void)
1042e4c0
SS
15159{
15160 VEC(breakpoint_p) *tp_vec = 0;
15161 struct breakpoint *tp;
15162
15163 ALL_TRACEPOINTS (tp)
15164 {
15165 VEC_safe_push (breakpoint_p, tp_vec, tp);
15166 }
15167
15168 return tp_vec;
15169}
15170
c906108c 15171\f
4a64f543
MS
15172/* This help string is used for the break, hbreak, tbreak and thbreak
15173 commands. It is defined as a macro to prevent duplication.
15174 COMMAND should be a string constant containing the name of the
15175 command. */
31e2b00f
AS
15176#define BREAK_ARGS_HELP(command) \
15177command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15178LOCATION may be a line number, function name, or \"*\" and an address.\n\
15179If a line number is specified, break at start of code for that line.\n\
15180If a function is specified, break at start of code for that function.\n\
15181If an address is specified, break at that exact address.\n\
dc10affe
PA
15182With no LOCATION, uses current execution address of the selected\n\
15183stack frame. This is useful for breaking on return to a stack frame.\n\
31e2b00f
AS
15184\n\
15185THREADNUM is the number from \"info threads\".\n\
15186CONDITION is a boolean expression.\n\
15187\n\
d41c0fc8
PA
15188Multiple breakpoints at one place are permitted, and useful if their\n\
15189conditions are different.\n\
31e2b00f
AS
15190\n\
15191Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15192
44feb3ce
TT
15193/* List of subcommands for "catch". */
15194static struct cmd_list_element *catch_cmdlist;
15195
15196/* List of subcommands for "tcatch". */
15197static struct cmd_list_element *tcatch_cmdlist;
15198
9ac4176b 15199void
44feb3ce
TT
15200add_catch_command (char *name, char *docstring,
15201 void (*sfunc) (char *args, int from_tty,
15202 struct cmd_list_element *command),
625e8578 15203 completer_ftype *completer,
44feb3ce
TT
15204 void *user_data_catch,
15205 void *user_data_tcatch)
15206{
15207 struct cmd_list_element *command;
15208
15209 command = add_cmd (name, class_breakpoint, NULL, docstring,
15210 &catch_cmdlist);
15211 set_cmd_sfunc (command, sfunc);
15212 set_cmd_context (command, user_data_catch);
a96d9b2e 15213 set_cmd_completer (command, completer);
44feb3ce
TT
15214
15215 command = add_cmd (name, class_breakpoint, NULL, docstring,
15216 &tcatch_cmdlist);
15217 set_cmd_sfunc (command, sfunc);
15218 set_cmd_context (command, user_data_tcatch);
a96d9b2e 15219 set_cmd_completer (command, completer);
44feb3ce
TT
15220}
15221
6c95b8df 15222static void
a79b8f6e 15223clear_syscall_counts (struct inferior *inf)
6c95b8df 15224{
fa3064dd
YQ
15225 struct catch_syscall_inferior_data *inf_data
15226 = get_catch_syscall_inferior_data (inf);
15227
15228 inf_data->total_syscalls_count = 0;
15229 inf_data->any_syscall_count = 0;
15230 VEC_free (int, inf_data->syscalls_counts);
6c95b8df
PA
15231}
15232
6149aea9
PA
15233static void
15234save_command (char *arg, int from_tty)
15235{
3e43a32a
MS
15236 printf_unfiltered (_("\"save\" must be followed by "
15237 "the name of a save subcommand.\n"));
6149aea9
PA
15238 help_list (save_cmdlist, "save ", -1, gdb_stdout);
15239}
15240
84f4c1fe
PM
15241struct breakpoint *
15242iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
15243 void *data)
15244{
35df4500 15245 struct breakpoint *b, *b_tmp;
84f4c1fe 15246
35df4500 15247 ALL_BREAKPOINTS_SAFE (b, b_tmp)
84f4c1fe
PM
15248 {
15249 if ((*callback) (b, data))
15250 return b;
15251 }
15252
15253 return NULL;
15254}
15255
0574c78f
GB
15256/* Zero if any of the breakpoint's locations could be a location where
15257 functions have been inlined, nonzero otherwise. */
15258
15259static int
15260is_non_inline_function (struct breakpoint *b)
15261{
15262 /* The shared library event breakpoint is set on the address of a
15263 non-inline function. */
15264 if (b->type == bp_shlib_event)
15265 return 1;
15266
15267 return 0;
15268}
15269
15270/* Nonzero if the specified PC cannot be a location where functions
15271 have been inlined. */
15272
15273int
09ac7c10
TT
15274pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
15275 const struct target_waitstatus *ws)
0574c78f
GB
15276{
15277 struct breakpoint *b;
15278 struct bp_location *bl;
15279
15280 ALL_BREAKPOINTS (b)
15281 {
15282 if (!is_non_inline_function (b))
15283 continue;
15284
15285 for (bl = b->loc; bl != NULL; bl = bl->next)
15286 {
15287 if (!bl->shlib_disabled
09ac7c10 15288 && bpstat_check_location (bl, aspace, pc, ws))
0574c78f
GB
15289 return 1;
15290 }
15291 }
15292
15293 return 0;
15294}
15295
2060206e
PA
15296void
15297initialize_breakpoint_ops (void)
15298{
15299 static int initialized = 0;
15300
15301 struct breakpoint_ops *ops;
15302
15303 if (initialized)
15304 return;
15305 initialized = 1;
15306
15307 /* The breakpoint_ops structure to be inherit by all kinds of
15308 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15309 internal and momentary breakpoints, etc.). */
15310 ops = &bkpt_base_breakpoint_ops;
15311 *ops = base_breakpoint_ops;
15312 ops->re_set = bkpt_re_set;
15313 ops->insert_location = bkpt_insert_location;
15314 ops->remove_location = bkpt_remove_location;
15315 ops->breakpoint_hit = bkpt_breakpoint_hit;
983af33b
SDJ
15316 ops->create_sals_from_address = bkpt_create_sals_from_address;
15317 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal;
15318 ops->decode_linespec = bkpt_decode_linespec;
2060206e
PA
15319
15320 /* The breakpoint_ops structure to be used in regular breakpoints. */
15321 ops = &bkpt_breakpoint_ops;
15322 *ops = bkpt_base_breakpoint_ops;
15323 ops->re_set = bkpt_re_set;
15324 ops->resources_needed = bkpt_resources_needed;
15325 ops->print_it = bkpt_print_it;
15326 ops->print_mention = bkpt_print_mention;
15327 ops->print_recreate = bkpt_print_recreate;
15328
15329 /* Ranged breakpoints. */
15330 ops = &ranged_breakpoint_ops;
15331 *ops = bkpt_breakpoint_ops;
15332 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint;
15333 ops->resources_needed = resources_needed_ranged_breakpoint;
15334 ops->print_it = print_it_ranged_breakpoint;
15335 ops->print_one = print_one_ranged_breakpoint;
15336 ops->print_one_detail = print_one_detail_ranged_breakpoint;
15337 ops->print_mention = print_mention_ranged_breakpoint;
15338 ops->print_recreate = print_recreate_ranged_breakpoint;
15339
15340 /* Internal breakpoints. */
15341 ops = &internal_breakpoint_ops;
15342 *ops = bkpt_base_breakpoint_ops;
15343 ops->re_set = internal_bkpt_re_set;
15344 ops->check_status = internal_bkpt_check_status;
15345 ops->print_it = internal_bkpt_print_it;
15346 ops->print_mention = internal_bkpt_print_mention;
15347
15348 /* Momentary breakpoints. */
15349 ops = &momentary_breakpoint_ops;
15350 *ops = bkpt_base_breakpoint_ops;
15351 ops->re_set = momentary_bkpt_re_set;
15352 ops->check_status = momentary_bkpt_check_status;
15353 ops->print_it = momentary_bkpt_print_it;
15354 ops->print_mention = momentary_bkpt_print_mention;
15355
55aa24fb
SDJ
15356 /* Probe breakpoints. */
15357 ops = &bkpt_probe_breakpoint_ops;
15358 *ops = bkpt_breakpoint_ops;
15359 ops->insert_location = bkpt_probe_insert_location;
15360 ops->remove_location = bkpt_probe_remove_location;
15361 ops->create_sals_from_address = bkpt_probe_create_sals_from_address;
15362 ops->decode_linespec = bkpt_probe_decode_linespec;
15363
2060206e
PA
15364 /* GNU v3 exception catchpoints. */
15365 ops = &gnu_v3_exception_catchpoint_ops;
15366 *ops = bkpt_breakpoint_ops;
15367 ops->print_it = print_it_exception_catchpoint;
15368 ops->print_one = print_one_exception_catchpoint;
15369 ops->print_mention = print_mention_exception_catchpoint;
15370 ops->print_recreate = print_recreate_exception_catchpoint;
15371
15372 /* Watchpoints. */
15373 ops = &watchpoint_breakpoint_ops;
15374 *ops = base_breakpoint_ops;
3a5c3e22 15375 ops->dtor = dtor_watchpoint;
2060206e
PA
15376 ops->re_set = re_set_watchpoint;
15377 ops->insert_location = insert_watchpoint;
15378 ops->remove_location = remove_watchpoint;
15379 ops->breakpoint_hit = breakpoint_hit_watchpoint;
15380 ops->check_status = check_status_watchpoint;
15381 ops->resources_needed = resources_needed_watchpoint;
15382 ops->works_in_software_mode = works_in_software_mode_watchpoint;
15383 ops->print_it = print_it_watchpoint;
15384 ops->print_mention = print_mention_watchpoint;
15385 ops->print_recreate = print_recreate_watchpoint;
15386
15387 /* Masked watchpoints. */
15388 ops = &masked_watchpoint_breakpoint_ops;
15389 *ops = watchpoint_breakpoint_ops;
15390 ops->insert_location = insert_masked_watchpoint;
15391 ops->remove_location = remove_masked_watchpoint;
15392 ops->resources_needed = resources_needed_masked_watchpoint;
15393 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint;
15394 ops->print_it = print_it_masked_watchpoint;
15395 ops->print_one_detail = print_one_detail_masked_watchpoint;
15396 ops->print_mention = print_mention_masked_watchpoint;
15397 ops->print_recreate = print_recreate_masked_watchpoint;
15398
15399 /* Tracepoints. */
15400 ops = &tracepoint_breakpoint_ops;
15401 *ops = base_breakpoint_ops;
15402 ops->re_set = tracepoint_re_set;
15403 ops->breakpoint_hit = tracepoint_breakpoint_hit;
15404 ops->print_one_detail = tracepoint_print_one_detail;
15405 ops->print_mention = tracepoint_print_mention;
15406 ops->print_recreate = tracepoint_print_recreate;
983af33b
SDJ
15407 ops->create_sals_from_address = tracepoint_create_sals_from_address;
15408 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal;
15409 ops->decode_linespec = tracepoint_decode_linespec;
15410
55aa24fb
SDJ
15411 /* Probe tracepoints. */
15412 ops = &tracepoint_probe_breakpoint_ops;
15413 *ops = tracepoint_breakpoint_ops;
15414 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address;
15415 ops->decode_linespec = tracepoint_probe_decode_linespec;
15416
983af33b
SDJ
15417 /* Static tracepoints with marker (`-m'). */
15418 ops = &strace_marker_breakpoint_ops;
15419 *ops = tracepoint_breakpoint_ops;
15420 ops->create_sals_from_address = strace_marker_create_sals_from_address;
15421 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal;
15422 ops->decode_linespec = strace_marker_decode_linespec;
2060206e
PA
15423
15424 /* Fork catchpoints. */
15425 ops = &catch_fork_breakpoint_ops;
15426 *ops = base_breakpoint_ops;
15427 ops->insert_location = insert_catch_fork;
15428 ops->remove_location = remove_catch_fork;
15429 ops->breakpoint_hit = breakpoint_hit_catch_fork;
15430 ops->print_it = print_it_catch_fork;
15431 ops->print_one = print_one_catch_fork;
15432 ops->print_mention = print_mention_catch_fork;
15433 ops->print_recreate = print_recreate_catch_fork;
15434
15435 /* Vfork catchpoints. */
15436 ops = &catch_vfork_breakpoint_ops;
15437 *ops = base_breakpoint_ops;
15438 ops->insert_location = insert_catch_vfork;
15439 ops->remove_location = remove_catch_vfork;
15440 ops->breakpoint_hit = breakpoint_hit_catch_vfork;
15441 ops->print_it = print_it_catch_vfork;
15442 ops->print_one = print_one_catch_vfork;
15443 ops->print_mention = print_mention_catch_vfork;
15444 ops->print_recreate = print_recreate_catch_vfork;
15445
15446 /* Exec catchpoints. */
15447 ops = &catch_exec_breakpoint_ops;
15448 *ops = base_breakpoint_ops;
15449 ops->dtor = dtor_catch_exec;
15450 ops->insert_location = insert_catch_exec;
15451 ops->remove_location = remove_catch_exec;
15452 ops->breakpoint_hit = breakpoint_hit_catch_exec;
15453 ops->print_it = print_it_catch_exec;
15454 ops->print_one = print_one_catch_exec;
15455 ops->print_mention = print_mention_catch_exec;
15456 ops->print_recreate = print_recreate_catch_exec;
15457
15458 /* Syscall catchpoints. */
15459 ops = &catch_syscall_breakpoint_ops;
15460 *ops = base_breakpoint_ops;
15461 ops->dtor = dtor_catch_syscall;
15462 ops->insert_location = insert_catch_syscall;
15463 ops->remove_location = remove_catch_syscall;
15464 ops->breakpoint_hit = breakpoint_hit_catch_syscall;
15465 ops->print_it = print_it_catch_syscall;
15466 ops->print_one = print_one_catch_syscall;
15467 ops->print_mention = print_mention_catch_syscall;
15468 ops->print_recreate = print_recreate_catch_syscall;
edcc5120
TT
15469
15470 /* Solib-related catchpoints. */
15471 ops = &catch_solib_breakpoint_ops;
15472 *ops = base_breakpoint_ops;
15473 ops->dtor = dtor_catch_solib;
15474 ops->insert_location = insert_catch_solib;
15475 ops->remove_location = remove_catch_solib;
15476 ops->breakpoint_hit = breakpoint_hit_catch_solib;
15477 ops->check_status = check_status_catch_solib;
15478 ops->print_it = print_it_catch_solib;
15479 ops->print_one = print_one_catch_solib;
15480 ops->print_mention = print_mention_catch_solib;
15481 ops->print_recreate = print_recreate_catch_solib;
e7e0cddf
SS
15482
15483 ops = &dprintf_breakpoint_ops;
15484 *ops = bkpt_base_breakpoint_ops;
15485 ops->re_set = bkpt_re_set;
15486 ops->resources_needed = bkpt_resources_needed;
15487 ops->print_it = bkpt_print_it;
15488 ops->print_mention = bkpt_print_mention;
15489 ops->print_recreate = bkpt_print_recreate;
2060206e
PA
15490}
15491
c906108c 15492void
fba45db2 15493_initialize_breakpoint (void)
c906108c
SS
15494{
15495 struct cmd_list_element *c;
15496
2060206e
PA
15497 initialize_breakpoint_ops ();
15498
84acb35a 15499 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
6c95b8df 15500 observer_attach_inferior_exit (clear_syscall_counts);
1f3b5d1b 15501 observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
84acb35a 15502
55aa24fb
SDJ
15503 breakpoint_objfile_key
15504 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
17450429 15505
fa3064dd
YQ
15506 catch_syscall_inferior_data
15507 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup);
15508
c906108c
SS
15509 breakpoint_chain = 0;
15510 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15511 before a breakpoint is set. */
15512 breakpoint_count = 0;
15513
1042e4c0
SS
15514 tracepoint_count = 0;
15515
1bedd215
AC
15516 add_com ("ignore", class_breakpoint, ignore_command, _("\
15517Set ignore-count of breakpoint number N to COUNT.\n\
15518Usage is `ignore N COUNT'."));
c906108c 15519 if (xdb_commands)
c5aa993b 15520 add_com_alias ("bc", "ignore", class_breakpoint, 1);
c906108c 15521
1bedd215
AC
15522 add_com ("commands", class_breakpoint, commands_command, _("\
15523Set commands to be executed when a breakpoint is hit.\n\
c906108c
SS
15524Give breakpoint number as argument after \"commands\".\n\
15525With no argument, the targeted breakpoint is the last one set.\n\
15526The commands themselves follow starting on the next line.\n\
15527Type a line containing \"end\" to indicate the end of them.\n\
15528Give \"silent\" as the first line to make the breakpoint silent;\n\
1bedd215 15529then no output is printed when it is hit, except what the commands print."));
c906108c 15530
1bedd215
AC
15531 add_com ("condition", class_breakpoint, condition_command, _("\
15532Specify breakpoint number N to break only if COND is true.\n\
c906108c 15533Usage is `condition N COND', where N is an integer and COND is an\n\
1bedd215 15534expression to be evaluated whenever breakpoint N is reached."));
c906108c 15535
1bedd215 15536 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
31e2b00f 15537Set a temporary breakpoint.\n\
c906108c
SS
15538Like \"break\" except the breakpoint is only temporary,\n\
15539so it will be deleted when hit. Equivalent to \"break\" followed\n\
31e2b00f
AS
15540by using \"enable delete\" on the breakpoint number.\n\
15541\n"
15542BREAK_ARGS_HELP ("tbreak")));
5ba2abeb 15543 set_cmd_completer (c, location_completer);
c94fdfd0 15544
1bedd215 15545 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
a3be7890 15546Set a hardware assisted breakpoint.\n\
c906108c 15547Like \"break\" except the breakpoint requires hardware support,\n\
31e2b00f
AS
15548some target hardware may not have this support.\n\
15549\n"
15550BREAK_ARGS_HELP ("hbreak")));
5ba2abeb 15551 set_cmd_completer (c, location_completer);
c906108c 15552
1bedd215 15553 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
31e2b00f 15554Set a temporary hardware assisted breakpoint.\n\
c906108c 15555Like \"hbreak\" except the breakpoint is only temporary,\n\
31e2b00f
AS
15556so it will be deleted when hit.\n\
15557\n"
15558BREAK_ARGS_HELP ("thbreak")));
5ba2abeb 15559 set_cmd_completer (c, location_completer);
c906108c 15560
1bedd215
AC
15561 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
15562Enable some breakpoints.\n\
c906108c
SS
15563Give breakpoint numbers (separated by spaces) as arguments.\n\
15564With no subcommand, breakpoints are enabled until you command otherwise.\n\
15565This is used to cancel the effect of the \"disable\" command.\n\
1bedd215 15566With a subcommand you can enable temporarily."),
c906108c
SS
15567 &enablelist, "enable ", 1, &cmdlist);
15568 if (xdb_commands)
1bedd215
AC
15569 add_com ("ab", class_breakpoint, enable_command, _("\
15570Enable some breakpoints.\n\
c906108c
SS
15571Give breakpoint numbers (separated by spaces) as arguments.\n\
15572With no subcommand, breakpoints are enabled until you command otherwise.\n\
15573This is used to cancel the effect of the \"disable\" command.\n\
1bedd215 15574With a subcommand you can enable temporarily."));
c906108c
SS
15575
15576 add_com_alias ("en", "enable", class_breakpoint, 1);
15577
84951ab5 15578 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
1bedd215 15579Enable some breakpoints.\n\
c906108c
SS
15580Give breakpoint numbers (separated by spaces) as arguments.\n\
15581This is used to cancel the effect of the \"disable\" command.\n\
1bedd215 15582May be abbreviated to simply \"enable\".\n"),
c5aa993b 15583 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
c906108c 15584
1a966eab
AC
15585 add_cmd ("once", no_class, enable_once_command, _("\
15586Enable breakpoints for one hit. Give breakpoint numbers.\n\
15587If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
c906108c
SS
15588 &enablebreaklist);
15589
1a966eab
AC
15590 add_cmd ("delete", no_class, enable_delete_command, _("\
15591Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15592If a breakpoint is hit while enabled in this fashion, it is deleted."),
c906108c
SS
15593 &enablebreaklist);
15594
816338b5
SS
15595 add_cmd ("count", no_class, enable_count_command, _("\
15596Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15597If a breakpoint is hit while enabled in this fashion,\n\
15598the count is decremented; when it reaches zero, the breakpoint is disabled."),
15599 &enablebreaklist);
15600
1a966eab
AC
15601 add_cmd ("delete", no_class, enable_delete_command, _("\
15602Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15603If a breakpoint is hit while enabled in this fashion, it is deleted."),
c906108c
SS
15604 &enablelist);
15605
1a966eab
AC
15606 add_cmd ("once", no_class, enable_once_command, _("\
15607Enable breakpoints for one hit. Give breakpoint numbers.\n\
15608If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
816338b5
SS
15609 &enablelist);
15610
15611 add_cmd ("count", no_class, enable_count_command, _("\
15612Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15613If a breakpoint is hit while enabled in this fashion,\n\
15614the count is decremented; when it reaches zero, the breakpoint is disabled."),
c906108c
SS
15615 &enablelist);
15616
1bedd215
AC
15617 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
15618Disable some breakpoints.\n\
c906108c
SS
15619Arguments are breakpoint numbers with spaces in between.\n\
15620To disable all breakpoints, give no argument.\n\
64b9b334 15621A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
c906108c
SS
15622 &disablelist, "disable ", 1, &cmdlist);
15623 add_com_alias ("dis", "disable", class_breakpoint, 1);
15624 add_com_alias ("disa", "disable", class_breakpoint, 1);
15625 if (xdb_commands)
1bedd215
AC
15626 add_com ("sb", class_breakpoint, disable_command, _("\
15627Disable some breakpoints.\n\
c906108c
SS
15628Arguments are breakpoint numbers with spaces in between.\n\
15629To disable all breakpoints, give no argument.\n\
64b9b334 15630A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
c906108c 15631
1a966eab
AC
15632 add_cmd ("breakpoints", class_alias, disable_command, _("\
15633Disable some breakpoints.\n\
c906108c
SS
15634Arguments are breakpoint numbers with spaces in between.\n\
15635To disable all breakpoints, give no argument.\n\
64b9b334 15636A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
1a966eab 15637This command may be abbreviated \"disable\"."),
c906108c
SS
15638 &disablelist);
15639
1bedd215
AC
15640 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
15641Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
15642Arguments are breakpoint numbers with spaces in between.\n\
15643To delete all breakpoints, give no argument.\n\
15644\n\
15645Also a prefix command for deletion of other GDB objects.\n\
1bedd215 15646The \"unset\" command is also an alias for \"delete\"."),
c906108c
SS
15647 &deletelist, "delete ", 1, &cmdlist);
15648 add_com_alias ("d", "delete", class_breakpoint, 1);
7f198e01 15649 add_com_alias ("del", "delete", class_breakpoint, 1);
c906108c 15650 if (xdb_commands)
1bedd215
AC
15651 add_com ("db", class_breakpoint, delete_command, _("\
15652Delete some breakpoints.\n\
c906108c 15653Arguments are breakpoint numbers with spaces in between.\n\
1bedd215 15654To delete all breakpoints, give no argument.\n"));
c906108c 15655
1a966eab
AC
15656 add_cmd ("breakpoints", class_alias, delete_command, _("\
15657Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
15658Arguments are breakpoint numbers with spaces in between.\n\
15659To delete all breakpoints, give no argument.\n\
1a966eab 15660This command may be abbreviated \"delete\"."),
c906108c
SS
15661 &deletelist);
15662
1bedd215
AC
15663 add_com ("clear", class_breakpoint, clear_command, _("\
15664Clear breakpoint at specified line or function.\n\
c906108c
SS
15665Argument may be line number, function name, or \"*\" and an address.\n\
15666If line number is specified, all breakpoints in that line are cleared.\n\
15667If function is specified, breakpoints at beginning of function are cleared.\n\
1bedd215
AC
15668If an address is specified, breakpoints at that address are cleared.\n\
15669\n\
15670With no argument, clears all breakpoints in the line that the selected frame\n\
c906108c
SS
15671is executing in.\n\
15672\n\
1bedd215 15673See also the \"delete\" command which clears breakpoints by number."));
a6cc4789 15674 add_com_alias ("cl", "clear", class_breakpoint, 1);
c906108c 15675
1bedd215 15676 c = add_com ("break", class_breakpoint, break_command, _("\
31e2b00f
AS
15677Set breakpoint at specified line or function.\n"
15678BREAK_ARGS_HELP ("break")));
5ba2abeb 15679 set_cmd_completer (c, location_completer);
c94fdfd0 15680
c906108c
SS
15681 add_com_alias ("b", "break", class_run, 1);
15682 add_com_alias ("br", "break", class_run, 1);
15683 add_com_alias ("bre", "break", class_run, 1);
15684 add_com_alias ("brea", "break", class_run, 1);
15685
7681d515
PM
15686 if (xdb_commands)
15687 add_com_alias ("ba", "break", class_breakpoint, 1);
c906108c
SS
15688
15689 if (dbx_commands)
15690 {
1bedd215
AC
15691 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
15692Break in function/address or break at a line in the current file."),
c5aa993b
JM
15693 &stoplist, "stop ", 1, &cmdlist);
15694 add_cmd ("in", class_breakpoint, stopin_command,
1a966eab 15695 _("Break in function or address."), &stoplist);
c5aa993b 15696 add_cmd ("at", class_breakpoint, stopat_command,
1a966eab 15697 _("Break at a line in the current file."), &stoplist);
1bedd215
AC
15698 add_com ("status", class_info, breakpoints_info, _("\
15699Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
15700The \"Type\" column indicates one of:\n\
15701\tbreakpoint - normal breakpoint\n\
15702\twatchpoint - watchpoint\n\
15703The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15704the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15705breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1bedd215
AC
15706address and file/line number respectively.\n\
15707\n\
15708Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
15709are set to the address of the last breakpoint listed unless the command\n\
15710is prefixed with \"server \".\n\n\
c906108c 15711Convenience variable \"$bpnum\" contains the number of the last\n\
1bedd215 15712breakpoint set."));
c906108c
SS
15713 }
15714
1bedd215 15715 add_info ("breakpoints", breakpoints_info, _("\
e5a67952 15716Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
c906108c
SS
15717The \"Type\" column indicates one of:\n\
15718\tbreakpoint - normal breakpoint\n\
15719\twatchpoint - watchpoint\n\
15720The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15721the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15722breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1bedd215
AC
15723address and file/line number respectively.\n\
15724\n\
15725Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
15726are set to the address of the last breakpoint listed unless the command\n\
15727is prefixed with \"server \".\n\n\
c906108c 15728Convenience variable \"$bpnum\" contains the number of the last\n\
1bedd215 15729breakpoint set."));
c906108c 15730
6b04bdb7
MS
15731 add_info_alias ("b", "breakpoints", 1);
15732
c906108c 15733 if (xdb_commands)
1bedd215
AC
15734 add_com ("lb", class_breakpoint, breakpoints_info, _("\
15735Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
15736The \"Type\" column indicates one of:\n\
15737\tbreakpoint - normal breakpoint\n\
15738\twatchpoint - watchpoint\n\
15739The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15740the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15741breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1bedd215
AC
15742address and file/line number respectively.\n\
15743\n\
15744Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
15745are set to the address of the last breakpoint listed unless the command\n\
15746is prefixed with \"server \".\n\n\
c906108c 15747Convenience variable \"$bpnum\" contains the number of the last\n\
1bedd215 15748breakpoint set."));
c906108c 15749
1a966eab
AC
15750 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
15751Status of all breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
15752The \"Type\" column indicates one of:\n\
15753\tbreakpoint - normal breakpoint\n\
15754\twatchpoint - watchpoint\n\
15755\tlongjmp - internal breakpoint used to step through longjmp()\n\
15756\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15757\tuntil - internal breakpoint used by the \"until\" command\n\
1a966eab
AC
15758\tfinish - internal breakpoint used by the \"finish\" command\n\
15759The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
c906108c
SS
15760the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15761breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1a966eab
AC
15762address and file/line number respectively.\n\
15763\n\
15764Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
15765are set to the address of the last breakpoint listed unless the command\n\
15766is prefixed with \"server \".\n\n\
c906108c 15767Convenience variable \"$bpnum\" contains the number of the last\n\
1a966eab 15768breakpoint set."),
c906108c
SS
15769 &maintenanceinfolist);
15770
44feb3ce
TT
15771 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
15772Set catchpoints to catch events."),
15773 &catch_cmdlist, "catch ",
15774 0/*allow-unknown*/, &cmdlist);
15775
15776 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
15777Set temporary catchpoints to catch events."),
15778 &tcatch_cmdlist, "tcatch ",
15779 0/*allow-unknown*/, &cmdlist);
15780
15781 /* Add catch and tcatch sub-commands. */
15782 add_catch_command ("catch", _("\
88e7d25d 15783Catch an exception, when caught."),
44feb3ce 15784 catch_catch_command,
a96d9b2e 15785 NULL,
44feb3ce
TT
15786 CATCH_PERMANENT,
15787 CATCH_TEMPORARY);
15788 add_catch_command ("throw", _("\
88e7d25d 15789Catch an exception, when thrown."),
44feb3ce 15790 catch_throw_command,
a96d9b2e 15791 NULL,
44feb3ce
TT
15792 CATCH_PERMANENT,
15793 CATCH_TEMPORARY);
15794 add_catch_command ("fork", _("Catch calls to fork."),
15795 catch_fork_command_1,
a96d9b2e 15796 NULL,
44feb3ce
TT
15797 (void *) (uintptr_t) catch_fork_permanent,
15798 (void *) (uintptr_t) catch_fork_temporary);
15799 add_catch_command ("vfork", _("Catch calls to vfork."),
15800 catch_fork_command_1,
a96d9b2e 15801 NULL,
44feb3ce
TT
15802 (void *) (uintptr_t) catch_vfork_permanent,
15803 (void *) (uintptr_t) catch_vfork_temporary);
15804 add_catch_command ("exec", _("Catch calls to exec."),
15805 catch_exec_command_1,
a96d9b2e
SDJ
15806 NULL,
15807 CATCH_PERMANENT,
15808 CATCH_TEMPORARY);
edcc5120
TT
15809 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15810Usage: catch load [REGEX]\n\
15811If REGEX is given, only stop for libraries matching the regular expression."),
15812 catch_load_command_1,
15813 NULL,
15814 CATCH_PERMANENT,
15815 CATCH_TEMPORARY);
15816 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15817Usage: catch unload [REGEX]\n\
15818If REGEX is given, only stop for libraries matching the regular expression."),
15819 catch_unload_command_1,
15820 NULL,
15821 CATCH_PERMANENT,
15822 CATCH_TEMPORARY);
a96d9b2e
SDJ
15823 add_catch_command ("syscall", _("\
15824Catch system calls by their names and/or numbers.\n\
15825Arguments say which system calls to catch. If no arguments\n\
15826are given, every system call will be caught.\n\
15827Arguments, if given, should be one or more system call names\n\
15828(if your system supports that), or system call numbers."),
15829 catch_syscall_command_1,
15830 catch_syscall_completer,
44feb3ce
TT
15831 CATCH_PERMANENT,
15832 CATCH_TEMPORARY);
c5aa993b 15833
1bedd215
AC
15834 c = add_com ("watch", class_breakpoint, watch_command, _("\
15835Set a watchpoint for an expression.\n\
06a64a0b 15836Usage: watch [-l|-location] EXPRESSION\n\
c906108c 15837A watchpoint stops execution of your program whenever the value of\n\
06a64a0b
TT
15838an expression changes.\n\
15839If -l or -location is given, this evaluates EXPRESSION and watches\n\
15840the memory to which it refers."));
65d12d83 15841 set_cmd_completer (c, expression_completer);
c906108c 15842
1bedd215
AC
15843 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
15844Set a read watchpoint for an expression.\n\
06a64a0b 15845Usage: rwatch [-l|-location] EXPRESSION\n\
c906108c 15846A watchpoint stops execution of your program whenever the value of\n\
06a64a0b
TT
15847an expression is read.\n\
15848If -l or -location is given, this evaluates EXPRESSION and watches\n\
15849the memory to which it refers."));
65d12d83 15850 set_cmd_completer (c, expression_completer);
c906108c 15851
1bedd215
AC
15852 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
15853Set a watchpoint for an expression.\n\
06a64a0b 15854Usage: awatch [-l|-location] EXPRESSION\n\
c906108c 15855A watchpoint stops execution of your program whenever the value of\n\
06a64a0b
TT
15856an expression is either read or written.\n\
15857If -l or -location is given, this evaluates EXPRESSION and watches\n\
15858the memory to which it refers."));
65d12d83 15859 set_cmd_completer (c, expression_completer);
c906108c 15860
d77f58be 15861 add_info ("watchpoints", watchpoints_info, _("\
e5a67952 15862Status of specified watchpoints (all watchpoints if no argument)."));
c906108c 15863
920d2a44
AC
15864 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15865 respond to changes - contrary to the description. */
85c07804
AC
15866 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
15867 &can_use_hw_watchpoints, _("\
15868Set debugger's willingness to use watchpoint hardware."), _("\
15869Show debugger's willingness to use watchpoint hardware."), _("\
c906108c
SS
15870If zero, gdb will not use hardware for new watchpoints, even if\n\
15871such is available. (However, any hardware watchpoints that were\n\
15872created before setting this to nonzero, will continue to use watchpoint\n\
85c07804
AC
15873hardware.)"),
15874 NULL,
920d2a44 15875 show_can_use_hw_watchpoints,
85c07804 15876 &setlist, &showlist);
c906108c
SS
15877
15878 can_use_hw_watchpoints = 1;
fa8d40ab 15879
1042e4c0
SS
15880 /* Tracepoint manipulation commands. */
15881
15882 c = add_com ("trace", class_breakpoint, trace_command, _("\
15883Set a tracepoint at specified line or function.\n\
15884\n"
15885BREAK_ARGS_HELP ("trace") "\n\
15886Do \"help tracepoints\" for info on other tracepoint commands."));
15887 set_cmd_completer (c, location_completer);
15888
15889 add_com_alias ("tp", "trace", class_alias, 0);
15890 add_com_alias ("tr", "trace", class_alias, 1);
15891 add_com_alias ("tra", "trace", class_alias, 1);
15892 add_com_alias ("trac", "trace", class_alias, 1);
15893
7a697b8d
SS
15894 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
15895Set a fast tracepoint at specified line or function.\n\
15896\n"
15897BREAK_ARGS_HELP ("ftrace") "\n\
15898Do \"help tracepoints\" for info on other tracepoint commands."));
15899 set_cmd_completer (c, location_completer);
15900
0fb4aa4b
PA
15901 c = add_com ("strace", class_breakpoint, strace_command, _("\
15902Set a static tracepoint at specified line, function or marker.\n\
15903\n\
15904strace [LOCATION] [if CONDITION]\n\
15905LOCATION may be a line number, function name, \"*\" and an address,\n\
15906or -m MARKER_ID.\n\
15907If a line number is specified, probe the marker at start of code\n\
15908for that line. If a function is specified, probe the marker at start\n\
15909of code for that function. If an address is specified, probe the marker\n\
15910at that exact address. If a marker id is specified, probe the marker\n\
15911with that name. With no LOCATION, uses current execution address of\n\
15912the selected stack frame.\n\
15913Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15914This collects arbitrary user data passed in the probe point call to the\n\
15915tracing library. You can inspect it when analyzing the trace buffer,\n\
15916by printing the $_sdata variable like any other convenience variable.\n\
15917\n\
15918CONDITION is a boolean expression.\n\
15919\n\
d41c0fc8
PA
15920Multiple tracepoints at one place are permitted, and useful if their\n\
15921conditions are different.\n\
0fb4aa4b
PA
15922\n\
15923Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15924Do \"help tracepoints\" for info on other tracepoint commands."));
15925 set_cmd_completer (c, location_completer);
15926
1042e4c0 15927 add_info ("tracepoints", tracepoints_info, _("\
e5a67952 15928Status of specified tracepoints (all tracepoints if no argument).\n\
1042e4c0
SS
15929Convenience variable \"$tpnum\" contains the number of the\n\
15930last tracepoint set."));
15931
15932 add_info_alias ("tp", "tracepoints", 1);
15933
15934 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
15935Delete specified tracepoints.\n\
15936Arguments are tracepoint numbers, separated by spaces.\n\
15937No argument means delete all tracepoints."),
15938 &deletelist);
15939
15940 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
15941Disable specified tracepoints.\n\
15942Arguments are tracepoint numbers, separated by spaces.\n\
15943No argument means disable all tracepoints."),
15944 &disablelist);
15945 deprecate_cmd (c, "disable");
15946
15947 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
15948Enable specified tracepoints.\n\
15949Arguments are tracepoint numbers, separated by spaces.\n\
15950No argument means enable all tracepoints."),
15951 &enablelist);
15952 deprecate_cmd (c, "enable");
15953
15954 add_com ("passcount", class_trace, trace_pass_command, _("\
15955Set the passcount for a tracepoint.\n\
15956The trace will end when the tracepoint has been passed 'count' times.\n\
15957Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15958if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15959
6149aea9
PA
15960 add_prefix_cmd ("save", class_breakpoint, save_command,
15961 _("Save breakpoint definitions as a script."),
15962 &save_cmdlist, "save ",
15963 0/*allow-unknown*/, &cmdlist);
15964
15965 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\
15966Save current breakpoint definitions as a script.\n\
cce7e648 15967This includes all types of breakpoints (breakpoints, watchpoints,\n\
6149aea9
PA
15968catchpoints, tracepoints). Use the 'source' command in another debug\n\
15969session to restore them."),
15970 &save_cmdlist);
15971 set_cmd_completer (c, filename_completer);
15972
15973 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
1042e4c0 15974Save current tracepoint definitions as a script.\n\
6149aea9
PA
15975Use the 'source' command in another debug session to restore them."),
15976 &save_cmdlist);
1042e4c0
SS
15977 set_cmd_completer (c, filename_completer);
15978
6149aea9
PA
15979 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
15980 deprecate_cmd (c, "save tracepoints");
15981
1bedd215 15982 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
fa8d40ab
JJ
15983Breakpoint specific settings\n\
15984Configure various breakpoint-specific variables such as\n\
1bedd215 15985pending breakpoint behavior"),
fa8d40ab
JJ
15986 &breakpoint_set_cmdlist, "set breakpoint ",
15987 0/*allow-unknown*/, &setlist);
1bedd215 15988 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
fa8d40ab
JJ
15989Breakpoint specific settings\n\
15990Configure various breakpoint-specific variables such as\n\
1bedd215 15991pending breakpoint behavior"),
fa8d40ab
JJ
15992 &breakpoint_show_cmdlist, "show breakpoint ",
15993 0/*allow-unknown*/, &showlist);
15994
7915a72c
AC
15995 add_setshow_auto_boolean_cmd ("pending", no_class,
15996 &pending_break_support, _("\
15997Set debugger's behavior regarding pending breakpoints."), _("\
15998Show debugger's behavior regarding pending breakpoints."), _("\
6e1d7d6c
AC
15999If on, an unrecognized breakpoint location will cause gdb to create a\n\
16000pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16001an error. If auto, an unrecognized breakpoint location results in a\n\
7915a72c 16002user-query to see if a pending breakpoint should be created."),
2c5b56ce 16003 NULL,
920d2a44 16004 show_pending_break_support,
6e1d7d6c
AC
16005 &breakpoint_set_cmdlist,
16006 &breakpoint_show_cmdlist);
fa8d40ab
JJ
16007
16008 pending_break_support = AUTO_BOOLEAN_AUTO;
765dc015
VP
16009
16010 add_setshow_boolean_cmd ("auto-hw", no_class,
16011 &automatic_hardware_breakpoints, _("\
16012Set automatic usage of hardware breakpoints."), _("\
16013Show automatic usage of hardware breakpoints."), _("\
16014If set, the debugger will automatically use hardware breakpoints for\n\
16015breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16016a warning will be emitted for such breakpoints."),
16017 NULL,
16018 show_automatic_hardware_breakpoints,
16019 &breakpoint_set_cmdlist,
16020 &breakpoint_show_cmdlist);
74960c60 16021
33e5cbd6
PA
16022 add_setshow_enum_cmd ("always-inserted", class_support,
16023 always_inserted_enums, &always_inserted_mode, _("\
74960c60
VP
16024Set mode for inserting breakpoints."), _("\
16025Show mode for inserting breakpoints."), _("\
33e5cbd6
PA
16026When this mode is off, breakpoints are inserted in inferior when it is\n\
16027resumed, and removed when execution stops. When this mode is on,\n\
16028breakpoints are inserted immediately and removed only when the user\n\
16029deletes the breakpoint. When this mode is auto (which is the default),\n\
16030the behaviour depends on the non-stop setting (see help set non-stop).\n\
16031In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16032behaves as if always-inserted mode is on; if gdb is controlling the\n\
16033inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
74960c60
VP
16034 NULL,
16035 &show_always_inserted_mode,
16036 &breakpoint_set_cmdlist,
16037 &breakpoint_show_cmdlist);
f1310107 16038
b775012e
LM
16039 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint,
16040 condition_evaluation_enums,
16041 &condition_evaluation_mode_1, _("\
16042Set mode of breakpoint condition evaluation."), _("\
16043Show mode of breakpoint condition evaluation."), _("\
d1cda5d9 16044When this is set to \"host\", breakpoint conditions will be\n\
b775012e
LM
16045evaluated on the host's side by GDB. When it is set to \"target\",\n\
16046breakpoint conditions will be downloaded to the target (if the target\n\
16047supports such feature) and conditions will be evaluated on the target's side.\n\
16048If this is set to \"auto\" (default), this will be automatically set to\n\
16049\"target\" if it supports condition evaluation, otherwise it will\n\
16050be set to \"gdb\""),
16051 &set_condition_evaluation_mode,
16052 &show_condition_evaluation_mode,
16053 &breakpoint_set_cmdlist,
16054 &breakpoint_show_cmdlist);
16055
f1310107
TJB
16056 add_com ("break-range", class_breakpoint, break_range_command, _("\
16057Set a breakpoint for an address range.\n\
16058break-range START-LOCATION, END-LOCATION\n\
16059where START-LOCATION and END-LOCATION can be one of the following:\n\
16060 LINENUM, for that line in the current file,\n\
16061 FILE:LINENUM, for that line in that file,\n\
16062 +OFFSET, for that number of lines after the current line\n\
16063 or the start of the range\n\
16064 FUNCTION, for the first line in that function,\n\
16065 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16066 *ADDRESS, for the instruction at that address.\n\
16067\n\
16068The breakpoint will stop execution of the inferior whenever it executes\n\
16069an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16070range (including START-LOCATION and END-LOCATION)."));
16071
e7e0cddf
SS
16072 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\
16073Set a dynamic printf at specified line or function.\n\
16074dprintf location,format string,arg1,arg2,...\n\
16075location may be a line number, function name, or \"*\" and an address.\n\
16076If a line number is specified, break at start of code for that line.\n\
16077If a function is specified, break at start of code for that function.\n\
16078"));
16079 set_cmd_completer (c, location_completer);
16080
16081 add_setshow_enum_cmd ("dprintf-style", class_support,
16082 dprintf_style_enums, &dprintf_style, _("\
16083Set the style of usage for dynamic printf."), _("\
16084Show the style of usage for dynamic printf."), _("\
16085This setting chooses how GDB will do a dynamic printf.\n\
16086If the value is \"gdb\", then the printing is done by GDB to its own\n\
16087console, as with the \"printf\" command.\n\
16088If the value is \"call\", the print is done by calling a function in your\n\
16089program; by default printf(), but you can choose a different function or\n\
16090output stream by setting dprintf-function and dprintf-channel."),
16091 update_dprintf_commands, NULL,
16092 &setlist, &showlist);
16093
16094 dprintf_function = xstrdup ("printf");
16095 add_setshow_string_cmd ("dprintf-function", class_support,
16096 &dprintf_function, _("\
16097Set the function to use for dynamic printf"), _("\
16098Show the function to use for dynamic printf"), NULL,
16099 update_dprintf_commands, NULL,
16100 &setlist, &showlist);
16101
16102 dprintf_channel = xstrdup ("");
16103 add_setshow_string_cmd ("dprintf-channel", class_support,
16104 &dprintf_channel, _("\
16105Set the channel to use for dynamic printf"), _("\
16106Show the channel to use for dynamic printf"), NULL,
16107 update_dprintf_commands, NULL,
16108 &setlist, &showlist);
16109
765dc015 16110 automatic_hardware_breakpoints = 1;
f3b1572e
PA
16111
16112 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
c906108c 16113}
This page took 2.303889 seconds and 4 git commands to generate.