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