1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
45 #include "completer.h"
49 #include "gdb-events.h"
51 /* Prototypes for local functions. */
53 static void until_break_command_continuation (struct continuation_arg *arg);
55 static void catch_command_1 (char *, int, int);
57 static void enable_delete_command (char *, int);
59 static void enable_delete_breakpoint (struct breakpoint *);
61 static void enable_once_command (char *, int);
63 static void enable_once_breakpoint (struct breakpoint *);
65 static void disable_command (char *, int);
67 static void enable_command (char *, int);
69 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
71 static void ignore_command (char *, int);
73 static int breakpoint_re_set_one (PTR);
75 static void clear_command (char *, int);
77 static void catch_command (char *, int);
79 static void handle_gnu_4_16_catch_command (char *, int, int);
81 static struct symtabs_and_lines get_catch_sals (int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value *);
87 static void break_at_finish_command (char *, int);
88 static void break_at_finish_at_depth_command (char *, int);
90 static void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint *);
96 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
98 static void check_duplicates (struct breakpoint *);
100 static void describe_other_breakpoints (CORE_ADDR, asection *);
102 static void breakpoints_info (char *, int);
104 static void breakpoint_1 (int, int);
106 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
108 static int breakpoint_cond_eval (PTR);
110 static void cleanup_executing_breakpoints (PTR);
112 static void commands_command (char *, int);
114 static void condition_command (char *, int);
116 static int get_number_trailer (char **, int);
118 void set_breakpoint_count (int);
121 static struct breakpoint *create_temp_exception_breakpoint (CORE_ADDR);
131 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
133 static enum print_stop_action print_it_typical (bpstat);
135 static enum print_stop_action print_bp_stop_message (bpstat bs);
139 enum exception_event_kind kind;
142 args_for_catchpoint_enable;
144 static int watchpoint_check (PTR);
146 static int cover_target_enable_exception_callback (PTR);
148 static void maintenance_info_breakpoints (char *, int);
150 #ifdef GET_LONGJMP_TARGET
151 static void create_longjmp_breakpoint (char *);
154 static int hw_breakpoint_used_count (void);
156 static int hw_watchpoint_used_count (enum bptype, int *);
158 static void hbreak_command (char *, int);
160 static void thbreak_command (char *, int);
162 static void watch_command_1 (char *, int, int);
164 static void rwatch_command (char *, int);
166 static void awatch_command (char *, int);
168 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
170 static void solib_load_unload_1 (char *hookname,
173 char *cond_string, enum bptype bp_kind);
175 static void create_fork_vfork_event_catchpoint (int tempflag,
177 enum bptype bp_kind);
179 static void break_at_finish_at_depth_command_1 (char *arg,
180 int flag, int from_tty);
182 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
184 static void stop_command (char *arg, int from_tty);
186 static void stopin_command (char *arg, int from_tty);
188 static void stopat_command (char *arg, int from_tty);
190 static char *ep_find_event_name_end (char *arg);
192 static char *ep_parse_optional_if_clause (char **arg);
194 static char *ep_parse_optional_filename (char **arg);
196 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
197 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
200 static void create_exception_catchpoint (int tempflag, char *cond_string,
201 enum exception_event_kind ex_event,
202 struct symtab_and_line *sal);
204 static void catch_exception_command_1 (enum exception_event_kind ex_event,
205 char *arg, int tempflag, int from_tty);
207 static void tcatch_command (char *arg, int from_tty);
209 static void ep_skip_leading_whitespace (char **s);
211 /* Prototypes for exported functions. */
213 /* If FALSE, gdb will not use hardware support for watchpoints, even
214 if such is available. */
215 static int can_use_hw_watchpoints;
217 void _initialize_breakpoint (void);
219 extern int addressprint; /* Print machine addresses? */
221 static int internal_breakpoint_number = -1;
223 /* Are we executing breakpoint commands? */
224 static int executing_breakpoint_commands;
226 /* Walk the following statement or block through all breakpoints.
227 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
230 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
232 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
233 for (B = breakpoint_chain; \
234 B ? (TMP=B->next, 1): 0; \
237 /* True if SHIFT_INST_REGS defined, false otherwise. */
239 int must_shift_inst_regs =
240 #if defined(SHIFT_INST_REGS)
247 /* True if breakpoint hit counts should be displayed in breakpoint info. */
249 int show_breakpoint_hit_counts = 1;
251 /* Chain of all breakpoints defined. */
253 struct breakpoint *breakpoint_chain;
255 /* Number of last breakpoint made. */
257 int breakpoint_count;
259 /* Pointer to current exception event record */
260 static struct exception_event_record *current_exception_event;
262 /* Indicator of whether exception catchpoints should be nuked
263 between runs of a program */
264 int exception_catchpoints_are_fragile = 0;
266 /* Indicator of when exception catchpoints set-up should be
267 reinitialized -- e.g. when program is re-run */
268 int exception_support_initialized = 0;
270 /* This function returns a pointer to the string representation of the
271 pathname of the dynamically-linked library that has just been
274 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
275 or undefined results are guaranteed.
277 This string's contents are only valid immediately after the
278 inferior has stopped in the dynamic linker hook, and becomes
279 invalid as soon as the inferior is continued. Clients should make
280 a copy of this string if they wish to continue the inferior and
281 then access the string. */
283 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
284 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
287 /* This function returns a pointer to the string representation of the
288 pathname of the dynamically-linked library that has just been
291 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
292 TRUE, or undefined results are guaranteed.
294 This string's contents are only valid immediately after the
295 inferior has stopped in the dynamic linker hook, and becomes
296 invalid as soon as the inferior is continued. Clients should make
297 a copy of this string if they wish to continue the inferior and
298 then access the string. */
300 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
301 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
304 /* This function is called by the "catch load" command. It allows the
305 debugger to be notified by the dynamic linker when a specified
306 library file (or any library file, if filename is NULL) is loaded. */
308 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
309 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
310 error ("catch of library loads not yet implemented on this platform")
313 /* This function is called by the "catch unload" command. It allows
314 the debugger to be notified by the dynamic linker when a specified
315 library file (or any library file, if filename is NULL) is
318 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
319 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
320 error ("catch of library unloads not yet implemented on this platform")
323 /* Set breakpoint count to NUM. */
326 set_breakpoint_count (int num)
328 breakpoint_count = num;
329 set_internalvar (lookup_internalvar ("bpnum"),
330 value_from_longest (builtin_type_int, (LONGEST) num));
333 /* Used in run_command to zero the hit count when a new run starts. */
336 clear_breakpoint_hit_counts (void)
338 struct breakpoint *b;
344 /* Default address, symtab and line to put a breakpoint at
345 for "break" command with no arg.
346 if default_breakpoint_valid is zero, the other three are
347 not valid, and "break" with no arg is an error.
349 This set by print_stack_frame, which calls set_default_breakpoint. */
351 int default_breakpoint_valid;
352 CORE_ADDR default_breakpoint_address;
353 struct symtab *default_breakpoint_symtab;
354 int default_breakpoint_line;
356 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
357 Advance *PP after the string and any trailing whitespace.
359 Currently the string can either be a number or "$" followed by the name
360 of a convenience variable. Making it an expression wouldn't work well
361 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
363 TRAILER is a character which can be found after the number; most
364 commonly this is `-'. If you don't want a trailer, use \0. */
366 get_number_trailer (char **pp, int trailer)
368 int retval = 0; /* default */
372 /* Empty line means refer to the last breakpoint. */
373 return breakpoint_count;
376 /* Make a copy of the name, so we can null-terminate it
377 to pass to lookup_internalvar(). */
382 while (isalnum (*p) || *p == '_')
384 varname = (char *) alloca (p - start + 1);
385 strncpy (varname, start, p - start);
386 varname[p - start] = '\0';
387 val = value_of_internalvar (lookup_internalvar (varname));
388 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
389 retval = (int) value_as_long (val);
392 printf_filtered ("Convenience variable must have integer value.\n");
400 while (*p >= '0' && *p <= '9')
403 /* There is no number here. (e.g. "cond a == b"). */
405 /* Skip non-numeric token */
406 while (*p && !isspace((int) *p))
408 /* Return zero, which caller must interpret as error. */
414 if (!(isspace (*p) || *p == '\0' || *p == trailer))
416 /* Trailing junk: return 0 and let caller print error msg. */
417 while (!(isspace (*p) || *p == '\0' || *p == trailer))
428 /* Like get_number_trailer, but don't allow a trailer. */
430 get_number (char **pp)
432 return get_number_trailer (pp, '\0');
435 /* Parse a number or a range.
436 * A number will be of the form handled by get_number.
437 * A range will be of the form <number1> - <number2>, and
438 * will represent all the integers between number1 and number2,
441 * While processing a range, this fuction is called iteratively;
442 * At each call it will return the next value in the range.
444 * At the beginning of parsing a range, the char pointer PP will
445 * be advanced past <number1> and left pointing at the '-' token.
446 * Subsequent calls will not advance the pointer until the range
447 * is completed. The call that completes the range will advance
448 * pointer PP past <number2>.
452 get_number_or_range (char **pp)
454 static int last_retval, end_value;
455 static char *end_ptr;
456 static int in_range = 0;
460 /* Default case: pp is pointing either to a solo number,
461 or to the first number of a range. */
462 last_retval = get_number_trailer (pp, '-');
467 /* This is the start of a range (<number1> - <number2>).
468 Skip the '-', parse and remember the second number,
469 and also remember the end of the final token. */
473 while (isspace ((int) *end_ptr))
474 end_ptr++; /* skip white space */
475 end_value = get_number (temp);
476 if (end_value < last_retval)
478 error ("inverted range");
480 else if (end_value == last_retval)
482 /* degenerate range (number1 == number2). Advance the
483 token pointer so that the range will be treated as a
492 error ("negative value");
495 /* pp points to the '-' that betokens a range. All
496 number-parsing has already been done. Return the next
497 integer value (one greater than the saved previous value).
498 Do not advance the token pointer 'pp' until the end of range
501 if (++last_retval == end_value)
503 /* End of range reached; advance token pointer. */
513 /* condition N EXP -- set break condition of breakpoint N to EXP. */
516 condition_command (char *arg, int from_tty)
518 register struct breakpoint *b;
523 error_no_arg ("breakpoint number");
526 bnum = get_number (&p);
528 error ("Bad breakpoint argument: '%s'", arg);
531 if (b->number == bnum)
538 if (b->cond_string != NULL)
539 xfree (b->cond_string);
544 b->cond_string = NULL;
546 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
551 /* I don't know if it matters whether this is the string the user
552 typed in or the decompiled expression. */
553 b->cond_string = savestring (arg, strlen (arg));
554 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
556 error ("Junk at end of expression");
558 breakpoints_changed ();
562 error ("No breakpoint number %d.", bnum);
567 commands_command (char *arg, int from_tty)
569 register struct breakpoint *b;
572 struct command_line *l;
574 /* If we allowed this, we would have problems with when to
575 free the storage, if we change the commands currently
578 if (executing_breakpoint_commands)
579 error ("Can't use the \"commands\" command among a breakpoint's commands.");
582 bnum = get_number (&p);
585 error ("Unexpected extra arguments following breakpoint number.");
588 if (b->number == bnum)
592 "Type commands for when breakpoint %d is hit, one per line.",
594 l = read_command_lines (tmpbuf, from_tty);
595 free_command_lines (&b->commands);
597 breakpoints_changed ();
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;
720 static char message1[] = "Error inserting catchpoint %d:\n";
721 static char message[sizeof (message1) + 30];
724 ALL_BREAKPOINTS_SAFE (b, temp)
726 if (b->enable_state == bp_permanent)
727 /* Permanent breakpoints cannot be inserted or removed. */
729 else if (b->type != bp_watchpoint
730 && b->type != bp_hardware_watchpoint
731 && b->type != bp_read_watchpoint
732 && b->type != bp_access_watchpoint
733 && b->type != bp_catch_fork
734 && b->type != bp_catch_vfork
735 && b->type != bp_catch_exec
736 && b->type != bp_catch_throw
737 && b->type != bp_catch_catch
738 && b->enable_state != bp_disabled
739 && b->enable_state != bp_shlib_disabled
740 && b->enable_state != bp_call_disabled
744 if (b->type == bp_hardware_breakpoint)
745 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
748 /* Check to see if breakpoint is in an overlay section;
749 if so, we should set the breakpoint at the LMA address.
750 Only if the section is currently mapped should we ALSO
751 set a break at the VMA address. */
752 if (overlay_debugging && b->section
753 && section_is_overlay (b->section))
757 addr = overlay_unmapped_address (b->address, b->section);
758 val = target_insert_breakpoint (addr, b->shadow_contents);
759 /* This would be the time to check val, to see if the
760 breakpoint write to the load address succeeded.
761 However, this might be an ordinary occurrance, eg. if
762 the unmapped overlay is in ROM. */
763 val = 0; /* in case unmapped address failed */
764 if (section_is_mapped (b->section))
765 val = target_insert_breakpoint (b->address,
768 else /* ordinary (non-overlay) address */
769 val = target_insert_breakpoint (b->address, b->shadow_contents);
773 /* Can't set the breakpoint. */
774 #if defined (DISABLE_UNSETTABLE_BREAK)
775 if (DISABLE_UNSETTABLE_BREAK (b->address))
777 /* See also: disable_breakpoints_in_shlibs. */
779 b->enable_state = bp_shlib_disabled;
780 if (!disabled_breaks)
782 target_terminal_ours_for_output ();
783 warning ("Cannot insert breakpoint %d:", b->number);
784 warning ("Temporarily disabling shared library breakpoints:");
787 warning ("breakpoint #%d ", b->number);
792 target_terminal_ours_for_output ();
793 warning ("Cannot insert breakpoint %d:", b->number);
794 #ifdef ONE_PROCESS_WRITETEXT
795 warning ("The same program may be running in another process.");
797 memory_error (val, b->address); /* which bombs us out */
804 return_val = val; /* remember failure */
806 else if (ep_is_exception_catchpoint (b)
807 && b->enable_state != bp_disabled
808 && b->enable_state != bp_shlib_disabled
809 && b->enable_state != bp_call_disabled
814 /* If we get here, we must have a callback mechanism for exception
815 events -- with g++ style embedded label support, we insert
816 ordinary breakpoints and not catchpoints. */
817 /* Format possible error message */
818 sprintf (message, message1, b->number);
820 val = target_insert_breakpoint (b->address, b->shadow_contents);
823 /* Couldn't set breakpoint for some reason */
824 target_terminal_ours_for_output ();
825 warning ("Cannot insert catchpoint %d; disabling it.",
827 b->enable_state = bp_disabled;
831 /* Bp set, now make sure callbacks are enabled */
833 args_for_catchpoint_enable args;
834 args.kind = b->type == bp_catch_catch ?
835 EX_EVENT_CATCH : EX_EVENT_THROW;
837 val = catch_errors (cover_target_enable_exception_callback,
839 message, RETURN_MASK_ALL);
840 if (val != 0 && val != -1)
844 /* Check if something went wrong; val == 0 can be ignored */
847 /* something went wrong */
848 target_terminal_ours_for_output ();
849 warning ("Cannot insert catchpoint %d; disabling it.",
851 b->enable_state = bp_disabled;
856 return_val = val; /* remember failure */
859 else if ((b->type == bp_hardware_watchpoint ||
860 b->type == bp_read_watchpoint ||
861 b->type == bp_access_watchpoint)
862 && b->enable_state == bp_enabled
863 && b->disposition != disp_del_at_next_stop
867 struct frame_info *saved_frame;
868 int saved_level, within_current_scope;
869 struct value *mark = value_mark ();
872 /* Save the current frame and level so we can restore it after
873 evaluating the watchpoint expression on its own frame. */
874 saved_frame = selected_frame;
875 saved_level = selected_frame_level;
877 /* Determine if the watchpoint is within scope. */
878 if (b->exp_valid_block == NULL)
879 within_current_scope = 1;
882 struct frame_info *fi;
884 /* There might be no current frame at this moment if we are
885 resuming from a step over a breakpoint.
886 Set up current frame before trying to find the watchpoint
888 get_current_frame ();
889 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
890 within_current_scope = (fi != NULL);
891 if (within_current_scope)
892 select_frame (fi, -1);
895 if (within_current_scope)
897 /* Evaluate the expression and cut the chain of values
898 produced off from the value chain.
900 Make sure the value returned isn't lazy; we use
901 laziness to determine what memory GDB actually needed
902 in order to compute the value of the expression. */
903 v = evaluate_expression (b->exp);
905 value_release_to_mark (mark);
910 /* Look at each value on the value chain. */
911 for (; v; v = v->next)
913 /* If it's a memory location, and GDB actually needed
914 its contents to evaluate the expression, then we
916 if (VALUE_LVAL (v) == lval_memory
919 struct type *vtype = check_typedef (VALUE_TYPE (v));
921 /* We only watch structs and arrays if user asked
922 for it explicitly, never if they just happen to
923 appear in the middle of some value chain. */
924 if (v == b->val_chain
925 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
926 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
931 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
932 len = TYPE_LENGTH (VALUE_TYPE (v));
934 if (b->type == bp_read_watchpoint)
936 else if (b->type == bp_access_watchpoint)
939 val = target_insert_watchpoint (addr, len, type);
942 /* Don't exit the loop, try to insert
943 every value on the value chain. That's
944 because we will be removing all the
945 watches below, and removing a
946 watchpoint we didn't insert could have
954 /* Failure to insert a watchpoint on any memory value in the
955 value chain brings us here. */
958 remove_breakpoint (b, mark_uninserted);
959 warning ("Could not insert hardware watchpoint %d.",
966 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
967 printf_filtered ("because the program has left the block \n");
968 printf_filtered ("in which its expression is valid.\n");
969 if (b->related_breakpoint)
970 b->related_breakpoint->disposition = disp_del_at_next_stop;
971 b->disposition = disp_del_at_next_stop;
974 /* Restore the frame and level. */
975 if ((saved_frame != selected_frame) ||
976 (saved_level != selected_frame_level))
977 select_frame (saved_frame, saved_level);
980 return_val = val; /* remember failure */
982 else if ((b->type == bp_catch_fork
983 || b->type == bp_catch_vfork
984 || b->type == bp_catch_exec)
985 && b->enable_state == bp_enabled
993 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
996 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
999 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
1002 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1007 target_terminal_ours_for_output ();
1008 warning ("Cannot insert catchpoint %d.", b->number);
1014 return_val = val; /* remember failure */
1023 remove_breakpoints (void)
1025 register struct breakpoint *b;
1032 val = remove_breakpoint (b, mark_uninserted);
1041 remove_hw_watchpoints (void)
1043 register struct breakpoint *b;
1049 && (b->type == bp_hardware_watchpoint
1050 || b->type == bp_read_watchpoint
1051 || b->type == bp_access_watchpoint))
1053 val = remove_breakpoint (b, mark_uninserted);
1062 reattach_breakpoints (int pid)
1064 register struct breakpoint *b;
1066 struct cleanup *old_chain = save_inferior_ptid ();
1068 /* Set inferior_ptid; remove_breakpoint uses this global. */
1069 inferior_ptid = pid_to_ptid (pid);
1074 remove_breakpoint (b, mark_inserted);
1075 if (b->type == bp_hardware_breakpoint)
1076 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1078 val = target_insert_breakpoint (b->address, b->shadow_contents);
1081 do_cleanups (old_chain);
1086 do_cleanups (old_chain);
1091 update_breakpoints_after_exec (void)
1093 struct breakpoint *b;
1094 struct breakpoint *temp;
1096 /* Doing this first prevents the badness of having delete_breakpoint()
1097 write a breakpoint's current "shadow contents" to lift the bp. That
1098 shadow is NOT valid after an exec()! */
1099 mark_breakpoints_out ();
1101 ALL_BREAKPOINTS_SAFE (b, temp)
1103 /* Solib breakpoints must be explicitly reset after an exec(). */
1104 if (b->type == bp_shlib_event)
1106 delete_breakpoint (b);
1110 /* Thread event breakpoints must be set anew after an exec(). */
1111 if (b->type == bp_thread_event)
1113 delete_breakpoint (b);
1117 /* Step-resume breakpoints are meaningless after an exec(). */
1118 if (b->type == bp_step_resume)
1120 delete_breakpoint (b);
1124 /* Ditto the sigtramp handler breakpoints. */
1125 if (b->type == bp_through_sigtramp)
1127 delete_breakpoint (b);
1131 /* Ditto the exception-handling catchpoints. */
1132 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1134 delete_breakpoint (b);
1138 /* Don't delete an exec catchpoint, because else the inferior
1139 won't stop when it ought!
1141 Similarly, we probably ought to keep vfork catchpoints, 'cause
1142 on this target, we may not be able to stop when the vfork is
1143 seen, but only when the subsequent exec is seen. (And because
1144 deleting fork catchpoints here but not vfork catchpoints will
1145 seem mysterious to users, keep those too.)
1147 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1148 target address field, if any, is sufficient to have it be reset
1149 automagically. Certainly on HP-UX that's true.
1151 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1152 valid code address on some platforms (like the mn10200 and
1153 mn10300 simulators). We shouldn't assign any special
1154 interpretation to a breakpoint with a zero address. And in
1155 fact, GDB doesn't --- I can't see what that comment above is
1156 talking about. As far as I can tell, setting the address of a
1157 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1158 is meaningless, since those are implemented with HP-UX kernel
1159 hackery, not by storing breakpoint instructions somewhere. */
1160 if ((b->type == bp_catch_exec) ||
1161 (b->type == bp_catch_vfork) ||
1162 (b->type == bp_catch_fork))
1164 b->address = (CORE_ADDR) NULL;
1168 /* bp_finish is a special case. The only way we ought to be able
1169 to see one of these when an exec() has happened, is if the user
1170 caught a vfork, and then said "finish". Ordinarily a finish just
1171 carries them to the call-site of the current callee, by setting
1172 a temporary bp there and resuming. But in this case, the finish
1173 will carry them entirely through the vfork & exec.
1175 We don't want to allow a bp_finish to remain inserted now. But
1176 we can't safely delete it, 'cause finish_command has a handle to
1177 the bp on a bpstat, and will later want to delete it. There's a
1178 chance (and I've seen it happen) that if we delete the bp_finish
1179 here, that its storage will get reused by the time finish_command
1180 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1181 We really must allow finish_command to delete a bp_finish.
1183 In the absense of a general solution for the "how do we know
1184 it's safe to delete something others may have handles to?"
1185 problem, what we'll do here is just uninsert the bp_finish, and
1186 let finish_command delete it.
1188 (We know the bp_finish is "doomed" in the sense that it's
1189 momentary, and will be deleted as soon as finish_command sees
1190 the inferior stopped. So it doesn't matter that the bp's
1191 address is probably bogus in the new a.out, unlike e.g., the
1192 solib breakpoints.) */
1194 if (b->type == bp_finish)
1199 /* Without a symbolic address, we have little hope of the
1200 pre-exec() address meaning the same thing in the post-exec()
1202 if (b->addr_string == NULL)
1204 delete_breakpoint (b);
1208 /* If this breakpoint has survived the above battery of checks, then
1209 it must have a symbolic address. Be sure that it gets reevaluated
1210 to a target address, rather than reusing the old evaluation.
1212 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1213 for bp_catch_exec and friends, I'm pretty sure this is entirely
1214 unnecessary. A call to breakpoint_re_set_one always recomputes
1215 the breakpoint's address from scratch, or deletes it if it can't.
1216 So I think this assignment could be deleted without effect. */
1217 b->address = (CORE_ADDR) NULL;
1222 detach_breakpoints (int pid)
1224 register struct breakpoint *b;
1226 struct cleanup *old_chain = save_inferior_ptid ();
1228 if (pid == PIDGET (inferior_ptid))
1229 error ("Cannot detach breakpoints of inferior_ptid");
1231 /* Set inferior_ptid; remove_breakpoint uses this global. */
1232 inferior_ptid = pid_to_ptid (pid);
1237 val = remove_breakpoint (b, mark_inserted);
1240 do_cleanups (old_chain);
1245 do_cleanups (old_chain);
1250 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1254 if (b->enable_state == bp_permanent)
1255 /* Permanent breakpoints cannot be inserted or removed. */
1258 if (b->type == bp_none)
1259 warning ("attempted to remove apparently deleted breakpoint #%d?",
1262 if (b->type != bp_watchpoint
1263 && b->type != bp_hardware_watchpoint
1264 && b->type != bp_read_watchpoint
1265 && b->type != bp_access_watchpoint
1266 && b->type != bp_catch_fork
1267 && b->type != bp_catch_vfork
1268 && b->type != bp_catch_exec
1269 && b->type != bp_catch_catch
1270 && b->type != bp_catch_throw)
1272 if (b->type == bp_hardware_breakpoint)
1273 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1276 /* Check to see if breakpoint is in an overlay section;
1277 if so, we should remove the breakpoint at the LMA address.
1278 If that is not equal to the raw address, then we should
1279 presumably remove the breakpoint there as well. */
1280 if (overlay_debugging && b->section
1281 && section_is_overlay (b->section))
1285 addr = overlay_unmapped_address (b->address, b->section);
1286 val = target_remove_breakpoint (addr, b->shadow_contents);
1287 /* This would be the time to check val, to see if the
1288 shadow breakpoint write to the load address succeeded.
1289 However, this might be an ordinary occurrance, eg. if
1290 the unmapped overlay is in ROM. */
1291 val = 0; /* in case unmapped address failed */
1292 if (section_is_mapped (b->section))
1293 val = target_remove_breakpoint (b->address,
1294 b->shadow_contents);
1296 else /* ordinary (non-overlay) address */
1297 val = target_remove_breakpoint (b->address, b->shadow_contents);
1301 b->inserted = (is == mark_inserted);
1303 else if ((b->type == bp_hardware_watchpoint ||
1304 b->type == bp_read_watchpoint ||
1305 b->type == bp_access_watchpoint)
1306 && b->enable_state == bp_enabled
1312 b->inserted = (is == mark_inserted);
1313 /* Walk down the saved value chain. */
1314 for (v = b->val_chain; v; v = v->next)
1316 /* For each memory reference remove the watchpoint
1318 if (VALUE_LVAL (v) == lval_memory
1319 && ! VALUE_LAZY (v))
1321 struct type *vtype = check_typedef (VALUE_TYPE (v));
1323 if (v == b->val_chain
1324 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1325 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1330 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1331 len = TYPE_LENGTH (VALUE_TYPE (v));
1333 if (b->type == bp_read_watchpoint)
1335 else if (b->type == bp_access_watchpoint)
1338 val = target_remove_watchpoint (addr, len, type);
1345 /* Failure to remove any of the hardware watchpoints comes here. */
1346 if ((is == mark_uninserted) && (b->inserted))
1347 warning ("Could not remove hardware watchpoint %d.",
1350 /* Free the saved value chain. We will construct a new one
1351 the next time the watchpoint is inserted. */
1352 for (v = b->val_chain; v; v = n)
1357 b->val_chain = NULL;
1359 else if ((b->type == bp_catch_fork ||
1360 b->type == bp_catch_vfork ||
1361 b->type == bp_catch_exec)
1362 && b->enable_state == bp_enabled
1369 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1371 case bp_catch_vfork:
1372 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1375 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1378 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1383 b->inserted = (is == mark_inserted);
1385 else if ((b->type == bp_catch_catch ||
1386 b->type == bp_catch_throw)
1387 && b->enable_state == bp_enabled
1391 val = target_remove_breakpoint (b->address, b->shadow_contents);
1394 b->inserted = (is == mark_inserted);
1396 else if (ep_is_exception_catchpoint (b)
1397 && b->inserted /* sometimes previous insert doesn't happen */
1398 && b->enable_state == bp_enabled
1402 val = target_remove_breakpoint (b->address, b->shadow_contents);
1406 b->inserted = (is == mark_inserted);
1412 /* Clear the "inserted" flag in all breakpoints. */
1415 mark_breakpoints_out (void)
1417 register struct breakpoint *b;
1423 /* Clear the "inserted" flag in all breakpoints and delete any
1424 breakpoints which should go away between runs of the program.
1426 Plus other such housekeeping that has to be done for breakpoints
1429 Note: this function gets called at the end of a run (by
1430 generic_mourn_inferior) and when a run begins (by
1431 init_wait_for_inferior). */
1436 breakpoint_init_inferior (enum inf_context context)
1438 register struct breakpoint *b, *temp;
1439 static int warning_needed = 0;
1441 ALL_BREAKPOINTS_SAFE (b, temp)
1448 case bp_watchpoint_scope:
1450 /* If the call dummy breakpoint is at the entry point it will
1451 cause problems when the inferior is rerun, so we better
1454 Also get rid of scope breakpoints. */
1455 delete_breakpoint (b);
1459 case bp_hardware_watchpoint:
1460 case bp_read_watchpoint:
1461 case bp_access_watchpoint:
1463 /* Likewise for watchpoints on local expressions. */
1464 if (b->exp_valid_block != NULL)
1465 delete_breakpoint (b);
1468 /* Likewise for exception catchpoints in dynamic-linked
1469 executables where required */
1470 if (ep_is_exception_catchpoint (b) &&
1471 exception_catchpoints_are_fragile)
1474 delete_breakpoint (b);
1480 if (exception_catchpoints_are_fragile)
1481 exception_support_initialized = 0;
1483 /* Don't issue the warning unless it's really needed... */
1484 if (warning_needed && (context != inf_exited))
1486 warning ("Exception catchpoints from last run were deleted.");
1487 warning ("You must reinsert them explicitly.");
1492 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1493 exists at PC. It returns ordinary_breakpoint_here if it's an
1494 ordinary breakpoint, or permanent_breakpoint_here if it's a
1495 permanent breakpoint.
1496 - When continuing from a location with an ordinary breakpoint, we
1497 actually single step once before calling insert_breakpoints.
1498 - When continuing from a localion with a permanent breakpoint, we
1499 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1500 the target, to advance the PC past the breakpoint. */
1502 enum breakpoint_here
1503 breakpoint_here_p (CORE_ADDR pc)
1505 register struct breakpoint *b;
1506 int any_breakpoint_here = 0;
1509 if ((b->enable_state == bp_enabled
1510 || b->enable_state == bp_permanent)
1511 && b->address == pc) /* bp is enabled and matches pc */
1513 if (overlay_debugging
1514 && section_is_overlay (b->section)
1515 && !section_is_mapped (b->section))
1516 continue; /* unmapped overlay -- can't be a match */
1517 else if (b->enable_state == bp_permanent)
1518 return permanent_breakpoint_here;
1520 any_breakpoint_here = 1;
1523 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1527 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1528 but it only returns true if there is actually a breakpoint inserted
1532 breakpoint_inserted_here_p (CORE_ADDR pc)
1534 register struct breakpoint *b;
1538 && b->address == pc) /* bp is inserted and matches pc */
1540 if (overlay_debugging
1541 && section_is_overlay (b->section)
1542 && !section_is_mapped (b->section))
1543 continue; /* unmapped overlay -- can't be a match */
1551 /* Return nonzero if FRAME is a dummy frame. We can't use
1552 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1553 much time, at least using get_saved_register on the 68k. This
1554 means that for this function to work right a port must use the
1555 bp_call_dummy breakpoint. */
1558 frame_in_dummy (struct frame_info *frame)
1560 struct breakpoint *b;
1565 if (USE_GENERIC_DUMMY_FRAMES)
1566 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1570 if (b->type == bp_call_dummy
1571 && b->frame == frame->frame
1572 /* We need to check the PC as well as the frame on the sparc,
1573 for signals.exp in the testsuite. */
1576 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1577 && frame->pc <= b->address)
1583 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1584 PC is valid for process/thread PID. */
1587 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1589 struct breakpoint *b;
1592 thread = pid_to_thread_id (ptid);
1595 if (b->enable_state != bp_disabled
1596 && b->enable_state != bp_shlib_disabled
1597 && b->enable_state != bp_call_disabled
1599 && (b->thread == -1 || b->thread == thread))
1601 if (overlay_debugging
1602 && section_is_overlay (b->section)
1603 && !section_is_mapped (b->section))
1604 continue; /* unmapped overlay -- can't be a match */
1613 /* bpstat stuff. External routines' interfaces are documented
1617 ep_is_catchpoint (struct breakpoint *ep)
1620 (ep->type == bp_catch_load)
1621 || (ep->type == bp_catch_unload)
1622 || (ep->type == bp_catch_fork)
1623 || (ep->type == bp_catch_vfork)
1624 || (ep->type == bp_catch_exec)
1625 || (ep->type == bp_catch_catch)
1626 || (ep->type == bp_catch_throw);
1628 /* ??rehrauer: Add more kinds here, as are implemented... */
1632 ep_is_shlib_catchpoint (struct breakpoint *ep)
1635 (ep->type == bp_catch_load)
1636 || (ep->type == bp_catch_unload);
1640 ep_is_exception_catchpoint (struct breakpoint *ep)
1643 (ep->type == bp_catch_catch)
1644 || (ep->type == bp_catch_throw);
1647 /* Clear a bpstat so that it says we are not at any breakpoint.
1648 Also free any storage that is part of a bpstat. */
1651 bpstat_clear (bpstat *bsp)
1662 if (p->old_val != NULL)
1663 value_free (p->old_val);
1670 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1671 is part of the bpstat is copied as well. */
1674 bpstat_copy (bpstat bs)
1678 bpstat retval = NULL;
1683 for (; bs != NULL; bs = bs->next)
1685 tmp = (bpstat) xmalloc (sizeof (*tmp));
1686 memcpy (tmp, bs, sizeof (*tmp));
1688 /* This is the first thing in the chain. */
1698 /* Find the bpstat associated with this breakpoint */
1701 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1706 for (; bsp != NULL; bsp = bsp->next)
1708 if (bsp->breakpoint_at == breakpoint)
1714 /* Find a step_resume breakpoint associated with this bpstat.
1715 (If there are multiple step_resume bp's on the list, this function
1716 will arbitrarily pick one.)
1718 It is an error to use this function if BPSTAT doesn't contain a
1719 step_resume breakpoint.
1721 See wait_for_inferior's use of this function. */
1723 bpstat_find_step_resume_breakpoint (bpstat bsp)
1728 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1730 current_thread = pid_to_thread_id (inferior_ptid);
1732 for (; bsp != NULL; bsp = bsp->next)
1734 if ((bsp->breakpoint_at != NULL) &&
1735 (bsp->breakpoint_at->type == bp_step_resume) &&
1736 (bsp->breakpoint_at->thread == current_thread ||
1737 bsp->breakpoint_at->thread == -1))
1738 return bsp->breakpoint_at;
1741 error ("Internal error (no step_resume breakpoint found)");
1745 /* Return the breakpoint number of the first breakpoint we are stopped
1746 at. *BSP upon return is a bpstat which points to the remaining
1747 breakpoints stopped at (but which is not guaranteed to be good for
1748 anything but further calls to bpstat_num).
1749 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1752 bpstat_num (bpstat *bsp)
1754 struct breakpoint *b;
1757 return 0; /* No more breakpoint values */
1760 b = (*bsp)->breakpoint_at;
1761 *bsp = (*bsp)->next;
1763 return -1; /* breakpoint that's been deleted since */
1765 return b->number; /* We have its number */
1769 /* Modify BS so that the actions will not be performed. */
1772 bpstat_clear_actions (bpstat bs)
1774 for (; bs != NULL; bs = bs->next)
1776 bs->commands = NULL;
1777 if (bs->old_val != NULL)
1779 value_free (bs->old_val);
1785 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1788 cleanup_executing_breakpoints (PTR ignore)
1790 executing_breakpoint_commands = 0;
1793 /* Execute all the commands associated with all the breakpoints at this
1794 location. Any of these commands could cause the process to proceed
1795 beyond this point, etc. We look out for such changes by checking
1796 the global "breakpoint_proceeded" after each command. */
1799 bpstat_do_actions (bpstat *bsp)
1802 struct cleanup *old_chain;
1803 struct command_line *cmd;
1805 /* Avoid endless recursion if a `source' command is contained
1807 if (executing_breakpoint_commands)
1810 executing_breakpoint_commands = 1;
1811 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1814 /* Note that (as of this writing), our callers all appear to
1815 be passing us the address of global stop_bpstat. And, if
1816 our calls to execute_control_command cause the inferior to
1817 proceed, that global (and hence, *bsp) will change.
1819 We must be careful to not touch *bsp unless the inferior
1820 has not proceeded. */
1822 /* This pointer will iterate over the list of bpstat's. */
1825 breakpoint_proceeded = 0;
1826 for (; bs != NULL; bs = bs->next)
1831 execute_control_command (cmd);
1833 if (breakpoint_proceeded)
1838 if (breakpoint_proceeded)
1839 /* The inferior is proceeded by the command; bomb out now.
1840 The bpstat chain has been blown away by wait_for_inferior.
1841 But since execution has stopped again, there is a new bpstat
1842 to look at, so start over. */
1845 bs->commands = NULL;
1848 executing_breakpoint_commands = 0;
1849 discard_cleanups (old_chain);
1852 /* This is the normal print function for a bpstat. In the future,
1853 much of this logic could (should?) be moved to bpstat_stop_status,
1854 by having it set different print_it values.
1856 Current scheme: When we stop, bpstat_print() is called. It loops
1857 through the bpstat list of things causing this stop, calling the
1858 print_bp_stop_message function on each one. The behavior of the
1859 print_bp_stop_message function depends on the print_it field of
1860 bpstat. If such field so indicates, call this function here.
1862 Return values from this routine (ultimately used by bpstat_print()
1863 and normal_stop() to decide what to do):
1864 PRINT_NOTHING: Means we already printed all we needed to print,
1865 don't print anything else.
1866 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1867 that something to be followed by a location.
1868 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1869 that something to be followed by a location.
1870 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1873 static enum print_stop_action
1874 print_it_typical (bpstat bs)
1876 struct cleanup *old_chain;
1877 struct ui_stream *stb;
1878 stb = ui_out_stream_new (uiout);
1879 old_chain = make_cleanup_ui_out_stream_delete (stb);
1880 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1881 which has since been deleted. */
1882 if (bs->breakpoint_at == NULL)
1883 return PRINT_UNKNOWN;
1885 switch (bs->breakpoint_at->type)
1888 case bp_hardware_breakpoint:
1889 annotate_breakpoint (bs->breakpoint_at->number);
1890 ui_out_text (uiout, "\nBreakpoint ");
1891 if (ui_out_is_mi_like_p (uiout))
1892 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1893 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1894 ui_out_text (uiout, ", ");
1895 return PRINT_SRC_AND_LOC;
1898 case bp_shlib_event:
1899 /* Did we stop because the user set the stop_on_solib_events
1900 variable? (If so, we report this as a generic, "Stopped due
1901 to shlib event" message.) */
1902 printf_filtered ("Stopped due to shared library event\n");
1903 return PRINT_NOTHING;
1906 case bp_thread_event:
1907 /* Not sure how we will get here.
1908 GDB should not stop for these breakpoints. */
1909 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1910 return PRINT_NOTHING;
1914 annotate_catchpoint (bs->breakpoint_at->number);
1915 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1916 printf_filtered ("loaded");
1917 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1918 return PRINT_SRC_AND_LOC;
1921 case bp_catch_unload:
1922 annotate_catchpoint (bs->breakpoint_at->number);
1923 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1924 printf_filtered ("unloaded");
1925 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1926 return PRINT_SRC_AND_LOC;
1930 annotate_catchpoint (bs->breakpoint_at->number);
1931 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1932 printf_filtered ("forked");
1933 printf_filtered (" process %d), ",
1934 bs->breakpoint_at->forked_inferior_pid);
1935 return PRINT_SRC_AND_LOC;
1938 case bp_catch_vfork:
1939 annotate_catchpoint (bs->breakpoint_at->number);
1940 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1941 printf_filtered ("vforked");
1942 printf_filtered (" process %d), ",
1943 bs->breakpoint_at->forked_inferior_pid);
1944 return PRINT_SRC_AND_LOC;
1948 annotate_catchpoint (bs->breakpoint_at->number);
1949 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1950 bs->breakpoint_at->number,
1951 bs->breakpoint_at->exec_pathname);
1952 return PRINT_SRC_AND_LOC;
1955 case bp_catch_catch:
1956 if (current_exception_event &&
1957 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1959 annotate_catchpoint (bs->breakpoint_at->number);
1960 printf_filtered ("\nCatchpoint %d (exception caught), ",
1961 bs->breakpoint_at->number);
1962 printf_filtered ("throw location ");
1963 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1964 printf_filtered ("%s:%d",
1965 CURRENT_EXCEPTION_THROW_FILE,
1966 CURRENT_EXCEPTION_THROW_LINE);
1968 printf_filtered ("unknown");
1970 printf_filtered (", catch location ");
1971 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1972 printf_filtered ("%s:%d",
1973 CURRENT_EXCEPTION_CATCH_FILE,
1974 CURRENT_EXCEPTION_CATCH_LINE);
1976 printf_filtered ("unknown");
1978 printf_filtered ("\n");
1979 /* don't bother to print location frame info */
1980 return PRINT_SRC_ONLY;
1984 /* really throw, some other bpstat will handle it */
1985 return PRINT_UNKNOWN;
1989 case bp_catch_throw:
1990 if (current_exception_event &&
1991 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1993 annotate_catchpoint (bs->breakpoint_at->number);
1994 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1995 bs->breakpoint_at->number);
1996 printf_filtered ("throw location ");
1997 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1998 printf_filtered ("%s:%d",
1999 CURRENT_EXCEPTION_THROW_FILE,
2000 CURRENT_EXCEPTION_THROW_LINE);
2002 printf_filtered ("unknown");
2004 printf_filtered (", catch location ");
2005 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2006 printf_filtered ("%s:%d",
2007 CURRENT_EXCEPTION_CATCH_FILE,
2008 CURRENT_EXCEPTION_CATCH_LINE);
2010 printf_filtered ("unknown");
2012 printf_filtered ("\n");
2013 /* don't bother to print location frame info */
2014 return PRINT_SRC_ONLY;
2018 /* really catch, some other bpstat will handle it */
2019 return PRINT_UNKNOWN;
2024 case bp_hardware_watchpoint:
2025 if (bs->old_val != NULL)
2027 annotate_watchpoint (bs->breakpoint_at->number);
2028 if (ui_out_is_mi_like_p (uiout))
2029 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2030 mention (bs->breakpoint_at);
2031 ui_out_tuple_begin (uiout, "value");
2032 ui_out_text (uiout, "\nOld value = ");
2033 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2034 ui_out_field_stream (uiout, "old", stb);
2035 ui_out_text (uiout, "\nNew value = ");
2036 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2037 ui_out_field_stream (uiout, "new", stb);
2038 ui_out_tuple_end (uiout);
2039 ui_out_text (uiout, "\n");
2040 value_free (bs->old_val);
2043 /* More than one watchpoint may have been triggered. */
2044 return PRINT_UNKNOWN;
2047 case bp_read_watchpoint:
2048 if (ui_out_is_mi_like_p (uiout))
2049 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2050 mention (bs->breakpoint_at);
2051 ui_out_tuple_begin (uiout, "value");
2052 ui_out_text (uiout, "\nValue = ");
2053 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2054 ui_out_field_stream (uiout, "value", stb);
2055 ui_out_tuple_end (uiout);
2056 ui_out_text (uiout, "\n");
2057 return PRINT_UNKNOWN;
2060 case bp_access_watchpoint:
2061 if (bs->old_val != NULL)
2063 annotate_watchpoint (bs->breakpoint_at->number);
2064 if (ui_out_is_mi_like_p (uiout))
2065 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2066 mention (bs->breakpoint_at);
2067 ui_out_tuple_begin (uiout, "value");
2068 ui_out_text (uiout, "\nOld value = ");
2069 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2070 ui_out_field_stream (uiout, "old", stb);
2071 value_free (bs->old_val);
2073 ui_out_text (uiout, "\nNew value = ");
2077 mention (bs->breakpoint_at);
2078 if (ui_out_is_mi_like_p (uiout))
2079 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2080 ui_out_tuple_begin (uiout, "value");
2081 ui_out_text (uiout, "\nValue = ");
2083 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2084 ui_out_field_stream (uiout, "new", stb);
2085 ui_out_tuple_end (uiout);
2086 ui_out_text (uiout, "\n");
2087 return PRINT_UNKNOWN;
2090 /* Fall through, we don't deal with these types of breakpoints
2094 if (ui_out_is_mi_like_p (uiout))
2095 ui_out_field_string (uiout, "reason", "function-finished");
2096 return PRINT_UNKNOWN;
2100 if (ui_out_is_mi_like_p (uiout))
2101 ui_out_field_string (uiout, "reason", "location-reached");
2102 return PRINT_UNKNOWN;
2107 case bp_longjmp_resume:
2108 case bp_step_resume:
2109 case bp_through_sigtramp:
2110 case bp_watchpoint_scope:
2113 return PRINT_UNKNOWN;
2117 /* Generic routine for printing messages indicating why we
2118 stopped. The behavior of this function depends on the value
2119 'print_it' in the bpstat structure. Under some circumstances we
2120 may decide not to print anything here and delegate the task to
2123 static enum print_stop_action
2124 print_bp_stop_message (bpstat bs)
2126 switch (bs->print_it)
2129 /* Nothing should be printed for this bpstat entry. */
2130 return PRINT_UNKNOWN;
2134 /* We still want to print the frame, but we already printed the
2135 relevant messages. */
2136 return PRINT_SRC_AND_LOC;
2139 case print_it_normal:
2140 /* Normal case, we handle everything in print_it_typical. */
2141 return print_it_typical (bs);
2144 internal_error (__FILE__, __LINE__,
2145 "print_bp_stop_message: unrecognized enum value");
2150 /* Print a message indicating what happened. This is called from
2151 normal_stop(). The input to this routine is the head of the bpstat
2152 list - a list of the eventpoints that caused this stop. This
2153 routine calls the generic print routine for printing a message
2154 about reasons for stopping. This will print (for example) the
2155 "Breakpoint n," part of the output. The return value of this
2158 PRINT_UNKNOWN: Means we printed nothing
2159 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2160 code to print the location. An example is
2161 "Breakpoint 1, " which should be followed by
2163 PRINT_SRC_ONLY: Means we printed something, but there is no need
2164 to also print the location part of the message.
2165 An example is the catch/throw messages, which
2166 don't require a location appended to the end.
2167 PRINT_NOTHING: We have done some printing and we don't need any
2168 further info to be printed.*/
2170 enum print_stop_action
2171 bpstat_print (bpstat bs)
2175 /* Maybe another breakpoint in the chain caused us to stop.
2176 (Currently all watchpoints go on the bpstat whether hit or not.
2177 That probably could (should) be changed, provided care is taken
2178 with respect to bpstat_explains_signal). */
2179 for (; bs; bs = bs->next)
2181 val = print_bp_stop_message (bs);
2182 if (val == PRINT_SRC_ONLY
2183 || val == PRINT_SRC_AND_LOC
2184 || val == PRINT_NOTHING)
2188 /* We reached the end of the chain, or we got a null BS to start
2189 with and nothing was printed. */
2190 return PRINT_UNKNOWN;
2193 /* Evaluate the expression EXP and return 1 if value is zero.
2194 This is used inside a catch_errors to evaluate the breakpoint condition.
2195 The argument is a "struct expression *" that has been cast to char * to
2196 make it pass through catch_errors. */
2199 breakpoint_cond_eval (PTR exp)
2201 struct value *mark = value_mark ();
2202 int i = !value_true (evaluate_expression ((struct expression *) exp));
2203 value_free_to_mark (mark);
2207 /* Allocate a new bpstat and chain it to the current one. */
2210 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2214 bs = (bpstat) xmalloc (sizeof (*bs));
2216 bs->breakpoint_at = b;
2217 /* If the condition is false, etc., don't do the commands. */
2218 bs->commands = NULL;
2220 bs->print_it = print_it_normal;
2224 /* Possible return values for watchpoint_check (this can't be an enum
2225 because of check_errors). */
2226 /* The watchpoint has been deleted. */
2227 #define WP_DELETED 1
2228 /* The value has changed. */
2229 #define WP_VALUE_CHANGED 2
2230 /* The value has not changed. */
2231 #define WP_VALUE_NOT_CHANGED 3
2233 #define BP_TEMPFLAG 1
2234 #define BP_HARDWAREFLAG 2
2236 /* Check watchpoint condition. */
2239 watchpoint_check (PTR p)
2241 bpstat bs = (bpstat) p;
2242 struct breakpoint *b;
2243 struct frame_info *fr;
2244 int within_current_scope;
2246 b = bs->breakpoint_at;
2248 if (b->exp_valid_block == NULL)
2249 within_current_scope = 1;
2252 /* There is no current frame at this moment. If we're going to have
2253 any chance of handling watchpoints on local variables, we'll need
2254 the frame chain (so we can determine if we're in scope). */
2255 reinit_frame_cache ();
2256 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2257 within_current_scope = (fr != NULL);
2258 /* in_function_epilogue_p() returns a non-zero value if we're still
2259 in the function but the stack frame has already been invalidated.
2260 Since we can't rely on the values of local variables after the
2261 stack has been destroyed, we are treating the watchpoint in that
2262 state as `not changed' without further checking. */
2263 if (within_current_scope && fr == get_current_frame ()
2264 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2265 return WP_VALUE_NOT_CHANGED;
2266 if (within_current_scope)
2267 /* If we end up stopping, the current frame will get selected
2268 in normal_stop. So this call to select_frame won't affect
2270 select_frame (fr, -1);
2273 if (within_current_scope)
2275 /* We use value_{,free_to_}mark because it could be a
2276 *long* time before we return to the command level and
2277 call free_all_values. We can't call free_all_values because
2278 we might be in the middle of evaluating a function call. */
2280 struct value *mark = value_mark ();
2281 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2282 if (!value_equal (b->val, new_val))
2284 release_value (new_val);
2285 value_free_to_mark (mark);
2286 bs->old_val = b->val;
2288 /* We will stop here */
2289 return WP_VALUE_CHANGED;
2293 /* Nothing changed, don't do anything. */
2294 value_free_to_mark (mark);
2295 /* We won't stop here */
2296 return WP_VALUE_NOT_CHANGED;
2301 /* This seems like the only logical thing to do because
2302 if we temporarily ignored the watchpoint, then when
2303 we reenter the block in which it is valid it contains
2304 garbage (in the case of a function, it may have two
2305 garbage values, one before and one after the prologue).
2306 So we can't even detect the first assignment to it and
2307 watch after that (since the garbage may or may not equal
2308 the first value assigned). */
2309 /* We print all the stop information in print_it_typical(), but
2310 in this case, by the time we call print_it_typical() this bp
2311 will be deleted already. So we have no choice but print the
2312 information here. */
2313 if (ui_out_is_mi_like_p (uiout))
2314 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2315 ui_out_text (uiout, "\nWatchpoint ");
2316 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2317 ui_out_text (uiout, " deleted because the program has left the block in\n\
2318 which its expression is valid.\n");
2320 if (b->related_breakpoint)
2321 b->related_breakpoint->disposition = disp_del_at_next_stop;
2322 b->disposition = disp_del_at_next_stop;
2328 /* Get a bpstat associated with having just stopped at address *PC
2329 and frame address CORE_ADDRESS. Update *PC to point at the
2330 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2331 if this is known to not be a real breakpoint (it could still be a
2332 watchpoint, though). */
2334 /* Determine whether we stopped at a breakpoint, etc, or whether we
2335 don't understand this stop. Result is a chain of bpstat's such that:
2337 if we don't understand the stop, the result is a null pointer.
2339 if we understand why we stopped, the result is not null.
2341 Each element of the chain refers to a particular breakpoint or
2342 watchpoint at which we have stopped. (We may have stopped for
2343 several reasons concurrently.)
2345 Each element of the chain has valid next, breakpoint_at,
2346 commands, FIXME??? fields. */
2349 bpstat_stop_status (CORE_ADDR *pc, int not_a_breakpoint)
2351 register struct breakpoint *b, *temp;
2353 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2354 int real_breakpoint = 0;
2355 /* Root of the chain of bpstat's */
2356 struct bpstats root_bs[1];
2357 /* Pointer to the last thing in the chain currently. */
2358 bpstat bs = root_bs;
2359 static char message1[] =
2360 "Error evaluating expression for watchpoint %d\n";
2361 char message[sizeof (message1) + 30 /* slop */ ];
2363 /* Get the address where the breakpoint would have been.
2364 The "not_a_breakpoint" argument is meant to distinguish
2365 between a breakpoint trap event and a trace/singlestep
2366 trap event. For a trace/singlestep trap event, we would
2367 not want to subtract DECR_PC_AFTER_BREAK from the PC. */
2369 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P () ?
2370 0 : DECR_PC_AFTER_BREAK);
2372 ALL_BREAKPOINTS_SAFE (b, temp)
2374 if (b->enable_state == bp_disabled
2375 || b->enable_state == bp_shlib_disabled
2376 || b->enable_state == bp_call_disabled)
2379 if (b->type != bp_watchpoint
2380 && b->type != bp_hardware_watchpoint
2381 && b->type != bp_read_watchpoint
2382 && b->type != bp_access_watchpoint
2383 && b->type != bp_hardware_breakpoint
2384 && b->type != bp_catch_fork
2385 && b->type != bp_catch_vfork
2386 && b->type != bp_catch_exec
2387 && b->type != bp_catch_catch
2388 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2390 if (b->address != bp_addr) /* address doesn't match */
2392 if (overlay_debugging /* unmapped overlay section */
2393 && section_is_overlay (b->section)
2394 && !section_is_mapped (b->section))
2398 if (b->type == bp_hardware_breakpoint
2399 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2402 /* Is this a catchpoint of a load or unload? If so, did we
2403 get a load or unload of the specified library? If not,
2405 if ((b->type == bp_catch_load)
2406 #if defined(SOLIB_HAVE_LOAD_EVENT)
2407 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2408 || ((b->dll_pathname != NULL)
2409 && (strcmp (b->dll_pathname,
2410 SOLIB_LOADED_LIBRARY_PATHNAME (
2411 PIDGET (inferior_ptid)))
2417 if ((b->type == bp_catch_unload)
2418 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2419 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2420 || ((b->dll_pathname != NULL)
2421 && (strcmp (b->dll_pathname,
2422 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2423 PIDGET (inferior_ptid)))
2429 if ((b->type == bp_catch_fork)
2430 && !target_has_forked (PIDGET (inferior_ptid),
2431 &b->forked_inferior_pid))
2434 if ((b->type == bp_catch_vfork)
2435 && !target_has_vforked (PIDGET (inferior_ptid),
2436 &b->forked_inferior_pid))
2439 if ((b->type == bp_catch_exec)
2440 && !target_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2443 if (ep_is_exception_catchpoint (b) &&
2444 !(current_exception_event = target_get_current_exception_event ()))
2447 /* Come here if it's a watchpoint, or if the break address matches */
2449 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2451 /* Watchpoints may change this, if not found to have triggered. */
2455 sprintf (message, message1, b->number);
2456 if (b->type == bp_watchpoint ||
2457 b->type == bp_hardware_watchpoint)
2459 switch (catch_errors (watchpoint_check, bs, message,
2463 /* We've already printed what needs to be printed. */
2464 /* Actually this is superfluous, because by the time we
2465 call print_it_typical() the wp will be already deleted,
2466 and the function will return immediately. */
2467 bs->print_it = print_it_done;
2470 case WP_VALUE_CHANGED:
2474 case WP_VALUE_NOT_CHANGED:
2476 bs->print_it = print_it_noop;
2483 /* Error from catch_errors. */
2484 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2485 if (b->related_breakpoint)
2486 b->related_breakpoint->disposition = disp_del_at_next_stop;
2487 b->disposition = disp_del_at_next_stop;
2488 /* We've already printed what needs to be printed. */
2489 bs->print_it = print_it_done;
2495 else if (b->type == bp_read_watchpoint ||
2496 b->type == bp_access_watchpoint)
2502 addr = target_stopped_data_address ();
2505 for (v = b->val_chain; v; v = v->next)
2507 if (VALUE_LVAL (v) == lval_memory
2508 && ! VALUE_LAZY (v))
2510 struct type *vtype = check_typedef (VALUE_TYPE (v));
2512 if (v == b->val_chain
2513 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2514 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2518 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2519 /* Exact match not required. Within range is
2521 if (addr >= vaddr &&
2522 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2528 switch (catch_errors (watchpoint_check, bs, message,
2532 /* We've already printed what needs to be printed. */
2533 bs->print_it = print_it_done;
2536 case WP_VALUE_CHANGED:
2537 if (b->type == bp_read_watchpoint)
2539 /* Don't stop: read watchpoints shouldn't fire if
2540 the value has changed. This is for targets which
2541 cannot set read-only watchpoints. */
2542 bs->print_it = print_it_noop;
2548 case WP_VALUE_NOT_CHANGED:
2555 /* Error from catch_errors. */
2556 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2557 if (b->related_breakpoint)
2558 b->related_breakpoint->disposition = disp_del_at_next_stop;
2559 b->disposition = disp_del_at_next_stop;
2560 /* We've already printed what needs to be printed. */
2561 bs->print_it = print_it_done;
2564 else /* found == 0 */
2566 /* This is a case where some watchpoint(s) triggered,
2567 but not at the address of this watchpoint (FOUND
2568 was left zero). So don't print anything for this
2570 bs->print_it = print_it_noop;
2577 /* By definition, an encountered breakpoint is a triggered
2581 real_breakpoint = 1;
2585 b->frame != (get_current_frame ())->frame)
2589 int value_is_zero = 0;
2593 /* Need to select the frame, with all that implies
2594 so that the conditions will have the right context. */
2595 select_frame (get_current_frame (), 0);
2597 = catch_errors (breakpoint_cond_eval, (b->cond),
2598 "Error in testing breakpoint condition:\n",
2600 /* FIXME-someday, should give breakpoint # */
2603 if (b->cond && value_is_zero)
2606 /* Don't consider this a hit. */
2609 else if (b->ignore_count > 0)
2612 annotate_ignore_count_change ();
2617 /* We will stop here */
2618 if (b->disposition == disp_disable)
2619 b->enable_state = bp_disabled;
2620 bs->commands = b->commands;
2624 (STREQ ("silent", bs->commands->line) ||
2625 (xdb_commands && STREQ ("Q", bs->commands->line))))
2627 bs->commands = bs->commands->next;
2632 /* Print nothing for this entry if we dont stop or if we dont print. */
2633 if (bs->stop == 0 || bs->print == 0)
2634 bs->print_it = print_it_noop;
2637 bs->next = NULL; /* Terminate the chain */
2638 bs = root_bs->next; /* Re-grab the head of the chain */
2640 if (real_breakpoint && bs)
2642 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2644 if (DECR_PC_AFTER_HW_BREAK != 0)
2646 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2652 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2655 #if defined (SHIFT_INST_REGS)
2657 #else /* No SHIFT_INST_REGS. */
2659 #endif /* No SHIFT_INST_REGS. */
2664 /* The value of a hardware watchpoint hasn't changed, but the
2665 intermediate memory locations we are watching may have. */
2666 if (bs && !bs->stop &&
2667 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2668 bs->breakpoint_at->type == bp_read_watchpoint ||
2669 bs->breakpoint_at->type == bp_access_watchpoint))
2671 remove_breakpoints ();
2672 insert_breakpoints ();
2677 /* Tell what to do about this bpstat. */
2679 bpstat_what (bpstat bs)
2681 /* Classify each bpstat as one of the following. */
2684 /* This bpstat element has no effect on the main_action. */
2687 /* There was a watchpoint, stop but don't print. */
2690 /* There was a watchpoint, stop and print. */
2693 /* There was a breakpoint but we're not stopping. */
2696 /* There was a breakpoint, stop but don't print. */
2699 /* There was a breakpoint, stop and print. */
2702 /* We hit the longjmp breakpoint. */
2705 /* We hit the longjmp_resume breakpoint. */
2708 /* We hit the step_resume breakpoint. */
2711 /* We hit the through_sigtramp breakpoint. */
2714 /* We hit the shared library event breakpoint. */
2717 /* We caught a shared library event. */
2720 /* This is just used to count how many enums there are. */
2724 /* Here is the table which drives this routine. So that we can
2725 format it pretty, we define some abbreviations for the
2726 enum bpstat_what codes. */
2727 #define kc BPSTAT_WHAT_KEEP_CHECKING
2728 #define ss BPSTAT_WHAT_STOP_SILENT
2729 #define sn BPSTAT_WHAT_STOP_NOISY
2730 #define sgl BPSTAT_WHAT_SINGLE
2731 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2732 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2733 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2734 #define sr BPSTAT_WHAT_STEP_RESUME
2735 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2736 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2737 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2739 /* "Can't happen." Might want to print an error message.
2740 abort() is not out of the question, but chances are GDB is just
2741 a bit confused, not unusable. */
2742 #define err BPSTAT_WHAT_STOP_NOISY
2744 /* Given an old action and a class, come up with a new action. */
2745 /* One interesting property of this table is that wp_silent is the same
2746 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2747 after stopping, the check for whether to step over a breakpoint
2748 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2749 reference to how we stopped. We retain separate wp_silent and
2750 bp_silent codes in case we want to change that someday.
2752 Another possibly interesting property of this table is that
2753 there's a partial ordering, priority-like, of the actions. Once
2754 you've decided that some action is appropriate, you'll never go
2755 back and decide something of a lower priority is better. The
2758 kc < clr sgl shl shlr slr sn sr ss ts
2759 sgl < clrs shl shlr slr sn sr ss ts
2760 slr < err shl shlr sn sr ss ts
2761 clr < clrs err shl shlr sn sr ss ts
2762 clrs < err shl shlr sn sr ss ts
2763 ss < shl shlr sn sr ts
2770 What I think this means is that we don't need a damned table
2771 here. If you just put the rows and columns in the right order,
2772 it'd look awfully regular. We could simply walk the bpstat list
2773 and choose the highest priority action we find, with a little
2774 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2775 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2776 is messy anyway). */
2778 /* step_resume entries: a step resume breakpoint overrides another
2779 breakpoint of signal handling (see comment in wait_for_inferior
2780 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2781 /* We handle the through_sigtramp_breakpoint the same way; having both
2782 one of those and a step_resume_breakpoint is probably very rare (?). */
2784 static const enum bpstat_what_main_action
2785 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2788 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2791 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2793 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2795 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2797 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2799 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2801 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2803 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2805 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2807 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2809 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2811 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2813 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2828 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2829 struct bpstat_what retval;
2831 retval.call_dummy = 0;
2832 for (; bs != NULL; bs = bs->next)
2834 enum class bs_class = no_effect;
2835 if (bs->breakpoint_at == NULL)
2836 /* I suspect this can happen if it was a momentary breakpoint
2837 which has since been deleted. */
2839 switch (bs->breakpoint_at->type)
2845 case bp_hardware_breakpoint:
2851 bs_class = bp_noisy;
2853 bs_class = bp_silent;
2856 bs_class = bp_nostop;
2859 case bp_hardware_watchpoint:
2860 case bp_read_watchpoint:
2861 case bp_access_watchpoint:
2865 bs_class = wp_noisy;
2867 bs_class = wp_silent;
2870 /* There was a watchpoint, but we're not stopping.
2871 This requires no further action. */
2872 bs_class = no_effect;
2875 bs_class = long_jump;
2877 case bp_longjmp_resume:
2878 bs_class = long_resume;
2880 case bp_step_resume:
2883 bs_class = step_resume;
2886 /* It is for the wrong frame. */
2887 bs_class = bp_nostop;
2889 case bp_through_sigtramp:
2890 bs_class = through_sig;
2892 case bp_watchpoint_scope:
2893 bs_class = bp_nostop;
2895 case bp_shlib_event:
2896 bs_class = shlib_event;
2898 case bp_thread_event:
2899 bs_class = bp_nostop;
2902 case bp_catch_unload:
2903 /* Only if this catchpoint triggered should we cause the
2904 step-out-of-dld behaviour. Otherwise, we ignore this
2907 bs_class = catch_shlib_event;
2909 bs_class = no_effect;
2912 case bp_catch_vfork:
2917 bs_class = bp_noisy;
2919 bs_class = bp_silent;
2922 /* There was a catchpoint, but we're not stopping.
2923 This requires no further action. */
2924 bs_class = no_effect;
2926 case bp_catch_catch:
2927 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2928 bs_class = bp_nostop;
2930 bs_class = bs->print ? bp_noisy : bp_silent;
2932 case bp_catch_throw:
2933 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2934 bs_class = bp_nostop;
2936 bs_class = bs->print ? bp_noisy : bp_silent;
2939 /* Make sure the action is stop (silent or noisy),
2940 so infrun.c pops the dummy frame. */
2941 bs_class = bp_silent;
2942 retval.call_dummy = 1;
2945 current_action = table[(int) bs_class][(int) current_action];
2947 retval.main_action = current_action;
2951 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2952 without hardware support). This isn't related to a specific bpstat,
2953 just to things like whether watchpoints are set. */
2956 bpstat_should_step (void)
2958 struct breakpoint *b;
2960 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
2965 /* Nonzero if there are enabled hardware watchpoints. */
2967 bpstat_have_active_hw_watchpoints (void)
2969 struct breakpoint *b;
2971 if ((b->enable_state == bp_enabled) &&
2973 ((b->type == bp_hardware_watchpoint) ||
2974 (b->type == bp_read_watchpoint) ||
2975 (b->type == bp_access_watchpoint)))
2981 /* Given a bpstat that records zero or more triggered eventpoints, this
2982 function returns another bpstat which contains only the catchpoints
2983 on that first list, if any. */
2985 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
2987 struct bpstats root_bs[1];
2988 bpstat bs = root_bs;
2989 struct breakpoint *ep;
2992 bpstat_clear (cp_list);
2993 root_bs->next = NULL;
2995 for (; ep_list != NULL; ep_list = ep_list->next)
2997 /* Is this eventpoint a catchpoint? If not, ignore it. */
2998 ep = ep_list->breakpoint_at;
3001 if ((ep->type != bp_catch_load) &&
3002 (ep->type != bp_catch_unload) &&
3003 (ep->type != bp_catch_catch) &&
3004 (ep->type != bp_catch_throw))
3005 /* pai: (temp) ADD fork/vfork here!! */
3008 /* Yes; add it to the list. */
3009 bs = bpstat_alloc (ep, bs);
3014 #if defined(SOLIB_ADD)
3015 /* Also, for each triggered catchpoint, tag it with the name of
3016 the library that caused this trigger. (We copy the name now,
3017 because it's only guaranteed to be available NOW, when the
3018 catchpoint triggers. Clients who may wish to know the name
3019 later must get it from the catchpoint itself.) */
3020 if (ep->triggered_dll_pathname != NULL)
3021 xfree (ep->triggered_dll_pathname);
3022 if (ep->type == bp_catch_load)
3023 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3024 PIDGET (inferior_ptid));
3026 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3027 PIDGET (inferior_ptid));
3029 dll_pathname = NULL;
3033 ep->triggered_dll_pathname = (char *)
3034 xmalloc (strlen (dll_pathname) + 1);
3035 strcpy (ep->triggered_dll_pathname, dll_pathname);
3038 ep->triggered_dll_pathname = NULL;
3044 /* Print B to gdb_stdout. */
3046 print_one_breakpoint (struct breakpoint *b,
3047 CORE_ADDR *last_addr)
3049 register struct command_line *l;
3050 register struct symbol *sym;
3051 struct ep_type_description
3056 static struct ep_type_description bptypes[] =
3058 {bp_none, "?deleted?"},
3059 {bp_breakpoint, "breakpoint"},
3060 {bp_hardware_breakpoint, "hw breakpoint"},
3061 {bp_until, "until"},
3062 {bp_finish, "finish"},
3063 {bp_watchpoint, "watchpoint"},
3064 {bp_hardware_watchpoint, "hw watchpoint"},
3065 {bp_read_watchpoint, "read watchpoint"},
3066 {bp_access_watchpoint, "acc watchpoint"},
3067 {bp_longjmp, "longjmp"},
3068 {bp_longjmp_resume, "longjmp resume"},
3069 {bp_step_resume, "step resume"},
3070 {bp_through_sigtramp, "sigtramp"},
3071 {bp_watchpoint_scope, "watchpoint scope"},
3072 {bp_call_dummy, "call dummy"},
3073 {bp_shlib_event, "shlib events"},
3074 {bp_thread_event, "thread events"},
3075 {bp_catch_load, "catch load"},
3076 {bp_catch_unload, "catch unload"},
3077 {bp_catch_fork, "catch fork"},
3078 {bp_catch_vfork, "catch vfork"},
3079 {bp_catch_exec, "catch exec"},
3080 {bp_catch_catch, "catch catch"},
3081 {bp_catch_throw, "catch throw"}
3084 static char *bpdisps[] =
3085 {"del", "dstp", "dis", "keep"};
3086 static char bpenables[] = "nynny";
3087 char wrap_indent[80];
3088 struct ui_stream *stb = ui_out_stream_new (uiout);
3089 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3092 ui_out_tuple_begin (uiout, "bkpt");
3096 ui_out_field_int (uiout, "number", b->number);
3100 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3101 || ((int) b->type != bptypes[(int) b->type].type))
3102 internal_error (__FILE__, __LINE__,
3103 "bptypes table does not describe type #%d.",
3105 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3109 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3113 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3114 ui_out_spaces (uiout, 2);
3117 strcpy (wrap_indent, " ");
3120 if (TARGET_ADDR_BIT <= 32)
3121 strcat (wrap_indent, " ");
3123 strcat (wrap_indent, " ");
3128 internal_error (__FILE__, __LINE__,
3129 "print_one_breakpoint: bp_none encountered\n");
3133 case bp_hardware_watchpoint:
3134 case bp_read_watchpoint:
3135 case bp_access_watchpoint:
3136 /* Field 4, the address, is omitted (which makes the columns
3137 not line up too nicely with the headers, but the effect
3138 is relatively readable). */
3140 ui_out_field_skip (uiout, "addr");
3142 print_expression (b->exp, stb->stream);
3143 ui_out_field_stream (uiout, "what", stb);
3147 case bp_catch_unload:
3148 /* Field 4, the address, is omitted (which makes the columns
3149 not line up too nicely with the headers, but the effect
3150 is relatively readable). */
3152 ui_out_field_skip (uiout, "addr");
3154 if (b->dll_pathname == NULL)
3156 ui_out_field_string (uiout, "what", "<any library>");
3157 ui_out_spaces (uiout, 1);
3161 ui_out_text (uiout, "library \"");
3162 ui_out_field_string (uiout, "what", b->dll_pathname);
3163 ui_out_text (uiout, "\" ");
3168 case bp_catch_vfork:
3169 /* Field 4, the address, is omitted (which makes the columns
3170 not line up too nicely with the headers, but the effect
3171 is relatively readable). */
3173 ui_out_field_skip (uiout, "addr");
3175 if (b->forked_inferior_pid != 0)
3177 ui_out_text (uiout, "process ");
3178 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3179 ui_out_spaces (uiout, 1);
3183 /* Field 4, the address, is omitted (which makes the columns
3184 not line up too nicely with the headers, but the effect
3185 is relatively readable). */
3187 ui_out_field_skip (uiout, "addr");
3189 if (b->exec_pathname != NULL)
3191 ui_out_text (uiout, "program \"");
3192 ui_out_field_string (uiout, "what", b->exec_pathname);
3193 ui_out_text (uiout, "\" ");
3197 case bp_catch_catch:
3198 /* Field 4, the address, is omitted (which makes the columns
3199 not line up too nicely with the headers, but the effect
3200 is relatively readable). */
3202 ui_out_field_skip (uiout, "addr");
3204 ui_out_field_string (uiout, "what", "exception catch");
3205 ui_out_spaces (uiout, 1);
3208 case bp_catch_throw:
3209 /* Field 4, the address, is omitted (which makes the columns
3210 not line up too nicely with the headers, but the effect
3211 is relatively readable). */
3213 ui_out_field_skip (uiout, "addr");
3215 ui_out_field_string (uiout, "what", "exception throw");
3216 ui_out_spaces (uiout, 1);
3220 case bp_hardware_breakpoint:
3224 case bp_longjmp_resume:
3225 case bp_step_resume:
3226 case bp_through_sigtramp:
3227 case bp_watchpoint_scope:
3229 case bp_shlib_event:
3230 case bp_thread_event:
3234 ui_out_field_core_addr (uiout, "addr", b->address);
3237 *last_addr = b->address;
3240 sym = find_pc_sect_function (b->address, b->section);
3243 ui_out_text (uiout, "in ");
3244 ui_out_field_string (uiout, "func",
3245 SYMBOL_SOURCE_NAME (sym));
3246 ui_out_wrap_hint (uiout, wrap_indent);
3247 ui_out_text (uiout, " at ");
3249 ui_out_field_string (uiout, "file", b->source_file);
3250 ui_out_text (uiout, ":");
3251 ui_out_field_int (uiout, "line", b->line_number);
3255 print_address_symbolic (b->address, stb->stream, demangle, "");
3256 ui_out_field_stream (uiout, "at", stb);
3261 if (b->thread != -1)
3263 /* FIXME: This seems to be redundant and lost here; see the
3264 "stop only in" line a little further down. */
3265 ui_out_text (uiout, " thread ");
3266 ui_out_field_int (uiout, "thread", b->thread);
3269 ui_out_text (uiout, "\n");
3274 ui_out_text (uiout, "\tstop only in stack frame at ");
3275 ui_out_field_core_addr (uiout, "frame", b->frame);
3276 ui_out_text (uiout, "\n");
3282 ui_out_text (uiout, "\tstop only if ");
3283 print_expression (b->cond, stb->stream);
3284 ui_out_field_stream (uiout, "cond", stb);
3285 ui_out_text (uiout, "\n");
3288 if (b->thread != -1)
3290 /* FIXME should make an annotation for this */
3291 ui_out_text (uiout, "\tstop only in thread ");
3292 ui_out_field_int (uiout, "thread", b->thread);
3293 ui_out_text (uiout, "\n");
3296 if (show_breakpoint_hit_counts && b->hit_count)
3298 /* FIXME should make an annotation for this */
3299 if (ep_is_catchpoint (b))
3300 ui_out_text (uiout, "\tcatchpoint");
3302 ui_out_text (uiout, "\tbreakpoint");
3303 ui_out_text (uiout, " already hit ");
3304 ui_out_field_int (uiout, "times", b->hit_count);
3305 if (b->hit_count == 1)
3306 ui_out_text (uiout, " time\n");
3308 ui_out_text (uiout, " times\n");
3311 /* Output the count also if it is zero, but only if this is
3312 mi. FIXME: Should have a better test for this. */
3313 if (ui_out_is_mi_like_p (uiout))
3314 if (show_breakpoint_hit_counts && b->hit_count == 0)
3315 ui_out_field_int (uiout, "times", b->hit_count);
3317 if (b->ignore_count)
3320 ui_out_text (uiout, "\tignore next ");
3321 ui_out_field_int (uiout, "ignore", b->ignore_count);
3322 ui_out_text (uiout, " hits\n");
3325 if ((l = b->commands))
3328 ui_out_tuple_begin (uiout, "script");
3329 print_command_lines (uiout, l, 4);
3330 ui_out_tuple_end (uiout);
3332 ui_out_tuple_end (uiout);
3333 do_cleanups (old_chain);
3336 struct captured_breakpoint_query_args
3342 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3344 struct captured_breakpoint_query_args *args = data;
3345 register struct breakpoint *b;
3346 CORE_ADDR dummy_addr = 0;
3349 if (args->bnum == b->number)
3351 print_one_breakpoint (b, &dummy_addr);
3359 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3361 struct captured_breakpoint_query_args args;
3363 /* For the moment we don't trust print_one_breakpoint() to not throw
3365 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3366 NULL, RETURN_MASK_ALL);
3369 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3370 catchpoints, et.al.). */
3373 user_settable_breakpoint (const struct breakpoint *b)
3375 return (b->type == bp_breakpoint
3376 || b->type == bp_catch_load
3377 || b->type == bp_catch_unload
3378 || b->type == bp_catch_fork
3379 || b->type == bp_catch_vfork
3380 || b->type == bp_catch_exec
3381 || b->type == bp_catch_catch
3382 || b->type == bp_catch_throw
3383 || b->type == bp_hardware_breakpoint
3384 || b->type == bp_watchpoint
3385 || b->type == bp_read_watchpoint
3386 || b->type == bp_access_watchpoint
3387 || b->type == bp_hardware_watchpoint);
3390 /* Print information on user settable breakpoint (watchpoint, etc)
3391 number BNUM. If BNUM is -1 print all user settable breakpoints.
3392 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3395 breakpoint_1 (int bnum, int allflag)
3397 register struct breakpoint *b;
3398 CORE_ADDR last_addr = (CORE_ADDR) -1;
3399 int nr_printable_breakpoints;
3401 /* Compute the number of rows in the table. */
3402 nr_printable_breakpoints = 0;
3405 || bnum == b->number)
3407 if (allflag || user_settable_breakpoint (b))
3408 nr_printable_breakpoints++;
3412 ui_out_table_begin (uiout, 6, nr_printable_breakpoints, "BreakpointTable");
3414 ui_out_table_begin (uiout, 5, nr_printable_breakpoints, "BreakpointTable");
3416 if (nr_printable_breakpoints > 0)
3417 annotate_breakpoints_headers ();
3418 if (nr_printable_breakpoints > 0)
3420 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3421 if (nr_printable_breakpoints > 0)
3423 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3424 if (nr_printable_breakpoints > 0)
3426 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3427 if (nr_printable_breakpoints > 0)
3429 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3432 if (nr_printable_breakpoints > 0)
3434 if (TARGET_ADDR_BIT <= 32)
3435 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3437 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3439 if (nr_printable_breakpoints > 0)
3441 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3442 ui_out_table_body (uiout);
3443 if (nr_printable_breakpoints > 0)
3444 annotate_breakpoints_table ();
3448 || bnum == b->number)
3450 /* We only print out user settable breakpoints unless the
3452 if (allflag || user_settable_breakpoint (b))
3453 print_one_breakpoint (b, &last_addr);
3456 ui_out_table_end (uiout);
3458 if (nr_printable_breakpoints == 0)
3461 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3463 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3468 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3469 that a comparison of an unsigned with -1 is always false. */
3470 if (last_addr != (CORE_ADDR) -1)
3471 set_next_address (last_addr);
3474 /* FIXME? Should this be moved up so that it is only called when
3475 there have been breakpoints? */
3476 annotate_breakpoints_table_end ();
3481 breakpoints_info (char *bnum_exp, int from_tty)
3486 bnum = parse_and_eval_long (bnum_exp);
3488 breakpoint_1 (bnum, 0);
3493 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3498 bnum = parse_and_eval_long (bnum_exp);
3500 breakpoint_1 (bnum, 1);
3503 /* Print a message describing any breakpoints set at PC. */
3506 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3508 register int others = 0;
3509 register struct breakpoint *b;
3512 if (b->address == pc) /* address match / overlay match */
3513 if (!overlay_debugging || b->section == section)
3517 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3519 if (b->address == pc) /* address match / overlay match */
3520 if (!overlay_debugging || b->section == section)
3523 printf_filtered ("%d%s%s ",
3525 ((b->enable_state == bp_disabled ||
3526 b->enable_state == bp_shlib_disabled ||
3527 b->enable_state == bp_call_disabled)
3529 : b->enable_state == bp_permanent
3533 : ((others == 1) ? " and" : ""));
3535 printf_filtered ("also set at pc ");
3536 print_address_numeric (pc, 1, gdb_stdout);
3537 printf_filtered (".\n");
3541 /* Set the default place to put a breakpoint
3542 for the `break' command with no arguments. */
3545 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3548 default_breakpoint_valid = valid;
3549 default_breakpoint_address = addr;
3550 default_breakpoint_symtab = symtab;
3551 default_breakpoint_line = line;
3554 /* Return true iff it is meaningful to use the address member of
3555 BPT. For some breakpoint types, the address member is irrelevant
3556 and it makes no sense to attempt to compare it to other addresses
3557 (or use it for any other purpose either).
3559 More specifically, each of the following breakpoint types will always
3560 have a zero valued address and we don't want check_duplicates() to mark
3561 breakpoints of any of these types to be a duplicate of an actual
3562 breakpoint at address zero:
3565 bp_hardware_watchpoint
3567 bp_access_watchpoint
3574 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3576 enum bptype type = bpt->type;
3578 return (type != bp_watchpoint
3579 && type != bp_hardware_watchpoint
3580 && type != bp_read_watchpoint
3581 && type != bp_access_watchpoint
3582 && type != bp_catch_exec
3583 && type != bp_longjmp_resume
3584 && type != bp_catch_fork
3585 && type != bp_catch_vfork);
3588 /* Rescan breakpoints at the same address and section as BPT,
3589 marking the first one as "first" and any others as "duplicates".
3590 This is so that the bpt instruction is only inserted once.
3591 If we have a permanent breakpoint at the same place as BPT, make
3592 that one the official one, and the rest as duplicates. */
3595 check_duplicates (struct breakpoint *bpt)
3597 register struct breakpoint *b;
3598 register int count = 0;
3599 struct breakpoint *perm_bp = 0;
3600 CORE_ADDR address = bpt->address;
3601 asection *section = bpt->section;
3603 if (! breakpoint_address_is_meaningful (bpt))
3607 if (b->enable_state != bp_disabled
3608 && b->enable_state != bp_shlib_disabled
3609 && b->enable_state != bp_call_disabled
3610 && b->address == address /* address / overlay match */
3611 && (!overlay_debugging || b->section == section)
3612 && breakpoint_address_is_meaningful (b))
3614 /* Have we found a permanent breakpoint? */
3615 if (b->enable_state == bp_permanent)
3622 b->duplicate = count > 1;
3625 /* If we found a permanent breakpoint at this address, go over the
3626 list again and declare all the other breakpoints there to be the
3630 perm_bp->duplicate = 0;
3632 /* Permanent breakpoint should always be inserted. */
3633 if (! perm_bp->inserted)
3634 internal_error (__FILE__, __LINE__,
3635 "allegedly permanent breakpoint is not "
3636 "actually inserted");
3642 internal_error (__FILE__, __LINE__,
3643 "another breakpoint was inserted on top of "
3644 "a permanent breakpoint");
3646 if (b->enable_state != bp_disabled
3647 && b->enable_state != bp_shlib_disabled
3648 && b->enable_state != bp_call_disabled
3649 && b->address == address /* address / overlay match */
3650 && (!overlay_debugging || b->section == section)
3651 && breakpoint_address_is_meaningful (b))
3657 /* set_raw_breakpoint() is a low level routine for allocating and
3658 partially initializing a breakpoint of type BPTYPE. The newly
3659 created breakpoint's address, section, source file name, and line
3660 number are provided by SAL. The newly created and partially
3661 initialized breakpoint is added to the breakpoint chain and
3662 is also returned as the value of this function.
3664 It is expected that the caller will complete the initialization of
3665 the newly created breakpoint struct as well as output any status
3666 information regarding the creation of a new breakpoint. In
3667 particular, set_raw_breakpoint() does NOT set the breakpoint
3668 number! Care should be taken to not allow an error() to occur
3669 prior to completing the initialization of the breakpoint. If this
3670 should happen, a bogus breakpoint will be left on the chain. */
3673 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3675 register struct breakpoint *b, *b1;
3677 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3678 memset (b, 0, sizeof (*b));
3679 b->address = sal.pc;
3680 if (sal.symtab == NULL)
3681 b->source_file = NULL;
3683 b->source_file = savestring (sal.symtab->filename,
3684 strlen (sal.symtab->filename));
3685 b->section = sal.section;
3687 b->language = current_language->la_language;
3688 b->input_radix = input_radix;
3690 b->line_number = sal.line;
3691 b->enable_state = bp_enabled;
3694 b->ignore_count = 0;
3697 b->dll_pathname = NULL;
3698 b->triggered_dll_pathname = NULL;
3699 b->forked_inferior_pid = 0;
3700 b->exec_pathname = NULL;
3702 /* Add this breakpoint to the end of the chain
3703 so that a list of breakpoints will come out in order
3704 of increasing numbers. */
3706 b1 = breakpoint_chain;
3708 breakpoint_chain = b;
3716 check_duplicates (b);
3717 breakpoints_changed ();
3723 /* Note that the breakpoint object B describes a permanent breakpoint
3724 instruction, hard-wired into the inferior's code. */
3726 make_breakpoint_permanent (struct breakpoint *b)
3728 b->enable_state = bp_permanent;
3730 /* By definition, permanent breakpoints are already present in the code. */
3734 #ifdef GET_LONGJMP_TARGET
3737 create_longjmp_breakpoint (char *func_name)
3739 struct symtab_and_line sal;
3740 struct breakpoint *b;
3742 INIT_SAL (&sal); /* initialize to zeroes */
3743 if (func_name != NULL)
3745 struct minimal_symbol *m;
3747 m = lookup_minimal_symbol_text (func_name, NULL,
3748 (struct objfile *) NULL);
3750 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3754 sal.section = find_pc_overlay (sal.pc);
3755 b = set_raw_breakpoint (sal,
3756 func_name != NULL ? bp_longjmp : bp_longjmp_resume);
3758 b->disposition = disp_donttouch;
3759 b->enable_state = bp_disabled;
3762 b->addr_string = xstrdup (func_name);
3763 b->number = internal_breakpoint_number--;
3766 #endif /* #ifdef GET_LONGJMP_TARGET */
3768 /* Call this routine when stepping and nexting to enable a breakpoint
3769 if we do a longjmp(). When we hit that breakpoint, call
3770 set_longjmp_resume_breakpoint() to figure out where we are going. */
3773 enable_longjmp_breakpoint (void)
3775 register struct breakpoint *b;
3778 if (b->type == bp_longjmp)
3780 b->enable_state = bp_enabled;
3781 check_duplicates (b);
3786 disable_longjmp_breakpoint (void)
3788 register struct breakpoint *b;
3791 if (b->type == bp_longjmp
3792 || b->type == bp_longjmp_resume)
3794 b->enable_state = bp_disabled;
3795 check_duplicates (b);
3800 create_thread_event_breakpoint (CORE_ADDR address)
3802 struct breakpoint *b;
3803 struct symtab_and_line sal;
3804 char addr_string[80]; /* Surely an addr can't be longer than that. */
3806 INIT_SAL (&sal); /* initialize to zeroes */
3808 sal.section = find_pc_overlay (sal.pc);
3809 b = set_raw_breakpoint (sal, bp_thread_event);
3811 b->number = internal_breakpoint_number--;
3812 b->disposition = disp_donttouch;
3813 b->enable_state = bp_enabled;
3814 /* addr_string has to be used or breakpoint_re_set will delete me. */
3815 sprintf (addr_string, "*0x%s", paddr (b->address));
3816 b->addr_string = xstrdup (addr_string);
3822 remove_thread_event_breakpoints (void)
3824 struct breakpoint *b, *temp;
3826 ALL_BREAKPOINTS_SAFE (b, temp)
3827 if (b->type == bp_thread_event)
3828 delete_breakpoint (b);
3833 remove_solib_event_breakpoints (void)
3835 register struct breakpoint *b, *temp;
3837 ALL_BREAKPOINTS_SAFE (b, temp)
3838 if (b->type == bp_shlib_event)
3839 delete_breakpoint (b);
3843 create_solib_event_breakpoint (CORE_ADDR address)
3845 struct breakpoint *b;
3846 struct symtab_and_line sal;
3848 INIT_SAL (&sal); /* initialize to zeroes */
3850 sal.section = find_pc_overlay (sal.pc);
3851 b = set_raw_breakpoint (sal, bp_shlib_event);
3852 b->number = internal_breakpoint_number--;
3853 b->disposition = disp_donttouch;
3858 /* Disable any breakpoints that are on code in shared libraries. Only
3859 apply to enabled breakpoints, disabled ones can just stay disabled. */
3862 disable_breakpoints_in_shlibs (int silent)
3864 struct breakpoint *b;
3865 int disabled_shlib_breaks = 0;
3867 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3870 #if defined (PC_SOLIB)
3871 if (((b->type == bp_breakpoint) ||
3872 (b->type == bp_hardware_breakpoint)) &&
3873 b->enable_state == bp_enabled &&
3875 PC_SOLIB (b->address))
3877 b->enable_state = bp_shlib_disabled;
3880 if (!disabled_shlib_breaks)
3882 target_terminal_ours_for_output ();
3883 warning ("Temporarily disabling shared library breakpoints:");
3885 disabled_shlib_breaks = 1;
3886 warning ("breakpoint #%d ", b->number);
3893 /* Try to reenable any breakpoints in shared libraries. */
3895 re_enable_breakpoints_in_shlibs (void)
3897 struct breakpoint *b;
3900 if (b->enable_state == bp_shlib_disabled)
3904 /* Do not reenable the breakpoint if the shared library
3905 is still not mapped in. */
3906 if (target_read_memory (b->address, buf, 1) == 0)
3907 b->enable_state = bp_enabled;
3914 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
3915 char *cond_string, enum bptype bp_kind)
3917 struct breakpoint *b;
3918 struct symtabs_and_lines sals;
3919 struct cleanup *old_chain;
3920 struct cleanup *canonical_strings_chain = NULL;
3921 char *addr_start = hookname;
3922 char *addr_end = NULL;
3923 char **canonical = (char **) NULL;
3924 int thread = -1; /* All threads. */
3926 /* Set a breakpoint on the specified hook. */
3927 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3928 addr_end = hookname;
3930 if (sals.nelts == 0)
3932 warning ("Unable to set a breakpoint on dynamic linker callback.");
3933 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3934 warning ("GDB will be unable to track shl_load/shl_unload calls");
3937 if (sals.nelts != 1)
3939 warning ("Unable to set unique breakpoint on dynamic linker callback.");
3940 warning ("GDB will be unable to track shl_load/shl_unload calls");
3944 /* Make sure that all storage allocated in decode_line_1 gets freed
3945 in case the following errors out. */
3946 old_chain = make_cleanup (xfree, sals.sals);
3947 if (canonical != (char **) NULL)
3949 make_cleanup (xfree, canonical);
3950 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3951 if (canonical[0] != NULL)
3952 make_cleanup (xfree, canonical[0]);
3955 resolve_sal_pc (&sals.sals[0]);
3957 /* Remove the canonical strings from the cleanup, they are needed below. */
3958 if (canonical != (char **) NULL)
3959 discard_cleanups (canonical_strings_chain);
3961 b = set_raw_breakpoint (sals.sals[0], bp_kind);
3962 set_breakpoint_count (breakpoint_count + 1);
3963 b->number = breakpoint_count;
3965 b->cond_string = (cond_string == NULL) ?
3966 NULL : savestring (cond_string, strlen (cond_string));
3969 if (canonical != (char **) NULL && canonical[0] != NULL)
3970 b->addr_string = canonical[0];
3971 else if (addr_start)
3972 b->addr_string = savestring (addr_start, addr_end - addr_start);
3974 b->enable_state = bp_enabled;
3975 b->disposition = tempflag ? disp_del : disp_donttouch;
3977 if (dll_pathname == NULL)
3978 b->dll_pathname = NULL;
3981 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3982 strcpy (b->dll_pathname, dll_pathname);
3986 do_cleanups (old_chain);
3990 create_solib_load_event_breakpoint (char *hookname, int tempflag,
3991 char *dll_pathname, char *cond_string)
3993 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3994 cond_string, bp_catch_load);
3998 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
3999 char *dll_pathname, char *cond_string)
4001 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4002 cond_string, bp_catch_unload);
4006 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4007 enum bptype bp_kind)
4009 struct symtab_and_line sal;
4010 struct breakpoint *b;
4011 int thread = -1; /* All threads. */
4018 b = set_raw_breakpoint (sal, bp_kind);
4019 set_breakpoint_count (breakpoint_count + 1);
4020 b->number = breakpoint_count;
4022 b->cond_string = (cond_string == NULL) ?
4023 NULL : savestring (cond_string, strlen (cond_string));
4025 b->addr_string = NULL;
4026 b->enable_state = bp_enabled;
4027 b->disposition = tempflag ? disp_del : disp_donttouch;
4028 b->forked_inferior_pid = 0;
4034 create_fork_event_catchpoint (int tempflag, char *cond_string)
4036 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4040 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4042 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4046 create_exec_event_catchpoint (int tempflag, char *cond_string)
4048 struct symtab_and_line sal;
4049 struct breakpoint *b;
4050 int thread = -1; /* All threads. */
4057 b = set_raw_breakpoint (sal, bp_catch_exec);
4058 set_breakpoint_count (breakpoint_count + 1);
4059 b->number = breakpoint_count;
4061 b->cond_string = (cond_string == NULL) ?
4062 NULL : savestring (cond_string, strlen (cond_string));
4064 b->addr_string = NULL;
4065 b->enable_state = bp_enabled;
4066 b->disposition = tempflag ? disp_del : disp_donttouch;
4072 hw_breakpoint_used_count (void)
4074 register struct breakpoint *b;
4079 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4087 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4089 register struct breakpoint *b;
4092 *other_type_used = 0;
4095 if (b->enable_state == bp_enabled)
4097 if (b->type == type)
4099 else if ((b->type == bp_hardware_watchpoint ||
4100 b->type == bp_read_watchpoint ||
4101 b->type == bp_access_watchpoint)
4102 && b->enable_state == bp_enabled)
4103 *other_type_used = 1;
4109 /* Call this after hitting the longjmp() breakpoint. Use this to set
4110 a new breakpoint at the target of the jmp_buf.
4112 FIXME - This ought to be done by setting a temporary breakpoint
4113 that gets deleted automatically... */
4116 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
4118 register struct breakpoint *b;
4121 if (b->type == bp_longjmp_resume)
4124 b->enable_state = bp_enabled;
4126 b->frame = frame->frame;
4129 check_duplicates (b);
4135 disable_watchpoints_before_interactive_call_start (void)
4137 struct breakpoint *b;
4141 if (((b->type == bp_watchpoint)
4142 || (b->type == bp_hardware_watchpoint)
4143 || (b->type == bp_read_watchpoint)
4144 || (b->type == bp_access_watchpoint)
4145 || ep_is_exception_catchpoint (b))
4146 && (b->enable_state == bp_enabled))
4148 b->enable_state = bp_call_disabled;
4149 check_duplicates (b);
4155 enable_watchpoints_after_interactive_call_stop (void)
4157 struct breakpoint *b;
4161 if (((b->type == bp_watchpoint)
4162 || (b->type == bp_hardware_watchpoint)
4163 || (b->type == bp_read_watchpoint)
4164 || (b->type == bp_access_watchpoint)
4165 || ep_is_exception_catchpoint (b))
4166 && (b->enable_state == bp_call_disabled))
4168 b->enable_state = bp_enabled;
4169 check_duplicates (b);
4175 /* Set a breakpoint that will evaporate an end of command
4176 at address specified by SAL.
4177 Restrict it to frame FRAME if FRAME is nonzero. */
4180 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4183 register struct breakpoint *b;
4184 b = set_raw_breakpoint (sal, type);
4185 b->enable_state = bp_enabled;
4186 b->disposition = disp_donttouch;
4187 b->frame = (frame ? frame->frame : 0);
4189 /* If we're debugging a multi-threaded program, then we
4190 want momentary breakpoints to be active in only a
4191 single thread of control. */
4192 if (in_thread_list (inferior_ptid))
4193 b->thread = pid_to_thread_id (inferior_ptid);
4199 /* Tell the user we have just set a breakpoint B. */
4202 mention (struct breakpoint *b)
4205 struct cleanup *old_chain;
4206 struct ui_stream *stb;
4208 stb = ui_out_stream_new (uiout);
4209 old_chain = make_cleanup_ui_out_stream_delete (stb);
4211 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4212 watchpoint) other than breakpoint creation. It should be possible to
4213 clean this up and at the same time replace the random calls to
4214 breakpoint_changed with this hook, as has already been done for
4215 delete_breakpoint_hook and so on. */
4216 if (create_breakpoint_hook)
4217 create_breakpoint_hook (b);
4218 breakpoint_create_event (b->number);
4223 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4226 ui_out_text (uiout, "Watchpoint ");
4227 ui_out_tuple_begin (uiout, "wpt");
4228 ui_out_field_int (uiout, "number", b->number);
4229 ui_out_text (uiout, ": ");
4230 print_expression (b->exp, stb->stream);
4231 ui_out_field_stream (uiout, "exp", stb);
4232 ui_out_tuple_end (uiout);
4234 case bp_hardware_watchpoint:
4235 ui_out_text (uiout, "Hardware watchpoint ");
4236 ui_out_tuple_begin (uiout, "wpt");
4237 ui_out_field_int (uiout, "number", b->number);
4238 ui_out_text (uiout, ": ");
4239 print_expression (b->exp, stb->stream);
4240 ui_out_field_stream (uiout, "exp", stb);
4241 ui_out_tuple_end (uiout);
4243 case bp_read_watchpoint:
4244 ui_out_text (uiout, "Hardware read watchpoint ");
4245 ui_out_tuple_begin (uiout, "hw-rwpt");
4246 ui_out_field_int (uiout, "number", b->number);
4247 ui_out_text (uiout, ": ");
4248 print_expression (b->exp, stb->stream);
4249 ui_out_field_stream (uiout, "exp", stb);
4250 ui_out_tuple_end (uiout);
4252 case bp_access_watchpoint:
4253 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4254 ui_out_tuple_begin (uiout, "hw-awpt");
4255 ui_out_field_int (uiout, "number", b->number);
4256 ui_out_text (uiout, ": ");
4257 print_expression (b->exp, stb->stream);
4258 ui_out_field_stream (uiout, "exp", stb);
4259 ui_out_tuple_end (uiout);
4262 if (ui_out_is_mi_like_p (uiout))
4267 printf_filtered ("Breakpoint %d", b->number);
4270 case bp_hardware_breakpoint:
4271 if (ui_out_is_mi_like_p (uiout))
4276 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4280 case bp_catch_unload:
4281 printf_filtered ("Catchpoint %d (%s %s)",
4283 (b->type == bp_catch_load) ? "load" : "unload",
4284 (b->dll_pathname != NULL) ?
4285 b->dll_pathname : "<any library>");
4288 case bp_catch_vfork:
4289 printf_filtered ("Catchpoint %d (%s)",
4291 (b->type == bp_catch_fork) ? "fork" : "vfork");
4294 printf_filtered ("Catchpoint %d (exec)",
4297 case bp_catch_catch:
4298 case bp_catch_throw:
4299 printf_filtered ("Catchpoint %d (%s)",
4301 (b->type == bp_catch_catch) ? "catch" : "throw");
4307 case bp_longjmp_resume:
4308 case bp_step_resume:
4309 case bp_through_sigtramp:
4311 case bp_watchpoint_scope:
4312 case bp_shlib_event:
4313 case bp_thread_event:
4318 if (addressprint || b->source_file == NULL)
4320 printf_filtered (" at ");
4321 print_address_numeric (b->address, 1, gdb_stdout);
4324 printf_filtered (": file %s, line %d.",
4325 b->source_file, b->line_number);
4327 do_cleanups (old_chain);
4328 if (ui_out_is_mi_like_p (uiout))
4330 printf_filtered ("\n");
4334 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4335 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4336 COND[i] and COND_STRING[i] values.
4338 NOTE: If the function succeeds, the caller is expected to cleanup
4339 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4340 array contents). If the function fails (error() is called), the
4341 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4342 COND and SALS arrays and each of those arrays contents. */
4345 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4346 struct expression **cond, char **cond_string,
4347 enum bptype type, enum bpdisp disposition,
4348 int thread, int ignore_count, int from_tty)
4350 if (type == bp_hardware_breakpoint)
4352 int i = hw_breakpoint_used_count ();
4353 int target_resources_ok =
4354 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4356 if (target_resources_ok == 0)
4357 error ("No hardware breakpoint support in the target.");
4358 else if (target_resources_ok < 0)
4359 error ("Hardware breakpoints used exceeds limit.");
4362 /* Now set all the breakpoints. */
4365 for (i = 0; i < sals.nelts; i++)
4367 struct breakpoint *b;
4368 struct symtab_and_line sal = sals.sals[i];
4371 describe_other_breakpoints (sal.pc, sal.section);
4373 b = set_raw_breakpoint (sal, type);
4374 set_breakpoint_count (breakpoint_count + 1);
4375 b->number = breakpoint_count;
4378 b->addr_string = addr_string[i];
4379 b->cond_string = cond_string[i];
4380 b->ignore_count = ignore_count;
4381 b->enable_state = bp_enabled;
4382 b->disposition = disposition;
4388 /* Parse ARG which is assumed to be a SAL specification possibly
4389 followed by conditionals. On return, SALS contains an array of SAL
4390 addresses found. ADDR_STRING contains a vector of (canonical)
4391 address strings. ARG points to the end of the SAL. */
4394 parse_breakpoint_sals (char **address,
4395 struct symtabs_and_lines *sals,
4396 char ***addr_string)
4398 char *addr_start = *address;
4399 *addr_string = NULL;
4400 /* If no arg given, or if first arg is 'if ', use the default
4402 if ((*address) == NULL
4403 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4405 if (default_breakpoint_valid)
4407 struct symtab_and_line sal;
4408 INIT_SAL (&sal); /* initialize to zeroes */
4409 sals->sals = (struct symtab_and_line *)
4410 xmalloc (sizeof (struct symtab_and_line));
4411 sal.pc = default_breakpoint_address;
4412 sal.line = default_breakpoint_line;
4413 sal.symtab = default_breakpoint_symtab;
4414 sal.section = find_pc_overlay (sal.pc);
4415 sals->sals[0] = sal;
4419 error ("No default breakpoint address now.");
4423 /* Force almost all breakpoints to be in terms of the
4424 current_source_symtab (which is decode_line_1's default). This
4425 should produce the results we want almost all of the time while
4426 leaving default_breakpoint_* alone. */
4427 if (default_breakpoint_valid
4428 && (!current_source_symtab
4429 || (strchr ("+-", (*address)[0]) != NULL)))
4430 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4431 default_breakpoint_line, addr_string);
4433 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4435 /* For any SAL that didn't have a canonical string, fill one in. */
4436 if (sals->nelts > 0 && *addr_string == NULL)
4437 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4438 if (addr_start != (*address))
4441 for (i = 0; i < sals->nelts; i++)
4443 /* Add the string if not present. */
4444 if ((*addr_string)[i] == NULL)
4445 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4451 /* Convert each SAL into a real PC. Verify that the PC can be
4452 inserted as a breakpoint. If it can't throw an error. */
4455 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4459 for (i = 0; i < sals->nelts; i++)
4461 resolve_sal_pc (&sals->sals[i]);
4463 /* It's possible for the PC to be nonzero, but still an illegal
4464 value on some targets.
4466 For example, on HP-UX if you start gdb, and before running the
4467 inferior you try to set a breakpoint on a shared library function
4468 "foo" where the inferior doesn't call "foo" directly but does
4469 pass its address to another function call, then we do find a
4470 minimal symbol for the "foo", but it's address is invalid.
4471 (Appears to be an index into a table that the loader sets up
4472 when the inferior is run.)
4474 Give the target a chance to bless sals.sals[i].pc before we
4475 try to make a breakpoint for it. */
4476 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4478 if (address == NULL)
4479 error ("Cannot break without a running program.");
4481 error ("Cannot break on %s without a running program.",
4487 /* Set a breakpoint according to ARG (function, linenum or *address)
4488 flag: first bit : 0 non-temporary, 1 temporary.
4489 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4492 break_command_1 (char *arg, int flag, int from_tty)
4494 int tempflag, hardwareflag;
4495 struct symtabs_and_lines sals;
4496 register struct expression **cond = 0;
4497 /* Pointers in arg to the start, and one past the end, of the
4499 char **cond_string = (char **) NULL;
4500 char *addr_start = arg;
4502 struct cleanup *old_chain;
4503 struct cleanup *breakpoint_chain = NULL;
4506 int ignore_count = 0;
4508 hardwareflag = flag & BP_HARDWAREFLAG;
4509 tempflag = flag & BP_TEMPFLAG;
4514 parse_breakpoint_sals (&arg, &sals, &addr_string);
4519 /* Create a chain of things that always need to be cleaned up. */
4520 old_chain = make_cleanup (null_cleanup, 0);
4522 /* Make sure that all storage allocated to SALS gets freed. */
4523 make_cleanup (xfree, sals.sals);
4525 /* Cleanup the addr_string array but not its contents. */
4526 make_cleanup (xfree, addr_string);
4528 /* Allocate space for all the cond expressions. */
4529 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4530 make_cleanup (xfree, cond);
4532 /* Allocate space for all the cond strings. */
4533 cond_string = xcalloc (sals.nelts, sizeof (char **));
4534 make_cleanup (xfree, cond_string);
4536 /* ----------------------------- SNIP -----------------------------
4537 Anything added to the cleanup chain beyond this point is assumed
4538 to be part of a breakpoint. If the breakpoint create succeeds
4539 then the memory is not reclaimed. */
4540 breakpoint_chain = make_cleanup (null_cleanup, 0);
4542 /* Mark the contents of the addr_string for cleanup. These go on
4543 the breakpoint_chain and only occure if the breakpoint create
4545 for (i = 0; i < sals.nelts; i++)
4547 if (addr_string[i] != NULL)
4548 make_cleanup (xfree, addr_string[i]);
4551 /* Resolve all line numbers to PC's and verify that the addresses
4552 are ok for the target. */
4553 breakpoint_sals_to_pc (&sals, addr_start);
4555 /* Verify that condition can be parsed, before setting any
4556 breakpoints. Allocate a separate condition expression for each
4558 thread = -1; /* No specific thread yet */
4559 for (i = 0; i < sals.nelts; i++)
4566 char *cond_start = NULL;
4567 char *cond_end = NULL;
4568 while (*tok == ' ' || *tok == '\t')
4573 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4576 toklen = end_tok - tok;
4578 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4580 tok = cond_start = end_tok + 1;
4581 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4582 make_cleanup (xfree, cond[i]);
4584 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4585 make_cleanup (xfree, cond_string[i]);
4587 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4593 thread = strtol (tok, &tok, 0);
4595 error ("Junk after thread keyword.");
4596 if (!valid_thread_id (thread))
4597 error ("Unknown thread %d\n", thread);
4600 error ("Junk at end of arguments.");
4604 create_breakpoints (sals, addr_string, cond, cond_string,
4605 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4606 tempflag ? disp_del : disp_donttouch,
4607 thread, ignore_count, from_tty);
4611 warning ("Multiple breakpoints were set.");
4612 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4614 /* That's it. Discard the cleanups for data inserted into the
4616 discard_cleanups (breakpoint_chain);
4617 /* But cleanup everything else. */
4618 do_cleanups (old_chain);
4621 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4622 linenum or *address) with COND and IGNORE_COUNT. */
4624 struct captured_breakpoint_args
4635 do_captured_breakpoint (void *data)
4637 struct captured_breakpoint_args *args = data;
4638 struct symtabs_and_lines sals;
4639 register struct expression **cond;
4640 struct cleanup *old_chain;
4641 struct cleanup *breakpoint_chain = NULL;
4648 /* Parse the source and lines spec. Delay check that the expression
4649 didn't contain trailing garbage until after cleanups are in
4653 address_end = args->address;
4655 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4660 /* Create a chain of things at always need to be cleaned up. */
4661 old_chain = make_cleanup (null_cleanup, 0);
4663 /* Always have a addr_string array, even if it is empty. */
4664 make_cleanup (xfree, addr_string);
4666 /* Make sure that all storage allocated to SALS gets freed. */
4667 make_cleanup (xfree, sals.sals);
4669 /* Allocate space for all the cond expressions. */
4670 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4671 make_cleanup (xfree, cond);
4673 /* Allocate space for all the cond strings. */
4674 cond_string = xcalloc (sals.nelts, sizeof (char **));
4675 make_cleanup (xfree, cond_string);
4677 /* ----------------------------- SNIP -----------------------------
4678 Anything added to the cleanup chain beyond this point is assumed
4679 to be part of a breakpoint. If the breakpoint create goes
4680 through then that memory is not cleaned up. */
4681 breakpoint_chain = make_cleanup (null_cleanup, 0);
4683 /* Mark the contents of the addr_string for cleanup. These go on
4684 the breakpoint_chain and only occure if the breakpoint create
4686 for (i = 0; i < sals.nelts; i++)
4688 if (addr_string[i] != NULL)
4689 make_cleanup (xfree, addr_string[i]);
4692 /* Wait until now before checking for garbage at the end of the
4693 address. That way cleanups can take care of freeing any
4695 if (*address_end != '\0')
4696 error ("Garbage %s following breakpoint address", address_end);
4698 /* Resolve all line numbers to PC's. */
4699 breakpoint_sals_to_pc (&sals, args->address);
4701 /* Verify that conditions can be parsed, before setting any
4703 for (i = 0; i < sals.nelts; i++)
4705 if (args->condition != NULL)
4707 char *tok = args->condition;
4708 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4710 error ("Garbage %s follows condition", tok);
4711 make_cleanup (xfree, cond[i]);
4712 cond_string[i] = xstrdup (args->condition);
4716 create_breakpoints (sals, addr_string, cond, cond_string,
4717 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4718 args->tempflag ? disp_del : disp_donttouch,
4719 args->thread, args->ignore_count, 0/*from-tty*/);
4721 /* That's it. Discard the cleanups for data inserted into the
4723 discard_cleanups (breakpoint_chain);
4724 /* But cleanup everything else. */
4725 do_cleanups (old_chain);
4730 gdb_breakpoint (char *address, char *condition,
4731 int hardwareflag, int tempflag,
4732 int thread, int ignore_count)
4734 struct captured_breakpoint_args args;
4735 args.address = address;
4736 args.condition = condition;
4737 args.hardwareflag = hardwareflag;
4738 args.tempflag = tempflag;
4739 args.thread = thread;
4740 args.ignore_count = ignore_count;
4741 return catch_errors (do_captured_breakpoint, &args,
4742 NULL, RETURN_MASK_ALL);
4747 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4749 struct frame_info *frame;
4750 CORE_ADDR low, high, selected_pc = 0;
4751 char *extra_args = NULL;
4754 int extra_args_len = 0, if_arg = 0;
4757 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4760 if (default_breakpoint_valid)
4764 selected_pc = selected_frame->pc;
4769 error ("No selected frame.");
4772 error ("No default breakpoint address now.");
4776 extra_args = strchr (arg, ' ');
4780 extra_args_len = strlen (extra_args);
4781 level_arg = (char *) xmalloc (extra_args - arg);
4782 strncpy (level_arg, arg, extra_args - arg - 1);
4783 level_arg[extra_args - arg - 1] = '\0';
4787 level_arg = (char *) xmalloc (strlen (arg) + 1);
4788 strcpy (level_arg, arg);
4791 frame = parse_frame_specification (level_arg);
4793 selected_pc = frame->pc;
4800 extra_args_len = strlen (arg);
4805 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4807 addr_string = (char *) xmalloc (26 + extra_args_len);
4809 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4811 sprintf (addr_string, "*0x%s", paddr_nz (high));
4812 break_command_1 (addr_string, flag, from_tty);
4813 xfree (addr_string);
4816 error ("No function contains the specified address");
4819 error ("Unable to set breakpoint at procedure exit");
4824 break_at_finish_command_1 (char *arg, int flag, int from_tty)
4826 char *addr_string, *break_string, *beg_addr_string;
4827 CORE_ADDR low, high;
4828 struct symtabs_and_lines sals;
4829 struct symtab_and_line sal;
4830 struct cleanup *old_chain;
4831 char *extra_args = NULL;
4832 int extra_args_len = 0;
4836 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4838 if (default_breakpoint_valid)
4842 addr_string = (char *) xmalloc (15);
4843 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
4848 error ("No selected frame.");
4851 error ("No default breakpoint address now.");
4855 addr_string = (char *) xmalloc (strlen (arg) + 1);
4856 strcpy (addr_string, arg);
4862 extra_args_len = strlen (arg);
4866 /* get the stuff after the function name or address */
4867 extra_args = strchr (arg, ' ');
4871 extra_args_len = strlen (extra_args);
4878 beg_addr_string = addr_string;
4879 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4882 xfree (beg_addr_string);
4883 old_chain = make_cleanup (xfree, sals.sals);
4884 for (i = 0; (i < sals.nelts); i++)
4887 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
4889 break_string = (char *) xmalloc (extra_args_len + 26);
4891 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
4893 sprintf (break_string, "*0x%s", paddr_nz (high));
4894 break_command_1 (break_string, flag, from_tty);
4895 xfree (break_string);
4898 error ("No function contains the specified address");
4902 warning ("Multiple breakpoints were set.\n");
4903 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4905 do_cleanups (old_chain);
4909 /* Helper function for break_command_1 and disassemble_command. */
4912 resolve_sal_pc (struct symtab_and_line *sal)
4916 if (sal->pc == 0 && sal->symtab != NULL)
4918 if (!find_line_pc (sal->symtab, sal->line, &pc))
4919 error ("No line %d in file \"%s\".",
4920 sal->line, sal->symtab->filename);
4924 if (sal->section == 0 && sal->symtab != NULL)
4926 struct blockvector *bv;
4931 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
4934 b = BLOCKVECTOR_BLOCK (bv, index);
4935 sym = block_function (b);
4938 fixup_symbol_section (sym, sal->symtab->objfile);
4939 sal->section = SYMBOL_BFD_SECTION (sym);
4943 /* It really is worthwhile to have the section, so we'll just
4944 have to look harder. This case can be executed if we have
4945 line numbers but no functions (as can happen in assembly
4948 struct minimal_symbol *msym;
4950 msym = lookup_minimal_symbol_by_pc (sal->pc);
4952 sal->section = SYMBOL_BFD_SECTION (msym);
4959 break_command (char *arg, int from_tty)
4961 break_command_1 (arg, 0, from_tty);
4965 break_at_finish_command (char *arg, int from_tty)
4967 break_at_finish_command_1 (arg, 0, from_tty);
4971 break_at_finish_at_depth_command (char *arg, int from_tty)
4973 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4977 tbreak_command (char *arg, int from_tty)
4979 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4983 tbreak_at_finish_command (char *arg, int from_tty)
4985 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4989 hbreak_command (char *arg, int from_tty)
4991 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4995 thbreak_command (char *arg, int from_tty)
4997 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5001 stop_command (char *arg, int from_tty)
5003 printf_filtered ("Specify the type of breakpoint to set.\n\
5004 Usage: stop in <function | address>\n\
5009 stopin_command (char *arg, int from_tty)
5013 if (arg == (char *) NULL)
5015 else if (*arg != '*')
5020 /* look for a ':'. If this is a line number specification, then
5021 say it is bad, otherwise, it should be an address or
5022 function/method name */
5023 while (*argptr && !hasColon)
5025 hasColon = (*argptr == ':');
5030 badInput = (*argptr != ':'); /* Not a class::method */
5032 badInput = isdigit (*arg); /* a simple line number */
5036 printf_filtered ("Usage: stop in <function | address>\n");
5038 break_command_1 (arg, 0, from_tty);
5042 stopat_command (char *arg, int from_tty)
5046 if (arg == (char *) NULL || *arg == '*') /* no line number */
5053 /* look for a ':'. If there is a '::' then get out, otherwise
5054 it is probably a line number. */
5055 while (*argptr && !hasColon)
5057 hasColon = (*argptr == ':');
5062 badInput = (*argptr == ':'); /* we have class::method */
5064 badInput = !isdigit (*arg); /* not a line number */
5068 printf_filtered ("Usage: stop at <line>\n");
5070 break_command_1 (arg, 0, from_tty);
5074 /* accessflag: hw_write: watch write,
5075 hw_read: watch read,
5076 hw_access: watch access (read or write) */
5078 watch_command_1 (char *arg, int accessflag, int from_tty)
5080 struct breakpoint *b;
5081 struct symtab_and_line sal;
5082 struct expression *exp;
5083 struct block *exp_valid_block;
5084 struct value *val, *mark;
5085 struct frame_info *frame;
5086 struct frame_info *prev_frame = NULL;
5087 char *exp_start = NULL;
5088 char *exp_end = NULL;
5089 char *tok, *end_tok;
5091 char *cond_start = NULL;
5092 char *cond_end = NULL;
5093 struct expression *cond = NULL;
5094 int i, other_type_used, target_resources_ok = 0;
5095 enum bptype bp_type;
5098 INIT_SAL (&sal); /* initialize to zeroes */
5100 /* Parse arguments. */
5101 innermost_block = NULL;
5103 exp = parse_exp_1 (&arg, 0, 0);
5105 exp_valid_block = innermost_block;
5106 mark = value_mark ();
5107 val = evaluate_expression (exp);
5108 release_value (val);
5109 if (VALUE_LAZY (val))
5110 value_fetch_lazy (val);
5113 while (*tok == ' ' || *tok == '\t')
5117 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5120 toklen = end_tok - tok;
5121 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5123 tok = cond_start = end_tok + 1;
5124 cond = parse_exp_1 (&tok, 0, 0);
5128 error ("Junk at end of command.");
5130 if (accessflag == hw_read)
5131 bp_type = bp_read_watchpoint;
5132 else if (accessflag == hw_access)
5133 bp_type = bp_access_watchpoint;
5135 bp_type = bp_hardware_watchpoint;
5137 mem_cnt = can_use_hardware_watchpoint (val);
5138 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5139 error ("Expression cannot be implemented with read/access watchpoint.");
5142 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5143 target_resources_ok =
5144 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5146 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5147 error ("Target does not support this type of hardware watchpoint.");
5149 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5150 error ("Target can only support one kind of HW watchpoint at a time.");
5153 #if defined(HPUXHPPA)
5154 /* On HP-UX if you set a h/w
5155 watchpoint before the "run" command, the inferior dies with a e.g.,
5156 SIGILL once you start it. I initially believed this was due to a
5157 bad interaction between page protection traps and the initial
5158 startup sequence by the dynamic linker.
5160 However, I tried avoiding that by having HP-UX's implementation of
5161 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5162 yet, which forced slow watches before a "run" or "attach", and it
5163 still fails somewhere in the startup code.
5165 Until I figure out what's happening, I'm disallowing watches altogether
5166 before the "run" or "attach" command. We'll tell the user they must
5167 set watches after getting the program started. */
5168 if (!target_has_execution)
5170 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5173 #endif /* HPUXHPPA */
5175 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5176 watchpoint could not be set. */
5177 if (!mem_cnt || target_resources_ok <= 0)
5178 bp_type = bp_watchpoint;
5180 /* Now set up the breakpoint. */
5181 b = set_raw_breakpoint (sal, bp_type);
5182 set_breakpoint_count (breakpoint_count + 1);
5183 b->number = breakpoint_count;
5184 b->disposition = disp_donttouch;
5186 b->exp_valid_block = exp_valid_block;
5187 b->exp_string = savestring (exp_start, exp_end - exp_start);
5191 b->cond_string = savestring (cond_start, cond_end - cond_start);
5195 frame = block_innermost_frame (exp_valid_block);
5198 prev_frame = get_prev_frame (frame);
5199 b->watchpoint_frame = frame->frame;
5202 b->watchpoint_frame = (CORE_ADDR) 0;
5204 /* If the expression is "local", then set up a "watchpoint scope"
5205 breakpoint at the point where we've left the scope of the watchpoint
5207 if (innermost_block)
5211 struct breakpoint *scope_breakpoint;
5212 struct symtab_and_line scope_sal;
5214 INIT_SAL (&scope_sal); /* initialize to zeroes */
5215 scope_sal.pc = get_frame_pc (prev_frame);
5216 scope_sal.section = find_pc_overlay (scope_sal.pc);
5218 scope_breakpoint = set_raw_breakpoint (scope_sal,
5219 bp_watchpoint_scope);
5220 set_breakpoint_count (breakpoint_count + 1);
5221 scope_breakpoint->number = breakpoint_count;
5223 scope_breakpoint->enable_state = bp_enabled;
5225 /* Automatically delete the breakpoint when it hits. */
5226 scope_breakpoint->disposition = disp_del;
5228 /* Only break in the proper frame (help with recursion). */
5229 scope_breakpoint->frame = prev_frame->frame;
5231 /* Set the address at which we will stop. */
5232 scope_breakpoint->address = get_frame_pc (prev_frame);
5234 /* The scope breakpoint is related to the watchpoint. We
5235 will need to act on them together. */
5236 b->related_breakpoint = scope_breakpoint;
5239 value_free_to_mark (mark);
5243 /* Return count of locations need to be watched and can be handled
5244 in hardware. If the watchpoint can not be handled
5245 in hardware return zero. */
5247 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5248 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5249 ((BYTE_SIZE) <= (REGISTER_SIZE))
5252 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5253 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5254 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5258 can_use_hardware_watchpoint (struct value *v)
5260 int found_memory_cnt = 0;
5261 struct value *head = v;
5263 /* Did the user specifically forbid us to use hardware watchpoints? */
5264 if (!can_use_hw_watchpoints)
5267 /* Make sure that the value of the expression depends only upon
5268 memory contents, and values computed from them within GDB. If we
5269 find any register references or function calls, we can't use a
5270 hardware watchpoint.
5272 The idea here is that evaluating an expression generates a series
5273 of values, one holding the value of every subexpression. (The
5274 expression a*b+c has five subexpressions: a, b, a*b, c, and
5275 a*b+c.) GDB's values hold almost enough information to establish
5276 the criteria given above --- they identify memory lvalues,
5277 register lvalues, computed values, etcetera. So we can evaluate
5278 the expression, and then scan the chain of values that leaves
5279 behind to decide whether we can detect any possible change to the
5280 expression's final value using only hardware watchpoints.
5282 However, I don't think that the values returned by inferior
5283 function calls are special in any way. So this function may not
5284 notice that an expression involving an inferior function call
5285 can't be watched with hardware watchpoints. FIXME. */
5286 for (; v; v = v->next)
5288 if (VALUE_LVAL (v) == lval_memory)
5291 /* A lazy memory lvalue is one that GDB never needed to fetch;
5292 we either just used its address (e.g., `a' in `a.b') or
5293 we never needed it at all (e.g., `a' in `a,b'). */
5297 /* Ahh, memory we actually used! Check if we can cover
5298 it with hardware watchpoints. */
5299 struct type *vtype = check_typedef (VALUE_TYPE (v));
5301 /* We only watch structs and arrays if user asked for it
5302 explicitly, never if they just happen to appear in a
5303 middle of some value chain. */
5305 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5306 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5308 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5309 int len = TYPE_LENGTH (VALUE_TYPE (v));
5311 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5318 else if (v->lval != not_lval && v->modifiable == 0)
5319 return 0; /* ??? What does this represent? */
5320 else if (v->lval == lval_register)
5321 return 0; /* cannot watch a register with a HW watchpoint */
5324 /* The expression itself looks suitable for using a hardware
5325 watchpoint, but give the target machine a chance to reject it. */
5326 return found_memory_cnt;
5330 watch_command_wrapper (char *arg, int from_tty)
5332 watch_command (arg, from_tty);
5336 watch_command (char *arg, int from_tty)
5338 watch_command_1 (arg, hw_write, from_tty);
5342 rwatch_command_wrapper (char *arg, int from_tty)
5344 rwatch_command (arg, from_tty);
5348 rwatch_command (char *arg, int from_tty)
5350 watch_command_1 (arg, hw_read, from_tty);
5354 awatch_command_wrapper (char *arg, int from_tty)
5356 awatch_command (arg, from_tty);
5360 awatch_command (char *arg, int from_tty)
5362 watch_command_1 (arg, hw_access, from_tty);
5366 /* Helper routines for the until_command routine in infcmd.c. Here
5367 because it uses the mechanisms of breakpoints. */
5369 /* This function is called by fetch_inferior_event via the
5370 cmd_continuation pointer, to complete the until command. It takes
5371 care of cleaning up the temporary breakpoints set up by the until
5374 until_break_command_continuation (struct continuation_arg *arg)
5376 struct cleanup *cleanups;
5378 cleanups = (struct cleanup *) arg->data.pointer;
5379 do_exec_cleanups (cleanups);
5384 until_break_command (char *arg, int from_tty)
5386 struct symtabs_and_lines sals;
5387 struct symtab_and_line sal;
5388 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5389 struct breakpoint *breakpoint;
5390 struct cleanup *old_chain;
5391 struct continuation_arg *arg1;
5394 clear_proceed_status ();
5396 /* Set a breakpoint where the user wants it and at return from
5399 if (default_breakpoint_valid)
5400 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5401 default_breakpoint_line, (char ***) NULL);
5403 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5404 0, (char ***) NULL);
5406 if (sals.nelts != 1)
5407 error ("Couldn't get information on specified line.");
5410 xfree (sals.sals); /* malloc'd, so freed */
5413 error ("Junk at end of arguments.");
5415 resolve_sal_pc (&sal);
5417 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5419 if (!event_loop_p || !target_can_async_p ())
5420 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5422 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5424 /* If we are running asynchronously, and the target supports async
5425 execution, we are not waiting for the target to stop, in the call
5426 tp proceed, below. This means that we cannot delete the
5427 brekpoints until the target has actually stopped. The only place
5428 where we get a chance to do that is in fetch_inferior_event, so
5429 we must set things up for that. */
5431 if (event_loop_p && target_can_async_p ())
5433 /* In this case the arg for the continuation is just the point
5434 in the exec_cleanups chain from where to start doing
5435 cleanups, because all the continuation does is the cleanups in
5436 the exec_cleanup_chain. */
5438 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5440 arg1->data.pointer = old_chain;
5442 add_continuation (until_break_command_continuation, arg1);
5445 /* Keep within the current frame */
5449 sal = find_pc_line (prev_frame->pc, 0);
5450 sal.pc = prev_frame->pc;
5451 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5452 if (!event_loop_p || !target_can_async_p ())
5453 make_cleanup_delete_breakpoint (breakpoint);
5455 make_exec_cleanup_delete_breakpoint (breakpoint);
5458 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5459 /* Do the cleanups now, anly if we are not running asynchronously,
5460 of if we are, but the target is still synchronous. */
5461 if (!event_loop_p || !target_can_async_p ())
5462 do_cleanups (old_chain);
5466 /* These aren't used; I don't konw what they were for. */
5467 /* Set a breakpoint at the catch clause for NAME. */
5469 catch_breakpoint (char *name)
5474 disable_catch_breakpoint (void)
5479 delete_catch_breakpoint (void)
5484 enable_catch_breakpoint (void)
5491 struct sal_chain *next;
5492 struct symtab_and_line sal;
5496 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5497 had been commented out in the v.4.16 sources, and stays
5498 disabled there now because "catch NAME" syntax isn't allowed.
5500 /* This isn't used; I don't know what it was for. */
5501 /* For each catch clause identified in ARGS, run FUNCTION
5502 with that clause as an argument. */
5503 static struct symtabs_and_lines
5504 map_catch_names (char *args, int (*function) ())
5506 register char *p = args;
5508 struct symtabs_and_lines sals;
5510 struct sal_chain *sal_chain = 0;
5514 error_no_arg ("one or more catch names");
5522 /* Don't swallow conditional part. */
5523 if (p1[0] == 'i' && p1[1] == 'f'
5524 && (p1[2] == ' ' || p1[2] == '\t'))
5530 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5534 if (*p1 && *p1 != ' ' && *p1 != '\t')
5535 error ("Arguments must be catch names.");
5541 struct sal_chain *next = (struct sal_chain *)
5542 alloca (sizeof (struct sal_chain));
5543 next->next = sal_chain;
5544 next->sal = get_catch_sal (p);
5549 printf_unfiltered ("No catch clause for exception %s.\n", p);
5554 while (*p == ' ' || *p == '\t')
5560 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5562 static struct symtabs_and_lines
5563 get_catch_sals (int this_level_only)
5565 register struct blockvector *bl;
5566 register struct block *block;
5567 int index, have_default = 0;
5569 struct symtabs_and_lines sals;
5570 struct sal_chain *sal_chain = 0;
5571 char *blocks_searched;
5573 /* Not sure whether an error message is always the correct response,
5574 but it's better than a core dump. */
5575 if (selected_frame == NULL)
5576 error ("No selected frame.");
5577 block = get_frame_block (selected_frame);
5578 pc = selected_frame->pc;
5584 error ("No symbol table info available.\n");
5586 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5587 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5588 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5592 CORE_ADDR end = BLOCK_END (block) - 4;
5595 if (bl != blockvector_for_pc (end, &index))
5596 error ("blockvector blotch");
5597 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5598 error ("blockvector botch");
5599 last_index = BLOCKVECTOR_NBLOCKS (bl);
5602 /* Don't print out blocks that have gone by. */
5603 while (index < last_index
5604 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5607 while (index < last_index
5608 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5610 if (blocks_searched[index] == 0)
5612 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5614 register struct symbol *sym;
5616 ALL_BLOCK_SYMBOLS (b, i, sym)
5618 if (STREQ (SYMBOL_NAME (sym), "default"))
5624 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5626 struct sal_chain *next = (struct sal_chain *)
5627 alloca (sizeof (struct sal_chain));
5628 next->next = sal_chain;
5629 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5634 blocks_searched[index] = 1;
5640 if (sal_chain && this_level_only)
5643 /* After handling the function's top-level block, stop.
5644 Don't continue to its superblock, the block of
5645 per-file symbols. */
5646 if (BLOCK_FUNCTION (block))
5648 block = BLOCK_SUPERBLOCK (block);
5653 struct sal_chain *tmp_chain;
5655 /* Count the number of entries. */
5656 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5657 tmp_chain = tmp_chain->next)
5661 sals.sals = (struct symtab_and_line *)
5662 xmalloc (index * sizeof (struct symtab_and_line));
5663 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5664 sals.sals[index] = sal_chain->sal;
5671 ep_skip_leading_whitespace (char **s)
5673 if ((s == NULL) || (*s == NULL))
5675 while (isspace (**s))
5679 /* This function examines a string, and attempts to find a token
5680 that might be an event name in the leading characters. If a
5681 possible match is found, a pointer to the last character of
5682 the token is returned. Else, NULL is returned. */
5685 ep_find_event_name_end (char *arg)
5688 char *event_name_end = NULL;
5690 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5694 /* We break out of the loop when we find a token delimiter.
5695 Basically, we're looking for alphanumerics and underscores;
5696 anything else delimites the token. */
5699 if (!isalnum (*s) && (*s != '_'))
5705 return event_name_end;
5709 /* This function attempts to parse an optional "if <cond>" clause
5710 from the arg string. If one is not found, it returns NULL.
5712 Else, it returns a pointer to the condition string. (It does not
5713 attempt to evaluate the string against a particular block.) And,
5714 it updates arg to point to the first character following the parsed
5715 if clause in the arg string. */
5718 ep_parse_optional_if_clause (char **arg)
5722 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5725 /* Skip the "if" keyword. */
5728 /* Skip any extra leading whitespace, and record the start of the
5729 condition string. */
5730 ep_skip_leading_whitespace (arg);
5733 /* Assume that the condition occupies the remainder of the arg string. */
5734 (*arg) += strlen (cond_string);
5739 /* This function attempts to parse an optional filename from the arg
5740 string. If one is not found, it returns NULL.
5742 Else, it returns a pointer to the parsed filename. (This function
5743 makes no attempt to verify that a file of that name exists, or is
5744 accessible.) And, it updates arg to point to the first character
5745 following the parsed filename in the arg string.
5747 Note that clients needing to preserve the returned filename for
5748 future access should copy it to their own buffers. */
5750 ep_parse_optional_filename (char **arg)
5752 static char filename[1024];
5757 if ((*arg_p == '\0') || isspace (*arg_p))
5775 /* Commands to deal with catching events, such as signals, exceptions,
5776 process start/exit, etc. */
5780 catch_fork, catch_vfork
5784 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5785 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5786 char *arg, int tempflag, int from_tty);
5789 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5792 char *cond_string = NULL;
5794 ep_skip_leading_whitespace (&arg);
5796 /* The allowed syntax is:
5798 catch [v]fork if <cond>
5800 First, check if there's an if clause. */
5801 cond_string = ep_parse_optional_if_clause (&arg);
5803 if ((*arg != '\0') && !isspace (*arg))
5804 error ("Junk at end of arguments.");
5806 /* If this target supports it, create a fork or vfork catchpoint
5807 and enable reporting of such events. */
5811 create_fork_event_catchpoint (tempflag, cond_string);
5814 create_vfork_event_catchpoint (tempflag, cond_string);
5817 error ("unsupported or unknown fork kind; cannot catch it");
5823 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5825 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
5827 char *cond_string = NULL;
5829 ep_skip_leading_whitespace (&arg);
5831 /* The allowed syntax is:
5833 catch exec if <cond>
5835 First, check if there's an if clause. */
5836 cond_string = ep_parse_optional_if_clause (&arg);
5838 if ((*arg != '\0') && !isspace (*arg))
5839 error ("Junk at end of arguments.");
5841 /* If this target supports it, create an exec catchpoint
5842 and enable reporting of such events. */
5843 create_exec_event_catchpoint (tempflag, cond_string);
5847 #if defined(SOLIB_ADD)
5849 catch_load_command_1 (char *arg, int tempflag, int from_tty)
5851 char *dll_pathname = NULL;
5852 char *cond_string = NULL;
5854 ep_skip_leading_whitespace (&arg);
5856 /* The allowed syntax is:
5858 catch load if <cond>
5859 catch load <filename>
5860 catch load <filename> if <cond>
5862 The user is not allowed to specify the <filename> after an
5865 We'll ignore the pathological case of a file named "if".
5867 First, check if there's an if clause. If so, then there
5868 cannot be a filename. */
5869 cond_string = ep_parse_optional_if_clause (&arg);
5871 /* If there was an if clause, then there cannot be a filename.
5872 Else, there might be a filename and an if clause. */
5873 if (cond_string == NULL)
5875 dll_pathname = ep_parse_optional_filename (&arg);
5876 ep_skip_leading_whitespace (&arg);
5877 cond_string = ep_parse_optional_if_clause (&arg);
5880 if ((*arg != '\0') && !isspace (*arg))
5881 error ("Junk at end of arguments.");
5883 /* Create a load breakpoint that only triggers when a load of
5884 the specified dll (or any dll, if no pathname was specified)
5886 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5887 dll_pathname, cond_string);
5891 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
5893 char *dll_pathname = NULL;
5894 char *cond_string = NULL;
5896 ep_skip_leading_whitespace (&arg);
5898 /* The allowed syntax is:
5900 catch unload if <cond>
5901 catch unload <filename>
5902 catch unload <filename> if <cond>
5904 The user is not allowed to specify the <filename> after an
5907 We'll ignore the pathological case of a file named "if".
5909 First, check if there's an if clause. If so, then there
5910 cannot be a filename. */
5911 cond_string = ep_parse_optional_if_clause (&arg);
5913 /* If there was an if clause, then there cannot be a filename.
5914 Else, there might be a filename and an if clause. */
5915 if (cond_string == NULL)
5917 dll_pathname = ep_parse_optional_filename (&arg);
5918 ep_skip_leading_whitespace (&arg);
5919 cond_string = ep_parse_optional_if_clause (&arg);
5922 if ((*arg != '\0') && !isspace (*arg))
5923 error ("Junk at end of arguments.");
5925 /* Create an unload breakpoint that only triggers when an unload of
5926 the specified dll (or any dll, if no pathname was specified)
5928 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5929 dll_pathname, cond_string);
5931 #endif /* SOLIB_ADD */
5933 /* Commands to deal with catching exceptions. */
5935 /* Set a breakpoint at the specified callback routine for an
5936 exception event callback */
5939 create_exception_catchpoint (int tempflag, char *cond_string,
5940 enum exception_event_kind ex_event,
5941 struct symtab_and_line *sal)
5943 struct breakpoint *b;
5944 int thread = -1; /* All threads. */
5947 if (!sal) /* no exception support? */
5952 case EX_EVENT_THROW:
5953 bptype = bp_catch_throw;
5955 case EX_EVENT_CATCH:
5956 bptype = bp_catch_catch;
5958 default: /* error condition */
5959 error ("Internal error -- invalid catchpoint kind");
5962 b = set_raw_breakpoint (*sal, bptype);
5963 set_breakpoint_count (breakpoint_count + 1);
5964 b->number = breakpoint_count;
5966 b->cond_string = (cond_string == NULL) ?
5967 NULL : savestring (cond_string, strlen (cond_string));
5969 b->addr_string = NULL;
5970 b->enable_state = bp_enabled;
5971 b->disposition = tempflag ? disp_del : disp_donttouch;
5975 /* Deal with "catch catch" and "catch throw" commands */
5978 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
5979 int tempflag, int from_tty)
5981 char *cond_string = NULL;
5982 struct symtab_and_line *sal = NULL;
5984 ep_skip_leading_whitespace (&arg);
5986 cond_string = ep_parse_optional_if_clause (&arg);
5988 if ((*arg != '\0') && !isspace (*arg))
5989 error ("Junk at end of arguments.");
5991 if ((ex_event != EX_EVENT_THROW) &&
5992 (ex_event != EX_EVENT_CATCH))
5993 error ("Unsupported or unknown exception event; cannot catch it");
5995 /* See if we can find a callback routine */
5996 sal = target_enable_exception_callback (ex_event, 1);
6000 /* We have callbacks from the runtime system for exceptions.
6001 Set a breakpoint on the sal found, if no errors */
6002 if (sal != (struct symtab_and_line *) -1)
6003 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6005 return; /* something went wrong with setting up callbacks */
6009 /* No callbacks from runtime system for exceptions.
6010 Try GNU C++ exception breakpoints using labels in debug info. */
6011 if (ex_event == EX_EVENT_CATCH)
6013 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6015 else if (ex_event == EX_EVENT_THROW)
6017 /* Set a breakpoint on __raise_exception () */
6019 warning ("Unsupported with this platform/compiler combination.");
6020 warning ("Perhaps you can achieve the effect you want by setting");
6021 warning ("a breakpoint on __raise_exception().");
6026 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6027 inside a catch_errors */
6030 cover_target_enable_exception_callback (PTR arg)
6032 args_for_catchpoint_enable *args = arg;
6033 struct symtab_and_line *sal;
6034 sal = target_enable_exception_callback (args->kind, args->enable_p);
6037 else if (sal == (struct symtab_and_line *) -1)
6040 return 1; /*is valid */
6045 /* This is the original v.4.16 and earlier version of the
6046 catch_command_1() function. Now that other flavours of "catch"
6047 have been introduced, and since exception handling can be handled
6048 in other ways (through target ops) also, this is used only for the
6049 GNU C++ exception handling system.
6050 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6051 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6052 there was no code in GDB 4.16 for "catch throw".
6054 Called from catch_exception_command_1 () */
6058 handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
6060 /* First, translate ARG into something we can deal with in terms
6063 struct symtabs_and_lines sals;
6064 struct symtab_and_line sal;
6065 register struct expression *cond = 0;
6066 register struct breakpoint *b;
6070 INIT_SAL (&sal); /* initialize to zeroes */
6072 /* If no arg given, or if first arg is 'if ', all active catch clauses
6073 are breakpointed. */
6075 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6076 && (arg[2] == ' ' || arg[2] == '\t')))
6078 /* Grab all active catch clauses. */
6079 sals = get_catch_sals (0);
6083 /* Grab selected catch clauses. */
6084 error ("catch NAME not implemented");
6087 /* Not sure why this code has been disabled. I'm leaving
6088 it disabled. We can never come here now anyway
6089 since we don't allow the "catch NAME" syntax.
6092 /* This isn't used; I don't know what it was for. */
6093 sals = map_catch_names (arg, catch_breakpoint);
6101 for (i = 0; i < sals.nelts; i++)
6103 resolve_sal_pc (&sals.sals[i]);
6107 if (arg[0] == 'i' && arg[1] == 'f'
6108 && (arg[2] == ' ' || arg[2] == '\t'))
6109 cond = parse_exp_1 ((arg += 2, &arg),
6110 block_for_pc (sals.sals[i].pc), 0);
6112 error ("Junk at end of arguments.");
6117 for (i = 0; i < sals.nelts; i++)
6122 describe_other_breakpoints (sal.pc, sal.section);
6124 /* Important -- this is an ordinary breakpoint. For platforms
6125 with callback support for exceptions,
6126 create_exception_catchpoint() will create special bp types
6127 (bp_catch_catch and bp_catch_throw), and there is code in
6128 insert_breakpoints() and elsewhere that depends on that. */
6129 b = set_raw_breakpoint (sal, bp_breakpoint);
6130 set_breakpoint_count (breakpoint_count + 1);
6131 b->number = breakpoint_count;
6134 b->enable_state = bp_enabled;
6135 b->disposition = tempflag ? disp_del : disp_donttouch;
6142 warning ("Multiple breakpoints were set.");
6143 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6149 catch_command_1 (char *arg, int tempflag, int from_tty)
6152 /* The first argument may be an event name, such as "start" or "load".
6153 If so, then handle it as such. If it doesn't match an event name,
6154 then attempt to interpret it as an exception name. (This latter is
6155 the v4.16-and-earlier GDB meaning of the "catch" command.)
6157 First, try to find the bounds of what might be an event name. */
6158 char *arg1_start = arg;
6162 if (arg1_start == NULL)
6164 /* Old behaviour was to use pre-v-4.16 syntax */
6165 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6167 /* Now, this is not allowed */
6168 error ("Catch requires an event name.");
6171 arg1_end = ep_find_event_name_end (arg1_start);
6172 if (arg1_end == NULL)
6173 error ("catch requires an event");
6174 arg1_length = arg1_end + 1 - arg1_start;
6176 /* Try to match what we found against known event names. */
6177 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6179 error ("Catch of signal not yet implemented");
6181 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6183 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6184 tempflag, from_tty);
6186 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6188 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6189 tempflag, from_tty);
6191 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6193 error ("Catch of thread_start not yet implemented");
6195 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6197 error ("Catch of thread_exit not yet implemented");
6199 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6201 error ("Catch of thread_join not yet implemented");
6203 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6205 error ("Catch of start not yet implemented");
6207 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6209 error ("Catch of exit not yet implemented");
6211 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6213 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6214 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6216 error ("Catch of fork not yet implemented");
6219 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6221 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6222 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6224 error ("Catch of vfork not yet implemented");
6227 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6229 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6230 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6232 error ("Catch of exec not yet implemented");
6235 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6237 #if defined(SOLIB_ADD)
6238 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6240 error ("Catch of load not implemented");
6243 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6245 #if defined(SOLIB_ADD)
6246 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6248 error ("Catch of load not implemented");
6251 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6253 error ("Catch of stop not yet implemented");
6256 /* This doesn't appear to be an event name */
6260 /* Pre-v.4.16 behaviour was to treat the argument
6261 as the name of an exception */
6262 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6263 /* Now this is not allowed */
6264 error ("Unknown event kind specified for catch");
6269 /* Used by the gui, could be made a worker for other things. */
6272 set_breakpoint_sal (struct symtab_and_line sal)
6274 struct breakpoint *b;
6275 b = set_raw_breakpoint (sal, bp_breakpoint);
6276 set_breakpoint_count (breakpoint_count + 1);
6277 b->number = breakpoint_count;
6284 /* These aren't used; I don't know what they were for. */
6285 /* Disable breakpoints on all catch clauses described in ARGS. */
6287 disable_catch (char *args)
6289 /* Map the disable command to catch clauses described in ARGS. */
6292 /* Enable breakpoints on all catch clauses described in ARGS. */
6294 enable_catch (char *args)
6296 /* Map the disable command to catch clauses described in ARGS. */
6299 /* Delete breakpoints on all catch clauses in the active scope. */
6301 delete_catch (char *args)
6303 /* Map the delete command to catch clauses described in ARGS. */
6308 catch_command (char *arg, int from_tty)
6310 catch_command_1 (arg, 0, from_tty);
6315 tcatch_command (char *arg, int from_tty)
6317 catch_command_1 (arg, 1, from_tty);
6322 clear_command (char *arg, int from_tty)
6324 register struct breakpoint *b, *b1;
6326 struct symtabs_and_lines sals;
6327 struct symtab_and_line sal;
6328 register struct breakpoint *found;
6333 sals = decode_line_spec (arg, 1);
6338 sals.sals = (struct symtab_and_line *)
6339 xmalloc (sizeof (struct symtab_and_line));
6340 INIT_SAL (&sal); /* initialize to zeroes */
6341 sal.line = default_breakpoint_line;
6342 sal.symtab = default_breakpoint_symtab;
6343 sal.pc = default_breakpoint_address;
6344 if (sal.symtab == 0)
6345 error ("No source file specified.");
6353 /* For each line spec given, delete bps which correspond
6354 to it. We do this in two loops: the first loop looks at
6355 the initial bp(s) in the chain which should be deleted,
6356 the second goes down the rest of the chain looking ahead
6357 one so it can take those bps off the chain without messing
6361 for (i = 0; i < sals.nelts; i++)
6363 /* If exact pc given, clear bpts at that pc.
6364 If line given (pc == 0), clear all bpts on specified line.
6365 If defaulting, clear all bpts on default line
6368 defaulting sal.pc != 0 tests to do
6373 1 0 <can't happen> */
6376 found = (struct breakpoint *) 0;
6379 while (breakpoint_chain
6380 /* Why don't we check here that this is not
6381 a watchpoint, etc., as we do below?
6382 I can't make it fail, but don't know
6383 what's stopping the failure: a watchpoint
6384 of the same address as "sal.pc" should
6385 wind up being deleted. */
6387 && (((sal.pc && (breakpoint_chain->address == sal.pc))
6388 && (!overlay_debugging
6389 || breakpoint_chain->section == sal.section))
6390 || ((default_match || (0 == sal.pc))
6391 && breakpoint_chain->source_file != NULL
6392 && sal.symtab != NULL
6393 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6394 && breakpoint_chain->line_number == sal.line)))
6397 b1 = breakpoint_chain;
6398 breakpoint_chain = b1->next;
6405 && b->next->type != bp_none
6406 && b->next->type != bp_watchpoint
6407 && b->next->type != bp_hardware_watchpoint
6408 && b->next->type != bp_read_watchpoint
6409 && b->next->type != bp_access_watchpoint
6410 && (((sal.pc && (b->next->address == sal.pc))
6411 && (!overlay_debugging || b->next->section == sal.section))
6412 || ((default_match || (0 == sal.pc))
6413 && b->next->source_file != NULL
6414 && sal.symtab != NULL
6415 && STREQ (b->next->source_file, sal.symtab->filename)
6416 && b->next->line_number == sal.line)))
6429 error ("No breakpoint at %s.", arg);
6431 error ("No breakpoint at this line.");
6435 from_tty = 1; /* Always report if deleted more than one */
6437 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6438 breakpoints_changed ();
6442 printf_unfiltered ("%d ", found->number);
6444 delete_breakpoint (found);
6448 putchar_unfiltered ('\n');
6453 /* Delete breakpoint in BS if they are `delete' breakpoints and
6454 all breakpoints that are marked for deletion, whether hit or not.
6455 This is called after any breakpoint is hit, or after errors. */
6458 breakpoint_auto_delete (bpstat bs)
6460 struct breakpoint *b, *temp;
6462 for (; bs; bs = bs->next)
6463 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6465 delete_breakpoint (bs->breakpoint_at);
6467 ALL_BREAKPOINTS_SAFE (b, temp)
6469 if (b->disposition == disp_del_at_next_stop)
6470 delete_breakpoint (b);
6474 /* Delete a breakpoint and clean up all traces of it in the data
6478 delete_breakpoint (struct breakpoint *bpt)
6480 register struct breakpoint *b;
6484 error ("Internal error (attempted to delete a NULL breakpoint)");
6487 /* Has this bp already been deleted? This can happen because multiple
6488 lists can hold pointers to bp's. bpstat lists are especial culprits.
6490 One example of this happening is a watchpoint's scope bp. When the
6491 scope bp triggers, we notice that the watchpoint is out of scope, and
6492 delete it. We also delete its scope bp. But the scope bp is marked
6493 "auto-deleting", and is already on a bpstat. That bpstat is then
6494 checked for auto-deleting bp's, which are deleted.
6496 A real solution to this problem might involve reference counts in bp's,
6497 and/or giving them pointers back to their referencing bpstat's, and
6498 teaching delete_breakpoint to only free a bp's storage when no more
6499 references were extent. A cheaper bandaid was chosen. */
6500 if (bpt->type == bp_none)
6503 if (delete_breakpoint_hook)
6504 delete_breakpoint_hook (bpt);
6505 breakpoint_delete_event (bpt->number);
6508 remove_breakpoint (bpt, mark_inserted);
6510 if (breakpoint_chain == bpt)
6511 breakpoint_chain = bpt->next;
6513 /* If we have callback-style exception catchpoints, don't go through
6514 the adjustments to the C++ runtime library etc. if the inferior
6515 isn't actually running. target_enable_exception_callback for a
6516 null target ops vector gives an undesirable error message, so we
6517 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6518 exceptions are supported in this way, it's OK for now. FIXME */
6519 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6521 static char message1[] = "Error in deleting catchpoint %d:\n";
6522 static char message[sizeof (message1) + 30];
6523 args_for_catchpoint_enable args;
6525 /* Format possible error msg */
6526 sprintf (message, message1, bpt->number);
6527 args.kind = bpt->type == bp_catch_catch ?
6528 EX_EVENT_CATCH : EX_EVENT_THROW;
6530 catch_errors (cover_target_enable_exception_callback, &args,
6531 message, RETURN_MASK_ALL);
6538 b->next = bpt->next;
6542 check_duplicates (bpt);
6543 /* If this breakpoint was inserted, and there is another breakpoint
6544 at the same address, we need to insert the other breakpoint. */
6546 && bpt->type != bp_hardware_watchpoint
6547 && bpt->type != bp_read_watchpoint
6548 && bpt->type != bp_access_watchpoint
6549 && bpt->type != bp_catch_fork
6550 && bpt->type != bp_catch_vfork
6551 && bpt->type != bp_catch_exec)
6554 if (b->address == bpt->address
6555 && b->section == bpt->section
6557 && b->enable_state != bp_disabled
6558 && b->enable_state != bp_shlib_disabled
6559 && b->enable_state != bp_call_disabled)
6563 /* We should never reach this point if there is a permanent
6564 breakpoint at the same address as the one being deleted.
6565 If there is a permanent breakpoint somewhere, it should
6566 always be the only one inserted. */
6567 if (b->enable_state == bp_permanent)
6568 internal_error (__FILE__, __LINE__,
6569 "another breakpoint was inserted on top of "
6570 "a permanent breakpoint");
6572 if (b->type == bp_hardware_breakpoint)
6573 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6575 val = target_insert_breakpoint (b->address, b->shadow_contents);
6579 target_terminal_ours_for_output ();
6580 warning ("Cannot insert breakpoint %d:", b->number);
6581 memory_error (val, b->address); /* which bombs us out */
6588 free_command_lines (&bpt->commands);
6591 if (bpt->cond_string != NULL)
6592 xfree (bpt->cond_string);
6593 if (bpt->addr_string != NULL)
6594 xfree (bpt->addr_string);
6595 if (bpt->exp != NULL)
6597 if (bpt->exp_string != NULL)
6598 xfree (bpt->exp_string);
6599 if (bpt->val != NULL)
6600 value_free (bpt->val);
6601 if (bpt->source_file != NULL)
6602 xfree (bpt->source_file);
6603 if (bpt->dll_pathname != NULL)
6604 xfree (bpt->dll_pathname);
6605 if (bpt->triggered_dll_pathname != NULL)
6606 xfree (bpt->triggered_dll_pathname);
6607 if (bpt->exec_pathname != NULL)
6608 xfree (bpt->exec_pathname);
6610 /* Be sure no bpstat's are pointing at it after it's been freed. */
6611 /* FIXME, how can we find all bpstat's?
6612 We just check stop_bpstat for now. */
6613 for (bs = stop_bpstat; bs; bs = bs->next)
6614 if (bs->breakpoint_at == bpt)
6616 bs->breakpoint_at = NULL;
6618 /* we'd call bpstat_clear_actions, but that free's stuff and due
6619 to the multiple pointers pointing to one item with no
6620 reference counts found anywhere through out the bpstat's (how
6621 do you spell fragile?), we don't want to free things twice --
6622 better a memory leak than a corrupt malloc pool! */
6623 bs->commands = NULL;
6626 /* On the chance that someone will soon try again to delete this same
6627 bp, we mark it as deleted before freeing its storage. */
6628 bpt->type = bp_none;
6634 do_delete_breakpoint_cleanup (void *b)
6636 delete_breakpoint (b);
6640 make_cleanup_delete_breakpoint (struct breakpoint *b)
6642 return make_cleanup (do_delete_breakpoint_cleanup, b);
6646 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6648 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6652 delete_command (char *arg, int from_tty)
6654 struct breakpoint *b, *temp;
6658 int breaks_to_delete = 0;
6660 /* Delete all breakpoints if no argument.
6661 Do not delete internal or call-dummy breakpoints, these
6662 have to be deleted with an explicit breakpoint number argument. */
6665 if (b->type != bp_call_dummy &&
6666 b->type != bp_shlib_event &&
6667 b->type != bp_thread_event &&
6669 breaks_to_delete = 1;
6672 /* Ask user only if there are some breakpoints to delete. */
6674 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6676 ALL_BREAKPOINTS_SAFE (b, temp)
6678 if (b->type != bp_call_dummy &&
6679 b->type != bp_shlib_event &&
6680 b->type != bp_thread_event &&
6682 delete_breakpoint (b);
6687 map_breakpoint_numbers (arg, delete_breakpoint);
6690 /* Reset a breakpoint given it's struct breakpoint * BINT.
6691 The value we return ends up being the return value from catch_errors.
6692 Unused in this case. */
6695 breakpoint_re_set_one (PTR bint)
6697 /* get past catch_errs */
6698 struct breakpoint *b = (struct breakpoint *) bint;
6701 struct symtabs_and_lines sals;
6703 enum enable_state save_enable;
6708 warning ("attempted to reset apparently deleted breakpoint #%d?",
6712 case bp_hardware_breakpoint:
6714 case bp_catch_unload:
6715 if (b->addr_string == NULL)
6717 /* Anything without a string can't be re-set. */
6718 delete_breakpoint (b);
6721 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6723 ``And a hack it is, although Apple's Darwin version of GDB
6724 contains an almost identical hack to implement a "future
6725 break" command. It seems to work in many real world cases,
6726 but it is easy to come up with a test case where the patch
6727 doesn't help at all.''
6729 ``It seems that the way GDB implements breakpoints - in -
6730 shared - libraries was designed for a.out shared library
6731 systems (SunOS 4) where shared libraries were loaded at a
6732 fixed address in memory. Since ELF shared libraries can (and
6733 will) be loaded at any address in memory, things break.
6734 Fixing this is not trivial. Therefore, I'm not sure whether
6735 we should add this hack to the branch only. I cannot
6736 guarantee that things will be fixed on the trunk in the near
6739 In case we have a problem, disable this breakpoint. We'll
6740 restore its status if we succeed. Don't disable a
6741 shlib_disabled breakpoint though. There's a fair chance we
6742 can't re-set it if the shared library it's in hasn't been
6744 save_enable = b->enable_state;
6745 if (b->enable_state != bp_shlib_disabled)
6746 b->enable_state = bp_disabled;
6748 set_language (b->language);
6749 input_radix = b->input_radix;
6751 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6752 for (i = 0; i < sals.nelts; i++)
6754 resolve_sal_pc (&sals.sals[i]);
6756 /* Reparse conditions, they might contain references to the
6758 if (b->cond_string != NULL)
6763 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6766 /* We need to re-set the breakpoint if the address changes... */
6767 if (b->address != sals.sals[i].pc
6768 /* ...or new and old breakpoints both have source files, and
6769 the source file name or the line number changes... */
6770 || (b->source_file != NULL
6771 && sals.sals[i].symtab != NULL
6772 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6773 || b->line_number != sals.sals[i].line)
6775 /* ...or we switch between having a source file and not having
6777 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6780 if (b->source_file != NULL)
6781 xfree (b->source_file);
6782 if (sals.sals[i].symtab == NULL)
6783 b->source_file = NULL;
6786 savestring (sals.sals[i].symtab->filename,
6787 strlen (sals.sals[i].symtab->filename));
6788 b->line_number = sals.sals[i].line;
6789 b->address = sals.sals[i].pc;
6791 /* Used to check for duplicates here, but that can
6792 cause trouble, as it doesn't check for disabled
6797 /* Might be better to do this just once per breakpoint_re_set,
6798 rather than once for every breakpoint. */
6799 breakpoints_changed ();
6801 b->section = sals.sals[i].section;
6802 b->enable_state = save_enable; /* Restore it, this worked. */
6805 /* Now that this is re-enabled, check_duplicates
6807 check_duplicates (b);
6814 case bp_hardware_watchpoint:
6815 case bp_read_watchpoint:
6816 case bp_access_watchpoint:
6817 innermost_block = NULL;
6818 /* The issue arises of what context to evaluate this in. The
6819 same one as when it was set, but what does that mean when
6820 symbols have been re-read? We could save the filename and
6821 functionname, but if the context is more local than that, the
6822 best we could do would be something like how many levels deep
6823 and which index at that particular level, but that's going to
6824 be less stable than filenames or function names. */
6826 /* So for now, just use a global context. */
6829 b->exp = parse_expression (b->exp_string);
6830 b->exp_valid_block = innermost_block;
6831 mark = value_mark ();
6833 value_free (b->val);
6834 b->val = evaluate_expression (b->exp);
6835 release_value (b->val);
6836 if (VALUE_LAZY (b->val))
6837 value_fetch_lazy (b->val);
6839 if (b->cond_string != NULL)
6844 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6846 if (b->enable_state == bp_enabled)
6848 value_free_to_mark (mark);
6850 case bp_catch_catch:
6851 case bp_catch_throw:
6853 /* We needn't really do anything to reset these, since the mask
6854 that requests them is unaffected by e.g., new libraries being
6857 case bp_catch_vfork:
6862 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6864 /* Delete longjmp breakpoints, they will be reset later by
6865 breakpoint_re_set. */
6867 case bp_longjmp_resume:
6868 delete_breakpoint (b);
6871 /* This breakpoint is special, it's set up when the inferior
6872 starts and we really don't want to touch it. */
6873 case bp_shlib_event:
6875 /* Like bp_shlib_event, this breakpoint type is special.
6876 Once it is set up, we do not want to touch it. */
6877 case bp_thread_event:
6879 /* Keep temporary breakpoints, which can be encountered when we step
6880 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6881 Otherwise these should have been blown away via the cleanup chain
6882 or by breakpoint_init_inferior when we rerun the executable. */
6885 case bp_watchpoint_scope:
6887 case bp_step_resume:
6894 /* Re-set all breakpoints after symbols have been re-loaded. */
6896 breakpoint_re_set (void)
6898 struct breakpoint *b, *temp;
6899 enum language save_language;
6900 int save_input_radix;
6901 static char message1[] = "Error in re-setting breakpoint %d:\n";
6902 char message[sizeof (message1) + 30 /* slop */ ];
6904 save_language = current_language->la_language;
6905 save_input_radix = input_radix;
6906 ALL_BREAKPOINTS_SAFE (b, temp)
6908 /* Format possible error msg */
6909 sprintf (message, message1, b->number);
6910 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6912 set_language (save_language);
6913 input_radix = save_input_radix;
6915 #ifdef GET_LONGJMP_TARGET
6916 create_longjmp_breakpoint ("longjmp");
6917 create_longjmp_breakpoint ("_longjmp");
6918 create_longjmp_breakpoint ("siglongjmp");
6919 create_longjmp_breakpoint ("_siglongjmp");
6920 create_longjmp_breakpoint (NULL);
6924 /* Reset the thread number of this breakpoint:
6926 - If the breakpoint is for all threads, leave it as-is.
6927 - Else, reset it to the current thread for inferior_ptid. */
6929 breakpoint_re_set_thread (struct breakpoint *b)
6931 if (b->thread != -1)
6933 if (in_thread_list (inferior_ptid))
6934 b->thread = pid_to_thread_id (inferior_ptid);
6938 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6939 If from_tty is nonzero, it prints a message to that effect,
6940 which ends with a period (no newline). */
6943 set_ignore_count (int bptnum, int count, int from_tty)
6945 register struct breakpoint *b;
6951 if (b->number == bptnum)
6953 b->ignore_count = count;
6956 else if (count == 0)
6957 printf_filtered ("Will stop next time breakpoint %d is reached.",
6959 else if (count == 1)
6960 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6963 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6965 breakpoints_changed ();
6969 error ("No breakpoint number %d.", bptnum);
6972 /* Clear the ignore counts of all breakpoints. */
6974 breakpoint_clear_ignore_counts (void)
6976 struct breakpoint *b;
6979 b->ignore_count = 0;
6982 /* Command to set ignore-count of breakpoint N to COUNT. */
6985 ignore_command (char *args, int from_tty)
6991 error_no_arg ("a breakpoint number");
6993 num = get_number (&p);
6995 error ("bad breakpoint number: '%s'", args);
6997 error ("Second argument (specified ignore-count) is missing.");
6999 set_ignore_count (num,
7000 longest_to_int (value_as_long (parse_and_eval (p))),
7002 printf_filtered ("\n");
7003 breakpoints_changed ();
7006 /* Call FUNCTION on each of the breakpoints
7007 whose numbers are given in ARGS. */
7010 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7012 register char *p = args;
7015 register struct breakpoint *b, *tmp;
7019 error_no_arg ("one or more breakpoint numbers");
7026 num = get_number_or_range (&p1);
7029 warning ("bad breakpoint number at or near '%s'", p);
7033 ALL_BREAKPOINTS_SAFE (b, tmp)
7034 if (b->number == num)
7036 struct breakpoint *related_breakpoint = b->related_breakpoint;
7039 if (related_breakpoint)
7040 function (related_breakpoint);
7044 printf_unfiltered ("No breakpoint number %d.\n", num);
7051 disable_breakpoint (struct breakpoint *bpt)
7053 /* Never disable a watchpoint scope breakpoint; we want to
7054 hit them when we leave scope so we can delete both the
7055 watchpoint and its scope breakpoint at that time. */
7056 if (bpt->type == bp_watchpoint_scope)
7059 /* You can't disable permanent breakpoints. */
7060 if (bpt->enable_state == bp_permanent)
7063 bpt->enable_state = bp_disabled;
7065 check_duplicates (bpt);
7067 if (modify_breakpoint_hook)
7068 modify_breakpoint_hook (bpt);
7069 breakpoint_modify_event (bpt->number);
7074 disable_command (char *args, int from_tty)
7076 register struct breakpoint *bpt;
7078 ALL_BREAKPOINTS (bpt)
7082 warning ("attempted to disable apparently deleted breakpoint #%d?",
7087 case bp_catch_unload:
7089 case bp_catch_vfork:
7091 case bp_catch_catch:
7092 case bp_catch_throw:
7093 case bp_hardware_breakpoint:
7095 case bp_hardware_watchpoint:
7096 case bp_read_watchpoint:
7097 case bp_access_watchpoint:
7098 disable_breakpoint (bpt);
7103 map_breakpoint_numbers (args, disable_breakpoint);
7107 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7109 struct frame_info *save_selected_frame = NULL;
7110 int save_selected_frame_level = -1;
7111 int target_resources_ok, other_type_used;
7114 if (bpt->type == bp_hardware_breakpoint)
7117 i = hw_breakpoint_used_count ();
7118 target_resources_ok =
7119 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7121 if (target_resources_ok == 0)
7122 error ("No hardware breakpoint support in the target.");
7123 else if (target_resources_ok < 0)
7124 error ("Hardware breakpoints used exceeds limit.");
7127 if (bpt->enable_state != bp_permanent)
7128 bpt->enable_state = bp_enabled;
7129 bpt->disposition = disposition;
7130 check_duplicates (bpt);
7131 breakpoints_changed ();
7133 if (bpt->type == bp_watchpoint ||
7134 bpt->type == bp_hardware_watchpoint ||
7135 bpt->type == bp_read_watchpoint ||
7136 bpt->type == bp_access_watchpoint)
7138 if (bpt->exp_valid_block != NULL)
7140 struct frame_info *fr =
7142 /* Ensure that we have the current frame. Else, this
7143 next query may pessimistically be answered as, "No,
7144 not within current scope". */
7145 get_current_frame ();
7146 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7150 Cannot enable watchpoint %d because the block in which its expression\n\
7151 is valid is not currently in scope.\n", bpt->number);
7152 bpt->enable_state = bp_disabled;
7156 save_selected_frame = selected_frame;
7157 save_selected_frame_level = selected_frame_level;
7158 select_frame (fr, -1);
7161 value_free (bpt->val);
7162 mark = value_mark ();
7163 bpt->val = evaluate_expression (bpt->exp);
7164 release_value (bpt->val);
7165 if (VALUE_LAZY (bpt->val))
7166 value_fetch_lazy (bpt->val);
7168 if (bpt->type == bp_hardware_watchpoint ||
7169 bpt->type == bp_read_watchpoint ||
7170 bpt->type == bp_access_watchpoint)
7172 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7173 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7175 /* Hack around 'unused var' error for some targets here */
7177 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7178 bpt->type, i + mem_cnt, other_type_used);
7179 /* we can consider of type is bp_hardware_watchpoint, convert to
7180 bp_watchpoint in the following condition */
7181 if (target_resources_ok < 0)
7184 Cannot enable watchpoint %d because target watch resources\n\
7185 have been allocated for other watchpoints.\n", bpt->number);
7186 bpt->enable_state = bp_disabled;
7187 value_free_to_mark (mark);
7192 if (save_selected_frame_level >= 0)
7193 select_frame (save_selected_frame, save_selected_frame_level);
7194 value_free_to_mark (mark);
7196 if (modify_breakpoint_hook)
7197 modify_breakpoint_hook (bpt);
7198 breakpoint_modify_event (bpt->number);
7202 enable_breakpoint (struct breakpoint *bpt)
7204 do_enable_breakpoint (bpt, bpt->disposition);
7207 /* The enable command enables the specified breakpoints (or all defined
7208 breakpoints) so they once again become (or continue to be) effective
7209 in stopping the inferior. */
7213 enable_command (char *args, int from_tty)
7215 register struct breakpoint *bpt;
7217 ALL_BREAKPOINTS (bpt)
7221 warning ("attempted to enable apparently deleted breakpoint #%d?",
7226 case bp_catch_unload:
7228 case bp_catch_vfork:
7230 case bp_catch_catch:
7231 case bp_catch_throw:
7232 case bp_hardware_breakpoint:
7234 case bp_hardware_watchpoint:
7235 case bp_read_watchpoint:
7236 case bp_access_watchpoint:
7237 enable_breakpoint (bpt);
7242 map_breakpoint_numbers (args, enable_breakpoint);
7246 enable_once_breakpoint (struct breakpoint *bpt)
7248 do_enable_breakpoint (bpt, disp_disable);
7253 enable_once_command (char *args, int from_tty)
7255 map_breakpoint_numbers (args, enable_once_breakpoint);
7259 enable_delete_breakpoint (struct breakpoint *bpt)
7261 do_enable_breakpoint (bpt, disp_del);
7266 enable_delete_command (char *args, int from_tty)
7268 map_breakpoint_numbers (args, enable_delete_breakpoint);
7271 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7273 struct symtabs_and_lines
7274 decode_line_spec_1 (char *string, int funfirstline)
7276 struct symtabs_and_lines sals;
7278 error ("Empty line specification.");
7279 if (default_breakpoint_valid)
7280 sals = decode_line_1 (&string, funfirstline,
7281 default_breakpoint_symtab,
7282 default_breakpoint_line,
7285 sals = decode_line_1 (&string, funfirstline,
7286 (struct symtab *) NULL, 0, (char ***) NULL);
7288 error ("Junk at end of line specification: %s", string);
7293 _initialize_breakpoint (void)
7295 struct cmd_list_element *c;
7297 breakpoint_chain = 0;
7298 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7299 before a breakpoint is set. */
7300 breakpoint_count = 0;
7302 add_com ("ignore", class_breakpoint, ignore_command,
7303 "Set ignore-count of breakpoint number N to COUNT.\n\
7304 Usage is `ignore N COUNT'.");
7306 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7308 add_com ("commands", class_breakpoint, commands_command,
7309 "Set commands to be executed when a breakpoint is hit.\n\
7310 Give breakpoint number as argument after \"commands\".\n\
7311 With no argument, the targeted breakpoint is the last one set.\n\
7312 The commands themselves follow starting on the next line.\n\
7313 Type a line containing \"end\" to indicate the end of them.\n\
7314 Give \"silent\" as the first line to make the breakpoint silent;\n\
7315 then no output is printed when it is hit, except what the commands print.");
7317 add_com ("condition", class_breakpoint, condition_command,
7318 "Specify breakpoint number N to break only if COND is true.\n\
7319 Usage is `condition N COND', where N is an integer and COND is an\n\
7320 expression to be evaluated whenever breakpoint N is reached. ");
7322 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7323 "Set a temporary breakpoint. Args like \"break\" command.\n\
7324 Like \"break\" except the breakpoint is only temporary,\n\
7325 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7326 by using \"enable delete\" on the breakpoint number.");
7327 c->completer = location_completer;
7329 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7330 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7331 Like \"break\" except the breakpoint requires hardware support,\n\
7332 some target hardware may not have this support.");
7333 c->completer = location_completer;
7335 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7336 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7337 Like \"hbreak\" except the breakpoint is only temporary,\n\
7338 so it will be deleted when hit.");
7339 c->completer = location_completer;
7341 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7342 "Enable some breakpoints.\n\
7343 Give breakpoint numbers (separated by spaces) as arguments.\n\
7344 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7345 This is used to cancel the effect of the \"disable\" command.\n\
7346 With a subcommand you can enable temporarily.",
7347 &enablelist, "enable ", 1, &cmdlist);
7349 add_com ("ab", class_breakpoint, enable_command,
7350 "Enable some breakpoints.\n\
7351 Give breakpoint numbers (separated by spaces) as arguments.\n\
7352 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7353 This is used to cancel the effect of the \"disable\" command.\n\
7354 With a subcommand you can enable temporarily.");
7356 add_com_alias ("en", "enable", class_breakpoint, 1);
7358 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7359 "Enable some breakpoints.\n\
7360 Give breakpoint numbers (separated by spaces) as arguments.\n\
7361 This is used to cancel the effect of the \"disable\" command.\n\
7362 May be abbreviated to simply \"enable\".\n",
7363 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7365 add_cmd ("once", no_class, enable_once_command,
7366 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7367 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7370 add_cmd ("delete", no_class, enable_delete_command,
7371 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7372 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7375 add_cmd ("delete", no_class, enable_delete_command,
7376 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7377 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7380 add_cmd ("once", no_class, enable_once_command,
7381 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7382 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7385 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7386 "Disable some breakpoints.\n\
7387 Arguments are breakpoint numbers with spaces in between.\n\
7388 To disable all breakpoints, give no argument.\n\
7389 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7390 &disablelist, "disable ", 1, &cmdlist);
7391 add_com_alias ("dis", "disable", class_breakpoint, 1);
7392 add_com_alias ("disa", "disable", class_breakpoint, 1);
7394 add_com ("sb", class_breakpoint, disable_command,
7395 "Disable some breakpoints.\n\
7396 Arguments are breakpoint numbers with spaces in between.\n\
7397 To disable all breakpoints, give no argument.\n\
7398 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7400 add_cmd ("breakpoints", class_alias, disable_command,
7401 "Disable some breakpoints.\n\
7402 Arguments are breakpoint numbers with spaces in between.\n\
7403 To disable all breakpoints, give no argument.\n\
7404 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7405 This command may be abbreviated \"disable\".",
7408 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7409 "Delete some breakpoints or auto-display expressions.\n\
7410 Arguments are breakpoint numbers with spaces in between.\n\
7411 To delete all breakpoints, give no argument.\n\
7413 Also a prefix command for deletion of other GDB objects.\n\
7414 The \"unset\" command is also an alias for \"delete\".",
7415 &deletelist, "delete ", 1, &cmdlist);
7416 add_com_alias ("d", "delete", class_breakpoint, 1);
7418 add_com ("db", class_breakpoint, delete_command,
7419 "Delete some breakpoints.\n\
7420 Arguments are breakpoint numbers with spaces in between.\n\
7421 To delete all breakpoints, give no argument.\n");
7423 add_cmd ("breakpoints", class_alias, delete_command,
7424 "Delete some breakpoints or auto-display expressions.\n\
7425 Arguments are breakpoint numbers with spaces in between.\n\
7426 To delete all breakpoints, give no argument.\n\
7427 This command may be abbreviated \"delete\".",
7430 add_com ("clear", class_breakpoint, clear_command,
7431 concat ("Clear breakpoint at specified line or function.\n\
7432 Argument may be line number, function name, or \"*\" and an address.\n\
7433 If line number is specified, all breakpoints in that line are cleared.\n\
7434 If function is specified, breakpoints at beginning of function are cleared.\n\
7435 If an address is specified, breakpoints at that address are cleared.\n\n",
7436 "With no argument, clears all breakpoints in the line that the selected frame\n\
7439 See also the \"delete\" command which clears breakpoints by number.", NULL));
7441 c = add_com ("break", class_breakpoint, break_command,
7442 concat ("Set breakpoint at specified line or function.\n\
7443 Argument may be line number, function name, or \"*\" and an address.\n\
7444 If line number is specified, break at start of code for that line.\n\
7445 If function is specified, break at start of code for that function.\n\
7446 If an address is specified, break at that exact address.\n",
7447 "With no arg, uses current execution address of selected stack frame.\n\
7448 This is useful for breaking on return to a stack frame.\n\
7450 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7452 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7453 c->completer = location_completer;
7455 add_com_alias ("b", "break", class_run, 1);
7456 add_com_alias ("br", "break", class_run, 1);
7457 add_com_alias ("bre", "break", class_run, 1);
7458 add_com_alias ("brea", "break", class_run, 1);
7462 add_com_alias ("ba", "break", class_breakpoint, 1);
7463 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7468 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7469 "Break in function/address or break at a line in the current file.",
7470 &stoplist, "stop ", 1, &cmdlist);
7471 add_cmd ("in", class_breakpoint, stopin_command,
7472 "Break in function or address.\n", &stoplist);
7473 add_cmd ("at", class_breakpoint, stopat_command,
7474 "Break at a line in the current file.\n", &stoplist);
7475 add_com ("status", class_info, breakpoints_info,
7476 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7477 The \"Type\" column indicates one of:\n\
7478 \tbreakpoint - normal breakpoint\n\
7479 \twatchpoint - watchpoint\n\
7480 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7481 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7482 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7483 address and file/line number respectively.\n\n",
7484 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7485 are set to the address of the last breakpoint listed.\n\n\
7486 Convenience variable \"$bpnum\" contains the number of the last\n\
7487 breakpoint set.", NULL));
7490 add_info ("breakpoints", breakpoints_info,
7491 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7492 The \"Type\" column indicates one of:\n\
7493 \tbreakpoint - normal breakpoint\n\
7494 \twatchpoint - watchpoint\n\
7495 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7496 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7497 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7498 address and file/line number respectively.\n\n",
7499 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7500 are set to the address of the last breakpoint listed.\n\n\
7501 Convenience variable \"$bpnum\" contains the number of the last\n\
7502 breakpoint set.", NULL));
7505 add_com ("lb", class_breakpoint, breakpoints_info,
7506 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7507 The \"Type\" column indicates one of:\n\
7508 \tbreakpoint - normal breakpoint\n\
7509 \twatchpoint - watchpoint\n\
7510 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7511 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7512 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7513 address and file/line number respectively.\n\n",
7514 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7515 are set to the address of the last breakpoint listed.\n\n\
7516 Convenience variable \"$bpnum\" contains the number of the last\n\
7517 breakpoint set.", NULL));
7519 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7520 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7521 The \"Type\" column indicates one of:\n\
7522 \tbreakpoint - normal breakpoint\n\
7523 \twatchpoint - watchpoint\n\
7524 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7525 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7526 \tuntil - internal breakpoint used by the \"until\" command\n\
7527 \tfinish - internal breakpoint used by the \"finish\" command\n",
7528 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7529 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7530 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7531 address and file/line number respectively.\n\n",
7532 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7533 are set to the address of the last breakpoint listed.\n\n\
7534 Convenience variable \"$bpnum\" contains the number of the last\n\
7535 breakpoint set.", NULL),
7536 &maintenanceinfolist);
7538 add_com ("catch", class_breakpoint, catch_command,
7539 "Set catchpoints to catch events.\n\
7540 Raised signals may be caught:\n\
7541 \tcatch signal - all signals\n\
7542 \tcatch signal <signame> - a particular signal\n\
7543 Raised exceptions may be caught:\n\
7544 \tcatch throw - all exceptions, when thrown\n\
7545 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7546 \tcatch catch - all exceptions, when caught\n\
7547 \tcatch catch <exceptname> - a particular exception, when caught\n\
7548 Thread or process events may be caught:\n\
7549 \tcatch thread_start - any threads, just after creation\n\
7550 \tcatch thread_exit - any threads, just before expiration\n\
7551 \tcatch thread_join - any threads, just after joins\n\
7552 Process events may be caught:\n\
7553 \tcatch start - any processes, just after creation\n\
7554 \tcatch exit - any processes, just before expiration\n\
7555 \tcatch fork - calls to fork()\n\
7556 \tcatch vfork - calls to vfork()\n\
7557 \tcatch exec - calls to exec()\n\
7558 Dynamically-linked library events may be caught:\n\
7559 \tcatch load - loads of any library\n\
7560 \tcatch load <libname> - loads of a particular library\n\
7561 \tcatch unload - unloads of any library\n\
7562 \tcatch unload <libname> - unloads of a particular library\n\
7563 The act of your program's execution stopping may also be caught:\n\
7565 C++ exceptions may be caught:\n\
7566 \tcatch throw - all exceptions, when thrown\n\
7567 \tcatch catch - all exceptions, when caught\n\
7569 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7570 after a fork or vfork is caught.\n\n\
7571 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7573 add_com ("tcatch", class_breakpoint, tcatch_command,
7574 "Set temporary catchpoints to catch events.\n\
7575 Args like \"catch\" command.\n\
7576 Like \"catch\" except the catchpoint is only temporary,\n\
7577 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7578 by using \"enable delete\" on the catchpoint number.");
7580 c = add_com ("watch", class_breakpoint, watch_command,
7581 "Set a watchpoint for an expression.\n\
7582 A watchpoint stops execution of your program whenever the value of\n\
7583 an expression changes.");
7584 c->completer = location_completer;
7586 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7587 "Set a read watchpoint for an expression.\n\
7588 A watchpoint stops execution of your program whenever the value of\n\
7589 an expression is read.");
7590 c->completer = location_completer;
7592 c = add_com ("awatch", class_breakpoint, awatch_command,
7593 "Set a watchpoint for an expression.\n\
7594 A watchpoint stops execution of your program whenever the value of\n\
7595 an expression is either read or written.");
7596 c->completer = location_completer;
7598 add_info ("watchpoints", breakpoints_info,
7599 "Synonym for ``info breakpoints''.");
7602 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7603 (char *) &can_use_hw_watchpoints,
7604 "Set debugger's willingness to use watchpoint hardware.\n\
7605 If zero, gdb will not use hardware for new watchpoints, even if\n\
7606 such is available. (However, any hardware watchpoints that were\n\
7607 created before setting this to nonzero, will continue to use watchpoint\n\
7610 add_show_from_set (c, &showlist);
7612 can_use_hw_watchpoints = 1;