Make disable_breakpoints_in_unloaded_shlib static.
[gdb.git] / gdb / breakpoint.c
blob2f4bd8b878b985e0a859b4b55f7fb4c8a392dd3a
1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "defs.h"
23 #include <ctype.h>
24 #include "symtab.h"
25 #include "frame.h"
26 #include "breakpoint.h"
27 #include "gdbtypes.h"
28 #include "expression.h"
29 #include "gdbcore.h"
30 #include "gdbcmd.h"
31 #include "value.h"
32 #include "command.h"
33 #include "inferior.h"
34 #include "gdbthread.h"
35 #include "target.h"
36 #include "language.h"
37 #include "gdb_string.h"
38 #include "demangle.h"
39 #include "annotate.h"
40 #include "symfile.h"
41 #include "objfiles.h"
42 #include "source.h"
43 #include "linespec.h"
44 #include "completer.h"
45 #include "gdb.h"
46 #include "ui-out.h"
47 #include "cli/cli-script.h"
48 #include "gdb_assert.h"
49 #include "block.h"
50 #include "solib.h"
51 #include "solist.h"
52 #include "observer.h"
53 #include "exceptions.h"
54 #include "memattr.h"
55 #include "ada-lang.h"
56 #include "top.h"
58 #include "gdb-events.h"
59 #include "mi/mi-common.h"
61 /* Prototypes for local functions. */
63 static void until_break_command_continuation (struct continuation_arg *arg);
65 static void catch_command_1 (char *, int, int);
67 static void enable_delete_command (char *, int);
69 static void enable_delete_breakpoint (struct breakpoint *);
71 static void enable_once_command (char *, int);
73 static void enable_once_breakpoint (struct breakpoint *);
75 static void disable_command (char *, int);
77 static void enable_command (char *, int);
79 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
81 static void ignore_command (char *, int);
83 static int breakpoint_re_set_one (void *);
85 static void clear_command (char *, int);
87 static void catch_command (char *, int);
89 static void watch_command (char *, int);
91 static int can_use_hardware_watchpoint (struct value *);
93 static int break_command_1 (char *, int, int);
95 static void mention (struct breakpoint *);
97 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
99 static void check_duplicates (struct breakpoint *);
101 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
103 static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
104 enum bptype bptype);
106 static void describe_other_breakpoints (CORE_ADDR, asection *, int);
108 static void breakpoints_info (char *, int);
110 static void breakpoint_1 (int, int);
112 static bpstat bpstat_alloc (const struct bp_location *, bpstat);
114 static int breakpoint_cond_eval (void *);
116 static void cleanup_executing_breakpoints (void *);
118 static void commands_command (char *, int);
120 static void condition_command (char *, int);
122 static int get_number_trailer (char **, int);
124 void set_breakpoint_count (int);
126 typedef enum
128 mark_inserted,
129 mark_uninserted
131 insertion_state_t;
133 static int remove_breakpoint (struct bp_location *, insertion_state_t);
135 static enum print_stop_action print_it_typical (bpstat);
137 static enum print_stop_action print_bp_stop_message (bpstat bs);
139 typedef struct
141 enum exception_event_kind kind;
142 int enable_p;
144 args_for_catchpoint_enable;
146 static int watchpoint_check (void *);
148 static int cover_target_enable_exception_callback (void *);
150 static void maintenance_info_breakpoints (char *, int);
152 static void create_longjmp_breakpoint (char *);
154 static void create_overlay_event_breakpoint (char *);
156 static int hw_breakpoint_used_count (void);
158 static int hw_watchpoint_used_count (enum bptype, int *);
160 static void hbreak_command (char *, int);
162 static void thbreak_command (char *, int);
164 static void watch_command_1 (char *, int, int);
166 static void rwatch_command (char *, int);
168 static void awatch_command (char *, int);
170 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
172 static void create_fork_vfork_event_catchpoint (int tempflag,
173 char *cond_string,
174 enum bptype bp_kind);
176 static void stop_command (char *arg, int from_tty);
178 static void stopin_command (char *arg, int from_tty);
180 static void stopat_command (char *arg, int from_tty);
182 static char *ep_find_event_name_end (char *arg);
184 static char *ep_parse_optional_if_clause (char **arg);
186 static char *ep_parse_optional_filename (char **arg);
188 static void create_exception_catchpoint (int tempflag, char *cond_string,
189 enum exception_event_kind ex_event,
190 struct symtab_and_line *sal);
192 static void catch_exception_command_1 (enum exception_event_kind ex_event,
193 char *arg, int tempflag, int from_tty);
195 static void tcatch_command (char *arg, int from_tty);
197 static void ep_skip_leading_whitespace (char **s);
199 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
201 static void free_bp_location (struct bp_location *loc);
203 static void mark_breakpoints_out (void);
205 /* Prototypes for exported functions. */
207 /* If FALSE, gdb will not use hardware support for watchpoints, even
208 if such is available. */
209 static int can_use_hw_watchpoints;
211 static void
212 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
213 struct cmd_list_element *c,
214 const char *value)
216 fprintf_filtered (file, _("\
217 Debugger's willingness to use watchpoint hardware is %s.\n"),
218 value);
221 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
222 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
223 for unrecognized breakpoint locations.
224 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
225 static enum auto_boolean pending_break_support;
226 static void
227 show_pending_break_support (struct ui_file *file, int from_tty,
228 struct cmd_list_element *c,
229 const char *value)
231 fprintf_filtered (file, _("\
232 Debugger's behavior regarding pending breakpoints is %s.\n"),
233 value);
236 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
237 set with "break" but falling in read-only memory.
238 If 0, gdb will warn about such breakpoints, but won't automatically
239 use hardware breakpoints. */
240 static int automatic_hardware_breakpoints;
241 static void
242 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
243 struct cmd_list_element *c,
244 const char *value)
246 fprintf_filtered (file, _("\
247 Automatic usage of hardware breakpoints is %s.\n"),
248 value);
252 void _initialize_breakpoint (void);
254 extern int addressprint; /* Print machine addresses? */
256 /* Are we executing breakpoint commands? */
257 static int executing_breakpoint_commands;
259 /* Are overlay event breakpoints enabled? */
260 static int overlay_events_enabled;
262 /* Walk the following statement or block through all breakpoints.
263 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
264 breakpoint. */
266 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
268 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
269 for (B = breakpoint_chain; \
270 B ? (TMP=B->next, 1): 0; \
271 B = TMP)
273 /* Similar iterators for the low-level breakpoints. */
275 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
277 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
278 for (B = bp_location_chain; \
279 B ? (TMP=B->global_next, 1): 0; \
280 B = TMP)
282 /* True if breakpoint hit counts should be displayed in breakpoint info. */
284 int show_breakpoint_hit_counts = 1;
286 /* Chains of all breakpoints defined. */
288 struct breakpoint *breakpoint_chain;
290 struct bp_location *bp_location_chain;
292 /* Number of last breakpoint made. */
294 int breakpoint_count;
296 /* Pointer to current exception event record */
297 static struct exception_event_record *current_exception_event;
299 /* This function returns a pointer to the string representation of the
300 pathname of the dynamically-linked library that has just been
301 loaded.
303 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
304 or undefined results are guaranteed.
306 This string's contents are only valid immediately after the
307 inferior has stopped in the dynamic linker hook, and becomes
308 invalid as soon as the inferior is continued. Clients should make
309 a copy of this string if they wish to continue the inferior and
310 then access the string. */
312 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
313 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
314 #endif
316 /* This function returns a pointer to the string representation of the
317 pathname of the dynamically-linked library that has just been
318 unloaded.
320 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
321 TRUE, or undefined results are guaranteed.
323 This string's contents are only valid immediately after the
324 inferior has stopped in the dynamic linker hook, and becomes
325 invalid as soon as the inferior is continued. Clients should make
326 a copy of this string if they wish to continue the inferior and
327 then access the string. */
329 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
330 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
331 #endif
333 /* This function is called by the "catch load" command. It allows the
334 debugger to be notified by the dynamic linker when a specified
335 library file (or any library file, if filename is NULL) is loaded. */
337 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
338 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
339 error (_("catch of library loads not yet implemented on this platform"))
340 #endif
342 /* This function is called by the "catch unload" command. It allows
343 the debugger to be notified by the dynamic linker when a specified
344 library file (or any library file, if filename is NULL) is
345 unloaded. */
347 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
348 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
349 error (_("catch of library unloads not yet implemented on this platform"))
350 #endif
352 /* Return whether a breakpoint is an active enabled breakpoint. */
353 static int
354 breakpoint_enabled (struct breakpoint *b)
356 return (b->enable_state == bp_enabled);
359 /* Set breakpoint count to NUM. */
361 void
362 set_breakpoint_count (int num)
364 breakpoint_count = num;
365 set_internalvar (lookup_internalvar ("bpnum"),
366 value_from_longest (builtin_type_int, (LONGEST) num));
369 /* Used in run_command to zero the hit count when a new run starts. */
371 void
372 clear_breakpoint_hit_counts (void)
374 struct breakpoint *b;
376 ALL_BREAKPOINTS (b)
377 b->hit_count = 0;
380 /* Default address, symtab and line to put a breakpoint at
381 for "break" command with no arg.
382 if default_breakpoint_valid is zero, the other three are
383 not valid, and "break" with no arg is an error.
385 This set by print_stack_frame, which calls set_default_breakpoint. */
387 int default_breakpoint_valid;
388 CORE_ADDR default_breakpoint_address;
389 struct symtab *default_breakpoint_symtab;
390 int default_breakpoint_line;
392 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
393 Advance *PP after the string and any trailing whitespace.
395 Currently the string can either be a number or "$" followed by the name
396 of a convenience variable. Making it an expression wouldn't work well
397 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
399 If the string is a NULL pointer, that denotes the last breakpoint.
401 TRAILER is a character which can be found after the number; most
402 commonly this is `-'. If you don't want a trailer, use \0. */
403 static int
404 get_number_trailer (char **pp, int trailer)
406 int retval = 0; /* default */
407 char *p = *pp;
409 if (p == NULL)
410 /* Empty line means refer to the last breakpoint. */
411 return breakpoint_count;
412 else if (*p == '$')
414 /* Make a copy of the name, so we can null-terminate it
415 to pass to lookup_internalvar(). */
416 char *varname;
417 char *start = ++p;
418 struct value *val;
420 while (isalnum (*p) || *p == '_')
421 p++;
422 varname = (char *) alloca (p - start + 1);
423 strncpy (varname, start, p - start);
424 varname[p - start] = '\0';
425 val = value_of_internalvar (lookup_internalvar (varname));
426 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
427 retval = (int) value_as_long (val);
428 else
430 printf_filtered (_("Convenience variable must have integer value.\n"));
431 retval = 0;
434 else
436 if (*p == '-')
437 ++p;
438 while (*p >= '0' && *p <= '9')
439 ++p;
440 if (p == *pp)
441 /* There is no number here. (e.g. "cond a == b"). */
443 /* Skip non-numeric token */
444 while (*p && !isspace((int) *p))
445 ++p;
446 /* Return zero, which caller must interpret as error. */
447 retval = 0;
449 else
450 retval = atoi (*pp);
452 if (!(isspace (*p) || *p == '\0' || *p == trailer))
454 /* Trailing junk: return 0 and let caller print error msg. */
455 while (!(isspace (*p) || *p == '\0' || *p == trailer))
456 ++p;
457 retval = 0;
459 while (isspace (*p))
460 p++;
461 *pp = p;
462 return retval;
466 /* Like get_number_trailer, but don't allow a trailer. */
468 get_number (char **pp)
470 return get_number_trailer (pp, '\0');
473 /* Parse a number or a range.
474 * A number will be of the form handled by get_number.
475 * A range will be of the form <number1> - <number2>, and
476 * will represent all the integers between number1 and number2,
477 * inclusive.
479 * While processing a range, this fuction is called iteratively;
480 * At each call it will return the next value in the range.
482 * At the beginning of parsing a range, the char pointer PP will
483 * be advanced past <number1> and left pointing at the '-' token.
484 * Subsequent calls will not advance the pointer until the range
485 * is completed. The call that completes the range will advance
486 * pointer PP past <number2>.
489 int
490 get_number_or_range (char **pp)
492 static int last_retval, end_value;
493 static char *end_ptr;
494 static int in_range = 0;
496 if (**pp != '-')
498 /* Default case: pp is pointing either to a solo number,
499 or to the first number of a range. */
500 last_retval = get_number_trailer (pp, '-');
501 if (**pp == '-')
503 char **temp;
505 /* This is the start of a range (<number1> - <number2>).
506 Skip the '-', parse and remember the second number,
507 and also remember the end of the final token. */
509 temp = &end_ptr;
510 end_ptr = *pp + 1;
511 while (isspace ((int) *end_ptr))
512 end_ptr++; /* skip white space */
513 end_value = get_number (temp);
514 if (end_value < last_retval)
516 error (_("inverted range"));
518 else if (end_value == last_retval)
520 /* degenerate range (number1 == number2). Advance the
521 token pointer so that the range will be treated as a
522 single number. */
523 *pp = end_ptr;
525 else
526 in_range = 1;
529 else if (! in_range)
530 error (_("negative value"));
531 else
533 /* pp points to the '-' that betokens a range. All
534 number-parsing has already been done. Return the next
535 integer value (one greater than the saved previous value).
536 Do not advance the token pointer 'pp' until the end of range
537 is reached. */
539 if (++last_retval == end_value)
541 /* End of range reached; advance token pointer. */
542 *pp = end_ptr;
543 in_range = 0;
546 return last_retval;
551 /* condition N EXP -- set break condition of breakpoint N to EXP. */
553 static void
554 condition_command (char *arg, int from_tty)
556 struct breakpoint *b;
557 char *p;
558 int bnum;
560 if (arg == 0)
561 error_no_arg (_("breakpoint number"));
563 p = arg;
564 bnum = get_number (&p);
565 if (bnum == 0)
566 error (_("Bad breakpoint argument: '%s'"), arg);
568 ALL_BREAKPOINTS (b)
569 if (b->number == bnum)
571 struct bp_location *loc = b->loc;
572 for (; loc; loc = loc->next)
574 if (loc->cond)
576 xfree (loc->cond);
577 loc->cond = 0;
580 if (b->cond_string != NULL)
581 xfree (b->cond_string);
583 if (*p == 0)
585 b->cond_string = NULL;
586 if (from_tty)
587 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
589 else
591 arg = p;
592 /* I don't know if it matters whether this is the string the user
593 typed in or the decompiled expression. */
594 b->cond_string = savestring (arg, strlen (arg));
595 b->condition_not_parsed = 0;
596 for (loc = b->loc; loc; loc = loc->next)
598 arg = p;
599 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
600 if (*arg)
601 error (_("Junk at end of expression"));
604 breakpoints_changed ();
605 breakpoint_modify_event (b->number);
606 return;
609 error (_("No breakpoint number %d."), bnum);
612 static void
613 commands_command (char *arg, int from_tty)
615 struct breakpoint *b;
616 char *p;
617 int bnum;
618 struct command_line *l;
620 /* If we allowed this, we would have problems with when to
621 free the storage, if we change the commands currently
622 being read from. */
624 if (executing_breakpoint_commands)
625 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
627 p = arg;
628 bnum = get_number (&p);
630 if (p && *p)
631 error (_("Unexpected extra arguments following breakpoint number."));
633 ALL_BREAKPOINTS (b)
634 if (b->number == bnum)
636 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
637 bnum);
638 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
639 l = read_command_lines (tmpbuf, from_tty);
640 do_cleanups (cleanups);
641 free_command_lines (&b->commands);
642 b->commands = l;
643 breakpoints_changed ();
644 breakpoint_modify_event (b->number);
645 return;
647 error (_("No breakpoint number %d."), bnum);
650 /* Like commands_command, but instead of reading the commands from
651 input stream, takes them from an already parsed command structure.
653 This is used by cli-script.c to DTRT with breakpoint commands
654 that are part of if and while bodies. */
655 enum command_control_type
656 commands_from_control_command (char *arg, struct command_line *cmd)
658 struct breakpoint *b;
659 char *p;
660 int bnum;
662 /* If we allowed this, we would have problems with when to
663 free the storage, if we change the commands currently
664 being read from. */
666 if (executing_breakpoint_commands)
667 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
669 /* An empty string for the breakpoint number means the last
670 breakpoint, but get_number expects a NULL pointer. */
671 if (arg && !*arg)
672 p = NULL;
673 else
674 p = arg;
675 bnum = get_number (&p);
677 if (p && *p)
678 error (_("Unexpected extra arguments following breakpoint number."));
680 ALL_BREAKPOINTS (b)
681 if (b->number == bnum)
683 free_command_lines (&b->commands);
684 if (cmd->body_count != 1)
685 error (_("Invalid \"commands\" block structure."));
686 /* We need to copy the commands because if/while will free the
687 list after it finishes execution. */
688 b->commands = copy_command_lines (cmd->body_list[0]);
689 breakpoints_changed ();
690 breakpoint_modify_event (b->number);
691 return simple_control;
693 error (_("No breakpoint number %d."), bnum);
696 /* Like target_read_memory() but if breakpoints are inserted, return
697 the shadow contents instead of the breakpoints themselves.
699 Read "memory data" from whatever target or inferior we have.
700 Returns zero if successful, errno value if not. EIO is used
701 for address out of bounds. If breakpoints are inserted, returns
702 shadow contents, not the breakpoints themselves. From breakpoint.c. */
705 read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr, unsigned len)
707 int status;
708 const struct bp_location *b;
709 CORE_ADDR bp_addr = 0;
710 int bp_size = 0;
712 if (gdbarch_breakpoint_from_pc (current_gdbarch, &bp_addr, &bp_size) == NULL)
713 /* No breakpoints on this machine. */
714 return target_read_memory (memaddr, myaddr, len);
716 ALL_BP_LOCATIONS (b)
718 if (b->owner->type == bp_none)
719 warning (_("reading through apparently deleted breakpoint #%d?"),
720 b->owner->number);
722 if (b->loc_type != bp_loc_software_breakpoint)
723 continue;
724 if (!b->inserted)
725 continue;
726 /* Addresses and length of the part of the breakpoint that
727 we need to copy. */
728 bp_addr = b->target_info.placed_address;
729 bp_size = b->target_info.shadow_len;
730 if (bp_size == 0)
731 /* bp isn't valid, or doesn't shadow memory. */
732 continue;
733 if (bp_addr + bp_size <= memaddr)
734 /* The breakpoint is entirely before the chunk of memory we
735 are reading. */
736 continue;
737 if (bp_addr >= memaddr + len)
738 /* The breakpoint is entirely after the chunk of memory we are
739 reading. */
740 continue;
741 /* Copy the breakpoint from the shadow contents, and recurse for
742 the things before and after. */
744 /* Offset within shadow_contents. */
745 int bptoffset = 0;
747 if (bp_addr < memaddr)
749 /* Only copy the second part of the breakpoint. */
750 bp_size -= memaddr - bp_addr;
751 bptoffset = memaddr - bp_addr;
752 bp_addr = memaddr;
755 if (bp_addr + bp_size > memaddr + len)
757 /* Only copy the first part of the breakpoint. */
758 bp_size -= (bp_addr + bp_size) - (memaddr + len);
761 memcpy (myaddr + bp_addr - memaddr,
762 b->target_info.shadow_contents + bptoffset, bp_size);
764 if (bp_addr > memaddr)
766 /* Copy the section of memory before the breakpoint. */
767 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
768 if (status != 0)
769 return status;
772 if (bp_addr + bp_size < memaddr + len)
774 /* Copy the section of memory after the breakpoint. */
775 status = read_memory_nobpt (bp_addr + bp_size,
776 myaddr + bp_addr + bp_size - memaddr,
777 memaddr + len - (bp_addr + bp_size));
778 if (status != 0)
779 return status;
781 return 0;
784 /* Nothing overlaps. Just call read_memory_noerr. */
785 return target_read_memory (memaddr, myaddr, len);
789 /* A wrapper function for inserting catchpoints. */
790 static void
791 insert_catchpoint (struct ui_out *uo, void *args)
793 struct breakpoint *b = (struct breakpoint *) args;
794 int val = -1;
796 switch (b->type)
798 case bp_catch_fork:
799 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
800 break;
801 case bp_catch_vfork:
802 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
803 break;
804 case bp_catch_exec:
805 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
806 break;
807 default:
808 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
809 break;
813 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
815 static void
816 free_valchain (struct bp_location *b)
818 struct value *v;
819 struct value *n;
821 /* Free the saved value chain. We will construct a new one
822 the next time the watchpoint is inserted. */
823 for (v = b->owner->val_chain; v; v = n)
825 n = value_next (v);
826 value_free (v);
828 b->owner->val_chain = NULL;
831 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
832 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
833 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
835 NOTE drow/2003-09-09: This routine could be broken down to an object-style
836 method for each breakpoint or catchpoint type. */
837 static int
838 insert_bp_location (struct bp_location *bpt,
839 struct ui_file *tmp_error_stream,
840 int *disabled_breaks, int *process_warning,
841 int *hw_breakpoint_error)
843 int val = 0;
845 /* Permanent breakpoints cannot be inserted or removed. Disabled
846 breakpoints should not be inserted. */
847 if (!breakpoint_enabled (bpt->owner))
848 return 0;
850 if (!bpt->enabled || bpt->shlib_disabled || bpt->inserted || bpt->duplicate)
851 return 0;
853 /* Initialize the target-specific information. */
854 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
855 bpt->target_info.placed_address = bpt->address;
857 if (bpt->loc_type == bp_loc_software_breakpoint
858 || bpt->loc_type == bp_loc_hardware_breakpoint)
860 if (bpt->owner->type != bp_hardware_breakpoint)
862 /* If the explicitly specified breakpoint type
863 is not hardware breakpoint, check the memory map to see
864 if the breakpoint address is in read only memory or not.
865 Two important cases are:
866 - location type is not hardware breakpoint, memory
867 is readonly. We change the type of the location to
868 hardware breakpoint.
869 - location type is hardware breakpoint, memory is read-write.
870 This means we've previously made the location hardware one, but
871 then the memory map changed, so we undo.
873 When breakpoints are removed, remove_breakpoints will
874 use location types we've just set here, the only possible
875 problem is that memory map has changed during running program,
876 but it's not going to work anyway with current gdb. */
877 struct mem_region *mr
878 = lookup_mem_region (bpt->target_info.placed_address);
880 if (mr)
882 if (automatic_hardware_breakpoints)
884 int changed = 0;
885 enum bp_loc_type new_type;
887 if (mr->attrib.mode != MEM_RW)
888 new_type = bp_loc_hardware_breakpoint;
889 else
890 new_type = bp_loc_software_breakpoint;
892 if (new_type != bpt->loc_type)
894 static int said = 0;
895 bpt->loc_type = new_type;
896 if (!said)
898 fprintf_filtered (gdb_stdout, _("\
899 Note: automatically using hardware breakpoints for read-only addresses.\n"));
900 said = 1;
904 else if (bpt->loc_type == bp_loc_software_breakpoint
905 && mr->attrib.mode != MEM_RW)
906 warning (_("cannot set software breakpoint at readonly address %s"),
907 paddr (bpt->address));
911 /* First check to see if we have to handle an overlay. */
912 if (overlay_debugging == ovly_off
913 || bpt->section == NULL
914 || !(section_is_overlay (bpt->section)))
916 /* No overlay handling: just set the breakpoint. */
918 if (bpt->loc_type == bp_loc_hardware_breakpoint)
919 val = target_insert_hw_breakpoint (&bpt->target_info);
920 else
921 val = target_insert_breakpoint (&bpt->target_info);
923 else
925 /* This breakpoint is in an overlay section.
926 Shall we set a breakpoint at the LMA? */
927 if (!overlay_events_enabled)
929 /* Yes -- overlay event support is not active,
930 so we must try to set a breakpoint at the LMA.
931 This will not work for a hardware breakpoint. */
932 if (bpt->loc_type == bp_loc_hardware_breakpoint)
933 warning (_("hardware breakpoint %d not supported in overlay!"),
934 bpt->owner->number);
935 else
937 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
938 bpt->section);
939 /* Set a software (trap) breakpoint at the LMA. */
940 bpt->overlay_target_info = bpt->target_info;
941 bpt->overlay_target_info.placed_address = addr;
942 val = target_insert_breakpoint (&bpt->overlay_target_info);
943 if (val != 0)
944 fprintf_unfiltered (tmp_error_stream,
945 "Overlay breakpoint %d failed: in ROM?",
946 bpt->owner->number);
949 /* Shall we set a breakpoint at the VMA? */
950 if (section_is_mapped (bpt->section))
952 /* Yes. This overlay section is mapped into memory. */
953 if (bpt->loc_type == bp_loc_hardware_breakpoint)
954 val = target_insert_hw_breakpoint (&bpt->target_info);
955 else
956 val = target_insert_breakpoint (&bpt->target_info);
958 else
960 /* No. This breakpoint will not be inserted.
961 No error, but do not mark the bp as 'inserted'. */
962 return 0;
966 if (val)
968 /* Can't set the breakpoint. */
969 if (solib_address (bpt->address))
971 /* See also: disable_breakpoints_in_shlibs. */
972 val = 0;
973 bpt->shlib_disabled = 1;
974 if (!*disabled_breaks)
976 fprintf_unfiltered (tmp_error_stream,
977 "Cannot insert breakpoint %d.\n",
978 bpt->owner->number);
979 fprintf_unfiltered (tmp_error_stream,
980 "Temporarily disabling shared library breakpoints:\n");
982 *disabled_breaks = 1;
983 fprintf_unfiltered (tmp_error_stream,
984 "breakpoint #%d\n", bpt->owner->number);
986 else
988 #ifdef ONE_PROCESS_WRITETEXT
989 *process_warning = 1;
990 #endif
991 if (bpt->loc_type == bp_loc_hardware_breakpoint)
993 *hw_breakpoint_error = 1;
994 fprintf_unfiltered (tmp_error_stream,
995 "Cannot insert hardware breakpoint %d.\n",
996 bpt->owner->number);
998 else
1000 fprintf_unfiltered (tmp_error_stream,
1001 "Cannot insert breakpoint %d.\n",
1002 bpt->owner->number);
1003 fprintf_filtered (tmp_error_stream,
1004 "Error accessing memory address ");
1005 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1006 fprintf_filtered (tmp_error_stream, ": %s.\n",
1007 safe_strerror (val));
1012 else
1013 bpt->inserted = 1;
1015 return val;
1018 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1019 /* NOTE drow/2003-09-08: This state only exists for removing
1020 watchpoints. It's not clear that it's necessary... */
1021 && bpt->owner->disposition != disp_del_at_next_stop)
1023 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
1024 based on the expression. Ideally this should happen at a higher level,
1025 and there should be one bp_location for each computed address we
1026 must watch. As soon as a many-to-one mapping is available I'll
1027 convert this. */
1029 int within_current_scope;
1030 struct value *mark = value_mark ();
1031 struct value *v;
1032 struct frame_id saved_frame_id;
1034 /* Save the current frame's ID so we can restore it after
1035 evaluating the watchpoint expression on its own frame. */
1036 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1037 took a frame parameter, so that we didn't have to change the
1038 selected frame. */
1039 saved_frame_id = get_frame_id (get_selected_frame (NULL));
1041 /* Determine if the watchpoint is within scope. */
1042 if (bpt->owner->exp_valid_block == NULL)
1043 within_current_scope = 1;
1044 else
1046 struct frame_info *fi;
1047 fi = frame_find_by_id (bpt->owner->watchpoint_frame);
1048 within_current_scope = (fi != NULL);
1049 if (within_current_scope)
1050 select_frame (fi);
1053 if (within_current_scope)
1055 free_valchain (bpt);
1057 /* Evaluate the expression and cut the chain of values
1058 produced off from the value chain.
1060 Make sure the value returned isn't lazy; we use
1061 laziness to determine what memory GDB actually needed
1062 in order to compute the value of the expression. */
1063 v = evaluate_expression (bpt->owner->exp);
1064 value_contents (v);
1065 value_release_to_mark (mark);
1067 bpt->owner->val_chain = v;
1068 bpt->inserted = 1;
1070 /* Look at each value on the value chain. */
1071 for (; v; v = value_next (v))
1073 /* If it's a memory location, and GDB actually needed
1074 its contents to evaluate the expression, then we
1075 must watch it. */
1076 if (VALUE_LVAL (v) == lval_memory
1077 && ! value_lazy (v))
1079 struct type *vtype = check_typedef (value_type (v));
1081 /* We only watch structs and arrays if user asked
1082 for it explicitly, never if they just happen to
1083 appear in the middle of some value chain. */
1084 if (v == bpt->owner->val_chain
1085 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1086 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1088 CORE_ADDR addr;
1089 int len, type;
1091 addr = VALUE_ADDRESS (v) + value_offset (v);
1092 len = TYPE_LENGTH (value_type (v));
1093 type = hw_write;
1094 if (bpt->owner->type == bp_read_watchpoint)
1095 type = hw_read;
1096 else if (bpt->owner->type == bp_access_watchpoint)
1097 type = hw_access;
1099 val = target_insert_watchpoint (addr, len, type);
1100 if (val == -1)
1102 /* Don't exit the loop, try to insert
1103 every value on the value chain. That's
1104 because we will be removing all the
1105 watches below, and removing a
1106 watchpoint we didn't insert could have
1107 adverse effects. */
1108 bpt->inserted = 0;
1110 val = 0;
1114 /* Failure to insert a watchpoint on any memory value in the
1115 value chain brings us here. */
1116 if (!bpt->inserted)
1118 remove_breakpoint (bpt, mark_uninserted);
1119 *hw_breakpoint_error = 1;
1120 fprintf_unfiltered (tmp_error_stream,
1121 "Could not insert hardware watchpoint %d.\n",
1122 bpt->owner->number);
1123 val = -1;
1126 else
1128 printf_filtered (_("\
1129 Hardware watchpoint %d deleted because the program has left the block \n\
1130 in which its expression is valid.\n"),
1131 bpt->owner->number);
1132 if (bpt->owner->related_breakpoint)
1133 bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop;
1134 bpt->owner->disposition = disp_del_at_next_stop;
1137 /* Restore the selected frame. */
1138 select_frame (frame_find_by_id (saved_frame_id));
1140 return val;
1143 else if (ep_is_exception_catchpoint (bpt->owner))
1145 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1146 breakpoint. Once again, it would be better if this was represented
1147 as two bp_locations. */
1149 /* If we get here, we must have a callback mechanism for exception
1150 events -- with g++ style embedded label support, we insert
1151 ordinary breakpoints and not catchpoints. */
1152 val = target_insert_breakpoint (&bpt->target_info);
1153 if (val)
1155 /* Couldn't set breakpoint for some reason */
1156 fprintf_unfiltered (tmp_error_stream,
1157 "Cannot insert catchpoint %d; disabling it.\n",
1158 bpt->owner->number);
1159 fprintf_filtered (tmp_error_stream,
1160 "Error accessing memory address ");
1161 deprecated_print_address_numeric (bpt->address, 1, tmp_error_stream);
1162 fprintf_filtered (tmp_error_stream, ": %s.\n",
1163 safe_strerror (val));
1164 bpt->owner->enable_state = bp_disabled;
1166 else
1168 /* Bp set, now make sure callbacks are enabled */
1169 /* Format possible error msg */
1170 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
1171 bpt->owner->number);
1172 struct cleanup *cleanups = make_cleanup (xfree, message);
1173 int val;
1174 args_for_catchpoint_enable args;
1175 args.kind = bpt->owner->type == bp_catch_catch ?
1176 EX_EVENT_CATCH : EX_EVENT_THROW;
1177 args.enable_p = 1;
1178 val = catch_errors (cover_target_enable_exception_callback,
1179 &args, message, RETURN_MASK_ALL);
1180 do_cleanups (cleanups);
1181 if (val != 0 && val != -1)
1182 bpt->inserted = 1;
1184 /* Check if something went wrong; val == 0 can be ignored */
1185 if (val == -1)
1187 /* something went wrong */
1188 fprintf_unfiltered (tmp_error_stream,
1189 "Cannot insert catchpoint %d; disabling it.\n",
1190 bpt->owner->number);
1191 bpt->owner->enable_state = bp_disabled;
1195 return val;
1198 else if (bpt->owner->type == bp_catch_fork
1199 || bpt->owner->type == bp_catch_vfork
1200 || bpt->owner->type == bp_catch_exec)
1202 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1203 bpt->owner, RETURN_MASK_ERROR);
1204 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1205 bpt->owner->number);
1206 if (e.reason < 0)
1207 bpt->owner->enable_state = bp_disabled;
1208 else
1209 bpt->inserted = 1;
1211 /* We've already printed an error message if there was a problem
1212 inserting this catchpoint, and we've disabled the catchpoint,
1213 so just return success. */
1214 return 0;
1217 return 0;
1220 /* insert_breakpoints is used when starting or continuing the program.
1221 remove_breakpoints is used when the program stops.
1222 Both return zero if successful,
1223 or an `errno' value if could not write the inferior. */
1226 insert_breakpoints (void)
1228 struct bp_location *b, *temp;
1229 int return_val = 0; /* return success code. */
1230 int val = 0;
1231 int disabled_breaks = 0;
1232 int hw_breakpoint_error = 0;
1233 int process_warning = 0;
1235 struct ui_file *tmp_error_stream = mem_fileopen ();
1236 make_cleanup_ui_file_delete (tmp_error_stream);
1238 /* Explicitly mark the warning -- this will only be printed if
1239 there was an error. */
1240 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1242 ALL_BP_LOCATIONS_SAFE (b, temp)
1244 /* Permanent breakpoints cannot be inserted or removed. Disabled
1245 breakpoints should not be inserted. */
1246 if (!breakpoint_enabled (b->owner))
1247 continue;
1249 /* There is no point inserting thread-specific breakpoints if the
1250 thread no longer exists. */
1251 if (b->owner->thread != -1
1252 && !valid_thread_id (b->owner->thread))
1253 continue;
1255 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1256 hardware watchpoints are split into multiple loc breakpoints. */
1257 if ((b->loc_type == bp_loc_hardware_watchpoint
1258 || b->owner->type == bp_watchpoint) && !b->owner->val)
1260 struct value *val;
1261 val = evaluate_expression (b->owner->exp);
1262 release_value (val);
1263 if (value_lazy (val))
1264 value_fetch_lazy (val);
1265 b->owner->val = val;
1268 val = insert_bp_location (b, tmp_error_stream,
1269 &disabled_breaks, &process_warning,
1270 &hw_breakpoint_error);
1271 if (val)
1272 return_val = val;
1275 if (return_val)
1277 /* If a hardware breakpoint or watchpoint was inserted, add a
1278 message about possibly exhausted resources. */
1279 if (hw_breakpoint_error)
1281 fprintf_unfiltered (tmp_error_stream,
1282 "Could not insert hardware breakpoints:\n\
1283 You may have requested too many hardware breakpoints/watchpoints.\n");
1285 #ifdef ONE_PROCESS_WRITETEXT
1286 if (process_warning)
1287 fprintf_unfiltered (tmp_error_stream,
1288 "The same program may be running in another process.");
1289 #endif
1290 target_terminal_ours_for_output ();
1291 error_stream (tmp_error_stream);
1293 return return_val;
1297 remove_breakpoints (void)
1299 struct bp_location *b;
1300 int val;
1302 ALL_BP_LOCATIONS (b)
1304 if (b->inserted)
1306 val = remove_breakpoint (b, mark_uninserted);
1307 if (val != 0)
1308 return val;
1311 return 0;
1315 remove_hw_watchpoints (void)
1317 struct bp_location *b;
1318 int val;
1320 ALL_BP_LOCATIONS (b)
1322 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1324 val = remove_breakpoint (b, mark_uninserted);
1325 if (val != 0)
1326 return val;
1329 return 0;
1333 reattach_breakpoints (int pid)
1335 struct bp_location *b;
1336 int val;
1337 struct cleanup *old_chain = save_inferior_ptid ();
1338 struct ui_file *tmp_error_stream = mem_fileopen ();
1339 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1341 make_cleanup_ui_file_delete (tmp_error_stream);
1343 inferior_ptid = pid_to_ptid (pid);
1344 ALL_BP_LOCATIONS (b)
1346 if (b->inserted)
1348 b->inserted = 0;
1349 val = insert_bp_location (b, tmp_error_stream,
1350 &dummy1, &dummy2, &dummy3);
1351 if (val != 0)
1353 do_cleanups (old_chain);
1354 return val;
1358 do_cleanups (old_chain);
1359 return 0;
1362 void
1363 update_breakpoints_after_exec (void)
1365 struct breakpoint *b;
1366 struct breakpoint *temp;
1368 /* Doing this first prevents the badness of having delete_breakpoint()
1369 write a breakpoint's current "shadow contents" to lift the bp. That
1370 shadow is NOT valid after an exec()! */
1371 mark_breakpoints_out ();
1373 ALL_BREAKPOINTS_SAFE (b, temp)
1375 /* Solib breakpoints must be explicitly reset after an exec(). */
1376 if (b->type == bp_shlib_event)
1378 delete_breakpoint (b);
1379 continue;
1382 /* Thread event breakpoints must be set anew after an exec(),
1383 as must overlay event breakpoints. */
1384 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1386 delete_breakpoint (b);
1387 continue;
1390 /* Step-resume breakpoints are meaningless after an exec(). */
1391 if (b->type == bp_step_resume)
1393 delete_breakpoint (b);
1394 continue;
1397 /* Ditto the exception-handling catchpoints. */
1398 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1400 delete_breakpoint (b);
1401 continue;
1404 /* Don't delete an exec catchpoint, because else the inferior
1405 won't stop when it ought!
1407 Similarly, we probably ought to keep vfork catchpoints, 'cause
1408 on this target, we may not be able to stop when the vfork is
1409 seen, but only when the subsequent exec is seen. (And because
1410 deleting fork catchpoints here but not vfork catchpoints will
1411 seem mysterious to users, keep those too.) */
1412 if ((b->type == bp_catch_exec) ||
1413 (b->type == bp_catch_vfork) ||
1414 (b->type == bp_catch_fork))
1416 continue;
1419 /* bp_finish is a special case. The only way we ought to be able
1420 to see one of these when an exec() has happened, is if the user
1421 caught a vfork, and then said "finish". Ordinarily a finish just
1422 carries them to the call-site of the current callee, by setting
1423 a temporary bp there and resuming. But in this case, the finish
1424 will carry them entirely through the vfork & exec.
1426 We don't want to allow a bp_finish to remain inserted now. But
1427 we can't safely delete it, 'cause finish_command has a handle to
1428 the bp on a bpstat, and will later want to delete it. There's a
1429 chance (and I've seen it happen) that if we delete the bp_finish
1430 here, that its storage will get reused by the time finish_command
1431 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1432 We really must allow finish_command to delete a bp_finish.
1434 In the absense of a general solution for the "how do we know
1435 it's safe to delete something others may have handles to?"
1436 problem, what we'll do here is just uninsert the bp_finish, and
1437 let finish_command delete it.
1439 (We know the bp_finish is "doomed" in the sense that it's
1440 momentary, and will be deleted as soon as finish_command sees
1441 the inferior stopped. So it doesn't matter that the bp's
1442 address is probably bogus in the new a.out, unlike e.g., the
1443 solib breakpoints.) */
1445 if (b->type == bp_finish)
1447 continue;
1450 /* Without a symbolic address, we have little hope of the
1451 pre-exec() address meaning the same thing in the post-exec()
1452 a.out. */
1453 if (b->addr_string == NULL)
1455 delete_breakpoint (b);
1456 continue;
1459 /* FIXME what about longjmp breakpoints? Re-create them here? */
1460 create_overlay_event_breakpoint ("_ovly_debug_event");
1464 detach_breakpoints (int pid)
1466 struct bp_location *b;
1467 int val;
1468 struct cleanup *old_chain = save_inferior_ptid ();
1470 if (pid == PIDGET (inferior_ptid))
1471 error (_("Cannot detach breakpoints of inferior_ptid"));
1473 /* Set inferior_ptid; remove_breakpoint uses this global. */
1474 inferior_ptid = pid_to_ptid (pid);
1475 ALL_BP_LOCATIONS (b)
1477 if (b->inserted)
1479 val = remove_breakpoint (b, mark_inserted);
1480 if (val != 0)
1482 do_cleanups (old_chain);
1483 return val;
1487 do_cleanups (old_chain);
1488 return 0;
1491 static int
1492 remove_breakpoint (struct bp_location *b, insertion_state_t is)
1494 int val;
1496 if (b->owner->enable_state == bp_permanent)
1497 /* Permanent breakpoints cannot be inserted or removed. */
1498 return 0;
1500 if (b->owner->type == bp_none)
1501 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1502 b->owner->number);
1504 if (b->loc_type == bp_loc_software_breakpoint
1505 || b->loc_type == bp_loc_hardware_breakpoint)
1507 /* "Normal" instruction breakpoint: either the standard
1508 trap-instruction bp (bp_breakpoint), or a
1509 bp_hardware_breakpoint. */
1511 /* First check to see if we have to handle an overlay. */
1512 if (overlay_debugging == ovly_off
1513 || b->section == NULL
1514 || !(section_is_overlay (b->section)))
1516 /* No overlay handling: just remove the breakpoint. */
1518 if (b->loc_type == bp_loc_hardware_breakpoint)
1519 val = target_remove_hw_breakpoint (&b->target_info);
1520 else
1521 val = target_remove_breakpoint (&b->target_info);
1523 else
1525 /* This breakpoint is in an overlay section.
1526 Did we set a breakpoint at the LMA? */
1527 if (!overlay_events_enabled)
1529 /* Yes -- overlay event support is not active, so we
1530 should have set a breakpoint at the LMA. Remove it.
1532 /* Ignore any failures: if the LMA is in ROM, we will
1533 have already warned when we failed to insert it. */
1534 if (b->loc_type == bp_loc_hardware_breakpoint)
1535 target_remove_hw_breakpoint (&b->overlay_target_info);
1536 else
1537 target_remove_breakpoint (&b->overlay_target_info);
1539 /* Did we set a breakpoint at the VMA?
1540 If so, we will have marked the breakpoint 'inserted'. */
1541 if (b->inserted)
1543 /* Yes -- remove it. Previously we did not bother to
1544 remove the breakpoint if the section had been
1545 unmapped, but let's not rely on that being safe. We
1546 don't know what the overlay manager might do. */
1547 if (b->loc_type == bp_loc_hardware_breakpoint)
1548 val = target_remove_hw_breakpoint (&b->target_info);
1550 /* However, we should remove *software* breakpoints only
1551 if the section is still mapped, or else we overwrite
1552 wrong code with the saved shadow contents. */
1553 else if (section_is_mapped (b->section))
1554 val = target_remove_breakpoint (&b->target_info);
1555 else
1556 val = 0;
1558 else
1560 /* No -- not inserted, so no need to remove. No error. */
1561 val = 0;
1564 if (val)
1565 return val;
1566 b->inserted = (is == mark_inserted);
1568 else if (b->loc_type == bp_loc_hardware_watchpoint
1569 && breakpoint_enabled (b->owner)
1570 && !b->duplicate)
1572 struct value *v;
1573 struct value *n;
1575 b->inserted = (is == mark_inserted);
1576 /* Walk down the saved value chain. */
1577 for (v = b->owner->val_chain; v; v = value_next (v))
1579 /* For each memory reference remove the watchpoint
1580 at that address. */
1581 if (VALUE_LVAL (v) == lval_memory
1582 && ! value_lazy (v))
1584 struct type *vtype = check_typedef (value_type (v));
1586 if (v == b->owner->val_chain
1587 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1588 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1590 CORE_ADDR addr;
1591 int len, type;
1593 addr = VALUE_ADDRESS (v) + value_offset (v);
1594 len = TYPE_LENGTH (value_type (v));
1595 type = hw_write;
1596 if (b->owner->type == bp_read_watchpoint)
1597 type = hw_read;
1598 else if (b->owner->type == bp_access_watchpoint)
1599 type = hw_access;
1601 val = target_remove_watchpoint (addr, len, type);
1602 if (val == -1)
1603 b->inserted = 1;
1604 val = 0;
1608 /* Failure to remove any of the hardware watchpoints comes here. */
1609 if ((is == mark_uninserted) && (b->inserted))
1610 warning (_("Could not remove hardware watchpoint %d."),
1611 b->owner->number);
1613 else if ((b->owner->type == bp_catch_fork ||
1614 b->owner->type == bp_catch_vfork ||
1615 b->owner->type == bp_catch_exec)
1616 && breakpoint_enabled (b->owner)
1617 && !b->duplicate)
1619 val = -1;
1620 switch (b->owner->type)
1622 case bp_catch_fork:
1623 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1624 break;
1625 case bp_catch_vfork:
1626 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1627 break;
1628 case bp_catch_exec:
1629 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1630 break;
1631 default:
1632 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1633 break;
1635 if (val)
1636 return val;
1637 b->inserted = (is == mark_inserted);
1639 else if ((b->owner->type == bp_catch_catch ||
1640 b->owner->type == bp_catch_throw)
1641 && breakpoint_enabled (b->owner)
1642 && !b->duplicate)
1644 val = target_remove_breakpoint (&b->target_info);
1645 if (val)
1646 return val;
1647 b->inserted = (is == mark_inserted);
1650 return 0;
1653 /* Clear the "inserted" flag in all breakpoints. */
1655 static void
1656 mark_breakpoints_out (void)
1658 struct bp_location *bpt;
1660 ALL_BP_LOCATIONS (bpt)
1661 bpt->inserted = 0;
1664 /* Clear the "inserted" flag in all breakpoints and delete any
1665 breakpoints which should go away between runs of the program.
1667 Plus other such housekeeping that has to be done for breakpoints
1668 between runs.
1670 Note: this function gets called at the end of a run (by
1671 generic_mourn_inferior) and when a run begins (by
1672 init_wait_for_inferior). */
1676 void
1677 breakpoint_init_inferior (enum inf_context context)
1679 struct breakpoint *b, *temp;
1680 struct bp_location *bpt;
1682 ALL_BP_LOCATIONS (bpt)
1683 bpt->inserted = 0;
1685 ALL_BREAKPOINTS_SAFE (b, temp)
1687 switch (b->type)
1689 case bp_call_dummy:
1690 case bp_watchpoint_scope:
1692 /* If the call dummy breakpoint is at the entry point it will
1693 cause problems when the inferior is rerun, so we better
1694 get rid of it.
1696 Also get rid of scope breakpoints. */
1697 delete_breakpoint (b);
1698 break;
1700 case bp_watchpoint:
1701 case bp_hardware_watchpoint:
1702 case bp_read_watchpoint:
1703 case bp_access_watchpoint:
1705 /* Likewise for watchpoints on local expressions. */
1706 if (b->exp_valid_block != NULL)
1707 delete_breakpoint (b);
1708 else if (context == inf_starting)
1710 /* Reset val field to force reread of starting value
1711 in insert_breakpoints. */
1712 if (b->val)
1713 value_free (b->val);
1714 b->val = NULL;
1716 break;
1717 default:
1718 break;
1723 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1724 exists at PC. It returns ordinary_breakpoint_here if it's an
1725 ordinary breakpoint, or permanent_breakpoint_here if it's a
1726 permanent breakpoint.
1727 - When continuing from a location with an ordinary breakpoint, we
1728 actually single step once before calling insert_breakpoints.
1729 - When continuing from a localion with a permanent breakpoint, we
1730 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1731 the target, to advance the PC past the breakpoint. */
1733 enum breakpoint_here
1734 breakpoint_here_p (CORE_ADDR pc)
1736 const struct bp_location *bpt;
1737 int any_breakpoint_here = 0;
1739 ALL_BP_LOCATIONS (bpt)
1741 if (bpt->loc_type != bp_loc_software_breakpoint
1742 && bpt->loc_type != bp_loc_hardware_breakpoint)
1743 continue;
1745 if ((breakpoint_enabled (bpt->owner)
1746 || bpt->owner->enable_state == bp_permanent)
1747 && bpt->address == pc) /* bp is enabled and matches pc */
1749 if (overlay_debugging
1750 && section_is_overlay (bpt->section)
1751 && !section_is_mapped (bpt->section))
1752 continue; /* unmapped overlay -- can't be a match */
1753 else if (bpt->owner->enable_state == bp_permanent)
1754 return permanent_breakpoint_here;
1755 else
1756 any_breakpoint_here = 1;
1760 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1764 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1765 but it only returns true if there is actually a breakpoint inserted
1766 at PC. */
1769 breakpoint_inserted_here_p (CORE_ADDR pc)
1771 const struct bp_location *bpt;
1773 ALL_BP_LOCATIONS (bpt)
1775 if (bpt->loc_type != bp_loc_software_breakpoint
1776 && bpt->loc_type != bp_loc_hardware_breakpoint)
1777 continue;
1779 if (bpt->inserted
1780 && bpt->address == pc) /* bp is inserted and matches pc */
1782 if (overlay_debugging
1783 && section_is_overlay (bpt->section)
1784 && !section_is_mapped (bpt->section))
1785 continue; /* unmapped overlay -- can't be a match */
1786 else
1787 return 1;
1791 /* Also check for software single-step breakpoints. */
1792 if (single_step_breakpoint_inserted_here_p (pc))
1793 return 1;
1795 return 0;
1798 /* This function returns non-zero iff there is a software breakpoint
1799 inserted at PC. */
1802 software_breakpoint_inserted_here_p (CORE_ADDR pc)
1804 const struct bp_location *bpt;
1805 int any_breakpoint_here = 0;
1807 ALL_BP_LOCATIONS (bpt)
1809 if (bpt->loc_type != bp_loc_software_breakpoint)
1810 continue;
1812 if (bpt->inserted
1813 && bpt->address == pc) /* bp is enabled and matches pc */
1815 if (overlay_debugging
1816 && section_is_overlay (bpt->section)
1817 && !section_is_mapped (bpt->section))
1818 continue; /* unmapped overlay -- can't be a match */
1819 else
1820 return 1;
1824 /* Also check for software single-step breakpoints. */
1825 if (single_step_breakpoint_inserted_here_p (pc))
1826 return 1;
1828 return 0;
1831 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1832 PC is valid for process/thread PTID. */
1835 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1837 const struct bp_location *bpt;
1838 int thread;
1840 thread = pid_to_thread_id (ptid);
1842 ALL_BP_LOCATIONS (bpt)
1844 if (bpt->loc_type != bp_loc_software_breakpoint
1845 && bpt->loc_type != bp_loc_hardware_breakpoint)
1846 continue;
1848 if ((breakpoint_enabled (bpt->owner)
1849 || bpt->owner->enable_state == bp_permanent)
1850 && bpt->address == pc
1851 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1853 if (overlay_debugging
1854 && section_is_overlay (bpt->section)
1855 && !section_is_mapped (bpt->section))
1856 continue; /* unmapped overlay -- can't be a match */
1857 else
1858 return 1;
1862 return 0;
1866 /* bpstat stuff. External routines' interfaces are documented
1867 in breakpoint.h. */
1870 ep_is_catchpoint (struct breakpoint *ep)
1872 return
1873 (ep->type == bp_catch_load)
1874 || (ep->type == bp_catch_unload)
1875 || (ep->type == bp_catch_fork)
1876 || (ep->type == bp_catch_vfork)
1877 || (ep->type == bp_catch_exec)
1878 || (ep->type == bp_catch_catch)
1879 || (ep->type == bp_catch_throw);
1881 /* ??rehrauer: Add more kinds here, as are implemented... */
1885 ep_is_shlib_catchpoint (struct breakpoint *ep)
1887 return
1888 (ep->type == bp_catch_load)
1889 || (ep->type == bp_catch_unload);
1893 ep_is_exception_catchpoint (struct breakpoint *ep)
1895 return
1896 (ep->type == bp_catch_catch)
1897 || (ep->type == bp_catch_throw);
1900 void
1901 bpstat_free (bpstat bs)
1903 if (bs->old_val != NULL)
1904 value_free (bs->old_val);
1905 free_command_lines (&bs->commands);
1906 xfree (bs);
1909 /* Clear a bpstat so that it says we are not at any breakpoint.
1910 Also free any storage that is part of a bpstat. */
1912 void
1913 bpstat_clear (bpstat *bsp)
1915 bpstat p;
1916 bpstat q;
1918 if (bsp == 0)
1919 return;
1920 p = *bsp;
1921 while (p != NULL)
1923 q = p->next;
1924 bpstat_free (p);
1925 p = q;
1927 *bsp = NULL;
1930 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1931 is part of the bpstat is copied as well. */
1933 bpstat
1934 bpstat_copy (bpstat bs)
1936 bpstat p = NULL;
1937 bpstat tmp;
1938 bpstat retval = NULL;
1940 if (bs == NULL)
1941 return bs;
1943 for (; bs != NULL; bs = bs->next)
1945 tmp = (bpstat) xmalloc (sizeof (*tmp));
1946 memcpy (tmp, bs, sizeof (*tmp));
1947 if (bs->commands != NULL)
1948 tmp->commands = copy_command_lines (bs->commands);
1949 if (bs->old_val != NULL)
1950 tmp->old_val = value_copy (bs->old_val);
1952 if (p == NULL)
1953 /* This is the first thing in the chain. */
1954 retval = tmp;
1955 else
1956 p->next = tmp;
1957 p = tmp;
1959 p->next = NULL;
1960 return retval;
1963 /* Find the bpstat associated with this breakpoint */
1965 bpstat
1966 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1968 if (bsp == NULL)
1969 return NULL;
1971 for (; bsp != NULL; bsp = bsp->next)
1973 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
1974 return bsp;
1976 return NULL;
1979 /* Find a step_resume breakpoint associated with this bpstat.
1980 (If there are multiple step_resume bp's on the list, this function
1981 will arbitrarily pick one.)
1983 It is an error to use this function if BPSTAT doesn't contain a
1984 step_resume breakpoint.
1986 See wait_for_inferior's use of this function. */
1987 struct breakpoint *
1988 bpstat_find_step_resume_breakpoint (bpstat bsp)
1990 int current_thread;
1992 gdb_assert (bsp != NULL);
1994 current_thread = pid_to_thread_id (inferior_ptid);
1996 for (; bsp != NULL; bsp = bsp->next)
1998 if ((bsp->breakpoint_at != NULL) &&
1999 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
2000 (bsp->breakpoint_at->owner->thread == current_thread ||
2001 bsp->breakpoint_at->owner->thread == -1))
2002 return bsp->breakpoint_at->owner;
2005 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2009 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2010 at. *BSP upon return is a bpstat which points to the remaining
2011 breakpoints stopped at (but which is not guaranteed to be good for
2012 anything but further calls to bpstat_num).
2013 Return 0 if passed a bpstat which does not indicate any breakpoints.
2014 Return -1 if stopped at a breakpoint that has been deleted since
2015 we set it.
2016 Return 1 otherwise. */
2019 bpstat_num (bpstat *bsp, int *num)
2021 struct breakpoint *b;
2023 if ((*bsp) == NULL)
2024 return 0; /* No more breakpoint values */
2026 /* We assume we'll never have several bpstats that
2027 correspond to a single breakpoint -- otherwise,
2028 this function might return the same number more
2029 than once and this will look ugly. */
2030 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2031 *bsp = (*bsp)->next;
2032 if (b == NULL)
2033 return -1; /* breakpoint that's been deleted since */
2035 *num = b->number; /* We have its number */
2036 return 1;
2039 /* Modify BS so that the actions will not be performed. */
2041 void
2042 bpstat_clear_actions (bpstat bs)
2044 for (; bs != NULL; bs = bs->next)
2046 free_command_lines (&bs->commands);
2047 if (bs->old_val != NULL)
2049 value_free (bs->old_val);
2050 bs->old_val = NULL;
2055 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2056 static void
2057 cleanup_executing_breakpoints (void *ignore)
2059 executing_breakpoint_commands = 0;
2062 /* Execute all the commands associated with all the breakpoints at this
2063 location. Any of these commands could cause the process to proceed
2064 beyond this point, etc. We look out for such changes by checking
2065 the global "breakpoint_proceeded" after each command. */
2067 void
2068 bpstat_do_actions (bpstat *bsp)
2070 bpstat bs;
2071 struct cleanup *old_chain;
2073 /* Avoid endless recursion if a `source' command is contained
2074 in bs->commands. */
2075 if (executing_breakpoint_commands)
2076 return;
2078 executing_breakpoint_commands = 1;
2079 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2081 top:
2082 /* Note that (as of this writing), our callers all appear to
2083 be passing us the address of global stop_bpstat. And, if
2084 our calls to execute_control_command cause the inferior to
2085 proceed, that global (and hence, *bsp) will change.
2087 We must be careful to not touch *bsp unless the inferior
2088 has not proceeded. */
2090 /* This pointer will iterate over the list of bpstat's. */
2091 bs = *bsp;
2093 breakpoint_proceeded = 0;
2094 for (; bs != NULL; bs = bs->next)
2096 struct command_line *cmd;
2097 struct cleanup *this_cmd_tree_chain;
2099 /* Take ownership of the BSP's command tree, if it has one.
2101 The command tree could legitimately contain commands like
2102 'step' and 'next', which call clear_proceed_status, which
2103 frees stop_bpstat's command tree. To make sure this doesn't
2104 free the tree we're executing out from under us, we need to
2105 take ownership of the tree ourselves. Since a given bpstat's
2106 commands are only executed once, we don't need to copy it; we
2107 can clear the pointer in the bpstat, and make sure we free
2108 the tree when we're done. */
2109 cmd = bs->commands;
2110 bs->commands = 0;
2111 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2113 while (cmd != NULL)
2115 execute_control_command (cmd);
2117 if (breakpoint_proceeded)
2118 break;
2119 else
2120 cmd = cmd->next;
2123 /* We can free this command tree now. */
2124 do_cleanups (this_cmd_tree_chain);
2126 if (breakpoint_proceeded)
2127 /* The inferior is proceeded by the command; bomb out now.
2128 The bpstat chain has been blown away by wait_for_inferior.
2129 But since execution has stopped again, there is a new bpstat
2130 to look at, so start over. */
2131 goto top;
2133 do_cleanups (old_chain);
2136 /* This is the normal print function for a bpstat. In the future,
2137 much of this logic could (should?) be moved to bpstat_stop_status,
2138 by having it set different print_it values.
2140 Current scheme: When we stop, bpstat_print() is called. It loops
2141 through the bpstat list of things causing this stop, calling the
2142 print_bp_stop_message function on each one. The behavior of the
2143 print_bp_stop_message function depends on the print_it field of
2144 bpstat. If such field so indicates, call this function here.
2146 Return values from this routine (ultimately used by bpstat_print()
2147 and normal_stop() to decide what to do):
2148 PRINT_NOTHING: Means we already printed all we needed to print,
2149 don't print anything else.
2150 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2151 that something to be followed by a location.
2152 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2153 that something to be followed by a location.
2154 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2155 analysis. */
2157 static enum print_stop_action
2158 print_it_typical (bpstat bs)
2160 struct cleanup *old_chain, *ui_out_chain;
2161 struct breakpoint *b;
2162 const struct bp_location *bl;
2163 struct ui_stream *stb;
2164 stb = ui_out_stream_new (uiout);
2165 old_chain = make_cleanup_ui_out_stream_delete (stb);
2166 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2167 which has since been deleted. */
2168 if (bs->breakpoint_at == NULL)
2169 return PRINT_UNKNOWN;
2170 bl = bs->breakpoint_at;
2171 b = bl->owner;
2173 switch (b->type)
2175 case bp_breakpoint:
2176 case bp_hardware_breakpoint:
2177 if (bl->address != bl->requested_address)
2178 breakpoint_adjustment_warning (bl->requested_address,
2179 bl->address,
2180 b->number, 1);
2181 annotate_breakpoint (b->number);
2182 ui_out_text (uiout, "\nBreakpoint ");
2183 if (ui_out_is_mi_like_p (uiout))
2184 ui_out_field_string (uiout, "reason",
2185 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2186 ui_out_field_int (uiout, "bkptno", b->number);
2187 ui_out_text (uiout, ", ");
2188 return PRINT_SRC_AND_LOC;
2189 break;
2191 case bp_shlib_event:
2192 /* Did we stop because the user set the stop_on_solib_events
2193 variable? (If so, we report this as a generic, "Stopped due
2194 to shlib event" message.) */
2195 printf_filtered (_("Stopped due to shared library event\n"));
2196 return PRINT_NOTHING;
2197 break;
2199 case bp_thread_event:
2200 /* Not sure how we will get here.
2201 GDB should not stop for these breakpoints. */
2202 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2203 return PRINT_NOTHING;
2204 break;
2206 case bp_overlay_event:
2207 /* By analogy with the thread event, GDB should not stop for these. */
2208 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2209 return PRINT_NOTHING;
2210 break;
2212 case bp_catch_load:
2213 annotate_catchpoint (b->number);
2214 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2215 b->number,
2216 b->triggered_dll_pathname);
2217 return PRINT_SRC_AND_LOC;
2218 break;
2220 case bp_catch_unload:
2221 annotate_catchpoint (b->number);
2222 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2223 b->number,
2224 b->triggered_dll_pathname);
2225 return PRINT_SRC_AND_LOC;
2226 break;
2228 case bp_catch_fork:
2229 annotate_catchpoint (b->number);
2230 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2231 b->number,
2232 b->forked_inferior_pid);
2233 return PRINT_SRC_AND_LOC;
2234 break;
2236 case bp_catch_vfork:
2237 annotate_catchpoint (b->number);
2238 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2239 b->number,
2240 b->forked_inferior_pid);
2241 return PRINT_SRC_AND_LOC;
2242 break;
2244 case bp_catch_exec:
2245 annotate_catchpoint (b->number);
2246 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2247 b->number,
2248 b->exec_pathname);
2249 return PRINT_SRC_AND_LOC;
2250 break;
2252 case bp_catch_catch:
2253 if (current_exception_event &&
2254 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2256 annotate_catchpoint (b->number);
2257 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2258 b->number);
2259 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2260 printf_filtered (_("throw location %s:%d, "),
2261 CURRENT_EXCEPTION_THROW_FILE,
2262 CURRENT_EXCEPTION_THROW_LINE);
2263 else
2264 printf_filtered (_("throw location unknown, "));
2266 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2267 printf_filtered (_("catch location %s:%d\n"),
2268 CURRENT_EXCEPTION_CATCH_FILE,
2269 CURRENT_EXCEPTION_CATCH_LINE);
2270 else
2271 printf_filtered (_("catch location unknown\n"));
2273 /* don't bother to print location frame info */
2274 return PRINT_SRC_ONLY;
2276 else
2278 /* really throw, some other bpstat will handle it */
2279 return PRINT_UNKNOWN;
2281 break;
2283 case bp_catch_throw:
2284 if (current_exception_event &&
2285 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2287 annotate_catchpoint (b->number);
2288 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2289 b->number);
2290 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2291 printf_filtered (_("throw location %s:%d, "),
2292 CURRENT_EXCEPTION_THROW_FILE,
2293 CURRENT_EXCEPTION_THROW_LINE);
2294 else
2295 printf_filtered (_("throw location unknown, "));
2297 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2298 printf_filtered (_("catch location %s:%d\n"),
2299 CURRENT_EXCEPTION_CATCH_FILE,
2300 CURRENT_EXCEPTION_CATCH_LINE);
2301 else
2302 printf_filtered (_("catch location unknown\n"));
2304 /* don't bother to print location frame info */
2305 return PRINT_SRC_ONLY;
2307 else
2309 /* really catch, some other bpstat will handle it */
2310 return PRINT_UNKNOWN;
2312 break;
2314 case bp_watchpoint:
2315 case bp_hardware_watchpoint:
2316 if (bs->old_val != NULL)
2318 annotate_watchpoint (b->number);
2319 if (ui_out_is_mi_like_p (uiout))
2320 ui_out_field_string
2321 (uiout, "reason",
2322 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2323 mention (b);
2324 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2325 ui_out_text (uiout, "\nOld value = ");
2326 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2327 ui_out_field_stream (uiout, "old", stb);
2328 ui_out_text (uiout, "\nNew value = ");
2329 value_print (b->val, stb->stream, 0, Val_pretty_default);
2330 ui_out_field_stream (uiout, "new", stb);
2331 do_cleanups (ui_out_chain);
2332 ui_out_text (uiout, "\n");
2333 value_free (bs->old_val);
2334 bs->old_val = NULL;
2336 /* More than one watchpoint may have been triggered. */
2337 return PRINT_UNKNOWN;
2338 break;
2340 case bp_read_watchpoint:
2341 if (ui_out_is_mi_like_p (uiout))
2342 ui_out_field_string
2343 (uiout, "reason",
2344 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2345 mention (b);
2346 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2347 ui_out_text (uiout, "\nValue = ");
2348 value_print (b->val, stb->stream, 0, Val_pretty_default);
2349 ui_out_field_stream (uiout, "value", stb);
2350 do_cleanups (ui_out_chain);
2351 ui_out_text (uiout, "\n");
2352 return PRINT_UNKNOWN;
2353 break;
2355 case bp_access_watchpoint:
2356 if (bs->old_val != NULL)
2358 annotate_watchpoint (b->number);
2359 if (ui_out_is_mi_like_p (uiout))
2360 ui_out_field_string
2361 (uiout, "reason",
2362 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2363 mention (b);
2364 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2365 ui_out_text (uiout, "\nOld value = ");
2366 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2367 ui_out_field_stream (uiout, "old", stb);
2368 value_free (bs->old_val);
2369 bs->old_val = NULL;
2370 ui_out_text (uiout, "\nNew value = ");
2372 else
2374 mention (b);
2375 if (ui_out_is_mi_like_p (uiout))
2376 ui_out_field_string
2377 (uiout, "reason",
2378 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2379 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2380 ui_out_text (uiout, "\nValue = ");
2382 value_print (b->val, stb->stream, 0,Val_pretty_default);
2383 ui_out_field_stream (uiout, "new", stb);
2384 do_cleanups (ui_out_chain);
2385 ui_out_text (uiout, "\n");
2386 return PRINT_UNKNOWN;
2387 break;
2389 /* Fall through, we don't deal with these types of breakpoints
2390 here. */
2392 case bp_finish:
2393 if (ui_out_is_mi_like_p (uiout))
2394 ui_out_field_string
2395 (uiout, "reason",
2396 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2397 return PRINT_UNKNOWN;
2398 break;
2400 case bp_until:
2401 if (ui_out_is_mi_like_p (uiout))
2402 ui_out_field_string
2403 (uiout, "reason",
2404 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2405 return PRINT_UNKNOWN;
2406 break;
2408 case bp_none:
2409 case bp_longjmp:
2410 case bp_longjmp_resume:
2411 case bp_step_resume:
2412 case bp_watchpoint_scope:
2413 case bp_call_dummy:
2414 default:
2415 return PRINT_UNKNOWN;
2419 /* Generic routine for printing messages indicating why we
2420 stopped. The behavior of this function depends on the value
2421 'print_it' in the bpstat structure. Under some circumstances we
2422 may decide not to print anything here and delegate the task to
2423 normal_stop(). */
2425 static enum print_stop_action
2426 print_bp_stop_message (bpstat bs)
2428 switch (bs->print_it)
2430 case print_it_noop:
2431 /* Nothing should be printed for this bpstat entry. */
2432 return PRINT_UNKNOWN;
2433 break;
2435 case print_it_done:
2436 /* We still want to print the frame, but we already printed the
2437 relevant messages. */
2438 return PRINT_SRC_AND_LOC;
2439 break;
2441 case print_it_normal:
2443 const struct bp_location *bl = bs->breakpoint_at;
2444 struct breakpoint *b = bl ? bl->owner : NULL;
2446 /* Normal case. Call the breakpoint's print_it method, or
2447 print_it_typical. */
2448 /* FIXME: how breakpoint can ever be NULL here? */
2449 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2450 return b->ops->print_it (b);
2451 else
2452 return print_it_typical (bs);
2454 break;
2456 default:
2457 internal_error (__FILE__, __LINE__,
2458 _("print_bp_stop_message: unrecognized enum value"));
2459 break;
2463 /* Print a message indicating what happened. This is called from
2464 normal_stop(). The input to this routine is the head of the bpstat
2465 list - a list of the eventpoints that caused this stop. This
2466 routine calls the generic print routine for printing a message
2467 about reasons for stopping. This will print (for example) the
2468 "Breakpoint n," part of the output. The return value of this
2469 routine is one of:
2471 PRINT_UNKNOWN: Means we printed nothing
2472 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2473 code to print the location. An example is
2474 "Breakpoint 1, " which should be followed by
2475 the location.
2476 PRINT_SRC_ONLY: Means we printed something, but there is no need
2477 to also print the location part of the message.
2478 An example is the catch/throw messages, which
2479 don't require a location appended to the end.
2480 PRINT_NOTHING: We have done some printing and we don't need any
2481 further info to be printed.*/
2483 enum print_stop_action
2484 bpstat_print (bpstat bs)
2486 int val;
2488 /* Maybe another breakpoint in the chain caused us to stop.
2489 (Currently all watchpoints go on the bpstat whether hit or not.
2490 That probably could (should) be changed, provided care is taken
2491 with respect to bpstat_explains_signal). */
2492 for (; bs; bs = bs->next)
2494 val = print_bp_stop_message (bs);
2495 if (val == PRINT_SRC_ONLY
2496 || val == PRINT_SRC_AND_LOC
2497 || val == PRINT_NOTHING)
2498 return val;
2501 /* We reached the end of the chain, or we got a null BS to start
2502 with and nothing was printed. */
2503 return PRINT_UNKNOWN;
2506 /* Evaluate the expression EXP and return 1 if value is zero.
2507 This is used inside a catch_errors to evaluate the breakpoint condition.
2508 The argument is a "struct expression *" that has been cast to char * to
2509 make it pass through catch_errors. */
2511 static int
2512 breakpoint_cond_eval (void *exp)
2514 struct value *mark = value_mark ();
2515 int i = !value_true (evaluate_expression ((struct expression *) exp));
2516 value_free_to_mark (mark);
2517 return i;
2520 /* Allocate a new bpstat and chain it to the current one. */
2522 static bpstat
2523 bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2525 bpstat bs;
2527 bs = (bpstat) xmalloc (sizeof (*bs));
2528 cbs->next = bs;
2529 bs->breakpoint_at = bl;
2530 /* If the condition is false, etc., don't do the commands. */
2531 bs->commands = NULL;
2532 bs->old_val = NULL;
2533 bs->print_it = print_it_normal;
2534 return bs;
2537 /* The target has stopped with waitstatus WS. Check if any hardware
2538 watchpoints have triggered, according to the target. */
2541 watchpoints_triggered (struct target_waitstatus *ws)
2543 int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws);
2544 CORE_ADDR addr;
2545 struct breakpoint *b;
2547 if (!stopped_by_watchpoint)
2549 /* We were not stopped by a watchpoint. Mark all watchpoints
2550 as not triggered. */
2551 ALL_BREAKPOINTS (b)
2552 if (b->type == bp_hardware_watchpoint
2553 || b->type == bp_read_watchpoint
2554 || b->type == bp_access_watchpoint)
2555 b->watchpoint_triggered = watch_triggered_no;
2557 return 0;
2560 if (!target_stopped_data_address (&current_target, &addr))
2562 /* We were stopped by a watchpoint, but we don't know where.
2563 Mark all watchpoints as unknown. */
2564 ALL_BREAKPOINTS (b)
2565 if (b->type == bp_hardware_watchpoint
2566 || b->type == bp_read_watchpoint
2567 || b->type == bp_access_watchpoint)
2568 b->watchpoint_triggered = watch_triggered_unknown;
2570 return stopped_by_watchpoint;
2573 /* The target could report the data address. Mark watchpoints
2574 affected by this data address as triggered, and all others as not
2575 triggered. */
2577 ALL_BREAKPOINTS (b)
2578 if (b->type == bp_hardware_watchpoint
2579 || b->type == bp_read_watchpoint
2580 || b->type == bp_access_watchpoint)
2582 struct value *v;
2584 b->watchpoint_triggered = watch_triggered_no;
2585 for (v = b->val_chain; v; v = value_next (v))
2587 if (VALUE_LVAL (v) == lval_memory && ! value_lazy (v))
2589 struct type *vtype = check_typedef (value_type (v));
2591 if (v == b->val_chain
2592 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2593 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2595 CORE_ADDR vaddr;
2597 vaddr = VALUE_ADDRESS (v) + value_offset (v);
2598 /* Exact match not required. Within range is
2599 sufficient. */
2600 if (addr >= vaddr
2601 && addr < vaddr + TYPE_LENGTH (value_type (v)))
2603 b->watchpoint_triggered = watch_triggered_yes;
2604 break;
2611 return 1;
2614 /* Possible return values for watchpoint_check (this can't be an enum
2615 because of check_errors). */
2616 /* The watchpoint has been deleted. */
2617 #define WP_DELETED 1
2618 /* The value has changed. */
2619 #define WP_VALUE_CHANGED 2
2620 /* The value has not changed. */
2621 #define WP_VALUE_NOT_CHANGED 3
2623 #define BP_TEMPFLAG 1
2624 #define BP_HARDWAREFLAG 2
2626 /* Check watchpoint condition. */
2628 static int
2629 watchpoint_check (void *p)
2631 bpstat bs = (bpstat) p;
2632 struct breakpoint *b;
2633 struct frame_info *fr;
2634 int within_current_scope;
2636 b = bs->breakpoint_at->owner;
2638 if (b->exp_valid_block == NULL)
2639 within_current_scope = 1;
2640 else
2642 /* There is no current frame at this moment. If we're going to have
2643 any chance of handling watchpoints on local variables, we'll need
2644 the frame chain (so we can determine if we're in scope). */
2645 reinit_frame_cache ();
2646 fr = frame_find_by_id (b->watchpoint_frame);
2647 within_current_scope = (fr != NULL);
2649 /* If we've gotten confused in the unwinder, we might have
2650 returned a frame that can't describe this variable. */
2651 if (within_current_scope
2652 && block_function (b->exp_valid_block) != get_frame_function (fr))
2653 within_current_scope = 0;
2655 /* in_function_epilogue_p() returns a non-zero value if we're still
2656 in the function but the stack frame has already been invalidated.
2657 Since we can't rely on the values of local variables after the
2658 stack has been destroyed, we are treating the watchpoint in that
2659 state as `not changed' without further checking.
2661 vinschen/2003-09-04: The former implementation left out the case
2662 that the watchpoint frame couldn't be found by frame_find_by_id()
2663 because the current PC is currently in an epilogue. Calling
2664 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2665 if ((!within_current_scope || fr == get_current_frame ())
2666 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2667 return WP_VALUE_NOT_CHANGED;
2668 if (fr && within_current_scope)
2669 /* If we end up stopping, the current frame will get selected
2670 in normal_stop. So this call to select_frame won't affect
2671 the user. */
2672 select_frame (fr);
2675 if (within_current_scope)
2677 /* We use value_{,free_to_}mark because it could be a
2678 *long* time before we return to the command level and
2679 call free_all_values. We can't call free_all_values because
2680 we might be in the middle of evaluating a function call. */
2682 struct value *mark = value_mark ();
2683 struct value *new_val = evaluate_expression (b->exp);
2684 if (!value_equal (b->val, new_val))
2686 release_value (new_val);
2687 value_free_to_mark (mark);
2688 bs->old_val = b->val;
2689 b->val = new_val;
2690 /* We will stop here */
2691 return WP_VALUE_CHANGED;
2693 else
2695 /* Nothing changed, don't do anything. */
2696 value_free_to_mark (mark);
2697 /* We won't stop here */
2698 return WP_VALUE_NOT_CHANGED;
2701 else
2703 /* This seems like the only logical thing to do because
2704 if we temporarily ignored the watchpoint, then when
2705 we reenter the block in which it is valid it contains
2706 garbage (in the case of a function, it may have two
2707 garbage values, one before and one after the prologue).
2708 So we can't even detect the first assignment to it and
2709 watch after that (since the garbage may or may not equal
2710 the first value assigned). */
2711 /* We print all the stop information in print_it_typical(), but
2712 in this case, by the time we call print_it_typical() this bp
2713 will be deleted already. So we have no choice but print the
2714 information here. */
2715 if (ui_out_is_mi_like_p (uiout))
2716 ui_out_field_string
2717 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2718 ui_out_text (uiout, "\nWatchpoint ");
2719 ui_out_field_int (uiout, "wpnum", b->number);
2720 ui_out_text (uiout, " deleted because the program has left the block in\n\
2721 which its expression is valid.\n");
2723 if (b->related_breakpoint)
2724 b->related_breakpoint->disposition = disp_del_at_next_stop;
2725 b->disposition = disp_del_at_next_stop;
2727 return WP_DELETED;
2731 /* Get a bpstat associated with having just stopped at address
2732 BP_ADDR in thread PTID.
2734 Determine whether we stopped at a breakpoint, etc, or whether we
2735 don't understand this stop. Result is a chain of bpstat's such that:
2737 if we don't understand the stop, the result is a null pointer.
2739 if we understand why we stopped, the result is not null.
2741 Each element of the chain refers to a particular breakpoint or
2742 watchpoint at which we have stopped. (We may have stopped for
2743 several reasons concurrently.)
2745 Each element of the chain has valid next, breakpoint_at,
2746 commands, FIXME??? fields. */
2748 bpstat
2749 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
2751 struct breakpoint *b = NULL;
2752 const struct bp_location *bl;
2753 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2754 int real_breakpoint = 0;
2755 /* Root of the chain of bpstat's */
2756 struct bpstats root_bs[1];
2757 /* Pointer to the last thing in the chain currently. */
2758 bpstat bs = root_bs;
2759 int thread_id = pid_to_thread_id (ptid);
2761 ALL_BP_LOCATIONS (bl)
2763 b = bl->owner;
2764 gdb_assert (b);
2765 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
2766 continue;
2768 if (b->type != bp_watchpoint
2769 && b->type != bp_hardware_watchpoint
2770 && b->type != bp_read_watchpoint
2771 && b->type != bp_access_watchpoint
2772 && b->type != bp_hardware_breakpoint
2773 && b->type != bp_catch_fork
2774 && b->type != bp_catch_vfork
2775 && b->type != bp_catch_exec
2776 && b->type != bp_catch_catch
2777 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2779 if (bl->address != bp_addr) /* address doesn't match */
2780 continue;
2781 if (overlay_debugging /* unmapped overlay section */
2782 && section_is_overlay (bl->section)
2783 && !section_is_mapped (bl->section))
2784 continue;
2787 /* Continuable hardware watchpoints are treated as non-existent if the
2788 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2789 some data address). Otherwise gdb won't stop on a break instruction
2790 in the code (not from a breakpoint) when a hardware watchpoint has
2791 been defined. Also skip watchpoints which we know did not trigger
2792 (did not match the data address). */
2794 if ((b->type == bp_hardware_watchpoint
2795 || b->type == bp_read_watchpoint
2796 || b->type == bp_access_watchpoint)
2797 && b->watchpoint_triggered == watch_triggered_no)
2798 continue;
2800 if (b->type == bp_hardware_breakpoint)
2802 if (bl->address != bp_addr)
2803 continue;
2804 if (overlay_debugging /* unmapped overlay section */
2805 && section_is_overlay (bl->section)
2806 && !section_is_mapped (bl->section))
2807 continue;
2810 /* Is this a catchpoint of a load or unload? If so, did we
2811 get a load or unload of the specified library? If not,
2812 ignore it. */
2813 if ((b->type == bp_catch_load)
2814 #if defined(SOLIB_HAVE_LOAD_EVENT)
2815 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2816 || ((b->dll_pathname != NULL)
2817 && (strcmp (b->dll_pathname,
2818 SOLIB_LOADED_LIBRARY_PATHNAME (
2819 PIDGET (inferior_ptid)))
2820 != 0)))
2821 #endif
2823 continue;
2825 if ((b->type == bp_catch_unload)
2826 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2827 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2828 || ((b->dll_pathname != NULL)
2829 && (strcmp (b->dll_pathname,
2830 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2831 PIDGET (inferior_ptid)))
2832 != 0)))
2833 #endif
2835 continue;
2837 if ((b->type == bp_catch_fork)
2838 && !inferior_has_forked (PIDGET (inferior_ptid),
2839 &b->forked_inferior_pid))
2840 continue;
2842 if ((b->type == bp_catch_vfork)
2843 && !inferior_has_vforked (PIDGET (inferior_ptid),
2844 &b->forked_inferior_pid))
2845 continue;
2847 if ((b->type == bp_catch_exec)
2848 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2849 continue;
2851 if (ep_is_exception_catchpoint (b) &&
2852 !(current_exception_event = target_get_current_exception_event ()))
2853 continue;
2855 /* Come here if it's a watchpoint, or if the break address matches */
2857 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
2859 /* Watchpoints may change this, if not found to have triggered. */
2860 bs->stop = 1;
2861 bs->print = 1;
2863 if (b->type == bp_watchpoint
2864 || b->type == bp_read_watchpoint
2865 || b->type == bp_access_watchpoint
2866 || b->type == bp_hardware_watchpoint)
2868 CORE_ADDR addr;
2869 struct value *v;
2870 int must_check_value = 0;
2872 if (b->type == bp_watchpoint)
2873 /* For a software watchpoint, we must always check the
2874 watched value. */
2875 must_check_value = 1;
2876 else if (b->watchpoint_triggered == watch_triggered_yes)
2877 /* We have a hardware watchpoint (read, write, or access)
2878 and the target earlier reported an address watched by
2879 this watchpoint. */
2880 must_check_value = 1;
2881 else if (b->watchpoint_triggered == watch_triggered_unknown
2882 && b->type == bp_hardware_watchpoint)
2883 /* We were stopped by a hardware watchpoint, but the target could
2884 not report the data address. We must check the watchpoint's
2885 value. Access and read watchpoints are out of luck; without
2886 a data address, we can't figure it out. */
2887 must_check_value = 1;
2889 if (must_check_value)
2891 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2892 b->number);
2893 struct cleanup *cleanups = make_cleanup (xfree, message);
2894 int e = catch_errors (watchpoint_check, bs, message,
2895 RETURN_MASK_ALL);
2896 do_cleanups (cleanups);
2897 switch (e)
2899 case WP_DELETED:
2900 /* We've already printed what needs to be printed. */
2901 bs->print_it = print_it_done;
2902 /* Stop. */
2903 break;
2904 case WP_VALUE_CHANGED:
2905 if (b->type == bp_read_watchpoint)
2907 /* Don't stop: read watchpoints shouldn't fire if
2908 the value has changed. This is for targets
2909 which cannot set read-only watchpoints. */
2910 bs->print_it = print_it_noop;
2911 bs->stop = 0;
2912 continue;
2914 ++(b->hit_count);
2915 break;
2916 case WP_VALUE_NOT_CHANGED:
2917 if (b->type == bp_hardware_watchpoint
2918 || b->type == bp_watchpoint)
2920 /* Don't stop: write watchpoints shouldn't fire if
2921 the value hasn't changed. */
2922 bs->print_it = print_it_noop;
2923 bs->stop = 0;
2924 continue;
2926 /* Stop. */
2927 ++(b->hit_count);
2928 break;
2929 default:
2930 /* Can't happen. */
2931 case 0:
2932 /* Error from catch_errors. */
2933 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2934 if (b->related_breakpoint)
2935 b->related_breakpoint->disposition = disp_del_at_next_stop;
2936 b->disposition = disp_del_at_next_stop;
2937 /* We've already printed what needs to be printed. */
2938 bs->print_it = print_it_done;
2939 break;
2942 else /* must_check_value == 0 */
2944 /* This is a case where some watchpoint(s) triggered, but
2945 not at the address of this watchpoint, or else no
2946 watchpoint triggered after all. So don't print
2947 anything for this watchpoint. */
2948 bs->print_it = print_it_noop;
2949 bs->stop = 0;
2950 continue;
2953 else
2955 /* By definition, an encountered breakpoint is a triggered
2956 breakpoint. */
2957 ++(b->hit_count);
2959 real_breakpoint = 1;
2962 if (frame_id_p (b->frame_id)
2963 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2964 bs->stop = 0;
2965 else
2967 int value_is_zero = 0;
2969 /* If this is a scope breakpoint, mark the associated
2970 watchpoint as triggered so that we will handle the
2971 out-of-scope event. We'll get to the watchpoint next
2972 iteration. */
2973 if (b->type == bp_watchpoint_scope)
2974 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
2976 if (bl->cond)
2978 /* Need to select the frame, with all that implies
2979 so that the conditions will have the right context. */
2980 select_frame (get_current_frame ());
2981 value_is_zero
2982 = catch_errors (breakpoint_cond_eval, (bl->cond),
2983 "Error in testing breakpoint condition:\n",
2984 RETURN_MASK_ALL);
2985 /* FIXME-someday, should give breakpoint # */
2986 free_all_values ();
2988 if (bl->cond && value_is_zero)
2990 bs->stop = 0;
2991 /* Don't consider this a hit. */
2992 --(b->hit_count);
2994 else if (b->thread != -1 && b->thread != thread_id)
2996 bs->stop = 0;
2997 /* Don't consider this a hit. */
2998 --(b->hit_count);
3000 else if (b->ignore_count > 0)
3002 b->ignore_count--;
3003 annotate_ignore_count_change ();
3004 bs->stop = 0;
3006 else if (b->type == bp_thread_event || b->type == bp_overlay_event)
3007 /* We do not stop for these. */
3008 bs->stop = 0;
3009 else
3011 /* We will stop here */
3012 if (b->disposition == disp_disable)
3013 b->enable_state = bp_disabled;
3014 if (b->silent)
3015 bs->print = 0;
3016 bs->commands = b->commands;
3017 if (bs->commands &&
3018 (strcmp ("silent", bs->commands->line) == 0
3019 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3021 bs->commands = bs->commands->next;
3022 bs->print = 0;
3024 bs->commands = copy_command_lines (bs->commands);
3027 /* Print nothing for this entry if we dont stop or if we dont print. */
3028 if (bs->stop == 0 || bs->print == 0)
3029 bs->print_it = print_it_noop;
3032 bs->next = NULL; /* Terminate the chain */
3033 bs = root_bs->next; /* Re-grab the head of the chain */
3035 /* If we aren't stopping, the value of some hardware watchpoint may
3036 not have changed, but the intermediate memory locations we are
3037 watching may have. Don't bother if we're stopping; this will get
3038 done later. */
3039 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3040 if (bs->stop)
3041 break;
3043 if (bs == NULL)
3044 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3045 if (!bs->stop
3046 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3047 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3048 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3050 remove_breakpoints ();
3051 insert_breakpoints ();
3052 break;
3055 return root_bs->next;
3058 /* Tell what to do about this bpstat. */
3059 struct bpstat_what
3060 bpstat_what (bpstat bs)
3062 /* Classify each bpstat as one of the following. */
3063 enum class
3065 /* This bpstat element has no effect on the main_action. */
3066 no_effect = 0,
3068 /* There was a watchpoint, stop but don't print. */
3069 wp_silent,
3071 /* There was a watchpoint, stop and print. */
3072 wp_noisy,
3074 /* There was a breakpoint but we're not stopping. */
3075 bp_nostop,
3077 /* There was a breakpoint, stop but don't print. */
3078 bp_silent,
3080 /* There was a breakpoint, stop and print. */
3081 bp_noisy,
3083 /* We hit the longjmp breakpoint. */
3084 long_jump,
3086 /* We hit the longjmp_resume breakpoint. */
3087 long_resume,
3089 /* We hit the step_resume breakpoint. */
3090 step_resume,
3092 /* We hit the shared library event breakpoint. */
3093 shlib_event,
3095 /* We caught a shared library event. */
3096 catch_shlib_event,
3098 /* This is just used to count how many enums there are. */
3099 class_last
3102 /* Here is the table which drives this routine. So that we can
3103 format it pretty, we define some abbreviations for the
3104 enum bpstat_what codes. */
3105 #define kc BPSTAT_WHAT_KEEP_CHECKING
3106 #define ss BPSTAT_WHAT_STOP_SILENT
3107 #define sn BPSTAT_WHAT_STOP_NOISY
3108 #define sgl BPSTAT_WHAT_SINGLE
3109 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3110 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3111 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
3112 #define sr BPSTAT_WHAT_STEP_RESUME
3113 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3114 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3116 /* "Can't happen." Might want to print an error message.
3117 abort() is not out of the question, but chances are GDB is just
3118 a bit confused, not unusable. */
3119 #define err BPSTAT_WHAT_STOP_NOISY
3121 /* Given an old action and a class, come up with a new action. */
3122 /* One interesting property of this table is that wp_silent is the same
3123 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3124 after stopping, the check for whether to step over a breakpoint
3125 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3126 reference to how we stopped. We retain separate wp_silent and
3127 bp_silent codes in case we want to change that someday.
3129 Another possibly interesting property of this table is that
3130 there's a partial ordering, priority-like, of the actions. Once
3131 you've decided that some action is appropriate, you'll never go
3132 back and decide something of a lower priority is better. The
3133 ordering is:
3135 kc < clr sgl shl shlr slr sn sr ss
3136 sgl < clrs shl shlr slr sn sr ss
3137 slr < err shl shlr sn sr ss
3138 clr < clrs err shl shlr sn sr ss
3139 clrs < err shl shlr sn sr ss
3140 ss < shl shlr sn sr
3141 sn < shl shlr sr
3142 shl < shlr sr
3143 shlr < sr
3144 sr <
3146 What I think this means is that we don't need a damned table
3147 here. If you just put the rows and columns in the right order,
3148 it'd look awfully regular. We could simply walk the bpstat list
3149 and choose the highest priority action we find, with a little
3150 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3151 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3152 is messy anyway). */
3154 /* step_resume entries: a step resume breakpoint overrides another
3155 breakpoint of signal handling (see comment in wait_for_inferior
3156 at where we set the step_resume breakpoint). */
3158 static const enum bpstat_what_main_action
3159 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3161 /* old action */
3162 /* kc ss sn sgl slr clr clrs sr shl shlr
3164 /*no_effect */
3165 {kc, ss, sn, sgl, slr, clr, clrs, sr, shl, shlr},
3166 /*wp_silent */
3167 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3168 /*wp_noisy */
3169 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3170 /*bp_nostop */
3171 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, shl, shlr},
3172 /*bp_silent */
3173 {ss, ss, sn, ss, ss, ss, ss, sr, shl, shlr},
3174 /*bp_noisy */
3175 {sn, sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3176 /*long_jump */
3177 {slr, ss, sn, slr, slr, err, err, sr, shl, shlr},
3178 /*long_resume */
3179 {clr, ss, sn, clrs, err, err, err, sr, shl, shlr},
3180 /*step_resume */
3181 {sr, sr, sr, sr, sr, sr, sr, sr, sr, sr},
3182 /*shlib */
3183 {shl, shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3184 /*catch_shlib */
3185 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3188 #undef kc
3189 #undef ss
3190 #undef sn
3191 #undef sgl
3192 #undef slr
3193 #undef clr
3194 #undef clrs
3195 #undef err
3196 #undef sr
3197 #undef ts
3198 #undef shl
3199 #undef shlr
3200 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3201 struct bpstat_what retval;
3203 retval.call_dummy = 0;
3204 for (; bs != NULL; bs = bs->next)
3206 enum class bs_class = no_effect;
3207 if (bs->breakpoint_at == NULL)
3208 /* I suspect this can happen if it was a momentary breakpoint
3209 which has since been deleted. */
3210 continue;
3211 switch (bs->breakpoint_at->owner->type)
3213 case bp_none:
3214 continue;
3216 case bp_breakpoint:
3217 case bp_hardware_breakpoint:
3218 case bp_until:
3219 case bp_finish:
3220 if (bs->stop)
3222 if (bs->print)
3223 bs_class = bp_noisy;
3224 else
3225 bs_class = bp_silent;
3227 else
3228 bs_class = bp_nostop;
3229 break;
3230 case bp_watchpoint:
3231 case bp_hardware_watchpoint:
3232 case bp_read_watchpoint:
3233 case bp_access_watchpoint:
3234 if (bs->stop)
3236 if (bs->print)
3237 bs_class = wp_noisy;
3238 else
3239 bs_class = wp_silent;
3241 else
3242 /* There was a watchpoint, but we're not stopping.
3243 This requires no further action. */
3244 bs_class = no_effect;
3245 break;
3246 case bp_longjmp:
3247 bs_class = long_jump;
3248 break;
3249 case bp_longjmp_resume:
3250 bs_class = long_resume;
3251 break;
3252 case bp_step_resume:
3253 if (bs->stop)
3255 bs_class = step_resume;
3257 else
3258 /* It is for the wrong frame. */
3259 bs_class = bp_nostop;
3260 break;
3261 case bp_watchpoint_scope:
3262 bs_class = bp_nostop;
3263 break;
3264 case bp_shlib_event:
3265 bs_class = shlib_event;
3266 break;
3267 case bp_thread_event:
3268 case bp_overlay_event:
3269 bs_class = bp_nostop;
3270 break;
3271 case bp_catch_load:
3272 case bp_catch_unload:
3273 /* Only if this catchpoint triggered should we cause the
3274 step-out-of-dld behaviour. Otherwise, we ignore this
3275 catchpoint. */
3276 if (bs->stop)
3277 bs_class = catch_shlib_event;
3278 else
3279 bs_class = no_effect;
3280 break;
3281 case bp_catch_fork:
3282 case bp_catch_vfork:
3283 case bp_catch_exec:
3284 if (bs->stop)
3286 if (bs->print)
3287 bs_class = bp_noisy;
3288 else
3289 bs_class = bp_silent;
3291 else
3292 /* There was a catchpoint, but we're not stopping.
3293 This requires no further action. */
3294 bs_class = no_effect;
3295 break;
3296 case bp_catch_catch:
3297 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3298 bs_class = bp_nostop;
3299 else if (bs->stop)
3300 bs_class = bs->print ? bp_noisy : bp_silent;
3301 break;
3302 case bp_catch_throw:
3303 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3304 bs_class = bp_nostop;
3305 else if (bs->stop)
3306 bs_class = bs->print ? bp_noisy : bp_silent;
3307 break;
3308 case bp_call_dummy:
3309 /* Make sure the action is stop (silent or noisy),
3310 so infrun.c pops the dummy frame. */
3311 bs_class = bp_silent;
3312 retval.call_dummy = 1;
3313 break;
3315 current_action = table[(int) bs_class][(int) current_action];
3317 retval.main_action = current_action;
3318 return retval;
3321 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3322 without hardware support). This isn't related to a specific bpstat,
3323 just to things like whether watchpoints are set. */
3326 bpstat_should_step (void)
3328 struct breakpoint *b;
3329 ALL_BREAKPOINTS (b)
3330 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3331 return 1;
3332 return 0;
3335 /* Nonzero if there are enabled hardware watchpoints. */
3337 bpstat_have_active_hw_watchpoints (void)
3339 const struct bp_location *bpt;
3340 ALL_BP_LOCATIONS (bpt)
3341 if (breakpoint_enabled (bpt->owner)
3342 && bpt->inserted
3343 && bpt->loc_type == bp_loc_hardware_watchpoint)
3344 return 1;
3345 return 0;
3349 /* Given a bpstat that records zero or more triggered eventpoints, this
3350 function returns another bpstat which contains only the catchpoints
3351 on that first list, if any. */
3352 void
3353 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3355 struct bpstats root_bs[1];
3356 bpstat bs = root_bs;
3357 struct breakpoint *ep;
3358 char *dll_pathname;
3360 bpstat_clear (cp_list);
3361 root_bs->next = NULL;
3363 for (; ep_list != NULL; ep_list = ep_list->next)
3365 /* Is this eventpoint a catchpoint? If not, ignore it. */
3366 ep = ep_list->breakpoint_at->owner;
3367 if (ep == NULL)
3368 break;
3369 if ((ep->type != bp_catch_load) &&
3370 (ep->type != bp_catch_unload) &&
3371 (ep->type != bp_catch_catch) &&
3372 (ep->type != bp_catch_throw))
3373 /* pai: (temp) ADD fork/vfork here!! */
3374 continue;
3376 /* Yes; add it to the list. */
3377 bs = bpstat_alloc (ep_list->breakpoint_at, bs);
3378 *bs = *ep_list;
3379 bs->next = NULL;
3380 bs = root_bs->next;
3382 #if defined(SOLIB_ADD)
3383 /* Also, for each triggered catchpoint, tag it with the name of
3384 the library that caused this trigger. (We copy the name now,
3385 because it's only guaranteed to be available NOW, when the
3386 catchpoint triggers. Clients who may wish to know the name
3387 later must get it from the catchpoint itself.) */
3388 if (ep->triggered_dll_pathname != NULL)
3389 xfree (ep->triggered_dll_pathname);
3390 if (ep->type == bp_catch_load)
3391 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3392 PIDGET (inferior_ptid));
3393 else
3394 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3395 PIDGET (inferior_ptid));
3396 #else
3397 dll_pathname = NULL;
3398 #endif
3399 if (dll_pathname)
3401 ep->triggered_dll_pathname = (char *)
3402 xmalloc (strlen (dll_pathname) + 1);
3403 strcpy (ep->triggered_dll_pathname, dll_pathname);
3405 else
3406 ep->triggered_dll_pathname = NULL;
3409 *cp_list = bs;
3412 static void print_breakpoint_location (struct breakpoint *b,
3413 struct bp_location *loc,
3414 char *wrap_indent,
3415 struct ui_stream *stb)
3417 if (b->source_file)
3419 struct symbol *sym
3420 = find_pc_sect_function (loc->address, loc->section);
3421 if (sym)
3423 ui_out_text (uiout, "in ");
3424 ui_out_field_string (uiout, "func",
3425 SYMBOL_PRINT_NAME (sym));
3426 ui_out_wrap_hint (uiout, wrap_indent);
3427 ui_out_text (uiout, " at ");
3429 ui_out_field_string (uiout, "file", b->source_file);
3430 ui_out_text (uiout, ":");
3432 if (ui_out_is_mi_like_p (uiout))
3434 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3435 char *fullname = symtab_to_fullname (sal.symtab);
3437 if (fullname)
3438 ui_out_field_string (uiout, "fullname", fullname);
3441 ui_out_field_int (uiout, "line", b->line_number);
3443 else if (!b->loc)
3445 ui_out_field_string (uiout, "pending", b->addr_string);
3447 else
3449 print_address_symbolic (loc->address, stb->stream, demangle, "");
3450 ui_out_field_stream (uiout, "at", stb);
3454 /* Print B to gdb_stdout. */
3455 static void
3456 print_one_breakpoint_location (struct breakpoint *b,
3457 struct bp_location *loc,
3458 int loc_number,
3459 CORE_ADDR *last_addr)
3461 struct command_line *l;
3462 struct symbol *sym;
3463 struct ep_type_description
3465 enum bptype type;
3466 char *description;
3468 static struct ep_type_description bptypes[] =
3470 {bp_none, "?deleted?"},
3471 {bp_breakpoint, "breakpoint"},
3472 {bp_hardware_breakpoint, "hw breakpoint"},
3473 {bp_until, "until"},
3474 {bp_finish, "finish"},
3475 {bp_watchpoint, "watchpoint"},
3476 {bp_hardware_watchpoint, "hw watchpoint"},
3477 {bp_read_watchpoint, "read watchpoint"},
3478 {bp_access_watchpoint, "acc watchpoint"},
3479 {bp_longjmp, "longjmp"},
3480 {bp_longjmp_resume, "longjmp resume"},
3481 {bp_step_resume, "step resume"},
3482 {bp_watchpoint_scope, "watchpoint scope"},
3483 {bp_call_dummy, "call dummy"},
3484 {bp_shlib_event, "shlib events"},
3485 {bp_thread_event, "thread events"},
3486 {bp_overlay_event, "overlay events"},
3487 {bp_catch_load, "catch load"},
3488 {bp_catch_unload, "catch unload"},
3489 {bp_catch_fork, "catch fork"},
3490 {bp_catch_vfork, "catch vfork"},
3491 {bp_catch_exec, "catch exec"},
3492 {bp_catch_catch, "catch catch"},
3493 {bp_catch_throw, "catch throw"}
3496 static char *bpdisps[] =
3497 {"del", "dstp", "dis", "keep"};
3498 static char bpenables[] = "nynny";
3499 char wrap_indent[80];
3500 struct ui_stream *stb = ui_out_stream_new (uiout);
3501 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3502 struct cleanup *bkpt_chain;
3504 int header_of_multiple = 0;
3505 int part_of_multiple = (loc != NULL);
3507 gdb_assert (!loc || loc_number != 0);
3508 /* See comment in print_one_breakpoint concerning
3509 treatment of breakpoints with single disabled
3510 location. */
3511 if (loc == NULL
3512 && (b->loc != NULL
3513 && (b->loc->next != NULL || !b->loc->enabled)))
3514 header_of_multiple = 1;
3515 if (loc == NULL)
3516 loc = b->loc;
3518 annotate_record ();
3519 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3521 /* 1 */
3522 annotate_field (0);
3523 if (part_of_multiple)
3525 char *formatted;
3526 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3527 ui_out_field_string (uiout, "number", formatted);
3528 xfree (formatted);
3530 else
3532 ui_out_field_int (uiout, "number", b->number);
3535 /* 2 */
3536 annotate_field (1);
3537 if (part_of_multiple)
3538 ui_out_field_skip (uiout, "type");
3539 else
3541 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3542 || ((int) b->type != bptypes[(int) b->type].type))
3543 internal_error (__FILE__, __LINE__,
3544 _("bptypes table does not describe type #%d."),
3545 (int) b->type);
3546 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3549 /* 3 */
3550 annotate_field (2);
3551 if (part_of_multiple)
3552 ui_out_field_skip (uiout, "disp");
3553 else
3554 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3557 /* 4 */
3558 annotate_field (3);
3559 if (part_of_multiple)
3560 ui_out_field_string (uiout, "enabled",
3561 loc->shlib_disabled
3562 ? (loc->enabled ? "y(p)" : "n(p)")
3563 : (loc->enabled ? "y" : "n"));
3564 else
3566 int pending = (b->loc == NULL || b->loc->shlib_disabled);
3567 /* For header of multiple, there's no point showing pending
3568 state -- it will be apparent from the locations. */
3569 if (header_of_multiple)
3570 pending = 0;
3571 ui_out_field_fmt (uiout, "enabled", "%c%s",
3572 bpenables[(int) b->enable_state],
3573 pending ? "(p)" : "");
3574 if (!pending)
3575 ui_out_spaces (uiout, 3);
3579 /* 5 and 6 */
3580 strcpy (wrap_indent, " ");
3581 if (addressprint)
3583 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3584 strcat (wrap_indent, " ");
3585 else
3586 strcat (wrap_indent, " ");
3589 if (b->ops != NULL && b->ops->print_one != NULL)
3591 /* Although the print_one can possibly print
3592 all locations, calling it here is not likely
3593 to get any nice result. So, make sure there's
3594 just one location. */
3595 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3596 b->ops->print_one (b, last_addr);
3598 else
3599 switch (b->type)
3601 case bp_none:
3602 internal_error (__FILE__, __LINE__,
3603 _("print_one_breakpoint: bp_none encountered\n"));
3604 break;
3606 case bp_watchpoint:
3607 case bp_hardware_watchpoint:
3608 case bp_read_watchpoint:
3609 case bp_access_watchpoint:
3610 /* Field 4, the address, is omitted (which makes the columns
3611 not line up too nicely with the headers, but the effect
3612 is relatively readable). */
3613 if (addressprint)
3614 ui_out_field_skip (uiout, "addr");
3615 annotate_field (5);
3616 print_expression (b->exp, stb->stream);
3617 ui_out_field_stream (uiout, "what", stb);
3618 break;
3620 case bp_catch_load:
3621 case bp_catch_unload:
3622 /* Field 4, the address, is omitted (which makes the columns
3623 not line up too nicely with the headers, but the effect
3624 is relatively readable). */
3625 if (addressprint)
3626 ui_out_field_skip (uiout, "addr");
3627 annotate_field (5);
3628 if (b->dll_pathname == NULL)
3630 ui_out_field_string (uiout, "what", "<any library>");
3631 ui_out_spaces (uiout, 1);
3633 else
3635 ui_out_text (uiout, "library \"");
3636 ui_out_field_string (uiout, "what", b->dll_pathname);
3637 ui_out_text (uiout, "\" ");
3639 break;
3641 case bp_catch_fork:
3642 case bp_catch_vfork:
3643 /* Field 4, the address, is omitted (which makes the columns
3644 not line up too nicely with the headers, but the effect
3645 is relatively readable). */
3646 if (addressprint)
3647 ui_out_field_skip (uiout, "addr");
3648 annotate_field (5);
3649 if (b->forked_inferior_pid != 0)
3651 ui_out_text (uiout, "process ");
3652 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3653 ui_out_spaces (uiout, 1);
3655 break;
3657 case bp_catch_exec:
3658 /* Field 4, the address, is omitted (which makes the columns
3659 not line up too nicely with the headers, but the effect
3660 is relatively readable). */
3661 if (addressprint)
3662 ui_out_field_skip (uiout, "addr");
3663 annotate_field (5);
3664 if (b->exec_pathname != NULL)
3666 ui_out_text (uiout, "program \"");
3667 ui_out_field_string (uiout, "what", b->exec_pathname);
3668 ui_out_text (uiout, "\" ");
3670 break;
3672 case bp_catch_catch:
3673 /* Field 4, the address, is omitted (which makes the columns
3674 not line up too nicely with the headers, but the effect
3675 is relatively readable). */
3676 if (addressprint)
3677 ui_out_field_skip (uiout, "addr");
3678 annotate_field (5);
3679 ui_out_field_string (uiout, "what", "exception catch");
3680 ui_out_spaces (uiout, 1);
3681 break;
3683 case bp_catch_throw:
3684 /* Field 4, the address, is omitted (which makes the columns
3685 not line up too nicely with the headers, but the effect
3686 is relatively readable). */
3687 if (addressprint)
3688 ui_out_field_skip (uiout, "addr");
3689 annotate_field (5);
3690 ui_out_field_string (uiout, "what", "exception throw");
3691 ui_out_spaces (uiout, 1);
3692 break;
3694 case bp_breakpoint:
3695 case bp_hardware_breakpoint:
3696 case bp_until:
3697 case bp_finish:
3698 case bp_longjmp:
3699 case bp_longjmp_resume:
3700 case bp_step_resume:
3701 case bp_watchpoint_scope:
3702 case bp_call_dummy:
3703 case bp_shlib_event:
3704 case bp_thread_event:
3705 case bp_overlay_event:
3706 if (addressprint)
3708 annotate_field (4);
3709 if (b->loc == NULL)
3710 ui_out_field_string (uiout, "addr", "<PENDING>");
3711 else if (header_of_multiple)
3712 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3713 else
3714 ui_out_field_core_addr (uiout, "addr", loc->address);
3716 annotate_field (5);
3717 if (!header_of_multiple)
3718 print_breakpoint_location (b, loc, wrap_indent, stb);
3719 if (b->loc)
3720 *last_addr = b->loc->address;
3721 break;
3724 if (!part_of_multiple && b->thread != -1)
3726 /* FIXME: This seems to be redundant and lost here; see the
3727 "stop only in" line a little further down. */
3728 ui_out_text (uiout, " thread ");
3729 ui_out_field_int (uiout, "thread", b->thread);
3732 ui_out_text (uiout, "\n");
3734 if (part_of_multiple && frame_id_p (b->frame_id))
3736 annotate_field (6);
3737 ui_out_text (uiout, "\tstop only in stack frame at ");
3738 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3739 the frame ID. */
3740 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3741 ui_out_text (uiout, "\n");
3744 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3746 /* We do not print the condition for Ada exception catchpoints
3747 because the condition is an internal implementation detail
3748 that we do not want to expose to the user. */
3749 annotate_field (7);
3750 ui_out_text (uiout, "\tstop only if ");
3751 ui_out_field_string (uiout, "cond", b->cond_string);
3752 ui_out_text (uiout, "\n");
3755 if (!part_of_multiple && b->thread != -1)
3757 /* FIXME should make an annotation for this */
3758 ui_out_text (uiout, "\tstop only in thread ");
3759 ui_out_field_int (uiout, "thread", b->thread);
3760 ui_out_text (uiout, "\n");
3763 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count)
3765 /* FIXME should make an annotation for this */
3766 if (ep_is_catchpoint (b))
3767 ui_out_text (uiout, "\tcatchpoint");
3768 else
3769 ui_out_text (uiout, "\tbreakpoint");
3770 ui_out_text (uiout, " already hit ");
3771 ui_out_field_int (uiout, "times", b->hit_count);
3772 if (b->hit_count == 1)
3773 ui_out_text (uiout, " time\n");
3774 else
3775 ui_out_text (uiout, " times\n");
3778 /* Output the count also if it is zero, but only if this is
3779 mi. FIXME: Should have a better test for this. */
3780 if (ui_out_is_mi_like_p (uiout))
3781 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count == 0)
3782 ui_out_field_int (uiout, "times", b->hit_count);
3784 if (!part_of_multiple && b->ignore_count)
3786 annotate_field (8);
3787 ui_out_text (uiout, "\tignore next ");
3788 ui_out_field_int (uiout, "ignore", b->ignore_count);
3789 ui_out_text (uiout, " hits\n");
3792 if (!part_of_multiple && (l = b->commands))
3794 struct cleanup *script_chain;
3796 annotate_field (9);
3797 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3798 print_command_lines (uiout, l, 4);
3799 do_cleanups (script_chain);
3801 do_cleanups (bkpt_chain);
3802 do_cleanups (old_chain);
3805 static void
3806 print_one_breakpoint (struct breakpoint *b,
3807 CORE_ADDR *last_addr)
3809 print_one_breakpoint_location (b, NULL, 0, last_addr);
3811 /* If this breakpoint has custom print function,
3812 it's already printed. Otherwise, print individual
3813 locations, if any. */
3814 if (b->ops == NULL || b->ops->print_one == NULL)
3816 /* If breakpoint has a single location that is
3817 disabled, we print it as if it had
3818 several locations, since otherwise it's hard to
3819 represent "breakpoint enabled, location disabled"
3820 situation. */
3821 if (b->loc
3822 && (b->loc->next || !b->loc->enabled)
3823 && !ui_out_is_mi_like_p (uiout))
3825 struct bp_location *loc;
3826 int n = 1;
3827 for (loc = b->loc; loc; loc = loc->next, ++n)
3828 print_one_breakpoint_location (b, loc, n, last_addr);
3834 struct captured_breakpoint_query_args
3836 int bnum;
3839 static int
3840 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3842 struct captured_breakpoint_query_args *args = data;
3843 struct breakpoint *b;
3844 CORE_ADDR dummy_addr = 0;
3845 ALL_BREAKPOINTS (b)
3847 if (args->bnum == b->number)
3849 print_one_breakpoint (b, &dummy_addr);
3850 return GDB_RC_OK;
3853 return GDB_RC_NONE;
3856 enum gdb_rc
3857 gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3859 struct captured_breakpoint_query_args args;
3860 args.bnum = bnum;
3861 /* For the moment we don't trust print_one_breakpoint() to not throw
3862 an error. */
3863 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3864 error_message, RETURN_MASK_ALL) < 0)
3865 return GDB_RC_FAIL;
3866 else
3867 return GDB_RC_OK;
3870 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3871 catchpoints, et.al.). */
3873 static int
3874 user_settable_breakpoint (const struct breakpoint *b)
3876 return (b->type == bp_breakpoint
3877 || b->type == bp_catch_load
3878 || b->type == bp_catch_unload
3879 || b->type == bp_catch_fork
3880 || b->type == bp_catch_vfork
3881 || b->type == bp_catch_exec
3882 || b->type == bp_catch_catch
3883 || b->type == bp_catch_throw
3884 || b->type == bp_hardware_breakpoint
3885 || b->type == bp_watchpoint
3886 || b->type == bp_read_watchpoint
3887 || b->type == bp_access_watchpoint
3888 || b->type == bp_hardware_watchpoint);
3891 /* Print information on user settable breakpoint (watchpoint, etc)
3892 number BNUM. If BNUM is -1 print all user settable breakpoints.
3893 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3895 static void
3896 breakpoint_1 (int bnum, int allflag)
3898 struct breakpoint *b;
3899 CORE_ADDR last_addr = (CORE_ADDR) -1;
3900 int nr_printable_breakpoints;
3901 struct cleanup *bkpttbl_chain;
3903 /* Compute the number of rows in the table. */
3904 nr_printable_breakpoints = 0;
3905 ALL_BREAKPOINTS (b)
3906 if (bnum == -1
3907 || bnum == b->number)
3909 if (allflag || user_settable_breakpoint (b))
3910 nr_printable_breakpoints++;
3913 if (addressprint)
3914 bkpttbl_chain
3915 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3916 "BreakpointTable");
3917 else
3918 bkpttbl_chain
3919 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3920 "BreakpointTable");
3922 if (nr_printable_breakpoints > 0)
3923 annotate_breakpoints_headers ();
3924 if (nr_printable_breakpoints > 0)
3925 annotate_field (0);
3926 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3927 if (nr_printable_breakpoints > 0)
3928 annotate_field (1);
3929 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3930 if (nr_printable_breakpoints > 0)
3931 annotate_field (2);
3932 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3933 if (nr_printable_breakpoints > 0)
3934 annotate_field (3);
3935 ui_out_table_header (uiout, 4, ui_left, "enabled", "Enb"); /* 4 */
3936 if (addressprint)
3938 if (nr_printable_breakpoints > 0)
3939 annotate_field (4);
3940 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3941 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3942 else
3943 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3945 if (nr_printable_breakpoints > 0)
3946 annotate_field (5);
3947 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3948 ui_out_table_body (uiout);
3949 if (nr_printable_breakpoints > 0)
3950 annotate_breakpoints_table ();
3952 ALL_BREAKPOINTS (b)
3953 if (bnum == -1
3954 || bnum == b->number)
3956 /* We only print out user settable breakpoints unless the
3957 allflag is set. */
3958 if (allflag || user_settable_breakpoint (b))
3959 print_one_breakpoint (b, &last_addr);
3962 do_cleanups (bkpttbl_chain);
3964 if (nr_printable_breakpoints == 0)
3966 if (bnum == -1)
3967 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3968 else
3969 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3970 bnum);
3972 else
3974 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3975 that a comparison of an unsigned with -1 is always false. */
3976 if (last_addr != (CORE_ADDR) -1 && !server_command)
3977 set_next_address (last_addr);
3980 /* FIXME? Should this be moved up so that it is only called when
3981 there have been breakpoints? */
3982 annotate_breakpoints_table_end ();
3985 static void
3986 breakpoints_info (char *bnum_exp, int from_tty)
3988 int bnum = -1;
3990 if (bnum_exp)
3991 bnum = parse_and_eval_long (bnum_exp);
3993 breakpoint_1 (bnum, 0);
3996 static void
3997 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3999 int bnum = -1;
4001 if (bnum_exp)
4002 bnum = parse_and_eval_long (bnum_exp);
4004 breakpoint_1 (bnum, 1);
4007 static int
4008 breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
4010 struct bp_location *bl = b->loc;
4011 for (; bl; bl = bl->next)
4013 if (bl->address == pc
4014 && (!overlay_debugging || bl->section == section))
4015 return 1;
4017 return 0;
4020 /* Print a message describing any breakpoints set at PC. */
4022 static void
4023 describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
4025 int others = 0;
4026 struct breakpoint *b;
4028 ALL_BREAKPOINTS (b)
4029 others += breakpoint_has_pc (b, pc, section);
4030 if (others > 0)
4032 if (others == 1)
4033 printf_filtered (_("Note: breakpoint "));
4034 else /* if (others == ???) */
4035 printf_filtered (_("Note: breakpoints "));
4036 ALL_BREAKPOINTS (b)
4037 if (breakpoint_has_pc (b, pc, section))
4039 others--;
4040 printf_filtered ("%d", b->number);
4041 if (b->thread == -1 && thread != -1)
4042 printf_filtered (" (all threads)");
4043 else if (b->thread != -1)
4044 printf_filtered (" (thread %d)", b->thread);
4045 printf_filtered ("%s%s ",
4046 ((b->enable_state == bp_disabled ||
4047 b->enable_state == bp_call_disabled)
4048 ? " (disabled)"
4049 : b->enable_state == bp_permanent
4050 ? " (permanent)"
4051 : ""),
4052 (others > 1) ? ","
4053 : ((others == 1) ? " and" : ""));
4055 printf_filtered (_("also set at pc "));
4056 deprecated_print_address_numeric (pc, 1, gdb_stdout);
4057 printf_filtered (".\n");
4061 /* Set the default place to put a breakpoint
4062 for the `break' command with no arguments. */
4064 void
4065 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4066 int line)
4068 default_breakpoint_valid = valid;
4069 default_breakpoint_address = addr;
4070 default_breakpoint_symtab = symtab;
4071 default_breakpoint_line = line;
4074 /* Return true iff it is meaningful to use the address member of
4075 BPT. For some breakpoint types, the address member is irrelevant
4076 and it makes no sense to attempt to compare it to other addresses
4077 (or use it for any other purpose either).
4079 More specifically, each of the following breakpoint types will always
4080 have a zero valued address and we don't want check_duplicates() to mark
4081 breakpoints of any of these types to be a duplicate of an actual
4082 breakpoint at address zero:
4084 bp_watchpoint
4085 bp_hardware_watchpoint
4086 bp_read_watchpoint
4087 bp_access_watchpoint
4088 bp_catch_exec
4089 bp_longjmp_resume
4090 bp_catch_fork
4091 bp_catch_vork */
4093 static int
4094 breakpoint_address_is_meaningful (struct breakpoint *bpt)
4096 enum bptype type = bpt->type;
4098 return (type != bp_watchpoint
4099 && type != bp_hardware_watchpoint
4100 && type != bp_read_watchpoint
4101 && type != bp_access_watchpoint
4102 && type != bp_catch_exec
4103 && type != bp_longjmp_resume
4104 && type != bp_catch_fork
4105 && type != bp_catch_vfork);
4108 /* Rescan breakpoints at the same address and section as BPT,
4109 marking the first one as "first" and any others as "duplicates".
4110 This is so that the bpt instruction is only inserted once.
4111 If we have a permanent breakpoint at the same place as BPT, make
4112 that one the official one, and the rest as duplicates. */
4114 static void
4115 check_duplicates_for (CORE_ADDR address, asection *section)
4117 struct bp_location *b;
4118 int count = 0;
4119 struct bp_location *perm_bp = 0;
4121 ALL_BP_LOCATIONS (b)
4122 if (b->owner->enable_state != bp_disabled
4123 && b->owner->enable_state != bp_call_disabled
4124 && b->enabled
4125 && !b->shlib_disabled
4126 && b->address == address /* address / overlay match */
4127 && (!overlay_debugging || b->section == section)
4128 && breakpoint_address_is_meaningful (b->owner))
4130 /* Have we found a permanent breakpoint? */
4131 if (b->owner->enable_state == bp_permanent)
4133 perm_bp = b;
4134 break;
4137 count++;
4138 b->duplicate = count > 1;
4141 /* If we found a permanent breakpoint at this address, go over the
4142 list again and declare all the other breakpoints there to be the
4143 duplicates. */
4144 if (perm_bp)
4146 perm_bp->duplicate = 0;
4148 /* Permanent breakpoint should always be inserted. */
4149 if (! perm_bp->inserted)
4150 internal_error (__FILE__, __LINE__,
4151 _("allegedly permanent breakpoint is not "
4152 "actually inserted"));
4154 ALL_BP_LOCATIONS (b)
4155 if (b != perm_bp)
4157 if (b->owner->enable_state != bp_disabled
4158 && b->owner->enable_state != bp_call_disabled
4159 && b->enabled && !b->shlib_disabled
4160 && b->address == address /* address / overlay match */
4161 && (!overlay_debugging || b->section == section)
4162 && breakpoint_address_is_meaningful (b->owner))
4164 if (b->inserted)
4165 internal_error (__FILE__, __LINE__,
4166 _("another breakpoint was inserted on top of "
4167 "a permanent breakpoint"));
4169 b->duplicate = 1;
4175 static void
4176 check_duplicates (struct breakpoint *bpt)
4178 struct bp_location *bl = bpt->loc;
4180 if (! breakpoint_address_is_meaningful (bpt))
4181 return;
4183 for (; bl; bl = bl->next)
4184 check_duplicates_for (bl->address, bl->section);
4187 static void
4188 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4189 int bnum, int have_bnum)
4191 char astr1[40];
4192 char astr2[40];
4194 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4195 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4196 if (have_bnum)
4197 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4198 bnum, astr1, astr2);
4199 else
4200 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4203 /* Adjust a breakpoint's address to account for architectural constraints
4204 on breakpoint placement. Return the adjusted address. Note: Very
4205 few targets require this kind of adjustment. For most targets,
4206 this function is simply the identity function. */
4208 static CORE_ADDR
4209 adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4211 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4213 /* Very few targets need any kind of breakpoint adjustment. */
4214 return bpaddr;
4216 else if (bptype == bp_watchpoint
4217 || bptype == bp_hardware_watchpoint
4218 || bptype == bp_read_watchpoint
4219 || bptype == bp_access_watchpoint
4220 || bptype == bp_catch_fork
4221 || bptype == bp_catch_vfork
4222 || bptype == bp_catch_exec)
4224 /* Watchpoints and the various bp_catch_* eventpoints should not
4225 have their addresses modified. */
4226 return bpaddr;
4228 else
4230 CORE_ADDR adjusted_bpaddr;
4232 /* Some targets have architectural constraints on the placement
4233 of breakpoint instructions. Obtain the adjusted address. */
4234 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4235 bpaddr);
4237 /* An adjusted breakpoint address can significantly alter
4238 a user's expectations. Print a warning if an adjustment
4239 is required. */
4240 if (adjusted_bpaddr != bpaddr)
4241 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4243 return adjusted_bpaddr;
4247 /* Allocate a struct bp_location. */
4249 static struct bp_location *
4250 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4252 struct bp_location *loc, *loc_p;
4254 loc = xmalloc (sizeof (struct bp_location));
4255 memset (loc, 0, sizeof (*loc));
4257 loc->owner = bpt;
4258 loc->cond = NULL;
4259 loc->shlib_disabled = 0;
4260 loc->enabled = 1;
4262 switch (bp_type)
4264 case bp_breakpoint:
4265 case bp_until:
4266 case bp_finish:
4267 case bp_longjmp:
4268 case bp_longjmp_resume:
4269 case bp_step_resume:
4270 case bp_watchpoint_scope:
4271 case bp_call_dummy:
4272 case bp_shlib_event:
4273 case bp_thread_event:
4274 case bp_overlay_event:
4275 case bp_catch_load:
4276 case bp_catch_unload:
4277 loc->loc_type = bp_loc_software_breakpoint;
4278 break;
4279 case bp_hardware_breakpoint:
4280 loc->loc_type = bp_loc_hardware_breakpoint;
4281 break;
4282 case bp_hardware_watchpoint:
4283 case bp_read_watchpoint:
4284 case bp_access_watchpoint:
4285 loc->loc_type = bp_loc_hardware_watchpoint;
4286 break;
4287 case bp_watchpoint:
4288 case bp_catch_fork:
4289 case bp_catch_vfork:
4290 case bp_catch_exec:
4291 case bp_catch_catch:
4292 case bp_catch_throw:
4293 loc->loc_type = bp_loc_other;
4294 break;
4295 default:
4296 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4299 /* Add this breakpoint to the end of the chain. */
4301 loc_p = bp_location_chain;
4302 if (loc_p == 0)
4303 bp_location_chain = loc;
4304 else
4306 while (loc_p->global_next)
4307 loc_p = loc_p->global_next;
4308 loc_p->global_next = loc;
4311 return loc;
4314 static void free_bp_location (struct bp_location *loc)
4316 if (loc->cond)
4317 xfree (loc->cond);
4318 xfree (loc);
4321 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4322 that has type BPTYPE and has no locations as yet. */
4324 static struct breakpoint *
4325 set_raw_breakpoint_without_location (enum bptype bptype)
4327 struct breakpoint *b, *b1;
4329 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4330 memset (b, 0, sizeof (*b));
4332 b->type = bptype;
4333 b->language = current_language->la_language;
4334 b->input_radix = input_radix;
4335 b->thread = -1;
4336 b->enable_state = bp_enabled;
4337 b->next = 0;
4338 b->silent = 0;
4339 b->ignore_count = 0;
4340 b->commands = NULL;
4341 b->frame_id = null_frame_id;
4342 b->dll_pathname = NULL;
4343 b->triggered_dll_pathname = NULL;
4344 b->forked_inferior_pid = 0;
4345 b->exec_pathname = NULL;
4346 b->ops = NULL;
4347 b->condition_not_parsed = 0;
4349 /* Add this breakpoint to the end of the chain
4350 so that a list of breakpoints will come out in order
4351 of increasing numbers. */
4353 b1 = breakpoint_chain;
4354 if (b1 == 0)
4355 breakpoint_chain = b;
4356 else
4358 while (b1->next)
4359 b1 = b1->next;
4360 b1->next = b;
4362 return b;
4365 /* Initialize loc->function_name. */
4366 static void
4367 set_breakpoint_location_function (struct bp_location *loc)
4369 if (loc->owner->type == bp_breakpoint
4370 || loc->owner->type == bp_hardware_breakpoint)
4372 find_pc_partial_function (loc->address, &(loc->function_name),
4373 NULL, NULL);
4374 if (loc->function_name)
4375 loc->function_name = xstrdup (loc->function_name);
4379 /* set_raw_breakpoint is a low level routine for allocating and
4380 partially initializing a breakpoint of type BPTYPE. The newly
4381 created breakpoint's address, section, source file name, and line
4382 number are provided by SAL. The newly created and partially
4383 initialized breakpoint is added to the breakpoint chain and
4384 is also returned as the value of this function.
4386 It is expected that the caller will complete the initialization of
4387 the newly created breakpoint struct as well as output any status
4388 information regarding the creation of a new breakpoint. In
4389 particular, set_raw_breakpoint does NOT set the breakpoint
4390 number! Care should be taken to not allow an error to occur
4391 prior to completing the initialization of the breakpoint. If this
4392 should happen, a bogus breakpoint will be left on the chain. */
4394 struct breakpoint *
4395 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4397 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4398 CORE_ADDR adjusted_address;
4400 /* Adjust the breakpoint's address prior to allocating a location.
4401 Once we call allocate_bp_location(), that mostly uninitialized
4402 location will be placed on the location chain. Adjustment of the
4403 breakpoint may cause read_memory_nobpt() to be called and we do
4404 not want its scan of the location chain to find a breakpoint and
4405 location that's only been partially initialized. */
4406 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4408 b->loc = allocate_bp_location (b, bptype);
4409 b->loc->requested_address = sal.pc;
4410 b->loc->address = adjusted_address;
4412 if (sal.symtab == NULL)
4413 b->source_file = NULL;
4414 else
4415 b->source_file = savestring (sal.symtab->filename,
4416 strlen (sal.symtab->filename));
4417 b->loc->section = sal.section;
4418 b->line_number = sal.line;
4420 set_breakpoint_location_function (b->loc);
4422 check_duplicates (b);
4423 breakpoints_changed ();
4425 return b;
4429 /* Note that the breakpoint object B describes a permanent breakpoint
4430 instruction, hard-wired into the inferior's code. */
4431 void
4432 make_breakpoint_permanent (struct breakpoint *b)
4434 struct bp_location *bl;
4435 b->enable_state = bp_permanent;
4437 /* By definition, permanent breakpoints are already present in the code.
4438 Mark all locations as inserted. For now, make_breakpoint_permanent
4439 is called in just one place, so it's hard to say if it's reasonable
4440 to have permanent breakpoint with multiple locations or not,
4441 but it's easy to implmement. */
4442 for (bl = b->loc; bl; bl = bl->next)
4443 bl->inserted = 1;
4446 static struct breakpoint *
4447 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4449 static int internal_breakpoint_number = -1;
4450 struct symtab_and_line sal;
4451 struct breakpoint *b;
4453 init_sal (&sal); /* initialize to zeroes */
4455 sal.pc = address;
4456 sal.section = find_pc_overlay (sal.pc);
4458 b = set_raw_breakpoint (sal, type);
4459 b->number = internal_breakpoint_number--;
4460 b->disposition = disp_donttouch;
4462 return b;
4466 static void
4467 create_longjmp_breakpoint (char *func_name)
4469 struct breakpoint *b;
4470 struct minimal_symbol *m;
4472 if (func_name == NULL)
4473 b = create_internal_breakpoint (0, bp_longjmp_resume);
4474 else
4476 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4477 return;
4479 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4482 b->enable_state = bp_disabled;
4483 b->silent = 1;
4484 if (func_name)
4485 b->addr_string = xstrdup (func_name);
4488 /* Call this routine when stepping and nexting to enable a breakpoint
4489 if we do a longjmp(). When we hit that breakpoint, call
4490 set_longjmp_resume_breakpoint() to figure out where we are going. */
4492 void
4493 enable_longjmp_breakpoint (void)
4495 struct breakpoint *b;
4497 ALL_BREAKPOINTS (b)
4498 if (b->type == bp_longjmp)
4500 b->enable_state = bp_enabled;
4501 check_duplicates (b);
4505 void
4506 disable_longjmp_breakpoint (void)
4508 struct breakpoint *b;
4510 ALL_BREAKPOINTS (b)
4511 if (b->type == bp_longjmp
4512 || b->type == bp_longjmp_resume)
4514 b->enable_state = bp_disabled;
4515 check_duplicates (b);
4519 static void
4520 create_overlay_event_breakpoint (char *func_name)
4522 struct breakpoint *b;
4523 struct minimal_symbol *m;
4525 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4526 return;
4528 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4529 bp_overlay_event);
4530 b->addr_string = xstrdup (func_name);
4532 if (overlay_debugging == ovly_auto)
4534 b->enable_state = bp_enabled;
4535 overlay_events_enabled = 1;
4537 else
4539 b->enable_state = bp_disabled;
4540 overlay_events_enabled = 0;
4544 void
4545 enable_overlay_breakpoints (void)
4547 struct breakpoint *b;
4549 ALL_BREAKPOINTS (b)
4550 if (b->type == bp_overlay_event)
4552 b->enable_state = bp_enabled;
4553 check_duplicates (b);
4554 overlay_events_enabled = 1;
4558 void
4559 disable_overlay_breakpoints (void)
4561 struct breakpoint *b;
4563 ALL_BREAKPOINTS (b)
4564 if (b->type == bp_overlay_event)
4566 b->enable_state = bp_disabled;
4567 check_duplicates (b);
4568 overlay_events_enabled = 0;
4572 struct breakpoint *
4573 create_thread_event_breakpoint (CORE_ADDR address)
4575 struct breakpoint *b;
4577 b = create_internal_breakpoint (address, bp_thread_event);
4579 b->enable_state = bp_enabled;
4580 /* addr_string has to be used or breakpoint_re_set will delete me. */
4581 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4583 return b;
4586 void
4587 remove_thread_event_breakpoints (void)
4589 struct breakpoint *b, *temp;
4591 ALL_BREAKPOINTS_SAFE (b, temp)
4592 if (b->type == bp_thread_event)
4593 delete_breakpoint (b);
4596 struct captured_parse_breakpoint_args
4598 char **arg_p;
4599 struct symtabs_and_lines *sals_p;
4600 char ***addr_string_p;
4601 int *not_found_ptr;
4604 struct lang_and_radix
4606 enum language lang;
4607 int radix;
4611 void
4612 remove_solib_event_breakpoints (void)
4614 struct breakpoint *b, *temp;
4616 ALL_BREAKPOINTS_SAFE (b, temp)
4617 if (b->type == bp_shlib_event)
4618 delete_breakpoint (b);
4621 struct breakpoint *
4622 create_solib_event_breakpoint (CORE_ADDR address)
4624 struct breakpoint *b;
4626 b = create_internal_breakpoint (address, bp_shlib_event);
4627 return b;
4630 /* Disable any breakpoints that are on code in shared libraries. Only
4631 apply to enabled breakpoints, disabled ones can just stay disabled. */
4633 void
4634 disable_breakpoints_in_shlibs (void)
4636 struct bp_location *loc;
4637 int disabled_shlib_breaks = 0;
4639 ALL_BP_LOCATIONS (loc)
4641 struct breakpoint *b = loc->owner;
4642 /* We apply the check to all breakpoints, including disabled
4643 for those with loc->duplicate set. This is so that when breakpoint
4644 becomes enabled, or the duplicate is removed, gdb will try to insert
4645 all breakpoints. If we don't set shlib_disabled here, we'll try
4646 to insert those breakpoints and fail. */
4647 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4648 && !loc->shlib_disabled
4649 #ifdef PC_SOLIB
4650 && PC_SOLIB (loc->address)
4651 #else
4652 && solib_address (loc->address)
4653 #endif
4656 loc->shlib_disabled = 1;
4661 /* Disable any breakpoints that are in in an unloaded shared library. Only
4662 apply to enabled breakpoints, disabled ones can just stay disabled. */
4664 static void
4665 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4667 struct bp_location *loc;
4668 int disabled_shlib_breaks = 0;
4670 ALL_BP_LOCATIONS (loc)
4672 struct breakpoint *b = loc->owner;
4673 if ((loc->loc_type == bp_loc_hardware_breakpoint
4674 || loc->loc_type == bp_loc_software_breakpoint)
4675 && !loc->shlib_disabled)
4677 #ifdef PC_SOLIB
4678 char *so_name = PC_SOLIB (loc->address);
4679 #else
4680 char *so_name = solib_address (loc->address);
4681 #endif
4682 if (so_name && !strcmp (so_name, solib->so_name))
4684 loc->shlib_disabled = 1;
4685 /* At this point, we cannot rely on remove_breakpoint
4686 succeeding so we must mark the breakpoint as not inserted
4687 to prevent future errors occurring in remove_breakpoints. */
4688 loc->inserted = 0;
4689 if (!disabled_shlib_breaks)
4691 target_terminal_ours_for_output ();
4692 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4693 so_name);
4695 disabled_shlib_breaks = 1;
4701 static void
4702 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4703 enum bptype bp_kind)
4705 struct symtab_and_line sal;
4706 struct breakpoint *b;
4707 int thread = -1; /* All threads. */
4709 init_sal (&sal);
4710 sal.pc = 0;
4711 sal.symtab = NULL;
4712 sal.line = 0;
4714 b = set_raw_breakpoint (sal, bp_kind);
4715 set_breakpoint_count (breakpoint_count + 1);
4716 b->number = breakpoint_count;
4717 b->cond_string = (cond_string == NULL) ?
4718 NULL : savestring (cond_string, strlen (cond_string));
4719 b->thread = thread;
4720 b->addr_string = NULL;
4721 b->enable_state = bp_enabled;
4722 b->disposition = tempflag ? disp_del : disp_donttouch;
4723 b->forked_inferior_pid = 0;
4725 mention (b);
4728 static void
4729 create_fork_event_catchpoint (int tempflag, char *cond_string)
4731 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4734 static void
4735 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4737 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4740 static void
4741 create_exec_event_catchpoint (int tempflag, char *cond_string)
4743 struct symtab_and_line sal;
4744 struct breakpoint *b;
4745 int thread = -1; /* All threads. */
4747 init_sal (&sal);
4748 sal.pc = 0;
4749 sal.symtab = NULL;
4750 sal.line = 0;
4752 b = set_raw_breakpoint (sal, bp_catch_exec);
4753 set_breakpoint_count (breakpoint_count + 1);
4754 b->number = breakpoint_count;
4755 b->cond_string = (cond_string == NULL) ?
4756 NULL : savestring (cond_string, strlen (cond_string));
4757 b->thread = thread;
4758 b->addr_string = NULL;
4759 b->enable_state = bp_enabled;
4760 b->disposition = tempflag ? disp_del : disp_donttouch;
4762 mention (b);
4765 static int
4766 hw_breakpoint_used_count (void)
4768 struct breakpoint *b;
4769 int i = 0;
4771 ALL_BREAKPOINTS (b)
4773 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4774 i++;
4777 return i;
4780 static int
4781 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4783 struct breakpoint *b;
4784 int i = 0;
4786 *other_type_used = 0;
4787 ALL_BREAKPOINTS (b)
4789 if (breakpoint_enabled (b))
4791 if (b->type == type)
4792 i++;
4793 else if ((b->type == bp_hardware_watchpoint ||
4794 b->type == bp_read_watchpoint ||
4795 b->type == bp_access_watchpoint))
4796 *other_type_used = 1;
4799 return i;
4802 /* Call this after hitting the longjmp() breakpoint. Use this to set
4803 a new breakpoint at the target of the jmp_buf.
4805 FIXME - This ought to be done by setting a temporary breakpoint
4806 that gets deleted automatically... */
4808 void
4809 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4811 struct breakpoint *b;
4813 ALL_BREAKPOINTS (b)
4814 if (b->type == bp_longjmp_resume)
4816 b->loc->requested_address = pc;
4817 b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
4818 b->type);
4819 b->enable_state = bp_enabled;
4820 b->frame_id = frame_id;
4821 check_duplicates (b);
4822 return;
4826 void
4827 disable_watchpoints_before_interactive_call_start (void)
4829 struct breakpoint *b;
4831 ALL_BREAKPOINTS (b)
4833 if (((b->type == bp_watchpoint)
4834 || (b->type == bp_hardware_watchpoint)
4835 || (b->type == bp_read_watchpoint)
4836 || (b->type == bp_access_watchpoint)
4837 || ep_is_exception_catchpoint (b))
4838 && breakpoint_enabled (b))
4840 b->enable_state = bp_call_disabled;
4841 check_duplicates (b);
4846 void
4847 enable_watchpoints_after_interactive_call_stop (void)
4849 struct breakpoint *b;
4851 ALL_BREAKPOINTS (b)
4853 if (((b->type == bp_watchpoint)
4854 || (b->type == bp_hardware_watchpoint)
4855 || (b->type == bp_read_watchpoint)
4856 || (b->type == bp_access_watchpoint)
4857 || ep_is_exception_catchpoint (b))
4858 && (b->enable_state == bp_call_disabled))
4860 b->enable_state = bp_enabled;
4861 check_duplicates (b);
4867 /* Set a breakpoint that will evaporate an end of command
4868 at address specified by SAL.
4869 Restrict it to frame FRAME if FRAME is nonzero. */
4871 struct breakpoint *
4872 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4873 enum bptype type)
4875 struct breakpoint *b;
4876 b = set_raw_breakpoint (sal, type);
4877 b->enable_state = bp_enabled;
4878 b->disposition = disp_donttouch;
4879 b->frame_id = frame_id;
4881 /* If we're debugging a multi-threaded program, then we
4882 want momentary breakpoints to be active in only a
4883 single thread of control. */
4884 if (in_thread_list (inferior_ptid))
4885 b->thread = pid_to_thread_id (inferior_ptid);
4887 return b;
4891 /* Tell the user we have just set a breakpoint B. */
4893 static void
4894 mention (struct breakpoint *b)
4896 int say_where = 0;
4897 struct cleanup *old_chain, *ui_out_chain;
4898 struct ui_stream *stb;
4900 stb = ui_out_stream_new (uiout);
4901 old_chain = make_cleanup_ui_out_stream_delete (stb);
4903 /* FIXME: This is misplaced; mention() is called by things (like
4904 hitting a watchpoint) other than breakpoint creation. It should
4905 be possible to clean this up and at the same time replace the
4906 random calls to breakpoint_changed with this hook, as has already
4907 been done for deprecated_delete_breakpoint_hook and so on. */
4908 if (deprecated_create_breakpoint_hook)
4909 deprecated_create_breakpoint_hook (b);
4910 breakpoint_create_event (b->number);
4912 if (b->ops != NULL && b->ops->print_mention != NULL)
4913 b->ops->print_mention (b);
4914 else
4915 switch (b->type)
4917 case bp_none:
4918 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4919 break;
4920 case bp_watchpoint:
4921 ui_out_text (uiout, "Watchpoint ");
4922 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4923 ui_out_field_int (uiout, "number", b->number);
4924 ui_out_text (uiout, ": ");
4925 print_expression (b->exp, stb->stream);
4926 ui_out_field_stream (uiout, "exp", stb);
4927 do_cleanups (ui_out_chain);
4928 break;
4929 case bp_hardware_watchpoint:
4930 ui_out_text (uiout, "Hardware watchpoint ");
4931 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4932 ui_out_field_int (uiout, "number", b->number);
4933 ui_out_text (uiout, ": ");
4934 print_expression (b->exp, stb->stream);
4935 ui_out_field_stream (uiout, "exp", stb);
4936 do_cleanups (ui_out_chain);
4937 break;
4938 case bp_read_watchpoint:
4939 ui_out_text (uiout, "Hardware read watchpoint ");
4940 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4941 ui_out_field_int (uiout, "number", b->number);
4942 ui_out_text (uiout, ": ");
4943 print_expression (b->exp, stb->stream);
4944 ui_out_field_stream (uiout, "exp", stb);
4945 do_cleanups (ui_out_chain);
4946 break;
4947 case bp_access_watchpoint:
4948 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4949 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4950 ui_out_field_int (uiout, "number", b->number);
4951 ui_out_text (uiout, ": ");
4952 print_expression (b->exp, stb->stream);
4953 ui_out_field_stream (uiout, "exp", stb);
4954 do_cleanups (ui_out_chain);
4955 break;
4956 case bp_breakpoint:
4957 if (ui_out_is_mi_like_p (uiout))
4959 say_where = 0;
4960 break;
4962 printf_filtered (_("Breakpoint %d"), b->number);
4963 say_where = 1;
4964 break;
4965 case bp_hardware_breakpoint:
4966 if (ui_out_is_mi_like_p (uiout))
4968 say_where = 0;
4969 break;
4971 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4972 say_where = 1;
4973 break;
4974 case bp_catch_load:
4975 case bp_catch_unload:
4976 printf_filtered (_("Catchpoint %d (%s %s)"),
4977 b->number,
4978 (b->type == bp_catch_load) ? "load" : "unload",
4979 (b->dll_pathname != NULL) ?
4980 b->dll_pathname : "<any library>");
4981 break;
4982 case bp_catch_fork:
4983 case bp_catch_vfork:
4984 printf_filtered (_("Catchpoint %d (%s)"),
4985 b->number,
4986 (b->type == bp_catch_fork) ? "fork" : "vfork");
4987 break;
4988 case bp_catch_exec:
4989 printf_filtered (_("Catchpoint %d (exec)"),
4990 b->number);
4991 break;
4992 case bp_catch_catch:
4993 case bp_catch_throw:
4994 printf_filtered (_("Catchpoint %d (%s)"),
4995 b->number,
4996 (b->type == bp_catch_catch) ? "catch" : "throw");
4997 break;
4999 case bp_until:
5000 case bp_finish:
5001 case bp_longjmp:
5002 case bp_longjmp_resume:
5003 case bp_step_resume:
5004 case bp_call_dummy:
5005 case bp_watchpoint_scope:
5006 case bp_shlib_event:
5007 case bp_thread_event:
5008 case bp_overlay_event:
5009 break;
5012 if (say_where)
5014 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5015 single string. */
5016 if (b->loc == NULL)
5018 printf_filtered (_(" (%s) pending."), b->addr_string);
5020 else
5022 if (addressprint || b->source_file == NULL)
5024 printf_filtered (" at ");
5025 deprecated_print_address_numeric (b->loc->address, 1, gdb_stdout);
5027 if (b->source_file)
5028 printf_filtered (": file %s, line %d.",
5029 b->source_file, b->line_number);
5031 if (b->loc->next)
5033 struct bp_location *loc = b->loc;
5034 int n = 0;
5035 for (; loc; loc = loc->next)
5036 ++n;
5037 printf_filtered (" (%d locations)", n);
5042 do_cleanups (old_chain);
5043 if (ui_out_is_mi_like_p (uiout))
5044 return;
5045 printf_filtered ("\n");
5049 static struct bp_location *
5050 add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
5051 const struct symtab_and_line *sal)
5053 struct bp_location *loc, **tmp;
5055 loc = allocate_bp_location (b, bptype);
5056 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5058 *tmp = loc;
5059 loc->requested_address = sal->pc;
5060 loc->address = adjust_breakpoint_address (loc->requested_address,
5061 bptype);
5062 loc->section = sal->section;
5064 set_breakpoint_location_function (loc);
5065 return loc;
5068 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5069 as textual description of the location, and COND_STRING
5070 as condition expression. */
5072 static void
5073 create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
5074 char *cond_string,
5075 enum bptype type, enum bpdisp disposition,
5076 int thread, int ignore_count, int from_tty)
5078 struct breakpoint *b = NULL;
5079 int i;
5081 if (type == bp_hardware_breakpoint)
5083 int i = hw_breakpoint_used_count ();
5084 int target_resources_ok =
5085 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5086 i + 1, 0);
5087 if (target_resources_ok == 0)
5088 error (_("No hardware breakpoint support in the target."));
5089 else if (target_resources_ok < 0)
5090 error (_("Hardware breakpoints used exceeds limit."));
5093 for (i = 0; i < sals.nelts; ++i)
5095 struct symtab_and_line sal = sals.sals[i];
5096 struct bp_location *loc;
5098 if (from_tty)
5099 describe_other_breakpoints (sal.pc, sal.section, thread);
5101 if (i == 0)
5103 b = set_raw_breakpoint (sal, type);
5104 set_breakpoint_count (breakpoint_count + 1);
5105 b->number = breakpoint_count;
5106 b->thread = thread;
5108 b->cond_string = cond_string;
5109 b->ignore_count = ignore_count;
5110 b->enable_state = bp_enabled;
5111 b->disposition = disposition;
5113 loc = b->loc;
5115 else
5117 loc = add_location_to_breakpoint (b, type, &sal);
5120 if (b->cond_string)
5122 char *arg = b->cond_string;
5123 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5124 if (*arg)
5125 error (_("Garbage %s follows condition"), arg);
5129 if (addr_string)
5130 b->addr_string = addr_string;
5131 else
5132 /* addr_string has to be used or breakpoint_re_set will delete
5133 me. */
5134 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5136 mention (b);
5139 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5140 elements to fill the void space. */
5141 static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5143 int i = index_to_remove+1;
5144 int last_index = sal->nelts-1;
5146 for (;i <= last_index; ++i)
5147 sal->sals[i-1] = sal->sals[i];
5149 --(sal->nelts);
5152 /* If appropriate, obtains all sals that correspond
5153 to the same file and line as SAL. This is done
5154 only if SAL does not have explicit PC and has
5155 line and file information. If we got just a single
5156 expanded sal, return the original.
5158 Otherwise, if SAL.explicit_line is not set, filter out
5159 all sals for which the name of enclosing function
5160 is different from SAL. This makes sure that if we have
5161 breakpoint originally set in template instantiation, say
5162 foo<int>(), we won't expand SAL to locations at the same
5163 line in all existing instantiations of 'foo'.
5166 struct symtabs_and_lines
5167 expand_line_sal_maybe (struct symtab_and_line sal)
5169 struct symtabs_and_lines expanded;
5170 CORE_ADDR original_pc = sal.pc;
5171 char *original_function = NULL;
5172 int found;
5173 int i;
5175 /* If we have explicit pc, don't expand.
5176 If we have no line number, we can't expand. */
5177 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5179 expanded.nelts = 1;
5180 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5181 expanded.sals[0] = sal;
5182 return expanded;
5185 sal.pc = 0;
5186 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5188 expanded = expand_line_sal (sal);
5189 if (expanded.nelts == 1)
5191 /* We had one sal, we got one sal. Without futher
5192 processing, just return the original sal. */
5193 xfree (expanded.sals);
5194 expanded.nelts = 1;
5195 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5196 sal.pc = original_pc;
5197 expanded.sals[0] = sal;
5198 return expanded;
5201 if (!sal.explicit_line)
5203 CORE_ADDR func_addr, func_end;
5204 for (i = 0; i < expanded.nelts; ++i)
5206 CORE_ADDR pc = expanded.sals[i].pc;
5207 char *this_function;
5208 if (find_pc_partial_function (pc, &this_function,
5209 &func_addr, &func_end))
5211 if (this_function &&
5212 strcmp (this_function, original_function) != 0)
5214 remove_sal (&expanded, i);
5215 --i;
5217 else if (func_addr == pc)
5219 /* We're at beginning of a function, and should
5220 skip prologue. */
5221 struct symbol *sym = find_pc_function (pc);
5222 if (sym)
5223 expanded.sals[i] = find_function_start_sal (sym, 1);
5224 else
5225 expanded.sals[i].pc
5226 = gdbarch_skip_prologue (current_gdbarch, pc);
5233 if (expanded.nelts <= 1)
5235 /* This is un ugly workaround. If we get zero
5236 expanded sals then something is really wrong.
5237 Fix that by returnign the original sal. */
5238 xfree (expanded.sals);
5239 expanded.nelts = 1;
5240 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5241 sal.pc = original_pc;
5242 expanded.sals[0] = sal;
5243 return expanded;
5246 if (original_pc)
5248 found = 0;
5249 for (i = 0; i < expanded.nelts; ++i)
5250 if (expanded.sals[i].pc == original_pc)
5252 found = 1;
5253 break;
5255 gdb_assert (found);
5258 return expanded;
5261 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5262 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5263 value. COND_STRING, if not NULL, specified the condition to be
5264 used for all breakpoints. Essentially the only case where
5265 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5266 function. In that case, it's still not possible to specify
5267 separate conditions for different overloaded functions, so
5268 we take just a single condition string.
5270 NOTE: If the function succeeds, the caller is expected to cleanup
5271 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5272 array contents). If the function fails (error() is called), the
5273 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5274 COND and SALS arrays and each of those arrays contents. */
5276 static void
5277 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5278 char *cond_string,
5279 enum bptype type, enum bpdisp disposition,
5280 int thread, int ignore_count, int from_tty)
5282 int i;
5283 for (i = 0; i < sals.nelts; ++i)
5285 struct symtabs_and_lines expanded =
5286 expand_line_sal_maybe (sals.sals[i]);
5288 create_breakpoint (expanded, addr_string[i],
5289 cond_string, type, disposition,
5290 thread, ignore_count, from_tty);
5294 /* Parse ARG which is assumed to be a SAL specification possibly
5295 followed by conditionals. On return, SALS contains an array of SAL
5296 addresses found. ADDR_STRING contains a vector of (canonical)
5297 address strings. ARG points to the end of the SAL. */
5299 static void
5300 parse_breakpoint_sals (char **address,
5301 struct symtabs_and_lines *sals,
5302 char ***addr_string,
5303 int *not_found_ptr)
5305 char *addr_start = *address;
5306 *addr_string = NULL;
5307 /* If no arg given, or if first arg is 'if ', use the default
5308 breakpoint. */
5309 if ((*address) == NULL
5310 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
5312 if (default_breakpoint_valid)
5314 struct symtab_and_line sal;
5315 init_sal (&sal); /* initialize to zeroes */
5316 sals->sals = (struct symtab_and_line *)
5317 xmalloc (sizeof (struct symtab_and_line));
5318 sal.pc = default_breakpoint_address;
5319 sal.line = default_breakpoint_line;
5320 sal.symtab = default_breakpoint_symtab;
5321 sal.section = find_pc_overlay (sal.pc);
5322 sals->sals[0] = sal;
5323 sals->nelts = 1;
5325 else
5326 error (_("No default breakpoint address now."));
5328 else
5330 /* Force almost all breakpoints to be in terms of the
5331 current_source_symtab (which is decode_line_1's default). This
5332 should produce the results we want almost all of the time while
5333 leaving default_breakpoint_* alone.
5334 ObjC: However, don't match an Objective-C method name which
5335 may have a '+' or '-' succeeded by a '[' */
5337 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5339 if (default_breakpoint_valid
5340 && (!cursal.symtab
5341 || ((strchr ("+-", (*address)[0]) != NULL)
5342 && ((*address)[1] != '['))))
5343 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
5344 default_breakpoint_line, addr_string,
5345 not_found_ptr);
5346 else
5347 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0,
5348 addr_string, not_found_ptr);
5350 /* For any SAL that didn't have a canonical string, fill one in. */
5351 if (sals->nelts > 0 && *addr_string == NULL)
5352 *addr_string = xcalloc (sals->nelts, sizeof (char **));
5353 if (addr_start != (*address))
5355 int i;
5356 for (i = 0; i < sals->nelts; i++)
5358 /* Add the string if not present. */
5359 if ((*addr_string)[i] == NULL)
5360 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5366 /* Convert each SAL into a real PC. Verify that the PC can be
5367 inserted as a breakpoint. If it can't throw an error. */
5369 static void
5370 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5371 char *address)
5373 int i;
5374 for (i = 0; i < sals->nelts; i++)
5375 resolve_sal_pc (&sals->sals[i]);
5378 static void
5379 do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5381 struct captured_parse_breakpoint_args *args = data;
5383 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5384 args->not_found_ptr);
5387 /* Given TOK, a string specification of condition and thread, as
5388 accepted by the 'break' command, extract the condition
5389 string and thread number and set *COND_STRING and *THREAD.
5390 PC identifies the context at which the condition should be parsed.
5391 If no condition is found, *COND_STRING is set to NULL.
5392 If no thread is found, *THREAD is set to -1. */
5393 static void
5394 find_condition_and_thread (char *tok, CORE_ADDR pc,
5395 char **cond_string, int *thread)
5397 *cond_string = NULL;
5398 *thread = -1;
5399 while (tok && *tok)
5401 char *end_tok;
5402 int toklen;
5403 char *cond_start = NULL;
5404 char *cond_end = NULL;
5405 while (*tok == ' ' || *tok == '\t')
5406 tok++;
5408 end_tok = tok;
5410 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5411 end_tok++;
5413 toklen = end_tok - tok;
5415 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5417 tok = cond_start = end_tok + 1;
5418 parse_exp_1 (&tok, block_for_pc (pc), 0);
5419 cond_end = tok;
5420 *cond_string = savestring (cond_start,
5421 cond_end - cond_start);
5423 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5425 char *tmptok;
5427 tok = end_tok + 1;
5428 tmptok = tok;
5429 *thread = strtol (tok, &tok, 0);
5430 if (tok == tmptok)
5431 error (_("Junk after thread keyword."));
5432 if (!valid_thread_id (*thread))
5433 error (_("Unknown thread %d."), *thread);
5435 else
5436 error (_("Junk at end of arguments."));
5440 /* Set a breakpoint according to ARG (function, linenum or *address)
5441 flag: first bit : 0 non-temporary, 1 temporary.
5442 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
5444 static int
5445 break_command_1 (char *arg, int flag, int from_tty)
5447 struct gdb_exception e;
5448 int tempflag, hardwareflag;
5449 struct symtabs_and_lines sals;
5450 struct symtab_and_line pending_sal;
5451 char *cond_string = NULL;
5452 char *copy_arg;
5453 char *err_msg;
5454 char *addr_start = arg;
5455 char **addr_string;
5456 struct cleanup *old_chain;
5457 struct cleanup *breakpoint_chain = NULL;
5458 struct captured_parse_breakpoint_args parse_args;
5459 int i;
5460 int pending = 0;
5461 int thread = -1;
5462 int ignore_count = 0;
5463 int not_found = 0;
5465 hardwareflag = flag & BP_HARDWAREFLAG;
5466 tempflag = flag & BP_TEMPFLAG;
5468 sals.sals = NULL;
5469 sals.nelts = 0;
5470 addr_string = NULL;
5472 parse_args.arg_p = &arg;
5473 parse_args.sals_p = &sals;
5474 parse_args.addr_string_p = &addr_string;
5475 parse_args.not_found_ptr = &not_found;
5477 e = catch_exception (uiout, do_captured_parse_breakpoint,
5478 &parse_args, RETURN_MASK_ALL);
5480 /* If caller is interested in rc value from parse, set value. */
5481 switch (e.reason)
5483 case RETURN_QUIT:
5484 exception_print (gdb_stderr, e);
5485 return e.reason;
5486 case RETURN_ERROR:
5487 switch (e.error)
5489 case NOT_FOUND_ERROR:
5491 exception_print (gdb_stderr, e);
5493 /* If pending breakpoint support is turned off, throw
5494 error. */
5496 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5497 deprecated_throw_reason (RETURN_ERROR);
5499 /* If pending breakpoint support is auto query and the user
5500 selects no, then simply return the error code. */
5501 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5502 !nquery ("Make breakpoint pending on future shared library load? "))
5503 return e.reason;
5505 /* At this point, either the user was queried about setting
5506 a pending breakpoint and selected yes, or pending
5507 breakpoint behavior is on and thus a pending breakpoint
5508 is defaulted on behalf of the user. */
5509 copy_arg = xstrdup (addr_start);
5510 addr_string = &copy_arg;
5511 sals.nelts = 1;
5512 sals.sals = &pending_sal;
5513 pending_sal.pc = 0;
5514 pending = 1;
5515 break;
5516 default:
5517 exception_print (gdb_stderr, e);
5518 return e.reason;
5520 default:
5521 if (!sals.nelts)
5522 return GDB_RC_FAIL;
5525 /* Create a chain of things that always need to be cleaned up. */
5526 old_chain = make_cleanup (null_cleanup, 0);
5528 if (!pending)
5530 /* Make sure that all storage allocated to SALS gets freed. */
5531 make_cleanup (xfree, sals.sals);
5533 /* Cleanup the addr_string array but not its contents. */
5534 make_cleanup (xfree, addr_string);
5537 /* ----------------------------- SNIP -----------------------------
5538 Anything added to the cleanup chain beyond this point is assumed
5539 to be part of a breakpoint. If the breakpoint create succeeds
5540 then the memory is not reclaimed. */
5541 breakpoint_chain = make_cleanup (null_cleanup, 0);
5543 /* Mark the contents of the addr_string for cleanup. These go on
5544 the breakpoint_chain and only occure if the breakpoint create
5545 fails. */
5546 for (i = 0; i < sals.nelts; i++)
5548 if (addr_string[i] != NULL)
5549 make_cleanup (xfree, addr_string[i]);
5552 /* Resolve all line numbers to PC's and verify that the addresses
5553 are ok for the target. */
5554 if (!pending)
5555 breakpoint_sals_to_pc (&sals, addr_start);
5557 /* Verify that condition can be parsed, before setting any
5558 breakpoints. Allocate a separate condition expression for each
5559 breakpoint. */
5560 if (!pending)
5562 /* Here we only parse 'arg' to separate condition
5563 from thread number, so parsing in context of first
5564 sal is OK. When setting the breakpoint we'll
5565 re-parse it in context of each sal. */
5566 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
5567 if (cond_string)
5568 make_cleanup (xfree, cond_string);
5569 create_breakpoints (sals, addr_string, cond_string,
5570 hardwareflag ? bp_hardware_breakpoint
5571 : bp_breakpoint,
5572 tempflag ? disp_del : disp_donttouch,
5573 thread, ignore_count, from_tty);
5575 else
5577 struct symtab_and_line sal = {0};
5578 struct breakpoint *b;
5580 make_cleanup (xfree, copy_arg);
5582 b = set_raw_breakpoint_without_location (hardwareflag
5583 ? bp_hardware_breakpoint
5584 : bp_breakpoint);
5585 set_breakpoint_count (breakpoint_count + 1);
5586 b->number = breakpoint_count;
5587 b->thread = thread;
5588 b->addr_string = addr_string[0];
5589 b->cond_string = cond_string;
5590 b->ignore_count = ignore_count;
5591 b->disposition = tempflag ? disp_del : disp_donttouch;
5592 b->from_tty = from_tty;
5593 b->flag = flag;
5594 b->condition_not_parsed = 1;
5595 mention (b);
5598 if (sals.nelts > 1)
5599 warning (_("Multiple breakpoints were set.\n"
5600 "Use the \"delete\" command to delete unwanted breakpoints."));
5601 /* That's it. Discard the cleanups for data inserted into the
5602 breakpoint. */
5603 discard_cleanups (breakpoint_chain);
5604 /* But cleanup everything else. */
5605 do_cleanups (old_chain);
5607 return GDB_RC_OK;
5610 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5611 linenum or *address) with COND and IGNORE_COUNT. */
5613 struct captured_breakpoint_args
5615 char *address;
5616 char *condition;
5617 int hardwareflag;
5618 int tempflag;
5619 int thread;
5620 int ignore_count;
5623 static int
5624 do_captured_breakpoint (struct ui_out *uiout, void *data)
5626 struct captured_breakpoint_args *args = data;
5627 struct symtabs_and_lines sals;
5628 struct expression **cond;
5629 struct cleanup *old_chain;
5630 struct cleanup *breakpoint_chain = NULL;
5631 int i;
5632 char **addr_string;
5633 char *cond_string = 0;
5635 char *address_end;
5637 /* Parse the source and lines spec. Delay check that the expression
5638 didn't contain trailing garbage until after cleanups are in
5639 place. */
5640 sals.sals = NULL;
5641 sals.nelts = 0;
5642 address_end = args->address;
5643 addr_string = NULL;
5644 parse_breakpoint_sals (&address_end, &sals, &addr_string, 0);
5646 if (!sals.nelts)
5647 return GDB_RC_NONE;
5649 /* Create a chain of things at always need to be cleaned up. */
5650 old_chain = make_cleanup (null_cleanup, 0);
5652 /* Always have a addr_string array, even if it is empty. */
5653 make_cleanup (xfree, addr_string);
5655 /* Make sure that all storage allocated to SALS gets freed. */
5656 make_cleanup (xfree, sals.sals);
5658 /* Allocate space for all the cond expressions. */
5659 cond = xcalloc (sals.nelts, sizeof (struct expression *));
5660 make_cleanup (xfree, cond);
5662 /* ----------------------------- SNIP -----------------------------
5663 Anything added to the cleanup chain beyond this point is assumed
5664 to be part of a breakpoint. If the breakpoint create goes
5665 through then that memory is not cleaned up. */
5666 breakpoint_chain = make_cleanup (null_cleanup, 0);
5668 /* Mark the contents of the addr_string for cleanup. These go on
5669 the breakpoint_chain and only occure if the breakpoint create
5670 fails. */
5671 for (i = 0; i < sals.nelts; i++)
5673 if (addr_string[i] != NULL)
5674 make_cleanup (xfree, addr_string[i]);
5677 /* Wait until now before checking for garbage at the end of the
5678 address. That way cleanups can take care of freeing any
5679 memory. */
5680 if (*address_end != '\0')
5681 error (_("Garbage %s following breakpoint address"), address_end);
5683 /* Resolve all line numbers to PC's. */
5684 breakpoint_sals_to_pc (&sals, args->address);
5686 if (args->condition != NULL)
5688 cond_string = xstrdup (args->condition);
5689 make_cleanup (xfree, cond_string);
5692 create_breakpoints (sals, addr_string, args->condition,
5693 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
5694 args->tempflag ? disp_del : disp_donttouch,
5695 args->thread, args->ignore_count, 0/*from-tty*/);
5697 /* That's it. Discard the cleanups for data inserted into the
5698 breakpoint. */
5699 discard_cleanups (breakpoint_chain);
5700 /* But cleanup everything else. */
5701 do_cleanups (old_chain);
5702 return GDB_RC_OK;
5705 enum gdb_rc
5706 gdb_breakpoint (char *address, char *condition,
5707 int hardwareflag, int tempflag,
5708 int thread, int ignore_count,
5709 char **error_message)
5711 struct captured_breakpoint_args args;
5712 args.address = address;
5713 args.condition = condition;
5714 args.hardwareflag = hardwareflag;
5715 args.tempflag = tempflag;
5716 args.thread = thread;
5717 args.ignore_count = ignore_count;
5718 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint, &args,
5719 error_message, RETURN_MASK_ALL) < 0)
5720 return GDB_RC_FAIL;
5721 else
5722 return GDB_RC_OK;
5726 /* Helper function for break_command_1 and disassemble_command. */
5728 void
5729 resolve_sal_pc (struct symtab_and_line *sal)
5731 CORE_ADDR pc;
5733 if (sal->pc == 0 && sal->symtab != NULL)
5735 if (!find_line_pc (sal->symtab, sal->line, &pc))
5736 error (_("No line %d in file \"%s\"."),
5737 sal->line, sal->symtab->filename);
5738 sal->pc = pc;
5741 if (sal->section == 0 && sal->symtab != NULL)
5743 struct blockvector *bv;
5744 struct block *b;
5745 struct symbol *sym;
5746 int index;
5748 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5749 if (bv != NULL)
5751 b = BLOCKVECTOR_BLOCK (bv, index);
5752 sym = block_function (b);
5753 if (sym != NULL)
5755 fixup_symbol_section (sym, sal->symtab->objfile);
5756 sal->section = SYMBOL_BFD_SECTION (sym);
5758 else
5760 /* It really is worthwhile to have the section, so we'll just
5761 have to look harder. This case can be executed if we have
5762 line numbers but no functions (as can happen in assembly
5763 source). */
5765 struct minimal_symbol *msym;
5767 msym = lookup_minimal_symbol_by_pc (sal->pc);
5768 if (msym)
5769 sal->section = SYMBOL_BFD_SECTION (msym);
5775 void
5776 break_command (char *arg, int from_tty)
5778 break_command_1 (arg, 0, from_tty);
5781 void
5782 tbreak_command (char *arg, int from_tty)
5784 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5787 static void
5788 hbreak_command (char *arg, int from_tty)
5790 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5793 static void
5794 thbreak_command (char *arg, int from_tty)
5796 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5799 static void
5800 stop_command (char *arg, int from_tty)
5802 printf_filtered (_("Specify the type of breakpoint to set.\n\
5803 Usage: stop in <function | address>\n\
5804 stop at <line>\n"));
5807 static void
5808 stopin_command (char *arg, int from_tty)
5810 int badInput = 0;
5812 if (arg == (char *) NULL)
5813 badInput = 1;
5814 else if (*arg != '*')
5816 char *argptr = arg;
5817 int hasColon = 0;
5819 /* look for a ':'. If this is a line number specification, then
5820 say it is bad, otherwise, it should be an address or
5821 function/method name */
5822 while (*argptr && !hasColon)
5824 hasColon = (*argptr == ':');
5825 argptr++;
5828 if (hasColon)
5829 badInput = (*argptr != ':'); /* Not a class::method */
5830 else
5831 badInput = isdigit (*arg); /* a simple line number */
5834 if (badInput)
5835 printf_filtered (_("Usage: stop in <function | address>\n"));
5836 else
5837 break_command_1 (arg, 0, from_tty);
5840 static void
5841 stopat_command (char *arg, int from_tty)
5843 int badInput = 0;
5845 if (arg == (char *) NULL || *arg == '*') /* no line number */
5846 badInput = 1;
5847 else
5849 char *argptr = arg;
5850 int hasColon = 0;
5852 /* look for a ':'. If there is a '::' then get out, otherwise
5853 it is probably a line number. */
5854 while (*argptr && !hasColon)
5856 hasColon = (*argptr == ':');
5857 argptr++;
5860 if (hasColon)
5861 badInput = (*argptr == ':'); /* we have class::method */
5862 else
5863 badInput = !isdigit (*arg); /* not a line number */
5866 if (badInput)
5867 printf_filtered (_("Usage: stop at <line>\n"));
5868 else
5869 break_command_1 (arg, 0, from_tty);
5872 /* accessflag: hw_write: watch write,
5873 hw_read: watch read,
5874 hw_access: watch access (read or write) */
5875 static void
5876 watch_command_1 (char *arg, int accessflag, int from_tty)
5878 struct breakpoint *b, *scope_breakpoint = NULL;
5879 struct symtab_and_line sal;
5880 struct expression *exp;
5881 struct block *exp_valid_block;
5882 struct value *val, *mark;
5883 struct frame_info *frame;
5884 struct frame_info *prev_frame = NULL;
5885 char *exp_start = NULL;
5886 char *exp_end = NULL;
5887 char *tok, *end_tok;
5888 int toklen;
5889 char *cond_start = NULL;
5890 char *cond_end = NULL;
5891 struct expression *cond = NULL;
5892 int i, other_type_used, target_resources_ok = 0;
5893 enum bptype bp_type;
5894 int mem_cnt = 0;
5896 init_sal (&sal); /* initialize to zeroes */
5898 /* Parse arguments. */
5899 innermost_block = NULL;
5900 exp_start = arg;
5901 exp = parse_exp_1 (&arg, 0, 0);
5902 exp_end = arg;
5903 exp_valid_block = innermost_block;
5904 mark = value_mark ();
5905 val = evaluate_expression (exp);
5906 release_value (val);
5907 if (value_lazy (val))
5908 value_fetch_lazy (val);
5910 tok = arg;
5911 while (*tok == ' ' || *tok == '\t')
5912 tok++;
5913 end_tok = tok;
5915 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5916 end_tok++;
5918 toklen = end_tok - tok;
5919 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5921 tok = cond_start = end_tok + 1;
5922 cond = parse_exp_1 (&tok, 0, 0);
5923 cond_end = tok;
5925 if (*tok)
5926 error (_("Junk at end of command."));
5928 if (accessflag == hw_read)
5929 bp_type = bp_read_watchpoint;
5930 else if (accessflag == hw_access)
5931 bp_type = bp_access_watchpoint;
5932 else
5933 bp_type = bp_hardware_watchpoint;
5935 mem_cnt = can_use_hardware_watchpoint (val);
5936 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5937 error (_("Expression cannot be implemented with read/access watchpoint."));
5938 if (mem_cnt != 0)
5940 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5941 target_resources_ok =
5942 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5943 other_type_used);
5944 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5945 error (_("Target does not support this type of hardware watchpoint."));
5947 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5948 error (_("Target can only support one kind of HW watchpoint at a time."));
5951 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5952 watchpoint could not be set. */
5953 if (!mem_cnt || target_resources_ok <= 0)
5954 bp_type = bp_watchpoint;
5956 frame = block_innermost_frame (exp_valid_block);
5957 if (frame)
5958 prev_frame = get_prev_frame (frame);
5959 else
5960 prev_frame = NULL;
5962 /* If the expression is "local", then set up a "watchpoint scope"
5963 breakpoint at the point where we've left the scope of the watchpoint
5964 expression. Create the scope breakpoint before the watchpoint, so
5965 that we will encounter it first in bpstat_stop_status. */
5966 if (innermost_block && prev_frame)
5968 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5969 bp_watchpoint_scope);
5971 scope_breakpoint->enable_state = bp_enabled;
5973 /* Automatically delete the breakpoint when it hits. */
5974 scope_breakpoint->disposition = disp_del;
5976 /* Only break in the proper frame (help with recursion). */
5977 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5979 /* Set the address at which we will stop. */
5980 scope_breakpoint->loc->requested_address
5981 = get_frame_pc (prev_frame);
5982 scope_breakpoint->loc->address
5983 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
5984 scope_breakpoint->type);
5987 /* Now set up the breakpoint. */
5988 b = set_raw_breakpoint (sal, bp_type);
5989 set_breakpoint_count (breakpoint_count + 1);
5990 b->number = breakpoint_count;
5991 b->disposition = disp_donttouch;
5992 b->exp = exp;
5993 b->exp_valid_block = exp_valid_block;
5994 b->exp_string = savestring (exp_start, exp_end - exp_start);
5995 b->val = val;
5996 b->loc->cond = cond;
5997 if (cond_start)
5998 b->cond_string = savestring (cond_start, cond_end - cond_start);
5999 else
6000 b->cond_string = 0;
6002 if (frame)
6003 b->watchpoint_frame = get_frame_id (frame);
6004 else
6005 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
6007 if (scope_breakpoint != NULL)
6009 /* The scope breakpoint is related to the watchpoint. We will
6010 need to act on them together. */
6011 b->related_breakpoint = scope_breakpoint;
6012 scope_breakpoint->related_breakpoint = b;
6015 value_free_to_mark (mark);
6016 mention (b);
6019 /* Return count of locations need to be watched and can be handled
6020 in hardware. If the watchpoint can not be handled
6021 in hardware return zero. */
6023 static int
6024 can_use_hardware_watchpoint (struct value *v)
6026 int found_memory_cnt = 0;
6027 struct value *head = v;
6029 /* Did the user specifically forbid us to use hardware watchpoints? */
6030 if (!can_use_hw_watchpoints)
6031 return 0;
6033 /* Make sure that the value of the expression depends only upon
6034 memory contents, and values computed from them within GDB. If we
6035 find any register references or function calls, we can't use a
6036 hardware watchpoint.
6038 The idea here is that evaluating an expression generates a series
6039 of values, one holding the value of every subexpression. (The
6040 expression a*b+c has five subexpressions: a, b, a*b, c, and
6041 a*b+c.) GDB's values hold almost enough information to establish
6042 the criteria given above --- they identify memory lvalues,
6043 register lvalues, computed values, etcetera. So we can evaluate
6044 the expression, and then scan the chain of values that leaves
6045 behind to decide whether we can detect any possible change to the
6046 expression's final value using only hardware watchpoints.
6048 However, I don't think that the values returned by inferior
6049 function calls are special in any way. So this function may not
6050 notice that an expression involving an inferior function call
6051 can't be watched with hardware watchpoints. FIXME. */
6052 for (; v; v = value_next (v))
6054 if (VALUE_LVAL (v) == lval_memory)
6056 if (value_lazy (v))
6057 /* A lazy memory lvalue is one that GDB never needed to fetch;
6058 we either just used its address (e.g., `a' in `a.b') or
6059 we never needed it at all (e.g., `a' in `a,b'). */
6061 else
6063 /* Ahh, memory we actually used! Check if we can cover
6064 it with hardware watchpoints. */
6065 struct type *vtype = check_typedef (value_type (v));
6067 /* We only watch structs and arrays if user asked for it
6068 explicitly, never if they just happen to appear in a
6069 middle of some value chain. */
6070 if (v == head
6071 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6072 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6074 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
6075 int len = TYPE_LENGTH (value_type (v));
6077 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
6078 return 0;
6079 else
6080 found_memory_cnt++;
6084 else if (VALUE_LVAL (v) != not_lval
6085 && deprecated_value_modifiable (v) == 0)
6086 return 0; /* ??? What does this represent? */
6087 else if (VALUE_LVAL (v) == lval_register)
6088 return 0; /* cannot watch a register with a HW watchpoint */
6091 /* The expression itself looks suitable for using a hardware
6092 watchpoint, but give the target machine a chance to reject it. */
6093 return found_memory_cnt;
6096 void
6097 watch_command_wrapper (char *arg, int from_tty)
6099 watch_command (arg, from_tty);
6102 static void
6103 watch_command (char *arg, int from_tty)
6105 watch_command_1 (arg, hw_write, from_tty);
6108 void
6109 rwatch_command_wrapper (char *arg, int from_tty)
6111 rwatch_command (arg, from_tty);
6114 static void
6115 rwatch_command (char *arg, int from_tty)
6117 watch_command_1 (arg, hw_read, from_tty);
6120 void
6121 awatch_command_wrapper (char *arg, int from_tty)
6123 awatch_command (arg, from_tty);
6126 static void
6127 awatch_command (char *arg, int from_tty)
6129 watch_command_1 (arg, hw_access, from_tty);
6133 /* Helper routines for the until_command routine in infcmd.c. Here
6134 because it uses the mechanisms of breakpoints. */
6136 /* This function is called by fetch_inferior_event via the
6137 cmd_continuation pointer, to complete the until command. It takes
6138 care of cleaning up the temporary breakpoints set up by the until
6139 command. */
6140 static void
6141 until_break_command_continuation (struct continuation_arg *arg)
6143 struct cleanup *cleanups;
6145 cleanups = (struct cleanup *) arg->data.pointer;
6146 do_exec_cleanups (cleanups);
6149 void
6150 until_break_command (char *arg, int from_tty, int anywhere)
6152 struct symtabs_and_lines sals;
6153 struct symtab_and_line sal;
6154 struct frame_info *frame = get_selected_frame (NULL);
6155 struct frame_info *prev_frame = get_prev_frame (frame);
6156 struct breakpoint *breakpoint;
6157 struct cleanup *old_chain;
6158 struct continuation_arg *arg1;
6161 clear_proceed_status ();
6163 /* Set a breakpoint where the user wants it and at return from
6164 this function */
6166 if (default_breakpoint_valid)
6167 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6168 default_breakpoint_line, (char ***) NULL, NULL);
6169 else
6170 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6171 0, (char ***) NULL, NULL);
6173 if (sals.nelts != 1)
6174 error (_("Couldn't get information on specified line."));
6176 sal = sals.sals[0];
6177 xfree (sals.sals); /* malloc'd, so freed */
6179 if (*arg)
6180 error (_("Junk at end of arguments."));
6182 resolve_sal_pc (&sal);
6184 if (anywhere)
6185 /* If the user told us to continue until a specified location,
6186 we don't specify a frame at which we need to stop. */
6187 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6188 else
6189 /* Otherwise, specify the current frame, because we want to stop only
6190 at the very same frame. */
6191 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6192 bp_until);
6194 if (!target_can_async_p ())
6195 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6196 else
6197 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
6199 /* If we are running asynchronously, and the target supports async
6200 execution, we are not waiting for the target to stop, in the call
6201 tp proceed, below. This means that we cannot delete the
6202 brekpoints until the target has actually stopped. The only place
6203 where we get a chance to do that is in fetch_inferior_event, so
6204 we must set things up for that. */
6206 if (target_can_async_p ())
6208 /* In this case the arg for the continuation is just the point
6209 in the exec_cleanups chain from where to start doing
6210 cleanups, because all the continuation does is the cleanups in
6211 the exec_cleanup_chain. */
6212 arg1 =
6213 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6214 arg1->next = NULL;
6215 arg1->data.pointer = old_chain;
6217 add_continuation (until_break_command_continuation, arg1);
6220 /* Keep within the current frame, or in frames called by the current
6221 one. */
6222 if (prev_frame)
6224 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6225 sal.pc = get_frame_pc (prev_frame);
6226 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6227 bp_until);
6228 if (!target_can_async_p ())
6229 make_cleanup_delete_breakpoint (breakpoint);
6230 else
6231 make_exec_cleanup_delete_breakpoint (breakpoint);
6234 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6235 /* Do the cleanups now, anly if we are not running asynchronously,
6236 of if we are, but the target is still synchronous. */
6237 if (!target_can_async_p ())
6238 do_cleanups (old_chain);
6241 static void
6242 ep_skip_leading_whitespace (char **s)
6244 if ((s == NULL) || (*s == NULL))
6245 return;
6246 while (isspace (**s))
6247 *s += 1;
6250 /* This function examines a string, and attempts to find a token
6251 that might be an event name in the leading characters. If a
6252 possible match is found, a pointer to the last character of
6253 the token is returned. Else, NULL is returned. */
6255 static char *
6256 ep_find_event_name_end (char *arg)
6258 char *s = arg;
6259 char *event_name_end = NULL;
6261 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6262 if (arg == NULL)
6263 return NULL;
6265 /* We break out of the loop when we find a token delimiter.
6266 Basically, we're looking for alphanumerics and underscores;
6267 anything else delimites the token. */
6268 while (*s != '\0')
6270 if (!isalnum (*s) && (*s != '_'))
6271 break;
6272 event_name_end = s;
6273 s++;
6276 return event_name_end;
6280 /* This function attempts to parse an optional "if <cond>" clause
6281 from the arg string. If one is not found, it returns NULL.
6283 Else, it returns a pointer to the condition string. (It does not
6284 attempt to evaluate the string against a particular block.) And,
6285 it updates arg to point to the first character following the parsed
6286 if clause in the arg string. */
6288 static char *
6289 ep_parse_optional_if_clause (char **arg)
6291 char *cond_string;
6293 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6294 return NULL;
6296 /* Skip the "if" keyword. */
6297 (*arg) += 2;
6299 /* Skip any extra leading whitespace, and record the start of the
6300 condition string. */
6301 ep_skip_leading_whitespace (arg);
6302 cond_string = *arg;
6304 /* Assume that the condition occupies the remainder of the arg string. */
6305 (*arg) += strlen (cond_string);
6307 return cond_string;
6310 /* This function attempts to parse an optional filename from the arg
6311 string. If one is not found, it returns NULL.
6313 Else, it returns a pointer to the parsed filename. (This function
6314 makes no attempt to verify that a file of that name exists, or is
6315 accessible.) And, it updates arg to point to the first character
6316 following the parsed filename in the arg string.
6318 Note that clients needing to preserve the returned filename for
6319 future access should copy it to their own buffers. */
6320 static char *
6321 ep_parse_optional_filename (char **arg)
6323 static char filename[1024];
6324 char *arg_p = *arg;
6325 int i;
6326 char c;
6328 if ((*arg_p == '\0') || isspace (*arg_p))
6329 return NULL;
6331 for (i = 0;; i++)
6333 c = *arg_p;
6334 if (isspace (c))
6335 c = '\0';
6336 filename[i] = c;
6337 if (c == '\0')
6338 break;
6339 arg_p++;
6341 *arg = arg_p;
6343 return filename;
6346 /* Commands to deal with catching events, such as signals, exceptions,
6347 process start/exit, etc. */
6349 typedef enum
6351 catch_fork, catch_vfork
6353 catch_fork_kind;
6355 static void
6356 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6357 int from_tty)
6359 char *cond_string = NULL;
6361 ep_skip_leading_whitespace (&arg);
6363 /* The allowed syntax is:
6364 catch [v]fork
6365 catch [v]fork if <cond>
6367 First, check if there's an if clause. */
6368 cond_string = ep_parse_optional_if_clause (&arg);
6370 if ((*arg != '\0') && !isspace (*arg))
6371 error (_("Junk at end of arguments."));
6373 /* If this target supports it, create a fork or vfork catchpoint
6374 and enable reporting of such events. */
6375 switch (fork_kind)
6377 case catch_fork:
6378 create_fork_event_catchpoint (tempflag, cond_string);
6379 break;
6380 case catch_vfork:
6381 create_vfork_event_catchpoint (tempflag, cond_string);
6382 break;
6383 default:
6384 error (_("unsupported or unknown fork kind; cannot catch it"));
6385 break;
6389 static void
6390 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6392 char *cond_string = NULL;
6394 ep_skip_leading_whitespace (&arg);
6396 /* The allowed syntax is:
6397 catch exec
6398 catch exec if <cond>
6400 First, check if there's an if clause. */
6401 cond_string = ep_parse_optional_if_clause (&arg);
6403 if ((*arg != '\0') && !isspace (*arg))
6404 error (_("Junk at end of arguments."));
6406 /* If this target supports it, create an exec catchpoint
6407 and enable reporting of such events. */
6408 create_exec_event_catchpoint (tempflag, cond_string);
6411 static void
6412 catch_load_command_1 (char *arg, int tempflag, int from_tty)
6414 char *dll_pathname = NULL;
6415 char *cond_string = NULL;
6417 ep_skip_leading_whitespace (&arg);
6419 /* The allowed syntax is:
6420 catch load
6421 catch load if <cond>
6422 catch load <filename>
6423 catch load <filename> if <cond>
6425 The user is not allowed to specify the <filename> after an
6426 if clause.
6428 We'll ignore the pathological case of a file named "if".
6430 First, check if there's an if clause. If so, then there
6431 cannot be a filename. */
6432 cond_string = ep_parse_optional_if_clause (&arg);
6434 /* If there was an if clause, then there cannot be a filename.
6435 Else, there might be a filename and an if clause. */
6436 if (cond_string == NULL)
6438 dll_pathname = ep_parse_optional_filename (&arg);
6439 ep_skip_leading_whitespace (&arg);
6440 cond_string = ep_parse_optional_if_clause (&arg);
6443 if ((*arg != '\0') && !isspace (*arg))
6444 error (_("Junk at end of arguments."));
6446 /* Create a load breakpoint that only triggers when a load of
6447 the specified dll (or any dll, if no pathname was specified)
6448 occurs. */
6449 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6450 dll_pathname, cond_string);
6453 static void
6454 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6456 char *dll_pathname = NULL;
6457 char *cond_string = NULL;
6459 ep_skip_leading_whitespace (&arg);
6461 /* The allowed syntax is:
6462 catch unload
6463 catch unload if <cond>
6464 catch unload <filename>
6465 catch unload <filename> if <cond>
6467 The user is not allowed to specify the <filename> after an
6468 if clause.
6470 We'll ignore the pathological case of a file named "if".
6472 First, check if there's an if clause. If so, then there
6473 cannot be a filename. */
6474 cond_string = ep_parse_optional_if_clause (&arg);
6476 /* If there was an if clause, then there cannot be a filename.
6477 Else, there might be a filename and an if clause. */
6478 if (cond_string == NULL)
6480 dll_pathname = ep_parse_optional_filename (&arg);
6481 ep_skip_leading_whitespace (&arg);
6482 cond_string = ep_parse_optional_if_clause (&arg);
6485 if ((*arg != '\0') && !isspace (*arg))
6486 error (_("Junk at end of arguments."));
6488 /* Create an unload breakpoint that only triggers when an unload of
6489 the specified dll (or any dll, if no pathname was specified)
6490 occurs. */
6491 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6492 dll_pathname, cond_string);
6495 /* Commands to deal with catching exceptions. */
6497 /* Set a breakpoint at the specified callback routine for an
6498 exception event callback */
6500 static void
6501 create_exception_catchpoint (int tempflag, char *cond_string,
6502 enum exception_event_kind ex_event,
6503 struct symtab_and_line *sal)
6505 struct breakpoint *b;
6506 int thread = -1; /* All threads. */
6507 enum bptype bptype;
6509 if (!sal) /* no exception support? */
6510 return;
6512 switch (ex_event)
6514 case EX_EVENT_THROW:
6515 bptype = bp_catch_throw;
6516 break;
6517 case EX_EVENT_CATCH:
6518 bptype = bp_catch_catch;
6519 break;
6520 default: /* error condition */
6521 error (_("Internal error -- invalid catchpoint kind"));
6524 b = set_raw_breakpoint (*sal, bptype);
6525 set_breakpoint_count (breakpoint_count + 1);
6526 b->number = breakpoint_count;
6527 b->cond_string = (cond_string == NULL) ?
6528 NULL : savestring (cond_string, strlen (cond_string));
6529 b->thread = thread;
6530 b->addr_string = NULL;
6531 b->enable_state = bp_enabled;
6532 b->disposition = tempflag ? disp_del : disp_donttouch;
6533 mention (b);
6536 static enum print_stop_action
6537 print_exception_catchpoint (struct breakpoint *b)
6539 annotate_catchpoint (b->number);
6541 if (strstr (b->addr_string, "throw") != NULL)
6542 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6543 b->number);
6544 else
6545 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6546 b->number);
6548 return PRINT_SRC_AND_LOC;
6551 static void
6552 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6554 if (addressprint)
6556 annotate_field (4);
6557 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6559 annotate_field (5);
6560 *last_addr = b->loc->address;
6561 if (strstr (b->addr_string, "throw") != NULL)
6562 ui_out_field_string (uiout, "what", "exception throw");
6563 else
6564 ui_out_field_string (uiout, "what", "exception catch");
6567 static void
6568 print_mention_exception_catchpoint (struct breakpoint *b)
6570 if (strstr (b->addr_string, "throw") != NULL)
6571 printf_filtered (_("Catchpoint %d (throw)"), b->number);
6572 else
6573 printf_filtered (_("Catchpoint %d (catch)"), b->number);
6576 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6577 print_exception_catchpoint,
6578 print_one_exception_catchpoint,
6579 print_mention_exception_catchpoint
6582 static int
6583 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6584 enum exception_event_kind ex_event, int from_tty)
6586 char *trigger_func_name, *nameptr;
6587 struct symtabs_and_lines sals;
6588 struct breakpoint *b;
6590 if (ex_event == EX_EVENT_CATCH)
6591 trigger_func_name = xstrdup ("__cxa_begin_catch");
6592 else
6593 trigger_func_name = xstrdup ("__cxa_throw");
6595 nameptr = trigger_func_name;
6596 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL);
6597 if (sals.nelts == 0)
6599 xfree (trigger_func_name);
6600 return 0;
6603 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6604 set_breakpoint_count (breakpoint_count + 1);
6605 b->number = breakpoint_count;
6606 b->cond_string = (cond_string == NULL) ?
6607 NULL : savestring (cond_string, strlen (cond_string));
6608 b->thread = -1;
6609 b->addr_string = trigger_func_name;
6610 b->enable_state = bp_enabled;
6611 b->disposition = tempflag ? disp_del : disp_donttouch;
6612 b->ops = &gnu_v3_exception_catchpoint_ops;
6614 xfree (sals.sals);
6615 mention (b);
6616 return 1;
6619 /* Deal with "catch catch" and "catch throw" commands */
6621 static void
6622 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6623 int tempflag, int from_tty)
6625 char *cond_string = NULL;
6626 struct symtab_and_line *sal = NULL;
6628 ep_skip_leading_whitespace (&arg);
6630 cond_string = ep_parse_optional_if_clause (&arg);
6632 if ((*arg != '\0') && !isspace (*arg))
6633 error (_("Junk at end of arguments."));
6635 if ((ex_event != EX_EVENT_THROW) &&
6636 (ex_event != EX_EVENT_CATCH))
6637 error (_("Unsupported or unknown exception event; cannot catch it"));
6639 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6640 return;
6642 /* See if we can find a callback routine */
6643 sal = target_enable_exception_callback (ex_event, 1);
6645 if (sal)
6647 /* We have callbacks from the runtime system for exceptions.
6648 Set a breakpoint on the sal found, if no errors */
6649 if (sal != (struct symtab_and_line *) -1)
6650 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6651 else
6652 return; /* something went wrong with setting up callbacks */
6655 warning (_("Unsupported with this platform/compiler combination."));
6658 /* Create a breakpoint struct for Ada exception catchpoints. */
6660 static void
6661 create_ada_exception_breakpoint (struct symtab_and_line sal,
6662 char *addr_string,
6663 char *exp_string,
6664 char *cond_string,
6665 struct expression *cond,
6666 struct breakpoint_ops *ops,
6667 int tempflag,
6668 int from_tty)
6670 struct breakpoint *b;
6672 if (from_tty)
6674 describe_other_breakpoints (sal.pc, sal.section, -1);
6675 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6676 version for exception catchpoints, because two catchpoints
6677 used for different exception names will use the same address.
6678 In this case, a "breakpoint ... also set at..." warning is
6679 unproductive. Besides. the warning phrasing is also a bit
6680 inapropriate, we should use the word catchpoint, and tell
6681 the user what type of catchpoint it is. The above is good
6682 enough for now, though. */
6685 b = set_raw_breakpoint (sal, bp_breakpoint);
6686 set_breakpoint_count (breakpoint_count + 1);
6688 b->enable_state = bp_enabled;
6689 b->disposition = tempflag ? disp_del : disp_donttouch;
6690 b->number = breakpoint_count;
6691 b->ignore_count = 0;
6692 b->loc->cond = cond;
6693 b->addr_string = addr_string;
6694 b->language = language_ada;
6695 b->cond_string = cond_string;
6696 b->exp_string = exp_string;
6697 b->thread = -1;
6698 b->ops = ops;
6699 b->from_tty = from_tty;
6701 mention (b);
6704 /* Implement the "catch exception" command. */
6706 static void
6707 catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6709 struct symtab_and_line sal;
6710 enum bptype type;
6711 char *addr_string = NULL;
6712 char *exp_string = NULL;
6713 char *cond_string = NULL;
6714 struct expression *cond = NULL;
6715 struct breakpoint_ops *ops = NULL;
6717 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6718 &cond_string, &cond, &ops);
6719 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6720 cond_string, cond, ops, tempflag,
6721 from_tty);
6724 /* Implement the "catch assert" command. */
6726 static void
6727 catch_assert_command (char *arg, int tempflag, int from_tty)
6729 struct symtab_and_line sal;
6730 char *addr_string = NULL;
6731 struct breakpoint_ops *ops = NULL;
6733 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6734 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6735 tempflag, from_tty);
6738 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6739 inside a catch_errors */
6741 static int
6742 cover_target_enable_exception_callback (void *arg)
6744 args_for_catchpoint_enable *args = arg;
6745 struct symtab_and_line *sal;
6746 sal = target_enable_exception_callback (args->kind, args->enable_p);
6747 if (sal == NULL)
6748 return 0;
6749 else if (sal == (struct symtab_and_line *) -1)
6750 return -1;
6751 else
6752 return 1; /*is valid */
6755 static void
6756 catch_command_1 (char *arg, int tempflag, int from_tty)
6759 /* The first argument may be an event name, such as "start" or "load".
6760 If so, then handle it as such. If it doesn't match an event name,
6761 then attempt to interpret it as an exception name. (This latter is
6762 the v4.16-and-earlier GDB meaning of the "catch" command.)
6764 First, try to find the bounds of what might be an event name. */
6765 char *arg1_start = arg;
6766 char *arg1_end;
6767 int arg1_length;
6769 if (arg1_start == NULL)
6771 /* Old behaviour was to use pre-v-4.16 syntax */
6772 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6773 /* return; */
6774 /* Now, this is not allowed */
6775 error (_("Catch requires an event name."));
6778 arg1_end = ep_find_event_name_end (arg1_start);
6779 if (arg1_end == NULL)
6780 error (_("catch requires an event"));
6781 arg1_length = arg1_end + 1 - arg1_start;
6783 /* Try to match what we found against known event names. */
6784 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6786 error (_("Catch of signal not yet implemented"));
6788 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6790 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6791 tempflag, from_tty);
6793 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6795 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6796 tempflag, from_tty);
6798 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6800 error (_("Catch of thread_start not yet implemented"));
6802 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6804 error (_("Catch of thread_exit not yet implemented"));
6806 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6808 error (_("Catch of thread_join not yet implemented"));
6810 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6812 error (_("Catch of start not yet implemented"));
6814 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6816 error (_("Catch of exit not yet implemented"));
6818 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6820 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6822 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6824 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6826 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6828 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6830 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6832 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6834 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6836 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6838 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6840 error (_("Catch of stop not yet implemented"));
6842 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6844 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6847 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6849 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6852 /* This doesn't appear to be an event name */
6854 else
6856 /* Pre-v.4.16 behaviour was to treat the argument
6857 as the name of an exception */
6858 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6859 /* Now this is not allowed */
6860 error (_("Unknown event kind specified for catch"));
6865 static void
6866 catch_command (char *arg, int from_tty)
6868 catch_command_1 (arg, 0, from_tty);
6872 static void
6873 tcatch_command (char *arg, int from_tty)
6875 catch_command_1 (arg, 1, from_tty);
6878 /* Delete breakpoints by address or line. */
6880 static void
6881 clear_command (char *arg, int from_tty)
6883 struct breakpoint *b;
6884 VEC(breakpoint_p) *found = 0;
6885 int ix;
6886 int default_match;
6887 struct symtabs_and_lines sals;
6888 struct symtab_and_line sal;
6889 int i;
6891 if (arg)
6893 sals = decode_line_spec (arg, 1);
6894 default_match = 0;
6896 else
6898 sals.sals = (struct symtab_and_line *)
6899 xmalloc (sizeof (struct symtab_and_line));
6900 make_cleanup (xfree, sals.sals);
6901 init_sal (&sal); /* initialize to zeroes */
6902 sal.line = default_breakpoint_line;
6903 sal.symtab = default_breakpoint_symtab;
6904 sal.pc = default_breakpoint_address;
6905 if (sal.symtab == 0)
6906 error (_("No source file specified."));
6908 sals.sals[0] = sal;
6909 sals.nelts = 1;
6911 default_match = 1;
6914 /* We don't call resolve_sal_pc here. That's not
6915 as bad as it seems, because all existing breakpoints
6916 typically have both file/line and pc set. So, if
6917 clear is given file/line, we can match this to existing
6918 breakpoint without obtaining pc at all.
6920 We only support clearing given the address explicitly
6921 present in breakpoint table. Say, we've set breakpoint
6922 at file:line. There were several PC values for that file:line,
6923 due to optimization, all in one block.
6924 We've picked one PC value. If "clear" is issued with another
6925 PC corresponding to the same file:line, the breakpoint won't
6926 be cleared. We probably can still clear the breakpoint, but
6927 since the other PC value is never presented to user, user
6928 can only find it by guessing, and it does not seem important
6929 to support that. */
6931 /* For each line spec given, delete bps which correspond
6932 to it. Do it in two passes, solely to preserve the current
6933 behavior that from_tty is forced true if we delete more than
6934 one breakpoint. */
6936 found = NULL;
6937 for (i = 0; i < sals.nelts; i++)
6939 /* If exact pc given, clear bpts at that pc.
6940 If line given (pc == 0), clear all bpts on specified line.
6941 If defaulting, clear all bpts on default line
6942 or at default pc.
6944 defaulting sal.pc != 0 tests to do
6946 0 1 pc
6947 1 1 pc _and_ line
6948 0 0 line
6949 1 0 <can't happen> */
6951 sal = sals.sals[i];
6953 /* Find all matching breakpoints and add them to
6954 'found'. */
6955 ALL_BREAKPOINTS (b)
6957 int match = 0;
6958 /* Are we going to delete b? */
6959 if (b->type != bp_none
6960 && b->type != bp_watchpoint
6961 && b->type != bp_hardware_watchpoint
6962 && b->type != bp_read_watchpoint
6963 && b->type != bp_access_watchpoint)
6965 struct bp_location *loc = b->loc;
6966 for (; loc; loc = loc->next)
6968 int pc_match = sal.pc
6969 && (loc->address == sal.pc)
6970 && (!section_is_overlay (loc->section)
6971 || loc->section == sal.section);
6972 int line_match = ((default_match || (0 == sal.pc))
6973 && b->source_file != NULL
6974 && sal.symtab != NULL
6975 && strcmp (b->source_file, sal.symtab->filename) == 0
6976 && b->line_number == sal.line);
6977 if (pc_match || line_match)
6979 match = 1;
6980 break;
6985 if (match)
6986 VEC_safe_push(breakpoint_p, found, b);
6989 /* Now go thru the 'found' chain and delete them. */
6990 if (VEC_empty(breakpoint_p, found))
6992 if (arg)
6993 error (_("No breakpoint at %s."), arg);
6994 else
6995 error (_("No breakpoint at this line."));
6998 if (VEC_length(breakpoint_p, found) > 1)
6999 from_tty = 1; /* Always report if deleted more than one */
7000 if (from_tty)
7002 if (VEC_length(breakpoint_p, found) == 1)
7003 printf_unfiltered (_("Deleted breakpoint "));
7004 else
7005 printf_unfiltered (_("Deleted breakpoints "));
7007 breakpoints_changed ();
7009 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
7011 if (from_tty)
7012 printf_unfiltered ("%d ", b->number);
7013 delete_breakpoint (b);
7015 if (from_tty)
7016 putchar_unfiltered ('\n');
7019 /* Delete breakpoint in BS if they are `delete' breakpoints and
7020 all breakpoints that are marked for deletion, whether hit or not.
7021 This is called after any breakpoint is hit, or after errors. */
7023 void
7024 breakpoint_auto_delete (bpstat bs)
7026 struct breakpoint *b, *temp;
7028 for (; bs; bs = bs->next)
7029 if (bs->breakpoint_at && bs->breakpoint_at->owner->disposition == disp_del
7030 && bs->stop)
7031 delete_breakpoint (bs->breakpoint_at->owner);
7033 ALL_BREAKPOINTS_SAFE (b, temp)
7035 if (b->disposition == disp_del_at_next_stop)
7036 delete_breakpoint (b);
7040 /* Remove locations of breakpoint BPT from
7041 the global list of breakpoint locations. */
7043 static void
7044 unlink_locations_from_global_list (struct breakpoint *bpt)
7046 /* This code assumes that the locations
7047 of a breakpoint are found in the global list
7048 in the same order, but not necessary adjacent. */
7049 struct bp_location **tmp = &bp_location_chain;
7050 struct bp_location *here = bpt->loc;
7052 if (here == NULL)
7053 return;
7055 for (; *tmp && here;)
7057 if (*tmp == here)
7059 *tmp = here->global_next;
7060 here = here->next;
7062 else
7064 tmp = &((*tmp)->global_next);
7069 /* Delete a breakpoint and clean up all traces of it in the data
7070 structures. */
7072 void
7073 delete_breakpoint (struct breakpoint *bpt)
7075 struct breakpoint *b;
7076 bpstat bs;
7077 struct bp_location *loc;
7079 gdb_assert (bpt != NULL);
7081 /* Has this bp already been deleted? This can happen because multiple
7082 lists can hold pointers to bp's. bpstat lists are especial culprits.
7084 One example of this happening is a watchpoint's scope bp. When the
7085 scope bp triggers, we notice that the watchpoint is out of scope, and
7086 delete it. We also delete its scope bp. But the scope bp is marked
7087 "auto-deleting", and is already on a bpstat. That bpstat is then
7088 checked for auto-deleting bp's, which are deleted.
7090 A real solution to this problem might involve reference counts in bp's,
7091 and/or giving them pointers back to their referencing bpstat's, and
7092 teaching delete_breakpoint to only free a bp's storage when no more
7093 references were extent. A cheaper bandaid was chosen. */
7094 if (bpt->type == bp_none)
7095 return;
7097 if (deprecated_delete_breakpoint_hook)
7098 deprecated_delete_breakpoint_hook (bpt);
7099 breakpoint_delete_event (bpt->number);
7101 for (loc = bpt->loc; loc; loc = loc->next)
7103 if (loc->inserted)
7104 remove_breakpoint (loc, mark_inserted);
7106 free_valchain (loc);
7108 if (loc->cond)
7109 xfree (loc->cond);
7111 if (loc->function_name)
7112 xfree (loc->function_name);
7115 if (breakpoint_chain == bpt)
7116 breakpoint_chain = bpt->next;
7118 /* If we have callback-style exception catchpoints, don't go through
7119 the adjustments to the C++ runtime library etc. if the inferior
7120 isn't actually running. target_enable_exception_callback for a
7121 null target ops vector gives an undesirable error message, so we
7122 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
7123 exceptions are supported in this way, it's OK for now. FIXME */
7124 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
7126 /* Format possible error msg */
7127 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
7128 bpt->number);
7129 struct cleanup *cleanups = make_cleanup (xfree, message);
7130 args_for_catchpoint_enable args;
7131 args.kind = bpt->type == bp_catch_catch ?
7132 EX_EVENT_CATCH : EX_EVENT_THROW;
7133 args.enable_p = 0;
7134 catch_errors (cover_target_enable_exception_callback, &args,
7135 message, RETURN_MASK_ALL);
7136 do_cleanups (cleanups);
7140 ALL_BREAKPOINTS (b)
7141 if (b->next == bpt)
7143 b->next = bpt->next;
7144 break;
7147 unlink_locations_from_global_list (bpt);
7149 check_duplicates (bpt);
7151 if (bpt->type != bp_hardware_watchpoint
7152 && bpt->type != bp_read_watchpoint
7153 && bpt->type != bp_access_watchpoint
7154 && bpt->type != bp_catch_fork
7155 && bpt->type != bp_catch_vfork
7156 && bpt->type != bp_catch_exec)
7157 for (loc = bpt->loc; loc; loc = loc->next)
7159 /* If this breakpoint location was inserted, and there is
7160 another breakpoint at the same address, we need to
7161 insert the other breakpoint. */
7162 if (loc->inserted)
7164 struct bp_location *loc2;
7165 ALL_BP_LOCATIONS (loc2)
7166 if (loc2->address == loc->address
7167 && loc2->section == loc->section
7168 && !loc->duplicate
7169 && loc2->owner->enable_state != bp_disabled
7170 && loc2->enabled
7171 && !loc2->shlib_disabled
7172 && loc2->owner->enable_state != bp_call_disabled)
7174 int val;
7176 /* We should never reach this point if there is a permanent
7177 breakpoint at the same address as the one being deleted.
7178 If there is a permanent breakpoint somewhere, it should
7179 always be the only one inserted. */
7180 if (loc2->owner->enable_state == bp_permanent)
7181 internal_error (__FILE__, __LINE__,
7182 _("another breakpoint was inserted on top of "
7183 "a permanent breakpoint"));
7185 memset (&loc2->target_info, 0, sizeof (loc2->target_info));
7186 loc2->target_info.placed_address = loc2->address;
7187 if (b->type == bp_hardware_breakpoint)
7188 val = target_insert_hw_breakpoint (&loc2->target_info);
7189 else
7190 val = target_insert_breakpoint (&loc2->target_info);
7192 /* If there was an error in the insert, print a message, then stop execution. */
7193 if (val != 0)
7195 struct ui_file *tmp_error_stream = mem_fileopen ();
7196 make_cleanup_ui_file_delete (tmp_error_stream);
7199 if (b->type == bp_hardware_breakpoint)
7201 fprintf_unfiltered (tmp_error_stream,
7202 "Cannot insert hardware breakpoint %d.\n"
7203 "You may have requested too many hardware breakpoints.\n",
7204 b->number);
7206 else
7208 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
7209 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
7210 deprecated_print_address_numeric (loc2->address, 1, tmp_error_stream);
7211 fprintf_filtered (tmp_error_stream, ": %s.\n",
7212 safe_strerror (val));
7215 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
7216 target_terminal_ours_for_output ();
7217 error_stream(tmp_error_stream);
7219 else
7220 loc2->inserted = 1;
7225 free_command_lines (&bpt->commands);
7226 if (bpt->cond_string != NULL)
7227 xfree (bpt->cond_string);
7228 if (bpt->addr_string != NULL)
7229 xfree (bpt->addr_string);
7230 if (bpt->exp != NULL)
7231 xfree (bpt->exp);
7232 if (bpt->exp_string != NULL)
7233 xfree (bpt->exp_string);
7234 if (bpt->val != NULL)
7235 value_free (bpt->val);
7236 if (bpt->source_file != NULL)
7237 xfree (bpt->source_file);
7238 if (bpt->dll_pathname != NULL)
7239 xfree (bpt->dll_pathname);
7240 if (bpt->triggered_dll_pathname != NULL)
7241 xfree (bpt->triggered_dll_pathname);
7242 if (bpt->exec_pathname != NULL)
7243 xfree (bpt->exec_pathname);
7245 /* Be sure no bpstat's are pointing at it after it's been freed. */
7246 /* FIXME, how can we find all bpstat's?
7247 We just check stop_bpstat for now. Note that we cannot just
7248 remove bpstats pointing at bpt from the stop_bpstat list
7249 entirely, as breakpoint commands are associated with the bpstat;
7250 if we remove it here, then the later call to
7251 bpstat_do_actions (&stop_bpstat);
7252 in event-top.c won't do anything, and temporary breakpoints
7253 with commands won't work. */
7254 for (bs = stop_bpstat; bs; bs = bs->next)
7255 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7257 bs->breakpoint_at = NULL;
7258 bs->old_val = NULL;
7259 /* bs->commands will be freed later. */
7261 /* On the chance that someone will soon try again to delete this same
7262 bp, we mark it as deleted before freeing its storage. */
7263 bpt->type = bp_none;
7265 for (loc = bpt->loc; loc;)
7267 struct bp_location *loc_next = loc->next;
7268 xfree (loc);
7269 loc = loc_next;
7271 xfree (bpt);
7274 static void
7275 do_delete_breakpoint_cleanup (void *b)
7277 delete_breakpoint (b);
7280 struct cleanup *
7281 make_cleanup_delete_breakpoint (struct breakpoint *b)
7283 return make_cleanup (do_delete_breakpoint_cleanup, b);
7286 struct cleanup *
7287 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
7289 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
7292 void
7293 delete_command (char *arg, int from_tty)
7295 struct breakpoint *b, *temp;
7297 dont_repeat ();
7299 if (arg == 0)
7301 int breaks_to_delete = 0;
7303 /* Delete all breakpoints if no argument.
7304 Do not delete internal or call-dummy breakpoints, these
7305 have to be deleted with an explicit breakpoint number argument. */
7306 ALL_BREAKPOINTS (b)
7308 if (b->type != bp_call_dummy &&
7309 b->type != bp_shlib_event &&
7310 b->type != bp_thread_event &&
7311 b->type != bp_overlay_event &&
7312 b->number >= 0)
7314 breaks_to_delete = 1;
7315 break;
7319 /* Ask user only if there are some breakpoints to delete. */
7320 if (!from_tty
7321 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7323 ALL_BREAKPOINTS_SAFE (b, temp)
7325 if (b->type != bp_call_dummy &&
7326 b->type != bp_shlib_event &&
7327 b->type != bp_thread_event &&
7328 b->type != bp_overlay_event &&
7329 b->number >= 0)
7330 delete_breakpoint (b);
7334 else
7335 map_breakpoint_numbers (arg, delete_breakpoint);
7338 static int
7339 all_locations_are_pending (struct bp_location *loc)
7341 for (; loc; loc = loc->next)
7342 if (!loc->shlib_disabled)
7343 return 0;
7344 return 1;
7347 static void
7348 update_breakpoint_locations (struct breakpoint *b,
7349 struct symtabs_and_lines sals)
7351 int i;
7352 char *s;
7353 struct bp_location *existing_locations = b->loc;
7355 /* If there's no new locations, and all existing locations
7356 are pending, don't do anything. This optimizes
7357 the common case where all locations are in the same
7358 shared library, that was unloaded. We'd like to
7359 retain the location, so that when the library
7360 is loaded again, we don't loose the enabled/disabled
7361 status of the individual locations. */
7362 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7363 return;
7365 unlink_locations_from_global_list (b);
7366 b->loc = NULL;
7368 for (i = 0; i < sals.nelts; ++i)
7370 struct bp_location *new_loc =
7371 add_location_to_breakpoint (b, b->type, &(sals.sals[i]));
7373 /* Reparse conditions, they might contain references to the
7374 old symtab. */
7375 if (b->cond_string != NULL)
7377 struct gdb_exception e;
7379 s = b->cond_string;
7380 TRY_CATCH (e, RETURN_MASK_ERROR)
7382 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7385 if (e.reason < 0)
7387 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7388 b->number, e.message);
7389 new_loc->enabled = 0;
7393 if (b->source_file != NULL)
7394 xfree (b->source_file);
7395 if (sals.sals[i].symtab == NULL)
7396 b->source_file = NULL;
7397 else
7398 b->source_file =
7399 savestring (sals.sals[i].symtab->filename,
7400 strlen (sals.sals[i].symtab->filename));
7402 if (b->line_number == 0)
7403 b->line_number = sals.sals[i].line;
7406 /* If possible, carry over 'disable' status from existing breakpoints. */
7408 struct bp_location *e = existing_locations;
7409 for (; e; e = e->next)
7411 if (!e->enabled && e->function_name)
7413 struct bp_location *l = b->loc;
7414 for (; l; l = l->next)
7415 if (l->function_name
7416 && strcmp (e->function_name, l->function_name) == 0)
7418 l->enabled = 0;
7419 break;
7425 while (existing_locations)
7427 struct bp_location *next = existing_locations->next;
7428 free_bp_location (existing_locations);
7429 existing_locations = next;
7434 /* Reset a breakpoint given it's struct breakpoint * BINT.
7435 The value we return ends up being the return value from catch_errors.
7436 Unused in this case. */
7438 static int
7439 breakpoint_re_set_one (void *bint)
7441 /* get past catch_errs */
7442 struct breakpoint *b = (struct breakpoint *) bint;
7443 struct value *mark;
7444 int i;
7445 int not_found = 0;
7446 int *not_found_ptr = &not_found;
7447 struct symtabs_and_lines sals = {};
7448 struct symtabs_and_lines expanded;
7449 char *s;
7450 enum enable_state save_enable;
7451 struct gdb_exception e;
7454 switch (b->type)
7456 case bp_none:
7457 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7458 b->number);
7459 return 0;
7460 case bp_breakpoint:
7461 case bp_hardware_breakpoint:
7462 case bp_catch_load:
7463 case bp_catch_unload:
7464 if (b->addr_string == NULL)
7466 /* Anything without a string can't be re-set. */
7467 delete_breakpoint (b);
7468 return 0;
7471 set_language (b->language);
7472 input_radix = b->input_radix;
7473 s = b->addr_string;
7474 TRY_CATCH (e, RETURN_MASK_ERROR)
7476 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7477 not_found_ptr);
7479 if (e.reason < 0)
7481 int not_found_and_ok = 0;
7482 /* For pending breakpoints, it's expected that parsing
7483 will fail until the right shared library is loaded.
7484 User has already told to create pending breakpoints and
7485 don't need extra messages. If breakpoint is in bp_shlib_disabled
7486 state, then user already saw the message about that breakpoint
7487 being disabled, and don't want to see more errors. */
7488 if (not_found
7489 && (b->condition_not_parsed
7490 || (b->loc && b->loc->shlib_disabled)
7491 || b->enable_state == bp_disabled))
7492 not_found_and_ok = 1;
7494 if (!not_found_and_ok)
7496 /* We surely don't want to warn about the same breakpoint
7497 10 times. One solution, implemented here, is disable
7498 the breakpoint on error. Another solution would be to
7499 have separate 'warning emitted' flag. Since this
7500 happens only when a binary has changed, I don't know
7501 which approach is better. */
7502 b->enable_state = bp_disabled;
7503 throw_exception (e);
7507 if (not_found)
7508 break;
7510 gdb_assert (sals.nelts == 1);
7511 resolve_sal_pc (&sals.sals[0]);
7512 if (b->condition_not_parsed && s && s[0])
7514 char *cond_string = 0;
7515 int thread = -1;
7516 find_condition_and_thread (s, sals.sals[0].pc,
7517 &cond_string, &thread);
7518 if (cond_string)
7519 b->cond_string = cond_string;
7520 b->thread = thread;
7521 b->condition_not_parsed = 0;
7523 expanded = expand_line_sal_maybe (sals.sals[0]);
7524 update_breakpoint_locations (b, expanded);
7526 /* Now that this is re-enabled, check_duplicates
7527 can be used. */
7528 check_duplicates (b);
7530 xfree (sals.sals);
7531 break;
7533 case bp_watchpoint:
7534 case bp_hardware_watchpoint:
7535 case bp_read_watchpoint:
7536 case bp_access_watchpoint:
7537 innermost_block = NULL;
7538 /* The issue arises of what context to evaluate this in. The
7539 same one as when it was set, but what does that mean when
7540 symbols have been re-read? We could save the filename and
7541 functionname, but if the context is more local than that, the
7542 best we could do would be something like how many levels deep
7543 and which index at that particular level, but that's going to
7544 be less stable than filenames or function names. */
7546 /* So for now, just use a global context. */
7547 if (b->exp)
7549 xfree (b->exp);
7550 /* Avoid re-freeing b->exp if an error during the call to
7551 parse_expression. */
7552 b->exp = NULL;
7554 b->exp = parse_expression (b->exp_string);
7555 b->exp_valid_block = innermost_block;
7556 mark = value_mark ();
7557 if (b->val)
7559 value_free (b->val);
7560 /* Avoid re-freeing b->val if an error during the call to
7561 evaluate_expression. */
7562 b->val = NULL;
7564 b->val = evaluate_expression (b->exp);
7565 release_value (b->val);
7566 if (value_lazy (b->val) && breakpoint_enabled (b))
7567 value_fetch_lazy (b->val);
7569 if (b->cond_string != NULL)
7571 s = b->cond_string;
7572 if (b->loc->cond)
7574 xfree (b->loc->cond);
7575 /* Avoid re-freeing b->exp if an error during the call
7576 to parse_exp_1. */
7577 b->loc->cond = NULL;
7579 b->loc->cond = parse_exp_1 (&s, (struct block *) 0, 0);
7581 if (breakpoint_enabled (b))
7582 mention (b);
7583 value_free_to_mark (mark);
7584 break;
7585 case bp_catch_catch:
7586 case bp_catch_throw:
7587 break;
7588 /* We needn't really do anything to reset these, since the mask
7589 that requests them is unaffected by e.g., new libraries being
7590 loaded. */
7591 case bp_catch_fork:
7592 case bp_catch_vfork:
7593 case bp_catch_exec:
7594 break;
7596 default:
7597 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7598 /* fall through */
7599 /* Delete longjmp and overlay event breakpoints; they will be
7600 reset later by breakpoint_re_set. */
7601 case bp_longjmp:
7602 case bp_longjmp_resume:
7603 case bp_overlay_event:
7604 delete_breakpoint (b);
7605 break;
7607 /* This breakpoint is special, it's set up when the inferior
7608 starts and we really don't want to touch it. */
7609 case bp_shlib_event:
7611 /* Like bp_shlib_event, this breakpoint type is special.
7612 Once it is set up, we do not want to touch it. */
7613 case bp_thread_event:
7615 /* Keep temporary breakpoints, which can be encountered when we step
7616 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7617 Otherwise these should have been blown away via the cleanup chain
7618 or by breakpoint_init_inferior when we rerun the executable. */
7619 case bp_until:
7620 case bp_finish:
7621 case bp_watchpoint_scope:
7622 case bp_call_dummy:
7623 case bp_step_resume:
7624 break;
7627 return 0;
7630 /* Re-set all breakpoints after symbols have been re-loaded. */
7631 void
7632 breakpoint_re_set (void)
7634 struct breakpoint *b, *temp;
7635 enum language save_language;
7636 int save_input_radix;
7638 save_language = current_language->la_language;
7639 save_input_radix = input_radix;
7640 ALL_BREAKPOINTS_SAFE (b, temp)
7642 /* Format possible error msg */
7643 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7644 b->number);
7645 struct cleanup *cleanups = make_cleanup (xfree, message);
7646 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7647 do_cleanups (cleanups);
7649 set_language (save_language);
7650 input_radix = save_input_radix;
7652 if (gdbarch_get_longjmp_target_p (current_gdbarch))
7654 create_longjmp_breakpoint ("longjmp");
7655 create_longjmp_breakpoint ("_longjmp");
7656 create_longjmp_breakpoint ("siglongjmp");
7657 create_longjmp_breakpoint ("_siglongjmp");
7658 create_longjmp_breakpoint (NULL);
7661 create_overlay_event_breakpoint ("_ovly_debug_event");
7664 /* Reset the thread number of this breakpoint:
7666 - If the breakpoint is for all threads, leave it as-is.
7667 - Else, reset it to the current thread for inferior_ptid. */
7668 void
7669 breakpoint_re_set_thread (struct breakpoint *b)
7671 if (b->thread != -1)
7673 if (in_thread_list (inferior_ptid))
7674 b->thread = pid_to_thread_id (inferior_ptid);
7678 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7679 If from_tty is nonzero, it prints a message to that effect,
7680 which ends with a period (no newline). */
7682 void
7683 set_ignore_count (int bptnum, int count, int from_tty)
7685 struct breakpoint *b;
7687 if (count < 0)
7688 count = 0;
7690 ALL_BREAKPOINTS (b)
7691 if (b->number == bptnum)
7693 b->ignore_count = count;
7694 if (from_tty)
7696 if (count == 0)
7697 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7698 bptnum);
7699 else if (count == 1)
7700 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7701 bptnum);
7702 else
7703 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7704 count, bptnum);
7706 breakpoints_changed ();
7707 breakpoint_modify_event (b->number);
7708 return;
7711 error (_("No breakpoint number %d."), bptnum);
7714 /* Clear the ignore counts of all breakpoints. */
7715 void
7716 breakpoint_clear_ignore_counts (void)
7718 struct breakpoint *b;
7720 ALL_BREAKPOINTS (b)
7721 b->ignore_count = 0;
7724 /* Command to set ignore-count of breakpoint N to COUNT. */
7726 static void
7727 ignore_command (char *args, int from_tty)
7729 char *p = args;
7730 int num;
7732 if (p == 0)
7733 error_no_arg (_("a breakpoint number"));
7735 num = get_number (&p);
7736 if (num == 0)
7737 error (_("bad breakpoint number: '%s'"), args);
7738 if (*p == 0)
7739 error (_("Second argument (specified ignore-count) is missing."));
7741 set_ignore_count (num,
7742 longest_to_int (value_as_long (parse_and_eval (p))),
7743 from_tty);
7744 if (from_tty)
7745 printf_filtered ("\n");
7748 /* Call FUNCTION on each of the breakpoints
7749 whose numbers are given in ARGS. */
7751 static void
7752 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7754 char *p = args;
7755 char *p1;
7756 int num;
7757 struct breakpoint *b, *tmp;
7758 int match;
7760 if (p == 0)
7761 error_no_arg (_("one or more breakpoint numbers"));
7763 while (*p)
7765 match = 0;
7766 p1 = p;
7768 num = get_number_or_range (&p1);
7769 if (num == 0)
7771 warning (_("bad breakpoint number at or near '%s'"), p);
7773 else
7775 ALL_BREAKPOINTS_SAFE (b, tmp)
7776 if (b->number == num)
7778 struct breakpoint *related_breakpoint = b->related_breakpoint;
7779 match = 1;
7780 function (b);
7781 if (related_breakpoint)
7782 function (related_breakpoint);
7783 break;
7785 if (match == 0)
7786 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7788 p = p1;
7792 static struct bp_location *
7793 find_location_by_number (char *number)
7795 char *dot = strchr (number, '.');
7796 char *p1;
7797 int bp_num;
7798 int loc_num;
7799 struct breakpoint *b;
7800 struct bp_location *loc;
7802 *dot = '\0';
7804 p1 = number;
7805 bp_num = get_number_or_range (&p1);
7806 if (bp_num == 0)
7807 error (_("Bad breakpoint number '%s'"), number);
7809 ALL_BREAKPOINTS (b)
7810 if (b->number == bp_num)
7812 break;
7815 if (!b || b->number != bp_num)
7816 error (_("Bad breakpoint number '%s'"), number);
7818 p1 = dot+1;
7819 loc_num = get_number_or_range (&p1);
7820 if (loc_num == 0)
7821 error (_("Bad breakpoint location number '%s'"), number);
7823 --loc_num;
7824 loc = b->loc;
7825 for (;loc_num && loc; --loc_num, loc = loc->next)
7827 if (!loc)
7828 error (_("Bad breakpoint location number '%s'"), dot+1);
7830 return loc;
7834 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7835 If from_tty is nonzero, it prints a message to that effect,
7836 which ends with a period (no newline). */
7838 void
7839 disable_breakpoint (struct breakpoint *bpt)
7841 /* Never disable a watchpoint scope breakpoint; we want to
7842 hit them when we leave scope so we can delete both the
7843 watchpoint and its scope breakpoint at that time. */
7844 if (bpt->type == bp_watchpoint_scope)
7845 return;
7847 /* You can't disable permanent breakpoints. */
7848 if (bpt->enable_state == bp_permanent)
7849 return;
7851 bpt->enable_state = bp_disabled;
7853 check_duplicates (bpt);
7855 if (deprecated_modify_breakpoint_hook)
7856 deprecated_modify_breakpoint_hook (bpt);
7857 breakpoint_modify_event (bpt->number);
7860 static void
7861 disable_command (char *args, int from_tty)
7863 struct breakpoint *bpt;
7864 if (args == 0)
7865 ALL_BREAKPOINTS (bpt)
7866 switch (bpt->type)
7868 case bp_none:
7869 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7870 bpt->number);
7871 continue;
7872 case bp_breakpoint:
7873 case bp_catch_load:
7874 case bp_catch_unload:
7875 case bp_catch_fork:
7876 case bp_catch_vfork:
7877 case bp_catch_exec:
7878 case bp_catch_catch:
7879 case bp_catch_throw:
7880 case bp_hardware_breakpoint:
7881 case bp_watchpoint:
7882 case bp_hardware_watchpoint:
7883 case bp_read_watchpoint:
7884 case bp_access_watchpoint:
7885 disable_breakpoint (bpt);
7886 default:
7887 continue;
7889 else if (strchr (args, '.'))
7891 struct bp_location *loc = find_location_by_number (args);
7892 if (loc)
7893 loc->enabled = 0;
7894 check_duplicates (loc->owner);
7896 else
7897 map_breakpoint_numbers (args, disable_breakpoint);
7900 static void
7901 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7903 int target_resources_ok, other_type_used;
7904 struct value *mark;
7906 if (bpt->type == bp_hardware_breakpoint)
7908 int i;
7909 i = hw_breakpoint_used_count ();
7910 target_resources_ok =
7911 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7912 i + 1, 0);
7913 if (target_resources_ok == 0)
7914 error (_("No hardware breakpoint support in the target."));
7915 else if (target_resources_ok < 0)
7916 error (_("Hardware breakpoints used exceeds limit."));
7919 if (bpt->type == bp_watchpoint ||
7920 bpt->type == bp_hardware_watchpoint ||
7921 bpt->type == bp_read_watchpoint ||
7922 bpt->type == bp_access_watchpoint)
7924 struct frame_id saved_frame_id;
7926 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7927 if (bpt->exp_valid_block != NULL)
7929 struct frame_info *fr =
7930 fr = frame_find_by_id (bpt->watchpoint_frame);
7931 if (fr == NULL)
7933 printf_filtered (_("\
7934 Cannot enable watchpoint %d because the block in which its expression\n\
7935 is valid is not currently in scope.\n"), bpt->number);
7936 return;
7938 select_frame (fr);
7941 if (bpt->val)
7942 value_free (bpt->val);
7943 mark = value_mark ();
7944 bpt->val = evaluate_expression (bpt->exp);
7945 release_value (bpt->val);
7946 if (value_lazy (bpt->val))
7947 value_fetch_lazy (bpt->val);
7949 if (bpt->type == bp_hardware_watchpoint ||
7950 bpt->type == bp_read_watchpoint ||
7951 bpt->type == bp_access_watchpoint)
7953 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7954 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7956 /* Hack around 'unused var' error for some targets here */
7957 (void) mem_cnt, (void) i;
7958 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7959 bpt->type, i + mem_cnt, other_type_used);
7960 /* we can consider of type is bp_hardware_watchpoint, convert to
7961 bp_watchpoint in the following condition */
7962 if (target_resources_ok < 0)
7964 printf_filtered (_("\
7965 Cannot enable watchpoint %d because target watch resources\n\
7966 have been allocated for other watchpoints.\n"), bpt->number);
7967 value_free_to_mark (mark);
7968 return;
7972 select_frame (frame_find_by_id (saved_frame_id));
7973 value_free_to_mark (mark);
7976 if (bpt->enable_state != bp_permanent)
7977 bpt->enable_state = bp_enabled;
7978 bpt->disposition = disposition;
7979 check_duplicates (bpt);
7980 breakpoints_changed ();
7982 if (deprecated_modify_breakpoint_hook)
7983 deprecated_modify_breakpoint_hook (bpt);
7984 breakpoint_modify_event (bpt->number);
7988 void
7989 enable_breakpoint (struct breakpoint *bpt)
7991 do_enable_breakpoint (bpt, bpt->disposition);
7994 /* The enable command enables the specified breakpoints (or all defined
7995 breakpoints) so they once again become (or continue to be) effective
7996 in stopping the inferior. */
7998 static void
7999 enable_command (char *args, int from_tty)
8001 struct breakpoint *bpt;
8002 if (args == 0)
8003 ALL_BREAKPOINTS (bpt)
8004 switch (bpt->type)
8006 case bp_none:
8007 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
8008 bpt->number);
8009 continue;
8010 case bp_breakpoint:
8011 case bp_catch_load:
8012 case bp_catch_unload:
8013 case bp_catch_fork:
8014 case bp_catch_vfork:
8015 case bp_catch_exec:
8016 case bp_catch_catch:
8017 case bp_catch_throw:
8018 case bp_hardware_breakpoint:
8019 case bp_watchpoint:
8020 case bp_hardware_watchpoint:
8021 case bp_read_watchpoint:
8022 case bp_access_watchpoint:
8023 enable_breakpoint (bpt);
8024 default:
8025 continue;
8027 else if (strchr (args, '.'))
8029 struct bp_location *loc = find_location_by_number (args);
8030 if (loc)
8031 loc->enabled = 1;
8032 check_duplicates (loc->owner);
8034 else
8035 map_breakpoint_numbers (args, enable_breakpoint);
8038 static void
8039 enable_once_breakpoint (struct breakpoint *bpt)
8041 do_enable_breakpoint (bpt, disp_disable);
8044 static void
8045 enable_once_command (char *args, int from_tty)
8047 map_breakpoint_numbers (args, enable_once_breakpoint);
8050 static void
8051 enable_delete_breakpoint (struct breakpoint *bpt)
8053 do_enable_breakpoint (bpt, disp_del);
8056 static void
8057 enable_delete_command (char *args, int from_tty)
8059 map_breakpoint_numbers (args, enable_delete_breakpoint);
8062 static void
8063 set_breakpoint_cmd (char *args, int from_tty)
8067 static void
8068 show_breakpoint_cmd (char *args, int from_tty)
8072 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8074 struct symtabs_and_lines
8075 decode_line_spec_1 (char *string, int funfirstline)
8077 struct symtabs_and_lines sals;
8078 if (string == 0)
8079 error (_("Empty line specification."));
8080 if (default_breakpoint_valid)
8081 sals = decode_line_1 (&string, funfirstline,
8082 default_breakpoint_symtab,
8083 default_breakpoint_line,
8084 (char ***) NULL, NULL);
8085 else
8086 sals = decode_line_1 (&string, funfirstline,
8087 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8088 if (*string)
8089 error (_("Junk at end of line specification: %s"), string);
8090 return sals;
8093 /* Create and insert a raw software breakpoint at PC. Return an
8094 identifier, which should be used to remove the breakpoint later.
8095 In general, places which call this should be using something on the
8096 breakpoint chain instead; this function should be eliminated
8097 someday. */
8099 void *
8100 deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8102 struct bp_target_info *bp_tgt;
8104 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8105 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8107 bp_tgt->placed_address = pc;
8108 if (target_insert_breakpoint (bp_tgt) != 0)
8110 /* Could not insert the breakpoint. */
8111 xfree (bp_tgt);
8112 return NULL;
8115 return bp_tgt;
8118 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8121 deprecated_remove_raw_breakpoint (void *bp)
8123 struct bp_target_info *bp_tgt = bp;
8124 int ret;
8126 ret = target_remove_breakpoint (bp_tgt);
8127 xfree (bp_tgt);
8129 return ret;
8132 /* One (or perhaps two) breakpoints used for software single stepping. */
8134 static void *single_step_breakpoints[2];
8136 /* Create and insert a breakpoint for software single step. */
8138 void
8139 insert_single_step_breakpoint (CORE_ADDR next_pc)
8141 void **bpt_p;
8143 if (single_step_breakpoints[0] == NULL)
8144 bpt_p = &single_step_breakpoints[0];
8145 else
8147 gdb_assert (single_step_breakpoints[1] == NULL);
8148 bpt_p = &single_step_breakpoints[1];
8151 /* NOTE drow/2006-04-11: A future improvement to this function would be
8152 to only create the breakpoints once, and actually put them on the
8153 breakpoint chain. That would let us use set_raw_breakpoint. We could
8154 adjust the addresses each time they were needed. Doing this requires
8155 corresponding changes elsewhere where single step breakpoints are
8156 handled, however. So, for now, we use this. */
8158 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8159 if (*bpt_p == NULL)
8160 error (_("Could not insert single-step breakpoint at 0x%s"),
8161 paddr_nz (next_pc));
8164 /* Remove and delete any breakpoints used for software single step. */
8166 void
8167 remove_single_step_breakpoints (void)
8169 gdb_assert (single_step_breakpoints[0] != NULL);
8171 /* See insert_single_step_breakpoint for more about this deprecated
8172 call. */
8173 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8174 single_step_breakpoints[0] = NULL;
8176 if (single_step_breakpoints[1] != NULL)
8178 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8179 single_step_breakpoints[1] = NULL;
8183 /* Check whether a software single-step breakpoint is inserted at PC. */
8185 static int
8186 single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8188 int i;
8190 for (i = 0; i < 2; i++)
8192 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8193 if (bp_tgt && bp_tgt->placed_address == pc)
8194 return 1;
8197 return 0;
8201 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8202 It is defined as a macro to prevent duplication.
8203 COMMAND should be a string constant containing the name of the command. */
8204 #define BREAK_ARGS_HELP(command) \
8205 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8206 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8207 If a line number is specified, break at start of code for that line.\n\
8208 If a function is specified, break at start of code for that function.\n\
8209 If an address is specified, break at that exact address.\n\
8210 With no LOCATION, uses current execution address of selected stack frame.\n\
8211 This is useful for breaking on return to a stack frame.\n\
8213 THREADNUM is the number from \"info threads\".\n\
8214 CONDITION is a boolean expression.\n\
8216 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8218 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8220 void
8221 _initialize_breakpoint (void)
8223 static struct cmd_list_element *breakpoint_set_cmdlist;
8224 static struct cmd_list_element *breakpoint_show_cmdlist;
8225 struct cmd_list_element *c;
8227 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8229 breakpoint_chain = 0;
8230 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8231 before a breakpoint is set. */
8232 breakpoint_count = 0;
8234 add_com ("ignore", class_breakpoint, ignore_command, _("\
8235 Set ignore-count of breakpoint number N to COUNT.\n\
8236 Usage is `ignore N COUNT'."));
8237 if (xdb_commands)
8238 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8240 add_com ("commands", class_breakpoint, commands_command, _("\
8241 Set commands to be executed when a breakpoint is hit.\n\
8242 Give breakpoint number as argument after \"commands\".\n\
8243 With no argument, the targeted breakpoint is the last one set.\n\
8244 The commands themselves follow starting on the next line.\n\
8245 Type a line containing \"end\" to indicate the end of them.\n\
8246 Give \"silent\" as the first line to make the breakpoint silent;\n\
8247 then no output is printed when it is hit, except what the commands print."));
8249 add_com ("condition", class_breakpoint, condition_command, _("\
8250 Specify breakpoint number N to break only if COND is true.\n\
8251 Usage is `condition N COND', where N is an integer and COND is an\n\
8252 expression to be evaluated whenever breakpoint N is reached."));
8254 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8255 Set a temporary breakpoint.\n\
8256 Like \"break\" except the breakpoint is only temporary,\n\
8257 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8258 by using \"enable delete\" on the breakpoint number.\n\
8260 BREAK_ARGS_HELP ("tbreak")));
8261 set_cmd_completer (c, location_completer);
8263 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8264 Set a hardware assisted breakpoint.\n\
8265 Like \"break\" except the breakpoint requires hardware support,\n\
8266 some target hardware may not have this support.\n\
8268 BREAK_ARGS_HELP ("hbreak")));
8269 set_cmd_completer (c, location_completer);
8271 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8272 Set a temporary hardware assisted breakpoint.\n\
8273 Like \"hbreak\" except the breakpoint is only temporary,\n\
8274 so it will be deleted when hit.\n\
8276 BREAK_ARGS_HELP ("thbreak")));
8277 set_cmd_completer (c, location_completer);
8279 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8280 Enable some breakpoints.\n\
8281 Give breakpoint numbers (separated by spaces) as arguments.\n\
8282 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8283 This is used to cancel the effect of the \"disable\" command.\n\
8284 With a subcommand you can enable temporarily."),
8285 &enablelist, "enable ", 1, &cmdlist);
8286 if (xdb_commands)
8287 add_com ("ab", class_breakpoint, enable_command, _("\
8288 Enable some breakpoints.\n\
8289 Give breakpoint numbers (separated by spaces) as arguments.\n\
8290 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8291 This is used to cancel the effect of the \"disable\" command.\n\
8292 With a subcommand you can enable temporarily."));
8294 add_com_alias ("en", "enable", class_breakpoint, 1);
8296 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8297 Enable some breakpoints.\n\
8298 Give breakpoint numbers (separated by spaces) as arguments.\n\
8299 This is used to cancel the effect of the \"disable\" command.\n\
8300 May be abbreviated to simply \"enable\".\n"),
8301 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8303 add_cmd ("once", no_class, enable_once_command, _("\
8304 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8305 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8306 &enablebreaklist);
8308 add_cmd ("delete", no_class, enable_delete_command, _("\
8309 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8310 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8311 &enablebreaklist);
8313 add_cmd ("delete", no_class, enable_delete_command, _("\
8314 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8315 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8316 &enablelist);
8318 add_cmd ("once", no_class, enable_once_command, _("\
8319 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8320 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8321 &enablelist);
8323 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8324 Disable some breakpoints.\n\
8325 Arguments are breakpoint numbers with spaces in between.\n\
8326 To disable all breakpoints, give no argument.\n\
8327 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8328 &disablelist, "disable ", 1, &cmdlist);
8329 add_com_alias ("dis", "disable", class_breakpoint, 1);
8330 add_com_alias ("disa", "disable", class_breakpoint, 1);
8331 if (xdb_commands)
8332 add_com ("sb", class_breakpoint, disable_command, _("\
8333 Disable some breakpoints.\n\
8334 Arguments are breakpoint numbers with spaces in between.\n\
8335 To disable all breakpoints, give no argument.\n\
8336 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8338 add_cmd ("breakpoints", class_alias, disable_command, _("\
8339 Disable some breakpoints.\n\
8340 Arguments are breakpoint numbers with spaces in between.\n\
8341 To disable all breakpoints, give no argument.\n\
8342 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8343 This command may be abbreviated \"disable\"."),
8344 &disablelist);
8346 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8347 Delete some breakpoints or auto-display expressions.\n\
8348 Arguments are breakpoint numbers with spaces in between.\n\
8349 To delete all breakpoints, give no argument.\n\
8351 Also a prefix command for deletion of other GDB objects.\n\
8352 The \"unset\" command is also an alias for \"delete\"."),
8353 &deletelist, "delete ", 1, &cmdlist);
8354 add_com_alias ("d", "delete", class_breakpoint, 1);
8355 add_com_alias ("del", "delete", class_breakpoint, 1);
8356 if (xdb_commands)
8357 add_com ("db", class_breakpoint, delete_command, _("\
8358 Delete some breakpoints.\n\
8359 Arguments are breakpoint numbers with spaces in between.\n\
8360 To delete all breakpoints, give no argument.\n"));
8362 add_cmd ("breakpoints", class_alias, delete_command, _("\
8363 Delete some breakpoints or auto-display expressions.\n\
8364 Arguments are breakpoint numbers with spaces in between.\n\
8365 To delete all breakpoints, give no argument.\n\
8366 This command may be abbreviated \"delete\"."),
8367 &deletelist);
8369 add_com ("clear", class_breakpoint, clear_command, _("\
8370 Clear breakpoint at specified line or function.\n\
8371 Argument may be line number, function name, or \"*\" and an address.\n\
8372 If line number is specified, all breakpoints in that line are cleared.\n\
8373 If function is specified, breakpoints at beginning of function are cleared.\n\
8374 If an address is specified, breakpoints at that address are cleared.\n\
8376 With no argument, clears all breakpoints in the line that the selected frame\n\
8377 is executing in.\n\
8379 See also the \"delete\" command which clears breakpoints by number."));
8381 c = add_com ("break", class_breakpoint, break_command, _("\
8382 Set breakpoint at specified line or function.\n"
8383 BREAK_ARGS_HELP ("break")));
8384 set_cmd_completer (c, location_completer);
8386 add_com_alias ("b", "break", class_run, 1);
8387 add_com_alias ("br", "break", class_run, 1);
8388 add_com_alias ("bre", "break", class_run, 1);
8389 add_com_alias ("brea", "break", class_run, 1);
8391 if (xdb_commands)
8393 add_com_alias ("ba", "break", class_breakpoint, 1);
8394 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8397 if (dbx_commands)
8399 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8400 Break in function/address or break at a line in the current file."),
8401 &stoplist, "stop ", 1, &cmdlist);
8402 add_cmd ("in", class_breakpoint, stopin_command,
8403 _("Break in function or address."), &stoplist);
8404 add_cmd ("at", class_breakpoint, stopat_command,
8405 _("Break at a line in the current file."), &stoplist);
8406 add_com ("status", class_info, breakpoints_info, _("\
8407 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8408 The \"Type\" column indicates one of:\n\
8409 \tbreakpoint - normal breakpoint\n\
8410 \twatchpoint - watchpoint\n\
8411 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8412 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8413 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8414 address and file/line number respectively.\n\
8416 Convenience variable \"$_\" and default examine address for \"x\"\n\
8417 are set to the address of the last breakpoint listed unless the command\n\
8418 is prefixed with \"server \".\n\n\
8419 Convenience variable \"$bpnum\" contains the number of the last\n\
8420 breakpoint set."));
8423 add_info ("breakpoints", breakpoints_info, _("\
8424 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8425 The \"Type\" column indicates one of:\n\
8426 \tbreakpoint - normal breakpoint\n\
8427 \twatchpoint - watchpoint\n\
8428 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8429 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8430 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8431 address and file/line number respectively.\n\
8433 Convenience variable \"$_\" and default examine address for \"x\"\n\
8434 are set to the address of the last breakpoint listed unless the command\n\
8435 is prefixed with \"server \".\n\n\
8436 Convenience variable \"$bpnum\" contains the number of the last\n\
8437 breakpoint set."));
8439 if (xdb_commands)
8440 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8441 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8442 The \"Type\" column indicates one of:\n\
8443 \tbreakpoint - normal breakpoint\n\
8444 \twatchpoint - watchpoint\n\
8445 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8446 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8447 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8448 address and file/line number respectively.\n\
8450 Convenience variable \"$_\" and default examine address for \"x\"\n\
8451 are set to the address of the last breakpoint listed unless the command\n\
8452 is prefixed with \"server \".\n\n\
8453 Convenience variable \"$bpnum\" contains the number of the last\n\
8454 breakpoint set."));
8456 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8457 Status of all breakpoints, or breakpoint number NUMBER.\n\
8458 The \"Type\" column indicates one of:\n\
8459 \tbreakpoint - normal breakpoint\n\
8460 \twatchpoint - watchpoint\n\
8461 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8462 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8463 \tuntil - internal breakpoint used by the \"until\" command\n\
8464 \tfinish - internal breakpoint used by the \"finish\" command\n\
8465 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8466 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8467 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8468 address and file/line number respectively.\n\
8470 Convenience variable \"$_\" and default examine address for \"x\"\n\
8471 are set to the address of the last breakpoint listed unless the command\n\
8472 is prefixed with \"server \".\n\n\
8473 Convenience variable \"$bpnum\" contains the number of the last\n\
8474 breakpoint set."),
8475 &maintenanceinfolist);
8477 add_com ("catch", class_breakpoint, catch_command, _("\
8478 Set catchpoints to catch events.\n\
8479 Raised signals may be caught:\n\
8480 \tcatch signal - all signals\n\
8481 \tcatch signal <signame> - a particular signal\n\
8482 Raised exceptions may be caught:\n\
8483 \tcatch throw - all exceptions, when thrown\n\
8484 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8485 \tcatch catch - all exceptions, when caught\n\
8486 \tcatch catch <exceptname> - a particular exception, when caught\n\
8487 Thread or process events may be caught:\n\
8488 \tcatch thread_start - any threads, just after creation\n\
8489 \tcatch thread_exit - any threads, just before expiration\n\
8490 \tcatch thread_join - any threads, just after joins\n\
8491 Process events may be caught:\n\
8492 \tcatch start - any processes, just after creation\n\
8493 \tcatch exit - any processes, just before expiration\n\
8494 \tcatch fork - calls to fork()\n\
8495 \tcatch vfork - calls to vfork()\n\
8496 \tcatch exec - calls to exec()\n\
8497 Dynamically-linked library events may be caught:\n\
8498 \tcatch load - loads of any library\n\
8499 \tcatch load <libname> - loads of a particular library\n\
8500 \tcatch unload - unloads of any library\n\
8501 \tcatch unload <libname> - unloads of a particular library\n\
8502 The act of your program's execution stopping may also be caught:\n\
8503 \tcatch stop\n\n\
8504 C++ exceptions may be caught:\n\
8505 \tcatch throw - all exceptions, when thrown\n\
8506 \tcatch catch - all exceptions, when caught\n\
8507 Ada exceptions may be caught:\n\
8508 \tcatch exception - all exceptions, when raised\n\
8509 \tcatch exception <name> - a particular exception, when raised\n\
8510 \tcatch exception unhandled - all unhandled exceptions, when raised\n\
8511 \tcatch assert - all failed assertions, when raised\n\
8513 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8514 after a fork or vfork is caught.\n\n\
8515 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8517 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8518 Set temporary catchpoints to catch events.\n\
8519 Args like \"catch\" command.\n\
8520 Like \"catch\" except the catchpoint is only temporary,\n\
8521 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8522 by using \"enable delete\" on the catchpoint number."));
8524 c = add_com ("watch", class_breakpoint, watch_command, _("\
8525 Set a watchpoint for an expression.\n\
8526 A watchpoint stops execution of your program whenever the value of\n\
8527 an expression changes."));
8528 set_cmd_completer (c, location_completer);
8530 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8531 Set a read watchpoint for an expression.\n\
8532 A watchpoint stops execution of your program whenever the value of\n\
8533 an expression is read."));
8534 set_cmd_completer (c, location_completer);
8536 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8537 Set a watchpoint for an expression.\n\
8538 A watchpoint stops execution of your program whenever the value of\n\
8539 an expression is either read or written."));
8540 set_cmd_completer (c, location_completer);
8542 add_info ("watchpoints", breakpoints_info,
8543 _("Synonym for ``info breakpoints''."));
8546 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8547 respond to changes - contrary to the description. */
8548 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8549 &can_use_hw_watchpoints, _("\
8550 Set debugger's willingness to use watchpoint hardware."), _("\
8551 Show debugger's willingness to use watchpoint hardware."), _("\
8552 If zero, gdb will not use hardware for new watchpoints, even if\n\
8553 such is available. (However, any hardware watchpoints that were\n\
8554 created before setting this to nonzero, will continue to use watchpoint\n\
8555 hardware.)"),
8556 NULL,
8557 show_can_use_hw_watchpoints,
8558 &setlist, &showlist);
8560 can_use_hw_watchpoints = 1;
8562 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8563 Breakpoint specific settings\n\
8564 Configure various breakpoint-specific variables such as\n\
8565 pending breakpoint behavior"),
8566 &breakpoint_set_cmdlist, "set breakpoint ",
8567 0/*allow-unknown*/, &setlist);
8568 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8569 Breakpoint specific settings\n\
8570 Configure various breakpoint-specific variables such as\n\
8571 pending breakpoint behavior"),
8572 &breakpoint_show_cmdlist, "show breakpoint ",
8573 0/*allow-unknown*/, &showlist);
8575 add_setshow_auto_boolean_cmd ("pending", no_class,
8576 &pending_break_support, _("\
8577 Set debugger's behavior regarding pending breakpoints."), _("\
8578 Show debugger's behavior regarding pending breakpoints."), _("\
8579 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8580 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8581 an error. If auto, an unrecognized breakpoint location results in a\n\
8582 user-query to see if a pending breakpoint should be created."),
8583 NULL,
8584 show_pending_break_support,
8585 &breakpoint_set_cmdlist,
8586 &breakpoint_show_cmdlist);
8588 pending_break_support = AUTO_BOOLEAN_AUTO;
8590 add_setshow_boolean_cmd ("auto-hw", no_class,
8591 &automatic_hardware_breakpoints, _("\
8592 Set automatic usage of hardware breakpoints."), _("\
8593 Show automatic usage of hardware breakpoints."), _("\
8594 If set, the debugger will automatically use hardware breakpoints for\n\
8595 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8596 a warning will be emitted for such breakpoints."),
8597 NULL,
8598 show_automatic_hardware_breakpoints,
8599 &breakpoint_set_cmdlist,
8600 &breakpoint_show_cmdlist);
8602 automatic_hardware_breakpoints = 1;