1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
45 #include "completer.h"
49 #include "gdb-events.h"
51 /* Prototypes for local functions. */
53 static void until_break_command_continuation (struct continuation_arg *arg);
55 static void catch_command_1 (char *, int, int);
57 static void enable_delete_command (char *, int);
59 static void enable_delete_breakpoint (struct breakpoint *);
61 static void enable_once_command (char *, int);
63 static void enable_once_breakpoint (struct breakpoint *);
65 static void disable_command (char *, int);
67 static void enable_command (char *, int);
69 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
71 static void ignore_command (char *, int);
73 static int breakpoint_re_set_one (PTR);
75 static void clear_command (char *, int);
77 static void catch_command (char *, int);
79 static void handle_gnu_4_16_catch_command (char *, int, int);
81 static struct symtabs_and_lines get_catch_sals (int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value *);
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
90 extern void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint *);
96 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
98 static void check_duplicates (struct breakpoint *);
100 static void describe_other_breakpoints (CORE_ADDR, asection *);
102 static void breakpoints_info (char *, int);
104 static void breakpoint_1 (int, int);
106 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
108 static int breakpoint_cond_eval (PTR);
110 static void cleanup_executing_breakpoints (PTR);
112 static void commands_command (char *, int);
114 static void condition_command (char *, int);
116 static int get_number_trailer (char **, int);
118 void set_breakpoint_count (int);
127 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
129 static enum print_stop_action print_it_typical (bpstat);
131 static enum print_stop_action print_bp_stop_message (bpstat bs);
135 enum exception_event_kind kind;
138 args_for_catchpoint_enable;
140 static int watchpoint_check (PTR);
142 static int cover_target_enable_exception_callback (PTR);
144 static void maintenance_info_breakpoints (char *, int);
146 static void create_longjmp_breakpoint (char *);
148 static void create_overlay_event_breakpoint (char *);
150 static int hw_breakpoint_used_count (void);
152 static int hw_watchpoint_used_count (enum bptype, int *);
154 static void hbreak_command (char *, int);
156 static void thbreak_command (char *, int);
158 static void watch_command_1 (char *, int, int);
160 static void rwatch_command (char *, int);
162 static void awatch_command (char *, int);
164 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
166 static void solib_load_unload_1 (char *hookname,
169 char *cond_string, enum bptype bp_kind);
171 static void create_fork_vfork_event_catchpoint (int tempflag,
173 enum bptype bp_kind);
175 static void break_at_finish_at_depth_command_1 (char *arg,
176 int flag, int from_tty);
178 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
180 static void stop_command (char *arg, int from_tty);
182 static void stopin_command (char *arg, int from_tty);
184 static void stopat_command (char *arg, int from_tty);
186 static char *ep_find_event_name_end (char *arg);
188 static char *ep_parse_optional_if_clause (char **arg);
190 static char *ep_parse_optional_filename (char **arg);
192 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
193 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
196 static void create_exception_catchpoint (int tempflag, char *cond_string,
197 enum exception_event_kind ex_event,
198 struct symtab_and_line *sal);
200 static void catch_exception_command_1 (enum exception_event_kind ex_event,
201 char *arg, int tempflag, int from_tty);
203 static void tcatch_command (char *arg, int from_tty);
205 static void ep_skip_leading_whitespace (char **s);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints;
213 void _initialize_breakpoint (void);
215 extern int addressprint; /* Print machine addresses? */
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands;
220 /* Walk the following statement or block through all breakpoints.
221 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
224 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
226 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
227 for (B = breakpoint_chain; \
228 B ? (TMP=B->next, 1): 0; \
231 /* True if SHIFT_INST_REGS defined, false otherwise. */
233 int must_shift_inst_regs =
234 #if defined(SHIFT_INST_REGS)
241 /* True if breakpoint hit counts should be displayed in breakpoint info. */
243 int show_breakpoint_hit_counts = 1;
245 /* Chain of all breakpoints defined. */
247 struct breakpoint *breakpoint_chain;
249 /* Number of last breakpoint made. */
251 int breakpoint_count;
253 /* Pointer to current exception event record */
254 static struct exception_event_record *current_exception_event;
256 /* Indicator of whether exception catchpoints should be nuked
257 between runs of a program */
258 int exception_catchpoints_are_fragile = 0;
260 /* Indicator of when exception catchpoints set-up should be
261 reinitialized -- e.g. when program is re-run */
262 int exception_support_initialized = 0;
264 /* This function returns a pointer to the string representation of the
265 pathname of the dynamically-linked library that has just been
268 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
269 or undefined results are guaranteed.
271 This string's contents are only valid immediately after the
272 inferior has stopped in the dynamic linker hook, and becomes
273 invalid as soon as the inferior is continued. Clients should make
274 a copy of this string if they wish to continue the inferior and
275 then access the string. */
277 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
278 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
281 /* This function returns a pointer to the string representation of the
282 pathname of the dynamically-linked library that has just been
285 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
286 TRUE, or undefined results are guaranteed.
288 This string's contents are only valid immediately after the
289 inferior has stopped in the dynamic linker hook, and becomes
290 invalid as soon as the inferior is continued. Clients should make
291 a copy of this string if they wish to continue the inferior and
292 then access the string. */
294 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
295 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
298 /* This function is called by the "catch load" command. It allows the
299 debugger to be notified by the dynamic linker when a specified
300 library file (or any library file, if filename is NULL) is loaded. */
302 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
303 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
304 error ("catch of library loads not yet implemented on this platform")
307 /* This function is called by the "catch unload" command. It allows
308 the debugger to be notified by the dynamic linker when a specified
309 library file (or any library file, if filename is NULL) is
312 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
313 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
314 error ("catch of library unloads not yet implemented on this platform")
317 /* Set breakpoint count to NUM. */
320 set_breakpoint_count (int num)
322 breakpoint_count = num;
323 set_internalvar (lookup_internalvar ("bpnum"),
324 value_from_longest (builtin_type_int, (LONGEST) num));
327 /* Used in run_command to zero the hit count when a new run starts. */
330 clear_breakpoint_hit_counts (void)
332 struct breakpoint *b;
338 /* Default address, symtab and line to put a breakpoint at
339 for "break" command with no arg.
340 if default_breakpoint_valid is zero, the other three are
341 not valid, and "break" with no arg is an error.
343 This set by print_stack_frame, which calls set_default_breakpoint. */
345 int default_breakpoint_valid;
346 CORE_ADDR default_breakpoint_address;
347 struct symtab *default_breakpoint_symtab;
348 int default_breakpoint_line;
350 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
351 Advance *PP after the string and any trailing whitespace.
353 Currently the string can either be a number or "$" followed by the name
354 of a convenience variable. Making it an expression wouldn't work well
355 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
357 TRAILER is a character which can be found after the number; most
358 commonly this is `-'. If you don't want a trailer, use \0. */
360 get_number_trailer (char **pp, int trailer)
362 int retval = 0; /* default */
366 /* Empty line means refer to the last breakpoint. */
367 return breakpoint_count;
370 /* Make a copy of the name, so we can null-terminate it
371 to pass to lookup_internalvar(). */
376 while (isalnum (*p) || *p == '_')
378 varname = (char *) alloca (p - start + 1);
379 strncpy (varname, start, p - start);
380 varname[p - start] = '\0';
381 val = value_of_internalvar (lookup_internalvar (varname));
382 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
383 retval = (int) value_as_long (val);
386 printf_filtered ("Convenience variable must have integer value.\n");
394 while (*p >= '0' && *p <= '9')
397 /* There is no number here. (e.g. "cond a == b"). */
399 /* Skip non-numeric token */
400 while (*p && !isspace((int) *p))
402 /* Return zero, which caller must interpret as error. */
408 if (!(isspace (*p) || *p == '\0' || *p == trailer))
410 /* Trailing junk: return 0 and let caller print error msg. */
411 while (!(isspace (*p) || *p == '\0' || *p == trailer))
422 /* Like get_number_trailer, but don't allow a trailer. */
424 get_number (char **pp)
426 return get_number_trailer (pp, '\0');
429 /* Parse a number or a range.
430 * A number will be of the form handled by get_number.
431 * A range will be of the form <number1> - <number2>, and
432 * will represent all the integers between number1 and number2,
435 * While processing a range, this fuction is called iteratively;
436 * At each call it will return the next value in the range.
438 * At the beginning of parsing a range, the char pointer PP will
439 * be advanced past <number1> and left pointing at the '-' token.
440 * Subsequent calls will not advance the pointer until the range
441 * is completed. The call that completes the range will advance
442 * pointer PP past <number2>.
446 get_number_or_range (char **pp)
448 static int last_retval, end_value;
449 static char *end_ptr;
450 static int in_range = 0;
454 /* Default case: pp is pointing either to a solo number,
455 or to the first number of a range. */
456 last_retval = get_number_trailer (pp, '-');
461 /* This is the start of a range (<number1> - <number2>).
462 Skip the '-', parse and remember the second number,
463 and also remember the end of the final token. */
467 while (isspace ((int) *end_ptr))
468 end_ptr++; /* skip white space */
469 end_value = get_number (temp);
470 if (end_value < last_retval)
472 error ("inverted range");
474 else if (end_value == last_retval)
476 /* degenerate range (number1 == number2). Advance the
477 token pointer so that the range will be treated as a
486 error ("negative value");
489 /* pp points to the '-' that betokens a range. All
490 number-parsing has already been done. Return the next
491 integer value (one greater than the saved previous value).
492 Do not advance the token pointer 'pp' until the end of range
495 if (++last_retval == end_value)
497 /* End of range reached; advance token pointer. */
507 /* condition N EXP -- set break condition of breakpoint N to EXP. */
510 condition_command (char *arg, int from_tty)
512 register struct breakpoint *b;
517 error_no_arg ("breakpoint number");
520 bnum = get_number (&p);
522 error ("Bad breakpoint argument: '%s'", arg);
525 if (b->number == bnum)
532 if (b->cond_string != NULL)
533 xfree (b->cond_string);
538 b->cond_string = NULL;
540 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
545 /* I don't know if it matters whether this is the string the user
546 typed in or the decompiled expression. */
547 b->cond_string = savestring (arg, strlen (arg));
548 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
550 error ("Junk at end of expression");
552 breakpoints_changed ();
556 error ("No breakpoint number %d.", bnum);
561 commands_command (char *arg, int from_tty)
563 register struct breakpoint *b;
566 struct command_line *l;
568 /* If we allowed this, we would have problems with when to
569 free the storage, if we change the commands currently
572 if (executing_breakpoint_commands)
573 error ("Can't use the \"commands\" command among a breakpoint's commands.");
576 bnum = get_number (&p);
579 error ("Unexpected extra arguments following breakpoint number.");
582 if (b->number == bnum)
586 "Type commands for when breakpoint %d is hit, one per line.",
588 l = read_command_lines (tmpbuf, from_tty);
589 free_command_lines (&b->commands);
591 breakpoints_changed ();
594 error ("No breakpoint number %d.", bnum);
597 /* Like target_read_memory() but if breakpoints are inserted, return
598 the shadow contents instead of the breakpoints themselves.
600 Read "memory data" from whatever target or inferior we have.
601 Returns zero if successful, errno value if not. EIO is used
602 for address out of bounds. If breakpoints are inserted, returns
603 shadow contents, not the breakpoints themselves. From breakpoint.c. */
606 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
609 struct breakpoint *b;
610 CORE_ADDR bp_addr = 0;
613 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
614 /* No breakpoints on this machine. */
615 return target_read_memory (memaddr, myaddr, len);
619 if (b->type == bp_none)
620 warning ("reading through apparently deleted breakpoint #%d?",
623 /* memory breakpoint? */
624 if (b->type == bp_watchpoint
625 || b->type == bp_hardware_watchpoint
626 || b->type == bp_read_watchpoint
627 || b->type == bp_access_watchpoint)
632 /* Addresses and length of the part of the breakpoint that
634 /* XXXX The m68k, sh and h8300 have different local and remote
635 breakpoint values. BREAKPOINT_FROM_PC still manages to
636 correctly determine the breakpoints memory address and size
637 for these targets. */
638 bp_addr = b->address;
640 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
645 if (bp_addr + bp_size <= memaddr)
646 /* The breakpoint is entirely before the chunk of memory we
649 if (bp_addr >= memaddr + len)
650 /* The breakpoint is entirely after the chunk of memory we are
653 /* Copy the breakpoint from the shadow contents, and recurse for
654 the things before and after. */
656 /* Offset within shadow_contents. */
659 if (bp_addr < memaddr)
661 /* Only copy the second part of the breakpoint. */
662 bp_size -= memaddr - bp_addr;
663 bptoffset = memaddr - bp_addr;
667 if (bp_addr + bp_size > memaddr + len)
669 /* Only copy the first part of the breakpoint. */
670 bp_size -= (bp_addr + bp_size) - (memaddr + len);
673 memcpy (myaddr + bp_addr - memaddr,
674 b->shadow_contents + bptoffset, bp_size);
676 if (bp_addr > memaddr)
678 /* Copy the section of memory before the breakpoint. */
679 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
684 if (bp_addr + bp_size < memaddr + len)
686 /* Copy the section of memory after the breakpoint. */
687 status = read_memory_nobpt (bp_addr + bp_size,
688 myaddr + bp_addr + bp_size - memaddr,
689 memaddr + len - (bp_addr + bp_size));
696 /* Nothing overlaps. Just call read_memory_noerr. */
697 return target_read_memory (memaddr, myaddr, len);
701 /* insert_breakpoints is used when starting or continuing the program.
702 remove_breakpoints is used when the program stops.
703 Both return zero if successful,
704 or an `errno' value if could not write the inferior. */
707 insert_breakpoints (void)
709 register struct breakpoint *b, *temp;
710 int return_val = 0; /* return success code. */
712 int disabled_breaks = 0;
714 static char message1[] = "Error inserting catchpoint %d:\n";
715 static char message[sizeof (message1) + 30];
718 ALL_BREAKPOINTS_SAFE (b, temp)
720 if (b->enable_state == bp_permanent)
721 /* Permanent breakpoints cannot be inserted or removed. */
723 else if (b->type != bp_watchpoint
724 && b->type != bp_hardware_watchpoint
725 && b->type != bp_read_watchpoint
726 && b->type != bp_access_watchpoint
727 && b->type != bp_catch_fork
728 && b->type != bp_catch_vfork
729 && b->type != bp_catch_exec
730 && b->type != bp_catch_throw
731 && b->type != bp_catch_catch
732 && b->enable_state != bp_disabled
733 && b->enable_state != bp_shlib_disabled
734 && b->enable_state != bp_call_disabled
738 if (b->type == bp_hardware_breakpoint)
739 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
742 /* Check to see if breakpoint is in an overlay section;
743 if so, we should set the breakpoint at the LMA address.
744 Only if the section is currently mapped should we ALSO
745 set a break at the VMA address. */
746 if (overlay_debugging && b->section
747 && section_is_overlay (b->section))
751 addr = overlay_unmapped_address (b->address, b->section);
752 val = target_insert_breakpoint (addr, b->shadow_contents);
753 /* This would be the time to check val, to see if the
754 breakpoint write to the load address succeeded.
755 However, this might be an ordinary occurrance, eg. if
756 the unmapped overlay is in ROM. */
757 val = 0; /* in case unmapped address failed */
758 if (section_is_mapped (b->section))
759 val = target_insert_breakpoint (b->address,
762 else /* ordinary (non-overlay) address */
763 val = target_insert_breakpoint (b->address, b->shadow_contents);
767 /* Can't set the breakpoint. */
768 #if defined (DISABLE_UNSETTABLE_BREAK)
769 if (DISABLE_UNSETTABLE_BREAK (b->address))
771 /* See also: disable_breakpoints_in_shlibs. */
773 b->enable_state = bp_shlib_disabled;
774 if (!disabled_breaks)
776 target_terminal_ours_for_output ();
777 warning ("Cannot insert breakpoint %d:", b->number);
778 warning ("Temporarily disabling shared library breakpoints:");
781 warning ("breakpoint #%d ", b->number);
786 target_terminal_ours_for_output ();
787 warning ("Cannot insert breakpoint %d:", b->number);
788 #ifdef ONE_PROCESS_WRITETEXT
789 warning ("The same program may be running in another process.");
791 memory_error (val, b->address); /* which bombs us out */
798 return_val = val; /* remember failure */
800 else if (ep_is_exception_catchpoint (b)
801 && b->enable_state != bp_disabled
802 && b->enable_state != bp_shlib_disabled
803 && b->enable_state != bp_call_disabled
808 /* If we get here, we must have a callback mechanism for exception
809 events -- with g++ style embedded label support, we insert
810 ordinary breakpoints and not catchpoints. */
811 /* Format possible error message */
812 sprintf (message, message1, b->number);
814 val = target_insert_breakpoint (b->address, b->shadow_contents);
817 /* Couldn't set breakpoint for some reason */
818 target_terminal_ours_for_output ();
819 warning ("Cannot insert catchpoint %d; disabling it.",
821 b->enable_state = bp_disabled;
825 /* Bp set, now make sure callbacks are enabled */
827 args_for_catchpoint_enable args;
828 args.kind = b->type == bp_catch_catch ?
829 EX_EVENT_CATCH : EX_EVENT_THROW;
831 val = catch_errors (cover_target_enable_exception_callback,
833 message, RETURN_MASK_ALL);
834 if (val != 0 && val != -1)
838 /* Check if something went wrong; val == 0 can be ignored */
841 /* something went wrong */
842 target_terminal_ours_for_output ();
843 warning ("Cannot insert catchpoint %d; disabling it.",
845 b->enable_state = bp_disabled;
850 return_val = val; /* remember failure */
853 else if ((b->type == bp_hardware_watchpoint ||
854 b->type == bp_read_watchpoint ||
855 b->type == bp_access_watchpoint)
856 && b->enable_state == bp_enabled
857 && b->disposition != disp_del_at_next_stop
861 struct frame_info *saved_frame;
862 int saved_level, within_current_scope;
863 struct value *mark = value_mark ();
866 /* Save the current frame and level so we can restore it after
867 evaluating the watchpoint expression on its own frame. */
868 saved_frame = selected_frame;
869 saved_level = selected_frame_level;
871 /* Determine if the watchpoint is within scope. */
872 if (b->exp_valid_block == NULL)
873 within_current_scope = 1;
876 struct frame_info *fi;
878 /* There might be no current frame at this moment if we are
879 resuming from a step over a breakpoint.
880 Set up current frame before trying to find the watchpoint
882 get_current_frame ();
883 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
884 within_current_scope = (fi != NULL);
885 if (within_current_scope)
886 select_frame (fi, -1);
889 if (within_current_scope)
891 /* Evaluate the expression and cut the chain of values
892 produced off from the value chain.
894 Make sure the value returned isn't lazy; we use
895 laziness to determine what memory GDB actually needed
896 in order to compute the value of the expression. */
897 v = evaluate_expression (b->exp);
899 value_release_to_mark (mark);
904 /* Look at each value on the value chain. */
905 for (; v; v = v->next)
907 /* If it's a memory location, and GDB actually needed
908 its contents to evaluate the expression, then we
910 if (VALUE_LVAL (v) == lval_memory
913 struct type *vtype = check_typedef (VALUE_TYPE (v));
915 /* We only watch structs and arrays if user asked
916 for it explicitly, never if they just happen to
917 appear in the middle of some value chain. */
918 if (v == b->val_chain
919 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
920 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
925 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
926 len = TYPE_LENGTH (VALUE_TYPE (v));
928 if (b->type == bp_read_watchpoint)
930 else if (b->type == bp_access_watchpoint)
933 val = target_insert_watchpoint (addr, len, type);
936 /* Don't exit the loop, try to insert
937 every value on the value chain. That's
938 because we will be removing all the
939 watches below, and removing a
940 watchpoint we didn't insert could have
948 /* Failure to insert a watchpoint on any memory value in the
949 value chain brings us here. */
952 remove_breakpoint (b, mark_uninserted);
953 warning ("Could not insert hardware watchpoint %d.",
960 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
961 printf_filtered ("because the program has left the block \n");
962 printf_filtered ("in which its expression is valid.\n");
963 if (b->related_breakpoint)
964 b->related_breakpoint->disposition = disp_del_at_next_stop;
965 b->disposition = disp_del_at_next_stop;
968 /* Restore the frame and level. */
969 if ((saved_frame != selected_frame) ||
970 (saved_level != selected_frame_level))
971 select_frame (saved_frame, saved_level);
974 return_val = val; /* remember failure */
976 else if ((b->type == bp_catch_fork
977 || b->type == bp_catch_vfork
978 || b->type == bp_catch_exec)
979 && b->enable_state == bp_enabled
987 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
990 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
993 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
996 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1001 target_terminal_ours_for_output ();
1002 warning ("Cannot insert catchpoint %d.", b->number);
1008 return_val = val; /* remember failure */
1017 remove_breakpoints (void)
1019 register struct breakpoint *b;
1026 val = remove_breakpoint (b, mark_uninserted);
1035 remove_hw_watchpoints (void)
1037 register struct breakpoint *b;
1043 && (b->type == bp_hardware_watchpoint
1044 || b->type == bp_read_watchpoint
1045 || b->type == bp_access_watchpoint))
1047 val = remove_breakpoint (b, mark_uninserted);
1056 reattach_breakpoints (int pid)
1058 register struct breakpoint *b;
1060 struct cleanup *old_chain = save_inferior_ptid ();
1062 /* Set inferior_ptid; remove_breakpoint uses this global. */
1063 inferior_ptid = pid_to_ptid (pid);
1068 remove_breakpoint (b, mark_inserted);
1069 if (b->type == bp_hardware_breakpoint)
1070 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1072 val = target_insert_breakpoint (b->address, b->shadow_contents);
1075 do_cleanups (old_chain);
1080 do_cleanups (old_chain);
1085 update_breakpoints_after_exec (void)
1087 struct breakpoint *b;
1088 struct breakpoint *temp;
1090 /* Doing this first prevents the badness of having delete_breakpoint()
1091 write a breakpoint's current "shadow contents" to lift the bp. That
1092 shadow is NOT valid after an exec()! */
1093 mark_breakpoints_out ();
1095 ALL_BREAKPOINTS_SAFE (b, temp)
1097 /* Solib breakpoints must be explicitly reset after an exec(). */
1098 if (b->type == bp_shlib_event)
1100 delete_breakpoint (b);
1104 /* Thread event breakpoints must be set anew after an exec(),
1105 as must overlay event breakpoints. */
1106 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1108 delete_breakpoint (b);
1112 /* Step-resume breakpoints are meaningless after an exec(). */
1113 if (b->type == bp_step_resume)
1115 delete_breakpoint (b);
1119 /* Ditto the sigtramp handler breakpoints. */
1120 if (b->type == bp_through_sigtramp)
1122 delete_breakpoint (b);
1126 /* Ditto the exception-handling catchpoints. */
1127 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1129 delete_breakpoint (b);
1133 /* Don't delete an exec catchpoint, because else the inferior
1134 won't stop when it ought!
1136 Similarly, we probably ought to keep vfork catchpoints, 'cause
1137 on this target, we may not be able to stop when the vfork is
1138 seen, but only when the subsequent exec is seen. (And because
1139 deleting fork catchpoints here but not vfork catchpoints will
1140 seem mysterious to users, keep those too.)
1142 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1143 target address field, if any, is sufficient to have it be reset
1144 automagically. Certainly on HP-UX that's true.
1147 valid code address on some platforms (like the mn10200 and
1148 mn10300 simulators). We shouldn't assign any special
1149 interpretation to a breakpoint with a zero address. And in
1150 fact, GDB doesn't --- I can't see what that comment above is
1151 talking about. As far as I can tell, setting the address of a
1152 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1153 is meaningless, since those are implemented with HP-UX kernel
1154 hackery, not by storing breakpoint instructions somewhere. */
1155 if ((b->type == bp_catch_exec) ||
1156 (b->type == bp_catch_vfork) ||
1157 (b->type == bp_catch_fork))
1159 b->address = (CORE_ADDR) NULL;
1163 /* bp_finish is a special case. The only way we ought to be able
1164 to see one of these when an exec() has happened, is if the user
1165 caught a vfork, and then said "finish". Ordinarily a finish just
1166 carries them to the call-site of the current callee, by setting
1167 a temporary bp there and resuming. But in this case, the finish
1168 will carry them entirely through the vfork & exec.
1170 We don't want to allow a bp_finish to remain inserted now. But
1171 we can't safely delete it, 'cause finish_command has a handle to
1172 the bp on a bpstat, and will later want to delete it. There's a
1173 chance (and I've seen it happen) that if we delete the bp_finish
1174 here, that its storage will get reused by the time finish_command
1175 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1176 We really must allow finish_command to delete a bp_finish.
1178 In the absense of a general solution for the "how do we know
1179 it's safe to delete something others may have handles to?"
1180 problem, what we'll do here is just uninsert the bp_finish, and
1181 let finish_command delete it.
1183 (We know the bp_finish is "doomed" in the sense that it's
1184 momentary, and will be deleted as soon as finish_command sees
1185 the inferior stopped. So it doesn't matter that the bp's
1186 address is probably bogus in the new a.out, unlike e.g., the
1187 solib breakpoints.) */
1189 if (b->type == bp_finish)
1194 /* Without a symbolic address, we have little hope of the
1195 pre-exec() address meaning the same thing in the post-exec()
1197 if (b->addr_string == NULL)
1199 delete_breakpoint (b);
1203 /* If this breakpoint has survived the above battery of checks, then
1204 it must have a symbolic address. Be sure that it gets reevaluated
1205 to a target address, rather than reusing the old evaluation.
1208 for bp_catch_exec and friends, I'm pretty sure this is entirely
1209 unnecessary. A call to breakpoint_re_set_one always recomputes
1210 the breakpoint's address from scratch, or deletes it if it can't.
1211 So I think this assignment could be deleted without effect. */
1212 b->address = (CORE_ADDR) NULL;
1214 /* FIXME what about longjmp breakpoints? Re-create them here? */
1215 create_overlay_event_breakpoint ("_ovly_debug_event");
1219 detach_breakpoints (int pid)
1221 register struct breakpoint *b;
1223 struct cleanup *old_chain = save_inferior_ptid ();
1225 if (pid == PIDGET (inferior_ptid))
1226 error ("Cannot detach breakpoints of inferior_ptid");
1228 /* Set inferior_ptid; remove_breakpoint uses this global. */
1229 inferior_ptid = pid_to_ptid (pid);
1234 val = remove_breakpoint (b, mark_inserted);
1237 do_cleanups (old_chain);
1242 do_cleanups (old_chain);
1247 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1251 if (b->enable_state == bp_permanent)
1252 /* Permanent breakpoints cannot be inserted or removed. */
1255 if (b->type == bp_none)
1256 warning ("attempted to remove apparently deleted breakpoint #%d?",
1259 if (b->type != bp_watchpoint
1260 && b->type != bp_hardware_watchpoint
1261 && b->type != bp_read_watchpoint
1262 && b->type != bp_access_watchpoint
1263 && b->type != bp_catch_fork
1264 && b->type != bp_catch_vfork
1265 && b->type != bp_catch_exec
1266 && b->type != bp_catch_catch
1267 && b->type != bp_catch_throw)
1269 if (b->type == bp_hardware_breakpoint)
1270 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1273 /* Check to see if breakpoint is in an overlay section;
1274 if so, we should remove the breakpoint at the LMA address.
1275 If that is not equal to the raw address, then we should
1276 presumably remove the breakpoint there as well. */
1277 if (overlay_debugging && b->section
1278 && section_is_overlay (b->section))
1282 addr = overlay_unmapped_address (b->address, b->section);
1283 val = target_remove_breakpoint (addr, b->shadow_contents);
1284 /* This would be the time to check val, to see if the
1285 shadow breakpoint write to the load address succeeded.
1286 However, this might be an ordinary occurrance, eg. if
1287 the unmapped overlay is in ROM. */
1288 val = 0; /* in case unmapped address failed */
1289 if (section_is_mapped (b->section))
1290 val = target_remove_breakpoint (b->address,
1291 b->shadow_contents);
1293 else /* ordinary (non-overlay) address */
1294 val = target_remove_breakpoint (b->address, b->shadow_contents);
1298 b->inserted = (is == mark_inserted);
1300 else if ((b->type == bp_hardware_watchpoint ||
1301 b->type == bp_read_watchpoint ||
1302 b->type == bp_access_watchpoint)
1303 && b->enable_state == bp_enabled
1309 b->inserted = (is == mark_inserted);
1310 /* Walk down the saved value chain. */
1311 for (v = b->val_chain; v; v = v->next)
1313 /* For each memory reference remove the watchpoint
1315 if (VALUE_LVAL (v) == lval_memory
1316 && ! VALUE_LAZY (v))
1318 struct type *vtype = check_typedef (VALUE_TYPE (v));
1320 if (v == b->val_chain
1321 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1322 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1327 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1328 len = TYPE_LENGTH (VALUE_TYPE (v));
1330 if (b->type == bp_read_watchpoint)
1332 else if (b->type == bp_access_watchpoint)
1335 val = target_remove_watchpoint (addr, len, type);
1342 /* Failure to remove any of the hardware watchpoints comes here. */
1343 if ((is == mark_uninserted) && (b->inserted))
1344 warning ("Could not remove hardware watchpoint %d.",
1347 /* Free the saved value chain. We will construct a new one
1348 the next time the watchpoint is inserted. */
1349 for (v = b->val_chain; v; v = n)
1354 b->val_chain = NULL;
1356 else if ((b->type == bp_catch_fork ||
1357 b->type == bp_catch_vfork ||
1358 b->type == bp_catch_exec)
1359 && b->enable_state == bp_enabled
1366 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1368 case bp_catch_vfork:
1369 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1372 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1375 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1380 b->inserted = (is == mark_inserted);
1382 else if ((b->type == bp_catch_catch ||
1383 b->type == bp_catch_throw)
1384 && b->enable_state == bp_enabled
1388 val = target_remove_breakpoint (b->address, b->shadow_contents);
1391 b->inserted = (is == mark_inserted);
1393 else if (ep_is_exception_catchpoint (b)
1394 && b->inserted /* sometimes previous insert doesn't happen */
1395 && b->enable_state == bp_enabled
1399 val = target_remove_breakpoint (b->address, b->shadow_contents);
1403 b->inserted = (is == mark_inserted);
1409 /* Clear the "inserted" flag in all breakpoints. */
1412 mark_breakpoints_out (void)
1414 register struct breakpoint *b;
1420 /* Clear the "inserted" flag in all breakpoints and delete any
1421 breakpoints which should go away between runs of the program.
1423 Plus other such housekeeping that has to be done for breakpoints
1426 Note: this function gets called at the end of a run (by
1427 generic_mourn_inferior) and when a run begins (by
1428 init_wait_for_inferior). */
1433 breakpoint_init_inferior (enum inf_context context)
1435 register struct breakpoint *b, *temp;
1436 static int warning_needed = 0;
1438 ALL_BREAKPOINTS_SAFE (b, temp)
1445 case bp_watchpoint_scope:
1447 /* If the call dummy breakpoint is at the entry point it will
1448 cause problems when the inferior is rerun, so we better
1451 Also get rid of scope breakpoints. */
1452 delete_breakpoint (b);
1456 case bp_hardware_watchpoint:
1457 case bp_read_watchpoint:
1458 case bp_access_watchpoint:
1460 /* Likewise for watchpoints on local expressions. */
1461 if (b->exp_valid_block != NULL)
1462 delete_breakpoint (b);
1465 /* Likewise for exception catchpoints in dynamic-linked
1466 executables where required */
1467 if (ep_is_exception_catchpoint (b) &&
1468 exception_catchpoints_are_fragile)
1471 delete_breakpoint (b);
1477 if (exception_catchpoints_are_fragile)
1478 exception_support_initialized = 0;
1480 /* Don't issue the warning unless it's really needed... */
1481 if (warning_needed && (context != inf_exited))
1483 warning ("Exception catchpoints from last run were deleted.");
1484 warning ("You must reinsert them explicitly.");
1489 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1490 exists at PC. It returns ordinary_breakpoint_here if it's an
1491 ordinary breakpoint, or permanent_breakpoint_here if it's a
1492 permanent breakpoint.
1493 - When continuing from a location with an ordinary breakpoint, we
1494 actually single step once before calling insert_breakpoints.
1495 - When continuing from a localion with a permanent breakpoint, we
1496 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1497 the target, to advance the PC past the breakpoint. */
1499 enum breakpoint_here
1500 breakpoint_here_p (CORE_ADDR pc)
1502 register struct breakpoint *b;
1503 int any_breakpoint_here = 0;
1506 if ((b->enable_state == bp_enabled
1507 || b->enable_state == bp_permanent)
1508 && b->address == pc) /* bp is enabled and matches pc */
1510 if (overlay_debugging
1511 && section_is_overlay (b->section)
1512 && !section_is_mapped (b->section))
1513 continue; /* unmapped overlay -- can't be a match */
1514 else if (b->enable_state == bp_permanent)
1515 return permanent_breakpoint_here;
1517 any_breakpoint_here = 1;
1520 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1524 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1525 but it only returns true if there is actually a breakpoint inserted
1529 breakpoint_inserted_here_p (CORE_ADDR 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 (struct frame_info *frame)
1557 struct breakpoint *b;
1562 if (USE_GENERIC_DUMMY_FRAMES)
1563 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1567 if (b->type == bp_call_dummy
1568 && b->frame == frame->frame
1569 /* We need to check the PC as well as the frame on the sparc,
1570 for signals.exp in the testsuite. */
1573 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1574 && frame->pc <= b->address)
1580 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1581 PC is valid for process/thread PID. */
1584 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1586 struct breakpoint *b;
1589 thread = pid_to_thread_id (ptid);
1592 if (b->enable_state != bp_disabled
1593 && b->enable_state != bp_shlib_disabled
1594 && b->enable_state != bp_call_disabled
1596 && (b->thread == -1 || b->thread == thread))
1598 if (overlay_debugging
1599 && section_is_overlay (b->section)
1600 && !section_is_mapped (b->section))
1601 continue; /* unmapped overlay -- can't be a match */
1610 /* bpstat stuff. External routines' interfaces are documented
1614 ep_is_catchpoint (struct breakpoint *ep)
1617 (ep->type == bp_catch_load)
1618 || (ep->type == bp_catch_unload)
1619 || (ep->type == bp_catch_fork)
1620 || (ep->type == bp_catch_vfork)
1621 || (ep->type == bp_catch_exec)
1622 || (ep->type == bp_catch_catch)
1623 || (ep->type == bp_catch_throw);
1625 /* ??rehrauer: Add more kinds here, as are implemented... */
1629 ep_is_shlib_catchpoint (struct breakpoint *ep)
1632 (ep->type == bp_catch_load)
1633 || (ep->type == bp_catch_unload);
1637 ep_is_exception_catchpoint (struct breakpoint *ep)
1640 (ep->type == bp_catch_catch)
1641 || (ep->type == bp_catch_throw);
1644 /* Clear a bpstat so that it says we are not at any breakpoint.
1645 Also free any storage that is part of a bpstat. */
1648 bpstat_clear (bpstat *bsp)
1659 if (p->old_val != NULL)
1660 value_free (p->old_val);
1667 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1668 is part of the bpstat is copied as well. */
1671 bpstat_copy (bpstat bs)
1675 bpstat retval = NULL;
1680 for (; bs != NULL; bs = bs->next)
1682 tmp = (bpstat) xmalloc (sizeof (*tmp));
1683 memcpy (tmp, bs, sizeof (*tmp));
1685 /* This is the first thing in the chain. */
1695 /* Find the bpstat associated with this breakpoint */
1698 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1703 for (; bsp != NULL; bsp = bsp->next)
1705 if (bsp->breakpoint_at == breakpoint)
1711 /* Find a step_resume breakpoint associated with this bpstat.
1712 (If there are multiple step_resume bp's on the list, this function
1713 will arbitrarily pick one.)
1715 It is an error to use this function if BPSTAT doesn't contain a
1716 step_resume breakpoint.
1718 See wait_for_inferior's use of this function. */
1720 bpstat_find_step_resume_breakpoint (bpstat bsp)
1725 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1727 current_thread = pid_to_thread_id (inferior_ptid);
1729 for (; bsp != NULL; bsp = bsp->next)
1731 if ((bsp->breakpoint_at != NULL) &&
1732 (bsp->breakpoint_at->type == bp_step_resume) &&
1733 (bsp->breakpoint_at->thread == current_thread ||
1734 bsp->breakpoint_at->thread == -1))
1735 return bsp->breakpoint_at;
1738 error ("Internal error (no step_resume breakpoint found)");
1742 /* Return the breakpoint number of the first breakpoint we are stopped
1743 at. *BSP upon return is a bpstat which points to the remaining
1744 breakpoints stopped at (but which is not guaranteed to be good for
1745 anything but further calls to bpstat_num).
1746 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1749 bpstat_num (bpstat *bsp)
1751 struct breakpoint *b;
1754 return 0; /* No more breakpoint values */
1757 b = (*bsp)->breakpoint_at;
1758 *bsp = (*bsp)->next;
1760 return -1; /* breakpoint that's been deleted since */
1762 return b->number; /* We have its number */
1766 /* Modify BS so that the actions will not be performed. */
1769 bpstat_clear_actions (bpstat bs)
1771 for (; bs != NULL; bs = bs->next)
1773 bs->commands = NULL;
1774 if (bs->old_val != NULL)
1776 value_free (bs->old_val);
1782 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1785 cleanup_executing_breakpoints (PTR ignore)
1787 executing_breakpoint_commands = 0;
1790 /* Execute all the commands associated with all the breakpoints at this
1791 location. Any of these commands could cause the process to proceed
1792 beyond this point, etc. We look out for such changes by checking
1793 the global "breakpoint_proceeded" after each command. */
1796 bpstat_do_actions (bpstat *bsp)
1799 struct cleanup *old_chain;
1800 struct command_line *cmd;
1802 /* Avoid endless recursion if a `source' command is contained
1804 if (executing_breakpoint_commands)
1807 executing_breakpoint_commands = 1;
1808 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1811 /* Note that (as of this writing), our callers all appear to
1812 be passing us the address of global stop_bpstat. And, if
1813 our calls to execute_control_command cause the inferior to
1814 proceed, that global (and hence, *bsp) will change.
1816 We must be careful to not touch *bsp unless the inferior
1817 has not proceeded. */
1819 /* This pointer will iterate over the list of bpstat's. */
1822 breakpoint_proceeded = 0;
1823 for (; bs != NULL; bs = bs->next)
1828 execute_control_command (cmd);
1830 if (breakpoint_proceeded)
1835 if (breakpoint_proceeded)
1836 /* The inferior is proceeded by the command; bomb out now.
1837 The bpstat chain has been blown away by wait_for_inferior.
1838 But since execution has stopped again, there is a new bpstat
1839 to look at, so start over. */
1842 bs->commands = NULL;
1845 executing_breakpoint_commands = 0;
1846 discard_cleanups (old_chain);
1849 /* This is the normal print function for a bpstat. In the future,
1850 much of this logic could (should?) be moved to bpstat_stop_status,
1851 by having it set different print_it values.
1853 Current scheme: When we stop, bpstat_print() is called. It loops
1854 through the bpstat list of things causing this stop, calling the
1855 print_bp_stop_message function on each one. The behavior of the
1856 print_bp_stop_message function depends on the print_it field of
1857 bpstat. If such field so indicates, call this function here.
1859 Return values from this routine (ultimately used by bpstat_print()
1860 and normal_stop() to decide what to do):
1861 PRINT_NOTHING: Means we already printed all we needed to print,
1862 don't print anything else.
1863 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1864 that something to be followed by a location.
1865 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1866 that something to be followed by a location.
1867 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1870 static enum print_stop_action
1871 print_it_typical (bpstat bs)
1873 struct cleanup *old_chain;
1874 struct ui_stream *stb;
1875 stb = ui_out_stream_new (uiout);
1876 old_chain = make_cleanup_ui_out_stream_delete (stb);
1877 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1878 which has since been deleted. */
1879 if (bs->breakpoint_at == NULL)
1880 return PRINT_UNKNOWN;
1882 switch (bs->breakpoint_at->type)
1885 case bp_hardware_breakpoint:
1886 annotate_breakpoint (bs->breakpoint_at->number);
1887 ui_out_text (uiout, "\nBreakpoint ");
1888 if (ui_out_is_mi_like_p (uiout))
1889 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1890 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1891 ui_out_text (uiout, ", ");
1892 return PRINT_SRC_AND_LOC;
1895 case bp_shlib_event:
1896 /* Did we stop because the user set the stop_on_solib_events
1897 variable? (If so, we report this as a generic, "Stopped due
1898 to shlib event" message.) */
1899 printf_filtered ("Stopped due to shared library event\n");
1900 return PRINT_NOTHING;
1903 case bp_thread_event:
1904 /* Not sure how we will get here.
1905 GDB should not stop for these breakpoints. */
1906 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1907 return PRINT_NOTHING;
1910 case bp_overlay_event:
1911 /* By analogy with the thread event, GDB should not stop for these. */
1912 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
1913 return PRINT_NOTHING;
1917 annotate_catchpoint (bs->breakpoint_at->number);
1918 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1919 printf_filtered ("loaded");
1920 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1921 return PRINT_SRC_AND_LOC;
1924 case bp_catch_unload:
1925 annotate_catchpoint (bs->breakpoint_at->number);
1926 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1927 printf_filtered ("unloaded");
1928 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1929 return PRINT_SRC_AND_LOC;
1933 annotate_catchpoint (bs->breakpoint_at->number);
1934 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1935 printf_filtered ("forked");
1936 printf_filtered (" process %d), ",
1937 bs->breakpoint_at->forked_inferior_pid);
1938 return PRINT_SRC_AND_LOC;
1941 case bp_catch_vfork:
1942 annotate_catchpoint (bs->breakpoint_at->number);
1943 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1944 printf_filtered ("vforked");
1945 printf_filtered (" process %d), ",
1946 bs->breakpoint_at->forked_inferior_pid);
1947 return PRINT_SRC_AND_LOC;
1951 annotate_catchpoint (bs->breakpoint_at->number);
1952 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1953 bs->breakpoint_at->number,
1954 bs->breakpoint_at->exec_pathname);
1955 return PRINT_SRC_AND_LOC;
1958 case bp_catch_catch:
1959 if (current_exception_event &&
1960 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1962 annotate_catchpoint (bs->breakpoint_at->number);
1963 printf_filtered ("\nCatchpoint %d (exception caught), ",
1964 bs->breakpoint_at->number);
1965 printf_filtered ("throw location ");
1966 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1967 printf_filtered ("%s:%d",
1968 CURRENT_EXCEPTION_THROW_FILE,
1969 CURRENT_EXCEPTION_THROW_LINE);
1971 printf_filtered ("unknown");
1973 printf_filtered (", catch location ");
1974 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1975 printf_filtered ("%s:%d",
1976 CURRENT_EXCEPTION_CATCH_FILE,
1977 CURRENT_EXCEPTION_CATCH_LINE);
1979 printf_filtered ("unknown");
1981 printf_filtered ("\n");
1982 /* don't bother to print location frame info */
1983 return PRINT_SRC_ONLY;
1987 /* really throw, some other bpstat will handle it */
1988 return PRINT_UNKNOWN;
1992 case bp_catch_throw:
1993 if (current_exception_event &&
1994 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1996 annotate_catchpoint (bs->breakpoint_at->number);
1997 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1998 bs->breakpoint_at->number);
1999 printf_filtered ("throw location ");
2000 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2001 printf_filtered ("%s:%d",
2002 CURRENT_EXCEPTION_THROW_FILE,
2003 CURRENT_EXCEPTION_THROW_LINE);
2005 printf_filtered ("unknown");
2007 printf_filtered (", catch location ");
2008 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2009 printf_filtered ("%s:%d",
2010 CURRENT_EXCEPTION_CATCH_FILE,
2011 CURRENT_EXCEPTION_CATCH_LINE);
2013 printf_filtered ("unknown");
2015 printf_filtered ("\n");
2016 /* don't bother to print location frame info */
2017 return PRINT_SRC_ONLY;
2021 /* really catch, some other bpstat will handle it */
2022 return PRINT_UNKNOWN;
2027 case bp_hardware_watchpoint:
2028 if (bs->old_val != NULL)
2030 annotate_watchpoint (bs->breakpoint_at->number);
2031 if (ui_out_is_mi_like_p (uiout))
2032 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2033 mention (bs->breakpoint_at);
2034 ui_out_tuple_begin (uiout, "value");
2035 ui_out_text (uiout, "\nOld value = ");
2036 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2037 ui_out_field_stream (uiout, "old", stb);
2038 ui_out_text (uiout, "\nNew value = ");
2039 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2040 ui_out_field_stream (uiout, "new", stb);
2041 ui_out_tuple_end (uiout);
2042 ui_out_text (uiout, "\n");
2043 value_free (bs->old_val);
2046 /* More than one watchpoint may have been triggered. */
2047 return PRINT_UNKNOWN;
2050 case bp_read_watchpoint:
2051 if (ui_out_is_mi_like_p (uiout))
2052 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2053 mention (bs->breakpoint_at);
2054 ui_out_tuple_begin (uiout, "value");
2055 ui_out_text (uiout, "\nValue = ");
2056 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2057 ui_out_field_stream (uiout, "value", stb);
2058 ui_out_tuple_end (uiout);
2059 ui_out_text (uiout, "\n");
2060 return PRINT_UNKNOWN;
2063 case bp_access_watchpoint:
2064 if (bs->old_val != NULL)
2066 annotate_watchpoint (bs->breakpoint_at->number);
2067 if (ui_out_is_mi_like_p (uiout))
2068 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2069 mention (bs->breakpoint_at);
2070 ui_out_tuple_begin (uiout, "value");
2071 ui_out_text (uiout, "\nOld value = ");
2072 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2073 ui_out_field_stream (uiout, "old", stb);
2074 value_free (bs->old_val);
2076 ui_out_text (uiout, "\nNew value = ");
2080 mention (bs->breakpoint_at);
2081 if (ui_out_is_mi_like_p (uiout))
2082 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2083 ui_out_tuple_begin (uiout, "value");
2084 ui_out_text (uiout, "\nValue = ");
2086 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2087 ui_out_field_stream (uiout, "new", stb);
2088 ui_out_tuple_end (uiout);
2089 ui_out_text (uiout, "\n");
2090 return PRINT_UNKNOWN;
2093 /* Fall through, we don't deal with these types of breakpoints
2097 if (ui_out_is_mi_like_p (uiout))
2098 ui_out_field_string (uiout, "reason", "function-finished");
2099 return PRINT_UNKNOWN;
2103 if (ui_out_is_mi_like_p (uiout))
2104 ui_out_field_string (uiout, "reason", "location-reached");
2105 return PRINT_UNKNOWN;
2110 case bp_longjmp_resume:
2111 case bp_step_resume:
2112 case bp_through_sigtramp:
2113 case bp_watchpoint_scope:
2116 return PRINT_UNKNOWN;
2120 /* Generic routine for printing messages indicating why we
2121 stopped. The behavior of this function depends on the value
2122 'print_it' in the bpstat structure. Under some circumstances we
2123 may decide not to print anything here and delegate the task to
2126 static enum print_stop_action
2127 print_bp_stop_message (bpstat bs)
2129 switch (bs->print_it)
2132 /* Nothing should be printed for this bpstat entry. */
2133 return PRINT_UNKNOWN;
2137 /* We still want to print the frame, but we already printed the
2138 relevant messages. */
2139 return PRINT_SRC_AND_LOC;
2142 case print_it_normal:
2143 /* Normal case, we handle everything in print_it_typical. */
2144 return print_it_typical (bs);
2147 internal_error (__FILE__, __LINE__,
2148 "print_bp_stop_message: unrecognized enum value");
2153 /* Print a message indicating what happened. This is called from
2154 normal_stop(). The input to this routine is the head of the bpstat
2155 list - a list of the eventpoints that caused this stop. This
2156 routine calls the generic print routine for printing a message
2157 about reasons for stopping. This will print (for example) the
2158 "Breakpoint n," part of the output. The return value of this
2161 PRINT_UNKNOWN: Means we printed nothing
2162 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2163 code to print the location. An example is
2164 "Breakpoint 1, " which should be followed by
2166 PRINT_SRC_ONLY: Means we printed something, but there is no need
2167 to also print the location part of the message.
2168 An example is the catch/throw messages, which
2169 don't require a location appended to the end.
2170 PRINT_NOTHING: We have done some printing and we don't need any
2171 further info to be printed.*/
2173 enum print_stop_action
2174 bpstat_print (bpstat bs)
2178 /* Maybe another breakpoint in the chain caused us to stop.
2179 (Currently all watchpoints go on the bpstat whether hit or not.
2180 That probably could (should) be changed, provided care is taken
2181 with respect to bpstat_explains_signal). */
2182 for (; bs; bs = bs->next)
2184 val = print_bp_stop_message (bs);
2185 if (val == PRINT_SRC_ONLY
2186 || val == PRINT_SRC_AND_LOC
2187 || val == PRINT_NOTHING)
2191 /* We reached the end of the chain, or we got a null BS to start
2192 with and nothing was printed. */
2193 return PRINT_UNKNOWN;
2196 /* Evaluate the expression EXP and return 1 if value is zero.
2197 This is used inside a catch_errors to evaluate the breakpoint condition.
2198 The argument is a "struct expression *" that has been cast to char * to
2199 make it pass through catch_errors. */
2202 breakpoint_cond_eval (PTR exp)
2204 struct value *mark = value_mark ();
2205 int i = !value_true (evaluate_expression ((struct expression *) exp));
2206 value_free_to_mark (mark);
2210 /* Allocate a new bpstat and chain it to the current one. */
2213 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2217 bs = (bpstat) xmalloc (sizeof (*bs));
2219 bs->breakpoint_at = b;
2220 /* If the condition is false, etc., don't do the commands. */
2221 bs->commands = NULL;
2223 bs->print_it = print_it_normal;
2227 /* Possible return values for watchpoint_check (this can't be an enum
2228 because of check_errors). */
2229 /* The watchpoint has been deleted. */
2230 #define WP_DELETED 1
2231 /* The value has changed. */
2232 #define WP_VALUE_CHANGED 2
2233 /* The value has not changed. */
2234 #define WP_VALUE_NOT_CHANGED 3
2236 #define BP_TEMPFLAG 1
2237 #define BP_HARDWAREFLAG 2
2239 /* Check watchpoint condition. */
2242 watchpoint_check (PTR p)
2244 bpstat bs = (bpstat) p;
2245 struct breakpoint *b;
2246 struct frame_info *fr;
2247 int within_current_scope;
2249 b = bs->breakpoint_at;
2251 if (b->exp_valid_block == NULL)
2252 within_current_scope = 1;
2255 /* There is no current frame at this moment. If we're going to have
2256 any chance of handling watchpoints on local variables, we'll need
2257 the frame chain (so we can determine if we're in scope). */
2258 reinit_frame_cache ();
2259 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2260 within_current_scope = (fr != NULL);
2261 /* in_function_epilogue_p() returns a non-zero value if we're still
2262 in the function but the stack frame has already been invalidated.
2263 Since we can't rely on the values of local variables after the
2264 stack has been destroyed, we are treating the watchpoint in that
2265 state as `not changed' without further checking. */
2266 if (within_current_scope && fr == get_current_frame ()
2267 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2268 return WP_VALUE_NOT_CHANGED;
2269 if (within_current_scope)
2270 /* If we end up stopping, the current frame will get selected
2271 in normal_stop. So this call to select_frame won't affect
2273 select_frame (fr, -1);
2276 if (within_current_scope)
2278 /* We use value_{,free_to_}mark because it could be a
2279 *long* time before we return to the command level and
2280 call free_all_values. We can't call free_all_values because
2281 we might be in the middle of evaluating a function call. */
2283 struct value *mark = value_mark ();
2284 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2285 if (!value_equal (b->val, new_val))
2287 release_value (new_val);
2288 value_free_to_mark (mark);
2289 bs->old_val = b->val;
2291 /* We will stop here */
2292 return WP_VALUE_CHANGED;
2296 /* Nothing changed, don't do anything. */
2297 value_free_to_mark (mark);
2298 /* We won't stop here */
2299 return WP_VALUE_NOT_CHANGED;
2304 /* This seems like the only logical thing to do because
2305 if we temporarily ignored the watchpoint, then when
2306 we reenter the block in which it is valid it contains
2307 garbage (in the case of a function, it may have two
2308 garbage values, one before and one after the prologue).
2309 So we can't even detect the first assignment to it and
2310 watch after that (since the garbage may or may not equal
2311 the first value assigned). */
2312 /* We print all the stop information in print_it_typical(), but
2313 in this case, by the time we call print_it_typical() this bp
2314 will be deleted already. So we have no choice but print the
2315 information here. */
2316 if (ui_out_is_mi_like_p (uiout))
2317 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2318 ui_out_text (uiout, "\nWatchpoint ");
2319 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2320 ui_out_text (uiout, " deleted because the program has left the block in\n\
2321 which its expression is valid.\n");
2323 if (b->related_breakpoint)
2324 b->related_breakpoint->disposition = disp_del_at_next_stop;
2325 b->disposition = disp_del_at_next_stop;
2331 /* Get a bpstat associated with having just stopped at address *PC
2332 and frame address CORE_ADDRESS. Update *PC to point at the
2333 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2334 if this is known to not be a real breakpoint (it could still be a
2335 watchpoint, though). */
2337 /* Determine whether we stopped at a breakpoint, etc, or whether we
2338 don't understand this stop. Result is a chain of bpstat's such that:
2340 if we don't understand the stop, the result is a null pointer.
2342 if we understand why we stopped, the result is not null.
2344 Each element of the chain refers to a particular breakpoint or
2345 watchpoint at which we have stopped. (We may have stopped for
2346 several reasons concurrently.)
2348 Each element of the chain has valid next, breakpoint_at,
2349 commands, FIXME??? fields. */
2352 bpstat_stop_status (CORE_ADDR *pc, int not_a_breakpoint)
2354 register struct breakpoint *b, *temp;
2356 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2357 int real_breakpoint = 0;
2358 /* Root of the chain of bpstat's */
2359 struct bpstats root_bs[1];
2360 /* Pointer to the last thing in the chain currently. */
2361 bpstat bs = root_bs;
2362 static char message1[] =
2363 "Error evaluating expression for watchpoint %d\n";
2364 char message[sizeof (message1) + 30 /* slop */ ];
2366 /* Get the address where the breakpoint would have been.
2367 The "not_a_breakpoint" argument is meant to distinguish
2368 between a breakpoint trap event and a trace/singlestep
2369 trap event. For a trace/singlestep trap event, we would
2370 not want to subtract DECR_PC_AFTER_BREAK from the PC. */
2372 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P () ?
2373 0 : DECR_PC_AFTER_BREAK);
2375 ALL_BREAKPOINTS_SAFE (b, temp)
2377 if (b->enable_state == bp_disabled
2378 || b->enable_state == bp_shlib_disabled
2379 || b->enable_state == bp_call_disabled)
2382 if (b->type != bp_watchpoint
2383 && b->type != bp_hardware_watchpoint
2384 && b->type != bp_read_watchpoint
2385 && b->type != bp_access_watchpoint
2386 && b->type != bp_hardware_breakpoint
2387 && b->type != bp_catch_fork
2388 && b->type != bp_catch_vfork
2389 && b->type != bp_catch_exec
2390 && b->type != bp_catch_catch
2391 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2393 if (b->address != bp_addr) /* address doesn't match */
2395 if (overlay_debugging /* unmapped overlay section */
2396 && section_is_overlay (b->section)
2397 && !section_is_mapped (b->section))
2401 if (b->type == bp_hardware_breakpoint
2402 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2405 /* Is this a catchpoint of a load or unload? If so, did we
2406 get a load or unload of the specified library? If not,
2408 if ((b->type == bp_catch_load)
2409 #if defined(SOLIB_HAVE_LOAD_EVENT)
2410 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2411 || ((b->dll_pathname != NULL)
2412 && (strcmp (b->dll_pathname,
2413 SOLIB_LOADED_LIBRARY_PATHNAME (
2414 PIDGET (inferior_ptid)))
2420 if ((b->type == bp_catch_unload)
2421 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2422 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2423 || ((b->dll_pathname != NULL)
2424 && (strcmp (b->dll_pathname,
2425 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2426 PIDGET (inferior_ptid)))
2432 if ((b->type == bp_catch_fork)
2433 && !target_has_forked (PIDGET (inferior_ptid),
2434 &b->forked_inferior_pid))
2437 if ((b->type == bp_catch_vfork)
2438 && !target_has_vforked (PIDGET (inferior_ptid),
2439 &b->forked_inferior_pid))
2442 if ((b->type == bp_catch_exec)
2443 && !target_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2446 if (ep_is_exception_catchpoint (b) &&
2447 !(current_exception_event = target_get_current_exception_event ()))
2450 /* Come here if it's a watchpoint, or if the break address matches */
2452 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2454 /* Watchpoints may change this, if not found to have triggered. */
2458 sprintf (message, message1, b->number);
2459 if (b->type == bp_watchpoint ||
2460 b->type == bp_hardware_watchpoint)
2462 switch (catch_errors (watchpoint_check, bs, message,
2466 /* We've already printed what needs to be printed. */
2467 /* Actually this is superfluous, because by the time we
2468 call print_it_typical() the wp will be already deleted,
2469 and the function will return immediately. */
2470 bs->print_it = print_it_done;
2473 case WP_VALUE_CHANGED:
2477 case WP_VALUE_NOT_CHANGED:
2479 bs->print_it = print_it_noop;
2486 /* Error from catch_errors. */
2487 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2488 if (b->related_breakpoint)
2489 b->related_breakpoint->disposition = disp_del_at_next_stop;
2490 b->disposition = disp_del_at_next_stop;
2491 /* We've already printed what needs to be printed. */
2492 bs->print_it = print_it_done;
2498 else if (b->type == bp_read_watchpoint ||
2499 b->type == bp_access_watchpoint)
2505 addr = target_stopped_data_address ();
2508 for (v = b->val_chain; v; v = v->next)
2510 if (VALUE_LVAL (v) == lval_memory
2511 && ! VALUE_LAZY (v))
2513 struct type *vtype = check_typedef (VALUE_TYPE (v));
2515 if (v == b->val_chain
2516 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2517 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2521 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2522 /* Exact match not required. Within range is
2524 if (addr >= vaddr &&
2525 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2531 switch (catch_errors (watchpoint_check, bs, message,
2535 /* We've already printed what needs to be printed. */
2536 bs->print_it = print_it_done;
2539 case WP_VALUE_CHANGED:
2540 if (b->type == bp_read_watchpoint)
2542 /* Don't stop: read watchpoints shouldn't fire if
2543 the value has changed. This is for targets which
2544 cannot set read-only watchpoints. */
2545 bs->print_it = print_it_noop;
2551 case WP_VALUE_NOT_CHANGED:
2558 /* Error from catch_errors. */
2559 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2560 if (b->related_breakpoint)
2561 b->related_breakpoint->disposition = disp_del_at_next_stop;
2562 b->disposition = disp_del_at_next_stop;
2563 /* We've already printed what needs to be printed. */
2564 bs->print_it = print_it_done;
2567 else /* found == 0 */
2569 /* This is a case where some watchpoint(s) triggered,
2570 but not at the address of this watchpoint (FOUND
2571 was left zero). So don't print anything for this
2573 bs->print_it = print_it_noop;
2580 /* By definition, an encountered breakpoint is a triggered
2584 real_breakpoint = 1;
2588 b->frame != (get_current_frame ())->frame)
2592 int value_is_zero = 0;
2596 /* Need to select the frame, with all that implies
2597 so that the conditions will have the right context. */
2598 select_frame (get_current_frame (), 0);
2600 = catch_errors (breakpoint_cond_eval, (b->cond),
2601 "Error in testing breakpoint condition:\n",
2603 /* FIXME-someday, should give breakpoint # */
2606 if (b->cond && value_is_zero)
2609 /* Don't consider this a hit. */
2612 else if (b->ignore_count > 0)
2615 annotate_ignore_count_change ();
2620 /* We will stop here */
2621 if (b->disposition == disp_disable)
2622 b->enable_state = bp_disabled;
2623 bs->commands = b->commands;
2627 (STREQ ("silent", bs->commands->line) ||
2628 (xdb_commands && STREQ ("Q", bs->commands->line))))
2630 bs->commands = bs->commands->next;
2635 /* Print nothing for this entry if we dont stop or if we dont print. */
2636 if (bs->stop == 0 || bs->print == 0)
2637 bs->print_it = print_it_noop;
2640 bs->next = NULL; /* Terminate the chain */
2641 bs = root_bs->next; /* Re-grab the head of the chain */
2643 if (real_breakpoint && bs)
2645 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2647 if (DECR_PC_AFTER_HW_BREAK != 0)
2649 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2655 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2658 #if defined (SHIFT_INST_REGS)
2660 #else /* No SHIFT_INST_REGS. */
2662 #endif /* No SHIFT_INST_REGS. */
2667 /* The value of a hardware watchpoint hasn't changed, but the
2668 intermediate memory locations we are watching may have. */
2669 if (bs && !bs->stop &&
2670 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2671 bs->breakpoint_at->type == bp_read_watchpoint ||
2672 bs->breakpoint_at->type == bp_access_watchpoint))
2674 remove_breakpoints ();
2675 insert_breakpoints ();
2680 /* Tell what to do about this bpstat. */
2682 bpstat_what (bpstat bs)
2684 /* Classify each bpstat as one of the following. */
2687 /* This bpstat element has no effect on the main_action. */
2690 /* There was a watchpoint, stop but don't print. */
2693 /* There was a watchpoint, stop and print. */
2696 /* There was a breakpoint but we're not stopping. */
2699 /* There was a breakpoint, stop but don't print. */
2702 /* There was a breakpoint, stop and print. */
2705 /* We hit the longjmp breakpoint. */
2708 /* We hit the longjmp_resume breakpoint. */
2711 /* We hit the step_resume breakpoint. */
2714 /* We hit the through_sigtramp breakpoint. */
2717 /* We hit the shared library event breakpoint. */
2720 /* We caught a shared library event. */
2723 /* This is just used to count how many enums there are. */
2727 /* Here is the table which drives this routine. So that we can
2728 format it pretty, we define some abbreviations for the
2729 enum bpstat_what codes. */
2730 #define kc BPSTAT_WHAT_KEEP_CHECKING
2731 #define ss BPSTAT_WHAT_STOP_SILENT
2732 #define sn BPSTAT_WHAT_STOP_NOISY
2733 #define sgl BPSTAT_WHAT_SINGLE
2734 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2735 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2736 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2737 #define sr BPSTAT_WHAT_STEP_RESUME
2738 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2739 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2740 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2742 /* "Can't happen." Might want to print an error message.
2743 abort() is not out of the question, but chances are GDB is just
2744 a bit confused, not unusable. */
2745 #define err BPSTAT_WHAT_STOP_NOISY
2747 /* Given an old action and a class, come up with a new action. */
2748 /* One interesting property of this table is that wp_silent is the same
2749 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2750 after stopping, the check for whether to step over a breakpoint
2751 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2752 reference to how we stopped. We retain separate wp_silent and
2753 bp_silent codes in case we want to change that someday.
2755 Another possibly interesting property of this table is that
2756 there's a partial ordering, priority-like, of the actions. Once
2757 you've decided that some action is appropriate, you'll never go
2758 back and decide something of a lower priority is better. The
2761 kc < clr sgl shl shlr slr sn sr ss ts
2762 sgl < clrs shl shlr slr sn sr ss ts
2763 slr < err shl shlr sn sr ss ts
2764 clr < clrs err shl shlr sn sr ss ts
2765 clrs < err shl shlr sn sr ss ts
2766 ss < shl shlr sn sr ts
2773 What I think this means is that we don't need a damned table
2774 here. If you just put the rows and columns in the right order,
2775 it'd look awfully regular. We could simply walk the bpstat list
2776 and choose the highest priority action we find, with a little
2777 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2778 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2779 is messy anyway). */
2781 /* step_resume entries: a step resume breakpoint overrides another
2782 breakpoint of signal handling (see comment in wait_for_inferior
2783 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2784 /* We handle the through_sigtramp_breakpoint the same way; having both
2785 one of those and a step_resume_breakpoint is probably very rare (?). */
2787 static const enum bpstat_what_main_action
2788 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2791 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2794 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2796 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2798 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2800 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2802 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2804 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2806 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2808 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2810 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2812 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2814 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2816 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2831 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2832 struct bpstat_what retval;
2834 retval.call_dummy = 0;
2835 for (; bs != NULL; bs = bs->next)
2837 enum class bs_class = no_effect;
2838 if (bs->breakpoint_at == NULL)
2839 /* I suspect this can happen if it was a momentary breakpoint
2840 which has since been deleted. */
2842 switch (bs->breakpoint_at->type)
2848 case bp_hardware_breakpoint:
2854 bs_class = bp_noisy;
2856 bs_class = bp_silent;
2859 bs_class = bp_nostop;
2862 case bp_hardware_watchpoint:
2863 case bp_read_watchpoint:
2864 case bp_access_watchpoint:
2868 bs_class = wp_noisy;
2870 bs_class = wp_silent;
2873 /* There was a watchpoint, but we're not stopping.
2874 This requires no further action. */
2875 bs_class = no_effect;
2878 bs_class = long_jump;
2880 case bp_longjmp_resume:
2881 bs_class = long_resume;
2883 case bp_step_resume:
2886 bs_class = step_resume;
2889 /* It is for the wrong frame. */
2890 bs_class = bp_nostop;
2892 case bp_through_sigtramp:
2893 bs_class = through_sig;
2895 case bp_watchpoint_scope:
2896 bs_class = bp_nostop;
2898 case bp_shlib_event:
2899 bs_class = shlib_event;
2901 case bp_thread_event:
2902 case bp_overlay_event:
2903 bs_class = bp_nostop;
2906 case bp_catch_unload:
2907 /* Only if this catchpoint triggered should we cause the
2908 step-out-of-dld behaviour. Otherwise, we ignore this
2911 bs_class = catch_shlib_event;
2913 bs_class = no_effect;
2916 case bp_catch_vfork:
2921 bs_class = bp_noisy;
2923 bs_class = bp_silent;
2926 /* There was a catchpoint, but we're not stopping.
2927 This requires no further action. */
2928 bs_class = no_effect;
2930 case bp_catch_catch:
2931 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2932 bs_class = bp_nostop;
2934 bs_class = bs->print ? bp_noisy : bp_silent;
2936 case bp_catch_throw:
2937 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2938 bs_class = bp_nostop;
2940 bs_class = bs->print ? bp_noisy : bp_silent;
2943 /* Make sure the action is stop (silent or noisy),
2944 so infrun.c pops the dummy frame. */
2945 bs_class = bp_silent;
2946 retval.call_dummy = 1;
2949 current_action = table[(int) bs_class][(int) current_action];
2951 retval.main_action = current_action;
2955 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2956 without hardware support). This isn't related to a specific bpstat,
2957 just to things like whether watchpoints are set. */
2960 bpstat_should_step (void)
2962 struct breakpoint *b;
2964 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
2969 /* Nonzero if there are enabled hardware watchpoints. */
2971 bpstat_have_active_hw_watchpoints (void)
2973 struct breakpoint *b;
2975 if ((b->enable_state == bp_enabled) &&
2977 ((b->type == bp_hardware_watchpoint) ||
2978 (b->type == bp_read_watchpoint) ||
2979 (b->type == bp_access_watchpoint)))
2985 /* Given a bpstat that records zero or more triggered eventpoints, this
2986 function returns another bpstat which contains only the catchpoints
2987 on that first list, if any. */
2989 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
2991 struct bpstats root_bs[1];
2992 bpstat bs = root_bs;
2993 struct breakpoint *ep;
2996 bpstat_clear (cp_list);
2997 root_bs->next = NULL;
2999 for (; ep_list != NULL; ep_list = ep_list->next)
3001 /* Is this eventpoint a catchpoint? If not, ignore it. */
3002 ep = ep_list->breakpoint_at;
3005 if ((ep->type != bp_catch_load) &&
3006 (ep->type != bp_catch_unload) &&
3007 (ep->type != bp_catch_catch) &&
3008 (ep->type != bp_catch_throw))
3009 /* pai: (temp) ADD fork/vfork here!! */
3012 /* Yes; add it to the list. */
3013 bs = bpstat_alloc (ep, bs);
3018 #if defined(SOLIB_ADD)
3019 /* Also, for each triggered catchpoint, tag it with the name of
3020 the library that caused this trigger. (We copy the name now,
3021 because it's only guaranteed to be available NOW, when the
3022 catchpoint triggers. Clients who may wish to know the name
3023 later must get it from the catchpoint itself.) */
3024 if (ep->triggered_dll_pathname != NULL)
3025 xfree (ep->triggered_dll_pathname);
3026 if (ep->type == bp_catch_load)
3027 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3028 PIDGET (inferior_ptid));
3030 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3031 PIDGET (inferior_ptid));
3033 dll_pathname = NULL;
3037 ep->triggered_dll_pathname = (char *)
3038 xmalloc (strlen (dll_pathname) + 1);
3039 strcpy (ep->triggered_dll_pathname, dll_pathname);
3042 ep->triggered_dll_pathname = NULL;
3048 /* Print B to gdb_stdout. */
3050 print_one_breakpoint (struct breakpoint *b,
3051 CORE_ADDR *last_addr)
3053 register struct command_line *l;
3054 register struct symbol *sym;
3055 struct ep_type_description
3060 static struct ep_type_description bptypes[] =
3062 {bp_none, "?deleted?"},
3063 {bp_breakpoint, "breakpoint"},
3064 {bp_hardware_breakpoint, "hw breakpoint"},
3065 {bp_until, "until"},
3066 {bp_finish, "finish"},
3067 {bp_watchpoint, "watchpoint"},
3068 {bp_hardware_watchpoint, "hw watchpoint"},
3069 {bp_read_watchpoint, "read watchpoint"},
3070 {bp_access_watchpoint, "acc watchpoint"},
3071 {bp_longjmp, "longjmp"},
3072 {bp_longjmp_resume, "longjmp resume"},
3073 {bp_step_resume, "step resume"},
3074 {bp_through_sigtramp, "sigtramp"},
3075 {bp_watchpoint_scope, "watchpoint scope"},
3076 {bp_call_dummy, "call dummy"},
3077 {bp_shlib_event, "shlib events"},
3078 {bp_thread_event, "thread events"},
3079 {bp_overlay_event, "overlay events"},
3080 {bp_catch_load, "catch load"},
3081 {bp_catch_unload, "catch unload"},
3082 {bp_catch_fork, "catch fork"},
3083 {bp_catch_vfork, "catch vfork"},
3084 {bp_catch_exec, "catch exec"},
3085 {bp_catch_catch, "catch catch"},
3086 {bp_catch_throw, "catch throw"}
3089 static char *bpdisps[] =
3090 {"del", "dstp", "dis", "keep"};
3091 static char bpenables[] = "nynny";
3092 char wrap_indent[80];
3093 struct ui_stream *stb = ui_out_stream_new (uiout);
3094 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3097 ui_out_tuple_begin (uiout, "bkpt");
3101 ui_out_field_int (uiout, "number", b->number);
3105 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3106 || ((int) b->type != bptypes[(int) b->type].type))
3107 internal_error (__FILE__, __LINE__,
3108 "bptypes table does not describe type #%d.",
3110 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3114 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3118 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3119 ui_out_spaces (uiout, 2);
3122 strcpy (wrap_indent, " ");
3125 if (TARGET_ADDR_BIT <= 32)
3126 strcat (wrap_indent, " ");
3128 strcat (wrap_indent, " ");
3133 internal_error (__FILE__, __LINE__,
3134 "print_one_breakpoint: bp_none encountered\n");
3138 case bp_hardware_watchpoint:
3139 case bp_read_watchpoint:
3140 case bp_access_watchpoint:
3141 /* Field 4, the address, is omitted (which makes the columns
3142 not line up too nicely with the headers, but the effect
3143 is relatively readable). */
3145 ui_out_field_skip (uiout, "addr");
3147 print_expression (b->exp, stb->stream);
3148 ui_out_field_stream (uiout, "what", stb);
3152 case bp_catch_unload:
3153 /* Field 4, the address, is omitted (which makes the columns
3154 not line up too nicely with the headers, but the effect
3155 is relatively readable). */
3157 ui_out_field_skip (uiout, "addr");
3159 if (b->dll_pathname == NULL)
3161 ui_out_field_string (uiout, "what", "<any library>");
3162 ui_out_spaces (uiout, 1);
3166 ui_out_text (uiout, "library \"");
3167 ui_out_field_string (uiout, "what", b->dll_pathname);
3168 ui_out_text (uiout, "\" ");
3173 case bp_catch_vfork:
3174 /* Field 4, the address, is omitted (which makes the columns
3175 not line up too nicely with the headers, but the effect
3176 is relatively readable). */
3178 ui_out_field_skip (uiout, "addr");
3180 if (b->forked_inferior_pid != 0)
3182 ui_out_text (uiout, "process ");
3183 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3184 ui_out_spaces (uiout, 1);
3188 /* Field 4, the address, is omitted (which makes the columns
3189 not line up too nicely with the headers, but the effect
3190 is relatively readable). */
3192 ui_out_field_skip (uiout, "addr");
3194 if (b->exec_pathname != NULL)
3196 ui_out_text (uiout, "program \"");
3197 ui_out_field_string (uiout, "what", b->exec_pathname);
3198 ui_out_text (uiout, "\" ");
3202 case bp_catch_catch:
3203 /* Field 4, the address, is omitted (which makes the columns
3204 not line up too nicely with the headers, but the effect
3205 is relatively readable). */
3207 ui_out_field_skip (uiout, "addr");
3209 ui_out_field_string (uiout, "what", "exception catch");
3210 ui_out_spaces (uiout, 1);
3213 case bp_catch_throw:
3214 /* Field 4, the address, is omitted (which makes the columns
3215 not line up too nicely with the headers, but the effect
3216 is relatively readable). */
3218 ui_out_field_skip (uiout, "addr");
3220 ui_out_field_string (uiout, "what", "exception throw");
3221 ui_out_spaces (uiout, 1);
3225 case bp_hardware_breakpoint:
3229 case bp_longjmp_resume:
3230 case bp_step_resume:
3231 case bp_through_sigtramp:
3232 case bp_watchpoint_scope:
3234 case bp_shlib_event:
3235 case bp_thread_event:
3236 case bp_overlay_event:
3240 ui_out_field_core_addr (uiout, "addr", b->address);
3243 *last_addr = b->address;
3246 sym = find_pc_sect_function (b->address, b->section);
3249 ui_out_text (uiout, "in ");
3250 ui_out_field_string (uiout, "func",
3251 SYMBOL_SOURCE_NAME (sym));
3252 ui_out_wrap_hint (uiout, wrap_indent);
3253 ui_out_text (uiout, " at ");
3255 ui_out_field_string (uiout, "file", b->source_file);
3256 ui_out_text (uiout, ":");
3257 ui_out_field_int (uiout, "line", b->line_number);
3261 print_address_symbolic (b->address, stb->stream, demangle, "");
3262 ui_out_field_stream (uiout, "at", stb);
3267 if (b->thread != -1)
3269 /* FIXME: This seems to be redundant and lost here; see the
3270 "stop only in" line a little further down. */
3271 ui_out_text (uiout, " thread ");
3272 ui_out_field_int (uiout, "thread", b->thread);
3275 ui_out_text (uiout, "\n");
3280 ui_out_text (uiout, "\tstop only in stack frame at ");
3281 ui_out_field_core_addr (uiout, "frame", b->frame);
3282 ui_out_text (uiout, "\n");
3288 ui_out_text (uiout, "\tstop only if ");
3289 print_expression (b->cond, stb->stream);
3290 ui_out_field_stream (uiout, "cond", stb);
3291 ui_out_text (uiout, "\n");
3294 if (b->thread != -1)
3296 /* FIXME should make an annotation for this */
3297 ui_out_text (uiout, "\tstop only in thread ");
3298 ui_out_field_int (uiout, "thread", b->thread);
3299 ui_out_text (uiout, "\n");
3302 if (show_breakpoint_hit_counts && b->hit_count)
3304 /* FIXME should make an annotation for this */
3305 if (ep_is_catchpoint (b))
3306 ui_out_text (uiout, "\tcatchpoint");
3308 ui_out_text (uiout, "\tbreakpoint");
3309 ui_out_text (uiout, " already hit ");
3310 ui_out_field_int (uiout, "times", b->hit_count);
3311 if (b->hit_count == 1)
3312 ui_out_text (uiout, " time\n");
3314 ui_out_text (uiout, " times\n");
3317 /* Output the count also if it is zero, but only if this is
3318 mi. FIXME: Should have a better test for this. */
3319 if (ui_out_is_mi_like_p (uiout))
3320 if (show_breakpoint_hit_counts && b->hit_count == 0)
3321 ui_out_field_int (uiout, "times", b->hit_count);
3323 if (b->ignore_count)
3326 ui_out_text (uiout, "\tignore next ");
3327 ui_out_field_int (uiout, "ignore", b->ignore_count);
3328 ui_out_text (uiout, " hits\n");
3331 if ((l = b->commands))
3334 ui_out_tuple_begin (uiout, "script");
3335 print_command_lines (uiout, l, 4);
3336 ui_out_tuple_end (uiout);
3338 ui_out_tuple_end (uiout);
3339 do_cleanups (old_chain);
3342 struct captured_breakpoint_query_args
3348 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3350 struct captured_breakpoint_query_args *args = data;
3351 register struct breakpoint *b;
3352 CORE_ADDR dummy_addr = 0;
3355 if (args->bnum == b->number)
3357 print_one_breakpoint (b, &dummy_addr);
3365 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3367 struct captured_breakpoint_query_args args;
3369 /* For the moment we don't trust print_one_breakpoint() to not throw
3371 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3372 NULL, RETURN_MASK_ALL);
3375 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3376 catchpoints, et.al.). */
3379 user_settable_breakpoint (const struct breakpoint *b)
3381 return (b->type == bp_breakpoint
3382 || b->type == bp_catch_load
3383 || b->type == bp_catch_unload
3384 || b->type == bp_catch_fork
3385 || b->type == bp_catch_vfork
3386 || b->type == bp_catch_exec
3387 || b->type == bp_catch_catch
3388 || b->type == bp_catch_throw
3389 || b->type == bp_hardware_breakpoint
3390 || b->type == bp_watchpoint
3391 || b->type == bp_read_watchpoint
3392 || b->type == bp_access_watchpoint
3393 || b->type == bp_hardware_watchpoint);
3396 /* Print information on user settable breakpoint (watchpoint, etc)
3397 number BNUM. If BNUM is -1 print all user settable breakpoints.
3398 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3401 breakpoint_1 (int bnum, int allflag)
3403 register struct breakpoint *b;
3404 CORE_ADDR last_addr = (CORE_ADDR) -1;
3405 int nr_printable_breakpoints;
3407 /* Compute the number of rows in the table. */
3408 nr_printable_breakpoints = 0;
3411 || bnum == b->number)
3413 if (allflag || user_settable_breakpoint (b))
3414 nr_printable_breakpoints++;
3418 ui_out_table_begin (uiout, 6, nr_printable_breakpoints, "BreakpointTable");
3420 ui_out_table_begin (uiout, 5, nr_printable_breakpoints, "BreakpointTable");
3422 if (nr_printable_breakpoints > 0)
3423 annotate_breakpoints_headers ();
3424 if (nr_printable_breakpoints > 0)
3426 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3427 if (nr_printable_breakpoints > 0)
3429 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3430 if (nr_printable_breakpoints > 0)
3432 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3433 if (nr_printable_breakpoints > 0)
3435 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3438 if (nr_printable_breakpoints > 0)
3440 if (TARGET_ADDR_BIT <= 32)
3441 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3443 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3445 if (nr_printable_breakpoints > 0)
3447 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3448 ui_out_table_body (uiout);
3449 if (nr_printable_breakpoints > 0)
3450 annotate_breakpoints_table ();
3454 || bnum == b->number)
3456 /* We only print out user settable breakpoints unless the
3458 if (allflag || user_settable_breakpoint (b))
3459 print_one_breakpoint (b, &last_addr);
3462 ui_out_table_end (uiout);
3464 if (nr_printable_breakpoints == 0)
3467 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3469 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3474 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3475 that a comparison of an unsigned with -1 is always false. */
3476 if (last_addr != (CORE_ADDR) -1)
3477 set_next_address (last_addr);
3480 /* FIXME? Should this be moved up so that it is only called when
3481 there have been breakpoints? */
3482 annotate_breakpoints_table_end ();
3487 breakpoints_info (char *bnum_exp, int from_tty)
3492 bnum = parse_and_eval_long (bnum_exp);
3494 breakpoint_1 (bnum, 0);
3499 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3504 bnum = parse_and_eval_long (bnum_exp);
3506 breakpoint_1 (bnum, 1);
3509 /* Print a message describing any breakpoints set at PC. */
3512 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3514 register int others = 0;
3515 register struct breakpoint *b;
3518 if (b->address == pc) /* address match / overlay match */
3519 if (!overlay_debugging || b->section == section)
3523 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3525 if (b->address == pc) /* address match / overlay match */
3526 if (!overlay_debugging || b->section == section)
3529 printf_filtered ("%d%s%s ",
3531 ((b->enable_state == bp_disabled ||
3532 b->enable_state == bp_shlib_disabled ||
3533 b->enable_state == bp_call_disabled)
3535 : b->enable_state == bp_permanent
3539 : ((others == 1) ? " and" : ""));
3541 printf_filtered ("also set at pc ");
3542 print_address_numeric (pc, 1, gdb_stdout);
3543 printf_filtered (".\n");
3547 /* Set the default place to put a breakpoint
3548 for the `break' command with no arguments. */
3551 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3554 default_breakpoint_valid = valid;
3555 default_breakpoint_address = addr;
3556 default_breakpoint_symtab = symtab;
3557 default_breakpoint_line = line;
3560 /* Return true iff it is meaningful to use the address member of
3561 BPT. For some breakpoint types, the address member is irrelevant
3562 and it makes no sense to attempt to compare it to other addresses
3563 (or use it for any other purpose either).
3565 More specifically, each of the following breakpoint types will always
3566 have a zero valued address and we don't want check_duplicates() to mark
3567 breakpoints of any of these types to be a duplicate of an actual
3568 breakpoint at address zero:
3571 bp_hardware_watchpoint
3573 bp_access_watchpoint
3580 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3582 enum bptype type = bpt->type;
3584 return (type != bp_watchpoint
3585 && type != bp_hardware_watchpoint
3586 && type != bp_read_watchpoint
3587 && type != bp_access_watchpoint
3588 && type != bp_catch_exec
3589 && type != bp_longjmp_resume
3590 && type != bp_catch_fork
3591 && type != bp_catch_vfork);
3594 /* Rescan breakpoints at the same address and section as BPT,
3595 marking the first one as "first" and any others as "duplicates".
3596 This is so that the bpt instruction is only inserted once.
3597 If we have a permanent breakpoint at the same place as BPT, make
3598 that one the official one, and the rest as duplicates. */
3601 check_duplicates (struct breakpoint *bpt)
3603 register struct breakpoint *b;
3604 register int count = 0;
3605 struct breakpoint *perm_bp = 0;
3606 CORE_ADDR address = bpt->address;
3607 asection *section = bpt->section;
3609 if (! breakpoint_address_is_meaningful (bpt))
3613 if (b->enable_state != bp_disabled
3614 && b->enable_state != bp_shlib_disabled
3615 && b->enable_state != bp_call_disabled
3616 && b->address == address /* address / overlay match */
3617 && (!overlay_debugging || b->section == section)
3618 && breakpoint_address_is_meaningful (b))
3620 /* Have we found a permanent breakpoint? */
3621 if (b->enable_state == bp_permanent)
3628 b->duplicate = count > 1;
3631 /* If we found a permanent breakpoint at this address, go over the
3632 list again and declare all the other breakpoints there to be the
3636 perm_bp->duplicate = 0;
3638 /* Permanent breakpoint should always be inserted. */
3639 if (! perm_bp->inserted)
3640 internal_error (__FILE__, __LINE__,
3641 "allegedly permanent breakpoint is not "
3642 "actually inserted");
3648 internal_error (__FILE__, __LINE__,
3649 "another breakpoint was inserted on top of "
3650 "a permanent breakpoint");
3652 if (b->enable_state != bp_disabled
3653 && b->enable_state != bp_shlib_disabled
3654 && b->enable_state != bp_call_disabled
3655 && b->address == address /* address / overlay match */
3656 && (!overlay_debugging || b->section == section)
3657 && breakpoint_address_is_meaningful (b))
3663 /* set_raw_breakpoint() is a low level routine for allocating and
3664 partially initializing a breakpoint of type BPTYPE. The newly
3665 created breakpoint's address, section, source file name, and line
3666 number are provided by SAL. The newly created and partially
3667 initialized breakpoint is added to the breakpoint chain and
3668 is also returned as the value of this function.
3670 It is expected that the caller will complete the initialization of
3671 the newly created breakpoint struct as well as output any status
3672 information regarding the creation of a new breakpoint. In
3673 particular, set_raw_breakpoint() does NOT set the breakpoint
3674 number! Care should be taken to not allow an error() to occur
3675 prior to completing the initialization of the breakpoint. If this
3676 should happen, a bogus breakpoint will be left on the chain. */
3679 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3681 register struct breakpoint *b, *b1;
3683 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3684 memset (b, 0, sizeof (*b));
3685 b->address = sal.pc;
3686 if (sal.symtab == NULL)
3687 b->source_file = NULL;
3689 b->source_file = savestring (sal.symtab->filename,
3690 strlen (sal.symtab->filename));
3691 b->section = sal.section;
3693 b->language = current_language->la_language;
3694 b->input_radix = input_radix;
3696 b->line_number = sal.line;
3697 b->enable_state = bp_enabled;
3700 b->ignore_count = 0;
3703 b->dll_pathname = NULL;
3704 b->triggered_dll_pathname = NULL;
3705 b->forked_inferior_pid = 0;
3706 b->exec_pathname = NULL;
3708 /* Add this breakpoint to the end of the chain
3709 so that a list of breakpoints will come out in order
3710 of increasing numbers. */
3712 b1 = breakpoint_chain;
3714 breakpoint_chain = b;
3722 check_duplicates (b);
3723 breakpoints_changed ();
3729 /* Note that the breakpoint object B describes a permanent breakpoint
3730 instruction, hard-wired into the inferior's code. */
3732 make_breakpoint_permanent (struct breakpoint *b)
3734 b->enable_state = bp_permanent;
3736 /* By definition, permanent breakpoints are already present in the code. */
3740 static struct breakpoint *
3741 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
3743 static int internal_breakpoint_number = -1;
3744 struct symtab_and_line sal;
3745 struct breakpoint *b;
3747 INIT_SAL (&sal); /* initialize to zeroes */
3750 sal.section = find_pc_overlay (sal.pc);
3752 b = set_raw_breakpoint (sal, type);
3753 b->number = internal_breakpoint_number--;
3754 b->disposition = disp_donttouch;
3761 create_longjmp_breakpoint (char *func_name)
3763 struct breakpoint *b;
3764 struct minimal_symbol *m;
3766 if (func_name == NULL)
3767 b = create_internal_breakpoint (0, bp_longjmp_resume);
3770 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3773 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
3776 b->enable_state = bp_disabled;
3779 b->addr_string = xstrdup (func_name);
3782 /* Call this routine when stepping and nexting to enable a breakpoint
3783 if we do a longjmp(). When we hit that breakpoint, call
3784 set_longjmp_resume_breakpoint() to figure out where we are going. */
3787 enable_longjmp_breakpoint (void)
3789 register struct breakpoint *b;
3792 if (b->type == bp_longjmp)
3794 b->enable_state = bp_enabled;
3795 check_duplicates (b);
3800 disable_longjmp_breakpoint (void)
3802 register struct breakpoint *b;
3805 if (b->type == bp_longjmp
3806 || b->type == bp_longjmp_resume)
3808 b->enable_state = bp_disabled;
3809 check_duplicates (b);
3814 create_overlay_event_breakpoint (char *func_name)
3816 struct breakpoint *b;
3817 struct minimal_symbol *m;
3819 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3822 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
3824 b->addr_string = xstrdup (func_name);
3826 if (overlay_debugging == ovly_auto)
3827 b->enable_state = bp_enabled;
3829 b->enable_state = bp_disabled;
3833 enable_overlay_breakpoints (void)
3835 register struct breakpoint *b;
3838 if (b->type == bp_overlay_event)
3840 b->enable_state = bp_enabled;
3841 check_duplicates (b);
3846 disable_overlay_breakpoints (void)
3848 register struct breakpoint *b;
3851 if (b->type == bp_overlay_event)
3853 b->enable_state = bp_disabled;
3854 check_duplicates (b);
3859 create_thread_event_breakpoint (CORE_ADDR address)
3861 struct breakpoint *b;
3862 char addr_string[80]; /* Surely an addr can't be longer than that. */
3864 b = create_internal_breakpoint (address, bp_thread_event);
3866 b->enable_state = bp_enabled;
3867 /* addr_string has to be used or breakpoint_re_set will delete me. */
3868 sprintf (addr_string, "*0x%s", paddr (b->address));
3869 b->addr_string = xstrdup (addr_string);
3875 remove_thread_event_breakpoints (void)
3877 struct breakpoint *b, *temp;
3879 ALL_BREAKPOINTS_SAFE (b, temp)
3880 if (b->type == bp_thread_event)
3881 delete_breakpoint (b);
3886 remove_solib_event_breakpoints (void)
3888 register struct breakpoint *b, *temp;
3890 ALL_BREAKPOINTS_SAFE (b, temp)
3891 if (b->type == bp_shlib_event)
3892 delete_breakpoint (b);
3896 create_solib_event_breakpoint (CORE_ADDR address)
3898 struct breakpoint *b;
3900 b = create_internal_breakpoint (address, bp_shlib_event);
3904 /* Disable any breakpoints that are on code in shared libraries. Only
3905 apply to enabled breakpoints, disabled ones can just stay disabled. */
3908 disable_breakpoints_in_shlibs (int silent)
3910 struct breakpoint *b;
3911 int disabled_shlib_breaks = 0;
3913 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3916 #if defined (PC_SOLIB)
3917 if (((b->type == bp_breakpoint) ||
3918 (b->type == bp_hardware_breakpoint)) &&
3919 b->enable_state == bp_enabled &&
3921 PC_SOLIB (b->address))
3923 b->enable_state = bp_shlib_disabled;
3926 if (!disabled_shlib_breaks)
3928 target_terminal_ours_for_output ();
3929 warning ("Temporarily disabling shared library breakpoints:");
3931 disabled_shlib_breaks = 1;
3932 warning ("breakpoint #%d ", b->number);
3939 /* Try to reenable any breakpoints in shared libraries. */
3941 re_enable_breakpoints_in_shlibs (void)
3943 struct breakpoint *b;
3946 if (b->enable_state == bp_shlib_disabled)
3950 /* Do not reenable the breakpoint if the shared library
3951 is still not mapped in. */
3952 if (target_read_memory (b->address, buf, 1) == 0)
3953 b->enable_state = bp_enabled;
3960 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
3961 char *cond_string, enum bptype bp_kind)
3963 struct breakpoint *b;
3964 struct symtabs_and_lines sals;
3965 struct cleanup *old_chain;
3966 struct cleanup *canonical_strings_chain = NULL;
3967 char *addr_start = hookname;
3968 char *addr_end = NULL;
3969 char **canonical = (char **) NULL;
3970 int thread = -1; /* All threads. */
3972 /* Set a breakpoint on the specified hook. */
3973 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3974 addr_end = hookname;
3976 if (sals.nelts == 0)
3978 warning ("Unable to set a breakpoint on dynamic linker callback.");
3979 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3980 warning ("GDB will be unable to track shl_load/shl_unload calls");
3983 if (sals.nelts != 1)
3985 warning ("Unable to set unique breakpoint on dynamic linker callback.");
3986 warning ("GDB will be unable to track shl_load/shl_unload calls");
3990 /* Make sure that all storage allocated in decode_line_1 gets freed
3991 in case the following errors out. */
3992 old_chain = make_cleanup (xfree, sals.sals);
3993 if (canonical != (char **) NULL)
3995 make_cleanup (xfree, canonical);
3996 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3997 if (canonical[0] != NULL)
3998 make_cleanup (xfree, canonical[0]);
4001 resolve_sal_pc (&sals.sals[0]);
4003 /* Remove the canonical strings from the cleanup, they are needed below. */
4004 if (canonical != (char **) NULL)
4005 discard_cleanups (canonical_strings_chain);
4007 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4008 set_breakpoint_count (breakpoint_count + 1);
4009 b->number = breakpoint_count;
4011 b->cond_string = (cond_string == NULL) ?
4012 NULL : savestring (cond_string, strlen (cond_string));
4015 if (canonical != (char **) NULL && canonical[0] != NULL)
4016 b->addr_string = canonical[0];
4017 else if (addr_start)
4018 b->addr_string = savestring (addr_start, addr_end - addr_start);
4020 b->enable_state = bp_enabled;
4021 b->disposition = tempflag ? disp_del : disp_donttouch;
4023 if (dll_pathname == NULL)
4024 b->dll_pathname = NULL;
4027 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4028 strcpy (b->dll_pathname, dll_pathname);
4032 do_cleanups (old_chain);
4036 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4037 char *dll_pathname, char *cond_string)
4039 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4040 cond_string, bp_catch_load);
4044 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4045 char *dll_pathname, char *cond_string)
4047 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4048 cond_string, bp_catch_unload);
4052 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4053 enum bptype bp_kind)
4055 struct symtab_and_line sal;
4056 struct breakpoint *b;
4057 int thread = -1; /* All threads. */
4064 b = set_raw_breakpoint (sal, bp_kind);
4065 set_breakpoint_count (breakpoint_count + 1);
4066 b->number = breakpoint_count;
4068 b->cond_string = (cond_string == NULL) ?
4069 NULL : savestring (cond_string, strlen (cond_string));
4071 b->addr_string = NULL;
4072 b->enable_state = bp_enabled;
4073 b->disposition = tempflag ? disp_del : disp_donttouch;
4074 b->forked_inferior_pid = 0;
4080 create_fork_event_catchpoint (int tempflag, char *cond_string)
4082 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4086 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4088 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4092 create_exec_event_catchpoint (int tempflag, char *cond_string)
4094 struct symtab_and_line sal;
4095 struct breakpoint *b;
4096 int thread = -1; /* All threads. */
4103 b = set_raw_breakpoint (sal, bp_catch_exec);
4104 set_breakpoint_count (breakpoint_count + 1);
4105 b->number = breakpoint_count;
4107 b->cond_string = (cond_string == NULL) ?
4108 NULL : savestring (cond_string, strlen (cond_string));
4110 b->addr_string = NULL;
4111 b->enable_state = bp_enabled;
4112 b->disposition = tempflag ? disp_del : disp_donttouch;
4118 hw_breakpoint_used_count (void)
4120 register struct breakpoint *b;
4125 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4133 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4135 register struct breakpoint *b;
4138 *other_type_used = 0;
4141 if (b->enable_state == bp_enabled)
4143 if (b->type == type)
4145 else if ((b->type == bp_hardware_watchpoint ||
4146 b->type == bp_read_watchpoint ||
4147 b->type == bp_access_watchpoint)
4148 && b->enable_state == bp_enabled)
4149 *other_type_used = 1;
4155 /* Call this after hitting the longjmp() breakpoint. Use this to set
4156 a new breakpoint at the target of the jmp_buf.
4158 FIXME - This ought to be done by setting a temporary breakpoint
4159 that gets deleted automatically... */
4162 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
4164 register struct breakpoint *b;
4167 if (b->type == bp_longjmp_resume)
4170 b->enable_state = bp_enabled;
4172 b->frame = frame->frame;
4175 check_duplicates (b);
4181 disable_watchpoints_before_interactive_call_start (void)
4183 struct breakpoint *b;
4187 if (((b->type == bp_watchpoint)
4188 || (b->type == bp_hardware_watchpoint)
4189 || (b->type == bp_read_watchpoint)
4190 || (b->type == bp_access_watchpoint)
4191 || ep_is_exception_catchpoint (b))
4192 && (b->enable_state == bp_enabled))
4194 b->enable_state = bp_call_disabled;
4195 check_duplicates (b);
4201 enable_watchpoints_after_interactive_call_stop (void)
4203 struct breakpoint *b;
4207 if (((b->type == bp_watchpoint)
4208 || (b->type == bp_hardware_watchpoint)
4209 || (b->type == bp_read_watchpoint)
4210 || (b->type == bp_access_watchpoint)
4211 || ep_is_exception_catchpoint (b))
4212 && (b->enable_state == bp_call_disabled))
4214 b->enable_state = bp_enabled;
4215 check_duplicates (b);
4221 /* Set a breakpoint that will evaporate an end of command
4222 at address specified by SAL.
4223 Restrict it to frame FRAME if FRAME is nonzero. */
4226 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4229 register struct breakpoint *b;
4230 b = set_raw_breakpoint (sal, type);
4231 b->enable_state = bp_enabled;
4232 b->disposition = disp_donttouch;
4233 b->frame = (frame ? frame->frame : 0);
4235 /* If we're debugging a multi-threaded program, then we
4236 want momentary breakpoints to be active in only a
4237 single thread of control. */
4238 if (in_thread_list (inferior_ptid))
4239 b->thread = pid_to_thread_id (inferior_ptid);
4245 /* Tell the user we have just set a breakpoint B. */
4248 mention (struct breakpoint *b)
4251 struct cleanup *old_chain;
4252 struct ui_stream *stb;
4254 stb = ui_out_stream_new (uiout);
4255 old_chain = make_cleanup_ui_out_stream_delete (stb);
4257 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4258 watchpoint) other than breakpoint creation. It should be possible to
4259 clean this up and at the same time replace the random calls to
4260 breakpoint_changed with this hook, as has already been done for
4261 delete_breakpoint_hook and so on. */
4262 if (create_breakpoint_hook)
4263 create_breakpoint_hook (b);
4264 breakpoint_create_event (b->number);
4269 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4272 ui_out_text (uiout, "Watchpoint ");
4273 ui_out_tuple_begin (uiout, "wpt");
4274 ui_out_field_int (uiout, "number", b->number);
4275 ui_out_text (uiout, ": ");
4276 print_expression (b->exp, stb->stream);
4277 ui_out_field_stream (uiout, "exp", stb);
4278 ui_out_tuple_end (uiout);
4280 case bp_hardware_watchpoint:
4281 ui_out_text (uiout, "Hardware watchpoint ");
4282 ui_out_tuple_begin (uiout, "wpt");
4283 ui_out_field_int (uiout, "number", b->number);
4284 ui_out_text (uiout, ": ");
4285 print_expression (b->exp, stb->stream);
4286 ui_out_field_stream (uiout, "exp", stb);
4287 ui_out_tuple_end (uiout);
4289 case bp_read_watchpoint:
4290 ui_out_text (uiout, "Hardware read watchpoint ");
4291 ui_out_tuple_begin (uiout, "hw-rwpt");
4292 ui_out_field_int (uiout, "number", b->number);
4293 ui_out_text (uiout, ": ");
4294 print_expression (b->exp, stb->stream);
4295 ui_out_field_stream (uiout, "exp", stb);
4296 ui_out_tuple_end (uiout);
4298 case bp_access_watchpoint:
4299 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4300 ui_out_tuple_begin (uiout, "hw-awpt");
4301 ui_out_field_int (uiout, "number", b->number);
4302 ui_out_text (uiout, ": ");
4303 print_expression (b->exp, stb->stream);
4304 ui_out_field_stream (uiout, "exp", stb);
4305 ui_out_tuple_end (uiout);
4308 if (ui_out_is_mi_like_p (uiout))
4313 printf_filtered ("Breakpoint %d", b->number);
4316 case bp_hardware_breakpoint:
4317 if (ui_out_is_mi_like_p (uiout))
4322 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4326 case bp_catch_unload:
4327 printf_filtered ("Catchpoint %d (%s %s)",
4329 (b->type == bp_catch_load) ? "load" : "unload",
4330 (b->dll_pathname != NULL) ?
4331 b->dll_pathname : "<any library>");
4334 case bp_catch_vfork:
4335 printf_filtered ("Catchpoint %d (%s)",
4337 (b->type == bp_catch_fork) ? "fork" : "vfork");
4340 printf_filtered ("Catchpoint %d (exec)",
4343 case bp_catch_catch:
4344 case bp_catch_throw:
4345 printf_filtered ("Catchpoint %d (%s)",
4347 (b->type == bp_catch_catch) ? "catch" : "throw");
4353 case bp_longjmp_resume:
4354 case bp_step_resume:
4355 case bp_through_sigtramp:
4357 case bp_watchpoint_scope:
4358 case bp_shlib_event:
4359 case bp_thread_event:
4360 case bp_overlay_event:
4365 if (addressprint || b->source_file == NULL)
4367 printf_filtered (" at ");
4368 print_address_numeric (b->address, 1, gdb_stdout);
4371 printf_filtered (": file %s, line %d.",
4372 b->source_file, b->line_number);
4374 do_cleanups (old_chain);
4375 if (ui_out_is_mi_like_p (uiout))
4377 printf_filtered ("\n");
4381 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4382 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4383 COND[i] and COND_STRING[i] values.
4385 NOTE: If the function succeeds, the caller is expected to cleanup
4386 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4387 array contents). If the function fails (error() is called), the
4388 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4389 COND and SALS arrays and each of those arrays contents. */
4392 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4393 struct expression **cond, char **cond_string,
4394 enum bptype type, enum bpdisp disposition,
4395 int thread, int ignore_count, int from_tty)
4397 if (type == bp_hardware_breakpoint)
4399 int i = hw_breakpoint_used_count ();
4400 int target_resources_ok =
4401 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4403 if (target_resources_ok == 0)
4404 error ("No hardware breakpoint support in the target.");
4405 else if (target_resources_ok < 0)
4406 error ("Hardware breakpoints used exceeds limit.");
4409 /* Now set all the breakpoints. */
4412 for (i = 0; i < sals.nelts; i++)
4414 struct breakpoint *b;
4415 struct symtab_and_line sal = sals.sals[i];
4418 describe_other_breakpoints (sal.pc, sal.section);
4420 b = set_raw_breakpoint (sal, type);
4421 set_breakpoint_count (breakpoint_count + 1);
4422 b->number = breakpoint_count;
4425 b->addr_string = addr_string[i];
4426 b->cond_string = cond_string[i];
4427 b->ignore_count = ignore_count;
4428 b->enable_state = bp_enabled;
4429 b->disposition = disposition;
4435 /* Parse ARG which is assumed to be a SAL specification possibly
4436 followed by conditionals. On return, SALS contains an array of SAL
4437 addresses found. ADDR_STRING contains a vector of (canonical)
4438 address strings. ARG points to the end of the SAL. */
4441 parse_breakpoint_sals (char **address,
4442 struct symtabs_and_lines *sals,
4443 char ***addr_string)
4445 char *addr_start = *address;
4446 *addr_string = NULL;
4447 /* If no arg given, or if first arg is 'if ', use the default
4449 if ((*address) == NULL
4450 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4452 if (default_breakpoint_valid)
4454 struct symtab_and_line sal;
4455 INIT_SAL (&sal); /* initialize to zeroes */
4456 sals->sals = (struct symtab_and_line *)
4457 xmalloc (sizeof (struct symtab_and_line));
4458 sal.pc = default_breakpoint_address;
4459 sal.line = default_breakpoint_line;
4460 sal.symtab = default_breakpoint_symtab;
4461 sal.section = find_pc_overlay (sal.pc);
4462 sals->sals[0] = sal;
4466 error ("No default breakpoint address now.");
4470 /* Force almost all breakpoints to be in terms of the
4471 current_source_symtab (which is decode_line_1's default). This
4472 should produce the results we want almost all of the time while
4473 leaving default_breakpoint_* alone. */
4474 if (default_breakpoint_valid
4475 && (!current_source_symtab
4476 || (strchr ("+-", (*address)[0]) != NULL)))
4477 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4478 default_breakpoint_line, addr_string);
4480 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4482 /* For any SAL that didn't have a canonical string, fill one in. */
4483 if (sals->nelts > 0 && *addr_string == NULL)
4484 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4485 if (addr_start != (*address))
4488 for (i = 0; i < sals->nelts; i++)
4490 /* Add the string if not present. */
4491 if ((*addr_string)[i] == NULL)
4492 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4498 /* Convert each SAL into a real PC. Verify that the PC can be
4499 inserted as a breakpoint. If it can't throw an error. */
4502 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4506 for (i = 0; i < sals->nelts; i++)
4508 resolve_sal_pc (&sals->sals[i]);
4510 /* It's possible for the PC to be nonzero, but still an illegal
4511 value on some targets.
4513 For example, on HP-UX if you start gdb, and before running the
4514 inferior you try to set a breakpoint on a shared library function
4515 "foo" where the inferior doesn't call "foo" directly but does
4516 pass its address to another function call, then we do find a
4517 minimal symbol for the "foo", but it's address is invalid.
4518 (Appears to be an index into a table that the loader sets up
4519 when the inferior is run.)
4521 Give the target a chance to bless sals.sals[i].pc before we
4522 try to make a breakpoint for it. */
4523 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4525 if (address == NULL)
4526 error ("Cannot break without a running program.");
4528 error ("Cannot break on %s without a running program.",
4534 /* Set a breakpoint according to ARG (function, linenum or *address)
4535 flag: first bit : 0 non-temporary, 1 temporary.
4536 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4539 break_command_1 (char *arg, int flag, int from_tty)
4541 int tempflag, hardwareflag;
4542 struct symtabs_and_lines sals;
4543 register struct expression **cond = 0;
4544 /* Pointers in arg to the start, and one past the end, of the
4546 char **cond_string = (char **) NULL;
4547 char *addr_start = arg;
4549 struct cleanup *old_chain;
4550 struct cleanup *breakpoint_chain = NULL;
4553 int ignore_count = 0;
4555 hardwareflag = flag & BP_HARDWAREFLAG;
4556 tempflag = flag & BP_TEMPFLAG;
4561 parse_breakpoint_sals (&arg, &sals, &addr_string);
4566 /* Create a chain of things that always need to be cleaned up. */
4567 old_chain = make_cleanup (null_cleanup, 0);
4569 /* Make sure that all storage allocated to SALS gets freed. */
4570 make_cleanup (xfree, sals.sals);
4572 /* Cleanup the addr_string array but not its contents. */
4573 make_cleanup (xfree, addr_string);
4575 /* Allocate space for all the cond expressions. */
4576 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4577 make_cleanup (xfree, cond);
4579 /* Allocate space for all the cond strings. */
4580 cond_string = xcalloc (sals.nelts, sizeof (char **));
4581 make_cleanup (xfree, cond_string);
4583 /* ----------------------------- SNIP -----------------------------
4584 Anything added to the cleanup chain beyond this point is assumed
4585 to be part of a breakpoint. If the breakpoint create succeeds
4586 then the memory is not reclaimed. */
4587 breakpoint_chain = make_cleanup (null_cleanup, 0);
4589 /* Mark the contents of the addr_string for cleanup. These go on
4590 the breakpoint_chain and only occure if the breakpoint create
4592 for (i = 0; i < sals.nelts; i++)
4594 if (addr_string[i] != NULL)
4595 make_cleanup (xfree, addr_string[i]);
4598 /* Resolve all line numbers to PC's and verify that the addresses
4599 are ok for the target. */
4600 breakpoint_sals_to_pc (&sals, addr_start);
4602 /* Verify that condition can be parsed, before setting any
4603 breakpoints. Allocate a separate condition expression for each
4605 thread = -1; /* No specific thread yet */
4606 for (i = 0; i < sals.nelts; i++)
4613 char *cond_start = NULL;
4614 char *cond_end = NULL;
4615 while (*tok == ' ' || *tok == '\t')
4620 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4623 toklen = end_tok - tok;
4625 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4627 tok = cond_start = end_tok + 1;
4628 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4629 make_cleanup (xfree, cond[i]);
4631 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4632 make_cleanup (xfree, cond_string[i]);
4634 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4640 thread = strtol (tok, &tok, 0);
4642 error ("Junk after thread keyword.");
4643 if (!valid_thread_id (thread))
4644 error ("Unknown thread %d\n", thread);
4647 error ("Junk at end of arguments.");
4651 create_breakpoints (sals, addr_string, cond, cond_string,
4652 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4653 tempflag ? disp_del : disp_donttouch,
4654 thread, ignore_count, from_tty);
4658 warning ("Multiple breakpoints were set.");
4659 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4661 /* That's it. Discard the cleanups for data inserted into the
4663 discard_cleanups (breakpoint_chain);
4664 /* But cleanup everything else. */
4665 do_cleanups (old_chain);
4668 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4669 linenum or *address) with COND and IGNORE_COUNT. */
4671 struct captured_breakpoint_args
4682 do_captured_breakpoint (void *data)
4684 struct captured_breakpoint_args *args = data;
4685 struct symtabs_and_lines sals;
4686 register struct expression **cond;
4687 struct cleanup *old_chain;
4688 struct cleanup *breakpoint_chain = NULL;
4695 /* Parse the source and lines spec. Delay check that the expression
4696 didn't contain trailing garbage until after cleanups are in
4700 address_end = args->address;
4702 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4707 /* Create a chain of things at always need to be cleaned up. */
4708 old_chain = make_cleanup (null_cleanup, 0);
4710 /* Always have a addr_string array, even if it is empty. */
4711 make_cleanup (xfree, addr_string);
4713 /* Make sure that all storage allocated to SALS gets freed. */
4714 make_cleanup (xfree, sals.sals);
4716 /* Allocate space for all the cond expressions. */
4717 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4718 make_cleanup (xfree, cond);
4720 /* Allocate space for all the cond strings. */
4721 cond_string = xcalloc (sals.nelts, sizeof (char **));
4722 make_cleanup (xfree, cond_string);
4724 /* ----------------------------- SNIP -----------------------------
4725 Anything added to the cleanup chain beyond this point is assumed
4726 to be part of a breakpoint. If the breakpoint create goes
4727 through then that memory is not cleaned up. */
4728 breakpoint_chain = make_cleanup (null_cleanup, 0);
4730 /* Mark the contents of the addr_string for cleanup. These go on
4731 the breakpoint_chain and only occure if the breakpoint create
4733 for (i = 0; i < sals.nelts; i++)
4735 if (addr_string[i] != NULL)
4736 make_cleanup (xfree, addr_string[i]);
4739 /* Wait until now before checking for garbage at the end of the
4740 address. That way cleanups can take care of freeing any
4742 if (*address_end != '\0')
4743 error ("Garbage %s following breakpoint address", address_end);
4745 /* Resolve all line numbers to PC's. */
4746 breakpoint_sals_to_pc (&sals, args->address);
4748 /* Verify that conditions can be parsed, before setting any
4750 for (i = 0; i < sals.nelts; i++)
4752 if (args->condition != NULL)
4754 char *tok = args->condition;
4755 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4757 error ("Garbage %s follows condition", tok);
4758 make_cleanup (xfree, cond[i]);
4759 cond_string[i] = xstrdup (args->condition);
4763 create_breakpoints (sals, addr_string, cond, cond_string,
4764 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4765 args->tempflag ? disp_del : disp_donttouch,
4766 args->thread, args->ignore_count, 0/*from-tty*/);
4768 /* That's it. Discard the cleanups for data inserted into the
4770 discard_cleanups (breakpoint_chain);
4771 /* But cleanup everything else. */
4772 do_cleanups (old_chain);
4777 gdb_breakpoint (char *address, char *condition,
4778 int hardwareflag, int tempflag,
4779 int thread, int ignore_count)
4781 struct captured_breakpoint_args args;
4782 args.address = address;
4783 args.condition = condition;
4784 args.hardwareflag = hardwareflag;
4785 args.tempflag = tempflag;
4786 args.thread = thread;
4787 args.ignore_count = ignore_count;
4788 return catch_errors (do_captured_breakpoint, &args,
4789 NULL, RETURN_MASK_ALL);
4794 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4796 struct frame_info *frame;
4797 CORE_ADDR low, high, selected_pc = 0;
4798 char *extra_args = NULL;
4801 int extra_args_len = 0, if_arg = 0;
4804 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4807 if (default_breakpoint_valid)
4811 selected_pc = selected_frame->pc;
4816 error ("No selected frame.");
4819 error ("No default breakpoint address now.");
4823 extra_args = strchr (arg, ' ');
4827 extra_args_len = strlen (extra_args);
4828 level_arg = (char *) xmalloc (extra_args - arg);
4829 strncpy (level_arg, arg, extra_args - arg - 1);
4830 level_arg[extra_args - arg - 1] = '\0';
4834 level_arg = (char *) xmalloc (strlen (arg) + 1);
4835 strcpy (level_arg, arg);
4838 frame = parse_frame_specification (level_arg);
4840 selected_pc = frame->pc;
4847 extra_args_len = strlen (arg);
4852 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4854 addr_string = (char *) xmalloc (26 + extra_args_len);
4856 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4858 sprintf (addr_string, "*0x%s", paddr_nz (high));
4859 break_command_1 (addr_string, flag, from_tty);
4860 xfree (addr_string);
4863 error ("No function contains the specified address");
4866 error ("Unable to set breakpoint at procedure exit");
4871 break_at_finish_command_1 (char *arg, int flag, int from_tty)
4873 char *addr_string, *break_string, *beg_addr_string;
4874 CORE_ADDR low, high;
4875 struct symtabs_and_lines sals;
4876 struct symtab_and_line sal;
4877 struct cleanup *old_chain;
4878 char *extra_args = NULL;
4879 int extra_args_len = 0;
4883 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4885 if (default_breakpoint_valid)
4889 addr_string = (char *) xmalloc (15);
4890 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
4895 error ("No selected frame.");
4898 error ("No default breakpoint address now.");
4902 addr_string = (char *) xmalloc (strlen (arg) + 1);
4903 strcpy (addr_string, arg);
4909 extra_args_len = strlen (arg);
4913 /* get the stuff after the function name or address */
4914 extra_args = strchr (arg, ' ');
4918 extra_args_len = strlen (extra_args);
4925 beg_addr_string = addr_string;
4926 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4929 xfree (beg_addr_string);
4930 old_chain = make_cleanup (xfree, sals.sals);
4931 for (i = 0; (i < sals.nelts); i++)
4934 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
4936 break_string = (char *) xmalloc (extra_args_len + 26);
4938 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
4940 sprintf (break_string, "*0x%s", paddr_nz (high));
4941 break_command_1 (break_string, flag, from_tty);
4942 xfree (break_string);
4945 error ("No function contains the specified address");
4949 warning ("Multiple breakpoints were set.\n");
4950 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4952 do_cleanups (old_chain);
4956 /* Helper function for break_command_1 and disassemble_command. */
4959 resolve_sal_pc (struct symtab_and_line *sal)
4963 if (sal->pc == 0 && sal->symtab != NULL)
4965 if (!find_line_pc (sal->symtab, sal->line, &pc))
4966 error ("No line %d in file \"%s\".",
4967 sal->line, sal->symtab->filename);
4971 if (sal->section == 0 && sal->symtab != NULL)
4973 struct blockvector *bv;
4978 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4981 b = BLOCKVECTOR_BLOCK (bv, index);
4982 sym = block_function (b);
4985 fixup_symbol_section (sym, sal->symtab->objfile);
4986 sal->section = SYMBOL_BFD_SECTION (sym);
4990 /* It really is worthwhile to have the section, so we'll just
4991 have to look harder. This case can be executed if we have
4992 line numbers but no functions (as can happen in assembly
4995 struct minimal_symbol *msym;
4997 msym = lookup_minimal_symbol_by_pc (sal->pc);
4999 sal->section = SYMBOL_BFD_SECTION (msym);
5006 break_command (char *arg, int from_tty)
5008 break_command_1 (arg, 0, from_tty);
5012 break_at_finish_command (char *arg, int from_tty)
5014 break_at_finish_command_1 (arg, 0, from_tty);
5018 break_at_finish_at_depth_command (char *arg, int from_tty)
5020 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5024 tbreak_command (char *arg, int from_tty)
5026 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5030 tbreak_at_finish_command (char *arg, int from_tty)
5032 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5036 hbreak_command (char *arg, int from_tty)
5038 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5042 thbreak_command (char *arg, int from_tty)
5044 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5048 stop_command (char *arg, int from_tty)
5050 printf_filtered ("Specify the type of breakpoint to set.\n\
5051 Usage: stop in <function | address>\n\
5056 stopin_command (char *arg, int from_tty)
5060 if (arg == (char *) NULL)
5062 else if (*arg != '*')
5067 /* look for a ':'. If this is a line number specification, then
5068 say it is bad, otherwise, it should be an address or
5069 function/method name */
5070 while (*argptr && !hasColon)
5072 hasColon = (*argptr == ':');
5077 badInput = (*argptr != ':'); /* Not a class::method */
5079 badInput = isdigit (*arg); /* a simple line number */
5083 printf_filtered ("Usage: stop in <function | address>\n");
5085 break_command_1 (arg, 0, from_tty);
5089 stopat_command (char *arg, int from_tty)
5093 if (arg == (char *) NULL || *arg == '*') /* no line number */
5100 /* look for a ':'. If there is a '::' then get out, otherwise
5101 it is probably a line number. */
5102 while (*argptr && !hasColon)
5104 hasColon = (*argptr == ':');
5109 badInput = (*argptr == ':'); /* we have class::method */
5111 badInput = !isdigit (*arg); /* not a line number */
5115 printf_filtered ("Usage: stop at <line>\n");
5117 break_command_1 (arg, 0, from_tty);
5121 /* accessflag: hw_write: watch write,
5122 hw_read: watch read,
5123 hw_access: watch access (read or write) */
5125 watch_command_1 (char *arg, int accessflag, int from_tty)
5127 struct breakpoint *b;
5128 struct symtab_and_line sal;
5129 struct expression *exp;
5130 struct block *exp_valid_block;
5131 struct value *val, *mark;
5132 struct frame_info *frame;
5133 struct frame_info *prev_frame = NULL;
5134 char *exp_start = NULL;
5135 char *exp_end = NULL;
5136 char *tok, *end_tok;
5138 char *cond_start = NULL;
5139 char *cond_end = NULL;
5140 struct expression *cond = NULL;
5141 int i, other_type_used, target_resources_ok = 0;
5142 enum bptype bp_type;
5145 INIT_SAL (&sal); /* initialize to zeroes */
5147 /* Parse arguments. */
5148 innermost_block = NULL;
5150 exp = parse_exp_1 (&arg, 0, 0);
5152 exp_valid_block = innermost_block;
5153 mark = value_mark ();
5154 val = evaluate_expression (exp);
5155 release_value (val);
5156 if (VALUE_LAZY (val))
5157 value_fetch_lazy (val);
5160 while (*tok == ' ' || *tok == '\t')
5164 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5167 toklen = end_tok - tok;
5168 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5170 tok = cond_start = end_tok + 1;
5171 cond = parse_exp_1 (&tok, 0, 0);
5175 error ("Junk at end of command.");
5177 if (accessflag == hw_read)
5178 bp_type = bp_read_watchpoint;
5179 else if (accessflag == hw_access)
5180 bp_type = bp_access_watchpoint;
5182 bp_type = bp_hardware_watchpoint;
5184 mem_cnt = can_use_hardware_watchpoint (val);
5185 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5186 error ("Expression cannot be implemented with read/access watchpoint.");
5189 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5190 target_resources_ok =
5191 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5193 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5194 error ("Target does not support this type of hardware watchpoint.");
5196 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5197 error ("Target can only support one kind of HW watchpoint at a time.");
5200 #if defined(HPUXHPPA)
5201 /* On HP-UX if you set a h/w
5202 watchpoint before the "run" command, the inferior dies with a e.g.,
5203 SIGILL once you start it. I initially believed this was due to a
5204 bad interaction between page protection traps and the initial
5205 startup sequence by the dynamic linker.
5207 However, I tried avoiding that by having HP-UX's implementation of
5208 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5209 yet, which forced slow watches before a "run" or "attach", and it
5210 still fails somewhere in the startup code.
5212 Until I figure out what's happening, I'm disallowing watches altogether
5213 before the "run" or "attach" command. We'll tell the user they must
5214 set watches after getting the program started. */
5215 if (!target_has_execution)
5217 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5220 #endif /* HPUXHPPA */
5222 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5223 watchpoint could not be set. */
5224 if (!mem_cnt || target_resources_ok <= 0)
5225 bp_type = bp_watchpoint;
5227 /* Now set up the breakpoint. */
5228 b = set_raw_breakpoint (sal, bp_type);
5229 set_breakpoint_count (breakpoint_count + 1);
5230 b->number = breakpoint_count;
5231 b->disposition = disp_donttouch;
5233 b->exp_valid_block = exp_valid_block;
5234 b->exp_string = savestring (exp_start, exp_end - exp_start);
5238 b->cond_string = savestring (cond_start, cond_end - cond_start);
5242 frame = block_innermost_frame (exp_valid_block);
5245 prev_frame = get_prev_frame (frame);
5246 b->watchpoint_frame = frame->frame;
5249 b->watchpoint_frame = (CORE_ADDR) 0;
5251 /* If the expression is "local", then set up a "watchpoint scope"
5252 breakpoint at the point where we've left the scope of the watchpoint
5254 if (innermost_block)
5258 struct breakpoint *scope_breakpoint;
5259 struct symtab_and_line scope_sal;
5261 INIT_SAL (&scope_sal); /* initialize to zeroes */
5262 scope_sal.pc = get_frame_pc (prev_frame);
5263 scope_sal.section = find_pc_overlay (scope_sal.pc);
5265 scope_breakpoint = set_raw_breakpoint (scope_sal,
5266 bp_watchpoint_scope);
5267 set_breakpoint_count (breakpoint_count + 1);
5268 scope_breakpoint->number = breakpoint_count;
5270 scope_breakpoint->enable_state = bp_enabled;
5272 /* Automatically delete the breakpoint when it hits. */
5273 scope_breakpoint->disposition = disp_del;
5275 /* Only break in the proper frame (help with recursion). */
5276 scope_breakpoint->frame = prev_frame->frame;
5278 /* Set the address at which we will stop. */
5279 scope_breakpoint->address = get_frame_pc (prev_frame);
5281 /* The scope breakpoint is related to the watchpoint. We
5282 will need to act on them together. */
5283 b->related_breakpoint = scope_breakpoint;
5286 value_free_to_mark (mark);
5290 /* Return count of locations need to be watched and can be handled
5291 in hardware. If the watchpoint can not be handled
5292 in hardware return zero. */
5294 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5295 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5296 ((BYTE_SIZE) <= (REGISTER_SIZE))
5299 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5300 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5301 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5305 can_use_hardware_watchpoint (struct value *v)
5307 int found_memory_cnt = 0;
5308 struct value *head = v;
5310 /* Did the user specifically forbid us to use hardware watchpoints? */
5311 if (!can_use_hw_watchpoints)
5314 /* Make sure that the value of the expression depends only upon
5315 memory contents, and values computed from them within GDB. If we
5316 find any register references or function calls, we can't use a
5317 hardware watchpoint.
5319 The idea here is that evaluating an expression generates a series
5320 of values, one holding the value of every subexpression. (The
5321 expression a*b+c has five subexpressions: a, b, a*b, c, and
5322 a*b+c.) GDB's values hold almost enough information to establish
5323 the criteria given above --- they identify memory lvalues,
5324 register lvalues, computed values, etcetera. So we can evaluate
5325 the expression, and then scan the chain of values that leaves
5326 behind to decide whether we can detect any possible change to the
5327 expression's final value using only hardware watchpoints.
5329 However, I don't think that the values returned by inferior
5330 function calls are special in any way. So this function may not
5331 notice that an expression involving an inferior function call
5332 can't be watched with hardware watchpoints. FIXME. */
5333 for (; v; v = v->next)
5335 if (VALUE_LVAL (v) == lval_memory)
5338 /* A lazy memory lvalue is one that GDB never needed to fetch;
5339 we either just used its address (e.g., `a' in `a.b') or
5340 we never needed it at all (e.g., `a' in `a,b'). */
5344 /* Ahh, memory we actually used! Check if we can cover
5345 it with hardware watchpoints. */
5346 struct type *vtype = check_typedef (VALUE_TYPE (v));
5348 /* We only watch structs and arrays if user asked for it
5349 explicitly, never if they just happen to appear in a
5350 middle of some value chain. */
5352 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5353 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5355 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5356 int len = TYPE_LENGTH (VALUE_TYPE (v));
5358 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5365 else if (v->lval != not_lval && v->modifiable == 0)
5366 return 0; /* ??? What does this represent? */
5367 else if (v->lval == lval_register)
5368 return 0; /* cannot watch a register with a HW watchpoint */
5371 /* The expression itself looks suitable for using a hardware
5372 watchpoint, but give the target machine a chance to reject it. */
5373 return found_memory_cnt;
5377 watch_command_wrapper (char *arg, int from_tty)
5379 watch_command (arg, from_tty);
5383 watch_command (char *arg, int from_tty)
5385 watch_command_1 (arg, hw_write, from_tty);
5389 rwatch_command_wrapper (char *arg, int from_tty)
5391 rwatch_command (arg, from_tty);
5395 rwatch_command (char *arg, int from_tty)
5397 watch_command_1 (arg, hw_read, from_tty);
5401 awatch_command_wrapper (char *arg, int from_tty)
5403 awatch_command (arg, from_tty);
5407 awatch_command (char *arg, int from_tty)
5409 watch_command_1 (arg, hw_access, from_tty);
5413 /* Helper routines for the until_command routine in infcmd.c. Here
5414 because it uses the mechanisms of breakpoints. */
5416 /* This function is called by fetch_inferior_event via the
5417 cmd_continuation pointer, to complete the until command. It takes
5418 care of cleaning up the temporary breakpoints set up by the until
5421 until_break_command_continuation (struct continuation_arg *arg)
5423 struct cleanup *cleanups;
5425 cleanups = (struct cleanup *) arg->data.pointer;
5426 do_exec_cleanups (cleanups);
5431 until_break_command (char *arg, int from_tty)
5433 struct symtabs_and_lines sals;
5434 struct symtab_and_line sal;
5435 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5436 struct breakpoint *breakpoint;
5437 struct cleanup *old_chain;
5438 struct continuation_arg *arg1;
5441 clear_proceed_status ();
5443 /* Set a breakpoint where the user wants it and at return from
5446 if (default_breakpoint_valid)
5447 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5448 default_breakpoint_line, (char ***) NULL);
5450 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5451 0, (char ***) NULL);
5453 if (sals.nelts != 1)
5454 error ("Couldn't get information on specified line.");
5457 xfree (sals.sals); /* malloc'd, so freed */
5460 error ("Junk at end of arguments.");
5462 resolve_sal_pc (&sal);
5464 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5466 if (!event_loop_p || !target_can_async_p ())
5467 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5469 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5471 /* If we are running asynchronously, and the target supports async
5472 execution, we are not waiting for the target to stop, in the call
5473 tp proceed, below. This means that we cannot delete the
5474 brekpoints until the target has actually stopped. The only place
5475 where we get a chance to do that is in fetch_inferior_event, so
5476 we must set things up for that. */
5478 if (event_loop_p && target_can_async_p ())
5480 /* In this case the arg for the continuation is just the point
5481 in the exec_cleanups chain from where to start doing
5482 cleanups, because all the continuation does is the cleanups in
5483 the exec_cleanup_chain. */
5485 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5487 arg1->data.pointer = old_chain;
5489 add_continuation (until_break_command_continuation, arg1);
5492 /* Keep within the current frame */
5496 sal = find_pc_line (prev_frame->pc, 0);
5497 sal.pc = prev_frame->pc;
5498 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5499 if (!event_loop_p || !target_can_async_p ())
5500 make_cleanup_delete_breakpoint (breakpoint);
5502 make_exec_cleanup_delete_breakpoint (breakpoint);
5505 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5506 /* Do the cleanups now, anly if we are not running asynchronously,
5507 of if we are, but the target is still synchronous. */
5508 if (!event_loop_p || !target_can_async_p ())
5509 do_cleanups (old_chain);
5513 /* These aren't used; I don't konw what they were for. */
5514 /* Set a breakpoint at the catch clause for NAME. */
5516 catch_breakpoint (char *name)
5521 disable_catch_breakpoint (void)
5526 delete_catch_breakpoint (void)
5531 enable_catch_breakpoint (void)
5538 struct sal_chain *next;
5539 struct symtab_and_line sal;
5543 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5544 had been commented out in the v.4.16 sources, and stays
5545 disabled there now because "catch NAME" syntax isn't allowed.
5547 /* This isn't used; I don't know what it was for. */
5548 /* For each catch clause identified in ARGS, run FUNCTION
5549 with that clause as an argument. */
5550 static struct symtabs_and_lines
5551 map_catch_names (char *args, int (*function) ())
5553 register char *p = args;
5555 struct symtabs_and_lines sals;
5557 struct sal_chain *sal_chain = 0;
5561 error_no_arg ("one or more catch names");
5569 /* Don't swallow conditional part. */
5570 if (p1[0] == 'i' && p1[1] == 'f'
5571 && (p1[2] == ' ' || p1[2] == '\t'))
5577 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5581 if (*p1 && *p1 != ' ' && *p1 != '\t')
5582 error ("Arguments must be catch names.");
5588 struct sal_chain *next = (struct sal_chain *)
5589 alloca (sizeof (struct sal_chain));
5590 next->next = sal_chain;
5591 next->sal = get_catch_sal (p);
5596 printf_unfiltered ("No catch clause for exception %s.\n", p);
5601 while (*p == ' ' || *p == '\t')
5607 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5609 static struct symtabs_and_lines
5610 get_catch_sals (int this_level_only)
5612 register struct blockvector *bl;
5613 register struct block *block;
5614 int index, have_default = 0;
5616 struct symtabs_and_lines sals;
5617 struct sal_chain *sal_chain = 0;
5618 char *blocks_searched;
5620 /* Not sure whether an error message is always the correct response,
5621 but it's better than a core dump. */
5622 if (selected_frame == NULL)
5623 error ("No selected frame.");
5624 block = get_frame_block (selected_frame);
5625 pc = selected_frame->pc;
5631 error ("No symbol table info available.\n");
5633 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5634 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5635 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5639 CORE_ADDR end = BLOCK_END (block) - 4;
5642 if (bl != blockvector_for_pc (end, &index))
5643 error ("blockvector blotch");
5644 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5645 error ("blockvector botch");
5646 last_index = BLOCKVECTOR_NBLOCKS (bl);
5649 /* Don't print out blocks that have gone by. */
5650 while (index < last_index
5651 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5654 while (index < last_index
5655 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5657 if (blocks_searched[index] == 0)
5659 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5661 register struct symbol *sym;
5663 ALL_BLOCK_SYMBOLS (b, i, sym)
5665 if (STREQ (SYMBOL_NAME (sym), "default"))
5671 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5673 struct sal_chain *next = (struct sal_chain *)
5674 alloca (sizeof (struct sal_chain));
5675 next->next = sal_chain;
5676 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5681 blocks_searched[index] = 1;
5687 if (sal_chain && this_level_only)
5690 /* After handling the function's top-level block, stop.
5691 Don't continue to its superblock, the block of
5692 per-file symbols. */
5693 if (BLOCK_FUNCTION (block))
5695 block = BLOCK_SUPERBLOCK (block);
5700 struct sal_chain *tmp_chain;
5702 /* Count the number of entries. */
5703 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5704 tmp_chain = tmp_chain->next)
5708 sals.sals = (struct symtab_and_line *)
5709 xmalloc (index * sizeof (struct symtab_and_line));
5710 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5711 sals.sals[index] = sal_chain->sal;
5718 ep_skip_leading_whitespace (char **s)
5720 if ((s == NULL) || (*s == NULL))
5722 while (isspace (**s))
5726 /* This function examines a string, and attempts to find a token
5727 that might be an event name in the leading characters. If a
5728 possible match is found, a pointer to the last character of
5729 the token is returned. Else, NULL is returned. */
5732 ep_find_event_name_end (char *arg)
5735 char *event_name_end = NULL;
5737 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5741 /* We break out of the loop when we find a token delimiter.
5742 Basically, we're looking for alphanumerics and underscores;
5743 anything else delimites the token. */
5746 if (!isalnum (*s) && (*s != '_'))
5752 return event_name_end;
5756 /* This function attempts to parse an optional "if <cond>" clause
5757 from the arg string. If one is not found, it returns NULL.
5759 Else, it returns a pointer to the condition string. (It does not
5760 attempt to evaluate the string against a particular block.) And,
5761 it updates arg to point to the first character following the parsed
5762 if clause in the arg string. */
5765 ep_parse_optional_if_clause (char **arg)
5769 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5772 /* Skip the "if" keyword. */
5775 /* Skip any extra leading whitespace, and record the start of the
5776 condition string. */
5777 ep_skip_leading_whitespace (arg);
5780 /* Assume that the condition occupies the remainder of the arg string. */
5781 (*arg) += strlen (cond_string);
5786 /* This function attempts to parse an optional filename from the arg
5787 string. If one is not found, it returns NULL.
5789 Else, it returns a pointer to the parsed filename. (This function
5790 makes no attempt to verify that a file of that name exists, or is
5791 accessible.) And, it updates arg to point to the first character
5792 following the parsed filename in the arg string.
5794 Note that clients needing to preserve the returned filename for
5795 future access should copy it to their own buffers. */
5797 ep_parse_optional_filename (char **arg)
5799 static char filename[1024];
5804 if ((*arg_p == '\0') || isspace (*arg_p))
5822 /* Commands to deal with catching events, such as signals, exceptions,
5823 process start/exit, etc. */
5827 catch_fork, catch_vfork
5831 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5832 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5833 char *arg, int tempflag, int from_tty);
5836 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5839 char *cond_string = NULL;
5841 ep_skip_leading_whitespace (&arg);
5843 /* The allowed syntax is:
5845 catch [v]fork if <cond>
5847 First, check if there's an if clause. */
5848 cond_string = ep_parse_optional_if_clause (&arg);
5850 if ((*arg != '\0') && !isspace (*arg))
5851 error ("Junk at end of arguments.");
5853 /* If this target supports it, create a fork or vfork catchpoint
5854 and enable reporting of such events. */
5858 create_fork_event_catchpoint (tempflag, cond_string);
5861 create_vfork_event_catchpoint (tempflag, cond_string);
5864 error ("unsupported or unknown fork kind; cannot catch it");
5870 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5872 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
5874 char *cond_string = NULL;
5876 ep_skip_leading_whitespace (&arg);
5878 /* The allowed syntax is:
5880 catch exec if <cond>
5882 First, check if there's an if clause. */
5883 cond_string = ep_parse_optional_if_clause (&arg);
5885 if ((*arg != '\0') && !isspace (*arg))
5886 error ("Junk at end of arguments.");
5888 /* If this target supports it, create an exec catchpoint
5889 and enable reporting of such events. */
5890 create_exec_event_catchpoint (tempflag, cond_string);
5894 #if defined(SOLIB_ADD)
5896 catch_load_command_1 (char *arg, int tempflag, int from_tty)
5898 char *dll_pathname = NULL;
5899 char *cond_string = NULL;
5901 ep_skip_leading_whitespace (&arg);
5903 /* The allowed syntax is:
5905 catch load if <cond>
5906 catch load <filename>
5907 catch load <filename> if <cond>
5909 The user is not allowed to specify the <filename> after an
5912 We'll ignore the pathological case of a file named "if".
5914 First, check if there's an if clause. If so, then there
5915 cannot be a filename. */
5916 cond_string = ep_parse_optional_if_clause (&arg);
5918 /* If there was an if clause, then there cannot be a filename.
5919 Else, there might be a filename and an if clause. */
5920 if (cond_string == NULL)
5922 dll_pathname = ep_parse_optional_filename (&arg);
5923 ep_skip_leading_whitespace (&arg);
5924 cond_string = ep_parse_optional_if_clause (&arg);
5927 if ((*arg != '\0') && !isspace (*arg))
5928 error ("Junk at end of arguments.");
5930 /* Create a load breakpoint that only triggers when a load of
5931 the specified dll (or any dll, if no pathname was specified)
5933 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5934 dll_pathname, cond_string);
5938 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
5940 char *dll_pathname = NULL;
5941 char *cond_string = NULL;
5943 ep_skip_leading_whitespace (&arg);
5945 /* The allowed syntax is:
5947 catch unload if <cond>
5948 catch unload <filename>
5949 catch unload <filename> if <cond>
5951 The user is not allowed to specify the <filename> after an
5954 We'll ignore the pathological case of a file named "if".
5956 First, check if there's an if clause. If so, then there
5957 cannot be a filename. */
5958 cond_string = ep_parse_optional_if_clause (&arg);
5960 /* If there was an if clause, then there cannot be a filename.
5961 Else, there might be a filename and an if clause. */
5962 if (cond_string == NULL)
5964 dll_pathname = ep_parse_optional_filename (&arg);
5965 ep_skip_leading_whitespace (&arg);
5966 cond_string = ep_parse_optional_if_clause (&arg);
5969 if ((*arg != '\0') && !isspace (*arg))
5970 error ("Junk at end of arguments.");
5972 /* Create an unload breakpoint that only triggers when an unload of
5973 the specified dll (or any dll, if no pathname was specified)
5975 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5976 dll_pathname, cond_string);
5978 #endif /* SOLIB_ADD */
5980 /* Commands to deal with catching exceptions. */
5982 /* Set a breakpoint at the specified callback routine for an
5983 exception event callback */
5986 create_exception_catchpoint (int tempflag, char *cond_string,
5987 enum exception_event_kind ex_event,
5988 struct symtab_and_line *sal)
5990 struct breakpoint *b;
5991 int thread = -1; /* All threads. */
5994 if (!sal) /* no exception support? */
5999 case EX_EVENT_THROW:
6000 bptype = bp_catch_throw;
6002 case EX_EVENT_CATCH:
6003 bptype = bp_catch_catch;
6005 default: /* error condition */
6006 error ("Internal error -- invalid catchpoint kind");
6009 b = set_raw_breakpoint (*sal, bptype);
6010 set_breakpoint_count (breakpoint_count + 1);
6011 b->number = breakpoint_count;
6013 b->cond_string = (cond_string == NULL) ?
6014 NULL : savestring (cond_string, strlen (cond_string));
6016 b->addr_string = NULL;
6017 b->enable_state = bp_enabled;
6018 b->disposition = tempflag ? disp_del : disp_donttouch;
6022 /* Deal with "catch catch" and "catch throw" commands */
6025 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6026 int tempflag, int from_tty)
6028 char *cond_string = NULL;
6029 struct symtab_and_line *sal = NULL;
6031 ep_skip_leading_whitespace (&arg);
6033 cond_string = ep_parse_optional_if_clause (&arg);
6035 if ((*arg != '\0') && !isspace (*arg))
6036 error ("Junk at end of arguments.");
6038 if ((ex_event != EX_EVENT_THROW) &&
6039 (ex_event != EX_EVENT_CATCH))
6040 error ("Unsupported or unknown exception event; cannot catch it");
6042 /* See if we can find a callback routine */
6043 sal = target_enable_exception_callback (ex_event, 1);
6047 /* We have callbacks from the runtime system for exceptions.
6048 Set a breakpoint on the sal found, if no errors */
6049 if (sal != (struct symtab_and_line *) -1)
6050 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6052 return; /* something went wrong with setting up callbacks */
6056 /* No callbacks from runtime system for exceptions.
6057 Try GNU C++ exception breakpoints using labels in debug info. */
6058 if (ex_event == EX_EVENT_CATCH)
6060 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6062 else if (ex_event == EX_EVENT_THROW)
6064 /* Set a breakpoint on __raise_exception () */
6066 warning ("Unsupported with this platform/compiler combination.");
6067 warning ("Perhaps you can achieve the effect you want by setting");
6068 warning ("a breakpoint on __raise_exception().");
6073 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6074 inside a catch_errors */
6077 cover_target_enable_exception_callback (PTR arg)
6079 args_for_catchpoint_enable *args = arg;
6080 struct symtab_and_line *sal;
6081 sal = target_enable_exception_callback (args->kind, args->enable_p);
6084 else if (sal == (struct symtab_and_line *) -1)
6087 return 1; /*is valid */
6092 /* This is the original v.4.16 and earlier version of the
6093 catch_command_1() function. Now that other flavours of "catch"
6094 have been introduced, and since exception handling can be handled
6095 in other ways (through target ops) also, this is used only for the
6096 GNU C++ exception handling system.
6097 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6098 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6099 there was no code in GDB 4.16 for "catch throw".
6101 Called from catch_exception_command_1 () */
6105 handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
6107 /* First, translate ARG into something we can deal with in terms
6110 struct symtabs_and_lines sals;
6111 struct symtab_and_line sal;
6112 register struct expression *cond = 0;
6113 register struct breakpoint *b;
6117 INIT_SAL (&sal); /* initialize to zeroes */
6119 /* If no arg given, or if first arg is 'if ', all active catch clauses
6120 are breakpointed. */
6122 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6123 && (arg[2] == ' ' || arg[2] == '\t')))
6125 /* Grab all active catch clauses. */
6126 sals = get_catch_sals (0);
6130 /* Grab selected catch clauses. */
6131 error ("catch NAME not implemented");
6134 /* Not sure why this code has been disabled. I'm leaving
6135 it disabled. We can never come here now anyway
6136 since we don't allow the "catch NAME" syntax.
6139 /* This isn't used; I don't know what it was for. */
6140 sals = map_catch_names (arg, catch_breakpoint);
6148 for (i = 0; i < sals.nelts; i++)
6150 resolve_sal_pc (&sals.sals[i]);
6154 if (arg[0] == 'i' && arg[1] == 'f'
6155 && (arg[2] == ' ' || arg[2] == '\t'))
6156 cond = parse_exp_1 ((arg += 2, &arg),
6157 block_for_pc (sals.sals[i].pc), 0);
6159 error ("Junk at end of arguments.");
6164 for (i = 0; i < sals.nelts; i++)
6169 describe_other_breakpoints (sal.pc, sal.section);
6171 /* Important -- this is an ordinary breakpoint. For platforms
6172 with callback support for exceptions,
6173 create_exception_catchpoint() will create special bp types
6174 (bp_catch_catch and bp_catch_throw), and there is code in
6175 insert_breakpoints() and elsewhere that depends on that. */
6176 b = set_raw_breakpoint (sal, bp_breakpoint);
6177 set_breakpoint_count (breakpoint_count + 1);
6178 b->number = breakpoint_count;
6181 b->enable_state = bp_enabled;
6182 b->disposition = tempflag ? disp_del : disp_donttouch;
6189 warning ("Multiple breakpoints were set.");
6190 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6196 catch_command_1 (char *arg, int tempflag, int from_tty)
6199 /* The first argument may be an event name, such as "start" or "load".
6200 If so, then handle it as such. If it doesn't match an event name,
6201 then attempt to interpret it as an exception name. (This latter is
6202 the v4.16-and-earlier GDB meaning of the "catch" command.)
6204 First, try to find the bounds of what might be an event name. */
6205 char *arg1_start = arg;
6209 if (arg1_start == NULL)
6211 /* Old behaviour was to use pre-v-4.16 syntax */
6212 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6214 /* Now, this is not allowed */
6215 error ("Catch requires an event name.");
6218 arg1_end = ep_find_event_name_end (arg1_start);
6219 if (arg1_end == NULL)
6220 error ("catch requires an event");
6221 arg1_length = arg1_end + 1 - arg1_start;
6223 /* Try to match what we found against known event names. */
6224 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6226 error ("Catch of signal not yet implemented");
6228 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6230 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6231 tempflag, from_tty);
6233 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6235 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6236 tempflag, from_tty);
6238 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6240 error ("Catch of thread_start not yet implemented");
6242 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6244 error ("Catch of thread_exit not yet implemented");
6246 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6248 error ("Catch of thread_join not yet implemented");
6250 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6252 error ("Catch of start not yet implemented");
6254 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6256 error ("Catch of exit not yet implemented");
6258 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6260 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6261 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6263 error ("Catch of fork not yet implemented");
6266 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6268 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6269 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6271 error ("Catch of vfork not yet implemented");
6274 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6276 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6277 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6279 error ("Catch of exec not yet implemented");
6282 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6284 #if defined(SOLIB_ADD)
6285 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6287 error ("Catch of load not implemented");
6290 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6292 #if defined(SOLIB_ADD)
6293 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6295 error ("Catch of load not implemented");
6298 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6300 error ("Catch of stop not yet implemented");
6303 /* This doesn't appear to be an event name */
6307 /* Pre-v.4.16 behaviour was to treat the argument
6308 as the name of an exception */
6309 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6310 /* Now this is not allowed */
6311 error ("Unknown event kind specified for catch");
6316 /* Used by the gui, could be made a worker for other things. */
6319 set_breakpoint_sal (struct symtab_and_line sal)
6321 struct breakpoint *b;
6322 b = set_raw_breakpoint (sal, bp_breakpoint);
6323 set_breakpoint_count (breakpoint_count + 1);
6324 b->number = breakpoint_count;
6331 /* These aren't used; I don't know what they were for. */
6332 /* Disable breakpoints on all catch clauses described in ARGS. */
6334 disable_catch (char *args)
6336 /* Map the disable command to catch clauses described in ARGS. */
6339 /* Enable breakpoints on all catch clauses described in ARGS. */
6341 enable_catch (char *args)
6343 /* Map the disable command to catch clauses described in ARGS. */
6346 /* Delete breakpoints on all catch clauses in the active scope. */
6348 delete_catch (char *args)
6350 /* Map the delete command to catch clauses described in ARGS. */
6355 catch_command (char *arg, int from_tty)
6357 catch_command_1 (arg, 0, from_tty);
6362 tcatch_command (char *arg, int from_tty)
6364 catch_command_1 (arg, 1, from_tty);
6369 clear_command (char *arg, int from_tty)
6371 register struct breakpoint *b, *b1;
6373 struct symtabs_and_lines sals;
6374 struct symtab_and_line sal;
6375 register struct breakpoint *found;
6380 sals = decode_line_spec (arg, 1);
6385 sals.sals = (struct symtab_and_line *)
6386 xmalloc (sizeof (struct symtab_and_line));
6387 INIT_SAL (&sal); /* initialize to zeroes */
6388 sal.line = default_breakpoint_line;
6389 sal.symtab = default_breakpoint_symtab;
6390 sal.pc = default_breakpoint_address;
6391 if (sal.symtab == 0)
6392 error ("No source file specified.");
6400 /* For each line spec given, delete bps which correspond
6401 to it. We do this in two loops: the first loop looks at
6402 the initial bp(s) in the chain which should be deleted,
6403 the second goes down the rest of the chain looking ahead
6404 one so it can take those bps off the chain without messing
6408 for (i = 0; i < sals.nelts; i++)
6410 /* If exact pc given, clear bpts at that pc.
6411 If line given (pc == 0), clear all bpts on specified line.
6412 If defaulting, clear all bpts on default line
6415 defaulting sal.pc != 0 tests to do
6420 1 0 <can't happen> */
6423 found = (struct breakpoint *) 0;
6426 while (breakpoint_chain
6427 /* Why don't we check here that this is not
6428 a watchpoint, etc., as we do below?
6429 I can't make it fail, but don't know
6430 what's stopping the failure: a watchpoint
6431 of the same address as "sal.pc" should
6432 wind up being deleted. */
6434 && (((sal.pc && (breakpoint_chain->address == sal.pc))
6435 && (!overlay_debugging
6436 || breakpoint_chain->section == sal.section))
6437 || ((default_match || (0 == sal.pc))
6438 && breakpoint_chain->source_file != NULL
6439 && sal.symtab != NULL
6440 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6441 && breakpoint_chain->line_number == sal.line)))
6444 b1 = breakpoint_chain;
6445 breakpoint_chain = b1->next;
6452 && b->next->type != bp_none
6453 && b->next->type != bp_watchpoint
6454 && b->next->type != bp_hardware_watchpoint
6455 && b->next->type != bp_read_watchpoint
6456 && b->next->type != bp_access_watchpoint
6457 && (((sal.pc && (b->next->address == sal.pc))
6458 && (!overlay_debugging || b->next->section == sal.section))
6459 || ((default_match || (0 == sal.pc))
6460 && b->next->source_file != NULL
6461 && sal.symtab != NULL
6462 && STREQ (b->next->source_file, sal.symtab->filename)
6463 && b->next->line_number == sal.line)))
6476 error ("No breakpoint at %s.", arg);
6478 error ("No breakpoint at this line.");
6482 from_tty = 1; /* Always report if deleted more than one */
6484 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6485 breakpoints_changed ();
6489 printf_unfiltered ("%d ", found->number);
6491 delete_breakpoint (found);
6495 putchar_unfiltered ('\n');
6500 /* Delete breakpoint in BS if they are `delete' breakpoints and
6501 all breakpoints that are marked for deletion, whether hit or not.
6502 This is called after any breakpoint is hit, or after errors. */
6505 breakpoint_auto_delete (bpstat bs)
6507 struct breakpoint *b, *temp;
6509 for (; bs; bs = bs->next)
6510 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6512 delete_breakpoint (bs->breakpoint_at);
6514 ALL_BREAKPOINTS_SAFE (b, temp)
6516 if (b->disposition == disp_del_at_next_stop)
6517 delete_breakpoint (b);
6521 /* Delete a breakpoint and clean up all traces of it in the data
6525 delete_breakpoint (struct breakpoint *bpt)
6527 register struct breakpoint *b;
6531 error ("Internal error (attempted to delete a NULL breakpoint)");
6534 /* Has this bp already been deleted? This can happen because multiple
6535 lists can hold pointers to bp's. bpstat lists are especial culprits.
6537 One example of this happening is a watchpoint's scope bp. When the
6538 scope bp triggers, we notice that the watchpoint is out of scope, and
6539 delete it. We also delete its scope bp. But the scope bp is marked
6540 "auto-deleting", and is already on a bpstat. That bpstat is then
6541 checked for auto-deleting bp's, which are deleted.
6543 A real solution to this problem might involve reference counts in bp's,
6544 and/or giving them pointers back to their referencing bpstat's, and
6545 teaching delete_breakpoint to only free a bp's storage when no more
6546 references were extent. A cheaper bandaid was chosen. */
6547 if (bpt->type == bp_none)
6550 if (delete_breakpoint_hook)
6551 delete_breakpoint_hook (bpt);
6552 breakpoint_delete_event (bpt->number);
6555 remove_breakpoint (bpt, mark_inserted);
6557 if (breakpoint_chain == bpt)
6558 breakpoint_chain = bpt->next;
6560 /* If we have callback-style exception catchpoints, don't go through
6561 the adjustments to the C++ runtime library etc. if the inferior
6562 isn't actually running. target_enable_exception_callback for a
6563 null target ops vector gives an undesirable error message, so we
6564 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6565 exceptions are supported in this way, it's OK for now. FIXME */
6566 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6568 static char message1[] = "Error in deleting catchpoint %d:\n";
6569 static char message[sizeof (message1) + 30];
6570 args_for_catchpoint_enable args;
6572 /* Format possible error msg */
6573 sprintf (message, message1, bpt->number);
6574 args.kind = bpt->type == bp_catch_catch ?
6575 EX_EVENT_CATCH : EX_EVENT_THROW;
6577 catch_errors (cover_target_enable_exception_callback, &args,
6578 message, RETURN_MASK_ALL);
6585 b->next = bpt->next;
6589 check_duplicates (bpt);
6590 /* If this breakpoint was inserted, and there is another breakpoint
6591 at the same address, we need to insert the other breakpoint. */
6593 && bpt->type != bp_hardware_watchpoint
6594 && bpt->type != bp_read_watchpoint
6595 && bpt->type != bp_access_watchpoint
6596 && bpt->type != bp_catch_fork
6597 && bpt->type != bp_catch_vfork
6598 && bpt->type != bp_catch_exec)
6601 if (b->address == bpt->address
6602 && b->section == bpt->section
6604 && b->enable_state != bp_disabled
6605 && b->enable_state != bp_shlib_disabled
6606 && b->enable_state != bp_call_disabled)
6610 /* We should never reach this point if there is a permanent
6611 breakpoint at the same address as the one being deleted.
6612 If there is a permanent breakpoint somewhere, it should
6613 always be the only one inserted. */
6614 if (b->enable_state == bp_permanent)
6615 internal_error (__FILE__, __LINE__,
6616 "another breakpoint was inserted on top of "
6617 "a permanent breakpoint");
6619 if (b->type == bp_hardware_breakpoint)
6620 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6622 val = target_insert_breakpoint (b->address, b->shadow_contents);
6626 target_terminal_ours_for_output ();
6627 warning ("Cannot insert breakpoint %d:", b->number);
6628 memory_error (val, b->address); /* which bombs us out */
6635 free_command_lines (&bpt->commands);
6638 if (bpt->cond_string != NULL)
6639 xfree (bpt->cond_string);
6640 if (bpt->addr_string != NULL)
6641 xfree (bpt->addr_string);
6642 if (bpt->exp != NULL)
6644 if (bpt->exp_string != NULL)
6645 xfree (bpt->exp_string);
6646 if (bpt->val != NULL)
6647 value_free (bpt->val);
6648 if (bpt->source_file != NULL)
6649 xfree (bpt->source_file);
6650 if (bpt->dll_pathname != NULL)
6651 xfree (bpt->dll_pathname);
6652 if (bpt->triggered_dll_pathname != NULL)
6653 xfree (bpt->triggered_dll_pathname);
6654 if (bpt->exec_pathname != NULL)
6655 xfree (bpt->exec_pathname);
6657 /* Be sure no bpstat's are pointing at it after it's been freed. */
6658 /* FIXME, how can we find all bpstat's?
6659 We just check stop_bpstat for now. */
6660 for (bs = stop_bpstat; bs; bs = bs->next)
6661 if (bs->breakpoint_at == bpt)
6663 bs->breakpoint_at = NULL;
6665 /* we'd call bpstat_clear_actions, but that free's stuff and due
6666 to the multiple pointers pointing to one item with no
6667 reference counts found anywhere through out the bpstat's (how
6668 do you spell fragile?), we don't want to free things twice --
6669 better a memory leak than a corrupt malloc pool! */
6670 bs->commands = NULL;
6673 /* On the chance that someone will soon try again to delete this same
6674 bp, we mark it as deleted before freeing its storage. */
6675 bpt->type = bp_none;
6681 do_delete_breakpoint_cleanup (void *b)
6683 delete_breakpoint (b);
6687 make_cleanup_delete_breakpoint (struct breakpoint *b)
6689 return make_cleanup (do_delete_breakpoint_cleanup, b);
6693 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6695 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6699 delete_command (char *arg, int from_tty)
6701 struct breakpoint *b, *temp;
6705 int breaks_to_delete = 0;
6707 /* Delete all breakpoints if no argument.
6708 Do not delete internal or call-dummy breakpoints, these
6709 have to be deleted with an explicit breakpoint number argument. */
6712 if (b->type != bp_call_dummy &&
6713 b->type != bp_shlib_event &&
6714 b->type != bp_thread_event &&
6715 b->type != bp_overlay_event &&
6717 breaks_to_delete = 1;
6720 /* Ask user only if there are some breakpoints to delete. */
6722 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6724 ALL_BREAKPOINTS_SAFE (b, temp)
6726 if (b->type != bp_call_dummy &&
6727 b->type != bp_shlib_event &&
6728 b->type != bp_thread_event &&
6729 b->type != bp_overlay_event &&
6731 delete_breakpoint (b);
6736 map_breakpoint_numbers (arg, delete_breakpoint);
6739 /* Reset a breakpoint given it's struct breakpoint * BINT.
6740 The value we return ends up being the return value from catch_errors.
6741 Unused in this case. */
6744 breakpoint_re_set_one (PTR bint)
6746 /* get past catch_errs */
6747 struct breakpoint *b = (struct breakpoint *) bint;
6750 struct symtabs_and_lines sals;
6752 enum enable_state save_enable;
6757 warning ("attempted to reset apparently deleted breakpoint #%d?",
6761 case bp_hardware_breakpoint:
6763 case bp_catch_unload:
6764 if (b->addr_string == NULL)
6766 /* Anything without a string can't be re-set. */
6767 delete_breakpoint (b);
6770 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6772 ``And a hack it is, although Apple's Darwin version of GDB
6773 contains an almost identical hack to implement a "future
6774 break" command. It seems to work in many real world cases,
6775 but it is easy to come up with a test case where the patch
6776 doesn't help at all.''
6778 ``It seems that the way GDB implements breakpoints - in -
6779 shared - libraries was designed for a.out shared library
6780 systems (SunOS 4) where shared libraries were loaded at a
6781 fixed address in memory. Since ELF shared libraries can (and
6782 will) be loaded at any address in memory, things break.
6783 Fixing this is not trivial. Therefore, I'm not sure whether
6784 we should add this hack to the branch only. I cannot
6785 guarantee that things will be fixed on the trunk in the near
6788 In case we have a problem, disable this breakpoint. We'll
6789 restore its status if we succeed. Don't disable a
6790 shlib_disabled breakpoint though. There's a fair chance we
6791 can't re-set it if the shared library it's in hasn't been
6793 save_enable = b->enable_state;
6794 if (b->enable_state != bp_shlib_disabled)
6795 b->enable_state = bp_disabled;
6797 set_language (b->language);
6798 input_radix = b->input_radix;
6800 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6801 for (i = 0; i < sals.nelts; i++)
6803 resolve_sal_pc (&sals.sals[i]);
6805 /* Reparse conditions, they might contain references to the
6807 if (b->cond_string != NULL)
6812 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6815 /* We need to re-set the breakpoint if the address changes... */
6816 if (b->address != sals.sals[i].pc
6817 /* ...or new and old breakpoints both have source files, and
6818 the source file name or the line number changes... */
6819 || (b->source_file != NULL
6820 && sals.sals[i].symtab != NULL
6821 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6822 || b->line_number != sals.sals[i].line)
6824 /* ...or we switch between having a source file and not having
6826 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6829 if (b->source_file != NULL)
6830 xfree (b->source_file);
6831 if (sals.sals[i].symtab == NULL)
6832 b->source_file = NULL;
6835 savestring (sals.sals[i].symtab->filename,
6836 strlen (sals.sals[i].symtab->filename));
6837 b->line_number = sals.sals[i].line;
6838 b->address = sals.sals[i].pc;
6840 /* Used to check for duplicates here, but that can
6841 cause trouble, as it doesn't check for disabled
6846 /* Might be better to do this just once per breakpoint_re_set,
6847 rather than once for every breakpoint. */
6848 breakpoints_changed ();
6850 b->section = sals.sals[i].section;
6851 b->enable_state = save_enable; /* Restore it, this worked. */
6854 /* Now that this is re-enabled, check_duplicates
6856 check_duplicates (b);
6863 case bp_hardware_watchpoint:
6864 case bp_read_watchpoint:
6865 case bp_access_watchpoint:
6866 innermost_block = NULL;
6867 /* The issue arises of what context to evaluate this in. The
6868 same one as when it was set, but what does that mean when
6869 symbols have been re-read? We could save the filename and
6870 functionname, but if the context is more local than that, the
6871 best we could do would be something like how many levels deep
6872 and which index at that particular level, but that's going to
6873 be less stable than filenames or function names. */
6875 /* So for now, just use a global context. */
6878 b->exp = parse_expression (b->exp_string);
6879 b->exp_valid_block = innermost_block;
6880 mark = value_mark ();
6882 value_free (b->val);
6883 b->val = evaluate_expression (b->exp);
6884 release_value (b->val);
6885 if (VALUE_LAZY (b->val))
6886 value_fetch_lazy (b->val);
6888 if (b->cond_string != NULL)
6893 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6895 if (b->enable_state == bp_enabled)
6897 value_free_to_mark (mark);
6899 case bp_catch_catch:
6900 case bp_catch_throw:
6902 /* We needn't really do anything to reset these, since the mask
6903 that requests them is unaffected by e.g., new libraries being
6906 case bp_catch_vfork:
6911 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6913 /* Delete longjmp and overlay event breakpoints; they will be
6914 reset later by breakpoint_re_set. */
6916 case bp_longjmp_resume:
6917 case bp_overlay_event:
6918 delete_breakpoint (b);
6921 /* This breakpoint is special, it's set up when the inferior
6922 starts and we really don't want to touch it. */
6923 case bp_shlib_event:
6925 /* Like bp_shlib_event, this breakpoint type is special.
6926 Once it is set up, we do not want to touch it. */
6927 case bp_thread_event:
6929 /* Keep temporary breakpoints, which can be encountered when we step
6930 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6931 Otherwise these should have been blown away via the cleanup chain
6932 or by breakpoint_init_inferior when we rerun the executable. */
6935 case bp_watchpoint_scope:
6937 case bp_step_resume:
6944 /* Re-set all breakpoints after symbols have been re-loaded. */
6946 breakpoint_re_set (void)
6948 struct breakpoint *b, *temp;
6949 enum language save_language;
6950 int save_input_radix;
6951 static char message1[] = "Error in re-setting breakpoint %d:\n";
6952 char message[sizeof (message1) + 30 /* slop */ ];
6954 save_language = current_language->la_language;
6955 save_input_radix = input_radix;
6956 ALL_BREAKPOINTS_SAFE (b, temp)
6958 /* Format possible error msg */
6959 sprintf (message, message1, b->number);
6960 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6962 set_language (save_language);
6963 input_radix = save_input_radix;
6965 if (GET_LONGJMP_TARGET_P ())
6967 create_longjmp_breakpoint ("longjmp");
6968 create_longjmp_breakpoint ("_longjmp");
6969 create_longjmp_breakpoint ("siglongjmp");
6970 create_longjmp_breakpoint ("_siglongjmp");
6971 create_longjmp_breakpoint (NULL);
6974 create_overlay_event_breakpoint ("_ovly_debug_event");
6977 /* Reset the thread number of this breakpoint:
6979 - If the breakpoint is for all threads, leave it as-is.
6980 - Else, reset it to the current thread for inferior_ptid. */
6982 breakpoint_re_set_thread (struct breakpoint *b)
6984 if (b->thread != -1)
6986 if (in_thread_list (inferior_ptid))
6987 b->thread = pid_to_thread_id (inferior_ptid);
6991 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6992 If from_tty is nonzero, it prints a message to that effect,
6993 which ends with a period (no newline). */
6996 set_ignore_count (int bptnum, int count, int from_tty)
6998 register struct breakpoint *b;
7004 if (b->number == bptnum)
7006 b->ignore_count = count;
7009 else if (count == 0)
7010 printf_filtered ("Will stop next time breakpoint %d is reached.",
7012 else if (count == 1)
7013 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7016 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7018 breakpoints_changed ();
7022 error ("No breakpoint number %d.", bptnum);
7025 /* Clear the ignore counts of all breakpoints. */
7027 breakpoint_clear_ignore_counts (void)
7029 struct breakpoint *b;
7032 b->ignore_count = 0;
7035 /* Command to set ignore-count of breakpoint N to COUNT. */
7038 ignore_command (char *args, int from_tty)
7044 error_no_arg ("a breakpoint number");
7046 num = get_number (&p);
7048 error ("bad breakpoint number: '%s'", args);
7050 error ("Second argument (specified ignore-count) is missing.");
7052 set_ignore_count (num,
7053 longest_to_int (value_as_long (parse_and_eval (p))),
7055 printf_filtered ("\n");
7056 breakpoints_changed ();
7059 /* Call FUNCTION on each of the breakpoints
7060 whose numbers are given in ARGS. */
7063 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7065 register char *p = args;
7068 register struct breakpoint *b, *tmp;
7072 error_no_arg ("one or more breakpoint numbers");
7079 num = get_number_or_range (&p1);
7082 warning ("bad breakpoint number at or near '%s'", p);
7086 ALL_BREAKPOINTS_SAFE (b, tmp)
7087 if (b->number == num)
7089 struct breakpoint *related_breakpoint = b->related_breakpoint;
7092 if (related_breakpoint)
7093 function (related_breakpoint);
7097 printf_unfiltered ("No breakpoint number %d.\n", num);
7103 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7104 If from_tty is nonzero, it prints a message to that effect,
7105 which ends with a period (no newline). */
7108 disable_breakpoint (struct breakpoint *bpt)
7110 /* Never disable a watchpoint scope breakpoint; we want to
7111 hit them when we leave scope so we can delete both the
7112 watchpoint and its scope breakpoint at that time. */
7113 if (bpt->type == bp_watchpoint_scope)
7116 /* You can't disable permanent breakpoints. */
7117 if (bpt->enable_state == bp_permanent)
7120 bpt->enable_state = bp_disabled;
7122 check_duplicates (bpt);
7124 if (modify_breakpoint_hook)
7125 modify_breakpoint_hook (bpt);
7126 breakpoint_modify_event (bpt->number);
7131 disable_command (char *args, int from_tty)
7133 register struct breakpoint *bpt;
7135 ALL_BREAKPOINTS (bpt)
7139 warning ("attempted to disable apparently deleted breakpoint #%d?",
7144 case bp_catch_unload:
7146 case bp_catch_vfork:
7148 case bp_catch_catch:
7149 case bp_catch_throw:
7150 case bp_hardware_breakpoint:
7152 case bp_hardware_watchpoint:
7153 case bp_read_watchpoint:
7154 case bp_access_watchpoint:
7155 disable_breakpoint (bpt);
7160 map_breakpoint_numbers (args, disable_breakpoint);
7164 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7166 struct frame_info *save_selected_frame = NULL;
7167 int save_selected_frame_level = -1;
7168 int target_resources_ok, other_type_used;
7171 if (bpt->type == bp_hardware_breakpoint)
7174 i = hw_breakpoint_used_count ();
7175 target_resources_ok =
7176 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7178 if (target_resources_ok == 0)
7179 error ("No hardware breakpoint support in the target.");
7180 else if (target_resources_ok < 0)
7181 error ("Hardware breakpoints used exceeds limit.");
7184 if (bpt->enable_state != bp_permanent)
7185 bpt->enable_state = bp_enabled;
7186 bpt->disposition = disposition;
7187 check_duplicates (bpt);
7188 breakpoints_changed ();
7190 if (bpt->type == bp_watchpoint ||
7191 bpt->type == bp_hardware_watchpoint ||
7192 bpt->type == bp_read_watchpoint ||
7193 bpt->type == bp_access_watchpoint)
7195 if (bpt->exp_valid_block != NULL)
7197 struct frame_info *fr =
7199 /* Ensure that we have the current frame. Else, this
7200 next query may pessimistically be answered as, "No,
7201 not within current scope". */
7202 get_current_frame ();
7203 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7207 Cannot enable watchpoint %d because the block in which its expression\n\
7208 is valid is not currently in scope.\n", bpt->number);
7209 bpt->enable_state = bp_disabled;
7213 save_selected_frame = selected_frame;
7214 save_selected_frame_level = selected_frame_level;
7215 select_frame (fr, -1);
7218 value_free (bpt->val);
7219 mark = value_mark ();
7220 bpt->val = evaluate_expression (bpt->exp);
7221 release_value (bpt->val);
7222 if (VALUE_LAZY (bpt->val))
7223 value_fetch_lazy (bpt->val);
7225 if (bpt->type == bp_hardware_watchpoint ||
7226 bpt->type == bp_read_watchpoint ||
7227 bpt->type == bp_access_watchpoint)
7229 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7230 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7232 /* Hack around 'unused var' error for some targets here */
7234 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7235 bpt->type, i + mem_cnt, other_type_used);
7236 /* we can consider of type is bp_hardware_watchpoint, convert to
7237 bp_watchpoint in the following condition */
7238 if (target_resources_ok < 0)
7241 Cannot enable watchpoint %d because target watch resources\n\
7242 have been allocated for other watchpoints.\n", bpt->number);
7243 bpt->enable_state = bp_disabled;
7244 value_free_to_mark (mark);
7249 if (save_selected_frame_level >= 0)
7250 select_frame (save_selected_frame, save_selected_frame_level);
7251 value_free_to_mark (mark);
7253 if (modify_breakpoint_hook)
7254 modify_breakpoint_hook (bpt);
7255 breakpoint_modify_event (bpt->number);
7259 enable_breakpoint (struct breakpoint *bpt)
7261 do_enable_breakpoint (bpt, bpt->disposition);
7264 /* The enable command enables the specified breakpoints (or all defined
7265 breakpoints) so they once again become (or continue to be) effective
7266 in stopping the inferior. */
7270 enable_command (char *args, int from_tty)
7272 register struct breakpoint *bpt;
7274 ALL_BREAKPOINTS (bpt)
7278 warning ("attempted to enable apparently deleted breakpoint #%d?",
7283 case bp_catch_unload:
7285 case bp_catch_vfork:
7287 case bp_catch_catch:
7288 case bp_catch_throw:
7289 case bp_hardware_breakpoint:
7291 case bp_hardware_watchpoint:
7292 case bp_read_watchpoint:
7293 case bp_access_watchpoint:
7294 enable_breakpoint (bpt);
7299 map_breakpoint_numbers (args, enable_breakpoint);
7303 enable_once_breakpoint (struct breakpoint *bpt)
7305 do_enable_breakpoint (bpt, disp_disable);
7310 enable_once_command (char *args, int from_tty)
7312 map_breakpoint_numbers (args, enable_once_breakpoint);
7316 enable_delete_breakpoint (struct breakpoint *bpt)
7318 do_enable_breakpoint (bpt, disp_del);
7323 enable_delete_command (char *args, int from_tty)
7325 map_breakpoint_numbers (args, enable_delete_breakpoint);
7328 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7330 struct symtabs_and_lines
7331 decode_line_spec_1 (char *string, int funfirstline)
7333 struct symtabs_and_lines sals;
7335 error ("Empty line specification.");
7336 if (default_breakpoint_valid)
7337 sals = decode_line_1 (&string, funfirstline,
7338 default_breakpoint_symtab,
7339 default_breakpoint_line,
7342 sals = decode_line_1 (&string, funfirstline,
7343 (struct symtab *) NULL, 0, (char ***) NULL);
7345 error ("Junk at end of line specification: %s", string);
7350 _initialize_breakpoint (void)
7352 struct cmd_list_element *c;
7354 breakpoint_chain = 0;
7355 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7356 before a breakpoint is set. */
7357 breakpoint_count = 0;
7359 add_com ("ignore", class_breakpoint, ignore_command,
7360 "Set ignore-count of breakpoint number N to COUNT.\n\
7361 Usage is `ignore N COUNT'.");
7363 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7365 add_com ("commands", class_breakpoint, commands_command,
7366 "Set commands to be executed when a breakpoint is hit.\n\
7367 Give breakpoint number as argument after \"commands\".\n\
7368 With no argument, the targeted breakpoint is the last one set.\n\
7369 The commands themselves follow starting on the next line.\n\
7370 Type a line containing \"end\" to indicate the end of them.\n\
7371 Give \"silent\" as the first line to make the breakpoint silent;\n\
7372 then no output is printed when it is hit, except what the commands print.");
7374 add_com ("condition", class_breakpoint, condition_command,
7375 "Specify breakpoint number N to break only if COND is true.\n\
7376 Usage is `condition N COND', where N is an integer and COND is an\n\
7377 expression to be evaluated whenever breakpoint N is reached. ");
7379 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7380 "Set a temporary breakpoint. Args like \"break\" command.\n\
7381 Like \"break\" except the breakpoint is only temporary,\n\
7382 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7383 by using \"enable delete\" on the breakpoint number.");
7384 set_cmd_completer (c, location_completer);
7386 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7387 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7388 Like \"break\" except the breakpoint requires hardware support,\n\
7389 some target hardware may not have this support.");
7390 set_cmd_completer (c, location_completer);
7392 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7393 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7394 Like \"hbreak\" except the breakpoint is only temporary,\n\
7395 so it will be deleted when hit.");
7396 set_cmd_completer (c, location_completer);
7398 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7399 "Enable some breakpoints.\n\
7400 Give breakpoint numbers (separated by spaces) as arguments.\n\
7401 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7402 This is used to cancel the effect of the \"disable\" command.\n\
7403 With a subcommand you can enable temporarily.",
7404 &enablelist, "enable ", 1, &cmdlist);
7406 add_com ("ab", class_breakpoint, enable_command,
7407 "Enable some breakpoints.\n\
7408 Give breakpoint numbers (separated by spaces) as arguments.\n\
7409 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7410 This is used to cancel the effect of the \"disable\" command.\n\
7411 With a subcommand you can enable temporarily.");
7413 add_com_alias ("en", "enable", class_breakpoint, 1);
7415 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7416 "Enable some breakpoints.\n\
7417 Give breakpoint numbers (separated by spaces) as arguments.\n\
7418 This is used to cancel the effect of the \"disable\" command.\n\
7419 May be abbreviated to simply \"enable\".\n",
7420 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7422 add_cmd ("once", no_class, enable_once_command,
7423 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7424 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7427 add_cmd ("delete", no_class, enable_delete_command,
7428 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7429 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7432 add_cmd ("delete", no_class, enable_delete_command,
7433 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7434 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7437 add_cmd ("once", no_class, enable_once_command,
7438 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7439 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7442 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7443 "Disable some breakpoints.\n\
7444 Arguments are breakpoint numbers with spaces in between.\n\
7445 To disable all breakpoints, give no argument.\n\
7446 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7447 &disablelist, "disable ", 1, &cmdlist);
7448 add_com_alias ("dis", "disable", class_breakpoint, 1);
7449 add_com_alias ("disa", "disable", class_breakpoint, 1);
7451 add_com ("sb", class_breakpoint, disable_command,
7452 "Disable some breakpoints.\n\
7453 Arguments are breakpoint numbers with spaces in between.\n\
7454 To disable all breakpoints, give no argument.\n\
7455 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7457 add_cmd ("breakpoints", class_alias, disable_command,
7458 "Disable some breakpoints.\n\
7459 Arguments are breakpoint numbers with spaces in between.\n\
7460 To disable all breakpoints, give no argument.\n\
7461 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7462 This command may be abbreviated \"disable\".",
7465 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7466 "Delete some breakpoints or auto-display expressions.\n\
7467 Arguments are breakpoint numbers with spaces in between.\n\
7468 To delete all breakpoints, give no argument.\n\
7470 Also a prefix command for deletion of other GDB objects.\n\
7471 The \"unset\" command is also an alias for \"delete\".",
7472 &deletelist, "delete ", 1, &cmdlist);
7473 add_com_alias ("d", "delete", class_breakpoint, 1);
7475 add_com ("db", class_breakpoint, delete_command,
7476 "Delete some breakpoints.\n\
7477 Arguments are breakpoint numbers with spaces in between.\n\
7478 To delete all breakpoints, give no argument.\n");
7480 add_cmd ("breakpoints", class_alias, delete_command,
7481 "Delete some breakpoints or auto-display expressions.\n\
7482 Arguments are breakpoint numbers with spaces in between.\n\
7483 To delete all breakpoints, give no argument.\n\
7484 This command may be abbreviated \"delete\".",
7487 add_com ("clear", class_breakpoint, clear_command,
7488 concat ("Clear breakpoint at specified line or function.\n\
7489 Argument may be line number, function name, or \"*\" and an address.\n\
7490 If line number is specified, all breakpoints in that line are cleared.\n\
7491 If function is specified, breakpoints at beginning of function are cleared.\n\
7492 If an address is specified, breakpoints at that address are cleared.\n\n",
7493 "With no argument, clears all breakpoints in the line that the selected frame\n\
7496 See also the \"delete\" command which clears breakpoints by number.", NULL));
7498 c = add_com ("break", class_breakpoint, break_command,
7499 concat ("Set breakpoint at specified line or function.\n\
7500 Argument may be line number, function name, or \"*\" and an address.\n\
7501 If line number is specified, break at start of code for that line.\n\
7502 If function is specified, break at start of code for that function.\n\
7503 If an address is specified, break at that exact address.\n",
7504 "With no arg, uses current execution address of selected stack frame.\n\
7505 This is useful for breaking on return to a stack frame.\n\
7507 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7509 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7510 set_cmd_completer (c, location_completer);
7512 add_com_alias ("b", "break", class_run, 1);
7513 add_com_alias ("br", "break", class_run, 1);
7514 add_com_alias ("bre", "break", class_run, 1);
7515 add_com_alias ("brea", "break", class_run, 1);
7519 add_com_alias ("ba", "break", class_breakpoint, 1);
7520 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7525 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7526 "Break in function/address or break at a line in the current file.",
7527 &stoplist, "stop ", 1, &cmdlist);
7528 add_cmd ("in", class_breakpoint, stopin_command,
7529 "Break in function or address.\n", &stoplist);
7530 add_cmd ("at", class_breakpoint, stopat_command,
7531 "Break at a line in the current file.\n", &stoplist);
7532 add_com ("status", class_info, breakpoints_info,
7533 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7534 The \"Type\" column indicates one of:\n\
7535 \tbreakpoint - normal breakpoint\n\
7536 \twatchpoint - watchpoint\n\
7537 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7538 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7539 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7540 address and file/line number respectively.\n\n",
7541 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7542 are set to the address of the last breakpoint listed.\n\n\
7543 Convenience variable \"$bpnum\" contains the number of the last\n\
7544 breakpoint set.", NULL));
7547 add_info ("breakpoints", breakpoints_info,
7548 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7549 The \"Type\" column indicates one of:\n\
7550 \tbreakpoint - normal breakpoint\n\
7551 \twatchpoint - watchpoint\n\
7552 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7553 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7554 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7555 address and file/line number respectively.\n\n",
7556 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7557 are set to the address of the last breakpoint listed.\n\n\
7558 Convenience variable \"$bpnum\" contains the number of the last\n\
7559 breakpoint set.", NULL));
7562 add_com ("lb", class_breakpoint, breakpoints_info,
7563 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7564 The \"Type\" column indicates one of:\n\
7565 \tbreakpoint - normal breakpoint\n\
7566 \twatchpoint - watchpoint\n\
7567 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7568 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7569 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7570 address and file/line number respectively.\n\n",
7571 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7572 are set to the address of the last breakpoint listed.\n\n\
7573 Convenience variable \"$bpnum\" contains the number of the last\n\
7574 breakpoint set.", NULL));
7576 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7577 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7578 The \"Type\" column indicates one of:\n\
7579 \tbreakpoint - normal breakpoint\n\
7580 \twatchpoint - watchpoint\n\
7581 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7582 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7583 \tuntil - internal breakpoint used by the \"until\" command\n\
7584 \tfinish - internal breakpoint used by the \"finish\" command\n",
7585 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7586 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7587 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7588 address and file/line number respectively.\n\n",
7589 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7590 are set to the address of the last breakpoint listed.\n\n\
7591 Convenience variable \"$bpnum\" contains the number of the last\n\
7592 breakpoint set.", NULL),
7593 &maintenanceinfolist);
7595 add_com ("catch", class_breakpoint, catch_command,
7596 "Set catchpoints to catch events.\n\
7597 Raised signals may be caught:\n\
7598 \tcatch signal - all signals\n\
7599 \tcatch signal <signame> - a particular signal\n\
7600 Raised exceptions may be caught:\n\
7601 \tcatch throw - all exceptions, when thrown\n\
7602 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7603 \tcatch catch - all exceptions, when caught\n\
7604 \tcatch catch <exceptname> - a particular exception, when caught\n\
7605 Thread or process events may be caught:\n\
7606 \tcatch thread_start - any threads, just after creation\n\
7607 \tcatch thread_exit - any threads, just before expiration\n\
7608 \tcatch thread_join - any threads, just after joins\n\
7609 Process events may be caught:\n\
7610 \tcatch start - any processes, just after creation\n\
7611 \tcatch exit - any processes, just before expiration\n\
7612 \tcatch fork - calls to fork()\n\
7613 \tcatch vfork - calls to vfork()\n\
7614 \tcatch exec - calls to exec()\n\
7615 Dynamically-linked library events may be caught:\n\
7616 \tcatch load - loads of any library\n\
7617 \tcatch load <libname> - loads of a particular library\n\
7618 \tcatch unload - unloads of any library\n\
7619 \tcatch unload <libname> - unloads of a particular library\n\
7620 The act of your program's execution stopping may also be caught:\n\
7622 C++ exceptions may be caught:\n\
7623 \tcatch throw - all exceptions, when thrown\n\
7624 \tcatch catch - all exceptions, when caught\n\
7626 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7627 after a fork or vfork is caught.\n\n\
7628 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7630 add_com ("tcatch", class_breakpoint, tcatch_command,
7631 "Set temporary catchpoints to catch events.\n\
7632 Args like \"catch\" command.\n\
7633 Like \"catch\" except the catchpoint is only temporary,\n\
7634 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7635 by using \"enable delete\" on the catchpoint number.");
7637 c = add_com ("watch", class_breakpoint, watch_command,
7638 "Set a watchpoint for an expression.\n\
7639 A watchpoint stops execution of your program whenever the value of\n\
7640 an expression changes.");
7641 set_cmd_completer (c, location_completer);
7643 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7644 "Set a read watchpoint for an expression.\n\
7645 A watchpoint stops execution of your program whenever the value of\n\
7646 an expression is read.");
7647 set_cmd_completer (c, location_completer);
7649 c = add_com ("awatch", class_breakpoint, awatch_command,
7650 "Set a watchpoint for an expression.\n\
7651 A watchpoint stops execution of your program whenever the value of\n\
7652 an expression is either read or written.");
7653 set_cmd_completer (c, location_completer);
7655 add_info ("watchpoints", breakpoints_info,
7656 "Synonym for ``info breakpoints''.");
7659 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7660 (char *) &can_use_hw_watchpoints,
7661 "Set debugger's willingness to use watchpoint hardware.\n\
7662 If zero, gdb will not use hardware for new watchpoints, even if\n\
7663 such is available. (However, any hardware watchpoints that were\n\
7664 created before setting this to nonzero, will continue to use watchpoint\n\
7667 add_show_from_set (c, &showlist);
7669 can_use_hw_watchpoints = 1;