1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 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"
46 #include "gdb-events.h"
48 /* Prototypes for local functions. */
50 static void until_break_command_continuation (struct continuation_arg *arg);
53 catch_command_1 PARAMS ((char *, int, int));
56 enable_delete_command PARAMS ((char *, int));
59 enable_delete_breakpoint PARAMS ((struct breakpoint *));
62 enable_once_command PARAMS ((char *, int));
65 enable_once_breakpoint PARAMS ((struct breakpoint *));
68 disable_command PARAMS ((char *, int));
71 enable_command PARAMS ((char *, int));
74 map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *)));
77 ignore_command PARAMS ((char *, int));
79 static int breakpoint_re_set_one PARAMS ((PTR));
82 clear_command PARAMS ((char *, int));
85 catch_command PARAMS ((char *, int));
88 handle_gnu_4_16_catch_command PARAMS ((char *, int, int));
90 static struct symtabs_and_lines
91 get_catch_sals PARAMS ((int));
94 watch_command PARAMS ((char *, int));
97 can_use_hardware_watchpoint PARAMS ((struct value *));
99 static void break_at_finish_command PARAMS ((char *, int));
100 static void break_at_finish_at_depth_command PARAMS ((char *, int));
103 tbreak_command PARAMS ((char *, int));
105 static void tbreak_at_finish_command PARAMS ((char *, int));
108 break_command_1 PARAMS ((char *, int, int));
111 mention PARAMS ((struct breakpoint *));
114 set_raw_breakpoint PARAMS ((struct symtab_and_line));
117 check_duplicates PARAMS ((CORE_ADDR, asection *));
120 describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
123 breakpoints_info PARAMS ((char *, int));
126 breakpoint_1 PARAMS ((int, int));
129 bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
131 static int breakpoint_cond_eval PARAMS ((PTR));
134 cleanup_executing_breakpoints PARAMS ((PTR));
137 commands_command PARAMS ((char *, int));
140 condition_command PARAMS ((char *, int));
143 get_number_trailer PARAMS ((char **, int));
146 set_breakpoint_count PARAMS ((int));
149 static struct breakpoint *
150 create_temp_exception_breakpoint PARAMS ((CORE_ADDR));
161 remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t));
163 static enum print_stop_action print_it_typical PARAMS ((bpstat));
165 static enum print_stop_action print_bp_stop_message (bpstat bs);
169 enum exception_event_kind kind;
172 args_for_catchpoint_enable;
174 static int watchpoint_check PARAMS ((PTR));
176 static int cover_target_enable_exception_callback PARAMS ((PTR));
178 static void maintenance_info_breakpoints PARAMS ((char *, int));
180 #ifdef GET_LONGJMP_TARGET
181 static void create_longjmp_breakpoint PARAMS ((char *));
184 static int hw_breakpoint_used_count PARAMS ((void));
186 static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
188 static void hbreak_command PARAMS ((char *, int));
190 static void thbreak_command PARAMS ((char *, int));
192 static void watch_command_1 PARAMS ((char *, int, int));
194 static void rwatch_command PARAMS ((char *, int));
196 static void awatch_command PARAMS ((char *, int));
198 static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
200 static void solib_load_unload_1 PARAMS ((char *hookname,
204 enum bptype bp_kind));
206 static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag,
208 enum bptype bp_kind));
210 static void break_at_finish_at_depth_command_1 PARAMS ((char *arg,
214 static void break_at_finish_command_1 PARAMS ((char *arg,
218 static void stop_command PARAMS ((char *arg, int from_tty));
220 static void stopin_command PARAMS ((char *arg, int from_tty));
222 static void stopat_command PARAMS ((char *arg, int from_tty));
224 static char *ep_find_event_name_end PARAMS ((char *arg));
226 static char *ep_parse_optional_if_clause PARAMS ((char **arg));
228 static char *ep_parse_optional_filename PARAMS ((char **arg));
230 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
231 static void catch_exec_command_1 PARAMS ((char *arg, int tempflag,
235 static void create_exception_catchpoint
236 PARAMS ((int tempflag, char *cond_string,
237 enum exception_event_kind ex_event,
238 struct symtab_and_line * sal));
240 static void catch_exception_command_1
241 PARAMS ((enum exception_event_kind ex_event,
242 char *arg, int tempflag, int from_tty));
244 static void tcatch_command PARAMS ((char *arg, int from_tty));
246 static void ep_skip_leading_whitespace PARAMS ((char **s));
248 /* Prototypes for exported functions. */
251 awatch_command PARAMS ((char *, int));
254 do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
256 /* If FALSE, gdb will not use hardware support for watchpoints, even
257 if such is available. */
258 static int can_use_hw_watchpoints;
260 void _initialize_breakpoint PARAMS ((void));
262 void set_breakpoint_count PARAMS ((int));
264 extern int addressprint; /* Print machine addresses? */
266 static int internal_breakpoint_number = -1;
268 /* Are we executing breakpoint commands? */
269 static int executing_breakpoint_commands;
271 /* Walk the following statement or block through all breakpoints.
272 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
275 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
277 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
278 for (B = breakpoint_chain; \
279 B ? (TMP=B->next, 1): 0; \
282 /* True if SHIFT_INST_REGS defined, false otherwise. */
284 int must_shift_inst_regs =
285 #if defined(SHIFT_INST_REGS)
292 /* True if breakpoint hit counts should be displayed in breakpoint info. */
294 int show_breakpoint_hit_counts = 1;
296 /* Chain of all breakpoints defined. */
298 struct breakpoint *breakpoint_chain;
300 /* Number of last breakpoint made. */
302 int breakpoint_count;
304 /* Pointer to current exception event record */
305 static struct exception_event_record *current_exception_event;
307 /* Indicator of whether exception catchpoints should be nuked
308 between runs of a program */
309 int exception_catchpoints_are_fragile = 0;
311 /* Indicator of when exception catchpoints set-up should be
312 reinitialized -- e.g. when program is re-run */
313 int exception_support_initialized = 0;
315 /* This function returns a pointer to the string representation of the
316 pathname of the dynamically-linked library that has just been
319 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
320 or undefined results are guaranteed.
322 This string's contents are only valid immediately after the
323 inferior has stopped in the dynamic linker hook, and becomes
324 invalid as soon as the inferior is continued. Clients should make
325 a copy of this string if they wish to continue the inferior and
326 then access the string. */
328 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
329 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
332 /* This function returns a pointer to the string representation of the
333 pathname of the dynamically-linked library that has just been
336 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
337 TRUE, or undefined results are guaranteed.
339 This string's contents are only valid immediately after the
340 inferior has stopped in the dynamic linker hook, and becomes
341 invalid as soon as the inferior is continued. Clients should make
342 a copy of this string if they wish to continue the inferior and
343 then access the string. */
345 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
346 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
349 /* This function is called by the "catch load" command. It allows the
350 debugger to be notified by the dynamic linker when a specified
351 library file (or any library file, if filename is NULL) is loaded. */
353 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
354 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
355 error ("catch of library loads not yet implemented on this platform")
358 /* This function is called by the "catch unload" command. It allows
359 the debugger to be notified by the dynamic linker when a specified
360 library file (or any library file, if filename is NULL) is
363 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
364 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
365 error ("catch of library unloads not yet implemented on this platform")
368 /* Set breakpoint count to NUM. */
371 set_breakpoint_count (num)
374 breakpoint_count = num;
375 set_internalvar (lookup_internalvar ("bpnum"),
376 value_from_longest (builtin_type_int, (LONGEST) num));
379 /* Used in run_command to zero the hit count when a new run starts. */
382 clear_breakpoint_hit_counts ()
384 struct breakpoint *b;
390 /* Default address, symtab and line to put a breakpoint at
391 for "break" command with no arg.
392 if default_breakpoint_valid is zero, the other three are
393 not valid, and "break" with no arg is an error.
395 This set by print_stack_frame, which calls set_default_breakpoint. */
397 int default_breakpoint_valid;
398 CORE_ADDR default_breakpoint_address;
399 struct symtab *default_breakpoint_symtab;
400 int default_breakpoint_line;
402 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
403 Advance *PP after the string and any trailing whitespace.
405 Currently the string can either be a number or "$" followed by the name
406 of a convenience variable. Making it an expression wouldn't work well
407 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
409 TRAILER is a character which can be found after the number; most
410 commonly this is `-'. If you don't want a trailer, use \0. */
412 get_number_trailer (pp, trailer)
416 int retval = 0; /* default */
420 /* Empty line means refer to the last breakpoint. */
421 return breakpoint_count;
424 /* Make a copy of the name, so we can null-terminate it
425 to pass to lookup_internalvar(). */
430 while (isalnum (*p) || *p == '_')
432 varname = (char *) alloca (p - start + 1);
433 strncpy (varname, start, p - start);
434 varname[p - start] = '\0';
435 val = value_of_internalvar (lookup_internalvar (varname));
436 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
437 retval = (int) value_as_long (val);
440 printf_filtered ("Convenience variable must have integer value.\n");
448 while (*p >= '0' && *p <= '9')
451 /* There is no number here. (e.g. "cond a == b"). */
453 /* Skip non-numeric token */
454 while (*p && !isspace((int) *p))
456 /* Return zero, which caller must interpret as error. */
462 if (!(isspace (*p) || *p == '\0' || *p == trailer))
464 /* Trailing junk: return 0 and let caller print error msg. */
465 while (!(isspace (*p) || *p == '\0' || *p == trailer))
476 /* Like get_number_trailer, but don't allow a trailer. */
481 return get_number_trailer (pp, '\0');
484 /* Parse a number or a range.
485 * A number will be of the form handled by get_number.
486 * A range will be of the form <number1> - <number2>, and
487 * will represent all the integers between number1 and number2,
490 * While processing a range, this fuction is called iteratively;
491 * At each call it will return the next value in the range.
493 * At the beginning of parsing a range, the char pointer PP will
494 * be advanced past <number1> and left pointing at the '-' token.
495 * Subsequent calls will not advance the pointer until the range
496 * is completed. The call that completes the range will advance
497 * pointer PP past <number2>.
501 get_number_or_range (pp)
504 static int last_retval, end_value;
505 static char *end_ptr;
506 static int in_range = 0;
510 /* Default case: pp is pointing either to a solo number,
511 or to the first number of a range. */
512 last_retval = get_number_trailer (pp, '-');
517 /* This is the start of a range (<number1> - <number2>).
518 Skip the '-', parse and remember the second number,
519 and also remember the end of the final token. */
523 while (isspace ((int) *end_ptr))
524 end_ptr++; /* skip white space */
525 end_value = get_number (temp);
526 if (end_value < last_retval)
528 error ("inverted range");
530 else if (end_value == last_retval)
532 /* degenerate range (number1 == number2). Advance the
533 token pointer so that the range will be treated as a
542 error ("negative value");
545 /* pp points to the '-' that betokens a range. All
546 number-parsing has already been done. Return the next
547 integer value (one greater than the saved previous value).
548 Do not advance the token pointer 'pp' until the end of range
551 if (++last_retval == end_value)
553 /* End of range reached; advance token pointer. */
563 /* condition N EXP -- set break condition of breakpoint N to EXP. */
566 condition_command (arg, from_tty)
570 register struct breakpoint *b;
575 error_no_arg ("breakpoint number");
578 bnum = get_number (&p);
580 error ("Bad breakpoint argument: '%s'", arg);
583 if (b->number == bnum)
587 free ((PTR) b->cond);
590 if (b->cond_string != NULL)
591 free ((PTR) b->cond_string);
596 b->cond_string = NULL;
598 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
603 /* I don't know if it matters whether this is the string the user
604 typed in or the decompiled expression. */
605 b->cond_string = savestring (arg, strlen (arg));
606 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
608 error ("Junk at end of expression");
610 breakpoints_changed ();
614 error ("No breakpoint number %d.", bnum);
619 commands_command (arg, from_tty)
623 register struct breakpoint *b;
626 struct command_line *l;
628 /* If we allowed this, we would have problems with when to
629 free the storage, if we change the commands currently
632 if (executing_breakpoint_commands)
633 error ("Can't use the \"commands\" command among a breakpoint's commands.");
636 bnum = get_number (&p);
639 error ("Unexpected extra arguments following breakpoint number.");
642 if (b->number == bnum)
646 "Type commands for when breakpoint %d is hit, one per line.",
648 l = read_command_lines (tmpbuf, from_tty);
649 free_command_lines (&b->commands);
651 breakpoints_changed ();
654 error ("No breakpoint number %d.", bnum);
657 /* Like target_read_memory() but if breakpoints are inserted, return
658 the shadow contents instead of the breakpoints themselves.
660 Read "memory data" from whatever target or inferior we have.
661 Returns zero if successful, errno value if not. EIO is used
662 for address out of bounds. If breakpoints are inserted, returns
663 shadow contents, not the breakpoints themselves. From breakpoint.c. */
666 read_memory_nobpt (memaddr, myaddr, len)
672 struct breakpoint *b;
673 CORE_ADDR bp_addr = 0;
676 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
677 /* No breakpoints on this machine. */
678 return target_read_memory (memaddr, myaddr, len);
682 if (b->type == bp_none)
683 warning ("reading through apparently deleted breakpoint #%d?",
686 /* memory breakpoint? */
687 if (b->type == bp_watchpoint
688 || b->type == bp_hardware_watchpoint
689 || b->type == bp_read_watchpoint
690 || b->type == bp_access_watchpoint)
695 /* Addresses and length of the part of the breakpoint that
697 /* XXXX The m68k, sh and h8300 have different local and remote
698 breakpoint values. BREAKPOINT_FROM_PC still manages to
699 correctly determine the breakpoints memory address and size
700 for these targets. */
701 bp_addr = b->address;
703 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
708 if (bp_addr + bp_size <= memaddr)
709 /* The breakpoint is entirely before the chunk of memory we
712 if (bp_addr >= memaddr + len)
713 /* The breakpoint is entirely after the chunk of memory we are
716 /* Copy the breakpoint from the shadow contents, and recurse for
717 the things before and after. */
719 /* Offset within shadow_contents. */
722 if (bp_addr < memaddr)
724 /* Only copy the second part of the breakpoint. */
725 bp_size -= memaddr - bp_addr;
726 bptoffset = memaddr - bp_addr;
730 if (bp_addr + bp_size > memaddr + len)
732 /* Only copy the first part of the breakpoint. */
733 bp_size -= (bp_addr + bp_size) - (memaddr + len);
736 memcpy (myaddr + bp_addr - memaddr,
737 b->shadow_contents + bptoffset, bp_size);
739 if (bp_addr > memaddr)
741 /* Copy the section of memory before the breakpoint. */
742 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
747 if (bp_addr + bp_size < memaddr + len)
749 /* Copy the section of memory after the breakpoint. */
750 status = read_memory_nobpt
752 myaddr + bp_addr + bp_size - memaddr,
753 memaddr + len - (bp_addr + bp_size));
760 /* Nothing overlaps. Just call read_memory_noerr. */
761 return target_read_memory (memaddr, myaddr, len);
765 /* insert_breakpoints is used when starting or continuing the program.
766 remove_breakpoints is used when the program stops.
767 Both return zero if successful,
768 or an `errno' value if could not write the inferior. */
771 insert_breakpoints ()
773 register struct breakpoint *b, *temp;
774 int return_val = 0; /* return success code. */
776 int disabled_breaks = 0;
778 static char message1[] = "Error inserting catchpoint %d:\n";
779 static char message[sizeof (message1) + 30];
782 ALL_BREAKPOINTS_SAFE (b, temp)
784 if (b->enable == permanent)
785 /* Permanent breakpoints cannot be inserted or removed. */
787 else if (b->type != bp_watchpoint
788 && b->type != bp_hardware_watchpoint
789 && b->type != bp_read_watchpoint
790 && b->type != bp_access_watchpoint
791 && b->type != bp_catch_fork
792 && b->type != bp_catch_vfork
793 && b->type != bp_catch_exec
794 && b->type != bp_catch_throw
795 && b->type != bp_catch_catch
796 && b->enable != disabled
797 && b->enable != shlib_disabled
798 && b->enable != call_disabled
802 if (b->type == bp_hardware_breakpoint)
803 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
806 /* Check to see if breakpoint is in an overlay section;
807 if so, we should set the breakpoint at the LMA address.
808 Only if the section is currently mapped should we ALSO
809 set a break at the VMA address. */
810 if (overlay_debugging && b->section &&
811 section_is_overlay (b->section))
815 addr = overlay_unmapped_address (b->address, b->section);
816 val = target_insert_breakpoint (addr, b->shadow_contents);
817 /* This would be the time to check val, to see if the
818 breakpoint write to the load address succeeded.
819 However, this might be an ordinary occurrance, eg. if
820 the unmapped overlay is in ROM. */
821 val = 0; /* in case unmapped address failed */
822 if (section_is_mapped (b->section))
823 val = target_insert_breakpoint (b->address,
826 else /* ordinary (non-overlay) address */
827 val = target_insert_breakpoint (b->address, b->shadow_contents);
831 /* Can't set the breakpoint. */
832 #if defined (DISABLE_UNSETTABLE_BREAK)
833 if (DISABLE_UNSETTABLE_BREAK (b->address))
835 /* See also: disable_breakpoints_in_shlibs. */
837 b->enable = shlib_disabled;
838 if (!disabled_breaks)
840 target_terminal_ours_for_output ();
841 warning ("Cannot insert breakpoint %d:", b->number);
842 warning ("Temporarily disabling shared library breakpoints:");
845 warning ("breakpoint #%d ", b->number);
850 target_terminal_ours_for_output ();
851 warning ("Cannot insert breakpoint %d:", b->number);
852 #ifdef ONE_PROCESS_WRITETEXT
853 warning ("The same program may be running in another process.");
855 memory_error (val, b->address); /* which bombs us out */
862 return_val = val; /* remember failure */
864 else if (ep_is_exception_catchpoint (b)
865 && b->enable != disabled
866 && b->enable != shlib_disabled
867 && b->enable != call_disabled
872 /* If we get here, we must have a callback mechanism for exception
873 events -- with g++ style embedded label support, we insert
874 ordinary breakpoints and not catchpoints. */
875 /* Format possible error message */
876 sprintf (message, message1, b->number);
878 val = target_insert_breakpoint (b->address, b->shadow_contents);
881 /* Couldn't set breakpoint for some reason */
882 target_terminal_ours_for_output ();
883 warning ("Cannot insert catchpoint %d; disabling it.",
885 b->enable = disabled;
889 /* Bp set, now make sure callbacks are enabled */
891 args_for_catchpoint_enable args;
892 args.kind = b->type == bp_catch_catch ?
893 EX_EVENT_CATCH : EX_EVENT_THROW;
895 val = catch_errors (cover_target_enable_exception_callback,
897 message, RETURN_MASK_ALL);
898 if (val != 0 && val != -1)
902 /* Check if something went wrong; val == 0 can be ignored */
905 /* something went wrong */
906 target_terminal_ours_for_output ();
907 warning ("Cannot insert catchpoint %d; disabling it.",
909 b->enable = disabled;
914 return_val = val; /* remember failure */
917 else if ((b->type == bp_hardware_watchpoint ||
918 b->type == bp_read_watchpoint ||
919 b->type == bp_access_watchpoint)
920 && b->enable == enabled
924 struct frame_info *saved_frame;
925 int saved_level, within_current_scope;
926 value_ptr mark = value_mark ();
929 /* Save the current frame and level so we can restore it after
930 evaluating the watchpoint expression on its own frame. */
931 saved_frame = selected_frame;
932 saved_level = selected_frame_level;
934 /* Determine if the watchpoint is within scope. */
935 if (b->exp_valid_block == NULL)
936 within_current_scope = 1;
939 struct frame_info *fi;
941 /* There might be no current frame at this moment if we are
942 resuming from a step over a breakpoint.
943 Set up current frame before trying to find the watchpoint
945 get_current_frame ();
946 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
947 within_current_scope = (fi != NULL);
948 if (within_current_scope)
949 select_frame (fi, -1);
952 if (within_current_scope)
954 /* Evaluate the expression and cut the chain of values
955 produced off from the value chain.
957 Make sure the value returned isn't lazy; we use
958 laziness to determine what memory GDB actually needed
959 in order to compute the value of the expression. */
960 v = evaluate_expression (b->exp);
962 value_release_to_mark (mark);
967 /* Look at each value on the value chain. */
968 for (; v; v = v->next)
970 /* If it's a memory location, and GDB actually needed
971 its contents to evaluate the expression, then we
973 if (VALUE_LVAL (v) == lval_memory
979 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
980 len = TYPE_LENGTH (VALUE_TYPE (v));
982 if (b->type == bp_read_watchpoint)
984 else if (b->type == bp_access_watchpoint)
987 val = target_insert_watchpoint (addr, len, type);
996 /* Failure to insert a watchpoint on any memory value in the
997 value chain brings us here. */
1000 remove_breakpoint (b, mark_uninserted);
1001 warning ("Could not insert hardware watchpoint %d.",
1008 printf_filtered ("Hardware watchpoint %d deleted", b->number);
1009 printf_filtered ("because the program has left the block \n");
1010 printf_filtered ("in which its expression is valid.\n");
1011 if (b->related_breakpoint)
1012 b->related_breakpoint->disposition = del_at_next_stop;
1013 b->disposition = del_at_next_stop;
1016 /* Restore the frame and level. */
1017 if ((saved_frame != selected_frame) ||
1018 (saved_level != selected_frame_level))
1019 select_and_print_frame (saved_frame, saved_level);
1022 return_val = val; /* remember failure */
1024 else if ((b->type == bp_catch_fork
1025 || b->type == bp_catch_vfork
1026 || b->type == bp_catch_exec)
1027 && b->enable == enabled
1035 val = target_insert_fork_catchpoint (inferior_pid);
1037 case bp_catch_vfork:
1038 val = target_insert_vfork_catchpoint (inferior_pid);
1041 val = target_insert_exec_catchpoint (inferior_pid);
1044 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1049 target_terminal_ours_for_output ();
1050 warning ("Cannot insert catchpoint %d.", b->number);
1056 return_val = val; /* remember failure */
1065 remove_breakpoints ()
1067 register struct breakpoint *b;
1074 val = remove_breakpoint (b, mark_uninserted);
1083 reattach_breakpoints (pid)
1086 register struct breakpoint *b;
1088 int saved_inferior_pid = inferior_pid;
1090 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1091 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1096 remove_breakpoint (b, mark_inserted);
1097 if (b->type == bp_hardware_breakpoint)
1098 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1100 val = target_insert_breakpoint (b->address, b->shadow_contents);
1103 inferior_pid = saved_inferior_pid;
1108 inferior_pid = saved_inferior_pid;
1113 update_breakpoints_after_exec ()
1115 struct breakpoint *b;
1116 struct breakpoint *temp;
1118 /* Doing this first prevents the badness of having delete_breakpoint()
1119 write a breakpoint's current "shadow contents" to lift the bp. That
1120 shadow is NOT valid after an exec()! */
1121 mark_breakpoints_out ();
1123 ALL_BREAKPOINTS_SAFE (b, temp)
1125 /* Solib breakpoints must be explicitly reset after an exec(). */
1126 if (b->type == bp_shlib_event)
1128 delete_breakpoint (b);
1132 /* Thread event breakpoints must be set anew after an exec(). */
1133 if (b->type == bp_thread_event)
1135 delete_breakpoint (b);
1139 /* Step-resume breakpoints are meaningless after an exec(). */
1140 if (b->type == bp_step_resume)
1142 delete_breakpoint (b);
1146 /* Ditto the sigtramp handler breakpoints. */
1147 if (b->type == bp_through_sigtramp)
1149 delete_breakpoint (b);
1153 /* Ditto the exception-handling catchpoints. */
1154 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1156 delete_breakpoint (b);
1160 /* Don't delete an exec catchpoint, because else the inferior
1161 won't stop when it ought!
1163 Similarly, we probably ought to keep vfork catchpoints, 'cause
1164 on this target, we may not be able to stop when the vfork is
1165 seen, but only when the subsequent exec is seen. (And because
1166 deleting fork catchpoints here but not vfork catchpoints will
1167 seem mysterious to users, keep those too.)
1169 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1170 target address field, if any, is sufficient to have it be reset
1171 automagically. Certainly on HP-UX that's true. */
1172 if ((b->type == bp_catch_exec) ||
1173 (b->type == bp_catch_vfork) ||
1174 (b->type == bp_catch_fork))
1176 b->address = (CORE_ADDR) NULL;
1180 /* bp_finish is a special case. The only way we ought to be able
1181 to see one of these when an exec() has happened, is if the user
1182 caught a vfork, and then said "finish". Ordinarily a finish just
1183 carries them to the call-site of the current callee, by setting
1184 a temporary bp there and resuming. But in this case, the finish
1185 will carry them entirely through the vfork & exec.
1187 We don't want to allow a bp_finish to remain inserted now. But
1188 we can't safely delete it, 'cause finish_command has a handle to
1189 the bp on a bpstat, and will later want to delete it. There's a
1190 chance (and I've seen it happen) that if we delete the bp_finish
1191 here, that its storage will get reused by the time finish_command
1192 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1193 We really must allow finish_command to delete a bp_finish.
1195 In the absense of a general solution for the "how do we know
1196 it's safe to delete something others may have handles to?"
1197 problem, what we'll do here is just uninsert the bp_finish, and
1198 let finish_command delete it.
1200 (We know the bp_finish is "doomed" in the sense that it's
1201 momentary, and will be deleted as soon as finish_command sees
1202 the inferior stopped. So it doesn't matter that the bp's
1203 address is probably bogus in the new a.out, unlike e.g., the
1204 solib breakpoints.) */
1206 if (b->type == bp_finish)
1211 /* Without a symbolic address, we have little hope of the
1212 pre-exec() address meaning the same thing in the post-exec()
1214 if (b->addr_string == NULL)
1216 delete_breakpoint (b);
1220 /* If this breakpoint has survived the above battery of checks, then
1221 it must have a symbolic address. Be sure that it gets reevaluated
1222 to a target address, rather than reusing the old evaluation. */
1223 b->address = (CORE_ADDR) NULL;
1228 detach_breakpoints (pid)
1231 register struct breakpoint *b;
1233 int saved_inferior_pid = inferior_pid;
1235 if (pid == inferior_pid)
1236 error ("Cannot detach breakpoints of inferior_pid");
1238 /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */
1239 inferior_pid = pid; /* Because remove_breakpoint will use this global. */
1244 val = remove_breakpoint (b, mark_inserted);
1247 inferior_pid = saved_inferior_pid;
1252 inferior_pid = saved_inferior_pid;
1257 remove_breakpoint (b, is)
1258 struct breakpoint *b;
1259 insertion_state_t is;
1263 if (b->enable == permanent)
1264 /* Permanent breakpoints cannot be inserted or removed. */
1267 if (b->type == bp_none)
1268 warning ("attempted to remove apparently deleted breakpoint #%d?",
1271 if (b->type != bp_watchpoint
1272 && b->type != bp_hardware_watchpoint
1273 && b->type != bp_read_watchpoint
1274 && b->type != bp_access_watchpoint
1275 && b->type != bp_catch_fork
1276 && b->type != bp_catch_vfork
1277 && b->type != bp_catch_exec
1278 && b->type != bp_catch_catch
1279 && b->type != bp_catch_throw)
1281 if (b->type == bp_hardware_breakpoint)
1282 val = target_remove_hw_breakpoint (b->address, b->shadow_contents);
1285 /* Check to see if breakpoint is in an overlay section;
1286 if so, we should remove the breakpoint at the LMA address.
1287 If that is not equal to the raw address, then we should
1288 presumable remove the breakpoint there as well. */
1289 if (overlay_debugging && b->section &&
1290 section_is_overlay (b->section))
1294 addr = overlay_unmapped_address (b->address, b->section);
1295 val = target_remove_breakpoint (addr, b->shadow_contents);
1296 /* This would be the time to check val, to see if the
1297 shadow breakpoint write to the load address succeeded.
1298 However, this might be an ordinary occurrance, eg. if
1299 the unmapped overlay is in ROM. */
1300 val = 0; /* in case unmapped address failed */
1301 if (section_is_mapped (b->section))
1302 val = target_remove_breakpoint (b->address,
1303 b->shadow_contents);
1305 else /* ordinary (non-overlay) address */
1306 val = target_remove_breakpoint (b->address, b->shadow_contents);
1310 b->inserted = (is == mark_inserted);
1312 else if ((b->type == bp_hardware_watchpoint ||
1313 b->type == bp_read_watchpoint ||
1314 b->type == bp_access_watchpoint)
1315 && b->enable == enabled
1320 b->inserted = (is == mark_inserted);
1321 /* Walk down the saved value chain. */
1322 for (v = b->val_chain; v; v = v->next)
1324 /* For each memory reference remove the watchpoint
1326 if (VALUE_LVAL (v) == lval_memory
1327 && ! VALUE_LAZY (v))
1332 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1333 len = TYPE_LENGTH (VALUE_TYPE (v));
1335 if (b->type == bp_read_watchpoint)
1337 else if (b->type == bp_access_watchpoint)
1340 val = target_remove_watchpoint (addr, len, type);
1346 /* Failure to remove any of the hardware watchpoints comes here. */
1347 if ((is == mark_uninserted) && (b->inserted))
1348 warning ("Could not remove hardware watchpoint %d.",
1351 /* Free the saved value chain. We will construct a new one
1352 the next time the watchpoint is inserted. */
1353 for (v = b->val_chain; v; v = n)
1358 b->val_chain = NULL;
1360 else if ((b->type == bp_catch_fork ||
1361 b->type == bp_catch_vfork ||
1362 b->type == bp_catch_exec)
1363 && b->enable == enabled
1370 val = target_remove_fork_catchpoint (inferior_pid);
1372 case bp_catch_vfork:
1373 val = target_remove_vfork_catchpoint (inferior_pid);
1376 val = target_remove_exec_catchpoint (inferior_pid);
1379 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1384 b->inserted = (is == mark_inserted);
1386 else if ((b->type == bp_catch_catch ||
1387 b->type == bp_catch_throw)
1388 && b->enable == enabled
1392 val = target_remove_breakpoint (b->address, b->shadow_contents);
1395 b->inserted = (is == mark_inserted);
1397 else if (ep_is_exception_catchpoint (b)
1398 && b->inserted /* sometimes previous insert doesn't happen */
1399 && b->enable == enabled
1403 val = target_remove_breakpoint (b->address, b->shadow_contents);
1407 b->inserted = (is == mark_inserted);
1413 /* Clear the "inserted" flag in all breakpoints. */
1416 mark_breakpoints_out ()
1418 register struct breakpoint *b;
1424 /* Clear the "inserted" flag in all breakpoints and delete any
1425 breakpoints which should go away between runs of the program.
1427 Plus other such housekeeping that has to be done for breakpoints
1430 Note: this function gets called at the end of a run (by
1431 generic_mourn_inferior) and when a run begins (by
1432 init_wait_for_inferior). */
1437 breakpoint_init_inferior (context)
1438 enum inf_context context;
1440 register struct breakpoint *b, *temp;
1441 static int warning_needed = 0;
1443 ALL_BREAKPOINTS_SAFE (b, temp)
1450 case bp_watchpoint_scope:
1452 /* If the call dummy breakpoint is at the entry point it will
1453 cause problems when the inferior is rerun, so we better
1456 Also get rid of scope breakpoints. */
1457 delete_breakpoint (b);
1461 case bp_hardware_watchpoint:
1462 case bp_read_watchpoint:
1463 case bp_access_watchpoint:
1465 /* Likewise for watchpoints on local expressions. */
1466 if (b->exp_valid_block != NULL)
1467 delete_breakpoint (b);
1470 /* Likewise for exception catchpoints in dynamic-linked
1471 executables where required */
1472 if (ep_is_exception_catchpoint (b) &&
1473 exception_catchpoints_are_fragile)
1476 delete_breakpoint (b);
1482 if (exception_catchpoints_are_fragile)
1483 exception_support_initialized = 0;
1485 /* Don't issue the warning unless it's really needed... */
1486 if (warning_needed && (context != inf_exited))
1488 warning ("Exception catchpoints from last run were deleted.");
1489 warning ("You must reinsert them explicitly.");
1494 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1495 exists at PC. It returns ordinary_breakpoint_here if it's an
1496 ordinary breakpoint, or permanent_breakpoint_here if it's a
1497 permanent breakpoint.
1498 - When continuing from a location with an ordinary breakpoint, we
1499 actually single step once before calling insert_breakpoints.
1500 - When continuing from a localion with a permanent breakpoint, we
1501 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1502 the target, to advance the PC past the breakpoint. */
1504 enum breakpoint_here
1505 breakpoint_here_p (pc)
1508 register struct breakpoint *b;
1509 int any_breakpoint_here = 0;
1512 if ((b->enable == enabled
1513 || b->enable == permanent)
1514 && b->address == pc) /* bp is enabled and matches pc */
1516 if (overlay_debugging &&
1517 section_is_overlay (b->section) &&
1518 !section_is_mapped (b->section))
1519 continue; /* unmapped overlay -- can't be a match */
1520 else if (b->enable == permanent)
1521 return permanent_breakpoint_here;
1523 any_breakpoint_here = 1;
1526 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1530 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1531 but it only returns true if there is actually a breakpoint inserted
1535 breakpoint_inserted_here_p (pc)
1538 register struct breakpoint *b;
1542 && b->address == pc) /* bp is inserted and matches pc */
1544 if (overlay_debugging &&
1545 section_is_overlay (b->section) &&
1546 !section_is_mapped (b->section))
1547 continue; /* unmapped overlay -- can't be a match */
1555 /* Return nonzero if FRAME is a dummy frame. We can't use
1556 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1557 much time, at least using get_saved_register on the 68k. This
1558 means that for this function to work right a port must use the
1559 bp_call_dummy breakpoint. */
1562 frame_in_dummy (frame)
1563 struct frame_info *frame;
1565 struct breakpoint *b;
1570 if (USE_GENERIC_DUMMY_FRAMES)
1571 return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame);
1575 if (b->type == bp_call_dummy
1576 && b->frame == frame->frame
1577 /* We need to check the PC as well as the frame on the sparc,
1578 for signals.exp in the testsuite. */
1581 - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE))
1582 && frame->pc <= b->address)
1588 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
1589 is valid for process/thread PID. */
1592 breakpoint_thread_match (pc, pid)
1596 struct breakpoint *b;
1599 thread = pid_to_thread_id (pid);
1602 if (b->enable != disabled
1603 && b->enable != shlib_disabled
1604 && b->enable != call_disabled
1606 && (b->thread == -1 || b->thread == thread))
1608 if (overlay_debugging &&
1609 section_is_overlay (b->section) &&
1610 !section_is_mapped (b->section))
1611 continue; /* unmapped overlay -- can't be a match */
1620 /* bpstat stuff. External routines' interfaces are documented
1624 ep_is_catchpoint (ep)
1625 struct breakpoint *ep;
1628 (ep->type == bp_catch_load)
1629 || (ep->type == bp_catch_unload)
1630 || (ep->type == bp_catch_fork)
1631 || (ep->type == bp_catch_vfork)
1632 || (ep->type == bp_catch_exec)
1633 || (ep->type == bp_catch_catch)
1634 || (ep->type == bp_catch_throw)
1637 /* ??rehrauer: Add more kinds here, as are implemented... */
1642 ep_is_shlib_catchpoint (ep)
1643 struct breakpoint *ep;
1646 (ep->type == bp_catch_load)
1647 || (ep->type == bp_catch_unload)
1652 ep_is_exception_catchpoint (ep)
1653 struct breakpoint *ep;
1656 (ep->type == bp_catch_catch)
1657 || (ep->type == bp_catch_throw)
1661 /* Clear a bpstat so that it says we are not at any breakpoint.
1662 Also free any storage that is part of a bpstat. */
1677 if (p->old_val != NULL)
1678 value_free (p->old_val);
1685 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1686 is part of the bpstat is copied as well. */
1694 bpstat retval = NULL;
1699 for (; bs != NULL; bs = bs->next)
1701 tmp = (bpstat) xmalloc (sizeof (*tmp));
1702 memcpy (tmp, bs, sizeof (*tmp));
1704 /* This is the first thing in the chain. */
1714 /* Find the bpstat associated with this breakpoint */
1717 bpstat_find_breakpoint (bsp, breakpoint)
1719 struct breakpoint *breakpoint;
1724 for (; bsp != NULL; bsp = bsp->next)
1726 if (bsp->breakpoint_at == breakpoint)
1732 /* Find a step_resume breakpoint associated with this bpstat.
1733 (If there are multiple step_resume bp's on the list, this function
1734 will arbitrarily pick one.)
1736 It is an error to use this function if BPSTAT doesn't contain a
1737 step_resume breakpoint.
1739 See wait_for_inferior's use of this function. */
1741 bpstat_find_step_resume_breakpoint (bsp)
1745 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1747 for (; bsp != NULL; bsp = bsp->next)
1749 if ((bsp->breakpoint_at != NULL) &&
1750 (bsp->breakpoint_at->type == bp_step_resume))
1751 return bsp->breakpoint_at;
1754 error ("Internal error (no step_resume breakpoint found)");
1758 /* Return the breakpoint number of the first breakpoint we are stopped
1759 at. *BSP upon return is a bpstat which points to the remaining
1760 breakpoints stopped at (but which is not guaranteed to be good for
1761 anything but further calls to bpstat_num).
1762 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1768 struct breakpoint *b;
1771 return 0; /* No more breakpoint values */
1774 b = (*bsp)->breakpoint_at;
1775 *bsp = (*bsp)->next;
1777 return -1; /* breakpoint that's been deleted since */
1779 return b->number; /* We have its number */
1783 /* Modify BS so that the actions will not be performed. */
1786 bpstat_clear_actions (bs)
1789 for (; bs != NULL; bs = bs->next)
1791 bs->commands = NULL;
1792 if (bs->old_val != NULL)
1794 value_free (bs->old_val);
1800 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1803 cleanup_executing_breakpoints (ignore)
1806 executing_breakpoint_commands = 0;
1809 /* Execute all the commands associated with all the breakpoints at this
1810 location. Any of these commands could cause the process to proceed
1811 beyond this point, etc. We look out for such changes by checking
1812 the global "breakpoint_proceeded" after each command. */
1815 bpstat_do_actions (bsp)
1819 struct cleanup *old_chain;
1820 struct command_line *cmd;
1822 /* Avoid endless recursion if a `source' command is contained
1824 if (executing_breakpoint_commands)
1827 executing_breakpoint_commands = 1;
1828 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1831 /* Note that (as of this writing), our callers all appear to
1832 be passing us the address of global stop_bpstat. And, if
1833 our calls to execute_control_command cause the inferior to
1834 proceed, that global (and hence, *bsp) will change.
1836 We must be careful to not touch *bsp unless the inferior
1837 has not proceeded. */
1839 /* This pointer will iterate over the list of bpstat's. */
1842 breakpoint_proceeded = 0;
1843 for (; bs != NULL; bs = bs->next)
1848 execute_control_command (cmd);
1850 if (breakpoint_proceeded)
1855 if (breakpoint_proceeded)
1856 /* The inferior is proceeded by the command; bomb out now.
1857 The bpstat chain has been blown away by wait_for_inferior.
1858 But since execution has stopped again, there is a new bpstat
1859 to look at, so start over. */
1862 bs->commands = NULL;
1865 executing_breakpoint_commands = 0;
1866 discard_cleanups (old_chain);
1869 /* This is the normal print function for a bpstat. In the future,
1870 much of this logic could (should?) be moved to bpstat_stop_status,
1871 by having it set different print_it values.
1873 Current scheme: When we stop, bpstat_print() is called. It loops
1874 through the bpstat list of things causing this stop, calling the
1875 print_bp_stop_message function on each one. The behavior of the
1876 print_bp_stop_message function depends on the print_it field of
1877 bpstat. If such field so indicates, call this function here.
1879 Return values from this routine (ultimately used by bpstat_print()
1880 and normal_stop() to decide what to do):
1881 PRINT_NOTHING: Means we already printed all we needed to print,
1882 don't print anything else.
1883 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1884 that something to be followed by a location.
1885 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1886 that something to be followed by a location.
1887 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1890 static enum print_stop_action
1891 print_it_typical (bs)
1895 struct cleanup *old_chain;
1896 struct ui_stream *stb;
1897 stb = ui_out_stream_new (uiout);
1898 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
1900 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1901 which has since been deleted. */
1902 if (bs->breakpoint_at == NULL)
1903 return PRINT_UNKNOWN;
1905 switch (bs->breakpoint_at->type)
1908 case bp_hardware_breakpoint:
1910 annotate_breakpoint (bs->breakpoint_at->number);
1911 ui_out_text (uiout, "\nBreakpoint ");
1912 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
1913 ui_out_field_string (uiout, "reason", "breakpoint-hit");
1914 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
1915 ui_out_text (uiout, ", ");
1916 return PRINT_SRC_AND_LOC;
1918 /* I think the user probably only wants to see one breakpoint
1919 number, not all of them. */
1920 annotate_breakpoint (bs->breakpoint_at->number);
1921 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1922 return PRINT_SRC_AND_LOC;
1926 case bp_shlib_event:
1927 /* Did we stop because the user set the stop_on_solib_events
1928 variable? (If so, we report this as a generic, "Stopped due
1929 to shlib event" message.) */
1930 printf_filtered ("Stopped due to shared library event\n");
1931 return PRINT_NOTHING;
1934 case bp_thread_event:
1935 /* Not sure how we will get here.
1936 GDB should not stop for these breakpoints. */
1937 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1938 return PRINT_NOTHING;
1942 annotate_catchpoint (bs->breakpoint_at->number);
1943 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1944 printf_filtered ("loaded");
1945 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1946 return PRINT_SRC_AND_LOC;
1949 case bp_catch_unload:
1950 annotate_catchpoint (bs->breakpoint_at->number);
1951 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1952 printf_filtered ("unloaded");
1953 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
1954 return PRINT_SRC_AND_LOC;
1958 annotate_catchpoint (bs->breakpoint_at->number);
1959 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1960 printf_filtered ("forked");
1961 printf_filtered (" process %d), ",
1962 bs->breakpoint_at->forked_inferior_pid);
1963 return PRINT_SRC_AND_LOC;
1966 case bp_catch_vfork:
1967 annotate_catchpoint (bs->breakpoint_at->number);
1968 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
1969 printf_filtered ("vforked");
1970 printf_filtered (" process %d), ",
1971 bs->breakpoint_at->forked_inferior_pid);
1972 return PRINT_SRC_AND_LOC;
1976 annotate_catchpoint (bs->breakpoint_at->number);
1977 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
1978 bs->breakpoint_at->number,
1979 bs->breakpoint_at->exec_pathname);
1980 return PRINT_SRC_AND_LOC;
1983 case bp_catch_catch:
1984 if (current_exception_event &&
1985 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
1987 annotate_catchpoint (bs->breakpoint_at->number);
1988 printf_filtered ("\nCatchpoint %d (exception caught), ",
1989 bs->breakpoint_at->number);
1990 printf_filtered ("throw location ");
1991 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
1992 printf_filtered ("%s:%d",
1993 CURRENT_EXCEPTION_THROW_FILE,
1994 CURRENT_EXCEPTION_THROW_LINE);
1996 printf_filtered ("unknown");
1998 printf_filtered (", catch location ");
1999 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2000 printf_filtered ("%s:%d",
2001 CURRENT_EXCEPTION_CATCH_FILE,
2002 CURRENT_EXCEPTION_CATCH_LINE);
2004 printf_filtered ("unknown");
2006 printf_filtered ("\n");
2007 /* don't bother to print location frame info */
2008 return PRINT_SRC_ONLY;
2012 /* really throw, some other bpstat will handle it */
2013 return PRINT_UNKNOWN;
2017 case bp_catch_throw:
2018 if (current_exception_event &&
2019 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2021 annotate_catchpoint (bs->breakpoint_at->number);
2022 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2023 bs->breakpoint_at->number);
2024 printf_filtered ("throw location ");
2025 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2026 printf_filtered ("%s:%d",
2027 CURRENT_EXCEPTION_THROW_FILE,
2028 CURRENT_EXCEPTION_THROW_LINE);
2030 printf_filtered ("unknown");
2032 printf_filtered (", catch location ");
2033 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2034 printf_filtered ("%s:%d",
2035 CURRENT_EXCEPTION_CATCH_FILE,
2036 CURRENT_EXCEPTION_CATCH_LINE);
2038 printf_filtered ("unknown");
2040 printf_filtered ("\n");
2041 /* don't bother to print location frame info */
2042 return PRINT_SRC_ONLY;
2046 /* really catch, some other bpstat will handle it */
2047 return PRINT_UNKNOWN;
2052 case bp_hardware_watchpoint:
2053 if (bs->old_val != NULL)
2055 annotate_watchpoint (bs->breakpoint_at->number);
2057 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2058 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2059 mention (bs->breakpoint_at);
2060 ui_out_list_begin (uiout, "value");
2061 ui_out_text (uiout, "\nOld value = ");
2062 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2063 ui_out_field_stream (uiout, "old", stb);
2064 ui_out_text (uiout, "\nNew value = ");
2065 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2066 ui_out_field_stream (uiout, "new", stb);
2067 ui_out_list_end (uiout);
2068 ui_out_text (uiout, "\n");
2070 mention (bs->breakpoint_at);
2071 printf_filtered ("\nOld value = ");
2072 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2073 printf_filtered ("\nNew value = ");
2074 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2075 Val_pretty_default);
2076 printf_filtered ("\n");
2078 value_free (bs->old_val);
2081 /* More than one watchpoint may have been triggered. */
2082 return PRINT_UNKNOWN;
2085 case bp_read_watchpoint:
2087 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2088 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2089 mention (bs->breakpoint_at);
2090 ui_out_list_begin (uiout, "value");
2091 ui_out_text (uiout, "\nValue = ");
2092 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2093 ui_out_field_stream (uiout, "value", stb);
2094 ui_out_list_end (uiout);
2095 ui_out_text (uiout, "\n");
2097 mention (bs->breakpoint_at);
2098 printf_filtered ("\nValue = ");
2099 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2100 Val_pretty_default);
2101 printf_filtered ("\n");
2103 return PRINT_UNKNOWN;
2106 case bp_access_watchpoint:
2108 if (bs->old_val != NULL)
2110 annotate_watchpoint (bs->breakpoint_at->number);
2111 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2112 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2113 mention (bs->breakpoint_at);
2114 ui_out_list_begin (uiout, "value");
2115 ui_out_text (uiout, "\nOld value = ");
2116 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2117 ui_out_field_stream (uiout, "old", stb);
2118 value_free (bs->old_val);
2120 ui_out_text (uiout, "\nNew value = ");
2124 mention (bs->breakpoint_at);
2125 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2126 ui_out_list_begin (uiout, "value");
2127 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2128 ui_out_text (uiout, "\nValue = ");
2130 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2131 ui_out_field_stream (uiout, "new", stb);
2132 ui_out_list_end (uiout);
2133 ui_out_text (uiout, "\n");
2135 if (bs->old_val != NULL)
2137 annotate_watchpoint (bs->breakpoint_at->number);
2138 mention (bs->breakpoint_at);
2139 printf_filtered ("\nOld value = ");
2140 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
2141 value_free (bs->old_val);
2143 printf_filtered ("\nNew value = ");
2147 mention (bs->breakpoint_at);
2148 printf_filtered ("\nValue = ");
2150 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
2151 Val_pretty_default);
2152 printf_filtered ("\n");
2154 return PRINT_UNKNOWN;
2157 /* Fall through, we don't deal with these types of breakpoints
2162 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2163 ui_out_field_string (uiout, "reason", "function-finished");
2165 return PRINT_UNKNOWN;
2170 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2171 ui_out_field_string (uiout, "reason", "location-reached");
2173 return PRINT_UNKNOWN;
2178 case bp_longjmp_resume:
2179 case bp_step_resume:
2180 case bp_through_sigtramp:
2181 case bp_watchpoint_scope:
2184 return PRINT_UNKNOWN;
2188 /* Generic routine for printing messages indicating why we
2189 stopped. The behavior of this function depends on the value
2190 'print_it' in the bpstat structure. Under some circumstances we
2191 may decide not to print anything here and delegate the task to
2194 static enum print_stop_action
2195 print_bp_stop_message (bpstat bs)
2197 switch (bs->print_it)
2200 /* Nothing should be printed for this bpstat entry. */
2201 return PRINT_UNKNOWN;
2205 /* We still want to print the frame, but we already printed the
2206 relevant messages. */
2207 return PRINT_SRC_AND_LOC;
2210 case print_it_normal:
2211 /* Normal case, we handle everything in print_it_typical. */
2212 return print_it_typical (bs);
2215 internal_error ("print_bp_stop_message: unrecognized enum value");
2220 /* Print a message indicating what happened. This is called from
2221 normal_stop(). The input to this routine is the head of the bpstat
2222 list - a list of the eventpoints that caused this stop. This
2223 routine calls the generic print routine for printing a message
2224 about reasons for stopping. This will print (for example) the
2225 "Breakpoint n," part of the output. The return value of this
2228 PRINT_UNKNOWN: Means we printed nothing
2229 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2230 code to print the location. An example is
2231 "Breakpoint 1, " which should be followed by
2233 PRINT_SRC_ONLY: Means we printed something, but there is no need
2234 to also print the location part of the message.
2235 An example is the catch/throw messages, which
2236 don't require a location appended to the end.
2237 PRINT_NOTHING: We have done some printing and we don't need any
2238 further info to be printed.*/
2240 enum print_stop_action
2246 /* Maybe another breakpoint in the chain caused us to stop.
2247 (Currently all watchpoints go on the bpstat whether hit or not.
2248 That probably could (should) be changed, provided care is taken
2249 with respect to bpstat_explains_signal). */
2250 for (; bs; bs = bs->next)
2252 val = print_bp_stop_message (bs);
2253 if (val == PRINT_SRC_ONLY
2254 || val == PRINT_SRC_AND_LOC
2255 || val == PRINT_NOTHING)
2259 /* We reached the end of the chain, or we got a null BS to start
2260 with and nothing was printed. */
2261 return PRINT_UNKNOWN;
2264 /* Evaluate the expression EXP and return 1 if value is zero.
2265 This is used inside a catch_errors to evaluate the breakpoint condition.
2266 The argument is a "struct expression *" that has been cast to char * to
2267 make it pass through catch_errors. */
2270 breakpoint_cond_eval (exp)
2273 value_ptr mark = value_mark ();
2274 int i = !value_true (evaluate_expression ((struct expression *) exp));
2275 value_free_to_mark (mark);
2279 /* Allocate a new bpstat and chain it to the current one. */
2282 bpstat_alloc (b, cbs)
2283 register struct breakpoint *b;
2284 bpstat cbs; /* Current "bs" value */
2288 bs = (bpstat) xmalloc (sizeof (*bs));
2290 bs->breakpoint_at = b;
2291 /* If the condition is false, etc., don't do the commands. */
2292 bs->commands = NULL;
2294 bs->print_it = print_it_normal;
2298 /* Possible return values for watchpoint_check (this can't be an enum
2299 because of check_errors). */
2300 /* The watchpoint has been deleted. */
2301 #define WP_DELETED 1
2302 /* The value has changed. */
2303 #define WP_VALUE_CHANGED 2
2304 /* The value has not changed. */
2305 #define WP_VALUE_NOT_CHANGED 3
2307 #define BP_TEMPFLAG 1
2308 #define BP_HARDWAREFLAG 2
2310 /* Check watchpoint condition. */
2313 watchpoint_check (p)
2316 bpstat bs = (bpstat) p;
2317 struct breakpoint *b;
2318 struct frame_info *fr;
2319 int within_current_scope;
2321 b = bs->breakpoint_at;
2323 if (b->exp_valid_block == NULL)
2324 within_current_scope = 1;
2327 /* There is no current frame at this moment. If we're going to have
2328 any chance of handling watchpoints on local variables, we'll need
2329 the frame chain (so we can determine if we're in scope). */
2330 reinit_frame_cache ();
2331 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
2332 within_current_scope = (fr != NULL);
2333 if (within_current_scope)
2334 /* If we end up stopping, the current frame will get selected
2335 in normal_stop. So this call to select_frame won't affect
2337 select_frame (fr, -1);
2340 if (within_current_scope)
2342 /* We use value_{,free_to_}mark because it could be a
2343 *long* time before we return to the command level and
2344 call free_all_values. We can't call free_all_values because
2345 we might be in the middle of evaluating a function call. */
2347 value_ptr mark = value_mark ();
2348 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
2349 if (!value_equal (b->val, new_val))
2351 release_value (new_val);
2352 value_free_to_mark (mark);
2353 bs->old_val = b->val;
2355 /* We will stop here */
2356 return WP_VALUE_CHANGED;
2360 /* Nothing changed, don't do anything. */
2361 value_free_to_mark (mark);
2362 /* We won't stop here */
2363 return WP_VALUE_NOT_CHANGED;
2368 /* This seems like the only logical thing to do because
2369 if we temporarily ignored the watchpoint, then when
2370 we reenter the block in which it is valid it contains
2371 garbage (in the case of a function, it may have two
2372 garbage values, one before and one after the prologue).
2373 So we can't even detect the first assignment to it and
2374 watch after that (since the garbage may or may not equal
2375 the first value assigned). */
2376 /* We print all the stop information in print_it_typical(), but
2377 in this case, by the time we call print_it_typical() this bp
2378 will be deleted already. So we have no choice but print the
2379 information here. */
2381 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
2382 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2383 ui_out_text (uiout, "\nWatchpoint ");
2384 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2385 ui_out_text (uiout, " deleted because the program has left the block in\n\
2386 which its expression is valid.\n");
2389 Watchpoint %d deleted because the program has left the block in\n\
2390 which its expression is valid.\n", bs->breakpoint_at->number);
2393 if (b->related_breakpoint)
2394 b->related_breakpoint->disposition = del_at_next_stop;
2395 b->disposition = del_at_next_stop;
2401 /* Get a bpstat associated with having just stopped at address *PC
2402 and frame address CORE_ADDRESS. Update *PC to point at the
2403 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2404 if this is known to not be a real breakpoint (it could still be a
2405 watchpoint, though). */
2407 /* Determine whether we stopped at a breakpoint, etc, or whether we
2408 don't understand this stop. Result is a chain of bpstat's such that:
2410 if we don't understand the stop, the result is a null pointer.
2412 if we understand why we stopped, the result is not null.
2414 Each element of the chain refers to a particular breakpoint or
2415 watchpoint at which we have stopped. (We may have stopped for
2416 several reasons concurrently.)
2418 Each element of the chain has valid next, breakpoint_at,
2419 commands, FIXME??? fields. */
2422 bpstat_stop_status (pc, not_a_breakpoint)
2424 int not_a_breakpoint;
2426 register struct breakpoint *b, *temp;
2428 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2429 int real_breakpoint = 0;
2430 /* Root of the chain of bpstat's */
2431 struct bpstats root_bs[1];
2432 /* Pointer to the last thing in the chain currently. */
2433 bpstat bs = root_bs;
2434 static char message1[] =
2435 "Error evaluating expression for watchpoint %d\n";
2436 char message[sizeof (message1) + 30 /* slop */ ];
2438 /* Get the address where the breakpoint would have been. */
2439 bp_addr = *pc - (not_a_breakpoint && !SOFTWARE_SINGLE_STEP_P ?
2440 0 : DECR_PC_AFTER_BREAK);
2442 ALL_BREAKPOINTS_SAFE (b, temp)
2444 if (b->enable == disabled
2445 || b->enable == shlib_disabled
2446 || b->enable == call_disabled)
2449 if (b->type != bp_watchpoint
2450 && b->type != bp_hardware_watchpoint
2451 && b->type != bp_read_watchpoint
2452 && b->type != bp_access_watchpoint
2453 && b->type != bp_hardware_breakpoint
2454 && b->type != bp_catch_fork
2455 && b->type != bp_catch_vfork
2456 && b->type != bp_catch_exec
2457 && b->type != bp_catch_catch
2458 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2459 if (b->address != bp_addr || /* address doesn't match or */
2460 (overlay_debugging && /* overlay doesn't match */
2461 section_is_overlay (b->section) &&
2462 !section_is_mapped (b->section)))
2465 if (b->type == bp_hardware_breakpoint
2466 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2469 /* Is this a catchpoint of a load or unload? If so, did we
2470 get a load or unload of the specified library? If not,
2472 if ((b->type == bp_catch_load)
2473 #if defined(SOLIB_HAVE_LOAD_EVENT)
2474 && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid)
2475 || ((b->dll_pathname != NULL)
2476 && (strcmp (b->dll_pathname,
2477 SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid))
2483 if ((b->type == bp_catch_unload)
2484 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2485 && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid)
2486 || ((b->dll_pathname != NULL)
2487 && (strcmp (b->dll_pathname,
2488 SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid))
2494 if ((b->type == bp_catch_fork)
2495 && !target_has_forked (inferior_pid, &b->forked_inferior_pid))
2498 if ((b->type == bp_catch_vfork)
2499 && !target_has_vforked (inferior_pid, &b->forked_inferior_pid))
2502 if ((b->type == bp_catch_exec)
2503 && !target_has_execd (inferior_pid, &b->exec_pathname))
2506 if (ep_is_exception_catchpoint (b) &&
2507 !(current_exception_event = target_get_current_exception_event ()))
2510 /* Come here if it's a watchpoint, or if the break address matches */
2512 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2514 /* Watchpoints may change this, if not found to have triggered. */
2518 sprintf (message, message1, b->number);
2519 if (b->type == bp_watchpoint ||
2520 b->type == bp_hardware_watchpoint)
2522 switch (catch_errors (watchpoint_check, bs, message,
2526 /* We've already printed what needs to be printed. */
2527 /* Actually this is superfluous, because by the time we
2528 call print_it_typical() the wp will be already deleted,
2529 and the function will return immediately. */
2530 bs->print_it = print_it_done;
2533 case WP_VALUE_CHANGED:
2537 case WP_VALUE_NOT_CHANGED:
2539 bs->print_it = print_it_noop;
2546 /* Error from catch_errors. */
2547 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2548 if (b->related_breakpoint)
2549 b->related_breakpoint->disposition = del_at_next_stop;
2550 b->disposition = del_at_next_stop;
2551 /* We've already printed what needs to be printed. */
2552 bs->print_it = print_it_done;
2558 else if (b->type == bp_read_watchpoint ||
2559 b->type == bp_access_watchpoint)
2565 addr = target_stopped_data_address ();
2568 for (v = b->val_chain; v; v = v->next)
2570 if (VALUE_LVAL (v) == lval_memory
2571 && ! VALUE_LAZY (v))
2575 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2576 /* Exact match not required. Within range is sufficient.
2578 if (addr >= vaddr &&
2579 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2584 switch (catch_errors (watchpoint_check, bs, message,
2588 /* We've already printed what needs to be printed. */
2589 bs->print_it = print_it_done;
2592 case WP_VALUE_CHANGED:
2593 case WP_VALUE_NOT_CHANGED:
2600 /* Error from catch_errors. */
2601 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2602 if (b->related_breakpoint)
2603 b->related_breakpoint->disposition = del_at_next_stop;
2604 b->disposition = del_at_next_stop;
2605 /* We've already printed what needs to be printed. */
2606 bs->print_it = print_it_done;
2609 else /* found == 0 */
2611 /* This is a case where some watchpoint(s) triggered,
2612 but not at the address of this watchpoint (FOUND
2613 was left zero). So don't print anything for this
2615 bs->print_it = print_it_noop;
2622 /* By definition, an encountered breakpoint is a triggered
2626 real_breakpoint = 1;
2630 b->frame != (get_current_frame ())->frame)
2634 int value_is_zero = 0;
2638 /* Need to select the frame, with all that implies
2639 so that the conditions will have the right context. */
2640 select_frame (get_current_frame (), 0);
2642 = catch_errors (breakpoint_cond_eval, (b->cond),
2643 "Error in testing breakpoint condition:\n",
2645 /* FIXME-someday, should give breakpoint # */
2648 if (b->cond && value_is_zero)
2651 /* Don't consider this a hit. */
2654 else if (b->ignore_count > 0)
2657 annotate_ignore_count_change ();
2662 /* We will stop here */
2663 if (b->disposition == disable)
2664 b->enable = disabled;
2665 bs->commands = b->commands;
2669 (STREQ ("silent", bs->commands->line) ||
2670 (xdb_commands && STREQ ("Q", bs->commands->line))))
2672 bs->commands = bs->commands->next;
2677 /* Print nothing for this entry if we dont stop or if we dont print. */
2678 if (bs->stop == 0 || bs->print == 0)
2679 bs->print_it = print_it_noop;
2682 bs->next = NULL; /* Terminate the chain */
2683 bs = root_bs->next; /* Re-grab the head of the chain */
2685 if (real_breakpoint && bs)
2687 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2689 if (DECR_PC_AFTER_HW_BREAK != 0)
2691 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2697 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2700 #if defined (SHIFT_INST_REGS)
2702 #else /* No SHIFT_INST_REGS. */
2704 #endif /* No SHIFT_INST_REGS. */
2709 /* The value of a hardware watchpoint hasn't changed, but the
2710 intermediate memory locations we are watching may have. */
2711 if (bs && !bs->stop &&
2712 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2713 bs->breakpoint_at->type == bp_read_watchpoint ||
2714 bs->breakpoint_at->type == bp_access_watchpoint))
2716 remove_breakpoints ();
2717 insert_breakpoints ();
2722 /* Tell what to do about this bpstat. */
2727 /* Classify each bpstat as one of the following. */
2730 /* This bpstat element has no effect on the main_action. */
2733 /* There was a watchpoint, stop but don't print. */
2736 /* There was a watchpoint, stop and print. */
2739 /* There was a breakpoint but we're not stopping. */
2742 /* There was a breakpoint, stop but don't print. */
2745 /* There was a breakpoint, stop and print. */
2748 /* We hit the longjmp breakpoint. */
2751 /* We hit the longjmp_resume breakpoint. */
2754 /* We hit the step_resume breakpoint. */
2757 /* We hit the through_sigtramp breakpoint. */
2760 /* We hit the shared library event breakpoint. */
2763 /* We caught a shared library event. */
2766 /* This is just used to count how many enums there are. */
2770 /* Here is the table which drives this routine. So that we can
2771 format it pretty, we define some abbreviations for the
2772 enum bpstat_what codes. */
2773 #define kc BPSTAT_WHAT_KEEP_CHECKING
2774 #define ss BPSTAT_WHAT_STOP_SILENT
2775 #define sn BPSTAT_WHAT_STOP_NOISY
2776 #define sgl BPSTAT_WHAT_SINGLE
2777 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2778 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2779 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2780 #define sr BPSTAT_WHAT_STEP_RESUME
2781 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2782 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2783 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2785 /* "Can't happen." Might want to print an error message.
2786 abort() is not out of the question, but chances are GDB is just
2787 a bit confused, not unusable. */
2788 #define err BPSTAT_WHAT_STOP_NOISY
2790 /* Given an old action and a class, come up with a new action. */
2791 /* One interesting property of this table is that wp_silent is the same
2792 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2793 after stopping, the check for whether to step over a breakpoint
2794 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2795 reference to how we stopped. We retain separate wp_silent and
2796 bp_silent codes in case we want to change that someday.
2798 Another possibly interesting property of this table is that
2799 there's a partial ordering, priority-like, of the actions. Once
2800 you've decided that some action is appropriate, you'll never go
2801 back and decide something of a lower priority is better. The
2804 kc < clr sgl shl slr sn sr ss ts
2805 sgl < clrs shl shlr slr sn sr ss ts
2806 slr < err shl shlr sn sr ss ts
2807 clr < clrs err shl shlr sn sr ss ts
2808 clrs < err shl shlr sn sr ss ts
2809 ss < shl shlr sn sr ts
2816 What I think this means is that we don't need a damned table
2817 here. If you just put the rows and columns in the right order,
2818 it'd look awfully regular. We could simply walk the bpstat list
2819 and choose the highest priority action we find, with a little
2820 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2821 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2822 is messy anyway). */
2824 /* step_resume entries: a step resume breakpoint overrides another
2825 breakpoint of signal handling (see comment in wait_for_inferior
2826 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2827 /* We handle the through_sigtramp_breakpoint the same way; having both
2828 one of those and a step_resume_breakpoint is probably very rare (?). */
2830 static const enum bpstat_what_main_action
2831 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2834 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2837 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2839 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2841 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2843 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2845 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2847 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2849 {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr},
2851 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2853 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2855 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2857 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2859 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2874 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2875 struct bpstat_what retval;
2877 retval.call_dummy = 0;
2878 for (; bs != NULL; bs = bs->next)
2880 enum class bs_class = no_effect;
2881 if (bs->breakpoint_at == NULL)
2882 /* I suspect this can happen if it was a momentary breakpoint
2883 which has since been deleted. */
2885 switch (bs->breakpoint_at->type)
2891 case bp_hardware_breakpoint:
2897 bs_class = bp_noisy;
2899 bs_class = bp_silent;
2902 bs_class = bp_nostop;
2905 case bp_hardware_watchpoint:
2906 case bp_read_watchpoint:
2907 case bp_access_watchpoint:
2911 bs_class = wp_noisy;
2913 bs_class = wp_silent;
2916 /* There was a watchpoint, but we're not stopping.
2917 This requires no further action. */
2918 bs_class = no_effect;
2921 bs_class = long_jump;
2923 case bp_longjmp_resume:
2924 bs_class = long_resume;
2926 case bp_step_resume:
2929 bs_class = step_resume;
2932 /* It is for the wrong frame. */
2933 bs_class = bp_nostop;
2935 case bp_through_sigtramp:
2936 bs_class = through_sig;
2938 case bp_watchpoint_scope:
2939 bs_class = bp_nostop;
2941 case bp_shlib_event:
2942 bs_class = shlib_event;
2944 case bp_thread_event:
2945 bs_class = bp_nostop;
2948 case bp_catch_unload:
2949 /* Only if this catchpoint triggered should we cause the
2950 step-out-of-dld behaviour. Otherwise, we ignore this
2953 bs_class = catch_shlib_event;
2955 bs_class = no_effect;
2958 case bp_catch_vfork:
2963 bs_class = bp_noisy;
2965 bs_class = bp_silent;
2968 /* There was a catchpoint, but we're not stopping.
2969 This requires no further action. */
2970 bs_class = no_effect;
2972 case bp_catch_catch:
2973 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2974 bs_class = bp_nostop;
2976 bs_class = bs->print ? bp_noisy : bp_silent;
2978 case bp_catch_throw:
2979 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2980 bs_class = bp_nostop;
2982 bs_class = bs->print ? bp_noisy : bp_silent;
2985 /* Make sure the action is stop (silent or noisy),
2986 so infrun.c pops the dummy frame. */
2987 bs_class = bp_silent;
2988 retval.call_dummy = 1;
2991 current_action = table[(int) bs_class][(int) current_action];
2993 retval.main_action = current_action;
2997 /* Nonzero if we should step constantly (e.g. watchpoints on machines
2998 without hardware support). This isn't related to a specific bpstat,
2999 just to things like whether watchpoints are set. */
3002 bpstat_should_step ()
3004 struct breakpoint *b;
3006 if (b->enable == enabled && b->type == bp_watchpoint)
3011 /* Nonzero if there are enabled hardware watchpoints. */
3013 bpstat_have_active_hw_watchpoints ()
3015 struct breakpoint *b;
3017 if ((b->enable == enabled) &&
3019 ((b->type == bp_hardware_watchpoint) ||
3020 (b->type == bp_read_watchpoint) ||
3021 (b->type == bp_access_watchpoint)))
3027 /* Given a bpstat that records zero or more triggered eventpoints, this
3028 function returns another bpstat which contains only the catchpoints
3029 on that first list, if any. */
3031 bpstat_get_triggered_catchpoints (ep_list, cp_list)
3035 struct bpstats root_bs[1];
3036 bpstat bs = root_bs;
3037 struct breakpoint *ep;
3040 bpstat_clear (cp_list);
3041 root_bs->next = NULL;
3043 for (; ep_list != NULL; ep_list = ep_list->next)
3045 /* Is this eventpoint a catchpoint? If not, ignore it. */
3046 ep = ep_list->breakpoint_at;
3049 if ((ep->type != bp_catch_load) &&
3050 (ep->type != bp_catch_unload) &&
3051 (ep->type != bp_catch_catch) &&
3052 (ep->type != bp_catch_throw))
3053 /* pai: (temp) ADD fork/vfork here!! */
3056 /* Yes; add it to the list. */
3057 bs = bpstat_alloc (ep, bs);
3062 #if defined(SOLIB_ADD)
3063 /* Also, for each triggered catchpoint, tag it with the name of
3064 the library that caused this trigger. (We copy the name now,
3065 because it's only guaranteed to be available NOW, when the
3066 catchpoint triggers. Clients who may wish to know the name
3067 later must get it from the catchpoint itself.) */
3068 if (ep->triggered_dll_pathname != NULL)
3069 free (ep->triggered_dll_pathname);
3070 if (ep->type == bp_catch_load)
3071 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid);
3073 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid);
3075 dll_pathname = NULL;
3079 ep->triggered_dll_pathname = (char *)
3080 xmalloc (strlen (dll_pathname) + 1);
3081 strcpy (ep->triggered_dll_pathname, dll_pathname);
3084 ep->triggered_dll_pathname = NULL;
3090 /* Print B to gdb_stdout. */
3092 print_one_breakpoint (struct breakpoint *b,
3093 CORE_ADDR *last_addr)
3095 register struct command_line *l;
3096 register struct symbol *sym;
3097 struct ep_type_description
3102 static struct ep_type_description bptypes[] =
3104 {bp_none, "?deleted?"},
3105 {bp_breakpoint, "breakpoint"},
3106 {bp_hardware_breakpoint, "hw breakpoint"},
3107 {bp_until, "until"},
3108 {bp_finish, "finish"},
3109 {bp_watchpoint, "watchpoint"},
3110 {bp_hardware_watchpoint, "hw watchpoint"},
3111 {bp_read_watchpoint, "read watchpoint"},
3112 {bp_access_watchpoint, "acc watchpoint"},
3113 {bp_longjmp, "longjmp"},
3114 {bp_longjmp_resume, "longjmp resume"},
3115 {bp_step_resume, "step resume"},
3116 {bp_through_sigtramp, "sigtramp"},
3117 {bp_watchpoint_scope, "watchpoint scope"},
3118 {bp_call_dummy, "call dummy"},
3119 {bp_shlib_event, "shlib events"},
3120 {bp_thread_event, "thread events"},
3121 {bp_catch_load, "catch load"},
3122 {bp_catch_unload, "catch unload"},
3123 {bp_catch_fork, "catch fork"},
3124 {bp_catch_vfork, "catch vfork"},
3125 {bp_catch_exec, "catch exec"},
3126 {bp_catch_catch, "catch catch"},
3127 {bp_catch_throw, "catch throw"}
3130 static char *bpdisps[] =
3131 {"del", "dstp", "dis", "keep"};
3132 static char bpenables[] = "nynny";
3133 char wrap_indent[80];
3135 struct ui_stream *stb = ui_out_stream_new (uiout);
3136 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3141 ui_out_list_begin (uiout, "bkpt");
3147 ui_out_field_int (uiout, "number", b->number);
3149 printf_filtered ("%-3d ", b->number);
3154 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3155 || ((int) b->type != bptypes[(int) b->type].type))
3156 internal_error ("bptypes table does not describe type #%d.",
3159 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3161 printf_filtered ("%-14s ", bptypes[(int) b->type].description);
3167 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3169 printf_filtered ("%-4s ", bpdisps[(int) b->disposition]);
3175 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable]);
3176 ui_out_spaces (uiout, 2);
3178 printf_filtered ("%-3c ", bpenables[(int) b->enable]);
3182 strcpy (wrap_indent, " ");
3184 strcat (wrap_indent, " ");
3188 internal_error ("print_one_breakpoint: bp_none encountered\n");
3192 case bp_hardware_watchpoint:
3193 case bp_read_watchpoint:
3194 case bp_access_watchpoint:
3195 /* Field 4, the address, is omitted (which makes the columns
3196 not line up too nicely with the headers, but the effect
3197 is relatively readable). */
3200 ui_out_field_skip (uiout, "addr");
3202 print_expression (b->exp, stb->stream);
3203 ui_out_field_stream (uiout, "what", stb);
3206 print_expression (b->exp, gdb_stdout);
3211 case bp_catch_unload:
3212 /* Field 4, the address, is omitted (which makes the columns
3213 not line up too nicely with the headers, but the effect
3214 is relatively readable). */
3217 ui_out_field_skip (uiout, "addr");
3219 if (b->dll_pathname == NULL)
3221 ui_out_field_string (uiout, "what", "<any library>");
3222 ui_out_spaces (uiout, 1);
3226 ui_out_text (uiout, "library \"");
3227 ui_out_field_string (uiout, "what", b->dll_pathname);
3228 ui_out_text (uiout, "\" ");
3232 if (b->dll_pathname == NULL)
3233 printf_filtered ("<any library> ");
3235 printf_filtered ("library \"%s\" ", b->dll_pathname);
3240 case bp_catch_vfork:
3241 /* Field 4, the address, is omitted (which makes the columns
3242 not line up too nicely with the headers, but the effect
3243 is relatively readable). */
3246 ui_out_field_skip (uiout, "addr");
3248 if (b->forked_inferior_pid != 0)
3250 ui_out_text (uiout, "process ");
3251 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3252 ui_out_spaces (uiout, 1);
3256 if (b->forked_inferior_pid != 0)
3257 printf_filtered ("process %d ", b->forked_inferior_pid);
3262 /* Field 4, the address, is omitted (which makes the columns
3263 not line up too nicely with the headers, but the effect
3264 is relatively readable). */
3267 ui_out_field_skip (uiout, "addr");
3269 if (b->exec_pathname != NULL)
3271 ui_out_text (uiout, "program \"");
3272 ui_out_field_string (uiout, "what", b->exec_pathname);
3273 ui_out_text (uiout, "\" ");
3277 if (b->exec_pathname != NULL)
3278 printf_filtered ("program \"%s\" ", b->exec_pathname);
3282 case bp_catch_catch:
3283 /* Field 4, the address, is omitted (which makes the columns
3284 not line up too nicely with the headers, but the effect
3285 is relatively readable). */
3288 ui_out_field_skip (uiout, "addr");
3290 ui_out_field_string (uiout, "what", "exception catch");
3291 ui_out_spaces (uiout, 1);
3294 printf_filtered ("exception catch ");
3298 case bp_catch_throw:
3299 /* Field 4, the address, is omitted (which makes the columns
3300 not line up too nicely with the headers, but the effect
3301 is relatively readable). */
3304 ui_out_field_skip (uiout, "addr");
3306 ui_out_field_string (uiout, "what", "exception throw");
3307 ui_out_spaces (uiout, 1);
3310 printf_filtered ("exception throw ");
3315 case bp_hardware_breakpoint:
3319 case bp_longjmp_resume:
3320 case bp_step_resume:
3321 case bp_through_sigtramp:
3322 case bp_watchpoint_scope:
3324 case bp_shlib_event:
3325 case bp_thread_event:
3330 ui_out_field_core_addr (uiout, "addr", b->address);
3333 *last_addr = b->address;
3336 sym = find_pc_sect_function (b->address, b->section);
3339 ui_out_text (uiout, "in ");
3340 ui_out_field_string (uiout, "func",
3341 SYMBOL_SOURCE_NAME (sym));
3342 ui_out_wrap_hint (uiout, wrap_indent);
3343 ui_out_text (uiout, " at ");
3345 ui_out_field_string (uiout, "file", b->source_file);
3346 ui_out_text (uiout, ":");
3347 ui_out_field_int (uiout, "line", b->line_number);
3351 print_address_symbolic (b->address, stb->stream, demangle, "");
3352 ui_out_field_stream (uiout, "at", stb);
3358 /* FIXME-32x64: need a print_address_numeric with
3362 local_hex_string_custom
3363 ((unsigned long) b->address, "08l"));
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_list_begin (uiout, "script");
3494 print_command_lines (uiout, l, 4);
3495 ui_out_list_end (uiout);
3499 print_command_line (l, 4, gdb_stdout);
3505 ui_out_list_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 (bnum, allflag)
3552 register struct breakpoint *b;
3553 CORE_ADDR last_addr = (CORE_ADDR) -1;
3554 int found_a_breakpoint = 0;
3558 ui_out_table_begin (uiout, 6, "BreakpointTable");
3560 ui_out_table_begin (uiout, 5, "BreakpointTable");
3565 || bnum == b->number)
3567 /* We only print out user settable breakpoints unless the
3570 && b->type != bp_breakpoint
3571 && b->type != bp_catch_load
3572 && b->type != bp_catch_unload
3573 && b->type != bp_catch_fork
3574 && b->type != bp_catch_vfork
3575 && b->type != bp_catch_exec
3576 && b->type != bp_catch_catch
3577 && b->type != bp_catch_throw
3578 && b->type != bp_hardware_breakpoint
3579 && b->type != bp_watchpoint
3580 && b->type != bp_read_watchpoint
3581 && b->type != bp_access_watchpoint
3582 && b->type != bp_hardware_watchpoint)
3585 if (!found_a_breakpoint++)
3587 annotate_breakpoints_headers ();
3590 ui_out_table_header (uiout, 3, ui_left, "Num"); /* 1 */
3592 ui_out_table_header (uiout, 14, ui_left, "Type"); /* 2 */
3594 ui_out_table_header (uiout, 4, ui_left, "Disp"); /* 3 */
3596 ui_out_table_header (uiout, 3, ui_left, "Enb"); /* 4 */
3600 ui_out_table_header (uiout, 10, ui_left, "Address"); /* 5 */
3603 ui_out_table_header (uiout, 40, ui_noalign, "What"); /* 6 */
3604 ui_out_table_body (uiout);
3607 printf_filtered ("Num ");
3609 printf_filtered ("Type ");
3611 printf_filtered ("Disp ");
3613 printf_filtered ("Enb ");
3617 printf_filtered ("Address ");
3620 printf_filtered ("What\n");
3622 annotate_breakpoints_table ();
3625 print_one_breakpoint (b, &last_addr);
3628 if (!found_a_breakpoint)
3632 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3634 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3638 printf_filtered ("No breakpoints or watchpoints.\n");
3640 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
3645 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3646 that a comparison of an unsigned with -1 is always false. */
3647 if (last_addr != (CORE_ADDR) -1)
3648 set_next_address (last_addr);
3652 ui_out_table_end (uiout);
3654 /* FIXME? Should this be moved up so that it is only called when
3655 there have been breakpoints? */
3656 annotate_breakpoints_table_end ();
3661 breakpoints_info (bnum_exp, from_tty)
3668 bnum = parse_and_eval_address (bnum_exp);
3670 breakpoint_1 (bnum, 0);
3675 maintenance_info_breakpoints (bnum_exp, from_tty)
3682 bnum = parse_and_eval_address (bnum_exp);
3684 breakpoint_1 (bnum, 1);
3687 /* Print a message describing any breakpoints set at PC. */
3690 describe_other_breakpoints (pc, section)
3694 register int others = 0;
3695 register struct breakpoint *b;
3698 if (b->address == pc)
3699 if (overlay_debugging == 0 ||
3700 b->section == section)
3704 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3706 if (b->address == pc)
3707 if (overlay_debugging == 0 ||
3708 b->section == section)
3714 ((b->enable == disabled ||
3715 b->enable == shlib_disabled ||
3716 b->enable == call_disabled) ? " (disabled)"
3717 : b->enable == permanent ? " (permanent)"
3719 (others > 1) ? "," : ((others == 1) ? " and" : ""));
3721 printf_filtered ("also set at pc ");
3722 print_address_numeric (pc, 1, gdb_stdout);
3723 printf_filtered (".\n");
3727 /* Set the default place to put a breakpoint
3728 for the `break' command with no arguments. */
3731 set_default_breakpoint (valid, addr, symtab, line)
3734 struct symtab *symtab;
3737 default_breakpoint_valid = valid;
3738 default_breakpoint_address = addr;
3739 default_breakpoint_symtab = symtab;
3740 default_breakpoint_line = line;
3743 /* Rescan breakpoints at address ADDRESS,
3744 marking the first one as "first" and any others as "duplicates".
3745 This is so that the bpt instruction is only inserted once.
3746 If we have a permanent breakpoint at ADDRESS, make that one
3747 the official one, and the rest as duplicates. */
3750 check_duplicates (address, section)
3754 register struct breakpoint *b;
3755 register int count = 0;
3756 struct breakpoint *perm_bp = 0;
3758 if (address == 0) /* Watchpoints are uninteresting */
3762 if (b->enable != disabled
3763 && b->enable != shlib_disabled
3764 && b->enable != call_disabled
3765 && b->address == address
3766 && (overlay_debugging == 0 || b->section == section))
3768 /* Have we found a permanent breakpoint? */
3769 if (b->enable == permanent)
3776 b->duplicate = count > 1;
3779 /* If we found a permanent breakpoint at this address, go over the
3780 list again and declare all the other breakpoints there to be the
3784 perm_bp->duplicate = 0;
3786 /* Permanent breakpoint should always be inserted. */
3787 if (! perm_bp->inserted)
3788 internal_error ("allegedly permanent breakpoint is not "
3789 "actually inserted");
3795 internal_error ("another breakpoint was inserted on top of "
3796 "a permanent breakpoint");
3798 if (b->enable != disabled
3799 && b->enable != shlib_disabled
3800 && b->enable != call_disabled
3801 && b->address == address
3802 && (overlay_debugging == 0 || b->section == section))
3808 /* Low level routine to set a breakpoint.
3809 Takes as args the three things that every breakpoint must have.
3810 Returns the breakpoint object so caller can set other things.
3811 Does not set the breakpoint number!
3812 Does not print anything.
3814 ==> This routine should not be called if there is a chance of later
3815 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
3816 your arguments BEFORE calling this routine! */
3819 set_raw_breakpoint (sal)
3820 struct symtab_and_line sal;
3822 register struct breakpoint *b, *b1;
3824 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3825 memset (b, 0, sizeof (*b));
3826 b->address = sal.pc;
3827 if (sal.symtab == NULL)
3828 b->source_file = NULL;
3830 b->source_file = savestring (sal.symtab->filename,
3831 strlen (sal.symtab->filename));
3832 b->section = sal.section;
3833 b->language = current_language->la_language;
3834 b->input_radix = input_radix;
3836 b->line_number = sal.line;
3837 b->enable = enabled;
3840 b->ignore_count = 0;
3843 b->dll_pathname = NULL;
3844 b->triggered_dll_pathname = NULL;
3845 b->forked_inferior_pid = 0;
3846 b->exec_pathname = NULL;
3848 /* Add this breakpoint to the end of the chain
3849 so that a list of breakpoints will come out in order
3850 of increasing numbers. */
3852 b1 = breakpoint_chain;
3854 breakpoint_chain = b;
3862 check_duplicates (sal.pc, sal.section);
3863 breakpoints_changed ();
3869 /* Note that the breakpoint object B describes a permanent breakpoint
3870 instruction, hard-wired into the inferior's code. */
3872 make_breakpoint_permanent (struct breakpoint *b)
3874 b->enable = permanent;
3876 /* By definition, permanent breakpoints are already present in the code. */
3880 #ifdef GET_LONGJMP_TARGET
3883 create_longjmp_breakpoint (func_name)
3886 struct symtab_and_line sal;
3887 struct breakpoint *b;
3889 INIT_SAL (&sal); /* initialize to zeroes */
3890 if (func_name != NULL)
3892 struct minimal_symbol *m;
3894 m = lookup_minimal_symbol_text (func_name, NULL,
3895 (struct objfile *) NULL);
3897 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3901 sal.section = find_pc_overlay (sal.pc);
3902 b = set_raw_breakpoint (sal);
3906 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
3907 b->disposition = donttouch;
3908 b->enable = disabled;
3911 b->addr_string = strsave (func_name);
3912 b->number = internal_breakpoint_number--;
3915 #endif /* #ifdef GET_LONGJMP_TARGET */
3917 /* Call this routine when stepping and nexting to enable a breakpoint
3918 if we do a longjmp(). When we hit that breakpoint, call
3919 set_longjmp_resume_breakpoint() to figure out where we are going. */
3922 enable_longjmp_breakpoint ()
3924 register struct breakpoint *b;
3927 if (b->type == bp_longjmp)
3929 b->enable = enabled;
3930 check_duplicates (b->address, b->section);
3935 disable_longjmp_breakpoint ()
3937 register struct breakpoint *b;
3940 if (b->type == bp_longjmp
3941 || b->type == bp_longjmp_resume)
3943 b->enable = disabled;
3944 check_duplicates (b->address, b->section);
3949 create_thread_event_breakpoint (address)
3952 struct breakpoint *b;
3953 struct symtab_and_line sal;
3954 char addr_string[80]; /* Surely an addr can't be longer than that. */
3956 INIT_SAL (&sal); /* initialize to zeroes */
3958 sal.section = find_pc_overlay (sal.pc);
3959 if ((b = set_raw_breakpoint (sal)) == NULL)
3962 b->number = internal_breakpoint_number--;
3963 b->disposition = donttouch;
3964 b->type = bp_thread_event; /* XXX: do we need a new type?
3966 b->enable = enabled;
3967 /* addr_string has to be used or breakpoint_re_set will delete me. */
3968 sprintf (addr_string, "*0x%s", paddr (b->address));
3969 b->addr_string = strsave (addr_string);
3975 remove_thread_event_breakpoints (void)
3977 struct breakpoint *b, *temp;
3979 ALL_BREAKPOINTS_SAFE (b, temp)
3980 if (b->type == bp_thread_event)
3981 delete_breakpoint (b);
3986 remove_solib_event_breakpoints ()
3988 register struct breakpoint *b, *temp;
3990 ALL_BREAKPOINTS_SAFE (b, temp)
3991 if (b->type == bp_shlib_event)
3992 delete_breakpoint (b);
3996 create_solib_event_breakpoint (address)
3999 struct breakpoint *b;
4000 struct symtab_and_line sal;
4002 INIT_SAL (&sal); /* initialize to zeroes */
4004 sal.section = find_pc_overlay (sal.pc);
4005 b = set_raw_breakpoint (sal);
4006 b->number = internal_breakpoint_number--;
4007 b->disposition = donttouch;
4008 b->type = bp_shlib_event;
4013 /* Disable any breakpoints that are on code in shared libraries. Only
4014 apply to enabled breakpoints, disabled ones can just stay disabled. */
4017 disable_breakpoints_in_shlibs (silent)
4020 struct breakpoint *b;
4021 int disabled_shlib_breaks = 0;
4023 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4026 #if defined (PC_SOLIB)
4027 if (((b->type == bp_breakpoint) ||
4028 (b->type == bp_hardware_breakpoint)) &&
4029 b->enable == enabled &&
4031 PC_SOLIB (b->address))
4033 b->enable = shlib_disabled;
4036 if (!disabled_shlib_breaks)
4038 target_terminal_ours_for_output ();
4039 warning ("Temporarily disabling shared library breakpoints:");
4041 disabled_shlib_breaks = 1;
4042 warning ("breakpoint #%d ", b->number);
4049 /* Try to reenable any breakpoints in shared libraries. */
4051 re_enable_breakpoints_in_shlibs ()
4053 struct breakpoint *b;
4056 if (b->enable == shlib_disabled)
4060 /* Do not reenable the breakpoint if the shared library
4061 is still not mapped in. */
4062 if (target_read_memory (b->address, buf, 1) == 0)
4063 b->enable = enabled;
4070 solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind)
4075 enum bptype bp_kind;
4077 struct breakpoint *b;
4078 struct symtabs_and_lines sals;
4079 struct cleanup *old_chain;
4080 struct cleanup *canonical_strings_chain = NULL;
4081 char *addr_start = hookname;
4082 char *addr_end = NULL;
4083 char **canonical = (char **) NULL;
4084 int thread = -1; /* All threads. */
4086 /* Set a breakpoint on the specified hook. */
4087 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4088 addr_end = hookname;
4090 if (sals.nelts == 0)
4092 warning ("Unable to set a breakpoint on dynamic linker callback.");
4093 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4094 warning ("GDB will be unable to track shl_load/shl_unload calls");
4097 if (sals.nelts != 1)
4099 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4100 warning ("GDB will be unable to track shl_load/shl_unload calls");
4104 /* Make sure that all storage allocated in decode_line_1 gets freed
4105 in case the following errors out. */
4106 old_chain = make_cleanup (free, sals.sals);
4107 if (canonical != (char **) NULL)
4109 make_cleanup (free, canonical);
4110 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4111 if (canonical[0] != NULL)
4112 make_cleanup (free, canonical[0]);
4115 resolve_sal_pc (&sals.sals[0]);
4117 /* Remove the canonical strings from the cleanup, they are needed below. */
4118 if (canonical != (char **) NULL)
4119 discard_cleanups (canonical_strings_chain);
4121 b = set_raw_breakpoint (sals.sals[0]);
4122 set_breakpoint_count (breakpoint_count + 1);
4123 b->number = breakpoint_count;
4125 b->cond_string = (cond_string == NULL) ?
4126 NULL : savestring (cond_string, strlen (cond_string));
4129 if (canonical != (char **) NULL && canonical[0] != NULL)
4130 b->addr_string = canonical[0];
4131 else if (addr_start)
4132 b->addr_string = savestring (addr_start, addr_end - addr_start);
4134 b->enable = enabled;
4135 b->disposition = tempflag ? del : donttouch;
4137 if (dll_pathname == NULL)
4138 b->dll_pathname = NULL;
4141 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4142 strcpy (b->dll_pathname, dll_pathname);
4147 do_cleanups (old_chain);
4151 create_solib_load_event_breakpoint (hookname, tempflag,
4152 dll_pathname, cond_string)
4158 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4159 cond_string, bp_catch_load);
4163 create_solib_unload_event_breakpoint (hookname, tempflag,
4164 dll_pathname, cond_string)
4170 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4171 cond_string, bp_catch_unload);
4175 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind)
4178 enum bptype bp_kind;
4180 struct symtab_and_line sal;
4181 struct breakpoint *b;
4182 int thread = -1; /* All threads. */
4189 b = set_raw_breakpoint (sal);
4190 set_breakpoint_count (breakpoint_count + 1);
4191 b->number = breakpoint_count;
4193 b->cond_string = (cond_string == NULL) ?
4194 NULL : savestring (cond_string, strlen (cond_string));
4196 b->addr_string = NULL;
4197 b->enable = enabled;
4198 b->disposition = tempflag ? del : donttouch;
4199 b->forked_inferior_pid = 0;
4207 create_fork_event_catchpoint (tempflag, cond_string)
4211 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4215 create_vfork_event_catchpoint (tempflag, cond_string)
4219 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4223 create_exec_event_catchpoint (tempflag, cond_string)
4227 struct symtab_and_line sal;
4228 struct breakpoint *b;
4229 int thread = -1; /* All threads. */
4236 b = set_raw_breakpoint (sal);
4237 set_breakpoint_count (breakpoint_count + 1);
4238 b->number = breakpoint_count;
4240 b->cond_string = (cond_string == NULL) ?
4241 NULL : savestring (cond_string, strlen (cond_string));
4243 b->addr_string = NULL;
4244 b->enable = enabled;
4245 b->disposition = tempflag ? del : donttouch;
4247 b->type = bp_catch_exec;
4253 hw_breakpoint_used_count ()
4255 register struct breakpoint *b;
4260 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
4268 hw_watchpoint_used_count (type, other_type_used)
4270 int *other_type_used;
4272 register struct breakpoint *b;
4275 *other_type_used = 0;
4278 if (b->enable == enabled)
4280 if (b->type == type)
4282 else if ((b->type == bp_hardware_watchpoint ||
4283 b->type == bp_read_watchpoint ||
4284 b->type == bp_access_watchpoint)
4285 && b->enable == enabled)
4286 *other_type_used = 1;
4292 /* Call this after hitting the longjmp() breakpoint. Use this to set
4293 a new breakpoint at the target of the jmp_buf.
4295 FIXME - This ought to be done by setting a temporary breakpoint
4296 that gets deleted automatically... */
4299 set_longjmp_resume_breakpoint (pc, frame)
4301 struct frame_info *frame;
4303 register struct breakpoint *b;
4306 if (b->type == bp_longjmp_resume)
4309 b->enable = enabled;
4311 b->frame = frame->frame;
4314 check_duplicates (b->address, b->section);
4320 disable_watchpoints_before_interactive_call_start ()
4322 struct breakpoint *b;
4326 if (((b->type == bp_watchpoint)
4327 || (b->type == bp_hardware_watchpoint)
4328 || (b->type == bp_read_watchpoint)
4329 || (b->type == bp_access_watchpoint)
4330 || ep_is_exception_catchpoint (b))
4331 && (b->enable == enabled))
4333 b->enable = call_disabled;
4334 check_duplicates (b->address, b->section);
4340 enable_watchpoints_after_interactive_call_stop ()
4342 struct breakpoint *b;
4346 if (((b->type == bp_watchpoint)
4347 || (b->type == bp_hardware_watchpoint)
4348 || (b->type == bp_read_watchpoint)
4349 || (b->type == bp_access_watchpoint)
4350 || ep_is_exception_catchpoint (b))
4351 && (b->enable == call_disabled))
4353 b->enable = enabled;
4354 check_duplicates (b->address, b->section);
4360 /* Set a breakpoint that will evaporate an end of command
4361 at address specified by SAL.
4362 Restrict it to frame FRAME if FRAME is nonzero. */
4365 set_momentary_breakpoint (sal, frame, type)
4366 struct symtab_and_line sal;
4367 struct frame_info *frame;
4370 register struct breakpoint *b;
4371 b = set_raw_breakpoint (sal);
4373 b->enable = enabled;
4374 b->disposition = donttouch;
4375 b->frame = (frame ? frame->frame : 0);
4377 /* If we're debugging a multi-threaded program, then we
4378 want momentary breakpoints to be active in only a
4379 single thread of control. */
4380 if (in_thread_list (inferior_pid))
4381 b->thread = pid_to_thread_id (inferior_pid);
4387 /* Tell the user we have just set a breakpoint B. */
4391 struct breakpoint *b;
4395 struct cleanup *old_chain;
4396 struct ui_stream *stb;
4398 stb = ui_out_stream_new (uiout);
4399 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
4402 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4403 watchpoint) other than breakpoint creation. It should be possible to
4404 clean this up and at the same time replace the random calls to
4405 breakpoint_changed with this hook, as has already been done for
4406 delete_breakpoint_hook and so on. */
4407 if (create_breakpoint_hook)
4408 create_breakpoint_hook (b);
4409 breakpoint_create_event (b->number);
4414 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4418 ui_out_text (uiout, "Watchpoint ");
4419 ui_out_list_begin (uiout, "wpt");
4420 ui_out_field_int (uiout, "number", b->number);
4421 ui_out_text (uiout, ": ");
4422 print_expression (b->exp, stb->stream);
4423 ui_out_field_stream (uiout, "exp", stb);
4424 ui_out_list_end (uiout);
4426 case bp_hardware_watchpoint:
4427 ui_out_text (uiout, "Hardware watchpoint ");
4428 ui_out_list_begin (uiout, "wpt");
4429 ui_out_field_int (uiout, "number", b->number);
4430 ui_out_text (uiout, ": ");
4431 print_expression (b->exp, stb->stream);
4432 ui_out_field_stream (uiout, "exp", stb);
4433 ui_out_list_end (uiout);
4437 printf_filtered ("Watchpoint %d: ", b->number);
4438 print_expression (b->exp, gdb_stdout);
4440 case bp_hardware_watchpoint:
4441 printf_filtered ("Hardware watchpoint %d: ", b->number);
4442 print_expression (b->exp, gdb_stdout);
4446 case bp_read_watchpoint:
4447 ui_out_text (uiout, "Hardware read watchpoint ");
4448 ui_out_list_begin (uiout, "hw-rwpt");
4449 ui_out_field_int (uiout, "number", b->number);
4450 ui_out_text (uiout, ": ");
4451 print_expression (b->exp, stb->stream);
4452 ui_out_field_stream (uiout, "exp", stb);
4453 ui_out_list_end (uiout);
4455 case bp_access_watchpoint:
4456 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4457 ui_out_list_begin (uiout, "hw-awpt");
4458 ui_out_field_int (uiout, "number", b->number);
4459 ui_out_text (uiout, ": ");
4460 print_expression (b->exp, stb->stream);
4461 ui_out_field_stream (uiout, "exp", stb);
4462 ui_out_list_end (uiout);
4465 case bp_read_watchpoint:
4466 printf_filtered ("Hardware read watchpoint %d: ", b->number);
4467 print_expression (b->exp, gdb_stdout);
4469 case bp_access_watchpoint:
4470 printf_filtered ("Hardware access (read/write) watchpoint %d: ",
4472 print_expression (b->exp, gdb_stdout);
4477 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4483 printf_filtered ("Breakpoint %d", b->number);
4486 case bp_hardware_breakpoint:
4488 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4494 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4498 case bp_catch_unload:
4499 printf_filtered ("Catchpoint %d (%s %s)",
4501 (b->type == bp_catch_load) ? "load" : "unload",
4502 (b->dll_pathname != NULL) ?
4503 b->dll_pathname : "<any library>");
4506 case bp_catch_vfork:
4507 printf_filtered ("Catchpoint %d (%s)",
4509 (b->type == bp_catch_fork) ? "fork" : "vfork");
4512 printf_filtered ("Catchpoint %d (exec)",
4515 case bp_catch_catch:
4516 case bp_catch_throw:
4517 printf_filtered ("Catchpoint %d (%s)",
4519 (b->type == bp_catch_catch) ? "catch" : "throw");
4525 case bp_longjmp_resume:
4526 case bp_step_resume:
4527 case bp_through_sigtramp:
4529 case bp_watchpoint_scope:
4530 case bp_shlib_event:
4531 case bp_thread_event:
4536 if (addressprint || b->source_file == NULL)
4538 printf_filtered (" at ");
4539 print_address_numeric (b->address, 1, gdb_stdout);
4542 printf_filtered (": file %s, line %d.",
4543 b->source_file, b->line_number);
4544 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1));
4545 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
4548 do_cleanups (old_chain);
4551 if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
4554 printf_filtered ("\n");
4558 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4559 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4560 COND[i] and COND_STRING[i] values.
4562 NOTE: If the function succeeds, the caller is expected to cleanup
4563 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4564 array contents). If the function fails (error() is called), the
4565 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4566 COND and SALS arrays and each of those arrays contents. */
4569 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4570 struct expression **cond, char **cond_string,
4571 enum bptype type, enum bpdisp disposition,
4572 int thread, int ignore_count, int from_tty)
4574 if (type == bp_hardware_breakpoint)
4576 int i = hw_breakpoint_used_count ();
4577 int target_resources_ok =
4578 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4580 if (target_resources_ok == 0)
4581 error ("No hardware breakpoint support in the target.");
4582 else if (target_resources_ok < 0)
4583 error ("Hardware breakpoints used exceeds limit.");
4586 /* Now set all the breakpoints. */
4589 for (i = 0; i < sals.nelts; i++)
4591 struct breakpoint *b;
4592 struct symtab_and_line sal = sals.sals[i];
4595 describe_other_breakpoints (sal.pc, sal.section);
4597 b = set_raw_breakpoint (sal);
4598 set_breakpoint_count (breakpoint_count + 1);
4599 b->number = breakpoint_count;
4603 b->addr_string = addr_string[i];
4604 b->cond_string = cond_string[i];
4605 b->ignore_count = ignore_count;
4606 b->enable = enabled;
4607 b->disposition = disposition;
4613 /* Parse ARG which is assumed to be a SAL specification possibly
4614 followed by conditionals. On return, SALS contains an array of SAL
4615 addresses found. ADDR_STRING contains a vector of (canonical)
4616 address strings. ARG points to the end of the SAL. */
4619 parse_breakpoint_sals (char **address,
4620 struct symtabs_and_lines *sals,
4621 char ***addr_string)
4623 char *addr_start = *address;
4624 *addr_string = NULL;
4625 /* If no arg given, or if first arg is 'if ', use the default
4627 if ((*address) == NULL
4628 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4630 if (default_breakpoint_valid)
4632 struct symtab_and_line sal;
4633 INIT_SAL (&sal); /* initialize to zeroes */
4634 sals->sals = (struct symtab_and_line *)
4635 xmalloc (sizeof (struct symtab_and_line));
4636 sal.pc = default_breakpoint_address;
4637 sal.line = default_breakpoint_line;
4638 sal.symtab = default_breakpoint_symtab;
4639 sal.section = find_pc_overlay (sal.pc);
4640 sals->sals[0] = sal;
4644 error ("No default breakpoint address now.");
4648 /* Force almost all breakpoints to be in terms of the
4649 current_source_symtab (which is decode_line_1's default). This
4650 should produce the results we want almost all of the time while
4651 leaving default_breakpoint_* alone. */
4652 if (default_breakpoint_valid
4653 && (!current_source_symtab
4654 || (strchr ("+-", (*address)[0]) != NULL)))
4655 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4656 default_breakpoint_line, addr_string);
4658 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4660 /* For any SAL that didn't have a canonical string, fill one in. */
4661 if (sals->nelts > 0 && *addr_string == NULL)
4662 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4663 if (addr_start != (*address))
4666 for (i = 0; i < sals->nelts; i++)
4668 /* Add the string if not present. */
4669 if ((*addr_string)[i] == NULL)
4670 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4676 /* Convert each SAL into a real PC. Verify that the PC can be
4677 inserted as a breakpoint. If it can't throw an error. */
4680 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4684 for (i = 0; i < sals->nelts; i++)
4686 resolve_sal_pc (&sals->sals[i]);
4688 /* It's possible for the PC to be nonzero, but still an illegal
4689 value on some targets.
4691 For example, on HP-UX if you start gdb, and before running the
4692 inferior you try to set a breakpoint on a shared library function
4693 "foo" where the inferior doesn't call "foo" directly but does
4694 pass its address to another function call, then we do find a
4695 minimal symbol for the "foo", but it's address is invalid.
4696 (Appears to be an index into a table that the loader sets up
4697 when the inferior is run.)
4699 Give the target a chance to bless sals.sals[i].pc before we
4700 try to make a breakpoint for it. */
4701 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4703 if (address == NULL)
4704 error ("Cannot break without a running program.");
4706 error ("Cannot break on %s without a running program.",
4712 /* Set a breakpoint according to ARG (function, linenum or *address)
4713 flag: first bit : 0 non-temporary, 1 temporary.
4714 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4717 break_command_1 (arg, flag, from_tty)
4721 int tempflag, hardwareflag;
4722 struct symtabs_and_lines sals;
4723 register struct expression **cond = 0;
4724 /* Pointers in arg to the start, and one past the end, of the
4726 char **cond_string = (char **) NULL;
4727 char *addr_start = arg;
4729 struct cleanup *old_chain;
4730 struct cleanup *breakpoint_chain = NULL;
4733 int ignore_count = 0;
4735 hardwareflag = flag & BP_HARDWAREFLAG;
4736 tempflag = flag & BP_TEMPFLAG;
4741 parse_breakpoint_sals (&arg, &sals, &addr_string);
4746 /* Create a chain of things that always need to be cleaned up. */
4747 old_chain = make_cleanup (null_cleanup, 0);
4749 /* Make sure that all storage allocated to SALS gets freed. */
4750 make_cleanup (free, sals.sals);
4752 /* Cleanup the addr_string array but not its contents. */
4753 make_cleanup (free, addr_string);
4755 /* Allocate space for all the cond expressions. */
4756 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4757 make_cleanup (free, cond);
4759 /* Allocate space for all the cond strings. */
4760 cond_string = xcalloc (sals.nelts, sizeof (char **));
4761 make_cleanup (free, cond_string);
4763 /* ----------------------------- SNIP -----------------------------
4764 Anything added to the cleanup chain beyond this point is assumed
4765 to be part of a breakpoint. If the breakpoint create succeeds
4766 then the memory is not reclaimed. */
4767 breakpoint_chain = make_cleanup (null_cleanup, 0);
4769 /* Mark the contents of the addr_string for cleanup. These go on
4770 the breakpoint_chain and only occure if the breakpoint create
4772 for (i = 0; i < sals.nelts; i++)
4774 if (addr_string[i] != NULL)
4775 make_cleanup (free, addr_string[i]);
4778 /* Resolve all line numbers to PC's and verify that the addresses
4779 are ok for the target. */
4780 breakpoint_sals_to_pc (&sals, addr_start);
4782 /* Verify that condition can be parsed, before setting any
4783 breakpoints. Allocate a separate condition expression for each
4785 thread = -1; /* No specific thread yet */
4786 for (i = 0; i < sals.nelts; i++)
4793 char *cond_start = NULL;
4794 char *cond_end = NULL;
4795 while (*tok == ' ' || *tok == '\t')
4800 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4803 toklen = end_tok - tok;
4805 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4807 tok = cond_start = end_tok + 1;
4808 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4809 make_cleanup (free, cond[i]);
4811 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4812 make_cleanup (free, cond_string[i]);
4814 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4820 thread = strtol (tok, &tok, 0);
4822 error ("Junk after thread keyword.");
4823 if (!valid_thread_id (thread))
4824 error ("Unknown thread %d\n", thread);
4827 error ("Junk at end of arguments.");
4831 create_breakpoints (sals, addr_string, cond, cond_string,
4832 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4833 tempflag ? del : donttouch,
4834 thread, ignore_count, from_tty);
4838 warning ("Multiple breakpoints were set.");
4839 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4841 /* That's it. Discard the cleanups for data inserted into the
4843 discard_cleanups (breakpoint_chain);
4844 /* But cleanup everything else. */
4845 do_cleanups (old_chain);
4848 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4849 linenum or *address) with COND and IGNORE_COUNT. */
4851 struct captured_breakpoint_args
4862 do_captured_breakpoint (void *data)
4864 struct captured_breakpoint_args *args = data;
4865 struct symtabs_and_lines sals;
4866 register struct expression **cond;
4867 struct cleanup *old_chain;
4868 struct cleanup *breakpoint_chain = NULL;
4875 /* Parse the source and lines spec. Delay check that the expression
4876 didn't contain trailing garbage until after cleanups are in
4880 address_end = args->address;
4882 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4887 /* Create a chain of things at always need to be cleaned up. */
4888 old_chain = make_cleanup (null_cleanup, 0);
4890 /* Always have a addr_string array, even if it is empty. */
4891 make_cleanup (free, addr_string);
4893 /* Make sure that all storage allocated to SALS gets freed. */
4894 make_cleanup (free, sals.sals);
4896 /* Allocate space for all the cond expressions. */
4897 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4898 make_cleanup (free, cond);
4900 /* Allocate space for all the cond strings. */
4901 cond_string = xcalloc (sals.nelts, sizeof (char **));
4902 make_cleanup (free, cond_string);
4904 /* ----------------------------- SNIP -----------------------------
4905 Anything added to the cleanup chain beyond this point is assumed
4906 to be part of a breakpoint. If the breakpoint create goes
4907 through then that memory is not cleaned up. */
4908 breakpoint_chain = make_cleanup (null_cleanup, 0);
4910 /* Mark the contents of the addr_string for cleanup. These go on
4911 the breakpoint_chain and only occure if the breakpoint create
4913 for (i = 0; i < sals.nelts; i++)
4915 if (addr_string[i] != NULL)
4916 make_cleanup (free, addr_string[i]);
4919 /* Wait until now before checking for garbage at the end of the
4920 address. That way cleanups can take care of freeing any
4922 if (*address_end != '\0')
4923 error ("Garbage %s following breakpoint address", address_end);
4925 /* Resolve all line numbers to PC's. */
4926 breakpoint_sals_to_pc (&sals, args->address);
4928 /* Verify that conditions can be parsed, before setting any
4930 for (i = 0; i < sals.nelts; i++)
4932 if (args->condition != NULL)
4934 char *tok = args->condition;
4935 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4937 error ("Garbage %s follows condition", tok);
4938 make_cleanup (free, cond[i]);
4939 cond_string[i] = xstrdup (args->condition);
4943 create_breakpoints (sals, addr_string, cond, cond_string,
4944 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4945 args->tempflag ? del : donttouch,
4946 args->thread, args->ignore_count, 0/*from-tty*/);
4948 /* That's it. Discard the cleanups for data inserted into the
4950 discard_cleanups (breakpoint_chain);
4951 /* But cleanup everything else. */
4952 do_cleanups (old_chain);
4957 gdb_breakpoint (char *address, char *condition,
4958 int hardwareflag, int tempflag,
4959 int thread, int ignore_count)
4961 struct captured_breakpoint_args args;
4962 args.address = address;
4963 args.condition = condition;
4964 args.hardwareflag = hardwareflag;
4965 args.tempflag = tempflag;
4966 args.thread = thread;
4967 args.ignore_count = ignore_count;
4968 return catch_errors (do_captured_breakpoint, &args,
4969 NULL, RETURN_MASK_ALL);
4974 break_at_finish_at_depth_command_1 (arg, flag, from_tty)
4979 struct frame_info *frame;
4980 CORE_ADDR low, high, selected_pc = 0;
4981 char *extra_args, *level_arg, *addr_string;
4982 int extra_args_len = 0, if_arg = 0;
4985 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4988 if (default_breakpoint_valid)
4992 selected_pc = selected_frame->pc;
4997 error ("No selected frame.");
5000 error ("No default breakpoint address now.");
5004 extra_args = strchr (arg, ' ');
5008 extra_args_len = strlen (extra_args);
5009 level_arg = (char *) xmalloc (extra_args - arg);
5010 strncpy (level_arg, arg, extra_args - arg - 1);
5011 level_arg[extra_args - arg - 1] = '\0';
5015 level_arg = (char *) xmalloc (strlen (arg) + 1);
5016 strcpy (level_arg, arg);
5019 frame = parse_frame_specification (level_arg);
5021 selected_pc = frame->pc;
5028 extra_args_len = strlen (arg);
5033 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5035 addr_string = (char *) xmalloc (26 + extra_args_len);
5037 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
5039 sprintf (addr_string, "*0x%s", paddr_nz (high));
5040 break_command_1 (addr_string, flag, from_tty);
5044 error ("No function contains the specified address");
5047 error ("Unable to set breakpoint at procedure exit");
5052 break_at_finish_command_1 (arg, flag, from_tty)
5057 char *addr_string, *break_string, *beg_addr_string;
5058 CORE_ADDR low, high;
5059 struct symtabs_and_lines sals;
5060 struct symtab_and_line sal;
5061 struct cleanup *old_chain;
5063 int extra_args_len = 0;
5067 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5069 if (default_breakpoint_valid)
5073 addr_string = (char *) xmalloc (15);
5074 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
5079 error ("No selected frame.");
5082 error ("No default breakpoint address now.");
5086 addr_string = (char *) xmalloc (strlen (arg) + 1);
5087 strcpy (addr_string, arg);
5093 extra_args_len = strlen (arg);
5097 /* get the stuff after the function name or address */
5098 extra_args = strchr (arg, ' ');
5102 extra_args_len = strlen (extra_args);
5109 beg_addr_string = addr_string;
5110 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5113 free (beg_addr_string);
5114 old_chain = make_cleanup (free, sals.sals);
5115 for (i = 0; (i < sals.nelts); i++)
5118 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5120 break_string = (char *) xmalloc (extra_args_len + 26);
5122 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
5124 sprintf (break_string, "*0x%s", paddr_nz (high));
5125 break_command_1 (break_string, flag, from_tty);
5126 free (break_string);
5129 error ("No function contains the specified address");
5133 warning ("Multiple breakpoints were set.\n");
5134 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5136 do_cleanups (old_chain);
5140 /* Helper function for break_command_1 and disassemble_command. */
5143 resolve_sal_pc (sal)
5144 struct symtab_and_line *sal;
5148 if (sal->pc == 0 && sal->symtab != NULL)
5150 if (!find_line_pc (sal->symtab, sal->line, &pc))
5151 error ("No line %d in file \"%s\".",
5152 sal->line, sal->symtab->filename);
5156 if (sal->section == 0 && sal->symtab != NULL)
5158 struct blockvector *bv;
5163 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5166 b = BLOCKVECTOR_BLOCK (bv, index);
5167 sym = block_function (b);
5170 fixup_symbol_section (sym, sal->symtab->objfile);
5171 sal->section = SYMBOL_BFD_SECTION (sym);
5175 /* It really is worthwhile to have the section, so we'll just
5176 have to look harder. This case can be executed if we have
5177 line numbers but no functions (as can happen in assembly
5180 struct minimal_symbol *msym;
5182 msym = lookup_minimal_symbol_by_pc (sal->pc);
5184 sal->section = SYMBOL_BFD_SECTION (msym);
5191 break_command (arg, from_tty)
5195 break_command_1 (arg, 0, from_tty);
5199 break_at_finish_command (arg, from_tty)
5203 break_at_finish_command_1 (arg, 0, from_tty);
5207 break_at_finish_at_depth_command (arg, from_tty)
5211 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5215 tbreak_command (arg, from_tty)
5219 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5223 tbreak_at_finish_command (arg, from_tty)
5227 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5231 hbreak_command (arg, from_tty)
5235 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5239 thbreak_command (arg, from_tty)
5243 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5247 stop_command (arg, from_tty)
5251 printf_filtered ("Specify the type of breakpoint to set.\n\
5252 Usage: stop in <function | address>\n\
5257 stopin_command (arg, from_tty)
5263 if (arg == (char *) NULL)
5265 else if (*arg != '*')
5270 /* look for a ':'. If this is a line number specification, then
5271 say it is bad, otherwise, it should be an address or
5272 function/method name */
5273 while (*argptr && !hasColon)
5275 hasColon = (*argptr == ':');
5280 badInput = (*argptr != ':'); /* Not a class::method */
5282 badInput = isdigit (*arg); /* a simple line number */
5286 printf_filtered ("Usage: stop in <function | address>\n");
5288 break_command_1 (arg, 0, from_tty);
5292 stopat_command (arg, from_tty)
5298 if (arg == (char *) NULL || *arg == '*') /* no line number */
5305 /* look for a ':'. If there is a '::' then get out, otherwise
5306 it is probably a line number. */
5307 while (*argptr && !hasColon)
5309 hasColon = (*argptr == ':');
5314 badInput = (*argptr == ':'); /* we have class::method */
5316 badInput = !isdigit (*arg); /* not a line number */
5320 printf_filtered ("Usage: stop at <line>\n");
5322 break_command_1 (arg, 0, from_tty);
5326 /* accessflag: hw_write: watch write,
5327 hw_read: watch read,
5328 hw_access: watch access (read or write) */
5330 watch_command_1 (arg, accessflag, from_tty)
5335 struct breakpoint *b;
5336 struct symtab_and_line sal;
5337 struct expression *exp;
5338 struct block *exp_valid_block;
5339 struct value *val, *mark;
5340 struct frame_info *frame;
5341 struct frame_info *prev_frame = NULL;
5342 char *exp_start = NULL;
5343 char *exp_end = NULL;
5344 char *tok, *end_tok;
5346 char *cond_start = NULL;
5347 char *cond_end = NULL;
5348 struct expression *cond = NULL;
5349 int i, other_type_used, target_resources_ok = 0;
5350 enum bptype bp_type;
5353 INIT_SAL (&sal); /* initialize to zeroes */
5355 /* Parse arguments. */
5356 innermost_block = NULL;
5358 exp = parse_exp_1 (&arg, 0, 0);
5360 exp_valid_block = innermost_block;
5361 mark = value_mark ();
5362 val = evaluate_expression (exp);
5363 release_value (val);
5364 if (VALUE_LAZY (val))
5365 value_fetch_lazy (val);
5368 while (*tok == ' ' || *tok == '\t')
5372 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5375 toklen = end_tok - tok;
5376 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5378 tok = cond_start = end_tok + 1;
5379 cond = parse_exp_1 (&tok, 0, 0);
5383 error ("Junk at end of command.");
5385 if (accessflag == hw_read)
5386 bp_type = bp_read_watchpoint;
5387 else if (accessflag == hw_access)
5388 bp_type = bp_access_watchpoint;
5390 bp_type = bp_hardware_watchpoint;
5392 mem_cnt = can_use_hardware_watchpoint (val);
5393 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5394 error ("Expression cannot be implemented with read/access watchpoint.");
5397 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5398 target_resources_ok =
5399 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5401 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5402 error ("Target does not support this type of hardware watchpoint.");
5404 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5405 error ("Target can only support one kind of HW watchpoint at a time.");
5408 #if defined(HPUXHPPA)
5409 /* On HP-UX if you set a h/w
5410 watchpoint before the "run" command, the inferior dies with a e.g.,
5411 SIGILL once you start it. I initially believed this was due to a
5412 bad interaction between page protection traps and the initial
5413 startup sequence by the dynamic linker.
5415 However, I tried avoiding that by having HP-UX's implementation of
5416 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid
5417 yet, which forced slow watches before a "run" or "attach", and it
5418 still fails somewhere in the startup code.
5420 Until I figure out what's happening, I'm disallowing watches altogether
5421 before the "run" or "attach" command. We'll tell the user they must
5422 set watches after getting the program started. */
5423 if (!target_has_execution)
5425 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5428 #endif /* HPUXHPPA */
5430 /* Now set up the breakpoint. */
5431 b = set_raw_breakpoint (sal);
5432 set_breakpoint_count (breakpoint_count + 1);
5433 b->number = breakpoint_count;
5434 b->disposition = donttouch;
5436 b->exp_valid_block = exp_valid_block;
5437 b->exp_string = savestring (exp_start, exp_end - exp_start);
5441 b->cond_string = savestring (cond_start, cond_end - cond_start);
5445 frame = block_innermost_frame (exp_valid_block);
5448 prev_frame = get_prev_frame (frame);
5449 b->watchpoint_frame = frame->frame;
5452 b->watchpoint_frame = (CORE_ADDR) 0;
5454 if (mem_cnt && target_resources_ok > 0)
5457 b->type = bp_watchpoint;
5459 /* If the expression is "local", then set up a "watchpoint scope"
5460 breakpoint at the point where we've left the scope of the watchpoint
5462 if (innermost_block)
5466 struct breakpoint *scope_breakpoint;
5467 struct symtab_and_line scope_sal;
5469 INIT_SAL (&scope_sal); /* initialize to zeroes */
5470 scope_sal.pc = get_frame_pc (prev_frame);
5471 scope_sal.section = find_pc_overlay (scope_sal.pc);
5473 scope_breakpoint = set_raw_breakpoint (scope_sal);
5474 set_breakpoint_count (breakpoint_count + 1);
5475 scope_breakpoint->number = breakpoint_count;
5477 scope_breakpoint->type = bp_watchpoint_scope;
5478 scope_breakpoint->enable = enabled;
5480 /* Automatically delete the breakpoint when it hits. */
5481 scope_breakpoint->disposition = del;
5483 /* Only break in the proper frame (help with recursion). */
5484 scope_breakpoint->frame = prev_frame->frame;
5486 /* Set the address at which we will stop. */
5487 scope_breakpoint->address = get_frame_pc (prev_frame);
5489 /* The scope breakpoint is related to the watchpoint. We
5490 will need to act on them together. */
5491 b->related_breakpoint = scope_breakpoint;
5494 value_free_to_mark (mark);
5498 /* Return count of locations need to be watched and can be handled
5499 in hardware. If the watchpoint can not be handled
5500 in hardware return zero. */
5502 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5503 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5504 ((BYTE_SIZE) <= (REGISTER_SIZE))
5507 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5508 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5509 TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)
5513 can_use_hardware_watchpoint (v)
5516 int found_memory_cnt = 0;
5518 /* Did the user specifically forbid us to use hardware watchpoints? */
5519 if (!can_use_hw_watchpoints)
5522 /* Make sure that the value of the expression depends only upon
5523 memory contents, and values computed from them within GDB. If we
5524 find any register references or function calls, we can't use a
5525 hardware watchpoint.
5527 The idea here is that evaluating an expression generates a series
5528 of values, one holding the value of every subexpression. (The
5529 expression a*b+c has five subexpressions: a, b, a*b, c, and
5530 a*b+c.) GDB's values hold almost enough information to establish
5531 the criteria given above --- they identify memory lvalues,
5532 register lvalues, computed values, etcetera. So we can evaluate
5533 the expression, and then scan the chain of values that leaves
5534 behind to decide whether we can detect any possible change to the
5535 expression's final value using only hardware watchpoints.
5537 However, I don't think that the values returned by inferior
5538 function calls are special in any way. So this function may not
5539 notice that an expression involving an inferior function call
5540 can't be watched with hardware watchpoints. FIXME. */
5541 for (; v; v = v->next)
5543 if (VALUE_LVAL (v) == lval_memory)
5546 /* A lazy memory lvalue is one that GDB never needed to fetch;
5547 we either just used its address (e.g., `a' in `a.b') or
5548 we never needed it at all (e.g., `a' in `a,b'). */
5552 /* Ahh, memory we actually used! Check if we can cover
5553 it with hardware watchpoints. */
5554 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5555 int len = TYPE_LENGTH (VALUE_TYPE (v));
5557 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5563 else if (v->lval != not_lval && v->modifiable == 0)
5564 return 0; /* ??? What does this represent? */
5565 else if (v->lval == lval_register)
5566 return 0; /* cannot watch a register with a HW watchpoint */
5569 /* The expression itself looks suitable for using a hardware
5570 watchpoint, but give the target machine a chance to reject it. */
5571 return found_memory_cnt;
5576 watch_command_wrapper (arg, from_tty)
5580 watch_command (arg, from_tty);
5584 watch_command (arg, from_tty)
5588 watch_command_1 (arg, hw_write, from_tty);
5593 rwatch_command_wrapper (arg, from_tty)
5597 rwatch_command (arg, from_tty);
5601 rwatch_command (arg, from_tty)
5605 watch_command_1 (arg, hw_read, from_tty);
5610 awatch_command_wrapper (arg, from_tty)
5614 awatch_command (arg, from_tty);
5618 awatch_command (arg, from_tty)
5622 watch_command_1 (arg, hw_access, from_tty);
5626 /* Helper routines for the until_command routine in infcmd.c. Here
5627 because it uses the mechanisms of breakpoints. */
5629 /* This function is called by fetch_inferior_event via the
5630 cmd_continuation pointer, to complete the until command. It takes
5631 care of cleaning up the temporary breakpoints set up by the until
5634 until_break_command_continuation (struct continuation_arg *arg)
5636 struct cleanup *cleanups;
5638 cleanups = (struct cleanup *) arg->data;
5639 do_exec_cleanups (cleanups);
5644 until_break_command (arg, from_tty)
5648 struct symtabs_and_lines sals;
5649 struct symtab_and_line sal;
5650 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5651 struct breakpoint *breakpoint;
5652 struct cleanup *old_chain;
5653 struct continuation_arg *arg1;
5656 clear_proceed_status ();
5658 /* Set a breakpoint where the user wants it and at return from
5661 if (default_breakpoint_valid)
5662 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5663 default_breakpoint_line, (char ***) NULL);
5665 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5666 0, (char ***) NULL);
5668 if (sals.nelts != 1)
5669 error ("Couldn't get information on specified line.");
5672 free ((PTR) sals.sals); /* malloc'd, so freed */
5675 error ("Junk at end of arguments.");
5677 resolve_sal_pc (&sal);
5679 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
5681 if (!event_loop_p || !target_can_async_p ())
5682 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint,
5685 old_chain = make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5687 /* If we are running asynchronously, and the target supports async
5688 execution, we are not waiting for the target to stop, in the call
5689 tp proceed, below. This means that we cannot delete the
5690 brekpoints until the target has actually stopped. The only place
5691 where we get a chance to do that is in fetch_inferior_event, so
5692 we must set things up for that. */
5694 if (event_loop_p && target_can_async_p ())
5696 /* In this case the arg for the continuation is just the point
5697 in the exec_cleanups chain from where to start doing
5698 cleanups, because all the continuation does is the cleanups in
5699 the exec_cleanup_chain. */
5701 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5703 arg1->data = (PTR) old_chain;
5705 add_continuation (until_break_command_continuation, arg1);
5708 /* Keep within the current frame */
5712 sal = find_pc_line (prev_frame->pc, 0);
5713 sal.pc = prev_frame->pc;
5714 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
5715 if (!event_loop_p || !target_can_async_p ())
5716 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5718 make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
5721 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5722 /* Do the cleanups now, anly if we are not running asynchronously,
5723 of if we are, but the target is still synchronous. */
5724 if (!event_loop_p || !target_can_async_p ())
5725 do_cleanups (old_chain);
5729 /* These aren't used; I don't konw what they were for. */
5730 /* Set a breakpoint at the catch clause for NAME. */
5732 catch_breakpoint (name)
5738 disable_catch_breakpoint ()
5743 delete_catch_breakpoint ()
5748 enable_catch_breakpoint ()
5755 struct sal_chain *next;
5756 struct symtab_and_line sal;
5760 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5761 had been commented out in the v.4.16 sources, and stays
5762 disabled there now because "catch NAME" syntax isn't allowed.
5764 /* This isn't used; I don't know what it was for. */
5765 /* For each catch clause identified in ARGS, run FUNCTION
5766 with that clause as an argument. */
5767 static struct symtabs_and_lines
5768 map_catch_names (args, function)
5772 register char *p = args;
5774 struct symtabs_and_lines sals;
5776 struct sal_chain *sal_chain = 0;
5780 error_no_arg ("one or more catch names");
5788 /* Don't swallow conditional part. */
5789 if (p1[0] == 'i' && p1[1] == 'f'
5790 && (p1[2] == ' ' || p1[2] == '\t'))
5796 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5800 if (*p1 && *p1 != ' ' && *p1 != '\t')
5801 error ("Arguments must be catch names.");
5807 struct sal_chain *next = (struct sal_chain *)
5808 alloca (sizeof (struct sal_chain));
5809 next->next = sal_chain;
5810 next->sal = get_catch_sal (p);
5815 printf_unfiltered ("No catch clause for exception %s.\n", p);
5820 while (*p == ' ' || *p == '\t')
5826 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5828 static struct symtabs_and_lines
5829 get_catch_sals (this_level_only)
5830 int this_level_only;
5832 register struct blockvector *bl;
5833 register struct block *block;
5834 int index, have_default = 0;
5836 struct symtabs_and_lines sals;
5837 struct sal_chain *sal_chain = 0;
5838 char *blocks_searched;
5840 /* Not sure whether an error message is always the correct response,
5841 but it's better than a core dump. */
5842 if (selected_frame == NULL)
5843 error ("No selected frame.");
5844 block = get_frame_block (selected_frame);
5845 pc = selected_frame->pc;
5851 error ("No symbol table info available.\n");
5853 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5854 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5855 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5859 CORE_ADDR end = BLOCK_END (block) - 4;
5862 if (bl != blockvector_for_pc (end, &index))
5863 error ("blockvector blotch");
5864 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5865 error ("blockvector botch");
5866 last_index = BLOCKVECTOR_NBLOCKS (bl);
5869 /* Don't print out blocks that have gone by. */
5870 while (index < last_index
5871 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5874 while (index < last_index
5875 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5877 if (blocks_searched[index] == 0)
5879 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
5882 register struct symbol *sym;
5884 nsyms = BLOCK_NSYMS (b);
5886 for (i = 0; i < nsyms; i++)
5888 sym = BLOCK_SYM (b, i);
5889 if (STREQ (SYMBOL_NAME (sym), "default"))
5895 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5897 struct sal_chain *next = (struct sal_chain *)
5898 alloca (sizeof (struct sal_chain));
5899 next->next = sal_chain;
5900 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5905 blocks_searched[index] = 1;
5911 if (sal_chain && this_level_only)
5914 /* After handling the function's top-level block, stop.
5915 Don't continue to its superblock, the block of
5916 per-file symbols. */
5917 if (BLOCK_FUNCTION (block))
5919 block = BLOCK_SUPERBLOCK (block);
5924 struct sal_chain *tmp_chain;
5926 /* Count the number of entries. */
5927 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5928 tmp_chain = tmp_chain->next)
5932 sals.sals = (struct symtab_and_line *)
5933 xmalloc (index * sizeof (struct symtab_and_line));
5934 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5935 sals.sals[index] = sal_chain->sal;
5942 ep_skip_leading_whitespace (s)
5945 if ((s == NULL) || (*s == NULL))
5947 while (isspace (**s))
5951 /* This function examines a string, and attempts to find a token
5952 that might be an event name in the leading characters. If a
5953 possible match is found, a pointer to the last character of
5954 the token is returned. Else, NULL is returned. */
5957 ep_find_event_name_end (arg)
5961 char *event_name_end = NULL;
5963 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5967 /* We break out of the loop when we find a token delimiter.
5968 Basically, we're looking for alphanumerics and underscores;
5969 anything else delimites the token. */
5972 if (!isalnum (*s) && (*s != '_'))
5978 return event_name_end;
5982 /* This function attempts to parse an optional "if <cond>" clause
5983 from the arg string. If one is not found, it returns NULL.
5985 Else, it returns a pointer to the condition string. (It does not
5986 attempt to evaluate the string against a particular block.) And,
5987 it updates arg to point to the first character following the parsed
5988 if clause in the arg string. */
5991 ep_parse_optional_if_clause (arg)
5996 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5999 /* Skip the "if" keyword. */
6002 /* Skip any extra leading whitespace, and record the start of the
6003 condition string. */
6004 ep_skip_leading_whitespace (arg);
6007 /* Assume that the condition occupies the remainder of the arg string. */
6008 (*arg) += strlen (cond_string);
6013 /* This function attempts to parse an optional filename from the arg
6014 string. If one is not found, it returns NULL.
6016 Else, it returns a pointer to the parsed filename. (This function
6017 makes no attempt to verify that a file of that name exists, or is
6018 accessible.) And, it updates arg to point to the first character
6019 following the parsed filename in the arg string.
6021 Note that clients needing to preserve the returned filename for
6022 future access should copy it to their own buffers. */
6024 ep_parse_optional_filename (arg)
6027 static char filename[1024];
6032 if ((*arg_p == '\0') || isspace (*arg_p))
6050 /* Commands to deal with catching events, such as signals, exceptions,
6051 process start/exit, etc. */
6055 catch_fork, catch_vfork
6059 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
6060 static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind,
6066 catch_fork_command_1 (fork_kind, arg, tempflag, from_tty)
6067 catch_fork_kind fork_kind;
6072 char *cond_string = NULL;
6074 ep_skip_leading_whitespace (&arg);
6076 /* The allowed syntax is:
6078 catch [v]fork if <cond>
6080 First, check if there's an if clause. */
6081 cond_string = ep_parse_optional_if_clause (&arg);
6083 if ((*arg != '\0') && !isspace (*arg))
6084 error ("Junk at end of arguments.");
6086 /* If this target supports it, create a fork or vfork catchpoint
6087 and enable reporting of such events. */
6091 create_fork_event_catchpoint (tempflag, cond_string);
6094 create_vfork_event_catchpoint (tempflag, cond_string);
6097 error ("unsupported or unknown fork kind; cannot catch it");
6103 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6105 catch_exec_command_1 (arg, tempflag, from_tty)
6110 char *cond_string = NULL;
6112 ep_skip_leading_whitespace (&arg);
6114 /* The allowed syntax is:
6116 catch exec if <cond>
6118 First, check if there's an if clause. */
6119 cond_string = ep_parse_optional_if_clause (&arg);
6121 if ((*arg != '\0') && !isspace (*arg))
6122 error ("Junk at end of arguments.");
6124 /* If this target supports it, create an exec catchpoint
6125 and enable reporting of such events. */
6126 create_exec_event_catchpoint (tempflag, cond_string);
6130 #if defined(SOLIB_ADD)
6132 catch_load_command_1 (arg, tempflag, from_tty)
6137 char *dll_pathname = NULL;
6138 char *cond_string = NULL;
6140 ep_skip_leading_whitespace (&arg);
6142 /* The allowed syntax is:
6144 catch load if <cond>
6145 catch load <filename>
6146 catch load <filename> if <cond>
6148 The user is not allowed to specify the <filename> after an
6151 We'll ignore the pathological case of a file named "if".
6153 First, check if there's an if clause. If so, then there
6154 cannot be a filename. */
6155 cond_string = ep_parse_optional_if_clause (&arg);
6157 /* If there was an if clause, then there cannot be a filename.
6158 Else, there might be a filename and an if clause. */
6159 if (cond_string == NULL)
6161 dll_pathname = ep_parse_optional_filename (&arg);
6162 ep_skip_leading_whitespace (&arg);
6163 cond_string = ep_parse_optional_if_clause (&arg);
6166 if ((*arg != '\0') && !isspace (*arg))
6167 error ("Junk at end of arguments.");
6169 /* Create a load breakpoint that only triggers when a load of
6170 the specified dll (or any dll, if no pathname was specified)
6172 SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag,
6173 dll_pathname, cond_string);
6177 catch_unload_command_1 (arg, tempflag, from_tty)
6182 char *dll_pathname = NULL;
6183 char *cond_string = NULL;
6185 ep_skip_leading_whitespace (&arg);
6187 /* The allowed syntax is:
6189 catch unload if <cond>
6190 catch unload <filename>
6191 catch unload <filename> if <cond>
6193 The user is not allowed to specify the <filename> after an
6196 We'll ignore the pathological case of a file named "if".
6198 First, check if there's an if clause. If so, then there
6199 cannot be a filename. */
6200 cond_string = ep_parse_optional_if_clause (&arg);
6202 /* If there was an if clause, then there cannot be a filename.
6203 Else, there might be a filename and an if clause. */
6204 if (cond_string == NULL)
6206 dll_pathname = ep_parse_optional_filename (&arg);
6207 ep_skip_leading_whitespace (&arg);
6208 cond_string = ep_parse_optional_if_clause (&arg);
6211 if ((*arg != '\0') && !isspace (*arg))
6212 error ("Junk at end of arguments.");
6214 /* Create an unload breakpoint that only triggers when an unload of
6215 the specified dll (or any dll, if no pathname was specified)
6217 SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag,
6218 dll_pathname, cond_string);
6220 #endif /* SOLIB_ADD */
6222 /* Commands to deal with catching exceptions. */
6224 /* Set a breakpoint at the specified callback routine for an
6225 exception event callback */
6228 create_exception_catchpoint (tempflag, cond_string, ex_event, sal)
6231 enum exception_event_kind ex_event;
6232 struct symtab_and_line *sal;
6234 struct breakpoint *b;
6235 int thread = -1; /* All threads. */
6237 if (!sal) /* no exception support? */
6240 b = set_raw_breakpoint (*sal);
6241 set_breakpoint_count (breakpoint_count + 1);
6242 b->number = breakpoint_count;
6244 b->cond_string = (cond_string == NULL) ?
6245 NULL : savestring (cond_string, strlen (cond_string));
6247 b->addr_string = NULL;
6248 b->enable = enabled;
6249 b->disposition = tempflag ? del : donttouch;
6252 case EX_EVENT_THROW:
6253 b->type = bp_catch_throw;
6255 case EX_EVENT_CATCH:
6256 b->type = bp_catch_catch;
6258 default: /* error condition */
6260 b->enable = disabled;
6261 error ("Internal error -- invalid catchpoint kind");
6266 /* Deal with "catch catch" and "catch throw" commands */
6269 catch_exception_command_1 (ex_event, arg, tempflag, from_tty)
6270 enum exception_event_kind ex_event;
6275 char *cond_string = NULL;
6276 struct symtab_and_line *sal = NULL;
6278 ep_skip_leading_whitespace (&arg);
6280 cond_string = ep_parse_optional_if_clause (&arg);
6282 if ((*arg != '\0') && !isspace (*arg))
6283 error ("Junk at end of arguments.");
6285 if ((ex_event != EX_EVENT_THROW) &&
6286 (ex_event != EX_EVENT_CATCH))
6287 error ("Unsupported or unknown exception event; cannot catch it");
6289 /* See if we can find a callback routine */
6290 sal = target_enable_exception_callback (ex_event, 1);
6294 /* We have callbacks from the runtime system for exceptions.
6295 Set a breakpoint on the sal found, if no errors */
6296 if (sal != (struct symtab_and_line *) -1)
6297 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6299 return; /* something went wrong with setting up callbacks */
6303 /* No callbacks from runtime system for exceptions.
6304 Try GNU C++ exception breakpoints using labels in debug info. */
6305 if (ex_event == EX_EVENT_CATCH)
6307 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6309 else if (ex_event == EX_EVENT_THROW)
6311 /* Set a breakpoint on __raise_exception () */
6313 warning ("Unsupported with this platform/compiler combination.");
6314 warning ("Perhaps you can achieve the effect you want by setting");
6315 warning ("a breakpoint on __raise_exception().");
6320 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6321 inside a catch_errors */
6324 cover_target_enable_exception_callback (arg)
6327 args_for_catchpoint_enable *args = arg;
6328 struct symtab_and_line *sal;
6329 sal = target_enable_exception_callback (args->kind, args->enable);
6332 else if (sal == (struct symtab_and_line *) -1)
6335 return 1; /*is valid */
6340 /* This is the original v.4.16 and earlier version of the
6341 catch_command_1() function. Now that other flavours of "catch"
6342 have been introduced, and since exception handling can be handled
6343 in other ways (through target ops) also, this is used only for the
6344 GNU C++ exception handling system.
6345 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6346 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6347 there was no code in GDB 4.16 for "catch throw".
6349 Called from catch_exception_command_1 () */
6353 handle_gnu_4_16_catch_command (arg, tempflag, from_tty)
6358 /* First, translate ARG into something we can deal with in terms
6361 struct symtabs_and_lines sals;
6362 struct symtab_and_line sal;
6363 register struct expression *cond = 0;
6364 register struct breakpoint *b;
6368 INIT_SAL (&sal); /* initialize to zeroes */
6370 /* If no arg given, or if first arg is 'if ', all active catch clauses
6371 are breakpointed. */
6373 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
6374 && (arg[2] == ' ' || arg[2] == '\t')))
6376 /* Grab all active catch clauses. */
6377 sals = get_catch_sals (0);
6381 /* Grab selected catch clauses. */
6382 error ("catch NAME not implemented");
6385 /* Not sure why this code has been disabled. I'm leaving
6386 it disabled. We can never come here now anyway
6387 since we don't allow the "catch NAME" syntax.
6390 /* This isn't used; I don't know what it was for. */
6391 sals = map_catch_names (arg, catch_breakpoint);
6399 for (i = 0; i < sals.nelts; i++)
6401 resolve_sal_pc (&sals.sals[i]);
6405 if (arg[0] == 'i' && arg[1] == 'f'
6406 && (arg[2] == ' ' || arg[2] == '\t'))
6407 cond = parse_exp_1 ((arg += 2, &arg),
6408 block_for_pc (sals.sals[i].pc), 0);
6410 error ("Junk at end of arguments.");
6415 for (i = 0; i < sals.nelts; i++)
6420 describe_other_breakpoints (sal.pc, sal.section);
6422 b = set_raw_breakpoint (sal);
6423 set_breakpoint_count (breakpoint_count + 1);
6424 b->number = breakpoint_count;
6426 /* Important -- this is an ordinary breakpoint. For platforms
6427 with callback support for exceptions,
6428 create_exception_catchpoint() will create special bp types
6429 (bp_catch_catch and bp_catch_throw), and there is code in
6430 insert_breakpoints() and elsewhere that depends on that. */
6431 b->type = bp_breakpoint;
6434 b->enable = enabled;
6435 b->disposition = tempflag ? del : donttouch;
6442 warning ("Multiple breakpoints were set.");
6443 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6445 free ((PTR) sals.sals);
6449 /* This creates a temporary internal breakpoint
6450 just to placate infrun */
6451 static struct breakpoint *
6452 create_temp_exception_breakpoint (pc)
6455 struct symtab_and_line sal;
6456 struct breakpoint *b;
6463 b = set_raw_breakpoint (sal);
6465 error ("Internal error -- couldn't set temp exception breakpoint");
6467 b->type = bp_breakpoint;
6468 b->disposition = del;
6469 b->enable = enabled;
6471 b->number = internal_breakpoint_number--;
6477 catch_command_1 (arg, tempflag, from_tty)
6483 /* The first argument may be an event name, such as "start" or "load".
6484 If so, then handle it as such. If it doesn't match an event name,
6485 then attempt to interpret it as an exception name. (This latter is
6486 the v4.16-and-earlier GDB meaning of the "catch" command.)
6488 First, try to find the bounds of what might be an event name. */
6489 char *arg1_start = arg;
6493 if (arg1_start == NULL)
6495 /* Old behaviour was to use pre-v-4.16 syntax */
6496 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6498 /* Now, this is not allowed */
6499 error ("Catch requires an event name.");
6502 arg1_end = ep_find_event_name_end (arg1_start);
6503 if (arg1_end == NULL)
6504 error ("catch requires an event");
6505 arg1_length = arg1_end + 1 - arg1_start;
6507 /* Try to match what we found against known event names. */
6508 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6510 error ("Catch of signal not yet implemented");
6512 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6514 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6515 tempflag, from_tty);
6517 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6519 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6520 tempflag, from_tty);
6522 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6524 error ("Catch of thread_start not yet implemented");
6526 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6528 error ("Catch of thread_exit not yet implemented");
6530 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6532 error ("Catch of thread_join not yet implemented");
6534 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6536 error ("Catch of start not yet implemented");
6538 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6540 error ("Catch of exit not yet implemented");
6542 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6544 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6545 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6547 error ("Catch of fork not yet implemented");
6550 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6552 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6553 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6555 error ("Catch of vfork not yet implemented");
6558 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6560 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6561 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6563 error ("Catch of exec not yet implemented");
6566 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6568 #if defined(SOLIB_ADD)
6569 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6571 error ("Catch of load not implemented");
6574 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6576 #if defined(SOLIB_ADD)
6577 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6579 error ("Catch of load not implemented");
6582 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6584 error ("Catch of stop not yet implemented");
6587 /* This doesn't appear to be an event name */
6591 /* Pre-v.4.16 behaviour was to treat the argument
6592 as the name of an exception */
6593 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6594 /* Now this is not allowed */
6595 error ("Unknown event kind specified for catch");
6600 /* Used by the gui, could be made a worker for other things. */
6603 set_breakpoint_sal (sal)
6604 struct symtab_and_line sal;
6606 struct breakpoint *b;
6607 b = set_raw_breakpoint (sal);
6608 set_breakpoint_count (breakpoint_count + 1);
6609 b->number = breakpoint_count;
6610 b->type = bp_breakpoint;
6617 /* These aren't used; I don't know what they were for. */
6618 /* Disable breakpoints on all catch clauses described in ARGS. */
6620 disable_catch (args)
6623 /* Map the disable command to catch clauses described in ARGS. */
6626 /* Enable breakpoints on all catch clauses described in ARGS. */
6631 /* Map the disable command to catch clauses described in ARGS. */
6634 /* Delete breakpoints on all catch clauses in the active scope. */
6639 /* Map the delete command to catch clauses described in ARGS. */
6644 catch_command (arg, from_tty)
6648 catch_command_1 (arg, 0, from_tty);
6653 tcatch_command (arg, from_tty)
6657 catch_command_1 (arg, 1, from_tty);
6662 clear_command (arg, from_tty)
6666 register struct breakpoint *b, *b1;
6668 struct symtabs_and_lines sals;
6669 struct symtab_and_line sal;
6670 register struct breakpoint *found;
6675 sals = decode_line_spec (arg, 1);
6680 sals.sals = (struct symtab_and_line *)
6681 xmalloc (sizeof (struct symtab_and_line));
6682 INIT_SAL (&sal); /* initialize to zeroes */
6683 sal.line = default_breakpoint_line;
6684 sal.symtab = default_breakpoint_symtab;
6685 sal.pc = default_breakpoint_address;
6686 if (sal.symtab == 0)
6687 error ("No source file specified.");
6695 /* For each line spec given, delete bps which correspond
6696 to it. We do this in two loops: the first loop looks at
6697 the initial bp(s) in the chain which should be deleted,
6698 the second goes down the rest of the chain looking ahead
6699 one so it can take those bps off the chain without messing
6703 for (i = 0; i < sals.nelts; i++)
6705 /* If exact pc given, clear bpts at that pc.
6706 If line given (pc == 0), clear all bpts on specified line.
6707 If defaulting, clear all bpts on default line
6710 defaulting sal.pc != 0 tests to do
6715 1 0 <can't happen> */
6718 found = (struct breakpoint *) 0;
6721 while (breakpoint_chain
6722 /* Why don't we check here that this is not
6723 a watchpoint, etc., as we do below?
6724 I can't make it fail, but don't know
6725 what's stopping the failure: a watchpoint
6726 of the same address as "sal.pc" should
6727 wind up being deleted. */
6729 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6730 (overlay_debugging == 0 ||
6731 breakpoint_chain->section == sal.section))
6732 || ((default_match || (0 == sal.pc))
6733 && breakpoint_chain->source_file != NULL
6734 && sal.symtab != NULL
6735 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6736 && breakpoint_chain->line_number == sal.line)))
6739 b1 = breakpoint_chain;
6740 breakpoint_chain = b1->next;
6748 && b->next->type != bp_none
6749 && b->next->type != bp_watchpoint
6750 && b->next->type != bp_hardware_watchpoint
6751 && b->next->type != bp_read_watchpoint
6752 && b->next->type != bp_access_watchpoint
6753 && (((sal.pc && (b->next->address == sal.pc)) &&
6754 (overlay_debugging == 0 ||
6755 b->next->section == sal.section))
6756 || ((default_match || (0 == sal.pc))
6757 && b->next->source_file != NULL
6758 && sal.symtab != NULL
6759 && STREQ (b->next->source_file, sal.symtab->filename)
6760 && b->next->line_number == sal.line)))
6773 error ("No breakpoint at %s.", arg);
6775 error ("No breakpoint at this line.");
6779 from_tty = 1; /* Always report if deleted more than one */
6781 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6782 breakpoints_changed ();
6786 printf_unfiltered ("%d ", found->number);
6788 delete_breakpoint (found);
6792 putchar_unfiltered ('\n');
6794 free ((PTR) sals.sals);
6797 /* Delete breakpoint in BS if they are `delete' breakpoints and
6798 all breakpoints that are marked for deletion, whether hit or not.
6799 This is called after any breakpoint is hit, or after errors. */
6802 breakpoint_auto_delete (bs)
6805 struct breakpoint *b, *temp;
6807 for (; bs; bs = bs->next)
6808 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
6810 delete_breakpoint (bs->breakpoint_at);
6812 ALL_BREAKPOINTS_SAFE (b, temp)
6814 if (b->disposition == del_at_next_stop)
6815 delete_breakpoint (b);
6819 /* Delete a breakpoint and clean up all traces of it in the data
6823 delete_breakpoint (bpt)
6824 struct breakpoint *bpt;
6826 register struct breakpoint *b;
6830 error ("Internal error (attempted to delete a NULL breakpoint)");
6833 /* Has this bp already been deleted? This can happen because multiple
6834 lists can hold pointers to bp's. bpstat lists are especial culprits.
6836 One example of this happening is a watchpoint's scope bp. When the
6837 scope bp triggers, we notice that the watchpoint is out of scope, and
6838 delete it. We also delete its scope bp. But the scope bp is marked
6839 "auto-deleting", and is already on a bpstat. That bpstat is then
6840 checked for auto-deleting bp's, which are deleted.
6842 A real solution to this problem might involve reference counts in bp's,
6843 and/or giving them pointers back to their referencing bpstat's, and
6844 teaching delete_breakpoint to only free a bp's storage when no more
6845 references were extent. A cheaper bandaid was chosen. */
6846 if (bpt->type == bp_none)
6849 if (delete_breakpoint_hook)
6850 delete_breakpoint_hook (bpt);
6851 breakpoint_delete_event (bpt->number);
6854 remove_breakpoint (bpt, mark_uninserted);
6856 if (breakpoint_chain == bpt)
6857 breakpoint_chain = bpt->next;
6859 /* If we have callback-style exception catchpoints, don't go through
6860 the adjustments to the C++ runtime library etc. if the inferior
6861 isn't actually running. target_enable_exception_callback for a
6862 null target ops vector gives an undesirable error message, so we
6863 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6864 exceptions are supported in this way, it's OK for now. FIXME */
6865 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6867 static char message1[] = "Error in deleting catchpoint %d:\n";
6868 static char message[sizeof (message1) + 30];
6869 args_for_catchpoint_enable args;
6871 /* Format possible error msg */
6872 sprintf (message, message1, bpt->number);
6873 args.kind = bpt->type == bp_catch_catch ?
6874 EX_EVENT_CATCH : EX_EVENT_THROW;
6876 catch_errors (cover_target_enable_exception_callback, &args,
6877 message, RETURN_MASK_ALL);
6884 b->next = bpt->next;
6888 /* Before turning off the visuals for the bp, check to see that
6889 there are no other bps at the same address. */
6896 clearIt = (b->address != bpt->address);
6903 TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0));
6904 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos));
6908 check_duplicates (bpt->address, bpt->section);
6909 /* If this breakpoint was inserted, and there is another breakpoint
6910 at the same address, we need to insert the other breakpoint. */
6912 && bpt->type != bp_hardware_watchpoint
6913 && bpt->type != bp_read_watchpoint
6914 && bpt->type != bp_access_watchpoint
6915 && bpt->type != bp_catch_fork
6916 && bpt->type != bp_catch_vfork
6917 && bpt->type != bp_catch_exec)
6920 if (b->address == bpt->address
6921 && b->section == bpt->section
6923 && b->enable != disabled
6924 && b->enable != shlib_disabled
6925 && b->enable != call_disabled)
6929 /* We should never reach this point if there is a permanent
6930 breakpoint at the same address as the one being deleted.
6931 If there is a permanent breakpoint somewhere, it should
6932 always be the only one inserted. */
6933 if (b->enable == permanent)
6934 internal_error ("another breakpoint was inserted on top of "
6935 "a permanent breakpoint");
6937 if (b->type == bp_hardware_breakpoint)
6938 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6940 val = target_insert_breakpoint (b->address, b->shadow_contents);
6944 target_terminal_ours_for_output ();
6945 warning ("Cannot insert breakpoint %d:", b->number);
6946 memory_error (val, b->address); /* which bombs us out */
6953 free_command_lines (&bpt->commands);
6956 if (bpt->cond_string != NULL)
6957 free (bpt->cond_string);
6958 if (bpt->addr_string != NULL)
6959 free (bpt->addr_string);
6960 if (bpt->exp != NULL)
6962 if (bpt->exp_string != NULL)
6963 free (bpt->exp_string);
6964 if (bpt->val != NULL)
6965 value_free (bpt->val);
6966 if (bpt->source_file != NULL)
6967 free (bpt->source_file);
6968 if (bpt->dll_pathname != NULL)
6969 free (bpt->dll_pathname);
6970 if (bpt->triggered_dll_pathname != NULL)
6971 free (bpt->triggered_dll_pathname);
6972 if (bpt->exec_pathname != NULL)
6973 free (bpt->exec_pathname);
6975 /* Be sure no bpstat's are pointing at it after it's been freed. */
6976 /* FIXME, how can we find all bpstat's?
6977 We just check stop_bpstat for now. */
6978 for (bs = stop_bpstat; bs; bs = bs->next)
6979 if (bs->breakpoint_at == bpt)
6981 bs->breakpoint_at = NULL;
6983 /* we'd call bpstat_clear_actions, but that free's stuff and due
6984 to the multiple pointers pointing to one item with no
6985 reference counts found anywhere through out the bpstat's (how
6986 do you spell fragile?), we don't want to free things twice --
6987 better a memory leak than a corrupt malloc pool! */
6988 bs->commands = NULL;
6991 /* On the chance that someone will soon try again to delete this same
6992 bp, we mark it as deleted before freeing its storage. */
6993 bpt->type = bp_none;
6999 delete_command (arg, from_tty)
7003 struct breakpoint *b, *temp;
7007 int breaks_to_delete = 0;
7009 /* Delete all breakpoints if no argument.
7010 Do not delete internal or call-dummy breakpoints, these
7011 have to be deleted with an explicit breakpoint number argument. */
7014 if (b->type != bp_call_dummy &&
7015 b->type != bp_shlib_event &&
7016 b->type != bp_thread_event &&
7018 breaks_to_delete = 1;
7021 /* Ask user only if there are some breakpoints to delete. */
7023 || (breaks_to_delete && query ("Delete all breakpoints? ")))
7025 ALL_BREAKPOINTS_SAFE (b, temp)
7027 if (b->type != bp_call_dummy &&
7028 b->type != bp_shlib_event &&
7029 b->type != bp_thread_event &&
7031 delete_breakpoint (b);
7036 map_breakpoint_numbers (arg, delete_breakpoint);
7039 /* Reset a breakpoint given it's struct breakpoint * BINT.
7040 The value we return ends up being the return value from catch_errors.
7041 Unused in this case. */
7044 breakpoint_re_set_one (bint)
7047 /* get past catch_errs */
7048 struct breakpoint *b = (struct breakpoint *) bint;
7051 struct symtabs_and_lines sals;
7053 enum enable save_enable;
7058 warning ("attempted to reset apparently deleted breakpoint #%d?",
7062 case bp_hardware_breakpoint:
7064 case bp_catch_unload:
7065 if (b->addr_string == NULL)
7067 /* Anything without a string can't be re-set. */
7068 delete_breakpoint (b);
7071 /* In case we have a problem, disable this breakpoint. We'll restore
7072 its status if we succeed. */
7073 save_enable = b->enable;
7074 b->enable = disabled;
7076 set_language (b->language);
7077 input_radix = b->input_radix;
7079 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
7080 for (i = 0; i < sals.nelts; i++)
7082 resolve_sal_pc (&sals.sals[i]);
7084 /* Reparse conditions, they might contain references to the
7086 if (b->cond_string != NULL)
7090 free ((PTR) b->cond);
7091 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
7094 /* We need to re-set the breakpoint if the address changes... */
7095 if (b->address != sals.sals[i].pc
7096 /* ...or new and old breakpoints both have source files, and
7097 the source file name or the line number changes... */
7098 || (b->source_file != NULL
7099 && sals.sals[i].symtab != NULL
7100 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
7101 || b->line_number != sals.sals[i].line)
7103 /* ...or we switch between having a source file and not having
7105 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
7108 if (b->source_file != NULL)
7109 free (b->source_file);
7110 if (sals.sals[i].symtab == NULL)
7111 b->source_file = NULL;
7114 savestring (sals.sals[i].symtab->filename,
7115 strlen (sals.sals[i].symtab->filename));
7116 b->line_number = sals.sals[i].line;
7117 b->address = sals.sals[i].pc;
7119 /* Used to check for duplicates here, but that can
7120 cause trouble, as it doesn't check for disable
7125 /* Might be better to do this just once per breakpoint_re_set,
7126 rather than once for every breakpoint. */
7127 breakpoints_changed ();
7129 b->section = sals.sals[i].section;
7130 b->enable = save_enable; /* Restore it, this worked. */
7133 /* Now that this is re-enabled, check_duplicates
7135 check_duplicates (b->address, b->section);
7138 free ((PTR) sals.sals);
7142 case bp_hardware_watchpoint:
7143 case bp_read_watchpoint:
7144 case bp_access_watchpoint:
7145 innermost_block = NULL;
7146 /* The issue arises of what context to evaluate this in. The
7147 same one as when it was set, but what does that mean when
7148 symbols have been re-read? We could save the filename and
7149 functionname, but if the context is more local than that, the
7150 best we could do would be something like how many levels deep
7151 and which index at that particular level, but that's going to
7152 be less stable than filenames or function names. */
7154 /* So for now, just use a global context. */
7156 free ((PTR) b->exp);
7157 b->exp = parse_expression (b->exp_string);
7158 b->exp_valid_block = innermost_block;
7159 mark = value_mark ();
7161 value_free (b->val);
7162 b->val = evaluate_expression (b->exp);
7163 release_value (b->val);
7164 if (VALUE_LAZY (b->val))
7165 value_fetch_lazy (b->val);
7167 if (b->cond_string != NULL)
7171 free ((PTR) b->cond);
7172 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7174 if (b->enable == enabled)
7176 value_free_to_mark (mark);
7178 case bp_catch_catch:
7179 case bp_catch_throw:
7181 /* We needn't really do anything to reset these, since the mask
7182 that requests them is unaffected by e.g., new libraries being
7185 case bp_catch_vfork:
7190 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
7192 /* Delete longjmp breakpoints, they will be reset later by
7193 breakpoint_re_set. */
7195 case bp_longjmp_resume:
7196 delete_breakpoint (b);
7199 /* This breakpoint is special, it's set up when the inferior
7200 starts and we really don't want to touch it. */
7201 case bp_shlib_event:
7203 /* Like bp_shlib_event, this breakpoint type is special.
7204 Once it is set up, we do not want to touch it. */
7205 case bp_thread_event:
7207 /* Keep temporary breakpoints, which can be encountered when we step
7208 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7209 Otherwise these should have been blown away via the cleanup chain
7210 or by breakpoint_init_inferior when we rerun the executable. */
7213 case bp_watchpoint_scope:
7215 case bp_step_resume:
7222 /* Re-set all breakpoints after symbols have been re-loaded. */
7224 breakpoint_re_set ()
7226 struct breakpoint *b, *temp;
7227 enum language save_language;
7228 int save_input_radix;
7229 static char message1[] = "Error in re-setting breakpoint %d:\n";
7230 char message[sizeof (message1) + 30 /* slop */ ];
7232 save_language = current_language->la_language;
7233 save_input_radix = input_radix;
7234 ALL_BREAKPOINTS_SAFE (b, temp)
7236 /* Format possible error msg */
7237 sprintf (message, message1, b->number);
7238 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7240 set_language (save_language);
7241 input_radix = save_input_radix;
7243 #ifdef GET_LONGJMP_TARGET
7244 create_longjmp_breakpoint ("longjmp");
7245 create_longjmp_breakpoint ("_longjmp");
7246 create_longjmp_breakpoint ("siglongjmp");
7247 create_longjmp_breakpoint ("_siglongjmp");
7248 create_longjmp_breakpoint (NULL);
7252 /* Took this out (temporarily at least), since it produces an extra
7253 blank line at startup. This messes up the gdbtests. -PB */
7254 /* Blank line to finish off all those mention() messages we just printed. */
7255 printf_filtered ("\n");
7259 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7260 If from_tty is nonzero, it prints a message to that effect,
7261 which ends with a period (no newline). */
7263 /* Reset the thread number of this breakpoint:
7265 - If the breakpoint is for all threads, leave it as-is.
7266 - Else, reset it to the current thread for inferior_pid. */
7268 breakpoint_re_set_thread (b)
7269 struct breakpoint *b;
7271 if (b->thread != -1)
7273 if (in_thread_list (inferior_pid))
7274 b->thread = pid_to_thread_id (inferior_pid);
7279 set_ignore_count (bptnum, count, from_tty)
7280 int bptnum, count, from_tty;
7282 register struct breakpoint *b;
7288 if (b->number == bptnum)
7290 b->ignore_count = count;
7293 else if (count == 0)
7294 printf_filtered ("Will stop next time breakpoint %d is reached.",
7296 else if (count == 1)
7297 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7300 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7302 breakpoints_changed ();
7306 error ("No breakpoint number %d.", bptnum);
7309 /* Clear the ignore counts of all breakpoints. */
7311 breakpoint_clear_ignore_counts ()
7313 struct breakpoint *b;
7316 b->ignore_count = 0;
7319 /* Command to set ignore-count of breakpoint N to COUNT. */
7322 ignore_command (args, from_tty)
7330 error_no_arg ("a breakpoint number");
7332 num = get_number (&p);
7334 error ("bad breakpoint number: '%s'", args);
7336 error ("Second argument (specified ignore-count) is missing.");
7338 set_ignore_count (num,
7339 longest_to_int (value_as_long (parse_and_eval (p))),
7341 printf_filtered ("\n");
7342 breakpoints_changed ();
7345 /* Call FUNCTION on each of the breakpoints
7346 whose numbers are given in ARGS. */
7349 map_breakpoint_numbers (args, function)
7351 void (*function) PARAMS ((struct breakpoint *));
7353 register char *p = args;
7356 register struct breakpoint *b, *tmp;
7360 error_no_arg ("one or more breakpoint numbers");
7367 num = get_number_or_range (&p1);
7370 warning ("bad breakpoint number at or near '%s'", p);
7374 ALL_BREAKPOINTS_SAFE (b, tmp)
7375 if (b->number == num)
7377 struct breakpoint *related_breakpoint = b->related_breakpoint;
7380 if (related_breakpoint)
7381 function (related_breakpoint);
7385 printf_unfiltered ("No breakpoint number %d.\n", num);
7392 disable_breakpoint (bpt)
7393 struct breakpoint *bpt;
7395 /* Never disable a watchpoint scope breakpoint; we want to
7396 hit them when we leave scope so we can delete both the
7397 watchpoint and its scope breakpoint at that time. */
7398 if (bpt->type == bp_watchpoint_scope)
7401 /* You can't disable permanent breakpoints. */
7402 if (bpt->enable == permanent)
7405 bpt->enable = disabled;
7407 check_duplicates (bpt->address, bpt->section);
7409 if (modify_breakpoint_hook)
7410 modify_breakpoint_hook (bpt);
7411 breakpoint_modify_event (bpt->number);
7416 disable_command (args, from_tty)
7420 register struct breakpoint *bpt;
7422 ALL_BREAKPOINTS (bpt)
7426 warning ("attempted to disable apparently deleted breakpoint #%d?",
7431 case bp_catch_unload:
7433 case bp_catch_vfork:
7435 case bp_catch_catch:
7436 case bp_catch_throw:
7437 case bp_hardware_breakpoint:
7439 case bp_hardware_watchpoint:
7440 case bp_read_watchpoint:
7441 case bp_access_watchpoint:
7442 disable_breakpoint (bpt);
7447 map_breakpoint_numbers (args, disable_breakpoint);
7451 do_enable_breakpoint (bpt, disposition)
7452 struct breakpoint *bpt;
7453 enum bpdisp disposition;
7455 struct frame_info *save_selected_frame = NULL;
7456 int save_selected_frame_level = -1;
7457 int target_resources_ok, other_type_used;
7460 if (bpt->type == bp_hardware_breakpoint)
7463 i = hw_breakpoint_used_count ();
7464 target_resources_ok =
7465 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7467 if (target_resources_ok == 0)
7468 error ("No hardware breakpoint support in the target.");
7469 else if (target_resources_ok < 0)
7470 error ("Hardware breakpoints used exceeds limit.");
7473 if (bpt->enable != permanent)
7474 bpt->enable = enabled;
7475 bpt->disposition = disposition;
7476 check_duplicates (bpt->address, bpt->section);
7477 breakpoints_changed ();
7479 if (bpt->type == bp_watchpoint ||
7480 bpt->type == bp_hardware_watchpoint ||
7481 bpt->type == bp_read_watchpoint ||
7482 bpt->type == bp_access_watchpoint)
7484 if (bpt->exp_valid_block != NULL)
7486 struct frame_info *fr =
7488 /* Ensure that we have the current frame. Else, this
7489 next query may pessimistically be answered as, "No,
7490 not within current scope". */
7491 get_current_frame ();
7492 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
7496 Cannot enable watchpoint %d because the block in which its expression\n\
7497 is valid is not currently in scope.\n", bpt->number);
7498 bpt->enable = disabled;
7502 save_selected_frame = selected_frame;
7503 save_selected_frame_level = selected_frame_level;
7504 select_frame (fr, -1);
7507 value_free (bpt->val);
7508 mark = value_mark ();
7509 bpt->val = evaluate_expression (bpt->exp);
7510 release_value (bpt->val);
7511 if (VALUE_LAZY (bpt->val))
7512 value_fetch_lazy (bpt->val);
7514 if (bpt->type == bp_hardware_watchpoint ||
7515 bpt->type == bp_read_watchpoint ||
7516 bpt->type == bp_access_watchpoint)
7518 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7519 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7521 /* Hack around 'unused var' error for some targets here */
7523 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7524 bpt->type, i + mem_cnt, other_type_used);
7525 /* we can consider of type is bp_hardware_watchpoint, convert to
7526 bp_watchpoint in the following condition */
7527 if (target_resources_ok < 0)
7530 Cannot enable watchpoint %d because target watch resources\n\
7531 have been allocated for other watchpoints.\n", bpt->number);
7532 bpt->enable = disabled;
7533 value_free_to_mark (mark);
7538 if (save_selected_frame_level >= 0)
7539 select_and_print_frame (save_selected_frame,
7540 save_selected_frame_level);
7541 value_free_to_mark (mark);
7543 if (modify_breakpoint_hook)
7544 modify_breakpoint_hook (bpt);
7545 breakpoint_modify_event (bpt->number);
7549 enable_breakpoint (bpt)
7550 struct breakpoint *bpt;
7552 do_enable_breakpoint (bpt, bpt->disposition);
7555 /* The enable command enables the specified breakpoints (or all defined
7556 breakpoints) so they once again become (or continue to be) effective
7557 in stopping the inferior. */
7561 enable_command (args, from_tty)
7565 register struct breakpoint *bpt;
7567 ALL_BREAKPOINTS (bpt)
7571 warning ("attempted to enable apparently deleted breakpoint #%d?",
7576 case bp_catch_unload:
7578 case bp_catch_vfork:
7580 case bp_catch_catch:
7581 case bp_catch_throw:
7582 case bp_hardware_breakpoint:
7584 case bp_hardware_watchpoint:
7585 case bp_read_watchpoint:
7586 case bp_access_watchpoint:
7587 enable_breakpoint (bpt);
7592 map_breakpoint_numbers (args, enable_breakpoint);
7596 enable_once_breakpoint (bpt)
7597 struct breakpoint *bpt;
7599 do_enable_breakpoint (bpt, disable);
7604 enable_once_command (args, from_tty)
7608 map_breakpoint_numbers (args, enable_once_breakpoint);
7612 enable_delete_breakpoint (bpt)
7613 struct breakpoint *bpt;
7615 do_enable_breakpoint (bpt, del);
7620 enable_delete_command (args, from_tty)
7624 map_breakpoint_numbers (args, enable_delete_breakpoint);
7627 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7629 struct symtabs_and_lines
7630 decode_line_spec_1 (string, funfirstline)
7634 struct symtabs_and_lines sals;
7636 error ("Empty line specification.");
7637 if (default_breakpoint_valid)
7638 sals = decode_line_1 (&string, funfirstline,
7639 default_breakpoint_symtab,
7640 default_breakpoint_line,
7643 sals = decode_line_1 (&string, funfirstline,
7644 (struct symtab *) NULL, 0, (char ***) NULL);
7646 error ("Junk at end of line specification: %s", string);
7651 _initialize_breakpoint ()
7653 struct cmd_list_element *c;
7655 breakpoint_chain = 0;
7656 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7657 before a breakpoint is set. */
7658 breakpoint_count = 0;
7660 add_com ("ignore", class_breakpoint, ignore_command,
7661 "Set ignore-count of breakpoint number N to COUNT.\n\
7662 Usage is `ignore N COUNT'.");
7664 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7666 add_com ("commands", class_breakpoint, commands_command,
7667 "Set commands to be executed when a breakpoint is hit.\n\
7668 Give breakpoint number as argument after \"commands\".\n\
7669 With no argument, the targeted breakpoint is the last one set.\n\
7670 The commands themselves follow starting on the next line.\n\
7671 Type a line containing \"end\" to indicate the end of them.\n\
7672 Give \"silent\" as the first line to make the breakpoint silent;\n\
7673 then no output is printed when it is hit, except what the commands print.");
7675 add_com ("condition", class_breakpoint, condition_command,
7676 "Specify breakpoint number N to break only if COND is true.\n\
7677 Usage is `condition N COND', where N is an integer and COND is an\n\
7678 expression to be evaluated whenever breakpoint N is reached. ");
7680 add_com ("tbreak", class_breakpoint, tbreak_command,
7681 "Set a temporary breakpoint. Args like \"break\" command.\n\
7682 Like \"break\" except the breakpoint is only temporary,\n\
7683 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7684 by using \"enable delete\" on the breakpoint number.");
7685 add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7686 "Set temporary breakpoint at procedure exit. Either there should\n\
7687 be no argument or the argument must be a depth.\n");
7689 add_com ("hbreak", class_breakpoint, hbreak_command,
7690 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7691 Like \"break\" except the breakpoint requires hardware support,\n\
7692 some target hardware may not have this support.");
7694 add_com ("thbreak", class_breakpoint, thbreak_command,
7695 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7696 Like \"hbreak\" except the breakpoint is only temporary,\n\
7697 so it will be deleted when hit.");
7699 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7700 "Enable some breakpoints.\n\
7701 Give breakpoint numbers (separated by spaces) as arguments.\n\
7702 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7703 This is used to cancel the effect of the \"disable\" command.\n\
7704 With a subcommand you can enable temporarily.",
7705 &enablelist, "enable ", 1, &cmdlist);
7707 add_com ("ab", class_breakpoint, enable_command,
7708 "Enable some breakpoints.\n\
7709 Give breakpoint numbers (separated by spaces) as arguments.\n\
7710 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7711 This is used to cancel the effect of the \"disable\" command.\n\
7712 With a subcommand you can enable temporarily.");
7714 add_com_alias ("en", "enable", class_breakpoint, 1);
7716 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7717 "Enable some breakpoints.\n\
7718 Give breakpoint numbers (separated by spaces) as arguments.\n\
7719 This is used to cancel the effect of the \"disable\" command.\n\
7720 May be abbreviated to simply \"enable\".\n",
7721 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7723 add_cmd ("once", no_class, enable_once_command,
7724 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7725 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7728 add_cmd ("delete", no_class, enable_delete_command,
7729 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7730 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7733 add_cmd ("delete", no_class, enable_delete_command,
7734 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7735 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7738 add_cmd ("once", no_class, enable_once_command,
7739 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7740 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7743 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7744 "Disable some breakpoints.\n\
7745 Arguments are breakpoint numbers with spaces in between.\n\
7746 To disable all breakpoints, give no argument.\n\
7747 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7748 &disablelist, "disable ", 1, &cmdlist);
7749 add_com_alias ("dis", "disable", class_breakpoint, 1);
7750 add_com_alias ("disa", "disable", class_breakpoint, 1);
7752 add_com ("sb", class_breakpoint, disable_command,
7753 "Disable some breakpoints.\n\
7754 Arguments are breakpoint numbers with spaces in between.\n\
7755 To disable all breakpoints, give no argument.\n\
7756 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7758 add_cmd ("breakpoints", class_alias, disable_command,
7759 "Disable some breakpoints.\n\
7760 Arguments are breakpoint numbers with spaces in between.\n\
7761 To disable all breakpoints, give no argument.\n\
7762 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7763 This command may be abbreviated \"disable\".",
7766 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7767 "Delete some breakpoints or auto-display expressions.\n\
7768 Arguments are breakpoint numbers with spaces in between.\n\
7769 To delete all breakpoints, give no argument.\n\
7771 Also a prefix command for deletion of other GDB objects.\n\
7772 The \"unset\" command is also an alias for \"delete\".",
7773 &deletelist, "delete ", 1, &cmdlist);
7774 add_com_alias ("d", "delete", class_breakpoint, 1);
7776 add_com ("db", class_breakpoint, delete_command,
7777 "Delete some breakpoints.\n\
7778 Arguments are breakpoint numbers with spaces in between.\n\
7779 To delete all breakpoints, give no argument.\n");
7781 add_cmd ("breakpoints", class_alias, delete_command,
7782 "Delete some breakpoints or auto-display expressions.\n\
7783 Arguments are breakpoint numbers with spaces in between.\n\
7784 To delete all breakpoints, give no argument.\n\
7785 This command may be abbreviated \"delete\".",
7788 add_com ("clear", class_breakpoint, clear_command,
7789 concat ("Clear breakpoint at specified line or function.\n\
7790 Argument may be line number, function name, or \"*\" and an address.\n\
7791 If line number is specified, all breakpoints in that line are cleared.\n\
7792 If function is specified, breakpoints at beginning of function are cleared.\n\
7793 If an address is specified, breakpoints at that address are cleared.\n\n",
7794 "With no argument, clears all breakpoints in the line that the selected frame\n\
7797 See also the \"delete\" command which clears breakpoints by number.", NULL));
7799 add_com ("break", class_breakpoint, break_command,
7800 concat ("Set breakpoint at specified line or function.\n\
7801 Argument may be line number, function name, or \"*\" and an address.\n\
7802 If line number is specified, break at start of code for that line.\n\
7803 If function is specified, break at start of code for that function.\n\
7804 If an address is specified, break at that exact address.\n",
7805 "With no arg, uses current execution address of selected stack frame.\n\
7806 This is useful for breaking on return to a stack frame.\n\
7808 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7810 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7811 add_com_alias ("b", "break", class_run, 1);
7812 add_com_alias ("br", "break", class_run, 1);
7813 add_com_alias ("bre", "break", class_run, 1);
7814 add_com_alias ("brea", "break", class_run, 1);
7816 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7817 concat ("Set breakpoint at procedure exit. \n\
7818 Argument may be function name, or \"*\" and an address.\n\
7819 If function is specified, break at end of code for that function.\n\
7820 If an address is specified, break at the end of the function that contains \n\
7821 that exact address.\n",
7822 "With no arg, uses current execution address of selected stack frame.\n\
7823 This is useful for breaking on return to a stack frame.\n\
7825 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7827 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7828 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7829 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7830 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7831 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7835 add_com_alias ("ba", "break", class_breakpoint, 1);
7836 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7837 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
7838 "Set breakpoint at procedure exit. Either there should\n\
7839 be no argument or the argument must be a depth.\n");
7844 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7845 "Break in function/address or break at a line in the current file.",
7846 &stoplist, "stop ", 1, &cmdlist);
7847 add_cmd ("in", class_breakpoint, stopin_command,
7848 "Break in function or address.\n", &stoplist);
7849 add_cmd ("at", class_breakpoint, stopat_command,
7850 "Break at a line in the current file.\n", &stoplist);
7851 add_com ("status", class_info, breakpoints_info,
7852 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7853 The \"Type\" column indicates one of:\n\
7854 \tbreakpoint - normal breakpoint\n\
7855 \twatchpoint - watchpoint\n\
7856 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7857 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7858 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7859 address and file/line number respectively.\n\n",
7860 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7861 are set to the address of the last breakpoint listed.\n\n\
7862 Convenience variable \"$bpnum\" contains the number of the last\n\
7863 breakpoint set.", NULL));
7866 add_info ("breakpoints", breakpoints_info,
7867 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7868 The \"Type\" column indicates one of:\n\
7869 \tbreakpoint - normal breakpoint\n\
7870 \twatchpoint - watchpoint\n\
7871 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7872 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7873 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7874 address and file/line number respectively.\n\n",
7875 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7876 are set to the address of the last breakpoint listed.\n\n\
7877 Convenience variable \"$bpnum\" contains the number of the last\n\
7878 breakpoint set.", NULL));
7881 add_com ("lb", class_breakpoint, breakpoints_info,
7882 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7883 The \"Type\" column indicates one of:\n\
7884 \tbreakpoint - normal breakpoint\n\
7885 \twatchpoint - watchpoint\n\
7886 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7887 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7888 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7889 address and file/line number respectively.\n\n",
7890 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7891 are set to the address of the last breakpoint listed.\n\n\
7892 Convenience variable \"$bpnum\" contains the number of the last\n\
7893 breakpoint set.", NULL));
7895 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7896 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7897 The \"Type\" column indicates one of:\n\
7898 \tbreakpoint - normal breakpoint\n\
7899 \twatchpoint - watchpoint\n\
7900 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7901 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7902 \tuntil - internal breakpoint used by the \"until\" command\n\
7903 \tfinish - internal breakpoint used by the \"finish\" command\n",
7904 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7905 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7906 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7907 address and file/line number respectively.\n\n",
7908 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7909 are set to the address of the last breakpoint listed.\n\n\
7910 Convenience variable \"$bpnum\" contains the number of the last\n\
7911 breakpoint set.", NULL),
7912 &maintenanceinfolist);
7914 add_com ("catch", class_breakpoint, catch_command,
7915 "Set catchpoints to catch events.\n\
7916 Raised signals may be caught:\n\
7917 \tcatch signal - all signals\n\
7918 \tcatch signal <signame> - a particular signal\n\
7919 Raised exceptions may be caught:\n\
7920 \tcatch throw - all exceptions, when thrown\n\
7921 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7922 \tcatch catch - all exceptions, when caught\n\
7923 \tcatch catch <exceptname> - a particular exception, when caught\n\
7924 Thread or process events may be caught:\n\
7925 \tcatch thread_start - any threads, just after creation\n\
7926 \tcatch thread_exit - any threads, just before expiration\n\
7927 \tcatch thread_join - any threads, just after joins\n\
7928 Process events may be caught:\n\
7929 \tcatch start - any processes, just after creation\n\
7930 \tcatch exit - any processes, just before expiration\n\
7931 \tcatch fork - calls to fork()\n\
7932 \tcatch vfork - calls to vfork()\n\
7933 \tcatch exec - calls to exec()\n\
7934 Dynamically-linked library events may be caught:\n\
7935 \tcatch load - loads of any library\n\
7936 \tcatch load <libname> - loads of a particular library\n\
7937 \tcatch unload - unloads of any library\n\
7938 \tcatch unload <libname> - unloads of a particular library\n\
7939 The act of your program's execution stopping may also be caught:\n\
7941 C++ exceptions may be caught:\n\
7942 \tcatch throw - all exceptions, when thrown\n\
7943 \tcatch catch - all exceptions, when caught\n\
7945 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7946 after a fork or vfork is caught.\n\n\
7947 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7949 add_com ("tcatch", class_breakpoint, tcatch_command,
7950 "Set temporary catchpoints to catch events.\n\
7951 Args like \"catch\" command.\n\
7952 Like \"catch\" except the catchpoint is only temporary,\n\
7953 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7954 by using \"enable delete\" on the catchpoint number.");
7956 add_com ("watch", class_breakpoint, watch_command,
7957 "Set a watchpoint for an expression.\n\
7958 A watchpoint stops execution of your program whenever the value of\n\
7959 an expression changes.");
7961 add_com ("rwatch", class_breakpoint, rwatch_command,
7962 "Set a read watchpoint for an expression.\n\
7963 A watchpoint stops execution of your program whenever the value of\n\
7964 an expression is read.");
7966 add_com ("awatch", class_breakpoint, awatch_command,
7967 "Set a watchpoint for an expression.\n\
7968 A watchpoint stops execution of your program whenever the value of\n\
7969 an expression is either read or written.");
7971 add_info ("watchpoints", breakpoints_info,
7972 "Synonym for ``info breakpoints''.");
7975 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7976 (char *) &can_use_hw_watchpoints,
7977 "Set debugger's willingness to use watchpoint hardware.\n\
7978 If zero, gdb will not use hardware for new watchpoints, even if\n\
7979 such is available. (However, any hardware watchpoints that were\n\
7980 created before setting this to nonzero, will continue to use watchpoint\n\
7983 add_show_from_set (c, &showlist);
7985 can_use_hw_watchpoints = 1;