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"
48 #include "cli/cli-script.h"
50 #include "gdb-events.h"
52 /* Prototypes for local functions. */
54 static void until_break_command_continuation (struct continuation_arg *arg);
56 static void catch_command_1 (char *, int, int);
58 static void enable_delete_command (char *, int);
60 static void enable_delete_breakpoint (struct breakpoint *);
62 static void enable_once_command (char *, int);
64 static void enable_once_breakpoint (struct breakpoint *);
66 static void disable_command (char *, int);
68 static void enable_command (char *, int);
70 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
72 static void ignore_command (char *, int);
74 static int breakpoint_re_set_one (PTR);
76 static void clear_command (char *, int);
78 static void catch_command (char *, int);
80 static void handle_gnu_4_16_catch_command (char *, int, int);
82 static struct symtabs_and_lines get_catch_sals (int);
84 static void watch_command (char *, int);
86 static int can_use_hardware_watchpoint (struct value *);
88 extern void break_at_finish_command (char *, int);
89 extern void break_at_finish_at_depth_command (char *, int);
91 extern void tbreak_at_finish_command (char *, int);
93 static void break_command_1 (char *, int, int);
95 static void mention (struct breakpoint *);
97 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
99 static void check_duplicates (struct breakpoint *);
101 static void describe_other_breakpoints (CORE_ADDR, asection *);
103 static void breakpoints_info (char *, int);
105 static void breakpoint_1 (int, int);
107 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
109 static int breakpoint_cond_eval (PTR);
111 static void cleanup_executing_breakpoints (PTR);
113 static void commands_command (char *, int);
115 static void condition_command (char *, int);
117 static int get_number_trailer (char **, int);
119 void set_breakpoint_count (int);
128 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
130 static enum print_stop_action print_it_typical (bpstat);
132 static enum print_stop_action print_bp_stop_message (bpstat bs);
136 enum exception_event_kind kind;
139 args_for_catchpoint_enable;
141 static int watchpoint_check (PTR);
143 static int cover_target_enable_exception_callback (PTR);
145 static void maintenance_info_breakpoints (char *, int);
147 static void create_longjmp_breakpoint (char *);
149 static void create_overlay_event_breakpoint (char *);
151 static int hw_breakpoint_used_count (void);
153 static int hw_watchpoint_used_count (enum bptype, int *);
155 static void hbreak_command (char *, int);
157 static void thbreak_command (char *, int);
159 static void watch_command_1 (char *, int, int);
161 static void rwatch_command (char *, int);
163 static void awatch_command (char *, int);
165 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
167 static void solib_load_unload_1 (char *hookname,
170 char *cond_string, enum bptype bp_kind);
172 static void create_fork_vfork_event_catchpoint (int tempflag,
174 enum bptype bp_kind);
176 static void break_at_finish_at_depth_command_1 (char *arg,
177 int flag, int from_tty);
179 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
181 static void stop_command (char *arg, int from_tty);
183 static void stopin_command (char *arg, int from_tty);
185 static void stopat_command (char *arg, int from_tty);
187 static char *ep_find_event_name_end (char *arg);
189 static char *ep_parse_optional_if_clause (char **arg);
191 static char *ep_parse_optional_filename (char **arg);
193 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
194 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
197 static void create_exception_catchpoint (int tempflag, char *cond_string,
198 enum exception_event_kind ex_event,
199 struct symtab_and_line *sal);
201 static void catch_exception_command_1 (enum exception_event_kind ex_event,
202 char *arg, int tempflag, int from_tty);
204 static void tcatch_command (char *arg, int from_tty);
206 static void ep_skip_leading_whitespace (char **s);
208 /* Prototypes for exported functions. */
210 /* If FALSE, gdb will not use hardware support for watchpoints, even
211 if such is available. */
212 static int can_use_hw_watchpoints;
214 void _initialize_breakpoint (void);
216 extern int addressprint; /* Print machine addresses? */
218 /* Are we executing breakpoint commands? */
219 static int executing_breakpoint_commands;
221 /* Are overlay event breakpoints enabled? */
222 static int overlay_events_enabled;
224 /* Walk the following statement or block through all breakpoints.
225 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
228 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
230 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
231 for (B = breakpoint_chain; \
232 B ? (TMP=B->next, 1): 0; \
235 /* True if SHIFT_INST_REGS defined, false otherwise. */
237 int must_shift_inst_regs =
238 #if defined(SHIFT_INST_REGS)
245 /* True if breakpoint hit counts should be displayed in breakpoint info. */
247 int show_breakpoint_hit_counts = 1;
249 /* Chain of all breakpoints defined. */
251 struct breakpoint *breakpoint_chain;
253 /* Number of last breakpoint made. */
255 int breakpoint_count;
257 /* Pointer to current exception event record */
258 static struct exception_event_record *current_exception_event;
260 /* Indicator of whether exception catchpoints should be nuked
261 between runs of a program */
262 int exception_catchpoints_are_fragile = 0;
264 /* Indicator of when exception catchpoints set-up should be
265 reinitialized -- e.g. when program is re-run */
266 int exception_support_initialized = 0;
268 /* This function returns a pointer to the string representation of the
269 pathname of the dynamically-linked library that has just been
272 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
273 or undefined results are guaranteed.
275 This string's contents are only valid immediately after the
276 inferior has stopped in the dynamic linker hook, and becomes
277 invalid as soon as the inferior is continued. Clients should make
278 a copy of this string if they wish to continue the inferior and
279 then access the string. */
281 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
282 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
285 /* This function returns a pointer to the string representation of the
286 pathname of the dynamically-linked library that has just been
289 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
290 TRUE, or undefined results are guaranteed.
292 This string's contents are only valid immediately after the
293 inferior has stopped in the dynamic linker hook, and becomes
294 invalid as soon as the inferior is continued. Clients should make
295 a copy of this string if they wish to continue the inferior and
296 then access the string. */
298 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
299 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
302 /* This function is called by the "catch load" command. It allows the
303 debugger to be notified by the dynamic linker when a specified
304 library file (or any library file, if filename is NULL) is loaded. */
306 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
307 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
308 error ("catch of library loads not yet implemented on this platform")
311 /* This function is called by the "catch unload" command. It allows
312 the debugger to be notified by the dynamic linker when a specified
313 library file (or any library file, if filename is NULL) is
316 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
317 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
318 error ("catch of library unloads not yet implemented on this platform")
321 /* Set breakpoint count to NUM. */
324 set_breakpoint_count (int num)
326 breakpoint_count = num;
327 set_internalvar (lookup_internalvar ("bpnum"),
328 value_from_longest (builtin_type_int, (LONGEST) num));
331 /* Used in run_command to zero the hit count when a new run starts. */
334 clear_breakpoint_hit_counts (void)
336 struct breakpoint *b;
342 /* Default address, symtab and line to put a breakpoint at
343 for "break" command with no arg.
344 if default_breakpoint_valid is zero, the other three are
345 not valid, and "break" with no arg is an error.
347 This set by print_stack_frame, which calls set_default_breakpoint. */
349 int default_breakpoint_valid;
350 CORE_ADDR default_breakpoint_address;
351 struct symtab *default_breakpoint_symtab;
352 int default_breakpoint_line;
354 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
355 Advance *PP after the string and any trailing whitespace.
357 Currently the string can either be a number or "$" followed by the name
358 of a convenience variable. Making it an expression wouldn't work well
359 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
361 TRAILER is a character which can be found after the number; most
362 commonly this is `-'. If you don't want a trailer, use \0. */
364 get_number_trailer (char **pp, int trailer)
366 int retval = 0; /* default */
370 /* Empty line means refer to the last breakpoint. */
371 return breakpoint_count;
374 /* Make a copy of the name, so we can null-terminate it
375 to pass to lookup_internalvar(). */
380 while (isalnum (*p) || *p == '_')
382 varname = (char *) alloca (p - start + 1);
383 strncpy (varname, start, p - start);
384 varname[p - start] = '\0';
385 val = value_of_internalvar (lookup_internalvar (varname));
386 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
387 retval = (int) value_as_long (val);
390 printf_filtered ("Convenience variable must have integer value.\n");
398 while (*p >= '0' && *p <= '9')
401 /* There is no number here. (e.g. "cond a == b"). */
403 /* Skip non-numeric token */
404 while (*p && !isspace((int) *p))
406 /* Return zero, which caller must interpret as error. */
412 if (!(isspace (*p) || *p == '\0' || *p == trailer))
414 /* Trailing junk: return 0 and let caller print error msg. */
415 while (!(isspace (*p) || *p == '\0' || *p == trailer))
426 /* Like get_number_trailer, but don't allow a trailer. */
428 get_number (char **pp)
430 return get_number_trailer (pp, '\0');
433 /* Parse a number or a range.
434 * A number will be of the form handled by get_number.
435 * A range will be of the form <number1> - <number2>, and
436 * will represent all the integers between number1 and number2,
439 * While processing a range, this fuction is called iteratively;
440 * At each call it will return the next value in the range.
442 * At the beginning of parsing a range, the char pointer PP will
443 * be advanced past <number1> and left pointing at the '-' token.
444 * Subsequent calls will not advance the pointer until the range
445 * is completed. The call that completes the range will advance
446 * pointer PP past <number2>.
450 get_number_or_range (char **pp)
452 static int last_retval, end_value;
453 static char *end_ptr;
454 static int in_range = 0;
458 /* Default case: pp is pointing either to a solo number,
459 or to the first number of a range. */
460 last_retval = get_number_trailer (pp, '-');
465 /* This is the start of a range (<number1> - <number2>).
466 Skip the '-', parse and remember the second number,
467 and also remember the end of the final token. */
471 while (isspace ((int) *end_ptr))
472 end_ptr++; /* skip white space */
473 end_value = get_number (temp);
474 if (end_value < last_retval)
476 error ("inverted range");
478 else if (end_value == last_retval)
480 /* degenerate range (number1 == number2). Advance the
481 token pointer so that the range will be treated as a
490 error ("negative value");
493 /* pp points to the '-' that betokens a range. All
494 number-parsing has already been done. Return the next
495 integer value (one greater than the saved previous value).
496 Do not advance the token pointer 'pp' until the end of range
499 if (++last_retval == end_value)
501 /* End of range reached; advance token pointer. */
511 /* condition N EXP -- set break condition of breakpoint N to EXP. */
514 condition_command (char *arg, int from_tty)
516 register struct breakpoint *b;
521 error_no_arg ("breakpoint number");
524 bnum = get_number (&p);
526 error ("Bad breakpoint argument: '%s'", arg);
529 if (b->number == bnum)
536 if (b->cond_string != NULL)
537 xfree (b->cond_string);
542 b->cond_string = NULL;
544 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
549 /* I don't know if it matters whether this is the string the user
550 typed in or the decompiled expression. */
551 b->cond_string = savestring (arg, strlen (arg));
552 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
554 error ("Junk at end of expression");
556 breakpoints_changed ();
557 breakpoint_modify_event (b->number);
561 error ("No breakpoint number %d.", bnum);
566 commands_command (char *arg, int from_tty)
568 register struct breakpoint *b;
571 struct command_line *l;
573 /* If we allowed this, we would have problems with when to
574 free the storage, if we change the commands currently
577 if (executing_breakpoint_commands)
578 error ("Can't use the \"commands\" command among a breakpoint's commands.");
581 bnum = get_number (&p);
584 error ("Unexpected extra arguments following breakpoint number.");
587 if (b->number == bnum)
591 "Type commands for when breakpoint %d is hit, one per line.",
593 l = read_command_lines (tmpbuf, from_tty);
594 free_command_lines (&b->commands);
596 breakpoints_changed ();
597 breakpoint_modify_event (b->number);
600 error ("No breakpoint number %d.", bnum);
603 /* Like target_read_memory() but if breakpoints are inserted, return
604 the shadow contents instead of the breakpoints themselves.
606 Read "memory data" from whatever target or inferior we have.
607 Returns zero if successful, errno value if not. EIO is used
608 for address out of bounds. If breakpoints are inserted, returns
609 shadow contents, not the breakpoints themselves. From breakpoint.c. */
612 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
615 struct breakpoint *b;
616 CORE_ADDR bp_addr = 0;
619 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
620 /* No breakpoints on this machine. */
621 return target_read_memory (memaddr, myaddr, len);
625 if (b->type == bp_none)
626 warning ("reading through apparently deleted breakpoint #%d?",
629 /* memory breakpoint? */
630 if (b->type == bp_watchpoint
631 || b->type == bp_hardware_watchpoint
632 || b->type == bp_read_watchpoint
633 || b->type == bp_access_watchpoint)
638 /* Addresses and length of the part of the breakpoint that
640 /* XXXX The m68k, sh and h8300 have different local and remote
641 breakpoint values. BREAKPOINT_FROM_PC still manages to
642 correctly determine the breakpoints memory address and size
643 for these targets. */
644 bp_addr = b->address;
646 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
651 if (bp_addr + bp_size <= memaddr)
652 /* The breakpoint is entirely before the chunk of memory we
655 if (bp_addr >= memaddr + len)
656 /* The breakpoint is entirely after the chunk of memory we are
659 /* Copy the breakpoint from the shadow contents, and recurse for
660 the things before and after. */
662 /* Offset within shadow_contents. */
665 if (bp_addr < memaddr)
667 /* Only copy the second part of the breakpoint. */
668 bp_size -= memaddr - bp_addr;
669 bptoffset = memaddr - bp_addr;
673 if (bp_addr + bp_size > memaddr + len)
675 /* Only copy the first part of the breakpoint. */
676 bp_size -= (bp_addr + bp_size) - (memaddr + len);
679 memcpy (myaddr + bp_addr - memaddr,
680 b->shadow_contents + bptoffset, bp_size);
682 if (bp_addr > memaddr)
684 /* Copy the section of memory before the breakpoint. */
685 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
690 if (bp_addr + bp_size < memaddr + len)
692 /* Copy the section of memory after the breakpoint. */
693 status = read_memory_nobpt (bp_addr + bp_size,
694 myaddr + bp_addr + bp_size - memaddr,
695 memaddr + len - (bp_addr + bp_size));
702 /* Nothing overlaps. Just call read_memory_noerr. */
703 return target_read_memory (memaddr, myaddr, len);
707 /* insert_breakpoints is used when starting or continuing the program.
708 remove_breakpoints is used when the program stops.
709 Both return zero if successful,
710 or an `errno' value if could not write the inferior. */
713 insert_breakpoints (void)
715 register struct breakpoint *b, *temp;
716 int return_val = 0; /* return success code. */
718 int disabled_breaks = 0;
719 int hw_breakpoint_error = 0;
720 #ifdef ONE_PROCESS_WRITETEXT
721 int process_warning = 0;
724 static char message1[] = "Error inserting catchpoint %d:\n";
725 static char message[sizeof (message1) + 30];
727 struct ui_file *tmp_error_stream = mem_fileopen ();
728 make_cleanup_ui_file_delete (tmp_error_stream);
730 /* Explicitly mark the warning -- this will only be printed if
731 there was an error. */
732 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
734 ALL_BREAKPOINTS_SAFE (b, temp)
736 if (b->enable_state == bp_permanent)
737 /* Permanent breakpoints cannot be inserted or removed. */
739 if ((b->type == bp_watchpoint
740 || b->type == bp_hardware_watchpoint
741 || b->type == bp_read_watchpoint
742 || b->type == bp_access_watchpoint) && (!b->val))
745 val = evaluate_expression (b->exp);
747 if (VALUE_LAZY (val))
748 value_fetch_lazy (val);
751 if (b->type != bp_watchpoint
752 && b->type != bp_hardware_watchpoint
753 && b->type != bp_read_watchpoint
754 && b->type != bp_access_watchpoint
755 && b->type != bp_catch_fork
756 && b->type != bp_catch_vfork
757 && b->type != bp_catch_exec
758 && b->type != bp_catch_throw
759 && b->type != bp_catch_catch
760 && b->enable_state != bp_disabled
761 && b->enable_state != bp_shlib_disabled
762 && b->enable_state != bp_call_disabled
766 /* "Normal" instruction breakpoint: either the standard
767 trap-instruction bp (bp_breakpoint), or a
768 bp_hardware_breakpoint. */
770 /* First check to see if we have to handle an overlay. */
771 if (overlay_debugging == ovly_off
772 || b->section == NULL
773 || !(section_is_overlay (b->section)))
775 /* No overlay handling: just set the breakpoint. */
777 if (b->type == bp_hardware_breakpoint)
778 val = target_insert_hw_breakpoint (b->address,
781 val = target_insert_breakpoint (b->address, b->shadow_contents);
785 /* This breakpoint is in an overlay section.
786 Shall we set a breakpoint at the LMA? */
787 if (!overlay_events_enabled)
789 /* Yes -- overlay event support is not active,
790 so we must try to set a breakpoint at the LMA.
791 This will not work for a hardware breakpoint. */
792 if (b->type == bp_hardware_breakpoint)
793 warning ("hardware breakpoint %d not supported in overlay!\n",
797 CORE_ADDR addr = overlay_unmapped_address (b->address,
799 /* Set a software (trap) breakpoint at the LMA. */
800 val = target_insert_breakpoint (addr, b->shadow_contents);
802 fprintf_unfiltered (tmp_error_stream,
803 "Overlay breakpoint %d failed: in ROM?",
807 /* Shall we set a breakpoint at the VMA? */
808 if (section_is_mapped (b->section))
810 /* Yes. This overlay section is mapped into memory. */
811 if (b->type == bp_hardware_breakpoint)
812 val = target_insert_hw_breakpoint (b->address,
815 val = target_insert_breakpoint (b->address,
820 /* No. This breakpoint will not be inserted.
821 No error, but do not mark the bp as 'inserted'. */
828 /* Can't set the breakpoint. */
829 #if defined (DISABLE_UNSETTABLE_BREAK)
830 if (DISABLE_UNSETTABLE_BREAK (b->address))
832 /* See also: disable_breakpoints_in_shlibs. */
834 b->enable_state = bp_shlib_disabled;
835 if (!disabled_breaks)
837 fprintf_unfiltered (tmp_error_stream,
838 "Cannot insert breakpoint %d.\n",
840 fprintf_unfiltered (tmp_error_stream,
841 "Temporarily disabling shared library breakpoints:\n");
844 fprintf_unfiltered (tmp_error_stream,
845 "breakpoint #%d\n", b->number);
850 #ifdef ONE_PROCESS_WRITETEXT
853 if (b->type == bp_hardware_breakpoint)
855 hw_breakpoint_error = 1;
856 fprintf_unfiltered (tmp_error_stream,
857 "Cannot insert hardware breakpoint %d.\n",
862 fprintf_unfiltered (tmp_error_stream,
863 "Cannot insert breakpoint %d.\n",
865 fprintf_filtered (tmp_error_stream,
866 "Error accessing memory address ");
867 print_address_numeric (b->address, 1, tmp_error_stream);
868 fprintf_filtered (tmp_error_stream, ": %s.\n",
869 safe_strerror (val));
878 return_val = val; /* remember failure */
880 else if (ep_is_exception_catchpoint (b)
881 && b->enable_state != bp_disabled
882 && b->enable_state != bp_shlib_disabled
883 && b->enable_state != bp_call_disabled
888 /* If we get here, we must have a callback mechanism for exception
889 events -- with g++ style embedded label support, we insert
890 ordinary breakpoints and not catchpoints. */
891 /* Format possible error message */
892 sprintf (message, message1, b->number);
894 val = target_insert_breakpoint (b->address, b->shadow_contents);
897 /* Couldn't set breakpoint for some reason */
898 fprintf_unfiltered (tmp_error_stream,
899 "Cannot insert catchpoint %d; disabling it.\n",
901 fprintf_filtered (tmp_error_stream,
902 "Error accessing memory address ");
903 print_address_numeric (b->address, 1, tmp_error_stream);
904 fprintf_filtered (tmp_error_stream, ": %s.\n",
905 safe_strerror (val));
906 b->enable_state = bp_disabled;
910 /* Bp set, now make sure callbacks are enabled */
912 args_for_catchpoint_enable args;
913 args.kind = b->type == bp_catch_catch ?
914 EX_EVENT_CATCH : EX_EVENT_THROW;
916 val = catch_errors (cover_target_enable_exception_callback,
918 message, RETURN_MASK_ALL);
919 if (val != 0 && val != -1)
923 /* Check if something went wrong; val == 0 can be ignored */
926 /* something went wrong */
927 fprintf_unfiltered (tmp_error_stream,
928 "Cannot insert catchpoint %d; disabling it.\n",
930 b->enable_state = bp_disabled;
935 return_val = val; /* remember failure */
938 else if ((b->type == bp_hardware_watchpoint ||
939 b->type == bp_read_watchpoint ||
940 b->type == bp_access_watchpoint)
941 && b->enable_state == bp_enabled
942 && b->disposition != disp_del_at_next_stop
946 struct frame_info *saved_frame;
947 int saved_level, within_current_scope;
948 struct value *mark = value_mark ();
951 /* Save the current frame and level so we can restore it after
952 evaluating the watchpoint expression on its own frame. */
953 saved_frame = selected_frame;
954 saved_level = frame_relative_level (selected_frame);
956 /* Determine if the watchpoint is within scope. */
957 if (b->exp_valid_block == NULL)
958 within_current_scope = 1;
961 struct frame_info *fi;
962 fi = frame_find_by_id (b->watchpoint_frame);
963 within_current_scope = (fi != NULL);
964 if (within_current_scope)
968 if (within_current_scope)
970 /* Evaluate the expression and cut the chain of values
971 produced off from the value chain.
973 Make sure the value returned isn't lazy; we use
974 laziness to determine what memory GDB actually needed
975 in order to compute the value of the expression. */
976 v = evaluate_expression (b->exp);
978 value_release_to_mark (mark);
983 /* Look at each value on the value chain. */
984 for (; v; v = v->next)
986 /* If it's a memory location, and GDB actually needed
987 its contents to evaluate the expression, then we
989 if (VALUE_LVAL (v) == lval_memory
992 struct type *vtype = check_typedef (VALUE_TYPE (v));
994 /* We only watch structs and arrays if user asked
995 for it explicitly, never if they just happen to
996 appear in the middle of some value chain. */
997 if (v == b->val_chain
998 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
999 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1004 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1005 len = TYPE_LENGTH (VALUE_TYPE (v));
1007 if (b->type == bp_read_watchpoint)
1009 else if (b->type == bp_access_watchpoint)
1012 val = target_insert_watchpoint (addr, len, type);
1015 /* Don't exit the loop, try to insert
1016 every value on the value chain. That's
1017 because we will be removing all the
1018 watches below, and removing a
1019 watchpoint we didn't insert could have
1027 /* Failure to insert a watchpoint on any memory value in the
1028 value chain brings us here. */
1031 remove_breakpoint (b, mark_uninserted);
1032 hw_breakpoint_error = 1;
1033 fprintf_unfiltered (tmp_error_stream,
1034 "Could not insert hardware watchpoint %d.\n",
1041 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
1042 printf_filtered ("because the program has left the block \n");
1043 printf_filtered ("in which its expression is valid.\n");
1044 if (b->related_breakpoint)
1045 b->related_breakpoint->disposition = disp_del_at_next_stop;
1046 b->disposition = disp_del_at_next_stop;
1049 /* Restore the frame and level. */
1050 if ((saved_frame != selected_frame) ||
1051 (saved_level != frame_relative_level (selected_frame)))
1052 select_frame (saved_frame);
1055 return_val = val; /* remember failure */
1057 else if ((b->type == bp_catch_fork
1058 || b->type == bp_catch_vfork
1059 || b->type == bp_catch_exec)
1060 && b->enable_state == bp_enabled
1068 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
1070 case bp_catch_vfork:
1071 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
1074 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
1077 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1082 fprintf_unfiltered (tmp_error_stream,
1083 "Cannot insert catchpoint %d.", b->number);
1089 return_val = val; /* remember failure */
1095 /* If a hardware breakpoint or watchpoint was inserted, add a
1096 message about possibly exhausted resources. */
1097 if (hw_breakpoint_error)
1099 fprintf_unfiltered (tmp_error_stream,
1100 "Could not insert hardware breakpoints:\n\
1101 You may have requested too many hardware breakpoints/watchpoints.\n");
1103 #ifdef ONE_PROCESS_WRITETEXT
1104 if (process_warning)
1105 fprintf_unfiltered (tmp_error_stream,
1106 "The same program may be running in another process.");
1108 target_terminal_ours_for_output ();
1109 error_stream (tmp_error_stream);
1115 remove_breakpoints (void)
1117 register struct breakpoint *b;
1124 val = remove_breakpoint (b, mark_uninserted);
1133 remove_hw_watchpoints (void)
1135 register struct breakpoint *b;
1141 && (b->type == bp_hardware_watchpoint
1142 || b->type == bp_read_watchpoint
1143 || b->type == bp_access_watchpoint))
1145 val = remove_breakpoint (b, mark_uninserted);
1154 reattach_breakpoints (int pid)
1156 register struct breakpoint *b;
1158 struct cleanup *old_chain = save_inferior_ptid ();
1160 /* Set inferior_ptid; remove_breakpoint uses this global. */
1161 inferior_ptid = pid_to_ptid (pid);
1166 remove_breakpoint (b, mark_inserted);
1167 if (b->type == bp_hardware_breakpoint)
1168 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1170 val = target_insert_breakpoint (b->address, b->shadow_contents);
1173 do_cleanups (old_chain);
1178 do_cleanups (old_chain);
1183 update_breakpoints_after_exec (void)
1185 struct breakpoint *b;
1186 struct breakpoint *temp;
1188 /* Doing this first prevents the badness of having delete_breakpoint()
1189 write a breakpoint's current "shadow contents" to lift the bp. That
1190 shadow is NOT valid after an exec()! */
1191 mark_breakpoints_out ();
1193 ALL_BREAKPOINTS_SAFE (b, temp)
1195 /* Solib breakpoints must be explicitly reset after an exec(). */
1196 if (b->type == bp_shlib_event)
1198 delete_breakpoint (b);
1202 /* Thread event breakpoints must be set anew after an exec(),
1203 as must overlay event breakpoints. */
1204 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1206 delete_breakpoint (b);
1210 /* Step-resume breakpoints are meaningless after an exec(). */
1211 if (b->type == bp_step_resume)
1213 delete_breakpoint (b);
1217 /* Ditto the sigtramp handler breakpoints. */
1218 if (b->type == bp_through_sigtramp)
1220 delete_breakpoint (b);
1224 /* Ditto the exception-handling catchpoints. */
1225 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1227 delete_breakpoint (b);
1231 /* Don't delete an exec catchpoint, because else the inferior
1232 won't stop when it ought!
1234 Similarly, we probably ought to keep vfork catchpoints, 'cause
1235 on this target, we may not be able to stop when the vfork is
1236 seen, but only when the subsequent exec is seen. (And because
1237 deleting fork catchpoints here but not vfork catchpoints will
1238 seem mysterious to users, keep those too.)
1240 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1241 target address field, if any, is sufficient to have it be reset
1242 automagically. Certainly on HP-UX that's true.
1245 valid code address on some platforms (like the mn10200 and
1246 mn10300 simulators). We shouldn't assign any special
1247 interpretation to a breakpoint with a zero address. And in
1248 fact, GDB doesn't --- I can't see what that comment above is
1249 talking about. As far as I can tell, setting the address of a
1250 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1251 is meaningless, since those are implemented with HP-UX kernel
1252 hackery, not by storing breakpoint instructions somewhere. */
1253 if ((b->type == bp_catch_exec) ||
1254 (b->type == bp_catch_vfork) ||
1255 (b->type == bp_catch_fork))
1257 b->address = (CORE_ADDR) NULL;
1261 /* bp_finish is a special case. The only way we ought to be able
1262 to see one of these when an exec() has happened, is if the user
1263 caught a vfork, and then said "finish". Ordinarily a finish just
1264 carries them to the call-site of the current callee, by setting
1265 a temporary bp there and resuming. But in this case, the finish
1266 will carry them entirely through the vfork & exec.
1268 We don't want to allow a bp_finish to remain inserted now. But
1269 we can't safely delete it, 'cause finish_command has a handle to
1270 the bp on a bpstat, and will later want to delete it. There's a
1271 chance (and I've seen it happen) that if we delete the bp_finish
1272 here, that its storage will get reused by the time finish_command
1273 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1274 We really must allow finish_command to delete a bp_finish.
1276 In the absense of a general solution for the "how do we know
1277 it's safe to delete something others may have handles to?"
1278 problem, what we'll do here is just uninsert the bp_finish, and
1279 let finish_command delete it.
1281 (We know the bp_finish is "doomed" in the sense that it's
1282 momentary, and will be deleted as soon as finish_command sees
1283 the inferior stopped. So it doesn't matter that the bp's
1284 address is probably bogus in the new a.out, unlike e.g., the
1285 solib breakpoints.) */
1287 if (b->type == bp_finish)
1292 /* Without a symbolic address, we have little hope of the
1293 pre-exec() address meaning the same thing in the post-exec()
1295 if (b->addr_string == NULL)
1297 delete_breakpoint (b);
1301 /* If this breakpoint has survived the above battery of checks, then
1302 it must have a symbolic address. Be sure that it gets reevaluated
1303 to a target address, rather than reusing the old evaluation.
1306 for bp_catch_exec and friends, I'm pretty sure this is entirely
1307 unnecessary. A call to breakpoint_re_set_one always recomputes
1308 the breakpoint's address from scratch, or deletes it if it can't.
1309 So I think this assignment could be deleted without effect. */
1310 b->address = (CORE_ADDR) NULL;
1312 /* FIXME what about longjmp breakpoints? Re-create them here? */
1313 create_overlay_event_breakpoint ("_ovly_debug_event");
1317 detach_breakpoints (int pid)
1319 register struct breakpoint *b;
1321 struct cleanup *old_chain = save_inferior_ptid ();
1323 if (pid == PIDGET (inferior_ptid))
1324 error ("Cannot detach breakpoints of inferior_ptid");
1326 /* Set inferior_ptid; remove_breakpoint uses this global. */
1327 inferior_ptid = pid_to_ptid (pid);
1332 val = remove_breakpoint (b, mark_inserted);
1335 do_cleanups (old_chain);
1340 do_cleanups (old_chain);
1345 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1349 if (b->enable_state == bp_permanent)
1350 /* Permanent breakpoints cannot be inserted or removed. */
1353 if (b->type == bp_none)
1354 warning ("attempted to remove apparently deleted breakpoint #%d?",
1357 if (b->type != bp_watchpoint
1358 && b->type != bp_hardware_watchpoint
1359 && b->type != bp_read_watchpoint
1360 && b->type != bp_access_watchpoint
1361 && b->type != bp_catch_fork
1362 && b->type != bp_catch_vfork
1363 && b->type != bp_catch_exec
1364 && b->type != bp_catch_catch
1365 && b->type != bp_catch_throw)
1367 /* "Normal" instruction breakpoint: either the standard
1368 trap-instruction bp (bp_breakpoint), or a
1369 bp_hardware_breakpoint. */
1371 /* First check to see if we have to handle an overlay. */
1372 if (overlay_debugging == ovly_off
1373 || b->section == NULL
1374 || !(section_is_overlay (b->section)))
1376 /* No overlay handling: just remove the breakpoint. */
1378 if (b->type == bp_hardware_breakpoint)
1379 val = target_remove_hw_breakpoint (b->address,
1380 b->shadow_contents);
1382 val = target_remove_breakpoint (b->address, b->shadow_contents);
1386 /* This breakpoint is in an overlay section.
1387 Did we set a breakpoint at the LMA? */
1388 if (!overlay_events_enabled)
1390 /* Yes -- overlay event support is not active, so we
1391 should have set a breakpoint at the LMA. Remove it.
1393 CORE_ADDR addr = overlay_unmapped_address (b->address,
1395 /* Ignore any failures: if the LMA is in ROM, we will
1396 have already warned when we failed to insert it. */
1397 if (b->type != bp_hardware_breakpoint)
1398 target_remove_hw_breakpoint (addr, b->shadow_contents);
1400 target_remove_breakpoint (addr, b->shadow_contents);
1402 /* Did we set a breakpoint at the VMA?
1403 If so, we will have marked the breakpoint 'inserted'. */
1406 /* Yes -- remove it. Previously we did not bother to
1407 remove the breakpoint if the section had been
1408 unmapped, but let's not rely on that being safe. We
1409 don't know what the overlay manager might do. */
1410 if (b->type == bp_hardware_breakpoint)
1411 val = target_remove_hw_breakpoint (b->address,
1412 b->shadow_contents);
1414 val = target_remove_breakpoint (b->address,
1415 b->shadow_contents);
1419 /* No -- not inserted, so no need to remove. No error. */
1425 b->inserted = (is == mark_inserted);
1427 else if ((b->type == bp_hardware_watchpoint ||
1428 b->type == bp_read_watchpoint ||
1429 b->type == bp_access_watchpoint)
1430 && b->enable_state == bp_enabled
1436 b->inserted = (is == mark_inserted);
1437 /* Walk down the saved value chain. */
1438 for (v = b->val_chain; v; v = v->next)
1440 /* For each memory reference remove the watchpoint
1442 if (VALUE_LVAL (v) == lval_memory
1443 && ! VALUE_LAZY (v))
1445 struct type *vtype = check_typedef (VALUE_TYPE (v));
1447 if (v == b->val_chain
1448 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1449 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1454 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1455 len = TYPE_LENGTH (VALUE_TYPE (v));
1457 if (b->type == bp_read_watchpoint)
1459 else if (b->type == bp_access_watchpoint)
1462 val = target_remove_watchpoint (addr, len, type);
1469 /* Failure to remove any of the hardware watchpoints comes here. */
1470 if ((is == mark_uninserted) && (b->inserted))
1471 warning ("Could not remove hardware watchpoint %d.",
1474 /* Free the saved value chain. We will construct a new one
1475 the next time the watchpoint is inserted. */
1476 for (v = b->val_chain; v; v = n)
1481 b->val_chain = NULL;
1483 else if ((b->type == bp_catch_fork ||
1484 b->type == bp_catch_vfork ||
1485 b->type == bp_catch_exec)
1486 && b->enable_state == bp_enabled
1493 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1495 case bp_catch_vfork:
1496 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1499 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1502 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1507 b->inserted = (is == mark_inserted);
1509 else if ((b->type == bp_catch_catch ||
1510 b->type == bp_catch_throw)
1511 && b->enable_state == bp_enabled
1515 val = target_remove_breakpoint (b->address, b->shadow_contents);
1518 b->inserted = (is == mark_inserted);
1520 else if (ep_is_exception_catchpoint (b)
1521 && b->inserted /* sometimes previous insert doesn't happen */
1522 && b->enable_state == bp_enabled
1526 val = target_remove_breakpoint (b->address, b->shadow_contents);
1530 b->inserted = (is == mark_inserted);
1536 /* Clear the "inserted" flag in all breakpoints. */
1539 mark_breakpoints_out (void)
1541 register struct breakpoint *b;
1547 /* Clear the "inserted" flag in all breakpoints and delete any
1548 breakpoints which should go away between runs of the program.
1550 Plus other such housekeeping that has to be done for breakpoints
1553 Note: this function gets called at the end of a run (by
1554 generic_mourn_inferior) and when a run begins (by
1555 init_wait_for_inferior). */
1560 breakpoint_init_inferior (enum inf_context context)
1562 register struct breakpoint *b, *temp;
1563 static int warning_needed = 0;
1565 ALL_BREAKPOINTS_SAFE (b, temp)
1572 case bp_watchpoint_scope:
1574 /* If the call dummy breakpoint is at the entry point it will
1575 cause problems when the inferior is rerun, so we better
1578 Also get rid of scope breakpoints. */
1579 delete_breakpoint (b);
1583 case bp_hardware_watchpoint:
1584 case bp_read_watchpoint:
1585 case bp_access_watchpoint:
1587 /* Likewise for watchpoints on local expressions. */
1588 if (b->exp_valid_block != NULL)
1589 delete_breakpoint (b);
1590 if (context == inf_starting)
1592 /* Reset val field to force reread of starting value
1593 in insert_breakpoints. */
1595 value_free (b->val);
1600 /* Likewise for exception catchpoints in dynamic-linked
1601 executables where required */
1602 if (ep_is_exception_catchpoint (b) &&
1603 exception_catchpoints_are_fragile)
1606 delete_breakpoint (b);
1612 if (exception_catchpoints_are_fragile)
1613 exception_support_initialized = 0;
1615 /* Don't issue the warning unless it's really needed... */
1616 if (warning_needed && (context != inf_exited))
1618 warning ("Exception catchpoints from last run were deleted.");
1619 warning ("You must reinsert them explicitly.");
1624 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1625 exists at PC. It returns ordinary_breakpoint_here if it's an
1626 ordinary breakpoint, or permanent_breakpoint_here if it's a
1627 permanent breakpoint.
1628 - When continuing from a location with an ordinary breakpoint, we
1629 actually single step once before calling insert_breakpoints.
1630 - When continuing from a localion with a permanent breakpoint, we
1631 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1632 the target, to advance the PC past the breakpoint. */
1634 enum breakpoint_here
1635 breakpoint_here_p (CORE_ADDR pc)
1637 register struct breakpoint *b;
1638 int any_breakpoint_here = 0;
1641 if ((b->enable_state == bp_enabled
1642 || b->enable_state == bp_permanent)
1643 && b->address == pc) /* bp is enabled and matches pc */
1645 if (overlay_debugging
1646 && section_is_overlay (b->section)
1647 && !section_is_mapped (b->section))
1648 continue; /* unmapped overlay -- can't be a match */
1649 else if (b->enable_state == bp_permanent)
1650 return permanent_breakpoint_here;
1652 any_breakpoint_here = 1;
1655 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1659 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1660 but it only returns true if there is actually a breakpoint inserted
1664 breakpoint_inserted_here_p (CORE_ADDR pc)
1666 register struct breakpoint *b;
1670 && b->address == pc) /* bp is inserted and matches pc */
1672 if (overlay_debugging
1673 && section_is_overlay (b->section)
1674 && !section_is_mapped (b->section))
1675 continue; /* unmapped overlay -- can't be a match */
1683 /* Return nonzero if FRAME is a dummy frame. We can't use
1684 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1685 much time, at least using get_saved_register on the 68k. This
1686 means that for this function to work right a port must use the
1687 bp_call_dummy breakpoint. */
1690 frame_in_dummy (struct frame_info *frame)
1692 struct breakpoint *b;
1697 if (USE_GENERIC_DUMMY_FRAMES)
1698 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1702 if (b->type == bp_call_dummy
1703 && b->frame == frame->frame
1704 /* We need to check the PC as well as the frame on the sparc,
1705 for signals.exp in the testsuite. */
1708 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1709 && frame->pc <= b->address)
1715 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1716 PC is valid for process/thread PID. */
1719 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1721 struct breakpoint *b;
1724 thread = pid_to_thread_id (ptid);
1727 if (b->enable_state != bp_disabled
1728 && b->enable_state != bp_shlib_disabled
1729 && b->enable_state != bp_call_disabled
1731 && (b->thread == -1 || b->thread == thread))
1733 if (overlay_debugging
1734 && section_is_overlay (b->section)
1735 && !section_is_mapped (b->section))
1736 continue; /* unmapped overlay -- can't be a match */
1745 /* bpstat stuff. External routines' interfaces are documented
1749 ep_is_catchpoint (struct breakpoint *ep)
1752 (ep->type == bp_catch_load)
1753 || (ep->type == bp_catch_unload)
1754 || (ep->type == bp_catch_fork)
1755 || (ep->type == bp_catch_vfork)
1756 || (ep->type == bp_catch_exec)
1757 || (ep->type == bp_catch_catch)
1758 || (ep->type == bp_catch_throw);
1760 /* ??rehrauer: Add more kinds here, as are implemented... */
1764 ep_is_shlib_catchpoint (struct breakpoint *ep)
1767 (ep->type == bp_catch_load)
1768 || (ep->type == bp_catch_unload);
1772 ep_is_exception_catchpoint (struct breakpoint *ep)
1775 (ep->type == bp_catch_catch)
1776 || (ep->type == bp_catch_throw);
1779 /* Clear a bpstat so that it says we are not at any breakpoint.
1780 Also free any storage that is part of a bpstat. */
1783 bpstat_clear (bpstat *bsp)
1794 if (p->old_val != NULL)
1795 value_free (p->old_val);
1796 free_command_lines (&p->commands);
1803 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1804 is part of the bpstat is copied as well. */
1807 bpstat_copy (bpstat bs)
1811 bpstat retval = NULL;
1816 for (; bs != NULL; bs = bs->next)
1818 tmp = (bpstat) xmalloc (sizeof (*tmp));
1819 memcpy (tmp, bs, sizeof (*tmp));
1821 /* This is the first thing in the chain. */
1831 /* Find the bpstat associated with this breakpoint */
1834 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1839 for (; bsp != NULL; bsp = bsp->next)
1841 if (bsp->breakpoint_at == breakpoint)
1847 /* Find a step_resume breakpoint associated with this bpstat.
1848 (If there are multiple step_resume bp's on the list, this function
1849 will arbitrarily pick one.)
1851 It is an error to use this function if BPSTAT doesn't contain a
1852 step_resume breakpoint.
1854 See wait_for_inferior's use of this function. */
1856 bpstat_find_step_resume_breakpoint (bpstat bsp)
1861 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1863 current_thread = pid_to_thread_id (inferior_ptid);
1865 for (; bsp != NULL; bsp = bsp->next)
1867 if ((bsp->breakpoint_at != NULL) &&
1868 (bsp->breakpoint_at->type == bp_step_resume) &&
1869 (bsp->breakpoint_at->thread == current_thread ||
1870 bsp->breakpoint_at->thread == -1))
1871 return bsp->breakpoint_at;
1874 error ("Internal error (no step_resume breakpoint found)");
1878 /* Return the breakpoint number of the first breakpoint we are stopped
1879 at. *BSP upon return is a bpstat which points to the remaining
1880 breakpoints stopped at (but which is not guaranteed to be good for
1881 anything but further calls to bpstat_num).
1882 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1885 bpstat_num (bpstat *bsp)
1887 struct breakpoint *b;
1890 return 0; /* No more breakpoint values */
1893 b = (*bsp)->breakpoint_at;
1894 *bsp = (*bsp)->next;
1896 return -1; /* breakpoint that's been deleted since */
1898 return b->number; /* We have its number */
1902 /* Modify BS so that the actions will not be performed. */
1905 bpstat_clear_actions (bpstat bs)
1907 for (; bs != NULL; bs = bs->next)
1909 free_command_lines (&bs->commands);
1910 if (bs->old_val != NULL)
1912 value_free (bs->old_val);
1918 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1921 cleanup_executing_breakpoints (PTR ignore)
1923 executing_breakpoint_commands = 0;
1926 /* Execute all the commands associated with all the breakpoints at this
1927 location. Any of these commands could cause the process to proceed
1928 beyond this point, etc. We look out for such changes by checking
1929 the global "breakpoint_proceeded" after each command. */
1932 bpstat_do_actions (bpstat *bsp)
1935 struct cleanup *old_chain;
1936 struct command_line *cmd;
1938 /* Avoid endless recursion if a `source' command is contained
1940 if (executing_breakpoint_commands)
1943 executing_breakpoint_commands = 1;
1944 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1947 /* Note that (as of this writing), our callers all appear to
1948 be passing us the address of global stop_bpstat. And, if
1949 our calls to execute_control_command cause the inferior to
1950 proceed, that global (and hence, *bsp) will change.
1952 We must be careful to not touch *bsp unless the inferior
1953 has not proceeded. */
1955 /* This pointer will iterate over the list of bpstat's. */
1958 breakpoint_proceeded = 0;
1959 for (; bs != NULL; bs = bs->next)
1964 execute_control_command (cmd);
1966 if (breakpoint_proceeded)
1971 if (breakpoint_proceeded)
1972 /* The inferior is proceeded by the command; bomb out now.
1973 The bpstat chain has been blown away by wait_for_inferior.
1974 But since execution has stopped again, there is a new bpstat
1975 to look at, so start over. */
1978 free_command_lines (&bs->commands);
1980 do_cleanups (old_chain);
1983 /* This is the normal print function for a bpstat. In the future,
1984 much of this logic could (should?) be moved to bpstat_stop_status,
1985 by having it set different print_it values.
1987 Current scheme: When we stop, bpstat_print() is called. It loops
1988 through the bpstat list of things causing this stop, calling the
1989 print_bp_stop_message function on each one. The behavior of the
1990 print_bp_stop_message function depends on the print_it field of
1991 bpstat. If such field so indicates, call this function here.
1993 Return values from this routine (ultimately used by bpstat_print()
1994 and normal_stop() to decide what to do):
1995 PRINT_NOTHING: Means we already printed all we needed to print,
1996 don't print anything else.
1997 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1998 that something to be followed by a location.
1999 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2000 that something to be followed by a location.
2001 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2004 static enum print_stop_action
2005 print_it_typical (bpstat bs)
2007 struct cleanup *old_chain;
2008 struct ui_stream *stb;
2009 stb = ui_out_stream_new (uiout);
2010 old_chain = make_cleanup_ui_out_stream_delete (stb);
2011 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2012 which has since been deleted. */
2013 if (bs->breakpoint_at == NULL)
2014 return PRINT_UNKNOWN;
2016 switch (bs->breakpoint_at->type)
2019 case bp_hardware_breakpoint:
2020 annotate_breakpoint (bs->breakpoint_at->number);
2021 ui_out_text (uiout, "\nBreakpoint ");
2022 if (ui_out_is_mi_like_p (uiout))
2023 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2024 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2025 ui_out_text (uiout, ", ");
2026 return PRINT_SRC_AND_LOC;
2029 case bp_shlib_event:
2030 /* Did we stop because the user set the stop_on_solib_events
2031 variable? (If so, we report this as a generic, "Stopped due
2032 to shlib event" message.) */
2033 printf_filtered ("Stopped due to shared library event\n");
2034 return PRINT_NOTHING;
2037 case bp_thread_event:
2038 /* Not sure how we will get here.
2039 GDB should not stop for these breakpoints. */
2040 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2041 return PRINT_NOTHING;
2044 case bp_overlay_event:
2045 /* By analogy with the thread event, GDB should not stop for these. */
2046 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2047 return PRINT_NOTHING;
2051 annotate_catchpoint (bs->breakpoint_at->number);
2052 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2053 printf_filtered ("loaded");
2054 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2055 return PRINT_SRC_AND_LOC;
2058 case bp_catch_unload:
2059 annotate_catchpoint (bs->breakpoint_at->number);
2060 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2061 printf_filtered ("unloaded");
2062 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2063 return PRINT_SRC_AND_LOC;
2067 annotate_catchpoint (bs->breakpoint_at->number);
2068 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2069 printf_filtered ("forked");
2070 printf_filtered (" process %d), ",
2071 bs->breakpoint_at->forked_inferior_pid);
2072 return PRINT_SRC_AND_LOC;
2075 case bp_catch_vfork:
2076 annotate_catchpoint (bs->breakpoint_at->number);
2077 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2078 printf_filtered ("vforked");
2079 printf_filtered (" process %d), ",
2080 bs->breakpoint_at->forked_inferior_pid);
2081 return PRINT_SRC_AND_LOC;
2085 annotate_catchpoint (bs->breakpoint_at->number);
2086 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2087 bs->breakpoint_at->number,
2088 bs->breakpoint_at->exec_pathname);
2089 return PRINT_SRC_AND_LOC;
2092 case bp_catch_catch:
2093 if (current_exception_event &&
2094 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2096 annotate_catchpoint (bs->breakpoint_at->number);
2097 printf_filtered ("\nCatchpoint %d (exception caught), ",
2098 bs->breakpoint_at->number);
2099 printf_filtered ("throw location ");
2100 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2101 printf_filtered ("%s:%d",
2102 CURRENT_EXCEPTION_THROW_FILE,
2103 CURRENT_EXCEPTION_THROW_LINE);
2105 printf_filtered ("unknown");
2107 printf_filtered (", catch location ");
2108 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2109 printf_filtered ("%s:%d",
2110 CURRENT_EXCEPTION_CATCH_FILE,
2111 CURRENT_EXCEPTION_CATCH_LINE);
2113 printf_filtered ("unknown");
2115 printf_filtered ("\n");
2116 /* don't bother to print location frame info */
2117 return PRINT_SRC_ONLY;
2121 /* really throw, some other bpstat will handle it */
2122 return PRINT_UNKNOWN;
2126 case bp_catch_throw:
2127 if (current_exception_event &&
2128 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2130 annotate_catchpoint (bs->breakpoint_at->number);
2131 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2132 bs->breakpoint_at->number);
2133 printf_filtered ("throw location ");
2134 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2135 printf_filtered ("%s:%d",
2136 CURRENT_EXCEPTION_THROW_FILE,
2137 CURRENT_EXCEPTION_THROW_LINE);
2139 printf_filtered ("unknown");
2141 printf_filtered (", catch location ");
2142 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2143 printf_filtered ("%s:%d",
2144 CURRENT_EXCEPTION_CATCH_FILE,
2145 CURRENT_EXCEPTION_CATCH_LINE);
2147 printf_filtered ("unknown");
2149 printf_filtered ("\n");
2150 /* don't bother to print location frame info */
2151 return PRINT_SRC_ONLY;
2155 /* really catch, some other bpstat will handle it */
2156 return PRINT_UNKNOWN;
2161 case bp_hardware_watchpoint:
2162 if (bs->old_val != NULL)
2164 annotate_watchpoint (bs->breakpoint_at->number);
2165 if (ui_out_is_mi_like_p (uiout))
2166 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2167 mention (bs->breakpoint_at);
2168 ui_out_tuple_begin (uiout, "value");
2169 ui_out_text (uiout, "\nOld value = ");
2170 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2171 ui_out_field_stream (uiout, "old", stb);
2172 ui_out_text (uiout, "\nNew value = ");
2173 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2174 ui_out_field_stream (uiout, "new", stb);
2175 ui_out_tuple_end (uiout);
2176 ui_out_text (uiout, "\n");
2177 value_free (bs->old_val);
2180 /* More than one watchpoint may have been triggered. */
2181 return PRINT_UNKNOWN;
2184 case bp_read_watchpoint:
2185 if (ui_out_is_mi_like_p (uiout))
2186 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2187 mention (bs->breakpoint_at);
2188 ui_out_tuple_begin (uiout, "value");
2189 ui_out_text (uiout, "\nValue = ");
2190 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2191 ui_out_field_stream (uiout, "value", stb);
2192 ui_out_tuple_end (uiout);
2193 ui_out_text (uiout, "\n");
2194 return PRINT_UNKNOWN;
2197 case bp_access_watchpoint:
2198 if (bs->old_val != NULL)
2200 annotate_watchpoint (bs->breakpoint_at->number);
2201 if (ui_out_is_mi_like_p (uiout))
2202 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2203 mention (bs->breakpoint_at);
2204 ui_out_tuple_begin (uiout, "value");
2205 ui_out_text (uiout, "\nOld value = ");
2206 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2207 ui_out_field_stream (uiout, "old", stb);
2208 value_free (bs->old_val);
2210 ui_out_text (uiout, "\nNew value = ");
2214 mention (bs->breakpoint_at);
2215 if (ui_out_is_mi_like_p (uiout))
2216 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2217 ui_out_tuple_begin (uiout, "value");
2218 ui_out_text (uiout, "\nValue = ");
2220 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2221 ui_out_field_stream (uiout, "new", stb);
2222 ui_out_tuple_end (uiout);
2223 ui_out_text (uiout, "\n");
2224 return PRINT_UNKNOWN;
2227 /* Fall through, we don't deal with these types of breakpoints
2231 if (ui_out_is_mi_like_p (uiout))
2232 ui_out_field_string (uiout, "reason", "function-finished");
2233 return PRINT_UNKNOWN;
2237 if (ui_out_is_mi_like_p (uiout))
2238 ui_out_field_string (uiout, "reason", "location-reached");
2239 return PRINT_UNKNOWN;
2244 case bp_longjmp_resume:
2245 case bp_step_resume:
2246 case bp_through_sigtramp:
2247 case bp_watchpoint_scope:
2250 return PRINT_UNKNOWN;
2254 /* Generic routine for printing messages indicating why we
2255 stopped. The behavior of this function depends on the value
2256 'print_it' in the bpstat structure. Under some circumstances we
2257 may decide not to print anything here and delegate the task to
2260 static enum print_stop_action
2261 print_bp_stop_message (bpstat bs)
2263 switch (bs->print_it)
2266 /* Nothing should be printed for this bpstat entry. */
2267 return PRINT_UNKNOWN;
2271 /* We still want to print the frame, but we already printed the
2272 relevant messages. */
2273 return PRINT_SRC_AND_LOC;
2276 case print_it_normal:
2277 /* Normal case, we handle everything in print_it_typical. */
2278 return print_it_typical (bs);
2281 internal_error (__FILE__, __LINE__,
2282 "print_bp_stop_message: unrecognized enum value");
2287 /* Print a message indicating what happened. This is called from
2288 normal_stop(). The input to this routine is the head of the bpstat
2289 list - a list of the eventpoints that caused this stop. This
2290 routine calls the generic print routine for printing a message
2291 about reasons for stopping. This will print (for example) the
2292 "Breakpoint n," part of the output. The return value of this
2295 PRINT_UNKNOWN: Means we printed nothing
2296 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2297 code to print the location. An example is
2298 "Breakpoint 1, " which should be followed by
2300 PRINT_SRC_ONLY: Means we printed something, but there is no need
2301 to also print the location part of the message.
2302 An example is the catch/throw messages, which
2303 don't require a location appended to the end.
2304 PRINT_NOTHING: We have done some printing and we don't need any
2305 further info to be printed.*/
2307 enum print_stop_action
2308 bpstat_print (bpstat bs)
2312 /* Maybe another breakpoint in the chain caused us to stop.
2313 (Currently all watchpoints go on the bpstat whether hit or not.
2314 That probably could (should) be changed, provided care is taken
2315 with respect to bpstat_explains_signal). */
2316 for (; bs; bs = bs->next)
2318 val = print_bp_stop_message (bs);
2319 if (val == PRINT_SRC_ONLY
2320 || val == PRINT_SRC_AND_LOC
2321 || val == PRINT_NOTHING)
2325 /* We reached the end of the chain, or we got a null BS to start
2326 with and nothing was printed. */
2327 return PRINT_UNKNOWN;
2330 /* Evaluate the expression EXP and return 1 if value is zero.
2331 This is used inside a catch_errors to evaluate the breakpoint condition.
2332 The argument is a "struct expression *" that has been cast to char * to
2333 make it pass through catch_errors. */
2336 breakpoint_cond_eval (PTR exp)
2338 struct value *mark = value_mark ();
2339 int i = !value_true (evaluate_expression ((struct expression *) exp));
2340 value_free_to_mark (mark);
2344 /* Allocate a new bpstat and chain it to the current one. */
2347 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2351 bs = (bpstat) xmalloc (sizeof (*bs));
2353 bs->breakpoint_at = b;
2354 /* If the condition is false, etc., don't do the commands. */
2355 bs->commands = NULL;
2357 bs->print_it = print_it_normal;
2361 /* Possible return values for watchpoint_check (this can't be an enum
2362 because of check_errors). */
2363 /* The watchpoint has been deleted. */
2364 #define WP_DELETED 1
2365 /* The value has changed. */
2366 #define WP_VALUE_CHANGED 2
2367 /* The value has not changed. */
2368 #define WP_VALUE_NOT_CHANGED 3
2370 #define BP_TEMPFLAG 1
2371 #define BP_HARDWAREFLAG 2
2373 /* Check watchpoint condition. */
2376 watchpoint_check (PTR p)
2378 bpstat bs = (bpstat) p;
2379 struct breakpoint *b;
2380 struct frame_info *fr;
2381 int within_current_scope;
2383 b = bs->breakpoint_at;
2385 if (b->exp_valid_block == NULL)
2386 within_current_scope = 1;
2389 /* There is no current frame at this moment. If we're going to have
2390 any chance of handling watchpoints on local variables, we'll need
2391 the frame chain (so we can determine if we're in scope). */
2392 reinit_frame_cache ();
2393 fr = frame_find_by_id (b->watchpoint_frame);
2394 within_current_scope = (fr != NULL);
2395 /* in_function_epilogue_p() returns a non-zero value if we're still
2396 in the function but the stack frame has already been invalidated.
2397 Since we can't rely on the values of local variables after the
2398 stack has been destroyed, we are treating the watchpoint in that
2399 state as `not changed' without further checking. */
2400 if (within_current_scope && fr == get_current_frame ()
2401 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2402 return WP_VALUE_NOT_CHANGED;
2403 if (within_current_scope)
2404 /* If we end up stopping, the current frame will get selected
2405 in normal_stop. So this call to select_frame won't affect
2410 if (within_current_scope)
2412 /* We use value_{,free_to_}mark because it could be a
2413 *long* time before we return to the command level and
2414 call free_all_values. We can't call free_all_values because
2415 we might be in the middle of evaluating a function call. */
2417 struct value *mark = value_mark ();
2418 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2419 if (!value_equal (b->val, new_val))
2421 release_value (new_val);
2422 value_free_to_mark (mark);
2423 bs->old_val = b->val;
2425 /* We will stop here */
2426 return WP_VALUE_CHANGED;
2430 /* Nothing changed, don't do anything. */
2431 value_free_to_mark (mark);
2432 /* We won't stop here */
2433 return WP_VALUE_NOT_CHANGED;
2438 /* This seems like the only logical thing to do because
2439 if we temporarily ignored the watchpoint, then when
2440 we reenter the block in which it is valid it contains
2441 garbage (in the case of a function, it may have two
2442 garbage values, one before and one after the prologue).
2443 So we can't even detect the first assignment to it and
2444 watch after that (since the garbage may or may not equal
2445 the first value assigned). */
2446 /* We print all the stop information in print_it_typical(), but
2447 in this case, by the time we call print_it_typical() this bp
2448 will be deleted already. So we have no choice but print the
2449 information here. */
2450 if (ui_out_is_mi_like_p (uiout))
2451 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2452 ui_out_text (uiout, "\nWatchpoint ");
2453 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2454 ui_out_text (uiout, " deleted because the program has left the block in\n\
2455 which its expression is valid.\n");
2457 if (b->related_breakpoint)
2458 b->related_breakpoint->disposition = disp_del_at_next_stop;
2459 b->disposition = disp_del_at_next_stop;
2465 /* Get a bpstat associated with having just stopped at address *PC
2466 and frame address CORE_ADDRESS. Update *PC to point at the
2467 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2468 if this is known to not be a real breakpoint (it could still be a
2469 watchpoint, though). */
2471 /* Determine whether we stopped at a breakpoint, etc, or whether we
2472 don't understand this stop. Result is a chain of bpstat's such that:
2474 if we don't understand the stop, the result is a null pointer.
2476 if we understand why we stopped, the result is not null.
2478 Each element of the chain refers to a particular breakpoint or
2479 watchpoint at which we have stopped. (We may have stopped for
2480 several reasons concurrently.)
2482 Each element of the chain has valid next, breakpoint_at,
2483 commands, FIXME??? fields. */
2486 bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
2488 register struct breakpoint *b, *temp;
2490 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2491 int real_breakpoint = 0;
2492 /* Root of the chain of bpstat's */
2493 struct bpstats root_bs[1];
2494 /* Pointer to the last thing in the chain currently. */
2495 bpstat bs = root_bs;
2496 static char message1[] =
2497 "Error evaluating expression for watchpoint %d\n";
2498 char message[sizeof (message1) + 30 /* slop */ ];
2500 /* Get the address where the breakpoint would have been. The
2501 "not_a_sw_breakpoint" argument is meant to distinguish between a
2502 breakpoint trap event and a trace/singlestep trap event. For a
2503 trace/singlestep trap event, we would not want to subtract
2504 DECR_PC_AFTER_BREAK from the PC. */
2506 bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK);
2508 ALL_BREAKPOINTS_SAFE (b, temp)
2510 if (b->enable_state == bp_disabled
2511 || b->enable_state == bp_shlib_disabled
2512 || b->enable_state == bp_call_disabled)
2515 if (b->type != bp_watchpoint
2516 && b->type != bp_hardware_watchpoint
2517 && b->type != bp_read_watchpoint
2518 && b->type != bp_access_watchpoint
2519 && b->type != bp_hardware_breakpoint
2520 && b->type != bp_catch_fork
2521 && b->type != bp_catch_vfork
2522 && b->type != bp_catch_exec
2523 && b->type != bp_catch_catch
2524 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2526 if (b->address != bp_addr) /* address doesn't match */
2528 if (overlay_debugging /* unmapped overlay section */
2529 && section_is_overlay (b->section)
2530 && !section_is_mapped (b->section))
2534 if (b->type == bp_hardware_breakpoint)
2536 if (b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2538 if (overlay_debugging /* unmapped overlay section */
2539 && section_is_overlay (b->section)
2540 && !section_is_mapped (b->section))
2544 /* Is this a catchpoint of a load or unload? If so, did we
2545 get a load or unload of the specified library? If not,
2547 if ((b->type == bp_catch_load)
2548 #if defined(SOLIB_HAVE_LOAD_EVENT)
2549 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2550 || ((b->dll_pathname != NULL)
2551 && (strcmp (b->dll_pathname,
2552 SOLIB_LOADED_LIBRARY_PATHNAME (
2553 PIDGET (inferior_ptid)))
2559 if ((b->type == bp_catch_unload)
2560 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2561 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2562 || ((b->dll_pathname != NULL)
2563 && (strcmp (b->dll_pathname,
2564 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2565 PIDGET (inferior_ptid)))
2571 if ((b->type == bp_catch_fork)
2572 && !target_has_forked (PIDGET (inferior_ptid),
2573 &b->forked_inferior_pid))
2576 if ((b->type == bp_catch_vfork)
2577 && !target_has_vforked (PIDGET (inferior_ptid),
2578 &b->forked_inferior_pid))
2581 if ((b->type == bp_catch_exec)
2582 && !target_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2585 if (ep_is_exception_catchpoint (b) &&
2586 !(current_exception_event = target_get_current_exception_event ()))
2589 /* Come here if it's a watchpoint, or if the break address matches */
2591 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2593 /* Watchpoints may change this, if not found to have triggered. */
2597 sprintf (message, message1, b->number);
2598 if (b->type == bp_watchpoint ||
2599 b->type == bp_hardware_watchpoint)
2601 switch (catch_errors (watchpoint_check, bs, message,
2605 /* We've already printed what needs to be printed. */
2606 /* Actually this is superfluous, because by the time we
2607 call print_it_typical() the wp will be already deleted,
2608 and the function will return immediately. */
2609 bs->print_it = print_it_done;
2612 case WP_VALUE_CHANGED:
2616 case WP_VALUE_NOT_CHANGED:
2618 bs->print_it = print_it_noop;
2625 /* Error from catch_errors. */
2626 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2627 if (b->related_breakpoint)
2628 b->related_breakpoint->disposition = disp_del_at_next_stop;
2629 b->disposition = disp_del_at_next_stop;
2630 /* We've already printed what needs to be printed. */
2631 bs->print_it = print_it_done;
2637 else if (b->type == bp_read_watchpoint ||
2638 b->type == bp_access_watchpoint)
2644 addr = target_stopped_data_address ();
2647 for (v = b->val_chain; v; v = v->next)
2649 if (VALUE_LVAL (v) == lval_memory
2650 && ! VALUE_LAZY (v))
2652 struct type *vtype = check_typedef (VALUE_TYPE (v));
2654 if (v == b->val_chain
2655 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2656 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2660 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2661 /* Exact match not required. Within range is
2663 if (addr >= vaddr &&
2664 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2670 switch (catch_errors (watchpoint_check, bs, message,
2674 /* We've already printed what needs to be printed. */
2675 bs->print_it = print_it_done;
2678 case WP_VALUE_CHANGED:
2679 if (b->type == bp_read_watchpoint)
2681 /* Don't stop: read watchpoints shouldn't fire if
2682 the value has changed. This is for targets which
2683 cannot set read-only watchpoints. */
2684 bs->print_it = print_it_noop;
2690 case WP_VALUE_NOT_CHANGED:
2697 /* Error from catch_errors. */
2698 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2699 if (b->related_breakpoint)
2700 b->related_breakpoint->disposition = disp_del_at_next_stop;
2701 b->disposition = disp_del_at_next_stop;
2702 /* We've already printed what needs to be printed. */
2703 bs->print_it = print_it_done;
2706 else /* found == 0 */
2708 /* This is a case where some watchpoint(s) triggered,
2709 but not at the address of this watchpoint (FOUND
2710 was left zero). So don't print anything for this
2712 bs->print_it = print_it_noop;
2719 /* By definition, an encountered breakpoint is a triggered
2723 real_breakpoint = 1;
2727 b->frame != (get_current_frame ())->frame)
2731 int value_is_zero = 0;
2735 /* Need to select the frame, with all that implies
2736 so that the conditions will have the right context. */
2737 select_frame (get_current_frame ());
2739 = catch_errors (breakpoint_cond_eval, (b->cond),
2740 "Error in testing breakpoint condition:\n",
2742 /* FIXME-someday, should give breakpoint # */
2745 if (b->cond && value_is_zero)
2748 /* Don't consider this a hit. */
2751 else if (b->ignore_count > 0)
2754 annotate_ignore_count_change ();
2759 /* We will stop here */
2760 if (b->disposition == disp_disable)
2761 b->enable_state = bp_disabled;
2762 bs->commands = copy_command_lines (b->commands);
2766 (STREQ ("silent", bs->commands->line) ||
2767 (xdb_commands && STREQ ("Q", bs->commands->line))))
2769 bs->commands = bs->commands->next;
2774 /* Print nothing for this entry if we dont stop or if we dont print. */
2775 if (bs->stop == 0 || bs->print == 0)
2776 bs->print_it = print_it_noop;
2779 bs->next = NULL; /* Terminate the chain */
2780 bs = root_bs->next; /* Re-grab the head of the chain */
2782 if (real_breakpoint && bs)
2784 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2786 if (DECR_PC_AFTER_HW_BREAK != 0)
2788 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2794 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2797 #if defined (SHIFT_INST_REGS)
2799 #else /* No SHIFT_INST_REGS. */
2801 #endif /* No SHIFT_INST_REGS. */
2806 /* The value of a hardware watchpoint hasn't changed, but the
2807 intermediate memory locations we are watching may have. */
2808 if (bs && !bs->stop &&
2809 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2810 bs->breakpoint_at->type == bp_read_watchpoint ||
2811 bs->breakpoint_at->type == bp_access_watchpoint))
2813 remove_breakpoints ();
2814 insert_breakpoints ();
2819 /* Tell what to do about this bpstat. */
2821 bpstat_what (bpstat bs)
2823 /* Classify each bpstat as one of the following. */
2826 /* This bpstat element has no effect on the main_action. */
2829 /* There was a watchpoint, stop but don't print. */
2832 /* There was a watchpoint, stop and print. */
2835 /* There was a breakpoint but we're not stopping. */
2838 /* There was a breakpoint, stop but don't print. */
2841 /* There was a breakpoint, stop and print. */
2844 /* We hit the longjmp breakpoint. */
2847 /* We hit the longjmp_resume breakpoint. */
2850 /* We hit the step_resume breakpoint. */
2853 /* We hit the through_sigtramp breakpoint. */
2856 /* We hit the shared library event breakpoint. */
2859 /* We caught a shared library event. */
2862 /* This is just used to count how many enums there are. */
2866 /* Here is the table which drives this routine. So that we can
2867 format it pretty, we define some abbreviations for the
2868 enum bpstat_what codes. */
2869 #define kc BPSTAT_WHAT_KEEP_CHECKING
2870 #define ss BPSTAT_WHAT_STOP_SILENT
2871 #define sn BPSTAT_WHAT_STOP_NOISY
2872 #define sgl BPSTAT_WHAT_SINGLE
2873 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2874 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2875 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2876 #define sr BPSTAT_WHAT_STEP_RESUME
2877 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2878 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2879 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2881 /* "Can't happen." Might want to print an error message.
2882 abort() is not out of the question, but chances are GDB is just
2883 a bit confused, not unusable. */
2884 #define err BPSTAT_WHAT_STOP_NOISY
2886 /* Given an old action and a class, come up with a new action. */
2887 /* One interesting property of this table is that wp_silent is the same
2888 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2889 after stopping, the check for whether to step over a breakpoint
2890 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2891 reference to how we stopped. We retain separate wp_silent and
2892 bp_silent codes in case we want to change that someday.
2894 Another possibly interesting property of this table is that
2895 there's a partial ordering, priority-like, of the actions. Once
2896 you've decided that some action is appropriate, you'll never go
2897 back and decide something of a lower priority is better. The
2900 kc < clr sgl shl shlr slr sn sr ss ts
2901 sgl < clrs shl shlr slr sn sr ss ts
2902 slr < err shl shlr sn sr ss ts
2903 clr < clrs err shl shlr sn sr ss ts
2904 clrs < err shl shlr sn sr ss ts
2905 ss < shl shlr sn sr ts
2912 What I think this means is that we don't need a damned table
2913 here. If you just put the rows and columns in the right order,
2914 it'd look awfully regular. We could simply walk the bpstat list
2915 and choose the highest priority action we find, with a little
2916 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2917 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2918 is messy anyway). */
2920 /* step_resume entries: a step resume breakpoint overrides another
2921 breakpoint of signal handling (see comment in wait_for_inferior
2922 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2923 /* We handle the through_sigtramp_breakpoint the same way; having both
2924 one of those and a step_resume_breakpoint is probably very rare (?). */
2926 static const enum bpstat_what_main_action
2927 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2930 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2933 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2935 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2937 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2939 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2941 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2943 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2945 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2947 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2949 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2951 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2953 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2955 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2970 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2971 struct bpstat_what retval;
2973 retval.call_dummy = 0;
2974 for (; bs != NULL; bs = bs->next)
2976 enum class bs_class = no_effect;
2977 if (bs->breakpoint_at == NULL)
2978 /* I suspect this can happen if it was a momentary breakpoint
2979 which has since been deleted. */
2981 switch (bs->breakpoint_at->type)
2987 case bp_hardware_breakpoint:
2993 bs_class = bp_noisy;
2995 bs_class = bp_silent;
2998 bs_class = bp_nostop;
3001 case bp_hardware_watchpoint:
3002 case bp_read_watchpoint:
3003 case bp_access_watchpoint:
3007 bs_class = wp_noisy;
3009 bs_class = wp_silent;
3012 /* There was a watchpoint, but we're not stopping.
3013 This requires no further action. */
3014 bs_class = no_effect;
3017 bs_class = long_jump;
3019 case bp_longjmp_resume:
3020 bs_class = long_resume;
3022 case bp_step_resume:
3025 bs_class = step_resume;
3028 /* It is for the wrong frame. */
3029 bs_class = bp_nostop;
3031 case bp_through_sigtramp:
3032 bs_class = through_sig;
3034 case bp_watchpoint_scope:
3035 bs_class = bp_nostop;
3037 case bp_shlib_event:
3038 bs_class = shlib_event;
3040 case bp_thread_event:
3041 case bp_overlay_event:
3042 bs_class = bp_nostop;
3045 case bp_catch_unload:
3046 /* Only if this catchpoint triggered should we cause the
3047 step-out-of-dld behaviour. Otherwise, we ignore this
3050 bs_class = catch_shlib_event;
3052 bs_class = no_effect;
3055 case bp_catch_vfork:
3060 bs_class = bp_noisy;
3062 bs_class = bp_silent;
3065 /* There was a catchpoint, but we're not stopping.
3066 This requires no further action. */
3067 bs_class = no_effect;
3069 case bp_catch_catch:
3070 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3071 bs_class = bp_nostop;
3073 bs_class = bs->print ? bp_noisy : bp_silent;
3075 case bp_catch_throw:
3076 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3077 bs_class = bp_nostop;
3079 bs_class = bs->print ? bp_noisy : bp_silent;
3082 /* Make sure the action is stop (silent or noisy),
3083 so infrun.c pops the dummy frame. */
3084 bs_class = bp_silent;
3085 retval.call_dummy = 1;
3088 current_action = table[(int) bs_class][(int) current_action];
3090 retval.main_action = current_action;
3094 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3095 without hardware support). This isn't related to a specific bpstat,
3096 just to things like whether watchpoints are set. */
3099 bpstat_should_step (void)
3101 struct breakpoint *b;
3103 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3108 /* Nonzero if there are enabled hardware watchpoints. */
3110 bpstat_have_active_hw_watchpoints (void)
3112 struct breakpoint *b;
3114 if ((b->enable_state == bp_enabled) &&
3116 ((b->type == bp_hardware_watchpoint) ||
3117 (b->type == bp_read_watchpoint) ||
3118 (b->type == bp_access_watchpoint)))
3124 /* Given a bpstat that records zero or more triggered eventpoints, this
3125 function returns another bpstat which contains only the catchpoints
3126 on that first list, if any. */
3128 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3130 struct bpstats root_bs[1];
3131 bpstat bs = root_bs;
3132 struct breakpoint *ep;
3135 bpstat_clear (cp_list);
3136 root_bs->next = NULL;
3138 for (; ep_list != NULL; ep_list = ep_list->next)
3140 /* Is this eventpoint a catchpoint? If not, ignore it. */
3141 ep = ep_list->breakpoint_at;
3144 if ((ep->type != bp_catch_load) &&
3145 (ep->type != bp_catch_unload) &&
3146 (ep->type != bp_catch_catch) &&
3147 (ep->type != bp_catch_throw))
3148 /* pai: (temp) ADD fork/vfork here!! */
3151 /* Yes; add it to the list. */
3152 bs = bpstat_alloc (ep, bs);
3157 #if defined(SOLIB_ADD)
3158 /* Also, for each triggered catchpoint, tag it with the name of
3159 the library that caused this trigger. (We copy the name now,
3160 because it's only guaranteed to be available NOW, when the
3161 catchpoint triggers. Clients who may wish to know the name
3162 later must get it from the catchpoint itself.) */
3163 if (ep->triggered_dll_pathname != NULL)
3164 xfree (ep->triggered_dll_pathname);
3165 if (ep->type == bp_catch_load)
3166 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3167 PIDGET (inferior_ptid));
3169 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3170 PIDGET (inferior_ptid));
3172 dll_pathname = NULL;
3176 ep->triggered_dll_pathname = (char *)
3177 xmalloc (strlen (dll_pathname) + 1);
3178 strcpy (ep->triggered_dll_pathname, dll_pathname);
3181 ep->triggered_dll_pathname = NULL;
3187 /* Print B to gdb_stdout. */
3189 print_one_breakpoint (struct breakpoint *b,
3190 CORE_ADDR *last_addr)
3192 register struct command_line *l;
3193 register struct symbol *sym;
3194 struct ep_type_description
3199 static struct ep_type_description bptypes[] =
3201 {bp_none, "?deleted?"},
3202 {bp_breakpoint, "breakpoint"},
3203 {bp_hardware_breakpoint, "hw breakpoint"},
3204 {bp_until, "until"},
3205 {bp_finish, "finish"},
3206 {bp_watchpoint, "watchpoint"},
3207 {bp_hardware_watchpoint, "hw watchpoint"},
3208 {bp_read_watchpoint, "read watchpoint"},
3209 {bp_access_watchpoint, "acc watchpoint"},
3210 {bp_longjmp, "longjmp"},
3211 {bp_longjmp_resume, "longjmp resume"},
3212 {bp_step_resume, "step resume"},
3213 {bp_through_sigtramp, "sigtramp"},
3214 {bp_watchpoint_scope, "watchpoint scope"},
3215 {bp_call_dummy, "call dummy"},
3216 {bp_shlib_event, "shlib events"},
3217 {bp_thread_event, "thread events"},
3218 {bp_overlay_event, "overlay events"},
3219 {bp_catch_load, "catch load"},
3220 {bp_catch_unload, "catch unload"},
3221 {bp_catch_fork, "catch fork"},
3222 {bp_catch_vfork, "catch vfork"},
3223 {bp_catch_exec, "catch exec"},
3224 {bp_catch_catch, "catch catch"},
3225 {bp_catch_throw, "catch throw"}
3228 static char *bpdisps[] =
3229 {"del", "dstp", "dis", "keep"};
3230 static char bpenables[] = "nynny";
3231 char wrap_indent[80];
3232 struct ui_stream *stb = ui_out_stream_new (uiout);
3233 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3236 ui_out_tuple_begin (uiout, "bkpt");
3240 ui_out_field_int (uiout, "number", b->number);
3244 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3245 || ((int) b->type != bptypes[(int) b->type].type))
3246 internal_error (__FILE__, __LINE__,
3247 "bptypes table does not describe type #%d.",
3249 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3253 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3257 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3258 ui_out_spaces (uiout, 2);
3261 strcpy (wrap_indent, " ");
3264 if (TARGET_ADDR_BIT <= 32)
3265 strcat (wrap_indent, " ");
3267 strcat (wrap_indent, " ");
3272 internal_error (__FILE__, __LINE__,
3273 "print_one_breakpoint: bp_none encountered\n");
3277 case bp_hardware_watchpoint:
3278 case bp_read_watchpoint:
3279 case bp_access_watchpoint:
3280 /* Field 4, the address, is omitted (which makes the columns
3281 not line up too nicely with the headers, but the effect
3282 is relatively readable). */
3284 ui_out_field_skip (uiout, "addr");
3286 print_expression (b->exp, stb->stream);
3287 ui_out_field_stream (uiout, "what", stb);
3291 case bp_catch_unload:
3292 /* Field 4, the address, is omitted (which makes the columns
3293 not line up too nicely with the headers, but the effect
3294 is relatively readable). */
3296 ui_out_field_skip (uiout, "addr");
3298 if (b->dll_pathname == NULL)
3300 ui_out_field_string (uiout, "what", "<any library>");
3301 ui_out_spaces (uiout, 1);
3305 ui_out_text (uiout, "library \"");
3306 ui_out_field_string (uiout, "what", b->dll_pathname);
3307 ui_out_text (uiout, "\" ");
3312 case bp_catch_vfork:
3313 /* Field 4, the address, is omitted (which makes the columns
3314 not line up too nicely with the headers, but the effect
3315 is relatively readable). */
3317 ui_out_field_skip (uiout, "addr");
3319 if (b->forked_inferior_pid != 0)
3321 ui_out_text (uiout, "process ");
3322 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3323 ui_out_spaces (uiout, 1);
3327 /* Field 4, the address, is omitted (which makes the columns
3328 not line up too nicely with the headers, but the effect
3329 is relatively readable). */
3331 ui_out_field_skip (uiout, "addr");
3333 if (b->exec_pathname != NULL)
3335 ui_out_text (uiout, "program \"");
3336 ui_out_field_string (uiout, "what", b->exec_pathname);
3337 ui_out_text (uiout, "\" ");
3341 case bp_catch_catch:
3342 /* Field 4, the address, is omitted (which makes the columns
3343 not line up too nicely with the headers, but the effect
3344 is relatively readable). */
3346 ui_out_field_skip (uiout, "addr");
3348 ui_out_field_string (uiout, "what", "exception catch");
3349 ui_out_spaces (uiout, 1);
3352 case bp_catch_throw:
3353 /* Field 4, the address, is omitted (which makes the columns
3354 not line up too nicely with the headers, but the effect
3355 is relatively readable). */
3357 ui_out_field_skip (uiout, "addr");
3359 ui_out_field_string (uiout, "what", "exception throw");
3360 ui_out_spaces (uiout, 1);
3364 case bp_hardware_breakpoint:
3368 case bp_longjmp_resume:
3369 case bp_step_resume:
3370 case bp_through_sigtramp:
3371 case bp_watchpoint_scope:
3373 case bp_shlib_event:
3374 case bp_thread_event:
3375 case bp_overlay_event:
3379 ui_out_field_core_addr (uiout, "addr", b->address);
3382 *last_addr = b->address;
3385 sym = find_pc_sect_function (b->address, b->section);
3388 ui_out_text (uiout, "in ");
3389 ui_out_field_string (uiout, "func",
3390 SYMBOL_SOURCE_NAME (sym));
3391 ui_out_wrap_hint (uiout, wrap_indent);
3392 ui_out_text (uiout, " at ");
3394 ui_out_field_string (uiout, "file", b->source_file);
3395 ui_out_text (uiout, ":");
3396 ui_out_field_int (uiout, "line", b->line_number);
3400 print_address_symbolic (b->address, stb->stream, demangle, "");
3401 ui_out_field_stream (uiout, "at", stb);
3406 if (b->thread != -1)
3408 /* FIXME: This seems to be redundant and lost here; see the
3409 "stop only in" line a little further down. */
3410 ui_out_text (uiout, " thread ");
3411 ui_out_field_int (uiout, "thread", b->thread);
3414 ui_out_text (uiout, "\n");
3419 ui_out_text (uiout, "\tstop only in stack frame at ");
3420 ui_out_field_core_addr (uiout, "frame", b->frame);
3421 ui_out_text (uiout, "\n");
3427 ui_out_text (uiout, "\tstop only if ");
3428 print_expression (b->cond, stb->stream);
3429 ui_out_field_stream (uiout, "cond", stb);
3430 ui_out_text (uiout, "\n");
3433 if (b->thread != -1)
3435 /* FIXME should make an annotation for this */
3436 ui_out_text (uiout, "\tstop only in thread ");
3437 ui_out_field_int (uiout, "thread", b->thread);
3438 ui_out_text (uiout, "\n");
3441 if (show_breakpoint_hit_counts && b->hit_count)
3443 /* FIXME should make an annotation for this */
3444 if (ep_is_catchpoint (b))
3445 ui_out_text (uiout, "\tcatchpoint");
3447 ui_out_text (uiout, "\tbreakpoint");
3448 ui_out_text (uiout, " already hit ");
3449 ui_out_field_int (uiout, "times", b->hit_count);
3450 if (b->hit_count == 1)
3451 ui_out_text (uiout, " time\n");
3453 ui_out_text (uiout, " times\n");
3456 /* Output the count also if it is zero, but only if this is
3457 mi. FIXME: Should have a better test for this. */
3458 if (ui_out_is_mi_like_p (uiout))
3459 if (show_breakpoint_hit_counts && b->hit_count == 0)
3460 ui_out_field_int (uiout, "times", b->hit_count);
3462 if (b->ignore_count)
3465 ui_out_text (uiout, "\tignore next ");
3466 ui_out_field_int (uiout, "ignore", b->ignore_count);
3467 ui_out_text (uiout, " hits\n");
3470 if ((l = b->commands))
3473 ui_out_tuple_begin (uiout, "script");
3474 print_command_lines (uiout, l, 4);
3475 ui_out_tuple_end (uiout);
3477 ui_out_tuple_end (uiout);
3478 do_cleanups (old_chain);
3481 struct captured_breakpoint_query_args
3487 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3489 struct captured_breakpoint_query_args *args = data;
3490 register struct breakpoint *b;
3491 CORE_ADDR dummy_addr = 0;
3494 if (args->bnum == b->number)
3496 print_one_breakpoint (b, &dummy_addr);
3504 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3506 struct captured_breakpoint_query_args args;
3508 /* For the moment we don't trust print_one_breakpoint() to not throw
3510 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3511 NULL, RETURN_MASK_ALL);
3514 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3515 catchpoints, et.al.). */
3518 user_settable_breakpoint (const struct breakpoint *b)
3520 return (b->type == bp_breakpoint
3521 || b->type == bp_catch_load
3522 || b->type == bp_catch_unload
3523 || b->type == bp_catch_fork
3524 || b->type == bp_catch_vfork
3525 || b->type == bp_catch_exec
3526 || b->type == bp_catch_catch
3527 || b->type == bp_catch_throw
3528 || b->type == bp_hardware_breakpoint
3529 || b->type == bp_watchpoint
3530 || b->type == bp_read_watchpoint
3531 || b->type == bp_access_watchpoint
3532 || b->type == bp_hardware_watchpoint);
3535 /* Print information on user settable breakpoint (watchpoint, etc)
3536 number BNUM. If BNUM is -1 print all user settable breakpoints.
3537 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3540 breakpoint_1 (int bnum, int allflag)
3542 register struct breakpoint *b;
3543 CORE_ADDR last_addr = (CORE_ADDR) -1;
3544 int nr_printable_breakpoints;
3546 /* Compute the number of rows in the table. */
3547 nr_printable_breakpoints = 0;
3550 || bnum == b->number)
3552 if (allflag || user_settable_breakpoint (b))
3553 nr_printable_breakpoints++;
3557 ui_out_table_begin (uiout, 6, nr_printable_breakpoints, "BreakpointTable");
3559 ui_out_table_begin (uiout, 5, nr_printable_breakpoints, "BreakpointTable");
3561 if (nr_printable_breakpoints > 0)
3562 annotate_breakpoints_headers ();
3563 if (nr_printable_breakpoints > 0)
3565 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3566 if (nr_printable_breakpoints > 0)
3568 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3569 if (nr_printable_breakpoints > 0)
3571 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3572 if (nr_printable_breakpoints > 0)
3574 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3577 if (nr_printable_breakpoints > 0)
3579 if (TARGET_ADDR_BIT <= 32)
3580 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3582 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3584 if (nr_printable_breakpoints > 0)
3586 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3587 ui_out_table_body (uiout);
3588 if (nr_printable_breakpoints > 0)
3589 annotate_breakpoints_table ();
3593 || bnum == b->number)
3595 /* We only print out user settable breakpoints unless the
3597 if (allflag || user_settable_breakpoint (b))
3598 print_one_breakpoint (b, &last_addr);
3601 ui_out_table_end (uiout);
3603 if (nr_printable_breakpoints == 0)
3606 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3608 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3613 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3614 that a comparison of an unsigned with -1 is always false. */
3615 if (last_addr != (CORE_ADDR) -1)
3616 set_next_address (last_addr);
3619 /* FIXME? Should this be moved up so that it is only called when
3620 there have been breakpoints? */
3621 annotate_breakpoints_table_end ();
3626 breakpoints_info (char *bnum_exp, int from_tty)
3631 bnum = parse_and_eval_long (bnum_exp);
3633 breakpoint_1 (bnum, 0);
3638 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3643 bnum = parse_and_eval_long (bnum_exp);
3645 breakpoint_1 (bnum, 1);
3648 /* Print a message describing any breakpoints set at PC. */
3651 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3653 register int others = 0;
3654 register struct breakpoint *b;
3657 if (b->address == pc) /* address match / overlay match */
3658 if (!overlay_debugging || b->section == section)
3662 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3664 if (b->address == pc) /* address match / overlay match */
3665 if (!overlay_debugging || b->section == section)
3668 printf_filtered ("%d%s%s ",
3670 ((b->enable_state == bp_disabled ||
3671 b->enable_state == bp_shlib_disabled ||
3672 b->enable_state == bp_call_disabled)
3674 : b->enable_state == bp_permanent
3678 : ((others == 1) ? " and" : ""));
3680 printf_filtered ("also set at pc ");
3681 print_address_numeric (pc, 1, gdb_stdout);
3682 printf_filtered (".\n");
3686 /* Set the default place to put a breakpoint
3687 for the `break' command with no arguments. */
3690 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3693 default_breakpoint_valid = valid;
3694 default_breakpoint_address = addr;
3695 default_breakpoint_symtab = symtab;
3696 default_breakpoint_line = line;
3699 /* Return true iff it is meaningful to use the address member of
3700 BPT. For some breakpoint types, the address member is irrelevant
3701 and it makes no sense to attempt to compare it to other addresses
3702 (or use it for any other purpose either).
3704 More specifically, each of the following breakpoint types will always
3705 have a zero valued address and we don't want check_duplicates() to mark
3706 breakpoints of any of these types to be a duplicate of an actual
3707 breakpoint at address zero:
3710 bp_hardware_watchpoint
3712 bp_access_watchpoint
3719 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3721 enum bptype type = bpt->type;
3723 return (type != bp_watchpoint
3724 && type != bp_hardware_watchpoint
3725 && type != bp_read_watchpoint
3726 && type != bp_access_watchpoint
3727 && type != bp_catch_exec
3728 && type != bp_longjmp_resume
3729 && type != bp_catch_fork
3730 && type != bp_catch_vfork);
3733 /* Rescan breakpoints at the same address and section as BPT,
3734 marking the first one as "first" and any others as "duplicates".
3735 This is so that the bpt instruction is only inserted once.
3736 If we have a permanent breakpoint at the same place as BPT, make
3737 that one the official one, and the rest as duplicates. */
3740 check_duplicates (struct breakpoint *bpt)
3742 register struct breakpoint *b;
3743 register int count = 0;
3744 struct breakpoint *perm_bp = 0;
3745 CORE_ADDR address = bpt->address;
3746 asection *section = bpt->section;
3748 if (! breakpoint_address_is_meaningful (bpt))
3752 if (b->enable_state != bp_disabled
3753 && b->enable_state != bp_shlib_disabled
3754 && b->enable_state != bp_call_disabled
3755 && b->address == address /* address / overlay match */
3756 && (!overlay_debugging || b->section == section)
3757 && breakpoint_address_is_meaningful (b))
3759 /* Have we found a permanent breakpoint? */
3760 if (b->enable_state == bp_permanent)
3767 b->duplicate = count > 1;
3770 /* If we found a permanent breakpoint at this address, go over the
3771 list again and declare all the other breakpoints there to be the
3775 perm_bp->duplicate = 0;
3777 /* Permanent breakpoint should always be inserted. */
3778 if (! perm_bp->inserted)
3779 internal_error (__FILE__, __LINE__,
3780 "allegedly permanent breakpoint is not "
3781 "actually inserted");
3787 internal_error (__FILE__, __LINE__,
3788 "another breakpoint was inserted on top of "
3789 "a permanent breakpoint");
3791 if (b->enable_state != bp_disabled
3792 && b->enable_state != bp_shlib_disabled
3793 && b->enable_state != bp_call_disabled
3794 && b->address == address /* address / overlay match */
3795 && (!overlay_debugging || b->section == section)
3796 && breakpoint_address_is_meaningful (b))
3802 /* set_raw_breakpoint() is a low level routine for allocating and
3803 partially initializing a breakpoint of type BPTYPE. The newly
3804 created breakpoint's address, section, source file name, and line
3805 number are provided by SAL. The newly created and partially
3806 initialized breakpoint is added to the breakpoint chain and
3807 is also returned as the value of this function.
3809 It is expected that the caller will complete the initialization of
3810 the newly created breakpoint struct as well as output any status
3811 information regarding the creation of a new breakpoint. In
3812 particular, set_raw_breakpoint() does NOT set the breakpoint
3813 number! Care should be taken to not allow an error() to occur
3814 prior to completing the initialization of the breakpoint. If this
3815 should happen, a bogus breakpoint will be left on the chain. */
3818 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3820 register struct breakpoint *b, *b1;
3822 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3823 memset (b, 0, sizeof (*b));
3824 b->address = sal.pc;
3825 if (sal.symtab == NULL)
3826 b->source_file = NULL;
3828 b->source_file = savestring (sal.symtab->filename,
3829 strlen (sal.symtab->filename));
3830 b->section = sal.section;
3832 b->language = current_language->la_language;
3833 b->input_radix = input_radix;
3835 b->line_number = sal.line;
3836 b->enable_state = bp_enabled;
3839 b->ignore_count = 0;
3842 b->dll_pathname = NULL;
3843 b->triggered_dll_pathname = NULL;
3844 b->forked_inferior_pid = 0;
3845 b->exec_pathname = NULL;
3847 /* Add this breakpoint to the end of the chain
3848 so that a list of breakpoints will come out in order
3849 of increasing numbers. */
3851 b1 = breakpoint_chain;
3853 breakpoint_chain = b;
3861 check_duplicates (b);
3862 breakpoints_changed ();
3868 /* Note that the breakpoint object B describes a permanent breakpoint
3869 instruction, hard-wired into the inferior's code. */
3871 make_breakpoint_permanent (struct breakpoint *b)
3873 b->enable_state = bp_permanent;
3875 /* By definition, permanent breakpoints are already present in the code. */
3879 static struct breakpoint *
3880 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
3882 static int internal_breakpoint_number = -1;
3883 struct symtab_and_line sal;
3884 struct breakpoint *b;
3886 INIT_SAL (&sal); /* initialize to zeroes */
3889 sal.section = find_pc_overlay (sal.pc);
3891 b = set_raw_breakpoint (sal, type);
3892 b->number = internal_breakpoint_number--;
3893 b->disposition = disp_donttouch;
3900 create_longjmp_breakpoint (char *func_name)
3902 struct breakpoint *b;
3903 struct minimal_symbol *m;
3905 if (func_name == NULL)
3906 b = create_internal_breakpoint (0, bp_longjmp_resume);
3909 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3912 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
3915 b->enable_state = bp_disabled;
3918 b->addr_string = xstrdup (func_name);
3921 /* Call this routine when stepping and nexting to enable a breakpoint
3922 if we do a longjmp(). When we hit that breakpoint, call
3923 set_longjmp_resume_breakpoint() to figure out where we are going. */
3926 enable_longjmp_breakpoint (void)
3928 register struct breakpoint *b;
3931 if (b->type == bp_longjmp)
3933 b->enable_state = bp_enabled;
3934 check_duplicates (b);
3939 disable_longjmp_breakpoint (void)
3941 register struct breakpoint *b;
3944 if (b->type == bp_longjmp
3945 || b->type == bp_longjmp_resume)
3947 b->enable_state = bp_disabled;
3948 check_duplicates (b);
3953 create_overlay_event_breakpoint (char *func_name)
3955 struct breakpoint *b;
3956 struct minimal_symbol *m;
3958 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3961 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
3963 b->addr_string = xstrdup (func_name);
3965 if (overlay_debugging == ovly_auto)
3967 b->enable_state = bp_enabled;
3968 overlay_events_enabled = 1;
3972 b->enable_state = bp_disabled;
3973 overlay_events_enabled = 0;
3978 enable_overlay_breakpoints (void)
3980 register struct breakpoint *b;
3983 if (b->type == bp_overlay_event)
3985 b->enable_state = bp_enabled;
3986 check_duplicates (b);
3987 overlay_events_enabled = 1;
3992 disable_overlay_breakpoints (void)
3994 register struct breakpoint *b;
3997 if (b->type == bp_overlay_event)
3999 b->enable_state = bp_disabled;
4000 check_duplicates (b);
4001 overlay_events_enabled = 0;
4006 create_thread_event_breakpoint (CORE_ADDR address)
4008 struct breakpoint *b;
4009 char addr_string[80]; /* Surely an addr can't be longer than that. */
4011 b = create_internal_breakpoint (address, bp_thread_event);
4013 b->enable_state = bp_enabled;
4014 /* addr_string has to be used or breakpoint_re_set will delete me. */
4015 sprintf (addr_string, "*0x%s", paddr (b->address));
4016 b->addr_string = xstrdup (addr_string);
4022 remove_thread_event_breakpoints (void)
4024 struct breakpoint *b, *temp;
4026 ALL_BREAKPOINTS_SAFE (b, temp)
4027 if (b->type == bp_thread_event)
4028 delete_breakpoint (b);
4033 remove_solib_event_breakpoints (void)
4035 register struct breakpoint *b, *temp;
4037 ALL_BREAKPOINTS_SAFE (b, temp)
4038 if (b->type == bp_shlib_event)
4039 delete_breakpoint (b);
4043 create_solib_event_breakpoint (CORE_ADDR address)
4045 struct breakpoint *b;
4047 b = create_internal_breakpoint (address, bp_shlib_event);
4051 /* Disable any breakpoints that are on code in shared libraries. Only
4052 apply to enabled breakpoints, disabled ones can just stay disabled. */
4055 disable_breakpoints_in_shlibs (int silent)
4057 struct breakpoint *b;
4058 int disabled_shlib_breaks = 0;
4060 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4063 #if defined (PC_SOLIB)
4064 if (((b->type == bp_breakpoint) ||
4065 (b->type == bp_hardware_breakpoint)) &&
4066 b->enable_state == bp_enabled &&
4068 PC_SOLIB (b->address))
4070 b->enable_state = bp_shlib_disabled;
4073 if (!disabled_shlib_breaks)
4075 target_terminal_ours_for_output ();
4076 warning ("Temporarily disabling shared library breakpoints:");
4078 disabled_shlib_breaks = 1;
4079 warning ("breakpoint #%d ", b->number);
4086 /* Try to reenable any breakpoints in shared libraries. */
4088 re_enable_breakpoints_in_shlibs (void)
4090 struct breakpoint *b;
4093 if (b->enable_state == bp_shlib_disabled)
4097 /* Do not reenable the breakpoint if the shared library
4098 is still not mapped in. */
4099 if (target_read_memory (b->address, buf, 1) == 0)
4100 b->enable_state = bp_enabled;
4107 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4108 char *cond_string, enum bptype bp_kind)
4110 struct breakpoint *b;
4111 struct symtabs_and_lines sals;
4112 struct cleanup *old_chain;
4113 struct cleanup *canonical_strings_chain = NULL;
4114 char *addr_start = hookname;
4115 char *addr_end = NULL;
4116 char **canonical = (char **) NULL;
4117 int thread = -1; /* All threads. */
4119 /* Set a breakpoint on the specified hook. */
4120 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4121 addr_end = hookname;
4123 if (sals.nelts == 0)
4125 warning ("Unable to set a breakpoint on dynamic linker callback.");
4126 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4127 warning ("GDB will be unable to track shl_load/shl_unload calls");
4130 if (sals.nelts != 1)
4132 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4133 warning ("GDB will be unable to track shl_load/shl_unload calls");
4137 /* Make sure that all storage allocated in decode_line_1 gets freed
4138 in case the following errors out. */
4139 old_chain = make_cleanup (xfree, sals.sals);
4140 if (canonical != (char **) NULL)
4142 make_cleanup (xfree, canonical);
4143 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4144 if (canonical[0] != NULL)
4145 make_cleanup (xfree, canonical[0]);
4148 resolve_sal_pc (&sals.sals[0]);
4150 /* Remove the canonical strings from the cleanup, they are needed below. */
4151 if (canonical != (char **) NULL)
4152 discard_cleanups (canonical_strings_chain);
4154 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4155 set_breakpoint_count (breakpoint_count + 1);
4156 b->number = breakpoint_count;
4158 b->cond_string = (cond_string == NULL) ?
4159 NULL : savestring (cond_string, strlen (cond_string));
4162 if (canonical != (char **) NULL && canonical[0] != NULL)
4163 b->addr_string = canonical[0];
4164 else if (addr_start)
4165 b->addr_string = savestring (addr_start, addr_end - addr_start);
4167 b->enable_state = bp_enabled;
4168 b->disposition = tempflag ? disp_del : disp_donttouch;
4170 if (dll_pathname == NULL)
4171 b->dll_pathname = NULL;
4174 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4175 strcpy (b->dll_pathname, dll_pathname);
4179 do_cleanups (old_chain);
4183 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4184 char *dll_pathname, char *cond_string)
4186 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4187 cond_string, bp_catch_load);
4191 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4192 char *dll_pathname, char *cond_string)
4194 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4195 cond_string, bp_catch_unload);
4199 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4200 enum bptype bp_kind)
4202 struct symtab_and_line sal;
4203 struct breakpoint *b;
4204 int thread = -1; /* All threads. */
4211 b = set_raw_breakpoint (sal, bp_kind);
4212 set_breakpoint_count (breakpoint_count + 1);
4213 b->number = breakpoint_count;
4215 b->cond_string = (cond_string == NULL) ?
4216 NULL : savestring (cond_string, strlen (cond_string));
4218 b->addr_string = NULL;
4219 b->enable_state = bp_enabled;
4220 b->disposition = tempflag ? disp_del : disp_donttouch;
4221 b->forked_inferior_pid = 0;
4227 create_fork_event_catchpoint (int tempflag, char *cond_string)
4229 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4233 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4235 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4239 create_exec_event_catchpoint (int tempflag, char *cond_string)
4241 struct symtab_and_line sal;
4242 struct breakpoint *b;
4243 int thread = -1; /* All threads. */
4250 b = set_raw_breakpoint (sal, bp_catch_exec);
4251 set_breakpoint_count (breakpoint_count + 1);
4252 b->number = breakpoint_count;
4254 b->cond_string = (cond_string == NULL) ?
4255 NULL : savestring (cond_string, strlen (cond_string));
4257 b->addr_string = NULL;
4258 b->enable_state = bp_enabled;
4259 b->disposition = tempflag ? disp_del : disp_donttouch;
4265 hw_breakpoint_used_count (void)
4267 register struct breakpoint *b;
4272 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4280 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4282 register struct breakpoint *b;
4285 *other_type_used = 0;
4288 if (b->enable_state == bp_enabled)
4290 if (b->type == type)
4292 else if ((b->type == bp_hardware_watchpoint ||
4293 b->type == bp_read_watchpoint ||
4294 b->type == bp_access_watchpoint)
4295 && b->enable_state == bp_enabled)
4296 *other_type_used = 1;
4302 /* Call this after hitting the longjmp() breakpoint. Use this to set
4303 a new breakpoint at the target of the jmp_buf.
4305 FIXME - This ought to be done by setting a temporary breakpoint
4306 that gets deleted automatically... */
4309 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
4311 register struct breakpoint *b;
4314 if (b->type == bp_longjmp_resume)
4317 b->enable_state = bp_enabled;
4319 b->frame = frame->frame;
4322 check_duplicates (b);
4328 disable_watchpoints_before_interactive_call_start (void)
4330 struct breakpoint *b;
4334 if (((b->type == bp_watchpoint)
4335 || (b->type == bp_hardware_watchpoint)
4336 || (b->type == bp_read_watchpoint)
4337 || (b->type == bp_access_watchpoint)
4338 || ep_is_exception_catchpoint (b))
4339 && (b->enable_state == bp_enabled))
4341 b->enable_state = bp_call_disabled;
4342 check_duplicates (b);
4348 enable_watchpoints_after_interactive_call_stop (void)
4350 struct breakpoint *b;
4354 if (((b->type == bp_watchpoint)
4355 || (b->type == bp_hardware_watchpoint)
4356 || (b->type == bp_read_watchpoint)
4357 || (b->type == bp_access_watchpoint)
4358 || ep_is_exception_catchpoint (b))
4359 && (b->enable_state == bp_call_disabled))
4361 b->enable_state = bp_enabled;
4362 check_duplicates (b);
4368 /* Set a breakpoint that will evaporate an end of command
4369 at address specified by SAL.
4370 Restrict it to frame FRAME if FRAME is nonzero. */
4373 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4376 register struct breakpoint *b;
4377 b = set_raw_breakpoint (sal, type);
4378 b->enable_state = bp_enabled;
4379 b->disposition = disp_donttouch;
4380 b->frame = (frame ? frame->frame : 0);
4382 /* If we're debugging a multi-threaded program, then we
4383 want momentary breakpoints to be active in only a
4384 single thread of control. */
4385 if (in_thread_list (inferior_ptid))
4386 b->thread = pid_to_thread_id (inferior_ptid);
4392 /* Tell the user we have just set a breakpoint B. */
4395 mention (struct breakpoint *b)
4398 struct cleanup *old_chain;
4399 struct ui_stream *stb;
4401 stb = ui_out_stream_new (uiout);
4402 old_chain = make_cleanup_ui_out_stream_delete (stb);
4404 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4405 watchpoint) other than breakpoint creation. It should be possible to
4406 clean this up and at the same time replace the random calls to
4407 breakpoint_changed with this hook, as has already been done for
4408 delete_breakpoint_hook and so on. */
4409 if (create_breakpoint_hook)
4410 create_breakpoint_hook (b);
4411 breakpoint_create_event (b->number);
4416 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4419 ui_out_text (uiout, "Watchpoint ");
4420 ui_out_tuple_begin (uiout, "wpt");
4421 ui_out_field_int (uiout, "number", b->number);
4422 ui_out_text (uiout, ": ");
4423 print_expression (b->exp, stb->stream);
4424 ui_out_field_stream (uiout, "exp", stb);
4425 ui_out_tuple_end (uiout);
4427 case bp_hardware_watchpoint:
4428 ui_out_text (uiout, "Hardware watchpoint ");
4429 ui_out_tuple_begin (uiout, "wpt");
4430 ui_out_field_int (uiout, "number", b->number);
4431 ui_out_text (uiout, ": ");
4432 print_expression (b->exp, stb->stream);
4433 ui_out_field_stream (uiout, "exp", stb);
4434 ui_out_tuple_end (uiout);
4436 case bp_read_watchpoint:
4437 ui_out_text (uiout, "Hardware read watchpoint ");
4438 ui_out_tuple_begin (uiout, "hw-rwpt");
4439 ui_out_field_int (uiout, "number", b->number);
4440 ui_out_text (uiout, ": ");
4441 print_expression (b->exp, stb->stream);
4442 ui_out_field_stream (uiout, "exp", stb);
4443 ui_out_tuple_end (uiout);
4445 case bp_access_watchpoint:
4446 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4447 ui_out_tuple_begin (uiout, "hw-awpt");
4448 ui_out_field_int (uiout, "number", b->number);
4449 ui_out_text (uiout, ": ");
4450 print_expression (b->exp, stb->stream);
4451 ui_out_field_stream (uiout, "exp", stb);
4452 ui_out_tuple_end (uiout);
4455 if (ui_out_is_mi_like_p (uiout))
4460 printf_filtered ("Breakpoint %d", b->number);
4463 case bp_hardware_breakpoint:
4464 if (ui_out_is_mi_like_p (uiout))
4469 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4473 case bp_catch_unload:
4474 printf_filtered ("Catchpoint %d (%s %s)",
4476 (b->type == bp_catch_load) ? "load" : "unload",
4477 (b->dll_pathname != NULL) ?
4478 b->dll_pathname : "<any library>");
4481 case bp_catch_vfork:
4482 printf_filtered ("Catchpoint %d (%s)",
4484 (b->type == bp_catch_fork) ? "fork" : "vfork");
4487 printf_filtered ("Catchpoint %d (exec)",
4490 case bp_catch_catch:
4491 case bp_catch_throw:
4492 printf_filtered ("Catchpoint %d (%s)",
4494 (b->type == bp_catch_catch) ? "catch" : "throw");
4500 case bp_longjmp_resume:
4501 case bp_step_resume:
4502 case bp_through_sigtramp:
4504 case bp_watchpoint_scope:
4505 case bp_shlib_event:
4506 case bp_thread_event:
4507 case bp_overlay_event:
4512 if (addressprint || b->source_file == NULL)
4514 printf_filtered (" at ");
4515 print_address_numeric (b->address, 1, gdb_stdout);
4518 printf_filtered (": file %s, line %d.",
4519 b->source_file, b->line_number);
4521 do_cleanups (old_chain);
4522 if (ui_out_is_mi_like_p (uiout))
4524 printf_filtered ("\n");
4528 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4529 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4530 COND[i] and COND_STRING[i] values.
4532 NOTE: If the function succeeds, the caller is expected to cleanup
4533 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4534 array contents). If the function fails (error() is called), the
4535 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4536 COND and SALS arrays and each of those arrays contents. */
4539 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4540 struct expression **cond, char **cond_string,
4541 enum bptype type, enum bpdisp disposition,
4542 int thread, int ignore_count, int from_tty)
4544 if (type == bp_hardware_breakpoint)
4546 int i = hw_breakpoint_used_count ();
4547 int target_resources_ok =
4548 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4550 if (target_resources_ok == 0)
4551 error ("No hardware breakpoint support in the target.");
4552 else if (target_resources_ok < 0)
4553 error ("Hardware breakpoints used exceeds limit.");
4556 /* Now set all the breakpoints. */
4559 for (i = 0; i < sals.nelts; i++)
4561 struct breakpoint *b;
4562 struct symtab_and_line sal = sals.sals[i];
4565 describe_other_breakpoints (sal.pc, sal.section);
4567 b = set_raw_breakpoint (sal, type);
4568 set_breakpoint_count (breakpoint_count + 1);
4569 b->number = breakpoint_count;
4572 b->addr_string = addr_string[i];
4573 b->cond_string = cond_string[i];
4574 b->ignore_count = ignore_count;
4575 b->enable_state = bp_enabled;
4576 b->disposition = disposition;
4582 /* Parse ARG which is assumed to be a SAL specification possibly
4583 followed by conditionals. On return, SALS contains an array of SAL
4584 addresses found. ADDR_STRING contains a vector of (canonical)
4585 address strings. ARG points to the end of the SAL. */
4588 parse_breakpoint_sals (char **address,
4589 struct symtabs_and_lines *sals,
4590 char ***addr_string)
4592 char *addr_start = *address;
4593 *addr_string = NULL;
4594 /* If no arg given, or if first arg is 'if ', use the default
4596 if ((*address) == NULL
4597 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4599 if (default_breakpoint_valid)
4601 struct symtab_and_line sal;
4602 INIT_SAL (&sal); /* initialize to zeroes */
4603 sals->sals = (struct symtab_and_line *)
4604 xmalloc (sizeof (struct symtab_and_line));
4605 sal.pc = default_breakpoint_address;
4606 sal.line = default_breakpoint_line;
4607 sal.symtab = default_breakpoint_symtab;
4608 sal.section = find_pc_overlay (sal.pc);
4609 sals->sals[0] = sal;
4613 error ("No default breakpoint address now.");
4617 /* Force almost all breakpoints to be in terms of the
4618 current_source_symtab (which is decode_line_1's default). This
4619 should produce the results we want almost all of the time while
4620 leaving default_breakpoint_* alone. */
4621 if (default_breakpoint_valid
4622 && (!current_source_symtab
4623 || (strchr ("+-", (*address)[0]) != NULL)))
4624 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4625 default_breakpoint_line, addr_string);
4627 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4629 /* For any SAL that didn't have a canonical string, fill one in. */
4630 if (sals->nelts > 0 && *addr_string == NULL)
4631 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4632 if (addr_start != (*address))
4635 for (i = 0; i < sals->nelts; i++)
4637 /* Add the string if not present. */
4638 if ((*addr_string)[i] == NULL)
4639 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4645 /* Convert each SAL into a real PC. Verify that the PC can be
4646 inserted as a breakpoint. If it can't throw an error. */
4649 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4653 for (i = 0; i < sals->nelts; i++)
4655 resolve_sal_pc (&sals->sals[i]);
4657 /* It's possible for the PC to be nonzero, but still an illegal
4658 value on some targets.
4660 For example, on HP-UX if you start gdb, and before running the
4661 inferior you try to set a breakpoint on a shared library function
4662 "foo" where the inferior doesn't call "foo" directly but does
4663 pass its address to another function call, then we do find a
4664 minimal symbol for the "foo", but it's address is invalid.
4665 (Appears to be an index into a table that the loader sets up
4666 when the inferior is run.)
4668 Give the target a chance to bless sals.sals[i].pc before we
4669 try to make a breakpoint for it. */
4670 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4672 if (address == NULL)
4673 error ("Cannot break without a running program.");
4675 error ("Cannot break on %s without a running program.",
4681 /* Set a breakpoint according to ARG (function, linenum or *address)
4682 flag: first bit : 0 non-temporary, 1 temporary.
4683 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4686 break_command_1 (char *arg, int flag, int from_tty)
4688 int tempflag, hardwareflag;
4689 struct symtabs_and_lines sals;
4690 register struct expression **cond = 0;
4691 /* Pointers in arg to the start, and one past the end, of the
4693 char **cond_string = (char **) NULL;
4694 char *addr_start = arg;
4696 struct cleanup *old_chain;
4697 struct cleanup *breakpoint_chain = NULL;
4700 int ignore_count = 0;
4702 hardwareflag = flag & BP_HARDWAREFLAG;
4703 tempflag = flag & BP_TEMPFLAG;
4708 parse_breakpoint_sals (&arg, &sals, &addr_string);
4713 /* Create a chain of things that always need to be cleaned up. */
4714 old_chain = make_cleanup (null_cleanup, 0);
4716 /* Make sure that all storage allocated to SALS gets freed. */
4717 make_cleanup (xfree, sals.sals);
4719 /* Cleanup the addr_string array but not its contents. */
4720 make_cleanup (xfree, addr_string);
4722 /* Allocate space for all the cond expressions. */
4723 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4724 make_cleanup (xfree, cond);
4726 /* Allocate space for all the cond strings. */
4727 cond_string = xcalloc (sals.nelts, sizeof (char **));
4728 make_cleanup (xfree, cond_string);
4730 /* ----------------------------- SNIP -----------------------------
4731 Anything added to the cleanup chain beyond this point is assumed
4732 to be part of a breakpoint. If the breakpoint create succeeds
4733 then the memory is not reclaimed. */
4734 breakpoint_chain = make_cleanup (null_cleanup, 0);
4736 /* Mark the contents of the addr_string for cleanup. These go on
4737 the breakpoint_chain and only occure if the breakpoint create
4739 for (i = 0; i < sals.nelts; i++)
4741 if (addr_string[i] != NULL)
4742 make_cleanup (xfree, addr_string[i]);
4745 /* Resolve all line numbers to PC's and verify that the addresses
4746 are ok for the target. */
4747 breakpoint_sals_to_pc (&sals, addr_start);
4749 /* Verify that condition can be parsed, before setting any
4750 breakpoints. Allocate a separate condition expression for each
4752 thread = -1; /* No specific thread yet */
4753 for (i = 0; i < sals.nelts; i++)
4760 char *cond_start = NULL;
4761 char *cond_end = NULL;
4762 while (*tok == ' ' || *tok == '\t')
4767 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4770 toklen = end_tok - tok;
4772 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4774 tok = cond_start = end_tok + 1;
4775 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4776 make_cleanup (xfree, cond[i]);
4778 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4779 make_cleanup (xfree, cond_string[i]);
4781 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4787 thread = strtol (tok, &tok, 0);
4789 error ("Junk after thread keyword.");
4790 if (!valid_thread_id (thread))
4791 error ("Unknown thread %d\n", thread);
4794 error ("Junk at end of arguments.");
4798 create_breakpoints (sals, addr_string, cond, cond_string,
4799 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4800 tempflag ? disp_del : disp_donttouch,
4801 thread, ignore_count, from_tty);
4805 warning ("Multiple breakpoints were set.");
4806 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4808 /* That's it. Discard the cleanups for data inserted into the
4810 discard_cleanups (breakpoint_chain);
4811 /* But cleanup everything else. */
4812 do_cleanups (old_chain);
4815 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4816 linenum or *address) with COND and IGNORE_COUNT. */
4818 struct captured_breakpoint_args
4829 do_captured_breakpoint (void *data)
4831 struct captured_breakpoint_args *args = data;
4832 struct symtabs_and_lines sals;
4833 register struct expression **cond;
4834 struct cleanup *old_chain;
4835 struct cleanup *breakpoint_chain = NULL;
4842 /* Parse the source and lines spec. Delay check that the expression
4843 didn't contain trailing garbage until after cleanups are in
4847 address_end = args->address;
4849 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4854 /* Create a chain of things at always need to be cleaned up. */
4855 old_chain = make_cleanup (null_cleanup, 0);
4857 /* Always have a addr_string array, even if it is empty. */
4858 make_cleanup (xfree, addr_string);
4860 /* Make sure that all storage allocated to SALS gets freed. */
4861 make_cleanup (xfree, sals.sals);
4863 /* Allocate space for all the cond expressions. */
4864 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4865 make_cleanup (xfree, cond);
4867 /* Allocate space for all the cond strings. */
4868 cond_string = xcalloc (sals.nelts, sizeof (char **));
4869 make_cleanup (xfree, cond_string);
4871 /* ----------------------------- SNIP -----------------------------
4872 Anything added to the cleanup chain beyond this point is assumed
4873 to be part of a breakpoint. If the breakpoint create goes
4874 through then that memory is not cleaned up. */
4875 breakpoint_chain = make_cleanup (null_cleanup, 0);
4877 /* Mark the contents of the addr_string for cleanup. These go on
4878 the breakpoint_chain and only occure if the breakpoint create
4880 for (i = 0; i < sals.nelts; i++)
4882 if (addr_string[i] != NULL)
4883 make_cleanup (xfree, addr_string[i]);
4886 /* Wait until now before checking for garbage at the end of the
4887 address. That way cleanups can take care of freeing any
4889 if (*address_end != '\0')
4890 error ("Garbage %s following breakpoint address", address_end);
4892 /* Resolve all line numbers to PC's. */
4893 breakpoint_sals_to_pc (&sals, args->address);
4895 /* Verify that conditions can be parsed, before setting any
4897 for (i = 0; i < sals.nelts; i++)
4899 if (args->condition != NULL)
4901 char *tok = args->condition;
4902 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4904 error ("Garbage %s follows condition", tok);
4905 make_cleanup (xfree, cond[i]);
4906 cond_string[i] = xstrdup (args->condition);
4910 create_breakpoints (sals, addr_string, cond, cond_string,
4911 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4912 args->tempflag ? disp_del : disp_donttouch,
4913 args->thread, args->ignore_count, 0/*from-tty*/);
4915 /* That's it. Discard the cleanups for data inserted into the
4917 discard_cleanups (breakpoint_chain);
4918 /* But cleanup everything else. */
4919 do_cleanups (old_chain);
4924 gdb_breakpoint (char *address, char *condition,
4925 int hardwareflag, int tempflag,
4926 int thread, int ignore_count)
4928 struct captured_breakpoint_args args;
4929 args.address = address;
4930 args.condition = condition;
4931 args.hardwareflag = hardwareflag;
4932 args.tempflag = tempflag;
4933 args.thread = thread;
4934 args.ignore_count = ignore_count;
4935 return catch_errors (do_captured_breakpoint, &args,
4936 NULL, RETURN_MASK_ALL);
4941 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4943 struct frame_info *frame;
4944 CORE_ADDR low, high, selected_pc = 0;
4945 char *extra_args = NULL;
4948 int extra_args_len = 0, if_arg = 0;
4951 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4954 if (default_breakpoint_valid)
4958 selected_pc = selected_frame->pc;
4963 error ("No selected frame.");
4966 error ("No default breakpoint address now.");
4970 extra_args = strchr (arg, ' ');
4974 extra_args_len = strlen (extra_args);
4975 level_arg = (char *) xmalloc (extra_args - arg);
4976 strncpy (level_arg, arg, extra_args - arg - 1);
4977 level_arg[extra_args - arg - 1] = '\0';
4981 level_arg = (char *) xmalloc (strlen (arg) + 1);
4982 strcpy (level_arg, arg);
4985 frame = parse_frame_specification (level_arg);
4987 selected_pc = frame->pc;
4994 extra_args_len = strlen (arg);
4999 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5001 addr_string = (char *) xmalloc (26 + extra_args_len);
5003 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
5005 sprintf (addr_string, "*0x%s", paddr_nz (high));
5006 break_command_1 (addr_string, flag, from_tty);
5007 xfree (addr_string);
5010 error ("No function contains the specified address");
5013 error ("Unable to set breakpoint at procedure exit");
5018 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5020 char *addr_string, *break_string, *beg_addr_string;
5021 CORE_ADDR low, high;
5022 struct symtabs_and_lines sals;
5023 struct symtab_and_line sal;
5024 struct cleanup *old_chain;
5025 char *extra_args = NULL;
5026 int extra_args_len = 0;
5030 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5032 if (default_breakpoint_valid)
5036 addr_string = (char *) xmalloc (15);
5037 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5042 error ("No selected frame.");
5045 error ("No default breakpoint address now.");
5049 addr_string = (char *) xmalloc (strlen (arg) + 1);
5050 strcpy (addr_string, arg);
5056 extra_args_len = strlen (arg);
5060 /* get the stuff after the function name or address */
5061 extra_args = strchr (arg, ' ');
5065 extra_args_len = strlen (extra_args);
5072 beg_addr_string = addr_string;
5073 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5076 xfree (beg_addr_string);
5077 old_chain = make_cleanup (xfree, sals.sals);
5078 for (i = 0; (i < sals.nelts); i++)
5081 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5083 break_string = (char *) xmalloc (extra_args_len + 26);
5085 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5087 sprintf (break_string, "*0x%s", paddr_nz (high));
5088 break_command_1 (break_string, flag, from_tty);
5089 xfree (break_string);
5092 error ("No function contains the specified address");
5096 warning ("Multiple breakpoints were set.\n");
5097 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5099 do_cleanups (old_chain);
5103 /* Helper function for break_command_1 and disassemble_command. */
5106 resolve_sal_pc (struct symtab_and_line *sal)
5110 if (sal->pc == 0 && sal->symtab != NULL)
5112 if (!find_line_pc (sal->symtab, sal->line, &pc))
5113 error ("No line %d in file \"%s\".",
5114 sal->line, sal->symtab->filename);
5118 if (sal->section == 0 && sal->symtab != NULL)
5120 struct blockvector *bv;
5125 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5128 b = BLOCKVECTOR_BLOCK (bv, index);
5129 sym = block_function (b);
5132 fixup_symbol_section (sym, sal->symtab->objfile);
5133 sal->section = SYMBOL_BFD_SECTION (sym);
5137 /* It really is worthwhile to have the section, so we'll just
5138 have to look harder. This case can be executed if we have
5139 line numbers but no functions (as can happen in assembly
5142 struct minimal_symbol *msym;
5144 msym = lookup_minimal_symbol_by_pc (sal->pc);
5146 sal->section = SYMBOL_BFD_SECTION (msym);
5153 break_command (char *arg, int from_tty)
5155 break_command_1 (arg, 0, from_tty);
5159 break_at_finish_command (char *arg, int from_tty)
5161 break_at_finish_command_1 (arg, 0, from_tty);
5165 break_at_finish_at_depth_command (char *arg, int from_tty)
5167 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5171 tbreak_command (char *arg, int from_tty)
5173 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5177 tbreak_at_finish_command (char *arg, int from_tty)
5179 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5183 hbreak_command (char *arg, int from_tty)
5185 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5189 thbreak_command (char *arg, int from_tty)
5191 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5195 stop_command (char *arg, int from_tty)
5197 printf_filtered ("Specify the type of breakpoint to set.\n\
5198 Usage: stop in <function | address>\n\
5203 stopin_command (char *arg, int from_tty)
5207 if (arg == (char *) NULL)
5209 else if (*arg != '*')
5214 /* look for a ':'. If this is a line number specification, then
5215 say it is bad, otherwise, it should be an address or
5216 function/method name */
5217 while (*argptr && !hasColon)
5219 hasColon = (*argptr == ':');
5224 badInput = (*argptr != ':'); /* Not a class::method */
5226 badInput = isdigit (*arg); /* a simple line number */
5230 printf_filtered ("Usage: stop in <function | address>\n");
5232 break_command_1 (arg, 0, from_tty);
5236 stopat_command (char *arg, int from_tty)
5240 if (arg == (char *) NULL || *arg == '*') /* no line number */
5247 /* look for a ':'. If there is a '::' then get out, otherwise
5248 it is probably a line number. */
5249 while (*argptr && !hasColon)
5251 hasColon = (*argptr == ':');
5256 badInput = (*argptr == ':'); /* we have class::method */
5258 badInput = !isdigit (*arg); /* not a line number */
5262 printf_filtered ("Usage: stop at <line>\n");
5264 break_command_1 (arg, 0, from_tty);
5268 /* accessflag: hw_write: watch write,
5269 hw_read: watch read,
5270 hw_access: watch access (read or write) */
5272 watch_command_1 (char *arg, int accessflag, int from_tty)
5274 struct breakpoint *b;
5275 struct symtab_and_line sal;
5276 struct expression *exp;
5277 struct block *exp_valid_block;
5278 struct value *val, *mark;
5279 struct frame_info *frame;
5280 struct frame_info *prev_frame = NULL;
5281 char *exp_start = NULL;
5282 char *exp_end = NULL;
5283 char *tok, *end_tok;
5285 char *cond_start = NULL;
5286 char *cond_end = NULL;
5287 struct expression *cond = NULL;
5288 int i, other_type_used, target_resources_ok = 0;
5289 enum bptype bp_type;
5292 INIT_SAL (&sal); /* initialize to zeroes */
5294 /* Parse arguments. */
5295 innermost_block = NULL;
5297 exp = parse_exp_1 (&arg, 0, 0);
5299 exp_valid_block = innermost_block;
5300 mark = value_mark ();
5301 val = evaluate_expression (exp);
5302 release_value (val);
5303 if (VALUE_LAZY (val))
5304 value_fetch_lazy (val);
5307 while (*tok == ' ' || *tok == '\t')
5311 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5314 toklen = end_tok - tok;
5315 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5317 tok = cond_start = end_tok + 1;
5318 cond = parse_exp_1 (&tok, 0, 0);
5322 error ("Junk at end of command.");
5324 if (accessflag == hw_read)
5325 bp_type = bp_read_watchpoint;
5326 else if (accessflag == hw_access)
5327 bp_type = bp_access_watchpoint;
5329 bp_type = bp_hardware_watchpoint;
5331 mem_cnt = can_use_hardware_watchpoint (val);
5332 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5333 error ("Expression cannot be implemented with read/access watchpoint.");
5336 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5337 target_resources_ok =
5338 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5340 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5341 error ("Target does not support this type of hardware watchpoint.");
5343 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5344 error ("Target can only support one kind of HW watchpoint at a time.");
5347 #if defined(HPUXHPPA)
5348 /* On HP-UX if you set a h/w
5349 watchpoint before the "run" command, the inferior dies with a e.g.,
5350 SIGILL once you start it. I initially believed this was due to a
5351 bad interaction between page protection traps and the initial
5352 startup sequence by the dynamic linker.
5354 However, I tried avoiding that by having HP-UX's implementation of
5355 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5356 yet, which forced slow watches before a "run" or "attach", and it
5357 still fails somewhere in the startup code.
5359 Until I figure out what's happening, I'm disallowing watches altogether
5360 before the "run" or "attach" command. We'll tell the user they must
5361 set watches after getting the program started. */
5362 if (!target_has_execution)
5364 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5367 #endif /* HPUXHPPA */
5369 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5370 watchpoint could not be set. */
5371 if (!mem_cnt || target_resources_ok <= 0)
5372 bp_type = bp_watchpoint;
5374 /* Now set up the breakpoint. */
5375 b = set_raw_breakpoint (sal, bp_type);
5376 set_breakpoint_count (breakpoint_count + 1);
5377 b->number = breakpoint_count;
5378 b->disposition = disp_donttouch;
5380 b->exp_valid_block = exp_valid_block;
5381 b->exp_string = savestring (exp_start, exp_end - exp_start);
5385 b->cond_string = savestring (cond_start, cond_end - cond_start);
5389 frame = block_innermost_frame (exp_valid_block);
5392 prev_frame = get_prev_frame (frame);
5393 get_frame_id (frame, &b->watchpoint_frame);
5397 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5400 /* If the expression is "local", then set up a "watchpoint scope"
5401 breakpoint at the point where we've left the scope of the watchpoint
5403 if (innermost_block)
5407 struct breakpoint *scope_breakpoint;
5408 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5409 bp_watchpoint_scope);
5411 scope_breakpoint->enable_state = bp_enabled;
5413 /* Automatically delete the breakpoint when it hits. */
5414 scope_breakpoint->disposition = disp_del;
5416 /* Only break in the proper frame (help with recursion). */
5417 scope_breakpoint->frame = prev_frame->frame;
5419 /* Set the address at which we will stop. */
5420 scope_breakpoint->address = get_frame_pc (prev_frame);
5422 /* The scope breakpoint is related to the watchpoint. We
5423 will need to act on them together. */
5424 b->related_breakpoint = scope_breakpoint;
5427 value_free_to_mark (mark);
5431 /* Return count of locations need to be watched and can be handled
5432 in hardware. If the watchpoint can not be handled
5433 in hardware return zero. */
5435 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5436 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5437 ((BYTE_SIZE) <= (REGISTER_SIZE))
5440 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5441 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5442 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5446 can_use_hardware_watchpoint (struct value *v)
5448 int found_memory_cnt = 0;
5449 struct value *head = v;
5451 /* Did the user specifically forbid us to use hardware watchpoints? */
5452 if (!can_use_hw_watchpoints)
5455 /* Make sure that the value of the expression depends only upon
5456 memory contents, and values computed from them within GDB. If we
5457 find any register references or function calls, we can't use a
5458 hardware watchpoint.
5460 The idea here is that evaluating an expression generates a series
5461 of values, one holding the value of every subexpression. (The
5462 expression a*b+c has five subexpressions: a, b, a*b, c, and
5463 a*b+c.) GDB's values hold almost enough information to establish
5464 the criteria given above --- they identify memory lvalues,
5465 register lvalues, computed values, etcetera. So we can evaluate
5466 the expression, and then scan the chain of values that leaves
5467 behind to decide whether we can detect any possible change to the
5468 expression's final value using only hardware watchpoints.
5470 However, I don't think that the values returned by inferior
5471 function calls are special in any way. So this function may not
5472 notice that an expression involving an inferior function call
5473 can't be watched with hardware watchpoints. FIXME. */
5474 for (; v; v = v->next)
5476 if (VALUE_LVAL (v) == lval_memory)
5479 /* A lazy memory lvalue is one that GDB never needed to fetch;
5480 we either just used its address (e.g., `a' in `a.b') or
5481 we never needed it at all (e.g., `a' in `a,b'). */
5485 /* Ahh, memory we actually used! Check if we can cover
5486 it with hardware watchpoints. */
5487 struct type *vtype = check_typedef (VALUE_TYPE (v));
5489 /* We only watch structs and arrays if user asked for it
5490 explicitly, never if they just happen to appear in a
5491 middle of some value chain. */
5493 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5494 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5496 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5497 int len = TYPE_LENGTH (VALUE_TYPE (v));
5499 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5506 else if (v->lval != not_lval && v->modifiable == 0)
5507 return 0; /* ??? What does this represent? */
5508 else if (v->lval == lval_register)
5509 return 0; /* cannot watch a register with a HW watchpoint */
5512 /* The expression itself looks suitable for using a hardware
5513 watchpoint, but give the target machine a chance to reject it. */
5514 return found_memory_cnt;
5518 watch_command_wrapper (char *arg, int from_tty)
5520 watch_command (arg, from_tty);
5524 watch_command (char *arg, int from_tty)
5526 watch_command_1 (arg, hw_write, from_tty);
5530 rwatch_command_wrapper (char *arg, int from_tty)
5532 rwatch_command (arg, from_tty);
5536 rwatch_command (char *arg, int from_tty)
5538 watch_command_1 (arg, hw_read, from_tty);
5542 awatch_command_wrapper (char *arg, int from_tty)
5544 awatch_command (arg, from_tty);
5548 awatch_command (char *arg, int from_tty)
5550 watch_command_1 (arg, hw_access, from_tty);
5554 /* Helper routines for the until_command routine in infcmd.c. Here
5555 because it uses the mechanisms of breakpoints. */
5557 /* This function is called by fetch_inferior_event via the
5558 cmd_continuation pointer, to complete the until command. It takes
5559 care of cleaning up the temporary breakpoints set up by the until
5562 until_break_command_continuation (struct continuation_arg *arg)
5564 struct cleanup *cleanups;
5566 cleanups = (struct cleanup *) arg->data.pointer;
5567 do_exec_cleanups (cleanups);
5572 until_break_command (char *arg, int from_tty)
5574 struct symtabs_and_lines sals;
5575 struct symtab_and_line sal;
5576 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5577 struct breakpoint *breakpoint;
5578 struct cleanup *old_chain;
5579 struct continuation_arg *arg1;
5582 clear_proceed_status ();
5584 /* Set a breakpoint where the user wants it and at return from
5587 if (default_breakpoint_valid)
5588 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5589 default_breakpoint_line, (char ***) NULL);
5591 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5592 0, (char ***) NULL);
5594 if (sals.nelts != 1)
5595 error ("Couldn't get information on specified line.");
5598 xfree (sals.sals); /* malloc'd, so freed */
5601 error ("Junk at end of arguments.");
5603 resolve_sal_pc (&sal);
5605 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5607 if (!event_loop_p || !target_can_async_p ())
5608 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5610 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5612 /* If we are running asynchronously, and the target supports async
5613 execution, we are not waiting for the target to stop, in the call
5614 tp proceed, below. This means that we cannot delete the
5615 brekpoints until the target has actually stopped. The only place
5616 where we get a chance to do that is in fetch_inferior_event, so
5617 we must set things up for that. */
5619 if (event_loop_p && target_can_async_p ())
5621 /* In this case the arg for the continuation is just the point
5622 in the exec_cleanups chain from where to start doing
5623 cleanups, because all the continuation does is the cleanups in
5624 the exec_cleanup_chain. */
5626 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5628 arg1->data.pointer = old_chain;
5630 add_continuation (until_break_command_continuation, arg1);
5633 /* Keep within the current frame */
5637 sal = find_pc_line (prev_frame->pc, 0);
5638 sal.pc = prev_frame->pc;
5639 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5640 if (!event_loop_p || !target_can_async_p ())
5641 make_cleanup_delete_breakpoint (breakpoint);
5643 make_exec_cleanup_delete_breakpoint (breakpoint);
5646 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5647 /* Do the cleanups now, anly if we are not running asynchronously,
5648 of if we are, but the target is still synchronous. */
5649 if (!event_loop_p || !target_can_async_p ())
5650 do_cleanups (old_chain);
5654 /* These aren't used; I don't konw what they were for. */
5655 /* Set a breakpoint at the catch clause for NAME. */
5657 catch_breakpoint (char *name)
5662 disable_catch_breakpoint (void)
5667 delete_catch_breakpoint (void)
5672 enable_catch_breakpoint (void)
5679 struct sal_chain *next;
5680 struct symtab_and_line sal;
5684 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5685 had been commented out in the v.4.16 sources, and stays
5686 disabled there now because "catch NAME" syntax isn't allowed.
5688 /* This isn't used; I don't know what it was for. */
5689 /* For each catch clause identified in ARGS, run FUNCTION
5690 with that clause as an argument. */
5691 static struct symtabs_and_lines
5692 map_catch_names (char *args, int (*function) ())
5694 register char *p = args;
5696 struct symtabs_and_lines sals;
5698 struct sal_chain *sal_chain = 0;
5702 error_no_arg ("one or more catch names");
5710 /* Don't swallow conditional part. */
5711 if (p1[0] == 'i' && p1[1] == 'f'
5712 && (p1[2] == ' ' || p1[2] == '\t'))
5718 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5722 if (*p1 && *p1 != ' ' && *p1 != '\t')
5723 error ("Arguments must be catch names.");
5729 struct sal_chain *next = (struct sal_chain *)
5730 alloca (sizeof (struct sal_chain));
5731 next->next = sal_chain;
5732 next->sal = get_catch_sal (p);
5737 printf_unfiltered ("No catch clause for exception %s.\n", p);
5742 while (*p == ' ' || *p == '\t')
5748 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5750 static struct symtabs_and_lines
5751 get_catch_sals (int this_level_only)
5753 register struct blockvector *bl;
5754 register struct block *block;
5755 int index, have_default = 0;
5757 struct symtabs_and_lines sals;
5758 struct sal_chain *sal_chain = 0;
5759 char *blocks_searched;
5761 /* Not sure whether an error message is always the correct response,
5762 but it's better than a core dump. */
5763 if (selected_frame == NULL)
5764 error ("No selected frame.");
5765 block = get_frame_block (selected_frame, 0);
5766 pc = selected_frame->pc;
5772 error ("No symbol table info available.\n");
5774 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5775 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5776 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5780 CORE_ADDR end = BLOCK_END (block) - 4;
5783 if (bl != blockvector_for_pc (end, &index))
5784 error ("blockvector blotch");
5785 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5786 error ("blockvector botch");
5787 last_index = BLOCKVECTOR_NBLOCKS (bl);
5790 /* Don't print out blocks that have gone by. */
5791 while (index < last_index
5792 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5795 while (index < last_index
5796 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5798 if (blocks_searched[index] == 0)
5800 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5802 register struct symbol *sym;
5804 ALL_BLOCK_SYMBOLS (b, i, sym)
5806 if (STREQ (SYMBOL_NAME (sym), "default"))
5812 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5814 struct sal_chain *next = (struct sal_chain *)
5815 alloca (sizeof (struct sal_chain));
5816 next->next = sal_chain;
5817 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5822 blocks_searched[index] = 1;
5828 if (sal_chain && this_level_only)
5831 /* After handling the function's top-level block, stop.
5832 Don't continue to its superblock, the block of
5833 per-file symbols. */
5834 if (BLOCK_FUNCTION (block))
5836 block = BLOCK_SUPERBLOCK (block);
5841 struct sal_chain *tmp_chain;
5843 /* Count the number of entries. */
5844 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5845 tmp_chain = tmp_chain->next)
5849 sals.sals = (struct symtab_and_line *)
5850 xmalloc (index * sizeof (struct symtab_and_line));
5851 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5852 sals.sals[index] = sal_chain->sal;
5859 ep_skip_leading_whitespace (char **s)
5861 if ((s == NULL) || (*s == NULL))
5863 while (isspace (**s))
5867 /* This function examines a string, and attempts to find a token
5868 that might be an event name in the leading characters. If a
5869 possible match is found, a pointer to the last character of
5870 the token is returned. Else, NULL is returned. */
5873 ep_find_event_name_end (char *arg)
5876 char *event_name_end = NULL;
5878 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5882 /* We break out of the loop when we find a token delimiter.
5883 Basically, we're looking for alphanumerics and underscores;
5884 anything else delimites the token. */
5887 if (!isalnum (*s) && (*s != '_'))
5893 return event_name_end;
5897 /* This function attempts to parse an optional "if <cond>" clause
5898 from the arg string. If one is not found, it returns NULL.
5900 Else, it returns a pointer to the condition string. (It does not
5901 attempt to evaluate the string against a particular block.) And,
5902 it updates arg to point to the first character following the parsed
5903 if clause in the arg string. */
5906 ep_parse_optional_if_clause (char **arg)
5910 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5913 /* Skip the "if" keyword. */
5916 /* Skip any extra leading whitespace, and record the start of the
5917 condition string. */
5918 ep_skip_leading_whitespace (arg);
5921 /* Assume that the condition occupies the remainder of the arg string. */
5922 (*arg) += strlen (cond_string);
5927 /* This function attempts to parse an optional filename from the arg
5928 string. If one is not found, it returns NULL.
5930 Else, it returns a pointer to the parsed filename. (This function
5931 makes no attempt to verify that a file of that name exists, or is
5932 accessible.) And, it updates arg to point to the first character
5933 following the parsed filename in the arg string.
5935 Note that clients needing to preserve the returned filename for
5936 future access should copy it to their own buffers. */
5938 ep_parse_optional_filename (char **arg)
5940 static char filename[1024];
5945 if ((*arg_p == '\0') || isspace (*arg_p))
5963 /* Commands to deal with catching events, such as signals, exceptions,
5964 process start/exit, etc. */
5968 catch_fork, catch_vfork
5972 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5973 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5974 char *arg, int tempflag, int from_tty);
5977 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5980 char *cond_string = NULL;
5982 ep_skip_leading_whitespace (&arg);
5984 /* The allowed syntax is:
5986 catch [v]fork if <cond>
5988 First, check if there's an if clause. */
5989 cond_string = ep_parse_optional_if_clause (&arg);
5991 if ((*arg != '\0') && !isspace (*arg))
5992 error ("Junk at end of arguments.");
5994 /* If this target supports it, create a fork or vfork catchpoint
5995 and enable reporting of such events. */
5999 create_fork_event_catchpoint (tempflag, cond_string);
6002 create_vfork_event_catchpoint (tempflag, cond_string);
6005 error ("unsupported or unknown fork kind; cannot catch it");
6011 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6013 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6015 char *cond_string = NULL;
6017 ep_skip_leading_whitespace (&arg);
6019 /* The allowed syntax is:
6021 catch exec if <cond>
6023 First, check if there's an if clause. */
6024 cond_string = ep_parse_optional_if_clause (&arg);
6026 if ((*arg != '\0') && !isspace (*arg))
6027 error ("Junk at end of arguments.");
6029 /* If this target supports it, create an exec catchpoint
6030 and enable reporting of such events. */
6031 create_exec_event_catchpoint (tempflag, cond_string);
6035 #if defined(SOLIB_ADD)
6037 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6039 char *dll_pathname = NULL;
6040 char *cond_string = NULL;
6042 ep_skip_leading_whitespace (&arg);
6044 /* The allowed syntax is:
6046 catch load if <cond>
6047 catch load <filename>
6048 catch load <filename> if <cond>
6050 The user is not allowed to specify the <filename> after an
6053 We'll ignore the pathological case of a file named "if".
6055 First, check if there's an if clause. If so, then there
6056 cannot be a filename. */
6057 cond_string = ep_parse_optional_if_clause (&arg);
6059 /* If there was an if clause, then there cannot be a filename.
6060 Else, there might be a filename and an if clause. */
6061 if (cond_string == NULL)
6063 dll_pathname = ep_parse_optional_filename (&arg);
6064 ep_skip_leading_whitespace (&arg);
6065 cond_string = ep_parse_optional_if_clause (&arg);
6068 if ((*arg != '\0') && !isspace (*arg))
6069 error ("Junk at end of arguments.");
6071 /* Create a load breakpoint that only triggers when a load of
6072 the specified dll (or any dll, if no pathname was specified)
6074 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6075 dll_pathname, cond_string);
6079 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6081 char *dll_pathname = NULL;
6082 char *cond_string = NULL;
6084 ep_skip_leading_whitespace (&arg);
6086 /* The allowed syntax is:
6088 catch unload if <cond>
6089 catch unload <filename>
6090 catch unload <filename> if <cond>
6092 The user is not allowed to specify the <filename> after an
6095 We'll ignore the pathological case of a file named "if".
6097 First, check if there's an if clause. If so, then there
6098 cannot be a filename. */
6099 cond_string = ep_parse_optional_if_clause (&arg);
6101 /* If there was an if clause, then there cannot be a filename.
6102 Else, there might be a filename and an if clause. */
6103 if (cond_string == NULL)
6105 dll_pathname = ep_parse_optional_filename (&arg);
6106 ep_skip_leading_whitespace (&arg);
6107 cond_string = ep_parse_optional_if_clause (&arg);
6110 if ((*arg != '\0') && !isspace (*arg))
6111 error ("Junk at end of arguments.");
6113 /* Create an unload breakpoint that only triggers when an unload of
6114 the specified dll (or any dll, if no pathname was specified)
6116 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6117 dll_pathname, cond_string);
6119 #endif /* SOLIB_ADD */
6121 /* Commands to deal with catching exceptions. */
6123 /* Set a breakpoint at the specified callback routine for an
6124 exception event callback */
6127 create_exception_catchpoint (int tempflag, char *cond_string,
6128 enum exception_event_kind ex_event,
6129 struct symtab_and_line *sal)
6131 struct breakpoint *b;
6132 int thread = -1; /* All threads. */
6135 if (!sal) /* no exception support? */
6140 case EX_EVENT_THROW:
6141 bptype = bp_catch_throw;
6143 case EX_EVENT_CATCH:
6144 bptype = bp_catch_catch;
6146 default: /* error condition */
6147 error ("Internal error -- invalid catchpoint kind");
6150 b = set_raw_breakpoint (*sal, bptype);
6151 set_breakpoint_count (breakpoint_count + 1);
6152 b->number = breakpoint_count;
6154 b->cond_string = (cond_string == NULL) ?
6155 NULL : savestring (cond_string, strlen (cond_string));
6157 b->addr_string = NULL;
6158 b->enable_state = bp_enabled;
6159 b->disposition = tempflag ? disp_del : disp_donttouch;
6163 /* Deal with "catch catch" and "catch throw" commands */
6166 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6167 int tempflag, int from_tty)
6169 char *cond_string = NULL;
6170 struct symtab_and_line *sal = NULL;
6172 ep_skip_leading_whitespace (&arg);
6174 cond_string = ep_parse_optional_if_clause (&arg);
6176 if ((*arg != '\0') && !isspace (*arg))
6177 error ("Junk at end of arguments.");
6179 if ((ex_event != EX_EVENT_THROW) &&
6180 (ex_event != EX_EVENT_CATCH))
6181 error ("Unsupported or unknown exception event; cannot catch it");
6183 /* See if we can find a callback routine */
6184 sal = target_enable_exception_callback (ex_event, 1);
6188 /* We have callbacks from the runtime system for exceptions.
6189 Set a breakpoint on the sal found, if no errors */
6190 if (sal != (struct symtab_and_line *) -1)
6191 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6193 return; /* something went wrong with setting up callbacks */
6197 /* No callbacks from runtime system for exceptions.
6198 Try GNU C++ exception breakpoints using labels in debug info. */
6199 if (ex_event == EX_EVENT_CATCH)
6201 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6203 else if (ex_event == EX_EVENT_THROW)
6205 /* Set a breakpoint on __raise_exception () */
6207 warning ("Unsupported with this platform/compiler combination.");
6208 warning ("Perhaps you can achieve the effect you want by setting");
6209 warning ("a breakpoint on __raise_exception().");
6214 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6215 inside a catch_errors */
6218 cover_target_enable_exception_callback (PTR arg)
6220 args_for_catchpoint_enable *args = arg;
6221 struct symtab_and_line *sal;
6222 sal = target_enable_exception_callback (args->kind, args->enable_p);
6225 else if (sal == (struct symtab_and_line *) -1)
6228 return 1; /*is valid */
6233 /* This is the original v.4.16 and earlier version of the
6234 catch_command_1() function. Now that other flavours of "catch"
6235 have been introduced, and since exception handling can be handled
6236 in other ways (through target ops) also, this is used only for the
6237 GNU C++ exception handling system.
6238 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6239 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6240 there was no code in GDB 4.16 for "catch throw".
6242 Called from catch_exception_command_1 () */
6246 handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
6248 /* First, translate ARG into something we can deal with in terms
6251 struct symtabs_and_lines sals;
6252 struct symtab_and_line sal;
6253 register struct expression *cond = 0;
6254 register struct breakpoint *b;
6258 INIT_SAL (&sal); /* initialize to zeroes */
6260 /* If no arg given, or if first arg is 'if ', all active catch clauses
6261 are breakpointed. */
6263 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6264 && (arg[2] == ' ' || arg[2] == '\t')))
6266 /* Grab all active catch clauses. */
6267 sals = get_catch_sals (0);
6271 /* Grab selected catch clauses. */
6272 error ("catch NAME not implemented");
6275 /* Not sure why this code has been disabled. I'm leaving
6276 it disabled. We can never come here now anyway
6277 since we don't allow the "catch NAME" syntax.
6280 /* This isn't used; I don't know what it was for. */
6281 sals = map_catch_names (arg, catch_breakpoint);
6289 for (i = 0; i < sals.nelts; i++)
6291 resolve_sal_pc (&sals.sals[i]);
6295 if (arg[0] == 'i' && arg[1] == 'f'
6296 && (arg[2] == ' ' || arg[2] == '\t'))
6297 cond = parse_exp_1 ((arg += 2, &arg),
6298 block_for_pc (sals.sals[i].pc), 0);
6300 error ("Junk at end of arguments.");
6305 for (i = 0; i < sals.nelts; i++)
6310 describe_other_breakpoints (sal.pc, sal.section);
6312 /* Important -- this is an ordinary breakpoint. For platforms
6313 with callback support for exceptions,
6314 create_exception_catchpoint() will create special bp types
6315 (bp_catch_catch and bp_catch_throw), and there is code in
6316 insert_breakpoints() and elsewhere that depends on that. */
6317 b = set_raw_breakpoint (sal, bp_breakpoint);
6318 set_breakpoint_count (breakpoint_count + 1);
6319 b->number = breakpoint_count;
6322 b->enable_state = bp_enabled;
6323 b->disposition = tempflag ? disp_del : disp_donttouch;
6330 warning ("Multiple breakpoints were set.");
6331 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6337 catch_command_1 (char *arg, int tempflag, int from_tty)
6340 /* The first argument may be an event name, such as "start" or "load".
6341 If so, then handle it as such. If it doesn't match an event name,
6342 then attempt to interpret it as an exception name. (This latter is
6343 the v4.16-and-earlier GDB meaning of the "catch" command.)
6345 First, try to find the bounds of what might be an event name. */
6346 char *arg1_start = arg;
6350 if (arg1_start == NULL)
6352 /* Old behaviour was to use pre-v-4.16 syntax */
6353 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6355 /* Now, this is not allowed */
6356 error ("Catch requires an event name.");
6359 arg1_end = ep_find_event_name_end (arg1_start);
6360 if (arg1_end == NULL)
6361 error ("catch requires an event");
6362 arg1_length = arg1_end + 1 - arg1_start;
6364 /* Try to match what we found against known event names. */
6365 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6367 error ("Catch of signal not yet implemented");
6369 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6371 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6372 tempflag, from_tty);
6374 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6376 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6377 tempflag, from_tty);
6379 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6381 error ("Catch of thread_start not yet implemented");
6383 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6385 error ("Catch of thread_exit not yet implemented");
6387 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6389 error ("Catch of thread_join not yet implemented");
6391 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6393 error ("Catch of start not yet implemented");
6395 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6397 error ("Catch of exit not yet implemented");
6399 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6401 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6402 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6404 error ("Catch of fork not yet implemented");
6407 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6409 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6410 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6412 error ("Catch of vfork not yet implemented");
6415 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6417 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6418 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6420 error ("Catch of exec not yet implemented");
6423 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6425 #if defined(SOLIB_ADD)
6426 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6428 error ("Catch of load not implemented");
6431 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6433 #if defined(SOLIB_ADD)
6434 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6436 error ("Catch of load not implemented");
6439 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6441 error ("Catch of stop not yet implemented");
6444 /* This doesn't appear to be an event name */
6448 /* Pre-v.4.16 behaviour was to treat the argument
6449 as the name of an exception */
6450 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6451 /* Now this is not allowed */
6452 error ("Unknown event kind specified for catch");
6457 /* Used by the gui, could be made a worker for other things. */
6460 set_breakpoint_sal (struct symtab_and_line sal)
6462 struct breakpoint *b;
6463 b = set_raw_breakpoint (sal, bp_breakpoint);
6464 set_breakpoint_count (breakpoint_count + 1);
6465 b->number = breakpoint_count;
6472 /* These aren't used; I don't know what they were for. */
6473 /* Disable breakpoints on all catch clauses described in ARGS. */
6475 disable_catch (char *args)
6477 /* Map the disable command to catch clauses described in ARGS. */
6480 /* Enable breakpoints on all catch clauses described in ARGS. */
6482 enable_catch (char *args)
6484 /* Map the disable command to catch clauses described in ARGS. */
6487 /* Delete breakpoints on all catch clauses in the active scope. */
6489 delete_catch (char *args)
6491 /* Map the delete command to catch clauses described in ARGS. */
6496 catch_command (char *arg, int from_tty)
6498 catch_command_1 (arg, 0, from_tty);
6503 tcatch_command (char *arg, int from_tty)
6505 catch_command_1 (arg, 1, from_tty);
6508 /* Delete breakpoints by address or line. */
6511 clear_command (char *arg, int from_tty)
6513 struct breakpoint *b, *tmp, *prev, *found;
6515 struct symtabs_and_lines sals;
6516 struct symtab_and_line sal;
6521 sals = decode_line_spec (arg, 1);
6526 sals.sals = (struct symtab_and_line *)
6527 xmalloc (sizeof (struct symtab_and_line));
6528 make_cleanup (xfree, sals.sals);
6529 INIT_SAL (&sal); /* initialize to zeroes */
6530 sal.line = default_breakpoint_line;
6531 sal.symtab = default_breakpoint_symtab;
6532 sal.pc = default_breakpoint_address;
6533 if (sal.symtab == 0)
6534 error ("No source file specified.");
6542 /* For each line spec given, delete bps which correspond
6543 to it. Do it in two passes, solely to preserve the current
6544 behavior that from_tty is forced true if we delete more than
6548 for (i = 0; i < sals.nelts; i++)
6550 /* If exact pc given, clear bpts at that pc.
6551 If line given (pc == 0), clear all bpts on specified line.
6552 If defaulting, clear all bpts on default line
6555 defaulting sal.pc != 0 tests to do
6560 1 0 <can't happen> */
6565 /* Find all matching breakpoints, remove them from the
6566 breakpoint chain, and add them to the 'found' chain. */
6567 ALL_BREAKPOINTS_SAFE (b, tmp)
6569 /* Are we going to delete b? */
6570 if (b->type != bp_none
6571 && b->type != bp_watchpoint
6572 && b->type != bp_hardware_watchpoint
6573 && b->type != bp_read_watchpoint
6574 && b->type != bp_access_watchpoint
6575 /* Not if b is a watchpoint of any sort... */
6576 && (((sal.pc && (b->address == sal.pc))
6577 && (!section_is_overlay (b->section)
6578 || b->section == sal.section))
6579 /* Yes, if sal.pc matches b (modulo overlays). */
6580 || ((default_match || (0 == sal.pc))
6581 && b->source_file != NULL
6582 && sal.symtab != NULL
6583 && STREQ (b->source_file, sal.symtab->filename)
6584 && b->line_number == sal.line)))
6585 /* Yes, if sal source file and line matches b. */
6587 /* Remove it from breakpoint_chain... */
6588 if (b == breakpoint_chain)
6590 /* b is at the head of the list */
6591 breakpoint_chain = b->next;
6595 prev->next = b->next;
6597 /* And add it to 'found' chain. */
6603 /* Keep b, and keep a pointer to it. */
6608 /* Now go thru the 'found' chain and delete them. */
6612 error ("No breakpoint at %s.", arg);
6614 error ("No breakpoint at this line.");
6618 from_tty = 1; /* Always report if deleted more than one */
6620 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6621 breakpoints_changed ();
6625 printf_unfiltered ("%d ", found->number);
6627 delete_breakpoint (found);
6631 putchar_unfiltered ('\n');
6634 /* Delete breakpoint in BS if they are `delete' breakpoints and
6635 all breakpoints that are marked for deletion, whether hit or not.
6636 This is called after any breakpoint is hit, or after errors. */
6639 breakpoint_auto_delete (bpstat bs)
6641 struct breakpoint *b, *temp;
6643 for (; bs; bs = bs->next)
6644 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6646 delete_breakpoint (bs->breakpoint_at);
6648 ALL_BREAKPOINTS_SAFE (b, temp)
6650 if (b->disposition == disp_del_at_next_stop)
6651 delete_breakpoint (b);
6655 /* Delete a breakpoint and clean up all traces of it in the data
6659 delete_breakpoint (struct breakpoint *bpt)
6661 register struct breakpoint *b;
6665 error ("Internal error (attempted to delete a NULL breakpoint)");
6668 /* Has this bp already been deleted? This can happen because multiple
6669 lists can hold pointers to bp's. bpstat lists are especial culprits.
6671 One example of this happening is a watchpoint's scope bp. When the
6672 scope bp triggers, we notice that the watchpoint is out of scope, and
6673 delete it. We also delete its scope bp. But the scope bp is marked
6674 "auto-deleting", and is already on a bpstat. That bpstat is then
6675 checked for auto-deleting bp's, which are deleted.
6677 A real solution to this problem might involve reference counts in bp's,
6678 and/or giving them pointers back to their referencing bpstat's, and
6679 teaching delete_breakpoint to only free a bp's storage when no more
6680 references were extent. A cheaper bandaid was chosen. */
6681 if (bpt->type == bp_none)
6684 if (delete_breakpoint_hook)
6685 delete_breakpoint_hook (bpt);
6686 breakpoint_delete_event (bpt->number);
6689 remove_breakpoint (bpt, mark_inserted);
6691 if (breakpoint_chain == bpt)
6692 breakpoint_chain = bpt->next;
6694 /* If we have callback-style exception catchpoints, don't go through
6695 the adjustments to the C++ runtime library etc. if the inferior
6696 isn't actually running. target_enable_exception_callback for a
6697 null target ops vector gives an undesirable error message, so we
6698 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6699 exceptions are supported in this way, it's OK for now. FIXME */
6700 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6702 static char message1[] = "Error in deleting catchpoint %d:\n";
6703 static char message[sizeof (message1) + 30];
6704 args_for_catchpoint_enable args;
6706 /* Format possible error msg */
6707 sprintf (message, message1, bpt->number);
6708 args.kind = bpt->type == bp_catch_catch ?
6709 EX_EVENT_CATCH : EX_EVENT_THROW;
6711 catch_errors (cover_target_enable_exception_callback, &args,
6712 message, RETURN_MASK_ALL);
6719 b->next = bpt->next;
6723 check_duplicates (bpt);
6724 /* If this breakpoint was inserted, and there is another breakpoint
6725 at the same address, we need to insert the other breakpoint. */
6727 && bpt->type != bp_hardware_watchpoint
6728 && bpt->type != bp_read_watchpoint
6729 && bpt->type != bp_access_watchpoint
6730 && bpt->type != bp_catch_fork
6731 && bpt->type != bp_catch_vfork
6732 && bpt->type != bp_catch_exec)
6735 if (b->address == bpt->address
6736 && b->section == bpt->section
6738 && b->enable_state != bp_disabled
6739 && b->enable_state != bp_shlib_disabled
6740 && b->enable_state != bp_call_disabled)
6744 /* We should never reach this point if there is a permanent
6745 breakpoint at the same address as the one being deleted.
6746 If there is a permanent breakpoint somewhere, it should
6747 always be the only one inserted. */
6748 if (b->enable_state == bp_permanent)
6749 internal_error (__FILE__, __LINE__,
6750 "another breakpoint was inserted on top of "
6751 "a permanent breakpoint");
6753 if (b->type == bp_hardware_breakpoint)
6754 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6756 val = target_insert_breakpoint (b->address, b->shadow_contents);
6758 /* If there was an error in the insert, print a message, then stop execution. */
6761 struct ui_file *tmp_error_stream = mem_fileopen ();
6762 make_cleanup_ui_file_delete (tmp_error_stream);
6765 if (b->type == bp_hardware_breakpoint)
6767 fprintf_unfiltered (tmp_error_stream,
6768 "Cannot insert hardware breakpoint %d.\n"
6769 "You may have requested too many hardware breakpoints.\n",
6774 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6775 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6776 print_address_numeric (b->address, 1, tmp_error_stream);
6777 fprintf_filtered (tmp_error_stream, ": %s.\n",
6778 safe_strerror (val));
6781 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6782 target_terminal_ours_for_output ();
6783 error_stream(tmp_error_stream);
6790 free_command_lines (&bpt->commands);
6793 if (bpt->cond_string != NULL)
6794 xfree (bpt->cond_string);
6795 if (bpt->addr_string != NULL)
6796 xfree (bpt->addr_string);
6797 if (bpt->exp != NULL)
6799 if (bpt->exp_string != NULL)
6800 xfree (bpt->exp_string);
6801 if (bpt->val != NULL)
6802 value_free (bpt->val);
6803 if (bpt->source_file != NULL)
6804 xfree (bpt->source_file);
6805 if (bpt->dll_pathname != NULL)
6806 xfree (bpt->dll_pathname);
6807 if (bpt->triggered_dll_pathname != NULL)
6808 xfree (bpt->triggered_dll_pathname);
6809 if (bpt->exec_pathname != NULL)
6810 xfree (bpt->exec_pathname);
6812 /* Be sure no bpstat's are pointing at it after it's been freed. */
6813 /* FIXME, how can we find all bpstat's?
6814 We just check stop_bpstat for now. */
6815 for (bs = stop_bpstat; bs; bs = bs->next)
6816 if (bs->breakpoint_at == bpt)
6818 bs->breakpoint_at = NULL;
6820 /* bs->commands will be freed later. */
6822 /* On the chance that someone will soon try again to delete this same
6823 bp, we mark it as deleted before freeing its storage. */
6824 bpt->type = bp_none;
6830 do_delete_breakpoint_cleanup (void *b)
6832 delete_breakpoint (b);
6836 make_cleanup_delete_breakpoint (struct breakpoint *b)
6838 return make_cleanup (do_delete_breakpoint_cleanup, b);
6842 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6844 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6848 delete_command (char *arg, int from_tty)
6850 struct breakpoint *b, *temp;
6856 int breaks_to_delete = 0;
6858 /* Delete all breakpoints if no argument.
6859 Do not delete internal or call-dummy breakpoints, these
6860 have to be deleted with an explicit breakpoint number argument. */
6863 if (b->type != bp_call_dummy &&
6864 b->type != bp_shlib_event &&
6865 b->type != bp_thread_event &&
6866 b->type != bp_overlay_event &&
6868 breaks_to_delete = 1;
6871 /* Ask user only if there are some breakpoints to delete. */
6873 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6875 ALL_BREAKPOINTS_SAFE (b, temp)
6877 if (b->type != bp_call_dummy &&
6878 b->type != bp_shlib_event &&
6879 b->type != bp_thread_event &&
6880 b->type != bp_overlay_event &&
6882 delete_breakpoint (b);
6887 map_breakpoint_numbers (arg, delete_breakpoint);
6890 /* Reset a breakpoint given it's struct breakpoint * BINT.
6891 The value we return ends up being the return value from catch_errors.
6892 Unused in this case. */
6895 breakpoint_re_set_one (PTR bint)
6897 /* get past catch_errs */
6898 struct breakpoint *b = (struct breakpoint *) bint;
6901 struct symtabs_and_lines sals;
6903 enum enable_state save_enable;
6908 warning ("attempted to reset apparently deleted breakpoint #%d?",
6912 case bp_hardware_breakpoint:
6914 case bp_catch_unload:
6915 if (b->addr_string == NULL)
6917 /* Anything without a string can't be re-set. */
6918 delete_breakpoint (b);
6921 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6923 ``And a hack it is, although Apple's Darwin version of GDB
6924 contains an almost identical hack to implement a "future
6925 break" command. It seems to work in many real world cases,
6926 but it is easy to come up with a test case where the patch
6927 doesn't help at all.''
6929 ``It seems that the way GDB implements breakpoints - in -
6930 shared - libraries was designed for a.out shared library
6931 systems (SunOS 4) where shared libraries were loaded at a
6932 fixed address in memory. Since ELF shared libraries can (and
6933 will) be loaded at any address in memory, things break.
6934 Fixing this is not trivial. Therefore, I'm not sure whether
6935 we should add this hack to the branch only. I cannot
6936 guarantee that things will be fixed on the trunk in the near
6939 In case we have a problem, disable this breakpoint. We'll
6940 restore its status if we succeed. Don't disable a
6941 shlib_disabled breakpoint though. There's a fair chance we
6942 can't re-set it if the shared library it's in hasn't been
6944 save_enable = b->enable_state;
6945 if (b->enable_state != bp_shlib_disabled)
6946 b->enable_state = bp_disabled;
6948 set_language (b->language);
6949 input_radix = b->input_radix;
6951 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6952 for (i = 0; i < sals.nelts; i++)
6954 resolve_sal_pc (&sals.sals[i]);
6956 /* Reparse conditions, they might contain references to the
6958 if (b->cond_string != NULL)
6963 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6966 /* We need to re-set the breakpoint if the address changes... */
6967 if (b->address != sals.sals[i].pc
6968 /* ...or new and old breakpoints both have source files, and
6969 the source file name or the line number changes... */
6970 || (b->source_file != NULL
6971 && sals.sals[i].symtab != NULL
6972 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6973 || b->line_number != sals.sals[i].line)
6975 /* ...or we switch between having a source file and not having
6977 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6980 if (b->source_file != NULL)
6981 xfree (b->source_file);
6982 if (sals.sals[i].symtab == NULL)
6983 b->source_file = NULL;
6986 savestring (sals.sals[i].symtab->filename,
6987 strlen (sals.sals[i].symtab->filename));
6988 b->line_number = sals.sals[i].line;
6989 b->address = sals.sals[i].pc;
6991 /* Used to check for duplicates here, but that can
6992 cause trouble, as it doesn't check for disabled
6997 /* Might be better to do this just once per breakpoint_re_set,
6998 rather than once for every breakpoint. */
6999 breakpoints_changed ();
7001 b->section = sals.sals[i].section;
7002 b->enable_state = save_enable; /* Restore it, this worked. */
7005 /* Now that this is re-enabled, check_duplicates
7007 check_duplicates (b);
7014 case bp_hardware_watchpoint:
7015 case bp_read_watchpoint:
7016 case bp_access_watchpoint:
7017 innermost_block = NULL;
7018 /* The issue arises of what context to evaluate this in. The
7019 same one as when it was set, but what does that mean when
7020 symbols have been re-read? We could save the filename and
7021 functionname, but if the context is more local than that, the
7022 best we could do would be something like how many levels deep
7023 and which index at that particular level, but that's going to
7024 be less stable than filenames or function names. */
7026 /* So for now, just use a global context. */
7029 b->exp = parse_expression (b->exp_string);
7030 b->exp_valid_block = innermost_block;
7031 mark = value_mark ();
7033 value_free (b->val);
7034 b->val = evaluate_expression (b->exp);
7035 release_value (b->val);
7036 if (VALUE_LAZY (b->val))
7037 value_fetch_lazy (b->val);
7039 if (b->cond_string != NULL)
7044 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7046 if (b->enable_state == bp_enabled)
7048 value_free_to_mark (mark);
7050 case bp_catch_catch:
7051 case bp_catch_throw:
7053 /* We needn't really do anything to reset these, since the mask
7054 that requests them is unaffected by e.g., new libraries being
7057 case bp_catch_vfork:
7062 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7064 /* Delete longjmp and overlay event breakpoints; they will be
7065 reset later by breakpoint_re_set. */
7067 case bp_longjmp_resume:
7068 case bp_overlay_event:
7069 delete_breakpoint (b);
7072 /* This breakpoint is special, it's set up when the inferior
7073 starts and we really don't want to touch it. */
7074 case bp_shlib_event:
7076 /* Like bp_shlib_event, this breakpoint type is special.
7077 Once it is set up, we do not want to touch it. */
7078 case bp_thread_event:
7080 /* Keep temporary breakpoints, which can be encountered when we step
7081 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7082 Otherwise these should have been blown away via the cleanup chain
7083 or by breakpoint_init_inferior when we rerun the executable. */
7086 case bp_watchpoint_scope:
7088 case bp_step_resume:
7095 /* Re-set all breakpoints after symbols have been re-loaded. */
7097 breakpoint_re_set (void)
7099 struct breakpoint *b, *temp;
7100 enum language save_language;
7101 int save_input_radix;
7102 static char message1[] = "Error in re-setting breakpoint %d:\n";
7103 char message[sizeof (message1) + 30 /* slop */ ];
7105 save_language = current_language->la_language;
7106 save_input_radix = input_radix;
7107 ALL_BREAKPOINTS_SAFE (b, temp)
7109 /* Format possible error msg */
7110 sprintf (message, message1, b->number);
7111 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7113 set_language (save_language);
7114 input_radix = save_input_radix;
7116 if (GET_LONGJMP_TARGET_P ())
7118 create_longjmp_breakpoint ("longjmp");
7119 create_longjmp_breakpoint ("_longjmp");
7120 create_longjmp_breakpoint ("siglongjmp");
7121 create_longjmp_breakpoint ("_siglongjmp");
7122 create_longjmp_breakpoint (NULL);
7125 create_overlay_event_breakpoint ("_ovly_debug_event");
7128 /* Reset the thread number of this breakpoint:
7130 - If the breakpoint is for all threads, leave it as-is.
7131 - Else, reset it to the current thread for inferior_ptid. */
7133 breakpoint_re_set_thread (struct breakpoint *b)
7135 if (b->thread != -1)
7137 if (in_thread_list (inferior_ptid))
7138 b->thread = pid_to_thread_id (inferior_ptid);
7142 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7143 If from_tty is nonzero, it prints a message to that effect,
7144 which ends with a period (no newline). */
7147 set_ignore_count (int bptnum, int count, int from_tty)
7149 register struct breakpoint *b;
7155 if (b->number == bptnum)
7157 b->ignore_count = count;
7161 printf_filtered ("Will stop next time breakpoint %d is reached.",
7163 else if (count == 1)
7164 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7167 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7170 breakpoints_changed ();
7171 breakpoint_modify_event (b->number);
7175 error ("No breakpoint number %d.", bptnum);
7178 /* Clear the ignore counts of all breakpoints. */
7180 breakpoint_clear_ignore_counts (void)
7182 struct breakpoint *b;
7185 b->ignore_count = 0;
7188 /* Command to set ignore-count of breakpoint N to COUNT. */
7191 ignore_command (char *args, int from_tty)
7197 error_no_arg ("a breakpoint number");
7199 num = get_number (&p);
7201 error ("bad breakpoint number: '%s'", args);
7203 error ("Second argument (specified ignore-count) is missing.");
7205 set_ignore_count (num,
7206 longest_to_int (value_as_long (parse_and_eval (p))),
7209 printf_filtered ("\n");
7212 /* Call FUNCTION on each of the breakpoints
7213 whose numbers are given in ARGS. */
7216 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7218 register char *p = args;
7221 register struct breakpoint *b, *tmp;
7225 error_no_arg ("one or more breakpoint numbers");
7232 num = get_number_or_range (&p1);
7235 warning ("bad breakpoint number at or near '%s'", p);
7239 ALL_BREAKPOINTS_SAFE (b, tmp)
7240 if (b->number == num)
7242 struct breakpoint *related_breakpoint = b->related_breakpoint;
7245 if (related_breakpoint)
7246 function (related_breakpoint);
7250 printf_unfiltered ("No breakpoint number %d.\n", num);
7256 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7257 If from_tty is nonzero, it prints a message to that effect,
7258 which ends with a period (no newline). */
7261 disable_breakpoint (struct breakpoint *bpt)
7263 /* Never disable a watchpoint scope breakpoint; we want to
7264 hit them when we leave scope so we can delete both the
7265 watchpoint and its scope breakpoint at that time. */
7266 if (bpt->type == bp_watchpoint_scope)
7269 /* You can't disable permanent breakpoints. */
7270 if (bpt->enable_state == bp_permanent)
7273 bpt->enable_state = bp_disabled;
7275 check_duplicates (bpt);
7277 if (modify_breakpoint_hook)
7278 modify_breakpoint_hook (bpt);
7279 breakpoint_modify_event (bpt->number);
7284 disable_command (char *args, int from_tty)
7286 register struct breakpoint *bpt;
7288 ALL_BREAKPOINTS (bpt)
7292 warning ("attempted to disable apparently deleted breakpoint #%d?",
7297 case bp_catch_unload:
7299 case bp_catch_vfork:
7301 case bp_catch_catch:
7302 case bp_catch_throw:
7303 case bp_hardware_breakpoint:
7305 case bp_hardware_watchpoint:
7306 case bp_read_watchpoint:
7307 case bp_access_watchpoint:
7308 disable_breakpoint (bpt);
7313 map_breakpoint_numbers (args, disable_breakpoint);
7317 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7319 struct frame_info *save_selected_frame = NULL;
7320 int save_selected_frame_level = -1;
7321 int target_resources_ok, other_type_used;
7324 if (bpt->type == bp_hardware_breakpoint)
7327 i = hw_breakpoint_used_count ();
7328 target_resources_ok =
7329 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7331 if (target_resources_ok == 0)
7332 error ("No hardware breakpoint support in the target.");
7333 else if (target_resources_ok < 0)
7334 error ("Hardware breakpoints used exceeds limit.");
7337 if (bpt->enable_state != bp_permanent)
7338 bpt->enable_state = bp_enabled;
7339 bpt->disposition = disposition;
7340 check_duplicates (bpt);
7341 breakpoints_changed ();
7343 if (bpt->type == bp_watchpoint ||
7344 bpt->type == bp_hardware_watchpoint ||
7345 bpt->type == bp_read_watchpoint ||
7346 bpt->type == bp_access_watchpoint)
7348 if (bpt->exp_valid_block != NULL)
7350 struct frame_info *fr =
7351 fr = frame_find_by_id (bpt->watchpoint_frame);
7355 Cannot enable watchpoint %d because the block in which its expression\n\
7356 is valid is not currently in scope.\n", bpt->number);
7357 bpt->enable_state = bp_disabled;
7361 save_selected_frame = selected_frame;
7362 save_selected_frame_level = frame_relative_level (selected_frame);
7366 value_free (bpt->val);
7367 mark = value_mark ();
7368 bpt->val = evaluate_expression (bpt->exp);
7369 release_value (bpt->val);
7370 if (VALUE_LAZY (bpt->val))
7371 value_fetch_lazy (bpt->val);
7373 if (bpt->type == bp_hardware_watchpoint ||
7374 bpt->type == bp_read_watchpoint ||
7375 bpt->type == bp_access_watchpoint)
7377 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7378 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7380 /* Hack around 'unused var' error for some targets here */
7382 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7383 bpt->type, i + mem_cnt, other_type_used);
7384 /* we can consider of type is bp_hardware_watchpoint, convert to
7385 bp_watchpoint in the following condition */
7386 if (target_resources_ok < 0)
7389 Cannot enable watchpoint %d because target watch resources\n\
7390 have been allocated for other watchpoints.\n", bpt->number);
7391 bpt->enable_state = bp_disabled;
7392 value_free_to_mark (mark);
7397 if (save_selected_frame_level >= 0)
7398 select_frame (save_selected_frame);
7399 value_free_to_mark (mark);
7401 if (modify_breakpoint_hook)
7402 modify_breakpoint_hook (bpt);
7403 breakpoint_modify_event (bpt->number);
7407 enable_breakpoint (struct breakpoint *bpt)
7409 do_enable_breakpoint (bpt, bpt->disposition);
7412 /* The enable command enables the specified breakpoints (or all defined
7413 breakpoints) so they once again become (or continue to be) effective
7414 in stopping the inferior. */
7418 enable_command (char *args, int from_tty)
7420 register struct breakpoint *bpt;
7422 ALL_BREAKPOINTS (bpt)
7426 warning ("attempted to enable apparently deleted breakpoint #%d?",
7431 case bp_catch_unload:
7433 case bp_catch_vfork:
7435 case bp_catch_catch:
7436 case bp_catch_throw:
7437 case bp_hardware_breakpoint:
7439 case bp_hardware_watchpoint:
7440 case bp_read_watchpoint:
7441 case bp_access_watchpoint:
7442 enable_breakpoint (bpt);
7447 map_breakpoint_numbers (args, enable_breakpoint);
7451 enable_once_breakpoint (struct breakpoint *bpt)
7453 do_enable_breakpoint (bpt, disp_disable);
7458 enable_once_command (char *args, int from_tty)
7460 map_breakpoint_numbers (args, enable_once_breakpoint);
7464 enable_delete_breakpoint (struct breakpoint *bpt)
7466 do_enable_breakpoint (bpt, disp_del);
7471 enable_delete_command (char *args, int from_tty)
7473 map_breakpoint_numbers (args, enable_delete_breakpoint);
7476 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7478 struct symtabs_and_lines
7479 decode_line_spec_1 (char *string, int funfirstline)
7481 struct symtabs_and_lines sals;
7483 error ("Empty line specification.");
7484 if (default_breakpoint_valid)
7485 sals = decode_line_1 (&string, funfirstline,
7486 default_breakpoint_symtab,
7487 default_breakpoint_line,
7490 sals = decode_line_1 (&string, funfirstline,
7491 (struct symtab *) NULL, 0, (char ***) NULL);
7493 error ("Junk at end of line specification: %s", string);
7498 _initialize_breakpoint (void)
7500 struct cmd_list_element *c;
7502 breakpoint_chain = 0;
7503 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7504 before a breakpoint is set. */
7505 breakpoint_count = 0;
7507 add_com ("ignore", class_breakpoint, ignore_command,
7508 "Set ignore-count of breakpoint number N to COUNT.\n\
7509 Usage is `ignore N COUNT'.");
7511 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7513 add_com ("commands", class_breakpoint, commands_command,
7514 "Set commands to be executed when a breakpoint is hit.\n\
7515 Give breakpoint number as argument after \"commands\".\n\
7516 With no argument, the targeted breakpoint is the last one set.\n\
7517 The commands themselves follow starting on the next line.\n\
7518 Type a line containing \"end\" to indicate the end of them.\n\
7519 Give \"silent\" as the first line to make the breakpoint silent;\n\
7520 then no output is printed when it is hit, except what the commands print.");
7522 add_com ("condition", class_breakpoint, condition_command,
7523 "Specify breakpoint number N to break only if COND is true.\n\
7524 Usage is `condition N COND', where N is an integer and COND is an\n\
7525 expression to be evaluated whenever breakpoint N is reached.");
7527 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7528 "Set a temporary breakpoint. Args like \"break\" command.\n\
7529 Like \"break\" except the breakpoint is only temporary,\n\
7530 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7531 by using \"enable delete\" on the breakpoint number.");
7532 set_cmd_completer (c, location_completer);
7534 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7535 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7536 Like \"break\" except the breakpoint requires hardware support,\n\
7537 some target hardware may not have this support.");
7538 set_cmd_completer (c, location_completer);
7540 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7541 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7542 Like \"hbreak\" except the breakpoint is only temporary,\n\
7543 so it will be deleted when hit.");
7544 set_cmd_completer (c, location_completer);
7546 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7547 "Enable some breakpoints.\n\
7548 Give breakpoint numbers (separated by spaces) as arguments.\n\
7549 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7550 This is used to cancel the effect of the \"disable\" command.\n\
7551 With a subcommand you can enable temporarily.",
7552 &enablelist, "enable ", 1, &cmdlist);
7554 add_com ("ab", class_breakpoint, enable_command,
7555 "Enable some breakpoints.\n\
7556 Give breakpoint numbers (separated by spaces) as arguments.\n\
7557 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7558 This is used to cancel the effect of the \"disable\" command.\n\
7559 With a subcommand you can enable temporarily.");
7561 add_com_alias ("en", "enable", class_breakpoint, 1);
7563 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7564 "Enable some breakpoints.\n\
7565 Give breakpoint numbers (separated by spaces) as arguments.\n\
7566 This is used to cancel the effect of the \"disable\" command.\n\
7567 May be abbreviated to simply \"enable\".\n",
7568 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7570 add_cmd ("once", no_class, enable_once_command,
7571 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7572 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7575 add_cmd ("delete", no_class, enable_delete_command,
7576 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7577 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7580 add_cmd ("delete", no_class, enable_delete_command,
7581 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7582 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7585 add_cmd ("once", no_class, enable_once_command,
7586 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7587 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7590 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7591 "Disable some breakpoints.\n\
7592 Arguments are breakpoint numbers with spaces in between.\n\
7593 To disable all breakpoints, give no argument.\n\
7594 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7595 &disablelist, "disable ", 1, &cmdlist);
7596 add_com_alias ("dis", "disable", class_breakpoint, 1);
7597 add_com_alias ("disa", "disable", class_breakpoint, 1);
7599 add_com ("sb", class_breakpoint, disable_command,
7600 "Disable some breakpoints.\n\
7601 Arguments are breakpoint numbers with spaces in between.\n\
7602 To disable all breakpoints, give no argument.\n\
7603 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7605 add_cmd ("breakpoints", class_alias, disable_command,
7606 "Disable some breakpoints.\n\
7607 Arguments are breakpoint numbers with spaces in between.\n\
7608 To disable all breakpoints, give no argument.\n\
7609 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7610 This command may be abbreviated \"disable\".",
7613 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7614 "Delete some breakpoints or auto-display expressions.\n\
7615 Arguments are breakpoint numbers with spaces in between.\n\
7616 To delete all breakpoints, give no argument.\n\
7618 Also a prefix command for deletion of other GDB objects.\n\
7619 The \"unset\" command is also an alias for \"delete\".",
7620 &deletelist, "delete ", 1, &cmdlist);
7621 add_com_alias ("d", "delete", class_breakpoint, 1);
7623 add_com ("db", class_breakpoint, delete_command,
7624 "Delete some breakpoints.\n\
7625 Arguments are breakpoint numbers with spaces in between.\n\
7626 To delete all breakpoints, give no argument.\n");
7628 add_cmd ("breakpoints", class_alias, delete_command,
7629 "Delete some breakpoints or auto-display expressions.\n\
7630 Arguments are breakpoint numbers with spaces in between.\n\
7631 To delete all breakpoints, give no argument.\n\
7632 This command may be abbreviated \"delete\".",
7635 add_com ("clear", class_breakpoint, clear_command,
7636 concat ("Clear breakpoint at specified line or function.\n\
7637 Argument may be line number, function name, or \"*\" and an address.\n\
7638 If line number is specified, all breakpoints in that line are cleared.\n\
7639 If function is specified, breakpoints at beginning of function are cleared.\n\
7640 If an address is specified, breakpoints at that address are cleared.\n\n",
7641 "With no argument, clears all breakpoints in the line that the selected frame\n\
7644 See also the \"delete\" command which clears breakpoints by number.", NULL));
7646 c = add_com ("break", class_breakpoint, break_command,
7647 concat ("Set breakpoint at specified line or function.\n\
7648 Argument may be line number, function name, or \"*\" and an address.\n\
7649 If line number is specified, break at start of code for that line.\n\
7650 If function is specified, break at start of code for that function.\n\
7651 If an address is specified, break at that exact address.\n",
7652 "With no arg, uses current execution address of selected stack frame.\n\
7653 This is useful for breaking on return to a stack frame.\n\
7655 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7657 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7658 set_cmd_completer (c, location_completer);
7660 add_com_alias ("b", "break", class_run, 1);
7661 add_com_alias ("br", "break", class_run, 1);
7662 add_com_alias ("bre", "break", class_run, 1);
7663 add_com_alias ("brea", "break", class_run, 1);
7667 add_com_alias ("ba", "break", class_breakpoint, 1);
7668 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7673 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7674 "Break in function/address or break at a line in the current file.",
7675 &stoplist, "stop ", 1, &cmdlist);
7676 add_cmd ("in", class_breakpoint, stopin_command,
7677 "Break in function or address.\n", &stoplist);
7678 add_cmd ("at", class_breakpoint, stopat_command,
7679 "Break at a line in the current file.\n", &stoplist);
7680 add_com ("status", class_info, breakpoints_info,
7681 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7682 The \"Type\" column indicates one of:\n\
7683 \tbreakpoint - normal breakpoint\n\
7684 \twatchpoint - watchpoint\n\
7685 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7686 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7687 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7688 address and file/line number respectively.\n\n",
7689 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7690 are set to the address of the last breakpoint listed.\n\n\
7691 Convenience variable \"$bpnum\" contains the number of the last\n\
7692 breakpoint set.", NULL));
7695 add_info ("breakpoints", breakpoints_info,
7696 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7697 The \"Type\" column indicates one of:\n\
7698 \tbreakpoint - normal breakpoint\n\
7699 \twatchpoint - watchpoint\n\
7700 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7701 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7702 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7703 address and file/line number respectively.\n\n",
7704 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7705 are set to the address of the last breakpoint listed.\n\n\
7706 Convenience variable \"$bpnum\" contains the number of the last\n\
7707 breakpoint set.", NULL));
7710 add_com ("lb", class_breakpoint, breakpoints_info,
7711 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7712 The \"Type\" column indicates one of:\n\
7713 \tbreakpoint - normal breakpoint\n\
7714 \twatchpoint - watchpoint\n\
7715 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7716 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7717 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7718 address and file/line number respectively.\n\n",
7719 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7720 are set to the address of the last breakpoint listed.\n\n\
7721 Convenience variable \"$bpnum\" contains the number of the last\n\
7722 breakpoint set.", NULL));
7724 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7725 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7726 The \"Type\" column indicates one of:\n\
7727 \tbreakpoint - normal breakpoint\n\
7728 \twatchpoint - watchpoint\n\
7729 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7730 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7731 \tuntil - internal breakpoint used by the \"until\" command\n\
7732 \tfinish - internal breakpoint used by the \"finish\" command\n",
7733 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7734 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7735 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7736 address and file/line number respectively.\n\n",
7737 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7738 are set to the address of the last breakpoint listed.\n\n\
7739 Convenience variable \"$bpnum\" contains the number of the last\n\
7740 breakpoint set.", NULL),
7741 &maintenanceinfolist);
7743 add_com ("catch", class_breakpoint, catch_command,
7744 "Set catchpoints to catch events.\n\
7745 Raised signals may be caught:\n\
7746 \tcatch signal - all signals\n\
7747 \tcatch signal <signame> - a particular signal\n\
7748 Raised exceptions may be caught:\n\
7749 \tcatch throw - all exceptions, when thrown\n\
7750 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7751 \tcatch catch - all exceptions, when caught\n\
7752 \tcatch catch <exceptname> - a particular exception, when caught\n\
7753 Thread or process events may be caught:\n\
7754 \tcatch thread_start - any threads, just after creation\n\
7755 \tcatch thread_exit - any threads, just before expiration\n\
7756 \tcatch thread_join - any threads, just after joins\n\
7757 Process events may be caught:\n\
7758 \tcatch start - any processes, just after creation\n\
7759 \tcatch exit - any processes, just before expiration\n\
7760 \tcatch fork - calls to fork()\n\
7761 \tcatch vfork - calls to vfork()\n\
7762 \tcatch exec - calls to exec()\n\
7763 Dynamically-linked library events may be caught:\n\
7764 \tcatch load - loads of any library\n\
7765 \tcatch load <libname> - loads of a particular library\n\
7766 \tcatch unload - unloads of any library\n\
7767 \tcatch unload <libname> - unloads of a particular library\n\
7768 The act of your program's execution stopping may also be caught:\n\
7770 C++ exceptions may be caught:\n\
7771 \tcatch throw - all exceptions, when thrown\n\
7772 \tcatch catch - all exceptions, when caught\n\
7774 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7775 after a fork or vfork is caught.\n\n\
7776 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7778 add_com ("tcatch", class_breakpoint, tcatch_command,
7779 "Set temporary catchpoints to catch events.\n\
7780 Args like \"catch\" command.\n\
7781 Like \"catch\" except the catchpoint is only temporary,\n\
7782 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7783 by using \"enable delete\" on the catchpoint number.");
7785 c = add_com ("watch", class_breakpoint, watch_command,
7786 "Set a watchpoint for an expression.\n\
7787 A watchpoint stops execution of your program whenever the value of\n\
7788 an expression changes.");
7789 set_cmd_completer (c, location_completer);
7791 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7792 "Set a read watchpoint for an expression.\n\
7793 A watchpoint stops execution of your program whenever the value of\n\
7794 an expression is read.");
7795 set_cmd_completer (c, location_completer);
7797 c = add_com ("awatch", class_breakpoint, awatch_command,
7798 "Set a watchpoint for an expression.\n\
7799 A watchpoint stops execution of your program whenever the value of\n\
7800 an expression is either read or written.");
7801 set_cmd_completer (c, location_completer);
7803 add_info ("watchpoints", breakpoints_info,
7804 "Synonym for ``info breakpoints''.");
7807 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7808 (char *) &can_use_hw_watchpoints,
7809 "Set debugger's willingness to use watchpoint hardware.\n\
7810 If zero, gdb will not use hardware for new watchpoints, even if\n\
7811 such is available. (However, any hardware watchpoints that were\n\
7812 created before setting this to nonzero, will continue to use watchpoint\n\
7815 add_show_from_set (c, &showlist);
7817 can_use_hw_watchpoints = 1;