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