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 case WP_VALUE_NOT_CHANGED:
2629 /* Error from catch_errors. */
2630 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2631 if (b->related_breakpoint)
2632 b->related_breakpoint->disposition = del_at_next_stop;
2633 b->disposition = del_at_next_stop;
2634 /* We've already printed what needs to be printed. */
2635 bs->print_it = print_it_done;
2638 else /* found == 0 */
2640 /* This is a case where some watchpoint(s) triggered,
2641 but not at the address of this watchpoint (FOUND
2642 was left zero). So don't print anything for this
2644 bs->print_it = print_it_noop;
2651 /* By definition, an encountered breakpoint is a triggered
2655 real_breakpoint = 1;
2659 b->frame != (get_current_frame ())->frame)
2663 int value_is_zero = 0;
2667 /* Need to select the frame, with all that implies
2668 so that the conditions will have the right context. */
2669 select_frame (get_current_frame (), 0);
2671 = catch_errors (breakpoint_cond_eval, (b->cond),
2672 "Error in testing breakpoint condition:\n",
2674 /* FIXME-someday, should give breakpoint # */
2677 if (b->cond && value_is_zero)
2680 /* Don't consider this a hit. */
2683 else if (b->ignore_count > 0)
2686 annotate_ignore_count_change ();
2691 /* We will stop here */
2692 if (b->disposition == disable)
2693 b->enable = disabled;
2694 bs->commands = b->commands;
2698 (STREQ ("silent", bs->commands->line) ||
2699 (xdb_commands && STREQ ("Q", bs->commands->line))))
2701 bs->commands = bs->commands->next;
2706 /* Print nothing for this entry if we dont stop or if we dont print. */
2707 if (bs->stop == 0 || bs->print == 0)
2708 bs->print_it = print_it_noop;
2711 bs->next = NULL; /* Terminate the chain */
2712 bs = root_bs->next; /* Re-grab the head of the chain */
2714 if (real_breakpoint && bs)
2716 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2718 if (DECR_PC_AFTER_HW_BREAK != 0)
2720 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2726 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2729 #if defined (SHIFT_INST_REGS)
2731 #else /* No SHIFT_INST_REGS. */
2733 #endif /* No SHIFT_INST_REGS. */
2738 /* The value of a hardware watchpoint hasn't changed, but the
2739 intermediate memory locations we are watching may have. */
2740 if (bs && !bs->stop &&
2741 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2742 bs->breakpoint_at->type == bp_read_watchpoint ||
2743 bs->breakpoint_at->type == bp_access_watchpoint))
2745 remove_breakpoints ();
2746 insert_breakpoints ();
2751 /* Tell what to do about this bpstat. */
2756 /* Classify each bpstat as one of the following. */
2759 /* This bpstat element has no effect on the main_action. */
2762 /* There was a watchpoint, stop but don't print. */
2765 /* There was a watchpoint, stop and print. */
2768 /* There was a breakpoint but we're not stopping. */
2771 /* There was a breakpoint, stop but don't print. */
2774 /* There was a breakpoint, stop and print. */
2777 /* We hit the longjmp breakpoint. */
2780 /* We hit the longjmp_resume breakpoint. */
2783 /* We hit the step_resume breakpoint. */
2786 /* We hit the through_sigtramp breakpoint. */
2789 /* We hit the shared library event breakpoint. */
2792 /* We caught a shared library event. */
2795 /* This is just used to count how many enums there are. */
2799 /* Here is the table which drives this routine. So that we can
2800 format it pretty, we define some abbreviations for the
2801 enum bpstat_what codes. */
2802 #define kc BPSTAT_WHAT_KEEP_CHECKING
2803 #define ss BPSTAT_WHAT_STOP_SILENT
2804 #define sn BPSTAT_WHAT_STOP_NOISY
2805 #define sgl BPSTAT_WHAT_SINGLE
2806 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2807 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2808 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2809 #define sr BPSTAT_WHAT_STEP_RESUME
2810 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2811 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2812 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2814 /* "Can't happen." Might want to print an error message.
2815 abort() is not out of the question, but chances are GDB is just
2816 a bit confused, not unusable. */
2817 #define err BPSTAT_WHAT_STOP_NOISY
2819 /* Given an old action and a class, come up with a new action. */
2820 /* One interesting property of this table is that wp_silent is the same
2821 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2822 after stopping, the check for whether to step over a breakpoint
2823 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2824 reference to how we stopped. We retain separate wp_silent and
2825 bp_silent codes in case we want to change that someday.
2827 Another possibly interesting property of this table is that
2828 there's a partial ordering, priority-like, of the actions. Once
2829 you've decided that some action is appropriate, you'll never go
2830 back and decide something of a lower priority is better. The
2833 kc < clr sgl shl slr sn sr ss ts
2834 sgl < clrs shl shlr slr sn sr ss ts
2835 slr < err shl shlr sn sr ss ts
2836 clr < clrs err shl shlr sn sr ss ts
2837 clrs < err shl shlr sn sr ss ts
2838 ss < shl shlr sn sr ts
2845 What I think this means is that we don't need a damned table
2846 here. If you just put the rows and columns in the right order,
2847 it'd look awfully regular. We could simply walk the bpstat list
2848 and choose the highest priority action we find, with a little
2849 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2850 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2851 is messy anyway). */
2853 /* step_resume entries: a step resume breakpoint overrides another
2854 breakpoint of signal handling (see comment in wait_for_inferior
2855 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2856 /* We handle the through_sigtramp_breakpoint the same way; having both
2857 one of those and a step_resume_breakpoint is probably very rare (?). */
2859 static const enum bpstat_what_main_action
2860 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2863 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2866 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2868 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2870 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2872 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2874 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2876 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2878 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2880 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2882 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2884 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2886 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2888 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2903 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2904 struct bpstat_what retval;
2906 retval.call_dummy = 0;
2907 for (; bs != NULL; bs = bs->next)
2909 enum class bs_class = no_effect;
2910 if (bs->breakpoint_at == NULL)
2911 /* I suspect this can happen if it was a momentary breakpoint
2912 which has since been deleted. */
2914 switch (bs->breakpoint_at->type)
2920 case bp_hardware_breakpoint:
2926 bs_class = bp_noisy;
2928 bs_class = bp_silent;
2931 bs_class = bp_nostop;
2934 case bp_hardware_watchpoint:
2935 case bp_read_watchpoint:
2936 case bp_access_watchpoint:
2940 bs_class = wp_noisy;
2942 bs_class = wp_silent;
2945 /* There was a watchpoint, but we're not stopping.
2946 This requires no further action. */
2947 bs_class = no_effect;
2950 bs_class = long_jump;
2952 case bp_longjmp_resume:
2953 bs_class = long_resume;
2955 case bp_step_resume:
2958 bs_class = step_resume;
2961 /* It is for the wrong frame. */
2962 bs_class = bp_nostop;
2964 case bp_through_sigtramp:
2965 bs_class = through_sig;
2967 case bp_watchpoint_scope:
2968 bs_class = bp_nostop;
2970 case bp_shlib_event:
2971 bs_class = shlib_event;
2973 case bp_thread_event:
2974 bs_class = bp_nostop;
2977 case bp_catch_unload:
2978 /* Only if this catchpoint triggered should we cause the
2979 step-out-of-dld behaviour. Otherwise, we ignore this
2982 bs_class = catch_shlib_event;
2984 bs_class = no_effect;
2987 case bp_catch_vfork:
2992 bs_class = bp_noisy;
2994 bs_class = bp_silent;
2997 /* There was a catchpoint, but we're not stopping.
2998 This requires no further action. */
2999 bs_class = no_effect;
3001 case bp_catch_catch:
3002 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3003 bs_class = bp_nostop;
3005 bs_class = bs->print ? bp_noisy : bp_silent;
3007 case bp_catch_throw:
3008 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3009 bs_class = bp_nostop;
3011 bs_class = bs->print ? bp_noisy : bp_silent;
3014 /* Make sure the action is stop (silent or noisy),
3015 so infrun.c pops the dummy frame. */
3016 bs_class = bp_silent;
3017 retval.call_dummy = 1;
3020 current_action = table[(int) bs_class][(int) current_action];
3022 retval.main_action = current_action;
3026 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3027 without hardware support). This isn't related to a specific bpstat,
3028 just to things like whether watchpoints are set. */
3031 bpstat_should_step ()
3033 struct breakpoint *b;
3035 if (b->enable == enabled && b->type == bp_watchpoint)
3040 /* Nonzero if there are enabled hardware watchpoints. */
3042 bpstat_have_active_hw_watchpoints ()
3044 struct breakpoint *b;
3046 if ((b->enable == enabled) &&
3048 ((b->type == bp_hardware_watchpoint) ||
3049 (b->type == bp_read_watchpoint) ||
3050 (b->type == bp_access_watchpoint)))
3056 /* Given a bpstat that records zero or more triggered eventpoints, this
3057 function returns another bpstat which contains only the catchpoints
3058 on that first list, if any. */
3060 bpstat_get_triggered_catchpoints (ep_list, cp_list)
3064 struct bpstats root_bs[1];
3065 bpstat bs = root_bs;
3066 struct breakpoint *ep;
3069 bpstat_clear (cp_list);
3070 root_bs->next = NULL;
3072 for (; ep_list != NULL; ep_list = ep_list->next)
3074 /* Is this eventpoint a catchpoint? If not, ignore it. */
3075 ep = ep_list->breakpoint_at;
3078 if ((ep->type != bp_catch_load) &&
3079 (ep->type != bp_catch_unload) &&
3080 (ep->type != bp_catch_catch) &&
3081 (ep->type != bp_catch_throw))
3082 /* pai: (temp) ADD fork/vfork here!! */
3085 /* Yes; add it to the list. */
3086 bs = bpstat_alloc (ep, bs);
3091 #if defined(SOLIB_ADD)
3092 /* Also, for each triggered catchpoint, tag it with the name of
3093 the library that caused this trigger. (We copy the name now,
3094 because it's only guaranteed to be available NOW, when the
3095 catchpoint triggers. Clients who may wish to know the name
3096 later must get it from the catchpoint itself.) */
3097 if (ep->triggered_dll_pathname != NULL)
3098 free (ep->triggered_dll_pathname);
3099 if (ep->type == bp_catch_load)
3100 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
3102 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
3104 dll_pathname = NULL;
3108 ep->triggered_dll_pathname = (char *)
3109 xmalloc (strlen (dll_pathname) + 1);
3110 strcpy (ep->triggered_dll_pathname, dll_pathname);
3113 ep->triggered_dll_pathname = NULL;
3119 /* Print B to gdb_stdout. */
3121 print_one_breakpoint (struct breakpoint *b,
3122 CORE_ADDR *last_addr)
3124 register struct command_line *l;
3125 register struct symbol *sym;
3126 struct ep_type_description
3131 static struct ep_type_description bptypes[] =
3133 {bp_none, "?deleted?"},
3134 {bp_breakpoint, "breakpoint"},
3135 {bp_hardware_breakpoint, "hw breakpoint"},
3136 {bp_until, "until"},
3137 {bp_finish, "finish"},
3138 {bp_watchpoint, "watchpoint"},
3139 {bp_hardware_watchpoint, "hw watchpoint"},
3140 {bp_read_watchpoint, "read watchpoint"},
3141 {bp_access_watchpoint, "acc watchpoint"},
3142 {bp_longjmp, "longjmp"},
3143 {bp_longjmp_resume, "longjmp resume"},
3144 {bp_step_resume, "step resume"},
3145 {bp_through_sigtramp, "sigtramp"},
3146 {bp_watchpoint_scope, "watchpoint scope"},
3147 {bp_call_dummy, "call dummy"},
3148 {bp_shlib_event, "shlib events"},
3149 {bp_thread_event, "thread events"},
3150 {bp_catch_load, "catch load"},
3151 {bp_catch_unload, "catch unload"},
3152 {bp_catch_fork, "catch fork"},
3153 {bp_catch_vfork, "catch vfork"},
3154 {bp_catch_exec, "catch exec"},
3155 {bp_catch_catch, "catch catch"},
3156 {bp_catch_throw, "catch throw"}
3159 static char *bpdisps[] =
3160 {"del", "dstp", "dis", "keep"};
3161 static char bpenables[] = "nynny";
3162 char wrap_indent[80];
3164 struct ui_stream *stb = ui_out_stream_new (uiout);
3165 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3170 ui_out_list_begin (uiout, "bkpt");
3176 ui_out_field_int (uiout, "number", b->number);
3178 printf_filtered ("%-3d ", b->number);
3183 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3184 || ((int) b->type != bptypes[(int) b->type].type))
3185 internal_error ("bptypes table does not describe type #%d.",
3188 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3190 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3196 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3198 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3204 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3205 ui_out_spaces (uiout, 2);
3207 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3211 strcpy (wrap_indent, " ");
3213 strcat (wrap_indent, " ");
3217 internal_error ("print_one_breakpoint: bp_none encountered\n");
3221 case bp_hardware_watchpoint:
3222 case bp_read_watchpoint:
3223 case bp_access_watchpoint:
3224 /* Field 4, the address, is omitted (which makes the columns
3225 not line up too nicely with the headers, but the effect
3226 is relatively readable). */
3229 ui_out_field_skip (uiout, "addr");
3231 print_expression (b->exp, stb->stream);
3232 ui_out_field_stream (uiout, "what", stb);
3235 print_expression (b->exp, gdb_stdout);
3240 case bp_catch_unload:
3241 /* Field 4, the address, is omitted (which makes the columns
3242 not line up too nicely with the headers, but the effect
3243 is relatively readable). */
3246 ui_out_field_skip (uiout, "addr");
3248 if (b->dll_pathname == NULL)
3250 ui_out_field_string (uiout, "what", "<any library>");
3251 ui_out_spaces (uiout, 1);
3255 ui_out_text (uiout, "library \"");
3256 ui_out_field_string (uiout, "what", b->dll_pathname);
3257 ui_out_text (uiout, "\" ");
3261 if (b->dll_pathname == NULL)
3262 printf_filtered ("<any library> ");
3264 printf_filtered ("library \"%s\" ", b->dll_pathname);
3269 case bp_catch_vfork:
3270 /* Field 4, the address, is omitted (which makes the columns
3271 not line up too nicely with the headers, but the effect
3272 is relatively readable). */
3275 ui_out_field_skip (uiout, "addr");
3277 if (b->forked_inferior_pid != 0)
3279 ui_out_text (uiout, "process ");
3280 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3281 ui_out_spaces (uiout, 1);
3285 if (b->forked_inferior_pid != 0)
3286 printf_filtered ("process %d ", b->forked_inferior_pid);
3291 /* Field 4, the address, is omitted (which makes the columns
3292 not line up too nicely with the headers, but the effect
3293 is relatively readable). */
3296 ui_out_field_skip (uiout, "addr");
3298 if (b->exec_pathname != NULL)
3300 ui_out_text (uiout, "program \"");
3301 ui_out_field_string (uiout, "what", b->exec_pathname);
3302 ui_out_text (uiout, "\" ");
3306 if (b->exec_pathname != NULL)
3307 printf_filtered ("program \"%s\" ", b->exec_pathname);
3311 case bp_catch_catch:
3312 /* Field 4, the address, is omitted (which makes the columns
3313 not line up too nicely with the headers, but the effect
3314 is relatively readable). */
3317 ui_out_field_skip (uiout, "addr");
3319 ui_out_field_string (uiout, "what", "exception catch");
3320 ui_out_spaces (uiout, 1);
3323 printf_filtered ("exception catch ");
3327 case bp_catch_throw:
3328 /* Field 4, the address, is omitted (which makes the columns
3329 not line up too nicely with the headers, but the effect
3330 is relatively readable). */
3333 ui_out_field_skip (uiout, "addr");
3335 ui_out_field_string (uiout, "what", "exception throw");
3336 ui_out_spaces (uiout, 1);
3339 printf_filtered ("exception throw ");
3344 case bp_hardware_breakpoint:
3348 case bp_longjmp_resume:
3349 case bp_step_resume:
3350 case bp_through_sigtramp:
3351 case bp_watchpoint_scope:
3353 case bp_shlib_event:
3354 case bp_thread_event:
3359 ui_out_field_core_addr (uiout, "addr", b->address);
3362 *last_addr = b->address;
3365 sym = find_pc_sect_function (b->address, b->section);
3368 ui_out_text (uiout, "in ");
3369 ui_out_field_string (uiout, "func",
3370 SYMBOL_SOURCE_NAME (sym));
3371 ui_out_wrap_hint (uiout, wrap_indent);
3372 ui_out_text (uiout, " at ");
3374 ui_out_field_string (uiout, "file", b->source_file);
3375 ui_out_text (uiout, ":");
3376 ui_out_field_int (uiout, "line", b->line_number);
3380 print_address_symbolic (b->address, stb->stream, demangle, "");
3381 ui_out_field_stream (uiout, "at", stb);
3387 /* FIXME-32x64: need a print_address_numeric with
3391 local_hex_string_custom
3392 ((unsigned long) b->address, "08l"));
3395 *last_addr = b->address;
3398 sym = find_pc_sect_function (b->address, b->section);
3401 fputs_filtered ("in ", gdb_stdout);
3402 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3403 wrap_here (wrap_indent);
3404 fputs_filtered (" at ", gdb_stdout);
3406 fputs_filtered (b->source_file, gdb_stdout);
3407 printf_filtered (":%d", b->line_number);
3410 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3415 if (b->thread != -1)
3418 /* FIXME: This seems to be redundant and lost here; see the
3419 "stop only in" line a little further down. */
3420 ui_out_text (uiout, " thread ");
3421 ui_out_field_int (uiout, "thread", b->thread);
3423 printf_filtered (" thread %d", b->thread);
3428 ui_out_text (uiout, "\n");
3430 printf_filtered ("\n");
3437 ui_out_text (uiout, "\tstop only in stack frame at ");
3438 ui_out_field_core_addr (uiout, "frame", b->frame);
3439 ui_out_text (uiout, "\n");
3441 printf_filtered ("\tstop only in stack frame at ");
3442 print_address_numeric (b->frame, 1, gdb_stdout);
3443 printf_filtered ("\n");
3451 ui_out_text (uiout, "\tstop only if ");
3452 print_expression (b->cond, stb->stream);
3453 ui_out_field_stream (uiout, "cond", stb);
3454 ui_out_text (uiout, "\n");
3456 printf_filtered ("\tstop only if ");
3457 print_expression (b->cond, gdb_stdout);
3458 printf_filtered ("\n");
3462 if (b->thread != -1)
3464 /* FIXME should make an annotation for this */
3466 ui_out_text (uiout, "\tstop only in thread ");
3467 ui_out_field_int (uiout, "thread", b->thread);
3468 ui_out_text (uiout, "\n");
3470 printf_filtered ("\tstop only in thread %d\n", b->thread);
3474 if (show_breakpoint_hit_counts && b->hit_count)
3476 /* FIXME should make an annotation for this */
3478 if (ep_is_catchpoint (b))
3479 ui_out_text (uiout, "\tcatchpoint");
3481 ui_out_text (uiout, "\tbreakpoint");
3482 ui_out_text (uiout, " already hit ");
3483 ui_out_field_int (uiout, "times", b->hit_count);
3484 if (b->hit_count == 1)
3485 ui_out_text (uiout, " time\n");
3487 ui_out_text (uiout, " times\n");
3489 if (ep_is_catchpoint (b))
3490 printf_filtered ("\tcatchpoint");
3492 printf_filtered ("\tbreakpoint");
3493 printf_filtered (" already hit %d time%s\n",
3494 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3499 /* Output the count also if it is zero, but only if this is
3500 mi. FIXME: Should have a better test for this. */
3501 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3502 if (show_breakpoint_hit_counts && b->hit_count == 0)
3503 ui_out_field_int (uiout, "times", b->hit_count);
3506 if (b->ignore_count)
3510 ui_out_text (uiout, "\tignore next ");
3511 ui_out_field_int (uiout, "ignore", b->ignore_count);
3512 ui_out_text (uiout, " hits\n");
3514 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3518 if ((l = b->commands))
3522 ui_out_list_begin (uiout, "script");
3523 print_command_lines (uiout, l, 4);
3524 ui_out_list_end (uiout);
3528 print_command_line (l, 4, gdb_stdout);
3534 ui_out_list_end (uiout);
3535 do_cleanups (old_chain);
3539 struct captured_breakpoint_query_args
3545 do_captured_breakpoint_query (void *data)
3547 struct captured_breakpoint_query_args *args = data;
3548 register struct breakpoint *b;
3549 CORE_ADDR dummy_addr = 0;
3552 if (args->bnum == b->number)
3554 print_one_breakpoint (b, &dummy_addr);
3562 gdb_breakpoint_query (/* output object, */ int bnum)
3564 struct captured_breakpoint_query_args args;
3566 /* For the moment we don't trust print_one_breakpoint() to not throw
3568 return catch_errors (do_captured_breakpoint_query, &args,
3569 NULL, RETURN_MASK_ALL);
3572 /* Print information on breakpoint number BNUM, or -1 if all.
3573 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3574 is nonzero, process only watchpoints. */
3577 breakpoint_1 (bnum, allflag)
3581 register struct breakpoint *b;
3582 CORE_ADDR last_addr = (CORE_ADDR) -1;
3583 int found_a_breakpoint = 0;
3587 ui_out_table_begin (uiout, 6, "BreakpointTable");
3589 ui_out_table_begin (uiout, 5, "BreakpointTable");
3594 || bnum == b->number)
3596 /* We only print out user settable breakpoints unless the
3599 && b->type != bp_breakpoint
3600 && b->type != bp_catch_load
3601 && b->type != bp_catch_unload
3602 && b->type != bp_catch_fork
3603 && b->type != bp_catch_vfork
3604 && b->type != bp_catch_exec
3605 && b->type != bp_catch_catch
3606 && b->type != bp_catch_throw
3607 && b->type != bp_hardware_breakpoint
3608 && b->type != bp_watchpoint
3609 && b->type != bp_read_watchpoint
3610 && b->type != bp_access_watchpoint
3611 && b->type != bp_hardware_watchpoint)
3614 if (!found_a_breakpoint++)
3616 annotate_breakpoints_headers ();
3619 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3621 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3623 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3625 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3629 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3632 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3633 ui_out_table_body (uiout);
3636 printf_filtered ("Num ");
3638 printf_filtered ("Type ");
3640 printf_filtered ("Disp ");
3642 printf_filtered ("Enb ");
3646 printf_filtered ("Address ");
3649 printf_filtered ("What\n");
3651 annotate_breakpoints_table ();
3654 print_one_breakpoint (b, &last_addr);
3657 if (!found_a_breakpoint)
3661 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3663 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3667 printf_filtered ("No breakpoints or watchpoints.\n");
3669 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3674 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3675 that a comparison of an unsigned with -1 is always false. */
3676 if (last_addr != (CORE_ADDR) -1)
3677 set_next_address (last_addr);
3681 ui_out_table_end (uiout);
3683 /* FIXME? Should this be moved up so that it is only called when
3684 there have been breakpoints? */
3685 annotate_breakpoints_table_end ();
3690 breakpoints_info (bnum_exp, from_tty)
3697 bnum = parse_and_eval_address (bnum_exp);
3699 breakpoint_1 (bnum, 0);
3704 maintenance_info_breakpoints (bnum_exp, from_tty)
3711 bnum = parse_and_eval_address (bnum_exp);
3713 breakpoint_1 (bnum, 1);
3716 /* Print a message describing any breakpoints set at PC. */
3719 describe_other_breakpoints (pc, section)
3723 register int others = 0;
3724 register struct breakpoint *b;
3727 if (b->address == pc)
3728 if (overlay_debugging == 0 ||
3729 b->section == section)
3733 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3735 if (b->address == pc)
3736 if (overlay_debugging == 0 ||
3737 b->section == section)
3743 ((b->enable == disabled ||
3744 b->enable == shlib_disabled ||
3745 b->enable == call_disabled) ? " (disabled)"
3746 : b->enable == permanent ? " (permanent)"
3748 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3750 printf_filtered ("also set at pc ");
3751 print_address_numeric (pc, 1, gdb_stdout);
3752 printf_filtered (".\n");
3756 /* Set the default place to put a breakpoint
3757 for the `break' command with no arguments. */
3760 set_default_breakpoint (valid, addr, symtab, line)
3763 struct symtab *symtab;
3766 default_breakpoint_valid = valid;
3767 default_breakpoint_address = addr;
3768 default_breakpoint_symtab = symtab;
3769 default_breakpoint_line = line;
3772 /* Rescan breakpoints at address ADDRESS,
3773 marking the first one as "first" and any others as "duplicates".
3774 This is so that the bpt instruction is only inserted once.
3775 If we have a permanent breakpoint at ADDRESS, make that one
3776 the official one, and the rest as duplicates. */
3779 check_duplicates (address, section)
3783 register struct breakpoint *b;
3784 register int count = 0;
3785 struct breakpoint *perm_bp = 0;
3787 if (address == 0) /* Watchpoints are uninteresting */
3791 if (b->enable != disabled
3792 && b->enable != shlib_disabled
3793 && b->enable != call_disabled
3794 && b->address == address
3795 && (overlay_debugging == 0 || b->section == section))
3797 /* Have we found a permanent breakpoint? */
3798 if (b->enable == permanent)
3805 b->duplicate = count > 1;
3808 /* If we found a permanent breakpoint at this address, go over the
3809 list again and declare all the other breakpoints there to be the
3813 perm_bp->duplicate = 0;
3815 /* Permanent breakpoint should always be inserted. */
3816 if (! perm_bp->inserted)
3817 internal_error ("allegedly permanent breakpoint is not "
3818 "actually inserted");
3824 internal_error ("another breakpoint was inserted on top of "
3825 "a permanent breakpoint");
3827 if (b->enable != disabled
3828 && b->enable != shlib_disabled
3829 && b->enable != call_disabled
3830 && b->address == address
3831 && (overlay_debugging == 0 || b->section == section))
3837 /* Low level routine to set a breakpoint.
3838 Takes as args the three things that every breakpoint must have.
3839 Returns the breakpoint object so caller can set other things.
3840 Does not set the breakpoint number!
3841 Does not print anything.
3843 ==> This routine should not be called if there is a chance of later
3844 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3845 your arguments BEFORE calling this routine! */
3848 set_raw_breakpoint (sal)
3849 struct symtab_and_line sal;
3851 register struct breakpoint *b, *b1;
3853 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3854 memset (b, 0, sizeof (*b));
3855 b->address = sal.pc;
3856 if (sal.symtab == NULL)
3857 b->source_file = NULL;
3859 b->source_file = savestring (sal.symtab->filename,
3860 strlen (sal.symtab->filename));
3861 b->section = sal.section;
3862 b->language = current_language->la_language;
3863 b->input_radix = input_radix;
3865 b->line_number = sal.line;
3866 b->enable = enabled;
3869 b->ignore_count = 0;
3872 b->dll_pathname = NULL;
3873 b->triggered_dll_pathname = NULL;
3874 b->forked_inferior_pid = 0;
3875 b->exec_pathname = NULL;
3877 /* Add this breakpoint to the end of the chain
3878 so that a list of breakpoints will come out in order
3879 of increasing numbers. */
3881 b1 = breakpoint_chain;
3883 breakpoint_chain = b;
3891 check_duplicates (sal.pc, sal.section);
3892 breakpoints_changed ();
3898 /* Note that the breakpoint object B describes a permanent breakpoint
3899 instruction, hard-wired into the inferior's code. */
3901 make_breakpoint_permanent (struct breakpoint *b)
3903 b->enable = permanent;
3905 /* By definition, permanent breakpoints are already present in the code. */
3909 #ifdef GET_LONGJMP_TARGET
3912 create_longjmp_breakpoint (func_name)
3915 struct symtab_and_line sal;
3916 struct breakpoint *b;
3918 INIT_SAL (&sal); /* initialize to zeroes */
3919 if (func_name != NULL)
3921 struct minimal_symbol *m;
3923 m = lookup_minimal_symbol_text (func_name, NULL,
3924 (struct objfile *) NULL);
3926 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3930 sal.section = find_pc_overlay (sal.pc);
3931 b = set_raw_breakpoint (sal);
3935 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3936 b->disposition = donttouch;
3937 b->enable = disabled;
3940 b->addr_string = strsave (func_name);
3941 b->number = internal_breakpoint_number--;
3944 #endif /* #ifdef GET_LONGJMP_TARGET */
3946 /* Call this routine when stepping and nexting to enable a breakpoint
3947 if we do a longjmp(). When we hit that breakpoint, call
3948 set_longjmp_resume_breakpoint() to figure out where we are going. */
3951 enable_longjmp_breakpoint ()
3953 register struct breakpoint *b;
3956 if (b->type == bp_longjmp)
3958 b->enable = enabled;
3959 check_duplicates (b->address, b->section);
3964 disable_longjmp_breakpoint ()
3966 register struct breakpoint *b;
3969 if (b->type == bp_longjmp
3970 || b->type == bp_longjmp_resume)
3972 b->enable = disabled;
3973 check_duplicates (b->address, b->section);
3978 create_thread_event_breakpoint (address)
3981 struct breakpoint *b;
3982 struct symtab_and_line sal;
3983 char addr_string[80]; /* Surely an addr can't be longer than that. */
3985 INIT_SAL (&sal); /* initialize to zeroes */
3987 sal.section = find_pc_overlay (sal.pc);
3988 if ((b = set_raw_breakpoint (sal)) == NULL)
3991 b->number = internal_breakpoint_number--;
3992 b->disposition = donttouch;
3993 b->type = bp_thread_event; /* XXX: do we need a new type?
3995 b->enable = enabled;
3996 /* addr_string has to be used or breakpoint_re_set will delete me. */
3997 sprintf (addr_string, "*0x%s", paddr (b->address));
3998 b->addr_string = strsave (addr_string);
4004 remove_thread_event_breakpoints (void)
4006 struct breakpoint *b, *temp;
4008 ALL_BREAKPOINTS_SAFE (b, temp)
4009 if (b->type == bp_thread_event)
4010 delete_breakpoint (b);
4015 remove_solib_event_breakpoints ()
4017 register struct breakpoint *b, *temp;
4019 ALL_BREAKPOINTS_SAFE (b, temp)
4020 if (b->type == bp_shlib_event)
4021 delete_breakpoint (b);
4025 create_solib_event_breakpoint (address)
4028 struct breakpoint *b;
4029 struct symtab_and_line sal;
4031 INIT_SAL (&sal); /* initialize to zeroes */
4033 sal.section = find_pc_overlay (sal.pc);
4034 b = set_raw_breakpoint (sal);
4035 b->number = internal_breakpoint_number--;
4036 b->disposition = donttouch;
4037 b->type = bp_shlib_event;
4042 /* Disable any breakpoints that are on code in shared libraries. Only
4043 apply to enabled breakpoints, disabled ones can just stay disabled. */
4046 disable_breakpoints_in_shlibs (silent)
4049 struct breakpoint *b;
4050 int disabled_shlib_breaks = 0;
4052 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4055 #if defined (PC_SOLIB)
4056 if (((b->type == bp_breakpoint) ||
4057 (b->type == bp_hardware_breakpoint)) &&
4058 b->enable == enabled &&
4060 PC_SOLIB (b->address))
4062 b->enable = shlib_disabled;
4065 if (!disabled_shlib_breaks)
4067 target_terminal_ours_for_output ();
4068 warning ("Temporarily disabling shared library breakpoints:");
4070 disabled_shlib_breaks = 1;
4071 warning ("breakpoint #%d ", b->number);
4078 /* Try to reenable any breakpoints in shared libraries. */
4080 re_enable_breakpoints_in_shlibs ()
4082 struct breakpoint *b;
4085 if (b->enable == shlib_disabled)
4089 /* Do not reenable the breakpoint if the shared library
4090 is still not mapped in. */
4091 if (target_read_memory (b->address, buf, 1) == 0)
4092 b->enable = enabled;
4099 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
4104 enum bptype bp_kind;
4106 struct breakpoint *b;
4107 struct symtabs_and_lines sals;
4108 struct cleanup *old_chain;
4109 struct cleanup *canonical_strings_chain = NULL;
4110 char *addr_start = hookname;
4111 char *addr_end = NULL;
4112 char **canonical = (char **) NULL;
4113 int thread = -1; /* All threads. */
4115 /* Set a breakpoint on the specified hook. */
4116 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4117 addr_end = hookname;
4119 if (sals.nelts == 0)
4121 warning ("Unable to set a breakpoint on dynamic linker callback.");
4122 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4123 warning ("GDB will be unable to track shl_load/shl_unload calls");
4126 if (sals.nelts != 1)
4128 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4129 warning ("GDB will be unable to track shl_load/shl_unload calls");
4133 /* Make sure that all storage allocated in decode_line_1 gets freed
4134 in case the following errors out. */
4135 old_chain = make_cleanup (free, sals.sals);
4136 if (canonical != (char **) NULL)
4138 make_cleanup (free, canonical);
4139 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4140 if (canonical[0] != NULL)
4141 make_cleanup (free, canonical[0]);
4144 resolve_sal_pc (&sals.sals[0]);
4146 /* Remove the canonical strings from the cleanup, they are needed below. */
4147 if (canonical != (char **) NULL)
4148 discard_cleanups (canonical_strings_chain);
4150 b = set_raw_breakpoint (sals.sals[0]);
4151 set_breakpoint_count (breakpoint_count + 1);
4152 b->number = breakpoint_count;
4154 b->cond_string = (cond_string == NULL) ?
4155 NULL : savestring (cond_string, strlen (cond_string));
4158 if (canonical != (char **) NULL && canonical[0] != NULL)
4159 b->addr_string = canonical[0];
4160 else if (addr_start)
4161 b->addr_string = savestring (addr_start, addr_end - addr_start);
4163 b->enable = enabled;
4164 b->disposition = tempflag ? del : donttouch;
4166 if (dll_pathname == NULL)
4167 b->dll_pathname = NULL;
4170 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4171 strcpy (b->dll_pathname, dll_pathname);
4176 do_cleanups (old_chain);
4180 create_solib_load_event_breakpoint (hookname, tempflag,
4181 dll_pathname, cond_string)
4187 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4188 cond_string, bp_catch_load);
4192 create_solib_unload_event_breakpoint (hookname, tempflag,
4193 dll_pathname, cond_string)
4199 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4200 cond_string, bp_catch_unload);
4204 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
4207 enum bptype bp_kind;
4209 struct symtab_and_line sal;
4210 struct breakpoint *b;
4211 int thread = -1; /* All threads. */
4218 b = set_raw_breakpoint (sal);
4219 set_breakpoint_count (breakpoint_count + 1);
4220 b->number = breakpoint_count;
4222 b->cond_string = (cond_string == NULL) ?
4223 NULL : savestring (cond_string, strlen (cond_string));
4225 b->addr_string = NULL;
4226 b->enable = enabled;
4227 b->disposition = tempflag ? del : donttouch;
4228 b->forked_inferior_pid = 0;
4236 create_fork_event_catchpoint (tempflag, cond_string)
4240 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4244 create_vfork_event_catchpoint (tempflag, cond_string)
4248 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4252 create_exec_event_catchpoint (tempflag, cond_string)
4256 struct symtab_and_line sal;
4257 struct breakpoint *b;
4258 int thread = -1; /* All threads. */
4265 b = set_raw_breakpoint (sal);
4266 set_breakpoint_count (breakpoint_count + 1);
4267 b->number = breakpoint_count;
4269 b->cond_string = (cond_string == NULL) ?
4270 NULL : savestring (cond_string, strlen (cond_string));
4272 b->addr_string = NULL;
4273 b->enable = enabled;
4274 b->disposition = tempflag ? del : donttouch;
4276 b->type = bp_catch_exec;
4282 hw_breakpoint_used_count ()
4284 register struct breakpoint *b;
4289 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4297 hw_watchpoint_used_count (type, other_type_used)
4299 int *other_type_used;
4301 register struct breakpoint *b;
4304 *other_type_used = 0;
4307 if (b->enable == enabled)
4309 if (b->type == type)
4311 else if ((b->type == bp_hardware_watchpoint ||
4312 b->type == bp_read_watchpoint ||
4313 b->type == bp_access_watchpoint)
4314 && b->enable == enabled)
4315 *other_type_used = 1;
4321 /* Call this after hitting the longjmp() breakpoint. Use this to set
4322 a new breakpoint at the target of the jmp_buf.
4324 FIXME - This ought to be done by setting a temporary breakpoint
4325 that gets deleted automatically... */
4328 set_longjmp_resume_breakpoint (pc, frame)
4330 struct frame_info *frame;
4332 register struct breakpoint *b;
4335 if (b->type == bp_longjmp_resume)
4338 b->enable = enabled;
4340 b->frame = frame->frame;
4343 check_duplicates (b->address, b->section);
4349 disable_watchpoints_before_interactive_call_start ()
4351 struct breakpoint *b;
4355 if (((b->type == bp_watchpoint)
4356 || (b->type == bp_hardware_watchpoint)
4357 || (b->type == bp_read_watchpoint)
4358 || (b->type == bp_access_watchpoint)
4359 || ep_is_exception_catchpoint (b))
4360 && (b->enable == enabled))
4362 b->enable = call_disabled;
4363 check_duplicates (b->address, b->section);
4369 enable_watchpoints_after_interactive_call_stop ()
4371 struct breakpoint *b;
4375 if (((b->type == bp_watchpoint)
4376 || (b->type == bp_hardware_watchpoint)
4377 || (b->type == bp_read_watchpoint)
4378 || (b->type == bp_access_watchpoint)
4379 || ep_is_exception_catchpoint (b))
4380 && (b->enable == call_disabled))
4382 b->enable = enabled;
4383 check_duplicates (b->address, b->section);
4389 /* Set a breakpoint that will evaporate an end of command
4390 at address specified by SAL.
4391 Restrict it to frame FRAME if FRAME is nonzero. */
4394 set_momentary_breakpoint (sal, frame, type)
4395 struct symtab_and_line sal;
4396 struct frame_info *frame;
4399 register struct breakpoint *b;
4400 b = set_raw_breakpoint (sal);
4402 b->enable = enabled;
4403 b->disposition = donttouch;
4404 b->frame = (frame ? frame->frame : 0);
4406 /* If we're debugging a multi-threaded program, then we
4407 want momentary breakpoints to be active in only a
4408 single thread of control. */
4409 if (in_thread_list (inferior_pid))
4410 b->thread = pid_to_thread_id (inferior_pid);
4416 /* Tell the user we have just set a breakpoint B. */
4420 struct breakpoint *b;
4424 struct cleanup *old_chain;
4425 struct ui_stream *stb;
4427 stb = ui_out_stream_new (uiout);
4428 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
4431 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4432 watchpoint) other than breakpoint creation. It should be possible to
4433 clean this up and at the same time replace the random calls to
4434 breakpoint_changed with this hook, as has already been done for
4435 delete_breakpoint_hook and so on. */
4436 if (create_breakpoint_hook)
4437 create_breakpoint_hook (b);
4438 breakpoint_create_event (b->number);
4443 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4447 ui_out_text (uiout, "Watchpoint ");
4448 ui_out_list_begin (uiout, "wpt");
4449 ui_out_field_int (uiout, "number", b->number);
4450 ui_out_text (uiout, ": ");
4451 print_expression (b->exp, stb->stream);
4452 ui_out_field_stream (uiout, "exp", stb);
4453 ui_out_list_end (uiout);
4455 case bp_hardware_watchpoint:
4456 ui_out_text (uiout, "Hardware watchpoint ");
4457 ui_out_list_begin (uiout, "wpt");
4458 ui_out_field_int (uiout, "number", b->number);
4459 ui_out_text (uiout, ": ");
4460 print_expression (b->exp, stb->stream);
4461 ui_out_field_stream (uiout, "exp", stb);
4462 ui_out_list_end (uiout);
4466 printf_filtered ("Watchpoint %d: ", b->number);
4467 print_expression (b->exp, gdb_stdout);
4469 case bp_hardware_watchpoint:
4470 printf_filtered ("Hardware watchpoint %d: ", b->number);
4471 print_expression (b->exp, gdb_stdout);
4475 case bp_read_watchpoint:
4476 ui_out_text (uiout, "Hardware read watchpoint ");
4477 ui_out_list_begin (uiout, "hw-rwpt");
4478 ui_out_field_int (uiout, "number", b->number);
4479 ui_out_text (uiout, ": ");
4480 print_expression (b->exp, stb->stream);
4481 ui_out_field_stream (uiout, "exp", stb);
4482 ui_out_list_end (uiout);
4484 case bp_access_watchpoint:
4485 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4486 ui_out_list_begin (uiout, "hw-awpt");
4487 ui_out_field_int (uiout, "number", b->number);
4488 ui_out_text (uiout, ": ");
4489 print_expression (b->exp, stb->stream);
4490 ui_out_field_stream (uiout, "exp", stb);
4491 ui_out_list_end (uiout);
4494 case bp_read_watchpoint:
4495 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4496 print_expression (b->exp, gdb_stdout);
4498 case bp_access_watchpoint:
4499 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4501 print_expression (b->exp, gdb_stdout);
4506 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4512 printf_filtered ("Breakpoint %d", b->number);
4515 case bp_hardware_breakpoint:
4517 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4523 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4527 case bp_catch_unload:
4528 printf_filtered ("Catchpoint %d (%s %s)",
4530 (b->type == bp_catch_load) ? "load" : "unload",
4531 (b->dll_pathname != NULL) ?
4532 b->dll_pathname : "<any library>");
4535 case bp_catch_vfork:
4536 printf_filtered ("Catchpoint %d (%s)",
4538 (b->type == bp_catch_fork) ? "fork" : "vfork");
4541 printf_filtered ("Catchpoint %d (exec)",
4544 case bp_catch_catch:
4545 case bp_catch_throw:
4546 printf_filtered ("Catchpoint %d (%s)",
4548 (b->type == bp_catch_catch) ? "catch" : "throw");
4554 case bp_longjmp_resume:
4555 case bp_step_resume:
4556 case bp_through_sigtramp:
4558 case bp_watchpoint_scope:
4559 case bp_shlib_event:
4560 case bp_thread_event:
4565 if (addressprint || b->source_file == NULL)
4567 printf_filtered (" at ");
4568 print_address_numeric (b->address, 1, gdb_stdout);
4571 printf_filtered (": file %s, line %d.",
4572 b->source_file, b->line_number);
4573 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4574 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4577 do_cleanups (old_chain);
4580 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4583 printf_filtered ("\n");
4587 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4588 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4589 COND[i] and COND_STRING[i] values.
4591 NOTE: If the function succeeds, the caller is expected to cleanup
4592 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4593 array contents). If the function fails (error() is called), the
4594 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4595 COND and SALS arrays and each of those arrays contents. */
4598 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4599 struct expression **cond, char **cond_string,
4600 enum bptype type, enum bpdisp disposition,
4601 int thread, int ignore_count, int from_tty)
4603 if (type == bp_hardware_breakpoint)
4605 int i = hw_breakpoint_used_count ();
4606 int target_resources_ok =
4607 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4609 if (target_resources_ok == 0)
4610 error ("No hardware breakpoint support in the target.");
4611 else if (target_resources_ok < 0)
4612 error ("Hardware breakpoints used exceeds limit.");
4615 /* Now set all the breakpoints. */
4618 for (i = 0; i < sals.nelts; i++)
4620 struct breakpoint *b;
4621 struct symtab_and_line sal = sals.sals[i];
4624 describe_other_breakpoints (sal.pc, sal.section);
4626 b = set_raw_breakpoint (sal);
4627 set_breakpoint_count (breakpoint_count + 1);
4628 b->number = breakpoint_count;
4632 b->addr_string = addr_string[i];
4633 b->cond_string = cond_string[i];
4634 b->ignore_count = ignore_count;
4635 b->enable = enabled;
4636 b->disposition = disposition;
4642 /* Parse ARG which is assumed to be a SAL specification possibly
4643 followed by conditionals. On return, SALS contains an array of SAL
4644 addresses found. ADDR_STRING contains a vector of (canonical)
4645 address strings. ARG points to the end of the SAL. */
4648 parse_breakpoint_sals (char **address,
4649 struct symtabs_and_lines *sals,
4650 char ***addr_string)
4652 char *addr_start = *address;
4653 *addr_string = NULL;
4654 /* If no arg given, or if first arg is 'if ', use the default
4656 if ((*address) == NULL
4657 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4659 if (default_breakpoint_valid)
4661 struct symtab_and_line sal;
4662 INIT_SAL (&sal); /* initialize to zeroes */
4663 sals->sals = (struct symtab_and_line *)
4664 xmalloc (sizeof (struct symtab_and_line));
4665 sal.pc = default_breakpoint_address;
4666 sal.line = default_breakpoint_line;
4667 sal.symtab = default_breakpoint_symtab;
4668 sal.section = find_pc_overlay (sal.pc);
4669 sals->sals[0] = sal;
4673 error ("No default breakpoint address now.");
4677 /* Force almost all breakpoints to be in terms of the
4678 current_source_symtab (which is decode_line_1's default). This
4679 should produce the results we want almost all of the time while
4680 leaving default_breakpoint_* alone. */
4681 if (default_breakpoint_valid
4682 && (!current_source_symtab
4683 || (strchr ("+-", (*address)[0]) != NULL)))
4684 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4685 default_breakpoint_line, addr_string);
4687 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4689 /* For any SAL that didn't have a canonical string, fill one in. */
4690 if (sals->nelts > 0 && *addr_string == NULL)
4691 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4692 if (addr_start != (*address))
4695 for (i = 0; i < sals->nelts; i++)
4697 /* Add the string if not present. */
4698 if ((*addr_string)[i] == NULL)
4699 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4705 /* Convert each SAL into a real PC. Verify that the PC can be
4706 inserted as a breakpoint. If it can't throw an error. */
4709 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4713 for (i = 0; i < sals->nelts; i++)
4715 resolve_sal_pc (&sals->sals[i]);
4717 /* It's possible for the PC to be nonzero, but still an illegal
4718 value on some targets.
4720 For example, on HP-UX if you start gdb, and before running the
4721 inferior you try to set a breakpoint on a shared library function
4722 "foo" where the inferior doesn't call "foo" directly but does
4723 pass its address to another function call, then we do find a
4724 minimal symbol for the "foo", but it's address is invalid.
4725 (Appears to be an index into a table that the loader sets up
4726 when the inferior is run.)
4728 Give the target a chance to bless sals.sals[i].pc before we
4729 try to make a breakpoint for it. */
4730 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4732 if (address == NULL)
4733 error ("Cannot break without a running program.");
4735 error ("Cannot break on %s without a running program.",
4741 /* Set a breakpoint according to ARG (function, linenum or *address)
4742 flag: first bit : 0 non-temporary, 1 temporary.
4743 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4746 break_command_1 (arg, flag, from_tty)
4750 int tempflag, hardwareflag;
4751 struct symtabs_and_lines sals;
4752 register struct expression **cond = 0;
4753 /* Pointers in arg to the start, and one past the end, of the
4755 char **cond_string = (char **) NULL;
4756 char *addr_start = arg;
4758 struct cleanup *old_chain;
4759 struct cleanup *breakpoint_chain = NULL;
4762 int ignore_count = 0;
4764 hardwareflag = flag & BP_HARDWAREFLAG;
4765 tempflag = flag & BP_TEMPFLAG;
4770 parse_breakpoint_sals (&arg, &sals, &addr_string);
4775 /* Create a chain of things that always need to be cleaned up. */
4776 old_chain = make_cleanup (null_cleanup, 0);
4778 /* Make sure that all storage allocated to SALS gets freed. */
4779 make_cleanup (free, sals.sals);
4781 /* Cleanup the addr_string array but not its contents. */
4782 make_cleanup (free, addr_string);
4784 /* Allocate space for all the cond expressions. */
4785 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4786 make_cleanup (free, cond);
4788 /* Allocate space for all the cond strings. */
4789 cond_string = xcalloc (sals.nelts, sizeof (char **));
4790 make_cleanup (free, cond_string);
4792 /* ----------------------------- SNIP -----------------------------
4793 Anything added to the cleanup chain beyond this point is assumed
4794 to be part of a breakpoint. If the breakpoint create succeeds
4795 then the memory is not reclaimed. */
4796 breakpoint_chain = make_cleanup (null_cleanup, 0);
4798 /* Mark the contents of the addr_string for cleanup. These go on
4799 the breakpoint_chain and only occure if the breakpoint create
4801 for (i = 0; i < sals.nelts; i++)
4803 if (addr_string[i] != NULL)
4804 make_cleanup (free, addr_string[i]);
4807 /* Resolve all line numbers to PC's and verify that the addresses
4808 are ok for the target. */
4809 breakpoint_sals_to_pc (&sals, addr_start);
4811 /* Verify that condition can be parsed, before setting any
4812 breakpoints. Allocate a separate condition expression for each
4814 thread = -1; /* No specific thread yet */
4815 for (i = 0; i < sals.nelts; i++)
4822 char *cond_start = NULL;
4823 char *cond_end = NULL;
4824 while (*tok == ' ' || *tok == '\t')
4829 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4832 toklen = end_tok - tok;
4834 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4836 tok = cond_start = end_tok + 1;
4837 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4838 make_cleanup (free, cond[i]);
4840 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4841 make_cleanup (free, cond_string[i]);
4843 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4849 thread = strtol (tok, &tok, 0);
4851 error ("Junk after thread keyword.");
4852 if (!valid_thread_id (thread))
4853 error ("Unknown thread %d\n", thread);
4856 error ("Junk at end of arguments.");
4860 create_breakpoints (sals, addr_string, cond, cond_string,
4861 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4862 tempflag ? del : donttouch,
4863 thread, ignore_count, from_tty);
4867 warning ("Multiple breakpoints were set.");
4868 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4870 /* That's it. Discard the cleanups for data inserted into the
4872 discard_cleanups (breakpoint_chain);
4873 /* But cleanup everything else. */
4874 do_cleanups (old_chain);
4877 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4878 linenum or *address) with COND and IGNORE_COUNT. */
4880 struct captured_breakpoint_args
4891 do_captured_breakpoint (void *data)
4893 struct captured_breakpoint_args *args = data;
4894 struct symtabs_and_lines sals;
4895 register struct expression **cond;
4896 struct cleanup *old_chain;
4897 struct cleanup *breakpoint_chain = NULL;
4904 /* Parse the source and lines spec. Delay check that the expression
4905 didn't contain trailing garbage until after cleanups are in
4909 address_end = args->address;
4911 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4916 /* Create a chain of things at always need to be cleaned up. */
4917 old_chain = make_cleanup (null_cleanup, 0);
4919 /* Always have a addr_string array, even if it is empty. */
4920 make_cleanup (free, addr_string);
4922 /* Make sure that all storage allocated to SALS gets freed. */
4923 make_cleanup (free, sals.sals);
4925 /* Allocate space for all the cond expressions. */
4926 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4927 make_cleanup (free, cond);
4929 /* Allocate space for all the cond strings. */
4930 cond_string = xcalloc (sals.nelts, sizeof (char **));
4931 make_cleanup (free, cond_string);
4933 /* ----------------------------- SNIP -----------------------------
4934 Anything added to the cleanup chain beyond this point is assumed
4935 to be part of a breakpoint. If the breakpoint create goes
4936 through then that memory is not cleaned up. */
4937 breakpoint_chain = make_cleanup (null_cleanup, 0);
4939 /* Mark the contents of the addr_string for cleanup. These go on
4940 the breakpoint_chain and only occure if the breakpoint create
4942 for (i = 0; i < sals.nelts; i++)
4944 if (addr_string[i] != NULL)
4945 make_cleanup (free, addr_string[i]);
4948 /* Wait until now before checking for garbage at the end of the
4949 address. That way cleanups can take care of freeing any
4951 if (*address_end != '\0')
4952 error ("Garbage %s following breakpoint address", address_end);
4954 /* Resolve all line numbers to PC's. */
4955 breakpoint_sals_to_pc (&sals, args->address);
4957 /* Verify that conditions can be parsed, before setting any
4959 for (i = 0; i < sals.nelts; i++)
4961 if (args->condition != NULL)
4963 char *tok = args->condition;
4964 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4966 error ("Garbage %s follows condition", tok);
4967 make_cleanup (free, cond[i]);
4968 cond_string[i] = xstrdup (args->condition);
4972 create_breakpoints (sals, addr_string, cond, cond_string,
4973 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4974 args->tempflag ? del : donttouch,
4975 args->thread, args->ignore_count, 0/*from-tty*/);
4977 /* That's it. Discard the cleanups for data inserted into the
4979 discard_cleanups (breakpoint_chain);
4980 /* But cleanup everything else. */
4981 do_cleanups (old_chain);
4986 gdb_breakpoint (char *address, char *condition,
4987 int hardwareflag, int tempflag,
4988 int thread, int ignore_count)
4990 struct captured_breakpoint_args args;
4991 args.address = address;
4992 args.condition = condition;
4993 args.hardwareflag = hardwareflag;
4994 args.tempflag = tempflag;
4995 args.thread = thread;
4996 args.ignore_count = ignore_count;
4997 return catch_errors (do_captured_breakpoint, &args,
4998 NULL, RETURN_MASK_ALL);
5003 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
5008 struct frame_info *frame;
5009 CORE_ADDR low, high, selected_pc = 0;
5010 char *extra_args, *level_arg, *addr_string;
5011 int extra_args_len = 0, if_arg = 0;
5014 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5017 if (default_breakpoint_valid)
5021 selected_pc = selected_frame->pc;
5026 error ("No selected frame.");
5029 error ("No default breakpoint address now.");
5033 extra_args = strchr (arg, ' ');
5037 extra_args_len = strlen (extra_args);
5038 level_arg = (char *) xmalloc (extra_args - arg);
5039 strncpy (level_arg, arg, extra_args - arg - 1);
5040 level_arg[extra_args - arg - 1] = '\0';
5044 level_arg = (char *) xmalloc (strlen (arg) + 1);
5045 strcpy (level_arg, arg);
5048 frame = parse_frame_specification (level_arg);
5050 selected_pc = frame->pc;
5057 extra_args_len = strlen (arg);
5062 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5064 addr_string = (char *) xmalloc (26 + extra_args_len);
5066 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
5068 sprintf (addr_string, "*0x%s", paddr_nz (high));
5069 break_command_1 (addr_string, flag, from_tty);
5073 error ("No function contains the specified address");
5076 error ("Unable to set breakpoint at procedure exit");
5081 break_at_finish_command_1 (arg, flag, from_tty)
5086 char *addr_string, *break_string, *beg_addr_string;
5087 CORE_ADDR low, high;
5088 struct symtabs_and_lines sals;
5089 struct symtab_and_line sal;
5090 struct cleanup *old_chain;
5092 int extra_args_len = 0;
5096 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5098 if (default_breakpoint_valid)
5102 addr_string = (char *) xmalloc (15);
5103 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5108 error ("No selected frame.");
5111 error ("No default breakpoint address now.");
5115 addr_string = (char *) xmalloc (strlen (arg) + 1);
5116 strcpy (addr_string, arg);
5122 extra_args_len = strlen (arg);
5126 /* get the stuff after the function name or address */
5127 extra_args = strchr (arg, ' ');
5131 extra_args_len = strlen (extra_args);
5138 beg_addr_string = addr_string;
5139 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5142 free (beg_addr_string);
5143 old_chain = make_cleanup (free, sals.sals);
5144 for (i = 0; (i < sals.nelts); i++)
5147 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5149 break_string = (char *) xmalloc (extra_args_len + 26);
5151 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5153 sprintf (break_string, "*0x%s", paddr_nz (high));
5154 break_command_1 (break_string, flag, from_tty);
5155 free (break_string);
5158 error ("No function contains the specified address");
5162 warning ("Multiple breakpoints were set.\n");
5163 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5165 do_cleanups (old_chain);
5169 /* Helper function for break_command_1 and disassemble_command. */
5172 resolve_sal_pc (sal)
5173 struct symtab_and_line *sal;
5177 if (sal->pc == 0 && sal->symtab != NULL)
5179 if (!find_line_pc (sal->symtab, sal->line, &pc))
5180 error ("No line %d in file \"%s\".",
5181 sal->line, sal->symtab->filename);
5185 if (sal->section == 0 && sal->symtab != NULL)
5187 struct blockvector *bv;
5192 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5195 b = BLOCKVECTOR_BLOCK (bv, index);
5196 sym = block_function (b);
5199 fixup_symbol_section (sym, sal->symtab->objfile);
5200 sal->section = SYMBOL_BFD_SECTION (sym);
5204 /* It really is worthwhile to have the section, so we'll just
5205 have to look harder. This case can be executed if we have
5206 line numbers but no functions (as can happen in assembly
5209 struct minimal_symbol *msym;
5211 msym = lookup_minimal_symbol_by_pc (sal->pc);
5213 sal->section = SYMBOL_BFD_SECTION (msym);
5220 break_command (arg, from_tty)
5224 break_command_1 (arg, 0, from_tty);
5228 break_at_finish_command (arg, from_tty)
5232 break_at_finish_command_1 (arg, 0, from_tty);
5236 break_at_finish_at_depth_command (arg, from_tty)
5240 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5244 tbreak_command (arg, from_tty)
5248 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5252 tbreak_at_finish_command (arg, from_tty)
5256 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5260 hbreak_command (arg, from_tty)
5264 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5268 thbreak_command (arg, from_tty)
5272 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5276 stop_command (arg, from_tty)
5280 printf_filtered ("Specify the type of breakpoint to set.\n\
5281 Usage: stop in <function | address>\n\
5286 stopin_command (arg, from_tty)
5292 if (arg == (char *) NULL)
5294 else if (*arg != '*')
5299 /* look for a ':'. If this is a line number specification, then
5300 say it is bad, otherwise, it should be an address or
5301 function/method name */
5302 while (*argptr && !hasColon)
5304 hasColon = (*argptr == ':');
5309 badInput = (*argptr != ':'); /* Not a class::method */
5311 badInput = isdigit (*arg); /* a simple line number */
5315 printf_filtered ("Usage: stop in <function | address>\n");
5317 break_command_1 (arg, 0, from_tty);
5321 stopat_command (arg, from_tty)
5327 if (arg == (char *) NULL || *arg == '*') /* no line number */
5334 /* look for a ':'. If there is a '::' then get out, otherwise
5335 it is probably a line number. */
5336 while (*argptr && !hasColon)
5338 hasColon = (*argptr == ':');
5343 badInput = (*argptr == ':'); /* we have class::method */
5345 badInput = !isdigit (*arg); /* not a line number */
5349 printf_filtered ("Usage: stop at <line>\n");
5351 break_command_1 (arg, 0, from_tty);
5355 /* accessflag: hw_write: watch write,
5356 hw_read: watch read,
5357 hw_access: watch access (read or write) */
5359 watch_command_1 (arg, accessflag, from_tty)
5364 struct breakpoint *b;
5365 struct symtab_and_line sal;
5366 struct expression *exp;
5367 struct block *exp_valid_block;
5368 struct value *val, *mark;
5369 struct frame_info *frame;
5370 struct frame_info *prev_frame = NULL;
5371 char *exp_start = NULL;
5372 char *exp_end = NULL;
5373 char *tok, *end_tok;
5375 char *cond_start = NULL;
5376 char *cond_end = NULL;
5377 struct expression *cond = NULL;
5378 int i, other_type_used, target_resources_ok = 0;
5379 enum bptype bp_type;
5382 INIT_SAL (&sal); /* initialize to zeroes */
5384 /* Parse arguments. */
5385 innermost_block = NULL;
5387 exp = parse_exp_1 (&arg, 0, 0);
5389 exp_valid_block = innermost_block;
5390 mark = value_mark ();
5391 val = evaluate_expression (exp);
5392 release_value (val);
5393 if (VALUE_LAZY (val))
5394 value_fetch_lazy (val);
5397 while (*tok == ' ' || *tok == '\t')
5401 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5404 toklen = end_tok - tok;
5405 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5407 tok = cond_start = end_tok + 1;
5408 cond = parse_exp_1 (&tok, 0, 0);
5412 error ("Junk at end of command.");
5414 if (accessflag == hw_read)
5415 bp_type = bp_read_watchpoint;
5416 else if (accessflag == hw_access)
5417 bp_type = bp_access_watchpoint;
5419 bp_type = bp_hardware_watchpoint;
5421 mem_cnt = can_use_hardware_watchpoint (val);
5422 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5423 error ("Expression cannot be implemented with read/access watchpoint.");
5426 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5427 target_resources_ok =
5428 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5430 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5431 error ("Target does not support this type of hardware watchpoint.");
5433 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5434 error ("Target can only support one kind of HW watchpoint at a time.");
5437 #if defined(HPUXHPPA)
5438 /* On HP-UX if you set a h/w
5439 watchpoint before the "run" command, the inferior dies with a e.g.,
5440 SIGILL once you start it. I initially believed this was due to a
5441 bad interaction between page protection traps and the initial
5442 startup sequence by the dynamic linker.
5444 However, I tried avoiding that by having HP-UX's implementation of
5445 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
5446 yet, which forced slow watches before a "run" or "attach", and it
5447 still fails somewhere in the startup code.
5449 Until I figure out what's happening, I'm disallowing watches altogether
5450 before the "run" or "attach" command. We'll tell the user they must
5451 set watches after getting the program started. */
5452 if (!target_has_execution)
5454 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5457 #endif /* HPUXHPPA */
5459 /* Now set up the breakpoint. */
5460 b = set_raw_breakpoint (sal);
5461 set_breakpoint_count (breakpoint_count + 1);
5462 b->number = breakpoint_count;
5463 b->disposition = donttouch;
5465 b->exp_valid_block = exp_valid_block;
5466 b->exp_string = savestring (exp_start, exp_end - exp_start);
5470 b->cond_string = savestring (cond_start, cond_end - cond_start);
5474 frame = block_innermost_frame (exp_valid_block);
5477 prev_frame = get_prev_frame (frame);
5478 b->watchpoint_frame = frame->frame;
5481 b->watchpoint_frame = (CORE_ADDR) 0;
5483 if (mem_cnt && target_resources_ok > 0)
5486 b->type = bp_watchpoint;
5488 /* If the expression is "local", then set up a "watchpoint scope"
5489 breakpoint at the point where we've left the scope of the watchpoint
5491 if (innermost_block)
5495 struct breakpoint *scope_breakpoint;
5496 struct symtab_and_line scope_sal;
5498 INIT_SAL (&scope_sal); /* initialize to zeroes */
5499 scope_sal.pc = get_frame_pc (prev_frame);
5500 scope_sal.section = find_pc_overlay (scope_sal.pc);
5502 scope_breakpoint = set_raw_breakpoint (scope_sal);
5503 set_breakpoint_count (breakpoint_count + 1);
5504 scope_breakpoint->number = breakpoint_count;
5506 scope_breakpoint->type = bp_watchpoint_scope;
5507 scope_breakpoint->enable = enabled;
5509 /* Automatically delete the breakpoint when it hits. */
5510 scope_breakpoint->disposition = del;
5512 /* Only break in the proper frame (help with recursion). */
5513 scope_breakpoint->frame = prev_frame->frame;
5515 /* Set the address at which we will stop. */
5516 scope_breakpoint->address = get_frame_pc (prev_frame);
5518 /* The scope breakpoint is related to the watchpoint. We
5519 will need to act on them together. */
5520 b->related_breakpoint = scope_breakpoint;
5523 value_free_to_mark (mark);
5527 /* Return count of locations need to be watched and can be handled
5528 in hardware. If the watchpoint can not be handled
5529 in hardware return zero. */
5531 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5532 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5533 ((BYTE_SIZE) <= (REGISTER_SIZE))
5536 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5537 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5538 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
5542 can_use_hardware_watchpoint (v)
5545 int found_memory_cnt = 0;
5546 struct value *head = v;
5548 /* Did the user specifically forbid us to use hardware watchpoints? */
5549 if (!can_use_hw_watchpoints)
5552 /* Make sure that the value of the expression depends only upon
5553 memory contents, and values computed from them within GDB. If we
5554 find any register references or function calls, we can't use a
5555 hardware watchpoint.
5557 The idea here is that evaluating an expression generates a series
5558 of values, one holding the value of every subexpression. (The
5559 expression a*b+c has five subexpressions: a, b, a*b, c, and
5560 a*b+c.) GDB's values hold almost enough information to establish
5561 the criteria given above --- they identify memory lvalues,
5562 register lvalues, computed values, etcetera. So we can evaluate
5563 the expression, and then scan the chain of values that leaves
5564 behind to decide whether we can detect any possible change to the
5565 expression's final value using only hardware watchpoints.
5567 However, I don't think that the values returned by inferior
5568 function calls are special in any way. So this function may not
5569 notice that an expression involving an inferior function call
5570 can't be watched with hardware watchpoints. FIXME. */
5571 for (; v; v = v->next)
5573 if (VALUE_LVAL (v) == lval_memory)
5576 /* A lazy memory lvalue is one that GDB never needed to fetch;
5577 we either just used its address (e.g., `a' in `a.b') or
5578 we never needed it at all (e.g., `a' in `a,b'). */
5582 /* Ahh, memory we actually used! Check if we can cover
5583 it with hardware watchpoints. */
5584 struct type *vtype = check_typedef (VALUE_TYPE (v));
5586 /* We only watch structs and arrays if user asked for it
5587 explicitly, never if they just happen to appear in a
5588 middle of some value chain. */
5590 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5591 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5593 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5594 int len = TYPE_LENGTH (VALUE_TYPE (v));
5596 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5603 else if (v->lval != not_lval && v->modifiable == 0)
5604 return 0; /* ??? What does this represent? */
5605 else if (v->lval == lval_register)
5606 return 0; /* cannot watch a register with a HW watchpoint */
5609 /* The expression itself looks suitable for using a hardware
5610 watchpoint, but give the target machine a chance to reject it. */
5611 return found_memory_cnt;
5616 watch_command_wrapper (arg, from_tty)
5620 watch_command (arg, from_tty);
5624 watch_command (arg, from_tty)
5628 watch_command_1 (arg, hw_write, from_tty);
5633 rwatch_command_wrapper (arg, from_tty)
5637 rwatch_command (arg, from_tty);
5641 rwatch_command (arg, from_tty)
5645 watch_command_1 (arg, hw_read, from_tty);
5650 awatch_command_wrapper (arg, from_tty)
5654 awatch_command (arg, from_tty);
5658 awatch_command (arg, from_tty)
5662 watch_command_1 (arg, hw_access, from_tty);
5666 /* Helper routines for the until_command routine in infcmd.c. Here
5667 because it uses the mechanisms of breakpoints. */
5669 /* This function is called by fetch_inferior_event via the
5670 cmd_continuation pointer, to complete the until command. It takes
5671 care of cleaning up the temporary breakpoints set up by the until
5674 until_break_command_continuation (struct continuation_arg *arg)
5676 struct cleanup *cleanups;
5678 cleanups = (struct cleanup *) arg->data;
5679 do_exec_cleanups (cleanups);
5684 until_break_command (arg, from_tty)
5688 struct symtabs_and_lines sals;
5689 struct symtab_and_line sal;
5690 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5691 struct breakpoint *breakpoint;
5692 struct cleanup *old_chain;
5693 struct continuation_arg *arg1;
5696 clear_proceed_status ();
5698 /* Set a breakpoint where the user wants it and at return from
5701 if (default_breakpoint_valid)
5702 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5703 default_breakpoint_line, (char ***) NULL);
5705 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5706 0, (char ***) NULL);
5708 if (sals.nelts != 1)
5709 error ("Couldn't get information on specified line.");
5712 free ((PTR) sals.sals); /* malloc'd, so freed */
5715 error ("Junk at end of arguments.");
5717 resolve_sal_pc (&sal);
5719 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5721 if (!event_loop_p || !target_can_async_p ())
5722 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
5725 old_chain = make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5727 /* If we are running asynchronously, and the target supports async
5728 execution, we are not waiting for the target to stop, in the call
5729 tp proceed, below. This means that we cannot delete the
5730 brekpoints until the target has actually stopped. The only place
5731 where we get a chance to do that is in fetch_inferior_event, so
5732 we must set things up for that. */
5734 if (event_loop_p && target_can_async_p ())
5736 /* In this case the arg for the continuation is just the point
5737 in the exec_cleanups chain from where to start doing
5738 cleanups, because all the continuation does is the cleanups in
5739 the exec_cleanup_chain. */
5741 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5743 arg1->data = (PTR) old_chain;
5745 add_continuation (until_break_command_continuation, arg1);
5748 /* Keep within the current frame */
5752 sal = find_pc_line (prev_frame->pc, 0);
5753 sal.pc = prev_frame->pc;
5754 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5755 if (!event_loop_p || !target_can_async_p ())
5756 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5758 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5761 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5762 /* Do the cleanups now, anly if we are not running asynchronously,
5763 of if we are, but the target is still synchronous. */
5764 if (!event_loop_p || !target_can_async_p ())
5765 do_cleanups (old_chain);
5769 /* These aren't used; I don't konw what they were for. */
5770 /* Set a breakpoint at the catch clause for NAME. */
5772 catch_breakpoint (name)
5778 disable_catch_breakpoint ()
5783 delete_catch_breakpoint ()
5788 enable_catch_breakpoint ()
5795 struct sal_chain *next;
5796 struct symtab_and_line sal;
5800 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5801 had been commented out in the v.4.16 sources, and stays
5802 disabled there now because "catch NAME" syntax isn't allowed.
5804 /* This isn't used; I don't know what it was for. */
5805 /* For each catch clause identified in ARGS, run FUNCTION
5806 with that clause as an argument. */
5807 static struct symtabs_and_lines
5808 map_catch_names (args, function)
5812 register char *p = args;
5814 struct symtabs_and_lines sals;
5816 struct sal_chain *sal_chain = 0;
5820 error_no_arg ("one or more catch names");
5828 /* Don't swallow conditional part. */
5829 if (p1[0] == 'i' && p1[1] == 'f'
5830 && (p1[2] == ' ' || p1[2] == '\t'))
5836 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5840 if (*p1 && *p1 != ' ' && *p1 != '\t')
5841 error ("Arguments must be catch names.");
5847 struct sal_chain *next = (struct sal_chain *)
5848 alloca (sizeof (struct sal_chain));
5849 next->next = sal_chain;
5850 next->sal = get_catch_sal (p);
5855 printf_unfiltered ("No catch clause for exception %s.\n", p);
5860 while (*p == ' ' || *p == '\t')
5866 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5868 static struct symtabs_and_lines
5869 get_catch_sals (this_level_only)
5870 int this_level_only;
5872 register struct blockvector *bl;
5873 register struct block *block;
5874 int index, have_default = 0;
5876 struct symtabs_and_lines sals;
5877 struct sal_chain *sal_chain = 0;
5878 char *blocks_searched;
5880 /* Not sure whether an error message is always the correct response,
5881 but it's better than a core dump. */
5882 if (selected_frame == NULL)
5883 error ("No selected frame.");
5884 block = get_frame_block (selected_frame);
5885 pc = selected_frame->pc;
5891 error ("No symbol table info available.\n");
5893 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5894 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5895 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5899 CORE_ADDR end = BLOCK_END (block) - 4;
5902 if (bl != blockvector_for_pc (end, &index))
5903 error ("blockvector blotch");
5904 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5905 error ("blockvector botch");
5906 last_index = BLOCKVECTOR_NBLOCKS (bl);
5909 /* Don't print out blocks that have gone by. */
5910 while (index < last_index
5911 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5914 while (index < last_index
5915 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5917 if (blocks_searched[index] == 0)
5919 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5922 register struct symbol *sym;
5924 nsyms = BLOCK_NSYMS (b);
5926 for (i = 0; i < nsyms; i++)
5928 sym = BLOCK_SYM (b, i);
5929 if (STREQ (SYMBOL_NAME (sym), "default"))
5935 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5937 struct sal_chain *next = (struct sal_chain *)
5938 alloca (sizeof (struct sal_chain));
5939 next->next = sal_chain;
5940 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5945 blocks_searched[index] = 1;
5951 if (sal_chain && this_level_only)
5954 /* After handling the function's top-level block, stop.
5955 Don't continue to its superblock, the block of
5956 per-file symbols. */
5957 if (BLOCK_FUNCTION (block))
5959 block = BLOCK_SUPERBLOCK (block);
5964 struct sal_chain *tmp_chain;
5966 /* Count the number of entries. */
5967 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5968 tmp_chain = tmp_chain->next)
5972 sals.sals = (struct symtab_and_line *)
5973 xmalloc (index * sizeof (struct symtab_and_line));
5974 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5975 sals.sals[index] = sal_chain->sal;
5982 ep_skip_leading_whitespace (s)
5985 if ((s == NULL) || (*s == NULL))
5987 while (isspace (**s))
5991 /* This function examines a string, and attempts to find a token
5992 that might be an event name in the leading characters. If a
5993 possible match is found, a pointer to the last character of
5994 the token is returned. Else, NULL is returned. */
5997 ep_find_event_name_end (arg)
6001 char *event_name_end = NULL;
6003 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6007 /* We break out of the loop when we find a token delimiter.
6008 Basically, we're looking for alphanumerics and underscores;
6009 anything else delimites the token. */
6012 if (!isalnum (*s) && (*s != '_'))
6018 return event_name_end;
6022 /* This function attempts to parse an optional "if <cond>" clause
6023 from the arg string. If one is not found, it returns NULL.
6025 Else, it returns a pointer to the condition string. (It does not
6026 attempt to evaluate the string against a particular block.) And,
6027 it updates arg to point to the first character following the parsed
6028 if clause in the arg string. */
6031 ep_parse_optional_if_clause (arg)
6036 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6039 /* Skip the "if" keyword. */
6042 /* Skip any extra leading whitespace, and record the start of the
6043 condition string. */
6044 ep_skip_leading_whitespace (arg);
6047 /* Assume that the condition occupies the remainder of the arg string. */
6048 (*arg) += strlen (cond_string);
6053 /* This function attempts to parse an optional filename from the arg
6054 string. If one is not found, it returns NULL.
6056 Else, it returns a pointer to the parsed filename. (This function
6057 makes no attempt to verify that a file of that name exists, or is
6058 accessible.) And, it updates arg to point to the first character
6059 following the parsed filename in the arg string.
6061 Note that clients needing to preserve the returned filename for
6062 future access should copy it to their own buffers. */
6064 ep_parse_optional_filename (arg)
6067 static char filename[1024];
6072 if ((*arg_p == '\0') || isspace (*arg_p))
6090 /* Commands to deal with catching events, such as signals, exceptions,
6091 process start/exit, etc. */
6095 catch_fork, catch_vfork
6099 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
6100 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
6106 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
6107 catch_fork_kind fork_kind;
6112 char *cond_string = NULL;
6114 ep_skip_leading_whitespace (&arg);
6116 /* The allowed syntax is:
6118 catch [v]fork if <cond>
6120 First, check if there's an if clause. */
6121 cond_string = ep_parse_optional_if_clause (&arg);
6123 if ((*arg != '\0') && !isspace (*arg))
6124 error ("Junk at end of arguments.");
6126 /* If this target supports it, create a fork or vfork catchpoint
6127 and enable reporting of such events. */
6131 create_fork_event_catchpoint (tempflag, cond_string);
6134 create_vfork_event_catchpoint (tempflag, cond_string);
6137 error ("unsupported or unknown fork kind; cannot catch it");
6143 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6145 catch_exec_command_1 (arg, tempflag, from_tty)
6150 char *cond_string = NULL;
6152 ep_skip_leading_whitespace (&arg);
6154 /* The allowed syntax is:
6156 catch exec if <cond>
6158 First, check if there's an if clause. */
6159 cond_string = ep_parse_optional_if_clause (&arg);
6161 if ((*arg != '\0') && !isspace (*arg))
6162 error ("Junk at end of arguments.");
6164 /* If this target supports it, create an exec catchpoint
6165 and enable reporting of such events. */
6166 create_exec_event_catchpoint (tempflag, cond_string);
6170 #if defined(SOLIB_ADD)
6172 catch_load_command_1 (arg, tempflag, from_tty)
6177 char *dll_pathname = NULL;
6178 char *cond_string = NULL;
6180 ep_skip_leading_whitespace (&arg);
6182 /* The allowed syntax is:
6184 catch load if <cond>
6185 catch load <filename>
6186 catch load <filename> if <cond>
6188 The user is not allowed to specify the <filename> after an
6191 We'll ignore the pathological case of a file named "if".
6193 First, check if there's an if clause. If so, then there
6194 cannot be a filename. */
6195 cond_string = ep_parse_optional_if_clause (&arg);
6197 /* If there was an if clause, then there cannot be a filename.
6198 Else, there might be a filename and an if clause. */
6199 if (cond_string == NULL)
6201 dll_pathname = ep_parse_optional_filename (&arg);
6202 ep_skip_leading_whitespace (&arg);
6203 cond_string = ep_parse_optional_if_clause (&arg);
6206 if ((*arg != '\0') && !isspace (*arg))
6207 error ("Junk at end of arguments.");
6209 /* Create a load breakpoint that only triggers when a load of
6210 the specified dll (or any dll, if no pathname was specified)
6212 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
6213 dll_pathname, cond_string);
6217 catch_unload_command_1 (arg, tempflag, from_tty)
6222 char *dll_pathname = NULL;
6223 char *cond_string = NULL;
6225 ep_skip_leading_whitespace (&arg);
6227 /* The allowed syntax is:
6229 catch unload if <cond>
6230 catch unload <filename>
6231 catch unload <filename> if <cond>
6233 The user is not allowed to specify the <filename> after an
6236 We'll ignore the pathological case of a file named "if".
6238 First, check if there's an if clause. If so, then there
6239 cannot be a filename. */
6240 cond_string = ep_parse_optional_if_clause (&arg);
6242 /* If there was an if clause, then there cannot be a filename.
6243 Else, there might be a filename and an if clause. */
6244 if (cond_string == NULL)
6246 dll_pathname = ep_parse_optional_filename (&arg);
6247 ep_skip_leading_whitespace (&arg);
6248 cond_string = ep_parse_optional_if_clause (&arg);
6251 if ((*arg != '\0') && !isspace (*arg))
6252 error ("Junk at end of arguments.");
6254 /* Create an unload breakpoint that only triggers when an unload of
6255 the specified dll (or any dll, if no pathname was specified)
6257 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
6258 dll_pathname, cond_string);
6260 #endif /* SOLIB_ADD */
6262 /* Commands to deal with catching exceptions. */
6264 /* Set a breakpoint at the specified callback routine for an
6265 exception event callback */
6268 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
6271 enum exception_event_kind ex_event;
6272 struct symtab_and_line *sal;
6274 struct breakpoint *b;
6275 int thread = -1; /* All threads. */
6277 if (!sal) /* no exception support? */
6280 b = set_raw_breakpoint (*sal);
6281 set_breakpoint_count (breakpoint_count + 1);
6282 b->number = breakpoint_count;
6284 b->cond_string = (cond_string == NULL) ?
6285 NULL : savestring (cond_string, strlen (cond_string));
6287 b->addr_string = NULL;
6288 b->enable = enabled;
6289 b->disposition = tempflag ? del : donttouch;
6292 case EX_EVENT_THROW:
6293 b->type = bp_catch_throw;
6295 case EX_EVENT_CATCH:
6296 b->type = bp_catch_catch;
6298 default: /* error condition */
6300 b->enable = disabled;
6301 error ("Internal error -- invalid catchpoint kind");
6306 /* Deal with "catch catch" and "catch throw" commands */
6309 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
6310 enum exception_event_kind ex_event;
6315 char *cond_string = NULL;
6316 struct symtab_and_line *sal = NULL;
6318 ep_skip_leading_whitespace (&arg);
6320 cond_string = ep_parse_optional_if_clause (&arg);
6322 if ((*arg != '\0') && !isspace (*arg))
6323 error ("Junk at end of arguments.");
6325 if ((ex_event != EX_EVENT_THROW) &&
6326 (ex_event != EX_EVENT_CATCH))
6327 error ("Unsupported or unknown exception event; cannot catch it");
6329 /* See if we can find a callback routine */
6330 sal = target_enable_exception_callback (ex_event, 1);
6334 /* We have callbacks from the runtime system for exceptions.
6335 Set a breakpoint on the sal found, if no errors */
6336 if (sal != (struct symtab_and_line *) -1)
6337 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6339 return; /* something went wrong with setting up callbacks */
6343 /* No callbacks from runtime system for exceptions.
6344 Try GNU C++ exception breakpoints using labels in debug info. */
6345 if (ex_event == EX_EVENT_CATCH)
6347 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6349 else if (ex_event == EX_EVENT_THROW)
6351 /* Set a breakpoint on __raise_exception () */
6353 warning ("Unsupported with this platform/compiler combination.");
6354 warning ("Perhaps you can achieve the effect you want by setting");
6355 warning ("a breakpoint on __raise_exception().");
6360 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6361 inside a catch_errors */
6364 cover_target_enable_exception_callback (arg)
6367 args_for_catchpoint_enable *args = arg;
6368 struct symtab_and_line *sal;
6369 sal = target_enable_exception_callback (args->kind, args->enable);
6372 else if (sal == (struct symtab_and_line *) -1)
6375 return 1; /*is valid */
6380 /* This is the original v.4.16 and earlier version of the
6381 catch_command_1() function. Now that other flavours of "catch"
6382 have been introduced, and since exception handling can be handled
6383 in other ways (through target ops) also, this is used only for the
6384 GNU C++ exception handling system.
6385 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6386 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6387 there was no code in GDB 4.16 for "catch throw".
6389 Called from catch_exception_command_1 () */
6393 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
6398 /* First, translate ARG into something we can deal with in terms
6401 struct symtabs_and_lines sals;
6402 struct symtab_and_line sal;
6403 register struct expression *cond = 0;
6404 register struct breakpoint *b;
6408 INIT_SAL (&sal); /* initialize to zeroes */
6410 /* If no arg given, or if first arg is 'if ', all active catch clauses
6411 are breakpointed. */
6413 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6414 && (arg[2] == ' ' || arg[2] == '\t')))
6416 /* Grab all active catch clauses. */
6417 sals = get_catch_sals (0);
6421 /* Grab selected catch clauses. */
6422 error ("catch NAME not implemented");
6425 /* Not sure why this code has been disabled. I'm leaving
6426 it disabled. We can never come here now anyway
6427 since we don't allow the "catch NAME" syntax.
6430 /* This isn't used; I don't know what it was for. */
6431 sals = map_catch_names (arg, catch_breakpoint);
6439 for (i = 0; i < sals.nelts; i++)
6441 resolve_sal_pc (&sals.sals[i]);
6445 if (arg[0] == 'i' && arg[1] == 'f'
6446 && (arg[2] == ' ' || arg[2] == '\t'))
6447 cond = parse_exp_1 ((arg += 2, &arg),
6448 block_for_pc (sals.sals[i].pc), 0);
6450 error ("Junk at end of arguments.");
6455 for (i = 0; i < sals.nelts; i++)
6460 describe_other_breakpoints (sal.pc, sal.section);
6462 b = set_raw_breakpoint (sal);
6463 set_breakpoint_count (breakpoint_count + 1);
6464 b->number = breakpoint_count;
6466 /* Important -- this is an ordinary breakpoint. For platforms
6467 with callback support for exceptions,
6468 create_exception_catchpoint() will create special bp types
6469 (bp_catch_catch and bp_catch_throw), and there is code in
6470 insert_breakpoints() and elsewhere that depends on that. */
6471 b->type = bp_breakpoint;
6474 b->enable = enabled;
6475 b->disposition = tempflag ? del : donttouch;
6482 warning ("Multiple breakpoints were set.");
6483 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6485 free ((PTR) sals.sals);
6489 /* This creates a temporary internal breakpoint
6490 just to placate infrun */
6491 static struct breakpoint *
6492 create_temp_exception_breakpoint (pc)
6495 struct symtab_and_line sal;
6496 struct breakpoint *b;
6503 b = set_raw_breakpoint (sal);
6505 error ("Internal error -- couldn't set temp exception breakpoint");
6507 b->type = bp_breakpoint;
6508 b->disposition = del;
6509 b->enable = enabled;
6511 b->number = internal_breakpoint_number--;
6517 catch_command_1 (arg, tempflag, from_tty)
6523 /* The first argument may be an event name, such as "start" or "load".
6524 If so, then handle it as such. If it doesn't match an event name,
6525 then attempt to interpret it as an exception name. (This latter is
6526 the v4.16-and-earlier GDB meaning of the "catch" command.)
6528 First, try to find the bounds of what might be an event name. */
6529 char *arg1_start = arg;
6533 if (arg1_start == NULL)
6535 /* Old behaviour was to use pre-v-4.16 syntax */
6536 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6538 /* Now, this is not allowed */
6539 error ("Catch requires an event name.");
6542 arg1_end = ep_find_event_name_end (arg1_start);
6543 if (arg1_end == NULL)
6544 error ("catch requires an event");
6545 arg1_length = arg1_end + 1 - arg1_start;
6547 /* Try to match what we found against known event names. */
6548 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6550 error ("Catch of signal not yet implemented");
6552 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6554 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6555 tempflag, from_tty);
6557 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6559 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6560 tempflag, from_tty);
6562 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6564 error ("Catch of thread_start not yet implemented");
6566 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6568 error ("Catch of thread_exit not yet implemented");
6570 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6572 error ("Catch of thread_join not yet implemented");
6574 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6576 error ("Catch of start not yet implemented");
6578 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6580 error ("Catch of exit not yet implemented");
6582 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6584 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6585 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6587 error ("Catch of fork not yet implemented");
6590 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6592 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6593 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6595 error ("Catch of vfork not yet implemented");
6598 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6600 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6601 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6603 error ("Catch of exec not yet implemented");
6606 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6608 #if defined(SOLIB_ADD)
6609 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6611 error ("Catch of load not implemented");
6614 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6616 #if defined(SOLIB_ADD)
6617 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6619 error ("Catch of load not implemented");
6622 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6624 error ("Catch of stop not yet implemented");
6627 /* This doesn't appear to be an event name */
6631 /* Pre-v.4.16 behaviour was to treat the argument
6632 as the name of an exception */
6633 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6634 /* Now this is not allowed */
6635 error ("Unknown event kind specified for catch");
6640 /* Used by the gui, could be made a worker for other things. */
6643 set_breakpoint_sal (sal)
6644 struct symtab_and_line sal;
6646 struct breakpoint *b;
6647 b = set_raw_breakpoint (sal);
6648 set_breakpoint_count (breakpoint_count + 1);
6649 b->number = breakpoint_count;
6650 b->type = bp_breakpoint;
6657 /* These aren't used; I don't know what they were for. */
6658 /* Disable breakpoints on all catch clauses described in ARGS. */
6660 disable_catch (args)
6663 /* Map the disable command to catch clauses described in ARGS. */
6666 /* Enable breakpoints on all catch clauses described in ARGS. */
6671 /* Map the disable command to catch clauses described in ARGS. */
6674 /* Delete breakpoints on all catch clauses in the active scope. */
6679 /* Map the delete command to catch clauses described in ARGS. */
6684 catch_command (arg, from_tty)
6688 catch_command_1 (arg, 0, from_tty);
6693 tcatch_command (arg, from_tty)
6697 catch_command_1 (arg, 1, from_tty);
6702 clear_command (arg, from_tty)
6706 register struct breakpoint *b, *b1;
6708 struct symtabs_and_lines sals;
6709 struct symtab_and_line sal;
6710 register struct breakpoint *found;
6715 sals = decode_line_spec (arg, 1);
6720 sals.sals = (struct symtab_and_line *)
6721 xmalloc (sizeof (struct symtab_and_line));
6722 INIT_SAL (&sal); /* initialize to zeroes */
6723 sal.line = default_breakpoint_line;
6724 sal.symtab = default_breakpoint_symtab;
6725 sal.pc = default_breakpoint_address;
6726 if (sal.symtab == 0)
6727 error ("No source file specified.");
6735 /* For each line spec given, delete bps which correspond
6736 to it. We do this in two loops: the first loop looks at
6737 the initial bp(s) in the chain which should be deleted,
6738 the second goes down the rest of the chain looking ahead
6739 one so it can take those bps off the chain without messing
6743 for (i = 0; i < sals.nelts; i++)
6745 /* If exact pc given, clear bpts at that pc.
6746 If line given (pc == 0), clear all bpts on specified line.
6747 If defaulting, clear all bpts on default line
6750 defaulting sal.pc != 0 tests to do
6755 1 0 <can't happen> */
6758 found = (struct breakpoint *) 0;
6761 while (breakpoint_chain
6762 /* Why don't we check here that this is not
6763 a watchpoint, etc., as we do below?
6764 I can't make it fail, but don't know
6765 what's stopping the failure: a watchpoint
6766 of the same address as "sal.pc" should
6767 wind up being deleted. */
6769 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6770 (overlay_debugging == 0 ||
6771 breakpoint_chain->section == sal.section))
6772 || ((default_match || (0 == sal.pc))
6773 && breakpoint_chain->source_file != NULL
6774 && sal.symtab != NULL
6775 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6776 && breakpoint_chain->line_number == sal.line)))
6779 b1 = breakpoint_chain;
6780 breakpoint_chain = b1->next;
6788 && b->next->type != bp_none
6789 && b->next->type != bp_watchpoint
6790 && b->next->type != bp_hardware_watchpoint
6791 && b->next->type != bp_read_watchpoint
6792 && b->next->type != bp_access_watchpoint
6793 && (((sal.pc && (b->next->address == sal.pc)) &&
6794 (overlay_debugging == 0 ||
6795 b->next->section == sal.section))
6796 || ((default_match || (0 == sal.pc))
6797 && b->next->source_file != NULL
6798 && sal.symtab != NULL
6799 && STREQ (b->next->source_file, sal.symtab->filename)
6800 && b->next->line_number == sal.line)))
6813 error ("No breakpoint at %s.", arg);
6815 error ("No breakpoint at this line.");
6819 from_tty = 1; /* Always report if deleted more than one */
6821 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6822 breakpoints_changed ();
6826 printf_unfiltered ("%d ", found->number);
6828 delete_breakpoint (found);
6832 putchar_unfiltered ('\n');
6834 free ((PTR) sals.sals);
6837 /* Delete breakpoint in BS if they are `delete' breakpoints and
6838 all breakpoints that are marked for deletion, whether hit or not.
6839 This is called after any breakpoint is hit, or after errors. */
6842 breakpoint_auto_delete (bs)
6845 struct breakpoint *b, *temp;
6847 for (; bs; bs = bs->next)
6848 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6850 delete_breakpoint (bs->breakpoint_at);
6852 ALL_BREAKPOINTS_SAFE (b, temp)
6854 if (b->disposition == del_at_next_stop)
6855 delete_breakpoint (b);
6859 /* Delete a breakpoint and clean up all traces of it in the data
6863 delete_breakpoint (bpt)
6864 struct breakpoint *bpt;
6866 register struct breakpoint *b;
6870 error ("Internal error (attempted to delete a NULL breakpoint)");
6873 /* Has this bp already been deleted? This can happen because multiple
6874 lists can hold pointers to bp's. bpstat lists are especial culprits.
6876 One example of this happening is a watchpoint's scope bp. When the
6877 scope bp triggers, we notice that the watchpoint is out of scope, and
6878 delete it. We also delete its scope bp. But the scope bp is marked
6879 "auto-deleting", and is already on a bpstat. That bpstat is then
6880 checked for auto-deleting bp's, which are deleted.
6882 A real solution to this problem might involve reference counts in bp's,
6883 and/or giving them pointers back to their referencing bpstat's, and
6884 teaching delete_breakpoint to only free a bp's storage when no more
6885 references were extent. A cheaper bandaid was chosen. */
6886 if (bpt->type == bp_none)
6889 if (delete_breakpoint_hook)
6890 delete_breakpoint_hook (bpt);
6891 breakpoint_delete_event (bpt->number);
6894 remove_breakpoint (bpt, mark_uninserted);
6896 if (breakpoint_chain == bpt)
6897 breakpoint_chain = bpt->next;
6899 /* If we have callback-style exception catchpoints, don't go through
6900 the adjustments to the C++ runtime library etc. if the inferior
6901 isn't actually running. target_enable_exception_callback for a
6902 null target ops vector gives an undesirable error message, so we
6903 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6904 exceptions are supported in this way, it's OK for now. FIXME */
6905 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6907 static char message1[] = "Error in deleting catchpoint %d:\n";
6908 static char message[sizeof (message1) + 30];
6909 args_for_catchpoint_enable args;
6911 /* Format possible error msg */
6912 sprintf (message, message1, bpt->number);
6913 args.kind = bpt->type == bp_catch_catch ?
6914 EX_EVENT_CATCH : EX_EVENT_THROW;
6916 catch_errors (cover_target_enable_exception_callback, &args,
6917 message, RETURN_MASK_ALL);
6924 b->next = bpt->next;
6928 /* Before turning off the visuals for the bp, check to see that
6929 there are no other bps at the same address. */
6936 clearIt = (b->address != bpt->address);
6943 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6944 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6948 check_duplicates (bpt->address, bpt->section);
6949 /* If this breakpoint was inserted, and there is another breakpoint
6950 at the same address, we need to insert the other breakpoint. */
6952 && bpt->type != bp_hardware_watchpoint
6953 && bpt->type != bp_read_watchpoint
6954 && bpt->type != bp_access_watchpoint
6955 && bpt->type != bp_catch_fork
6956 && bpt->type != bp_catch_vfork
6957 && bpt->type != bp_catch_exec)
6960 if (b->address == bpt->address
6961 && b->section == bpt->section
6963 && b->enable != disabled
6964 && b->enable != shlib_disabled
6965 && b->enable != call_disabled)
6969 /* We should never reach this point if there is a permanent
6970 breakpoint at the same address as the one being deleted.
6971 If there is a permanent breakpoint somewhere, it should
6972 always be the only one inserted. */
6973 if (b->enable == permanent)
6974 internal_error ("another breakpoint was inserted on top of "
6975 "a permanent breakpoint");
6977 if (b->type == bp_hardware_breakpoint)
6978 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6980 val = target_insert_breakpoint (b->address, b->shadow_contents);
6984 target_terminal_ours_for_output ();
6985 warning ("Cannot insert breakpoint %d:", b->number);
6986 memory_error (val, b->address); /* which bombs us out */
6993 free_command_lines (&bpt->commands);
6996 if (bpt->cond_string != NULL)
6997 free (bpt->cond_string);
6998 if (bpt->addr_string != NULL)
6999 free (bpt->addr_string);
7000 if (bpt->exp != NULL)
7002 if (bpt->exp_string != NULL)
7003 free (bpt->exp_string);
7004 if (bpt->val != NULL)
7005 value_free (bpt->val);
7006 if (bpt->source_file != NULL)
7007 free (bpt->source_file);
7008 if (bpt->dll_pathname != NULL)
7009 free (bpt->dll_pathname);
7010 if (bpt->triggered_dll_pathname != NULL)
7011 free (bpt->triggered_dll_pathname);
7012 if (bpt->exec_pathname != NULL)
7013 free (bpt->exec_pathname);
7015 /* Be sure no bpstat's are pointing at it after it's been freed. */
7016 /* FIXME, how can we find all bpstat's?
7017 We just check stop_bpstat for now. */
7018 for (bs = stop_bpstat; bs; bs = bs->next)
7019 if (bs->breakpoint_at == bpt)
7021 bs->breakpoint_at = NULL;
7023 /* we'd call bpstat_clear_actions, but that free's stuff and due
7024 to the multiple pointers pointing to one item with no
7025 reference counts found anywhere through out the bpstat's (how
7026 do you spell fragile?), we don't want to free things twice --
7027 better a memory leak than a corrupt malloc pool! */
7028 bs->commands = NULL;
7031 /* On the chance that someone will soon try again to delete this same
7032 bp, we mark it as deleted before freeing its storage. */
7033 bpt->type = bp_none;
7039 delete_command (arg, from_tty)
7043 struct breakpoint *b, *temp;
7047 int breaks_to_delete = 0;
7049 /* Delete all breakpoints if no argument.
7050 Do not delete internal or call-dummy breakpoints, these
7051 have to be deleted with an explicit breakpoint number argument. */
7054 if (b->type != bp_call_dummy &&
7055 b->type != bp_shlib_event &&
7056 b->type != bp_thread_event &&
7058 breaks_to_delete = 1;
7061 /* Ask user only if there are some breakpoints to delete. */
7063 || (breaks_to_delete && query ("Delete all breakpoints? ")))
7065 ALL_BREAKPOINTS_SAFE (b, temp)
7067 if (b->type != bp_call_dummy &&
7068 b->type != bp_shlib_event &&
7069 b->type != bp_thread_event &&
7071 delete_breakpoint (b);
7076 map_breakpoint_numbers (arg, delete_breakpoint);
7079 /* Reset a breakpoint given it's struct breakpoint * BINT.
7080 The value we return ends up being the return value from catch_errors.
7081 Unused in this case. */
7084 breakpoint_re_set_one (bint)
7087 /* get past catch_errs */
7088 struct breakpoint *b = (struct breakpoint *) bint;
7091 struct symtabs_and_lines sals;
7093 enum enable save_enable;
7098 warning ("attempted to reset apparently deleted breakpoint #%d?",
7102 case bp_hardware_breakpoint:
7104 case bp_catch_unload:
7105 if (b->addr_string == NULL)
7107 /* Anything without a string can't be re-set. */
7108 delete_breakpoint (b);
7111 /* In case we have a problem, disable this breakpoint. We'll restore
7112 its status if we succeed. */
7113 save_enable = b->enable;
7114 b->enable = disabled;
7116 set_language (b->language);
7117 input_radix = b->input_radix;
7119 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
7120 for (i = 0; i < sals.nelts; i++)
7122 resolve_sal_pc (&sals.sals[i]);
7124 /* Reparse conditions, they might contain references to the
7126 if (b->cond_string != NULL)
7130 free ((PTR) b->cond);
7131 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7134 /* We need to re-set the breakpoint if the address changes... */
7135 if (b->address != sals.sals[i].pc
7136 /* ...or new and old breakpoints both have source files, and
7137 the source file name or the line number changes... */
7138 || (b->source_file != NULL
7139 && sals.sals[i].symtab != NULL
7140 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
7141 || b->line_number != sals.sals[i].line)
7143 /* ...or we switch between having a source file and not having
7145 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7148 if (b->source_file != NULL)
7149 free (b->source_file);
7150 if (sals.sals[i].symtab == NULL)
7151 b->source_file = NULL;
7154 savestring (sals.sals[i].symtab->filename,
7155 strlen (sals.sals[i].symtab->filename));
7156 b->line_number = sals.sals[i].line;
7157 b->address = sals.sals[i].pc;
7159 /* Used to check for duplicates here, but that can
7160 cause trouble, as it doesn't check for disable
7165 /* Might be better to do this just once per breakpoint_re_set,
7166 rather than once for every breakpoint. */
7167 breakpoints_changed ();
7169 b->section = sals.sals[i].section;
7170 b->enable = save_enable; /* Restore it, this worked. */
7173 /* Now that this is re-enabled, check_duplicates
7175 check_duplicates (b->address, b->section);
7178 free ((PTR) sals.sals);
7182 case bp_hardware_watchpoint:
7183 case bp_read_watchpoint:
7184 case bp_access_watchpoint:
7185 innermost_block = NULL;
7186 /* The issue arises of what context to evaluate this in. The
7187 same one as when it was set, but what does that mean when
7188 symbols have been re-read? We could save the filename and
7189 functionname, but if the context is more local than that, the
7190 best we could do would be something like how many levels deep
7191 and which index at that particular level, but that's going to
7192 be less stable than filenames or function names. */
7194 /* So for now, just use a global context. */
7196 free ((PTR) b->exp);
7197 b->exp = parse_expression (b->exp_string);
7198 b->exp_valid_block = innermost_block;
7199 mark = value_mark ();
7201 value_free (b->val);
7202 b->val = evaluate_expression (b->exp);
7203 release_value (b->val);
7204 if (VALUE_LAZY (b->val))
7205 value_fetch_lazy (b->val);
7207 if (b->cond_string != NULL)
7211 free ((PTR) b->cond);
7212 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7214 if (b->enable == enabled)
7216 value_free_to_mark (mark);
7218 case bp_catch_catch:
7219 case bp_catch_throw:
7221 /* We needn't really do anything to reset these, since the mask
7222 that requests them is unaffected by e.g., new libraries being
7225 case bp_catch_vfork:
7230 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7232 /* Delete longjmp breakpoints, they will be reset later by
7233 breakpoint_re_set. */
7235 case bp_longjmp_resume:
7236 delete_breakpoint (b);
7239 /* This breakpoint is special, it's set up when the inferior
7240 starts and we really don't want to touch it. */
7241 case bp_shlib_event:
7243 /* Like bp_shlib_event, this breakpoint type is special.
7244 Once it is set up, we do not want to touch it. */
7245 case bp_thread_event:
7247 /* Keep temporary breakpoints, which can be encountered when we step
7248 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7249 Otherwise these should have been blown away via the cleanup chain
7250 or by breakpoint_init_inferior when we rerun the executable. */
7253 case bp_watchpoint_scope:
7255 case bp_step_resume:
7262 /* Re-set all breakpoints after symbols have been re-loaded. */
7264 breakpoint_re_set ()
7266 struct breakpoint *b, *temp;
7267 enum language save_language;
7268 int save_input_radix;
7269 static char message1[] = "Error in re-setting breakpoint %d:\n";
7270 char message[sizeof (message1) + 30 /* slop */ ];
7272 save_language = current_language->la_language;
7273 save_input_radix = input_radix;
7274 ALL_BREAKPOINTS_SAFE (b, temp)
7276 /* Format possible error msg */
7277 sprintf (message, message1, b->number);
7278 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7280 set_language (save_language);
7281 input_radix = save_input_radix;
7283 #ifdef GET_LONGJMP_TARGET
7284 create_longjmp_breakpoint ("longjmp");
7285 create_longjmp_breakpoint ("_longjmp");
7286 create_longjmp_breakpoint ("siglongjmp");
7287 create_longjmp_breakpoint ("_siglongjmp");
7288 create_longjmp_breakpoint (NULL);
7292 /* Took this out (temporarily at least), since it produces an extra
7293 blank line at startup. This messes up the gdbtests. -PB */
7294 /* Blank line to finish off all those mention() messages we just printed. */
7295 printf_filtered ("\n");
7299 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7300 If from_tty is nonzero, it prints a message to that effect,
7301 which ends with a period (no newline). */
7303 /* Reset the thread number of this breakpoint:
7305 - If the breakpoint is for all threads, leave it as-is.
7306 - Else, reset it to the current thread for inferior_pid. */
7308 breakpoint_re_set_thread (b)
7309 struct breakpoint *b;
7311 if (b->thread != -1)
7313 if (in_thread_list (inferior_pid))
7314 b->thread = pid_to_thread_id (inferior_pid);
7319 set_ignore_count (bptnum, count, from_tty)
7320 int bptnum, count, from_tty;
7322 register struct breakpoint *b;
7328 if (b->number == bptnum)
7330 b->ignore_count = count;
7333 else if (count == 0)
7334 printf_filtered ("Will stop next time breakpoint %d is reached.",
7336 else if (count == 1)
7337 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7340 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7342 breakpoints_changed ();
7346 error ("No breakpoint number %d.", bptnum);
7349 /* Clear the ignore counts of all breakpoints. */
7351 breakpoint_clear_ignore_counts ()
7353 struct breakpoint *b;
7356 b->ignore_count = 0;
7359 /* Command to set ignore-count of breakpoint N to COUNT. */
7362 ignore_command (args, from_tty)
7370 error_no_arg ("a breakpoint number");
7372 num = get_number (&p);
7374 error ("bad breakpoint number: '%s'", args);
7376 error ("Second argument (specified ignore-count) is missing.");
7378 set_ignore_count (num,
7379 longest_to_int (value_as_long (parse_and_eval (p))),
7381 printf_filtered ("\n");
7382 breakpoints_changed ();
7385 /* Call FUNCTION on each of the breakpoints
7386 whose numbers are given in ARGS. */
7389 map_breakpoint_numbers (args, function)
7391 void (*function) PARAMS ((struct breakpoint *));
7393 register char *p = args;
7396 register struct breakpoint *b, *tmp;
7400 error_no_arg ("one or more breakpoint numbers");
7407 num = get_number_or_range (&p1);
7410 warning ("bad breakpoint number at or near '%s'", p);
7414 ALL_BREAKPOINTS_SAFE (b, tmp)
7415 if (b->number == num)
7417 struct breakpoint *related_breakpoint = b->related_breakpoint;
7420 if (related_breakpoint)
7421 function (related_breakpoint);
7425 printf_unfiltered ("No breakpoint number %d.\n", num);
7432 disable_breakpoint (bpt)
7433 struct breakpoint *bpt;
7435 /* Never disable a watchpoint scope breakpoint; we want to
7436 hit them when we leave scope so we can delete both the
7437 watchpoint and its scope breakpoint at that time. */
7438 if (bpt->type == bp_watchpoint_scope)
7441 /* You can't disable permanent breakpoints. */
7442 if (bpt->enable == permanent)
7445 bpt->enable = disabled;
7447 check_duplicates (bpt->address, bpt->section);
7449 if (modify_breakpoint_hook)
7450 modify_breakpoint_hook (bpt);
7451 breakpoint_modify_event (bpt->number);
7456 disable_command (args, from_tty)
7460 register struct breakpoint *bpt;
7462 ALL_BREAKPOINTS (bpt)
7466 warning ("attempted to disable apparently deleted breakpoint #%d?",
7471 case bp_catch_unload:
7473 case bp_catch_vfork:
7475 case bp_catch_catch:
7476 case bp_catch_throw:
7477 case bp_hardware_breakpoint:
7479 case bp_hardware_watchpoint:
7480 case bp_read_watchpoint:
7481 case bp_access_watchpoint:
7482 disable_breakpoint (bpt);
7487 map_breakpoint_numbers (args, disable_breakpoint);
7491 do_enable_breakpoint (bpt, disposition)
7492 struct breakpoint *bpt;
7493 enum bpdisp disposition;
7495 struct frame_info *save_selected_frame = NULL;
7496 int save_selected_frame_level = -1;
7497 int target_resources_ok, other_type_used;
7500 if (bpt->type == bp_hardware_breakpoint)
7503 i = hw_breakpoint_used_count ();
7504 target_resources_ok =
7505 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7507 if (target_resources_ok == 0)
7508 error ("No hardware breakpoint support in the target.");
7509 else if (target_resources_ok < 0)
7510 error ("Hardware breakpoints used exceeds limit.");
7513 if (bpt->enable != permanent)
7514 bpt->enable = enabled;
7515 bpt->disposition = disposition;
7516 check_duplicates (bpt->address, bpt->section);
7517 breakpoints_changed ();
7519 if (bpt->type == bp_watchpoint ||
7520 bpt->type == bp_hardware_watchpoint ||
7521 bpt->type == bp_read_watchpoint ||
7522 bpt->type == bp_access_watchpoint)
7524 if (bpt->exp_valid_block != NULL)
7526 struct frame_info *fr =
7528 /* Ensure that we have the current frame. Else, this
7529 next query may pessimistically be answered as, "No,
7530 not within current scope". */
7531 get_current_frame ();
7532 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7536 Cannot enable watchpoint %d because the block in which its expression\n\
7537 is valid is not currently in scope.\n", bpt->number);
7538 bpt->enable = disabled;
7542 save_selected_frame = selected_frame;
7543 save_selected_frame_level = selected_frame_level;
7544 select_frame (fr, -1);
7547 value_free (bpt->val);
7548 mark = value_mark ();
7549 bpt->val = evaluate_expression (bpt->exp);
7550 release_value (bpt->val);
7551 if (VALUE_LAZY (bpt->val))
7552 value_fetch_lazy (bpt->val);
7554 if (bpt->type == bp_hardware_watchpoint ||
7555 bpt->type == bp_read_watchpoint ||
7556 bpt->type == bp_access_watchpoint)
7558 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7559 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7561 /* Hack around 'unused var' error for some targets here */
7563 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7564 bpt->type, i + mem_cnt, other_type_used);
7565 /* we can consider of type is bp_hardware_watchpoint, convert to
7566 bp_watchpoint in the following condition */
7567 if (target_resources_ok < 0)
7570 Cannot enable watchpoint %d because target watch resources\n\
7571 have been allocated for other watchpoints.\n", bpt->number);
7572 bpt->enable = disabled;
7573 value_free_to_mark (mark);
7578 if (save_selected_frame_level >= 0)
7579 select_and_print_frame (save_selected_frame,
7580 save_selected_frame_level);
7581 value_free_to_mark (mark);
7583 if (modify_breakpoint_hook)
7584 modify_breakpoint_hook (bpt);
7585 breakpoint_modify_event (bpt->number);
7589 enable_breakpoint (bpt)
7590 struct breakpoint *bpt;
7592 do_enable_breakpoint (bpt, bpt->disposition);
7595 /* The enable command enables the specified breakpoints (or all defined
7596 breakpoints) so they once again become (or continue to be) effective
7597 in stopping the inferior. */
7601 enable_command (args, from_tty)
7605 register struct breakpoint *bpt;
7607 ALL_BREAKPOINTS (bpt)
7611 warning ("attempted to enable apparently deleted breakpoint #%d?",
7616 case bp_catch_unload:
7618 case bp_catch_vfork:
7620 case bp_catch_catch:
7621 case bp_catch_throw:
7622 case bp_hardware_breakpoint:
7624 case bp_hardware_watchpoint:
7625 case bp_read_watchpoint:
7626 case bp_access_watchpoint:
7627 enable_breakpoint (bpt);
7632 map_breakpoint_numbers (args, enable_breakpoint);
7636 enable_once_breakpoint (bpt)
7637 struct breakpoint *bpt;
7639 do_enable_breakpoint (bpt, disable);
7644 enable_once_command (args, from_tty)
7648 map_breakpoint_numbers (args, enable_once_breakpoint);
7652 enable_delete_breakpoint (bpt)
7653 struct breakpoint *bpt;
7655 do_enable_breakpoint (bpt, del);
7660 enable_delete_command (args, from_tty)
7664 map_breakpoint_numbers (args, enable_delete_breakpoint);
7667 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7669 struct symtabs_and_lines
7670 decode_line_spec_1 (string, funfirstline)
7674 struct symtabs_and_lines sals;
7676 error ("Empty line specification.");
7677 if (default_breakpoint_valid)
7678 sals = decode_line_1 (&string, funfirstline,
7679 default_breakpoint_symtab,
7680 default_breakpoint_line,
7683 sals = decode_line_1 (&string, funfirstline,
7684 (struct symtab *) NULL, 0, (char ***) NULL);
7686 error ("Junk at end of line specification: %s", string);
7691 _initialize_breakpoint ()
7693 struct cmd_list_element *c;
7695 breakpoint_chain = 0;
7696 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7697 before a breakpoint is set. */
7698 breakpoint_count = 0;
7700 add_com ("ignore", class_breakpoint, ignore_command,
7701 "Set ignore-count of breakpoint number N to COUNT.\n\
7702 Usage is `ignore N COUNT'.");
7704 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7706 add_com ("commands", class_breakpoint, commands_command,
7707 "Set commands to be executed when a breakpoint is hit.\n\
7708 Give breakpoint number as argument after \"commands\".\n\
7709 With no argument, the targeted breakpoint is the last one set.\n\
7710 The commands themselves follow starting on the next line.\n\
7711 Type a line containing \"end\" to indicate the end of them.\n\
7712 Give \"silent\" as the first line to make the breakpoint silent;\n\
7713 then no output is printed when it is hit, except what the commands print.");
7715 add_com ("condition", class_breakpoint, condition_command,
7716 "Specify breakpoint number N to break only if COND is true.\n\
7717 Usage is `condition N COND', where N is an integer and COND is an\n\
7718 expression to be evaluated whenever breakpoint N is reached. ");
7720 add_com ("tbreak", class_breakpoint, tbreak_command,
7721 "Set a temporary breakpoint. Args like \"break\" command.\n\
7722 Like \"break\" except the breakpoint is only temporary,\n\
7723 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7724 by using \"enable delete\" on the breakpoint number.");
7725 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7726 "Set temporary breakpoint at procedure exit. Either there should\n\
7727 be no argument or the argument must be a depth.\n");
7729 add_com ("hbreak", class_breakpoint, hbreak_command,
7730 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7731 Like \"break\" except the breakpoint requires hardware support,\n\
7732 some target hardware may not have this support.");
7734 add_com ("thbreak", class_breakpoint, thbreak_command,
7735 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7736 Like \"hbreak\" except the breakpoint is only temporary,\n\
7737 so it will be deleted when hit.");
7739 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7740 "Enable some breakpoints.\n\
7741 Give breakpoint numbers (separated by spaces) as arguments.\n\
7742 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7743 This is used to cancel the effect of the \"disable\" command.\n\
7744 With a subcommand you can enable temporarily.",
7745 &enablelist, "enable ", 1, &cmdlist);
7747 add_com ("ab", class_breakpoint, enable_command,
7748 "Enable some breakpoints.\n\
7749 Give breakpoint numbers (separated by spaces) as arguments.\n\
7750 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7751 This is used to cancel the effect of the \"disable\" command.\n\
7752 With a subcommand you can enable temporarily.");
7754 add_com_alias ("en", "enable", class_breakpoint, 1);
7756 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7757 "Enable some breakpoints.\n\
7758 Give breakpoint numbers (separated by spaces) as arguments.\n\
7759 This is used to cancel the effect of the \"disable\" command.\n\
7760 May be abbreviated to simply \"enable\".\n",
7761 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7763 add_cmd ("once", no_class, enable_once_command,
7764 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7765 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7768 add_cmd ("delete", no_class, enable_delete_command,
7769 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7770 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7773 add_cmd ("delete", no_class, enable_delete_command,
7774 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7775 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7778 add_cmd ("once", no_class, enable_once_command,
7779 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7780 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7783 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7784 "Disable some breakpoints.\n\
7785 Arguments are breakpoint numbers with spaces in between.\n\
7786 To disable all breakpoints, give no argument.\n\
7787 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7788 &disablelist, "disable ", 1, &cmdlist);
7789 add_com_alias ("dis", "disable", class_breakpoint, 1);
7790 add_com_alias ("disa", "disable", class_breakpoint, 1);
7792 add_com ("sb", class_breakpoint, disable_command,
7793 "Disable some breakpoints.\n\
7794 Arguments are breakpoint numbers with spaces in between.\n\
7795 To disable all breakpoints, give no argument.\n\
7796 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7798 add_cmd ("breakpoints", class_alias, disable_command,
7799 "Disable some breakpoints.\n\
7800 Arguments are breakpoint numbers with spaces in between.\n\
7801 To disable all breakpoints, give no argument.\n\
7802 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7803 This command may be abbreviated \"disable\".",
7806 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7807 "Delete some breakpoints or auto-display expressions.\n\
7808 Arguments are breakpoint numbers with spaces in between.\n\
7809 To delete all breakpoints, give no argument.\n\
7811 Also a prefix command for deletion of other GDB objects.\n\
7812 The \"unset\" command is also an alias for \"delete\".",
7813 &deletelist, "delete ", 1, &cmdlist);
7814 add_com_alias ("d", "delete", class_breakpoint, 1);
7816 add_com ("db", class_breakpoint, delete_command,
7817 "Delete some breakpoints.\n\
7818 Arguments are breakpoint numbers with spaces in between.\n\
7819 To delete all breakpoints, give no argument.\n");
7821 add_cmd ("breakpoints", class_alias, delete_command,
7822 "Delete some breakpoints or auto-display expressions.\n\
7823 Arguments are breakpoint numbers with spaces in between.\n\
7824 To delete all breakpoints, give no argument.\n\
7825 This command may be abbreviated \"delete\".",
7828 add_com ("clear", class_breakpoint, clear_command,
7829 concat ("Clear breakpoint at specified line or function.\n\
7830 Argument may be line number, function name, or \"*\" and an address.\n\
7831 If line number is specified, all breakpoints in that line are cleared.\n\
7832 If function is specified, breakpoints at beginning of function are cleared.\n\
7833 If an address is specified, breakpoints at that address are cleared.\n\n",
7834 "With no argument, clears all breakpoints in the line that the selected frame\n\
7837 See also the \"delete\" command which clears breakpoints by number.", NULL));
7839 add_com ("break", class_breakpoint, break_command,
7840 concat ("Set 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, break at start of code for that line.\n\
7843 If function is specified, break at start of code for that function.\n\
7844 If an address is specified, break at that exact address.\n",
7845 "With no arg, uses current execution address of selected stack frame.\n\
7846 This is useful for breaking on return to a stack frame.\n\
7848 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7850 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7851 add_com_alias ("b", "break", class_run, 1);
7852 add_com_alias ("br", "break", class_run, 1);
7853 add_com_alias ("bre", "break", class_run, 1);
7854 add_com_alias ("brea", "break", class_run, 1);
7856 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7857 concat ("Set breakpoint at procedure exit. \n\
7858 Argument may be function name, or \"*\" and an address.\n\
7859 If function is specified, break at end of code for that function.\n\
7860 If an address is specified, break at the end of the function that contains \n\
7861 that exact address.\n",
7862 "With no arg, uses current execution address of selected stack frame.\n\
7863 This is useful for breaking on return to a stack frame.\n\
7865 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7867 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7868 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7869 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7870 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7871 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7875 add_com_alias ("ba", "break", class_breakpoint, 1);
7876 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7877 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7878 "Set breakpoint at procedure exit. Either there should\n\
7879 be no argument or the argument must be a depth.\n");
7884 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7885 "Break in function/address or break at a line in the current file.",
7886 &stoplist, "stop ", 1, &cmdlist);
7887 add_cmd ("in", class_breakpoint, stopin_command,
7888 "Break in function or address.\n", &stoplist);
7889 add_cmd ("at", class_breakpoint, stopat_command,
7890 "Break at a line in the current file.\n", &stoplist);
7891 add_com ("status", class_info, breakpoints_info,
7892 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7893 The \"Type\" column indicates one of:\n\
7894 \tbreakpoint - normal breakpoint\n\
7895 \twatchpoint - watchpoint\n\
7896 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7897 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7898 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7899 address and file/line number respectively.\n\n",
7900 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7901 are set to the address of the last breakpoint listed.\n\n\
7902 Convenience variable \"$bpnum\" contains the number of the last\n\
7903 breakpoint set.", NULL));
7906 add_info ("breakpoints", breakpoints_info,
7907 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7908 The \"Type\" column indicates one of:\n\
7909 \tbreakpoint - normal breakpoint\n\
7910 \twatchpoint - watchpoint\n\
7911 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7912 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7913 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7914 address and file/line number respectively.\n\n",
7915 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7916 are set to the address of the last breakpoint listed.\n\n\
7917 Convenience variable \"$bpnum\" contains the number of the last\n\
7918 breakpoint set.", NULL));
7921 add_com ("lb", class_breakpoint, breakpoints_info,
7922 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7923 The \"Type\" column indicates one of:\n\
7924 \tbreakpoint - normal breakpoint\n\
7925 \twatchpoint - watchpoint\n\
7926 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7927 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7928 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7929 address and file/line number respectively.\n\n",
7930 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7931 are set to the address of the last breakpoint listed.\n\n\
7932 Convenience variable \"$bpnum\" contains the number of the last\n\
7933 breakpoint set.", NULL));
7935 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7936 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7937 The \"Type\" column indicates one of:\n\
7938 \tbreakpoint - normal breakpoint\n\
7939 \twatchpoint - watchpoint\n\
7940 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7941 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7942 \tuntil - internal breakpoint used by the \"until\" command\n\
7943 \tfinish - internal breakpoint used by the \"finish\" command\n",
7944 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7945 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7946 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7947 address and file/line number respectively.\n\n",
7948 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7949 are set to the address of the last breakpoint listed.\n\n\
7950 Convenience variable \"$bpnum\" contains the number of the last\n\
7951 breakpoint set.", NULL),
7952 &maintenanceinfolist);
7954 add_com ("catch", class_breakpoint, catch_command,
7955 "Set catchpoints to catch events.\n\
7956 Raised signals may be caught:\n\
7957 \tcatch signal - all signals\n\
7958 \tcatch signal <signame> - a particular signal\n\
7959 Raised exceptions may be caught:\n\
7960 \tcatch throw - all exceptions, when thrown\n\
7961 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7962 \tcatch catch - all exceptions, when caught\n\
7963 \tcatch catch <exceptname> - a particular exception, when caught\n\
7964 Thread or process events may be caught:\n\
7965 \tcatch thread_start - any threads, just after creation\n\
7966 \tcatch thread_exit - any threads, just before expiration\n\
7967 \tcatch thread_join - any threads, just after joins\n\
7968 Process events may be caught:\n\
7969 \tcatch start - any processes, just after creation\n\
7970 \tcatch exit - any processes, just before expiration\n\
7971 \tcatch fork - calls to fork()\n\
7972 \tcatch vfork - calls to vfork()\n\
7973 \tcatch exec - calls to exec()\n\
7974 Dynamically-linked library events may be caught:\n\
7975 \tcatch load - loads of any library\n\
7976 \tcatch load <libname> - loads of a particular library\n\
7977 \tcatch unload - unloads of any library\n\
7978 \tcatch unload <libname> - unloads of a particular library\n\
7979 The act of your program's execution stopping may also be caught:\n\
7981 C++ exceptions may be caught:\n\
7982 \tcatch throw - all exceptions, when thrown\n\
7983 \tcatch catch - all exceptions, when caught\n\
7985 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7986 after a fork or vfork is caught.\n\n\
7987 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7989 add_com ("tcatch", class_breakpoint, tcatch_command,
7990 "Set temporary catchpoints to catch events.\n\
7991 Args like \"catch\" command.\n\
7992 Like \"catch\" except the catchpoint is only temporary,\n\
7993 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7994 by using \"enable delete\" on the catchpoint number.");
7996 add_com ("watch", class_breakpoint, watch_command,
7997 "Set a watchpoint for an expression.\n\
7998 A watchpoint stops execution of your program whenever the value of\n\
7999 an expression changes.");
8001 add_com ("rwatch", class_breakpoint, rwatch_command,
8002 "Set a read watchpoint for an expression.\n\
8003 A watchpoint stops execution of your program whenever the value of\n\
8004 an expression is read.");
8006 add_com ("awatch", class_breakpoint, awatch_command,
8007 "Set a watchpoint for an expression.\n\
8008 A watchpoint stops execution of your program whenever the value of\n\
8009 an expression is either read or written.");
8011 add_info ("watchpoints", breakpoints_info,
8012 "Synonym for ``info breakpoints''.");
8015 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
8016 (char *) &can_use_hw_watchpoints,
8017 "Set debugger's willingness to use watchpoint hardware.\n\
8018 If zero, gdb will not use hardware for new watchpoints, even if\n\
8019 such is available. (However, any hardware watchpoints that were\n\
8020 created before setting this to nonzero, will continue to use watchpoint\n\
8023 add_show_from_set (c, &showlist);
8025 can_use_hw_watchpoints = 1;