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