Add __FILE__ and __LINE__ parameter to internal_error() /
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
CommitLineData
c906108c 1/* Everything about breakpoints, for GDB.
4fcf66da
AC
2 Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999,
3 2000, 2001 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23#include <ctype.h>
24#include "symtab.h"
25#include "frame.h"
26#include "breakpoint.h"
27#include "gdbtypes.h"
28#include "expression.h"
29#include "gdbcore.h"
30#include "gdbcmd.h"
31#include "value.h"
32#include "command.h"
33#include "inferior.h"
34#include "gdbthread.h"
35#include "target.h"
36#include "language.h"
37#include "gdb_string.h"
38#include "demangle.h"
39#include "annotate.h"
40#include "symfile.h"
41#include "objfiles.h"
c5f0f3d0 42#include "linespec.h"
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:
8e65ff28
AC
2185 internal_error (__FILE__, __LINE__,
2186 "print_bp_stop_message: unrecognized enum value");
e514a9d6 2187 break;
c906108c 2188 }
c906108c
SS
2189}
2190
e514a9d6
JM
2191/* Print a message indicating what happened. This is called from
2192 normal_stop(). The input to this routine is the head of the bpstat
2193 list - a list of the eventpoints that caused this stop. This
2194 routine calls the generic print routine for printing a message
2195 about reasons for stopping. This will print (for example) the
2196 "Breakpoint n," part of the output. The return value of this
2197 routine is one of:
c906108c 2198
917317f4
JM
2199 PRINT_UNKNOWN: Means we printed nothing
2200 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
c5aa993b
JM
2201 code to print the location. An example is
2202 "Breakpoint 1, " which should be followed by
2203 the location.
917317f4 2204 PRINT_SRC_ONLY: Means we printed something, but there is no need
c5aa993b
JM
2205 to also print the location part of the message.
2206 An example is the catch/throw messages, which
917317f4
JM
2207 don't require a location appended to the end.
2208 PRINT_NOTHING: We have done some printing and we don't need any
2209 further info to be printed.*/
c906108c 2210
917317f4 2211enum print_stop_action
fba45db2 2212bpstat_print (bpstat bs)
c906108c
SS
2213{
2214 int val;
c5aa993b 2215
c906108c 2216 /* Maybe another breakpoint in the chain caused us to stop.
53a5351d
JM
2217 (Currently all watchpoints go on the bpstat whether hit or not.
2218 That probably could (should) be changed, provided care is taken
c906108c 2219 with respect to bpstat_explains_signal). */
e514a9d6
JM
2220 for (; bs; bs = bs->next)
2221 {
2222 val = print_bp_stop_message (bs);
2223 if (val == PRINT_SRC_ONLY
2224 || val == PRINT_SRC_AND_LOC
2225 || val == PRINT_NOTHING)
2226 return val;
2227 }
c906108c 2228
e514a9d6
JM
2229 /* We reached the end of the chain, or we got a null BS to start
2230 with and nothing was printed. */
917317f4 2231 return PRINT_UNKNOWN;
c906108c
SS
2232}
2233
2234/* Evaluate the expression EXP and return 1 if value is zero.
2235 This is used inside a catch_errors to evaluate the breakpoint condition.
2236 The argument is a "struct expression *" that has been cast to char * to
2237 make it pass through catch_errors. */
2238
2239static int
fba45db2 2240breakpoint_cond_eval (PTR exp)
c906108c
SS
2241{
2242 value_ptr mark = value_mark ();
c5aa993b 2243 int i = !value_true (evaluate_expression ((struct expression *) exp));
c906108c
SS
2244 value_free_to_mark (mark);
2245 return i;
2246}
2247
2248/* Allocate a new bpstat and chain it to the current one. */
2249
2250static bpstat
831662b3 2251bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
c906108c
SS
2252{
2253 bpstat bs;
2254
2255 bs = (bpstat) xmalloc (sizeof (*bs));
2256 cbs->next = bs;
2257 bs->breakpoint_at = b;
2258 /* If the condition is false, etc., don't do the commands. */
2259 bs->commands = NULL;
2260 bs->old_val = NULL;
2261 bs->print_it = print_it_normal;
2262 return bs;
2263}
2264\f
2265/* Possible return values for watchpoint_check (this can't be an enum
2266 because of check_errors). */
2267/* The watchpoint has been deleted. */
2268#define WP_DELETED 1
2269/* The value has changed. */
2270#define WP_VALUE_CHANGED 2
2271/* The value has not changed. */
2272#define WP_VALUE_NOT_CHANGED 3
2273
2274#define BP_TEMPFLAG 1
2275#define BP_HARDWAREFLAG 2
2276
2277/* Check watchpoint condition. */
2278
2279static int
fba45db2 2280watchpoint_check (PTR p)
c906108c
SS
2281{
2282 bpstat bs = (bpstat) p;
2283 struct breakpoint *b;
2284 struct frame_info *fr;
2285 int within_current_scope;
2286
2287 b = bs->breakpoint_at;
2288
2289 if (b->exp_valid_block == NULL)
2290 within_current_scope = 1;
2291 else
2292 {
2293 /* There is no current frame at this moment. If we're going to have
c5aa993b
JM
2294 any chance of handling watchpoints on local variables, we'll need
2295 the frame chain (so we can determine if we're in scope). */
2296 reinit_frame_cache ();
c906108c
SS
2297 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2298 within_current_scope = (fr != NULL);
2299 if (within_current_scope)
2300 /* If we end up stopping, the current frame will get selected
2301 in normal_stop. So this call to select_frame won't affect
2302 the user. */
2303 select_frame (fr, -1);
2304 }
c5aa993b 2305
c906108c
SS
2306 if (within_current_scope)
2307 {
2308 /* We use value_{,free_to_}mark because it could be a
2309 *long* time before we return to the command level and
c5aa993b
JM
2310 call free_all_values. We can't call free_all_values because
2311 we might be in the middle of evaluating a function call. */
c906108c
SS
2312
2313 value_ptr mark = value_mark ();
2314 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2315 if (!value_equal (b->val, new_val))
2316 {
2317 release_value (new_val);
2318 value_free_to_mark (mark);
2319 bs->old_val = b->val;
2320 b->val = new_val;
2321 /* We will stop here */
2322 return WP_VALUE_CHANGED;
2323 }
2324 else
2325 {
2326 /* Nothing changed, don't do anything. */
2327 value_free_to_mark (mark);
2328 /* We won't stop here */
2329 return WP_VALUE_NOT_CHANGED;
2330 }
2331 }
2332 else
2333 {
2334 /* This seems like the only logical thing to do because
c5aa993b
JM
2335 if we temporarily ignored the watchpoint, then when
2336 we reenter the block in which it is valid it contains
2337 garbage (in the case of a function, it may have two
2338 garbage values, one before and one after the prologue).
2339 So we can't even detect the first assignment to it and
2340 watch after that (since the garbage may or may not equal
2341 the first value assigned). */
4ce44c66
JM
2342 /* We print all the stop information in print_it_typical(), but
2343 in this case, by the time we call print_it_typical() this bp
2344 will be deleted already. So we have no choice but print the
2345 information here. */
8b93c638 2346#ifdef UI_OUT
fb40c209
AC
2347 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2348 ui_out_field_string (uiout, "reason", "watchpoint-scope");
8b93c638
JM
2349 ui_out_text (uiout, "\nWatchpoint ");
2350 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2351 ui_out_text (uiout, " deleted because the program has left the block in\n\
2352which its expression is valid.\n");
2353#else
c906108c
SS
2354 printf_filtered ("\
2355Watchpoint %d deleted because the program has left the block in\n\
2356which its expression is valid.\n", bs->breakpoint_at->number);
8b93c638 2357#endif
4ce44c66 2358
c906108c
SS
2359 if (b->related_breakpoint)
2360 b->related_breakpoint->disposition = del_at_next_stop;
2361 b->disposition = del_at_next_stop;
2362
2363 return WP_DELETED;
2364 }
2365}
2366
c906108c
SS
2367/* Get a bpstat associated with having just stopped at address *PC
2368 and frame address CORE_ADDRESS. Update *PC to point at the
2369 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2370 if this is known to not be a real breakpoint (it could still be a
2371 watchpoint, though). */
2372
2373/* Determine whether we stopped at a breakpoint, etc, or whether we
2374 don't understand this stop. Result is a chain of bpstat's such that:
2375
c5aa993b 2376 if we don't understand the stop, the result is a null pointer.
c906108c 2377
c5aa993b 2378 if we understand why we stopped, the result is not null.
c906108c 2379
c5aa993b
JM
2380 Each element of the chain refers to a particular breakpoint or
2381 watchpoint at which we have stopped. (We may have stopped for
2382 several reasons concurrently.)
c906108c 2383
c5aa993b
JM
2384 Each element of the chain has valid next, breakpoint_at,
2385 commands, FIXME??? fields. */
c906108c
SS
2386
2387bpstat
fba45db2 2388bpstat_stop_status (CORE_ADDR *pc, int not_a_breakpoint)
c906108c
SS
2389{
2390 register struct breakpoint *b, *temp;
2391 CORE_ADDR bp_addr;
2392 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2393 int real_breakpoint = 0;
2394 /* Root of the chain of bpstat's */
2395 struct bpstats root_bs[1];
2396 /* Pointer to the last thing in the chain currently. */
2397 bpstat bs = root_bs;
2398 static char message1[] =
c5aa993b
JM
2399 "Error evaluating expression for watchpoint %d\n";
2400 char message[sizeof (message1) + 30 /* slop */ ];
c906108c
SS
2401
2402 /* Get the address where the breakpoint would have been. */
6426a772
JM
2403 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ?
2404 0 : DECR_PC_AFTER_BREAK);
c906108c
SS
2405
2406 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
2407 {
2408 if (b->enable == disabled
2409 || b->enable == shlib_disabled
2410 || b->enable == call_disabled)
2411 continue;
2412
2413 if (b->type != bp_watchpoint
2414 && b->type != bp_hardware_watchpoint
2415 && b->type != bp_read_watchpoint
2416 && b->type != bp_access_watchpoint
2417 && b->type != bp_hardware_breakpoint
2418 && b->type != bp_catch_fork
2419 && b->type != bp_catch_vfork
2420 && b->type != bp_catch_exec
2421 && b->type != bp_catch_catch
2422 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2423 if (b->address != bp_addr || /* address doesn't match or */
2424 (overlay_debugging && /* overlay doesn't match */
2425 section_is_overlay (b->section) &&
2426 !section_is_mapped (b->section)))
c906108c
SS
2427 continue;
2428
c5aa993b
JM
2429 if (b->type == bp_hardware_breakpoint
2430 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2431 continue;
2432
c5aa993b
JM
2433 /* Is this a catchpoint of a load or unload? If so, did we
2434 get a load or unload of the specified library? If not,
2435 ignore it. */
2436 if ((b->type == bp_catch_load)
c906108c 2437#if defined(SOLIB_HAVE_LOAD_EVENT)
c5aa993b
JM
2438 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2439 || ((b->dll_pathname != NULL)
53a5351d
JM
2440 && (strcmp (b->dll_pathname,
2441 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2442 != 0)))
c906108c 2443#endif
c5aa993b
JM
2444 )
2445 continue;
2446
2447 if ((b->type == bp_catch_unload)
c906108c 2448#if defined(SOLIB_HAVE_UNLOAD_EVENT)
c5aa993b
JM
2449 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2450 || ((b->dll_pathname != NULL)
53a5351d
JM
2451 && (strcmp (b->dll_pathname,
2452 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2453 != 0)))
c906108c 2454#endif
c5aa993b
JM
2455 )
2456 continue;
c906108c 2457
c5aa993b
JM
2458 if ((b->type == bp_catch_fork)
2459 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2460 continue;
c906108c 2461
c5aa993b
JM
2462 if ((b->type == bp_catch_vfork)
2463 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2464 continue;
c906108c 2465
c5aa993b
JM
2466 if ((b->type == bp_catch_exec)
2467 && !target_has_execd (inferior_pid, &b->exec_pathname))
2468 continue;
c906108c 2469
c5aa993b
JM
2470 if (ep_is_exception_catchpoint (b) &&
2471 !(current_exception_event = target_get_current_exception_event ()))
2472 continue;
c906108c 2473
c5aa993b
JM
2474 /* Come here if it's a watchpoint, or if the break address matches */
2475
2476 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2477
2478 /* Watchpoints may change this, if not found to have triggered. */
2479 bs->stop = 1;
2480 bs->print = 1;
2481
2482 sprintf (message, message1, b->number);
53a5351d
JM
2483 if (b->type == bp_watchpoint ||
2484 b->type == bp_hardware_watchpoint)
c5aa993b 2485 {
53a5351d
JM
2486 switch (catch_errors (watchpoint_check, bs, message,
2487 RETURN_MASK_ALL))
c5aa993b
JM
2488 {
2489 case WP_DELETED:
2490 /* We've already printed what needs to be printed. */
4ce44c66
JM
2491 /* Actually this is superfluous, because by the time we
2492 call print_it_typical() the wp will be already deleted,
2493 and the function will return immediately. */
c5aa993b
JM
2494 bs->print_it = print_it_done;
2495 /* Stop. */
2496 break;
2497 case WP_VALUE_CHANGED:
2498 /* Stop. */
2499 ++(b->hit_count);
2500 break;
2501 case WP_VALUE_NOT_CHANGED:
2502 /* Don't stop. */
2503 bs->print_it = print_it_noop;
2504 bs->stop = 0;
c5aa993b
JM
2505 continue;
2506 default:
2507 /* Can't happen. */
2508 /* FALLTHROUGH */
2509 case 0:
2510 /* Error from catch_errors. */
2511 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2512 if (b->related_breakpoint)
2513 b->related_breakpoint->disposition = del_at_next_stop;
2514 b->disposition = del_at_next_stop;
2515 /* We've already printed what needs to be printed. */
2516 bs->print_it = print_it_done;
2517
2518 /* Stop. */
2519 break;
2520 }
2521 }
53a5351d
JM
2522 else if (b->type == bp_read_watchpoint ||
2523 b->type == bp_access_watchpoint)
c5aa993b
JM
2524 {
2525 CORE_ADDR addr;
2526 value_ptr v;
2527 int found = 0;
2528
2529 addr = target_stopped_data_address ();
2530 if (addr == 0)
2531 continue;
2532 for (v = b->val_chain; v; v = v->next)
2533 {
5c44784c
JM
2534 if (VALUE_LVAL (v) == lval_memory
2535 && ! VALUE_LAZY (v))
c5aa993b 2536 {
2e70b7b9
MS
2537 struct type *vtype = check_typedef (VALUE_TYPE (v));
2538
2539 if (v == b->val_chain
2540 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2541 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2542 {
2543 CORE_ADDR vaddr;
2544
2545 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2546 /* Exact match not required. Within range is
2547 sufficient. */
2548 if (addr >= vaddr &&
2549 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2550 found = 1;
2551 }
c5aa993b
JM
2552 }
2553 }
2554 if (found)
53a5351d
JM
2555 switch (catch_errors (watchpoint_check, bs, message,
2556 RETURN_MASK_ALL))
c906108c
SS
2557 {
2558 case WP_DELETED:
2559 /* We've already printed what needs to be printed. */
2560 bs->print_it = print_it_done;
2561 /* Stop. */
2562 break;
2563 case WP_VALUE_CHANGED:
99e5c1c8
MS
2564 if (b->type == bp_read_watchpoint)
2565 {
2566 /* Don't stop: read watchpoints shouldn't fire if
2567 the value has changed. This is for targets which
2568 cannot set read-only watchpoints. */
2569 bs->print_it = print_it_noop;
2570 bs->stop = 0;
2571 continue;
2572 }
2573 ++(b->hit_count);
2574 break;
c5aa993b 2575 case WP_VALUE_NOT_CHANGED:
c906108c
SS
2576 /* Stop. */
2577 ++(b->hit_count);
2578 break;
c906108c
SS
2579 default:
2580 /* Can't happen. */
c906108c
SS
2581 case 0:
2582 /* Error from catch_errors. */
2583 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2584 if (b->related_breakpoint)
2585 b->related_breakpoint->disposition = del_at_next_stop;
2586 b->disposition = del_at_next_stop;
2587 /* We've already printed what needs to be printed. */
2588 bs->print_it = print_it_done;
c906108c
SS
2589 break;
2590 }
53a5351d
JM
2591 else /* found == 0 */
2592 {
2593 /* This is a case where some watchpoint(s) triggered,
2594 but not at the address of this watchpoint (FOUND
2595 was left zero). So don't print anything for this
2596 watchpoint. */
2597 bs->print_it = print_it_noop;
2598 bs->stop = 0;
2599 continue;
2600 }
c5aa993b
JM
2601 }
2602 else
2603 {
2604 /* By definition, an encountered breakpoint is a triggered
2605 breakpoint. */
2606 ++(b->hit_count);
c906108c 2607
c5aa993b
JM
2608 real_breakpoint = 1;
2609 }
2610
ed9a39eb
JM
2611 if (b->frame &&
2612 b->frame != (get_current_frame ())->frame)
c5aa993b
JM
2613 bs->stop = 0;
2614 else
2615 {
2616 int value_is_zero = 0;
2617
2618 if (b->cond)
2619 {
2620 /* Need to select the frame, with all that implies
2621 so that the conditions will have the right context. */
2622 select_frame (get_current_frame (), 0);
2623 value_is_zero
2624 = catch_errors (breakpoint_cond_eval, (b->cond),
2625 "Error in testing breakpoint condition:\n",
2626 RETURN_MASK_ALL);
2627 /* FIXME-someday, should give breakpoint # */
2628 free_all_values ();
2629 }
2630 if (b->cond && value_is_zero)
2631 {
2632 bs->stop = 0;
2633 /* Don't consider this a hit. */
2634 --(b->hit_count);
2635 }
2636 else if (b->ignore_count > 0)
2637 {
2638 b->ignore_count--;
5c44784c 2639 annotate_ignore_count_change ();
c5aa993b
JM
2640 bs->stop = 0;
2641 }
2642 else
2643 {
2644 /* We will stop here */
2645 if (b->disposition == disable)
2646 b->enable = disabled;
2647 bs->commands = b->commands;
2648 if (b->silent)
2649 bs->print = 0;
2650 if (bs->commands &&
2651 (STREQ ("silent", bs->commands->line) ||
2652 (xdb_commands && STREQ ("Q", bs->commands->line))))
2653 {
2654 bs->commands = bs->commands->next;
c906108c 2655 bs->print = 0;
c5aa993b
JM
2656 }
2657 }
2658 }
2659 /* Print nothing for this entry if we dont stop or if we dont print. */
2660 if (bs->stop == 0 || bs->print == 0)
2661 bs->print_it = print_it_noop;
2662 }
c906108c
SS
2663
2664 bs->next = NULL; /* Terminate the chain */
2665 bs = root_bs->next; /* Re-grab the head of the chain */
2666
2667 if (real_breakpoint && bs)
2668 {
c5aa993b 2669 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
c906108c 2670 {
c5aa993b 2671 if (DECR_PC_AFTER_HW_BREAK != 0)
c906108c
SS
2672 {
2673 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2674 write_pc (*pc);
2675 }
2676 }
2677 else
2678 {
2679 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2680 {
2681 *pc = bp_addr;
2682#if defined (SHIFT_INST_REGS)
c5aa993b 2683 SHIFT_INST_REGS ();
c906108c
SS
2684#else /* No SHIFT_INST_REGS. */
2685 write_pc (bp_addr);
2686#endif /* No SHIFT_INST_REGS. */
2687 }
2688 }
2689 }
2690
2691 /* The value of a hardware watchpoint hasn't changed, but the
2692 intermediate memory locations we are watching may have. */
c5aa993b 2693 if (bs && !bs->stop &&
c906108c
SS
2694 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2695 bs->breakpoint_at->type == bp_read_watchpoint ||
2696 bs->breakpoint_at->type == bp_access_watchpoint))
2697 {
2698 remove_breakpoints ();
2699 insert_breakpoints ();
2700 }
2701 return bs;
2702}
2703\f
2704/* Tell what to do about this bpstat. */
2705struct bpstat_what
fba45db2 2706bpstat_what (bpstat bs)
c906108c
SS
2707{
2708 /* Classify each bpstat as one of the following. */
c5aa993b
JM
2709 enum class
2710 {
2711 /* This bpstat element has no effect on the main_action. */
2712 no_effect = 0,
2713
2714 /* There was a watchpoint, stop but don't print. */
2715 wp_silent,
c906108c 2716
c5aa993b
JM
2717 /* There was a watchpoint, stop and print. */
2718 wp_noisy,
c906108c 2719
c5aa993b
JM
2720 /* There was a breakpoint but we're not stopping. */
2721 bp_nostop,
c906108c 2722
c5aa993b
JM
2723 /* There was a breakpoint, stop but don't print. */
2724 bp_silent,
c906108c 2725
c5aa993b
JM
2726 /* There was a breakpoint, stop and print. */
2727 bp_noisy,
c906108c 2728
c5aa993b
JM
2729 /* We hit the longjmp breakpoint. */
2730 long_jump,
c906108c 2731
c5aa993b
JM
2732 /* We hit the longjmp_resume breakpoint. */
2733 long_resume,
c906108c 2734
c5aa993b
JM
2735 /* We hit the step_resume breakpoint. */
2736 step_resume,
c906108c 2737
c5aa993b
JM
2738 /* We hit the through_sigtramp breakpoint. */
2739 through_sig,
c906108c 2740
c5aa993b
JM
2741 /* We hit the shared library event breakpoint. */
2742 shlib_event,
c906108c 2743
c5aa993b
JM
2744 /* We caught a shared library event. */
2745 catch_shlib_event,
c906108c 2746
c5aa993b
JM
2747 /* This is just used to count how many enums there are. */
2748 class_last
c906108c
SS
2749 };
2750
2751 /* Here is the table which drives this routine. So that we can
2752 format it pretty, we define some abbreviations for the
2753 enum bpstat_what codes. */
2754#define kc BPSTAT_WHAT_KEEP_CHECKING
2755#define ss BPSTAT_WHAT_STOP_SILENT
2756#define sn BPSTAT_WHAT_STOP_NOISY
2757#define sgl BPSTAT_WHAT_SINGLE
2758#define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2759#define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2760#define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2761#define sr BPSTAT_WHAT_STEP_RESUME
2762#define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2763#define shl BPSTAT_WHAT_CHECK_SHLIBS
2764#define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2765
2766/* "Can't happen." Might want to print an error message.
2767 abort() is not out of the question, but chances are GDB is just
2768 a bit confused, not unusable. */
2769#define err BPSTAT_WHAT_STOP_NOISY
2770
2771 /* Given an old action and a class, come up with a new action. */
2772 /* One interesting property of this table is that wp_silent is the same
2773 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2774 after stopping, the check for whether to step over a breakpoint
2775 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
53a5351d
JM
2776 reference to how we stopped. We retain separate wp_silent and
2777 bp_silent codes in case we want to change that someday.
43ff13b4
JM
2778
2779 Another possibly interesting property of this table is that
2780 there's a partial ordering, priority-like, of the actions. Once
2781 you've decided that some action is appropriate, you'll never go
2782 back and decide something of a lower priority is better. The
2783 ordering is:
2784
7e73cedf 2785 kc < clr sgl shl shlr slr sn sr ss ts
c5aa993b
JM
2786 sgl < clrs shl shlr slr sn sr ss ts
2787 slr < err shl shlr sn sr ss ts
2788 clr < clrs err shl shlr sn sr ss ts
2789 clrs < err shl shlr sn sr ss ts
2790 ss < shl shlr sn sr ts
2791 sn < shl shlr sr ts
2792 sr < shl shlr ts
2793 shl < shlr
2794 ts <
2795 shlr <
2796
43ff13b4
JM
2797 What I think this means is that we don't need a damned table
2798 here. If you just put the rows and columns in the right order,
2799 it'd look awfully regular. We could simply walk the bpstat list
2800 and choose the highest priority action we find, with a little
2801 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2802 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2803 is messy anyway). */
c906108c
SS
2804
2805 /* step_resume entries: a step resume breakpoint overrides another
2806 breakpoint of signal handling (see comment in wait_for_inferior
2807 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2808 /* We handle the through_sigtramp_breakpoint the same way; having both
2809 one of those and a step_resume_breakpoint is probably very rare (?). */
2810
2811 static const enum bpstat_what_main_action
c5aa993b
JM
2812 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2813 {
2814 /* old action */
2815 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2816 */
2817/*no_effect */
2818 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2819/*wp_silent */
2820 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2821/*wp_noisy */
2822 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2823/*bp_nostop */
2824 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2825/*bp_silent */
2826 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2827/*bp_noisy */
2828 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2829/*long_jump */
a48bb0b3 2830 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
c5aa993b
JM
2831/*long_resume */
2832 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2833/*step_resume */
2834 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2835/*through_sig */
2836 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2837/*shlib */
2838 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2839/*catch_shlib */
2840 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2841 };
c906108c
SS
2842
2843#undef kc
2844#undef ss
2845#undef sn
2846#undef sgl
2847#undef slr
2848#undef clr
2849#undef clrs
2850#undef err
2851#undef sr
2852#undef ts
2853#undef shl
2854#undef shlr
2855 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2856 struct bpstat_what retval;
2857
2858 retval.call_dummy = 0;
2859 for (; bs != NULL; bs = bs->next)
2860 {
2861 enum class bs_class = no_effect;
2862 if (bs->breakpoint_at == NULL)
2863 /* I suspect this can happen if it was a momentary breakpoint
2864 which has since been deleted. */
2865 continue;
2866 switch (bs->breakpoint_at->type)
2867 {
2868 case bp_none:
2869 continue;
2870
2871 case bp_breakpoint:
2872 case bp_hardware_breakpoint:
2873 case bp_until:
2874 case bp_finish:
2875 if (bs->stop)
2876 {
2877 if (bs->print)
2878 bs_class = bp_noisy;
2879 else
2880 bs_class = bp_silent;
2881 }
2882 else
2883 bs_class = bp_nostop;
2884 break;
2885 case bp_watchpoint:
2886 case bp_hardware_watchpoint:
2887 case bp_read_watchpoint:
2888 case bp_access_watchpoint:
2889 if (bs->stop)
2890 {
2891 if (bs->print)
2892 bs_class = wp_noisy;
2893 else
2894 bs_class = wp_silent;
2895 }
2896 else
53a5351d
JM
2897 /* There was a watchpoint, but we're not stopping.
2898 This requires no further action. */
c906108c
SS
2899 bs_class = no_effect;
2900 break;
2901 case bp_longjmp:
2902 bs_class = long_jump;
2903 break;
2904 case bp_longjmp_resume:
2905 bs_class = long_resume;
2906 break;
2907 case bp_step_resume:
2908 if (bs->stop)
2909 {
2910 bs_class = step_resume;
2911 }
2912 else
2913 /* It is for the wrong frame. */
2914 bs_class = bp_nostop;
2915 break;
2916 case bp_through_sigtramp:
2917 bs_class = through_sig;
2918 break;
2919 case bp_watchpoint_scope:
2920 bs_class = bp_nostop;
2921 break;
c5aa993b
JM
2922 case bp_shlib_event:
2923 bs_class = shlib_event;
2924 break;
c4093a6a
JM
2925 case bp_thread_event:
2926 bs_class = bp_nostop;
2927 break;
c5aa993b
JM
2928 case bp_catch_load:
2929 case bp_catch_unload:
2930 /* Only if this catchpoint triggered should we cause the
2931 step-out-of-dld behaviour. Otherwise, we ignore this
2932 catchpoint. */
2933 if (bs->stop)
2934 bs_class = catch_shlib_event;
2935 else
2936 bs_class = no_effect;
2937 break;
2938 case bp_catch_fork:
2939 case bp_catch_vfork:
2940 case bp_catch_exec:
2941 if (bs->stop)
2942 {
2943 if (bs->print)
2944 bs_class = bp_noisy;
2945 else
2946 bs_class = bp_silent;
2947 }
2948 else
53a5351d
JM
2949 /* There was a catchpoint, but we're not stopping.
2950 This requires no further action. */
c5aa993b
JM
2951 bs_class = no_effect;
2952 break;
2953 case bp_catch_catch:
2954 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2955 bs_class = bp_nostop;
2956 else if (bs->stop)
2957 bs_class = bs->print ? bp_noisy : bp_silent;
2958 break;
2959 case bp_catch_throw:
2960 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2961 bs_class = bp_nostop;
2962 else if (bs->stop)
2963 bs_class = bs->print ? bp_noisy : bp_silent;
c906108c 2964 break;
c906108c 2965 case bp_call_dummy:
53a5351d
JM
2966 /* Make sure the action is stop (silent or noisy),
2967 so infrun.c pops the dummy frame. */
c906108c
SS
2968 bs_class = bp_silent;
2969 retval.call_dummy = 1;
2970 break;
2971 }
c5aa993b 2972 current_action = table[(int) bs_class][(int) current_action];
c906108c
SS
2973 }
2974 retval.main_action = current_action;
2975 return retval;
2976}
2977
2978/* Nonzero if we should step constantly (e.g. watchpoints on machines
2979 without hardware support). This isn't related to a specific bpstat,
2980 just to things like whether watchpoints are set. */
2981
c5aa993b 2982int
fba45db2 2983bpstat_should_step (void)
c906108c
SS
2984{
2985 struct breakpoint *b;
2986 ALL_BREAKPOINTS (b)
2987 if (b->enable == enabled && b->type == bp_watchpoint)
c5aa993b 2988 return 1;
c906108c
SS
2989 return 0;
2990}
2991
2992/* Nonzero if there are enabled hardware watchpoints. */
2993int
fba45db2 2994bpstat_have_active_hw_watchpoints (void)
c906108c
SS
2995{
2996 struct breakpoint *b;
2997 ALL_BREAKPOINTS (b)
2998 if ((b->enable == enabled) &&
c5aa993b
JM
2999 (b->inserted) &&
3000 ((b->type == bp_hardware_watchpoint) ||
3001 (b->type == bp_read_watchpoint) ||
3002 (b->type == bp_access_watchpoint)))
3003 return 1;
c906108c
SS
3004 return 0;
3005}
c906108c 3006\f
c5aa993b 3007
c906108c
SS
3008/* Given a bpstat that records zero or more triggered eventpoints, this
3009 function returns another bpstat which contains only the catchpoints
3010 on that first list, if any. */
3011void
fba45db2 3012bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
c5aa993b
JM
3013{
3014 struct bpstats root_bs[1];
3015 bpstat bs = root_bs;
3016 struct breakpoint *ep;
3017 char *dll_pathname;
3018
c906108c
SS
3019 bpstat_clear (cp_list);
3020 root_bs->next = NULL;
c5aa993b
JM
3021
3022 for (; ep_list != NULL; ep_list = ep_list->next)
c906108c
SS
3023 {
3024 /* Is this eventpoint a catchpoint? If not, ignore it. */
3025 ep = ep_list->breakpoint_at;
3026 if (ep == NULL)
c5aa993b
JM
3027 break;
3028 if ((ep->type != bp_catch_load) &&
3029 (ep->type != bp_catch_unload) &&
3030 (ep->type != bp_catch_catch) &&
53a5351d
JM
3031 (ep->type != bp_catch_throw))
3032 /* pai: (temp) ADD fork/vfork here!! */
c5aa993b
JM
3033 continue;
3034
c906108c
SS
3035 /* Yes; add it to the list. */
3036 bs = bpstat_alloc (ep, bs);
3037 *bs = *ep_list;
3038 bs->next = NULL;
3039 bs = root_bs->next;
c5aa993b 3040
c906108c
SS
3041#if defined(SOLIB_ADD)
3042 /* Also, for each triggered catchpoint, tag it with the name of
3043 the library that caused this trigger. (We copy the name now,
3044 because it's only guaranteed to be available NOW, when the
3045 catchpoint triggers. Clients who may wish to know the name
3046 later must get it from the catchpoint itself.) */
3047 if (ep->triggered_dll_pathname != NULL)
b8c9b27d 3048 xfree (ep->triggered_dll_pathname);
c906108c 3049 if (ep->type == bp_catch_load)
c5aa993b 3050 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
c906108c 3051 else
c5aa993b 3052 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
c906108c
SS
3053#else
3054 dll_pathname = NULL;
3055#endif
3056 if (dll_pathname)
3057 {
53a5351d
JM
3058 ep->triggered_dll_pathname = (char *)
3059 xmalloc (strlen (dll_pathname) + 1);
c906108c
SS
3060 strcpy (ep->triggered_dll_pathname, dll_pathname);
3061 }
3062 else
3063 ep->triggered_dll_pathname = NULL;
3064 }
c5aa993b 3065
c906108c
SS
3066 *cp_list = bs;
3067}
3068
c4093a6a 3069/* Print B to gdb_stdout. */
c906108c 3070static void
c4093a6a
JM
3071print_one_breakpoint (struct breakpoint *b,
3072 CORE_ADDR *last_addr)
c906108c 3073{
c906108c
SS
3074 register struct command_line *l;
3075 register struct symbol *sym;
c4093a6a
JM
3076 struct ep_type_description
3077 {
3078 enum bptype type;
3079 char *description;
3080 };
3081 static struct ep_type_description bptypes[] =
c906108c 3082 {
c5aa993b
JM
3083 {bp_none, "?deleted?"},
3084 {bp_breakpoint, "breakpoint"},
c906108c 3085 {bp_hardware_breakpoint, "hw breakpoint"},
c5aa993b
JM
3086 {bp_until, "until"},
3087 {bp_finish, "finish"},
3088 {bp_watchpoint, "watchpoint"},
c906108c 3089 {bp_hardware_watchpoint, "hw watchpoint"},
c5aa993b
JM
3090 {bp_read_watchpoint, "read watchpoint"},
3091 {bp_access_watchpoint, "acc watchpoint"},
3092 {bp_longjmp, "longjmp"},
3093 {bp_longjmp_resume, "longjmp resume"},
3094 {bp_step_resume, "step resume"},
3095 {bp_through_sigtramp, "sigtramp"},
3096 {bp_watchpoint_scope, "watchpoint scope"},
3097 {bp_call_dummy, "call dummy"},
3098 {bp_shlib_event, "shlib events"},
c4093a6a 3099 {bp_thread_event, "thread events"},
c5aa993b
JM
3100 {bp_catch_load, "catch load"},
3101 {bp_catch_unload, "catch unload"},
3102 {bp_catch_fork, "catch fork"},
3103 {bp_catch_vfork, "catch vfork"},
3104 {bp_catch_exec, "catch exec"},
3105 {bp_catch_catch, "catch catch"},
3106 {bp_catch_throw, "catch throw"}
3107 };
c4093a6a 3108
c5aa993b
JM
3109 static char *bpdisps[] =
3110 {"del", "dstp", "dis", "keep"};
c2c6d25f 3111 static char bpenables[] = "nynny";
c906108c 3112 char wrap_indent[80];
8b93c638
JM
3113#ifdef UI_OUT
3114 struct ui_stream *stb = ui_out_stream_new (uiout);
3115 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3116#endif
c906108c 3117
c4093a6a 3118 annotate_record ();
8b93c638
JM
3119#ifdef UI_OUT
3120 ui_out_list_begin (uiout, "bkpt");
3121#endif
c4093a6a
JM
3122
3123 /* 1 */
3124 annotate_field (0);
8b93c638
JM
3125#ifdef UI_OUT
3126 ui_out_field_int (uiout, "number", b->number);
3127#else
c4093a6a 3128 printf_filtered ("%-3d ", b->number);
8b93c638 3129#endif
c4093a6a
JM
3130
3131 /* 2 */
3132 annotate_field (1);
3133 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3134 || ((int) b->type != bptypes[(int) b->type].type))
8e65ff28
AC
3135 internal_error (__FILE__, __LINE__,
3136 "bptypes table does not describe type #%d.",
c4093a6a 3137 (int) b->type);
8b93c638
JM
3138#ifdef UI_OUT
3139 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3140#else
c4093a6a 3141 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
8b93c638 3142#endif
c4093a6a
JM
3143
3144 /* 3 */
3145 annotate_field (2);
8b93c638
JM
3146#ifdef UI_OUT
3147 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3148#else
c4093a6a 3149 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
8b93c638 3150#endif
c4093a6a
JM
3151
3152 /* 4 */
3153 annotate_field (3);
8b93c638
JM
3154#ifdef UI_OUT
3155 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3156 ui_out_spaces (uiout, 2);
3157#else
c4093a6a 3158 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
8b93c638 3159#endif
c4093a6a
JM
3160
3161 /* 5 and 6 */
3162 strcpy (wrap_indent, " ");
3163 if (addressprint)
3164 strcat (wrap_indent, " ");
3165 switch (b->type)
c5aa993b 3166 {
c4093a6a 3167 case bp_none:
8e65ff28
AC
3168 internal_error (__FILE__, __LINE__,
3169 "print_one_breakpoint: bp_none encountered\n");
c4093a6a 3170 break;
c906108c 3171
c4093a6a
JM
3172 case bp_watchpoint:
3173 case bp_hardware_watchpoint:
3174 case bp_read_watchpoint:
3175 case bp_access_watchpoint:
3176 /* Field 4, the address, is omitted (which makes the columns
3177 not line up too nicely with the headers, but the effect
3178 is relatively readable). */
8b93c638
JM
3179#ifdef UI_OUT
3180 if (addressprint)
3181 ui_out_field_skip (uiout, "addr");
3182 annotate_field (5);
3183 print_expression (b->exp, stb->stream);
3184 ui_out_field_stream (uiout, "what", stb);
3185#else
c4093a6a
JM
3186 annotate_field (5);
3187 print_expression (b->exp, gdb_stdout);
8b93c638 3188#endif
c4093a6a
JM
3189 break;
3190
3191 case bp_catch_load:
3192 case bp_catch_unload:
3193 /* Field 4, the address, is omitted (which makes the columns
3194 not line up too nicely with the headers, but the effect
3195 is relatively readable). */
8b93c638
JM
3196#ifdef UI_OUT
3197 if (addressprint)
3198 ui_out_field_skip (uiout, "addr");
3199 annotate_field (5);
3200 if (b->dll_pathname == NULL)
3201 {
3202 ui_out_field_string (uiout, "what", "<any library>");
3203 ui_out_spaces (uiout, 1);
3204 }
3205 else
3206 {
3207 ui_out_text (uiout, "library \"");
3208 ui_out_field_string (uiout, "what", b->dll_pathname);
3209 ui_out_text (uiout, "\" ");
3210 }
3211#else
c4093a6a
JM
3212 annotate_field (5);
3213 if (b->dll_pathname == NULL)
3214 printf_filtered ("<any library> ");
3215 else
3216 printf_filtered ("library \"%s\" ", b->dll_pathname);
8b93c638 3217#endif
c4093a6a
JM
3218 break;
3219
3220 case bp_catch_fork:
3221 case bp_catch_vfork:
3222 /* Field 4, the address, is omitted (which makes the columns
3223 not line up too nicely with the headers, but the effect
3224 is relatively readable). */
8b93c638
JM
3225#ifdef UI_OUT
3226 if (addressprint)
3227 ui_out_field_skip (uiout, "addr");
3228 annotate_field (5);
3229 if (b->forked_inferior_pid != 0)
3230 {
3231 ui_out_text (uiout, "process ");
3232 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3233 ui_out_spaces (uiout, 1);
3234 }
3235#else
c4093a6a
JM
3236 annotate_field (5);
3237 if (b->forked_inferior_pid != 0)
3238 printf_filtered ("process %d ", b->forked_inferior_pid);
3239 break;
8b93c638 3240#endif
c4093a6a
JM
3241
3242 case bp_catch_exec:
3243 /* Field 4, the address, is omitted (which makes the columns
3244 not line up too nicely with the headers, but the effect
3245 is relatively readable). */
8b93c638
JM
3246#ifdef UI_OUT
3247 if (addressprint)
3248 ui_out_field_skip (uiout, "addr");
3249 annotate_field (5);
3250 if (b->exec_pathname != NULL)
3251 {
3252 ui_out_text (uiout, "program \"");
3253 ui_out_field_string (uiout, "what", b->exec_pathname);
3254 ui_out_text (uiout, "\" ");
3255 }
3256#else
c4093a6a
JM
3257 annotate_field (5);
3258 if (b->exec_pathname != NULL)
3259 printf_filtered ("program \"%s\" ", b->exec_pathname);
8b93c638 3260#endif
c4093a6a 3261 break;
c906108c 3262
c4093a6a
JM
3263 case bp_catch_catch:
3264 /* Field 4, the address, is omitted (which makes the columns
3265 not line up too nicely with the headers, but the effect
3266 is relatively readable). */
8b93c638
JM
3267#ifdef UI_OUT
3268 if (addressprint)
3269 ui_out_field_skip (uiout, "addr");
3270 annotate_field (5);
3271 ui_out_field_string (uiout, "what", "exception catch");
3272 ui_out_spaces (uiout, 1);
3273#else
c4093a6a
JM
3274 annotate_field (5);
3275 printf_filtered ("exception catch ");
8b93c638 3276#endif
c4093a6a 3277 break;
c906108c 3278
c4093a6a
JM
3279 case bp_catch_throw:
3280 /* Field 4, the address, is omitted (which makes the columns
3281 not line up too nicely with the headers, but the effect
3282 is relatively readable). */
8b93c638
JM
3283#ifdef UI_OUT
3284 if (addressprint)
3285 ui_out_field_skip (uiout, "addr");
3286 annotate_field (5);
3287 ui_out_field_string (uiout, "what", "exception throw");
3288 ui_out_spaces (uiout, 1);
3289#else
c4093a6a
JM
3290 annotate_field (5);
3291 printf_filtered ("exception throw ");
8b93c638 3292#endif
c4093a6a
JM
3293 break;
3294
3295 case bp_breakpoint:
3296 case bp_hardware_breakpoint:
3297 case bp_until:
3298 case bp_finish:
3299 case bp_longjmp:
3300 case bp_longjmp_resume:
3301 case bp_step_resume:
3302 case bp_through_sigtramp:
3303 case bp_watchpoint_scope:
3304 case bp_call_dummy:
3305 case bp_shlib_event:
3306 case bp_thread_event:
8b93c638
JM
3307#ifdef UI_OUT
3308 if (addressprint)
3309 {
3310 annotate_field (4);
3311 ui_out_field_core_addr (uiout, "addr", b->address);
3312 }
3313 annotate_field (5);
3314 *last_addr = b->address;
3315 if (b->source_file)
3316 {
3317 sym = find_pc_sect_function (b->address, b->section);
3318 if (sym)
3319 {
3320 ui_out_text (uiout, "in ");
3321 ui_out_field_string (uiout, "func",
3322 SYMBOL_SOURCE_NAME (sym));
3323 ui_out_wrap_hint (uiout, wrap_indent);
3324 ui_out_text (uiout, " at ");
3325 }
3326 ui_out_field_string (uiout, "file", b->source_file);
3327 ui_out_text (uiout, ":");
3328 ui_out_field_int (uiout, "line", b->line_number);
3329 }
3330 else
3331 {
3332 print_address_symbolic (b->address, stb->stream, demangle, "");
3333 ui_out_field_stream (uiout, "at", stb);
3334 }
3335#else
c5aa993b 3336 if (addressprint)
c5aa993b 3337 {
c4093a6a
JM
3338 annotate_field (4);
3339 /* FIXME-32x64: need a print_address_numeric with
3340 field width */
3341 printf_filtered
3342 ("%s ",
3343 local_hex_string_custom
3344 ((unsigned long) b->address, "08l"));
3345 }
3346 annotate_field (5);
3347 *last_addr = b->address;
3348 if (b->source_file)
3349 {
3350 sym = find_pc_sect_function (b->address, b->section);
3351 if (sym)
c5aa993b 3352 {
c4093a6a
JM
3353 fputs_filtered ("in ", gdb_stdout);
3354 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3355 wrap_here (wrap_indent);
3356 fputs_filtered (" at ", gdb_stdout);
c5aa993b 3357 }
c4093a6a
JM
3358 fputs_filtered (b->source_file, gdb_stdout);
3359 printf_filtered (":%d", b->line_number);
c5aa993b 3360 }
c4093a6a
JM
3361 else
3362 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
8b93c638 3363#endif
c4093a6a
JM
3364 break;
3365 }
3366
3367 if (b->thread != -1)
3368 {
8b93c638
JM
3369#ifdef UI_OUT
3370 /* FIXME: This seems to be redundant and lost here; see the
3371 "stop only in" line a little further down. */
3372 ui_out_text (uiout, " thread ");
3373 ui_out_field_int (uiout, "thread", b->thread);
3374#else
c4093a6a 3375 printf_filtered (" thread %d", b->thread);
8b93c638 3376#endif
c4093a6a
JM
3377 }
3378
8b93c638
JM
3379#ifdef UI_OUT
3380 ui_out_text (uiout, "\n");
3381#else
c4093a6a 3382 printf_filtered ("\n");
8b93c638 3383#endif
c4093a6a
JM
3384
3385 if (b->frame)
3386 {
3387 annotate_field (6);
8b93c638
JM
3388#ifdef UI_OUT
3389 ui_out_text (uiout, "\tstop only in stack frame at ");
3390 ui_out_field_core_addr (uiout, "frame", b->frame);
3391 ui_out_text (uiout, "\n");
3392#else
c4093a6a
JM
3393 printf_filtered ("\tstop only in stack frame at ");
3394 print_address_numeric (b->frame, 1, gdb_stdout);
c5aa993b 3395 printf_filtered ("\n");
8b93c638 3396#endif
c4093a6a
JM
3397 }
3398
3399 if (b->cond)
3400 {
3401 annotate_field (7);
8b93c638
JM
3402#ifdef UI_OUT
3403 ui_out_text (uiout, "\tstop only if ");
3404 print_expression (b->cond, stb->stream);
3405 ui_out_field_stream (uiout, "cond", stb);
3406 ui_out_text (uiout, "\n");
3407#else
c4093a6a
JM
3408 printf_filtered ("\tstop only if ");
3409 print_expression (b->cond, gdb_stdout);
3410 printf_filtered ("\n");
8b93c638 3411#endif
c4093a6a
JM
3412 }
3413
3414 if (b->thread != -1)
3415 {
3416 /* FIXME should make an annotation for this */
8b93c638
JM
3417#ifdef UI_OUT
3418 ui_out_text (uiout, "\tstop only in thread ");
3419 ui_out_field_int (uiout, "thread", b->thread);
3420 ui_out_text (uiout, "\n");
3421#else
c4093a6a 3422 printf_filtered ("\tstop only in thread %d\n", b->thread);
8b93c638 3423#endif
c4093a6a
JM
3424 }
3425
3426 if (show_breakpoint_hit_counts && b->hit_count)
3427 {
3428 /* FIXME should make an annotation for this */
8b93c638
JM
3429#ifdef UI_OUT
3430 if (ep_is_catchpoint (b))
3431 ui_out_text (uiout, "\tcatchpoint");
3432 else
3433 ui_out_text (uiout, "\tbreakpoint");
3434 ui_out_text (uiout, " already hit ");
3435 ui_out_field_int (uiout, "times", b->hit_count);
3436 if (b->hit_count == 1)
3437 ui_out_text (uiout, " time\n");
3438 else
3439 ui_out_text (uiout, " times\n");
3440#else
c4093a6a
JM
3441 if (ep_is_catchpoint (b))
3442 printf_filtered ("\tcatchpoint");
3443 else
3444 printf_filtered ("\tbreakpoint");
3445 printf_filtered (" already hit %d time%s\n",
3446 b->hit_count, (b->hit_count == 1 ? "" : "s"));
8b93c638 3447#endif
c4093a6a
JM
3448 }
3449
fb40c209
AC
3450#ifdef UI_OUT
3451 /* Output the count also if it is zero, but only if this is
3452 mi. FIXME: Should have a better test for this. */
3453 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3454 if (show_breakpoint_hit_counts && b->hit_count == 0)
3455 ui_out_field_int (uiout, "times", b->hit_count);
3456#endif
8b93c638 3457
c4093a6a
JM
3458 if (b->ignore_count)
3459 {
3460 annotate_field (8);
8b93c638
JM
3461#ifdef UI_OUT
3462 ui_out_text (uiout, "\tignore next ");
3463 ui_out_field_int (uiout, "ignore", b->ignore_count);
3464 ui_out_text (uiout, " hits\n");
3465#else
c4093a6a 3466 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
8b93c638 3467#endif
c4093a6a
JM
3468 }
3469
3470 if ((l = b->commands))
3471 {
3472 annotate_field (9);
8b93c638
JM
3473#ifdef UI_OUT
3474 ui_out_list_begin (uiout, "script");
3475 print_command_lines (uiout, l, 4);
3476 ui_out_list_end (uiout);
3477#else
c4093a6a 3478 while (l)
c5aa993b 3479 {
c4093a6a
JM
3480 print_command_line (l, 4, gdb_stdout);
3481 l = l->next;
c5aa993b 3482 }
8b93c638 3483#endif
c4093a6a 3484 }
8b93c638
JM
3485#ifdef UI_OUT
3486 ui_out_list_end (uiout);
3487 do_cleanups (old_chain);
3488#endif
c4093a6a 3489}
c5aa993b 3490
c4093a6a
JM
3491struct captured_breakpoint_query_args
3492 {
3493 int bnum;
3494 };
c5aa993b 3495
c4093a6a
JM
3496static int
3497do_captured_breakpoint_query (void *data)
3498{
3499 struct captured_breakpoint_query_args *args = data;
3500 register struct breakpoint *b;
3501 CORE_ADDR dummy_addr = 0;
3502 ALL_BREAKPOINTS (b)
3503 {
3504 if (args->bnum == b->number)
c5aa993b 3505 {
c4093a6a
JM
3506 print_one_breakpoint (b, &dummy_addr);
3507 return GDB_RC_OK;
c5aa993b 3508 }
c4093a6a
JM
3509 }
3510 return GDB_RC_NONE;
3511}
c5aa993b 3512
c4093a6a
JM
3513enum gdb_rc
3514gdb_breakpoint_query (/* output object, */ int bnum)
3515{
3516 struct captured_breakpoint_query_args args;
3517 args.bnum = bnum;
3518 /* For the moment we don't trust print_one_breakpoint() to not throw
3519 an error. */
3520 return catch_errors (do_captured_breakpoint_query, &args,
3521 NULL, RETURN_MASK_ALL);
3522}
c5aa993b 3523
c4093a6a
JM
3524/* Print information on breakpoint number BNUM, or -1 if all.
3525 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3526 is nonzero, process only watchpoints. */
c906108c 3527
c4093a6a 3528static void
fba45db2 3529breakpoint_1 (int bnum, int allflag)
c4093a6a
JM
3530{
3531 register struct breakpoint *b;
3532 CORE_ADDR last_addr = (CORE_ADDR) -1;
3533 int found_a_breakpoint = 0;
3534
8b93c638
JM
3535#ifdef UI_OUT
3536 if (addressprint)
3537 ui_out_table_begin (uiout, 6, "BreakpointTable");
3538 else
3539 ui_out_table_begin (uiout, 5, "BreakpointTable");
3540#endif /* UI_OUT */
3541
c4093a6a
JM
3542 ALL_BREAKPOINTS (b)
3543 if (bnum == -1
3544 || bnum == b->number)
3545 {
3546 /* We only print out user settable breakpoints unless the
3547 allflag is set. */
3548 if (!allflag
3549 && b->type != bp_breakpoint
3550 && b->type != bp_catch_load
3551 && b->type != bp_catch_unload
3552 && b->type != bp_catch_fork
3553 && b->type != bp_catch_vfork
3554 && b->type != bp_catch_exec
3555 && b->type != bp_catch_catch
3556 && b->type != bp_catch_throw
3557 && b->type != bp_hardware_breakpoint
3558 && b->type != bp_watchpoint
3559 && b->type != bp_read_watchpoint
3560 && b->type != bp_access_watchpoint
3561 && b->type != bp_hardware_watchpoint)
3562 continue;
3563
3564 if (!found_a_breakpoint++)
3565 {
3566 annotate_breakpoints_headers ();
8b93c638
JM
3567#ifdef UI_OUT
3568 annotate_field (0);
3569 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3570 annotate_field (1);
3571 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3572 annotate_field (2);
3573 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3574 annotate_field (3);
3575 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3576 if (addressprint)
3577 {
3578 annotate_field (4);
3579 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3580 }
3581 annotate_field (5);
3582 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3583 ui_out_table_body (uiout);
3584#else
c4093a6a
JM
3585 annotate_field (0);
3586 printf_filtered ("Num ");
3587 annotate_field (1);
3588 printf_filtered ("Type ");
3589 annotate_field (2);
3590 printf_filtered ("Disp ");
3591 annotate_field (3);
3592 printf_filtered ("Enb ");
3593 if (addressprint)
3594 {
3595 annotate_field (4);
3596 printf_filtered ("Address ");
3597 }
3598 annotate_field (5);
3599 printf_filtered ("What\n");
8b93c638 3600#endif /* UI_OUT */
c4093a6a
JM
3601 annotate_breakpoints_table ();
3602 }
3603
3604 print_one_breakpoint (b, &last_addr);
3605 }
3606
c906108c
SS
3607 if (!found_a_breakpoint)
3608 {
8b93c638
JM
3609#ifdef UI_OUT
3610 if (bnum == -1)
3611 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3612 else
3613 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3614 bnum);
3615#else
c906108c 3616 if (bnum == -1)
c5aa993b 3617 printf_filtered ("No breakpoints or watchpoints.\n");
c906108c 3618 else
c5aa993b 3619 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
8b93c638 3620#endif /* UI_OUT */
c906108c
SS
3621 }
3622 else
c4093a6a
JM
3623 {
3624 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3625 that a comparison of an unsigned with -1 is always false. */
3626 if (last_addr != (CORE_ADDR) -1)
3627 set_next_address (last_addr);
3628 }
c906108c 3629
8b93c638
JM
3630#ifdef UI_OUT
3631 ui_out_table_end (uiout);
3632#endif /* UI_OUT */
c4093a6a
JM
3633 /* FIXME? Should this be moved up so that it is only called when
3634 there have been breakpoints? */
c906108c
SS
3635 annotate_breakpoints_table_end ();
3636}
3637
3638/* ARGSUSED */
3639static void
fba45db2 3640breakpoints_info (char *bnum_exp, int from_tty)
c906108c
SS
3641{
3642 int bnum = -1;
3643
3644 if (bnum_exp)
bb518678 3645 bnum = parse_and_eval_long (bnum_exp);
c906108c
SS
3646
3647 breakpoint_1 (bnum, 0);
3648}
3649
c906108c 3650/* ARGSUSED */
7a292a7a 3651static void
fba45db2 3652maintenance_info_breakpoints (char *bnum_exp, int from_tty)
c906108c
SS
3653{
3654 int bnum = -1;
3655
3656 if (bnum_exp)
bb518678 3657 bnum = parse_and_eval_long (bnum_exp);
c906108c
SS
3658
3659 breakpoint_1 (bnum, 1);
3660}
3661
c906108c
SS
3662/* Print a message describing any breakpoints set at PC. */
3663
3664static void
fba45db2 3665describe_other_breakpoints (CORE_ADDR pc, asection *section)
c906108c
SS
3666{
3667 register int others = 0;
3668 register struct breakpoint *b;
3669
3670 ALL_BREAKPOINTS (b)
3671 if (b->address == pc)
c5aa993b
JM
3672 if (overlay_debugging == 0 ||
3673 b->section == section)
3674 others++;
c906108c
SS
3675 if (others > 0)
3676 {
3677 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3678 ALL_BREAKPOINTS (b)
3679 if (b->address == pc)
c5aa993b
JM
3680 if (overlay_debugging == 0 ||
3681 b->section == section)
3682 {
3683 others--;
3684 printf_filtered
3685 ("%d%s%s ",
3686 b->number,
53a5351d
JM
3687 ((b->enable == disabled ||
3688 b->enable == shlib_disabled ||
c2c6d25f
JM
3689 b->enable == call_disabled) ? " (disabled)"
3690 : b->enable == permanent ? " (permanent)"
3691 : ""),
c5aa993b
JM
3692 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3693 }
c906108c
SS
3694 printf_filtered ("also set at pc ");
3695 print_address_numeric (pc, 1, gdb_stdout);
3696 printf_filtered (".\n");
3697 }
3698}
3699\f
3700/* Set the default place to put a breakpoint
3701 for the `break' command with no arguments. */
3702
3703void
fba45db2
KB
3704set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3705 int line)
c906108c
SS
3706{
3707 default_breakpoint_valid = valid;
3708 default_breakpoint_address = addr;
3709 default_breakpoint_symtab = symtab;
3710 default_breakpoint_line = line;
3711}
3712
3713/* Rescan breakpoints at address ADDRESS,
3714 marking the first one as "first" and any others as "duplicates".
c2c6d25f
JM
3715 This is so that the bpt instruction is only inserted once.
3716 If we have a permanent breakpoint at ADDRESS, make that one
3717 the official one, and the rest as duplicates. */
c906108c
SS
3718
3719static void
fba45db2 3720check_duplicates (CORE_ADDR address, asection *section)
c906108c
SS
3721{
3722 register struct breakpoint *b;
3723 register int count = 0;
c2c6d25f 3724 struct breakpoint *perm_bp = 0;
c906108c
SS
3725
3726 if (address == 0) /* Watchpoints are uninteresting */
3727 return;
3728
3729 ALL_BREAKPOINTS (b)
3730 if (b->enable != disabled
3731 && b->enable != shlib_disabled
3732 && b->enable != call_disabled
3733 && b->address == address
3734 && (overlay_debugging == 0 || b->section == section))
c5aa993b 3735 {
c2c6d25f
JM
3736 /* Have we found a permanent breakpoint? */
3737 if (b->enable == permanent)
3738 {
3739 perm_bp = b;
3740 break;
3741 }
3742
c5aa993b
JM
3743 count++;
3744 b->duplicate = count > 1;
3745 }
c2c6d25f
JM
3746
3747 /* If we found a permanent breakpoint at this address, go over the
3748 list again and declare all the other breakpoints there to be the
3749 duplicates. */
3750 if (perm_bp)
3751 {
3752 perm_bp->duplicate = 0;
3753
3754 /* Permanent breakpoint should always be inserted. */
3755 if (! perm_bp->inserted)
8e65ff28
AC
3756 internal_error (__FILE__, __LINE__,
3757 "allegedly permanent breakpoint is not "
c2c6d25f
JM
3758 "actually inserted");
3759
3760 ALL_BREAKPOINTS (b)
3761 if (b != perm_bp)
3762 {
3763 if (b->inserted)
8e65ff28
AC
3764 internal_error (__FILE__, __LINE__,
3765 "another breakpoint was inserted on top of "
c2c6d25f
JM
3766 "a permanent breakpoint");
3767
3768 if (b->enable != disabled
3769 && b->enable != shlib_disabled
3770 && b->enable != call_disabled
3771 && b->address == address
3772 && (overlay_debugging == 0 || b->section == section))
3773 b->duplicate = 1;
3774 }
3775 }
c906108c
SS
3776}
3777
3778/* Low level routine to set a breakpoint.
3779 Takes as args the three things that every breakpoint must have.
3780 Returns the breakpoint object so caller can set other things.
3781 Does not set the breakpoint number!
3782 Does not print anything.
3783
3784 ==> This routine should not be called if there is a chance of later
3785 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3786 your arguments BEFORE calling this routine! */
3787
3788struct breakpoint *
fba45db2 3789set_raw_breakpoint (struct symtab_and_line sal)
c906108c
SS
3790{
3791 register struct breakpoint *b, *b1;
3792
3793 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3794 memset (b, 0, sizeof (*b));
3795 b->address = sal.pc;
3796 if (sal.symtab == NULL)
3797 b->source_file = NULL;
3798 else
3799 b->source_file = savestring (sal.symtab->filename,
3800 strlen (sal.symtab->filename));
3801 b->section = sal.section;
3802 b->language = current_language->la_language;
3803 b->input_radix = input_radix;
3804 b->thread = -1;
3805 b->line_number = sal.line;
3806 b->enable = enabled;
3807 b->next = 0;
3808 b->silent = 0;
3809 b->ignore_count = 0;
3810 b->commands = NULL;
3811 b->frame = 0;
3812 b->dll_pathname = NULL;
3813 b->triggered_dll_pathname = NULL;
3814 b->forked_inferior_pid = 0;
3815 b->exec_pathname = NULL;
3816
3817 /* Add this breakpoint to the end of the chain
3818 so that a list of breakpoints will come out in order
3819 of increasing numbers. */
3820
3821 b1 = breakpoint_chain;
3822 if (b1 == 0)
3823 breakpoint_chain = b;
3824 else
3825 {
3826 while (b1->next)
3827 b1 = b1->next;
3828 b1->next = b;
3829 }
3830
3831 check_duplicates (sal.pc, sal.section);
3832 breakpoints_changed ();
3833
3834 return b;
3835}
3836
c2c6d25f
JM
3837
3838/* Note that the breakpoint object B describes a permanent breakpoint
3839 instruction, hard-wired into the inferior's code. */
3840void
3841make_breakpoint_permanent (struct breakpoint *b)
3842{
3843 b->enable = permanent;
3844
3845 /* By definition, permanent breakpoints are already present in the code. */
3846 b->inserted = 1;
3847}
3848
c906108c
SS
3849#ifdef GET_LONGJMP_TARGET
3850
3851static void
fba45db2 3852create_longjmp_breakpoint (char *func_name)
c906108c
SS
3853{
3854 struct symtab_and_line sal;
3855 struct breakpoint *b;
3856
c5aa993b 3857 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3858 if (func_name != NULL)
3859 {
3860 struct minimal_symbol *m;
3861
53a5351d
JM
3862 m = lookup_minimal_symbol_text (func_name, NULL,
3863 (struct objfile *) NULL);
c906108c
SS
3864 if (m)
3865 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3866 else
3867 return;
3868 }
3869 sal.section = find_pc_overlay (sal.pc);
3870 b = set_raw_breakpoint (sal);
c5aa993b
JM
3871 if (!b)
3872 return;
c906108c
SS
3873
3874 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3875 b->disposition = donttouch;
3876 b->enable = disabled;
3877 b->silent = 1;
3878 if (func_name)
4fcf66da 3879 b->addr_string = xstrdup (func_name);
c906108c
SS
3880 b->number = internal_breakpoint_number--;
3881}
3882
c5aa993b 3883#endif /* #ifdef GET_LONGJMP_TARGET */
c906108c 3884
53a5351d
JM
3885/* Call this routine when stepping and nexting to enable a breakpoint
3886 if we do a longjmp(). When we hit that breakpoint, call
c906108c
SS
3887 set_longjmp_resume_breakpoint() to figure out where we are going. */
3888
3889void
fba45db2 3890enable_longjmp_breakpoint (void)
c906108c
SS
3891{
3892 register struct breakpoint *b;
3893
3894 ALL_BREAKPOINTS (b)
3895 if (b->type == bp_longjmp)
c5aa993b
JM
3896 {
3897 b->enable = enabled;
3898 check_duplicates (b->address, b->section);
3899 }
c906108c
SS
3900}
3901
3902void
fba45db2 3903disable_longjmp_breakpoint (void)
c906108c
SS
3904{
3905 register struct breakpoint *b;
3906
3907 ALL_BREAKPOINTS (b)
c5aa993b 3908 if (b->type == bp_longjmp
c906108c 3909 || b->type == bp_longjmp_resume)
c5aa993b
JM
3910 {
3911 b->enable = disabled;
3912 check_duplicates (b->address, b->section);
3913 }
c906108c
SS
3914}
3915
c4093a6a 3916struct breakpoint *
fba45db2 3917create_thread_event_breakpoint (CORE_ADDR address)
c4093a6a
JM
3918{
3919 struct breakpoint *b;
3920 struct symtab_and_line sal;
3921 char addr_string[80]; /* Surely an addr can't be longer than that. */
3922
3923 INIT_SAL (&sal); /* initialize to zeroes */
3924 sal.pc = address;
3925 sal.section = find_pc_overlay (sal.pc);
3926 if ((b = set_raw_breakpoint (sal)) == NULL)
3927 return NULL;
3928
3929 b->number = internal_breakpoint_number--;
3930 b->disposition = donttouch;
3931 b->type = bp_thread_event; /* XXX: do we need a new type?
3932 bp_thread_event */
3933 b->enable = enabled;
3934 /* addr_string has to be used or breakpoint_re_set will delete me. */
3935 sprintf (addr_string, "*0x%s", paddr (b->address));
4fcf66da 3936 b->addr_string = xstrdup (addr_string);
c4093a6a
JM
3937
3938 return b;
3939}
3940
3941void
3942remove_thread_event_breakpoints (void)
3943{
3944 struct breakpoint *b, *temp;
3945
3946 ALL_BREAKPOINTS_SAFE (b, temp)
3947 if (b->type == bp_thread_event)
3948 delete_breakpoint (b);
3949}
3950
c906108c
SS
3951#ifdef SOLIB_ADD
3952void
fba45db2 3953remove_solib_event_breakpoints (void)
c906108c
SS
3954{
3955 register struct breakpoint *b, *temp;
3956
3957 ALL_BREAKPOINTS_SAFE (b, temp)
3958 if (b->type == bp_shlib_event)
c5aa993b 3959 delete_breakpoint (b);
c906108c
SS
3960}
3961
c2c6d25f 3962struct breakpoint *
fba45db2 3963create_solib_event_breakpoint (CORE_ADDR address)
c906108c
SS
3964{
3965 struct breakpoint *b;
3966 struct symtab_and_line sal;
3967
c5aa993b 3968 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3969 sal.pc = address;
3970 sal.section = find_pc_overlay (sal.pc);
3971 b = set_raw_breakpoint (sal);
3972 b->number = internal_breakpoint_number--;
3973 b->disposition = donttouch;
3974 b->type = bp_shlib_event;
c2c6d25f
JM
3975
3976 return b;
c906108c
SS
3977}
3978
104c1213
JM
3979/* Disable any breakpoints that are on code in shared libraries. Only
3980 apply to enabled breakpoints, disabled ones can just stay disabled. */
3981
c906108c 3982void
fba45db2 3983disable_breakpoints_in_shlibs (int silent)
c906108c 3984{
c5aa993b
JM
3985 struct breakpoint *b;
3986 int disabled_shlib_breaks = 0;
c906108c
SS
3987
3988 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3989 ALL_BREAKPOINTS (b)
c5aa993b 3990 {
c906108c 3991#if defined (PC_SOLIB)
c5aa993b
JM
3992 if (((b->type == bp_breakpoint) ||
3993 (b->type == bp_hardware_breakpoint)) &&
104c1213 3994 b->enable == enabled &&
c5aa993b
JM
3995 !b->duplicate &&
3996 PC_SOLIB (b->address))
3997 {
3998 b->enable = shlib_disabled;
3999 if (!silent)
4000 {
4001 if (!disabled_shlib_breaks)
4002 {
4003 target_terminal_ours_for_output ();
53a5351d 4004 warning ("Temporarily disabling shared library breakpoints:");
c5aa993b
JM
4005 }
4006 disabled_shlib_breaks = 1;
53a5351d 4007 warning ("breakpoint #%d ", b->number);
c5aa993b
JM
4008 }
4009 }
c906108c 4010#endif
c5aa993b 4011 }
c906108c
SS
4012}
4013
4014/* Try to reenable any breakpoints in shared libraries. */
4015void
fba45db2 4016re_enable_breakpoints_in_shlibs (void)
c906108c
SS
4017{
4018 struct breakpoint *b;
4019
4020 ALL_BREAKPOINTS (b)
4021 if (b->enable == shlib_disabled)
c5aa993b
JM
4022 {
4023 char buf[1];
c906108c 4024
c5aa993b
JM
4025 /* Do not reenable the breakpoint if the shared library
4026 is still not mapped in. */
4027 if (target_read_memory (b->address, buf, 1) == 0)
4028 b->enable = enabled;
4029 }
c906108c
SS
4030}
4031
4032#endif
4033
4034static void
fba45db2
KB
4035solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4036 char *cond_string, enum bptype bp_kind)
c906108c 4037{
c5aa993b 4038 struct breakpoint *b;
c906108c 4039 struct symtabs_and_lines sals;
c5aa993b
JM
4040 struct cleanup *old_chain;
4041 struct cleanup *canonical_strings_chain = NULL;
c5aa993b
JM
4042 char *addr_start = hookname;
4043 char *addr_end = NULL;
4044 char **canonical = (char **) NULL;
4045 int thread = -1; /* All threads. */
4046
c906108c
SS
4047 /* Set a breakpoint on the specified hook. */
4048 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4049 addr_end = hookname;
c5aa993b 4050
c906108c
SS
4051 if (sals.nelts == 0)
4052 {
4053 warning ("Unable to set a breakpoint on dynamic linker callback.");
4054 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4055 warning ("GDB will be unable to track shl_load/shl_unload calls");
4056 return;
4057 }
4058 if (sals.nelts != 1)
4059 {
53a5351d 4060 warning ("Unable to set unique breakpoint on dynamic linker callback.");
c906108c
SS
4061 warning ("GDB will be unable to track shl_load/shl_unload calls");
4062 return;
4063 }
4064
53a5351d
JM
4065 /* Make sure that all storage allocated in decode_line_1 gets freed
4066 in case the following errors out. */
b8c9b27d 4067 old_chain = make_cleanup (xfree, sals.sals);
c5aa993b 4068 if (canonical != (char **) NULL)
c906108c 4069 {
b8c9b27d 4070 make_cleanup (xfree, canonical);
c906108c
SS
4071 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4072 if (canonical[0] != NULL)
b8c9b27d 4073 make_cleanup (xfree, canonical[0]);
c906108c 4074 }
c5aa993b 4075
c906108c 4076 resolve_sal_pc (&sals.sals[0]);
c5aa993b 4077
c906108c 4078 /* Remove the canonical strings from the cleanup, they are needed below. */
c5aa993b 4079 if (canonical != (char **) NULL)
c906108c 4080 discard_cleanups (canonical_strings_chain);
c5aa993b 4081
c906108c
SS
4082 b = set_raw_breakpoint (sals.sals[0]);
4083 set_breakpoint_count (breakpoint_count + 1);
4084 b->number = breakpoint_count;
4085 b->cond = NULL;
53a5351d
JM
4086 b->cond_string = (cond_string == NULL) ?
4087 NULL : savestring (cond_string, strlen (cond_string));
c906108c 4088 b->thread = thread;
c5aa993b
JM
4089
4090 if (canonical != (char **) NULL && canonical[0] != NULL)
c906108c
SS
4091 b->addr_string = canonical[0];
4092 else if (addr_start)
4093 b->addr_string = savestring (addr_start, addr_end - addr_start);
c5aa993b 4094
c906108c
SS
4095 b->enable = enabled;
4096 b->disposition = tempflag ? del : donttouch;
c5aa993b 4097
c906108c
SS
4098 if (dll_pathname == NULL)
4099 b->dll_pathname = NULL;
4100 else
4101 {
4102 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4103 strcpy (b->dll_pathname, dll_pathname);
4104 }
4105 b->type = bp_kind;
c5aa993b 4106
c906108c
SS
4107 mention (b);
4108 do_cleanups (old_chain);
4109}
4110
4111void
fba45db2
KB
4112create_solib_load_event_breakpoint (char *hookname, int tempflag,
4113 char *dll_pathname, char *cond_string)
c906108c 4114{
53a5351d
JM
4115 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4116 cond_string, bp_catch_load);
c906108c
SS
4117}
4118
4119void
fba45db2
KB
4120create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4121 char *dll_pathname, char *cond_string)
c906108c 4122{
53a5351d
JM
4123 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4124 cond_string, bp_catch_unload);
c906108c
SS
4125}
4126
4127static void
fba45db2
KB
4128create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4129 enum bptype bp_kind)
c906108c 4130{
c5aa993b
JM
4131 struct symtab_and_line sal;
4132 struct breakpoint *b;
4133 int thread = -1; /* All threads. */
4134
4135 INIT_SAL (&sal);
c906108c
SS
4136 sal.pc = 0;
4137 sal.symtab = NULL;
4138 sal.line = 0;
c5aa993b 4139
c906108c
SS
4140 b = set_raw_breakpoint (sal);
4141 set_breakpoint_count (breakpoint_count + 1);
4142 b->number = breakpoint_count;
4143 b->cond = NULL;
53a5351d
JM
4144 b->cond_string = (cond_string == NULL) ?
4145 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
4146 b->thread = thread;
4147 b->addr_string = NULL;
4148 b->enable = enabled;
4149 b->disposition = tempflag ? del : donttouch;
4150 b->forked_inferior_pid = 0;
c5aa993b 4151
c906108c 4152 b->type = bp_kind;
c5aa993b 4153
c906108c
SS
4154 mention (b);
4155}
4156
4157void
fba45db2 4158create_fork_event_catchpoint (int tempflag, char *cond_string)
c906108c
SS
4159{
4160 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4161}
c5aa993b 4162
c906108c 4163void
fba45db2 4164create_vfork_event_catchpoint (int tempflag, char *cond_string)
c906108c
SS
4165{
4166 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4167}
4168
4169void
fba45db2 4170create_exec_event_catchpoint (int tempflag, char *cond_string)
c906108c 4171{
c5aa993b
JM
4172 struct symtab_and_line sal;
4173 struct breakpoint *b;
4174 int thread = -1; /* All threads. */
c906108c 4175
c5aa993b 4176 INIT_SAL (&sal);
c906108c
SS
4177 sal.pc = 0;
4178 sal.symtab = NULL;
4179 sal.line = 0;
4180
4181 b = set_raw_breakpoint (sal);
4182 set_breakpoint_count (breakpoint_count + 1);
4183 b->number = breakpoint_count;
4184 b->cond = NULL;
53a5351d
JM
4185 b->cond_string = (cond_string == NULL) ?
4186 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
4187 b->thread = thread;
4188 b->addr_string = NULL;
4189 b->enable = enabled;
4190 b->disposition = tempflag ? del : donttouch;
4191
4192 b->type = bp_catch_exec;
4193
4194 mention (b);
4195}
4196
4197static int
fba45db2 4198hw_breakpoint_used_count (void)
c906108c
SS
4199{
4200 register struct breakpoint *b;
4201 int i = 0;
4202
4203 ALL_BREAKPOINTS (b)
c5aa993b
JM
4204 {
4205 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4206 i++;
4207 }
c906108c
SS
4208
4209 return i;
4210}
4211
4212static int
fba45db2 4213hw_watchpoint_used_count (enum bptype type, int *other_type_used)
c906108c
SS
4214{
4215 register struct breakpoint *b;
4216 int i = 0;
4217
4218 *other_type_used = 0;
4219 ALL_BREAKPOINTS (b)
c5aa993b
JM
4220 {
4221 if (b->enable == enabled)
4222 {
4223 if (b->type == type)
4224 i++;
4225 else if ((b->type == bp_hardware_watchpoint ||
4226 b->type == bp_read_watchpoint ||
4227 b->type == bp_access_watchpoint)
4228 && b->enable == enabled)
4229 *other_type_used = 1;
4230 }
4231 }
c906108c
SS
4232 return i;
4233}
4234
53a5351d
JM
4235/* Call this after hitting the longjmp() breakpoint. Use this to set
4236 a new breakpoint at the target of the jmp_buf.
c906108c 4237
53a5351d
JM
4238 FIXME - This ought to be done by setting a temporary breakpoint
4239 that gets deleted automatically... */
c906108c
SS
4240
4241void
fba45db2 4242set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
c906108c
SS
4243{
4244 register struct breakpoint *b;
4245
4246 ALL_BREAKPOINTS (b)
4247 if (b->type == bp_longjmp_resume)
c5aa993b
JM
4248 {
4249 b->address = pc;
4250 b->enable = enabled;
4251 if (frame != NULL)
4252 b->frame = frame->frame;
4253 else
4254 b->frame = 0;
4255 check_duplicates (b->address, b->section);
4256 return;
4257 }
c906108c
SS
4258}
4259
4260void
fba45db2 4261disable_watchpoints_before_interactive_call_start (void)
c906108c 4262{
c5aa993b 4263 struct breakpoint *b;
c906108c
SS
4264
4265 ALL_BREAKPOINTS (b)
c5aa993b
JM
4266 {
4267 if (((b->type == bp_watchpoint)
4268 || (b->type == bp_hardware_watchpoint)
4269 || (b->type == bp_read_watchpoint)
4270 || (b->type == bp_access_watchpoint)
4271 || ep_is_exception_catchpoint (b))
4272 && (b->enable == enabled))
4273 {
4274 b->enable = call_disabled;
4275 check_duplicates (b->address, b->section);
4276 }
4277 }
c906108c
SS
4278}
4279
4280void
fba45db2 4281enable_watchpoints_after_interactive_call_stop (void)
c906108c 4282{
c5aa993b 4283 struct breakpoint *b;
c906108c
SS
4284
4285 ALL_BREAKPOINTS (b)
c5aa993b
JM
4286 {
4287 if (((b->type == bp_watchpoint)
4288 || (b->type == bp_hardware_watchpoint)
4289 || (b->type == bp_read_watchpoint)
4290 || (b->type == bp_access_watchpoint)
4291 || ep_is_exception_catchpoint (b))
4292 && (b->enable == call_disabled))
4293 {
4294 b->enable = enabled;
4295 check_duplicates (b->address, b->section);
4296 }
4297 }
c906108c
SS
4298}
4299
4300
4301/* Set a breakpoint that will evaporate an end of command
4302 at address specified by SAL.
4303 Restrict it to frame FRAME if FRAME is nonzero. */
4304
4305struct breakpoint *
fba45db2
KB
4306set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4307 enum bptype type)
c906108c
SS
4308{
4309 register struct breakpoint *b;
4310 b = set_raw_breakpoint (sal);
4311 b->type = type;
4312 b->enable = enabled;
4313 b->disposition = donttouch;
4314 b->frame = (frame ? frame->frame : 0);
4315
4316 /* If we're debugging a multi-threaded program, then we
4317 want momentary breakpoints to be active in only a
4318 single thread of control. */
4319 if (in_thread_list (inferior_pid))
4320 b->thread = pid_to_thread_id (inferior_pid);
4321
4322 return b;
4323}
c906108c 4324\f
c5aa993b 4325
c906108c
SS
4326/* Tell the user we have just set a breakpoint B. */
4327
4328static void
fba45db2 4329mention (struct breakpoint *b)
c906108c
SS
4330{
4331 int say_where = 0;
8b93c638
JM
4332#ifdef UI_OUT
4333 struct cleanup *old_chain;
4334 struct ui_stream *stb;
4335
4336 stb = ui_out_stream_new (uiout);
b02eeafb 4337 old_chain = make_cleanup_ui_out_stream_delete (stb);
8b93c638 4338#endif /* UI_OUT */
c906108c
SS
4339
4340 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4341 watchpoint) other than breakpoint creation. It should be possible to
4342 clean this up and at the same time replace the random calls to
4343 breakpoint_changed with this hook, as has already been done for
4344 delete_breakpoint_hook and so on. */
4345 if (create_breakpoint_hook)
4346 create_breakpoint_hook (b);
104c1213 4347 breakpoint_create_event (b->number);
c906108c
SS
4348
4349 switch (b->type)
4350 {
4351 case bp_none:
4352 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4353 break;
8b93c638
JM
4354#ifdef UI_OUT
4355 case bp_watchpoint:
4356 ui_out_text (uiout, "Watchpoint ");
4357 ui_out_list_begin (uiout, "wpt");
4358 ui_out_field_int (uiout, "number", b->number);
4359 ui_out_text (uiout, ": ");
4360 print_expression (b->exp, stb->stream);
4361 ui_out_field_stream (uiout, "exp", stb);
4362 ui_out_list_end (uiout);
4363 break;
4364 case bp_hardware_watchpoint:
4365 ui_out_text (uiout, "Hardware watchpoint ");
4366 ui_out_list_begin (uiout, "wpt");
4367 ui_out_field_int (uiout, "number", b->number);
4368 ui_out_text (uiout, ": ");
4369 print_expression (b->exp, stb->stream);
4370 ui_out_field_stream (uiout, "exp", stb);
4371 ui_out_list_end (uiout);
4372 break;
4373#else
c906108c
SS
4374 case bp_watchpoint:
4375 printf_filtered ("Watchpoint %d: ", b->number);
4376 print_expression (b->exp, gdb_stdout);
4377 break;
4378 case bp_hardware_watchpoint:
4379 printf_filtered ("Hardware watchpoint %d: ", b->number);
4380 print_expression (b->exp, gdb_stdout);
4381 break;
8b93c638
JM
4382#endif
4383#ifdef UI_OUT
4384 case bp_read_watchpoint:
4385 ui_out_text (uiout, "Hardware read watchpoint ");
4386 ui_out_list_begin (uiout, "hw-rwpt");
4387 ui_out_field_int (uiout, "number", b->number);
4388 ui_out_text (uiout, ": ");
4389 print_expression (b->exp, stb->stream);
4390 ui_out_field_stream (uiout, "exp", stb);
4391 ui_out_list_end (uiout);
4392 break;
4393 case bp_access_watchpoint:
4394 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4395 ui_out_list_begin (uiout, "hw-awpt");
4396 ui_out_field_int (uiout, "number", b->number);
4397 ui_out_text (uiout, ": ");
4398 print_expression (b->exp, stb->stream);
4399 ui_out_field_stream (uiout, "exp", stb);
4400 ui_out_list_end (uiout);
4401 break;
4402#else
c906108c
SS
4403 case bp_read_watchpoint:
4404 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4405 print_expression (b->exp, gdb_stdout);
4406 break;
4407 case bp_access_watchpoint:
53a5351d
JM
4408 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4409 b->number);
c906108c
SS
4410 print_expression (b->exp, gdb_stdout);
4411 break;
8b93c638 4412#endif
c906108c 4413 case bp_breakpoint:
fb40c209
AC
4414#ifdef UI_OUT
4415 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4416 {
4417 say_where = 0;
4418 break;
4419 }
4420#endif
c906108c
SS
4421 printf_filtered ("Breakpoint %d", b->number);
4422 say_where = 1;
4423 break;
4424 case bp_hardware_breakpoint:
fb40c209
AC
4425#ifdef UI_OUT
4426 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4427 {
4428 say_where = 0;
4429 break;
4430 }
4431#endif
c906108c
SS
4432 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4433 say_where = 1;
4434 break;
4435 case bp_catch_load:
4436 case bp_catch_unload:
4437 printf_filtered ("Catchpoint %d (%s %s)",
c5aa993b
JM
4438 b->number,
4439 (b->type == bp_catch_load) ? "load" : "unload",
53a5351d
JM
4440 (b->dll_pathname != NULL) ?
4441 b->dll_pathname : "<any library>");
c906108c
SS
4442 break;
4443 case bp_catch_fork:
4444 case bp_catch_vfork:
4445 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
4446 b->number,
4447 (b->type == bp_catch_fork) ? "fork" : "vfork");
c906108c
SS
4448 break;
4449 case bp_catch_exec:
4450 printf_filtered ("Catchpoint %d (exec)",
c5aa993b 4451 b->number);
c906108c
SS
4452 break;
4453 case bp_catch_catch:
4454 case bp_catch_throw:
4455 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
4456 b->number,
4457 (b->type == bp_catch_catch) ? "catch" : "throw");
c906108c
SS
4458 break;
4459
4460 case bp_until:
4461 case bp_finish:
4462 case bp_longjmp:
4463 case bp_longjmp_resume:
4464 case bp_step_resume:
4465 case bp_through_sigtramp:
4466 case bp_call_dummy:
4467 case bp_watchpoint_scope:
4468 case bp_shlib_event:
c4093a6a 4469 case bp_thread_event:
c906108c
SS
4470 break;
4471 }
4472 if (say_where)
4473 {
4474 if (addressprint || b->source_file == NULL)
4475 {
4476 printf_filtered (" at ");
4477 print_address_numeric (b->address, 1, gdb_stdout);
4478 }
4479 if (b->source_file)
4480 printf_filtered (": file %s, line %d.",
4481 b->source_file, b->line_number);
c5aa993b
JM
4482 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4483 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
c906108c 4484 }
8b93c638
JM
4485#ifdef UI_OUT
4486 do_cleanups (old_chain);
fb40c209
AC
4487#endif
4488#ifdef UI_OUT
4489 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4490 return;
8b93c638 4491#endif
c906108c
SS
4492 printf_filtered ("\n");
4493}
c906108c 4494\f
c5aa993b 4495
c3f6f71d
JM
4496/* Add SALS.nelts breakpoints to the breakpoint table. For each
4497 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4498 COND[i] and COND_STRING[i] values.
4499
4500 NOTE: If the function succeeds, the caller is expected to cleanup
4501 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4502 array contents). If the function fails (error() is called), the
4503 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4504 COND and SALS arrays and each of those arrays contents. */
c906108c
SS
4505
4506static void
c3f6f71d
JM
4507create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4508 struct expression **cond, char **cond_string,
4509 enum bptype type, enum bpdisp disposition,
4510 int thread, int ignore_count, int from_tty)
c906108c 4511{
c3f6f71d
JM
4512 if (type == bp_hardware_breakpoint)
4513 {
4514 int i = hw_breakpoint_used_count ();
4515 int target_resources_ok =
4516 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4517 i + sals.nelts, 0);
4518 if (target_resources_ok == 0)
4519 error ("No hardware breakpoint support in the target.");
4520 else if (target_resources_ok < 0)
4521 error ("Hardware breakpoints used exceeds limit.");
4522 }
c906108c 4523
c3f6f71d
JM
4524 /* Now set all the breakpoints. */
4525 {
4526 int i;
4527 for (i = 0; i < sals.nelts; i++)
4528 {
4529 struct breakpoint *b;
4530 struct symtab_and_line sal = sals.sals[i];
c906108c 4531
c3f6f71d
JM
4532 if (from_tty)
4533 describe_other_breakpoints (sal.pc, sal.section);
4534
4535 b = set_raw_breakpoint (sal);
4536 set_breakpoint_count (breakpoint_count + 1);
4537 b->number = breakpoint_count;
4538 b->type = type;
4539 b->cond = cond[i];
4540 b->thread = thread;
4541 b->addr_string = addr_string[i];
4542 b->cond_string = cond_string[i];
4543 b->ignore_count = ignore_count;
4544 b->enable = enabled;
4545 b->disposition = disposition;
4546 mention (b);
4547 }
4548 }
4549}
c906108c 4550
c3f6f71d
JM
4551/* Parse ARG which is assumed to be a SAL specification possibly
4552 followed by conditionals. On return, SALS contains an array of SAL
4553 addresses found. ADDR_STRING contains a vector of (canonical)
4554 address strings. ARG points to the end of the SAL. */
c906108c 4555
c3f6f71d
JM
4556void
4557parse_breakpoint_sals (char **address,
4558 struct symtabs_and_lines *sals,
4559 char ***addr_string)
4560{
4561 char *addr_start = *address;
4562 *addr_string = NULL;
4563 /* If no arg given, or if first arg is 'if ', use the default
4564 breakpoint. */
4565 if ((*address) == NULL
4566 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
c906108c
SS
4567 {
4568 if (default_breakpoint_valid)
4569 {
c3f6f71d
JM
4570 struct symtab_and_line sal;
4571 INIT_SAL (&sal); /* initialize to zeroes */
4572 sals->sals = (struct symtab_and_line *)
c906108c
SS
4573 xmalloc (sizeof (struct symtab_and_line));
4574 sal.pc = default_breakpoint_address;
4575 sal.line = default_breakpoint_line;
4576 sal.symtab = default_breakpoint_symtab;
c5aa993b 4577 sal.section = find_pc_overlay (sal.pc);
c3f6f71d
JM
4578 sals->sals[0] = sal;
4579 sals->nelts = 1;
c906108c
SS
4580 }
4581 else
4582 error ("No default breakpoint address now.");
4583 }
4584 else
4585 {
c906108c 4586 /* Force almost all breakpoints to be in terms of the
c5aa993b
JM
4587 current_source_symtab (which is decode_line_1's default). This
4588 should produce the results we want almost all of the time while
4589 leaving default_breakpoint_* alone. */
c906108c
SS
4590 if (default_breakpoint_valid
4591 && (!current_source_symtab
c3f6f71d
JM
4592 || (strchr ("+-", (*address)[0]) != NULL)))
4593 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4594 default_breakpoint_line, addr_string);
c906108c 4595 else
c3f6f71d 4596 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
c906108c 4597 }
c3f6f71d
JM
4598 /* For any SAL that didn't have a canonical string, fill one in. */
4599 if (sals->nelts > 0 && *addr_string == NULL)
4600 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4601 if (addr_start != (*address))
c906108c 4602 {
c3f6f71d
JM
4603 int i;
4604 for (i = 0; i < sals->nelts; i++)
c906108c 4605 {
c3f6f71d
JM
4606 /* Add the string if not present. */
4607 if ((*addr_string)[i] == NULL)
4608 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
c906108c
SS
4609 }
4610 }
c3f6f71d 4611}
c906108c 4612
c906108c 4613
c3f6f71d
JM
4614/* Convert each SAL into a real PC. Verify that the PC can be
4615 inserted as a breakpoint. If it can't throw an error. */
c906108c 4616
c3f6f71d
JM
4617void
4618breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4619 char *address)
4620{
4621 int i;
4622 for (i = 0; i < sals->nelts; i++)
4623 {
4624 resolve_sal_pc (&sals->sals[i]);
c906108c
SS
4625
4626 /* It's possible for the PC to be nonzero, but still an illegal
4627 value on some targets.
4628
4629 For example, on HP-UX if you start gdb, and before running the
4630 inferior you try to set a breakpoint on a shared library function
4631 "foo" where the inferior doesn't call "foo" directly but does
4632 pass its address to another function call, then we do find a
4633 minimal symbol for the "foo", but it's address is invalid.
4634 (Appears to be an index into a table that the loader sets up
4635 when the inferior is run.)
4636
4637 Give the target a chance to bless sals.sals[i].pc before we
4638 try to make a breakpoint for it. */
c3f6f71d 4639 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
c5aa993b 4640 {
c3f6f71d
JM
4641 if (address == NULL)
4642 error ("Cannot break without a running program.");
4643 else
4644 error ("Cannot break on %s without a running program.",
4645 address);
c5aa993b 4646 }
c3f6f71d
JM
4647 }
4648}
4649
4650/* Set a breakpoint according to ARG (function, linenum or *address)
4651 flag: first bit : 0 non-temporary, 1 temporary.
4652 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
c5aa993b 4653
c3f6f71d 4654static void
fba45db2 4655break_command_1 (char *arg, int flag, int from_tty)
c3f6f71d
JM
4656{
4657 int tempflag, hardwareflag;
4658 struct symtabs_and_lines sals;
4659 register struct expression **cond = 0;
4660 /* Pointers in arg to the start, and one past the end, of the
4661 condition. */
4662 char **cond_string = (char **) NULL;
4663 char *addr_start = arg;
4664 char **addr_string;
4665 struct cleanup *old_chain;
4666 struct cleanup *breakpoint_chain = NULL;
4667 int i;
4668 int thread = -1;
4669 int ignore_count = 0;
4670
4671 hardwareflag = flag & BP_HARDWAREFLAG;
4672 tempflag = flag & BP_TEMPFLAG;
c906108c 4673
c3f6f71d
JM
4674 sals.sals = NULL;
4675 sals.nelts = 0;
4676 addr_string = NULL;
4677 parse_breakpoint_sals (&arg, &sals, &addr_string);
4678
4679 if (!sals.nelts)
4680 return;
4681
4682 /* Create a chain of things that always need to be cleaned up. */
4683 old_chain = make_cleanup (null_cleanup, 0);
4684
4685 /* Make sure that all storage allocated to SALS gets freed. */
b8c9b27d 4686 make_cleanup (xfree, sals.sals);
c3f6f71d
JM
4687
4688 /* Cleanup the addr_string array but not its contents. */
b8c9b27d 4689 make_cleanup (xfree, addr_string);
c3f6f71d
JM
4690
4691 /* Allocate space for all the cond expressions. */
4692 cond = xcalloc (sals.nelts, sizeof (struct expression *));
b8c9b27d 4693 make_cleanup (xfree, cond);
c3f6f71d
JM
4694
4695 /* Allocate space for all the cond strings. */
4696 cond_string = xcalloc (sals.nelts, sizeof (char **));
b8c9b27d 4697 make_cleanup (xfree, cond_string);
c3f6f71d
JM
4698
4699 /* ----------------------------- SNIP -----------------------------
4700 Anything added to the cleanup chain beyond this point is assumed
4701 to be part of a breakpoint. If the breakpoint create succeeds
4702 then the memory is not reclaimed. */
4703 breakpoint_chain = make_cleanup (null_cleanup, 0);
4704
4705 /* Mark the contents of the addr_string for cleanup. These go on
4706 the breakpoint_chain and only occure if the breakpoint create
4707 fails. */
4708 for (i = 0; i < sals.nelts; i++)
4709 {
4710 if (addr_string[i] != NULL)
b8c9b27d 4711 make_cleanup (xfree, addr_string[i]);
c3f6f71d
JM
4712 }
4713
4714 /* Resolve all line numbers to PC's and verify that the addresses
4715 are ok for the target. */
4716 breakpoint_sals_to_pc (&sals, addr_start);
4717
4718 /* Verify that condition can be parsed, before setting any
4719 breakpoints. Allocate a separate condition expression for each
4720 breakpoint. */
4721 thread = -1; /* No specific thread yet */
4722 for (i = 0; i < sals.nelts; i++)
4723 {
4724 char *tok = arg;
c906108c
SS
4725 while (tok && *tok)
4726 {
c3f6f71d
JM
4727 char *end_tok;
4728 int toklen;
4729 char *cond_start = NULL;
4730 char *cond_end = NULL;
c906108c
SS
4731 while (*tok == ' ' || *tok == '\t')
4732 tok++;
4733
4734 end_tok = tok;
4735
4736 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4737 end_tok++;
4738
4739 toklen = end_tok - tok;
4740
4741 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4742 {
4743 tok = cond_start = end_tok + 1;
c3f6f71d 4744 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
b8c9b27d 4745 make_cleanup (xfree, cond[i]);
c906108c 4746 cond_end = tok;
c3f6f71d 4747 cond_string[i] = savestring (cond_start, cond_end - cond_start);
b8c9b27d 4748 make_cleanup (xfree, cond_string[i]);
c906108c
SS
4749 }
4750 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4751 {
4752 char *tmptok;
4753
4754 tok = end_tok + 1;
4755 tmptok = tok;
4756 thread = strtol (tok, &tok, 0);
4757 if (tok == tmptok)
4758 error ("Junk after thread keyword.");
4759 if (!valid_thread_id (thread))
4760 error ("Unknown thread %d\n", thread);
4761 }
4762 else
4763 error ("Junk at end of arguments.");
4764 }
4765 }
c906108c 4766
c3f6f71d
JM
4767 create_breakpoints (sals, addr_string, cond, cond_string,
4768 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4769 tempflag ? del : donttouch,
4770 thread, ignore_count, from_tty);
4771
4772 if (sals.nelts > 1)
4773 {
4774 warning ("Multiple breakpoints were set.");
4775 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 4776 }
c3f6f71d
JM
4777 /* That's it. Discard the cleanups for data inserted into the
4778 breakpoint. */
4779 discard_cleanups (breakpoint_chain);
4780 /* But cleanup everything else. */
4781 do_cleanups (old_chain);
4782}
c906108c 4783
c3f6f71d
JM
4784/* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4785 linenum or *address) with COND and IGNORE_COUNT. */
c906108c 4786
c3f6f71d
JM
4787struct captured_breakpoint_args
4788 {
4789 char *address;
4790 char *condition;
4791 int hardwareflag;
4792 int tempflag;
4793 int thread;
4794 int ignore_count;
4795 };
4796
4797static int
4798do_captured_breakpoint (void *data)
4799{
4800 struct captured_breakpoint_args *args = data;
4801 struct symtabs_and_lines sals;
4802 register struct expression **cond;
4803 struct cleanup *old_chain;
4804 struct cleanup *breakpoint_chain = NULL;
4805 int i;
4806 char **addr_string;
4807 char **cond_string;
4808
4809 char *address_end;
4810
4811 /* Parse the source and lines spec. Delay check that the expression
4812 didn't contain trailing garbage until after cleanups are in
4813 place. */
4814 sals.sals = NULL;
4815 sals.nelts = 0;
4816 address_end = args->address;
4817 addr_string = NULL;
4818 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4819
4820 if (!sals.nelts)
4821 return GDB_RC_NONE;
4822
4823 /* Create a chain of things at always need to be cleaned up. */
4824 old_chain = make_cleanup (null_cleanup, 0);
4825
4826 /* Always have a addr_string array, even if it is empty. */
b8c9b27d 4827 make_cleanup (xfree, addr_string);
c3f6f71d
JM
4828
4829 /* Make sure that all storage allocated to SALS gets freed. */
b8c9b27d 4830 make_cleanup (xfree, sals.sals);
c3f6f71d
JM
4831
4832 /* Allocate space for all the cond expressions. */
4833 cond = xcalloc (sals.nelts, sizeof (struct expression *));
b8c9b27d 4834 make_cleanup (xfree, cond);
c3f6f71d
JM
4835
4836 /* Allocate space for all the cond strings. */
4837 cond_string = xcalloc (sals.nelts, sizeof (char **));
b8c9b27d 4838 make_cleanup (xfree, cond_string);
c3f6f71d
JM
4839
4840 /* ----------------------------- SNIP -----------------------------
4841 Anything added to the cleanup chain beyond this point is assumed
4842 to be part of a breakpoint. If the breakpoint create goes
4843 through then that memory is not cleaned up. */
4844 breakpoint_chain = make_cleanup (null_cleanup, 0);
4845
4846 /* Mark the contents of the addr_string for cleanup. These go on
4847 the breakpoint_chain and only occure if the breakpoint create
4848 fails. */
c906108c
SS
4849 for (i = 0; i < sals.nelts; i++)
4850 {
c3f6f71d 4851 if (addr_string[i] != NULL)
b8c9b27d 4852 make_cleanup (xfree, addr_string[i]);
c906108c
SS
4853 }
4854
c3f6f71d
JM
4855 /* Wait until now before checking for garbage at the end of the
4856 address. That way cleanups can take care of freeing any
4857 memory. */
4858 if (*address_end != '\0')
4859 error ("Garbage %s following breakpoint address", address_end);
4860
4861 /* Resolve all line numbers to PC's. */
4862 breakpoint_sals_to_pc (&sals, args->address);
4863
4864 /* Verify that conditions can be parsed, before setting any
4865 breakpoints. */
4866 for (i = 0; i < sals.nelts; i++)
c906108c 4867 {
c3f6f71d
JM
4868 if (args->condition != NULL)
4869 {
4870 char *tok = args->condition;
4871 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4872 if (*tok != '\0')
4873 error ("Garbage %s follows condition", tok);
b8c9b27d 4874 make_cleanup (xfree, cond[i]);
c3f6f71d
JM
4875 cond_string[i] = xstrdup (args->condition);
4876 }
c906108c 4877 }
c3f6f71d
JM
4878
4879 create_breakpoints (sals, addr_string, cond, cond_string,
4880 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4881 args->tempflag ? del : donttouch,
4882 args->thread, args->ignore_count, 0/*from-tty*/);
4883
4884 /* That's it. Discard the cleanups for data inserted into the
4885 breakpoint. */
4886 discard_cleanups (breakpoint_chain);
4887 /* But cleanup everything else. */
c906108c 4888 do_cleanups (old_chain);
c3f6f71d 4889 return GDB_RC_OK;
c906108c
SS
4890}
4891
c3f6f71d
JM
4892enum gdb_rc
4893gdb_breakpoint (char *address, char *condition,
4894 int hardwareflag, int tempflag,
4895 int thread, int ignore_count)
4896{
4897 struct captured_breakpoint_args args;
4898 args.address = address;
4899 args.condition = condition;
4900 args.hardwareflag = hardwareflag;
4901 args.tempflag = tempflag;
4902 args.thread = thread;
4903 args.ignore_count = ignore_count;
4904 return catch_errors (do_captured_breakpoint, &args,
4905 NULL, RETURN_MASK_ALL);
4906}
4907
4908
c906108c 4909static void
fba45db2 4910break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
c906108c
SS
4911{
4912 struct frame_info *frame;
4913 CORE_ADDR low, high, selected_pc = 0;
7f7e9482
AC
4914 char *extra_args = NULL;
4915 char *level_arg;
4916 char *addr_string;
c906108c
SS
4917 int extra_args_len = 0, if_arg = 0;
4918
4919 if (!arg ||
4920 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4921 {
4922
4923 if (default_breakpoint_valid)
4924 {
4925 if (selected_frame)
4926 {
4927 selected_pc = selected_frame->pc;
4928 if (arg)
4929 if_arg = 1;
4930 }
4931 else
4932 error ("No selected frame.");
4933 }
4934 else
4935 error ("No default breakpoint address now.");
4936 }
4937 else
4938 {
4939 extra_args = strchr (arg, ' ');
4940 if (extra_args)
4941 {
4942 extra_args++;
4943 extra_args_len = strlen (extra_args);
4944 level_arg = (char *) xmalloc (extra_args - arg);
4945 strncpy (level_arg, arg, extra_args - arg - 1);
4946 level_arg[extra_args - arg - 1] = '\0';
4947 }
4948 else
4949 {
4950 level_arg = (char *) xmalloc (strlen (arg) + 1);
4951 strcpy (level_arg, arg);
4952 }
4953
4954 frame = parse_frame_specification (level_arg);
4955 if (frame)
4956 selected_pc = frame->pc;
4957 else
4958 selected_pc = 0;
4959 }
4960 if (if_arg)
4961 {
4962 extra_args = arg;
c5aa993b 4963 extra_args_len = strlen (arg);
c906108c
SS
4964 }
4965
4966 if (selected_pc)
4967 {
c5aa993b 4968 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
c906108c
SS
4969 {
4970 addr_string = (char *) xmalloc (26 + extra_args_len);
4971 if (extra_args_len)
d4f3574e 4972 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
c906108c 4973 else
d4f3574e 4974 sprintf (addr_string, "*0x%s", paddr_nz (high));
c906108c 4975 break_command_1 (addr_string, flag, from_tty);
b8c9b27d 4976 xfree (addr_string);
c906108c
SS
4977 }
4978 else
4979 error ("No function contains the specified address");
4980 }
4981 else
4982 error ("Unable to set breakpoint at procedure exit");
4983}
4984
4985
4986static void
fba45db2 4987break_at_finish_command_1 (char *arg, int flag, int from_tty)
c906108c
SS
4988{
4989 char *addr_string, *break_string, *beg_addr_string;
4990 CORE_ADDR low, high;
4991 struct symtabs_and_lines sals;
4992 struct symtab_and_line sal;
4993 struct cleanup *old_chain;
7f7e9482 4994 char *extra_args = NULL;
c906108c
SS
4995 int extra_args_len = 0;
4996 int i, if_arg = 0;
4997
4998 if (!arg ||
4999 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5000 {
5001 if (default_breakpoint_valid)
5002 {
5003 if (selected_frame)
5004 {
5005 addr_string = (char *) xmalloc (15);
d4f3574e 5006 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
c906108c
SS
5007 if (arg)
5008 if_arg = 1;
5009 }
5010 else
5011 error ("No selected frame.");
5012 }
5013 else
5014 error ("No default breakpoint address now.");
5015 }
5016 else
5017 {
5018 addr_string = (char *) xmalloc (strlen (arg) + 1);
5019 strcpy (addr_string, arg);
5020 }
5021
5022 if (if_arg)
5023 {
5024 extra_args = arg;
c5aa993b
JM
5025 extra_args_len = strlen (arg);
5026 }
5027 else if (arg)
5028 {
5029 /* get the stuff after the function name or address */
5030 extra_args = strchr (arg, ' ');
5031 if (extra_args)
5032 {
5033 extra_args++;
5034 extra_args_len = strlen (extra_args);
5035 }
c906108c 5036 }
c906108c
SS
5037
5038 sals.sals = NULL;
5039 sals.nelts = 0;
5040
c5aa993b
JM
5041 beg_addr_string = addr_string;
5042 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5043 (char ***) NULL);
c906108c 5044
b8c9b27d
KB
5045 xfree (beg_addr_string);
5046 old_chain = make_cleanup (xfree, sals.sals);
c906108c
SS
5047 for (i = 0; (i < sals.nelts); i++)
5048 {
5049 sal = sals.sals[i];
c5aa993b 5050 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
c906108c
SS
5051 {
5052 break_string = (char *) xmalloc (extra_args_len + 26);
5053 if (extra_args_len)
d4f3574e 5054 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
c906108c 5055 else
d4f3574e 5056 sprintf (break_string, "*0x%s", paddr_nz (high));
c906108c 5057 break_command_1 (break_string, flag, from_tty);
b8c9b27d 5058 xfree (break_string);
c906108c
SS
5059 }
5060 else
5061 error ("No function contains the specified address");
5062 }
5063 if (sals.nelts > 1)
5064 {
53a5351d
JM
5065 warning ("Multiple breakpoints were set.\n");
5066 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 5067 }
c5aa993b 5068 do_cleanups (old_chain);
c906108c
SS
5069}
5070
5071
5072/* Helper function for break_command_1 and disassemble_command. */
5073
5074void
fba45db2 5075resolve_sal_pc (struct symtab_and_line *sal)
c906108c
SS
5076{
5077 CORE_ADDR pc;
5078
5079 if (sal->pc == 0 && sal->symtab != NULL)
5080 {
5081 if (!find_line_pc (sal->symtab, sal->line, &pc))
5082 error ("No line %d in file \"%s\".",
5083 sal->line, sal->symtab->filename);
5084 sal->pc = pc;
5085 }
5086
5087 if (sal->section == 0 && sal->symtab != NULL)
5088 {
5089 struct blockvector *bv;
c5aa993b
JM
5090 struct block *b;
5091 struct symbol *sym;
5092 int index;
c906108c 5093
c5aa993b 5094 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
c906108c
SS
5095 if (bv != NULL)
5096 {
c5aa993b 5097 b = BLOCKVECTOR_BLOCK (bv, index);
c906108c
SS
5098 sym = block_function (b);
5099 if (sym != NULL)
5100 {
5101 fixup_symbol_section (sym, sal->symtab->objfile);
5102 sal->section = SYMBOL_BFD_SECTION (sym);
5103 }
5104 else
5105 {
5106 /* It really is worthwhile to have the section, so we'll just
c5aa993b
JM
5107 have to look harder. This case can be executed if we have
5108 line numbers but no functions (as can happen in assembly
5109 source). */
c906108c 5110
c5aa993b 5111 struct minimal_symbol *msym;
c906108c
SS
5112
5113 msym = lookup_minimal_symbol_by_pc (sal->pc);
5114 if (msym)
5115 sal->section = SYMBOL_BFD_SECTION (msym);
5116 }
5117 }
5118 }
5119}
5120
5121void
fba45db2 5122break_command (char *arg, int from_tty)
c906108c
SS
5123{
5124 break_command_1 (arg, 0, from_tty);
5125}
5126
7a292a7a 5127static void
fba45db2 5128break_at_finish_command (char *arg, int from_tty)
c906108c
SS
5129{
5130 break_at_finish_command_1 (arg, 0, from_tty);
5131}
5132
7a292a7a 5133static void
fba45db2 5134break_at_finish_at_depth_command (char *arg, int from_tty)
c906108c
SS
5135{
5136 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5137}
5138
5139void
fba45db2 5140tbreak_command (char *arg, int from_tty)
c906108c
SS
5141{
5142 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5143}
5144
7a292a7a 5145static void
fba45db2 5146tbreak_at_finish_command (char *arg, int from_tty)
c906108c
SS
5147{
5148 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5149}
5150
5151static void
fba45db2 5152hbreak_command (char *arg, int from_tty)
c906108c
SS
5153{
5154 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5155}
5156
5157static void
fba45db2 5158thbreak_command (char *arg, int from_tty)
c906108c
SS
5159{
5160 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5161}
5162
5163static void
fba45db2 5164stop_command (char *arg, int from_tty)
c906108c
SS
5165{
5166 printf_filtered ("Specify the type of breakpoint to set.\n\
5167Usage: stop in <function | address>\n\
5168 stop at <line>\n");
5169}
5170
5171static void
fba45db2 5172stopin_command (char *arg, int from_tty)
c906108c
SS
5173{
5174 int badInput = 0;
5175
c5aa993b 5176 if (arg == (char *) NULL)
c906108c
SS
5177 badInput = 1;
5178 else if (*arg != '*')
5179 {
5180 char *argptr = arg;
5181 int hasColon = 0;
5182
53a5351d
JM
5183 /* look for a ':'. If this is a line number specification, then
5184 say it is bad, otherwise, it should be an address or
5185 function/method name */
c906108c 5186 while (*argptr && !hasColon)
c5aa993b
JM
5187 {
5188 hasColon = (*argptr == ':');
5189 argptr++;
5190 }
c906108c
SS
5191
5192 if (hasColon)
c5aa993b 5193 badInput = (*argptr != ':'); /* Not a class::method */
c906108c 5194 else
c5aa993b 5195 badInput = isdigit (*arg); /* a simple line number */
c906108c
SS
5196 }
5197
5198 if (badInput)
c5aa993b 5199 printf_filtered ("Usage: stop in <function | address>\n");
c906108c
SS
5200 else
5201 break_command_1 (arg, 0, from_tty);
5202}
5203
5204static void
fba45db2 5205stopat_command (char *arg, int from_tty)
c906108c
SS
5206{
5207 int badInput = 0;
5208
c5aa993b 5209 if (arg == (char *) NULL || *arg == '*') /* no line number */
c906108c
SS
5210 badInput = 1;
5211 else
5212 {
5213 char *argptr = arg;
5214 int hasColon = 0;
5215
5216 /* look for a ':'. If there is a '::' then get out, otherwise
c5aa993b 5217 it is probably a line number. */
c906108c 5218 while (*argptr && !hasColon)
c5aa993b
JM
5219 {
5220 hasColon = (*argptr == ':');
5221 argptr++;
5222 }
c906108c
SS
5223
5224 if (hasColon)
c5aa993b 5225 badInput = (*argptr == ':'); /* we have class::method */
c906108c 5226 else
c5aa993b 5227 badInput = !isdigit (*arg); /* not a line number */
c906108c
SS
5228 }
5229
5230 if (badInput)
c5aa993b 5231 printf_filtered ("Usage: stop at <line>\n");
c906108c
SS
5232 else
5233 break_command_1 (arg, 0, from_tty);
5234}
5235
5236/* ARGSUSED */
53a5351d
JM
5237/* accessflag: hw_write: watch write,
5238 hw_read: watch read,
5239 hw_access: watch access (read or write) */
c906108c 5240static void
fba45db2 5241watch_command_1 (char *arg, int accessflag, int from_tty)
c906108c
SS
5242{
5243 struct breakpoint *b;
5244 struct symtab_and_line sal;
5245 struct expression *exp;
5246 struct block *exp_valid_block;
5247 struct value *val, *mark;
5248 struct frame_info *frame;
5249 struct frame_info *prev_frame = NULL;
5250 char *exp_start = NULL;
5251 char *exp_end = NULL;
5252 char *tok, *end_tok;
5253 int toklen;
5254 char *cond_start = NULL;
5255 char *cond_end = NULL;
5256 struct expression *cond = NULL;
5257 int i, other_type_used, target_resources_ok = 0;
5258 enum bptype bp_type;
5259 int mem_cnt = 0;
5260
c5aa993b
JM
5261 INIT_SAL (&sal); /* initialize to zeroes */
5262
c906108c
SS
5263 /* Parse arguments. */
5264 innermost_block = NULL;
5265 exp_start = arg;
5266 exp = parse_exp_1 (&arg, 0, 0);
5267 exp_end = arg;
5268 exp_valid_block = innermost_block;
5269 mark = value_mark ();
5270 val = evaluate_expression (exp);
5271 release_value (val);
5272 if (VALUE_LAZY (val))
5273 value_fetch_lazy (val);
5274
5275 tok = arg;
5276 while (*tok == ' ' || *tok == '\t')
5277 tok++;
5278 end_tok = tok;
5279
5280 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5281 end_tok++;
5282
5283 toklen = end_tok - tok;
5284 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5285 {
5286 tok = cond_start = end_tok + 1;
5287 cond = parse_exp_1 (&tok, 0, 0);
5288 cond_end = tok;
5289 }
5290 if (*tok)
c5aa993b 5291 error ("Junk at end of command.");
c906108c 5292
53a5351d 5293 if (accessflag == hw_read)
c5aa993b 5294 bp_type = bp_read_watchpoint;
53a5351d 5295 else if (accessflag == hw_access)
c5aa993b
JM
5296 bp_type = bp_access_watchpoint;
5297 else
5298 bp_type = bp_hardware_watchpoint;
c906108c
SS
5299
5300 mem_cnt = can_use_hardware_watchpoint (val);
5301 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5302 error ("Expression cannot be implemented with read/access watchpoint.");
c5aa993b
JM
5303 if (mem_cnt != 0)
5304 {
5305 i = hw_watchpoint_used_count (bp_type, &other_type_used);
53a5351d
JM
5306 target_resources_ok =
5307 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5308 other_type_used);
c5aa993b 5309 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
53a5351d
JM
5310 error ("Target does not support this type of hardware watchpoint.");
5311
c5aa993b 5312 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
53a5351d 5313 error ("Target can only support one kind of HW watchpoint at a time.");
c5aa993b 5314 }
c906108c
SS
5315
5316#if defined(HPUXHPPA)
c5aa993b 5317 /* On HP-UX if you set a h/w
c906108c
SS
5318 watchpoint before the "run" command, the inferior dies with a e.g.,
5319 SIGILL once you start it. I initially believed this was due to a
5320 bad interaction between page protection traps and the initial
5321 startup sequence by the dynamic linker.
5322
5323 However, I tried avoiding that by having HP-UX's implementation of
5324 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
5325 yet, which forced slow watches before a "run" or "attach", and it
5326 still fails somewhere in the startup code.
5327
5328 Until I figure out what's happening, I'm disallowing watches altogether
5329 before the "run" or "attach" command. We'll tell the user they must
5330 set watches after getting the program started. */
c5aa993b 5331 if (!target_has_execution)
c906108c
SS
5332 {
5333 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5334 return;
5335 }
5336#endif /* HPUXHPPA */
c5aa993b 5337
c906108c
SS
5338 /* Now set up the breakpoint. */
5339 b = set_raw_breakpoint (sal);
5340 set_breakpoint_count (breakpoint_count + 1);
5341 b->number = breakpoint_count;
5342 b->disposition = donttouch;
5343 b->exp = exp;
5344 b->exp_valid_block = exp_valid_block;
5345 b->exp_string = savestring (exp_start, exp_end - exp_start);
5346 b->val = val;
5347 b->cond = cond;
5348 if (cond_start)
5349 b->cond_string = savestring (cond_start, cond_end - cond_start);
5350 else
5351 b->cond_string = 0;
c5aa993b 5352
c906108c
SS
5353 frame = block_innermost_frame (exp_valid_block);
5354 if (frame)
5355 {
5356 prev_frame = get_prev_frame (frame);
5357 b->watchpoint_frame = frame->frame;
5358 }
5359 else
c5aa993b 5360 b->watchpoint_frame = (CORE_ADDR) 0;
c906108c
SS
5361
5362 if (mem_cnt && target_resources_ok > 0)
5363 b->type = bp_type;
5364 else
5365 b->type = bp_watchpoint;
5366
5367 /* If the expression is "local", then set up a "watchpoint scope"
5368 breakpoint at the point where we've left the scope of the watchpoint
5369 expression. */
5370 if (innermost_block)
5371 {
5372 if (prev_frame)
5373 {
5374 struct breakpoint *scope_breakpoint;
5375 struct symtab_and_line scope_sal;
5376
5377 INIT_SAL (&scope_sal); /* initialize to zeroes */
c5aa993b 5378 scope_sal.pc = get_frame_pc (prev_frame);
c906108c
SS
5379 scope_sal.section = find_pc_overlay (scope_sal.pc);
5380
5381 scope_breakpoint = set_raw_breakpoint (scope_sal);
5382 set_breakpoint_count (breakpoint_count + 1);
5383 scope_breakpoint->number = breakpoint_count;
5384
5385 scope_breakpoint->type = bp_watchpoint_scope;
5386 scope_breakpoint->enable = enabled;
5387
5388 /* Automatically delete the breakpoint when it hits. */
5389 scope_breakpoint->disposition = del;
5390
5391 /* Only break in the proper frame (help with recursion). */
5392 scope_breakpoint->frame = prev_frame->frame;
5393
5394 /* Set the address at which we will stop. */
5395 scope_breakpoint->address = get_frame_pc (prev_frame);
5396
5397 /* The scope breakpoint is related to the watchpoint. We
5398 will need to act on them together. */
5399 b->related_breakpoint = scope_breakpoint;
5400 }
5401 }
5402 value_free_to_mark (mark);
5403 mention (b);
5404}
5405
5406/* Return count of locations need to be watched and can be handled
5407 in hardware. If the watchpoint can not be handled
5408 in hardware return zero. */
5409
5410#if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
53a5351d
JM
5411#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5412 ((BYTE_SIZE) <= (REGISTER_SIZE))
5413#endif
5414
5415#if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5416#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
6ab3a9c9 5417 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
c906108c
SS
5418#endif
5419
5420static int
fba45db2 5421can_use_hardware_watchpoint (struct value *v)
c906108c
SS
5422{
5423 int found_memory_cnt = 0;
2e70b7b9 5424 struct value *head = v;
c906108c
SS
5425
5426 /* Did the user specifically forbid us to use hardware watchpoints? */
c5aa993b 5427 if (!can_use_hw_watchpoints)
c906108c 5428 return 0;
c5aa993b 5429
5c44784c
JM
5430 /* Make sure that the value of the expression depends only upon
5431 memory contents, and values computed from them within GDB. If we
5432 find any register references or function calls, we can't use a
5433 hardware watchpoint.
5434
5435 The idea here is that evaluating an expression generates a series
5436 of values, one holding the value of every subexpression. (The
5437 expression a*b+c has five subexpressions: a, b, a*b, c, and
5438 a*b+c.) GDB's values hold almost enough information to establish
5439 the criteria given above --- they identify memory lvalues,
5440 register lvalues, computed values, etcetera. So we can evaluate
5441 the expression, and then scan the chain of values that leaves
5442 behind to decide whether we can detect any possible change to the
5443 expression's final value using only hardware watchpoints.
5444
5445 However, I don't think that the values returned by inferior
5446 function calls are special in any way. So this function may not
5447 notice that an expression involving an inferior function call
5448 can't be watched with hardware watchpoints. FIXME. */
c5aa993b 5449 for (; v; v = v->next)
c906108c 5450 {
5c44784c 5451 if (VALUE_LVAL (v) == lval_memory)
c906108c 5452 {
5c44784c
JM
5453 if (VALUE_LAZY (v))
5454 /* A lazy memory lvalue is one that GDB never needed to fetch;
5455 we either just used its address (e.g., `a' in `a.b') or
5456 we never needed it at all (e.g., `a' in `a,b'). */
5457 ;
53a5351d 5458 else
5c44784c
JM
5459 {
5460 /* Ahh, memory we actually used! Check if we can cover
5461 it with hardware watchpoints. */
2e70b7b9
MS
5462 struct type *vtype = check_typedef (VALUE_TYPE (v));
5463
5464 /* We only watch structs and arrays if user asked for it
5465 explicitly, never if they just happen to appear in a
5466 middle of some value chain. */
5467 if (v == head
5468 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5469 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5470 {
5471 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5472 int len = TYPE_LENGTH (VALUE_TYPE (v));
5473
5474 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5475 return 0;
5476 else
5477 found_memory_cnt++;
5478 }
5c44784c 5479 }
c5aa993b 5480 }
c906108c 5481 else if (v->lval != not_lval && v->modifiable == 0)
53a5351d
JM
5482 return 0; /* ??? What does this represent? */
5483 else if (v->lval == lval_register)
5484 return 0; /* cannot watch a register with a HW watchpoint */
c906108c
SS
5485 }
5486
5487 /* The expression itself looks suitable for using a hardware
5488 watchpoint, but give the target machine a chance to reject it. */
5489 return found_memory_cnt;
5490}
5491
8b93c638
JM
5492#ifdef UI_OUT
5493void
fba45db2 5494watch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
5495{
5496 watch_command (arg, from_tty);
5497}
5498#endif
c5aa993b 5499static void
fba45db2 5500watch_command (char *arg, int from_tty)
c906108c 5501{
53a5351d 5502 watch_command_1 (arg, hw_write, from_tty);
c906108c
SS
5503}
5504
8b93c638
JM
5505#ifdef UI_OUT
5506void
fba45db2 5507rwatch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
5508{
5509 rwatch_command (arg, from_tty);
5510}
5511#endif
c5aa993b 5512static void
fba45db2 5513rwatch_command (char *arg, int from_tty)
c906108c 5514{
53a5351d 5515 watch_command_1 (arg, hw_read, from_tty);
c906108c
SS
5516}
5517
8b93c638
JM
5518#ifdef UI_OUT
5519void
fba45db2 5520awatch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
5521{
5522 awatch_command (arg, from_tty);
5523}
5524#endif
c5aa993b 5525static void
fba45db2 5526awatch_command (char *arg, int from_tty)
c906108c 5527{
53a5351d 5528 watch_command_1 (arg, hw_access, from_tty);
c906108c 5529}
c906108c 5530\f
c5aa993b 5531
43ff13b4 5532/* Helper routines for the until_command routine in infcmd.c. Here
c906108c
SS
5533 because it uses the mechanisms of breakpoints. */
5534
43ff13b4
JM
5535/* This function is called by fetch_inferior_event via the
5536 cmd_continuation pointer, to complete the until command. It takes
5537 care of cleaning up the temporary breakpoints set up by the until
5538 command. */
c2c6d25f
JM
5539static void
5540until_break_command_continuation (struct continuation_arg *arg)
43ff13b4 5541{
0d06e24b
JM
5542 struct cleanup *cleanups;
5543
57e687d9 5544 cleanups = (struct cleanup *) arg->data.pointer;
0d06e24b 5545 do_exec_cleanups (cleanups);
43ff13b4
JM
5546}
5547
c906108c
SS
5548/* ARGSUSED */
5549void
fba45db2 5550until_break_command (char *arg, int from_tty)
c906108c
SS
5551{
5552 struct symtabs_and_lines sals;
5553 struct symtab_and_line sal;
5554 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5555 struct breakpoint *breakpoint;
5556 struct cleanup *old_chain;
0d06e24b
JM
5557 struct continuation_arg *arg1;
5558
c906108c
SS
5559
5560 clear_proceed_status ();
5561
5562 /* Set a breakpoint where the user wants it and at return from
5563 this function */
c5aa993b 5564
c906108c
SS
5565 if (default_breakpoint_valid)
5566 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
c5aa993b 5567 default_breakpoint_line, (char ***) NULL);
c906108c 5568 else
53a5351d
JM
5569 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5570 0, (char ***) NULL);
c5aa993b 5571
c906108c
SS
5572 if (sals.nelts != 1)
5573 error ("Couldn't get information on specified line.");
c5aa993b 5574
c906108c 5575 sal = sals.sals[0];
b8c9b27d 5576 xfree (sals.sals); /* malloc'd, so freed */
c5aa993b 5577
c906108c
SS
5578 if (*arg)
5579 error ("Junk at end of arguments.");
c5aa993b 5580
c906108c 5581 resolve_sal_pc (&sal);
c5aa993b 5582
c906108c 5583 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
c5aa993b 5584
6426a772 5585 if (!event_loop_p || !target_can_async_p ())
4d6140d9 5586 old_chain = make_cleanup_delete_breakpoint (breakpoint);
43ff13b4 5587 else
4d6140d9 5588 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
43ff13b4
JM
5589
5590 /* If we are running asynchronously, and the target supports async
5591 execution, we are not waiting for the target to stop, in the call
5592 tp proceed, below. This means that we cannot delete the
5593 brekpoints until the target has actually stopped. The only place
5594 where we get a chance to do that is in fetch_inferior_event, so
5595 we must set things up for that. */
5596
6426a772 5597 if (event_loop_p && target_can_async_p ())
43ff13b4 5598 {
0d06e24b
JM
5599 /* In this case the arg for the continuation is just the point
5600 in the exec_cleanups chain from where to start doing
5601 cleanups, because all the continuation does is the cleanups in
5602 the exec_cleanup_chain. */
5603 arg1 =
5604 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
57e687d9
MS
5605 arg1->next = NULL;
5606 arg1->data.pointer = old_chain;
0d06e24b
JM
5607
5608 add_continuation (until_break_command_continuation, arg1);
43ff13b4 5609 }
c906108c
SS
5610
5611 /* Keep within the current frame */
c5aa993b 5612
c906108c
SS
5613 if (prev_frame)
5614 {
5615 sal = find_pc_line (prev_frame->pc, 0);
5616 sal.pc = prev_frame->pc;
5617 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
6426a772 5618 if (!event_loop_p || !target_can_async_p ())
4d6140d9 5619 make_cleanup_delete_breakpoint (breakpoint);
43ff13b4 5620 else
4d6140d9 5621 make_exec_cleanup_delete_breakpoint (breakpoint);
c906108c 5622 }
c5aa993b 5623
c906108c 5624 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
43ff13b4
JM
5625 /* Do the cleanups now, anly if we are not running asynchronously,
5626 of if we are, but the target is still synchronous. */
6426a772 5627 if (!event_loop_p || !target_can_async_p ())
c5aa993b 5628 do_cleanups (old_chain);
c906108c
SS
5629}
5630\f
5631#if 0
5632/* These aren't used; I don't konw what they were for. */
5633/* Set a breakpoint at the catch clause for NAME. */
5634static int
fba45db2 5635catch_breakpoint (char *name)
c906108c
SS
5636{
5637}
5638
5639static int
fba45db2 5640disable_catch_breakpoint (void)
c906108c
SS
5641{
5642}
5643
5644static int
fba45db2 5645delete_catch_breakpoint (void)
c906108c
SS
5646{
5647}
5648
5649static int
fba45db2 5650enable_catch_breakpoint (void)
c906108c
SS
5651{
5652}
5653#endif /* 0 */
5654
5655struct sal_chain
5656{
5657 struct sal_chain *next;
5658 struct symtab_and_line sal;
5659};
5660
7a292a7a 5661#if 0
c906108c
SS
5662/* Not really used -- invocation in handle_gnu_4_16_catch_command
5663 had been commented out in the v.4.16 sources, and stays
5664 disabled there now because "catch NAME" syntax isn't allowed.
5665 pai/1997-07-11 */
5666/* This isn't used; I don't know what it was for. */
5667/* For each catch clause identified in ARGS, run FUNCTION
5668 with that clause as an argument. */
5669static struct symtabs_and_lines
831662b3 5670map_catch_names (char *args, int (*function) ())
c906108c
SS
5671{
5672 register char *p = args;
5673 register char *p1;
5674 struct symtabs_and_lines sals;
5675#if 0
5676 struct sal_chain *sal_chain = 0;
5677#endif
5678
5679 if (p == 0)
5680 error_no_arg ("one or more catch names");
5681
5682 sals.nelts = 0;
5683 sals.sals = NULL;
5684
5685 while (*p)
5686 {
5687 p1 = p;
5688 /* Don't swallow conditional part. */
5689 if (p1[0] == 'i' && p1[1] == 'f'
5690 && (p1[2] == ' ' || p1[2] == '\t'))
5691 break;
5692
5693 if (isalpha (*p1))
5694 {
5695 p1++;
5696 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5697 p1++;
5698 }
5699
5700 if (*p1 && *p1 != ' ' && *p1 != '\t')
5701 error ("Arguments must be catch names.");
5702
5703 *p1 = 0;
5704#if 0
5705 if (function (p))
5706 {
5707 struct sal_chain *next = (struct sal_chain *)
c5aa993b 5708 alloca (sizeof (struct sal_chain));
c906108c
SS
5709 next->next = sal_chain;
5710 next->sal = get_catch_sal (p);
5711 sal_chain = next;
5712 goto win;
5713 }
5714#endif
5715 printf_unfiltered ("No catch clause for exception %s.\n", p);
5716#if 0
5717 win:
5718#endif
5719 p = p1;
c5aa993b
JM
5720 while (*p == ' ' || *p == '\t')
5721 p++;
c906108c
SS
5722 }
5723}
7a292a7a 5724#endif
c906108c
SS
5725
5726/* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5727
5728static struct symtabs_and_lines
fba45db2 5729get_catch_sals (int this_level_only)
c906108c
SS
5730{
5731 register struct blockvector *bl;
5732 register struct block *block;
5733 int index, have_default = 0;
5734 CORE_ADDR pc;
5735 struct symtabs_and_lines sals;
5736 struct sal_chain *sal_chain = 0;
5737 char *blocks_searched;
5738
5739 /* Not sure whether an error message is always the correct response,
5740 but it's better than a core dump. */
5741 if (selected_frame == NULL)
5742 error ("No selected frame.");
5743 block = get_frame_block (selected_frame);
5744 pc = selected_frame->pc;
5745
5746 sals.nelts = 0;
5747 sals.sals = NULL;
5748
5749 if (block == 0)
5750 error ("No symbol table info available.\n");
5751
5752 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5753 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5754 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5755
5756 while (block != 0)
5757 {
5758 CORE_ADDR end = BLOCK_END (block) - 4;
5759 int last_index;
5760
5761 if (bl != blockvector_for_pc (end, &index))
5762 error ("blockvector blotch");
5763 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5764 error ("blockvector botch");
5765 last_index = BLOCKVECTOR_NBLOCKS (bl);
5766 index += 1;
5767
5768 /* Don't print out blocks that have gone by. */
5769 while (index < last_index
5770 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5771 index++;
5772
5773 while (index < last_index
5774 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5775 {
5776 if (blocks_searched[index] == 0)
5777 {
5778 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5779 int nsyms;
5780 register int i;
5781 register struct symbol *sym;
5782
5783 nsyms = BLOCK_NSYMS (b);
5784
5785 for (i = 0; i < nsyms; i++)
5786 {
5787 sym = BLOCK_SYM (b, i);
5788 if (STREQ (SYMBOL_NAME (sym), "default"))
5789 {
5790 if (have_default)
5791 continue;
5792 have_default = 1;
5793 }
5794 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5795 {
5796 struct sal_chain *next = (struct sal_chain *)
c5aa993b 5797 alloca (sizeof (struct sal_chain));
c906108c 5798 next->next = sal_chain;
53a5351d
JM
5799 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5800 0);
c906108c
SS
5801 sal_chain = next;
5802 }
5803 }
5804 blocks_searched[index] = 1;
5805 }
5806 index++;
5807 }
5808 if (have_default)
5809 break;
5810 if (sal_chain && this_level_only)
5811 break;
5812
5813 /* After handling the function's top-level block, stop.
c5aa993b
JM
5814 Don't continue to its superblock, the block of
5815 per-file symbols. */
c906108c
SS
5816 if (BLOCK_FUNCTION (block))
5817 break;
5818 block = BLOCK_SUPERBLOCK (block);
5819 }
5820
5821 if (sal_chain)
5822 {
5823 struct sal_chain *tmp_chain;
5824
5825 /* Count the number of entries. */
5826 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5827 tmp_chain = tmp_chain->next)
5828 index++;
5829
5830 sals.nelts = index;
5831 sals.sals = (struct symtab_and_line *)
5832 xmalloc (index * sizeof (struct symtab_and_line));
5833 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5834 sals.sals[index] = sal_chain->sal;
5835 }
5836
5837 return sals;
5838}
5839
5840static void
fba45db2 5841ep_skip_leading_whitespace (char **s)
c906108c 5842{
c5aa993b
JM
5843 if ((s == NULL) || (*s == NULL))
5844 return;
5845 while (isspace (**s))
5846 *s += 1;
c906108c 5847}
c5aa993b 5848
c906108c
SS
5849/* This function examines a string, and attempts to find a token
5850 that might be an event name in the leading characters. If a
5851 possible match is found, a pointer to the last character of
5852 the token is returned. Else, NULL is returned. */
53a5351d 5853
c906108c 5854static char *
fba45db2 5855ep_find_event_name_end (char *arg)
c906108c 5856{
c5aa993b
JM
5857 char *s = arg;
5858 char *event_name_end = NULL;
5859
c906108c
SS
5860 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5861 if (arg == NULL)
5862 return NULL;
c5aa993b 5863
c906108c 5864 /* We break out of the loop when we find a token delimiter.
c5aa993b
JM
5865 Basically, we're looking for alphanumerics and underscores;
5866 anything else delimites the token. */
c906108c
SS
5867 while (*s != '\0')
5868 {
c5aa993b
JM
5869 if (!isalnum (*s) && (*s != '_'))
5870 break;
c906108c
SS
5871 event_name_end = s;
5872 s++;
5873 }
c5aa993b 5874
c906108c
SS
5875 return event_name_end;
5876}
5877
c5aa993b 5878
c906108c
SS
5879/* This function attempts to parse an optional "if <cond>" clause
5880 from the arg string. If one is not found, it returns NULL.
c5aa993b 5881
c906108c
SS
5882 Else, it returns a pointer to the condition string. (It does not
5883 attempt to evaluate the string against a particular block.) And,
5884 it updates arg to point to the first character following the parsed
5885 if clause in the arg string. */
53a5351d 5886
c906108c 5887static char *
fba45db2 5888ep_parse_optional_if_clause (char **arg)
c906108c 5889{
c5aa993b
JM
5890 char *cond_string;
5891
5892 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
c906108c 5893 return NULL;
c5aa993b 5894
c906108c
SS
5895 /* Skip the "if" keyword. */
5896 (*arg) += 2;
c5aa993b 5897
c906108c
SS
5898 /* Skip any extra leading whitespace, and record the start of the
5899 condition string. */
5900 ep_skip_leading_whitespace (arg);
5901 cond_string = *arg;
c5aa993b 5902
c906108c
SS
5903 /* Assume that the condition occupies the remainder of the arg string. */
5904 (*arg) += strlen (cond_string);
c5aa993b 5905
c906108c
SS
5906 return cond_string;
5907}
c5aa993b 5908
c906108c
SS
5909/* This function attempts to parse an optional filename from the arg
5910 string. If one is not found, it returns NULL.
c5aa993b 5911
c906108c
SS
5912 Else, it returns a pointer to the parsed filename. (This function
5913 makes no attempt to verify that a file of that name exists, or is
5914 accessible.) And, it updates arg to point to the first character
5915 following the parsed filename in the arg string.
c5aa993b 5916
c906108c
SS
5917 Note that clients needing to preserve the returned filename for
5918 future access should copy it to their own buffers. */
5919static char *
fba45db2 5920ep_parse_optional_filename (char **arg)
c906108c 5921{
c5aa993b
JM
5922 static char filename[1024];
5923 char *arg_p = *arg;
5924 int i;
5925 char c;
5926
c906108c
SS
5927 if ((*arg_p == '\0') || isspace (*arg_p))
5928 return NULL;
c5aa993b
JM
5929
5930 for (i = 0;; i++)
c906108c
SS
5931 {
5932 c = *arg_p;
5933 if (isspace (c))
c5aa993b 5934 c = '\0';
c906108c
SS
5935 filename[i] = c;
5936 if (c == '\0')
c5aa993b 5937 break;
c906108c
SS
5938 arg_p++;
5939 }
5940 *arg = arg_p;
c5aa993b 5941
c906108c
SS
5942 return filename;
5943}
c5aa993b 5944
c906108c
SS
5945/* Commands to deal with catching events, such as signals, exceptions,
5946 process start/exit, etc. */
c5aa993b
JM
5947
5948typedef enum
5949{
5950 catch_fork, catch_vfork
5951}
5952catch_fork_kind;
5953
e514a9d6 5954#if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
a14ed312
KB
5955static void catch_fork_command_1 (catch_fork_kind fork_kind,
5956 char *arg, int tempflag, int from_tty);
7a292a7a 5957
c906108c 5958static void
fba45db2
KB
5959catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5960 int from_tty)
c906108c 5961{
c5aa993b
JM
5962 char *cond_string = NULL;
5963
c906108c 5964 ep_skip_leading_whitespace (&arg);
c5aa993b 5965
c906108c 5966 /* The allowed syntax is:
c5aa993b
JM
5967 catch [v]fork
5968 catch [v]fork if <cond>
5969
c906108c
SS
5970 First, check if there's an if clause. */
5971 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5972
c906108c
SS
5973 if ((*arg != '\0') && !isspace (*arg))
5974 error ("Junk at end of arguments.");
c5aa993b 5975
c906108c
SS
5976 /* If this target supports it, create a fork or vfork catchpoint
5977 and enable reporting of such events. */
c5aa993b
JM
5978 switch (fork_kind)
5979 {
5980 case catch_fork:
c906108c
SS
5981 create_fork_event_catchpoint (tempflag, cond_string);
5982 break;
c5aa993b 5983 case catch_vfork:
c906108c
SS
5984 create_vfork_event_catchpoint (tempflag, cond_string);
5985 break;
c5aa993b 5986 default:
c906108c
SS
5987 error ("unsupported or unknown fork kind; cannot catch it");
5988 break;
c5aa993b 5989 }
c906108c 5990}
e514a9d6 5991#endif
c906108c 5992
e514a9d6 5993#if defined(CHILD_INSERT_EXEC_CATCHPOINT)
c906108c 5994static void
fba45db2 5995catch_exec_command_1 (char *arg, int tempflag, int from_tty)
c906108c 5996{
c5aa993b 5997 char *cond_string = NULL;
c906108c
SS
5998
5999 ep_skip_leading_whitespace (&arg);
6000
6001 /* The allowed syntax is:
c5aa993b
JM
6002 catch exec
6003 catch exec if <cond>
c906108c
SS
6004
6005 First, check if there's an if clause. */
6006 cond_string = ep_parse_optional_if_clause (&arg);
6007
6008 if ((*arg != '\0') && !isspace (*arg))
6009 error ("Junk at end of arguments.");
6010
6011 /* If this target supports it, create an exec catchpoint
6012 and enable reporting of such events. */
6013 create_exec_event_catchpoint (tempflag, cond_string);
6014}
e514a9d6 6015#endif
c5aa993b 6016
c906108c
SS
6017#if defined(SOLIB_ADD)
6018static void
fba45db2 6019catch_load_command_1 (char *arg, int tempflag, int from_tty)
c906108c 6020{
c5aa993b
JM
6021 char *dll_pathname = NULL;
6022 char *cond_string = NULL;
6023
c906108c 6024 ep_skip_leading_whitespace (&arg);
c5aa993b 6025
c906108c 6026 /* The allowed syntax is:
c5aa993b
JM
6027 catch load
6028 catch load if <cond>
6029 catch load <filename>
6030 catch load <filename> if <cond>
6031
c906108c
SS
6032 The user is not allowed to specify the <filename> after an
6033 if clause.
c5aa993b 6034
c906108c 6035 We'll ignore the pathological case of a file named "if".
c5aa993b 6036
c906108c
SS
6037 First, check if there's an if clause. If so, then there
6038 cannot be a filename. */
6039 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 6040
c906108c
SS
6041 /* If there was an if clause, then there cannot be a filename.
6042 Else, there might be a filename and an if clause. */
6043 if (cond_string == NULL)
6044 {
6045 dll_pathname = ep_parse_optional_filename (&arg);
6046 ep_skip_leading_whitespace (&arg);
6047 cond_string = ep_parse_optional_if_clause (&arg);
6048 }
c5aa993b 6049
c906108c
SS
6050 if ((*arg != '\0') && !isspace (*arg))
6051 error ("Junk at end of arguments.");
c5aa993b 6052
c906108c
SS
6053 /* Create a load breakpoint that only triggers when a load of
6054 the specified dll (or any dll, if no pathname was specified)
6055 occurs. */
53a5351d
JM
6056 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
6057 dll_pathname, cond_string);
c906108c 6058}
c5aa993b 6059
c906108c 6060static void
fba45db2 6061catch_unload_command_1 (char *arg, int tempflag, int from_tty)
c906108c 6062{
c5aa993b
JM
6063 char *dll_pathname = NULL;
6064 char *cond_string = NULL;
6065
c906108c 6066 ep_skip_leading_whitespace (&arg);
c5aa993b 6067
c906108c 6068 /* The allowed syntax is:
c5aa993b
JM
6069 catch unload
6070 catch unload if <cond>
6071 catch unload <filename>
6072 catch unload <filename> if <cond>
6073
c906108c
SS
6074 The user is not allowed to specify the <filename> after an
6075 if clause.
c5aa993b 6076
c906108c 6077 We'll ignore the pathological case of a file named "if".
c5aa993b 6078
c906108c
SS
6079 First, check if there's an if clause. If so, then there
6080 cannot be a filename. */
6081 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 6082
c906108c
SS
6083 /* If there was an if clause, then there cannot be a filename.
6084 Else, there might be a filename and an if clause. */
6085 if (cond_string == NULL)
6086 {
6087 dll_pathname = ep_parse_optional_filename (&arg);
6088 ep_skip_leading_whitespace (&arg);
6089 cond_string = ep_parse_optional_if_clause (&arg);
6090 }
c5aa993b 6091
c906108c
SS
6092 if ((*arg != '\0') && !isspace (*arg))
6093 error ("Junk at end of arguments.");
c5aa993b 6094
c906108c
SS
6095 /* Create an unload breakpoint that only triggers when an unload of
6096 the specified dll (or any dll, if no pathname was specified)
6097 occurs. */
53a5351d
JM
6098 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
6099 dll_pathname, cond_string);
c906108c
SS
6100}
6101#endif /* SOLIB_ADD */
6102
6103/* Commands to deal with catching exceptions. */
6104
6105/* Set a breakpoint at the specified callback routine for an
c5aa993b 6106 exception event callback */
c906108c
SS
6107
6108static void
fba45db2
KB
6109create_exception_catchpoint (int tempflag, char *cond_string,
6110 enum exception_event_kind ex_event,
6111 struct symtab_and_line *sal)
c906108c 6112{
c5aa993b 6113 struct breakpoint *b;
c5aa993b 6114 int thread = -1; /* All threads. */
c906108c 6115
c5aa993b 6116 if (!sal) /* no exception support? */
c906108c
SS
6117 return;
6118
6119 b = set_raw_breakpoint (*sal);
6120 set_breakpoint_count (breakpoint_count + 1);
6121 b->number = breakpoint_count;
6122 b->cond = NULL;
53a5351d
JM
6123 b->cond_string = (cond_string == NULL) ?
6124 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
6125 b->thread = thread;
6126 b->addr_string = NULL;
6127 b->enable = enabled;
6128 b->disposition = tempflag ? del : donttouch;
6129 switch (ex_event)
6130 {
c5aa993b
JM
6131 case EX_EVENT_THROW:
6132 b->type = bp_catch_throw;
6133 break;
6134 case EX_EVENT_CATCH:
6135 b->type = bp_catch_catch;
6136 break;
6137 default: /* error condition */
6138 b->type = bp_none;
6139 b->enable = disabled;
6140 error ("Internal error -- invalid catchpoint kind");
c906108c
SS
6141 }
6142 mention (b);
6143}
6144
c5aa993b 6145/* Deal with "catch catch" and "catch throw" commands */
c906108c
SS
6146
6147static void
fba45db2
KB
6148catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6149 int tempflag, int from_tty)
c906108c 6150{
c5aa993b
JM
6151 char *cond_string = NULL;
6152 struct symtab_and_line *sal = NULL;
6153
c906108c 6154 ep_skip_leading_whitespace (&arg);
c5aa993b 6155
c906108c
SS
6156 cond_string = ep_parse_optional_if_clause (&arg);
6157
6158 if ((*arg != '\0') && !isspace (*arg))
6159 error ("Junk at end of arguments.");
6160
6161 if ((ex_event != EX_EVENT_THROW) &&
6162 (ex_event != EX_EVENT_CATCH))
6163 error ("Unsupported or unknown exception event; cannot catch it");
6164
6165 /* See if we can find a callback routine */
6166 sal = target_enable_exception_callback (ex_event, 1);
6167
c5aa993b 6168 if (sal)
c906108c
SS
6169 {
6170 /* We have callbacks from the runtime system for exceptions.
c5aa993b 6171 Set a breakpoint on the sal found, if no errors */
c906108c 6172 if (sal != (struct symtab_and_line *) -1)
c5aa993b 6173 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
c906108c 6174 else
53a5351d 6175 return; /* something went wrong with setting up callbacks */
c906108c 6176 }
c5aa993b 6177 else
c906108c
SS
6178 {
6179 /* No callbacks from runtime system for exceptions.
6180 Try GNU C++ exception breakpoints using labels in debug info. */
6181 if (ex_event == EX_EVENT_CATCH)
c5aa993b
JM
6182 {
6183 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6184 }
c906108c 6185 else if (ex_event == EX_EVENT_THROW)
c5aa993b
JM
6186 {
6187 /* Set a breakpoint on __raise_exception () */
6188
53a5351d
JM
6189 warning ("Unsupported with this platform/compiler combination.");
6190 warning ("Perhaps you can achieve the effect you want by setting");
6191 warning ("a breakpoint on __raise_exception().");
c5aa993b 6192 }
c906108c
SS
6193 }
6194}
6195
6196/* Cover routine to allow wrapping target_enable_exception_catchpoints
6197 inside a catch_errors */
6198
6199static int
fba45db2 6200cover_target_enable_exception_callback (PTR arg)
c906108c
SS
6201{
6202 args_for_catchpoint_enable *args = arg;
6203 struct symtab_and_line *sal;
6204 sal = target_enable_exception_callback (args->kind, args->enable);
6205 if (sal == NULL)
6206 return 0;
6207 else if (sal == (struct symtab_and_line *) -1)
6208 return -1;
6209 else
c5aa993b 6210 return 1; /*is valid */
c906108c
SS
6211}
6212
6213
6214
6215/* This is the original v.4.16 and earlier version of the
6216 catch_command_1() function. Now that other flavours of "catch"
6217 have been introduced, and since exception handling can be handled
6218 in other ways (through target ops) also, this is used only for the
6219 GNU C++ exception handling system.
6220 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6221 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6222 there was no code in GDB 4.16 for "catch throw".
c5aa993b 6223
c906108c
SS
6224 Called from catch_exception_command_1 () */
6225
6226
6227static void
fba45db2 6228handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
c906108c
SS
6229{
6230 /* First, translate ARG into something we can deal with in terms
6231 of breakpoints. */
6232
6233 struct symtabs_and_lines sals;
6234 struct symtab_and_line sal;
6235 register struct expression *cond = 0;
6236 register struct breakpoint *b;
6237 char *save_arg;
6238 int i;
6239
c5aa993b 6240 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
6241
6242 /* If no arg given, or if first arg is 'if ', all active catch clauses
6243 are breakpointed. */
6244
c5aa993b 6245 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
c906108c
SS
6246 && (arg[2] == ' ' || arg[2] == '\t')))
6247 {
6248 /* Grab all active catch clauses. */
6249 sals = get_catch_sals (0);
6250 }
6251 else
6252 {
6253 /* Grab selected catch clauses. */
6254 error ("catch NAME not implemented");
6255
6256#if 0
6257 /* Not sure why this code has been disabled. I'm leaving
6258 it disabled. We can never come here now anyway
6259 since we don't allow the "catch NAME" syntax.
c5aa993b 6260 pai/1997-07-11 */
c906108c
SS
6261
6262 /* This isn't used; I don't know what it was for. */
6263 sals = map_catch_names (arg, catch_breakpoint);
6264#endif
6265 }
6266
c5aa993b 6267 if (!sals.nelts)
c906108c
SS
6268 return;
6269
6270 save_arg = arg;
6271 for (i = 0; i < sals.nelts; i++)
6272 {
6273 resolve_sal_pc (&sals.sals[i]);
c5aa993b 6274
c906108c
SS
6275 while (arg && *arg)
6276 {
6277 if (arg[0] == 'i' && arg[1] == 'f'
6278 && (arg[2] == ' ' || arg[2] == '\t'))
c5aa993b 6279 cond = parse_exp_1 ((arg += 2, &arg),
c906108c
SS
6280 block_for_pc (sals.sals[i].pc), 0);
6281 else
6282 error ("Junk at end of arguments.");
6283 }
6284 arg = save_arg;
6285 }
6286
6287 for (i = 0; i < sals.nelts; i++)
6288 {
6289 sal = sals.sals[i];
6290
6291 if (from_tty)
6292 describe_other_breakpoints (sal.pc, sal.section);
6293
6294 b = set_raw_breakpoint (sal);
6295 set_breakpoint_count (breakpoint_count + 1);
6296 b->number = breakpoint_count;
53a5351d
JM
6297
6298 /* Important -- this is an ordinary breakpoint. For platforms
6299 with callback support for exceptions,
6300 create_exception_catchpoint() will create special bp types
6301 (bp_catch_catch and bp_catch_throw), and there is code in
6302 insert_breakpoints() and elsewhere that depends on that. */
6303 b->type = bp_breakpoint;
c906108c
SS
6304
6305 b->cond = cond;
6306 b->enable = enabled;
6307 b->disposition = tempflag ? del : donttouch;
6308
6309 mention (b);
6310 }
6311
6312 if (sals.nelts > 1)
6313 {
53a5351d
JM
6314 warning ("Multiple breakpoints were set.");
6315 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 6316 }
b8c9b27d 6317 xfree (sals.sals);
c906108c
SS
6318}
6319
6320#if 0
6321/* This creates a temporary internal breakpoint
6322 just to placate infrun */
6323static struct breakpoint *
fba45db2 6324create_temp_exception_breakpoint (CORE_ADDR pc)
c906108c
SS
6325{
6326 struct symtab_and_line sal;
6327 struct breakpoint *b;
6328
c5aa993b 6329 INIT_SAL (&sal);
c906108c
SS
6330 sal.pc = pc;
6331 sal.symtab = NULL;
6332 sal.line = 0;
6333
6334 b = set_raw_breakpoint (sal);
6335 if (!b)
6336 error ("Internal error -- couldn't set temp exception breakpoint");
6337
6338 b->type = bp_breakpoint;
6339 b->disposition = del;
6340 b->enable = enabled;
6341 b->silent = 1;
6342 b->number = internal_breakpoint_number--;
6343 return b;
6344}
6345#endif
6346
6347static void
fba45db2 6348catch_command_1 (char *arg, int tempflag, int from_tty)
c906108c 6349{
c5aa993b 6350
c906108c
SS
6351 /* The first argument may be an event name, such as "start" or "load".
6352 If so, then handle it as such. If it doesn't match an event name,
6353 then attempt to interpret it as an exception name. (This latter is
6354 the v4.16-and-earlier GDB meaning of the "catch" command.)
c5aa993b 6355
c906108c 6356 First, try to find the bounds of what might be an event name. */
c5aa993b
JM
6357 char *arg1_start = arg;
6358 char *arg1_end;
6359 int arg1_length;
6360
c906108c
SS
6361 if (arg1_start == NULL)
6362 {
c5aa993b 6363 /* Old behaviour was to use pre-v-4.16 syntax */
c906108c
SS
6364 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6365 /* return; */
c5aa993b 6366 /* Now, this is not allowed */
c906108c
SS
6367 error ("Catch requires an event name.");
6368
6369 }
6370 arg1_end = ep_find_event_name_end (arg1_start);
6371 if (arg1_end == NULL)
6372 error ("catch requires an event");
6373 arg1_length = arg1_end + 1 - arg1_start;
c5aa993b 6374
c906108c
SS
6375 /* Try to match what we found against known event names. */
6376 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6377 {
6378 error ("Catch of signal not yet implemented");
6379 }
6380 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6381 {
53a5351d
JM
6382 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6383 tempflag, from_tty);
c906108c
SS
6384 }
6385 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6386 {
53a5351d
JM
6387 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6388 tempflag, from_tty);
c906108c
SS
6389 }
6390 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6391 {
6392 error ("Catch of thread_start not yet implemented");
6393 }
6394 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6395 {
6396 error ("Catch of thread_exit not yet implemented");
6397 }
6398 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6399 {
6400 error ("Catch of thread_join not yet implemented");
6401 }
6402 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6403 {
6404 error ("Catch of start not yet implemented");
6405 }
6406 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6407 {
6408 error ("Catch of exit not yet implemented");
6409 }
6410 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6411 {
6412#if defined(CHILD_INSERT_FORK_CATCHPOINT)
c5aa993b 6413 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
6414#else
6415 error ("Catch of fork not yet implemented");
6416#endif
6417 }
6418 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6419 {
6420#if defined(CHILD_INSERT_VFORK_CATCHPOINT)
c5aa993b 6421 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
6422#else
6423 error ("Catch of vfork not yet implemented");
6424#endif
6425 }
6426 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6427 {
6428#if defined(CHILD_INSERT_EXEC_CATCHPOINT)
c5aa993b 6429 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
6430#else
6431 error ("Catch of exec not yet implemented");
6432#endif
6433 }
6434 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6435 {
6436#if defined(SOLIB_ADD)
c5aa993b 6437 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
6438#else
6439 error ("Catch of load not implemented");
6440#endif
6441 }
6442 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6443 {
6444#if defined(SOLIB_ADD)
c5aa993b 6445 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
6446#else
6447 error ("Catch of load not implemented");
6448#endif
6449 }
6450 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6451 {
6452 error ("Catch of stop not yet implemented");
6453 }
c5aa993b 6454
c906108c
SS
6455 /* This doesn't appear to be an event name */
6456
6457 else
6458 {
6459 /* Pre-v.4.16 behaviour was to treat the argument
c5aa993b 6460 as the name of an exception */
c906108c 6461 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
c5aa993b 6462 /* Now this is not allowed */
c906108c
SS
6463 error ("Unknown event kind specified for catch");
6464
6465 }
6466}
6467
6468/* Used by the gui, could be made a worker for other things. */
6469
6470struct breakpoint *
fba45db2 6471set_breakpoint_sal (struct symtab_and_line sal)
c906108c
SS
6472{
6473 struct breakpoint *b;
6474 b = set_raw_breakpoint (sal);
6475 set_breakpoint_count (breakpoint_count + 1);
6476 b->number = breakpoint_count;
6477 b->type = bp_breakpoint;
6478 b->cond = 0;
6479 b->thread = -1;
6480 return b;
6481}
6482
6483#if 0
6484/* These aren't used; I don't know what they were for. */
6485/* Disable breakpoints on all catch clauses described in ARGS. */
6486static void
fba45db2 6487disable_catch (char *args)
c906108c
SS
6488{
6489 /* Map the disable command to catch clauses described in ARGS. */
6490}
6491
6492/* Enable breakpoints on all catch clauses described in ARGS. */
6493static void
fba45db2 6494enable_catch (char *args)
c906108c
SS
6495{
6496 /* Map the disable command to catch clauses described in ARGS. */
6497}
6498
6499/* Delete breakpoints on all catch clauses in the active scope. */
6500static void
fba45db2 6501delete_catch (char *args)
c906108c
SS
6502{
6503 /* Map the delete command to catch clauses described in ARGS. */
6504}
6505#endif /* 0 */
6506
6507static void
fba45db2 6508catch_command (char *arg, int from_tty)
c906108c
SS
6509{
6510 catch_command_1 (arg, 0, from_tty);
6511}
6512\f
6513
6514static void
fba45db2 6515tcatch_command (char *arg, int from_tty)
c906108c
SS
6516{
6517 catch_command_1 (arg, 1, from_tty);
6518}
6519
6520
6521static void
fba45db2 6522clear_command (char *arg, int from_tty)
c906108c
SS
6523{
6524 register struct breakpoint *b, *b1;
6525 int default_match;
6526 struct symtabs_and_lines sals;
6527 struct symtab_and_line sal;
6528 register struct breakpoint *found;
6529 int i;
6530
6531 if (arg)
6532 {
6533 sals = decode_line_spec (arg, 1);
6534 default_match = 0;
6535 }
6536 else
6537 {
c5aa993b 6538 sals.sals = (struct symtab_and_line *)
c906108c 6539 xmalloc (sizeof (struct symtab_and_line));
c5aa993b 6540 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
6541 sal.line = default_breakpoint_line;
6542 sal.symtab = default_breakpoint_symtab;
6543 sal.pc = default_breakpoint_address;
6544 if (sal.symtab == 0)
6545 error ("No source file specified.");
6546
6547 sals.sals[0] = sal;
6548 sals.nelts = 1;
6549
6550 default_match = 1;
6551 }
6552
6553 /* For each line spec given, delete bps which correspond
6554 to it. We do this in two loops: the first loop looks at
6555 the initial bp(s) in the chain which should be deleted,
6556 the second goes down the rest of the chain looking ahead
6557 one so it can take those bps off the chain without messing
6558 up the chain. */
6559
6560
6561 for (i = 0; i < sals.nelts; i++)
6562 {
6563 /* If exact pc given, clear bpts at that pc.
c5aa993b
JM
6564 If line given (pc == 0), clear all bpts on specified line.
6565 If defaulting, clear all bpts on default line
c906108c 6566 or at default pc.
c5aa993b
JM
6567
6568 defaulting sal.pc != 0 tests to do
6569
6570 0 1 pc
6571 1 1 pc _and_ line
6572 0 0 line
6573 1 0 <can't happen> */
c906108c
SS
6574
6575 sal = sals.sals[i];
6576 found = (struct breakpoint *) 0;
6577
6578
6579 while (breakpoint_chain
c5aa993b
JM
6580 /* Why don't we check here that this is not
6581 a watchpoint, etc., as we do below?
6582 I can't make it fail, but don't know
6583 what's stopping the failure: a watchpoint
6584 of the same address as "sal.pc" should
6585 wind up being deleted. */
6586
6587 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6588 (overlay_debugging == 0 ||
6589 breakpoint_chain->section == sal.section))
6590 || ((default_match || (0 == sal.pc))
6591 && breakpoint_chain->source_file != NULL
6592 && sal.symtab != NULL
6593 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6594 && breakpoint_chain->line_number == sal.line)))
c906108c
SS
6595
6596 {
6597 b1 = breakpoint_chain;
6598 breakpoint_chain = b1->next;
6599 b1->next = found;
6600 found = b1;
6601 }
6602
6603 ALL_BREAKPOINTS (b)
6604
c5aa993b
JM
6605 while (b->next
6606 && b->next->type != bp_none
6607 && b->next->type != bp_watchpoint
6608 && b->next->type != bp_hardware_watchpoint
6609 && b->next->type != bp_read_watchpoint
6610 && b->next->type != bp_access_watchpoint
6611 && (((sal.pc && (b->next->address == sal.pc)) &&
6612 (overlay_debugging == 0 ||
6613 b->next->section == sal.section))
6614 || ((default_match || (0 == sal.pc))
6615 && b->next->source_file != NULL
6616 && sal.symtab != NULL
6617 && STREQ (b->next->source_file, sal.symtab->filename)
6618 && b->next->line_number == sal.line)))
c906108c
SS
6619
6620
c5aa993b
JM
6621 {
6622 b1 = b->next;
6623 b->next = b1->next;
6624 b1->next = found;
6625 found = b1;
6626 }
c906108c
SS
6627
6628 if (found == 0)
6629 {
6630 if (arg)
6631 error ("No breakpoint at %s.", arg);
6632 else
6633 error ("No breakpoint at this line.");
6634 }
6635
c5aa993b
JM
6636 if (found->next)
6637 from_tty = 1; /* Always report if deleted more than one */
6638 if (from_tty)
6639 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
c906108c
SS
6640 breakpoints_changed ();
6641 while (found)
6642 {
c5aa993b
JM
6643 if (from_tty)
6644 printf_unfiltered ("%d ", found->number);
c906108c
SS
6645 b1 = found->next;
6646 delete_breakpoint (found);
6647 found = b1;
6648 }
c5aa993b
JM
6649 if (from_tty)
6650 putchar_unfiltered ('\n');
c906108c 6651 }
b8c9b27d 6652 xfree (sals.sals);
c906108c
SS
6653}
6654\f
6655/* Delete breakpoint in BS if they are `delete' breakpoints and
6656 all breakpoints that are marked for deletion, whether hit or not.
6657 This is called after any breakpoint is hit, or after errors. */
6658
6659void
fba45db2 6660breakpoint_auto_delete (bpstat bs)
c906108c
SS
6661{
6662 struct breakpoint *b, *temp;
6663
6664 for (; bs; bs = bs->next)
c5aa993b 6665 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
c906108c
SS
6666 && bs->stop)
6667 delete_breakpoint (bs->breakpoint_at);
6668
6669 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b
JM
6670 {
6671 if (b->disposition == del_at_next_stop)
6672 delete_breakpoint (b);
6673 }
c906108c
SS
6674}
6675
53a5351d
JM
6676/* Delete a breakpoint and clean up all traces of it in the data
6677 structures. */
c906108c
SS
6678
6679void
fba45db2 6680delete_breakpoint (struct breakpoint *bpt)
c906108c
SS
6681{
6682 register struct breakpoint *b;
6683 register bpstat bs;
6684
6685 if (bpt == NULL)
6686 error ("Internal error (attempted to delete a NULL breakpoint)");
6687
6688
6689 /* Has this bp already been deleted? This can happen because multiple
6690 lists can hold pointers to bp's. bpstat lists are especial culprits.
6691
6692 One example of this happening is a watchpoint's scope bp. When the
6693 scope bp triggers, we notice that the watchpoint is out of scope, and
6694 delete it. We also delete its scope bp. But the scope bp is marked
6695 "auto-deleting", and is already on a bpstat. That bpstat is then
6696 checked for auto-deleting bp's, which are deleted.
6697
6698 A real solution to this problem might involve reference counts in bp's,
6699 and/or giving them pointers back to their referencing bpstat's, and
6700 teaching delete_breakpoint to only free a bp's storage when no more
6701 references were extent. A cheaper bandaid was chosen. */
6702 if (bpt->type == bp_none)
6703 return;
6704
6705 if (delete_breakpoint_hook)
6706 delete_breakpoint_hook (bpt);
104c1213 6707 breakpoint_delete_event (bpt->number);
c906108c
SS
6708
6709 if (bpt->inserted)
6710 remove_breakpoint (bpt, mark_uninserted);
c5aa993b 6711
c906108c
SS
6712 if (breakpoint_chain == bpt)
6713 breakpoint_chain = bpt->next;
6714
6715 /* If we have callback-style exception catchpoints, don't go through
6716 the adjustments to the C++ runtime library etc. if the inferior
6717 isn't actually running. target_enable_exception_callback for a
6718 null target ops vector gives an undesirable error message, so we
6719 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
c5aa993b 6720 exceptions are supported in this way, it's OK for now. FIXME */
c906108c
SS
6721 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6722 {
6723 static char message1[] = "Error in deleting catchpoint %d:\n";
6724 static char message[sizeof (message1) + 30];
6725 args_for_catchpoint_enable args;
6726
53a5351d
JM
6727 /* Format possible error msg */
6728 sprintf (message, message1, bpt->number);
6729 args.kind = bpt->type == bp_catch_catch ?
6730 EX_EVENT_CATCH : EX_EVENT_THROW;
c906108c
SS
6731 args.enable = 0;
6732 catch_errors (cover_target_enable_exception_callback, &args,
6733 message, RETURN_MASK_ALL);
6734 }
6735
6736
6737 ALL_BREAKPOINTS (b)
6738 if (b->next == bpt)
c5aa993b
JM
6739 {
6740 b->next = bpt->next;
6741 break;
6742 }
c906108c
SS
6743
6744 /* Before turning off the visuals for the bp, check to see that
6745 there are no other bps at the same address. */
6746 if (tui_version)
6747 {
6748 int clearIt;
6749
6750 ALL_BREAKPOINTS (b)
c5aa993b
JM
6751 {
6752 clearIt = (b->address != bpt->address);
6753 if (!clearIt)
6754 break;
6755 }
c906108c
SS
6756
6757 if (clearIt)
c5aa993b
JM
6758 {
6759 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6760 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6761 }
c906108c
SS
6762 }
6763
6764 check_duplicates (bpt->address, bpt->section);
6765 /* If this breakpoint was inserted, and there is another breakpoint
6766 at the same address, we need to insert the other breakpoint. */
6767 if (bpt->inserted
6768 && bpt->type != bp_hardware_watchpoint
6769 && bpt->type != bp_read_watchpoint
6770 && bpt->type != bp_access_watchpoint
6771 && bpt->type != bp_catch_fork
6772 && bpt->type != bp_catch_vfork
6773 && bpt->type != bp_catch_exec)
6774 {
6775 ALL_BREAKPOINTS (b)
6776 if (b->address == bpt->address
6777 && b->section == bpt->section
6778 && !b->duplicate
6779 && b->enable != disabled
6780 && b->enable != shlib_disabled
6781 && b->enable != call_disabled)
c5aa993b
JM
6782 {
6783 int val;
53a5351d 6784
c2c6d25f
JM
6785 /* We should never reach this point if there is a permanent
6786 breakpoint at the same address as the one being deleted.
6787 If there is a permanent breakpoint somewhere, it should
6788 always be the only one inserted. */
6789 if (b->enable == permanent)
8e65ff28
AC
6790 internal_error (__FILE__, __LINE__,
6791 "another breakpoint was inserted on top of "
c2c6d25f
JM
6792 "a permanent breakpoint");
6793
53a5351d
JM
6794 if (b->type == bp_hardware_breakpoint)
6795 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6796 else
6797 val = target_insert_breakpoint (b->address, b->shadow_contents);
6798
c5aa993b
JM
6799 if (val != 0)
6800 {
6801 target_terminal_ours_for_output ();
53a5351d 6802 warning ("Cannot insert breakpoint %d:", b->number);
c5aa993b
JM
6803 memory_error (val, b->address); /* which bombs us out */
6804 }
6805 else
6806 b->inserted = 1;
6807 }
c906108c
SS
6808 }
6809
6810 free_command_lines (&bpt->commands);
6811 if (bpt->cond)
b8c9b27d 6812 xfree (bpt->cond);
c906108c 6813 if (bpt->cond_string != NULL)
b8c9b27d 6814 xfree (bpt->cond_string);
c906108c 6815 if (bpt->addr_string != NULL)
b8c9b27d 6816 xfree (bpt->addr_string);
c906108c 6817 if (bpt->exp != NULL)
b8c9b27d 6818 xfree (bpt->exp);
c906108c 6819 if (bpt->exp_string != NULL)
b8c9b27d 6820 xfree (bpt->exp_string);
c906108c
SS
6821 if (bpt->val != NULL)
6822 value_free (bpt->val);
6823 if (bpt->source_file != NULL)
b8c9b27d 6824 xfree (bpt->source_file);
c906108c 6825 if (bpt->dll_pathname != NULL)
b8c9b27d 6826 xfree (bpt->dll_pathname);
c906108c 6827 if (bpt->triggered_dll_pathname != NULL)
b8c9b27d 6828 xfree (bpt->triggered_dll_pathname);
c906108c 6829 if (bpt->exec_pathname != NULL)
b8c9b27d 6830 xfree (bpt->exec_pathname);
c906108c
SS
6831
6832 /* Be sure no bpstat's are pointing at it after it's been freed. */
6833 /* FIXME, how can we find all bpstat's?
6834 We just check stop_bpstat for now. */
6835 for (bs = stop_bpstat; bs; bs = bs->next)
6836 if (bs->breakpoint_at == bpt)
6837 {
6838 bs->breakpoint_at = NULL;
6839
6840 /* we'd call bpstat_clear_actions, but that free's stuff and due
6841 to the multiple pointers pointing to one item with no
6842 reference counts found anywhere through out the bpstat's (how
6843 do you spell fragile?), we don't want to free things twice --
6844 better a memory leak than a corrupt malloc pool! */
6845 bs->commands = NULL;
6846 bs->old_val = NULL;
6847 }
6848 /* On the chance that someone will soon try again to delete this same
6849 bp, we mark it as deleted before freeing its storage. */
6850 bpt->type = bp_none;
6851
b8c9b27d 6852 xfree (bpt);
c906108c
SS
6853}
6854
4d6140d9
AC
6855static void
6856do_delete_breakpoint_cleanup (void *b)
6857{
6858 delete_breakpoint (b);
6859}
6860
6861struct cleanup *
6862make_cleanup_delete_breakpoint (struct breakpoint *b)
6863{
6864 return make_cleanup (do_delete_breakpoint_cleanup, b);
6865}
6866
6867struct cleanup *
6868make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6869{
6870 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6871}
6872
c906108c 6873void
fba45db2 6874delete_command (char *arg, int from_tty)
c906108c
SS
6875{
6876 struct breakpoint *b, *temp;
6877
6878 if (arg == 0)
6879 {
6880 int breaks_to_delete = 0;
6881
6882 /* Delete all breakpoints if no argument.
c5aa993b
JM
6883 Do not delete internal or call-dummy breakpoints, these
6884 have to be deleted with an explicit breakpoint number argument. */
6885 ALL_BREAKPOINTS (b)
6886 {
6887 if (b->type != bp_call_dummy &&
6888 b->type != bp_shlib_event &&
c4093a6a 6889 b->type != bp_thread_event &&
c5aa993b
JM
6890 b->number >= 0)
6891 breaks_to_delete = 1;
6892 }
c906108c
SS
6893
6894 /* Ask user only if there are some breakpoints to delete. */
6895 if (!from_tty
6896 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6897 {
c5aa993b
JM
6898 ALL_BREAKPOINTS_SAFE (b, temp)
6899 {
6900 if (b->type != bp_call_dummy &&
6901 b->type != bp_shlib_event &&
c4093a6a 6902 b->type != bp_thread_event &&
c5aa993b
JM
6903 b->number >= 0)
6904 delete_breakpoint (b);
6905 }
c906108c
SS
6906 }
6907 }
6908 else
6909 map_breakpoint_numbers (arg, delete_breakpoint);
6910}
6911
6912/* Reset a breakpoint given it's struct breakpoint * BINT.
6913 The value we return ends up being the return value from catch_errors.
6914 Unused in this case. */
6915
6916static int
fba45db2 6917breakpoint_re_set_one (PTR bint)
c906108c 6918{
53a5351d
JM
6919 /* get past catch_errs */
6920 struct breakpoint *b = (struct breakpoint *) bint;
c906108c
SS
6921 struct value *mark;
6922 int i;
6923 struct symtabs_and_lines sals;
6924 char *s;
6925 enum enable save_enable;
6926
6927 switch (b->type)
6928 {
6929 case bp_none:
53a5351d
JM
6930 warning ("attempted to reset apparently deleted breakpoint #%d?",
6931 b->number);
c906108c
SS
6932 return 0;
6933 case bp_breakpoint:
6934 case bp_hardware_breakpoint:
6935 case bp_catch_load:
6936 case bp_catch_unload:
6937 if (b->addr_string == NULL)
6938 {
6939 /* Anything without a string can't be re-set. */
6940 delete_breakpoint (b);
6941 return 0;
6942 }
6943 /* In case we have a problem, disable this breakpoint. We'll restore
c5aa993b 6944 its status if we succeed. */
c906108c
SS
6945 save_enable = b->enable;
6946 b->enable = disabled;
6947
6948 set_language (b->language);
6949 input_radix = b->input_radix;
6950 s = b->addr_string;
c5aa993b 6951 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
6952 for (i = 0; i < sals.nelts; i++)
6953 {
6954 resolve_sal_pc (&sals.sals[i]);
6955
6956 /* Reparse conditions, they might contain references to the
6957 old symtab. */
6958 if (b->cond_string != NULL)
6959 {
6960 s = b->cond_string;
6961 if (b->cond)
b8c9b27d 6962 xfree (b->cond);
c906108c
SS
6963 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6964 }
6965
c5aa993b 6966 /* We need to re-set the breakpoint if the address changes... */
c906108c 6967 if (b->address != sals.sals[i].pc
c5aa993b
JM
6968 /* ...or new and old breakpoints both have source files, and
6969 the source file name or the line number changes... */
c906108c
SS
6970 || (b->source_file != NULL
6971 && sals.sals[i].symtab != NULL
6972 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6973 || b->line_number != sals.sals[i].line)
c906108c 6974 )
c5aa993b
JM
6975 /* ...or we switch between having a source file and not having
6976 one. */
6977 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6978 )
c906108c
SS
6979 {
6980 if (b->source_file != NULL)
b8c9b27d 6981 xfree (b->source_file);
c906108c
SS
6982 if (sals.sals[i].symtab == NULL)
6983 b->source_file = NULL;
6984 else
6985 b->source_file =
6986 savestring (sals.sals[i].symtab->filename,
6987 strlen (sals.sals[i].symtab->filename));
6988 b->line_number = sals.sals[i].line;
6989 b->address = sals.sals[i].pc;
6990
c5aa993b
JM
6991 /* Used to check for duplicates here, but that can
6992 cause trouble, as it doesn't check for disable
6993 breakpoints. */
c906108c
SS
6994
6995 mention (b);
6996
6997 /* Might be better to do this just once per breakpoint_re_set,
c5aa993b 6998 rather than once for every breakpoint. */
c906108c
SS
6999 breakpoints_changed ();
7000 }
7001 b->section = sals.sals[i].section;
7002 b->enable = save_enable; /* Restore it, this worked. */
7003
7004
c5aa993b 7005 /* Now that this is re-enabled, check_duplicates
c906108c 7006 can be used. */
c5aa993b 7007 check_duplicates (b->address, b->section);
c906108c
SS
7008
7009 }
b8c9b27d 7010 xfree (sals.sals);
c906108c
SS
7011 break;
7012
7013 case bp_watchpoint:
7014 case bp_hardware_watchpoint:
7015 case bp_read_watchpoint:
7016 case bp_access_watchpoint:
7017 innermost_block = NULL;
53a5351d
JM
7018 /* The issue arises of what context to evaluate this in. The
7019 same one as when it was set, but what does that mean when
7020 symbols have been re-read? We could save the filename and
7021 functionname, but if the context is more local than that, the
7022 best we could do would be something like how many levels deep
7023 and which index at that particular level, but that's going to
7024 be less stable than filenames or function names. */
7025
c906108c
SS
7026 /* So for now, just use a global context. */
7027 if (b->exp)
b8c9b27d 7028 xfree (b->exp);
c906108c
SS
7029 b->exp = parse_expression (b->exp_string);
7030 b->exp_valid_block = innermost_block;
7031 mark = value_mark ();
7032 if (b->val)
7033 value_free (b->val);
7034 b->val = evaluate_expression (b->exp);
7035 release_value (b->val);
7036 if (VALUE_LAZY (b->val))
7037 value_fetch_lazy (b->val);
7038
7039 if (b->cond_string != NULL)
7040 {
7041 s = b->cond_string;
7042 if (b->cond)
b8c9b27d 7043 xfree (b->cond);
c5aa993b 7044 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
c906108c
SS
7045 }
7046 if (b->enable == enabled)
7047 mention (b);
7048 value_free_to_mark (mark);
7049 break;
c5aa993b
JM
7050 case bp_catch_catch:
7051 case bp_catch_throw:
c906108c 7052 break;
c5aa993b
JM
7053 /* We needn't really do anything to reset these, since the mask
7054 that requests them is unaffected by e.g., new libraries being
7055 loaded. */
c906108c
SS
7056 case bp_catch_fork:
7057 case bp_catch_vfork:
7058 case bp_catch_exec:
7059 break;
c5aa993b 7060
c906108c
SS
7061 default:
7062 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7063 /* fall through */
c5aa993b
JM
7064 /* Delete longjmp breakpoints, they will be reset later by
7065 breakpoint_re_set. */
c906108c
SS
7066 case bp_longjmp:
7067 case bp_longjmp_resume:
7068 delete_breakpoint (b);
7069 break;
7070
c5aa993b
JM
7071 /* This breakpoint is special, it's set up when the inferior
7072 starts and we really don't want to touch it. */
c906108c
SS
7073 case bp_shlib_event:
7074
c4093a6a
JM
7075 /* Like bp_shlib_event, this breakpoint type is special.
7076 Once it is set up, we do not want to touch it. */
7077 case bp_thread_event:
7078
c5aa993b
JM
7079 /* Keep temporary breakpoints, which can be encountered when we step
7080 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7081 Otherwise these should have been blown away via the cleanup chain
7082 or by breakpoint_init_inferior when we rerun the executable. */
c906108c
SS
7083 case bp_until:
7084 case bp_finish:
7085 case bp_watchpoint_scope:
7086 case bp_call_dummy:
7087 case bp_step_resume:
7088 break;
7089 }
7090
7091 return 0;
7092}
7093
7094/* Re-set all breakpoints after symbols have been re-loaded. */
7095void
fba45db2 7096breakpoint_re_set (void)
c906108c
SS
7097{
7098 struct breakpoint *b, *temp;
7099 enum language save_language;
7100 int save_input_radix;
7101 static char message1[] = "Error in re-setting breakpoint %d:\n";
c5aa993b
JM
7102 char message[sizeof (message1) + 30 /* slop */ ];
7103
c906108c
SS
7104 save_language = current_language->la_language;
7105 save_input_radix = input_radix;
7106 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 7107 {
53a5351d
JM
7108 /* Format possible error msg */
7109 sprintf (message, message1, b->number);
c5aa993b
JM
7110 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7111 }
c906108c
SS
7112 set_language (save_language);
7113 input_radix = save_input_radix;
7114
7115#ifdef GET_LONGJMP_TARGET
7116 create_longjmp_breakpoint ("longjmp");
7117 create_longjmp_breakpoint ("_longjmp");
7118 create_longjmp_breakpoint ("siglongjmp");
7119 create_longjmp_breakpoint ("_siglongjmp");
7120 create_longjmp_breakpoint (NULL);
7121#endif
7122
7123#if 0
7124 /* Took this out (temporarily at least), since it produces an extra
7125 blank line at startup. This messes up the gdbtests. -PB */
7126 /* Blank line to finish off all those mention() messages we just printed. */
7127 printf_filtered ("\n");
7128#endif
7129}
7130\f
7131/* Set ignore-count of breakpoint number BPTNUM to COUNT.
7132 If from_tty is nonzero, it prints a message to that effect,
7133 which ends with a period (no newline). */
7134
7135/* Reset the thread number of this breakpoint:
7136
7137 - If the breakpoint is for all threads, leave it as-is.
7138 - Else, reset it to the current thread for inferior_pid. */
7139void
fba45db2 7140breakpoint_re_set_thread (struct breakpoint *b)
c906108c
SS
7141{
7142 if (b->thread != -1)
7143 {
7144 if (in_thread_list (inferior_pid))
c5aa993b 7145 b->thread = pid_to_thread_id (inferior_pid);
c906108c
SS
7146 }
7147}
7148
7149void
fba45db2 7150set_ignore_count (int bptnum, int count, int from_tty)
c906108c
SS
7151{
7152 register struct breakpoint *b;
7153
7154 if (count < 0)
7155 count = 0;
7156
7157 ALL_BREAKPOINTS (b)
7158 if (b->number == bptnum)
c5aa993b
JM
7159 {
7160 b->ignore_count = count;
7161 if (!from_tty)
c906108c 7162 return;
c5aa993b
JM
7163 else if (count == 0)
7164 printf_filtered ("Will stop next time breakpoint %d is reached.",
7165 bptnum);
7166 else if (count == 1)
7167 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7168 bptnum);
7169 else
7170 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7171 count, bptnum);
7172 breakpoints_changed ();
7173 return;
7174 }
c906108c
SS
7175
7176 error ("No breakpoint number %d.", bptnum);
7177}
7178
7179/* Clear the ignore counts of all breakpoints. */
7180void
fba45db2 7181breakpoint_clear_ignore_counts (void)
c906108c
SS
7182{
7183 struct breakpoint *b;
7184
7185 ALL_BREAKPOINTS (b)
7186 b->ignore_count = 0;
7187}
7188
7189/* Command to set ignore-count of breakpoint N to COUNT. */
7190
7191static void
fba45db2 7192ignore_command (char *args, int from_tty)
c906108c
SS
7193{
7194 char *p = args;
7195 register int num;
7196
7197 if (p == 0)
7198 error_no_arg ("a breakpoint number");
c5aa993b 7199
c906108c 7200 num = get_number (&p);
5c44784c
JM
7201 if (num == 0)
7202 error ("bad breakpoint number: '%s'", args);
c906108c
SS
7203 if (*p == 0)
7204 error ("Second argument (specified ignore-count) is missing.");
7205
7206 set_ignore_count (num,
7207 longest_to_int (value_as_long (parse_and_eval (p))),
7208 from_tty);
7209 printf_filtered ("\n");
7210 breakpoints_changed ();
7211}
7212\f
7213/* Call FUNCTION on each of the breakpoints
7214 whose numbers are given in ARGS. */
7215
7216static void
831662b3 7217map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
c906108c
SS
7218{
7219 register char *p = args;
7220 char *p1;
7221 register int num;
5c44784c 7222 register struct breakpoint *b, *tmp;
11cf8741 7223 int match;
c906108c
SS
7224
7225 if (p == 0)
7226 error_no_arg ("one or more breakpoint numbers");
7227
7228 while (*p)
7229 {
11cf8741 7230 match = 0;
c906108c 7231 p1 = p;
c5aa993b 7232
5c44784c
JM
7233 num = get_number_or_range (&p1);
7234 if (num == 0)
c5aa993b 7235 {
5c44784c
JM
7236 warning ("bad breakpoint number at or near '%s'", p);
7237 }
7238 else
7239 {
7240 ALL_BREAKPOINTS_SAFE (b, tmp)
7241 if (b->number == num)
7242 {
7243 struct breakpoint *related_breakpoint = b->related_breakpoint;
11cf8741 7244 match = 1;
5c44784c
JM
7245 function (b);
7246 if (related_breakpoint)
7247 function (related_breakpoint);
11cf8741 7248 break;
5c44784c 7249 }
11cf8741
JM
7250 if (match == 0)
7251 printf_unfiltered ("No breakpoint number %d.\n", num);
c5aa993b 7252 }
c906108c
SS
7253 p = p1;
7254 }
7255}
7256
7257void
fba45db2 7258disable_breakpoint (struct breakpoint *bpt)
c906108c
SS
7259{
7260 /* Never disable a watchpoint scope breakpoint; we want to
7261 hit them when we leave scope so we can delete both the
7262 watchpoint and its scope breakpoint at that time. */
7263 if (bpt->type == bp_watchpoint_scope)
7264 return;
7265
c2c6d25f
JM
7266 /* You can't disable permanent breakpoints. */
7267 if (bpt->enable == permanent)
7268 return;
7269
c906108c
SS
7270 bpt->enable = disabled;
7271
7272 check_duplicates (bpt->address, bpt->section);
7273
7274 if (modify_breakpoint_hook)
7275 modify_breakpoint_hook (bpt);
104c1213 7276 breakpoint_modify_event (bpt->number);
c906108c
SS
7277}
7278
7279/* ARGSUSED */
7280static void
fba45db2 7281disable_command (char *args, int from_tty)
c906108c
SS
7282{
7283 register struct breakpoint *bpt;
7284 if (args == 0)
7285 ALL_BREAKPOINTS (bpt)
7286 switch (bpt->type)
c5aa993b
JM
7287 {
7288 case bp_none:
53a5351d
JM
7289 warning ("attempted to disable apparently deleted breakpoint #%d?",
7290 bpt->number);
c5aa993b
JM
7291 continue;
7292 case bp_breakpoint:
7293 case bp_catch_load:
7294 case bp_catch_unload:
7295 case bp_catch_fork:
7296 case bp_catch_vfork:
7297 case bp_catch_exec:
7298 case bp_catch_catch:
7299 case bp_catch_throw:
7300 case bp_hardware_breakpoint:
7301 case bp_watchpoint:
7302 case bp_hardware_watchpoint:
7303 case bp_read_watchpoint:
7304 case bp_access_watchpoint:
7305 disable_breakpoint (bpt);
7306 default:
7307 continue;
7308 }
c906108c
SS
7309 else
7310 map_breakpoint_numbers (args, disable_breakpoint);
7311}
7312
7313static void
fba45db2 7314do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
c906108c
SS
7315{
7316 struct frame_info *save_selected_frame = NULL;
7317 int save_selected_frame_level = -1;
7318 int target_resources_ok, other_type_used;
7319 struct value *mark;
7320
7321 if (bpt->type == bp_hardware_breakpoint)
7322 {
7323 int i;
c5aa993b 7324 i = hw_breakpoint_used_count ();
53a5351d
JM
7325 target_resources_ok =
7326 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7327 i + 1, 0);
c906108c 7328 if (target_resources_ok == 0)
c5aa993b 7329 error ("No hardware breakpoint support in the target.");
c906108c 7330 else if (target_resources_ok < 0)
c5aa993b 7331 error ("Hardware breakpoints used exceeds limit.");
c906108c
SS
7332 }
7333
c2c6d25f
JM
7334 if (bpt->enable != permanent)
7335 bpt->enable = enabled;
c906108c
SS
7336 bpt->disposition = disposition;
7337 check_duplicates (bpt->address, bpt->section);
7338 breakpoints_changed ();
7339
53a5351d
JM
7340 if (bpt->type == bp_watchpoint ||
7341 bpt->type == bp_hardware_watchpoint ||
7342 bpt->type == bp_read_watchpoint ||
7343 bpt->type == bp_access_watchpoint)
c906108c
SS
7344 {
7345 if (bpt->exp_valid_block != NULL)
7346 {
7347 struct frame_info *fr =
7348
c5aa993b
JM
7349 /* Ensure that we have the current frame. Else, this
7350 next query may pessimistically be answered as, "No,
7351 not within current scope". */
7352 get_current_frame ();
7353 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
c906108c
SS
7354 if (fr == NULL)
7355 {
7356 printf_filtered ("\
7357Cannot enable watchpoint %d because the block in which its expression\n\
7358is valid is not currently in scope.\n", bpt->number);
7359 bpt->enable = disabled;
7360 return;
7361 }
7362
7363 save_selected_frame = selected_frame;
7364 save_selected_frame_level = selected_frame_level;
7365 select_frame (fr, -1);
7366 }
7367
7368 value_free (bpt->val);
7369 mark = value_mark ();
7370 bpt->val = evaluate_expression (bpt->exp);
7371 release_value (bpt->val);
7372 if (VALUE_LAZY (bpt->val))
7373 value_fetch_lazy (bpt->val);
7374
7375 if (bpt->type == bp_hardware_watchpoint ||
c5aa993b
JM
7376 bpt->type == bp_read_watchpoint ||
7377 bpt->type == bp_access_watchpoint)
7378 {
7379 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7380 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7381
7382 /* Hack around 'unused var' error for some targets here */
7383 (void) mem_cnt, i;
7384 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7385 bpt->type, i + mem_cnt, other_type_used);
7386 /* we can consider of type is bp_hardware_watchpoint, convert to
7387 bp_watchpoint in the following condition */
7388 if (target_resources_ok < 0)
7389 {
7390 printf_filtered ("\
c906108c
SS
7391Cannot enable watchpoint %d because target watch resources\n\
7392have been allocated for other watchpoints.\n", bpt->number);
c5aa993b
JM
7393 bpt->enable = disabled;
7394 value_free_to_mark (mark);
7395 return;
7396 }
7397 }
c906108c
SS
7398
7399 if (save_selected_frame_level >= 0)
c6902688 7400 select_frame (save_selected_frame, save_selected_frame_level);
c906108c
SS
7401 value_free_to_mark (mark);
7402 }
7403 if (modify_breakpoint_hook)
7404 modify_breakpoint_hook (bpt);
104c1213 7405 breakpoint_modify_event (bpt->number);
c906108c
SS
7406}
7407
7408void
fba45db2 7409enable_breakpoint (struct breakpoint *bpt)
c906108c
SS
7410{
7411 do_enable_breakpoint (bpt, bpt->disposition);
7412}
7413
7414/* The enable command enables the specified breakpoints (or all defined
7415 breakpoints) so they once again become (or continue to be) effective
7416 in stopping the inferior. */
7417
7418/* ARGSUSED */
7419static void
fba45db2 7420enable_command (char *args, int from_tty)
c906108c
SS
7421{
7422 register struct breakpoint *bpt;
7423 if (args == 0)
7424 ALL_BREAKPOINTS (bpt)
7425 switch (bpt->type)
c5aa993b
JM
7426 {
7427 case bp_none:
53a5351d
JM
7428 warning ("attempted to enable apparently deleted breakpoint #%d?",
7429 bpt->number);
c5aa993b
JM
7430 continue;
7431 case bp_breakpoint:
7432 case bp_catch_load:
7433 case bp_catch_unload:
7434 case bp_catch_fork:
7435 case bp_catch_vfork:
7436 case bp_catch_exec:
7437 case bp_catch_catch:
7438 case bp_catch_throw:
7439 case bp_hardware_breakpoint:
7440 case bp_watchpoint:
7441 case bp_hardware_watchpoint:
7442 case bp_read_watchpoint:
7443 case bp_access_watchpoint:
7444 enable_breakpoint (bpt);
7445 default:
7446 continue;
7447 }
c906108c
SS
7448 else
7449 map_breakpoint_numbers (args, enable_breakpoint);
7450}
7451
7452static void
fba45db2 7453enable_once_breakpoint (struct breakpoint *bpt)
c906108c
SS
7454{
7455 do_enable_breakpoint (bpt, disable);
7456}
7457
7458/* ARGSUSED */
7459static void
fba45db2 7460enable_once_command (char *args, int from_tty)
c906108c
SS
7461{
7462 map_breakpoint_numbers (args, enable_once_breakpoint);
7463}
7464
7465static void
fba45db2 7466enable_delete_breakpoint (struct breakpoint *bpt)
c906108c
SS
7467{
7468 do_enable_breakpoint (bpt, del);
7469}
7470
7471/* ARGSUSED */
7472static void
fba45db2 7473enable_delete_command (char *args, int from_tty)
c906108c
SS
7474{
7475 map_breakpoint_numbers (args, enable_delete_breakpoint);
7476}
7477\f
7478/* Use default_breakpoint_'s, or nothing if they aren't valid. */
7479
7480struct symtabs_and_lines
fba45db2 7481decode_line_spec_1 (char *string, int funfirstline)
c906108c
SS
7482{
7483 struct symtabs_and_lines sals;
7484 if (string == 0)
7485 error ("Empty line specification.");
7486 if (default_breakpoint_valid)
7487 sals = decode_line_1 (&string, funfirstline,
53a5351d
JM
7488 default_breakpoint_symtab,
7489 default_breakpoint_line,
c5aa993b 7490 (char ***) NULL);
c906108c
SS
7491 else
7492 sals = decode_line_1 (&string, funfirstline,
c5aa993b 7493 (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
7494 if (*string)
7495 error ("Junk at end of line specification: %s", string);
7496 return sals;
7497}
7498\f
7499void
fba45db2 7500_initialize_breakpoint (void)
c906108c
SS
7501{
7502 struct cmd_list_element *c;
7503
7504 breakpoint_chain = 0;
7505 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7506 before a breakpoint is set. */
7507 breakpoint_count = 0;
7508
7509 add_com ("ignore", class_breakpoint, ignore_command,
7510 "Set ignore-count of breakpoint number N to COUNT.\n\
7511Usage is `ignore N COUNT'.");
7512 if (xdb_commands)
c5aa993b 7513 add_com_alias ("bc", "ignore", class_breakpoint, 1);
c906108c
SS
7514
7515 add_com ("commands", class_breakpoint, commands_command,
7516 "Set commands to be executed when a breakpoint is hit.\n\
7517Give breakpoint number as argument after \"commands\".\n\
7518With no argument, the targeted breakpoint is the last one set.\n\
7519The commands themselves follow starting on the next line.\n\
7520Type a line containing \"end\" to indicate the end of them.\n\
7521Give \"silent\" as the first line to make the breakpoint silent;\n\
7522then no output is printed when it is hit, except what the commands print.");
7523
7524 add_com ("condition", class_breakpoint, condition_command,
7525 "Specify breakpoint number N to break only if COND is true.\n\
7526Usage is `condition N COND', where N is an integer and COND is an\n\
7527expression to be evaluated whenever breakpoint N is reached. ");
7528
7529 add_com ("tbreak", class_breakpoint, tbreak_command,
7530 "Set a temporary breakpoint. Args like \"break\" command.\n\
7531Like \"break\" except the breakpoint is only temporary,\n\
7532so it will be deleted when hit. Equivalent to \"break\" followed\n\
7533by using \"enable delete\" on the breakpoint number.");
c5aa993b
JM
7534 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7535 "Set temporary breakpoint at procedure exit. Either there should\n\
c906108c
SS
7536be no argument or the argument must be a depth.\n");
7537
7538 add_com ("hbreak", class_breakpoint, hbreak_command,
7539 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7540Like \"break\" except the breakpoint requires hardware support,\n\
7541some target hardware may not have this support.");
7542
7543 add_com ("thbreak", class_breakpoint, thbreak_command,
7544 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7545Like \"hbreak\" except the breakpoint is only temporary,\n\
7546so it will be deleted when hit.");
7547
7548 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7549 "Enable some breakpoints.\n\
7550Give breakpoint numbers (separated by spaces) as arguments.\n\
7551With no subcommand, breakpoints are enabled until you command otherwise.\n\
7552This is used to cancel the effect of the \"disable\" command.\n\
7553With a subcommand you can enable temporarily.",
7554 &enablelist, "enable ", 1, &cmdlist);
7555 if (xdb_commands)
c5aa993b
JM
7556 add_com ("ab", class_breakpoint, enable_command,
7557 "Enable some breakpoints.\n\
c906108c
SS
7558Give breakpoint numbers (separated by spaces) as arguments.\n\
7559With no subcommand, breakpoints are enabled until you command otherwise.\n\
7560This is used to cancel the effect of the \"disable\" command.\n\
7561With a subcommand you can enable temporarily.");
7562
7563 add_com_alias ("en", "enable", class_breakpoint, 1);
7564
7565 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
c5aa993b 7566 "Enable some breakpoints.\n\
c906108c
SS
7567Give breakpoint numbers (separated by spaces) as arguments.\n\
7568This is used to cancel the effect of the \"disable\" command.\n\
7569May be abbreviated to simply \"enable\".\n",
c5aa993b 7570 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
c906108c
SS
7571
7572 add_cmd ("once", no_class, enable_once_command,
7573 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7574If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7575 &enablebreaklist);
7576
7577 add_cmd ("delete", no_class, enable_delete_command,
7578 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7579If a breakpoint is hit while enabled in this fashion, it is deleted.",
7580 &enablebreaklist);
7581
7582 add_cmd ("delete", no_class, enable_delete_command,
7583 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7584If a breakpoint is hit while enabled in this fashion, it is deleted.",
7585 &enablelist);
7586
7587 add_cmd ("once", no_class, enable_once_command,
7588 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7589If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7590 &enablelist);
7591
7592 add_prefix_cmd ("disable", class_breakpoint, disable_command,
c5aa993b 7593 "Disable some breakpoints.\n\
c906108c
SS
7594Arguments are breakpoint numbers with spaces in between.\n\
7595To disable all breakpoints, give no argument.\n\
7596A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7597 &disablelist, "disable ", 1, &cmdlist);
7598 add_com_alias ("dis", "disable", class_breakpoint, 1);
7599 add_com_alias ("disa", "disable", class_breakpoint, 1);
7600 if (xdb_commands)
c5aa993b
JM
7601 add_com ("sb", class_breakpoint, disable_command,
7602 "Disable some breakpoints.\n\
c906108c
SS
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.");
7606
7607 add_cmd ("breakpoints", class_alias, disable_command,
7608 "Disable some breakpoints.\n\
7609Arguments are breakpoint numbers with spaces in between.\n\
7610To disable all breakpoints, give no argument.\n\
7611A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7612This command may be abbreviated \"disable\".",
7613 &disablelist);
7614
7615 add_prefix_cmd ("delete", class_breakpoint, delete_command,
c5aa993b 7616 "Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
7617Arguments are breakpoint numbers with spaces in between.\n\
7618To delete all breakpoints, give no argument.\n\
7619\n\
7620Also a prefix command for deletion of other GDB objects.\n\
7621The \"unset\" command is also an alias for \"delete\".",
7622 &deletelist, "delete ", 1, &cmdlist);
7623 add_com_alias ("d", "delete", class_breakpoint, 1);
7624 if (xdb_commands)
7625 add_com ("db", class_breakpoint, delete_command,
c5aa993b 7626 "Delete some breakpoints.\n\
c906108c
SS
7627Arguments are breakpoint numbers with spaces in between.\n\
7628To delete all breakpoints, give no argument.\n");
7629
7630 add_cmd ("breakpoints", class_alias, delete_command,
7631 "Delete some breakpoints or auto-display expressions.\n\
7632Arguments are breakpoint numbers with spaces in between.\n\
7633To delete all breakpoints, give no argument.\n\
7634This command may be abbreviated \"delete\".",
7635 &deletelist);
7636
7637 add_com ("clear", class_breakpoint, clear_command,
7638 concat ("Clear breakpoint at specified line or function.\n\
7639Argument may be line number, function name, or \"*\" and an address.\n\
7640If line number is specified, all breakpoints in that line are cleared.\n\
7641If function is specified, breakpoints at beginning of function are cleared.\n\
7642If an address is specified, breakpoints at that address are cleared.\n\n",
c5aa993b 7643 "With no argument, clears all breakpoints in the line that the selected frame\n\
c906108c
SS
7644is executing in.\n\
7645\n\
7646See also the \"delete\" command which clears breakpoints by number.", NULL));
7647
7648 add_com ("break", class_breakpoint, break_command,
7649 concat ("Set breakpoint at specified line or function.\n\
7650Argument may be line number, function name, or \"*\" and an address.\n\
7651If line number is specified, break at start of code for that line.\n\
7652If function is specified, break at start of code for that function.\n\
7653If an address is specified, break at that exact address.\n",
c5aa993b 7654 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
7655This is useful for breaking on return to a stack frame.\n\
7656\n\
7657Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7658\n\
7659Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7660 add_com_alias ("b", "break", class_run, 1);
7661 add_com_alias ("br", "break", class_run, 1);
7662 add_com_alias ("bre", "break", class_run, 1);
7663 add_com_alias ("brea", "break", class_run, 1);
7664
c5aa993b
JM
7665 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7666 concat ("Set breakpoint at procedure exit. \n\
c906108c
SS
7667Argument may be function name, or \"*\" and an address.\n\
7668If function is specified, break at end of code for that function.\n\
7669If an address is specified, break at the end of the function that contains \n\
7670that exact address.\n",
c5aa993b 7671 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
7672This is useful for breaking on return to a stack frame.\n\
7673\n\
7674Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7675\n\
7676Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7677 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7678 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7679 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7680 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7681
7682 if (xdb_commands)
7683 {
7684 add_com_alias ("ba", "break", class_breakpoint, 1);
7685 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7686 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
c5aa993b 7687 "Set breakpoint at procedure exit. Either there should\n\
c906108c
SS
7688be no argument or the argument must be a depth.\n");
7689 }
7690
7691 if (dbx_commands)
7692 {
c5aa993b
JM
7693 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7694 "Break in function/address or break at a line in the current file.",
7695 &stoplist, "stop ", 1, &cmdlist);
7696 add_cmd ("in", class_breakpoint, stopin_command,
7697 "Break in function or address.\n", &stoplist);
7698 add_cmd ("at", class_breakpoint, stopat_command,
7699 "Break at a line in the current file.\n", &stoplist);
7700 add_com ("status", class_info, breakpoints_info,
7701 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
7702The \"Type\" column indicates one of:\n\
7703\tbreakpoint - normal breakpoint\n\
7704\twatchpoint - watchpoint\n\
7705The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7706the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7707breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7708address and file/line number respectively.\n\n",
c5aa993b 7709 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
7710are set to the address of the last breakpoint listed.\n\n\
7711Convenience variable \"$bpnum\" contains the number of the last\n\
7712breakpoint set.", NULL));
7713 }
7714
7715 add_info ("breakpoints", breakpoints_info,
7716 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7717The \"Type\" column indicates one of:\n\
7718\tbreakpoint - normal breakpoint\n\
7719\twatchpoint - watchpoint\n\
7720The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7721the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7722breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7723address and file/line number respectively.\n\n",
c5aa993b 7724 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
7725are set to the address of the last breakpoint listed.\n\n\
7726Convenience variable \"$bpnum\" contains the number of the last\n\
7727breakpoint set.", NULL));
7728
7729 if (xdb_commands)
c5aa993b
JM
7730 add_com ("lb", class_breakpoint, breakpoints_info,
7731 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
7732The \"Type\" column indicates one of:\n\
7733\tbreakpoint - normal breakpoint\n\
7734\twatchpoint - watchpoint\n\
7735The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7736the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7737breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7738address and file/line number respectively.\n\n",
c5aa993b 7739 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
7740are set to the address of the last breakpoint listed.\n\n\
7741Convenience variable \"$bpnum\" contains the number of the last\n\
7742breakpoint set.", NULL));
7743
c906108c 7744 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
c5aa993b 7745 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
7746The \"Type\" column indicates one of:\n\
7747\tbreakpoint - normal breakpoint\n\
7748\twatchpoint - watchpoint\n\
7749\tlongjmp - internal breakpoint used to step through longjmp()\n\
7750\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7751\tuntil - internal breakpoint used by the \"until\" command\n\
7752\tfinish - internal breakpoint used by the \"finish\" command\n",
c5aa993b 7753 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
c906108c
SS
7754the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7755breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7756address and file/line number respectively.\n\n",
c5aa993b 7757 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
7758are set to the address of the last breakpoint listed.\n\n\
7759Convenience variable \"$bpnum\" contains the number of the last\n\
7760breakpoint set.", NULL),
7761 &maintenanceinfolist);
7762
c906108c 7763 add_com ("catch", class_breakpoint, catch_command,
c5aa993b 7764 "Set catchpoints to catch events.\n\
c906108c
SS
7765Raised signals may be caught:\n\
7766\tcatch signal - all signals\n\
7767\tcatch signal <signame> - a particular signal\n\
7768Raised exceptions may be caught:\n\
7769\tcatch throw - all exceptions, when thrown\n\
7770\tcatch throw <exceptname> - a particular exception, when thrown\n\
7771\tcatch catch - all exceptions, when caught\n\
7772\tcatch catch <exceptname> - a particular exception, when caught\n\
7773Thread or process events may be caught:\n\
7774\tcatch thread_start - any threads, just after creation\n\
7775\tcatch thread_exit - any threads, just before expiration\n\
7776\tcatch thread_join - any threads, just after joins\n\
7777Process events may be caught:\n\
7778\tcatch start - any processes, just after creation\n\
7779\tcatch exit - any processes, just before expiration\n\
7780\tcatch fork - calls to fork()\n\
7781\tcatch vfork - calls to vfork()\n\
7782\tcatch exec - calls to exec()\n\
7783Dynamically-linked library events may be caught:\n\
7784\tcatch load - loads of any library\n\
7785\tcatch load <libname> - loads of a particular library\n\
7786\tcatch unload - unloads of any library\n\
7787\tcatch unload <libname> - unloads of a particular library\n\
7788The act of your program's execution stopping may also be caught:\n\
7789\tcatch stop\n\n\
7790C++ exceptions may be caught:\n\
7791\tcatch throw - all exceptions, when thrown\n\
7792\tcatch catch - all exceptions, when caught\n\
7793\n\
7794Do \"help set follow-fork-mode\" for info on debugging your program\n\
7795after a fork or vfork is caught.\n\n\
7796Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
c5aa993b 7797
c906108c 7798 add_com ("tcatch", class_breakpoint, tcatch_command,
c5aa993b 7799 "Set temporary catchpoints to catch events.\n\
c906108c
SS
7800Args like \"catch\" command.\n\
7801Like \"catch\" except the catchpoint is only temporary,\n\
7802so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7803by using \"enable delete\" on the catchpoint number.");
c5aa993b
JM
7804
7805 add_com ("watch", class_breakpoint, watch_command,
c906108c
SS
7806 "Set a watchpoint for an expression.\n\
7807A watchpoint stops execution of your program whenever the value of\n\
7808an expression changes.");
7809
7810 add_com ("rwatch", class_breakpoint, rwatch_command,
7811 "Set a read watchpoint for an expression.\n\
7812A watchpoint stops execution of your program whenever the value of\n\
7813an expression is read.");
7814
7815 add_com ("awatch", class_breakpoint, awatch_command,
7816 "Set a watchpoint for an expression.\n\
7817A watchpoint stops execution of your program whenever the value of\n\
7818an expression is either read or written.");
7819
7820 add_info ("watchpoints", breakpoints_info,
7821 "Synonym for ``info breakpoints''.");
7822
7823
7824 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
c5aa993b
JM
7825 (char *) &can_use_hw_watchpoints,
7826 "Set debugger's willingness to use watchpoint hardware.\n\
c906108c
SS
7827If zero, gdb will not use hardware for new watchpoints, even if\n\
7828such is available. (However, any hardware watchpoints that were\n\
7829created before setting this to nonzero, will continue to use watchpoint\n\
7830hardware.)",
c5aa993b 7831 &setlist);
c906108c
SS
7832 add_show_from_set (c, &showlist);
7833
7834 can_use_hw_watchpoints = 1;
7835}
This page took 0.525128 seconds and 4 git commands to generate.