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