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