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"
43 #include "gdb-events.h"
45 /* Prototypes for local functions. */
47 static void until_break_command_continuation (struct continuation_arg *arg);
50 catch_command_1 PARAMS ((char *, int, int));
53 enable_delete_command PARAMS ((char *, int));
56 enable_delete_breakpoint PARAMS ((struct breakpoint *));
59 enable_once_command PARAMS ((char *, int));
62 enable_once_breakpoint PARAMS ((struct breakpoint *));
65 disable_command PARAMS ((char *, int));
68 enable_command PARAMS ((char *, int));
71 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
74 ignore_command PARAMS ((char *, int));
76 static int breakpoint_re_set_one PARAMS ((PTR));
79 clear_command PARAMS ((char *, int));
82 catch_command PARAMS ((char *, int));
85 handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
87 static struct symtabs_and_lines
88 get_catch_sals PARAMS ((int));
91 watch_command PARAMS ((char *, int));
94 can_use_hardware_watchpoint PARAMS ((struct value *));
96 static void break_at_finish_command PARAMS ((char *, int));
97 static void break_at_finish_at_depth_command PARAMS ((char *, int));
100 tbreak_command PARAMS ((char *, int));
102 static void tbreak_at_finish_command PARAMS ((char *, int));
105 break_command_1 PARAMS ((char *, int, int));
108 mention PARAMS ((struct breakpoint *));
111 set_raw_breakpoint PARAMS ((struct symtab_and_line));
114 check_duplicates PARAMS ((CORE_ADDR, asection *));
117 describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
120 breakpoints_info PARAMS ((char *, int));
123 breakpoint_1 PARAMS ((int, int));
126 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
128 static int breakpoint_cond_eval PARAMS ((PTR));
131 cleanup_executing_breakpoints PARAMS ((PTR));
134 commands_command PARAMS ((char *, int));
137 condition_command PARAMS ((char *, int));
140 get_number_trailer PARAMS ((char **, int));
143 set_breakpoint_count PARAMS ((int));
146 static struct breakpoint *
147 create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
158 remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
160 static enum print_stop_action print_it_typical PARAMS ((bpstat));
162 static enum print_stop_action print_bp_stop_message (bpstat bs);
166 enum exception_event_kind kind;
169 args_for_catchpoint_enable;
171 static int watchpoint_check PARAMS ((PTR));
173 static int cover_target_enable_exception_callback PARAMS ((PTR));
175 static void maintenance_info_breakpoints PARAMS ((char *, int));
177 #ifdef GET_LONGJMP_TARGET
178 static void create_longjmp_breakpoint PARAMS ((char *));
181 static int hw_breakpoint_used_count PARAMS ((void));
183 static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
185 static void hbreak_command PARAMS ((char *, int));
187 static void thbreak_command PARAMS ((char *, int));
189 static void watch_command_1 PARAMS ((char *, int, int));
191 static void rwatch_command PARAMS ((char *, int));
193 static void awatch_command PARAMS ((char *, int));
195 static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
197 static void solib_load_unload_1 PARAMS ((char *hookname,
201 enum bptype bp_kind));
203 static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag,
205 enum bptype bp_kind));
207 static void break_at_finish_at_depth_command_1 PARAMS ((char *arg,
211 static void break_at_finish_command_1 PARAMS ((char *arg,
215 static void stop_command PARAMS ((char *arg, int from_tty));
217 static void stopin_command PARAMS ((char *arg, int from_tty));
219 static void stopat_command PARAMS ((char *arg, int from_tty));
221 static char *ep_find_event_name_end PARAMS ((char *arg));
223 static char *ep_parse_optional_if_clause PARAMS ((char **arg));
225 static char *ep_parse_optional_filename PARAMS ((char **arg));
227 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
228 static void catch_exec_command_1 PARAMS ((char *arg, int tempflag,
232 static void create_exception_catchpoint
233 PARAMS ((int tempflag, char *cond_string,
234 enum exception_event_kind ex_event,
235 struct symtab_and_line * sal));
237 static void catch_exception_command_1
238 PARAMS ((enum exception_event_kind ex_event,
239 char *arg, int tempflag, int from_tty));
241 static void tcatch_command PARAMS ((char *arg, int from_tty));
243 static void ep_skip_leading_whitespace PARAMS ((char **s));
245 /* Prototypes for exported functions. */
248 awatch_command PARAMS ((char *, int));
251 do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
253 /* If FALSE, gdb will not use hardware support for watchpoints, even
254 if such is available. */
255 static int can_use_hw_watchpoints;
257 void _initialize_breakpoint PARAMS ((void));
259 void set_breakpoint_count PARAMS ((int));
261 extern int addressprint; /* Print machine addresses? */
263 #if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD)
264 static int internal_breakpoint_number = -1;
267 /* Are we executing breakpoint commands? */
268 static int executing_breakpoint_commands;
270 /* Walk the following statement or block through all breakpoints.
271 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
274 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
276 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
277 for (B = breakpoint_chain; \
278 B ? (TMP=B->next, 1): 0; \
281 /* True if SHIFT_INST_REGS defined, false otherwise. */
283 int must_shift_inst_regs =
284 #if defined(SHIFT_INST_REGS)
291 /* True if breakpoint hit counts should be displayed in breakpoint info. */
293 int show_breakpoint_hit_counts = 1;
295 /* Chain of all breakpoints defined. */
297 struct breakpoint *breakpoint_chain;
299 /* Number of last breakpoint made. */
301 int breakpoint_count;
303 /* Pointer to current exception event record */
304 static struct exception_event_record *current_exception_event;
306 /* Indicator of whether exception catchpoints should be nuked
307 between runs of a program */
308 int exception_catchpoints_are_fragile = 0;
310 /* Indicator of when exception catchpoints set-up should be
311 reinitialized -- e.g. when program is re-run */
312 int exception_support_initialized = 0;
314 /* This function returns a pointer to the string representation of the
315 pathname of the dynamically-linked library that has just been
318 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
319 or undefined results are guaranteed.
321 This string's contents are only valid immediately after the
322 inferior has stopped in the dynamic linker hook, and becomes
323 invalid as soon as the inferior is continued. Clients should make
324 a copy of this string if they wish to continue the inferior and
325 then access the string. */
327 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
328 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
331 /* This function returns a pointer to the string representation of the
332 pathname of the dynamically-linked library that has just been
335 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
336 TRUE, or undefined results are guaranteed.
338 This string's contents are only valid immediately after the
339 inferior has stopped in the dynamic linker hook, and becomes
340 invalid as soon as the inferior is continued. Clients should make
341 a copy of this string if they wish to continue the inferior and
342 then access the string. */
344 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
345 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
348 /* This function is called by the "catch load" command. It allows the
349 debugger to be notified by the dynamic linker when a specified
350 library file (or any library file, if filename is NULL) is loaded. */
352 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
353 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
354 error ("catch of library loads not yet implemented on this platform")
357 /* This function is called by the "catch unload" command. It allows
358 the debugger to be notified by the dynamic linker when a specified
359 library file (or any library file, if filename is NULL) is
362 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
363 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
364 error ("catch of library unloads not yet implemented on this platform")
367 /* Set breakpoint count to NUM. */
370 set_breakpoint_count (num)
373 breakpoint_count = num;
374 set_internalvar (lookup_internalvar ("bpnum"),
375 value_from_longest (builtin_type_int, (LONGEST) num));
378 /* Used in run_command to zero the hit count when a new run starts. */
381 clear_breakpoint_hit_counts ()
383 struct breakpoint *b;
389 /* Default address, symtab and line to put a breakpoint at
390 for "break" command with no arg.
391 if default_breakpoint_valid is zero, the other three are
392 not valid, and "break" with no arg is an error.
394 This set by print_stack_frame, which calls set_default_breakpoint. */
396 int default_breakpoint_valid;
397 CORE_ADDR default_breakpoint_address;
398 struct symtab *default_breakpoint_symtab;
399 int default_breakpoint_line;
401 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
402 Advance *PP after the string and any trailing whitespace.
404 Currently the string can either be a number or "$" followed by the name
405 of a convenience variable. Making it an expression wouldn't work well
406 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
408 TRAILER is a character which can be found after the number; most
409 commonly this is `-'. If you don't want a trailer, use \0. */
411 get_number_trailer (pp, trailer)
415 int retval = 0; /* default */
419 /* Empty line means refer to the last breakpoint. */
420 return breakpoint_count;
423 /* Make a copy of the name, so we can null-terminate it
424 to pass to lookup_internalvar(). */
429 while (isalnum (*p) || *p == '_')
431 varname = (char *) alloca (p - start + 1);
432 strncpy (varname, start, p - start);
433 varname[p - start] = '\0';
434 val = value_of_internalvar (lookup_internalvar (varname));
435 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
436 retval = (int) value_as_long (val);
439 printf_filtered ("Convenience variable must have integer value.\n");
447 while (*p >= '0' && *p <= '9')
450 /* There is no number here. (e.g. "cond a == b"). */
452 /* Skip non-numeric token */
453 while (*p && !isspace((int) *p))
455 /* Return zero, which caller must interpret as error. */
461 if (!(isspace (*p) || *p == '\0' || *p == trailer))
463 /* Trailing junk: return 0 and let caller print error msg. */
464 while (!(isspace (*p) || *p == '\0' || *p == trailer))
474 /* Like get_number_trailer, but don't allow a trailer. */
479 return get_number_trailer (pp, '\0');
482 /* Parse a number or a range.
483 * A number will be of the form handled by get_number.
484 * A range will be of the form <number1> - <number2>, and
485 * will represent all the integers between number1 and number2,
488 * While processing a range, this fuction is called iteratively;
489 * At each call it will return the next value in the range.
491 * At the beginning of parsing a range, the char pointer PP will
492 * be advanced past <number1> and left pointing at the '-' token.
493 * Subsequent calls will not advance the pointer until the range
494 * is completed. The call that completes the range will advance
495 * pointer PP past <number2>.
499 get_number_or_range (pp)
502 static int last_retval, end_value;
503 static char *end_ptr;
504 static int in_range = 0;
508 /* Default case: pp is pointing either to a solo number,
509 or to the first number of a range. */
510 last_retval = get_number_trailer (pp, '-');
515 /* This is the start of a range (<number1> - <number2>).
516 Skip the '-', parse and remember the second number,
517 and also remember the end of the final token. */
521 while (isspace ((int) *end_ptr))
522 end_ptr++; /* skip white space */
523 end_value = get_number (temp);
524 if (end_value < last_retval)
526 error ("inverted range");
528 else if (end_value == last_retval)
530 /* degenerate range (number1 == number2). Advance the
531 token pointer so that the range will be treated as a
540 error ("negative value");
543 /* pp points to the '-' that betokens a range. All
544 number-parsing has already been done. Return the next
545 integer value (one greater than the saved previous value).
546 Do not advance the token pointer 'pp' until the end of range
549 if (++last_retval == end_value)
551 /* End of range reached; advance token pointer. */
561 /* condition N EXP -- set break condition of breakpoint N to EXP. */
564 condition_command (arg, from_tty)
568 register struct breakpoint *b;
573 error_no_arg ("breakpoint number");
576 bnum = get_number (&p);
578 error ("Bad breakpoint argument: '%s'", arg);
581 if (b->number == bnum)
585 free ((PTR) b->cond);
588 if (b->cond_string != NULL)
589 free ((PTR) b->cond_string);
594 b->cond_string = NULL;
596 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
601 /* I don't know if it matters whether this is the string the user
602 typed in or the decompiled expression. */
603 b->cond_string = savestring (arg, strlen (arg));
604 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
606 error ("Junk at end of expression");
608 breakpoints_changed ();
612 error ("No breakpoint number %d.", bnum);
617 commands_command (arg, from_tty)
621 register struct breakpoint *b;
624 struct command_line *l;
626 /* If we allowed this, we would have problems with when to
627 free the storage, if we change the commands currently
630 if (executing_breakpoint_commands)
631 error ("Can't use the \"commands\" command among a breakpoint's commands.");
634 bnum = get_number (&p);
636 error ("bad breakpoint number: '%s'", arg);
639 error ("Unexpected extra arguments following breakpoint number.");
642 if (b->number == bnum)
646 "Type commands for when breakpoint %d is hit, one per line.",
648 l = read_command_lines (tmpbuf, from_tty);
649 free_command_lines (&b->commands);
651 breakpoints_changed ();
654 error ("No breakpoint number %d.", bnum);
657 /* Like target_read_memory() but if breakpoints are inserted, return
658 the shadow contents instead of the breakpoints themselves.
660 Read "memory data" from whatever target or inferior we have.
661 Returns zero if successful, errno value if not. EIO is used
662 for address out of bounds. If breakpoints are inserted, returns
663 shadow contents, not the breakpoints themselves. From breakpoint.c. */
666 read_memory_nobpt (memaddr, myaddr, len)
672 struct breakpoint *b;
673 CORE_ADDR bp_addr = 0;
676 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
677 /* No breakpoints on this machine. */
678 return target_read_memory (memaddr, myaddr, len);
682 if (b->type == bp_none)
683 warning ("reading through apparently deleted breakpoint #%d?",
686 /* memory breakpoint? */
687 if (b->type == bp_watchpoint
688 || b->type == bp_hardware_watchpoint
689 || b->type == bp_read_watchpoint
690 || b->type == bp_access_watchpoint)
695 /* Addresses and length of the part of the breakpoint that
697 /* XXXX The m68k, sh and h8300 have different local and remote
698 breakpoint values. BREAKPOINT_FROM_PC still manages to
699 correctly determine the breakpoints memory address and size
700 for these targets. */
701 bp_addr = b->address;
703 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
708 if (bp_addr + bp_size <= memaddr)
709 /* The breakpoint is entirely before the chunk of memory we
712 if (bp_addr >= memaddr + len)
713 /* The breakpoint is entirely after the chunk of memory we are
716 /* Copy the breakpoint from the shadow contents, and recurse for
717 the things before and after. */
719 /* Offset within shadow_contents. */
722 if (bp_addr < memaddr)
724 /* Only copy the second part of the breakpoint. */
725 bp_size -= memaddr - bp_addr;
726 bptoffset = memaddr - bp_addr;
730 if (bp_addr + bp_size > memaddr + len)
732 /* Only copy the first part of the breakpoint. */
733 bp_size -= (bp_addr + bp_size) - (memaddr + len);
736 memcpy (myaddr + bp_addr - memaddr,
737 b->shadow_contents + bptoffset, bp_size);
739 if (bp_addr > memaddr)
741 /* Copy the section of memory before the breakpoint. */
742 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
747 if (bp_addr + bp_size < memaddr + len)
749 /* Copy the section of memory after the breakpoint. */
750 status = read_memory_nobpt
752 myaddr + bp_addr + bp_size - memaddr,
753 memaddr + len - (bp_addr + bp_size));
760 /* Nothing overlaps. Just call read_memory_noerr. */
761 return target_read_memory (memaddr, myaddr, len);
765 /* insert_breakpoints is used when starting or continuing the program.
766 remove_breakpoints is used when the program stops.
767 Both return zero if successful,
768 or an `errno' value if could not write the inferior. */
771 insert_breakpoints ()
773 register struct breakpoint *b, *temp;
774 int return_val = 0; /* return success code. */
776 int disabled_breaks = 0;
778 static char message1[] = "Error inserting catchpoint %d:\n";
779 static char message[sizeof (message1) + 30];
782 ALL_BREAKPOINTS_SAFE (b, temp)
784 if (b->enable == permanent)
785 /* Permanent breakpoints cannot be inserted or removed. */
787 else if (b->type != bp_watchpoint
788 && b->type != bp_hardware_watchpoint
789 && b->type != bp_read_watchpoint
790 && b->type != bp_access_watchpoint
791 && b->type != bp_catch_fork
792 && b->type != bp_catch_vfork
793 && b->type != bp_catch_exec
794 && b->type != bp_catch_throw
795 && b->type != bp_catch_catch
796 && b->enable != disabled
797 && b->enable != shlib_disabled
798 && b->enable != call_disabled
802 if (b->type == bp_hardware_breakpoint)
803 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
806 /* Check to see if breakpoint is in an overlay section;
807 if so, we should set the breakpoint at the LMA address.
808 Only if the section is currently mapped should we ALSO
809 set a break at the VMA address. */
810 if (overlay_debugging && b->section &&
811 section_is_overlay (b->section))
815 addr = overlay_unmapped_address (b->address, b->section);
816 val = target_insert_breakpoint (addr, b->shadow_contents);
817 /* This would be the time to check val, to see if the
818 breakpoint write to the load address succeeded.
819 However, this might be an ordinary occurrance, eg. if
820 the unmapped overlay is in ROM. */
821 val = 0; /* in case unmapped address failed */
822 if (section_is_mapped (b->section))
823 val = target_insert_breakpoint (b->address,
826 else /* ordinary (non-overlay) address */
827 val = target_insert_breakpoint (b->address, b->shadow_contents);
831 /* Can't set the breakpoint. */
832 #if defined (DISABLE_UNSETTABLE_BREAK)
833 if (DISABLE_UNSETTABLE_BREAK (b->address))
835 /* See also: disable_breakpoints_in_shlibs. */
837 b->enable = shlib_disabled;
838 if (!disabled_breaks)
840 target_terminal_ours_for_output ();
841 warning ("Cannot insert breakpoint %d:", b->number);
842 warning ("Temporarily disabling shared library breakpoints:");
845 warning ("breakpoint #%d ", b->number);
850 target_terminal_ours_for_output ();
851 warning ("Cannot insert breakpoint %d:", b->number);
852 #ifdef ONE_PROCESS_WRITETEXT
853 warning ("The same program may be running in another process.");
855 memory_error (val, b->address); /* which bombs us out */
862 return_val = val; /* remember failure */
864 else if (ep_is_exception_catchpoint (b)
865 && b->enable != disabled
866 && b->enable != shlib_disabled
867 && b->enable != call_disabled
872 /* If we get here, we must have a callback mechanism for exception
873 events -- with g++ style embedded label support, we insert
874 ordinary breakpoints and not catchpoints. */
875 /* Format possible error message */
876 sprintf (message, message1, b->number);
878 val = target_insert_breakpoint (b->address, b->shadow_contents);
881 /* Couldn't set breakpoint for some reason */
882 target_terminal_ours_for_output ();
883 warning ("Cannot insert catchpoint %d; disabling it.",
885 b->enable = disabled;
889 /* Bp set, now make sure callbacks are enabled */
891 args_for_catchpoint_enable args;
892 args.kind = b->type == bp_catch_catch ?
893 EX_EVENT_CATCH : EX_EVENT_THROW;
895 val = catch_errors (cover_target_enable_exception_callback,
897 message, RETURN_MASK_ALL);
898 if (val != 0 && val != -1)
902 /* Check if something went wrong; val == 0 can be ignored */
905 /* something went wrong */
906 target_terminal_ours_for_output ();
907 warning ("Cannot insert catchpoint %d; disabling it.",
909 b->enable = disabled;
914 return_val = val; /* remember failure */
917 else if ((b->type == bp_hardware_watchpoint ||
918 b->type == bp_read_watchpoint ||
919 b->type == bp_access_watchpoint)
920 && b->enable == enabled
924 struct frame_info *saved_frame;
925 int saved_level, within_current_scope;
926 value_ptr mark = value_mark ();
929 /* Save the current frame and level so we can restore it after
930 evaluating the watchpoint expression on its own frame. */
931 saved_frame = selected_frame;
932 saved_level = selected_frame_level;
934 /* Determine if the watchpoint is within scope. */
935 if (b->exp_valid_block == NULL)
936 within_current_scope = 1;
939 struct frame_info *fi;
941 /* There might be no current frame at this moment if we are
942 resuming from a step over a breakpoint.
943 Set up current frame before trying to find the watchpoint
945 get_current_frame ();
946 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
947 within_current_scope = (fi != NULL);
948 if (within_current_scope)
949 select_frame (fi, -1);
952 if (within_current_scope)
954 /* Evaluate the expression and cut the chain of values
955 produced off from the value chain.
957 Make sure the value returned isn't lazy; we use
958 laziness to determine what memory GDB actually needed
959 in order to compute the value of the expression. */
960 v = evaluate_expression (b->exp);
962 value_release_to_mark (mark);
967 /* Look at each value on the value chain. */
968 for (; v; v = v->next)
970 /* If it's a memory location, and GDB actually needed
971 its contents to evaluate the expression, then we
973 if (VALUE_LVAL (v) == lval_memory
979 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
980 len = TYPE_LENGTH (VALUE_TYPE (v));
982 if (b->type == bp_read_watchpoint)
984 else if (b->type == bp_access_watchpoint)
987 val = target_insert_watchpoint (addr, len, type);
996 /* Failure to insert a watchpoint on any memory value in the
997 value chain brings us here. */
1000 remove_breakpoint (b, mark_uninserted);
1001 warning ("Could not insert hardware watchpoint %d.",
1008 printf_filtered ("Hardware watchpoint %d deleted", b->number);
1009 printf_filtered ("because the program has left the block \n");
1010 printf_filtered ("in which its expression is valid.\n");
1011 if (b->related_breakpoint)
1012 b->related_breakpoint->disposition = del_at_next_stop;
1013 b->disposition = del_at_next_stop;
1016 /* Restore the frame and level. */
1017 if ((saved_frame != selected_frame) ||
1018 (saved_level != selected_frame_level))
1019 select_and_print_frame (saved_frame, saved_level);
1022 return_val = val; /* remember failure */
1024 else if ((b->type == bp_catch_fork
1025 || b->type == bp_catch_vfork
1026 || b->type == bp_catch_exec)
1027 && b->enable == enabled
1035 val = target_insert_fork_catchpoint (inferior_pid);
1037 case bp_catch_vfork:
1038 val = target_insert_vfork_catchpoint (inferior_pid);
1041 val = target_insert_exec_catchpoint (inferior_pid);
1044 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1049 target_terminal_ours_for_output ();
1050 warning ("Cannot insert catchpoint %d.", b->number);
1056 return_val = val; /* remember failure */
1065 remove_breakpoints ()
1067 register struct breakpoint *b;
1074 val = remove_breakpoint (b, mark_uninserted);
1083 reattach_breakpoints (pid)
1086 register struct breakpoint *b;
1088 int saved_inferior_pid = inferior_pid;
1090 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1091 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1096 remove_breakpoint (b, mark_inserted);
1097 if (b->type == bp_hardware_breakpoint)
1098 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1100 val = target_insert_breakpoint (b->address, b->shadow_contents);
1103 inferior_pid = saved_inferior_pid;
1108 inferior_pid = saved_inferior_pid;
1113 update_breakpoints_after_exec ()
1115 struct breakpoint *b;
1116 struct breakpoint *temp;
1118 /* Doing this first prevents the badness of having delete_breakpoint()
1119 write a breakpoint's current "shadow contents" to lift the bp. That
1120 shadow is NOT valid after an exec()! */
1121 mark_breakpoints_out ();
1123 ALL_BREAKPOINTS_SAFE (b, temp)
1125 /* Solib breakpoints must be explicitly reset after an exec(). */
1126 if (b->type == bp_shlib_event)
1128 delete_breakpoint (b);
1132 /* Step-resume breakpoints are meaningless after an exec(). */
1133 if (b->type == bp_step_resume)
1135 delete_breakpoint (b);
1139 /* Ditto the sigtramp handler breakpoints. */
1140 if (b->type == bp_through_sigtramp)
1142 delete_breakpoint (b);
1146 /* Ditto the exception-handling catchpoints. */
1147 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1149 delete_breakpoint (b);
1153 /* Don't delete an exec catchpoint, because else the inferior
1154 won't stop when it ought!
1156 Similarly, we probably ought to keep vfork catchpoints, 'cause
1157 on this target, we may not be able to stop when the vfork is
1158 seen, but only when the subsequent exec is seen. (And because
1159 deleting fork catchpoints here but not vfork catchpoints will
1160 seem mysterious to users, keep those too.)
1162 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1163 target address field, if any, is sufficient to have it be reset
1164 automagically. Certainly on HP-UX that's true. */
1165 if ((b->type == bp_catch_exec) ||
1166 (b->type == bp_catch_vfork) ||
1167 (b->type == bp_catch_fork))
1169 b->address = (CORE_ADDR) NULL;
1173 /* bp_finish is a special case. The only way we ought to be able
1174 to see one of these when an exec() has happened, is if the user
1175 caught a vfork, and then said "finish". Ordinarily a finish just
1176 carries them to the call-site of the current callee, by setting
1177 a temporary bp there and resuming. But in this case, the finish
1178 will carry them entirely through the vfork & exec.
1180 We don't want to allow a bp_finish to remain inserted now. But
1181 we can't safely delete it, 'cause finish_command has a handle to
1182 the bp on a bpstat, and will later want to delete it. There's a
1183 chance (and I've seen it happen) that if we delete the bp_finish
1184 here, that its storage will get reused by the time finish_command
1185 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1186 We really must allow finish_command to delete a bp_finish.
1188 In the absense of a general solution for the "how do we know
1189 it's safe to delete something others may have handles to?"
1190 problem, what we'll do here is just uninsert the bp_finish, and
1191 let finish_command delete it.
1193 (We know the bp_finish is "doomed" in the sense that it's
1194 momentary, and will be deleted as soon as finish_command sees
1195 the inferior stopped. So it doesn't matter that the bp's
1196 address is probably bogus in the new a.out, unlike e.g., the
1197 solib breakpoints.) */
1199 if (b->type == bp_finish)
1204 /* Without a symbolic address, we have little hope of the
1205 pre-exec() address meaning the same thing in the post-exec()
1207 if (b->addr_string == NULL)
1209 delete_breakpoint (b);
1213 /* If this breakpoint has survived the above battery of checks, then
1214 it must have a symbolic address. Be sure that it gets reevaluated
1215 to a target address, rather than reusing the old evaluation. */
1216 b->address = (CORE_ADDR) NULL;
1221 detach_breakpoints (pid)
1224 register struct breakpoint *b;
1226 int saved_inferior_pid = inferior_pid;
1228 if (pid == inferior_pid)
1229 error ("Cannot detach breakpoints of inferior_pid");
1231 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1232 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1237 val = remove_breakpoint (b, mark_inserted);
1240 inferior_pid = saved_inferior_pid;
1245 inferior_pid = saved_inferior_pid;
1250 remove_breakpoint (b, is)
1251 struct breakpoint *b;
1252 insertion_state_t is;
1256 if (b->enable == permanent)
1257 /* Permanent breakpoints cannot be inserted or removed. */
1260 if (b->type == bp_none)
1261 warning ("attempted to remove apparently deleted breakpoint #%d?",
1264 if (b->type != bp_watchpoint
1265 && b->type != bp_hardware_watchpoint
1266 && b->type != bp_read_watchpoint
1267 && b->type != bp_access_watchpoint
1268 && b->type != bp_catch_fork
1269 && b->type != bp_catch_vfork
1270 && b->type != bp_catch_exec
1271 && b->type != bp_catch_catch
1272 && b->type != bp_catch_throw)
1274 if (b->type == bp_hardware_breakpoint)
1275 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1278 /* Check to see if breakpoint is in an overlay section;
1279 if so, we should remove the breakpoint at the LMA address.
1280 If that is not equal to the raw address, then we should
1281 presumable remove the breakpoint there as well. */
1282 if (overlay_debugging && b->section &&
1283 section_is_overlay (b->section))
1287 addr = overlay_unmapped_address (b->address, b->section);
1288 val = target_remove_breakpoint (addr, b->shadow_contents);
1289 /* This would be the time to check val, to see if the
1290 shadow breakpoint write to the load address succeeded.
1291 However, this might be an ordinary occurrance, eg. if
1292 the unmapped overlay is in ROM. */
1293 val = 0; /* in case unmapped address failed */
1294 if (section_is_mapped (b->section))
1295 val = target_remove_breakpoint (b->address,
1296 b->shadow_contents);
1298 else /* ordinary (non-overlay) address */
1299 val = target_remove_breakpoint (b->address, b->shadow_contents);
1303 b->inserted = (is == mark_inserted);
1305 else if ((b->type == bp_hardware_watchpoint ||
1306 b->type == bp_read_watchpoint ||
1307 b->type == bp_access_watchpoint)
1308 && b->enable == enabled
1313 b->inserted = (is == mark_inserted);
1314 /* Walk down the saved value chain. */
1315 for (v = b->val_chain; v; v = v->next)
1317 /* For each memory reference remove the watchpoint
1319 if (VALUE_LVAL (v) == lval_memory
1320 && ! VALUE_LAZY (v))
1325 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1326 len = TYPE_LENGTH (VALUE_TYPE (v));
1328 if (b->type == bp_read_watchpoint)
1330 else if (b->type == bp_access_watchpoint)
1333 val = target_remove_watchpoint (addr, len, type);
1339 /* Failure to remove any of the hardware watchpoints comes here. */
1340 if ((is == mark_uninserted) && (b->inserted))
1341 warning ("Could not remove hardware watchpoint %d.",
1344 /* Free the saved value chain. We will construct a new one
1345 the next time the watchpoint is inserted. */
1346 for (v = b->val_chain; v; v = n)
1351 b->val_chain = NULL;
1353 else if ((b->type == bp_catch_fork ||
1354 b->type == bp_catch_vfork ||
1355 b->type == bp_catch_exec)
1356 && b->enable == enabled
1363 val = target_remove_fork_catchpoint (inferior_pid);
1365 case bp_catch_vfork:
1366 val = target_remove_vfork_catchpoint (inferior_pid);
1369 val = target_remove_exec_catchpoint (inferior_pid);
1372 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1377 b->inserted = (is == mark_inserted);
1379 else if ((b->type == bp_catch_catch ||
1380 b->type == bp_catch_throw)
1381 && b->enable == enabled
1385 val = target_remove_breakpoint (b->address, b->shadow_contents);
1388 b->inserted = (is == mark_inserted);
1390 else if (ep_is_exception_catchpoint (b)
1391 && b->inserted /* sometimes previous insert doesn't happen */
1392 && b->enable == enabled
1396 val = target_remove_breakpoint (b->address, b->shadow_contents);
1400 b->inserted = (is == mark_inserted);
1406 /* Clear the "inserted" flag in all breakpoints. */
1409 mark_breakpoints_out ()
1411 register struct breakpoint *b;
1417 /* Clear the "inserted" flag in all breakpoints and delete any
1418 breakpoints which should go away between runs of the program.
1420 Plus other such housekeeping that has to be done for breakpoints
1423 Note: this function gets called at the end of a run (by
1424 generic_mourn_inferior) and when a run begins (by
1425 init_wait_for_inferior). */
1430 breakpoint_init_inferior (context)
1431 enum inf_context context;
1433 register struct breakpoint *b, *temp;
1434 static int warning_needed = 0;
1436 ALL_BREAKPOINTS_SAFE (b, temp)
1443 case bp_watchpoint_scope:
1445 /* If the call dummy breakpoint is at the entry point it will
1446 cause problems when the inferior is rerun, so we better
1449 Also get rid of scope breakpoints. */
1450 delete_breakpoint (b);
1454 case bp_hardware_watchpoint:
1455 case bp_read_watchpoint:
1456 case bp_access_watchpoint:
1458 /* Likewise for watchpoints on local expressions. */
1459 if (b->exp_valid_block != NULL)
1460 delete_breakpoint (b);
1463 /* Likewise for exception catchpoints in dynamic-linked
1464 executables where required */
1465 if (ep_is_exception_catchpoint (b) &&
1466 exception_catchpoints_are_fragile)
1469 delete_breakpoint (b);
1475 if (exception_catchpoints_are_fragile)
1476 exception_support_initialized = 0;
1478 /* Don't issue the warning unless it's really needed... */
1479 if (warning_needed && (context != inf_exited))
1481 warning ("Exception catchpoints from last run were deleted.");
1482 warning ("You must reinsert them explicitly.");
1487 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1488 exists at PC. It returns ordinary_breakpoint_here if it's an
1489 ordinary breakpoint, or permanent_breakpoint_here if it's a
1490 permanent breakpoint.
1491 - When continuing from a location with an ordinary breakpoint, we
1492 actually single step once before calling insert_breakpoints.
1493 - When continuing from a localion with a permanent breakpoint, we
1494 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1495 the target, to advance the PC past the breakpoint. */
1497 enum breakpoint_here
1498 breakpoint_here_p (pc)
1501 register struct breakpoint *b;
1502 int any_breakpoint_here = 0;
1505 if ((b->enable == enabled
1506 || b->enable == permanent)
1507 && b->address == pc) /* bp is enabled and matches pc */
1509 if (overlay_debugging &&
1510 section_is_overlay (b->section) &&
1511 !section_is_mapped (b->section))
1512 continue; /* unmapped overlay -- can't be a match */
1513 else if (b->enable == permanent)
1514 return permanent_breakpoint_here;
1516 any_breakpoint_here = 1;
1519 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1523 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1524 but it only returns true if there is actually a breakpoint inserted
1528 breakpoint_inserted_here_p (pc)
1531 register struct breakpoint *b;
1535 && b->address == pc) /* bp is inserted and matches pc */
1537 if (overlay_debugging &&
1538 section_is_overlay (b->section) &&
1539 !section_is_mapped (b->section))
1540 continue; /* unmapped overlay -- can't be a match */
1548 /* Return nonzero if FRAME is a dummy frame. We can't use
1549 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1550 much time, at least using get_saved_register on the 68k. This
1551 means that for this function to work right a port must use the
1552 bp_call_dummy breakpoint. */
1555 frame_in_dummy (frame)
1556 struct frame_info *frame;
1558 struct breakpoint *b;
1563 if (USE_GENERIC_DUMMY_FRAMES)
1564 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1568 if (b->type == bp_call_dummy
1569 && b->frame == frame->frame
1570 /* We need to check the PC as well as the frame on the sparc,
1571 for signals.exp in the testsuite. */
1574 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1575 && frame->pc <= b->address)
1581 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1582 is valid for process/thread PID. */
1585 breakpoint_thread_match (pc, pid)
1589 struct breakpoint *b;
1592 thread = pid_to_thread_id (pid);
1595 if (b->enable != disabled
1596 && b->enable != shlib_disabled
1597 && b->enable != call_disabled
1599 && (b->thread == -1 || b->thread == thread))
1601 if (overlay_debugging &&
1602 section_is_overlay (b->section) &&
1603 !section_is_mapped (b->section))
1604 continue; /* unmapped overlay -- can't be a match */
1613 /* bpstat stuff. External routines' interfaces are documented
1617 ep_is_catchpoint (ep)
1618 struct breakpoint *ep;
1621 (ep->type == bp_catch_load)
1622 || (ep->type == bp_catch_unload)
1623 || (ep->type == bp_catch_fork)
1624 || (ep->type == bp_catch_vfork)
1625 || (ep->type == bp_catch_exec)
1626 || (ep->type == bp_catch_catch)
1627 || (ep->type == bp_catch_throw)
1630 /* ??rehrauer: Add more kinds here, as are implemented... */
1635 ep_is_shlib_catchpoint (ep)
1636 struct breakpoint *ep;
1639 (ep->type == bp_catch_load)
1640 || (ep->type == bp_catch_unload)
1645 ep_is_exception_catchpoint (ep)
1646 struct breakpoint *ep;
1649 (ep->type == bp_catch_catch)
1650 || (ep->type == bp_catch_throw)
1654 /* Clear a bpstat so that it says we are not at any breakpoint.
1655 Also free any storage that is part of a bpstat. */
1670 if (p->old_val != NULL)
1671 value_free (p->old_val);
1678 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1679 is part of the bpstat is copied as well. */
1687 bpstat retval = NULL;
1692 for (; bs != NULL; bs = bs->next)
1694 tmp = (bpstat) xmalloc (sizeof (*tmp));
1695 memcpy (tmp, bs, sizeof (*tmp));
1697 /* This is the first thing in the chain. */
1707 /* Find the bpstat associated with this breakpoint */
1710 bpstat_find_breakpoint (bsp, breakpoint)
1712 struct breakpoint *breakpoint;
1717 for (; bsp != NULL; bsp = bsp->next)
1719 if (bsp->breakpoint_at == breakpoint)
1725 /* Find a step_resume breakpoint associated with this bpstat.
1726 (If there are multiple step_resume bp's on the list, this function
1727 will arbitrarily pick one.)
1729 It is an error to use this function if BPSTAT doesn't contain a
1730 step_resume breakpoint.
1732 See wait_for_inferior's use of this function. */
1734 bpstat_find_step_resume_breakpoint (bsp)
1738 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1740 for (; bsp != NULL; bsp = bsp->next)
1742 if ((bsp->breakpoint_at != NULL) &&
1743 (bsp->breakpoint_at->type == bp_step_resume))
1744 return bsp->breakpoint_at;
1747 error ("Internal error (no step_resume breakpoint found)");
1751 /* Return the breakpoint number of the first breakpoint we are stopped
1752 at. *BSP upon return is a bpstat which points to the remaining
1753 breakpoints stopped at (but which is not guaranteed to be good for
1754 anything but further calls to bpstat_num).
1755 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1761 struct breakpoint *b;
1764 return 0; /* No more breakpoint values */
1767 b = (*bsp)->breakpoint_at;
1768 *bsp = (*bsp)->next;
1770 return -1; /* breakpoint that's been deleted since */
1772 return b->number; /* We have its number */
1776 /* Modify BS so that the actions will not be performed. */
1779 bpstat_clear_actions (bs)
1782 for (; bs != NULL; bs = bs->next)
1784 bs->commands = NULL;
1785 if (bs->old_val != NULL)
1787 value_free (bs->old_val);
1793 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1796 cleanup_executing_breakpoints (ignore)
1799 executing_breakpoint_commands = 0;
1802 /* Execute all the commands associated with all the breakpoints at this
1803 location. Any of these commands could cause the process to proceed
1804 beyond this point, etc. We look out for such changes by checking
1805 the global "breakpoint_proceeded" after each command. */
1808 bpstat_do_actions (bsp)
1812 struct cleanup *old_chain;
1813 struct command_line *cmd;
1815 /* Avoid endless recursion if a `source' command is contained
1817 if (executing_breakpoint_commands)
1820 executing_breakpoint_commands = 1;
1821 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1824 /* Note that (as of this writing), our callers all appear to
1825 be passing us the address of global stop_bpstat. And, if
1826 our calls to execute_control_command cause the inferior to
1827 proceed, that global (and hence, *bsp) will change.
1829 We must be careful to not touch *bsp unless the inferior
1830 has not proceeded. */
1832 /* This pointer will iterate over the list of bpstat's. */
1835 breakpoint_proceeded = 0;
1836 for (; bs != NULL; bs = bs->next)
1841 execute_control_command (cmd);
1843 if (breakpoint_proceeded)
1848 if (breakpoint_proceeded)
1849 /* The inferior is proceeded by the command; bomb out now.
1850 The bpstat chain has been blown away by wait_for_inferior.
1851 But since execution has stopped again, there is a new bpstat
1852 to look at, so start over. */
1855 bs->commands = NULL;
1858 executing_breakpoint_commands = 0;
1859 discard_cleanups (old_chain);
1862 /* This is the normal print function for a bpstat. In the future,
1863 much of this logic could (should?) be moved to bpstat_stop_status,
1864 by having it set different print_it values.
1866 Current scheme: When we stop, bpstat_print() is called. It loops
1867 through the bpstat list of things causing this stop, calling the
1868 print_bp_stop_message function on each one. The behavior of the
1869 print_bp_stop_message function depends on the print_it field of
1870 bpstat. If such field so indicates, call this function here.
1872 Return values from this routine (ultimately used by bpstat_print()
1873 and normal_stop() to decide what to do):
1874 PRINT_NOTHING: Means we already printed all we needed to print,
1875 don't print anything else.
1876 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1877 that something to be followed by a location.
1878 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1879 that something to be followed by a location.
1880 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1883 static enum print_stop_action
1884 print_it_typical (bs)
1887 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1888 which has since been deleted. */
1889 if (bs->breakpoint_at == NULL)
1890 return PRINT_UNKNOWN;
1892 switch (bs->breakpoint_at->type)
1895 case bp_hardware_breakpoint:
1896 /* I think the user probably only wants to see one breakpoint
1897 number, not all of them. */
1898 annotate_breakpoint (bs->breakpoint_at->number);
1899 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1900 return PRINT_SRC_AND_LOC;
1903 case bp_shlib_event:
1904 /* Did we stop because the user set the stop_on_solib_events
1905 variable? (If so, we report this as a generic, "Stopped due
1906 to shlib event" message.) */
1907 printf_filtered ("Stopped due to shared library event\n");
1908 return PRINT_NOTHING;
1912 annotate_catchpoint (bs->breakpoint_at->number);
1913 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1914 printf_filtered ("loaded");
1915 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1916 return PRINT_SRC_AND_LOC;
1919 case bp_catch_unload:
1920 annotate_catchpoint (bs->breakpoint_at->number);
1921 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1922 printf_filtered ("unloaded");
1923 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1924 return PRINT_SRC_AND_LOC;
1928 annotate_catchpoint (bs->breakpoint_at->number);
1929 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1930 printf_filtered ("forked");
1931 printf_filtered (" process %d), ",
1932 bs->breakpoint_at->forked_inferior_pid);
1933 return PRINT_SRC_AND_LOC;
1936 case bp_catch_vfork:
1937 annotate_catchpoint (bs->breakpoint_at->number);
1938 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1939 printf_filtered ("vforked");
1940 printf_filtered (" process %d), ",
1941 bs->breakpoint_at->forked_inferior_pid);
1942 return PRINT_SRC_AND_LOC;
1946 annotate_catchpoint (bs->breakpoint_at->number);
1947 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1948 bs->breakpoint_at->number,
1949 bs->breakpoint_at->exec_pathname);
1950 return PRINT_SRC_AND_LOC;
1953 case bp_catch_catch:
1954 if (current_exception_event &&
1955 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1957 annotate_catchpoint (bs->breakpoint_at->number);
1958 printf_filtered ("\nCatchpoint %d (exception caught), ",
1959 bs->breakpoint_at->number);
1960 printf_filtered ("throw location ");
1961 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1962 printf_filtered ("%s:%d",
1963 CURRENT_EXCEPTION_THROW_FILE,
1964 CURRENT_EXCEPTION_THROW_LINE);
1966 printf_filtered ("unknown");
1968 printf_filtered (", catch location ");
1969 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1970 printf_filtered ("%s:%d",
1971 CURRENT_EXCEPTION_CATCH_FILE,
1972 CURRENT_EXCEPTION_CATCH_LINE);
1974 printf_filtered ("unknown");
1976 printf_filtered ("\n");
1977 /* don't bother to print location frame info */
1978 return PRINT_SRC_ONLY;
1982 /* really throw, some other bpstat will handle it */
1983 return PRINT_UNKNOWN;
1987 case bp_catch_throw:
1988 if (current_exception_event &&
1989 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1991 annotate_catchpoint (bs->breakpoint_at->number);
1992 printf_filtered ("\nCatchpoint %d (exception thrown), ",
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 catch, some other bpstat will handle it */
2017 return PRINT_UNKNOWN;
2022 case bp_hardware_watchpoint:
2023 if (bs->old_val != NULL)
2025 annotate_watchpoint (bs->breakpoint_at->number);
2026 mention (bs->breakpoint_at);
2027 printf_filtered ("\nOld value = ");
2028 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2029 printf_filtered ("\nNew value = ");
2030 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2031 Val_pretty_default);
2032 printf_filtered ("\n");
2033 value_free (bs->old_val);
2036 /* More than one watchpoint may have been triggered. */
2037 return PRINT_UNKNOWN;
2040 case bp_read_watchpoint:
2041 mention (bs->breakpoint_at);
2042 printf_filtered ("\nValue = ");
2043 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2044 Val_pretty_default);
2045 printf_filtered ("\n");
2046 return PRINT_UNKNOWN;
2049 case bp_access_watchpoint:
2050 if (bs->old_val != NULL)
2052 annotate_watchpoint (bs->breakpoint_at->number);
2053 mention (bs->breakpoint_at);
2054 printf_filtered ("\nOld value = ");
2055 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2056 value_free (bs->old_val);
2058 printf_filtered ("\nNew value = ");
2062 mention (bs->breakpoint_at);
2063 printf_filtered ("\nValue = ");
2065 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2066 Val_pretty_default);
2067 printf_filtered ("\n");
2068 return PRINT_UNKNOWN;
2070 /* Fall through, we don't deal with these types of breakpoints
2077 case bp_longjmp_resume:
2078 case bp_step_resume:
2079 case bp_through_sigtramp:
2080 case bp_watchpoint_scope:
2083 return PRINT_UNKNOWN;
2087 /* Generic routine for printing messages indicating why we
2088 stopped. The behavior of this function depends on the value
2089 'print_it' in the bpstat structure. Under some circumstances we
2090 may decide not to print anything here and delegate the task to
2093 static enum print_stop_action
2094 print_bp_stop_message (bpstat bs)
2096 switch (bs->print_it)
2099 /* Nothing should be printed for this bpstat entry. */
2100 return PRINT_UNKNOWN;
2104 /* We still want to print the frame, but we already printed the
2105 relevant messages. */
2106 return PRINT_SRC_AND_LOC;
2109 case print_it_normal:
2110 /* Normal case, we handle everything in print_it_typical. */
2111 return print_it_typical (bs);
2114 internal_error ("print_bp_stop_message: unrecognized enum value");
2120 /* Print a message indicating what happened. This is called from
2121 normal_stop(). The input to this routine is the head of the bpstat
2122 list - a list of the eventpoints that caused this stop. This
2123 routine calls the generic print routine for printing a message
2124 about reasons for stopping. This will print (for example) the
2125 "Breakpoint n," part of the output. The return value of this
2128 PRINT_UNKNOWN: Means we printed nothing
2129 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2130 code to print the location. An example is
2131 "Breakpoint 1, " which should be followed by
2133 PRINT_SRC_ONLY: Means we printed something, but there is no need
2134 to also print the location part of the message.
2135 An example is the catch/throw messages, which
2136 don't require a location appended to the end.
2137 PRINT_NOTHING: We have done some printing and we don't need any
2138 further info to be printed.*/
2140 enum print_stop_action
2146 /* Maybe another breakpoint in the chain caused us to stop.
2147 (Currently all watchpoints go on the bpstat whether hit or not.
2148 That probably could (should) be changed, provided care is taken
2149 with respect to bpstat_explains_signal). */
2150 for (; bs; bs = bs->next)
2152 val = print_bp_stop_message (bs);
2153 if (val == PRINT_SRC_ONLY
2154 || val == PRINT_SRC_AND_LOC
2155 || val == PRINT_NOTHING)
2159 /* We reached the end of the chain, or we got a null BS to start
2160 with and nothing was printed. */
2161 return PRINT_UNKNOWN;
2164 /* Evaluate the expression EXP and return 1 if value is zero.
2165 This is used inside a catch_errors to evaluate the breakpoint condition.
2166 The argument is a "struct expression *" that has been cast to char * to
2167 make it pass through catch_errors. */
2170 breakpoint_cond_eval (exp)
2173 value_ptr mark = value_mark ();
2174 int i = !value_true (evaluate_expression ((struct expression *) exp));
2175 value_free_to_mark (mark);
2179 /* Allocate a new bpstat and chain it to the current one. */
2182 bpstat_alloc (b, cbs)
2183 register struct breakpoint *b;
2184 bpstat cbs; /* Current "bs" value */
2188 bs = (bpstat) xmalloc (sizeof (*bs));
2190 bs->breakpoint_at = b;
2191 /* If the condition is false, etc., don't do the commands. */
2192 bs->commands = NULL;
2194 bs->print_it = print_it_normal;
2198 /* Possible return values for watchpoint_check (this can't be an enum
2199 because of check_errors). */
2200 /* The watchpoint has been deleted. */
2201 #define WP_DELETED 1
2202 /* The value has changed. */
2203 #define WP_VALUE_CHANGED 2
2204 /* The value has not changed. */
2205 #define WP_VALUE_NOT_CHANGED 3
2207 #define BP_TEMPFLAG 1
2208 #define BP_HARDWAREFLAG 2
2210 /* Check watchpoint condition. */
2213 watchpoint_check (p)
2216 bpstat bs = (bpstat) p;
2217 struct breakpoint *b;
2218 struct frame_info *fr;
2219 int within_current_scope;
2221 b = bs->breakpoint_at;
2223 if (b->exp_valid_block == NULL)
2224 within_current_scope = 1;
2227 /* There is no current frame at this moment. If we're going to have
2228 any chance of handling watchpoints on local variables, we'll need
2229 the frame chain (so we can determine if we're in scope). */
2230 reinit_frame_cache ();
2231 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2232 within_current_scope = (fr != NULL);
2233 if (within_current_scope)
2234 /* If we end up stopping, the current frame will get selected
2235 in normal_stop. So this call to select_frame won't affect
2237 select_frame (fr, -1);
2240 if (within_current_scope)
2242 /* We use value_{,free_to_}mark because it could be a
2243 *long* time before we return to the command level and
2244 call free_all_values. We can't call free_all_values because
2245 we might be in the middle of evaluating a function call. */
2247 value_ptr mark = value_mark ();
2248 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2249 if (!value_equal (b->val, new_val))
2251 release_value (new_val);
2252 value_free_to_mark (mark);
2253 bs->old_val = b->val;
2255 /* We will stop here */
2256 return WP_VALUE_CHANGED;
2260 /* Nothing changed, don't do anything. */
2261 value_free_to_mark (mark);
2262 /* We won't stop here */
2263 return WP_VALUE_NOT_CHANGED;
2268 /* This seems like the only logical thing to do because
2269 if we temporarily ignored the watchpoint, then when
2270 we reenter the block in which it is valid it contains
2271 garbage (in the case of a function, it may have two
2272 garbage values, one before and one after the prologue).
2273 So we can't even detect the first assignment to it and
2274 watch after that (since the garbage may or may not equal
2275 the first value assigned). */
2277 Watchpoint %d deleted because the program has left the block in\n\
2278 which its expression is valid.\n", bs->breakpoint_at->number);
2279 if (b->related_breakpoint)
2280 b->related_breakpoint->disposition = del_at_next_stop;
2281 b->disposition = del_at_next_stop;
2287 /* Get a bpstat associated with having just stopped at address *PC
2288 and frame address CORE_ADDRESS. Update *PC to point at the
2289 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2290 if this is known to not be a real breakpoint (it could still be a
2291 watchpoint, though). */
2293 /* Determine whether we stopped at a breakpoint, etc, or whether we
2294 don't understand this stop. Result is a chain of bpstat's such that:
2296 if we don't understand the stop, the result is a null pointer.
2298 if we understand why we stopped, the result is not null.
2300 Each element of the chain refers to a particular breakpoint or
2301 watchpoint at which we have stopped. (We may have stopped for
2302 several reasons concurrently.)
2304 Each element of the chain has valid next, breakpoint_at,
2305 commands, FIXME??? fields. */
2308 bpstat_stop_status (pc, not_a_breakpoint)
2310 int not_a_breakpoint;
2312 register struct breakpoint *b, *temp;
2314 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2315 int real_breakpoint = 0;
2316 /* Root of the chain of bpstat's */
2317 struct bpstats root_bs[1];
2318 /* Pointer to the last thing in the chain currently. */
2319 bpstat bs = root_bs;
2320 static char message1[] =
2321 "Error evaluating expression for watchpoint %d\n";
2322 char message[sizeof (message1) + 30 /* slop */ ];
2324 /* Get the address where the breakpoint would have been. */
2325 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ?
2326 0 : DECR_PC_AFTER_BREAK);
2328 ALL_BREAKPOINTS_SAFE (b, temp)
2330 if (b->enable == disabled
2331 || b->enable == shlib_disabled
2332 || b->enable == call_disabled)
2335 if (b->type != bp_watchpoint
2336 && b->type != bp_hardware_watchpoint
2337 && b->type != bp_read_watchpoint
2338 && b->type != bp_access_watchpoint
2339 && b->type != bp_hardware_breakpoint
2340 && b->type != bp_catch_fork
2341 && b->type != bp_catch_vfork
2342 && b->type != bp_catch_exec
2343 && b->type != bp_catch_catch
2344 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2345 if (b->address != bp_addr || /* address doesn't match or */
2346 (overlay_debugging && /* overlay doesn't match */
2347 section_is_overlay (b->section) &&
2348 !section_is_mapped (b->section)))
2351 if (b->type == bp_hardware_breakpoint
2352 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2355 /* Is this a catchpoint of a load or unload? If so, did we
2356 get a load or unload of the specified library? If not,
2358 if ((b->type == bp_catch_load)
2359 #if defined(SOLIB_HAVE_LOAD_EVENT)
2360 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2361 || ((b->dll_pathname != NULL)
2362 && (strcmp (b->dll_pathname,
2363 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2369 if ((b->type == bp_catch_unload)
2370 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2371 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2372 || ((b->dll_pathname != NULL)
2373 && (strcmp (b->dll_pathname,
2374 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2380 if ((b->type == bp_catch_fork)
2381 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2384 if ((b->type == bp_catch_vfork)
2385 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2388 if ((b->type == bp_catch_exec)
2389 && !target_has_execd (inferior_pid, &b->exec_pathname))
2392 if (ep_is_exception_catchpoint (b) &&
2393 !(current_exception_event = target_get_current_exception_event ()))
2396 /* Come here if it's a watchpoint, or if the break address matches */
2398 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2400 /* Watchpoints may change this, if not found to have triggered. */
2404 sprintf (message, message1, b->number);
2405 if (b->type == bp_watchpoint ||
2406 b->type == bp_hardware_watchpoint)
2408 switch (catch_errors (watchpoint_check, bs, message,
2412 /* We've already printed what needs to be printed. */
2413 bs->print_it = print_it_done;
2416 case WP_VALUE_CHANGED:
2420 case WP_VALUE_NOT_CHANGED:
2422 bs->print_it = print_it_noop;
2424 /* Don't consider this a hit. */
2431 /* Error from catch_errors. */
2432 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2433 if (b->related_breakpoint)
2434 b->related_breakpoint->disposition = del_at_next_stop;
2435 b->disposition = del_at_next_stop;
2436 /* We've already printed what needs to be printed. */
2437 bs->print_it = print_it_done;
2443 else if (b->type == bp_read_watchpoint ||
2444 b->type == bp_access_watchpoint)
2450 addr = target_stopped_data_address ();
2453 for (v = b->val_chain; v; v = v->next)
2455 if (VALUE_LVAL (v) == lval_memory
2456 && ! VALUE_LAZY (v))
2460 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2461 /* Exact match not required. Within range is sufficient.
2463 if (addr >= vaddr &&
2464 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2469 switch (catch_errors (watchpoint_check, bs, message,
2473 /* We've already printed what needs to be printed. */
2474 bs->print_it = print_it_done;
2477 case WP_VALUE_CHANGED:
2478 case WP_VALUE_NOT_CHANGED:
2485 /* Error from catch_errors. */
2486 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2487 if (b->related_breakpoint)
2488 b->related_breakpoint->disposition = del_at_next_stop;
2489 b->disposition = del_at_next_stop;
2490 /* We've already printed what needs to be printed. */
2491 bs->print_it = print_it_done;
2494 else /* found == 0 */
2496 /* This is a case where some watchpoint(s) triggered,
2497 but not at the address of this watchpoint (FOUND
2498 was left zero). So don't print anything for this
2500 bs->print_it = print_it_noop;
2507 /* By definition, an encountered breakpoint is a triggered
2511 real_breakpoint = 1;
2514 if (b->frame && b->frame != (get_current_frame ())->frame &&
2515 (b->type == bp_step_resume &&
2516 (INNER_THAN (get_current_frame ()->frame, b->frame))))
2520 int value_is_zero = 0;
2524 /* Need to select the frame, with all that implies
2525 so that the conditions will have the right context. */
2526 select_frame (get_current_frame (), 0);
2528 = catch_errors (breakpoint_cond_eval, (b->cond),
2529 "Error in testing breakpoint condition:\n",
2531 /* FIXME-someday, should give breakpoint # */
2534 if (b->cond && value_is_zero)
2537 /* Don't consider this a hit. */
2540 else if (b->ignore_count > 0)
2543 annotate_ignore_count_change ();
2548 /* We will stop here */
2549 if (b->disposition == disable)
2550 b->enable = disabled;
2551 bs->commands = b->commands;
2555 (STREQ ("silent", bs->commands->line) ||
2556 (xdb_commands && STREQ ("Q", bs->commands->line))))
2558 bs->commands = bs->commands->next;
2563 /* Print nothing for this entry if we dont stop or if we dont print. */
2564 if (bs->stop == 0 || bs->print == 0)
2565 bs->print_it = print_it_noop;
2568 bs->next = NULL; /* Terminate the chain */
2569 bs = root_bs->next; /* Re-grab the head of the chain */
2571 if (real_breakpoint && bs)
2573 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2575 if (DECR_PC_AFTER_HW_BREAK != 0)
2577 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2583 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2586 #if defined (SHIFT_INST_REGS)
2588 #else /* No SHIFT_INST_REGS. */
2590 #endif /* No SHIFT_INST_REGS. */
2595 /* The value of a hardware watchpoint hasn't changed, but the
2596 intermediate memory locations we are watching may have. */
2597 if (bs && !bs->stop &&
2598 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2599 bs->breakpoint_at->type == bp_read_watchpoint ||
2600 bs->breakpoint_at->type == bp_access_watchpoint))
2602 remove_breakpoints ();
2603 insert_breakpoints ();
2608 /* Tell what to do about this bpstat. */
2613 /* Classify each bpstat as one of the following. */
2616 /* This bpstat element has no effect on the main_action. */
2619 /* There was a watchpoint, stop but don't print. */
2622 /* There was a watchpoint, stop and print. */
2625 /* There was a breakpoint but we're not stopping. */
2628 /* There was a breakpoint, stop but don't print. */
2631 /* There was a breakpoint, stop and print. */
2634 /* We hit the longjmp breakpoint. */
2637 /* We hit the longjmp_resume breakpoint. */
2640 /* We hit the step_resume breakpoint. */
2643 /* We hit the through_sigtramp breakpoint. */
2646 /* We hit the shared library event breakpoint. */
2649 /* We caught a shared library event. */
2652 /* This is just used to count how many enums there are. */
2656 /* Here is the table which drives this routine. So that we can
2657 format it pretty, we define some abbreviations for the
2658 enum bpstat_what codes. */
2659 #define kc BPSTAT_WHAT_KEEP_CHECKING
2660 #define ss BPSTAT_WHAT_STOP_SILENT
2661 #define sn BPSTAT_WHAT_STOP_NOISY
2662 #define sgl BPSTAT_WHAT_SINGLE
2663 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2664 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2665 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2666 #define sr BPSTAT_WHAT_STEP_RESUME
2667 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2668 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2669 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2671 /* "Can't happen." Might want to print an error message.
2672 abort() is not out of the question, but chances are GDB is just
2673 a bit confused, not unusable. */
2674 #define err BPSTAT_WHAT_STOP_NOISY
2676 /* Given an old action and a class, come up with a new action. */
2677 /* One interesting property of this table is that wp_silent is the same
2678 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2679 after stopping, the check for whether to step over a breakpoint
2680 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2681 reference to how we stopped. We retain separate wp_silent and
2682 bp_silent codes in case we want to change that someday.
2684 Another possibly interesting property of this table is that
2685 there's a partial ordering, priority-like, of the actions. Once
2686 you've decided that some action is appropriate, you'll never go
2687 back and decide something of a lower priority is better. The
2690 kc < clr sgl shl slr sn sr ss ts
2691 sgl < clrs shl shlr slr sn sr ss ts
2692 slr < err shl shlr sn sr ss ts
2693 clr < clrs err shl shlr sn sr ss ts
2694 clrs < err shl shlr sn sr ss ts
2695 ss < shl shlr sn sr ts
2702 What I think this means is that we don't need a damned table
2703 here. If you just put the rows and columns in the right order,
2704 it'd look awfully regular. We could simply walk the bpstat list
2705 and choose the highest priority action we find, with a little
2706 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2707 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2708 is messy anyway). */
2710 /* step_resume entries: a step resume breakpoint overrides another
2711 breakpoint of signal handling (see comment in wait_for_inferior
2712 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2713 /* We handle the through_sigtramp_breakpoint the same way; having both
2714 one of those and a step_resume_breakpoint is probably very rare (?). */
2716 static const enum bpstat_what_main_action
2717 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2720 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2723 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2725 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2727 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2729 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2731 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2733 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2735 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2737 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2739 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2741 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2743 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2745 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2760 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2761 struct bpstat_what retval;
2763 retval.call_dummy = 0;
2764 for (; bs != NULL; bs = bs->next)
2766 enum class bs_class = no_effect;
2767 if (bs->breakpoint_at == NULL)
2768 /* I suspect this can happen if it was a momentary breakpoint
2769 which has since been deleted. */
2771 switch (bs->breakpoint_at->type)
2777 case bp_hardware_breakpoint:
2783 bs_class = bp_noisy;
2785 bs_class = bp_silent;
2788 bs_class = bp_nostop;
2791 case bp_hardware_watchpoint:
2792 case bp_read_watchpoint:
2793 case bp_access_watchpoint:
2797 bs_class = wp_noisy;
2799 bs_class = wp_silent;
2802 /* There was a watchpoint, but we're not stopping.
2803 This requires no further action. */
2804 bs_class = no_effect;
2807 bs_class = long_jump;
2809 case bp_longjmp_resume:
2810 bs_class = long_resume;
2812 case bp_step_resume:
2815 bs_class = step_resume;
2818 /* It is for the wrong frame. */
2819 bs_class = bp_nostop;
2821 case bp_through_sigtramp:
2822 bs_class = through_sig;
2824 case bp_watchpoint_scope:
2825 bs_class = bp_nostop;
2827 case bp_shlib_event:
2828 bs_class = shlib_event;
2831 case bp_catch_unload:
2832 /* Only if this catchpoint triggered should we cause the
2833 step-out-of-dld behaviour. Otherwise, we ignore this
2836 bs_class = catch_shlib_event;
2838 bs_class = no_effect;
2841 case bp_catch_vfork:
2846 bs_class = bp_noisy;
2848 bs_class = bp_silent;
2851 /* There was a catchpoint, but we're not stopping.
2852 This requires no further action. */
2853 bs_class = no_effect;
2855 case bp_catch_catch:
2856 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2857 bs_class = bp_nostop;
2859 bs_class = bs->print ? bp_noisy : bp_silent;
2861 case bp_catch_throw:
2862 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2863 bs_class = bp_nostop;
2865 bs_class = bs->print ? bp_noisy : bp_silent;
2868 /* Make sure the action is stop (silent or noisy),
2869 so infrun.c pops the dummy frame. */
2870 bs_class = bp_silent;
2871 retval.call_dummy = 1;
2874 current_action = table[(int) bs_class][(int) current_action];
2876 retval.main_action = current_action;
2880 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2881 without hardware support). This isn't related to a specific bpstat,
2882 just to things like whether watchpoints are set. */
2885 bpstat_should_step ()
2887 struct breakpoint *b;
2889 if (b->enable == enabled && b->type == bp_watchpoint)
2894 /* Nonzero if there are enabled hardware watchpoints. */
2896 bpstat_have_active_hw_watchpoints ()
2898 struct breakpoint *b;
2900 if ((b->enable == enabled) &&
2902 ((b->type == bp_hardware_watchpoint) ||
2903 (b->type == bp_read_watchpoint) ||
2904 (b->type == bp_access_watchpoint)))
2910 /* Given a bpstat that records zero or more triggered eventpoints, this
2911 function returns another bpstat which contains only the catchpoints
2912 on that first list, if any. */
2914 bpstat_get_triggered_catchpoints (ep_list, cp_list)
2918 struct bpstats root_bs[1];
2919 bpstat bs = root_bs;
2920 struct breakpoint *ep;
2923 bpstat_clear (cp_list);
2924 root_bs->next = NULL;
2926 for (; ep_list != NULL; ep_list = ep_list->next)
2928 /* Is this eventpoint a catchpoint? If not, ignore it. */
2929 ep = ep_list->breakpoint_at;
2932 if ((ep->type != bp_catch_load) &&
2933 (ep->type != bp_catch_unload) &&
2934 (ep->type != bp_catch_catch) &&
2935 (ep->type != bp_catch_throw))
2936 /* pai: (temp) ADD fork/vfork here!! */
2939 /* Yes; add it to the list. */
2940 bs = bpstat_alloc (ep, bs);
2945 #if defined(SOLIB_ADD)
2946 /* Also, for each triggered catchpoint, tag it with the name of
2947 the library that caused this trigger. (We copy the name now,
2948 because it's only guaranteed to be available NOW, when the
2949 catchpoint triggers. Clients who may wish to know the name
2950 later must get it from the catchpoint itself.) */
2951 if (ep->triggered_dll_pathname != NULL)
2952 free (ep->triggered_dll_pathname);
2953 if (ep->type == bp_catch_load)
2954 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
2956 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
2958 dll_pathname = NULL;
2962 ep->triggered_dll_pathname = (char *)
2963 xmalloc (strlen (dll_pathname) + 1);
2964 strcpy (ep->triggered_dll_pathname, dll_pathname);
2967 ep->triggered_dll_pathname = NULL;
2973 /* Print information on breakpoint number BNUM, or -1 if all.
2974 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
2975 is nonzero, process only watchpoints. */
2982 ep_type_description_t;
2985 breakpoint_1 (bnum, allflag)
2989 register struct breakpoint *b;
2990 register struct command_line *l;
2991 register struct symbol *sym;
2992 CORE_ADDR last_addr = (CORE_ADDR) -1;
2993 int found_a_breakpoint = 0;
2994 static ep_type_description_t bptypes[] =
2996 {bp_none, "?deleted?"},
2997 {bp_breakpoint, "breakpoint"},
2998 {bp_hardware_breakpoint, "hw breakpoint"},
2999 {bp_until, "until"},
3000 {bp_finish, "finish"},
3001 {bp_watchpoint, "watchpoint"},
3002 {bp_hardware_watchpoint, "hw watchpoint"},
3003 {bp_read_watchpoint, "read watchpoint"},
3004 {bp_access_watchpoint, "acc watchpoint"},
3005 {bp_longjmp, "longjmp"},
3006 {bp_longjmp_resume, "longjmp resume"},
3007 {bp_step_resume, "step resume"},
3008 {bp_through_sigtramp, "sigtramp"},
3009 {bp_watchpoint_scope, "watchpoint scope"},
3010 {bp_call_dummy, "call dummy"},
3011 {bp_shlib_event, "shlib events"},
3012 {bp_catch_load, "catch load"},
3013 {bp_catch_unload, "catch unload"},
3014 {bp_catch_fork, "catch fork"},
3015 {bp_catch_vfork, "catch vfork"},
3016 {bp_catch_exec, "catch exec"},
3017 {bp_catch_catch, "catch catch"},
3018 {bp_catch_throw, "catch throw"}
3021 static char *bpdisps[] =
3022 {"del", "dstp", "dis", "keep"};
3023 static char bpenables[] = "nynny";
3024 char wrap_indent[80];
3030 || bnum == b->number)
3032 /* We only print out user settable breakpoints unless the allflag is set. */
3034 && b->type != bp_breakpoint
3035 && b->type != bp_catch_load
3036 && b->type != bp_catch_unload
3037 && b->type != bp_catch_fork
3038 && b->type != bp_catch_vfork
3039 && b->type != bp_catch_exec
3040 && b->type != bp_catch_catch
3041 && b->type != bp_catch_throw
3042 && b->type != bp_hardware_breakpoint
3043 && b->type != bp_watchpoint
3044 && b->type != bp_read_watchpoint
3045 && b->type != bp_access_watchpoint
3046 && b->type != bp_hardware_watchpoint)
3049 if (!found_a_breakpoint++)
3051 annotate_breakpoints_headers ();
3054 printf_filtered ("Num ");
3056 printf_filtered ("Type ");
3058 printf_filtered ("Disp ");
3060 printf_filtered ("Enb ");
3064 printf_filtered ("Address ");
3067 printf_filtered ("What\n");
3069 annotate_breakpoints_table ();
3074 printf_filtered ("%-3d ", b->number);
3076 if ((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3077 error ("bptypes table does not describe type #%d.", (int) b->type);
3078 if ((int) b->type != bptypes[(int) b->type].type)
3079 error ("bptypes table does not describe type #%d?", (int) b->type);
3080 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3082 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3084 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3086 strcpy (wrap_indent, " ");
3088 strcat (wrap_indent, " ");
3092 case bp_hardware_watchpoint:
3093 case bp_read_watchpoint:
3094 case bp_access_watchpoint:
3095 /* Field 4, the address, is omitted (which makes the columns
3096 not line up too nicely with the headers, but the effect
3097 is relatively readable). */
3099 print_expression (b->exp, gdb_stdout);
3103 case bp_catch_unload:
3104 /* Field 4, the address, is omitted (which makes the columns
3105 not line up too nicely with the headers, but the effect
3106 is relatively readable). */
3108 if (b->dll_pathname == NULL)
3109 printf_filtered ("<any library> ");
3111 printf_filtered ("library \"%s\" ", b->dll_pathname);
3115 case bp_catch_vfork:
3116 /* Field 4, the address, is omitted (which makes the columns
3117 not line up too nicely with the headers, but the effect
3118 is relatively readable). */
3120 if (b->forked_inferior_pid != 0)
3121 printf_filtered ("process %d ", b->forked_inferior_pid);
3125 /* Field 4, the address, is omitted (which makes the columns
3126 not line up too nicely with the headers, but the effect
3127 is relatively readable). */
3129 if (b->exec_pathname != NULL)
3130 printf_filtered ("program \"%s\" ", b->exec_pathname);
3132 case bp_catch_catch:
3133 /* Field 4, the address, is omitted (which makes the columns
3134 not line up too nicely with the headers, but the effect
3135 is relatively readable). */
3137 printf_filtered ("exception catch ");
3139 case bp_catch_throw:
3140 /* Field 4, the address, is omitted (which makes the columns
3141 not line up too nicely with the headers, but the effect
3142 is relatively readable). */
3144 printf_filtered ("exception throw ");
3148 case bp_hardware_breakpoint:
3152 case bp_longjmp_resume:
3153 case bp_step_resume:
3154 case bp_through_sigtramp:
3155 case bp_watchpoint_scope:
3157 case bp_shlib_event:
3161 /* FIXME-32x64: need a print_address_numeric with
3165 local_hex_string_custom
3166 ((unsigned long) b->address, "08l"));
3171 last_addr = b->address;
3174 sym = find_pc_sect_function (b->address, b->section);
3177 fputs_filtered ("in ", gdb_stdout);
3178 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3179 wrap_here (wrap_indent);
3180 fputs_filtered (" at ", gdb_stdout);
3182 fputs_filtered (b->source_file, gdb_stdout);
3183 printf_filtered (":%d", b->line_number);
3186 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3190 if (b->thread != -1)
3191 printf_filtered (" thread %d", b->thread);
3193 printf_filtered ("\n");
3199 printf_filtered ("\tstop only in stack frame at ");
3200 print_address_numeric (b->frame, 1, gdb_stdout);
3201 printf_filtered ("\n");
3208 printf_filtered ("\tstop only if ");
3209 print_expression (b->cond, gdb_stdout);
3210 printf_filtered ("\n");
3213 if (b->thread != -1)
3215 /* FIXME should make an annotation for this */
3216 printf_filtered ("\tstop only in thread %d\n", b->thread);
3219 if (show_breakpoint_hit_counts && b->hit_count)
3221 /* FIXME should make an annotation for this */
3222 if (ep_is_catchpoint (b))
3223 printf_filtered ("\tcatchpoint");
3225 printf_filtered ("\tbreakpoint");
3226 printf_filtered (" already hit %d time%s\n",
3227 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3230 if (b->ignore_count)
3234 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3237 if ((l = b->commands))
3243 print_command_line (l, 4, gdb_stdout);
3249 if (!found_a_breakpoint)
3252 printf_filtered ("No breakpoints or watchpoints.\n");
3254 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3257 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3258 that a comparison of an unsigned with -1 is always false. */
3259 if (last_addr != (CORE_ADDR) -1)
3260 set_next_address (last_addr);
3262 annotate_breakpoints_table_end ();
3267 breakpoints_info (bnum_exp, from_tty)
3274 bnum = parse_and_eval_address (bnum_exp);
3276 breakpoint_1 (bnum, 0);
3281 maintenance_info_breakpoints (bnum_exp, from_tty)
3288 bnum = parse_and_eval_address (bnum_exp);
3290 breakpoint_1 (bnum, 1);
3293 /* Print a message describing any breakpoints set at PC. */
3296 describe_other_breakpoints (pc, section)
3300 register int others = 0;
3301 register struct breakpoint *b;
3304 if (b->address == pc)
3305 if (overlay_debugging == 0 ||
3306 b->section == section)
3310 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3312 if (b->address == pc)
3313 if (overlay_debugging == 0 ||
3314 b->section == section)
3320 ((b->enable == disabled ||
3321 b->enable == shlib_disabled ||
3322 b->enable == call_disabled) ? " (disabled)"
3323 : b->enable == permanent ? " (permanent)"
3325 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3327 printf_filtered ("also set at pc ");
3328 print_address_numeric (pc, 1, gdb_stdout);
3329 printf_filtered (".\n");
3333 /* Set the default place to put a breakpoint
3334 for the `break' command with no arguments. */
3337 set_default_breakpoint (valid, addr, symtab, line)
3340 struct symtab *symtab;
3343 default_breakpoint_valid = valid;
3344 default_breakpoint_address = addr;
3345 default_breakpoint_symtab = symtab;
3346 default_breakpoint_line = line;
3349 /* Rescan breakpoints at address ADDRESS,
3350 marking the first one as "first" and any others as "duplicates".
3351 This is so that the bpt instruction is only inserted once.
3352 If we have a permanent breakpoint at ADDRESS, make that one
3353 the official one, and the rest as duplicates. */
3356 check_duplicates (address, section)
3360 register struct breakpoint *b;
3361 register int count = 0;
3362 struct breakpoint *perm_bp = 0;
3364 if (address == 0) /* Watchpoints are uninteresting */
3368 if (b->enable != disabled
3369 && b->enable != shlib_disabled
3370 && b->enable != call_disabled
3371 && b->address == address
3372 && (overlay_debugging == 0 || b->section == section))
3374 /* Have we found a permanent breakpoint? */
3375 if (b->enable == permanent)
3382 b->duplicate = count > 1;
3385 /* If we found a permanent breakpoint at this address, go over the
3386 list again and declare all the other breakpoints there to be the
3390 perm_bp->duplicate = 0;
3392 /* Permanent breakpoint should always be inserted. */
3393 if (! perm_bp->inserted)
3394 internal_error ("allegedly permanent breakpoint is not "
3395 "actually inserted");
3401 internal_error ("another breakpoint was inserted on top of "
3402 "a permanent breakpoint");
3404 if (b->enable != disabled
3405 && b->enable != shlib_disabled
3406 && b->enable != call_disabled
3407 && b->address == address
3408 && (overlay_debugging == 0 || b->section == section))
3414 /* Low level routine to set a breakpoint.
3415 Takes as args the three things that every breakpoint must have.
3416 Returns the breakpoint object so caller can set other things.
3417 Does not set the breakpoint number!
3418 Does not print anything.
3420 ==> This routine should not be called if there is a chance of later
3421 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3422 your arguments BEFORE calling this routine! */
3425 set_raw_breakpoint (sal)
3426 struct symtab_and_line sal;
3428 register struct breakpoint *b, *b1;
3430 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3431 memset (b, 0, sizeof (*b));
3432 b->address = sal.pc;
3433 if (sal.symtab == NULL)
3434 b->source_file = NULL;
3436 b->source_file = savestring (sal.symtab->filename,
3437 strlen (sal.symtab->filename));
3438 b->section = sal.section;
3439 b->language = current_language->la_language;
3440 b->input_radix = input_radix;
3442 b->line_number = sal.line;
3443 b->enable = enabled;
3446 b->ignore_count = 0;
3449 b->dll_pathname = NULL;
3450 b->triggered_dll_pathname = NULL;
3451 b->forked_inferior_pid = 0;
3452 b->exec_pathname = NULL;
3454 /* Add this breakpoint to the end of the chain
3455 so that a list of breakpoints will come out in order
3456 of increasing numbers. */
3458 b1 = breakpoint_chain;
3460 breakpoint_chain = b;
3468 check_duplicates (sal.pc, sal.section);
3469 breakpoints_changed ();
3475 /* Note that the breakpoint object B describes a permanent breakpoint
3476 instruction, hard-wired into the inferior's code. */
3478 make_breakpoint_permanent (struct breakpoint *b)
3480 b->enable = permanent;
3482 /* By definition, permanent breakpoints are already present in the code. */
3486 #ifdef GET_LONGJMP_TARGET
3489 create_longjmp_breakpoint (func_name)
3492 struct symtab_and_line sal;
3493 struct breakpoint *b;
3495 INIT_SAL (&sal); /* initialize to zeroes */
3496 if (func_name != NULL)
3498 struct minimal_symbol *m;
3500 m = lookup_minimal_symbol_text (func_name, NULL,
3501 (struct objfile *) NULL);
3503 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3507 sal.section = find_pc_overlay (sal.pc);
3508 b = set_raw_breakpoint (sal);
3512 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3513 b->disposition = donttouch;
3514 b->enable = disabled;
3517 b->addr_string = strsave (func_name);
3518 b->number = internal_breakpoint_number--;
3521 #endif /* #ifdef GET_LONGJMP_TARGET */
3523 /* Call this routine when stepping and nexting to enable a breakpoint
3524 if we do a longjmp(). When we hit that breakpoint, call
3525 set_longjmp_resume_breakpoint() to figure out where we are going. */
3528 enable_longjmp_breakpoint ()
3530 register struct breakpoint *b;
3533 if (b->type == bp_longjmp)
3535 b->enable = enabled;
3536 check_duplicates (b->address, b->section);
3541 disable_longjmp_breakpoint ()
3543 register struct breakpoint *b;
3546 if (b->type == bp_longjmp
3547 || b->type == bp_longjmp_resume)
3549 b->enable = disabled;
3550 check_duplicates (b->address, b->section);
3556 remove_solib_event_breakpoints ()
3558 register struct breakpoint *b, *temp;
3560 ALL_BREAKPOINTS_SAFE (b, temp)
3561 if (b->type == bp_shlib_event)
3562 delete_breakpoint (b);
3566 create_solib_event_breakpoint (address)
3569 struct breakpoint *b;
3570 struct symtab_and_line sal;
3572 INIT_SAL (&sal); /* initialize to zeroes */
3574 sal.section = find_pc_overlay (sal.pc);
3575 b = set_raw_breakpoint (sal);
3576 b->number = internal_breakpoint_number--;
3577 b->disposition = donttouch;
3578 b->type = bp_shlib_event;
3583 /* Disable any breakpoints that are on code in shared libraries. Only
3584 apply to enabled breakpoints, disabled ones can just stay disabled. */
3587 disable_breakpoints_in_shlibs (silent)
3590 struct breakpoint *b;
3591 int disabled_shlib_breaks = 0;
3593 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3596 #if defined (PC_SOLIB)
3597 if (((b->type == bp_breakpoint) ||
3598 (b->type == bp_hardware_breakpoint)) &&
3599 b->enable == enabled &&
3601 PC_SOLIB (b->address))
3603 b->enable = shlib_disabled;
3606 if (!disabled_shlib_breaks)
3608 target_terminal_ours_for_output ();
3609 warning ("Temporarily disabling shared library breakpoints:");
3611 disabled_shlib_breaks = 1;
3612 warning ("breakpoint #%d ", b->number);
3619 /* Try to reenable any breakpoints in shared libraries. */
3621 re_enable_breakpoints_in_shlibs ()
3623 struct breakpoint *b;
3626 if (b->enable == shlib_disabled)
3630 /* Do not reenable the breakpoint if the shared library
3631 is still not mapped in. */
3632 if (target_read_memory (b->address, buf, 1) == 0)
3633 b->enable = enabled;
3640 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
3645 enum bptype bp_kind;
3647 struct breakpoint *b;
3648 struct symtabs_and_lines sals;
3649 struct cleanup *old_chain;
3650 struct cleanup *canonical_strings_chain = NULL;
3651 char *addr_start = hookname;
3652 char *addr_end = NULL;
3653 char **canonical = (char **) NULL;
3654 int thread = -1; /* All threads. */
3656 /* Set a breakpoint on the specified hook. */
3657 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3658 addr_end = hookname;
3660 if (sals.nelts == 0)
3662 warning ("Unable to set a breakpoint on dynamic linker callback.");
3663 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3664 warning ("GDB will be unable to track shl_load/shl_unload calls");
3667 if (sals.nelts != 1)
3669 warning ("Unable to set unique breakpoint on dynamic linker callback.");
3670 warning ("GDB will be unable to track shl_load/shl_unload calls");
3674 /* Make sure that all storage allocated in decode_line_1 gets freed
3675 in case the following errors out. */
3676 old_chain = make_cleanup (free, sals.sals);
3677 if (canonical != (char **) NULL)
3679 make_cleanup (free, canonical);
3680 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3681 if (canonical[0] != NULL)
3682 make_cleanup (free, canonical[0]);
3685 resolve_sal_pc (&sals.sals[0]);
3687 /* Remove the canonical strings from the cleanup, they are needed below. */
3688 if (canonical != (char **) NULL)
3689 discard_cleanups (canonical_strings_chain);
3691 b = set_raw_breakpoint (sals.sals[0]);
3692 set_breakpoint_count (breakpoint_count + 1);
3693 b->number = breakpoint_count;
3695 b->cond_string = (cond_string == NULL) ?
3696 NULL : savestring (cond_string, strlen (cond_string));
3699 if (canonical != (char **) NULL && canonical[0] != NULL)
3700 b->addr_string = canonical[0];
3701 else if (addr_start)
3702 b->addr_string = savestring (addr_start, addr_end - addr_start);
3704 b->enable = enabled;
3705 b->disposition = tempflag ? del : donttouch;
3707 if (dll_pathname == NULL)
3708 b->dll_pathname = NULL;
3711 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3712 strcpy (b->dll_pathname, dll_pathname);
3717 do_cleanups (old_chain);
3721 create_solib_load_event_breakpoint (hookname, tempflag,
3722 dll_pathname, cond_string)
3728 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3729 cond_string, bp_catch_load);
3733 create_solib_unload_event_breakpoint (hookname, tempflag,
3734 dll_pathname, cond_string)
3740 solib_load_unload_1 (hookname,tempflag, dll_pathname,
3741 cond_string, bp_catch_unload);
3745 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
3748 enum bptype bp_kind;
3750 struct symtab_and_line sal;
3751 struct breakpoint *b;
3752 int thread = -1; /* All threads. */
3759 b = set_raw_breakpoint (sal);
3760 set_breakpoint_count (breakpoint_count + 1);
3761 b->number = breakpoint_count;
3763 b->cond_string = (cond_string == NULL) ?
3764 NULL : savestring (cond_string, strlen (cond_string));
3766 b->addr_string = NULL;
3767 b->enable = enabled;
3768 b->disposition = tempflag ? del : donttouch;
3769 b->forked_inferior_pid = 0;
3777 create_fork_event_catchpoint (tempflag, cond_string)
3781 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
3785 create_vfork_event_catchpoint (tempflag, cond_string)
3789 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
3793 create_exec_event_catchpoint (tempflag, cond_string)
3797 struct symtab_and_line sal;
3798 struct breakpoint *b;
3799 int thread = -1; /* All threads. */
3806 b = set_raw_breakpoint (sal);
3807 set_breakpoint_count (breakpoint_count + 1);
3808 b->number = breakpoint_count;
3810 b->cond_string = (cond_string == NULL) ?
3811 NULL : savestring (cond_string, strlen (cond_string));
3813 b->addr_string = NULL;
3814 b->enable = enabled;
3815 b->disposition = tempflag ? del : donttouch;
3817 b->type = bp_catch_exec;
3823 hw_breakpoint_used_count ()
3825 register struct breakpoint *b;
3830 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
3838 hw_watchpoint_used_count (type, other_type_used)
3840 int *other_type_used;
3842 register struct breakpoint *b;
3845 *other_type_used = 0;
3848 if (b->enable == enabled)
3850 if (b->type == type)
3852 else if ((b->type == bp_hardware_watchpoint ||
3853 b->type == bp_read_watchpoint ||
3854 b->type == bp_access_watchpoint)
3855 && b->enable == enabled)
3856 *other_type_used = 1;
3862 /* Call this after hitting the longjmp() breakpoint. Use this to set
3863 a new breakpoint at the target of the jmp_buf.
3865 FIXME - This ought to be done by setting a temporary breakpoint
3866 that gets deleted automatically... */
3869 set_longjmp_resume_breakpoint (pc, frame)
3871 struct frame_info *frame;
3873 register struct breakpoint *b;
3876 if (b->type == bp_longjmp_resume)
3879 b->enable = enabled;
3881 b->frame = frame->frame;
3884 check_duplicates (b->address, b->section);
3890 disable_watchpoints_before_interactive_call_start ()
3892 struct breakpoint *b;
3896 if (((b->type == bp_watchpoint)
3897 || (b->type == bp_hardware_watchpoint)
3898 || (b->type == bp_read_watchpoint)
3899 || (b->type == bp_access_watchpoint)
3900 || ep_is_exception_catchpoint (b))
3901 && (b->enable == enabled))
3903 b->enable = call_disabled;
3904 check_duplicates (b->address, b->section);
3910 enable_watchpoints_after_interactive_call_stop ()
3912 struct breakpoint *b;
3916 if (((b->type == bp_watchpoint)
3917 || (b->type == bp_hardware_watchpoint)
3918 || (b->type == bp_read_watchpoint)
3919 || (b->type == bp_access_watchpoint)
3920 || ep_is_exception_catchpoint (b))
3921 && (b->enable == call_disabled))
3923 b->enable = enabled;
3924 check_duplicates (b->address, b->section);
3930 /* Set a breakpoint that will evaporate an end of command
3931 at address specified by SAL.
3932 Restrict it to frame FRAME if FRAME is nonzero. */
3935 set_momentary_breakpoint (sal, frame, type)
3936 struct symtab_and_line sal;
3937 struct frame_info *frame;
3940 register struct breakpoint *b;
3941 b = set_raw_breakpoint (sal);
3943 b->enable = enabled;
3944 b->disposition = donttouch;
3945 b->frame = (frame ? frame->frame : 0);
3947 /* If we're debugging a multi-threaded program, then we
3948 want momentary breakpoints to be active in only a
3949 single thread of control. */
3950 if (in_thread_list (inferior_pid))
3951 b->thread = pid_to_thread_id (inferior_pid);
3957 /* Tell the user we have just set a breakpoint B. */
3961 struct breakpoint *b;
3965 /* FIXME: This is misplaced; mention() is called by things (like hitting a
3966 watchpoint) other than breakpoint creation. It should be possible to
3967 clean this up and at the same time replace the random calls to
3968 breakpoint_changed with this hook, as has already been done for
3969 delete_breakpoint_hook and so on. */
3970 if (create_breakpoint_hook)
3971 create_breakpoint_hook (b);
3972 breakpoint_create_event (b->number);
3977 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
3980 printf_filtered ("Watchpoint %d: ", b->number);
3981 print_expression (b->exp, gdb_stdout);
3983 case bp_hardware_watchpoint:
3984 printf_filtered ("Hardware watchpoint %d: ", b->number);
3985 print_expression (b->exp, gdb_stdout);
3987 case bp_read_watchpoint:
3988 printf_filtered ("Hardware read watchpoint %d: ", b->number);
3989 print_expression (b->exp, gdb_stdout);
3991 case bp_access_watchpoint:
3992 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
3994 print_expression (b->exp, gdb_stdout);
3997 printf_filtered ("Breakpoint %d", b->number);
4000 case bp_hardware_breakpoint:
4001 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4005 case bp_catch_unload:
4006 printf_filtered ("Catchpoint %d (%s %s)",
4008 (b->type == bp_catch_load) ? "load" : "unload",
4009 (b->dll_pathname != NULL) ?
4010 b->dll_pathname : "<any library>");
4013 case bp_catch_vfork:
4014 printf_filtered ("Catchpoint %d (%s)",
4016 (b->type == bp_catch_fork) ? "fork" : "vfork");
4019 printf_filtered ("Catchpoint %d (exec)",
4022 case bp_catch_catch:
4023 case bp_catch_throw:
4024 printf_filtered ("Catchpoint %d (%s)",
4026 (b->type == bp_catch_catch) ? "catch" : "throw");
4032 case bp_longjmp_resume:
4033 case bp_step_resume:
4034 case bp_through_sigtramp:
4036 case bp_watchpoint_scope:
4037 case bp_shlib_event:
4042 if (addressprint || b->source_file == NULL)
4044 printf_filtered (" at ");
4045 print_address_numeric (b->address, 1, gdb_stdout);
4048 printf_filtered (": file %s, line %d.",
4049 b->source_file, b->line_number);
4050 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4051 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4053 printf_filtered ("\n");
4057 /* Set a breakpoint according to ARG (function, linenum or *address)
4058 flag: first bit : 0 non-temporary, 1 temporary.
4059 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4062 break_command_1 (arg, flag, from_tty)
4066 int tempflag, hardwareflag;
4067 struct symtabs_and_lines sals;
4068 struct symtab_and_line sal;
4069 register struct expression *cond = 0;
4070 register struct breakpoint *b;
4072 /* Pointers in arg to the start, and one past the end, of the condition. */
4073 char *cond_start = NULL;
4074 char *cond_end = NULL;
4075 /* Pointers in arg to the start, and one past the end,
4076 of the address part. */
4077 char *addr_start = NULL;
4078 char *addr_end = NULL;
4079 struct cleanup *old_chain;
4080 struct cleanup *canonical_strings_chain = NULL;
4081 char **canonical = (char **) NULL;
4085 hardwareflag = flag & BP_HARDWAREFLAG;
4086 tempflag = flag & BP_TEMPFLAG;
4091 INIT_SAL (&sal); /* initialize to zeroes */
4093 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
4095 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
4096 && (arg[2] == ' ' || arg[2] == '\t')))
4098 if (default_breakpoint_valid)
4100 sals.sals = (struct symtab_and_line *)
4101 xmalloc (sizeof (struct symtab_and_line));
4102 sal.pc = default_breakpoint_address;
4103 sal.line = default_breakpoint_line;
4104 sal.symtab = default_breakpoint_symtab;
4105 sal.section = find_pc_overlay (sal.pc);
4110 error ("No default breakpoint address now.");
4116 /* Force almost all breakpoints to be in terms of the
4117 current_source_symtab (which is decode_line_1's default). This
4118 should produce the results we want almost all of the time while
4119 leaving default_breakpoint_* alone. */
4120 if (default_breakpoint_valid
4121 && (!current_source_symtab
4122 || (arg && (*arg == '+' || *arg == '-'))))
4123 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
4124 default_breakpoint_line, &canonical);
4126 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical);
4134 /* Make sure that all storage allocated in decode_line_1 gets freed
4135 in case the following `for' loop errors out. */
4136 old_chain = make_cleanup (free, sals.sals);
4137 if (canonical != (char **) NULL)
4139 make_cleanup (free, canonical);
4140 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4141 for (i = 0; i < sals.nelts; i++)
4143 if (canonical[i] != NULL)
4144 make_cleanup (free, canonical[i]);
4148 thread = -1; /* No specific thread yet */
4150 /* Resolve all line numbers to PC's, and verify that conditions
4151 can be parsed, before setting any breakpoints. */
4152 for (i = 0; i < sals.nelts; i++)
4154 char *tok, *end_tok;
4157 resolve_sal_pc (&sals.sals[i]);
4159 /* It's possible for the PC to be nonzero, but still an illegal
4160 value on some targets.
4162 For example, on HP-UX if you start gdb, and before running the
4163 inferior you try to set a breakpoint on a shared library function
4164 "foo" where the inferior doesn't call "foo" directly but does
4165 pass its address to another function call, then we do find a
4166 minimal symbol for the "foo", but it's address is invalid.
4167 (Appears to be an index into a table that the loader sets up
4168 when the inferior is run.)
4170 Give the target a chance to bless sals.sals[i].pc before we
4171 try to make a breakpoint for it. */
4172 if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc))
4174 error ("Cannot break on %s without a running program.",
4182 while (*tok == ' ' || *tok == '\t')
4187 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4190 toklen = end_tok - tok;
4192 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4194 tok = cond_start = end_tok + 1;
4195 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4198 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4204 thread = strtol (tok, &tok, 0);
4206 error ("Junk after thread keyword.");
4207 if (!valid_thread_id (thread))
4208 error ("Unknown thread %d\n", thread);
4211 error ("Junk at end of arguments.");
4216 int i, target_resources_ok;
4218 i = hw_breakpoint_used_count ();
4219 target_resources_ok =
4220 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4222 if (target_resources_ok == 0)
4223 error ("No hardware breakpoint support in the target.");
4224 else if (target_resources_ok < 0)
4225 error ("Hardware breakpoints used exceeds limit.");
4228 /* Remove the canonical strings from the cleanup, they are needed below. */
4229 if (canonical != (char **) NULL)
4230 discard_cleanups (canonical_strings_chain);
4232 /* Now set all the breakpoints. */
4233 for (i = 0; i < sals.nelts; i++)
4238 describe_other_breakpoints (sal.pc, sal.section);
4240 b = set_raw_breakpoint (sal);
4241 set_breakpoint_count (breakpoint_count + 1);
4242 b->number = breakpoint_count;
4243 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
4247 /* If a canonical line spec is needed use that instead of the
4249 if (canonical != (char **) NULL && canonical[i] != NULL)
4250 b->addr_string = canonical[i];
4251 else if (addr_start)
4252 b->addr_string = savestring (addr_start, addr_end - addr_start);
4254 b->cond_string = savestring (cond_start, cond_end - cond_start);
4256 b->enable = enabled;
4257 b->disposition = tempflag ? del : donttouch;
4263 warning ("Multiple breakpoints were set.");
4264 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4266 do_cleanups (old_chain);
4270 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4275 struct frame_info *frame;
4276 CORE_ADDR low, high, selected_pc = 0;
4277 char *extra_args, *level_arg, *addr_string;
4278 int extra_args_len = 0, if_arg = 0;
4281 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4284 if (default_breakpoint_valid)
4288 selected_pc = selected_frame->pc;
4293 error ("No selected frame.");
4296 error ("No default breakpoint address now.");
4300 extra_args = strchr (arg, ' ');
4304 extra_args_len = strlen (extra_args);
4305 level_arg = (char *) xmalloc (extra_args - arg);
4306 strncpy (level_arg, arg, extra_args - arg - 1);
4307 level_arg[extra_args - arg - 1] = '\0';
4311 level_arg = (char *) xmalloc (strlen (arg) + 1);
4312 strcpy (level_arg, arg);
4315 frame = parse_frame_specification (level_arg);
4317 selected_pc = frame->pc;
4324 extra_args_len = strlen (arg);
4329 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4331 addr_string = (char *) xmalloc (26 + extra_args_len);
4333 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4335 sprintf (addr_string, "*0x%s", paddr_nz (high));
4336 break_command_1 (addr_string, flag, from_tty);
4340 error ("No function contains the specified address");
4343 error ("Unable to set breakpoint at procedure exit");
4348 break_at_finish_command_1 (arg, flag, from_tty)
4353 char *addr_string, *break_string, *beg_addr_string;
4354 CORE_ADDR low, high;
4355 struct symtabs_and_lines sals;
4356 struct symtab_and_line sal;
4357 struct cleanup *old_chain;
4359 int extra_args_len = 0;
4363 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4365 if (default_breakpoint_valid)
4369 addr_string = (char *) xmalloc (15);
4370 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
4375 error ("No selected frame.");
4378 error ("No default breakpoint address now.");
4382 addr_string = (char *) xmalloc (strlen (arg) + 1);
4383 strcpy (addr_string, arg);
4389 extra_args_len = strlen (arg);
4393 /* get the stuff after the function name or address */
4394 extra_args = strchr (arg, ' ');
4398 extra_args_len = strlen (extra_args);
4405 beg_addr_string = addr_string;
4406 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4409 free (beg_addr_string);
4410 old_chain = make_cleanup (free, sals.sals);
4411 for (i = 0; (i < sals.nelts); i++)
4414 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
4416 break_string = (char *) xmalloc (extra_args_len + 26);
4418 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
4420 sprintf (break_string, "*0x%s", paddr_nz (high));
4421 break_command_1 (break_string, flag, from_tty);
4422 free (break_string);
4425 error ("No function contains the specified address");
4429 warning ("Multiple breakpoints were set.\n");
4430 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4432 do_cleanups (old_chain);
4436 /* Helper function for break_command_1 and disassemble_command. */
4439 resolve_sal_pc (sal)
4440 struct symtab_and_line *sal;
4444 if (sal->pc == 0 && sal->symtab != NULL)
4446 if (!find_line_pc (sal->symtab, sal->line, &pc))
4447 error ("No line %d in file \"%s\".",
4448 sal->line, sal->symtab->filename);
4452 if (sal->section == 0 && sal->symtab != NULL)
4454 struct blockvector *bv;
4459 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4462 b = BLOCKVECTOR_BLOCK (bv, index);
4463 sym = block_function (b);
4466 fixup_symbol_section (sym, sal->symtab->objfile);
4467 sal->section = SYMBOL_BFD_SECTION (sym);
4471 /* It really is worthwhile to have the section, so we'll just
4472 have to look harder. This case can be executed if we have
4473 line numbers but no functions (as can happen in assembly
4476 struct minimal_symbol *msym;
4478 msym = lookup_minimal_symbol_by_pc (sal->pc);
4480 sal->section = SYMBOL_BFD_SECTION (msym);
4487 break_command (arg, from_tty)
4491 break_command_1 (arg, 0, from_tty);
4495 break_at_finish_command (arg, from_tty)
4499 break_at_finish_command_1 (arg, 0, from_tty);
4503 break_at_finish_at_depth_command (arg, from_tty)
4507 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4511 tbreak_command (arg, from_tty)
4515 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4519 tbreak_at_finish_command (arg, from_tty)
4523 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4527 hbreak_command (arg, from_tty)
4531 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4535 thbreak_command (arg, from_tty)
4539 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4543 stop_command (arg, from_tty)
4547 printf_filtered ("Specify the type of breakpoint to set.\n\
4548 Usage: stop in <function | address>\n\
4553 stopin_command (arg, from_tty)
4559 if (arg == (char *) NULL)
4561 else if (*arg != '*')
4566 /* look for a ':'. If this is a line number specification, then
4567 say it is bad, otherwise, it should be an address or
4568 function/method name */
4569 while (*argptr && !hasColon)
4571 hasColon = (*argptr == ':');
4576 badInput = (*argptr != ':'); /* Not a class::method */
4578 badInput = isdigit (*arg); /* a simple line number */
4582 printf_filtered ("Usage: stop in <function | address>\n");
4584 break_command_1 (arg, 0, from_tty);
4588 stopat_command (arg, from_tty)
4594 if (arg == (char *) NULL || *arg == '*') /* no line number */
4601 /* look for a ':'. If there is a '::' then get out, otherwise
4602 it is probably a line number. */
4603 while (*argptr && !hasColon)
4605 hasColon = (*argptr == ':');
4610 badInput = (*argptr == ':'); /* we have class::method */
4612 badInput = !isdigit (*arg); /* not a line number */
4616 printf_filtered ("Usage: stop at <line>\n");
4618 break_command_1 (arg, 0, from_tty);
4622 /* accessflag: hw_write: watch write,
4623 hw_read: watch read,
4624 hw_access: watch access (read or write) */
4626 watch_command_1 (arg, accessflag, from_tty)
4631 struct breakpoint *b;
4632 struct symtab_and_line sal;
4633 struct expression *exp;
4634 struct block *exp_valid_block;
4635 struct value *val, *mark;
4636 struct frame_info *frame;
4637 struct frame_info *prev_frame = NULL;
4638 char *exp_start = NULL;
4639 char *exp_end = NULL;
4640 char *tok, *end_tok;
4642 char *cond_start = NULL;
4643 char *cond_end = NULL;
4644 struct expression *cond = NULL;
4645 int i, other_type_used, target_resources_ok = 0;
4646 enum bptype bp_type;
4649 INIT_SAL (&sal); /* initialize to zeroes */
4651 /* Parse arguments. */
4652 innermost_block = NULL;
4654 exp = parse_exp_1 (&arg, 0, 0);
4656 exp_valid_block = innermost_block;
4657 mark = value_mark ();
4658 val = evaluate_expression (exp);
4659 release_value (val);
4660 if (VALUE_LAZY (val))
4661 value_fetch_lazy (val);
4664 while (*tok == ' ' || *tok == '\t')
4668 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4671 toklen = end_tok - tok;
4672 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4674 tok = cond_start = end_tok + 1;
4675 cond = parse_exp_1 (&tok, 0, 0);
4679 error ("Junk at end of command.");
4681 if (accessflag == hw_read)
4682 bp_type = bp_read_watchpoint;
4683 else if (accessflag == hw_access)
4684 bp_type = bp_access_watchpoint;
4686 bp_type = bp_hardware_watchpoint;
4688 mem_cnt = can_use_hardware_watchpoint (val);
4689 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
4690 error ("Expression cannot be implemented with read/access watchpoint.");
4693 i = hw_watchpoint_used_count (bp_type, &other_type_used);
4694 target_resources_ok =
4695 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
4697 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
4698 error ("Target does not support this type of hardware watchpoint.");
4700 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
4701 error ("Target can only support one kind of HW watchpoint at a time.");
4704 #if defined(HPUXHPPA)
4705 /* On HP-UX if you set a h/w
4706 watchpoint before the "run" command, the inferior dies with a e.g.,
4707 SIGILL once you start it. I initially believed this was due to a
4708 bad interaction between page protection traps and the initial
4709 startup sequence by the dynamic linker.
4711 However, I tried avoiding that by having HP-UX's implementation of
4712 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
4713 yet, which forced slow watches before a "run" or "attach", and it
4714 still fails somewhere in the startup code.
4716 Until I figure out what's happening, I'm disallowing watches altogether
4717 before the "run" or "attach" command. We'll tell the user they must
4718 set watches after getting the program started. */
4719 if (!target_has_execution)
4721 warning ("can't do that without a running program; try \"break main\", \"run\" first");
4724 #endif /* HPUXHPPA */
4726 /* Now set up the breakpoint. */
4727 b = set_raw_breakpoint (sal);
4728 set_breakpoint_count (breakpoint_count + 1);
4729 b->number = breakpoint_count;
4730 b->disposition = donttouch;
4732 b->exp_valid_block = exp_valid_block;
4733 b->exp_string = savestring (exp_start, exp_end - exp_start);
4737 b->cond_string = savestring (cond_start, cond_end - cond_start);
4741 frame = block_innermost_frame (exp_valid_block);
4744 prev_frame = get_prev_frame (frame);
4745 b->watchpoint_frame = frame->frame;
4748 b->watchpoint_frame = (CORE_ADDR) 0;
4750 if (mem_cnt && target_resources_ok > 0)
4753 b->type = bp_watchpoint;
4755 /* If the expression is "local", then set up a "watchpoint scope"
4756 breakpoint at the point where we've left the scope of the watchpoint
4758 if (innermost_block)
4762 struct breakpoint *scope_breakpoint;
4763 struct symtab_and_line scope_sal;
4765 INIT_SAL (&scope_sal); /* initialize to zeroes */
4766 scope_sal.pc = get_frame_pc (prev_frame);
4767 scope_sal.section = find_pc_overlay (scope_sal.pc);
4769 scope_breakpoint = set_raw_breakpoint (scope_sal);
4770 set_breakpoint_count (breakpoint_count + 1);
4771 scope_breakpoint->number = breakpoint_count;
4773 scope_breakpoint->type = bp_watchpoint_scope;
4774 scope_breakpoint->enable = enabled;
4776 /* Automatically delete the breakpoint when it hits. */
4777 scope_breakpoint->disposition = del;
4779 /* Only break in the proper frame (help with recursion). */
4780 scope_breakpoint->frame = prev_frame->frame;
4782 /* Set the address at which we will stop. */
4783 scope_breakpoint->address = get_frame_pc (prev_frame);
4785 /* The scope breakpoint is related to the watchpoint. We
4786 will need to act on them together. */
4787 b->related_breakpoint = scope_breakpoint;
4790 value_free_to_mark (mark);
4794 /* Return count of locations need to be watched and can be handled
4795 in hardware. If the watchpoint can not be handled
4796 in hardware return zero. */
4798 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
4799 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
4800 ((BYTE_SIZE) <= (REGISTER_SIZE))
4803 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
4804 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
4805 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
4809 can_use_hardware_watchpoint (v)
4812 int found_memory_cnt = 0;
4814 /* Did the user specifically forbid us to use hardware watchpoints? */
4815 if (!can_use_hw_watchpoints)
4818 /* Make sure that the value of the expression depends only upon
4819 memory contents, and values computed from them within GDB. If we
4820 find any register references or function calls, we can't use a
4821 hardware watchpoint.
4823 The idea here is that evaluating an expression generates a series
4824 of values, one holding the value of every subexpression. (The
4825 expression a*b+c has five subexpressions: a, b, a*b, c, and
4826 a*b+c.) GDB's values hold almost enough information to establish
4827 the criteria given above --- they identify memory lvalues,
4828 register lvalues, computed values, etcetera. So we can evaluate
4829 the expression, and then scan the chain of values that leaves
4830 behind to decide whether we can detect any possible change to the
4831 expression's final value using only hardware watchpoints.
4833 However, I don't think that the values returned by inferior
4834 function calls are special in any way. So this function may not
4835 notice that an expression involving an inferior function call
4836 can't be watched with hardware watchpoints. FIXME. */
4837 for (; v; v = v->next)
4839 if (VALUE_LVAL (v) == lval_memory)
4842 /* A lazy memory lvalue is one that GDB never needed to fetch;
4843 we either just used its address (e.g., `a' in `a.b') or
4844 we never needed it at all (e.g., `a' in `a,b'). */
4848 /* Ahh, memory we actually used! Check if we can cover
4849 it with hardware watchpoints. */
4850 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
4851 int len = TYPE_LENGTH (VALUE_TYPE (v));
4853 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
4859 else if (v->lval != not_lval && v->modifiable == 0)
4860 return 0; /* ??? What does this represent? */
4861 else if (v->lval == lval_register)
4862 return 0; /* cannot watch a register with a HW watchpoint */
4865 /* The expression itself looks suitable for using a hardware
4866 watchpoint, but give the target machine a chance to reject it. */
4867 return found_memory_cnt;
4871 watch_command (arg, from_tty)
4875 watch_command_1 (arg, hw_write, from_tty);
4879 rwatch_command (arg, from_tty)
4883 watch_command_1 (arg, hw_read, from_tty);
4887 awatch_command (arg, from_tty)
4891 watch_command_1 (arg, hw_access, from_tty);
4895 /* Helper routines for the until_command routine in infcmd.c. Here
4896 because it uses the mechanisms of breakpoints. */
4898 /* This function is called by fetch_inferior_event via the
4899 cmd_continuation pointer, to complete the until command. It takes
4900 care of cleaning up the temporary breakpoints set up by the until
4903 until_break_command_continuation (struct continuation_arg *arg)
4905 /* Do all the exec cleanups, which at this point should only be the
4906 one set up in the first part of the until_break_command
4908 do_exec_cleanups (ALL_CLEANUPS);
4913 until_break_command (arg, from_tty)
4917 struct symtabs_and_lines sals;
4918 struct symtab_and_line sal;
4919 struct frame_info *prev_frame = get_prev_frame (selected_frame);
4920 struct breakpoint *breakpoint;
4921 struct cleanup *old_chain;
4923 clear_proceed_status ();
4925 /* Set a breakpoint where the user wants it and at return from
4928 if (default_breakpoint_valid)
4929 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
4930 default_breakpoint_line, (char ***) NULL);
4932 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
4933 0, (char ***) NULL);
4935 if (sals.nelts != 1)
4936 error ("Couldn't get information on specified line.");
4939 free ((PTR) sals.sals); /* malloc'd, so freed */
4942 error ("Junk at end of arguments.");
4944 resolve_sal_pc (&sal);
4946 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
4948 if (!event_loop_p || !target_can_async_p ())
4949 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
4952 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4954 /* If we are running asynchronously, and the target supports async
4955 execution, we are not waiting for the target to stop, in the call
4956 tp proceed, below. This means that we cannot delete the
4957 brekpoints until the target has actually stopped. The only place
4958 where we get a chance to do that is in fetch_inferior_event, so
4959 we must set things up for that. */
4961 if (event_loop_p && target_can_async_p ())
4963 /* In this case we don't need args for the continuation, because
4964 all it needs to do is do the cleanups in the
4965 exec_cleanup_chain, which will be only those inserted by this
4966 function. We can get away by using ALL_CLEANUPS. */
4967 add_continuation (until_break_command_continuation, NULL);
4970 /* Keep within the current frame */
4974 sal = find_pc_line (prev_frame->pc, 0);
4975 sal.pc = prev_frame->pc;
4976 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
4977 if (!event_loop_p || !target_can_async_p ())
4978 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4980 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
4983 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
4984 /* Do the cleanups now, anly if we are not running asynchronously,
4985 of if we are, but the target is still synchronous. */
4986 if (!event_loop_p || !target_can_async_p ())
4987 do_cleanups (old_chain);
4991 /* These aren't used; I don't konw what they were for. */
4992 /* Set a breakpoint at the catch clause for NAME. */
4994 catch_breakpoint (name)
5000 disable_catch_breakpoint ()
5005 delete_catch_breakpoint ()
5010 enable_catch_breakpoint ()
5017 struct sal_chain *next;
5018 struct symtab_and_line sal;
5022 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5023 had been commented out in the v.4.16 sources, and stays
5024 disabled there now because "catch NAME" syntax isn't allowed.
5026 /* This isn't used; I don't know what it was for. */
5027 /* For each catch clause identified in ARGS, run FUNCTION
5028 with that clause as an argument. */
5029 static struct symtabs_and_lines
5030 map_catch_names (args, function)
5034 register char *p = args;
5036 struct symtabs_and_lines sals;
5038 struct sal_chain *sal_chain = 0;
5042 error_no_arg ("one or more catch names");
5050 /* Don't swallow conditional part. */
5051 if (p1[0] == 'i' && p1[1] == 'f'
5052 && (p1[2] == ' ' || p1[2] == '\t'))
5058 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5062 if (*p1 && *p1 != ' ' && *p1 != '\t')
5063 error ("Arguments must be catch names.");
5069 struct sal_chain *next = (struct sal_chain *)
5070 alloca (sizeof (struct sal_chain));
5071 next->next = sal_chain;
5072 next->sal = get_catch_sal (p);
5077 printf_unfiltered ("No catch clause for exception %s.\n", p);
5082 while (*p == ' ' || *p == '\t')
5088 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5090 static struct symtabs_and_lines
5091 get_catch_sals (this_level_only)
5092 int this_level_only;
5094 register struct blockvector *bl;
5095 register struct block *block;
5096 int index, have_default = 0;
5098 struct symtabs_and_lines sals;
5099 struct sal_chain *sal_chain = 0;
5100 char *blocks_searched;
5102 /* Not sure whether an error message is always the correct response,
5103 but it's better than a core dump. */
5104 if (selected_frame == NULL)
5105 error ("No selected frame.");
5106 block = get_frame_block (selected_frame);
5107 pc = selected_frame->pc;
5113 error ("No symbol table info available.\n");
5115 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5116 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5117 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5121 CORE_ADDR end = BLOCK_END (block) - 4;
5124 if (bl != blockvector_for_pc (end, &index))
5125 error ("blockvector blotch");
5126 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5127 error ("blockvector botch");
5128 last_index = BLOCKVECTOR_NBLOCKS (bl);
5131 /* Don't print out blocks that have gone by. */
5132 while (index < last_index
5133 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5136 while (index < last_index
5137 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5139 if (blocks_searched[index] == 0)
5141 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5144 register struct symbol *sym;
5146 nsyms = BLOCK_NSYMS (b);
5148 for (i = 0; i < nsyms; i++)
5150 sym = BLOCK_SYM (b, i);
5151 if (STREQ (SYMBOL_NAME (sym), "default"))
5157 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5159 struct sal_chain *next = (struct sal_chain *)
5160 alloca (sizeof (struct sal_chain));
5161 next->next = sal_chain;
5162 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5167 blocks_searched[index] = 1;
5173 if (sal_chain && this_level_only)
5176 /* After handling the function's top-level block, stop.
5177 Don't continue to its superblock, the block of
5178 per-file symbols. */
5179 if (BLOCK_FUNCTION (block))
5181 block = BLOCK_SUPERBLOCK (block);
5186 struct sal_chain *tmp_chain;
5188 /* Count the number of entries. */
5189 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5190 tmp_chain = tmp_chain->next)
5194 sals.sals = (struct symtab_and_line *)
5195 xmalloc (index * sizeof (struct symtab_and_line));
5196 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5197 sals.sals[index] = sal_chain->sal;
5204 ep_skip_leading_whitespace (s)
5207 if ((s == NULL) || (*s == NULL))
5209 while (isspace (**s))
5213 /* This function examines a string, and attempts to find a token
5214 that might be an event name in the leading characters. If a
5215 possible match is found, a pointer to the last character of
5216 the token is returned. Else, NULL is returned. */
5219 ep_find_event_name_end (arg)
5223 char *event_name_end = NULL;
5225 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5229 /* We break out of the loop when we find a token delimiter.
5230 Basically, we're looking for alphanumerics and underscores;
5231 anything else delimites the token. */
5234 if (!isalnum (*s) && (*s != '_'))
5240 return event_name_end;
5244 /* This function attempts to parse an optional "if <cond>" clause
5245 from the arg string. If one is not found, it returns NULL.
5247 Else, it returns a pointer to the condition string. (It does not
5248 attempt to evaluate the string against a particular block.) And,
5249 it updates arg to point to the first character following the parsed
5250 if clause in the arg string. */
5253 ep_parse_optional_if_clause (arg)
5258 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5261 /* Skip the "if" keyword. */
5264 /* Skip any extra leading whitespace, and record the start of the
5265 condition string. */
5266 ep_skip_leading_whitespace (arg);
5269 /* Assume that the condition occupies the remainder of the arg string. */
5270 (*arg) += strlen (cond_string);
5275 /* This function attempts to parse an optional filename from the arg
5276 string. If one is not found, it returns NULL.
5278 Else, it returns a pointer to the parsed filename. (This function
5279 makes no attempt to verify that a file of that name exists, or is
5280 accessible.) And, it updates arg to point to the first character
5281 following the parsed filename in the arg string.
5283 Note that clients needing to preserve the returned filename for
5284 future access should copy it to their own buffers. */
5286 ep_parse_optional_filename (arg)
5289 static char filename[1024];
5294 if ((*arg_p == '\0') || isspace (*arg_p))
5312 /* Commands to deal with catching events, such as signals, exceptions,
5313 process start/exit, etc. */
5317 catch_fork, catch_vfork
5321 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5322 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
5328 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
5329 catch_fork_kind fork_kind;
5334 char *cond_string = NULL;
5336 ep_skip_leading_whitespace (&arg);
5338 /* The allowed syntax is:
5340 catch [v]fork if <cond>
5342 First, check if there's an if clause. */
5343 cond_string = ep_parse_optional_if_clause (&arg);
5345 if ((*arg != '\0') && !isspace (*arg))
5346 error ("Junk at end of arguments.");
5348 /* If this target supports it, create a fork or vfork catchpoint
5349 and enable reporting of such events. */
5353 create_fork_event_catchpoint (tempflag, cond_string);
5356 create_vfork_event_catchpoint (tempflag, cond_string);
5359 error ("unsupported or unknown fork kind; cannot catch it");
5365 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5367 catch_exec_command_1 (arg, tempflag, from_tty)
5372 char *cond_string = NULL;
5374 ep_skip_leading_whitespace (&arg);
5376 /* The allowed syntax is:
5378 catch exec if <cond>
5380 First, check if there's an if clause. */
5381 cond_string = ep_parse_optional_if_clause (&arg);
5383 if ((*arg != '\0') && !isspace (*arg))
5384 error ("Junk at end of arguments.");
5386 /* If this target supports it, create an exec catchpoint
5387 and enable reporting of such events. */
5388 create_exec_event_catchpoint (tempflag, cond_string);
5392 #if defined(SOLIB_ADD)
5394 catch_load_command_1 (arg, tempflag, from_tty)
5399 char *dll_pathname = NULL;
5400 char *cond_string = NULL;
5402 ep_skip_leading_whitespace (&arg);
5404 /* The allowed syntax is:
5406 catch load if <cond>
5407 catch load <filename>
5408 catch load <filename> if <cond>
5410 The user is not allowed to specify the <filename> after an
5413 We'll ignore the pathological case of a file named "if".
5415 First, check if there's an if clause. If so, then there
5416 cannot be a filename. */
5417 cond_string = ep_parse_optional_if_clause (&arg);
5419 /* If there was an if clause, then there cannot be a filename.
5420 Else, there might be a filename and an if clause. */
5421 if (cond_string == NULL)
5423 dll_pathname = ep_parse_optional_filename (&arg);
5424 ep_skip_leading_whitespace (&arg);
5425 cond_string = ep_parse_optional_if_clause (&arg);
5428 if ((*arg != '\0') && !isspace (*arg))
5429 error ("Junk at end of arguments.");
5431 /* Create a load breakpoint that only triggers when a load of
5432 the specified dll (or any dll, if no pathname was specified)
5434 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
5435 dll_pathname, cond_string);
5439 catch_unload_command_1 (arg, tempflag, from_tty)
5444 char *dll_pathname = NULL;
5445 char *cond_string = NULL;
5447 ep_skip_leading_whitespace (&arg);
5449 /* The allowed syntax is:
5451 catch unload if <cond>
5452 catch unload <filename>
5453 catch unload <filename> if <cond>
5455 The user is not allowed to specify the <filename> after an
5458 We'll ignore the pathological case of a file named "if".
5460 First, check if there's an if clause. If so, then there
5461 cannot be a filename. */
5462 cond_string = ep_parse_optional_if_clause (&arg);
5464 /* If there was an if clause, then there cannot be a filename.
5465 Else, there might be a filename and an if clause. */
5466 if (cond_string == NULL)
5468 dll_pathname = ep_parse_optional_filename (&arg);
5469 ep_skip_leading_whitespace (&arg);
5470 cond_string = ep_parse_optional_if_clause (&arg);
5473 if ((*arg != '\0') && !isspace (*arg))
5474 error ("Junk at end of arguments.");
5476 /* Create an unload breakpoint that only triggers when an unload of
5477 the specified dll (or any dll, if no pathname was specified)
5479 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
5480 dll_pathname, cond_string);
5482 #endif /* SOLIB_ADD */
5484 /* Commands to deal with catching exceptions. */
5486 /* Set a breakpoint at the specified callback routine for an
5487 exception event callback */
5490 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
5493 enum exception_event_kind ex_event;
5494 struct symtab_and_line *sal;
5496 struct breakpoint *b;
5497 int thread = -1; /* All threads. */
5499 if (!sal) /* no exception support? */
5502 b = set_raw_breakpoint (*sal);
5503 set_breakpoint_count (breakpoint_count + 1);
5504 b->number = breakpoint_count;
5506 b->cond_string = (cond_string == NULL) ?
5507 NULL : savestring (cond_string, strlen (cond_string));
5509 b->addr_string = NULL;
5510 b->enable = enabled;
5511 b->disposition = tempflag ? del : donttouch;
5514 case EX_EVENT_THROW:
5515 b->type = bp_catch_throw;
5517 case EX_EVENT_CATCH:
5518 b->type = bp_catch_catch;
5520 default: /* error condition */
5522 b->enable = disabled;
5523 error ("Internal error -- invalid catchpoint kind");
5528 /* Deal with "catch catch" and "catch throw" commands */
5531 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
5532 enum exception_event_kind ex_event;
5537 char *cond_string = NULL;
5538 struct symtab_and_line *sal = NULL;
5540 ep_skip_leading_whitespace (&arg);
5542 cond_string = ep_parse_optional_if_clause (&arg);
5544 if ((*arg != '\0') && !isspace (*arg))
5545 error ("Junk at end of arguments.");
5547 if ((ex_event != EX_EVENT_THROW) &&
5548 (ex_event != EX_EVENT_CATCH))
5549 error ("Unsupported or unknown exception event; cannot catch it");
5551 /* See if we can find a callback routine */
5552 sal = target_enable_exception_callback (ex_event, 1);
5556 /* We have callbacks from the runtime system for exceptions.
5557 Set a breakpoint on the sal found, if no errors */
5558 if (sal != (struct symtab_and_line *) -1)
5559 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
5561 return; /* something went wrong with setting up callbacks */
5565 /* No callbacks from runtime system for exceptions.
5566 Try GNU C++ exception breakpoints using labels in debug info. */
5567 if (ex_event == EX_EVENT_CATCH)
5569 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
5571 else if (ex_event == EX_EVENT_THROW)
5573 /* Set a breakpoint on __raise_exception () */
5575 warning ("Unsupported with this platform/compiler combination.");
5576 warning ("Perhaps you can achieve the effect you want by setting");
5577 warning ("a breakpoint on __raise_exception().");
5582 /* Cover routine to allow wrapping target_enable_exception_catchpoints
5583 inside a catch_errors */
5586 cover_target_enable_exception_callback (arg)
5589 args_for_catchpoint_enable *args = arg;
5590 struct symtab_and_line *sal;
5591 sal = target_enable_exception_callback (args->kind, args->enable);
5594 else if (sal == (struct symtab_and_line *) -1)
5597 return 1; /*is valid */
5602 /* This is the original v.4.16 and earlier version of the
5603 catch_command_1() function. Now that other flavours of "catch"
5604 have been introduced, and since exception handling can be handled
5605 in other ways (through target ops) also, this is used only for the
5606 GNU C++ exception handling system.
5607 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
5608 "catch NAME" is now no longer allowed in catch_command_1(). Also,
5609 there was no code in GDB 4.16 for "catch throw".
5611 Called from catch_exception_command_1 () */
5615 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
5620 /* First, translate ARG into something we can deal with in terms
5623 struct symtabs_and_lines sals;
5624 struct symtab_and_line sal;
5625 register struct expression *cond = 0;
5626 register struct breakpoint *b;
5630 INIT_SAL (&sal); /* initialize to zeroes */
5632 /* If no arg given, or if first arg is 'if ', all active catch clauses
5633 are breakpointed. */
5635 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
5636 && (arg[2] == ' ' || arg[2] == '\t')))
5638 /* Grab all active catch clauses. */
5639 sals = get_catch_sals (0);
5643 /* Grab selected catch clauses. */
5644 error ("catch NAME not implemented");
5647 /* Not sure why this code has been disabled. I'm leaving
5648 it disabled. We can never come here now anyway
5649 since we don't allow the "catch NAME" syntax.
5652 /* This isn't used; I don't know what it was for. */
5653 sals = map_catch_names (arg, catch_breakpoint);
5661 for (i = 0; i < sals.nelts; i++)
5663 resolve_sal_pc (&sals.sals[i]);
5667 if (arg[0] == 'i' && arg[1] == 'f'
5668 && (arg[2] == ' ' || arg[2] == '\t'))
5669 cond = parse_exp_1 ((arg += 2, &arg),
5670 block_for_pc (sals.sals[i].pc), 0);
5672 error ("Junk at end of arguments.");
5677 for (i = 0; i < sals.nelts; i++)
5682 describe_other_breakpoints (sal.pc, sal.section);
5684 b = set_raw_breakpoint (sal);
5685 set_breakpoint_count (breakpoint_count + 1);
5686 b->number = breakpoint_count;
5688 /* Important -- this is an ordinary breakpoint. For platforms
5689 with callback support for exceptions,
5690 create_exception_catchpoint() will create special bp types
5691 (bp_catch_catch and bp_catch_throw), and there is code in
5692 insert_breakpoints() and elsewhere that depends on that. */
5693 b->type = bp_breakpoint;
5696 b->enable = enabled;
5697 b->disposition = tempflag ? del : donttouch;
5704 warning ("Multiple breakpoints were set.");
5705 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5707 free ((PTR) sals.sals);
5711 /* This creates a temporary internal breakpoint
5712 just to placate infrun */
5713 static struct breakpoint *
5714 create_temp_exception_breakpoint (pc)
5717 struct symtab_and_line sal;
5718 struct breakpoint *b;
5725 b = set_raw_breakpoint (sal);
5727 error ("Internal error -- couldn't set temp exception breakpoint");
5729 b->type = bp_breakpoint;
5730 b->disposition = del;
5731 b->enable = enabled;
5733 b->number = internal_breakpoint_number--;
5739 catch_command_1 (arg, tempflag, from_tty)
5745 /* The first argument may be an event name, such as "start" or "load".
5746 If so, then handle it as such. If it doesn't match an event name,
5747 then attempt to interpret it as an exception name. (This latter is
5748 the v4.16-and-earlier GDB meaning of the "catch" command.)
5750 First, try to find the bounds of what might be an event name. */
5751 char *arg1_start = arg;
5755 if (arg1_start == NULL)
5757 /* Old behaviour was to use pre-v-4.16 syntax */
5758 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5760 /* Now, this is not allowed */
5761 error ("Catch requires an event name.");
5764 arg1_end = ep_find_event_name_end (arg1_start);
5765 if (arg1_end == NULL)
5766 error ("catch requires an event");
5767 arg1_length = arg1_end + 1 - arg1_start;
5769 /* Try to match what we found against known event names. */
5770 if (strncmp (arg1_start, "signal", arg1_length) == 0)
5772 error ("Catch of signal not yet implemented");
5774 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
5776 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
5777 tempflag, from_tty);
5779 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
5781 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
5782 tempflag, from_tty);
5784 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
5786 error ("Catch of thread_start not yet implemented");
5788 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
5790 error ("Catch of thread_exit not yet implemented");
5792 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
5794 error ("Catch of thread_join not yet implemented");
5796 else if (strncmp (arg1_start, "start", arg1_length) == 0)
5798 error ("Catch of start not yet implemented");
5800 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
5802 error ("Catch of exit not yet implemented");
5804 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
5806 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
5807 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
5809 error ("Catch of fork not yet implemented");
5812 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
5814 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
5815 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
5817 error ("Catch of vfork not yet implemented");
5820 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
5822 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5823 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
5825 error ("Catch of exec not yet implemented");
5828 else if (strncmp (arg1_start, "load", arg1_length) == 0)
5830 #if defined(SOLIB_ADD)
5831 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
5833 error ("Catch of load not implemented");
5836 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
5838 #if defined(SOLIB_ADD)
5839 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
5841 error ("Catch of load not implemented");
5844 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
5846 error ("Catch of stop not yet implemented");
5849 /* This doesn't appear to be an event name */
5853 /* Pre-v.4.16 behaviour was to treat the argument
5854 as the name of an exception */
5855 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
5856 /* Now this is not allowed */
5857 error ("Unknown event kind specified for catch");
5862 /* Used by the gui, could be made a worker for other things. */
5865 set_breakpoint_sal (sal)
5866 struct symtab_and_line sal;
5868 struct breakpoint *b;
5869 b = set_raw_breakpoint (sal);
5870 set_breakpoint_count (breakpoint_count + 1);
5871 b->number = breakpoint_count;
5872 b->type = bp_breakpoint;
5879 /* These aren't used; I don't know what they were for. */
5880 /* Disable breakpoints on all catch clauses described in ARGS. */
5882 disable_catch (args)
5885 /* Map the disable command to catch clauses described in ARGS. */
5888 /* Enable breakpoints on all catch clauses described in ARGS. */
5893 /* Map the disable command to catch clauses described in ARGS. */
5896 /* Delete breakpoints on all catch clauses in the active scope. */
5901 /* Map the delete command to catch clauses described in ARGS. */
5906 catch_command (arg, from_tty)
5910 catch_command_1 (arg, 0, from_tty);
5915 tcatch_command (arg, from_tty)
5919 catch_command_1 (arg, 1, from_tty);
5924 clear_command (arg, from_tty)
5928 register struct breakpoint *b, *b1;
5930 struct symtabs_and_lines sals;
5931 struct symtab_and_line sal;
5932 register struct breakpoint *found;
5937 sals = decode_line_spec (arg, 1);
5942 sals.sals = (struct symtab_and_line *)
5943 xmalloc (sizeof (struct symtab_and_line));
5944 INIT_SAL (&sal); /* initialize to zeroes */
5945 sal.line = default_breakpoint_line;
5946 sal.symtab = default_breakpoint_symtab;
5947 sal.pc = default_breakpoint_address;
5948 if (sal.symtab == 0)
5949 error ("No source file specified.");
5957 /* For each line spec given, delete bps which correspond
5958 to it. We do this in two loops: the first loop looks at
5959 the initial bp(s) in the chain which should be deleted,
5960 the second goes down the rest of the chain looking ahead
5961 one so it can take those bps off the chain without messing
5965 for (i = 0; i < sals.nelts; i++)
5967 /* If exact pc given, clear bpts at that pc.
5968 If line given (pc == 0), clear all bpts on specified line.
5969 If defaulting, clear all bpts on default line
5972 defaulting sal.pc != 0 tests to do
5977 1 0 <can't happen> */
5980 found = (struct breakpoint *) 0;
5983 while (breakpoint_chain
5984 /* Why don't we check here that this is not
5985 a watchpoint, etc., as we do below?
5986 I can't make it fail, but don't know
5987 what's stopping the failure: a watchpoint
5988 of the same address as "sal.pc" should
5989 wind up being deleted. */
5991 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
5992 (overlay_debugging == 0 ||
5993 breakpoint_chain->section == sal.section))
5994 || ((default_match || (0 == sal.pc))
5995 && breakpoint_chain->source_file != NULL
5996 && sal.symtab != NULL
5997 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
5998 && breakpoint_chain->line_number == sal.line)))
6001 b1 = breakpoint_chain;
6002 breakpoint_chain = b1->next;
6010 && b->next->type != bp_none
6011 && b->next->type != bp_watchpoint
6012 && b->next->type != bp_hardware_watchpoint
6013 && b->next->type != bp_read_watchpoint
6014 && b->next->type != bp_access_watchpoint
6015 && (((sal.pc && (b->next->address == sal.pc)) &&
6016 (overlay_debugging == 0 ||
6017 b->next->section == sal.section))
6018 || ((default_match || (0 == sal.pc))
6019 && b->next->source_file != NULL
6020 && sal.symtab != NULL
6021 && STREQ (b->next->source_file, sal.symtab->filename)
6022 && b->next->line_number == sal.line)))
6035 error ("No breakpoint at %s.", arg);
6037 error ("No breakpoint at this line.");
6041 from_tty = 1; /* Always report if deleted more than one */
6043 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6044 breakpoints_changed ();
6048 printf_unfiltered ("%d ", found->number);
6050 delete_breakpoint (found);
6054 putchar_unfiltered ('\n');
6056 free ((PTR) sals.sals);
6059 /* Delete breakpoint in BS if they are `delete' breakpoints and
6060 all breakpoints that are marked for deletion, whether hit or not.
6061 This is called after any breakpoint is hit, or after errors. */
6064 breakpoint_auto_delete (bs)
6067 struct breakpoint *b, *temp;
6069 for (; bs; bs = bs->next)
6070 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6072 delete_breakpoint (bs->breakpoint_at);
6074 ALL_BREAKPOINTS_SAFE (b, temp)
6076 if (b->disposition == del_at_next_stop)
6077 delete_breakpoint (b);
6081 /* Delete a breakpoint and clean up all traces of it in the data
6085 delete_breakpoint (bpt)
6086 struct breakpoint *bpt;
6088 register struct breakpoint *b;
6092 error ("Internal error (attempted to delete a NULL breakpoint)");
6095 /* Has this bp already been deleted? This can happen because multiple
6096 lists can hold pointers to bp's. bpstat lists are especial culprits.
6098 One example of this happening is a watchpoint's scope bp. When the
6099 scope bp triggers, we notice that the watchpoint is out of scope, and
6100 delete it. We also delete its scope bp. But the scope bp is marked
6101 "auto-deleting", and is already on a bpstat. That bpstat is then
6102 checked for auto-deleting bp's, which are deleted.
6104 A real solution to this problem might involve reference counts in bp's,
6105 and/or giving them pointers back to their referencing bpstat's, and
6106 teaching delete_breakpoint to only free a bp's storage when no more
6107 references were extent. A cheaper bandaid was chosen. */
6108 if (bpt->type == bp_none)
6111 if (delete_breakpoint_hook)
6112 delete_breakpoint_hook (bpt);
6113 breakpoint_delete_event (bpt->number);
6116 remove_breakpoint (bpt, mark_uninserted);
6118 if (breakpoint_chain == bpt)
6119 breakpoint_chain = bpt->next;
6121 /* If we have callback-style exception catchpoints, don't go through
6122 the adjustments to the C++ runtime library etc. if the inferior
6123 isn't actually running. target_enable_exception_callback for a
6124 null target ops vector gives an undesirable error message, so we
6125 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6126 exceptions are supported in this way, it's OK for now. FIXME */
6127 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6129 static char message1[] = "Error in deleting catchpoint %d:\n";
6130 static char message[sizeof (message1) + 30];
6131 args_for_catchpoint_enable args;
6133 /* Format possible error msg */
6134 sprintf (message, message1, bpt->number);
6135 args.kind = bpt->type == bp_catch_catch ?
6136 EX_EVENT_CATCH : EX_EVENT_THROW;
6138 catch_errors (cover_target_enable_exception_callback, &args,
6139 message, RETURN_MASK_ALL);
6146 b->next = bpt->next;
6150 /* Before turning off the visuals for the bp, check to see that
6151 there are no other bps at the same address. */
6158 clearIt = (b->address != bpt->address);
6165 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6166 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6170 check_duplicates (bpt->address, bpt->section);
6171 /* If this breakpoint was inserted, and there is another breakpoint
6172 at the same address, we need to insert the other breakpoint. */
6174 && bpt->type != bp_hardware_watchpoint
6175 && bpt->type != bp_read_watchpoint
6176 && bpt->type != bp_access_watchpoint
6177 && bpt->type != bp_catch_fork
6178 && bpt->type != bp_catch_vfork
6179 && bpt->type != bp_catch_exec)
6182 if (b->address == bpt->address
6183 && b->section == bpt->section
6185 && b->enable != disabled
6186 && b->enable != shlib_disabled
6187 && b->enable != call_disabled)
6191 /* We should never reach this point if there is a permanent
6192 breakpoint at the same address as the one being deleted.
6193 If there is a permanent breakpoint somewhere, it should
6194 always be the only one inserted. */
6195 if (b->enable == permanent)
6196 internal_error ("another breakpoint was inserted on top of "
6197 "a permanent breakpoint");
6199 if (b->type == bp_hardware_breakpoint)
6200 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6202 val = target_insert_breakpoint (b->address, b->shadow_contents);
6206 target_terminal_ours_for_output ();
6207 warning ("Cannot insert breakpoint %d:", b->number);
6208 memory_error (val, b->address); /* which bombs us out */
6215 free_command_lines (&bpt->commands);
6218 if (bpt->cond_string != NULL)
6219 free (bpt->cond_string);
6220 if (bpt->addr_string != NULL)
6221 free (bpt->addr_string);
6222 if (bpt->exp != NULL)
6224 if (bpt->exp_string != NULL)
6225 free (bpt->exp_string);
6226 if (bpt->val != NULL)
6227 value_free (bpt->val);
6228 if (bpt->source_file != NULL)
6229 free (bpt->source_file);
6230 if (bpt->dll_pathname != NULL)
6231 free (bpt->dll_pathname);
6232 if (bpt->triggered_dll_pathname != NULL)
6233 free (bpt->triggered_dll_pathname);
6234 if (bpt->exec_pathname != NULL)
6235 free (bpt->exec_pathname);
6237 /* Be sure no bpstat's are pointing at it after it's been freed. */
6238 /* FIXME, how can we find all bpstat's?
6239 We just check stop_bpstat for now. */
6240 for (bs = stop_bpstat; bs; bs = bs->next)
6241 if (bs->breakpoint_at == bpt)
6243 bs->breakpoint_at = NULL;
6245 /* we'd call bpstat_clear_actions, but that free's stuff and due
6246 to the multiple pointers pointing to one item with no
6247 reference counts found anywhere through out the bpstat's (how
6248 do you spell fragile?), we don't want to free things twice --
6249 better a memory leak than a corrupt malloc pool! */
6250 bs->commands = NULL;
6253 /* On the chance that someone will soon try again to delete this same
6254 bp, we mark it as deleted before freeing its storage. */
6255 bpt->type = bp_none;
6261 delete_command (arg, from_tty)
6265 struct breakpoint *b, *temp;
6269 int breaks_to_delete = 0;
6271 /* Delete all breakpoints if no argument.
6272 Do not delete internal or call-dummy breakpoints, these
6273 have to be deleted with an explicit breakpoint number argument. */
6276 if (b->type != bp_call_dummy &&
6277 b->type != bp_shlib_event &&
6279 breaks_to_delete = 1;
6282 /* Ask user only if there are some breakpoints to delete. */
6284 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6286 ALL_BREAKPOINTS_SAFE (b, temp)
6288 if (b->type != bp_call_dummy &&
6289 b->type != bp_shlib_event &&
6291 delete_breakpoint (b);
6296 map_breakpoint_numbers (arg, delete_breakpoint);
6299 /* Reset a breakpoint given it's struct breakpoint * BINT.
6300 The value we return ends up being the return value from catch_errors.
6301 Unused in this case. */
6304 breakpoint_re_set_one (bint)
6307 /* get past catch_errs */
6308 struct breakpoint *b = (struct breakpoint *) bint;
6311 struct symtabs_and_lines sals;
6313 enum enable save_enable;
6318 warning ("attempted to reset apparently deleted breakpoint #%d?",
6322 case bp_hardware_breakpoint:
6324 case bp_catch_unload:
6325 if (b->addr_string == NULL)
6327 /* Anything without a string can't be re-set. */
6328 delete_breakpoint (b);
6331 /* In case we have a problem, disable this breakpoint. We'll restore
6332 its status if we succeed. */
6333 save_enable = b->enable;
6334 b->enable = disabled;
6336 set_language (b->language);
6337 input_radix = b->input_radix;
6339 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6340 for (i = 0; i < sals.nelts; i++)
6342 resolve_sal_pc (&sals.sals[i]);
6344 /* Reparse conditions, they might contain references to the
6346 if (b->cond_string != NULL)
6350 free ((PTR) b->cond);
6351 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6354 /* We need to re-set the breakpoint if the address changes... */
6355 if (b->address != sals.sals[i].pc
6356 /* ...or new and old breakpoints both have source files, and
6357 the source file name or the line number changes... */
6358 || (b->source_file != NULL
6359 && sals.sals[i].symtab != NULL
6360 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6361 || b->line_number != sals.sals[i].line)
6363 /* ...or we switch between having a source file and not having
6365 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6368 if (b->source_file != NULL)
6369 free (b->source_file);
6370 if (sals.sals[i].symtab == NULL)
6371 b->source_file = NULL;
6374 savestring (sals.sals[i].symtab->filename,
6375 strlen (sals.sals[i].symtab->filename));
6376 b->line_number = sals.sals[i].line;
6377 b->address = sals.sals[i].pc;
6379 /* Used to check for duplicates here, but that can
6380 cause trouble, as it doesn't check for disable
6385 /* Might be better to do this just once per breakpoint_re_set,
6386 rather than once for every breakpoint. */
6387 breakpoints_changed ();
6389 b->section = sals.sals[i].section;
6390 b->enable = save_enable; /* Restore it, this worked. */
6393 /* Now that this is re-enabled, check_duplicates
6395 check_duplicates (b->address, b->section);
6398 free ((PTR) sals.sals);
6402 case bp_hardware_watchpoint:
6403 case bp_read_watchpoint:
6404 case bp_access_watchpoint:
6405 innermost_block = NULL;
6406 /* The issue arises of what context to evaluate this in. The
6407 same one as when it was set, but what does that mean when
6408 symbols have been re-read? We could save the filename and
6409 functionname, but if the context is more local than that, the
6410 best we could do would be something like how many levels deep
6411 and which index at that particular level, but that's going to
6412 be less stable than filenames or function names. */
6414 /* So for now, just use a global context. */
6416 free ((PTR) b->exp);
6417 b->exp = parse_expression (b->exp_string);
6418 b->exp_valid_block = innermost_block;
6419 mark = value_mark ();
6421 value_free (b->val);
6422 b->val = evaluate_expression (b->exp);
6423 release_value (b->val);
6424 if (VALUE_LAZY (b->val))
6425 value_fetch_lazy (b->val);
6427 if (b->cond_string != NULL)
6431 free ((PTR) b->cond);
6432 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6434 if (b->enable == enabled)
6436 value_free_to_mark (mark);
6438 case bp_catch_catch:
6439 case bp_catch_throw:
6441 /* We needn't really do anything to reset these, since the mask
6442 that requests them is unaffected by e.g., new libraries being
6445 case bp_catch_vfork:
6450 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6452 /* Delete longjmp breakpoints, they will be reset later by
6453 breakpoint_re_set. */
6455 case bp_longjmp_resume:
6456 delete_breakpoint (b);
6459 /* This breakpoint is special, it's set up when the inferior
6460 starts and we really don't want to touch it. */
6461 case bp_shlib_event:
6463 /* Keep temporary breakpoints, which can be encountered when we step
6464 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6465 Otherwise these should have been blown away via the cleanup chain
6466 or by breakpoint_init_inferior when we rerun the executable. */
6469 case bp_watchpoint_scope:
6471 case bp_step_resume:
6478 /* Re-set all breakpoints after symbols have been re-loaded. */
6480 breakpoint_re_set ()
6482 struct breakpoint *b, *temp;
6483 enum language save_language;
6484 int save_input_radix;
6485 static char message1[] = "Error in re-setting breakpoint %d:\n";
6486 char message[sizeof (message1) + 30 /* slop */ ];
6488 save_language = current_language->la_language;
6489 save_input_radix = input_radix;
6490 ALL_BREAKPOINTS_SAFE (b, temp)
6492 /* Format possible error msg */
6493 sprintf (message, message1, b->number);
6494 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6496 set_language (save_language);
6497 input_radix = save_input_radix;
6499 #ifdef GET_LONGJMP_TARGET
6500 create_longjmp_breakpoint ("longjmp");
6501 create_longjmp_breakpoint ("_longjmp");
6502 create_longjmp_breakpoint ("siglongjmp");
6503 create_longjmp_breakpoint ("_siglongjmp");
6504 create_longjmp_breakpoint (NULL);
6508 /* Took this out (temporarily at least), since it produces an extra
6509 blank line at startup. This messes up the gdbtests. -PB */
6510 /* Blank line to finish off all those mention() messages we just printed. */
6511 printf_filtered ("\n");
6515 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6516 If from_tty is nonzero, it prints a message to that effect,
6517 which ends with a period (no newline). */
6519 /* Reset the thread number of this breakpoint:
6521 - If the breakpoint is for all threads, leave it as-is.
6522 - Else, reset it to the current thread for inferior_pid. */
6524 breakpoint_re_set_thread (b)
6525 struct breakpoint *b;
6527 if (b->thread != -1)
6529 if (in_thread_list (inferior_pid))
6530 b->thread = pid_to_thread_id (inferior_pid);
6535 set_ignore_count (bptnum, count, from_tty)
6536 int bptnum, count, from_tty;
6538 register struct breakpoint *b;
6544 if (b->number == bptnum)
6546 b->ignore_count = count;
6549 else if (count == 0)
6550 printf_filtered ("Will stop next time breakpoint %d is reached.",
6552 else if (count == 1)
6553 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6556 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6558 breakpoints_changed ();
6562 error ("No breakpoint number %d.", bptnum);
6565 /* Clear the ignore counts of all breakpoints. */
6567 breakpoint_clear_ignore_counts ()
6569 struct breakpoint *b;
6572 b->ignore_count = 0;
6575 /* Command to set ignore-count of breakpoint N to COUNT. */
6578 ignore_command (args, from_tty)
6586 error_no_arg ("a breakpoint number");
6588 num = get_number (&p);
6590 error ("bad breakpoint number: '%s'", args);
6592 error ("Second argument (specified ignore-count) is missing.");
6594 set_ignore_count (num,
6595 longest_to_int (value_as_long (parse_and_eval (p))),
6597 printf_filtered ("\n");
6598 breakpoints_changed ();
6601 /* Call FUNCTION on each of the breakpoints
6602 whose numbers are given in ARGS. */
6605 map_breakpoint_numbers (args, function)
6607 void (*function) PARAMS ((struct breakpoint *));
6609 register char *p = args;
6612 register struct breakpoint *b, *tmp;
6615 error_no_arg ("one or more breakpoint numbers");
6621 num = get_number_or_range (&p1);
6624 warning ("bad breakpoint number at or near '%s'", p);
6628 ALL_BREAKPOINTS_SAFE (b, tmp)
6629 if (b->number == num)
6631 struct breakpoint *related_breakpoint = b->related_breakpoint;
6633 if (related_breakpoint)
6634 function (related_breakpoint);
6637 printf_unfiltered ("No breakpoint number %d.\n", num);
6645 disable_breakpoint (bpt)
6646 struct breakpoint *bpt;
6648 /* Never disable a watchpoint scope breakpoint; we want to
6649 hit them when we leave scope so we can delete both the
6650 watchpoint and its scope breakpoint at that time. */
6651 if (bpt->type == bp_watchpoint_scope)
6654 /* You can't disable permanent breakpoints. */
6655 if (bpt->enable == permanent)
6658 bpt->enable = disabled;
6660 check_duplicates (bpt->address, bpt->section);
6662 if (modify_breakpoint_hook)
6663 modify_breakpoint_hook (bpt);
6664 breakpoint_modify_event (bpt->number);
6669 disable_command (args, from_tty)
6673 register struct breakpoint *bpt;
6675 ALL_BREAKPOINTS (bpt)
6679 warning ("attempted to disable apparently deleted breakpoint #%d?",
6684 case bp_catch_unload:
6686 case bp_catch_vfork:
6688 case bp_catch_catch:
6689 case bp_catch_throw:
6690 case bp_hardware_breakpoint:
6692 case bp_hardware_watchpoint:
6693 case bp_read_watchpoint:
6694 case bp_access_watchpoint:
6695 disable_breakpoint (bpt);
6700 map_breakpoint_numbers (args, disable_breakpoint);
6704 do_enable_breakpoint (bpt, disposition)
6705 struct breakpoint *bpt;
6706 enum bpdisp disposition;
6708 struct frame_info *save_selected_frame = NULL;
6709 int save_selected_frame_level = -1;
6710 int target_resources_ok, other_type_used;
6713 if (bpt->type == bp_hardware_breakpoint)
6716 i = hw_breakpoint_used_count ();
6717 target_resources_ok =
6718 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
6720 if (target_resources_ok == 0)
6721 error ("No hardware breakpoint support in the target.");
6722 else if (target_resources_ok < 0)
6723 error ("Hardware breakpoints used exceeds limit.");
6726 if (bpt->enable != permanent)
6727 bpt->enable = enabled;
6728 bpt->disposition = disposition;
6729 check_duplicates (bpt->address, bpt->section);
6730 breakpoints_changed ();
6732 if (bpt->type == bp_watchpoint ||
6733 bpt->type == bp_hardware_watchpoint ||
6734 bpt->type == bp_read_watchpoint ||
6735 bpt->type == bp_access_watchpoint)
6737 if (bpt->exp_valid_block != NULL)
6739 struct frame_info *fr =
6741 /* Ensure that we have the current frame. Else, this
6742 next query may pessimistically be answered as, "No,
6743 not within current scope". */
6744 get_current_frame ();
6745 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
6749 Cannot enable watchpoint %d because the block in which its expression\n\
6750 is valid is not currently in scope.\n", bpt->number);
6751 bpt->enable = disabled;
6755 save_selected_frame = selected_frame;
6756 save_selected_frame_level = selected_frame_level;
6757 select_frame (fr, -1);
6760 value_free (bpt->val);
6761 mark = value_mark ();
6762 bpt->val = evaluate_expression (bpt->exp);
6763 release_value (bpt->val);
6764 if (VALUE_LAZY (bpt->val))
6765 value_fetch_lazy (bpt->val);
6767 if (bpt->type == bp_hardware_watchpoint ||
6768 bpt->type == bp_read_watchpoint ||
6769 bpt->type == bp_access_watchpoint)
6771 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
6772 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
6774 /* Hack around 'unused var' error for some targets here */
6776 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
6777 bpt->type, i + mem_cnt, other_type_used);
6778 /* we can consider of type is bp_hardware_watchpoint, convert to
6779 bp_watchpoint in the following condition */
6780 if (target_resources_ok < 0)
6783 Cannot enable watchpoint %d because target watch resources\n\
6784 have been allocated for other watchpoints.\n", bpt->number);
6785 bpt->enable = disabled;
6786 value_free_to_mark (mark);
6791 if (save_selected_frame_level >= 0)
6792 select_and_print_frame (save_selected_frame,
6793 save_selected_frame_level);
6794 value_free_to_mark (mark);
6796 if (modify_breakpoint_hook)
6797 modify_breakpoint_hook (bpt);
6798 breakpoint_modify_event (bpt->number);
6802 enable_breakpoint (bpt)
6803 struct breakpoint *bpt;
6805 do_enable_breakpoint (bpt, bpt->disposition);
6808 /* The enable command enables the specified breakpoints (or all defined
6809 breakpoints) so they once again become (or continue to be) effective
6810 in stopping the inferior. */
6814 enable_command (args, from_tty)
6818 register struct breakpoint *bpt;
6820 ALL_BREAKPOINTS (bpt)
6824 warning ("attempted to enable apparently deleted breakpoint #%d?",
6829 case bp_catch_unload:
6831 case bp_catch_vfork:
6833 case bp_catch_catch:
6834 case bp_catch_throw:
6835 case bp_hardware_breakpoint:
6837 case bp_hardware_watchpoint:
6838 case bp_read_watchpoint:
6839 case bp_access_watchpoint:
6840 enable_breakpoint (bpt);
6845 map_breakpoint_numbers (args, enable_breakpoint);
6849 enable_once_breakpoint (bpt)
6850 struct breakpoint *bpt;
6852 do_enable_breakpoint (bpt, disable);
6857 enable_once_command (args, from_tty)
6861 map_breakpoint_numbers (args, enable_once_breakpoint);
6865 enable_delete_breakpoint (bpt)
6866 struct breakpoint *bpt;
6868 do_enable_breakpoint (bpt, del);
6873 enable_delete_command (args, from_tty)
6877 map_breakpoint_numbers (args, enable_delete_breakpoint);
6880 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
6882 struct symtabs_and_lines
6883 decode_line_spec_1 (string, funfirstline)
6887 struct symtabs_and_lines sals;
6889 error ("Empty line specification.");
6890 if (default_breakpoint_valid)
6891 sals = decode_line_1 (&string, funfirstline,
6892 default_breakpoint_symtab,
6893 default_breakpoint_line,
6896 sals = decode_line_1 (&string, funfirstline,
6897 (struct symtab *) NULL, 0, (char ***) NULL);
6899 error ("Junk at end of line specification: %s", string);
6904 _initialize_breakpoint ()
6906 struct cmd_list_element *c;
6908 breakpoint_chain = 0;
6909 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
6910 before a breakpoint is set. */
6911 breakpoint_count = 0;
6913 add_com ("ignore", class_breakpoint, ignore_command,
6914 "Set ignore-count of breakpoint number N to COUNT.\n\
6915 Usage is `ignore N COUNT'.");
6917 add_com_alias ("bc", "ignore", class_breakpoint, 1);
6919 add_com ("commands", class_breakpoint, commands_command,
6920 "Set commands to be executed when a breakpoint is hit.\n\
6921 Give breakpoint number as argument after \"commands\".\n\
6922 With no argument, the targeted breakpoint is the last one set.\n\
6923 The commands themselves follow starting on the next line.\n\
6924 Type a line containing \"end\" to indicate the end of them.\n\
6925 Give \"silent\" as the first line to make the breakpoint silent;\n\
6926 then no output is printed when it is hit, except what the commands print.");
6928 add_com ("condition", class_breakpoint, condition_command,
6929 "Specify breakpoint number N to break only if COND is true.\n\
6930 Usage is `condition N COND', where N is an integer and COND is an\n\
6931 expression to be evaluated whenever breakpoint N is reached. ");
6933 add_com ("tbreak", class_breakpoint, tbreak_command,
6934 "Set a temporary breakpoint. Args like \"break\" command.\n\
6935 Like \"break\" except the breakpoint is only temporary,\n\
6936 so it will be deleted when hit. Equivalent to \"break\" followed\n\
6937 by using \"enable delete\" on the breakpoint number.");
6938 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
6939 "Set temporary breakpoint at procedure exit. Either there should\n\
6940 be no argument or the argument must be a depth.\n");
6942 add_com ("hbreak", class_breakpoint, hbreak_command,
6943 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
6944 Like \"break\" except the breakpoint requires hardware support,\n\
6945 some target hardware may not have this support.");
6947 add_com ("thbreak", class_breakpoint, thbreak_command,
6948 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
6949 Like \"hbreak\" except the breakpoint is only temporary,\n\
6950 so it will be deleted when hit.");
6952 add_prefix_cmd ("enable", class_breakpoint, enable_command,
6953 "Enable some breakpoints.\n\
6954 Give breakpoint numbers (separated by spaces) as arguments.\n\
6955 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6956 This is used to cancel the effect of the \"disable\" command.\n\
6957 With a subcommand you can enable temporarily.",
6958 &enablelist, "enable ", 1, &cmdlist);
6960 add_com ("ab", class_breakpoint, enable_command,
6961 "Enable some breakpoints.\n\
6962 Give breakpoint numbers (separated by spaces) as arguments.\n\
6963 With no subcommand, breakpoints are enabled until you command otherwise.\n\
6964 This is used to cancel the effect of the \"disable\" command.\n\
6965 With a subcommand you can enable temporarily.");
6967 add_com_alias ("en", "enable", class_breakpoint, 1);
6969 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
6970 "Enable some breakpoints.\n\
6971 Give breakpoint numbers (separated by spaces) as arguments.\n\
6972 This is used to cancel the effect of the \"disable\" command.\n\
6973 May be abbreviated to simply \"enable\".\n",
6974 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
6976 add_cmd ("once", no_class, enable_once_command,
6977 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6978 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6981 add_cmd ("delete", no_class, enable_delete_command,
6982 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6983 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6986 add_cmd ("delete", no_class, enable_delete_command,
6987 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
6988 If a breakpoint is hit while enabled in this fashion, it is deleted.",
6991 add_cmd ("once", no_class, enable_once_command,
6992 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
6993 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
6996 add_prefix_cmd ("disable", class_breakpoint, disable_command,
6997 "Disable some breakpoints.\n\
6998 Arguments are breakpoint numbers with spaces in between.\n\
6999 To disable all breakpoints, give no argument.\n\
7000 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7001 &disablelist, "disable ", 1, &cmdlist);
7002 add_com_alias ("dis", "disable", class_breakpoint, 1);
7003 add_com_alias ("disa", "disable", class_breakpoint, 1);
7005 add_com ("sb", class_breakpoint, disable_command,
7006 "Disable some breakpoints.\n\
7007 Arguments are breakpoint numbers with spaces in between.\n\
7008 To disable all breakpoints, give no argument.\n\
7009 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7011 add_cmd ("breakpoints", class_alias, disable_command,
7012 "Disable some breakpoints.\n\
7013 Arguments are breakpoint numbers with spaces in between.\n\
7014 To disable all breakpoints, give no argument.\n\
7015 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7016 This command may be abbreviated \"disable\".",
7019 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7020 "Delete some breakpoints or auto-display expressions.\n\
7021 Arguments are breakpoint numbers with spaces in between.\n\
7022 To delete all breakpoints, give no argument.\n\
7024 Also a prefix command for deletion of other GDB objects.\n\
7025 The \"unset\" command is also an alias for \"delete\".",
7026 &deletelist, "delete ", 1, &cmdlist);
7027 add_com_alias ("d", "delete", class_breakpoint, 1);
7029 add_com ("db", class_breakpoint, delete_command,
7030 "Delete some breakpoints.\n\
7031 Arguments are breakpoint numbers with spaces in between.\n\
7032 To delete all breakpoints, give no argument.\n");
7034 add_cmd ("breakpoints", class_alias, delete_command,
7035 "Delete some breakpoints or auto-display expressions.\n\
7036 Arguments are breakpoint numbers with spaces in between.\n\
7037 To delete all breakpoints, give no argument.\n\
7038 This command may be abbreviated \"delete\".",
7041 add_com ("clear", class_breakpoint, clear_command,
7042 concat ("Clear breakpoint at specified line or function.\n\
7043 Argument may be line number, function name, or \"*\" and an address.\n\
7044 If line number is specified, all breakpoints in that line are cleared.\n\
7045 If function is specified, breakpoints at beginning of function are cleared.\n\
7046 If an address is specified, breakpoints at that address are cleared.\n\n",
7047 "With no argument, clears all breakpoints in the line that the selected frame\n\
7050 See also the \"delete\" command which clears breakpoints by number.", NULL));
7052 add_com ("break", class_breakpoint, break_command,
7053 concat ("Set breakpoint at specified line or function.\n\
7054 Argument may be line number, function name, or \"*\" and an address.\n\
7055 If line number is specified, break at start of code for that line.\n\
7056 If function is specified, break at start of code for that function.\n\
7057 If an address is specified, break at that exact address.\n",
7058 "With no arg, uses current execution address of selected stack frame.\n\
7059 This is useful for breaking on return to a stack frame.\n\
7061 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7063 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7064 add_com_alias ("b", "break", class_run, 1);
7065 add_com_alias ("br", "break", class_run, 1);
7066 add_com_alias ("bre", "break", class_run, 1);
7067 add_com_alias ("brea", "break", class_run, 1);
7069 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7070 concat ("Set breakpoint at procedure exit. \n\
7071 Argument may be function name, or \"*\" and an address.\n\
7072 If function is specified, break at end of code for that function.\n\
7073 If an address is specified, break at the end of the function that contains \n\
7074 that exact address.\n",
7075 "With no arg, uses current execution address of selected stack frame.\n\
7076 This is useful for breaking on return to a stack frame.\n\
7078 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7080 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7081 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7082 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7083 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7084 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7088 add_com_alias ("ba", "break", class_breakpoint, 1);
7089 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7090 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7091 "Set breakpoint at procedure exit. Either there should\n\
7092 be no argument or the argument must be a depth.\n");
7097 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7098 "Break in function/address or break at a line in the current file.",
7099 &stoplist, "stop ", 1, &cmdlist);
7100 add_cmd ("in", class_breakpoint, stopin_command,
7101 "Break in function or address.\n", &stoplist);
7102 add_cmd ("at", class_breakpoint, stopat_command,
7103 "Break at a line in the current file.\n", &stoplist);
7104 add_com ("status", class_info, breakpoints_info,
7105 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7106 The \"Type\" column indicates one of:\n\
7107 \tbreakpoint - normal breakpoint\n\
7108 \twatchpoint - watchpoint\n\
7109 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7110 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7111 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7112 address and file/line number respectively.\n\n",
7113 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7114 are set to the address of the last breakpoint listed.\n\n\
7115 Convenience variable \"$bpnum\" contains the number of the last\n\
7116 breakpoint set.", NULL));
7119 add_info ("breakpoints", breakpoints_info,
7120 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7121 The \"Type\" column indicates one of:\n\
7122 \tbreakpoint - normal breakpoint\n\
7123 \twatchpoint - watchpoint\n\
7124 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7125 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7126 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7127 address and file/line number respectively.\n\n",
7128 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7129 are set to the address of the last breakpoint listed.\n\n\
7130 Convenience variable \"$bpnum\" contains the number of the last\n\
7131 breakpoint set.", NULL));
7134 add_com ("lb", class_breakpoint, breakpoints_info,
7135 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7136 The \"Type\" column indicates one of:\n\
7137 \tbreakpoint - normal breakpoint\n\
7138 \twatchpoint - watchpoint\n\
7139 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7140 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7141 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7142 address and file/line number respectively.\n\n",
7143 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7144 are set to the address of the last breakpoint listed.\n\n\
7145 Convenience variable \"$bpnum\" contains the number of the last\n\
7146 breakpoint set.", NULL));
7148 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7149 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7150 The \"Type\" column indicates one of:\n\
7151 \tbreakpoint - normal breakpoint\n\
7152 \twatchpoint - watchpoint\n\
7153 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7154 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7155 \tuntil - internal breakpoint used by the \"until\" command\n\
7156 \tfinish - internal breakpoint used by the \"finish\" command\n",
7157 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7158 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7159 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7160 address and file/line number respectively.\n\n",
7161 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7162 are set to the address of the last breakpoint listed.\n\n\
7163 Convenience variable \"$bpnum\" contains the number of the last\n\
7164 breakpoint set.", NULL),
7165 &maintenanceinfolist);
7167 add_com ("catch", class_breakpoint, catch_command,
7168 "Set catchpoints to catch events.\n\
7169 Raised signals may be caught:\n\
7170 \tcatch signal - all signals\n\
7171 \tcatch signal <signame> - a particular signal\n\
7172 Raised exceptions may be caught:\n\
7173 \tcatch throw - all exceptions, when thrown\n\
7174 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7175 \tcatch catch - all exceptions, when caught\n\
7176 \tcatch catch <exceptname> - a particular exception, when caught\n\
7177 Thread or process events may be caught:\n\
7178 \tcatch thread_start - any threads, just after creation\n\
7179 \tcatch thread_exit - any threads, just before expiration\n\
7180 \tcatch thread_join - any threads, just after joins\n\
7181 Process events may be caught:\n\
7182 \tcatch start - any processes, just after creation\n\
7183 \tcatch exit - any processes, just before expiration\n\
7184 \tcatch fork - calls to fork()\n\
7185 \tcatch vfork - calls to vfork()\n\
7186 \tcatch exec - calls to exec()\n\
7187 Dynamically-linked library events may be caught:\n\
7188 \tcatch load - loads of any library\n\
7189 \tcatch load <libname> - loads of a particular library\n\
7190 \tcatch unload - unloads of any library\n\
7191 \tcatch unload <libname> - unloads of a particular library\n\
7192 The act of your program's execution stopping may also be caught:\n\
7194 C++ exceptions may be caught:\n\
7195 \tcatch throw - all exceptions, when thrown\n\
7196 \tcatch catch - all exceptions, when caught\n\
7198 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7199 after a fork or vfork is caught.\n\n\
7200 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7202 add_com ("tcatch", class_breakpoint, tcatch_command,
7203 "Set temporary catchpoints to catch events.\n\
7204 Args like \"catch\" command.\n\
7205 Like \"catch\" except the catchpoint is only temporary,\n\
7206 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7207 by using \"enable delete\" on the catchpoint number.");
7209 add_com ("watch", class_breakpoint, watch_command,
7210 "Set a watchpoint for an expression.\n\
7211 A watchpoint stops execution of your program whenever the value of\n\
7212 an expression changes.");
7214 add_com ("rwatch", class_breakpoint, rwatch_command,
7215 "Set a read watchpoint for an expression.\n\
7216 A watchpoint stops execution of your program whenever the value of\n\
7217 an expression is read.");
7219 add_com ("awatch", class_breakpoint, awatch_command,
7220 "Set a watchpoint for an expression.\n\
7221 A watchpoint stops execution of your program whenever the value of\n\
7222 an expression is either read or written.");
7224 add_info ("watchpoints", breakpoints_info,
7225 "Synonym for ``info breakpoints''.");
7228 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7229 (char *) &can_use_hw_watchpoints,
7230 "Set debugger's willingness to use watchpoint hardware.\n\
7231 If zero, gdb will not use hardware for new watchpoints, even if\n\
7232 such is available. (However, any hardware watchpoints that were\n\
7233 created before setting this to nonzero, will continue to use watchpoint\n\
7236 add_show_from_set (c, &showlist);
7238 can_use_hw_watchpoints = 1;