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