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