1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999,
3 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "breakpoint.h"
28 #include "expression.h"
34 #include "gdbthread.h"
37 #include "gdb_string.h"
47 #include "gdb-events.h"
49 /* Prototypes for local functions. */
51 static void until_break_command_continuation (struct continuation_arg *arg);
53 static void catch_command_1 (char *, int, int);
55 static void enable_delete_command (char *, int);
57 static void enable_delete_breakpoint (struct breakpoint *);
59 static void enable_once_command (char *, int);
61 static void enable_once_breakpoint (struct breakpoint *);
63 static void disable_command (char *, int);
65 static void enable_command (char *, int);
67 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
69 static void ignore_command (char *, int);
71 static int breakpoint_re_set_one (PTR);
73 static void clear_command (char *, int);
75 static void catch_command (char *, int);
77 static void handle_gnu_4_16_catch_command (char *, int, int);
79 static struct symtabs_and_lines get_catch_sals (int);
81 static void watch_command (char *, int);
83 static int can_use_hardware_watchpoint (struct value *);
85 static void break_at_finish_command (char *, int);
86 static void break_at_finish_at_depth_command (char *, int);
88 void tbreak_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);
98 static void check_duplicates (CORE_ADDR, asection *);
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 static void awatch_command (char *, int);
215 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
217 /* If FALSE, gdb will not use hardware support for watchpoints, even
218 if such is available. */
219 static int can_use_hw_watchpoints;
221 void _initialize_breakpoint (void);
223 void set_breakpoint_count (int);
225 extern int addressprint; /* Print machine addresses? */
227 static int internal_breakpoint_number = -1;
229 /* Are we executing breakpoint commands? */
230 static int executing_breakpoint_commands;
232 /* Walk the following statement or block through all breakpoints.
233 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
236 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
238 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
239 for (B = breakpoint_chain; \
240 B ? (TMP=B->next, 1): 0; \
243 /* True if SHIFT_INST_REGS defined, false otherwise. */
245 int must_shift_inst_regs =
246 #if defined(SHIFT_INST_REGS)
253 /* True if breakpoint hit counts should be displayed in breakpoint info. */
255 int show_breakpoint_hit_counts = 1;
257 /* Chain of all breakpoints defined. */
259 struct breakpoint *breakpoint_chain;
261 /* Number of last breakpoint made. */
263 int breakpoint_count;
265 /* Pointer to current exception event record */
266 static struct exception_event_record *current_exception_event;
268 /* Indicator of whether exception catchpoints should be nuked
269 between runs of a program */
270 int exception_catchpoints_are_fragile = 0;
272 /* Indicator of when exception catchpoints set-up should be
273 reinitialized -- e.g. when program is re-run */
274 int exception_support_initialized = 0;
276 /* This function returns a pointer to the string representation of the
277 pathname of the dynamically-linked library that has just been
280 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
281 or undefined results are guaranteed.
283 This string's contents are only valid immediately after the
284 inferior has stopped in the dynamic linker hook, and becomes
285 invalid as soon as the inferior is continued. Clients should make
286 a copy of this string if they wish to continue the inferior and
287 then access the string. */
289 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
290 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
293 /* This function returns a pointer to the string representation of the
294 pathname of the dynamically-linked library that has just been
297 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
298 TRUE, or undefined results are guaranteed.
300 This string's contents are only valid immediately after the
301 inferior has stopped in the dynamic linker hook, and becomes
302 invalid as soon as the inferior is continued. Clients should make
303 a copy of this string if they wish to continue the inferior and
304 then access the string. */
306 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
307 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
310 /* This function is called by the "catch load" command. It allows the
311 debugger to be notified by the dynamic linker when a specified
312 library file (or any library file, if filename is NULL) is loaded. */
314 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
315 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
316 error ("catch of library loads not yet implemented on this platform")
319 /* This function is called by the "catch unload" command. It allows
320 the debugger to be notified by the dynamic linker when a specified
321 library file (or any library file, if filename is NULL) is
324 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
325 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
326 error ("catch of library unloads not yet implemented on this platform")
329 /* Set breakpoint count to NUM. */
332 set_breakpoint_count (int num)
334 breakpoint_count = num;
335 set_internalvar (lookup_internalvar ("bpnum"),
336 value_from_longest (builtin_type_int, (LONGEST) num));
339 /* Used in run_command to zero the hit count when a new run starts. */
342 clear_breakpoint_hit_counts (void)
344 struct breakpoint *b;
350 /* Default address, symtab and line to put a breakpoint at
351 for "break" command with no arg.
352 if default_breakpoint_valid is zero, the other three are
353 not valid, and "break" with no arg is an error.
355 This set by print_stack_frame, which calls set_default_breakpoint. */
357 int default_breakpoint_valid;
358 CORE_ADDR default_breakpoint_address;
359 struct symtab *default_breakpoint_symtab;
360 int default_breakpoint_line;
362 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
363 Advance *PP after the string and any trailing whitespace.
365 Currently the string can either be a number or "$" followed by the name
366 of a convenience variable. Making it an expression wouldn't work well
367 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
369 TRAILER is a character which can be found after the number; most
370 commonly this is `-'. If you don't want a trailer, use \0. */
372 get_number_trailer (char **pp, int trailer)
374 int retval = 0; /* default */
378 /* Empty line means refer to the last breakpoint. */
379 return breakpoint_count;
382 /* Make a copy of the name, so we can null-terminate it
383 to pass to lookup_internalvar(). */
388 while (isalnum (*p) || *p == '_')
390 varname = (char *) alloca (p - start + 1);
391 strncpy (varname, start, p - start);
392 varname[p - start] = '\0';
393 val = value_of_internalvar (lookup_internalvar (varname));
394 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
395 retval = (int) value_as_long (val);
398 printf_filtered ("Convenience variable must have integer value.\n");
406 while (*p >= '0' && *p <= '9')
409 /* There is no number here. (e.g. "cond a == b"). */
411 /* Skip non-numeric token */
412 while (*p && !isspace((int) *p))
414 /* Return zero, which caller must interpret as error. */
420 if (!(isspace (*p) || *p == '\0' || *p == trailer))
422 /* Trailing junk: return 0 and let caller print error msg. */
423 while (!(isspace (*p) || *p == '\0' || *p == trailer))
434 /* Like get_number_trailer, but don't allow a trailer. */
436 get_number (char **pp)
438 return get_number_trailer (pp, '\0');
441 /* Parse a number or a range.
442 * A number will be of the form handled by get_number.
443 * A range will be of the form <number1> - <number2>, and
444 * will represent all the integers between number1 and number2,
447 * While processing a range, this fuction is called iteratively;
448 * At each call it will return the next value in the range.
450 * At the beginning of parsing a range, the char pointer PP will
451 * be advanced past <number1> and left pointing at the '-' token.
452 * Subsequent calls will not advance the pointer until the range
453 * is completed. The call that completes the range will advance
454 * pointer PP past <number2>.
458 get_number_or_range (char **pp)
460 static int last_retval, end_value;
461 static char *end_ptr;
462 static int in_range = 0;
466 /* Default case: pp is pointing either to a solo number,
467 or to the first number of a range. */
468 last_retval = get_number_trailer (pp, '-');
473 /* This is the start of a range (<number1> - <number2>).
474 Skip the '-', parse and remember the second number,
475 and also remember the end of the final token. */
479 while (isspace ((int) *end_ptr))
480 end_ptr++; /* skip white space */
481 end_value = get_number (temp);
482 if (end_value < last_retval)
484 error ("inverted range");
486 else if (end_value == last_retval)
488 /* degenerate range (number1 == number2). Advance the
489 token pointer so that the range will be treated as a
498 error ("negative value");
501 /* pp points to the '-' that betokens a range. All
502 number-parsing has already been done. Return the next
503 integer value (one greater than the saved previous value).
504 Do not advance the token pointer 'pp' until the end of range
507 if (++last_retval == end_value)
509 /* End of range reached; advance token pointer. */
519 /* condition N EXP -- set break condition of breakpoint N to EXP. */
522 condition_command (char *arg, int from_tty)
524 register struct breakpoint *b;
529 error_no_arg ("breakpoint number");
532 bnum = get_number (&p);
534 error ("Bad breakpoint argument: '%s'", arg);
537 if (b->number == bnum)
544 if (b->cond_string != NULL)
545 xfree (b->cond_string);
550 b->cond_string = NULL;
552 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
557 /* I don't know if it matters whether this is the string the user
558 typed in or the decompiled expression. */
559 b->cond_string = savestring (arg, strlen (arg));
560 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
562 error ("Junk at end of expression");
564 breakpoints_changed ();
568 error ("No breakpoint number %d.", bnum);
573 commands_command (char *arg, int from_tty)
575 register struct breakpoint *b;
578 struct command_line *l;
580 /* If we allowed this, we would have problems with when to
581 free the storage, if we change the commands currently
584 if (executing_breakpoint_commands)
585 error ("Can't use the \"commands\" command among a breakpoint's commands.");
588 bnum = get_number (&p);
591 error ("Unexpected extra arguments following breakpoint number.");
594 if (b->number == bnum)
598 "Type commands for when breakpoint %d is hit, one per line.",
600 l = read_command_lines (tmpbuf, from_tty);
601 free_command_lines (&b->commands);
603 breakpoints_changed ();
606 error ("No breakpoint number %d.", bnum);
609 /* Like target_read_memory() but if breakpoints are inserted, return
610 the shadow contents instead of the breakpoints themselves.
612 Read "memory data" from whatever target or inferior we have.
613 Returns zero if successful, errno value if not. EIO is used
614 for address out of bounds. If breakpoints are inserted, returns
615 shadow contents, not the breakpoints themselves. From breakpoint.c. */
618 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
621 struct breakpoint *b;
622 CORE_ADDR bp_addr = 0;
625 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
626 /* No breakpoints on this machine. */
627 return target_read_memory (memaddr, myaddr, len);
631 if (b->type == bp_none)
632 warning ("reading through apparently deleted breakpoint #%d?",
635 /* memory breakpoint? */
636 if (b->type == bp_watchpoint
637 || b->type == bp_hardware_watchpoint
638 || b->type == bp_read_watchpoint
639 || b->type == bp_access_watchpoint)
644 /* Addresses and length of the part of the breakpoint that
646 /* XXXX The m68k, sh and h8300 have different local and remote
647 breakpoint values. BREAKPOINT_FROM_PC still manages to
648 correctly determine the breakpoints memory address and size
649 for these targets. */
650 bp_addr = b->address;
652 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
657 if (bp_addr + bp_size <= memaddr)
658 /* The breakpoint is entirely before the chunk of memory we
661 if (bp_addr >= memaddr + len)
662 /* The breakpoint is entirely after the chunk of memory we are
665 /* Copy the breakpoint from the shadow contents, and recurse for
666 the things before and after. */
668 /* Offset within shadow_contents. */
671 if (bp_addr < memaddr)
673 /* Only copy the second part of the breakpoint. */
674 bp_size -= memaddr - bp_addr;
675 bptoffset = memaddr - bp_addr;
679 if (bp_addr + bp_size > memaddr + len)
681 /* Only copy the first part of the breakpoint. */
682 bp_size -= (bp_addr + bp_size) - (memaddr + len);
685 memcpy (myaddr + bp_addr - memaddr,
686 b->shadow_contents + bptoffset, bp_size);
688 if (bp_addr > memaddr)
690 /* Copy the section of memory before the breakpoint. */
691 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
696 if (bp_addr + bp_size < memaddr + len)
698 /* Copy the section of memory after the breakpoint. */
699 status = read_memory_nobpt (bp_addr + bp_size,
700 myaddr + bp_addr + bp_size - memaddr,
701 memaddr + len - (bp_addr + bp_size));
708 /* Nothing overlaps. Just call read_memory_noerr. */
709 return target_read_memory (memaddr, myaddr, len);
713 /* insert_breakpoints is used when starting or continuing the program.
714 remove_breakpoints is used when the program stops.
715 Both return zero if successful,
716 or an `errno' value if could not write the inferior. */
719 insert_breakpoints (void)
721 register struct breakpoint *b, *temp;
722 int return_val = 0; /* return success code. */
724 int disabled_breaks = 0;
726 static char message1[] = "Error inserting catchpoint %d:\n";
727 static char message[sizeof (message1) + 30];
730 ALL_BREAKPOINTS_SAFE (b, temp)
732 if (b->enable == permanent)
733 /* Permanent breakpoints cannot be inserted or removed. */
735 else if (b->type != bp_watchpoint
736 && b->type != bp_hardware_watchpoint
737 && b->type != bp_read_watchpoint
738 && b->type != bp_access_watchpoint
739 && b->type != bp_catch_fork
740 && b->type != bp_catch_vfork
741 && b->type != bp_catch_exec
742 && b->type != bp_catch_throw
743 && b->type != bp_catch_catch
744 && b->enable != disabled
745 && b->enable != shlib_disabled
746 && b->enable != call_disabled
750 if (b->type == bp_hardware_breakpoint)
751 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
754 /* Check to see if breakpoint is in an overlay section;
755 if so, we should set the breakpoint at the LMA address.
756 Only if the section is currently mapped should we ALSO
757 set a break at the VMA address. */
758 if (overlay_debugging && b->section &&
759 section_is_overlay (b->section))
763 addr = overlay_unmapped_address (b->address, b->section);
764 val = target_insert_breakpoint (addr, b->shadow_contents);
765 /* This would be the time to check val, to see if the
766 breakpoint write to the load address succeeded.
767 However, this might be an ordinary occurrance, eg. if
768 the unmapped overlay is in ROM. */
769 val = 0; /* in case unmapped address failed */
770 if (section_is_mapped (b->section))
771 val = target_insert_breakpoint (b->address,
774 else /* ordinary (non-overlay) address */
775 val = target_insert_breakpoint (b->address, b->shadow_contents);
779 /* Can't set the breakpoint. */
780 #if defined (DISABLE_UNSETTABLE_BREAK)
781 if (DISABLE_UNSETTABLE_BREAK (b->address))
783 /* See also: disable_breakpoints_in_shlibs. */
785 b->enable = shlib_disabled;
786 if (!disabled_breaks)
788 target_terminal_ours_for_output ();
789 warning ("Cannot insert breakpoint %d:", b->number);
790 warning ("Temporarily disabling shared library breakpoints:");
793 warning ("breakpoint #%d ", b->number);
798 target_terminal_ours_for_output ();
799 warning ("Cannot insert breakpoint %d:", b->number);
800 #ifdef ONE_PROCESS_WRITETEXT
801 warning ("The same program may be running in another process.");
803 memory_error (val, b->address); /* which bombs us out */
810 return_val = val; /* remember failure */
812 else if (ep_is_exception_catchpoint (b)
813 && b->enable != disabled
814 && b->enable != shlib_disabled
815 && b->enable != call_disabled
820 /* If we get here, we must have a callback mechanism for exception
821 events -- with g++ style embedded label support, we insert
822 ordinary breakpoints and not catchpoints. */
823 /* Format possible error message */
824 sprintf (message, message1, b->number);
826 val = target_insert_breakpoint (b->address, b->shadow_contents);
829 /* Couldn't set breakpoint for some reason */
830 target_terminal_ours_for_output ();
831 warning ("Cannot insert catchpoint %d; disabling it.",
833 b->enable = disabled;
837 /* Bp set, now make sure callbacks are enabled */
839 args_for_catchpoint_enable args;
840 args.kind = b->type == bp_catch_catch ?
841 EX_EVENT_CATCH : EX_EVENT_THROW;
843 val = catch_errors (cover_target_enable_exception_callback,
845 message, RETURN_MASK_ALL);
846 if (val != 0 && val != -1)
850 /* Check if something went wrong; val == 0 can be ignored */
853 /* something went wrong */
854 target_terminal_ours_for_output ();
855 warning ("Cannot insert catchpoint %d; disabling it.",
857 b->enable = disabled;
862 return_val = val; /* remember failure */
865 else if ((b->type == bp_hardware_watchpoint ||
866 b->type == bp_read_watchpoint ||
867 b->type == bp_access_watchpoint)
868 && b->enable == enabled
869 && b->disposition != del_at_next_stop
873 struct frame_info *saved_frame;
874 int saved_level, within_current_scope;
875 value_ptr mark = value_mark ();
878 /* Save the current frame and level so we can restore it after
879 evaluating the watchpoint expression on its own frame. */
880 saved_frame = selected_frame;
881 saved_level = selected_frame_level;
883 /* Determine if the watchpoint is within scope. */
884 if (b->exp_valid_block == NULL)
885 within_current_scope = 1;
888 struct frame_info *fi;
890 /* There might be no current frame at this moment if we are
891 resuming from a step over a breakpoint.
892 Set up current frame before trying to find the watchpoint
894 get_current_frame ();
895 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
896 within_current_scope = (fi != NULL);
897 if (within_current_scope)
898 select_frame (fi, -1);
901 if (within_current_scope)
903 /* Evaluate the expression and cut the chain of values
904 produced off from the value chain.
906 Make sure the value returned isn't lazy; we use
907 laziness to determine what memory GDB actually needed
908 in order to compute the value of the expression. */
909 v = evaluate_expression (b->exp);
911 value_release_to_mark (mark);
916 /* Look at each value on the value chain. */
917 for (; v; v = v->next)
919 /* If it's a memory location, and GDB actually needed
920 its contents to evaluate the expression, then we
922 if (VALUE_LVAL (v) == lval_memory
925 struct type *vtype = check_typedef (VALUE_TYPE (v));
927 /* We only watch structs and arrays if user asked
928 for it explicitly, never if they just happen to
929 appear in the middle of some value chain. */
930 if (v == b->val_chain
931 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
932 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
937 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
938 len = TYPE_LENGTH (VALUE_TYPE (v));
940 if (b->type == bp_read_watchpoint)
942 else if (b->type == bp_access_watchpoint)
945 val = target_insert_watchpoint (addr, len, type);
948 /* Don't exit the loop, try to insert
949 every value on the value chain. That's
950 because we will be removing all the
951 watches below, and removing a
952 watchpoint we didn't insert could have
960 /* Failure to insert a watchpoint on any memory value in the
961 value chain brings us here. */
964 remove_breakpoint (b, mark_uninserted);
965 warning ("Could not insert hardware watchpoint %d.",
972 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
973 printf_filtered ("because the program has left the block \n");
974 printf_filtered ("in which its expression is valid.\n");
975 if (b->related_breakpoint)
976 b->related_breakpoint->disposition = del_at_next_stop;
977 b->disposition = del_at_next_stop;
980 /* Restore the frame and level. */
981 if ((saved_frame != selected_frame) ||
982 (saved_level != selected_frame_level))
983 select_frame (saved_frame, saved_level);
986 return_val = val; /* remember failure */
988 else if ((b->type == bp_catch_fork
989 || b->type == bp_catch_vfork
990 || b->type == bp_catch_exec)
991 && b->enable == enabled
999 val = target_insert_fork_catchpoint (inferior_pid);
1001 case bp_catch_vfork:
1002 val = target_insert_vfork_catchpoint (inferior_pid);
1005 val = target_insert_exec_catchpoint (inferior_pid);
1008 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1013 target_terminal_ours_for_output ();
1014 warning ("Cannot insert catchpoint %d.", b->number);
1020 return_val = val; /* remember failure */
1029 remove_breakpoints (void)
1031 register struct breakpoint *b;
1038 val = remove_breakpoint (b, mark_uninserted);
1047 remove_hw_watchpoints (void)
1049 register struct breakpoint *b;
1055 && (b->type == bp_hardware_watchpoint
1056 || b->type == bp_read_watchpoint
1057 || b->type == bp_access_watchpoint))
1059 val = remove_breakpoint (b, mark_uninserted);
1068 reattach_breakpoints (int pid)
1070 register struct breakpoint *b;
1072 int saved_inferior_pid = inferior_pid;
1074 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1075 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1080 remove_breakpoint (b, mark_inserted);
1081 if (b->type == bp_hardware_breakpoint)
1082 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1084 val = target_insert_breakpoint (b->address, b->shadow_contents);
1087 inferior_pid = saved_inferior_pid;
1092 inferior_pid = saved_inferior_pid;
1097 update_breakpoints_after_exec (void)
1099 struct breakpoint *b;
1100 struct breakpoint *temp;
1102 /* Doing this first prevents the badness of having delete_breakpoint()
1103 write a breakpoint's current "shadow contents" to lift the bp. That
1104 shadow is NOT valid after an exec()! */
1105 mark_breakpoints_out ();
1107 ALL_BREAKPOINTS_SAFE (b, temp)
1109 /* Solib breakpoints must be explicitly reset after an exec(). */
1110 if (b->type == bp_shlib_event)
1112 delete_breakpoint (b);
1116 /* Thread event breakpoints must be set anew after an exec(). */
1117 if (b->type == bp_thread_event)
1119 delete_breakpoint (b);
1123 /* Step-resume breakpoints are meaningless after an exec(). */
1124 if (b->type == bp_step_resume)
1126 delete_breakpoint (b);
1130 /* Ditto the sigtramp handler breakpoints. */
1131 if (b->type == bp_through_sigtramp)
1133 delete_breakpoint (b);
1137 /* Ditto the exception-handling catchpoints. */
1138 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1140 delete_breakpoint (b);
1144 /* Don't delete an exec catchpoint, because else the inferior
1145 won't stop when it ought!
1147 Similarly, we probably ought to keep vfork catchpoints, 'cause
1148 on this target, we may not be able to stop when the vfork is
1149 seen, but only when the subsequent exec is seen. (And because
1150 deleting fork catchpoints here but not vfork catchpoints will
1151 seem mysterious to users, keep those too.)
1153 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1154 target address field, if any, is sufficient to have it be reset
1155 automagically. Certainly on HP-UX that's true. */
1156 if ((b->type == bp_catch_exec) ||
1157 (b->type == bp_catch_vfork) ||
1158 (b->type == bp_catch_fork))
1160 b->address = (CORE_ADDR) NULL;
1164 /* bp_finish is a special case. The only way we ought to be able
1165 to see one of these when an exec() has happened, is if the user
1166 caught a vfork, and then said "finish". Ordinarily a finish just
1167 carries them to the call-site of the current callee, by setting
1168 a temporary bp there and resuming. But in this case, the finish
1169 will carry them entirely through the vfork & exec.
1171 We don't want to allow a bp_finish to remain inserted now. But
1172 we can't safely delete it, 'cause finish_command has a handle to
1173 the bp on a bpstat, and will later want to delete it. There's a
1174 chance (and I've seen it happen) that if we delete the bp_finish
1175 here, that its storage will get reused by the time finish_command
1176 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1177 We really must allow finish_command to delete a bp_finish.
1179 In the absense of a general solution for the "how do we know
1180 it's safe to delete something others may have handles to?"
1181 problem, what we'll do here is just uninsert the bp_finish, and
1182 let finish_command delete it.
1184 (We know the bp_finish is "doomed" in the sense that it's
1185 momentary, and will be deleted as soon as finish_command sees
1186 the inferior stopped. So it doesn't matter that the bp's
1187 address is probably bogus in the new a.out, unlike e.g., the
1188 solib breakpoints.) */
1190 if (b->type == bp_finish)
1195 /* Without a symbolic address, we have little hope of the
1196 pre-exec() address meaning the same thing in the post-exec()
1198 if (b->addr_string == NULL)
1200 delete_breakpoint (b);
1204 /* If this breakpoint has survived the above battery of checks, then
1205 it must have a symbolic address. Be sure that it gets reevaluated
1206 to a target address, rather than reusing the old evaluation. */
1207 b->address = (CORE_ADDR) NULL;
1212 detach_breakpoints (int pid)
1214 register struct breakpoint *b;
1216 int saved_inferior_pid = inferior_pid;
1218 if (pid == inferior_pid)
1219 error ("Cannot detach breakpoints of inferior_pid");
1221 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1222 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1227 val = remove_breakpoint (b, mark_inserted);
1230 inferior_pid = saved_inferior_pid;
1235 inferior_pid = saved_inferior_pid;
1240 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1244 if (b->enable == permanent)
1245 /* Permanent breakpoints cannot be inserted or removed. */
1248 if (b->type == bp_none)
1249 warning ("attempted to remove apparently deleted breakpoint #%d?",
1252 if (b->type != bp_watchpoint
1253 && b->type != bp_hardware_watchpoint
1254 && b->type != bp_read_watchpoint
1255 && b->type != bp_access_watchpoint
1256 && b->type != bp_catch_fork
1257 && b->type != bp_catch_vfork
1258 && b->type != bp_catch_exec
1259 && b->type != bp_catch_catch
1260 && b->type != bp_catch_throw)
1262 if (b->type == bp_hardware_breakpoint)
1263 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1266 /* Check to see if breakpoint is in an overlay section;
1267 if so, we should remove the breakpoint at the LMA address.
1268 If that is not equal to the raw address, then we should
1269 presumably remove the breakpoint there as well. */
1270 if (overlay_debugging && b->section &&
1271 section_is_overlay (b->section))
1275 addr = overlay_unmapped_address (b->address, b->section);
1276 val = target_remove_breakpoint (addr, b->shadow_contents);
1277 /* This would be the time to check val, to see if the
1278 shadow breakpoint write to the load address succeeded.
1279 However, this might be an ordinary occurrance, eg. if
1280 the unmapped overlay is in ROM. */
1281 val = 0; /* in case unmapped address failed */
1282 if (section_is_mapped (b->section))
1283 val = target_remove_breakpoint (b->address,
1284 b->shadow_contents);
1286 else /* ordinary (non-overlay) address */
1287 val = target_remove_breakpoint (b->address, b->shadow_contents);
1291 b->inserted = (is == mark_inserted);
1293 else if ((b->type == bp_hardware_watchpoint ||
1294 b->type == bp_read_watchpoint ||
1295 b->type == bp_access_watchpoint)
1296 && b->enable == enabled
1301 b->inserted = (is == mark_inserted);
1302 /* Walk down the saved value chain. */
1303 for (v = b->val_chain; v; v = v->next)
1305 /* For each memory reference remove the watchpoint
1307 if (VALUE_LVAL (v) == lval_memory
1308 && ! VALUE_LAZY (v))
1310 struct type *vtype = check_typedef (VALUE_TYPE (v));
1312 if (v == b->val_chain
1313 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1314 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1319 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1320 len = TYPE_LENGTH (VALUE_TYPE (v));
1322 if (b->type == bp_read_watchpoint)
1324 else if (b->type == bp_access_watchpoint)
1327 val = target_remove_watchpoint (addr, len, type);
1334 /* Failure to remove any of the hardware watchpoints comes here. */
1335 if ((is == mark_uninserted) && (b->inserted))
1336 warning ("Could not remove hardware watchpoint %d.",
1339 /* Free the saved value chain. We will construct a new one
1340 the next time the watchpoint is inserted. */
1341 for (v = b->val_chain; v; v = n)
1346 b->val_chain = NULL;
1348 else if ((b->type == bp_catch_fork ||
1349 b->type == bp_catch_vfork ||
1350 b->type == bp_catch_exec)
1351 && b->enable == enabled
1358 val = target_remove_fork_catchpoint (inferior_pid);
1360 case bp_catch_vfork:
1361 val = target_remove_vfork_catchpoint (inferior_pid);
1364 val = target_remove_exec_catchpoint (inferior_pid);
1367 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1372 b->inserted = (is == mark_inserted);
1374 else if ((b->type == bp_catch_catch ||
1375 b->type == bp_catch_throw)
1376 && b->enable == enabled
1380 val = target_remove_breakpoint (b->address, b->shadow_contents);
1383 b->inserted = (is == mark_inserted);
1385 else if (ep_is_exception_catchpoint (b)
1386 && b->inserted /* sometimes previous insert doesn't happen */
1387 && b->enable == enabled
1391 val = target_remove_breakpoint (b->address, b->shadow_contents);
1395 b->inserted = (is == mark_inserted);
1401 /* Clear the "inserted" flag in all breakpoints. */
1404 mark_breakpoints_out (void)
1406 register struct breakpoint *b;
1412 /* Clear the "inserted" flag in all breakpoints and delete any
1413 breakpoints which should go away between runs of the program.
1415 Plus other such housekeeping that has to be done for breakpoints
1418 Note: this function gets called at the end of a run (by
1419 generic_mourn_inferior) and when a run begins (by
1420 init_wait_for_inferior). */
1425 breakpoint_init_inferior (enum inf_context context)
1427 register struct breakpoint *b, *temp;
1428 static int warning_needed = 0;
1430 ALL_BREAKPOINTS_SAFE (b, temp)
1437 case bp_watchpoint_scope:
1439 /* If the call dummy breakpoint is at the entry point it will
1440 cause problems when the inferior is rerun, so we better
1443 Also get rid of scope breakpoints. */
1444 delete_breakpoint (b);
1448 case bp_hardware_watchpoint:
1449 case bp_read_watchpoint:
1450 case bp_access_watchpoint:
1452 /* Likewise for watchpoints on local expressions. */
1453 if (b->exp_valid_block != NULL)
1454 delete_breakpoint (b);
1457 /* Likewise for exception catchpoints in dynamic-linked
1458 executables where required */
1459 if (ep_is_exception_catchpoint (b) &&
1460 exception_catchpoints_are_fragile)
1463 delete_breakpoint (b);
1469 if (exception_catchpoints_are_fragile)
1470 exception_support_initialized = 0;
1472 /* Don't issue the warning unless it's really needed... */
1473 if (warning_needed && (context != inf_exited))
1475 warning ("Exception catchpoints from last run were deleted.");
1476 warning ("You must reinsert them explicitly.");
1481 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1482 exists at PC. It returns ordinary_breakpoint_here if it's an
1483 ordinary breakpoint, or permanent_breakpoint_here if it's a
1484 permanent breakpoint.
1485 - When continuing from a location with an ordinary breakpoint, we
1486 actually single step once before calling insert_breakpoints.
1487 - When continuing from a localion with a permanent breakpoint, we
1488 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1489 the target, to advance the PC past the breakpoint. */
1491 enum breakpoint_here
1492 breakpoint_here_p (CORE_ADDR pc)
1494 register struct breakpoint *b;
1495 int any_breakpoint_here = 0;
1498 if ((b->enable == enabled
1499 || b->enable == permanent)
1500 && b->address == pc) /* bp is enabled and matches pc */
1502 if (overlay_debugging &&
1503 section_is_overlay (b->section) &&
1504 !section_is_mapped (b->section))
1505 continue; /* unmapped overlay -- can't be a match */
1506 else if (b->enable == permanent)
1507 return permanent_breakpoint_here;
1509 any_breakpoint_here = 1;
1512 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1516 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1517 but it only returns true if there is actually a breakpoint inserted
1521 breakpoint_inserted_here_p (CORE_ADDR pc)
1523 register struct breakpoint *b;
1527 && b->address == pc) /* bp is inserted and matches pc */
1529 if (overlay_debugging &&
1530 section_is_overlay (b->section) &&
1531 !section_is_mapped (b->section))
1532 continue; /* unmapped overlay -- can't be a match */
1540 /* Return nonzero if FRAME is a dummy frame. We can't use
1541 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1542 much time, at least using get_saved_register on the 68k. This
1543 means that for this function to work right a port must use the
1544 bp_call_dummy breakpoint. */
1547 frame_in_dummy (struct frame_info *frame)
1549 struct breakpoint *b;
1554 if (USE_GENERIC_DUMMY_FRAMES)
1555 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1559 if (b->type == bp_call_dummy
1560 && b->frame == frame->frame
1561 /* We need to check the PC as well as the frame on the sparc,
1562 for signals.exp in the testsuite. */
1565 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1566 && frame->pc <= b->address)
1572 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1573 PC is valid for process/thread PID. */
1576 breakpoint_thread_match (CORE_ADDR pc, int pid)
1578 struct breakpoint *b;
1581 thread = pid_to_thread_id (pid);
1584 if (b->enable != disabled
1585 && b->enable != shlib_disabled
1586 && b->enable != call_disabled
1588 && (b->thread == -1 || b->thread == thread))
1590 if (overlay_debugging &&
1591 section_is_overlay (b->section) &&
1592 !section_is_mapped (b->section))
1593 continue; /* unmapped overlay -- can't be a match */
1602 /* bpstat stuff. External routines' interfaces are documented
1606 ep_is_catchpoint (struct breakpoint *ep)
1609 (ep->type == bp_catch_load)
1610 || (ep->type == bp_catch_unload)
1611 || (ep->type == bp_catch_fork)
1612 || (ep->type == bp_catch_vfork)
1613 || (ep->type == bp_catch_exec)
1614 || (ep->type == bp_catch_catch)
1615 || (ep->type == bp_catch_throw);
1617 /* ??rehrauer: Add more kinds here, as are implemented... */
1621 ep_is_shlib_catchpoint (struct breakpoint *ep)
1624 (ep->type == bp_catch_load)
1625 || (ep->type == bp_catch_unload);
1629 ep_is_exception_catchpoint (struct breakpoint *ep)
1632 (ep->type == bp_catch_catch)
1633 || (ep->type == bp_catch_throw);
1636 /* Clear a bpstat so that it says we are not at any breakpoint.
1637 Also free any storage that is part of a bpstat. */
1640 bpstat_clear (bpstat *bsp)
1651 if (p->old_val != NULL)
1652 value_free (p->old_val);
1659 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1660 is part of the bpstat is copied as well. */
1663 bpstat_copy (bpstat bs)
1667 bpstat retval = NULL;
1672 for (; bs != NULL; bs = bs->next)
1674 tmp = (bpstat) xmalloc (sizeof (*tmp));
1675 memcpy (tmp, bs, sizeof (*tmp));
1677 /* This is the first thing in the chain. */
1687 /* Find the bpstat associated with this breakpoint */
1690 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1695 for (; bsp != NULL; bsp = bsp->next)
1697 if (bsp->breakpoint_at == breakpoint)
1703 /* Find a step_resume breakpoint associated with this bpstat.
1704 (If there are multiple step_resume bp's on the list, this function
1705 will arbitrarily pick one.)
1707 It is an error to use this function if BPSTAT doesn't contain a
1708 step_resume breakpoint.
1710 See wait_for_inferior's use of this function. */
1712 bpstat_find_step_resume_breakpoint (bpstat bsp)
1715 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1717 for (; bsp != NULL; bsp = bsp->next)
1719 if ((bsp->breakpoint_at != NULL) &&
1720 (bsp->breakpoint_at->type == bp_step_resume))
1721 return bsp->breakpoint_at;
1724 error ("Internal error (no step_resume breakpoint found)");
1728 /* Return the breakpoint number of the first breakpoint we are stopped
1729 at. *BSP upon return is a bpstat which points to the remaining
1730 breakpoints stopped at (but which is not guaranteed to be good for
1731 anything but further calls to bpstat_num).
1732 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1735 bpstat_num (bpstat *bsp)
1737 struct breakpoint *b;
1740 return 0; /* No more breakpoint values */
1743 b = (*bsp)->breakpoint_at;
1744 *bsp = (*bsp)->next;
1746 return -1; /* breakpoint that's been deleted since */
1748 return b->number; /* We have its number */
1752 /* Modify BS so that the actions will not be performed. */
1755 bpstat_clear_actions (bpstat bs)
1757 for (; bs != NULL; bs = bs->next)
1759 bs->commands = NULL;
1760 if (bs->old_val != NULL)
1762 value_free (bs->old_val);
1768 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1771 cleanup_executing_breakpoints (PTR ignore)
1773 executing_breakpoint_commands = 0;
1776 /* Execute all the commands associated with all the breakpoints at this
1777 location. Any of these commands could cause the process to proceed
1778 beyond this point, etc. We look out for such changes by checking
1779 the global "breakpoint_proceeded" after each command. */
1782 bpstat_do_actions (bpstat *bsp)
1785 struct cleanup *old_chain;
1786 struct command_line *cmd;
1788 /* Avoid endless recursion if a `source' command is contained
1790 if (executing_breakpoint_commands)
1793 executing_breakpoint_commands = 1;
1794 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1797 /* Note that (as of this writing), our callers all appear to
1798 be passing us the address of global stop_bpstat. And, if
1799 our calls to execute_control_command cause the inferior to
1800 proceed, that global (and hence, *bsp) will change.
1802 We must be careful to not touch *bsp unless the inferior
1803 has not proceeded. */
1805 /* This pointer will iterate over the list of bpstat's. */
1808 breakpoint_proceeded = 0;
1809 for (; bs != NULL; bs = bs->next)
1814 execute_control_command (cmd);
1816 if (breakpoint_proceeded)
1821 if (breakpoint_proceeded)
1822 /* The inferior is proceeded by the command; bomb out now.
1823 The bpstat chain has been blown away by wait_for_inferior.
1824 But since execution has stopped again, there is a new bpstat
1825 to look at, so start over. */
1828 bs->commands = NULL;
1831 executing_breakpoint_commands = 0;
1832 discard_cleanups (old_chain);
1835 /* This is the normal print function for a bpstat. In the future,
1836 much of this logic could (should?) be moved to bpstat_stop_status,
1837 by having it set different print_it values.
1839 Current scheme: When we stop, bpstat_print() is called. It loops
1840 through the bpstat list of things causing this stop, calling the
1841 print_bp_stop_message function on each one. The behavior of the
1842 print_bp_stop_message function depends on the print_it field of
1843 bpstat. If such field so indicates, call this function here.
1845 Return values from this routine (ultimately used by bpstat_print()
1846 and normal_stop() to decide what to do):
1847 PRINT_NOTHING: Means we already printed all we needed to print,
1848 don't print anything else.
1849 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1850 that something to be followed by a location.
1851 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1852 that something to be followed by a location.
1853 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1856 static enum print_stop_action
1857 print_it_typical (bpstat bs)
1860 struct cleanup *old_chain;
1861 struct ui_stream *stb;
1862 stb = ui_out_stream_new (uiout);
1863 old_chain = make_cleanup_ui_out_stream_delete (stb);
1865 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1866 which has since been deleted. */
1867 if (bs->breakpoint_at == NULL)
1868 return PRINT_UNKNOWN;
1870 switch (bs->breakpoint_at->type)
1873 case bp_hardware_breakpoint:
1875 annotate_breakpoint (bs->breakpoint_at->number);
1876 ui_out_text (uiout, "\nBreakpoint ");
1877 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
1878 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1879 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1880 ui_out_text (uiout, ", ");
1881 return PRINT_SRC_AND_LOC;
1883 /* I think the user probably only wants to see one breakpoint
1884 number, not all of them. */
1885 annotate_breakpoint (bs->breakpoint_at->number);
1886 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1887 return PRINT_SRC_AND_LOC;
1891 case bp_shlib_event:
1892 /* Did we stop because the user set the stop_on_solib_events
1893 variable? (If so, we report this as a generic, "Stopped due
1894 to shlib event" message.) */
1895 printf_filtered ("Stopped due to shared library event\n");
1896 return PRINT_NOTHING;
1899 case bp_thread_event:
1900 /* Not sure how we will get here.
1901 GDB should not stop for these breakpoints. */
1902 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1903 return PRINT_NOTHING;
1907 annotate_catchpoint (bs->breakpoint_at->number);
1908 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1909 printf_filtered ("loaded");
1910 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1911 return PRINT_SRC_AND_LOC;
1914 case bp_catch_unload:
1915 annotate_catchpoint (bs->breakpoint_at->number);
1916 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1917 printf_filtered ("unloaded");
1918 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1919 return PRINT_SRC_AND_LOC;
1923 annotate_catchpoint (bs->breakpoint_at->number);
1924 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1925 printf_filtered ("forked");
1926 printf_filtered (" process %d), ",
1927 bs->breakpoint_at->forked_inferior_pid);
1928 return PRINT_SRC_AND_LOC;
1931 case bp_catch_vfork:
1932 annotate_catchpoint (bs->breakpoint_at->number);
1933 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1934 printf_filtered ("vforked");
1935 printf_filtered (" process %d), ",
1936 bs->breakpoint_at->forked_inferior_pid);
1937 return PRINT_SRC_AND_LOC;
1941 annotate_catchpoint (bs->breakpoint_at->number);
1942 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1943 bs->breakpoint_at->number,
1944 bs->breakpoint_at->exec_pathname);
1945 return PRINT_SRC_AND_LOC;
1948 case bp_catch_catch:
1949 if (current_exception_event &&
1950 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1952 annotate_catchpoint (bs->breakpoint_at->number);
1953 printf_filtered ("\nCatchpoint %d (exception caught), ",
1954 bs->breakpoint_at->number);
1955 printf_filtered ("throw location ");
1956 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1957 printf_filtered ("%s:%d",
1958 CURRENT_EXCEPTION_THROW_FILE,
1959 CURRENT_EXCEPTION_THROW_LINE);
1961 printf_filtered ("unknown");
1963 printf_filtered (", catch location ");
1964 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1965 printf_filtered ("%s:%d",
1966 CURRENT_EXCEPTION_CATCH_FILE,
1967 CURRENT_EXCEPTION_CATCH_LINE);
1969 printf_filtered ("unknown");
1971 printf_filtered ("\n");
1972 /* don't bother to print location frame info */
1973 return PRINT_SRC_ONLY;
1977 /* really throw, some other bpstat will handle it */
1978 return PRINT_UNKNOWN;
1982 case bp_catch_throw:
1983 if (current_exception_event &&
1984 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1986 annotate_catchpoint (bs->breakpoint_at->number);
1987 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1988 bs->breakpoint_at->number);
1989 printf_filtered ("throw location ");
1990 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1991 printf_filtered ("%s:%d",
1992 CURRENT_EXCEPTION_THROW_FILE,
1993 CURRENT_EXCEPTION_THROW_LINE);
1995 printf_filtered ("unknown");
1997 printf_filtered (", catch location ");
1998 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1999 printf_filtered ("%s:%d",
2000 CURRENT_EXCEPTION_CATCH_FILE,
2001 CURRENT_EXCEPTION_CATCH_LINE);
2003 printf_filtered ("unknown");
2005 printf_filtered ("\n");
2006 /* don't bother to print location frame info */
2007 return PRINT_SRC_ONLY;
2011 /* really catch, some other bpstat will handle it */
2012 return PRINT_UNKNOWN;
2017 case bp_hardware_watchpoint:
2018 if (bs->old_val != NULL)
2020 annotate_watchpoint (bs->breakpoint_at->number);
2022 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2023 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2024 mention (bs->breakpoint_at);
2025 ui_out_list_begin (uiout, "value");
2026 ui_out_text (uiout, "\nOld value = ");
2027 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2028 ui_out_field_stream (uiout, "old", stb);
2029 ui_out_text (uiout, "\nNew value = ");
2030 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2031 ui_out_field_stream (uiout, "new", stb);
2032 ui_out_list_end (uiout);
2033 ui_out_text (uiout, "\n");
2035 mention (bs->breakpoint_at);
2036 printf_filtered ("\nOld value = ");
2037 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2038 printf_filtered ("\nNew value = ");
2039 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2040 Val_pretty_default);
2041 printf_filtered ("\n");
2043 value_free (bs->old_val);
2046 /* More than one watchpoint may have been triggered. */
2047 return PRINT_UNKNOWN;
2050 case bp_read_watchpoint:
2052 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2053 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2054 mention (bs->breakpoint_at);
2055 ui_out_list_begin (uiout, "value");
2056 ui_out_text (uiout, "\nValue = ");
2057 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2058 ui_out_field_stream (uiout, "value", stb);
2059 ui_out_list_end (uiout);
2060 ui_out_text (uiout, "\n");
2062 mention (bs->breakpoint_at);
2063 printf_filtered ("\nValue = ");
2064 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2065 Val_pretty_default);
2066 printf_filtered ("\n");
2068 return PRINT_UNKNOWN;
2071 case bp_access_watchpoint:
2073 if (bs->old_val != NULL)
2075 annotate_watchpoint (bs->breakpoint_at->number);
2076 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2077 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2078 mention (bs->breakpoint_at);
2079 ui_out_list_begin (uiout, "value");
2080 ui_out_text (uiout, "\nOld value = ");
2081 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2082 ui_out_field_stream (uiout, "old", stb);
2083 value_free (bs->old_val);
2085 ui_out_text (uiout, "\nNew value = ");
2089 mention (bs->breakpoint_at);
2090 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2091 ui_out_list_begin (uiout, "value");
2092 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2093 ui_out_text (uiout, "\nValue = ");
2095 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2096 ui_out_field_stream (uiout, "new", stb);
2097 ui_out_list_end (uiout);
2098 ui_out_text (uiout, "\n");
2100 if (bs->old_val != NULL)
2102 annotate_watchpoint (bs->breakpoint_at->number);
2103 mention (bs->breakpoint_at);
2104 printf_filtered ("\nOld value = ");
2105 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2106 value_free (bs->old_val);
2108 printf_filtered ("\nNew value = ");
2112 mention (bs->breakpoint_at);
2113 printf_filtered ("\nValue = ");
2115 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2116 Val_pretty_default);
2117 printf_filtered ("\n");
2119 return PRINT_UNKNOWN;
2122 /* Fall through, we don't deal with these types of breakpoints
2127 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2128 ui_out_field_string (uiout, "reason", "function-finished");
2130 return PRINT_UNKNOWN;
2135 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2136 ui_out_field_string (uiout, "reason", "location-reached");
2138 return PRINT_UNKNOWN;
2143 case bp_longjmp_resume:
2144 case bp_step_resume:
2145 case bp_through_sigtramp:
2146 case bp_watchpoint_scope:
2149 return PRINT_UNKNOWN;
2153 /* Generic routine for printing messages indicating why we
2154 stopped. The behavior of this function depends on the value
2155 'print_it' in the bpstat structure. Under some circumstances we
2156 may decide not to print anything here and delegate the task to
2159 static enum print_stop_action
2160 print_bp_stop_message (bpstat bs)
2162 switch (bs->print_it)
2165 /* Nothing should be printed for this bpstat entry. */
2166 return PRINT_UNKNOWN;
2170 /* We still want to print the frame, but we already printed the
2171 relevant messages. */
2172 return PRINT_SRC_AND_LOC;
2175 case print_it_normal:
2176 /* Normal case, we handle everything in print_it_typical. */
2177 return print_it_typical (bs);
2180 internal_error (__FILE__, __LINE__,
2181 "print_bp_stop_message: unrecognized enum value");
2186 /* Print a message indicating what happened. This is called from
2187 normal_stop(). The input to this routine is the head of the bpstat
2188 list - a list of the eventpoints that caused this stop. This
2189 routine calls the generic print routine for printing a message
2190 about reasons for stopping. This will print (for example) the
2191 "Breakpoint n," part of the output. The return value of this
2194 PRINT_UNKNOWN: Means we printed nothing
2195 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2196 code to print the location. An example is
2197 "Breakpoint 1, " which should be followed by
2199 PRINT_SRC_ONLY: Means we printed something, but there is no need
2200 to also print the location part of the message.
2201 An example is the catch/throw messages, which
2202 don't require a location appended to the end.
2203 PRINT_NOTHING: We have done some printing and we don't need any
2204 further info to be printed.*/
2206 enum print_stop_action
2207 bpstat_print (bpstat bs)
2211 /* Maybe another breakpoint in the chain caused us to stop.
2212 (Currently all watchpoints go on the bpstat whether hit or not.
2213 That probably could (should) be changed, provided care is taken
2214 with respect to bpstat_explains_signal). */
2215 for (; bs; bs = bs->next)
2217 val = print_bp_stop_message (bs);
2218 if (val == PRINT_SRC_ONLY
2219 || val == PRINT_SRC_AND_LOC
2220 || val == PRINT_NOTHING)
2224 /* We reached the end of the chain, or we got a null BS to start
2225 with and nothing was printed. */
2226 return PRINT_UNKNOWN;
2229 /* Evaluate the expression EXP and return 1 if value is zero.
2230 This is used inside a catch_errors to evaluate the breakpoint condition.
2231 The argument is a "struct expression *" that has been cast to char * to
2232 make it pass through catch_errors. */
2235 breakpoint_cond_eval (PTR exp)
2237 value_ptr mark = value_mark ();
2238 int i = !value_true (evaluate_expression ((struct expression *) exp));
2239 value_free_to_mark (mark);
2243 /* Allocate a new bpstat and chain it to the current one. */
2246 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2250 bs = (bpstat) xmalloc (sizeof (*bs));
2252 bs->breakpoint_at = b;
2253 /* If the condition is false, etc., don't do the commands. */
2254 bs->commands = NULL;
2256 bs->print_it = print_it_normal;
2260 /* Possible return values for watchpoint_check (this can't be an enum
2261 because of check_errors). */
2262 /* The watchpoint has been deleted. */
2263 #define WP_DELETED 1
2264 /* The value has changed. */
2265 #define WP_VALUE_CHANGED 2
2266 /* The value has not changed. */
2267 #define WP_VALUE_NOT_CHANGED 3
2269 #define BP_TEMPFLAG 1
2270 #define BP_HARDWAREFLAG 2
2272 /* Check watchpoint condition. */
2275 watchpoint_check (PTR p)
2277 bpstat bs = (bpstat) p;
2278 struct breakpoint *b;
2279 struct frame_info *fr;
2280 int within_current_scope;
2282 b = bs->breakpoint_at;
2284 if (b->exp_valid_block == NULL)
2285 within_current_scope = 1;
2288 /* There is no current frame at this moment. If we're going to have
2289 any chance of handling watchpoints on local variables, we'll need
2290 the frame chain (so we can determine if we're in scope). */
2291 reinit_frame_cache ();
2292 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2293 within_current_scope = (fr != NULL);
2294 if (within_current_scope)
2295 /* If we end up stopping, the current frame will get selected
2296 in normal_stop. So this call to select_frame won't affect
2298 select_frame (fr, -1);
2301 if (within_current_scope)
2303 /* We use value_{,free_to_}mark because it could be a
2304 *long* time before we return to the command level and
2305 call free_all_values. We can't call free_all_values because
2306 we might be in the middle of evaluating a function call. */
2308 value_ptr mark = value_mark ();
2309 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2310 if (!value_equal (b->val, new_val))
2312 release_value (new_val);
2313 value_free_to_mark (mark);
2314 bs->old_val = b->val;
2316 /* We will stop here */
2317 return WP_VALUE_CHANGED;
2321 /* Nothing changed, don't do anything. */
2322 value_free_to_mark (mark);
2323 /* We won't stop here */
2324 return WP_VALUE_NOT_CHANGED;
2329 /* This seems like the only logical thing to do because
2330 if we temporarily ignored the watchpoint, then when
2331 we reenter the block in which it is valid it contains
2332 garbage (in the case of a function, it may have two
2333 garbage values, one before and one after the prologue).
2334 So we can't even detect the first assignment to it and
2335 watch after that (since the garbage may or may not equal
2336 the first value assigned). */
2337 /* We print all the stop information in print_it_typical(), but
2338 in this case, by the time we call print_it_typical() this bp
2339 will be deleted already. So we have no choice but print the
2340 information here. */
2342 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2343 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2344 ui_out_text (uiout, "\nWatchpoint ");
2345 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2346 ui_out_text (uiout, " deleted because the program has left the block in\n\
2347 which its expression is valid.\n");
2350 Watchpoint %d deleted because the program has left the block in\n\
2351 which its expression is valid.\n", bs->breakpoint_at->number);
2354 if (b->related_breakpoint)
2355 b->related_breakpoint->disposition = del_at_next_stop;
2356 b->disposition = del_at_next_stop;
2362 /* Get a bpstat associated with having just stopped at address *PC
2363 and frame address CORE_ADDRESS. Update *PC to point at the
2364 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2365 if this is known to not be a real breakpoint (it could still be a
2366 watchpoint, though). */
2368 /* Determine whether we stopped at a breakpoint, etc, or whether we
2369 don't understand this stop. Result is a chain of bpstat's such that:
2371 if we don't understand the stop, the result is a null pointer.
2373 if we understand why we stopped, the result is not null.
2375 Each element of the chain refers to a particular breakpoint or
2376 watchpoint at which we have stopped. (We may have stopped for
2377 several reasons concurrently.)
2379 Each element of the chain has valid next, breakpoint_at,
2380 commands, FIXME??? fields. */
2383 bpstat_stop_status (CORE_ADDR *pc, int not_a_breakpoint)
2385 register struct breakpoint *b, *temp;
2387 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2388 int real_breakpoint = 0;
2389 /* Root of the chain of bpstat's */
2390 struct bpstats root_bs[1];
2391 /* Pointer to the last thing in the chain currently. */
2392 bpstat bs = root_bs;
2393 static char message1[] =
2394 "Error evaluating expression for watchpoint %d\n";
2395 char message[sizeof (message1) + 30 /* slop */ ];
2397 /* Get the address where the breakpoint would have been. */
2398 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ?
2399 0 : DECR_PC_AFTER_BREAK);
2401 ALL_BREAKPOINTS_SAFE (b, temp)
2403 if (b->enable == disabled
2404 || b->enable == shlib_disabled
2405 || b->enable == call_disabled)
2408 if (b->type != bp_watchpoint
2409 && b->type != bp_hardware_watchpoint
2410 && b->type != bp_read_watchpoint
2411 && b->type != bp_access_watchpoint
2412 && b->type != bp_hardware_breakpoint
2413 && b->type != bp_catch_fork
2414 && b->type != bp_catch_vfork
2415 && b->type != bp_catch_exec
2416 && b->type != bp_catch_catch
2417 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2418 if (b->address != bp_addr || /* address doesn't match or */
2419 (overlay_debugging && /* overlay doesn't match */
2420 section_is_overlay (b->section) &&
2421 !section_is_mapped (b->section)))
2424 if (b->type == bp_hardware_breakpoint
2425 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2428 /* Is this a catchpoint of a load or unload? If so, did we
2429 get a load or unload of the specified library? If not,
2431 if ((b->type == bp_catch_load)
2432 #if defined(SOLIB_HAVE_LOAD_EVENT)
2433 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2434 || ((b->dll_pathname != NULL)
2435 && (strcmp (b->dll_pathname,
2436 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2442 if ((b->type == bp_catch_unload)
2443 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2444 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2445 || ((b->dll_pathname != NULL)
2446 && (strcmp (b->dll_pathname,
2447 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2453 if ((b->type == bp_catch_fork)
2454 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2457 if ((b->type == bp_catch_vfork)
2458 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2461 if ((b->type == bp_catch_exec)
2462 && !target_has_execd (inferior_pid, &b->exec_pathname))
2465 if (ep_is_exception_catchpoint (b) &&
2466 !(current_exception_event = target_get_current_exception_event ()))
2469 /* Come here if it's a watchpoint, or if the break address matches */
2471 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2473 /* Watchpoints may change this, if not found to have triggered. */
2477 sprintf (message, message1, b->number);
2478 if (b->type == bp_watchpoint ||
2479 b->type == bp_hardware_watchpoint)
2481 switch (catch_errors (watchpoint_check, bs, message,
2485 /* We've already printed what needs to be printed. */
2486 /* Actually this is superfluous, because by the time we
2487 call print_it_typical() the wp will be already deleted,
2488 and the function will return immediately. */
2489 bs->print_it = print_it_done;
2492 case WP_VALUE_CHANGED:
2496 case WP_VALUE_NOT_CHANGED:
2498 bs->print_it = print_it_noop;
2505 /* Error from catch_errors. */
2506 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2507 if (b->related_breakpoint)
2508 b->related_breakpoint->disposition = del_at_next_stop;
2509 b->disposition = del_at_next_stop;
2510 /* We've already printed what needs to be printed. */
2511 bs->print_it = print_it_done;
2517 else if (b->type == bp_read_watchpoint ||
2518 b->type == bp_access_watchpoint)
2524 addr = target_stopped_data_address ();
2527 for (v = b->val_chain; v; v = v->next)
2529 if (VALUE_LVAL (v) == lval_memory
2530 && ! VALUE_LAZY (v))
2532 struct type *vtype = check_typedef (VALUE_TYPE (v));
2534 if (v == b->val_chain
2535 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2536 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2540 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2541 /* Exact match not required. Within range is
2543 if (addr >= vaddr &&
2544 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2550 switch (catch_errors (watchpoint_check, bs, message,
2554 /* We've already printed what needs to be printed. */
2555 bs->print_it = print_it_done;
2558 case WP_VALUE_CHANGED:
2559 if (b->type == bp_read_watchpoint)
2561 /* Don't stop: read watchpoints shouldn't fire if
2562 the value has changed. This is for targets which
2563 cannot set read-only watchpoints. */
2564 bs->print_it = print_it_noop;
2570 case WP_VALUE_NOT_CHANGED:
2577 /* Error from catch_errors. */
2578 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2579 if (b->related_breakpoint)
2580 b->related_breakpoint->disposition = del_at_next_stop;
2581 b->disposition = del_at_next_stop;
2582 /* We've already printed what needs to be printed. */
2583 bs->print_it = print_it_done;
2586 else /* found == 0 */
2588 /* This is a case where some watchpoint(s) triggered,
2589 but not at the address of this watchpoint (FOUND
2590 was left zero). So don't print anything for this
2592 bs->print_it = print_it_noop;
2599 /* By definition, an encountered breakpoint is a triggered
2603 real_breakpoint = 1;
2607 b->frame != (get_current_frame ())->frame)
2611 int value_is_zero = 0;
2615 /* Need to select the frame, with all that implies
2616 so that the conditions will have the right context. */
2617 select_frame (get_current_frame (), 0);
2619 = catch_errors (breakpoint_cond_eval, (b->cond),
2620 "Error in testing breakpoint condition:\n",
2622 /* FIXME-someday, should give breakpoint # */
2625 if (b->cond && value_is_zero)
2628 /* Don't consider this a hit. */
2631 else if (b->ignore_count > 0)
2634 annotate_ignore_count_change ();
2639 /* We will stop here */
2640 if (b->disposition == disable)
2641 b->enable = disabled;
2642 bs->commands = b->commands;
2646 (STREQ ("silent", bs->commands->line) ||
2647 (xdb_commands && STREQ ("Q", bs->commands->line))))
2649 bs->commands = bs->commands->next;
2654 /* Print nothing for this entry if we dont stop or if we dont print. */
2655 if (bs->stop == 0 || bs->print == 0)
2656 bs->print_it = print_it_noop;
2659 bs->next = NULL; /* Terminate the chain */
2660 bs = root_bs->next; /* Re-grab the head of the chain */
2662 if (real_breakpoint && bs)
2664 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2666 if (DECR_PC_AFTER_HW_BREAK != 0)
2668 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2674 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2677 #if defined (SHIFT_INST_REGS)
2679 #else /* No SHIFT_INST_REGS. */
2681 #endif /* No SHIFT_INST_REGS. */
2686 /* The value of a hardware watchpoint hasn't changed, but the
2687 intermediate memory locations we are watching may have. */
2688 if (bs && !bs->stop &&
2689 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2690 bs->breakpoint_at->type == bp_read_watchpoint ||
2691 bs->breakpoint_at->type == bp_access_watchpoint))
2693 remove_breakpoints ();
2694 insert_breakpoints ();
2699 /* Tell what to do about this bpstat. */
2701 bpstat_what (bpstat bs)
2703 /* Classify each bpstat as one of the following. */
2706 /* This bpstat element has no effect on the main_action. */
2709 /* There was a watchpoint, stop but don't print. */
2712 /* There was a watchpoint, stop and print. */
2715 /* There was a breakpoint but we're not stopping. */
2718 /* There was a breakpoint, stop but don't print. */
2721 /* There was a breakpoint, stop and print. */
2724 /* We hit the longjmp breakpoint. */
2727 /* We hit the longjmp_resume breakpoint. */
2730 /* We hit the step_resume breakpoint. */
2733 /* We hit the through_sigtramp breakpoint. */
2736 /* We hit the shared library event breakpoint. */
2739 /* We caught a shared library event. */
2742 /* This is just used to count how many enums there are. */
2746 /* Here is the table which drives this routine. So that we can
2747 format it pretty, we define some abbreviations for the
2748 enum bpstat_what codes. */
2749 #define kc BPSTAT_WHAT_KEEP_CHECKING
2750 #define ss BPSTAT_WHAT_STOP_SILENT
2751 #define sn BPSTAT_WHAT_STOP_NOISY
2752 #define sgl BPSTAT_WHAT_SINGLE
2753 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2754 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2755 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2756 #define sr BPSTAT_WHAT_STEP_RESUME
2757 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2758 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2759 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2761 /* "Can't happen." Might want to print an error message.
2762 abort() is not out of the question, but chances are GDB is just
2763 a bit confused, not unusable. */
2764 #define err BPSTAT_WHAT_STOP_NOISY
2766 /* Given an old action and a class, come up with a new action. */
2767 /* One interesting property of this table is that wp_silent is the same
2768 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2769 after stopping, the check for whether to step over a breakpoint
2770 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2771 reference to how we stopped. We retain separate wp_silent and
2772 bp_silent codes in case we want to change that someday.
2774 Another possibly interesting property of this table is that
2775 there's a partial ordering, priority-like, of the actions. Once
2776 you've decided that some action is appropriate, you'll never go
2777 back and decide something of a lower priority is better. The
2780 kc < clr sgl shl shlr slr sn sr ss ts
2781 sgl < clrs shl shlr slr sn sr ss ts
2782 slr < err shl shlr sn sr ss ts
2783 clr < clrs err shl shlr sn sr ss ts
2784 clrs < err shl shlr sn sr ss ts
2785 ss < shl shlr sn sr ts
2792 What I think this means is that we don't need a damned table
2793 here. If you just put the rows and columns in the right order,
2794 it'd look awfully regular. We could simply walk the bpstat list
2795 and choose the highest priority action we find, with a little
2796 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2797 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2798 is messy anyway). */
2800 /* step_resume entries: a step resume breakpoint overrides another
2801 breakpoint of signal handling (see comment in wait_for_inferior
2802 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2803 /* We handle the through_sigtramp_breakpoint the same way; having both
2804 one of those and a step_resume_breakpoint is probably very rare (?). */
2806 static const enum bpstat_what_main_action
2807 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2810 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2813 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2815 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2817 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2819 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2821 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2823 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2825 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2827 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2829 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2831 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2833 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2835 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2850 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2851 struct bpstat_what retval;
2853 retval.call_dummy = 0;
2854 for (; bs != NULL; bs = bs->next)
2856 enum class bs_class = no_effect;
2857 if (bs->breakpoint_at == NULL)
2858 /* I suspect this can happen if it was a momentary breakpoint
2859 which has since been deleted. */
2861 switch (bs->breakpoint_at->type)
2867 case bp_hardware_breakpoint:
2873 bs_class = bp_noisy;
2875 bs_class = bp_silent;
2878 bs_class = bp_nostop;
2881 case bp_hardware_watchpoint:
2882 case bp_read_watchpoint:
2883 case bp_access_watchpoint:
2887 bs_class = wp_noisy;
2889 bs_class = wp_silent;
2892 /* There was a watchpoint, but we're not stopping.
2893 This requires no further action. */
2894 bs_class = no_effect;
2897 bs_class = long_jump;
2899 case bp_longjmp_resume:
2900 bs_class = long_resume;
2902 case bp_step_resume:
2905 bs_class = step_resume;
2908 /* It is for the wrong frame. */
2909 bs_class = bp_nostop;
2911 case bp_through_sigtramp:
2912 bs_class = through_sig;
2914 case bp_watchpoint_scope:
2915 bs_class = bp_nostop;
2917 case bp_shlib_event:
2918 bs_class = shlib_event;
2920 case bp_thread_event:
2921 bs_class = bp_nostop;
2924 case bp_catch_unload:
2925 /* Only if this catchpoint triggered should we cause the
2926 step-out-of-dld behaviour. Otherwise, we ignore this
2929 bs_class = catch_shlib_event;
2931 bs_class = no_effect;
2934 case bp_catch_vfork:
2939 bs_class = bp_noisy;
2941 bs_class = bp_silent;
2944 /* There was a catchpoint, but we're not stopping.
2945 This requires no further action. */
2946 bs_class = no_effect;
2948 case bp_catch_catch:
2949 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2950 bs_class = bp_nostop;
2952 bs_class = bs->print ? bp_noisy : bp_silent;
2954 case bp_catch_throw:
2955 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2956 bs_class = bp_nostop;
2958 bs_class = bs->print ? bp_noisy : bp_silent;
2961 /* Make sure the action is stop (silent or noisy),
2962 so infrun.c pops the dummy frame. */
2963 bs_class = bp_silent;
2964 retval.call_dummy = 1;
2967 current_action = table[(int) bs_class][(int) current_action];
2969 retval.main_action = current_action;
2973 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2974 without hardware support). This isn't related to a specific bpstat,
2975 just to things like whether watchpoints are set. */
2978 bpstat_should_step (void)
2980 struct breakpoint *b;
2982 if (b->enable == enabled && b->type == bp_watchpoint)
2987 /* Nonzero if there are enabled hardware watchpoints. */
2989 bpstat_have_active_hw_watchpoints (void)
2991 struct breakpoint *b;
2993 if ((b->enable == enabled) &&
2995 ((b->type == bp_hardware_watchpoint) ||
2996 (b->type == bp_read_watchpoint) ||
2997 (b->type == bp_access_watchpoint)))
3003 /* Given a bpstat that records zero or more triggered eventpoints, this
3004 function returns another bpstat which contains only the catchpoints
3005 on that first list, if any. */
3007 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3009 struct bpstats root_bs[1];
3010 bpstat bs = root_bs;
3011 struct breakpoint *ep;
3014 bpstat_clear (cp_list);
3015 root_bs->next = NULL;
3017 for (; ep_list != NULL; ep_list = ep_list->next)
3019 /* Is this eventpoint a catchpoint? If not, ignore it. */
3020 ep = ep_list->breakpoint_at;
3023 if ((ep->type != bp_catch_load) &&
3024 (ep->type != bp_catch_unload) &&
3025 (ep->type != bp_catch_catch) &&
3026 (ep->type != bp_catch_throw))
3027 /* pai: (temp) ADD fork/vfork here!! */
3030 /* Yes; add it to the list. */
3031 bs = bpstat_alloc (ep, bs);
3036 #if defined(SOLIB_ADD)
3037 /* Also, for each triggered catchpoint, tag it with the name of
3038 the library that caused this trigger. (We copy the name now,
3039 because it's only guaranteed to be available NOW, when the
3040 catchpoint triggers. Clients who may wish to know the name
3041 later must get it from the catchpoint itself.) */
3042 if (ep->triggered_dll_pathname != NULL)
3043 xfree (ep->triggered_dll_pathname);
3044 if (ep->type == bp_catch_load)
3045 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
3047 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
3049 dll_pathname = NULL;
3053 ep->triggered_dll_pathname = (char *)
3054 xmalloc (strlen (dll_pathname) + 1);
3055 strcpy (ep->triggered_dll_pathname, dll_pathname);
3058 ep->triggered_dll_pathname = NULL;
3064 /* Print B to gdb_stdout. */
3066 print_one_breakpoint (struct breakpoint *b,
3067 CORE_ADDR *last_addr)
3069 register struct command_line *l;
3070 register struct symbol *sym;
3071 struct ep_type_description
3076 static struct ep_type_description bptypes[] =
3078 {bp_none, "?deleted?"},
3079 {bp_breakpoint, "breakpoint"},
3080 {bp_hardware_breakpoint, "hw breakpoint"},
3081 {bp_until, "until"},
3082 {bp_finish, "finish"},
3083 {bp_watchpoint, "watchpoint"},
3084 {bp_hardware_watchpoint, "hw watchpoint"},
3085 {bp_read_watchpoint, "read watchpoint"},
3086 {bp_access_watchpoint, "acc watchpoint"},
3087 {bp_longjmp, "longjmp"},
3088 {bp_longjmp_resume, "longjmp resume"},
3089 {bp_step_resume, "step resume"},
3090 {bp_through_sigtramp, "sigtramp"},
3091 {bp_watchpoint_scope, "watchpoint scope"},
3092 {bp_call_dummy, "call dummy"},
3093 {bp_shlib_event, "shlib events"},
3094 {bp_thread_event, "thread events"},
3095 {bp_catch_load, "catch load"},
3096 {bp_catch_unload, "catch unload"},
3097 {bp_catch_fork, "catch fork"},
3098 {bp_catch_vfork, "catch vfork"},
3099 {bp_catch_exec, "catch exec"},
3100 {bp_catch_catch, "catch catch"},
3101 {bp_catch_throw, "catch throw"}
3104 static char *bpdisps[] =
3105 {"del", "dstp", "dis", "keep"};
3106 static char bpenables[] = "nynny";
3107 char wrap_indent[80];
3109 struct ui_stream *stb = ui_out_stream_new (uiout);
3110 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3115 ui_out_list_begin (uiout, "bkpt");
3121 ui_out_field_int (uiout, "number", b->number);
3123 printf_filtered ("%-3d ", b->number);
3128 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3129 || ((int) b->type != bptypes[(int) b->type].type))
3130 internal_error (__FILE__, __LINE__,
3131 "bptypes table does not describe type #%d.",
3134 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3136 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3142 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3144 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3150 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3151 ui_out_spaces (uiout, 2);
3153 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3157 strcpy (wrap_indent, " ");
3159 strcat (wrap_indent, " ");
3163 internal_error (__FILE__, __LINE__,
3164 "print_one_breakpoint: bp_none encountered\n");
3168 case bp_hardware_watchpoint:
3169 case bp_read_watchpoint:
3170 case bp_access_watchpoint:
3171 /* Field 4, the address, is omitted (which makes the columns
3172 not line up too nicely with the headers, but the effect
3173 is relatively readable). */
3176 ui_out_field_skip (uiout, "addr");
3178 print_expression (b->exp, stb->stream);
3179 ui_out_field_stream (uiout, "what", stb);
3182 print_expression (b->exp, gdb_stdout);
3187 case bp_catch_unload:
3188 /* Field 4, the address, is omitted (which makes the columns
3189 not line up too nicely with the headers, but the effect
3190 is relatively readable). */
3193 ui_out_field_skip (uiout, "addr");
3195 if (b->dll_pathname == NULL)
3197 ui_out_field_string (uiout, "what", "<any library>");
3198 ui_out_spaces (uiout, 1);
3202 ui_out_text (uiout, "library \"");
3203 ui_out_field_string (uiout, "what", b->dll_pathname);
3204 ui_out_text (uiout, "\" ");
3208 if (b->dll_pathname == NULL)
3209 printf_filtered ("<any library> ");
3211 printf_filtered ("library \"%s\" ", b->dll_pathname);
3216 case bp_catch_vfork:
3217 /* Field 4, the address, is omitted (which makes the columns
3218 not line up too nicely with the headers, but the effect
3219 is relatively readable). */
3222 ui_out_field_skip (uiout, "addr");
3224 if (b->forked_inferior_pid != 0)
3226 ui_out_text (uiout, "process ");
3227 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3228 ui_out_spaces (uiout, 1);
3232 if (b->forked_inferior_pid != 0)
3233 printf_filtered ("process %d ", b->forked_inferior_pid);
3238 /* Field 4, the address, is omitted (which makes the columns
3239 not line up too nicely with the headers, but the effect
3240 is relatively readable). */
3243 ui_out_field_skip (uiout, "addr");
3245 if (b->exec_pathname != NULL)
3247 ui_out_text (uiout, "program \"");
3248 ui_out_field_string (uiout, "what", b->exec_pathname);
3249 ui_out_text (uiout, "\" ");
3253 if (b->exec_pathname != NULL)
3254 printf_filtered ("program \"%s\" ", b->exec_pathname);
3258 case bp_catch_catch:
3259 /* Field 4, the address, is omitted (which makes the columns
3260 not line up too nicely with the headers, but the effect
3261 is relatively readable). */
3264 ui_out_field_skip (uiout, "addr");
3266 ui_out_field_string (uiout, "what", "exception catch");
3267 ui_out_spaces (uiout, 1);
3270 printf_filtered ("exception catch ");
3274 case bp_catch_throw:
3275 /* Field 4, the address, is omitted (which makes the columns
3276 not line up too nicely with the headers, but the effect
3277 is relatively readable). */
3280 ui_out_field_skip (uiout, "addr");
3282 ui_out_field_string (uiout, "what", "exception throw");
3283 ui_out_spaces (uiout, 1);
3286 printf_filtered ("exception throw ");
3291 case bp_hardware_breakpoint:
3295 case bp_longjmp_resume:
3296 case bp_step_resume:
3297 case bp_through_sigtramp:
3298 case bp_watchpoint_scope:
3300 case bp_shlib_event:
3301 case bp_thread_event:
3306 ui_out_field_core_addr (uiout, "addr", b->address);
3309 *last_addr = b->address;
3312 sym = find_pc_sect_function (b->address, b->section);
3315 ui_out_text (uiout, "in ");
3316 ui_out_field_string (uiout, "func",
3317 SYMBOL_SOURCE_NAME (sym));
3318 ui_out_wrap_hint (uiout, wrap_indent);
3319 ui_out_text (uiout, " at ");
3321 ui_out_field_string (uiout, "file", b->source_file);
3322 ui_out_text (uiout, ":");
3323 ui_out_field_int (uiout, "line", b->line_number);
3327 print_address_symbolic (b->address, stb->stream, demangle, "");
3328 ui_out_field_stream (uiout, "at", stb);
3334 /* FIXME-32x64: need a print_address_numeric with
3336 printf_filtered ("%s ",
3337 local_hex_string_custom
3338 ((unsigned long) b->address, "08l"));
3341 *last_addr = b->address;
3344 sym = find_pc_sect_function (b->address, b->section);
3347 fputs_filtered ("in ", gdb_stdout);
3348 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3349 wrap_here (wrap_indent);
3350 fputs_filtered (" at ", gdb_stdout);
3352 fputs_filtered (b->source_file, gdb_stdout);
3353 printf_filtered (":%d", b->line_number);
3356 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3361 if (b->thread != -1)
3364 /* FIXME: This seems to be redundant and lost here; see the
3365 "stop only in" line a little further down. */
3366 ui_out_text (uiout, " thread ");
3367 ui_out_field_int (uiout, "thread", b->thread);
3369 printf_filtered (" thread %d", b->thread);
3374 ui_out_text (uiout, "\n");
3376 printf_filtered ("\n");
3383 ui_out_text (uiout, "\tstop only in stack frame at ");
3384 ui_out_field_core_addr (uiout, "frame", b->frame);
3385 ui_out_text (uiout, "\n");
3387 printf_filtered ("\tstop only in stack frame at ");
3388 print_address_numeric (b->frame, 1, gdb_stdout);
3389 printf_filtered ("\n");
3397 ui_out_text (uiout, "\tstop only if ");
3398 print_expression (b->cond, stb->stream);
3399 ui_out_field_stream (uiout, "cond", stb);
3400 ui_out_text (uiout, "\n");
3402 printf_filtered ("\tstop only if ");
3403 print_expression (b->cond, gdb_stdout);
3404 printf_filtered ("\n");
3408 if (b->thread != -1)
3410 /* FIXME should make an annotation for this */
3412 ui_out_text (uiout, "\tstop only in thread ");
3413 ui_out_field_int (uiout, "thread", b->thread);
3414 ui_out_text (uiout, "\n");
3416 printf_filtered ("\tstop only in thread %d\n", b->thread);
3420 if (show_breakpoint_hit_counts && b->hit_count)
3422 /* FIXME should make an annotation for this */
3424 if (ep_is_catchpoint (b))
3425 ui_out_text (uiout, "\tcatchpoint");
3427 ui_out_text (uiout, "\tbreakpoint");
3428 ui_out_text (uiout, " already hit ");
3429 ui_out_field_int (uiout, "times", b->hit_count);
3430 if (b->hit_count == 1)
3431 ui_out_text (uiout, " time\n");
3433 ui_out_text (uiout, " times\n");
3435 if (ep_is_catchpoint (b))
3436 printf_filtered ("\tcatchpoint");
3438 printf_filtered ("\tbreakpoint");
3439 printf_filtered (" already hit %d time%s\n",
3440 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3445 /* Output the count also if it is zero, but only if this is
3446 mi. FIXME: Should have a better test for this. */
3447 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3448 if (show_breakpoint_hit_counts && b->hit_count == 0)
3449 ui_out_field_int (uiout, "times", b->hit_count);
3452 if (b->ignore_count)
3456 ui_out_text (uiout, "\tignore next ");
3457 ui_out_field_int (uiout, "ignore", b->ignore_count);
3458 ui_out_text (uiout, " hits\n");
3460 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3464 if ((l = b->commands))
3468 ui_out_list_begin (uiout, "script");
3469 print_command_lines (uiout, l, 4);
3470 ui_out_list_end (uiout);
3474 print_command_line (l, 4, gdb_stdout);
3480 ui_out_list_end (uiout);
3481 do_cleanups (old_chain);
3485 struct captured_breakpoint_query_args
3491 do_captured_breakpoint_query (void *data)
3493 struct captured_breakpoint_query_args *args = data;
3494 register struct breakpoint *b;
3495 CORE_ADDR dummy_addr = 0;
3498 if (args->bnum == b->number)
3500 print_one_breakpoint (b, &dummy_addr);
3508 gdb_breakpoint_query (/* output object, */ int bnum)
3510 struct captured_breakpoint_query_args args;
3512 /* For the moment we don't trust print_one_breakpoint() to not throw
3514 return catch_errors (do_captured_breakpoint_query, &args,
3515 NULL, RETURN_MASK_ALL);
3518 /* Print information on breakpoint number BNUM, or -1 if all.
3519 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3520 is nonzero, process only watchpoints. */
3523 breakpoint_1 (int bnum, int allflag)
3525 register struct breakpoint *b;
3526 CORE_ADDR last_addr = (CORE_ADDR) -1;
3527 int found_a_breakpoint = 0;
3531 ui_out_table_begin (uiout, 6, "BreakpointTable");
3533 ui_out_table_begin (uiout, 5, "BreakpointTable");
3538 || bnum == b->number)
3540 /* We only print out user settable breakpoints unless the
3543 && b->type != bp_breakpoint
3544 && b->type != bp_catch_load
3545 && b->type != bp_catch_unload
3546 && b->type != bp_catch_fork
3547 && b->type != bp_catch_vfork
3548 && b->type != bp_catch_exec
3549 && b->type != bp_catch_catch
3550 && b->type != bp_catch_throw
3551 && b->type != bp_hardware_breakpoint
3552 && b->type != bp_watchpoint
3553 && b->type != bp_read_watchpoint
3554 && b->type != bp_access_watchpoint
3555 && b->type != bp_hardware_watchpoint)
3558 if (!found_a_breakpoint++)
3560 annotate_breakpoints_headers ();
3563 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3565 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3567 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3569 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3573 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3576 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3577 ui_out_table_body (uiout);
3580 printf_filtered ("Num ");
3582 printf_filtered ("Type ");
3584 printf_filtered ("Disp ");
3586 printf_filtered ("Enb ");
3590 printf_filtered ("Address ");
3593 printf_filtered ("What\n");
3595 annotate_breakpoints_table ();
3598 print_one_breakpoint (b, &last_addr);
3601 if (!found_a_breakpoint)
3605 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3607 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3611 printf_filtered ("No breakpoints or watchpoints.\n");
3613 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3618 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3619 that a comparison of an unsigned with -1 is always false. */
3620 if (last_addr != (CORE_ADDR) -1)
3621 set_next_address (last_addr);
3625 ui_out_table_end (uiout);
3627 /* FIXME? Should this be moved up so that it is only called when
3628 there have been breakpoints? */
3629 annotate_breakpoints_table_end ();
3634 breakpoints_info (char *bnum_exp, int from_tty)
3639 bnum = parse_and_eval_long (bnum_exp);
3641 breakpoint_1 (bnum, 0);
3646 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3651 bnum = parse_and_eval_long (bnum_exp);
3653 breakpoint_1 (bnum, 1);
3656 /* Print a message describing any breakpoints set at PC. */
3659 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3661 register int others = 0;
3662 register struct breakpoint *b;
3665 if (b->address == pc)
3666 if (overlay_debugging == 0 ||
3667 b->section == section)
3671 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3673 if (b->address == pc)
3674 if (overlay_debugging == 0 ||
3675 b->section == section)
3678 printf_filtered ("%d%s%s ",
3680 ((b->enable == disabled ||
3681 b->enable == shlib_disabled ||
3682 b->enable == call_disabled) ? " (disabled)"
3683 : b->enable == permanent ? " (permanent)"
3686 : ((others == 1) ? " and" : ""));
3688 printf_filtered ("also set at pc ");
3689 print_address_numeric (pc, 1, gdb_stdout);
3690 printf_filtered (".\n");
3694 /* Set the default place to put a breakpoint
3695 for the `break' command with no arguments. */
3698 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3701 default_breakpoint_valid = valid;
3702 default_breakpoint_address = addr;
3703 default_breakpoint_symtab = symtab;
3704 default_breakpoint_line = line;
3707 /* Rescan breakpoints at address ADDRESS,
3708 marking the first one as "first" and any others as "duplicates".
3709 This is so that the bpt instruction is only inserted once.
3710 If we have a permanent breakpoint at ADDRESS, make that one
3711 the official one, and the rest as duplicates. */
3714 check_duplicates (CORE_ADDR address, asection *section)
3716 register struct breakpoint *b;
3717 register int count = 0;
3718 struct breakpoint *perm_bp = 0;
3720 if (address == 0) /* Watchpoints are uninteresting */
3724 if (b->enable != disabled
3725 && b->enable != shlib_disabled
3726 && b->enable != call_disabled
3727 && b->address == address
3728 && (overlay_debugging == 0 || b->section == section))
3730 /* Have we found a permanent breakpoint? */
3731 if (b->enable == permanent)
3738 b->duplicate = count > 1;
3741 /* If we found a permanent breakpoint at this address, go over the
3742 list again and declare all the other breakpoints there to be the
3746 perm_bp->duplicate = 0;
3748 /* Permanent breakpoint should always be inserted. */
3749 if (! perm_bp->inserted)
3750 internal_error (__FILE__, __LINE__,
3751 "allegedly permanent breakpoint is not "
3752 "actually inserted");
3758 internal_error (__FILE__, __LINE__,
3759 "another breakpoint was inserted on top of "
3760 "a permanent breakpoint");
3762 if (b->enable != disabled
3763 && b->enable != shlib_disabled
3764 && b->enable != call_disabled
3765 && b->address == address
3766 && (overlay_debugging == 0 || b->section == section))
3772 /* Low level routine to set a breakpoint.
3773 Takes as args the three things that every breakpoint must have.
3774 Returns the breakpoint object so caller can set other things.
3775 Does not set the breakpoint number!
3776 Does not print anything.
3778 ==> This routine should not be called if there is a chance of later
3779 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3780 your arguments BEFORE calling this routine! */
3783 set_raw_breakpoint (struct symtab_and_line sal)
3785 register struct breakpoint *b, *b1;
3787 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3788 memset (b, 0, sizeof (*b));
3789 b->address = sal.pc;
3790 if (sal.symtab == NULL)
3791 b->source_file = NULL;
3793 b->source_file = savestring (sal.symtab->filename,
3794 strlen (sal.symtab->filename));
3795 b->section = sal.section;
3796 b->language = current_language->la_language;
3797 b->input_radix = input_radix;
3799 b->line_number = sal.line;
3800 b->enable = enabled;
3803 b->ignore_count = 0;
3806 b->dll_pathname = NULL;
3807 b->triggered_dll_pathname = NULL;
3808 b->forked_inferior_pid = 0;
3809 b->exec_pathname = NULL;
3811 /* Add this breakpoint to the end of the chain
3812 so that a list of breakpoints will come out in order
3813 of increasing numbers. */
3815 b1 = breakpoint_chain;
3817 breakpoint_chain = b;
3825 check_duplicates (sal.pc, sal.section);
3826 breakpoints_changed ();
3832 /* Note that the breakpoint object B describes a permanent breakpoint
3833 instruction, hard-wired into the inferior's code. */
3835 make_breakpoint_permanent (struct breakpoint *b)
3837 b->enable = permanent;
3839 /* By definition, permanent breakpoints are already present in the code. */
3843 #ifdef GET_LONGJMP_TARGET
3846 create_longjmp_breakpoint (char *func_name)
3848 struct symtab_and_line sal;
3849 struct breakpoint *b;
3851 INIT_SAL (&sal); /* initialize to zeroes */
3852 if (func_name != NULL)
3854 struct minimal_symbol *m;
3856 m = lookup_minimal_symbol_text (func_name, NULL,
3857 (struct objfile *) NULL);
3859 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3863 sal.section = find_pc_overlay (sal.pc);
3864 b = set_raw_breakpoint (sal);
3868 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3869 b->disposition = donttouch;
3870 b->enable = disabled;
3873 b->addr_string = xstrdup (func_name);
3874 b->number = internal_breakpoint_number--;
3877 #endif /* #ifdef GET_LONGJMP_TARGET */
3879 /* Call this routine when stepping and nexting to enable a breakpoint
3880 if we do a longjmp(). When we hit that breakpoint, call
3881 set_longjmp_resume_breakpoint() to figure out where we are going. */
3884 enable_longjmp_breakpoint (void)
3886 register struct breakpoint *b;
3889 if (b->type == bp_longjmp)
3891 b->enable = enabled;
3892 check_duplicates (b->address, b->section);
3897 disable_longjmp_breakpoint (void)
3899 register struct breakpoint *b;
3902 if (b->type == bp_longjmp
3903 || b->type == bp_longjmp_resume)
3905 b->enable = disabled;
3906 check_duplicates (b->address, b->section);
3911 create_thread_event_breakpoint (CORE_ADDR address)
3913 struct breakpoint *b;
3914 struct symtab_and_line sal;
3915 char addr_string[80]; /* Surely an addr can't be longer than that. */
3917 INIT_SAL (&sal); /* initialize to zeroes */
3919 sal.section = find_pc_overlay (sal.pc);
3920 if ((b = set_raw_breakpoint (sal)) == NULL)
3923 b->number = internal_breakpoint_number--;
3924 b->disposition = donttouch;
3925 b->type = bp_thread_event; /* XXX: do we need a new type?
3927 b->enable = enabled;
3928 /* addr_string has to be used or breakpoint_re_set will delete me. */
3929 sprintf (addr_string, "*0x%s", paddr (b->address));
3930 b->addr_string = xstrdup (addr_string);
3936 remove_thread_event_breakpoints (void)
3938 struct breakpoint *b, *temp;
3940 ALL_BREAKPOINTS_SAFE (b, temp)
3941 if (b->type == bp_thread_event)
3942 delete_breakpoint (b);
3947 remove_solib_event_breakpoints (void)
3949 register struct breakpoint *b, *temp;
3951 ALL_BREAKPOINTS_SAFE (b, temp)
3952 if (b->type == bp_shlib_event)
3953 delete_breakpoint (b);
3957 create_solib_event_breakpoint (CORE_ADDR address)
3959 struct breakpoint *b;
3960 struct symtab_and_line sal;
3962 INIT_SAL (&sal); /* initialize to zeroes */
3964 sal.section = find_pc_overlay (sal.pc);
3965 b = set_raw_breakpoint (sal);
3966 b->number = internal_breakpoint_number--;
3967 b->disposition = donttouch;
3968 b->type = bp_shlib_event;
3973 /* Disable any breakpoints that are on code in shared libraries. Only
3974 apply to enabled breakpoints, disabled ones can just stay disabled. */
3977 disable_breakpoints_in_shlibs (int silent)
3979 struct breakpoint *b;
3980 int disabled_shlib_breaks = 0;
3982 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3985 #if defined (PC_SOLIB)
3986 if (((b->type == bp_breakpoint) ||
3987 (b->type == bp_hardware_breakpoint)) &&
3988 b->enable == enabled &&
3990 PC_SOLIB (b->address))
3992 b->enable = shlib_disabled;
3995 if (!disabled_shlib_breaks)
3997 target_terminal_ours_for_output ();
3998 warning ("Temporarily disabling shared library breakpoints:");
4000 disabled_shlib_breaks = 1;
4001 warning ("breakpoint #%d ", b->number);
4008 /* Try to reenable any breakpoints in shared libraries. */
4010 re_enable_breakpoints_in_shlibs (void)
4012 struct breakpoint *b;
4015 if (b->enable == shlib_disabled)
4019 /* Do not reenable the breakpoint if the shared library
4020 is still not mapped in. */
4021 if (target_read_memory (b->address, buf, 1) == 0)
4022 b->enable = enabled;
4029 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4030 char *cond_string, enum bptype bp_kind)
4032 struct breakpoint *b;
4033 struct symtabs_and_lines sals;
4034 struct cleanup *old_chain;
4035 struct cleanup *canonical_strings_chain = NULL;
4036 char *addr_start = hookname;
4037 char *addr_end = NULL;
4038 char **canonical = (char **) NULL;
4039 int thread = -1; /* All threads. */
4041 /* Set a breakpoint on the specified hook. */
4042 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4043 addr_end = hookname;
4045 if (sals.nelts == 0)
4047 warning ("Unable to set a breakpoint on dynamic linker callback.");
4048 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4049 warning ("GDB will be unable to track shl_load/shl_unload calls");
4052 if (sals.nelts != 1)
4054 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4055 warning ("GDB will be unable to track shl_load/shl_unload calls");
4059 /* Make sure that all storage allocated in decode_line_1 gets freed
4060 in case the following errors out. */
4061 old_chain = make_cleanup (xfree, sals.sals);
4062 if (canonical != (char **) NULL)
4064 make_cleanup (xfree, canonical);
4065 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4066 if (canonical[0] != NULL)
4067 make_cleanup (xfree, canonical[0]);
4070 resolve_sal_pc (&sals.sals[0]);
4072 /* Remove the canonical strings from the cleanup, they are needed below. */
4073 if (canonical != (char **) NULL)
4074 discard_cleanups (canonical_strings_chain);
4076 b = set_raw_breakpoint (sals.sals[0]);
4077 set_breakpoint_count (breakpoint_count + 1);
4078 b->number = breakpoint_count;
4080 b->cond_string = (cond_string == NULL) ?
4081 NULL : savestring (cond_string, strlen (cond_string));
4084 if (canonical != (char **) NULL && canonical[0] != NULL)
4085 b->addr_string = canonical[0];
4086 else if (addr_start)
4087 b->addr_string = savestring (addr_start, addr_end - addr_start);
4089 b->enable = enabled;
4090 b->disposition = tempflag ? del : donttouch;
4092 if (dll_pathname == NULL)
4093 b->dll_pathname = NULL;
4096 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4097 strcpy (b->dll_pathname, dll_pathname);
4102 do_cleanups (old_chain);
4106 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4107 char *dll_pathname, char *cond_string)
4109 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4110 cond_string, bp_catch_load);
4114 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4115 char *dll_pathname, char *cond_string)
4117 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4118 cond_string, bp_catch_unload);
4122 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4123 enum bptype bp_kind)
4125 struct symtab_and_line sal;
4126 struct breakpoint *b;
4127 int thread = -1; /* All threads. */
4134 b = set_raw_breakpoint (sal);
4135 set_breakpoint_count (breakpoint_count + 1);
4136 b->number = breakpoint_count;
4138 b->cond_string = (cond_string == NULL) ?
4139 NULL : savestring (cond_string, strlen (cond_string));
4141 b->addr_string = NULL;
4142 b->enable = enabled;
4143 b->disposition = tempflag ? del : donttouch;
4144 b->forked_inferior_pid = 0;
4152 create_fork_event_catchpoint (int tempflag, char *cond_string)
4154 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4158 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4160 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4164 create_exec_event_catchpoint (int tempflag, char *cond_string)
4166 struct symtab_and_line sal;
4167 struct breakpoint *b;
4168 int thread = -1; /* All threads. */
4175 b = set_raw_breakpoint (sal);
4176 set_breakpoint_count (breakpoint_count + 1);
4177 b->number = breakpoint_count;
4179 b->cond_string = (cond_string == NULL) ?
4180 NULL : savestring (cond_string, strlen (cond_string));
4182 b->addr_string = NULL;
4183 b->enable = enabled;
4184 b->disposition = tempflag ? del : donttouch;
4186 b->type = bp_catch_exec;
4192 hw_breakpoint_used_count (void)
4194 register struct breakpoint *b;
4199 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4207 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4209 register struct breakpoint *b;
4212 *other_type_used = 0;
4215 if (b->enable == enabled)
4217 if (b->type == type)
4219 else if ((b->type == bp_hardware_watchpoint ||
4220 b->type == bp_read_watchpoint ||
4221 b->type == bp_access_watchpoint)
4222 && b->enable == enabled)
4223 *other_type_used = 1;
4229 /* Call this after hitting the longjmp() breakpoint. Use this to set
4230 a new breakpoint at the target of the jmp_buf.
4232 FIXME - This ought to be done by setting a temporary breakpoint
4233 that gets deleted automatically... */
4236 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
4238 register struct breakpoint *b;
4241 if (b->type == bp_longjmp_resume)
4244 b->enable = enabled;
4246 b->frame = frame->frame;
4249 check_duplicates (b->address, b->section);
4255 disable_watchpoints_before_interactive_call_start (void)
4257 struct breakpoint *b;
4261 if (((b->type == bp_watchpoint)
4262 || (b->type == bp_hardware_watchpoint)
4263 || (b->type == bp_read_watchpoint)
4264 || (b->type == bp_access_watchpoint)
4265 || ep_is_exception_catchpoint (b))
4266 && (b->enable == enabled))
4268 b->enable = call_disabled;
4269 check_duplicates (b->address, b->section);
4275 enable_watchpoints_after_interactive_call_stop (void)
4277 struct breakpoint *b;
4281 if (((b->type == bp_watchpoint)
4282 || (b->type == bp_hardware_watchpoint)
4283 || (b->type == bp_read_watchpoint)
4284 || (b->type == bp_access_watchpoint)
4285 || ep_is_exception_catchpoint (b))
4286 && (b->enable == call_disabled))
4288 b->enable = enabled;
4289 check_duplicates (b->address, b->section);
4295 /* Set a breakpoint that will evaporate an end of command
4296 at address specified by SAL.
4297 Restrict it to frame FRAME if FRAME is nonzero. */
4300 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4303 register struct breakpoint *b;
4304 b = set_raw_breakpoint (sal);
4306 b->enable = enabled;
4307 b->disposition = donttouch;
4308 b->frame = (frame ? frame->frame : 0);
4310 /* If we're debugging a multi-threaded program, then we
4311 want momentary breakpoints to be active in only a
4312 single thread of control. */
4313 if (in_thread_list (inferior_pid))
4314 b->thread = pid_to_thread_id (inferior_pid);
4320 /* Tell the user we have just set a breakpoint B. */
4323 mention (struct breakpoint *b)
4327 struct cleanup *old_chain;
4328 struct ui_stream *stb;
4330 stb = ui_out_stream_new (uiout);
4331 old_chain = make_cleanup_ui_out_stream_delete (stb);
4334 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4335 watchpoint) other than breakpoint creation. It should be possible to
4336 clean this up and at the same time replace the random calls to
4337 breakpoint_changed with this hook, as has already been done for
4338 delete_breakpoint_hook and so on. */
4339 if (create_breakpoint_hook)
4340 create_breakpoint_hook (b);
4341 breakpoint_create_event (b->number);
4346 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4350 ui_out_text (uiout, "Watchpoint ");
4351 ui_out_list_begin (uiout, "wpt");
4352 ui_out_field_int (uiout, "number", b->number);
4353 ui_out_text (uiout, ": ");
4354 print_expression (b->exp, stb->stream);
4355 ui_out_field_stream (uiout, "exp", stb);
4356 ui_out_list_end (uiout);
4358 case bp_hardware_watchpoint:
4359 ui_out_text (uiout, "Hardware watchpoint ");
4360 ui_out_list_begin (uiout, "wpt");
4361 ui_out_field_int (uiout, "number", b->number);
4362 ui_out_text (uiout, ": ");
4363 print_expression (b->exp, stb->stream);
4364 ui_out_field_stream (uiout, "exp", stb);
4365 ui_out_list_end (uiout);
4369 printf_filtered ("Watchpoint %d: ", b->number);
4370 print_expression (b->exp, gdb_stdout);
4372 case bp_hardware_watchpoint:
4373 printf_filtered ("Hardware watchpoint %d: ", b->number);
4374 print_expression (b->exp, gdb_stdout);
4378 case bp_read_watchpoint:
4379 ui_out_text (uiout, "Hardware read watchpoint ");
4380 ui_out_list_begin (uiout, "hw-rwpt");
4381 ui_out_field_int (uiout, "number", b->number);
4382 ui_out_text (uiout, ": ");
4383 print_expression (b->exp, stb->stream);
4384 ui_out_field_stream (uiout, "exp", stb);
4385 ui_out_list_end (uiout);
4387 case bp_access_watchpoint:
4388 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4389 ui_out_list_begin (uiout, "hw-awpt");
4390 ui_out_field_int (uiout, "number", b->number);
4391 ui_out_text (uiout, ": ");
4392 print_expression (b->exp, stb->stream);
4393 ui_out_field_stream (uiout, "exp", stb);
4394 ui_out_list_end (uiout);
4397 case bp_read_watchpoint:
4398 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4399 print_expression (b->exp, gdb_stdout);
4401 case bp_access_watchpoint:
4402 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4404 print_expression (b->exp, gdb_stdout);
4409 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4415 printf_filtered ("Breakpoint %d", b->number);
4418 case bp_hardware_breakpoint:
4420 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4426 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4430 case bp_catch_unload:
4431 printf_filtered ("Catchpoint %d (%s %s)",
4433 (b->type == bp_catch_load) ? "load" : "unload",
4434 (b->dll_pathname != NULL) ?
4435 b->dll_pathname : "<any library>");
4438 case bp_catch_vfork:
4439 printf_filtered ("Catchpoint %d (%s)",
4441 (b->type == bp_catch_fork) ? "fork" : "vfork");
4444 printf_filtered ("Catchpoint %d (exec)",
4447 case bp_catch_catch:
4448 case bp_catch_throw:
4449 printf_filtered ("Catchpoint %d (%s)",
4451 (b->type == bp_catch_catch) ? "catch" : "throw");
4457 case bp_longjmp_resume:
4458 case bp_step_resume:
4459 case bp_through_sigtramp:
4461 case bp_watchpoint_scope:
4462 case bp_shlib_event:
4463 case bp_thread_event:
4468 if (addressprint || b->source_file == NULL)
4470 printf_filtered (" at ");
4471 print_address_numeric (b->address, 1, gdb_stdout);
4474 printf_filtered (": file %s, line %d.",
4475 b->source_file, b->line_number);
4476 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4477 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4480 do_cleanups (old_chain);
4483 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4486 printf_filtered ("\n");
4490 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4491 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4492 COND[i] and COND_STRING[i] values.
4494 NOTE: If the function succeeds, the caller is expected to cleanup
4495 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4496 array contents). If the function fails (error() is called), the
4497 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4498 COND and SALS arrays and each of those arrays contents. */
4501 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4502 struct expression **cond, char **cond_string,
4503 enum bptype type, enum bpdisp disposition,
4504 int thread, int ignore_count, int from_tty)
4506 if (type == bp_hardware_breakpoint)
4508 int i = hw_breakpoint_used_count ();
4509 int target_resources_ok =
4510 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4512 if (target_resources_ok == 0)
4513 error ("No hardware breakpoint support in the target.");
4514 else if (target_resources_ok < 0)
4515 error ("Hardware breakpoints used exceeds limit.");
4518 /* Now set all the breakpoints. */
4521 for (i = 0; i < sals.nelts; i++)
4523 struct breakpoint *b;
4524 struct symtab_and_line sal = sals.sals[i];
4527 describe_other_breakpoints (sal.pc, sal.section);
4529 b = set_raw_breakpoint (sal);
4530 set_breakpoint_count (breakpoint_count + 1);
4531 b->number = breakpoint_count;
4535 b->addr_string = addr_string[i];
4536 b->cond_string = cond_string[i];
4537 b->ignore_count = ignore_count;
4538 b->enable = enabled;
4539 b->disposition = disposition;
4545 /* Parse ARG which is assumed to be a SAL specification possibly
4546 followed by conditionals. On return, SALS contains an array of SAL
4547 addresses found. ADDR_STRING contains a vector of (canonical)
4548 address strings. ARG points to the end of the SAL. */
4551 parse_breakpoint_sals (char **address,
4552 struct symtabs_and_lines *sals,
4553 char ***addr_string)
4555 char *addr_start = *address;
4556 *addr_string = NULL;
4557 /* If no arg given, or if first arg is 'if ', use the default
4559 if ((*address) == NULL
4560 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4562 if (default_breakpoint_valid)
4564 struct symtab_and_line sal;
4565 INIT_SAL (&sal); /* initialize to zeroes */
4566 sals->sals = (struct symtab_and_line *)
4567 xmalloc (sizeof (struct symtab_and_line));
4568 sal.pc = default_breakpoint_address;
4569 sal.line = default_breakpoint_line;
4570 sal.symtab = default_breakpoint_symtab;
4571 sal.section = find_pc_overlay (sal.pc);
4572 sals->sals[0] = sal;
4576 error ("No default breakpoint address now.");
4580 /* Force almost all breakpoints to be in terms of the
4581 current_source_symtab (which is decode_line_1's default). This
4582 should produce the results we want almost all of the time while
4583 leaving default_breakpoint_* alone. */
4584 if (default_breakpoint_valid
4585 && (!current_source_symtab
4586 || (strchr ("+-", (*address)[0]) != NULL)))
4587 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4588 default_breakpoint_line, addr_string);
4590 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4592 /* For any SAL that didn't have a canonical string, fill one in. */
4593 if (sals->nelts > 0 && *addr_string == NULL)
4594 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4595 if (addr_start != (*address))
4598 for (i = 0; i < sals->nelts; i++)
4600 /* Add the string if not present. */
4601 if ((*addr_string)[i] == NULL)
4602 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4608 /* Convert each SAL into a real PC. Verify that the PC can be
4609 inserted as a breakpoint. If it can't throw an error. */
4612 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4616 for (i = 0; i < sals->nelts; i++)
4618 resolve_sal_pc (&sals->sals[i]);
4620 /* It's possible for the PC to be nonzero, but still an illegal
4621 value on some targets.
4623 For example, on HP-UX if you start gdb, and before running the
4624 inferior you try to set a breakpoint on a shared library function
4625 "foo" where the inferior doesn't call "foo" directly but does
4626 pass its address to another function call, then we do find a
4627 minimal symbol for the "foo", but it's address is invalid.
4628 (Appears to be an index into a table that the loader sets up
4629 when the inferior is run.)
4631 Give the target a chance to bless sals.sals[i].pc before we
4632 try to make a breakpoint for it. */
4633 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4635 if (address == NULL)
4636 error ("Cannot break without a running program.");
4638 error ("Cannot break on %s without a running program.",
4644 /* Set a breakpoint according to ARG (function, linenum or *address)
4645 flag: first bit : 0 non-temporary, 1 temporary.
4646 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4649 break_command_1 (char *arg, int flag, int from_tty)
4651 int tempflag, hardwareflag;
4652 struct symtabs_and_lines sals;
4653 register struct expression **cond = 0;
4654 /* Pointers in arg to the start, and one past the end, of the
4656 char **cond_string = (char **) NULL;
4657 char *addr_start = arg;
4659 struct cleanup *old_chain;
4660 struct cleanup *breakpoint_chain = NULL;
4663 int ignore_count = 0;
4665 hardwareflag = flag & BP_HARDWAREFLAG;
4666 tempflag = flag & BP_TEMPFLAG;
4671 parse_breakpoint_sals (&arg, &sals, &addr_string);
4676 /* Create a chain of things that always need to be cleaned up. */
4677 old_chain = make_cleanup (null_cleanup, 0);
4679 /* Make sure that all storage allocated to SALS gets freed. */
4680 make_cleanup (xfree, sals.sals);
4682 /* Cleanup the addr_string array but not its contents. */
4683 make_cleanup (xfree, addr_string);
4685 /* Allocate space for all the cond expressions. */
4686 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4687 make_cleanup (xfree, cond);
4689 /* Allocate space for all the cond strings. */
4690 cond_string = xcalloc (sals.nelts, sizeof (char **));
4691 make_cleanup (xfree, cond_string);
4693 /* ----------------------------- SNIP -----------------------------
4694 Anything added to the cleanup chain beyond this point is assumed
4695 to be part of a breakpoint. If the breakpoint create succeeds
4696 then the memory is not reclaimed. */
4697 breakpoint_chain = make_cleanup (null_cleanup, 0);
4699 /* Mark the contents of the addr_string for cleanup. These go on
4700 the breakpoint_chain and only occure if the breakpoint create
4702 for (i = 0; i < sals.nelts; i++)
4704 if (addr_string[i] != NULL)
4705 make_cleanup (xfree, addr_string[i]);
4708 /* Resolve all line numbers to PC's and verify that the addresses
4709 are ok for the target. */
4710 breakpoint_sals_to_pc (&sals, addr_start);
4712 /* Verify that condition can be parsed, before setting any
4713 breakpoints. Allocate a separate condition expression for each
4715 thread = -1; /* No specific thread yet */
4716 for (i = 0; i < sals.nelts; i++)
4723 char *cond_start = NULL;
4724 char *cond_end = NULL;
4725 while (*tok == ' ' || *tok == '\t')
4730 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4733 toklen = end_tok - tok;
4735 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4737 tok = cond_start = end_tok + 1;
4738 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4739 make_cleanup (xfree, cond[i]);
4741 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4742 make_cleanup (xfree, cond_string[i]);
4744 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4750 thread = strtol (tok, &tok, 0);
4752 error ("Junk after thread keyword.");
4753 if (!valid_thread_id (thread))
4754 error ("Unknown thread %d\n", thread);
4757 error ("Junk at end of arguments.");
4761 create_breakpoints (sals, addr_string, cond, cond_string,
4762 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4763 tempflag ? del : donttouch,
4764 thread, ignore_count, from_tty);
4768 warning ("Multiple breakpoints were set.");
4769 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4771 /* That's it. Discard the cleanups for data inserted into the
4773 discard_cleanups (breakpoint_chain);
4774 /* But cleanup everything else. */
4775 do_cleanups (old_chain);
4778 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4779 linenum or *address) with COND and IGNORE_COUNT. */
4781 struct captured_breakpoint_args
4792 do_captured_breakpoint (void *data)
4794 struct captured_breakpoint_args *args = data;
4795 struct symtabs_and_lines sals;
4796 register struct expression **cond;
4797 struct cleanup *old_chain;
4798 struct cleanup *breakpoint_chain = NULL;
4805 /* Parse the source and lines spec. Delay check that the expression
4806 didn't contain trailing garbage until after cleanups are in
4810 address_end = args->address;
4812 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4817 /* Create a chain of things at always need to be cleaned up. */
4818 old_chain = make_cleanup (null_cleanup, 0);
4820 /* Always have a addr_string array, even if it is empty. */
4821 make_cleanup (xfree, addr_string);
4823 /* Make sure that all storage allocated to SALS gets freed. */
4824 make_cleanup (xfree, sals.sals);
4826 /* Allocate space for all the cond expressions. */
4827 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4828 make_cleanup (xfree, cond);
4830 /* Allocate space for all the cond strings. */
4831 cond_string = xcalloc (sals.nelts, sizeof (char **));
4832 make_cleanup (xfree, cond_string);
4834 /* ----------------------------- SNIP -----------------------------
4835 Anything added to the cleanup chain beyond this point is assumed
4836 to be part of a breakpoint. If the breakpoint create goes
4837 through then that memory is not cleaned up. */
4838 breakpoint_chain = make_cleanup (null_cleanup, 0);
4840 /* Mark the contents of the addr_string for cleanup. These go on
4841 the breakpoint_chain and only occure if the breakpoint create
4843 for (i = 0; i < sals.nelts; i++)
4845 if (addr_string[i] != NULL)
4846 make_cleanup (xfree, addr_string[i]);
4849 /* Wait until now before checking for garbage at the end of the
4850 address. That way cleanups can take care of freeing any
4852 if (*address_end != '\0')
4853 error ("Garbage %s following breakpoint address", address_end);
4855 /* Resolve all line numbers to PC's. */
4856 breakpoint_sals_to_pc (&sals, args->address);
4858 /* Verify that conditions can be parsed, before setting any
4860 for (i = 0; i < sals.nelts; i++)
4862 if (args->condition != NULL)
4864 char *tok = args->condition;
4865 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4867 error ("Garbage %s follows condition", tok);
4868 make_cleanup (xfree, cond[i]);
4869 cond_string[i] = xstrdup (args->condition);
4873 create_breakpoints (sals, addr_string, cond, cond_string,
4874 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4875 args->tempflag ? del : donttouch,
4876 args->thread, args->ignore_count, 0/*from-tty*/);
4878 /* That's it. Discard the cleanups for data inserted into the
4880 discard_cleanups (breakpoint_chain);
4881 /* But cleanup everything else. */
4882 do_cleanups (old_chain);
4887 gdb_breakpoint (char *address, char *condition,
4888 int hardwareflag, int tempflag,
4889 int thread, int ignore_count)
4891 struct captured_breakpoint_args args;
4892 args.address = address;
4893 args.condition = condition;
4894 args.hardwareflag = hardwareflag;
4895 args.tempflag = tempflag;
4896 args.thread = thread;
4897 args.ignore_count = ignore_count;
4898 return catch_errors (do_captured_breakpoint, &args,
4899 NULL, RETURN_MASK_ALL);
4904 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4906 struct frame_info *frame;
4907 CORE_ADDR low, high, selected_pc = 0;
4908 char *extra_args = NULL;
4911 int extra_args_len = 0, if_arg = 0;
4914 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4917 if (default_breakpoint_valid)
4921 selected_pc = selected_frame->pc;
4926 error ("No selected frame.");
4929 error ("No default breakpoint address now.");
4933 extra_args = strchr (arg, ' ');
4937 extra_args_len = strlen (extra_args);
4938 level_arg = (char *) xmalloc (extra_args - arg);
4939 strncpy (level_arg, arg, extra_args - arg - 1);
4940 level_arg[extra_args - arg - 1] = '\0';
4944 level_arg = (char *) xmalloc (strlen (arg) + 1);
4945 strcpy (level_arg, arg);
4948 frame = parse_frame_specification (level_arg);
4950 selected_pc = frame->pc;
4957 extra_args_len = strlen (arg);
4962 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4964 addr_string = (char *) xmalloc (26 + extra_args_len);
4966 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4968 sprintf (addr_string, "*0x%s", paddr_nz (high));
4969 break_command_1 (addr_string, flag, from_tty);
4970 xfree (addr_string);
4973 error ("No function contains the specified address");
4976 error ("Unable to set breakpoint at procedure exit");
4981 break_at_finish_command_1 (char *arg, int flag, int from_tty)
4983 char *addr_string, *break_string, *beg_addr_string;
4984 CORE_ADDR low, high;
4985 struct symtabs_and_lines sals;
4986 struct symtab_and_line sal;
4987 struct cleanup *old_chain;
4988 char *extra_args = NULL;
4989 int extra_args_len = 0;
4993 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4995 if (default_breakpoint_valid)
4999 addr_string = (char *) xmalloc (15);
5000 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5005 error ("No selected frame.");
5008 error ("No default breakpoint address now.");
5012 addr_string = (char *) xmalloc (strlen (arg) + 1);
5013 strcpy (addr_string, arg);
5019 extra_args_len = strlen (arg);
5023 /* get the stuff after the function name or address */
5024 extra_args = strchr (arg, ' ');
5028 extra_args_len = strlen (extra_args);
5035 beg_addr_string = addr_string;
5036 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5039 xfree (beg_addr_string);
5040 old_chain = make_cleanup (xfree, sals.sals);
5041 for (i = 0; (i < sals.nelts); i++)
5044 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5046 break_string = (char *) xmalloc (extra_args_len + 26);
5048 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5050 sprintf (break_string, "*0x%s", paddr_nz (high));
5051 break_command_1 (break_string, flag, from_tty);
5052 xfree (break_string);
5055 error ("No function contains the specified address");
5059 warning ("Multiple breakpoints were set.\n");
5060 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5062 do_cleanups (old_chain);
5066 /* Helper function for break_command_1 and disassemble_command. */
5069 resolve_sal_pc (struct symtab_and_line *sal)
5073 if (sal->pc == 0 && sal->symtab != NULL)
5075 if (!find_line_pc (sal->symtab, sal->line, &pc))
5076 error ("No line %d in file \"%s\".",
5077 sal->line, sal->symtab->filename);
5081 if (sal->section == 0 && sal->symtab != NULL)
5083 struct blockvector *bv;
5088 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5091 b = BLOCKVECTOR_BLOCK (bv, index);
5092 sym = block_function (b);
5095 fixup_symbol_section (sym, sal->symtab->objfile);
5096 sal->section = SYMBOL_BFD_SECTION (sym);
5100 /* It really is worthwhile to have the section, so we'll just
5101 have to look harder. This case can be executed if we have
5102 line numbers but no functions (as can happen in assembly
5105 struct minimal_symbol *msym;
5107 msym = lookup_minimal_symbol_by_pc (sal->pc);
5109 sal->section = SYMBOL_BFD_SECTION (msym);
5116 break_command (char *arg, int from_tty)
5118 break_command_1 (arg, 0, from_tty);
5122 break_at_finish_command (char *arg, int from_tty)
5124 break_at_finish_command_1 (arg, 0, from_tty);
5128 break_at_finish_at_depth_command (char *arg, int from_tty)
5130 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5134 tbreak_command (char *arg, int from_tty)
5136 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5140 tbreak_at_finish_command (char *arg, int from_tty)
5142 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5146 hbreak_command (char *arg, int from_tty)
5148 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5152 thbreak_command (char *arg, int from_tty)
5154 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5158 stop_command (char *arg, int from_tty)
5160 printf_filtered ("Specify the type of breakpoint to set.\n\
5161 Usage: stop in <function | address>\n\
5166 stopin_command (char *arg, int from_tty)
5170 if (arg == (char *) NULL)
5172 else if (*arg != '*')
5177 /* look for a ':'. If this is a line number specification, then
5178 say it is bad, otherwise, it should be an address or
5179 function/method name */
5180 while (*argptr && !hasColon)
5182 hasColon = (*argptr == ':');
5187 badInput = (*argptr != ':'); /* Not a class::method */
5189 badInput = isdigit (*arg); /* a simple line number */
5193 printf_filtered ("Usage: stop in <function | address>\n");
5195 break_command_1 (arg, 0, from_tty);
5199 stopat_command (char *arg, int from_tty)
5203 if (arg == (char *) NULL || *arg == '*') /* no line number */
5210 /* look for a ':'. If there is a '::' then get out, otherwise
5211 it is probably a line number. */
5212 while (*argptr && !hasColon)
5214 hasColon = (*argptr == ':');
5219 badInput = (*argptr == ':'); /* we have class::method */
5221 badInput = !isdigit (*arg); /* not a line number */
5225 printf_filtered ("Usage: stop at <line>\n");
5227 break_command_1 (arg, 0, from_tty);
5231 /* accessflag: hw_write: watch write,
5232 hw_read: watch read,
5233 hw_access: watch access (read or write) */
5235 watch_command_1 (char *arg, int accessflag, int from_tty)
5237 struct breakpoint *b;
5238 struct symtab_and_line sal;
5239 struct expression *exp;
5240 struct block *exp_valid_block;
5241 struct value *val, *mark;
5242 struct frame_info *frame;
5243 struct frame_info *prev_frame = NULL;
5244 char *exp_start = NULL;
5245 char *exp_end = NULL;
5246 char *tok, *end_tok;
5248 char *cond_start = NULL;
5249 char *cond_end = NULL;
5250 struct expression *cond = NULL;
5251 int i, other_type_used, target_resources_ok = 0;
5252 enum bptype bp_type;
5255 INIT_SAL (&sal); /* initialize to zeroes */
5257 /* Parse arguments. */
5258 innermost_block = NULL;
5260 exp = parse_exp_1 (&arg, 0, 0);
5262 exp_valid_block = innermost_block;
5263 mark = value_mark ();
5264 val = evaluate_expression (exp);
5265 release_value (val);
5266 if (VALUE_LAZY (val))
5267 value_fetch_lazy (val);
5270 while (*tok == ' ' || *tok == '\t')
5274 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5277 toklen = end_tok - tok;
5278 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5280 tok = cond_start = end_tok + 1;
5281 cond = parse_exp_1 (&tok, 0, 0);
5285 error ("Junk at end of command.");
5287 if (accessflag == hw_read)
5288 bp_type = bp_read_watchpoint;
5289 else if (accessflag == hw_access)
5290 bp_type = bp_access_watchpoint;
5292 bp_type = bp_hardware_watchpoint;
5294 mem_cnt = can_use_hardware_watchpoint (val);
5295 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5296 error ("Expression cannot be implemented with read/access watchpoint.");
5299 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5300 target_resources_ok =
5301 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5303 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5304 error ("Target does not support this type of hardware watchpoint.");
5306 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5307 error ("Target can only support one kind of HW watchpoint at a time.");
5310 #if defined(HPUXHPPA)
5311 /* On HP-UX if you set a h/w
5312 watchpoint before the "run" command, the inferior dies with a e.g.,
5313 SIGILL once you start it. I initially believed this was due to a
5314 bad interaction between page protection traps and the initial
5315 startup sequence by the dynamic linker.
5317 However, I tried avoiding that by having HP-UX's implementation of
5318 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
5319 yet, which forced slow watches before a "run" or "attach", and it
5320 still fails somewhere in the startup code.
5322 Until I figure out what's happening, I'm disallowing watches altogether
5323 before the "run" or "attach" command. We'll tell the user they must
5324 set watches after getting the program started. */
5325 if (!target_has_execution)
5327 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5330 #endif /* HPUXHPPA */
5332 /* Now set up the breakpoint. */
5333 b = set_raw_breakpoint (sal);
5334 set_breakpoint_count (breakpoint_count + 1);
5335 b->number = breakpoint_count;
5336 b->disposition = donttouch;
5338 b->exp_valid_block = exp_valid_block;
5339 b->exp_string = savestring (exp_start, exp_end - exp_start);
5343 b->cond_string = savestring (cond_start, cond_end - cond_start);
5347 frame = block_innermost_frame (exp_valid_block);
5350 prev_frame = get_prev_frame (frame);
5351 b->watchpoint_frame = frame->frame;
5354 b->watchpoint_frame = (CORE_ADDR) 0;
5356 if (mem_cnt && target_resources_ok > 0)
5359 b->type = bp_watchpoint;
5361 /* If the expression is "local", then set up a "watchpoint scope"
5362 breakpoint at the point where we've left the scope of the watchpoint
5364 if (innermost_block)
5368 struct breakpoint *scope_breakpoint;
5369 struct symtab_and_line scope_sal;
5371 INIT_SAL (&scope_sal); /* initialize to zeroes */
5372 scope_sal.pc = get_frame_pc (prev_frame);
5373 scope_sal.section = find_pc_overlay (scope_sal.pc);
5375 scope_breakpoint = set_raw_breakpoint (scope_sal);
5376 set_breakpoint_count (breakpoint_count + 1);
5377 scope_breakpoint->number = breakpoint_count;
5379 scope_breakpoint->type = bp_watchpoint_scope;
5380 scope_breakpoint->enable = enabled;
5382 /* Automatically delete the breakpoint when it hits. */
5383 scope_breakpoint->disposition = del;
5385 /* Only break in the proper frame (help with recursion). */
5386 scope_breakpoint->frame = prev_frame->frame;
5388 /* Set the address at which we will stop. */
5389 scope_breakpoint->address = get_frame_pc (prev_frame);
5391 /* The scope breakpoint is related to the watchpoint. We
5392 will need to act on them together. */
5393 b->related_breakpoint = scope_breakpoint;
5396 value_free_to_mark (mark);
5400 /* Return count of locations need to be watched and can be handled
5401 in hardware. If the watchpoint can not be handled
5402 in hardware return zero. */
5404 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5405 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5406 ((BYTE_SIZE) <= (REGISTER_SIZE))
5409 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5410 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5411 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5415 can_use_hardware_watchpoint (struct value *v)
5417 int found_memory_cnt = 0;
5418 struct value *head = v;
5420 /* Did the user specifically forbid us to use hardware watchpoints? */
5421 if (!can_use_hw_watchpoints)
5424 /* Make sure that the value of the expression depends only upon
5425 memory contents, and values computed from them within GDB. If we
5426 find any register references or function calls, we can't use a
5427 hardware watchpoint.
5429 The idea here is that evaluating an expression generates a series
5430 of values, one holding the value of every subexpression. (The
5431 expression a*b+c has five subexpressions: a, b, a*b, c, and
5432 a*b+c.) GDB's values hold almost enough information to establish
5433 the criteria given above --- they identify memory lvalues,
5434 register lvalues, computed values, etcetera. So we can evaluate
5435 the expression, and then scan the chain of values that leaves
5436 behind to decide whether we can detect any possible change to the
5437 expression's final value using only hardware watchpoints.
5439 However, I don't think that the values returned by inferior
5440 function calls are special in any way. So this function may not
5441 notice that an expression involving an inferior function call
5442 can't be watched with hardware watchpoints. FIXME. */
5443 for (; v; v = v->next)
5445 if (VALUE_LVAL (v) == lval_memory)
5448 /* A lazy memory lvalue is one that GDB never needed to fetch;
5449 we either just used its address (e.g., `a' in `a.b') or
5450 we never needed it at all (e.g., `a' in `a,b'). */
5454 /* Ahh, memory we actually used! Check if we can cover
5455 it with hardware watchpoints. */
5456 struct type *vtype = check_typedef (VALUE_TYPE (v));
5458 /* We only watch structs and arrays if user asked for it
5459 explicitly, never if they just happen to appear in a
5460 middle of some value chain. */
5462 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5463 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5465 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5466 int len = TYPE_LENGTH (VALUE_TYPE (v));
5468 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5475 else if (v->lval != not_lval && v->modifiable == 0)
5476 return 0; /* ??? What does this represent? */
5477 else if (v->lval == lval_register)
5478 return 0; /* cannot watch a register with a HW watchpoint */
5481 /* The expression itself looks suitable for using a hardware
5482 watchpoint, but give the target machine a chance to reject it. */
5483 return found_memory_cnt;
5488 watch_command_wrapper (char *arg, int from_tty)
5490 watch_command (arg, from_tty);
5494 watch_command (char *arg, int from_tty)
5496 watch_command_1 (arg, hw_write, from_tty);
5501 rwatch_command_wrapper (char *arg, int from_tty)
5503 rwatch_command (arg, from_tty);
5507 rwatch_command (char *arg, int from_tty)
5509 watch_command_1 (arg, hw_read, from_tty);
5514 awatch_command_wrapper (char *arg, int from_tty)
5516 awatch_command (arg, from_tty);
5520 awatch_command (char *arg, int from_tty)
5522 watch_command_1 (arg, hw_access, from_tty);
5526 /* Helper routines for the until_command routine in infcmd.c. Here
5527 because it uses the mechanisms of breakpoints. */
5529 /* This function is called by fetch_inferior_event via the
5530 cmd_continuation pointer, to complete the until command. It takes
5531 care of cleaning up the temporary breakpoints set up by the until
5534 until_break_command_continuation (struct continuation_arg *arg)
5536 struct cleanup *cleanups;
5538 cleanups = (struct cleanup *) arg->data.pointer;
5539 do_exec_cleanups (cleanups);
5544 until_break_command (char *arg, int from_tty)
5546 struct symtabs_and_lines sals;
5547 struct symtab_and_line sal;
5548 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5549 struct breakpoint *breakpoint;
5550 struct cleanup *old_chain;
5551 struct continuation_arg *arg1;
5554 clear_proceed_status ();
5556 /* Set a breakpoint where the user wants it and at return from
5559 if (default_breakpoint_valid)
5560 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5561 default_breakpoint_line, (char ***) NULL);
5563 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5564 0, (char ***) NULL);
5566 if (sals.nelts != 1)
5567 error ("Couldn't get information on specified line.");
5570 xfree (sals.sals); /* malloc'd, so freed */
5573 error ("Junk at end of arguments.");
5575 resolve_sal_pc (&sal);
5577 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5579 if (!event_loop_p || !target_can_async_p ())
5580 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5582 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5584 /* If we are running asynchronously, and the target supports async
5585 execution, we are not waiting for the target to stop, in the call
5586 tp proceed, below. This means that we cannot delete the
5587 brekpoints until the target has actually stopped. The only place
5588 where we get a chance to do that is in fetch_inferior_event, so
5589 we must set things up for that. */
5591 if (event_loop_p && target_can_async_p ())
5593 /* In this case the arg for the continuation is just the point
5594 in the exec_cleanups chain from where to start doing
5595 cleanups, because all the continuation does is the cleanups in
5596 the exec_cleanup_chain. */
5598 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5600 arg1->data.pointer = old_chain;
5602 add_continuation (until_break_command_continuation, arg1);
5605 /* Keep within the current frame */
5609 sal = find_pc_line (prev_frame->pc, 0);
5610 sal.pc = prev_frame->pc;
5611 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5612 if (!event_loop_p || !target_can_async_p ())
5613 make_cleanup_delete_breakpoint (breakpoint);
5615 make_exec_cleanup_delete_breakpoint (breakpoint);
5618 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5619 /* Do the cleanups now, anly if we are not running asynchronously,
5620 of if we are, but the target is still synchronous. */
5621 if (!event_loop_p || !target_can_async_p ())
5622 do_cleanups (old_chain);
5626 /* These aren't used; I don't konw what they were for. */
5627 /* Set a breakpoint at the catch clause for NAME. */
5629 catch_breakpoint (char *name)
5634 disable_catch_breakpoint (void)
5639 delete_catch_breakpoint (void)
5644 enable_catch_breakpoint (void)
5651 struct sal_chain *next;
5652 struct symtab_and_line sal;
5656 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5657 had been commented out in the v.4.16 sources, and stays
5658 disabled there now because "catch NAME" syntax isn't allowed.
5660 /* This isn't used; I don't know what it was for. */
5661 /* For each catch clause identified in ARGS, run FUNCTION
5662 with that clause as an argument. */
5663 static struct symtabs_and_lines
5664 map_catch_names (char *args, int (*function) ())
5666 register char *p = args;
5668 struct symtabs_and_lines sals;
5670 struct sal_chain *sal_chain = 0;
5674 error_no_arg ("one or more catch names");
5682 /* Don't swallow conditional part. */
5683 if (p1[0] == 'i' && p1[1] == 'f'
5684 && (p1[2] == ' ' || p1[2] == '\t'))
5690 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5694 if (*p1 && *p1 != ' ' && *p1 != '\t')
5695 error ("Arguments must be catch names.");
5701 struct sal_chain *next = (struct sal_chain *)
5702 alloca (sizeof (struct sal_chain));
5703 next->next = sal_chain;
5704 next->sal = get_catch_sal (p);
5709 printf_unfiltered ("No catch clause for exception %s.\n", p);
5714 while (*p == ' ' || *p == '\t')
5720 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5722 static struct symtabs_and_lines
5723 get_catch_sals (int this_level_only)
5725 register struct blockvector *bl;
5726 register struct block *block;
5727 int index, have_default = 0;
5729 struct symtabs_and_lines sals;
5730 struct sal_chain *sal_chain = 0;
5731 char *blocks_searched;
5733 /* Not sure whether an error message is always the correct response,
5734 but it's better than a core dump. */
5735 if (selected_frame == NULL)
5736 error ("No selected frame.");
5737 block = get_frame_block (selected_frame);
5738 pc = selected_frame->pc;
5744 error ("No symbol table info available.\n");
5746 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5747 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5748 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5752 CORE_ADDR end = BLOCK_END (block) - 4;
5755 if (bl != blockvector_for_pc (end, &index))
5756 error ("blockvector blotch");
5757 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5758 error ("blockvector botch");
5759 last_index = BLOCKVECTOR_NBLOCKS (bl);
5762 /* Don't print out blocks that have gone by. */
5763 while (index < last_index
5764 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5767 while (index < last_index
5768 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5770 if (blocks_searched[index] == 0)
5772 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5775 register struct symbol *sym;
5777 nsyms = BLOCK_NSYMS (b);
5779 for (i = 0; i < nsyms; i++)
5781 sym = BLOCK_SYM (b, i);
5782 if (STREQ (SYMBOL_NAME (sym), "default"))
5788 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5790 struct sal_chain *next = (struct sal_chain *)
5791 alloca (sizeof (struct sal_chain));
5792 next->next = sal_chain;
5793 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5798 blocks_searched[index] = 1;
5804 if (sal_chain && this_level_only)
5807 /* After handling the function's top-level block, stop.
5808 Don't continue to its superblock, the block of
5809 per-file symbols. */
5810 if (BLOCK_FUNCTION (block))
5812 block = BLOCK_SUPERBLOCK (block);
5817 struct sal_chain *tmp_chain;
5819 /* Count the number of entries. */
5820 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5821 tmp_chain = tmp_chain->next)
5825 sals.sals = (struct symtab_and_line *)
5826 xmalloc (index * sizeof (struct symtab_and_line));
5827 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5828 sals.sals[index] = sal_chain->sal;
5835 ep_skip_leading_whitespace (char **s)
5837 if ((s == NULL) || (*s == NULL))
5839 while (isspace (**s))
5843 /* This function examines a string, and attempts to find a token
5844 that might be an event name in the leading characters. If a
5845 possible match is found, a pointer to the last character of
5846 the token is returned. Else, NULL is returned. */
5849 ep_find_event_name_end (char *arg)
5852 char *event_name_end = NULL;
5854 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5858 /* We break out of the loop when we find a token delimiter.
5859 Basically, we're looking for alphanumerics and underscores;
5860 anything else delimites the token. */
5863 if (!isalnum (*s) && (*s != '_'))
5869 return event_name_end;
5873 /* This function attempts to parse an optional "if <cond>" clause
5874 from the arg string. If one is not found, it returns NULL.
5876 Else, it returns a pointer to the condition string. (It does not
5877 attempt to evaluate the string against a particular block.) And,
5878 it updates arg to point to the first character following the parsed
5879 if clause in the arg string. */
5882 ep_parse_optional_if_clause (char **arg)
5886 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5889 /* Skip the "if" keyword. */
5892 /* Skip any extra leading whitespace, and record the start of the
5893 condition string. */
5894 ep_skip_leading_whitespace (arg);
5897 /* Assume that the condition occupies the remainder of the arg string. */
5898 (*arg) += strlen (cond_string);
5903 /* This function attempts to parse an optional filename from the arg
5904 string. If one is not found, it returns NULL.
5906 Else, it returns a pointer to the parsed filename. (This function
5907 makes no attempt to verify that a file of that name exists, or is
5908 accessible.) And, it updates arg to point to the first character
5909 following the parsed filename in the arg string.
5911 Note that clients needing to preserve the returned filename for
5912 future access should copy it to their own buffers. */
5914 ep_parse_optional_filename (char **arg)
5916 static char filename[1024];
5921 if ((*arg_p == '\0') || isspace (*arg_p))
5939 /* Commands to deal with catching events, such as signals, exceptions,
5940 process start/exit, etc. */
5944 catch_fork, catch_vfork
5948 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5949 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5950 char *arg, int tempflag, int from_tty);
5953 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5956 char *cond_string = NULL;
5958 ep_skip_leading_whitespace (&arg);
5960 /* The allowed syntax is:
5962 catch [v]fork if <cond>
5964 First, check if there's an if clause. */
5965 cond_string = ep_parse_optional_if_clause (&arg);
5967 if ((*arg != '\0') && !isspace (*arg))
5968 error ("Junk at end of arguments.");
5970 /* If this target supports it, create a fork or vfork catchpoint
5971 and enable reporting of such events. */
5975 create_fork_event_catchpoint (tempflag, cond_string);
5978 create_vfork_event_catchpoint (tempflag, cond_string);
5981 error ("unsupported or unknown fork kind; cannot catch it");
5987 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5989 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
5991 char *cond_string = NULL;
5993 ep_skip_leading_whitespace (&arg);
5995 /* The allowed syntax is:
5997 catch exec if <cond>
5999 First, check if there's an if clause. */
6000 cond_string = ep_parse_optional_if_clause (&arg);
6002 if ((*arg != '\0') && !isspace (*arg))
6003 error ("Junk at end of arguments.");
6005 /* If this target supports it, create an exec catchpoint
6006 and enable reporting of such events. */
6007 create_exec_event_catchpoint (tempflag, cond_string);
6011 #if defined(SOLIB_ADD)
6013 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6015 char *dll_pathname = NULL;
6016 char *cond_string = NULL;
6018 ep_skip_leading_whitespace (&arg);
6020 /* The allowed syntax is:
6022 catch load if <cond>
6023 catch load <filename>
6024 catch load <filename> if <cond>
6026 The user is not allowed to specify the <filename> after an
6029 We'll ignore the pathological case of a file named "if".
6031 First, check if there's an if clause. If so, then there
6032 cannot be a filename. */
6033 cond_string = ep_parse_optional_if_clause (&arg);
6035 /* If there was an if clause, then there cannot be a filename.
6036 Else, there might be a filename and an if clause. */
6037 if (cond_string == NULL)
6039 dll_pathname = ep_parse_optional_filename (&arg);
6040 ep_skip_leading_whitespace (&arg);
6041 cond_string = ep_parse_optional_if_clause (&arg);
6044 if ((*arg != '\0') && !isspace (*arg))
6045 error ("Junk at end of arguments.");
6047 /* Create a load breakpoint that only triggers when a load of
6048 the specified dll (or any dll, if no pathname was specified)
6050 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
6051 dll_pathname, cond_string);
6055 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6057 char *dll_pathname = NULL;
6058 char *cond_string = NULL;
6060 ep_skip_leading_whitespace (&arg);
6062 /* The allowed syntax is:
6064 catch unload if <cond>
6065 catch unload <filename>
6066 catch unload <filename> if <cond>
6068 The user is not allowed to specify the <filename> after an
6071 We'll ignore the pathological case of a file named "if".
6073 First, check if there's an if clause. If so, then there
6074 cannot be a filename. */
6075 cond_string = ep_parse_optional_if_clause (&arg);
6077 /* If there was an if clause, then there cannot be a filename.
6078 Else, there might be a filename and an if clause. */
6079 if (cond_string == NULL)
6081 dll_pathname = ep_parse_optional_filename (&arg);
6082 ep_skip_leading_whitespace (&arg);
6083 cond_string = ep_parse_optional_if_clause (&arg);
6086 if ((*arg != '\0') && !isspace (*arg))
6087 error ("Junk at end of arguments.");
6089 /* Create an unload breakpoint that only triggers when an unload of
6090 the specified dll (or any dll, if no pathname was specified)
6092 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
6093 dll_pathname, cond_string);
6095 #endif /* SOLIB_ADD */
6097 /* Commands to deal with catching exceptions. */
6099 /* Set a breakpoint at the specified callback routine for an
6100 exception event callback */
6103 create_exception_catchpoint (int tempflag, char *cond_string,
6104 enum exception_event_kind ex_event,
6105 struct symtab_and_line *sal)
6107 struct breakpoint *b;
6108 int thread = -1; /* All threads. */
6110 if (!sal) /* no exception support? */
6113 b = set_raw_breakpoint (*sal);
6114 set_breakpoint_count (breakpoint_count + 1);
6115 b->number = breakpoint_count;
6117 b->cond_string = (cond_string == NULL) ?
6118 NULL : savestring (cond_string, strlen (cond_string));
6120 b->addr_string = NULL;
6121 b->enable = enabled;
6122 b->disposition = tempflag ? del : donttouch;
6125 case EX_EVENT_THROW:
6126 b->type = bp_catch_throw;
6128 case EX_EVENT_CATCH:
6129 b->type = bp_catch_catch;
6131 default: /* error condition */
6133 b->enable = disabled;
6134 error ("Internal error -- invalid catchpoint kind");
6139 /* Deal with "catch catch" and "catch throw" commands */
6142 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6143 int tempflag, int from_tty)
6145 char *cond_string = NULL;
6146 struct symtab_and_line *sal = NULL;
6148 ep_skip_leading_whitespace (&arg);
6150 cond_string = ep_parse_optional_if_clause (&arg);
6152 if ((*arg != '\0') && !isspace (*arg))
6153 error ("Junk at end of arguments.");
6155 if ((ex_event != EX_EVENT_THROW) &&
6156 (ex_event != EX_EVENT_CATCH))
6157 error ("Unsupported or unknown exception event; cannot catch it");
6159 /* See if we can find a callback routine */
6160 sal = target_enable_exception_callback (ex_event, 1);
6164 /* We have callbacks from the runtime system for exceptions.
6165 Set a breakpoint on the sal found, if no errors */
6166 if (sal != (struct symtab_and_line *) -1)
6167 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6169 return; /* something went wrong with setting up callbacks */
6173 /* No callbacks from runtime system for exceptions.
6174 Try GNU C++ exception breakpoints using labels in debug info. */
6175 if (ex_event == EX_EVENT_CATCH)
6177 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6179 else if (ex_event == EX_EVENT_THROW)
6181 /* Set a breakpoint on __raise_exception () */
6183 warning ("Unsupported with this platform/compiler combination.");
6184 warning ("Perhaps you can achieve the effect you want by setting");
6185 warning ("a breakpoint on __raise_exception().");
6190 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6191 inside a catch_errors */
6194 cover_target_enable_exception_callback (PTR arg)
6196 args_for_catchpoint_enable *args = arg;
6197 struct symtab_and_line *sal;
6198 sal = target_enable_exception_callback (args->kind, args->enable);
6201 else if (sal == (struct symtab_and_line *) -1)
6204 return 1; /*is valid */
6209 /* This is the original v.4.16 and earlier version of the
6210 catch_command_1() function. Now that other flavours of "catch"
6211 have been introduced, and since exception handling can be handled
6212 in other ways (through target ops) also, this is used only for the
6213 GNU C++ exception handling system.
6214 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6215 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6216 there was no code in GDB 4.16 for "catch throw".
6218 Called from catch_exception_command_1 () */
6222 handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
6224 /* First, translate ARG into something we can deal with in terms
6227 struct symtabs_and_lines sals;
6228 struct symtab_and_line sal;
6229 register struct expression *cond = 0;
6230 register struct breakpoint *b;
6234 INIT_SAL (&sal); /* initialize to zeroes */
6236 /* If no arg given, or if first arg is 'if ', all active catch clauses
6237 are breakpointed. */
6239 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6240 && (arg[2] == ' ' || arg[2] == '\t')))
6242 /* Grab all active catch clauses. */
6243 sals = get_catch_sals (0);
6247 /* Grab selected catch clauses. */
6248 error ("catch NAME not implemented");
6251 /* Not sure why this code has been disabled. I'm leaving
6252 it disabled. We can never come here now anyway
6253 since we don't allow the "catch NAME" syntax.
6256 /* This isn't used; I don't know what it was for. */
6257 sals = map_catch_names (arg, catch_breakpoint);
6265 for (i = 0; i < sals.nelts; i++)
6267 resolve_sal_pc (&sals.sals[i]);
6271 if (arg[0] == 'i' && arg[1] == 'f'
6272 && (arg[2] == ' ' || arg[2] == '\t'))
6273 cond = parse_exp_1 ((arg += 2, &arg),
6274 block_for_pc (sals.sals[i].pc), 0);
6276 error ("Junk at end of arguments.");
6281 for (i = 0; i < sals.nelts; i++)
6286 describe_other_breakpoints (sal.pc, sal.section);
6288 b = set_raw_breakpoint (sal);
6289 set_breakpoint_count (breakpoint_count + 1);
6290 b->number = breakpoint_count;
6292 /* Important -- this is an ordinary breakpoint. For platforms
6293 with callback support for exceptions,
6294 create_exception_catchpoint() will create special bp types
6295 (bp_catch_catch and bp_catch_throw), and there is code in
6296 insert_breakpoints() and elsewhere that depends on that. */
6297 b->type = bp_breakpoint;
6300 b->enable = enabled;
6301 b->disposition = tempflag ? del : donttouch;
6308 warning ("Multiple breakpoints were set.");
6309 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6315 /* This creates a temporary internal breakpoint
6316 just to placate infrun */
6317 static struct breakpoint *
6318 create_temp_exception_breakpoint (CORE_ADDR pc)
6320 struct symtab_and_line sal;
6321 struct breakpoint *b;
6328 b = set_raw_breakpoint (sal);
6330 error ("Internal error -- couldn't set temp exception breakpoint");
6332 b->type = bp_breakpoint;
6333 b->disposition = del;
6334 b->enable = enabled;
6336 b->number = internal_breakpoint_number--;
6342 catch_command_1 (char *arg, int tempflag, int from_tty)
6345 /* The first argument may be an event name, such as "start" or "load".
6346 If so, then handle it as such. If it doesn't match an event name,
6347 then attempt to interpret it as an exception name. (This latter is
6348 the v4.16-and-earlier GDB meaning of the "catch" command.)
6350 First, try to find the bounds of what might be an event name. */
6351 char *arg1_start = arg;
6355 if (arg1_start == NULL)
6357 /* Old behaviour was to use pre-v-4.16 syntax */
6358 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6360 /* Now, this is not allowed */
6361 error ("Catch requires an event name.");
6364 arg1_end = ep_find_event_name_end (arg1_start);
6365 if (arg1_end == NULL)
6366 error ("catch requires an event");
6367 arg1_length = arg1_end + 1 - arg1_start;
6369 /* Try to match what we found against known event names. */
6370 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6372 error ("Catch of signal not yet implemented");
6374 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6376 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6377 tempflag, from_tty);
6379 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6381 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6382 tempflag, from_tty);
6384 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6386 error ("Catch of thread_start not yet implemented");
6388 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6390 error ("Catch of thread_exit not yet implemented");
6392 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6394 error ("Catch of thread_join not yet implemented");
6396 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6398 error ("Catch of start not yet implemented");
6400 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6402 error ("Catch of exit not yet implemented");
6404 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6406 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6407 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6409 error ("Catch of fork not yet implemented");
6412 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6414 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6415 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6417 error ("Catch of vfork not yet implemented");
6420 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6422 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6423 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6425 error ("Catch of exec not yet implemented");
6428 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6430 #if defined(SOLIB_ADD)
6431 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6433 error ("Catch of load not implemented");
6436 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6438 #if defined(SOLIB_ADD)
6439 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6441 error ("Catch of load not implemented");
6444 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6446 error ("Catch of stop not yet implemented");
6449 /* This doesn't appear to be an event name */
6453 /* Pre-v.4.16 behaviour was to treat the argument
6454 as the name of an exception */
6455 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6456 /* Now this is not allowed */
6457 error ("Unknown event kind specified for catch");
6462 /* Used by the gui, could be made a worker for other things. */
6465 set_breakpoint_sal (struct symtab_and_line sal)
6467 struct breakpoint *b;
6468 b = set_raw_breakpoint (sal);
6469 set_breakpoint_count (breakpoint_count + 1);
6470 b->number = breakpoint_count;
6471 b->type = bp_breakpoint;
6478 /* These aren't used; I don't know what they were for. */
6479 /* Disable breakpoints on all catch clauses described in ARGS. */
6481 disable_catch (char *args)
6483 /* Map the disable command to catch clauses described in ARGS. */
6486 /* Enable breakpoints on all catch clauses described in ARGS. */
6488 enable_catch (char *args)
6490 /* Map the disable command to catch clauses described in ARGS. */
6493 /* Delete breakpoints on all catch clauses in the active scope. */
6495 delete_catch (char *args)
6497 /* Map the delete command to catch clauses described in ARGS. */
6502 catch_command (char *arg, int from_tty)
6504 catch_command_1 (arg, 0, from_tty);
6509 tcatch_command (char *arg, int from_tty)
6511 catch_command_1 (arg, 1, from_tty);
6516 clear_command (char *arg, int from_tty)
6518 register struct breakpoint *b, *b1;
6520 struct symtabs_and_lines sals;
6521 struct symtab_and_line sal;
6522 register struct breakpoint *found;
6527 sals = decode_line_spec (arg, 1);
6532 sals.sals = (struct symtab_and_line *)
6533 xmalloc (sizeof (struct symtab_and_line));
6534 INIT_SAL (&sal); /* initialize to zeroes */
6535 sal.line = default_breakpoint_line;
6536 sal.symtab = default_breakpoint_symtab;
6537 sal.pc = default_breakpoint_address;
6538 if (sal.symtab == 0)
6539 error ("No source file specified.");
6547 /* For each line spec given, delete bps which correspond
6548 to it. We do this in two loops: the first loop looks at
6549 the initial bp(s) in the chain which should be deleted,
6550 the second goes down the rest of the chain looking ahead
6551 one so it can take those bps off the chain without messing
6555 for (i = 0; i < sals.nelts; i++)
6557 /* If exact pc given, clear bpts at that pc.
6558 If line given (pc == 0), clear all bpts on specified line.
6559 If defaulting, clear all bpts on default line
6562 defaulting sal.pc != 0 tests to do
6567 1 0 <can't happen> */
6570 found = (struct breakpoint *) 0;
6573 while (breakpoint_chain
6574 /* Why don't we check here that this is not
6575 a watchpoint, etc., as we do below?
6576 I can't make it fail, but don't know
6577 what's stopping the failure: a watchpoint
6578 of the same address as "sal.pc" should
6579 wind up being deleted. */
6581 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6582 (overlay_debugging == 0 ||
6583 breakpoint_chain->section == sal.section))
6584 || ((default_match || (0 == sal.pc))
6585 && breakpoint_chain->source_file != NULL
6586 && sal.symtab != NULL
6587 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6588 && breakpoint_chain->line_number == sal.line)))
6591 b1 = breakpoint_chain;
6592 breakpoint_chain = b1->next;
6600 && b->next->type != bp_none
6601 && b->next->type != bp_watchpoint
6602 && b->next->type != bp_hardware_watchpoint
6603 && b->next->type != bp_read_watchpoint
6604 && b->next->type != bp_access_watchpoint
6605 && (((sal.pc && (b->next->address == sal.pc)) &&
6606 (overlay_debugging == 0 ||
6607 b->next->section == sal.section))
6608 || ((default_match || (0 == sal.pc))
6609 && b->next->source_file != NULL
6610 && sal.symtab != NULL
6611 && STREQ (b->next->source_file, sal.symtab->filename)
6612 && b->next->line_number == sal.line)))
6625 error ("No breakpoint at %s.", arg);
6627 error ("No breakpoint at this line.");
6631 from_tty = 1; /* Always report if deleted more than one */
6633 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6634 breakpoints_changed ();
6638 printf_unfiltered ("%d ", found->number);
6640 delete_breakpoint (found);
6644 putchar_unfiltered ('\n');
6649 /* Delete breakpoint in BS if they are `delete' breakpoints and
6650 all breakpoints that are marked for deletion, whether hit or not.
6651 This is called after any breakpoint is hit, or after errors. */
6654 breakpoint_auto_delete (bpstat bs)
6656 struct breakpoint *b, *temp;
6658 for (; bs; bs = bs->next)
6659 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6661 delete_breakpoint (bs->breakpoint_at);
6663 ALL_BREAKPOINTS_SAFE (b, temp)
6665 if (b->disposition == del_at_next_stop)
6666 delete_breakpoint (b);
6670 /* Delete a breakpoint and clean up all traces of it in the data
6674 delete_breakpoint (struct breakpoint *bpt)
6676 register struct breakpoint *b;
6680 error ("Internal error (attempted to delete a NULL breakpoint)");
6683 /* Has this bp already been deleted? This can happen because multiple
6684 lists can hold pointers to bp's. bpstat lists are especial culprits.
6686 One example of this happening is a watchpoint's scope bp. When the
6687 scope bp triggers, we notice that the watchpoint is out of scope, and
6688 delete it. We also delete its scope bp. But the scope bp is marked
6689 "auto-deleting", and is already on a bpstat. That bpstat is then
6690 checked for auto-deleting bp's, which are deleted.
6692 A real solution to this problem might involve reference counts in bp's,
6693 and/or giving them pointers back to their referencing bpstat's, and
6694 teaching delete_breakpoint to only free a bp's storage when no more
6695 references were extent. A cheaper bandaid was chosen. */
6696 if (bpt->type == bp_none)
6699 if (delete_breakpoint_hook)
6700 delete_breakpoint_hook (bpt);
6701 breakpoint_delete_event (bpt->number);
6704 remove_breakpoint (bpt, mark_uninserted);
6706 if (breakpoint_chain == bpt)
6707 breakpoint_chain = bpt->next;
6709 /* If we have callback-style exception catchpoints, don't go through
6710 the adjustments to the C++ runtime library etc. if the inferior
6711 isn't actually running. target_enable_exception_callback for a
6712 null target ops vector gives an undesirable error message, so we
6713 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6714 exceptions are supported in this way, it's OK for now. FIXME */
6715 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6717 static char message1[] = "Error in deleting catchpoint %d:\n";
6718 static char message[sizeof (message1) + 30];
6719 args_for_catchpoint_enable args;
6721 /* Format possible error msg */
6722 sprintf (message, message1, bpt->number);
6723 args.kind = bpt->type == bp_catch_catch ?
6724 EX_EVENT_CATCH : EX_EVENT_THROW;
6726 catch_errors (cover_target_enable_exception_callback, &args,
6727 message, RETURN_MASK_ALL);
6734 b->next = bpt->next;
6738 /* Before turning off the visuals for the bp, check to see that
6739 there are no other bps at the same address. */
6746 clearIt = (b->address != bpt->address);
6753 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6754 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6758 check_duplicates (bpt->address, bpt->section);
6759 /* If this breakpoint was inserted, and there is another breakpoint
6760 at the same address, we need to insert the other breakpoint. */
6762 && bpt->type != bp_hardware_watchpoint
6763 && bpt->type != bp_read_watchpoint
6764 && bpt->type != bp_access_watchpoint
6765 && bpt->type != bp_catch_fork
6766 && bpt->type != bp_catch_vfork
6767 && bpt->type != bp_catch_exec)
6770 if (b->address == bpt->address
6771 && b->section == bpt->section
6773 && b->enable != disabled
6774 && b->enable != shlib_disabled
6775 && b->enable != call_disabled)
6779 /* We should never reach this point if there is a permanent
6780 breakpoint at the same address as the one being deleted.
6781 If there is a permanent breakpoint somewhere, it should
6782 always be the only one inserted. */
6783 if (b->enable == permanent)
6784 internal_error (__FILE__, __LINE__,
6785 "another breakpoint was inserted on top of "
6786 "a permanent breakpoint");
6788 if (b->type == bp_hardware_breakpoint)
6789 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6791 val = target_insert_breakpoint (b->address, b->shadow_contents);
6795 target_terminal_ours_for_output ();
6796 warning ("Cannot insert breakpoint %d:", b->number);
6797 memory_error (val, b->address); /* which bombs us out */
6804 free_command_lines (&bpt->commands);
6807 if (bpt->cond_string != NULL)
6808 xfree (bpt->cond_string);
6809 if (bpt->addr_string != NULL)
6810 xfree (bpt->addr_string);
6811 if (bpt->exp != NULL)
6813 if (bpt->exp_string != NULL)
6814 xfree (bpt->exp_string);
6815 if (bpt->val != NULL)
6816 value_free (bpt->val);
6817 if (bpt->source_file != NULL)
6818 xfree (bpt->source_file);
6819 if (bpt->dll_pathname != NULL)
6820 xfree (bpt->dll_pathname);
6821 if (bpt->triggered_dll_pathname != NULL)
6822 xfree (bpt->triggered_dll_pathname);
6823 if (bpt->exec_pathname != NULL)
6824 xfree (bpt->exec_pathname);
6826 /* Be sure no bpstat's are pointing at it after it's been freed. */
6827 /* FIXME, how can we find all bpstat's?
6828 We just check stop_bpstat for now. */
6829 for (bs = stop_bpstat; bs; bs = bs->next)
6830 if (bs->breakpoint_at == bpt)
6832 bs->breakpoint_at = NULL;
6834 /* we'd call bpstat_clear_actions, but that free's stuff and due
6835 to the multiple pointers pointing to one item with no
6836 reference counts found anywhere through out the bpstat's (how
6837 do you spell fragile?), we don't want to free things twice --
6838 better a memory leak than a corrupt malloc pool! */
6839 bs->commands = NULL;
6842 /* On the chance that someone will soon try again to delete this same
6843 bp, we mark it as deleted before freeing its storage. */
6844 bpt->type = bp_none;
6850 do_delete_breakpoint_cleanup (void *b)
6852 delete_breakpoint (b);
6856 make_cleanup_delete_breakpoint (struct breakpoint *b)
6858 return make_cleanup (do_delete_breakpoint_cleanup, b);
6862 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6864 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6868 delete_command (char *arg, int from_tty)
6870 struct breakpoint *b, *temp;
6874 int breaks_to_delete = 0;
6876 /* Delete all breakpoints if no argument.
6877 Do not delete internal or call-dummy breakpoints, these
6878 have to be deleted with an explicit breakpoint number argument. */
6881 if (b->type != bp_call_dummy &&
6882 b->type != bp_shlib_event &&
6883 b->type != bp_thread_event &&
6885 breaks_to_delete = 1;
6888 /* Ask user only if there are some breakpoints to delete. */
6890 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6892 ALL_BREAKPOINTS_SAFE (b, temp)
6894 if (b->type != bp_call_dummy &&
6895 b->type != bp_shlib_event &&
6896 b->type != bp_thread_event &&
6898 delete_breakpoint (b);
6903 map_breakpoint_numbers (arg, delete_breakpoint);
6906 /* Reset a breakpoint given it's struct breakpoint * BINT.
6907 The value we return ends up being the return value from catch_errors.
6908 Unused in this case. */
6911 breakpoint_re_set_one (PTR bint)
6913 /* get past catch_errs */
6914 struct breakpoint *b = (struct breakpoint *) bint;
6917 struct symtabs_and_lines sals;
6919 enum enable save_enable;
6924 warning ("attempted to reset apparently deleted breakpoint #%d?",
6928 case bp_hardware_breakpoint:
6930 case bp_catch_unload:
6931 if (b->addr_string == NULL)
6933 /* Anything without a string can't be re-set. */
6934 delete_breakpoint (b);
6937 /* In case we have a problem, disable this breakpoint. We'll restore
6938 its status if we succeed. */
6939 save_enable = b->enable;
6940 b->enable = disabled;
6942 set_language (b->language);
6943 input_radix = b->input_radix;
6945 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6946 for (i = 0; i < sals.nelts; i++)
6948 resolve_sal_pc (&sals.sals[i]);
6950 /* Reparse conditions, they might contain references to the
6952 if (b->cond_string != NULL)
6957 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6960 /* We need to re-set the breakpoint if the address changes... */
6961 if (b->address != sals.sals[i].pc
6962 /* ...or new and old breakpoints both have source files, and
6963 the source file name or the line number changes... */
6964 || (b->source_file != NULL
6965 && sals.sals[i].symtab != NULL
6966 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6967 || b->line_number != sals.sals[i].line)
6969 /* ...or we switch between having a source file and not having
6971 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6974 if (b->source_file != NULL)
6975 xfree (b->source_file);
6976 if (sals.sals[i].symtab == NULL)
6977 b->source_file = NULL;
6980 savestring (sals.sals[i].symtab->filename,
6981 strlen (sals.sals[i].symtab->filename));
6982 b->line_number = sals.sals[i].line;
6983 b->address = sals.sals[i].pc;
6985 /* Used to check for duplicates here, but that can
6986 cause trouble, as it doesn't check for disable
6991 /* Might be better to do this just once per breakpoint_re_set,
6992 rather than once for every breakpoint. */
6993 breakpoints_changed ();
6995 b->section = sals.sals[i].section;
6996 b->enable = save_enable; /* Restore it, this worked. */
6999 /* Now that this is re-enabled, check_duplicates
7001 check_duplicates (b->address, b->section);
7008 case bp_hardware_watchpoint:
7009 case bp_read_watchpoint:
7010 case bp_access_watchpoint:
7011 innermost_block = NULL;
7012 /* The issue arises of what context to evaluate this in. The
7013 same one as when it was set, but what does that mean when
7014 symbols have been re-read? We could save the filename and
7015 functionname, but if the context is more local than that, the
7016 best we could do would be something like how many levels deep
7017 and which index at that particular level, but that's going to
7018 be less stable than filenames or function names. */
7020 /* So for now, just use a global context. */
7023 b->exp = parse_expression (b->exp_string);
7024 b->exp_valid_block = innermost_block;
7025 mark = value_mark ();
7027 value_free (b->val);
7028 b->val = evaluate_expression (b->exp);
7029 release_value (b->val);
7030 if (VALUE_LAZY (b->val))
7031 value_fetch_lazy (b->val);
7033 if (b->cond_string != NULL)
7038 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7040 if (b->enable == enabled)
7042 value_free_to_mark (mark);
7044 case bp_catch_catch:
7045 case bp_catch_throw:
7047 /* We needn't really do anything to reset these, since the mask
7048 that requests them is unaffected by e.g., new libraries being
7051 case bp_catch_vfork:
7056 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7058 /* Delete longjmp breakpoints, they will be reset later by
7059 breakpoint_re_set. */
7061 case bp_longjmp_resume:
7062 delete_breakpoint (b);
7065 /* This breakpoint is special, it's set up when the inferior
7066 starts and we really don't want to touch it. */
7067 case bp_shlib_event:
7069 /* Like bp_shlib_event, this breakpoint type is special.
7070 Once it is set up, we do not want to touch it. */
7071 case bp_thread_event:
7073 /* Keep temporary breakpoints, which can be encountered when we step
7074 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7075 Otherwise these should have been blown away via the cleanup chain
7076 or by breakpoint_init_inferior when we rerun the executable. */
7079 case bp_watchpoint_scope:
7081 case bp_step_resume:
7088 /* Re-set all breakpoints after symbols have been re-loaded. */
7090 breakpoint_re_set (void)
7092 struct breakpoint *b, *temp;
7093 enum language save_language;
7094 int save_input_radix;
7095 static char message1[] = "Error in re-setting breakpoint %d:\n";
7096 char message[sizeof (message1) + 30 /* slop */ ];
7098 save_language = current_language->la_language;
7099 save_input_radix = input_radix;
7100 ALL_BREAKPOINTS_SAFE (b, temp)
7102 /* Format possible error msg */
7103 sprintf (message, message1, b->number);
7104 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7106 set_language (save_language);
7107 input_radix = save_input_radix;
7109 #ifdef GET_LONGJMP_TARGET
7110 create_longjmp_breakpoint ("longjmp");
7111 create_longjmp_breakpoint ("_longjmp");
7112 create_longjmp_breakpoint ("siglongjmp");
7113 create_longjmp_breakpoint ("_siglongjmp");
7114 create_longjmp_breakpoint (NULL);
7118 /* Took this out (temporarily at least), since it produces an extra
7119 blank line at startup. This messes up the gdbtests. -PB */
7120 /* Blank line to finish off all those mention() messages we just printed. */
7121 printf_filtered ("\n");
7125 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7126 If from_tty is nonzero, it prints a message to that effect,
7127 which ends with a period (no newline). */
7129 /* Reset the thread number of this breakpoint:
7131 - If the breakpoint is for all threads, leave it as-is.
7132 - Else, reset it to the current thread for inferior_pid. */
7134 breakpoint_re_set_thread (struct breakpoint *b)
7136 if (b->thread != -1)
7138 if (in_thread_list (inferior_pid))
7139 b->thread = pid_to_thread_id (inferior_pid);
7144 set_ignore_count (int bptnum, int count, int from_tty)
7146 register struct breakpoint *b;
7152 if (b->number == bptnum)
7154 b->ignore_count = count;
7157 else if (count == 0)
7158 printf_filtered ("Will stop next time breakpoint %d is reached.",
7160 else if (count == 1)
7161 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7164 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7166 breakpoints_changed ();
7170 error ("No breakpoint number %d.", bptnum);
7173 /* Clear the ignore counts of all breakpoints. */
7175 breakpoint_clear_ignore_counts (void)
7177 struct breakpoint *b;
7180 b->ignore_count = 0;
7183 /* Command to set ignore-count of breakpoint N to COUNT. */
7186 ignore_command (char *args, int from_tty)
7192 error_no_arg ("a breakpoint number");
7194 num = get_number (&p);
7196 error ("bad breakpoint number: '%s'", args);
7198 error ("Second argument (specified ignore-count) is missing.");
7200 set_ignore_count (num,
7201 longest_to_int (value_as_long (parse_and_eval (p))),
7203 printf_filtered ("\n");
7204 breakpoints_changed ();
7207 /* Call FUNCTION on each of the breakpoints
7208 whose numbers are given in ARGS. */
7211 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7213 register char *p = args;
7216 register struct breakpoint *b, *tmp;
7220 error_no_arg ("one or more breakpoint numbers");
7227 num = get_number_or_range (&p1);
7230 warning ("bad breakpoint number at or near '%s'", p);
7234 ALL_BREAKPOINTS_SAFE (b, tmp)
7235 if (b->number == num)
7237 struct breakpoint *related_breakpoint = b->related_breakpoint;
7240 if (related_breakpoint)
7241 function (related_breakpoint);
7245 printf_unfiltered ("No breakpoint number %d.\n", num);
7252 disable_breakpoint (struct breakpoint *bpt)
7254 /* Never disable a watchpoint scope breakpoint; we want to
7255 hit them when we leave scope so we can delete both the
7256 watchpoint and its scope breakpoint at that time. */
7257 if (bpt->type == bp_watchpoint_scope)
7260 /* You can't disable permanent breakpoints. */
7261 if (bpt->enable == permanent)
7264 bpt->enable = disabled;
7266 check_duplicates (bpt->address, bpt->section);
7268 if (modify_breakpoint_hook)
7269 modify_breakpoint_hook (bpt);
7270 breakpoint_modify_event (bpt->number);
7275 disable_command (char *args, int from_tty)
7277 register struct breakpoint *bpt;
7279 ALL_BREAKPOINTS (bpt)
7283 warning ("attempted to disable apparently deleted breakpoint #%d?",
7288 case bp_catch_unload:
7290 case bp_catch_vfork:
7292 case bp_catch_catch:
7293 case bp_catch_throw:
7294 case bp_hardware_breakpoint:
7296 case bp_hardware_watchpoint:
7297 case bp_read_watchpoint:
7298 case bp_access_watchpoint:
7299 disable_breakpoint (bpt);
7304 map_breakpoint_numbers (args, disable_breakpoint);
7308 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7310 struct frame_info *save_selected_frame = NULL;
7311 int save_selected_frame_level = -1;
7312 int target_resources_ok, other_type_used;
7315 if (bpt->type == bp_hardware_breakpoint)
7318 i = hw_breakpoint_used_count ();
7319 target_resources_ok =
7320 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7322 if (target_resources_ok == 0)
7323 error ("No hardware breakpoint support in the target.");
7324 else if (target_resources_ok < 0)
7325 error ("Hardware breakpoints used exceeds limit.");
7328 if (bpt->enable != permanent)
7329 bpt->enable = enabled;
7330 bpt->disposition = disposition;
7331 check_duplicates (bpt->address, bpt->section);
7332 breakpoints_changed ();
7334 if (bpt->type == bp_watchpoint ||
7335 bpt->type == bp_hardware_watchpoint ||
7336 bpt->type == bp_read_watchpoint ||
7337 bpt->type == bp_access_watchpoint)
7339 if (bpt->exp_valid_block != NULL)
7341 struct frame_info *fr =
7343 /* Ensure that we have the current frame. Else, this
7344 next query may pessimistically be answered as, "No,
7345 not within current scope". */
7346 get_current_frame ();
7347 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7351 Cannot enable watchpoint %d because the block in which its expression\n\
7352 is valid is not currently in scope.\n", bpt->number);
7353 bpt->enable = disabled;
7357 save_selected_frame = selected_frame;
7358 save_selected_frame_level = selected_frame_level;
7359 select_frame (fr, -1);
7362 value_free (bpt->val);
7363 mark = value_mark ();
7364 bpt->val = evaluate_expression (bpt->exp);
7365 release_value (bpt->val);
7366 if (VALUE_LAZY (bpt->val))
7367 value_fetch_lazy (bpt->val);
7369 if (bpt->type == bp_hardware_watchpoint ||
7370 bpt->type == bp_read_watchpoint ||
7371 bpt->type == bp_access_watchpoint)
7373 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7374 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7376 /* Hack around 'unused var' error for some targets here */
7378 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7379 bpt->type, i + mem_cnt, other_type_used);
7380 /* we can consider of type is bp_hardware_watchpoint, convert to
7381 bp_watchpoint in the following condition */
7382 if (target_resources_ok < 0)
7385 Cannot enable watchpoint %d because target watch resources\n\
7386 have been allocated for other watchpoints.\n", bpt->number);
7387 bpt->enable = disabled;
7388 value_free_to_mark (mark);
7393 if (save_selected_frame_level >= 0)
7394 select_frame (save_selected_frame, save_selected_frame_level);
7395 value_free_to_mark (mark);
7397 if (modify_breakpoint_hook)
7398 modify_breakpoint_hook (bpt);
7399 breakpoint_modify_event (bpt->number);
7403 enable_breakpoint (struct breakpoint *bpt)
7405 do_enable_breakpoint (bpt, bpt->disposition);
7408 /* The enable command enables the specified breakpoints (or all defined
7409 breakpoints) so they once again become (or continue to be) effective
7410 in stopping the inferior. */
7414 enable_command (char *args, int from_tty)
7416 register struct breakpoint *bpt;
7418 ALL_BREAKPOINTS (bpt)
7422 warning ("attempted to enable apparently deleted breakpoint #%d?",
7427 case bp_catch_unload:
7429 case bp_catch_vfork:
7431 case bp_catch_catch:
7432 case bp_catch_throw:
7433 case bp_hardware_breakpoint:
7435 case bp_hardware_watchpoint:
7436 case bp_read_watchpoint:
7437 case bp_access_watchpoint:
7438 enable_breakpoint (bpt);
7443 map_breakpoint_numbers (args, enable_breakpoint);
7447 enable_once_breakpoint (struct breakpoint *bpt)
7449 do_enable_breakpoint (bpt, disable);
7454 enable_once_command (char *args, int from_tty)
7456 map_breakpoint_numbers (args, enable_once_breakpoint);
7460 enable_delete_breakpoint (struct breakpoint *bpt)
7462 do_enable_breakpoint (bpt, del);
7467 enable_delete_command (char *args, int from_tty)
7469 map_breakpoint_numbers (args, enable_delete_breakpoint);
7472 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7474 struct symtabs_and_lines
7475 decode_line_spec_1 (char *string, int funfirstline)
7477 struct symtabs_and_lines sals;
7479 error ("Empty line specification.");
7480 if (default_breakpoint_valid)
7481 sals = decode_line_1 (&string, funfirstline,
7482 default_breakpoint_symtab,
7483 default_breakpoint_line,
7486 sals = decode_line_1 (&string, funfirstline,
7487 (struct symtab *) NULL, 0, (char ***) NULL);
7489 error ("Junk at end of line specification: %s", string);
7494 _initialize_breakpoint (void)
7496 struct cmd_list_element *c;
7498 breakpoint_chain = 0;
7499 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7500 before a breakpoint is set. */
7501 breakpoint_count = 0;
7503 add_com ("ignore", class_breakpoint, ignore_command,
7504 "Set ignore-count of breakpoint number N to COUNT.\n\
7505 Usage is `ignore N COUNT'.");
7507 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7509 add_com ("commands", class_breakpoint, commands_command,
7510 "Set commands to be executed when a breakpoint is hit.\n\
7511 Give breakpoint number as argument after \"commands\".\n\
7512 With no argument, the targeted breakpoint is the last one set.\n\
7513 The commands themselves follow starting on the next line.\n\
7514 Type a line containing \"end\" to indicate the end of them.\n\
7515 Give \"silent\" as the first line to make the breakpoint silent;\n\
7516 then no output is printed when it is hit, except what the commands print.");
7518 add_com ("condition", class_breakpoint, condition_command,
7519 "Specify breakpoint number N to break only if COND is true.\n\
7520 Usage is `condition N COND', where N is an integer and COND is an\n\
7521 expression to be evaluated whenever breakpoint N is reached. ");
7523 add_com ("tbreak", class_breakpoint, tbreak_command,
7524 "Set a temporary breakpoint. Args like \"break\" command.\n\
7525 Like \"break\" except the breakpoint is only temporary,\n\
7526 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7527 by using \"enable delete\" on the breakpoint number.");
7528 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7529 "Set temporary breakpoint at procedure exit. Either there should\n\
7530 be no argument or the argument must be a depth.\n");
7532 add_com ("hbreak", class_breakpoint, hbreak_command,
7533 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7534 Like \"break\" except the breakpoint requires hardware support,\n\
7535 some target hardware may not have this support.");
7537 add_com ("thbreak", class_breakpoint, thbreak_command,
7538 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7539 Like \"hbreak\" except the breakpoint is only temporary,\n\
7540 so it will be deleted when hit.");
7542 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7543 "Enable some breakpoints.\n\
7544 Give breakpoint numbers (separated by spaces) as arguments.\n\
7545 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7546 This is used to cancel the effect of the \"disable\" command.\n\
7547 With a subcommand you can enable temporarily.",
7548 &enablelist, "enable ", 1, &cmdlist);
7550 add_com ("ab", class_breakpoint, enable_command,
7551 "Enable some breakpoints.\n\
7552 Give breakpoint numbers (separated by spaces) as arguments.\n\
7553 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7554 This is used to cancel the effect of the \"disable\" command.\n\
7555 With a subcommand you can enable temporarily.");
7557 add_com_alias ("en", "enable", class_breakpoint, 1);
7559 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7560 "Enable some breakpoints.\n\
7561 Give breakpoint numbers (separated by spaces) as arguments.\n\
7562 This is used to cancel the effect of the \"disable\" command.\n\
7563 May be abbreviated to simply \"enable\".\n",
7564 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7566 add_cmd ("once", no_class, enable_once_command,
7567 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7568 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7571 add_cmd ("delete", no_class, enable_delete_command,
7572 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7573 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7576 add_cmd ("delete", no_class, enable_delete_command,
7577 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7578 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7581 add_cmd ("once", no_class, enable_once_command,
7582 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7583 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7586 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7587 "Disable some breakpoints.\n\
7588 Arguments are breakpoint numbers with spaces in between.\n\
7589 To disable all breakpoints, give no argument.\n\
7590 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7591 &disablelist, "disable ", 1, &cmdlist);
7592 add_com_alias ("dis", "disable", class_breakpoint, 1);
7593 add_com_alias ("disa", "disable", class_breakpoint, 1);
7595 add_com ("sb", class_breakpoint, disable_command,
7596 "Disable some breakpoints.\n\
7597 Arguments are breakpoint numbers with spaces in between.\n\
7598 To disable all breakpoints, give no argument.\n\
7599 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7601 add_cmd ("breakpoints", class_alias, disable_command,
7602 "Disable some breakpoints.\n\
7603 Arguments are breakpoint numbers with spaces in between.\n\
7604 To disable all breakpoints, give no argument.\n\
7605 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7606 This command may be abbreviated \"disable\".",
7609 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7610 "Delete some breakpoints or auto-display expressions.\n\
7611 Arguments are breakpoint numbers with spaces in between.\n\
7612 To delete all breakpoints, give no argument.\n\
7614 Also a prefix command for deletion of other GDB objects.\n\
7615 The \"unset\" command is also an alias for \"delete\".",
7616 &deletelist, "delete ", 1, &cmdlist);
7617 add_com_alias ("d", "delete", class_breakpoint, 1);
7619 add_com ("db", class_breakpoint, delete_command,
7620 "Delete some breakpoints.\n\
7621 Arguments are breakpoint numbers with spaces in between.\n\
7622 To delete all breakpoints, give no argument.\n");
7624 add_cmd ("breakpoints", class_alias, delete_command,
7625 "Delete some breakpoints or auto-display expressions.\n\
7626 Arguments are breakpoint numbers with spaces in between.\n\
7627 To delete all breakpoints, give no argument.\n\
7628 This command may be abbreviated \"delete\".",
7631 add_com ("clear", class_breakpoint, clear_command,
7632 concat ("Clear breakpoint at specified line or function.\n\
7633 Argument may be line number, function name, or \"*\" and an address.\n\
7634 If line number is specified, all breakpoints in that line are cleared.\n\
7635 If function is specified, breakpoints at beginning of function are cleared.\n\
7636 If an address is specified, breakpoints at that address are cleared.\n\n",
7637 "With no argument, clears all breakpoints in the line that the selected frame\n\
7640 See also the \"delete\" command which clears breakpoints by number.", NULL));
7642 add_com ("break", class_breakpoint, break_command,
7643 concat ("Set breakpoint at specified line or function.\n\
7644 Argument may be line number, function name, or \"*\" and an address.\n\
7645 If line number is specified, break at start of code for that line.\n\
7646 If function is specified, break at start of code for that function.\n\
7647 If an address is specified, break at that exact address.\n",
7648 "With no arg, uses current execution address of selected stack frame.\n\
7649 This is useful for breaking on return to a stack frame.\n\
7651 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7653 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7654 add_com_alias ("b", "break", class_run, 1);
7655 add_com_alias ("br", "break", class_run, 1);
7656 add_com_alias ("bre", "break", class_run, 1);
7657 add_com_alias ("brea", "break", class_run, 1);
7659 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7660 concat ("Set breakpoint at procedure exit. \n\
7661 Argument may be function name, or \"*\" and an address.\n\
7662 If function is specified, break at end of code for that function.\n\
7663 If an address is specified, break at the end of the function that contains \n\
7664 that exact address.\n",
7665 "With no arg, uses current execution address of selected stack frame.\n\
7666 This is useful for breaking on return to a stack frame.\n\
7668 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7670 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7671 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7672 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7673 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7674 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7678 add_com_alias ("ba", "break", class_breakpoint, 1);
7679 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7680 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7681 "Set breakpoint at procedure exit. Either there should\n\
7682 be no argument or the argument must be a depth.\n");
7687 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7688 "Break in function/address or break at a line in the current file.",
7689 &stoplist, "stop ", 1, &cmdlist);
7690 add_cmd ("in", class_breakpoint, stopin_command,
7691 "Break in function or address.\n", &stoplist);
7692 add_cmd ("at", class_breakpoint, stopat_command,
7693 "Break at a line in the current file.\n", &stoplist);
7694 add_com ("status", class_info, breakpoints_info,
7695 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7696 The \"Type\" column indicates one of:\n\
7697 \tbreakpoint - normal breakpoint\n\
7698 \twatchpoint - watchpoint\n\
7699 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7700 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7701 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7702 address and file/line number respectively.\n\n",
7703 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7704 are set to the address of the last breakpoint listed.\n\n\
7705 Convenience variable \"$bpnum\" contains the number of the last\n\
7706 breakpoint set.", NULL));
7709 add_info ("breakpoints", breakpoints_info,
7710 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7711 The \"Type\" column indicates one of:\n\
7712 \tbreakpoint - normal breakpoint\n\
7713 \twatchpoint - watchpoint\n\
7714 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7715 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7716 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7717 address and file/line number respectively.\n\n",
7718 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7719 are set to the address of the last breakpoint listed.\n\n\
7720 Convenience variable \"$bpnum\" contains the number of the last\n\
7721 breakpoint set.", NULL));
7724 add_com ("lb", class_breakpoint, breakpoints_info,
7725 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7726 The \"Type\" column indicates one of:\n\
7727 \tbreakpoint - normal breakpoint\n\
7728 \twatchpoint - watchpoint\n\
7729 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7730 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7731 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7732 address and file/line number respectively.\n\n",
7733 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7734 are set to the address of the last breakpoint listed.\n\n\
7735 Convenience variable \"$bpnum\" contains the number of the last\n\
7736 breakpoint set.", NULL));
7738 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7739 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7740 The \"Type\" column indicates one of:\n\
7741 \tbreakpoint - normal breakpoint\n\
7742 \twatchpoint - watchpoint\n\
7743 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7744 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7745 \tuntil - internal breakpoint used by the \"until\" command\n\
7746 \tfinish - internal breakpoint used by the \"finish\" command\n",
7747 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7748 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7749 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7750 address and file/line number respectively.\n\n",
7751 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7752 are set to the address of the last breakpoint listed.\n\n\
7753 Convenience variable \"$bpnum\" contains the number of the last\n\
7754 breakpoint set.", NULL),
7755 &maintenanceinfolist);
7757 add_com ("catch", class_breakpoint, catch_command,
7758 "Set catchpoints to catch events.\n\
7759 Raised signals may be caught:\n\
7760 \tcatch signal - all signals\n\
7761 \tcatch signal <signame> - a particular signal\n\
7762 Raised exceptions may be caught:\n\
7763 \tcatch throw - all exceptions, when thrown\n\
7764 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7765 \tcatch catch - all exceptions, when caught\n\
7766 \tcatch catch <exceptname> - a particular exception, when caught\n\
7767 Thread or process events may be caught:\n\
7768 \tcatch thread_start - any threads, just after creation\n\
7769 \tcatch thread_exit - any threads, just before expiration\n\
7770 \tcatch thread_join - any threads, just after joins\n\
7771 Process events may be caught:\n\
7772 \tcatch start - any processes, just after creation\n\
7773 \tcatch exit - any processes, just before expiration\n\
7774 \tcatch fork - calls to fork()\n\
7775 \tcatch vfork - calls to vfork()\n\
7776 \tcatch exec - calls to exec()\n\
7777 Dynamically-linked library events may be caught:\n\
7778 \tcatch load - loads of any library\n\
7779 \tcatch load <libname> - loads of a particular library\n\
7780 \tcatch unload - unloads of any library\n\
7781 \tcatch unload <libname> - unloads of a particular library\n\
7782 The act of your program's execution stopping may also be caught:\n\
7784 C++ exceptions may be caught:\n\
7785 \tcatch throw - all exceptions, when thrown\n\
7786 \tcatch catch - all exceptions, when caught\n\
7788 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7789 after a fork or vfork is caught.\n\n\
7790 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7792 add_com ("tcatch", class_breakpoint, tcatch_command,
7793 "Set temporary catchpoints to catch events.\n\
7794 Args like \"catch\" command.\n\
7795 Like \"catch\" except the catchpoint is only temporary,\n\
7796 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7797 by using \"enable delete\" on the catchpoint number.");
7799 add_com ("watch", class_breakpoint, watch_command,
7800 "Set a watchpoint for an expression.\n\
7801 A watchpoint stops execution of your program whenever the value of\n\
7802 an expression changes.");
7804 add_com ("rwatch", class_breakpoint, rwatch_command,
7805 "Set a read watchpoint for an expression.\n\
7806 A watchpoint stops execution of your program whenever the value of\n\
7807 an expression is read.");
7809 add_com ("awatch", class_breakpoint, awatch_command,
7810 "Set a watchpoint for an expression.\n\
7811 A watchpoint stops execution of your program whenever the value of\n\
7812 an expression is either read or written.");
7814 add_info ("watchpoints", breakpoints_info,
7815 "Synonym for ``info breakpoints''.");
7818 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7819 (char *) &can_use_hw_watchpoints,
7820 "Set debugger's willingness to use watchpoint hardware.\n\
7821 If zero, gdb will not use hardware for new watchpoints, even if\n\
7822 such is available. (However, any hardware watchpoints that were\n\
7823 created before setting this to nonzero, will continue to use watchpoint\n\
7826 add_show_from_set (c, &showlist);
7828 can_use_hw_watchpoints = 1;