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.
5 This file is part of GDB.
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.
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.
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. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
46 #include "gdb-events.h"
48 /* Prototypes for local functions. */
50 static void until_break_command_continuation (struct continuation_arg *arg);
53 catch_command_1 PARAMS ((char *, int, int));
56 enable_delete_command PARAMS ((char *, int));
59 enable_delete_breakpoint PARAMS ((struct breakpoint *));
62 enable_once_command PARAMS ((char *, int));
65 enable_once_breakpoint PARAMS ((struct breakpoint *));
68 disable_command PARAMS ((char *, int));
71 enable_command PARAMS ((char *, int));
74 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
77 ignore_command PARAMS ((char *, int));
79 static int breakpoint_re_set_one PARAMS ((PTR));
82 clear_command PARAMS ((char *, int));
85 catch_command PARAMS ((char *, int));
88 handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
90 static struct symtabs_and_lines
91 get_catch_sals PARAMS ((int));
94 watch_command PARAMS ((char *, int));
97 can_use_hardware_watchpoint PARAMS ((struct value *));
99 static void break_at_finish_command PARAMS ((char *, int));
100 static void break_at_finish_at_depth_command PARAMS ((char *, int));
103 tbreak_command PARAMS ((char *, int));
105 static void tbreak_at_finish_command PARAMS ((char *, int));
108 break_command_1 PARAMS ((char *, int, int));
111 mention PARAMS ((struct breakpoint *));
114 set_raw_breakpoint PARAMS ((struct symtab_and_line));
117 check_duplicates PARAMS ((CORE_ADDR, asection *));
120 describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
123 breakpoints_info PARAMS ((char *, int));
126 breakpoint_1 PARAMS ((int, int));
129 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
131 static int breakpoint_cond_eval PARAMS ((PTR));
134 cleanup_executing_breakpoints PARAMS ((PTR));
137 commands_command PARAMS ((char *, int));
140 condition_command PARAMS ((char *, int));
143 get_number_trailer PARAMS ((char **, int));
146 set_breakpoint_count PARAMS ((int));
149 static struct breakpoint *
150 create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
161 remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
163 static enum print_stop_action print_it_typical PARAMS ((bpstat));
165 static enum print_stop_action print_bp_stop_message (bpstat bs);
169 enum exception_event_kind kind;
172 args_for_catchpoint_enable;
174 static int watchpoint_check PARAMS ((PTR));
176 static int cover_target_enable_exception_callback PARAMS ((PTR));
178 static void maintenance_info_breakpoints PARAMS ((char *, int));
180 #ifdef GET_LONGJMP_TARGET
181 static void create_longjmp_breakpoint PARAMS ((char *));
184 static int hw_breakpoint_used_count PARAMS ((void));
186 static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
188 static void hbreak_command PARAMS ((char *, int));
190 static void thbreak_command PARAMS ((char *, int));
192 static void watch_command_1 PARAMS ((char *, int, int));
194 static void rwatch_command PARAMS ((char *, int));
196 static void awatch_command PARAMS ((char *, int));
198 static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
200 static void solib_load_unload_1 PARAMS ((char *hookname,
204 enum bptype bp_kind));
206 static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag,
208 enum bptype bp_kind));
210 static void break_at_finish_at_depth_command_1 PARAMS ((char *arg,
214 static void break_at_finish_command_1 PARAMS ((char *arg,
218 static void stop_command PARAMS ((char *arg, int from_tty));
220 static void stopin_command PARAMS ((char *arg, int from_tty));
222 static void stopat_command PARAMS ((char *arg, int from_tty));
224 static char *ep_find_event_name_end PARAMS ((char *arg));
226 static char *ep_parse_optional_if_clause PARAMS ((char **arg));
228 static char *ep_parse_optional_filename PARAMS ((char **arg));
230 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
231 static void catch_exec_command_1 PARAMS ((char *arg, int tempflag,
235 static void create_exception_catchpoint
236 PARAMS ((int tempflag, char *cond_string,
237 enum exception_event_kind ex_event,
238 struct symtab_and_line * sal));
240 static void catch_exception_command_1
241 PARAMS ((enum exception_event_kind ex_event,
242 char *arg, int tempflag, int from_tty));
244 static void tcatch_command PARAMS ((char *arg, int from_tty));
246 static void ep_skip_leading_whitespace PARAMS ((char **s));
248 /* Prototypes for exported functions. */
251 awatch_command PARAMS ((char *, int));
254 do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
256 /* If FALSE, gdb will not use hardware support for watchpoints, even
257 if such is available. */
258 static int can_use_hw_watchpoints;
260 void _initialize_breakpoint PARAMS ((void));
262 void set_breakpoint_count PARAMS ((int));
264 extern int addressprint; /* Print machine addresses? */
266 static int internal_breakpoint_number = -1;
268 /* Are we executing breakpoint commands? */
269 static int executing_breakpoint_commands;
271 /* Walk the following statement or block through all breakpoints.
272 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
275 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
277 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
278 for (B = breakpoint_chain; \
279 B ? (TMP=B->next, 1): 0; \
282 /* True if SHIFT_INST_REGS defined, false otherwise. */
284 int must_shift_inst_regs =
285 #if defined(SHIFT_INST_REGS)
292 /* True if breakpoint hit counts should be displayed in breakpoint info. */
294 int show_breakpoint_hit_counts = 1;
296 /* Chain of all breakpoints defined. */
298 struct breakpoint *breakpoint_chain;
300 /* Number of last breakpoint made. */
302 int breakpoint_count;
304 /* Pointer to current exception event record */
305 static struct exception_event_record *current_exception_event;
307 /* Indicator of whether exception catchpoints should be nuked
308 between runs of a program */
309 int exception_catchpoints_are_fragile = 0;
311 /* Indicator of when exception catchpoints set-up should be
312 reinitialized -- e.g. when program is re-run */
313 int exception_support_initialized = 0;
315 /* This function returns a pointer to the string representation of the
316 pathname of the dynamically-linked library that has just been
319 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
320 or undefined results are guaranteed.
322 This string's contents are only valid immediately after the
323 inferior has stopped in the dynamic linker hook, and becomes
324 invalid as soon as the inferior is continued. Clients should make
325 a copy of this string if they wish to continue the inferior and
326 then access the string. */
328 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
329 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
332 /* This function returns a pointer to the string representation of the
333 pathname of the dynamically-linked library that has just been
336 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
337 TRUE, or undefined results are guaranteed.
339 This string's contents are only valid immediately after the
340 inferior has stopped in the dynamic linker hook, and becomes
341 invalid as soon as the inferior is continued. Clients should make
342 a copy of this string if they wish to continue the inferior and
343 then access the string. */
345 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
346 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
349 /* This function is called by the "catch load" command. It allows the
350 debugger to be notified by the dynamic linker when a specified
351 library file (or any library file, if filename is NULL) is loaded. */
353 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
354 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
355 error ("catch of library loads not yet implemented on this platform")
358 /* This function is called by the "catch unload" command. It allows
359 the debugger to be notified by the dynamic linker when a specified
360 library file (or any library file, if filename is NULL) is
363 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
364 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
365 error ("catch of library unloads not yet implemented on this platform")
368 /* Set breakpoint count to NUM. */
371 set_breakpoint_count (num)
374 breakpoint_count = num;
375 set_internalvar (lookup_internalvar ("bpnum"),
376 value_from_longest (builtin_type_int, (LONGEST) num));
379 /* Used in run_command to zero the hit count when a new run starts. */
382 clear_breakpoint_hit_counts ()
384 struct breakpoint *b;
390 /* Default address, symtab and line to put a breakpoint at
391 for "break" command with no arg.
392 if default_breakpoint_valid is zero, the other three are
393 not valid, and "break" with no arg is an error.
395 This set by print_stack_frame, which calls set_default_breakpoint. */
397 int default_breakpoint_valid;
398 CORE_ADDR default_breakpoint_address;
399 struct symtab *default_breakpoint_symtab;
400 int default_breakpoint_line;
402 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
403 Advance *PP after the string and any trailing whitespace.
405 Currently the string can either be a number or "$" followed by the name
406 of a convenience variable. Making it an expression wouldn't work well
407 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
409 TRAILER is a character which can be found after the number; most
410 commonly this is `-'. If you don't want a trailer, use \0. */
412 get_number_trailer (pp, trailer)
416 int retval = 0; /* default */
420 /* Empty line means refer to the last breakpoint. */
421 return breakpoint_count;
424 /* Make a copy of the name, so we can null-terminate it
425 to pass to lookup_internalvar(). */
430 while (isalnum (*p) || *p == '_')
432 varname = (char *) alloca (p - start + 1);
433 strncpy (varname, start, p - start);
434 varname[p - start] = '\0';
435 val = value_of_internalvar (lookup_internalvar (varname));
436 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
437 retval = (int) value_as_long (val);
440 printf_filtered ("Convenience variable must have integer value.\n");
448 while (*p >= '0' && *p <= '9')
451 /* There is no number here. (e.g. "cond a == b"). */
453 /* Skip non-numeric token */
454 while (*p && !isspace((int) *p))
456 /* Return zero, which caller must interpret as error. */
462 if (!(isspace (*p) || *p == '\0' || *p == trailer))
464 /* Trailing junk: return 0 and let caller print error msg. */
465 while (!(isspace (*p) || *p == '\0' || *p == trailer))
476 /* Like get_number_trailer, but don't allow a trailer. */
481 return get_number_trailer (pp, '\0');
484 /* Parse a number or a range.
485 * A number will be of the form handled by get_number.
486 * A range will be of the form <number1> - <number2>, and
487 * will represent all the integers between number1 and number2,
490 * While processing a range, this fuction is called iteratively;
491 * At each call it will return the next value in the range.
493 * At the beginning of parsing a range, the char pointer PP will
494 * be advanced past <number1> and left pointing at the '-' token.
495 * Subsequent calls will not advance the pointer until the range
496 * is completed. The call that completes the range will advance
497 * pointer PP past <number2>.
501 get_number_or_range (pp)
504 static int last_retval, end_value;
505 static char *end_ptr;
506 static int in_range = 0;
510 /* Default case: pp is pointing either to a solo number,
511 or to the first number of a range. */
512 last_retval = get_number_trailer (pp, '-');
517 /* This is the start of a range (<number1> - <number2>).
518 Skip the '-', parse and remember the second number,
519 and also remember the end of the final token. */
523 while (isspace ((int) *end_ptr))
524 end_ptr++; /* skip white space */
525 end_value = get_number (temp);
526 if (end_value < last_retval)
528 error ("inverted range");
530 else if (end_value == last_retval)
532 /* degenerate range (number1 == number2). Advance the
533 token pointer so that the range will be treated as a
542 error ("negative value");
545 /* pp points to the '-' that betokens a range. All
546 number-parsing has already been done. Return the next
547 integer value (one greater than the saved previous value).
548 Do not advance the token pointer 'pp' until the end of range
551 if (++last_retval == end_value)
553 /* End of range reached; advance token pointer. */
563 /* condition N EXP -- set break condition of breakpoint N to EXP. */
566 condition_command (arg, from_tty)
570 register struct breakpoint *b;
575 error_no_arg ("breakpoint number");
578 bnum = get_number (&p);
580 error ("Bad breakpoint argument: '%s'", arg);
583 if (b->number == bnum)
587 free ((PTR) b->cond);
590 if (b->cond_string != NULL)
591 free ((PTR) b->cond_string);
596 b->cond_string = NULL;
598 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
603 /* I don't know if it matters whether this is the string the user
604 typed in or the decompiled expression. */
605 b->cond_string = savestring (arg, strlen (arg));
606 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
608 error ("Junk at end of expression");
610 breakpoints_changed ();
614 error ("No breakpoint number %d.", bnum);
619 commands_command (arg, from_tty)
623 register struct breakpoint *b;
626 struct command_line *l;
628 /* If we allowed this, we would have problems with when to
629 free the storage, if we change the commands currently
632 if (executing_breakpoint_commands)
633 error ("Can't use the \"commands\" command among a breakpoint's commands.");
636 bnum = get_number (&p);
639 error ("Unexpected extra arguments following breakpoint number.");
642 if (b->number == bnum)
646 "Type commands for when breakpoint %d is hit, one per line.",
648 l = read_command_lines (tmpbuf, from_tty);
649 free_command_lines (&b->commands);
651 breakpoints_changed ();
654 error ("No breakpoint number %d.", bnum);
657 /* Like target_read_memory() but if breakpoints are inserted, return
658 the shadow contents instead of the breakpoints themselves.
660 Read "memory data" from whatever target or inferior we have.
661 Returns zero if successful, errno value if not. EIO is used
662 for address out of bounds. If breakpoints are inserted, returns
663 shadow contents, not the breakpoints themselves. From breakpoint.c. */
666 read_memory_nobpt (memaddr, myaddr, len)
672 struct breakpoint *b;
673 CORE_ADDR bp_addr = 0;
676 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
677 /* No breakpoints on this machine. */
678 return target_read_memory (memaddr, myaddr, len);
682 if (b->type == bp_none)
683 warning ("reading through apparently deleted breakpoint #%d?",
686 /* memory breakpoint? */
687 if (b->type == bp_watchpoint
688 || b->type == bp_hardware_watchpoint
689 || b->type == bp_read_watchpoint
690 || b->type == bp_access_watchpoint)
695 /* Addresses and length of the part of the breakpoint that
697 /* XXXX The m68k, sh and h8300 have different local and remote
698 breakpoint values. BREAKPOINT_FROM_PC still manages to
699 correctly determine the breakpoints memory address and size
700 for these targets. */
701 bp_addr = b->address;
703 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
708 if (bp_addr + bp_size <= memaddr)
709 /* The breakpoint is entirely before the chunk of memory we
712 if (bp_addr >= memaddr + len)
713 /* The breakpoint is entirely after the chunk of memory we are
716 /* Copy the breakpoint from the shadow contents, and recurse for
717 the things before and after. */
719 /* Offset within shadow_contents. */
722 if (bp_addr < memaddr)
724 /* Only copy the second part of the breakpoint. */
725 bp_size -= memaddr - bp_addr;
726 bptoffset = memaddr - bp_addr;
730 if (bp_addr + bp_size > memaddr + len)
732 /* Only copy the first part of the breakpoint. */
733 bp_size -= (bp_addr + bp_size) - (memaddr + len);
736 memcpy (myaddr + bp_addr - memaddr,
737 b->shadow_contents + bptoffset, bp_size);
739 if (bp_addr > memaddr)
741 /* Copy the section of memory before the breakpoint. */
742 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
747 if (bp_addr + bp_size < memaddr + len)
749 /* Copy the section of memory after the breakpoint. */
750 status = read_memory_nobpt
752 myaddr + bp_addr + bp_size - memaddr,
753 memaddr + len - (bp_addr + bp_size));
760 /* Nothing overlaps. Just call read_memory_noerr. */
761 return target_read_memory (memaddr, myaddr, len);
765 /* insert_breakpoints is used when starting or continuing the program.
766 remove_breakpoints is used when the program stops.
767 Both return zero if successful,
768 or an `errno' value if could not write the inferior. */
771 insert_breakpoints ()
773 register struct breakpoint *b, *temp;
774 int return_val = 0; /* return success code. */
776 int disabled_breaks = 0;
778 static char message1[] = "Error inserting catchpoint %d:\n";
779 static char message[sizeof (message1) + 30];
782 ALL_BREAKPOINTS_SAFE (b, temp)
784 if (b->enable == permanent)
785 /* Permanent breakpoints cannot be inserted or removed. */
787 else if (b->type != bp_watchpoint
788 && b->type != bp_hardware_watchpoint
789 && b->type != bp_read_watchpoint
790 && b->type != bp_access_watchpoint
791 && b->type != bp_catch_fork
792 && b->type != bp_catch_vfork
793 && b->type != bp_catch_exec
794 && b->type != bp_catch_throw
795 && b->type != bp_catch_catch
796 && b->enable != disabled
797 && b->enable != shlib_disabled
798 && b->enable != call_disabled
802 if (b->type == bp_hardware_breakpoint)
803 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
806 /* Check to see if breakpoint is in an overlay section;
807 if so, we should set the breakpoint at the LMA address.
808 Only if the section is currently mapped should we ALSO
809 set a break at the VMA address. */
810 if (overlay_debugging && b->section &&
811 section_is_overlay (b->section))
815 addr = overlay_unmapped_address (b->address, b->section);
816 val = target_insert_breakpoint (addr, b->shadow_contents);
817 /* This would be the time to check val, to see if the
818 breakpoint write to the load address succeeded.
819 However, this might be an ordinary occurrance, eg. if
820 the unmapped overlay is in ROM. */
821 val = 0; /* in case unmapped address failed */
822 if (section_is_mapped (b->section))
823 val = target_insert_breakpoint (b->address,
826 else /* ordinary (non-overlay) address */
827 val = target_insert_breakpoint (b->address, b->shadow_contents);
831 /* Can't set the breakpoint. */
832 #if defined (DISABLE_UNSETTABLE_BREAK)
833 if (DISABLE_UNSETTABLE_BREAK (b->address))
835 /* See also: disable_breakpoints_in_shlibs. */
837 b->enable = shlib_disabled;
838 if (!disabled_breaks)
840 target_terminal_ours_for_output ();
841 warning ("Cannot insert breakpoint %d:", b->number);
842 warning ("Temporarily disabling shared library breakpoints:");
845 warning ("breakpoint #%d ", b->number);
850 target_terminal_ours_for_output ();
851 warning ("Cannot insert breakpoint %d:", b->number);
852 #ifdef ONE_PROCESS_WRITETEXT
853 warning ("The same program may be running in another process.");
855 memory_error (val, b->address); /* which bombs us out */
862 return_val = val; /* remember failure */
864 else if (ep_is_exception_catchpoint (b)
865 && b->enable != disabled
866 && b->enable != shlib_disabled
867 && b->enable != call_disabled
872 /* If we get here, we must have a callback mechanism for exception
873 events -- with g++ style embedded label support, we insert
874 ordinary breakpoints and not catchpoints. */
875 /* Format possible error message */
876 sprintf (message, message1, b->number);
878 val = target_insert_breakpoint (b->address, b->shadow_contents);
881 /* Couldn't set breakpoint for some reason */
882 target_terminal_ours_for_output ();
883 warning ("Cannot insert catchpoint %d; disabling it.",
885 b->enable = disabled;
889 /* Bp set, now make sure callbacks are enabled */
891 args_for_catchpoint_enable args;
892 args.kind = b->type == bp_catch_catch ?
893 EX_EVENT_CATCH : EX_EVENT_THROW;
895 val = catch_errors (cover_target_enable_exception_callback,
897 message, RETURN_MASK_ALL);
898 if (val != 0 && val != -1)
902 /* Check if something went wrong; val == 0 can be ignored */
905 /* something went wrong */
906 target_terminal_ours_for_output ();
907 warning ("Cannot insert catchpoint %d; disabling it.",
909 b->enable = disabled;
914 return_val = val; /* remember failure */
917 else if ((b->type == bp_hardware_watchpoint ||
918 b->type == bp_read_watchpoint ||
919 b->type == bp_access_watchpoint)
920 && b->enable == enabled
921 && b->disposition != del_at_next_stop
925 struct frame_info *saved_frame;
926 int saved_level, within_current_scope;
927 value_ptr mark = value_mark ();
930 /* Save the current frame and level so we can restore it after
931 evaluating the watchpoint expression on its own frame. */
932 saved_frame = selected_frame;
933 saved_level = selected_frame_level;
935 /* Determine if the watchpoint is within scope. */
936 if (b->exp_valid_block == NULL)
937 within_current_scope = 1;
940 struct frame_info *fi;
942 /* There might be no current frame at this moment if we are
943 resuming from a step over a breakpoint.
944 Set up current frame before trying to find the watchpoint
946 get_current_frame ();
947 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
948 within_current_scope = (fi != NULL);
949 if (within_current_scope)
950 select_frame (fi, -1);
953 if (within_current_scope)
955 /* Evaluate the expression and cut the chain of values
956 produced off from the value chain.
958 Make sure the value returned isn't lazy; we use
959 laziness to determine what memory GDB actually needed
960 in order to compute the value of the expression. */
961 v = evaluate_expression (b->exp);
963 value_release_to_mark (mark);
968 /* Look at each value on the value chain. */
969 for (; v; v = v->next)
971 /* If it's a memory location, and GDB actually needed
972 its contents to evaluate the expression, then we
974 if (VALUE_LVAL (v) == lval_memory
977 struct type *vtype = check_typedef (VALUE_TYPE (v));
979 /* We only watch structs and arrays if user asked
980 for it explicitly, never if they just happen to
981 appear in the middle of some value chain. */
982 if (v == b->val_chain
983 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
984 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
989 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
990 len = TYPE_LENGTH (VALUE_TYPE (v));
992 if (b->type == bp_read_watchpoint)
994 else if (b->type == bp_access_watchpoint)
997 val = target_insert_watchpoint (addr, len, type);
1000 /* Don't exit the loop, try to insert
1001 every value on the value chain. That's
1002 because we will be removing all the
1003 watches below, and removing a
1004 watchpoint we didn't insert could have
1012 /* Failure to insert a watchpoint on any memory value in the
1013 value chain brings us here. */
1016 remove_breakpoint (b, mark_uninserted);
1017 warning ("Could not insert hardware watchpoint %d.",
1024 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
1025 printf_filtered ("because the program has left the block \n");
1026 printf_filtered ("in which its expression is valid.\n");
1027 if (b->related_breakpoint)
1028 b->related_breakpoint->disposition = del_at_next_stop;
1029 b->disposition = del_at_next_stop;
1032 /* Restore the frame and level. */
1033 if ((saved_frame != selected_frame) ||
1034 (saved_level != selected_frame_level))
1035 select_frame (saved_frame, saved_level);
1038 return_val = val; /* remember failure */
1040 else if ((b->type == bp_catch_fork
1041 || b->type == bp_catch_vfork
1042 || b->type == bp_catch_exec)
1043 && b->enable == enabled
1051 val = target_insert_fork_catchpoint (inferior_pid);
1053 case bp_catch_vfork:
1054 val = target_insert_vfork_catchpoint (inferior_pid);
1057 val = target_insert_exec_catchpoint (inferior_pid);
1060 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1065 target_terminal_ours_for_output ();
1066 warning ("Cannot insert catchpoint %d.", b->number);
1072 return_val = val; /* remember failure */
1081 remove_breakpoints ()
1083 register struct breakpoint *b;
1090 val = remove_breakpoint (b, mark_uninserted);
1099 reattach_breakpoints (pid)
1102 register struct breakpoint *b;
1104 int saved_inferior_pid = inferior_pid;
1106 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1107 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1112 remove_breakpoint (b, mark_inserted);
1113 if (b->type == bp_hardware_breakpoint)
1114 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1116 val = target_insert_breakpoint (b->address, b->shadow_contents);
1119 inferior_pid = saved_inferior_pid;
1124 inferior_pid = saved_inferior_pid;
1129 update_breakpoints_after_exec ()
1131 struct breakpoint *b;
1132 struct breakpoint *temp;
1134 /* Doing this first prevents the badness of having delete_breakpoint()
1135 write a breakpoint's current "shadow contents" to lift the bp. That
1136 shadow is NOT valid after an exec()! */
1137 mark_breakpoints_out ();
1139 ALL_BREAKPOINTS_SAFE (b, temp)
1141 /* Solib breakpoints must be explicitly reset after an exec(). */
1142 if (b->type == bp_shlib_event)
1144 delete_breakpoint (b);
1148 /* Thread event breakpoints must be set anew after an exec(). */
1149 if (b->type == bp_thread_event)
1151 delete_breakpoint (b);
1155 /* Step-resume breakpoints are meaningless after an exec(). */
1156 if (b->type == bp_step_resume)
1158 delete_breakpoint (b);
1162 /* Ditto the sigtramp handler breakpoints. */
1163 if (b->type == bp_through_sigtramp)
1165 delete_breakpoint (b);
1169 /* Ditto the exception-handling catchpoints. */
1170 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1172 delete_breakpoint (b);
1176 /* Don't delete an exec catchpoint, because else the inferior
1177 won't stop when it ought!
1179 Similarly, we probably ought to keep vfork catchpoints, 'cause
1180 on this target, we may not be able to stop when the vfork is
1181 seen, but only when the subsequent exec is seen. (And because
1182 deleting fork catchpoints here but not vfork catchpoints will
1183 seem mysterious to users, keep those too.)
1185 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1186 target address field, if any, is sufficient to have it be reset
1187 automagically. Certainly on HP-UX that's true. */
1188 if ((b->type == bp_catch_exec) ||
1189 (b->type == bp_catch_vfork) ||
1190 (b->type == bp_catch_fork))
1192 b->address = (CORE_ADDR) NULL;
1196 /* bp_finish is a special case. The only way we ought to be able
1197 to see one of these when an exec() has happened, is if the user
1198 caught a vfork, and then said "finish". Ordinarily a finish just
1199 carries them to the call-site of the current callee, by setting
1200 a temporary bp there and resuming. But in this case, the finish
1201 will carry them entirely through the vfork & exec.
1203 We don't want to allow a bp_finish to remain inserted now. But
1204 we can't safely delete it, 'cause finish_command has a handle to
1205 the bp on a bpstat, and will later want to delete it. There's a
1206 chance (and I've seen it happen) that if we delete the bp_finish
1207 here, that its storage will get reused by the time finish_command
1208 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1209 We really must allow finish_command to delete a bp_finish.
1211 In the absense of a general solution for the "how do we know
1212 it's safe to delete something others may have handles to?"
1213 problem, what we'll do here is just uninsert the bp_finish, and
1214 let finish_command delete it.
1216 (We know the bp_finish is "doomed" in the sense that it's
1217 momentary, and will be deleted as soon as finish_command sees
1218 the inferior stopped. So it doesn't matter that the bp's
1219 address is probably bogus in the new a.out, unlike e.g., the
1220 solib breakpoints.) */
1222 if (b->type == bp_finish)
1227 /* Without a symbolic address, we have little hope of the
1228 pre-exec() address meaning the same thing in the post-exec()
1230 if (b->addr_string == NULL)
1232 delete_breakpoint (b);
1236 /* If this breakpoint has survived the above battery of checks, then
1237 it must have a symbolic address. Be sure that it gets reevaluated
1238 to a target address, rather than reusing the old evaluation. */
1239 b->address = (CORE_ADDR) NULL;
1244 detach_breakpoints (pid)
1247 register struct breakpoint *b;
1249 int saved_inferior_pid = inferior_pid;
1251 if (pid == inferior_pid)
1252 error ("Cannot detach breakpoints of inferior_pid");
1254 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1255 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1260 val = remove_breakpoint (b, mark_inserted);
1263 inferior_pid = saved_inferior_pid;
1268 inferior_pid = saved_inferior_pid;
1273 remove_breakpoint (b, is)
1274 struct breakpoint *b;
1275 insertion_state_t is;
1279 if (b->enable == permanent)
1280 /* Permanent breakpoints cannot be inserted or removed. */
1283 if (b->type == bp_none)
1284 warning ("attempted to remove apparently deleted breakpoint #%d?",
1287 if (b->type != bp_watchpoint
1288 && b->type != bp_hardware_watchpoint
1289 && b->type != bp_read_watchpoint
1290 && b->type != bp_access_watchpoint
1291 && b->type != bp_catch_fork
1292 && b->type != bp_catch_vfork
1293 && b->type != bp_catch_exec
1294 && b->type != bp_catch_catch
1295 && b->type != bp_catch_throw)
1297 if (b->type == bp_hardware_breakpoint)
1298 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1301 /* Check to see if breakpoint is in an overlay section;
1302 if so, we should remove the breakpoint at the LMA address.
1303 If that is not equal to the raw address, then we should
1304 presumable remove the breakpoint there as well. */
1305 if (overlay_debugging && b->section &&
1306 section_is_overlay (b->section))
1310 addr = overlay_unmapped_address (b->address, b->section);
1311 val = target_remove_breakpoint (addr, b->shadow_contents);
1312 /* This would be the time to check val, to see if the
1313 shadow breakpoint write to the load address succeeded.
1314 However, this might be an ordinary occurrance, eg. if
1315 the unmapped overlay is in ROM. */
1316 val = 0; /* in case unmapped address failed */
1317 if (section_is_mapped (b->section))
1318 val = target_remove_breakpoint (b->address,
1319 b->shadow_contents);
1321 else /* ordinary (non-overlay) address */
1322 val = target_remove_breakpoint (b->address, b->shadow_contents);
1326 b->inserted = (is == mark_inserted);
1328 else if ((b->type == bp_hardware_watchpoint ||
1329 b->type == bp_read_watchpoint ||
1330 b->type == bp_access_watchpoint)
1331 && b->enable == enabled
1336 b->inserted = (is == mark_inserted);
1337 /* Walk down the saved value chain. */
1338 for (v = b->val_chain; v; v = v->next)
1340 /* For each memory reference remove the watchpoint
1342 if (VALUE_LVAL (v) == lval_memory
1343 && ! VALUE_LAZY (v))
1345 struct type *vtype = check_typedef (VALUE_TYPE (v));
1347 if (v == b->val_chain
1348 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1349 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1354 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1355 len = TYPE_LENGTH (VALUE_TYPE (v));
1357 if (b->type == bp_read_watchpoint)
1359 else if (b->type == bp_access_watchpoint)
1362 val = target_remove_watchpoint (addr, len, type);
1369 /* Failure to remove any of the hardware watchpoints comes here. */
1370 if ((is == mark_uninserted) && (b->inserted))
1371 warning ("Could not remove hardware watchpoint %d.",
1374 /* Free the saved value chain. We will construct a new one
1375 the next time the watchpoint is inserted. */
1376 for (v = b->val_chain; v; v = n)
1381 b->val_chain = NULL;
1383 else if ((b->type == bp_catch_fork ||
1384 b->type == bp_catch_vfork ||
1385 b->type == bp_catch_exec)
1386 && b->enable == enabled
1393 val = target_remove_fork_catchpoint (inferior_pid);
1395 case bp_catch_vfork:
1396 val = target_remove_vfork_catchpoint (inferior_pid);
1399 val = target_remove_exec_catchpoint (inferior_pid);
1402 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1407 b->inserted = (is == mark_inserted);
1409 else if ((b->type == bp_catch_catch ||
1410 b->type == bp_catch_throw)
1411 && b->enable == enabled
1415 val = target_remove_breakpoint (b->address, b->shadow_contents);
1418 b->inserted = (is == mark_inserted);
1420 else if (ep_is_exception_catchpoint (b)
1421 && b->inserted /* sometimes previous insert doesn't happen */
1422 && b->enable == enabled
1426 val = target_remove_breakpoint (b->address, b->shadow_contents);
1430 b->inserted = (is == mark_inserted);
1436 /* Clear the "inserted" flag in all breakpoints. */
1439 mark_breakpoints_out ()
1441 register struct breakpoint *b;
1447 /* Clear the "inserted" flag in all breakpoints and delete any
1448 breakpoints which should go away between runs of the program.
1450 Plus other such housekeeping that has to be done for breakpoints
1453 Note: this function gets called at the end of a run (by
1454 generic_mourn_inferior) and when a run begins (by
1455 init_wait_for_inferior). */
1460 breakpoint_init_inferior (context)
1461 enum inf_context context;
1463 register struct breakpoint *b, *temp;
1464 static int warning_needed = 0;
1466 ALL_BREAKPOINTS_SAFE (b, temp)
1473 case bp_watchpoint_scope:
1475 /* If the call dummy breakpoint is at the entry point it will
1476 cause problems when the inferior is rerun, so we better
1479 Also get rid of scope breakpoints. */
1480 delete_breakpoint (b);
1484 case bp_hardware_watchpoint:
1485 case bp_read_watchpoint:
1486 case bp_access_watchpoint:
1488 /* Likewise for watchpoints on local expressions. */
1489 if (b->exp_valid_block != NULL)
1490 delete_breakpoint (b);
1493 /* Likewise for exception catchpoints in dynamic-linked
1494 executables where required */
1495 if (ep_is_exception_catchpoint (b) &&
1496 exception_catchpoints_are_fragile)
1499 delete_breakpoint (b);
1505 if (exception_catchpoints_are_fragile)
1506 exception_support_initialized = 0;
1508 /* Don't issue the warning unless it's really needed... */
1509 if (warning_needed && (context != inf_exited))
1511 warning ("Exception catchpoints from last run were deleted.");
1512 warning ("You must reinsert them explicitly.");
1517 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1518 exists at PC. It returns ordinary_breakpoint_here if it's an
1519 ordinary breakpoint, or permanent_breakpoint_here if it's a
1520 permanent breakpoint.
1521 - When continuing from a location with an ordinary breakpoint, we
1522 actually single step once before calling insert_breakpoints.
1523 - When continuing from a localion with a permanent breakpoint, we
1524 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1525 the target, to advance the PC past the breakpoint. */
1527 enum breakpoint_here
1528 breakpoint_here_p (pc)
1531 register struct breakpoint *b;
1532 int any_breakpoint_here = 0;
1535 if ((b->enable == enabled
1536 || b->enable == permanent)
1537 && b->address == pc) /* bp is enabled and matches pc */
1539 if (overlay_debugging &&
1540 section_is_overlay (b->section) &&
1541 !section_is_mapped (b->section))
1542 continue; /* unmapped overlay -- can't be a match */
1543 else if (b->enable == permanent)
1544 return permanent_breakpoint_here;
1546 any_breakpoint_here = 1;
1549 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1553 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1554 but it only returns true if there is actually a breakpoint inserted
1558 breakpoint_inserted_here_p (pc)
1561 register struct breakpoint *b;
1565 && b->address == pc) /* bp is inserted and matches pc */
1567 if (overlay_debugging &&
1568 section_is_overlay (b->section) &&
1569 !section_is_mapped (b->section))
1570 continue; /* unmapped overlay -- can't be a match */
1578 /* Return nonzero if FRAME is a dummy frame. We can't use
1579 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1580 much time, at least using get_saved_register on the 68k. This
1581 means that for this function to work right a port must use the
1582 bp_call_dummy breakpoint. */
1585 frame_in_dummy (frame)
1586 struct frame_info *frame;
1588 struct breakpoint *b;
1593 if (USE_GENERIC_DUMMY_FRAMES)
1594 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1598 if (b->type == bp_call_dummy
1599 && b->frame == frame->frame
1600 /* We need to check the PC as well as the frame on the sparc,
1601 for signals.exp in the testsuite. */
1604 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1605 && frame->pc <= b->address)
1611 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1612 is valid for process/thread PID. */
1615 breakpoint_thread_match (pc, pid)
1619 struct breakpoint *b;
1622 thread = pid_to_thread_id (pid);
1625 if (b->enable != disabled
1626 && b->enable != shlib_disabled
1627 && b->enable != call_disabled
1629 && (b->thread == -1 || b->thread == thread))
1631 if (overlay_debugging &&
1632 section_is_overlay (b->section) &&
1633 !section_is_mapped (b->section))
1634 continue; /* unmapped overlay -- can't be a match */
1643 /* bpstat stuff. External routines' interfaces are documented
1647 ep_is_catchpoint (ep)
1648 struct breakpoint *ep;
1651 (ep->type == bp_catch_load)
1652 || (ep->type == bp_catch_unload)
1653 || (ep->type == bp_catch_fork)
1654 || (ep->type == bp_catch_vfork)
1655 || (ep->type == bp_catch_exec)
1656 || (ep->type == bp_catch_catch)
1657 || (ep->type == bp_catch_throw)
1660 /* ??rehrauer: Add more kinds here, as are implemented... */
1665 ep_is_shlib_catchpoint (ep)
1666 struct breakpoint *ep;
1669 (ep->type == bp_catch_load)
1670 || (ep->type == bp_catch_unload)
1675 ep_is_exception_catchpoint (ep)
1676 struct breakpoint *ep;
1679 (ep->type == bp_catch_catch)
1680 || (ep->type == bp_catch_throw)
1684 /* Clear a bpstat so that it says we are not at any breakpoint.
1685 Also free any storage that is part of a bpstat. */
1700 if (p->old_val != NULL)
1701 value_free (p->old_val);
1708 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1709 is part of the bpstat is copied as well. */
1717 bpstat retval = NULL;
1722 for (; bs != NULL; bs = bs->next)
1724 tmp = (bpstat) xmalloc (sizeof (*tmp));
1725 memcpy (tmp, bs, sizeof (*tmp));
1727 /* This is the first thing in the chain. */
1737 /* Find the bpstat associated with this breakpoint */
1740 bpstat_find_breakpoint (bsp, breakpoint)
1742 struct breakpoint *breakpoint;
1747 for (; bsp != NULL; bsp = bsp->next)
1749 if (bsp->breakpoint_at == breakpoint)
1755 /* Find a step_resume breakpoint associated with this bpstat.
1756 (If there are multiple step_resume bp's on the list, this function
1757 will arbitrarily pick one.)
1759 It is an error to use this function if BPSTAT doesn't contain a
1760 step_resume breakpoint.
1762 See wait_for_inferior's use of this function. */
1764 bpstat_find_step_resume_breakpoint (bsp)
1768 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1770 for (; bsp != NULL; bsp = bsp->next)
1772 if ((bsp->breakpoint_at != NULL) &&
1773 (bsp->breakpoint_at->type == bp_step_resume))
1774 return bsp->breakpoint_at;
1777 error ("Internal error (no step_resume breakpoint found)");
1781 /* Return the breakpoint number of the first breakpoint we are stopped
1782 at. *BSP upon return is a bpstat which points to the remaining
1783 breakpoints stopped at (but which is not guaranteed to be good for
1784 anything but further calls to bpstat_num).
1785 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1791 struct breakpoint *b;
1794 return 0; /* No more breakpoint values */
1797 b = (*bsp)->breakpoint_at;
1798 *bsp = (*bsp)->next;
1800 return -1; /* breakpoint that's been deleted since */
1802 return b->number; /* We have its number */
1806 /* Modify BS so that the actions will not be performed. */
1809 bpstat_clear_actions (bs)
1812 for (; bs != NULL; bs = bs->next)
1814 bs->commands = NULL;
1815 if (bs->old_val != NULL)
1817 value_free (bs->old_val);
1823 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1826 cleanup_executing_breakpoints (ignore)
1829 executing_breakpoint_commands = 0;
1832 /* Execute all the commands associated with all the breakpoints at this
1833 location. Any of these commands could cause the process to proceed
1834 beyond this point, etc. We look out for such changes by checking
1835 the global "breakpoint_proceeded" after each command. */
1838 bpstat_do_actions (bsp)
1842 struct cleanup *old_chain;
1843 struct command_line *cmd;
1845 /* Avoid endless recursion if a `source' command is contained
1847 if (executing_breakpoint_commands)
1850 executing_breakpoint_commands = 1;
1851 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1854 /* Note that (as of this writing), our callers all appear to
1855 be passing us the address of global stop_bpstat. And, if
1856 our calls to execute_control_command cause the inferior to
1857 proceed, that global (and hence, *bsp) will change.
1859 We must be careful to not touch *bsp unless the inferior
1860 has not proceeded. */
1862 /* This pointer will iterate over the list of bpstat's. */
1865 breakpoint_proceeded = 0;
1866 for (; bs != NULL; bs = bs->next)
1871 execute_control_command (cmd);
1873 if (breakpoint_proceeded)
1878 if (breakpoint_proceeded)
1879 /* The inferior is proceeded by the command; bomb out now.
1880 The bpstat chain has been blown away by wait_for_inferior.
1881 But since execution has stopped again, there is a new bpstat
1882 to look at, so start over. */
1885 bs->commands = NULL;
1888 executing_breakpoint_commands = 0;
1889 discard_cleanups (old_chain);
1892 /* This is the normal print function for a bpstat. In the future,
1893 much of this logic could (should?) be moved to bpstat_stop_status,
1894 by having it set different print_it values.
1896 Current scheme: When we stop, bpstat_print() is called. It loops
1897 through the bpstat list of things causing this stop, calling the
1898 print_bp_stop_message function on each one. The behavior of the
1899 print_bp_stop_message function depends on the print_it field of
1900 bpstat. If such field so indicates, call this function here.
1902 Return values from this routine (ultimately used by bpstat_print()
1903 and normal_stop() to decide what to do):
1904 PRINT_NOTHING: Means we already printed all we needed to print,
1905 don't print anything else.
1906 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1907 that something to be followed by a location.
1908 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1909 that something to be followed by a location.
1910 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1913 static enum print_stop_action
1914 print_it_typical (bs)
1918 struct cleanup *old_chain;
1919 struct ui_stream *stb;
1920 stb = ui_out_stream_new (uiout);
1921 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
1923 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1924 which has since been deleted. */
1925 if (bs->breakpoint_at == NULL)
1926 return PRINT_UNKNOWN;
1928 switch (bs->breakpoint_at->type)
1931 case bp_hardware_breakpoint:
1933 annotate_breakpoint (bs->breakpoint_at->number);
1934 ui_out_text (uiout, "\nBreakpoint ");
1935 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
1936 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1937 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1938 ui_out_text (uiout, ", ");
1939 return PRINT_SRC_AND_LOC;
1941 /* I think the user probably only wants to see one breakpoint
1942 number, not all of them. */
1943 annotate_breakpoint (bs->breakpoint_at->number);
1944 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1945 return PRINT_SRC_AND_LOC;
1949 case bp_shlib_event:
1950 /* Did we stop because the user set the stop_on_solib_events
1951 variable? (If so, we report this as a generic, "Stopped due
1952 to shlib event" message.) */
1953 printf_filtered ("Stopped due to shared library event\n");
1954 return PRINT_NOTHING;
1957 case bp_thread_event:
1958 /* Not sure how we will get here.
1959 GDB should not stop for these breakpoints. */
1960 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1961 return PRINT_NOTHING;
1965 annotate_catchpoint (bs->breakpoint_at->number);
1966 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1967 printf_filtered ("loaded");
1968 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1969 return PRINT_SRC_AND_LOC;
1972 case bp_catch_unload:
1973 annotate_catchpoint (bs->breakpoint_at->number);
1974 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1975 printf_filtered ("unloaded");
1976 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1977 return PRINT_SRC_AND_LOC;
1981 annotate_catchpoint (bs->breakpoint_at->number);
1982 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1983 printf_filtered ("forked");
1984 printf_filtered (" process %d), ",
1985 bs->breakpoint_at->forked_inferior_pid);
1986 return PRINT_SRC_AND_LOC;
1989 case bp_catch_vfork:
1990 annotate_catchpoint (bs->breakpoint_at->number);
1991 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1992 printf_filtered ("vforked");
1993 printf_filtered (" process %d), ",
1994 bs->breakpoint_at->forked_inferior_pid);
1995 return PRINT_SRC_AND_LOC;
1999 annotate_catchpoint (bs->breakpoint_at->number);
2000 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2001 bs->breakpoint_at->number,
2002 bs->breakpoint_at->exec_pathname);
2003 return PRINT_SRC_AND_LOC;
2006 case bp_catch_catch:
2007 if (current_exception_event &&
2008 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2010 annotate_catchpoint (bs->breakpoint_at->number);
2011 printf_filtered ("\nCatchpoint %d (exception caught), ",
2012 bs->breakpoint_at->number);
2013 printf_filtered ("throw location ");
2014 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2015 printf_filtered ("%s:%d",
2016 CURRENT_EXCEPTION_THROW_FILE,
2017 CURRENT_EXCEPTION_THROW_LINE);
2019 printf_filtered ("unknown");
2021 printf_filtered (", catch location ");
2022 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2023 printf_filtered ("%s:%d",
2024 CURRENT_EXCEPTION_CATCH_FILE,
2025 CURRENT_EXCEPTION_CATCH_LINE);
2027 printf_filtered ("unknown");
2029 printf_filtered ("\n");
2030 /* don't bother to print location frame info */
2031 return PRINT_SRC_ONLY;
2035 /* really throw, some other bpstat will handle it */
2036 return PRINT_UNKNOWN;
2040 case bp_catch_throw:
2041 if (current_exception_event &&
2042 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2044 annotate_catchpoint (bs->breakpoint_at->number);
2045 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2046 bs->breakpoint_at->number);
2047 printf_filtered ("throw location ");
2048 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2049 printf_filtered ("%s:%d",
2050 CURRENT_EXCEPTION_THROW_FILE,
2051 CURRENT_EXCEPTION_THROW_LINE);
2053 printf_filtered ("unknown");
2055 printf_filtered (", catch location ");
2056 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2057 printf_filtered ("%s:%d",
2058 CURRENT_EXCEPTION_CATCH_FILE,
2059 CURRENT_EXCEPTION_CATCH_LINE);
2061 printf_filtered ("unknown");
2063 printf_filtered ("\n");
2064 /* don't bother to print location frame info */
2065 return PRINT_SRC_ONLY;
2069 /* really catch, some other bpstat will handle it */
2070 return PRINT_UNKNOWN;
2075 case bp_hardware_watchpoint:
2076 if (bs->old_val != NULL)
2078 annotate_watchpoint (bs->breakpoint_at->number);
2080 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2081 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2082 mention (bs->breakpoint_at);
2083 ui_out_list_begin (uiout, "value");
2084 ui_out_text (uiout, "\nOld value = ");
2085 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2086 ui_out_field_stream (uiout, "old", stb);
2087 ui_out_text (uiout, "\nNew value = ");
2088 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2089 ui_out_field_stream (uiout, "new", stb);
2090 ui_out_list_end (uiout);
2091 ui_out_text (uiout, "\n");
2093 mention (bs->breakpoint_at);
2094 printf_filtered ("\nOld value = ");
2095 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2096 printf_filtered ("\nNew value = ");
2097 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2098 Val_pretty_default);
2099 printf_filtered ("\n");
2101 value_free (bs->old_val);
2104 /* More than one watchpoint may have been triggered. */
2105 return PRINT_UNKNOWN;
2108 case bp_read_watchpoint:
2110 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2111 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2112 mention (bs->breakpoint_at);
2113 ui_out_list_begin (uiout, "value");
2114 ui_out_text (uiout, "\nValue = ");
2115 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2116 ui_out_field_stream (uiout, "value", stb);
2117 ui_out_list_end (uiout);
2118 ui_out_text (uiout, "\n");
2120 mention (bs->breakpoint_at);
2121 printf_filtered ("\nValue = ");
2122 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2123 Val_pretty_default);
2124 printf_filtered ("\n");
2126 return PRINT_UNKNOWN;
2129 case bp_access_watchpoint:
2131 if (bs->old_val != NULL)
2133 annotate_watchpoint (bs->breakpoint_at->number);
2134 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2135 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2136 mention (bs->breakpoint_at);
2137 ui_out_list_begin (uiout, "value");
2138 ui_out_text (uiout, "\nOld value = ");
2139 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2140 ui_out_field_stream (uiout, "old", stb);
2141 value_free (bs->old_val);
2143 ui_out_text (uiout, "\nNew value = ");
2147 mention (bs->breakpoint_at);
2148 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2149 ui_out_list_begin (uiout, "value");
2150 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2151 ui_out_text (uiout, "\nValue = ");
2153 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2154 ui_out_field_stream (uiout, "new", stb);
2155 ui_out_list_end (uiout);
2156 ui_out_text (uiout, "\n");
2158 if (bs->old_val != NULL)
2160 annotate_watchpoint (bs->breakpoint_at->number);
2161 mention (bs->breakpoint_at);
2162 printf_filtered ("\nOld value = ");
2163 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2164 value_free (bs->old_val);
2166 printf_filtered ("\nNew value = ");
2170 mention (bs->breakpoint_at);
2171 printf_filtered ("\nValue = ");
2173 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2174 Val_pretty_default);
2175 printf_filtered ("\n");
2177 return PRINT_UNKNOWN;
2180 /* Fall through, we don't deal with these types of breakpoints
2185 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2186 ui_out_field_string (uiout, "reason", "function-finished");
2188 return PRINT_UNKNOWN;
2193 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2194 ui_out_field_string (uiout, "reason", "location-reached");
2196 return PRINT_UNKNOWN;
2201 case bp_longjmp_resume:
2202 case bp_step_resume:
2203 case bp_through_sigtramp:
2204 case bp_watchpoint_scope:
2207 return PRINT_UNKNOWN;
2211 /* Generic routine for printing messages indicating why we
2212 stopped. The behavior of this function depends on the value
2213 'print_it' in the bpstat structure. Under some circumstances we
2214 may decide not to print anything here and delegate the task to
2217 static enum print_stop_action
2218 print_bp_stop_message (bpstat bs)
2220 switch (bs->print_it)
2223 /* Nothing should be printed for this bpstat entry. */
2224 return PRINT_UNKNOWN;
2228 /* We still want to print the frame, but we already printed the
2229 relevant messages. */
2230 return PRINT_SRC_AND_LOC;
2233 case print_it_normal:
2234 /* Normal case, we handle everything in print_it_typical. */
2235 return print_it_typical (bs);
2238 internal_error ("print_bp_stop_message: unrecognized enum value");
2243 /* Print a message indicating what happened. This is called from
2244 normal_stop(). The input to this routine is the head of the bpstat
2245 list - a list of the eventpoints that caused this stop. This
2246 routine calls the generic print routine for printing a message
2247 about reasons for stopping. This will print (for example) the
2248 "Breakpoint n," part of the output. The return value of this
2251 PRINT_UNKNOWN: Means we printed nothing
2252 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2253 code to print the location. An example is
2254 "Breakpoint 1, " which should be followed by
2256 PRINT_SRC_ONLY: Means we printed something, but there is no need
2257 to also print the location part of the message.
2258 An example is the catch/throw messages, which
2259 don't require a location appended to the end.
2260 PRINT_NOTHING: We have done some printing and we don't need any
2261 further info to be printed.*/
2263 enum print_stop_action
2269 /* Maybe another breakpoint in the chain caused us to stop.
2270 (Currently all watchpoints go on the bpstat whether hit or not.
2271 That probably could (should) be changed, provided care is taken
2272 with respect to bpstat_explains_signal). */
2273 for (; bs; bs = bs->next)
2275 val = print_bp_stop_message (bs);
2276 if (val == PRINT_SRC_ONLY
2277 || val == PRINT_SRC_AND_LOC
2278 || val == PRINT_NOTHING)
2282 /* We reached the end of the chain, or we got a null BS to start
2283 with and nothing was printed. */
2284 return PRINT_UNKNOWN;
2287 /* Evaluate the expression EXP and return 1 if value is zero.
2288 This is used inside a catch_errors to evaluate the breakpoint condition.
2289 The argument is a "struct expression *" that has been cast to char * to
2290 make it pass through catch_errors. */
2293 breakpoint_cond_eval (exp)
2296 value_ptr mark = value_mark ();
2297 int i = !value_true (evaluate_expression ((struct expression *) exp));
2298 value_free_to_mark (mark);
2302 /* Allocate a new bpstat and chain it to the current one. */
2305 bpstat_alloc (b, cbs)
2306 register struct breakpoint *b;
2307 bpstat cbs; /* Current "bs" value */
2311 bs = (bpstat) xmalloc (sizeof (*bs));
2313 bs->breakpoint_at = b;
2314 /* If the condition is false, etc., don't do the commands. */
2315 bs->commands = NULL;
2317 bs->print_it = print_it_normal;
2321 /* Possible return values for watchpoint_check (this can't be an enum
2322 because of check_errors). */
2323 /* The watchpoint has been deleted. */
2324 #define WP_DELETED 1
2325 /* The value has changed. */
2326 #define WP_VALUE_CHANGED 2
2327 /* The value has not changed. */
2328 #define WP_VALUE_NOT_CHANGED 3
2330 #define BP_TEMPFLAG 1
2331 #define BP_HARDWAREFLAG 2
2333 /* Check watchpoint condition. */
2336 watchpoint_check (p)
2339 bpstat bs = (bpstat) p;
2340 struct breakpoint *b;
2341 struct frame_info *fr;
2342 int within_current_scope;
2344 b = bs->breakpoint_at;
2346 if (b->exp_valid_block == NULL)
2347 within_current_scope = 1;
2350 /* There is no current frame at this moment. If we're going to have
2351 any chance of handling watchpoints on local variables, we'll need
2352 the frame chain (so we can determine if we're in scope). */
2353 reinit_frame_cache ();
2354 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2355 within_current_scope = (fr != NULL);
2356 if (within_current_scope)
2357 /* If we end up stopping, the current frame will get selected
2358 in normal_stop. So this call to select_frame won't affect
2360 select_frame (fr, -1);
2363 if (within_current_scope)
2365 /* We use value_{,free_to_}mark because it could be a
2366 *long* time before we return to the command level and
2367 call free_all_values. We can't call free_all_values because
2368 we might be in the middle of evaluating a function call. */
2370 value_ptr mark = value_mark ();
2371 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2372 if (!value_equal (b->val, new_val))
2374 release_value (new_val);
2375 value_free_to_mark (mark);
2376 bs->old_val = b->val;
2378 /* We will stop here */
2379 return WP_VALUE_CHANGED;
2383 /* Nothing changed, don't do anything. */
2384 value_free_to_mark (mark);
2385 /* We won't stop here */
2386 return WP_VALUE_NOT_CHANGED;
2391 /* This seems like the only logical thing to do because
2392 if we temporarily ignored the watchpoint, then when
2393 we reenter the block in which it is valid it contains
2394 garbage (in the case of a function, it may have two
2395 garbage values, one before and one after the prologue).
2396 So we can't even detect the first assignment to it and
2397 watch after that (since the garbage may or may not equal
2398 the first value assigned). */
2399 /* We print all the stop information in print_it_typical(), but
2400 in this case, by the time we call print_it_typical() this bp
2401 will be deleted already. So we have no choice but print the
2402 information here. */
2404 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2405 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2406 ui_out_text (uiout, "\nWatchpoint ");
2407 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2408 ui_out_text (uiout, " deleted because the program has left the block in\n\
2409 which its expression is valid.\n");
2412 Watchpoint %d deleted because the program has left the block in\n\
2413 which its expression is valid.\n", bs->breakpoint_at->number);
2416 if (b->related_breakpoint)
2417 b->related_breakpoint->disposition = del_at_next_stop;
2418 b->disposition = del_at_next_stop;
2424 /* Get a bpstat associated with having just stopped at address *PC
2425 and frame address CORE_ADDRESS. Update *PC to point at the
2426 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2427 if this is known to not be a real breakpoint (it could still be a
2428 watchpoint, though). */
2430 /* Determine whether we stopped at a breakpoint, etc, or whether we
2431 don't understand this stop. Result is a chain of bpstat's such that:
2433 if we don't understand the stop, the result is a null pointer.
2435 if we understand why we stopped, the result is not null.
2437 Each element of the chain refers to a particular breakpoint or
2438 watchpoint at which we have stopped. (We may have stopped for
2439 several reasons concurrently.)
2441 Each element of the chain has valid next, breakpoint_at,
2442 commands, FIXME??? fields. */
2445 bpstat_stop_status (pc, not_a_breakpoint)
2447 int not_a_breakpoint;
2449 register struct breakpoint *b, *temp;
2451 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2452 int real_breakpoint = 0;
2453 /* Root of the chain of bpstat's */
2454 struct bpstats root_bs[1];
2455 /* Pointer to the last thing in the chain currently. */
2456 bpstat bs = root_bs;
2457 static char message1[] =
2458 "Error evaluating expression for watchpoint %d\n";
2459 char message[sizeof (message1) + 30 /* slop */ ];
2461 /* Get the address where the breakpoint would have been. */
2462 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ?
2463 0 : DECR_PC_AFTER_BREAK);
2465 ALL_BREAKPOINTS_SAFE (b, temp)
2467 if (b->enable == disabled
2468 || b->enable == shlib_disabled
2469 || b->enable == call_disabled)
2472 if (b->type != bp_watchpoint
2473 && b->type != bp_hardware_watchpoint
2474 && b->type != bp_read_watchpoint
2475 && b->type != bp_access_watchpoint
2476 && b->type != bp_hardware_breakpoint
2477 && b->type != bp_catch_fork
2478 && b->type != bp_catch_vfork
2479 && b->type != bp_catch_exec
2480 && b->type != bp_catch_catch
2481 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2482 if (b->address != bp_addr || /* address doesn't match or */
2483 (overlay_debugging && /* overlay doesn't match */
2484 section_is_overlay (b->section) &&
2485 !section_is_mapped (b->section)))
2488 if (b->type == bp_hardware_breakpoint
2489 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2492 /* Is this a catchpoint of a load or unload? If so, did we
2493 get a load or unload of the specified library? If not,
2495 if ((b->type == bp_catch_load)
2496 #if defined(SOLIB_HAVE_LOAD_EVENT)
2497 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2498 || ((b->dll_pathname != NULL)
2499 && (strcmp (b->dll_pathname,
2500 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2506 if ((b->type == bp_catch_unload)
2507 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2508 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2509 || ((b->dll_pathname != NULL)
2510 && (strcmp (b->dll_pathname,
2511 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2517 if ((b->type == bp_catch_fork)
2518 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2521 if ((b->type == bp_catch_vfork)
2522 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2525 if ((b->type == bp_catch_exec)
2526 && !target_has_execd (inferior_pid, &b->exec_pathname))
2529 if (ep_is_exception_catchpoint (b) &&
2530 !(current_exception_event = target_get_current_exception_event ()))
2533 /* Come here if it's a watchpoint, or if the break address matches */
2535 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2537 /* Watchpoints may change this, if not found to have triggered. */
2541 sprintf (message, message1, b->number);
2542 if (b->type == bp_watchpoint ||
2543 b->type == bp_hardware_watchpoint)
2545 switch (catch_errors (watchpoint_check, bs, message,
2549 /* We've already printed what needs to be printed. */
2550 /* Actually this is superfluous, because by the time we
2551 call print_it_typical() the wp will be already deleted,
2552 and the function will return immediately. */
2553 bs->print_it = print_it_done;
2556 case WP_VALUE_CHANGED:
2560 case WP_VALUE_NOT_CHANGED:
2562 bs->print_it = print_it_noop;
2569 /* Error from catch_errors. */
2570 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2571 if (b->related_breakpoint)
2572 b->related_breakpoint->disposition = del_at_next_stop;
2573 b->disposition = del_at_next_stop;
2574 /* We've already printed what needs to be printed. */
2575 bs->print_it = print_it_done;
2581 else if (b->type == bp_read_watchpoint ||
2582 b->type == bp_access_watchpoint)
2588 addr = target_stopped_data_address ();
2591 for (v = b->val_chain; v; v = v->next)
2593 if (VALUE_LVAL (v) == lval_memory
2594 && ! VALUE_LAZY (v))
2596 struct type *vtype = check_typedef (VALUE_TYPE (v));
2598 if (v == b->val_chain
2599 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2600 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2604 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2605 /* Exact match not required. Within range is
2607 if (addr >= vaddr &&
2608 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2614 switch (catch_errors (watchpoint_check, bs, message,
2618 /* We've already printed what needs to be printed. */
2619 bs->print_it = print_it_done;
2622 case WP_VALUE_CHANGED:
2623 if (b->type == bp_read_watchpoint)
2625 /* Don't stop: read watchpoints shouldn't fire if
2626 the value has changed. This is for targets which
2627 cannot set read-only watchpoints. */
2628 bs->print_it = print_it_noop;
2634 case WP_VALUE_NOT_CHANGED:
2641 /* Error from catch_errors. */
2642 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2643 if (b->related_breakpoint)
2644 b->related_breakpoint->disposition = del_at_next_stop;
2645 b->disposition = del_at_next_stop;
2646 /* We've already printed what needs to be printed. */
2647 bs->print_it = print_it_done;
2650 else /* found == 0 */
2652 /* This is a case where some watchpoint(s) triggered,
2653 but not at the address of this watchpoint (FOUND
2654 was left zero). So don't print anything for this
2656 bs->print_it = print_it_noop;
2663 /* By definition, an encountered breakpoint is a triggered
2667 real_breakpoint = 1;
2671 b->frame != (get_current_frame ())->frame)
2675 int value_is_zero = 0;
2679 /* Need to select the frame, with all that implies
2680 so that the conditions will have the right context. */
2681 select_frame (get_current_frame (), 0);
2683 = catch_errors (breakpoint_cond_eval, (b->cond),
2684 "Error in testing breakpoint condition:\n",
2686 /* FIXME-someday, should give breakpoint # */
2689 if (b->cond && value_is_zero)
2692 /* Don't consider this a hit. */
2695 else if (b->ignore_count > 0)
2698 annotate_ignore_count_change ();
2703 /* We will stop here */
2704 if (b->disposition == disable)
2705 b->enable = disabled;
2706 bs->commands = b->commands;
2710 (STREQ ("silent", bs->commands->line) ||
2711 (xdb_commands && STREQ ("Q", bs->commands->line))))
2713 bs->commands = bs->commands->next;
2718 /* Print nothing for this entry if we dont stop or if we dont print. */
2719 if (bs->stop == 0 || bs->print == 0)
2720 bs->print_it = print_it_noop;
2723 bs->next = NULL; /* Terminate the chain */
2724 bs = root_bs->next; /* Re-grab the head of the chain */
2726 if (real_breakpoint && bs)
2728 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2730 if (DECR_PC_AFTER_HW_BREAK != 0)
2732 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2738 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2741 #if defined (SHIFT_INST_REGS)
2743 #else /* No SHIFT_INST_REGS. */
2745 #endif /* No SHIFT_INST_REGS. */
2750 /* The value of a hardware watchpoint hasn't changed, but the
2751 intermediate memory locations we are watching may have. */
2752 if (bs && !bs->stop &&
2753 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2754 bs->breakpoint_at->type == bp_read_watchpoint ||
2755 bs->breakpoint_at->type == bp_access_watchpoint))
2757 remove_breakpoints ();
2758 insert_breakpoints ();
2763 /* Tell what to do about this bpstat. */
2768 /* Classify each bpstat as one of the following. */
2771 /* This bpstat element has no effect on the main_action. */
2774 /* There was a watchpoint, stop but don't print. */
2777 /* There was a watchpoint, stop and print. */
2780 /* There was a breakpoint but we're not stopping. */
2783 /* There was a breakpoint, stop but don't print. */
2786 /* There was a breakpoint, stop and print. */
2789 /* We hit the longjmp breakpoint. */
2792 /* We hit the longjmp_resume breakpoint. */
2795 /* We hit the step_resume breakpoint. */
2798 /* We hit the through_sigtramp breakpoint. */
2801 /* We hit the shared library event breakpoint. */
2804 /* We caught a shared library event. */
2807 /* This is just used to count how many enums there are. */
2811 /* Here is the table which drives this routine. So that we can
2812 format it pretty, we define some abbreviations for the
2813 enum bpstat_what codes. */
2814 #define kc BPSTAT_WHAT_KEEP_CHECKING
2815 #define ss BPSTAT_WHAT_STOP_SILENT
2816 #define sn BPSTAT_WHAT_STOP_NOISY
2817 #define sgl BPSTAT_WHAT_SINGLE
2818 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2819 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2820 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2821 #define sr BPSTAT_WHAT_STEP_RESUME
2822 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2823 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2824 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2826 /* "Can't happen." Might want to print an error message.
2827 abort() is not out of the question, but chances are GDB is just
2828 a bit confused, not unusable. */
2829 #define err BPSTAT_WHAT_STOP_NOISY
2831 /* Given an old action and a class, come up with a new action. */
2832 /* One interesting property of this table is that wp_silent is the same
2833 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2834 after stopping, the check for whether to step over a breakpoint
2835 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2836 reference to how we stopped. We retain separate wp_silent and
2837 bp_silent codes in case we want to change that someday.
2839 Another possibly interesting property of this table is that
2840 there's a partial ordering, priority-like, of the actions. Once
2841 you've decided that some action is appropriate, you'll never go
2842 back and decide something of a lower priority is better. The
2845 kc < clr sgl shl slr sn sr ss ts
2846 sgl < clrs shl shlr slr sn sr ss ts
2847 slr < err shl shlr sn sr ss ts
2848 clr < clrs err shl shlr sn sr ss ts
2849 clrs < err shl shlr sn sr ss ts
2850 ss < shl shlr sn sr ts
2857 What I think this means is that we don't need a damned table
2858 here. If you just put the rows and columns in the right order,
2859 it'd look awfully regular. We could simply walk the bpstat list
2860 and choose the highest priority action we find, with a little
2861 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2862 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2863 is messy anyway). */
2865 /* step_resume entries: a step resume breakpoint overrides another
2866 breakpoint of signal handling (see comment in wait_for_inferior
2867 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2868 /* We handle the through_sigtramp_breakpoint the same way; having both
2869 one of those and a step_resume_breakpoint is probably very rare (?). */
2871 static const enum bpstat_what_main_action
2872 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2875 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2878 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2880 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2882 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2884 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2886 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2888 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2890 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2892 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2894 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2896 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2898 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2900 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2915 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2916 struct bpstat_what retval;
2918 retval.call_dummy = 0;
2919 for (; bs != NULL; bs = bs->next)
2921 enum class bs_class = no_effect;
2922 if (bs->breakpoint_at == NULL)
2923 /* I suspect this can happen if it was a momentary breakpoint
2924 which has since been deleted. */
2926 switch (bs->breakpoint_at->type)
2932 case bp_hardware_breakpoint:
2938 bs_class = bp_noisy;
2940 bs_class = bp_silent;
2943 bs_class = bp_nostop;
2946 case bp_hardware_watchpoint:
2947 case bp_read_watchpoint:
2948 case bp_access_watchpoint:
2952 bs_class = wp_noisy;
2954 bs_class = wp_silent;
2957 /* There was a watchpoint, but we're not stopping.
2958 This requires no further action. */
2959 bs_class = no_effect;
2962 bs_class = long_jump;
2964 case bp_longjmp_resume:
2965 bs_class = long_resume;
2967 case bp_step_resume:
2970 bs_class = step_resume;
2973 /* It is for the wrong frame. */
2974 bs_class = bp_nostop;
2976 case bp_through_sigtramp:
2977 bs_class = through_sig;
2979 case bp_watchpoint_scope:
2980 bs_class = bp_nostop;
2982 case bp_shlib_event:
2983 bs_class = shlib_event;
2985 case bp_thread_event:
2986 bs_class = bp_nostop;
2989 case bp_catch_unload:
2990 /* Only if this catchpoint triggered should we cause the
2991 step-out-of-dld behaviour. Otherwise, we ignore this
2994 bs_class = catch_shlib_event;
2996 bs_class = no_effect;
2999 case bp_catch_vfork:
3004 bs_class = bp_noisy;
3006 bs_class = bp_silent;
3009 /* There was a catchpoint, but we're not stopping.
3010 This requires no further action. */
3011 bs_class = no_effect;
3013 case bp_catch_catch:
3014 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3015 bs_class = bp_nostop;
3017 bs_class = bs->print ? bp_noisy : bp_silent;
3019 case bp_catch_throw:
3020 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3021 bs_class = bp_nostop;
3023 bs_class = bs->print ? bp_noisy : bp_silent;
3026 /* Make sure the action is stop (silent or noisy),
3027 so infrun.c pops the dummy frame. */
3028 bs_class = bp_silent;
3029 retval.call_dummy = 1;
3032 current_action = table[(int) bs_class][(int) current_action];
3034 retval.main_action = current_action;
3038 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3039 without hardware support). This isn't related to a specific bpstat,
3040 just to things like whether watchpoints are set. */
3043 bpstat_should_step ()
3045 struct breakpoint *b;
3047 if (b->enable == enabled && b->type == bp_watchpoint)
3052 /* Nonzero if there are enabled hardware watchpoints. */
3054 bpstat_have_active_hw_watchpoints ()
3056 struct breakpoint *b;
3058 if ((b->enable == enabled) &&
3060 ((b->type == bp_hardware_watchpoint) ||
3061 (b->type == bp_read_watchpoint) ||
3062 (b->type == bp_access_watchpoint)))
3068 /* Given a bpstat that records zero or more triggered eventpoints, this
3069 function returns another bpstat which contains only the catchpoints
3070 on that first list, if any. */
3072 bpstat_get_triggered_catchpoints (ep_list, cp_list)
3076 struct bpstats root_bs[1];
3077 bpstat bs = root_bs;
3078 struct breakpoint *ep;
3081 bpstat_clear (cp_list);
3082 root_bs->next = NULL;
3084 for (; ep_list != NULL; ep_list = ep_list->next)
3086 /* Is this eventpoint a catchpoint? If not, ignore it. */
3087 ep = ep_list->breakpoint_at;
3090 if ((ep->type != bp_catch_load) &&
3091 (ep->type != bp_catch_unload) &&
3092 (ep->type != bp_catch_catch) &&
3093 (ep->type != bp_catch_throw))
3094 /* pai: (temp) ADD fork/vfork here!! */
3097 /* Yes; add it to the list. */
3098 bs = bpstat_alloc (ep, bs);
3103 #if defined(SOLIB_ADD)
3104 /* Also, for each triggered catchpoint, tag it with the name of
3105 the library that caused this trigger. (We copy the name now,
3106 because it's only guaranteed to be available NOW, when the
3107 catchpoint triggers. Clients who may wish to know the name
3108 later must get it from the catchpoint itself.) */
3109 if (ep->triggered_dll_pathname != NULL)
3110 free (ep->triggered_dll_pathname);
3111 if (ep->type == bp_catch_load)
3112 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
3114 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
3116 dll_pathname = NULL;
3120 ep->triggered_dll_pathname = (char *)
3121 xmalloc (strlen (dll_pathname) + 1);
3122 strcpy (ep->triggered_dll_pathname, dll_pathname);
3125 ep->triggered_dll_pathname = NULL;
3131 /* Print B to gdb_stdout. */
3133 print_one_breakpoint (struct breakpoint *b,
3134 CORE_ADDR *last_addr)
3136 register struct command_line *l;
3137 register struct symbol *sym;
3138 struct ep_type_description
3143 static struct ep_type_description bptypes[] =
3145 {bp_none, "?deleted?"},
3146 {bp_breakpoint, "breakpoint"},
3147 {bp_hardware_breakpoint, "hw breakpoint"},
3148 {bp_until, "until"},
3149 {bp_finish, "finish"},
3150 {bp_watchpoint, "watchpoint"},
3151 {bp_hardware_watchpoint, "hw watchpoint"},
3152 {bp_read_watchpoint, "read watchpoint"},
3153 {bp_access_watchpoint, "acc watchpoint"},
3154 {bp_longjmp, "longjmp"},
3155 {bp_longjmp_resume, "longjmp resume"},
3156 {bp_step_resume, "step resume"},
3157 {bp_through_sigtramp, "sigtramp"},
3158 {bp_watchpoint_scope, "watchpoint scope"},
3159 {bp_call_dummy, "call dummy"},
3160 {bp_shlib_event, "shlib events"},
3161 {bp_thread_event, "thread events"},
3162 {bp_catch_load, "catch load"},
3163 {bp_catch_unload, "catch unload"},
3164 {bp_catch_fork, "catch fork"},
3165 {bp_catch_vfork, "catch vfork"},
3166 {bp_catch_exec, "catch exec"},
3167 {bp_catch_catch, "catch catch"},
3168 {bp_catch_throw, "catch throw"}
3171 static char *bpdisps[] =
3172 {"del", "dstp", "dis", "keep"};
3173 static char bpenables[] = "nynny";
3174 char wrap_indent[80];
3176 struct ui_stream *stb = ui_out_stream_new (uiout);
3177 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3182 ui_out_list_begin (uiout, "bkpt");
3188 ui_out_field_int (uiout, "number", b->number);
3190 printf_filtered ("%-3d ", b->number);
3195 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3196 || ((int) b->type != bptypes[(int) b->type].type))
3197 internal_error ("bptypes table does not describe type #%d.",
3200 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3202 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3208 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3210 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3216 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3217 ui_out_spaces (uiout, 2);
3219 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3223 strcpy (wrap_indent, " ");
3225 strcat (wrap_indent, " ");
3229 internal_error ("print_one_breakpoint: bp_none encountered\n");
3233 case bp_hardware_watchpoint:
3234 case bp_read_watchpoint:
3235 case bp_access_watchpoint:
3236 /* Field 4, the address, is omitted (which makes the columns
3237 not line up too nicely with the headers, but the effect
3238 is relatively readable). */
3241 ui_out_field_skip (uiout, "addr");
3243 print_expression (b->exp, stb->stream);
3244 ui_out_field_stream (uiout, "what", stb);
3247 print_expression (b->exp, gdb_stdout);
3252 case bp_catch_unload:
3253 /* Field 4, the address, is omitted (which makes the columns
3254 not line up too nicely with the headers, but the effect
3255 is relatively readable). */
3258 ui_out_field_skip (uiout, "addr");
3260 if (b->dll_pathname == NULL)
3262 ui_out_field_string (uiout, "what", "<any library>");
3263 ui_out_spaces (uiout, 1);
3267 ui_out_text (uiout, "library \"");
3268 ui_out_field_string (uiout, "what", b->dll_pathname);
3269 ui_out_text (uiout, "\" ");
3273 if (b->dll_pathname == NULL)
3274 printf_filtered ("<any library> ");
3276 printf_filtered ("library \"%s\" ", b->dll_pathname);
3281 case bp_catch_vfork:
3282 /* Field 4, the address, is omitted (which makes the columns
3283 not line up too nicely with the headers, but the effect
3284 is relatively readable). */
3287 ui_out_field_skip (uiout, "addr");
3289 if (b->forked_inferior_pid != 0)
3291 ui_out_text (uiout, "process ");
3292 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3293 ui_out_spaces (uiout, 1);
3297 if (b->forked_inferior_pid != 0)
3298 printf_filtered ("process %d ", b->forked_inferior_pid);
3303 /* Field 4, the address, is omitted (which makes the columns
3304 not line up too nicely with the headers, but the effect
3305 is relatively readable). */
3308 ui_out_field_skip (uiout, "addr");
3310 if (b->exec_pathname != NULL)
3312 ui_out_text (uiout, "program \"");
3313 ui_out_field_string (uiout, "what", b->exec_pathname);
3314 ui_out_text (uiout, "\" ");
3318 if (b->exec_pathname != NULL)
3319 printf_filtered ("program \"%s\" ", b->exec_pathname);
3323 case bp_catch_catch:
3324 /* Field 4, the address, is omitted (which makes the columns
3325 not line up too nicely with the headers, but the effect
3326 is relatively readable). */
3329 ui_out_field_skip (uiout, "addr");
3331 ui_out_field_string (uiout, "what", "exception catch");
3332 ui_out_spaces (uiout, 1);
3335 printf_filtered ("exception catch ");
3339 case bp_catch_throw:
3340 /* Field 4, the address, is omitted (which makes the columns
3341 not line up too nicely with the headers, but the effect
3342 is relatively readable). */
3345 ui_out_field_skip (uiout, "addr");
3347 ui_out_field_string (uiout, "what", "exception throw");
3348 ui_out_spaces (uiout, 1);
3351 printf_filtered ("exception throw ");
3356 case bp_hardware_breakpoint:
3360 case bp_longjmp_resume:
3361 case bp_step_resume:
3362 case bp_through_sigtramp:
3363 case bp_watchpoint_scope:
3365 case bp_shlib_event:
3366 case bp_thread_event:
3371 ui_out_field_core_addr (uiout, "addr", b->address);
3374 *last_addr = b->address;
3377 sym = find_pc_sect_function (b->address, b->section);
3380 ui_out_text (uiout, "in ");
3381 ui_out_field_string (uiout, "func",
3382 SYMBOL_SOURCE_NAME (sym));
3383 ui_out_wrap_hint (uiout, wrap_indent);
3384 ui_out_text (uiout, " at ");
3386 ui_out_field_string (uiout, "file", b->source_file);
3387 ui_out_text (uiout, ":");
3388 ui_out_field_int (uiout, "line", b->line_number);
3392 print_address_symbolic (b->address, stb->stream, demangle, "");
3393 ui_out_field_stream (uiout, "at", stb);
3399 /* FIXME-32x64: need a print_address_numeric with
3403 local_hex_string_custom
3404 ((unsigned long) b->address, "08l"));
3407 *last_addr = b->address;
3410 sym = find_pc_sect_function (b->address, b->section);
3413 fputs_filtered ("in ", gdb_stdout);
3414 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3415 wrap_here (wrap_indent);
3416 fputs_filtered (" at ", gdb_stdout);
3418 fputs_filtered (b->source_file, gdb_stdout);
3419 printf_filtered (":%d", b->line_number);
3422 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3427 if (b->thread != -1)
3430 /* FIXME: This seems to be redundant and lost here; see the
3431 "stop only in" line a little further down. */
3432 ui_out_text (uiout, " thread ");
3433 ui_out_field_int (uiout, "thread", b->thread);
3435 printf_filtered (" thread %d", b->thread);
3440 ui_out_text (uiout, "\n");
3442 printf_filtered ("\n");
3449 ui_out_text (uiout, "\tstop only in stack frame at ");
3450 ui_out_field_core_addr (uiout, "frame", b->frame);
3451 ui_out_text (uiout, "\n");
3453 printf_filtered ("\tstop only in stack frame at ");
3454 print_address_numeric (b->frame, 1, gdb_stdout);
3455 printf_filtered ("\n");
3463 ui_out_text (uiout, "\tstop only if ");
3464 print_expression (b->cond, stb->stream);
3465 ui_out_field_stream (uiout, "cond", stb);
3466 ui_out_text (uiout, "\n");
3468 printf_filtered ("\tstop only if ");
3469 print_expression (b->cond, gdb_stdout);
3470 printf_filtered ("\n");
3474 if (b->thread != -1)
3476 /* FIXME should make an annotation for this */
3478 ui_out_text (uiout, "\tstop only in thread ");
3479 ui_out_field_int (uiout, "thread", b->thread);
3480 ui_out_text (uiout, "\n");
3482 printf_filtered ("\tstop only in thread %d\n", b->thread);
3486 if (show_breakpoint_hit_counts && b->hit_count)
3488 /* FIXME should make an annotation for this */
3490 if (ep_is_catchpoint (b))
3491 ui_out_text (uiout, "\tcatchpoint");
3493 ui_out_text (uiout, "\tbreakpoint");
3494 ui_out_text (uiout, " already hit ");
3495 ui_out_field_int (uiout, "times", b->hit_count);
3496 if (b->hit_count == 1)
3497 ui_out_text (uiout, " time\n");
3499 ui_out_text (uiout, " times\n");
3501 if (ep_is_catchpoint (b))
3502 printf_filtered ("\tcatchpoint");
3504 printf_filtered ("\tbreakpoint");
3505 printf_filtered (" already hit %d time%s\n",
3506 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3511 /* Output the count also if it is zero, but only if this is
3512 mi. FIXME: Should have a better test for this. */
3513 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3514 if (show_breakpoint_hit_counts && b->hit_count == 0)
3515 ui_out_field_int (uiout, "times", b->hit_count);
3518 if (b->ignore_count)
3522 ui_out_text (uiout, "\tignore next ");
3523 ui_out_field_int (uiout, "ignore", b->ignore_count);
3524 ui_out_text (uiout, " hits\n");
3526 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3530 if ((l = b->commands))
3534 ui_out_list_begin (uiout, "script");
3535 print_command_lines (uiout, l, 4);
3536 ui_out_list_end (uiout);
3540 print_command_line (l, 4, gdb_stdout);
3546 ui_out_list_end (uiout);
3547 do_cleanups (old_chain);
3551 struct captured_breakpoint_query_args
3557 do_captured_breakpoint_query (void *data)
3559 struct captured_breakpoint_query_args *args = data;
3560 register struct breakpoint *b;
3561 CORE_ADDR dummy_addr = 0;
3564 if (args->bnum == b->number)
3566 print_one_breakpoint (b, &dummy_addr);
3574 gdb_breakpoint_query (/* output object, */ int bnum)
3576 struct captured_breakpoint_query_args args;
3578 /* For the moment we don't trust print_one_breakpoint() to not throw
3580 return catch_errors (do_captured_breakpoint_query, &args,
3581 NULL, RETURN_MASK_ALL);
3584 /* Print information on breakpoint number BNUM, or -1 if all.
3585 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3586 is nonzero, process only watchpoints. */
3589 breakpoint_1 (bnum, allflag)
3593 register struct breakpoint *b;
3594 CORE_ADDR last_addr = (CORE_ADDR) -1;
3595 int found_a_breakpoint = 0;
3599 ui_out_table_begin (uiout, 6, "BreakpointTable");
3601 ui_out_table_begin (uiout, 5, "BreakpointTable");
3606 || bnum == b->number)
3608 /* We only print out user settable breakpoints unless the
3611 && b->type != bp_breakpoint
3612 && b->type != bp_catch_load
3613 && b->type != bp_catch_unload
3614 && b->type != bp_catch_fork
3615 && b->type != bp_catch_vfork
3616 && b->type != bp_catch_exec
3617 && b->type != bp_catch_catch
3618 && b->type != bp_catch_throw
3619 && b->type != bp_hardware_breakpoint
3620 && b->type != bp_watchpoint
3621 && b->type != bp_read_watchpoint
3622 && b->type != bp_access_watchpoint
3623 && b->type != bp_hardware_watchpoint)
3626 if (!found_a_breakpoint++)
3628 annotate_breakpoints_headers ();
3631 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3633 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3635 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3637 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3641 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3644 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3645 ui_out_table_body (uiout);
3648 printf_filtered ("Num ");
3650 printf_filtered ("Type ");
3652 printf_filtered ("Disp ");
3654 printf_filtered ("Enb ");
3658 printf_filtered ("Address ");
3661 printf_filtered ("What\n");
3663 annotate_breakpoints_table ();
3666 print_one_breakpoint (b, &last_addr);
3669 if (!found_a_breakpoint)
3673 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3675 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3679 printf_filtered ("No breakpoints or watchpoints.\n");
3681 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3686 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3687 that a comparison of an unsigned with -1 is always false. */
3688 if (last_addr != (CORE_ADDR) -1)
3689 set_next_address (last_addr);
3693 ui_out_table_end (uiout);
3695 /* FIXME? Should this be moved up so that it is only called when
3696 there have been breakpoints? */
3697 annotate_breakpoints_table_end ();
3702 breakpoints_info (bnum_exp, from_tty)
3709 bnum = parse_and_eval_address (bnum_exp);
3711 breakpoint_1 (bnum, 0);
3716 maintenance_info_breakpoints (bnum_exp, from_tty)
3723 bnum = parse_and_eval_address (bnum_exp);
3725 breakpoint_1 (bnum, 1);
3728 /* Print a message describing any breakpoints set at PC. */
3731 describe_other_breakpoints (pc, section)
3735 register int others = 0;
3736 register struct breakpoint *b;
3739 if (b->address == pc)
3740 if (overlay_debugging == 0 ||
3741 b->section == section)
3745 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3747 if (b->address == pc)
3748 if (overlay_debugging == 0 ||
3749 b->section == section)
3755 ((b->enable == disabled ||
3756 b->enable == shlib_disabled ||
3757 b->enable == call_disabled) ? " (disabled)"
3758 : b->enable == permanent ? " (permanent)"
3760 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3762 printf_filtered ("also set at pc ");
3763 print_address_numeric (pc, 1, gdb_stdout);
3764 printf_filtered (".\n");
3768 /* Set the default place to put a breakpoint
3769 for the `break' command with no arguments. */
3772 set_default_breakpoint (valid, addr, symtab, line)
3775 struct symtab *symtab;
3778 default_breakpoint_valid = valid;
3779 default_breakpoint_address = addr;
3780 default_breakpoint_symtab = symtab;
3781 default_breakpoint_line = line;
3784 /* Rescan breakpoints at address ADDRESS,
3785 marking the first one as "first" and any others as "duplicates".
3786 This is so that the bpt instruction is only inserted once.
3787 If we have a permanent breakpoint at ADDRESS, make that one
3788 the official one, and the rest as duplicates. */
3791 check_duplicates (address, section)
3795 register struct breakpoint *b;
3796 register int count = 0;
3797 struct breakpoint *perm_bp = 0;
3799 if (address == 0) /* Watchpoints are uninteresting */
3803 if (b->enable != disabled
3804 && b->enable != shlib_disabled
3805 && b->enable != call_disabled
3806 && b->address == address
3807 && (overlay_debugging == 0 || b->section == section))
3809 /* Have we found a permanent breakpoint? */
3810 if (b->enable == permanent)
3817 b->duplicate = count > 1;
3820 /* If we found a permanent breakpoint at this address, go over the
3821 list again and declare all the other breakpoints there to be the
3825 perm_bp->duplicate = 0;
3827 /* Permanent breakpoint should always be inserted. */
3828 if (! perm_bp->inserted)
3829 internal_error ("allegedly permanent breakpoint is not "
3830 "actually inserted");
3836 internal_error ("another breakpoint was inserted on top of "
3837 "a permanent breakpoint");
3839 if (b->enable != disabled
3840 && b->enable != shlib_disabled
3841 && b->enable != call_disabled
3842 && b->address == address
3843 && (overlay_debugging == 0 || b->section == section))
3849 /* Low level routine to set a breakpoint.
3850 Takes as args the three things that every breakpoint must have.
3851 Returns the breakpoint object so caller can set other things.
3852 Does not set the breakpoint number!
3853 Does not print anything.
3855 ==> This routine should not be called if there is a chance of later
3856 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3857 your arguments BEFORE calling this routine! */
3860 set_raw_breakpoint (sal)
3861 struct symtab_and_line sal;
3863 register struct breakpoint *b, *b1;
3865 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3866 memset (b, 0, sizeof (*b));
3867 b->address = sal.pc;
3868 if (sal.symtab == NULL)
3869 b->source_file = NULL;
3871 b->source_file = savestring (sal.symtab->filename,
3872 strlen (sal.symtab->filename));
3873 b->section = sal.section;
3874 b->language = current_language->la_language;
3875 b->input_radix = input_radix;
3877 b->line_number = sal.line;
3878 b->enable = enabled;
3881 b->ignore_count = 0;
3884 b->dll_pathname = NULL;
3885 b->triggered_dll_pathname = NULL;
3886 b->forked_inferior_pid = 0;
3887 b->exec_pathname = NULL;
3889 /* Add this breakpoint to the end of the chain
3890 so that a list of breakpoints will come out in order
3891 of increasing numbers. */
3893 b1 = breakpoint_chain;
3895 breakpoint_chain = b;
3903 check_duplicates (sal.pc, sal.section);
3904 breakpoints_changed ();
3910 /* Note that the breakpoint object B describes a permanent breakpoint
3911 instruction, hard-wired into the inferior's code. */
3913 make_breakpoint_permanent (struct breakpoint *b)
3915 b->enable = permanent;
3917 /* By definition, permanent breakpoints are already present in the code. */
3921 #ifdef GET_LONGJMP_TARGET
3924 create_longjmp_breakpoint (func_name)
3927 struct symtab_and_line sal;
3928 struct breakpoint *b;
3930 INIT_SAL (&sal); /* initialize to zeroes */
3931 if (func_name != NULL)
3933 struct minimal_symbol *m;
3935 m = lookup_minimal_symbol_text (func_name, NULL,
3936 (struct objfile *) NULL);
3938 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3942 sal.section = find_pc_overlay (sal.pc);
3943 b = set_raw_breakpoint (sal);
3947 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3948 b->disposition = donttouch;
3949 b->enable = disabled;
3952 b->addr_string = strsave (func_name);
3953 b->number = internal_breakpoint_number--;
3956 #endif /* #ifdef GET_LONGJMP_TARGET */
3958 /* Call this routine when stepping and nexting to enable a breakpoint
3959 if we do a longjmp(). When we hit that breakpoint, call
3960 set_longjmp_resume_breakpoint() to figure out where we are going. */
3963 enable_longjmp_breakpoint ()
3965 register struct breakpoint *b;
3968 if (b->type == bp_longjmp)
3970 b->enable = enabled;
3971 check_duplicates (b->address, b->section);
3976 disable_longjmp_breakpoint ()
3978 register struct breakpoint *b;
3981 if (b->type == bp_longjmp
3982 || b->type == bp_longjmp_resume)
3984 b->enable = disabled;
3985 check_duplicates (b->address, b->section);
3990 create_thread_event_breakpoint (address)
3993 struct breakpoint *b;
3994 struct symtab_and_line sal;
3995 char addr_string[80]; /* Surely an addr can't be longer than that. */
3997 INIT_SAL (&sal); /* initialize to zeroes */
3999 sal.section = find_pc_overlay (sal.pc);
4000 if ((b = set_raw_breakpoint (sal)) == NULL)
4003 b->number = internal_breakpoint_number--;
4004 b->disposition = donttouch;
4005 b->type = bp_thread_event; /* XXX: do we need a new type?
4007 b->enable = enabled;
4008 /* addr_string has to be used or breakpoint_re_set will delete me. */
4009 sprintf (addr_string, "*0x%s", paddr (b->address));
4010 b->addr_string = strsave (addr_string);
4016 remove_thread_event_breakpoints (void)
4018 struct breakpoint *b, *temp;
4020 ALL_BREAKPOINTS_SAFE (b, temp)
4021 if (b->type == bp_thread_event)
4022 delete_breakpoint (b);
4027 remove_solib_event_breakpoints ()
4029 register struct breakpoint *b, *temp;
4031 ALL_BREAKPOINTS_SAFE (b, temp)
4032 if (b->type == bp_shlib_event)
4033 delete_breakpoint (b);
4037 create_solib_event_breakpoint (address)
4040 struct breakpoint *b;
4041 struct symtab_and_line sal;
4043 INIT_SAL (&sal); /* initialize to zeroes */
4045 sal.section = find_pc_overlay (sal.pc);
4046 b = set_raw_breakpoint (sal);
4047 b->number = internal_breakpoint_number--;
4048 b->disposition = donttouch;
4049 b->type = bp_shlib_event;
4054 /* Disable any breakpoints that are on code in shared libraries. Only
4055 apply to enabled breakpoints, disabled ones can just stay disabled. */
4058 disable_breakpoints_in_shlibs (silent)
4061 struct breakpoint *b;
4062 int disabled_shlib_breaks = 0;
4064 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4067 #if defined (PC_SOLIB)
4068 if (((b->type == bp_breakpoint) ||
4069 (b->type == bp_hardware_breakpoint)) &&
4070 b->enable == enabled &&
4072 PC_SOLIB (b->address))
4074 b->enable = shlib_disabled;
4077 if (!disabled_shlib_breaks)
4079 target_terminal_ours_for_output ();
4080 warning ("Temporarily disabling shared library breakpoints:");
4082 disabled_shlib_breaks = 1;
4083 warning ("breakpoint #%d ", b->number);
4090 /* Try to reenable any breakpoints in shared libraries. */
4092 re_enable_breakpoints_in_shlibs ()
4094 struct breakpoint *b;
4097 if (b->enable == shlib_disabled)
4101 /* Do not reenable the breakpoint if the shared library
4102 is still not mapped in. */
4103 if (target_read_memory (b->address, buf, 1) == 0)
4104 b->enable = enabled;
4111 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
4116 enum bptype bp_kind;
4118 struct breakpoint *b;
4119 struct symtabs_and_lines sals;
4120 struct cleanup *old_chain;
4121 struct cleanup *canonical_strings_chain = NULL;
4122 char *addr_start = hookname;
4123 char *addr_end = NULL;
4124 char **canonical = (char **) NULL;
4125 int thread = -1; /* All threads. */
4127 /* Set a breakpoint on the specified hook. */
4128 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4129 addr_end = hookname;
4131 if (sals.nelts == 0)
4133 warning ("Unable to set a breakpoint on dynamic linker callback.");
4134 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4135 warning ("GDB will be unable to track shl_load/shl_unload calls");
4138 if (sals.nelts != 1)
4140 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4141 warning ("GDB will be unable to track shl_load/shl_unload calls");
4145 /* Make sure that all storage allocated in decode_line_1 gets freed
4146 in case the following errors out. */
4147 old_chain = make_cleanup (free, sals.sals);
4148 if (canonical != (char **) NULL)
4150 make_cleanup (free, canonical);
4151 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4152 if (canonical[0] != NULL)
4153 make_cleanup (free, canonical[0]);
4156 resolve_sal_pc (&sals.sals[0]);
4158 /* Remove the canonical strings from the cleanup, they are needed below. */
4159 if (canonical != (char **) NULL)
4160 discard_cleanups (canonical_strings_chain);
4162 b = set_raw_breakpoint (sals.sals[0]);
4163 set_breakpoint_count (breakpoint_count + 1);
4164 b->number = breakpoint_count;
4166 b->cond_string = (cond_string == NULL) ?
4167 NULL : savestring (cond_string, strlen (cond_string));
4170 if (canonical != (char **) NULL && canonical[0] != NULL)
4171 b->addr_string = canonical[0];
4172 else if (addr_start)
4173 b->addr_string = savestring (addr_start, addr_end - addr_start);
4175 b->enable = enabled;
4176 b->disposition = tempflag ? del : donttouch;
4178 if (dll_pathname == NULL)
4179 b->dll_pathname = NULL;
4182 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4183 strcpy (b->dll_pathname, dll_pathname);
4188 do_cleanups (old_chain);
4192 create_solib_load_event_breakpoint (hookname, tempflag,
4193 dll_pathname, cond_string)
4199 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4200 cond_string, bp_catch_load);
4204 create_solib_unload_event_breakpoint (hookname, tempflag,
4205 dll_pathname, cond_string)
4211 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4212 cond_string, bp_catch_unload);
4216 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
4219 enum bptype bp_kind;
4221 struct symtab_and_line sal;
4222 struct breakpoint *b;
4223 int thread = -1; /* All threads. */
4230 b = set_raw_breakpoint (sal);
4231 set_breakpoint_count (breakpoint_count + 1);
4232 b->number = breakpoint_count;
4234 b->cond_string = (cond_string == NULL) ?
4235 NULL : savestring (cond_string, strlen (cond_string));
4237 b->addr_string = NULL;
4238 b->enable = enabled;
4239 b->disposition = tempflag ? del : donttouch;
4240 b->forked_inferior_pid = 0;
4248 create_fork_event_catchpoint (tempflag, cond_string)
4252 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4256 create_vfork_event_catchpoint (tempflag, cond_string)
4260 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4264 create_exec_event_catchpoint (tempflag, cond_string)
4268 struct symtab_and_line sal;
4269 struct breakpoint *b;
4270 int thread = -1; /* All threads. */
4277 b = set_raw_breakpoint (sal);
4278 set_breakpoint_count (breakpoint_count + 1);
4279 b->number = breakpoint_count;
4281 b->cond_string = (cond_string == NULL) ?
4282 NULL : savestring (cond_string, strlen (cond_string));
4284 b->addr_string = NULL;
4285 b->enable = enabled;
4286 b->disposition = tempflag ? del : donttouch;
4288 b->type = bp_catch_exec;
4294 hw_breakpoint_used_count ()
4296 register struct breakpoint *b;
4301 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4309 hw_watchpoint_used_count (type, other_type_used)
4311 int *other_type_used;
4313 register struct breakpoint *b;
4316 *other_type_used = 0;
4319 if (b->enable == enabled)
4321 if (b->type == type)
4323 else if ((b->type == bp_hardware_watchpoint ||
4324 b->type == bp_read_watchpoint ||
4325 b->type == bp_access_watchpoint)
4326 && b->enable == enabled)
4327 *other_type_used = 1;
4333 /* Call this after hitting the longjmp() breakpoint. Use this to set
4334 a new breakpoint at the target of the jmp_buf.
4336 FIXME - This ought to be done by setting a temporary breakpoint
4337 that gets deleted automatically... */
4340 set_longjmp_resume_breakpoint (pc, frame)
4342 struct frame_info *frame;
4344 register struct breakpoint *b;
4347 if (b->type == bp_longjmp_resume)
4350 b->enable = enabled;
4352 b->frame = frame->frame;
4355 check_duplicates (b->address, b->section);
4361 disable_watchpoints_before_interactive_call_start ()
4363 struct breakpoint *b;
4367 if (((b->type == bp_watchpoint)
4368 || (b->type == bp_hardware_watchpoint)
4369 || (b->type == bp_read_watchpoint)
4370 || (b->type == bp_access_watchpoint)
4371 || ep_is_exception_catchpoint (b))
4372 && (b->enable == enabled))
4374 b->enable = call_disabled;
4375 check_duplicates (b->address, b->section);
4381 enable_watchpoints_after_interactive_call_stop ()
4383 struct breakpoint *b;
4387 if (((b->type == bp_watchpoint)
4388 || (b->type == bp_hardware_watchpoint)
4389 || (b->type == bp_read_watchpoint)
4390 || (b->type == bp_access_watchpoint)
4391 || ep_is_exception_catchpoint (b))
4392 && (b->enable == call_disabled))
4394 b->enable = enabled;
4395 check_duplicates (b->address, b->section);
4401 /* Set a breakpoint that will evaporate an end of command
4402 at address specified by SAL.
4403 Restrict it to frame FRAME if FRAME is nonzero. */
4406 set_momentary_breakpoint (sal, frame, type)
4407 struct symtab_and_line sal;
4408 struct frame_info *frame;
4411 register struct breakpoint *b;
4412 b = set_raw_breakpoint (sal);
4414 b->enable = enabled;
4415 b->disposition = donttouch;
4416 b->frame = (frame ? frame->frame : 0);
4418 /* If we're debugging a multi-threaded program, then we
4419 want momentary breakpoints to be active in only a
4420 single thread of control. */
4421 if (in_thread_list (inferior_pid))
4422 b->thread = pid_to_thread_id (inferior_pid);
4428 /* Tell the user we have just set a breakpoint B. */
4432 struct breakpoint *b;
4436 struct cleanup *old_chain;
4437 struct ui_stream *stb;
4439 stb = ui_out_stream_new (uiout);
4440 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
4443 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4444 watchpoint) other than breakpoint creation. It should be possible to
4445 clean this up and at the same time replace the random calls to
4446 breakpoint_changed with this hook, as has already been done for
4447 delete_breakpoint_hook and so on. */
4448 if (create_breakpoint_hook)
4449 create_breakpoint_hook (b);
4450 breakpoint_create_event (b->number);
4455 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4459 ui_out_text (uiout, "Watchpoint ");
4460 ui_out_list_begin (uiout, "wpt");
4461 ui_out_field_int (uiout, "number", b->number);
4462 ui_out_text (uiout, ": ");
4463 print_expression (b->exp, stb->stream);
4464 ui_out_field_stream (uiout, "exp", stb);
4465 ui_out_list_end (uiout);
4467 case bp_hardware_watchpoint:
4468 ui_out_text (uiout, "Hardware watchpoint ");
4469 ui_out_list_begin (uiout, "wpt");
4470 ui_out_field_int (uiout, "number", b->number);
4471 ui_out_text (uiout, ": ");
4472 print_expression (b->exp, stb->stream);
4473 ui_out_field_stream (uiout, "exp", stb);
4474 ui_out_list_end (uiout);
4478 printf_filtered ("Watchpoint %d: ", b->number);
4479 print_expression (b->exp, gdb_stdout);
4481 case bp_hardware_watchpoint:
4482 printf_filtered ("Hardware watchpoint %d: ", b->number);
4483 print_expression (b->exp, gdb_stdout);
4487 case bp_read_watchpoint:
4488 ui_out_text (uiout, "Hardware read watchpoint ");
4489 ui_out_list_begin (uiout, "hw-rwpt");
4490 ui_out_field_int (uiout, "number", b->number);
4491 ui_out_text (uiout, ": ");
4492 print_expression (b->exp, stb->stream);
4493 ui_out_field_stream (uiout, "exp", stb);
4494 ui_out_list_end (uiout);
4496 case bp_access_watchpoint:
4497 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4498 ui_out_list_begin (uiout, "hw-awpt");
4499 ui_out_field_int (uiout, "number", b->number);
4500 ui_out_text (uiout, ": ");
4501 print_expression (b->exp, stb->stream);
4502 ui_out_field_stream (uiout, "exp", stb);
4503 ui_out_list_end (uiout);
4506 case bp_read_watchpoint:
4507 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4508 print_expression (b->exp, gdb_stdout);
4510 case bp_access_watchpoint:
4511 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4513 print_expression (b->exp, gdb_stdout);
4518 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4524 printf_filtered ("Breakpoint %d", b->number);
4527 case bp_hardware_breakpoint:
4529 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4535 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4539 case bp_catch_unload:
4540 printf_filtered ("Catchpoint %d (%s %s)",
4542 (b->type == bp_catch_load) ? "load" : "unload",
4543 (b->dll_pathname != NULL) ?
4544 b->dll_pathname : "<any library>");
4547 case bp_catch_vfork:
4548 printf_filtered ("Catchpoint %d (%s)",
4550 (b->type == bp_catch_fork) ? "fork" : "vfork");
4553 printf_filtered ("Catchpoint %d (exec)",
4556 case bp_catch_catch:
4557 case bp_catch_throw:
4558 printf_filtered ("Catchpoint %d (%s)",
4560 (b->type == bp_catch_catch) ? "catch" : "throw");
4566 case bp_longjmp_resume:
4567 case bp_step_resume:
4568 case bp_through_sigtramp:
4570 case bp_watchpoint_scope:
4571 case bp_shlib_event:
4572 case bp_thread_event:
4577 if (addressprint || b->source_file == NULL)
4579 printf_filtered (" at ");
4580 print_address_numeric (b->address, 1, gdb_stdout);
4583 printf_filtered (": file %s, line %d.",
4584 b->source_file, b->line_number);
4585 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4586 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4589 do_cleanups (old_chain);
4592 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4595 printf_filtered ("\n");
4599 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4600 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4601 COND[i] and COND_STRING[i] values.
4603 NOTE: If the function succeeds, the caller is expected to cleanup
4604 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4605 array contents). If the function fails (error() is called), the
4606 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4607 COND and SALS arrays and each of those arrays contents. */
4610 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4611 struct expression **cond, char **cond_string,
4612 enum bptype type, enum bpdisp disposition,
4613 int thread, int ignore_count, int from_tty)
4615 if (type == bp_hardware_breakpoint)
4617 int i = hw_breakpoint_used_count ();
4618 int target_resources_ok =
4619 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4621 if (target_resources_ok == 0)
4622 error ("No hardware breakpoint support in the target.");
4623 else if (target_resources_ok < 0)
4624 error ("Hardware breakpoints used exceeds limit.");
4627 /* Now set all the breakpoints. */
4630 for (i = 0; i < sals.nelts; i++)
4632 struct breakpoint *b;
4633 struct symtab_and_line sal = sals.sals[i];
4636 describe_other_breakpoints (sal.pc, sal.section);
4638 b = set_raw_breakpoint (sal);
4639 set_breakpoint_count (breakpoint_count + 1);
4640 b->number = breakpoint_count;
4644 b->addr_string = addr_string[i];
4645 b->cond_string = cond_string[i];
4646 b->ignore_count = ignore_count;
4647 b->enable = enabled;
4648 b->disposition = disposition;
4654 /* Parse ARG which is assumed to be a SAL specification possibly
4655 followed by conditionals. On return, SALS contains an array of SAL
4656 addresses found. ADDR_STRING contains a vector of (canonical)
4657 address strings. ARG points to the end of the SAL. */
4660 parse_breakpoint_sals (char **address,
4661 struct symtabs_and_lines *sals,
4662 char ***addr_string)
4664 char *addr_start = *address;
4665 *addr_string = NULL;
4666 /* If no arg given, or if first arg is 'if ', use the default
4668 if ((*address) == NULL
4669 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4671 if (default_breakpoint_valid)
4673 struct symtab_and_line sal;
4674 INIT_SAL (&sal); /* initialize to zeroes */
4675 sals->sals = (struct symtab_and_line *)
4676 xmalloc (sizeof (struct symtab_and_line));
4677 sal.pc = default_breakpoint_address;
4678 sal.line = default_breakpoint_line;
4679 sal.symtab = default_breakpoint_symtab;
4680 sal.section = find_pc_overlay (sal.pc);
4681 sals->sals[0] = sal;
4685 error ("No default breakpoint address now.");
4689 /* Force almost all breakpoints to be in terms of the
4690 current_source_symtab (which is decode_line_1's default). This
4691 should produce the results we want almost all of the time while
4692 leaving default_breakpoint_* alone. */
4693 if (default_breakpoint_valid
4694 && (!current_source_symtab
4695 || (strchr ("+-", (*address)[0]) != NULL)))
4696 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4697 default_breakpoint_line, addr_string);
4699 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4701 /* For any SAL that didn't have a canonical string, fill one in. */
4702 if (sals->nelts > 0 && *addr_string == NULL)
4703 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4704 if (addr_start != (*address))
4707 for (i = 0; i < sals->nelts; i++)
4709 /* Add the string if not present. */
4710 if ((*addr_string)[i] == NULL)
4711 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4717 /* Convert each SAL into a real PC. Verify that the PC can be
4718 inserted as a breakpoint. If it can't throw an error. */
4721 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4725 for (i = 0; i < sals->nelts; i++)
4727 resolve_sal_pc (&sals->sals[i]);
4729 /* It's possible for the PC to be nonzero, but still an illegal
4730 value on some targets.
4732 For example, on HP-UX if you start gdb, and before running the
4733 inferior you try to set a breakpoint on a shared library function
4734 "foo" where the inferior doesn't call "foo" directly but does
4735 pass its address to another function call, then we do find a
4736 minimal symbol for the "foo", but it's address is invalid.
4737 (Appears to be an index into a table that the loader sets up
4738 when the inferior is run.)
4740 Give the target a chance to bless sals.sals[i].pc before we
4741 try to make a breakpoint for it. */
4742 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4744 if (address == NULL)
4745 error ("Cannot break without a running program.");
4747 error ("Cannot break on %s without a running program.",
4753 /* Set a breakpoint according to ARG (function, linenum or *address)
4754 flag: first bit : 0 non-temporary, 1 temporary.
4755 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4758 break_command_1 (arg, flag, from_tty)
4762 int tempflag, hardwareflag;
4763 struct symtabs_and_lines sals;
4764 register struct expression **cond = 0;
4765 /* Pointers in arg to the start, and one past the end, of the
4767 char **cond_string = (char **) NULL;
4768 char *addr_start = arg;
4770 struct cleanup *old_chain;
4771 struct cleanup *breakpoint_chain = NULL;
4774 int ignore_count = 0;
4776 hardwareflag = flag & BP_HARDWAREFLAG;
4777 tempflag = flag & BP_TEMPFLAG;
4782 parse_breakpoint_sals (&arg, &sals, &addr_string);
4787 /* Create a chain of things that always need to be cleaned up. */
4788 old_chain = make_cleanup (null_cleanup, 0);
4790 /* Make sure that all storage allocated to SALS gets freed. */
4791 make_cleanup (free, sals.sals);
4793 /* Cleanup the addr_string array but not its contents. */
4794 make_cleanup (free, addr_string);
4796 /* Allocate space for all the cond expressions. */
4797 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4798 make_cleanup (free, cond);
4800 /* Allocate space for all the cond strings. */
4801 cond_string = xcalloc (sals.nelts, sizeof (char **));
4802 make_cleanup (free, cond_string);
4804 /* ----------------------------- SNIP -----------------------------
4805 Anything added to the cleanup chain beyond this point is assumed
4806 to be part of a breakpoint. If the breakpoint create succeeds
4807 then the memory is not reclaimed. */
4808 breakpoint_chain = make_cleanup (null_cleanup, 0);
4810 /* Mark the contents of the addr_string for cleanup. These go on
4811 the breakpoint_chain and only occure if the breakpoint create
4813 for (i = 0; i < sals.nelts; i++)
4815 if (addr_string[i] != NULL)
4816 make_cleanup (free, addr_string[i]);
4819 /* Resolve all line numbers to PC's and verify that the addresses
4820 are ok for the target. */
4821 breakpoint_sals_to_pc (&sals, addr_start);
4823 /* Verify that condition can be parsed, before setting any
4824 breakpoints. Allocate a separate condition expression for each
4826 thread = -1; /* No specific thread yet */
4827 for (i = 0; i < sals.nelts; i++)
4834 char *cond_start = NULL;
4835 char *cond_end = NULL;
4836 while (*tok == ' ' || *tok == '\t')
4841 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4844 toklen = end_tok - tok;
4846 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4848 tok = cond_start = end_tok + 1;
4849 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4850 make_cleanup (free, cond[i]);
4852 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4853 make_cleanup (free, cond_string[i]);
4855 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4861 thread = strtol (tok, &tok, 0);
4863 error ("Junk after thread keyword.");
4864 if (!valid_thread_id (thread))
4865 error ("Unknown thread %d\n", thread);
4868 error ("Junk at end of arguments.");
4872 create_breakpoints (sals, addr_string, cond, cond_string,
4873 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4874 tempflag ? del : donttouch,
4875 thread, ignore_count, from_tty);
4879 warning ("Multiple breakpoints were set.");
4880 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4882 /* That's it. Discard the cleanups for data inserted into the
4884 discard_cleanups (breakpoint_chain);
4885 /* But cleanup everything else. */
4886 do_cleanups (old_chain);
4889 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4890 linenum or *address) with COND and IGNORE_COUNT. */
4892 struct captured_breakpoint_args
4903 do_captured_breakpoint (void *data)
4905 struct captured_breakpoint_args *args = data;
4906 struct symtabs_and_lines sals;
4907 register struct expression **cond;
4908 struct cleanup *old_chain;
4909 struct cleanup *breakpoint_chain = NULL;
4916 /* Parse the source and lines spec. Delay check that the expression
4917 didn't contain trailing garbage until after cleanups are in
4921 address_end = args->address;
4923 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4928 /* Create a chain of things at always need to be cleaned up. */
4929 old_chain = make_cleanup (null_cleanup, 0);
4931 /* Always have a addr_string array, even if it is empty. */
4932 make_cleanup (free, addr_string);
4934 /* Make sure that all storage allocated to SALS gets freed. */
4935 make_cleanup (free, sals.sals);
4937 /* Allocate space for all the cond expressions. */
4938 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4939 make_cleanup (free, cond);
4941 /* Allocate space for all the cond strings. */
4942 cond_string = xcalloc (sals.nelts, sizeof (char **));
4943 make_cleanup (free, cond_string);
4945 /* ----------------------------- SNIP -----------------------------
4946 Anything added to the cleanup chain beyond this point is assumed
4947 to be part of a breakpoint. If the breakpoint create goes
4948 through then that memory is not cleaned up. */
4949 breakpoint_chain = make_cleanup (null_cleanup, 0);
4951 /* Mark the contents of the addr_string for cleanup. These go on
4952 the breakpoint_chain and only occure if the breakpoint create
4954 for (i = 0; i < sals.nelts; i++)
4956 if (addr_string[i] != NULL)
4957 make_cleanup (free, addr_string[i]);
4960 /* Wait until now before checking for garbage at the end of the
4961 address. That way cleanups can take care of freeing any
4963 if (*address_end != '\0')
4964 error ("Garbage %s following breakpoint address", address_end);
4966 /* Resolve all line numbers to PC's. */
4967 breakpoint_sals_to_pc (&sals, args->address);
4969 /* Verify that conditions can be parsed, before setting any
4971 for (i = 0; i < sals.nelts; i++)
4973 if (args->condition != NULL)
4975 char *tok = args->condition;
4976 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4978 error ("Garbage %s follows condition", tok);
4979 make_cleanup (free, cond[i]);
4980 cond_string[i] = xstrdup (args->condition);
4984 create_breakpoints (sals, addr_string, cond, cond_string,
4985 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4986 args->tempflag ? del : donttouch,
4987 args->thread, args->ignore_count, 0/*from-tty*/);
4989 /* That's it. Discard the cleanups for data inserted into the
4991 discard_cleanups (breakpoint_chain);
4992 /* But cleanup everything else. */
4993 do_cleanups (old_chain);
4998 gdb_breakpoint (char *address, char *condition,
4999 int hardwareflag, int tempflag,
5000 int thread, int ignore_count)
5002 struct captured_breakpoint_args args;
5003 args.address = address;
5004 args.condition = condition;
5005 args.hardwareflag = hardwareflag;
5006 args.tempflag = tempflag;
5007 args.thread = thread;
5008 args.ignore_count = ignore_count;
5009 return catch_errors (do_captured_breakpoint, &args,
5010 NULL, RETURN_MASK_ALL);
5015 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
5020 struct frame_info *frame;
5021 CORE_ADDR low, high, selected_pc = 0;
5022 char *extra_args, *level_arg, *addr_string;
5023 int extra_args_len = 0, if_arg = 0;
5026 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5029 if (default_breakpoint_valid)
5033 selected_pc = selected_frame->pc;
5038 error ("No selected frame.");
5041 error ("No default breakpoint address now.");
5045 extra_args = strchr (arg, ' ');
5049 extra_args_len = strlen (extra_args);
5050 level_arg = (char *) xmalloc (extra_args - arg);
5051 strncpy (level_arg, arg, extra_args - arg - 1);
5052 level_arg[extra_args - arg - 1] = '\0';
5056 level_arg = (char *) xmalloc (strlen (arg) + 1);
5057 strcpy (level_arg, arg);
5060 frame = parse_frame_specification (level_arg);
5062 selected_pc = frame->pc;
5069 extra_args_len = strlen (arg);
5074 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5076 addr_string = (char *) xmalloc (26 + extra_args_len);
5078 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
5080 sprintf (addr_string, "*0x%s", paddr_nz (high));
5081 break_command_1 (addr_string, flag, from_tty);
5085 error ("No function contains the specified address");
5088 error ("Unable to set breakpoint at procedure exit");
5093 break_at_finish_command_1 (arg, flag, from_tty)
5098 char *addr_string, *break_string, *beg_addr_string;
5099 CORE_ADDR low, high;
5100 struct symtabs_and_lines sals;
5101 struct symtab_and_line sal;
5102 struct cleanup *old_chain;
5104 int extra_args_len = 0;
5108 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5110 if (default_breakpoint_valid)
5114 addr_string = (char *) xmalloc (15);
5115 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5120 error ("No selected frame.");
5123 error ("No default breakpoint address now.");
5127 addr_string = (char *) xmalloc (strlen (arg) + 1);
5128 strcpy (addr_string, arg);
5134 extra_args_len = strlen (arg);
5138 /* get the stuff after the function name or address */
5139 extra_args = strchr (arg, ' ');
5143 extra_args_len = strlen (extra_args);
5150 beg_addr_string = addr_string;
5151 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5154 free (beg_addr_string);
5155 old_chain = make_cleanup (free, sals.sals);
5156 for (i = 0; (i < sals.nelts); i++)
5159 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5161 break_string = (char *) xmalloc (extra_args_len + 26);
5163 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5165 sprintf (break_string, "*0x%s", paddr_nz (high));
5166 break_command_1 (break_string, flag, from_tty);
5167 free (break_string);
5170 error ("No function contains the specified address");
5174 warning ("Multiple breakpoints were set.\n");
5175 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5177 do_cleanups (old_chain);
5181 /* Helper function for break_command_1 and disassemble_command. */
5184 resolve_sal_pc (sal)
5185 struct symtab_and_line *sal;
5189 if (sal->pc == 0 && sal->symtab != NULL)
5191 if (!find_line_pc (sal->symtab, sal->line, &pc))
5192 error ("No line %d in file \"%s\".",
5193 sal->line, sal->symtab->filename);
5197 if (sal->section == 0 && sal->symtab != NULL)
5199 struct blockvector *bv;
5204 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5207 b = BLOCKVECTOR_BLOCK (bv, index);
5208 sym = block_function (b);
5211 fixup_symbol_section (sym, sal->symtab->objfile);
5212 sal->section = SYMBOL_BFD_SECTION (sym);
5216 /* It really is worthwhile to have the section, so we'll just
5217 have to look harder. This case can be executed if we have
5218 line numbers but no functions (as can happen in assembly
5221 struct minimal_symbol *msym;
5223 msym = lookup_minimal_symbol_by_pc (sal->pc);
5225 sal->section = SYMBOL_BFD_SECTION (msym);
5232 break_command (arg, from_tty)
5236 break_command_1 (arg, 0, from_tty);
5240 break_at_finish_command (arg, from_tty)
5244 break_at_finish_command_1 (arg, 0, from_tty);
5248 break_at_finish_at_depth_command (arg, from_tty)
5252 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5256 tbreak_command (arg, from_tty)
5260 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5264 tbreak_at_finish_command (arg, from_tty)
5268 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5272 hbreak_command (arg, from_tty)
5276 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5280 thbreak_command (arg, from_tty)
5284 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5288 stop_command (arg, from_tty)
5292 printf_filtered ("Specify the type of breakpoint to set.\n\
5293 Usage: stop in <function | address>\n\
5298 stopin_command (arg, from_tty)
5304 if (arg == (char *) NULL)
5306 else if (*arg != '*')
5311 /* look for a ':'. If this is a line number specification, then
5312 say it is bad, otherwise, it should be an address or
5313 function/method name */
5314 while (*argptr && !hasColon)
5316 hasColon = (*argptr == ':');
5321 badInput = (*argptr != ':'); /* Not a class::method */
5323 badInput = isdigit (*arg); /* a simple line number */
5327 printf_filtered ("Usage: stop in <function | address>\n");
5329 break_command_1 (arg, 0, from_tty);
5333 stopat_command (arg, from_tty)
5339 if (arg == (char *) NULL || *arg == '*') /* no line number */
5346 /* look for a ':'. If there is a '::' then get out, otherwise
5347 it is probably a line number. */
5348 while (*argptr && !hasColon)
5350 hasColon = (*argptr == ':');
5355 badInput = (*argptr == ':'); /* we have class::method */
5357 badInput = !isdigit (*arg); /* not a line number */
5361 printf_filtered ("Usage: stop at <line>\n");
5363 break_command_1 (arg, 0, from_tty);
5367 /* accessflag: hw_write: watch write,
5368 hw_read: watch read,
5369 hw_access: watch access (read or write) */
5371 watch_command_1 (arg, accessflag, from_tty)
5376 struct breakpoint *b;
5377 struct symtab_and_line sal;
5378 struct expression *exp;
5379 struct block *exp_valid_block;
5380 struct value *val, *mark;
5381 struct frame_info *frame;
5382 struct frame_info *prev_frame = NULL;
5383 char *exp_start = NULL;
5384 char *exp_end = NULL;
5385 char *tok, *end_tok;
5387 char *cond_start = NULL;
5388 char *cond_end = NULL;
5389 struct expression *cond = NULL;
5390 int i, other_type_used, target_resources_ok = 0;
5391 enum bptype bp_type;
5394 INIT_SAL (&sal); /* initialize to zeroes */
5396 /* Parse arguments. */
5397 innermost_block = NULL;
5399 exp = parse_exp_1 (&arg, 0, 0);
5401 exp_valid_block = innermost_block;
5402 mark = value_mark ();
5403 val = evaluate_expression (exp);
5404 release_value (val);
5405 if (VALUE_LAZY (val))
5406 value_fetch_lazy (val);
5409 while (*tok == ' ' || *tok == '\t')
5413 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5416 toklen = end_tok - tok;
5417 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5419 tok = cond_start = end_tok + 1;
5420 cond = parse_exp_1 (&tok, 0, 0);
5424 error ("Junk at end of command.");
5426 if (accessflag == hw_read)
5427 bp_type = bp_read_watchpoint;
5428 else if (accessflag == hw_access)
5429 bp_type = bp_access_watchpoint;
5431 bp_type = bp_hardware_watchpoint;
5433 mem_cnt = can_use_hardware_watchpoint (val);
5434 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5435 error ("Expression cannot be implemented with read/access watchpoint.");
5438 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5439 target_resources_ok =
5440 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5442 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5443 error ("Target does not support this type of hardware watchpoint.");
5445 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5446 error ("Target can only support one kind of HW watchpoint at a time.");
5449 #if defined(HPUXHPPA)
5450 /* On HP-UX if you set a h/w
5451 watchpoint before the "run" command, the inferior dies with a e.g.,
5452 SIGILL once you start it. I initially believed this was due to a
5453 bad interaction between page protection traps and the initial
5454 startup sequence by the dynamic linker.
5456 However, I tried avoiding that by having HP-UX's implementation of
5457 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
5458 yet, which forced slow watches before a "run" or "attach", and it
5459 still fails somewhere in the startup code.
5461 Until I figure out what's happening, I'm disallowing watches altogether
5462 before the "run" or "attach" command. We'll tell the user they must
5463 set watches after getting the program started. */
5464 if (!target_has_execution)
5466 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5469 #endif /* HPUXHPPA */
5471 /* Now set up the breakpoint. */
5472 b = set_raw_breakpoint (sal);
5473 set_breakpoint_count (breakpoint_count + 1);
5474 b->number = breakpoint_count;
5475 b->disposition = donttouch;
5477 b->exp_valid_block = exp_valid_block;
5478 b->exp_string = savestring (exp_start, exp_end - exp_start);
5482 b->cond_string = savestring (cond_start, cond_end - cond_start);
5486 frame = block_innermost_frame (exp_valid_block);
5489 prev_frame = get_prev_frame (frame);
5490 b->watchpoint_frame = frame->frame;
5493 b->watchpoint_frame = (CORE_ADDR) 0;
5495 if (mem_cnt && target_resources_ok > 0)
5498 b->type = bp_watchpoint;
5500 /* If the expression is "local", then set up a "watchpoint scope"
5501 breakpoint at the point where we've left the scope of the watchpoint
5503 if (innermost_block)
5507 struct breakpoint *scope_breakpoint;
5508 struct symtab_and_line scope_sal;
5510 INIT_SAL (&scope_sal); /* initialize to zeroes */
5511 scope_sal.pc = get_frame_pc (prev_frame);
5512 scope_sal.section = find_pc_overlay (scope_sal.pc);
5514 scope_breakpoint = set_raw_breakpoint (scope_sal);
5515 set_breakpoint_count (breakpoint_count + 1);
5516 scope_breakpoint->number = breakpoint_count;
5518 scope_breakpoint->type = bp_watchpoint_scope;
5519 scope_breakpoint->enable = enabled;
5521 /* Automatically delete the breakpoint when it hits. */
5522 scope_breakpoint->disposition = del;
5524 /* Only break in the proper frame (help with recursion). */
5525 scope_breakpoint->frame = prev_frame->frame;
5527 /* Set the address at which we will stop. */
5528 scope_breakpoint->address = get_frame_pc (prev_frame);
5530 /* The scope breakpoint is related to the watchpoint. We
5531 will need to act on them together. */
5532 b->related_breakpoint = scope_breakpoint;
5535 value_free_to_mark (mark);
5539 /* Return count of locations need to be watched and can be handled
5540 in hardware. If the watchpoint can not be handled
5541 in hardware return zero. */
5543 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5544 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5545 ((BYTE_SIZE) <= (REGISTER_SIZE))
5548 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5549 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5550 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
5554 can_use_hardware_watchpoint (v)
5557 int found_memory_cnt = 0;
5558 struct value *head = v;
5560 /* Did the user specifically forbid us to use hardware watchpoints? */
5561 if (!can_use_hw_watchpoints)
5564 /* Make sure that the value of the expression depends only upon
5565 memory contents, and values computed from them within GDB. If we
5566 find any register references or function calls, we can't use a
5567 hardware watchpoint.
5569 The idea here is that evaluating an expression generates a series
5570 of values, one holding the value of every subexpression. (The
5571 expression a*b+c has five subexpressions: a, b, a*b, c, and
5572 a*b+c.) GDB's values hold almost enough information to establish
5573 the criteria given above --- they identify memory lvalues,
5574 register lvalues, computed values, etcetera. So we can evaluate
5575 the expression, and then scan the chain of values that leaves
5576 behind to decide whether we can detect any possible change to the
5577 expression's final value using only hardware watchpoints.
5579 However, I don't think that the values returned by inferior
5580 function calls are special in any way. So this function may not
5581 notice that an expression involving an inferior function call
5582 can't be watched with hardware watchpoints. FIXME. */
5583 for (; v; v = v->next)
5585 if (VALUE_LVAL (v) == lval_memory)
5588 /* A lazy memory lvalue is one that GDB never needed to fetch;
5589 we either just used its address (e.g., `a' in `a.b') or
5590 we never needed it at all (e.g., `a' in `a,b'). */
5594 /* Ahh, memory we actually used! Check if we can cover
5595 it with hardware watchpoints. */
5596 struct type *vtype = check_typedef (VALUE_TYPE (v));
5598 /* We only watch structs and arrays if user asked for it
5599 explicitly, never if they just happen to appear in a
5600 middle of some value chain. */
5602 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5603 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5605 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5606 int len = TYPE_LENGTH (VALUE_TYPE (v));
5608 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5615 else if (v->lval != not_lval && v->modifiable == 0)
5616 return 0; /* ??? What does this represent? */
5617 else if (v->lval == lval_register)
5618 return 0; /* cannot watch a register with a HW watchpoint */
5621 /* The expression itself looks suitable for using a hardware
5622 watchpoint, but give the target machine a chance to reject it. */
5623 return found_memory_cnt;
5628 watch_command_wrapper (arg, from_tty)
5632 watch_command (arg, from_tty);
5636 watch_command (arg, from_tty)
5640 watch_command_1 (arg, hw_write, from_tty);
5645 rwatch_command_wrapper (arg, from_tty)
5649 rwatch_command (arg, from_tty);
5653 rwatch_command (arg, from_tty)
5657 watch_command_1 (arg, hw_read, from_tty);
5662 awatch_command_wrapper (arg, from_tty)
5666 awatch_command (arg, from_tty);
5670 awatch_command (arg, from_tty)
5674 watch_command_1 (arg, hw_access, from_tty);
5678 /* Helper routines for the until_command routine in infcmd.c. Here
5679 because it uses the mechanisms of breakpoints. */
5681 /* This function is called by fetch_inferior_event via the
5682 cmd_continuation pointer, to complete the until command. It takes
5683 care of cleaning up the temporary breakpoints set up by the until
5686 until_break_command_continuation (struct continuation_arg *arg)
5688 struct cleanup *cleanups;
5690 cleanups = (struct cleanup *) arg->data;
5691 do_exec_cleanups (cleanups);
5696 until_break_command (arg, from_tty)
5700 struct symtabs_and_lines sals;
5701 struct symtab_and_line sal;
5702 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5703 struct breakpoint *breakpoint;
5704 struct cleanup *old_chain;
5705 struct continuation_arg *arg1;
5708 clear_proceed_status ();
5710 /* Set a breakpoint where the user wants it and at return from
5713 if (default_breakpoint_valid)
5714 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5715 default_breakpoint_line, (char ***) NULL);
5717 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5718 0, (char ***) NULL);
5720 if (sals.nelts != 1)
5721 error ("Couldn't get information on specified line.");
5724 free ((PTR) sals.sals); /* malloc'd, so freed */
5727 error ("Junk at end of arguments.");
5729 resolve_sal_pc (&sal);
5731 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5733 if (!event_loop_p || !target_can_async_p ())
5734 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
5737 old_chain = make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5739 /* If we are running asynchronously, and the target supports async
5740 execution, we are not waiting for the target to stop, in the call
5741 tp proceed, below. This means that we cannot delete the
5742 brekpoints until the target has actually stopped. The only place
5743 where we get a chance to do that is in fetch_inferior_event, so
5744 we must set things up for that. */
5746 if (event_loop_p && target_can_async_p ())
5748 /* In this case the arg for the continuation is just the point
5749 in the exec_cleanups chain from where to start doing
5750 cleanups, because all the continuation does is the cleanups in
5751 the exec_cleanup_chain. */
5753 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5755 arg1->data = (PTR) old_chain;
5757 add_continuation (until_break_command_continuation, arg1);
5760 /* Keep within the current frame */
5764 sal = find_pc_line (prev_frame->pc, 0);
5765 sal.pc = prev_frame->pc;
5766 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5767 if (!event_loop_p || !target_can_async_p ())
5768 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5770 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5773 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5774 /* Do the cleanups now, anly if we are not running asynchronously,
5775 of if we are, but the target is still synchronous. */
5776 if (!event_loop_p || !target_can_async_p ())
5777 do_cleanups (old_chain);
5781 /* These aren't used; I don't konw what they were for. */
5782 /* Set a breakpoint at the catch clause for NAME. */
5784 catch_breakpoint (name)
5790 disable_catch_breakpoint ()
5795 delete_catch_breakpoint ()
5800 enable_catch_breakpoint ()
5807 struct sal_chain *next;
5808 struct symtab_and_line sal;
5812 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5813 had been commented out in the v.4.16 sources, and stays
5814 disabled there now because "catch NAME" syntax isn't allowed.
5816 /* This isn't used; I don't know what it was for. */
5817 /* For each catch clause identified in ARGS, run FUNCTION
5818 with that clause as an argument. */
5819 static struct symtabs_and_lines
5820 map_catch_names (args, function)
5824 register char *p = args;
5826 struct symtabs_and_lines sals;
5828 struct sal_chain *sal_chain = 0;
5832 error_no_arg ("one or more catch names");
5840 /* Don't swallow conditional part. */
5841 if (p1[0] == 'i' && p1[1] == 'f'
5842 && (p1[2] == ' ' || p1[2] == '\t'))
5848 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5852 if (*p1 && *p1 != ' ' && *p1 != '\t')
5853 error ("Arguments must be catch names.");
5859 struct sal_chain *next = (struct sal_chain *)
5860 alloca (sizeof (struct sal_chain));
5861 next->next = sal_chain;
5862 next->sal = get_catch_sal (p);
5867 printf_unfiltered ("No catch clause for exception %s.\n", p);
5872 while (*p == ' ' || *p == '\t')
5878 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5880 static struct symtabs_and_lines
5881 get_catch_sals (this_level_only)
5882 int this_level_only;
5884 register struct blockvector *bl;
5885 register struct block *block;
5886 int index, have_default = 0;
5888 struct symtabs_and_lines sals;
5889 struct sal_chain *sal_chain = 0;
5890 char *blocks_searched;
5892 /* Not sure whether an error message is always the correct response,
5893 but it's better than a core dump. */
5894 if (selected_frame == NULL)
5895 error ("No selected frame.");
5896 block = get_frame_block (selected_frame);
5897 pc = selected_frame->pc;
5903 error ("No symbol table info available.\n");
5905 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5906 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5907 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5911 CORE_ADDR end = BLOCK_END (block) - 4;
5914 if (bl != blockvector_for_pc (end, &index))
5915 error ("blockvector blotch");
5916 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5917 error ("blockvector botch");
5918 last_index = BLOCKVECTOR_NBLOCKS (bl);
5921 /* Don't print out blocks that have gone by. */
5922 while (index < last_index
5923 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5926 while (index < last_index
5927 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5929 if (blocks_searched[index] == 0)
5931 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5934 register struct symbol *sym;
5936 nsyms = BLOCK_NSYMS (b);
5938 for (i = 0; i < nsyms; i++)
5940 sym = BLOCK_SYM (b, i);
5941 if (STREQ (SYMBOL_NAME (sym), "default"))
5947 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5949 struct sal_chain *next = (struct sal_chain *)
5950 alloca (sizeof (struct sal_chain));
5951 next->next = sal_chain;
5952 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5957 blocks_searched[index] = 1;
5963 if (sal_chain && this_level_only)
5966 /* After handling the function's top-level block, stop.
5967 Don't continue to its superblock, the block of
5968 per-file symbols. */
5969 if (BLOCK_FUNCTION (block))
5971 block = BLOCK_SUPERBLOCK (block);
5976 struct sal_chain *tmp_chain;
5978 /* Count the number of entries. */
5979 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5980 tmp_chain = tmp_chain->next)
5984 sals.sals = (struct symtab_and_line *)
5985 xmalloc (index * sizeof (struct symtab_and_line));
5986 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5987 sals.sals[index] = sal_chain->sal;
5994 ep_skip_leading_whitespace (s)
5997 if ((s == NULL) || (*s == NULL))
5999 while (isspace (**s))
6003 /* This function examines a string, and attempts to find a token
6004 that might be an event name in the leading characters. If a
6005 possible match is found, a pointer to the last character of
6006 the token is returned. Else, NULL is returned. */
6009 ep_find_event_name_end (arg)
6013 char *event_name_end = NULL;
6015 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6019 /* We break out of the loop when we find a token delimiter.
6020 Basically, we're looking for alphanumerics and underscores;
6021 anything else delimites the token. */
6024 if (!isalnum (*s) && (*s != '_'))
6030 return event_name_end;
6034 /* This function attempts to parse an optional "if <cond>" clause
6035 from the arg string. If one is not found, it returns NULL.
6037 Else, it returns a pointer to the condition string. (It does not
6038 attempt to evaluate the string against a particular block.) And,
6039 it updates arg to point to the first character following the parsed
6040 if clause in the arg string. */
6043 ep_parse_optional_if_clause (arg)
6048 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6051 /* Skip the "if" keyword. */
6054 /* Skip any extra leading whitespace, and record the start of the
6055 condition string. */
6056 ep_skip_leading_whitespace (arg);
6059 /* Assume that the condition occupies the remainder of the arg string. */
6060 (*arg) += strlen (cond_string);
6065 /* This function attempts to parse an optional filename from the arg
6066 string. If one is not found, it returns NULL.
6068 Else, it returns a pointer to the parsed filename. (This function
6069 makes no attempt to verify that a file of that name exists, or is
6070 accessible.) And, it updates arg to point to the first character
6071 following the parsed filename in the arg string.
6073 Note that clients needing to preserve the returned filename for
6074 future access should copy it to their own buffers. */
6076 ep_parse_optional_filename (arg)
6079 static char filename[1024];
6084 if ((*arg_p == '\0') || isspace (*arg_p))
6102 /* Commands to deal with catching events, such as signals, exceptions,
6103 process start/exit, etc. */
6107 catch_fork, catch_vfork
6111 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
6112 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
6118 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
6119 catch_fork_kind fork_kind;
6124 char *cond_string = NULL;
6126 ep_skip_leading_whitespace (&arg);
6128 /* The allowed syntax is:
6130 catch [v]fork if <cond>
6132 First, check if there's an if clause. */
6133 cond_string = ep_parse_optional_if_clause (&arg);
6135 if ((*arg != '\0') && !isspace (*arg))
6136 error ("Junk at end of arguments.");
6138 /* If this target supports it, create a fork or vfork catchpoint
6139 and enable reporting of such events. */
6143 create_fork_event_catchpoint (tempflag, cond_string);
6146 create_vfork_event_catchpoint (tempflag, cond_string);
6149 error ("unsupported or unknown fork kind; cannot catch it");
6155 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6157 catch_exec_command_1 (arg, tempflag, from_tty)
6162 char *cond_string = NULL;
6164 ep_skip_leading_whitespace (&arg);
6166 /* The allowed syntax is:
6168 catch exec if <cond>
6170 First, check if there's an if clause. */
6171 cond_string = ep_parse_optional_if_clause (&arg);
6173 if ((*arg != '\0') && !isspace (*arg))
6174 error ("Junk at end of arguments.");
6176 /* If this target supports it, create an exec catchpoint
6177 and enable reporting of such events. */
6178 create_exec_event_catchpoint (tempflag, cond_string);
6182 #if defined(SOLIB_ADD)
6184 catch_load_command_1 (arg, tempflag, from_tty)
6189 char *dll_pathname = NULL;
6190 char *cond_string = NULL;
6192 ep_skip_leading_whitespace (&arg);
6194 /* The allowed syntax is:
6196 catch load if <cond>
6197 catch load <filename>
6198 catch load <filename> if <cond>
6200 The user is not allowed to specify the <filename> after an
6203 We'll ignore the pathological case of a file named "if".
6205 First, check if there's an if clause. If so, then there
6206 cannot be a filename. */
6207 cond_string = ep_parse_optional_if_clause (&arg);
6209 /* If there was an if clause, then there cannot be a filename.
6210 Else, there might be a filename and an if clause. */
6211 if (cond_string == NULL)
6213 dll_pathname = ep_parse_optional_filename (&arg);
6214 ep_skip_leading_whitespace (&arg);
6215 cond_string = ep_parse_optional_if_clause (&arg);
6218 if ((*arg != '\0') && !isspace (*arg))
6219 error ("Junk at end of arguments.");
6221 /* Create a load breakpoint that only triggers when a load of
6222 the specified dll (or any dll, if no pathname was specified)
6224 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
6225 dll_pathname, cond_string);
6229 catch_unload_command_1 (arg, tempflag, from_tty)
6234 char *dll_pathname = NULL;
6235 char *cond_string = NULL;
6237 ep_skip_leading_whitespace (&arg);
6239 /* The allowed syntax is:
6241 catch unload if <cond>
6242 catch unload <filename>
6243 catch unload <filename> if <cond>
6245 The user is not allowed to specify the <filename> after an
6248 We'll ignore the pathological case of a file named "if".
6250 First, check if there's an if clause. If so, then there
6251 cannot be a filename. */
6252 cond_string = ep_parse_optional_if_clause (&arg);
6254 /* If there was an if clause, then there cannot be a filename.
6255 Else, there might be a filename and an if clause. */
6256 if (cond_string == NULL)
6258 dll_pathname = ep_parse_optional_filename (&arg);
6259 ep_skip_leading_whitespace (&arg);
6260 cond_string = ep_parse_optional_if_clause (&arg);
6263 if ((*arg != '\0') && !isspace (*arg))
6264 error ("Junk at end of arguments.");
6266 /* Create an unload breakpoint that only triggers when an unload of
6267 the specified dll (or any dll, if no pathname was specified)
6269 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
6270 dll_pathname, cond_string);
6272 #endif /* SOLIB_ADD */
6274 /* Commands to deal with catching exceptions. */
6276 /* Set a breakpoint at the specified callback routine for an
6277 exception event callback */
6280 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
6283 enum exception_event_kind ex_event;
6284 struct symtab_and_line *sal;
6286 struct breakpoint *b;
6287 int thread = -1; /* All threads. */
6289 if (!sal) /* no exception support? */
6292 b = set_raw_breakpoint (*sal);
6293 set_breakpoint_count (breakpoint_count + 1);
6294 b->number = breakpoint_count;
6296 b->cond_string = (cond_string == NULL) ?
6297 NULL : savestring (cond_string, strlen (cond_string));
6299 b->addr_string = NULL;
6300 b->enable = enabled;
6301 b->disposition = tempflag ? del : donttouch;
6304 case EX_EVENT_THROW:
6305 b->type = bp_catch_throw;
6307 case EX_EVENT_CATCH:
6308 b->type = bp_catch_catch;
6310 default: /* error condition */
6312 b->enable = disabled;
6313 error ("Internal error -- invalid catchpoint kind");
6318 /* Deal with "catch catch" and "catch throw" commands */
6321 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
6322 enum exception_event_kind ex_event;
6327 char *cond_string = NULL;
6328 struct symtab_and_line *sal = NULL;
6330 ep_skip_leading_whitespace (&arg);
6332 cond_string = ep_parse_optional_if_clause (&arg);
6334 if ((*arg != '\0') && !isspace (*arg))
6335 error ("Junk at end of arguments.");
6337 if ((ex_event != EX_EVENT_THROW) &&
6338 (ex_event != EX_EVENT_CATCH))
6339 error ("Unsupported or unknown exception event; cannot catch it");
6341 /* See if we can find a callback routine */
6342 sal = target_enable_exception_callback (ex_event, 1);
6346 /* We have callbacks from the runtime system for exceptions.
6347 Set a breakpoint on the sal found, if no errors */
6348 if (sal != (struct symtab_and_line *) -1)
6349 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6351 return; /* something went wrong with setting up callbacks */
6355 /* No callbacks from runtime system for exceptions.
6356 Try GNU C++ exception breakpoints using labels in debug info. */
6357 if (ex_event == EX_EVENT_CATCH)
6359 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6361 else if (ex_event == EX_EVENT_THROW)
6363 /* Set a breakpoint on __raise_exception () */
6365 warning ("Unsupported with this platform/compiler combination.");
6366 warning ("Perhaps you can achieve the effect you want by setting");
6367 warning ("a breakpoint on __raise_exception().");
6372 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6373 inside a catch_errors */
6376 cover_target_enable_exception_callback (arg)
6379 args_for_catchpoint_enable *args = arg;
6380 struct symtab_and_line *sal;
6381 sal = target_enable_exception_callback (args->kind, args->enable);
6384 else if (sal == (struct symtab_and_line *) -1)
6387 return 1; /*is valid */
6392 /* This is the original v.4.16 and earlier version of the
6393 catch_command_1() function. Now that other flavours of "catch"
6394 have been introduced, and since exception handling can be handled
6395 in other ways (through target ops) also, this is used only for the
6396 GNU C++ exception handling system.
6397 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6398 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6399 there was no code in GDB 4.16 for "catch throw".
6401 Called from catch_exception_command_1 () */
6405 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
6410 /* First, translate ARG into something we can deal with in terms
6413 struct symtabs_and_lines sals;
6414 struct symtab_and_line sal;
6415 register struct expression *cond = 0;
6416 register struct breakpoint *b;
6420 INIT_SAL (&sal); /* initialize to zeroes */
6422 /* If no arg given, or if first arg is 'if ', all active catch clauses
6423 are breakpointed. */
6425 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6426 && (arg[2] == ' ' || arg[2] == '\t')))
6428 /* Grab all active catch clauses. */
6429 sals = get_catch_sals (0);
6433 /* Grab selected catch clauses. */
6434 error ("catch NAME not implemented");
6437 /* Not sure why this code has been disabled. I'm leaving
6438 it disabled. We can never come here now anyway
6439 since we don't allow the "catch NAME" syntax.
6442 /* This isn't used; I don't know what it was for. */
6443 sals = map_catch_names (arg, catch_breakpoint);
6451 for (i = 0; i < sals.nelts; i++)
6453 resolve_sal_pc (&sals.sals[i]);
6457 if (arg[0] == 'i' && arg[1] == 'f'
6458 && (arg[2] == ' ' || arg[2] == '\t'))
6459 cond = parse_exp_1 ((arg += 2, &arg),
6460 block_for_pc (sals.sals[i].pc), 0);
6462 error ("Junk at end of arguments.");
6467 for (i = 0; i < sals.nelts; i++)
6472 describe_other_breakpoints (sal.pc, sal.section);
6474 b = set_raw_breakpoint (sal);
6475 set_breakpoint_count (breakpoint_count + 1);
6476 b->number = breakpoint_count;
6478 /* Important -- this is an ordinary breakpoint. For platforms
6479 with callback support for exceptions,
6480 create_exception_catchpoint() will create special bp types
6481 (bp_catch_catch and bp_catch_throw), and there is code in
6482 insert_breakpoints() and elsewhere that depends on that. */
6483 b->type = bp_breakpoint;
6486 b->enable = enabled;
6487 b->disposition = tempflag ? del : donttouch;
6494 warning ("Multiple breakpoints were set.");
6495 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6497 free ((PTR) sals.sals);
6501 /* This creates a temporary internal breakpoint
6502 just to placate infrun */
6503 static struct breakpoint *
6504 create_temp_exception_breakpoint (pc)
6507 struct symtab_and_line sal;
6508 struct breakpoint *b;
6515 b = set_raw_breakpoint (sal);
6517 error ("Internal error -- couldn't set temp exception breakpoint");
6519 b->type = bp_breakpoint;
6520 b->disposition = del;
6521 b->enable = enabled;
6523 b->number = internal_breakpoint_number--;
6529 catch_command_1 (arg, tempflag, from_tty)
6535 /* The first argument may be an event name, such as "start" or "load".
6536 If so, then handle it as such. If it doesn't match an event name,
6537 then attempt to interpret it as an exception name. (This latter is
6538 the v4.16-and-earlier GDB meaning of the "catch" command.)
6540 First, try to find the bounds of what might be an event name. */
6541 char *arg1_start = arg;
6545 if (arg1_start == NULL)
6547 /* Old behaviour was to use pre-v-4.16 syntax */
6548 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6550 /* Now, this is not allowed */
6551 error ("Catch requires an event name.");
6554 arg1_end = ep_find_event_name_end (arg1_start);
6555 if (arg1_end == NULL)
6556 error ("catch requires an event");
6557 arg1_length = arg1_end + 1 - arg1_start;
6559 /* Try to match what we found against known event names. */
6560 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6562 error ("Catch of signal not yet implemented");
6564 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6566 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6567 tempflag, from_tty);
6569 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6571 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6572 tempflag, from_tty);
6574 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6576 error ("Catch of thread_start not yet implemented");
6578 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6580 error ("Catch of thread_exit not yet implemented");
6582 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6584 error ("Catch of thread_join not yet implemented");
6586 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6588 error ("Catch of start not yet implemented");
6590 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6592 error ("Catch of exit not yet implemented");
6594 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6596 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6597 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6599 error ("Catch of fork not yet implemented");
6602 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6604 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6605 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6607 error ("Catch of vfork not yet implemented");
6610 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6612 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6613 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6615 error ("Catch of exec not yet implemented");
6618 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6620 #if defined(SOLIB_ADD)
6621 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6623 error ("Catch of load not implemented");
6626 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6628 #if defined(SOLIB_ADD)
6629 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6631 error ("Catch of load not implemented");
6634 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6636 error ("Catch of stop not yet implemented");
6639 /* This doesn't appear to be an event name */
6643 /* Pre-v.4.16 behaviour was to treat the argument
6644 as the name of an exception */
6645 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6646 /* Now this is not allowed */
6647 error ("Unknown event kind specified for catch");
6652 /* Used by the gui, could be made a worker for other things. */
6655 set_breakpoint_sal (sal)
6656 struct symtab_and_line sal;
6658 struct breakpoint *b;
6659 b = set_raw_breakpoint (sal);
6660 set_breakpoint_count (breakpoint_count + 1);
6661 b->number = breakpoint_count;
6662 b->type = bp_breakpoint;
6669 /* These aren't used; I don't know what they were for. */
6670 /* Disable breakpoints on all catch clauses described in ARGS. */
6672 disable_catch (args)
6675 /* Map the disable command to catch clauses described in ARGS. */
6678 /* Enable breakpoints on all catch clauses described in ARGS. */
6683 /* Map the disable command to catch clauses described in ARGS. */
6686 /* Delete breakpoints on all catch clauses in the active scope. */
6691 /* Map the delete command to catch clauses described in ARGS. */
6696 catch_command (arg, from_tty)
6700 catch_command_1 (arg, 0, from_tty);
6705 tcatch_command (arg, from_tty)
6709 catch_command_1 (arg, 1, from_tty);
6714 clear_command (arg, from_tty)
6718 register struct breakpoint *b, *b1;
6720 struct symtabs_and_lines sals;
6721 struct symtab_and_line sal;
6722 register struct breakpoint *found;
6727 sals = decode_line_spec (arg, 1);
6732 sals.sals = (struct symtab_and_line *)
6733 xmalloc (sizeof (struct symtab_and_line));
6734 INIT_SAL (&sal); /* initialize to zeroes */
6735 sal.line = default_breakpoint_line;
6736 sal.symtab = default_breakpoint_symtab;
6737 sal.pc = default_breakpoint_address;
6738 if (sal.symtab == 0)
6739 error ("No source file specified.");
6747 /* For each line spec given, delete bps which correspond
6748 to it. We do this in two loops: the first loop looks at
6749 the initial bp(s) in the chain which should be deleted,
6750 the second goes down the rest of the chain looking ahead
6751 one so it can take those bps off the chain without messing
6755 for (i = 0; i < sals.nelts; i++)
6757 /* If exact pc given, clear bpts at that pc.
6758 If line given (pc == 0), clear all bpts on specified line.
6759 If defaulting, clear all bpts on default line
6762 defaulting sal.pc != 0 tests to do
6767 1 0 <can't happen> */
6770 found = (struct breakpoint *) 0;
6773 while (breakpoint_chain
6774 /* Why don't we check here that this is not
6775 a watchpoint, etc., as we do below?
6776 I can't make it fail, but don't know
6777 what's stopping the failure: a watchpoint
6778 of the same address as "sal.pc" should
6779 wind up being deleted. */
6781 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6782 (overlay_debugging == 0 ||
6783 breakpoint_chain->section == sal.section))
6784 || ((default_match || (0 == sal.pc))
6785 && breakpoint_chain->source_file != NULL
6786 && sal.symtab != NULL
6787 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6788 && breakpoint_chain->line_number == sal.line)))
6791 b1 = breakpoint_chain;
6792 breakpoint_chain = b1->next;
6800 && b->next->type != bp_none
6801 && b->next->type != bp_watchpoint
6802 && b->next->type != bp_hardware_watchpoint
6803 && b->next->type != bp_read_watchpoint
6804 && b->next->type != bp_access_watchpoint
6805 && (((sal.pc && (b->next->address == sal.pc)) &&
6806 (overlay_debugging == 0 ||
6807 b->next->section == sal.section))
6808 || ((default_match || (0 == sal.pc))
6809 && b->next->source_file != NULL
6810 && sal.symtab != NULL
6811 && STREQ (b->next->source_file, sal.symtab->filename)
6812 && b->next->line_number == sal.line)))
6825 error ("No breakpoint at %s.", arg);
6827 error ("No breakpoint at this line.");
6831 from_tty = 1; /* Always report if deleted more than one */
6833 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6834 breakpoints_changed ();
6838 printf_unfiltered ("%d ", found->number);
6840 delete_breakpoint (found);
6844 putchar_unfiltered ('\n');
6846 free ((PTR) sals.sals);
6849 /* Delete breakpoint in BS if they are `delete' breakpoints and
6850 all breakpoints that are marked for deletion, whether hit or not.
6851 This is called after any breakpoint is hit, or after errors. */
6854 breakpoint_auto_delete (bs)
6857 struct breakpoint *b, *temp;
6859 for (; bs; bs = bs->next)
6860 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6862 delete_breakpoint (bs->breakpoint_at);
6864 ALL_BREAKPOINTS_SAFE (b, temp)
6866 if (b->disposition == del_at_next_stop)
6867 delete_breakpoint (b);
6871 /* Delete a breakpoint and clean up all traces of it in the data
6875 delete_breakpoint (bpt)
6876 struct breakpoint *bpt;
6878 register struct breakpoint *b;
6882 error ("Internal error (attempted to delete a NULL breakpoint)");
6885 /* Has this bp already been deleted? This can happen because multiple
6886 lists can hold pointers to bp's. bpstat lists are especial culprits.
6888 One example of this happening is a watchpoint's scope bp. When the
6889 scope bp triggers, we notice that the watchpoint is out of scope, and
6890 delete it. We also delete its scope bp. But the scope bp is marked
6891 "auto-deleting", and is already on a bpstat. That bpstat is then
6892 checked for auto-deleting bp's, which are deleted.
6894 A real solution to this problem might involve reference counts in bp's,
6895 and/or giving them pointers back to their referencing bpstat's, and
6896 teaching delete_breakpoint to only free a bp's storage when no more
6897 references were extent. A cheaper bandaid was chosen. */
6898 if (bpt->type == bp_none)
6901 if (delete_breakpoint_hook)
6902 delete_breakpoint_hook (bpt);
6903 breakpoint_delete_event (bpt->number);
6906 remove_breakpoint (bpt, mark_uninserted);
6908 if (breakpoint_chain == bpt)
6909 breakpoint_chain = bpt->next;
6911 /* If we have callback-style exception catchpoints, don't go through
6912 the adjustments to the C++ runtime library etc. if the inferior
6913 isn't actually running. target_enable_exception_callback for a
6914 null target ops vector gives an undesirable error message, so we
6915 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6916 exceptions are supported in this way, it's OK for now. FIXME */
6917 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6919 static char message1[] = "Error in deleting catchpoint %d:\n";
6920 static char message[sizeof (message1) + 30];
6921 args_for_catchpoint_enable args;
6923 /* Format possible error msg */
6924 sprintf (message, message1, bpt->number);
6925 args.kind = bpt->type == bp_catch_catch ?
6926 EX_EVENT_CATCH : EX_EVENT_THROW;
6928 catch_errors (cover_target_enable_exception_callback, &args,
6929 message, RETURN_MASK_ALL);
6936 b->next = bpt->next;
6940 /* Before turning off the visuals for the bp, check to see that
6941 there are no other bps at the same address. */
6948 clearIt = (b->address != bpt->address);
6955 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6956 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6960 check_duplicates (bpt->address, bpt->section);
6961 /* If this breakpoint was inserted, and there is another breakpoint
6962 at the same address, we need to insert the other breakpoint. */
6964 && bpt->type != bp_hardware_watchpoint
6965 && bpt->type != bp_read_watchpoint
6966 && bpt->type != bp_access_watchpoint
6967 && bpt->type != bp_catch_fork
6968 && bpt->type != bp_catch_vfork
6969 && bpt->type != bp_catch_exec)
6972 if (b->address == bpt->address
6973 && b->section == bpt->section
6975 && b->enable != disabled
6976 && b->enable != shlib_disabled
6977 && b->enable != call_disabled)
6981 /* We should never reach this point if there is a permanent
6982 breakpoint at the same address as the one being deleted.
6983 If there is a permanent breakpoint somewhere, it should
6984 always be the only one inserted. */
6985 if (b->enable == permanent)
6986 internal_error ("another breakpoint was inserted on top of "
6987 "a permanent breakpoint");
6989 if (b->type == bp_hardware_breakpoint)
6990 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6992 val = target_insert_breakpoint (b->address, b->shadow_contents);
6996 target_terminal_ours_for_output ();
6997 warning ("Cannot insert breakpoint %d:", b->number);
6998 memory_error (val, b->address); /* which bombs us out */
7005 free_command_lines (&bpt->commands);
7008 if (bpt->cond_string != NULL)
7009 free (bpt->cond_string);
7010 if (bpt->addr_string != NULL)
7011 free (bpt->addr_string);
7012 if (bpt->exp != NULL)
7014 if (bpt->exp_string != NULL)
7015 free (bpt->exp_string);
7016 if (bpt->val != NULL)
7017 value_free (bpt->val);
7018 if (bpt->source_file != NULL)
7019 free (bpt->source_file);
7020 if (bpt->dll_pathname != NULL)
7021 free (bpt->dll_pathname);
7022 if (bpt->triggered_dll_pathname != NULL)
7023 free (bpt->triggered_dll_pathname);
7024 if (bpt->exec_pathname != NULL)
7025 free (bpt->exec_pathname);
7027 /* Be sure no bpstat's are pointing at it after it's been freed. */
7028 /* FIXME, how can we find all bpstat's?
7029 We just check stop_bpstat for now. */
7030 for (bs = stop_bpstat; bs; bs = bs->next)
7031 if (bs->breakpoint_at == bpt)
7033 bs->breakpoint_at = NULL;
7035 /* we'd call bpstat_clear_actions, but that free's stuff and due
7036 to the multiple pointers pointing to one item with no
7037 reference counts found anywhere through out the bpstat's (how
7038 do you spell fragile?), we don't want to free things twice --
7039 better a memory leak than a corrupt malloc pool! */
7040 bs->commands = NULL;
7043 /* On the chance that someone will soon try again to delete this same
7044 bp, we mark it as deleted before freeing its storage. */
7045 bpt->type = bp_none;
7051 delete_command (arg, from_tty)
7055 struct breakpoint *b, *temp;
7059 int breaks_to_delete = 0;
7061 /* Delete all breakpoints if no argument.
7062 Do not delete internal or call-dummy breakpoints, these
7063 have to be deleted with an explicit breakpoint number argument. */
7066 if (b->type != bp_call_dummy &&
7067 b->type != bp_shlib_event &&
7068 b->type != bp_thread_event &&
7070 breaks_to_delete = 1;
7073 /* Ask user only if there are some breakpoints to delete. */
7075 || (breaks_to_delete && query ("Delete all breakpoints? ")))
7077 ALL_BREAKPOINTS_SAFE (b, temp)
7079 if (b->type != bp_call_dummy &&
7080 b->type != bp_shlib_event &&
7081 b->type != bp_thread_event &&
7083 delete_breakpoint (b);
7088 map_breakpoint_numbers (arg, delete_breakpoint);
7091 /* Reset a breakpoint given it's struct breakpoint * BINT.
7092 The value we return ends up being the return value from catch_errors.
7093 Unused in this case. */
7096 breakpoint_re_set_one (bint)
7099 /* get past catch_errs */
7100 struct breakpoint *b = (struct breakpoint *) bint;
7103 struct symtabs_and_lines sals;
7105 enum enable save_enable;
7110 warning ("attempted to reset apparently deleted breakpoint #%d?",
7114 case bp_hardware_breakpoint:
7116 case bp_catch_unload:
7117 if (b->addr_string == NULL)
7119 /* Anything without a string can't be re-set. */
7120 delete_breakpoint (b);
7123 /* In case we have a problem, disable this breakpoint. We'll restore
7124 its status if we succeed. */
7125 save_enable = b->enable;
7126 b->enable = disabled;
7128 set_language (b->language);
7129 input_radix = b->input_radix;
7131 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
7132 for (i = 0; i < sals.nelts; i++)
7134 resolve_sal_pc (&sals.sals[i]);
7136 /* Reparse conditions, they might contain references to the
7138 if (b->cond_string != NULL)
7142 free ((PTR) b->cond);
7143 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7146 /* We need to re-set the breakpoint if the address changes... */
7147 if (b->address != sals.sals[i].pc
7148 /* ...or new and old breakpoints both have source files, and
7149 the source file name or the line number changes... */
7150 || (b->source_file != NULL
7151 && sals.sals[i].symtab != NULL
7152 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
7153 || b->line_number != sals.sals[i].line)
7155 /* ...or we switch between having a source file and not having
7157 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7160 if (b->source_file != NULL)
7161 free (b->source_file);
7162 if (sals.sals[i].symtab == NULL)
7163 b->source_file = NULL;
7166 savestring (sals.sals[i].symtab->filename,
7167 strlen (sals.sals[i].symtab->filename));
7168 b->line_number = sals.sals[i].line;
7169 b->address = sals.sals[i].pc;
7171 /* Used to check for duplicates here, but that can
7172 cause trouble, as it doesn't check for disable
7177 /* Might be better to do this just once per breakpoint_re_set,
7178 rather than once for every breakpoint. */
7179 breakpoints_changed ();
7181 b->section = sals.sals[i].section;
7182 b->enable = save_enable; /* Restore it, this worked. */
7185 /* Now that this is re-enabled, check_duplicates
7187 check_duplicates (b->address, b->section);
7190 free ((PTR) sals.sals);
7194 case bp_hardware_watchpoint:
7195 case bp_read_watchpoint:
7196 case bp_access_watchpoint:
7197 innermost_block = NULL;
7198 /* The issue arises of what context to evaluate this in. The
7199 same one as when it was set, but what does that mean when
7200 symbols have been re-read? We could save the filename and
7201 functionname, but if the context is more local than that, the
7202 best we could do would be something like how many levels deep
7203 and which index at that particular level, but that's going to
7204 be less stable than filenames or function names. */
7206 /* So for now, just use a global context. */
7208 free ((PTR) b->exp);
7209 b->exp = parse_expression (b->exp_string);
7210 b->exp_valid_block = innermost_block;
7211 mark = value_mark ();
7213 value_free (b->val);
7214 b->val = evaluate_expression (b->exp);
7215 release_value (b->val);
7216 if (VALUE_LAZY (b->val))
7217 value_fetch_lazy (b->val);
7219 if (b->cond_string != NULL)
7223 free ((PTR) b->cond);
7224 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7226 if (b->enable == enabled)
7228 value_free_to_mark (mark);
7230 case bp_catch_catch:
7231 case bp_catch_throw:
7233 /* We needn't really do anything to reset these, since the mask
7234 that requests them is unaffected by e.g., new libraries being
7237 case bp_catch_vfork:
7242 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7244 /* Delete longjmp breakpoints, they will be reset later by
7245 breakpoint_re_set. */
7247 case bp_longjmp_resume:
7248 delete_breakpoint (b);
7251 /* This breakpoint is special, it's set up when the inferior
7252 starts and we really don't want to touch it. */
7253 case bp_shlib_event:
7255 /* Like bp_shlib_event, this breakpoint type is special.
7256 Once it is set up, we do not want to touch it. */
7257 case bp_thread_event:
7259 /* Keep temporary breakpoints, which can be encountered when we step
7260 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7261 Otherwise these should have been blown away via the cleanup chain
7262 or by breakpoint_init_inferior when we rerun the executable. */
7265 case bp_watchpoint_scope:
7267 case bp_step_resume:
7274 /* Re-set all breakpoints after symbols have been re-loaded. */
7276 breakpoint_re_set ()
7278 struct breakpoint *b, *temp;
7279 enum language save_language;
7280 int save_input_radix;
7281 static char message1[] = "Error in re-setting breakpoint %d:\n";
7282 char message[sizeof (message1) + 30 /* slop */ ];
7284 save_language = current_language->la_language;
7285 save_input_radix = input_radix;
7286 ALL_BREAKPOINTS_SAFE (b, temp)
7288 /* Format possible error msg */
7289 sprintf (message, message1, b->number);
7290 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7292 set_language (save_language);
7293 input_radix = save_input_radix;
7295 #ifdef GET_LONGJMP_TARGET
7296 create_longjmp_breakpoint ("longjmp");
7297 create_longjmp_breakpoint ("_longjmp");
7298 create_longjmp_breakpoint ("siglongjmp");
7299 create_longjmp_breakpoint ("_siglongjmp");
7300 create_longjmp_breakpoint (NULL);
7304 /* Took this out (temporarily at least), since it produces an extra
7305 blank line at startup. This messes up the gdbtests. -PB */
7306 /* Blank line to finish off all those mention() messages we just printed. */
7307 printf_filtered ("\n");
7311 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7312 If from_tty is nonzero, it prints a message to that effect,
7313 which ends with a period (no newline). */
7315 /* Reset the thread number of this breakpoint:
7317 - If the breakpoint is for all threads, leave it as-is.
7318 - Else, reset it to the current thread for inferior_pid. */
7320 breakpoint_re_set_thread (b)
7321 struct breakpoint *b;
7323 if (b->thread != -1)
7325 if (in_thread_list (inferior_pid))
7326 b->thread = pid_to_thread_id (inferior_pid);
7331 set_ignore_count (bptnum, count, from_tty)
7332 int bptnum, count, from_tty;
7334 register struct breakpoint *b;
7340 if (b->number == bptnum)
7342 b->ignore_count = count;
7345 else if (count == 0)
7346 printf_filtered ("Will stop next time breakpoint %d is reached.",
7348 else if (count == 1)
7349 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7352 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7354 breakpoints_changed ();
7358 error ("No breakpoint number %d.", bptnum);
7361 /* Clear the ignore counts of all breakpoints. */
7363 breakpoint_clear_ignore_counts ()
7365 struct breakpoint *b;
7368 b->ignore_count = 0;
7371 /* Command to set ignore-count of breakpoint N to COUNT. */
7374 ignore_command (args, from_tty)
7382 error_no_arg ("a breakpoint number");
7384 num = get_number (&p);
7386 error ("bad breakpoint number: '%s'", args);
7388 error ("Second argument (specified ignore-count) is missing.");
7390 set_ignore_count (num,
7391 longest_to_int (value_as_long (parse_and_eval (p))),
7393 printf_filtered ("\n");
7394 breakpoints_changed ();
7397 /* Call FUNCTION on each of the breakpoints
7398 whose numbers are given in ARGS. */
7401 map_breakpoint_numbers (args, function)
7403 void (*function) PARAMS ((struct breakpoint *));
7405 register char *p = args;
7408 register struct breakpoint *b, *tmp;
7412 error_no_arg ("one or more breakpoint numbers");
7419 num = get_number_or_range (&p1);
7422 warning ("bad breakpoint number at or near '%s'", p);
7426 ALL_BREAKPOINTS_SAFE (b, tmp)
7427 if (b->number == num)
7429 struct breakpoint *related_breakpoint = b->related_breakpoint;
7432 if (related_breakpoint)
7433 function (related_breakpoint);
7437 printf_unfiltered ("No breakpoint number %d.\n", num);
7444 disable_breakpoint (bpt)
7445 struct breakpoint *bpt;
7447 /* Never disable a watchpoint scope breakpoint; we want to
7448 hit them when we leave scope so we can delete both the
7449 watchpoint and its scope breakpoint at that time. */
7450 if (bpt->type == bp_watchpoint_scope)
7453 /* You can't disable permanent breakpoints. */
7454 if (bpt->enable == permanent)
7457 bpt->enable = disabled;
7459 check_duplicates (bpt->address, bpt->section);
7461 if (modify_breakpoint_hook)
7462 modify_breakpoint_hook (bpt);
7463 breakpoint_modify_event (bpt->number);
7468 disable_command (args, from_tty)
7472 register struct breakpoint *bpt;
7474 ALL_BREAKPOINTS (bpt)
7478 warning ("attempted to disable apparently deleted breakpoint #%d?",
7483 case bp_catch_unload:
7485 case bp_catch_vfork:
7487 case bp_catch_catch:
7488 case bp_catch_throw:
7489 case bp_hardware_breakpoint:
7491 case bp_hardware_watchpoint:
7492 case bp_read_watchpoint:
7493 case bp_access_watchpoint:
7494 disable_breakpoint (bpt);
7499 map_breakpoint_numbers (args, disable_breakpoint);
7503 do_enable_breakpoint (bpt, disposition)
7504 struct breakpoint *bpt;
7505 enum bpdisp disposition;
7507 struct frame_info *save_selected_frame = NULL;
7508 int save_selected_frame_level = -1;
7509 int target_resources_ok, other_type_used;
7512 if (bpt->type == bp_hardware_breakpoint)
7515 i = hw_breakpoint_used_count ();
7516 target_resources_ok =
7517 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7519 if (target_resources_ok == 0)
7520 error ("No hardware breakpoint support in the target.");
7521 else if (target_resources_ok < 0)
7522 error ("Hardware breakpoints used exceeds limit.");
7525 if (bpt->enable != permanent)
7526 bpt->enable = enabled;
7527 bpt->disposition = disposition;
7528 check_duplicates (bpt->address, bpt->section);
7529 breakpoints_changed ();
7531 if (bpt->type == bp_watchpoint ||
7532 bpt->type == bp_hardware_watchpoint ||
7533 bpt->type == bp_read_watchpoint ||
7534 bpt->type == bp_access_watchpoint)
7536 if (bpt->exp_valid_block != NULL)
7538 struct frame_info *fr =
7540 /* Ensure that we have the current frame. Else, this
7541 next query may pessimistically be answered as, "No,
7542 not within current scope". */
7543 get_current_frame ();
7544 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7548 Cannot enable watchpoint %d because the block in which its expression\n\
7549 is valid is not currently in scope.\n", bpt->number);
7550 bpt->enable = disabled;
7554 save_selected_frame = selected_frame;
7555 save_selected_frame_level = selected_frame_level;
7556 select_frame (fr, -1);
7559 value_free (bpt->val);
7560 mark = value_mark ();
7561 bpt->val = evaluate_expression (bpt->exp);
7562 release_value (bpt->val);
7563 if (VALUE_LAZY (bpt->val))
7564 value_fetch_lazy (bpt->val);
7566 if (bpt->type == bp_hardware_watchpoint ||
7567 bpt->type == bp_read_watchpoint ||
7568 bpt->type == bp_access_watchpoint)
7570 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7571 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7573 /* Hack around 'unused var' error for some targets here */
7575 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7576 bpt->type, i + mem_cnt, other_type_used);
7577 /* we can consider of type is bp_hardware_watchpoint, convert to
7578 bp_watchpoint in the following condition */
7579 if (target_resources_ok < 0)
7582 Cannot enable watchpoint %d because target watch resources\n\
7583 have been allocated for other watchpoints.\n", bpt->number);
7584 bpt->enable = disabled;
7585 value_free_to_mark (mark);
7590 if (save_selected_frame_level >= 0)
7591 select_frame (save_selected_frame, save_selected_frame_level);
7592 value_free_to_mark (mark);
7594 if (modify_breakpoint_hook)
7595 modify_breakpoint_hook (bpt);
7596 breakpoint_modify_event (bpt->number);
7600 enable_breakpoint (bpt)
7601 struct breakpoint *bpt;
7603 do_enable_breakpoint (bpt, bpt->disposition);
7606 /* The enable command enables the specified breakpoints (or all defined
7607 breakpoints) so they once again become (or continue to be) effective
7608 in stopping the inferior. */
7612 enable_command (args, from_tty)
7616 register struct breakpoint *bpt;
7618 ALL_BREAKPOINTS (bpt)
7622 warning ("attempted to enable apparently deleted breakpoint #%d?",
7627 case bp_catch_unload:
7629 case bp_catch_vfork:
7631 case bp_catch_catch:
7632 case bp_catch_throw:
7633 case bp_hardware_breakpoint:
7635 case bp_hardware_watchpoint:
7636 case bp_read_watchpoint:
7637 case bp_access_watchpoint:
7638 enable_breakpoint (bpt);
7643 map_breakpoint_numbers (args, enable_breakpoint);
7647 enable_once_breakpoint (bpt)
7648 struct breakpoint *bpt;
7650 do_enable_breakpoint (bpt, disable);
7655 enable_once_command (args, from_tty)
7659 map_breakpoint_numbers (args, enable_once_breakpoint);
7663 enable_delete_breakpoint (bpt)
7664 struct breakpoint *bpt;
7666 do_enable_breakpoint (bpt, del);
7671 enable_delete_command (args, from_tty)
7675 map_breakpoint_numbers (args, enable_delete_breakpoint);
7678 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7680 struct symtabs_and_lines
7681 decode_line_spec_1 (string, funfirstline)
7685 struct symtabs_and_lines sals;
7687 error ("Empty line specification.");
7688 if (default_breakpoint_valid)
7689 sals = decode_line_1 (&string, funfirstline,
7690 default_breakpoint_symtab,
7691 default_breakpoint_line,
7694 sals = decode_line_1 (&string, funfirstline,
7695 (struct symtab *) NULL, 0, (char ***) NULL);
7697 error ("Junk at end of line specification: %s", string);
7702 _initialize_breakpoint ()
7704 struct cmd_list_element *c;
7706 breakpoint_chain = 0;
7707 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7708 before a breakpoint is set. */
7709 breakpoint_count = 0;
7711 add_com ("ignore", class_breakpoint, ignore_command,
7712 "Set ignore-count of breakpoint number N to COUNT.\n\
7713 Usage is `ignore N COUNT'.");
7715 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7717 add_com ("commands", class_breakpoint, commands_command,
7718 "Set commands to be executed when a breakpoint is hit.\n\
7719 Give breakpoint number as argument after \"commands\".\n\
7720 With no argument, the targeted breakpoint is the last one set.\n\
7721 The commands themselves follow starting on the next line.\n\
7722 Type a line containing \"end\" to indicate the end of them.\n\
7723 Give \"silent\" as the first line to make the breakpoint silent;\n\
7724 then no output is printed when it is hit, except what the commands print.");
7726 add_com ("condition", class_breakpoint, condition_command,
7727 "Specify breakpoint number N to break only if COND is true.\n\
7728 Usage is `condition N COND', where N is an integer and COND is an\n\
7729 expression to be evaluated whenever breakpoint N is reached. ");
7731 add_com ("tbreak", class_breakpoint, tbreak_command,
7732 "Set a temporary breakpoint. Args like \"break\" command.\n\
7733 Like \"break\" except the breakpoint is only temporary,\n\
7734 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7735 by using \"enable delete\" on the breakpoint number.");
7736 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7737 "Set temporary breakpoint at procedure exit. Either there should\n\
7738 be no argument or the argument must be a depth.\n");
7740 add_com ("hbreak", class_breakpoint, hbreak_command,
7741 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7742 Like \"break\" except the breakpoint requires hardware support,\n\
7743 some target hardware may not have this support.");
7745 add_com ("thbreak", class_breakpoint, thbreak_command,
7746 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7747 Like \"hbreak\" except the breakpoint is only temporary,\n\
7748 so it will be deleted when hit.");
7750 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7751 "Enable some breakpoints.\n\
7752 Give breakpoint numbers (separated by spaces) as arguments.\n\
7753 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7754 This is used to cancel the effect of the \"disable\" command.\n\
7755 With a subcommand you can enable temporarily.",
7756 &enablelist, "enable ", 1, &cmdlist);
7758 add_com ("ab", class_breakpoint, enable_command,
7759 "Enable some breakpoints.\n\
7760 Give breakpoint numbers (separated by spaces) as arguments.\n\
7761 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7762 This is used to cancel the effect of the \"disable\" command.\n\
7763 With a subcommand you can enable temporarily.");
7765 add_com_alias ("en", "enable", class_breakpoint, 1);
7767 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7768 "Enable some breakpoints.\n\
7769 Give breakpoint numbers (separated by spaces) as arguments.\n\
7770 This is used to cancel the effect of the \"disable\" command.\n\
7771 May be abbreviated to simply \"enable\".\n",
7772 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7774 add_cmd ("once", no_class, enable_once_command,
7775 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7776 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7779 add_cmd ("delete", no_class, enable_delete_command,
7780 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7781 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7784 add_cmd ("delete", no_class, enable_delete_command,
7785 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7786 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7789 add_cmd ("once", no_class, enable_once_command,
7790 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7791 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7794 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7795 "Disable some breakpoints.\n\
7796 Arguments are breakpoint numbers with spaces in between.\n\
7797 To disable all breakpoints, give no argument.\n\
7798 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7799 &disablelist, "disable ", 1, &cmdlist);
7800 add_com_alias ("dis", "disable", class_breakpoint, 1);
7801 add_com_alias ("disa", "disable", class_breakpoint, 1);
7803 add_com ("sb", class_breakpoint, disable_command,
7804 "Disable some breakpoints.\n\
7805 Arguments are breakpoint numbers with spaces in between.\n\
7806 To disable all breakpoints, give no argument.\n\
7807 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7809 add_cmd ("breakpoints", class_alias, disable_command,
7810 "Disable some breakpoints.\n\
7811 Arguments are breakpoint numbers with spaces in between.\n\
7812 To disable all breakpoints, give no argument.\n\
7813 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7814 This command may be abbreviated \"disable\".",
7817 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7818 "Delete some breakpoints or auto-display expressions.\n\
7819 Arguments are breakpoint numbers with spaces in between.\n\
7820 To delete all breakpoints, give no argument.\n\
7822 Also a prefix command for deletion of other GDB objects.\n\
7823 The \"unset\" command is also an alias for \"delete\".",
7824 &deletelist, "delete ", 1, &cmdlist);
7825 add_com_alias ("d", "delete", class_breakpoint, 1);
7827 add_com ("db", class_breakpoint, delete_command,
7828 "Delete some breakpoints.\n\
7829 Arguments are breakpoint numbers with spaces in between.\n\
7830 To delete all breakpoints, give no argument.\n");
7832 add_cmd ("breakpoints", class_alias, delete_command,
7833 "Delete some breakpoints or auto-display expressions.\n\
7834 Arguments are breakpoint numbers with spaces in between.\n\
7835 To delete all breakpoints, give no argument.\n\
7836 This command may be abbreviated \"delete\".",
7839 add_com ("clear", class_breakpoint, clear_command,
7840 concat ("Clear breakpoint at specified line or function.\n\
7841 Argument may be line number, function name, or \"*\" and an address.\n\
7842 If line number is specified, all breakpoints in that line are cleared.\n\
7843 If function is specified, breakpoints at beginning of function are cleared.\n\
7844 If an address is specified, breakpoints at that address are cleared.\n\n",
7845 "With no argument, clears all breakpoints in the line that the selected frame\n\
7848 See also the \"delete\" command which clears breakpoints by number.", NULL));
7850 add_com ("break", class_breakpoint, break_command,
7851 concat ("Set breakpoint at specified line or function.\n\
7852 Argument may be line number, function name, or \"*\" and an address.\n\
7853 If line number is specified, break at start of code for that line.\n\
7854 If function is specified, break at start of code for that function.\n\
7855 If an address is specified, break at that exact address.\n",
7856 "With no arg, uses current execution address of selected stack frame.\n\
7857 This is useful for breaking on return to a stack frame.\n\
7859 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7861 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7862 add_com_alias ("b", "break", class_run, 1);
7863 add_com_alias ("br", "break", class_run, 1);
7864 add_com_alias ("bre", "break", class_run, 1);
7865 add_com_alias ("brea", "break", class_run, 1);
7867 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7868 concat ("Set breakpoint at procedure exit. \n\
7869 Argument may be function name, or \"*\" and an address.\n\
7870 If function is specified, break at end of code for that function.\n\
7871 If an address is specified, break at the end of the function that contains \n\
7872 that exact address.\n",
7873 "With no arg, uses current execution address of selected stack frame.\n\
7874 This is useful for breaking on return to a stack frame.\n\
7876 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7878 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7879 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7880 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7881 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7882 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7886 add_com_alias ("ba", "break", class_breakpoint, 1);
7887 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7888 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7889 "Set breakpoint at procedure exit. Either there should\n\
7890 be no argument or the argument must be a depth.\n");
7895 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7896 "Break in function/address or break at a line in the current file.",
7897 &stoplist, "stop ", 1, &cmdlist);
7898 add_cmd ("in", class_breakpoint, stopin_command,
7899 "Break in function or address.\n", &stoplist);
7900 add_cmd ("at", class_breakpoint, stopat_command,
7901 "Break at a line in the current file.\n", &stoplist);
7902 add_com ("status", class_info, breakpoints_info,
7903 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7904 The \"Type\" column indicates one of:\n\
7905 \tbreakpoint - normal breakpoint\n\
7906 \twatchpoint - watchpoint\n\
7907 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7908 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7909 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7910 address and file/line number respectively.\n\n",
7911 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7912 are set to the address of the last breakpoint listed.\n\n\
7913 Convenience variable \"$bpnum\" contains the number of the last\n\
7914 breakpoint set.", NULL));
7917 add_info ("breakpoints", breakpoints_info,
7918 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7919 The \"Type\" column indicates one of:\n\
7920 \tbreakpoint - normal breakpoint\n\
7921 \twatchpoint - watchpoint\n\
7922 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7923 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7924 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7925 address and file/line number respectively.\n\n",
7926 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7927 are set to the address of the last breakpoint listed.\n\n\
7928 Convenience variable \"$bpnum\" contains the number of the last\n\
7929 breakpoint set.", NULL));
7932 add_com ("lb", class_breakpoint, breakpoints_info,
7933 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7934 The \"Type\" column indicates one of:\n\
7935 \tbreakpoint - normal breakpoint\n\
7936 \twatchpoint - watchpoint\n\
7937 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7938 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7939 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7940 address and file/line number respectively.\n\n",
7941 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7942 are set to the address of the last breakpoint listed.\n\n\
7943 Convenience variable \"$bpnum\" contains the number of the last\n\
7944 breakpoint set.", NULL));
7946 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7947 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7948 The \"Type\" column indicates one of:\n\
7949 \tbreakpoint - normal breakpoint\n\
7950 \twatchpoint - watchpoint\n\
7951 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7952 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7953 \tuntil - internal breakpoint used by the \"until\" command\n\
7954 \tfinish - internal breakpoint used by the \"finish\" command\n",
7955 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7956 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7957 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7958 address and file/line number respectively.\n\n",
7959 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7960 are set to the address of the last breakpoint listed.\n\n\
7961 Convenience variable \"$bpnum\" contains the number of the last\n\
7962 breakpoint set.", NULL),
7963 &maintenanceinfolist);
7965 add_com ("catch", class_breakpoint, catch_command,
7966 "Set catchpoints to catch events.\n\
7967 Raised signals may be caught:\n\
7968 \tcatch signal - all signals\n\
7969 \tcatch signal <signame> - a particular signal\n\
7970 Raised exceptions may be caught:\n\
7971 \tcatch throw - all exceptions, when thrown\n\
7972 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7973 \tcatch catch - all exceptions, when caught\n\
7974 \tcatch catch <exceptname> - a particular exception, when caught\n\
7975 Thread or process events may be caught:\n\
7976 \tcatch thread_start - any threads, just after creation\n\
7977 \tcatch thread_exit - any threads, just before expiration\n\
7978 \tcatch thread_join - any threads, just after joins\n\
7979 Process events may be caught:\n\
7980 \tcatch start - any processes, just after creation\n\
7981 \tcatch exit - any processes, just before expiration\n\
7982 \tcatch fork - calls to fork()\n\
7983 \tcatch vfork - calls to vfork()\n\
7984 \tcatch exec - calls to exec()\n\
7985 Dynamically-linked library events may be caught:\n\
7986 \tcatch load - loads of any library\n\
7987 \tcatch load <libname> - loads of a particular library\n\
7988 \tcatch unload - unloads of any library\n\
7989 \tcatch unload <libname> - unloads of a particular library\n\
7990 The act of your program's execution stopping may also be caught:\n\
7992 C++ exceptions may be caught:\n\
7993 \tcatch throw - all exceptions, when thrown\n\
7994 \tcatch catch - all exceptions, when caught\n\
7996 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7997 after a fork or vfork is caught.\n\n\
7998 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
8000 add_com ("tcatch", class_breakpoint, tcatch_command,
8001 "Set temporary catchpoints to catch events.\n\
8002 Args like \"catch\" command.\n\
8003 Like \"catch\" except the catchpoint is only temporary,\n\
8004 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8005 by using \"enable delete\" on the catchpoint number.");
8007 add_com ("watch", class_breakpoint, watch_command,
8008 "Set a watchpoint for an expression.\n\
8009 A watchpoint stops execution of your program whenever the value of\n\
8010 an expression changes.");
8012 add_com ("rwatch", class_breakpoint, rwatch_command,
8013 "Set a read watchpoint for an expression.\n\
8014 A watchpoint stops execution of your program whenever the value of\n\
8015 an expression is read.");
8017 add_com ("awatch", class_breakpoint, awatch_command,
8018 "Set a watchpoint for an expression.\n\
8019 A watchpoint stops execution of your program whenever the value of\n\
8020 an expression is either read or written.");
8022 add_info ("watchpoints", breakpoints_info,
8023 "Synonym for ``info breakpoints''.");
8026 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
8027 (char *) &can_use_hw_watchpoints,
8028 "Set debugger's willingness to use watchpoint hardware.\n\
8029 If zero, gdb will not use hardware for new watchpoints, even if\n\
8030 such is available. (However, any hardware watchpoints that were\n\
8031 created before setting this to nonzero, will continue to use watchpoint\n\
8034 add_show_from_set (c, &showlist);
8036 can_use_hw_watchpoints = 1;