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