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