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