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