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