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, enum bptype);
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 struct cleanup *old_chain = save_inferior_ptid ();
1066 /* Set inferior_ptid; remove_breakpoint uses this global. */
1067 inferior_ptid = pid_to_ptid (pid);
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 do_cleanups (old_chain);
1084 do_cleanups (old_chain);
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.
1149 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1150 valid code address on some platforms (like the mn10200 and
1151 mn10300 simulators). We shouldn't assign any special
1152 interpretation to a breakpoint with a zero address. And in
1153 fact, GDB doesn't --- I can't see what that comment above is
1154 talking about. As far as I can tell, setting the address of a
1155 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1156 is meaningless, since those are implemented with HP-UX kernel
1157 hackery, not by storing breakpoint instructions somewhere. */
1158 if ((b->type == bp_catch_exec) ||
1159 (b->type == bp_catch_vfork) ||
1160 (b->type == bp_catch_fork))
1162 b->address = (CORE_ADDR) NULL;
1166 /* bp_finish is a special case. The only way we ought to be able
1167 to see one of these when an exec() has happened, is if the user
1168 caught a vfork, and then said "finish". Ordinarily a finish just
1169 carries them to the call-site of the current callee, by setting
1170 a temporary bp there and resuming. But in this case, the finish
1171 will carry them entirely through the vfork & exec.
1173 We don't want to allow a bp_finish to remain inserted now. But
1174 we can't safely delete it, 'cause finish_command has a handle to
1175 the bp on a bpstat, and will later want to delete it. There's a
1176 chance (and I've seen it happen) that if we delete the bp_finish
1177 here, that its storage will get reused by the time finish_command
1178 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1179 We really must allow finish_command to delete a bp_finish.
1181 In the absense of a general solution for the "how do we know
1182 it's safe to delete something others may have handles to?"
1183 problem, what we'll do here is just uninsert the bp_finish, and
1184 let finish_command delete it.
1186 (We know the bp_finish is "doomed" in the sense that it's
1187 momentary, and will be deleted as soon as finish_command sees
1188 the inferior stopped. So it doesn't matter that the bp's
1189 address is probably bogus in the new a.out, unlike e.g., the
1190 solib breakpoints.) */
1192 if (b->type == bp_finish)
1197 /* Without a symbolic address, we have little hope of the
1198 pre-exec() address meaning the same thing in the post-exec()
1200 if (b->addr_string == NULL)
1202 delete_breakpoint (b);
1206 /* If this breakpoint has survived the above battery of checks, then
1207 it must have a symbolic address. Be sure that it gets reevaluated
1208 to a target address, rather than reusing the old evaluation.
1210 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1211 for bp_catch_exec and friends, I'm pretty sure this is entirely
1212 unnecessary. A call to breakpoint_re_set_one always recomputes
1213 the breakpoint's address from scratch, or deletes it if it can't.
1214 So I think this assignment could be deleted without effect. */
1215 b->address = (CORE_ADDR) NULL;
1220 detach_breakpoints (int pid)
1222 register struct breakpoint *b;
1224 struct cleanup *old_chain = save_inferior_ptid ();
1226 if (pid == PIDGET (inferior_ptid))
1227 error ("Cannot detach breakpoints of inferior_ptid");
1229 /* Set inferior_ptid; remove_breakpoint uses this global. */
1230 inferior_ptid = pid_to_ptid (pid);
1235 val = remove_breakpoint (b, mark_inserted);
1238 do_cleanups (old_chain);
1243 do_cleanups (old_chain);
1248 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1252 if (b->enable == permanent)
1253 /* Permanent breakpoints cannot be inserted or removed. */
1256 if (b->type == bp_none)
1257 warning ("attempted to remove apparently deleted breakpoint #%d?",
1260 if (b->type != bp_watchpoint
1261 && b->type != bp_hardware_watchpoint
1262 && b->type != bp_read_watchpoint
1263 && b->type != bp_access_watchpoint
1264 && b->type != bp_catch_fork
1265 && b->type != bp_catch_vfork
1266 && b->type != bp_catch_exec
1267 && b->type != bp_catch_catch
1268 && b->type != bp_catch_throw)
1270 if (b->type == bp_hardware_breakpoint)
1271 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1274 /* Check to see if breakpoint is in an overlay section;
1275 if so, we should remove the breakpoint at the LMA address.
1276 If that is not equal to the raw address, then we should
1277 presumably remove the breakpoint there as well. */
1278 if (overlay_debugging && b->section &&
1279 section_is_overlay (b->section))
1283 addr = overlay_unmapped_address (b->address, b->section);
1284 val = target_remove_breakpoint (addr, b->shadow_contents);
1285 /* This would be the time to check val, to see if the
1286 shadow breakpoint write to the load address succeeded.
1287 However, this might be an ordinary occurrance, eg. if
1288 the unmapped overlay is in ROM. */
1289 val = 0; /* in case unmapped address failed */
1290 if (section_is_mapped (b->section))
1291 val = target_remove_breakpoint (b->address,
1292 b->shadow_contents);
1294 else /* ordinary (non-overlay) address */
1295 val = target_remove_breakpoint (b->address, b->shadow_contents);
1299 b->inserted = (is == mark_inserted);
1301 else if ((b->type == bp_hardware_watchpoint ||
1302 b->type == bp_read_watchpoint ||
1303 b->type == bp_access_watchpoint)
1304 && b->enable == enabled
1309 b->inserted = (is == mark_inserted);
1310 /* Walk down the saved value chain. */
1311 for (v = b->val_chain; v; v = v->next)
1313 /* For each memory reference remove the watchpoint
1315 if (VALUE_LVAL (v) == lval_memory
1316 && ! VALUE_LAZY (v))
1318 struct type *vtype = check_typedef (VALUE_TYPE (v));
1320 if (v == b->val_chain
1321 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1322 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1327 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1328 len = TYPE_LENGTH (VALUE_TYPE (v));
1330 if (b->type == bp_read_watchpoint)
1332 else if (b->type == bp_access_watchpoint)
1335 val = target_remove_watchpoint (addr, len, type);
1342 /* Failure to remove any of the hardware watchpoints comes here. */
1343 if ((is == mark_uninserted) && (b->inserted))
1344 warning ("Could not remove hardware watchpoint %d.",
1347 /* Free the saved value chain. We will construct a new one
1348 the next time the watchpoint is inserted. */
1349 for (v = b->val_chain; v; v = n)
1354 b->val_chain = NULL;
1356 else if ((b->type == bp_catch_fork ||
1357 b->type == bp_catch_vfork ||
1358 b->type == bp_catch_exec)
1359 && b->enable == enabled
1366 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1368 case bp_catch_vfork:
1369 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1372 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1375 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1380 b->inserted = (is == mark_inserted);
1382 else if ((b->type == bp_catch_catch ||
1383 b->type == bp_catch_throw)
1384 && b->enable == enabled
1388 val = target_remove_breakpoint (b->address, b->shadow_contents);
1391 b->inserted = (is == mark_inserted);
1393 else if (ep_is_exception_catchpoint (b)
1394 && b->inserted /* sometimes previous insert doesn't happen */
1395 && b->enable == enabled
1399 val = target_remove_breakpoint (b->address, b->shadow_contents);
1403 b->inserted = (is == mark_inserted);
1409 /* Clear the "inserted" flag in all breakpoints. */
1412 mark_breakpoints_out (void)
1414 register struct breakpoint *b;
1420 /* Clear the "inserted" flag in all breakpoints and delete any
1421 breakpoints which should go away between runs of the program.
1423 Plus other such housekeeping that has to be done for breakpoints
1426 Note: this function gets called at the end of a run (by
1427 generic_mourn_inferior) and when a run begins (by
1428 init_wait_for_inferior). */
1433 breakpoint_init_inferior (enum inf_context context)
1435 register struct breakpoint *b, *temp;
1436 static int warning_needed = 0;
1438 ALL_BREAKPOINTS_SAFE (b, temp)
1445 case bp_watchpoint_scope:
1447 /* If the call dummy breakpoint is at the entry point it will
1448 cause problems when the inferior is rerun, so we better
1451 Also get rid of scope breakpoints. */
1452 delete_breakpoint (b);
1456 case bp_hardware_watchpoint:
1457 case bp_read_watchpoint:
1458 case bp_access_watchpoint:
1460 /* Likewise for watchpoints on local expressions. */
1461 if (b->exp_valid_block != NULL)
1462 delete_breakpoint (b);
1465 /* Likewise for exception catchpoints in dynamic-linked
1466 executables where required */
1467 if (ep_is_exception_catchpoint (b) &&
1468 exception_catchpoints_are_fragile)
1471 delete_breakpoint (b);
1477 if (exception_catchpoints_are_fragile)
1478 exception_support_initialized = 0;
1480 /* Don't issue the warning unless it's really needed... */
1481 if (warning_needed && (context != inf_exited))
1483 warning ("Exception catchpoints from last run were deleted.");
1484 warning ("You must reinsert them explicitly.");
1489 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1490 exists at PC. It returns ordinary_breakpoint_here if it's an
1491 ordinary breakpoint, or permanent_breakpoint_here if it's a
1492 permanent breakpoint.
1493 - When continuing from a location with an ordinary breakpoint, we
1494 actually single step once before calling insert_breakpoints.
1495 - When continuing from a localion with a permanent breakpoint, we
1496 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1497 the target, to advance the PC past the breakpoint. */
1499 enum breakpoint_here
1500 breakpoint_here_p (CORE_ADDR pc)
1502 register struct breakpoint *b;
1503 int any_breakpoint_here = 0;
1506 if ((b->enable == enabled
1507 || b->enable == permanent)
1508 && b->address == pc) /* bp is enabled and matches pc */
1510 if (overlay_debugging &&
1511 section_is_overlay (b->section) &&
1512 !section_is_mapped (b->section))
1513 continue; /* unmapped overlay -- can't be a match */
1514 else if (b->enable == permanent)
1515 return permanent_breakpoint_here;
1517 any_breakpoint_here = 1;
1520 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1524 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1525 but it only returns true if there is actually a breakpoint inserted
1529 breakpoint_inserted_here_p (CORE_ADDR pc)
1531 register struct breakpoint *b;
1535 && b->address == pc) /* bp is inserted and matches pc */
1537 if (overlay_debugging &&
1538 section_is_overlay (b->section) &&
1539 !section_is_mapped (b->section))
1540 continue; /* unmapped overlay -- can't be a match */
1548 /* Return nonzero if FRAME is a dummy frame. We can't use
1549 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1550 much time, at least using get_saved_register on the 68k. This
1551 means that for this function to work right a port must use the
1552 bp_call_dummy breakpoint. */
1555 frame_in_dummy (struct frame_info *frame)
1557 struct breakpoint *b;
1562 if (USE_GENERIC_DUMMY_FRAMES)
1563 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1567 if (b->type == bp_call_dummy
1568 && b->frame == frame->frame
1569 /* We need to check the PC as well as the frame on the sparc,
1570 for signals.exp in the testsuite. */
1573 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1574 && frame->pc <= b->address)
1580 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1581 PC is valid for process/thread PID. */
1584 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1586 struct breakpoint *b;
1589 thread = pid_to_thread_id (ptid);
1592 if (b->enable != disabled
1593 && b->enable != shlib_disabled
1594 && b->enable != call_disabled
1596 && (b->thread == -1 || b->thread == thread))
1598 if (overlay_debugging &&
1599 section_is_overlay (b->section) &&
1600 !section_is_mapped (b->section))
1601 continue; /* unmapped overlay -- can't be a match */
1610 /* bpstat stuff. External routines' interfaces are documented
1614 ep_is_catchpoint (struct breakpoint *ep)
1617 (ep->type == bp_catch_load)
1618 || (ep->type == bp_catch_unload)
1619 || (ep->type == bp_catch_fork)
1620 || (ep->type == bp_catch_vfork)
1621 || (ep->type == bp_catch_exec)
1622 || (ep->type == bp_catch_catch)
1623 || (ep->type == bp_catch_throw);
1625 /* ??rehrauer: Add more kinds here, as are implemented... */
1629 ep_is_shlib_catchpoint (struct breakpoint *ep)
1632 (ep->type == bp_catch_load)
1633 || (ep->type == bp_catch_unload);
1637 ep_is_exception_catchpoint (struct breakpoint *ep)
1640 (ep->type == bp_catch_catch)
1641 || (ep->type == bp_catch_throw);
1644 /* Clear a bpstat so that it says we are not at any breakpoint.
1645 Also free any storage that is part of a bpstat. */
1648 bpstat_clear (bpstat *bsp)
1659 if (p->old_val != NULL)
1660 value_free (p->old_val);
1667 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1668 is part of the bpstat is copied as well. */
1671 bpstat_copy (bpstat bs)
1675 bpstat retval = NULL;
1680 for (; bs != NULL; bs = bs->next)
1682 tmp = (bpstat) xmalloc (sizeof (*tmp));
1683 memcpy (tmp, bs, sizeof (*tmp));
1685 /* This is the first thing in the chain. */
1695 /* Find the bpstat associated with this breakpoint */
1698 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1703 for (; bsp != NULL; bsp = bsp->next)
1705 if (bsp->breakpoint_at == breakpoint)
1711 /* Find a step_resume breakpoint associated with this bpstat.
1712 (If there are multiple step_resume bp's on the list, this function
1713 will arbitrarily pick one.)
1715 It is an error to use this function if BPSTAT doesn't contain a
1716 step_resume breakpoint.
1718 See wait_for_inferior's use of this function. */
1720 bpstat_find_step_resume_breakpoint (bpstat bsp)
1723 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1725 for (; bsp != NULL; bsp = bsp->next)
1727 if ((bsp->breakpoint_at != NULL) &&
1728 (bsp->breakpoint_at->type == bp_step_resume))
1729 return bsp->breakpoint_at;
1732 error ("Internal error (no step_resume breakpoint found)");
1736 /* Return the breakpoint number of the first breakpoint we are stopped
1737 at. *BSP upon return is a bpstat which points to the remaining
1738 breakpoints stopped at (but which is not guaranteed to be good for
1739 anything but further calls to bpstat_num).
1740 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1743 bpstat_num (bpstat *bsp)
1745 struct breakpoint *b;
1748 return 0; /* No more breakpoint values */
1751 b = (*bsp)->breakpoint_at;
1752 *bsp = (*bsp)->next;
1754 return -1; /* breakpoint that's been deleted since */
1756 return b->number; /* We have its number */
1760 /* Modify BS so that the actions will not be performed. */
1763 bpstat_clear_actions (bpstat bs)
1765 for (; bs != NULL; bs = bs->next)
1767 bs->commands = NULL;
1768 if (bs->old_val != NULL)
1770 value_free (bs->old_val);
1776 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1779 cleanup_executing_breakpoints (PTR ignore)
1781 executing_breakpoint_commands = 0;
1784 /* Execute all the commands associated with all the breakpoints at this
1785 location. Any of these commands could cause the process to proceed
1786 beyond this point, etc. We look out for such changes by checking
1787 the global "breakpoint_proceeded" after each command. */
1790 bpstat_do_actions (bpstat *bsp)
1793 struct cleanup *old_chain;
1794 struct command_line *cmd;
1796 /* Avoid endless recursion if a `source' command is contained
1798 if (executing_breakpoint_commands)
1801 executing_breakpoint_commands = 1;
1802 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1805 /* Note that (as of this writing), our callers all appear to
1806 be passing us the address of global stop_bpstat. And, if
1807 our calls to execute_control_command cause the inferior to
1808 proceed, that global (and hence, *bsp) will change.
1810 We must be careful to not touch *bsp unless the inferior
1811 has not proceeded. */
1813 /* This pointer will iterate over the list of bpstat's. */
1816 breakpoint_proceeded = 0;
1817 for (; bs != NULL; bs = bs->next)
1822 execute_control_command (cmd);
1824 if (breakpoint_proceeded)
1829 if (breakpoint_proceeded)
1830 /* The inferior is proceeded by the command; bomb out now.
1831 The bpstat chain has been blown away by wait_for_inferior.
1832 But since execution has stopped again, there is a new bpstat
1833 to look at, so start over. */
1836 bs->commands = NULL;
1839 executing_breakpoint_commands = 0;
1840 discard_cleanups (old_chain);
1843 /* This is the normal print function for a bpstat. In the future,
1844 much of this logic could (should?) be moved to bpstat_stop_status,
1845 by having it set different print_it values.
1847 Current scheme: When we stop, bpstat_print() is called. It loops
1848 through the bpstat list of things causing this stop, calling the
1849 print_bp_stop_message function on each one. The behavior of the
1850 print_bp_stop_message function depends on the print_it field of
1851 bpstat. If such field so indicates, call this function here.
1853 Return values from this routine (ultimately used by bpstat_print()
1854 and normal_stop() to decide what to do):
1855 PRINT_NOTHING: Means we already printed all we needed to print,
1856 don't print anything else.
1857 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1858 that something to be followed by a location.
1859 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1860 that something to be followed by a location.
1861 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1864 static enum print_stop_action
1865 print_it_typical (bpstat bs)
1868 struct cleanup *old_chain;
1869 struct ui_stream *stb;
1870 stb = ui_out_stream_new (uiout);
1871 old_chain = make_cleanup_ui_out_stream_delete (stb);
1873 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1874 which has since been deleted. */
1875 if (bs->breakpoint_at == NULL)
1876 return PRINT_UNKNOWN;
1878 switch (bs->breakpoint_at->type)
1881 case bp_hardware_breakpoint:
1883 annotate_breakpoint (bs->breakpoint_at->number);
1884 ui_out_text (uiout, "\nBreakpoint ");
1885 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
1886 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1887 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1888 ui_out_text (uiout, ", ");
1889 return PRINT_SRC_AND_LOC;
1891 /* I think the user probably only wants to see one breakpoint
1892 number, not all of them. */
1893 annotate_breakpoint (bs->breakpoint_at->number);
1894 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1895 return PRINT_SRC_AND_LOC;
1899 case bp_shlib_event:
1900 /* Did we stop because the user set the stop_on_solib_events
1901 variable? (If so, we report this as a generic, "Stopped due
1902 to shlib event" message.) */
1903 printf_filtered ("Stopped due to shared library event\n");
1904 return PRINT_NOTHING;
1907 case bp_thread_event:
1908 /* Not sure how we will get here.
1909 GDB should not stop for these breakpoints. */
1910 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1911 return PRINT_NOTHING;
1915 annotate_catchpoint (bs->breakpoint_at->number);
1916 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1917 printf_filtered ("loaded");
1918 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1919 return PRINT_SRC_AND_LOC;
1922 case bp_catch_unload:
1923 annotate_catchpoint (bs->breakpoint_at->number);
1924 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1925 printf_filtered ("unloaded");
1926 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1927 return PRINT_SRC_AND_LOC;
1931 annotate_catchpoint (bs->breakpoint_at->number);
1932 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1933 printf_filtered ("forked");
1934 printf_filtered (" process %d), ",
1935 bs->breakpoint_at->forked_inferior_pid);
1936 return PRINT_SRC_AND_LOC;
1939 case bp_catch_vfork:
1940 annotate_catchpoint (bs->breakpoint_at->number);
1941 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1942 printf_filtered ("vforked");
1943 printf_filtered (" process %d), ",
1944 bs->breakpoint_at->forked_inferior_pid);
1945 return PRINT_SRC_AND_LOC;
1949 annotate_catchpoint (bs->breakpoint_at->number);
1950 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1951 bs->breakpoint_at->number,
1952 bs->breakpoint_at->exec_pathname);
1953 return PRINT_SRC_AND_LOC;
1956 case bp_catch_catch:
1957 if (current_exception_event &&
1958 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1960 annotate_catchpoint (bs->breakpoint_at->number);
1961 printf_filtered ("\nCatchpoint %d (exception caught), ",
1962 bs->breakpoint_at->number);
1963 printf_filtered ("throw location ");
1964 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1965 printf_filtered ("%s:%d",
1966 CURRENT_EXCEPTION_THROW_FILE,
1967 CURRENT_EXCEPTION_THROW_LINE);
1969 printf_filtered ("unknown");
1971 printf_filtered (", catch location ");
1972 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
1973 printf_filtered ("%s:%d",
1974 CURRENT_EXCEPTION_CATCH_FILE,
1975 CURRENT_EXCEPTION_CATCH_LINE);
1977 printf_filtered ("unknown");
1979 printf_filtered ("\n");
1980 /* don't bother to print location frame info */
1981 return PRINT_SRC_ONLY;
1985 /* really throw, some other bpstat will handle it */
1986 return PRINT_UNKNOWN;
1990 case bp_catch_throw:
1991 if (current_exception_event &&
1992 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
1994 annotate_catchpoint (bs->breakpoint_at->number);
1995 printf_filtered ("\nCatchpoint %d (exception thrown), ",
1996 bs->breakpoint_at->number);
1997 printf_filtered ("throw location ");
1998 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1999 printf_filtered ("%s:%d",
2000 CURRENT_EXCEPTION_THROW_FILE,
2001 CURRENT_EXCEPTION_THROW_LINE);
2003 printf_filtered ("unknown");
2005 printf_filtered (", catch location ");
2006 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2007 printf_filtered ("%s:%d",
2008 CURRENT_EXCEPTION_CATCH_FILE,
2009 CURRENT_EXCEPTION_CATCH_LINE);
2011 printf_filtered ("unknown");
2013 printf_filtered ("\n");
2014 /* don't bother to print location frame info */
2015 return PRINT_SRC_ONLY;
2019 /* really catch, some other bpstat will handle it */
2020 return PRINT_UNKNOWN;
2025 case bp_hardware_watchpoint:
2026 if (bs->old_val != NULL)
2028 annotate_watchpoint (bs->breakpoint_at->number);
2030 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2031 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2032 mention (bs->breakpoint_at);
2033 ui_out_tuple_begin (uiout, "value");
2034 ui_out_text (uiout, "\nOld value = ");
2035 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2036 ui_out_field_stream (uiout, "old", stb);
2037 ui_out_text (uiout, "\nNew value = ");
2038 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2039 ui_out_field_stream (uiout, "new", stb);
2040 ui_out_tuple_end (uiout);
2041 ui_out_text (uiout, "\n");
2043 mention (bs->breakpoint_at);
2044 printf_filtered ("\nOld value = ");
2045 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2046 printf_filtered ("\nNew value = ");
2047 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2048 Val_pretty_default);
2049 printf_filtered ("\n");
2051 value_free (bs->old_val);
2054 /* More than one watchpoint may have been triggered. */
2055 return PRINT_UNKNOWN;
2058 case bp_read_watchpoint:
2060 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2061 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2062 mention (bs->breakpoint_at);
2063 ui_out_tuple_begin (uiout, "value");
2064 ui_out_text (uiout, "\nValue = ");
2065 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2066 ui_out_field_stream (uiout, "value", stb);
2067 ui_out_tuple_end (uiout);
2068 ui_out_text (uiout, "\n");
2070 mention (bs->breakpoint_at);
2071 printf_filtered ("\nValue = ");
2072 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2073 Val_pretty_default);
2074 printf_filtered ("\n");
2076 return PRINT_UNKNOWN;
2079 case bp_access_watchpoint:
2081 if (bs->old_val != NULL)
2083 annotate_watchpoint (bs->breakpoint_at->number);
2084 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2085 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2086 mention (bs->breakpoint_at);
2087 ui_out_tuple_begin (uiout, "value");
2088 ui_out_text (uiout, "\nOld value = ");
2089 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2090 ui_out_field_stream (uiout, "old", stb);
2091 value_free (bs->old_val);
2093 ui_out_text (uiout, "\nNew value = ");
2097 mention (bs->breakpoint_at);
2098 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2099 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2100 ui_out_tuple_begin (uiout, "value");
2101 ui_out_text (uiout, "\nValue = ");
2103 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2104 ui_out_field_stream (uiout, "new", stb);
2105 ui_out_tuple_end (uiout);
2106 ui_out_text (uiout, "\n");
2108 if (bs->old_val != NULL)
2110 annotate_watchpoint (bs->breakpoint_at->number);
2111 mention (bs->breakpoint_at);
2112 printf_filtered ("\nOld value = ");
2113 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2114 value_free (bs->old_val);
2116 printf_filtered ("\nNew value = ");
2120 mention (bs->breakpoint_at);
2121 printf_filtered ("\nValue = ");
2123 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2124 Val_pretty_default);
2125 printf_filtered ("\n");
2127 return PRINT_UNKNOWN;
2130 /* Fall through, we don't deal with these types of breakpoints
2135 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2136 ui_out_field_string (uiout, "reason", "function-finished");
2138 return PRINT_UNKNOWN;
2143 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2144 ui_out_field_string (uiout, "reason", "location-reached");
2146 return PRINT_UNKNOWN;
2151 case bp_longjmp_resume:
2152 case bp_step_resume:
2153 case bp_through_sigtramp:
2154 case bp_watchpoint_scope:
2157 return PRINT_UNKNOWN;
2161 /* Generic routine for printing messages indicating why we
2162 stopped. The behavior of this function depends on the value
2163 'print_it' in the bpstat structure. Under some circumstances we
2164 may decide not to print anything here and delegate the task to
2167 static enum print_stop_action
2168 print_bp_stop_message (bpstat bs)
2170 switch (bs->print_it)
2173 /* Nothing should be printed for this bpstat entry. */
2174 return PRINT_UNKNOWN;
2178 /* We still want to print the frame, but we already printed the
2179 relevant messages. */
2180 return PRINT_SRC_AND_LOC;
2183 case print_it_normal:
2184 /* Normal case, we handle everything in print_it_typical. */
2185 return print_it_typical (bs);
2188 internal_error (__FILE__, __LINE__,
2189 "print_bp_stop_message: unrecognized enum value");
2194 /* Print a message indicating what happened. This is called from
2195 normal_stop(). The input to this routine is the head of the bpstat
2196 list - a list of the eventpoints that caused this stop. This
2197 routine calls the generic print routine for printing a message
2198 about reasons for stopping. This will print (for example) the
2199 "Breakpoint n," part of the output. The return value of this
2202 PRINT_UNKNOWN: Means we printed nothing
2203 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2204 code to print the location. An example is
2205 "Breakpoint 1, " which should be followed by
2207 PRINT_SRC_ONLY: Means we printed something, but there is no need
2208 to also print the location part of the message.
2209 An example is the catch/throw messages, which
2210 don't require a location appended to the end.
2211 PRINT_NOTHING: We have done some printing and we don't need any
2212 further info to be printed.*/
2214 enum print_stop_action
2215 bpstat_print (bpstat bs)
2219 /* Maybe another breakpoint in the chain caused us to stop.
2220 (Currently all watchpoints go on the bpstat whether hit or not.
2221 That probably could (should) be changed, provided care is taken
2222 with respect to bpstat_explains_signal). */
2223 for (; bs; bs = bs->next)
2225 val = print_bp_stop_message (bs);
2226 if (val == PRINT_SRC_ONLY
2227 || val == PRINT_SRC_AND_LOC
2228 || val == PRINT_NOTHING)
2232 /* We reached the end of the chain, or we got a null BS to start
2233 with and nothing was printed. */
2234 return PRINT_UNKNOWN;
2237 /* Evaluate the expression EXP and return 1 if value is zero.
2238 This is used inside a catch_errors to evaluate the breakpoint condition.
2239 The argument is a "struct expression *" that has been cast to char * to
2240 make it pass through catch_errors. */
2243 breakpoint_cond_eval (PTR exp)
2245 value_ptr mark = value_mark ();
2246 int i = !value_true (evaluate_expression ((struct expression *) exp));
2247 value_free_to_mark (mark);
2251 /* Allocate a new bpstat and chain it to the current one. */
2254 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2258 bs = (bpstat) xmalloc (sizeof (*bs));
2260 bs->breakpoint_at = b;
2261 /* If the condition is false, etc., don't do the commands. */
2262 bs->commands = NULL;
2264 bs->print_it = print_it_normal;
2268 /* Possible return values for watchpoint_check (this can't be an enum
2269 because of check_errors). */
2270 /* The watchpoint has been deleted. */
2271 #define WP_DELETED 1
2272 /* The value has changed. */
2273 #define WP_VALUE_CHANGED 2
2274 /* The value has not changed. */
2275 #define WP_VALUE_NOT_CHANGED 3
2277 #define BP_TEMPFLAG 1
2278 #define BP_HARDWAREFLAG 2
2280 /* Check watchpoint condition. */
2283 watchpoint_check (PTR p)
2285 bpstat bs = (bpstat) p;
2286 struct breakpoint *b;
2287 struct frame_info *fr;
2288 int within_current_scope;
2290 b = bs->breakpoint_at;
2292 if (b->exp_valid_block == NULL)
2293 within_current_scope = 1;
2296 /* There is no current frame at this moment. If we're going to have
2297 any chance of handling watchpoints on local variables, we'll need
2298 the frame chain (so we can determine if we're in scope). */
2299 reinit_frame_cache ();
2300 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2301 within_current_scope = (fr != NULL);
2302 if (within_current_scope)
2303 /* If we end up stopping, the current frame will get selected
2304 in normal_stop. So this call to select_frame won't affect
2306 select_frame (fr, -1);
2309 if (within_current_scope)
2311 /* We use value_{,free_to_}mark because it could be a
2312 *long* time before we return to the command level and
2313 call free_all_values. We can't call free_all_values because
2314 we might be in the middle of evaluating a function call. */
2316 value_ptr mark = value_mark ();
2317 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2318 if (!value_equal (b->val, new_val))
2320 release_value (new_val);
2321 value_free_to_mark (mark);
2322 bs->old_val = b->val;
2324 /* We will stop here */
2325 return WP_VALUE_CHANGED;
2329 /* Nothing changed, don't do anything. */
2330 value_free_to_mark (mark);
2331 /* We won't stop here */
2332 return WP_VALUE_NOT_CHANGED;
2337 /* This seems like the only logical thing to do because
2338 if we temporarily ignored the watchpoint, then when
2339 we reenter the block in which it is valid it contains
2340 garbage (in the case of a function, it may have two
2341 garbage values, one before and one after the prologue).
2342 So we can't even detect the first assignment to it and
2343 watch after that (since the garbage may or may not equal
2344 the first value assigned). */
2345 /* We print all the stop information in print_it_typical(), but
2346 in this case, by the time we call print_it_typical() this bp
2347 will be deleted already. So we have no choice but print the
2348 information here. */
2350 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2351 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2352 ui_out_text (uiout, "\nWatchpoint ");
2353 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2354 ui_out_text (uiout, " deleted because the program has left the block in\n\
2355 which its expression is valid.\n");
2358 Watchpoint %d deleted because the program has left the block in\n\
2359 which its expression is valid.\n", bs->breakpoint_at->number);
2362 if (b->related_breakpoint)
2363 b->related_breakpoint->disposition = del_at_next_stop;
2364 b->disposition = del_at_next_stop;
2370 /* Get a bpstat associated with having just stopped at address *PC
2371 and frame address CORE_ADDRESS. Update *PC to point at the
2372 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2373 if this is known to not be a real breakpoint (it could still be a
2374 watchpoint, though). */
2376 /* Determine whether we stopped at a breakpoint, etc, or whether we
2377 don't understand this stop. Result is a chain of bpstat's such that:
2379 if we don't understand the stop, the result is a null pointer.
2381 if we understand why we stopped, the result is not null.
2383 Each element of the chain refers to a particular breakpoint or
2384 watchpoint at which we have stopped. (We may have stopped for
2385 several reasons concurrently.)
2387 Each element of the chain has valid next, breakpoint_at,
2388 commands, FIXME??? fields. */
2391 bpstat_stop_status (CORE_ADDR *pc, int not_a_breakpoint)
2393 register struct breakpoint *b, *temp;
2395 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2396 int real_breakpoint = 0;
2397 /* Root of the chain of bpstat's */
2398 struct bpstats root_bs[1];
2399 /* Pointer to the last thing in the chain currently. */
2400 bpstat bs = root_bs;
2401 static char message1[] =
2402 "Error evaluating expression for watchpoint %d\n";
2403 char message[sizeof (message1) + 30 /* slop */ ];
2405 /* Get the address where the breakpoint would have been. */
2406 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P () ?
2407 0 : DECR_PC_AFTER_BREAK);
2409 ALL_BREAKPOINTS_SAFE (b, temp)
2411 if (b->enable == disabled
2412 || b->enable == shlib_disabled
2413 || b->enable == call_disabled)
2416 if (b->type != bp_watchpoint
2417 && b->type != bp_hardware_watchpoint
2418 && b->type != bp_read_watchpoint
2419 && b->type != bp_access_watchpoint
2420 && b->type != bp_hardware_breakpoint
2421 && b->type != bp_catch_fork
2422 && b->type != bp_catch_vfork
2423 && b->type != bp_catch_exec
2424 && b->type != bp_catch_catch
2425 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2426 if (b->address != bp_addr || /* address doesn't match or */
2427 (overlay_debugging && /* overlay doesn't match */
2428 section_is_overlay (b->section) &&
2429 !section_is_mapped (b->section)))
2432 if (b->type == bp_hardware_breakpoint
2433 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2436 /* Is this a catchpoint of a load or unload? If so, did we
2437 get a load or unload of the specified library? If not,
2439 if ((b->type == bp_catch_load)
2440 #if defined(SOLIB_HAVE_LOAD_EVENT)
2441 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2442 || ((b->dll_pathname != NULL)
2443 && (strcmp (b->dll_pathname,
2444 SOLIB_LOADED_LIBRARY_PATHNAME (
2445 PIDGET (inferior_ptid)))
2451 if ((b->type == bp_catch_unload)
2452 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2453 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2454 || ((b->dll_pathname != NULL)
2455 && (strcmp (b->dll_pathname,
2456 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2457 PIDGET (inferior_ptid)))
2463 if ((b->type == bp_catch_fork)
2464 && !target_has_forked (PIDGET (inferior_ptid),
2465 &b->forked_inferior_pid))
2468 if ((b->type == bp_catch_vfork)
2469 && !target_has_vforked (PIDGET (inferior_ptid),
2470 &b->forked_inferior_pid))
2473 if ((b->type == bp_catch_exec)
2474 && !target_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2477 if (ep_is_exception_catchpoint (b) &&
2478 !(current_exception_event = target_get_current_exception_event ()))
2481 /* Come here if it's a watchpoint, or if the break address matches */
2483 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2485 /* Watchpoints may change this, if not found to have triggered. */
2489 sprintf (message, message1, b->number);
2490 if (b->type == bp_watchpoint ||
2491 b->type == bp_hardware_watchpoint)
2493 switch (catch_errors (watchpoint_check, bs, message,
2497 /* We've already printed what needs to be printed. */
2498 /* Actually this is superfluous, because by the time we
2499 call print_it_typical() the wp will be already deleted,
2500 and the function will return immediately. */
2501 bs->print_it = print_it_done;
2504 case WP_VALUE_CHANGED:
2508 case WP_VALUE_NOT_CHANGED:
2510 bs->print_it = print_it_noop;
2517 /* Error from catch_errors. */
2518 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2519 if (b->related_breakpoint)
2520 b->related_breakpoint->disposition = del_at_next_stop;
2521 b->disposition = del_at_next_stop;
2522 /* We've already printed what needs to be printed. */
2523 bs->print_it = print_it_done;
2529 else if (b->type == bp_read_watchpoint ||
2530 b->type == bp_access_watchpoint)
2536 addr = target_stopped_data_address ();
2539 for (v = b->val_chain; v; v = v->next)
2541 if (VALUE_LVAL (v) == lval_memory
2542 && ! VALUE_LAZY (v))
2544 struct type *vtype = check_typedef (VALUE_TYPE (v));
2546 if (v == b->val_chain
2547 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2548 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2552 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2553 /* Exact match not required. Within range is
2555 if (addr >= vaddr &&
2556 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2562 switch (catch_errors (watchpoint_check, bs, message,
2566 /* We've already printed what needs to be printed. */
2567 bs->print_it = print_it_done;
2570 case WP_VALUE_CHANGED:
2571 if (b->type == bp_read_watchpoint)
2573 /* Don't stop: read watchpoints shouldn't fire if
2574 the value has changed. This is for targets which
2575 cannot set read-only watchpoints. */
2576 bs->print_it = print_it_noop;
2582 case WP_VALUE_NOT_CHANGED:
2589 /* Error from catch_errors. */
2590 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2591 if (b->related_breakpoint)
2592 b->related_breakpoint->disposition = del_at_next_stop;
2593 b->disposition = del_at_next_stop;
2594 /* We've already printed what needs to be printed. */
2595 bs->print_it = print_it_done;
2598 else /* found == 0 */
2600 /* This is a case where some watchpoint(s) triggered,
2601 but not at the address of this watchpoint (FOUND
2602 was left zero). So don't print anything for this
2604 bs->print_it = print_it_noop;
2611 /* By definition, an encountered breakpoint is a triggered
2615 real_breakpoint = 1;
2619 b->frame != (get_current_frame ())->frame)
2623 int value_is_zero = 0;
2627 /* Need to select the frame, with all that implies
2628 so that the conditions will have the right context. */
2629 select_frame (get_current_frame (), 0);
2631 = catch_errors (breakpoint_cond_eval, (b->cond),
2632 "Error in testing breakpoint condition:\n",
2634 /* FIXME-someday, should give breakpoint # */
2637 if (b->cond && value_is_zero)
2640 /* Don't consider this a hit. */
2643 else if (b->ignore_count > 0)
2646 annotate_ignore_count_change ();
2651 /* We will stop here */
2652 if (b->disposition == disable)
2653 b->enable = disabled;
2654 bs->commands = b->commands;
2658 (STREQ ("silent", bs->commands->line) ||
2659 (xdb_commands && STREQ ("Q", bs->commands->line))))
2661 bs->commands = bs->commands->next;
2666 /* Print nothing for this entry if we dont stop or if we dont print. */
2667 if (bs->stop == 0 || bs->print == 0)
2668 bs->print_it = print_it_noop;
2671 bs->next = NULL; /* Terminate the chain */
2672 bs = root_bs->next; /* Re-grab the head of the chain */
2674 if (real_breakpoint && bs)
2676 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2678 if (DECR_PC_AFTER_HW_BREAK != 0)
2680 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2686 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2689 #if defined (SHIFT_INST_REGS)
2691 #else /* No SHIFT_INST_REGS. */
2693 #endif /* No SHIFT_INST_REGS. */
2698 /* The value of a hardware watchpoint hasn't changed, but the
2699 intermediate memory locations we are watching may have. */
2700 if (bs && !bs->stop &&
2701 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2702 bs->breakpoint_at->type == bp_read_watchpoint ||
2703 bs->breakpoint_at->type == bp_access_watchpoint))
2705 remove_breakpoints ();
2706 insert_breakpoints ();
2711 /* Tell what to do about this bpstat. */
2713 bpstat_what (bpstat bs)
2715 /* Classify each bpstat as one of the following. */
2718 /* This bpstat element has no effect on the main_action. */
2721 /* There was a watchpoint, stop but don't print. */
2724 /* There was a watchpoint, stop and print. */
2727 /* There was a breakpoint but we're not stopping. */
2730 /* There was a breakpoint, stop but don't print. */
2733 /* There was a breakpoint, stop and print. */
2736 /* We hit the longjmp breakpoint. */
2739 /* We hit the longjmp_resume breakpoint. */
2742 /* We hit the step_resume breakpoint. */
2745 /* We hit the through_sigtramp breakpoint. */
2748 /* We hit the shared library event breakpoint. */
2751 /* We caught a shared library event. */
2754 /* This is just used to count how many enums there are. */
2758 /* Here is the table which drives this routine. So that we can
2759 format it pretty, we define some abbreviations for the
2760 enum bpstat_what codes. */
2761 #define kc BPSTAT_WHAT_KEEP_CHECKING
2762 #define ss BPSTAT_WHAT_STOP_SILENT
2763 #define sn BPSTAT_WHAT_STOP_NOISY
2764 #define sgl BPSTAT_WHAT_SINGLE
2765 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2766 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2767 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2768 #define sr BPSTAT_WHAT_STEP_RESUME
2769 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2770 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2771 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2773 /* "Can't happen." Might want to print an error message.
2774 abort() is not out of the question, but chances are GDB is just
2775 a bit confused, not unusable. */
2776 #define err BPSTAT_WHAT_STOP_NOISY
2778 /* Given an old action and a class, come up with a new action. */
2779 /* One interesting property of this table is that wp_silent is the same
2780 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2781 after stopping, the check for whether to step over a breakpoint
2782 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2783 reference to how we stopped. We retain separate wp_silent and
2784 bp_silent codes in case we want to change that someday.
2786 Another possibly interesting property of this table is that
2787 there's a partial ordering, priority-like, of the actions. Once
2788 you've decided that some action is appropriate, you'll never go
2789 back and decide something of a lower priority is better. The
2792 kc < clr sgl shl shlr slr sn sr ss ts
2793 sgl < clrs shl shlr slr sn sr ss ts
2794 slr < err shl shlr sn sr ss ts
2795 clr < clrs err shl shlr sn sr ss ts
2796 clrs < err shl shlr sn sr ss ts
2797 ss < shl shlr sn sr ts
2804 What I think this means is that we don't need a damned table
2805 here. If you just put the rows and columns in the right order,
2806 it'd look awfully regular. We could simply walk the bpstat list
2807 and choose the highest priority action we find, with a little
2808 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2809 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2810 is messy anyway). */
2812 /* step_resume entries: a step resume breakpoint overrides another
2813 breakpoint of signal handling (see comment in wait_for_inferior
2814 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2815 /* We handle the through_sigtramp_breakpoint the same way; having both
2816 one of those and a step_resume_breakpoint is probably very rare (?). */
2818 static const enum bpstat_what_main_action
2819 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2822 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2825 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2827 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2829 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2831 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2833 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2835 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2837 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2839 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2841 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2843 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2845 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2847 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2862 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2863 struct bpstat_what retval;
2865 retval.call_dummy = 0;
2866 for (; bs != NULL; bs = bs->next)
2868 enum class bs_class = no_effect;
2869 if (bs->breakpoint_at == NULL)
2870 /* I suspect this can happen if it was a momentary breakpoint
2871 which has since been deleted. */
2873 switch (bs->breakpoint_at->type)
2879 case bp_hardware_breakpoint:
2885 bs_class = bp_noisy;
2887 bs_class = bp_silent;
2890 bs_class = bp_nostop;
2893 case bp_hardware_watchpoint:
2894 case bp_read_watchpoint:
2895 case bp_access_watchpoint:
2899 bs_class = wp_noisy;
2901 bs_class = wp_silent;
2904 /* There was a watchpoint, but we're not stopping.
2905 This requires no further action. */
2906 bs_class = no_effect;
2909 bs_class = long_jump;
2911 case bp_longjmp_resume:
2912 bs_class = long_resume;
2914 case bp_step_resume:
2917 bs_class = step_resume;
2920 /* It is for the wrong frame. */
2921 bs_class = bp_nostop;
2923 case bp_through_sigtramp:
2924 bs_class = through_sig;
2926 case bp_watchpoint_scope:
2927 bs_class = bp_nostop;
2929 case bp_shlib_event:
2930 bs_class = shlib_event;
2932 case bp_thread_event:
2933 bs_class = bp_nostop;
2936 case bp_catch_unload:
2937 /* Only if this catchpoint triggered should we cause the
2938 step-out-of-dld behaviour. Otherwise, we ignore this
2941 bs_class = catch_shlib_event;
2943 bs_class = no_effect;
2946 case bp_catch_vfork:
2951 bs_class = bp_noisy;
2953 bs_class = bp_silent;
2956 /* There was a catchpoint, but we're not stopping.
2957 This requires no further action. */
2958 bs_class = no_effect;
2960 case bp_catch_catch:
2961 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2962 bs_class = bp_nostop;
2964 bs_class = bs->print ? bp_noisy : bp_silent;
2966 case bp_catch_throw:
2967 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2968 bs_class = bp_nostop;
2970 bs_class = bs->print ? bp_noisy : bp_silent;
2973 /* Make sure the action is stop (silent or noisy),
2974 so infrun.c pops the dummy frame. */
2975 bs_class = bp_silent;
2976 retval.call_dummy = 1;
2979 current_action = table[(int) bs_class][(int) current_action];
2981 retval.main_action = current_action;
2985 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2986 without hardware support). This isn't related to a specific bpstat,
2987 just to things like whether watchpoints are set. */
2990 bpstat_should_step (void)
2992 struct breakpoint *b;
2994 if (b->enable == enabled && b->type == bp_watchpoint)
2999 /* Nonzero if there are enabled hardware watchpoints. */
3001 bpstat_have_active_hw_watchpoints (void)
3003 struct breakpoint *b;
3005 if ((b->enable == enabled) &&
3007 ((b->type == bp_hardware_watchpoint) ||
3008 (b->type == bp_read_watchpoint) ||
3009 (b->type == bp_access_watchpoint)))
3015 /* Given a bpstat that records zero or more triggered eventpoints, this
3016 function returns another bpstat which contains only the catchpoints
3017 on that first list, if any. */
3019 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3021 struct bpstats root_bs[1];
3022 bpstat bs = root_bs;
3023 struct breakpoint *ep;
3026 bpstat_clear (cp_list);
3027 root_bs->next = NULL;
3029 for (; ep_list != NULL; ep_list = ep_list->next)
3031 /* Is this eventpoint a catchpoint? If not, ignore it. */
3032 ep = ep_list->breakpoint_at;
3035 if ((ep->type != bp_catch_load) &&
3036 (ep->type != bp_catch_unload) &&
3037 (ep->type != bp_catch_catch) &&
3038 (ep->type != bp_catch_throw))
3039 /* pai: (temp) ADD fork/vfork here!! */
3042 /* Yes; add it to the list. */
3043 bs = bpstat_alloc (ep, bs);
3048 #if defined(SOLIB_ADD)
3049 /* Also, for each triggered catchpoint, tag it with the name of
3050 the library that caused this trigger. (We copy the name now,
3051 because it's only guaranteed to be available NOW, when the
3052 catchpoint triggers. Clients who may wish to know the name
3053 later must get it from the catchpoint itself.) */
3054 if (ep->triggered_dll_pathname != NULL)
3055 xfree (ep->triggered_dll_pathname);
3056 if (ep->type == bp_catch_load)
3057 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3058 PIDGET (inferior_ptid));
3060 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3061 PIDGET (inferior_ptid));
3063 dll_pathname = NULL;
3067 ep->triggered_dll_pathname = (char *)
3068 xmalloc (strlen (dll_pathname) + 1);
3069 strcpy (ep->triggered_dll_pathname, dll_pathname);
3072 ep->triggered_dll_pathname = NULL;
3078 /* Print B to gdb_stdout. */
3080 print_one_breakpoint (struct breakpoint *b,
3081 CORE_ADDR *last_addr)
3083 register struct command_line *l;
3084 register struct symbol *sym;
3085 struct ep_type_description
3090 static struct ep_type_description bptypes[] =
3092 {bp_none, "?deleted?"},
3093 {bp_breakpoint, "breakpoint"},
3094 {bp_hardware_breakpoint, "hw breakpoint"},
3095 {bp_until, "until"},
3096 {bp_finish, "finish"},
3097 {bp_watchpoint, "watchpoint"},
3098 {bp_hardware_watchpoint, "hw watchpoint"},
3099 {bp_read_watchpoint, "read watchpoint"},
3100 {bp_access_watchpoint, "acc watchpoint"},
3101 {bp_longjmp, "longjmp"},
3102 {bp_longjmp_resume, "longjmp resume"},
3103 {bp_step_resume, "step resume"},
3104 {bp_through_sigtramp, "sigtramp"},
3105 {bp_watchpoint_scope, "watchpoint scope"},
3106 {bp_call_dummy, "call dummy"},
3107 {bp_shlib_event, "shlib events"},
3108 {bp_thread_event, "thread events"},
3109 {bp_catch_load, "catch load"},
3110 {bp_catch_unload, "catch unload"},
3111 {bp_catch_fork, "catch fork"},
3112 {bp_catch_vfork, "catch vfork"},
3113 {bp_catch_exec, "catch exec"},
3114 {bp_catch_catch, "catch catch"},
3115 {bp_catch_throw, "catch throw"}
3118 static char *bpdisps[] =
3119 {"del", "dstp", "dis", "keep"};
3120 static char bpenables[] = "nynny";
3121 char wrap_indent[80];
3123 struct ui_stream *stb = ui_out_stream_new (uiout);
3124 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3129 ui_out_tuple_begin (uiout, "bkpt");
3135 ui_out_field_int (uiout, "number", b->number);
3137 printf_filtered ("%-3d ", b->number);
3142 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3143 || ((int) b->type != bptypes[(int) b->type].type))
3144 internal_error (__FILE__, __LINE__,
3145 "bptypes table does not describe type #%d.",
3148 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3150 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3156 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3158 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3164 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3165 ui_out_spaces (uiout, 2);
3167 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3171 strcpy (wrap_indent, " ");
3174 if (TARGET_ADDR_BIT <= 32)
3175 strcat (wrap_indent, " ");
3177 strcat (wrap_indent, " ");
3182 internal_error (__FILE__, __LINE__,
3183 "print_one_breakpoint: bp_none encountered\n");
3187 case bp_hardware_watchpoint:
3188 case bp_read_watchpoint:
3189 case bp_access_watchpoint:
3190 /* Field 4, the address, is omitted (which makes the columns
3191 not line up too nicely with the headers, but the effect
3192 is relatively readable). */
3195 ui_out_field_skip (uiout, "addr");
3197 print_expression (b->exp, stb->stream);
3198 ui_out_field_stream (uiout, "what", stb);
3201 print_expression (b->exp, gdb_stdout);
3206 case bp_catch_unload:
3207 /* Field 4, the address, is omitted (which makes the columns
3208 not line up too nicely with the headers, but the effect
3209 is relatively readable). */
3212 ui_out_field_skip (uiout, "addr");
3214 if (b->dll_pathname == NULL)
3216 ui_out_field_string (uiout, "what", "<any library>");
3217 ui_out_spaces (uiout, 1);
3221 ui_out_text (uiout, "library \"");
3222 ui_out_field_string (uiout, "what", b->dll_pathname);
3223 ui_out_text (uiout, "\" ");
3227 if (b->dll_pathname == NULL)
3228 printf_filtered ("<any library> ");
3230 printf_filtered ("library \"%s\" ", b->dll_pathname);
3235 case bp_catch_vfork:
3236 /* Field 4, the address, is omitted (which makes the columns
3237 not line up too nicely with the headers, but the effect
3238 is relatively readable). */
3241 ui_out_field_skip (uiout, "addr");
3243 if (b->forked_inferior_pid != 0)
3245 ui_out_text (uiout, "process ");
3246 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3247 ui_out_spaces (uiout, 1);
3251 if (b->forked_inferior_pid != 0)
3252 printf_filtered ("process %d ", b->forked_inferior_pid);
3257 /* Field 4, the address, is omitted (which makes the columns
3258 not line up too nicely with the headers, but the effect
3259 is relatively readable). */
3262 ui_out_field_skip (uiout, "addr");
3264 if (b->exec_pathname != NULL)
3266 ui_out_text (uiout, "program \"");
3267 ui_out_field_string (uiout, "what", b->exec_pathname);
3268 ui_out_text (uiout, "\" ");
3272 if (b->exec_pathname != NULL)
3273 printf_filtered ("program \"%s\" ", b->exec_pathname);
3277 case bp_catch_catch:
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 catch");
3286 ui_out_spaces (uiout, 1);
3289 printf_filtered ("exception catch ");
3293 case bp_catch_throw:
3294 /* Field 4, the address, is omitted (which makes the columns
3295 not line up too nicely with the headers, but the effect
3296 is relatively readable). */
3299 ui_out_field_skip (uiout, "addr");
3301 ui_out_field_string (uiout, "what", "exception throw");
3302 ui_out_spaces (uiout, 1);
3305 printf_filtered ("exception throw ");
3310 case bp_hardware_breakpoint:
3314 case bp_longjmp_resume:
3315 case bp_step_resume:
3316 case bp_through_sigtramp:
3317 case bp_watchpoint_scope:
3319 case bp_shlib_event:
3320 case bp_thread_event:
3325 ui_out_field_core_addr (uiout, "addr", b->address);
3328 *last_addr = b->address;
3331 sym = find_pc_sect_function (b->address, b->section);
3334 ui_out_text (uiout, "in ");
3335 ui_out_field_string (uiout, "func",
3336 SYMBOL_SOURCE_NAME (sym));
3337 ui_out_wrap_hint (uiout, wrap_indent);
3338 ui_out_text (uiout, " at ");
3340 ui_out_field_string (uiout, "file", b->source_file);
3341 ui_out_text (uiout, ":");
3342 ui_out_field_int (uiout, "line", b->line_number);
3346 print_address_symbolic (b->address, stb->stream, demangle, "");
3347 ui_out_field_stream (uiout, "at", stb);
3356 if (TARGET_ADDR_BIT <= 32)
3357 tmp = longest_local_hex_string_custom (b->address
3358 & (CORE_ADDR) 0xffffffff,
3361 tmp = longest_local_hex_string_custom (b->address, "016l");
3363 printf_filtered ("%s ", tmp);
3366 *last_addr = b->address;
3369 sym = find_pc_sect_function (b->address, b->section);
3372 fputs_filtered ("in ", gdb_stdout);
3373 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
3374 wrap_here (wrap_indent);
3375 fputs_filtered (" at ", gdb_stdout);
3377 fputs_filtered (b->source_file, gdb_stdout);
3378 printf_filtered (":%d", b->line_number);
3381 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
3386 if (b->thread != -1)
3389 /* FIXME: This seems to be redundant and lost here; see the
3390 "stop only in" line a little further down. */
3391 ui_out_text (uiout, " thread ");
3392 ui_out_field_int (uiout, "thread", b->thread);
3394 printf_filtered (" thread %d", b->thread);
3399 ui_out_text (uiout, "\n");
3401 printf_filtered ("\n");
3408 ui_out_text (uiout, "\tstop only in stack frame at ");
3409 ui_out_field_core_addr (uiout, "frame", b->frame);
3410 ui_out_text (uiout, "\n");
3412 printf_filtered ("\tstop only in stack frame at ");
3413 print_address_numeric (b->frame, 1, gdb_stdout);
3414 printf_filtered ("\n");
3422 ui_out_text (uiout, "\tstop only if ");
3423 print_expression (b->cond, stb->stream);
3424 ui_out_field_stream (uiout, "cond", stb);
3425 ui_out_text (uiout, "\n");
3427 printf_filtered ("\tstop only if ");
3428 print_expression (b->cond, gdb_stdout);
3429 printf_filtered ("\n");
3433 if (b->thread != -1)
3435 /* FIXME should make an annotation for this */
3437 ui_out_text (uiout, "\tstop only in thread ");
3438 ui_out_field_int (uiout, "thread", b->thread);
3439 ui_out_text (uiout, "\n");
3441 printf_filtered ("\tstop only in thread %d\n", b->thread);
3445 if (show_breakpoint_hit_counts && b->hit_count)
3447 /* FIXME should make an annotation for this */
3449 if (ep_is_catchpoint (b))
3450 ui_out_text (uiout, "\tcatchpoint");
3452 ui_out_text (uiout, "\tbreakpoint");
3453 ui_out_text (uiout, " already hit ");
3454 ui_out_field_int (uiout, "times", b->hit_count);
3455 if (b->hit_count == 1)
3456 ui_out_text (uiout, " time\n");
3458 ui_out_text (uiout, " times\n");
3460 if (ep_is_catchpoint (b))
3461 printf_filtered ("\tcatchpoint");
3463 printf_filtered ("\tbreakpoint");
3464 printf_filtered (" already hit %d time%s\n",
3465 b->hit_count, (b->hit_count == 1 ? "" : "s"));
3470 /* Output the count also if it is zero, but only if this is
3471 mi. FIXME: Should have a better test for this. */
3472 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
3473 if (show_breakpoint_hit_counts && b->hit_count == 0)
3474 ui_out_field_int (uiout, "times", b->hit_count);
3477 if (b->ignore_count)
3481 ui_out_text (uiout, "\tignore next ");
3482 ui_out_field_int (uiout, "ignore", b->ignore_count);
3483 ui_out_text (uiout, " hits\n");
3485 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
3489 if ((l = b->commands))
3493 ui_out_tuple_begin (uiout, "script");
3494 print_command_lines (uiout, l, 4);
3495 ui_out_tuple_end (uiout);
3499 print_command_line (l, 4, gdb_stdout);
3505 ui_out_tuple_end (uiout);
3506 do_cleanups (old_chain);
3510 struct captured_breakpoint_query_args
3516 do_captured_breakpoint_query (void *data)
3518 struct captured_breakpoint_query_args *args = data;
3519 register struct breakpoint *b;
3520 CORE_ADDR dummy_addr = 0;
3523 if (args->bnum == b->number)
3525 print_one_breakpoint (b, &dummy_addr);
3533 gdb_breakpoint_query (/* output object, */ int bnum)
3535 struct captured_breakpoint_query_args args;
3537 /* For the moment we don't trust print_one_breakpoint() to not throw
3539 return catch_errors (do_captured_breakpoint_query, &args,
3540 NULL, RETURN_MASK_ALL);
3543 /* Print information on breakpoint number BNUM, or -1 if all.
3544 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
3545 is nonzero, process only watchpoints. */
3548 breakpoint_1 (int bnum, int allflag)
3550 register struct breakpoint *b;
3551 CORE_ADDR last_addr = (CORE_ADDR) -1;
3552 int found_a_breakpoint = 0;
3556 ui_out_table_begin (uiout, 6, "BreakpointTable");
3558 ui_out_table_begin (uiout, 5, "BreakpointTable");
3563 || bnum == b->number)
3565 /* We only print out user settable breakpoints unless the
3568 && b->type != bp_breakpoint
3569 && b->type != bp_catch_load
3570 && b->type != bp_catch_unload
3571 && b->type != bp_catch_fork
3572 && b->type != bp_catch_vfork
3573 && b->type != bp_catch_exec
3574 && b->type != bp_catch_catch
3575 && b->type != bp_catch_throw
3576 && b->type != bp_hardware_breakpoint
3577 && b->type != bp_watchpoint
3578 && b->type != bp_read_watchpoint
3579 && b->type != bp_access_watchpoint
3580 && b->type != bp_hardware_watchpoint)
3583 if (!found_a_breakpoint++)
3585 annotate_breakpoints_headers ();
3588 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3590 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3592 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3594 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3598 if (TARGET_ADDR_BIT <= 32)
3599 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3601 ui_out_table_header (uiout, 18, ui_left, "Address"); /* 5 */
3604 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3605 ui_out_table_body (uiout);
3608 printf_filtered ("Num ");
3610 printf_filtered ("Type ");
3612 printf_filtered ("Disp ");
3614 printf_filtered ("Enb ");
3618 if (TARGET_ADDR_BIT <= 32)
3619 printf_filtered ("Address ");
3621 printf_filtered ("Address ");
3624 printf_filtered ("What\n");
3626 annotate_breakpoints_table ();
3629 print_one_breakpoint (b, &last_addr);
3632 if (!found_a_breakpoint)
3636 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3638 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3642 printf_filtered ("No breakpoints or watchpoints.\n");
3644 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3649 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3650 that a comparison of an unsigned with -1 is always false. */
3651 if (last_addr != (CORE_ADDR) -1)
3652 set_next_address (last_addr);
3656 ui_out_table_end (uiout);
3658 /* FIXME? Should this be moved up so that it is only called when
3659 there have been breakpoints? */
3660 annotate_breakpoints_table_end ();
3665 breakpoints_info (char *bnum_exp, int from_tty)
3670 bnum = parse_and_eval_long (bnum_exp);
3672 breakpoint_1 (bnum, 0);
3677 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3682 bnum = parse_and_eval_long (bnum_exp);
3684 breakpoint_1 (bnum, 1);
3687 /* Print a message describing any breakpoints set at PC. */
3690 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3692 register int others = 0;
3693 register struct breakpoint *b;
3696 if (b->address == pc)
3697 if (overlay_debugging == 0 ||
3698 b->section == section)
3702 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3704 if (b->address == pc)
3705 if (overlay_debugging == 0 ||
3706 b->section == section)
3709 printf_filtered ("%d%s%s ",
3711 ((b->enable == disabled ||
3712 b->enable == shlib_disabled ||
3713 b->enable == call_disabled) ? " (disabled)"
3714 : b->enable == permanent ? " (permanent)"
3717 : ((others == 1) ? " and" : ""));
3719 printf_filtered ("also set at pc ");
3720 print_address_numeric (pc, 1, gdb_stdout);
3721 printf_filtered (".\n");
3725 /* Set the default place to put a breakpoint
3726 for the `break' command with no arguments. */
3729 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3732 default_breakpoint_valid = valid;
3733 default_breakpoint_address = addr;
3734 default_breakpoint_symtab = symtab;
3735 default_breakpoint_line = line;
3738 /* Rescan breakpoints at the same address and section as BPT,
3739 marking the first one as "first" and any others as "duplicates".
3740 This is so that the bpt instruction is only inserted once.
3741 If we have a permanent breakpoint at the same place as BPT, make
3742 that one the official one, and the rest as duplicates. */
3745 check_duplicates (struct breakpoint *bpt)
3747 register struct breakpoint *b;
3748 register int count = 0;
3749 struct breakpoint *perm_bp = 0;
3750 CORE_ADDR address = bpt->address;
3751 asection *section = bpt->section;
3753 /* Watchpoints are uninteresting. */
3754 if (bpt->type == bp_watchpoint
3755 || bpt->type == bp_hardware_watchpoint
3756 || bpt->type == bp_read_watchpoint
3757 || bpt->type == bp_access_watchpoint)
3761 if (b->enable != disabled
3762 && b->enable != shlib_disabled
3763 && b->enable != call_disabled
3764 && b->address == address
3765 && (overlay_debugging == 0 || b->section == section))
3767 /* Have we found a permanent breakpoint? */
3768 if (b->enable == permanent)
3775 b->duplicate = count > 1;
3778 /* If we found a permanent breakpoint at this address, go over the
3779 list again and declare all the other breakpoints there to be the
3783 perm_bp->duplicate = 0;
3785 /* Permanent breakpoint should always be inserted. */
3786 if (! perm_bp->inserted)
3787 internal_error (__FILE__, __LINE__,
3788 "allegedly permanent breakpoint is not "
3789 "actually inserted");
3795 internal_error (__FILE__, __LINE__,
3796 "another breakpoint was inserted on top of "
3797 "a permanent breakpoint");
3799 if (b->enable != disabled
3800 && b->enable != shlib_disabled
3801 && b->enable != call_disabled
3802 && b->address == address
3803 && (overlay_debugging == 0 || b->section == section))
3809 /* set_raw_breakpoint() is a low level routine for allocating and
3810 partially initializing a breakpoint of type BPTYPE. The newly
3811 created breakpoint's address, section, source file name, and line
3812 number are provided by SAL. The newly created and partially
3813 initialized breakpoint is added to the breakpoint chain and
3814 is also returned as the value of this function.
3816 It is expected that the caller will complete the initialization of
3817 the newly created breakpoint struct as well as output any status
3818 information regarding the creation of a new breakpoint. In
3819 particular, set_raw_breakpoint() does NOT set the breakpoint
3820 number! Care should be taken to not allow an error() to occur
3821 prior to completing the initialization of the breakpoint. If this
3822 should happen, a bogus breakpoint will be left on the chain. */
3825 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3827 register struct breakpoint *b, *b1;
3829 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3830 memset (b, 0, sizeof (*b));
3831 b->address = sal.pc;
3832 if (sal.symtab == NULL)
3833 b->source_file = NULL;
3835 b->source_file = savestring (sal.symtab->filename,
3836 strlen (sal.symtab->filename));
3837 b->section = sal.section;
3839 b->language = current_language->la_language;
3840 b->input_radix = input_radix;
3842 b->line_number = sal.line;
3843 b->enable = enabled;
3846 b->ignore_count = 0;
3849 b->dll_pathname = NULL;
3850 b->triggered_dll_pathname = NULL;
3851 b->forked_inferior_pid = 0;
3852 b->exec_pathname = NULL;
3854 /* Add this breakpoint to the end of the chain
3855 so that a list of breakpoints will come out in order
3856 of increasing numbers. */
3858 b1 = breakpoint_chain;
3860 breakpoint_chain = b;
3868 check_duplicates (b);
3869 breakpoints_changed ();
3875 /* Note that the breakpoint object B describes a permanent breakpoint
3876 instruction, hard-wired into the inferior's code. */
3878 make_breakpoint_permanent (struct breakpoint *b)
3880 b->enable = permanent;
3882 /* By definition, permanent breakpoints are already present in the code. */
3886 #ifdef GET_LONGJMP_TARGET
3889 create_longjmp_breakpoint (char *func_name)
3891 struct symtab_and_line sal;
3892 struct breakpoint *b;
3894 INIT_SAL (&sal); /* initialize to zeroes */
3895 if (func_name != NULL)
3897 struct minimal_symbol *m;
3899 m = lookup_minimal_symbol_text (func_name, NULL,
3900 (struct objfile *) NULL);
3902 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3906 sal.section = find_pc_overlay (sal.pc);
3907 b = set_raw_breakpoint (sal,
3908 func_name != NULL ? bp_longjmp : bp_longjmp_resume);
3910 b->disposition = donttouch;
3911 b->enable = disabled;
3914 b->addr_string = xstrdup (func_name);
3915 b->number = internal_breakpoint_number--;
3918 #endif /* #ifdef GET_LONGJMP_TARGET */
3920 /* Call this routine when stepping and nexting to enable a breakpoint
3921 if we do a longjmp(). When we hit that breakpoint, call
3922 set_longjmp_resume_breakpoint() to figure out where we are going. */
3925 enable_longjmp_breakpoint (void)
3927 register struct breakpoint *b;
3930 if (b->type == bp_longjmp)
3932 b->enable = enabled;
3933 check_duplicates (b);
3938 disable_longjmp_breakpoint (void)
3940 register struct breakpoint *b;
3943 if (b->type == bp_longjmp
3944 || b->type == bp_longjmp_resume)
3946 b->enable = disabled;
3947 check_duplicates (b);
3952 create_thread_event_breakpoint (CORE_ADDR address)
3954 struct breakpoint *b;
3955 struct symtab_and_line sal;
3956 char addr_string[80]; /* Surely an addr can't be longer than that. */
3958 INIT_SAL (&sal); /* initialize to zeroes */
3960 sal.section = find_pc_overlay (sal.pc);
3961 b = set_raw_breakpoint (sal, bp_thread_event);
3963 b->number = internal_breakpoint_number--;
3964 b->disposition = donttouch;
3965 b->enable = enabled;
3966 /* addr_string has to be used or breakpoint_re_set will delete me. */
3967 sprintf (addr_string, "*0x%s", paddr (b->address));
3968 b->addr_string = xstrdup (addr_string);
3974 remove_thread_event_breakpoints (void)
3976 struct breakpoint *b, *temp;
3978 ALL_BREAKPOINTS_SAFE (b, temp)
3979 if (b->type == bp_thread_event)
3980 delete_breakpoint (b);
3985 remove_solib_event_breakpoints (void)
3987 register struct breakpoint *b, *temp;
3989 ALL_BREAKPOINTS_SAFE (b, temp)
3990 if (b->type == bp_shlib_event)
3991 delete_breakpoint (b);
3995 create_solib_event_breakpoint (CORE_ADDR address)
3997 struct breakpoint *b;
3998 struct symtab_and_line sal;
4000 INIT_SAL (&sal); /* initialize to zeroes */
4002 sal.section = find_pc_overlay (sal.pc);
4003 b = set_raw_breakpoint (sal, bp_shlib_event);
4004 b->number = internal_breakpoint_number--;
4005 b->disposition = donttouch;
4010 /* Disable any breakpoints that are on code in shared libraries. Only
4011 apply to enabled breakpoints, disabled ones can just stay disabled. */
4014 disable_breakpoints_in_shlibs (int silent)
4016 struct breakpoint *b;
4017 int disabled_shlib_breaks = 0;
4019 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4022 #if defined (PC_SOLIB)
4023 if (((b->type == bp_breakpoint) ||
4024 (b->type == bp_hardware_breakpoint)) &&
4025 b->enable == enabled &&
4027 PC_SOLIB (b->address))
4029 b->enable = shlib_disabled;
4032 if (!disabled_shlib_breaks)
4034 target_terminal_ours_for_output ();
4035 warning ("Temporarily disabling shared library breakpoints:");
4037 disabled_shlib_breaks = 1;
4038 warning ("breakpoint #%d ", b->number);
4045 /* Try to reenable any breakpoints in shared libraries. */
4047 re_enable_breakpoints_in_shlibs (void)
4049 struct breakpoint *b;
4052 if (b->enable == shlib_disabled)
4056 /* Do not reenable the breakpoint if the shared library
4057 is still not mapped in. */
4058 if (target_read_memory (b->address, buf, 1) == 0)
4059 b->enable = enabled;
4066 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4067 char *cond_string, enum bptype bp_kind)
4069 struct breakpoint *b;
4070 struct symtabs_and_lines sals;
4071 struct cleanup *old_chain;
4072 struct cleanup *canonical_strings_chain = NULL;
4073 char *addr_start = hookname;
4074 char *addr_end = NULL;
4075 char **canonical = (char **) NULL;
4076 int thread = -1; /* All threads. */
4078 /* Set a breakpoint on the specified hook. */
4079 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4080 addr_end = hookname;
4082 if (sals.nelts == 0)
4084 warning ("Unable to set a breakpoint on dynamic linker callback.");
4085 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4086 warning ("GDB will be unable to track shl_load/shl_unload calls");
4089 if (sals.nelts != 1)
4091 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4092 warning ("GDB will be unable to track shl_load/shl_unload calls");
4096 /* Make sure that all storage allocated in decode_line_1 gets freed
4097 in case the following errors out. */
4098 old_chain = make_cleanup (xfree, sals.sals);
4099 if (canonical != (char **) NULL)
4101 make_cleanup (xfree, canonical);
4102 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4103 if (canonical[0] != NULL)
4104 make_cleanup (xfree, canonical[0]);
4107 resolve_sal_pc (&sals.sals[0]);
4109 /* Remove the canonical strings from the cleanup, they are needed below. */
4110 if (canonical != (char **) NULL)
4111 discard_cleanups (canonical_strings_chain);
4113 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4114 set_breakpoint_count (breakpoint_count + 1);
4115 b->number = breakpoint_count;
4117 b->cond_string = (cond_string == NULL) ?
4118 NULL : savestring (cond_string, strlen (cond_string));
4121 if (canonical != (char **) NULL && canonical[0] != NULL)
4122 b->addr_string = canonical[0];
4123 else if (addr_start)
4124 b->addr_string = savestring (addr_start, addr_end - addr_start);
4126 b->enable = enabled;
4127 b->disposition = tempflag ? del : donttouch;
4129 if (dll_pathname == NULL)
4130 b->dll_pathname = NULL;
4133 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4134 strcpy (b->dll_pathname, dll_pathname);
4138 do_cleanups (old_chain);
4142 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4143 char *dll_pathname, char *cond_string)
4145 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4146 cond_string, bp_catch_load);
4150 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4151 char *dll_pathname, char *cond_string)
4153 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4154 cond_string, bp_catch_unload);
4158 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4159 enum bptype bp_kind)
4161 struct symtab_and_line sal;
4162 struct breakpoint *b;
4163 int thread = -1; /* All threads. */
4170 b = set_raw_breakpoint (sal, bp_kind);
4171 set_breakpoint_count (breakpoint_count + 1);
4172 b->number = breakpoint_count;
4174 b->cond_string = (cond_string == NULL) ?
4175 NULL : savestring (cond_string, strlen (cond_string));
4177 b->addr_string = NULL;
4178 b->enable = enabled;
4179 b->disposition = tempflag ? del : donttouch;
4180 b->forked_inferior_pid = 0;
4186 create_fork_event_catchpoint (int tempflag, char *cond_string)
4188 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4192 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4194 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4198 create_exec_event_catchpoint (int tempflag, char *cond_string)
4200 struct symtab_and_line sal;
4201 struct breakpoint *b;
4202 int thread = -1; /* All threads. */
4209 b = set_raw_breakpoint (sal, bp_catch_exec);
4210 set_breakpoint_count (breakpoint_count + 1);
4211 b->number = breakpoint_count;
4213 b->cond_string = (cond_string == NULL) ?
4214 NULL : savestring (cond_string, strlen (cond_string));
4216 b->addr_string = NULL;
4217 b->enable = enabled;
4218 b->disposition = tempflag ? del : donttouch;
4224 hw_breakpoint_used_count (void)
4226 register struct breakpoint *b;
4231 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4239 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4241 register struct breakpoint *b;
4244 *other_type_used = 0;
4247 if (b->enable == enabled)
4249 if (b->type == type)
4251 else if ((b->type == bp_hardware_watchpoint ||
4252 b->type == bp_read_watchpoint ||
4253 b->type == bp_access_watchpoint)
4254 && b->enable == enabled)
4255 *other_type_used = 1;
4261 /* Call this after hitting the longjmp() breakpoint. Use this to set
4262 a new breakpoint at the target of the jmp_buf.
4264 FIXME - This ought to be done by setting a temporary breakpoint
4265 that gets deleted automatically... */
4268 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
4270 register struct breakpoint *b;
4273 if (b->type == bp_longjmp_resume)
4276 b->enable = enabled;
4278 b->frame = frame->frame;
4281 check_duplicates (b);
4287 disable_watchpoints_before_interactive_call_start (void)
4289 struct breakpoint *b;
4293 if (((b->type == bp_watchpoint)
4294 || (b->type == bp_hardware_watchpoint)
4295 || (b->type == bp_read_watchpoint)
4296 || (b->type == bp_access_watchpoint)
4297 || ep_is_exception_catchpoint (b))
4298 && (b->enable == enabled))
4300 b->enable = call_disabled;
4301 check_duplicates (b);
4307 enable_watchpoints_after_interactive_call_stop (void)
4309 struct breakpoint *b;
4313 if (((b->type == bp_watchpoint)
4314 || (b->type == bp_hardware_watchpoint)
4315 || (b->type == bp_read_watchpoint)
4316 || (b->type == bp_access_watchpoint)
4317 || ep_is_exception_catchpoint (b))
4318 && (b->enable == call_disabled))
4320 b->enable = enabled;
4321 check_duplicates (b);
4327 /* Set a breakpoint that will evaporate an end of command
4328 at address specified by SAL.
4329 Restrict it to frame FRAME if FRAME is nonzero. */
4332 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4335 register struct breakpoint *b;
4336 b = set_raw_breakpoint (sal, type);
4337 b->enable = enabled;
4338 b->disposition = donttouch;
4339 b->frame = (frame ? frame->frame : 0);
4341 /* If we're debugging a multi-threaded program, then we
4342 want momentary breakpoints to be active in only a
4343 single thread of control. */
4344 if (in_thread_list (inferior_ptid))
4345 b->thread = pid_to_thread_id (inferior_ptid);
4351 /* Tell the user we have just set a breakpoint B. */
4354 mention (struct breakpoint *b)
4358 struct cleanup *old_chain;
4359 struct ui_stream *stb;
4361 stb = ui_out_stream_new (uiout);
4362 old_chain = make_cleanup_ui_out_stream_delete (stb);
4365 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4366 watchpoint) other than breakpoint creation. It should be possible to
4367 clean this up and at the same time replace the random calls to
4368 breakpoint_changed with this hook, as has already been done for
4369 delete_breakpoint_hook and so on. */
4370 if (create_breakpoint_hook)
4371 create_breakpoint_hook (b);
4372 breakpoint_create_event (b->number);
4377 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4381 ui_out_text (uiout, "Watchpoint ");
4382 ui_out_tuple_begin (uiout, "wpt");
4383 ui_out_field_int (uiout, "number", b->number);
4384 ui_out_text (uiout, ": ");
4385 print_expression (b->exp, stb->stream);
4386 ui_out_field_stream (uiout, "exp", stb);
4387 ui_out_tuple_end (uiout);
4389 case bp_hardware_watchpoint:
4390 ui_out_text (uiout, "Hardware watchpoint ");
4391 ui_out_tuple_begin (uiout, "wpt");
4392 ui_out_field_int (uiout, "number", b->number);
4393 ui_out_text (uiout, ": ");
4394 print_expression (b->exp, stb->stream);
4395 ui_out_field_stream (uiout, "exp", stb);
4396 ui_out_tuple_end (uiout);
4400 printf_filtered ("Watchpoint %d: ", b->number);
4401 print_expression (b->exp, gdb_stdout);
4403 case bp_hardware_watchpoint:
4404 printf_filtered ("Hardware watchpoint %d: ", b->number);
4405 print_expression (b->exp, gdb_stdout);
4409 case bp_read_watchpoint:
4410 ui_out_text (uiout, "Hardware read watchpoint ");
4411 ui_out_tuple_begin (uiout, "hw-rwpt");
4412 ui_out_field_int (uiout, "number", b->number);
4413 ui_out_text (uiout, ": ");
4414 print_expression (b->exp, stb->stream);
4415 ui_out_field_stream (uiout, "exp", stb);
4416 ui_out_tuple_end (uiout);
4418 case bp_access_watchpoint:
4419 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4420 ui_out_tuple_begin (uiout, "hw-awpt");
4421 ui_out_field_int (uiout, "number", b->number);
4422 ui_out_text (uiout, ": ");
4423 print_expression (b->exp, stb->stream);
4424 ui_out_field_stream (uiout, "exp", stb);
4425 ui_out_tuple_end (uiout);
4428 case bp_read_watchpoint:
4429 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4430 print_expression (b->exp, gdb_stdout);
4432 case bp_access_watchpoint:
4433 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4435 print_expression (b->exp, gdb_stdout);
4440 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4446 printf_filtered ("Breakpoint %d", b->number);
4449 case bp_hardware_breakpoint:
4451 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4457 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4461 case bp_catch_unload:
4462 printf_filtered ("Catchpoint %d (%s %s)",
4464 (b->type == bp_catch_load) ? "load" : "unload",
4465 (b->dll_pathname != NULL) ?
4466 b->dll_pathname : "<any library>");
4469 case bp_catch_vfork:
4470 printf_filtered ("Catchpoint %d (%s)",
4472 (b->type == bp_catch_fork) ? "fork" : "vfork");
4475 printf_filtered ("Catchpoint %d (exec)",
4478 case bp_catch_catch:
4479 case bp_catch_throw:
4480 printf_filtered ("Catchpoint %d (%s)",
4482 (b->type == bp_catch_catch) ? "catch" : "throw");
4488 case bp_longjmp_resume:
4489 case bp_step_resume:
4490 case bp_through_sigtramp:
4492 case bp_watchpoint_scope:
4493 case bp_shlib_event:
4494 case bp_thread_event:
4499 if (addressprint || b->source_file == NULL)
4501 printf_filtered (" at ");
4502 print_address_numeric (b->address, 1, gdb_stdout);
4505 printf_filtered (": file %s, line %d.",
4506 b->source_file, b->line_number);
4507 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4508 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4511 do_cleanups (old_chain);
4514 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4517 printf_filtered ("\n");
4521 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4522 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4523 COND[i] and COND_STRING[i] values.
4525 NOTE: If the function succeeds, the caller is expected to cleanup
4526 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4527 array contents). If the function fails (error() is called), the
4528 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4529 COND and SALS arrays and each of those arrays contents. */
4532 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4533 struct expression **cond, char **cond_string,
4534 enum bptype type, enum bpdisp disposition,
4535 int thread, int ignore_count, int from_tty)
4537 if (type == bp_hardware_breakpoint)
4539 int i = hw_breakpoint_used_count ();
4540 int target_resources_ok =
4541 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4543 if (target_resources_ok == 0)
4544 error ("No hardware breakpoint support in the target.");
4545 else if (target_resources_ok < 0)
4546 error ("Hardware breakpoints used exceeds limit.");
4549 /* Now set all the breakpoints. */
4552 for (i = 0; i < sals.nelts; i++)
4554 struct breakpoint *b;
4555 struct symtab_and_line sal = sals.sals[i];
4558 describe_other_breakpoints (sal.pc, sal.section);
4560 b = set_raw_breakpoint (sal, type);
4561 set_breakpoint_count (breakpoint_count + 1);
4562 b->number = breakpoint_count;
4565 b->addr_string = addr_string[i];
4566 b->cond_string = cond_string[i];
4567 b->ignore_count = ignore_count;
4568 b->enable = enabled;
4569 b->disposition = disposition;
4575 /* Parse ARG which is assumed to be a SAL specification possibly
4576 followed by conditionals. On return, SALS contains an array of SAL
4577 addresses found. ADDR_STRING contains a vector of (canonical)
4578 address strings. ARG points to the end of the SAL. */
4581 parse_breakpoint_sals (char **address,
4582 struct symtabs_and_lines *sals,
4583 char ***addr_string)
4585 char *addr_start = *address;
4586 *addr_string = NULL;
4587 /* If no arg given, or if first arg is 'if ', use the default
4589 if ((*address) == NULL
4590 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4592 if (default_breakpoint_valid)
4594 struct symtab_and_line sal;
4595 INIT_SAL (&sal); /* initialize to zeroes */
4596 sals->sals = (struct symtab_and_line *)
4597 xmalloc (sizeof (struct symtab_and_line));
4598 sal.pc = default_breakpoint_address;
4599 sal.line = default_breakpoint_line;
4600 sal.symtab = default_breakpoint_symtab;
4601 sal.section = find_pc_overlay (sal.pc);
4602 sals->sals[0] = sal;
4606 error ("No default breakpoint address now.");
4610 /* Force almost all breakpoints to be in terms of the
4611 current_source_symtab (which is decode_line_1's default). This
4612 should produce the results we want almost all of the time while
4613 leaving default_breakpoint_* alone. */
4614 if (default_breakpoint_valid
4615 && (!current_source_symtab
4616 || (strchr ("+-", (*address)[0]) != NULL)))
4617 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4618 default_breakpoint_line, addr_string);
4620 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4622 /* For any SAL that didn't have a canonical string, fill one in. */
4623 if (sals->nelts > 0 && *addr_string == NULL)
4624 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4625 if (addr_start != (*address))
4628 for (i = 0; i < sals->nelts; i++)
4630 /* Add the string if not present. */
4631 if ((*addr_string)[i] == NULL)
4632 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4638 /* Convert each SAL into a real PC. Verify that the PC can be
4639 inserted as a breakpoint. If it can't throw an error. */
4642 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4646 for (i = 0; i < sals->nelts; i++)
4648 resolve_sal_pc (&sals->sals[i]);
4650 /* It's possible for the PC to be nonzero, but still an illegal
4651 value on some targets.
4653 For example, on HP-UX if you start gdb, and before running the
4654 inferior you try to set a breakpoint on a shared library function
4655 "foo" where the inferior doesn't call "foo" directly but does
4656 pass its address to another function call, then we do find a
4657 minimal symbol for the "foo", but it's address is invalid.
4658 (Appears to be an index into a table that the loader sets up
4659 when the inferior is run.)
4661 Give the target a chance to bless sals.sals[i].pc before we
4662 try to make a breakpoint for it. */
4663 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4665 if (address == NULL)
4666 error ("Cannot break without a running program.");
4668 error ("Cannot break on %s without a running program.",
4674 /* Set a breakpoint according to ARG (function, linenum or *address)
4675 flag: first bit : 0 non-temporary, 1 temporary.
4676 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4679 break_command_1 (char *arg, int flag, int from_tty)
4681 int tempflag, hardwareflag;
4682 struct symtabs_and_lines sals;
4683 register struct expression **cond = 0;
4684 /* Pointers in arg to the start, and one past the end, of the
4686 char **cond_string = (char **) NULL;
4687 char *addr_start = arg;
4689 struct cleanup *old_chain;
4690 struct cleanup *breakpoint_chain = NULL;
4693 int ignore_count = 0;
4695 hardwareflag = flag & BP_HARDWAREFLAG;
4696 tempflag = flag & BP_TEMPFLAG;
4701 parse_breakpoint_sals (&arg, &sals, &addr_string);
4706 /* Create a chain of things that always need to be cleaned up. */
4707 old_chain = make_cleanup (null_cleanup, 0);
4709 /* Make sure that all storage allocated to SALS gets freed. */
4710 make_cleanup (xfree, sals.sals);
4712 /* Cleanup the addr_string array but not its contents. */
4713 make_cleanup (xfree, addr_string);
4715 /* Allocate space for all the cond expressions. */
4716 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4717 make_cleanup (xfree, cond);
4719 /* Allocate space for all the cond strings. */
4720 cond_string = xcalloc (sals.nelts, sizeof (char **));
4721 make_cleanup (xfree, cond_string);
4723 /* ----------------------------- SNIP -----------------------------
4724 Anything added to the cleanup chain beyond this point is assumed
4725 to be part of a breakpoint. If the breakpoint create succeeds
4726 then the memory is not reclaimed. */
4727 breakpoint_chain = make_cleanup (null_cleanup, 0);
4729 /* Mark the contents of the addr_string for cleanup. These go on
4730 the breakpoint_chain and only occure if the breakpoint create
4732 for (i = 0; i < sals.nelts; i++)
4734 if (addr_string[i] != NULL)
4735 make_cleanup (xfree, addr_string[i]);
4738 /* Resolve all line numbers to PC's and verify that the addresses
4739 are ok for the target. */
4740 breakpoint_sals_to_pc (&sals, addr_start);
4742 /* Verify that condition can be parsed, before setting any
4743 breakpoints. Allocate a separate condition expression for each
4745 thread = -1; /* No specific thread yet */
4746 for (i = 0; i < sals.nelts; i++)
4753 char *cond_start = NULL;
4754 char *cond_end = NULL;
4755 while (*tok == ' ' || *tok == '\t')
4760 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4763 toklen = end_tok - tok;
4765 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4767 tok = cond_start = end_tok + 1;
4768 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4769 make_cleanup (xfree, cond[i]);
4771 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4772 make_cleanup (xfree, cond_string[i]);
4774 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4780 thread = strtol (tok, &tok, 0);
4782 error ("Junk after thread keyword.");
4783 if (!valid_thread_id (thread))
4784 error ("Unknown thread %d\n", thread);
4787 error ("Junk at end of arguments.");
4791 create_breakpoints (sals, addr_string, cond, cond_string,
4792 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4793 tempflag ? del : donttouch,
4794 thread, ignore_count, from_tty);
4798 warning ("Multiple breakpoints were set.");
4799 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4801 /* That's it. Discard the cleanups for data inserted into the
4803 discard_cleanups (breakpoint_chain);
4804 /* But cleanup everything else. */
4805 do_cleanups (old_chain);
4808 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4809 linenum or *address) with COND and IGNORE_COUNT. */
4811 struct captured_breakpoint_args
4822 do_captured_breakpoint (void *data)
4824 struct captured_breakpoint_args *args = data;
4825 struct symtabs_and_lines sals;
4826 register struct expression **cond;
4827 struct cleanup *old_chain;
4828 struct cleanup *breakpoint_chain = NULL;
4835 /* Parse the source and lines spec. Delay check that the expression
4836 didn't contain trailing garbage until after cleanups are in
4840 address_end = args->address;
4842 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4847 /* Create a chain of things at always need to be cleaned up. */
4848 old_chain = make_cleanup (null_cleanup, 0);
4850 /* Always have a addr_string array, even if it is empty. */
4851 make_cleanup (xfree, addr_string);
4853 /* Make sure that all storage allocated to SALS gets freed. */
4854 make_cleanup (xfree, sals.sals);
4856 /* Allocate space for all the cond expressions. */
4857 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4858 make_cleanup (xfree, cond);
4860 /* Allocate space for all the cond strings. */
4861 cond_string = xcalloc (sals.nelts, sizeof (char **));
4862 make_cleanup (xfree, cond_string);
4864 /* ----------------------------- SNIP -----------------------------
4865 Anything added to the cleanup chain beyond this point is assumed
4866 to be part of a breakpoint. If the breakpoint create goes
4867 through then that memory is not cleaned up. */
4868 breakpoint_chain = make_cleanup (null_cleanup, 0);
4870 /* Mark the contents of the addr_string for cleanup. These go on
4871 the breakpoint_chain and only occure if the breakpoint create
4873 for (i = 0; i < sals.nelts; i++)
4875 if (addr_string[i] != NULL)
4876 make_cleanup (xfree, addr_string[i]);
4879 /* Wait until now before checking for garbage at the end of the
4880 address. That way cleanups can take care of freeing any
4882 if (*address_end != '\0')
4883 error ("Garbage %s following breakpoint address", address_end);
4885 /* Resolve all line numbers to PC's. */
4886 breakpoint_sals_to_pc (&sals, args->address);
4888 /* Verify that conditions can be parsed, before setting any
4890 for (i = 0; i < sals.nelts; i++)
4892 if (args->condition != NULL)
4894 char *tok = args->condition;
4895 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4897 error ("Garbage %s follows condition", tok);
4898 make_cleanup (xfree, cond[i]);
4899 cond_string[i] = xstrdup (args->condition);
4903 create_breakpoints (sals, addr_string, cond, cond_string,
4904 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4905 args->tempflag ? del : donttouch,
4906 args->thread, args->ignore_count, 0/*from-tty*/);
4908 /* That's it. Discard the cleanups for data inserted into the
4910 discard_cleanups (breakpoint_chain);
4911 /* But cleanup everything else. */
4912 do_cleanups (old_chain);
4917 gdb_breakpoint (char *address, char *condition,
4918 int hardwareflag, int tempflag,
4919 int thread, int ignore_count)
4921 struct captured_breakpoint_args args;
4922 args.address = address;
4923 args.condition = condition;
4924 args.hardwareflag = hardwareflag;
4925 args.tempflag = tempflag;
4926 args.thread = thread;
4927 args.ignore_count = ignore_count;
4928 return catch_errors (do_captured_breakpoint, &args,
4929 NULL, RETURN_MASK_ALL);
4934 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4936 struct frame_info *frame;
4937 CORE_ADDR low, high, selected_pc = 0;
4938 char *extra_args = NULL;
4941 int extra_args_len = 0, if_arg = 0;
4944 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4947 if (default_breakpoint_valid)
4951 selected_pc = selected_frame->pc;
4956 error ("No selected frame.");
4959 error ("No default breakpoint address now.");
4963 extra_args = strchr (arg, ' ');
4967 extra_args_len = strlen (extra_args);
4968 level_arg = (char *) xmalloc (extra_args - arg);
4969 strncpy (level_arg, arg, extra_args - arg - 1);
4970 level_arg[extra_args - arg - 1] = '\0';
4974 level_arg = (char *) xmalloc (strlen (arg) + 1);
4975 strcpy (level_arg, arg);
4978 frame = parse_frame_specification (level_arg);
4980 selected_pc = frame->pc;
4987 extra_args_len = strlen (arg);
4992 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
4994 addr_string = (char *) xmalloc (26 + extra_args_len);
4996 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
4998 sprintf (addr_string, "*0x%s", paddr_nz (high));
4999 break_command_1 (addr_string, flag, from_tty);
5000 xfree (addr_string);
5003 error ("No function contains the specified address");
5006 error ("Unable to set breakpoint at procedure exit");
5011 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5013 char *addr_string, *break_string, *beg_addr_string;
5014 CORE_ADDR low, high;
5015 struct symtabs_and_lines sals;
5016 struct symtab_and_line sal;
5017 struct cleanup *old_chain;
5018 char *extra_args = NULL;
5019 int extra_args_len = 0;
5023 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5025 if (default_breakpoint_valid)
5029 addr_string = (char *) xmalloc (15);
5030 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5035 error ("No selected frame.");
5038 error ("No default breakpoint address now.");
5042 addr_string = (char *) xmalloc (strlen (arg) + 1);
5043 strcpy (addr_string, arg);
5049 extra_args_len = strlen (arg);
5053 /* get the stuff after the function name or address */
5054 extra_args = strchr (arg, ' ');
5058 extra_args_len = strlen (extra_args);
5065 beg_addr_string = addr_string;
5066 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5069 xfree (beg_addr_string);
5070 old_chain = make_cleanup (xfree, sals.sals);
5071 for (i = 0; (i < sals.nelts); i++)
5074 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5076 break_string = (char *) xmalloc (extra_args_len + 26);
5078 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5080 sprintf (break_string, "*0x%s", paddr_nz (high));
5081 break_command_1 (break_string, flag, from_tty);
5082 xfree (break_string);
5085 error ("No function contains the specified address");
5089 warning ("Multiple breakpoints were set.\n");
5090 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5092 do_cleanups (old_chain);
5096 /* Helper function for break_command_1 and disassemble_command. */
5099 resolve_sal_pc (struct symtab_and_line *sal)
5103 if (sal->pc == 0 && sal->symtab != NULL)
5105 if (!find_line_pc (sal->symtab, sal->line, &pc))
5106 error ("No line %d in file \"%s\".",
5107 sal->line, sal->symtab->filename);
5111 if (sal->section == 0 && sal->symtab != NULL)
5113 struct blockvector *bv;
5118 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5121 b = BLOCKVECTOR_BLOCK (bv, index);
5122 sym = block_function (b);
5125 fixup_symbol_section (sym, sal->symtab->objfile);
5126 sal->section = SYMBOL_BFD_SECTION (sym);
5130 /* It really is worthwhile to have the section, so we'll just
5131 have to look harder. This case can be executed if we have
5132 line numbers but no functions (as can happen in assembly
5135 struct minimal_symbol *msym;
5137 msym = lookup_minimal_symbol_by_pc (sal->pc);
5139 sal->section = SYMBOL_BFD_SECTION (msym);
5146 break_command (char *arg, int from_tty)
5148 break_command_1 (arg, 0, from_tty);
5152 break_at_finish_command (char *arg, int from_tty)
5154 break_at_finish_command_1 (arg, 0, from_tty);
5158 break_at_finish_at_depth_command (char *arg, int from_tty)
5160 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5164 tbreak_command (char *arg, int from_tty)
5166 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5170 tbreak_at_finish_command (char *arg, int from_tty)
5172 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5176 hbreak_command (char *arg, int from_tty)
5178 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5182 thbreak_command (char *arg, int from_tty)
5184 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5188 stop_command (char *arg, int from_tty)
5190 printf_filtered ("Specify the type of breakpoint to set.\n\
5191 Usage: stop in <function | address>\n\
5196 stopin_command (char *arg, int from_tty)
5200 if (arg == (char *) NULL)
5202 else if (*arg != '*')
5207 /* look for a ':'. If this is a line number specification, then
5208 say it is bad, otherwise, it should be an address or
5209 function/method name */
5210 while (*argptr && !hasColon)
5212 hasColon = (*argptr == ':');
5217 badInput = (*argptr != ':'); /* Not a class::method */
5219 badInput = isdigit (*arg); /* a simple line number */
5223 printf_filtered ("Usage: stop in <function | address>\n");
5225 break_command_1 (arg, 0, from_tty);
5229 stopat_command (char *arg, int from_tty)
5233 if (arg == (char *) NULL || *arg == '*') /* no line number */
5240 /* look for a ':'. If there is a '::' then get out, otherwise
5241 it is probably a line number. */
5242 while (*argptr && !hasColon)
5244 hasColon = (*argptr == ':');
5249 badInput = (*argptr == ':'); /* we have class::method */
5251 badInput = !isdigit (*arg); /* not a line number */
5255 printf_filtered ("Usage: stop at <line>\n");
5257 break_command_1 (arg, 0, from_tty);
5261 /* accessflag: hw_write: watch write,
5262 hw_read: watch read,
5263 hw_access: watch access (read or write) */
5265 watch_command_1 (char *arg, int accessflag, int from_tty)
5267 struct breakpoint *b;
5268 struct symtab_and_line sal;
5269 struct expression *exp;
5270 struct block *exp_valid_block;
5271 struct value *val, *mark;
5272 struct frame_info *frame;
5273 struct frame_info *prev_frame = NULL;
5274 char *exp_start = NULL;
5275 char *exp_end = NULL;
5276 char *tok, *end_tok;
5278 char *cond_start = NULL;
5279 char *cond_end = NULL;
5280 struct expression *cond = NULL;
5281 int i, other_type_used, target_resources_ok = 0;
5282 enum bptype bp_type;
5285 INIT_SAL (&sal); /* initialize to zeroes */
5287 /* Parse arguments. */
5288 innermost_block = NULL;
5290 exp = parse_exp_1 (&arg, 0, 0);
5292 exp_valid_block = innermost_block;
5293 mark = value_mark ();
5294 val = evaluate_expression (exp);
5295 release_value (val);
5296 if (VALUE_LAZY (val))
5297 value_fetch_lazy (val);
5300 while (*tok == ' ' || *tok == '\t')
5304 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5307 toklen = end_tok - tok;
5308 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5310 tok = cond_start = end_tok + 1;
5311 cond = parse_exp_1 (&tok, 0, 0);
5315 error ("Junk at end of command.");
5317 if (accessflag == hw_read)
5318 bp_type = bp_read_watchpoint;
5319 else if (accessflag == hw_access)
5320 bp_type = bp_access_watchpoint;
5322 bp_type = bp_hardware_watchpoint;
5324 mem_cnt = can_use_hardware_watchpoint (val);
5325 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5326 error ("Expression cannot be implemented with read/access watchpoint.");
5329 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5330 target_resources_ok =
5331 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5333 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5334 error ("Target does not support this type of hardware watchpoint.");
5336 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5337 error ("Target can only support one kind of HW watchpoint at a time.");
5340 #if defined(HPUXHPPA)
5341 /* On HP-UX if you set a h/w
5342 watchpoint before the "run" command, the inferior dies with a e.g.,
5343 SIGILL once you start it. I initially believed this was due to a
5344 bad interaction between page protection traps and the initial
5345 startup sequence by the dynamic linker.
5347 However, I tried avoiding that by having HP-UX's implementation of
5348 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5349 yet, which forced slow watches before a "run" or "attach", and it
5350 still fails somewhere in the startup code.
5352 Until I figure out what's happening, I'm disallowing watches altogether
5353 before the "run" or "attach" command. We'll tell the user they must
5354 set watches after getting the program started. */
5355 if (!target_has_execution)
5357 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5360 #endif /* HPUXHPPA */
5362 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5363 watchpoint could not be set. */
5364 if (!mem_cnt || target_resources_ok <= 0)
5365 bp_type = bp_watchpoint;
5367 /* Now set up the breakpoint. */
5368 b = set_raw_breakpoint (sal, bp_type);
5369 set_breakpoint_count (breakpoint_count + 1);
5370 b->number = breakpoint_count;
5371 b->disposition = donttouch;
5373 b->exp_valid_block = exp_valid_block;
5374 b->exp_string = savestring (exp_start, exp_end - exp_start);
5378 b->cond_string = savestring (cond_start, cond_end - cond_start);
5382 frame = block_innermost_frame (exp_valid_block);
5385 prev_frame = get_prev_frame (frame);
5386 b->watchpoint_frame = frame->frame;
5389 b->watchpoint_frame = (CORE_ADDR) 0;
5391 /* If the expression is "local", then set up a "watchpoint scope"
5392 breakpoint at the point where we've left the scope of the watchpoint
5394 if (innermost_block)
5398 struct breakpoint *scope_breakpoint;
5399 struct symtab_and_line scope_sal;
5401 INIT_SAL (&scope_sal); /* initialize to zeroes */
5402 scope_sal.pc = get_frame_pc (prev_frame);
5403 scope_sal.section = find_pc_overlay (scope_sal.pc);
5405 scope_breakpoint = set_raw_breakpoint (scope_sal,
5406 bp_watchpoint_scope);
5407 set_breakpoint_count (breakpoint_count + 1);
5408 scope_breakpoint->number = breakpoint_count;
5410 scope_breakpoint->enable = enabled;
5412 /* Automatically delete the breakpoint when it hits. */
5413 scope_breakpoint->disposition = del;
5415 /* Only break in the proper frame (help with recursion). */
5416 scope_breakpoint->frame = prev_frame->frame;
5418 /* Set the address at which we will stop. */
5419 scope_breakpoint->address = get_frame_pc (prev_frame);
5421 /* The scope breakpoint is related to the watchpoint. We
5422 will need to act on them together. */
5423 b->related_breakpoint = scope_breakpoint;
5426 value_free_to_mark (mark);
5430 /* Return count of locations need to be watched and can be handled
5431 in hardware. If the watchpoint can not be handled
5432 in hardware return zero. */
5434 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5435 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5436 ((BYTE_SIZE) <= (REGISTER_SIZE))
5439 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5440 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5441 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5445 can_use_hardware_watchpoint (struct value *v)
5447 int found_memory_cnt = 0;
5448 struct value *head = v;
5450 /* Did the user specifically forbid us to use hardware watchpoints? */
5451 if (!can_use_hw_watchpoints)
5454 /* Make sure that the value of the expression depends only upon
5455 memory contents, and values computed from them within GDB. If we
5456 find any register references or function calls, we can't use a
5457 hardware watchpoint.
5459 The idea here is that evaluating an expression generates a series
5460 of values, one holding the value of every subexpression. (The
5461 expression a*b+c has five subexpressions: a, b, a*b, c, and
5462 a*b+c.) GDB's values hold almost enough information to establish
5463 the criteria given above --- they identify memory lvalues,
5464 register lvalues, computed values, etcetera. So we can evaluate
5465 the expression, and then scan the chain of values that leaves
5466 behind to decide whether we can detect any possible change to the
5467 expression's final value using only hardware watchpoints.
5469 However, I don't think that the values returned by inferior
5470 function calls are special in any way. So this function may not
5471 notice that an expression involving an inferior function call
5472 can't be watched with hardware watchpoints. FIXME. */
5473 for (; v; v = v->next)
5475 if (VALUE_LVAL (v) == lval_memory)
5478 /* A lazy memory lvalue is one that GDB never needed to fetch;
5479 we either just used its address (e.g., `a' in `a.b') or
5480 we never needed it at all (e.g., `a' in `a,b'). */
5484 /* Ahh, memory we actually used! Check if we can cover
5485 it with hardware watchpoints. */
5486 struct type *vtype = check_typedef (VALUE_TYPE (v));
5488 /* We only watch structs and arrays if user asked for it
5489 explicitly, never if they just happen to appear in a
5490 middle of some value chain. */
5492 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5493 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5495 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5496 int len = TYPE_LENGTH (VALUE_TYPE (v));
5498 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5505 else if (v->lval != not_lval && v->modifiable == 0)
5506 return 0; /* ??? What does this represent? */
5507 else if (v->lval == lval_register)
5508 return 0; /* cannot watch a register with a HW watchpoint */
5511 /* The expression itself looks suitable for using a hardware
5512 watchpoint, but give the target machine a chance to reject it. */
5513 return found_memory_cnt;
5518 watch_command_wrapper (char *arg, int from_tty)
5520 watch_command (arg, from_tty);
5524 watch_command (char *arg, int from_tty)
5526 watch_command_1 (arg, hw_write, from_tty);
5531 rwatch_command_wrapper (char *arg, int from_tty)
5533 rwatch_command (arg, from_tty);
5537 rwatch_command (char *arg, int from_tty)
5539 watch_command_1 (arg, hw_read, from_tty);
5544 awatch_command_wrapper (char *arg, int from_tty)
5546 awatch_command (arg, from_tty);
5550 awatch_command (char *arg, int from_tty)
5552 watch_command_1 (arg, hw_access, from_tty);
5556 /* Helper routines for the until_command routine in infcmd.c. Here
5557 because it uses the mechanisms of breakpoints. */
5559 /* This function is called by fetch_inferior_event via the
5560 cmd_continuation pointer, to complete the until command. It takes
5561 care of cleaning up the temporary breakpoints set up by the until
5564 until_break_command_continuation (struct continuation_arg *arg)
5566 struct cleanup *cleanups;
5568 cleanups = (struct cleanup *) arg->data.pointer;
5569 do_exec_cleanups (cleanups);
5574 until_break_command (char *arg, int from_tty)
5576 struct symtabs_and_lines sals;
5577 struct symtab_and_line sal;
5578 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5579 struct breakpoint *breakpoint;
5580 struct cleanup *old_chain;
5581 struct continuation_arg *arg1;
5584 clear_proceed_status ();
5586 /* Set a breakpoint where the user wants it and at return from
5589 if (default_breakpoint_valid)
5590 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5591 default_breakpoint_line, (char ***) NULL);
5593 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5594 0, (char ***) NULL);
5596 if (sals.nelts != 1)
5597 error ("Couldn't get information on specified line.");
5600 xfree (sals.sals); /* malloc'd, so freed */
5603 error ("Junk at end of arguments.");
5605 resolve_sal_pc (&sal);
5607 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5609 if (!event_loop_p || !target_can_async_p ())
5610 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5612 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5614 /* If we are running asynchronously, and the target supports async
5615 execution, we are not waiting for the target to stop, in the call
5616 tp proceed, below. This means that we cannot delete the
5617 brekpoints until the target has actually stopped. The only place
5618 where we get a chance to do that is in fetch_inferior_event, so
5619 we must set things up for that. */
5621 if (event_loop_p && target_can_async_p ())
5623 /* In this case the arg for the continuation is just the point
5624 in the exec_cleanups chain from where to start doing
5625 cleanups, because all the continuation does is the cleanups in
5626 the exec_cleanup_chain. */
5628 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5630 arg1->data.pointer = old_chain;
5632 add_continuation (until_break_command_continuation, arg1);
5635 /* Keep within the current frame */
5639 sal = find_pc_line (prev_frame->pc, 0);
5640 sal.pc = prev_frame->pc;
5641 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5642 if (!event_loop_p || !target_can_async_p ())
5643 make_cleanup_delete_breakpoint (breakpoint);
5645 make_exec_cleanup_delete_breakpoint (breakpoint);
5648 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5649 /* Do the cleanups now, anly if we are not running asynchronously,
5650 of if we are, but the target is still synchronous. */
5651 if (!event_loop_p || !target_can_async_p ())
5652 do_cleanups (old_chain);
5656 /* These aren't used; I don't konw what they were for. */
5657 /* Set a breakpoint at the catch clause for NAME. */
5659 catch_breakpoint (char *name)
5664 disable_catch_breakpoint (void)
5669 delete_catch_breakpoint (void)
5674 enable_catch_breakpoint (void)
5681 struct sal_chain *next;
5682 struct symtab_and_line sal;
5686 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5687 had been commented out in the v.4.16 sources, and stays
5688 disabled there now because "catch NAME" syntax isn't allowed.
5690 /* This isn't used; I don't know what it was for. */
5691 /* For each catch clause identified in ARGS, run FUNCTION
5692 with that clause as an argument. */
5693 static struct symtabs_and_lines
5694 map_catch_names (char *args, int (*function) ())
5696 register char *p = args;
5698 struct symtabs_and_lines sals;
5700 struct sal_chain *sal_chain = 0;
5704 error_no_arg ("one or more catch names");
5712 /* Don't swallow conditional part. */
5713 if (p1[0] == 'i' && p1[1] == 'f'
5714 && (p1[2] == ' ' || p1[2] == '\t'))
5720 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5724 if (*p1 && *p1 != ' ' && *p1 != '\t')
5725 error ("Arguments must be catch names.");
5731 struct sal_chain *next = (struct sal_chain *)
5732 alloca (sizeof (struct sal_chain));
5733 next->next = sal_chain;
5734 next->sal = get_catch_sal (p);
5739 printf_unfiltered ("No catch clause for exception %s.\n", p);
5744 while (*p == ' ' || *p == '\t')
5750 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5752 static struct symtabs_and_lines
5753 get_catch_sals (int this_level_only)
5755 register struct blockvector *bl;
5756 register struct block *block;
5757 int index, have_default = 0;
5759 struct symtabs_and_lines sals;
5760 struct sal_chain *sal_chain = 0;
5761 char *blocks_searched;
5763 /* Not sure whether an error message is always the correct response,
5764 but it's better than a core dump. */
5765 if (selected_frame == NULL)
5766 error ("No selected frame.");
5767 block = get_frame_block (selected_frame);
5768 pc = selected_frame->pc;
5774 error ("No symbol table info available.\n");
5776 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5777 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5778 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5782 CORE_ADDR end = BLOCK_END (block) - 4;
5785 if (bl != blockvector_for_pc (end, &index))
5786 error ("blockvector blotch");
5787 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5788 error ("blockvector botch");
5789 last_index = BLOCKVECTOR_NBLOCKS (bl);
5792 /* Don't print out blocks that have gone by. */
5793 while (index < last_index
5794 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5797 while (index < last_index
5798 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5800 if (blocks_searched[index] == 0)
5802 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5805 register struct symbol *sym;
5807 nsyms = BLOCK_NSYMS (b);
5809 for (i = 0; i < nsyms; i++)
5811 sym = BLOCK_SYM (b, i);
5812 if (STREQ (SYMBOL_NAME (sym), "default"))
5818 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5820 struct sal_chain *next = (struct sal_chain *)
5821 alloca (sizeof (struct sal_chain));
5822 next->next = sal_chain;
5823 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5828 blocks_searched[index] = 1;
5834 if (sal_chain && this_level_only)
5837 /* After handling the function's top-level block, stop.
5838 Don't continue to its superblock, the block of
5839 per-file symbols. */
5840 if (BLOCK_FUNCTION (block))
5842 block = BLOCK_SUPERBLOCK (block);
5847 struct sal_chain *tmp_chain;
5849 /* Count the number of entries. */
5850 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5851 tmp_chain = tmp_chain->next)
5855 sals.sals = (struct symtab_and_line *)
5856 xmalloc (index * sizeof (struct symtab_and_line));
5857 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5858 sals.sals[index] = sal_chain->sal;
5865 ep_skip_leading_whitespace (char **s)
5867 if ((s == NULL) || (*s == NULL))
5869 while (isspace (**s))
5873 /* This function examines a string, and attempts to find a token
5874 that might be an event name in the leading characters. If a
5875 possible match is found, a pointer to the last character of
5876 the token is returned. Else, NULL is returned. */
5879 ep_find_event_name_end (char *arg)
5882 char *event_name_end = NULL;
5884 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5888 /* We break out of the loop when we find a token delimiter.
5889 Basically, we're looking for alphanumerics and underscores;
5890 anything else delimites the token. */
5893 if (!isalnum (*s) && (*s != '_'))
5899 return event_name_end;
5903 /* This function attempts to parse an optional "if <cond>" clause
5904 from the arg string. If one is not found, it returns NULL.
5906 Else, it returns a pointer to the condition string. (It does not
5907 attempt to evaluate the string against a particular block.) And,
5908 it updates arg to point to the first character following the parsed
5909 if clause in the arg string. */
5912 ep_parse_optional_if_clause (char **arg)
5916 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5919 /* Skip the "if" keyword. */
5922 /* Skip any extra leading whitespace, and record the start of the
5923 condition string. */
5924 ep_skip_leading_whitespace (arg);
5927 /* Assume that the condition occupies the remainder of the arg string. */
5928 (*arg) += strlen (cond_string);
5933 /* This function attempts to parse an optional filename from the arg
5934 string. If one is not found, it returns NULL.
5936 Else, it returns a pointer to the parsed filename. (This function
5937 makes no attempt to verify that a file of that name exists, or is
5938 accessible.) And, it updates arg to point to the first character
5939 following the parsed filename in the arg string.
5941 Note that clients needing to preserve the returned filename for
5942 future access should copy it to their own buffers. */
5944 ep_parse_optional_filename (char **arg)
5946 static char filename[1024];
5951 if ((*arg_p == '\0') || isspace (*arg_p))
5969 /* Commands to deal with catching events, such as signals, exceptions,
5970 process start/exit, etc. */
5974 catch_fork, catch_vfork
5978 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5979 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5980 char *arg, int tempflag, int from_tty);
5983 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5986 char *cond_string = NULL;
5988 ep_skip_leading_whitespace (&arg);
5990 /* The allowed syntax is:
5992 catch [v]fork if <cond>
5994 First, check if there's an if clause. */
5995 cond_string = ep_parse_optional_if_clause (&arg);
5997 if ((*arg != '\0') && !isspace (*arg))
5998 error ("Junk at end of arguments.");
6000 /* If this target supports it, create a fork or vfork catchpoint
6001 and enable reporting of such events. */
6005 create_fork_event_catchpoint (tempflag, cond_string);
6008 create_vfork_event_catchpoint (tempflag, cond_string);
6011 error ("unsupported or unknown fork kind; cannot catch it");
6017 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6019 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6021 char *cond_string = NULL;
6023 ep_skip_leading_whitespace (&arg);
6025 /* The allowed syntax is:
6027 catch exec if <cond>
6029 First, check if there's an if clause. */
6030 cond_string = ep_parse_optional_if_clause (&arg);
6032 if ((*arg != '\0') && !isspace (*arg))
6033 error ("Junk at end of arguments.");
6035 /* If this target supports it, create an exec catchpoint
6036 and enable reporting of such events. */
6037 create_exec_event_catchpoint (tempflag, cond_string);
6041 #if defined(SOLIB_ADD)
6043 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6045 char *dll_pathname = NULL;
6046 char *cond_string = NULL;
6048 ep_skip_leading_whitespace (&arg);
6050 /* The allowed syntax is:
6052 catch load if <cond>
6053 catch load <filename>
6054 catch load <filename> if <cond>
6056 The user is not allowed to specify the <filename> after an
6059 We'll ignore the pathological case of a file named "if".
6061 First, check if there's an if clause. If so, then there
6062 cannot be a filename. */
6063 cond_string = ep_parse_optional_if_clause (&arg);
6065 /* If there was an if clause, then there cannot be a filename.
6066 Else, there might be a filename and an if clause. */
6067 if (cond_string == NULL)
6069 dll_pathname = ep_parse_optional_filename (&arg);
6070 ep_skip_leading_whitespace (&arg);
6071 cond_string = ep_parse_optional_if_clause (&arg);
6074 if ((*arg != '\0') && !isspace (*arg))
6075 error ("Junk at end of arguments.");
6077 /* Create a load breakpoint that only triggers when a load of
6078 the specified dll (or any dll, if no pathname was specified)
6080 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6081 dll_pathname, cond_string);
6085 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6087 char *dll_pathname = NULL;
6088 char *cond_string = NULL;
6090 ep_skip_leading_whitespace (&arg);
6092 /* The allowed syntax is:
6094 catch unload if <cond>
6095 catch unload <filename>
6096 catch unload <filename> if <cond>
6098 The user is not allowed to specify the <filename> after an
6101 We'll ignore the pathological case of a file named "if".
6103 First, check if there's an if clause. If so, then there
6104 cannot be a filename. */
6105 cond_string = ep_parse_optional_if_clause (&arg);
6107 /* If there was an if clause, then there cannot be a filename.
6108 Else, there might be a filename and an if clause. */
6109 if (cond_string == NULL)
6111 dll_pathname = ep_parse_optional_filename (&arg);
6112 ep_skip_leading_whitespace (&arg);
6113 cond_string = ep_parse_optional_if_clause (&arg);
6116 if ((*arg != '\0') && !isspace (*arg))
6117 error ("Junk at end of arguments.");
6119 /* Create an unload breakpoint that only triggers when an unload of
6120 the specified dll (or any dll, if no pathname was specified)
6122 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6123 dll_pathname, cond_string);
6125 #endif /* SOLIB_ADD */
6127 /* Commands to deal with catching exceptions. */
6129 /* Set a breakpoint at the specified callback routine for an
6130 exception event callback */
6133 create_exception_catchpoint (int tempflag, char *cond_string,
6134 enum exception_event_kind ex_event,
6135 struct symtab_and_line *sal)
6137 struct breakpoint *b;
6138 int thread = -1; /* All threads. */
6141 if (!sal) /* no exception support? */
6146 case EX_EVENT_THROW:
6147 bptype = bp_catch_throw;
6149 case EX_EVENT_CATCH:
6150 bptype = bp_catch_catch;
6152 default: /* error condition */
6153 error ("Internal error -- invalid catchpoint kind");
6156 b = set_raw_breakpoint (*sal, bptype);
6157 set_breakpoint_count (breakpoint_count + 1);
6158 b->number = breakpoint_count;
6160 b->cond_string = (cond_string == NULL) ?
6161 NULL : savestring (cond_string, strlen (cond_string));
6163 b->addr_string = NULL;
6164 b->enable = enabled;
6165 b->disposition = tempflag ? del : donttouch;
6169 /* Deal with "catch catch" and "catch throw" commands */
6172 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6173 int tempflag, int from_tty)
6175 char *cond_string = NULL;
6176 struct symtab_and_line *sal = NULL;
6178 ep_skip_leading_whitespace (&arg);
6180 cond_string = ep_parse_optional_if_clause (&arg);
6182 if ((*arg != '\0') && !isspace (*arg))
6183 error ("Junk at end of arguments.");
6185 if ((ex_event != EX_EVENT_THROW) &&
6186 (ex_event != EX_EVENT_CATCH))
6187 error ("Unsupported or unknown exception event; cannot catch it");
6189 /* See if we can find a callback routine */
6190 sal = target_enable_exception_callback (ex_event, 1);
6194 /* We have callbacks from the runtime system for exceptions.
6195 Set a breakpoint on the sal found, if no errors */
6196 if (sal != (struct symtab_and_line *) -1)
6197 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6199 return; /* something went wrong with setting up callbacks */
6203 /* No callbacks from runtime system for exceptions.
6204 Try GNU C++ exception breakpoints using labels in debug info. */
6205 if (ex_event == EX_EVENT_CATCH)
6207 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6209 else if (ex_event == EX_EVENT_THROW)
6211 /* Set a breakpoint on __raise_exception () */
6213 warning ("Unsupported with this platform/compiler combination.");
6214 warning ("Perhaps you can achieve the effect you want by setting");
6215 warning ("a breakpoint on __raise_exception().");
6220 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6221 inside a catch_errors */
6224 cover_target_enable_exception_callback (PTR arg)
6226 args_for_catchpoint_enable *args = arg;
6227 struct symtab_and_line *sal;
6228 sal = target_enable_exception_callback (args->kind, args->enable);
6231 else if (sal == (struct symtab_and_line *) -1)
6234 return 1; /*is valid */
6239 /* This is the original v.4.16 and earlier version of the
6240 catch_command_1() function. Now that other flavours of "catch"
6241 have been introduced, and since exception handling can be handled
6242 in other ways (through target ops) also, this is used only for the
6243 GNU C++ exception handling system.
6244 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6245 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6246 there was no code in GDB 4.16 for "catch throw".
6248 Called from catch_exception_command_1 () */
6252 handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
6254 /* First, translate ARG into something we can deal with in terms
6257 struct symtabs_and_lines sals;
6258 struct symtab_and_line sal;
6259 register struct expression *cond = 0;
6260 register struct breakpoint *b;
6264 INIT_SAL (&sal); /* initialize to zeroes */
6266 /* If no arg given, or if first arg is 'if ', all active catch clauses
6267 are breakpointed. */
6269 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6270 && (arg[2] == ' ' || arg[2] == '\t')))
6272 /* Grab all active catch clauses. */
6273 sals = get_catch_sals (0);
6277 /* Grab selected catch clauses. */
6278 error ("catch NAME not implemented");
6281 /* Not sure why this code has been disabled. I'm leaving
6282 it disabled. We can never come here now anyway
6283 since we don't allow the "catch NAME" syntax.
6286 /* This isn't used; I don't know what it was for. */
6287 sals = map_catch_names (arg, catch_breakpoint);
6295 for (i = 0; i < sals.nelts; i++)
6297 resolve_sal_pc (&sals.sals[i]);
6301 if (arg[0] == 'i' && arg[1] == 'f'
6302 && (arg[2] == ' ' || arg[2] == '\t'))
6303 cond = parse_exp_1 ((arg += 2, &arg),
6304 block_for_pc (sals.sals[i].pc), 0);
6306 error ("Junk at end of arguments.");
6311 for (i = 0; i < sals.nelts; i++)
6316 describe_other_breakpoints (sal.pc, sal.section);
6318 /* Important -- this is an ordinary breakpoint. For platforms
6319 with callback support for exceptions,
6320 create_exception_catchpoint() will create special bp types
6321 (bp_catch_catch and bp_catch_throw), and there is code in
6322 insert_breakpoints() and elsewhere that depends on that. */
6323 b = set_raw_breakpoint (sal, bp_breakpoint);
6324 set_breakpoint_count (breakpoint_count + 1);
6325 b->number = breakpoint_count;
6328 b->enable = enabled;
6329 b->disposition = tempflag ? del : donttouch;
6336 warning ("Multiple breakpoints were set.");
6337 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6343 /* This creates a temporary internal breakpoint
6344 just to placate infrun */
6345 static struct breakpoint *
6346 create_temp_exception_breakpoint (CORE_ADDR pc)
6348 struct symtab_and_line sal;
6349 struct breakpoint *b;
6356 b = set_raw_breakpoint (sal, bp_breakpoint);
6358 b->disposition = del;
6359 b->enable = enabled;
6361 b->number = internal_breakpoint_number--;
6367 catch_command_1 (char *arg, int tempflag, int from_tty)
6370 /* The first argument may be an event name, such as "start" or "load".
6371 If so, then handle it as such. If it doesn't match an event name,
6372 then attempt to interpret it as an exception name. (This latter is
6373 the v4.16-and-earlier GDB meaning of the "catch" command.)
6375 First, try to find the bounds of what might be an event name. */
6376 char *arg1_start = arg;
6380 if (arg1_start == NULL)
6382 /* Old behaviour was to use pre-v-4.16 syntax */
6383 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6385 /* Now, this is not allowed */
6386 error ("Catch requires an event name.");
6389 arg1_end = ep_find_event_name_end (arg1_start);
6390 if (arg1_end == NULL)
6391 error ("catch requires an event");
6392 arg1_length = arg1_end + 1 - arg1_start;
6394 /* Try to match what we found against known event names. */
6395 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6397 error ("Catch of signal not yet implemented");
6399 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6401 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6402 tempflag, from_tty);
6404 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6406 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6407 tempflag, from_tty);
6409 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6411 error ("Catch of thread_start not yet implemented");
6413 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6415 error ("Catch of thread_exit not yet implemented");
6417 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6419 error ("Catch of thread_join not yet implemented");
6421 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6423 error ("Catch of start not yet implemented");
6425 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6427 error ("Catch of exit not yet implemented");
6429 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6431 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6432 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6434 error ("Catch of fork not yet implemented");
6437 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6439 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6440 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6442 error ("Catch of vfork not yet implemented");
6445 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6447 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6448 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6450 error ("Catch of exec not yet implemented");
6453 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6455 #if defined(SOLIB_ADD)
6456 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6458 error ("Catch of load not implemented");
6461 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6463 #if defined(SOLIB_ADD)
6464 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6466 error ("Catch of load not implemented");
6469 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6471 error ("Catch of stop not yet implemented");
6474 /* This doesn't appear to be an event name */
6478 /* Pre-v.4.16 behaviour was to treat the argument
6479 as the name of an exception */
6480 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6481 /* Now this is not allowed */
6482 error ("Unknown event kind specified for catch");
6487 /* Used by the gui, could be made a worker for other things. */
6490 set_breakpoint_sal (struct symtab_and_line sal)
6492 struct breakpoint *b;
6493 b = set_raw_breakpoint (sal, bp_breakpoint);
6494 set_breakpoint_count (breakpoint_count + 1);
6495 b->number = breakpoint_count;
6502 /* These aren't used; I don't know what they were for. */
6503 /* Disable breakpoints on all catch clauses described in ARGS. */
6505 disable_catch (char *args)
6507 /* Map the disable command to catch clauses described in ARGS. */
6510 /* Enable breakpoints on all catch clauses described in ARGS. */
6512 enable_catch (char *args)
6514 /* Map the disable command to catch clauses described in ARGS. */
6517 /* Delete breakpoints on all catch clauses in the active scope. */
6519 delete_catch (char *args)
6521 /* Map the delete command to catch clauses described in ARGS. */
6526 catch_command (char *arg, int from_tty)
6528 catch_command_1 (arg, 0, from_tty);
6533 tcatch_command (char *arg, int from_tty)
6535 catch_command_1 (arg, 1, from_tty);
6540 clear_command (char *arg, int from_tty)
6542 register struct breakpoint *b, *b1;
6544 struct symtabs_and_lines sals;
6545 struct symtab_and_line sal;
6546 register struct breakpoint *found;
6551 sals = decode_line_spec (arg, 1);
6556 sals.sals = (struct symtab_and_line *)
6557 xmalloc (sizeof (struct symtab_and_line));
6558 INIT_SAL (&sal); /* initialize to zeroes */
6559 sal.line = default_breakpoint_line;
6560 sal.symtab = default_breakpoint_symtab;
6561 sal.pc = default_breakpoint_address;
6562 if (sal.symtab == 0)
6563 error ("No source file specified.");
6571 /* For each line spec given, delete bps which correspond
6572 to it. We do this in two loops: the first loop looks at
6573 the initial bp(s) in the chain which should be deleted,
6574 the second goes down the rest of the chain looking ahead
6575 one so it can take those bps off the chain without messing
6579 for (i = 0; i < sals.nelts; i++)
6581 /* If exact pc given, clear bpts at that pc.
6582 If line given (pc == 0), clear all bpts on specified line.
6583 If defaulting, clear all bpts on default line
6586 defaulting sal.pc != 0 tests to do
6591 1 0 <can't happen> */
6594 found = (struct breakpoint *) 0;
6597 while (breakpoint_chain
6598 /* Why don't we check here that this is not
6599 a watchpoint, etc., as we do below?
6600 I can't make it fail, but don't know
6601 what's stopping the failure: a watchpoint
6602 of the same address as "sal.pc" should
6603 wind up being deleted. */
6605 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6606 (overlay_debugging == 0 ||
6607 breakpoint_chain->section == sal.section))
6608 || ((default_match || (0 == sal.pc))
6609 && breakpoint_chain->source_file != NULL
6610 && sal.symtab != NULL
6611 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6612 && breakpoint_chain->line_number == sal.line)))
6615 b1 = breakpoint_chain;
6616 breakpoint_chain = b1->next;
6624 && b->next->type != bp_none
6625 && b->next->type != bp_watchpoint
6626 && b->next->type != bp_hardware_watchpoint
6627 && b->next->type != bp_read_watchpoint
6628 && b->next->type != bp_access_watchpoint
6629 && (((sal.pc && (b->next->address == sal.pc)) &&
6630 (overlay_debugging == 0 ||
6631 b->next->section == sal.section))
6632 || ((default_match || (0 == sal.pc))
6633 && b->next->source_file != NULL
6634 && sal.symtab != NULL
6635 && STREQ (b->next->source_file, sal.symtab->filename)
6636 && b->next->line_number == sal.line)))
6649 error ("No breakpoint at %s.", arg);
6651 error ("No breakpoint at this line.");
6655 from_tty = 1; /* Always report if deleted more than one */
6657 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6658 breakpoints_changed ();
6662 printf_unfiltered ("%d ", found->number);
6664 delete_breakpoint (found);
6668 putchar_unfiltered ('\n');
6673 /* Delete breakpoint in BS if they are `delete' breakpoints and
6674 all breakpoints that are marked for deletion, whether hit or not.
6675 This is called after any breakpoint is hit, or after errors. */
6678 breakpoint_auto_delete (bpstat bs)
6680 struct breakpoint *b, *temp;
6682 for (; bs; bs = bs->next)
6683 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6685 delete_breakpoint (bs->breakpoint_at);
6687 ALL_BREAKPOINTS_SAFE (b, temp)
6689 if (b->disposition == del_at_next_stop)
6690 delete_breakpoint (b);
6694 /* Delete a breakpoint and clean up all traces of it in the data
6698 delete_breakpoint (struct breakpoint *bpt)
6700 register struct breakpoint *b;
6704 error ("Internal error (attempted to delete a NULL breakpoint)");
6707 /* Has this bp already been deleted? This can happen because multiple
6708 lists can hold pointers to bp's. bpstat lists are especial culprits.
6710 One example of this happening is a watchpoint's scope bp. When the
6711 scope bp triggers, we notice that the watchpoint is out of scope, and
6712 delete it. We also delete its scope bp. But the scope bp is marked
6713 "auto-deleting", and is already on a bpstat. That bpstat is then
6714 checked for auto-deleting bp's, which are deleted.
6716 A real solution to this problem might involve reference counts in bp's,
6717 and/or giving them pointers back to their referencing bpstat's, and
6718 teaching delete_breakpoint to only free a bp's storage when no more
6719 references were extent. A cheaper bandaid was chosen. */
6720 if (bpt->type == bp_none)
6723 if (delete_breakpoint_hook)
6724 delete_breakpoint_hook (bpt);
6725 breakpoint_delete_event (bpt->number);
6728 remove_breakpoint (bpt, mark_uninserted);
6730 if (breakpoint_chain == bpt)
6731 breakpoint_chain = bpt->next;
6733 /* If we have callback-style exception catchpoints, don't go through
6734 the adjustments to the C++ runtime library etc. if the inferior
6735 isn't actually running. target_enable_exception_callback for a
6736 null target ops vector gives an undesirable error message, so we
6737 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6738 exceptions are supported in this way, it's OK for now. FIXME */
6739 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6741 static char message1[] = "Error in deleting catchpoint %d:\n";
6742 static char message[sizeof (message1) + 30];
6743 args_for_catchpoint_enable args;
6745 /* Format possible error msg */
6746 sprintf (message, message1, bpt->number);
6747 args.kind = bpt->type == bp_catch_catch ?
6748 EX_EVENT_CATCH : EX_EVENT_THROW;
6750 catch_errors (cover_target_enable_exception_callback, &args,
6751 message, RETURN_MASK_ALL);
6758 b->next = bpt->next;
6762 /* Before turning off the visuals for the bp, check to see that
6763 there are no other bps at the same address. */
6770 clearIt = (b->address != bpt->address);
6777 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6778 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6782 check_duplicates (bpt);
6783 /* If this breakpoint was inserted, and there is another breakpoint
6784 at the same address, we need to insert the other breakpoint. */
6786 && bpt->type != bp_hardware_watchpoint
6787 && bpt->type != bp_read_watchpoint
6788 && bpt->type != bp_access_watchpoint
6789 && bpt->type != bp_catch_fork
6790 && bpt->type != bp_catch_vfork
6791 && bpt->type != bp_catch_exec)
6794 if (b->address == bpt->address
6795 && b->section == bpt->section
6797 && b->enable != disabled
6798 && b->enable != shlib_disabled
6799 && b->enable != call_disabled)
6803 /* We should never reach this point if there is a permanent
6804 breakpoint at the same address as the one being deleted.
6805 If there is a permanent breakpoint somewhere, it should
6806 always be the only one inserted. */
6807 if (b->enable == permanent)
6808 internal_error (__FILE__, __LINE__,
6809 "another breakpoint was inserted on top of "
6810 "a permanent breakpoint");
6812 if (b->type == bp_hardware_breakpoint)
6813 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6815 val = target_insert_breakpoint (b->address, b->shadow_contents);
6819 target_terminal_ours_for_output ();
6820 warning ("Cannot insert breakpoint %d:", b->number);
6821 memory_error (val, b->address); /* which bombs us out */
6828 free_command_lines (&bpt->commands);
6831 if (bpt->cond_string != NULL)
6832 xfree (bpt->cond_string);
6833 if (bpt->addr_string != NULL)
6834 xfree (bpt->addr_string);
6835 if (bpt->exp != NULL)
6837 if (bpt->exp_string != NULL)
6838 xfree (bpt->exp_string);
6839 if (bpt->val != NULL)
6840 value_free (bpt->val);
6841 if (bpt->source_file != NULL)
6842 xfree (bpt->source_file);
6843 if (bpt->dll_pathname != NULL)
6844 xfree (bpt->dll_pathname);
6845 if (bpt->triggered_dll_pathname != NULL)
6846 xfree (bpt->triggered_dll_pathname);
6847 if (bpt->exec_pathname != NULL)
6848 xfree (bpt->exec_pathname);
6850 /* Be sure no bpstat's are pointing at it after it's been freed. */
6851 /* FIXME, how can we find all bpstat's?
6852 We just check stop_bpstat for now. */
6853 for (bs = stop_bpstat; bs; bs = bs->next)
6854 if (bs->breakpoint_at == bpt)
6856 bs->breakpoint_at = NULL;
6858 /* we'd call bpstat_clear_actions, but that free's stuff and due
6859 to the multiple pointers pointing to one item with no
6860 reference counts found anywhere through out the bpstat's (how
6861 do you spell fragile?), we don't want to free things twice --
6862 better a memory leak than a corrupt malloc pool! */
6863 bs->commands = NULL;
6866 /* On the chance that someone will soon try again to delete this same
6867 bp, we mark it as deleted before freeing its storage. */
6868 bpt->type = bp_none;
6874 do_delete_breakpoint_cleanup (void *b)
6876 delete_breakpoint (b);
6880 make_cleanup_delete_breakpoint (struct breakpoint *b)
6882 return make_cleanup (do_delete_breakpoint_cleanup, b);
6886 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6888 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6892 delete_command (char *arg, int from_tty)
6894 struct breakpoint *b, *temp;
6898 int breaks_to_delete = 0;
6900 /* Delete all breakpoints if no argument.
6901 Do not delete internal or call-dummy breakpoints, these
6902 have to be deleted with an explicit breakpoint number argument. */
6905 if (b->type != bp_call_dummy &&
6906 b->type != bp_shlib_event &&
6907 b->type != bp_thread_event &&
6909 breaks_to_delete = 1;
6912 /* Ask user only if there are some breakpoints to delete. */
6914 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6916 ALL_BREAKPOINTS_SAFE (b, temp)
6918 if (b->type != bp_call_dummy &&
6919 b->type != bp_shlib_event &&
6920 b->type != bp_thread_event &&
6922 delete_breakpoint (b);
6927 map_breakpoint_numbers (arg, delete_breakpoint);
6930 /* Reset a breakpoint given it's struct breakpoint * BINT.
6931 The value we return ends up being the return value from catch_errors.
6932 Unused in this case. */
6935 breakpoint_re_set_one (PTR bint)
6937 /* get past catch_errs */
6938 struct breakpoint *b = (struct breakpoint *) bint;
6941 struct symtabs_and_lines sals;
6943 enum enable save_enable;
6948 warning ("attempted to reset apparently deleted breakpoint #%d?",
6952 case bp_hardware_breakpoint:
6954 case bp_catch_unload:
6955 if (b->addr_string == NULL)
6957 /* Anything without a string can't be re-set. */
6958 delete_breakpoint (b);
6961 /* In case we have a problem, disable this breakpoint. We'll restore
6962 its status if we succeed. */
6963 save_enable = b->enable;
6964 b->enable = disabled;
6966 set_language (b->language);
6967 input_radix = b->input_radix;
6969 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6970 for (i = 0; i < sals.nelts; i++)
6972 resolve_sal_pc (&sals.sals[i]);
6974 /* Reparse conditions, they might contain references to the
6976 if (b->cond_string != NULL)
6981 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6984 /* We need to re-set the breakpoint if the address changes... */
6985 if (b->address != sals.sals[i].pc
6986 /* ...or new and old breakpoints both have source files, and
6987 the source file name or the line number changes... */
6988 || (b->source_file != NULL
6989 && sals.sals[i].symtab != NULL
6990 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6991 || b->line_number != sals.sals[i].line)
6993 /* ...or we switch between having a source file and not having
6995 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6998 if (b->source_file != NULL)
6999 xfree (b->source_file);
7000 if (sals.sals[i].symtab == NULL)
7001 b->source_file = NULL;
7004 savestring (sals.sals[i].symtab->filename,
7005 strlen (sals.sals[i].symtab->filename));
7006 b->line_number = sals.sals[i].line;
7007 b->address = sals.sals[i].pc;
7009 /* Used to check for duplicates here, but that can
7010 cause trouble, as it doesn't check for disable
7015 /* Might be better to do this just once per breakpoint_re_set,
7016 rather than once for every breakpoint. */
7017 breakpoints_changed ();
7019 b->section = sals.sals[i].section;
7020 b->enable = save_enable; /* Restore it, this worked. */
7023 /* Now that this is re-enabled, check_duplicates
7025 check_duplicates (b);
7032 case bp_hardware_watchpoint:
7033 case bp_read_watchpoint:
7034 case bp_access_watchpoint:
7035 innermost_block = NULL;
7036 /* The issue arises of what context to evaluate this in. The
7037 same one as when it was set, but what does that mean when
7038 symbols have been re-read? We could save the filename and
7039 functionname, but if the context is more local than that, the
7040 best we could do would be something like how many levels deep
7041 and which index at that particular level, but that's going to
7042 be less stable than filenames or function names. */
7044 /* So for now, just use a global context. */
7047 b->exp = parse_expression (b->exp_string);
7048 b->exp_valid_block = innermost_block;
7049 mark = value_mark ();
7051 value_free (b->val);
7052 b->val = evaluate_expression (b->exp);
7053 release_value (b->val);
7054 if (VALUE_LAZY (b->val))
7055 value_fetch_lazy (b->val);
7057 if (b->cond_string != NULL)
7062 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7064 if (b->enable == enabled)
7066 value_free_to_mark (mark);
7068 case bp_catch_catch:
7069 case bp_catch_throw:
7071 /* We needn't really do anything to reset these, since the mask
7072 that requests them is unaffected by e.g., new libraries being
7075 case bp_catch_vfork:
7080 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7082 /* Delete longjmp breakpoints, they will be reset later by
7083 breakpoint_re_set. */
7085 case bp_longjmp_resume:
7086 delete_breakpoint (b);
7089 /* This breakpoint is special, it's set up when the inferior
7090 starts and we really don't want to touch it. */
7091 case bp_shlib_event:
7093 /* Like bp_shlib_event, this breakpoint type is special.
7094 Once it is set up, we do not want to touch it. */
7095 case bp_thread_event:
7097 /* Keep temporary breakpoints, which can be encountered when we step
7098 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7099 Otherwise these should have been blown away via the cleanup chain
7100 or by breakpoint_init_inferior when we rerun the executable. */
7103 case bp_watchpoint_scope:
7105 case bp_step_resume:
7112 /* Re-set all breakpoints after symbols have been re-loaded. */
7114 breakpoint_re_set (void)
7116 struct breakpoint *b, *temp;
7117 enum language save_language;
7118 int save_input_radix;
7119 static char message1[] = "Error in re-setting breakpoint %d:\n";
7120 char message[sizeof (message1) + 30 /* slop */ ];
7122 save_language = current_language->la_language;
7123 save_input_radix = input_radix;
7124 ALL_BREAKPOINTS_SAFE (b, temp)
7126 /* Format possible error msg */
7127 sprintf (message, message1, b->number);
7128 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7130 set_language (save_language);
7131 input_radix = save_input_radix;
7133 #ifdef GET_LONGJMP_TARGET
7134 create_longjmp_breakpoint ("longjmp");
7135 create_longjmp_breakpoint ("_longjmp");
7136 create_longjmp_breakpoint ("siglongjmp");
7137 create_longjmp_breakpoint ("_siglongjmp");
7138 create_longjmp_breakpoint (NULL);
7142 /* Took this out (temporarily at least), since it produces an extra
7143 blank line at startup. This messes up the gdbtests. -PB */
7144 /* Blank line to finish off all those mention() messages we just printed. */
7145 printf_filtered ("\n");
7149 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7150 If from_tty is nonzero, it prints a message to that effect,
7151 which ends with a period (no newline). */
7153 /* Reset the thread number of this breakpoint:
7155 - If the breakpoint is for all threads, leave it as-is.
7156 - Else, reset it to the current thread for inferior_ptid. */
7158 breakpoint_re_set_thread (struct breakpoint *b)
7160 if (b->thread != -1)
7162 if (in_thread_list (inferior_ptid))
7163 b->thread = pid_to_thread_id (inferior_ptid);
7168 set_ignore_count (int bptnum, int count, int from_tty)
7170 register struct breakpoint *b;
7176 if (b->number == bptnum)
7178 b->ignore_count = count;
7181 else if (count == 0)
7182 printf_filtered ("Will stop next time breakpoint %d is reached.",
7184 else if (count == 1)
7185 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7188 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7190 breakpoints_changed ();
7194 error ("No breakpoint number %d.", bptnum);
7197 /* Clear the ignore counts of all breakpoints. */
7199 breakpoint_clear_ignore_counts (void)
7201 struct breakpoint *b;
7204 b->ignore_count = 0;
7207 /* Command to set ignore-count of breakpoint N to COUNT. */
7210 ignore_command (char *args, int from_tty)
7216 error_no_arg ("a breakpoint number");
7218 num = get_number (&p);
7220 error ("bad breakpoint number: '%s'", args);
7222 error ("Second argument (specified ignore-count) is missing.");
7224 set_ignore_count (num,
7225 longest_to_int (value_as_long (parse_and_eval (p))),
7227 printf_filtered ("\n");
7228 breakpoints_changed ();
7231 /* Call FUNCTION on each of the breakpoints
7232 whose numbers are given in ARGS. */
7235 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7237 register char *p = args;
7240 register struct breakpoint *b, *tmp;
7244 error_no_arg ("one or more breakpoint numbers");
7251 num = get_number_or_range (&p1);
7254 warning ("bad breakpoint number at or near '%s'", p);
7258 ALL_BREAKPOINTS_SAFE (b, tmp)
7259 if (b->number == num)
7261 struct breakpoint *related_breakpoint = b->related_breakpoint;
7264 if (related_breakpoint)
7265 function (related_breakpoint);
7269 printf_unfiltered ("No breakpoint number %d.\n", num);
7276 disable_breakpoint (struct breakpoint *bpt)
7278 /* Never disable a watchpoint scope breakpoint; we want to
7279 hit them when we leave scope so we can delete both the
7280 watchpoint and its scope breakpoint at that time. */
7281 if (bpt->type == bp_watchpoint_scope)
7284 /* You can't disable permanent breakpoints. */
7285 if (bpt->enable == permanent)
7288 bpt->enable = disabled;
7290 check_duplicates (bpt);
7292 if (modify_breakpoint_hook)
7293 modify_breakpoint_hook (bpt);
7294 breakpoint_modify_event (bpt->number);
7299 disable_command (char *args, int from_tty)
7301 register struct breakpoint *bpt;
7303 ALL_BREAKPOINTS (bpt)
7307 warning ("attempted to disable apparently deleted breakpoint #%d?",
7312 case bp_catch_unload:
7314 case bp_catch_vfork:
7316 case bp_catch_catch:
7317 case bp_catch_throw:
7318 case bp_hardware_breakpoint:
7320 case bp_hardware_watchpoint:
7321 case bp_read_watchpoint:
7322 case bp_access_watchpoint:
7323 disable_breakpoint (bpt);
7328 map_breakpoint_numbers (args, disable_breakpoint);
7332 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7334 struct frame_info *save_selected_frame = NULL;
7335 int save_selected_frame_level = -1;
7336 int target_resources_ok, other_type_used;
7339 if (bpt->type == bp_hardware_breakpoint)
7342 i = hw_breakpoint_used_count ();
7343 target_resources_ok =
7344 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7346 if (target_resources_ok == 0)
7347 error ("No hardware breakpoint support in the target.");
7348 else if (target_resources_ok < 0)
7349 error ("Hardware breakpoints used exceeds limit.");
7352 if (bpt->enable != permanent)
7353 bpt->enable = enabled;
7354 bpt->disposition = disposition;
7355 check_duplicates (bpt);
7356 breakpoints_changed ();
7358 if (bpt->type == bp_watchpoint ||
7359 bpt->type == bp_hardware_watchpoint ||
7360 bpt->type == bp_read_watchpoint ||
7361 bpt->type == bp_access_watchpoint)
7363 if (bpt->exp_valid_block != NULL)
7365 struct frame_info *fr =
7367 /* Ensure that we have the current frame. Else, this
7368 next query may pessimistically be answered as, "No,
7369 not within current scope". */
7370 get_current_frame ();
7371 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7375 Cannot enable watchpoint %d because the block in which its expression\n\
7376 is valid is not currently in scope.\n", bpt->number);
7377 bpt->enable = disabled;
7381 save_selected_frame = selected_frame;
7382 save_selected_frame_level = selected_frame_level;
7383 select_frame (fr, -1);
7386 value_free (bpt->val);
7387 mark = value_mark ();
7388 bpt->val = evaluate_expression (bpt->exp);
7389 release_value (bpt->val);
7390 if (VALUE_LAZY (bpt->val))
7391 value_fetch_lazy (bpt->val);
7393 if (bpt->type == bp_hardware_watchpoint ||
7394 bpt->type == bp_read_watchpoint ||
7395 bpt->type == bp_access_watchpoint)
7397 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7398 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7400 /* Hack around 'unused var' error for some targets here */
7402 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7403 bpt->type, i + mem_cnt, other_type_used);
7404 /* we can consider of type is bp_hardware_watchpoint, convert to
7405 bp_watchpoint in the following condition */
7406 if (target_resources_ok < 0)
7409 Cannot enable watchpoint %d because target watch resources\n\
7410 have been allocated for other watchpoints.\n", bpt->number);
7411 bpt->enable = disabled;
7412 value_free_to_mark (mark);
7417 if (save_selected_frame_level >= 0)
7418 select_frame (save_selected_frame, save_selected_frame_level);
7419 value_free_to_mark (mark);
7421 if (modify_breakpoint_hook)
7422 modify_breakpoint_hook (bpt);
7423 breakpoint_modify_event (bpt->number);
7427 enable_breakpoint (struct breakpoint *bpt)
7429 do_enable_breakpoint (bpt, bpt->disposition);
7432 /* The enable command enables the specified breakpoints (or all defined
7433 breakpoints) so they once again become (or continue to be) effective
7434 in stopping the inferior. */
7438 enable_command (char *args, int from_tty)
7440 register struct breakpoint *bpt;
7442 ALL_BREAKPOINTS (bpt)
7446 warning ("attempted to enable apparently deleted breakpoint #%d?",
7451 case bp_catch_unload:
7453 case bp_catch_vfork:
7455 case bp_catch_catch:
7456 case bp_catch_throw:
7457 case bp_hardware_breakpoint:
7459 case bp_hardware_watchpoint:
7460 case bp_read_watchpoint:
7461 case bp_access_watchpoint:
7462 enable_breakpoint (bpt);
7467 map_breakpoint_numbers (args, enable_breakpoint);
7471 enable_once_breakpoint (struct breakpoint *bpt)
7473 do_enable_breakpoint (bpt, disable);
7478 enable_once_command (char *args, int from_tty)
7480 map_breakpoint_numbers (args, enable_once_breakpoint);
7484 enable_delete_breakpoint (struct breakpoint *bpt)
7486 do_enable_breakpoint (bpt, del);
7491 enable_delete_command (char *args, int from_tty)
7493 map_breakpoint_numbers (args, enable_delete_breakpoint);
7496 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7498 struct symtabs_and_lines
7499 decode_line_spec_1 (char *string, int funfirstline)
7501 struct symtabs_and_lines sals;
7503 error ("Empty line specification.");
7504 if (default_breakpoint_valid)
7505 sals = decode_line_1 (&string, funfirstline,
7506 default_breakpoint_symtab,
7507 default_breakpoint_line,
7510 sals = decode_line_1 (&string, funfirstline,
7511 (struct symtab *) NULL, 0, (char ***) NULL);
7513 error ("Junk at end of line specification: %s", string);
7518 _initialize_breakpoint (void)
7520 struct cmd_list_element *c;
7522 breakpoint_chain = 0;
7523 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7524 before a breakpoint is set. */
7525 breakpoint_count = 0;
7527 add_com ("ignore", class_breakpoint, ignore_command,
7528 "Set ignore-count of breakpoint number N to COUNT.\n\
7529 Usage is `ignore N COUNT'.");
7531 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7533 add_com ("commands", class_breakpoint, commands_command,
7534 "Set commands to be executed when a breakpoint is hit.\n\
7535 Give breakpoint number as argument after \"commands\".\n\
7536 With no argument, the targeted breakpoint is the last one set.\n\
7537 The commands themselves follow starting on the next line.\n\
7538 Type a line containing \"end\" to indicate the end of them.\n\
7539 Give \"silent\" as the first line to make the breakpoint silent;\n\
7540 then no output is printed when it is hit, except what the commands print.");
7542 add_com ("condition", class_breakpoint, condition_command,
7543 "Specify breakpoint number N to break only if COND is true.\n\
7544 Usage is `condition N COND', where N is an integer and COND is an\n\
7545 expression to be evaluated whenever breakpoint N is reached. ");
7547 add_com ("tbreak", class_breakpoint, tbreak_command,
7548 "Set a temporary breakpoint. Args like \"break\" command.\n\
7549 Like \"break\" except the breakpoint is only temporary,\n\
7550 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7551 by using \"enable delete\" on the breakpoint number.");
7552 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7553 "Set temporary breakpoint at procedure exit. Either there should\n\
7554 be no argument or the argument must be a depth.\n");
7556 add_com ("hbreak", class_breakpoint, hbreak_command,
7557 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7558 Like \"break\" except the breakpoint requires hardware support,\n\
7559 some target hardware may not have this support.");
7561 add_com ("thbreak", class_breakpoint, thbreak_command,
7562 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7563 Like \"hbreak\" except the breakpoint is only temporary,\n\
7564 so it will be deleted when hit.");
7566 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7567 "Enable some breakpoints.\n\
7568 Give breakpoint numbers (separated by spaces) as arguments.\n\
7569 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7570 This is used to cancel the effect of the \"disable\" command.\n\
7571 With a subcommand you can enable temporarily.",
7572 &enablelist, "enable ", 1, &cmdlist);
7574 add_com ("ab", class_breakpoint, enable_command,
7575 "Enable some breakpoints.\n\
7576 Give breakpoint numbers (separated by spaces) as arguments.\n\
7577 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7578 This is used to cancel the effect of the \"disable\" command.\n\
7579 With a subcommand you can enable temporarily.");
7581 add_com_alias ("en", "enable", class_breakpoint, 1);
7583 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7584 "Enable some breakpoints.\n\
7585 Give breakpoint numbers (separated by spaces) as arguments.\n\
7586 This is used to cancel the effect of the \"disable\" command.\n\
7587 May be abbreviated to simply \"enable\".\n",
7588 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7590 add_cmd ("once", no_class, enable_once_command,
7591 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7592 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7595 add_cmd ("delete", no_class, enable_delete_command,
7596 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7597 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7600 add_cmd ("delete", no_class, enable_delete_command,
7601 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7602 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7605 add_cmd ("once", no_class, enable_once_command,
7606 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7607 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7610 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7611 "Disable some breakpoints.\n\
7612 Arguments are breakpoint numbers with spaces in between.\n\
7613 To disable all breakpoints, give no argument.\n\
7614 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7615 &disablelist, "disable ", 1, &cmdlist);
7616 add_com_alias ("dis", "disable", class_breakpoint, 1);
7617 add_com_alias ("disa", "disable", class_breakpoint, 1);
7619 add_com ("sb", class_breakpoint, disable_command,
7620 "Disable some breakpoints.\n\
7621 Arguments are breakpoint numbers with spaces in between.\n\
7622 To disable all breakpoints, give no argument.\n\
7623 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7625 add_cmd ("breakpoints", class_alias, disable_command,
7626 "Disable some breakpoints.\n\
7627 Arguments are breakpoint numbers with spaces in between.\n\
7628 To disable all breakpoints, give no argument.\n\
7629 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7630 This command may be abbreviated \"disable\".",
7633 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7634 "Delete some breakpoints or auto-display expressions.\n\
7635 Arguments are breakpoint numbers with spaces in between.\n\
7636 To delete all breakpoints, give no argument.\n\
7638 Also a prefix command for deletion of other GDB objects.\n\
7639 The \"unset\" command is also an alias for \"delete\".",
7640 &deletelist, "delete ", 1, &cmdlist);
7641 add_com_alias ("d", "delete", class_breakpoint, 1);
7643 add_com ("db", class_breakpoint, delete_command,
7644 "Delete some breakpoints.\n\
7645 Arguments are breakpoint numbers with spaces in between.\n\
7646 To delete all breakpoints, give no argument.\n");
7648 add_cmd ("breakpoints", class_alias, delete_command,
7649 "Delete some breakpoints or auto-display expressions.\n\
7650 Arguments are breakpoint numbers with spaces in between.\n\
7651 To delete all breakpoints, give no argument.\n\
7652 This command may be abbreviated \"delete\".",
7655 add_com ("clear", class_breakpoint, clear_command,
7656 concat ("Clear breakpoint at specified line or function.\n\
7657 Argument may be line number, function name, or \"*\" and an address.\n\
7658 If line number is specified, all breakpoints in that line are cleared.\n\
7659 If function is specified, breakpoints at beginning of function are cleared.\n\
7660 If an address is specified, breakpoints at that address are cleared.\n\n",
7661 "With no argument, clears all breakpoints in the line that the selected frame\n\
7664 See also the \"delete\" command which clears breakpoints by number.", NULL));
7666 add_com ("break", class_breakpoint, break_command,
7667 concat ("Set breakpoint at specified line or function.\n\
7668 Argument may be line number, function name, or \"*\" and an address.\n\
7669 If line number is specified, break at start of code for that line.\n\
7670 If function is specified, break at start of code for that function.\n\
7671 If an address is specified, break at that exact address.\n",
7672 "With no arg, uses current execution address of selected stack frame.\n\
7673 This is useful for breaking on return to a stack frame.\n\
7675 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7677 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7678 add_com_alias ("b", "break", class_run, 1);
7679 add_com_alias ("br", "break", class_run, 1);
7680 add_com_alias ("bre", "break", class_run, 1);
7681 add_com_alias ("brea", "break", class_run, 1);
7683 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7684 concat ("Set breakpoint at procedure exit. \n\
7685 Argument may be function name, or \"*\" and an address.\n\
7686 If function is specified, break at end of code for that function.\n\
7687 If an address is specified, break at the end of the function that contains \n\
7688 that exact address.\n",
7689 "With no arg, uses current execution address of selected stack frame.\n\
7690 This is useful for breaking on return to a stack frame.\n\
7692 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7694 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7695 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7696 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7697 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7698 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7702 add_com_alias ("ba", "break", class_breakpoint, 1);
7703 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7704 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7705 "Set breakpoint at procedure exit. Either there should\n\
7706 be no argument or the argument must be a depth.\n");
7711 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7712 "Break in function/address or break at a line in the current file.",
7713 &stoplist, "stop ", 1, &cmdlist);
7714 add_cmd ("in", class_breakpoint, stopin_command,
7715 "Break in function or address.\n", &stoplist);
7716 add_cmd ("at", class_breakpoint, stopat_command,
7717 "Break at a line in the current file.\n", &stoplist);
7718 add_com ("status", class_info, breakpoints_info,
7719 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7720 The \"Type\" column indicates one of:\n\
7721 \tbreakpoint - normal breakpoint\n\
7722 \twatchpoint - watchpoint\n\
7723 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7724 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7725 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7726 address and file/line number respectively.\n\n",
7727 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7728 are set to the address of the last breakpoint listed.\n\n\
7729 Convenience variable \"$bpnum\" contains the number of the last\n\
7730 breakpoint set.", NULL));
7733 add_info ("breakpoints", breakpoints_info,
7734 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7735 The \"Type\" column indicates one of:\n\
7736 \tbreakpoint - normal breakpoint\n\
7737 \twatchpoint - watchpoint\n\
7738 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7739 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7740 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7741 address and file/line number respectively.\n\n",
7742 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7743 are set to the address of the last breakpoint listed.\n\n\
7744 Convenience variable \"$bpnum\" contains the number of the last\n\
7745 breakpoint set.", NULL));
7748 add_com ("lb", class_breakpoint, breakpoints_info,
7749 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7750 The \"Type\" column indicates one of:\n\
7751 \tbreakpoint - normal breakpoint\n\
7752 \twatchpoint - watchpoint\n\
7753 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7754 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7755 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7756 address and file/line number respectively.\n\n",
7757 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7758 are set to the address of the last breakpoint listed.\n\n\
7759 Convenience variable \"$bpnum\" contains the number of the last\n\
7760 breakpoint set.", NULL));
7762 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7763 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7764 The \"Type\" column indicates one of:\n\
7765 \tbreakpoint - normal breakpoint\n\
7766 \twatchpoint - watchpoint\n\
7767 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7768 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7769 \tuntil - internal breakpoint used by the \"until\" command\n\
7770 \tfinish - internal breakpoint used by the \"finish\" command\n",
7771 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7772 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7773 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7774 address and file/line number respectively.\n\n",
7775 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7776 are set to the address of the last breakpoint listed.\n\n\
7777 Convenience variable \"$bpnum\" contains the number of the last\n\
7778 breakpoint set.", NULL),
7779 &maintenanceinfolist);
7781 add_com ("catch", class_breakpoint, catch_command,
7782 "Set catchpoints to catch events.\n\
7783 Raised signals may be caught:\n\
7784 \tcatch signal - all signals\n\
7785 \tcatch signal <signame> - a particular signal\n\
7786 Raised exceptions may be caught:\n\
7787 \tcatch throw - all exceptions, when thrown\n\
7788 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7789 \tcatch catch - all exceptions, when caught\n\
7790 \tcatch catch <exceptname> - a particular exception, when caught\n\
7791 Thread or process events may be caught:\n\
7792 \tcatch thread_start - any threads, just after creation\n\
7793 \tcatch thread_exit - any threads, just before expiration\n\
7794 \tcatch thread_join - any threads, just after joins\n\
7795 Process events may be caught:\n\
7796 \tcatch start - any processes, just after creation\n\
7797 \tcatch exit - any processes, just before expiration\n\
7798 \tcatch fork - calls to fork()\n\
7799 \tcatch vfork - calls to vfork()\n\
7800 \tcatch exec - calls to exec()\n\
7801 Dynamically-linked library events may be caught:\n\
7802 \tcatch load - loads of any library\n\
7803 \tcatch load <libname> - loads of a particular library\n\
7804 \tcatch unload - unloads of any library\n\
7805 \tcatch unload <libname> - unloads of a particular library\n\
7806 The act of your program's execution stopping may also be caught:\n\
7808 C++ exceptions may be caught:\n\
7809 \tcatch throw - all exceptions, when thrown\n\
7810 \tcatch catch - all exceptions, when caught\n\
7812 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7813 after a fork or vfork is caught.\n\n\
7814 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7816 add_com ("tcatch", class_breakpoint, tcatch_command,
7817 "Set temporary catchpoints to catch events.\n\
7818 Args like \"catch\" command.\n\
7819 Like \"catch\" except the catchpoint is only temporary,\n\
7820 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7821 by using \"enable delete\" on the catchpoint number.");
7823 add_com ("watch", class_breakpoint, watch_command,
7824 "Set a watchpoint for an expression.\n\
7825 A watchpoint stops execution of your program whenever the value of\n\
7826 an expression changes.");
7828 add_com ("rwatch", class_breakpoint, rwatch_command,
7829 "Set a read watchpoint for an expression.\n\
7830 A watchpoint stops execution of your program whenever the value of\n\
7831 an expression is read.");
7833 add_com ("awatch", class_breakpoint, awatch_command,
7834 "Set a watchpoint for an expression.\n\
7835 A watchpoint stops execution of your program whenever the value of\n\
7836 an expression is either read or written.");
7838 add_info ("watchpoints", breakpoints_info,
7839 "Synonym for ``info breakpoints''.");
7842 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7843 (char *) &can_use_hw_watchpoints,
7844 "Set debugger's willingness to use watchpoint hardware.\n\
7845 If zero, gdb will not use hardware for new watchpoints, even if\n\
7846 such is available. (However, any hardware watchpoints that were\n\
7847 created before setting this to nonzero, will continue to use watchpoint\n\
7850 add_show_from_set (c, &showlist);
7852 can_use_hw_watchpoints = 1;