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
924 struct frame_info *saved_frame;
925 int saved_level, within_current_scope;
926 value_ptr mark = value_mark ();
929 /* Save the current frame and level so we can restore it after
930 evaluating the watchpoint expression on its own frame. */
931 saved_frame = selected_frame;
932 saved_level = selected_frame_level;
934 /* Determine if the watchpoint is within scope. */
935 if (b->exp_valid_block == NULL)
936 within_current_scope = 1;
939 struct frame_info *fi;
941 /* There might be no current frame at this moment if we are
942 resuming from a step over a breakpoint.
943 Set up current frame before trying to find the watchpoint
945 get_current_frame ();
946 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
947 within_current_scope = (fi != NULL);
948 if (within_current_scope)
949 select_frame (fi, -1);
952 if (within_current_scope)
954 /* Evaluate the expression and cut the chain of values
955 produced off from the value chain.
957 Make sure the value returned isn't lazy; we use
958 laziness to determine what memory GDB actually needed
959 in order to compute the value of the expression. */
960 v = evaluate_expression (b->exp);
962 value_release_to_mark (mark);
967 /* Look at each value on the value chain. */
968 for (; v; v = v->next)
970 /* If it's a memory location, and GDB actually needed
971 its contents to evaluate the expression, then we
973 if (VALUE_LVAL (v) == lval_memory
976 struct type *vtype = check_typedef (VALUE_TYPE (v));
978 /* We only watch structs and arrays if user asked
979 for it explicitly, never if they just happen to
980 appear in the middle of some value chain. */
981 if (v == b->val_chain
982 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
983 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
988 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
989 len = TYPE_LENGTH (VALUE_TYPE (v));
991 if (b->type == bp_read_watchpoint)
993 else if (b->type == bp_access_watchpoint)
996 val = target_insert_watchpoint (addr, len, type);
999 /* Don't exit the loop, try to insert
1000 every value on the value chain. That's
1001 because we will be removing all the
1002 watches below, and removing a
1003 watchpoint we didn't insert could have
1011 /* Failure to insert a watchpoint on any memory value in the
1012 value chain brings us here. */
1015 remove_breakpoint (b, mark_uninserted);
1016 warning ("Could not insert hardware watchpoint %d.",
1023 printf_filtered ("Hardware watchpoint %d deleted", b->number);
1024 printf_filtered ("because the program has left the block \n");
1025 printf_filtered ("in which its expression is valid.\n");
1026 if (b->related_breakpoint)
1027 b->related_breakpoint->disposition = del_at_next_stop;
1028 b->disposition = del_at_next_stop;
1031 /* Restore the frame and level. */
1032 if ((saved_frame != selected_frame) ||
1033 (saved_level != selected_frame_level))
1034 select_and_print_frame (saved_frame, saved_level);
1037 return_val = val; /* remember failure */
1039 else if ((b->type == bp_catch_fork
1040 || b->type == bp_catch_vfork
1041 || b->type == bp_catch_exec)
1042 && b->enable == enabled
1050 val = target_insert_fork_catchpoint (inferior_pid);
1052 case bp_catch_vfork:
1053 val = target_insert_vfork_catchpoint (inferior_pid);
1056 val = target_insert_exec_catchpoint (inferior_pid);
1059 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1064 target_terminal_ours_for_output ();
1065 warning ("Cannot insert catchpoint %d.", b->number);
1071 return_val = val; /* remember failure */
1080 remove_breakpoints ()
1082 register struct breakpoint *b;
1089 val = remove_breakpoint (b, mark_uninserted);
1098 reattach_breakpoints (pid)
1101 register struct breakpoint *b;
1103 int saved_inferior_pid = inferior_pid;
1105 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1106 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1111 remove_breakpoint (b, mark_inserted);
1112 if (b->type == bp_hardware_breakpoint)
1113 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1115 val = target_insert_breakpoint (b->address, b->shadow_contents);
1118 inferior_pid = saved_inferior_pid;
1123 inferior_pid = saved_inferior_pid;
1128 update_breakpoints_after_exec ()
1130 struct breakpoint *b;
1131 struct breakpoint *temp;
1133 /* Doing this first prevents the badness of having delete_breakpoint()
1134 write a breakpoint's current "shadow contents" to lift the bp. That
1135 shadow is NOT valid after an exec()! */
1136 mark_breakpoints_out ();
1138 ALL_BREAKPOINTS_SAFE (b, temp)
1140 /* Solib breakpoints must be explicitly reset after an exec(). */
1141 if (b->type == bp_shlib_event)
1143 delete_breakpoint (b);
1147 /* Thread event breakpoints must be set anew after an exec(). */
1148 if (b->type == bp_thread_event)
1150 delete_breakpoint (b);
1154 /* Step-resume breakpoints are meaningless after an exec(). */
1155 if (b->type == bp_step_resume)
1157 delete_breakpoint (b);
1161 /* Ditto the sigtramp handler breakpoints. */
1162 if (b->type == bp_through_sigtramp)
1164 delete_breakpoint (b);
1168 /* Ditto the exception-handling catchpoints. */
1169 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1171 delete_breakpoint (b);
1175 /* Don't delete an exec catchpoint, because else the inferior
1176 won't stop when it ought!
1178 Similarly, we probably ought to keep vfork catchpoints, 'cause
1179 on this target, we may not be able to stop when the vfork is
1180 seen, but only when the subsequent exec is seen. (And because
1181 deleting fork catchpoints here but not vfork catchpoints will
1182 seem mysterious to users, keep those too.)
1184 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1185 target address field, if any, is sufficient to have it be reset
1186 automagically. Certainly on HP-UX that's true. */
1187 if ((b->type == bp_catch_exec) ||
1188 (b->type == bp_catch_vfork) ||
1189 (b->type == bp_catch_fork))
1191 b->address = (CORE_ADDR) NULL;
1195 /* bp_finish is a special case. The only way we ought to be able
1196 to see one of these when an exec() has happened, is if the user
1197 caught a vfork, and then said "finish". Ordinarily a finish just
1198 carries them to the call-site of the current callee, by setting
1199 a temporary bp there and resuming. But in this case, the finish
1200 will carry them entirely through the vfork & exec.
1202 We don't want to allow a bp_finish to remain inserted now. But
1203 we can't safely delete it, 'cause finish_command has a handle to
1204 the bp on a bpstat, and will later want to delete it. There's a
1205 chance (and I've seen it happen) that if we delete the bp_finish
1206 here, that its storage will get reused by the time finish_command
1207 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1208 We really must allow finish_command to delete a bp_finish.
1210 In the absense of a general solution for the "how do we know
1211 it's safe to delete something others may have handles to?"
1212 problem, what we'll do here is just uninsert the bp_finish, and
1213 let finish_command delete it.
1215 (We know the bp_finish is "doomed" in the sense that it's
1216 momentary, and will be deleted as soon as finish_command sees
1217 the inferior stopped. So it doesn't matter that the bp's
1218 address is probably bogus in the new a.out, unlike e.g., the
1219 solib breakpoints.) */
1221 if (b->type == bp_finish)
1226 /* Without a symbolic address, we have little hope of the
1227 pre-exec() address meaning the same thing in the post-exec()
1229 if (b->addr_string == NULL)
1231 delete_breakpoint (b);
1235 /* If this breakpoint has survived the above battery of checks, then
1236 it must have a symbolic address. Be sure that it gets reevaluated
1237 to a target address, rather than reusing the old evaluation. */
1238 b->address = (CORE_ADDR) NULL;
1243 detach_breakpoints (pid)
1246 register struct breakpoint *b;
1248 int saved_inferior_pid = inferior_pid;
1250 if (pid == inferior_pid)
1251 error ("Cannot detach breakpoints of inferior_pid");
1253 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1254 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1259 val = remove_breakpoint (b, mark_inserted);
1262 inferior_pid = saved_inferior_pid;
1267 inferior_pid = saved_inferior_pid;
1272 remove_breakpoint (b, is)
1273 struct breakpoint *b;
1274 insertion_state_t is;
1278 if (b->enable == permanent)
1279 /* Permanent breakpoints cannot be inserted or removed. */
1282 if (b->type == bp_none)
1283 warning ("attempted to remove apparently deleted breakpoint #%d?",
1286 if (b->type != bp_watchpoint
1287 && b->type != bp_hardware_watchpoint
1288 && b->type != bp_read_watchpoint
1289 && b->type != bp_access_watchpoint
1290 && b->type != bp_catch_fork
1291 && b->type != bp_catch_vfork
1292 && b->type != bp_catch_exec
1293 && b->type != bp_catch_catch
1294 && b->type != bp_catch_throw)
1296 if (b->type == bp_hardware_breakpoint)
1297 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1300 /* Check to see if breakpoint is in an overlay section;
1301 if so, we should remove the breakpoint at the LMA address.
1302 If that is not equal to the raw address, then we should
1303 presumable remove the breakpoint there as well. */
1304 if (overlay_debugging && b->section &&
1305 section_is_overlay (b->section))
1309 addr = overlay_unmapped_address (b->address, b->section);
1310 val = target_remove_breakpoint (addr, b->shadow_contents);
1311 /* This would be the time to check val, to see if the
1312 shadow breakpoint write to the load address succeeded.
1313 However, this might be an ordinary occurrance, eg. if
1314 the unmapped overlay is in ROM. */
1315 val = 0; /* in case unmapped address failed */
1316 if (section_is_mapped (b->section))
1317 val = target_remove_breakpoint (b->address,
1318 b->shadow_contents);
1320 else /* ordinary (non-overlay) address */
1321 val = target_remove_breakpoint (b->address, b->shadow_contents);
1325 b->inserted = (is == mark_inserted);
1327 else if ((b->type == bp_hardware_watchpoint ||
1328 b->type == bp_read_watchpoint ||
1329 b->type == bp_access_watchpoint)
1330 && b->enable == enabled
1335 b->inserted = (is == mark_inserted);
1336 /* Walk down the saved value chain. */
1337 for (v = b->val_chain; v; v = v->next)
1339 /* For each memory reference remove the watchpoint
1341 if (VALUE_LVAL (v) == lval_memory
1342 && ! VALUE_LAZY (v))
1344 struct type *vtype = check_typedef (VALUE_TYPE (v));
1346 if (v == b->val_chain
1347 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1348 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1353 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1354 len = TYPE_LENGTH (VALUE_TYPE (v));
1356 if (b->type == bp_read_watchpoint)
1358 else if (b->type == bp_access_watchpoint)
1361 val = target_remove_watchpoint (addr, len, type);
1368 /* Failure to remove any of the hardware watchpoints comes here. */
1369 if ((is == mark_uninserted) && (b->inserted))
1370 warning ("Could not remove hardware watchpoint %d.",
1373 /* Free the saved value chain. We will construct a new one
1374 the next time the watchpoint is inserted. */
1375 for (v = b->val_chain; v; v = n)
1380 b->val_chain = NULL;
1382 else if ((b->type == bp_catch_fork ||
1383 b->type == bp_catch_vfork ||
1384 b->type == bp_catch_exec)
1385 && b->enable == enabled
1392 val = target_remove_fork_catchpoint (inferior_pid);
1394 case bp_catch_vfork:
1395 val = target_remove_vfork_catchpoint (inferior_pid);
1398 val = target_remove_exec_catchpoint (inferior_pid);
1401 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1406 b->inserted = (is == mark_inserted);
1408 else if ((b->type == bp_catch_catch ||
1409 b->type == bp_catch_throw)
1410 && b->enable == enabled
1414 val = target_remove_breakpoint (b->address, b->shadow_contents);
1417 b->inserted = (is == mark_inserted);
1419 else if (ep_is_exception_catchpoint (b)
1420 && b->inserted /* sometimes previous insert doesn't happen */
1421 && b->enable == enabled
1425 val = target_remove_breakpoint (b->address, b->shadow_contents);
1429 b->inserted = (is == mark_inserted);
1435 /* Clear the "inserted" flag in all breakpoints. */
1438 mark_breakpoints_out ()
1440 register struct breakpoint *b;
1446 /* Clear the "inserted" flag in all breakpoints and delete any
1447 breakpoints which should go away between runs of the program.
1449 Plus other such housekeeping that has to be done for breakpoints
1452 Note: this function gets called at the end of a run (by
1453 generic_mourn_inferior) and when a run begins (by
1454 init_wait_for_inferior). */
1459 breakpoint_init_inferior (context)
1460 enum inf_context context;
1462 register struct breakpoint *b, *temp;
1463 static int warning_needed = 0;
1465 ALL_BREAKPOINTS_SAFE (b, temp)
1472 case bp_watchpoint_scope:
1474 /* If the call dummy breakpoint is at the entry point it will
1475 cause problems when the inferior is rerun, so we better
1478 Also get rid of scope breakpoints. */
1479 delete_breakpoint (b);
1483 case bp_hardware_watchpoint:
1484 case bp_read_watchpoint:
1485 case bp_access_watchpoint:
1487 /* Likewise for watchpoints on local expressions. */
1488 if (b->exp_valid_block != NULL)
1489 delete_breakpoint (b);
1492 /* Likewise for exception catchpoints in dynamic-linked
1493 executables where required */
1494 if (ep_is_exception_catchpoint (b) &&
1495 exception_catchpoints_are_fragile)
1498 delete_breakpoint (b);
1504 if (exception_catchpoints_are_fragile)
1505 exception_support_initialized = 0;
1507 /* Don't issue the warning unless it's really needed... */
1508 if (warning_needed && (context != inf_exited))
1510 warning ("Exception catchpoints from last run were deleted.");
1511 warning ("You must reinsert them explicitly.");
1516 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1517 exists at PC. It returns ordinary_breakpoint_here if it's an
1518 ordinary breakpoint, or permanent_breakpoint_here if it's a
1519 permanent breakpoint.
1520 - When continuing from a location with an ordinary breakpoint, we
1521 actually single step once before calling insert_breakpoints.
1522 - When continuing from a localion with a permanent breakpoint, we
1523 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1524 the target, to advance the PC past the breakpoint. */
1526 enum breakpoint_here
1527 breakpoint_here_p (pc)
1530 register struct breakpoint *b;
1531 int any_breakpoint_here = 0;
1534 if ((b->enable == enabled
1535 || b->enable == permanent)
1536 && b->address == pc) /* bp is enabled and matches pc */
1538 if (overlay_debugging &&
1539 section_is_overlay (b->section) &&
1540 !section_is_mapped (b->section))
1541 continue; /* unmapped overlay -- can't be a match */
1542 else if (b->enable == permanent)
1543 return permanent_breakpoint_here;
1545 any_breakpoint_here = 1;
1548 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1552 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1553 but it only returns true if there is actually a breakpoint inserted
1557 breakpoint_inserted_here_p (pc)
1560 register struct breakpoint *b;
1564 && b->address == pc) /* bp is inserted and matches pc */
1566 if (overlay_debugging &&
1567 section_is_overlay (b->section) &&
1568 !section_is_mapped (b->section))
1569 continue; /* unmapped overlay -- can't be a match */
1577 /* Return nonzero if FRAME is a dummy frame. We can't use
1578 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1579 much time, at least using get_saved_register on the 68k. This
1580 means that for this function to work right a port must use the
1581 bp_call_dummy breakpoint. */
1584 frame_in_dummy (frame)
1585 struct frame_info *frame;
1587 struct breakpoint *b;
1592 if (USE_GENERIC_DUMMY_FRAMES)
1593 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1597 if (b->type == bp_call_dummy
1598 && b->frame == frame->frame
1599 /* We need to check the PC as well as the frame on the sparc,
1600 for signals.exp in the testsuite. */
1603 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1604 && frame->pc <= b->address)
1610 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1611 is valid for process/thread PID. */
1614 breakpoint_thread_match (pc, pid)
1618 struct breakpoint *b;
1621 thread = pid_to_thread_id (pid);
1624 if (b->enable != disabled
1625 && b->enable != shlib_disabled
1626 && b->enable != call_disabled
1628 && (b->thread == -1 || b->thread == thread))
1630 if (overlay_debugging &&
1631 section_is_overlay (b->section) &&
1632 !section_is_mapped (b->section))
1633 continue; /* unmapped overlay -- can't be a match */
1642 /* bpstat stuff. External routines' interfaces are documented
1646 ep_is_catchpoint (ep)
1647 struct breakpoint *ep;
1650 (ep->type == bp_catch_load)
1651 || (ep->type == bp_catch_unload)
1652 || (ep->type == bp_catch_fork)
1653 || (ep->type == bp_catch_vfork)
1654 || (ep->type == bp_catch_exec)
1655 || (ep->type == bp_catch_catch)
1656 || (ep->type == bp_catch_throw)
1659 /* ??rehrauer: Add more kinds here, as are implemented... */
1664 ep_is_shlib_catchpoint (ep)
1665 struct breakpoint *ep;
1668 (ep->type == bp_catch_load)
1669 || (ep->type == bp_catch_unload)
1674 ep_is_exception_catchpoint (ep)
1675 struct breakpoint *ep;
1678 (ep->type == bp_catch_catch)
1679 || (ep->type == bp_catch_throw)
1683 /* Clear a bpstat so that it says we are not at any breakpoint.
1684 Also free any storage that is part of a bpstat. */
1699 if (p->old_val != NULL)
1700 value_free (p->old_val);
1707 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1708 is part of the bpstat is copied as well. */
1716 bpstat retval = NULL;
1721 for (; bs != NULL; bs = bs->next)
1723 tmp = (bpstat) xmalloc (sizeof (*tmp));
1724 memcpy (tmp, bs, sizeof (*tmp));
1726 /* This is the first thing in the chain. */
1736 /* Find the bpstat associated with this breakpoint */
1739 bpstat_find_breakpoint (bsp, breakpoint)
1741 struct breakpoint *breakpoint;
1746 for (; bsp != NULL; bsp = bsp->next)
1748 if (bsp->breakpoint_at == breakpoint)
1754 /* Find a step_resume breakpoint associated with this bpstat.
1755 (If there are multiple step_resume bp's on the list, this function
1756 will arbitrarily pick one.)
1758 It is an error to use this function if BPSTAT doesn't contain a
1759 step_resume breakpoint.
1761 See wait_for_inferior's use of this function. */
1763 bpstat_find_step_resume_breakpoint (bsp)
1767 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1769 for (; bsp != NULL; bsp = bsp->next)
1771 if ((bsp->breakpoint_at != NULL) &&
1772 (bsp->breakpoint_at->type == bp_step_resume))
1773 return bsp->breakpoint_at;
1776 error ("Internal error (no step_resume breakpoint found)");
1780 /* Return the breakpoint number of the first breakpoint we are stopped
1781 at. *BSP upon return is a bpstat which points to the remaining
1782 breakpoints stopped at (but which is not guaranteed to be good for
1783 anything but further calls to bpstat_num).
1784 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1790 struct breakpoint *b;
1793 return 0; /* No more breakpoint values */
1796 b = (*bsp)->breakpoint_at;
1797 *bsp = (*bsp)->next;
1799 return -1; /* breakpoint that's been deleted since */
1801 return b->number; /* We have its number */
1805 /* Modify BS so that the actions will not be performed. */
1808 bpstat_clear_actions (bs)
1811 for (; bs != NULL; bs = bs->next)
1813 bs->commands = NULL;
1814 if (bs->old_val != NULL)
1816 value_free (bs->old_val);
1822 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1825 cleanup_executing_breakpoints (ignore)
1828 executing_breakpoint_commands = 0;
1831 /* Execute all the commands associated with all the breakpoints at this
1832 location. Any of these commands could cause the process to proceed
1833 beyond this point, etc. We look out for such changes by checking
1834 the global "breakpoint_proceeded" after each command. */
1837 bpstat_do_actions (bsp)
1841 struct cleanup *old_chain;
1842 struct command_line *cmd;
1844 /* Avoid endless recursion if a `source' command is contained
1846 if (executing_breakpoint_commands)
1849 executing_breakpoint_commands = 1;
1850 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1853 /* Note that (as of this writing), our callers all appear to
1854 be passing us the address of global stop_bpstat. And, if
1855 our calls to execute_control_command cause the inferior to
1856 proceed, that global (and hence, *bsp) will change.
1858 We must be careful to not touch *bsp unless the inferior
1859 has not proceeded. */
1861 /* This pointer will iterate over the list of bpstat's. */
1864 breakpoint_proceeded = 0;
1865 for (; bs != NULL; bs = bs->next)
1870 execute_control_command (cmd);
1872 if (breakpoint_proceeded)
1877 if (breakpoint_proceeded)
1878 /* The inferior is proceeded by the command; bomb out now.
1879 The bpstat chain has been blown away by wait_for_inferior.
1880 But since execution has stopped again, there is a new bpstat
1881 to look at, so start over. */
1884 bs->commands = NULL;
1887 executing_breakpoint_commands = 0;
1888 discard_cleanups (old_chain);
1891 /* This is the normal print function for a bpstat. In the future,
1892 much of this logic could (should?) be moved to bpstat_stop_status,
1893 by having it set different print_it values.
1895 Current scheme: When we stop, bpstat_print() is called. It loops
1896 through the bpstat list of things causing this stop, calling the
1897 print_bp_stop_message function on each one. The behavior of the
1898 print_bp_stop_message function depends on the print_it field of
1899 bpstat. If such field so indicates, call this function here.
1901 Return values from this routine (ultimately used by bpstat_print()
1902 and normal_stop() to decide what to do):
1903 PRINT_NOTHING: Means we already printed all we needed to print,
1904 don't print anything else.
1905 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1906 that something to be followed by a location.
1907 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1908 that something to be followed by a location.
1909 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1912 static enum print_stop_action
1913 print_it_typical (bs)
1917 struct cleanup *old_chain;
1918 struct ui_stream *stb;
1919 stb = ui_out_stream_new (uiout);
1920 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
1922 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1923 which has since been deleted. */
1924 if (bs->breakpoint_at == NULL)
1925 return PRINT_UNKNOWN;
1927 switch (bs->breakpoint_at->type)
1930 case bp_hardware_breakpoint:
1932 annotate_breakpoint (bs->breakpoint_at->number);
1933 ui_out_text (uiout, "\nBreakpoint ");
1934 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
1935 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1936 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1937 ui_out_text (uiout, ", ");
1938 return PRINT_SRC_AND_LOC;
1940 /* I think the user probably only wants to see one breakpoint
1941 number, not all of them. */
1942 annotate_breakpoint (bs->breakpoint_at->number);
1943 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1944 return PRINT_SRC_AND_LOC;
1948 case bp_shlib_event:
1949 /* Did we stop because the user set the stop_on_solib_events
1950 variable? (If so, we report this as a generic, "Stopped due
1951 to shlib event" message.) */
1952 printf_filtered ("Stopped due to shared library event\n");
1953 return PRINT_NOTHING;
1956 case bp_thread_event:
1957 /* Not sure how we will get here.
1958 GDB should not stop for these breakpoints. */
1959 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1960 return PRINT_NOTHING;
1964 annotate_catchpoint (bs->breakpoint_at->number);
1965 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1966 printf_filtered ("loaded");
1967 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1968 return PRINT_SRC_AND_LOC;
1971 case bp_catch_unload:
1972 annotate_catchpoint (bs->breakpoint_at->number);
1973 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1974 printf_filtered ("unloaded");
1975 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1976 return PRINT_SRC_AND_LOC;
1980 annotate_catchpoint (bs->breakpoint_at->number);
1981 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1982 printf_filtered ("forked");
1983 printf_filtered (" process %d), ",
1984 bs->breakpoint_at->forked_inferior_pid);
1985 return PRINT_SRC_AND_LOC;
1988 case bp_catch_vfork:
1989 annotate_catchpoint (bs->breakpoint_at->number);
1990 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1991 printf_filtered ("vforked");
1992 printf_filtered (" process %d), ",
1993 bs->breakpoint_at->forked_inferior_pid);
1994 return PRINT_SRC_AND_LOC;
1998 annotate_catchpoint (bs->breakpoint_at->number);
1999 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2000 bs->breakpoint_at->number,
2001 bs->breakpoint_at->exec_pathname);
2002 return PRINT_SRC_AND_LOC;
2005 case bp_catch_catch:
2006 if (current_exception_event &&
2007 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2009 annotate_catchpoint (bs->breakpoint_at->number);
2010 printf_filtered ("\nCatchpoint %d (exception caught), ",
2011 bs->breakpoint_at->number);
2012 printf_filtered ("throw location ");
2013 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2014 printf_filtered ("%s:%d",
2015 CURRENT_EXCEPTION_THROW_FILE,
2016 CURRENT_EXCEPTION_THROW_LINE);
2018 printf_filtered ("unknown");
2020 printf_filtered (", catch location ");
2021 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2022 printf_filtered ("%s:%d",
2023 CURRENT_EXCEPTION_CATCH_FILE,
2024 CURRENT_EXCEPTION_CATCH_LINE);
2026 printf_filtered ("unknown");
2028 printf_filtered ("\n");
2029 /* don't bother to print location frame info */
2030 return PRINT_SRC_ONLY;
2034 /* really throw, some other bpstat will handle it */
2035 return PRINT_UNKNOWN;
2039 case bp_catch_throw:
2040 if (current_exception_event &&
2041 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2043 annotate_catchpoint (bs->breakpoint_at->number);
2044 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2045 bs->breakpoint_at->number);
2046 printf_filtered ("throw location ");
2047 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2048 printf_filtered ("%s:%d",
2049 CURRENT_EXCEPTION_THROW_FILE,
2050 CURRENT_EXCEPTION_THROW_LINE);
2052 printf_filtered ("unknown");
2054 printf_filtered (", catch location ");
2055 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2056 printf_filtered ("%s:%d",
2057 CURRENT_EXCEPTION_CATCH_FILE,
2058 CURRENT_EXCEPTION_CATCH_LINE);
2060 printf_filtered ("unknown");
2062 printf_filtered ("\n");
2063 /* don't bother to print location frame info */
2064 return PRINT_SRC_ONLY;
2068 /* really catch, some other bpstat will handle it */
2069 return PRINT_UNKNOWN;
2074 case bp_hardware_watchpoint:
2075 if (bs->old_val != NULL)
2077 annotate_watchpoint (bs->breakpoint_at->number);
2079 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2080 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2081 mention (bs->breakpoint_at);
2082 ui_out_list_begin (uiout, "value");
2083 ui_out_text (uiout, "\nOld value = ");
2084 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2085 ui_out_field_stream (uiout, "old", stb);
2086 ui_out_text (uiout, "\nNew value = ");
2087 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2088 ui_out_field_stream (uiout, "new", stb);
2089 ui_out_list_end (uiout);
2090 ui_out_text (uiout, "\n");
2092 mention (bs->breakpoint_at);
2093 printf_filtered ("\nOld value = ");
2094 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2095 printf_filtered ("\nNew value = ");
2096 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2097 Val_pretty_default);
2098 printf_filtered ("\n");
2100 value_free (bs->old_val);
2103 /* More than one watchpoint may have been triggered. */
2104 return PRINT_UNKNOWN;
2107 case bp_read_watchpoint:
2109 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2110 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2111 mention (bs->breakpoint_at);
2112 ui_out_list_begin (uiout, "value");
2113 ui_out_text (uiout, "\nValue = ");
2114 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2115 ui_out_field_stream (uiout, "value", stb);
2116 ui_out_list_end (uiout);
2117 ui_out_text (uiout, "\n");
2119 mention (bs->breakpoint_at);
2120 printf_filtered ("\nValue = ");
2121 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2122 Val_pretty_default);
2123 printf_filtered ("\n");
2125 return PRINT_UNKNOWN;
2128 case bp_access_watchpoint:
2130 if (bs->old_val != NULL)
2132 annotate_watchpoint (bs->breakpoint_at->number);
2133 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2134 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2135 mention (bs->breakpoint_at);
2136 ui_out_list_begin (uiout, "value");
2137 ui_out_text (uiout, "\nOld value = ");
2138 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2139 ui_out_field_stream (uiout, "old", stb);
2140 value_free (bs->old_val);
2142 ui_out_text (uiout, "\nNew value = ");
2146 mention (bs->breakpoint_at);
2147 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2148 ui_out_list_begin (uiout, "value");
2149 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2150 ui_out_text (uiout, "\nValue = ");
2152 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2153 ui_out_field_stream (uiout, "new", stb);
2154 ui_out_list_end (uiout);
2155 ui_out_text (uiout, "\n");
2157 if (bs->old_val != NULL)
2159 annotate_watchpoint (bs->breakpoint_at->number);
2160 mention (bs->breakpoint_at);
2161 printf_filtered ("\nOld value = ");
2162 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2163 value_free (bs->old_val);
2165 printf_filtered ("\nNew value = ");
2169 mention (bs->breakpoint_at);
2170 printf_filtered ("\nValue = ");
2172 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2173 Val_pretty_default);
2174 printf_filtered ("\n");
2176 return PRINT_UNKNOWN;
2179 /* Fall through, we don't deal with these types of breakpoints
2184 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2185 ui_out_field_string (uiout, "reason", "function-finished");
2187 return PRINT_UNKNOWN;
2192 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2193 ui_out_field_string (uiout, "reason", "location-reached");
2195 return PRINT_UNKNOWN;
2200 case bp_longjmp_resume:
2201 case bp_step_resume:
2202 case bp_through_sigtramp:
2203 case bp_watchpoint_scope:
2206 return PRINT_UNKNOWN;
2210 /* Generic routine for printing messages indicating why we
2211 stopped. The behavior of this function depends on the value
2212 'print_it' in the bpstat structure. Under some circumstances we
2213 may decide not to print anything here and delegate the task to
2216 static enum print_stop_action
2217 print_bp_stop_message (bpstat bs)
2219 switch (bs->print_it)
2222 /* Nothing should be printed for this bpstat entry. */
2223 return PRINT_UNKNOWN;
2227 /* We still want to print the frame, but we already printed the
2228 relevant messages. */
2229 return PRINT_SRC_AND_LOC;
2232 case print_it_normal:
2233 /* Normal case, we handle everything in print_it_typical. */
2234 return print_it_typical (bs);
2237 internal_error ("print_bp_stop_message: unrecognized enum value");
2242 /* Print a message indicating what happened. This is called from
2243 normal_stop(). The input to this routine is the head of the bpstat
2244 list - a list of the eventpoints that caused this stop. This
2245 routine calls the generic print routine for printing a message
2246 about reasons for stopping. This will print (for example) the
2247 "Breakpoint n," part of the output. The return value of this
2250 PRINT_UNKNOWN: Means we printed nothing
2251 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2252 code to print the location. An example is
2253 "Breakpoint 1, " which should be followed by
2255 PRINT_SRC_ONLY: Means we printed something, but there is no need
2256 to also print the location part of the message.
2257 An example is the catch/throw messages, which
2258 don't require a location appended to the end.
2259 PRINT_NOTHING: We have done some printing and we don't need any
2260 further info to be printed.*/
2262 enum print_stop_action
2268 /* Maybe another breakpoint in the chain caused us to stop.
2269 (Currently all watchpoints go on the bpstat whether hit or not.
2270 That probably could (should) be changed, provided care is taken
2271 with respect to bpstat_explains_signal). */
2272 for (; bs; bs = bs->next)
2274 val = print_bp_stop_message (bs);
2275 if (val == PRINT_SRC_ONLY
2276 || val == PRINT_SRC_AND_LOC
2277 || val == PRINT_NOTHING)
2281 /* We reached the end of the chain, or we got a null BS to start
2282 with and nothing was printed. */
2283 return PRINT_UNKNOWN;
2286 /* Evaluate the expression EXP and return 1 if value is zero.
2287 This is used inside a catch_errors to evaluate the breakpoint condition.
2288 The argument is a "struct expression *" that has been cast to char * to
2289 make it pass through catch_errors. */
2292 breakpoint_cond_eval (exp)
2295 value_ptr mark = value_mark ();
2296 int i = !value_true (evaluate_expression ((struct expression *) exp));
2297 value_free_to_mark (mark);
2301 /* Allocate a new bpstat and chain it to the current one. */
2304 bpstat_alloc (b, cbs)
2305 register struct breakpoint *b;
2306 bpstat cbs; /* Current "bs" value */
2310 bs = (bpstat) xmalloc (sizeof (*bs));
2312 bs->breakpoint_at = b;
2313 /* If the condition is false, etc., don't do the commands. */
2314 bs->commands = NULL;
2316 bs->print_it = print_it_normal;
2320 /* Possible return values for watchpoint_check (this can't be an enum
2321 because of check_errors). */
2322 /* The watchpoint has been deleted. */
2323 #define WP_DELETED 1
2324 /* The value has changed. */
2325 #define WP_VALUE_CHANGED 2
2326 /* The value has not changed. */
2327 #define WP_VALUE_NOT_CHANGED 3
2329 #define BP_TEMPFLAG 1
2330 #define BP_HARDWAREFLAG 2
2332 /* Check watchpoint condition. */
2335 watchpoint_check (p)
2338 bpstat bs = (bpstat) p;
2339 struct breakpoint *b;
2340 struct frame_info *fr;
2341 int within_current_scope;
2343 b = bs->breakpoint_at;
2345 if (b->exp_valid_block == NULL)
2346 within_current_scope = 1;
2349 /* There is no current frame at this moment. If we're going to have
2350 any chance of handling watchpoints on local variables, we'll need
2351 the frame chain (so we can determine if we're in scope). */
2352 reinit_frame_cache ();
2353 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2354 within_current_scope = (fr != NULL);
2355 if (within_current_scope)
2356 /* If we end up stopping, the current frame will get selected
2357 in normal_stop. So this call to select_frame won't affect
2359 select_frame (fr, -1);
2362 if (within_current_scope)
2364 /* We use value_{,free_to_}mark because it could be a
2365 *long* time before we return to the command level and
2366 call free_all_values. We can't call free_all_values because
2367 we might be in the middle of evaluating a function call. */
2369 value_ptr mark = value_mark ();
2370 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2371 if (!value_equal (b->val, new_val))
2373 release_value (new_val);
2374 value_free_to_mark (mark);
2375 bs->old_val = b->val;
2377 /* We will stop here */
2378 return WP_VALUE_CHANGED;
2382 /* Nothing changed, don't do anything. */
2383 value_free_to_mark (mark);
2384 /* We won't stop here */
2385 return WP_VALUE_NOT_CHANGED;
2390 /* This seems like the only logical thing to do because
2391 if we temporarily ignored the watchpoint, then when
2392 we reenter the block in which it is valid it contains
2393 garbage (in the case of a function, it may have two
2394 garbage values, one before and one after the prologue).
2395 So we can't even detect the first assignment to it and
2396 watch after that (since the garbage may or may not equal
2397 the first value assigned). */
2398 /* We print all the stop information in print_it_typical(), but
2399 in this case, by the time we call print_it_typical() this bp
2400 will be deleted already. So we have no choice but print the
2401 information here. */
2403 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2404 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2405 ui_out_text (uiout, "\nWatchpoint ");
2406 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2407 ui_out_text (uiout, " deleted because the program has left the block in\n\
2408 which its expression is valid.\n");
2411 Watchpoint %d deleted because the program has left the block in\n\
2412 which its expression is valid.\n", bs->breakpoint_at->number);
2415 if (b->related_breakpoint)
2416 b->related_breakpoint->disposition = del_at_next_stop;
2417 b->disposition = del_at_next_stop;
2423 /* Get a bpstat associated with having just stopped at address *PC
2424 and frame address CORE_ADDRESS. Update *PC to point at the
2425 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2426 if this is known to not be a real breakpoint (it could still be a
2427 watchpoint, though). */
2429 /* Determine whether we stopped at a breakpoint, etc, or whether we
2430 don't understand this stop. Result is a chain of bpstat's such that:
2432 if we don't understand the stop, the result is a null pointer.
2434 if we understand why we stopped, the result is not null.
2436 Each element of the chain refers to a particular breakpoint or
2437 watchpoint at which we have stopped. (We may have stopped for
2438 several reasons concurrently.)
2440 Each element of the chain has valid next, breakpoint_at,
2441 commands, FIXME??? fields. */
2444 bpstat_stop_status (pc, not_a_breakpoint)
2446 int not_a_breakpoint;
2448 register struct breakpoint *b, *temp;
2450 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2451 int real_breakpoint = 0;
2452 /* Root of the chain of bpstat's */
2453 struct bpstats root_bs[1];
2454 /* Pointer to the last thing in the chain currently. */
2455 bpstat bs = root_bs;
2456 static char message1[] =
2457 "Error evaluating expression for watchpoint %d\n";
2458 char message[sizeof (message1) + 30 /* slop */ ];
2460 /* Get the address where the breakpoint would have been. */
2461 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ?
2462 0 : DECR_PC_AFTER_BREAK);
2464 ALL_BREAKPOINTS_SAFE (b, temp)
2466 if (b->enable == disabled
2467 || b->enable == shlib_disabled
2468 || b->enable == call_disabled)
2471 if (b->type != bp_watchpoint
2472 && b->type != bp_hardware_watchpoint
2473 && b->type != bp_read_watchpoint
2474 && b->type != bp_access_watchpoint
2475 && b->type != bp_hardware_breakpoint
2476 && b->type != bp_catch_fork
2477 && b->type != bp_catch_vfork
2478 && b->type != bp_catch_exec
2479 && b->type != bp_catch_catch
2480 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2481 if (b->address != bp_addr || /* address doesn't match or */
2482 (overlay_debugging && /* overlay doesn't match */
2483 section_is_overlay (b->section) &&
2484 !section_is_mapped (b->section)))
2487 if (b->type == bp_hardware_breakpoint
2488 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2491 /* Is this a catchpoint of a load or unload? If so, did we
2492 get a load or unload of the specified library? If not,
2494 if ((b->type == bp_catch_load)
2495 #if defined(SOLIB_HAVE_LOAD_EVENT)
2496 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2497 || ((b->dll_pathname != NULL)
2498 && (strcmp (b->dll_pathname,
2499 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2505 if ((b->type == bp_catch_unload)
2506 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2507 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2508 || ((b->dll_pathname != NULL)
2509 && (strcmp (b->dll_pathname,
2510 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2516 if ((b->type == bp_catch_fork)
2517 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2520 if ((b->type == bp_catch_vfork)
2521 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2524 if ((b->type == bp_catch_exec)
2525 && !target_has_execd (inferior_pid, &b->exec_pathname))
2528 if (ep_is_exception_catchpoint (b) &&
2529 !(current_exception_event = target_get_current_exception_event ()))
2532 /* Come here if it's a watchpoint, or if the break address matches */
2534 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2536 /* Watchpoints may change this, if not found to have triggered. */
2540 sprintf (message, message1, b->number);
2541 if (b->type == bp_watchpoint ||
2542 b->type == bp_hardware_watchpoint)
2544 switch (catch_errors (watchpoint_check, bs, message,
2548 /* We've already printed what needs to be printed. */
2549 /* Actually this is superfluous, because by the time we
2550 call print_it_typical() the wp will be already deleted,
2551 and the function will return immediately. */
2552 bs->print_it = print_it_done;
2555 case WP_VALUE_CHANGED:
2559 case WP_VALUE_NOT_CHANGED:
2561 bs->print_it = print_it_noop;
2568 /* Error from catch_errors. */
2569 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2570 if (b->related_breakpoint)
2571 b->related_breakpoint->disposition = del_at_next_stop;
2572 b->disposition = del_at_next_stop;
2573 /* We've already printed what needs to be printed. */
2574 bs->print_it = print_it_done;
2580 else if (b->type == bp_read_watchpoint ||
2581 b->type == bp_access_watchpoint)
2587 addr = target_stopped_data_address ();
2590 for (v = b->val_chain; v; v = v->next)
2592 if (VALUE_LVAL (v) == lval_memory
2593 && ! VALUE_LAZY (v))
2595 struct type *vtype = check_typedef (VALUE_TYPE (v));
2597 if (v == b->val_chain
2598 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2599 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2603 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2604 /* Exact match not required. Within range is
2606 if (addr >= vaddr &&
2607 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2613 switch (catch_errors (watchpoint_check, bs, message,
2617 /* We've already printed what needs to be printed. */
2618 bs->print_it = print_it_done;
2621 case WP_VALUE_CHANGED:
2622 if (b->type == bp_read_watchpoint)
2624 /* Don't stop: read watchpoints shouldn't fire if
2625 the value has changed. This is for targets which
2626 cannot set read-only watchpoints. */
2627 bs->print_it = print_it_noop;
2633 case WP_VALUE_NOT_CHANGED:
2640 /* Error from catch_errors. */
2641 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2642 if (b->related_breakpoint)
2643 b->related_breakpoint->disposition = del_at_next_stop;
2644 b->disposition = del_at_next_stop;
2645 /* We've already printed what needs to be printed. */
2646 bs->print_it = print_it_done;
2649 else /* found == 0 */
2651 /* This is a case where some watchpoint(s) triggered,
2652 but not at the address of this watchpoint (FOUND
2653 was left zero). So don't print anything for this
2655 bs->print_it = print_it_noop;
2662 /* By definition, an encountered breakpoint is a triggered
2666 real_breakpoint = 1;
2670 b->frame != (get_current_frame ())->frame)
2674 int value_is_zero = 0;
2678 /* Need to select the frame, with all that implies
2679 so that the conditions will have the right context. */
2680 select_frame (get_current_frame (), 0);
2682 = catch_errors (breakpoint_cond_eval, (b->cond),
2683 "Error in testing breakpoint condition:\n",
2685 /* FIXME-someday, should give breakpoint # */
2688 if (b->cond && value_is_zero)
2691 /* Don't consider this a hit. */
2694 else if (b->ignore_count > 0)
2697 annotate_ignore_count_change ();
2702 /* We will stop here */
2703 if (b->disposition == disable)
2704 b->enable = disabled;
2705 bs->commands = b->commands;
2709 (STREQ ("silent", bs->commands->line) ||
2710 (xdb_commands && STREQ ("Q", bs->commands->line))))
2712 bs->commands = bs->commands->next;
2717 /* Print nothing for this entry if we dont stop or if we dont print. */
2718 if (bs->stop == 0 || bs->print == 0)
2719 bs->print_it = print_it_noop;
2722 bs->next = NULL; /* Terminate the chain */
2723 bs = root_bs->next; /* Re-grab the head of the chain */
2725 if (real_breakpoint && bs)
2727 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2729 if (DECR_PC_AFTER_HW_BREAK != 0)
2731 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2737 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2740 #if defined (SHIFT_INST_REGS)
2742 #else /* No SHIFT_INST_REGS. */
2744 #endif /* No SHIFT_INST_REGS. */
2749 /* The value of a hardware watchpoint hasn't changed, but the
2750 intermediate memory locations we are watching may have. */
2751 if (bs && !bs->stop &&
2752 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2753 bs->breakpoint_at->type == bp_read_watchpoint ||
2754 bs->breakpoint_at->type == bp_access_watchpoint))
2756 remove_breakpoints ();
2757 insert_breakpoints ();
2762 /* Tell what to do about this bpstat. */
2767 /* Classify each bpstat as one of the following. */
2770 /* This bpstat element has no effect on the main_action. */
2773 /* There was a watchpoint, stop but don't print. */
2776 /* There was a watchpoint, stop and print. */
2779 /* There was a breakpoint but we're not stopping. */
2782 /* There was a breakpoint, stop but don't print. */
2785 /* There was a breakpoint, stop and print. */
2788 /* We hit the longjmp breakpoint. */
2791 /* We hit the longjmp_resume breakpoint. */
2794 /* We hit the step_resume breakpoint. */
2797 /* We hit the through_sigtramp breakpoint. */
2800 /* We hit the shared library event breakpoint. */
2803 /* We caught a shared library event. */
2806 /* This is just used to count how many enums there are. */
2810 /* Here is the table which drives this routine. So that we can
2811 format it pretty, we define some abbreviations for the
2812 enum bpstat_what codes. */
2813 #define kc BPSTAT_WHAT_KEEP_CHECKING
2814 #define ss BPSTAT_WHAT_STOP_SILENT
2815 #define sn BPSTAT_WHAT_STOP_NOISY
2816 #define sgl BPSTAT_WHAT_SINGLE
2817 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2818 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2819 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2820 #define sr BPSTAT_WHAT_STEP_RESUME
2821 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2822 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2823 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2825 /* "Can't happen." Might want to print an error message.
2826 abort() is not out of the question, but chances are GDB is just
2827 a bit confused, not unusable. */
2828 #define err BPSTAT_WHAT_STOP_NOISY
2830 /* Given an old action and a class, come up with a new action. */
2831 /* One interesting property of this table is that wp_silent is the same
2832 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2833 after stopping, the check for whether to step over a breakpoint
2834 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2835 reference to how we stopped. We retain separate wp_silent and
2836 bp_silent codes in case we want to change that someday.
2838 Another possibly interesting property of this table is that
2839 there's a partial ordering, priority-like, of the actions. Once
2840 you've decided that some action is appropriate, you'll never go
2841 back and decide something of a lower priority is better. The
2844 kc < clr sgl shl slr sn sr ss ts
2845 sgl < clrs shl shlr slr sn sr ss ts
2846 slr < err shl shlr sn sr ss ts
2847 clr < clrs err shl shlr sn sr ss ts
2848 clrs < err shl shlr sn sr ss ts
2849 ss < shl shlr sn sr ts
2856 What I think this means is that we don't need a damned table
2857 here. If you just put the rows and columns in the right order,
2858 it'd look awfully regular. We could simply walk the bpstat list
2859 and choose the highest priority action we find, with a little
2860 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2861 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2862 is messy anyway). */
2864 /* step_resume entries: a step resume breakpoint overrides another
2865 breakpoint of signal handling (see comment in wait_for_inferior
2866 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2867 /* We handle the through_sigtramp_breakpoint the same way; having both
2868 one of those and a step_resume_breakpoint is probably very rare (?). */
2870 static const enum bpstat_what_main_action
2871 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2874 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2877 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2879 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2881 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2883 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2885 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2887 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2889 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2891 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2893 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2895 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2897 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2899 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2914 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2915 struct bpstat_what retval;
2917 retval.call_dummy = 0;
2918 for (; bs != NULL; bs = bs->next)
2920 enum class bs_class = no_effect;
2921 if (bs->breakpoint_at == NULL)
2922 /* I suspect this can happen if it was a momentary breakpoint
2923 which has since been deleted. */
2925 switch (bs->breakpoint_at->type)
2931 case bp_hardware_breakpoint:
2937 bs_class = bp_noisy;
2939 bs_class = bp_silent;
2942 bs_class = bp_nostop;
2945 case bp_hardware_watchpoint:
2946 case bp_read_watchpoint:
2947 case bp_access_watchpoint:
2951 bs_class = wp_noisy;
2953 bs_class = wp_silent;
2956 /* There was a watchpoint, but we're not stopping.
2957 This requires no further action. */
2958 bs_class = no_effect;
2961 bs_class = long_jump;
2963 case bp_longjmp_resume:
2964 bs_class = long_resume;
2966 case bp_step_resume:
2969 bs_class = step_resume;
2972 /* It is for the wrong frame. */
2973 bs_class = bp_nostop;
2975 case bp_through_sigtramp:
2976 bs_class = through_sig;
2978 case bp_watchpoint_scope:
2979 bs_class = bp_nostop;
2981 case bp_shlib_event:
2982 bs_class = shlib_event;
2984 case bp_thread_event:
2985 bs_class = bp_nostop;
2988 case bp_catch_unload:
2989 /* Only if this catchpoint triggered should we cause the
2990 step-out-of-dld behaviour. Otherwise, we ignore this
2993 bs_class = catch_shlib_event;
2995 bs_class = no_effect;
2998 case bp_catch_vfork:
3003 bs_class = bp_noisy;
3005 bs_class = bp_silent;
3008 /* There was a catchpoint, but we're not stopping.
3009 This requires no further action. */
3010 bs_class = no_effect;
3012 case bp_catch_catch:
3013 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3014 bs_class = bp_nostop;
3016 bs_class = bs->print ? bp_noisy : bp_silent;
3018 case bp_catch_throw:
3019 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3020 bs_class = bp_nostop;
3022 bs_class = bs->print ? bp_noisy : bp_silent;
3025 /* Make sure the action is stop (silent or noisy),
3026 so infrun.c pops the dummy frame. */
3027 bs_class = bp_silent;
3028 retval.call_dummy = 1;
3031 current_action = table[(int) bs_class][(int) current_action];
3033 retval.main_action = current_action;
3037 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3038 without hardware support). This isn't related to a specific bpstat,
3039 just to things like whether watchpoints are set. */
3042 bpstat_should_step ()
3044 struct breakpoint *b;
3046 if (b->enable == enabled && b->type == bp_watchpoint)
3051 /* Nonzero if there are enabled hardware watchpoints. */
3053 bpstat_have_active_hw_watchpoints ()
3055 struct breakpoint *b;
3057 if ((b->enable == enabled) &&
3059 ((b->type == bp_hardware_watchpoint) ||
3060 (b->type == bp_read_watchpoint) ||
3061 (b->type == bp_access_watchpoint)))
3067 /* Given a bpstat that records zero or more triggered eventpoints, this
3068 function returns another bpstat which contains only the catchpoints
3069 on that first list, if any. */
3071 bpstat_get_triggered_catchpoints (ep_list, cp_list)
3075 struct bpstats root_bs[1];
3076 bpstat bs = root_bs;
3077 struct breakpoint *ep;
3080 bpstat_clear (cp_list);
3081 root_bs->next = NULL;
3083 for (; ep_list != NULL; ep_list = ep_list->next)
3085 /* Is this eventpoint a catchpoint? If not, ignore it. */
3086 ep = ep_list->breakpoint_at;
3089 if ((ep->type != bp_catch_load) &&
3090 (ep->type != bp_catch_unload) &&
3091 (ep->type != bp_catch_catch) &&
3092 (ep->type != bp_catch_throw))
3093 /* pai: (temp) ADD fork/vfork here!! */
3096 /* Yes; add it to the list. */
3097 bs = bpstat_alloc (ep, bs);
3102 #if defined(SOLIB_ADD)
3103 /* Also, for each triggered catchpoint, tag it with the name of
3104 the library that caused this trigger. (We copy the name now,
3105 because it's only guaranteed to be available NOW, when the
3106 catchpoint triggers. Clients who may wish to know the name
3107 later must get it from the catchpoint itself.) */
3108 if (ep->triggered_dll_pathname != NULL)
3109 free (ep->triggered_dll_pathname);
3110 if (ep->type == bp_catch_load)
3111 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
3113 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
3115 dll_pathname = NULL;
3119 ep->triggered_dll_pathname = (char *)
3120 xmalloc (strlen (dll_pathname) + 1);
3121 strcpy (ep->triggered_dll_pathname, dll_pathname);
3124 ep->triggered_dll_pathname = NULL;
3130 /* Print B to gdb_stdout. */
3132 print_one_breakpoint (struct breakpoint *b,
3133 CORE_ADDR *last_addr)
3135 register struct command_line *l;
3136 register struct symbol *sym;
3137 struct ep_type_description
3142 static struct ep_type_description bptypes[] =
3144 {bp_none, "?deleted?"},
3145 {bp_breakpoint, "breakpoint"},
3146 {bp_hardware_breakpoint, "hw breakpoint"},
3147 {bp_until, "until"},
3148 {bp_finish, "finish"},
3149 {bp_watchpoint, "watchpoint"},
3150 {bp_hardware_watchpoint, "hw watchpoint"},
3151 {bp_read_watchpoint, "read watchpoint"},
3152 {bp_access_watchpoint, "acc watchpoint"},
3153 {bp_longjmp, "longjmp"},
3154 {bp_longjmp_resume, "longjmp resume"},
3155 {bp_step_resume, "step resume"},
3156 {bp_through_sigtramp, "sigtramp"},
3157 {bp_watchpoint_scope, "watchpoint scope"},
3158 {bp_call_dummy, "call dummy"},
3159 {bp_shlib_event, "shlib events"},
3160 {bp_thread_event, "thread events"},
3161 {bp_catch_load, "catch load"},
3162 {bp_catch_unload, "catch unload"},
3163 {bp_catch_fork, "catch fork"},
3164 {bp_catch_vfork, "catch vfork"},
3165 {bp_catch_exec, "catch exec"},
3166 {bp_catch_catch, "catch catch"},
3167 {bp_catch_throw, "catch throw"}
3170 static char *bpdisps[] =
3171 {"del", "dstp", "dis", "keep"};
3172 static char bpenables[] = "nynny";
3173 char wrap_indent[80];
3175 struct ui_stream *stb = ui_out_stream_new (uiout);
3176 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3181 ui_out_list_begin (uiout, "bkpt");
3187 ui_out_field_int (uiout, "number", b->number);
3189 printf_filtered ("%-3d ", b->number);
3194 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3195 || ((int) b->type != bptypes[(int) b->type].type))
3196 internal_error ("bptypes table does not describe type #%d.",
3199 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3201 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3207 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3209 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3215 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3216 ui_out_spaces (uiout, 2);
3218 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3222 strcpy (wrap_indent, " ");
3224 strcat (wrap_indent, " ");
3228 internal_error ("print_one_breakpoint: bp_none encountered\n");
3232 case bp_hardware_watchpoint:
3233 case bp_read_watchpoint:
3234 case bp_access_watchpoint:
3235 /* Field 4, the address, is omitted (which makes the columns
3236 not line up too nicely with the headers, but the effect
3237 is relatively readable). */
3240 ui_out_field_skip (uiout, "addr");
3242 print_expression (b->exp, stb->stream);
3243 ui_out_field_stream (uiout, "what", stb);
3246 print_expression (b->exp, gdb_stdout);
3251 case bp_catch_unload:
3252 /* Field 4, the address, is omitted (which makes the columns
3253 not line up too nicely with the headers, but the effect
3254 is relatively readable). */
3257 ui_out_field_skip (uiout, "addr");
3259 if (b->dll_pathname == NULL)
3261 ui_out_field_string (uiout, "what", "<any library>");
3262 ui_out_spaces (uiout, 1);
3266 ui_out_text (uiout, "library \"");
3267 ui_out_field_string (uiout, "what", b->dll_pathname);
3268 ui_out_text (uiout, "\" ");
3272 if (b->dll_pathname == NULL)
3273 printf_filtered ("<any library> ");
3275 printf_filtered ("library \"%s\" ", b->dll_pathname);
3280 case bp_catch_vfork:
3281 /* Field 4, the address, is omitted (which makes the columns
3282 not line up too nicely with the headers, but the effect
3283 is relatively readable). */
3286 ui_out_field_skip (uiout, "addr");
3288 if (b->forked_inferior_pid != 0)
3290 ui_out_text (uiout, "process ");
3291 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3292 ui_out_spaces (uiout, 1);
3296 if (b->forked_inferior_pid != 0)
3297 printf_filtered ("process %d ", b->forked_inferior_pid);
3302 /* Field 4, the address, is omitted (which makes the columns
3303 not line up too nicely with the headers, but the effect
3304 is relatively readable). */
3307 ui_out_field_skip (uiout, "addr");
3309 if (b->exec_pathname != NULL)
3311 ui_out_text (uiout, "program \"");
3312 ui_out_field_string (uiout, "what", b->exec_pathname);
3313 ui_out_text (uiout, "\" ");
3317 if (b->exec_pathname != NULL)
3318 printf_filtered ("program \"%s\" ", b->exec_pathname);
3322 case bp_catch_catch:
3323 /* Field 4, the address, is omitted (which makes the columns
3324 not line up too nicely with the headers, but the effect
3325 is relatively readable). */
3328 ui_out_field_skip (uiout, "addr");
3330 ui_out_field_string (uiout, "what", "exception catch");
3331 ui_out_spaces (uiout, 1);
3334 printf_filtered ("exception catch ");
3338 case bp_catch_throw:
3339 /* Field 4, the address, is omitted (which makes the columns
3340 not line up too nicely with the headers, but the effect
3341 is relatively readable). */
3344 ui_out_field_skip (uiout, "addr");
3346 ui_out_field_string (uiout, "what", "exception throw");
3347 ui_out_spaces (uiout, 1);
3350 printf_filtered ("exception throw ");
3355 case bp_hardware_breakpoint:
3359 case bp_longjmp_resume:
3360 case bp_step_resume:
3361 case bp_through_sigtramp:
3362 case bp_watchpoint_scope:
3364 case bp_shlib_event:
3365 case bp_thread_event:
3370 ui_out_field_core_addr (uiout, "addr", b->address);
3373 *last_addr = b->address;
3376 sym = find_pc_sect_function (b->address, b->section);
3379 ui_out_text (uiout, "in ");
3380 ui_out_field_string (uiout, "func",
3381 SYMBOL_SOURCE_NAME (sym));
3382 ui_out_wrap_hint (uiout, wrap_indent);
3383 ui_out_text (uiout, " at ");
3385 ui_out_field_string (uiout, "file", b->source_file);
3386 ui_out_text (uiout, ":");
3387 ui_out_field_int (uiout, "line", b->line_number);
3391 print_address_symbolic (b->address, stb->stream, demangle, "");
3392 ui_out_field_stream (uiout, "at", stb);
3398 /* FIXME-32x64: need a print_address_numeric with
3402 local_hex_string_custom
3403 ((unsigned long) b->address, "08l"));
3406 *last_addr = b->address;
3409 sym = find_pc_sect_function (b->address, b->section);
3412 fputs_filtered ("in ", gdb_stdout);
3413 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3414 wrap_here (wrap_indent);
3415 fputs_filtered (" at ", gdb_stdout);
3417 fputs_filtered (b->source_file, gdb_stdout);
3418 printf_filtered (":%d", b->line_number);
3421 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3426 if (b->thread != -1)
3429 /* FIXME: This seems to be redundant and lost here; see the
3430 "stop only in" line a little further down. */
3431 ui_out_text (uiout, " thread ");
3432 ui_out_field_int (uiout, "thread", b->thread);
3434 printf_filtered (" thread %d", b->thread);
3439 ui_out_text (uiout, "\n");
3441 printf_filtered ("\n");
3448 ui_out_text (uiout, "\tstop only in stack frame at ");
3449 ui_out_field_core_addr (uiout, "frame", b->frame);
3450 ui_out_text (uiout, "\n");
3452 printf_filtered ("\tstop only in stack frame at ");
3453 print_address_numeric (b->frame, 1, gdb_stdout);
3454 printf_filtered ("\n");
3462 ui_out_text (uiout, "\tstop only if ");
3463 print_expression (b->cond, stb->stream);
3464 ui_out_field_stream (uiout, "cond", stb);
3465 ui_out_text (uiout, "\n");
3467 printf_filtered ("\tstop only if ");
3468 print_expression (b->cond, gdb_stdout);
3469 printf_filtered ("\n");
3473 if (b->thread != -1)
3475 /* FIXME should make an annotation for this */
3477 ui_out_text (uiout, "\tstop only in thread ");
3478 ui_out_field_int (uiout, "thread", b->thread);
3479 ui_out_text (uiout, "\n");
3481 printf_filtered ("\tstop only in thread %d\n", b->thread);
3485 if (show_breakpoint_hit_counts && b->hit_count)
3487 /* FIXME should make an annotation for this */
3489 if (ep_is_catchpoint (b))
3490 ui_out_text (uiout, "\tcatchpoint");
3492 ui_out_text (uiout, "\tbreakpoint");
3493 ui_out_text (uiout, " already hit ");
3494 ui_out_field_int (uiout, "times", b->hit_count);
3495 if (b->hit_count == 1)
3496 ui_out_text (uiout, " time\n");
3498 ui_out_text (uiout, " times\n");
3500 if (ep_is_catchpoint (b))
3501 printf_filtered ("\tcatchpoint");
3503 printf_filtered ("\tbreakpoint");
3504 printf_filtered (" already hit %d time%s\n",
3505 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3510 /* Output the count also if it is zero, but only if this is
3511 mi. FIXME: Should have a better test for this. */
3512 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3513 if (show_breakpoint_hit_counts && b->hit_count == 0)
3514 ui_out_field_int (uiout, "times", b->hit_count);
3517 if (b->ignore_count)
3521 ui_out_text (uiout, "\tignore next ");
3522 ui_out_field_int (uiout, "ignore", b->ignore_count);
3523 ui_out_text (uiout, " hits\n");
3525 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3529 if ((l = b->commands))
3533 ui_out_list_begin (uiout, "script");
3534 print_command_lines (uiout, l, 4);
3535 ui_out_list_end (uiout);
3539 print_command_line (l, 4, gdb_stdout);
3545 ui_out_list_end (uiout);
3546 do_cleanups (old_chain);
3550 struct captured_breakpoint_query_args
3556 do_captured_breakpoint_query (void *data)
3558 struct captured_breakpoint_query_args *args = data;
3559 register struct breakpoint *b;
3560 CORE_ADDR dummy_addr = 0;
3563 if (args->bnum == b->number)
3565 print_one_breakpoint (b, &dummy_addr);
3573 gdb_breakpoint_query (/* output object, */ int bnum)
3575 struct captured_breakpoint_query_args args;
3577 /* For the moment we don't trust print_one_breakpoint() to not throw
3579 return catch_errors (do_captured_breakpoint_query, &args,
3580 NULL, RETURN_MASK_ALL);
3583 /* Print information on breakpoint number BNUM, or -1 if all.
3584 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3585 is nonzero, process only watchpoints. */
3588 breakpoint_1 (bnum, allflag)
3592 register struct breakpoint *b;
3593 CORE_ADDR last_addr = (CORE_ADDR) -1;
3594 int found_a_breakpoint = 0;
3598 ui_out_table_begin (uiout, 6, "BreakpointTable");
3600 ui_out_table_begin (uiout, 5, "BreakpointTable");
3605 || bnum == b->number)
3607 /* We only print out user settable breakpoints unless the
3610 && b->type != bp_breakpoint
3611 && b->type != bp_catch_load
3612 && b->type != bp_catch_unload
3613 && b->type != bp_catch_fork
3614 && b->type != bp_catch_vfork
3615 && b->type != bp_catch_exec
3616 && b->type != bp_catch_catch
3617 && b->type != bp_catch_throw
3618 && b->type != bp_hardware_breakpoint
3619 && b->type != bp_watchpoint
3620 && b->type != bp_read_watchpoint
3621 && b->type != bp_access_watchpoint
3622 && b->type != bp_hardware_watchpoint)
3625 if (!found_a_breakpoint++)
3627 annotate_breakpoints_headers ();
3630 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3632 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3634 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3636 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3640 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3643 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3644 ui_out_table_body (uiout);
3647 printf_filtered ("Num ");
3649 printf_filtered ("Type ");
3651 printf_filtered ("Disp ");
3653 printf_filtered ("Enb ");
3657 printf_filtered ("Address ");
3660 printf_filtered ("What\n");
3662 annotate_breakpoints_table ();
3665 print_one_breakpoint (b, &last_addr);
3668 if (!found_a_breakpoint)
3672 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3674 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3678 printf_filtered ("No breakpoints or watchpoints.\n");
3680 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3685 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3686 that a comparison of an unsigned with -1 is always false. */
3687 if (last_addr != (CORE_ADDR) -1)
3688 set_next_address (last_addr);
3692 ui_out_table_end (uiout);
3694 /* FIXME? Should this be moved up so that it is only called when
3695 there have been breakpoints? */
3696 annotate_breakpoints_table_end ();
3701 breakpoints_info (bnum_exp, from_tty)
3708 bnum = parse_and_eval_address (bnum_exp);
3710 breakpoint_1 (bnum, 0);
3715 maintenance_info_breakpoints (bnum_exp, from_tty)
3722 bnum = parse_and_eval_address (bnum_exp);
3724 breakpoint_1 (bnum, 1);
3727 /* Print a message describing any breakpoints set at PC. */
3730 describe_other_breakpoints (pc, section)
3734 register int others = 0;
3735 register struct breakpoint *b;
3738 if (b->address == pc)
3739 if (overlay_debugging == 0 ||
3740 b->section == section)
3744 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3746 if (b->address == pc)
3747 if (overlay_debugging == 0 ||
3748 b->section == section)
3754 ((b->enable == disabled ||
3755 b->enable == shlib_disabled ||
3756 b->enable == call_disabled) ? " (disabled)"
3757 : b->enable == permanent ? " (permanent)"
3759 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3761 printf_filtered ("also set at pc ");
3762 print_address_numeric (pc, 1, gdb_stdout);
3763 printf_filtered (".\n");
3767 /* Set the default place to put a breakpoint
3768 for the `break' command with no arguments. */
3771 set_default_breakpoint (valid, addr, symtab, line)
3774 struct symtab *symtab;
3777 default_breakpoint_valid = valid;
3778 default_breakpoint_address = addr;
3779 default_breakpoint_symtab = symtab;
3780 default_breakpoint_line = line;
3783 /* Rescan breakpoints at address ADDRESS,
3784 marking the first one as "first" and any others as "duplicates".
3785 This is so that the bpt instruction is only inserted once.
3786 If we have a permanent breakpoint at ADDRESS, make that one
3787 the official one, and the rest as duplicates. */
3790 check_duplicates (address, section)
3794 register struct breakpoint *b;
3795 register int count = 0;
3796 struct breakpoint *perm_bp = 0;
3798 if (address == 0) /* Watchpoints are uninteresting */
3802 if (b->enable != disabled
3803 && b->enable != shlib_disabled
3804 && b->enable != call_disabled
3805 && b->address == address
3806 && (overlay_debugging == 0 || b->section == section))
3808 /* Have we found a permanent breakpoint? */
3809 if (b->enable == permanent)
3816 b->duplicate = count > 1;
3819 /* If we found a permanent breakpoint at this address, go over the
3820 list again and declare all the other breakpoints there to be the
3824 perm_bp->duplicate = 0;
3826 /* Permanent breakpoint should always be inserted. */
3827 if (! perm_bp->inserted)
3828 internal_error ("allegedly permanent breakpoint is not "
3829 "actually inserted");
3835 internal_error ("another breakpoint was inserted on top of "
3836 "a permanent breakpoint");
3838 if (b->enable != disabled
3839 && b->enable != shlib_disabled
3840 && b->enable != call_disabled
3841 && b->address == address
3842 && (overlay_debugging == 0 || b->section == section))
3848 /* Low level routine to set a breakpoint.
3849 Takes as args the three things that every breakpoint must have.
3850 Returns the breakpoint object so caller can set other things.
3851 Does not set the breakpoint number!
3852 Does not print anything.
3854 ==> This routine should not be called if there is a chance of later
3855 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3856 your arguments BEFORE calling this routine! */
3859 set_raw_breakpoint (sal)
3860 struct symtab_and_line sal;
3862 register struct breakpoint *b, *b1;
3864 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3865 memset (b, 0, sizeof (*b));
3866 b->address = sal.pc;
3867 if (sal.symtab == NULL)
3868 b->source_file = NULL;
3870 b->source_file = savestring (sal.symtab->filename,
3871 strlen (sal.symtab->filename));
3872 b->section = sal.section;
3873 b->language = current_language->la_language;
3874 b->input_radix = input_radix;
3876 b->line_number = sal.line;
3877 b->enable = enabled;
3880 b->ignore_count = 0;
3883 b->dll_pathname = NULL;
3884 b->triggered_dll_pathname = NULL;
3885 b->forked_inferior_pid = 0;
3886 b->exec_pathname = NULL;
3888 /* Add this breakpoint to the end of the chain
3889 so that a list of breakpoints will come out in order
3890 of increasing numbers. */
3892 b1 = breakpoint_chain;
3894 breakpoint_chain = b;
3902 check_duplicates (sal.pc, sal.section);
3903 breakpoints_changed ();
3909 /* Note that the breakpoint object B describes a permanent breakpoint
3910 instruction, hard-wired into the inferior's code. */
3912 make_breakpoint_permanent (struct breakpoint *b)
3914 b->enable = permanent;
3916 /* By definition, permanent breakpoints are already present in the code. */
3920 #ifdef GET_LONGJMP_TARGET
3923 create_longjmp_breakpoint (func_name)
3926 struct symtab_and_line sal;
3927 struct breakpoint *b;
3929 INIT_SAL (&sal); /* initialize to zeroes */
3930 if (func_name != NULL)
3932 struct minimal_symbol *m;
3934 m = lookup_minimal_symbol_text (func_name, NULL,
3935 (struct objfile *) NULL);
3937 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3941 sal.section = find_pc_overlay (sal.pc);
3942 b = set_raw_breakpoint (sal);
3946 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3947 b->disposition = donttouch;
3948 b->enable = disabled;
3951 b->addr_string = strsave (func_name);
3952 b->number = internal_breakpoint_number--;
3955 #endif /* #ifdef GET_LONGJMP_TARGET */
3957 /* Call this routine when stepping and nexting to enable a breakpoint
3958 if we do a longjmp(). When we hit that breakpoint, call
3959 set_longjmp_resume_breakpoint() to figure out where we are going. */
3962 enable_longjmp_breakpoint ()
3964 register struct breakpoint *b;
3967 if (b->type == bp_longjmp)
3969 b->enable = enabled;
3970 check_duplicates (b->address, b->section);
3975 disable_longjmp_breakpoint ()
3977 register struct breakpoint *b;
3980 if (b->type == bp_longjmp
3981 || b->type == bp_longjmp_resume)
3983 b->enable = disabled;
3984 check_duplicates (b->address, b->section);
3989 create_thread_event_breakpoint (address)
3992 struct breakpoint *b;
3993 struct symtab_and_line sal;
3994 char addr_string[80]; /* Surely an addr can't be longer than that. */
3996 INIT_SAL (&sal); /* initialize to zeroes */
3998 sal.section = find_pc_overlay (sal.pc);
3999 if ((b = set_raw_breakpoint (sal)) == NULL)
4002 b->number = internal_breakpoint_number--;
4003 b->disposition = donttouch;
4004 b->type = bp_thread_event; /* XXX: do we need a new type?
4006 b->enable = enabled;
4007 /* addr_string has to be used or breakpoint_re_set will delete me. */
4008 sprintf (addr_string, "*0x%s", paddr (b->address));
4009 b->addr_string = strsave (addr_string);
4015 remove_thread_event_breakpoints (void)
4017 struct breakpoint *b, *temp;
4019 ALL_BREAKPOINTS_SAFE (b, temp)
4020 if (b->type == bp_thread_event)
4021 delete_breakpoint (b);
4026 remove_solib_event_breakpoints ()
4028 register struct breakpoint *b, *temp;
4030 ALL_BREAKPOINTS_SAFE (b, temp)
4031 if (b->type == bp_shlib_event)
4032 delete_breakpoint (b);
4036 create_solib_event_breakpoint (address)
4039 struct breakpoint *b;
4040 struct symtab_and_line sal;
4042 INIT_SAL (&sal); /* initialize to zeroes */
4044 sal.section = find_pc_overlay (sal.pc);
4045 b = set_raw_breakpoint (sal);
4046 b->number = internal_breakpoint_number--;
4047 b->disposition = donttouch;
4048 b->type = bp_shlib_event;
4053 /* Disable any breakpoints that are on code in shared libraries. Only
4054 apply to enabled breakpoints, disabled ones can just stay disabled. */
4057 disable_breakpoints_in_shlibs (silent)
4060 struct breakpoint *b;
4061 int disabled_shlib_breaks = 0;
4063 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4066 #if defined (PC_SOLIB)
4067 if (((b->type == bp_breakpoint) ||
4068 (b->type == bp_hardware_breakpoint)) &&
4069 b->enable == enabled &&
4071 PC_SOLIB (b->address))
4073 b->enable = shlib_disabled;
4076 if (!disabled_shlib_breaks)
4078 target_terminal_ours_for_output ();
4079 warning ("Temporarily disabling shared library breakpoints:");
4081 disabled_shlib_breaks = 1;
4082 warning ("breakpoint #%d ", b->number);
4089 /* Try to reenable any breakpoints in shared libraries. */
4091 re_enable_breakpoints_in_shlibs ()
4093 struct breakpoint *b;
4096 if (b->enable == shlib_disabled)
4100 /* Do not reenable the breakpoint if the shared library
4101 is still not mapped in. */
4102 if (target_read_memory (b->address, buf, 1) == 0)
4103 b->enable = enabled;
4110 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
4115 enum bptype bp_kind;
4117 struct breakpoint *b;
4118 struct symtabs_and_lines sals;
4119 struct cleanup *old_chain;
4120 struct cleanup *canonical_strings_chain = NULL;
4121 char *addr_start = hookname;
4122 char *addr_end = NULL;
4123 char **canonical = (char **) NULL;
4124 int thread = -1; /* All threads. */
4126 /* Set a breakpoint on the specified hook. */
4127 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4128 addr_end = hookname;
4130 if (sals.nelts == 0)
4132 warning ("Unable to set a breakpoint on dynamic linker callback.");
4133 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4134 warning ("GDB will be unable to track shl_load/shl_unload calls");
4137 if (sals.nelts != 1)
4139 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4140 warning ("GDB will be unable to track shl_load/shl_unload calls");
4144 /* Make sure that all storage allocated in decode_line_1 gets freed
4145 in case the following errors out. */
4146 old_chain = make_cleanup (free, sals.sals);
4147 if (canonical != (char **) NULL)
4149 make_cleanup (free, canonical);
4150 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4151 if (canonical[0] != NULL)
4152 make_cleanup (free, canonical[0]);
4155 resolve_sal_pc (&sals.sals[0]);
4157 /* Remove the canonical strings from the cleanup, they are needed below. */
4158 if (canonical != (char **) NULL)
4159 discard_cleanups (canonical_strings_chain);
4161 b = set_raw_breakpoint (sals.sals[0]);
4162 set_breakpoint_count (breakpoint_count + 1);
4163 b->number = breakpoint_count;
4165 b->cond_string = (cond_string == NULL) ?
4166 NULL : savestring (cond_string, strlen (cond_string));
4169 if (canonical != (char **) NULL && canonical[0] != NULL)
4170 b->addr_string = canonical[0];
4171 else if (addr_start)
4172 b->addr_string = savestring (addr_start, addr_end - addr_start);
4174 b->enable = enabled;
4175 b->disposition = tempflag ? del : donttouch;
4177 if (dll_pathname == NULL)
4178 b->dll_pathname = NULL;
4181 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4182 strcpy (b->dll_pathname, dll_pathname);
4187 do_cleanups (old_chain);
4191 create_solib_load_event_breakpoint (hookname, tempflag,
4192 dll_pathname, cond_string)
4198 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4199 cond_string, bp_catch_load);
4203 create_solib_unload_event_breakpoint (hookname, tempflag,
4204 dll_pathname, cond_string)
4210 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4211 cond_string, bp_catch_unload);
4215 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
4218 enum bptype bp_kind;
4220 struct symtab_and_line sal;
4221 struct breakpoint *b;
4222 int thread = -1; /* All threads. */
4229 b = set_raw_breakpoint (sal);
4230 set_breakpoint_count (breakpoint_count + 1);
4231 b->number = breakpoint_count;
4233 b->cond_string = (cond_string == NULL) ?
4234 NULL : savestring (cond_string, strlen (cond_string));
4236 b->addr_string = NULL;
4237 b->enable = enabled;
4238 b->disposition = tempflag ? del : donttouch;
4239 b->forked_inferior_pid = 0;
4247 create_fork_event_catchpoint (tempflag, cond_string)
4251 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4255 create_vfork_event_catchpoint (tempflag, cond_string)
4259 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4263 create_exec_event_catchpoint (tempflag, cond_string)
4267 struct symtab_and_line sal;
4268 struct breakpoint *b;
4269 int thread = -1; /* All threads. */
4276 b = set_raw_breakpoint (sal);
4277 set_breakpoint_count (breakpoint_count + 1);
4278 b->number = breakpoint_count;
4280 b->cond_string = (cond_string == NULL) ?
4281 NULL : savestring (cond_string, strlen (cond_string));
4283 b->addr_string = NULL;
4284 b->enable = enabled;
4285 b->disposition = tempflag ? del : donttouch;
4287 b->type = bp_catch_exec;
4293 hw_breakpoint_used_count ()
4295 register struct breakpoint *b;
4300 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4308 hw_watchpoint_used_count (type, other_type_used)
4310 int *other_type_used;
4312 register struct breakpoint *b;
4315 *other_type_used = 0;
4318 if (b->enable == enabled)
4320 if (b->type == type)
4322 else if ((b->type == bp_hardware_watchpoint ||
4323 b->type == bp_read_watchpoint ||
4324 b->type == bp_access_watchpoint)
4325 && b->enable == enabled)
4326 *other_type_used = 1;
4332 /* Call this after hitting the longjmp() breakpoint. Use this to set
4333 a new breakpoint at the target of the jmp_buf.
4335 FIXME - This ought to be done by setting a temporary breakpoint
4336 that gets deleted automatically... */
4339 set_longjmp_resume_breakpoint (pc, frame)
4341 struct frame_info *frame;
4343 register struct breakpoint *b;
4346 if (b->type == bp_longjmp_resume)
4349 b->enable = enabled;
4351 b->frame = frame->frame;
4354 check_duplicates (b->address, b->section);
4360 disable_watchpoints_before_interactive_call_start ()
4362 struct breakpoint *b;
4366 if (((b->type == bp_watchpoint)
4367 || (b->type == bp_hardware_watchpoint)
4368 || (b->type == bp_read_watchpoint)
4369 || (b->type == bp_access_watchpoint)
4370 || ep_is_exception_catchpoint (b))
4371 && (b->enable == enabled))
4373 b->enable = call_disabled;
4374 check_duplicates (b->address, b->section);
4380 enable_watchpoints_after_interactive_call_stop ()
4382 struct breakpoint *b;
4386 if (((b->type == bp_watchpoint)
4387 || (b->type == bp_hardware_watchpoint)
4388 || (b->type == bp_read_watchpoint)
4389 || (b->type == bp_access_watchpoint)
4390 || ep_is_exception_catchpoint (b))
4391 && (b->enable == call_disabled))
4393 b->enable = enabled;
4394 check_duplicates (b->address, b->section);
4400 /* Set a breakpoint that will evaporate an end of command
4401 at address specified by SAL.
4402 Restrict it to frame FRAME if FRAME is nonzero. */
4405 set_momentary_breakpoint (sal, frame, type)
4406 struct symtab_and_line sal;
4407 struct frame_info *frame;
4410 register struct breakpoint *b;
4411 b = set_raw_breakpoint (sal);
4413 b->enable = enabled;
4414 b->disposition = donttouch;
4415 b->frame = (frame ? frame->frame : 0);
4417 /* If we're debugging a multi-threaded program, then we
4418 want momentary breakpoints to be active in only a
4419 single thread of control. */
4420 if (in_thread_list (inferior_pid))
4421 b->thread = pid_to_thread_id (inferior_pid);
4427 /* Tell the user we have just set a breakpoint B. */
4431 struct breakpoint *b;
4435 struct cleanup *old_chain;
4436 struct ui_stream *stb;
4438 stb = ui_out_stream_new (uiout);
4439 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
4442 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4443 watchpoint) other than breakpoint creation. It should be possible to
4444 clean this up and at the same time replace the random calls to
4445 breakpoint_changed with this hook, as has already been done for
4446 delete_breakpoint_hook and so on. */
4447 if (create_breakpoint_hook)
4448 create_breakpoint_hook (b);
4449 breakpoint_create_event (b->number);
4454 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4458 ui_out_text (uiout, "Watchpoint ");
4459 ui_out_list_begin (uiout, "wpt");
4460 ui_out_field_int (uiout, "number", b->number);
4461 ui_out_text (uiout, ": ");
4462 print_expression (b->exp, stb->stream);
4463 ui_out_field_stream (uiout, "exp", stb);
4464 ui_out_list_end (uiout);
4466 case bp_hardware_watchpoint:
4467 ui_out_text (uiout, "Hardware watchpoint ");
4468 ui_out_list_begin (uiout, "wpt");
4469 ui_out_field_int (uiout, "number", b->number);
4470 ui_out_text (uiout, ": ");
4471 print_expression (b->exp, stb->stream);
4472 ui_out_field_stream (uiout, "exp", stb);
4473 ui_out_list_end (uiout);
4477 printf_filtered ("Watchpoint %d: ", b->number);
4478 print_expression (b->exp, gdb_stdout);
4480 case bp_hardware_watchpoint:
4481 printf_filtered ("Hardware watchpoint %d: ", b->number);
4482 print_expression (b->exp, gdb_stdout);
4486 case bp_read_watchpoint:
4487 ui_out_text (uiout, "Hardware read watchpoint ");
4488 ui_out_list_begin (uiout, "hw-rwpt");
4489 ui_out_field_int (uiout, "number", b->number);
4490 ui_out_text (uiout, ": ");
4491 print_expression (b->exp, stb->stream);
4492 ui_out_field_stream (uiout, "exp", stb);
4493 ui_out_list_end (uiout);
4495 case bp_access_watchpoint:
4496 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4497 ui_out_list_begin (uiout, "hw-awpt");
4498 ui_out_field_int (uiout, "number", b->number);
4499 ui_out_text (uiout, ": ");
4500 print_expression (b->exp, stb->stream);
4501 ui_out_field_stream (uiout, "exp", stb);
4502 ui_out_list_end (uiout);
4505 case bp_read_watchpoint:
4506 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4507 print_expression (b->exp, gdb_stdout);
4509 case bp_access_watchpoint:
4510 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4512 print_expression (b->exp, gdb_stdout);
4517 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4523 printf_filtered ("Breakpoint %d", b->number);
4526 case bp_hardware_breakpoint:
4528 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4534 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4538 case bp_catch_unload:
4539 printf_filtered ("Catchpoint %d (%s %s)",
4541 (b->type == bp_catch_load) ? "load" : "unload",
4542 (b->dll_pathname != NULL) ?
4543 b->dll_pathname : "<any library>");
4546 case bp_catch_vfork:
4547 printf_filtered ("Catchpoint %d (%s)",
4549 (b->type == bp_catch_fork) ? "fork" : "vfork");
4552 printf_filtered ("Catchpoint %d (exec)",
4555 case bp_catch_catch:
4556 case bp_catch_throw:
4557 printf_filtered ("Catchpoint %d (%s)",
4559 (b->type == bp_catch_catch) ? "catch" : "throw");
4565 case bp_longjmp_resume:
4566 case bp_step_resume:
4567 case bp_through_sigtramp:
4569 case bp_watchpoint_scope:
4570 case bp_shlib_event:
4571 case bp_thread_event:
4576 if (addressprint || b->source_file == NULL)
4578 printf_filtered (" at ");
4579 print_address_numeric (b->address, 1, gdb_stdout);
4582 printf_filtered (": file %s, line %d.",
4583 b->source_file, b->line_number);
4584 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4585 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4588 do_cleanups (old_chain);
4591 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4594 printf_filtered ("\n");
4598 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4599 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4600 COND[i] and COND_STRING[i] values.
4602 NOTE: If the function succeeds, the caller is expected to cleanup
4603 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4604 array contents). If the function fails (error() is called), the
4605 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4606 COND and SALS arrays and each of those arrays contents. */
4609 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4610 struct expression **cond, char **cond_string,
4611 enum bptype type, enum bpdisp disposition,
4612 int thread, int ignore_count, int from_tty)
4614 if (type == bp_hardware_breakpoint)
4616 int i = hw_breakpoint_used_count ();
4617 int target_resources_ok =
4618 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4620 if (target_resources_ok == 0)
4621 error ("No hardware breakpoint support in the target.");
4622 else if (target_resources_ok < 0)
4623 error ("Hardware breakpoints used exceeds limit.");
4626 /* Now set all the breakpoints. */
4629 for (i = 0; i < sals.nelts; i++)
4631 struct breakpoint *b;
4632 struct symtab_and_line sal = sals.sals[i];
4635 describe_other_breakpoints (sal.pc, sal.section);
4637 b = set_raw_breakpoint (sal);
4638 set_breakpoint_count (breakpoint_count + 1);
4639 b->number = breakpoint_count;
4643 b->addr_string = addr_string[i];
4644 b->cond_string = cond_string[i];
4645 b->ignore_count = ignore_count;
4646 b->enable = enabled;
4647 b->disposition = disposition;
4653 /* Parse ARG which is assumed to be a SAL specification possibly
4654 followed by conditionals. On return, SALS contains an array of SAL
4655 addresses found. ADDR_STRING contains a vector of (canonical)
4656 address strings. ARG points to the end of the SAL. */
4659 parse_breakpoint_sals (char **address,
4660 struct symtabs_and_lines *sals,
4661 char ***addr_string)
4663 char *addr_start = *address;
4664 *addr_string = NULL;
4665 /* If no arg given, or if first arg is 'if ', use the default
4667 if ((*address) == NULL
4668 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4670 if (default_breakpoint_valid)
4672 struct symtab_and_line sal;
4673 INIT_SAL (&sal); /* initialize to zeroes */
4674 sals->sals = (struct symtab_and_line *)
4675 xmalloc (sizeof (struct symtab_and_line));
4676 sal.pc = default_breakpoint_address;
4677 sal.line = default_breakpoint_line;
4678 sal.symtab = default_breakpoint_symtab;
4679 sal.section = find_pc_overlay (sal.pc);
4680 sals->sals[0] = sal;
4684 error ("No default breakpoint address now.");
4688 /* Force almost all breakpoints to be in terms of the
4689 current_source_symtab (which is decode_line_1's default). This
4690 should produce the results we want almost all of the time while
4691 leaving default_breakpoint_* alone. */
4692 if (default_breakpoint_valid
4693 && (!current_source_symtab
4694 || (strchr ("+-", (*address)[0]) != NULL)))
4695 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4696 default_breakpoint_line, addr_string);
4698 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4700 /* For any SAL that didn't have a canonical string, fill one in. */
4701 if (sals->nelts > 0 && *addr_string == NULL)
4702 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4703 if (addr_start != (*address))
4706 for (i = 0; i < sals->nelts; i++)
4708 /* Add the string if not present. */
4709 if ((*addr_string)[i] == NULL)
4710 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4716 /* Convert each SAL into a real PC. Verify that the PC can be
4717 inserted as a breakpoint. If it can't throw an error. */
4720 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4724 for (i = 0; i < sals->nelts; i++)
4726 resolve_sal_pc (&sals->sals[i]);
4728 /* It's possible for the PC to be nonzero, but still an illegal
4729 value on some targets.
4731 For example, on HP-UX if you start gdb, and before running the
4732 inferior you try to set a breakpoint on a shared library function
4733 "foo" where the inferior doesn't call "foo" directly but does
4734 pass its address to another function call, then we do find a
4735 minimal symbol for the "foo", but it's address is invalid.
4736 (Appears to be an index into a table that the loader sets up
4737 when the inferior is run.)
4739 Give the target a chance to bless sals.sals[i].pc before we
4740 try to make a breakpoint for it. */
4741 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4743 if (address == NULL)
4744 error ("Cannot break without a running program.");
4746 error ("Cannot break on %s without a running program.",
4752 /* Set a breakpoint according to ARG (function, linenum or *address)
4753 flag: first bit : 0 non-temporary, 1 temporary.
4754 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4757 break_command_1 (arg, flag, from_tty)
4761 int tempflag, hardwareflag;
4762 struct symtabs_and_lines sals;
4763 register struct expression **cond = 0;
4764 /* Pointers in arg to the start, and one past the end, of the
4766 char **cond_string = (char **) NULL;
4767 char *addr_start = arg;
4769 struct cleanup *old_chain;
4770 struct cleanup *breakpoint_chain = NULL;
4773 int ignore_count = 0;
4775 hardwareflag = flag & BP_HARDWAREFLAG;
4776 tempflag = flag & BP_TEMPFLAG;
4781 parse_breakpoint_sals (&arg, &sals, &addr_string);
4786 /* Create a chain of things that always need to be cleaned up. */
4787 old_chain = make_cleanup (null_cleanup, 0);
4789 /* Make sure that all storage allocated to SALS gets freed. */
4790 make_cleanup (free, sals.sals);
4792 /* Cleanup the addr_string array but not its contents. */
4793 make_cleanup (free, addr_string);
4795 /* Allocate space for all the cond expressions. */
4796 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4797 make_cleanup (free, cond);
4799 /* Allocate space for all the cond strings. */
4800 cond_string = xcalloc (sals.nelts, sizeof (char **));
4801 make_cleanup (free, cond_string);
4803 /* ----------------------------- SNIP -----------------------------
4804 Anything added to the cleanup chain beyond this point is assumed
4805 to be part of a breakpoint. If the breakpoint create succeeds
4806 then the memory is not reclaimed. */
4807 breakpoint_chain = make_cleanup (null_cleanup, 0);
4809 /* Mark the contents of the addr_string for cleanup. These go on
4810 the breakpoint_chain and only occure if the breakpoint create
4812 for (i = 0; i < sals.nelts; i++)
4814 if (addr_string[i] != NULL)
4815 make_cleanup (free, addr_string[i]);
4818 /* Resolve all line numbers to PC's and verify that the addresses
4819 are ok for the target. */
4820 breakpoint_sals_to_pc (&sals, addr_start);
4822 /* Verify that condition can be parsed, before setting any
4823 breakpoints. Allocate a separate condition expression for each
4825 thread = -1; /* No specific thread yet */
4826 for (i = 0; i < sals.nelts; i++)
4833 char *cond_start = NULL;
4834 char *cond_end = NULL;
4835 while (*tok == ' ' || *tok == '\t')
4840 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4843 toklen = end_tok - tok;
4845 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4847 tok = cond_start = end_tok + 1;
4848 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4849 make_cleanup (free, cond[i]);
4851 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4852 make_cleanup (free, cond_string[i]);
4854 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4860 thread = strtol (tok, &tok, 0);
4862 error ("Junk after thread keyword.");
4863 if (!valid_thread_id (thread))
4864 error ("Unknown thread %d\n", thread);
4867 error ("Junk at end of arguments.");
4871 create_breakpoints (sals, addr_string, cond, cond_string,
4872 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4873 tempflag ? del : donttouch,
4874 thread, ignore_count, from_tty);
4878 warning ("Multiple breakpoints were set.");
4879 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4881 /* That's it. Discard the cleanups for data inserted into the
4883 discard_cleanups (breakpoint_chain);
4884 /* But cleanup everything else. */
4885 do_cleanups (old_chain);
4888 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4889 linenum or *address) with COND and IGNORE_COUNT. */
4891 struct captured_breakpoint_args
4902 do_captured_breakpoint (void *data)
4904 struct captured_breakpoint_args *args = data;
4905 struct symtabs_and_lines sals;
4906 register struct expression **cond;
4907 struct cleanup *old_chain;
4908 struct cleanup *breakpoint_chain = NULL;
4915 /* Parse the source and lines spec. Delay check that the expression
4916 didn't contain trailing garbage until after cleanups are in
4920 address_end = args->address;
4922 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4927 /* Create a chain of things at always need to be cleaned up. */
4928 old_chain = make_cleanup (null_cleanup, 0);
4930 /* Always have a addr_string array, even if it is empty. */
4931 make_cleanup (free, addr_string);
4933 /* Make sure that all storage allocated to SALS gets freed. */
4934 make_cleanup (free, sals.sals);
4936 /* Allocate space for all the cond expressions. */
4937 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4938 make_cleanup (free, cond);
4940 /* Allocate space for all the cond strings. */
4941 cond_string = xcalloc (sals.nelts, sizeof (char **));
4942 make_cleanup (free, cond_string);
4944 /* ----------------------------- SNIP -----------------------------
4945 Anything added to the cleanup chain beyond this point is assumed
4946 to be part of a breakpoint. If the breakpoint create goes
4947 through then that memory is not cleaned up. */
4948 breakpoint_chain = make_cleanup (null_cleanup, 0);
4950 /* Mark the contents of the addr_string for cleanup. These go on
4951 the breakpoint_chain and only occure if the breakpoint create
4953 for (i = 0; i < sals.nelts; i++)
4955 if (addr_string[i] != NULL)
4956 make_cleanup (free, addr_string[i]);
4959 /* Wait until now before checking for garbage at the end of the
4960 address. That way cleanups can take care of freeing any
4962 if (*address_end != '\0')
4963 error ("Garbage %s following breakpoint address", address_end);
4965 /* Resolve all line numbers to PC's. */
4966 breakpoint_sals_to_pc (&sals, args->address);
4968 /* Verify that conditions can be parsed, before setting any
4970 for (i = 0; i < sals.nelts; i++)
4972 if (args->condition != NULL)
4974 char *tok = args->condition;
4975 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4977 error ("Garbage %s follows condition", tok);
4978 make_cleanup (free, cond[i]);
4979 cond_string[i] = xstrdup (args->condition);
4983 create_breakpoints (sals, addr_string, cond, cond_string,
4984 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4985 args->tempflag ? del : donttouch,
4986 args->thread, args->ignore_count, 0/*from-tty*/);
4988 /* That's it. Discard the cleanups for data inserted into the
4990 discard_cleanups (breakpoint_chain);
4991 /* But cleanup everything else. */
4992 do_cleanups (old_chain);
4997 gdb_breakpoint (char *address, char *condition,
4998 int hardwareflag, int tempflag,
4999 int thread, int ignore_count)
5001 struct captured_breakpoint_args args;
5002 args.address = address;
5003 args.condition = condition;
5004 args.hardwareflag = hardwareflag;
5005 args.tempflag = tempflag;
5006 args.thread = thread;
5007 args.ignore_count = ignore_count;
5008 return catch_errors (do_captured_breakpoint, &args,
5009 NULL, RETURN_MASK_ALL);
5014 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
5019 struct frame_info *frame;
5020 CORE_ADDR low, high, selected_pc = 0;
5021 char *extra_args, *level_arg, *addr_string;
5022 int extra_args_len = 0, if_arg = 0;
5025 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5028 if (default_breakpoint_valid)
5032 selected_pc = selected_frame->pc;
5037 error ("No selected frame.");
5040 error ("No default breakpoint address now.");
5044 extra_args = strchr (arg, ' ');
5048 extra_args_len = strlen (extra_args);
5049 level_arg = (char *) xmalloc (extra_args - arg);
5050 strncpy (level_arg, arg, extra_args - arg - 1);
5051 level_arg[extra_args - arg - 1] = '\0';
5055 level_arg = (char *) xmalloc (strlen (arg) + 1);
5056 strcpy (level_arg, arg);
5059 frame = parse_frame_specification (level_arg);
5061 selected_pc = frame->pc;
5068 extra_args_len = strlen (arg);
5073 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5075 addr_string = (char *) xmalloc (26 + extra_args_len);
5077 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
5079 sprintf (addr_string, "*0x%s", paddr_nz (high));
5080 break_command_1 (addr_string, flag, from_tty);
5084 error ("No function contains the specified address");
5087 error ("Unable to set breakpoint at procedure exit");
5092 break_at_finish_command_1 (arg, flag, from_tty)
5097 char *addr_string, *break_string, *beg_addr_string;
5098 CORE_ADDR low, high;
5099 struct symtabs_and_lines sals;
5100 struct symtab_and_line sal;
5101 struct cleanup *old_chain;
5103 int extra_args_len = 0;
5107 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5109 if (default_breakpoint_valid)
5113 addr_string = (char *) xmalloc (15);
5114 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5119 error ("No selected frame.");
5122 error ("No default breakpoint address now.");
5126 addr_string = (char *) xmalloc (strlen (arg) + 1);
5127 strcpy (addr_string, arg);
5133 extra_args_len = strlen (arg);
5137 /* get the stuff after the function name or address */
5138 extra_args = strchr (arg, ' ');
5142 extra_args_len = strlen (extra_args);
5149 beg_addr_string = addr_string;
5150 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5153 free (beg_addr_string);
5154 old_chain = make_cleanup (free, sals.sals);
5155 for (i = 0; (i < sals.nelts); i++)
5158 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5160 break_string = (char *) xmalloc (extra_args_len + 26);
5162 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5164 sprintf (break_string, "*0x%s", paddr_nz (high));
5165 break_command_1 (break_string, flag, from_tty);
5166 free (break_string);
5169 error ("No function contains the specified address");
5173 warning ("Multiple breakpoints were set.\n");
5174 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5176 do_cleanups (old_chain);
5180 /* Helper function for break_command_1 and disassemble_command. */
5183 resolve_sal_pc (sal)
5184 struct symtab_and_line *sal;
5188 if (sal->pc == 0 && sal->symtab != NULL)
5190 if (!find_line_pc (sal->symtab, sal->line, &pc))
5191 error ("No line %d in file \"%s\".",
5192 sal->line, sal->symtab->filename);
5196 if (sal->section == 0 && sal->symtab != NULL)
5198 struct blockvector *bv;
5203 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5206 b = BLOCKVECTOR_BLOCK (bv, index);
5207 sym = block_function (b);
5210 fixup_symbol_section (sym, sal->symtab->objfile);
5211 sal->section = SYMBOL_BFD_SECTION (sym);
5215 /* It really is worthwhile to have the section, so we'll just
5216 have to look harder. This case can be executed if we have
5217 line numbers but no functions (as can happen in assembly
5220 struct minimal_symbol *msym;
5222 msym = lookup_minimal_symbol_by_pc (sal->pc);
5224 sal->section = SYMBOL_BFD_SECTION (msym);
5231 break_command (arg, from_tty)
5235 break_command_1 (arg, 0, from_tty);
5239 break_at_finish_command (arg, from_tty)
5243 break_at_finish_command_1 (arg, 0, from_tty);
5247 break_at_finish_at_depth_command (arg, from_tty)
5251 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5255 tbreak_command (arg, from_tty)
5259 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5263 tbreak_at_finish_command (arg, from_tty)
5267 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5271 hbreak_command (arg, from_tty)
5275 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5279 thbreak_command (arg, from_tty)
5283 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5287 stop_command (arg, from_tty)
5291 printf_filtered ("Specify the type of breakpoint to set.\n\
5292 Usage: stop in <function | address>\n\
5297 stopin_command (arg, from_tty)
5303 if (arg == (char *) NULL)
5305 else if (*arg != '*')
5310 /* look for a ':'. If this is a line number specification, then
5311 say it is bad, otherwise, it should be an address or
5312 function/method name */
5313 while (*argptr && !hasColon)
5315 hasColon = (*argptr == ':');
5320 badInput = (*argptr != ':'); /* Not a class::method */
5322 badInput = isdigit (*arg); /* a simple line number */
5326 printf_filtered ("Usage: stop in <function | address>\n");
5328 break_command_1 (arg, 0, from_tty);
5332 stopat_command (arg, from_tty)
5338 if (arg == (char *) NULL || *arg == '*') /* no line number */
5345 /* look for a ':'. If there is a '::' then get out, otherwise
5346 it is probably a line number. */
5347 while (*argptr && !hasColon)
5349 hasColon = (*argptr == ':');
5354 badInput = (*argptr == ':'); /* we have class::method */
5356 badInput = !isdigit (*arg); /* not a line number */
5360 printf_filtered ("Usage: stop at <line>\n");
5362 break_command_1 (arg, 0, from_tty);
5366 /* accessflag: hw_write: watch write,
5367 hw_read: watch read,
5368 hw_access: watch access (read or write) */
5370 watch_command_1 (arg, accessflag, from_tty)
5375 struct breakpoint *b;
5376 struct symtab_and_line sal;
5377 struct expression *exp;
5378 struct block *exp_valid_block;
5379 struct value *val, *mark;
5380 struct frame_info *frame;
5381 struct frame_info *prev_frame = NULL;
5382 char *exp_start = NULL;
5383 char *exp_end = NULL;
5384 char *tok, *end_tok;
5386 char *cond_start = NULL;
5387 char *cond_end = NULL;
5388 struct expression *cond = NULL;
5389 int i, other_type_used, target_resources_ok = 0;
5390 enum bptype bp_type;
5393 INIT_SAL (&sal); /* initialize to zeroes */
5395 /* Parse arguments. */
5396 innermost_block = NULL;
5398 exp = parse_exp_1 (&arg, 0, 0);
5400 exp_valid_block = innermost_block;
5401 mark = value_mark ();
5402 val = evaluate_expression (exp);
5403 release_value (val);
5404 if (VALUE_LAZY (val))
5405 value_fetch_lazy (val);
5408 while (*tok == ' ' || *tok == '\t')
5412 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5415 toklen = end_tok - tok;
5416 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5418 tok = cond_start = end_tok + 1;
5419 cond = parse_exp_1 (&tok, 0, 0);
5423 error ("Junk at end of command.");
5425 if (accessflag == hw_read)
5426 bp_type = bp_read_watchpoint;
5427 else if (accessflag == hw_access)
5428 bp_type = bp_access_watchpoint;
5430 bp_type = bp_hardware_watchpoint;
5432 mem_cnt = can_use_hardware_watchpoint (val);
5433 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5434 error ("Expression cannot be implemented with read/access watchpoint.");
5437 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5438 target_resources_ok =
5439 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5441 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5442 error ("Target does not support this type of hardware watchpoint.");
5444 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5445 error ("Target can only support one kind of HW watchpoint at a time.");
5448 #if defined(HPUXHPPA)
5449 /* On HP-UX if you set a h/w
5450 watchpoint before the "run" command, the inferior dies with a e.g.,
5451 SIGILL once you start it. I initially believed this was due to a
5452 bad interaction between page protection traps and the initial
5453 startup sequence by the dynamic linker.
5455 However, I tried avoiding that by having HP-UX's implementation of
5456 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
5457 yet, which forced slow watches before a "run" or "attach", and it
5458 still fails somewhere in the startup code.
5460 Until I figure out what's happening, I'm disallowing watches altogether
5461 before the "run" or "attach" command. We'll tell the user they must
5462 set watches after getting the program started. */
5463 if (!target_has_execution)
5465 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5468 #endif /* HPUXHPPA */
5470 /* Now set up the breakpoint. */
5471 b = set_raw_breakpoint (sal);
5472 set_breakpoint_count (breakpoint_count + 1);
5473 b->number = breakpoint_count;
5474 b->disposition = donttouch;
5476 b->exp_valid_block = exp_valid_block;
5477 b->exp_string = savestring (exp_start, exp_end - exp_start);
5481 b->cond_string = savestring (cond_start, cond_end - cond_start);
5485 frame = block_innermost_frame (exp_valid_block);
5488 prev_frame = get_prev_frame (frame);
5489 b->watchpoint_frame = frame->frame;
5492 b->watchpoint_frame = (CORE_ADDR) 0;
5494 if (mem_cnt && target_resources_ok > 0)
5497 b->type = bp_watchpoint;
5499 /* If the expression is "local", then set up a "watchpoint scope"
5500 breakpoint at the point where we've left the scope of the watchpoint
5502 if (innermost_block)
5506 struct breakpoint *scope_breakpoint;
5507 struct symtab_and_line scope_sal;
5509 INIT_SAL (&scope_sal); /* initialize to zeroes */
5510 scope_sal.pc = get_frame_pc (prev_frame);
5511 scope_sal.section = find_pc_overlay (scope_sal.pc);
5513 scope_breakpoint = set_raw_breakpoint (scope_sal);
5514 set_breakpoint_count (breakpoint_count + 1);
5515 scope_breakpoint->number = breakpoint_count;
5517 scope_breakpoint->type = bp_watchpoint_scope;
5518 scope_breakpoint->enable = enabled;
5520 /* Automatically delete the breakpoint when it hits. */
5521 scope_breakpoint->disposition = del;
5523 /* Only break in the proper frame (help with recursion). */
5524 scope_breakpoint->frame = prev_frame->frame;
5526 /* Set the address at which we will stop. */
5527 scope_breakpoint->address = get_frame_pc (prev_frame);
5529 /* The scope breakpoint is related to the watchpoint. We
5530 will need to act on them together. */
5531 b->related_breakpoint = scope_breakpoint;
5534 value_free_to_mark (mark);
5538 /* Return count of locations need to be watched and can be handled
5539 in hardware. If the watchpoint can not be handled
5540 in hardware return zero. */
5542 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5543 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5544 ((BYTE_SIZE) <= (REGISTER_SIZE))
5547 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5548 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5549 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
5553 can_use_hardware_watchpoint (v)
5556 int found_memory_cnt = 0;
5557 struct value *head = v;
5559 /* Did the user specifically forbid us to use hardware watchpoints? */
5560 if (!can_use_hw_watchpoints)
5563 /* Make sure that the value of the expression depends only upon
5564 memory contents, and values computed from them within GDB. If we
5565 find any register references or function calls, we can't use a
5566 hardware watchpoint.
5568 The idea here is that evaluating an expression generates a series
5569 of values, one holding the value of every subexpression. (The
5570 expression a*b+c has five subexpressions: a, b, a*b, c, and
5571 a*b+c.) GDB's values hold almost enough information to establish
5572 the criteria given above --- they identify memory lvalues,
5573 register lvalues, computed values, etcetera. So we can evaluate
5574 the expression, and then scan the chain of values that leaves
5575 behind to decide whether we can detect any possible change to the
5576 expression's final value using only hardware watchpoints.
5578 However, I don't think that the values returned by inferior
5579 function calls are special in any way. So this function may not
5580 notice that an expression involving an inferior function call
5581 can't be watched with hardware watchpoints. FIXME. */
5582 for (; v; v = v->next)
5584 if (VALUE_LVAL (v) == lval_memory)
5587 /* A lazy memory lvalue is one that GDB never needed to fetch;
5588 we either just used its address (e.g., `a' in `a.b') or
5589 we never needed it at all (e.g., `a' in `a,b'). */
5593 /* Ahh, memory we actually used! Check if we can cover
5594 it with hardware watchpoints. */
5595 struct type *vtype = check_typedef (VALUE_TYPE (v));
5597 /* We only watch structs and arrays if user asked for it
5598 explicitly, never if they just happen to appear in a
5599 middle of some value chain. */
5601 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5602 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5604 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5605 int len = TYPE_LENGTH (VALUE_TYPE (v));
5607 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5614 else if (v->lval != not_lval && v->modifiable == 0)
5615 return 0; /* ??? What does this represent? */
5616 else if (v->lval == lval_register)
5617 return 0; /* cannot watch a register with a HW watchpoint */
5620 /* The expression itself looks suitable for using a hardware
5621 watchpoint, but give the target machine a chance to reject it. */
5622 return found_memory_cnt;
5627 watch_command_wrapper (arg, from_tty)
5631 watch_command (arg, from_tty);
5635 watch_command (arg, from_tty)
5639 watch_command_1 (arg, hw_write, from_tty);
5644 rwatch_command_wrapper (arg, from_tty)
5648 rwatch_command (arg, from_tty);
5652 rwatch_command (arg, from_tty)
5656 watch_command_1 (arg, hw_read, from_tty);
5661 awatch_command_wrapper (arg, from_tty)
5665 awatch_command (arg, from_tty);
5669 awatch_command (arg, from_tty)
5673 watch_command_1 (arg, hw_access, from_tty);
5677 /* Helper routines for the until_command routine in infcmd.c. Here
5678 because it uses the mechanisms of breakpoints. */
5680 /* This function is called by fetch_inferior_event via the
5681 cmd_continuation pointer, to complete the until command. It takes
5682 care of cleaning up the temporary breakpoints set up by the until
5685 until_break_command_continuation (struct continuation_arg *arg)
5687 struct cleanup *cleanups;
5689 cleanups = (struct cleanup *) arg->data;
5690 do_exec_cleanups (cleanups);
5695 until_break_command (arg, from_tty)
5699 struct symtabs_and_lines sals;
5700 struct symtab_and_line sal;
5701 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5702 struct breakpoint *breakpoint;
5703 struct cleanup *old_chain;
5704 struct continuation_arg *arg1;
5707 clear_proceed_status ();
5709 /* Set a breakpoint where the user wants it and at return from
5712 if (default_breakpoint_valid)
5713 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5714 default_breakpoint_line, (char ***) NULL);
5716 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5717 0, (char ***) NULL);
5719 if (sals.nelts != 1)
5720 error ("Couldn't get information on specified line.");
5723 free ((PTR) sals.sals); /* malloc'd, so freed */
5726 error ("Junk at end of arguments.");
5728 resolve_sal_pc (&sal);
5730 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5732 if (!event_loop_p || !target_can_async_p ())
5733 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
5736 old_chain = make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5738 /* If we are running asynchronously, and the target supports async
5739 execution, we are not waiting for the target to stop, in the call
5740 tp proceed, below. This means that we cannot delete the
5741 brekpoints until the target has actually stopped. The only place
5742 where we get a chance to do that is in fetch_inferior_event, so
5743 we must set things up for that. */
5745 if (event_loop_p && target_can_async_p ())
5747 /* In this case the arg for the continuation is just the point
5748 in the exec_cleanups chain from where to start doing
5749 cleanups, because all the continuation does is the cleanups in
5750 the exec_cleanup_chain. */
5752 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5754 arg1->data = (PTR) old_chain;
5756 add_continuation (until_break_command_continuation, arg1);
5759 /* Keep within the current frame */
5763 sal = find_pc_line (prev_frame->pc, 0);
5764 sal.pc = prev_frame->pc;
5765 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5766 if (!event_loop_p || !target_can_async_p ())
5767 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5769 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5772 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5773 /* Do the cleanups now, anly if we are not running asynchronously,
5774 of if we are, but the target is still synchronous. */
5775 if (!event_loop_p || !target_can_async_p ())
5776 do_cleanups (old_chain);
5780 /* These aren't used; I don't konw what they were for. */
5781 /* Set a breakpoint at the catch clause for NAME. */
5783 catch_breakpoint (name)
5789 disable_catch_breakpoint ()
5794 delete_catch_breakpoint ()
5799 enable_catch_breakpoint ()
5806 struct sal_chain *next;
5807 struct symtab_and_line sal;
5811 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5812 had been commented out in the v.4.16 sources, and stays
5813 disabled there now because "catch NAME" syntax isn't allowed.
5815 /* This isn't used; I don't know what it was for. */
5816 /* For each catch clause identified in ARGS, run FUNCTION
5817 with that clause as an argument. */
5818 static struct symtabs_and_lines
5819 map_catch_names (args, function)
5823 register char *p = args;
5825 struct symtabs_and_lines sals;
5827 struct sal_chain *sal_chain = 0;
5831 error_no_arg ("one or more catch names");
5839 /* Don't swallow conditional part. */
5840 if (p1[0] == 'i' && p1[1] == 'f'
5841 && (p1[2] == ' ' || p1[2] == '\t'))
5847 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5851 if (*p1 && *p1 != ' ' && *p1 != '\t')
5852 error ("Arguments must be catch names.");
5858 struct sal_chain *next = (struct sal_chain *)
5859 alloca (sizeof (struct sal_chain));
5860 next->next = sal_chain;
5861 next->sal = get_catch_sal (p);
5866 printf_unfiltered ("No catch clause for exception %s.\n", p);
5871 while (*p == ' ' || *p == '\t')
5877 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5879 static struct symtabs_and_lines
5880 get_catch_sals (this_level_only)
5881 int this_level_only;
5883 register struct blockvector *bl;
5884 register struct block *block;
5885 int index, have_default = 0;
5887 struct symtabs_and_lines sals;
5888 struct sal_chain *sal_chain = 0;
5889 char *blocks_searched;
5891 /* Not sure whether an error message is always the correct response,
5892 but it's better than a core dump. */
5893 if (selected_frame == NULL)
5894 error ("No selected frame.");
5895 block = get_frame_block (selected_frame);
5896 pc = selected_frame->pc;
5902 error ("No symbol table info available.\n");
5904 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5905 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5906 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5910 CORE_ADDR end = BLOCK_END (block) - 4;
5913 if (bl != blockvector_for_pc (end, &index))
5914 error ("blockvector blotch");
5915 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5916 error ("blockvector botch");
5917 last_index = BLOCKVECTOR_NBLOCKS (bl);
5920 /* Don't print out blocks that have gone by. */
5921 while (index < last_index
5922 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5925 while (index < last_index
5926 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5928 if (blocks_searched[index] == 0)
5930 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5933 register struct symbol *sym;
5935 nsyms = BLOCK_NSYMS (b);
5937 for (i = 0; i < nsyms; i++)
5939 sym = BLOCK_SYM (b, i);
5940 if (STREQ (SYMBOL_NAME (sym), "default"))
5946 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5948 struct sal_chain *next = (struct sal_chain *)
5949 alloca (sizeof (struct sal_chain));
5950 next->next = sal_chain;
5951 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5956 blocks_searched[index] = 1;
5962 if (sal_chain && this_level_only)
5965 /* After handling the function's top-level block, stop.
5966 Don't continue to its superblock, the block of
5967 per-file symbols. */
5968 if (BLOCK_FUNCTION (block))
5970 block = BLOCK_SUPERBLOCK (block);
5975 struct sal_chain *tmp_chain;
5977 /* Count the number of entries. */
5978 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5979 tmp_chain = tmp_chain->next)
5983 sals.sals = (struct symtab_and_line *)
5984 xmalloc (index * sizeof (struct symtab_and_line));
5985 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5986 sals.sals[index] = sal_chain->sal;
5993 ep_skip_leading_whitespace (s)
5996 if ((s == NULL) || (*s == NULL))
5998 while (isspace (**s))
6002 /* This function examines a string, and attempts to find a token
6003 that might be an event name in the leading characters. If a
6004 possible match is found, a pointer to the last character of
6005 the token is returned. Else, NULL is returned. */
6008 ep_find_event_name_end (arg)
6012 char *event_name_end = NULL;
6014 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6018 /* We break out of the loop when we find a token delimiter.
6019 Basically, we're looking for alphanumerics and underscores;
6020 anything else delimites the token. */
6023 if (!isalnum (*s) && (*s != '_'))
6029 return event_name_end;
6033 /* This function attempts to parse an optional "if <cond>" clause
6034 from the arg string. If one is not found, it returns NULL.
6036 Else, it returns a pointer to the condition string. (It does not
6037 attempt to evaluate the string against a particular block.) And,
6038 it updates arg to point to the first character following the parsed
6039 if clause in the arg string. */
6042 ep_parse_optional_if_clause (arg)
6047 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6050 /* Skip the "if" keyword. */
6053 /* Skip any extra leading whitespace, and record the start of the
6054 condition string. */
6055 ep_skip_leading_whitespace (arg);
6058 /* Assume that the condition occupies the remainder of the arg string. */
6059 (*arg) += strlen (cond_string);
6064 /* This function attempts to parse an optional filename from the arg
6065 string. If one is not found, it returns NULL.
6067 Else, it returns a pointer to the parsed filename. (This function
6068 makes no attempt to verify that a file of that name exists, or is
6069 accessible.) And, it updates arg to point to the first character
6070 following the parsed filename in the arg string.
6072 Note that clients needing to preserve the returned filename for
6073 future access should copy it to their own buffers. */
6075 ep_parse_optional_filename (arg)
6078 static char filename[1024];
6083 if ((*arg_p == '\0') || isspace (*arg_p))
6101 /* Commands to deal with catching events, such as signals, exceptions,
6102 process start/exit, etc. */
6106 catch_fork, catch_vfork
6110 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
6111 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
6117 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
6118 catch_fork_kind fork_kind;
6123 char *cond_string = NULL;
6125 ep_skip_leading_whitespace (&arg);
6127 /* The allowed syntax is:
6129 catch [v]fork if <cond>
6131 First, check if there's an if clause. */
6132 cond_string = ep_parse_optional_if_clause (&arg);
6134 if ((*arg != '\0') && !isspace (*arg))
6135 error ("Junk at end of arguments.");
6137 /* If this target supports it, create a fork or vfork catchpoint
6138 and enable reporting of such events. */
6142 create_fork_event_catchpoint (tempflag, cond_string);
6145 create_vfork_event_catchpoint (tempflag, cond_string);
6148 error ("unsupported or unknown fork kind; cannot catch it");
6154 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6156 catch_exec_command_1 (arg, tempflag, from_tty)
6161 char *cond_string = NULL;
6163 ep_skip_leading_whitespace (&arg);
6165 /* The allowed syntax is:
6167 catch exec if <cond>
6169 First, check if there's an if clause. */
6170 cond_string = ep_parse_optional_if_clause (&arg);
6172 if ((*arg != '\0') && !isspace (*arg))
6173 error ("Junk at end of arguments.");
6175 /* If this target supports it, create an exec catchpoint
6176 and enable reporting of such events. */
6177 create_exec_event_catchpoint (tempflag, cond_string);
6181 #if defined(SOLIB_ADD)
6183 catch_load_command_1 (arg, tempflag, from_tty)
6188 char *dll_pathname = NULL;
6189 char *cond_string = NULL;
6191 ep_skip_leading_whitespace (&arg);
6193 /* The allowed syntax is:
6195 catch load if <cond>
6196 catch load <filename>
6197 catch load <filename> if <cond>
6199 The user is not allowed to specify the <filename> after an
6202 We'll ignore the pathological case of a file named "if".
6204 First, check if there's an if clause. If so, then there
6205 cannot be a filename. */
6206 cond_string = ep_parse_optional_if_clause (&arg);
6208 /* If there was an if clause, then there cannot be a filename.
6209 Else, there might be a filename and an if clause. */
6210 if (cond_string == NULL)
6212 dll_pathname = ep_parse_optional_filename (&arg);
6213 ep_skip_leading_whitespace (&arg);
6214 cond_string = ep_parse_optional_if_clause (&arg);
6217 if ((*arg != '\0') && !isspace (*arg))
6218 error ("Junk at end of arguments.");
6220 /* Create a load breakpoint that only triggers when a load of
6221 the specified dll (or any dll, if no pathname was specified)
6223 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
6224 dll_pathname, cond_string);
6228 catch_unload_command_1 (arg, tempflag, from_tty)
6233 char *dll_pathname = NULL;
6234 char *cond_string = NULL;
6236 ep_skip_leading_whitespace (&arg);
6238 /* The allowed syntax is:
6240 catch unload if <cond>
6241 catch unload <filename>
6242 catch unload <filename> if <cond>
6244 The user is not allowed to specify the <filename> after an
6247 We'll ignore the pathological case of a file named "if".
6249 First, check if there's an if clause. If so, then there
6250 cannot be a filename. */
6251 cond_string = ep_parse_optional_if_clause (&arg);
6253 /* If there was an if clause, then there cannot be a filename.
6254 Else, there might be a filename and an if clause. */
6255 if (cond_string == NULL)
6257 dll_pathname = ep_parse_optional_filename (&arg);
6258 ep_skip_leading_whitespace (&arg);
6259 cond_string = ep_parse_optional_if_clause (&arg);
6262 if ((*arg != '\0') && !isspace (*arg))
6263 error ("Junk at end of arguments.");
6265 /* Create an unload breakpoint that only triggers when an unload of
6266 the specified dll (or any dll, if no pathname was specified)
6268 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
6269 dll_pathname, cond_string);
6271 #endif /* SOLIB_ADD */
6273 /* Commands to deal with catching exceptions. */
6275 /* Set a breakpoint at the specified callback routine for an
6276 exception event callback */
6279 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
6282 enum exception_event_kind ex_event;
6283 struct symtab_and_line *sal;
6285 struct breakpoint *b;
6286 int thread = -1; /* All threads. */
6288 if (!sal) /* no exception support? */
6291 b = set_raw_breakpoint (*sal);
6292 set_breakpoint_count (breakpoint_count + 1);
6293 b->number = breakpoint_count;
6295 b->cond_string = (cond_string == NULL) ?
6296 NULL : savestring (cond_string, strlen (cond_string));
6298 b->addr_string = NULL;
6299 b->enable = enabled;
6300 b->disposition = tempflag ? del : donttouch;
6303 case EX_EVENT_THROW:
6304 b->type = bp_catch_throw;
6306 case EX_EVENT_CATCH:
6307 b->type = bp_catch_catch;
6309 default: /* error condition */
6311 b->enable = disabled;
6312 error ("Internal error -- invalid catchpoint kind");
6317 /* Deal with "catch catch" and "catch throw" commands */
6320 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
6321 enum exception_event_kind ex_event;
6326 char *cond_string = NULL;
6327 struct symtab_and_line *sal = NULL;
6329 ep_skip_leading_whitespace (&arg);
6331 cond_string = ep_parse_optional_if_clause (&arg);
6333 if ((*arg != '\0') && !isspace (*arg))
6334 error ("Junk at end of arguments.");
6336 if ((ex_event != EX_EVENT_THROW) &&
6337 (ex_event != EX_EVENT_CATCH))
6338 error ("Unsupported or unknown exception event; cannot catch it");
6340 /* See if we can find a callback routine */
6341 sal = target_enable_exception_callback (ex_event, 1);
6345 /* We have callbacks from the runtime system for exceptions.
6346 Set a breakpoint on the sal found, if no errors */
6347 if (sal != (struct symtab_and_line *) -1)
6348 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6350 return; /* something went wrong with setting up callbacks */
6354 /* No callbacks from runtime system for exceptions.
6355 Try GNU C++ exception breakpoints using labels in debug info. */
6356 if (ex_event == EX_EVENT_CATCH)
6358 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6360 else if (ex_event == EX_EVENT_THROW)
6362 /* Set a breakpoint on __raise_exception () */
6364 warning ("Unsupported with this platform/compiler combination.");
6365 warning ("Perhaps you can achieve the effect you want by setting");
6366 warning ("a breakpoint on __raise_exception().");
6371 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6372 inside a catch_errors */
6375 cover_target_enable_exception_callback (arg)
6378 args_for_catchpoint_enable *args = arg;
6379 struct symtab_and_line *sal;
6380 sal = target_enable_exception_callback (args->kind, args->enable);
6383 else if (sal == (struct symtab_and_line *) -1)
6386 return 1; /*is valid */
6391 /* This is the original v.4.16 and earlier version of the
6392 catch_command_1() function. Now that other flavours of "catch"
6393 have been introduced, and since exception handling can be handled
6394 in other ways (through target ops) also, this is used only for the
6395 GNU C++ exception handling system.
6396 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6397 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6398 there was no code in GDB 4.16 for "catch throw".
6400 Called from catch_exception_command_1 () */
6404 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
6409 /* First, translate ARG into something we can deal with in terms
6412 struct symtabs_and_lines sals;
6413 struct symtab_and_line sal;
6414 register struct expression *cond = 0;
6415 register struct breakpoint *b;
6419 INIT_SAL (&sal); /* initialize to zeroes */
6421 /* If no arg given, or if first arg is 'if ', all active catch clauses
6422 are breakpointed. */
6424 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6425 && (arg[2] == ' ' || arg[2] == '\t')))
6427 /* Grab all active catch clauses. */
6428 sals = get_catch_sals (0);
6432 /* Grab selected catch clauses. */
6433 error ("catch NAME not implemented");
6436 /* Not sure why this code has been disabled. I'm leaving
6437 it disabled. We can never come here now anyway
6438 since we don't allow the "catch NAME" syntax.
6441 /* This isn't used; I don't know what it was for. */
6442 sals = map_catch_names (arg, catch_breakpoint);
6450 for (i = 0; i < sals.nelts; i++)
6452 resolve_sal_pc (&sals.sals[i]);
6456 if (arg[0] == 'i' && arg[1] == 'f'
6457 && (arg[2] == ' ' || arg[2] == '\t'))
6458 cond = parse_exp_1 ((arg += 2, &arg),
6459 block_for_pc (sals.sals[i].pc), 0);
6461 error ("Junk at end of arguments.");
6466 for (i = 0; i < sals.nelts; i++)
6471 describe_other_breakpoints (sal.pc, sal.section);
6473 b = set_raw_breakpoint (sal);
6474 set_breakpoint_count (breakpoint_count + 1);
6475 b->number = breakpoint_count;
6477 /* Important -- this is an ordinary breakpoint. For platforms
6478 with callback support for exceptions,
6479 create_exception_catchpoint() will create special bp types
6480 (bp_catch_catch and bp_catch_throw), and there is code in
6481 insert_breakpoints() and elsewhere that depends on that. */
6482 b->type = bp_breakpoint;
6485 b->enable = enabled;
6486 b->disposition = tempflag ? del : donttouch;
6493 warning ("Multiple breakpoints were set.");
6494 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6496 free ((PTR) sals.sals);
6500 /* This creates a temporary internal breakpoint
6501 just to placate infrun */
6502 static struct breakpoint *
6503 create_temp_exception_breakpoint (pc)
6506 struct symtab_and_line sal;
6507 struct breakpoint *b;
6514 b = set_raw_breakpoint (sal);
6516 error ("Internal error -- couldn't set temp exception breakpoint");
6518 b->type = bp_breakpoint;
6519 b->disposition = del;
6520 b->enable = enabled;
6522 b->number = internal_breakpoint_number--;
6528 catch_command_1 (arg, tempflag, from_tty)
6534 /* The first argument may be an event name, such as "start" or "load".
6535 If so, then handle it as such. If it doesn't match an event name,
6536 then attempt to interpret it as an exception name. (This latter is
6537 the v4.16-and-earlier GDB meaning of the "catch" command.)
6539 First, try to find the bounds of what might be an event name. */
6540 char *arg1_start = arg;
6544 if (arg1_start == NULL)
6546 /* Old behaviour was to use pre-v-4.16 syntax */
6547 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6549 /* Now, this is not allowed */
6550 error ("Catch requires an event name.");
6553 arg1_end = ep_find_event_name_end (arg1_start);
6554 if (arg1_end == NULL)
6555 error ("catch requires an event");
6556 arg1_length = arg1_end + 1 - arg1_start;
6558 /* Try to match what we found against known event names. */
6559 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6561 error ("Catch of signal not yet implemented");
6563 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6565 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6566 tempflag, from_tty);
6568 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6570 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6571 tempflag, from_tty);
6573 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6575 error ("Catch of thread_start not yet implemented");
6577 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6579 error ("Catch of thread_exit not yet implemented");
6581 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6583 error ("Catch of thread_join not yet implemented");
6585 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6587 error ("Catch of start not yet implemented");
6589 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6591 error ("Catch of exit not yet implemented");
6593 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6595 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6596 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6598 error ("Catch of fork not yet implemented");
6601 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6603 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6604 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6606 error ("Catch of vfork not yet implemented");
6609 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6611 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6612 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6614 error ("Catch of exec not yet implemented");
6617 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6619 #if defined(SOLIB_ADD)
6620 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6622 error ("Catch of load not implemented");
6625 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6627 #if defined(SOLIB_ADD)
6628 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6630 error ("Catch of load not implemented");
6633 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6635 error ("Catch of stop not yet implemented");
6638 /* This doesn't appear to be an event name */
6642 /* Pre-v.4.16 behaviour was to treat the argument
6643 as the name of an exception */
6644 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6645 /* Now this is not allowed */
6646 error ("Unknown event kind specified for catch");
6651 /* Used by the gui, could be made a worker for other things. */
6654 set_breakpoint_sal (sal)
6655 struct symtab_and_line sal;
6657 struct breakpoint *b;
6658 b = set_raw_breakpoint (sal);
6659 set_breakpoint_count (breakpoint_count + 1);
6660 b->number = breakpoint_count;
6661 b->type = bp_breakpoint;
6668 /* These aren't used; I don't know what they were for. */
6669 /* Disable breakpoints on all catch clauses described in ARGS. */
6671 disable_catch (args)
6674 /* Map the disable command to catch clauses described in ARGS. */
6677 /* Enable breakpoints on all catch clauses described in ARGS. */
6682 /* Map the disable command to catch clauses described in ARGS. */
6685 /* Delete breakpoints on all catch clauses in the active scope. */
6690 /* Map the delete command to catch clauses described in ARGS. */
6695 catch_command (arg, from_tty)
6699 catch_command_1 (arg, 0, from_tty);
6704 tcatch_command (arg, from_tty)
6708 catch_command_1 (arg, 1, from_tty);
6713 clear_command (arg, from_tty)
6717 register struct breakpoint *b, *b1;
6719 struct symtabs_and_lines sals;
6720 struct symtab_and_line sal;
6721 register struct breakpoint *found;
6726 sals = decode_line_spec (arg, 1);
6731 sals.sals = (struct symtab_and_line *)
6732 xmalloc (sizeof (struct symtab_and_line));
6733 INIT_SAL (&sal); /* initialize to zeroes */
6734 sal.line = default_breakpoint_line;
6735 sal.symtab = default_breakpoint_symtab;
6736 sal.pc = default_breakpoint_address;
6737 if (sal.symtab == 0)
6738 error ("No source file specified.");
6746 /* For each line spec given, delete bps which correspond
6747 to it. We do this in two loops: the first loop looks at
6748 the initial bp(s) in the chain which should be deleted,
6749 the second goes down the rest of the chain looking ahead
6750 one so it can take those bps off the chain without messing
6754 for (i = 0; i < sals.nelts; i++)
6756 /* If exact pc given, clear bpts at that pc.
6757 If line given (pc == 0), clear all bpts on specified line.
6758 If defaulting, clear all bpts on default line
6761 defaulting sal.pc != 0 tests to do
6766 1 0 <can't happen> */
6769 found = (struct breakpoint *) 0;
6772 while (breakpoint_chain
6773 /* Why don't we check here that this is not
6774 a watchpoint, etc., as we do below?
6775 I can't make it fail, but don't know
6776 what's stopping the failure: a watchpoint
6777 of the same address as "sal.pc" should
6778 wind up being deleted. */
6780 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6781 (overlay_debugging == 0 ||
6782 breakpoint_chain->section == sal.section))
6783 || ((default_match || (0 == sal.pc))
6784 && breakpoint_chain->source_file != NULL
6785 && sal.symtab != NULL
6786 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6787 && breakpoint_chain->line_number == sal.line)))
6790 b1 = breakpoint_chain;
6791 breakpoint_chain = b1->next;
6799 && b->next->type != bp_none
6800 && b->next->type != bp_watchpoint
6801 && b->next->type != bp_hardware_watchpoint
6802 && b->next->type != bp_read_watchpoint
6803 && b->next->type != bp_access_watchpoint
6804 && (((sal.pc && (b->next->address == sal.pc)) &&
6805 (overlay_debugging == 0 ||
6806 b->next->section == sal.section))
6807 || ((default_match || (0 == sal.pc))
6808 && b->next->source_file != NULL
6809 && sal.symtab != NULL
6810 && STREQ (b->next->source_file, sal.symtab->filename)
6811 && b->next->line_number == sal.line)))
6824 error ("No breakpoint at %s.", arg);
6826 error ("No breakpoint at this line.");
6830 from_tty = 1; /* Always report if deleted more than one */
6832 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6833 breakpoints_changed ();
6837 printf_unfiltered ("%d ", found->number);
6839 delete_breakpoint (found);
6843 putchar_unfiltered ('\n');
6845 free ((PTR) sals.sals);
6848 /* Delete breakpoint in BS if they are `delete' breakpoints and
6849 all breakpoints that are marked for deletion, whether hit or not.
6850 This is called after any breakpoint is hit, or after errors. */
6853 breakpoint_auto_delete (bs)
6856 struct breakpoint *b, *temp;
6858 for (; bs; bs = bs->next)
6859 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6861 delete_breakpoint (bs->breakpoint_at);
6863 ALL_BREAKPOINTS_SAFE (b, temp)
6865 if (b->disposition == del_at_next_stop)
6866 delete_breakpoint (b);
6870 /* Delete a breakpoint and clean up all traces of it in the data
6874 delete_breakpoint (bpt)
6875 struct breakpoint *bpt;
6877 register struct breakpoint *b;
6881 error ("Internal error (attempted to delete a NULL breakpoint)");
6884 /* Has this bp already been deleted? This can happen because multiple
6885 lists can hold pointers to bp's. bpstat lists are especial culprits.
6887 One example of this happening is a watchpoint's scope bp. When the
6888 scope bp triggers, we notice that the watchpoint is out of scope, and
6889 delete it. We also delete its scope bp. But the scope bp is marked
6890 "auto-deleting", and is already on a bpstat. That bpstat is then
6891 checked for auto-deleting bp's, which are deleted.
6893 A real solution to this problem might involve reference counts in bp's,
6894 and/or giving them pointers back to their referencing bpstat's, and
6895 teaching delete_breakpoint to only free a bp's storage when no more
6896 references were extent. A cheaper bandaid was chosen. */
6897 if (bpt->type == bp_none)
6900 if (delete_breakpoint_hook)
6901 delete_breakpoint_hook (bpt);
6902 breakpoint_delete_event (bpt->number);
6905 remove_breakpoint (bpt, mark_uninserted);
6907 if (breakpoint_chain == bpt)
6908 breakpoint_chain = bpt->next;
6910 /* If we have callback-style exception catchpoints, don't go through
6911 the adjustments to the C++ runtime library etc. if the inferior
6912 isn't actually running. target_enable_exception_callback for a
6913 null target ops vector gives an undesirable error message, so we
6914 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6915 exceptions are supported in this way, it's OK for now. FIXME */
6916 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6918 static char message1[] = "Error in deleting catchpoint %d:\n";
6919 static char message[sizeof (message1) + 30];
6920 args_for_catchpoint_enable args;
6922 /* Format possible error msg */
6923 sprintf (message, message1, bpt->number);
6924 args.kind = bpt->type == bp_catch_catch ?
6925 EX_EVENT_CATCH : EX_EVENT_THROW;
6927 catch_errors (cover_target_enable_exception_callback, &args,
6928 message, RETURN_MASK_ALL);
6935 b->next = bpt->next;
6939 /* Before turning off the visuals for the bp, check to see that
6940 there are no other bps at the same address. */
6947 clearIt = (b->address != bpt->address);
6954 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6955 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6959 check_duplicates (bpt->address, bpt->section);
6960 /* If this breakpoint was inserted, and there is another breakpoint
6961 at the same address, we need to insert the other breakpoint. */
6963 && bpt->type != bp_hardware_watchpoint
6964 && bpt->type != bp_read_watchpoint
6965 && bpt->type != bp_access_watchpoint
6966 && bpt->type != bp_catch_fork
6967 && bpt->type != bp_catch_vfork
6968 && bpt->type != bp_catch_exec)
6971 if (b->address == bpt->address
6972 && b->section == bpt->section
6974 && b->enable != disabled
6975 && b->enable != shlib_disabled
6976 && b->enable != call_disabled)
6980 /* We should never reach this point if there is a permanent
6981 breakpoint at the same address as the one being deleted.
6982 If there is a permanent breakpoint somewhere, it should
6983 always be the only one inserted. */
6984 if (b->enable == permanent)
6985 internal_error ("another breakpoint was inserted on top of "
6986 "a permanent breakpoint");
6988 if (b->type == bp_hardware_breakpoint)
6989 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6991 val = target_insert_breakpoint (b->address, b->shadow_contents);
6995 target_terminal_ours_for_output ();
6996 warning ("Cannot insert breakpoint %d:", b->number);
6997 memory_error (val, b->address); /* which bombs us out */
7004 free_command_lines (&bpt->commands);
7007 if (bpt->cond_string != NULL)
7008 free (bpt->cond_string);
7009 if (bpt->addr_string != NULL)
7010 free (bpt->addr_string);
7011 if (bpt->exp != NULL)
7013 if (bpt->exp_string != NULL)
7014 free (bpt->exp_string);
7015 if (bpt->val != NULL)
7016 value_free (bpt->val);
7017 if (bpt->source_file != NULL)
7018 free (bpt->source_file);
7019 if (bpt->dll_pathname != NULL)
7020 free (bpt->dll_pathname);
7021 if (bpt->triggered_dll_pathname != NULL)
7022 free (bpt->triggered_dll_pathname);
7023 if (bpt->exec_pathname != NULL)
7024 free (bpt->exec_pathname);
7026 /* Be sure no bpstat's are pointing at it after it's been freed. */
7027 /* FIXME, how can we find all bpstat's?
7028 We just check stop_bpstat for now. */
7029 for (bs = stop_bpstat; bs; bs = bs->next)
7030 if (bs->breakpoint_at == bpt)
7032 bs->breakpoint_at = NULL;
7034 /* we'd call bpstat_clear_actions, but that free's stuff and due
7035 to the multiple pointers pointing to one item with no
7036 reference counts found anywhere through out the bpstat's (how
7037 do you spell fragile?), we don't want to free things twice --
7038 better a memory leak than a corrupt malloc pool! */
7039 bs->commands = NULL;
7042 /* On the chance that someone will soon try again to delete this same
7043 bp, we mark it as deleted before freeing its storage. */
7044 bpt->type = bp_none;
7050 delete_command (arg, from_tty)
7054 struct breakpoint *b, *temp;
7058 int breaks_to_delete = 0;
7060 /* Delete all breakpoints if no argument.
7061 Do not delete internal or call-dummy breakpoints, these
7062 have to be deleted with an explicit breakpoint number argument. */
7065 if (b->type != bp_call_dummy &&
7066 b->type != bp_shlib_event &&
7067 b->type != bp_thread_event &&
7069 breaks_to_delete = 1;
7072 /* Ask user only if there are some breakpoints to delete. */
7074 || (breaks_to_delete && query ("Delete all breakpoints? ")))
7076 ALL_BREAKPOINTS_SAFE (b, temp)
7078 if (b->type != bp_call_dummy &&
7079 b->type != bp_shlib_event &&
7080 b->type != bp_thread_event &&
7082 delete_breakpoint (b);
7087 map_breakpoint_numbers (arg, delete_breakpoint);
7090 /* Reset a breakpoint given it's struct breakpoint * BINT.
7091 The value we return ends up being the return value from catch_errors.
7092 Unused in this case. */
7095 breakpoint_re_set_one (bint)
7098 /* get past catch_errs */
7099 struct breakpoint *b = (struct breakpoint *) bint;
7102 struct symtabs_and_lines sals;
7104 enum enable save_enable;
7109 warning ("attempted to reset apparently deleted breakpoint #%d?",
7113 case bp_hardware_breakpoint:
7115 case bp_catch_unload:
7116 if (b->addr_string == NULL)
7118 /* Anything without a string can't be re-set. */
7119 delete_breakpoint (b);
7122 /* In case we have a problem, disable this breakpoint. We'll restore
7123 its status if we succeed. */
7124 save_enable = b->enable;
7125 b->enable = disabled;
7127 set_language (b->language);
7128 input_radix = b->input_radix;
7130 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
7131 for (i = 0; i < sals.nelts; i++)
7133 resolve_sal_pc (&sals.sals[i]);
7135 /* Reparse conditions, they might contain references to the
7137 if (b->cond_string != NULL)
7141 free ((PTR) b->cond);
7142 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7145 /* We need to re-set the breakpoint if the address changes... */
7146 if (b->address != sals.sals[i].pc
7147 /* ...or new and old breakpoints both have source files, and
7148 the source file name or the line number changes... */
7149 || (b->source_file != NULL
7150 && sals.sals[i].symtab != NULL
7151 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
7152 || b->line_number != sals.sals[i].line)
7154 /* ...or we switch between having a source file and not having
7156 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7159 if (b->source_file != NULL)
7160 free (b->source_file);
7161 if (sals.sals[i].symtab == NULL)
7162 b->source_file = NULL;
7165 savestring (sals.sals[i].symtab->filename,
7166 strlen (sals.sals[i].symtab->filename));
7167 b->line_number = sals.sals[i].line;
7168 b->address = sals.sals[i].pc;
7170 /* Used to check for duplicates here, but that can
7171 cause trouble, as it doesn't check for disable
7176 /* Might be better to do this just once per breakpoint_re_set,
7177 rather than once for every breakpoint. */
7178 breakpoints_changed ();
7180 b->section = sals.sals[i].section;
7181 b->enable = save_enable; /* Restore it, this worked. */
7184 /* Now that this is re-enabled, check_duplicates
7186 check_duplicates (b->address, b->section);
7189 free ((PTR) sals.sals);
7193 case bp_hardware_watchpoint:
7194 case bp_read_watchpoint:
7195 case bp_access_watchpoint:
7196 innermost_block = NULL;
7197 /* The issue arises of what context to evaluate this in. The
7198 same one as when it was set, but what does that mean when
7199 symbols have been re-read? We could save the filename and
7200 functionname, but if the context is more local than that, the
7201 best we could do would be something like how many levels deep
7202 and which index at that particular level, but that's going to
7203 be less stable than filenames or function names. */
7205 /* So for now, just use a global context. */
7207 free ((PTR) b->exp);
7208 b->exp = parse_expression (b->exp_string);
7209 b->exp_valid_block = innermost_block;
7210 mark = value_mark ();
7212 value_free (b->val);
7213 b->val = evaluate_expression (b->exp);
7214 release_value (b->val);
7215 if (VALUE_LAZY (b->val))
7216 value_fetch_lazy (b->val);
7218 if (b->cond_string != NULL)
7222 free ((PTR) b->cond);
7223 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7225 if (b->enable == enabled)
7227 value_free_to_mark (mark);
7229 case bp_catch_catch:
7230 case bp_catch_throw:
7232 /* We needn't really do anything to reset these, since the mask
7233 that requests them is unaffected by e.g., new libraries being
7236 case bp_catch_vfork:
7241 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7243 /* Delete longjmp breakpoints, they will be reset later by
7244 breakpoint_re_set. */
7246 case bp_longjmp_resume:
7247 delete_breakpoint (b);
7250 /* This breakpoint is special, it's set up when the inferior
7251 starts and we really don't want to touch it. */
7252 case bp_shlib_event:
7254 /* Like bp_shlib_event, this breakpoint type is special.
7255 Once it is set up, we do not want to touch it. */
7256 case bp_thread_event:
7258 /* Keep temporary breakpoints, which can be encountered when we step
7259 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7260 Otherwise these should have been blown away via the cleanup chain
7261 or by breakpoint_init_inferior when we rerun the executable. */
7264 case bp_watchpoint_scope:
7266 case bp_step_resume:
7273 /* Re-set all breakpoints after symbols have been re-loaded. */
7275 breakpoint_re_set ()
7277 struct breakpoint *b, *temp;
7278 enum language save_language;
7279 int save_input_radix;
7280 static char message1[] = "Error in re-setting breakpoint %d:\n";
7281 char message[sizeof (message1) + 30 /* slop */ ];
7283 save_language = current_language->la_language;
7284 save_input_radix = input_radix;
7285 ALL_BREAKPOINTS_SAFE (b, temp)
7287 /* Format possible error msg */
7288 sprintf (message, message1, b->number);
7289 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7291 set_language (save_language);
7292 input_radix = save_input_radix;
7294 #ifdef GET_LONGJMP_TARGET
7295 create_longjmp_breakpoint ("longjmp");
7296 create_longjmp_breakpoint ("_longjmp");
7297 create_longjmp_breakpoint ("siglongjmp");
7298 create_longjmp_breakpoint ("_siglongjmp");
7299 create_longjmp_breakpoint (NULL);
7303 /* Took this out (temporarily at least), since it produces an extra
7304 blank line at startup. This messes up the gdbtests. -PB */
7305 /* Blank line to finish off all those mention() messages we just printed. */
7306 printf_filtered ("\n");
7310 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7311 If from_tty is nonzero, it prints a message to that effect,
7312 which ends with a period (no newline). */
7314 /* Reset the thread number of this breakpoint:
7316 - If the breakpoint is for all threads, leave it as-is.
7317 - Else, reset it to the current thread for inferior_pid. */
7319 breakpoint_re_set_thread (b)
7320 struct breakpoint *b;
7322 if (b->thread != -1)
7324 if (in_thread_list (inferior_pid))
7325 b->thread = pid_to_thread_id (inferior_pid);
7330 set_ignore_count (bptnum, count, from_tty)
7331 int bptnum, count, from_tty;
7333 register struct breakpoint *b;
7339 if (b->number == bptnum)
7341 b->ignore_count = count;
7344 else if (count == 0)
7345 printf_filtered ("Will stop next time breakpoint %d is reached.",
7347 else if (count == 1)
7348 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7351 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7353 breakpoints_changed ();
7357 error ("No breakpoint number %d.", bptnum);
7360 /* Clear the ignore counts of all breakpoints. */
7362 breakpoint_clear_ignore_counts ()
7364 struct breakpoint *b;
7367 b->ignore_count = 0;
7370 /* Command to set ignore-count of breakpoint N to COUNT. */
7373 ignore_command (args, from_tty)
7381 error_no_arg ("a breakpoint number");
7383 num = get_number (&p);
7385 error ("bad breakpoint number: '%s'", args);
7387 error ("Second argument (specified ignore-count) is missing.");
7389 set_ignore_count (num,
7390 longest_to_int (value_as_long (parse_and_eval (p))),
7392 printf_filtered ("\n");
7393 breakpoints_changed ();
7396 /* Call FUNCTION on each of the breakpoints
7397 whose numbers are given in ARGS. */
7400 map_breakpoint_numbers (args, function)
7402 void (*function) PARAMS ((struct breakpoint *));
7404 register char *p = args;
7407 register struct breakpoint *b, *tmp;
7411 error_no_arg ("one or more breakpoint numbers");
7418 num = get_number_or_range (&p1);
7421 warning ("bad breakpoint number at or near '%s'", p);
7425 ALL_BREAKPOINTS_SAFE (b, tmp)
7426 if (b->number == num)
7428 struct breakpoint *related_breakpoint = b->related_breakpoint;
7431 if (related_breakpoint)
7432 function (related_breakpoint);
7436 printf_unfiltered ("No breakpoint number %d.\n", num);
7443 disable_breakpoint (bpt)
7444 struct breakpoint *bpt;
7446 /* Never disable a watchpoint scope breakpoint; we want to
7447 hit them when we leave scope so we can delete both the
7448 watchpoint and its scope breakpoint at that time. */
7449 if (bpt->type == bp_watchpoint_scope)
7452 /* You can't disable permanent breakpoints. */
7453 if (bpt->enable == permanent)
7456 bpt->enable = disabled;
7458 check_duplicates (bpt->address, bpt->section);
7460 if (modify_breakpoint_hook)
7461 modify_breakpoint_hook (bpt);
7462 breakpoint_modify_event (bpt->number);
7467 disable_command (args, from_tty)
7471 register struct breakpoint *bpt;
7473 ALL_BREAKPOINTS (bpt)
7477 warning ("attempted to disable apparently deleted breakpoint #%d?",
7482 case bp_catch_unload:
7484 case bp_catch_vfork:
7486 case bp_catch_catch:
7487 case bp_catch_throw:
7488 case bp_hardware_breakpoint:
7490 case bp_hardware_watchpoint:
7491 case bp_read_watchpoint:
7492 case bp_access_watchpoint:
7493 disable_breakpoint (bpt);
7498 map_breakpoint_numbers (args, disable_breakpoint);
7502 do_enable_breakpoint (bpt, disposition)
7503 struct breakpoint *bpt;
7504 enum bpdisp disposition;
7506 struct frame_info *save_selected_frame = NULL;
7507 int save_selected_frame_level = -1;
7508 int target_resources_ok, other_type_used;
7511 if (bpt->type == bp_hardware_breakpoint)
7514 i = hw_breakpoint_used_count ();
7515 target_resources_ok =
7516 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7518 if (target_resources_ok == 0)
7519 error ("No hardware breakpoint support in the target.");
7520 else if (target_resources_ok < 0)
7521 error ("Hardware breakpoints used exceeds limit.");
7524 if (bpt->enable != permanent)
7525 bpt->enable = enabled;
7526 bpt->disposition = disposition;
7527 check_duplicates (bpt->address, bpt->section);
7528 breakpoints_changed ();
7530 if (bpt->type == bp_watchpoint ||
7531 bpt->type == bp_hardware_watchpoint ||
7532 bpt->type == bp_read_watchpoint ||
7533 bpt->type == bp_access_watchpoint)
7535 if (bpt->exp_valid_block != NULL)
7537 struct frame_info *fr =
7539 /* Ensure that we have the current frame. Else, this
7540 next query may pessimistically be answered as, "No,
7541 not within current scope". */
7542 get_current_frame ();
7543 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7547 Cannot enable watchpoint %d because the block in which its expression\n\
7548 is valid is not currently in scope.\n", bpt->number);
7549 bpt->enable = disabled;
7553 save_selected_frame = selected_frame;
7554 save_selected_frame_level = selected_frame_level;
7555 select_frame (fr, -1);
7558 value_free (bpt->val);
7559 mark = value_mark ();
7560 bpt->val = evaluate_expression (bpt->exp);
7561 release_value (bpt->val);
7562 if (VALUE_LAZY (bpt->val))
7563 value_fetch_lazy (bpt->val);
7565 if (bpt->type == bp_hardware_watchpoint ||
7566 bpt->type == bp_read_watchpoint ||
7567 bpt->type == bp_access_watchpoint)
7569 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7570 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7572 /* Hack around 'unused var' error for some targets here */
7574 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7575 bpt->type, i + mem_cnt, other_type_used);
7576 /* we can consider of type is bp_hardware_watchpoint, convert to
7577 bp_watchpoint in the following condition */
7578 if (target_resources_ok < 0)
7581 Cannot enable watchpoint %d because target watch resources\n\
7582 have been allocated for other watchpoints.\n", bpt->number);
7583 bpt->enable = disabled;
7584 value_free_to_mark (mark);
7589 if (save_selected_frame_level >= 0)
7590 select_and_print_frame (save_selected_frame,
7591 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;