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