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