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