1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 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 static void tbreak_at_finish_command (char *, int);
90 static void break_command_1 (char *, int, int);
92 static void mention (struct breakpoint *);
94 struct breakpoint *set_raw_breakpoint (struct symtab_and_line);
96 static void check_duplicates (struct breakpoint *);
98 static void describe_other_breakpoints (CORE_ADDR, asection *);
100 static void breakpoints_info (char *, int);
102 static void breakpoint_1 (int, int);
104 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
106 static int breakpoint_cond_eval (PTR);
108 static void cleanup_executing_breakpoints (PTR);
110 static void commands_command (char *, int);
112 static void condition_command (char *, int);
114 static int get_number_trailer (char **, int);
116 void set_breakpoint_count (int);
119 static struct breakpoint *create_temp_exception_breakpoint (CORE_ADDR);
129 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
131 static enum print_stop_action print_it_typical (bpstat);
133 static enum print_stop_action print_bp_stop_message (bpstat bs);
137 enum exception_event_kind kind;
140 args_for_catchpoint_enable;
142 static int watchpoint_check (PTR);
144 static int cover_target_enable_exception_callback (PTR);
146 static void maintenance_info_breakpoints (char *, int);
148 #ifdef GET_LONGJMP_TARGET
149 static void create_longjmp_breakpoint (char *);
152 static int hw_breakpoint_used_count (void);
154 static int hw_watchpoint_used_count (enum bptype, int *);
156 static void hbreak_command (char *, int);
158 static void thbreak_command (char *, int);
160 static void watch_command_1 (char *, int, int);
162 static void rwatch_command (char *, int);
164 static void awatch_command (char *, int);
166 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
168 static void solib_load_unload_1 (char *hookname,
171 char *cond_string, enum bptype bp_kind);
173 static void create_fork_vfork_event_catchpoint (int tempflag,
175 enum bptype bp_kind);
177 static void break_at_finish_at_depth_command_1 (char *arg,
178 int flag, int from_tty);
180 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
182 static void stop_command (char *arg, int from_tty);
184 static void stopin_command (char *arg, int from_tty);
186 static void stopat_command (char *arg, int from_tty);
188 static char *ep_find_event_name_end (char *arg);
190 static char *ep_parse_optional_if_clause (char **arg);
192 static char *ep_parse_optional_filename (char **arg);
194 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
195 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
198 static void create_exception_catchpoint (int tempflag, char *cond_string,
199 enum exception_event_kind ex_event,
200 struct symtab_and_line *sal);
202 static void catch_exception_command_1 (enum exception_event_kind ex_event,
203 char *arg, int tempflag, int from_tty);
205 static void tcatch_command (char *arg, int from_tty);
207 static void ep_skip_leading_whitespace (char **s);
209 /* Prototypes for exported functions. */
211 /* If FALSE, gdb will not use hardware support for watchpoints, even
212 if such is available. */
213 static int can_use_hw_watchpoints;
215 void _initialize_breakpoint (void);
217 extern int addressprint; /* Print machine addresses? */
219 static int internal_breakpoint_number = -1;
221 /* Are we executing breakpoint commands? */
222 static int executing_breakpoint_commands;
224 /* Walk the following statement or block through all breakpoints.
225 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
228 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
230 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
231 for (B = breakpoint_chain; \
232 B ? (TMP=B->next, 1): 0; \
235 /* True if SHIFT_INST_REGS defined, false otherwise. */
237 int must_shift_inst_regs =
238 #if defined(SHIFT_INST_REGS)
245 /* True if breakpoint hit counts should be displayed in breakpoint info. */
247 int show_breakpoint_hit_counts = 1;
249 /* Chain of all breakpoints defined. */
251 struct breakpoint *breakpoint_chain;
253 /* Number of last breakpoint made. */
255 int breakpoint_count;
257 /* Pointer to current exception event record */
258 static struct exception_event_record *current_exception_event;
260 /* Indicator of whether exception catchpoints should be nuked
261 between runs of a program */
262 int exception_catchpoints_are_fragile = 0;
264 /* Indicator of when exception catchpoints set-up should be
265 reinitialized -- e.g. when program is re-run */
266 int exception_support_initialized = 0;
268 /* This function returns a pointer to the string representation of the
269 pathname of the dynamically-linked library that has just been
272 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
273 or undefined results are guaranteed.
275 This string's contents are only valid immediately after the
276 inferior has stopped in the dynamic linker hook, and becomes
277 invalid as soon as the inferior is continued. Clients should make
278 a copy of this string if they wish to continue the inferior and
279 then access the string. */
281 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
282 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
285 /* This function returns a pointer to the string representation of the
286 pathname of the dynamically-linked library that has just been
289 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
290 TRUE, or undefined results are guaranteed.
292 This string's contents are only valid immediately after the
293 inferior has stopped in the dynamic linker hook, and becomes
294 invalid as soon as the inferior is continued. Clients should make
295 a copy of this string if they wish to continue the inferior and
296 then access the string. */
298 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
299 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
302 /* This function is called by the "catch load" command. It allows the
303 debugger to be notified by the dynamic linker when a specified
304 library file (or any library file, if filename is NULL) is loaded. */
306 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
307 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
308 error ("catch of library loads not yet implemented on this platform")
311 /* This function is called by the "catch unload" command. It allows
312 the debugger to be notified by the dynamic linker when a specified
313 library file (or any library file, if filename is NULL) is
316 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
317 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
318 error ("catch of library unloads not yet implemented on this platform")
321 /* Set breakpoint count to NUM. */
324 set_breakpoint_count (int num)
326 breakpoint_count = num;
327 set_internalvar (lookup_internalvar ("bpnum"),
328 value_from_longest (builtin_type_int, (LONGEST) num));
331 /* Used in run_command to zero the hit count when a new run starts. */
334 clear_breakpoint_hit_counts (void)
336 struct breakpoint *b;
342 /* Default address, symtab and line to put a breakpoint at
343 for "break" command with no arg.
344 if default_breakpoint_valid is zero, the other three are
345 not valid, and "break" with no arg is an error.
347 This set by print_stack_frame, which calls set_default_breakpoint. */
349 int default_breakpoint_valid;
350 CORE_ADDR default_breakpoint_address;
351 struct symtab *default_breakpoint_symtab;
352 int default_breakpoint_line;
354 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
355 Advance *PP after the string and any trailing whitespace.
357 Currently the string can either be a number or "$" followed by the name
358 of a convenience variable. Making it an expression wouldn't work well
359 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
361 TRAILER is a character which can be found after the number; most
362 commonly this is `-'. If you don't want a trailer, use \0. */
364 get_number_trailer (char **pp, int trailer)
366 int retval = 0; /* default */
370 /* Empty line means refer to the last breakpoint. */
371 return breakpoint_count;
374 /* Make a copy of the name, so we can null-terminate it
375 to pass to lookup_internalvar(). */
380 while (isalnum (*p) || *p == '_')
382 varname = (char *) alloca (p - start + 1);
383 strncpy (varname, start, p - start);
384 varname[p - start] = '\0';
385 val = value_of_internalvar (lookup_internalvar (varname));
386 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
387 retval = (int) value_as_long (val);
390 printf_filtered ("Convenience variable must have integer value.\n");
398 while (*p >= '0' && *p <= '9')
401 /* There is no number here. (e.g. "cond a == b"). */
403 /* Skip non-numeric token */
404 while (*p && !isspace((int) *p))
406 /* Return zero, which caller must interpret as error. */
412 if (!(isspace (*p) || *p == '\0' || *p == trailer))
414 /* Trailing junk: return 0 and let caller print error msg. */
415 while (!(isspace (*p) || *p == '\0' || *p == trailer))
426 /* Like get_number_trailer, but don't allow a trailer. */
428 get_number (char **pp)
430 return get_number_trailer (pp, '\0');
433 /* Parse a number or a range.
434 * A number will be of the form handled by get_number.
435 * A range will be of the form <number1> - <number2>, and
436 * will represent all the integers between number1 and number2,
439 * While processing a range, this fuction is called iteratively;
440 * At each call it will return the next value in the range.
442 * At the beginning of parsing a range, the char pointer PP will
443 * be advanced past <number1> and left pointing at the '-' token.
444 * Subsequent calls will not advance the pointer until the range
445 * is completed. The call that completes the range will advance
446 * pointer PP past <number2>.
450 get_number_or_range (char **pp)
452 static int last_retval, end_value;
453 static char *end_ptr;
454 static int in_range = 0;
458 /* Default case: pp is pointing either to a solo number,
459 or to the first number of a range. */
460 last_retval = get_number_trailer (pp, '-');
465 /* This is the start of a range (<number1> - <number2>).
466 Skip the '-', parse and remember the second number,
467 and also remember the end of the final token. */
471 while (isspace ((int) *end_ptr))
472 end_ptr++; /* skip white space */
473 end_value = get_number (temp);
474 if (end_value < last_retval)
476 error ("inverted range");
478 else if (end_value == last_retval)
480 /* degenerate range (number1 == number2). Advance the
481 token pointer so that the range will be treated as a
490 error ("negative value");
493 /* pp points to the '-' that betokens a range. All
494 number-parsing has already been done. Return the next
495 integer value (one greater than the saved previous value).
496 Do not advance the token pointer 'pp' until the end of range
499 if (++last_retval == end_value)
501 /* End of range reached; advance token pointer. */
511 /* condition N EXP -- set break condition of breakpoint N to EXP. */
514 condition_command (char *arg, int from_tty)
516 register struct breakpoint *b;
521 error_no_arg ("breakpoint number");
524 bnum = get_number (&p);
526 error ("Bad breakpoint argument: '%s'", arg);
529 if (b->number == bnum)
536 if (b->cond_string != NULL)
537 xfree (b->cond_string);
542 b->cond_string = NULL;
544 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
549 /* I don't know if it matters whether this is the string the user
550 typed in or the decompiled expression. */
551 b->cond_string = savestring (arg, strlen (arg));
552 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
554 error ("Junk at end of expression");
556 breakpoints_changed ();
560 error ("No breakpoint number %d.", bnum);
565 commands_command (char *arg, int from_tty)
567 register struct breakpoint *b;
570 struct command_line *l;
572 /* If we allowed this, we would have problems with when to
573 free the storage, if we change the commands currently
576 if (executing_breakpoint_commands)
577 error ("Can't use the \"commands\" command among a breakpoint's commands.");
580 bnum = get_number (&p);
583 error ("Unexpected extra arguments following breakpoint number.");
586 if (b->number == bnum)
590 "Type commands for when breakpoint %d is hit, one per line.",
592 l = read_command_lines (tmpbuf, from_tty);
593 free_command_lines (&b->commands);
595 breakpoints_changed ();
598 error ("No breakpoint number %d.", bnum);
601 /* Like target_read_memory() but if breakpoints are inserted, return
602 the shadow contents instead of the breakpoints themselves.
604 Read "memory data" from whatever target or inferior we have.
605 Returns zero if successful, errno value if not. EIO is used
606 for address out of bounds. If breakpoints are inserted, returns
607 shadow contents, not the breakpoints themselves. From breakpoint.c. */
610 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
613 struct breakpoint *b;
614 CORE_ADDR bp_addr = 0;
617 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
618 /* No breakpoints on this machine. */
619 return target_read_memory (memaddr, myaddr, len);
623 if (b->type == bp_none)
624 warning ("reading through apparently deleted breakpoint #%d?",
627 /* memory breakpoint? */
628 if (b->type == bp_watchpoint
629 || b->type == bp_hardware_watchpoint
630 || b->type == bp_read_watchpoint
631 || b->type == bp_access_watchpoint)
636 /* Addresses and length of the part of the breakpoint that
638 /* XXXX The m68k, sh and h8300 have different local and remote
639 breakpoint values. BREAKPOINT_FROM_PC still manages to
640 correctly determine the breakpoints memory address and size
641 for these targets. */
642 bp_addr = b->address;
644 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
649 if (bp_addr + bp_size <= memaddr)
650 /* The breakpoint is entirely before the chunk of memory we
653 if (bp_addr >= memaddr + len)
654 /* The breakpoint is entirely after the chunk of memory we are
657 /* Copy the breakpoint from the shadow contents, and recurse for
658 the things before and after. */
660 /* Offset within shadow_contents. */
663 if (bp_addr < memaddr)
665 /* Only copy the second part of the breakpoint. */
666 bp_size -= memaddr - bp_addr;
667 bptoffset = memaddr - bp_addr;
671 if (bp_addr + bp_size > memaddr + len)
673 /* Only copy the first part of the breakpoint. */
674 bp_size -= (bp_addr + bp_size) - (memaddr + len);
677 memcpy (myaddr + bp_addr - memaddr,
678 b->shadow_contents + bptoffset, bp_size);
680 if (bp_addr > memaddr)
682 /* Copy the section of memory before the breakpoint. */
683 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
688 if (bp_addr + bp_size < memaddr + len)
690 /* Copy the section of memory after the breakpoint. */
691 status = read_memory_nobpt (bp_addr + bp_size,
692 myaddr + bp_addr + bp_size - memaddr,
693 memaddr + len - (bp_addr + bp_size));
700 /* Nothing overlaps. Just call read_memory_noerr. */
701 return target_read_memory (memaddr, myaddr, len);
705 /* insert_breakpoints is used when starting or continuing the program.
706 remove_breakpoints is used when the program stops.
707 Both return zero if successful,
708 or an `errno' value if could not write the inferior. */
711 insert_breakpoints (void)
713 register struct breakpoint *b, *temp;
714 int return_val = 0; /* return success code. */
716 int disabled_breaks = 0;
718 static char message1[] = "Error inserting catchpoint %d:\n";
719 static char message[sizeof (message1) + 30];
722 ALL_BREAKPOINTS_SAFE (b, temp)
724 if (b->enable == permanent)
725 /* Permanent breakpoints cannot be inserted or removed. */
727 else if (b->type != bp_watchpoint
728 && b->type != bp_hardware_watchpoint
729 && b->type != bp_read_watchpoint
730 && b->type != bp_access_watchpoint
731 && b->type != bp_catch_fork
732 && b->type != bp_catch_vfork
733 && b->type != bp_catch_exec
734 && b->type != bp_catch_throw
735 && b->type != bp_catch_catch
736 && b->enable != disabled
737 && b->enable != shlib_disabled
738 && b->enable != call_disabled
742 if (b->type == bp_hardware_breakpoint)
743 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
746 /* Check to see if breakpoint is in an overlay section;
747 if so, we should set the breakpoint at the LMA address.
748 Only if the section is currently mapped should we ALSO
749 set a break at the VMA address. */
750 if (overlay_debugging && b->section &&
751 section_is_overlay (b->section))
755 addr = overlay_unmapped_address (b->address, b->section);
756 val = target_insert_breakpoint (addr, b->shadow_contents);
757 /* This would be the time to check val, to see if the
758 breakpoint write to the load address succeeded.
759 However, this might be an ordinary occurrance, eg. if
760 the unmapped overlay is in ROM. */
761 val = 0; /* in case unmapped address failed */
762 if (section_is_mapped (b->section))
763 val = target_insert_breakpoint (b->address,
766 else /* ordinary (non-overlay) address */
767 val = target_insert_breakpoint (b->address, b->shadow_contents);
771 /* Can't set the breakpoint. */
772 #if defined (DISABLE_UNSETTABLE_BREAK)
773 if (DISABLE_UNSETTABLE_BREAK (b->address))
775 /* See also: disable_breakpoints_in_shlibs. */
777 b->enable = shlib_disabled;
778 if (!disabled_breaks)
780 target_terminal_ours_for_output ();
781 warning ("Cannot insert breakpoint %d:", b->number);
782 warning ("Temporarily disabling shared library breakpoints:");
785 warning ("breakpoint #%d ", b->number);
790 target_terminal_ours_for_output ();
791 warning ("Cannot insert breakpoint %d:", b->number);
792 #ifdef ONE_PROCESS_WRITETEXT
793 warning ("The same program may be running in another process.");
795 memory_error (val, b->address); /* which bombs us out */
802 return_val = val; /* remember failure */
804 else if (ep_is_exception_catchpoint (b)
805 && b->enable != disabled
806 && b->enable != shlib_disabled
807 && b->enable != call_disabled
812 /* If we get here, we must have a callback mechanism for exception
813 events -- with g++ style embedded label support, we insert
814 ordinary breakpoints and not catchpoints. */
815 /* Format possible error message */
816 sprintf (message, message1, b->number);
818 val = target_insert_breakpoint (b->address, b->shadow_contents);
821 /* Couldn't set breakpoint for some reason */
822 target_terminal_ours_for_output ();
823 warning ("Cannot insert catchpoint %d; disabling it.",
825 b->enable = disabled;
829 /* Bp set, now make sure callbacks are enabled */
831 args_for_catchpoint_enable args;
832 args.kind = b->type == bp_catch_catch ?
833 EX_EVENT_CATCH : EX_EVENT_THROW;
835 val = catch_errors (cover_target_enable_exception_callback,
837 message, RETURN_MASK_ALL);
838 if (val != 0 && val != -1)
842 /* Check if something went wrong; val == 0 can be ignored */
845 /* something went wrong */
846 target_terminal_ours_for_output ();
847 warning ("Cannot insert catchpoint %d; disabling it.",
849 b->enable = disabled;
854 return_val = val; /* remember failure */
857 else if ((b->type == bp_hardware_watchpoint ||
858 b->type == bp_read_watchpoint ||
859 b->type == bp_access_watchpoint)
860 && b->enable == enabled
861 && b->disposition != del_at_next_stop
865 struct frame_info *saved_frame;
866 int saved_level, within_current_scope;
867 value_ptr mark = value_mark ();
870 /* Save the current frame and level so we can restore it after
871 evaluating the watchpoint expression on its own frame. */
872 saved_frame = selected_frame;
873 saved_level = selected_frame_level;
875 /* Determine if the watchpoint is within scope. */
876 if (b->exp_valid_block == NULL)
877 within_current_scope = 1;
880 struct frame_info *fi;
882 /* There might be no current frame at this moment if we are
883 resuming from a step over a breakpoint.
884 Set up current frame before trying to find the watchpoint
886 get_current_frame ();
887 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
888 within_current_scope = (fi != NULL);
889 if (within_current_scope)
890 select_frame (fi, -1);
893 if (within_current_scope)
895 /* Evaluate the expression and cut the chain of values
896 produced off from the value chain.
898 Make sure the value returned isn't lazy; we use
899 laziness to determine what memory GDB actually needed
900 in order to compute the value of the expression. */
901 v = evaluate_expression (b->exp);
903 value_release_to_mark (mark);
908 /* Look at each value on the value chain. */
909 for (; v; v = v->next)
911 /* If it's a memory location, and GDB actually needed
912 its contents to evaluate the expression, then we
914 if (VALUE_LVAL (v) == lval_memory
917 struct type *vtype = check_typedef (VALUE_TYPE (v));
919 /* We only watch structs and arrays if user asked
920 for it explicitly, never if they just happen to
921 appear in the middle of some value chain. */
922 if (v == b->val_chain
923 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
924 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
929 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
930 len = TYPE_LENGTH (VALUE_TYPE (v));
932 if (b->type == bp_read_watchpoint)
934 else if (b->type == bp_access_watchpoint)
937 val = target_insert_watchpoint (addr, len, type);
940 /* Don't exit the loop, try to insert
941 every value on the value chain. That's
942 because we will be removing all the
943 watches below, and removing a
944 watchpoint we didn't insert could have
952 /* Failure to insert a watchpoint on any memory value in the
953 value chain brings us here. */
956 remove_breakpoint (b, mark_uninserted);
957 warning ("Could not insert hardware watchpoint %d.",
964 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
965 printf_filtered ("because the program has left the block \n");
966 printf_filtered ("in which its expression is valid.\n");
967 if (b->related_breakpoint)
968 b->related_breakpoint->disposition = del_at_next_stop;
969 b->disposition = del_at_next_stop;
972 /* Restore the frame and level. */
973 if ((saved_frame != selected_frame) ||
974 (saved_level != selected_frame_level))
975 select_frame (saved_frame, saved_level);
978 return_val = val; /* remember failure */
980 else if ((b->type == bp_catch_fork
981 || b->type == bp_catch_vfork
982 || b->type == bp_catch_exec)
983 && b->enable == enabled
991 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
994 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
997 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
1000 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1005 target_terminal_ours_for_output ();
1006 warning ("Cannot insert catchpoint %d.", b->number);
1012 return_val = val; /* remember failure */
1021 remove_breakpoints (void)
1023 register struct breakpoint *b;
1030 val = remove_breakpoint (b, mark_uninserted);
1039 remove_hw_watchpoints (void)
1041 register struct breakpoint *b;
1047 && (b->type == bp_hardware_watchpoint
1048 || b->type == bp_read_watchpoint
1049 || b->type == bp_access_watchpoint))
1051 val = remove_breakpoint (b, mark_uninserted);
1060 reattach_breakpoints (int pid)
1062 register struct breakpoint *b;
1064 ptid_t saved_inferior_ptid = inferior_ptid;
1066 /* FIXME: use a cleanup, to insure that inferior_ptid gets replaced! */
1067 inferior_ptid = pid_to_ptid (pid); /* Because remove_breakpoint will use this global. */
1072 remove_breakpoint (b, mark_inserted);
1073 if (b->type == bp_hardware_breakpoint)
1074 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1076 val = target_insert_breakpoint (b->address, b->shadow_contents);
1079 inferior_ptid = saved_inferior_ptid;
1084 inferior_ptid = saved_inferior_ptid;
1089 update_breakpoints_after_exec (void)
1091 struct breakpoint *b;
1092 struct breakpoint *temp;
1094 /* Doing this first prevents the badness of having delete_breakpoint()
1095 write a breakpoint's current "shadow contents" to lift the bp. That
1096 shadow is NOT valid after an exec()! */
1097 mark_breakpoints_out ();
1099 ALL_BREAKPOINTS_SAFE (b, temp)
1101 /* Solib breakpoints must be explicitly reset after an exec(). */
1102 if (b->type == bp_shlib_event)
1104 delete_breakpoint (b);
1108 /* Thread event breakpoints must be set anew after an exec(). */
1109 if (b->type == bp_thread_event)
1111 delete_breakpoint (b);
1115 /* Step-resume breakpoints are meaningless after an exec(). */
1116 if (b->type == bp_step_resume)
1118 delete_breakpoint (b);
1122 /* Ditto the sigtramp handler breakpoints. */
1123 if (b->type == bp_through_sigtramp)
1125 delete_breakpoint (b);
1129 /* Ditto the exception-handling catchpoints. */
1130 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1132 delete_breakpoint (b);
1136 /* Don't delete an exec catchpoint, because else the inferior
1137 won't stop when it ought!
1139 Similarly, we probably ought to keep vfork catchpoints, 'cause
1140 on this target, we may not be able to stop when the vfork is
1141 seen, but only when the subsequent exec is seen. (And because
1142 deleting fork catchpoints here but not vfork catchpoints will
1143 seem mysterious to users, keep those too.)
1145 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1146 target address field, if any, is sufficient to have it be reset
1147 automagically. Certainly on HP-UX that's true. */
1148 if ((b->type == bp_catch_exec) ||
1149 (b->type == bp_catch_vfork) ||
1150 (b->type == bp_catch_fork))
1152 b->address = (CORE_ADDR) NULL;
1156 /* bp_finish is a special case. The only way we ought to be able
1157 to see one of these when an exec() has happened, is if the user
1158 caught a vfork, and then said "finish". Ordinarily a finish just
1159 carries them to the call-site of the current callee, by setting
1160 a temporary bp there and resuming. But in this case, the finish
1161 will carry them entirely through the vfork & exec.
1163 We don't want to allow a bp_finish to remain inserted now. But
1164 we can't safely delete it, 'cause finish_command has a handle to
1165 the bp on a bpstat, and will later want to delete it. There's a
1166 chance (and I've seen it happen) that if we delete the bp_finish
1167 here, that its storage will get reused by the time finish_command
1168 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1169 We really must allow finish_command to delete a bp_finish.
1171 In the absense of a general solution for the "how do we know
1172 it's safe to delete something others may have handles to?"
1173 problem, what we'll do here is just uninsert the bp_finish, and
1174 let finish_command delete it.
1176 (We know the bp_finish is "doomed" in the sense that it's
1177 momentary, and will be deleted as soon as finish_command sees
1178 the inferior stopped. So it doesn't matter that the bp's
1179 address is probably bogus in the new a.out, unlike e.g., the
1180 solib breakpoints.) */
1182 if (b->type == bp_finish)
1187 /* Without a symbolic address, we have little hope of the
1188 pre-exec() address meaning the same thing in the post-exec()
1190 if (b->addr_string == NULL)
1192 delete_breakpoint (b);
1196 /* If this breakpoint has survived the above battery of checks, then
1197 it must have a symbolic address. Be sure that it gets reevaluated
1198 to a target address, rather than reusing the old evaluation. */
1199 b->address = (CORE_ADDR) NULL;
1204 detach_breakpoints (int pid)
1206 register struct breakpoint *b;
1208 ptid_t saved_inferior_ptid = inferior_ptid;
1210 if (pid == PIDGET (inferior_ptid))
1211 error ("Cannot detach breakpoints of inferior_ptid");
1213 /* FIXME: use a cleanup, to insure that inferior_ptid gets replaced! */
1214 inferior_ptid = pid_to_ptid (pid); /* Because remove_breakpoint will use this global. */
1219 val = remove_breakpoint (b, mark_inserted);
1222 inferior_ptid = saved_inferior_ptid;
1227 inferior_ptid = saved_inferior_ptid;
1232 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1236 if (b->enable == permanent)
1237 /* Permanent breakpoints cannot be inserted or removed. */
1240 if (b->type == bp_none)
1241 warning ("attempted to remove apparently deleted breakpoint #%d?",
1244 if (b->type != bp_watchpoint
1245 && b->type != bp_hardware_watchpoint
1246 && b->type != bp_read_watchpoint
1247 && b->type != bp_access_watchpoint
1248 && b->type != bp_catch_fork
1249 && b->type != bp_catch_vfork
1250 && b->type != bp_catch_exec
1251 && b->type != bp_catch_catch
1252 && b->type != bp_catch_throw)
1254 if (b->type == bp_hardware_breakpoint)
1255 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1258 /* Check to see if breakpoint is in an overlay section;
1259 if so, we should remove the breakpoint at the LMA address.
1260 If that is not equal to the raw address, then we should
1261 presumably remove the breakpoint there as well. */
1262 if (overlay_debugging && b->section &&
1263 section_is_overlay (b->section))
1267 addr = overlay_unmapped_address (b->address, b->section);
1268 val = target_remove_breakpoint (addr, b->shadow_contents);
1269 /* This would be the time to check val, to see if the
1270 shadow breakpoint write to the load address succeeded.
1271 However, this might be an ordinary occurrance, eg. if
1272 the unmapped overlay is in ROM. */
1273 val = 0; /* in case unmapped address failed */
1274 if (section_is_mapped (b->section))
1275 val = target_remove_breakpoint (b->address,
1276 b->shadow_contents);
1278 else /* ordinary (non-overlay) address */
1279 val = target_remove_breakpoint (b->address, b->shadow_contents);
1283 b->inserted = (is == mark_inserted);
1285 else if ((b->type == bp_hardware_watchpoint ||
1286 b->type == bp_read_watchpoint ||
1287 b->type == bp_access_watchpoint)
1288 && b->enable == enabled
1293 b->inserted = (is == mark_inserted);
1294 /* Walk down the saved value chain. */
1295 for (v = b->val_chain; v; v = v->next)
1297 /* For each memory reference remove the watchpoint
1299 if (VALUE_LVAL (v) == lval_memory
1300 && ! VALUE_LAZY (v))
1302 struct type *vtype = check_typedef (VALUE_TYPE (v));
1304 if (v == b->val_chain
1305 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1306 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1311 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1312 len = TYPE_LENGTH (VALUE_TYPE (v));
1314 if (b->type == bp_read_watchpoint)
1316 else if (b->type == bp_access_watchpoint)
1319 val = target_remove_watchpoint (addr, len, type);
1326 /* Failure to remove any of the hardware watchpoints comes here. */
1327 if ((is == mark_uninserted) && (b->inserted))
1328 warning ("Could not remove hardware watchpoint %d.",
1331 /* Free the saved value chain. We will construct a new one
1332 the next time the watchpoint is inserted. */
1333 for (v = b->val_chain; v; v = n)
1338 b->val_chain = NULL;
1340 else if ((b->type == bp_catch_fork ||
1341 b->type == bp_catch_vfork ||
1342 b->type == bp_catch_exec)
1343 && b->enable == enabled
1350 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1352 case bp_catch_vfork:
1353 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1356 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1359 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1364 b->inserted = (is == mark_inserted);
1366 else if ((b->type == bp_catch_catch ||
1367 b->type == bp_catch_throw)
1368 && b->enable == enabled
1372 val = target_remove_breakpoint (b->address, b->shadow_contents);
1375 b->inserted = (is == mark_inserted);
1377 else if (ep_is_exception_catchpoint (b)
1378 && b->inserted /* sometimes previous insert doesn't happen */
1379 && b->enable == enabled
1383 val = target_remove_breakpoint (b->address, b->shadow_contents);
1387 b->inserted = (is == mark_inserted);
1393 /* Clear the "inserted" flag in all breakpoints. */
1396 mark_breakpoints_out (void)
1398 register struct breakpoint *b;
1404 /* Clear the "inserted" flag in all breakpoints and delete any
1405 breakpoints which should go away between runs of the program.
1407 Plus other such housekeeping that has to be done for breakpoints
1410 Note: this function gets called at the end of a run (by
1411 generic_mourn_inferior) and when a run begins (by
1412 init_wait_for_inferior). */
1417 breakpoint_init_inferior (enum inf_context context)
1419 register struct breakpoint *b, *temp;
1420 static int warning_needed = 0;
1422 ALL_BREAKPOINTS_SAFE (b, temp)
1429 case bp_watchpoint_scope:
1431 /* If the call dummy breakpoint is at the entry point it will
1432 cause problems when the inferior is rerun, so we better
1435 Also get rid of scope breakpoints. */
1436 delete_breakpoint (b);
1440 case bp_hardware_watchpoint:
1441 case bp_read_watchpoint:
1442 case bp_access_watchpoint:
1444 /* Likewise for watchpoints on local expressions. */
1445 if (b->exp_valid_block != NULL)
1446 delete_breakpoint (b);
1449 /* Likewise for exception catchpoints in dynamic-linked
1450 executables where required */
1451 if (ep_is_exception_catchpoint (b) &&
1452 exception_catchpoints_are_fragile)
1455 delete_breakpoint (b);
1461 if (exception_catchpoints_are_fragile)
1462 exception_support_initialized = 0;
1464 /* Don't issue the warning unless it's really needed... */
1465 if (warning_needed && (context != inf_exited))
1467 warning ("Exception catchpoints from last run were deleted.");
1468 warning ("You must reinsert them explicitly.");
1473 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1474 exists at PC. It returns ordinary_breakpoint_here if it's an
1475 ordinary breakpoint, or permanent_breakpoint_here if it's a
1476 permanent breakpoint.
1477 - When continuing from a location with an ordinary breakpoint, we
1478 actually single step once before calling insert_breakpoints.
1479 - When continuing from a localion with a permanent breakpoint, we
1480 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1481 the target, to advance the PC past the breakpoint. */
1483 enum breakpoint_here
1484 breakpoint_here_p (CORE_ADDR pc)
1486 register struct breakpoint *b;
1487 int any_breakpoint_here = 0;
1490 if ((b->enable == enabled
1491 || b->enable == permanent)
1492 && b->address == pc) /* bp is enabled and matches pc */
1494 if (overlay_debugging &&
1495 section_is_overlay (b->section) &&
1496 !section_is_mapped (b->section))
1497 continue; /* unmapped overlay -- can't be a match */
1498 else if (b->enable == permanent)
1499 return permanent_breakpoint_here;
1501 any_breakpoint_here = 1;
1504 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1508 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1509 but it only returns true if there is actually a breakpoint inserted
1513 breakpoint_inserted_here_p (CORE_ADDR pc)
1515 register struct breakpoint *b;
1519 && b->address == pc) /* bp is inserted and matches pc */
1521 if (overlay_debugging &&
1522 section_is_overlay (b->section) &&
1523 !section_is_mapped (b->section))
1524 continue; /* unmapped overlay -- can't be a match */
1532 /* Return nonzero if FRAME is a dummy frame. We can't use
1533 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1534 much time, at least using get_saved_register on the 68k. This
1535 means that for this function to work right a port must use the
1536 bp_call_dummy breakpoint. */
1539 frame_in_dummy (struct frame_info *frame)
1541 struct breakpoint *b;
1546 if (USE_GENERIC_DUMMY_FRAMES)
1547 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1551 if (b->type == bp_call_dummy
1552 && b->frame == frame->frame
1553 /* We need to check the PC as well as the frame on the sparc,
1554 for signals.exp in the testsuite. */
1557 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1558 && frame->pc <= b->address)
1564 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1565 PC is valid for process/thread PID. */
1568 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1570 struct breakpoint *b;
1573 thread = pid_to_thread_id (ptid);
1576 if (b->enable != disabled
1577 && b->enable != shlib_disabled
1578 && b->enable != call_disabled
1580 && (b->thread == -1 || b->thread == thread))
1582 if (overlay_debugging &&
1583 section_is_overlay (b->section) &&
1584 !section_is_mapped (b->section))
1585 continue; /* unmapped overlay -- can't be a match */
1594 /* bpstat stuff. External routines' interfaces are documented
1598 ep_is_catchpoint (struct breakpoint *ep)
1601 (ep->type == bp_catch_load)
1602 || (ep->type == bp_catch_unload)
1603 || (ep->type == bp_catch_fork)
1604 || (ep->type == bp_catch_vfork)
1605 || (ep->type == bp_catch_exec)
1606 || (ep->type == bp_catch_catch)
1607 || (ep->type == bp_catch_throw);
1609 /* ??rehrauer: Add more kinds here, as are implemented... */
1613 ep_is_shlib_catchpoint (struct breakpoint *ep)
1616 (ep->type == bp_catch_load)
1617 || (ep->type == bp_catch_unload);
1621 ep_is_exception_catchpoint (struct breakpoint *ep)
1624 (ep->type == bp_catch_catch)
1625 || (ep->type == bp_catch_throw);
1628 /* Clear a bpstat so that it says we are not at any breakpoint.
1629 Also free any storage that is part of a bpstat. */
1632 bpstat_clear (bpstat *bsp)
1643 if (p->old_val != NULL)
1644 value_free (p->old_val);
1651 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1652 is part of the bpstat is copied as well. */
1655 bpstat_copy (bpstat bs)
1659 bpstat retval = NULL;
1664 for (; bs != NULL; bs = bs->next)
1666 tmp = (bpstat) xmalloc (sizeof (*tmp));
1667 memcpy (tmp, bs, sizeof (*tmp));
1669 /* This is the first thing in the chain. */
1679 /* Find the bpstat associated with this breakpoint */
1682 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1687 for (; bsp != NULL; bsp = bsp->next)
1689 if (bsp->breakpoint_at == breakpoint)
1695 /* Find a step_resume breakpoint associated with this bpstat.
1696 (If there are multiple step_resume bp's on the list, this function
1697 will arbitrarily pick one.)
1699 It is an error to use this function if BPSTAT doesn't contain a
1700 step_resume breakpoint.
1702 See wait_for_inferior's use of this function. */
1704 bpstat_find_step_resume_breakpoint (bpstat bsp)
1707 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1709 for (; bsp != NULL; bsp = bsp->next)
1711 if ((bsp->breakpoint_at != NULL) &&
1712 (bsp->breakpoint_at->type == bp_step_resume))
1713 return bsp->breakpoint_at;
1716 error ("Internal error (no step_resume breakpoint found)");
1720 /* Return the breakpoint number of the first breakpoint we are stopped
1721 at. *BSP upon return is a bpstat which points to the remaining
1722 breakpoints stopped at (but which is not guaranteed to be good for
1723 anything but further calls to bpstat_num).
1724 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1727 bpstat_num (bpstat *bsp)
1729 struct breakpoint *b;
1732 return 0; /* No more breakpoint values */
1735 b = (*bsp)->breakpoint_at;
1736 *bsp = (*bsp)->next;
1738 return -1; /* breakpoint that's been deleted since */
1740 return b->number; /* We have its number */
1744 /* Modify BS so that the actions will not be performed. */
1747 bpstat_clear_actions (bpstat bs)
1749 for (; bs != NULL; bs = bs->next)
1751 bs->commands = NULL;
1752 if (bs->old_val != NULL)
1754 value_free (bs->old_val);
1760 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1763 cleanup_executing_breakpoints (PTR ignore)
1765 executing_breakpoint_commands = 0;
1768 /* Execute all the commands associated with all the breakpoints at this
1769 location. Any of these commands could cause the process to proceed
1770 beyond this point, etc. We look out for such changes by checking
1771 the global "breakpoint_proceeded" after each command. */
1774 bpstat_do_actions (bpstat *bsp)
1777 struct cleanup *old_chain;
1778 struct command_line *cmd;
1780 /* Avoid endless recursion if a `source' command is contained
1782 if (executing_breakpoint_commands)
1785 executing_breakpoint_commands = 1;
1786 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1789 /* Note that (as of this writing), our callers all appear to
1790 be passing us the address of global stop_bpstat. And, if
1791 our calls to execute_control_command cause the inferior to
1792 proceed, that global (and hence, *bsp) will change.
1794 We must be careful to not touch *bsp unless the inferior
1795 has not proceeded. */
1797 /* This pointer will iterate over the list of bpstat's. */
1800 breakpoint_proceeded = 0;
1801 for (; bs != NULL; bs = bs->next)
1806 execute_control_command (cmd);
1808 if (breakpoint_proceeded)
1813 if (breakpoint_proceeded)
1814 /* The inferior is proceeded by the command; bomb out now.
1815 The bpstat chain has been blown away by wait_for_inferior.
1816 But since execution has stopped again, there is a new bpstat
1817 to look at, so start over. */
1820 bs->commands = NULL;
1823 executing_breakpoint_commands = 0;
1824 discard_cleanups (old_chain);
1827 /* This is the normal print function for a bpstat. In the future,
1828 much of this logic could (should?) be moved to bpstat_stop_status,
1829 by having it set different print_it values.
1831 Current scheme: When we stop, bpstat_print() is called. It loops
1832 through the bpstat list of things causing this stop, calling the
1833 print_bp_stop_message function on each one. The behavior of the
1834 print_bp_stop_message function depends on the print_it field of
1835 bpstat. If such field so indicates, call this function here.
1837 Return values from this routine (ultimately used by bpstat_print()
1838 and normal_stop() to decide what to do):
1839 PRINT_NOTHING: Means we already printed all we needed to print,
1840 don't print anything else.
1841 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1842 that something to be followed by a location.
1843 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1844 that something to be followed by a location.
1845 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1848 static enum print_stop_action
1849 print_it_typical (bpstat bs)
1852 struct cleanup *old_chain;
1853 struct ui_stream *stb;
1854 stb = ui_out_stream_new (uiout);
1855 old_chain = make_cleanup_ui_out_stream_delete (stb);
1857 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1858 which has since been deleted. */
1859 if (bs->breakpoint_at == NULL)
1860 return PRINT_UNKNOWN;
1862 switch (bs->breakpoint_at->type)
1865 case bp_hardware_breakpoint:
1867 annotate_breakpoint (bs->breakpoint_at->number);
1868 ui_out_text (uiout, "\nBreakpoint ");
1869 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
1870 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1871 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1872 ui_out_text (uiout, ", ");
1873 return PRINT_SRC_AND_LOC;
1875 /* I think the user probably only wants to see one breakpoint
1876 number, not all of them. */
1877 annotate_breakpoint (bs->breakpoint_at->number);
1878 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1879 return PRINT_SRC_AND_LOC;
1883 case bp_shlib_event:
1884 /* Did we stop because the user set the stop_on_solib_events
1885 variable? (If so, we report this as a generic, "Stopped due
1886 to shlib event" message.) */
1887 printf_filtered ("Stopped due to shared library event\n");
1888 return PRINT_NOTHING;
1891 case bp_thread_event:
1892 /* Not sure how we will get here.
1893 GDB should not stop for these breakpoints. */
1894 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1895 return PRINT_NOTHING;
1899 annotate_catchpoint (bs->breakpoint_at->number);
1900 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1901 printf_filtered ("loaded");
1902 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1903 return PRINT_SRC_AND_LOC;
1906 case bp_catch_unload:
1907 annotate_catchpoint (bs->breakpoint_at->number);
1908 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1909 printf_filtered ("unloaded");
1910 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1911 return PRINT_SRC_AND_LOC;
1915 annotate_catchpoint (bs->breakpoint_at->number);
1916 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1917 printf_filtered ("forked");
1918 printf_filtered (" process %d), ",
1919 bs->breakpoint_at->forked_inferior_pid);
1920 return PRINT_SRC_AND_LOC;
1923 case bp_catch_vfork:
1924 annotate_catchpoint (bs->breakpoint_at->number);
1925 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1926 printf_filtered ("vforked");
1927 printf_filtered (" process %d), ",
1928 bs->breakpoint_at->forked_inferior_pid);
1929 return PRINT_SRC_AND_LOC;
1933 annotate_catchpoint (bs->breakpoint_at->number);
1934 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1935 bs->breakpoint_at->number,
1936 bs->breakpoint_at->exec_pathname);
1937 return PRINT_SRC_AND_LOC;
1940 case bp_catch_catch:
1941 if (current_exception_event &&
1942 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1944 annotate_catchpoint (bs->breakpoint_at->number);
1945 printf_filtered ("\nCatchpoint %d (exception caught), ",
1946 bs->breakpoint_at->number);
1947 printf_filtered ("throw location ");
1948 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1949 printf_filtered ("%s:%d",
1950 CURRENT_EXCEPTION_THROW_FILE,
1951 CURRENT_EXCEPTION_THROW_LINE);
1953 printf_filtered ("unknown");
1955 printf_filtered (", catch location ");
1956 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1957 printf_filtered ("%s:%d",
1958 CURRENT_EXCEPTION_CATCH_FILE,
1959 CURRENT_EXCEPTION_CATCH_LINE);
1961 printf_filtered ("unknown");
1963 printf_filtered ("\n");
1964 /* don't bother to print location frame info */
1965 return PRINT_SRC_ONLY;
1969 /* really throw, some other bpstat will handle it */
1970 return PRINT_UNKNOWN;
1974 case bp_catch_throw:
1975 if (current_exception_event &&
1976 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1978 annotate_catchpoint (bs->breakpoint_at->number);
1979 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1980 bs->breakpoint_at->number);
1981 printf_filtered ("throw location ");
1982 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1983 printf_filtered ("%s:%d",
1984 CURRENT_EXCEPTION_THROW_FILE,
1985 CURRENT_EXCEPTION_THROW_LINE);
1987 printf_filtered ("unknown");
1989 printf_filtered (", catch location ");
1990 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1991 printf_filtered ("%s:%d",
1992 CURRENT_EXCEPTION_CATCH_FILE,
1993 CURRENT_EXCEPTION_CATCH_LINE);
1995 printf_filtered ("unknown");
1997 printf_filtered ("\n");
1998 /* don't bother to print location frame info */
1999 return PRINT_SRC_ONLY;
2003 /* really catch, some other bpstat will handle it */
2004 return PRINT_UNKNOWN;
2009 case bp_hardware_watchpoint:
2010 if (bs->old_val != NULL)
2012 annotate_watchpoint (bs->breakpoint_at->number);
2014 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2015 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2016 mention (bs->breakpoint_at);
2017 ui_out_list_begin (uiout, "value");
2018 ui_out_text (uiout, "\nOld value = ");
2019 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2020 ui_out_field_stream (uiout, "old", stb);
2021 ui_out_text (uiout, "\nNew value = ");
2022 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2023 ui_out_field_stream (uiout, "new", stb);
2024 ui_out_list_end (uiout);
2025 ui_out_text (uiout, "\n");
2027 mention (bs->breakpoint_at);
2028 printf_filtered ("\nOld value = ");
2029 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2030 printf_filtered ("\nNew value = ");
2031 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2032 Val_pretty_default);
2033 printf_filtered ("\n");
2035 value_free (bs->old_val);
2038 /* More than one watchpoint may have been triggered. */
2039 return PRINT_UNKNOWN;
2042 case bp_read_watchpoint:
2044 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2045 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2046 mention (bs->breakpoint_at);
2047 ui_out_list_begin (uiout, "value");
2048 ui_out_text (uiout, "\nValue = ");
2049 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2050 ui_out_field_stream (uiout, "value", stb);
2051 ui_out_list_end (uiout);
2052 ui_out_text (uiout, "\n");
2054 mention (bs->breakpoint_at);
2055 printf_filtered ("\nValue = ");
2056 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2057 Val_pretty_default);
2058 printf_filtered ("\n");
2060 return PRINT_UNKNOWN;
2063 case bp_access_watchpoint:
2065 if (bs->old_val != NULL)
2067 annotate_watchpoint (bs->breakpoint_at->number);
2068 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2069 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2070 mention (bs->breakpoint_at);
2071 ui_out_list_begin (uiout, "value");
2072 ui_out_text (uiout, "\nOld value = ");
2073 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2074 ui_out_field_stream (uiout, "old", stb);
2075 value_free (bs->old_val);
2077 ui_out_text (uiout, "\nNew value = ");
2081 mention (bs->breakpoint_at);
2082 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2083 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2084 ui_out_list_begin (uiout, "value");
2085 ui_out_text (uiout, "\nValue = ");
2087 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2088 ui_out_field_stream (uiout, "new", stb);
2089 ui_out_list_end (uiout);
2090 ui_out_text (uiout, "\n");
2092 if (bs->old_val != NULL)
2094 annotate_watchpoint (bs->breakpoint_at->number);
2095 mention (bs->breakpoint_at);
2096 printf_filtered ("\nOld value = ");
2097 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2098 value_free (bs->old_val);
2100 printf_filtered ("\nNew value = ");
2104 mention (bs->breakpoint_at);
2105 printf_filtered ("\nValue = ");
2107 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2108 Val_pretty_default);
2109 printf_filtered ("\n");
2111 return PRINT_UNKNOWN;
2114 /* Fall through, we don't deal with these types of breakpoints
2119 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2120 ui_out_field_string (uiout, "reason", "function-finished");
2122 return PRINT_UNKNOWN;
2127 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2128 ui_out_field_string (uiout, "reason", "location-reached");
2130 return PRINT_UNKNOWN;
2135 case bp_longjmp_resume:
2136 case bp_step_resume:
2137 case bp_through_sigtramp:
2138 case bp_watchpoint_scope:
2141 return PRINT_UNKNOWN;
2145 /* Generic routine for printing messages indicating why we
2146 stopped. The behavior of this function depends on the value
2147 'print_it' in the bpstat structure. Under some circumstances we
2148 may decide not to print anything here and delegate the task to
2151 static enum print_stop_action
2152 print_bp_stop_message (bpstat bs)
2154 switch (bs->print_it)
2157 /* Nothing should be printed for this bpstat entry. */
2158 return PRINT_UNKNOWN;
2162 /* We still want to print the frame, but we already printed the
2163 relevant messages. */
2164 return PRINT_SRC_AND_LOC;
2167 case print_it_normal:
2168 /* Normal case, we handle everything in print_it_typical. */
2169 return print_it_typical (bs);
2172 internal_error (__FILE__, __LINE__,
2173 "print_bp_stop_message: unrecognized enum value");
2178 /* Print a message indicating what happened. This is called from
2179 normal_stop(). The input to this routine is the head of the bpstat
2180 list - a list of the eventpoints that caused this stop. This
2181 routine calls the generic print routine for printing a message
2182 about reasons for stopping. This will print (for example) the
2183 "Breakpoint n," part of the output. The return value of this
2186 PRINT_UNKNOWN: Means we printed nothing
2187 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2188 code to print the location. An example is
2189 "Breakpoint 1, " which should be followed by
2191 PRINT_SRC_ONLY: Means we printed something, but there is no need
2192 to also print the location part of the message.
2193 An example is the catch/throw messages, which
2194 don't require a location appended to the end.
2195 PRINT_NOTHING: We have done some printing and we don't need any
2196 further info to be printed.*/
2198 enum print_stop_action
2199 bpstat_print (bpstat bs)
2203 /* Maybe another breakpoint in the chain caused us to stop.
2204 (Currently all watchpoints go on the bpstat whether hit or not.
2205 That probably could (should) be changed, provided care is taken
2206 with respect to bpstat_explains_signal). */
2207 for (; bs; bs = bs->next)
2209 val = print_bp_stop_message (bs);
2210 if (val == PRINT_SRC_ONLY
2211 || val == PRINT_SRC_AND_LOC
2212 || val == PRINT_NOTHING)
2216 /* We reached the end of the chain, or we got a null BS to start
2217 with and nothing was printed. */
2218 return PRINT_UNKNOWN;
2221 /* Evaluate the expression EXP and return 1 if value is zero.
2222 This is used inside a catch_errors to evaluate the breakpoint condition.
2223 The argument is a "struct expression *" that has been cast to char * to
2224 make it pass through catch_errors. */
2227 breakpoint_cond_eval (PTR exp)
2229 value_ptr mark = value_mark ();
2230 int i = !value_true (evaluate_expression ((struct expression *) exp));
2231 value_free_to_mark (mark);
2235 /* Allocate a new bpstat and chain it to the current one. */
2238 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2242 bs = (bpstat) xmalloc (sizeof (*bs));
2244 bs->breakpoint_at = b;
2245 /* If the condition is false, etc., don't do the commands. */
2246 bs->commands = NULL;
2248 bs->print_it = print_it_normal;
2252 /* Possible return values for watchpoint_check (this can't be an enum
2253 because of check_errors). */
2254 /* The watchpoint has been deleted. */
2255 #define WP_DELETED 1
2256 /* The value has changed. */
2257 #define WP_VALUE_CHANGED 2
2258 /* The value has not changed. */
2259 #define WP_VALUE_NOT_CHANGED 3
2261 #define BP_TEMPFLAG 1
2262 #define BP_HARDWAREFLAG 2
2264 /* Check watchpoint condition. */
2267 watchpoint_check (PTR p)
2269 bpstat bs = (bpstat) p;
2270 struct breakpoint *b;
2271 struct frame_info *fr;
2272 int within_current_scope;
2274 b = bs->breakpoint_at;
2276 if (b->exp_valid_block == NULL)
2277 within_current_scope = 1;
2280 /* There is no current frame at this moment. If we're going to have
2281 any chance of handling watchpoints on local variables, we'll need
2282 the frame chain (so we can determine if we're in scope). */
2283 reinit_frame_cache ();
2284 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2285 within_current_scope = (fr != NULL);
2286 if (within_current_scope)
2287 /* If we end up stopping, the current frame will get selected
2288 in normal_stop. So this call to select_frame won't affect
2290 select_frame (fr, -1);
2293 if (within_current_scope)
2295 /* We use value_{,free_to_}mark because it could be a
2296 *long* time before we return to the command level and
2297 call free_all_values. We can't call free_all_values because
2298 we might be in the middle of evaluating a function call. */
2300 value_ptr mark = value_mark ();
2301 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2302 if (!value_equal (b->val, new_val))
2304 release_value (new_val);
2305 value_free_to_mark (mark);
2306 bs->old_val = b->val;
2308 /* We will stop here */
2309 return WP_VALUE_CHANGED;
2313 /* Nothing changed, don't do anything. */
2314 value_free_to_mark (mark);
2315 /* We won't stop here */
2316 return WP_VALUE_NOT_CHANGED;
2321 /* This seems like the only logical thing to do because
2322 if we temporarily ignored the watchpoint, then when
2323 we reenter the block in which it is valid it contains
2324 garbage (in the case of a function, it may have two
2325 garbage values, one before and one after the prologue).
2326 So we can't even detect the first assignment to it and
2327 watch after that (since the garbage may or may not equal
2328 the first value assigned). */
2329 /* We print all the stop information in print_it_typical(), but
2330 in this case, by the time we call print_it_typical() this bp
2331 will be deleted already. So we have no choice but print the
2332 information here. */
2334 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2335 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2336 ui_out_text (uiout, "\nWatchpoint ");
2337 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2338 ui_out_text (uiout, " deleted because the program has left the block in\n\
2339 which its expression is valid.\n");
2342 Watchpoint %d deleted because the program has left the block in\n\
2343 which its expression is valid.\n", bs->breakpoint_at->number);
2346 if (b->related_breakpoint)
2347 b->related_breakpoint->disposition = del_at_next_stop;
2348 b->disposition = del_at_next_stop;
2354 /* Get a bpstat associated with having just stopped at address *PC
2355 and frame address CORE_ADDRESS. Update *PC to point at the
2356 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2357 if this is known to not be a real breakpoint (it could still be a
2358 watchpoint, though). */
2360 /* Determine whether we stopped at a breakpoint, etc, or whether we
2361 don't understand this stop. Result is a chain of bpstat's such that:
2363 if we don't understand the stop, the result is a null pointer.
2365 if we understand why we stopped, the result is not null.
2367 Each element of the chain refers to a particular breakpoint or
2368 watchpoint at which we have stopped. (We may have stopped for
2369 several reasons concurrently.)
2371 Each element of the chain has valid next, breakpoint_at,
2372 commands, FIXME??? fields. */
2375 bpstat_stop_status (CORE_ADDR *pc, int not_a_breakpoint)
2377 register struct breakpoint *b, *temp;
2379 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2380 int real_breakpoint = 0;
2381 /* Root of the chain of bpstat's */
2382 struct bpstats root_bs[1];
2383 /* Pointer to the last thing in the chain currently. */
2384 bpstat bs = root_bs;
2385 static char message1[] =
2386 "Error evaluating expression for watchpoint %d\n";
2387 char message[sizeof (message1) + 30 /* slop */ ];
2389 /* Get the address where the breakpoint would have been. */
2390 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P () ?
2391 0 : DECR_PC_AFTER_BREAK);
2393 ALL_BREAKPOINTS_SAFE (b, temp)
2395 if (b->enable == disabled
2396 || b->enable == shlib_disabled
2397 || b->enable == call_disabled)
2400 if (b->type != bp_watchpoint
2401 && b->type != bp_hardware_watchpoint
2402 && b->type != bp_read_watchpoint
2403 && b->type != bp_access_watchpoint
2404 && b->type != bp_hardware_breakpoint
2405 && b->type != bp_catch_fork
2406 && b->type != bp_catch_vfork
2407 && b->type != bp_catch_exec
2408 && b->type != bp_catch_catch
2409 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2410 if (b->address != bp_addr || /* address doesn't match or */
2411 (overlay_debugging && /* overlay doesn't match */
2412 section_is_overlay (b->section) &&
2413 !section_is_mapped (b->section)))
2416 if (b->type == bp_hardware_breakpoint
2417 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2420 /* Is this a catchpoint of a load or unload? If so, did we
2421 get a load or unload of the specified library? If not,
2423 if ((b->type == bp_catch_load)
2424 #if defined(SOLIB_HAVE_LOAD_EVENT)
2425 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2426 || ((b->dll_pathname != NULL)
2427 && (strcmp (b->dll_pathname,
2428 SOLIB_LOADED_LIBRARY_PATHNAME (
2429 PIDGET (inferior_ptid)))
2435 if ((b->type == bp_catch_unload)
2436 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2437 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2438 || ((b->dll_pathname != NULL)
2439 && (strcmp (b->dll_pathname,
2440 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2441 PIDGET (inferior_ptid)))
2447 if ((b->type == bp_catch_fork)
2448 && !target_has_forked (PIDGET (inferior_ptid),
2449 &b->forked_inferior_pid))
2452 if ((b->type == bp_catch_vfork)
2453 && !target_has_vforked (PIDGET (inferior_ptid),
2454 &b->forked_inferior_pid))
2457 if ((b->type == bp_catch_exec)
2458 && !target_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2461 if (ep_is_exception_catchpoint (b) &&
2462 !(current_exception_event = target_get_current_exception_event ()))
2465 /* Come here if it's a watchpoint, or if the break address matches */
2467 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2469 /* Watchpoints may change this, if not found to have triggered. */
2473 sprintf (message, message1, b->number);
2474 if (b->type == bp_watchpoint ||
2475 b->type == bp_hardware_watchpoint)
2477 switch (catch_errors (watchpoint_check, bs, message,
2481 /* We've already printed what needs to be printed. */
2482 /* Actually this is superfluous, because by the time we
2483 call print_it_typical() the wp will be already deleted,
2484 and the function will return immediately. */
2485 bs->print_it = print_it_done;
2488 case WP_VALUE_CHANGED:
2492 case WP_VALUE_NOT_CHANGED:
2494 bs->print_it = print_it_noop;
2501 /* Error from catch_errors. */
2502 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2503 if (b->related_breakpoint)
2504 b->related_breakpoint->disposition = del_at_next_stop;
2505 b->disposition = del_at_next_stop;
2506 /* We've already printed what needs to be printed. */
2507 bs->print_it = print_it_done;
2513 else if (b->type == bp_read_watchpoint ||
2514 b->type == bp_access_watchpoint)
2520 addr = target_stopped_data_address ();
2523 for (v = b->val_chain; v; v = v->next)
2525 if (VALUE_LVAL (v) == lval_memory
2526 && ! VALUE_LAZY (v))
2528 struct type *vtype = check_typedef (VALUE_TYPE (v));
2530 if (v == b->val_chain
2531 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2532 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2536 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2537 /* Exact match not required. Within range is
2539 if (addr >= vaddr &&
2540 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2546 switch (catch_errors (watchpoint_check, bs, message,
2550 /* We've already printed what needs to be printed. */
2551 bs->print_it = print_it_done;
2554 case WP_VALUE_CHANGED:
2555 if (b->type == bp_read_watchpoint)
2557 /* Don't stop: read watchpoints shouldn't fire if
2558 the value has changed. This is for targets which
2559 cannot set read-only watchpoints. */
2560 bs->print_it = print_it_noop;
2566 case WP_VALUE_NOT_CHANGED:
2573 /* Error from catch_errors. */
2574 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2575 if (b->related_breakpoint)
2576 b->related_breakpoint->disposition = del_at_next_stop;
2577 b->disposition = del_at_next_stop;
2578 /* We've already printed what needs to be printed. */
2579 bs->print_it = print_it_done;
2582 else /* found == 0 */
2584 /* This is a case where some watchpoint(s) triggered,
2585 but not at the address of this watchpoint (FOUND
2586 was left zero). So don't print anything for this
2588 bs->print_it = print_it_noop;
2595 /* By definition, an encountered breakpoint is a triggered
2599 real_breakpoint = 1;
2603 b->frame != (get_current_frame ())->frame)
2607 int value_is_zero = 0;
2611 /* Need to select the frame, with all that implies
2612 so that the conditions will have the right context. */
2613 select_frame (get_current_frame (), 0);
2615 = catch_errors (breakpoint_cond_eval, (b->cond),
2616 "Error in testing breakpoint condition:\n",
2618 /* FIXME-someday, should give breakpoint # */
2621 if (b->cond && value_is_zero)
2624 /* Don't consider this a hit. */
2627 else if (b->ignore_count > 0)
2630 annotate_ignore_count_change ();
2635 /* We will stop here */
2636 if (b->disposition == disable)
2637 b->enable = disabled;
2638 bs->commands = b->commands;
2642 (STREQ ("silent", bs->commands->line) ||
2643 (xdb_commands && STREQ ("Q", bs->commands->line))))
2645 bs->commands = bs->commands->next;
2650 /* Print nothing for this entry if we dont stop or if we dont print. */
2651 if (bs->stop == 0 || bs->print == 0)
2652 bs->print_it = print_it_noop;
2655 bs->next = NULL; /* Terminate the chain */
2656 bs = root_bs->next; /* Re-grab the head of the chain */
2658 if (real_breakpoint && bs)
2660 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2662 if (DECR_PC_AFTER_HW_BREAK != 0)
2664 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2670 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2673 #if defined (SHIFT_INST_REGS)
2675 #else /* No SHIFT_INST_REGS. */
2677 #endif /* No SHIFT_INST_REGS. */
2682 /* The value of a hardware watchpoint hasn't changed, but the
2683 intermediate memory locations we are watching may have. */
2684 if (bs && !bs->stop &&
2685 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2686 bs->breakpoint_at->type == bp_read_watchpoint ||
2687 bs->breakpoint_at->type == bp_access_watchpoint))
2689 remove_breakpoints ();
2690 insert_breakpoints ();
2695 /* Tell what to do about this bpstat. */
2697 bpstat_what (bpstat bs)
2699 /* Classify each bpstat as one of the following. */
2702 /* This bpstat element has no effect on the main_action. */
2705 /* There was a watchpoint, stop but don't print. */
2708 /* There was a watchpoint, stop and print. */
2711 /* There was a breakpoint but we're not stopping. */
2714 /* There was a breakpoint, stop but don't print. */
2717 /* There was a breakpoint, stop and print. */
2720 /* We hit the longjmp breakpoint. */
2723 /* We hit the longjmp_resume breakpoint. */
2726 /* We hit the step_resume breakpoint. */
2729 /* We hit the through_sigtramp breakpoint. */
2732 /* We hit the shared library event breakpoint. */
2735 /* We caught a shared library event. */
2738 /* This is just used to count how many enums there are. */
2742 /* Here is the table which drives this routine. So that we can
2743 format it pretty, we define some abbreviations for the
2744 enum bpstat_what codes. */
2745 #define kc BPSTAT_WHAT_KEEP_CHECKING
2746 #define ss BPSTAT_WHAT_STOP_SILENT
2747 #define sn BPSTAT_WHAT_STOP_NOISY
2748 #define sgl BPSTAT_WHAT_SINGLE
2749 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2750 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2751 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2752 #define sr BPSTAT_WHAT_STEP_RESUME
2753 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2754 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2755 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2757 /* "Can't happen." Might want to print an error message.
2758 abort() is not out of the question, but chances are GDB is just
2759 a bit confused, not unusable. */
2760 #define err BPSTAT_WHAT_STOP_NOISY
2762 /* Given an old action and a class, come up with a new action. */
2763 /* One interesting property of this table is that wp_silent is the same
2764 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2765 after stopping, the check for whether to step over a breakpoint
2766 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2767 reference to how we stopped. We retain separate wp_silent and
2768 bp_silent codes in case we want to change that someday.
2770 Another possibly interesting property of this table is that
2771 there's a partial ordering, priority-like, of the actions. Once
2772 you've decided that some action is appropriate, you'll never go
2773 back and decide something of a lower priority is better. The
2776 kc < clr sgl shl shlr slr sn sr ss ts
2777 sgl < clrs shl shlr slr sn sr ss ts
2778 slr < err shl shlr sn sr ss ts
2779 clr < clrs err shl shlr sn sr ss ts
2780 clrs < err shl shlr sn sr ss ts
2781 ss < shl shlr sn sr ts
2788 What I think this means is that we don't need a damned table
2789 here. If you just put the rows and columns in the right order,
2790 it'd look awfully regular. We could simply walk the bpstat list
2791 and choose the highest priority action we find, with a little
2792 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2793 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2794 is messy anyway). */
2796 /* step_resume entries: a step resume breakpoint overrides another
2797 breakpoint of signal handling (see comment in wait_for_inferior
2798 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2799 /* We handle the through_sigtramp_breakpoint the same way; having both
2800 one of those and a step_resume_breakpoint is probably very rare (?). */
2802 static const enum bpstat_what_main_action
2803 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2806 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2809 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2811 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2813 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2815 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2817 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2819 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2821 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2823 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2825 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2827 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2829 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2831 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2846 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2847 struct bpstat_what retval;
2849 retval.call_dummy = 0;
2850 for (; bs != NULL; bs = bs->next)
2852 enum class bs_class = no_effect;
2853 if (bs->breakpoint_at == NULL)
2854 /* I suspect this can happen if it was a momentary breakpoint
2855 which has since been deleted. */
2857 switch (bs->breakpoint_at->type)
2863 case bp_hardware_breakpoint:
2869 bs_class = bp_noisy;
2871 bs_class = bp_silent;
2874 bs_class = bp_nostop;
2877 case bp_hardware_watchpoint:
2878 case bp_read_watchpoint:
2879 case bp_access_watchpoint:
2883 bs_class = wp_noisy;
2885 bs_class = wp_silent;
2888 /* There was a watchpoint, but we're not stopping.
2889 This requires no further action. */
2890 bs_class = no_effect;
2893 bs_class = long_jump;
2895 case bp_longjmp_resume:
2896 bs_class = long_resume;
2898 case bp_step_resume:
2901 bs_class = step_resume;
2904 /* It is for the wrong frame. */
2905 bs_class = bp_nostop;
2907 case bp_through_sigtramp:
2908 bs_class = through_sig;
2910 case bp_watchpoint_scope:
2911 bs_class = bp_nostop;
2913 case bp_shlib_event:
2914 bs_class = shlib_event;
2916 case bp_thread_event:
2917 bs_class = bp_nostop;
2920 case bp_catch_unload:
2921 /* Only if this catchpoint triggered should we cause the
2922 step-out-of-dld behaviour. Otherwise, we ignore this
2925 bs_class = catch_shlib_event;
2927 bs_class = no_effect;
2930 case bp_catch_vfork:
2935 bs_class = bp_noisy;
2937 bs_class = bp_silent;
2940 /* There was a catchpoint, but we're not stopping.
2941 This requires no further action. */
2942 bs_class = no_effect;
2944 case bp_catch_catch:
2945 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2946 bs_class = bp_nostop;
2948 bs_class = bs->print ? bp_noisy : bp_silent;
2950 case bp_catch_throw:
2951 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2952 bs_class = bp_nostop;
2954 bs_class = bs->print ? bp_noisy : bp_silent;
2957 /* Make sure the action is stop (silent or noisy),
2958 so infrun.c pops the dummy frame. */
2959 bs_class = bp_silent;
2960 retval.call_dummy = 1;
2963 current_action = table[(int) bs_class][(int) current_action];
2965 retval.main_action = current_action;
2969 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2970 without hardware support). This isn't related to a specific bpstat,
2971 just to things like whether watchpoints are set. */
2974 bpstat_should_step (void)
2976 struct breakpoint *b;
2978 if (b->enable == enabled && b->type == bp_watchpoint)
2983 /* Nonzero if there are enabled hardware watchpoints. */
2985 bpstat_have_active_hw_watchpoints (void)
2987 struct breakpoint *b;
2989 if ((b->enable == enabled) &&
2991 ((b->type == bp_hardware_watchpoint) ||
2992 (b->type == bp_read_watchpoint) ||
2993 (b->type == bp_access_watchpoint)))
2999 /* Given a bpstat that records zero or more triggered eventpoints, this
3000 function returns another bpstat which contains only the catchpoints
3001 on that first list, if any. */
3003 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3005 struct bpstats root_bs[1];
3006 bpstat bs = root_bs;
3007 struct breakpoint *ep;
3010 bpstat_clear (cp_list);
3011 root_bs->next = NULL;
3013 for (; ep_list != NULL; ep_list = ep_list->next)
3015 /* Is this eventpoint a catchpoint? If not, ignore it. */
3016 ep = ep_list->breakpoint_at;
3019 if ((ep->type != bp_catch_load) &&
3020 (ep->type != bp_catch_unload) &&
3021 (ep->type != bp_catch_catch) &&
3022 (ep->type != bp_catch_throw))
3023 /* pai: (temp) ADD fork/vfork here!! */
3026 /* Yes; add it to the list. */
3027 bs = bpstat_alloc (ep, bs);
3032 #if defined(SOLIB_ADD)
3033 /* Also, for each triggered catchpoint, tag it with the name of
3034 the library that caused this trigger. (We copy the name now,
3035 because it's only guaranteed to be available NOW, when the
3036 catchpoint triggers. Clients who may wish to know the name
3037 later must get it from the catchpoint itself.) */
3038 if (ep->triggered_dll_pathname != NULL)
3039 xfree (ep->triggered_dll_pathname);
3040 if (ep->type == bp_catch_load)
3041 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3042 PIDGET (inferior_ptid));
3044 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3045 PIDGET (inferior_ptid));
3047 dll_pathname = NULL;
3051 ep->triggered_dll_pathname = (char *)
3052 xmalloc (strlen (dll_pathname) + 1);
3053 strcpy (ep->triggered_dll_pathname, dll_pathname);
3056 ep->triggered_dll_pathname = NULL;
3062 /* Print B to gdb_stdout. */
3064 print_one_breakpoint (struct breakpoint *b,
3065 CORE_ADDR *last_addr)
3067 register struct command_line *l;
3068 register struct symbol *sym;
3069 struct ep_type_description
3074 static struct ep_type_description bptypes[] =
3076 {bp_none, "?deleted?"},
3077 {bp_breakpoint, "breakpoint"},
3078 {bp_hardware_breakpoint, "hw breakpoint"},
3079 {bp_until, "until"},
3080 {bp_finish, "finish"},
3081 {bp_watchpoint, "watchpoint"},
3082 {bp_hardware_watchpoint, "hw watchpoint"},
3083 {bp_read_watchpoint, "read watchpoint"},
3084 {bp_access_watchpoint, "acc watchpoint"},
3085 {bp_longjmp, "longjmp"},
3086 {bp_longjmp_resume, "longjmp resume"},
3087 {bp_step_resume, "step resume"},
3088 {bp_through_sigtramp, "sigtramp"},
3089 {bp_watchpoint_scope, "watchpoint scope"},
3090 {bp_call_dummy, "call dummy"},
3091 {bp_shlib_event, "shlib events"},
3092 {bp_thread_event, "thread events"},
3093 {bp_catch_load, "catch load"},
3094 {bp_catch_unload, "catch unload"},
3095 {bp_catch_fork, "catch fork"},
3096 {bp_catch_vfork, "catch vfork"},
3097 {bp_catch_exec, "catch exec"},
3098 {bp_catch_catch, "catch catch"},
3099 {bp_catch_throw, "catch throw"}
3102 static char *bpdisps[] =
3103 {"del", "dstp", "dis", "keep"};
3104 static char bpenables[] = "nynny";
3105 char wrap_indent[80];
3107 struct ui_stream *stb = ui_out_stream_new (uiout);
3108 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3113 ui_out_list_begin (uiout, "bkpt");
3119 ui_out_field_int (uiout, "number", b->number);
3121 printf_filtered ("%-3d ", b->number);
3126 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3127 || ((int) b->type != bptypes[(int) b->type].type))
3128 internal_error (__FILE__, __LINE__,
3129 "bptypes table does not describe type #%d.",
3132 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3134 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3140 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3142 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3148 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3149 ui_out_spaces (uiout, 2);
3151 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3155 strcpy (wrap_indent, " ");
3158 if (TARGET_ADDR_BIT <= 32)
3159 strcat (wrap_indent, " ");
3161 strcat (wrap_indent, " ");
3166 internal_error (__FILE__, __LINE__,
3167 "print_one_breakpoint: bp_none encountered\n");
3171 case bp_hardware_watchpoint:
3172 case bp_read_watchpoint:
3173 case bp_access_watchpoint:
3174 /* Field 4, the address, is omitted (which makes the columns
3175 not line up too nicely with the headers, but the effect
3176 is relatively readable). */
3179 ui_out_field_skip (uiout, "addr");
3181 print_expression (b->exp, stb->stream);
3182 ui_out_field_stream (uiout, "what", stb);
3185 print_expression (b->exp, gdb_stdout);
3190 case bp_catch_unload:
3191 /* Field 4, the address, is omitted (which makes the columns
3192 not line up too nicely with the headers, but the effect
3193 is relatively readable). */
3196 ui_out_field_skip (uiout, "addr");
3198 if (b->dll_pathname == NULL)
3200 ui_out_field_string (uiout, "what", "<any library>");
3201 ui_out_spaces (uiout, 1);
3205 ui_out_text (uiout, "library \"");
3206 ui_out_field_string (uiout, "what", b->dll_pathname);
3207 ui_out_text (uiout, "\" ");
3211 if (b->dll_pathname == NULL)
3212 printf_filtered ("<any library> ");
3214 printf_filtered ("library \"%s\" ", b->dll_pathname);
3219 case bp_catch_vfork:
3220 /* Field 4, the address, is omitted (which makes the columns
3221 not line up too nicely with the headers, but the effect
3222 is relatively readable). */
3225 ui_out_field_skip (uiout, "addr");
3227 if (b->forked_inferior_pid != 0)
3229 ui_out_text (uiout, "process ");
3230 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3231 ui_out_spaces (uiout, 1);
3235 if (b->forked_inferior_pid != 0)
3236 printf_filtered ("process %d ", b->forked_inferior_pid);
3241 /* Field 4, the address, is omitted (which makes the columns
3242 not line up too nicely with the headers, but the effect
3243 is relatively readable). */
3246 ui_out_field_skip (uiout, "addr");
3248 if (b->exec_pathname != NULL)
3250 ui_out_text (uiout, "program \"");
3251 ui_out_field_string (uiout, "what", b->exec_pathname);
3252 ui_out_text (uiout, "\" ");
3256 if (b->exec_pathname != NULL)
3257 printf_filtered ("program \"%s\" ", b->exec_pathname);
3261 case bp_catch_catch:
3262 /* Field 4, the address, is omitted (which makes the columns
3263 not line up too nicely with the headers, but the effect
3264 is relatively readable). */
3267 ui_out_field_skip (uiout, "addr");
3269 ui_out_field_string (uiout, "what", "exception catch");
3270 ui_out_spaces (uiout, 1);
3273 printf_filtered ("exception catch ");
3277 case bp_catch_throw:
3278 /* Field 4, the address, is omitted (which makes the columns
3279 not line up too nicely with the headers, but the effect
3280 is relatively readable). */
3283 ui_out_field_skip (uiout, "addr");
3285 ui_out_field_string (uiout, "what", "exception throw");
3286 ui_out_spaces (uiout, 1);
3289 printf_filtered ("exception throw ");
3294 case bp_hardware_breakpoint:
3298 case bp_longjmp_resume:
3299 case bp_step_resume:
3300 case bp_through_sigtramp:
3301 case bp_watchpoint_scope:
3303 case bp_shlib_event:
3304 case bp_thread_event:
3309 ui_out_field_core_addr (uiout, "addr", b->address);
3312 *last_addr = b->address;
3315 sym = find_pc_sect_function (b->address, b->section);
3318 ui_out_text (uiout, "in ");
3319 ui_out_field_string (uiout, "func",
3320 SYMBOL_SOURCE_NAME (sym));
3321 ui_out_wrap_hint (uiout, wrap_indent);
3322 ui_out_text (uiout, " at ");
3324 ui_out_field_string (uiout, "file", b->source_file);
3325 ui_out_text (uiout, ":");
3326 ui_out_field_int (uiout, "line", b->line_number);
3330 print_address_symbolic (b->address, stb->stream, demangle, "");
3331 ui_out_field_stream (uiout, "at", stb);
3340 if (TARGET_ADDR_BIT <= 32)
3341 tmp = longest_local_hex_string_custom (b->address
3342 & (CORE_ADDR) 0xffffffff,
3345 tmp = longest_local_hex_string_custom (b->address, "016l");
3347 printf_filtered ("%s ", tmp);
3350 *last_addr = b->address;
3353 sym = find_pc_sect_function (b->address, b->section);
3356 fputs_filtered ("in ", gdb_stdout);
3357 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3358 wrap_here (wrap_indent);
3359 fputs_filtered (" at ", gdb_stdout);
3361 fputs_filtered (b->source_file, gdb_stdout);
3362 printf_filtered (":%d", b->line_number);
3365 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3370 if (b->thread != -1)
3373 /* FIXME: This seems to be redundant and lost here; see the
3374 "stop only in" line a little further down. */
3375 ui_out_text (uiout, " thread ");
3376 ui_out_field_int (uiout, "thread", b->thread);
3378 printf_filtered (" thread %d", b->thread);
3383 ui_out_text (uiout, "\n");
3385 printf_filtered ("\n");
3392 ui_out_text (uiout, "\tstop only in stack frame at ");
3393 ui_out_field_core_addr (uiout, "frame", b->frame);
3394 ui_out_text (uiout, "\n");
3396 printf_filtered ("\tstop only in stack frame at ");
3397 print_address_numeric (b->frame, 1, gdb_stdout);
3398 printf_filtered ("\n");
3406 ui_out_text (uiout, "\tstop only if ");
3407 print_expression (b->cond, stb->stream);
3408 ui_out_field_stream (uiout, "cond", stb);
3409 ui_out_text (uiout, "\n");
3411 printf_filtered ("\tstop only if ");
3412 print_expression (b->cond, gdb_stdout);
3413 printf_filtered ("\n");
3417 if (b->thread != -1)
3419 /* FIXME should make an annotation for this */
3421 ui_out_text (uiout, "\tstop only in thread ");
3422 ui_out_field_int (uiout, "thread", b->thread);
3423 ui_out_text (uiout, "\n");
3425 printf_filtered ("\tstop only in thread %d\n", b->thread);
3429 if (show_breakpoint_hit_counts && b->hit_count)
3431 /* FIXME should make an annotation for this */
3433 if (ep_is_catchpoint (b))
3434 ui_out_text (uiout, "\tcatchpoint");
3436 ui_out_text (uiout, "\tbreakpoint");
3437 ui_out_text (uiout, " already hit ");
3438 ui_out_field_int (uiout, "times", b->hit_count);
3439 if (b->hit_count == 1)
3440 ui_out_text (uiout, " time\n");
3442 ui_out_text (uiout, " times\n");
3444 if (ep_is_catchpoint (b))
3445 printf_filtered ("\tcatchpoint");
3447 printf_filtered ("\tbreakpoint");
3448 printf_filtered (" already hit %d time%s\n",
3449 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3454 /* Output the count also if it is zero, but only if this is
3455 mi. FIXME: Should have a better test for this. */
3456 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3457 if (show_breakpoint_hit_counts && b->hit_count == 0)
3458 ui_out_field_int (uiout, "times", b->hit_count);
3461 if (b->ignore_count)
3465 ui_out_text (uiout, "\tignore next ");
3466 ui_out_field_int (uiout, "ignore", b->ignore_count);
3467 ui_out_text (uiout, " hits\n");
3469 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3473 if ((l = b->commands))
3477 ui_out_list_begin (uiout, "script");
3478 print_command_lines (uiout, l, 4);
3479 ui_out_list_end (uiout);
3483 print_command_line (l, 4, gdb_stdout);
3489 ui_out_list_end (uiout);
3490 do_cleanups (old_chain);
3494 struct captured_breakpoint_query_args
3500 do_captured_breakpoint_query (void *data)
3502 struct captured_breakpoint_query_args *args = data;
3503 register struct breakpoint *b;
3504 CORE_ADDR dummy_addr = 0;
3507 if (args->bnum == b->number)
3509 print_one_breakpoint (b, &dummy_addr);
3517 gdb_breakpoint_query (/* output object, */ int bnum)
3519 struct captured_breakpoint_query_args args;
3521 /* For the moment we don't trust print_one_breakpoint() to not throw
3523 return catch_errors (do_captured_breakpoint_query, &args,
3524 NULL, RETURN_MASK_ALL);
3527 /* Print information on breakpoint number BNUM, or -1 if all.
3528 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3529 is nonzero, process only watchpoints. */
3532 breakpoint_1 (int bnum, int allflag)
3534 register struct breakpoint *b;
3535 CORE_ADDR last_addr = (CORE_ADDR) -1;
3536 int found_a_breakpoint = 0;
3540 ui_out_table_begin (uiout, 6, "BreakpointTable");
3542 ui_out_table_begin (uiout, 5, "BreakpointTable");
3547 || bnum == b->number)
3549 /* We only print out user settable breakpoints unless the
3552 && b->type != bp_breakpoint
3553 && b->type != bp_catch_load
3554 && b->type != bp_catch_unload
3555 && b->type != bp_catch_fork
3556 && b->type != bp_catch_vfork
3557 && b->type != bp_catch_exec
3558 && b->type != bp_catch_catch
3559 && b->type != bp_catch_throw
3560 && b->type != bp_hardware_breakpoint
3561 && b->type != bp_watchpoint
3562 && b->type != bp_read_watchpoint
3563 && b->type != bp_access_watchpoint
3564 && b->type != bp_hardware_watchpoint)
3567 if (!found_a_breakpoint++)
3569 annotate_breakpoints_headers ();
3572 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3574 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3576 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3578 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3582 if (TARGET_ADDR_BIT <= 32)
3583 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3585 ui_out_table_header (uiout, 18, ui_left, "Address"); /* 5 */
3588 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3589 ui_out_table_body (uiout);
3592 printf_filtered ("Num ");
3594 printf_filtered ("Type ");
3596 printf_filtered ("Disp ");
3598 printf_filtered ("Enb ");
3602 if (TARGET_ADDR_BIT <= 32)
3603 printf_filtered ("Address ");
3605 printf_filtered ("Address ");
3608 printf_filtered ("What\n");
3610 annotate_breakpoints_table ();
3613 print_one_breakpoint (b, &last_addr);
3616 if (!found_a_breakpoint)
3620 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3622 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3626 printf_filtered ("No breakpoints or watchpoints.\n");
3628 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3633 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3634 that a comparison of an unsigned with -1 is always false. */
3635 if (last_addr != (CORE_ADDR) -1)
3636 set_next_address (last_addr);
3640 ui_out_table_end (uiout);
3642 /* FIXME? Should this be moved up so that it is only called when
3643 there have been breakpoints? */
3644 annotate_breakpoints_table_end ();
3649 breakpoints_info (char *bnum_exp, int from_tty)
3654 bnum = parse_and_eval_long (bnum_exp);
3656 breakpoint_1 (bnum, 0);
3661 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3666 bnum = parse_and_eval_long (bnum_exp);
3668 breakpoint_1 (bnum, 1);
3671 /* Print a message describing any breakpoints set at PC. */
3674 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3676 register int others = 0;
3677 register struct breakpoint *b;
3680 if (b->address == pc)
3681 if (overlay_debugging == 0 ||
3682 b->section == section)
3686 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3688 if (b->address == pc)
3689 if (overlay_debugging == 0 ||
3690 b->section == section)
3693 printf_filtered ("%d%s%s ",
3695 ((b->enable == disabled ||
3696 b->enable == shlib_disabled ||
3697 b->enable == call_disabled) ? " (disabled)"
3698 : b->enable == permanent ? " (permanent)"
3701 : ((others == 1) ? " and" : ""));
3703 printf_filtered ("also set at pc ");
3704 print_address_numeric (pc, 1, gdb_stdout);
3705 printf_filtered (".\n");
3709 /* Set the default place to put a breakpoint
3710 for the `break' command with no arguments. */
3713 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3716 default_breakpoint_valid = valid;
3717 default_breakpoint_address = addr;
3718 default_breakpoint_symtab = symtab;
3719 default_breakpoint_line = line;
3722 /* Rescan breakpoints at the same address and section as BPT,
3723 marking the first one as "first" and any others as "duplicates".
3724 This is so that the bpt instruction is only inserted once.
3725 If we have a permanent breakpoint at the same place as BPT, make
3726 that one the official one, and the rest as duplicates. */
3729 check_duplicates (struct breakpoint *bpt)
3731 register struct breakpoint *b;
3732 register int count = 0;
3733 struct breakpoint *perm_bp = 0;
3734 CORE_ADDR address = bpt->address;
3735 asection *section = bpt->section;
3737 if (address == 0) /* Watchpoints are uninteresting */
3741 if (b->enable != disabled
3742 && b->enable != shlib_disabled
3743 && b->enable != call_disabled
3744 && b->address == address
3745 && (overlay_debugging == 0 || b->section == section))
3747 /* Have we found a permanent breakpoint? */
3748 if (b->enable == permanent)
3755 b->duplicate = count > 1;
3758 /* If we found a permanent breakpoint at this address, go over the
3759 list again and declare all the other breakpoints there to be the
3763 perm_bp->duplicate = 0;
3765 /* Permanent breakpoint should always be inserted. */
3766 if (! perm_bp->inserted)
3767 internal_error (__FILE__, __LINE__,
3768 "allegedly permanent breakpoint is not "
3769 "actually inserted");
3775 internal_error (__FILE__, __LINE__,
3776 "another breakpoint was inserted on top of "
3777 "a permanent breakpoint");
3779 if (b->enable != disabled
3780 && b->enable != shlib_disabled
3781 && b->enable != call_disabled
3782 && b->address == address
3783 && (overlay_debugging == 0 || b->section == section))
3789 /* Low level routine to set a breakpoint.
3790 Takes as args the three things that every breakpoint must have.
3791 Returns the breakpoint object so caller can set other things.
3792 Does not set the breakpoint number!
3793 Does not print anything.
3795 ==> This routine should not be called if there is a chance of later
3796 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3797 your arguments BEFORE calling this routine! */
3800 set_raw_breakpoint (struct symtab_and_line sal)
3802 register struct breakpoint *b, *b1;
3804 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3805 memset (b, 0, sizeof (*b));
3806 b->address = sal.pc;
3807 if (sal.symtab == NULL)
3808 b->source_file = NULL;
3810 b->source_file = savestring (sal.symtab->filename,
3811 strlen (sal.symtab->filename));
3812 b->section = sal.section;
3813 b->language = current_language->la_language;
3814 b->input_radix = input_radix;
3816 b->line_number = sal.line;
3817 b->enable = enabled;
3820 b->ignore_count = 0;
3823 b->dll_pathname = NULL;
3824 b->triggered_dll_pathname = NULL;
3825 b->forked_inferior_pid = 0;
3826 b->exec_pathname = NULL;
3828 /* Add this breakpoint to the end of the chain
3829 so that a list of breakpoints will come out in order
3830 of increasing numbers. */
3832 b1 = breakpoint_chain;
3834 breakpoint_chain = b;
3842 check_duplicates (b);
3843 breakpoints_changed ();
3849 /* Note that the breakpoint object B describes a permanent breakpoint
3850 instruction, hard-wired into the inferior's code. */
3852 make_breakpoint_permanent (struct breakpoint *b)
3854 b->enable = permanent;
3856 /* By definition, permanent breakpoints are already present in the code. */
3860 #ifdef GET_LONGJMP_TARGET
3863 create_longjmp_breakpoint (char *func_name)
3865 struct symtab_and_line sal;
3866 struct breakpoint *b;
3868 INIT_SAL (&sal); /* initialize to zeroes */
3869 if (func_name != NULL)
3871 struct minimal_symbol *m;
3873 m = lookup_minimal_symbol_text (func_name, NULL,
3874 (struct objfile *) NULL);
3876 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3880 sal.section = find_pc_overlay (sal.pc);
3881 b = set_raw_breakpoint (sal);
3885 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3886 b->disposition = donttouch;
3887 b->enable = disabled;
3890 b->addr_string = xstrdup (func_name);
3891 b->number = internal_breakpoint_number--;
3894 #endif /* #ifdef GET_LONGJMP_TARGET */
3896 /* Call this routine when stepping and nexting to enable a breakpoint
3897 if we do a longjmp(). When we hit that breakpoint, call
3898 set_longjmp_resume_breakpoint() to figure out where we are going. */
3901 enable_longjmp_breakpoint (void)
3903 register struct breakpoint *b;
3906 if (b->type == bp_longjmp)
3908 b->enable = enabled;
3909 check_duplicates (b);
3914 disable_longjmp_breakpoint (void)
3916 register struct breakpoint *b;
3919 if (b->type == bp_longjmp
3920 || b->type == bp_longjmp_resume)
3922 b->enable = disabled;
3923 check_duplicates (b);
3928 create_thread_event_breakpoint (CORE_ADDR address)
3930 struct breakpoint *b;
3931 struct symtab_and_line sal;
3932 char addr_string[80]; /* Surely an addr can't be longer than that. */
3934 INIT_SAL (&sal); /* initialize to zeroes */
3936 sal.section = find_pc_overlay (sal.pc);
3937 if ((b = set_raw_breakpoint (sal)) == NULL)
3940 b->number = internal_breakpoint_number--;
3941 b->disposition = donttouch;
3942 b->type = bp_thread_event; /* XXX: do we need a new type?
3944 b->enable = enabled;
3945 /* addr_string has to be used or breakpoint_re_set will delete me. */
3946 sprintf (addr_string, "*0x%s", paddr (b->address));
3947 b->addr_string = xstrdup (addr_string);
3953 remove_thread_event_breakpoints (void)
3955 struct breakpoint *b, *temp;
3957 ALL_BREAKPOINTS_SAFE (b, temp)
3958 if (b->type == bp_thread_event)
3959 delete_breakpoint (b);
3964 remove_solib_event_breakpoints (void)
3966 register struct breakpoint *b, *temp;
3968 ALL_BREAKPOINTS_SAFE (b, temp)
3969 if (b->type == bp_shlib_event)
3970 delete_breakpoint (b);
3974 create_solib_event_breakpoint (CORE_ADDR address)
3976 struct breakpoint *b;
3977 struct symtab_and_line sal;
3979 INIT_SAL (&sal); /* initialize to zeroes */
3981 sal.section = find_pc_overlay (sal.pc);
3982 b = set_raw_breakpoint (sal);
3983 b->number = internal_breakpoint_number--;
3984 b->disposition = donttouch;
3985 b->type = bp_shlib_event;
3990 /* Disable any breakpoints that are on code in shared libraries. Only
3991 apply to enabled breakpoints, disabled ones can just stay disabled. */
3994 disable_breakpoints_in_shlibs (int silent)
3996 struct breakpoint *b;
3997 int disabled_shlib_breaks = 0;
3999 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4002 #if defined (PC_SOLIB)
4003 if (((b->type == bp_breakpoint) ||
4004 (b->type == bp_hardware_breakpoint)) &&
4005 b->enable == enabled &&
4007 PC_SOLIB (b->address))
4009 b->enable = shlib_disabled;
4012 if (!disabled_shlib_breaks)
4014 target_terminal_ours_for_output ();
4015 warning ("Temporarily disabling shared library breakpoints:");
4017 disabled_shlib_breaks = 1;
4018 warning ("breakpoint #%d ", b->number);
4025 /* Try to reenable any breakpoints in shared libraries. */
4027 re_enable_breakpoints_in_shlibs (void)
4029 struct breakpoint *b;
4032 if (b->enable == shlib_disabled)
4036 /* Do not reenable the breakpoint if the shared library
4037 is still not mapped in. */
4038 if (target_read_memory (b->address, buf, 1) == 0)
4039 b->enable = enabled;
4046 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4047 char *cond_string, enum bptype bp_kind)
4049 struct breakpoint *b;
4050 struct symtabs_and_lines sals;
4051 struct cleanup *old_chain;
4052 struct cleanup *canonical_strings_chain = NULL;
4053 char *addr_start = hookname;
4054 char *addr_end = NULL;
4055 char **canonical = (char **) NULL;
4056 int thread = -1; /* All threads. */
4058 /* Set a breakpoint on the specified hook. */
4059 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4060 addr_end = hookname;
4062 if (sals.nelts == 0)
4064 warning ("Unable to set a breakpoint on dynamic linker callback.");
4065 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4066 warning ("GDB will be unable to track shl_load/shl_unload calls");
4069 if (sals.nelts != 1)
4071 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4072 warning ("GDB will be unable to track shl_load/shl_unload calls");
4076 /* Make sure that all storage allocated in decode_line_1 gets freed
4077 in case the following errors out. */
4078 old_chain = make_cleanup (xfree, sals.sals);
4079 if (canonical != (char **) NULL)
4081 make_cleanup (xfree, canonical);
4082 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4083 if (canonical[0] != NULL)
4084 make_cleanup (xfree, canonical[0]);
4087 resolve_sal_pc (&sals.sals[0]);
4089 /* Remove the canonical strings from the cleanup, they are needed below. */
4090 if (canonical != (char **) NULL)
4091 discard_cleanups (canonical_strings_chain);
4093 b = set_raw_breakpoint (sals.sals[0]);
4094 set_breakpoint_count (breakpoint_count + 1);
4095 b->number = breakpoint_count;
4097 b->cond_string = (cond_string == NULL) ?
4098 NULL : savestring (cond_string, strlen (cond_string));
4101 if (canonical != (char **) NULL && canonical[0] != NULL)
4102 b->addr_string = canonical[0];
4103 else if (addr_start)
4104 b->addr_string = savestring (addr_start, addr_end - addr_start);
4106 b->enable = enabled;
4107 b->disposition = tempflag ? del : donttouch;
4109 if (dll_pathname == NULL)
4110 b->dll_pathname = NULL;
4113 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4114 strcpy (b->dll_pathname, dll_pathname);
4119 do_cleanups (old_chain);
4123 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4124 char *dll_pathname, char *cond_string)
4126 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4127 cond_string, bp_catch_load);
4131 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4132 char *dll_pathname, char *cond_string)
4134 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4135 cond_string, bp_catch_unload);
4139 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4140 enum bptype bp_kind)
4142 struct symtab_and_line sal;
4143 struct breakpoint *b;
4144 int thread = -1; /* All threads. */
4151 b = set_raw_breakpoint (sal);
4152 set_breakpoint_count (breakpoint_count + 1);
4153 b->number = breakpoint_count;
4155 b->cond_string = (cond_string == NULL) ?
4156 NULL : savestring (cond_string, strlen (cond_string));
4158 b->addr_string = NULL;
4159 b->enable = enabled;
4160 b->disposition = tempflag ? del : donttouch;
4161 b->forked_inferior_pid = 0;
4169 create_fork_event_catchpoint (int tempflag, char *cond_string)
4171 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4175 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4177 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4181 create_exec_event_catchpoint (int tempflag, char *cond_string)
4183 struct symtab_and_line sal;
4184 struct breakpoint *b;
4185 int thread = -1; /* All threads. */
4192 b = set_raw_breakpoint (sal);
4193 set_breakpoint_count (breakpoint_count + 1);
4194 b->number = breakpoint_count;
4196 b->cond_string = (cond_string == NULL) ?
4197 NULL : savestring (cond_string, strlen (cond_string));
4199 b->addr_string = NULL;
4200 b->enable = enabled;
4201 b->disposition = tempflag ? del : donttouch;
4203 b->type = bp_catch_exec;
4209 hw_breakpoint_used_count (void)
4211 register struct breakpoint *b;
4216 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4224 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4226 register struct breakpoint *b;
4229 *other_type_used = 0;
4232 if (b->enable == enabled)
4234 if (b->type == type)
4236 else if ((b->type == bp_hardware_watchpoint ||
4237 b->type == bp_read_watchpoint ||
4238 b->type == bp_access_watchpoint)
4239 && b->enable == enabled)
4240 *other_type_used = 1;
4246 /* Call this after hitting the longjmp() breakpoint. Use this to set
4247 a new breakpoint at the target of the jmp_buf.
4249 FIXME - This ought to be done by setting a temporary breakpoint
4250 that gets deleted automatically... */
4253 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
4255 register struct breakpoint *b;
4258 if (b->type == bp_longjmp_resume)
4261 b->enable = enabled;
4263 b->frame = frame->frame;
4266 check_duplicates (b);
4272 disable_watchpoints_before_interactive_call_start (void)
4274 struct breakpoint *b;
4278 if (((b->type == bp_watchpoint)
4279 || (b->type == bp_hardware_watchpoint)
4280 || (b->type == bp_read_watchpoint)
4281 || (b->type == bp_access_watchpoint)
4282 || ep_is_exception_catchpoint (b))
4283 && (b->enable == enabled))
4285 b->enable = call_disabled;
4286 check_duplicates (b);
4292 enable_watchpoints_after_interactive_call_stop (void)
4294 struct breakpoint *b;
4298 if (((b->type == bp_watchpoint)
4299 || (b->type == bp_hardware_watchpoint)
4300 || (b->type == bp_read_watchpoint)
4301 || (b->type == bp_access_watchpoint)
4302 || ep_is_exception_catchpoint (b))
4303 && (b->enable == call_disabled))
4305 b->enable = enabled;
4306 check_duplicates (b);
4312 /* Set a breakpoint that will evaporate an end of command
4313 at address specified by SAL.
4314 Restrict it to frame FRAME if FRAME is nonzero. */
4317 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4320 register struct breakpoint *b;
4321 b = set_raw_breakpoint (sal);
4323 b->enable = enabled;
4324 b->disposition = donttouch;
4325 b->frame = (frame ? frame->frame : 0);
4327 /* If we're debugging a multi-threaded program, then we
4328 want momentary breakpoints to be active in only a
4329 single thread of control. */
4330 if (in_thread_list (inferior_ptid))
4331 b->thread = pid_to_thread_id (inferior_ptid);
4337 /* Tell the user we have just set a breakpoint B. */
4340 mention (struct breakpoint *b)
4344 struct cleanup *old_chain;
4345 struct ui_stream *stb;
4347 stb = ui_out_stream_new (uiout);
4348 old_chain = make_cleanup_ui_out_stream_delete (stb);
4351 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4352 watchpoint) other than breakpoint creation. It should be possible to
4353 clean this up and at the same time replace the random calls to
4354 breakpoint_changed with this hook, as has already been done for
4355 delete_breakpoint_hook and so on. */
4356 if (create_breakpoint_hook)
4357 create_breakpoint_hook (b);
4358 breakpoint_create_event (b->number);
4363 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4367 ui_out_text (uiout, "Watchpoint ");
4368 ui_out_list_begin (uiout, "wpt");
4369 ui_out_field_int (uiout, "number", b->number);
4370 ui_out_text (uiout, ": ");
4371 print_expression (b->exp, stb->stream);
4372 ui_out_field_stream (uiout, "exp", stb);
4373 ui_out_list_end (uiout);
4375 case bp_hardware_watchpoint:
4376 ui_out_text (uiout, "Hardware watchpoint ");
4377 ui_out_list_begin (uiout, "wpt");
4378 ui_out_field_int (uiout, "number", b->number);
4379 ui_out_text (uiout, ": ");
4380 print_expression (b->exp, stb->stream);
4381 ui_out_field_stream (uiout, "exp", stb);
4382 ui_out_list_end (uiout);
4386 printf_filtered ("Watchpoint %d: ", b->number);
4387 print_expression (b->exp, gdb_stdout);
4389 case bp_hardware_watchpoint:
4390 printf_filtered ("Hardware watchpoint %d: ", b->number);
4391 print_expression (b->exp, gdb_stdout);
4395 case bp_read_watchpoint:
4396 ui_out_text (uiout, "Hardware read watchpoint ");
4397 ui_out_list_begin (uiout, "hw-rwpt");
4398 ui_out_field_int (uiout, "number", b->number);
4399 ui_out_text (uiout, ": ");
4400 print_expression (b->exp, stb->stream);
4401 ui_out_field_stream (uiout, "exp", stb);
4402 ui_out_list_end (uiout);
4404 case bp_access_watchpoint:
4405 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4406 ui_out_list_begin (uiout, "hw-awpt");
4407 ui_out_field_int (uiout, "number", b->number);
4408 ui_out_text (uiout, ": ");
4409 print_expression (b->exp, stb->stream);
4410 ui_out_field_stream (uiout, "exp", stb);
4411 ui_out_list_end (uiout);
4414 case bp_read_watchpoint:
4415 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4416 print_expression (b->exp, gdb_stdout);
4418 case bp_access_watchpoint:
4419 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4421 print_expression (b->exp, gdb_stdout);
4426 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4432 printf_filtered ("Breakpoint %d", b->number);
4435 case bp_hardware_breakpoint:
4437 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4443 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4447 case bp_catch_unload:
4448 printf_filtered ("Catchpoint %d (%s %s)",
4450 (b->type == bp_catch_load) ? "load" : "unload",
4451 (b->dll_pathname != NULL) ?
4452 b->dll_pathname : "<any library>");
4455 case bp_catch_vfork:
4456 printf_filtered ("Catchpoint %d (%s)",
4458 (b->type == bp_catch_fork) ? "fork" : "vfork");
4461 printf_filtered ("Catchpoint %d (exec)",
4464 case bp_catch_catch:
4465 case bp_catch_throw:
4466 printf_filtered ("Catchpoint %d (%s)",
4468 (b->type == bp_catch_catch) ? "catch" : "throw");
4474 case bp_longjmp_resume:
4475 case bp_step_resume:
4476 case bp_through_sigtramp:
4478 case bp_watchpoint_scope:
4479 case bp_shlib_event:
4480 case bp_thread_event:
4485 if (addressprint || b->source_file == NULL)
4487 printf_filtered (" at ");
4488 print_address_numeric (b->address, 1, gdb_stdout);
4491 printf_filtered (": file %s, line %d.",
4492 b->source_file, b->line_number);
4493 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4494 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4497 do_cleanups (old_chain);
4500 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4503 printf_filtered ("\n");
4507 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4508 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4509 COND[i] and COND_STRING[i] values.
4511 NOTE: If the function succeeds, the caller is expected to cleanup
4512 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4513 array contents). If the function fails (error() is called), the
4514 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4515 COND and SALS arrays and each of those arrays contents. */
4518 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4519 struct expression **cond, char **cond_string,
4520 enum bptype type, enum bpdisp disposition,
4521 int thread, int ignore_count, int from_tty)
4523 if (type == bp_hardware_breakpoint)
4525 int i = hw_breakpoint_used_count ();
4526 int target_resources_ok =
4527 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4529 if (target_resources_ok == 0)
4530 error ("No hardware breakpoint support in the target.");
4531 else if (target_resources_ok < 0)
4532 error ("Hardware breakpoints used exceeds limit.");
4535 /* Now set all the breakpoints. */
4538 for (i = 0; i < sals.nelts; i++)
4540 struct breakpoint *b;
4541 struct symtab_and_line sal = sals.sals[i];
4544 describe_other_breakpoints (sal.pc, sal.section);
4546 b = set_raw_breakpoint (sal);
4547 set_breakpoint_count (breakpoint_count + 1);
4548 b->number = breakpoint_count;
4552 b->addr_string = addr_string[i];
4553 b->cond_string = cond_string[i];
4554 b->ignore_count = ignore_count;
4555 b->enable = enabled;
4556 b->disposition = disposition;
4562 /* Parse ARG which is assumed to be a SAL specification possibly
4563 followed by conditionals. On return, SALS contains an array of SAL
4564 addresses found. ADDR_STRING contains a vector of (canonical)
4565 address strings. ARG points to the end of the SAL. */
4568 parse_breakpoint_sals (char **address,
4569 struct symtabs_and_lines *sals,
4570 char ***addr_string)
4572 char *addr_start = *address;
4573 *addr_string = NULL;
4574 /* If no arg given, or if first arg is 'if ', use the default
4576 if ((*address) == NULL
4577 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4579 if (default_breakpoint_valid)
4581 struct symtab_and_line sal;
4582 INIT_SAL (&sal); /* initialize to zeroes */
4583 sals->sals = (struct symtab_and_line *)
4584 xmalloc (sizeof (struct symtab_and_line));
4585 sal.pc = default_breakpoint_address;
4586 sal.line = default_breakpoint_line;
4587 sal.symtab = default_breakpoint_symtab;
4588 sal.section = find_pc_overlay (sal.pc);
4589 sals->sals[0] = sal;
4593 error ("No default breakpoint address now.");
4597 /* Force almost all breakpoints to be in terms of the
4598 current_source_symtab (which is decode_line_1's default). This
4599 should produce the results we want almost all of the time while
4600 leaving default_breakpoint_* alone. */
4601 if (default_breakpoint_valid
4602 && (!current_source_symtab
4603 || (strchr ("+-", (*address)[0]) != NULL)))
4604 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4605 default_breakpoint_line, addr_string);
4607 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4609 /* For any SAL that didn't have a canonical string, fill one in. */
4610 if (sals->nelts > 0 && *addr_string == NULL)
4611 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4612 if (addr_start != (*address))
4615 for (i = 0; i < sals->nelts; i++)
4617 /* Add the string if not present. */
4618 if ((*addr_string)[i] == NULL)
4619 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4625 /* Convert each SAL into a real PC. Verify that the PC can be
4626 inserted as a breakpoint. If it can't throw an error. */
4629 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4633 for (i = 0; i < sals->nelts; i++)
4635 resolve_sal_pc (&sals->sals[i]);
4637 /* It's possible for the PC to be nonzero, but still an illegal
4638 value on some targets.
4640 For example, on HP-UX if you start gdb, and before running the
4641 inferior you try to set a breakpoint on a shared library function
4642 "foo" where the inferior doesn't call "foo" directly but does
4643 pass its address to another function call, then we do find a
4644 minimal symbol for the "foo", but it's address is invalid.
4645 (Appears to be an index into a table that the loader sets up
4646 when the inferior is run.)
4648 Give the target a chance to bless sals.sals[i].pc before we
4649 try to make a breakpoint for it. */
4650 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4652 if (address == NULL)
4653 error ("Cannot break without a running program.");
4655 error ("Cannot break on %s without a running program.",
4661 /* Set a breakpoint according to ARG (function, linenum or *address)
4662 flag: first bit : 0 non-temporary, 1 temporary.
4663 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4666 break_command_1 (char *arg, int flag, int from_tty)
4668 int tempflag, hardwareflag;
4669 struct symtabs_and_lines sals;
4670 register struct expression **cond = 0;
4671 /* Pointers in arg to the start, and one past the end, of the
4673 char **cond_string = (char **) NULL;
4674 char *addr_start = arg;
4676 struct cleanup *old_chain;
4677 struct cleanup *breakpoint_chain = NULL;
4680 int ignore_count = 0;
4682 hardwareflag = flag & BP_HARDWAREFLAG;
4683 tempflag = flag & BP_TEMPFLAG;
4688 parse_breakpoint_sals (&arg, &sals, &addr_string);
4693 /* Create a chain of things that always need to be cleaned up. */
4694 old_chain = make_cleanup (null_cleanup, 0);
4696 /* Make sure that all storage allocated to SALS gets freed. */
4697 make_cleanup (xfree, sals.sals);
4699 /* Cleanup the addr_string array but not its contents. */
4700 make_cleanup (xfree, addr_string);
4702 /* Allocate space for all the cond expressions. */
4703 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4704 make_cleanup (xfree, cond);
4706 /* Allocate space for all the cond strings. */
4707 cond_string = xcalloc (sals.nelts, sizeof (char **));
4708 make_cleanup (xfree, cond_string);
4710 /* ----------------------------- SNIP -----------------------------
4711 Anything added to the cleanup chain beyond this point is assumed
4712 to be part of a breakpoint. If the breakpoint create succeeds
4713 then the memory is not reclaimed. */
4714 breakpoint_chain = make_cleanup (null_cleanup, 0);
4716 /* Mark the contents of the addr_string for cleanup. These go on
4717 the breakpoint_chain and only occure if the breakpoint create
4719 for (i = 0; i < sals.nelts; i++)
4721 if (addr_string[i] != NULL)
4722 make_cleanup (xfree, addr_string[i]);
4725 /* Resolve all line numbers to PC's and verify that the addresses
4726 are ok for the target. */
4727 breakpoint_sals_to_pc (&sals, addr_start);
4729 /* Verify that condition can be parsed, before setting any
4730 breakpoints. Allocate a separate condition expression for each
4732 thread = -1; /* No specific thread yet */
4733 for (i = 0; i < sals.nelts; i++)
4740 char *cond_start = NULL;
4741 char *cond_end = NULL;
4742 while (*tok == ' ' || *tok == '\t')
4747 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4750 toklen = end_tok - tok;
4752 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4754 tok = cond_start = end_tok + 1;
4755 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4756 make_cleanup (xfree, cond[i]);
4758 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4759 make_cleanup (xfree, cond_string[i]);
4761 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4767 thread = strtol (tok, &tok, 0);
4769 error ("Junk after thread keyword.");
4770 if (!valid_thread_id (thread))
4771 error ("Unknown thread %d\n", thread);
4774 error ("Junk at end of arguments.");
4778 create_breakpoints (sals, addr_string, cond, cond_string,
4779 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4780 tempflag ? del : donttouch,
4781 thread, ignore_count, from_tty);
4785 warning ("Multiple breakpoints were set.");
4786 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4788 /* That's it. Discard the cleanups for data inserted into the
4790 discard_cleanups (breakpoint_chain);
4791 /* But cleanup everything else. */
4792 do_cleanups (old_chain);
4795 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4796 linenum or *address) with COND and IGNORE_COUNT. */
4798 struct captured_breakpoint_args
4809 do_captured_breakpoint (void *data)
4811 struct captured_breakpoint_args *args = data;
4812 struct symtabs_and_lines sals;
4813 register struct expression **cond;
4814 struct cleanup *old_chain;
4815 struct cleanup *breakpoint_chain = NULL;
4822 /* Parse the source and lines spec. Delay check that the expression
4823 didn't contain trailing garbage until after cleanups are in
4827 address_end = args->address;
4829 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4834 /* Create a chain of things at always need to be cleaned up. */
4835 old_chain = make_cleanup (null_cleanup, 0);
4837 /* Always have a addr_string array, even if it is empty. */
4838 make_cleanup (xfree, addr_string);
4840 /* Make sure that all storage allocated to SALS gets freed. */
4841 make_cleanup (xfree, sals.sals);
4843 /* Allocate space for all the cond expressions. */
4844 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4845 make_cleanup (xfree, cond);
4847 /* Allocate space for all the cond strings. */
4848 cond_string = xcalloc (sals.nelts, sizeof (char **));
4849 make_cleanup (xfree, cond_string);
4851 /* ----------------------------- SNIP -----------------------------
4852 Anything added to the cleanup chain beyond this point is assumed
4853 to be part of a breakpoint. If the breakpoint create goes
4854 through then that memory is not cleaned up. */
4855 breakpoint_chain = make_cleanup (null_cleanup, 0);
4857 /* Mark the contents of the addr_string for cleanup. These go on
4858 the breakpoint_chain and only occure if the breakpoint create
4860 for (i = 0; i < sals.nelts; i++)
4862 if (addr_string[i] != NULL)
4863 make_cleanup (xfree, addr_string[i]);
4866 /* Wait until now before checking for garbage at the end of the
4867 address. That way cleanups can take care of freeing any
4869 if (*address_end != '\0')
4870 error ("Garbage %s following breakpoint address", address_end);
4872 /* Resolve all line numbers to PC's. */
4873 breakpoint_sals_to_pc (&sals, args->address);
4875 /* Verify that conditions can be parsed, before setting any
4877 for (i = 0; i < sals.nelts; i++)
4879 if (args->condition != NULL)
4881 char *tok = args->condition;
4882 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4884 error ("Garbage %s follows condition", tok);
4885 make_cleanup (xfree, cond[i]);
4886 cond_string[i] = xstrdup (args->condition);
4890 create_breakpoints (sals, addr_string, cond, cond_string,
4891 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4892 args->tempflag ? del : donttouch,
4893 args->thread, args->ignore_count, 0/*from-tty*/);
4895 /* That's it. Discard the cleanups for data inserted into the
4897 discard_cleanups (breakpoint_chain);
4898 /* But cleanup everything else. */
4899 do_cleanups (old_chain);
4904 gdb_breakpoint (char *address, char *condition,
4905 int hardwareflag, int tempflag,
4906 int thread, int ignore_count)
4908 struct captured_breakpoint_args args;
4909 args.address = address;
4910 args.condition = condition;
4911 args.hardwareflag = hardwareflag;
4912 args.tempflag = tempflag;
4913 args.thread = thread;
4914 args.ignore_count = ignore_count;
4915 return catch_errors (do_captured_breakpoint, &args,
4916 NULL, RETURN_MASK_ALL);
4921 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4923 struct frame_info *frame;
4924 CORE_ADDR low, high, selected_pc = 0;
4925 char *extra_args = NULL;
4928 int extra_args_len = 0, if_arg = 0;
4931 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4934 if (default_breakpoint_valid)
4938 selected_pc = selected_frame->pc;
4943 error ("No selected frame.");
4946 error ("No default breakpoint address now.");
4950 extra_args = strchr (arg, ' ');
4954 extra_args_len = strlen (extra_args);
4955 level_arg = (char *) xmalloc (extra_args - arg);
4956 strncpy (level_arg, arg, extra_args - arg - 1);
4957 level_arg[extra_args - arg - 1] = '\0';
4961 level_arg = (char *) xmalloc (strlen (arg) + 1);
4962 strcpy (level_arg, arg);
4965 frame = parse_frame_specification (level_arg);
4967 selected_pc = frame->pc;
4974 extra_args_len = strlen (arg);
4979 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4981 addr_string = (char *) xmalloc (26 + extra_args_len);
4983 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4985 sprintf (addr_string, "*0x%s", paddr_nz (high));
4986 break_command_1 (addr_string, flag, from_tty);
4987 xfree (addr_string);
4990 error ("No function contains the specified address");
4993 error ("Unable to set breakpoint at procedure exit");
4998 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5000 char *addr_string, *break_string, *beg_addr_string;
5001 CORE_ADDR low, high;
5002 struct symtabs_and_lines sals;
5003 struct symtab_and_line sal;
5004 struct cleanup *old_chain;
5005 char *extra_args = NULL;
5006 int extra_args_len = 0;
5010 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5012 if (default_breakpoint_valid)
5016 addr_string = (char *) xmalloc (15);
5017 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5022 error ("No selected frame.");
5025 error ("No default breakpoint address now.");
5029 addr_string = (char *) xmalloc (strlen (arg) + 1);
5030 strcpy (addr_string, arg);
5036 extra_args_len = strlen (arg);
5040 /* get the stuff after the function name or address */
5041 extra_args = strchr (arg, ' ');
5045 extra_args_len = strlen (extra_args);
5052 beg_addr_string = addr_string;
5053 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5056 xfree (beg_addr_string);
5057 old_chain = make_cleanup (xfree, sals.sals);
5058 for (i = 0; (i < sals.nelts); i++)
5061 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5063 break_string = (char *) xmalloc (extra_args_len + 26);
5065 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5067 sprintf (break_string, "*0x%s", paddr_nz (high));
5068 break_command_1 (break_string, flag, from_tty);
5069 xfree (break_string);
5072 error ("No function contains the specified address");
5076 warning ("Multiple breakpoints were set.\n");
5077 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5079 do_cleanups (old_chain);
5083 /* Helper function for break_command_1 and disassemble_command. */
5086 resolve_sal_pc (struct symtab_and_line *sal)
5090 if (sal->pc == 0 && sal->symtab != NULL)
5092 if (!find_line_pc (sal->symtab, sal->line, &pc))
5093 error ("No line %d in file \"%s\".",
5094 sal->line, sal->symtab->filename);
5098 if (sal->section == 0 && sal->symtab != NULL)
5100 struct blockvector *bv;
5105 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5108 b = BLOCKVECTOR_BLOCK (bv, index);
5109 sym = block_function (b);
5112 fixup_symbol_section (sym, sal->symtab->objfile);
5113 sal->section = SYMBOL_BFD_SECTION (sym);
5117 /* It really is worthwhile to have the section, so we'll just
5118 have to look harder. This case can be executed if we have
5119 line numbers but no functions (as can happen in assembly
5122 struct minimal_symbol *msym;
5124 msym = lookup_minimal_symbol_by_pc (sal->pc);
5126 sal->section = SYMBOL_BFD_SECTION (msym);
5133 break_command (char *arg, int from_tty)
5135 break_command_1 (arg, 0, from_tty);
5139 break_at_finish_command (char *arg, int from_tty)
5141 break_at_finish_command_1 (arg, 0, from_tty);
5145 break_at_finish_at_depth_command (char *arg, int from_tty)
5147 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5151 tbreak_command (char *arg, int from_tty)
5153 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5157 tbreak_at_finish_command (char *arg, int from_tty)
5159 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5163 hbreak_command (char *arg, int from_tty)
5165 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5169 thbreak_command (char *arg, int from_tty)
5171 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5175 stop_command (char *arg, int from_tty)
5177 printf_filtered ("Specify the type of breakpoint to set.\n\
5178 Usage: stop in <function | address>\n\
5183 stopin_command (char *arg, int from_tty)
5187 if (arg == (char *) NULL)
5189 else if (*arg != '*')
5194 /* look for a ':'. If this is a line number specification, then
5195 say it is bad, otherwise, it should be an address or
5196 function/method name */
5197 while (*argptr && !hasColon)
5199 hasColon = (*argptr == ':');
5204 badInput = (*argptr != ':'); /* Not a class::method */
5206 badInput = isdigit (*arg); /* a simple line number */
5210 printf_filtered ("Usage: stop in <function | address>\n");
5212 break_command_1 (arg, 0, from_tty);
5216 stopat_command (char *arg, int from_tty)
5220 if (arg == (char *) NULL || *arg == '*') /* no line number */
5227 /* look for a ':'. If there is a '::' then get out, otherwise
5228 it is probably a line number. */
5229 while (*argptr && !hasColon)
5231 hasColon = (*argptr == ':');
5236 badInput = (*argptr == ':'); /* we have class::method */
5238 badInput = !isdigit (*arg); /* not a line number */
5242 printf_filtered ("Usage: stop at <line>\n");
5244 break_command_1 (arg, 0, from_tty);
5248 /* accessflag: hw_write: watch write,
5249 hw_read: watch read,
5250 hw_access: watch access (read or write) */
5252 watch_command_1 (char *arg, int accessflag, int from_tty)
5254 struct breakpoint *b;
5255 struct symtab_and_line sal;
5256 struct expression *exp;
5257 struct block *exp_valid_block;
5258 struct value *val, *mark;
5259 struct frame_info *frame;
5260 struct frame_info *prev_frame = NULL;
5261 char *exp_start = NULL;
5262 char *exp_end = NULL;
5263 char *tok, *end_tok;
5265 char *cond_start = NULL;
5266 char *cond_end = NULL;
5267 struct expression *cond = NULL;
5268 int i, other_type_used, target_resources_ok = 0;
5269 enum bptype bp_type;
5272 INIT_SAL (&sal); /* initialize to zeroes */
5274 /* Parse arguments. */
5275 innermost_block = NULL;
5277 exp = parse_exp_1 (&arg, 0, 0);
5279 exp_valid_block = innermost_block;
5280 mark = value_mark ();
5281 val = evaluate_expression (exp);
5282 release_value (val);
5283 if (VALUE_LAZY (val))
5284 value_fetch_lazy (val);
5287 while (*tok == ' ' || *tok == '\t')
5291 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5294 toklen = end_tok - tok;
5295 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5297 tok = cond_start = end_tok + 1;
5298 cond = parse_exp_1 (&tok, 0, 0);
5302 error ("Junk at end of command.");
5304 if (accessflag == hw_read)
5305 bp_type = bp_read_watchpoint;
5306 else if (accessflag == hw_access)
5307 bp_type = bp_access_watchpoint;
5309 bp_type = bp_hardware_watchpoint;
5311 mem_cnt = can_use_hardware_watchpoint (val);
5312 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5313 error ("Expression cannot be implemented with read/access watchpoint.");
5316 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5317 target_resources_ok =
5318 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5320 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5321 error ("Target does not support this type of hardware watchpoint.");
5323 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5324 error ("Target can only support one kind of HW watchpoint at a time.");
5327 #if defined(HPUXHPPA)
5328 /* On HP-UX if you set a h/w
5329 watchpoint before the "run" command, the inferior dies with a e.g.,
5330 SIGILL once you start it. I initially believed this was due to a
5331 bad interaction between page protection traps and the initial
5332 startup sequence by the dynamic linker.
5334 However, I tried avoiding that by having HP-UX's implementation of
5335 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5336 yet, which forced slow watches before a "run" or "attach", and it
5337 still fails somewhere in the startup code.
5339 Until I figure out what's happening, I'm disallowing watches altogether
5340 before the "run" or "attach" command. We'll tell the user they must
5341 set watches after getting the program started. */
5342 if (!target_has_execution)
5344 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5347 #endif /* HPUXHPPA */
5349 /* Now set up the breakpoint. */
5350 b = set_raw_breakpoint (sal);
5351 set_breakpoint_count (breakpoint_count + 1);
5352 b->number = breakpoint_count;
5353 b->disposition = donttouch;
5355 b->exp_valid_block = exp_valid_block;
5356 b->exp_string = savestring (exp_start, exp_end - exp_start);
5360 b->cond_string = savestring (cond_start, cond_end - cond_start);
5364 frame = block_innermost_frame (exp_valid_block);
5367 prev_frame = get_prev_frame (frame);
5368 b->watchpoint_frame = frame->frame;
5371 b->watchpoint_frame = (CORE_ADDR) 0;
5373 if (mem_cnt && target_resources_ok > 0)
5376 b->type = bp_watchpoint;
5378 /* If the expression is "local", then set up a "watchpoint scope"
5379 breakpoint at the point where we've left the scope of the watchpoint
5381 if (innermost_block)
5385 struct breakpoint *scope_breakpoint;
5386 struct symtab_and_line scope_sal;
5388 INIT_SAL (&scope_sal); /* initialize to zeroes */
5389 scope_sal.pc = get_frame_pc (prev_frame);
5390 scope_sal.section = find_pc_overlay (scope_sal.pc);
5392 scope_breakpoint = set_raw_breakpoint (scope_sal);
5393 set_breakpoint_count (breakpoint_count + 1);
5394 scope_breakpoint->number = breakpoint_count;
5396 scope_breakpoint->type = bp_watchpoint_scope;
5397 scope_breakpoint->enable = enabled;
5399 /* Automatically delete the breakpoint when it hits. */
5400 scope_breakpoint->disposition = del;
5402 /* Only break in the proper frame (help with recursion). */
5403 scope_breakpoint->frame = prev_frame->frame;
5405 /* Set the address at which we will stop. */
5406 scope_breakpoint->address = get_frame_pc (prev_frame);
5408 /* The scope breakpoint is related to the watchpoint. We
5409 will need to act on them together. */
5410 b->related_breakpoint = scope_breakpoint;
5413 value_free_to_mark (mark);
5417 /* Return count of locations need to be watched and can be handled
5418 in hardware. If the watchpoint can not be handled
5419 in hardware return zero. */
5421 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5422 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5423 ((BYTE_SIZE) <= (REGISTER_SIZE))
5426 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5427 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5428 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5432 can_use_hardware_watchpoint (struct value *v)
5434 int found_memory_cnt = 0;
5435 struct value *head = v;
5437 /* Did the user specifically forbid us to use hardware watchpoints? */
5438 if (!can_use_hw_watchpoints)
5441 /* Make sure that the value of the expression depends only upon
5442 memory contents, and values computed from them within GDB. If we
5443 find any register references or function calls, we can't use a
5444 hardware watchpoint.
5446 The idea here is that evaluating an expression generates a series
5447 of values, one holding the value of every subexpression. (The
5448 expression a*b+c has five subexpressions: a, b, a*b, c, and
5449 a*b+c.) GDB's values hold almost enough information to establish
5450 the criteria given above --- they identify memory lvalues,
5451 register lvalues, computed values, etcetera. So we can evaluate
5452 the expression, and then scan the chain of values that leaves
5453 behind to decide whether we can detect any possible change to the
5454 expression's final value using only hardware watchpoints.
5456 However, I don't think that the values returned by inferior
5457 function calls are special in any way. So this function may not
5458 notice that an expression involving an inferior function call
5459 can't be watched with hardware watchpoints. FIXME. */
5460 for (; v; v = v->next)
5462 if (VALUE_LVAL (v) == lval_memory)
5465 /* A lazy memory lvalue is one that GDB never needed to fetch;
5466 we either just used its address (e.g., `a' in `a.b') or
5467 we never needed it at all (e.g., `a' in `a,b'). */
5471 /* Ahh, memory we actually used! Check if we can cover
5472 it with hardware watchpoints. */
5473 struct type *vtype = check_typedef (VALUE_TYPE (v));
5475 /* We only watch structs and arrays if user asked for it
5476 explicitly, never if they just happen to appear in a
5477 middle of some value chain. */
5479 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5480 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5482 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5483 int len = TYPE_LENGTH (VALUE_TYPE (v));
5485 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5492 else if (v->lval != not_lval && v->modifiable == 0)
5493 return 0; /* ??? What does this represent? */
5494 else if (v->lval == lval_register)
5495 return 0; /* cannot watch a register with a HW watchpoint */
5498 /* The expression itself looks suitable for using a hardware
5499 watchpoint, but give the target machine a chance to reject it. */
5500 return found_memory_cnt;
5505 watch_command_wrapper (char *arg, int from_tty)
5507 watch_command (arg, from_tty);
5511 watch_command (char *arg, int from_tty)
5513 watch_command_1 (arg, hw_write, from_tty);
5518 rwatch_command_wrapper (char *arg, int from_tty)
5520 rwatch_command (arg, from_tty);
5524 rwatch_command (char *arg, int from_tty)
5526 watch_command_1 (arg, hw_read, from_tty);
5531 awatch_command_wrapper (char *arg, int from_tty)
5533 awatch_command (arg, from_tty);
5537 awatch_command (char *arg, int from_tty)
5539 watch_command_1 (arg, hw_access, from_tty);
5543 /* Helper routines for the until_command routine in infcmd.c. Here
5544 because it uses the mechanisms of breakpoints. */
5546 /* This function is called by fetch_inferior_event via the
5547 cmd_continuation pointer, to complete the until command. It takes
5548 care of cleaning up the temporary breakpoints set up by the until
5551 until_break_command_continuation (struct continuation_arg *arg)
5553 struct cleanup *cleanups;
5555 cleanups = (struct cleanup *) arg->data.pointer;
5556 do_exec_cleanups (cleanups);
5561 until_break_command (char *arg, int from_tty)
5563 struct symtabs_and_lines sals;
5564 struct symtab_and_line sal;
5565 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5566 struct breakpoint *breakpoint;
5567 struct cleanup *old_chain;
5568 struct continuation_arg *arg1;
5571 clear_proceed_status ();
5573 /* Set a breakpoint where the user wants it and at return from
5576 if (default_breakpoint_valid)
5577 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5578 default_breakpoint_line, (char ***) NULL);
5580 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5581 0, (char ***) NULL);
5583 if (sals.nelts != 1)
5584 error ("Couldn't get information on specified line.");
5587 xfree (sals.sals); /* malloc'd, so freed */
5590 error ("Junk at end of arguments.");
5592 resolve_sal_pc (&sal);
5594 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5596 if (!event_loop_p || !target_can_async_p ())
5597 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5599 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5601 /* If we are running asynchronously, and the target supports async
5602 execution, we are not waiting for the target to stop, in the call
5603 tp proceed, below. This means that we cannot delete the
5604 brekpoints until the target has actually stopped. The only place
5605 where we get a chance to do that is in fetch_inferior_event, so
5606 we must set things up for that. */
5608 if (event_loop_p && target_can_async_p ())
5610 /* In this case the arg for the continuation is just the point
5611 in the exec_cleanups chain from where to start doing
5612 cleanups, because all the continuation does is the cleanups in
5613 the exec_cleanup_chain. */
5615 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5617 arg1->data.pointer = old_chain;
5619 add_continuation (until_break_command_continuation, arg1);
5622 /* Keep within the current frame */
5626 sal = find_pc_line (prev_frame->pc, 0);
5627 sal.pc = prev_frame->pc;
5628 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5629 if (!event_loop_p || !target_can_async_p ())
5630 make_cleanup_delete_breakpoint (breakpoint);
5632 make_exec_cleanup_delete_breakpoint (breakpoint);
5635 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5636 /* Do the cleanups now, anly if we are not running asynchronously,
5637 of if we are, but the target is still synchronous. */
5638 if (!event_loop_p || !target_can_async_p ())
5639 do_cleanups (old_chain);
5643 /* These aren't used; I don't konw what they were for. */
5644 /* Set a breakpoint at the catch clause for NAME. */
5646 catch_breakpoint (char *name)
5651 disable_catch_breakpoint (void)
5656 delete_catch_breakpoint (void)
5661 enable_catch_breakpoint (void)
5668 struct sal_chain *next;
5669 struct symtab_and_line sal;
5673 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5674 had been commented out in the v.4.16 sources, and stays
5675 disabled there now because "catch NAME" syntax isn't allowed.
5677 /* This isn't used; I don't know what it was for. */
5678 /* For each catch clause identified in ARGS, run FUNCTION
5679 with that clause as an argument. */
5680 static struct symtabs_and_lines
5681 map_catch_names (char *args, int (*function) ())
5683 register char *p = args;
5685 struct symtabs_and_lines sals;
5687 struct sal_chain *sal_chain = 0;
5691 error_no_arg ("one or more catch names");
5699 /* Don't swallow conditional part. */
5700 if (p1[0] == 'i' && p1[1] == 'f'
5701 && (p1[2] == ' ' || p1[2] == '\t'))
5707 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5711 if (*p1 && *p1 != ' ' && *p1 != '\t')
5712 error ("Arguments must be catch names.");
5718 struct sal_chain *next = (struct sal_chain *)
5719 alloca (sizeof (struct sal_chain));
5720 next->next = sal_chain;
5721 next->sal = get_catch_sal (p);
5726 printf_unfiltered ("No catch clause for exception %s.\n", p);
5731 while (*p == ' ' || *p == '\t')
5737 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5739 static struct symtabs_and_lines
5740 get_catch_sals (int this_level_only)
5742 register struct blockvector *bl;
5743 register struct block *block;
5744 int index, have_default = 0;
5746 struct symtabs_and_lines sals;
5747 struct sal_chain *sal_chain = 0;
5748 char *blocks_searched;
5750 /* Not sure whether an error message is always the correct response,
5751 but it's better than a core dump. */
5752 if (selected_frame == NULL)
5753 error ("No selected frame.");
5754 block = get_frame_block (selected_frame);
5755 pc = selected_frame->pc;
5761 error ("No symbol table info available.\n");
5763 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5764 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5765 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5769 CORE_ADDR end = BLOCK_END (block) - 4;
5772 if (bl != blockvector_for_pc (end, &index))
5773 error ("blockvector blotch");
5774 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5775 error ("blockvector botch");
5776 last_index = BLOCKVECTOR_NBLOCKS (bl);
5779 /* Don't print out blocks that have gone by. */
5780 while (index < last_index
5781 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5784 while (index < last_index
5785 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5787 if (blocks_searched[index] == 0)
5789 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5792 register struct symbol *sym;
5794 nsyms = BLOCK_NSYMS (b);
5796 for (i = 0; i < nsyms; i++)
5798 sym = BLOCK_SYM (b, i);
5799 if (STREQ (SYMBOL_NAME (sym), "default"))
5805 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5807 struct sal_chain *next = (struct sal_chain *)
5808 alloca (sizeof (struct sal_chain));
5809 next->next = sal_chain;
5810 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5815 blocks_searched[index] = 1;
5821 if (sal_chain && this_level_only)
5824 /* After handling the function's top-level block, stop.
5825 Don't continue to its superblock, the block of
5826 per-file symbols. */
5827 if (BLOCK_FUNCTION (block))
5829 block = BLOCK_SUPERBLOCK (block);
5834 struct sal_chain *tmp_chain;
5836 /* Count the number of entries. */
5837 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5838 tmp_chain = tmp_chain->next)
5842 sals.sals = (struct symtab_and_line *)
5843 xmalloc (index * sizeof (struct symtab_and_line));
5844 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5845 sals.sals[index] = sal_chain->sal;
5852 ep_skip_leading_whitespace (char **s)
5854 if ((s == NULL) || (*s == NULL))
5856 while (isspace (**s))
5860 /* This function examines a string, and attempts to find a token
5861 that might be an event name in the leading characters. If a
5862 possible match is found, a pointer to the last character of
5863 the token is returned. Else, NULL is returned. */
5866 ep_find_event_name_end (char *arg)
5869 char *event_name_end = NULL;
5871 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5875 /* We break out of the loop when we find a token delimiter.
5876 Basically, we're looking for alphanumerics and underscores;
5877 anything else delimites the token. */
5880 if (!isalnum (*s) && (*s != '_'))
5886 return event_name_end;
5890 /* This function attempts to parse an optional "if <cond>" clause
5891 from the arg string. If one is not found, it returns NULL.
5893 Else, it returns a pointer to the condition string. (It does not
5894 attempt to evaluate the string against a particular block.) And,
5895 it updates arg to point to the first character following the parsed
5896 if clause in the arg string. */
5899 ep_parse_optional_if_clause (char **arg)
5903 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5906 /* Skip the "if" keyword. */
5909 /* Skip any extra leading whitespace, and record the start of the
5910 condition string. */
5911 ep_skip_leading_whitespace (arg);
5914 /* Assume that the condition occupies the remainder of the arg string. */
5915 (*arg) += strlen (cond_string);
5920 /* This function attempts to parse an optional filename from the arg
5921 string. If one is not found, it returns NULL.
5923 Else, it returns a pointer to the parsed filename. (This function
5924 makes no attempt to verify that a file of that name exists, or is
5925 accessible.) And, it updates arg to point to the first character
5926 following the parsed filename in the arg string.
5928 Note that clients needing to preserve the returned filename for
5929 future access should copy it to their own buffers. */
5931 ep_parse_optional_filename (char **arg)
5933 static char filename[1024];
5938 if ((*arg_p == '\0') || isspace (*arg_p))
5956 /* Commands to deal with catching events, such as signals, exceptions,
5957 process start/exit, etc. */
5961 catch_fork, catch_vfork
5965 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5966 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5967 char *arg, int tempflag, int from_tty);
5970 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5973 char *cond_string = NULL;
5975 ep_skip_leading_whitespace (&arg);
5977 /* The allowed syntax is:
5979 catch [v]fork if <cond>
5981 First, check if there's an if clause. */
5982 cond_string = ep_parse_optional_if_clause (&arg);
5984 if ((*arg != '\0') && !isspace (*arg))
5985 error ("Junk at end of arguments.");
5987 /* If this target supports it, create a fork or vfork catchpoint
5988 and enable reporting of such events. */
5992 create_fork_event_catchpoint (tempflag, cond_string);
5995 create_vfork_event_catchpoint (tempflag, cond_string);
5998 error ("unsupported or unknown fork kind; cannot catch it");
6004 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6006 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6008 char *cond_string = NULL;
6010 ep_skip_leading_whitespace (&arg);
6012 /* The allowed syntax is:
6014 catch exec if <cond>
6016 First, check if there's an if clause. */
6017 cond_string = ep_parse_optional_if_clause (&arg);
6019 if ((*arg != '\0') && !isspace (*arg))
6020 error ("Junk at end of arguments.");
6022 /* If this target supports it, create an exec catchpoint
6023 and enable reporting of such events. */
6024 create_exec_event_catchpoint (tempflag, cond_string);
6028 #if defined(SOLIB_ADD)
6030 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6032 char *dll_pathname = NULL;
6033 char *cond_string = NULL;
6035 ep_skip_leading_whitespace (&arg);
6037 /* The allowed syntax is:
6039 catch load if <cond>
6040 catch load <filename>
6041 catch load <filename> if <cond>
6043 The user is not allowed to specify the <filename> after an
6046 We'll ignore the pathological case of a file named "if".
6048 First, check if there's an if clause. If so, then there
6049 cannot be a filename. */
6050 cond_string = ep_parse_optional_if_clause (&arg);
6052 /* If there was an if clause, then there cannot be a filename.
6053 Else, there might be a filename and an if clause. */
6054 if (cond_string == NULL)
6056 dll_pathname = ep_parse_optional_filename (&arg);
6057 ep_skip_leading_whitespace (&arg);
6058 cond_string = ep_parse_optional_if_clause (&arg);
6061 if ((*arg != '\0') && !isspace (*arg))
6062 error ("Junk at end of arguments.");
6064 /* Create a load breakpoint that only triggers when a load of
6065 the specified dll (or any dll, if no pathname was specified)
6067 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6068 dll_pathname, cond_string);
6072 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6074 char *dll_pathname = NULL;
6075 char *cond_string = NULL;
6077 ep_skip_leading_whitespace (&arg);
6079 /* The allowed syntax is:
6081 catch unload if <cond>
6082 catch unload <filename>
6083 catch unload <filename> if <cond>
6085 The user is not allowed to specify the <filename> after an
6088 We'll ignore the pathological case of a file named "if".
6090 First, check if there's an if clause. If so, then there
6091 cannot be a filename. */
6092 cond_string = ep_parse_optional_if_clause (&arg);
6094 /* If there was an if clause, then there cannot be a filename.
6095 Else, there might be a filename and an if clause. */
6096 if (cond_string == NULL)
6098 dll_pathname = ep_parse_optional_filename (&arg);
6099 ep_skip_leading_whitespace (&arg);
6100 cond_string = ep_parse_optional_if_clause (&arg);
6103 if ((*arg != '\0') && !isspace (*arg))
6104 error ("Junk at end of arguments.");
6106 /* Create an unload breakpoint that only triggers when an unload of
6107 the specified dll (or any dll, if no pathname was specified)
6109 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6110 dll_pathname, cond_string);
6112 #endif /* SOLIB_ADD */
6114 /* Commands to deal with catching exceptions. */
6116 /* Set a breakpoint at the specified callback routine for an
6117 exception event callback */
6120 create_exception_catchpoint (int tempflag, char *cond_string,
6121 enum exception_event_kind ex_event,
6122 struct symtab_and_line *sal)
6124 struct breakpoint *b;
6125 int thread = -1; /* All threads. */
6127 if (!sal) /* no exception support? */
6130 b = set_raw_breakpoint (*sal);
6131 set_breakpoint_count (breakpoint_count + 1);
6132 b->number = breakpoint_count;
6134 b->cond_string = (cond_string == NULL) ?
6135 NULL : savestring (cond_string, strlen (cond_string));
6137 b->addr_string = NULL;
6138 b->enable = enabled;
6139 b->disposition = tempflag ? del : donttouch;
6142 case EX_EVENT_THROW:
6143 b->type = bp_catch_throw;
6145 case EX_EVENT_CATCH:
6146 b->type = bp_catch_catch;
6148 default: /* error condition */
6150 b->enable = disabled;
6151 error ("Internal error -- invalid catchpoint kind");
6156 /* Deal with "catch catch" and "catch throw" commands */
6159 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6160 int tempflag, int from_tty)
6162 char *cond_string = NULL;
6163 struct symtab_and_line *sal = NULL;
6165 ep_skip_leading_whitespace (&arg);
6167 cond_string = ep_parse_optional_if_clause (&arg);
6169 if ((*arg != '\0') && !isspace (*arg))
6170 error ("Junk at end of arguments.");
6172 if ((ex_event != EX_EVENT_THROW) &&
6173 (ex_event != EX_EVENT_CATCH))
6174 error ("Unsupported or unknown exception event; cannot catch it");
6176 /* See if we can find a callback routine */
6177 sal = target_enable_exception_callback (ex_event, 1);
6181 /* We have callbacks from the runtime system for exceptions.
6182 Set a breakpoint on the sal found, if no errors */
6183 if (sal != (struct symtab_and_line *) -1)
6184 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6186 return; /* something went wrong with setting up callbacks */
6190 /* No callbacks from runtime system for exceptions.
6191 Try GNU C++ exception breakpoints using labels in debug info. */
6192 if (ex_event == EX_EVENT_CATCH)
6194 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6196 else if (ex_event == EX_EVENT_THROW)
6198 /* Set a breakpoint on __raise_exception () */
6200 warning ("Unsupported with this platform/compiler combination.");
6201 warning ("Perhaps you can achieve the effect you want by setting");
6202 warning ("a breakpoint on __raise_exception().");
6207 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6208 inside a catch_errors */
6211 cover_target_enable_exception_callback (PTR arg)
6213 args_for_catchpoint_enable *args = arg;
6214 struct symtab_and_line *sal;
6215 sal = target_enable_exception_callback (args->kind, args->enable);
6218 else if (sal == (struct symtab_and_line *) -1)
6221 return 1; /*is valid */
6226 /* This is the original v.4.16 and earlier version of the
6227 catch_command_1() function. Now that other flavours of "catch"
6228 have been introduced, and since exception handling can be handled
6229 in other ways (through target ops) also, this is used only for the
6230 GNU C++ exception handling system.
6231 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6232 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6233 there was no code in GDB 4.16 for "catch throw".
6235 Called from catch_exception_command_1 () */
6239 handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
6241 /* First, translate ARG into something we can deal with in terms
6244 struct symtabs_and_lines sals;
6245 struct symtab_and_line sal;
6246 register struct expression *cond = 0;
6247 register struct breakpoint *b;
6251 INIT_SAL (&sal); /* initialize to zeroes */
6253 /* If no arg given, or if first arg is 'if ', all active catch clauses
6254 are breakpointed. */
6256 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6257 && (arg[2] == ' ' || arg[2] == '\t')))
6259 /* Grab all active catch clauses. */
6260 sals = get_catch_sals (0);
6264 /* Grab selected catch clauses. */
6265 error ("catch NAME not implemented");
6268 /* Not sure why this code has been disabled. I'm leaving
6269 it disabled. We can never come here now anyway
6270 since we don't allow the "catch NAME" syntax.
6273 /* This isn't used; I don't know what it was for. */
6274 sals = map_catch_names (arg, catch_breakpoint);
6282 for (i = 0; i < sals.nelts; i++)
6284 resolve_sal_pc (&sals.sals[i]);
6288 if (arg[0] == 'i' && arg[1] == 'f'
6289 && (arg[2] == ' ' || arg[2] == '\t'))
6290 cond = parse_exp_1 ((arg += 2, &arg),
6291 block_for_pc (sals.sals[i].pc), 0);
6293 error ("Junk at end of arguments.");
6298 for (i = 0; i < sals.nelts; i++)
6303 describe_other_breakpoints (sal.pc, sal.section);
6305 b = set_raw_breakpoint (sal);
6306 set_breakpoint_count (breakpoint_count + 1);
6307 b->number = breakpoint_count;
6309 /* Important -- this is an ordinary breakpoint. For platforms
6310 with callback support for exceptions,
6311 create_exception_catchpoint() will create special bp types
6312 (bp_catch_catch and bp_catch_throw), and there is code in
6313 insert_breakpoints() and elsewhere that depends on that. */
6314 b->type = bp_breakpoint;
6317 b->enable = enabled;
6318 b->disposition = tempflag ? del : donttouch;
6325 warning ("Multiple breakpoints were set.");
6326 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6332 /* This creates a temporary internal breakpoint
6333 just to placate infrun */
6334 static struct breakpoint *
6335 create_temp_exception_breakpoint (CORE_ADDR pc)
6337 struct symtab_and_line sal;
6338 struct breakpoint *b;
6345 b = set_raw_breakpoint (sal);
6347 error ("Internal error -- couldn't set temp exception breakpoint");
6349 b->type = bp_breakpoint;
6350 b->disposition = del;
6351 b->enable = enabled;
6353 b->number = internal_breakpoint_number--;
6359 catch_command_1 (char *arg, int tempflag, int from_tty)
6362 /* The first argument may be an event name, such as "start" or "load".
6363 If so, then handle it as such. If it doesn't match an event name,
6364 then attempt to interpret it as an exception name. (This latter is
6365 the v4.16-and-earlier GDB meaning of the "catch" command.)
6367 First, try to find the bounds of what might be an event name. */
6368 char *arg1_start = arg;
6372 if (arg1_start == NULL)
6374 /* Old behaviour was to use pre-v-4.16 syntax */
6375 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6377 /* Now, this is not allowed */
6378 error ("Catch requires an event name.");
6381 arg1_end = ep_find_event_name_end (arg1_start);
6382 if (arg1_end == NULL)
6383 error ("catch requires an event");
6384 arg1_length = arg1_end + 1 - arg1_start;
6386 /* Try to match what we found against known event names. */
6387 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6389 error ("Catch of signal not yet implemented");
6391 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6393 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6394 tempflag, from_tty);
6396 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6398 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6399 tempflag, from_tty);
6401 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6403 error ("Catch of thread_start not yet implemented");
6405 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6407 error ("Catch of thread_exit not yet implemented");
6409 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6411 error ("Catch of thread_join not yet implemented");
6413 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6415 error ("Catch of start not yet implemented");
6417 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6419 error ("Catch of exit not yet implemented");
6421 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6423 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6424 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6426 error ("Catch of fork not yet implemented");
6429 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6431 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6432 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6434 error ("Catch of vfork not yet implemented");
6437 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6439 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6440 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6442 error ("Catch of exec not yet implemented");
6445 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6447 #if defined(SOLIB_ADD)
6448 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6450 error ("Catch of load not implemented");
6453 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6455 #if defined(SOLIB_ADD)
6456 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6458 error ("Catch of load not implemented");
6461 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6463 error ("Catch of stop not yet implemented");
6466 /* This doesn't appear to be an event name */
6470 /* Pre-v.4.16 behaviour was to treat the argument
6471 as the name of an exception */
6472 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6473 /* Now this is not allowed */
6474 error ("Unknown event kind specified for catch");
6479 /* Used by the gui, could be made a worker for other things. */
6482 set_breakpoint_sal (struct symtab_and_line sal)
6484 struct breakpoint *b;
6485 b = set_raw_breakpoint (sal);
6486 set_breakpoint_count (breakpoint_count + 1);
6487 b->number = breakpoint_count;
6488 b->type = bp_breakpoint;
6495 /* These aren't used; I don't know what they were for. */
6496 /* Disable breakpoints on all catch clauses described in ARGS. */
6498 disable_catch (char *args)
6500 /* Map the disable command to catch clauses described in ARGS. */
6503 /* Enable breakpoints on all catch clauses described in ARGS. */
6505 enable_catch (char *args)
6507 /* Map the disable command to catch clauses described in ARGS. */
6510 /* Delete breakpoints on all catch clauses in the active scope. */
6512 delete_catch (char *args)
6514 /* Map the delete command to catch clauses described in ARGS. */
6519 catch_command (char *arg, int from_tty)
6521 catch_command_1 (arg, 0, from_tty);
6526 tcatch_command (char *arg, int from_tty)
6528 catch_command_1 (arg, 1, from_tty);
6533 clear_command (char *arg, int from_tty)
6535 register struct breakpoint *b, *b1;
6537 struct symtabs_and_lines sals;
6538 struct symtab_and_line sal;
6539 register struct breakpoint *found;
6544 sals = decode_line_spec (arg, 1);
6549 sals.sals = (struct symtab_and_line *)
6550 xmalloc (sizeof (struct symtab_and_line));
6551 INIT_SAL (&sal); /* initialize to zeroes */
6552 sal.line = default_breakpoint_line;
6553 sal.symtab = default_breakpoint_symtab;
6554 sal.pc = default_breakpoint_address;
6555 if (sal.symtab == 0)
6556 error ("No source file specified.");
6564 /* For each line spec given, delete bps which correspond
6565 to it. We do this in two loops: the first loop looks at
6566 the initial bp(s) in the chain which should be deleted,
6567 the second goes down the rest of the chain looking ahead
6568 one so it can take those bps off the chain without messing
6572 for (i = 0; i < sals.nelts; i++)
6574 /* If exact pc given, clear bpts at that pc.
6575 If line given (pc == 0), clear all bpts on specified line.
6576 If defaulting, clear all bpts on default line
6579 defaulting sal.pc != 0 tests to do
6584 1 0 <can't happen> */
6587 found = (struct breakpoint *) 0;
6590 while (breakpoint_chain
6591 /* Why don't we check here that this is not
6592 a watchpoint, etc., as we do below?
6593 I can't make it fail, but don't know
6594 what's stopping the failure: a watchpoint
6595 of the same address as "sal.pc" should
6596 wind up being deleted. */
6598 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6599 (overlay_debugging == 0 ||
6600 breakpoint_chain->section == sal.section))
6601 || ((default_match || (0 == sal.pc))
6602 && breakpoint_chain->source_file != NULL
6603 && sal.symtab != NULL
6604 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6605 && breakpoint_chain->line_number == sal.line)))
6608 b1 = breakpoint_chain;
6609 breakpoint_chain = b1->next;
6617 && b->next->type != bp_none
6618 && b->next->type != bp_watchpoint
6619 && b->next->type != bp_hardware_watchpoint
6620 && b->next->type != bp_read_watchpoint
6621 && b->next->type != bp_access_watchpoint
6622 && (((sal.pc && (b->next->address == sal.pc)) &&
6623 (overlay_debugging == 0 ||
6624 b->next->section == sal.section))
6625 || ((default_match || (0 == sal.pc))
6626 && b->next->source_file != NULL
6627 && sal.symtab != NULL
6628 && STREQ (b->next->source_file, sal.symtab->filename)
6629 && b->next->line_number == sal.line)))
6642 error ("No breakpoint at %s.", arg);
6644 error ("No breakpoint at this line.");
6648 from_tty = 1; /* Always report if deleted more than one */
6650 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6651 breakpoints_changed ();
6655 printf_unfiltered ("%d ", found->number);
6657 delete_breakpoint (found);
6661 putchar_unfiltered ('\n');
6666 /* Delete breakpoint in BS if they are `delete' breakpoints and
6667 all breakpoints that are marked for deletion, whether hit or not.
6668 This is called after any breakpoint is hit, or after errors. */
6671 breakpoint_auto_delete (bpstat bs)
6673 struct breakpoint *b, *temp;
6675 for (; bs; bs = bs->next)
6676 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6678 delete_breakpoint (bs->breakpoint_at);
6680 ALL_BREAKPOINTS_SAFE (b, temp)
6682 if (b->disposition == del_at_next_stop)
6683 delete_breakpoint (b);
6687 /* Delete a breakpoint and clean up all traces of it in the data
6691 delete_breakpoint (struct breakpoint *bpt)
6693 register struct breakpoint *b;
6697 error ("Internal error (attempted to delete a NULL breakpoint)");
6700 /* Has this bp already been deleted? This can happen because multiple
6701 lists can hold pointers to bp's. bpstat lists are especial culprits.
6703 One example of this happening is a watchpoint's scope bp. When the
6704 scope bp triggers, we notice that the watchpoint is out of scope, and
6705 delete it. We also delete its scope bp. But the scope bp is marked
6706 "auto-deleting", and is already on a bpstat. That bpstat is then
6707 checked for auto-deleting bp's, which are deleted.
6709 A real solution to this problem might involve reference counts in bp's,
6710 and/or giving them pointers back to their referencing bpstat's, and
6711 teaching delete_breakpoint to only free a bp's storage when no more
6712 references were extent. A cheaper bandaid was chosen. */
6713 if (bpt->type == bp_none)
6716 if (delete_breakpoint_hook)
6717 delete_breakpoint_hook (bpt);
6718 breakpoint_delete_event (bpt->number);
6721 remove_breakpoint (bpt, mark_uninserted);
6723 if (breakpoint_chain == bpt)
6724 breakpoint_chain = bpt->next;
6726 /* If we have callback-style exception catchpoints, don't go through
6727 the adjustments to the C++ runtime library etc. if the inferior
6728 isn't actually running. target_enable_exception_callback for a
6729 null target ops vector gives an undesirable error message, so we
6730 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6731 exceptions are supported in this way, it's OK for now. FIXME */
6732 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6734 static char message1[] = "Error in deleting catchpoint %d:\n";
6735 static char message[sizeof (message1) + 30];
6736 args_for_catchpoint_enable args;
6738 /* Format possible error msg */
6739 sprintf (message, message1, bpt->number);
6740 args.kind = bpt->type == bp_catch_catch ?
6741 EX_EVENT_CATCH : EX_EVENT_THROW;
6743 catch_errors (cover_target_enable_exception_callback, &args,
6744 message, RETURN_MASK_ALL);
6751 b->next = bpt->next;
6755 /* Before turning off the visuals for the bp, check to see that
6756 there are no other bps at the same address. */
6763 clearIt = (b->address != bpt->address);
6770 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6771 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6775 check_duplicates (bpt);
6776 /* If this breakpoint was inserted, and there is another breakpoint
6777 at the same address, we need to insert the other breakpoint. */
6779 && bpt->type != bp_hardware_watchpoint
6780 && bpt->type != bp_read_watchpoint
6781 && bpt->type != bp_access_watchpoint
6782 && bpt->type != bp_catch_fork
6783 && bpt->type != bp_catch_vfork
6784 && bpt->type != bp_catch_exec)
6787 if (b->address == bpt->address
6788 && b->section == bpt->section
6790 && b->enable != disabled
6791 && b->enable != shlib_disabled
6792 && b->enable != call_disabled)
6796 /* We should never reach this point if there is a permanent
6797 breakpoint at the same address as the one being deleted.
6798 If there is a permanent breakpoint somewhere, it should
6799 always be the only one inserted. */
6800 if (b->enable == permanent)
6801 internal_error (__FILE__, __LINE__,
6802 "another breakpoint was inserted on top of "
6803 "a permanent breakpoint");
6805 if (b->type == bp_hardware_breakpoint)
6806 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6808 val = target_insert_breakpoint (b->address, b->shadow_contents);
6812 target_terminal_ours_for_output ();
6813 warning ("Cannot insert breakpoint %d:", b->number);
6814 memory_error (val, b->address); /* which bombs us out */
6821 free_command_lines (&bpt->commands);
6824 if (bpt->cond_string != NULL)
6825 xfree (bpt->cond_string);
6826 if (bpt->addr_string != NULL)
6827 xfree (bpt->addr_string);
6828 if (bpt->exp != NULL)
6830 if (bpt->exp_string != NULL)
6831 xfree (bpt->exp_string);
6832 if (bpt->val != NULL)
6833 value_free (bpt->val);
6834 if (bpt->source_file != NULL)
6835 xfree (bpt->source_file);
6836 if (bpt->dll_pathname != NULL)
6837 xfree (bpt->dll_pathname);
6838 if (bpt->triggered_dll_pathname != NULL)
6839 xfree (bpt->triggered_dll_pathname);
6840 if (bpt->exec_pathname != NULL)
6841 xfree (bpt->exec_pathname);
6843 /* Be sure no bpstat's are pointing at it after it's been freed. */
6844 /* FIXME, how can we find all bpstat's?
6845 We just check stop_bpstat for now. */
6846 for (bs = stop_bpstat; bs; bs = bs->next)
6847 if (bs->breakpoint_at == bpt)
6849 bs->breakpoint_at = NULL;
6851 /* we'd call bpstat_clear_actions, but that free's stuff and due
6852 to the multiple pointers pointing to one item with no
6853 reference counts found anywhere through out the bpstat's (how
6854 do you spell fragile?), we don't want to free things twice --
6855 better a memory leak than a corrupt malloc pool! */
6856 bs->commands = NULL;
6859 /* On the chance that someone will soon try again to delete this same
6860 bp, we mark it as deleted before freeing its storage. */
6861 bpt->type = bp_none;
6867 do_delete_breakpoint_cleanup (void *b)
6869 delete_breakpoint (b);
6873 make_cleanup_delete_breakpoint (struct breakpoint *b)
6875 return make_cleanup (do_delete_breakpoint_cleanup, b);
6879 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6881 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6885 delete_command (char *arg, int from_tty)
6887 struct breakpoint *b, *temp;
6891 int breaks_to_delete = 0;
6893 /* Delete all breakpoints if no argument.
6894 Do not delete internal or call-dummy breakpoints, these
6895 have to be deleted with an explicit breakpoint number argument. */
6898 if (b->type != bp_call_dummy &&
6899 b->type != bp_shlib_event &&
6900 b->type != bp_thread_event &&
6902 breaks_to_delete = 1;
6905 /* Ask user only if there are some breakpoints to delete. */
6907 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6909 ALL_BREAKPOINTS_SAFE (b, temp)
6911 if (b->type != bp_call_dummy &&
6912 b->type != bp_shlib_event &&
6913 b->type != bp_thread_event &&
6915 delete_breakpoint (b);
6920 map_breakpoint_numbers (arg, delete_breakpoint);
6923 /* Reset a breakpoint given it's struct breakpoint * BINT.
6924 The value we return ends up being the return value from catch_errors.
6925 Unused in this case. */
6928 breakpoint_re_set_one (PTR bint)
6930 /* get past catch_errs */
6931 struct breakpoint *b = (struct breakpoint *) bint;
6934 struct symtabs_and_lines sals;
6936 enum enable save_enable;
6941 warning ("attempted to reset apparently deleted breakpoint #%d?",
6945 case bp_hardware_breakpoint:
6947 case bp_catch_unload:
6948 if (b->addr_string == NULL)
6950 /* Anything without a string can't be re-set. */
6951 delete_breakpoint (b);
6954 /* In case we have a problem, disable this breakpoint. We'll restore
6955 its status if we succeed. */
6956 save_enable = b->enable;
6957 b->enable = disabled;
6959 set_language (b->language);
6960 input_radix = b->input_radix;
6962 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6963 for (i = 0; i < sals.nelts; i++)
6965 resolve_sal_pc (&sals.sals[i]);
6967 /* Reparse conditions, they might contain references to the
6969 if (b->cond_string != NULL)
6974 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6977 /* We need to re-set the breakpoint if the address changes... */
6978 if (b->address != sals.sals[i].pc
6979 /* ...or new and old breakpoints both have source files, and
6980 the source file name or the line number changes... */
6981 || (b->source_file != NULL
6982 && sals.sals[i].symtab != NULL
6983 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6984 || b->line_number != sals.sals[i].line)
6986 /* ...or we switch between having a source file and not having
6988 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6991 if (b->source_file != NULL)
6992 xfree (b->source_file);
6993 if (sals.sals[i].symtab == NULL)
6994 b->source_file = NULL;
6997 savestring (sals.sals[i].symtab->filename,
6998 strlen (sals.sals[i].symtab->filename));
6999 b->line_number = sals.sals[i].line;
7000 b->address = sals.sals[i].pc;
7002 /* Used to check for duplicates here, but that can
7003 cause trouble, as it doesn't check for disable
7008 /* Might be better to do this just once per breakpoint_re_set,
7009 rather than once for every breakpoint. */
7010 breakpoints_changed ();
7012 b->section = sals.sals[i].section;
7013 b->enable = save_enable; /* Restore it, this worked. */
7016 /* Now that this is re-enabled, check_duplicates
7018 check_duplicates (b);
7025 case bp_hardware_watchpoint:
7026 case bp_read_watchpoint:
7027 case bp_access_watchpoint:
7028 innermost_block = NULL;
7029 /* The issue arises of what context to evaluate this in. The
7030 same one as when it was set, but what does that mean when
7031 symbols have been re-read? We could save the filename and
7032 functionname, but if the context is more local than that, the
7033 best we could do would be something like how many levels deep
7034 and which index at that particular level, but that's going to
7035 be less stable than filenames or function names. */
7037 /* So for now, just use a global context. */
7040 b->exp = parse_expression (b->exp_string);
7041 b->exp_valid_block = innermost_block;
7042 mark = value_mark ();
7044 value_free (b->val);
7045 b->val = evaluate_expression (b->exp);
7046 release_value (b->val);
7047 if (VALUE_LAZY (b->val))
7048 value_fetch_lazy (b->val);
7050 if (b->cond_string != NULL)
7055 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7057 if (b->enable == enabled)
7059 value_free_to_mark (mark);
7061 case bp_catch_catch:
7062 case bp_catch_throw:
7064 /* We needn't really do anything to reset these, since the mask
7065 that requests them is unaffected by e.g., new libraries being
7068 case bp_catch_vfork:
7073 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7075 /* Delete longjmp breakpoints, they will be reset later by
7076 breakpoint_re_set. */
7078 case bp_longjmp_resume:
7079 delete_breakpoint (b);
7082 /* This breakpoint is special, it's set up when the inferior
7083 starts and we really don't want to touch it. */
7084 case bp_shlib_event:
7086 /* Like bp_shlib_event, this breakpoint type is special.
7087 Once it is set up, we do not want to touch it. */
7088 case bp_thread_event:
7090 /* Keep temporary breakpoints, which can be encountered when we step
7091 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7092 Otherwise these should have been blown away via the cleanup chain
7093 or by breakpoint_init_inferior when we rerun the executable. */
7096 case bp_watchpoint_scope:
7098 case bp_step_resume:
7105 /* Re-set all breakpoints after symbols have been re-loaded. */
7107 breakpoint_re_set (void)
7109 struct breakpoint *b, *temp;
7110 enum language save_language;
7111 int save_input_radix;
7112 static char message1[] = "Error in re-setting breakpoint %d:\n";
7113 char message[sizeof (message1) + 30 /* slop */ ];
7115 save_language = current_language->la_language;
7116 save_input_radix = input_radix;
7117 ALL_BREAKPOINTS_SAFE (b, temp)
7119 /* Format possible error msg */
7120 sprintf (message, message1, b->number);
7121 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7123 set_language (save_language);
7124 input_radix = save_input_radix;
7126 #ifdef GET_LONGJMP_TARGET
7127 create_longjmp_breakpoint ("longjmp");
7128 create_longjmp_breakpoint ("_longjmp");
7129 create_longjmp_breakpoint ("siglongjmp");
7130 create_longjmp_breakpoint ("_siglongjmp");
7131 create_longjmp_breakpoint (NULL);
7135 /* Took this out (temporarily at least), since it produces an extra
7136 blank line at startup. This messes up the gdbtests. -PB */
7137 /* Blank line to finish off all those mention() messages we just printed. */
7138 printf_filtered ("\n");
7142 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7143 If from_tty is nonzero, it prints a message to that effect,
7144 which ends with a period (no newline). */
7146 /* Reset the thread number of this breakpoint:
7148 - If the breakpoint is for all threads, leave it as-is.
7149 - Else, reset it to the current thread for inferior_ptid. */
7151 breakpoint_re_set_thread (struct breakpoint *b)
7153 if (b->thread != -1)
7155 if (in_thread_list (inferior_ptid))
7156 b->thread = pid_to_thread_id (inferior_ptid);
7161 set_ignore_count (int bptnum, int count, int from_tty)
7163 register struct breakpoint *b;
7169 if (b->number == bptnum)
7171 b->ignore_count = count;
7174 else if (count == 0)
7175 printf_filtered ("Will stop next time breakpoint %d is reached.",
7177 else if (count == 1)
7178 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7181 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7183 breakpoints_changed ();
7187 error ("No breakpoint number %d.", bptnum);
7190 /* Clear the ignore counts of all breakpoints. */
7192 breakpoint_clear_ignore_counts (void)
7194 struct breakpoint *b;
7197 b->ignore_count = 0;
7200 /* Command to set ignore-count of breakpoint N to COUNT. */
7203 ignore_command (char *args, int from_tty)
7209 error_no_arg ("a breakpoint number");
7211 num = get_number (&p);
7213 error ("bad breakpoint number: '%s'", args);
7215 error ("Second argument (specified ignore-count) is missing.");
7217 set_ignore_count (num,
7218 longest_to_int (value_as_long (parse_and_eval (p))),
7220 printf_filtered ("\n");
7221 breakpoints_changed ();
7224 /* Call FUNCTION on each of the breakpoints
7225 whose numbers are given in ARGS. */
7228 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7230 register char *p = args;
7233 register struct breakpoint *b, *tmp;
7237 error_no_arg ("one or more breakpoint numbers");
7244 num = get_number_or_range (&p1);
7247 warning ("bad breakpoint number at or near '%s'", p);
7251 ALL_BREAKPOINTS_SAFE (b, tmp)
7252 if (b->number == num)
7254 struct breakpoint *related_breakpoint = b->related_breakpoint;
7257 if (related_breakpoint)
7258 function (related_breakpoint);
7262 printf_unfiltered ("No breakpoint number %d.\n", num);
7269 disable_breakpoint (struct breakpoint *bpt)
7271 /* Never disable a watchpoint scope breakpoint; we want to
7272 hit them when we leave scope so we can delete both the
7273 watchpoint and its scope breakpoint at that time. */
7274 if (bpt->type == bp_watchpoint_scope)
7277 /* You can't disable permanent breakpoints. */
7278 if (bpt->enable == permanent)
7281 bpt->enable = disabled;
7283 check_duplicates (bpt);
7285 if (modify_breakpoint_hook)
7286 modify_breakpoint_hook (bpt);
7287 breakpoint_modify_event (bpt->number);
7292 disable_command (char *args, int from_tty)
7294 register struct breakpoint *bpt;
7296 ALL_BREAKPOINTS (bpt)
7300 warning ("attempted to disable apparently deleted breakpoint #%d?",
7305 case bp_catch_unload:
7307 case bp_catch_vfork:
7309 case bp_catch_catch:
7310 case bp_catch_throw:
7311 case bp_hardware_breakpoint:
7313 case bp_hardware_watchpoint:
7314 case bp_read_watchpoint:
7315 case bp_access_watchpoint:
7316 disable_breakpoint (bpt);
7321 map_breakpoint_numbers (args, disable_breakpoint);
7325 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7327 struct frame_info *save_selected_frame = NULL;
7328 int save_selected_frame_level = -1;
7329 int target_resources_ok, other_type_used;
7332 if (bpt->type == bp_hardware_breakpoint)
7335 i = hw_breakpoint_used_count ();
7336 target_resources_ok =
7337 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7339 if (target_resources_ok == 0)
7340 error ("No hardware breakpoint support in the target.");
7341 else if (target_resources_ok < 0)
7342 error ("Hardware breakpoints used exceeds limit.");
7345 if (bpt->enable != permanent)
7346 bpt->enable = enabled;
7347 bpt->disposition = disposition;
7348 check_duplicates (bpt);
7349 breakpoints_changed ();
7351 if (bpt->type == bp_watchpoint ||
7352 bpt->type == bp_hardware_watchpoint ||
7353 bpt->type == bp_read_watchpoint ||
7354 bpt->type == bp_access_watchpoint)
7356 if (bpt->exp_valid_block != NULL)
7358 struct frame_info *fr =
7360 /* Ensure that we have the current frame. Else, this
7361 next query may pessimistically be answered as, "No,
7362 not within current scope". */
7363 get_current_frame ();
7364 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7368 Cannot enable watchpoint %d because the block in which its expression\n\
7369 is valid is not currently in scope.\n", bpt->number);
7370 bpt->enable = disabled;
7374 save_selected_frame = selected_frame;
7375 save_selected_frame_level = selected_frame_level;
7376 select_frame (fr, -1);
7379 value_free (bpt->val);
7380 mark = value_mark ();
7381 bpt->val = evaluate_expression (bpt->exp);
7382 release_value (bpt->val);
7383 if (VALUE_LAZY (bpt->val))
7384 value_fetch_lazy (bpt->val);
7386 if (bpt->type == bp_hardware_watchpoint ||
7387 bpt->type == bp_read_watchpoint ||
7388 bpt->type == bp_access_watchpoint)
7390 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7391 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7393 /* Hack around 'unused var' error for some targets here */
7395 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7396 bpt->type, i + mem_cnt, other_type_used);
7397 /* we can consider of type is bp_hardware_watchpoint, convert to
7398 bp_watchpoint in the following condition */
7399 if (target_resources_ok < 0)
7402 Cannot enable watchpoint %d because target watch resources\n\
7403 have been allocated for other watchpoints.\n", bpt->number);
7404 bpt->enable = disabled;
7405 value_free_to_mark (mark);
7410 if (save_selected_frame_level >= 0)
7411 select_frame (save_selected_frame, save_selected_frame_level);
7412 value_free_to_mark (mark);
7414 if (modify_breakpoint_hook)
7415 modify_breakpoint_hook (bpt);
7416 breakpoint_modify_event (bpt->number);
7420 enable_breakpoint (struct breakpoint *bpt)
7422 do_enable_breakpoint (bpt, bpt->disposition);
7425 /* The enable command enables the specified breakpoints (or all defined
7426 breakpoints) so they once again become (or continue to be) effective
7427 in stopping the inferior. */
7431 enable_command (char *args, int from_tty)
7433 register struct breakpoint *bpt;
7435 ALL_BREAKPOINTS (bpt)
7439 warning ("attempted to enable apparently deleted breakpoint #%d?",
7444 case bp_catch_unload:
7446 case bp_catch_vfork:
7448 case bp_catch_catch:
7449 case bp_catch_throw:
7450 case bp_hardware_breakpoint:
7452 case bp_hardware_watchpoint:
7453 case bp_read_watchpoint:
7454 case bp_access_watchpoint:
7455 enable_breakpoint (bpt);
7460 map_breakpoint_numbers (args, enable_breakpoint);
7464 enable_once_breakpoint (struct breakpoint *bpt)
7466 do_enable_breakpoint (bpt, disable);
7471 enable_once_command (char *args, int from_tty)
7473 map_breakpoint_numbers (args, enable_once_breakpoint);
7477 enable_delete_breakpoint (struct breakpoint *bpt)
7479 do_enable_breakpoint (bpt, del);
7484 enable_delete_command (char *args, int from_tty)
7486 map_breakpoint_numbers (args, enable_delete_breakpoint);
7489 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7491 struct symtabs_and_lines
7492 decode_line_spec_1 (char *string, int funfirstline)
7494 struct symtabs_and_lines sals;
7496 error ("Empty line specification.");
7497 if (default_breakpoint_valid)
7498 sals = decode_line_1 (&string, funfirstline,
7499 default_breakpoint_symtab,
7500 default_breakpoint_line,
7503 sals = decode_line_1 (&string, funfirstline,
7504 (struct symtab *) NULL, 0, (char ***) NULL);
7506 error ("Junk at end of line specification: %s", string);
7511 _initialize_breakpoint (void)
7513 struct cmd_list_element *c;
7515 breakpoint_chain = 0;
7516 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7517 before a breakpoint is set. */
7518 breakpoint_count = 0;
7520 add_com ("ignore", class_breakpoint, ignore_command,
7521 "Set ignore-count of breakpoint number N to COUNT.\n\
7522 Usage is `ignore N COUNT'.");
7524 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7526 add_com ("commands", class_breakpoint, commands_command,
7527 "Set commands to be executed when a breakpoint is hit.\n\
7528 Give breakpoint number as argument after \"commands\".\n\
7529 With no argument, the targeted breakpoint is the last one set.\n\
7530 The commands themselves follow starting on the next line.\n\
7531 Type a line containing \"end\" to indicate the end of them.\n\
7532 Give \"silent\" as the first line to make the breakpoint silent;\n\
7533 then no output is printed when it is hit, except what the commands print.");
7535 add_com ("condition", class_breakpoint, condition_command,
7536 "Specify breakpoint number N to break only if COND is true.\n\
7537 Usage is `condition N COND', where N is an integer and COND is an\n\
7538 expression to be evaluated whenever breakpoint N is reached. ");
7540 add_com ("tbreak", class_breakpoint, tbreak_command,
7541 "Set a temporary breakpoint. Args like \"break\" command.\n\
7542 Like \"break\" except the breakpoint is only temporary,\n\
7543 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7544 by using \"enable delete\" on the breakpoint number.");
7545 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7546 "Set temporary breakpoint at procedure exit. Either there should\n\
7547 be no argument or the argument must be a depth.\n");
7549 add_com ("hbreak", class_breakpoint, hbreak_command,
7550 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7551 Like \"break\" except the breakpoint requires hardware support,\n\
7552 some target hardware may not have this support.");
7554 add_com ("thbreak", class_breakpoint, thbreak_command,
7555 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7556 Like \"hbreak\" except the breakpoint is only temporary,\n\
7557 so it will be deleted when hit.");
7559 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7560 "Enable some breakpoints.\n\
7561 Give breakpoint numbers (separated by spaces) as arguments.\n\
7562 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7563 This is used to cancel the effect of the \"disable\" command.\n\
7564 With a subcommand you can enable temporarily.",
7565 &enablelist, "enable ", 1, &cmdlist);
7567 add_com ("ab", class_breakpoint, enable_command,
7568 "Enable some breakpoints.\n\
7569 Give breakpoint numbers (separated by spaces) as arguments.\n\
7570 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7571 This is used to cancel the effect of the \"disable\" command.\n\
7572 With a subcommand you can enable temporarily.");
7574 add_com_alias ("en", "enable", class_breakpoint, 1);
7576 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7577 "Enable some breakpoints.\n\
7578 Give breakpoint numbers (separated by spaces) as arguments.\n\
7579 This is used to cancel the effect of the \"disable\" command.\n\
7580 May be abbreviated to simply \"enable\".\n",
7581 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7583 add_cmd ("once", no_class, enable_once_command,
7584 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7585 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7588 add_cmd ("delete", no_class, enable_delete_command,
7589 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7590 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7593 add_cmd ("delete", no_class, enable_delete_command,
7594 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7595 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7598 add_cmd ("once", no_class, enable_once_command,
7599 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7600 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7603 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7604 "Disable some breakpoints.\n\
7605 Arguments are breakpoint numbers with spaces in between.\n\
7606 To disable all breakpoints, give no argument.\n\
7607 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7608 &disablelist, "disable ", 1, &cmdlist);
7609 add_com_alias ("dis", "disable", class_breakpoint, 1);
7610 add_com_alias ("disa", "disable", class_breakpoint, 1);
7612 add_com ("sb", class_breakpoint, disable_command,
7613 "Disable some breakpoints.\n\
7614 Arguments are breakpoint numbers with spaces in between.\n\
7615 To disable all breakpoints, give no argument.\n\
7616 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7618 add_cmd ("breakpoints", class_alias, disable_command,
7619 "Disable some breakpoints.\n\
7620 Arguments are breakpoint numbers with spaces in between.\n\
7621 To disable all breakpoints, give no argument.\n\
7622 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7623 This command may be abbreviated \"disable\".",
7626 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7627 "Delete some breakpoints or auto-display expressions.\n\
7628 Arguments are breakpoint numbers with spaces in between.\n\
7629 To delete all breakpoints, give no argument.\n\
7631 Also a prefix command for deletion of other GDB objects.\n\
7632 The \"unset\" command is also an alias for \"delete\".",
7633 &deletelist, "delete ", 1, &cmdlist);
7634 add_com_alias ("d", "delete", class_breakpoint, 1);
7636 add_com ("db", class_breakpoint, delete_command,
7637 "Delete some breakpoints.\n\
7638 Arguments are breakpoint numbers with spaces in between.\n\
7639 To delete all breakpoints, give no argument.\n");
7641 add_cmd ("breakpoints", class_alias, delete_command,
7642 "Delete some breakpoints or auto-display expressions.\n\
7643 Arguments are breakpoint numbers with spaces in between.\n\
7644 To delete all breakpoints, give no argument.\n\
7645 This command may be abbreviated \"delete\".",
7648 add_com ("clear", class_breakpoint, clear_command,
7649 concat ("Clear breakpoint at specified line or function.\n\
7650 Argument may be line number, function name, or \"*\" and an address.\n\
7651 If line number is specified, all breakpoints in that line are cleared.\n\
7652 If function is specified, breakpoints at beginning of function are cleared.\n\
7653 If an address is specified, breakpoints at that address are cleared.\n\n",
7654 "With no argument, clears all breakpoints in the line that the selected frame\n\
7657 See also the \"delete\" command which clears breakpoints by number.", NULL));
7659 add_com ("break", class_breakpoint, break_command,
7660 concat ("Set breakpoint at specified line or function.\n\
7661 Argument may be line number, function name, or \"*\" and an address.\n\
7662 If line number is specified, break at start of code for that line.\n\
7663 If function is specified, break at start of code for that function.\n\
7664 If an address is specified, break at 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 ("b", "break", class_run, 1);
7672 add_com_alias ("br", "break", class_run, 1);
7673 add_com_alias ("bre", "break", class_run, 1);
7674 add_com_alias ("brea", "break", class_run, 1);
7676 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7677 concat ("Set breakpoint at procedure exit. \n\
7678 Argument may be function name, or \"*\" and an address.\n\
7679 If function is specified, break at end of code for that function.\n\
7680 If an address is specified, break at the end of the function that contains \n\
7681 that exact address.\n",
7682 "With no arg, uses current execution address of selected stack frame.\n\
7683 This is useful for breaking on return to a stack frame.\n\
7685 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7687 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7688 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7689 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7690 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7691 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7695 add_com_alias ("ba", "break", class_breakpoint, 1);
7696 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7697 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7698 "Set breakpoint at procedure exit. Either there should\n\
7699 be no argument or the argument must be a depth.\n");
7704 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7705 "Break in function/address or break at a line in the current file.",
7706 &stoplist, "stop ", 1, &cmdlist);
7707 add_cmd ("in", class_breakpoint, stopin_command,
7708 "Break in function or address.\n", &stoplist);
7709 add_cmd ("at", class_breakpoint, stopat_command,
7710 "Break at a line in the current file.\n", &stoplist);
7711 add_com ("status", class_info, breakpoints_info,
7712 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7713 The \"Type\" column indicates one of:\n\
7714 \tbreakpoint - normal breakpoint\n\
7715 \twatchpoint - watchpoint\n\
7716 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7717 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7718 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7719 address and file/line number respectively.\n\n",
7720 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7721 are set to the address of the last breakpoint listed.\n\n\
7722 Convenience variable \"$bpnum\" contains the number of the last\n\
7723 breakpoint set.", NULL));
7726 add_info ("breakpoints", breakpoints_info,
7727 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7728 The \"Type\" column indicates one of:\n\
7729 \tbreakpoint - normal breakpoint\n\
7730 \twatchpoint - watchpoint\n\
7731 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7732 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7733 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7734 address and file/line number respectively.\n\n",
7735 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7736 are set to the address of the last breakpoint listed.\n\n\
7737 Convenience variable \"$bpnum\" contains the number of the last\n\
7738 breakpoint set.", NULL));
7741 add_com ("lb", class_breakpoint, breakpoints_info,
7742 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7743 The \"Type\" column indicates one of:\n\
7744 \tbreakpoint - normal breakpoint\n\
7745 \twatchpoint - watchpoint\n\
7746 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7747 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7748 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7749 address and file/line number respectively.\n\n",
7750 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7751 are set to the address of the last breakpoint listed.\n\n\
7752 Convenience variable \"$bpnum\" contains the number of the last\n\
7753 breakpoint set.", NULL));
7755 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7756 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7757 The \"Type\" column indicates one of:\n\
7758 \tbreakpoint - normal breakpoint\n\
7759 \twatchpoint - watchpoint\n\
7760 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7761 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7762 \tuntil - internal breakpoint used by the \"until\" command\n\
7763 \tfinish - internal breakpoint used by the \"finish\" command\n",
7764 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7765 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7766 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7767 address and file/line number respectively.\n\n",
7768 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7769 are set to the address of the last breakpoint listed.\n\n\
7770 Convenience variable \"$bpnum\" contains the number of the last\n\
7771 breakpoint set.", NULL),
7772 &maintenanceinfolist);
7774 add_com ("catch", class_breakpoint, catch_command,
7775 "Set catchpoints to catch events.\n\
7776 Raised signals may be caught:\n\
7777 \tcatch signal - all signals\n\
7778 \tcatch signal <signame> - a particular signal\n\
7779 Raised exceptions may be caught:\n\
7780 \tcatch throw - all exceptions, when thrown\n\
7781 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7782 \tcatch catch - all exceptions, when caught\n\
7783 \tcatch catch <exceptname> - a particular exception, when caught\n\
7784 Thread or process events may be caught:\n\
7785 \tcatch thread_start - any threads, just after creation\n\
7786 \tcatch thread_exit - any threads, just before expiration\n\
7787 \tcatch thread_join - any threads, just after joins\n\
7788 Process events may be caught:\n\
7789 \tcatch start - any processes, just after creation\n\
7790 \tcatch exit - any processes, just before expiration\n\
7791 \tcatch fork - calls to fork()\n\
7792 \tcatch vfork - calls to vfork()\n\
7793 \tcatch exec - calls to exec()\n\
7794 Dynamically-linked library events may be caught:\n\
7795 \tcatch load - loads of any library\n\
7796 \tcatch load <libname> - loads of a particular library\n\
7797 \tcatch unload - unloads of any library\n\
7798 \tcatch unload <libname> - unloads of a particular library\n\
7799 The act of your program's execution stopping may also be caught:\n\
7801 C++ exceptions may be caught:\n\
7802 \tcatch throw - all exceptions, when thrown\n\
7803 \tcatch catch - all exceptions, when caught\n\
7805 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7806 after a fork or vfork is caught.\n\n\
7807 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7809 add_com ("tcatch", class_breakpoint, tcatch_command,
7810 "Set temporary catchpoints to catch events.\n\
7811 Args like \"catch\" command.\n\
7812 Like \"catch\" except the catchpoint is only temporary,\n\
7813 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7814 by using \"enable delete\" on the catchpoint number.");
7816 add_com ("watch", class_breakpoint, watch_command,
7817 "Set a watchpoint for an expression.\n\
7818 A watchpoint stops execution of your program whenever the value of\n\
7819 an expression changes.");
7821 add_com ("rwatch", class_breakpoint, rwatch_command,
7822 "Set a read watchpoint for an expression.\n\
7823 A watchpoint stops execution of your program whenever the value of\n\
7824 an expression is read.");
7826 add_com ("awatch", class_breakpoint, awatch_command,
7827 "Set a watchpoint for an expression.\n\
7828 A watchpoint stops execution of your program whenever the value of\n\
7829 an expression is either read or written.");
7831 add_info ("watchpoints", breakpoints_info,
7832 "Synonym for ``info breakpoints''.");
7835 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7836 (char *) &can_use_hw_watchpoints,
7837 "Set debugger's willingness to use watchpoint hardware.\n\
7838 If zero, gdb will not use hardware for new watchpoints, even if\n\
7839 such is available. (However, any hardware watchpoints that were\n\
7840 created before setting this to nonzero, will continue to use watchpoint\n\
7843 add_show_from_set (c, &showlist);
7845 can_use_hw_watchpoints = 1;