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