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);
52 static void catch_command_1 (char *, int, int);
54 static void enable_delete_command (char *, int);
56 static void enable_delete_breakpoint (struct breakpoint *);
58 static void enable_once_command (char *, int);
60 static void enable_once_breakpoint (struct breakpoint *);
62 static void disable_command (char *, int);
64 static void enable_command (char *, int);
66 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
68 static void ignore_command (char *, int);
70 static int breakpoint_re_set_one (PTR);
72 static void clear_command (char *, int);
74 static void catch_command (char *, int);
76 static void handle_gnu_4_16_catch_command (char *, int, int);
78 static struct symtabs_and_lines get_catch_sals (int);
80 static void watch_command (char *, int);
82 static int can_use_hardware_watchpoint (struct value *);
84 static void break_at_finish_command (char *, int);
85 static void break_at_finish_at_depth_command (char *, int);
87 void tbreak_command (char *, int);
89 static void tbreak_at_finish_command (char *, int);
91 static void break_command_1 (char *, int, int);
93 static void mention (struct breakpoint *);
95 struct breakpoint *set_raw_breakpoint (struct symtab_and_line);
97 static void check_duplicates (CORE_ADDR, asection *);
99 static void describe_other_breakpoints (CORE_ADDR, asection *);
101 static void breakpoints_info (char *, int);
103 static void breakpoint_1 (int, int);
105 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
107 static int breakpoint_cond_eval (PTR);
109 static void cleanup_executing_breakpoints (PTR);
111 static void commands_command (char *, int);
113 static void condition_command (char *, int);
115 static int get_number_trailer (char **, int);
117 void set_breakpoint_count (int);
120 static struct breakpoint *create_temp_exception_breakpoint (CORE_ADDR);
130 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
132 static enum print_stop_action print_it_typical (bpstat);
134 static enum print_stop_action print_bp_stop_message (bpstat bs);
138 enum exception_event_kind kind;
141 args_for_catchpoint_enable;
143 static int watchpoint_check (PTR);
145 static int cover_target_enable_exception_callback (PTR);
147 static void maintenance_info_breakpoints (char *, int);
149 #ifdef GET_LONGJMP_TARGET
150 static void create_longjmp_breakpoint (char *);
153 static int hw_breakpoint_used_count (void);
155 static int hw_watchpoint_used_count (enum bptype, int *);
157 static void hbreak_command (char *, int);
159 static void thbreak_command (char *, int);
161 static void watch_command_1 (char *, int, int);
163 static void rwatch_command (char *, int);
165 static void awatch_command (char *, int);
167 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
169 static void solib_load_unload_1 (char *hookname,
172 char *cond_string, enum bptype bp_kind);
174 static void create_fork_vfork_event_catchpoint (int tempflag,
176 enum bptype bp_kind);
178 static void break_at_finish_at_depth_command_1 (char *arg,
179 int flag, int from_tty);
181 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
183 static void stop_command (char *arg, int from_tty);
185 static void stopin_command (char *arg, int from_tty);
187 static void stopat_command (char *arg, int from_tty);
189 static char *ep_find_event_name_end (char *arg);
191 static char *ep_parse_optional_if_clause (char **arg);
193 static char *ep_parse_optional_filename (char **arg);
195 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
196 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
199 static void create_exception_catchpoint
200 (int tempflag, char *cond_string,
201 enum exception_event_kind ex_event, struct symtab_and_line *sal);
203 static void catch_exception_command_1
204 (enum exception_event_kind ex_event, char *arg, int tempflag, int from_tty);
206 static void tcatch_command (char *arg, int from_tty);
208 static void ep_skip_leading_whitespace (char **s);
210 /* Prototypes for exported functions. */
212 static void awatch_command (char *, int);
214 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
216 /* If FALSE, gdb will not use hardware support for watchpoints, even
217 if such is available. */
218 static int can_use_hw_watchpoints;
220 void _initialize_breakpoint (void);
222 void set_breakpoint_count (int);
224 extern int addressprint; /* Print machine addresses? */
226 static int internal_breakpoint_number = -1;
228 /* Are we executing breakpoint commands? */
229 static int executing_breakpoint_commands;
231 /* Walk the following statement or block through all breakpoints.
232 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
235 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
237 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
238 for (B = breakpoint_chain; \
239 B ? (TMP=B->next, 1): 0; \
242 /* True if SHIFT_INST_REGS defined, false otherwise. */
244 int must_shift_inst_regs =
245 #if defined(SHIFT_INST_REGS)
252 /* True if breakpoint hit counts should be displayed in breakpoint info. */
254 int show_breakpoint_hit_counts = 1;
256 /* Chain of all breakpoints defined. */
258 struct breakpoint *breakpoint_chain;
260 /* Number of last breakpoint made. */
262 int breakpoint_count;
264 /* Pointer to current exception event record */
265 static struct exception_event_record *current_exception_event;
267 /* Indicator of whether exception catchpoints should be nuked
268 between runs of a program */
269 int exception_catchpoints_are_fragile = 0;
271 /* Indicator of when exception catchpoints set-up should be
272 reinitialized -- e.g. when program is re-run */
273 int exception_support_initialized = 0;
275 /* This function returns a pointer to the string representation of the
276 pathname of the dynamically-linked library that has just been
279 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
280 or undefined results are guaranteed.
282 This string's contents are only valid immediately after the
283 inferior has stopped in the dynamic linker hook, and becomes
284 invalid as soon as the inferior is continued. Clients should make
285 a copy of this string if they wish to continue the inferior and
286 then access the string. */
288 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
289 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
292 /* This function returns a pointer to the string representation of the
293 pathname of the dynamically-linked library that has just been
296 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
297 TRUE, or undefined results are guaranteed.
299 This string's contents are only valid immediately after the
300 inferior has stopped in the dynamic linker hook, and becomes
301 invalid as soon as the inferior is continued. Clients should make
302 a copy of this string if they wish to continue the inferior and
303 then access the string. */
305 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
306 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
309 /* This function is called by the "catch load" command. It allows the
310 debugger to be notified by the dynamic linker when a specified
311 library file (or any library file, if filename is NULL) is loaded. */
313 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
314 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
315 error ("catch of library loads not yet implemented on this platform")
318 /* This function is called by the "catch unload" command. It allows
319 the debugger to be notified by the dynamic linker when a specified
320 library file (or any library file, if filename is NULL) is
323 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
324 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
325 error ("catch of library unloads not yet implemented on this platform")
328 /* Set breakpoint count to NUM. */
331 set_breakpoint_count (num)
334 breakpoint_count = num;
335 set_internalvar (lookup_internalvar ("bpnum"),
336 value_from_longest (builtin_type_int, (LONGEST) num));
339 /* Used in run_command to zero the hit count when a new run starts. */
342 clear_breakpoint_hit_counts ()
344 struct breakpoint *b;
350 /* Default address, symtab and line to put a breakpoint at
351 for "break" command with no arg.
352 if default_breakpoint_valid is zero, the other three are
353 not valid, and "break" with no arg is an error.
355 This set by print_stack_frame, which calls set_default_breakpoint. */
357 int default_breakpoint_valid;
358 CORE_ADDR default_breakpoint_address;
359 struct symtab *default_breakpoint_symtab;
360 int default_breakpoint_line;
362 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
363 Advance *PP after the string and any trailing whitespace.
365 Currently the string can either be a number or "$" followed by the name
366 of a convenience variable. Making it an expression wouldn't work well
367 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
369 TRAILER is a character which can be found after the number; most
370 commonly this is `-'. If you don't want a trailer, use \0. */
372 get_number_trailer (pp, trailer)
376 int retval = 0; /* default */
380 /* Empty line means refer to the last breakpoint. */
381 return breakpoint_count;
384 /* Make a copy of the name, so we can null-terminate it
385 to pass to lookup_internalvar(). */
390 while (isalnum (*p) || *p == '_')
392 varname = (char *) alloca (p - start + 1);
393 strncpy (varname, start, p - start);
394 varname[p - start] = '\0';
395 val = value_of_internalvar (lookup_internalvar (varname));
396 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
397 retval = (int) value_as_long (val);
400 printf_filtered ("Convenience variable must have integer value.\n");
408 while (*p >= '0' && *p <= '9')
411 /* There is no number here. (e.g. "cond a == b"). */
413 /* Skip non-numeric token */
414 while (*p && !isspace((int) *p))
416 /* Return zero, which caller must interpret as error. */
422 if (!(isspace (*p) || *p == '\0' || *p == trailer))
424 /* Trailing junk: return 0 and let caller print error msg. */
425 while (!(isspace (*p) || *p == '\0' || *p == trailer))
436 /* Like get_number_trailer, but don't allow a trailer. */
441 return get_number_trailer (pp, '\0');
444 /* Parse a number or a range.
445 * A number will be of the form handled by get_number.
446 * A range will be of the form <number1> - <number2>, and
447 * will represent all the integers between number1 and number2,
450 * While processing a range, this fuction is called iteratively;
451 * At each call it will return the next value in the range.
453 * At the beginning of parsing a range, the char pointer PP will
454 * be advanced past <number1> and left pointing at the '-' token.
455 * Subsequent calls will not advance the pointer until the range
456 * is completed. The call that completes the range will advance
457 * pointer PP past <number2>.
461 get_number_or_range (pp)
464 static int last_retval, end_value;
465 static char *end_ptr;
466 static int in_range = 0;
470 /* Default case: pp is pointing either to a solo number,
471 or to the first number of a range. */
472 last_retval = get_number_trailer (pp, '-');
477 /* This is the start of a range (<number1> - <number2>).
478 Skip the '-', parse and remember the second number,
479 and also remember the end of the final token. */
483 while (isspace ((int) *end_ptr))
484 end_ptr++; /* skip white space */
485 end_value = get_number (temp);
486 if (end_value < last_retval)
488 error ("inverted range");
490 else if (end_value == last_retval)
492 /* degenerate range (number1 == number2). Advance the
493 token pointer so that the range will be treated as a
502 error ("negative value");
505 /* pp points to the '-' that betokens a range. All
506 number-parsing has already been done. Return the next
507 integer value (one greater than the saved previous value).
508 Do not advance the token pointer 'pp' until the end of range
511 if (++last_retval == end_value)
513 /* End of range reached; advance token pointer. */
523 /* condition N EXP -- set break condition of breakpoint N to EXP. */
526 condition_command (arg, from_tty)
530 register struct breakpoint *b;
535 error_no_arg ("breakpoint number");
538 bnum = get_number (&p);
540 error ("Bad breakpoint argument: '%s'", arg);
543 if (b->number == bnum)
547 free ((PTR) b->cond);
550 if (b->cond_string != NULL)
551 free ((PTR) b->cond_string);
556 b->cond_string = NULL;
558 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
563 /* I don't know if it matters whether this is the string the user
564 typed in or the decompiled expression. */
565 b->cond_string = savestring (arg, strlen (arg));
566 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
568 error ("Junk at end of expression");
570 breakpoints_changed ();
574 error ("No breakpoint number %d.", bnum);
579 commands_command (arg, from_tty)
583 register struct breakpoint *b;
586 struct command_line *l;
588 /* If we allowed this, we would have problems with when to
589 free the storage, if we change the commands currently
592 if (executing_breakpoint_commands)
593 error ("Can't use the \"commands\" command among a breakpoint's commands.");
596 bnum = get_number (&p);
599 error ("Unexpected extra arguments following breakpoint number.");
602 if (b->number == bnum)
606 "Type commands for when breakpoint %d is hit, one per line.",
608 l = read_command_lines (tmpbuf, from_tty);
609 free_command_lines (&b->commands);
611 breakpoints_changed ();
614 error ("No breakpoint number %d.", bnum);
617 /* Like target_read_memory() but if breakpoints are inserted, return
618 the shadow contents instead of the breakpoints themselves.
620 Read "memory data" from whatever target or inferior we have.
621 Returns zero if successful, errno value if not. EIO is used
622 for address out of bounds. If breakpoints are inserted, returns
623 shadow contents, not the breakpoints themselves. From breakpoint.c. */
626 read_memory_nobpt (memaddr, myaddr, len)
632 struct breakpoint *b;
633 CORE_ADDR bp_addr = 0;
636 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
637 /* No breakpoints on this machine. */
638 return target_read_memory (memaddr, myaddr, len);
642 if (b->type == bp_none)
643 warning ("reading through apparently deleted breakpoint #%d?",
646 /* memory breakpoint? */
647 if (b->type == bp_watchpoint
648 || b->type == bp_hardware_watchpoint
649 || b->type == bp_read_watchpoint
650 || b->type == bp_access_watchpoint)
655 /* Addresses and length of the part of the breakpoint that
657 /* XXXX The m68k, sh and h8300 have different local and remote
658 breakpoint values. BREAKPOINT_FROM_PC still manages to
659 correctly determine the breakpoints memory address and size
660 for these targets. */
661 bp_addr = b->address;
663 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
668 if (bp_addr + bp_size <= memaddr)
669 /* The breakpoint is entirely before the chunk of memory we
672 if (bp_addr >= memaddr + len)
673 /* The breakpoint is entirely after the chunk of memory we are
676 /* Copy the breakpoint from the shadow contents, and recurse for
677 the things before and after. */
679 /* Offset within shadow_contents. */
682 if (bp_addr < memaddr)
684 /* Only copy the second part of the breakpoint. */
685 bp_size -= memaddr - bp_addr;
686 bptoffset = memaddr - bp_addr;
690 if (bp_addr + bp_size > memaddr + len)
692 /* Only copy the first part of the breakpoint. */
693 bp_size -= (bp_addr + bp_size) - (memaddr + len);
696 memcpy (myaddr + bp_addr - memaddr,
697 b->shadow_contents + bptoffset, bp_size);
699 if (bp_addr > memaddr)
701 /* Copy the section of memory before the breakpoint. */
702 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
707 if (bp_addr + bp_size < memaddr + len)
709 /* Copy the section of memory after the breakpoint. */
710 status = read_memory_nobpt
712 myaddr + bp_addr + bp_size - memaddr,
713 memaddr + len - (bp_addr + bp_size));
720 /* Nothing overlaps. Just call read_memory_noerr. */
721 return target_read_memory (memaddr, myaddr, len);
725 /* insert_breakpoints is used when starting or continuing the program.
726 remove_breakpoints is used when the program stops.
727 Both return zero if successful,
728 or an `errno' value if could not write the inferior. */
731 insert_breakpoints ()
733 register struct breakpoint *b, *temp;
734 int return_val = 0; /* return success code. */
736 int disabled_breaks = 0;
738 static char message1[] = "Error inserting catchpoint %d:\n";
739 static char message[sizeof (message1) + 30];
742 ALL_BREAKPOINTS_SAFE (b, temp)
744 if (b->enable == permanent)
745 /* Permanent breakpoints cannot be inserted or removed. */
747 else if (b->type != bp_watchpoint
748 && b->type != bp_hardware_watchpoint
749 && b->type != bp_read_watchpoint
750 && b->type != bp_access_watchpoint
751 && b->type != bp_catch_fork
752 && b->type != bp_catch_vfork
753 && b->type != bp_catch_exec
754 && b->type != bp_catch_throw
755 && b->type != bp_catch_catch
756 && b->enable != disabled
757 && b->enable != shlib_disabled
758 && b->enable != call_disabled
762 if (b->type == bp_hardware_breakpoint)
763 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
766 /* Check to see if breakpoint is in an overlay section;
767 if so, we should set the breakpoint at the LMA address.
768 Only if the section is currently mapped should we ALSO
769 set a break at the VMA address. */
770 if (overlay_debugging && b->section &&
771 section_is_overlay (b->section))
775 addr = overlay_unmapped_address (b->address, b->section);
776 val = target_insert_breakpoint (addr, b->shadow_contents);
777 /* This would be the time to check val, to see if the
778 breakpoint write to the load address succeeded.
779 However, this might be an ordinary occurrance, eg. if
780 the unmapped overlay is in ROM. */
781 val = 0; /* in case unmapped address failed */
782 if (section_is_mapped (b->section))
783 val = target_insert_breakpoint (b->address,
786 else /* ordinary (non-overlay) address */
787 val = target_insert_breakpoint (b->address, b->shadow_contents);
791 /* Can't set the breakpoint. */
792 #if defined (DISABLE_UNSETTABLE_BREAK)
793 if (DISABLE_UNSETTABLE_BREAK (b->address))
795 /* See also: disable_breakpoints_in_shlibs. */
797 b->enable = shlib_disabled;
798 if (!disabled_breaks)
800 target_terminal_ours_for_output ();
801 warning ("Cannot insert breakpoint %d:", b->number);
802 warning ("Temporarily disabling shared library breakpoints:");
805 warning ("breakpoint #%d ", b->number);
810 target_terminal_ours_for_output ();
811 warning ("Cannot insert breakpoint %d:", b->number);
812 #ifdef ONE_PROCESS_WRITETEXT
813 warning ("The same program may be running in another process.");
815 memory_error (val, b->address); /* which bombs us out */
822 return_val = val; /* remember failure */
824 else if (ep_is_exception_catchpoint (b)
825 && b->enable != disabled
826 && b->enable != shlib_disabled
827 && b->enable != call_disabled
832 /* If we get here, we must have a callback mechanism for exception
833 events -- with g++ style embedded label support, we insert
834 ordinary breakpoints and not catchpoints. */
835 /* Format possible error message */
836 sprintf (message, message1, b->number);
838 val = target_insert_breakpoint (b->address, b->shadow_contents);
841 /* Couldn't set breakpoint for some reason */
842 target_terminal_ours_for_output ();
843 warning ("Cannot insert catchpoint %d; disabling it.",
845 b->enable = disabled;
849 /* Bp set, now make sure callbacks are enabled */
851 args_for_catchpoint_enable args;
852 args.kind = b->type == bp_catch_catch ?
853 EX_EVENT_CATCH : EX_EVENT_THROW;
855 val = catch_errors (cover_target_enable_exception_callback,
857 message, RETURN_MASK_ALL);
858 if (val != 0 && val != -1)
862 /* Check if something went wrong; val == 0 can be ignored */
865 /* something went wrong */
866 target_terminal_ours_for_output ();
867 warning ("Cannot insert catchpoint %d; disabling it.",
869 b->enable = disabled;
874 return_val = val; /* remember failure */
877 else if ((b->type == bp_hardware_watchpoint ||
878 b->type == bp_read_watchpoint ||
879 b->type == bp_access_watchpoint)
880 && b->enable == enabled
881 && b->disposition != del_at_next_stop
885 struct frame_info *saved_frame;
886 int saved_level, within_current_scope;
887 value_ptr mark = value_mark ();
890 /* Save the current frame and level so we can restore it after
891 evaluating the watchpoint expression on its own frame. */
892 saved_frame = selected_frame;
893 saved_level = selected_frame_level;
895 /* Determine if the watchpoint is within scope. */
896 if (b->exp_valid_block == NULL)
897 within_current_scope = 1;
900 struct frame_info *fi;
902 /* There might be no current frame at this moment if we are
903 resuming from a step over a breakpoint.
904 Set up current frame before trying to find the watchpoint
906 get_current_frame ();
907 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
908 within_current_scope = (fi != NULL);
909 if (within_current_scope)
910 select_frame (fi, -1);
913 if (within_current_scope)
915 /* Evaluate the expression and cut the chain of values
916 produced off from the value chain.
918 Make sure the value returned isn't lazy; we use
919 laziness to determine what memory GDB actually needed
920 in order to compute the value of the expression. */
921 v = evaluate_expression (b->exp);
923 value_release_to_mark (mark);
928 /* Look at each value on the value chain. */
929 for (; v; v = v->next)
931 /* If it's a memory location, and GDB actually needed
932 its contents to evaluate the expression, then we
934 if (VALUE_LVAL (v) == lval_memory
937 struct type *vtype = check_typedef (VALUE_TYPE (v));
939 /* We only watch structs and arrays if user asked
940 for it explicitly, never if they just happen to
941 appear in the middle of some value chain. */
942 if (v == b->val_chain
943 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
944 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
949 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
950 len = TYPE_LENGTH (VALUE_TYPE (v));
952 if (b->type == bp_read_watchpoint)
954 else if (b->type == bp_access_watchpoint)
957 val = target_insert_watchpoint (addr, len, type);
960 /* Don't exit the loop, try to insert
961 every value on the value chain. That's
962 because we will be removing all the
963 watches below, and removing a
964 watchpoint we didn't insert could have
972 /* Failure to insert a watchpoint on any memory value in the
973 value chain brings us here. */
976 remove_breakpoint (b, mark_uninserted);
977 warning ("Could not insert hardware watchpoint %d.",
984 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
985 printf_filtered ("because the program has left the block \n");
986 printf_filtered ("in which its expression is valid.\n");
987 if (b->related_breakpoint)
988 b->related_breakpoint->disposition = del_at_next_stop;
989 b->disposition = del_at_next_stop;
992 /* Restore the frame and level. */
993 if ((saved_frame != selected_frame) ||
994 (saved_level != selected_frame_level))
995 select_frame (saved_frame, saved_level);
998 return_val = val; /* remember failure */
1000 else if ((b->type == bp_catch_fork
1001 || b->type == bp_catch_vfork
1002 || b->type == bp_catch_exec)
1003 && b->enable == enabled
1011 val = target_insert_fork_catchpoint (inferior_pid);
1013 case bp_catch_vfork:
1014 val = target_insert_vfork_catchpoint (inferior_pid);
1017 val = target_insert_exec_catchpoint (inferior_pid);
1020 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1025 target_terminal_ours_for_output ();
1026 warning ("Cannot insert catchpoint %d.", b->number);
1032 return_val = val; /* remember failure */
1041 remove_breakpoints ()
1043 register struct breakpoint *b;
1050 val = remove_breakpoint (b, mark_uninserted);
1059 remove_hw_watchpoints (void)
1061 register struct breakpoint *b;
1067 && (b->type == bp_hardware_watchpoint
1068 || b->type == bp_read_watchpoint
1069 || b->type == bp_access_watchpoint))
1071 val = remove_breakpoint (b, mark_uninserted);
1080 reattach_breakpoints (pid)
1083 register struct breakpoint *b;
1085 int saved_inferior_pid = inferior_pid;
1087 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1088 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1093 remove_breakpoint (b, mark_inserted);
1094 if (b->type == bp_hardware_breakpoint)
1095 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1097 val = target_insert_breakpoint (b->address, b->shadow_contents);
1100 inferior_pid = saved_inferior_pid;
1105 inferior_pid = saved_inferior_pid;
1110 update_breakpoints_after_exec ()
1112 struct breakpoint *b;
1113 struct breakpoint *temp;
1115 /* Doing this first prevents the badness of having delete_breakpoint()
1116 write a breakpoint's current "shadow contents" to lift the bp. That
1117 shadow is NOT valid after an exec()! */
1118 mark_breakpoints_out ();
1120 ALL_BREAKPOINTS_SAFE (b, temp)
1122 /* Solib breakpoints must be explicitly reset after an exec(). */
1123 if (b->type == bp_shlib_event)
1125 delete_breakpoint (b);
1129 /* Thread event breakpoints must be set anew after an exec(). */
1130 if (b->type == bp_thread_event)
1132 delete_breakpoint (b);
1136 /* Step-resume breakpoints are meaningless after an exec(). */
1137 if (b->type == bp_step_resume)
1139 delete_breakpoint (b);
1143 /* Ditto the sigtramp handler breakpoints. */
1144 if (b->type == bp_through_sigtramp)
1146 delete_breakpoint (b);
1150 /* Ditto the exception-handling catchpoints. */
1151 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1153 delete_breakpoint (b);
1157 /* Don't delete an exec catchpoint, because else the inferior
1158 won't stop when it ought!
1160 Similarly, we probably ought to keep vfork catchpoints, 'cause
1161 on this target, we may not be able to stop when the vfork is
1162 seen, but only when the subsequent exec is seen. (And because
1163 deleting fork catchpoints here but not vfork catchpoints will
1164 seem mysterious to users, keep those too.)
1166 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1167 target address field, if any, is sufficient to have it be reset
1168 automagically. Certainly on HP-UX that's true. */
1169 if ((b->type == bp_catch_exec) ||
1170 (b->type == bp_catch_vfork) ||
1171 (b->type == bp_catch_fork))
1173 b->address = (CORE_ADDR) NULL;
1177 /* bp_finish is a special case. The only way we ought to be able
1178 to see one of these when an exec() has happened, is if the user
1179 caught a vfork, and then said "finish". Ordinarily a finish just
1180 carries them to the call-site of the current callee, by setting
1181 a temporary bp there and resuming. But in this case, the finish
1182 will carry them entirely through the vfork & exec.
1184 We don't want to allow a bp_finish to remain inserted now. But
1185 we can't safely delete it, 'cause finish_command has a handle to
1186 the bp on a bpstat, and will later want to delete it. There's a
1187 chance (and I've seen it happen) that if we delete the bp_finish
1188 here, that its storage will get reused by the time finish_command
1189 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1190 We really must allow finish_command to delete a bp_finish.
1192 In the absense of a general solution for the "how do we know
1193 it's safe to delete something others may have handles to?"
1194 problem, what we'll do here is just uninsert the bp_finish, and
1195 let finish_command delete it.
1197 (We know the bp_finish is "doomed" in the sense that it's
1198 momentary, and will be deleted as soon as finish_command sees
1199 the inferior stopped. So it doesn't matter that the bp's
1200 address is probably bogus in the new a.out, unlike e.g., the
1201 solib breakpoints.) */
1203 if (b->type == bp_finish)
1208 /* Without a symbolic address, we have little hope of the
1209 pre-exec() address meaning the same thing in the post-exec()
1211 if (b->addr_string == NULL)
1213 delete_breakpoint (b);
1217 /* If this breakpoint has survived the above battery of checks, then
1218 it must have a symbolic address. Be sure that it gets reevaluated
1219 to a target address, rather than reusing the old evaluation. */
1220 b->address = (CORE_ADDR) NULL;
1225 detach_breakpoints (pid)
1228 register struct breakpoint *b;
1230 int saved_inferior_pid = inferior_pid;
1232 if (pid == inferior_pid)
1233 error ("Cannot detach breakpoints of inferior_pid");
1235 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1236 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1241 val = remove_breakpoint (b, mark_inserted);
1244 inferior_pid = saved_inferior_pid;
1249 inferior_pid = saved_inferior_pid;
1254 remove_breakpoint (b, is)
1255 struct breakpoint *b;
1256 insertion_state_t is;
1260 if (b->enable == permanent)
1261 /* Permanent breakpoints cannot be inserted or removed. */
1264 if (b->type == bp_none)
1265 warning ("attempted to remove apparently deleted breakpoint #%d?",
1268 if (b->type != bp_watchpoint
1269 && b->type != bp_hardware_watchpoint
1270 && b->type != bp_read_watchpoint
1271 && b->type != bp_access_watchpoint
1272 && b->type != bp_catch_fork
1273 && b->type != bp_catch_vfork
1274 && b->type != bp_catch_exec
1275 && b->type != bp_catch_catch
1276 && b->type != bp_catch_throw)
1278 if (b->type == bp_hardware_breakpoint)
1279 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1282 /* Check to see if breakpoint is in an overlay section;
1283 if so, we should remove the breakpoint at the LMA address.
1284 If that is not equal to the raw address, then we should
1285 presumable remove the breakpoint there as well. */
1286 if (overlay_debugging && b->section &&
1287 section_is_overlay (b->section))
1291 addr = overlay_unmapped_address (b->address, b->section);
1292 val = target_remove_breakpoint (addr, b->shadow_contents);
1293 /* This would be the time to check val, to see if the
1294 shadow breakpoint write to the load address succeeded.
1295 However, this might be an ordinary occurrance, eg. if
1296 the unmapped overlay is in ROM. */
1297 val = 0; /* in case unmapped address failed */
1298 if (section_is_mapped (b->section))
1299 val = target_remove_breakpoint (b->address,
1300 b->shadow_contents);
1302 else /* ordinary (non-overlay) address */
1303 val = target_remove_breakpoint (b->address, b->shadow_contents);
1307 b->inserted = (is == mark_inserted);
1309 else if ((b->type == bp_hardware_watchpoint ||
1310 b->type == bp_read_watchpoint ||
1311 b->type == bp_access_watchpoint)
1312 && b->enable == enabled
1317 b->inserted = (is == mark_inserted);
1318 /* Walk down the saved value chain. */
1319 for (v = b->val_chain; v; v = v->next)
1321 /* For each memory reference remove the watchpoint
1323 if (VALUE_LVAL (v) == lval_memory
1324 && ! VALUE_LAZY (v))
1326 struct type *vtype = check_typedef (VALUE_TYPE (v));
1328 if (v == b->val_chain
1329 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1330 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1335 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1336 len = TYPE_LENGTH (VALUE_TYPE (v));
1338 if (b->type == bp_read_watchpoint)
1340 else if (b->type == bp_access_watchpoint)
1343 val = target_remove_watchpoint (addr, len, type);
1350 /* Failure to remove any of the hardware watchpoints comes here. */
1351 if ((is == mark_uninserted) && (b->inserted))
1352 warning ("Could not remove hardware watchpoint %d.",
1355 /* Free the saved value chain. We will construct a new one
1356 the next time the watchpoint is inserted. */
1357 for (v = b->val_chain; v; v = n)
1362 b->val_chain = NULL;
1364 else if ((b->type == bp_catch_fork ||
1365 b->type == bp_catch_vfork ||
1366 b->type == bp_catch_exec)
1367 && b->enable == enabled
1374 val = target_remove_fork_catchpoint (inferior_pid);
1376 case bp_catch_vfork:
1377 val = target_remove_vfork_catchpoint (inferior_pid);
1380 val = target_remove_exec_catchpoint (inferior_pid);
1383 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1388 b->inserted = (is == mark_inserted);
1390 else if ((b->type == bp_catch_catch ||
1391 b->type == bp_catch_throw)
1392 && b->enable == enabled
1396 val = target_remove_breakpoint (b->address, b->shadow_contents);
1399 b->inserted = (is == mark_inserted);
1401 else if (ep_is_exception_catchpoint (b)
1402 && b->inserted /* sometimes previous insert doesn't happen */
1403 && b->enable == enabled
1407 val = target_remove_breakpoint (b->address, b->shadow_contents);
1411 b->inserted = (is == mark_inserted);
1417 /* Clear the "inserted" flag in all breakpoints. */
1420 mark_breakpoints_out ()
1422 register struct breakpoint *b;
1428 /* Clear the "inserted" flag in all breakpoints and delete any
1429 breakpoints which should go away between runs of the program.
1431 Plus other such housekeeping that has to be done for breakpoints
1434 Note: this function gets called at the end of a run (by
1435 generic_mourn_inferior) and when a run begins (by
1436 init_wait_for_inferior). */
1441 breakpoint_init_inferior (context)
1442 enum inf_context context;
1444 register struct breakpoint *b, *temp;
1445 static int warning_needed = 0;
1447 ALL_BREAKPOINTS_SAFE (b, temp)
1454 case bp_watchpoint_scope:
1456 /* If the call dummy breakpoint is at the entry point it will
1457 cause problems when the inferior is rerun, so we better
1460 Also get rid of scope breakpoints. */
1461 delete_breakpoint (b);
1465 case bp_hardware_watchpoint:
1466 case bp_read_watchpoint:
1467 case bp_access_watchpoint:
1469 /* Likewise for watchpoints on local expressions. */
1470 if (b->exp_valid_block != NULL)
1471 delete_breakpoint (b);
1474 /* Likewise for exception catchpoints in dynamic-linked
1475 executables where required */
1476 if (ep_is_exception_catchpoint (b) &&
1477 exception_catchpoints_are_fragile)
1480 delete_breakpoint (b);
1486 if (exception_catchpoints_are_fragile)
1487 exception_support_initialized = 0;
1489 /* Don't issue the warning unless it's really needed... */
1490 if (warning_needed && (context != inf_exited))
1492 warning ("Exception catchpoints from last run were deleted.");
1493 warning ("You must reinsert them explicitly.");
1498 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1499 exists at PC. It returns ordinary_breakpoint_here if it's an
1500 ordinary breakpoint, or permanent_breakpoint_here if it's a
1501 permanent breakpoint.
1502 - When continuing from a location with an ordinary breakpoint, we
1503 actually single step once before calling insert_breakpoints.
1504 - When continuing from a localion with a permanent breakpoint, we
1505 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1506 the target, to advance the PC past the breakpoint. */
1508 enum breakpoint_here
1509 breakpoint_here_p (pc)
1512 register struct breakpoint *b;
1513 int any_breakpoint_here = 0;
1516 if ((b->enable == enabled
1517 || b->enable == permanent)
1518 && b->address == pc) /* bp is enabled and matches pc */
1520 if (overlay_debugging &&
1521 section_is_overlay (b->section) &&
1522 !section_is_mapped (b->section))
1523 continue; /* unmapped overlay -- can't be a match */
1524 else if (b->enable == permanent)
1525 return permanent_breakpoint_here;
1527 any_breakpoint_here = 1;
1530 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1534 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1535 but it only returns true if there is actually a breakpoint inserted
1539 breakpoint_inserted_here_p (pc)
1542 register struct breakpoint *b;
1546 && b->address == pc) /* bp is inserted and matches pc */
1548 if (overlay_debugging &&
1549 section_is_overlay (b->section) &&
1550 !section_is_mapped (b->section))
1551 continue; /* unmapped overlay -- can't be a match */
1559 /* Return nonzero if FRAME is a dummy frame. We can't use
1560 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1561 much time, at least using get_saved_register on the 68k. This
1562 means that for this function to work right a port must use the
1563 bp_call_dummy breakpoint. */
1566 frame_in_dummy (frame)
1567 struct frame_info *frame;
1569 struct breakpoint *b;
1574 if (USE_GENERIC_DUMMY_FRAMES)
1575 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1579 if (b->type == bp_call_dummy
1580 && b->frame == frame->frame
1581 /* We need to check the PC as well as the frame on the sparc,
1582 for signals.exp in the testsuite. */
1585 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1586 && frame->pc <= b->address)
1592 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1593 PC is valid for process/thread PID. */
1596 breakpoint_thread_match (pc, pid)
1600 struct breakpoint *b;
1603 thread = pid_to_thread_id (pid);
1606 if (b->enable != disabled
1607 && b->enable != shlib_disabled
1608 && b->enable != call_disabled
1610 && (b->thread == -1 || b->thread == thread))
1612 if (overlay_debugging &&
1613 section_is_overlay (b->section) &&
1614 !section_is_mapped (b->section))
1615 continue; /* unmapped overlay -- can't be a match */
1624 /* bpstat stuff. External routines' interfaces are documented
1628 ep_is_catchpoint (ep)
1629 struct breakpoint *ep;
1632 (ep->type == bp_catch_load)
1633 || (ep->type == bp_catch_unload)
1634 || (ep->type == bp_catch_fork)
1635 || (ep->type == bp_catch_vfork)
1636 || (ep->type == bp_catch_exec)
1637 || (ep->type == bp_catch_catch)
1638 || (ep->type == bp_catch_throw)
1641 /* ??rehrauer: Add more kinds here, as are implemented... */
1646 ep_is_shlib_catchpoint (ep)
1647 struct breakpoint *ep;
1650 (ep->type == bp_catch_load)
1651 || (ep->type == bp_catch_unload)
1656 ep_is_exception_catchpoint (ep)
1657 struct breakpoint *ep;
1660 (ep->type == bp_catch_catch)
1661 || (ep->type == bp_catch_throw)
1665 /* Clear a bpstat so that it says we are not at any breakpoint.
1666 Also free any storage that is part of a bpstat. */
1681 if (p->old_val != NULL)
1682 value_free (p->old_val);
1689 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1690 is part of the bpstat is copied as well. */
1698 bpstat retval = NULL;
1703 for (; bs != NULL; bs = bs->next)
1705 tmp = (bpstat) xmalloc (sizeof (*tmp));
1706 memcpy (tmp, bs, sizeof (*tmp));
1708 /* This is the first thing in the chain. */
1718 /* Find the bpstat associated with this breakpoint */
1721 bpstat_find_breakpoint (bsp, breakpoint)
1723 struct breakpoint *breakpoint;
1728 for (; bsp != NULL; bsp = bsp->next)
1730 if (bsp->breakpoint_at == breakpoint)
1736 /* Find a step_resume breakpoint associated with this bpstat.
1737 (If there are multiple step_resume bp's on the list, this function
1738 will arbitrarily pick one.)
1740 It is an error to use this function if BPSTAT doesn't contain a
1741 step_resume breakpoint.
1743 See wait_for_inferior's use of this function. */
1745 bpstat_find_step_resume_breakpoint (bsp)
1749 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1751 for (; bsp != NULL; bsp = bsp->next)
1753 if ((bsp->breakpoint_at != NULL) &&
1754 (bsp->breakpoint_at->type == bp_step_resume))
1755 return bsp->breakpoint_at;
1758 error ("Internal error (no step_resume breakpoint found)");
1762 /* Return the breakpoint number of the first breakpoint we are stopped
1763 at. *BSP upon return is a bpstat which points to the remaining
1764 breakpoints stopped at (but which is not guaranteed to be good for
1765 anything but further calls to bpstat_num).
1766 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1772 struct breakpoint *b;
1775 return 0; /* No more breakpoint values */
1778 b = (*bsp)->breakpoint_at;
1779 *bsp = (*bsp)->next;
1781 return -1; /* breakpoint that's been deleted since */
1783 return b->number; /* We have its number */
1787 /* Modify BS so that the actions will not be performed. */
1790 bpstat_clear_actions (bs)
1793 for (; bs != NULL; bs = bs->next)
1795 bs->commands = NULL;
1796 if (bs->old_val != NULL)
1798 value_free (bs->old_val);
1804 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1807 cleanup_executing_breakpoints (ignore)
1810 executing_breakpoint_commands = 0;
1813 /* Execute all the commands associated with all the breakpoints at this
1814 location. Any of these commands could cause the process to proceed
1815 beyond this point, etc. We look out for such changes by checking
1816 the global "breakpoint_proceeded" after each command. */
1819 bpstat_do_actions (bsp)
1823 struct cleanup *old_chain;
1824 struct command_line *cmd;
1826 /* Avoid endless recursion if a `source' command is contained
1828 if (executing_breakpoint_commands)
1831 executing_breakpoint_commands = 1;
1832 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1835 /* Note that (as of this writing), our callers all appear to
1836 be passing us the address of global stop_bpstat. And, if
1837 our calls to execute_control_command cause the inferior to
1838 proceed, that global (and hence, *bsp) will change.
1840 We must be careful to not touch *bsp unless the inferior
1841 has not proceeded. */
1843 /* This pointer will iterate over the list of bpstat's. */
1846 breakpoint_proceeded = 0;
1847 for (; bs != NULL; bs = bs->next)
1852 execute_control_command (cmd);
1854 if (breakpoint_proceeded)
1859 if (breakpoint_proceeded)
1860 /* The inferior is proceeded by the command; bomb out now.
1861 The bpstat chain has been blown away by wait_for_inferior.
1862 But since execution has stopped again, there is a new bpstat
1863 to look at, so start over. */
1866 bs->commands = NULL;
1869 executing_breakpoint_commands = 0;
1870 discard_cleanups (old_chain);
1873 /* This is the normal print function for a bpstat. In the future,
1874 much of this logic could (should?) be moved to bpstat_stop_status,
1875 by having it set different print_it values.
1877 Current scheme: When we stop, bpstat_print() is called. It loops
1878 through the bpstat list of things causing this stop, calling the
1879 print_bp_stop_message function on each one. The behavior of the
1880 print_bp_stop_message function depends on the print_it field of
1881 bpstat. If such field so indicates, call this function here.
1883 Return values from this routine (ultimately used by bpstat_print()
1884 and normal_stop() to decide what to do):
1885 PRINT_NOTHING: Means we already printed all we needed to print,
1886 don't print anything else.
1887 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1888 that something to be followed by a location.
1889 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1890 that something to be followed by a location.
1891 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1894 static enum print_stop_action
1895 print_it_typical (bs)
1899 struct cleanup *old_chain;
1900 struct ui_stream *stb;
1901 stb = ui_out_stream_new (uiout);
1902 old_chain = make_cleanup_ui_out_stream_delete (stb);
1904 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1905 which has since been deleted. */
1906 if (bs->breakpoint_at == NULL)
1907 return PRINT_UNKNOWN;
1909 switch (bs->breakpoint_at->type)
1912 case bp_hardware_breakpoint:
1914 annotate_breakpoint (bs->breakpoint_at->number);
1915 ui_out_text (uiout, "\nBreakpoint ");
1916 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
1917 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1918 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1919 ui_out_text (uiout, ", ");
1920 return PRINT_SRC_AND_LOC;
1922 /* I think the user probably only wants to see one breakpoint
1923 number, not all of them. */
1924 annotate_breakpoint (bs->breakpoint_at->number);
1925 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1926 return PRINT_SRC_AND_LOC;
1930 case bp_shlib_event:
1931 /* Did we stop because the user set the stop_on_solib_events
1932 variable? (If so, we report this as a generic, "Stopped due
1933 to shlib event" message.) */
1934 printf_filtered ("Stopped due to shared library event\n");
1935 return PRINT_NOTHING;
1938 case bp_thread_event:
1939 /* Not sure how we will get here.
1940 GDB should not stop for these breakpoints. */
1941 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1942 return PRINT_NOTHING;
1946 annotate_catchpoint (bs->breakpoint_at->number);
1947 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1948 printf_filtered ("loaded");
1949 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1950 return PRINT_SRC_AND_LOC;
1953 case bp_catch_unload:
1954 annotate_catchpoint (bs->breakpoint_at->number);
1955 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1956 printf_filtered ("unloaded");
1957 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1958 return PRINT_SRC_AND_LOC;
1962 annotate_catchpoint (bs->breakpoint_at->number);
1963 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1964 printf_filtered ("forked");
1965 printf_filtered (" process %d), ",
1966 bs->breakpoint_at->forked_inferior_pid);
1967 return PRINT_SRC_AND_LOC;
1970 case bp_catch_vfork:
1971 annotate_catchpoint (bs->breakpoint_at->number);
1972 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1973 printf_filtered ("vforked");
1974 printf_filtered (" process %d), ",
1975 bs->breakpoint_at->forked_inferior_pid);
1976 return PRINT_SRC_AND_LOC;
1980 annotate_catchpoint (bs->breakpoint_at->number);
1981 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1982 bs->breakpoint_at->number,
1983 bs->breakpoint_at->exec_pathname);
1984 return PRINT_SRC_AND_LOC;
1987 case bp_catch_catch:
1988 if (current_exception_event &&
1989 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1991 annotate_catchpoint (bs->breakpoint_at->number);
1992 printf_filtered ("\nCatchpoint %d (exception caught), ",
1993 bs->breakpoint_at->number);
1994 printf_filtered ("throw location ");
1995 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1996 printf_filtered ("%s:%d",
1997 CURRENT_EXCEPTION_THROW_FILE,
1998 CURRENT_EXCEPTION_THROW_LINE);
2000 printf_filtered ("unknown");
2002 printf_filtered (", catch location ");
2003 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2004 printf_filtered ("%s:%d",
2005 CURRENT_EXCEPTION_CATCH_FILE,
2006 CURRENT_EXCEPTION_CATCH_LINE);
2008 printf_filtered ("unknown");
2010 printf_filtered ("\n");
2011 /* don't bother to print location frame info */
2012 return PRINT_SRC_ONLY;
2016 /* really throw, some other bpstat will handle it */
2017 return PRINT_UNKNOWN;
2021 case bp_catch_throw:
2022 if (current_exception_event &&
2023 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2025 annotate_catchpoint (bs->breakpoint_at->number);
2026 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2027 bs->breakpoint_at->number);
2028 printf_filtered ("throw location ");
2029 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2030 printf_filtered ("%s:%d",
2031 CURRENT_EXCEPTION_THROW_FILE,
2032 CURRENT_EXCEPTION_THROW_LINE);
2034 printf_filtered ("unknown");
2036 printf_filtered (", catch location ");
2037 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2038 printf_filtered ("%s:%d",
2039 CURRENT_EXCEPTION_CATCH_FILE,
2040 CURRENT_EXCEPTION_CATCH_LINE);
2042 printf_filtered ("unknown");
2044 printf_filtered ("\n");
2045 /* don't bother to print location frame info */
2046 return PRINT_SRC_ONLY;
2050 /* really catch, some other bpstat will handle it */
2051 return PRINT_UNKNOWN;
2056 case bp_hardware_watchpoint:
2057 if (bs->old_val != NULL)
2059 annotate_watchpoint (bs->breakpoint_at->number);
2061 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2062 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2063 mention (bs->breakpoint_at);
2064 ui_out_list_begin (uiout, "value");
2065 ui_out_text (uiout, "\nOld value = ");
2066 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2067 ui_out_field_stream (uiout, "old", stb);
2068 ui_out_text (uiout, "\nNew value = ");
2069 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2070 ui_out_field_stream (uiout, "new", stb);
2071 ui_out_list_end (uiout);
2072 ui_out_text (uiout, "\n");
2074 mention (bs->breakpoint_at);
2075 printf_filtered ("\nOld value = ");
2076 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2077 printf_filtered ("\nNew value = ");
2078 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2079 Val_pretty_default);
2080 printf_filtered ("\n");
2082 value_free (bs->old_val);
2085 /* More than one watchpoint may have been triggered. */
2086 return PRINT_UNKNOWN;
2089 case bp_read_watchpoint:
2091 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2092 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2093 mention (bs->breakpoint_at);
2094 ui_out_list_begin (uiout, "value");
2095 ui_out_text (uiout, "\nValue = ");
2096 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2097 ui_out_field_stream (uiout, "value", stb);
2098 ui_out_list_end (uiout);
2099 ui_out_text (uiout, "\n");
2101 mention (bs->breakpoint_at);
2102 printf_filtered ("\nValue = ");
2103 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2104 Val_pretty_default);
2105 printf_filtered ("\n");
2107 return PRINT_UNKNOWN;
2110 case bp_access_watchpoint:
2112 if (bs->old_val != NULL)
2114 annotate_watchpoint (bs->breakpoint_at->number);
2115 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2116 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2117 mention (bs->breakpoint_at);
2118 ui_out_list_begin (uiout, "value");
2119 ui_out_text (uiout, "\nOld value = ");
2120 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2121 ui_out_field_stream (uiout, "old", stb);
2122 value_free (bs->old_val);
2124 ui_out_text (uiout, "\nNew value = ");
2128 mention (bs->breakpoint_at);
2129 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2130 ui_out_list_begin (uiout, "value");
2131 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2132 ui_out_text (uiout, "\nValue = ");
2134 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2135 ui_out_field_stream (uiout, "new", stb);
2136 ui_out_list_end (uiout);
2137 ui_out_text (uiout, "\n");
2139 if (bs->old_val != NULL)
2141 annotate_watchpoint (bs->breakpoint_at->number);
2142 mention (bs->breakpoint_at);
2143 printf_filtered ("\nOld value = ");
2144 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2145 value_free (bs->old_val);
2147 printf_filtered ("\nNew value = ");
2151 mention (bs->breakpoint_at);
2152 printf_filtered ("\nValue = ");
2154 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2155 Val_pretty_default);
2156 printf_filtered ("\n");
2158 return PRINT_UNKNOWN;
2161 /* Fall through, we don't deal with these types of breakpoints
2166 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2167 ui_out_field_string (uiout, "reason", "function-finished");
2169 return PRINT_UNKNOWN;
2174 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2175 ui_out_field_string (uiout, "reason", "location-reached");
2177 return PRINT_UNKNOWN;
2182 case bp_longjmp_resume:
2183 case bp_step_resume:
2184 case bp_through_sigtramp:
2185 case bp_watchpoint_scope:
2188 return PRINT_UNKNOWN;
2192 /* Generic routine for printing messages indicating why we
2193 stopped. The behavior of this function depends on the value
2194 'print_it' in the bpstat structure. Under some circumstances we
2195 may decide not to print anything here and delegate the task to
2198 static enum print_stop_action
2199 print_bp_stop_message (bpstat bs)
2201 switch (bs->print_it)
2204 /* Nothing should be printed for this bpstat entry. */
2205 return PRINT_UNKNOWN;
2209 /* We still want to print the frame, but we already printed the
2210 relevant messages. */
2211 return PRINT_SRC_AND_LOC;
2214 case print_it_normal:
2215 /* Normal case, we handle everything in print_it_typical. */
2216 return print_it_typical (bs);
2219 internal_error ("print_bp_stop_message: unrecognized enum value");
2224 /* Print a message indicating what happened. This is called from
2225 normal_stop(). The input to this routine is the head of the bpstat
2226 list - a list of the eventpoints that caused this stop. This
2227 routine calls the generic print routine for printing a message
2228 about reasons for stopping. This will print (for example) the
2229 "Breakpoint n," part of the output. The return value of this
2232 PRINT_UNKNOWN: Means we printed nothing
2233 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2234 code to print the location. An example is
2235 "Breakpoint 1, " which should be followed by
2237 PRINT_SRC_ONLY: Means we printed something, but there is no need
2238 to also print the location part of the message.
2239 An example is the catch/throw messages, which
2240 don't require a location appended to the end.
2241 PRINT_NOTHING: We have done some printing and we don't need any
2242 further info to be printed.*/
2244 enum print_stop_action
2250 /* Maybe another breakpoint in the chain caused us to stop.
2251 (Currently all watchpoints go on the bpstat whether hit or not.
2252 That probably could (should) be changed, provided care is taken
2253 with respect to bpstat_explains_signal). */
2254 for (; bs; bs = bs->next)
2256 val = print_bp_stop_message (bs);
2257 if (val == PRINT_SRC_ONLY
2258 || val == PRINT_SRC_AND_LOC
2259 || val == PRINT_NOTHING)
2263 /* We reached the end of the chain, or we got a null BS to start
2264 with and nothing was printed. */
2265 return PRINT_UNKNOWN;
2268 /* Evaluate the expression EXP and return 1 if value is zero.
2269 This is used inside a catch_errors to evaluate the breakpoint condition.
2270 The argument is a "struct expression *" that has been cast to char * to
2271 make it pass through catch_errors. */
2274 breakpoint_cond_eval (exp)
2277 value_ptr mark = value_mark ();
2278 int i = !value_true (evaluate_expression ((struct expression *) exp));
2279 value_free_to_mark (mark);
2283 /* Allocate a new bpstat and chain it to the current one. */
2286 bpstat_alloc (b, cbs)
2287 register struct breakpoint *b;
2288 bpstat cbs; /* Current "bs" value */
2292 bs = (bpstat) xmalloc (sizeof (*bs));
2294 bs->breakpoint_at = b;
2295 /* If the condition is false, etc., don't do the commands. */
2296 bs->commands = NULL;
2298 bs->print_it = print_it_normal;
2302 /* Possible return values for watchpoint_check (this can't be an enum
2303 because of check_errors). */
2304 /* The watchpoint has been deleted. */
2305 #define WP_DELETED 1
2306 /* The value has changed. */
2307 #define WP_VALUE_CHANGED 2
2308 /* The value has not changed. */
2309 #define WP_VALUE_NOT_CHANGED 3
2311 #define BP_TEMPFLAG 1
2312 #define BP_HARDWAREFLAG 2
2314 /* Check watchpoint condition. */
2317 watchpoint_check (p)
2320 bpstat bs = (bpstat) p;
2321 struct breakpoint *b;
2322 struct frame_info *fr;
2323 int within_current_scope;
2325 b = bs->breakpoint_at;
2327 if (b->exp_valid_block == NULL)
2328 within_current_scope = 1;
2331 /* There is no current frame at this moment. If we're going to have
2332 any chance of handling watchpoints on local variables, we'll need
2333 the frame chain (so we can determine if we're in scope). */
2334 reinit_frame_cache ();
2335 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2336 within_current_scope = (fr != NULL);
2337 if (within_current_scope)
2338 /* If we end up stopping, the current frame will get selected
2339 in normal_stop. So this call to select_frame won't affect
2341 select_frame (fr, -1);
2344 if (within_current_scope)
2346 /* We use value_{,free_to_}mark because it could be a
2347 *long* time before we return to the command level and
2348 call free_all_values. We can't call free_all_values because
2349 we might be in the middle of evaluating a function call. */
2351 value_ptr mark = value_mark ();
2352 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2353 if (!value_equal (b->val, new_val))
2355 release_value (new_val);
2356 value_free_to_mark (mark);
2357 bs->old_val = b->val;
2359 /* We will stop here */
2360 return WP_VALUE_CHANGED;
2364 /* Nothing changed, don't do anything. */
2365 value_free_to_mark (mark);
2366 /* We won't stop here */
2367 return WP_VALUE_NOT_CHANGED;
2372 /* This seems like the only logical thing to do because
2373 if we temporarily ignored the watchpoint, then when
2374 we reenter the block in which it is valid it contains
2375 garbage (in the case of a function, it may have two
2376 garbage values, one before and one after the prologue).
2377 So we can't even detect the first assignment to it and
2378 watch after that (since the garbage may or may not equal
2379 the first value assigned). */
2380 /* We print all the stop information in print_it_typical(), but
2381 in this case, by the time we call print_it_typical() this bp
2382 will be deleted already. So we have no choice but print the
2383 information here. */
2385 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2386 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2387 ui_out_text (uiout, "\nWatchpoint ");
2388 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2389 ui_out_text (uiout, " deleted because the program has left the block in\n\
2390 which its expression is valid.\n");
2393 Watchpoint %d deleted because the program has left the block in\n\
2394 which its expression is valid.\n", bs->breakpoint_at->number);
2397 if (b->related_breakpoint)
2398 b->related_breakpoint->disposition = del_at_next_stop;
2399 b->disposition = del_at_next_stop;
2405 /* Get a bpstat associated with having just stopped at address *PC
2406 and frame address CORE_ADDRESS. Update *PC to point at the
2407 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2408 if this is known to not be a real breakpoint (it could still be a
2409 watchpoint, though). */
2411 /* Determine whether we stopped at a breakpoint, etc, or whether we
2412 don't understand this stop. Result is a chain of bpstat's such that:
2414 if we don't understand the stop, the result is a null pointer.
2416 if we understand why we stopped, the result is not null.
2418 Each element of the chain refers to a particular breakpoint or
2419 watchpoint at which we have stopped. (We may have stopped for
2420 several reasons concurrently.)
2422 Each element of the chain has valid next, breakpoint_at,
2423 commands, FIXME??? fields. */
2426 bpstat_stop_status (pc, not_a_breakpoint)
2428 int not_a_breakpoint;
2430 register struct breakpoint *b, *temp;
2432 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2433 int real_breakpoint = 0;
2434 /* Root of the chain of bpstat's */
2435 struct bpstats root_bs[1];
2436 /* Pointer to the last thing in the chain currently. */
2437 bpstat bs = root_bs;
2438 static char message1[] =
2439 "Error evaluating expression for watchpoint %d\n";
2440 char message[sizeof (message1) + 30 /* slop */ ];
2442 /* Get the address where the breakpoint would have been. */
2443 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ?
2444 0 : DECR_PC_AFTER_BREAK);
2446 ALL_BREAKPOINTS_SAFE (b, temp)
2448 if (b->enable == disabled
2449 || b->enable == shlib_disabled
2450 || b->enable == call_disabled)
2453 if (b->type != bp_watchpoint
2454 && b->type != bp_hardware_watchpoint
2455 && b->type != bp_read_watchpoint
2456 && b->type != bp_access_watchpoint
2457 && b->type != bp_hardware_breakpoint
2458 && b->type != bp_catch_fork
2459 && b->type != bp_catch_vfork
2460 && b->type != bp_catch_exec
2461 && b->type != bp_catch_catch
2462 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2463 if (b->address != bp_addr || /* address doesn't match or */
2464 (overlay_debugging && /* overlay doesn't match */
2465 section_is_overlay (b->section) &&
2466 !section_is_mapped (b->section)))
2469 if (b->type == bp_hardware_breakpoint
2470 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2473 /* Is this a catchpoint of a load or unload? If so, did we
2474 get a load or unload of the specified library? If not,
2476 if ((b->type == bp_catch_load)
2477 #if defined(SOLIB_HAVE_LOAD_EVENT)
2478 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2479 || ((b->dll_pathname != NULL)
2480 && (strcmp (b->dll_pathname,
2481 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2487 if ((b->type == bp_catch_unload)
2488 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2489 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2490 || ((b->dll_pathname != NULL)
2491 && (strcmp (b->dll_pathname,
2492 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2498 if ((b->type == bp_catch_fork)
2499 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2502 if ((b->type == bp_catch_vfork)
2503 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2506 if ((b->type == bp_catch_exec)
2507 && !target_has_execd (inferior_pid, &b->exec_pathname))
2510 if (ep_is_exception_catchpoint (b) &&
2511 !(current_exception_event = target_get_current_exception_event ()))
2514 /* Come here if it's a watchpoint, or if the break address matches */
2516 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2518 /* Watchpoints may change this, if not found to have triggered. */
2522 sprintf (message, message1, b->number);
2523 if (b->type == bp_watchpoint ||
2524 b->type == bp_hardware_watchpoint)
2526 switch (catch_errors (watchpoint_check, bs, message,
2530 /* We've already printed what needs to be printed. */
2531 /* Actually this is superfluous, because by the time we
2532 call print_it_typical() the wp will be already deleted,
2533 and the function will return immediately. */
2534 bs->print_it = print_it_done;
2537 case WP_VALUE_CHANGED:
2541 case WP_VALUE_NOT_CHANGED:
2543 bs->print_it = print_it_noop;
2550 /* Error from catch_errors. */
2551 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2552 if (b->related_breakpoint)
2553 b->related_breakpoint->disposition = del_at_next_stop;
2554 b->disposition = del_at_next_stop;
2555 /* We've already printed what needs to be printed. */
2556 bs->print_it = print_it_done;
2562 else if (b->type == bp_read_watchpoint ||
2563 b->type == bp_access_watchpoint)
2569 addr = target_stopped_data_address ();
2572 for (v = b->val_chain; v; v = v->next)
2574 if (VALUE_LVAL (v) == lval_memory
2575 && ! VALUE_LAZY (v))
2577 struct type *vtype = check_typedef (VALUE_TYPE (v));
2579 if (v == b->val_chain
2580 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2581 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2585 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2586 /* Exact match not required. Within range is
2588 if (addr >= vaddr &&
2589 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2595 switch (catch_errors (watchpoint_check, bs, message,
2599 /* We've already printed what needs to be printed. */
2600 bs->print_it = print_it_done;
2603 case WP_VALUE_CHANGED:
2604 if (b->type == bp_read_watchpoint)
2606 /* Don't stop: read watchpoints shouldn't fire if
2607 the value has changed. This is for targets which
2608 cannot set read-only watchpoints. */
2609 bs->print_it = print_it_noop;
2615 case WP_VALUE_NOT_CHANGED:
2622 /* Error from catch_errors. */
2623 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2624 if (b->related_breakpoint)
2625 b->related_breakpoint->disposition = del_at_next_stop;
2626 b->disposition = del_at_next_stop;
2627 /* We've already printed what needs to be printed. */
2628 bs->print_it = print_it_done;
2631 else /* found == 0 */
2633 /* This is a case where some watchpoint(s) triggered,
2634 but not at the address of this watchpoint (FOUND
2635 was left zero). So don't print anything for this
2637 bs->print_it = print_it_noop;
2644 /* By definition, an encountered breakpoint is a triggered
2648 real_breakpoint = 1;
2652 b->frame != (get_current_frame ())->frame)
2656 int value_is_zero = 0;
2660 /* Need to select the frame, with all that implies
2661 so that the conditions will have the right context. */
2662 select_frame (get_current_frame (), 0);
2664 = catch_errors (breakpoint_cond_eval, (b->cond),
2665 "Error in testing breakpoint condition:\n",
2667 /* FIXME-someday, should give breakpoint # */
2670 if (b->cond && value_is_zero)
2673 /* Don't consider this a hit. */
2676 else if (b->ignore_count > 0)
2679 annotate_ignore_count_change ();
2684 /* We will stop here */
2685 if (b->disposition == disable)
2686 b->enable = disabled;
2687 bs->commands = b->commands;
2691 (STREQ ("silent", bs->commands->line) ||
2692 (xdb_commands && STREQ ("Q", bs->commands->line))))
2694 bs->commands = bs->commands->next;
2699 /* Print nothing for this entry if we dont stop or if we dont print. */
2700 if (bs->stop == 0 || bs->print == 0)
2701 bs->print_it = print_it_noop;
2704 bs->next = NULL; /* Terminate the chain */
2705 bs = root_bs->next; /* Re-grab the head of the chain */
2707 if (real_breakpoint && bs)
2709 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2711 if (DECR_PC_AFTER_HW_BREAK != 0)
2713 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2719 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2722 #if defined (SHIFT_INST_REGS)
2724 #else /* No SHIFT_INST_REGS. */
2726 #endif /* No SHIFT_INST_REGS. */
2731 /* The value of a hardware watchpoint hasn't changed, but the
2732 intermediate memory locations we are watching may have. */
2733 if (bs && !bs->stop &&
2734 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2735 bs->breakpoint_at->type == bp_read_watchpoint ||
2736 bs->breakpoint_at->type == bp_access_watchpoint))
2738 remove_breakpoints ();
2739 insert_breakpoints ();
2744 /* Tell what to do about this bpstat. */
2749 /* Classify each bpstat as one of the following. */
2752 /* This bpstat element has no effect on the main_action. */
2755 /* There was a watchpoint, stop but don't print. */
2758 /* There was a watchpoint, stop and print. */
2761 /* There was a breakpoint but we're not stopping. */
2764 /* There was a breakpoint, stop but don't print. */
2767 /* There was a breakpoint, stop and print. */
2770 /* We hit the longjmp breakpoint. */
2773 /* We hit the longjmp_resume breakpoint. */
2776 /* We hit the step_resume breakpoint. */
2779 /* We hit the through_sigtramp breakpoint. */
2782 /* We hit the shared library event breakpoint. */
2785 /* We caught a shared library event. */
2788 /* This is just used to count how many enums there are. */
2792 /* Here is the table which drives this routine. So that we can
2793 format it pretty, we define some abbreviations for the
2794 enum bpstat_what codes. */
2795 #define kc BPSTAT_WHAT_KEEP_CHECKING
2796 #define ss BPSTAT_WHAT_STOP_SILENT
2797 #define sn BPSTAT_WHAT_STOP_NOISY
2798 #define sgl BPSTAT_WHAT_SINGLE
2799 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2800 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2801 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2802 #define sr BPSTAT_WHAT_STEP_RESUME
2803 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2804 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2805 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2807 /* "Can't happen." Might want to print an error message.
2808 abort() is not out of the question, but chances are GDB is just
2809 a bit confused, not unusable. */
2810 #define err BPSTAT_WHAT_STOP_NOISY
2812 /* Given an old action and a class, come up with a new action. */
2813 /* One interesting property of this table is that wp_silent is the same
2814 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2815 after stopping, the check for whether to step over a breakpoint
2816 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2817 reference to how we stopped. We retain separate wp_silent and
2818 bp_silent codes in case we want to change that someday.
2820 Another possibly interesting property of this table is that
2821 there's a partial ordering, priority-like, of the actions. Once
2822 you've decided that some action is appropriate, you'll never go
2823 back and decide something of a lower priority is better. The
2826 kc < clr sgl shl slr sn sr ss ts
2827 sgl < clrs shl shlr slr sn sr ss ts
2828 slr < err shl shlr sn sr ss ts
2829 clr < clrs err shl shlr sn sr ss ts
2830 clrs < err shl shlr sn sr ss ts
2831 ss < shl shlr sn sr ts
2838 What I think this means is that we don't need a damned table
2839 here. If you just put the rows and columns in the right order,
2840 it'd look awfully regular. We could simply walk the bpstat list
2841 and choose the highest priority action we find, with a little
2842 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2843 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2844 is messy anyway). */
2846 /* step_resume entries: a step resume breakpoint overrides another
2847 breakpoint of signal handling (see comment in wait_for_inferior
2848 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2849 /* We handle the through_sigtramp_breakpoint the same way; having both
2850 one of those and a step_resume_breakpoint is probably very rare (?). */
2852 static const enum bpstat_what_main_action
2853 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2856 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2859 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2861 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2863 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2865 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2867 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2869 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2871 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2873 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2875 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2877 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2879 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2881 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2896 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2897 struct bpstat_what retval;
2899 retval.call_dummy = 0;
2900 for (; bs != NULL; bs = bs->next)
2902 enum class bs_class = no_effect;
2903 if (bs->breakpoint_at == NULL)
2904 /* I suspect this can happen if it was a momentary breakpoint
2905 which has since been deleted. */
2907 switch (bs->breakpoint_at->type)
2913 case bp_hardware_breakpoint:
2919 bs_class = bp_noisy;
2921 bs_class = bp_silent;
2924 bs_class = bp_nostop;
2927 case bp_hardware_watchpoint:
2928 case bp_read_watchpoint:
2929 case bp_access_watchpoint:
2933 bs_class = wp_noisy;
2935 bs_class = wp_silent;
2938 /* There was a watchpoint, but we're not stopping.
2939 This requires no further action. */
2940 bs_class = no_effect;
2943 bs_class = long_jump;
2945 case bp_longjmp_resume:
2946 bs_class = long_resume;
2948 case bp_step_resume:
2951 bs_class = step_resume;
2954 /* It is for the wrong frame. */
2955 bs_class = bp_nostop;
2957 case bp_through_sigtramp:
2958 bs_class = through_sig;
2960 case bp_watchpoint_scope:
2961 bs_class = bp_nostop;
2963 case bp_shlib_event:
2964 bs_class = shlib_event;
2966 case bp_thread_event:
2967 bs_class = bp_nostop;
2970 case bp_catch_unload:
2971 /* Only if this catchpoint triggered should we cause the
2972 step-out-of-dld behaviour. Otherwise, we ignore this
2975 bs_class = catch_shlib_event;
2977 bs_class = no_effect;
2980 case bp_catch_vfork:
2985 bs_class = bp_noisy;
2987 bs_class = bp_silent;
2990 /* There was a catchpoint, but we're not stopping.
2991 This requires no further action. */
2992 bs_class = no_effect;
2994 case bp_catch_catch:
2995 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2996 bs_class = bp_nostop;
2998 bs_class = bs->print ? bp_noisy : bp_silent;
3000 case bp_catch_throw:
3001 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3002 bs_class = bp_nostop;
3004 bs_class = bs->print ? bp_noisy : bp_silent;
3007 /* Make sure the action is stop (silent or noisy),
3008 so infrun.c pops the dummy frame. */
3009 bs_class = bp_silent;
3010 retval.call_dummy = 1;
3013 current_action = table[(int) bs_class][(int) current_action];
3015 retval.main_action = current_action;
3019 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3020 without hardware support). This isn't related to a specific bpstat,
3021 just to things like whether watchpoints are set. */
3024 bpstat_should_step ()
3026 struct breakpoint *b;
3028 if (b->enable == enabled && b->type == bp_watchpoint)
3033 /* Nonzero if there are enabled hardware watchpoints. */
3035 bpstat_have_active_hw_watchpoints ()
3037 struct breakpoint *b;
3039 if ((b->enable == enabled) &&
3041 ((b->type == bp_hardware_watchpoint) ||
3042 (b->type == bp_read_watchpoint) ||
3043 (b->type == bp_access_watchpoint)))
3049 /* Given a bpstat that records zero or more triggered eventpoints, this
3050 function returns another bpstat which contains only the catchpoints
3051 on that first list, if any. */
3053 bpstat_get_triggered_catchpoints (ep_list, cp_list)
3057 struct bpstats root_bs[1];
3058 bpstat bs = root_bs;
3059 struct breakpoint *ep;
3062 bpstat_clear (cp_list);
3063 root_bs->next = NULL;
3065 for (; ep_list != NULL; ep_list = ep_list->next)
3067 /* Is this eventpoint a catchpoint? If not, ignore it. */
3068 ep = ep_list->breakpoint_at;
3071 if ((ep->type != bp_catch_load) &&
3072 (ep->type != bp_catch_unload) &&
3073 (ep->type != bp_catch_catch) &&
3074 (ep->type != bp_catch_throw))
3075 /* pai: (temp) ADD fork/vfork here!! */
3078 /* Yes; add it to the list. */
3079 bs = bpstat_alloc (ep, bs);
3084 #if defined(SOLIB_ADD)
3085 /* Also, for each triggered catchpoint, tag it with the name of
3086 the library that caused this trigger. (We copy the name now,
3087 because it's only guaranteed to be available NOW, when the
3088 catchpoint triggers. Clients who may wish to know the name
3089 later must get it from the catchpoint itself.) */
3090 if (ep->triggered_dll_pathname != NULL)
3091 free (ep->triggered_dll_pathname);
3092 if (ep->type == bp_catch_load)
3093 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
3095 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
3097 dll_pathname = NULL;
3101 ep->triggered_dll_pathname = (char *)
3102 xmalloc (strlen (dll_pathname) + 1);
3103 strcpy (ep->triggered_dll_pathname, dll_pathname);
3106 ep->triggered_dll_pathname = NULL;
3112 /* Print B to gdb_stdout. */
3114 print_one_breakpoint (struct breakpoint *b,
3115 CORE_ADDR *last_addr)
3117 register struct command_line *l;
3118 register struct symbol *sym;
3119 struct ep_type_description
3124 static struct ep_type_description bptypes[] =
3126 {bp_none, "?deleted?"},
3127 {bp_breakpoint, "breakpoint"},
3128 {bp_hardware_breakpoint, "hw breakpoint"},
3129 {bp_until, "until"},
3130 {bp_finish, "finish"},
3131 {bp_watchpoint, "watchpoint"},
3132 {bp_hardware_watchpoint, "hw watchpoint"},
3133 {bp_read_watchpoint, "read watchpoint"},
3134 {bp_access_watchpoint, "acc watchpoint"},
3135 {bp_longjmp, "longjmp"},
3136 {bp_longjmp_resume, "longjmp resume"},
3137 {bp_step_resume, "step resume"},
3138 {bp_through_sigtramp, "sigtramp"},
3139 {bp_watchpoint_scope, "watchpoint scope"},
3140 {bp_call_dummy, "call dummy"},
3141 {bp_shlib_event, "shlib events"},
3142 {bp_thread_event, "thread events"},
3143 {bp_catch_load, "catch load"},
3144 {bp_catch_unload, "catch unload"},
3145 {bp_catch_fork, "catch fork"},
3146 {bp_catch_vfork, "catch vfork"},
3147 {bp_catch_exec, "catch exec"},
3148 {bp_catch_catch, "catch catch"},
3149 {bp_catch_throw, "catch throw"}
3152 static char *bpdisps[] =
3153 {"del", "dstp", "dis", "keep"};
3154 static char bpenables[] = "nynny";
3155 char wrap_indent[80];
3157 struct ui_stream *stb = ui_out_stream_new (uiout);
3158 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3163 ui_out_list_begin (uiout, "bkpt");
3169 ui_out_field_int (uiout, "number", b->number);
3171 printf_filtered ("%-3d ", b->number);
3176 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3177 || ((int) b->type != bptypes[(int) b->type].type))
3178 internal_error ("bptypes table does not describe type #%d.",
3181 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3183 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3189 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3191 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3197 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3198 ui_out_spaces (uiout, 2);
3200 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3204 strcpy (wrap_indent, " ");
3206 strcat (wrap_indent, " ");
3210 internal_error ("print_one_breakpoint: bp_none encountered\n");
3214 case bp_hardware_watchpoint:
3215 case bp_read_watchpoint:
3216 case bp_access_watchpoint:
3217 /* Field 4, the address, is omitted (which makes the columns
3218 not line up too nicely with the headers, but the effect
3219 is relatively readable). */
3222 ui_out_field_skip (uiout, "addr");
3224 print_expression (b->exp, stb->stream);
3225 ui_out_field_stream (uiout, "what", stb);
3228 print_expression (b->exp, gdb_stdout);
3233 case bp_catch_unload:
3234 /* Field 4, the address, is omitted (which makes the columns
3235 not line up too nicely with the headers, but the effect
3236 is relatively readable). */
3239 ui_out_field_skip (uiout, "addr");
3241 if (b->dll_pathname == NULL)
3243 ui_out_field_string (uiout, "what", "<any library>");
3244 ui_out_spaces (uiout, 1);
3248 ui_out_text (uiout, "library \"");
3249 ui_out_field_string (uiout, "what", b->dll_pathname);
3250 ui_out_text (uiout, "\" ");
3254 if (b->dll_pathname == NULL)
3255 printf_filtered ("<any library> ");
3257 printf_filtered ("library \"%s\" ", b->dll_pathname);
3262 case bp_catch_vfork:
3263 /* Field 4, the address, is omitted (which makes the columns
3264 not line up too nicely with the headers, but the effect
3265 is relatively readable). */
3268 ui_out_field_skip (uiout, "addr");
3270 if (b->forked_inferior_pid != 0)
3272 ui_out_text (uiout, "process ");
3273 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3274 ui_out_spaces (uiout, 1);
3278 if (b->forked_inferior_pid != 0)
3279 printf_filtered ("process %d ", b->forked_inferior_pid);
3284 /* Field 4, the address, is omitted (which makes the columns
3285 not line up too nicely with the headers, but the effect
3286 is relatively readable). */
3289 ui_out_field_skip (uiout, "addr");
3291 if (b->exec_pathname != NULL)
3293 ui_out_text (uiout, "program \"");
3294 ui_out_field_string (uiout, "what", b->exec_pathname);
3295 ui_out_text (uiout, "\" ");
3299 if (b->exec_pathname != NULL)
3300 printf_filtered ("program \"%s\" ", b->exec_pathname);
3304 case bp_catch_catch:
3305 /* Field 4, the address, is omitted (which makes the columns
3306 not line up too nicely with the headers, but the effect
3307 is relatively readable). */
3310 ui_out_field_skip (uiout, "addr");
3312 ui_out_field_string (uiout, "what", "exception catch");
3313 ui_out_spaces (uiout, 1);
3316 printf_filtered ("exception catch ");
3320 case bp_catch_throw:
3321 /* Field 4, the address, is omitted (which makes the columns
3322 not line up too nicely with the headers, but the effect
3323 is relatively readable). */
3326 ui_out_field_skip (uiout, "addr");
3328 ui_out_field_string (uiout, "what", "exception throw");
3329 ui_out_spaces (uiout, 1);
3332 printf_filtered ("exception throw ");
3337 case bp_hardware_breakpoint:
3341 case bp_longjmp_resume:
3342 case bp_step_resume:
3343 case bp_through_sigtramp:
3344 case bp_watchpoint_scope:
3346 case bp_shlib_event:
3347 case bp_thread_event:
3352 ui_out_field_core_addr (uiout, "addr", b->address);
3355 *last_addr = b->address;
3358 sym = find_pc_sect_function (b->address, b->section);
3361 ui_out_text (uiout, "in ");
3362 ui_out_field_string (uiout, "func",
3363 SYMBOL_SOURCE_NAME (sym));
3364 ui_out_wrap_hint (uiout, wrap_indent);
3365 ui_out_text (uiout, " at ");
3367 ui_out_field_string (uiout, "file", b->source_file);
3368 ui_out_text (uiout, ":");
3369 ui_out_field_int (uiout, "line", b->line_number);
3373 print_address_symbolic (b->address, stb->stream, demangle, "");
3374 ui_out_field_stream (uiout, "at", stb);
3380 /* FIXME-32x64: need a print_address_numeric with
3384 local_hex_string_custom
3385 ((unsigned long) b->address, "08l"));
3388 *last_addr = b->address;
3391 sym = find_pc_sect_function (b->address, b->section);
3394 fputs_filtered ("in ", gdb_stdout);
3395 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3396 wrap_here (wrap_indent);
3397 fputs_filtered (" at ", gdb_stdout);
3399 fputs_filtered (b->source_file, gdb_stdout);
3400 printf_filtered (":%d", b->line_number);
3403 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3408 if (b->thread != -1)
3411 /* FIXME: This seems to be redundant and lost here; see the
3412 "stop only in" line a little further down. */
3413 ui_out_text (uiout, " thread ");
3414 ui_out_field_int (uiout, "thread", b->thread);
3416 printf_filtered (" thread %d", b->thread);
3421 ui_out_text (uiout, "\n");
3423 printf_filtered ("\n");
3430 ui_out_text (uiout, "\tstop only in stack frame at ");
3431 ui_out_field_core_addr (uiout, "frame", b->frame);
3432 ui_out_text (uiout, "\n");
3434 printf_filtered ("\tstop only in stack frame at ");
3435 print_address_numeric (b->frame, 1, gdb_stdout);
3436 printf_filtered ("\n");
3444 ui_out_text (uiout, "\tstop only if ");
3445 print_expression (b->cond, stb->stream);
3446 ui_out_field_stream (uiout, "cond", stb);
3447 ui_out_text (uiout, "\n");
3449 printf_filtered ("\tstop only if ");
3450 print_expression (b->cond, gdb_stdout);
3451 printf_filtered ("\n");
3455 if (b->thread != -1)
3457 /* FIXME should make an annotation for this */
3459 ui_out_text (uiout, "\tstop only in thread ");
3460 ui_out_field_int (uiout, "thread", b->thread);
3461 ui_out_text (uiout, "\n");
3463 printf_filtered ("\tstop only in thread %d\n", b->thread);
3467 if (show_breakpoint_hit_counts && b->hit_count)
3469 /* FIXME should make an annotation for this */
3471 if (ep_is_catchpoint (b))
3472 ui_out_text (uiout, "\tcatchpoint");
3474 ui_out_text (uiout, "\tbreakpoint");
3475 ui_out_text (uiout, " already hit ");
3476 ui_out_field_int (uiout, "times", b->hit_count);
3477 if (b->hit_count == 1)
3478 ui_out_text (uiout, " time\n");
3480 ui_out_text (uiout, " times\n");
3482 if (ep_is_catchpoint (b))
3483 printf_filtered ("\tcatchpoint");
3485 printf_filtered ("\tbreakpoint");
3486 printf_filtered (" already hit %d time%s\n",
3487 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3492 /* Output the count also if it is zero, but only if this is
3493 mi. FIXME: Should have a better test for this. */
3494 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3495 if (show_breakpoint_hit_counts && b->hit_count == 0)
3496 ui_out_field_int (uiout, "times", b->hit_count);
3499 if (b->ignore_count)
3503 ui_out_text (uiout, "\tignore next ");
3504 ui_out_field_int (uiout, "ignore", b->ignore_count);
3505 ui_out_text (uiout, " hits\n");
3507 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3511 if ((l = b->commands))
3515 ui_out_list_begin (uiout, "script");
3516 print_command_lines (uiout, l, 4);
3517 ui_out_list_end (uiout);
3521 print_command_line (l, 4, gdb_stdout);
3527 ui_out_list_end (uiout);
3528 do_cleanups (old_chain);
3532 struct captured_breakpoint_query_args
3538 do_captured_breakpoint_query (void *data)
3540 struct captured_breakpoint_query_args *args = data;
3541 register struct breakpoint *b;
3542 CORE_ADDR dummy_addr = 0;
3545 if (args->bnum == b->number)
3547 print_one_breakpoint (b, &dummy_addr);
3555 gdb_breakpoint_query (/* output object, */ int bnum)
3557 struct captured_breakpoint_query_args args;
3559 /* For the moment we don't trust print_one_breakpoint() to not throw
3561 return catch_errors (do_captured_breakpoint_query, &args,
3562 NULL, RETURN_MASK_ALL);
3565 /* Print information on breakpoint number BNUM, or -1 if all.
3566 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3567 is nonzero, process only watchpoints. */
3570 breakpoint_1 (bnum, allflag)
3574 register struct breakpoint *b;
3575 CORE_ADDR last_addr = (CORE_ADDR) -1;
3576 int found_a_breakpoint = 0;
3580 ui_out_table_begin (uiout, 6, "BreakpointTable");
3582 ui_out_table_begin (uiout, 5, "BreakpointTable");
3587 || bnum == b->number)
3589 /* We only print out user settable breakpoints unless the
3592 && b->type != bp_breakpoint
3593 && b->type != bp_catch_load
3594 && b->type != bp_catch_unload
3595 && b->type != bp_catch_fork
3596 && b->type != bp_catch_vfork
3597 && b->type != bp_catch_exec
3598 && b->type != bp_catch_catch
3599 && b->type != bp_catch_throw
3600 && b->type != bp_hardware_breakpoint
3601 && b->type != bp_watchpoint
3602 && b->type != bp_read_watchpoint
3603 && b->type != bp_access_watchpoint
3604 && b->type != bp_hardware_watchpoint)
3607 if (!found_a_breakpoint++)
3609 annotate_breakpoints_headers ();
3612 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3614 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3616 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3618 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3622 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3625 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3626 ui_out_table_body (uiout);
3629 printf_filtered ("Num ");
3631 printf_filtered ("Type ");
3633 printf_filtered ("Disp ");
3635 printf_filtered ("Enb ");
3639 printf_filtered ("Address ");
3642 printf_filtered ("What\n");
3644 annotate_breakpoints_table ();
3647 print_one_breakpoint (b, &last_addr);
3650 if (!found_a_breakpoint)
3654 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3656 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3660 printf_filtered ("No breakpoints or watchpoints.\n");
3662 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3667 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3668 that a comparison of an unsigned with -1 is always false. */
3669 if (last_addr != (CORE_ADDR) -1)
3670 set_next_address (last_addr);
3674 ui_out_table_end (uiout);
3676 /* FIXME? Should this be moved up so that it is only called when
3677 there have been breakpoints? */
3678 annotate_breakpoints_table_end ();
3683 breakpoints_info (bnum_exp, from_tty)
3690 bnum = parse_and_eval_address (bnum_exp);
3692 breakpoint_1 (bnum, 0);
3697 maintenance_info_breakpoints (bnum_exp, from_tty)
3704 bnum = parse_and_eval_address (bnum_exp);
3706 breakpoint_1 (bnum, 1);
3709 /* Print a message describing any breakpoints set at PC. */
3712 describe_other_breakpoints (pc, section)
3716 register int others = 0;
3717 register struct breakpoint *b;
3720 if (b->address == pc)
3721 if (overlay_debugging == 0 ||
3722 b->section == section)
3726 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3728 if (b->address == pc)
3729 if (overlay_debugging == 0 ||
3730 b->section == section)
3736 ((b->enable == disabled ||
3737 b->enable == shlib_disabled ||
3738 b->enable == call_disabled) ? " (disabled)"
3739 : b->enable == permanent ? " (permanent)"
3741 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3743 printf_filtered ("also set at pc ");
3744 print_address_numeric (pc, 1, gdb_stdout);
3745 printf_filtered (".\n");
3749 /* Set the default place to put a breakpoint
3750 for the `break' command with no arguments. */
3753 set_default_breakpoint (valid, addr, symtab, line)
3756 struct symtab *symtab;
3759 default_breakpoint_valid = valid;
3760 default_breakpoint_address = addr;
3761 default_breakpoint_symtab = symtab;
3762 default_breakpoint_line = line;
3765 /* Rescan breakpoints at address ADDRESS,
3766 marking the first one as "first" and any others as "duplicates".
3767 This is so that the bpt instruction is only inserted once.
3768 If we have a permanent breakpoint at ADDRESS, make that one
3769 the official one, and the rest as duplicates. */
3772 check_duplicates (address, section)
3776 register struct breakpoint *b;
3777 register int count = 0;
3778 struct breakpoint *perm_bp = 0;
3780 if (address == 0) /* Watchpoints are uninteresting */
3784 if (b->enable != disabled
3785 && b->enable != shlib_disabled
3786 && b->enable != call_disabled
3787 && b->address == address
3788 && (overlay_debugging == 0 || b->section == section))
3790 /* Have we found a permanent breakpoint? */
3791 if (b->enable == permanent)
3798 b->duplicate = count > 1;
3801 /* If we found a permanent breakpoint at this address, go over the
3802 list again and declare all the other breakpoints there to be the
3806 perm_bp->duplicate = 0;
3808 /* Permanent breakpoint should always be inserted. */
3809 if (! perm_bp->inserted)
3810 internal_error ("allegedly permanent breakpoint is not "
3811 "actually inserted");
3817 internal_error ("another breakpoint was inserted on top of "
3818 "a permanent breakpoint");
3820 if (b->enable != disabled
3821 && b->enable != shlib_disabled
3822 && b->enable != call_disabled
3823 && b->address == address
3824 && (overlay_debugging == 0 || b->section == section))
3830 /* Low level routine to set a breakpoint.
3831 Takes as args the three things that every breakpoint must have.
3832 Returns the breakpoint object so caller can set other things.
3833 Does not set the breakpoint number!
3834 Does not print anything.
3836 ==> This routine should not be called if there is a chance of later
3837 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3838 your arguments BEFORE calling this routine! */
3841 set_raw_breakpoint (sal)
3842 struct symtab_and_line sal;
3844 register struct breakpoint *b, *b1;
3846 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3847 memset (b, 0, sizeof (*b));
3848 b->address = sal.pc;
3849 if (sal.symtab == NULL)
3850 b->source_file = NULL;
3852 b->source_file = savestring (sal.symtab->filename,
3853 strlen (sal.symtab->filename));
3854 b->section = sal.section;
3855 b->language = current_language->la_language;
3856 b->input_radix = input_radix;
3858 b->line_number = sal.line;
3859 b->enable = enabled;
3862 b->ignore_count = 0;
3865 b->dll_pathname = NULL;
3866 b->triggered_dll_pathname = NULL;
3867 b->forked_inferior_pid = 0;
3868 b->exec_pathname = NULL;
3870 /* Add this breakpoint to the end of the chain
3871 so that a list of breakpoints will come out in order
3872 of increasing numbers. */
3874 b1 = breakpoint_chain;
3876 breakpoint_chain = b;
3884 check_duplicates (sal.pc, sal.section);
3885 breakpoints_changed ();
3891 /* Note that the breakpoint object B describes a permanent breakpoint
3892 instruction, hard-wired into the inferior's code. */
3894 make_breakpoint_permanent (struct breakpoint *b)
3896 b->enable = permanent;
3898 /* By definition, permanent breakpoints are already present in the code. */
3902 #ifdef GET_LONGJMP_TARGET
3905 create_longjmp_breakpoint (func_name)
3908 struct symtab_and_line sal;
3909 struct breakpoint *b;
3911 INIT_SAL (&sal); /* initialize to zeroes */
3912 if (func_name != NULL)
3914 struct minimal_symbol *m;
3916 m = lookup_minimal_symbol_text (func_name, NULL,
3917 (struct objfile *) NULL);
3919 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3923 sal.section = find_pc_overlay (sal.pc);
3924 b = set_raw_breakpoint (sal);
3928 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3929 b->disposition = donttouch;
3930 b->enable = disabled;
3933 b->addr_string = strsave (func_name);
3934 b->number = internal_breakpoint_number--;
3937 #endif /* #ifdef GET_LONGJMP_TARGET */
3939 /* Call this routine when stepping and nexting to enable a breakpoint
3940 if we do a longjmp(). When we hit that breakpoint, call
3941 set_longjmp_resume_breakpoint() to figure out where we are going. */
3944 enable_longjmp_breakpoint ()
3946 register struct breakpoint *b;
3949 if (b->type == bp_longjmp)
3951 b->enable = enabled;
3952 check_duplicates (b->address, b->section);
3957 disable_longjmp_breakpoint ()
3959 register struct breakpoint *b;
3962 if (b->type == bp_longjmp
3963 || b->type == bp_longjmp_resume)
3965 b->enable = disabled;
3966 check_duplicates (b->address, b->section);
3971 create_thread_event_breakpoint (address)
3974 struct breakpoint *b;
3975 struct symtab_and_line sal;
3976 char addr_string[80]; /* Surely an addr can't be longer than that. */
3978 INIT_SAL (&sal); /* initialize to zeroes */
3980 sal.section = find_pc_overlay (sal.pc);
3981 if ((b = set_raw_breakpoint (sal)) == NULL)
3984 b->number = internal_breakpoint_number--;
3985 b->disposition = donttouch;
3986 b->type = bp_thread_event; /* XXX: do we need a new type?
3988 b->enable = enabled;
3989 /* addr_string has to be used or breakpoint_re_set will delete me. */
3990 sprintf (addr_string, "*0x%s", paddr (b->address));
3991 b->addr_string = strsave (addr_string);
3997 remove_thread_event_breakpoints (void)
3999 struct breakpoint *b, *temp;
4001 ALL_BREAKPOINTS_SAFE (b, temp)
4002 if (b->type == bp_thread_event)
4003 delete_breakpoint (b);
4008 remove_solib_event_breakpoints ()
4010 register struct breakpoint *b, *temp;
4012 ALL_BREAKPOINTS_SAFE (b, temp)
4013 if (b->type == bp_shlib_event)
4014 delete_breakpoint (b);
4018 create_solib_event_breakpoint (address)
4021 struct breakpoint *b;
4022 struct symtab_and_line sal;
4024 INIT_SAL (&sal); /* initialize to zeroes */
4026 sal.section = find_pc_overlay (sal.pc);
4027 b = set_raw_breakpoint (sal);
4028 b->number = internal_breakpoint_number--;
4029 b->disposition = donttouch;
4030 b->type = bp_shlib_event;
4035 /* Disable any breakpoints that are on code in shared libraries. Only
4036 apply to enabled breakpoints, disabled ones can just stay disabled. */
4039 disable_breakpoints_in_shlibs (silent)
4042 struct breakpoint *b;
4043 int disabled_shlib_breaks = 0;
4045 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4048 #if defined (PC_SOLIB)
4049 if (((b->type == bp_breakpoint) ||
4050 (b->type == bp_hardware_breakpoint)) &&
4051 b->enable == enabled &&
4053 PC_SOLIB (b->address))
4055 b->enable = shlib_disabled;
4058 if (!disabled_shlib_breaks)
4060 target_terminal_ours_for_output ();
4061 warning ("Temporarily disabling shared library breakpoints:");
4063 disabled_shlib_breaks = 1;
4064 warning ("breakpoint #%d ", b->number);
4071 /* Try to reenable any breakpoints in shared libraries. */
4073 re_enable_breakpoints_in_shlibs ()
4075 struct breakpoint *b;
4078 if (b->enable == shlib_disabled)
4082 /* Do not reenable the breakpoint if the shared library
4083 is still not mapped in. */
4084 if (target_read_memory (b->address, buf, 1) == 0)
4085 b->enable = enabled;
4092 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
4097 enum bptype bp_kind;
4099 struct breakpoint *b;
4100 struct symtabs_and_lines sals;
4101 struct cleanup *old_chain;
4102 struct cleanup *canonical_strings_chain = NULL;
4103 char *addr_start = hookname;
4104 char *addr_end = NULL;
4105 char **canonical = (char **) NULL;
4106 int thread = -1; /* All threads. */
4108 /* Set a breakpoint on the specified hook. */
4109 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4110 addr_end = hookname;
4112 if (sals.nelts == 0)
4114 warning ("Unable to set a breakpoint on dynamic linker callback.");
4115 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4116 warning ("GDB will be unable to track shl_load/shl_unload calls");
4119 if (sals.nelts != 1)
4121 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4122 warning ("GDB will be unable to track shl_load/shl_unload calls");
4126 /* Make sure that all storage allocated in decode_line_1 gets freed
4127 in case the following errors out. */
4128 old_chain = make_cleanup (free, sals.sals);
4129 if (canonical != (char **) NULL)
4131 make_cleanup (free, canonical);
4132 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4133 if (canonical[0] != NULL)
4134 make_cleanup (free, canonical[0]);
4137 resolve_sal_pc (&sals.sals[0]);
4139 /* Remove the canonical strings from the cleanup, they are needed below. */
4140 if (canonical != (char **) NULL)
4141 discard_cleanups (canonical_strings_chain);
4143 b = set_raw_breakpoint (sals.sals[0]);
4144 set_breakpoint_count (breakpoint_count + 1);
4145 b->number = breakpoint_count;
4147 b->cond_string = (cond_string == NULL) ?
4148 NULL : savestring (cond_string, strlen (cond_string));
4151 if (canonical != (char **) NULL && canonical[0] != NULL)
4152 b->addr_string = canonical[0];
4153 else if (addr_start)
4154 b->addr_string = savestring (addr_start, addr_end - addr_start);
4156 b->enable = enabled;
4157 b->disposition = tempflag ? del : donttouch;
4159 if (dll_pathname == NULL)
4160 b->dll_pathname = NULL;
4163 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4164 strcpy (b->dll_pathname, dll_pathname);
4169 do_cleanups (old_chain);
4173 create_solib_load_event_breakpoint (hookname, tempflag,
4174 dll_pathname, cond_string)
4180 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4181 cond_string, bp_catch_load);
4185 create_solib_unload_event_breakpoint (hookname, tempflag,
4186 dll_pathname, cond_string)
4192 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4193 cond_string, bp_catch_unload);
4197 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
4200 enum bptype bp_kind;
4202 struct symtab_and_line sal;
4203 struct breakpoint *b;
4204 int thread = -1; /* All threads. */
4211 b = set_raw_breakpoint (sal);
4212 set_breakpoint_count (breakpoint_count + 1);
4213 b->number = breakpoint_count;
4215 b->cond_string = (cond_string == NULL) ?
4216 NULL : savestring (cond_string, strlen (cond_string));
4218 b->addr_string = NULL;
4219 b->enable = enabled;
4220 b->disposition = tempflag ? del : donttouch;
4221 b->forked_inferior_pid = 0;
4229 create_fork_event_catchpoint (tempflag, cond_string)
4233 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4237 create_vfork_event_catchpoint (tempflag, cond_string)
4241 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4245 create_exec_event_catchpoint (tempflag, cond_string)
4249 struct symtab_and_line sal;
4250 struct breakpoint *b;
4251 int thread = -1; /* All threads. */
4258 b = set_raw_breakpoint (sal);
4259 set_breakpoint_count (breakpoint_count + 1);
4260 b->number = breakpoint_count;
4262 b->cond_string = (cond_string == NULL) ?
4263 NULL : savestring (cond_string, strlen (cond_string));
4265 b->addr_string = NULL;
4266 b->enable = enabled;
4267 b->disposition = tempflag ? del : donttouch;
4269 b->type = bp_catch_exec;
4275 hw_breakpoint_used_count ()
4277 register struct breakpoint *b;
4282 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4290 hw_watchpoint_used_count (type, other_type_used)
4292 int *other_type_used;
4294 register struct breakpoint *b;
4297 *other_type_used = 0;
4300 if (b->enable == enabled)
4302 if (b->type == type)
4304 else if ((b->type == bp_hardware_watchpoint ||
4305 b->type == bp_read_watchpoint ||
4306 b->type == bp_access_watchpoint)
4307 && b->enable == enabled)
4308 *other_type_used = 1;
4314 /* Call this after hitting the longjmp() breakpoint. Use this to set
4315 a new breakpoint at the target of the jmp_buf.
4317 FIXME - This ought to be done by setting a temporary breakpoint
4318 that gets deleted automatically... */
4321 set_longjmp_resume_breakpoint (pc, frame)
4323 struct frame_info *frame;
4325 register struct breakpoint *b;
4328 if (b->type == bp_longjmp_resume)
4331 b->enable = enabled;
4333 b->frame = frame->frame;
4336 check_duplicates (b->address, b->section);
4342 disable_watchpoints_before_interactive_call_start ()
4344 struct breakpoint *b;
4348 if (((b->type == bp_watchpoint)
4349 || (b->type == bp_hardware_watchpoint)
4350 || (b->type == bp_read_watchpoint)
4351 || (b->type == bp_access_watchpoint)
4352 || ep_is_exception_catchpoint (b))
4353 && (b->enable == enabled))
4355 b->enable = call_disabled;
4356 check_duplicates (b->address, b->section);
4362 enable_watchpoints_after_interactive_call_stop ()
4364 struct breakpoint *b;
4368 if (((b->type == bp_watchpoint)
4369 || (b->type == bp_hardware_watchpoint)
4370 || (b->type == bp_read_watchpoint)
4371 || (b->type == bp_access_watchpoint)
4372 || ep_is_exception_catchpoint (b))
4373 && (b->enable == call_disabled))
4375 b->enable = enabled;
4376 check_duplicates (b->address, b->section);
4382 /* Set a breakpoint that will evaporate an end of command
4383 at address specified by SAL.
4384 Restrict it to frame FRAME if FRAME is nonzero. */
4387 set_momentary_breakpoint (sal, frame, type)
4388 struct symtab_and_line sal;
4389 struct frame_info *frame;
4392 register struct breakpoint *b;
4393 b = set_raw_breakpoint (sal);
4395 b->enable = enabled;
4396 b->disposition = donttouch;
4397 b->frame = (frame ? frame->frame : 0);
4399 /* If we're debugging a multi-threaded program, then we
4400 want momentary breakpoints to be active in only a
4401 single thread of control. */
4402 if (in_thread_list (inferior_pid))
4403 b->thread = pid_to_thread_id (inferior_pid);
4409 /* Tell the user we have just set a breakpoint B. */
4413 struct breakpoint *b;
4417 struct cleanup *old_chain;
4418 struct ui_stream *stb;
4420 stb = ui_out_stream_new (uiout);
4421 old_chain = make_cleanup_ui_out_stream_delete (stb);
4424 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4425 watchpoint) other than breakpoint creation. It should be possible to
4426 clean this up and at the same time replace the random calls to
4427 breakpoint_changed with this hook, as has already been done for
4428 delete_breakpoint_hook and so on. */
4429 if (create_breakpoint_hook)
4430 create_breakpoint_hook (b);
4431 breakpoint_create_event (b->number);
4436 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4440 ui_out_text (uiout, "Watchpoint ");
4441 ui_out_list_begin (uiout, "wpt");
4442 ui_out_field_int (uiout, "number", b->number);
4443 ui_out_text (uiout, ": ");
4444 print_expression (b->exp, stb->stream);
4445 ui_out_field_stream (uiout, "exp", stb);
4446 ui_out_list_end (uiout);
4448 case bp_hardware_watchpoint:
4449 ui_out_text (uiout, "Hardware watchpoint ");
4450 ui_out_list_begin (uiout, "wpt");
4451 ui_out_field_int (uiout, "number", b->number);
4452 ui_out_text (uiout, ": ");
4453 print_expression (b->exp, stb->stream);
4454 ui_out_field_stream (uiout, "exp", stb);
4455 ui_out_list_end (uiout);
4459 printf_filtered ("Watchpoint %d: ", b->number);
4460 print_expression (b->exp, gdb_stdout);
4462 case bp_hardware_watchpoint:
4463 printf_filtered ("Hardware watchpoint %d: ", b->number);
4464 print_expression (b->exp, gdb_stdout);
4468 case bp_read_watchpoint:
4469 ui_out_text (uiout, "Hardware read watchpoint ");
4470 ui_out_list_begin (uiout, "hw-rwpt");
4471 ui_out_field_int (uiout, "number", b->number);
4472 ui_out_text (uiout, ": ");
4473 print_expression (b->exp, stb->stream);
4474 ui_out_field_stream (uiout, "exp", stb);
4475 ui_out_list_end (uiout);
4477 case bp_access_watchpoint:
4478 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4479 ui_out_list_begin (uiout, "hw-awpt");
4480 ui_out_field_int (uiout, "number", b->number);
4481 ui_out_text (uiout, ": ");
4482 print_expression (b->exp, stb->stream);
4483 ui_out_field_stream (uiout, "exp", stb);
4484 ui_out_list_end (uiout);
4487 case bp_read_watchpoint:
4488 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4489 print_expression (b->exp, gdb_stdout);
4491 case bp_access_watchpoint:
4492 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4494 print_expression (b->exp, gdb_stdout);
4499 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4505 printf_filtered ("Breakpoint %d", b->number);
4508 case bp_hardware_breakpoint:
4510 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4516 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4520 case bp_catch_unload:
4521 printf_filtered ("Catchpoint %d (%s %s)",
4523 (b->type == bp_catch_load) ? "load" : "unload",
4524 (b->dll_pathname != NULL) ?
4525 b->dll_pathname : "<any library>");
4528 case bp_catch_vfork:
4529 printf_filtered ("Catchpoint %d (%s)",
4531 (b->type == bp_catch_fork) ? "fork" : "vfork");
4534 printf_filtered ("Catchpoint %d (exec)",
4537 case bp_catch_catch:
4538 case bp_catch_throw:
4539 printf_filtered ("Catchpoint %d (%s)",
4541 (b->type == bp_catch_catch) ? "catch" : "throw");
4547 case bp_longjmp_resume:
4548 case bp_step_resume:
4549 case bp_through_sigtramp:
4551 case bp_watchpoint_scope:
4552 case bp_shlib_event:
4553 case bp_thread_event:
4558 if (addressprint || b->source_file == NULL)
4560 printf_filtered (" at ");
4561 print_address_numeric (b->address, 1, gdb_stdout);
4564 printf_filtered (": file %s, line %d.",
4565 b->source_file, b->line_number);
4566 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4567 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4570 do_cleanups (old_chain);
4573 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4576 printf_filtered ("\n");
4580 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4581 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4582 COND[i] and COND_STRING[i] values.
4584 NOTE: If the function succeeds, the caller is expected to cleanup
4585 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4586 array contents). If the function fails (error() is called), the
4587 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4588 COND and SALS arrays and each of those arrays contents. */
4591 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4592 struct expression **cond, char **cond_string,
4593 enum bptype type, enum bpdisp disposition,
4594 int thread, int ignore_count, int from_tty)
4596 if (type == bp_hardware_breakpoint)
4598 int i = hw_breakpoint_used_count ();
4599 int target_resources_ok =
4600 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4602 if (target_resources_ok == 0)
4603 error ("No hardware breakpoint support in the target.");
4604 else if (target_resources_ok < 0)
4605 error ("Hardware breakpoints used exceeds limit.");
4608 /* Now set all the breakpoints. */
4611 for (i = 0; i < sals.nelts; i++)
4613 struct breakpoint *b;
4614 struct symtab_and_line sal = sals.sals[i];
4617 describe_other_breakpoints (sal.pc, sal.section);
4619 b = set_raw_breakpoint (sal);
4620 set_breakpoint_count (breakpoint_count + 1);
4621 b->number = breakpoint_count;
4625 b->addr_string = addr_string[i];
4626 b->cond_string = cond_string[i];
4627 b->ignore_count = ignore_count;
4628 b->enable = enabled;
4629 b->disposition = disposition;
4635 /* Parse ARG which is assumed to be a SAL specification possibly
4636 followed by conditionals. On return, SALS contains an array of SAL
4637 addresses found. ADDR_STRING contains a vector of (canonical)
4638 address strings. ARG points to the end of the SAL. */
4641 parse_breakpoint_sals (char **address,
4642 struct symtabs_and_lines *sals,
4643 char ***addr_string)
4645 char *addr_start = *address;
4646 *addr_string = NULL;
4647 /* If no arg given, or if first arg is 'if ', use the default
4649 if ((*address) == NULL
4650 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4652 if (default_breakpoint_valid)
4654 struct symtab_and_line sal;
4655 INIT_SAL (&sal); /* initialize to zeroes */
4656 sals->sals = (struct symtab_and_line *)
4657 xmalloc (sizeof (struct symtab_and_line));
4658 sal.pc = default_breakpoint_address;
4659 sal.line = default_breakpoint_line;
4660 sal.symtab = default_breakpoint_symtab;
4661 sal.section = find_pc_overlay (sal.pc);
4662 sals->sals[0] = sal;
4666 error ("No default breakpoint address now.");
4670 /* Force almost all breakpoints to be in terms of the
4671 current_source_symtab (which is decode_line_1's default). This
4672 should produce the results we want almost all of the time while
4673 leaving default_breakpoint_* alone. */
4674 if (default_breakpoint_valid
4675 && (!current_source_symtab
4676 || (strchr ("+-", (*address)[0]) != NULL)))
4677 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4678 default_breakpoint_line, addr_string);
4680 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4682 /* For any SAL that didn't have a canonical string, fill one in. */
4683 if (sals->nelts > 0 && *addr_string == NULL)
4684 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4685 if (addr_start != (*address))
4688 for (i = 0; i < sals->nelts; i++)
4690 /* Add the string if not present. */
4691 if ((*addr_string)[i] == NULL)
4692 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4698 /* Convert each SAL into a real PC. Verify that the PC can be
4699 inserted as a breakpoint. If it can't throw an error. */
4702 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4706 for (i = 0; i < sals->nelts; i++)
4708 resolve_sal_pc (&sals->sals[i]);
4710 /* It's possible for the PC to be nonzero, but still an illegal
4711 value on some targets.
4713 For example, on HP-UX if you start gdb, and before running the
4714 inferior you try to set a breakpoint on a shared library function
4715 "foo" where the inferior doesn't call "foo" directly but does
4716 pass its address to another function call, then we do find a
4717 minimal symbol for the "foo", but it's address is invalid.
4718 (Appears to be an index into a table that the loader sets up
4719 when the inferior is run.)
4721 Give the target a chance to bless sals.sals[i].pc before we
4722 try to make a breakpoint for it. */
4723 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4725 if (address == NULL)
4726 error ("Cannot break without a running program.");
4728 error ("Cannot break on %s without a running program.",
4734 /* Set a breakpoint according to ARG (function, linenum or *address)
4735 flag: first bit : 0 non-temporary, 1 temporary.
4736 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4739 break_command_1 (arg, flag, from_tty)
4743 int tempflag, hardwareflag;
4744 struct symtabs_and_lines sals;
4745 register struct expression **cond = 0;
4746 /* Pointers in arg to the start, and one past the end, of the
4748 char **cond_string = (char **) NULL;
4749 char *addr_start = arg;
4751 struct cleanup *old_chain;
4752 struct cleanup *breakpoint_chain = NULL;
4755 int ignore_count = 0;
4757 hardwareflag = flag & BP_HARDWAREFLAG;
4758 tempflag = flag & BP_TEMPFLAG;
4763 parse_breakpoint_sals (&arg, &sals, &addr_string);
4768 /* Create a chain of things that always need to be cleaned up. */
4769 old_chain = make_cleanup (null_cleanup, 0);
4771 /* Make sure that all storage allocated to SALS gets freed. */
4772 make_cleanup (free, sals.sals);
4774 /* Cleanup the addr_string array but not its contents. */
4775 make_cleanup (free, addr_string);
4777 /* Allocate space for all the cond expressions. */
4778 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4779 make_cleanup (free, cond);
4781 /* Allocate space for all the cond strings. */
4782 cond_string = xcalloc (sals.nelts, sizeof (char **));
4783 make_cleanup (free, cond_string);
4785 /* ----------------------------- SNIP -----------------------------
4786 Anything added to the cleanup chain beyond this point is assumed
4787 to be part of a breakpoint. If the breakpoint create succeeds
4788 then the memory is not reclaimed. */
4789 breakpoint_chain = make_cleanup (null_cleanup, 0);
4791 /* Mark the contents of the addr_string for cleanup. These go on
4792 the breakpoint_chain and only occure if the breakpoint create
4794 for (i = 0; i < sals.nelts; i++)
4796 if (addr_string[i] != NULL)
4797 make_cleanup (free, addr_string[i]);
4800 /* Resolve all line numbers to PC's and verify that the addresses
4801 are ok for the target. */
4802 breakpoint_sals_to_pc (&sals, addr_start);
4804 /* Verify that condition can be parsed, before setting any
4805 breakpoints. Allocate a separate condition expression for each
4807 thread = -1; /* No specific thread yet */
4808 for (i = 0; i < sals.nelts; i++)
4815 char *cond_start = NULL;
4816 char *cond_end = NULL;
4817 while (*tok == ' ' || *tok == '\t')
4822 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4825 toklen = end_tok - tok;
4827 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4829 tok = cond_start = end_tok + 1;
4830 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4831 make_cleanup (free, cond[i]);
4833 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4834 make_cleanup (free, cond_string[i]);
4836 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4842 thread = strtol (tok, &tok, 0);
4844 error ("Junk after thread keyword.");
4845 if (!valid_thread_id (thread))
4846 error ("Unknown thread %d\n", thread);
4849 error ("Junk at end of arguments.");
4853 create_breakpoints (sals, addr_string, cond, cond_string,
4854 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4855 tempflag ? del : donttouch,
4856 thread, ignore_count, from_tty);
4860 warning ("Multiple breakpoints were set.");
4861 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4863 /* That's it. Discard the cleanups for data inserted into the
4865 discard_cleanups (breakpoint_chain);
4866 /* But cleanup everything else. */
4867 do_cleanups (old_chain);
4870 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4871 linenum or *address) with COND and IGNORE_COUNT. */
4873 struct captured_breakpoint_args
4884 do_captured_breakpoint (void *data)
4886 struct captured_breakpoint_args *args = data;
4887 struct symtabs_and_lines sals;
4888 register struct expression **cond;
4889 struct cleanup *old_chain;
4890 struct cleanup *breakpoint_chain = NULL;
4897 /* Parse the source and lines spec. Delay check that the expression
4898 didn't contain trailing garbage until after cleanups are in
4902 address_end = args->address;
4904 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4909 /* Create a chain of things at always need to be cleaned up. */
4910 old_chain = make_cleanup (null_cleanup, 0);
4912 /* Always have a addr_string array, even if it is empty. */
4913 make_cleanup (free, addr_string);
4915 /* Make sure that all storage allocated to SALS gets freed. */
4916 make_cleanup (free, sals.sals);
4918 /* Allocate space for all the cond expressions. */
4919 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4920 make_cleanup (free, cond);
4922 /* Allocate space for all the cond strings. */
4923 cond_string = xcalloc (sals.nelts, sizeof (char **));
4924 make_cleanup (free, cond_string);
4926 /* ----------------------------- SNIP -----------------------------
4927 Anything added to the cleanup chain beyond this point is assumed
4928 to be part of a breakpoint. If the breakpoint create goes
4929 through then that memory is not cleaned up. */
4930 breakpoint_chain = make_cleanup (null_cleanup, 0);
4932 /* Mark the contents of the addr_string for cleanup. These go on
4933 the breakpoint_chain and only occure if the breakpoint create
4935 for (i = 0; i < sals.nelts; i++)
4937 if (addr_string[i] != NULL)
4938 make_cleanup (free, addr_string[i]);
4941 /* Wait until now before checking for garbage at the end of the
4942 address. That way cleanups can take care of freeing any
4944 if (*address_end != '\0')
4945 error ("Garbage %s following breakpoint address", address_end);
4947 /* Resolve all line numbers to PC's. */
4948 breakpoint_sals_to_pc (&sals, args->address);
4950 /* Verify that conditions can be parsed, before setting any
4952 for (i = 0; i < sals.nelts; i++)
4954 if (args->condition != NULL)
4956 char *tok = args->condition;
4957 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4959 error ("Garbage %s follows condition", tok);
4960 make_cleanup (free, cond[i]);
4961 cond_string[i] = xstrdup (args->condition);
4965 create_breakpoints (sals, addr_string, cond, cond_string,
4966 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4967 args->tempflag ? del : donttouch,
4968 args->thread, args->ignore_count, 0/*from-tty*/);
4970 /* That's it. Discard the cleanups for data inserted into the
4972 discard_cleanups (breakpoint_chain);
4973 /* But cleanup everything else. */
4974 do_cleanups (old_chain);
4979 gdb_breakpoint (char *address, char *condition,
4980 int hardwareflag, int tempflag,
4981 int thread, int ignore_count)
4983 struct captured_breakpoint_args args;
4984 args.address = address;
4985 args.condition = condition;
4986 args.hardwareflag = hardwareflag;
4987 args.tempflag = tempflag;
4988 args.thread = thread;
4989 args.ignore_count = ignore_count;
4990 return catch_errors (do_captured_breakpoint, &args,
4991 NULL, RETURN_MASK_ALL);
4996 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
5001 struct frame_info *frame;
5002 CORE_ADDR low, high, selected_pc = 0;
5003 char *extra_args, *level_arg, *addr_string;
5004 int extra_args_len = 0, if_arg = 0;
5007 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5010 if (default_breakpoint_valid)
5014 selected_pc = selected_frame->pc;
5019 error ("No selected frame.");
5022 error ("No default breakpoint address now.");
5026 extra_args = strchr (arg, ' ');
5030 extra_args_len = strlen (extra_args);
5031 level_arg = (char *) xmalloc (extra_args - arg);
5032 strncpy (level_arg, arg, extra_args - arg - 1);
5033 level_arg[extra_args - arg - 1] = '\0';
5037 level_arg = (char *) xmalloc (strlen (arg) + 1);
5038 strcpy (level_arg, arg);
5041 frame = parse_frame_specification (level_arg);
5043 selected_pc = frame->pc;
5050 extra_args_len = strlen (arg);
5055 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5057 addr_string = (char *) xmalloc (26 + extra_args_len);
5059 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
5061 sprintf (addr_string, "*0x%s", paddr_nz (high));
5062 break_command_1 (addr_string, flag, from_tty);
5066 error ("No function contains the specified address");
5069 error ("Unable to set breakpoint at procedure exit");
5074 break_at_finish_command_1 (arg, flag, from_tty)
5079 char *addr_string, *break_string, *beg_addr_string;
5080 CORE_ADDR low, high;
5081 struct symtabs_and_lines sals;
5082 struct symtab_and_line sal;
5083 struct cleanup *old_chain;
5085 int extra_args_len = 0;
5089 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5091 if (default_breakpoint_valid)
5095 addr_string = (char *) xmalloc (15);
5096 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5101 error ("No selected frame.");
5104 error ("No default breakpoint address now.");
5108 addr_string = (char *) xmalloc (strlen (arg) + 1);
5109 strcpy (addr_string, arg);
5115 extra_args_len = strlen (arg);
5119 /* get the stuff after the function name or address */
5120 extra_args = strchr (arg, ' ');
5124 extra_args_len = strlen (extra_args);
5131 beg_addr_string = addr_string;
5132 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5135 free (beg_addr_string);
5136 old_chain = make_cleanup (free, sals.sals);
5137 for (i = 0; (i < sals.nelts); i++)
5140 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5142 break_string = (char *) xmalloc (extra_args_len + 26);
5144 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5146 sprintf (break_string, "*0x%s", paddr_nz (high));
5147 break_command_1 (break_string, flag, from_tty);
5148 free (break_string);
5151 error ("No function contains the specified address");
5155 warning ("Multiple breakpoints were set.\n");
5156 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5158 do_cleanups (old_chain);
5162 /* Helper function for break_command_1 and disassemble_command. */
5165 resolve_sal_pc (sal)
5166 struct symtab_and_line *sal;
5170 if (sal->pc == 0 && sal->symtab != NULL)
5172 if (!find_line_pc (sal->symtab, sal->line, &pc))
5173 error ("No line %d in file \"%s\".",
5174 sal->line, sal->symtab->filename);
5178 if (sal->section == 0 && sal->symtab != NULL)
5180 struct blockvector *bv;
5185 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5188 b = BLOCKVECTOR_BLOCK (bv, index);
5189 sym = block_function (b);
5192 fixup_symbol_section (sym, sal->symtab->objfile);
5193 sal->section = SYMBOL_BFD_SECTION (sym);
5197 /* It really is worthwhile to have the section, so we'll just
5198 have to look harder. This case can be executed if we have
5199 line numbers but no functions (as can happen in assembly
5202 struct minimal_symbol *msym;
5204 msym = lookup_minimal_symbol_by_pc (sal->pc);
5206 sal->section = SYMBOL_BFD_SECTION (msym);
5213 break_command (arg, from_tty)
5217 break_command_1 (arg, 0, from_tty);
5221 break_at_finish_command (arg, from_tty)
5225 break_at_finish_command_1 (arg, 0, from_tty);
5229 break_at_finish_at_depth_command (arg, from_tty)
5233 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5237 tbreak_command (arg, from_tty)
5241 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5245 tbreak_at_finish_command (arg, from_tty)
5249 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5253 hbreak_command (arg, from_tty)
5257 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5261 thbreak_command (arg, from_tty)
5265 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5269 stop_command (arg, from_tty)
5273 printf_filtered ("Specify the type of breakpoint to set.\n\
5274 Usage: stop in <function | address>\n\
5279 stopin_command (arg, from_tty)
5285 if (arg == (char *) NULL)
5287 else if (*arg != '*')
5292 /* look for a ':'. If this is a line number specification, then
5293 say it is bad, otherwise, it should be an address or
5294 function/method name */
5295 while (*argptr && !hasColon)
5297 hasColon = (*argptr == ':');
5302 badInput = (*argptr != ':'); /* Not a class::method */
5304 badInput = isdigit (*arg); /* a simple line number */
5308 printf_filtered ("Usage: stop in <function | address>\n");
5310 break_command_1 (arg, 0, from_tty);
5314 stopat_command (arg, from_tty)
5320 if (arg == (char *) NULL || *arg == '*') /* no line number */
5327 /* look for a ':'. If there is a '::' then get out, otherwise
5328 it is probably a line number. */
5329 while (*argptr && !hasColon)
5331 hasColon = (*argptr == ':');
5336 badInput = (*argptr == ':'); /* we have class::method */
5338 badInput = !isdigit (*arg); /* not a line number */
5342 printf_filtered ("Usage: stop at <line>\n");
5344 break_command_1 (arg, 0, from_tty);
5348 /* accessflag: hw_write: watch write,
5349 hw_read: watch read,
5350 hw_access: watch access (read or write) */
5352 watch_command_1 (arg, accessflag, from_tty)
5357 struct breakpoint *b;
5358 struct symtab_and_line sal;
5359 struct expression *exp;
5360 struct block *exp_valid_block;
5361 struct value *val, *mark;
5362 struct frame_info *frame;
5363 struct frame_info *prev_frame = NULL;
5364 char *exp_start = NULL;
5365 char *exp_end = NULL;
5366 char *tok, *end_tok;
5368 char *cond_start = NULL;
5369 char *cond_end = NULL;
5370 struct expression *cond = NULL;
5371 int i, other_type_used, target_resources_ok = 0;
5372 enum bptype bp_type;
5375 INIT_SAL (&sal); /* initialize to zeroes */
5377 /* Parse arguments. */
5378 innermost_block = NULL;
5380 exp = parse_exp_1 (&arg, 0, 0);
5382 exp_valid_block = innermost_block;
5383 mark = value_mark ();
5384 val = evaluate_expression (exp);
5385 release_value (val);
5386 if (VALUE_LAZY (val))
5387 value_fetch_lazy (val);
5390 while (*tok == ' ' || *tok == '\t')
5394 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5397 toklen = end_tok - tok;
5398 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5400 tok = cond_start = end_tok + 1;
5401 cond = parse_exp_1 (&tok, 0, 0);
5405 error ("Junk at end of command.");
5407 if (accessflag == hw_read)
5408 bp_type = bp_read_watchpoint;
5409 else if (accessflag == hw_access)
5410 bp_type = bp_access_watchpoint;
5412 bp_type = bp_hardware_watchpoint;
5414 mem_cnt = can_use_hardware_watchpoint (val);
5415 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5416 error ("Expression cannot be implemented with read/access watchpoint.");
5419 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5420 target_resources_ok =
5421 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5423 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5424 error ("Target does not support this type of hardware watchpoint.");
5426 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5427 error ("Target can only support one kind of HW watchpoint at a time.");
5430 #if defined(HPUXHPPA)
5431 /* On HP-UX if you set a h/w
5432 watchpoint before the "run" command, the inferior dies with a e.g.,
5433 SIGILL once you start it. I initially believed this was due to a
5434 bad interaction between page protection traps and the initial
5435 startup sequence by the dynamic linker.
5437 However, I tried avoiding that by having HP-UX's implementation of
5438 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
5439 yet, which forced slow watches before a "run" or "attach", and it
5440 still fails somewhere in the startup code.
5442 Until I figure out what's happening, I'm disallowing watches altogether
5443 before the "run" or "attach" command. We'll tell the user they must
5444 set watches after getting the program started. */
5445 if (!target_has_execution)
5447 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5450 #endif /* HPUXHPPA */
5452 /* Now set up the breakpoint. */
5453 b = set_raw_breakpoint (sal);
5454 set_breakpoint_count (breakpoint_count + 1);
5455 b->number = breakpoint_count;
5456 b->disposition = donttouch;
5458 b->exp_valid_block = exp_valid_block;
5459 b->exp_string = savestring (exp_start, exp_end - exp_start);
5463 b->cond_string = savestring (cond_start, cond_end - cond_start);
5467 frame = block_innermost_frame (exp_valid_block);
5470 prev_frame = get_prev_frame (frame);
5471 b->watchpoint_frame = frame->frame;
5474 b->watchpoint_frame = (CORE_ADDR) 0;
5476 if (mem_cnt && target_resources_ok > 0)
5479 b->type = bp_watchpoint;
5481 /* If the expression is "local", then set up a "watchpoint scope"
5482 breakpoint at the point where we've left the scope of the watchpoint
5484 if (innermost_block)
5488 struct breakpoint *scope_breakpoint;
5489 struct symtab_and_line scope_sal;
5491 INIT_SAL (&scope_sal); /* initialize to zeroes */
5492 scope_sal.pc = get_frame_pc (prev_frame);
5493 scope_sal.section = find_pc_overlay (scope_sal.pc);
5495 scope_breakpoint = set_raw_breakpoint (scope_sal);
5496 set_breakpoint_count (breakpoint_count + 1);
5497 scope_breakpoint->number = breakpoint_count;
5499 scope_breakpoint->type = bp_watchpoint_scope;
5500 scope_breakpoint->enable = enabled;
5502 /* Automatically delete the breakpoint when it hits. */
5503 scope_breakpoint->disposition = del;
5505 /* Only break in the proper frame (help with recursion). */
5506 scope_breakpoint->frame = prev_frame->frame;
5508 /* Set the address at which we will stop. */
5509 scope_breakpoint->address = get_frame_pc (prev_frame);
5511 /* The scope breakpoint is related to the watchpoint. We
5512 will need to act on them together. */
5513 b->related_breakpoint = scope_breakpoint;
5516 value_free_to_mark (mark);
5520 /* Return count of locations need to be watched and can be handled
5521 in hardware. If the watchpoint can not be handled
5522 in hardware return zero. */
5524 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5525 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5526 ((BYTE_SIZE) <= (REGISTER_SIZE))
5529 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5530 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5531 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
5535 can_use_hardware_watchpoint (v)
5538 int found_memory_cnt = 0;
5539 struct value *head = v;
5541 /* Did the user specifically forbid us to use hardware watchpoints? */
5542 if (!can_use_hw_watchpoints)
5545 /* Make sure that the value of the expression depends only upon
5546 memory contents, and values computed from them within GDB. If we
5547 find any register references or function calls, we can't use a
5548 hardware watchpoint.
5550 The idea here is that evaluating an expression generates a series
5551 of values, one holding the value of every subexpression. (The
5552 expression a*b+c has five subexpressions: a, b, a*b, c, and
5553 a*b+c.) GDB's values hold almost enough information to establish
5554 the criteria given above --- they identify memory lvalues,
5555 register lvalues, computed values, etcetera. So we can evaluate
5556 the expression, and then scan the chain of values that leaves
5557 behind to decide whether we can detect any possible change to the
5558 expression's final value using only hardware watchpoints.
5560 However, I don't think that the values returned by inferior
5561 function calls are special in any way. So this function may not
5562 notice that an expression involving an inferior function call
5563 can't be watched with hardware watchpoints. FIXME. */
5564 for (; v; v = v->next)
5566 if (VALUE_LVAL (v) == lval_memory)
5569 /* A lazy memory lvalue is one that GDB never needed to fetch;
5570 we either just used its address (e.g., `a' in `a.b') or
5571 we never needed it at all (e.g., `a' in `a,b'). */
5575 /* Ahh, memory we actually used! Check if we can cover
5576 it with hardware watchpoints. */
5577 struct type *vtype = check_typedef (VALUE_TYPE (v));
5579 /* We only watch structs and arrays if user asked for it
5580 explicitly, never if they just happen to appear in a
5581 middle of some value chain. */
5583 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5584 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5586 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5587 int len = TYPE_LENGTH (VALUE_TYPE (v));
5589 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5596 else if (v->lval != not_lval && v->modifiable == 0)
5597 return 0; /* ??? What does this represent? */
5598 else if (v->lval == lval_register)
5599 return 0; /* cannot watch a register with a HW watchpoint */
5602 /* The expression itself looks suitable for using a hardware
5603 watchpoint, but give the target machine a chance to reject it. */
5604 return found_memory_cnt;
5609 watch_command_wrapper (arg, from_tty)
5613 watch_command (arg, from_tty);
5617 watch_command (arg, from_tty)
5621 watch_command_1 (arg, hw_write, from_tty);
5626 rwatch_command_wrapper (arg, from_tty)
5630 rwatch_command (arg, from_tty);
5634 rwatch_command (arg, from_tty)
5638 watch_command_1 (arg, hw_read, from_tty);
5643 awatch_command_wrapper (arg, from_tty)
5647 awatch_command (arg, from_tty);
5651 awatch_command (arg, from_tty)
5655 watch_command_1 (arg, hw_access, from_tty);
5659 /* Helper routines for the until_command routine in infcmd.c. Here
5660 because it uses the mechanisms of breakpoints. */
5662 /* This function is called by fetch_inferior_event via the
5663 cmd_continuation pointer, to complete the until command. It takes
5664 care of cleaning up the temporary breakpoints set up by the until
5667 until_break_command_continuation (struct continuation_arg *arg)
5669 struct cleanup *cleanups;
5671 cleanups = (struct cleanup *) arg->data.pointer;
5672 do_exec_cleanups (cleanups);
5677 until_break_command (arg, from_tty)
5681 struct symtabs_and_lines sals;
5682 struct symtab_and_line sal;
5683 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5684 struct breakpoint *breakpoint;
5685 struct cleanup *old_chain;
5686 struct continuation_arg *arg1;
5689 clear_proceed_status ();
5691 /* Set a breakpoint where the user wants it and at return from
5694 if (default_breakpoint_valid)
5695 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5696 default_breakpoint_line, (char ***) NULL);
5698 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5699 0, (char ***) NULL);
5701 if (sals.nelts != 1)
5702 error ("Couldn't get information on specified line.");
5705 free ((PTR) sals.sals); /* malloc'd, so freed */
5708 error ("Junk at end of arguments.");
5710 resolve_sal_pc (&sal);
5712 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5714 if (!event_loop_p || !target_can_async_p ())
5715 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5717 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5719 /* If we are running asynchronously, and the target supports async
5720 execution, we are not waiting for the target to stop, in the call
5721 tp proceed, below. This means that we cannot delete the
5722 brekpoints until the target has actually stopped. The only place
5723 where we get a chance to do that is in fetch_inferior_event, so
5724 we must set things up for that. */
5726 if (event_loop_p && target_can_async_p ())
5728 /* In this case the arg for the continuation is just the point
5729 in the exec_cleanups chain from where to start doing
5730 cleanups, because all the continuation does is the cleanups in
5731 the exec_cleanup_chain. */
5733 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5735 arg1->data.pointer = old_chain;
5737 add_continuation (until_break_command_continuation, arg1);
5740 /* Keep within the current frame */
5744 sal = find_pc_line (prev_frame->pc, 0);
5745 sal.pc = prev_frame->pc;
5746 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5747 if (!event_loop_p || !target_can_async_p ())
5748 make_cleanup_delete_breakpoint (breakpoint);
5750 make_exec_cleanup_delete_breakpoint (breakpoint);
5753 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5754 /* Do the cleanups now, anly if we are not running asynchronously,
5755 of if we are, but the target is still synchronous. */
5756 if (!event_loop_p || !target_can_async_p ())
5757 do_cleanups (old_chain);
5761 /* These aren't used; I don't konw what they were for. */
5762 /* Set a breakpoint at the catch clause for NAME. */
5764 catch_breakpoint (name)
5770 disable_catch_breakpoint ()
5775 delete_catch_breakpoint ()
5780 enable_catch_breakpoint ()
5787 struct sal_chain *next;
5788 struct symtab_and_line sal;
5792 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5793 had been commented out in the v.4.16 sources, and stays
5794 disabled there now because "catch NAME" syntax isn't allowed.
5796 /* This isn't used; I don't know what it was for. */
5797 /* For each catch clause identified in ARGS, run FUNCTION
5798 with that clause as an argument. */
5799 static struct symtabs_and_lines
5800 map_catch_names (args, function)
5804 register char *p = args;
5806 struct symtabs_and_lines sals;
5808 struct sal_chain *sal_chain = 0;
5812 error_no_arg ("one or more catch names");
5820 /* Don't swallow conditional part. */
5821 if (p1[0] == 'i' && p1[1] == 'f'
5822 && (p1[2] == ' ' || p1[2] == '\t'))
5828 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5832 if (*p1 && *p1 != ' ' && *p1 != '\t')
5833 error ("Arguments must be catch names.");
5839 struct sal_chain *next = (struct sal_chain *)
5840 alloca (sizeof (struct sal_chain));
5841 next->next = sal_chain;
5842 next->sal = get_catch_sal (p);
5847 printf_unfiltered ("No catch clause for exception %s.\n", p);
5852 while (*p == ' ' || *p == '\t')
5858 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5860 static struct symtabs_and_lines
5861 get_catch_sals (this_level_only)
5862 int this_level_only;
5864 register struct blockvector *bl;
5865 register struct block *block;
5866 int index, have_default = 0;
5868 struct symtabs_and_lines sals;
5869 struct sal_chain *sal_chain = 0;
5870 char *blocks_searched;
5872 /* Not sure whether an error message is always the correct response,
5873 but it's better than a core dump. */
5874 if (selected_frame == NULL)
5875 error ("No selected frame.");
5876 block = get_frame_block (selected_frame);
5877 pc = selected_frame->pc;
5883 error ("No symbol table info available.\n");
5885 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5886 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5887 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5891 CORE_ADDR end = BLOCK_END (block) - 4;
5894 if (bl != blockvector_for_pc (end, &index))
5895 error ("blockvector blotch");
5896 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5897 error ("blockvector botch");
5898 last_index = BLOCKVECTOR_NBLOCKS (bl);
5901 /* Don't print out blocks that have gone by. */
5902 while (index < last_index
5903 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5906 while (index < last_index
5907 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5909 if (blocks_searched[index] == 0)
5911 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5914 register struct symbol *sym;
5916 nsyms = BLOCK_NSYMS (b);
5918 for (i = 0; i < nsyms; i++)
5920 sym = BLOCK_SYM (b, i);
5921 if (STREQ (SYMBOL_NAME (sym), "default"))
5927 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5929 struct sal_chain *next = (struct sal_chain *)
5930 alloca (sizeof (struct sal_chain));
5931 next->next = sal_chain;
5932 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5937 blocks_searched[index] = 1;
5943 if (sal_chain && this_level_only)
5946 /* After handling the function's top-level block, stop.
5947 Don't continue to its superblock, the block of
5948 per-file symbols. */
5949 if (BLOCK_FUNCTION (block))
5951 block = BLOCK_SUPERBLOCK (block);
5956 struct sal_chain *tmp_chain;
5958 /* Count the number of entries. */
5959 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5960 tmp_chain = tmp_chain->next)
5964 sals.sals = (struct symtab_and_line *)
5965 xmalloc (index * sizeof (struct symtab_and_line));
5966 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5967 sals.sals[index] = sal_chain->sal;
5974 ep_skip_leading_whitespace (s)
5977 if ((s == NULL) || (*s == NULL))
5979 while (isspace (**s))
5983 /* This function examines a string, and attempts to find a token
5984 that might be an event name in the leading characters. If a
5985 possible match is found, a pointer to the last character of
5986 the token is returned. Else, NULL is returned. */
5989 ep_find_event_name_end (arg)
5993 char *event_name_end = NULL;
5995 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5999 /* We break out of the loop when we find a token delimiter.
6000 Basically, we're looking for alphanumerics and underscores;
6001 anything else delimites the token. */
6004 if (!isalnum (*s) && (*s != '_'))
6010 return event_name_end;
6014 /* This function attempts to parse an optional "if <cond>" clause
6015 from the arg string. If one is not found, it returns NULL.
6017 Else, it returns a pointer to the condition string. (It does not
6018 attempt to evaluate the string against a particular block.) And,
6019 it updates arg to point to the first character following the parsed
6020 if clause in the arg string. */
6023 ep_parse_optional_if_clause (arg)
6028 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6031 /* Skip the "if" keyword. */
6034 /* Skip any extra leading whitespace, and record the start of the
6035 condition string. */
6036 ep_skip_leading_whitespace (arg);
6039 /* Assume that the condition occupies the remainder of the arg string. */
6040 (*arg) += strlen (cond_string);
6045 /* This function attempts to parse an optional filename from the arg
6046 string. If one is not found, it returns NULL.
6048 Else, it returns a pointer to the parsed filename. (This function
6049 makes no attempt to verify that a file of that name exists, or is
6050 accessible.) And, it updates arg to point to the first character
6051 following the parsed filename in the arg string.
6053 Note that clients needing to preserve the returned filename for
6054 future access should copy it to their own buffers. */
6056 ep_parse_optional_filename (arg)
6059 static char filename[1024];
6064 if ((*arg_p == '\0') || isspace (*arg_p))
6082 /* Commands to deal with catching events, such as signals, exceptions,
6083 process start/exit, etc. */
6087 catch_fork, catch_vfork
6091 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
6092 static void catch_fork_command_1 (catch_fork_kind fork_kind,
6093 char *arg, int tempflag, int from_tty);
6096 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
6097 catch_fork_kind fork_kind;
6102 char *cond_string = NULL;
6104 ep_skip_leading_whitespace (&arg);
6106 /* The allowed syntax is:
6108 catch [v]fork if <cond>
6110 First, check if there's an if clause. */
6111 cond_string = ep_parse_optional_if_clause (&arg);
6113 if ((*arg != '\0') && !isspace (*arg))
6114 error ("Junk at end of arguments.");
6116 /* If this target supports it, create a fork or vfork catchpoint
6117 and enable reporting of such events. */
6121 create_fork_event_catchpoint (tempflag, cond_string);
6124 create_vfork_event_catchpoint (tempflag, cond_string);
6127 error ("unsupported or unknown fork kind; cannot catch it");
6133 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6135 catch_exec_command_1 (arg, tempflag, from_tty)
6140 char *cond_string = NULL;
6142 ep_skip_leading_whitespace (&arg);
6144 /* The allowed syntax is:
6146 catch exec if <cond>
6148 First, check if there's an if clause. */
6149 cond_string = ep_parse_optional_if_clause (&arg);
6151 if ((*arg != '\0') && !isspace (*arg))
6152 error ("Junk at end of arguments.");
6154 /* If this target supports it, create an exec catchpoint
6155 and enable reporting of such events. */
6156 create_exec_event_catchpoint (tempflag, cond_string);
6160 #if defined(SOLIB_ADD)
6162 catch_load_command_1 (arg, tempflag, from_tty)
6167 char *dll_pathname = NULL;
6168 char *cond_string = NULL;
6170 ep_skip_leading_whitespace (&arg);
6172 /* The allowed syntax is:
6174 catch load if <cond>
6175 catch load <filename>
6176 catch load <filename> if <cond>
6178 The user is not allowed to specify the <filename> after an
6181 We'll ignore the pathological case of a file named "if".
6183 First, check if there's an if clause. If so, then there
6184 cannot be a filename. */
6185 cond_string = ep_parse_optional_if_clause (&arg);
6187 /* If there was an if clause, then there cannot be a filename.
6188 Else, there might be a filename and an if clause. */
6189 if (cond_string == NULL)
6191 dll_pathname = ep_parse_optional_filename (&arg);
6192 ep_skip_leading_whitespace (&arg);
6193 cond_string = ep_parse_optional_if_clause (&arg);
6196 if ((*arg != '\0') && !isspace (*arg))
6197 error ("Junk at end of arguments.");
6199 /* Create a load breakpoint that only triggers when a load of
6200 the specified dll (or any dll, if no pathname was specified)
6202 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
6203 dll_pathname, cond_string);
6207 catch_unload_command_1 (arg, tempflag, from_tty)
6212 char *dll_pathname = NULL;
6213 char *cond_string = NULL;
6215 ep_skip_leading_whitespace (&arg);
6217 /* The allowed syntax is:
6219 catch unload if <cond>
6220 catch unload <filename>
6221 catch unload <filename> if <cond>
6223 The user is not allowed to specify the <filename> after an
6226 We'll ignore the pathological case of a file named "if".
6228 First, check if there's an if clause. If so, then there
6229 cannot be a filename. */
6230 cond_string = ep_parse_optional_if_clause (&arg);
6232 /* If there was an if clause, then there cannot be a filename.
6233 Else, there might be a filename and an if clause. */
6234 if (cond_string == NULL)
6236 dll_pathname = ep_parse_optional_filename (&arg);
6237 ep_skip_leading_whitespace (&arg);
6238 cond_string = ep_parse_optional_if_clause (&arg);
6241 if ((*arg != '\0') && !isspace (*arg))
6242 error ("Junk at end of arguments.");
6244 /* Create an unload breakpoint that only triggers when an unload of
6245 the specified dll (or any dll, if no pathname was specified)
6247 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
6248 dll_pathname, cond_string);
6250 #endif /* SOLIB_ADD */
6252 /* Commands to deal with catching exceptions. */
6254 /* Set a breakpoint at the specified callback routine for an
6255 exception event callback */
6258 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
6261 enum exception_event_kind ex_event;
6262 struct symtab_and_line *sal;
6264 struct breakpoint *b;
6265 int thread = -1; /* All threads. */
6267 if (!sal) /* no exception support? */
6270 b = set_raw_breakpoint (*sal);
6271 set_breakpoint_count (breakpoint_count + 1);
6272 b->number = breakpoint_count;
6274 b->cond_string = (cond_string == NULL) ?
6275 NULL : savestring (cond_string, strlen (cond_string));
6277 b->addr_string = NULL;
6278 b->enable = enabled;
6279 b->disposition = tempflag ? del : donttouch;
6282 case EX_EVENT_THROW:
6283 b->type = bp_catch_throw;
6285 case EX_EVENT_CATCH:
6286 b->type = bp_catch_catch;
6288 default: /* error condition */
6290 b->enable = disabled;
6291 error ("Internal error -- invalid catchpoint kind");
6296 /* Deal with "catch catch" and "catch throw" commands */
6299 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
6300 enum exception_event_kind ex_event;
6305 char *cond_string = NULL;
6306 struct symtab_and_line *sal = NULL;
6308 ep_skip_leading_whitespace (&arg);
6310 cond_string = ep_parse_optional_if_clause (&arg);
6312 if ((*arg != '\0') && !isspace (*arg))
6313 error ("Junk at end of arguments.");
6315 if ((ex_event != EX_EVENT_THROW) &&
6316 (ex_event != EX_EVENT_CATCH))
6317 error ("Unsupported or unknown exception event; cannot catch it");
6319 /* See if we can find a callback routine */
6320 sal = target_enable_exception_callback (ex_event, 1);
6324 /* We have callbacks from the runtime system for exceptions.
6325 Set a breakpoint on the sal found, if no errors */
6326 if (sal != (struct symtab_and_line *) -1)
6327 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6329 return; /* something went wrong with setting up callbacks */
6333 /* No callbacks from runtime system for exceptions.
6334 Try GNU C++ exception breakpoints using labels in debug info. */
6335 if (ex_event == EX_EVENT_CATCH)
6337 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6339 else if (ex_event == EX_EVENT_THROW)
6341 /* Set a breakpoint on __raise_exception () */
6343 warning ("Unsupported with this platform/compiler combination.");
6344 warning ("Perhaps you can achieve the effect you want by setting");
6345 warning ("a breakpoint on __raise_exception().");
6350 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6351 inside a catch_errors */
6354 cover_target_enable_exception_callback (arg)
6357 args_for_catchpoint_enable *args = arg;
6358 struct symtab_and_line *sal;
6359 sal = target_enable_exception_callback (args->kind, args->enable);
6362 else if (sal == (struct symtab_and_line *) -1)
6365 return 1; /*is valid */
6370 /* This is the original v.4.16 and earlier version of the
6371 catch_command_1() function. Now that other flavours of "catch"
6372 have been introduced, and since exception handling can be handled
6373 in other ways (through target ops) also, this is used only for the
6374 GNU C++ exception handling system.
6375 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6376 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6377 there was no code in GDB 4.16 for "catch throw".
6379 Called from catch_exception_command_1 () */
6383 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
6388 /* First, translate ARG into something we can deal with in terms
6391 struct symtabs_and_lines sals;
6392 struct symtab_and_line sal;
6393 register struct expression *cond = 0;
6394 register struct breakpoint *b;
6398 INIT_SAL (&sal); /* initialize to zeroes */
6400 /* If no arg given, or if first arg is 'if ', all active catch clauses
6401 are breakpointed. */
6403 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6404 && (arg[2] == ' ' || arg[2] == '\t')))
6406 /* Grab all active catch clauses. */
6407 sals = get_catch_sals (0);
6411 /* Grab selected catch clauses. */
6412 error ("catch NAME not implemented");
6415 /* Not sure why this code has been disabled. I'm leaving
6416 it disabled. We can never come here now anyway
6417 since we don't allow the "catch NAME" syntax.
6420 /* This isn't used; I don't know what it was for. */
6421 sals = map_catch_names (arg, catch_breakpoint);
6429 for (i = 0; i < sals.nelts; i++)
6431 resolve_sal_pc (&sals.sals[i]);
6435 if (arg[0] == 'i' && arg[1] == 'f'
6436 && (arg[2] == ' ' || arg[2] == '\t'))
6437 cond = parse_exp_1 ((arg += 2, &arg),
6438 block_for_pc (sals.sals[i].pc), 0);
6440 error ("Junk at end of arguments.");
6445 for (i = 0; i < sals.nelts; i++)
6450 describe_other_breakpoints (sal.pc, sal.section);
6452 b = set_raw_breakpoint (sal);
6453 set_breakpoint_count (breakpoint_count + 1);
6454 b->number = breakpoint_count;
6456 /* Important -- this is an ordinary breakpoint. For platforms
6457 with callback support for exceptions,
6458 create_exception_catchpoint() will create special bp types
6459 (bp_catch_catch and bp_catch_throw), and there is code in
6460 insert_breakpoints() and elsewhere that depends on that. */
6461 b->type = bp_breakpoint;
6464 b->enable = enabled;
6465 b->disposition = tempflag ? del : donttouch;
6472 warning ("Multiple breakpoints were set.");
6473 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6475 free ((PTR) sals.sals);
6479 /* This creates a temporary internal breakpoint
6480 just to placate infrun */
6481 static struct breakpoint *
6482 create_temp_exception_breakpoint (pc)
6485 struct symtab_and_line sal;
6486 struct breakpoint *b;
6493 b = set_raw_breakpoint (sal);
6495 error ("Internal error -- couldn't set temp exception breakpoint");
6497 b->type = bp_breakpoint;
6498 b->disposition = del;
6499 b->enable = enabled;
6501 b->number = internal_breakpoint_number--;
6507 catch_command_1 (arg, tempflag, from_tty)
6513 /* The first argument may be an event name, such as "start" or "load".
6514 If so, then handle it as such. If it doesn't match an event name,
6515 then attempt to interpret it as an exception name. (This latter is
6516 the v4.16-and-earlier GDB meaning of the "catch" command.)
6518 First, try to find the bounds of what might be an event name. */
6519 char *arg1_start = arg;
6523 if (arg1_start == NULL)
6525 /* Old behaviour was to use pre-v-4.16 syntax */
6526 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6528 /* Now, this is not allowed */
6529 error ("Catch requires an event name.");
6532 arg1_end = ep_find_event_name_end (arg1_start);
6533 if (arg1_end == NULL)
6534 error ("catch requires an event");
6535 arg1_length = arg1_end + 1 - arg1_start;
6537 /* Try to match what we found against known event names. */
6538 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6540 error ("Catch of signal not yet implemented");
6542 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6544 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6545 tempflag, from_tty);
6547 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6549 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6550 tempflag, from_tty);
6552 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6554 error ("Catch of thread_start not yet implemented");
6556 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6558 error ("Catch of thread_exit not yet implemented");
6560 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6562 error ("Catch of thread_join not yet implemented");
6564 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6566 error ("Catch of start not yet implemented");
6568 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6570 error ("Catch of exit not yet implemented");
6572 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6574 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6575 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6577 error ("Catch of fork not yet implemented");
6580 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6582 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6583 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6585 error ("Catch of vfork not yet implemented");
6588 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6590 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6591 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6593 error ("Catch of exec not yet implemented");
6596 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6598 #if defined(SOLIB_ADD)
6599 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6601 error ("Catch of load not implemented");
6604 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6606 #if defined(SOLIB_ADD)
6607 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6609 error ("Catch of load not implemented");
6612 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6614 error ("Catch of stop not yet implemented");
6617 /* This doesn't appear to be an event name */
6621 /* Pre-v.4.16 behaviour was to treat the argument
6622 as the name of an exception */
6623 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6624 /* Now this is not allowed */
6625 error ("Unknown event kind specified for catch");
6630 /* Used by the gui, could be made a worker for other things. */
6633 set_breakpoint_sal (sal)
6634 struct symtab_and_line sal;
6636 struct breakpoint *b;
6637 b = set_raw_breakpoint (sal);
6638 set_breakpoint_count (breakpoint_count + 1);
6639 b->number = breakpoint_count;
6640 b->type = bp_breakpoint;
6647 /* These aren't used; I don't know what they were for. */
6648 /* Disable breakpoints on all catch clauses described in ARGS. */
6650 disable_catch (args)
6653 /* Map the disable command to catch clauses described in ARGS. */
6656 /* Enable breakpoints on all catch clauses described in ARGS. */
6661 /* Map the disable command to catch clauses described in ARGS. */
6664 /* Delete breakpoints on all catch clauses in the active scope. */
6669 /* Map the delete command to catch clauses described in ARGS. */
6674 catch_command (arg, from_tty)
6678 catch_command_1 (arg, 0, from_tty);
6683 tcatch_command (arg, from_tty)
6687 catch_command_1 (arg, 1, from_tty);
6692 clear_command (arg, from_tty)
6696 register struct breakpoint *b, *b1;
6698 struct symtabs_and_lines sals;
6699 struct symtab_and_line sal;
6700 register struct breakpoint *found;
6705 sals = decode_line_spec (arg, 1);
6710 sals.sals = (struct symtab_and_line *)
6711 xmalloc (sizeof (struct symtab_and_line));
6712 INIT_SAL (&sal); /* initialize to zeroes */
6713 sal.line = default_breakpoint_line;
6714 sal.symtab = default_breakpoint_symtab;
6715 sal.pc = default_breakpoint_address;
6716 if (sal.symtab == 0)
6717 error ("No source file specified.");
6725 /* For each line spec given, delete bps which correspond
6726 to it. We do this in two loops: the first loop looks at
6727 the initial bp(s) in the chain which should be deleted,
6728 the second goes down the rest of the chain looking ahead
6729 one so it can take those bps off the chain without messing
6733 for (i = 0; i < sals.nelts; i++)
6735 /* If exact pc given, clear bpts at that pc.
6736 If line given (pc == 0), clear all bpts on specified line.
6737 If defaulting, clear all bpts on default line
6740 defaulting sal.pc != 0 tests to do
6745 1 0 <can't happen> */
6748 found = (struct breakpoint *) 0;
6751 while (breakpoint_chain
6752 /* Why don't we check here that this is not
6753 a watchpoint, etc., as we do below?
6754 I can't make it fail, but don't know
6755 what's stopping the failure: a watchpoint
6756 of the same address as "sal.pc" should
6757 wind up being deleted. */
6759 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6760 (overlay_debugging == 0 ||
6761 breakpoint_chain->section == sal.section))
6762 || ((default_match || (0 == sal.pc))
6763 && breakpoint_chain->source_file != NULL
6764 && sal.symtab != NULL
6765 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6766 && breakpoint_chain->line_number == sal.line)))
6769 b1 = breakpoint_chain;
6770 breakpoint_chain = b1->next;
6778 && b->next->type != bp_none
6779 && b->next->type != bp_watchpoint
6780 && b->next->type != bp_hardware_watchpoint
6781 && b->next->type != bp_read_watchpoint
6782 && b->next->type != bp_access_watchpoint
6783 && (((sal.pc && (b->next->address == sal.pc)) &&
6784 (overlay_debugging == 0 ||
6785 b->next->section == sal.section))
6786 || ((default_match || (0 == sal.pc))
6787 && b->next->source_file != NULL
6788 && sal.symtab != NULL
6789 && STREQ (b->next->source_file, sal.symtab->filename)
6790 && b->next->line_number == sal.line)))
6803 error ("No breakpoint at %s.", arg);
6805 error ("No breakpoint at this line.");
6809 from_tty = 1; /* Always report if deleted more than one */
6811 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6812 breakpoints_changed ();
6816 printf_unfiltered ("%d ", found->number);
6818 delete_breakpoint (found);
6822 putchar_unfiltered ('\n');
6824 free ((PTR) sals.sals);
6827 /* Delete breakpoint in BS if they are `delete' breakpoints and
6828 all breakpoints that are marked for deletion, whether hit or not.
6829 This is called after any breakpoint is hit, or after errors. */
6832 breakpoint_auto_delete (bs)
6835 struct breakpoint *b, *temp;
6837 for (; bs; bs = bs->next)
6838 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6840 delete_breakpoint (bs->breakpoint_at);
6842 ALL_BREAKPOINTS_SAFE (b, temp)
6844 if (b->disposition == del_at_next_stop)
6845 delete_breakpoint (b);
6849 /* Delete a breakpoint and clean up all traces of it in the data
6853 delete_breakpoint (bpt)
6854 struct breakpoint *bpt;
6856 register struct breakpoint *b;
6860 error ("Internal error (attempted to delete a NULL breakpoint)");
6863 /* Has this bp already been deleted? This can happen because multiple
6864 lists can hold pointers to bp's. bpstat lists are especial culprits.
6866 One example of this happening is a watchpoint's scope bp. When the
6867 scope bp triggers, we notice that the watchpoint is out of scope, and
6868 delete it. We also delete its scope bp. But the scope bp is marked
6869 "auto-deleting", and is already on a bpstat. That bpstat is then
6870 checked for auto-deleting bp's, which are deleted.
6872 A real solution to this problem might involve reference counts in bp's,
6873 and/or giving them pointers back to their referencing bpstat's, and
6874 teaching delete_breakpoint to only free a bp's storage when no more
6875 references were extent. A cheaper bandaid was chosen. */
6876 if (bpt->type == bp_none)
6879 if (delete_breakpoint_hook)
6880 delete_breakpoint_hook (bpt);
6881 breakpoint_delete_event (bpt->number);
6884 remove_breakpoint (bpt, mark_uninserted);
6886 if (breakpoint_chain == bpt)
6887 breakpoint_chain = bpt->next;
6889 /* If we have callback-style exception catchpoints, don't go through
6890 the adjustments to the C++ runtime library etc. if the inferior
6891 isn't actually running. target_enable_exception_callback for a
6892 null target ops vector gives an undesirable error message, so we
6893 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6894 exceptions are supported in this way, it's OK for now. FIXME */
6895 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6897 static char message1[] = "Error in deleting catchpoint %d:\n";
6898 static char message[sizeof (message1) + 30];
6899 args_for_catchpoint_enable args;
6901 /* Format possible error msg */
6902 sprintf (message, message1, bpt->number);
6903 args.kind = bpt->type == bp_catch_catch ?
6904 EX_EVENT_CATCH : EX_EVENT_THROW;
6906 catch_errors (cover_target_enable_exception_callback, &args,
6907 message, RETURN_MASK_ALL);
6914 b->next = bpt->next;
6918 /* Before turning off the visuals for the bp, check to see that
6919 there are no other bps at the same address. */
6926 clearIt = (b->address != bpt->address);
6933 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6934 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6938 check_duplicates (bpt->address, bpt->section);
6939 /* If this breakpoint was inserted, and there is another breakpoint
6940 at the same address, we need to insert the other breakpoint. */
6942 && bpt->type != bp_hardware_watchpoint
6943 && bpt->type != bp_read_watchpoint
6944 && bpt->type != bp_access_watchpoint
6945 && bpt->type != bp_catch_fork
6946 && bpt->type != bp_catch_vfork
6947 && bpt->type != bp_catch_exec)
6950 if (b->address == bpt->address
6951 && b->section == bpt->section
6953 && b->enable != disabled
6954 && b->enable != shlib_disabled
6955 && b->enable != call_disabled)
6959 /* We should never reach this point if there is a permanent
6960 breakpoint at the same address as the one being deleted.
6961 If there is a permanent breakpoint somewhere, it should
6962 always be the only one inserted. */
6963 if (b->enable == permanent)
6964 internal_error ("another breakpoint was inserted on top of "
6965 "a permanent breakpoint");
6967 if (b->type == bp_hardware_breakpoint)
6968 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6970 val = target_insert_breakpoint (b->address, b->shadow_contents);
6974 target_terminal_ours_for_output ();
6975 warning ("Cannot insert breakpoint %d:", b->number);
6976 memory_error (val, b->address); /* which bombs us out */
6983 free_command_lines (&bpt->commands);
6986 if (bpt->cond_string != NULL)
6987 free (bpt->cond_string);
6988 if (bpt->addr_string != NULL)
6989 free (bpt->addr_string);
6990 if (bpt->exp != NULL)
6992 if (bpt->exp_string != NULL)
6993 free (bpt->exp_string);
6994 if (bpt->val != NULL)
6995 value_free (bpt->val);
6996 if (bpt->source_file != NULL)
6997 free (bpt->source_file);
6998 if (bpt->dll_pathname != NULL)
6999 free (bpt->dll_pathname);
7000 if (bpt->triggered_dll_pathname != NULL)
7001 free (bpt->triggered_dll_pathname);
7002 if (bpt->exec_pathname != NULL)
7003 free (bpt->exec_pathname);
7005 /* Be sure no bpstat's are pointing at it after it's been freed. */
7006 /* FIXME, how can we find all bpstat's?
7007 We just check stop_bpstat for now. */
7008 for (bs = stop_bpstat; bs; bs = bs->next)
7009 if (bs->breakpoint_at == bpt)
7011 bs->breakpoint_at = NULL;
7013 /* we'd call bpstat_clear_actions, but that free's stuff and due
7014 to the multiple pointers pointing to one item with no
7015 reference counts found anywhere through out the bpstat's (how
7016 do you spell fragile?), we don't want to free things twice --
7017 better a memory leak than a corrupt malloc pool! */
7018 bs->commands = NULL;
7021 /* On the chance that someone will soon try again to delete this same
7022 bp, we mark it as deleted before freeing its storage. */
7023 bpt->type = bp_none;
7029 do_delete_breakpoint_cleanup (void *b)
7031 delete_breakpoint (b);
7035 make_cleanup_delete_breakpoint (struct breakpoint *b)
7037 return make_cleanup (do_delete_breakpoint_cleanup, b);
7041 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
7043 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
7047 delete_command (arg, from_tty)
7051 struct breakpoint *b, *temp;
7055 int breaks_to_delete = 0;
7057 /* Delete all breakpoints if no argument.
7058 Do not delete internal or call-dummy breakpoints, these
7059 have to be deleted with an explicit breakpoint number argument. */
7062 if (b->type != bp_call_dummy &&
7063 b->type != bp_shlib_event &&
7064 b->type != bp_thread_event &&
7066 breaks_to_delete = 1;
7069 /* Ask user only if there are some breakpoints to delete. */
7071 || (breaks_to_delete && query ("Delete all breakpoints? ")))
7073 ALL_BREAKPOINTS_SAFE (b, temp)
7075 if (b->type != bp_call_dummy &&
7076 b->type != bp_shlib_event &&
7077 b->type != bp_thread_event &&
7079 delete_breakpoint (b);
7084 map_breakpoint_numbers (arg, delete_breakpoint);
7087 /* Reset a breakpoint given it's struct breakpoint * BINT.
7088 The value we return ends up being the return value from catch_errors.
7089 Unused in this case. */
7092 breakpoint_re_set_one (bint)
7095 /* get past catch_errs */
7096 struct breakpoint *b = (struct breakpoint *) bint;
7099 struct symtabs_and_lines sals;
7101 enum enable save_enable;
7106 warning ("attempted to reset apparently deleted breakpoint #%d?",
7110 case bp_hardware_breakpoint:
7112 case bp_catch_unload:
7113 if (b->addr_string == NULL)
7115 /* Anything without a string can't be re-set. */
7116 delete_breakpoint (b);
7119 /* In case we have a problem, disable this breakpoint. We'll restore
7120 its status if we succeed. */
7121 save_enable = b->enable;
7122 b->enable = disabled;
7124 set_language (b->language);
7125 input_radix = b->input_radix;
7127 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
7128 for (i = 0; i < sals.nelts; i++)
7130 resolve_sal_pc (&sals.sals[i]);
7132 /* Reparse conditions, they might contain references to the
7134 if (b->cond_string != NULL)
7138 free ((PTR) b->cond);
7139 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7142 /* We need to re-set the breakpoint if the address changes... */
7143 if (b->address != sals.sals[i].pc
7144 /* ...or new and old breakpoints both have source files, and
7145 the source file name or the line number changes... */
7146 || (b->source_file != NULL
7147 && sals.sals[i].symtab != NULL
7148 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
7149 || b->line_number != sals.sals[i].line)
7151 /* ...or we switch between having a source file and not having
7153 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7156 if (b->source_file != NULL)
7157 free (b->source_file);
7158 if (sals.sals[i].symtab == NULL)
7159 b->source_file = NULL;
7162 savestring (sals.sals[i].symtab->filename,
7163 strlen (sals.sals[i].symtab->filename));
7164 b->line_number = sals.sals[i].line;
7165 b->address = sals.sals[i].pc;
7167 /* Used to check for duplicates here, but that can
7168 cause trouble, as it doesn't check for disable
7173 /* Might be better to do this just once per breakpoint_re_set,
7174 rather than once for every breakpoint. */
7175 breakpoints_changed ();
7177 b->section = sals.sals[i].section;
7178 b->enable = save_enable; /* Restore it, this worked. */
7181 /* Now that this is re-enabled, check_duplicates
7183 check_duplicates (b->address, b->section);
7186 free ((PTR) sals.sals);
7190 case bp_hardware_watchpoint:
7191 case bp_read_watchpoint:
7192 case bp_access_watchpoint:
7193 innermost_block = NULL;
7194 /* The issue arises of what context to evaluate this in. The
7195 same one as when it was set, but what does that mean when
7196 symbols have been re-read? We could save the filename and
7197 functionname, but if the context is more local than that, the
7198 best we could do would be something like how many levels deep
7199 and which index at that particular level, but that's going to
7200 be less stable than filenames or function names. */
7202 /* So for now, just use a global context. */
7204 free ((PTR) b->exp);
7205 b->exp = parse_expression (b->exp_string);
7206 b->exp_valid_block = innermost_block;
7207 mark = value_mark ();
7209 value_free (b->val);
7210 b->val = evaluate_expression (b->exp);
7211 release_value (b->val);
7212 if (VALUE_LAZY (b->val))
7213 value_fetch_lazy (b->val);
7215 if (b->cond_string != NULL)
7219 free ((PTR) b->cond);
7220 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7222 if (b->enable == enabled)
7224 value_free_to_mark (mark);
7226 case bp_catch_catch:
7227 case bp_catch_throw:
7229 /* We needn't really do anything to reset these, since the mask
7230 that requests them is unaffected by e.g., new libraries being
7233 case bp_catch_vfork:
7238 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7240 /* Delete longjmp breakpoints, they will be reset later by
7241 breakpoint_re_set. */
7243 case bp_longjmp_resume:
7244 delete_breakpoint (b);
7247 /* This breakpoint is special, it's set up when the inferior
7248 starts and we really don't want to touch it. */
7249 case bp_shlib_event:
7251 /* Like bp_shlib_event, this breakpoint type is special.
7252 Once it is set up, we do not want to touch it. */
7253 case bp_thread_event:
7255 /* Keep temporary breakpoints, which can be encountered when we step
7256 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7257 Otherwise these should have been blown away via the cleanup chain
7258 or by breakpoint_init_inferior when we rerun the executable. */
7261 case bp_watchpoint_scope:
7263 case bp_step_resume:
7270 /* Re-set all breakpoints after symbols have been re-loaded. */
7272 breakpoint_re_set ()
7274 struct breakpoint *b, *temp;
7275 enum language save_language;
7276 int save_input_radix;
7277 static char message1[] = "Error in re-setting breakpoint %d:\n";
7278 char message[sizeof (message1) + 30 /* slop */ ];
7280 save_language = current_language->la_language;
7281 save_input_radix = input_radix;
7282 ALL_BREAKPOINTS_SAFE (b, temp)
7284 /* Format possible error msg */
7285 sprintf (message, message1, b->number);
7286 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7288 set_language (save_language);
7289 input_radix = save_input_radix;
7291 #ifdef GET_LONGJMP_TARGET
7292 create_longjmp_breakpoint ("longjmp");
7293 create_longjmp_breakpoint ("_longjmp");
7294 create_longjmp_breakpoint ("siglongjmp");
7295 create_longjmp_breakpoint ("_siglongjmp");
7296 create_longjmp_breakpoint (NULL);
7300 /* Took this out (temporarily at least), since it produces an extra
7301 blank line at startup. This messes up the gdbtests. -PB */
7302 /* Blank line to finish off all those mention() messages we just printed. */
7303 printf_filtered ("\n");
7307 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7308 If from_tty is nonzero, it prints a message to that effect,
7309 which ends with a period (no newline). */
7311 /* Reset the thread number of this breakpoint:
7313 - If the breakpoint is for all threads, leave it as-is.
7314 - Else, reset it to the current thread for inferior_pid. */
7316 breakpoint_re_set_thread (b)
7317 struct breakpoint *b;
7319 if (b->thread != -1)
7321 if (in_thread_list (inferior_pid))
7322 b->thread = pid_to_thread_id (inferior_pid);
7327 set_ignore_count (bptnum, count, from_tty)
7328 int bptnum, count, from_tty;
7330 register struct breakpoint *b;
7336 if (b->number == bptnum)
7338 b->ignore_count = count;
7341 else if (count == 0)
7342 printf_filtered ("Will stop next time breakpoint %d is reached.",
7344 else if (count == 1)
7345 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7348 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7350 breakpoints_changed ();
7354 error ("No breakpoint number %d.", bptnum);
7357 /* Clear the ignore counts of all breakpoints. */
7359 breakpoint_clear_ignore_counts ()
7361 struct breakpoint *b;
7364 b->ignore_count = 0;
7367 /* Command to set ignore-count of breakpoint N to COUNT. */
7370 ignore_command (args, from_tty)
7378 error_no_arg ("a breakpoint number");
7380 num = get_number (&p);
7382 error ("bad breakpoint number: '%s'", args);
7384 error ("Second argument (specified ignore-count) is missing.");
7386 set_ignore_count (num,
7387 longest_to_int (value_as_long (parse_and_eval (p))),
7389 printf_filtered ("\n");
7390 breakpoints_changed ();
7393 /* Call FUNCTION on each of the breakpoints
7394 whose numbers are given in ARGS. */
7397 map_breakpoint_numbers (args, function)
7399 void (*function) (struct breakpoint *);
7401 register char *p = args;
7404 register struct breakpoint *b, *tmp;
7408 error_no_arg ("one or more breakpoint numbers");
7415 num = get_number_or_range (&p1);
7418 warning ("bad breakpoint number at or near '%s'", p);
7422 ALL_BREAKPOINTS_SAFE (b, tmp)
7423 if (b->number == num)
7425 struct breakpoint *related_breakpoint = b->related_breakpoint;
7428 if (related_breakpoint)
7429 function (related_breakpoint);
7433 printf_unfiltered ("No breakpoint number %d.\n", num);
7440 disable_breakpoint (bpt)
7441 struct breakpoint *bpt;
7443 /* Never disable a watchpoint scope breakpoint; we want to
7444 hit them when we leave scope so we can delete both the
7445 watchpoint and its scope breakpoint at that time. */
7446 if (bpt->type == bp_watchpoint_scope)
7449 /* You can't disable permanent breakpoints. */
7450 if (bpt->enable == permanent)
7453 bpt->enable = disabled;
7455 check_duplicates (bpt->address, bpt->section);
7457 if (modify_breakpoint_hook)
7458 modify_breakpoint_hook (bpt);
7459 breakpoint_modify_event (bpt->number);
7464 disable_command (args, from_tty)
7468 register struct breakpoint *bpt;
7470 ALL_BREAKPOINTS (bpt)
7474 warning ("attempted to disable apparently deleted breakpoint #%d?",
7479 case bp_catch_unload:
7481 case bp_catch_vfork:
7483 case bp_catch_catch:
7484 case bp_catch_throw:
7485 case bp_hardware_breakpoint:
7487 case bp_hardware_watchpoint:
7488 case bp_read_watchpoint:
7489 case bp_access_watchpoint:
7490 disable_breakpoint (bpt);
7495 map_breakpoint_numbers (args, disable_breakpoint);
7499 do_enable_breakpoint (bpt, disposition)
7500 struct breakpoint *bpt;
7501 enum bpdisp disposition;
7503 struct frame_info *save_selected_frame = NULL;
7504 int save_selected_frame_level = -1;
7505 int target_resources_ok, other_type_used;
7508 if (bpt->type == bp_hardware_breakpoint)
7511 i = hw_breakpoint_used_count ();
7512 target_resources_ok =
7513 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7515 if (target_resources_ok == 0)
7516 error ("No hardware breakpoint support in the target.");
7517 else if (target_resources_ok < 0)
7518 error ("Hardware breakpoints used exceeds limit.");
7521 if (bpt->enable != permanent)
7522 bpt->enable = enabled;
7523 bpt->disposition = disposition;
7524 check_duplicates (bpt->address, bpt->section);
7525 breakpoints_changed ();
7527 if (bpt->type == bp_watchpoint ||
7528 bpt->type == bp_hardware_watchpoint ||
7529 bpt->type == bp_read_watchpoint ||
7530 bpt->type == bp_access_watchpoint)
7532 if (bpt->exp_valid_block != NULL)
7534 struct frame_info *fr =
7536 /* Ensure that we have the current frame. Else, this
7537 next query may pessimistically be answered as, "No,
7538 not within current scope". */
7539 get_current_frame ();
7540 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7544 Cannot enable watchpoint %d because the block in which its expression\n\
7545 is valid is not currently in scope.\n", bpt->number);
7546 bpt->enable = disabled;
7550 save_selected_frame = selected_frame;
7551 save_selected_frame_level = selected_frame_level;
7552 select_frame (fr, -1);
7555 value_free (bpt->val);
7556 mark = value_mark ();
7557 bpt->val = evaluate_expression (bpt->exp);
7558 release_value (bpt->val);
7559 if (VALUE_LAZY (bpt->val))
7560 value_fetch_lazy (bpt->val);
7562 if (bpt->type == bp_hardware_watchpoint ||
7563 bpt->type == bp_read_watchpoint ||
7564 bpt->type == bp_access_watchpoint)
7566 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7567 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7569 /* Hack around 'unused var' error for some targets here */
7571 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7572 bpt->type, i + mem_cnt, other_type_used);
7573 /* we can consider of type is bp_hardware_watchpoint, convert to
7574 bp_watchpoint in the following condition */
7575 if (target_resources_ok < 0)
7578 Cannot enable watchpoint %d because target watch resources\n\
7579 have been allocated for other watchpoints.\n", bpt->number);
7580 bpt->enable = disabled;
7581 value_free_to_mark (mark);
7586 if (save_selected_frame_level >= 0)
7587 select_frame (save_selected_frame, save_selected_frame_level);
7588 value_free_to_mark (mark);
7590 if (modify_breakpoint_hook)
7591 modify_breakpoint_hook (bpt);
7592 breakpoint_modify_event (bpt->number);
7596 enable_breakpoint (bpt)
7597 struct breakpoint *bpt;
7599 do_enable_breakpoint (bpt, bpt->disposition);
7602 /* The enable command enables the specified breakpoints (or all defined
7603 breakpoints) so they once again become (or continue to be) effective
7604 in stopping the inferior. */
7608 enable_command (args, from_tty)
7612 register struct breakpoint *bpt;
7614 ALL_BREAKPOINTS (bpt)
7618 warning ("attempted to enable apparently deleted breakpoint #%d?",
7623 case bp_catch_unload:
7625 case bp_catch_vfork:
7627 case bp_catch_catch:
7628 case bp_catch_throw:
7629 case bp_hardware_breakpoint:
7631 case bp_hardware_watchpoint:
7632 case bp_read_watchpoint:
7633 case bp_access_watchpoint:
7634 enable_breakpoint (bpt);
7639 map_breakpoint_numbers (args, enable_breakpoint);
7643 enable_once_breakpoint (bpt)
7644 struct breakpoint *bpt;
7646 do_enable_breakpoint (bpt, disable);
7651 enable_once_command (args, from_tty)
7655 map_breakpoint_numbers (args, enable_once_breakpoint);
7659 enable_delete_breakpoint (bpt)
7660 struct breakpoint *bpt;
7662 do_enable_breakpoint (bpt, del);
7667 enable_delete_command (args, from_tty)
7671 map_breakpoint_numbers (args, enable_delete_breakpoint);
7674 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7676 struct symtabs_and_lines
7677 decode_line_spec_1 (string, funfirstline)
7681 struct symtabs_and_lines sals;
7683 error ("Empty line specification.");
7684 if (default_breakpoint_valid)
7685 sals = decode_line_1 (&string, funfirstline,
7686 default_breakpoint_symtab,
7687 default_breakpoint_line,
7690 sals = decode_line_1 (&string, funfirstline,
7691 (struct symtab *) NULL, 0, (char ***) NULL);
7693 error ("Junk at end of line specification: %s", string);
7698 _initialize_breakpoint ()
7700 struct cmd_list_element *c;
7702 breakpoint_chain = 0;
7703 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7704 before a breakpoint is set. */
7705 breakpoint_count = 0;
7707 add_com ("ignore", class_breakpoint, ignore_command,
7708 "Set ignore-count of breakpoint number N to COUNT.\n\
7709 Usage is `ignore N COUNT'.");
7711 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7713 add_com ("commands", class_breakpoint, commands_command,
7714 "Set commands to be executed when a breakpoint is hit.\n\
7715 Give breakpoint number as argument after \"commands\".\n\
7716 With no argument, the targeted breakpoint is the last one set.\n\
7717 The commands themselves follow starting on the next line.\n\
7718 Type a line containing \"end\" to indicate the end of them.\n\
7719 Give \"silent\" as the first line to make the breakpoint silent;\n\
7720 then no output is printed when it is hit, except what the commands print.");
7722 add_com ("condition", class_breakpoint, condition_command,
7723 "Specify breakpoint number N to break only if COND is true.\n\
7724 Usage is `condition N COND', where N is an integer and COND is an\n\
7725 expression to be evaluated whenever breakpoint N is reached. ");
7727 add_com ("tbreak", class_breakpoint, tbreak_command,
7728 "Set a temporary breakpoint. Args like \"break\" command.\n\
7729 Like \"break\" except the breakpoint is only temporary,\n\
7730 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7731 by using \"enable delete\" on the breakpoint number.");
7732 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7733 "Set temporary breakpoint at procedure exit. Either there should\n\
7734 be no argument or the argument must be a depth.\n");
7736 add_com ("hbreak", class_breakpoint, hbreak_command,
7737 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7738 Like \"break\" except the breakpoint requires hardware support,\n\
7739 some target hardware may not have this support.");
7741 add_com ("thbreak", class_breakpoint, thbreak_command,
7742 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7743 Like \"hbreak\" except the breakpoint is only temporary,\n\
7744 so it will be deleted when hit.");
7746 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7747 "Enable some breakpoints.\n\
7748 Give breakpoint numbers (separated by spaces) as arguments.\n\
7749 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7750 This is used to cancel the effect of the \"disable\" command.\n\
7751 With a subcommand you can enable temporarily.",
7752 &enablelist, "enable ", 1, &cmdlist);
7754 add_com ("ab", class_breakpoint, enable_command,
7755 "Enable some breakpoints.\n\
7756 Give breakpoint numbers (separated by spaces) as arguments.\n\
7757 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7758 This is used to cancel the effect of the \"disable\" command.\n\
7759 With a subcommand you can enable temporarily.");
7761 add_com_alias ("en", "enable", class_breakpoint, 1);
7763 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7764 "Enable some breakpoints.\n\
7765 Give breakpoint numbers (separated by spaces) as arguments.\n\
7766 This is used to cancel the effect of the \"disable\" command.\n\
7767 May be abbreviated to simply \"enable\".\n",
7768 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7770 add_cmd ("once", no_class, enable_once_command,
7771 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7772 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7775 add_cmd ("delete", no_class, enable_delete_command,
7776 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7777 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7780 add_cmd ("delete", no_class, enable_delete_command,
7781 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7782 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7785 add_cmd ("once", no_class, enable_once_command,
7786 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7787 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7790 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7791 "Disable some breakpoints.\n\
7792 Arguments are breakpoint numbers with spaces in between.\n\
7793 To disable all breakpoints, give no argument.\n\
7794 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7795 &disablelist, "disable ", 1, &cmdlist);
7796 add_com_alias ("dis", "disable", class_breakpoint, 1);
7797 add_com_alias ("disa", "disable", class_breakpoint, 1);
7799 add_com ("sb", class_breakpoint, disable_command,
7800 "Disable some breakpoints.\n\
7801 Arguments are breakpoint numbers with spaces in between.\n\
7802 To disable all breakpoints, give no argument.\n\
7803 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7805 add_cmd ("breakpoints", class_alias, disable_command,
7806 "Disable some breakpoints.\n\
7807 Arguments are breakpoint numbers with spaces in between.\n\
7808 To disable all breakpoints, give no argument.\n\
7809 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7810 This command may be abbreviated \"disable\".",
7813 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7814 "Delete some breakpoints or auto-display expressions.\n\
7815 Arguments are breakpoint numbers with spaces in between.\n\
7816 To delete all breakpoints, give no argument.\n\
7818 Also a prefix command for deletion of other GDB objects.\n\
7819 The \"unset\" command is also an alias for \"delete\".",
7820 &deletelist, "delete ", 1, &cmdlist);
7821 add_com_alias ("d", "delete", class_breakpoint, 1);
7823 add_com ("db", class_breakpoint, delete_command,
7824 "Delete some breakpoints.\n\
7825 Arguments are breakpoint numbers with spaces in between.\n\
7826 To delete all breakpoints, give no argument.\n");
7828 add_cmd ("breakpoints", class_alias, delete_command,
7829 "Delete some breakpoints or auto-display expressions.\n\
7830 Arguments are breakpoint numbers with spaces in between.\n\
7831 To delete all breakpoints, give no argument.\n\
7832 This command may be abbreviated \"delete\".",
7835 add_com ("clear", class_breakpoint, clear_command,
7836 concat ("Clear breakpoint at specified line or function.\n\
7837 Argument may be line number, function name, or \"*\" and an address.\n\
7838 If line number is specified, all breakpoints in that line are cleared.\n\
7839 If function is specified, breakpoints at beginning of function are cleared.\n\
7840 If an address is specified, breakpoints at that address are cleared.\n\n",
7841 "With no argument, clears all breakpoints in the line that the selected frame\n\
7844 See also the \"delete\" command which clears breakpoints by number.", NULL));
7846 add_com ("break", class_breakpoint, break_command,
7847 concat ("Set breakpoint at specified line or function.\n\
7848 Argument may be line number, function name, or \"*\" and an address.\n\
7849 If line number is specified, break at start of code for that line.\n\
7850 If function is specified, break at start of code for that function.\n\
7851 If an address is specified, break at that exact address.\n",
7852 "With no arg, uses current execution address of selected stack frame.\n\
7853 This is useful for breaking on return to a stack frame.\n\
7855 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7857 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7858 add_com_alias ("b", "break", class_run, 1);
7859 add_com_alias ("br", "break", class_run, 1);
7860 add_com_alias ("bre", "break", class_run, 1);
7861 add_com_alias ("brea", "break", class_run, 1);
7863 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7864 concat ("Set breakpoint at procedure exit. \n\
7865 Argument may be function name, or \"*\" and an address.\n\
7866 If function is specified, break at end of code for that function.\n\
7867 If an address is specified, break at the end of the function that contains \n\
7868 that exact address.\n",
7869 "With no arg, uses current execution address of selected stack frame.\n\
7870 This is useful for breaking on return to a stack frame.\n\
7872 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7874 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7875 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7876 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7877 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7878 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7882 add_com_alias ("ba", "break", class_breakpoint, 1);
7883 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7884 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7885 "Set breakpoint at procedure exit. Either there should\n\
7886 be no argument or the argument must be a depth.\n");
7891 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7892 "Break in function/address or break at a line in the current file.",
7893 &stoplist, "stop ", 1, &cmdlist);
7894 add_cmd ("in", class_breakpoint, stopin_command,
7895 "Break in function or address.\n", &stoplist);
7896 add_cmd ("at", class_breakpoint, stopat_command,
7897 "Break at a line in the current file.\n", &stoplist);
7898 add_com ("status", class_info, breakpoints_info,
7899 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7900 The \"Type\" column indicates one of:\n\
7901 \tbreakpoint - normal breakpoint\n\
7902 \twatchpoint - watchpoint\n\
7903 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7904 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7905 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7906 address and file/line number respectively.\n\n",
7907 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7908 are set to the address of the last breakpoint listed.\n\n\
7909 Convenience variable \"$bpnum\" contains the number of the last\n\
7910 breakpoint set.", NULL));
7913 add_info ("breakpoints", breakpoints_info,
7914 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7915 The \"Type\" column indicates one of:\n\
7916 \tbreakpoint - normal breakpoint\n\
7917 \twatchpoint - watchpoint\n\
7918 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7919 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7920 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7921 address and file/line number respectively.\n\n",
7922 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7923 are set to the address of the last breakpoint listed.\n\n\
7924 Convenience variable \"$bpnum\" contains the number of the last\n\
7925 breakpoint set.", NULL));
7928 add_com ("lb", class_breakpoint, breakpoints_info,
7929 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7930 The \"Type\" column indicates one of:\n\
7931 \tbreakpoint - normal breakpoint\n\
7932 \twatchpoint - watchpoint\n\
7933 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7934 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7935 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7936 address and file/line number respectively.\n\n",
7937 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7938 are set to the address of the last breakpoint listed.\n\n\
7939 Convenience variable \"$bpnum\" contains the number of the last\n\
7940 breakpoint set.", NULL));
7942 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7943 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7944 The \"Type\" column indicates one of:\n\
7945 \tbreakpoint - normal breakpoint\n\
7946 \twatchpoint - watchpoint\n\
7947 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7948 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7949 \tuntil - internal breakpoint used by the \"until\" command\n\
7950 \tfinish - internal breakpoint used by the \"finish\" command\n",
7951 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7952 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7953 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7954 address and file/line number respectively.\n\n",
7955 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7956 are set to the address of the last breakpoint listed.\n\n\
7957 Convenience variable \"$bpnum\" contains the number of the last\n\
7958 breakpoint set.", NULL),
7959 &maintenanceinfolist);
7961 add_com ("catch", class_breakpoint, catch_command,
7962 "Set catchpoints to catch events.\n\
7963 Raised signals may be caught:\n\
7964 \tcatch signal - all signals\n\
7965 \tcatch signal <signame> - a particular signal\n\
7966 Raised exceptions may be caught:\n\
7967 \tcatch throw - all exceptions, when thrown\n\
7968 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7969 \tcatch catch - all exceptions, when caught\n\
7970 \tcatch catch <exceptname> - a particular exception, when caught\n\
7971 Thread or process events may be caught:\n\
7972 \tcatch thread_start - any threads, just after creation\n\
7973 \tcatch thread_exit - any threads, just before expiration\n\
7974 \tcatch thread_join - any threads, just after joins\n\
7975 Process events may be caught:\n\
7976 \tcatch start - any processes, just after creation\n\
7977 \tcatch exit - any processes, just before expiration\n\
7978 \tcatch fork - calls to fork()\n\
7979 \tcatch vfork - calls to vfork()\n\
7980 \tcatch exec - calls to exec()\n\
7981 Dynamically-linked library events may be caught:\n\
7982 \tcatch load - loads of any library\n\
7983 \tcatch load <libname> - loads of a particular library\n\
7984 \tcatch unload - unloads of any library\n\
7985 \tcatch unload <libname> - unloads of a particular library\n\
7986 The act of your program's execution stopping may also be caught:\n\
7988 C++ exceptions may be caught:\n\
7989 \tcatch throw - all exceptions, when thrown\n\
7990 \tcatch catch - all exceptions, when caught\n\
7992 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7993 after a fork or vfork is caught.\n\n\
7994 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7996 add_com ("tcatch", class_breakpoint, tcatch_command,
7997 "Set temporary catchpoints to catch events.\n\
7998 Args like \"catch\" command.\n\
7999 Like \"catch\" except the catchpoint is only temporary,\n\
8000 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8001 by using \"enable delete\" on the catchpoint number.");
8003 add_com ("watch", class_breakpoint, watch_command,
8004 "Set a watchpoint for an expression.\n\
8005 A watchpoint stops execution of your program whenever the value of\n\
8006 an expression changes.");
8008 add_com ("rwatch", class_breakpoint, rwatch_command,
8009 "Set a read watchpoint for an expression.\n\
8010 A watchpoint stops execution of your program whenever the value of\n\
8011 an expression is read.");
8013 add_com ("awatch", class_breakpoint, awatch_command,
8014 "Set a watchpoint for an expression.\n\
8015 A watchpoint stops execution of your program whenever the value of\n\
8016 an expression is either read or written.");
8018 add_info ("watchpoints", breakpoints_info,
8019 "Synonym for ``info breakpoints''.");
8022 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
8023 (char *) &can_use_hw_watchpoints,
8024 "Set debugger's willingness to use watchpoint hardware.\n\
8025 If zero, gdb will not use hardware for new watchpoints, even if\n\
8026 such is available. (However, any hardware watchpoints that were\n\
8027 created before setting this to nonzero, will continue to use watchpoint\n\
8030 add_show_from_set (c, &showlist);
8032 can_use_hw_watchpoints = 1;