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