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