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