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