* dwarf2read.c (dwarf_decode_lines): Ignore rows where is_stmt is 0.
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
CommitLineData
c906108c 1/* Everything about breakpoints, for GDB.
8926118c 2
6aba47ca 3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
9b254dd1 4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
0fb0cc75 5 2008, 2009 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
23#include <ctype.h>
776592bf 24#include "hashtab.h"
c906108c
SS
25#include "symtab.h"
26#include "frame.h"
27#include "breakpoint.h"
1042e4c0 28#include "tracepoint.h"
c906108c
SS
29#include "gdbtypes.h"
30#include "expression.h"
31#include "gdbcore.h"
32#include "gdbcmd.h"
33#include "value.h"
34#include "command.h"
35#include "inferior.h"
36#include "gdbthread.h"
37#include "target.h"
38#include "language.h"
39#include "gdb_string.h"
40#include "demangle.h"
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"
fa4727a6 59#include "wrapper.h"
79a45b7d 60#include "valprint.h"
c906108c 61
1042e4c0
SS
62/* readline include files */
63#include "readline/readline.h"
64#include "readline/history.h"
65
66/* readline defines this. */
67#undef savestring
68
034dad6f 69#include "mi/mi-common.h"
104c1213 70
44feb3ce
TT
71/* Arguments to pass as context to some catch command handlers. */
72#define CATCH_PERMANENT ((void *) (uintptr_t) 0)
73#define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
c906108c 74
44feb3ce 75/* Prototypes for local functions. */
c906108c 76
a14ed312 77static void enable_delete_command (char *, int);
c906108c 78
a14ed312 79static void enable_delete_breakpoint (struct breakpoint *);
c906108c 80
a14ed312 81static void enable_once_command (char *, int);
c906108c 82
a14ed312 83static void enable_once_breakpoint (struct breakpoint *);
c906108c 84
a14ed312 85static void disable_command (char *, int);
c906108c 86
a14ed312 87static void enable_command (char *, int);
c906108c 88
a14ed312 89static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
c906108c 90
a14ed312 91static void ignore_command (char *, int);
c906108c 92
4efb68b1 93static int breakpoint_re_set_one (void *);
c906108c 94
a14ed312 95static void clear_command (char *, int);
c906108c 96
a14ed312 97static void catch_command (char *, int);
c906108c 98
a14ed312 99static void watch_command (char *, int);
c906108c 100
a14ed312 101static int can_use_hardware_watchpoint (struct value *);
c906108c 102
98deb0da 103static void break_command_1 (char *, int, int);
c906108c 104
a14ed312 105static void mention (struct breakpoint *);
c906108c 106
4d28f7a8 107struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
c906108c 108
9f60f21b 109static void check_duplicates (struct breakpoint *);
c906108c 110
76897487
KB
111static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
112
88f7da05
KB
113static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
114 enum bptype bptype);
76897487 115
714835d5 116static void describe_other_breakpoints (CORE_ADDR, struct obj_section *, int);
c906108c 117
a14ed312 118static void breakpoints_info (char *, int);
c906108c 119
a14ed312 120static void breakpoint_1 (int, int);
c906108c 121
89f9893c 122static bpstat bpstat_alloc (const struct bp_location *, bpstat);
c906108c 123
4efb68b1 124static int breakpoint_cond_eval (void *);
c906108c 125
4efb68b1 126static void cleanup_executing_breakpoints (void *);
c906108c 127
a14ed312 128static void commands_command (char *, int);
c906108c 129
a14ed312 130static void condition_command (char *, int);
c906108c 131
a14ed312 132static int get_number_trailer (char **, int);
c906108c 133
a14ed312 134void set_breakpoint_count (int);
c906108c 135
c5aa993b
JM
136typedef enum
137 {
138 mark_inserted,
139 mark_uninserted
140 }
141insertion_state_t;
c906108c 142
0bde7532 143static int remove_breakpoint (struct bp_location *, insertion_state_t);
c906108c 144
a14ed312 145static enum print_stop_action print_it_typical (bpstat);
e514a9d6
JM
146
147static enum print_stop_action print_bp_stop_message (bpstat bs);
c906108c 148
4efb68b1 149static int watchpoint_check (void *);
c906108c 150
a14ed312 151static void maintenance_info_breakpoints (char *, int);
c906108c 152
a14ed312 153static int hw_breakpoint_used_count (void);
c906108c 154
a14ed312 155static int hw_watchpoint_used_count (enum bptype, int *);
c906108c 156
a14ed312 157static void hbreak_command (char *, int);
c906108c 158
a14ed312 159static void thbreak_command (char *, int);
c906108c 160
a14ed312 161static void watch_command_1 (char *, int, int);
c906108c 162
a14ed312 163static void rwatch_command (char *, int);
c906108c 164
a14ed312 165static void awatch_command (char *, int);
c906108c 166
a14ed312 167static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
c906108c 168
a14ed312 169static void stop_command (char *arg, int from_tty);
7a292a7a 170
a14ed312 171static void stopin_command (char *arg, int from_tty);
7a292a7a 172
a14ed312 173static void stopat_command (char *arg, int from_tty);
7a292a7a 174
a14ed312 175static char *ep_parse_optional_if_clause (char **arg);
7a292a7a 176
a14ed312 177static char *ep_parse_optional_filename (char **arg);
7a292a7a 178
d85310f7
MS
179static void catch_exception_command_1 (enum exception_event_kind ex_event,
180 char *arg, int tempflag, int from_tty);
7a292a7a 181
a14ed312 182static void tcatch_command (char *arg, int from_tty);
7a292a7a 183
a14ed312 184static void ep_skip_leading_whitespace (char **s);
7a292a7a 185
1aafd4da
UW
186static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
187
fe3f5fa8
VP
188static void free_bp_location (struct bp_location *loc);
189
39d61571 190static struct bp_location *allocate_bp_location (struct breakpoint *bpt);
a5606eee 191
b60e7edf 192static void update_global_location_list (int);
a5606eee 193
b60e7edf 194static void update_global_location_list_nothrow (int);
74960c60
VP
195
196static int is_hardware_watchpoint (struct breakpoint *bpt);
197
198static void insert_breakpoint_locations (void);
a5606eee 199
1042e4c0
SS
200static void tracepoints_info (char *, int);
201
202static void delete_trace_command (char *, int);
203
204static void enable_trace_command (char *, int);
205
206static void disable_trace_command (char *, int);
207
208static void trace_pass_command (char *, int);
209
3daf8fe5
JG
210static void skip_prologue_sal (struct symtab_and_line *sal);
211
212
f3b1572e
PA
213/* Flag indicating that a command has proceeded the inferior past the
214 current breakpoint. */
215
216static int breakpoint_proceeded;
217
2cec12e5
AR
218static const char *
219bpdisp_text (enum bpdisp disp)
220{
221 /* NOTE: the following values are a part of MI protocol and represent
222 values of 'disp' field returned when inferior stops at a breakpoint. */
223 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
224 return bpdisps[(int) disp];
225}
c906108c 226
2cec12e5 227/* Prototypes for exported functions. */
c906108c
SS
228/* If FALSE, gdb will not use hardware support for watchpoints, even
229 if such is available. */
230static int can_use_hw_watchpoints;
231
920d2a44
AC
232static void
233show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
234 struct cmd_list_element *c,
235 const char *value)
236{
237 fprintf_filtered (file, _("\
238Debugger's willingness to use watchpoint hardware is %s.\n"),
239 value);
240}
241
fa8d40ab
JJ
242/* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
243 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
244 for unrecognized breakpoint locations.
245 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
246static enum auto_boolean pending_break_support;
920d2a44
AC
247static void
248show_pending_break_support (struct ui_file *file, int from_tty,
249 struct cmd_list_element *c,
250 const char *value)
251{
252 fprintf_filtered (file, _("\
253Debugger's behavior regarding pending breakpoints is %s.\n"),
254 value);
255}
fa8d40ab 256
765dc015
VP
257/* If 1, gdb will automatically use hardware breakpoints for breakpoints
258 set with "break" but falling in read-only memory.
259 If 0, gdb will warn about such breakpoints, but won't automatically
260 use hardware breakpoints. */
261static int automatic_hardware_breakpoints;
262static void
263show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
264 struct cmd_list_element *c,
265 const char *value)
266{
267 fprintf_filtered (file, _("\
268Automatic usage of hardware breakpoints is %s.\n"),
269 value);
270}
271
33e5cbd6
PA
272/* If on, gdb will keep breakpoints inserted even as inferior is
273 stopped, and immediately insert any new breakpoints. If off, gdb
274 will insert breakpoints into inferior only when resuming it, and
275 will remove breakpoints upon stop. If auto, GDB will behave as ON
276 if in non-stop mode, and as OFF if all-stop mode.*/
277
278static const char always_inserted_auto[] = "auto";
279static const char always_inserted_on[] = "on";
280static const char always_inserted_off[] = "off";
281static const char *always_inserted_enums[] = {
282 always_inserted_auto,
283 always_inserted_off,
284 always_inserted_on,
285 NULL
286};
287static const char *always_inserted_mode = always_inserted_auto;
288static void
74960c60 289show_always_inserted_mode (struct ui_file *file, int from_tty,
33e5cbd6 290 struct cmd_list_element *c, const char *value)
74960c60 291{
33e5cbd6
PA
292 if (always_inserted_mode == always_inserted_auto)
293 fprintf_filtered (file, _("\
294Always inserted breakpoint mode is %s (currently %s).\n"),
295 value,
296 breakpoints_always_inserted_mode () ? "on" : "off");
297 else
298 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
74960c60
VP
299}
300
33e5cbd6
PA
301int
302breakpoints_always_inserted_mode (void)
303{
304 return (always_inserted_mode == always_inserted_on
305 || (always_inserted_mode == always_inserted_auto && non_stop));
306}
765dc015 307
a14ed312 308void _initialize_breakpoint (void);
c906108c 309
c906108c
SS
310/* Are we executing breakpoint commands? */
311static int executing_breakpoint_commands;
312
c02f5703
MS
313/* Are overlay event breakpoints enabled? */
314static int overlay_events_enabled;
315
c906108c
SS
316/* Walk the following statement or block through all breakpoints.
317 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
318 breakpoint. */
319
5c44784c 320#define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
c906108c 321
5c44784c
JM
322#define ALL_BREAKPOINTS_SAFE(B,TMP) \
323 for (B = breakpoint_chain; \
324 B ? (TMP=B->next, 1): 0; \
325 B = TMP)
c906108c 326
7cc221ef
DJ
327/* Similar iterators for the low-level breakpoints. */
328
0d381245 329#define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
7cc221ef
DJ
330
331#define ALL_BP_LOCATIONS_SAFE(B,TMP) \
332 for (B = bp_location_chain; \
0d381245 333 B ? (TMP=B->global_next, 1): 0; \
7cc221ef
DJ
334 B = TMP)
335
1042e4c0
SS
336/* Iterator for tracepoints only. */
337
338#define ALL_TRACEPOINTS(B) \
339 for (B = breakpoint_chain; B; B = B->next) \
340 if ((B)->type == bp_tracepoint)
341
7cc221ef 342/* Chains of all breakpoints defined. */
c906108c
SS
343
344struct breakpoint *breakpoint_chain;
345
7cc221ef
DJ
346struct bp_location *bp_location_chain;
347
20874c92
VP
348/* The locations that no longer correspond to any breakpoint,
349 unlinked from bp_location_chain, but for which a hit
350 may still be reported by a target. */
351VEC(bp_location_p) *moribund_locations = NULL;
352
c906108c
SS
353/* Number of last breakpoint made. */
354
355int breakpoint_count;
356
1042e4c0
SS
357/* Number of last tracepoint made. */
358
359int tracepoint_count;
360
468d015d
JJ
361/* Return whether a breakpoint is an active enabled breakpoint. */
362static int
363breakpoint_enabled (struct breakpoint *b)
364{
0d381245 365 return (b->enable_state == bp_enabled);
468d015d
JJ
366}
367
c906108c
SS
368/* Set breakpoint count to NUM. */
369
370void
fba45db2 371set_breakpoint_count (int num)
c906108c
SS
372{
373 breakpoint_count = num;
4fa62494 374 set_internalvar_integer (lookup_internalvar ("bpnum"), num);
c906108c
SS
375}
376
377/* Used in run_command to zero the hit count when a new run starts. */
378
379void
fba45db2 380clear_breakpoint_hit_counts (void)
c906108c
SS
381{
382 struct breakpoint *b;
383
384 ALL_BREAKPOINTS (b)
385 b->hit_count = 0;
386}
387
388/* Default address, symtab and line to put a breakpoint at
389 for "break" command with no arg.
390 if default_breakpoint_valid is zero, the other three are
391 not valid, and "break" with no arg is an error.
392
393 This set by print_stack_frame, which calls set_default_breakpoint. */
394
395int default_breakpoint_valid;
396CORE_ADDR default_breakpoint_address;
397struct symtab *default_breakpoint_symtab;
398int default_breakpoint_line;
399\f
400/* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
401 Advance *PP after the string and any trailing whitespace.
402
403 Currently the string can either be a number or "$" followed by the name
404 of a convenience variable. Making it an expression wouldn't work well
5c44784c 405 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
40c03ae8
EZ
406
407 If the string is a NULL pointer, that denotes the last breakpoint.
5c44784c
JM
408
409 TRAILER is a character which can be found after the number; most
410 commonly this is `-'. If you don't want a trailer, use \0. */
c906108c 411static int
fba45db2 412get_number_trailer (char **pp, int trailer)
c906108c 413{
5c44784c 414 int retval = 0; /* default */
c906108c
SS
415 char *p = *pp;
416
417 if (p == NULL)
418 /* Empty line means refer to the last breakpoint. */
419 return breakpoint_count;
420 else if (*p == '$')
421 {
422 /* Make a copy of the name, so we can null-terminate it
c5aa993b 423 to pass to lookup_internalvar(). */
c906108c
SS
424 char *varname;
425 char *start = ++p;
4fa62494 426 LONGEST val;
c906108c
SS
427
428 while (isalnum (*p) || *p == '_')
429 p++;
430 varname = (char *) alloca (p - start + 1);
431 strncpy (varname, start, p - start);
432 varname[p - start] = '\0';
4fa62494
UW
433 if (get_internalvar_integer (lookup_internalvar (varname), &val))
434 retval = (int) val;
5c44784c
JM
435 else
436 {
a3f17187 437 printf_filtered (_("Convenience variable must have integer value.\n"));
5c44784c
JM
438 retval = 0;
439 }
c906108c
SS
440 }
441 else
442 {
443 if (*p == '-')
444 ++p;
445 while (*p >= '0' && *p <= '9')
446 ++p;
447 if (p == *pp)
448 /* There is no number here. (e.g. "cond a == b"). */
5c44784c
JM
449 {
450 /* Skip non-numeric token */
451 while (*p && !isspace((int) *p))
452 ++p;
453 /* Return zero, which caller must interpret as error. */
454 retval = 0;
455 }
456 else
457 retval = atoi (*pp);
458 }
459 if (!(isspace (*p) || *p == '\0' || *p == trailer))
460 {
461 /* Trailing junk: return 0 and let caller print error msg. */
462 while (!(isspace (*p) || *p == '\0' || *p == trailer))
463 ++p;
464 retval = 0;
c906108c 465 }
c906108c
SS
466 while (isspace (*p))
467 p++;
468 *pp = p;
469 return retval;
470}
5c44784c 471
11cf8741 472
5c44784c
JM
473/* Like get_number_trailer, but don't allow a trailer. */
474int
fba45db2 475get_number (char **pp)
5c44784c
JM
476{
477 return get_number_trailer (pp, '\0');
478}
479
480/* Parse a number or a range.
481 * A number will be of the form handled by get_number.
482 * A range will be of the form <number1> - <number2>, and
483 * will represent all the integers between number1 and number2,
484 * inclusive.
485 *
486 * While processing a range, this fuction is called iteratively;
487 * At each call it will return the next value in the range.
488 *
489 * At the beginning of parsing a range, the char pointer PP will
490 * be advanced past <number1> and left pointing at the '-' token.
491 * Subsequent calls will not advance the pointer until the range
492 * is completed. The call that completes the range will advance
493 * pointer PP past <number2>.
494 */
495
496int
fba45db2 497get_number_or_range (char **pp)
5c44784c
JM
498{
499 static int last_retval, end_value;
500 static char *end_ptr;
501 static int in_range = 0;
502
503 if (**pp != '-')
504 {
505 /* Default case: pp is pointing either to a solo number,
506 or to the first number of a range. */
507 last_retval = get_number_trailer (pp, '-');
508 if (**pp == '-')
509 {
510 char **temp;
511
512 /* This is the start of a range (<number1> - <number2>).
513 Skip the '-', parse and remember the second number,
514 and also remember the end of the final token. */
515
516 temp = &end_ptr;
517 end_ptr = *pp + 1;
518 while (isspace ((int) *end_ptr))
519 end_ptr++; /* skip white space */
520 end_value = get_number (temp);
521 if (end_value < last_retval)
522 {
8a3fe4f8 523 error (_("inverted range"));
5c44784c
JM
524 }
525 else if (end_value == last_retval)
526 {
527 /* degenerate range (number1 == number2). Advance the
528 token pointer so that the range will be treated as a
529 single number. */
530 *pp = end_ptr;
531 }
532 else
533 in_range = 1;
534 }
535 }
536 else if (! in_range)
8a3fe4f8 537 error (_("negative value"));
5c44784c
JM
538 else
539 {
540 /* pp points to the '-' that betokens a range. All
541 number-parsing has already been done. Return the next
542 integer value (one greater than the saved previous value).
543 Do not advance the token pointer 'pp' until the end of range
544 is reached. */
545
546 if (++last_retval == end_value)
547 {
548 /* End of range reached; advance token pointer. */
549 *pp = end_ptr;
550 in_range = 0;
551 }
552 }
553 return last_retval;
554}
555
556
c906108c
SS
557\f
558/* condition N EXP -- set break condition of breakpoint N to EXP. */
559
560static void
fba45db2 561condition_command (char *arg, int from_tty)
c906108c 562{
52f0bd74 563 struct breakpoint *b;
c906108c 564 char *p;
52f0bd74 565 int bnum;
c906108c
SS
566
567 if (arg == 0)
e2e0b3e5 568 error_no_arg (_("breakpoint number"));
c906108c
SS
569
570 p = arg;
571 bnum = get_number (&p);
5c44784c 572 if (bnum == 0)
8a3fe4f8 573 error (_("Bad breakpoint argument: '%s'"), arg);
c906108c
SS
574
575 ALL_BREAKPOINTS (b)
576 if (b->number == bnum)
2f069f6f
JB
577 {
578 struct bp_location *loc = b->loc;
579 for (; loc; loc = loc->next)
580 {
581 if (loc->cond)
582 {
583 xfree (loc->cond);
584 loc->cond = 0;
585 }
586 }
587 if (b->cond_string != NULL)
588 xfree (b->cond_string);
c906108c 589
2f069f6f
JB
590 if (*p == 0)
591 {
592 b->cond_string = NULL;
593 if (from_tty)
594 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
595 }
596 else
597 {
598 arg = p;
599 /* I don't know if it matters whether this is the string the user
600 typed in or the decompiled expression. */
1b36a34b 601 b->cond_string = xstrdup (arg);
2f069f6f
JB
602 b->condition_not_parsed = 0;
603 for (loc = b->loc; loc; loc = loc->next)
604 {
605 arg = p;
606 loc->cond =
607 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
608 if (*arg)
609 error (_("Junk at end of expression"));
610 }
611 }
612 breakpoints_changed ();
383f836e 613 observer_notify_breakpoint_modified (b->number);
2f069f6f
JB
614 return;
615 }
c906108c 616
8a3fe4f8 617 error (_("No breakpoint number %d."), bnum);
c906108c
SS
618}
619
c906108c 620static void
fba45db2 621commands_command (char *arg, int from_tty)
c906108c 622{
52f0bd74 623 struct breakpoint *b;
c906108c 624 char *p;
52f0bd74 625 int bnum;
c906108c
SS
626 struct command_line *l;
627
628 /* If we allowed this, we would have problems with when to
629 free the storage, if we change the commands currently
630 being read from. */
631
632 if (executing_breakpoint_commands)
8a3fe4f8 633 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
c906108c
SS
634
635 p = arg;
636 bnum = get_number (&p);
5c44784c 637
c906108c 638 if (p && *p)
8a3fe4f8 639 error (_("Unexpected extra arguments following breakpoint number."));
c5aa993b 640
c906108c
SS
641 ALL_BREAKPOINTS (b)
642 if (b->number == bnum)
9ebf4acf
AC
643 {
644 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
645 bnum);
646 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
311a4e6b 647 l = read_command_lines (tmpbuf, from_tty, 1);
9ebf4acf
AC
648 do_cleanups (cleanups);
649 free_command_lines (&b->commands);
650 b->commands = l;
651 breakpoints_changed ();
383f836e 652 observer_notify_breakpoint_modified (b->number);
9ebf4acf 653 return;
c5aa993b 654 }
8a3fe4f8 655 error (_("No breakpoint number %d."), bnum);
c906108c 656}
40c03ae8
EZ
657
658/* Like commands_command, but instead of reading the commands from
659 input stream, takes them from an already parsed command structure.
660
661 This is used by cli-script.c to DTRT with breakpoint commands
662 that are part of if and while bodies. */
663enum command_control_type
664commands_from_control_command (char *arg, struct command_line *cmd)
665{
666 struct breakpoint *b;
667 char *p;
668 int bnum;
669
670 /* If we allowed this, we would have problems with when to
671 free the storage, if we change the commands currently
672 being read from. */
673
674 if (executing_breakpoint_commands)
675 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
676
677 /* An empty string for the breakpoint number means the last
678 breakpoint, but get_number expects a NULL pointer. */
679 if (arg && !*arg)
680 p = NULL;
681 else
682 p = arg;
683 bnum = get_number (&p);
684
685 if (p && *p)
686 error (_("Unexpected extra arguments following breakpoint number."));
687
688 ALL_BREAKPOINTS (b)
689 if (b->number == bnum)
690 {
691 free_command_lines (&b->commands);
692 if (cmd->body_count != 1)
693 error (_("Invalid \"commands\" block structure."));
694 /* We need to copy the commands because if/while will free the
695 list after it finishes execution. */
696 b->commands = copy_command_lines (cmd->body_list[0]);
697 breakpoints_changed ();
383f836e 698 observer_notify_breakpoint_modified (b->number);
40c03ae8 699 return simple_control;
2f069f6f 700 }
40c03ae8
EZ
701 error (_("No breakpoint number %d."), bnum);
702}
c906108c 703\f
8defab1a
DJ
704/* Update BUF, which is LEN bytes read from the target address MEMADDR,
705 by replacing any memory breakpoints with their shadowed contents. */
c906108c 706
8defab1a
DJ
707void
708breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
c906108c 709{
8defab1a 710 struct bp_location *b;
c906108c
SS
711 CORE_ADDR bp_addr = 0;
712 int bp_size = 0;
8defab1a 713 int bptoffset = 0;
c5aa993b 714
ffce0d52 715 ALL_BP_LOCATIONS (b)
c5aa993b 716 {
ffce0d52 717 if (b->owner->type == bp_none)
8a3fe4f8 718 warning (_("reading through apparently deleted breakpoint #%d?"),
ffce0d52
DJ
719 b->owner->number);
720
721 if (b->loc_type != bp_loc_software_breakpoint)
c5aa993b 722 continue;
ffce0d52 723 if (!b->inserted)
c5aa993b
JM
724 continue;
725 /* Addresses and length of the part of the breakpoint that
726 we need to copy. */
8181d85f
DJ
727 bp_addr = b->target_info.placed_address;
728 bp_size = b->target_info.shadow_len;
c5aa993b 729 if (bp_size == 0)
8181d85f 730 /* bp isn't valid, or doesn't shadow memory. */
c5aa993b 731 continue;
8defab1a 732
c5aa993b
JM
733 if (bp_addr + bp_size <= memaddr)
734 /* The breakpoint is entirely before the chunk of memory we
735 are reading. */
736 continue;
8defab1a 737
c5aa993b
JM
738 if (bp_addr >= memaddr + len)
739 /* The breakpoint is entirely after the chunk of memory we are
740 reading. */
741 continue;
c5aa993b 742
8defab1a
DJ
743 /* Offset within shadow_contents. */
744 if (bp_addr < memaddr)
745 {
746 /* Only copy the second part of the breakpoint. */
747 bp_size -= memaddr - bp_addr;
748 bptoffset = memaddr - bp_addr;
749 bp_addr = memaddr;
750 }
c5aa993b 751
8defab1a
DJ
752 if (bp_addr + bp_size > memaddr + len)
753 {
754 /* Only copy the first part of the breakpoint. */
755 bp_size -= (bp_addr + bp_size) - (memaddr + len);
756 }
c5aa993b 757
8defab1a
DJ
758 memcpy (buf + bp_addr - memaddr,
759 b->target_info.shadow_contents + bptoffset, bp_size);
c5aa993b 760 }
c906108c 761}
c906108c 762\f
c5aa993b 763
687595f9 764/* A wrapper function for inserting catchpoints. */
9cbc821d 765static void
687595f9
DJ
766insert_catchpoint (struct ui_out *uo, void *args)
767{
768 struct breakpoint *b = (struct breakpoint *) args;
769 int val = -1;
770
fe798b75
JB
771 gdb_assert (b->type == bp_catchpoint);
772 gdb_assert (b->ops != NULL && b->ops->insert != NULL);
773
774 b->ops->insert (b);
687595f9
DJ
775}
776
a5606eee
VP
777static int
778is_hardware_watchpoint (struct breakpoint *bpt)
779{
780 return (bpt->type == bp_hardware_watchpoint
781 || bpt->type == bp_read_watchpoint
782 || bpt->type == bp_access_watchpoint);
783}
7270d8f2 784
fa4727a6
DJ
785/* Find the current value of a watchpoint on EXP. Return the value in
786 *VALP and *RESULTP and the chain of intermediate and final values
787 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
788 not need them.
789
ccc57cf9 790 If a memory error occurs while evaluating the expression, *RESULTP will
fa4727a6
DJ
791 be set to NULL. *RESULTP may be a lazy value, if the result could
792 not be read from memory. It is used to determine whether a value
793 is user-specified (we should watch the whole value) or intermediate
794 (we should watch only the bit used to locate the final value).
795
796 If the final value, or any intermediate value, could not be read
797 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
798 set to any referenced values. *VALP will never be a lazy value.
799 This is the value which we store in struct breakpoint.
800
801 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
802 value chain. The caller must free the values individually. If
803 VAL_CHAIN is NULL, all generated values will be left on the value
804 chain. */
805
806static void
807fetch_watchpoint_value (struct expression *exp, struct value **valp,
808 struct value **resultp, struct value **val_chain)
809{
810 struct value *mark, *new_mark, *result;
ccc57cf9 811 volatile struct gdb_exception ex;
fa4727a6
DJ
812
813 *valp = NULL;
814 if (resultp)
815 *resultp = NULL;
816 if (val_chain)
817 *val_chain = NULL;
818
819 /* Evaluate the expression. */
820 mark = value_mark ();
821 result = NULL;
ccc57cf9
PA
822
823 TRY_CATCH (ex, RETURN_MASK_ALL)
824 {
825 result = evaluate_expression (exp);
826 }
827 if (ex.reason < 0)
828 {
829 /* Ignore memory errors, we want watchpoints pointing at
830 inaccessible memory to still be created; otherwise, throw the
831 error to some higher catcher. */
832 switch (ex.error)
833 {
834 case MEMORY_ERROR:
835 break;
836 default:
837 throw_exception (ex);
838 break;
839 }
840 }
841
fa4727a6
DJ
842 new_mark = value_mark ();
843 if (mark == new_mark)
844 return;
845 if (resultp)
846 *resultp = result;
847
848 /* Make sure it's not lazy, so that after the target stops again we
849 have a non-lazy previous value to compare with. */
850 if (result != NULL
851 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
852 *valp = result;
853
854 if (val_chain)
855 {
856 /* Return the chain of intermediate values. We use this to
857 decide which addresses to watch. */
858 *val_chain = new_mark;
859 value_release_to_mark (mark);
860 }
861}
862
567e1b4e
JB
863/* Assuming that B is a watchpoint:
864 - Reparse watchpoint expression, if REPARSE is non-zero
a5606eee 865 - Evaluate expression and store the result in B->val
567e1b4e
JB
866 - Evaluate the condition if there is one, and store the result
867 in b->loc->cond.
a5606eee
VP
868 - Update the list of values that must be watched in B->loc.
869
bfa149ac
JB
870 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
871 If this is local watchpoint that is out of scope, delete it. */
b40ce68a 872static void
a5606eee 873update_watchpoint (struct breakpoint *b, int reparse)
7270d8f2 874{
a5606eee 875 int within_current_scope;
a5606eee
VP
876 struct frame_id saved_frame_id;
877 struct bp_location *loc;
878 bpstat bs;
879
567e1b4e
JB
880 /* We don't free locations. They are stored in bp_location_chain and
881 update_global_locations will eventually delete them and remove
882 breakpoints if needed. */
a5606eee
VP
883 b->loc = NULL;
884
885 if (b->disposition == disp_del_at_next_stop)
886 return;
887
888 /* Save the current frame's ID so we can restore it after
889 evaluating the watchpoint expression on its own frame. */
890 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
891 took a frame parameter, so that we didn't have to change the
892 selected frame. */
893 saved_frame_id = get_frame_id (get_selected_frame (NULL));
894
895 /* Determine if the watchpoint is within scope. */
896 if (b->exp_valid_block == NULL)
897 within_current_scope = 1;
898 else
899 {
900 struct frame_info *fi;
901 fi = frame_find_by_id (b->watchpoint_frame);
902 within_current_scope = (fi != NULL);
903 if (within_current_scope)
904 select_frame (fi);
905 }
906
907 if (within_current_scope && reparse)
908 {
909 char *s;
910 if (b->exp)
911 {
912 xfree (b->exp);
913 b->exp = NULL;
914 }
915 s = b->exp_string;
916 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
917 /* If the meaning of expression itself changed, the old value is
918 no longer relevant. We don't want to report a watchpoint hit
919 to the user when the old value and the new value may actually
920 be completely different objects. */
921 value_free (b->val);
fa4727a6
DJ
922 b->val = NULL;
923 b->val_valid = 0;
a5606eee 924 }
a5606eee
VP
925
926 /* If we failed to parse the expression, for example because
927 it refers to a global variable in a not-yet-loaded shared library,
928 don't try to insert watchpoint. We don't automatically delete
929 such watchpoint, though, since failure to parse expression
930 is different from out-of-scope watchpoint. */
931 if (within_current_scope && b->exp)
932 {
fa4727a6 933 struct value *val_chain, *v, *result, *next;
a5606eee 934
fa4727a6 935 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
a5606eee 936
a5606eee
VP
937 /* Avoid setting b->val if it's already set. The meaning of
938 b->val is 'the last value' user saw, and we should update
939 it only if we reported that last value to user. As it
940 happens, the code that reports it updates b->val directly. */
fa4727a6
DJ
941 if (!b->val_valid)
942 {
943 b->val = v;
944 b->val_valid = 1;
945 }
a5606eee 946
db2ad4c3
JK
947 /* Change the type of breakpoint between hardware assisted or an
948 ordinary watchpoint depending on the hardware support and free
949 hardware slots. REPARSE is set when the inferior is started. */
950 if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
951 && reparse)
952 {
ca2d49e8 953 int i, mem_cnt, other_type_used;
db2ad4c3
JK
954
955 i = hw_watchpoint_used_count (bp_hardware_watchpoint,
956 &other_type_used);
957 mem_cnt = can_use_hardware_watchpoint (val_chain);
958
ca2d49e8 959 if (!mem_cnt)
db2ad4c3
JK
960 b->type = bp_watchpoint;
961 else
ca2d49e8 962 {
d92524f1 963 int target_resources_ok = target_can_use_hardware_watchpoint
ca2d49e8
SL
964 (bp_hardware_watchpoint, i + mem_cnt, other_type_used);
965 if (target_resources_ok <= 0)
966 b->type = bp_watchpoint;
967 else
968 b->type = bp_hardware_watchpoint;
969 }
db2ad4c3
JK
970 }
971
a5606eee 972 /* Look at each value on the value chain. */
fa4727a6 973 for (v = val_chain; v; v = next)
a5606eee
VP
974 {
975 /* If it's a memory location, and GDB actually needed
976 its contents to evaluate the expression, then we
fa4727a6
DJ
977 must watch it. If the first value returned is
978 still lazy, that means an error occurred reading it;
979 watch it anyway in case it becomes readable. */
a5606eee 980 if (VALUE_LVAL (v) == lval_memory
fa4727a6 981 && (v == val_chain || ! value_lazy (v)))
a5606eee
VP
982 {
983 struct type *vtype = check_typedef (value_type (v));
7270d8f2 984
a5606eee
VP
985 /* We only watch structs and arrays if user asked
986 for it explicitly, never if they just happen to
987 appear in the middle of some value chain. */
fa4727a6 988 if (v == result
a5606eee
VP
989 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
990 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
991 {
992 CORE_ADDR addr;
993 int len, type;
994 struct bp_location *loc, **tmp;
995
42ae5230 996 addr = value_address (v);
a5606eee
VP
997 len = TYPE_LENGTH (value_type (v));
998 type = hw_write;
999 if (b->type == bp_read_watchpoint)
1000 type = hw_read;
1001 else if (b->type == bp_access_watchpoint)
1002 type = hw_access;
1003
39d61571 1004 loc = allocate_bp_location (b);
a5606eee
VP
1005 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
1006 ;
1007 *tmp = loc;
1008 loc->address = addr;
1009 loc->length = len;
1010 loc->watchpoint_type = type;
1011 }
1012 }
1013
1014 next = value_next (v);
1015 if (v != b->val)
1016 value_free (v);
1017 }
1018
2ec93238
MK
1019 /* We just regenerated the list of breakpoint locations.
1020 The new location does not have its condition field set to anything
1021 and therefore, we must always reparse the cond_string, independently
1022 of the value of the reparse flag. */
1023 if (b->cond_string != NULL)
a5606eee
VP
1024 {
1025 char *s = b->cond_string;
a5606eee
VP
1026 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1027 }
1028 }
1029 else if (!within_current_scope)
7270d8f2 1030 {
a5606eee 1031 printf_filtered (_("\
567e1b4e 1032Watchpoint %d deleted because the program has left the block \n\
a5606eee
VP
1033in which its expression is valid.\n"),
1034 b->number);
1035 if (b->related_breakpoint)
1036 b->related_breakpoint->disposition = disp_del_at_next_stop;
1037 b->disposition = disp_del_at_next_stop;
7270d8f2 1038 }
a5606eee
VP
1039
1040 /* Restore the selected frame. */
1041 select_frame (frame_find_by_id (saved_frame_id));
7270d8f2
OF
1042}
1043
a5606eee 1044
74960c60
VP
1045/* Returns 1 iff breakpoint location should be
1046 inserted in the inferior. */
1047static int
1048should_be_inserted (struct bp_location *bpt)
1049{
1050 if (!breakpoint_enabled (bpt->owner))
1051 return 0;
1052
1053 if (bpt->owner->disposition == disp_del_at_next_stop)
1054 return 0;
1055
1056 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1057 return 0;
1058
1042e4c0
SS
1059 /* Tracepoints are inserted by the target at a time of its choosing,
1060 not by us. */
1061 if (bpt->owner->type == bp_tracepoint)
1062 return 0;
1063
74960c60
VP
1064 return 1;
1065}
1066
879bfdc2
DJ
1067/* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1068 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
fa3a767f 1069 and HW_BREAKPOINT_ERROR are used to report problems.
879bfdc2
DJ
1070
1071 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1072 method for each breakpoint or catchpoint type. */
26bb91f3 1073static int
879bfdc2 1074insert_bp_location (struct bp_location *bpt,
26bb91f3 1075 struct ui_file *tmp_error_stream,
fa3a767f 1076 int *disabled_breaks,
26bb91f3 1077 int *hw_breakpoint_error)
879bfdc2
DJ
1078{
1079 int val = 0;
1080
74960c60 1081 if (!should_be_inserted (bpt) || bpt->inserted)
879bfdc2
DJ
1082 return 0;
1083
8181d85f
DJ
1084 /* Initialize the target-specific information. */
1085 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1086 bpt->target_info.placed_address = bpt->address;
1087
879bfdc2
DJ
1088 if (bpt->loc_type == bp_loc_software_breakpoint
1089 || bpt->loc_type == bp_loc_hardware_breakpoint)
1090 {
765dc015
VP
1091 if (bpt->owner->type != bp_hardware_breakpoint)
1092 {
1093 /* If the explicitly specified breakpoint type
1094 is not hardware breakpoint, check the memory map to see
1095 if the breakpoint address is in read only memory or not.
1096 Two important cases are:
1097 - location type is not hardware breakpoint, memory
1098 is readonly. We change the type of the location to
1099 hardware breakpoint.
1100 - location type is hardware breakpoint, memory is read-write.
1101 This means we've previously made the location hardware one, but
1102 then the memory map changed, so we undo.
1103
1104 When breakpoints are removed, remove_breakpoints will
1105 use location types we've just set here, the only possible
1106 problem is that memory map has changed during running program,
1107 but it's not going to work anyway with current gdb. */
1108 struct mem_region *mr
1109 = lookup_mem_region (bpt->target_info.placed_address);
1110
1111 if (mr)
1112 {
1113 if (automatic_hardware_breakpoints)
1114 {
1115 int changed = 0;
1116 enum bp_loc_type new_type;
1117
1118 if (mr->attrib.mode != MEM_RW)
1119 new_type = bp_loc_hardware_breakpoint;
1120 else
1121 new_type = bp_loc_software_breakpoint;
1122
1123 if (new_type != bpt->loc_type)
1124 {
1125 static int said = 0;
1126 bpt->loc_type = new_type;
1127 if (!said)
1128 {
1129 fprintf_filtered (gdb_stdout, _("\
0767c96d 1130Note: automatically using hardware breakpoints for read-only addresses.\n"));
765dc015
VP
1131 said = 1;
1132 }
1133 }
1134 }
1135 else if (bpt->loc_type == bp_loc_software_breakpoint
1136 && mr->attrib.mode != MEM_RW)
1137 warning (_("cannot set software breakpoint at readonly address %s"),
1138 paddr (bpt->address));
1139 }
1140 }
1141
879bfdc2
DJ
1142 /* First check to see if we have to handle an overlay. */
1143 if (overlay_debugging == ovly_off
1144 || bpt->section == NULL
1145 || !(section_is_overlay (bpt->section)))
1146 {
1147 /* No overlay handling: just set the breakpoint. */
1148
1149 if (bpt->loc_type == bp_loc_hardware_breakpoint)
8181d85f 1150 val = target_insert_hw_breakpoint (&bpt->target_info);
879bfdc2 1151 else
8181d85f 1152 val = target_insert_breakpoint (&bpt->target_info);
879bfdc2
DJ
1153 }
1154 else
1155 {
1156 /* This breakpoint is in an overlay section.
1157 Shall we set a breakpoint at the LMA? */
1158 if (!overlay_events_enabled)
1159 {
1160 /* Yes -- overlay event support is not active,
1161 so we must try to set a breakpoint at the LMA.
1162 This will not work for a hardware breakpoint. */
1163 if (bpt->loc_type == bp_loc_hardware_breakpoint)
8a3fe4f8 1164 warning (_("hardware breakpoint %d not supported in overlay!"),
879bfdc2
DJ
1165 bpt->owner->number);
1166 else
1167 {
1168 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1169 bpt->section);
1170 /* Set a software (trap) breakpoint at the LMA. */
8181d85f
DJ
1171 bpt->overlay_target_info = bpt->target_info;
1172 bpt->overlay_target_info.placed_address = addr;
1173 val = target_insert_breakpoint (&bpt->overlay_target_info);
879bfdc2 1174 if (val != 0)
99361f52
DE
1175 fprintf_unfiltered (tmp_error_stream,
1176 "Overlay breakpoint %d failed: in ROM?\n",
879bfdc2
DJ
1177 bpt->owner->number);
1178 }
1179 }
1180 /* Shall we set a breakpoint at the VMA? */
1181 if (section_is_mapped (bpt->section))
1182 {
1183 /* Yes. This overlay section is mapped into memory. */
1184 if (bpt->loc_type == bp_loc_hardware_breakpoint)
8181d85f 1185 val = target_insert_hw_breakpoint (&bpt->target_info);
879bfdc2 1186 else
8181d85f 1187 val = target_insert_breakpoint (&bpt->target_info);
879bfdc2
DJ
1188 }
1189 else
1190 {
1191 /* No. This breakpoint will not be inserted.
1192 No error, but do not mark the bp as 'inserted'. */
1193 return 0;
1194 }
1195 }
1196
1197 if (val)
1198 {
1199 /* Can't set the breakpoint. */
f5c9a895 1200 if (solib_name_from_address (bpt->address))
879bfdc2
DJ
1201 {
1202 /* See also: disable_breakpoints_in_shlibs. */
1203 val = 0;
0d381245 1204 bpt->shlib_disabled = 1;
879bfdc2
DJ
1205 if (!*disabled_breaks)
1206 {
1207 fprintf_unfiltered (tmp_error_stream,
1208 "Cannot insert breakpoint %d.\n",
1209 bpt->owner->number);
1210 fprintf_unfiltered (tmp_error_stream,
1211 "Temporarily disabling shared library breakpoints:\n");
1212 }
1213 *disabled_breaks = 1;
1214 fprintf_unfiltered (tmp_error_stream,
1215 "breakpoint #%d\n", bpt->owner->number);
1216 }
1217 else
879bfdc2 1218 {
879bfdc2
DJ
1219 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1220 {
1221 *hw_breakpoint_error = 1;
1222 fprintf_unfiltered (tmp_error_stream,
1223 "Cannot insert hardware breakpoint %d.\n",
1224 bpt->owner->number);
1225 }
1226 else
1227 {
1228 fprintf_unfiltered (tmp_error_stream,
1229 "Cannot insert breakpoint %d.\n",
1230 bpt->owner->number);
1231 fprintf_filtered (tmp_error_stream,
1232 "Error accessing memory address ");
ed49a04f 1233 fputs_filtered (paddress (bpt->address), tmp_error_stream);
879bfdc2
DJ
1234 fprintf_filtered (tmp_error_stream, ": %s.\n",
1235 safe_strerror (val));
1236 }
1237
1238 }
1239 }
1240 else
1241 bpt->inserted = 1;
1242
1243 return val;
1244 }
1245
1246 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1247 /* NOTE drow/2003-09-08: This state only exists for removing
1248 watchpoints. It's not clear that it's necessary... */
1249 && bpt->owner->disposition != disp_del_at_next_stop)
1250 {
a5606eee
VP
1251 val = target_insert_watchpoint (bpt->address,
1252 bpt->length,
1253 bpt->watchpoint_type);
1254 bpt->inserted = (val != -1);
879bfdc2
DJ
1255 }
1256
fe798b75 1257 else if (bpt->owner->type == bp_catchpoint)
879bfdc2 1258 {
71fff37b
AC
1259 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1260 bpt->owner, RETURN_MASK_ERROR);
9cbc821d
AC
1261 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1262 bpt->owner->number);
1263 if (e.reason < 0)
879bfdc2
DJ
1264 bpt->owner->enable_state = bp_disabled;
1265 else
1266 bpt->inserted = 1;
1640b821
DJ
1267
1268 /* We've already printed an error message if there was a problem
1269 inserting this catchpoint, and we've disabled the catchpoint,
1270 so just return success. */
1271 return 0;
879bfdc2
DJ
1272 }
1273
1274 return 0;
1275}
1276
74960c60
VP
1277/* Make sure all breakpoints are inserted in inferior.
1278 Throws exception on any error.
1279 A breakpoint that is already inserted won't be inserted
1280 again, so calling this function twice is safe. */
1281void
1282insert_breakpoints (void)
1283{
1284 struct breakpoint *bpt;
1285
1286 ALL_BREAKPOINTS (bpt)
1287 if (is_hardware_watchpoint (bpt))
1288 update_watchpoint (bpt, 0 /* don't reparse. */);
1289
b60e7edf 1290 update_global_location_list (1);
74960c60 1291
c35b1492
PA
1292 /* update_global_location_list does not insert breakpoints when
1293 always_inserted_mode is not enabled. Explicitly insert them
1294 now. */
1295 if (!breakpoints_always_inserted_mode ())
74960c60
VP
1296 insert_breakpoint_locations ();
1297}
1298
c906108c
SS
1299/* insert_breakpoints is used when starting or continuing the program.
1300 remove_breakpoints is used when the program stops.
1301 Both return zero if successful,
1302 or an `errno' value if could not write the inferior. */
1303
74960c60
VP
1304static void
1305insert_breakpoint_locations (void)
c906108c 1306{
a5606eee 1307 struct breakpoint *bpt;
879bfdc2 1308 struct bp_location *b, *temp;
e236ba44 1309 int error = 0;
c906108c
SS
1310 int val = 0;
1311 int disabled_breaks = 0;
81d0cc19 1312 int hw_breakpoint_error = 0;
c906108c 1313
81d0cc19 1314 struct ui_file *tmp_error_stream = mem_fileopen ();
f7545552 1315 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream);
74960c60 1316
81d0cc19
GS
1317 /* Explicitly mark the warning -- this will only be printed if
1318 there was an error. */
1319 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
a5606eee 1320
879bfdc2
DJ
1321 ALL_BP_LOCATIONS_SAFE (b, temp)
1322 {
74960c60 1323 if (!should_be_inserted (b) || b->inserted)
879bfdc2
DJ
1324 continue;
1325
f365de73
AS
1326 /* There is no point inserting thread-specific breakpoints if the
1327 thread no longer exists. */
1328 if (b->owner->thread != -1
1329 && !valid_thread_id (b->owner->thread))
1330 continue;
1331
879bfdc2 1332 val = insert_bp_location (b, tmp_error_stream,
fa3a767f 1333 &disabled_breaks,
879bfdc2
DJ
1334 &hw_breakpoint_error);
1335 if (val)
e236ba44 1336 error = val;
879bfdc2 1337 }
c906108c 1338
a5606eee
VP
1339 /* If we failed to insert all locations of a watchpoint,
1340 remove them, as half-inserted watchpoint is of limited use. */
1341 ALL_BREAKPOINTS (bpt)
1342 {
1343 int some_failed = 0;
1344 struct bp_location *loc;
1345
1346 if (!is_hardware_watchpoint (bpt))
1347 continue;
1348
d6b74ac4 1349 if (!breakpoint_enabled (bpt))
a5606eee 1350 continue;
74960c60
VP
1351
1352 if (bpt->disposition == disp_del_at_next_stop)
1353 continue;
a5606eee
VP
1354
1355 for (loc = bpt->loc; loc; loc = loc->next)
1356 if (!loc->inserted)
1357 {
1358 some_failed = 1;
1359 break;
1360 }
1361 if (some_failed)
1362 {
1363 for (loc = bpt->loc; loc; loc = loc->next)
1364 if (loc->inserted)
1365 remove_breakpoint (loc, mark_uninserted);
1366
1367 hw_breakpoint_error = 1;
1368 fprintf_unfiltered (tmp_error_stream,
1369 "Could not insert hardware watchpoint %d.\n",
1370 bpt->number);
1371 error = -1;
1372 }
1373 }
1374
e236ba44 1375 if (error)
81d0cc19
GS
1376 {
1377 /* If a hardware breakpoint or watchpoint was inserted, add a
1378 message about possibly exhausted resources. */
879bfdc2 1379 if (hw_breakpoint_error)
81d0cc19 1380 {
c6510018
MS
1381 fprintf_unfiltered (tmp_error_stream,
1382 "Could not insert hardware breakpoints:\n\
1383You may have requested too many hardware breakpoints/watchpoints.\n");
81d0cc19 1384 }
81d0cc19
GS
1385 target_terminal_ours_for_output ();
1386 error_stream (tmp_error_stream);
1387 }
f7545552
TT
1388
1389 do_cleanups (cleanups);
c906108c
SS
1390}
1391
c906108c 1392int
fba45db2 1393remove_breakpoints (void)
c906108c 1394{
0bde7532 1395 struct bp_location *b;
c906108c
SS
1396 int val;
1397
0bde7532 1398 ALL_BP_LOCATIONS (b)
c5aa993b 1399 {
0bde7532 1400 if (b->inserted)
c5aa993b
JM
1401 {
1402 val = remove_breakpoint (b, mark_uninserted);
1403 if (val != 0)
1404 return val;
1405 }
1406 }
c906108c
SS
1407 return 0;
1408}
1409
692590c1 1410int
80ce1ecb 1411remove_hw_watchpoints (void)
692590c1 1412{
0bde7532 1413 struct bp_location *b;
692590c1
MS
1414 int val;
1415
0bde7532 1416 ALL_BP_LOCATIONS (b)
692590c1 1417 {
0bde7532 1418 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
692590c1
MS
1419 {
1420 val = remove_breakpoint (b, mark_uninserted);
1421 if (val != 0)
1422 return val;
1423 }
1424 }
1425 return 0;
1426}
1427
c906108c 1428int
fba45db2 1429reattach_breakpoints (int pid)
c906108c 1430{
0bde7532 1431 struct bp_location *b;
c906108c 1432 int val;
ce696e05 1433 struct cleanup *old_chain = save_inferior_ptid ();
a4954f26 1434 struct ui_file *tmp_error_stream = mem_fileopen ();
fa3a767f 1435 int dummy1 = 0, dummy2 = 0;
a4954f26
DJ
1436
1437 make_cleanup_ui_file_delete (tmp_error_stream);
c906108c 1438
ce696e05 1439 inferior_ptid = pid_to_ptid (pid);
0bde7532 1440 ALL_BP_LOCATIONS (b)
c5aa993b 1441 {
0bde7532 1442 if (b->inserted)
c5aa993b 1443 {
a4954f26
DJ
1444 b->inserted = 0;
1445 val = insert_bp_location (b, tmp_error_stream,
fa3a767f 1446 &dummy1, &dummy2);
c5aa993b
JM
1447 if (val != 0)
1448 {
ce696e05 1449 do_cleanups (old_chain);
c5aa993b
JM
1450 return val;
1451 }
1452 }
1453 }
ce696e05 1454 do_cleanups (old_chain);
c906108c
SS
1455 return 0;
1456}
1457
e58b0e63
PA
1458static int internal_breakpoint_number = -1;
1459
e62c965a
PP
1460static struct breakpoint *
1461create_internal_breakpoint (CORE_ADDR address, enum bptype type)
1462{
e62c965a
PP
1463 struct symtab_and_line sal;
1464 struct breakpoint *b;
1465
1466 init_sal (&sal); /* initialize to zeroes */
1467
1468 sal.pc = address;
1469 sal.section = find_pc_overlay (sal.pc);
1470
1471 b = set_raw_breakpoint (sal, type);
1472 b->number = internal_breakpoint_number--;
1473 b->disposition = disp_donttouch;
1474
1475 return b;
1476}
1477
1478static void
69de3c6a 1479create_overlay_event_breakpoint (char *func_name)
e62c965a 1480{
69de3c6a 1481 struct objfile *objfile;
e62c965a 1482
69de3c6a
PP
1483 ALL_OBJFILES (objfile)
1484 {
1485 struct breakpoint *b;
1486 struct minimal_symbol *m;
1487
1488 m = lookup_minimal_symbol_text (func_name, objfile);
1489 if (m == NULL)
1490 continue;
e62c965a 1491
69de3c6a
PP
1492 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
1493 bp_overlay_event);
1494 b->addr_string = xstrdup (func_name);
e62c965a 1495
69de3c6a
PP
1496 if (overlay_debugging == ovly_auto)
1497 {
1498 b->enable_state = bp_enabled;
1499 overlay_events_enabled = 1;
1500 }
1501 else
1502 {
1503 b->enable_state = bp_disabled;
1504 overlay_events_enabled = 0;
1505 }
e62c965a
PP
1506 }
1507 update_global_location_list (1);
1508}
1509
c906108c 1510void
fba45db2 1511update_breakpoints_after_exec (void)
c906108c 1512{
c5aa993b
JM
1513 struct breakpoint *b;
1514 struct breakpoint *temp;
25b22b0a 1515 struct bp_location *bploc;
c906108c 1516
25b22b0a
PA
1517 /* We're about to delete breakpoints from GDB's lists. If the
1518 INSERTED flag is true, GDB will try to lift the breakpoints by
1519 writing the breakpoints' "shadow contents" back into memory. The
1520 "shadow contents" are NOT valid after an exec, so GDB should not
1521 do that. Instead, the target is responsible from marking
1522 breakpoints out as soon as it detects an exec. We don't do that
1523 here instead, because there may be other attempts to delete
1524 breakpoints after detecting an exec and before reaching here. */
1525 ALL_BP_LOCATIONS (bploc)
1526 gdb_assert (!bploc->inserted);
c906108c
SS
1527
1528 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
1529 {
1530 /* Solib breakpoints must be explicitly reset after an exec(). */
1531 if (b->type == bp_shlib_event)
1532 {
1533 delete_breakpoint (b);
1534 continue;
1535 }
c906108c 1536
1900040c
MS
1537 /* Thread event breakpoints must be set anew after an exec(),
1538 as must overlay event breakpoints. */
1539 if (b->type == bp_thread_event || b->type == bp_overlay_event)
c4093a6a
JM
1540 {
1541 delete_breakpoint (b);
1542 continue;
1543 }
1544
c5aa993b
JM
1545 /* Step-resume breakpoints are meaningless after an exec(). */
1546 if (b->type == bp_step_resume)
1547 {
1548 delete_breakpoint (b);
1549 continue;
1550 }
1551
611c83ae
PA
1552 /* Longjmp and longjmp-resume breakpoints are also meaningless
1553 after an exec. */
1554 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
1555 {
1556 delete_breakpoint (b);
1557 continue;
1558 }
1559
ce78b96d
JB
1560 if (b->type == bp_catchpoint)
1561 {
1562 /* For now, none of the bp_catchpoint breakpoints need to
1563 do anything at this point. In the future, if some of
1564 the catchpoints need to something, we will need to add
1565 a new method, and call this method from here. */
1566 continue;
1567 }
1568
c5aa993b
JM
1569 /* bp_finish is a special case. The only way we ought to be able
1570 to see one of these when an exec() has happened, is if the user
1571 caught a vfork, and then said "finish". Ordinarily a finish just
1572 carries them to the call-site of the current callee, by setting
1573 a temporary bp there and resuming. But in this case, the finish
1574 will carry them entirely through the vfork & exec.
1575
1576 We don't want to allow a bp_finish to remain inserted now. But
1577 we can't safely delete it, 'cause finish_command has a handle to
1578 the bp on a bpstat, and will later want to delete it. There's a
1579 chance (and I've seen it happen) that if we delete the bp_finish
1580 here, that its storage will get reused by the time finish_command
1581 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1582 We really must allow finish_command to delete a bp_finish.
1583
53a5351d
JM
1584 In the absense of a general solution for the "how do we know
1585 it's safe to delete something others may have handles to?"
1586 problem, what we'll do here is just uninsert the bp_finish, and
1587 let finish_command delete it.
1588
1589 (We know the bp_finish is "doomed" in the sense that it's
1590 momentary, and will be deleted as soon as finish_command sees
1591 the inferior stopped. So it doesn't matter that the bp's
1592 address is probably bogus in the new a.out, unlike e.g., the
1593 solib breakpoints.) */
c5aa993b 1594
c5aa993b
JM
1595 if (b->type == bp_finish)
1596 {
1597 continue;
1598 }
1599
1600 /* Without a symbolic address, we have little hope of the
1601 pre-exec() address meaning the same thing in the post-exec()
1602 a.out. */
1603 if (b->addr_string == NULL)
1604 {
1605 delete_breakpoint (b);
1606 continue;
1607 }
c5aa993b 1608 }
1900040c 1609 /* FIXME what about longjmp breakpoints? Re-create them here? */
69de3c6a 1610 create_overlay_event_breakpoint ("_ovly_debug_event");
c906108c
SS
1611}
1612
1613int
fba45db2 1614detach_breakpoints (int pid)
c906108c 1615{
0bde7532 1616 struct bp_location *b;
c906108c 1617 int val;
ce696e05 1618 struct cleanup *old_chain = save_inferior_ptid ();
c5aa993b 1619
39f77062 1620 if (pid == PIDGET (inferior_ptid))
8a3fe4f8 1621 error (_("Cannot detach breakpoints of inferior_ptid"));
c5aa993b 1622
ce696e05
KB
1623 /* Set inferior_ptid; remove_breakpoint uses this global. */
1624 inferior_ptid = pid_to_ptid (pid);
0bde7532 1625 ALL_BP_LOCATIONS (b)
c5aa993b 1626 {
0bde7532 1627 if (b->inserted)
c5aa993b
JM
1628 {
1629 val = remove_breakpoint (b, mark_inserted);
1630 if (val != 0)
1631 {
ce696e05 1632 do_cleanups (old_chain);
c5aa993b
JM
1633 return val;
1634 }
1635 }
1636 }
ce696e05 1637 do_cleanups (old_chain);
c906108c
SS
1638 return 0;
1639}
1640
1641static int
0bde7532 1642remove_breakpoint (struct bp_location *b, insertion_state_t is)
c906108c
SS
1643{
1644 int val;
c5aa993b 1645
0bde7532 1646 if (b->owner->enable_state == bp_permanent)
c2c6d25f
JM
1647 /* Permanent breakpoints cannot be inserted or removed. */
1648 return 0;
1649
74960c60
VP
1650 /* The type of none suggests that owner is actually deleted.
1651 This should not ever happen. */
1652 gdb_assert (b->owner->type != bp_none);
0bde7532
DJ
1653
1654 if (b->loc_type == bp_loc_software_breakpoint
1655 || b->loc_type == bp_loc_hardware_breakpoint)
c906108c 1656 {
c02f5703
MS
1657 /* "Normal" instruction breakpoint: either the standard
1658 trap-instruction bp (bp_breakpoint), or a
1659 bp_hardware_breakpoint. */
1660
1661 /* First check to see if we have to handle an overlay. */
1662 if (overlay_debugging == ovly_off
0bde7532
DJ
1663 || b->section == NULL
1664 || !(section_is_overlay (b->section)))
c02f5703
MS
1665 {
1666 /* No overlay handling: just remove the breakpoint. */
1667
0bde7532 1668 if (b->loc_type == bp_loc_hardware_breakpoint)
8181d85f 1669 val = target_remove_hw_breakpoint (&b->target_info);
c02f5703 1670 else
8181d85f 1671 val = target_remove_breakpoint (&b->target_info);
c02f5703 1672 }
c906108c
SS
1673 else
1674 {
c02f5703
MS
1675 /* This breakpoint is in an overlay section.
1676 Did we set a breakpoint at the LMA? */
1677 if (!overlay_events_enabled)
1678 {
1679 /* Yes -- overlay event support is not active, so we
1680 should have set a breakpoint at the LMA. Remove it.
1681 */
c02f5703
MS
1682 /* Ignore any failures: if the LMA is in ROM, we will
1683 have already warned when we failed to insert it. */
0bde7532 1684 if (b->loc_type == bp_loc_hardware_breakpoint)
8181d85f 1685 target_remove_hw_breakpoint (&b->overlay_target_info);
c02f5703 1686 else
8181d85f 1687 target_remove_breakpoint (&b->overlay_target_info);
c02f5703
MS
1688 }
1689 /* Did we set a breakpoint at the VMA?
1690 If so, we will have marked the breakpoint 'inserted'. */
0bde7532 1691 if (b->inserted)
c906108c 1692 {
c02f5703
MS
1693 /* Yes -- remove it. Previously we did not bother to
1694 remove the breakpoint if the section had been
1695 unmapped, but let's not rely on that being safe. We
1696 don't know what the overlay manager might do. */
0bde7532 1697 if (b->loc_type == bp_loc_hardware_breakpoint)
8181d85f 1698 val = target_remove_hw_breakpoint (&b->target_info);
aa67235e
UW
1699
1700 /* However, we should remove *software* breakpoints only
1701 if the section is still mapped, or else we overwrite
1702 wrong code with the saved shadow contents. */
1703 else if (section_is_mapped (b->section))
8181d85f 1704 val = target_remove_breakpoint (&b->target_info);
aa67235e
UW
1705 else
1706 val = 0;
c906108c 1707 }
c02f5703
MS
1708 else
1709 {
1710 /* No -- not inserted, so no need to remove. No error. */
1711 val = 0;
1712 }
c906108c 1713 }
879d1e6b
UW
1714
1715 /* In some cases, we might not be able to remove a breakpoint
1716 in a shared library that has already been removed, but we
1717 have not yet processed the shlib unload event. */
f5c9a895 1718 if (val && solib_name_from_address (b->address))
879d1e6b
UW
1719 val = 0;
1720
c906108c
SS
1721 if (val)
1722 return val;
0bde7532 1723 b->inserted = (is == mark_inserted);
c906108c 1724 }
a5606eee 1725 else if (b->loc_type == bp_loc_hardware_watchpoint)
c906108c 1726 {
278cd55f
AC
1727 struct value *v;
1728 struct value *n;
c5aa993b 1729
0bde7532 1730 b->inserted = (is == mark_inserted);
a5606eee
VP
1731 val = target_remove_watchpoint (b->address, b->length,
1732 b->watchpoint_type);
2e70b7b9 1733
c906108c 1734 /* Failure to remove any of the hardware watchpoints comes here. */
0bde7532 1735 if ((is == mark_uninserted) && (b->inserted))
8a3fe4f8 1736 warning (_("Could not remove hardware watchpoint %d."),
0bde7532 1737 b->owner->number);
c906108c 1738 }
ce78b96d
JB
1739 else if (b->owner->type == bp_catchpoint
1740 && breakpoint_enabled (b->owner)
1741 && !b->duplicate)
1742 {
1743 gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL);
1744
1745 val = b->owner->ops->remove (b->owner);
1746 if (val)
1747 return val;
1748 b->inserted = (is == mark_inserted);
1749 }
c906108c
SS
1750
1751 return 0;
1752}
1753
1754/* Clear the "inserted" flag in all breakpoints. */
1755
25b22b0a 1756void
fba45db2 1757mark_breakpoints_out (void)
c906108c 1758{
075f6582 1759 struct bp_location *bpt;
c906108c 1760
075f6582
DJ
1761 ALL_BP_LOCATIONS (bpt)
1762 bpt->inserted = 0;
c906108c
SS
1763}
1764
53a5351d
JM
1765/* Clear the "inserted" flag in all breakpoints and delete any
1766 breakpoints which should go away between runs of the program.
c906108c
SS
1767
1768 Plus other such housekeeping that has to be done for breakpoints
1769 between runs.
1770
53a5351d
JM
1771 Note: this function gets called at the end of a run (by
1772 generic_mourn_inferior) and when a run begins (by
1773 init_wait_for_inferior). */
c906108c
SS
1774
1775
1776
1777void
fba45db2 1778breakpoint_init_inferior (enum inf_context context)
c906108c 1779{
52f0bd74 1780 struct breakpoint *b, *temp;
075f6582 1781 struct bp_location *bpt;
1c5cfe86 1782 int ix;
c906108c 1783
50c71eaf
PA
1784 /* If breakpoint locations are shared across processes, then there's
1785 nothing to do. */
2567c7d9 1786 if (gdbarch_has_global_breakpoints (target_gdbarch))
50c71eaf
PA
1787 return;
1788
075f6582 1789 ALL_BP_LOCATIONS (bpt)
514f746b
AR
1790 if (bpt->owner->enable_state != bp_permanent)
1791 bpt->inserted = 0;
075f6582 1792
c906108c 1793 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 1794 {
c5aa993b
JM
1795 switch (b->type)
1796 {
1797 case bp_call_dummy:
1798 case bp_watchpoint_scope:
c906108c 1799
c5aa993b
JM
1800 /* If the call dummy breakpoint is at the entry point it will
1801 cause problems when the inferior is rerun, so we better
1802 get rid of it.
c906108c 1803
c5aa993b
JM
1804 Also get rid of scope breakpoints. */
1805 delete_breakpoint (b);
1806 break;
c906108c 1807
c5aa993b
JM
1808 case bp_watchpoint:
1809 case bp_hardware_watchpoint:
1810 case bp_read_watchpoint:
1811 case bp_access_watchpoint:
c906108c 1812
c5aa993b
JM
1813 /* Likewise for watchpoints on local expressions. */
1814 if (b->exp_valid_block != NULL)
1815 delete_breakpoint (b);
967af18d 1816 else if (context == inf_starting)
c860120c
PM
1817 {
1818 /* Reset val field to force reread of starting value
1819 in insert_breakpoints. */
1820 if (b->val)
1821 value_free (b->val);
1822 b->val = NULL;
fa4727a6 1823 b->val_valid = 0;
c860120c 1824 }
c5aa993b
JM
1825 break;
1826 default:
c5aa993b
JM
1827 break;
1828 }
1829 }
1c5cfe86
PA
1830
1831 /* Get rid of the moribund locations. */
1832 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix)
1833 free_bp_location (bpt);
1834 VEC_free (bp_location_p, moribund_locations);
c906108c
SS
1835}
1836
c2c6d25f
JM
1837/* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1838 exists at PC. It returns ordinary_breakpoint_here if it's an
1839 ordinary breakpoint, or permanent_breakpoint_here if it's a
1840 permanent breakpoint.
1841 - When continuing from a location with an ordinary breakpoint, we
1842 actually single step once before calling insert_breakpoints.
1843 - When continuing from a localion with a permanent breakpoint, we
1844 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1845 the target, to advance the PC past the breakpoint. */
c906108c 1846
c2c6d25f 1847enum breakpoint_here
fba45db2 1848breakpoint_here_p (CORE_ADDR pc)
c906108c 1849{
89f9893c 1850 const struct bp_location *bpt;
c2c6d25f 1851 int any_breakpoint_here = 0;
c906108c 1852
075f6582
DJ
1853 ALL_BP_LOCATIONS (bpt)
1854 {
1855 if (bpt->loc_type != bp_loc_software_breakpoint
1856 && bpt->loc_type != bp_loc_hardware_breakpoint)
1857 continue;
1858
468d015d 1859 if ((breakpoint_enabled (bpt->owner)
075f6582
DJ
1860 || bpt->owner->enable_state == bp_permanent)
1861 && bpt->address == pc) /* bp is enabled and matches pc */
1862 {
1863 if (overlay_debugging
1864 && section_is_overlay (bpt->section)
1865 && !section_is_mapped (bpt->section))
1866 continue; /* unmapped overlay -- can't be a match */
1867 else if (bpt->owner->enable_state == bp_permanent)
1868 return permanent_breakpoint_here;
1869 else
1870 any_breakpoint_here = 1;
1871 }
1872 }
c906108c 1873
c2c6d25f 1874 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
c906108c
SS
1875}
1876
1c5cfe86
PA
1877/* Return true if there's a moribund breakpoint at PC. */
1878
1879int
1880moribund_breakpoint_here_p (CORE_ADDR pc)
1881{
1882 struct bp_location *loc;
1883 int ix;
1884
1885 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
1886 if (loc->address == pc)
1887 return 1;
1888
1889 return 0;
1890}
c2c6d25f 1891
c36b740a
VP
1892/* Returns non-zero if there's a breakpoint inserted at PC, which is
1893 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1894 This does not check for single-step breakpoints, which are
1895 inserted and removed using direct target manipulation. */
c906108c
SS
1896
1897int
c36b740a 1898regular_breakpoint_inserted_here_p (CORE_ADDR pc)
c906108c 1899{
89f9893c 1900 const struct bp_location *bpt;
c906108c 1901
075f6582 1902 ALL_BP_LOCATIONS (bpt)
c5aa993b 1903 {
075f6582
DJ
1904 if (bpt->loc_type != bp_loc_software_breakpoint
1905 && bpt->loc_type != bp_loc_hardware_breakpoint)
1906 continue;
1907
1908 if (bpt->inserted
1909 && bpt->address == pc) /* bp is inserted and matches pc */
1910 {
1911 if (overlay_debugging
1912 && section_is_overlay (bpt->section)
1913 && !section_is_mapped (bpt->section))
1914 continue; /* unmapped overlay -- can't be a match */
1915 else
1916 return 1;
1917 }
c5aa993b 1918 }
c36b740a
VP
1919 return 0;
1920}
1921
1922/* Returns non-zero iff there's either regular breakpoint
1923 or a single step breakpoint inserted at PC. */
1924
1925int
1926breakpoint_inserted_here_p (CORE_ADDR pc)
1927{
1928 if (regular_breakpoint_inserted_here_p (pc))
1929 return 1;
c906108c 1930
1aafd4da
UW
1931 if (single_step_breakpoint_inserted_here_p (pc))
1932 return 1;
1933
c906108c
SS
1934 return 0;
1935}
1936
4fa8626c
DJ
1937/* This function returns non-zero iff there is a software breakpoint
1938 inserted at PC. */
1939
1940int
1941software_breakpoint_inserted_here_p (CORE_ADDR pc)
1942{
89f9893c 1943 const struct bp_location *bpt;
4fa8626c
DJ
1944 int any_breakpoint_here = 0;
1945
1946 ALL_BP_LOCATIONS (bpt)
1947 {
1948 if (bpt->loc_type != bp_loc_software_breakpoint)
1949 continue;
1950
0d381245 1951 if (bpt->inserted
4fa8626c
DJ
1952 && bpt->address == pc) /* bp is enabled and matches pc */
1953 {
1954 if (overlay_debugging
1955 && section_is_overlay (bpt->section)
1956 && !section_is_mapped (bpt->section))
1957 continue; /* unmapped overlay -- can't be a match */
1958 else
1959 return 1;
1960 }
1961 }
1962
1aafd4da
UW
1963 /* Also check for software single-step breakpoints. */
1964 if (single_step_breakpoint_inserted_here_p (pc))
1965 return 1;
1966
4fa8626c
DJ
1967 return 0;
1968}
1969
075f6582
DJ
1970/* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1971 PC is valid for process/thread PTID. */
c906108c
SS
1972
1973int
39f77062 1974breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
c906108c 1975{
89f9893c 1976 const struct bp_location *bpt;
4a306c9a 1977 /* The thread and task IDs associated to PTID, computed lazily. */
a6f1cd96 1978 int thread = -1;
4a306c9a 1979 int task = 0;
a6f1cd96 1980
075f6582 1981 ALL_BP_LOCATIONS (bpt)
c5aa993b 1982 {
075f6582
DJ
1983 if (bpt->loc_type != bp_loc_software_breakpoint
1984 && bpt->loc_type != bp_loc_hardware_breakpoint)
1985 continue;
1986
a6f1cd96
JB
1987 if (!breakpoint_enabled (bpt->owner)
1988 && bpt->owner->enable_state != bp_permanent)
1989 continue;
1990
1991 if (bpt->address != pc)
1992 continue;
1993
1994 if (bpt->owner->thread != -1)
075f6582 1995 {
a6f1cd96
JB
1996 /* This is a thread-specific breakpoint. Check that ptid
1997 matches that thread. If thread hasn't been computed yet,
1998 it is now time to do so. */
1999 if (thread == -1)
2000 thread = pid_to_thread_id (ptid);
2001 if (bpt->owner->thread != thread)
2002 continue;
075f6582 2003 }
a6f1cd96 2004
4a306c9a
JB
2005 if (bpt->owner->task != 0)
2006 {
2007 /* This is a task-specific breakpoint. Check that ptid
2008 matches that task. If task hasn't been computed yet,
2009 it is now time to do so. */
2010 if (task == 0)
2011 task = ada_get_task_number (ptid);
2012 if (bpt->owner->task != task)
2013 continue;
2014 }
2015
a6f1cd96
JB
2016 if (overlay_debugging
2017 && section_is_overlay (bpt->section)
2018 && !section_is_mapped (bpt->section))
2019 continue; /* unmapped overlay -- can't be a match */
2020
2021 return 1;
c5aa993b 2022 }
c906108c
SS
2023
2024 return 0;
2025}
c906108c 2026\f
c5aa993b 2027
c906108c
SS
2028/* bpstat stuff. External routines' interfaces are documented
2029 in breakpoint.h. */
2030
2031int
fba45db2 2032ep_is_catchpoint (struct breakpoint *ep)
c906108c 2033{
533be4dd 2034 return (ep->type == bp_catchpoint);
c906108c
SS
2035}
2036
198757a8
VP
2037void
2038bpstat_free (bpstat bs)
2039{
2040 if (bs->old_val != NULL)
2041 value_free (bs->old_val);
2042 free_command_lines (&bs->commands);
2043 xfree (bs);
2044}
2045
c906108c
SS
2046/* Clear a bpstat so that it says we are not at any breakpoint.
2047 Also free any storage that is part of a bpstat. */
2048
2049void
fba45db2 2050bpstat_clear (bpstat *bsp)
c906108c
SS
2051{
2052 bpstat p;
2053 bpstat q;
2054
2055 if (bsp == 0)
2056 return;
2057 p = *bsp;
2058 while (p != NULL)
2059 {
2060 q = p->next;
198757a8 2061 bpstat_free (p);
c906108c
SS
2062 p = q;
2063 }
2064 *bsp = NULL;
2065}
2066
2067/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2068 is part of the bpstat is copied as well. */
2069
2070bpstat
fba45db2 2071bpstat_copy (bpstat bs)
c906108c
SS
2072{
2073 bpstat p = NULL;
2074 bpstat tmp;
2075 bpstat retval = NULL;
2076
2077 if (bs == NULL)
2078 return bs;
2079
2080 for (; bs != NULL; bs = bs->next)
2081 {
2082 tmp = (bpstat) xmalloc (sizeof (*tmp));
2083 memcpy (tmp, bs, sizeof (*tmp));
31cc81e9
DJ
2084 if (bs->commands != NULL)
2085 tmp->commands = copy_command_lines (bs->commands);
2086 if (bs->old_val != NULL)
3c3185ac
JK
2087 {
2088 tmp->old_val = value_copy (bs->old_val);
2089 release_value (tmp->old_val);
2090 }
31cc81e9 2091
c906108c
SS
2092 if (p == NULL)
2093 /* This is the first thing in the chain. */
2094 retval = tmp;
2095 else
2096 p->next = tmp;
2097 p = tmp;
2098 }
2099 p->next = NULL;
2100 return retval;
2101}
2102
2103/* Find the bpstat associated with this breakpoint */
2104
2105bpstat
fba45db2 2106bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
c906108c 2107{
c5aa993b
JM
2108 if (bsp == NULL)
2109 return NULL;
c906108c 2110
c5aa993b
JM
2111 for (; bsp != NULL; bsp = bsp->next)
2112 {
4f8d1dc6 2113 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
c5aa993b
JM
2114 return bsp;
2115 }
c906108c
SS
2116 return NULL;
2117}
2118
2119/* Find a step_resume breakpoint associated with this bpstat.
2120 (If there are multiple step_resume bp's on the list, this function
2121 will arbitrarily pick one.)
2122
2123 It is an error to use this function if BPSTAT doesn't contain a
2124 step_resume breakpoint.
2125
2126 See wait_for_inferior's use of this function. */
2127struct breakpoint *
fba45db2 2128bpstat_find_step_resume_breakpoint (bpstat bsp)
c906108c 2129{
8601f500
MS
2130 int current_thread;
2131
8a3fe4f8 2132 gdb_assert (bsp != NULL);
c906108c 2133
8601f500
MS
2134 current_thread = pid_to_thread_id (inferior_ptid);
2135
c906108c
SS
2136 for (; bsp != NULL; bsp = bsp->next)
2137 {
059fb39f
PM
2138 if ((bsp->breakpoint_at != NULL)
2139 && (bsp->breakpoint_at->owner->type == bp_step_resume)
2140 && (bsp->breakpoint_at->owner->thread == current_thread
2141 || bsp->breakpoint_at->owner->thread == -1))
4f8d1dc6 2142 return bsp->breakpoint_at->owner;
c906108c
SS
2143 }
2144
8a3fe4f8 2145 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
c906108c
SS
2146}
2147
2148
8671a17b 2149/* Put in *NUM the breakpoint number of the first breakpoint we are stopped
c906108c
SS
2150 at. *BSP upon return is a bpstat which points to the remaining
2151 breakpoints stopped at (but which is not guaranteed to be good for
2152 anything but further calls to bpstat_num).
8671a17b
PA
2153 Return 0 if passed a bpstat which does not indicate any breakpoints.
2154 Return -1 if stopped at a breakpoint that has been deleted since
2155 we set it.
2156 Return 1 otherwise. */
c906108c
SS
2157
2158int
8671a17b 2159bpstat_num (bpstat *bsp, int *num)
c906108c
SS
2160{
2161 struct breakpoint *b;
2162
2163 if ((*bsp) == NULL)
2164 return 0; /* No more breakpoint values */
8671a17b 2165
4f8d1dc6
VP
2166 /* We assume we'll never have several bpstats that
2167 correspond to a single breakpoint -- otherwise,
2168 this function might return the same number more
2169 than once and this will look ugly. */
2170 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
8671a17b
PA
2171 *bsp = (*bsp)->next;
2172 if (b == NULL)
2173 return -1; /* breakpoint that's been deleted since */
2174
2175 *num = b->number; /* We have its number */
2176 return 1;
c906108c
SS
2177}
2178
2179/* Modify BS so that the actions will not be performed. */
2180
2181void
fba45db2 2182bpstat_clear_actions (bpstat bs)
c906108c
SS
2183{
2184 for (; bs != NULL; bs = bs->next)
2185 {
c2b8ed2c 2186 free_command_lines (&bs->commands);
c906108c
SS
2187 if (bs->old_val != NULL)
2188 {
2189 value_free (bs->old_val);
2190 bs->old_val = NULL;
2191 }
2192 }
2193}
2194
f3b1572e
PA
2195/* Called when a command is about to proceed the inferior. */
2196
2197static void
2198breakpoint_about_to_proceed (void)
2199{
2200 if (!ptid_equal (inferior_ptid, null_ptid))
2201 {
2202 struct thread_info *tp = inferior_thread ();
2203
2204 /* Allow inferior function calls in breakpoint commands to not
2205 interrupt the command list. When the call finishes
2206 successfully, the inferior will be standing at the same
2207 breakpoint as if nothing happened. */
2208 if (tp->in_infcall)
2209 return;
2210 }
2211
2212 breakpoint_proceeded = 1;
2213}
2214
c906108c 2215/* Stub for cleaning up our state if we error-out of a breakpoint command */
c906108c 2216static void
4efb68b1 2217cleanup_executing_breakpoints (void *ignore)
c906108c
SS
2218{
2219 executing_breakpoint_commands = 0;
2220}
2221
2222/* Execute all the commands associated with all the breakpoints at this
2223 location. Any of these commands could cause the process to proceed
2224 beyond this point, etc. We look out for such changes by checking
347bddb7 2225 the global "breakpoint_proceeded" after each command.
c906108c 2226
347bddb7
PA
2227 Returns true if a breakpoint command resumed the inferior. In that
2228 case, it is the caller's responsibility to recall it again with the
2229 bpstat of the current thread. */
2230
2231static int
2232bpstat_do_actions_1 (bpstat *bsp)
c906108c
SS
2233{
2234 bpstat bs;
2235 struct cleanup *old_chain;
347bddb7 2236 int again = 0;
c906108c
SS
2237
2238 /* Avoid endless recursion if a `source' command is contained
2239 in bs->commands. */
2240 if (executing_breakpoint_commands)
347bddb7 2241 return 0;
c906108c
SS
2242
2243 executing_breakpoint_commands = 1;
2244 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2245
c906108c
SS
2246 /* This pointer will iterate over the list of bpstat's. */
2247 bs = *bsp;
2248
2249 breakpoint_proceeded = 0;
2250 for (; bs != NULL; bs = bs->next)
2251 {
6c50ab1c
JB
2252 struct command_line *cmd;
2253 struct cleanup *this_cmd_tree_chain;
2254
2255 /* Take ownership of the BSP's command tree, if it has one.
2256
2257 The command tree could legitimately contain commands like
2258 'step' and 'next', which call clear_proceed_status, which
2259 frees stop_bpstat's command tree. To make sure this doesn't
2260 free the tree we're executing out from under us, we need to
2261 take ownership of the tree ourselves. Since a given bpstat's
2262 commands are only executed once, we don't need to copy it; we
2263 can clear the pointer in the bpstat, and make sure we free
2264 the tree when we're done. */
c906108c 2265 cmd = bs->commands;
6c50ab1c
JB
2266 bs->commands = 0;
2267 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2268
c906108c
SS
2269 while (cmd != NULL)
2270 {
2271 execute_control_command (cmd);
2272
2273 if (breakpoint_proceeded)
2274 break;
2275 else
2276 cmd = cmd->next;
2277 }
6c50ab1c
JB
2278
2279 /* We can free this command tree now. */
2280 do_cleanups (this_cmd_tree_chain);
2281
c906108c 2282 if (breakpoint_proceeded)
32c1e744
VP
2283 {
2284 if (target_can_async_p ())
347bddb7
PA
2285 /* If we are in async mode, then the target might be still
2286 running, not stopped at any breakpoint, so nothing for
2287 us to do here -- just return to the event loop. */
2288 ;
32c1e744
VP
2289 else
2290 /* In sync mode, when execute_control_command returns
2291 we're already standing on the next breakpoint.
347bddb7
PA
2292 Breakpoint commands for that stop were not run, since
2293 execute_command does not run breakpoint commands --
2294 only command_line_handler does, but that one is not
2295 involved in execution of breakpoint commands. So, we
2296 can now execute breakpoint commands. It should be
2297 noted that making execute_command do bpstat actions is
2298 not an option -- in this case we'll have recursive
2299 invocation of bpstat for each breakpoint with a
2300 command, and can easily blow up GDB stack. Instead, we
2301 return true, which will trigger the caller to recall us
2302 with the new stop_bpstat. */
2303 again = 1;
2304 break;
32c1e744 2305 }
c906108c 2306 }
c2b8ed2c 2307 do_cleanups (old_chain);
347bddb7
PA
2308 return again;
2309}
2310
2311void
2312bpstat_do_actions (void)
2313{
2314 /* Do any commands attached to breakpoint we are stopped at. */
2315 while (!ptid_equal (inferior_ptid, null_ptid)
2316 && target_has_execution
2317 && !is_exited (inferior_ptid)
2318 && !is_executing (inferior_ptid))
2319 /* Since in sync mode, bpstat_do_actions may resume the inferior,
2320 and only return when it is stopped at the next breakpoint, we
2321 keep doing breakpoint actions until it returns false to
2322 indicate the inferior was not resumed. */
2323 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat))
2324 break;
c906108c
SS
2325}
2326
fa4727a6
DJ
2327/* Print out the (old or new) value associated with a watchpoint. */
2328
2329static void
2330watchpoint_value_print (struct value *val, struct ui_file *stream)
2331{
2332 if (val == NULL)
2333 fprintf_unfiltered (stream, _("<unreadable>"));
2334 else
79a45b7d
TT
2335 {
2336 struct value_print_options opts;
2337 get_user_print_options (&opts);
2338 value_print (val, stream, &opts);
2339 }
fa4727a6
DJ
2340}
2341
e514a9d6 2342/* This is the normal print function for a bpstat. In the future,
c906108c 2343 much of this logic could (should?) be moved to bpstat_stop_status,
e514a9d6
JM
2344 by having it set different print_it values.
2345
2346 Current scheme: When we stop, bpstat_print() is called. It loops
2347 through the bpstat list of things causing this stop, calling the
2348 print_bp_stop_message function on each one. The behavior of the
2349 print_bp_stop_message function depends on the print_it field of
2350 bpstat. If such field so indicates, call this function here.
2351
2352 Return values from this routine (ultimately used by bpstat_print()
2353 and normal_stop() to decide what to do):
2354 PRINT_NOTHING: Means we already printed all we needed to print,
2355 don't print anything else.
2356 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2357 that something to be followed by a location.
2358 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2359 that something to be followed by a location.
2360 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2361 analysis. */
c906108c 2362
917317f4 2363static enum print_stop_action
fba45db2 2364print_it_typical (bpstat bs)
c906108c 2365{
f7545552 2366 struct cleanup *old_chain;
4f8d1dc6 2367 struct breakpoint *b;
89f9893c 2368 const struct bp_location *bl;
8b93c638 2369 struct ui_stream *stb;
f7545552
TT
2370 int bp_temp = 0;
2371 enum print_stop_action result;
2372
c906108c
SS
2373 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2374 which has since been deleted. */
e514a9d6 2375 if (bs->breakpoint_at == NULL)
917317f4 2376 return PRINT_UNKNOWN;
0d381245
VP
2377 bl = bs->breakpoint_at;
2378 b = bl->owner;
c906108c 2379
f7545552
TT
2380 stb = ui_out_stream_new (uiout);
2381 old_chain = make_cleanup_ui_out_stream_delete (stb);
2382
4f8d1dc6 2383 switch (b->type)
c906108c 2384 {
e514a9d6
JM
2385 case bp_breakpoint:
2386 case bp_hardware_breakpoint:
2cec12e5 2387 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
0d381245
VP
2388 if (bl->address != bl->requested_address)
2389 breakpoint_adjustment_warning (bl->requested_address,
2390 bl->address,
4f8d1dc6
VP
2391 b->number, 1);
2392 annotate_breakpoint (b->number);
2cec12e5
AR
2393 if (bp_temp)
2394 ui_out_text (uiout, "\nTemporary breakpoint ");
2395 else
2396 ui_out_text (uiout, "\nBreakpoint ");
9dc5e2a9 2397 if (ui_out_is_mi_like_p (uiout))
2cec12e5
AR
2398 {
2399 ui_out_field_string (uiout, "reason",
2400 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2401 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2402 }
4f8d1dc6 2403 ui_out_field_int (uiout, "bkptno", b->number);
8b93c638 2404 ui_out_text (uiout, ", ");
f7545552 2405 result = PRINT_SRC_AND_LOC;
e514a9d6
JM
2406 break;
2407
2408 case bp_shlib_event:
917317f4
JM
2409 /* Did we stop because the user set the stop_on_solib_events
2410 variable? (If so, we report this as a generic, "Stopped due
2411 to shlib event" message.) */
a3f17187 2412 printf_filtered (_("Stopped due to shared library event\n"));
f7545552 2413 result = PRINT_NOTHING;
e514a9d6
JM
2414 break;
2415
c4093a6a
JM
2416 case bp_thread_event:
2417 /* Not sure how we will get here.
2418 GDB should not stop for these breakpoints. */
a3f17187 2419 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
f7545552 2420 result = PRINT_NOTHING;
c4093a6a
JM
2421 break;
2422
1900040c
MS
2423 case bp_overlay_event:
2424 /* By analogy with the thread event, GDB should not stop for these. */
a3f17187 2425 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
f7545552 2426 result = PRINT_NOTHING;
1900040c
MS
2427 break;
2428
e514a9d6
JM
2429 case bp_watchpoint:
2430 case bp_hardware_watchpoint:
fa4727a6
DJ
2431 annotate_watchpoint (b->number);
2432 if (ui_out_is_mi_like_p (uiout))
2433 ui_out_field_string
2434 (uiout, "reason",
2435 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2436 mention (b);
f7545552 2437 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
fa4727a6
DJ
2438 ui_out_text (uiout, "\nOld value = ");
2439 watchpoint_value_print (bs->old_val, stb->stream);
2440 ui_out_field_stream (uiout, "old", stb);
2441 ui_out_text (uiout, "\nNew value = ");
2442 watchpoint_value_print (b->val, stb->stream);
2443 ui_out_field_stream (uiout, "new", stb);
fa4727a6 2444 ui_out_text (uiout, "\n");
e514a9d6 2445 /* More than one watchpoint may have been triggered. */
f7545552 2446 result = PRINT_UNKNOWN;
e514a9d6
JM
2447 break;
2448
2449 case bp_read_watchpoint:
9dc5e2a9 2450 if (ui_out_is_mi_like_p (uiout))
034dad6f
BR
2451 ui_out_field_string
2452 (uiout, "reason",
2453 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
4f8d1dc6 2454 mention (b);
f7545552 2455 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8b93c638 2456 ui_out_text (uiout, "\nValue = ");
fa4727a6 2457 watchpoint_value_print (b->val, stb->stream);
8b93c638 2458 ui_out_field_stream (uiout, "value", stb);
8b93c638 2459 ui_out_text (uiout, "\n");
f7545552 2460 result = PRINT_UNKNOWN;
e514a9d6
JM
2461 break;
2462
2463 case bp_access_watchpoint:
fa4727a6 2464 if (bs->old_val != NULL)
8b93c638 2465 {
4f8d1dc6 2466 annotate_watchpoint (b->number);
9dc5e2a9 2467 if (ui_out_is_mi_like_p (uiout))
034dad6f
BR
2468 ui_out_field_string
2469 (uiout, "reason",
2470 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
4f8d1dc6 2471 mention (b);
f7545552 2472 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8b93c638 2473 ui_out_text (uiout, "\nOld value = ");
fa4727a6 2474 watchpoint_value_print (bs->old_val, stb->stream);
8b93c638 2475 ui_out_field_stream (uiout, "old", stb);
8b93c638
JM
2476 ui_out_text (uiout, "\nNew value = ");
2477 }
2478 else
2479 {
4f8d1dc6 2480 mention (b);
9dc5e2a9 2481 if (ui_out_is_mi_like_p (uiout))
034dad6f
BR
2482 ui_out_field_string
2483 (uiout, "reason",
2484 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
f7545552 2485 make_cleanup_ui_out_tuple_begin_end (uiout, "value");
8b93c638
JM
2486 ui_out_text (uiout, "\nValue = ");
2487 }
fa4727a6 2488 watchpoint_value_print (b->val, stb->stream);
8b93c638 2489 ui_out_field_stream (uiout, "new", stb);
8b93c638 2490 ui_out_text (uiout, "\n");
f7545552 2491 result = PRINT_UNKNOWN;
e514a9d6 2492 break;
4ce44c66 2493
e514a9d6
JM
2494 /* Fall through, we don't deal with these types of breakpoints
2495 here. */
2496
11cf8741 2497 case bp_finish:
9dc5e2a9 2498 if (ui_out_is_mi_like_p (uiout))
034dad6f
BR
2499 ui_out_field_string
2500 (uiout, "reason",
2501 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
f7545552 2502 result = PRINT_UNKNOWN;
8b93c638
JM
2503 break;
2504
e514a9d6 2505 case bp_until:
9dc5e2a9 2506 if (ui_out_is_mi_like_p (uiout))
1fbc2a49
NR
2507 ui_out_field_string
2508 (uiout, "reason",
2509 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
f7545552 2510 result = PRINT_UNKNOWN;
8b93c638
JM
2511 break;
2512
c2d11a7d 2513 case bp_none:
e514a9d6
JM
2514 case bp_longjmp:
2515 case bp_longjmp_resume:
2516 case bp_step_resume:
e514a9d6
JM
2517 case bp_watchpoint_scope:
2518 case bp_call_dummy:
1042e4c0 2519 case bp_tracepoint:
e514a9d6 2520 default:
f7545552
TT
2521 result = PRINT_UNKNOWN;
2522 break;
e514a9d6 2523 }
f7545552
TT
2524
2525 do_cleanups (old_chain);
2526 return result;
e514a9d6
JM
2527}
2528
2529/* Generic routine for printing messages indicating why we
2530 stopped. The behavior of this function depends on the value
2531 'print_it' in the bpstat structure. Under some circumstances we
2532 may decide not to print anything here and delegate the task to
2533 normal_stop(). */
2534
2535static enum print_stop_action
2536print_bp_stop_message (bpstat bs)
2537{
2538 switch (bs->print_it)
2539 {
2540 case print_it_noop:
2541 /* Nothing should be printed for this bpstat entry. */
2542 return PRINT_UNKNOWN;
2543 break;
2544
2545 case print_it_done:
2546 /* We still want to print the frame, but we already printed the
2547 relevant messages. */
2548 return PRINT_SRC_AND_LOC;
2549 break;
2550
2551 case print_it_normal:
4f8d1dc6 2552 {
89f9893c 2553 const struct bp_location *bl = bs->breakpoint_at;
4f8d1dc6
VP
2554 struct breakpoint *b = bl ? bl->owner : NULL;
2555
2556 /* Normal case. Call the breakpoint's print_it method, or
2557 print_it_typical. */
2558 /* FIXME: how breakpoint can ever be NULL here? */
2559 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2560 return b->ops->print_it (b);
2561 else
2562 return print_it_typical (bs);
2563 }
2564 break;
3086aeae 2565
e514a9d6 2566 default:
8e65ff28 2567 internal_error (__FILE__, __LINE__,
e2e0b3e5 2568 _("print_bp_stop_message: unrecognized enum value"));
e514a9d6 2569 break;
c906108c 2570 }
c906108c
SS
2571}
2572
e514a9d6
JM
2573/* Print a message indicating what happened. This is called from
2574 normal_stop(). The input to this routine is the head of the bpstat
2575 list - a list of the eventpoints that caused this stop. This
2576 routine calls the generic print routine for printing a message
2577 about reasons for stopping. This will print (for example) the
2578 "Breakpoint n," part of the output. The return value of this
2579 routine is one of:
c906108c 2580
917317f4
JM
2581 PRINT_UNKNOWN: Means we printed nothing
2582 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
c5aa993b
JM
2583 code to print the location. An example is
2584 "Breakpoint 1, " which should be followed by
2585 the location.
917317f4 2586 PRINT_SRC_ONLY: Means we printed something, but there is no need
c5aa993b
JM
2587 to also print the location part of the message.
2588 An example is the catch/throw messages, which
917317f4
JM
2589 don't require a location appended to the end.
2590 PRINT_NOTHING: We have done some printing and we don't need any
2591 further info to be printed.*/
c906108c 2592
917317f4 2593enum print_stop_action
fba45db2 2594bpstat_print (bpstat bs)
c906108c
SS
2595{
2596 int val;
c5aa993b 2597
c906108c 2598 /* Maybe another breakpoint in the chain caused us to stop.
53a5351d
JM
2599 (Currently all watchpoints go on the bpstat whether hit or not.
2600 That probably could (should) be changed, provided care is taken
c906108c 2601 with respect to bpstat_explains_signal). */
e514a9d6
JM
2602 for (; bs; bs = bs->next)
2603 {
2604 val = print_bp_stop_message (bs);
2605 if (val == PRINT_SRC_ONLY
2606 || val == PRINT_SRC_AND_LOC
2607 || val == PRINT_NOTHING)
2608 return val;
2609 }
c906108c 2610
e514a9d6
JM
2611 /* We reached the end of the chain, or we got a null BS to start
2612 with and nothing was printed. */
917317f4 2613 return PRINT_UNKNOWN;
c906108c
SS
2614}
2615
2616/* Evaluate the expression EXP and return 1 if value is zero.
2617 This is used inside a catch_errors to evaluate the breakpoint condition.
2618 The argument is a "struct expression *" that has been cast to char * to
2619 make it pass through catch_errors. */
2620
2621static int
4efb68b1 2622breakpoint_cond_eval (void *exp)
c906108c 2623{
278cd55f 2624 struct value *mark = value_mark ();
c5aa993b 2625 int i = !value_true (evaluate_expression ((struct expression *) exp));
c906108c
SS
2626 value_free_to_mark (mark);
2627 return i;
2628}
2629
2630/* Allocate a new bpstat and chain it to the current one. */
2631
2632static bpstat
89f9893c 2633bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
c906108c
SS
2634{
2635 bpstat bs;
2636
2637 bs = (bpstat) xmalloc (sizeof (*bs));
2638 cbs->next = bs;
4f8d1dc6 2639 bs->breakpoint_at = bl;
c906108c
SS
2640 /* If the condition is false, etc., don't do the commands. */
2641 bs->commands = NULL;
2642 bs->old_val = NULL;
2643 bs->print_it = print_it_normal;
2644 return bs;
2645}
2646\f
d983da9c
DJ
2647/* The target has stopped with waitstatus WS. Check if any hardware
2648 watchpoints have triggered, according to the target. */
2649
2650int
2651watchpoints_triggered (struct target_waitstatus *ws)
2652{
d92524f1 2653 int stopped_by_watchpoint = target_stopped_by_watchpoint ();
d983da9c
DJ
2654 CORE_ADDR addr;
2655 struct breakpoint *b;
2656
2657 if (!stopped_by_watchpoint)
2658 {
2659 /* We were not stopped by a watchpoint. Mark all watchpoints
2660 as not triggered. */
2661 ALL_BREAKPOINTS (b)
2662 if (b->type == bp_hardware_watchpoint
2663 || b->type == bp_read_watchpoint
2664 || b->type == bp_access_watchpoint)
2665 b->watchpoint_triggered = watch_triggered_no;
2666
2667 return 0;
2668 }
2669
2670 if (!target_stopped_data_address (&current_target, &addr))
2671 {
2672 /* We were stopped by a watchpoint, but we don't know where.
2673 Mark all watchpoints as unknown. */
2674 ALL_BREAKPOINTS (b)
2675 if (b->type == bp_hardware_watchpoint
2676 || b->type == bp_read_watchpoint
2677 || b->type == bp_access_watchpoint)
2678 b->watchpoint_triggered = watch_triggered_unknown;
2679
2680 return stopped_by_watchpoint;
2681 }
2682
2683 /* The target could report the data address. Mark watchpoints
2684 affected by this data address as triggered, and all others as not
2685 triggered. */
2686
2687 ALL_BREAKPOINTS (b)
2688 if (b->type == bp_hardware_watchpoint
2689 || b->type == bp_read_watchpoint
2690 || b->type == bp_access_watchpoint)
2691 {
a5606eee 2692 struct bp_location *loc;
d983da9c
DJ
2693 struct value *v;
2694
2695 b->watchpoint_triggered = watch_triggered_no;
a5606eee
VP
2696 for (loc = b->loc; loc; loc = loc->next)
2697 /* Exact match not required. Within range is
2698 sufficient. */
5009afc5
AS
2699 if (target_watchpoint_addr_within_range (&current_target,
2700 addr, loc->address,
2701 loc->length))
a5606eee
VP
2702 {
2703 b->watchpoint_triggered = watch_triggered_yes;
2704 break;
2705 }
d983da9c
DJ
2706 }
2707
2708 return 1;
2709}
2710
c906108c
SS
2711/* Possible return values for watchpoint_check (this can't be an enum
2712 because of check_errors). */
2713/* The watchpoint has been deleted. */
2714#define WP_DELETED 1
2715/* The value has changed. */
2716#define WP_VALUE_CHANGED 2
2717/* The value has not changed. */
2718#define WP_VALUE_NOT_CHANGED 3
2719
2720#define BP_TEMPFLAG 1
2721#define BP_HARDWAREFLAG 2
2722
2723/* Check watchpoint condition. */
2724
2725static int
4efb68b1 2726watchpoint_check (void *p)
c906108c
SS
2727{
2728 bpstat bs = (bpstat) p;
2729 struct breakpoint *b;
2730 struct frame_info *fr;
2731 int within_current_scope;
2732
4f8d1dc6 2733 b = bs->breakpoint_at->owner;
c906108c
SS
2734
2735 if (b->exp_valid_block == NULL)
2736 within_current_scope = 1;
2737 else
2738 {
2739 /* There is no current frame at this moment. If we're going to have
c5aa993b
JM
2740 any chance of handling watchpoints on local variables, we'll need
2741 the frame chain (so we can determine if we're in scope). */
2742 reinit_frame_cache ();
101dcfbe 2743 fr = frame_find_by_id (b->watchpoint_frame);
c906108c 2744 within_current_scope = (fr != NULL);
69fbadd5
DJ
2745
2746 /* If we've gotten confused in the unwinder, we might have
2747 returned a frame that can't describe this variable. */
2748 if (within_current_scope
7f0df278
DJ
2749 && (block_linkage_function (b->exp_valid_block)
2750 != get_frame_function (fr)))
69fbadd5
DJ
2751 within_current_scope = 0;
2752
c12260ac
CV
2753 /* in_function_epilogue_p() returns a non-zero value if we're still
2754 in the function but the stack frame has already been invalidated.
2755 Since we can't rely on the values of local variables after the
2756 stack has been destroyed, we are treating the watchpoint in that
a957e642
CV
2757 state as `not changed' without further checking.
2758
2759 vinschen/2003-09-04: The former implementation left out the case
2760 that the watchpoint frame couldn't be found by frame_find_by_id()
2761 because the current PC is currently in an epilogue. Calling
2762 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
fb14de7b
UW
2763 if (!within_current_scope || fr == get_current_frame ())
2764 {
2765 struct frame_info *frame = get_current_frame ();
2766 struct gdbarch *frame_arch = get_frame_arch (frame);
2767 CORE_ADDR frame_pc = get_frame_pc (frame);
2768
2769 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc))
2770 return WP_VALUE_NOT_CHANGED;
2771 }
a6fbcf2f 2772 if (fr && within_current_scope)
c906108c
SS
2773 /* If we end up stopping, the current frame will get selected
2774 in normal_stop. So this call to select_frame won't affect
2775 the user. */
0f7d239c 2776 select_frame (fr);
c906108c 2777 }
c5aa993b 2778
c906108c
SS
2779 if (within_current_scope)
2780 {
2781 /* We use value_{,free_to_}mark because it could be a
2782 *long* time before we return to the command level and
c5aa993b
JM
2783 call free_all_values. We can't call free_all_values because
2784 we might be in the middle of evaluating a function call. */
c906108c 2785
278cd55f 2786 struct value *mark = value_mark ();
fa4727a6
DJ
2787 struct value *new_val;
2788
2789 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2790 if ((b->val != NULL) != (new_val != NULL)
2791 || (b->val != NULL && !value_equal (b->val, new_val)))
c906108c 2792 {
fa4727a6
DJ
2793 if (new_val != NULL)
2794 {
2795 release_value (new_val);
2796 value_free_to_mark (mark);
2797 }
c906108c
SS
2798 bs->old_val = b->val;
2799 b->val = new_val;
fa4727a6 2800 b->val_valid = 1;
c906108c
SS
2801 /* We will stop here */
2802 return WP_VALUE_CHANGED;
2803 }
2804 else
2805 {
2806 /* Nothing changed, don't do anything. */
2807 value_free_to_mark (mark);
2808 /* We won't stop here */
2809 return WP_VALUE_NOT_CHANGED;
2810 }
2811 }
2812 else
2813 {
2814 /* This seems like the only logical thing to do because
c5aa993b
JM
2815 if we temporarily ignored the watchpoint, then when
2816 we reenter the block in which it is valid it contains
2817 garbage (in the case of a function, it may have two
2818 garbage values, one before and one after the prologue).
2819 So we can't even detect the first assignment to it and
2820 watch after that (since the garbage may or may not equal
2821 the first value assigned). */
4ce44c66
JM
2822 /* We print all the stop information in print_it_typical(), but
2823 in this case, by the time we call print_it_typical() this bp
2824 will be deleted already. So we have no choice but print the
2825 information here. */
9dc5e2a9 2826 if (ui_out_is_mi_like_p (uiout))
034dad6f
BR
2827 ui_out_field_string
2828 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
8b93c638 2829 ui_out_text (uiout, "\nWatchpoint ");
4f8d1dc6 2830 ui_out_field_int (uiout, "wpnum", b->number);
8b93c638
JM
2831 ui_out_text (uiout, " deleted because the program has left the block in\n\
2832which its expression is valid.\n");
4ce44c66 2833
c906108c 2834 if (b->related_breakpoint)
b5de0fa7
EZ
2835 b->related_breakpoint->disposition = disp_del_at_next_stop;
2836 b->disposition = disp_del_at_next_stop;
c906108c
SS
2837
2838 return WP_DELETED;
2839 }
2840}
2841
18a18393
VP
2842/* Return true if it looks like target has stopped due to hitting
2843 breakpoint location BL. This function does not check if we
2844 should stop, only if BL explains the stop. */
2845static int
2846bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
2847{
2848 struct breakpoint *b = bl->owner;
2849
2850 if (b->type != bp_watchpoint
2851 && b->type != bp_hardware_watchpoint
2852 && b->type != bp_read_watchpoint
2853 && b->type != bp_access_watchpoint
2854 && b->type != bp_hardware_breakpoint
fe798b75 2855 && b->type != bp_catchpoint) /* a non-watchpoint bp */
18a18393
VP
2856 {
2857 if (bl->address != bp_addr) /* address doesn't match */
2858 return 0;
2859 if (overlay_debugging /* unmapped overlay section */
2860 && section_is_overlay (bl->section)
2861 && !section_is_mapped (bl->section))
2862 return 0;
2863 }
2864
2865 /* Continuable hardware watchpoints are treated as non-existent if the
2866 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2867 some data address). Otherwise gdb won't stop on a break instruction
2868 in the code (not from a breakpoint) when a hardware watchpoint has
2869 been defined. Also skip watchpoints which we know did not trigger
2870 (did not match the data address). */
2871
2872 if ((b->type == bp_hardware_watchpoint
2873 || b->type == bp_read_watchpoint
2874 || b->type == bp_access_watchpoint)
2875 && b->watchpoint_triggered == watch_triggered_no)
2876 return 0;
2877
2878 if (b->type == bp_hardware_breakpoint)
2879 {
2880 if (bl->address != bp_addr)
2881 return 0;
2882 if (overlay_debugging /* unmapped overlay section */
2883 && section_is_overlay (bl->section)
2884 && !section_is_mapped (bl->section))
2885 return 0;
2886 }
ce78b96d 2887
ce78b96d
JB
2888 if (b->type == bp_catchpoint)
2889 {
2890 gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
2891 if (!b->ops->breakpoint_hit (b))
2892 return 0;
2893 }
2894
18a18393
VP
2895 return 1;
2896}
2897
2898/* If BS refers to a watchpoint, determine if the watched values
2899 has actually changed, and we should stop. If not, set BS->stop
2900 to 0. */
2901static void
2902bpstat_check_watchpoint (bpstat bs)
2903{
2904 const struct bp_location *bl = bs->breakpoint_at;
2905 struct breakpoint *b = bl->owner;
2906
2907 if (b->type == bp_watchpoint
2908 || b->type == bp_read_watchpoint
2909 || b->type == bp_access_watchpoint
2910 || b->type == bp_hardware_watchpoint)
2911 {
2912 CORE_ADDR addr;
2913 struct value *v;
2914 int must_check_value = 0;
2915
2916 if (b->type == bp_watchpoint)
2917 /* For a software watchpoint, we must always check the
2918 watched value. */
2919 must_check_value = 1;
2920 else if (b->watchpoint_triggered == watch_triggered_yes)
2921 /* We have a hardware watchpoint (read, write, or access)
2922 and the target earlier reported an address watched by
2923 this watchpoint. */
2924 must_check_value = 1;
2925 else if (b->watchpoint_triggered == watch_triggered_unknown
2926 && b->type == bp_hardware_watchpoint)
2927 /* We were stopped by a hardware watchpoint, but the target could
2928 not report the data address. We must check the watchpoint's
2929 value. Access and read watchpoints are out of luck; without
2930 a data address, we can't figure it out. */
2931 must_check_value = 1;
2932
2933 if (must_check_value)
2934 {
2935 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2936 b->number);
2937 struct cleanup *cleanups = make_cleanup (xfree, message);
2938 int e = catch_errors (watchpoint_check, bs, message,
2939 RETURN_MASK_ALL);
2940 do_cleanups (cleanups);
2941 switch (e)
2942 {
2943 case WP_DELETED:
2944 /* We've already printed what needs to be printed. */
2945 bs->print_it = print_it_done;
2946 /* Stop. */
2947 break;
2948 case WP_VALUE_CHANGED:
2949 if (b->type == bp_read_watchpoint)
2950 {
2951 /* Don't stop: read watchpoints shouldn't fire if
2952 the value has changed. This is for targets
2953 which cannot set read-only watchpoints. */
2954 bs->print_it = print_it_noop;
2955 bs->stop = 0;
2956 }
2957 break;
2958 case WP_VALUE_NOT_CHANGED:
2959 if (b->type == bp_hardware_watchpoint
2960 || b->type == bp_watchpoint)
2961 {
2962 /* Don't stop: write watchpoints shouldn't fire if
2963 the value hasn't changed. */
2964 bs->print_it = print_it_noop;
2965 bs->stop = 0;
2966 }
2967 /* Stop. */
2968 break;
2969 default:
2970 /* Can't happen. */
2971 case 0:
2972 /* Error from catch_errors. */
2973 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2974 if (b->related_breakpoint)
2975 b->related_breakpoint->disposition = disp_del_at_next_stop;
2976 b->disposition = disp_del_at_next_stop;
2977 /* We've already printed what needs to be printed. */
2978 bs->print_it = print_it_done;
2979 break;
2980 }
2981 }
2982 else /* must_check_value == 0 */
2983 {
2984 /* This is a case where some watchpoint(s) triggered, but
2985 not at the address of this watchpoint, or else no
2986 watchpoint triggered after all. So don't print
2987 anything for this watchpoint. */
2988 bs->print_it = print_it_noop;
2989 bs->stop = 0;
2990 }
2991 }
2992}
2993
2994
2995/* Check conditions (condition proper, frame, thread and ignore count)
2996 of breakpoint referred to by BS. If we should not stop for this
2997 breakpoint, set BS->stop to 0. */
2998static void
2999bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
3000{
3001 int thread_id = pid_to_thread_id (ptid);
3002 const struct bp_location *bl = bs->breakpoint_at;
3003 struct breakpoint *b = bl->owner;
3004
3005 if (frame_id_p (b->frame_id)
3006 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
3007 bs->stop = 0;
3008 else if (bs->stop)
3009 {
3010 int value_is_zero = 0;
3011
3012 /* If this is a scope breakpoint, mark the associated
3013 watchpoint as triggered so that we will handle the
3014 out-of-scope event. We'll get to the watchpoint next
3015 iteration. */
3016 if (b->type == bp_watchpoint_scope)
3017 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
3018
3019 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
3020 {
c5bc3a77
DJ
3021 /* We use value_mark and value_free_to_mark because it could
3022 be a long time before we return to the command level and
3023 call free_all_values. We can't call free_all_values
3024 because we might be in the middle of evaluating a
3025 function call. */
3026 struct value *mark = value_mark ();
3027
18a18393
VP
3028 /* Need to select the frame, with all that implies
3029 so that the conditions will have the right context. */
3030 select_frame (get_current_frame ());
3031 value_is_zero
3032 = catch_errors (breakpoint_cond_eval, (bl->cond),
3033 "Error in testing breakpoint condition:\n",
3034 RETURN_MASK_ALL);
3035 /* FIXME-someday, should give breakpoint # */
c5bc3a77 3036 value_free_to_mark (mark);
18a18393
VP
3037 }
3038 if (bl->cond && value_is_zero)
3039 {
3040 bs->stop = 0;
3041 }
3042 else if (b->thread != -1 && b->thread != thread_id)
3043 {
3044 bs->stop = 0;
3045 }
3046 else if (b->ignore_count > 0)
3047 {
3048 b->ignore_count--;
3049 annotate_ignore_count_change ();
3050 bs->stop = 0;
3051 /* Increase the hit count even though we don't
3052 stop. */
3053 ++(b->hit_count);
3054 }
3055 }
3056}
3057
3058
9709f61c 3059/* Get a bpstat associated with having just stopped at address
d983da9c 3060 BP_ADDR in thread PTID.
c906108c 3061
d983da9c 3062 Determine whether we stopped at a breakpoint, etc, or whether we
c906108c
SS
3063 don't understand this stop. Result is a chain of bpstat's such that:
3064
c5aa993b 3065 if we don't understand the stop, the result is a null pointer.
c906108c 3066
c5aa993b 3067 if we understand why we stopped, the result is not null.
c906108c 3068
c5aa993b
JM
3069 Each element of the chain refers to a particular breakpoint or
3070 watchpoint at which we have stopped. (We may have stopped for
3071 several reasons concurrently.)
c906108c 3072
c5aa993b
JM
3073 Each element of the chain has valid next, breakpoint_at,
3074 commands, FIXME??? fields. */
c906108c
SS
3075
3076bpstat
d983da9c 3077bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
c906108c 3078{
0d381245 3079 struct breakpoint *b = NULL;
89f9893c 3080 const struct bp_location *bl;
20874c92 3081 struct bp_location *loc;
c906108c
SS
3082 /* Root of the chain of bpstat's */
3083 struct bpstats root_bs[1];
3084 /* Pointer to the last thing in the chain currently. */
3085 bpstat bs = root_bs;
20874c92 3086 int ix;
d832cb68 3087 int need_remove_insert;
c906108c 3088
0d381245 3089 ALL_BP_LOCATIONS (bl)
c5aa993b 3090 {
0d381245
VP
3091 b = bl->owner;
3092 gdb_assert (b);
468d015d 3093 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
c5aa993b
JM
3094 continue;
3095
a5606eee
VP
3096 /* For hardware watchpoints, we look only at the first location.
3097 The watchpoint_check function will work on entire expression,
3098 not the individual locations. For read watchopints, the
3099 watchpoints_triggered function have checked all locations
3100 alrea
3101 */
3102 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3103 continue;
3104
18a18393
VP
3105 if (!bpstat_check_location (bl, bp_addr))
3106 continue;
3107
c5aa993b
JM
3108 /* Come here if it's a watchpoint, or if the break address matches */
3109
0d381245 3110 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
c5aa993b 3111
18a18393
VP
3112 /* Assume we stop. Should we find watchpoint that is not actually
3113 triggered, or if condition of breakpoint is false, we'll reset
3114 'stop' to 0. */
c5aa993b
JM
3115 bs->stop = 1;
3116 bs->print = 1;
3117
18a18393
VP
3118 bpstat_check_watchpoint (bs);
3119 if (!bs->stop)
3120 continue;
c5aa993b 3121
18a18393
VP
3122 if (b->type == bp_thread_event || b->type == bp_overlay_event)
3123 /* We do not stop for these. */
c5aa993b
JM
3124 bs->stop = 0;
3125 else
18a18393
VP
3126 bpstat_check_breakpoint_conditions (bs, ptid);
3127
3128 if (bs->stop)
c5aa993b 3129 {
18a18393 3130 ++(b->hit_count);
d983da9c 3131
18a18393
VP
3132 /* We will stop here */
3133 if (b->disposition == disp_disable)
c5aa993b 3134 {
514f746b
AR
3135 if (b->enable_state != bp_permanent)
3136 b->enable_state = bp_disabled;
b60e7edf 3137 update_global_location_list (0);
c5aa993b 3138 }
18a18393
VP
3139 if (b->silent)
3140 bs->print = 0;
3141 bs->commands = b->commands;
059fb39f
PM
3142 if (bs->commands
3143 && (strcmp ("silent", bs->commands->line) == 0
3144 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
c5aa993b 3145 {
18a18393
VP
3146 bs->commands = bs->commands->next;
3147 bs->print = 0;
c5aa993b 3148 }
18a18393 3149 bs->commands = copy_command_lines (bs->commands);
c5aa993b 3150 }
18a18393 3151
c5aa993b
JM
3152 /* Print nothing for this entry if we dont stop or if we dont print. */
3153 if (bs->stop == 0 || bs->print == 0)
3154 bs->print_it = print_it_noop;
3155 }
c906108c 3156
20874c92
VP
3157 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3158 {
3159 if (loc->address == bp_addr)
3160 {
3161 bs = bpstat_alloc (loc, bs);
3162 /* For hits of moribund locations, we should just proceed. */
3163 bs->stop = 0;
3164 bs->print = 0;
3165 bs->print_it = print_it_noop;
3166 }
3167 }
3168
c906108c
SS
3169 bs->next = NULL; /* Terminate the chain */
3170 bs = root_bs->next; /* Re-grab the head of the chain */
3171
d983da9c
DJ
3172 /* If we aren't stopping, the value of some hardware watchpoint may
3173 not have changed, but the intermediate memory locations we are
3174 watching may have. Don't bother if we're stopping; this will get
3175 done later. */
3176 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3177 if (bs->stop)
3178 break;
3179
d832cb68 3180 need_remove_insert = 0;
d983da9c
DJ
3181 if (bs == NULL)
3182 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3183 if (!bs->stop
20874c92 3184 && bs->breakpoint_at->owner
d983da9c
DJ
3185 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3186 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3187 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3188 {
a5606eee
VP
3189 /* remove/insert can invalidate bs->breakpoint_at, if this
3190 location is no longer used by the watchpoint. Prevent
3191 further code from trying to use it. */
3192 bs->breakpoint_at = NULL;
d832cb68 3193 need_remove_insert = 1;
d983da9c
DJ
3194 }
3195
d832cb68
DD
3196 if (need_remove_insert)
3197 {
3198 remove_breakpoints ();
3199 insert_breakpoints ();
3200 }
3201
d983da9c 3202 return root_bs->next;
c906108c
SS
3203}
3204\f
3205/* Tell what to do about this bpstat. */
3206struct bpstat_what
fba45db2 3207bpstat_what (bpstat bs)
c906108c
SS
3208{
3209 /* Classify each bpstat as one of the following. */
c5aa993b
JM
3210 enum class
3211 {
3212 /* This bpstat element has no effect on the main_action. */
3213 no_effect = 0,
3214
3215 /* There was a watchpoint, stop but don't print. */
3216 wp_silent,
c906108c 3217
c5aa993b
JM
3218 /* There was a watchpoint, stop and print. */
3219 wp_noisy,
c906108c 3220
c5aa993b
JM
3221 /* There was a breakpoint but we're not stopping. */
3222 bp_nostop,
c906108c 3223
c5aa993b
JM
3224 /* There was a breakpoint, stop but don't print. */
3225 bp_silent,
c906108c 3226
c5aa993b
JM
3227 /* There was a breakpoint, stop and print. */
3228 bp_noisy,
c906108c 3229
c5aa993b
JM
3230 /* We hit the longjmp breakpoint. */
3231 long_jump,
c906108c 3232
c5aa993b
JM
3233 /* We hit the longjmp_resume breakpoint. */
3234 long_resume,
c906108c 3235
c5aa993b
JM
3236 /* We hit the step_resume breakpoint. */
3237 step_resume,
c906108c 3238
c5aa993b
JM
3239 /* We hit the shared library event breakpoint. */
3240 shlib_event,
c906108c 3241
c5aa993b
JM
3242 /* This is just used to count how many enums there are. */
3243 class_last
c906108c
SS
3244 };
3245
3246 /* Here is the table which drives this routine. So that we can
3247 format it pretty, we define some abbreviations for the
3248 enum bpstat_what codes. */
3249#define kc BPSTAT_WHAT_KEEP_CHECKING
3250#define ss BPSTAT_WHAT_STOP_SILENT
3251#define sn BPSTAT_WHAT_STOP_NOISY
3252#define sgl BPSTAT_WHAT_SINGLE
3253#define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3254#define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
c906108c 3255#define sr BPSTAT_WHAT_STEP_RESUME
c906108c 3256#define shl BPSTAT_WHAT_CHECK_SHLIBS
c906108c
SS
3257
3258/* "Can't happen." Might want to print an error message.
3259 abort() is not out of the question, but chances are GDB is just
3260 a bit confused, not unusable. */
3261#define err BPSTAT_WHAT_STOP_NOISY
3262
3263 /* Given an old action and a class, come up with a new action. */
3264 /* One interesting property of this table is that wp_silent is the same
3265 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3266 after stopping, the check for whether to step over a breakpoint
3267 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
53a5351d
JM
3268 reference to how we stopped. We retain separate wp_silent and
3269 bp_silent codes in case we want to change that someday.
43ff13b4
JM
3270
3271 Another possibly interesting property of this table is that
3272 there's a partial ordering, priority-like, of the actions. Once
3273 you've decided that some action is appropriate, you'll never go
3274 back and decide something of a lower priority is better. The
3275 ordering is:
3276
d81191fc
JB
3277 kc < clr sgl shl slr sn sr ss
3278 sgl < shl slr sn sr ss
3279 slr < err shl sn sr ss
3280 clr < err shl sn sr ss
3281 ss < shl sn sr
3282 sn < shl sr
3283 shl < sr
4d5b2cd7 3284 sr <
c5aa993b 3285
43ff13b4
JM
3286 What I think this means is that we don't need a damned table
3287 here. If you just put the rows and columns in the right order,
3288 it'd look awfully regular. We could simply walk the bpstat list
3289 and choose the highest priority action we find, with a little
78b6a731 3290 logic to handle the 'err' cases. */
c906108c
SS
3291
3292 /* step_resume entries: a step resume breakpoint overrides another
3293 breakpoint of signal handling (see comment in wait_for_inferior
fcf70625 3294 at where we set the step_resume breakpoint). */
c906108c
SS
3295
3296 static const enum bpstat_what_main_action
c5aa993b
JM
3297 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3298 {
3299 /* old action */
d81191fc 3300 /* kc ss sn sgl slr clr sr shl
c5aa993b
JM
3301 */
3302/*no_effect */
d81191fc 3303 {kc, ss, sn, sgl, slr, clr, sr, shl},
c5aa993b 3304/*wp_silent */
d81191fc 3305 {ss, ss, sn, ss, ss, ss, sr, shl},
c5aa993b 3306/*wp_noisy */
d81191fc 3307 {sn, sn, sn, sn, sn, sn, sr, shl},
c5aa993b 3308/*bp_nostop */
d81191fc 3309 {sgl, ss, sn, sgl, slr, slr, sr, shl},
c5aa993b 3310/*bp_silent */
d81191fc 3311 {ss, ss, sn, ss, ss, ss, sr, shl},
c5aa993b 3312/*bp_noisy */
d81191fc 3313 {sn, sn, sn, sn, sn, sn, sr, shl},
c5aa993b 3314/*long_jump */
d81191fc 3315 {slr, ss, sn, slr, slr, err, sr, shl},
c5aa993b 3316/*long_resume */
d81191fc 3317 {clr, ss, sn, err, err, err, sr, shl},
c5aa993b 3318/*step_resume */
d81191fc 3319 {sr, sr, sr, sr, sr, sr, sr, sr},
c5aa993b 3320/*shlib */
d81191fc 3321 {shl, shl, shl, shl, shl, shl, sr, shl}
c5aa993b 3322 };
c906108c
SS
3323
3324#undef kc
3325#undef ss
3326#undef sn
3327#undef sgl
3328#undef slr
3329#undef clr
c906108c
SS
3330#undef err
3331#undef sr
3332#undef ts
3333#undef shl
c906108c
SS
3334 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3335 struct bpstat_what retval;
3336
3337 retval.call_dummy = 0;
3338 for (; bs != NULL; bs = bs->next)
3339 {
3340 enum class bs_class = no_effect;
3341 if (bs->breakpoint_at == NULL)
3342 /* I suspect this can happen if it was a momentary breakpoint
3343 which has since been deleted. */
3344 continue;
20874c92
VP
3345 if (bs->breakpoint_at->owner == NULL)
3346 bs_class = bp_nostop;
3347 else
4f8d1dc6 3348 switch (bs->breakpoint_at->owner->type)
c906108c
SS
3349 {
3350 case bp_none:
3351 continue;
3352
3353 case bp_breakpoint:
3354 case bp_hardware_breakpoint:
3355 case bp_until:
3356 case bp_finish:
3357 if (bs->stop)
3358 {
3359 if (bs->print)
3360 bs_class = bp_noisy;
3361 else
3362 bs_class = bp_silent;
3363 }
3364 else
3365 bs_class = bp_nostop;
3366 break;
3367 case bp_watchpoint:
3368 case bp_hardware_watchpoint:
3369 case bp_read_watchpoint:
3370 case bp_access_watchpoint:
3371 if (bs->stop)
3372 {
3373 if (bs->print)
3374 bs_class = wp_noisy;
3375 else
3376 bs_class = wp_silent;
3377 }
3378 else
53a5351d
JM
3379 /* There was a watchpoint, but we're not stopping.
3380 This requires no further action. */
c906108c
SS
3381 bs_class = no_effect;
3382 break;
3383 case bp_longjmp:
3384 bs_class = long_jump;
3385 break;
3386 case bp_longjmp_resume:
3387 bs_class = long_resume;
3388 break;
3389 case bp_step_resume:
3390 if (bs->stop)
3391 {
3392 bs_class = step_resume;
3393 }
3394 else
3395 /* It is for the wrong frame. */
3396 bs_class = bp_nostop;
3397 break;
c906108c
SS
3398 case bp_watchpoint_scope:
3399 bs_class = bp_nostop;
3400 break;
c5aa993b
JM
3401 case bp_shlib_event:
3402 bs_class = shlib_event;
3403 break;
c4093a6a 3404 case bp_thread_event:
1900040c 3405 case bp_overlay_event:
c4093a6a
JM
3406 bs_class = bp_nostop;
3407 break;
ce78b96d 3408 case bp_catchpoint:
c5aa993b
JM
3409 if (bs->stop)
3410 {
3411 if (bs->print)
3412 bs_class = bp_noisy;
3413 else
3414 bs_class = bp_silent;
3415 }
3416 else
53a5351d
JM
3417 /* There was a catchpoint, but we're not stopping.
3418 This requires no further action. */
c5aa993b
JM
3419 bs_class = no_effect;
3420 break;
c906108c 3421 case bp_call_dummy:
53a5351d
JM
3422 /* Make sure the action is stop (silent or noisy),
3423 so infrun.c pops the dummy frame. */
c906108c
SS
3424 bs_class = bp_silent;
3425 retval.call_dummy = 1;
3426 break;
1042e4c0
SS
3427 case bp_tracepoint:
3428 /* Tracepoint hits should not be reported back to GDB, and
3429 if one got through somehow, it should have been filtered
3430 out already. */
3431 internal_error (__FILE__, __LINE__,
3432 _("bpstat_what: bp_tracepoint encountered"));
3433 break;
c906108c 3434 }
c5aa993b 3435 current_action = table[(int) bs_class][(int) current_action];
c906108c
SS
3436 }
3437 retval.main_action = current_action;
3438 return retval;
3439}
3440
3441/* Nonzero if we should step constantly (e.g. watchpoints on machines
3442 without hardware support). This isn't related to a specific bpstat,
3443 just to things like whether watchpoints are set. */
3444
c5aa993b 3445int
fba45db2 3446bpstat_should_step (void)
c906108c
SS
3447{
3448 struct breakpoint *b;
3449 ALL_BREAKPOINTS (b)
717a8278 3450 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL)
3172dc30 3451 return 1;
c906108c
SS
3452 return 0;
3453}
3454
c906108c 3455\f
c5aa993b 3456
0d381245
VP
3457static void print_breakpoint_location (struct breakpoint *b,
3458 struct bp_location *loc,
3459 char *wrap_indent,
3460 struct ui_stream *stb)
3461{
3462 if (b->source_file)
3463 {
3464 struct symbol *sym
3465 = find_pc_sect_function (loc->address, loc->section);
3466 if (sym)
3467 {
3468 ui_out_text (uiout, "in ");
3469 ui_out_field_string (uiout, "func",
3470 SYMBOL_PRINT_NAME (sym));
3471 ui_out_wrap_hint (uiout, wrap_indent);
3472 ui_out_text (uiout, " at ");
3473 }
3474 ui_out_field_string (uiout, "file", b->source_file);
3475 ui_out_text (uiout, ":");
3476
3477 if (ui_out_is_mi_like_p (uiout))
3478 {
3479 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3480 char *fullname = symtab_to_fullname (sal.symtab);
3481
3482 if (fullname)
3483 ui_out_field_string (uiout, "fullname", fullname);
3484 }
3485
3486 ui_out_field_int (uiout, "line", b->line_number);
3487 }
3488 else if (!b->loc)
3489 {
3490 ui_out_field_string (uiout, "pending", b->addr_string);
3491 }
3492 else
3493 {
3494 print_address_symbolic (loc->address, stb->stream, demangle, "");
3495 ui_out_field_stream (uiout, "at", stb);
3496 }
3497}
3498
c4093a6a 3499/* Print B to gdb_stdout. */
c906108c 3500static void
0d381245
VP
3501print_one_breakpoint_location (struct breakpoint *b,
3502 struct bp_location *loc,
3503 int loc_number,
3504 CORE_ADDR *last_addr)
c906108c 3505{
52f0bd74
AC
3506 struct command_line *l;
3507 struct symbol *sym;
c4093a6a
JM
3508 struct ep_type_description
3509 {
3510 enum bptype type;
3511 char *description;
3512 };
3513 static struct ep_type_description bptypes[] =
c906108c 3514 {
c5aa993b
JM
3515 {bp_none, "?deleted?"},
3516 {bp_breakpoint, "breakpoint"},
c906108c 3517 {bp_hardware_breakpoint, "hw breakpoint"},
c5aa993b
JM
3518 {bp_until, "until"},
3519 {bp_finish, "finish"},
3520 {bp_watchpoint, "watchpoint"},
c906108c 3521 {bp_hardware_watchpoint, "hw watchpoint"},
c5aa993b
JM
3522 {bp_read_watchpoint, "read watchpoint"},
3523 {bp_access_watchpoint, "acc watchpoint"},
3524 {bp_longjmp, "longjmp"},
3525 {bp_longjmp_resume, "longjmp resume"},
3526 {bp_step_resume, "step resume"},
c5aa993b
JM
3527 {bp_watchpoint_scope, "watchpoint scope"},
3528 {bp_call_dummy, "call dummy"},
3529 {bp_shlib_event, "shlib events"},
c4093a6a 3530 {bp_thread_event, "thread events"},
1900040c 3531 {bp_overlay_event, "overlay events"},
ce78b96d 3532 {bp_catchpoint, "catchpoint"},
1042e4c0 3533 {bp_tracepoint, "tracepoint"},
c5aa993b 3534 };
c4093a6a 3535
c2c6d25f 3536 static char bpenables[] = "nynny";
c906108c 3537 char wrap_indent[80];
8b93c638
JM
3538 struct ui_stream *stb = ui_out_stream_new (uiout);
3539 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3b31d625 3540 struct cleanup *bkpt_chain;
c906108c 3541
0d381245
VP
3542 int header_of_multiple = 0;
3543 int part_of_multiple = (loc != NULL);
79a45b7d
TT
3544 struct value_print_options opts;
3545
3546 get_user_print_options (&opts);
0d381245
VP
3547
3548 gdb_assert (!loc || loc_number != 0);
3549 /* See comment in print_one_breakpoint concerning
3550 treatment of breakpoints with single disabled
3551 location. */
3552 if (loc == NULL
3553 && (b->loc != NULL
3554 && (b->loc->next != NULL || !b->loc->enabled)))
3555 header_of_multiple = 1;
3556 if (loc == NULL)
3557 loc = b->loc;
3558
c4093a6a 3559 annotate_record ();
3b31d625 3560 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
c4093a6a
JM
3561
3562 /* 1 */
3563 annotate_field (0);
0d381245
VP
3564 if (part_of_multiple)
3565 {
3566 char *formatted;
0c6773c1 3567 formatted = xstrprintf ("%d.%d", b->number, loc_number);
0d381245
VP
3568 ui_out_field_string (uiout, "number", formatted);
3569 xfree (formatted);
3570 }
3571 else
3572 {
3573 ui_out_field_int (uiout, "number", b->number);
3574 }
c4093a6a
JM
3575
3576 /* 2 */
3577 annotate_field (1);
0d381245
VP
3578 if (part_of_multiple)
3579 ui_out_field_skip (uiout, "type");
3580 else
3581 {
3582 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3583 || ((int) b->type != bptypes[(int) b->type].type))
3584 internal_error (__FILE__, __LINE__,
3585 _("bptypes table does not describe type #%d."),
3586 (int) b->type);
3587 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3588 }
c4093a6a
JM
3589
3590 /* 3 */
3591 annotate_field (2);
0d381245
VP
3592 if (part_of_multiple)
3593 ui_out_field_skip (uiout, "disp");
3594 else
2cec12e5 3595 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
0d381245 3596
c4093a6a
JM
3597
3598 /* 4 */
3599 annotate_field (3);
0d381245 3600 if (part_of_multiple)
54e52265 3601 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
0d381245 3602 else
54e52265
VP
3603 ui_out_field_fmt (uiout, "enabled", "%c",
3604 bpenables[(int) b->enable_state]);
3605 ui_out_spaces (uiout, 2);
0d381245 3606
c4093a6a
JM
3607
3608 /* 5 and 6 */
3609 strcpy (wrap_indent, " ");
79a45b7d 3610 if (opts.addressprint)
75ac9d7b 3611 {
17a912b6 3612 if (gdbarch_addr_bit (current_gdbarch) <= 32)
75ac9d7b
MS
3613 strcat (wrap_indent, " ");
3614 else
3615 strcat (wrap_indent, " ");
3616 }
c906108c 3617
3086aeae 3618 if (b->ops != NULL && b->ops->print_one != NULL)
0d381245
VP
3619 {
3620 /* Although the print_one can possibly print
3621 all locations, calling it here is not likely
3622 to get any nice result. So, make sure there's
3623 just one location. */
3624 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3625 b->ops->print_one (b, last_addr);
3626 }
3086aeae
DJ
3627 else
3628 switch (b->type)
3629 {
3630 case bp_none:
3631 internal_error (__FILE__, __LINE__,
e2e0b3e5 3632 _("print_one_breakpoint: bp_none encountered\n"));
3086aeae 3633 break;
c906108c 3634
3086aeae
DJ
3635 case bp_watchpoint:
3636 case bp_hardware_watchpoint:
3637 case bp_read_watchpoint:
3638 case bp_access_watchpoint:
3639 /* Field 4, the address, is omitted (which makes the columns
3640 not line up too nicely with the headers, but the effect
3641 is relatively readable). */
79a45b7d 3642 if (opts.addressprint)
3086aeae
DJ
3643 ui_out_field_skip (uiout, "addr");
3644 annotate_field (5);
fa8a61dc 3645 ui_out_field_string (uiout, "what", b->exp_string);
3086aeae
DJ
3646 break;
3647
3086aeae
DJ
3648 case bp_breakpoint:
3649 case bp_hardware_breakpoint:
3650 case bp_until:
3651 case bp_finish:
3652 case bp_longjmp:
3653 case bp_longjmp_resume:
3654 case bp_step_resume:
3086aeae
DJ
3655 case bp_watchpoint_scope:
3656 case bp_call_dummy:
3657 case bp_shlib_event:
3658 case bp_thread_event:
3659 case bp_overlay_event:
1042e4c0 3660 case bp_tracepoint:
79a45b7d 3661 if (opts.addressprint)
3086aeae
DJ
3662 {
3663 annotate_field (4);
54e52265 3664 if (header_of_multiple)
0d381245 3665 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
e9bbd7c5 3666 else if (b->loc == NULL || loc->shlib_disabled)
54e52265 3667 ui_out_field_string (uiout, "addr", "<PENDING>");
0101ce28 3668 else
0d381245 3669 ui_out_field_core_addr (uiout, "addr", loc->address);
3086aeae
DJ
3670 }
3671 annotate_field (5);
0d381245
VP
3672 if (!header_of_multiple)
3673 print_breakpoint_location (b, loc, wrap_indent, stb);
3674 if (b->loc)
3675 *last_addr = b->loc->address;
3086aeae
DJ
3676 break;
3677 }
c906108c 3678
4a306c9a 3679 if (!part_of_multiple)
c4093a6a 3680 {
4a306c9a
JB
3681 if (b->thread != -1)
3682 {
3683 /* FIXME: This seems to be redundant and lost here; see the
3684 "stop only in" line a little further down. */
3685 ui_out_text (uiout, " thread ");
3686 ui_out_field_int (uiout, "thread", b->thread);
3687 }
3688 else if (b->task != 0)
3689 {
3690 ui_out_text (uiout, " task ");
3691 ui_out_field_int (uiout, "task", b->task);
3692 }
c4093a6a
JM
3693 }
3694
8b93c638 3695 ui_out_text (uiout, "\n");
c4093a6a 3696
0d381245 3697 if (part_of_multiple && frame_id_p (b->frame_id))
c4093a6a
JM
3698 {
3699 annotate_field (6);
8b93c638 3700 ui_out_text (uiout, "\tstop only in stack frame at ");
818dd999
AC
3701 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3702 the frame ID. */
d0a55772 3703 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
8b93c638 3704 ui_out_text (uiout, "\n");
c4093a6a
JM
3705 }
3706
0d381245 3707 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
c4093a6a 3708 {
f7f9143b
JB
3709 /* We do not print the condition for Ada exception catchpoints
3710 because the condition is an internal implementation detail
3711 that we do not want to expose to the user. */
c4093a6a 3712 annotate_field (7);
1042e4c0
SS
3713 if (b->type == bp_tracepoint)
3714 ui_out_text (uiout, "\ttrace only if ");
3715 else
3716 ui_out_text (uiout, "\tstop only if ");
0101ce28
JJ
3717 ui_out_field_string (uiout, "cond", b->cond_string);
3718 ui_out_text (uiout, "\n");
3719 }
3720
0d381245 3721 if (!part_of_multiple && b->thread != -1)
c4093a6a
JM
3722 {
3723 /* FIXME should make an annotation for this */
8b93c638
JM
3724 ui_out_text (uiout, "\tstop only in thread ");
3725 ui_out_field_int (uiout, "thread", b->thread);
3726 ui_out_text (uiout, "\n");
c4093a6a
JM
3727 }
3728
63c715c6 3729 if (!part_of_multiple && b->hit_count)
c4093a6a
JM
3730 {
3731 /* FIXME should make an annotation for this */
8b93c638
JM
3732 if (ep_is_catchpoint (b))
3733 ui_out_text (uiout, "\tcatchpoint");
3734 else
3735 ui_out_text (uiout, "\tbreakpoint");
3736 ui_out_text (uiout, " already hit ");
3737 ui_out_field_int (uiout, "times", b->hit_count);
3738 if (b->hit_count == 1)
3739 ui_out_text (uiout, " time\n");
3740 else
3741 ui_out_text (uiout, " times\n");
c4093a6a
JM
3742 }
3743
fb40c209
AC
3744 /* Output the count also if it is zero, but only if this is
3745 mi. FIXME: Should have a better test for this. */
9dc5e2a9 3746 if (ui_out_is_mi_like_p (uiout))
63c715c6 3747 if (!part_of_multiple && b->hit_count == 0)
fb40c209 3748 ui_out_field_int (uiout, "times", b->hit_count);
8b93c638 3749
0d381245 3750 if (!part_of_multiple && b->ignore_count)
c4093a6a
JM
3751 {
3752 annotate_field (8);
8b93c638
JM
3753 ui_out_text (uiout, "\tignore next ");
3754 ui_out_field_int (uiout, "ignore", b->ignore_count);
3755 ui_out_text (uiout, " hits\n");
c4093a6a 3756 }
059fb39f
PM
3757
3758 l = b->commands;
3759 if (!part_of_multiple && l)
c4093a6a 3760 {
3b31d625
EZ
3761 struct cleanup *script_chain;
3762
c4093a6a 3763 annotate_field (9);
3b31d625 3764 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
8b93c638 3765 print_command_lines (uiout, l, 4);
3b31d625 3766 do_cleanups (script_chain);
c4093a6a 3767 }
d24317b4 3768
1042e4c0
SS
3769 if (!part_of_multiple && b->pass_count)
3770 {
3771 annotate_field (10);
3772 ui_out_text (uiout, "\tpass count ");
3773 ui_out_field_int (uiout, "pass", b->pass_count);
3774 ui_out_text (uiout, " \n");
3775 }
3776
3777 if (!part_of_multiple && b->step_count)
3778 {
3779 annotate_field (11);
3780 ui_out_text (uiout, "\tstep count ");
3781 ui_out_field_int (uiout, "step", b->step_count);
3782 ui_out_text (uiout, " \n");
3783 }
3784
3785 if (!part_of_multiple && b->actions)
3786 {
3787 struct action_line *action;
3788 annotate_field (12);
3789 for (action = b->actions; action; action = action->next)
3790 {
3791 ui_out_text (uiout, " A\t");
3792 ui_out_text (uiout, action->action);
3793 ui_out_text (uiout, "\n");
3794 }
3795 }
3796
d24317b4
VP
3797 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
3798 {
3799 if (b->addr_string)
3800 ui_out_field_string (uiout, "original-location", b->addr_string);
3801 else if (b->exp_string)
3802 ui_out_field_string (uiout, "original-location", b->exp_string);
3803 }
3804
3b31d625 3805 do_cleanups (bkpt_chain);
8b93c638 3806 do_cleanups (old_chain);
c4093a6a 3807}
c5aa993b 3808
0d381245
VP
3809static void
3810print_one_breakpoint (struct breakpoint *b,
3811 CORE_ADDR *last_addr)
3812{
3813 print_one_breakpoint_location (b, NULL, 0, last_addr);
3814
3815 /* If this breakpoint has custom print function,
3816 it's already printed. Otherwise, print individual
3817 locations, if any. */
3818 if (b->ops == NULL || b->ops->print_one == NULL)
3819 {
3820 /* If breakpoint has a single location that is
3821 disabled, we print it as if it had
3822 several locations, since otherwise it's hard to
3823 represent "breakpoint enabled, location disabled"
a5606eee
VP
3824 situation.
3825 Note that while hardware watchpoints have
3826 several locations internally, that's no a property
3827 exposed to user. */
0d381245 3828 if (b->loc
a5606eee 3829 && !is_hardware_watchpoint (b)
0d381245 3830 && (b->loc->next || !b->loc->enabled)
a5606eee 3831 && !ui_out_is_mi_like_p (uiout))
0d381245
VP
3832 {
3833 struct bp_location *loc;
3834 int n = 1;
3835 for (loc = b->loc; loc; loc = loc->next, ++n)
3836 print_one_breakpoint_location (b, loc, n, last_addr);
3837 }
3838 }
3839}
3840
3841
c4093a6a
JM
3842struct captured_breakpoint_query_args
3843 {
3844 int bnum;
3845 };
c5aa993b 3846
c4093a6a 3847static int
2b65245e 3848do_captured_breakpoint_query (struct ui_out *uiout, void *data)
c4093a6a
JM
3849{
3850 struct captured_breakpoint_query_args *args = data;
52f0bd74 3851 struct breakpoint *b;
c4093a6a
JM
3852 CORE_ADDR dummy_addr = 0;
3853 ALL_BREAKPOINTS (b)
3854 {
3855 if (args->bnum == b->number)
c5aa993b 3856 {
c4093a6a
JM
3857 print_one_breakpoint (b, &dummy_addr);
3858 return GDB_RC_OK;
c5aa993b 3859 }
c4093a6a
JM
3860 }
3861 return GDB_RC_NONE;
3862}
c5aa993b 3863
c4093a6a 3864enum gdb_rc
ce43223b 3865gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
c4093a6a
JM
3866{
3867 struct captured_breakpoint_query_args args;
3868 args.bnum = bnum;
3869 /* For the moment we don't trust print_one_breakpoint() to not throw
3870 an error. */
b0b13bb4
DJ
3871 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3872 error_message, RETURN_MASK_ALL) < 0)
3873 return GDB_RC_FAIL;
3874 else
3875 return GDB_RC_OK;
c4093a6a 3876}
c5aa993b 3877
7f3b0473
AC
3878/* Return non-zero if B is user settable (breakpoints, watchpoints,
3879 catchpoints, et.al.). */
3880
3881static int
3882user_settable_breakpoint (const struct breakpoint *b)
3883{
3884 return (b->type == bp_breakpoint
ce78b96d 3885 || b->type == bp_catchpoint
7f3b0473 3886 || b->type == bp_hardware_breakpoint
1042e4c0 3887 || b->type == bp_tracepoint
7f3b0473
AC
3888 || b->type == bp_watchpoint
3889 || b->type == bp_read_watchpoint
3890 || b->type == bp_access_watchpoint
3891 || b->type == bp_hardware_watchpoint);
3892}
3893
3894/* Print information on user settable breakpoint (watchpoint, etc)
3895 number BNUM. If BNUM is -1 print all user settable breakpoints.
3896 If ALLFLAG is non-zero, include non- user settable breakpoints. */
c906108c 3897
c4093a6a 3898static void
fba45db2 3899breakpoint_1 (int bnum, int allflag)
c4093a6a 3900{
52f0bd74 3901 struct breakpoint *b;
c4093a6a 3902 CORE_ADDR last_addr = (CORE_ADDR) -1;
7f3b0473 3903 int nr_printable_breakpoints;
3b31d625 3904 struct cleanup *bkpttbl_chain;
79a45b7d 3905 struct value_print_options opts;
c4093a6a 3906
79a45b7d
TT
3907 get_user_print_options (&opts);
3908
7f3b0473
AC
3909 /* Compute the number of rows in the table. */
3910 nr_printable_breakpoints = 0;
3911 ALL_BREAKPOINTS (b)
3912 if (bnum == -1
3913 || bnum == b->number)
3914 {
3915 if (allflag || user_settable_breakpoint (b))
3916 nr_printable_breakpoints++;
3917 }
3918
79a45b7d 3919 if (opts.addressprint)
3b31d625
EZ
3920 bkpttbl_chain
3921 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3922 "BreakpointTable");
8b93c638 3923 else
3b31d625
EZ
3924 bkpttbl_chain
3925 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3926 "BreakpointTable");
8b93c638 3927
7f3b0473 3928 if (nr_printable_breakpoints > 0)
d7faa9e7
AC
3929 annotate_breakpoints_headers ();
3930 if (nr_printable_breakpoints > 0)
3931 annotate_field (0);
0d381245 3932 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
d7faa9e7
AC
3933 if (nr_printable_breakpoints > 0)
3934 annotate_field (1);
3935 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3936 if (nr_printable_breakpoints > 0)
3937 annotate_field (2);
3938 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3939 if (nr_printable_breakpoints > 0)
3940 annotate_field (3);
54e52265 3941 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
79a45b7d 3942 if (opts.addressprint)
7f3b0473 3943 {
d7faa9e7
AC
3944 if (nr_printable_breakpoints > 0)
3945 annotate_field (4);
17a912b6 3946 if (gdbarch_addr_bit (current_gdbarch) <= 32)
b25959ec 3947 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
7f3b0473 3948 else
b25959ec 3949 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
7f3b0473 3950 }
d7faa9e7
AC
3951 if (nr_printable_breakpoints > 0)
3952 annotate_field (5);
3953 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3954 ui_out_table_body (uiout);
3955 if (nr_printable_breakpoints > 0)
3956 annotate_breakpoints_table ();
7f3b0473 3957
c4093a6a
JM
3958 ALL_BREAKPOINTS (b)
3959 if (bnum == -1
3960 || bnum == b->number)
3961 {
3962 /* We only print out user settable breakpoints unless the
3963 allflag is set. */
7f3b0473
AC
3964 if (allflag || user_settable_breakpoint (b))
3965 print_one_breakpoint (b, &last_addr);
c4093a6a
JM
3966 }
3967
3b31d625 3968 do_cleanups (bkpttbl_chain);
698384cd 3969
7f3b0473 3970 if (nr_printable_breakpoints == 0)
c906108c 3971 {
8b93c638
JM
3972 if (bnum == -1)
3973 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3974 else
3975 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3976 bnum);
c906108c
SS
3977 }
3978 else
c4093a6a
JM
3979 {
3980 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3981 that a comparison of an unsigned with -1 is always false. */
d1aa2f50 3982 if (last_addr != (CORE_ADDR) -1 && !server_command)
8b9b9e1a 3983 set_next_address (current_gdbarch, last_addr);
c4093a6a 3984 }
c906108c 3985
c4093a6a
JM
3986 /* FIXME? Should this be moved up so that it is only called when
3987 there have been breakpoints? */
c906108c
SS
3988 annotate_breakpoints_table_end ();
3989}
3990
c906108c 3991static void
fba45db2 3992breakpoints_info (char *bnum_exp, int from_tty)
c906108c
SS
3993{
3994 int bnum = -1;
3995
3996 if (bnum_exp)
bb518678 3997 bnum = parse_and_eval_long (bnum_exp);
c906108c
SS
3998
3999 breakpoint_1 (bnum, 0);
4000}
4001
7a292a7a 4002static void
fba45db2 4003maintenance_info_breakpoints (char *bnum_exp, int from_tty)
c906108c
SS
4004{
4005 int bnum = -1;
4006
4007 if (bnum_exp)
bb518678 4008 bnum = parse_and_eval_long (bnum_exp);
c906108c
SS
4009
4010 breakpoint_1 (bnum, 1);
4011}
4012
0d381245 4013static int
714835d5
UW
4014breakpoint_has_pc (struct breakpoint *b,
4015 CORE_ADDR pc, struct obj_section *section)
0d381245
VP
4016{
4017 struct bp_location *bl = b->loc;
4018 for (; bl; bl = bl->next)
4019 {
4020 if (bl->address == pc
4021 && (!overlay_debugging || bl->section == section))
4022 return 1;
4023 }
4024 return 0;
4025}
4026
c906108c
SS
4027/* Print a message describing any breakpoints set at PC. */
4028
4029static void
714835d5
UW
4030describe_other_breakpoints (CORE_ADDR pc, struct obj_section *section,
4031 int thread)
c906108c 4032{
52f0bd74
AC
4033 int others = 0;
4034 struct breakpoint *b;
c906108c
SS
4035
4036 ALL_BREAKPOINTS (b)
0d381245 4037 others += breakpoint_has_pc (b, pc, section);
c906108c
SS
4038 if (others > 0)
4039 {
a3f17187
AC
4040 if (others == 1)
4041 printf_filtered (_("Note: breakpoint "));
4042 else /* if (others == ???) */
4043 printf_filtered (_("Note: breakpoints "));
c906108c 4044 ALL_BREAKPOINTS (b)
0d381245
VP
4045 if (breakpoint_has_pc (b, pc, section))
4046 {
4047 others--;
4048 printf_filtered ("%d", b->number);
4049 if (b->thread == -1 && thread != -1)
4050 printf_filtered (" (all threads)");
4051 else if (b->thread != -1)
4052 printf_filtered (" (thread %d)", b->thread);
4053 printf_filtered ("%s%s ",
059fb39f
PM
4054 ((b->enable_state == bp_disabled
4055 || b->enable_state == bp_call_disabled)
0d381245
VP
4056 ? " (disabled)"
4057 : b->enable_state == bp_permanent
4058 ? " (permanent)"
4059 : ""),
4060 (others > 1) ? ","
4061 : ((others == 1) ? " and" : ""));
4062 }
a3f17187 4063 printf_filtered (_("also set at pc "));
ed49a04f 4064 fputs_filtered (paddress (pc), gdb_stdout);
c906108c
SS
4065 printf_filtered (".\n");
4066 }
4067}
4068\f
4069/* Set the default place to put a breakpoint
4070 for the `break' command with no arguments. */
4071
4072void
fba45db2
KB
4073set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4074 int line)
c906108c
SS
4075{
4076 default_breakpoint_valid = valid;
4077 default_breakpoint_address = addr;
4078 default_breakpoint_symtab = symtab;
4079 default_breakpoint_line = line;
4080}
4081
e4f237da
KB
4082/* Return true iff it is meaningful to use the address member of
4083 BPT. For some breakpoint types, the address member is irrelevant
4084 and it makes no sense to attempt to compare it to other addresses
4085 (or use it for any other purpose either).
4086
4087 More specifically, each of the following breakpoint types will always
4088 have a zero valued address and we don't want check_duplicates() to mark
4089 breakpoints of any of these types to be a duplicate of an actual
4090 breakpoint at address zero:
4091
4092 bp_watchpoint
4093 bp_hardware_watchpoint
4094 bp_read_watchpoint
4095 bp_access_watchpoint
fe798b75 4096 bp_catchpoint */
e4f237da
KB
4097
4098static int
4099breakpoint_address_is_meaningful (struct breakpoint *bpt)
4100{
4101 enum bptype type = bpt->type;
4102
4103 return (type != bp_watchpoint
4104 && type != bp_hardware_watchpoint
4105 && type != bp_read_watchpoint
4106 && type != bp_access_watchpoint
fe798b75 4107 && type != bp_catchpoint);
e4f237da
KB
4108}
4109
9f60f21b 4110/* Rescan breakpoints at the same address and section as BPT,
c906108c 4111 marking the first one as "first" and any others as "duplicates".
c2c6d25f 4112 This is so that the bpt instruction is only inserted once.
9f60f21b
JB
4113 If we have a permanent breakpoint at the same place as BPT, make
4114 that one the official one, and the rest as duplicates. */
c906108c
SS
4115
4116static void
714835d5 4117check_duplicates_for (CORE_ADDR address, struct obj_section *section)
c906108c 4118{
075f6582 4119 struct bp_location *b;
52f0bd74 4120 int count = 0;
075f6582 4121 struct bp_location *perm_bp = 0;
c906108c 4122
075f6582
DJ
4123 ALL_BP_LOCATIONS (b)
4124 if (b->owner->enable_state != bp_disabled
075f6582 4125 && b->owner->enable_state != bp_call_disabled
0d381245
VP
4126 && b->enabled
4127 && !b->shlib_disabled
075f6582
DJ
4128 && b->address == address /* address / overlay match */
4129 && (!overlay_debugging || b->section == section)
4130 && breakpoint_address_is_meaningful (b->owner))
c5aa993b 4131 {
c2c6d25f 4132 /* Have we found a permanent breakpoint? */
075f6582 4133 if (b->owner->enable_state == bp_permanent)
c2c6d25f
JM
4134 {
4135 perm_bp = b;
4136 break;
4137 }
4138
c5aa993b 4139 count++;
075f6582 4140 b->duplicate = count > 1;
c5aa993b 4141 }
c2c6d25f
JM
4142
4143 /* If we found a permanent breakpoint at this address, go over the
aae64587
PA
4144 list again and declare all the other breakpoints there (except
4145 other permanent breakpoints) to be the duplicates. */
c2c6d25f
JM
4146 if (perm_bp)
4147 {
075f6582 4148 perm_bp->duplicate = 0;
c2c6d25f
JM
4149
4150 /* Permanent breakpoint should always be inserted. */
075f6582 4151 if (! perm_bp->inserted)
8e65ff28 4152 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
4153 _("allegedly permanent breakpoint is not "
4154 "actually inserted"));
c2c6d25f 4155
075f6582 4156 ALL_BP_LOCATIONS (b)
c2c6d25f
JM
4157 if (b != perm_bp)
4158 {
aae64587
PA
4159 if (b->owner->enable_state != bp_permanent
4160 && b->owner->enable_state != bp_disabled
075f6582 4161 && b->owner->enable_state != bp_call_disabled
0d381245 4162 && b->enabled && !b->shlib_disabled
075f6582
DJ
4163 && b->address == address /* address / overlay match */
4164 && (!overlay_debugging || b->section == section)
4165 && breakpoint_address_is_meaningful (b->owner))
4166 {
4167 if (b->inserted)
4168 internal_error (__FILE__, __LINE__,
e2e0b3e5
AC
4169 _("another breakpoint was inserted on top of "
4170 "a permanent breakpoint"));
075f6582
DJ
4171
4172 b->duplicate = 1;
4173 }
c2c6d25f
JM
4174 }
4175 }
c906108c
SS
4176}
4177
0d381245
VP
4178static void
4179check_duplicates (struct breakpoint *bpt)
4180{
4181 struct bp_location *bl = bpt->loc;
4182
4183 if (! breakpoint_address_is_meaningful (bpt))
4184 return;
4185
4186 for (; bl; bl = bl->next)
4187 check_duplicates_for (bl->address, bl->section);
4188}
4189
76897487
KB
4190static void
4191breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4192 int bnum, int have_bnum)
4193{
4194 char astr1[40];
4195 char astr2[40];
4196
bb599908
PH
4197 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4198 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
76897487 4199 if (have_bnum)
8a3fe4f8 4200 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
76897487
KB
4201 bnum, astr1, astr2);
4202 else
8a3fe4f8 4203 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
76897487
KB
4204}
4205
4206/* Adjust a breakpoint's address to account for architectural constraints
4207 on breakpoint placement. Return the adjusted address. Note: Very
4208 few targets require this kind of adjustment. For most targets,
4209 this function is simply the identity function. */
4210
4211static CORE_ADDR
88f7da05 4212adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
76897487
KB
4213{
4214 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4215 {
4216 /* Very few targets need any kind of breakpoint adjustment. */
4217 return bpaddr;
4218 }
88f7da05
KB
4219 else if (bptype == bp_watchpoint
4220 || bptype == bp_hardware_watchpoint
4221 || bptype == bp_read_watchpoint
4222 || bptype == bp_access_watchpoint
fe798b75 4223 || bptype == bp_catchpoint)
88f7da05
KB
4224 {
4225 /* Watchpoints and the various bp_catch_* eventpoints should not
4226 have their addresses modified. */
4227 return bpaddr;
4228 }
76897487
KB
4229 else
4230 {
4231 CORE_ADDR adjusted_bpaddr;
4232
4233 /* Some targets have architectural constraints on the placement
4234 of breakpoint instructions. Obtain the adjusted address. */
4235 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4236 bpaddr);
4237
4238 /* An adjusted breakpoint address can significantly alter
4239 a user's expectations. Print a warning if an adjustment
4240 is required. */
4241 if (adjusted_bpaddr != bpaddr)
4242 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4243
4244 return adjusted_bpaddr;
4245 }
4246}
4247
7cc221ef
DJ
4248/* Allocate a struct bp_location. */
4249
26bb91f3 4250static struct bp_location *
39d61571 4251allocate_bp_location (struct breakpoint *bpt)
7cc221ef
DJ
4252{
4253 struct bp_location *loc, *loc_p;
4254
4255 loc = xmalloc (sizeof (struct bp_location));
4256 memset (loc, 0, sizeof (*loc));
4257
e049a4b5 4258 loc->owner = bpt;
511a6cd4 4259 loc->cond = NULL;
0d381245
VP
4260 loc->shlib_disabled = 0;
4261 loc->enabled = 1;
e049a4b5 4262
39d61571 4263 switch (bpt->type)
e049a4b5
DJ
4264 {
4265 case bp_breakpoint:
1042e4c0 4266 case bp_tracepoint:
e049a4b5
DJ
4267 case bp_until:
4268 case bp_finish:
4269 case bp_longjmp:
4270 case bp_longjmp_resume:
4271 case bp_step_resume:
e049a4b5
DJ
4272 case bp_watchpoint_scope:
4273 case bp_call_dummy:
4274 case bp_shlib_event:
4275 case bp_thread_event:
4276 case bp_overlay_event:
e049a4b5
DJ
4277 loc->loc_type = bp_loc_software_breakpoint;
4278 break;
4279 case bp_hardware_breakpoint:
4280 loc->loc_type = bp_loc_hardware_breakpoint;
4281 break;
4282 case bp_hardware_watchpoint:
4283 case bp_read_watchpoint:
4284 case bp_access_watchpoint:
4285 loc->loc_type = bp_loc_hardware_watchpoint;
4286 break;
4287 case bp_watchpoint:
ce78b96d 4288 case bp_catchpoint:
e049a4b5
DJ
4289 loc->loc_type = bp_loc_other;
4290 break;
4291 default:
e2e0b3e5 4292 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
e049a4b5
DJ
4293 }
4294
7cc221ef
DJ
4295 return loc;
4296}
4297
fe3f5fa8
VP
4298static void free_bp_location (struct bp_location *loc)
4299{
4300 if (loc->cond)
4301 xfree (loc->cond);
74960c60
VP
4302
4303 if (loc->function_name)
4304 xfree (loc->function_name);
4305
fe3f5fa8
VP
4306 xfree (loc);
4307}
4308
0d381245
VP
4309/* Helper to set_raw_breakpoint below. Creates a breakpoint
4310 that has type BPTYPE and has no locations as yet. */
c906108c 4311
c40e75cd 4312static struct breakpoint *
0d381245 4313set_raw_breakpoint_without_location (enum bptype bptype)
c906108c 4314{
52f0bd74 4315 struct breakpoint *b, *b1;
c906108c
SS
4316
4317 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4318 memset (b, 0, sizeof (*b));
2219d63c 4319
4d28f7a8 4320 b->type = bptype;
c906108c
SS
4321 b->language = current_language->la_language;
4322 b->input_radix = input_radix;
4323 b->thread = -1;
b5de0fa7 4324 b->enable_state = bp_enabled;
c906108c
SS
4325 b->next = 0;
4326 b->silent = 0;
4327 b->ignore_count = 0;
4328 b->commands = NULL;
818dd999 4329 b->frame_id = null_frame_id;
3a3e9ee3 4330 b->forked_inferior_pid = null_ptid;
c906108c 4331 b->exec_pathname = NULL;
3086aeae 4332 b->ops = NULL;
0d381245 4333 b->condition_not_parsed = 0;
c906108c
SS
4334
4335 /* Add this breakpoint to the end of the chain
4336 so that a list of breakpoints will come out in order
4337 of increasing numbers. */
4338
4339 b1 = breakpoint_chain;
4340 if (b1 == 0)
4341 breakpoint_chain = b;
4342 else
4343 {
4344 while (b1->next)
4345 b1 = b1->next;
4346 b1->next = b;
4347 }
0d381245
VP
4348 return b;
4349}
4350
4351/* Initialize loc->function_name. */
4352static void
4353set_breakpoint_location_function (struct bp_location *loc)
4354{
4355 if (loc->owner->type == bp_breakpoint
1042e4c0
SS
4356 || loc->owner->type == bp_hardware_breakpoint
4357 || loc->owner->type == bp_tracepoint)
0d381245
VP
4358 {
4359 find_pc_partial_function (loc->address, &(loc->function_name),
4360 NULL, NULL);
4361 if (loc->function_name)
4362 loc->function_name = xstrdup (loc->function_name);
4363 }
4364}
4365
4366/* set_raw_breakpoint is a low level routine for allocating and
4367 partially initializing a breakpoint of type BPTYPE. The newly
4368 created breakpoint's address, section, source file name, and line
4369 number are provided by SAL. The newly created and partially
4370 initialized breakpoint is added to the breakpoint chain and
4371 is also returned as the value of this function.
4372
4373 It is expected that the caller will complete the initialization of
4374 the newly created breakpoint struct as well as output any status
4375 information regarding the creation of a new breakpoint. In
4376 particular, set_raw_breakpoint does NOT set the breakpoint
4377 number! Care should be taken to not allow an error to occur
4378 prior to completing the initialization of the breakpoint. If this
4379 should happen, a bogus breakpoint will be left on the chain. */
4380
4381struct breakpoint *
4382set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4383{
4384 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4385 CORE_ADDR adjusted_address;
4386
4387 /* Adjust the breakpoint's address prior to allocating a location.
4388 Once we call allocate_bp_location(), that mostly uninitialized
4389 location will be placed on the location chain. Adjustment of the
8defab1a 4390 breakpoint may cause target_read_memory() to be called and we do
0d381245
VP
4391 not want its scan of the location chain to find a breakpoint and
4392 location that's only been partially initialized. */
39d61571 4393 adjusted_address = adjust_breakpoint_address (sal.pc, b->type);
0d381245 4394
39d61571 4395 b->loc = allocate_bp_location (b);
0d381245
VP
4396 b->loc->requested_address = sal.pc;
4397 b->loc->address = adjusted_address;
4398
4399 if (sal.symtab == NULL)
4400 b->source_file = NULL;
4401 else
1b36a34b 4402 b->source_file = xstrdup (sal.symtab->filename);
0d381245
VP
4403 b->loc->section = sal.section;
4404 b->line_number = sal.line;
4405
4406 set_breakpoint_location_function (b->loc);
c906108c 4407
c906108c
SS
4408 breakpoints_changed ();
4409
4410 return b;
4411}
4412
c2c6d25f
JM
4413
4414/* Note that the breakpoint object B describes a permanent breakpoint
4415 instruction, hard-wired into the inferior's code. */
4416void
4417make_breakpoint_permanent (struct breakpoint *b)
4418{
0d381245 4419 struct bp_location *bl;
b5de0fa7 4420 b->enable_state = bp_permanent;
c2c6d25f 4421
0d381245
VP
4422 /* By definition, permanent breakpoints are already present in the code.
4423 Mark all locations as inserted. For now, make_breakpoint_permanent
4424 is called in just one place, so it's hard to say if it's reasonable
4425 to have permanent breakpoint with multiple locations or not,
4426 but it's easy to implmement. */
4427 for (bl = b->loc; bl; bl = bl->next)
4428 bl->inserted = 1;
c2c6d25f
JM
4429}
4430
c906108c 4431static void
fba45db2 4432create_longjmp_breakpoint (char *func_name)
c906108c 4433{
1900040c 4434 struct minimal_symbol *m;
c906108c 4435
059fb39f
PM
4436 m = lookup_minimal_symbol_text (func_name, NULL);
4437 if (m == NULL)
611c83ae
PA
4438 return;
4439 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
b60e7edf 4440 update_global_location_list (1);
c906108c
SS
4441}
4442
53a5351d
JM
4443/* Call this routine when stepping and nexting to enable a breakpoint
4444 if we do a longjmp(). When we hit that breakpoint, call
c906108c
SS
4445 set_longjmp_resume_breakpoint() to figure out where we are going. */
4446
4447void
611c83ae 4448set_longjmp_breakpoint (void)
c906108c 4449{
611c83ae 4450 if (gdbarch_get_longjmp_target_p (current_gdbarch))
c5aa993b 4451 {
611c83ae
PA
4452 create_longjmp_breakpoint ("longjmp");
4453 create_longjmp_breakpoint ("_longjmp");
4454 create_longjmp_breakpoint ("siglongjmp");
4455 create_longjmp_breakpoint ("_siglongjmp");
c5aa993b 4456 }
c906108c
SS
4457}
4458
611c83ae 4459/* Delete all longjmp breakpoints from THREAD. */
c906108c 4460void
611c83ae 4461delete_longjmp_breakpoint (int thread)
c906108c 4462{
611c83ae 4463 struct breakpoint *b, *temp;
c906108c 4464
611c83ae
PA
4465 ALL_BREAKPOINTS_SAFE (b, temp)
4466 if (b->type == bp_longjmp)
4467 {
4468 if (b->thread == thread)
4469 delete_breakpoint (b);
4470 }
c906108c
SS
4471}
4472
1900040c
MS
4473void
4474enable_overlay_breakpoints (void)
4475{
52f0bd74 4476 struct breakpoint *b;
1900040c
MS
4477
4478 ALL_BREAKPOINTS (b)
4479 if (b->type == bp_overlay_event)
4480 {
4481 b->enable_state = bp_enabled;
b60e7edf 4482 update_global_location_list (1);
c02f5703 4483 overlay_events_enabled = 1;
1900040c
MS
4484 }
4485}
4486
4487void
4488disable_overlay_breakpoints (void)
4489{
52f0bd74 4490 struct breakpoint *b;
1900040c
MS
4491
4492 ALL_BREAKPOINTS (b)
4493 if (b->type == bp_overlay_event)
4494 {
4495 b->enable_state = bp_disabled;
b60e7edf 4496 update_global_location_list (0);
c02f5703 4497 overlay_events_enabled = 0;
1900040c
MS
4498 }
4499}
4500
c4093a6a 4501struct breakpoint *
fba45db2 4502create_thread_event_breakpoint (CORE_ADDR address)
c4093a6a
JM
4503{
4504 struct breakpoint *b;
c4093a6a 4505
1900040c 4506 b = create_internal_breakpoint (address, bp_thread_event);
c4093a6a 4507
b5de0fa7 4508 b->enable_state = bp_enabled;
c4093a6a 4509 /* addr_string has to be used or breakpoint_re_set will delete me. */
b435e160 4510 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
c4093a6a 4511
b60e7edf 4512 update_global_location_list_nothrow (1);
74960c60 4513
c4093a6a
JM
4514 return b;
4515}
4516
4517void
4518remove_thread_event_breakpoints (void)
4519{
4520 struct breakpoint *b, *temp;
4521
4522 ALL_BREAKPOINTS_SAFE (b, temp)
4523 if (b->type == bp_thread_event)
4524 delete_breakpoint (b);
4525}
4526
0101ce28
JJ
4527struct captured_parse_breakpoint_args
4528 {
4529 char **arg_p;
4530 struct symtabs_and_lines *sals_p;
4531 char ***addr_string_p;
4532 int *not_found_ptr;
4533 };
4534
4535struct lang_and_radix
4536 {
4537 enum language lang;
4538 int radix;
4539 };
4540
0101ce28 4541
cae688ec
JJ
4542void
4543remove_solib_event_breakpoints (void)
4544{
4545 struct breakpoint *b, *temp;
4546
4547 ALL_BREAKPOINTS_SAFE (b, temp)
4548 if (b->type == bp_shlib_event)
4549 delete_breakpoint (b);
4550}
4551
4552struct breakpoint *
4553create_solib_event_breakpoint (CORE_ADDR address)
4554{
4555 struct breakpoint *b;
4556
4557 b = create_internal_breakpoint (address, bp_shlib_event);
b60e7edf 4558 update_global_location_list_nothrow (1);
cae688ec
JJ
4559 return b;
4560}
4561
4562/* Disable any breakpoints that are on code in shared libraries. Only
4563 apply to enabled breakpoints, disabled ones can just stay disabled. */
4564
4565void
cb851954 4566disable_breakpoints_in_shlibs (void)
cae688ec 4567{
0d381245 4568 struct bp_location *loc;
cae688ec 4569
0d381245 4570 ALL_BP_LOCATIONS (loc)
cae688ec 4571 {
0d381245
VP
4572 struct breakpoint *b = loc->owner;
4573 /* We apply the check to all breakpoints, including disabled
4574 for those with loc->duplicate set. This is so that when breakpoint
4575 becomes enabled, or the duplicate is removed, gdb will try to insert
4576 all breakpoints. If we don't set shlib_disabled here, we'll try
4577 to insert those breakpoints and fail. */
1042e4c0
SS
4578 if (((b->type == bp_breakpoint)
4579 || (b->type == bp_hardware_breakpoint)
4580 || (b->type == bp_tracepoint))
0d381245 4581 && !loc->shlib_disabled
a77053c2 4582#ifdef PC_SOLIB
0d381245 4583 && PC_SOLIB (loc->address)
a77053c2 4584#else
f5c9a895 4585 && solib_name_from_address (loc->address)
a77053c2
MK
4586#endif
4587 )
0d381245
VP
4588 {
4589 loc->shlib_disabled = 1;
4590 }
cae688ec
JJ
4591 }
4592}
4593
84acb35a
JJ
4594/* Disable any breakpoints that are in in an unloaded shared library. Only
4595 apply to enabled breakpoints, disabled ones can just stay disabled. */
4596
75149521 4597static void
84acb35a
JJ
4598disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4599{
0d381245 4600 struct bp_location *loc;
84acb35a
JJ
4601 int disabled_shlib_breaks = 0;
4602
c86cf029
VP
4603 /* SunOS a.out shared libraries are always mapped, so do not
4604 disable breakpoints; they will only be reported as unloaded
4605 through clear_solib when GDB discards its shared library
4606 list. See clear_solib for more information. */
4607 if (exec_bfd != NULL
4608 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
4609 return;
4610
0d381245 4611 ALL_BP_LOCATIONS (loc)
84acb35a 4612 {
0d381245
VP
4613 struct breakpoint *b = loc->owner;
4614 if ((loc->loc_type == bp_loc_hardware_breakpoint
4615 || loc->loc_type == bp_loc_software_breakpoint)
e2dd7057
PP
4616 && !loc->shlib_disabled
4617 && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint)
4618 && solib_contains_address_p (solib, loc->address))
84acb35a 4619 {
e2dd7057
PP
4620 loc->shlib_disabled = 1;
4621 /* At this point, we cannot rely on remove_breakpoint
4622 succeeding so we must mark the breakpoint as not inserted
4623 to prevent future errors occurring in remove_breakpoints. */
4624 loc->inserted = 0;
4625 if (!disabled_shlib_breaks)
4626 {
4627 target_terminal_ours_for_output ();
4628 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4629 solib->so_name);
84acb35a 4630 }
e2dd7057 4631 disabled_shlib_breaks = 1;
84acb35a
JJ
4632 }
4633 }
84acb35a
JJ
4634}
4635
ce78b96d
JB
4636/* FORK & VFORK catchpoints. */
4637
4638/* Implement the "insert" breakpoint_ops method for fork catchpoints. */
4639
c906108c 4640static void
ce78b96d
JB
4641insert_catch_fork (struct breakpoint *b)
4642{
4643 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
4644}
4645
4646/* Implement the "remove" breakpoint_ops method for fork catchpoints. */
4647
4648static int
4649remove_catch_fork (struct breakpoint *b)
4650{
4651 return target_remove_fork_catchpoint (PIDGET (inferior_ptid));
4652}
4653
4654/* Implement the "breakpoint_hit" breakpoint_ops method for fork
4655 catchpoints. */
4656
4657static int
4658breakpoint_hit_catch_fork (struct breakpoint *b)
4659{
4660 return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid);
4661}
4662
4663/* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
4664
4665static enum print_stop_action
4666print_it_catch_fork (struct breakpoint *b)
4667{
4668 annotate_catchpoint (b->number);
4669 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
4670 b->number, ptid_get_pid (b->forked_inferior_pid));
4671 return PRINT_SRC_AND_LOC;
4672}
4673
4674/* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
4675
4676static void
4677print_one_catch_fork (struct breakpoint *b, CORE_ADDR *last_addr)
4678{
79a45b7d
TT
4679 struct value_print_options opts;
4680
4681 get_user_print_options (&opts);
4682
ce78b96d
JB
4683 /* Field 4, the address, is omitted (which makes the columns
4684 not line up too nicely with the headers, but the effect
4685 is relatively readable). */
79a45b7d 4686 if (opts.addressprint)
ce78b96d
JB
4687 ui_out_field_skip (uiout, "addr");
4688 annotate_field (5);
4689 ui_out_text (uiout, "fork");
4690 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4691 {
4692 ui_out_text (uiout, ", process ");
4693 ui_out_field_int (uiout, "what",
4694 ptid_get_pid (b->forked_inferior_pid));
4695 ui_out_spaces (uiout, 1);
4696 }
4697}
4698
4699/* Implement the "print_mention" breakpoint_ops method for fork
4700 catchpoints. */
4701
4702static void
4703print_mention_catch_fork (struct breakpoint *b)
4704{
4705 printf_filtered (_("Catchpoint %d (fork)"), b->number);
4706}
4707
4708/* The breakpoint_ops structure to be used in fork catchpoints. */
4709
4710static struct breakpoint_ops catch_fork_breakpoint_ops =
4711{
4712 insert_catch_fork,
4713 remove_catch_fork,
4714 breakpoint_hit_catch_fork,
4715 print_it_catch_fork,
4716 print_one_catch_fork,
4717 print_mention_catch_fork
4718};
4719
4720/* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
4721
4722static void
4723insert_catch_vfork (struct breakpoint *b)
4724{
4725 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
4726}
4727
4728/* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
4729
4730static int
4731remove_catch_vfork (struct breakpoint *b)
4732{
4733 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
4734}
4735
4736/* Implement the "breakpoint_hit" breakpoint_ops method for vfork
4737 catchpoints. */
4738
4739static int
4740breakpoint_hit_catch_vfork (struct breakpoint *b)
4741{
4742 return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid);
4743}
4744
4745/* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
4746
4747static enum print_stop_action
4748print_it_catch_vfork (struct breakpoint *b)
4749{
4750 annotate_catchpoint (b->number);
4751 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
4752 b->number, ptid_get_pid (b->forked_inferior_pid));
4753 return PRINT_SRC_AND_LOC;
4754}
4755
4756/* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
4757
4758static void
4759print_one_catch_vfork (struct breakpoint *b, CORE_ADDR *last_addr)
4760{
79a45b7d
TT
4761 struct value_print_options opts;
4762
4763 get_user_print_options (&opts);
ce78b96d
JB
4764 /* Field 4, the address, is omitted (which makes the columns
4765 not line up too nicely with the headers, but the effect
4766 is relatively readable). */
79a45b7d 4767 if (opts.addressprint)
ce78b96d
JB
4768 ui_out_field_skip (uiout, "addr");
4769 annotate_field (5);
4770 ui_out_text (uiout, "vfork");
4771 if (!ptid_equal (b->forked_inferior_pid, null_ptid))
4772 {
4773 ui_out_text (uiout, ", process ");
4774 ui_out_field_int (uiout, "what",
4775 ptid_get_pid (b->forked_inferior_pid));
4776 ui_out_spaces (uiout, 1);
4777 }
4778}
4779
4780/* Implement the "print_mention" breakpoint_ops method for vfork
4781 catchpoints. */
4782
4783static void
4784print_mention_catch_vfork (struct breakpoint *b)
4785{
4786 printf_filtered (_("Catchpoint %d (vfork)"), b->number);
4787}
4788
4789/* The breakpoint_ops structure to be used in vfork catchpoints. */
4790
4791static struct breakpoint_ops catch_vfork_breakpoint_ops =
4792{
4793 insert_catch_vfork,
4794 remove_catch_vfork,
4795 breakpoint_hit_catch_vfork,
4796 print_it_catch_vfork,
4797 print_one_catch_vfork,
4798 print_mention_catch_vfork
4799};
4800
4801/* Create a new breakpoint of the bp_catchpoint kind and return it.
4802
4803 If TEMPFLAG is non-zero, then make the breakpoint temporary.
4804 If COND_STRING is not NULL, then store it in the breakpoint.
4805 OPS, if not NULL, is the breakpoint_ops structure associated
4806 to the catchpoint. */
4807
4808static struct breakpoint *
4809create_catchpoint (int tempflag, char *cond_string,
4810 struct breakpoint_ops *ops)
c906108c 4811{
c5aa993b
JM
4812 struct symtab_and_line sal;
4813 struct breakpoint *b;
c5aa993b 4814
fe39c653 4815 init_sal (&sal);
c906108c
SS
4816 sal.pc = 0;
4817 sal.symtab = NULL;
4818 sal.line = 0;
c5aa993b 4819
ce78b96d 4820 b = set_raw_breakpoint (sal, bp_catchpoint);
c906108c
SS
4821 set_breakpoint_count (breakpoint_count + 1);
4822 b->number = breakpoint_count;
ce78b96d 4823
1b36a34b 4824 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
ce78b96d 4825 b->thread = -1;
c906108c 4826 b->addr_string = NULL;
b5de0fa7
EZ
4827 b->enable_state = bp_enabled;
4828 b->disposition = tempflag ? disp_del : disp_donttouch;
ce78b96d 4829 b->ops = ops;
c5aa993b 4830
c906108c 4831 mention (b);
ce78b96d 4832 update_global_location_list (1);
c906108c 4833
ce78b96d 4834 return b;
c906108c 4835}
c5aa993b 4836
9b70b993 4837static void
ce78b96d
JB
4838create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4839 struct breakpoint_ops *ops)
c906108c 4840{
ce78b96d
JB
4841 struct breakpoint *b = create_catchpoint (tempflag, cond_string, ops);
4842
4843 /* FIXME: We should put this information in a breakpoint private data
4844 area. */
4845 b->forked_inferior_pid = null_ptid;
c906108c
SS
4846}
4847
fe798b75
JB
4848/* Exec catchpoints. */
4849
9b70b993 4850static void
fe798b75 4851insert_catch_exec (struct breakpoint *b)
c906108c 4852{
fe798b75
JB
4853 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
4854}
c906108c 4855
fe798b75
JB
4856static int
4857remove_catch_exec (struct breakpoint *b)
4858{
4859 return target_remove_exec_catchpoint (PIDGET (inferior_ptid));
4860}
c906108c 4861
fe798b75
JB
4862static int
4863breakpoint_hit_catch_exec (struct breakpoint *b)
4864{
4865 return inferior_has_execd (inferior_ptid, &b->exec_pathname);
4866}
c906108c 4867
fe798b75
JB
4868static enum print_stop_action
4869print_it_catch_exec (struct breakpoint *b)
4870{
4871 annotate_catchpoint (b->number);
4872 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
4873 b->exec_pathname);
4874 return PRINT_SRC_AND_LOC;
c906108c
SS
4875}
4876
fe798b75
JB
4877static void
4878print_one_catch_exec (struct breakpoint *b, CORE_ADDR *last_addr)
4879{
4880 struct value_print_options opts;
4881
4882 get_user_print_options (&opts);
4883
4884 /* Field 4, the address, is omitted (which makes the columns
4885 not line up too nicely with the headers, but the effect
4886 is relatively readable). */
4887 if (opts.addressprint)
4888 ui_out_field_skip (uiout, "addr");
4889 annotate_field (5);
4890 ui_out_text (uiout, "exec");
4891 if (b->exec_pathname != NULL)
4892 {
4893 ui_out_text (uiout, ", program \"");
4894 ui_out_field_string (uiout, "what", b->exec_pathname);
4895 ui_out_text (uiout, "\" ");
4896 }
4897}
4898
4899static void
4900print_mention_catch_exec (struct breakpoint *b)
4901{
4902 printf_filtered (_("Catchpoint %d (exec)"), b->number);
4903}
4904
4905static struct breakpoint_ops catch_exec_breakpoint_ops =
4906{
4907 insert_catch_exec,
4908 remove_catch_exec,
4909 breakpoint_hit_catch_exec,
4910 print_it_catch_exec,
4911 print_one_catch_exec,
4912 print_mention_catch_exec
4913};
4914
c906108c 4915static int
fba45db2 4916hw_breakpoint_used_count (void)
c906108c 4917{
52f0bd74 4918 struct breakpoint *b;
c906108c
SS
4919 int i = 0;
4920
4921 ALL_BREAKPOINTS (b)
c5aa993b 4922 {
d6b74ac4 4923 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b))
c5aa993b
JM
4924 i++;
4925 }
c906108c
SS
4926
4927 return i;
4928}
4929
4930static int
fba45db2 4931hw_watchpoint_used_count (enum bptype type, int *other_type_used)
c906108c 4932{
52f0bd74 4933 struct breakpoint *b;
c906108c
SS
4934 int i = 0;
4935
4936 *other_type_used = 0;
4937 ALL_BREAKPOINTS (b)
c5aa993b 4938 {
468d015d 4939 if (breakpoint_enabled (b))
c5aa993b
JM
4940 {
4941 if (b->type == type)
4942 i++;
059fb39f
PM
4943 else if ((b->type == bp_hardware_watchpoint
4944 || b->type == bp_read_watchpoint
4945 || b->type == bp_access_watchpoint))
c5aa993b
JM
4946 *other_type_used = 1;
4947 }
4948 }
c906108c
SS
4949 return i;
4950}
4951
c906108c 4952void
fba45db2 4953disable_watchpoints_before_interactive_call_start (void)
c906108c 4954{
c5aa993b 4955 struct breakpoint *b;
c906108c
SS
4956
4957 ALL_BREAKPOINTS (b)
c5aa993b
JM
4958 {
4959 if (((b->type == bp_watchpoint)
4960 || (b->type == bp_hardware_watchpoint)
4961 || (b->type == bp_read_watchpoint)
dfdfb3ca 4962 || (b->type == bp_access_watchpoint))
468d015d 4963 && breakpoint_enabled (b))
c5aa993b 4964 {
b5de0fa7 4965 b->enable_state = bp_call_disabled;
b60e7edf 4966 update_global_location_list (0);
c5aa993b
JM
4967 }
4968 }
c906108c
SS
4969}
4970
4971void
fba45db2 4972enable_watchpoints_after_interactive_call_stop (void)
c906108c 4973{
c5aa993b 4974 struct breakpoint *b;
c906108c
SS
4975
4976 ALL_BREAKPOINTS (b)
c5aa993b
JM
4977 {
4978 if (((b->type == bp_watchpoint)
4979 || (b->type == bp_hardware_watchpoint)
4980 || (b->type == bp_read_watchpoint)
dfdfb3ca 4981 || (b->type == bp_access_watchpoint))
b5de0fa7 4982 && (b->enable_state == bp_call_disabled))
c5aa993b 4983 {
b5de0fa7 4984 b->enable_state = bp_enabled;
b60e7edf 4985 update_global_location_list (1);
c5aa993b
JM
4986 }
4987 }
c906108c
SS
4988}
4989
4990
4991/* Set a breakpoint that will evaporate an end of command
4992 at address specified by SAL.
4993 Restrict it to frame FRAME if FRAME is nonzero. */
4994
4995struct breakpoint *
818dd999 4996set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
fba45db2 4997 enum bptype type)
c906108c 4998{
52f0bd74 4999 struct breakpoint *b;
4d28f7a8 5000 b = set_raw_breakpoint (sal, type);
b5de0fa7
EZ
5001 b->enable_state = bp_enabled;
5002 b->disposition = disp_donttouch;
818dd999 5003 b->frame_id = frame_id;
c906108c
SS
5004
5005 /* If we're debugging a multi-threaded program, then we
5006 want momentary breakpoints to be active in only a
5007 single thread of control. */
39f77062
KB
5008 if (in_thread_list (inferior_ptid))
5009 b->thread = pid_to_thread_id (inferior_ptid);
c906108c 5010
b60e7edf 5011 update_global_location_list_nothrow (1);
74960c60 5012
c906108c
SS
5013 return b;
5014}
611c83ae 5015
e58b0e63
PA
5016/* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
5017 ORIG is NULL. */
5018
5019struct breakpoint *
5020clone_momentary_breakpoint (struct breakpoint *orig)
5021{
5022 struct breakpoint *copy;
5023
5024 /* If there's nothing to clone, then return nothing. */
5025 if (orig == NULL)
5026 return NULL;
5027
5028 copy = set_raw_breakpoint_without_location (orig->type);
5029 copy->loc = allocate_bp_location (copy);
5030 set_breakpoint_location_function (copy->loc);
5031
5032 copy->loc->requested_address = orig->loc->requested_address;
5033 copy->loc->address = orig->loc->address;
5034 copy->loc->section = orig->loc->section;
5035
5036 if (orig->source_file == NULL)
5037 copy->source_file = NULL;
5038 else
5039 copy->source_file = xstrdup (orig->source_file);
5040
5041 copy->line_number = orig->line_number;
5042 copy->frame_id = orig->frame_id;
5043 copy->thread = orig->thread;
5044
5045 copy->enable_state = bp_enabled;
5046 copy->disposition = disp_donttouch;
5047 copy->number = internal_breakpoint_number--;
5048
5049 update_global_location_list_nothrow (0);
5050 return copy;
5051}
5052
611c83ae
PA
5053struct breakpoint *
5054set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type)
5055{
5056 struct symtab_and_line sal;
5057
5058 sal = find_pc_line (pc, 0);
5059 sal.pc = pc;
5060 sal.section = find_pc_overlay (pc);
5061 sal.explicit_pc = 1;
5062
5063 return set_momentary_breakpoint (sal, null_frame_id, type);
5064}
c906108c 5065\f
c5aa993b 5066
c906108c
SS
5067/* Tell the user we have just set a breakpoint B. */
5068
5069static void
fba45db2 5070mention (struct breakpoint *b)
c906108c
SS
5071{
5072 int say_where = 0;
fa8a61dc 5073 struct cleanup *ui_out_chain;
79a45b7d
TT
5074 struct value_print_options opts;
5075
5076 get_user_print_options (&opts);
8b93c638 5077
9a4105ab
AC
5078 /* FIXME: This is misplaced; mention() is called by things (like
5079 hitting a watchpoint) other than breakpoint creation. It should
5080 be possible to clean this up and at the same time replace the
7f4b89d1 5081 random calls to breakpoint_changed with this hook. */
383f836e 5082 observer_notify_breakpoint_created (b->number);
c906108c 5083
3086aeae
DJ
5084 if (b->ops != NULL && b->ops->print_mention != NULL)
5085 b->ops->print_mention (b);
5086 else
5087 switch (b->type)
5088 {
5089 case bp_none:
a3f17187 5090 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
3086aeae
DJ
5091 break;
5092 case bp_watchpoint:
5093 ui_out_text (uiout, "Watchpoint ");
5094 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5095 ui_out_field_int (uiout, "number", b->number);
5096 ui_out_text (uiout, ": ");
fa8a61dc 5097 ui_out_field_string (uiout, "exp", b->exp_string);
3086aeae
DJ
5098 do_cleanups (ui_out_chain);
5099 break;
5100 case bp_hardware_watchpoint:
5101 ui_out_text (uiout, "Hardware watchpoint ");
5102 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
5103 ui_out_field_int (uiout, "number", b->number);
5104 ui_out_text (uiout, ": ");
fa8a61dc 5105 ui_out_field_string (uiout, "exp", b->exp_string);
3086aeae
DJ
5106 do_cleanups (ui_out_chain);
5107 break;
5108 case bp_read_watchpoint:
5109 ui_out_text (uiout, "Hardware read watchpoint ");
5110 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
5111 ui_out_field_int (uiout, "number", b->number);
5112 ui_out_text (uiout, ": ");
fa8a61dc 5113 ui_out_field_string (uiout, "exp", b->exp_string);
3086aeae
DJ
5114 do_cleanups (ui_out_chain);
5115 break;
5116 case bp_access_watchpoint:
5117 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
5118 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
5119 ui_out_field_int (uiout, "number", b->number);
5120 ui_out_text (uiout, ": ");
fa8a61dc 5121 ui_out_field_string (uiout, "exp", b->exp_string);
3086aeae
DJ
5122 do_cleanups (ui_out_chain);
5123 break;
5124 case bp_breakpoint:
5125 if (ui_out_is_mi_like_p (uiout))
5126 {
5127 say_where = 0;
5128 break;
5129 }
2cec12e5
AR
5130 if (b->disposition == disp_del)
5131 printf_filtered (_("Temporary breakpoint"));
5132 else
5133 printf_filtered (_("Breakpoint"));
5134 printf_filtered (_(" %d"), b->number);
3086aeae
DJ
5135 say_where = 1;
5136 break;
5137 case bp_hardware_breakpoint:
5138 if (ui_out_is_mi_like_p (uiout))
5139 {
5140 say_where = 0;
5141 break;
5142 }
a3f17187 5143 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
3086aeae
DJ
5144 say_where = 1;
5145 break;
1042e4c0
SS
5146 case bp_tracepoint:
5147 if (ui_out_is_mi_like_p (uiout))
5148 {
5149 say_where = 0;
5150 break;
5151 }
5152 printf_filtered (_("Tracepoint"));
5153 printf_filtered (_(" %d"), b->number);
5154 say_where = 1;
5155 break;
3086aeae
DJ
5156
5157 case bp_until:
5158 case bp_finish:
5159 case bp_longjmp:
5160 case bp_longjmp_resume:
5161 case bp_step_resume:
3086aeae
DJ
5162 case bp_call_dummy:
5163 case bp_watchpoint_scope:
5164 case bp_shlib_event:
5165 case bp_thread_event:
5166 case bp_overlay_event:
5167 break;
5168 }
c906108c 5169
c906108c
SS
5170 if (say_where)
5171 {
a3f17187
AC
5172 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5173 single string. */
0d381245 5174 if (b->loc == NULL)
c906108c 5175 {
a3f17187 5176 printf_filtered (_(" (%s) pending."), b->addr_string);
0101ce28
JJ
5177 }
5178 else
5179 {
79a45b7d 5180 if (opts.addressprint || b->source_file == NULL)
0101ce28
JJ
5181 {
5182 printf_filtered (" at ");
ed49a04f 5183 fputs_filtered (paddress (b->loc->address), gdb_stdout);
0101ce28
JJ
5184 }
5185 if (b->source_file)
5186 printf_filtered (": file %s, line %d.",
5187 b->source_file, b->line_number);
0d381245
VP
5188
5189 if (b->loc->next)
5190 {
5191 struct bp_location *loc = b->loc;
5192 int n = 0;
5193 for (; loc; loc = loc->next)
5194 ++n;
5195 printf_filtered (" (%d locations)", n);
5196 }
5197
c906108c 5198 }
c906108c 5199 }
9dc5e2a9 5200 if (ui_out_is_mi_like_p (uiout))
fb40c209 5201 return;
c906108c
SS
5202 printf_filtered ("\n");
5203}
c906108c 5204\f
c5aa993b 5205
0d381245 5206static struct bp_location *
39d61571 5207add_location_to_breakpoint (struct breakpoint *b,
0d381245
VP
5208 const struct symtab_and_line *sal)
5209{
5210 struct bp_location *loc, **tmp;
5211
39d61571 5212 loc = allocate_bp_location (b);
0d381245
VP
5213 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5214 ;
5215 *tmp = loc;
5216 loc->requested_address = sal->pc;
39d61571 5217 loc->address = adjust_breakpoint_address (loc->requested_address, b->type);
0d381245
VP
5218 loc->section = sal->section;
5219
5220 set_breakpoint_location_function (loc);
5221 return loc;
5222}
514f746b
AR
5223\f
5224
5225/* Return 1 if LOC is pointing to a permanent breakpoint,
5226 return 0 otherwise. */
5227
5228static int
5229bp_loc_is_permanent (struct bp_location *loc)
5230{
5231 int len;
5232 CORE_ADDR addr;
5233 const gdb_byte *brk;
5234 gdb_byte *target_mem;
939c61fa
JK
5235 struct cleanup *cleanup;
5236 int retval = 0;
514f746b
AR
5237
5238 gdb_assert (loc != NULL);
5239
5240 addr = loc->address;
5241 brk = gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &len);
5242
939c61fa
JK
5243 /* Software breakpoints unsupported? */
5244 if (brk == NULL)
5245 return 0;
5246
514f746b
AR
5247 target_mem = alloca (len);
5248
939c61fa
JK
5249 /* Enable the automatic memory restoration from breakpoints while
5250 we read the memory. Otherwise we could say about our temporary
5251 breakpoints they are permanent. */
5252 cleanup = make_show_memory_breakpoints_cleanup (0);
5253
514f746b
AR
5254 if (target_read_memory (loc->address, target_mem, len) == 0
5255 && memcmp (target_mem, brk, len) == 0)
939c61fa 5256 retval = 1;
514f746b 5257
939c61fa
JK
5258 do_cleanups (cleanup);
5259
5260 return retval;
514f746b
AR
5261}
5262
5263
c3f6f71d 5264
018d34a4
VP
5265/* Create a breakpoint with SAL as location. Use ADDR_STRING
5266 as textual description of the location, and COND_STRING
db107f19 5267 as condition expression. */
018d34a4
VP
5268
5269static void
0d381245 5270create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
018d34a4
VP
5271 char *cond_string,
5272 enum bptype type, enum bpdisp disposition,
4a306c9a 5273 int thread, int task, int ignore_count,
41447f92 5274 struct breakpoint_ops *ops, int from_tty, int enabled)
018d34a4 5275{
0d381245
VP
5276 struct breakpoint *b = NULL;
5277 int i;
018d34a4
VP
5278
5279 if (type == bp_hardware_breakpoint)
5280 {
5281 int i = hw_breakpoint_used_count ();
5282 int target_resources_ok =
d92524f1 5283 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
018d34a4
VP
5284 i + 1, 0);
5285 if (target_resources_ok == 0)
5286 error (_("No hardware breakpoint support in the target."));
5287 else if (target_resources_ok < 0)
5288 error (_("Hardware breakpoints used exceeds limit."));
5289 }
5290
0d381245
VP
5291 for (i = 0; i < sals.nelts; ++i)
5292 {
5293 struct symtab_and_line sal = sals.sals[i];
5294 struct bp_location *loc;
5295
5296 if (from_tty)
5297 describe_other_breakpoints (sal.pc, sal.section, thread);
5298
5299 if (i == 0)
5300 {
5301 b = set_raw_breakpoint (sal, type);
5302 set_breakpoint_count (breakpoint_count + 1);
5303 b->number = breakpoint_count;
5304 b->thread = thread;
4a306c9a 5305 b->task = task;
018d34a4 5306
0d381245
VP
5307 b->cond_string = cond_string;
5308 b->ignore_count = ignore_count;
41447f92 5309 b->enable_state = enabled ? bp_enabled : bp_disabled;
0d381245 5310 b->disposition = disposition;
018d34a4 5311
0d381245
VP
5312 loc = b->loc;
5313 }
5314 else
018d34a4 5315 {
39d61571 5316 loc = add_location_to_breakpoint (b, &sal);
0d381245
VP
5317 }
5318
514f746b
AR
5319 if (bp_loc_is_permanent (loc))
5320 make_breakpoint_permanent (b);
5321
0d381245
VP
5322 if (b->cond_string)
5323 {
5324 char *arg = b->cond_string;
d32a6982 5325 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
0d381245 5326 if (*arg)
db107f19 5327 error (_("Garbage %s follows condition"), arg);
018d34a4 5328 }
0d381245 5329 }
018d34a4
VP
5330
5331 if (addr_string)
5332 b->addr_string = addr_string;
5333 else
5334 /* addr_string has to be used or breakpoint_re_set will delete
5335 me. */
5336 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5337
604133b5 5338 b->ops = ops;
018d34a4
VP
5339 mention (b);
5340}
5341
ed0616c6
VP
5342/* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5343 elements to fill the void space. */
2c0b251b
PA
5344static void
5345remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
ed0616c6
VP
5346{
5347 int i = index_to_remove+1;
5348 int last_index = sal->nelts-1;
5349
5350 for (;i <= last_index; ++i)
5351 sal->sals[i-1] = sal->sals[i];
5352
5353 --(sal->nelts);
5354}
5355
5356/* If appropriate, obtains all sals that correspond
5357 to the same file and line as SAL. This is done
5358 only if SAL does not have explicit PC and has
5359 line and file information. If we got just a single
5360 expanded sal, return the original.
5361
5362 Otherwise, if SAL.explicit_line is not set, filter out
5363 all sals for which the name of enclosing function
5364 is different from SAL. This makes sure that if we have
5365 breakpoint originally set in template instantiation, say
5366 foo<int>(), we won't expand SAL to locations at the same
5367 line in all existing instantiations of 'foo'.
5368
5369*/
2c0b251b 5370static struct symtabs_and_lines
ed0616c6
VP
5371expand_line_sal_maybe (struct symtab_and_line sal)
5372{
5373 struct symtabs_and_lines expanded;
5374 CORE_ADDR original_pc = sal.pc;
5375 char *original_function = NULL;
5376 int found;
5377 int i;
5378
5379 /* If we have explicit pc, don't expand.
5380 If we have no line number, we can't expand. */
5381 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5382 {
5383 expanded.nelts = 1;
5384 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5385 expanded.sals[0] = sal;
5386 return expanded;
5387 }
5388
5389 sal.pc = 0;
5390 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5391
5392 expanded = expand_line_sal (sal);
5393 if (expanded.nelts == 1)
5394 {
5395 /* We had one sal, we got one sal. Without futher
5396 processing, just return the original sal. */
5397 xfree (expanded.sals);
5398 expanded.nelts = 1;
5399 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5400 sal.pc = original_pc;
5401 expanded.sals[0] = sal;
5402 return expanded;
5403 }
5404
5405 if (!sal.explicit_line)
5406 {
5407 CORE_ADDR func_addr, func_end;
5408 for (i = 0; i < expanded.nelts; ++i)
5409 {
5410 CORE_ADDR pc = expanded.sals[i].pc;
5411 char *this_function;
5412 if (find_pc_partial_function (pc, &this_function,
5413 &func_addr, &func_end))
5414 {
059fb39f
PM
5415 if (this_function
5416 && strcmp (this_function, original_function) != 0)
ed0616c6
VP
5417 {
5418 remove_sal (&expanded, i);
5419 --i;
5420 }
5421 else if (func_addr == pc)
5422 {
5423 /* We're at beginning of a function, and should
5424 skip prologue. */
5425 struct symbol *sym = find_pc_function (pc);
5426 if (sym)
5427 expanded.sals[i] = find_function_start_sal (sym, 1);
5428 else
d80b854b
UW
5429 {
5430 /* Since find_pc_partial_function returned true,
5431 we should really always find the section here. */
5432 struct obj_section *section = find_pc_section (pc);
5433 if (section)
5434 {
5435 struct gdbarch *gdbarch
5436 = get_objfile_arch (section->objfile);
5437 expanded.sals[i].pc
5438 = gdbarch_skip_prologue (gdbarch, pc);
5439 }
5440 }
ed0616c6
VP
5441 }
5442 }
5443 }
5444 }
3daf8fe5
JG
5445 else
5446 {
5447 for (i = 0; i < expanded.nelts; ++i)
5448 {
5449 /* If this SAL corresponds to a breakpoint inserted using a
5450 line number, then skip the function prologue if necessary. */
5451 skip_prologue_sal (&expanded.sals[i]);
5452 }
5453 }
ed0616c6
VP
5454
5455
5456 if (expanded.nelts <= 1)
5457 {
5458 /* This is un ugly workaround. If we get zero
5459 expanded sals then something is really wrong.
5460 Fix that by returnign the original sal. */
5461 xfree (expanded.sals);
5462 expanded.nelts = 1;
5463 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5464 sal.pc = original_pc;
5465 expanded.sals[0] = sal;
5466 return expanded;
5467 }
5468
5469 if (original_pc)
5470 {
5471 found = 0;
5472 for (i = 0; i < expanded.nelts; ++i)
5473 if (expanded.sals[i].pc == original_pc)
5474 {
5475 found = 1;
5476 break;
5477 }
5478 gdb_assert (found);
5479 }
5480
5481 return expanded;
5482}
5483
018d34a4
VP
5484/* Add SALS.nelts breakpoints to the breakpoint table. For each
5485 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5486 value. COND_STRING, if not NULL, specified the condition to be
5487 used for all breakpoints. Essentially the only case where
5488 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5489 function. In that case, it's still not possible to specify
5490 separate conditions for different overloaded functions, so
5491 we take just a single condition string.
5492
c3f6f71d 5493 NOTE: If the function succeeds, the caller is expected to cleanup
018d34a4 5494 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
c3f6f71d
JM
5495 array contents). If the function fails (error() is called), the
5496 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5497 COND and SALS arrays and each of those arrays contents. */
c906108c
SS
5498
5499static void
c3f6f71d 5500create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
018d34a4 5501 char *cond_string,
c3f6f71d 5502 enum bptype type, enum bpdisp disposition,
4a306c9a 5503 int thread, int task, int ignore_count,
41447f92
VP
5504 struct breakpoint_ops *ops, int from_tty,
5505 int enabled)
c906108c 5506{
018d34a4
VP
5507 int i;
5508 for (i = 0; i < sals.nelts; ++i)
c3f6f71d 5509 {
ed0616c6
VP
5510 struct symtabs_and_lines expanded =
5511 expand_line_sal_maybe (sals.sals[i]);
0d381245 5512
ed0616c6 5513 create_breakpoint (expanded, addr_string[i],
018d34a4 5514 cond_string, type, disposition,
4a306c9a 5515 thread, task, ignore_count, ops, from_tty, enabled);
c3f6f71d 5516 }
c3f6f71d 5517}
c906108c 5518
c3f6f71d
JM
5519/* Parse ARG which is assumed to be a SAL specification possibly
5520 followed by conditionals. On return, SALS contains an array of SAL
5521 addresses found. ADDR_STRING contains a vector of (canonical)
5522 address strings. ARG points to the end of the SAL. */
c906108c 5523
b9362cc7 5524static void
c3f6f71d
JM
5525parse_breakpoint_sals (char **address,
5526 struct symtabs_and_lines *sals,
0101ce28
JJ
5527 char ***addr_string,
5528 int *not_found_ptr)
c3f6f71d
JM
5529{
5530 char *addr_start = *address;
5531 *addr_string = NULL;
5532 /* If no arg given, or if first arg is 'if ', use the default
5533 breakpoint. */
5534 if ((*address) == NULL
5535 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
c906108c
SS
5536 {
5537 if (default_breakpoint_valid)
5538 {
c3f6f71d 5539 struct symtab_and_line sal;
fe39c653 5540 init_sal (&sal); /* initialize to zeroes */
c3f6f71d 5541 sals->sals = (struct symtab_and_line *)
c906108c
SS
5542 xmalloc (sizeof (struct symtab_and_line));
5543 sal.pc = default_breakpoint_address;
5544 sal.line = default_breakpoint_line;
5545 sal.symtab = default_breakpoint_symtab;
c5aa993b 5546 sal.section = find_pc_overlay (sal.pc);
00903456
JK
5547
5548 /* "break" without arguments is equivalent to "break *PC" where PC is
5549 the default_breakpoint_address. So make sure to set
5550 sal.explicit_pc to prevent GDB from trying to expand the list of
5551 sals to include all other instances with the same symtab and line.
5552 */
5553 sal.explicit_pc = 1;
5554
c3f6f71d
JM
5555 sals->sals[0] = sal;
5556 sals->nelts = 1;
c906108c
SS
5557 }
5558 else
8a3fe4f8 5559 error (_("No default breakpoint address now."));
c906108c
SS
5560 }
5561 else
5562 {
c906108c 5563 /* Force almost all breakpoints to be in terms of the
c5aa993b
JM
5564 current_source_symtab (which is decode_line_1's default). This
5565 should produce the results we want almost all of the time while
1aeae86e
AF
5566 leaving default_breakpoint_* alone.
5567 ObjC: However, don't match an Objective-C method name which
5568 may have a '+' or '-' succeeded by a '[' */
0378c332 5569
c214a6fd 5570 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
0378c332 5571
c906108c 5572 if (default_breakpoint_valid
0378c332 5573 && (!cursal.symtab
1aeae86e
AF
5574 || ((strchr ("+-", (*address)[0]) != NULL)
5575 && ((*address)[1] != '['))))
c3f6f71d 5576 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
0101ce28
JJ
5577 default_breakpoint_line, addr_string,
5578 not_found_ptr);
c906108c 5579 else
0101ce28
JJ
5580 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5581 addr_string, not_found_ptr);
c906108c 5582 }
c3f6f71d
JM
5583 /* For any SAL that didn't have a canonical string, fill one in. */
5584 if (sals->nelts > 0 && *addr_string == NULL)
5585 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5586 if (addr_start != (*address))
c906108c 5587 {
c3f6f71d
JM
5588 int i;
5589 for (i = 0; i < sals->nelts; i++)
c906108c 5590 {
c3f6f71d
JM
5591 /* Add the string if not present. */
5592 if ((*addr_string)[i] == NULL)
5593 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
c906108c
SS
5594 }
5595 }
c3f6f71d 5596}
c906108c 5597
c906108c 5598
c3f6f71d
JM
5599/* Convert each SAL into a real PC. Verify that the PC can be
5600 inserted as a breakpoint. If it can't throw an error. */
c906108c 5601
b9362cc7 5602static void
c3f6f71d
JM
5603breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5604 char *address)
5605{
5606 int i;
5607 for (i = 0; i < sals->nelts; i++)
ee53e872 5608 resolve_sal_pc (&sals->sals[i]);
c3f6f71d
JM
5609}
5610
05ff989b 5611static void
0101ce28
JJ
5612do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5613{
5614 struct captured_parse_breakpoint_args *args = data;
5615
5616 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5617 args->not_found_ptr);
0101ce28
JJ
5618}
5619
018d34a4
VP
5620/* Given TOK, a string specification of condition and thread, as
5621 accepted by the 'break' command, extract the condition
5622 string and thread number and set *COND_STRING and *THREAD.
5623 PC identifies the context at which the condition should be parsed.
5624 If no condition is found, *COND_STRING is set to NULL.
5625 If no thread is found, *THREAD is set to -1. */
5626static void
5627find_condition_and_thread (char *tok, CORE_ADDR pc,
4a306c9a 5628 char **cond_string, int *thread, int *task)
018d34a4
VP
5629{
5630 *cond_string = NULL;
5631 *thread = -1;
5632 while (tok && *tok)
5633 {
5634 char *end_tok;
5635 int toklen;
5636 char *cond_start = NULL;
5637 char *cond_end = NULL;
5638 while (*tok == ' ' || *tok == '\t')
5639 tok++;
5640
5641 end_tok = tok;
5642
5643 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5644 end_tok++;
5645
5646 toklen = end_tok - tok;
5647
5648 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5649 {
f7545552
TT
5650 struct expression *expr;
5651
018d34a4 5652 tok = cond_start = end_tok + 1;
f7545552
TT
5653 expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
5654 xfree (expr);
018d34a4
VP
5655 cond_end = tok;
5656 *cond_string = savestring (cond_start,
5657 cond_end - cond_start);
5658 }
5659 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5660 {
5661 char *tmptok;
5662
5663 tok = end_tok + 1;
5664 tmptok = tok;
5665 *thread = strtol (tok, &tok, 0);
5666 if (tok == tmptok)
5667 error (_("Junk after thread keyword."));
5668 if (!valid_thread_id (*thread))
5669 error (_("Unknown thread %d."), *thread);
5670 }
4a306c9a
JB
5671 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
5672 {
5673 char *tmptok;
5674
5675 tok = end_tok + 1;
5676 tmptok = tok;
5677 *task = strtol (tok, &tok, 0);
5678 if (tok == tmptok)
5679 error (_("Junk after task keyword."));
5680 if (!valid_task_id (*task))
5681 error (_("Unknown task %d\n"), *task);
5682 }
018d34a4
VP
5683 else
5684 error (_("Junk at end of arguments."));
5685 }
5686}
5687
72b2ff0e
VP
5688/* Set a breakpoint. This function is shared between
5689 CLI and MI functions for setting a breakpoint.
5690 This function has two major modes of operations,
5691 selected by the PARSE_CONDITION_AND_THREAD parameter.
5692 If non-zero, the function will parse arg, extracting
5693 breakpoint location, address and thread. Otherwise,
5694 ARG is just the location of breakpoint, with condition
5695 and thread specified by the COND_STRING and THREAD
5696 parameters. */
0101ce28 5697
98deb0da 5698static void
72b2ff0e 5699break_command_really (char *arg, char *cond_string, int thread,
60c46647 5700 int parse_condition_and_thread,
1042e4c0 5701 int tempflag, int hardwareflag, int traceflag,
60c46647
VP
5702 int ignore_count,
5703 enum auto_boolean pending_break_support,
604133b5 5704 struct breakpoint_ops *ops,
41447f92
VP
5705 int from_tty,
5706 int enabled)
c3f6f71d 5707{
71fff37b 5708 struct gdb_exception e;
c3f6f71d 5709 struct symtabs_and_lines sals;
0101ce28 5710 struct symtab_and_line pending_sal;
0101ce28
JJ
5711 char *copy_arg;
5712 char *err_msg;
c3f6f71d
JM
5713 char *addr_start = arg;
5714 char **addr_string;
5715 struct cleanup *old_chain;
80c99de1 5716 struct cleanup *bkpt_chain = NULL;
0101ce28 5717 struct captured_parse_breakpoint_args parse_args;
05ff989b 5718 int i;
0101ce28 5719 int pending = 0;
0101ce28 5720 int not_found = 0;
1042e4c0 5721 enum bptype type_wanted;
4a306c9a 5722 int task = 0;
c3f6f71d 5723
c3f6f71d
JM
5724 sals.sals = NULL;
5725 sals.nelts = 0;
5726 addr_string = NULL;
c3f6f71d 5727
0101ce28
JJ
5728 parse_args.arg_p = &arg;
5729 parse_args.sals_p = &sals;
5730 parse_args.addr_string_p = &addr_string;
5731 parse_args.not_found_ptr = &not_found;
5732
05ff989b
AC
5733 e = catch_exception (uiout, do_captured_parse_breakpoint,
5734 &parse_args, RETURN_MASK_ALL);
0101ce28
JJ
5735
5736 /* If caller is interested in rc value from parse, set value. */
05ff989b 5737 switch (e.reason)
0101ce28 5738 {
05ff989b 5739 case RETURN_QUIT:
98deb0da 5740 throw_exception (e);
05ff989b
AC
5741 case RETURN_ERROR:
5742 switch (e.error)
0101ce28 5743 {
05ff989b 5744 case NOT_FOUND_ERROR:
0101ce28 5745
05ff989b
AC
5746 /* If pending breakpoint support is turned off, throw
5747 error. */
fa8d40ab
JJ
5748
5749 if (pending_break_support == AUTO_BOOLEAN_FALSE)
723a2275
VP
5750 throw_exception (e);
5751
5752 exception_print (gdb_stderr, e);
fa8d40ab 5753
05ff989b
AC
5754 /* If pending breakpoint support is auto query and the user
5755 selects no, then simply return the error code. */
059fb39f
PM
5756 if (pending_break_support == AUTO_BOOLEAN_AUTO
5757 && !nquery ("Make breakpoint pending on future shared library load? "))
98deb0da 5758 return;
fa8d40ab 5759
05ff989b
AC
5760 /* At this point, either the user was queried about setting
5761 a pending breakpoint and selected yes, or pending
5762 breakpoint behavior is on and thus a pending breakpoint
5763 is defaulted on behalf of the user. */
0101ce28
JJ
5764 copy_arg = xstrdup (addr_start);
5765 addr_string = &copy_arg;
5766 sals.nelts = 1;
5767 sals.sals = &pending_sal;
5768 pending_sal.pc = 0;
5769 pending = 1;
05ff989b
AC
5770 break;
5771 default:
98deb0da 5772 throw_exception (e);
0101ce28 5773 }
05ff989b
AC
5774 default:
5775 if (!sals.nelts)
98deb0da 5776 return;
0101ce28 5777 }
c3f6f71d
JM
5778
5779 /* Create a chain of things that always need to be cleaned up. */
5780 old_chain = make_cleanup (null_cleanup, 0);
5781
0101ce28
JJ
5782 if (!pending)
5783 {
5784 /* Make sure that all storage allocated to SALS gets freed. */
5785 make_cleanup (xfree, sals.sals);
5786
5787 /* Cleanup the addr_string array but not its contents. */
5788 make_cleanup (xfree, addr_string);
5789 }
c3f6f71d 5790
c3f6f71d
JM
5791 /* ----------------------------- SNIP -----------------------------
5792 Anything added to the cleanup chain beyond this point is assumed
5793 to be part of a breakpoint. If the breakpoint create succeeds
80c99de1
PA
5794 then the memory is not reclaimed. */
5795 bkpt_chain = make_cleanup (null_cleanup, 0);
c3f6f71d
JM
5796
5797 /* Mark the contents of the addr_string for cleanup. These go on
80c99de1 5798 the bkpt_chain and only occur if the breakpoint create fails. */
c3f6f71d
JM
5799 for (i = 0; i < sals.nelts; i++)
5800 {
5801 if (addr_string[i] != NULL)
b8c9b27d 5802 make_cleanup (xfree, addr_string[i]);
c3f6f71d
JM
5803 }
5804
5805 /* Resolve all line numbers to PC's and verify that the addresses
5806 are ok for the target. */
0101ce28
JJ
5807 if (!pending)
5808 breakpoint_sals_to_pc (&sals, addr_start);
c3f6f71d 5809
1042e4c0
SS
5810 type_wanted = (traceflag
5811 ? bp_tracepoint
5812 : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint));
5813
c3f6f71d
JM
5814 /* Verify that condition can be parsed, before setting any
5815 breakpoints. Allocate a separate condition expression for each
5816 breakpoint. */
0101ce28 5817 if (!pending)
c3f6f71d 5818 {
2f069f6f 5819 if (parse_condition_and_thread)
72b2ff0e
VP
5820 {
5821 /* Here we only parse 'arg' to separate condition
5822 from thread number, so parsing in context of first
5823 sal is OK. When setting the breakpoint we'll
5824 re-parse it in context of each sal. */
5825 cond_string = NULL;
5826 thread = -1;
4a306c9a
JB
5827 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string,
5828 &thread, &task);
72b2ff0e
VP
5829 if (cond_string)
5830 make_cleanup (xfree, cond_string);
5831 }
2f069f6f 5832 else
72b2ff0e
VP
5833 {
5834 /* Create a private copy of condition string. */
5835 if (cond_string)
5836 {
5837 cond_string = xstrdup (cond_string);
5838 make_cleanup (xfree, cond_string);
5839 }
5840 }
1042e4c0 5841 create_breakpoints (sals, addr_string, cond_string, type_wanted,
0101ce28 5842 tempflag ? disp_del : disp_donttouch,
4a306c9a 5843 thread, task, ignore_count, ops, from_tty, enabled);
c906108c 5844 }
0101ce28
JJ
5845 else
5846 {
fe3f5fa8 5847 struct symtab_and_line sal = {0};
0101ce28
JJ
5848 struct breakpoint *b;
5849
0101ce28
JJ
5850 make_cleanup (xfree, copy_arg);
5851
1042e4c0 5852 b = set_raw_breakpoint_without_location (type_wanted);
0101ce28
JJ
5853 set_breakpoint_count (breakpoint_count + 1);
5854 b->number = breakpoint_count;
72b2ff0e 5855 b->thread = -1;
018d34a4 5856 b->addr_string = addr_string[0];
72b2ff0e 5857 b->cond_string = NULL;
0101ce28 5858 b->ignore_count = ignore_count;
0101ce28 5859 b->disposition = tempflag ? disp_del : disp_donttouch;
0d381245 5860 b->condition_not_parsed = 1;
604133b5 5861 b->ops = ops;
41447f92 5862 b->enable_state = enabled ? bp_enabled : bp_disabled;
74960c60 5863
0101ce28
JJ
5864 mention (b);
5865 }
5866
c3f6f71d 5867 if (sals.nelts > 1)
8a3fe4f8
AC
5868 warning (_("Multiple breakpoints were set.\n"
5869 "Use the \"delete\" command to delete unwanted breakpoints."));
80c99de1
PA
5870 /* That's it. Discard the cleanups for data inserted into the
5871 breakpoint. */
5872 discard_cleanups (bkpt_chain);
5873 /* But cleanup everything else. */
c3f6f71d 5874 do_cleanups (old_chain);
217dc9e2 5875
80c99de1 5876 /* error call may happen here - have BKPT_CHAIN already discarded. */
217dc9e2 5877 update_global_location_list (1);
c3f6f71d 5878}
c906108c 5879
72b2ff0e
VP
5880/* Set a breakpoint.
5881 ARG is a string describing breakpoint address,
5882 condition, and thread.
5883 FLAG specifies if a breakpoint is hardware on,
5884 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5885 and BP_TEMPFLAG. */
5886
98deb0da 5887static void
72b2ff0e 5888break_command_1 (char *arg, int flag, int from_tty)
c3f6f71d 5889{
72b2ff0e
VP
5890 int hardwareflag = flag & BP_HARDWAREFLAG;
5891 int tempflag = flag & BP_TEMPFLAG;
c3f6f71d 5892
98deb0da
VP
5893 break_command_really (arg,
5894 NULL, 0, 1 /* parse arg */,
1042e4c0 5895 tempflag, hardwareflag, 0 /* traceflag */,
98deb0da 5896 0 /* Ignore count */,
604133b5
AR
5897 pending_break_support,
5898 NULL /* breakpoint_ops */,
41447f92
VP
5899 from_tty,
5900 1 /* enabled */);
c906108c
SS
5901}
5902
72b2ff0e 5903
98deb0da
VP
5904void
5905set_breakpoint (char *address, char *condition,
c3f6f71d 5906 int hardwareflag, int tempflag,
ce43223b 5907 int thread, int ignore_count,
41447f92 5908 int pending, int enabled)
c3f6f71d 5909{
98deb0da
VP
5910 break_command_really (address, condition, thread,
5911 0 /* condition and thread are valid. */,
1042e4c0 5912 tempflag, hardwareflag, 0 /* traceflag */,
98deb0da
VP
5913 ignore_count,
5914 pending
5915 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
41447f92 5916 NULL, 0, enabled);
c3f6f71d
JM
5917}
5918
6a048695
JB
5919/* Adjust SAL to the first instruction past the function prologue.
5920 The end of the prologue is determined using the line table from
3daf8fe5
JG
5921 the debugging information. explicit_pc and explicit_line are
5922 not modified.
6a048695
JB
5923
5924 If SAL is already past the prologue, then do nothing. */
5925
5926static void
5927skip_prologue_sal (struct symtab_and_line *sal)
5928{
5929 struct symbol *sym = find_pc_function (sal->pc);
5930 struct symtab_and_line start_sal;
5931
5932 if (sym == NULL)
5933 return;
5934
5935 start_sal = find_function_start_sal (sym, 1);
5936 if (sal->pc < start_sal.pc)
3daf8fe5
JG
5937 {
5938 start_sal.explicit_line = sal->explicit_line;
5939 start_sal.explicit_pc = sal->explicit_pc;
5940 *sal = start_sal;
5941 }
6a048695 5942}
c3f6f71d 5943
c906108c
SS
5944/* Helper function for break_command_1 and disassemble_command. */
5945
5946void
fba45db2 5947resolve_sal_pc (struct symtab_and_line *sal)
c906108c
SS
5948{
5949 CORE_ADDR pc;
5950
5951 if (sal->pc == 0 && sal->symtab != NULL)
5952 {
5953 if (!find_line_pc (sal->symtab, sal->line, &pc))
8a3fe4f8 5954 error (_("No line %d in file \"%s\"."),
c906108c
SS
5955 sal->line, sal->symtab->filename);
5956 sal->pc = pc;
6a048695
JB
5957
5958 /* If this SAL corresponds to a breakpoint inserted using
5959 a line number, then skip the function prologue if necessary. */
5960 if (sal->explicit_line)
56ef84b1
TT
5961 {
5962 /* Preserve the original line number. */
5963 int saved_line = sal->line;
5964 skip_prologue_sal (sal);
5965 sal->line = saved_line;
5966 }
c906108c
SS
5967 }
5968
5969 if (sal->section == 0 && sal->symtab != NULL)
5970 {
5971 struct blockvector *bv;
c5aa993b
JM
5972 struct block *b;
5973 struct symbol *sym;
c906108c 5974
801e3a5b 5975 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
c906108c
SS
5976 if (bv != NULL)
5977 {
7f0df278 5978 sym = block_linkage_function (b);
c906108c
SS
5979 if (sym != NULL)
5980 {
5981 fixup_symbol_section (sym, sal->symtab->objfile);
714835d5 5982 sal->section = SYMBOL_OBJ_SECTION (sym);
c906108c
SS
5983 }
5984 else
5985 {
5986 /* It really is worthwhile to have the section, so we'll just
c5aa993b
JM
5987 have to look harder. This case can be executed if we have
5988 line numbers but no functions (as can happen in assembly
5989 source). */
c906108c 5990
c5aa993b 5991 struct minimal_symbol *msym;
c906108c
SS
5992
5993 msym = lookup_minimal_symbol_by_pc (sal->pc);
5994 if (msym)
714835d5 5995 sal->section = SYMBOL_OBJ_SECTION (msym);
c906108c
SS
5996 }
5997 }
5998 }
5999}
6000
6001void
fba45db2 6002break_command (char *arg, int from_tty)
c906108c 6003{
db107f19 6004 break_command_1 (arg, 0, from_tty);
c906108c
SS
6005}
6006
c906108c 6007void
fba45db2 6008tbreak_command (char *arg, int from_tty)
c906108c 6009{
db107f19 6010 break_command_1 (arg, BP_TEMPFLAG, from_tty);
c906108c
SS
6011}
6012
c906108c 6013static void
fba45db2 6014hbreak_command (char *arg, int from_tty)
c906108c 6015{
db107f19 6016 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
c906108c
SS
6017}
6018
6019static void
fba45db2 6020thbreak_command (char *arg, int from_tty)
c906108c 6021{
db107f19 6022 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
c906108c
SS
6023}
6024
6025static void
fba45db2 6026stop_command (char *arg, int from_tty)
c906108c 6027{
a3f17187 6028 printf_filtered (_("Specify the type of breakpoint to set.\n\
c906108c 6029Usage: stop in <function | address>\n\
a3f17187 6030 stop at <line>\n"));
c906108c
SS
6031}
6032
6033static void
fba45db2 6034stopin_command (char *arg, int from_tty)
c906108c
SS
6035{
6036 int badInput = 0;
6037
c5aa993b 6038 if (arg == (char *) NULL)
c906108c
SS
6039 badInput = 1;
6040 else if (*arg != '*')
6041 {
6042 char *argptr = arg;
6043 int hasColon = 0;
6044
53a5351d
JM
6045 /* look for a ':'. If this is a line number specification, then
6046 say it is bad, otherwise, it should be an address or
6047 function/method name */
c906108c 6048 while (*argptr && !hasColon)
c5aa993b
JM
6049 {
6050 hasColon = (*argptr == ':');
6051 argptr++;
6052 }
c906108c
SS
6053
6054 if (hasColon)
c5aa993b 6055 badInput = (*argptr != ':'); /* Not a class::method */
c906108c 6056 else
c5aa993b 6057 badInput = isdigit (*arg); /* a simple line number */
c906108c
SS
6058 }
6059
6060 if (badInput)
a3f17187 6061 printf_filtered (_("Usage: stop in <function | address>\n"));
c906108c 6062 else
db107f19 6063 break_command_1 (arg, 0, from_tty);
c906108c
SS
6064}
6065
6066static void
fba45db2 6067stopat_command (char *arg, int from_tty)
c906108c
SS
6068{
6069 int badInput = 0;
6070
c5aa993b 6071 if (arg == (char *) NULL || *arg == '*') /* no line number */
c906108c
SS
6072 badInput = 1;
6073 else
6074 {
6075 char *argptr = arg;
6076 int hasColon = 0;
6077
6078 /* look for a ':'. If there is a '::' then get out, otherwise
c5aa993b 6079 it is probably a line number. */
c906108c 6080 while (*argptr && !hasColon)
c5aa993b
JM
6081 {
6082 hasColon = (*argptr == ':');
6083 argptr++;
6084 }
c906108c
SS
6085
6086 if (hasColon)
c5aa993b 6087 badInput = (*argptr == ':'); /* we have class::method */
c906108c 6088 else
c5aa993b 6089 badInput = !isdigit (*arg); /* not a line number */
c906108c
SS
6090 }
6091
6092 if (badInput)
a3f17187 6093 printf_filtered (_("Usage: stop at <line>\n"));
c906108c 6094 else
db107f19 6095 break_command_1 (arg, 0, from_tty);
c906108c
SS
6096}
6097
53a5351d
JM
6098/* accessflag: hw_write: watch write,
6099 hw_read: watch read,
6100 hw_access: watch access (read or write) */
c906108c 6101static void
fba45db2 6102watch_command_1 (char *arg, int accessflag, int from_tty)
c906108c 6103{
d983da9c 6104 struct breakpoint *b, *scope_breakpoint = NULL;
c906108c
SS
6105 struct symtab_and_line sal;
6106 struct expression *exp;
6107 struct block *exp_valid_block;
6108 struct value *val, *mark;
6109 struct frame_info *frame;
6110 struct frame_info *prev_frame = NULL;
6111 char *exp_start = NULL;
6112 char *exp_end = NULL;
37e4754d 6113 char *tok, *id_tok_start, *end_tok;
c906108c
SS
6114 int toklen;
6115 char *cond_start = NULL;
6116 char *cond_end = NULL;
6117 struct expression *cond = NULL;
6118 int i, other_type_used, target_resources_ok = 0;
6119 enum bptype bp_type;
6120 int mem_cnt = 0;
37e4754d 6121 int thread = -1;
c906108c 6122
fe39c653 6123 init_sal (&sal); /* initialize to zeroes */
c5aa993b 6124
37e4754d
LM
6125 /* Make sure that we actually have parameters to parse. */
6126 if (arg != NULL && arg[0] != '\0')
6127 {
6128 toklen = strlen (arg); /* Size of argument list. */
6129
6130 /* Points tok to the end of the argument list. */
6131 tok = arg + toklen - 1;
6132
6133 /* Go backwards in the parameters list. Skip the last parameter.
6134 If we're expecting a 'thread <thread_num>' parameter, this should
6135 be the thread identifier. */
6136 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6137 tok--;
6138 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6139 tok--;
6140
6141 /* Points end_tok to the beginning of the last token. */
6142 id_tok_start = tok + 1;
6143
6144 /* Go backwards in the parameters list. Skip one more parameter.
6145 If we're expecting a 'thread <thread_num>' parameter, we should
6146 reach a "thread" token. */
6147 while (tok > arg && (*tok == ' ' || *tok == '\t'))
6148 tok--;
6149
6150 end_tok = tok;
6151
6152 while (tok > arg && (*tok != ' ' && *tok != '\t'))
6153 tok--;
6154
6155 /* Move the pointer forward to skip the whitespace and
6156 calculate the length of the token. */
6157 tok++;
6158 toklen = end_tok - tok;
6159
6160 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
6161 {
6162 /* At this point we've found a "thread" token, which means
6163 the user is trying to set a watchpoint that triggers
6164 only in a specific thread. */
6165 char *endp;
6166
6167 /* Extract the thread ID from the next token. */
6168 thread = strtol (id_tok_start, &endp, 0);
6169
6170 /* Check if the user provided a valid numeric value for the
6171 thread ID. */
6172 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
6173 error (_("Invalid thread ID specification %s."), id_tok_start);
6174
6175 /* Check if the thread actually exists. */
6176 if (!valid_thread_id (thread))
6177 error (_("Unknown thread %d."), thread);
6178
6179 /* Truncate the string and get rid of the thread <thread_num>
6180 parameter before the parameter list is parsed by the
6181 evaluate_expression() function. */
6182 *tok = '\0';
6183 }
6184 }
6185
6186 /* Parse the rest of the arguments. */
c906108c
SS
6187 innermost_block = NULL;
6188 exp_start = arg;
6189 exp = parse_exp_1 (&arg, 0, 0);
6190 exp_end = arg;
fa8a61dc
TT
6191 /* Remove trailing whitespace from the expression before saving it.
6192 This makes the eventual display of the expression string a bit
6193 prettier. */
6194 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
6195 --exp_end;
6196
c906108c
SS
6197 exp_valid_block = innermost_block;
6198 mark = value_mark ();
fa4727a6
DJ
6199 fetch_watchpoint_value (exp, &val, NULL, NULL);
6200 if (val != NULL)
6201 release_value (val);
c906108c
SS
6202
6203 tok = arg;
6204 while (*tok == ' ' || *tok == '\t')
6205 tok++;
6206 end_tok = tok;
6207
6208 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
6209 end_tok++;
6210
6211 toklen = end_tok - tok;
6212 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
6213 {
6214 tok = cond_start = end_tok + 1;
6215 cond = parse_exp_1 (&tok, 0, 0);
6216 cond_end = tok;
6217 }
6218 if (*tok)
8a3fe4f8 6219 error (_("Junk at end of command."));
c906108c 6220
53a5351d 6221 if (accessflag == hw_read)
c5aa993b 6222 bp_type = bp_read_watchpoint;
53a5351d 6223 else if (accessflag == hw_access)
c5aa993b
JM
6224 bp_type = bp_access_watchpoint;
6225 else
6226 bp_type = bp_hardware_watchpoint;
c906108c
SS
6227
6228 mem_cnt = can_use_hardware_watchpoint (val);
6229 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
8a3fe4f8 6230 error (_("Expression cannot be implemented with read/access watchpoint."));
c5aa993b
JM
6231 if (mem_cnt != 0)
6232 {
6233 i = hw_watchpoint_used_count (bp_type, &other_type_used);
53a5351d 6234 target_resources_ok =
d92524f1 6235 target_can_use_hardware_watchpoint (bp_type, i + mem_cnt,
53a5351d 6236 other_type_used);
c5aa993b 6237 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
8a3fe4f8 6238 error (_("Target does not support this type of hardware watchpoint."));
53a5351d 6239
c5aa993b 6240 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
8a3fe4f8 6241 error (_("Target can only support one kind of HW watchpoint at a time."));
c5aa993b 6242 }
c906108c 6243
4d28f7a8
KB
6244 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
6245 watchpoint could not be set. */
6246 if (!mem_cnt || target_resources_ok <= 0)
6247 bp_type = bp_watchpoint;
6248
d983da9c
DJ
6249 frame = block_innermost_frame (exp_valid_block);
6250 if (frame)
6251 prev_frame = get_prev_frame (frame);
6252 else
6253 prev_frame = NULL;
6254
6255 /* If the expression is "local", then set up a "watchpoint scope"
6256 breakpoint at the point where we've left the scope of the watchpoint
6257 expression. Create the scope breakpoint before the watchpoint, so
6258 that we will encounter it first in bpstat_stop_status. */
6259 if (innermost_block && prev_frame)
6260 {
6261 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
6262 bp_watchpoint_scope);
6263
6264 scope_breakpoint->enable_state = bp_enabled;
6265
6266 /* Automatically delete the breakpoint when it hits. */
6267 scope_breakpoint->disposition = disp_del;
6268
6269 /* Only break in the proper frame (help with recursion). */
6270 scope_breakpoint->frame_id = get_frame_id (prev_frame);
6271
6272 /* Set the address at which we will stop. */
6273 scope_breakpoint->loc->requested_address
6274 = get_frame_pc (prev_frame);
6275 scope_breakpoint->loc->address
6276 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
6277 scope_breakpoint->type);
6278 }
6279
c906108c 6280 /* Now set up the breakpoint. */
4d28f7a8 6281 b = set_raw_breakpoint (sal, bp_type);
c906108c
SS
6282 set_breakpoint_count (breakpoint_count + 1);
6283 b->number = breakpoint_count;
37e4754d 6284 b->thread = thread;
b5de0fa7 6285 b->disposition = disp_donttouch;
c906108c
SS
6286 b->exp = exp;
6287 b->exp_valid_block = exp_valid_block;
6288 b->exp_string = savestring (exp_start, exp_end - exp_start);
6289 b->val = val;
fa4727a6 6290 b->val_valid = 1;
511a6cd4 6291 b->loc->cond = cond;
c906108c
SS
6292 if (cond_start)
6293 b->cond_string = savestring (cond_start, cond_end - cond_start);
6294 else
6295 b->cond_string = 0;
c5aa993b 6296
c906108c 6297 if (frame)
d983da9c 6298 b->watchpoint_frame = get_frame_id (frame);
c906108c 6299 else
35a487f1 6300 b->watchpoint_frame = null_frame_id;
c906108c 6301
d983da9c 6302 if (scope_breakpoint != NULL)
c906108c 6303 {
d983da9c
DJ
6304 /* The scope breakpoint is related to the watchpoint. We will
6305 need to act on them together. */
6306 b->related_breakpoint = scope_breakpoint;
6307 scope_breakpoint->related_breakpoint = b;
c906108c 6308 }
d983da9c 6309
c906108c
SS
6310 value_free_to_mark (mark);
6311 mention (b);
b60e7edf 6312 update_global_location_list (1);
c906108c
SS
6313}
6314
6315/* Return count of locations need to be watched and can be handled
6316 in hardware. If the watchpoint can not be handled
6317 in hardware return zero. */
6318
c906108c 6319static int
fba45db2 6320can_use_hardware_watchpoint (struct value *v)
c906108c
SS
6321{
6322 int found_memory_cnt = 0;
2e70b7b9 6323 struct value *head = v;
c906108c
SS
6324
6325 /* Did the user specifically forbid us to use hardware watchpoints? */
c5aa993b 6326 if (!can_use_hw_watchpoints)
c906108c 6327 return 0;
c5aa993b 6328
5c44784c
JM
6329 /* Make sure that the value of the expression depends only upon
6330 memory contents, and values computed from them within GDB. If we
6331 find any register references or function calls, we can't use a
6332 hardware watchpoint.
6333
6334 The idea here is that evaluating an expression generates a series
6335 of values, one holding the value of every subexpression. (The
6336 expression a*b+c has five subexpressions: a, b, a*b, c, and
6337 a*b+c.) GDB's values hold almost enough information to establish
6338 the criteria given above --- they identify memory lvalues,
6339 register lvalues, computed values, etcetera. So we can evaluate
6340 the expression, and then scan the chain of values that leaves
6341 behind to decide whether we can detect any possible change to the
6342 expression's final value using only hardware watchpoints.
6343
6344 However, I don't think that the values returned by inferior
6345 function calls are special in any way. So this function may not
6346 notice that an expression involving an inferior function call
6347 can't be watched with hardware watchpoints. FIXME. */
17cf0ecd 6348 for (; v; v = value_next (v))
c906108c 6349 {
5c44784c 6350 if (VALUE_LVAL (v) == lval_memory)
c906108c 6351 {
d69fe07e 6352 if (value_lazy (v))
5c44784c
JM
6353 /* A lazy memory lvalue is one that GDB never needed to fetch;
6354 we either just used its address (e.g., `a' in `a.b') or
6355 we never needed it at all (e.g., `a' in `a,b'). */
6356 ;
53a5351d 6357 else
5c44784c
JM
6358 {
6359 /* Ahh, memory we actually used! Check if we can cover
6360 it with hardware watchpoints. */
df407dfe 6361 struct type *vtype = check_typedef (value_type (v));
2e70b7b9
MS
6362
6363 /* We only watch structs and arrays if user asked for it
6364 explicitly, never if they just happen to appear in a
6365 middle of some value chain. */
6366 if (v == head
6367 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6368 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6369 {
42ae5230 6370 CORE_ADDR vaddr = value_address (v);
df407dfe 6371 int len = TYPE_LENGTH (value_type (v));
2e70b7b9 6372
d92524f1 6373 if (!target_region_ok_for_hw_watchpoint (vaddr, len))
2e70b7b9
MS
6374 return 0;
6375 else
6376 found_memory_cnt++;
6377 }
5c44784c 6378 }
c5aa993b 6379 }
5086187c
AC
6380 else if (VALUE_LVAL (v) != not_lval
6381 && deprecated_value_modifiable (v) == 0)
53a5351d 6382 return 0; /* ??? What does this represent? */
5086187c 6383 else if (VALUE_LVAL (v) == lval_register)
53a5351d 6384 return 0; /* cannot watch a register with a HW watchpoint */
c906108c
SS
6385 }
6386
6387 /* The expression itself looks suitable for using a hardware
6388 watchpoint, but give the target machine a chance to reject it. */
6389 return found_memory_cnt;
6390}
6391
8b93c638 6392void
fba45db2 6393watch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
6394{
6395 watch_command (arg, from_tty);
6396}
8926118c 6397
c5aa993b 6398static void
fba45db2 6399watch_command (char *arg, int from_tty)
c906108c 6400{
53a5351d 6401 watch_command_1 (arg, hw_write, from_tty);
c906108c
SS
6402}
6403
8b93c638 6404void
fba45db2 6405rwatch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
6406{
6407 rwatch_command (arg, from_tty);
6408}
8926118c 6409
c5aa993b 6410static void
fba45db2 6411rwatch_command (char *arg, int from_tty)
c906108c 6412{
53a5351d 6413 watch_command_1 (arg, hw_read, from_tty);
c906108c
SS
6414}
6415
8b93c638 6416void
fba45db2 6417awatch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
6418{
6419 awatch_command (arg, from_tty);
6420}
8926118c 6421
c5aa993b 6422static void
fba45db2 6423awatch_command (char *arg, int from_tty)
c906108c 6424{
53a5351d 6425 watch_command_1 (arg, hw_access, from_tty);
c906108c 6426}
c906108c 6427\f
c5aa993b 6428
43ff13b4 6429/* Helper routines for the until_command routine in infcmd.c. Here
c906108c
SS
6430 because it uses the mechanisms of breakpoints. */
6431
bfec99b2
PA
6432struct until_break_command_continuation_args
6433{
6434 struct breakpoint *breakpoint;
6435 struct breakpoint *breakpoint2;
6436};
6437
43ff13b4
JM
6438/* This function is called by fetch_inferior_event via the
6439 cmd_continuation pointer, to complete the until command. It takes
6440 care of cleaning up the temporary breakpoints set up by the until
6441 command. */
c2c6d25f 6442static void
604ead4a 6443until_break_command_continuation (void *arg)
43ff13b4 6444{
bfec99b2
PA
6445 struct until_break_command_continuation_args *a = arg;
6446
6447 delete_breakpoint (a->breakpoint);
6448 if (a->breakpoint2)
6449 delete_breakpoint (a->breakpoint2);
43ff13b4
JM
6450}
6451
c906108c 6452void
ae66c1fc 6453until_break_command (char *arg, int from_tty, int anywhere)
c906108c
SS
6454{
6455 struct symtabs_and_lines sals;
6456 struct symtab_and_line sal;
206415a3
DJ
6457 struct frame_info *frame = get_selected_frame (NULL);
6458 struct frame_info *prev_frame = get_prev_frame (frame);
c906108c 6459 struct breakpoint *breakpoint;
f107f563 6460 struct breakpoint *breakpoint2 = NULL;
c906108c
SS
6461 struct cleanup *old_chain;
6462
6463 clear_proceed_status ();
6464
6465 /* Set a breakpoint where the user wants it and at return from
6466 this function */
c5aa993b 6467
c906108c
SS
6468 if (default_breakpoint_valid)
6469 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
68219205 6470 default_breakpoint_line, (char ***) NULL, NULL);
c906108c 6471 else
53a5351d 6472 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
68219205 6473 0, (char ***) NULL, NULL);
c5aa993b 6474
c906108c 6475 if (sals.nelts != 1)
8a3fe4f8 6476 error (_("Couldn't get information on specified line."));
c5aa993b 6477
c906108c 6478 sal = sals.sals[0];
b8c9b27d 6479 xfree (sals.sals); /* malloc'd, so freed */
c5aa993b 6480
c906108c 6481 if (*arg)
8a3fe4f8 6482 error (_("Junk at end of arguments."));
c5aa993b 6483
c906108c 6484 resolve_sal_pc (&sal);
c5aa993b 6485
ae66c1fc
EZ
6486 if (anywhere)
6487 /* If the user told us to continue until a specified location,
6488 we don't specify a frame at which we need to stop. */
6489 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6490 else
6491 /* Otherwise, specify the current frame, because we want to stop only
6492 at the very same frame. */
206415a3 6493 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
ae66c1fc 6494 bp_until);
c5aa993b 6495
f107f563 6496 old_chain = make_cleanup_delete_breakpoint (breakpoint);
c906108c 6497
ae66c1fc
EZ
6498 /* Keep within the current frame, or in frames called by the current
6499 one. */
c906108c
SS
6500 if (prev_frame)
6501 {
30f7db39
AC
6502 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6503 sal.pc = get_frame_pc (prev_frame);
f107f563
VP
6504 breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6505 bp_until);
6506 make_cleanup_delete_breakpoint (breakpoint2);
c906108c 6507 }
c5aa993b 6508
c906108c 6509 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
f107f563
VP
6510
6511 /* If we are running asynchronously, and proceed call above has actually
6512 managed to start the target, arrange for breakpoints to be
6513 deleted when the target stops. Otherwise, we're already stopped and
6514 delete breakpoints via cleanup chain. */
6515
8ea051c5 6516 if (target_can_async_p () && is_running (inferior_ptid))
f107f563 6517 {
bfec99b2
PA
6518 struct until_break_command_continuation_args *args;
6519 args = xmalloc (sizeof (*args));
f107f563 6520
bfec99b2
PA
6521 args->breakpoint = breakpoint;
6522 args->breakpoint2 = breakpoint2;
f107f563
VP
6523
6524 discard_cleanups (old_chain);
95e54da7
PA
6525 add_continuation (inferior_thread (),
6526 until_break_command_continuation, args,
604ead4a 6527 xfree);
f107f563
VP
6528 }
6529 else
c5aa993b 6530 do_cleanups (old_chain);
c906108c 6531}
ae66c1fc 6532
c906108c 6533static void
fba45db2 6534ep_skip_leading_whitespace (char **s)
c906108c 6535{
c5aa993b
JM
6536 if ((s == NULL) || (*s == NULL))
6537 return;
6538 while (isspace (**s))
6539 *s += 1;
c906108c 6540}
c5aa993b 6541
c906108c
SS
6542/* This function attempts to parse an optional "if <cond>" clause
6543 from the arg string. If one is not found, it returns NULL.
c5aa993b 6544
c906108c
SS
6545 Else, it returns a pointer to the condition string. (It does not
6546 attempt to evaluate the string against a particular block.) And,
6547 it updates arg to point to the first character following the parsed
6548 if clause in the arg string. */
53a5351d 6549
c906108c 6550static char *
fba45db2 6551ep_parse_optional_if_clause (char **arg)
c906108c 6552{
c5aa993b
JM
6553 char *cond_string;
6554
6555 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
c906108c 6556 return NULL;
c5aa993b 6557
c906108c
SS
6558 /* Skip the "if" keyword. */
6559 (*arg) += 2;
c5aa993b 6560
c906108c
SS
6561 /* Skip any extra leading whitespace, and record the start of the
6562 condition string. */
6563 ep_skip_leading_whitespace (arg);
6564 cond_string = *arg;
c5aa993b 6565
c906108c
SS
6566 /* Assume that the condition occupies the remainder of the arg string. */
6567 (*arg) += strlen (cond_string);
c5aa993b 6568
c906108c
SS
6569 return cond_string;
6570}
c5aa993b 6571
c906108c
SS
6572/* This function attempts to parse an optional filename from the arg
6573 string. If one is not found, it returns NULL.
c5aa993b 6574
c906108c
SS
6575 Else, it returns a pointer to the parsed filename. (This function
6576 makes no attempt to verify that a file of that name exists, or is
6577 accessible.) And, it updates arg to point to the first character
6578 following the parsed filename in the arg string.
c5aa993b 6579
c906108c
SS
6580 Note that clients needing to preserve the returned filename for
6581 future access should copy it to their own buffers. */
6582static char *
fba45db2 6583ep_parse_optional_filename (char **arg)
c906108c 6584{
c5aa993b
JM
6585 static char filename[1024];
6586 char *arg_p = *arg;
6587 int i;
6588 char c;
6589
c906108c
SS
6590 if ((*arg_p == '\0') || isspace (*arg_p))
6591 return NULL;
c5aa993b
JM
6592
6593 for (i = 0;; i++)
c906108c
SS
6594 {
6595 c = *arg_p;
6596 if (isspace (c))
c5aa993b 6597 c = '\0';
c906108c
SS
6598 filename[i] = c;
6599 if (c == '\0')
c5aa993b 6600 break;
c906108c
SS
6601 arg_p++;
6602 }
6603 *arg = arg_p;
c5aa993b 6604
c906108c
SS
6605 return filename;
6606}
c5aa993b 6607
c906108c
SS
6608/* Commands to deal with catching events, such as signals, exceptions,
6609 process start/exit, etc. */
c5aa993b
JM
6610
6611typedef enum
6612{
44feb3ce
TT
6613 catch_fork_temporary, catch_vfork_temporary,
6614 catch_fork_permanent, catch_vfork_permanent
c5aa993b
JM
6615}
6616catch_fork_kind;
6617
c906108c 6618static void
44feb3ce 6619catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
c906108c 6620{
c5aa993b 6621 char *cond_string = NULL;
44feb3ce
TT
6622 catch_fork_kind fork_kind;
6623 int tempflag;
6624
6625 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
6626 tempflag = (fork_kind == catch_fork_temporary
6627 || fork_kind == catch_vfork_temporary);
c5aa993b 6628
44feb3ce
TT
6629 if (!arg)
6630 arg = "";
c906108c 6631 ep_skip_leading_whitespace (&arg);
c5aa993b 6632
c906108c 6633 /* The allowed syntax is:
c5aa993b
JM
6634 catch [v]fork
6635 catch [v]fork if <cond>
6636
c906108c
SS
6637 First, check if there's an if clause. */
6638 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 6639
c906108c 6640 if ((*arg != '\0') && !isspace (*arg))
8a3fe4f8 6641 error (_("Junk at end of arguments."));
c5aa993b 6642
c906108c
SS
6643 /* If this target supports it, create a fork or vfork catchpoint
6644 and enable reporting of such events. */
c5aa993b
JM
6645 switch (fork_kind)
6646 {
44feb3ce
TT
6647 case catch_fork_temporary:
6648 case catch_fork_permanent:
ce78b96d
JB
6649 create_fork_vfork_event_catchpoint (tempflag, cond_string,
6650 &catch_fork_breakpoint_ops);
c906108c 6651 break;
44feb3ce
TT
6652 case catch_vfork_temporary:
6653 case catch_vfork_permanent:
ce78b96d
JB
6654 create_fork_vfork_event_catchpoint (tempflag, cond_string,
6655 &catch_vfork_breakpoint_ops);
c906108c 6656 break;
c5aa993b 6657 default:
8a3fe4f8 6658 error (_("unsupported or unknown fork kind; cannot catch it"));
c906108c 6659 break;
c5aa993b 6660 }
c906108c
SS
6661}
6662
6663static void
44feb3ce 6664catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command)
c906108c 6665{
44feb3ce 6666 int tempflag;
c5aa993b 6667 char *cond_string = NULL;
c906108c 6668
44feb3ce
TT
6669 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6670
6671 if (!arg)
6672 arg = "";
c906108c
SS
6673 ep_skip_leading_whitespace (&arg);
6674
6675 /* The allowed syntax is:
c5aa993b
JM
6676 catch exec
6677 catch exec if <cond>
c906108c
SS
6678
6679 First, check if there's an if clause. */
6680 cond_string = ep_parse_optional_if_clause (&arg);
6681
6682 if ((*arg != '\0') && !isspace (*arg))
8a3fe4f8 6683 error (_("Junk at end of arguments."));
c906108c
SS
6684
6685 /* If this target supports it, create an exec catchpoint
6686 and enable reporting of such events. */
fe798b75 6687 create_catchpoint (tempflag, cond_string, &catch_exec_breakpoint_ops);
c906108c 6688}
c5aa993b 6689
3086aeae
DJ
6690static enum print_stop_action
6691print_exception_catchpoint (struct breakpoint *b)
6692{
ade92717 6693 int bp_temp, bp_throw;
3086aeae 6694
ade92717 6695 annotate_catchpoint (b->number);
3086aeae 6696
ade92717
AR
6697 bp_throw = strstr (b->addr_string, "throw") != NULL;
6698 if (b->loc->address != b->loc->requested_address)
6699 breakpoint_adjustment_warning (b->loc->requested_address,
6700 b->loc->address,
6701 b->number, 1);
df2b6d2d 6702 bp_temp = b->disposition == disp_del;
ade92717
AR
6703 ui_out_text (uiout,
6704 bp_temp ? "Temporary catchpoint "
6705 : "Catchpoint ");
6706 if (!ui_out_is_mi_like_p (uiout))
6707 ui_out_field_int (uiout, "bkptno", b->number);
6708 ui_out_text (uiout,
c0b37c48
AR
6709 bp_throw ? " (exception thrown), "
6710 : " (exception caught), ");
ade92717
AR
6711 if (ui_out_is_mi_like_p (uiout))
6712 {
6713 ui_out_field_string (uiout, "reason",
6714 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
6715 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6716 ui_out_field_int (uiout, "bkptno", b->number);
6717 }
3086aeae
DJ
6718 return PRINT_SRC_AND_LOC;
6719}
6720
6721static void
6722print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6723{
79a45b7d
TT
6724 struct value_print_options opts;
6725 get_user_print_options (&opts);
6726 if (opts.addressprint)
3086aeae
DJ
6727 {
6728 annotate_field (4);
604133b5
AR
6729 if (b->loc == NULL || b->loc->shlib_disabled)
6730 ui_out_field_string (uiout, "addr", "<PENDING>");
6731 else
6732 ui_out_field_core_addr (uiout, "addr", b->loc->address);
3086aeae
DJ
6733 }
6734 annotate_field (5);
604133b5
AR
6735 if (b->loc)
6736 *last_addr = b->loc->address;
3086aeae
DJ
6737 if (strstr (b->addr_string, "throw") != NULL)
6738 ui_out_field_string (uiout, "what", "exception throw");
6739 else
6740 ui_out_field_string (uiout, "what", "exception catch");
6741}
6742
6743static void
6744print_mention_exception_catchpoint (struct breakpoint *b)
6745{
ade92717
AR
6746 int bp_temp;
6747 int bp_throw;
6748
df2b6d2d 6749 bp_temp = b->disposition == disp_del;
ade92717
AR
6750 bp_throw = strstr (b->addr_string, "throw") != NULL;
6751 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
6752 : _("Catchpoint "));
6753 ui_out_field_int (uiout, "bkptno", b->number);
6754 ui_out_text (uiout, bp_throw ? _(" (throw)")
6755 : _(" (catch)"));
3086aeae
DJ
6756}
6757
6758static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
ce78b96d
JB
6759 NULL, /* insert */
6760 NULL, /* remove */
6761 NULL, /* breakpoint_hit */
3086aeae
DJ
6762 print_exception_catchpoint,
6763 print_one_exception_catchpoint,
6764 print_mention_exception_catchpoint
6765};
6766
6767static int
6768handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6769 enum exception_event_kind ex_event, int from_tty)
6770{
604133b5
AR
6771 char *trigger_func_name;
6772
3086aeae 6773 if (ex_event == EX_EVENT_CATCH)
604133b5 6774 trigger_func_name = "__cxa_begin_catch";
3086aeae 6775 else
604133b5 6776 trigger_func_name = "__cxa_throw";
3086aeae 6777
604133b5
AR
6778 break_command_really (trigger_func_name, cond_string, -1,
6779 0 /* condition and thread are valid. */,
1042e4c0 6780 tempflag, 0, 0,
604133b5
AR
6781 0,
6782 AUTO_BOOLEAN_TRUE /* pending */,
41447f92
VP
6783 &gnu_v3_exception_catchpoint_ops, from_tty,
6784 1 /* enabled */);
3086aeae 6785
3086aeae
DJ
6786 return 1;
6787}
6788
c5aa993b 6789/* Deal with "catch catch" and "catch throw" commands */
c906108c
SS
6790
6791static void
fba45db2
KB
6792catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6793 int tempflag, int from_tty)
c906108c 6794{
c5aa993b
JM
6795 char *cond_string = NULL;
6796 struct symtab_and_line *sal = NULL;
6797
44feb3ce
TT
6798 if (!arg)
6799 arg = "";
c906108c 6800 ep_skip_leading_whitespace (&arg);
c5aa993b 6801
c906108c
SS
6802 cond_string = ep_parse_optional_if_clause (&arg);
6803
6804 if ((*arg != '\0') && !isspace (*arg))
8a3fe4f8 6805 error (_("Junk at end of arguments."));
c906108c 6806
059fb39f
PM
6807 if (ex_event != EX_EVENT_THROW
6808 && ex_event != EX_EVENT_CATCH)
8a3fe4f8 6809 error (_("Unsupported or unknown exception event; cannot catch it"));
c906108c 6810
3086aeae
DJ
6811 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6812 return;
6813
8a3fe4f8 6814 warning (_("Unsupported with this platform/compiler combination."));
c906108c
SS
6815}
6816
44feb3ce
TT
6817/* Implementation of "catch catch" command. */
6818
6819static void
6820catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command)
6821{
6822 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6823 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty);
6824}
6825
6826/* Implementation of "catch throw" command. */
6827
6828static void
6829catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command)
6830{
6831 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6832 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty);
6833}
6834
f7f9143b
JB
6835/* Create a breakpoint struct for Ada exception catchpoints. */
6836
6837static void
6838create_ada_exception_breakpoint (struct symtab_and_line sal,
6839 char *addr_string,
6840 char *exp_string,
6841 char *cond_string,
6842 struct expression *cond,
6843 struct breakpoint_ops *ops,
6844 int tempflag,
6845 int from_tty)
6846{
6847 struct breakpoint *b;
6848
6849 if (from_tty)
6850 {
6851 describe_other_breakpoints (sal.pc, sal.section, -1);
6852 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6853 version for exception catchpoints, because two catchpoints
6854 used for different exception names will use the same address.
6855 In this case, a "breakpoint ... also set at..." warning is
6856 unproductive. Besides. the warning phrasing is also a bit
6857 inapropriate, we should use the word catchpoint, and tell
6858 the user what type of catchpoint it is. The above is good
6859 enough for now, though. */
6860 }
6861
6862 b = set_raw_breakpoint (sal, bp_breakpoint);
6863 set_breakpoint_count (breakpoint_count + 1);
6864
6865 b->enable_state = bp_enabled;
6866 b->disposition = tempflag ? disp_del : disp_donttouch;
6867 b->number = breakpoint_count;
6868 b->ignore_count = 0;
511a6cd4 6869 b->loc->cond = cond;
f7f9143b
JB
6870 b->addr_string = addr_string;
6871 b->language = language_ada;
6872 b->cond_string = cond_string;
6873 b->exp_string = exp_string;
6874 b->thread = -1;
6875 b->ops = ops;
f7f9143b
JB
6876
6877 mention (b);
b60e7edf 6878 update_global_location_list (1);
f7f9143b
JB
6879}
6880
6881/* Implement the "catch exception" command. */
6882
6883static void
44feb3ce
TT
6884catch_ada_exception_command (char *arg, int from_tty,
6885 struct cmd_list_element *command)
f7f9143b 6886{
44feb3ce 6887 int tempflag;
f7f9143b
JB
6888 struct symtab_and_line sal;
6889 enum bptype type;
6890 char *addr_string = NULL;
6891 char *exp_string = NULL;
6892 char *cond_string = NULL;
6893 struct expression *cond = NULL;
6894 struct breakpoint_ops *ops = NULL;
6895
44feb3ce
TT
6896 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6897
6898 if (!arg)
6899 arg = "";
f7f9143b
JB
6900 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6901 &cond_string, &cond, &ops);
6902 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6903 cond_string, cond, ops, tempflag,
6904 from_tty);
6905}
6906
6907/* Implement the "catch assert" command. */
6908
6909static void
44feb3ce 6910catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command)
f7f9143b 6911{
44feb3ce 6912 int tempflag;
f7f9143b
JB
6913 struct symtab_and_line sal;
6914 char *addr_string = NULL;
6915 struct breakpoint_ops *ops = NULL;
6916
44feb3ce
TT
6917 tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
6918
6919 if (!arg)
6920 arg = "";
f7f9143b
JB
6921 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6922 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6923 tempflag, from_tty);
6924}
6925
c906108c 6926static void
fba45db2 6927catch_command (char *arg, int from_tty)
c906108c 6928{
44feb3ce 6929 error (_("Catch requires an event name."));
c906108c
SS
6930}
6931\f
6932
6933static void
fba45db2 6934tcatch_command (char *arg, int from_tty)
c906108c 6935{
44feb3ce 6936 error (_("Catch requires an event name."));
c906108c
SS
6937}
6938
80f8a6eb 6939/* Delete breakpoints by address or line. */
c906108c
SS
6940
6941static void
fba45db2 6942clear_command (char *arg, int from_tty)
c906108c 6943{
d6e956e5
VP
6944 struct breakpoint *b;
6945 VEC(breakpoint_p) *found = 0;
6946 int ix;
c906108c
SS
6947 int default_match;
6948 struct symtabs_and_lines sals;
6949 struct symtab_and_line sal;
c906108c
SS
6950 int i;
6951
6952 if (arg)
6953 {
6954 sals = decode_line_spec (arg, 1);
6955 default_match = 0;
6956 }
6957 else
6958 {
c5aa993b 6959 sals.sals = (struct symtab_and_line *)
c906108c 6960 xmalloc (sizeof (struct symtab_and_line));
80f8a6eb 6961 make_cleanup (xfree, sals.sals);
fe39c653 6962 init_sal (&sal); /* initialize to zeroes */
c906108c
SS
6963 sal.line = default_breakpoint_line;
6964 sal.symtab = default_breakpoint_symtab;
6965 sal.pc = default_breakpoint_address;
6966 if (sal.symtab == 0)
8a3fe4f8 6967 error (_("No source file specified."));
c906108c
SS
6968
6969 sals.sals[0] = sal;
6970 sals.nelts = 1;
6971
6972 default_match = 1;
6973 }
6974
ed0616c6
VP
6975 /* We don't call resolve_sal_pc here. That's not
6976 as bad as it seems, because all existing breakpoints
6977 typically have both file/line and pc set. So, if
6978 clear is given file/line, we can match this to existing
6979 breakpoint without obtaining pc at all.
6980
6981 We only support clearing given the address explicitly
6982 present in breakpoint table. Say, we've set breakpoint
6983 at file:line. There were several PC values for that file:line,
6984 due to optimization, all in one block.
6985 We've picked one PC value. If "clear" is issued with another
6986 PC corresponding to the same file:line, the breakpoint won't
6987 be cleared. We probably can still clear the breakpoint, but
6988 since the other PC value is never presented to user, user
6989 can only find it by guessing, and it does not seem important
6990 to support that. */
6991
c906108c 6992 /* For each line spec given, delete bps which correspond
80f8a6eb
MS
6993 to it. Do it in two passes, solely to preserve the current
6994 behavior that from_tty is forced true if we delete more than
6995 one breakpoint. */
c906108c 6996
80f8a6eb 6997 found = NULL;
c906108c
SS
6998 for (i = 0; i < sals.nelts; i++)
6999 {
7000 /* If exact pc given, clear bpts at that pc.
c5aa993b
JM
7001 If line given (pc == 0), clear all bpts on specified line.
7002 If defaulting, clear all bpts on default line
c906108c 7003 or at default pc.
c5aa993b
JM
7004
7005 defaulting sal.pc != 0 tests to do
7006
7007 0 1 pc
7008 1 1 pc _and_ line
7009 0 0 line
7010 1 0 <can't happen> */
c906108c
SS
7011
7012 sal = sals.sals[i];
c906108c 7013
d6e956e5
VP
7014 /* Find all matching breakpoints and add them to
7015 'found'. */
7016 ALL_BREAKPOINTS (b)
c5aa993b 7017 {
0d381245 7018 int match = 0;
80f8a6eb
MS
7019 /* Are we going to delete b? */
7020 if (b->type != bp_none
7021 && b->type != bp_watchpoint
7022 && b->type != bp_hardware_watchpoint
7023 && b->type != bp_read_watchpoint
0d381245
VP
7024 && b->type != bp_access_watchpoint)
7025 {
7026 struct bp_location *loc = b->loc;
7027 for (; loc; loc = loc->next)
7028 {
7029 int pc_match = sal.pc
7030 && (loc->address == sal.pc)
7031 && (!section_is_overlay (loc->section)
7032 || loc->section == sal.section);
7033 int line_match = ((default_match || (0 == sal.pc))
7034 && b->source_file != NULL
7035 && sal.symtab != NULL
7036 && strcmp (b->source_file, sal.symtab->filename) == 0
7037 && b->line_number == sal.line);
7038 if (pc_match || line_match)
7039 {
7040 match = 1;
7041 break;
7042 }
7043 }
7044 }
7045
7046 if (match)
d6e956e5 7047 VEC_safe_push(breakpoint_p, found, b);
c906108c 7048 }
80f8a6eb
MS
7049 }
7050 /* Now go thru the 'found' chain and delete them. */
d6e956e5 7051 if (VEC_empty(breakpoint_p, found))
80f8a6eb
MS
7052 {
7053 if (arg)
8a3fe4f8 7054 error (_("No breakpoint at %s."), arg);
80f8a6eb 7055 else
8a3fe4f8 7056 error (_("No breakpoint at this line."));
80f8a6eb 7057 }
c906108c 7058
d6e956e5 7059 if (VEC_length(breakpoint_p, found) > 1)
80f8a6eb
MS
7060 from_tty = 1; /* Always report if deleted more than one */
7061 if (from_tty)
a3f17187 7062 {
d6e956e5 7063 if (VEC_length(breakpoint_p, found) == 1)
a3f17187
AC
7064 printf_unfiltered (_("Deleted breakpoint "));
7065 else
7066 printf_unfiltered (_("Deleted breakpoints "));
7067 }
80f8a6eb 7068 breakpoints_changed ();
d6e956e5
VP
7069
7070 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
80f8a6eb 7071 {
c5aa993b 7072 if (from_tty)
d6e956e5
VP
7073 printf_unfiltered ("%d ", b->number);
7074 delete_breakpoint (b);
c906108c 7075 }
80f8a6eb
MS
7076 if (from_tty)
7077 putchar_unfiltered ('\n');
c906108c
SS
7078}
7079\f
7080/* Delete breakpoint in BS if they are `delete' breakpoints and
7081 all breakpoints that are marked for deletion, whether hit or not.
7082 This is called after any breakpoint is hit, or after errors. */
7083
7084void
fba45db2 7085breakpoint_auto_delete (bpstat bs)
c906108c
SS
7086{
7087 struct breakpoint *b, *temp;
7088
7089 for (; bs; bs = bs->next)
20874c92
VP
7090 if (bs->breakpoint_at
7091 && bs->breakpoint_at->owner
7092 && bs->breakpoint_at->owner->disposition == disp_del
c906108c 7093 && bs->stop)
4f8d1dc6 7094 delete_breakpoint (bs->breakpoint_at->owner);
c906108c
SS
7095
7096 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 7097 {
b5de0fa7 7098 if (b->disposition == disp_del_at_next_stop)
c5aa993b
JM
7099 delete_breakpoint (b);
7100 }
c906108c
SS
7101}
7102
f7545552
TT
7103/* A cleanup function which destroys a vector. */
7104
7105static void
7106do_vec_free (void *p)
7107{
7108 VEC(bp_location_p) **vec = p;
7109 if (*vec)
7110 VEC_free (bp_location_p, *vec);
7111}
7112
4cd9bd08 7113/* If SHOULD_INSERT is false, do not insert any breakpoint locations
b60e7edf
PA
7114 into the inferior, only remove already-inserted locations that no
7115 longer should be inserted. Functions that delete a breakpoint or
7116 breakpoints should pass false, so that deleting a breakpoint
7117 doesn't have the side effect of inserting the locations of other
7118 breakpoints that are marked not-inserted, but should_be_inserted
7119 returns true on them.
7120
7121 This behaviour is useful is situations close to tear-down -- e.g.,
7122 after an exec, while the target still has execution, but breakpoint
7123 shadows of the previous executable image should *NOT* be restored
7124 to the new image; or before detaching, where the target still has
7125 execution and wants to delete breakpoints from GDB's lists, and all
7126 breakpoints had already been removed from the inferior. */
7127
0d381245 7128static void
b60e7edf 7129update_global_location_list (int should_insert)
0d381245 7130{
74960c60
VP
7131 struct breakpoint *b;
7132 struct bp_location **next = &bp_location_chain;
7133 struct bp_location *loc;
7134 struct bp_location *loc2;
74960c60
VP
7135 VEC(bp_location_p) *old_locations = NULL;
7136 int ret;
7137 int ix;
f7545552
TT
7138 struct cleanup *cleanups;
7139
7140 cleanups = make_cleanup (do_vec_free, &old_locations);
74960c60
VP
7141 /* Store old locations for future reference. */
7142 for (loc = bp_location_chain; loc; loc = loc->global_next)
7143 VEC_safe_push (bp_location_p, old_locations, loc);
0d381245 7144
74960c60
VP
7145 bp_location_chain = NULL;
7146 ALL_BREAKPOINTS (b)
0d381245 7147 {
74960c60 7148 for (loc = b->loc; loc; loc = loc->next)
0d381245 7149 {
74960c60
VP
7150 *next = loc;
7151 next = &(loc->global_next);
7152 *next = NULL;
0d381245 7153 }
74960c60
VP
7154 }
7155
7156 /* Identify bp_location instances that are no longer present in the new
7157 list, and therefore should be freed. Note that it's not necessary that
7158 those locations should be removed from inferior -- if there's another
7159 location at the same address (previously marked as duplicate),
7160 we don't need to remove/insert the location. */
7161 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
7162 {
7163 /* Tells if 'loc' is found amoung the new locations. If not, we
7164 have to free it. */
7165 int found_object = 0;
20874c92
VP
7166 /* Tells if the location should remain inserted in the target. */
7167 int keep_in_target = 0;
7168 int removed = 0;
74960c60
VP
7169 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7170 if (loc2 == loc)
7171 {
7172 found_object = 1;
7173 break;
7174 }
7175
7176 /* If this location is no longer present, and inserted, look if there's
7177 maybe a new location at the same address. If so, mark that one
7178 inserted, and don't remove this one. This is needed so that we
7179 don't have a time window where a breakpoint at certain location is not
7180 inserted. */
7181
7182 if (loc->inserted)
0d381245 7183 {
74960c60 7184 /* If the location is inserted now, we might have to remove it. */
74960c60
VP
7185
7186 if (found_object && should_be_inserted (loc))
7187 {
7188 /* The location is still present in the location list, and still
7189 should be inserted. Don't do anything. */
20874c92 7190 keep_in_target = 1;
74960c60
VP
7191 }
7192 else
7193 {
7194 /* The location is either no longer present, or got disabled.
7195 See if there's another location at the same address, in which
7196 case we don't need to remove this one from the target. */
7197 if (breakpoint_address_is_meaningful (loc->owner))
7198 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7199 {
7200 /* For the sake of should_insert_location. The
7201 call to check_duplicates will fix up this later. */
7202 loc2->duplicate = 0;
7203 if (should_be_inserted (loc2)
7204 && loc2 != loc && loc2->address == loc->address)
7205 {
7206 loc2->inserted = 1;
7207 loc2->target_info = loc->target_info;
20874c92 7208 keep_in_target = 1;
74960c60
VP
7209 break;
7210 }
7211 }
7212 }
7213
20874c92
VP
7214 if (!keep_in_target)
7215 {
7216 if (remove_breakpoint (loc, mark_uninserted))
7217 {
7218 /* This is just about all we can do. We could keep this
7219 location on the global list, and try to remove it next
7220 time, but there's no particular reason why we will
7221 succeed next time.
7222
7223 Note that at this point, loc->owner is still valid,
7224 as delete_breakpoint frees the breakpoint only
7225 after calling us. */
7226 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7227 loc->owner->number);
7228 }
7229 removed = 1;
7230 }
0d381245 7231 }
74960c60
VP
7232
7233 if (!found_object)
1c5cfe86
PA
7234 {
7235 if (removed && non_stop)
20874c92
VP
7236 {
7237 /* This location was removed from the targets. In non-stop mode,
7238 a race condition is possible where we've removed a breakpoint,
7239 but stop events for that breakpoint are already queued and will
7240 arrive later. To suppress spurious SIGTRAPs reported to user,
7241 we keep this breakpoint location for a bit, and will retire it
7242 after we see 3 * thread_count events.
1c5cfe86 7243 The theory here is that reporting of events should,
20874c92
VP
7244 "on the average", be fair, so after that many event we'll see
7245 events from all threads that have anything of interest, and no
1c5cfe86 7246 longer need to keep this breakpoint. This is just a
20874c92 7247 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
1c5cfe86 7248 which is usability issue, but not a correctness problem. */
20874c92
VP
7249 loc->events_till_retirement = 3 * (thread_count () + 1);
7250 loc->owner = NULL;
20874c92 7251
1c5cfe86
PA
7252 VEC_safe_push (bp_location_p, moribund_locations, loc);
7253 }
7254 else
7255 free_bp_location (loc);
20874c92 7256 }
74960c60 7257 }
1c5cfe86 7258
74960c60
VP
7259 ALL_BREAKPOINTS (b)
7260 {
7261 check_duplicates (b);
0d381245 7262 }
74960c60 7263
50c71eaf 7264 if (breakpoints_always_inserted_mode () && should_insert
c35b1492 7265 && (have_live_inferiors ()
2567c7d9 7266 || (gdbarch_has_global_breakpoints (target_gdbarch))))
74960c60 7267 insert_breakpoint_locations ();
f7545552
TT
7268
7269 do_cleanups (cleanups);
74960c60
VP
7270}
7271
20874c92
VP
7272void
7273breakpoint_retire_moribund (void)
7274{
7275 struct bp_location *loc;
7276 int ix;
7277
7278 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
7279 if (--(loc->events_till_retirement) == 0)
7280 {
7281 free_bp_location (loc);
7282 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
7283 --ix;
7284 }
7285}
7286
74960c60 7287static void
b60e7edf 7288update_global_location_list_nothrow (int inserting)
74960c60
VP
7289{
7290 struct gdb_exception e;
7291 TRY_CATCH (e, RETURN_MASK_ERROR)
b60e7edf 7292 update_global_location_list (inserting);
0d381245
VP
7293}
7294
a474d7c2
PA
7295/* Clear BPT from a BPS. */
7296static void
7297bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt)
7298{
7299 bpstat bs;
7300 for (bs = bps; bs; bs = bs->next)
7301 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7302 {
7303 bs->breakpoint_at = NULL;
7304 bs->old_val = NULL;
7305 /* bs->commands will be freed later. */
7306 }
7307}
7308
7309/* Callback for iterate_over_threads. */
7310static int
7311bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
7312{
7313 struct breakpoint *bpt = data;
7314 bpstat_remove_breakpoint (th->stop_bpstat, bpt);
7315 return 0;
7316}
7317
53a5351d
JM
7318/* Delete a breakpoint and clean up all traces of it in the data
7319 structures. */
c906108c
SS
7320
7321void
fba45db2 7322delete_breakpoint (struct breakpoint *bpt)
c906108c 7323{
52f0bd74 7324 struct breakpoint *b;
74960c60 7325 struct bp_location *loc, *next;
c906108c 7326
8a3fe4f8 7327 gdb_assert (bpt != NULL);
c906108c
SS
7328
7329 /* Has this bp already been deleted? This can happen because multiple
7330 lists can hold pointers to bp's. bpstat lists are especial culprits.
7331
7332 One example of this happening is a watchpoint's scope bp. When the
7333 scope bp triggers, we notice that the watchpoint is out of scope, and
7334 delete it. We also delete its scope bp. But the scope bp is marked
7335 "auto-deleting", and is already on a bpstat. That bpstat is then
7336 checked for auto-deleting bp's, which are deleted.
7337
7338 A real solution to this problem might involve reference counts in bp's,
7339 and/or giving them pointers back to their referencing bpstat's, and
7340 teaching delete_breakpoint to only free a bp's storage when no more
1272ad14 7341 references were extent. A cheaper bandaid was chosen. */
c906108c
SS
7342 if (bpt->type == bp_none)
7343 return;
7344
383f836e 7345 observer_notify_breakpoint_deleted (bpt->number);
c906108c 7346
c906108c
SS
7347 if (breakpoint_chain == bpt)
7348 breakpoint_chain = bpt->next;
7349
c906108c
SS
7350 ALL_BREAKPOINTS (b)
7351 if (b->next == bpt)
c5aa993b
JM
7352 {
7353 b->next = bpt->next;
7354 break;
7355 }
c906108c 7356
c906108c 7357 free_command_lines (&bpt->commands);
c906108c 7358 if (bpt->cond_string != NULL)
b8c9b27d 7359 xfree (bpt->cond_string);
c906108c 7360 if (bpt->addr_string != NULL)
b8c9b27d 7361 xfree (bpt->addr_string);
c906108c 7362 if (bpt->exp != NULL)
b8c9b27d 7363 xfree (bpt->exp);
c906108c 7364 if (bpt->exp_string != NULL)
b8c9b27d 7365 xfree (bpt->exp_string);
c906108c
SS
7366 if (bpt->val != NULL)
7367 value_free (bpt->val);
7368 if (bpt->source_file != NULL)
b8c9b27d 7369 xfree (bpt->source_file);
c906108c 7370 if (bpt->exec_pathname != NULL)
b8c9b27d 7371 xfree (bpt->exec_pathname);
c906108c
SS
7372
7373 /* Be sure no bpstat's are pointing at it after it's been freed. */
7374 /* FIXME, how can we find all bpstat's?
198757a8
VP
7375 We just check stop_bpstat for now. Note that we cannot just
7376 remove bpstats pointing at bpt from the stop_bpstat list
7377 entirely, as breakpoint commands are associated with the bpstat;
7378 if we remove it here, then the later call to
7379 bpstat_do_actions (&stop_bpstat);
7380 in event-top.c won't do anything, and temporary breakpoints
7381 with commands won't work. */
a474d7c2 7382
a474d7c2 7383 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
74960c60
VP
7384
7385 /* Now that breakpoint is removed from breakpoint
7386 list, update the global location list. This
7387 will remove locations that used to belong to
7388 this breakpoint. Do this before freeing
7389 the breakpoint itself, since remove_breakpoint
7390 looks at location's owner. It might be better
7391 design to have location completely self-contained,
7392 but it's not the case now. */
b60e7edf 7393 update_global_location_list (0);
74960c60
VP
7394
7395
c906108c
SS
7396 /* On the chance that someone will soon try again to delete this same
7397 bp, we mark it as deleted before freeing its storage. */
7398 bpt->type = bp_none;
7399
b8c9b27d 7400 xfree (bpt);
c906108c
SS
7401}
7402
4d6140d9
AC
7403static void
7404do_delete_breakpoint_cleanup (void *b)
7405{
7406 delete_breakpoint (b);
7407}
7408
7409struct cleanup *
7410make_cleanup_delete_breakpoint (struct breakpoint *b)
7411{
7412 return make_cleanup (do_delete_breakpoint_cleanup, b);
7413}
7414
c906108c 7415void
fba45db2 7416delete_command (char *arg, int from_tty)
c906108c
SS
7417{
7418 struct breakpoint *b, *temp;
7419
ea9365bb
TT
7420 dont_repeat ();
7421
c906108c
SS
7422 if (arg == 0)
7423 {
7424 int breaks_to_delete = 0;
7425
7426 /* Delete all breakpoints if no argument.
c5aa993b
JM
7427 Do not delete internal or call-dummy breakpoints, these
7428 have to be deleted with an explicit breakpoint number argument. */
7429 ALL_BREAKPOINTS (b)
7430 {
059fb39f
PM
7431 if (b->type != bp_call_dummy
7432 && b->type != bp_shlib_event
7433 && b->type != bp_thread_event
7434 && b->type != bp_overlay_event
7435 && b->number >= 0)
973d738b
DJ
7436 {
7437 breaks_to_delete = 1;
7438 break;
7439 }
c5aa993b 7440 }
c906108c
SS
7441
7442 /* Ask user only if there are some breakpoints to delete. */
7443 if (!from_tty
e2e0b3e5 7444 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
c906108c 7445 {
c5aa993b
JM
7446 ALL_BREAKPOINTS_SAFE (b, temp)
7447 {
059fb39f
PM
7448 if (b->type != bp_call_dummy
7449 && b->type != bp_shlib_event
7450 && b->type != bp_thread_event
7451 && b->type != bp_overlay_event
7452 && b->number >= 0)
c5aa993b
JM
7453 delete_breakpoint (b);
7454 }
c906108c
SS
7455 }
7456 }
7457 else
7458 map_breakpoint_numbers (arg, delete_breakpoint);
7459}
7460
0d381245
VP
7461static int
7462all_locations_are_pending (struct bp_location *loc)
fe3f5fa8 7463{
0d381245
VP
7464 for (; loc; loc = loc->next)
7465 if (!loc->shlib_disabled)
7466 return 0;
7467 return 1;
fe3f5fa8
VP
7468}
7469
776592bf
DE
7470/* Subroutine of update_breakpoint_locations to simplify it.
7471 Return non-zero if multiple fns in list LOC have the same name.
7472 Null names are ignored. */
7473
7474static int
7475ambiguous_names_p (struct bp_location *loc)
7476{
7477 struct bp_location *l;
7478 htab_t htab = htab_create_alloc (13, htab_hash_string,
7479 (int (*) (const void *, const void *)) streq,
7480 NULL, xcalloc, xfree);
7481
7482 for (l = loc; l != NULL; l = l->next)
7483 {
7484 const char **slot;
7485 const char *name = l->function_name;
7486
7487 /* Allow for some names to be NULL, ignore them. */
7488 if (name == NULL)
7489 continue;
7490
7491 slot = (const char **) htab_find_slot (htab, (const void *) name,
7492 INSERT);
7493 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7494 NULL. */
7495 if (*slot != NULL)
7496 {
7497 htab_delete (htab);
7498 return 1;
7499 }
7500 *slot = name;
7501 }
7502
7503 htab_delete (htab);
7504 return 0;
7505}
7506
fe3f5fa8 7507static void
0d381245
VP
7508update_breakpoint_locations (struct breakpoint *b,
7509 struct symtabs_and_lines sals)
fe3f5fa8
VP
7510{
7511 int i;
7512 char *s;
0d381245
VP
7513 struct bp_location *existing_locations = b->loc;
7514
7515 /* If there's no new locations, and all existing locations
7516 are pending, don't do anything. This optimizes
7517 the common case where all locations are in the same
7518 shared library, that was unloaded. We'd like to
7519 retain the location, so that when the library
7520 is loaded again, we don't loose the enabled/disabled
7521 status of the individual locations. */
7522 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
fe3f5fa8
VP
7523 return;
7524
fe3f5fa8
VP
7525 b->loc = NULL;
7526
0d381245 7527 for (i = 0; i < sals.nelts; ++i)
fe3f5fa8 7528 {
0d381245 7529 struct bp_location *new_loc =
39d61571 7530 add_location_to_breakpoint (b, &(sals.sals[i]));
fe3f5fa8 7531
0d381245
VP
7532 /* Reparse conditions, they might contain references to the
7533 old symtab. */
7534 if (b->cond_string != NULL)
7535 {
7536 struct gdb_exception e;
fe3f5fa8 7537
0d381245
VP
7538 s = b->cond_string;
7539 TRY_CATCH (e, RETURN_MASK_ERROR)
7540 {
7541 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7542 0);
7543 }
7544 if (e.reason < 0)
7545 {
7546 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7547 b->number, e.message);
7548 new_loc->enabled = 0;
7549 }
7550 }
fe3f5fa8 7551
0d381245
VP
7552 if (b->source_file != NULL)
7553 xfree (b->source_file);
7554 if (sals.sals[i].symtab == NULL)
7555 b->source_file = NULL;
7556 else
1b36a34b 7557 b->source_file = xstrdup (sals.sals[i].symtab->filename);
fe3f5fa8 7558
0d381245
VP
7559 if (b->line_number == 0)
7560 b->line_number = sals.sals[i].line;
7561 }
fe3f5fa8 7562
514f746b
AR
7563 /* Update locations of permanent breakpoints. */
7564 if (b->enable_state == bp_permanent)
7565 make_breakpoint_permanent (b);
7566
0d381245
VP
7567 /* If possible, carry over 'disable' status from existing breakpoints. */
7568 {
7569 struct bp_location *e = existing_locations;
776592bf
DE
7570 /* If there are multiple breakpoints with the same function name,
7571 e.g. for inline functions, comparing function names won't work.
7572 Instead compare pc addresses; this is just a heuristic as things
7573 may have moved, but in practice it gives the correct answer
7574 often enough until a better solution is found. */
7575 int have_ambiguous_names = ambiguous_names_p (b->loc);
7576
0d381245
VP
7577 for (; e; e = e->next)
7578 {
7579 if (!e->enabled && e->function_name)
7580 {
7581 struct bp_location *l = b->loc;
776592bf
DE
7582 if (have_ambiguous_names)
7583 {
7584 for (; l; l = l->next)
7585 if (e->address == l->address)
7586 {
7587 l->enabled = 0;
7588 break;
7589 }
7590 }
7591 else
7592 {
7593 for (; l; l = l->next)
7594 if (l->function_name
7595 && strcmp (e->function_name, l->function_name) == 0)
7596 {
7597 l->enabled = 0;
7598 break;
7599 }
7600 }
0d381245
VP
7601 }
7602 }
7603 }
fe3f5fa8 7604
b60e7edf 7605 update_global_location_list (1);
fe3f5fa8
VP
7606}
7607
7608
c906108c
SS
7609/* Reset a breakpoint given it's struct breakpoint * BINT.
7610 The value we return ends up being the return value from catch_errors.
7611 Unused in this case. */
7612
7613static int
4efb68b1 7614breakpoint_re_set_one (void *bint)
c906108c 7615{
53a5351d
JM
7616 /* get past catch_errs */
7617 struct breakpoint *b = (struct breakpoint *) bint;
c906108c
SS
7618 struct value *mark;
7619 int i;
fe3f5fa8
VP
7620 int not_found = 0;
7621 int *not_found_ptr = &not_found;
7622 struct symtabs_and_lines sals = {};
ed0616c6 7623 struct symtabs_and_lines expanded;
c906108c 7624 char *s;
b5de0fa7 7625 enum enable_state save_enable;
fe3f5fa8 7626 struct gdb_exception e;
f7545552 7627 struct cleanup *cleanups;
c906108c
SS
7628
7629 switch (b->type)
7630 {
7631 case bp_none:
8a3fe4f8 7632 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
53a5351d 7633 b->number);
c906108c
SS
7634 return 0;
7635 case bp_breakpoint:
7636 case bp_hardware_breakpoint:
1042e4c0 7637 case bp_tracepoint:
c906108c
SS
7638 if (b->addr_string == NULL)
7639 {
7640 /* Anything without a string can't be re-set. */
7641 delete_breakpoint (b);
7642 return 0;
7643 }
c906108c
SS
7644
7645 set_language (b->language);
7646 input_radix = b->input_radix;
7647 s = b->addr_string;
fe3f5fa8 7648 TRY_CATCH (e, RETURN_MASK_ERROR)
c906108c 7649 {
fe3f5fa8
VP
7650 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7651 not_found_ptr);
7652 }
7653 if (e.reason < 0)
7654 {
7655 int not_found_and_ok = 0;
7656 /* For pending breakpoints, it's expected that parsing
7657 will fail until the right shared library is loaded.
7658 User has already told to create pending breakpoints and
7659 don't need extra messages. If breakpoint is in bp_shlib_disabled
7660 state, then user already saw the message about that breakpoint
7661 being disabled, and don't want to see more errors. */
0d381245
VP
7662 if (not_found
7663 && (b->condition_not_parsed
7664 || (b->loc && b->loc->shlib_disabled)
7665 || b->enable_state == bp_disabled))
fe3f5fa8
VP
7666 not_found_and_ok = 1;
7667
7668 if (!not_found_and_ok)
c906108c 7669 {
fe3f5fa8
VP
7670 /* We surely don't want to warn about the same breakpoint
7671 10 times. One solution, implemented here, is disable
7672 the breakpoint on error. Another solution would be to
7673 have separate 'warning emitted' flag. Since this
7674 happens only when a binary has changed, I don't know
7675 which approach is better. */
7676 b->enable_state = bp_disabled;
7677 throw_exception (e);
c906108c 7678 }
fe3f5fa8 7679 }
c906108c 7680
fe3f5fa8
VP
7681 if (not_found)
7682 break;
7683
7684 gdb_assert (sals.nelts == 1);
7685 resolve_sal_pc (&sals.sals[0]);
0d381245 7686 if (b->condition_not_parsed && s && s[0])
fe3f5fa8
VP
7687 {
7688 char *cond_string = 0;
7689 int thread = -1;
4a306c9a
JB
7690 int task = 0;
7691
fe3f5fa8 7692 find_condition_and_thread (s, sals.sals[0].pc,
4a306c9a 7693 &cond_string, &thread, &task);
fe3f5fa8
VP
7694 if (cond_string)
7695 b->cond_string = cond_string;
7696 b->thread = thread;
4a306c9a 7697 b->task = task;
0d381245 7698 b->condition_not_parsed = 0;
fe3f5fa8 7699 }
ed0616c6 7700 expanded = expand_line_sal_maybe (sals.sals[0]);
f7545552 7701 cleanups = make_cleanup (xfree, sals.sals);
ed0616c6 7702 update_breakpoint_locations (b, expanded);
f7545552 7703 do_cleanups (cleanups);
c906108c
SS
7704 break;
7705
7706 case bp_watchpoint:
7707 case bp_hardware_watchpoint:
7708 case bp_read_watchpoint:
7709 case bp_access_watchpoint:
0b3de036
VP
7710 /* Watchpoint can be either on expression using entirely global variables,
7711 or it can be on local variables.
7712
7713 Watchpoints of the first kind are never auto-deleted, and even persist
7714 across program restarts. Since they can use variables from shared
7715 libraries, we need to reparse expression as libraries are loaded
7716 and unloaded.
7717
7718 Watchpoints on local variables can also change meaning as result
7719 of solib event. For example, if a watchpoint uses both a local and
7720 a global variables in expression, it's a local watchpoint, but
7721 unloading of a shared library will make the expression invalid.
7722 This is not a very common use case, but we still re-evaluate
7723 expression, to avoid surprises to the user.
7724
7725 Note that for local watchpoints, we re-evaluate it only if
7726 watchpoints frame id is still valid. If it's not, it means
7727 the watchpoint is out of scope and will be deleted soon. In fact,
7728 I'm not sure we'll ever be called in this case.
7729
7730 If a local watchpoint's frame id is still valid, then
7731 b->exp_valid_block is likewise valid, and we can safely use it.
7732
7733 Don't do anything about disabled watchpoints, since they will
7734 be reevaluated again when enabled. */
a5606eee 7735 update_watchpoint (b, 1 /* reparse */);
c906108c 7736 break;
c5aa993b
JM
7737 /* We needn't really do anything to reset these, since the mask
7738 that requests them is unaffected by e.g., new libraries being
7739 loaded. */
ce78b96d 7740 case bp_catchpoint:
c906108c 7741 break;
c5aa993b 7742
c906108c 7743 default:
a3f17187 7744 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
c906108c 7745 /* fall through */
611c83ae
PA
7746 /* Delete overlay event breakpoints; they will be reset later by
7747 breakpoint_re_set. */
1900040c 7748 case bp_overlay_event:
c906108c
SS
7749 delete_breakpoint (b);
7750 break;
7751
c5aa993b
JM
7752 /* This breakpoint is special, it's set up when the inferior
7753 starts and we really don't want to touch it. */
c906108c
SS
7754 case bp_shlib_event:
7755
c4093a6a
JM
7756 /* Like bp_shlib_event, this breakpoint type is special.
7757 Once it is set up, we do not want to touch it. */
7758 case bp_thread_event:
7759
c5aa993b
JM
7760 /* Keep temporary breakpoints, which can be encountered when we step
7761 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7762 Otherwise these should have been blown away via the cleanup chain
7763 or by breakpoint_init_inferior when we rerun the executable. */
c906108c
SS
7764 case bp_until:
7765 case bp_finish:
7766 case bp_watchpoint_scope:
7767 case bp_call_dummy:
7768 case bp_step_resume:
611c83ae
PA
7769 case bp_longjmp:
7770 case bp_longjmp_resume:
c906108c
SS
7771 break;
7772 }
7773
7774 return 0;
7775}
7776
69de3c6a 7777/* Re-set all breakpoints after symbols have been re-loaded. */
c906108c 7778void
69de3c6a 7779breakpoint_re_set (void)
c906108c
SS
7780{
7781 struct breakpoint *b, *temp;
7782 enum language save_language;
7783 int save_input_radix;
c5aa993b 7784
c906108c
SS
7785 save_language = current_language->la_language;
7786 save_input_radix = input_radix;
7787 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 7788 {
53a5351d 7789 /* Format possible error msg */
fe3f5fa8 7790 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
9ebf4acf
AC
7791 b->number);
7792 struct cleanup *cleanups = make_cleanup (xfree, message);
c5aa993b 7793 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
9ebf4acf 7794 do_cleanups (cleanups);
c5aa993b 7795 }
c906108c
SS
7796 set_language (save_language);
7797 input_radix = save_input_radix;
e62c965a 7798
69de3c6a 7799 create_overlay_event_breakpoint ("_ovly_debug_event");
c906108c
SS
7800}
7801\f
c906108c
SS
7802/* Reset the thread number of this breakpoint:
7803
7804 - If the breakpoint is for all threads, leave it as-is.
39f77062 7805 - Else, reset it to the current thread for inferior_ptid. */
c906108c 7806void
fba45db2 7807breakpoint_re_set_thread (struct breakpoint *b)
c906108c
SS
7808{
7809 if (b->thread != -1)
7810 {
39f77062
KB
7811 if (in_thread_list (inferior_ptid))
7812 b->thread = pid_to_thread_id (inferior_ptid);
c906108c
SS
7813 }
7814}
7815
03ac34d5
MS
7816/* Set ignore-count of breakpoint number BPTNUM to COUNT.
7817 If from_tty is nonzero, it prints a message to that effect,
7818 which ends with a period (no newline). */
7819
c906108c 7820void
fba45db2 7821set_ignore_count (int bptnum, int count, int from_tty)
c906108c 7822{
52f0bd74 7823 struct breakpoint *b;
c906108c
SS
7824
7825 if (count < 0)
7826 count = 0;
7827
7828 ALL_BREAKPOINTS (b)
7829 if (b->number == bptnum)
c5aa993b
JM
7830 {
7831 b->ignore_count = count;
221ea385
KS
7832 if (from_tty)
7833 {
7834 if (count == 0)
a3f17187 7835 printf_filtered (_("Will stop next time breakpoint %d is reached."),
221ea385
KS
7836 bptnum);
7837 else if (count == 1)
a3f17187 7838 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
221ea385
KS
7839 bptnum);
7840 else
a3f17187 7841 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
221ea385
KS
7842 count, bptnum);
7843 }
c5aa993b 7844 breakpoints_changed ();
383f836e 7845 observer_notify_breakpoint_modified (b->number);
c5aa993b
JM
7846 return;
7847 }
c906108c 7848
8a3fe4f8 7849 error (_("No breakpoint number %d."), bptnum);
c906108c
SS
7850}
7851
b2175913
MS
7852void
7853make_breakpoint_silent (struct breakpoint *b)
7854{
7855 /* Silence the breakpoint. */
7856 b->silent = 1;
7857}
7858
c906108c
SS
7859/* Command to set ignore-count of breakpoint N to COUNT. */
7860
7861static void
fba45db2 7862ignore_command (char *args, int from_tty)
c906108c
SS
7863{
7864 char *p = args;
52f0bd74 7865 int num;
c906108c
SS
7866
7867 if (p == 0)
e2e0b3e5 7868 error_no_arg (_("a breakpoint number"));
c5aa993b 7869
c906108c 7870 num = get_number (&p);
5c44784c 7871 if (num == 0)
8a3fe4f8 7872 error (_("bad breakpoint number: '%s'"), args);
c906108c 7873 if (*p == 0)
8a3fe4f8 7874 error (_("Second argument (specified ignore-count) is missing."));
c906108c
SS
7875
7876 set_ignore_count (num,
7877 longest_to_int (value_as_long (parse_and_eval (p))),
7878 from_tty);
221ea385
KS
7879 if (from_tty)
7880 printf_filtered ("\n");
c906108c
SS
7881}
7882\f
7883/* Call FUNCTION on each of the breakpoints
7884 whose numbers are given in ARGS. */
7885
7886static void
831662b3 7887map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
c906108c 7888{
52f0bd74 7889 char *p = args;
c906108c 7890 char *p1;
52f0bd74
AC
7891 int num;
7892 struct breakpoint *b, *tmp;
11cf8741 7893 int match;
c906108c
SS
7894
7895 if (p == 0)
e2e0b3e5 7896 error_no_arg (_("one or more breakpoint numbers"));
c906108c
SS
7897
7898 while (*p)
7899 {
11cf8741 7900 match = 0;
c906108c 7901 p1 = p;
c5aa993b 7902
5c44784c
JM
7903 num = get_number_or_range (&p1);
7904 if (num == 0)
c5aa993b 7905 {
8a3fe4f8 7906 warning (_("bad breakpoint number at or near '%s'"), p);
5c44784c
JM
7907 }
7908 else
7909 {
7910 ALL_BREAKPOINTS_SAFE (b, tmp)
7911 if (b->number == num)
7912 {
7913 struct breakpoint *related_breakpoint = b->related_breakpoint;
11cf8741 7914 match = 1;
5c44784c
JM
7915 function (b);
7916 if (related_breakpoint)
7917 function (related_breakpoint);
11cf8741 7918 break;
5c44784c 7919 }
11cf8741 7920 if (match == 0)
a3f17187 7921 printf_unfiltered (_("No breakpoint number %d.\n"), num);
c5aa993b 7922 }
c906108c
SS
7923 p = p1;
7924 }
7925}
7926
0d381245
VP
7927static struct bp_location *
7928find_location_by_number (char *number)
7929{
7930 char *dot = strchr (number, '.');
7931 char *p1;
7932 int bp_num;
7933 int loc_num;
7934 struct breakpoint *b;
7935 struct bp_location *loc;
7936
7937 *dot = '\0';
7938
7939 p1 = number;
7940 bp_num = get_number_or_range (&p1);
7941 if (bp_num == 0)
7942 error (_("Bad breakpoint number '%s'"), number);
7943
7944 ALL_BREAKPOINTS (b)
7945 if (b->number == bp_num)
7946 {
7947 break;
7948 }
7949
7950 if (!b || b->number != bp_num)
7951 error (_("Bad breakpoint number '%s'"), number);
7952
7953 p1 = dot+1;
7954 loc_num = get_number_or_range (&p1);
7955 if (loc_num == 0)
7956 error (_("Bad breakpoint location number '%s'"), number);
7957
7958 --loc_num;
7959 loc = b->loc;
7960 for (;loc_num && loc; --loc_num, loc = loc->next)
7961 ;
7962 if (!loc)
7963 error (_("Bad breakpoint location number '%s'"), dot+1);
7964
7965 return loc;
7966}
7967
7968
1900040c
MS
7969/* Set ignore-count of breakpoint number BPTNUM to COUNT.
7970 If from_tty is nonzero, it prints a message to that effect,
7971 which ends with a period (no newline). */
7972
c906108c 7973void
fba45db2 7974disable_breakpoint (struct breakpoint *bpt)
c906108c
SS
7975{
7976 /* Never disable a watchpoint scope breakpoint; we want to
7977 hit them when we leave scope so we can delete both the
7978 watchpoint and its scope breakpoint at that time. */
7979 if (bpt->type == bp_watchpoint_scope)
7980 return;
7981
c2c6d25f 7982 /* You can't disable permanent breakpoints. */
b5de0fa7 7983 if (bpt->enable_state == bp_permanent)
c2c6d25f
JM
7984 return;
7985
b5de0fa7 7986 bpt->enable_state = bp_disabled;
c906108c 7987
b60e7edf 7988 update_global_location_list (0);
c906108c 7989
383f836e 7990 observer_notify_breakpoint_modified (bpt->number);
c906108c
SS
7991}
7992
c906108c 7993static void
fba45db2 7994disable_command (char *args, int from_tty)
c906108c 7995{
52f0bd74 7996 struct breakpoint *bpt;
c906108c
SS
7997 if (args == 0)
7998 ALL_BREAKPOINTS (bpt)
7999 switch (bpt->type)
c5aa993b
JM
8000 {
8001 case bp_none:
8a3fe4f8 8002 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
53a5351d 8003 bpt->number);
c5aa993b
JM
8004 continue;
8005 case bp_breakpoint:
1042e4c0 8006 case bp_tracepoint:
ce78b96d 8007 case bp_catchpoint:
c5aa993b
JM
8008 case bp_hardware_breakpoint:
8009 case bp_watchpoint:
8010 case bp_hardware_watchpoint:
8011 case bp_read_watchpoint:
8012 case bp_access_watchpoint:
8013 disable_breakpoint (bpt);
8014 default:
8015 continue;
8016 }
0d381245
VP
8017 else if (strchr (args, '.'))
8018 {
8019 struct bp_location *loc = find_location_by_number (args);
8020 if (loc)
8021 loc->enabled = 0;
b60e7edf 8022 update_global_location_list (0);
0d381245 8023 }
c906108c
SS
8024 else
8025 map_breakpoint_numbers (args, disable_breakpoint);
8026}
8027
8028static void
fba45db2 8029do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
c906108c 8030{
c906108c
SS
8031 int target_resources_ok, other_type_used;
8032 struct value *mark;
8033
8034 if (bpt->type == bp_hardware_breakpoint)
8035 {
8036 int i;
c5aa993b 8037 i = hw_breakpoint_used_count ();
53a5351d 8038 target_resources_ok =
d92524f1 8039 target_can_use_hardware_watchpoint (bp_hardware_breakpoint,
53a5351d 8040 i + 1, 0);
c906108c 8041 if (target_resources_ok == 0)
8a3fe4f8 8042 error (_("No hardware breakpoint support in the target."));
c906108c 8043 else if (target_resources_ok < 0)
8a3fe4f8 8044 error (_("Hardware breakpoints used exceeds limit."));
c906108c
SS
8045 }
8046
059fb39f
PM
8047 if (bpt->type == bp_watchpoint
8048 || bpt->type == bp_hardware_watchpoint
8049 || bpt->type == bp_read_watchpoint
8050 || bpt->type == bp_access_watchpoint)
c906108c 8051 {
dde02812
ES
8052 struct gdb_exception e;
8053
8054 TRY_CATCH (e, RETURN_MASK_ALL)
c906108c 8055 {
dde02812 8056 update_watchpoint (bpt, 1 /* reparse */);
c906108c 8057 }
dde02812 8058 if (e.reason < 0)
c5aa993b 8059 {
dde02812
ES
8060 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
8061 bpt->number);
8062 return;
c5aa993b 8063 }
c906108c 8064 }
0101ce28 8065
b4c291bb
KH
8066 if (bpt->enable_state != bp_permanent)
8067 bpt->enable_state = bp_enabled;
8068 bpt->disposition = disposition;
b60e7edf 8069 update_global_location_list (1);
b4c291bb
KH
8070 breakpoints_changed ();
8071
383f836e 8072 observer_notify_breakpoint_modified (bpt->number);
c906108c
SS
8073}
8074
fe3f5fa8 8075
c906108c 8076void
fba45db2 8077enable_breakpoint (struct breakpoint *bpt)
c906108c
SS
8078{
8079 do_enable_breakpoint (bpt, bpt->disposition);
8080}
8081
8082/* The enable command enables the specified breakpoints (or all defined
8083 breakpoints) so they once again become (or continue to be) effective
1272ad14 8084 in stopping the inferior. */
c906108c 8085
c906108c 8086static void
fba45db2 8087enable_command (char *args, int from_tty)
c906108c 8088{
52f0bd74 8089 struct breakpoint *bpt;
c906108c
SS
8090 if (args == 0)
8091 ALL_BREAKPOINTS (bpt)
8092 switch (bpt->type)
c5aa993b
JM
8093 {
8094 case bp_none:
8a3fe4f8 8095 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
53a5351d 8096 bpt->number);
c5aa993b
JM
8097 continue;
8098 case bp_breakpoint:
1042e4c0 8099 case bp_tracepoint:
ce78b96d 8100 case bp_catchpoint:
c5aa993b
JM
8101 case bp_hardware_breakpoint:
8102 case bp_watchpoint:
8103 case bp_hardware_watchpoint:
8104 case bp_read_watchpoint:
8105 case bp_access_watchpoint:
8106 enable_breakpoint (bpt);
8107 default:
8108 continue;
8109 }
0d381245
VP
8110 else if (strchr (args, '.'))
8111 {
8112 struct bp_location *loc = find_location_by_number (args);
8113 if (loc)
8114 loc->enabled = 1;
b60e7edf 8115 update_global_location_list (1);
0d381245 8116 }
c906108c
SS
8117 else
8118 map_breakpoint_numbers (args, enable_breakpoint);
8119}
8120
8121static void
fba45db2 8122enable_once_breakpoint (struct breakpoint *bpt)
c906108c 8123{
b5de0fa7 8124 do_enable_breakpoint (bpt, disp_disable);
c906108c
SS
8125}
8126
c906108c 8127static void
fba45db2 8128enable_once_command (char *args, int from_tty)
c906108c
SS
8129{
8130 map_breakpoint_numbers (args, enable_once_breakpoint);
8131}
8132
8133static void
fba45db2 8134enable_delete_breakpoint (struct breakpoint *bpt)
c906108c 8135{
b5de0fa7 8136 do_enable_breakpoint (bpt, disp_del);
c906108c
SS
8137}
8138
c906108c 8139static void
fba45db2 8140enable_delete_command (char *args, int from_tty)
c906108c
SS
8141{
8142 map_breakpoint_numbers (args, enable_delete_breakpoint);
8143}
8144\f
fa8d40ab
JJ
8145static void
8146set_breakpoint_cmd (char *args, int from_tty)
8147{
8148}
8149
8150static void
8151show_breakpoint_cmd (char *args, int from_tty)
8152{
8153}
8154
c906108c
SS
8155/* Use default_breakpoint_'s, or nothing if they aren't valid. */
8156
8157struct symtabs_and_lines
fba45db2 8158decode_line_spec_1 (char *string, int funfirstline)
c906108c
SS
8159{
8160 struct symtabs_and_lines sals;
8161 if (string == 0)
8a3fe4f8 8162 error (_("Empty line specification."));
c906108c
SS
8163 if (default_breakpoint_valid)
8164 sals = decode_line_1 (&string, funfirstline,
53a5351d
JM
8165 default_breakpoint_symtab,
8166 default_breakpoint_line,
68219205 8167 (char ***) NULL, NULL);
c906108c
SS
8168 else
8169 sals = decode_line_1 (&string, funfirstline,
68219205 8170 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
c906108c 8171 if (*string)
8a3fe4f8 8172 error (_("Junk at end of line specification: %s"), string);
c906108c
SS
8173 return sals;
8174}
8181d85f
DJ
8175
8176/* Create and insert a raw software breakpoint at PC. Return an
8177 identifier, which should be used to remove the breakpoint later.
8178 In general, places which call this should be using something on the
8179 breakpoint chain instead; this function should be eliminated
8180 someday. */
8181
8182void *
8183deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8184{
8185 struct bp_target_info *bp_tgt;
8186
8187 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8188 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8189
8190 bp_tgt->placed_address = pc;
8191 if (target_insert_breakpoint (bp_tgt) != 0)
8192 {
8193 /* Could not insert the breakpoint. */
8194 xfree (bp_tgt);
8195 return NULL;
8196 }
8197
8198 return bp_tgt;
8199}
8200
8201/* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8202
8203int
8204deprecated_remove_raw_breakpoint (void *bp)
8205{
8206 struct bp_target_info *bp_tgt = bp;
8207 int ret;
8208
8209 ret = target_remove_breakpoint (bp_tgt);
8210 xfree (bp_tgt);
8211
8212 return ret;
8213}
8214
8215/* One (or perhaps two) breakpoints used for software single stepping. */
8216
8217static void *single_step_breakpoints[2];
8218
8219/* Create and insert a breakpoint for software single step. */
8220
8221void
8222insert_single_step_breakpoint (CORE_ADDR next_pc)
8223{
8224 void **bpt_p;
8225
8226 if (single_step_breakpoints[0] == NULL)
8227 bpt_p = &single_step_breakpoints[0];
8228 else
8229 {
8230 gdb_assert (single_step_breakpoints[1] == NULL);
8231 bpt_p = &single_step_breakpoints[1];
8232 }
8233
8234 /* NOTE drow/2006-04-11: A future improvement to this function would be
8235 to only create the breakpoints once, and actually put them on the
8236 breakpoint chain. That would let us use set_raw_breakpoint. We could
8237 adjust the addresses each time they were needed. Doing this requires
8238 corresponding changes elsewhere where single step breakpoints are
8239 handled, however. So, for now, we use this. */
8240
8241 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8242 if (*bpt_p == NULL)
1893a4c0 8243 error (_("Could not insert single-step breakpoint at 0x%s"),
8181d85f
DJ
8244 paddr_nz (next_pc));
8245}
8246
8247/* Remove and delete any breakpoints used for software single step. */
8248
8249void
8250remove_single_step_breakpoints (void)
8251{
8252 gdb_assert (single_step_breakpoints[0] != NULL);
8253
8254 /* See insert_single_step_breakpoint for more about this deprecated
8255 call. */
8256 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8257 single_step_breakpoints[0] = NULL;
8258
8259 if (single_step_breakpoints[1] != NULL)
8260 {
8261 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8262 single_step_breakpoints[1] = NULL;
8263 }
8264}
8265
1aafd4da
UW
8266/* Check whether a software single-step breakpoint is inserted at PC. */
8267
8268static int
8269single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8270{
8271 int i;
8272
8273 for (i = 0; i < 2; i++)
8274 {
8275 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8276 if (bp_tgt && bp_tgt->placed_address == pc)
8277 return 1;
8278 }
8279
8280 return 0;
8281}
8282
1042e4c0
SS
8283/* Tracepoint-specific operations. */
8284
8285/* Set tracepoint count to NUM. */
8286static void
8287set_tracepoint_count (int num)
8288{
8289 tracepoint_count = num;
4fa62494 8290 set_internalvar_integer (lookup_internalvar ("tpnum"), num);
1042e4c0
SS
8291}
8292
8293void
8294trace_command (char *arg, int from_tty)
8295{
8296 break_command_really (arg,
8297 NULL, 0, 1 /* parse arg */,
8298 0 /* tempflag */, 0 /* hardwareflag */,
8299 1 /* traceflag */,
8300 0 /* Ignore count */,
8301 pending_break_support,
8302 NULL,
8303 from_tty,
8304 1 /* enabled */);
8305 set_tracepoint_count (breakpoint_count);
8306}
8307
8308/* Print information on tracepoint number TPNUM_EXP, or all if
8309 omitted. */
8310
8311static void
8312tracepoints_info (char *tpnum_exp, int from_tty)
8313{
8314 struct breakpoint *b;
8315 int tps_to_list = 0;
8316
8317 /* In the no-arguments case, say "No tracepoints" if none found. */
8318 if (tpnum_exp == 0)
8319 {
8320 ALL_TRACEPOINTS (b)
8321 {
8322 if (b->number >= 0)
8323 {
8324 tps_to_list = 1;
8325 break;
8326 }
8327 }
8328 if (!tps_to_list)
8329 {
8330 ui_out_message (uiout, 0, "No tracepoints.\n");
8331 return;
8332 }
8333 }
8334
8335 /* Otherwise be the same as "info break". */
8336 breakpoints_info (tpnum_exp, from_tty);
8337}
8338
8339/* The 'enable trace' command enables tracepoints.
8340 Not supported by all targets. */
8341static void
8342enable_trace_command (char *args, int from_tty)
8343{
8344 enable_command (args, from_tty);
8345}
8346
8347/* The 'disable trace' command disables tracepoints.
8348 Not supported by all targets. */
8349static void
8350disable_trace_command (char *args, int from_tty)
8351{
8352 disable_command (args, from_tty);
8353}
8354
8355/* Remove a tracepoint (or all if no argument) */
8356static void
8357delete_trace_command (char *arg, int from_tty)
8358{
8359 struct breakpoint *b, *temp;
8360
8361 dont_repeat ();
8362
8363 if (arg == 0)
8364 {
8365 int breaks_to_delete = 0;
8366
8367 /* Delete all breakpoints if no argument.
8368 Do not delete internal or call-dummy breakpoints, these
8369 have to be deleted with an explicit breakpoint number argument. */
8370 ALL_TRACEPOINTS (b)
8371 {
8372 if (b->number >= 0)
8373 {
8374 breaks_to_delete = 1;
8375 break;
8376 }
8377 }
8378
8379 /* Ask user only if there are some breakpoints to delete. */
8380 if (!from_tty
8381 || (breaks_to_delete && query (_("Delete all tracepoints? "))))
8382 {
8383 ALL_BREAKPOINTS_SAFE (b, temp)
8384 {
059fb39f
PM
8385 if (b->type == bp_tracepoint
8386 && b->number >= 0)
1042e4c0
SS
8387 delete_breakpoint (b);
8388 }
8389 }
8390 }
8391 else
8392 map_breakpoint_numbers (arg, delete_breakpoint);
8393}
8394
8395/* Set passcount for tracepoint.
8396
8397 First command argument is passcount, second is tracepoint number.
8398 If tracepoint number omitted, apply to most recently defined.
8399 Also accepts special argument "all". */
8400
8401static void
8402trace_pass_command (char *args, int from_tty)
8403{
8404 struct breakpoint *t1 = (struct breakpoint *) -1, *t2;
8405 unsigned int count;
8406 int all = 0;
8407
8408 if (args == 0 || *args == 0)
8409 error (_("passcount command requires an argument (count + optional TP num)"));
8410
8411 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */
8412
8413 while (*args && isspace ((int) *args))
8414 args++;
8415
8416 if (*args && strncasecmp (args, "all", 3) == 0)
8417 {
8418 args += 3; /* Skip special argument "all". */
8419 all = 1;
8420 if (*args)
8421 error (_("Junk at end of arguments."));
8422 }
8423 else
8424 t1 = get_tracepoint_by_number (&args, 1, 1);
8425
8426 do
8427 {
8428 if (t1)
8429 {
8430 ALL_TRACEPOINTS (t2)
8431 if (t1 == (struct breakpoint *) -1 || t1 == t2)
8432 {
8433 t2->pass_count = count;
8434 observer_notify_tracepoint_modified (t2->number);
8435 if (from_tty)
8436 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
8437 t2->number, count);
8438 }
8439 if (! all && *args)
8440 t1 = get_tracepoint_by_number (&args, 1, 0);
8441 }
8442 }
8443 while (*args);
8444}
8445
8446struct breakpoint *
8447get_tracepoint (int num)
8448{
8449 struct breakpoint *t;
8450
8451 ALL_TRACEPOINTS (t)
8452 if (t->number == num)
8453 return t;
8454
8455 return NULL;
8456}
8457
8458/* Utility: parse a tracepoint number and look it up in the list.
8459 If MULTI_P is true, there might be a range of tracepoints in ARG.
8460 if OPTIONAL_P is true, then if the argument is missing, the most
8461 recent tracepoint (tracepoint_count) is returned. */
8462struct breakpoint *
8463get_tracepoint_by_number (char **arg, int multi_p, int optional_p)
8464{
8465 extern int tracepoint_count;
8466 struct breakpoint *t;
8467 int tpnum;
8468 char *instring = arg == NULL ? NULL : *arg;
8469
8470 if (arg == NULL || *arg == NULL || ! **arg)
8471 {
8472 if (optional_p)
8473 tpnum = tracepoint_count;
8474 else
8475 error_no_arg (_("tracepoint number"));
8476 }
8477 else
8478 tpnum = multi_p ? get_number_or_range (arg) : get_number (arg);
8479
8480 if (tpnum <= 0)
8481 {
8482 if (instring && *instring)
8483 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
8484 instring);
8485 else
8486 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
8487 return NULL;
8488 }
8489
8490 ALL_TRACEPOINTS (t)
8491 if (t->number == tpnum)
8492 {
8493 return t;
8494 }
8495
8496 /* FIXME: if we are in the middle of a range we don't want to give
8497 a message. The current interface to get_number_or_range doesn't
8498 allow us to discover this. */
8499 printf_unfiltered ("No tracepoint number %d.\n", tpnum);
8500 return NULL;
8501}
8502
8503/* save-tracepoints command */
8504static void
8505tracepoint_save_command (char *args, int from_tty)
8506{
8507 struct breakpoint *tp;
8508 int any_tp = 0;
8509 struct action_line *line;
8510 FILE *fp;
8511 char *i1 = " ", *i2 = " ";
8512 char *indent, *actionline, *pathname;
8513 char tmp[40];
8514 struct cleanup *cleanup;
8515
8516 if (args == 0 || *args == 0)
8517 error (_("Argument required (file name in which to save tracepoints)"));
8518
8519 /* See if we have anything to save. */
8520 ALL_TRACEPOINTS (tp)
8521 {
8522 any_tp = 1;
8523 break;
8524 }
8525 if (!any_tp)
8526 {
8527 warning (_("save-tracepoints: no tracepoints to save."));
8528 return;
8529 }
8530
8531 pathname = tilde_expand (args);
8532 cleanup = make_cleanup (xfree, pathname);
059fb39f
PM
8533 fp = fopen (pathname, "w");
8534 if (!fp)
1042e4c0
SS
8535 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
8536 args, safe_strerror (errno));
8537 make_cleanup_fclose (fp);
8538
8539 ALL_TRACEPOINTS (tp)
8540 {
8541 if (tp->addr_string)
8542 fprintf (fp, "trace %s\n", tp->addr_string);
8543 else
8544 {
8545 sprintf_vma (tmp, tp->loc->address);
8546 fprintf (fp, "trace *0x%s\n", tmp);
8547 }
8548
8549 if (tp->pass_count)
8550 fprintf (fp, " passcount %d\n", tp->pass_count);
8551
8552 if (tp->actions)
8553 {
8554 fprintf (fp, " actions\n");
8555 indent = i1;
8556 for (line = tp->actions; line; line = line->next)
8557 {
8558 struct cmd_list_element *cmd;
8559
8560 QUIT; /* allow user to bail out with ^C */
8561 actionline = line->action;
8562 while (isspace ((int) *actionline))
8563 actionline++;
8564
8565 fprintf (fp, "%s%s\n", indent, actionline);
8566 if (*actionline != '#') /* skip for comment lines */
8567 {
8568 cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1);
8569 if (cmd == 0)
8570 error (_("Bad action list item: %s"), actionline);
8571 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
8572 indent = i2;
8573 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
8574 indent = i1;
8575 }
8576 }
8577 }
8578 }
8579 do_cleanups (cleanup);
8580 if (from_tty)
8581 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args);
8582 return;
8583}
8584
8585/* Create a vector of all tracepoints. */
8586
8587VEC(breakpoint_p) *
8588all_tracepoints ()
8589{
8590 VEC(breakpoint_p) *tp_vec = 0;
8591 struct breakpoint *tp;
8592
8593 ALL_TRACEPOINTS (tp)
8594 {
8595 VEC_safe_push (breakpoint_p, tp_vec, tp);
8596 }
8597
8598 return tp_vec;
8599}
8600
c906108c 8601\f
31e2b00f
AS
8602/* This help string is used for the break, hbreak, tbreak and thbreak commands.
8603 It is defined as a macro to prevent duplication.
8604 COMMAND should be a string constant containing the name of the command. */
8605#define BREAK_ARGS_HELP(command) \
8606command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8607LOCATION may be a line number, function name, or \"*\" and an address.\n\
8608If a line number is specified, break at start of code for that line.\n\
8609If a function is specified, break at start of code for that function.\n\
8610If an address is specified, break at that exact address.\n\
8611With no LOCATION, uses current execution address of selected stack frame.\n\
8612This is useful for breaking on return to a stack frame.\n\
8613\n\
8614THREADNUM is the number from \"info threads\".\n\
8615CONDITION is a boolean expression.\n\
8616\n\
8617Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8618\n\
8619Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8620
44feb3ce
TT
8621/* List of subcommands for "catch". */
8622static struct cmd_list_element *catch_cmdlist;
8623
8624/* List of subcommands for "tcatch". */
8625static struct cmd_list_element *tcatch_cmdlist;
8626
8627/* Like add_cmd, but add the command to both the "catch" and "tcatch"
8628 lists, and pass some additional user data to the command function. */
8629static void
8630add_catch_command (char *name, char *docstring,
8631 void (*sfunc) (char *args, int from_tty,
8632 struct cmd_list_element *command),
8633 void *user_data_catch,
8634 void *user_data_tcatch)
8635{
8636 struct cmd_list_element *command;
8637
8638 command = add_cmd (name, class_breakpoint, NULL, docstring,
8639 &catch_cmdlist);
8640 set_cmd_sfunc (command, sfunc);
8641 set_cmd_context (command, user_data_catch);
8642
8643 command = add_cmd (name, class_breakpoint, NULL, docstring,
8644 &tcatch_cmdlist);
8645 set_cmd_sfunc (command, sfunc);
8646 set_cmd_context (command, user_data_tcatch);
8647}
8648
c906108c 8649void
fba45db2 8650_initialize_breakpoint (void)
c906108c 8651{
fa8d40ab
JJ
8652 static struct cmd_list_element *breakpoint_set_cmdlist;
8653 static struct cmd_list_element *breakpoint_show_cmdlist;
c906108c
SS
8654 struct cmd_list_element *c;
8655
84acb35a 8656 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
84acb35a 8657
c906108c
SS
8658 breakpoint_chain = 0;
8659 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8660 before a breakpoint is set. */
8661 breakpoint_count = 0;
8662
1042e4c0
SS
8663 tracepoint_count = 0;
8664
1bedd215
AC
8665 add_com ("ignore", class_breakpoint, ignore_command, _("\
8666Set ignore-count of breakpoint number N to COUNT.\n\
8667Usage is `ignore N COUNT'."));
c906108c 8668 if (xdb_commands)
c5aa993b 8669 add_com_alias ("bc", "ignore", class_breakpoint, 1);
c906108c 8670
1bedd215
AC
8671 add_com ("commands", class_breakpoint, commands_command, _("\
8672Set commands to be executed when a breakpoint is hit.\n\
c906108c
SS
8673Give breakpoint number as argument after \"commands\".\n\
8674With no argument, the targeted breakpoint is the last one set.\n\
8675The commands themselves follow starting on the next line.\n\
8676Type a line containing \"end\" to indicate the end of them.\n\
8677Give \"silent\" as the first line to make the breakpoint silent;\n\
1bedd215 8678then no output is printed when it is hit, except what the commands print."));
c906108c 8679
1bedd215
AC
8680 add_com ("condition", class_breakpoint, condition_command, _("\
8681Specify breakpoint number N to break only if COND is true.\n\
c906108c 8682Usage is `condition N COND', where N is an integer and COND is an\n\
1bedd215 8683expression to be evaluated whenever breakpoint N is reached."));
c906108c 8684
1bedd215 8685 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
31e2b00f 8686Set a temporary breakpoint.\n\
c906108c
SS
8687Like \"break\" except the breakpoint is only temporary,\n\
8688so it will be deleted when hit. Equivalent to \"break\" followed\n\
31e2b00f
AS
8689by using \"enable delete\" on the breakpoint number.\n\
8690\n"
8691BREAK_ARGS_HELP ("tbreak")));
5ba2abeb 8692 set_cmd_completer (c, location_completer);
c94fdfd0 8693
1bedd215 8694 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
31e2b00f 8695Set a hardware assisted breakpoint.\n\
c906108c 8696Like \"break\" except the breakpoint requires hardware support,\n\
31e2b00f
AS
8697some target hardware may not have this support.\n\
8698\n"
8699BREAK_ARGS_HELP ("hbreak")));
5ba2abeb 8700 set_cmd_completer (c, location_completer);
c906108c 8701
1bedd215 8702 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
31e2b00f 8703Set a temporary hardware assisted breakpoint.\n\
c906108c 8704Like \"hbreak\" except the breakpoint is only temporary,\n\
31e2b00f
AS
8705so it will be deleted when hit.\n\
8706\n"
8707BREAK_ARGS_HELP ("thbreak")));
5ba2abeb 8708 set_cmd_completer (c, location_completer);
c906108c 8709
1bedd215
AC
8710 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8711Enable some breakpoints.\n\
c906108c
SS
8712Give breakpoint numbers (separated by spaces) as arguments.\n\
8713With no subcommand, breakpoints are enabled until you command otherwise.\n\
8714This is used to cancel the effect of the \"disable\" command.\n\
1bedd215 8715With a subcommand you can enable temporarily."),
c906108c
SS
8716 &enablelist, "enable ", 1, &cmdlist);
8717 if (xdb_commands)
1bedd215
AC
8718 add_com ("ab", class_breakpoint, enable_command, _("\
8719Enable some breakpoints.\n\
c906108c
SS
8720Give breakpoint numbers (separated by spaces) as arguments.\n\
8721With no subcommand, breakpoints are enabled until you command otherwise.\n\
8722This is used to cancel the effect of the \"disable\" command.\n\
1bedd215 8723With a subcommand you can enable temporarily."));
c906108c
SS
8724
8725 add_com_alias ("en", "enable", class_breakpoint, 1);
8726
1bedd215
AC
8727 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8728Enable some breakpoints.\n\
c906108c
SS
8729Give breakpoint numbers (separated by spaces) as arguments.\n\
8730This is used to cancel the effect of the \"disable\" command.\n\
1bedd215 8731May be abbreviated to simply \"enable\".\n"),
c5aa993b 8732 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
c906108c 8733
1a966eab
AC
8734 add_cmd ("once", no_class, enable_once_command, _("\
8735Enable breakpoints for one hit. Give breakpoint numbers.\n\
8736If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
c906108c
SS
8737 &enablebreaklist);
8738
1a966eab
AC
8739 add_cmd ("delete", no_class, enable_delete_command, _("\
8740Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8741If a breakpoint is hit while enabled in this fashion, it is deleted."),
c906108c
SS
8742 &enablebreaklist);
8743
1a966eab
AC
8744 add_cmd ("delete", no_class, enable_delete_command, _("\
8745Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8746If a breakpoint is hit while enabled in this fashion, it is deleted."),
c906108c
SS
8747 &enablelist);
8748
1a966eab
AC
8749 add_cmd ("once", no_class, enable_once_command, _("\
8750Enable breakpoints for one hit. Give breakpoint numbers.\n\
8751If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
c906108c
SS
8752 &enablelist);
8753
1bedd215
AC
8754 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8755Disable some breakpoints.\n\
c906108c
SS
8756Arguments are breakpoint numbers with spaces in between.\n\
8757To disable all breakpoints, give no argument.\n\
1bedd215 8758A disabled breakpoint is not forgotten, but has no effect until reenabled."),
c906108c
SS
8759 &disablelist, "disable ", 1, &cmdlist);
8760 add_com_alias ("dis", "disable", class_breakpoint, 1);
8761 add_com_alias ("disa", "disable", class_breakpoint, 1);
8762 if (xdb_commands)
1bedd215
AC
8763 add_com ("sb", class_breakpoint, disable_command, _("\
8764Disable some breakpoints.\n\
c906108c
SS
8765Arguments are breakpoint numbers with spaces in between.\n\
8766To disable all breakpoints, give no argument.\n\
1bedd215 8767A disabled breakpoint is not forgotten, but has no effect until reenabled."));
c906108c 8768
1a966eab
AC
8769 add_cmd ("breakpoints", class_alias, disable_command, _("\
8770Disable some breakpoints.\n\
c906108c
SS
8771Arguments are breakpoint numbers with spaces in between.\n\
8772To disable all breakpoints, give no argument.\n\
8773A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
1a966eab 8774This command may be abbreviated \"disable\"."),
c906108c
SS
8775 &disablelist);
8776
1bedd215
AC
8777 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8778Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
8779Arguments are breakpoint numbers with spaces in between.\n\
8780To delete all breakpoints, give no argument.\n\
8781\n\
8782Also a prefix command for deletion of other GDB objects.\n\
1bedd215 8783The \"unset\" command is also an alias for \"delete\"."),
c906108c
SS
8784 &deletelist, "delete ", 1, &cmdlist);
8785 add_com_alias ("d", "delete", class_breakpoint, 1);
7f198e01 8786 add_com_alias ("del", "delete", class_breakpoint, 1);
c906108c 8787 if (xdb_commands)
1bedd215
AC
8788 add_com ("db", class_breakpoint, delete_command, _("\
8789Delete some breakpoints.\n\
c906108c 8790Arguments are breakpoint numbers with spaces in between.\n\
1bedd215 8791To delete all breakpoints, give no argument.\n"));
c906108c 8792
1a966eab
AC
8793 add_cmd ("breakpoints", class_alias, delete_command, _("\
8794Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
8795Arguments are breakpoint numbers with spaces in between.\n\
8796To delete all breakpoints, give no argument.\n\
1a966eab 8797This command may be abbreviated \"delete\"."),
c906108c
SS
8798 &deletelist);
8799
1bedd215
AC
8800 add_com ("clear", class_breakpoint, clear_command, _("\
8801Clear breakpoint at specified line or function.\n\
c906108c
SS
8802Argument may be line number, function name, or \"*\" and an address.\n\
8803If line number is specified, all breakpoints in that line are cleared.\n\
8804If function is specified, breakpoints at beginning of function are cleared.\n\
1bedd215
AC
8805If an address is specified, breakpoints at that address are cleared.\n\
8806\n\
8807With no argument, clears all breakpoints in the line that the selected frame\n\
c906108c
SS
8808is executing in.\n\
8809\n\
1bedd215 8810See also the \"delete\" command which clears breakpoints by number."));
c906108c 8811
1bedd215 8812 c = add_com ("break", class_breakpoint, break_command, _("\
31e2b00f
AS
8813Set breakpoint at specified line or function.\n"
8814BREAK_ARGS_HELP ("break")));
5ba2abeb 8815 set_cmd_completer (c, location_completer);
c94fdfd0 8816
c906108c
SS
8817 add_com_alias ("b", "break", class_run, 1);
8818 add_com_alias ("br", "break", class_run, 1);
8819 add_com_alias ("bre", "break", class_run, 1);
8820 add_com_alias ("brea", "break", class_run, 1);
8821
7681d515
PM
8822 if (xdb_commands)
8823 add_com_alias ("ba", "break", class_breakpoint, 1);
c906108c
SS
8824
8825 if (dbx_commands)
8826 {
1bedd215
AC
8827 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8828Break in function/address or break at a line in the current file."),
c5aa993b
JM
8829 &stoplist, "stop ", 1, &cmdlist);
8830 add_cmd ("in", class_breakpoint, stopin_command,
1a966eab 8831 _("Break in function or address."), &stoplist);
c5aa993b 8832 add_cmd ("at", class_breakpoint, stopat_command,
1a966eab 8833 _("Break at a line in the current file."), &stoplist);
1bedd215
AC
8834 add_com ("status", class_info, breakpoints_info, _("\
8835Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
8836The \"Type\" column indicates one of:\n\
8837\tbreakpoint - normal breakpoint\n\
8838\twatchpoint - watchpoint\n\
8839The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8840the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8841breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1bedd215
AC
8842address and file/line number respectively.\n\
8843\n\
8844Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
8845are set to the address of the last breakpoint listed unless the command\n\
8846is prefixed with \"server \".\n\n\
c906108c 8847Convenience variable \"$bpnum\" contains the number of the last\n\
1bedd215 8848breakpoint set."));
c906108c
SS
8849 }
8850
1bedd215
AC
8851 add_info ("breakpoints", breakpoints_info, _("\
8852Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
8853The \"Type\" column indicates one of:\n\
8854\tbreakpoint - normal breakpoint\n\
8855\twatchpoint - watchpoint\n\
8856The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8857the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8858breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1bedd215
AC
8859address and file/line number respectively.\n\
8860\n\
8861Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
8862are set to the address of the last breakpoint listed unless the command\n\
8863is prefixed with \"server \".\n\n\
c906108c 8864Convenience variable \"$bpnum\" contains the number of the last\n\
1bedd215 8865breakpoint set."));
c906108c
SS
8866
8867 if (xdb_commands)
1bedd215
AC
8868 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8869Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
8870The \"Type\" column indicates one of:\n\
8871\tbreakpoint - normal breakpoint\n\
8872\twatchpoint - watchpoint\n\
8873The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8874the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8875breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1bedd215
AC
8876address and file/line number respectively.\n\
8877\n\
8878Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
8879are set to the address of the last breakpoint listed unless the command\n\
8880is prefixed with \"server \".\n\n\
c906108c 8881Convenience variable \"$bpnum\" contains the number of the last\n\
1bedd215 8882breakpoint set."));
c906108c 8883
1a966eab
AC
8884 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8885Status of all breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
8886The \"Type\" column indicates one of:\n\
8887\tbreakpoint - normal breakpoint\n\
8888\twatchpoint - watchpoint\n\
8889\tlongjmp - internal breakpoint used to step through longjmp()\n\
8890\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8891\tuntil - internal breakpoint used by the \"until\" command\n\
1a966eab
AC
8892\tfinish - internal breakpoint used by the \"finish\" command\n\
8893The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
c906108c
SS
8894the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8895breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
1a966eab
AC
8896address and file/line number respectively.\n\
8897\n\
8898Convenience variable \"$_\" and default examine address for \"x\"\n\
d1aa2f50
NR
8899are set to the address of the last breakpoint listed unless the command\n\
8900is prefixed with \"server \".\n\n\
c906108c 8901Convenience variable \"$bpnum\" contains the number of the last\n\
1a966eab 8902breakpoint set."),
c906108c
SS
8903 &maintenanceinfolist);
8904
44feb3ce
TT
8905 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
8906Set catchpoints to catch events."),
8907 &catch_cmdlist, "catch ",
8908 0/*allow-unknown*/, &cmdlist);
8909
8910 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
8911Set temporary catchpoints to catch events."),
8912 &tcatch_cmdlist, "tcatch ",
8913 0/*allow-unknown*/, &cmdlist);
8914
8915 /* Add catch and tcatch sub-commands. */
8916 add_catch_command ("catch", _("\
8917Catch an exception, when caught.\n\
8918With an argument, catch only exceptions with the given name."),
8919 catch_catch_command,
8920 CATCH_PERMANENT,
8921 CATCH_TEMPORARY);
8922 add_catch_command ("throw", _("\
8923Catch an exception, when thrown.\n\
8924With an argument, catch only exceptions with the given name."),
8925 catch_throw_command,
8926 CATCH_PERMANENT,
8927 CATCH_TEMPORARY);
8928 add_catch_command ("fork", _("Catch calls to fork."),
8929 catch_fork_command_1,
8930 (void *) (uintptr_t) catch_fork_permanent,
8931 (void *) (uintptr_t) catch_fork_temporary);
8932 add_catch_command ("vfork", _("Catch calls to vfork."),
8933 catch_fork_command_1,
8934 (void *) (uintptr_t) catch_vfork_permanent,
8935 (void *) (uintptr_t) catch_vfork_temporary);
8936 add_catch_command ("exec", _("Catch calls to exec."),
8937 catch_exec_command_1,
8938 CATCH_PERMANENT,
8939 CATCH_TEMPORARY);
44feb3ce
TT
8940 add_catch_command ("exception", _("\
8941Catch Ada exceptions, when raised.\n\
8942With an argument, catch only exceptions with the given name."),
8943 catch_ada_exception_command,
8944 CATCH_PERMANENT,
8945 CATCH_TEMPORARY);
8946 add_catch_command ("assert", _("\
8947Catch failed Ada assertions, when raised.\n\
8948With an argument, catch only exceptions with the given name."),
8949 catch_assert_command,
8950 CATCH_PERMANENT,
8951 CATCH_TEMPORARY);
c5aa993b 8952
1bedd215
AC
8953 c = add_com ("watch", class_breakpoint, watch_command, _("\
8954Set a watchpoint for an expression.\n\
c906108c 8955A watchpoint stops execution of your program whenever the value of\n\
1bedd215 8956an expression changes."));
65d12d83 8957 set_cmd_completer (c, expression_completer);
c906108c 8958
1bedd215
AC
8959 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8960Set a read watchpoint for an expression.\n\
c906108c 8961A watchpoint stops execution of your program whenever the value of\n\
1bedd215 8962an expression is read."));
65d12d83 8963 set_cmd_completer (c, expression_completer);
c906108c 8964
1bedd215
AC
8965 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8966Set a watchpoint for an expression.\n\
c906108c 8967A watchpoint stops execution of your program whenever the value of\n\
1bedd215 8968an expression is either read or written."));
65d12d83 8969 set_cmd_completer (c, expression_completer);
c906108c
SS
8970
8971 add_info ("watchpoints", breakpoints_info,
1bedd215 8972 _("Synonym for ``info breakpoints''."));
c906108c
SS
8973
8974
920d2a44
AC
8975 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8976 respond to changes - contrary to the description. */
85c07804
AC
8977 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8978 &can_use_hw_watchpoints, _("\
8979Set debugger's willingness to use watchpoint hardware."), _("\
8980Show debugger's willingness to use watchpoint hardware."), _("\
c906108c
SS
8981If zero, gdb will not use hardware for new watchpoints, even if\n\
8982such is available. (However, any hardware watchpoints that were\n\
8983created before setting this to nonzero, will continue to use watchpoint\n\
85c07804
AC
8984hardware.)"),
8985 NULL,
920d2a44 8986 show_can_use_hw_watchpoints,
85c07804 8987 &setlist, &showlist);
c906108c
SS
8988
8989 can_use_hw_watchpoints = 1;
fa8d40ab 8990
1042e4c0
SS
8991 /* Tracepoint manipulation commands. */
8992
8993 c = add_com ("trace", class_breakpoint, trace_command, _("\
8994Set a tracepoint at specified line or function.\n\
8995\n"
8996BREAK_ARGS_HELP ("trace") "\n\
8997Do \"help tracepoints\" for info on other tracepoint commands."));
8998 set_cmd_completer (c, location_completer);
8999
9000 add_com_alias ("tp", "trace", class_alias, 0);
9001 add_com_alias ("tr", "trace", class_alias, 1);
9002 add_com_alias ("tra", "trace", class_alias, 1);
9003 add_com_alias ("trac", "trace", class_alias, 1);
9004
9005 add_info ("tracepoints", tracepoints_info, _("\
9006Status of tracepoints, or tracepoint number NUMBER.\n\
9007Convenience variable \"$tpnum\" contains the number of the\n\
9008last tracepoint set."));
9009
9010 add_info_alias ("tp", "tracepoints", 1);
9011
9012 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
9013Delete specified tracepoints.\n\
9014Arguments are tracepoint numbers, separated by spaces.\n\
9015No argument means delete all tracepoints."),
9016 &deletelist);
9017
9018 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
9019Disable specified tracepoints.\n\
9020Arguments are tracepoint numbers, separated by spaces.\n\
9021No argument means disable all tracepoints."),
9022 &disablelist);
9023 deprecate_cmd (c, "disable");
9024
9025 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\
9026Enable specified tracepoints.\n\
9027Arguments are tracepoint numbers, separated by spaces.\n\
9028No argument means enable all tracepoints."),
9029 &enablelist);
9030 deprecate_cmd (c, "enable");
9031
9032 add_com ("passcount", class_trace, trace_pass_command, _("\
9033Set the passcount for a tracepoint.\n\
9034The trace will end when the tracepoint has been passed 'count' times.\n\
9035Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
9036if TPNUM is omitted, passcount refers to the last tracepoint defined."));
9037
9038 c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\
9039Save current tracepoint definitions as a script.\n\
9040Use the 'source' command in another debug session to restore them."));
9041 set_cmd_completer (c, filename_completer);
9042
1bedd215 9043 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
fa8d40ab
JJ
9044Breakpoint specific settings\n\
9045Configure various breakpoint-specific variables such as\n\
1bedd215 9046pending breakpoint behavior"),
fa8d40ab
JJ
9047 &breakpoint_set_cmdlist, "set breakpoint ",
9048 0/*allow-unknown*/, &setlist);
1bedd215 9049 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
fa8d40ab
JJ
9050Breakpoint specific settings\n\
9051Configure various breakpoint-specific variables such as\n\
1bedd215 9052pending breakpoint behavior"),
fa8d40ab
JJ
9053 &breakpoint_show_cmdlist, "show breakpoint ",
9054 0/*allow-unknown*/, &showlist);
9055
7915a72c
AC
9056 add_setshow_auto_boolean_cmd ("pending", no_class,
9057 &pending_break_support, _("\
9058Set debugger's behavior regarding pending breakpoints."), _("\
9059Show debugger's behavior regarding pending breakpoints."), _("\
6e1d7d6c
AC
9060If on, an unrecognized breakpoint location will cause gdb to create a\n\
9061pending breakpoint. If off, an unrecognized breakpoint location results in\n\
9062an error. If auto, an unrecognized breakpoint location results in a\n\
7915a72c 9063user-query to see if a pending breakpoint should be created."),
2c5b56ce 9064 NULL,
920d2a44 9065 show_pending_break_support,
6e1d7d6c
AC
9066 &breakpoint_set_cmdlist,
9067 &breakpoint_show_cmdlist);
fa8d40ab
JJ
9068
9069 pending_break_support = AUTO_BOOLEAN_AUTO;
765dc015
VP
9070
9071 add_setshow_boolean_cmd ("auto-hw", no_class,
9072 &automatic_hardware_breakpoints, _("\
9073Set automatic usage of hardware breakpoints."), _("\
9074Show automatic usage of hardware breakpoints."), _("\
9075If set, the debugger will automatically use hardware breakpoints for\n\
9076breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
9077a warning will be emitted for such breakpoints."),
9078 NULL,
9079 show_automatic_hardware_breakpoints,
9080 &breakpoint_set_cmdlist,
9081 &breakpoint_show_cmdlist);
74960c60 9082
33e5cbd6
PA
9083 add_setshow_enum_cmd ("always-inserted", class_support,
9084 always_inserted_enums, &always_inserted_mode, _("\
74960c60
VP
9085Set mode for inserting breakpoints."), _("\
9086Show mode for inserting breakpoints."), _("\
33e5cbd6
PA
9087When this mode is off, breakpoints are inserted in inferior when it is\n\
9088resumed, and removed when execution stops. When this mode is on,\n\
9089breakpoints are inserted immediately and removed only when the user\n\
9090deletes the breakpoint. When this mode is auto (which is the default),\n\
9091the behaviour depends on the non-stop setting (see help set non-stop).\n\
9092In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
9093behaves as if always-inserted mode is on; if gdb is controlling the\n\
9094inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
74960c60
VP
9095 NULL,
9096 &show_always_inserted_mode,
9097 &breakpoint_set_cmdlist,
9098 &breakpoint_show_cmdlist);
765dc015
VP
9099
9100 automatic_hardware_breakpoints = 1;
f3b1572e
PA
9101
9102 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
c906108c 9103}
This page took 1.306812 seconds and 4 git commands to generate.