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