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