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