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