* breakpoint.c (mark_breakpoints_out): Make public.
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
... / ...
CommitLineData
1/* Everything about breakpoints, for GDB.
2
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 2008 Free Software Foundation, Inc.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22#include "defs.h"
23#include <ctype.h>
24#include "hashtab.h"
25#include "symtab.h"
26#include "frame.h"
27#include "breakpoint.h"
28#include "gdbtypes.h"
29#include "expression.h"
30#include "gdbcore.h"
31#include "gdbcmd.h"
32#include "value.h"
33#include "command.h"
34#include "inferior.h"
35#include "gdbthread.h"
36#include "target.h"
37#include "language.h"
38#include "gdb_string.h"
39#include "demangle.h"
40#include "annotate.h"
41#include "symfile.h"
42#include "objfiles.h"
43#include "source.h"
44#include "linespec.h"
45#include "completer.h"
46#include "gdb.h"
47#include "ui-out.h"
48#include "cli/cli-script.h"
49#include "gdb_assert.h"
50#include "block.h"
51#include "solib.h"
52#include "solist.h"
53#include "observer.h"
54#include "exceptions.h"
55#include "memattr.h"
56#include "ada-lang.h"
57#include "top.h"
58#include "wrapper.h"
59
60#include "gdb-events.h"
61#include "mi/mi-common.h"
62
63/* Prototypes for local functions. */
64
65static void until_break_command_continuation (struct continuation_arg *arg,
66 int error);
67
68static void catch_command_1 (char *, int, int);
69
70static void enable_delete_command (char *, int);
71
72static void enable_delete_breakpoint (struct breakpoint *);
73
74static void enable_once_command (char *, int);
75
76static void enable_once_breakpoint (struct breakpoint *);
77
78static void disable_command (char *, int);
79
80static void enable_command (char *, int);
81
82static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
83
84static void ignore_command (char *, int);
85
86static int breakpoint_re_set_one (void *);
87
88static void clear_command (char *, int);
89
90static void catch_command (char *, int);
91
92static void watch_command (char *, int);
93
94static int can_use_hardware_watchpoint (struct value *);
95
96static void break_command_1 (char *, int, int);
97
98static void mention (struct breakpoint *);
99
100struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
101
102static void check_duplicates (struct breakpoint *);
103
104static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
105
106static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
107 enum bptype bptype);
108
109static void describe_other_breakpoints (CORE_ADDR, asection *, int);
110
111static void breakpoints_info (char *, int);
112
113static void breakpoint_1 (int, int);
114
115static bpstat bpstat_alloc (const struct bp_location *, bpstat);
116
117static int breakpoint_cond_eval (void *);
118
119static void cleanup_executing_breakpoints (void *);
120
121static void commands_command (char *, int);
122
123static void condition_command (char *, int);
124
125static int get_number_trailer (char **, int);
126
127void set_breakpoint_count (int);
128
129typedef enum
130 {
131 mark_inserted,
132 mark_uninserted
133 }
134insertion_state_t;
135
136static int remove_breakpoint (struct bp_location *, insertion_state_t);
137
138static enum print_stop_action print_it_typical (bpstat);
139
140static enum print_stop_action print_bp_stop_message (bpstat bs);
141
142static int watchpoint_check (void *);
143
144static void maintenance_info_breakpoints (char *, int);
145
146static void create_overlay_event_breakpoint (char *);
147
148static int hw_breakpoint_used_count (void);
149
150static int hw_watchpoint_used_count (enum bptype, int *);
151
152static void hbreak_command (char *, int);
153
154static void thbreak_command (char *, int);
155
156static void watch_command_1 (char *, int, int);
157
158static void rwatch_command (char *, int);
159
160static void awatch_command (char *, int);
161
162static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
163
164static void create_fork_vfork_event_catchpoint (int tempflag,
165 char *cond_string,
166 enum bptype bp_kind);
167
168static void stop_command (char *arg, int from_tty);
169
170static void stopin_command (char *arg, int from_tty);
171
172static void stopat_command (char *arg, int from_tty);
173
174static char *ep_find_event_name_end (char *arg);
175
176static char *ep_parse_optional_if_clause (char **arg);
177
178static char *ep_parse_optional_filename (char **arg);
179
180static void catch_exception_command_1 (enum exception_event_kind ex_event,
181 char *arg, int tempflag, int from_tty);
182
183static void tcatch_command (char *arg, int from_tty);
184
185static void ep_skip_leading_whitespace (char **s);
186
187static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc);
188
189static void free_bp_location (struct bp_location *loc);
190
191static struct bp_location *
192allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type);
193
194static void update_global_location_list (void);
195
196static void update_global_location_list_nothrow (void);
197
198static int is_hardware_watchpoint (struct breakpoint *bpt);
199
200static void insert_breakpoint_locations (void);
201
202static const char *
203bpdisp_text (enum bpdisp disp)
204{
205 /* NOTE: the following values are a part of MI protocol and represent
206 values of 'disp' field returned when inferior stops at a breakpoint. */
207 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
208 return bpdisps[(int) disp];
209}
210
211/* Prototypes for exported functions. */
212/* If FALSE, gdb will not use hardware support for watchpoints, even
213 if such is available. */
214static int can_use_hw_watchpoints;
215
216static void
217show_can_use_hw_watchpoints (struct ui_file *file, int from_tty,
218 struct cmd_list_element *c,
219 const char *value)
220{
221 fprintf_filtered (file, _("\
222Debugger's willingness to use watchpoint hardware is %s.\n"),
223 value);
224}
225
226/* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
227 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
228 for unrecognized breakpoint locations.
229 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
230static enum auto_boolean pending_break_support;
231static void
232show_pending_break_support (struct ui_file *file, int from_tty,
233 struct cmd_list_element *c,
234 const char *value)
235{
236 fprintf_filtered (file, _("\
237Debugger's behavior regarding pending breakpoints is %s.\n"),
238 value);
239}
240
241/* If 1, gdb will automatically use hardware breakpoints for breakpoints
242 set with "break" but falling in read-only memory.
243 If 0, gdb will warn about such breakpoints, but won't automatically
244 use hardware breakpoints. */
245static int automatic_hardware_breakpoints;
246static void
247show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty,
248 struct cmd_list_element *c,
249 const char *value)
250{
251 fprintf_filtered (file, _("\
252Automatic usage of hardware breakpoints is %s.\n"),
253 value);
254}
255
256/* If 1, gdb will keep breakpoints inserted even as inferior is stopped,
257 and immediately insert any new breakpoints. If 0, gdb will insert
258 breakpoints into inferior only when resuming it, and will remove
259 breakpoints upon stop. */
260static int always_inserted_mode = 0;
261static void
262show_always_inserted_mode (struct ui_file *file, int from_tty,
263 struct cmd_list_element *c, const char *value)
264{
265 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value);
266}
267
268
269void _initialize_breakpoint (void);
270
271extern int addressprint; /* Print machine addresses? */
272
273/* Are we executing breakpoint commands? */
274static int executing_breakpoint_commands;
275
276/* Are overlay event breakpoints enabled? */
277static int overlay_events_enabled;
278
279/* Walk the following statement or block through all breakpoints.
280 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
281 breakpoint. */
282
283#define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
284
285#define ALL_BREAKPOINTS_SAFE(B,TMP) \
286 for (B = breakpoint_chain; \
287 B ? (TMP=B->next, 1): 0; \
288 B = TMP)
289
290/* Similar iterators for the low-level breakpoints. */
291
292#define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
293
294#define ALL_BP_LOCATIONS_SAFE(B,TMP) \
295 for (B = bp_location_chain; \
296 B ? (TMP=B->global_next, 1): 0; \
297 B = TMP)
298
299/* True if breakpoint hit counts should be displayed in breakpoint info. */
300
301int show_breakpoint_hit_counts = 1;
302
303/* Chains of all breakpoints defined. */
304
305struct breakpoint *breakpoint_chain;
306
307struct bp_location *bp_location_chain;
308
309/* The locations that no longer correspond to any breakpoint,
310 unlinked from bp_location_chain, but for which a hit
311 may still be reported by a target. */
312VEC(bp_location_p) *moribund_locations = NULL;
313
314/* Number of last breakpoint made. */
315
316int breakpoint_count;
317
318/* This function returns a pointer to the string representation of the
319 pathname of the dynamically-linked library that has just been
320 loaded.
321
322 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
323 or undefined results are guaranteed.
324
325 This string's contents are only valid immediately after the
326 inferior has stopped in the dynamic linker hook, and becomes
327 invalid as soon as the inferior is continued. Clients should make
328 a copy of this string if they wish to continue the inferior and
329 then access the string. */
330
331#ifndef SOLIB_LOADED_LIBRARY_PATHNAME
332#define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
333#endif
334
335/* This function returns a pointer to the string representation of the
336 pathname of the dynamically-linked library that has just been
337 unloaded.
338
339 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
340 TRUE, or undefined results are guaranteed.
341
342 This string's contents are only valid immediately after the
343 inferior has stopped in the dynamic linker hook, and becomes
344 invalid as soon as the inferior is continued. Clients should make
345 a copy of this string if they wish to continue the inferior and
346 then access the string. */
347
348#ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
349#define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
350#endif
351
352/* This function is called by the "catch load" command. It allows the
353 debugger to be notified by the dynamic linker when a specified
354 library file (or any library file, if filename is NULL) is loaded. */
355
356#ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
357#define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
358 error (_("catch of library loads not yet implemented on this platform"))
359#endif
360
361/* This function is called by the "catch unload" command. It allows
362 the debugger to be notified by the dynamic linker when a specified
363 library file (or any library file, if filename is NULL) is
364 unloaded. */
365
366#ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
367#define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
368 error (_("catch of library unloads not yet implemented on this platform"))
369#endif
370
371/* Return whether a breakpoint is an active enabled breakpoint. */
372static int
373breakpoint_enabled (struct breakpoint *b)
374{
375 return (b->enable_state == bp_enabled);
376}
377
378/* Set breakpoint count to NUM. */
379
380void
381set_breakpoint_count (int num)
382{
383 breakpoint_count = num;
384 set_internalvar (lookup_internalvar ("bpnum"),
385 value_from_longest (builtin_type_int, (LONGEST) num));
386}
387
388/* Used in run_command to zero the hit count when a new run starts. */
389
390void
391clear_breakpoint_hit_counts (void)
392{
393 struct breakpoint *b;
394
395 ALL_BREAKPOINTS (b)
396 b->hit_count = 0;
397}
398
399/* Default address, symtab and line to put a breakpoint at
400 for "break" command with no arg.
401 if default_breakpoint_valid is zero, the other three are
402 not valid, and "break" with no arg is an error.
403
404 This set by print_stack_frame, which calls set_default_breakpoint. */
405
406int default_breakpoint_valid;
407CORE_ADDR default_breakpoint_address;
408struct symtab *default_breakpoint_symtab;
409int default_breakpoint_line;
410\f
411/* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
412 Advance *PP after the string and any trailing whitespace.
413
414 Currently the string can either be a number or "$" followed by the name
415 of a convenience variable. Making it an expression wouldn't work well
416 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
417
418 If the string is a NULL pointer, that denotes the last breakpoint.
419
420 TRAILER is a character which can be found after the number; most
421 commonly this is `-'. If you don't want a trailer, use \0. */
422static int
423get_number_trailer (char **pp, int trailer)
424{
425 int retval = 0; /* default */
426 char *p = *pp;
427
428 if (p == NULL)
429 /* Empty line means refer to the last breakpoint. */
430 return breakpoint_count;
431 else if (*p == '$')
432 {
433 /* Make a copy of the name, so we can null-terminate it
434 to pass to lookup_internalvar(). */
435 char *varname;
436 char *start = ++p;
437 struct value *val;
438
439 while (isalnum (*p) || *p == '_')
440 p++;
441 varname = (char *) alloca (p - start + 1);
442 strncpy (varname, start, p - start);
443 varname[p - start] = '\0';
444 val = value_of_internalvar (lookup_internalvar (varname));
445 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
446 retval = (int) value_as_long (val);
447 else
448 {
449 printf_filtered (_("Convenience variable must have integer value.\n"));
450 retval = 0;
451 }
452 }
453 else
454 {
455 if (*p == '-')
456 ++p;
457 while (*p >= '0' && *p <= '9')
458 ++p;
459 if (p == *pp)
460 /* There is no number here. (e.g. "cond a == b"). */
461 {
462 /* Skip non-numeric token */
463 while (*p && !isspace((int) *p))
464 ++p;
465 /* Return zero, which caller must interpret as error. */
466 retval = 0;
467 }
468 else
469 retval = atoi (*pp);
470 }
471 if (!(isspace (*p) || *p == '\0' || *p == trailer))
472 {
473 /* Trailing junk: return 0 and let caller print error msg. */
474 while (!(isspace (*p) || *p == '\0' || *p == trailer))
475 ++p;
476 retval = 0;
477 }
478 while (isspace (*p))
479 p++;
480 *pp = p;
481 return retval;
482}
483
484
485/* Like get_number_trailer, but don't allow a trailer. */
486int
487get_number (char **pp)
488{
489 return get_number_trailer (pp, '\0');
490}
491
492/* Parse a number or a range.
493 * A number will be of the form handled by get_number.
494 * A range will be of the form <number1> - <number2>, and
495 * will represent all the integers between number1 and number2,
496 * inclusive.
497 *
498 * While processing a range, this fuction is called iteratively;
499 * At each call it will return the next value in the range.
500 *
501 * At the beginning of parsing a range, the char pointer PP will
502 * be advanced past <number1> and left pointing at the '-' token.
503 * Subsequent calls will not advance the pointer until the range
504 * is completed. The call that completes the range will advance
505 * pointer PP past <number2>.
506 */
507
508int
509get_number_or_range (char **pp)
510{
511 static int last_retval, end_value;
512 static char *end_ptr;
513 static int in_range = 0;
514
515 if (**pp != '-')
516 {
517 /* Default case: pp is pointing either to a solo number,
518 or to the first number of a range. */
519 last_retval = get_number_trailer (pp, '-');
520 if (**pp == '-')
521 {
522 char **temp;
523
524 /* This is the start of a range (<number1> - <number2>).
525 Skip the '-', parse and remember the second number,
526 and also remember the end of the final token. */
527
528 temp = &end_ptr;
529 end_ptr = *pp + 1;
530 while (isspace ((int) *end_ptr))
531 end_ptr++; /* skip white space */
532 end_value = get_number (temp);
533 if (end_value < last_retval)
534 {
535 error (_("inverted range"));
536 }
537 else if (end_value == last_retval)
538 {
539 /* degenerate range (number1 == number2). Advance the
540 token pointer so that the range will be treated as a
541 single number. */
542 *pp = end_ptr;
543 }
544 else
545 in_range = 1;
546 }
547 }
548 else if (! in_range)
549 error (_("negative value"));
550 else
551 {
552 /* pp points to the '-' that betokens a range. All
553 number-parsing has already been done. Return the next
554 integer value (one greater than the saved previous value).
555 Do not advance the token pointer 'pp' until the end of range
556 is reached. */
557
558 if (++last_retval == end_value)
559 {
560 /* End of range reached; advance token pointer. */
561 *pp = end_ptr;
562 in_range = 0;
563 }
564 }
565 return last_retval;
566}
567
568
569\f
570/* condition N EXP -- set break condition of breakpoint N to EXP. */
571
572static void
573condition_command (char *arg, int from_tty)
574{
575 struct breakpoint *b;
576 char *p;
577 int bnum;
578
579 if (arg == 0)
580 error_no_arg (_("breakpoint number"));
581
582 p = arg;
583 bnum = get_number (&p);
584 if (bnum == 0)
585 error (_("Bad breakpoint argument: '%s'"), arg);
586
587 ALL_BREAKPOINTS (b)
588 if (b->number == bnum)
589 {
590 struct bp_location *loc = b->loc;
591 for (; loc; loc = loc->next)
592 {
593 if (loc->cond)
594 {
595 xfree (loc->cond);
596 loc->cond = 0;
597 }
598 }
599 if (b->cond_string != NULL)
600 xfree (b->cond_string);
601
602 if (*p == 0)
603 {
604 b->cond_string = NULL;
605 if (from_tty)
606 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
607 }
608 else
609 {
610 arg = p;
611 /* I don't know if it matters whether this is the string the user
612 typed in or the decompiled expression. */
613 b->cond_string = savestring (arg, strlen (arg));
614 b->condition_not_parsed = 0;
615 for (loc = b->loc; loc; loc = loc->next)
616 {
617 arg = p;
618 loc->cond =
619 parse_exp_1 (&arg, block_for_pc (loc->address), 0);
620 if (*arg)
621 error (_("Junk at end of expression"));
622 }
623 }
624 breakpoints_changed ();
625 breakpoint_modify_event (b->number);
626 return;
627 }
628
629 error (_("No breakpoint number %d."), bnum);
630}
631
632static void
633commands_command (char *arg, int from_tty)
634{
635 struct breakpoint *b;
636 char *p;
637 int bnum;
638 struct command_line *l;
639
640 /* If we allowed this, we would have problems with when to
641 free the storage, if we change the commands currently
642 being read from. */
643
644 if (executing_breakpoint_commands)
645 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
646
647 p = arg;
648 bnum = get_number (&p);
649
650 if (p && *p)
651 error (_("Unexpected extra arguments following breakpoint number."));
652
653 ALL_BREAKPOINTS (b)
654 if (b->number == bnum)
655 {
656 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
657 bnum);
658 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
659 l = read_command_lines (tmpbuf, from_tty);
660 do_cleanups (cleanups);
661 free_command_lines (&b->commands);
662 b->commands = l;
663 breakpoints_changed ();
664 breakpoint_modify_event (b->number);
665 return;
666 }
667 error (_("No breakpoint number %d."), bnum);
668}
669
670/* Like commands_command, but instead of reading the commands from
671 input stream, takes them from an already parsed command structure.
672
673 This is used by cli-script.c to DTRT with breakpoint commands
674 that are part of if and while bodies. */
675enum command_control_type
676commands_from_control_command (char *arg, struct command_line *cmd)
677{
678 struct breakpoint *b;
679 char *p;
680 int bnum;
681
682 /* If we allowed this, we would have problems with when to
683 free the storage, if we change the commands currently
684 being read from. */
685
686 if (executing_breakpoint_commands)
687 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
688
689 /* An empty string for the breakpoint number means the last
690 breakpoint, but get_number expects a NULL pointer. */
691 if (arg && !*arg)
692 p = NULL;
693 else
694 p = arg;
695 bnum = get_number (&p);
696
697 if (p && *p)
698 error (_("Unexpected extra arguments following breakpoint number."));
699
700 ALL_BREAKPOINTS (b)
701 if (b->number == bnum)
702 {
703 free_command_lines (&b->commands);
704 if (cmd->body_count != 1)
705 error (_("Invalid \"commands\" block structure."));
706 /* We need to copy the commands because if/while will free the
707 list after it finishes execution. */
708 b->commands = copy_command_lines (cmd->body_list[0]);
709 breakpoints_changed ();
710 breakpoint_modify_event (b->number);
711 return simple_control;
712 }
713 error (_("No breakpoint number %d."), bnum);
714}
715\f
716/* Update BUF, which is LEN bytes read from the target address MEMADDR,
717 by replacing any memory breakpoints with their shadowed contents. */
718
719void
720breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
721{
722 struct bp_location *b;
723 CORE_ADDR bp_addr = 0;
724 int bp_size = 0;
725 int bptoffset = 0;
726
727 ALL_BP_LOCATIONS (b)
728 {
729 if (b->owner->type == bp_none)
730 warning (_("reading through apparently deleted breakpoint #%d?"),
731 b->owner->number);
732
733 if (b->loc_type != bp_loc_software_breakpoint)
734 continue;
735 if (!b->inserted)
736 continue;
737 /* Addresses and length of the part of the breakpoint that
738 we need to copy. */
739 bp_addr = b->target_info.placed_address;
740 bp_size = b->target_info.shadow_len;
741 if (bp_size == 0)
742 /* bp isn't valid, or doesn't shadow memory. */
743 continue;
744
745 if (bp_addr + bp_size <= memaddr)
746 /* The breakpoint is entirely before the chunk of memory we
747 are reading. */
748 continue;
749
750 if (bp_addr >= memaddr + len)
751 /* The breakpoint is entirely after the chunk of memory we are
752 reading. */
753 continue;
754
755 /* Offset within shadow_contents. */
756 if (bp_addr < memaddr)
757 {
758 /* Only copy the second part of the breakpoint. */
759 bp_size -= memaddr - bp_addr;
760 bptoffset = memaddr - bp_addr;
761 bp_addr = memaddr;
762 }
763
764 if (bp_addr + bp_size > memaddr + len)
765 {
766 /* Only copy the first part of the breakpoint. */
767 bp_size -= (bp_addr + bp_size) - (memaddr + len);
768 }
769
770 memcpy (buf + bp_addr - memaddr,
771 b->target_info.shadow_contents + bptoffset, bp_size);
772 }
773}
774\f
775
776/* A wrapper function for inserting catchpoints. */
777static void
778insert_catchpoint (struct ui_out *uo, void *args)
779{
780 struct breakpoint *b = (struct breakpoint *) args;
781 int val = -1;
782
783 switch (b->type)
784 {
785 case bp_catch_fork:
786 target_insert_fork_catchpoint (PIDGET (inferior_ptid));
787 break;
788 case bp_catch_vfork:
789 target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
790 break;
791 case bp_catch_exec:
792 target_insert_exec_catchpoint (PIDGET (inferior_ptid));
793 break;
794 default:
795 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
796 break;
797 }
798}
799
800static int
801is_hardware_watchpoint (struct breakpoint *bpt)
802{
803 return (bpt->type == bp_hardware_watchpoint
804 || bpt->type == bp_read_watchpoint
805 || bpt->type == bp_access_watchpoint);
806}
807
808/* Find the current value of a watchpoint on EXP. Return the value in
809 *VALP and *RESULTP and the chain of intermediate and final values
810 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
811 not need them.
812
813 If an error occurs while evaluating the expression, *RESULTP will
814 be set to NULL. *RESULTP may be a lazy value, if the result could
815 not be read from memory. It is used to determine whether a value
816 is user-specified (we should watch the whole value) or intermediate
817 (we should watch only the bit used to locate the final value).
818
819 If the final value, or any intermediate value, could not be read
820 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
821 set to any referenced values. *VALP will never be a lazy value.
822 This is the value which we store in struct breakpoint.
823
824 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
825 value chain. The caller must free the values individually. If
826 VAL_CHAIN is NULL, all generated values will be left on the value
827 chain. */
828
829static void
830fetch_watchpoint_value (struct expression *exp, struct value **valp,
831 struct value **resultp, struct value **val_chain)
832{
833 struct value *mark, *new_mark, *result;
834
835 *valp = NULL;
836 if (resultp)
837 *resultp = NULL;
838 if (val_chain)
839 *val_chain = NULL;
840
841 /* Evaluate the expression. */
842 mark = value_mark ();
843 result = NULL;
844 gdb_evaluate_expression (exp, &result);
845 new_mark = value_mark ();
846 if (mark == new_mark)
847 return;
848 if (resultp)
849 *resultp = result;
850
851 /* Make sure it's not lazy, so that after the target stops again we
852 have a non-lazy previous value to compare with. */
853 if (result != NULL
854 && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
855 *valp = result;
856
857 if (val_chain)
858 {
859 /* Return the chain of intermediate values. We use this to
860 decide which addresses to watch. */
861 *val_chain = new_mark;
862 value_release_to_mark (mark);
863 }
864}
865
866/* Assuming that B is a hardware watchpoint:
867 - Reparse watchpoint expression, is REPARSE is non-zero
868 - Evaluate expression and store the result in B->val
869 - Update the list of values that must be watched in B->loc.
870
871 If the watchpoint is disabled, do nothing. If this is
872 local watchpoint that is out of scope, delete it. */
873static void
874update_watchpoint (struct breakpoint *b, int reparse)
875{
876 int within_current_scope;
877 struct frame_id saved_frame_id;
878 struct bp_location *loc;
879 bpstat bs;
880
881 /* We don't free locations. They are stored in
882 bp_location_chain and update_global_locations will
883 eventually delete them and remove breakpoints if
884 needed. */
885 b->loc = NULL;
886
887 if (b->disposition == disp_del_at_next_stop)
888 return;
889
890 /* Save the current frame's ID so we can restore it after
891 evaluating the watchpoint expression on its own frame. */
892 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
893 took a frame parameter, so that we didn't have to change the
894 selected frame. */
895 saved_frame_id = get_frame_id (get_selected_frame (NULL));
896
897 /* Determine if the watchpoint is within scope. */
898 if (b->exp_valid_block == NULL)
899 within_current_scope = 1;
900 else
901 {
902 struct frame_info *fi;
903 fi = frame_find_by_id (b->watchpoint_frame);
904 within_current_scope = (fi != NULL);
905 if (within_current_scope)
906 select_frame (fi);
907 }
908
909 if (within_current_scope && reparse)
910 {
911 char *s;
912 if (b->exp)
913 {
914 xfree (b->exp);
915 b->exp = NULL;
916 }
917 s = b->exp_string;
918 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0);
919 /* If the meaning of expression itself changed, the old value is
920 no longer relevant. We don't want to report a watchpoint hit
921 to the user when the old value and the new value may actually
922 be completely different objects. */
923 value_free (b->val);
924 b->val = NULL;
925 b->val_valid = 0;
926 }
927
928 /* If we failed to parse the expression, for example because
929 it refers to a global variable in a not-yet-loaded shared library,
930 don't try to insert watchpoint. We don't automatically delete
931 such watchpoint, though, since failure to parse expression
932 is different from out-of-scope watchpoint. */
933 if (within_current_scope && b->exp)
934 {
935 struct value *val_chain, *v, *result, *next;
936
937 fetch_watchpoint_value (b->exp, &v, &result, &val_chain);
938
939 /* Avoid setting b->val if it's already set. The meaning of
940 b->val is 'the last value' user saw, and we should update
941 it only if we reported that last value to user. As it
942 happens, the code that reports it updates b->val directly. */
943 if (!b->val_valid)
944 {
945 b->val = v;
946 b->val_valid = 1;
947 }
948
949 /* Look at each value on the value chain. */
950 for (v = val_chain; v; v = next)
951 {
952 /* If it's a memory location, and GDB actually needed
953 its contents to evaluate the expression, then we
954 must watch it. If the first value returned is
955 still lazy, that means an error occurred reading it;
956 watch it anyway in case it becomes readable. */
957 if (VALUE_LVAL (v) == lval_memory
958 && (v == val_chain || ! value_lazy (v)))
959 {
960 struct type *vtype = check_typedef (value_type (v));
961
962 /* We only watch structs and arrays if user asked
963 for it explicitly, never if they just happen to
964 appear in the middle of some value chain. */
965 if (v == result
966 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
967 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
968 {
969 CORE_ADDR addr;
970 int len, type;
971 struct bp_location *loc, **tmp;
972
973 addr = VALUE_ADDRESS (v) + value_offset (v);
974 len = TYPE_LENGTH (value_type (v));
975 type = hw_write;
976 if (b->type == bp_read_watchpoint)
977 type = hw_read;
978 else if (b->type == bp_access_watchpoint)
979 type = hw_access;
980
981 loc = allocate_bp_location (b, bp_hardware_watchpoint);
982 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
983 ;
984 *tmp = loc;
985 loc->address = addr;
986 loc->length = len;
987 loc->watchpoint_type = type;
988 }
989 }
990
991 next = value_next (v);
992 if (v != b->val)
993 value_free (v);
994 }
995
996 /* We just regenerated the list of breakpoint locations.
997 The new location does not have its condition field set to anything
998 and therefore, we must always reparse the cond_string, independently
999 of the value of the reparse flag. */
1000 if (b->cond_string != NULL)
1001 {
1002 char *s = b->cond_string;
1003 b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0);
1004 }
1005 }
1006 else if (!within_current_scope)
1007 {
1008 printf_filtered (_("\
1009Hardware watchpoint %d deleted because the program has left the block \n\
1010in which its expression is valid.\n"),
1011 b->number);
1012 if (b->related_breakpoint)
1013 b->related_breakpoint->disposition = disp_del_at_next_stop;
1014 b->disposition = disp_del_at_next_stop;
1015 }
1016
1017 /* Restore the selected frame. */
1018 select_frame (frame_find_by_id (saved_frame_id));
1019}
1020
1021
1022/* Returns 1 iff breakpoint location should be
1023 inserted in the inferior. */
1024static int
1025should_be_inserted (struct bp_location *bpt)
1026{
1027 if (!breakpoint_enabled (bpt->owner))
1028 return 0;
1029
1030 if (bpt->owner->disposition == disp_del_at_next_stop)
1031 return 0;
1032
1033 if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate)
1034 return 0;
1035
1036 return 1;
1037}
1038
1039/* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1040 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1041 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1042
1043 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1044 method for each breakpoint or catchpoint type. */
1045static int
1046insert_bp_location (struct bp_location *bpt,
1047 struct ui_file *tmp_error_stream,
1048 int *disabled_breaks, int *process_warning,
1049 int *hw_breakpoint_error)
1050{
1051 int val = 0;
1052
1053 if (!should_be_inserted (bpt) || bpt->inserted)
1054 return 0;
1055
1056 /* Initialize the target-specific information. */
1057 memset (&bpt->target_info, 0, sizeof (bpt->target_info));
1058 bpt->target_info.placed_address = bpt->address;
1059
1060 if (bpt->loc_type == bp_loc_software_breakpoint
1061 || bpt->loc_type == bp_loc_hardware_breakpoint)
1062 {
1063 if (bpt->owner->type != bp_hardware_breakpoint)
1064 {
1065 /* If the explicitly specified breakpoint type
1066 is not hardware breakpoint, check the memory map to see
1067 if the breakpoint address is in read only memory or not.
1068 Two important cases are:
1069 - location type is not hardware breakpoint, memory
1070 is readonly. We change the type of the location to
1071 hardware breakpoint.
1072 - location type is hardware breakpoint, memory is read-write.
1073 This means we've previously made the location hardware one, but
1074 then the memory map changed, so we undo.
1075
1076 When breakpoints are removed, remove_breakpoints will
1077 use location types we've just set here, the only possible
1078 problem is that memory map has changed during running program,
1079 but it's not going to work anyway with current gdb. */
1080 struct mem_region *mr
1081 = lookup_mem_region (bpt->target_info.placed_address);
1082
1083 if (mr)
1084 {
1085 if (automatic_hardware_breakpoints)
1086 {
1087 int changed = 0;
1088 enum bp_loc_type new_type;
1089
1090 if (mr->attrib.mode != MEM_RW)
1091 new_type = bp_loc_hardware_breakpoint;
1092 else
1093 new_type = bp_loc_software_breakpoint;
1094
1095 if (new_type != bpt->loc_type)
1096 {
1097 static int said = 0;
1098 bpt->loc_type = new_type;
1099 if (!said)
1100 {
1101 fprintf_filtered (gdb_stdout, _("\
1102Note: automatically using hardware breakpoints for read-only addresses.\n"));
1103 said = 1;
1104 }
1105 }
1106 }
1107 else if (bpt->loc_type == bp_loc_software_breakpoint
1108 && mr->attrib.mode != MEM_RW)
1109 warning (_("cannot set software breakpoint at readonly address %s"),
1110 paddr (bpt->address));
1111 }
1112 }
1113
1114 /* First check to see if we have to handle an overlay. */
1115 if (overlay_debugging == ovly_off
1116 || bpt->section == NULL
1117 || !(section_is_overlay (bpt->section)))
1118 {
1119 /* No overlay handling: just set the breakpoint. */
1120
1121 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1122 val = target_insert_hw_breakpoint (&bpt->target_info);
1123 else
1124 val = target_insert_breakpoint (&bpt->target_info);
1125 }
1126 else
1127 {
1128 /* This breakpoint is in an overlay section.
1129 Shall we set a breakpoint at the LMA? */
1130 if (!overlay_events_enabled)
1131 {
1132 /* Yes -- overlay event support is not active,
1133 so we must try to set a breakpoint at the LMA.
1134 This will not work for a hardware breakpoint. */
1135 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1136 warning (_("hardware breakpoint %d not supported in overlay!"),
1137 bpt->owner->number);
1138 else
1139 {
1140 CORE_ADDR addr = overlay_unmapped_address (bpt->address,
1141 bpt->section);
1142 /* Set a software (trap) breakpoint at the LMA. */
1143 bpt->overlay_target_info = bpt->target_info;
1144 bpt->overlay_target_info.placed_address = addr;
1145 val = target_insert_breakpoint (&bpt->overlay_target_info);
1146 if (val != 0)
1147 fprintf_unfiltered (tmp_error_stream,
1148 "Overlay breakpoint %d failed: in ROM?",
1149 bpt->owner->number);
1150 }
1151 }
1152 /* Shall we set a breakpoint at the VMA? */
1153 if (section_is_mapped (bpt->section))
1154 {
1155 /* Yes. This overlay section is mapped into memory. */
1156 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1157 val = target_insert_hw_breakpoint (&bpt->target_info);
1158 else
1159 val = target_insert_breakpoint (&bpt->target_info);
1160 }
1161 else
1162 {
1163 /* No. This breakpoint will not be inserted.
1164 No error, but do not mark the bp as 'inserted'. */
1165 return 0;
1166 }
1167 }
1168
1169 if (val)
1170 {
1171 /* Can't set the breakpoint. */
1172 if (solib_address (bpt->address))
1173 {
1174 /* See also: disable_breakpoints_in_shlibs. */
1175 val = 0;
1176 bpt->shlib_disabled = 1;
1177 if (!*disabled_breaks)
1178 {
1179 fprintf_unfiltered (tmp_error_stream,
1180 "Cannot insert breakpoint %d.\n",
1181 bpt->owner->number);
1182 fprintf_unfiltered (tmp_error_stream,
1183 "Temporarily disabling shared library breakpoints:\n");
1184 }
1185 *disabled_breaks = 1;
1186 fprintf_unfiltered (tmp_error_stream,
1187 "breakpoint #%d\n", bpt->owner->number);
1188 }
1189 else
1190 {
1191#ifdef ONE_PROCESS_WRITETEXT
1192 *process_warning = 1;
1193#endif
1194 if (bpt->loc_type == bp_loc_hardware_breakpoint)
1195 {
1196 *hw_breakpoint_error = 1;
1197 fprintf_unfiltered (tmp_error_stream,
1198 "Cannot insert hardware breakpoint %d.\n",
1199 bpt->owner->number);
1200 }
1201 else
1202 {
1203 fprintf_unfiltered (tmp_error_stream,
1204 "Cannot insert breakpoint %d.\n",
1205 bpt->owner->number);
1206 fprintf_filtered (tmp_error_stream,
1207 "Error accessing memory address ");
1208 fputs_filtered (paddress (bpt->address), tmp_error_stream);
1209 fprintf_filtered (tmp_error_stream, ": %s.\n",
1210 safe_strerror (val));
1211 }
1212
1213 }
1214 }
1215 else
1216 bpt->inserted = 1;
1217
1218 return val;
1219 }
1220
1221 else if (bpt->loc_type == bp_loc_hardware_watchpoint
1222 /* NOTE drow/2003-09-08: This state only exists for removing
1223 watchpoints. It's not clear that it's necessary... */
1224 && bpt->owner->disposition != disp_del_at_next_stop)
1225 {
1226 val = target_insert_watchpoint (bpt->address,
1227 bpt->length,
1228 bpt->watchpoint_type);
1229 bpt->inserted = (val != -1);
1230 }
1231
1232 else if (bpt->owner->type == bp_catch_fork
1233 || bpt->owner->type == bp_catch_vfork
1234 || bpt->owner->type == bp_catch_exec)
1235 {
1236 struct gdb_exception e = catch_exception (uiout, insert_catchpoint,
1237 bpt->owner, RETURN_MASK_ERROR);
1238 exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
1239 bpt->owner->number);
1240 if (e.reason < 0)
1241 bpt->owner->enable_state = bp_disabled;
1242 else
1243 bpt->inserted = 1;
1244
1245 /* We've already printed an error message if there was a problem
1246 inserting this catchpoint, and we've disabled the catchpoint,
1247 so just return success. */
1248 return 0;
1249 }
1250
1251 return 0;
1252}
1253
1254/* Make sure all breakpoints are inserted in inferior.
1255 Throws exception on any error.
1256 A breakpoint that is already inserted won't be inserted
1257 again, so calling this function twice is safe. */
1258void
1259insert_breakpoints (void)
1260{
1261 struct breakpoint *bpt;
1262
1263 ALL_BREAKPOINTS (bpt)
1264 if (is_hardware_watchpoint (bpt))
1265 update_watchpoint (bpt, 0 /* don't reparse. */);
1266
1267 update_global_location_list ();
1268
1269 if (!always_inserted_mode && target_has_execution)
1270 /* update_global_location_list does not insert breakpoints
1271 when always_inserted_mode is not enabled. Explicitly
1272 insert them now. */
1273 insert_breakpoint_locations ();
1274}
1275
1276/* insert_breakpoints is used when starting or continuing the program.
1277 remove_breakpoints is used when the program stops.
1278 Both return zero if successful,
1279 or an `errno' value if could not write the inferior. */
1280
1281static void
1282insert_breakpoint_locations (void)
1283{
1284 struct breakpoint *bpt;
1285 struct bp_location *b, *temp;
1286 int error = 0;
1287 int val = 0;
1288 int disabled_breaks = 0;
1289 int hw_breakpoint_error = 0;
1290 int process_warning = 0;
1291
1292 struct ui_file *tmp_error_stream = mem_fileopen ();
1293 make_cleanup_ui_file_delete (tmp_error_stream);
1294
1295 /* Explicitly mark the warning -- this will only be printed if
1296 there was an error. */
1297 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
1298
1299 ALL_BP_LOCATIONS_SAFE (b, temp)
1300 {
1301 if (!should_be_inserted (b) || b->inserted)
1302 continue;
1303
1304 /* There is no point inserting thread-specific breakpoints if the
1305 thread no longer exists. */
1306 if (b->owner->thread != -1
1307 && !valid_thread_id (b->owner->thread))
1308 continue;
1309
1310 val = insert_bp_location (b, tmp_error_stream,
1311 &disabled_breaks, &process_warning,
1312 &hw_breakpoint_error);
1313 if (val)
1314 error = val;
1315 }
1316
1317 /* If we failed to insert all locations of a watchpoint,
1318 remove them, as half-inserted watchpoint is of limited use. */
1319 ALL_BREAKPOINTS (bpt)
1320 {
1321 int some_failed = 0;
1322 struct bp_location *loc;
1323
1324 if (!is_hardware_watchpoint (bpt))
1325 continue;
1326
1327 if (bpt->enable_state != bp_enabled)
1328 continue;
1329
1330 if (bpt->disposition == disp_del_at_next_stop)
1331 continue;
1332
1333 for (loc = bpt->loc; loc; loc = loc->next)
1334 if (!loc->inserted)
1335 {
1336 some_failed = 1;
1337 break;
1338 }
1339 if (some_failed)
1340 {
1341 for (loc = bpt->loc; loc; loc = loc->next)
1342 if (loc->inserted)
1343 remove_breakpoint (loc, mark_uninserted);
1344
1345 hw_breakpoint_error = 1;
1346 fprintf_unfiltered (tmp_error_stream,
1347 "Could not insert hardware watchpoint %d.\n",
1348 bpt->number);
1349 error = -1;
1350 }
1351 }
1352
1353 if (error)
1354 {
1355 /* If a hardware breakpoint or watchpoint was inserted, add a
1356 message about possibly exhausted resources. */
1357 if (hw_breakpoint_error)
1358 {
1359 fprintf_unfiltered (tmp_error_stream,
1360 "Could not insert hardware breakpoints:\n\
1361You may have requested too many hardware breakpoints/watchpoints.\n");
1362 }
1363#ifdef ONE_PROCESS_WRITETEXT
1364 if (process_warning)
1365 fprintf_unfiltered (tmp_error_stream,
1366 "The same program may be running in another process.");
1367#endif
1368 target_terminal_ours_for_output ();
1369 error_stream (tmp_error_stream);
1370 }
1371}
1372
1373int
1374remove_breakpoints (void)
1375{
1376 struct bp_location *b;
1377 int val;
1378
1379 ALL_BP_LOCATIONS (b)
1380 {
1381 if (b->inserted)
1382 {
1383 val = remove_breakpoint (b, mark_uninserted);
1384 if (val != 0)
1385 return val;
1386 }
1387 }
1388 return 0;
1389}
1390
1391int
1392remove_hw_watchpoints (void)
1393{
1394 struct bp_location *b;
1395 int val;
1396
1397 ALL_BP_LOCATIONS (b)
1398 {
1399 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
1400 {
1401 val = remove_breakpoint (b, mark_uninserted);
1402 if (val != 0)
1403 return val;
1404 }
1405 }
1406 return 0;
1407}
1408
1409int
1410reattach_breakpoints (int pid)
1411{
1412 struct bp_location *b;
1413 int val;
1414 struct cleanup *old_chain = save_inferior_ptid ();
1415 struct ui_file *tmp_error_stream = mem_fileopen ();
1416 int dummy1 = 0, dummy2 = 0, dummy3 = 0;
1417
1418 make_cleanup_ui_file_delete (tmp_error_stream);
1419
1420 inferior_ptid = pid_to_ptid (pid);
1421 ALL_BP_LOCATIONS (b)
1422 {
1423 if (b->inserted)
1424 {
1425 b->inserted = 0;
1426 val = insert_bp_location (b, tmp_error_stream,
1427 &dummy1, &dummy2, &dummy3);
1428 if (val != 0)
1429 {
1430 do_cleanups (old_chain);
1431 return val;
1432 }
1433 }
1434 }
1435 do_cleanups (old_chain);
1436 return 0;
1437}
1438
1439void
1440update_breakpoints_after_exec (void)
1441{
1442 struct breakpoint *b;
1443 struct breakpoint *temp;
1444 struct bp_location *bploc;
1445 struct cleanup *cleanup;
1446
1447 /* We're about to delete breakpoints from GDB's lists. If the
1448 INSERTED flag is true, GDB will try to lift the breakpoints by
1449 writing the breakpoints' "shadow contents" back into memory. The
1450 "shadow contents" are NOT valid after an exec, so GDB should not
1451 do that. Instead, the target is responsible from marking
1452 breakpoints out as soon as it detects an exec. We don't do that
1453 here instead, because there may be other attempts to delete
1454 breakpoints after detecting an exec and before reaching here. */
1455 ALL_BP_LOCATIONS (bploc)
1456 gdb_assert (!bploc->inserted);
1457
1458 /* The binary we used to debug is now gone, and we're updating
1459 breakpoints for the new binary. Until we're done, we should not
1460 try to insert breakpoints. */
1461 cleanup = make_cleanup_restore_integer (&always_inserted_mode);
1462 always_inserted_mode = 0;
1463
1464 ALL_BREAKPOINTS_SAFE (b, temp)
1465 {
1466 /* Solib breakpoints must be explicitly reset after an exec(). */
1467 if (b->type == bp_shlib_event)
1468 {
1469 delete_breakpoint (b);
1470 continue;
1471 }
1472
1473 /* Thread event breakpoints must be set anew after an exec(),
1474 as must overlay event breakpoints. */
1475 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1476 {
1477 delete_breakpoint (b);
1478 continue;
1479 }
1480
1481 /* Step-resume breakpoints are meaningless after an exec(). */
1482 if (b->type == bp_step_resume)
1483 {
1484 delete_breakpoint (b);
1485 continue;
1486 }
1487
1488 /* Longjmp and longjmp-resume breakpoints are also meaningless
1489 after an exec. */
1490 if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
1491 {
1492 delete_breakpoint (b);
1493 continue;
1494 }
1495
1496 /* Don't delete an exec catchpoint, because else the inferior
1497 won't stop when it ought!
1498
1499 Similarly, we probably ought to keep vfork catchpoints, 'cause
1500 on this target, we may not be able to stop when the vfork is
1501 seen, but only when the subsequent exec is seen. (And because
1502 deleting fork catchpoints here but not vfork catchpoints will
1503 seem mysterious to users, keep those too.) */
1504 if ((b->type == bp_catch_exec) ||
1505 (b->type == bp_catch_vfork) ||
1506 (b->type == bp_catch_fork))
1507 {
1508 continue;
1509 }
1510
1511 /* bp_finish is a special case. The only way we ought to be able
1512 to see one of these when an exec() has happened, is if the user
1513 caught a vfork, and then said "finish". Ordinarily a finish just
1514 carries them to the call-site of the current callee, by setting
1515 a temporary bp there and resuming. But in this case, the finish
1516 will carry them entirely through the vfork & exec.
1517
1518 We don't want to allow a bp_finish to remain inserted now. But
1519 we can't safely delete it, 'cause finish_command has a handle to
1520 the bp on a bpstat, and will later want to delete it. There's a
1521 chance (and I've seen it happen) that if we delete the bp_finish
1522 here, that its storage will get reused by the time finish_command
1523 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1524 We really must allow finish_command to delete a bp_finish.
1525
1526 In the absense of a general solution for the "how do we know
1527 it's safe to delete something others may have handles to?"
1528 problem, what we'll do here is just uninsert the bp_finish, and
1529 let finish_command delete it.
1530
1531 (We know the bp_finish is "doomed" in the sense that it's
1532 momentary, and will be deleted as soon as finish_command sees
1533 the inferior stopped. So it doesn't matter that the bp's
1534 address is probably bogus in the new a.out, unlike e.g., the
1535 solib breakpoints.) */
1536
1537 if (b->type == bp_finish)
1538 {
1539 continue;
1540 }
1541
1542 /* Without a symbolic address, we have little hope of the
1543 pre-exec() address meaning the same thing in the post-exec()
1544 a.out. */
1545 if (b->addr_string == NULL)
1546 {
1547 delete_breakpoint (b);
1548 continue;
1549 }
1550 }
1551 /* FIXME what about longjmp breakpoints? Re-create them here? */
1552 create_overlay_event_breakpoint ("_ovly_debug_event");
1553 do_cleanups (cleanup);
1554}
1555
1556int
1557detach_breakpoints (int pid)
1558{
1559 struct bp_location *b;
1560 int val;
1561 struct cleanup *old_chain = save_inferior_ptid ();
1562
1563 if (pid == PIDGET (inferior_ptid))
1564 error (_("Cannot detach breakpoints of inferior_ptid"));
1565
1566 /* Set inferior_ptid; remove_breakpoint uses this global. */
1567 inferior_ptid = pid_to_ptid (pid);
1568 ALL_BP_LOCATIONS (b)
1569 {
1570 if (b->inserted)
1571 {
1572 val = remove_breakpoint (b, mark_inserted);
1573 if (val != 0)
1574 {
1575 do_cleanups (old_chain);
1576 return val;
1577 }
1578 }
1579 }
1580 do_cleanups (old_chain);
1581 return 0;
1582}
1583
1584static int
1585remove_breakpoint (struct bp_location *b, insertion_state_t is)
1586{
1587 int val;
1588
1589 if (b->owner->enable_state == bp_permanent)
1590 /* Permanent breakpoints cannot be inserted or removed. */
1591 return 0;
1592
1593 /* The type of none suggests that owner is actually deleted.
1594 This should not ever happen. */
1595 gdb_assert (b->owner->type != bp_none);
1596
1597 if (b->loc_type == bp_loc_software_breakpoint
1598 || b->loc_type == bp_loc_hardware_breakpoint)
1599 {
1600 /* "Normal" instruction breakpoint: either the standard
1601 trap-instruction bp (bp_breakpoint), or a
1602 bp_hardware_breakpoint. */
1603
1604 /* First check to see if we have to handle an overlay. */
1605 if (overlay_debugging == ovly_off
1606 || b->section == NULL
1607 || !(section_is_overlay (b->section)))
1608 {
1609 /* No overlay handling: just remove the breakpoint. */
1610
1611 if (b->loc_type == bp_loc_hardware_breakpoint)
1612 val = target_remove_hw_breakpoint (&b->target_info);
1613 else
1614 val = target_remove_breakpoint (&b->target_info);
1615 }
1616 else
1617 {
1618 /* This breakpoint is in an overlay section.
1619 Did we set a breakpoint at the LMA? */
1620 if (!overlay_events_enabled)
1621 {
1622 /* Yes -- overlay event support is not active, so we
1623 should have set a breakpoint at the LMA. Remove it.
1624 */
1625 /* Ignore any failures: if the LMA is in ROM, we will
1626 have already warned when we failed to insert it. */
1627 if (b->loc_type == bp_loc_hardware_breakpoint)
1628 target_remove_hw_breakpoint (&b->overlay_target_info);
1629 else
1630 target_remove_breakpoint (&b->overlay_target_info);
1631 }
1632 /* Did we set a breakpoint at the VMA?
1633 If so, we will have marked the breakpoint 'inserted'. */
1634 if (b->inserted)
1635 {
1636 /* Yes -- remove it. Previously we did not bother to
1637 remove the breakpoint if the section had been
1638 unmapped, but let's not rely on that being safe. We
1639 don't know what the overlay manager might do. */
1640 if (b->loc_type == bp_loc_hardware_breakpoint)
1641 val = target_remove_hw_breakpoint (&b->target_info);
1642
1643 /* However, we should remove *software* breakpoints only
1644 if the section is still mapped, or else we overwrite
1645 wrong code with the saved shadow contents. */
1646 else if (section_is_mapped (b->section))
1647 val = target_remove_breakpoint (&b->target_info);
1648 else
1649 val = 0;
1650 }
1651 else
1652 {
1653 /* No -- not inserted, so no need to remove. No error. */
1654 val = 0;
1655 }
1656 }
1657 if (val)
1658 return val;
1659 b->inserted = (is == mark_inserted);
1660 }
1661 else if (b->loc_type == bp_loc_hardware_watchpoint)
1662 {
1663 struct value *v;
1664 struct value *n;
1665
1666 b->inserted = (is == mark_inserted);
1667 val = target_remove_watchpoint (b->address, b->length,
1668 b->watchpoint_type);
1669
1670 /* Failure to remove any of the hardware watchpoints comes here. */
1671 if ((is == mark_uninserted) && (b->inserted))
1672 warning (_("Could not remove hardware watchpoint %d."),
1673 b->owner->number);
1674 }
1675 else if ((b->owner->type == bp_catch_fork ||
1676 b->owner->type == bp_catch_vfork ||
1677 b->owner->type == bp_catch_exec)
1678 && breakpoint_enabled (b->owner)
1679 && !b->duplicate)
1680 {
1681 val = -1;
1682 switch (b->owner->type)
1683 {
1684 case bp_catch_fork:
1685 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1686 break;
1687 case bp_catch_vfork:
1688 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1689 break;
1690 case bp_catch_exec:
1691 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1692 break;
1693 default:
1694 warning (_("Internal error, %s line %d."), __FILE__, __LINE__);
1695 break;
1696 }
1697 if (val)
1698 return val;
1699 b->inserted = (is == mark_inserted);
1700 }
1701
1702 return 0;
1703}
1704
1705/* Clear the "inserted" flag in all breakpoints. */
1706
1707void
1708mark_breakpoints_out (void)
1709{
1710 struct bp_location *bpt;
1711
1712 ALL_BP_LOCATIONS (bpt)
1713 bpt->inserted = 0;
1714}
1715
1716/* Clear the "inserted" flag in all breakpoints and delete any
1717 breakpoints which should go away between runs of the program.
1718
1719 Plus other such housekeeping that has to be done for breakpoints
1720 between runs.
1721
1722 Note: this function gets called at the end of a run (by
1723 generic_mourn_inferior) and when a run begins (by
1724 init_wait_for_inferior). */
1725
1726
1727
1728void
1729breakpoint_init_inferior (enum inf_context context)
1730{
1731 struct breakpoint *b, *temp;
1732 struct bp_location *bpt;
1733
1734 ALL_BP_LOCATIONS (bpt)
1735 bpt->inserted = 0;
1736
1737 ALL_BREAKPOINTS_SAFE (b, temp)
1738 {
1739 switch (b->type)
1740 {
1741 case bp_call_dummy:
1742 case bp_watchpoint_scope:
1743
1744 /* If the call dummy breakpoint is at the entry point it will
1745 cause problems when the inferior is rerun, so we better
1746 get rid of it.
1747
1748 Also get rid of scope breakpoints. */
1749 delete_breakpoint (b);
1750 break;
1751
1752 case bp_watchpoint:
1753 case bp_hardware_watchpoint:
1754 case bp_read_watchpoint:
1755 case bp_access_watchpoint:
1756
1757 /* Likewise for watchpoints on local expressions. */
1758 if (b->exp_valid_block != NULL)
1759 delete_breakpoint (b);
1760 else if (context == inf_starting)
1761 {
1762 /* Reset val field to force reread of starting value
1763 in insert_breakpoints. */
1764 if (b->val)
1765 value_free (b->val);
1766 b->val = NULL;
1767 b->val_valid = 0;
1768 }
1769 break;
1770 default:
1771 break;
1772 }
1773 }
1774}
1775
1776/* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1777 exists at PC. It returns ordinary_breakpoint_here if it's an
1778 ordinary breakpoint, or permanent_breakpoint_here if it's a
1779 permanent breakpoint.
1780 - When continuing from a location with an ordinary breakpoint, we
1781 actually single step once before calling insert_breakpoints.
1782 - When continuing from a localion with a permanent breakpoint, we
1783 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1784 the target, to advance the PC past the breakpoint. */
1785
1786enum breakpoint_here
1787breakpoint_here_p (CORE_ADDR pc)
1788{
1789 const struct bp_location *bpt;
1790 int any_breakpoint_here = 0;
1791
1792 ALL_BP_LOCATIONS (bpt)
1793 {
1794 if (bpt->loc_type != bp_loc_software_breakpoint
1795 && bpt->loc_type != bp_loc_hardware_breakpoint)
1796 continue;
1797
1798 if ((breakpoint_enabled (bpt->owner)
1799 || bpt->owner->enable_state == bp_permanent)
1800 && bpt->address == pc) /* bp is enabled and matches pc */
1801 {
1802 if (overlay_debugging
1803 && section_is_overlay (bpt->section)
1804 && !section_is_mapped (bpt->section))
1805 continue; /* unmapped overlay -- can't be a match */
1806 else if (bpt->owner->enable_state == bp_permanent)
1807 return permanent_breakpoint_here;
1808 else
1809 any_breakpoint_here = 1;
1810 }
1811 }
1812
1813 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1814}
1815
1816
1817/* Returns non-zero if there's a breakpoint inserted at PC, which is
1818 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1819 This does not check for single-step breakpoints, which are
1820 inserted and removed using direct target manipulation. */
1821
1822int
1823regular_breakpoint_inserted_here_p (CORE_ADDR pc)
1824{
1825 const struct bp_location *bpt;
1826
1827 ALL_BP_LOCATIONS (bpt)
1828 {
1829 if (bpt->loc_type != bp_loc_software_breakpoint
1830 && bpt->loc_type != bp_loc_hardware_breakpoint)
1831 continue;
1832
1833 if (bpt->inserted
1834 && bpt->address == pc) /* bp is inserted and matches pc */
1835 {
1836 if (overlay_debugging
1837 && section_is_overlay (bpt->section)
1838 && !section_is_mapped (bpt->section))
1839 continue; /* unmapped overlay -- can't be a match */
1840 else
1841 return 1;
1842 }
1843 }
1844 return 0;
1845}
1846
1847/* Returns non-zero iff there's either regular breakpoint
1848 or a single step breakpoint inserted at PC. */
1849
1850int
1851breakpoint_inserted_here_p (CORE_ADDR pc)
1852{
1853 if (regular_breakpoint_inserted_here_p (pc))
1854 return 1;
1855
1856 if (single_step_breakpoint_inserted_here_p (pc))
1857 return 1;
1858
1859 return 0;
1860}
1861
1862/* This function returns non-zero iff there is a software breakpoint
1863 inserted at PC. */
1864
1865int
1866software_breakpoint_inserted_here_p (CORE_ADDR pc)
1867{
1868 const struct bp_location *bpt;
1869 int any_breakpoint_here = 0;
1870
1871 ALL_BP_LOCATIONS (bpt)
1872 {
1873 if (bpt->loc_type != bp_loc_software_breakpoint)
1874 continue;
1875
1876 if (bpt->inserted
1877 && bpt->address == pc) /* bp is enabled and matches pc */
1878 {
1879 if (overlay_debugging
1880 && section_is_overlay (bpt->section)
1881 && !section_is_mapped (bpt->section))
1882 continue; /* unmapped overlay -- can't be a match */
1883 else
1884 return 1;
1885 }
1886 }
1887
1888 /* Also check for software single-step breakpoints. */
1889 if (single_step_breakpoint_inserted_here_p (pc))
1890 return 1;
1891
1892 return 0;
1893}
1894
1895/* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1896 PC is valid for process/thread PTID. */
1897
1898int
1899breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1900{
1901 const struct bp_location *bpt;
1902 int thread;
1903
1904 thread = pid_to_thread_id (ptid);
1905
1906 ALL_BP_LOCATIONS (bpt)
1907 {
1908 if (bpt->loc_type != bp_loc_software_breakpoint
1909 && bpt->loc_type != bp_loc_hardware_breakpoint)
1910 continue;
1911
1912 if ((breakpoint_enabled (bpt->owner)
1913 || bpt->owner->enable_state == bp_permanent)
1914 && bpt->address == pc
1915 && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
1916 {
1917 if (overlay_debugging
1918 && section_is_overlay (bpt->section)
1919 && !section_is_mapped (bpt->section))
1920 continue; /* unmapped overlay -- can't be a match */
1921 else
1922 return 1;
1923 }
1924 }
1925
1926 return 0;
1927}
1928\f
1929
1930/* bpstat stuff. External routines' interfaces are documented
1931 in breakpoint.h. */
1932
1933int
1934ep_is_catchpoint (struct breakpoint *ep)
1935{
1936 return
1937 (ep->type == bp_catch_load)
1938 || (ep->type == bp_catch_unload)
1939 || (ep->type == bp_catch_fork)
1940 || (ep->type == bp_catch_vfork)
1941 || (ep->type == bp_catch_exec);
1942
1943 /* ??rehrauer: Add more kinds here, as are implemented... */
1944}
1945
1946int
1947ep_is_shlib_catchpoint (struct breakpoint *ep)
1948{
1949 return
1950 (ep->type == bp_catch_load)
1951 || (ep->type == bp_catch_unload);
1952}
1953
1954void
1955bpstat_free (bpstat bs)
1956{
1957 if (bs->old_val != NULL)
1958 value_free (bs->old_val);
1959 free_command_lines (&bs->commands);
1960 xfree (bs);
1961}
1962
1963/* Clear a bpstat so that it says we are not at any breakpoint.
1964 Also free any storage that is part of a bpstat. */
1965
1966void
1967bpstat_clear (bpstat *bsp)
1968{
1969 bpstat p;
1970 bpstat q;
1971
1972 if (bsp == 0)
1973 return;
1974 p = *bsp;
1975 while (p != NULL)
1976 {
1977 q = p->next;
1978 bpstat_free (p);
1979 p = q;
1980 }
1981 *bsp = NULL;
1982}
1983
1984/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1985 is part of the bpstat is copied as well. */
1986
1987bpstat
1988bpstat_copy (bpstat bs)
1989{
1990 bpstat p = NULL;
1991 bpstat tmp;
1992 bpstat retval = NULL;
1993
1994 if (bs == NULL)
1995 return bs;
1996
1997 for (; bs != NULL; bs = bs->next)
1998 {
1999 tmp = (bpstat) xmalloc (sizeof (*tmp));
2000 memcpy (tmp, bs, sizeof (*tmp));
2001 if (bs->commands != NULL)
2002 tmp->commands = copy_command_lines (bs->commands);
2003 if (bs->old_val != NULL)
2004 {
2005 tmp->old_val = value_copy (bs->old_val);
2006 release_value (tmp->old_val);
2007 }
2008
2009 if (p == NULL)
2010 /* This is the first thing in the chain. */
2011 retval = tmp;
2012 else
2013 p->next = tmp;
2014 p = tmp;
2015 }
2016 p->next = NULL;
2017 return retval;
2018}
2019
2020/* Find the bpstat associated with this breakpoint */
2021
2022bpstat
2023bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
2024{
2025 if (bsp == NULL)
2026 return NULL;
2027
2028 for (; bsp != NULL; bsp = bsp->next)
2029 {
2030 if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint)
2031 return bsp;
2032 }
2033 return NULL;
2034}
2035
2036/* Find a step_resume breakpoint associated with this bpstat.
2037 (If there are multiple step_resume bp's on the list, this function
2038 will arbitrarily pick one.)
2039
2040 It is an error to use this function if BPSTAT doesn't contain a
2041 step_resume breakpoint.
2042
2043 See wait_for_inferior's use of this function. */
2044struct breakpoint *
2045bpstat_find_step_resume_breakpoint (bpstat bsp)
2046{
2047 int current_thread;
2048
2049 gdb_assert (bsp != NULL);
2050
2051 current_thread = pid_to_thread_id (inferior_ptid);
2052
2053 for (; bsp != NULL; bsp = bsp->next)
2054 {
2055 if ((bsp->breakpoint_at != NULL) &&
2056 (bsp->breakpoint_at->owner->type == bp_step_resume) &&
2057 (bsp->breakpoint_at->owner->thread == current_thread ||
2058 bsp->breakpoint_at->owner->thread == -1))
2059 return bsp->breakpoint_at->owner;
2060 }
2061
2062 internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found."));
2063}
2064
2065
2066/* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2067 at. *BSP upon return is a bpstat which points to the remaining
2068 breakpoints stopped at (but which is not guaranteed to be good for
2069 anything but further calls to bpstat_num).
2070 Return 0 if passed a bpstat which does not indicate any breakpoints.
2071 Return -1 if stopped at a breakpoint that has been deleted since
2072 we set it.
2073 Return 1 otherwise. */
2074
2075int
2076bpstat_num (bpstat *bsp, int *num)
2077{
2078 struct breakpoint *b;
2079
2080 if ((*bsp) == NULL)
2081 return 0; /* No more breakpoint values */
2082
2083 /* We assume we'll never have several bpstats that
2084 correspond to a single breakpoint -- otherwise,
2085 this function might return the same number more
2086 than once and this will look ugly. */
2087 b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL;
2088 *bsp = (*bsp)->next;
2089 if (b == NULL)
2090 return -1; /* breakpoint that's been deleted since */
2091
2092 *num = b->number; /* We have its number */
2093 return 1;
2094}
2095
2096/* Modify BS so that the actions will not be performed. */
2097
2098void
2099bpstat_clear_actions (bpstat bs)
2100{
2101 for (; bs != NULL; bs = bs->next)
2102 {
2103 free_command_lines (&bs->commands);
2104 if (bs->old_val != NULL)
2105 {
2106 value_free (bs->old_val);
2107 bs->old_val = NULL;
2108 }
2109 }
2110}
2111
2112/* Stub for cleaning up our state if we error-out of a breakpoint command */
2113static void
2114cleanup_executing_breakpoints (void *ignore)
2115{
2116 executing_breakpoint_commands = 0;
2117}
2118
2119/* Execute all the commands associated with all the breakpoints at this
2120 location. Any of these commands could cause the process to proceed
2121 beyond this point, etc. We look out for such changes by checking
2122 the global "breakpoint_proceeded" after each command. */
2123
2124void
2125bpstat_do_actions (bpstat *bsp)
2126{
2127 bpstat bs;
2128 struct cleanup *old_chain;
2129
2130 /* Avoid endless recursion if a `source' command is contained
2131 in bs->commands. */
2132 if (executing_breakpoint_commands)
2133 return;
2134
2135 executing_breakpoint_commands = 1;
2136 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
2137
2138top:
2139 /* Note that (as of this writing), our callers all appear to
2140 be passing us the address of global stop_bpstat. And, if
2141 our calls to execute_control_command cause the inferior to
2142 proceed, that global (and hence, *bsp) will change.
2143
2144 We must be careful to not touch *bsp unless the inferior
2145 has not proceeded. */
2146
2147 /* This pointer will iterate over the list of bpstat's. */
2148 bs = *bsp;
2149
2150 breakpoint_proceeded = 0;
2151 for (; bs != NULL; bs = bs->next)
2152 {
2153 struct command_line *cmd;
2154 struct cleanup *this_cmd_tree_chain;
2155
2156 /* Take ownership of the BSP's command tree, if it has one.
2157
2158 The command tree could legitimately contain commands like
2159 'step' and 'next', which call clear_proceed_status, which
2160 frees stop_bpstat's command tree. To make sure this doesn't
2161 free the tree we're executing out from under us, we need to
2162 take ownership of the tree ourselves. Since a given bpstat's
2163 commands are only executed once, we don't need to copy it; we
2164 can clear the pointer in the bpstat, and make sure we free
2165 the tree when we're done. */
2166 cmd = bs->commands;
2167 bs->commands = 0;
2168 this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd);
2169
2170 while (cmd != NULL)
2171 {
2172 execute_control_command (cmd);
2173
2174 if (breakpoint_proceeded)
2175 break;
2176 else
2177 cmd = cmd->next;
2178 }
2179
2180 /* We can free this command tree now. */
2181 do_cleanups (this_cmd_tree_chain);
2182
2183 if (breakpoint_proceeded)
2184 {
2185 if (target_can_async_p ())
2186 /* If we are in async mode, then the target might
2187 be still running, not stopped at any breakpoint,
2188 so nothing for us to do here -- just return to
2189 the event loop. */
2190 break;
2191 else
2192 /* In sync mode, when execute_control_command returns
2193 we're already standing on the next breakpoint.
2194 Breakpoint commands for that stop were not run,
2195 since execute_command does not run breakpoint
2196 commands -- only command_line_handler does, but
2197 that one is not involved in execution of breakpoint
2198 commands. So, we can now execute breakpoint commands.
2199 There's an implicit assumption that we're called with
2200 stop_bpstat, so our parameter is the new bpstat to
2201 handle.
2202 It should be noted that making execute_command do
2203 bpstat actions is not an option -- in this case we'll
2204 have recursive invocation of bpstat for each breakpoint
2205 with a command, and can easily blow up GDB stack. */
2206 goto top;
2207 }
2208 }
2209 do_cleanups (old_chain);
2210}
2211
2212/* Print out the (old or new) value associated with a watchpoint. */
2213
2214static void
2215watchpoint_value_print (struct value *val, struct ui_file *stream)
2216{
2217 if (val == NULL)
2218 fprintf_unfiltered (stream, _("<unreadable>"));
2219 else
2220 value_print (val, stream, 0, Val_pretty_default);
2221}
2222
2223/* This is the normal print function for a bpstat. In the future,
2224 much of this logic could (should?) be moved to bpstat_stop_status,
2225 by having it set different print_it values.
2226
2227 Current scheme: When we stop, bpstat_print() is called. It loops
2228 through the bpstat list of things causing this stop, calling the
2229 print_bp_stop_message function on each one. The behavior of the
2230 print_bp_stop_message function depends on the print_it field of
2231 bpstat. If such field so indicates, call this function here.
2232
2233 Return values from this routine (ultimately used by bpstat_print()
2234 and normal_stop() to decide what to do):
2235 PRINT_NOTHING: Means we already printed all we needed to print,
2236 don't print anything else.
2237 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2238 that something to be followed by a location.
2239 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2240 that something to be followed by a location.
2241 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2242 analysis. */
2243
2244static enum print_stop_action
2245print_it_typical (bpstat bs)
2246{
2247 struct cleanup *old_chain, *ui_out_chain;
2248 struct breakpoint *b;
2249 const struct bp_location *bl;
2250 struct ui_stream *stb;
2251 int bp_temp = 0;
2252 stb = ui_out_stream_new (uiout);
2253 old_chain = make_cleanup_ui_out_stream_delete (stb);
2254 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2255 which has since been deleted. */
2256 if (bs->breakpoint_at == NULL)
2257 return PRINT_UNKNOWN;
2258 bl = bs->breakpoint_at;
2259 b = bl->owner;
2260
2261 switch (b->type)
2262 {
2263 case bp_breakpoint:
2264 case bp_hardware_breakpoint:
2265 bp_temp = bs->breakpoint_at->owner->disposition == disp_del;
2266 if (bl->address != bl->requested_address)
2267 breakpoint_adjustment_warning (bl->requested_address,
2268 bl->address,
2269 b->number, 1);
2270 annotate_breakpoint (b->number);
2271 if (bp_temp)
2272 ui_out_text (uiout, "\nTemporary breakpoint ");
2273 else
2274 ui_out_text (uiout, "\nBreakpoint ");
2275 if (ui_out_is_mi_like_p (uiout))
2276 {
2277 ui_out_field_string (uiout, "reason",
2278 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
2279 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
2280 }
2281 ui_out_field_int (uiout, "bkptno", b->number);
2282 ui_out_text (uiout, ", ");
2283 return PRINT_SRC_AND_LOC;
2284 break;
2285
2286 case bp_shlib_event:
2287 /* Did we stop because the user set the stop_on_solib_events
2288 variable? (If so, we report this as a generic, "Stopped due
2289 to shlib event" message.) */
2290 printf_filtered (_("Stopped due to shared library event\n"));
2291 return PRINT_NOTHING;
2292 break;
2293
2294 case bp_thread_event:
2295 /* Not sure how we will get here.
2296 GDB should not stop for these breakpoints. */
2297 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2298 return PRINT_NOTHING;
2299 break;
2300
2301 case bp_overlay_event:
2302 /* By analogy with the thread event, GDB should not stop for these. */
2303 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2304 return PRINT_NOTHING;
2305 break;
2306
2307 case bp_catch_load:
2308 annotate_catchpoint (b->number);
2309 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2310 b->number,
2311 b->triggered_dll_pathname);
2312 return PRINT_SRC_AND_LOC;
2313 break;
2314
2315 case bp_catch_unload:
2316 annotate_catchpoint (b->number);
2317 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2318 b->number,
2319 b->triggered_dll_pathname);
2320 return PRINT_SRC_AND_LOC;
2321 break;
2322
2323 case bp_catch_fork:
2324 annotate_catchpoint (b->number);
2325 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2326 b->number,
2327 b->forked_inferior_pid);
2328 return PRINT_SRC_AND_LOC;
2329 break;
2330
2331 case bp_catch_vfork:
2332 annotate_catchpoint (b->number);
2333 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2334 b->number,
2335 b->forked_inferior_pid);
2336 return PRINT_SRC_AND_LOC;
2337 break;
2338
2339 case bp_catch_exec:
2340 annotate_catchpoint (b->number);
2341 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2342 b->number,
2343 b->exec_pathname);
2344 return PRINT_SRC_AND_LOC;
2345 break;
2346
2347 case bp_watchpoint:
2348 case bp_hardware_watchpoint:
2349 annotate_watchpoint (b->number);
2350 if (ui_out_is_mi_like_p (uiout))
2351 ui_out_field_string
2352 (uiout, "reason",
2353 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
2354 mention (b);
2355 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2356 ui_out_text (uiout, "\nOld value = ");
2357 watchpoint_value_print (bs->old_val, stb->stream);
2358 ui_out_field_stream (uiout, "old", stb);
2359 ui_out_text (uiout, "\nNew value = ");
2360 watchpoint_value_print (b->val, stb->stream);
2361 ui_out_field_stream (uiout, "new", stb);
2362 do_cleanups (ui_out_chain);
2363 ui_out_text (uiout, "\n");
2364 /* More than one watchpoint may have been triggered. */
2365 return PRINT_UNKNOWN;
2366 break;
2367
2368 case bp_read_watchpoint:
2369 if (ui_out_is_mi_like_p (uiout))
2370 ui_out_field_string
2371 (uiout, "reason",
2372 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER));
2373 mention (b);
2374 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2375 ui_out_text (uiout, "\nValue = ");
2376 watchpoint_value_print (b->val, stb->stream);
2377 ui_out_field_stream (uiout, "value", stb);
2378 do_cleanups (ui_out_chain);
2379 ui_out_text (uiout, "\n");
2380 return PRINT_UNKNOWN;
2381 break;
2382
2383 case bp_access_watchpoint:
2384 if (bs->old_val != NULL)
2385 {
2386 annotate_watchpoint (b->number);
2387 if (ui_out_is_mi_like_p (uiout))
2388 ui_out_field_string
2389 (uiout, "reason",
2390 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2391 mention (b);
2392 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2393 ui_out_text (uiout, "\nOld value = ");
2394 watchpoint_value_print (bs->old_val, stb->stream);
2395 ui_out_field_stream (uiout, "old", stb);
2396 ui_out_text (uiout, "\nNew value = ");
2397 }
2398 else
2399 {
2400 mention (b);
2401 if (ui_out_is_mi_like_p (uiout))
2402 ui_out_field_string
2403 (uiout, "reason",
2404 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER));
2405 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2406 ui_out_text (uiout, "\nValue = ");
2407 }
2408 watchpoint_value_print (b->val, stb->stream);
2409 ui_out_field_stream (uiout, "new", stb);
2410 do_cleanups (ui_out_chain);
2411 ui_out_text (uiout, "\n");
2412 return PRINT_UNKNOWN;
2413 break;
2414
2415 /* Fall through, we don't deal with these types of breakpoints
2416 here. */
2417
2418 case bp_finish:
2419 if (ui_out_is_mi_like_p (uiout))
2420 ui_out_field_string
2421 (uiout, "reason",
2422 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED));
2423 return PRINT_UNKNOWN;
2424 break;
2425
2426 case bp_until:
2427 if (ui_out_is_mi_like_p (uiout))
2428 ui_out_field_string
2429 (uiout, "reason",
2430 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED));
2431 return PRINT_UNKNOWN;
2432 break;
2433
2434 case bp_none:
2435 case bp_longjmp:
2436 case bp_longjmp_resume:
2437 case bp_step_resume:
2438 case bp_watchpoint_scope:
2439 case bp_call_dummy:
2440 default:
2441 return PRINT_UNKNOWN;
2442 }
2443}
2444
2445/* Generic routine for printing messages indicating why we
2446 stopped. The behavior of this function depends on the value
2447 'print_it' in the bpstat structure. Under some circumstances we
2448 may decide not to print anything here and delegate the task to
2449 normal_stop(). */
2450
2451static enum print_stop_action
2452print_bp_stop_message (bpstat bs)
2453{
2454 switch (bs->print_it)
2455 {
2456 case print_it_noop:
2457 /* Nothing should be printed for this bpstat entry. */
2458 return PRINT_UNKNOWN;
2459 break;
2460
2461 case print_it_done:
2462 /* We still want to print the frame, but we already printed the
2463 relevant messages. */
2464 return PRINT_SRC_AND_LOC;
2465 break;
2466
2467 case print_it_normal:
2468 {
2469 const struct bp_location *bl = bs->breakpoint_at;
2470 struct breakpoint *b = bl ? bl->owner : NULL;
2471
2472 /* Normal case. Call the breakpoint's print_it method, or
2473 print_it_typical. */
2474 /* FIXME: how breakpoint can ever be NULL here? */
2475 if (b != NULL && b->ops != NULL && b->ops->print_it != NULL)
2476 return b->ops->print_it (b);
2477 else
2478 return print_it_typical (bs);
2479 }
2480 break;
2481
2482 default:
2483 internal_error (__FILE__, __LINE__,
2484 _("print_bp_stop_message: unrecognized enum value"));
2485 break;
2486 }
2487}
2488
2489/* Print a message indicating what happened. This is called from
2490 normal_stop(). The input to this routine is the head of the bpstat
2491 list - a list of the eventpoints that caused this stop. This
2492 routine calls the generic print routine for printing a message
2493 about reasons for stopping. This will print (for example) the
2494 "Breakpoint n," part of the output. The return value of this
2495 routine is one of:
2496
2497 PRINT_UNKNOWN: Means we printed nothing
2498 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2499 code to print the location. An example is
2500 "Breakpoint 1, " which should be followed by
2501 the location.
2502 PRINT_SRC_ONLY: Means we printed something, but there is no need
2503 to also print the location part of the message.
2504 An example is the catch/throw messages, which
2505 don't require a location appended to the end.
2506 PRINT_NOTHING: We have done some printing and we don't need any
2507 further info to be printed.*/
2508
2509enum print_stop_action
2510bpstat_print (bpstat bs)
2511{
2512 int val;
2513
2514 /* Maybe another breakpoint in the chain caused us to stop.
2515 (Currently all watchpoints go on the bpstat whether hit or not.
2516 That probably could (should) be changed, provided care is taken
2517 with respect to bpstat_explains_signal). */
2518 for (; bs; bs = bs->next)
2519 {
2520 val = print_bp_stop_message (bs);
2521 if (val == PRINT_SRC_ONLY
2522 || val == PRINT_SRC_AND_LOC
2523 || val == PRINT_NOTHING)
2524 return val;
2525 }
2526
2527 /* We reached the end of the chain, or we got a null BS to start
2528 with and nothing was printed. */
2529 return PRINT_UNKNOWN;
2530}
2531
2532/* Evaluate the expression EXP and return 1 if value is zero.
2533 This is used inside a catch_errors to evaluate the breakpoint condition.
2534 The argument is a "struct expression *" that has been cast to char * to
2535 make it pass through catch_errors. */
2536
2537static int
2538breakpoint_cond_eval (void *exp)
2539{
2540 struct value *mark = value_mark ();
2541 int i = !value_true (evaluate_expression ((struct expression *) exp));
2542 value_free_to_mark (mark);
2543 return i;
2544}
2545
2546/* Allocate a new bpstat and chain it to the current one. */
2547
2548static bpstat
2549bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ )
2550{
2551 bpstat bs;
2552
2553 bs = (bpstat) xmalloc (sizeof (*bs));
2554 cbs->next = bs;
2555 bs->breakpoint_at = bl;
2556 /* If the condition is false, etc., don't do the commands. */
2557 bs->commands = NULL;
2558 bs->old_val = NULL;
2559 bs->print_it = print_it_normal;
2560 return bs;
2561}
2562\f
2563/* The target has stopped with waitstatus WS. Check if any hardware
2564 watchpoints have triggered, according to the target. */
2565
2566int
2567watchpoints_triggered (struct target_waitstatus *ws)
2568{
2569 int stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (*ws);
2570 CORE_ADDR addr;
2571 struct breakpoint *b;
2572
2573 if (!stopped_by_watchpoint)
2574 {
2575 /* We were not stopped by a watchpoint. Mark all watchpoints
2576 as not triggered. */
2577 ALL_BREAKPOINTS (b)
2578 if (b->type == bp_hardware_watchpoint
2579 || b->type == bp_read_watchpoint
2580 || b->type == bp_access_watchpoint)
2581 b->watchpoint_triggered = watch_triggered_no;
2582
2583 return 0;
2584 }
2585
2586 if (!target_stopped_data_address (&current_target, &addr))
2587 {
2588 /* We were stopped by a watchpoint, but we don't know where.
2589 Mark all watchpoints as unknown. */
2590 ALL_BREAKPOINTS (b)
2591 if (b->type == bp_hardware_watchpoint
2592 || b->type == bp_read_watchpoint
2593 || b->type == bp_access_watchpoint)
2594 b->watchpoint_triggered = watch_triggered_unknown;
2595
2596 return stopped_by_watchpoint;
2597 }
2598
2599 /* The target could report the data address. Mark watchpoints
2600 affected by this data address as triggered, and all others as not
2601 triggered. */
2602
2603 ALL_BREAKPOINTS (b)
2604 if (b->type == bp_hardware_watchpoint
2605 || b->type == bp_read_watchpoint
2606 || b->type == bp_access_watchpoint)
2607 {
2608 struct bp_location *loc;
2609 struct value *v;
2610
2611 b->watchpoint_triggered = watch_triggered_no;
2612 for (loc = b->loc; loc; loc = loc->next)
2613 /* Exact match not required. Within range is
2614 sufficient. */
2615 if (target_watchpoint_addr_within_range (&current_target,
2616 addr, loc->address,
2617 loc->length))
2618 {
2619 b->watchpoint_triggered = watch_triggered_yes;
2620 break;
2621 }
2622 }
2623
2624 return 1;
2625}
2626
2627/* Possible return values for watchpoint_check (this can't be an enum
2628 because of check_errors). */
2629/* The watchpoint has been deleted. */
2630#define WP_DELETED 1
2631/* The value has changed. */
2632#define WP_VALUE_CHANGED 2
2633/* The value has not changed. */
2634#define WP_VALUE_NOT_CHANGED 3
2635
2636#define BP_TEMPFLAG 1
2637#define BP_HARDWAREFLAG 2
2638
2639/* Check watchpoint condition. */
2640
2641static int
2642watchpoint_check (void *p)
2643{
2644 bpstat bs = (bpstat) p;
2645 struct breakpoint *b;
2646 struct frame_info *fr;
2647 int within_current_scope;
2648
2649 b = bs->breakpoint_at->owner;
2650
2651 if (b->exp_valid_block == NULL)
2652 within_current_scope = 1;
2653 else
2654 {
2655 /* There is no current frame at this moment. If we're going to have
2656 any chance of handling watchpoints on local variables, we'll need
2657 the frame chain (so we can determine if we're in scope). */
2658 reinit_frame_cache ();
2659 fr = frame_find_by_id (b->watchpoint_frame);
2660 within_current_scope = (fr != NULL);
2661
2662 /* If we've gotten confused in the unwinder, we might have
2663 returned a frame that can't describe this variable. */
2664 if (within_current_scope
2665 && block_function (b->exp_valid_block) != get_frame_function (fr))
2666 within_current_scope = 0;
2667
2668 /* in_function_epilogue_p() returns a non-zero value if we're still
2669 in the function but the stack frame has already been invalidated.
2670 Since we can't rely on the values of local variables after the
2671 stack has been destroyed, we are treating the watchpoint in that
2672 state as `not changed' without further checking.
2673
2674 vinschen/2003-09-04: The former implementation left out the case
2675 that the watchpoint frame couldn't be found by frame_find_by_id()
2676 because the current PC is currently in an epilogue. Calling
2677 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2678 if ((!within_current_scope || fr == get_current_frame ())
2679 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2680 return WP_VALUE_NOT_CHANGED;
2681 if (fr && within_current_scope)
2682 /* If we end up stopping, the current frame will get selected
2683 in normal_stop. So this call to select_frame won't affect
2684 the user. */
2685 select_frame (fr);
2686 }
2687
2688 if (within_current_scope)
2689 {
2690 /* We use value_{,free_to_}mark because it could be a
2691 *long* time before we return to the command level and
2692 call free_all_values. We can't call free_all_values because
2693 we might be in the middle of evaluating a function call. */
2694
2695 struct value *mark = value_mark ();
2696 struct value *new_val;
2697
2698 fetch_watchpoint_value (b->exp, &new_val, NULL, NULL);
2699 if ((b->val != NULL) != (new_val != NULL)
2700 || (b->val != NULL && !value_equal (b->val, new_val)))
2701 {
2702 if (new_val != NULL)
2703 {
2704 release_value (new_val);
2705 value_free_to_mark (mark);
2706 }
2707 bs->old_val = b->val;
2708 b->val = new_val;
2709 b->val_valid = 1;
2710 /* We will stop here */
2711 return WP_VALUE_CHANGED;
2712 }
2713 else
2714 {
2715 /* Nothing changed, don't do anything. */
2716 value_free_to_mark (mark);
2717 /* We won't stop here */
2718 return WP_VALUE_NOT_CHANGED;
2719 }
2720 }
2721 else
2722 {
2723 /* This seems like the only logical thing to do because
2724 if we temporarily ignored the watchpoint, then when
2725 we reenter the block in which it is valid it contains
2726 garbage (in the case of a function, it may have two
2727 garbage values, one before and one after the prologue).
2728 So we can't even detect the first assignment to it and
2729 watch after that (since the garbage may or may not equal
2730 the first value assigned). */
2731 /* We print all the stop information in print_it_typical(), but
2732 in this case, by the time we call print_it_typical() this bp
2733 will be deleted already. So we have no choice but print the
2734 information here. */
2735 if (ui_out_is_mi_like_p (uiout))
2736 ui_out_field_string
2737 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
2738 ui_out_text (uiout, "\nWatchpoint ");
2739 ui_out_field_int (uiout, "wpnum", b->number);
2740 ui_out_text (uiout, " deleted because the program has left the block in\n\
2741which its expression is valid.\n");
2742
2743 if (b->related_breakpoint)
2744 b->related_breakpoint->disposition = disp_del_at_next_stop;
2745 b->disposition = disp_del_at_next_stop;
2746
2747 return WP_DELETED;
2748 }
2749}
2750
2751/* Return true if it looks like target has stopped due to hitting
2752 breakpoint location BL. This function does not check if we
2753 should stop, only if BL explains the stop. */
2754static int
2755bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
2756{
2757 struct breakpoint *b = bl->owner;
2758
2759 if (b->type != bp_watchpoint
2760 && b->type != bp_hardware_watchpoint
2761 && b->type != bp_read_watchpoint
2762 && b->type != bp_access_watchpoint
2763 && b->type != bp_hardware_breakpoint
2764 && b->type != bp_catch_fork
2765 && b->type != bp_catch_vfork
2766 && b->type != bp_catch_exec) /* a non-watchpoint bp */
2767 {
2768 if (bl->address != bp_addr) /* address doesn't match */
2769 return 0;
2770 if (overlay_debugging /* unmapped overlay section */
2771 && section_is_overlay (bl->section)
2772 && !section_is_mapped (bl->section))
2773 return 0;
2774 }
2775
2776 /* Continuable hardware watchpoints are treated as non-existent if the
2777 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2778 some data address). Otherwise gdb won't stop on a break instruction
2779 in the code (not from a breakpoint) when a hardware watchpoint has
2780 been defined. Also skip watchpoints which we know did not trigger
2781 (did not match the data address). */
2782
2783 if ((b->type == bp_hardware_watchpoint
2784 || b->type == bp_read_watchpoint
2785 || b->type == bp_access_watchpoint)
2786 && b->watchpoint_triggered == watch_triggered_no)
2787 return 0;
2788
2789 if (b->type == bp_hardware_breakpoint)
2790 {
2791 if (bl->address != bp_addr)
2792 return 0;
2793 if (overlay_debugging /* unmapped overlay section */
2794 && section_is_overlay (bl->section)
2795 && !section_is_mapped (bl->section))
2796 return 0;
2797 }
2798
2799 /* Is this a catchpoint of a load or unload? If so, did we
2800 get a load or unload of the specified library? If not,
2801 ignore it. */
2802 if ((b->type == bp_catch_load)
2803#if defined(SOLIB_HAVE_LOAD_EVENT)
2804 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2805 || ((b->dll_pathname != NULL)
2806 && (strcmp (b->dll_pathname,
2807 SOLIB_LOADED_LIBRARY_PATHNAME (
2808 PIDGET (inferior_ptid)))
2809 != 0)))
2810#endif
2811 )
2812 return 0;
2813
2814 if ((b->type == bp_catch_unload)
2815#if defined(SOLIB_HAVE_UNLOAD_EVENT)
2816 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2817 || ((b->dll_pathname != NULL)
2818 && (strcmp (b->dll_pathname,
2819 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2820 PIDGET (inferior_ptid)))
2821 != 0)))
2822#endif
2823 )
2824 return 0;
2825
2826 if ((b->type == bp_catch_fork)
2827 && !inferior_has_forked (PIDGET (inferior_ptid),
2828 &b->forked_inferior_pid))
2829 return 0;
2830
2831 if ((b->type == bp_catch_vfork)
2832 && !inferior_has_vforked (PIDGET (inferior_ptid),
2833 &b->forked_inferior_pid))
2834 return 0;
2835
2836 if ((b->type == bp_catch_exec)
2837 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2838 return 0;
2839
2840 return 1;
2841}
2842
2843/* If BS refers to a watchpoint, determine if the watched values
2844 has actually changed, and we should stop. If not, set BS->stop
2845 to 0. */
2846static void
2847bpstat_check_watchpoint (bpstat bs)
2848{
2849 const struct bp_location *bl = bs->breakpoint_at;
2850 struct breakpoint *b = bl->owner;
2851
2852 if (b->type == bp_watchpoint
2853 || b->type == bp_read_watchpoint
2854 || b->type == bp_access_watchpoint
2855 || b->type == bp_hardware_watchpoint)
2856 {
2857 CORE_ADDR addr;
2858 struct value *v;
2859 int must_check_value = 0;
2860
2861 if (b->type == bp_watchpoint)
2862 /* For a software watchpoint, we must always check the
2863 watched value. */
2864 must_check_value = 1;
2865 else if (b->watchpoint_triggered == watch_triggered_yes)
2866 /* We have a hardware watchpoint (read, write, or access)
2867 and the target earlier reported an address watched by
2868 this watchpoint. */
2869 must_check_value = 1;
2870 else if (b->watchpoint_triggered == watch_triggered_unknown
2871 && b->type == bp_hardware_watchpoint)
2872 /* We were stopped by a hardware watchpoint, but the target could
2873 not report the data address. We must check the watchpoint's
2874 value. Access and read watchpoints are out of luck; without
2875 a data address, we can't figure it out. */
2876 must_check_value = 1;
2877
2878 if (must_check_value)
2879 {
2880 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2881 b->number);
2882 struct cleanup *cleanups = make_cleanup (xfree, message);
2883 int e = catch_errors (watchpoint_check, bs, message,
2884 RETURN_MASK_ALL);
2885 do_cleanups (cleanups);
2886 switch (e)
2887 {
2888 case WP_DELETED:
2889 /* We've already printed what needs to be printed. */
2890 bs->print_it = print_it_done;
2891 /* Stop. */
2892 break;
2893 case WP_VALUE_CHANGED:
2894 if (b->type == bp_read_watchpoint)
2895 {
2896 /* Don't stop: read watchpoints shouldn't fire if
2897 the value has changed. This is for targets
2898 which cannot set read-only watchpoints. */
2899 bs->print_it = print_it_noop;
2900 bs->stop = 0;
2901 }
2902 break;
2903 case WP_VALUE_NOT_CHANGED:
2904 if (b->type == bp_hardware_watchpoint
2905 || b->type == bp_watchpoint)
2906 {
2907 /* Don't stop: write watchpoints shouldn't fire if
2908 the value hasn't changed. */
2909 bs->print_it = print_it_noop;
2910 bs->stop = 0;
2911 }
2912 /* Stop. */
2913 break;
2914 default:
2915 /* Can't happen. */
2916 case 0:
2917 /* Error from catch_errors. */
2918 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
2919 if (b->related_breakpoint)
2920 b->related_breakpoint->disposition = disp_del_at_next_stop;
2921 b->disposition = disp_del_at_next_stop;
2922 /* We've already printed what needs to be printed. */
2923 bs->print_it = print_it_done;
2924 break;
2925 }
2926 }
2927 else /* must_check_value == 0 */
2928 {
2929 /* This is a case where some watchpoint(s) triggered, but
2930 not at the address of this watchpoint, or else no
2931 watchpoint triggered after all. So don't print
2932 anything for this watchpoint. */
2933 bs->print_it = print_it_noop;
2934 bs->stop = 0;
2935 }
2936 }
2937}
2938
2939
2940/* Check conditions (condition proper, frame, thread and ignore count)
2941 of breakpoint referred to by BS. If we should not stop for this
2942 breakpoint, set BS->stop to 0. */
2943static void
2944bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
2945{
2946 int thread_id = pid_to_thread_id (ptid);
2947 const struct bp_location *bl = bs->breakpoint_at;
2948 struct breakpoint *b = bl->owner;
2949
2950 if (frame_id_p (b->frame_id)
2951 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2952 bs->stop = 0;
2953 else if (bs->stop)
2954 {
2955 int value_is_zero = 0;
2956
2957 /* If this is a scope breakpoint, mark the associated
2958 watchpoint as triggered so that we will handle the
2959 out-of-scope event. We'll get to the watchpoint next
2960 iteration. */
2961 if (b->type == bp_watchpoint_scope)
2962 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
2963
2964 if (bl->cond && bl->owner->disposition != disp_del_at_next_stop)
2965 {
2966 /* Need to select the frame, with all that implies
2967 so that the conditions will have the right context. */
2968 select_frame (get_current_frame ());
2969 value_is_zero
2970 = catch_errors (breakpoint_cond_eval, (bl->cond),
2971 "Error in testing breakpoint condition:\n",
2972 RETURN_MASK_ALL);
2973 /* FIXME-someday, should give breakpoint # */
2974 free_all_values ();
2975 }
2976 if (bl->cond && value_is_zero)
2977 {
2978 bs->stop = 0;
2979 }
2980 else if (b->thread != -1 && b->thread != thread_id)
2981 {
2982 bs->stop = 0;
2983 }
2984 else if (b->ignore_count > 0)
2985 {
2986 b->ignore_count--;
2987 annotate_ignore_count_change ();
2988 bs->stop = 0;
2989 /* Increase the hit count even though we don't
2990 stop. */
2991 ++(b->hit_count);
2992 }
2993 }
2994}
2995
2996
2997/* Get a bpstat associated with having just stopped at address
2998 BP_ADDR in thread PTID.
2999
3000 Determine whether we stopped at a breakpoint, etc, or whether we
3001 don't understand this stop. Result is a chain of bpstat's such that:
3002
3003 if we don't understand the stop, the result is a null pointer.
3004
3005 if we understand why we stopped, the result is not null.
3006
3007 Each element of the chain refers to a particular breakpoint or
3008 watchpoint at which we have stopped. (We may have stopped for
3009 several reasons concurrently.)
3010
3011 Each element of the chain has valid next, breakpoint_at,
3012 commands, FIXME??? fields. */
3013
3014bpstat
3015bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
3016{
3017 struct breakpoint *b = NULL;
3018 const struct bp_location *bl;
3019 struct bp_location *loc;
3020 /* Root of the chain of bpstat's */
3021 struct bpstats root_bs[1];
3022 /* Pointer to the last thing in the chain currently. */
3023 bpstat bs = root_bs;
3024 int ix;
3025
3026 ALL_BP_LOCATIONS (bl)
3027 {
3028 b = bl->owner;
3029 gdb_assert (b);
3030 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
3031 continue;
3032
3033 /* For hardware watchpoints, we look only at the first location.
3034 The watchpoint_check function will work on entire expression,
3035 not the individual locations. For read watchopints, the
3036 watchpoints_triggered function have checked all locations
3037 alrea
3038 */
3039 if (b->type == bp_hardware_watchpoint && bl != b->loc)
3040 continue;
3041
3042 if (!bpstat_check_location (bl, bp_addr))
3043 continue;
3044
3045 /* Come here if it's a watchpoint, or if the break address matches */
3046
3047 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
3048
3049 /* Assume we stop. Should we find watchpoint that is not actually
3050 triggered, or if condition of breakpoint is false, we'll reset
3051 'stop' to 0. */
3052 bs->stop = 1;
3053 bs->print = 1;
3054
3055 bpstat_check_watchpoint (bs);
3056 if (!bs->stop)
3057 continue;
3058
3059 if (b->type == bp_thread_event || b->type == bp_overlay_event)
3060 /* We do not stop for these. */
3061 bs->stop = 0;
3062 else
3063 bpstat_check_breakpoint_conditions (bs, ptid);
3064
3065 if (bs->stop)
3066 {
3067 ++(b->hit_count);
3068
3069 /* We will stop here */
3070 if (b->disposition == disp_disable)
3071 {
3072 b->enable_state = bp_disabled;
3073 update_global_location_list ();
3074 }
3075 if (b->silent)
3076 bs->print = 0;
3077 bs->commands = b->commands;
3078 if (bs->commands &&
3079 (strcmp ("silent", bs->commands->line) == 0
3080 || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
3081 {
3082 bs->commands = bs->commands->next;
3083 bs->print = 0;
3084 }
3085 bs->commands = copy_command_lines (bs->commands);
3086 }
3087
3088 /* Print nothing for this entry if we dont stop or if we dont print. */
3089 if (bs->stop == 0 || bs->print == 0)
3090 bs->print_it = print_it_noop;
3091 }
3092
3093 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
3094 {
3095 if (loc->address == bp_addr)
3096 {
3097 bs = bpstat_alloc (loc, bs);
3098 /* For hits of moribund locations, we should just proceed. */
3099 bs->stop = 0;
3100 bs->print = 0;
3101 bs->print_it = print_it_noop;
3102 }
3103 }
3104
3105 bs->next = NULL; /* Terminate the chain */
3106 bs = root_bs->next; /* Re-grab the head of the chain */
3107
3108 /* If we aren't stopping, the value of some hardware watchpoint may
3109 not have changed, but the intermediate memory locations we are
3110 watching may have. Don't bother if we're stopping; this will get
3111 done later. */
3112 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3113 if (bs->stop)
3114 break;
3115
3116 if (bs == NULL)
3117 for (bs = root_bs->next; bs != NULL; bs = bs->next)
3118 if (!bs->stop
3119 && bs->breakpoint_at->owner
3120 && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint
3121 || bs->breakpoint_at->owner->type == bp_read_watchpoint
3122 || bs->breakpoint_at->owner->type == bp_access_watchpoint))
3123 {
3124 /* remove/insert can invalidate bs->breakpoint_at, if this
3125 location is no longer used by the watchpoint. Prevent
3126 further code from trying to use it. */
3127 bs->breakpoint_at = NULL;
3128 remove_breakpoints ();
3129 insert_breakpoints ();
3130 break;
3131 }
3132
3133 return root_bs->next;
3134}
3135\f
3136/* Tell what to do about this bpstat. */
3137struct bpstat_what
3138bpstat_what (bpstat bs)
3139{
3140 /* Classify each bpstat as one of the following. */
3141 enum class
3142 {
3143 /* This bpstat element has no effect on the main_action. */
3144 no_effect = 0,
3145
3146 /* There was a watchpoint, stop but don't print. */
3147 wp_silent,
3148
3149 /* There was a watchpoint, stop and print. */
3150 wp_noisy,
3151
3152 /* There was a breakpoint but we're not stopping. */
3153 bp_nostop,
3154
3155 /* There was a breakpoint, stop but don't print. */
3156 bp_silent,
3157
3158 /* There was a breakpoint, stop and print. */
3159 bp_noisy,
3160
3161 /* We hit the longjmp breakpoint. */
3162 long_jump,
3163
3164 /* We hit the longjmp_resume breakpoint. */
3165 long_resume,
3166
3167 /* We hit the step_resume breakpoint. */
3168 step_resume,
3169
3170 /* We hit the shared library event breakpoint. */
3171 shlib_event,
3172
3173 /* We caught a shared library event. */
3174 catch_shlib_event,
3175
3176 /* This is just used to count how many enums there are. */
3177 class_last
3178 };
3179
3180 /* Here is the table which drives this routine. So that we can
3181 format it pretty, we define some abbreviations for the
3182 enum bpstat_what codes. */
3183#define kc BPSTAT_WHAT_KEEP_CHECKING
3184#define ss BPSTAT_WHAT_STOP_SILENT
3185#define sn BPSTAT_WHAT_STOP_NOISY
3186#define sgl BPSTAT_WHAT_SINGLE
3187#define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3188#define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3189#define sr BPSTAT_WHAT_STEP_RESUME
3190#define shl BPSTAT_WHAT_CHECK_SHLIBS
3191#define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3192
3193/* "Can't happen." Might want to print an error message.
3194 abort() is not out of the question, but chances are GDB is just
3195 a bit confused, not unusable. */
3196#define err BPSTAT_WHAT_STOP_NOISY
3197
3198 /* Given an old action and a class, come up with a new action. */
3199 /* One interesting property of this table is that wp_silent is the same
3200 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3201 after stopping, the check for whether to step over a breakpoint
3202 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3203 reference to how we stopped. We retain separate wp_silent and
3204 bp_silent codes in case we want to change that someday.
3205
3206 Another possibly interesting property of this table is that
3207 there's a partial ordering, priority-like, of the actions. Once
3208 you've decided that some action is appropriate, you'll never go
3209 back and decide something of a lower priority is better. The
3210 ordering is:
3211
3212 kc < clr sgl shl shlr slr sn sr ss
3213 sgl < shl shlr slr sn sr ss
3214 slr < err shl shlr sn sr ss
3215 clr < err shl shlr sn sr ss
3216 ss < shl shlr sn sr
3217 sn < shl shlr sr
3218 shl < shlr sr
3219 shlr < sr
3220 sr <
3221
3222 What I think this means is that we don't need a damned table
3223 here. If you just put the rows and columns in the right order,
3224 it'd look awfully regular. We could simply walk the bpstat list
3225 and choose the highest priority action we find, with a little
3226 logic to handle the 'err' cases. */
3227
3228 /* step_resume entries: a step resume breakpoint overrides another
3229 breakpoint of signal handling (see comment in wait_for_inferior
3230 at where we set the step_resume breakpoint). */
3231
3232 static const enum bpstat_what_main_action
3233 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
3234 {
3235 /* old action */
3236 /* kc ss sn sgl slr clr sr shl shlr
3237 */
3238/*no_effect */
3239 {kc, ss, sn, sgl, slr, clr, sr, shl, shlr},
3240/*wp_silent */
3241 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3242/*wp_noisy */
3243 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3244/*bp_nostop */
3245 {sgl, ss, sn, sgl, slr, slr, sr, shl, shlr},
3246/*bp_silent */
3247 {ss, ss, sn, ss, ss, ss, sr, shl, shlr},
3248/*bp_noisy */
3249 {sn, sn, sn, sn, sn, sn, sr, shl, shlr},
3250/*long_jump */
3251 {slr, ss, sn, slr, slr, err, sr, shl, shlr},
3252/*long_resume */
3253 {clr, ss, sn, err, err, err, sr, shl, shlr},
3254/*step_resume */
3255 {sr, sr, sr, sr, sr, sr, sr, sr, sr},
3256/*shlib */
3257 {shl, shl, shl, shl, shl, shl, sr, shl, shlr},
3258/*catch_shlib */
3259 {shlr, shlr, shlr, shlr, shlr, shlr, sr, shlr, shlr}
3260 };
3261
3262#undef kc
3263#undef ss
3264#undef sn
3265#undef sgl
3266#undef slr
3267#undef clr
3268#undef err
3269#undef sr
3270#undef ts
3271#undef shl
3272#undef shlr
3273 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3274 struct bpstat_what retval;
3275
3276 retval.call_dummy = 0;
3277 for (; bs != NULL; bs = bs->next)
3278 {
3279 enum class bs_class = no_effect;
3280 if (bs->breakpoint_at == NULL)
3281 /* I suspect this can happen if it was a momentary breakpoint
3282 which has since been deleted. */
3283 continue;
3284 if (bs->breakpoint_at->owner == NULL)
3285 bs_class = bp_nostop;
3286 else
3287 switch (bs->breakpoint_at->owner->type)
3288 {
3289 case bp_none:
3290 continue;
3291
3292 case bp_breakpoint:
3293 case bp_hardware_breakpoint:
3294 case bp_until:
3295 case bp_finish:
3296 if (bs->stop)
3297 {
3298 if (bs->print)
3299 bs_class = bp_noisy;
3300 else
3301 bs_class = bp_silent;
3302 }
3303 else
3304 bs_class = bp_nostop;
3305 break;
3306 case bp_watchpoint:
3307 case bp_hardware_watchpoint:
3308 case bp_read_watchpoint:
3309 case bp_access_watchpoint:
3310 if (bs->stop)
3311 {
3312 if (bs->print)
3313 bs_class = wp_noisy;
3314 else
3315 bs_class = wp_silent;
3316 }
3317 else
3318 /* There was a watchpoint, but we're not stopping.
3319 This requires no further action. */
3320 bs_class = no_effect;
3321 break;
3322 case bp_longjmp:
3323 bs_class = long_jump;
3324 break;
3325 case bp_longjmp_resume:
3326 bs_class = long_resume;
3327 break;
3328 case bp_step_resume:
3329 if (bs->stop)
3330 {
3331 bs_class = step_resume;
3332 }
3333 else
3334 /* It is for the wrong frame. */
3335 bs_class = bp_nostop;
3336 break;
3337 case bp_watchpoint_scope:
3338 bs_class = bp_nostop;
3339 break;
3340 case bp_shlib_event:
3341 bs_class = shlib_event;
3342 break;
3343 case bp_thread_event:
3344 case bp_overlay_event:
3345 bs_class = bp_nostop;
3346 break;
3347 case bp_catch_load:
3348 case bp_catch_unload:
3349 /* Only if this catchpoint triggered should we cause the
3350 step-out-of-dld behaviour. Otherwise, we ignore this
3351 catchpoint. */
3352 if (bs->stop)
3353 bs_class = catch_shlib_event;
3354 else
3355 bs_class = no_effect;
3356 break;
3357 case bp_catch_fork:
3358 case bp_catch_vfork:
3359 case bp_catch_exec:
3360 if (bs->stop)
3361 {
3362 if (bs->print)
3363 bs_class = bp_noisy;
3364 else
3365 bs_class = bp_silent;
3366 }
3367 else
3368 /* There was a catchpoint, but we're not stopping.
3369 This requires no further action. */
3370 bs_class = no_effect;
3371 break;
3372 case bp_call_dummy:
3373 /* Make sure the action is stop (silent or noisy),
3374 so infrun.c pops the dummy frame. */
3375 bs_class = bp_silent;
3376 retval.call_dummy = 1;
3377 break;
3378 }
3379 current_action = table[(int) bs_class][(int) current_action];
3380 }
3381 retval.main_action = current_action;
3382 return retval;
3383}
3384
3385/* Nonzero if we should step constantly (e.g. watchpoints on machines
3386 without hardware support). This isn't related to a specific bpstat,
3387 just to things like whether watchpoints are set. */
3388
3389int
3390bpstat_should_step (void)
3391{
3392 struct breakpoint *b;
3393 ALL_BREAKPOINTS (b)
3394 if (breakpoint_enabled (b) && b->type == bp_watchpoint)
3395 return 1;
3396 return 0;
3397}
3398
3399\f
3400
3401/* Given a bpstat that records zero or more triggered eventpoints, this
3402 function returns another bpstat which contains only the catchpoints
3403 on that first list, if any. */
3404void
3405bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3406{
3407 struct bpstats root_bs[1];
3408 bpstat bs = root_bs;
3409 struct breakpoint *ep;
3410 char *dll_pathname;
3411
3412 bpstat_clear (cp_list);
3413 root_bs->next = NULL;
3414
3415 for (; ep_list != NULL; ep_list = ep_list->next)
3416 {
3417 /* Is this eventpoint a catchpoint? If not, ignore it. */
3418 ep = ep_list->breakpoint_at->owner;
3419 if (ep == NULL)
3420 break;
3421 if ((ep->type != bp_catch_load) &&
3422 (ep->type != bp_catch_unload))
3423 /* pai: (temp) ADD fork/vfork here!! */
3424 continue;
3425
3426 /* Yes; add it to the list. */
3427 bs = bpstat_alloc (ep_list->breakpoint_at, bs);
3428 *bs = *ep_list;
3429 bs->next = NULL;
3430 bs = root_bs->next;
3431
3432#if defined(SOLIB_ADD)
3433 /* Also, for each triggered catchpoint, tag it with the name of
3434 the library that caused this trigger. (We copy the name now,
3435 because it's only guaranteed to be available NOW, when the
3436 catchpoint triggers. Clients who may wish to know the name
3437 later must get it from the catchpoint itself.) */
3438 if (ep->triggered_dll_pathname != NULL)
3439 xfree (ep->triggered_dll_pathname);
3440 if (ep->type == bp_catch_load)
3441 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3442 PIDGET (inferior_ptid));
3443 else
3444 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3445 PIDGET (inferior_ptid));
3446#else
3447 dll_pathname = NULL;
3448#endif
3449 if (dll_pathname)
3450 {
3451 ep->triggered_dll_pathname = (char *)
3452 xmalloc (strlen (dll_pathname) + 1);
3453 strcpy (ep->triggered_dll_pathname, dll_pathname);
3454 }
3455 else
3456 ep->triggered_dll_pathname = NULL;
3457 }
3458
3459 *cp_list = bs;
3460}
3461
3462static void print_breakpoint_location (struct breakpoint *b,
3463 struct bp_location *loc,
3464 char *wrap_indent,
3465 struct ui_stream *stb)
3466{
3467 if (b->source_file)
3468 {
3469 struct symbol *sym
3470 = find_pc_sect_function (loc->address, loc->section);
3471 if (sym)
3472 {
3473 ui_out_text (uiout, "in ");
3474 ui_out_field_string (uiout, "func",
3475 SYMBOL_PRINT_NAME (sym));
3476 ui_out_wrap_hint (uiout, wrap_indent);
3477 ui_out_text (uiout, " at ");
3478 }
3479 ui_out_field_string (uiout, "file", b->source_file);
3480 ui_out_text (uiout, ":");
3481
3482 if (ui_out_is_mi_like_p (uiout))
3483 {
3484 struct symtab_and_line sal = find_pc_line (loc->address, 0);
3485 char *fullname = symtab_to_fullname (sal.symtab);
3486
3487 if (fullname)
3488 ui_out_field_string (uiout, "fullname", fullname);
3489 }
3490
3491 ui_out_field_int (uiout, "line", b->line_number);
3492 }
3493 else if (!b->loc)
3494 {
3495 ui_out_field_string (uiout, "pending", b->addr_string);
3496 }
3497 else
3498 {
3499 print_address_symbolic (loc->address, stb->stream, demangle, "");
3500 ui_out_field_stream (uiout, "at", stb);
3501 }
3502}
3503
3504/* Print B to gdb_stdout. */
3505static void
3506print_one_breakpoint_location (struct breakpoint *b,
3507 struct bp_location *loc,
3508 int loc_number,
3509 CORE_ADDR *last_addr)
3510{
3511 struct command_line *l;
3512 struct symbol *sym;
3513 struct ep_type_description
3514 {
3515 enum bptype type;
3516 char *description;
3517 };
3518 static struct ep_type_description bptypes[] =
3519 {
3520 {bp_none, "?deleted?"},
3521 {bp_breakpoint, "breakpoint"},
3522 {bp_hardware_breakpoint, "hw breakpoint"},
3523 {bp_until, "until"},
3524 {bp_finish, "finish"},
3525 {bp_watchpoint, "watchpoint"},
3526 {bp_hardware_watchpoint, "hw watchpoint"},
3527 {bp_read_watchpoint, "read watchpoint"},
3528 {bp_access_watchpoint, "acc watchpoint"},
3529 {bp_longjmp, "longjmp"},
3530 {bp_longjmp_resume, "longjmp resume"},
3531 {bp_step_resume, "step resume"},
3532 {bp_watchpoint_scope, "watchpoint scope"},
3533 {bp_call_dummy, "call dummy"},
3534 {bp_shlib_event, "shlib events"},
3535 {bp_thread_event, "thread events"},
3536 {bp_overlay_event, "overlay events"},
3537 {bp_catch_load, "catch load"},
3538 {bp_catch_unload, "catch unload"},
3539 {bp_catch_fork, "catch fork"},
3540 {bp_catch_vfork, "catch vfork"},
3541 {bp_catch_exec, "catch exec"}
3542 };
3543
3544 static char bpenables[] = "nynny";
3545 char wrap_indent[80];
3546 struct ui_stream *stb = ui_out_stream_new (uiout);
3547 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3548 struct cleanup *bkpt_chain;
3549
3550 int header_of_multiple = 0;
3551 int part_of_multiple = (loc != NULL);
3552
3553 gdb_assert (!loc || loc_number != 0);
3554 /* See comment in print_one_breakpoint concerning
3555 treatment of breakpoints with single disabled
3556 location. */
3557 if (loc == NULL
3558 && (b->loc != NULL
3559 && (b->loc->next != NULL || !b->loc->enabled)))
3560 header_of_multiple = 1;
3561 if (loc == NULL)
3562 loc = b->loc;
3563
3564 annotate_record ();
3565 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3566
3567 /* 1 */
3568 annotate_field (0);
3569 if (part_of_multiple)
3570 {
3571 char *formatted;
3572 formatted = xstrprintf ("%d.%d", b->number, loc_number);
3573 ui_out_field_string (uiout, "number", formatted);
3574 xfree (formatted);
3575 }
3576 else
3577 {
3578 ui_out_field_int (uiout, "number", b->number);
3579 }
3580
3581 /* 2 */
3582 annotate_field (1);
3583 if (part_of_multiple)
3584 ui_out_field_skip (uiout, "type");
3585 else
3586 {
3587 if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0])))
3588 || ((int) b->type != bptypes[(int) b->type].type))
3589 internal_error (__FILE__, __LINE__,
3590 _("bptypes table does not describe type #%d."),
3591 (int) b->type);
3592 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3593 }
3594
3595 /* 3 */
3596 annotate_field (2);
3597 if (part_of_multiple)
3598 ui_out_field_skip (uiout, "disp");
3599 else
3600 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
3601
3602
3603 /* 4 */
3604 annotate_field (3);
3605 if (part_of_multiple)
3606 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n");
3607 else
3608 ui_out_field_fmt (uiout, "enabled", "%c",
3609 bpenables[(int) b->enable_state]);
3610 ui_out_spaces (uiout, 2);
3611
3612
3613 /* 5 and 6 */
3614 strcpy (wrap_indent, " ");
3615 if (addressprint)
3616 {
3617 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3618 strcat (wrap_indent, " ");
3619 else
3620 strcat (wrap_indent, " ");
3621 }
3622
3623 if (b->ops != NULL && b->ops->print_one != NULL)
3624 {
3625 /* Although the print_one can possibly print
3626 all locations, calling it here is not likely
3627 to get any nice result. So, make sure there's
3628 just one location. */
3629 gdb_assert (b->loc == NULL || b->loc->next == NULL);
3630 b->ops->print_one (b, last_addr);
3631 }
3632 else
3633 switch (b->type)
3634 {
3635 case bp_none:
3636 internal_error (__FILE__, __LINE__,
3637 _("print_one_breakpoint: bp_none encountered\n"));
3638 break;
3639
3640 case bp_watchpoint:
3641 case bp_hardware_watchpoint:
3642 case bp_read_watchpoint:
3643 case bp_access_watchpoint:
3644 /* Field 4, the address, is omitted (which makes the columns
3645 not line up too nicely with the headers, but the effect
3646 is relatively readable). */
3647 if (addressprint)
3648 ui_out_field_skip (uiout, "addr");
3649 annotate_field (5);
3650 print_expression (b->exp, stb->stream);
3651 ui_out_field_stream (uiout, "what", stb);
3652 break;
3653
3654 case bp_catch_load:
3655 case bp_catch_unload:
3656 /* Field 4, the address, is omitted (which makes the columns
3657 not line up too nicely with the headers, but the effect
3658 is relatively readable). */
3659 if (addressprint)
3660 ui_out_field_skip (uiout, "addr");
3661 annotate_field (5);
3662 if (b->dll_pathname == NULL)
3663 {
3664 ui_out_field_string (uiout, "what", "<any library>");
3665 ui_out_spaces (uiout, 1);
3666 }
3667 else
3668 {
3669 ui_out_text (uiout, "library \"");
3670 ui_out_field_string (uiout, "what", b->dll_pathname);
3671 ui_out_text (uiout, "\" ");
3672 }
3673 break;
3674
3675 case bp_catch_fork:
3676 case bp_catch_vfork:
3677 /* Field 4, the address, is omitted (which makes the columns
3678 not line up too nicely with the headers, but the effect
3679 is relatively readable). */
3680 if (addressprint)
3681 ui_out_field_skip (uiout, "addr");
3682 annotate_field (5);
3683 if (b->forked_inferior_pid != 0)
3684 {
3685 ui_out_text (uiout, "process ");
3686 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3687 ui_out_spaces (uiout, 1);
3688 }
3689 break;
3690
3691 case bp_catch_exec:
3692 /* Field 4, the address, is omitted (which makes the columns
3693 not line up too nicely with the headers, but the effect
3694 is relatively readable). */
3695 if (addressprint)
3696 ui_out_field_skip (uiout, "addr");
3697 annotate_field (5);
3698 if (b->exec_pathname != NULL)
3699 {
3700 ui_out_text (uiout, "program \"");
3701 ui_out_field_string (uiout, "what", b->exec_pathname);
3702 ui_out_text (uiout, "\" ");
3703 }
3704 break;
3705
3706 case bp_breakpoint:
3707 case bp_hardware_breakpoint:
3708 case bp_until:
3709 case bp_finish:
3710 case bp_longjmp:
3711 case bp_longjmp_resume:
3712 case bp_step_resume:
3713 case bp_watchpoint_scope:
3714 case bp_call_dummy:
3715 case bp_shlib_event:
3716 case bp_thread_event:
3717 case bp_overlay_event:
3718 if (addressprint)
3719 {
3720 annotate_field (4);
3721 if (header_of_multiple)
3722 ui_out_field_string (uiout, "addr", "<MULTIPLE>");
3723 else if (b->loc == NULL || loc->shlib_disabled)
3724 ui_out_field_string (uiout, "addr", "<PENDING>");
3725 else
3726 ui_out_field_core_addr (uiout, "addr", loc->address);
3727 }
3728 annotate_field (5);
3729 if (!header_of_multiple)
3730 print_breakpoint_location (b, loc, wrap_indent, stb);
3731 if (b->loc)
3732 *last_addr = b->loc->address;
3733 break;
3734 }
3735
3736 if (!part_of_multiple && b->thread != -1)
3737 {
3738 /* FIXME: This seems to be redundant and lost here; see the
3739 "stop only in" line a little further down. */
3740 ui_out_text (uiout, " thread ");
3741 ui_out_field_int (uiout, "thread", b->thread);
3742 }
3743
3744 ui_out_text (uiout, "\n");
3745
3746 if (part_of_multiple && frame_id_p (b->frame_id))
3747 {
3748 annotate_field (6);
3749 ui_out_text (uiout, "\tstop only in stack frame at ");
3750 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3751 the frame ID. */
3752 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3753 ui_out_text (uiout, "\n");
3754 }
3755
3756 if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b))
3757 {
3758 /* We do not print the condition for Ada exception catchpoints
3759 because the condition is an internal implementation detail
3760 that we do not want to expose to the user. */
3761 annotate_field (7);
3762 ui_out_text (uiout, "\tstop only if ");
3763 ui_out_field_string (uiout, "cond", b->cond_string);
3764 ui_out_text (uiout, "\n");
3765 }
3766
3767 if (!part_of_multiple && b->thread != -1)
3768 {
3769 /* FIXME should make an annotation for this */
3770 ui_out_text (uiout, "\tstop only in thread ");
3771 ui_out_field_int (uiout, "thread", b->thread);
3772 ui_out_text (uiout, "\n");
3773 }
3774
3775 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count)
3776 {
3777 /* FIXME should make an annotation for this */
3778 if (ep_is_catchpoint (b))
3779 ui_out_text (uiout, "\tcatchpoint");
3780 else
3781 ui_out_text (uiout, "\tbreakpoint");
3782 ui_out_text (uiout, " already hit ");
3783 ui_out_field_int (uiout, "times", b->hit_count);
3784 if (b->hit_count == 1)
3785 ui_out_text (uiout, " time\n");
3786 else
3787 ui_out_text (uiout, " times\n");
3788 }
3789
3790 /* Output the count also if it is zero, but only if this is
3791 mi. FIXME: Should have a better test for this. */
3792 if (ui_out_is_mi_like_p (uiout))
3793 if (!part_of_multiple && show_breakpoint_hit_counts && b->hit_count == 0)
3794 ui_out_field_int (uiout, "times", b->hit_count);
3795
3796 if (!part_of_multiple && b->ignore_count)
3797 {
3798 annotate_field (8);
3799 ui_out_text (uiout, "\tignore next ");
3800 ui_out_field_int (uiout, "ignore", b->ignore_count);
3801 ui_out_text (uiout, " hits\n");
3802 }
3803
3804 if (!part_of_multiple && (l = b->commands))
3805 {
3806 struct cleanup *script_chain;
3807
3808 annotate_field (9);
3809 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3810 print_command_lines (uiout, l, 4);
3811 do_cleanups (script_chain);
3812 }
3813
3814 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple)
3815 {
3816 if (b->addr_string)
3817 ui_out_field_string (uiout, "original-location", b->addr_string);
3818 else if (b->exp_string)
3819 ui_out_field_string (uiout, "original-location", b->exp_string);
3820 }
3821
3822 do_cleanups (bkpt_chain);
3823 do_cleanups (old_chain);
3824}
3825
3826static void
3827print_one_breakpoint (struct breakpoint *b,
3828 CORE_ADDR *last_addr)
3829{
3830 print_one_breakpoint_location (b, NULL, 0, last_addr);
3831
3832 /* If this breakpoint has custom print function,
3833 it's already printed. Otherwise, print individual
3834 locations, if any. */
3835 if (b->ops == NULL || b->ops->print_one == NULL)
3836 {
3837 /* If breakpoint has a single location that is
3838 disabled, we print it as if it had
3839 several locations, since otherwise it's hard to
3840 represent "breakpoint enabled, location disabled"
3841 situation.
3842 Note that while hardware watchpoints have
3843 several locations internally, that's no a property
3844 exposed to user. */
3845 if (b->loc
3846 && !is_hardware_watchpoint (b)
3847 && (b->loc->next || !b->loc->enabled)
3848 && !ui_out_is_mi_like_p (uiout))
3849 {
3850 struct bp_location *loc;
3851 int n = 1;
3852 for (loc = b->loc; loc; loc = loc->next, ++n)
3853 print_one_breakpoint_location (b, loc, n, last_addr);
3854 }
3855 }
3856}
3857
3858
3859struct captured_breakpoint_query_args
3860 {
3861 int bnum;
3862 };
3863
3864static int
3865do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3866{
3867 struct captured_breakpoint_query_args *args = data;
3868 struct breakpoint *b;
3869 CORE_ADDR dummy_addr = 0;
3870 ALL_BREAKPOINTS (b)
3871 {
3872 if (args->bnum == b->number)
3873 {
3874 print_one_breakpoint (b, &dummy_addr);
3875 return GDB_RC_OK;
3876 }
3877 }
3878 return GDB_RC_NONE;
3879}
3880
3881enum gdb_rc
3882gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message)
3883{
3884 struct captured_breakpoint_query_args args;
3885 args.bnum = bnum;
3886 /* For the moment we don't trust print_one_breakpoint() to not throw
3887 an error. */
3888 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
3889 error_message, RETURN_MASK_ALL) < 0)
3890 return GDB_RC_FAIL;
3891 else
3892 return GDB_RC_OK;
3893}
3894
3895/* Return non-zero if B is user settable (breakpoints, watchpoints,
3896 catchpoints, et.al.). */
3897
3898static int
3899user_settable_breakpoint (const struct breakpoint *b)
3900{
3901 return (b->type == bp_breakpoint
3902 || b->type == bp_catch_load
3903 || b->type == bp_catch_unload
3904 || b->type == bp_catch_fork
3905 || b->type == bp_catch_vfork
3906 || b->type == bp_catch_exec
3907 || b->type == bp_hardware_breakpoint
3908 || b->type == bp_watchpoint
3909 || b->type == bp_read_watchpoint
3910 || b->type == bp_access_watchpoint
3911 || b->type == bp_hardware_watchpoint);
3912}
3913
3914/* Print information on user settable breakpoint (watchpoint, etc)
3915 number BNUM. If BNUM is -1 print all user settable breakpoints.
3916 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3917
3918static void
3919breakpoint_1 (int bnum, int allflag)
3920{
3921 struct breakpoint *b;
3922 CORE_ADDR last_addr = (CORE_ADDR) -1;
3923 int nr_printable_breakpoints;
3924 struct cleanup *bkpttbl_chain;
3925
3926 /* Compute the number of rows in the table. */
3927 nr_printable_breakpoints = 0;
3928 ALL_BREAKPOINTS (b)
3929 if (bnum == -1
3930 || bnum == b->number)
3931 {
3932 if (allflag || user_settable_breakpoint (b))
3933 nr_printable_breakpoints++;
3934 }
3935
3936 if (addressprint)
3937 bkpttbl_chain
3938 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3939 "BreakpointTable");
3940 else
3941 bkpttbl_chain
3942 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3943 "BreakpointTable");
3944
3945 if (nr_printable_breakpoints > 0)
3946 annotate_breakpoints_headers ();
3947 if (nr_printable_breakpoints > 0)
3948 annotate_field (0);
3949 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */
3950 if (nr_printable_breakpoints > 0)
3951 annotate_field (1);
3952 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3953 if (nr_printable_breakpoints > 0)
3954 annotate_field (2);
3955 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3956 if (nr_printable_breakpoints > 0)
3957 annotate_field (3);
3958 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3959 if (addressprint)
3960 {
3961 if (nr_printable_breakpoints > 0)
3962 annotate_field (4);
3963 if (gdbarch_addr_bit (current_gdbarch) <= 32)
3964 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3965 else
3966 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3967 }
3968 if (nr_printable_breakpoints > 0)
3969 annotate_field (5);
3970 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3971 ui_out_table_body (uiout);
3972 if (nr_printable_breakpoints > 0)
3973 annotate_breakpoints_table ();
3974
3975 ALL_BREAKPOINTS (b)
3976 if (bnum == -1
3977 || bnum == b->number)
3978 {
3979 /* We only print out user settable breakpoints unless the
3980 allflag is set. */
3981 if (allflag || user_settable_breakpoint (b))
3982 print_one_breakpoint (b, &last_addr);
3983 }
3984
3985 do_cleanups (bkpttbl_chain);
3986
3987 if (nr_printable_breakpoints == 0)
3988 {
3989 if (bnum == -1)
3990 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3991 else
3992 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3993 bnum);
3994 }
3995 else
3996 {
3997 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3998 that a comparison of an unsigned with -1 is always false. */
3999 if (last_addr != (CORE_ADDR) -1 && !server_command)
4000 set_next_address (last_addr);
4001 }
4002
4003 /* FIXME? Should this be moved up so that it is only called when
4004 there have been breakpoints? */
4005 annotate_breakpoints_table_end ();
4006}
4007
4008static void
4009breakpoints_info (char *bnum_exp, int from_tty)
4010{
4011 int bnum = -1;
4012
4013 if (bnum_exp)
4014 bnum = parse_and_eval_long (bnum_exp);
4015
4016 breakpoint_1 (bnum, 0);
4017}
4018
4019static void
4020maintenance_info_breakpoints (char *bnum_exp, int from_tty)
4021{
4022 int bnum = -1;
4023
4024 if (bnum_exp)
4025 bnum = parse_and_eval_long (bnum_exp);
4026
4027 breakpoint_1 (bnum, 1);
4028}
4029
4030static int
4031breakpoint_has_pc (struct breakpoint *b, CORE_ADDR pc, asection *section)
4032{
4033 struct bp_location *bl = b->loc;
4034 for (; bl; bl = bl->next)
4035 {
4036 if (bl->address == pc
4037 && (!overlay_debugging || bl->section == section))
4038 return 1;
4039 }
4040 return 0;
4041}
4042
4043/* Print a message describing any breakpoints set at PC. */
4044
4045static void
4046describe_other_breakpoints (CORE_ADDR pc, asection *section, int thread)
4047{
4048 int others = 0;
4049 struct breakpoint *b;
4050
4051 ALL_BREAKPOINTS (b)
4052 others += breakpoint_has_pc (b, pc, section);
4053 if (others > 0)
4054 {
4055 if (others == 1)
4056 printf_filtered (_("Note: breakpoint "));
4057 else /* if (others == ???) */
4058 printf_filtered (_("Note: breakpoints "));
4059 ALL_BREAKPOINTS (b)
4060 if (breakpoint_has_pc (b, pc, section))
4061 {
4062 others--;
4063 printf_filtered ("%d", b->number);
4064 if (b->thread == -1 && thread != -1)
4065 printf_filtered (" (all threads)");
4066 else if (b->thread != -1)
4067 printf_filtered (" (thread %d)", b->thread);
4068 printf_filtered ("%s%s ",
4069 ((b->enable_state == bp_disabled ||
4070 b->enable_state == bp_call_disabled)
4071 ? " (disabled)"
4072 : b->enable_state == bp_permanent
4073 ? " (permanent)"
4074 : ""),
4075 (others > 1) ? ","
4076 : ((others == 1) ? " and" : ""));
4077 }
4078 printf_filtered (_("also set at pc "));
4079 fputs_filtered (paddress (pc), gdb_stdout);
4080 printf_filtered (".\n");
4081 }
4082}
4083\f
4084/* Set the default place to put a breakpoint
4085 for the `break' command with no arguments. */
4086
4087void
4088set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
4089 int line)
4090{
4091 default_breakpoint_valid = valid;
4092 default_breakpoint_address = addr;
4093 default_breakpoint_symtab = symtab;
4094 default_breakpoint_line = line;
4095}
4096
4097/* Return true iff it is meaningful to use the address member of
4098 BPT. For some breakpoint types, the address member is irrelevant
4099 and it makes no sense to attempt to compare it to other addresses
4100 (or use it for any other purpose either).
4101
4102 More specifically, each of the following breakpoint types will always
4103 have a zero valued address and we don't want check_duplicates() to mark
4104 breakpoints of any of these types to be a duplicate of an actual
4105 breakpoint at address zero:
4106
4107 bp_watchpoint
4108 bp_hardware_watchpoint
4109 bp_read_watchpoint
4110 bp_access_watchpoint
4111 bp_catch_exec
4112 bp_catch_fork
4113 bp_catch_vork */
4114
4115static int
4116breakpoint_address_is_meaningful (struct breakpoint *bpt)
4117{
4118 enum bptype type = bpt->type;
4119
4120 return (type != bp_watchpoint
4121 && type != bp_hardware_watchpoint
4122 && type != bp_read_watchpoint
4123 && type != bp_access_watchpoint
4124 && type != bp_catch_exec
4125 && type != bp_catch_fork
4126 && type != bp_catch_vfork);
4127}
4128
4129/* Rescan breakpoints at the same address and section as BPT,
4130 marking the first one as "first" and any others as "duplicates".
4131 This is so that the bpt instruction is only inserted once.
4132 If we have a permanent breakpoint at the same place as BPT, make
4133 that one the official one, and the rest as duplicates. */
4134
4135static void
4136check_duplicates_for (CORE_ADDR address, asection *section)
4137{
4138 struct bp_location *b;
4139 int count = 0;
4140 struct bp_location *perm_bp = 0;
4141
4142 ALL_BP_LOCATIONS (b)
4143 if (b->owner->enable_state != bp_disabled
4144 && b->owner->enable_state != bp_call_disabled
4145 && b->enabled
4146 && !b->shlib_disabled
4147 && b->address == address /* address / overlay match */
4148 && (!overlay_debugging || b->section == section)
4149 && breakpoint_address_is_meaningful (b->owner))
4150 {
4151 /* Have we found a permanent breakpoint? */
4152 if (b->owner->enable_state == bp_permanent)
4153 {
4154 perm_bp = b;
4155 break;
4156 }
4157
4158 count++;
4159 b->duplicate = count > 1;
4160 }
4161
4162 /* If we found a permanent breakpoint at this address, go over the
4163 list again and declare all the other breakpoints there to be the
4164 duplicates. */
4165 if (perm_bp)
4166 {
4167 perm_bp->duplicate = 0;
4168
4169 /* Permanent breakpoint should always be inserted. */
4170 if (! perm_bp->inserted)
4171 internal_error (__FILE__, __LINE__,
4172 _("allegedly permanent breakpoint is not "
4173 "actually inserted"));
4174
4175 ALL_BP_LOCATIONS (b)
4176 if (b != perm_bp)
4177 {
4178 if (b->owner->enable_state != bp_disabled
4179 && b->owner->enable_state != bp_call_disabled
4180 && b->enabled && !b->shlib_disabled
4181 && b->address == address /* address / overlay match */
4182 && (!overlay_debugging || b->section == section)
4183 && breakpoint_address_is_meaningful (b->owner))
4184 {
4185 if (b->inserted)
4186 internal_error (__FILE__, __LINE__,
4187 _("another breakpoint was inserted on top of "
4188 "a permanent breakpoint"));
4189
4190 b->duplicate = 1;
4191 }
4192 }
4193 }
4194}
4195
4196static void
4197check_duplicates (struct breakpoint *bpt)
4198{
4199 struct bp_location *bl = bpt->loc;
4200
4201 if (! breakpoint_address_is_meaningful (bpt))
4202 return;
4203
4204 for (; bl; bl = bl->next)
4205 check_duplicates_for (bl->address, bl->section);
4206}
4207
4208static void
4209breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
4210 int bnum, int have_bnum)
4211{
4212 char astr1[40];
4213 char astr2[40];
4214
4215 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8));
4216 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8));
4217 if (have_bnum)
4218 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4219 bnum, astr1, astr2);
4220 else
4221 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2);
4222}
4223
4224/* Adjust a breakpoint's address to account for architectural constraints
4225 on breakpoint placement. Return the adjusted address. Note: Very
4226 few targets require this kind of adjustment. For most targets,
4227 this function is simply the identity function. */
4228
4229static CORE_ADDR
4230adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
4231{
4232 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
4233 {
4234 /* Very few targets need any kind of breakpoint adjustment. */
4235 return bpaddr;
4236 }
4237 else if (bptype == bp_watchpoint
4238 || bptype == bp_hardware_watchpoint
4239 || bptype == bp_read_watchpoint
4240 || bptype == bp_access_watchpoint
4241 || bptype == bp_catch_fork
4242 || bptype == bp_catch_vfork
4243 || bptype == bp_catch_exec)
4244 {
4245 /* Watchpoints and the various bp_catch_* eventpoints should not
4246 have their addresses modified. */
4247 return bpaddr;
4248 }
4249 else
4250 {
4251 CORE_ADDR adjusted_bpaddr;
4252
4253 /* Some targets have architectural constraints on the placement
4254 of breakpoint instructions. Obtain the adjusted address. */
4255 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch,
4256 bpaddr);
4257
4258 /* An adjusted breakpoint address can significantly alter
4259 a user's expectations. Print a warning if an adjustment
4260 is required. */
4261 if (adjusted_bpaddr != bpaddr)
4262 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0);
4263
4264 return adjusted_bpaddr;
4265 }
4266}
4267
4268/* Allocate a struct bp_location. */
4269
4270static struct bp_location *
4271allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
4272{
4273 struct bp_location *loc, *loc_p;
4274
4275 loc = xmalloc (sizeof (struct bp_location));
4276 memset (loc, 0, sizeof (*loc));
4277
4278 loc->owner = bpt;
4279 loc->cond = NULL;
4280 loc->shlib_disabled = 0;
4281 loc->enabled = 1;
4282
4283 switch (bp_type)
4284 {
4285 case bp_breakpoint:
4286 case bp_until:
4287 case bp_finish:
4288 case bp_longjmp:
4289 case bp_longjmp_resume:
4290 case bp_step_resume:
4291 case bp_watchpoint_scope:
4292 case bp_call_dummy:
4293 case bp_shlib_event:
4294 case bp_thread_event:
4295 case bp_overlay_event:
4296 case bp_catch_load:
4297 case bp_catch_unload:
4298 loc->loc_type = bp_loc_software_breakpoint;
4299 break;
4300 case bp_hardware_breakpoint:
4301 loc->loc_type = bp_loc_hardware_breakpoint;
4302 break;
4303 case bp_hardware_watchpoint:
4304 case bp_read_watchpoint:
4305 case bp_access_watchpoint:
4306 loc->loc_type = bp_loc_hardware_watchpoint;
4307 break;
4308 case bp_watchpoint:
4309 case bp_catch_fork:
4310 case bp_catch_vfork:
4311 case bp_catch_exec:
4312 loc->loc_type = bp_loc_other;
4313 break;
4314 default:
4315 internal_error (__FILE__, __LINE__, _("unknown breakpoint type"));
4316 }
4317
4318 return loc;
4319}
4320
4321static void free_bp_location (struct bp_location *loc)
4322{
4323 if (loc->cond)
4324 xfree (loc->cond);
4325
4326 if (loc->function_name)
4327 xfree (loc->function_name);
4328
4329 xfree (loc);
4330}
4331
4332/* Helper to set_raw_breakpoint below. Creates a breakpoint
4333 that has type BPTYPE and has no locations as yet. */
4334
4335static struct breakpoint *
4336set_raw_breakpoint_without_location (enum bptype bptype)
4337{
4338 struct breakpoint *b, *b1;
4339
4340 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4341 memset (b, 0, sizeof (*b));
4342
4343 b->type = bptype;
4344 b->language = current_language->la_language;
4345 b->input_radix = input_radix;
4346 b->thread = -1;
4347 b->enable_state = bp_enabled;
4348 b->next = 0;
4349 b->silent = 0;
4350 b->ignore_count = 0;
4351 b->commands = NULL;
4352 b->frame_id = null_frame_id;
4353 b->dll_pathname = NULL;
4354 b->triggered_dll_pathname = NULL;
4355 b->forked_inferior_pid = 0;
4356 b->exec_pathname = NULL;
4357 b->ops = NULL;
4358 b->condition_not_parsed = 0;
4359
4360 /* Add this breakpoint to the end of the chain
4361 so that a list of breakpoints will come out in order
4362 of increasing numbers. */
4363
4364 b1 = breakpoint_chain;
4365 if (b1 == 0)
4366 breakpoint_chain = b;
4367 else
4368 {
4369 while (b1->next)
4370 b1 = b1->next;
4371 b1->next = b;
4372 }
4373 return b;
4374}
4375
4376/* Initialize loc->function_name. */
4377static void
4378set_breakpoint_location_function (struct bp_location *loc)
4379{
4380 if (loc->owner->type == bp_breakpoint
4381 || loc->owner->type == bp_hardware_breakpoint)
4382 {
4383 find_pc_partial_function (loc->address, &(loc->function_name),
4384 NULL, NULL);
4385 if (loc->function_name)
4386 loc->function_name = xstrdup (loc->function_name);
4387 }
4388}
4389
4390/* set_raw_breakpoint is a low level routine for allocating and
4391 partially initializing a breakpoint of type BPTYPE. The newly
4392 created breakpoint's address, section, source file name, and line
4393 number are provided by SAL. The newly created and partially
4394 initialized breakpoint is added to the breakpoint chain and
4395 is also returned as the value of this function.
4396
4397 It is expected that the caller will complete the initialization of
4398 the newly created breakpoint struct as well as output any status
4399 information regarding the creation of a new breakpoint. In
4400 particular, set_raw_breakpoint does NOT set the breakpoint
4401 number! Care should be taken to not allow an error to occur
4402 prior to completing the initialization of the breakpoint. If this
4403 should happen, a bogus breakpoint will be left on the chain. */
4404
4405struct breakpoint *
4406set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
4407{
4408 struct breakpoint *b = set_raw_breakpoint_without_location (bptype);
4409 CORE_ADDR adjusted_address;
4410
4411 /* Adjust the breakpoint's address prior to allocating a location.
4412 Once we call allocate_bp_location(), that mostly uninitialized
4413 location will be placed on the location chain. Adjustment of the
4414 breakpoint may cause target_read_memory() to be called and we do
4415 not want its scan of the location chain to find a breakpoint and
4416 location that's only been partially initialized. */
4417 adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
4418
4419 b->loc = allocate_bp_location (b, bptype);
4420 b->loc->requested_address = sal.pc;
4421 b->loc->address = adjusted_address;
4422
4423 if (sal.symtab == NULL)
4424 b->source_file = NULL;
4425 else
4426 b->source_file = savestring (sal.symtab->filename,
4427 strlen (sal.symtab->filename));
4428 b->loc->section = sal.section;
4429 b->line_number = sal.line;
4430
4431 set_breakpoint_location_function (b->loc);
4432
4433 breakpoints_changed ();
4434
4435 return b;
4436}
4437
4438
4439/* Note that the breakpoint object B describes a permanent breakpoint
4440 instruction, hard-wired into the inferior's code. */
4441void
4442make_breakpoint_permanent (struct breakpoint *b)
4443{
4444 struct bp_location *bl;
4445 b->enable_state = bp_permanent;
4446
4447 /* By definition, permanent breakpoints are already present in the code.
4448 Mark all locations as inserted. For now, make_breakpoint_permanent
4449 is called in just one place, so it's hard to say if it's reasonable
4450 to have permanent breakpoint with multiple locations or not,
4451 but it's easy to implmement. */
4452 for (bl = b->loc; bl; bl = bl->next)
4453 bl->inserted = 1;
4454}
4455
4456static struct breakpoint *
4457create_internal_breakpoint (CORE_ADDR address, enum bptype type)
4458{
4459 static int internal_breakpoint_number = -1;
4460 struct symtab_and_line sal;
4461 struct breakpoint *b;
4462
4463 init_sal (&sal); /* initialize to zeroes */
4464
4465 sal.pc = address;
4466 sal.section = find_pc_overlay (sal.pc);
4467
4468 b = set_raw_breakpoint (sal, type);
4469 b->number = internal_breakpoint_number--;
4470 b->disposition = disp_donttouch;
4471
4472 return b;
4473}
4474
4475
4476static void
4477create_longjmp_breakpoint (char *func_name)
4478{
4479 struct breakpoint *b;
4480 struct minimal_symbol *m;
4481
4482 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4483 return;
4484 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
4485 update_global_location_list ();
4486}
4487
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. */
4491
4492void
4493set_longjmp_breakpoint (void)
4494{
4495 struct breakpoint *b;
4496
4497 if (gdbarch_get_longjmp_target_p (current_gdbarch))
4498 {
4499 create_longjmp_breakpoint ("longjmp");
4500 create_longjmp_breakpoint ("_longjmp");
4501 create_longjmp_breakpoint ("siglongjmp");
4502 create_longjmp_breakpoint ("_siglongjmp");
4503 }
4504}
4505
4506/* Delete all longjmp breakpoints from THREAD. */
4507void
4508delete_longjmp_breakpoint (int thread)
4509{
4510 struct breakpoint *b, *temp;
4511
4512 ALL_BREAKPOINTS_SAFE (b, temp)
4513 if (b->type == bp_longjmp)
4514 {
4515 if (b->thread == thread)
4516 delete_breakpoint (b);
4517 }
4518}
4519
4520static void
4521create_overlay_event_breakpoint (char *func_name)
4522{
4523 struct breakpoint *b;
4524 struct minimal_symbol *m;
4525
4526 if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL)
4527 return;
4528
4529 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4530 bp_overlay_event);
4531 b->addr_string = xstrdup (func_name);
4532
4533 if (overlay_debugging == ovly_auto)
4534 {
4535 b->enable_state = bp_enabled;
4536 overlay_events_enabled = 1;
4537 }
4538 else
4539 {
4540 b->enable_state = bp_disabled;
4541 overlay_events_enabled = 0;
4542 }
4543 update_global_location_list ();
4544}
4545
4546void
4547enable_overlay_breakpoints (void)
4548{
4549 struct breakpoint *b;
4550
4551 ALL_BREAKPOINTS (b)
4552 if (b->type == bp_overlay_event)
4553 {
4554 b->enable_state = bp_enabled;
4555 update_global_location_list ();
4556 overlay_events_enabled = 1;
4557 }
4558}
4559
4560void
4561disable_overlay_breakpoints (void)
4562{
4563 struct breakpoint *b;
4564
4565 ALL_BREAKPOINTS (b)
4566 if (b->type == bp_overlay_event)
4567 {
4568 b->enable_state = bp_disabled;
4569 update_global_location_list ();
4570 overlay_events_enabled = 0;
4571 }
4572}
4573
4574struct breakpoint *
4575create_thread_event_breakpoint (CORE_ADDR address)
4576{
4577 struct breakpoint *b;
4578
4579 b = create_internal_breakpoint (address, bp_thread_event);
4580
4581 b->enable_state = bp_enabled;
4582 /* addr_string has to be used or breakpoint_re_set will delete me. */
4583 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
4584
4585 update_global_location_list_nothrow ();
4586
4587 return b;
4588}
4589
4590void
4591remove_thread_event_breakpoints (void)
4592{
4593 struct breakpoint *b, *temp;
4594
4595 ALL_BREAKPOINTS_SAFE (b, temp)
4596 if (b->type == bp_thread_event)
4597 delete_breakpoint (b);
4598}
4599
4600struct captured_parse_breakpoint_args
4601 {
4602 char **arg_p;
4603 struct symtabs_and_lines *sals_p;
4604 char ***addr_string_p;
4605 int *not_found_ptr;
4606 };
4607
4608struct lang_and_radix
4609 {
4610 enum language lang;
4611 int radix;
4612 };
4613
4614
4615void
4616remove_solib_event_breakpoints (void)
4617{
4618 struct breakpoint *b, *temp;
4619
4620 ALL_BREAKPOINTS_SAFE (b, temp)
4621 if (b->type == bp_shlib_event)
4622 delete_breakpoint (b);
4623}
4624
4625struct breakpoint *
4626create_solib_event_breakpoint (CORE_ADDR address)
4627{
4628 struct breakpoint *b;
4629
4630 b = create_internal_breakpoint (address, bp_shlib_event);
4631 update_global_location_list_nothrow ();
4632 return b;
4633}
4634
4635/* Disable any breakpoints that are on code in shared libraries. Only
4636 apply to enabled breakpoints, disabled ones can just stay disabled. */
4637
4638void
4639disable_breakpoints_in_shlibs (void)
4640{
4641 struct bp_location *loc;
4642 int disabled_shlib_breaks = 0;
4643
4644 ALL_BP_LOCATIONS (loc)
4645 {
4646 struct breakpoint *b = loc->owner;
4647 /* We apply the check to all breakpoints, including disabled
4648 for those with loc->duplicate set. This is so that when breakpoint
4649 becomes enabled, or the duplicate is removed, gdb will try to insert
4650 all breakpoints. If we don't set shlib_disabled here, we'll try
4651 to insert those breakpoints and fail. */
4652 if (((b->type == bp_breakpoint) || (b->type == bp_hardware_breakpoint))
4653 && !loc->shlib_disabled
4654#ifdef PC_SOLIB
4655 && PC_SOLIB (loc->address)
4656#else
4657 && solib_address (loc->address)
4658#endif
4659 )
4660 {
4661 loc->shlib_disabled = 1;
4662 }
4663 }
4664}
4665
4666/* Disable any breakpoints that are in in an unloaded shared library. Only
4667 apply to enabled breakpoints, disabled ones can just stay disabled. */
4668
4669static void
4670disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
4671{
4672 struct bp_location *loc;
4673 int disabled_shlib_breaks = 0;
4674
4675 ALL_BP_LOCATIONS (loc)
4676 {
4677 struct breakpoint *b = loc->owner;
4678 if ((loc->loc_type == bp_loc_hardware_breakpoint
4679 || loc->loc_type == bp_loc_software_breakpoint)
4680 && !loc->shlib_disabled)
4681 {
4682#ifdef PC_SOLIB
4683 char *so_name = PC_SOLIB (loc->address);
4684#else
4685 char *so_name = solib_address (loc->address);
4686#endif
4687 if (so_name && !strcmp (so_name, solib->so_name))
4688 {
4689 loc->shlib_disabled = 1;
4690 /* At this point, we cannot rely on remove_breakpoint
4691 succeeding so we must mark the breakpoint as not inserted
4692 to prevent future errors occurring in remove_breakpoints. */
4693 loc->inserted = 0;
4694 if (!disabled_shlib_breaks)
4695 {
4696 target_terminal_ours_for_output ();
4697 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4698 so_name);
4699 }
4700 disabled_shlib_breaks = 1;
4701 }
4702 }
4703 }
4704}
4705
4706static void
4707create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4708 enum bptype bp_kind)
4709{
4710 struct symtab_and_line sal;
4711 struct breakpoint *b;
4712 int thread = -1; /* All threads. */
4713
4714 init_sal (&sal);
4715 sal.pc = 0;
4716 sal.symtab = NULL;
4717 sal.line = 0;
4718
4719 b = set_raw_breakpoint (sal, bp_kind);
4720 set_breakpoint_count (breakpoint_count + 1);
4721 b->number = breakpoint_count;
4722 b->cond_string = (cond_string == NULL) ?
4723 NULL : savestring (cond_string, strlen (cond_string));
4724 b->thread = thread;
4725 b->addr_string = NULL;
4726 b->enable_state = bp_enabled;
4727 b->disposition = tempflag ? disp_del : disp_donttouch;
4728 b->forked_inferior_pid = 0;
4729 update_global_location_list ();
4730
4731
4732 mention (b);
4733}
4734
4735static void
4736create_fork_event_catchpoint (int tempflag, char *cond_string)
4737{
4738 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4739}
4740
4741static void
4742create_vfork_event_catchpoint (int tempflag, char *cond_string)
4743{
4744 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4745}
4746
4747static void
4748create_exec_event_catchpoint (int tempflag, char *cond_string)
4749{
4750 struct symtab_and_line sal;
4751 struct breakpoint *b;
4752 int thread = -1; /* All threads. */
4753
4754 init_sal (&sal);
4755 sal.pc = 0;
4756 sal.symtab = NULL;
4757 sal.line = 0;
4758
4759 b = set_raw_breakpoint (sal, bp_catch_exec);
4760 set_breakpoint_count (breakpoint_count + 1);
4761 b->number = breakpoint_count;
4762 b->cond_string = (cond_string == NULL) ?
4763 NULL : savestring (cond_string, strlen (cond_string));
4764 b->thread = thread;
4765 b->addr_string = NULL;
4766 b->enable_state = bp_enabled;
4767 b->disposition = tempflag ? disp_del : disp_donttouch;
4768 update_global_location_list ();
4769
4770 mention (b);
4771}
4772
4773static int
4774hw_breakpoint_used_count (void)
4775{
4776 struct breakpoint *b;
4777 int i = 0;
4778
4779 ALL_BREAKPOINTS (b)
4780 {
4781 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4782 i++;
4783 }
4784
4785 return i;
4786}
4787
4788static int
4789hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4790{
4791 struct breakpoint *b;
4792 int i = 0;
4793
4794 *other_type_used = 0;
4795 ALL_BREAKPOINTS (b)
4796 {
4797 if (breakpoint_enabled (b))
4798 {
4799 if (b->type == type)
4800 i++;
4801 else if ((b->type == bp_hardware_watchpoint ||
4802 b->type == bp_read_watchpoint ||
4803 b->type == bp_access_watchpoint))
4804 *other_type_used = 1;
4805 }
4806 }
4807 return i;
4808}
4809
4810void
4811disable_watchpoints_before_interactive_call_start (void)
4812{
4813 struct breakpoint *b;
4814
4815 ALL_BREAKPOINTS (b)
4816 {
4817 if (((b->type == bp_watchpoint)
4818 || (b->type == bp_hardware_watchpoint)
4819 || (b->type == bp_read_watchpoint)
4820 || (b->type == bp_access_watchpoint))
4821 && breakpoint_enabled (b))
4822 {
4823 b->enable_state = bp_call_disabled;
4824 update_global_location_list ();
4825 }
4826 }
4827}
4828
4829void
4830enable_watchpoints_after_interactive_call_stop (void)
4831{
4832 struct breakpoint *b;
4833
4834 ALL_BREAKPOINTS (b)
4835 {
4836 if (((b->type == bp_watchpoint)
4837 || (b->type == bp_hardware_watchpoint)
4838 || (b->type == bp_read_watchpoint)
4839 || (b->type == bp_access_watchpoint))
4840 && (b->enable_state == bp_call_disabled))
4841 {
4842 b->enable_state = bp_enabled;
4843 update_global_location_list ();
4844 }
4845 }
4846}
4847
4848
4849/* Set a breakpoint that will evaporate an end of command
4850 at address specified by SAL.
4851 Restrict it to frame FRAME if FRAME is nonzero. */
4852
4853struct breakpoint *
4854set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4855 enum bptype type)
4856{
4857 struct breakpoint *b;
4858 b = set_raw_breakpoint (sal, type);
4859 b->enable_state = bp_enabled;
4860 b->disposition = disp_donttouch;
4861 b->frame_id = frame_id;
4862
4863 /* If we're debugging a multi-threaded program, then we
4864 want momentary breakpoints to be active in only a
4865 single thread of control. */
4866 if (in_thread_list (inferior_ptid))
4867 b->thread = pid_to_thread_id (inferior_ptid);
4868
4869 update_global_location_list_nothrow ();
4870
4871 return b;
4872}
4873
4874struct breakpoint *
4875set_momentary_breakpoint_at_pc (CORE_ADDR pc, enum bptype type)
4876{
4877 struct symtab_and_line sal;
4878
4879 sal = find_pc_line (pc, 0);
4880 sal.pc = pc;
4881 sal.section = find_pc_overlay (pc);
4882 sal.explicit_pc = 1;
4883
4884 return set_momentary_breakpoint (sal, null_frame_id, type);
4885}
4886\f
4887
4888/* Tell the user we have just set a breakpoint B. */
4889
4890static void
4891mention (struct breakpoint *b)
4892{
4893 int say_where = 0;
4894 struct cleanup *old_chain, *ui_out_chain;
4895 struct ui_stream *stb;
4896
4897 stb = ui_out_stream_new (uiout);
4898 old_chain = make_cleanup_ui_out_stream_delete (stb);
4899
4900 /* FIXME: This is misplaced; mention() is called by things (like
4901 hitting a watchpoint) other than breakpoint creation. It should
4902 be possible to clean this up and at the same time replace the
4903 random calls to breakpoint_changed with this hook, as has already
4904 been done for deprecated_delete_breakpoint_hook and so on. */
4905 if (deprecated_create_breakpoint_hook)
4906 deprecated_create_breakpoint_hook (b);
4907 breakpoint_create_event (b->number);
4908
4909 if (b->ops != NULL && b->ops->print_mention != NULL)
4910 b->ops->print_mention (b);
4911 else
4912 switch (b->type)
4913 {
4914 case bp_none:
4915 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number);
4916 break;
4917 case bp_watchpoint:
4918 ui_out_text (uiout, "Watchpoint ");
4919 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4920 ui_out_field_int (uiout, "number", b->number);
4921 ui_out_text (uiout, ": ");
4922 print_expression (b->exp, stb->stream);
4923 ui_out_field_stream (uiout, "exp", stb);
4924 do_cleanups (ui_out_chain);
4925 break;
4926 case bp_hardware_watchpoint:
4927 ui_out_text (uiout, "Hardware watchpoint ");
4928 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4929 ui_out_field_int (uiout, "number", b->number);
4930 ui_out_text (uiout, ": ");
4931 print_expression (b->exp, stb->stream);
4932 ui_out_field_stream (uiout, "exp", stb);
4933 do_cleanups (ui_out_chain);
4934 break;
4935 case bp_read_watchpoint:
4936 ui_out_text (uiout, "Hardware read watchpoint ");
4937 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4938 ui_out_field_int (uiout, "number", b->number);
4939 ui_out_text (uiout, ": ");
4940 print_expression (b->exp, stb->stream);
4941 ui_out_field_stream (uiout, "exp", stb);
4942 do_cleanups (ui_out_chain);
4943 break;
4944 case bp_access_watchpoint:
4945 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4946 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4947 ui_out_field_int (uiout, "number", b->number);
4948 ui_out_text (uiout, ": ");
4949 print_expression (b->exp, stb->stream);
4950 ui_out_field_stream (uiout, "exp", stb);
4951 do_cleanups (ui_out_chain);
4952 break;
4953 case bp_breakpoint:
4954 if (ui_out_is_mi_like_p (uiout))
4955 {
4956 say_where = 0;
4957 break;
4958 }
4959 if (b->disposition == disp_del)
4960 printf_filtered (_("Temporary breakpoint"));
4961 else
4962 printf_filtered (_("Breakpoint"));
4963 printf_filtered (_(" %d"), b->number);
4964 say_where = 1;
4965 break;
4966 case bp_hardware_breakpoint:
4967 if (ui_out_is_mi_like_p (uiout))
4968 {
4969 say_where = 0;
4970 break;
4971 }
4972 printf_filtered (_("Hardware assisted breakpoint %d"), b->number);
4973 say_where = 1;
4974 break;
4975 case bp_catch_load:
4976 case bp_catch_unload:
4977 printf_filtered (_("Catchpoint %d (%s %s)"),
4978 b->number,
4979 (b->type == bp_catch_load) ? "load" : "unload",
4980 (b->dll_pathname != NULL) ?
4981 b->dll_pathname : "<any library>");
4982 break;
4983 case bp_catch_fork:
4984 case bp_catch_vfork:
4985 printf_filtered (_("Catchpoint %d (%s)"),
4986 b->number,
4987 (b->type == bp_catch_fork) ? "fork" : "vfork");
4988 break;
4989 case bp_catch_exec:
4990 printf_filtered (_("Catchpoint %d (exec)"),
4991 b->number);
4992 break;
4993
4994 case bp_until:
4995 case bp_finish:
4996 case bp_longjmp:
4997 case bp_longjmp_resume:
4998 case bp_step_resume:
4999 case bp_call_dummy:
5000 case bp_watchpoint_scope:
5001 case bp_shlib_event:
5002 case bp_thread_event:
5003 case bp_overlay_event:
5004 break;
5005 }
5006
5007 if (say_where)
5008 {
5009 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5010 single string. */
5011 if (b->loc == NULL)
5012 {
5013 printf_filtered (_(" (%s) pending."), b->addr_string);
5014 }
5015 else
5016 {
5017 if (addressprint || b->source_file == NULL)
5018 {
5019 printf_filtered (" at ");
5020 fputs_filtered (paddress (b->loc->address), gdb_stdout);
5021 }
5022 if (b->source_file)
5023 printf_filtered (": file %s, line %d.",
5024 b->source_file, b->line_number);
5025
5026 if (b->loc->next)
5027 {
5028 struct bp_location *loc = b->loc;
5029 int n = 0;
5030 for (; loc; loc = loc->next)
5031 ++n;
5032 printf_filtered (" (%d locations)", n);
5033 }
5034
5035 }
5036 }
5037 do_cleanups (old_chain);
5038 if (ui_out_is_mi_like_p (uiout))
5039 return;
5040 printf_filtered ("\n");
5041}
5042\f
5043
5044static struct bp_location *
5045add_location_to_breakpoint (struct breakpoint *b, enum bptype bptype,
5046 const struct symtab_and_line *sal)
5047{
5048 struct bp_location *loc, **tmp;
5049
5050 loc = allocate_bp_location (b, bptype);
5051 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next))
5052 ;
5053 *tmp = loc;
5054 loc->requested_address = sal->pc;
5055 loc->address = adjust_breakpoint_address (loc->requested_address,
5056 bptype);
5057 loc->section = sal->section;
5058
5059 set_breakpoint_location_function (loc);
5060 return loc;
5061}
5062
5063/* Create a breakpoint with SAL as location. Use ADDR_STRING
5064 as textual description of the location, and COND_STRING
5065 as condition expression. */
5066
5067static void
5068create_breakpoint (struct symtabs_and_lines sals, char *addr_string,
5069 char *cond_string,
5070 enum bptype type, enum bpdisp disposition,
5071 int thread, int ignore_count,
5072 struct breakpoint_ops *ops, int from_tty)
5073{
5074 struct breakpoint *b = NULL;
5075 int i;
5076
5077 if (type == bp_hardware_breakpoint)
5078 {
5079 int i = hw_breakpoint_used_count ();
5080 int target_resources_ok =
5081 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
5082 i + 1, 0);
5083 if (target_resources_ok == 0)
5084 error (_("No hardware breakpoint support in the target."));
5085 else if (target_resources_ok < 0)
5086 error (_("Hardware breakpoints used exceeds limit."));
5087 }
5088
5089 for (i = 0; i < sals.nelts; ++i)
5090 {
5091 struct symtab_and_line sal = sals.sals[i];
5092 struct bp_location *loc;
5093
5094 if (from_tty)
5095 describe_other_breakpoints (sal.pc, sal.section, thread);
5096
5097 if (i == 0)
5098 {
5099 b = set_raw_breakpoint (sal, type);
5100 set_breakpoint_count (breakpoint_count + 1);
5101 b->number = breakpoint_count;
5102 b->thread = thread;
5103
5104 b->cond_string = cond_string;
5105 b->ignore_count = ignore_count;
5106 b->enable_state = bp_enabled;
5107 b->disposition = disposition;
5108
5109 loc = b->loc;
5110 }
5111 else
5112 {
5113 loc = add_location_to_breakpoint (b, type, &sal);
5114 }
5115
5116 if (b->cond_string)
5117 {
5118 char *arg = b->cond_string;
5119 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0);
5120 if (*arg)
5121 error (_("Garbage %s follows condition"), arg);
5122 }
5123 }
5124
5125 if (addr_string)
5126 b->addr_string = addr_string;
5127 else
5128 /* addr_string has to be used or breakpoint_re_set will delete
5129 me. */
5130 b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
5131
5132 b->ops = ops;
5133 mention (b);
5134}
5135
5136/* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5137 elements to fill the void space. */
5138static void remove_sal (struct symtabs_and_lines *sal, int index_to_remove)
5139{
5140 int i = index_to_remove+1;
5141 int last_index = sal->nelts-1;
5142
5143 for (;i <= last_index; ++i)
5144 sal->sals[i-1] = sal->sals[i];
5145
5146 --(sal->nelts);
5147}
5148
5149/* If appropriate, obtains all sals that correspond
5150 to the same file and line as SAL. This is done
5151 only if SAL does not have explicit PC and has
5152 line and file information. If we got just a single
5153 expanded sal, return the original.
5154
5155 Otherwise, if SAL.explicit_line is not set, filter out
5156 all sals for which the name of enclosing function
5157 is different from SAL. This makes sure that if we have
5158 breakpoint originally set in template instantiation, say
5159 foo<int>(), we won't expand SAL to locations at the same
5160 line in all existing instantiations of 'foo'.
5161
5162*/
5163struct symtabs_and_lines
5164expand_line_sal_maybe (struct symtab_and_line sal)
5165{
5166 struct symtabs_and_lines expanded;
5167 CORE_ADDR original_pc = sal.pc;
5168 char *original_function = NULL;
5169 int found;
5170 int i;
5171
5172 /* If we have explicit pc, don't expand.
5173 If we have no line number, we can't expand. */
5174 if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL)
5175 {
5176 expanded.nelts = 1;
5177 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5178 expanded.sals[0] = sal;
5179 return expanded;
5180 }
5181
5182 sal.pc = 0;
5183 find_pc_partial_function (original_pc, &original_function, NULL, NULL);
5184
5185 expanded = expand_line_sal (sal);
5186 if (expanded.nelts == 1)
5187 {
5188 /* We had one sal, we got one sal. Without futher
5189 processing, just return the original sal. */
5190 xfree (expanded.sals);
5191 expanded.nelts = 1;
5192 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5193 sal.pc = original_pc;
5194 expanded.sals[0] = sal;
5195 return expanded;
5196 }
5197
5198 if (!sal.explicit_line)
5199 {
5200 CORE_ADDR func_addr, func_end;
5201 for (i = 0; i < expanded.nelts; ++i)
5202 {
5203 CORE_ADDR pc = expanded.sals[i].pc;
5204 char *this_function;
5205 if (find_pc_partial_function (pc, &this_function,
5206 &func_addr, &func_end))
5207 {
5208 if (this_function &&
5209 strcmp (this_function, original_function) != 0)
5210 {
5211 remove_sal (&expanded, i);
5212 --i;
5213 }
5214 else if (func_addr == pc)
5215 {
5216 /* We're at beginning of a function, and should
5217 skip prologue. */
5218 struct symbol *sym = find_pc_function (pc);
5219 if (sym)
5220 expanded.sals[i] = find_function_start_sal (sym, 1);
5221 else
5222 expanded.sals[i].pc
5223 = gdbarch_skip_prologue (current_gdbarch, pc);
5224 }
5225 }
5226 }
5227 }
5228
5229
5230 if (expanded.nelts <= 1)
5231 {
5232 /* This is un ugly workaround. If we get zero
5233 expanded sals then something is really wrong.
5234 Fix that by returnign the original sal. */
5235 xfree (expanded.sals);
5236 expanded.nelts = 1;
5237 expanded.sals = xmalloc (sizeof (struct symtab_and_line));
5238 sal.pc = original_pc;
5239 expanded.sals[0] = sal;
5240 return expanded;
5241 }
5242
5243 if (original_pc)
5244 {
5245 found = 0;
5246 for (i = 0; i < expanded.nelts; ++i)
5247 if (expanded.sals[i].pc == original_pc)
5248 {
5249 found = 1;
5250 break;
5251 }
5252 gdb_assert (found);
5253 }
5254
5255 return expanded;
5256}
5257
5258/* Add SALS.nelts breakpoints to the breakpoint table. For each
5259 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5260 value. COND_STRING, if not NULL, specified the condition to be
5261 used for all breakpoints. Essentially the only case where
5262 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5263 function. In that case, it's still not possible to specify
5264 separate conditions for different overloaded functions, so
5265 we take just a single condition string.
5266
5267 NOTE: If the function succeeds, the caller is expected to cleanup
5268 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5269 array contents). If the function fails (error() is called), the
5270 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5271 COND and SALS arrays and each of those arrays contents. */
5272
5273static void
5274create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
5275 char *cond_string,
5276 enum bptype type, enum bpdisp disposition,
5277 int thread, int ignore_count,
5278 struct breakpoint_ops *ops, int from_tty)
5279{
5280 int i;
5281 for (i = 0; i < sals.nelts; ++i)
5282 {
5283 struct symtabs_and_lines expanded =
5284 expand_line_sal_maybe (sals.sals[i]);
5285
5286 create_breakpoint (expanded, addr_string[i],
5287 cond_string, type, disposition,
5288 thread, ignore_count, ops, from_tty);
5289 }
5290
5291 update_global_location_list ();
5292}
5293
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. */
5298
5299static void
5300parse_breakpoint_sals (char **address,
5301 struct symtabs_and_lines *sals,
5302 char ***addr_string,
5303 int *not_found_ptr)
5304{
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])))
5311 {
5312 if (default_breakpoint_valid)
5313 {
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;
5324 }
5325 else
5326 error (_("No default breakpoint address now."));
5327 }
5328 else
5329 {
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 '[' */
5336
5337 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
5338
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);
5349 }
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))
5354 {
5355 int i;
5356 for (i = 0; i < sals->nelts; i++)
5357 {
5358 /* Add the string if not present. */
5359 if ((*addr_string)[i] == NULL)
5360 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
5361 }
5362 }
5363}
5364
5365
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. */
5368
5369static void
5370breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
5371 char *address)
5372{
5373 int i;
5374 for (i = 0; i < sals->nelts; i++)
5375 resolve_sal_pc (&sals->sals[i]);
5376}
5377
5378static void
5379do_captured_parse_breakpoint (struct ui_out *ui, void *data)
5380{
5381 struct captured_parse_breakpoint_args *args = data;
5382
5383 parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p,
5384 args->not_found_ptr);
5385}
5386
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. */
5393static void
5394find_condition_and_thread (char *tok, CORE_ADDR pc,
5395 char **cond_string, int *thread)
5396{
5397 *cond_string = NULL;
5398 *thread = -1;
5399 while (tok && *tok)
5400 {
5401 char *end_tok;
5402 int toklen;
5403 char *cond_start = NULL;
5404 char *cond_end = NULL;
5405 while (*tok == ' ' || *tok == '\t')
5406 tok++;
5407
5408 end_tok = tok;
5409
5410 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5411 end_tok++;
5412
5413 toklen = end_tok - tok;
5414
5415 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5416 {
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);
5422 }
5423 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5424 {
5425 char *tmptok;
5426
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);
5434 }
5435 else
5436 error (_("Junk at end of arguments."));
5437 }
5438}
5439
5440/* Set a breakpoint. This function is shared between
5441 CLI and MI functions for setting a breakpoint.
5442 This function has two major modes of operations,
5443 selected by the PARSE_CONDITION_AND_THREAD parameter.
5444 If non-zero, the function will parse arg, extracting
5445 breakpoint location, address and thread. Otherwise,
5446 ARG is just the location of breakpoint, with condition
5447 and thread specified by the COND_STRING and THREAD
5448 parameters. */
5449
5450static void
5451break_command_really (char *arg, char *cond_string, int thread,
5452 int parse_condition_and_thread,
5453 int tempflag, int hardwareflag,
5454 int ignore_count,
5455 enum auto_boolean pending_break_support,
5456 struct breakpoint_ops *ops,
5457 int from_tty)
5458{
5459 struct gdb_exception e;
5460 struct symtabs_and_lines sals;
5461 struct symtab_and_line pending_sal;
5462 char *copy_arg;
5463 char *err_msg;
5464 char *addr_start = arg;
5465 char **addr_string;
5466 struct cleanup *old_chain;
5467 struct cleanup *breakpoint_chain = NULL;
5468 struct captured_parse_breakpoint_args parse_args;
5469 int i;
5470 int pending = 0;
5471 int not_found = 0;
5472
5473 sals.sals = NULL;
5474 sals.nelts = 0;
5475 addr_string = NULL;
5476
5477 parse_args.arg_p = &arg;
5478 parse_args.sals_p = &sals;
5479 parse_args.addr_string_p = &addr_string;
5480 parse_args.not_found_ptr = &not_found;
5481
5482 e = catch_exception (uiout, do_captured_parse_breakpoint,
5483 &parse_args, RETURN_MASK_ALL);
5484
5485 /* If caller is interested in rc value from parse, set value. */
5486 switch (e.reason)
5487 {
5488 case RETURN_QUIT:
5489 throw_exception (e);
5490 case RETURN_ERROR:
5491 switch (e.error)
5492 {
5493 case NOT_FOUND_ERROR:
5494
5495 /* If pending breakpoint support is turned off, throw
5496 error. */
5497
5498 if (pending_break_support == AUTO_BOOLEAN_FALSE)
5499 throw_exception (e);
5500
5501 exception_print (gdb_stderr, e);
5502
5503 /* If pending breakpoint support is auto query and the user
5504 selects no, then simply return the error code. */
5505 if (pending_break_support == AUTO_BOOLEAN_AUTO &&
5506 !nquery ("Make breakpoint pending on future shared library load? "))
5507 return;
5508
5509 /* At this point, either the user was queried about setting
5510 a pending breakpoint and selected yes, or pending
5511 breakpoint behavior is on and thus a pending breakpoint
5512 is defaulted on behalf of the user. */
5513 copy_arg = xstrdup (addr_start);
5514 addr_string = &copy_arg;
5515 sals.nelts = 1;
5516 sals.sals = &pending_sal;
5517 pending_sal.pc = 0;
5518 pending = 1;
5519 break;
5520 default:
5521 throw_exception (e);
5522 }
5523 default:
5524 if (!sals.nelts)
5525 return;
5526 }
5527
5528 /* Create a chain of things that always need to be cleaned up. */
5529 old_chain = make_cleanup (null_cleanup, 0);
5530
5531 if (!pending)
5532 {
5533 /* Make sure that all storage allocated to SALS gets freed. */
5534 make_cleanup (xfree, sals.sals);
5535
5536 /* Cleanup the addr_string array but not its contents. */
5537 make_cleanup (xfree, addr_string);
5538 }
5539
5540 /* ----------------------------- SNIP -----------------------------
5541 Anything added to the cleanup chain beyond this point is assumed
5542 to be part of a breakpoint. If the breakpoint create succeeds
5543 then the memory is not reclaimed. */
5544 breakpoint_chain = make_cleanup (null_cleanup, 0);
5545
5546 /* Mark the contents of the addr_string for cleanup. These go on
5547 the breakpoint_chain and only occure if the breakpoint create
5548 fails. */
5549 for (i = 0; i < sals.nelts; i++)
5550 {
5551 if (addr_string[i] != NULL)
5552 make_cleanup (xfree, addr_string[i]);
5553 }
5554
5555 /* Resolve all line numbers to PC's and verify that the addresses
5556 are ok for the target. */
5557 if (!pending)
5558 breakpoint_sals_to_pc (&sals, addr_start);
5559
5560 /* Verify that condition can be parsed, before setting any
5561 breakpoints. Allocate a separate condition expression for each
5562 breakpoint. */
5563 if (!pending)
5564 {
5565 if (parse_condition_and_thread)
5566 {
5567 /* Here we only parse 'arg' to separate condition
5568 from thread number, so parsing in context of first
5569 sal is OK. When setting the breakpoint we'll
5570 re-parse it in context of each sal. */
5571 cond_string = NULL;
5572 thread = -1;
5573 find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread);
5574 if (cond_string)
5575 make_cleanup (xfree, cond_string);
5576 }
5577 else
5578 {
5579 /* Create a private copy of condition string. */
5580 if (cond_string)
5581 {
5582 cond_string = xstrdup (cond_string);
5583 make_cleanup (xfree, cond_string);
5584 }
5585 }
5586 create_breakpoints (sals, addr_string, cond_string,
5587 hardwareflag ? bp_hardware_breakpoint
5588 : bp_breakpoint,
5589 tempflag ? disp_del : disp_donttouch,
5590 thread, ignore_count, ops, from_tty);
5591 }
5592 else
5593 {
5594 struct symtab_and_line sal = {0};
5595 struct breakpoint *b;
5596
5597 make_cleanup (xfree, copy_arg);
5598
5599 b = set_raw_breakpoint_without_location (hardwareflag
5600 ? bp_hardware_breakpoint
5601 : bp_breakpoint);
5602 set_breakpoint_count (breakpoint_count + 1);
5603 b->number = breakpoint_count;
5604 b->thread = -1;
5605 b->addr_string = addr_string[0];
5606 b->cond_string = NULL;
5607 b->ignore_count = ignore_count;
5608 b->disposition = tempflag ? disp_del : disp_donttouch;
5609 b->condition_not_parsed = 1;
5610 b->ops = ops;
5611
5612 update_global_location_list ();
5613 mention (b);
5614 }
5615
5616 if (sals.nelts > 1)
5617 warning (_("Multiple breakpoints were set.\n"
5618 "Use the \"delete\" command to delete unwanted breakpoints."));
5619 /* That's it. Discard the cleanups for data inserted into the
5620 breakpoint. */
5621 discard_cleanups (breakpoint_chain);
5622 /* But cleanup everything else. */
5623 do_cleanups (old_chain);
5624}
5625
5626/* Set a breakpoint.
5627 ARG is a string describing breakpoint address,
5628 condition, and thread.
5629 FLAG specifies if a breakpoint is hardware on,
5630 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5631 and BP_TEMPFLAG. */
5632
5633static void
5634break_command_1 (char *arg, int flag, int from_tty)
5635{
5636 int hardwareflag = flag & BP_HARDWAREFLAG;
5637 int tempflag = flag & BP_TEMPFLAG;
5638
5639 break_command_really (arg,
5640 NULL, 0, 1 /* parse arg */,
5641 tempflag, hardwareflag,
5642 0 /* Ignore count */,
5643 pending_break_support,
5644 NULL /* breakpoint_ops */,
5645 from_tty);
5646}
5647
5648
5649void
5650set_breakpoint (char *address, char *condition,
5651 int hardwareflag, int tempflag,
5652 int thread, int ignore_count,
5653 int pending)
5654{
5655 break_command_really (address, condition, thread,
5656 0 /* condition and thread are valid. */,
5657 tempflag, hardwareflag,
5658 ignore_count,
5659 pending
5660 ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
5661 NULL, 0);
5662}
5663
5664/* Adjust SAL to the first instruction past the function prologue.
5665 The end of the prologue is determined using the line table from
5666 the debugging information.
5667
5668 If SAL is already past the prologue, then do nothing. */
5669
5670static void
5671skip_prologue_sal (struct symtab_and_line *sal)
5672{
5673 struct symbol *sym = find_pc_function (sal->pc);
5674 struct symtab_and_line start_sal;
5675
5676 if (sym == NULL)
5677 return;
5678
5679 start_sal = find_function_start_sal (sym, 1);
5680 if (sal->pc < start_sal.pc)
5681 *sal = start_sal;
5682}
5683
5684/* Helper function for break_command_1 and disassemble_command. */
5685
5686void
5687resolve_sal_pc (struct symtab_and_line *sal)
5688{
5689 CORE_ADDR pc;
5690
5691 if (sal->pc == 0 && sal->symtab != NULL)
5692 {
5693 if (!find_line_pc (sal->symtab, sal->line, &pc))
5694 error (_("No line %d in file \"%s\"."),
5695 sal->line, sal->symtab->filename);
5696 sal->pc = pc;
5697
5698 /* If this SAL corresponds to a breakpoint inserted using
5699 a line number, then skip the function prologue if necessary. */
5700 if (sal->explicit_line)
5701 skip_prologue_sal (sal);
5702 }
5703
5704 if (sal->section == 0 && sal->symtab != NULL)
5705 {
5706 struct blockvector *bv;
5707 struct block *b;
5708 struct symbol *sym;
5709
5710 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab);
5711 if (bv != NULL)
5712 {
5713 sym = block_function (b);
5714 if (sym != NULL)
5715 {
5716 fixup_symbol_section (sym, sal->symtab->objfile);
5717 sal->section = SYMBOL_BFD_SECTION (sym);
5718 }
5719 else
5720 {
5721 /* It really is worthwhile to have the section, so we'll just
5722 have to look harder. This case can be executed if we have
5723 line numbers but no functions (as can happen in assembly
5724 source). */
5725
5726 struct minimal_symbol *msym;
5727
5728 msym = lookup_minimal_symbol_by_pc (sal->pc);
5729 if (msym)
5730 sal->section = SYMBOL_BFD_SECTION (msym);
5731 }
5732 }
5733 }
5734}
5735
5736void
5737break_command (char *arg, int from_tty)
5738{
5739 break_command_1 (arg, 0, from_tty);
5740}
5741
5742void
5743tbreak_command (char *arg, int from_tty)
5744{
5745 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5746}
5747
5748static void
5749hbreak_command (char *arg, int from_tty)
5750{
5751 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5752}
5753
5754static void
5755thbreak_command (char *arg, int from_tty)
5756{
5757 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5758}
5759
5760static void
5761stop_command (char *arg, int from_tty)
5762{
5763 printf_filtered (_("Specify the type of breakpoint to set.\n\
5764Usage: stop in <function | address>\n\
5765 stop at <line>\n"));
5766}
5767
5768static void
5769stopin_command (char *arg, int from_tty)
5770{
5771 int badInput = 0;
5772
5773 if (arg == (char *) NULL)
5774 badInput = 1;
5775 else if (*arg != '*')
5776 {
5777 char *argptr = arg;
5778 int hasColon = 0;
5779
5780 /* look for a ':'. If this is a line number specification, then
5781 say it is bad, otherwise, it should be an address or
5782 function/method name */
5783 while (*argptr && !hasColon)
5784 {
5785 hasColon = (*argptr == ':');
5786 argptr++;
5787 }
5788
5789 if (hasColon)
5790 badInput = (*argptr != ':'); /* Not a class::method */
5791 else
5792 badInput = isdigit (*arg); /* a simple line number */
5793 }
5794
5795 if (badInput)
5796 printf_filtered (_("Usage: stop in <function | address>\n"));
5797 else
5798 break_command_1 (arg, 0, from_tty);
5799}
5800
5801static void
5802stopat_command (char *arg, int from_tty)
5803{
5804 int badInput = 0;
5805
5806 if (arg == (char *) NULL || *arg == '*') /* no line number */
5807 badInput = 1;
5808 else
5809 {
5810 char *argptr = arg;
5811 int hasColon = 0;
5812
5813 /* look for a ':'. If there is a '::' then get out, otherwise
5814 it is probably a line number. */
5815 while (*argptr && !hasColon)
5816 {
5817 hasColon = (*argptr == ':');
5818 argptr++;
5819 }
5820
5821 if (hasColon)
5822 badInput = (*argptr == ':'); /* we have class::method */
5823 else
5824 badInput = !isdigit (*arg); /* not a line number */
5825 }
5826
5827 if (badInput)
5828 printf_filtered (_("Usage: stop at <line>\n"));
5829 else
5830 break_command_1 (arg, 0, from_tty);
5831}
5832
5833/* accessflag: hw_write: watch write,
5834 hw_read: watch read,
5835 hw_access: watch access (read or write) */
5836static void
5837watch_command_1 (char *arg, int accessflag, int from_tty)
5838{
5839 struct breakpoint *b, *scope_breakpoint = NULL;
5840 struct symtab_and_line sal;
5841 struct expression *exp;
5842 struct block *exp_valid_block;
5843 struct value *val, *mark;
5844 struct frame_info *frame;
5845 struct frame_info *prev_frame = NULL;
5846 char *exp_start = NULL;
5847 char *exp_end = NULL;
5848 char *tok, *id_tok_start, *end_tok;
5849 int toklen;
5850 char *cond_start = NULL;
5851 char *cond_end = NULL;
5852 struct expression *cond = NULL;
5853 int i, other_type_used, target_resources_ok = 0;
5854 enum bptype bp_type;
5855 int mem_cnt = 0;
5856 int thread = -1;
5857
5858 init_sal (&sal); /* initialize to zeroes */
5859
5860 /* Make sure that we actually have parameters to parse. */
5861 if (arg != NULL && arg[0] != '\0')
5862 {
5863 toklen = strlen (arg); /* Size of argument list. */
5864
5865 /* Points tok to the end of the argument list. */
5866 tok = arg + toklen - 1;
5867
5868 /* Go backwards in the parameters list. Skip the last parameter.
5869 If we're expecting a 'thread <thread_num>' parameter, this should
5870 be the thread identifier. */
5871 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5872 tok--;
5873 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5874 tok--;
5875
5876 /* Points end_tok to the beginning of the last token. */
5877 id_tok_start = tok + 1;
5878
5879 /* Go backwards in the parameters list. Skip one more parameter.
5880 If we're expecting a 'thread <thread_num>' parameter, we should
5881 reach a "thread" token. */
5882 while (tok > arg && (*tok == ' ' || *tok == '\t'))
5883 tok--;
5884
5885 end_tok = tok;
5886
5887 while (tok > arg && (*tok != ' ' && *tok != '\t'))
5888 tok--;
5889
5890 /* Move the pointer forward to skip the whitespace and
5891 calculate the length of the token. */
5892 tok++;
5893 toklen = end_tok - tok;
5894
5895 if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
5896 {
5897 /* At this point we've found a "thread" token, which means
5898 the user is trying to set a watchpoint that triggers
5899 only in a specific thread. */
5900 char *endp;
5901
5902 /* Extract the thread ID from the next token. */
5903 thread = strtol (id_tok_start, &endp, 0);
5904
5905 /* Check if the user provided a valid numeric value for the
5906 thread ID. */
5907 if (*endp != ' ' && *endp != '\t' && *endp != '\0')
5908 error (_("Invalid thread ID specification %s."), id_tok_start);
5909
5910 /* Check if the thread actually exists. */
5911 if (!valid_thread_id (thread))
5912 error (_("Unknown thread %d."), thread);
5913
5914 /* Truncate the string and get rid of the thread <thread_num>
5915 parameter before the parameter list is parsed by the
5916 evaluate_expression() function. */
5917 *tok = '\0';
5918 }
5919 }
5920
5921 /* Parse the rest of the arguments. */
5922 innermost_block = NULL;
5923 exp_start = arg;
5924 exp = parse_exp_1 (&arg, 0, 0);
5925 exp_end = arg;
5926 exp_valid_block = innermost_block;
5927 mark = value_mark ();
5928 fetch_watchpoint_value (exp, &val, NULL, NULL);
5929 if (val != NULL)
5930 release_value (val);
5931
5932 tok = arg;
5933 while (*tok == ' ' || *tok == '\t')
5934 tok++;
5935 end_tok = tok;
5936
5937 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5938 end_tok++;
5939
5940 toklen = end_tok - tok;
5941 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5942 {
5943 tok = cond_start = end_tok + 1;
5944 cond = parse_exp_1 (&tok, 0, 0);
5945 cond_end = tok;
5946 }
5947 if (*tok)
5948 error (_("Junk at end of command."));
5949
5950 if (accessflag == hw_read)
5951 bp_type = bp_read_watchpoint;
5952 else if (accessflag == hw_access)
5953 bp_type = bp_access_watchpoint;
5954 else
5955 bp_type = bp_hardware_watchpoint;
5956
5957 mem_cnt = can_use_hardware_watchpoint (val);
5958 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5959 error (_("Expression cannot be implemented with read/access watchpoint."));
5960 if (mem_cnt != 0)
5961 {
5962 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5963 target_resources_ok =
5964 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5965 other_type_used);
5966 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5967 error (_("Target does not support this type of hardware watchpoint."));
5968
5969 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5970 error (_("Target can only support one kind of HW watchpoint at a time."));
5971 }
5972
5973 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5974 watchpoint could not be set. */
5975 if (!mem_cnt || target_resources_ok <= 0)
5976 bp_type = bp_watchpoint;
5977
5978 frame = block_innermost_frame (exp_valid_block);
5979 if (frame)
5980 prev_frame = get_prev_frame (frame);
5981 else
5982 prev_frame = NULL;
5983
5984 /* If the expression is "local", then set up a "watchpoint scope"
5985 breakpoint at the point where we've left the scope of the watchpoint
5986 expression. Create the scope breakpoint before the watchpoint, so
5987 that we will encounter it first in bpstat_stop_status. */
5988 if (innermost_block && prev_frame)
5989 {
5990 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5991 bp_watchpoint_scope);
5992
5993 scope_breakpoint->enable_state = bp_enabled;
5994
5995 /* Automatically delete the breakpoint when it hits. */
5996 scope_breakpoint->disposition = disp_del;
5997
5998 /* Only break in the proper frame (help with recursion). */
5999 scope_breakpoint->frame_id = get_frame_id (prev_frame);
6000
6001 /* Set the address at which we will stop. */
6002 scope_breakpoint->loc->requested_address
6003 = get_frame_pc (prev_frame);
6004 scope_breakpoint->loc->address
6005 = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
6006 scope_breakpoint->type);
6007 }
6008
6009 /* Now set up the breakpoint. */
6010 b = set_raw_breakpoint (sal, bp_type);
6011 set_breakpoint_count (breakpoint_count + 1);
6012 b->number = breakpoint_count;
6013 b->thread = thread;
6014 b->disposition = disp_donttouch;
6015 b->exp = exp;
6016 b->exp_valid_block = exp_valid_block;
6017 b->exp_string = savestring (exp_start, exp_end - exp_start);
6018 b->val = val;
6019 b->val_valid = 1;
6020 b->loc->cond = cond;
6021 if (cond_start)
6022 b->cond_string = savestring (cond_start, cond_end - cond_start);
6023 else
6024 b->cond_string = 0;
6025
6026 if (frame)
6027 b->watchpoint_frame = get_frame_id (frame);
6028 else
6029 b->watchpoint_frame = null_frame_id;
6030
6031 if (scope_breakpoint != NULL)
6032 {
6033 /* The scope breakpoint is related to the watchpoint. We will
6034 need to act on them together. */
6035 b->related_breakpoint = scope_breakpoint;
6036 scope_breakpoint->related_breakpoint = b;
6037 }
6038
6039 value_free_to_mark (mark);
6040 mention (b);
6041 update_global_location_list ();
6042}
6043
6044/* Return count of locations need to be watched and can be handled
6045 in hardware. If the watchpoint can not be handled
6046 in hardware return zero. */
6047
6048static int
6049can_use_hardware_watchpoint (struct value *v)
6050{
6051 int found_memory_cnt = 0;
6052 struct value *head = v;
6053
6054 /* Did the user specifically forbid us to use hardware watchpoints? */
6055 if (!can_use_hw_watchpoints)
6056 return 0;
6057
6058 /* Make sure that the value of the expression depends only upon
6059 memory contents, and values computed from them within GDB. If we
6060 find any register references or function calls, we can't use a
6061 hardware watchpoint.
6062
6063 The idea here is that evaluating an expression generates a series
6064 of values, one holding the value of every subexpression. (The
6065 expression a*b+c has five subexpressions: a, b, a*b, c, and
6066 a*b+c.) GDB's values hold almost enough information to establish
6067 the criteria given above --- they identify memory lvalues,
6068 register lvalues, computed values, etcetera. So we can evaluate
6069 the expression, and then scan the chain of values that leaves
6070 behind to decide whether we can detect any possible change to the
6071 expression's final value using only hardware watchpoints.
6072
6073 However, I don't think that the values returned by inferior
6074 function calls are special in any way. So this function may not
6075 notice that an expression involving an inferior function call
6076 can't be watched with hardware watchpoints. FIXME. */
6077 for (; v; v = value_next (v))
6078 {
6079 if (VALUE_LVAL (v) == lval_memory)
6080 {
6081 if (value_lazy (v))
6082 /* A lazy memory lvalue is one that GDB never needed to fetch;
6083 we either just used its address (e.g., `a' in `a.b') or
6084 we never needed it at all (e.g., `a' in `a,b'). */
6085 ;
6086 else
6087 {
6088 /* Ahh, memory we actually used! Check if we can cover
6089 it with hardware watchpoints. */
6090 struct type *vtype = check_typedef (value_type (v));
6091
6092 /* We only watch structs and arrays if user asked for it
6093 explicitly, never if they just happen to appear in a
6094 middle of some value chain. */
6095 if (v == head
6096 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
6097 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
6098 {
6099 CORE_ADDR vaddr = VALUE_ADDRESS (v) + value_offset (v);
6100 int len = TYPE_LENGTH (value_type (v));
6101
6102 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
6103 return 0;
6104 else
6105 found_memory_cnt++;
6106 }
6107 }
6108 }
6109 else if (VALUE_LVAL (v) != not_lval
6110 && deprecated_value_modifiable (v) == 0)
6111 return 0; /* ??? What does this represent? */
6112 else if (VALUE_LVAL (v) == lval_register)
6113 return 0; /* cannot watch a register with a HW watchpoint */
6114 }
6115
6116 /* The expression itself looks suitable for using a hardware
6117 watchpoint, but give the target machine a chance to reject it. */
6118 return found_memory_cnt;
6119}
6120
6121void
6122watch_command_wrapper (char *arg, int from_tty)
6123{
6124 watch_command (arg, from_tty);
6125}
6126
6127static void
6128watch_command (char *arg, int from_tty)
6129{
6130 watch_command_1 (arg, hw_write, from_tty);
6131}
6132
6133void
6134rwatch_command_wrapper (char *arg, int from_tty)
6135{
6136 rwatch_command (arg, from_tty);
6137}
6138
6139static void
6140rwatch_command (char *arg, int from_tty)
6141{
6142 watch_command_1 (arg, hw_read, from_tty);
6143}
6144
6145void
6146awatch_command_wrapper (char *arg, int from_tty)
6147{
6148 awatch_command (arg, from_tty);
6149}
6150
6151static void
6152awatch_command (char *arg, int from_tty)
6153{
6154 watch_command_1 (arg, hw_access, from_tty);
6155}
6156\f
6157
6158/* Helper routines for the until_command routine in infcmd.c. Here
6159 because it uses the mechanisms of breakpoints. */
6160
6161/* This function is called by fetch_inferior_event via the
6162 cmd_continuation pointer, to complete the until command. It takes
6163 care of cleaning up the temporary breakpoints set up by the until
6164 command. */
6165static void
6166until_break_command_continuation (struct continuation_arg *arg, int error)
6167{
6168 delete_breakpoint ((struct breakpoint *)(arg->data.pointer));
6169 if (arg->next)
6170 delete_breakpoint ((struct breakpoint *)(arg->next->data.pointer));
6171}
6172
6173void
6174until_break_command (char *arg, int from_tty, int anywhere)
6175{
6176 struct symtabs_and_lines sals;
6177 struct symtab_and_line sal;
6178 struct frame_info *frame = get_selected_frame (NULL);
6179 struct frame_info *prev_frame = get_prev_frame (frame);
6180 struct breakpoint *breakpoint;
6181 struct breakpoint *breakpoint2 = NULL;
6182 struct cleanup *old_chain;
6183 struct continuation_arg *arg1;
6184 struct continuation_arg *arg2;
6185
6186
6187 clear_proceed_status ();
6188
6189 /* Set a breakpoint where the user wants it and at return from
6190 this function */
6191
6192 if (default_breakpoint_valid)
6193 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
6194 default_breakpoint_line, (char ***) NULL, NULL);
6195 else
6196 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
6197 0, (char ***) NULL, NULL);
6198
6199 if (sals.nelts != 1)
6200 error (_("Couldn't get information on specified line."));
6201
6202 sal = sals.sals[0];
6203 xfree (sals.sals); /* malloc'd, so freed */
6204
6205 if (*arg)
6206 error (_("Junk at end of arguments."));
6207
6208 resolve_sal_pc (&sal);
6209
6210 if (anywhere)
6211 /* If the user told us to continue until a specified location,
6212 we don't specify a frame at which we need to stop. */
6213 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
6214 else
6215 /* Otherwise, specify the current frame, because we want to stop only
6216 at the very same frame. */
6217 breakpoint = set_momentary_breakpoint (sal, get_frame_id (frame),
6218 bp_until);
6219
6220 old_chain = make_cleanup_delete_breakpoint (breakpoint);
6221
6222 /* Keep within the current frame, or in frames called by the current
6223 one. */
6224 if (prev_frame)
6225 {
6226 sal = find_pc_line (get_frame_pc (prev_frame), 0);
6227 sal.pc = get_frame_pc (prev_frame);
6228 breakpoint2 = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
6229 bp_until);
6230 make_cleanup_delete_breakpoint (breakpoint2);
6231 }
6232
6233 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
6234
6235 /* If we are running asynchronously, and proceed call above has actually
6236 managed to start the target, arrange for breakpoints to be
6237 deleted when the target stops. Otherwise, we're already stopped and
6238 delete breakpoints via cleanup chain. */
6239
6240 if (target_can_async_p () && target_executing)
6241 {
6242 arg1 =
6243 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
6244 arg1->next = NULL;
6245 arg1->data.pointer = breakpoint;
6246
6247 if (breakpoint2)
6248 {
6249 arg2 = (struct continuation_arg *)
6250 xmalloc ( sizeof (struct continuation_arg));
6251 arg2->next = NULL;
6252 arg2->data.pointer = breakpoint2;
6253 arg1->next = arg2;
6254 }
6255
6256 discard_cleanups (old_chain);
6257 add_continuation (until_break_command_continuation, arg1);
6258 }
6259 else
6260 do_cleanups (old_chain);
6261}
6262
6263static void
6264ep_skip_leading_whitespace (char **s)
6265{
6266 if ((s == NULL) || (*s == NULL))
6267 return;
6268 while (isspace (**s))
6269 *s += 1;
6270}
6271
6272/* This function examines a string, and attempts to find a token
6273 that might be an event name in the leading characters. If a
6274 possible match is found, a pointer to the last character of
6275 the token is returned. Else, NULL is returned. */
6276
6277static char *
6278ep_find_event_name_end (char *arg)
6279{
6280 char *s = arg;
6281 char *event_name_end = NULL;
6282
6283 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6284 if (arg == NULL)
6285 return NULL;
6286
6287 /* We break out of the loop when we find a token delimiter.
6288 Basically, we're looking for alphanumerics and underscores;
6289 anything else delimites the token. */
6290 while (*s != '\0')
6291 {
6292 if (!isalnum (*s) && (*s != '_'))
6293 break;
6294 event_name_end = s;
6295 s++;
6296 }
6297
6298 return event_name_end;
6299}
6300
6301
6302/* This function attempts to parse an optional "if <cond>" clause
6303 from the arg string. If one is not found, it returns NULL.
6304
6305 Else, it returns a pointer to the condition string. (It does not
6306 attempt to evaluate the string against a particular block.) And,
6307 it updates arg to point to the first character following the parsed
6308 if clause in the arg string. */
6309
6310static char *
6311ep_parse_optional_if_clause (char **arg)
6312{
6313 char *cond_string;
6314
6315 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
6316 return NULL;
6317
6318 /* Skip the "if" keyword. */
6319 (*arg) += 2;
6320
6321 /* Skip any extra leading whitespace, and record the start of the
6322 condition string. */
6323 ep_skip_leading_whitespace (arg);
6324 cond_string = *arg;
6325
6326 /* Assume that the condition occupies the remainder of the arg string. */
6327 (*arg) += strlen (cond_string);
6328
6329 return cond_string;
6330}
6331
6332/* This function attempts to parse an optional filename from the arg
6333 string. If one is not found, it returns NULL.
6334
6335 Else, it returns a pointer to the parsed filename. (This function
6336 makes no attempt to verify that a file of that name exists, or is
6337 accessible.) And, it updates arg to point to the first character
6338 following the parsed filename in the arg string.
6339
6340 Note that clients needing to preserve the returned filename for
6341 future access should copy it to their own buffers. */
6342static char *
6343ep_parse_optional_filename (char **arg)
6344{
6345 static char filename[1024];
6346 char *arg_p = *arg;
6347 int i;
6348 char c;
6349
6350 if ((*arg_p == '\0') || isspace (*arg_p))
6351 return NULL;
6352
6353 for (i = 0;; i++)
6354 {
6355 c = *arg_p;
6356 if (isspace (c))
6357 c = '\0';
6358 filename[i] = c;
6359 if (c == '\0')
6360 break;
6361 arg_p++;
6362 }
6363 *arg = arg_p;
6364
6365 return filename;
6366}
6367
6368/* Commands to deal with catching events, such as signals, exceptions,
6369 process start/exit, etc. */
6370
6371typedef enum
6372{
6373 catch_fork, catch_vfork
6374}
6375catch_fork_kind;
6376
6377static void
6378catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
6379 int from_tty)
6380{
6381 char *cond_string = NULL;
6382
6383 ep_skip_leading_whitespace (&arg);
6384
6385 /* The allowed syntax is:
6386 catch [v]fork
6387 catch [v]fork if <cond>
6388
6389 First, check if there's an if clause. */
6390 cond_string = ep_parse_optional_if_clause (&arg);
6391
6392 if ((*arg != '\0') && !isspace (*arg))
6393 error (_("Junk at end of arguments."));
6394
6395 /* If this target supports it, create a fork or vfork catchpoint
6396 and enable reporting of such events. */
6397 switch (fork_kind)
6398 {
6399 case catch_fork:
6400 create_fork_event_catchpoint (tempflag, cond_string);
6401 break;
6402 case catch_vfork:
6403 create_vfork_event_catchpoint (tempflag, cond_string);
6404 break;
6405 default:
6406 error (_("unsupported or unknown fork kind; cannot catch it"));
6407 break;
6408 }
6409}
6410
6411static void
6412catch_exec_command_1 (char *arg, int tempflag, int from_tty)
6413{
6414 char *cond_string = NULL;
6415
6416 ep_skip_leading_whitespace (&arg);
6417
6418 /* The allowed syntax is:
6419 catch exec
6420 catch exec if <cond>
6421
6422 First, check if there's an if clause. */
6423 cond_string = ep_parse_optional_if_clause (&arg);
6424
6425 if ((*arg != '\0') && !isspace (*arg))
6426 error (_("Junk at end of arguments."));
6427
6428 /* If this target supports it, create an exec catchpoint
6429 and enable reporting of such events. */
6430 create_exec_event_catchpoint (tempflag, cond_string);
6431}
6432
6433static void
6434catch_load_command_1 (char *arg, int tempflag, int from_tty)
6435{
6436 char *dll_pathname = NULL;
6437 char *cond_string = NULL;
6438
6439 ep_skip_leading_whitespace (&arg);
6440
6441 /* The allowed syntax is:
6442 catch load
6443 catch load if <cond>
6444 catch load <filename>
6445 catch load <filename> if <cond>
6446
6447 The user is not allowed to specify the <filename> after an
6448 if clause.
6449
6450 We'll ignore the pathological case of a file named "if".
6451
6452 First, check if there's an if clause. If so, then there
6453 cannot be a filename. */
6454 cond_string = ep_parse_optional_if_clause (&arg);
6455
6456 /* If there was an if clause, then there cannot be a filename.
6457 Else, there might be a filename and an if clause. */
6458 if (cond_string == NULL)
6459 {
6460 dll_pathname = ep_parse_optional_filename (&arg);
6461 ep_skip_leading_whitespace (&arg);
6462 cond_string = ep_parse_optional_if_clause (&arg);
6463 }
6464
6465 if ((*arg != '\0') && !isspace (*arg))
6466 error (_("Junk at end of arguments."));
6467
6468 /* Create a load breakpoint that only triggers when a load of
6469 the specified dll (or any dll, if no pathname was specified)
6470 occurs. */
6471 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6472 dll_pathname, cond_string);
6473}
6474
6475static void
6476catch_unload_command_1 (char *arg, int tempflag, int from_tty)
6477{
6478 char *dll_pathname = NULL;
6479 char *cond_string = NULL;
6480
6481 ep_skip_leading_whitespace (&arg);
6482
6483 /* The allowed syntax is:
6484 catch unload
6485 catch unload if <cond>
6486 catch unload <filename>
6487 catch unload <filename> if <cond>
6488
6489 The user is not allowed to specify the <filename> after an
6490 if clause.
6491
6492 We'll ignore the pathological case of a file named "if".
6493
6494 First, check if there's an if clause. If so, then there
6495 cannot be a filename. */
6496 cond_string = ep_parse_optional_if_clause (&arg);
6497
6498 /* If there was an if clause, then there cannot be a filename.
6499 Else, there might be a filename and an if clause. */
6500 if (cond_string == NULL)
6501 {
6502 dll_pathname = ep_parse_optional_filename (&arg);
6503 ep_skip_leading_whitespace (&arg);
6504 cond_string = ep_parse_optional_if_clause (&arg);
6505 }
6506
6507 if ((*arg != '\0') && !isspace (*arg))
6508 error (_("Junk at end of arguments."));
6509
6510 /* Create an unload breakpoint that only triggers when an unload of
6511 the specified dll (or any dll, if no pathname was specified)
6512 occurs. */
6513 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
6514 dll_pathname, cond_string);
6515}
6516
6517static enum print_stop_action
6518print_exception_catchpoint (struct breakpoint *b)
6519{
6520 int bp_temp, bp_throw;
6521
6522 annotate_catchpoint (b->number);
6523
6524 bp_throw = strstr (b->addr_string, "throw") != NULL;
6525 if (b->loc->address != b->loc->requested_address)
6526 breakpoint_adjustment_warning (b->loc->requested_address,
6527 b->loc->address,
6528 b->number, 1);
6529 bp_temp = b->loc->owner->disposition == disp_del;
6530 ui_out_text (uiout,
6531 bp_temp ? "Temporary catchpoint "
6532 : "Catchpoint ");
6533 if (!ui_out_is_mi_like_p (uiout))
6534 ui_out_field_int (uiout, "bkptno", b->number);
6535 ui_out_text (uiout,
6536 bp_throw ? " (exception thrown), "
6537 : " (exception caught), ");
6538 if (ui_out_is_mi_like_p (uiout))
6539 {
6540 ui_out_field_string (uiout, "reason",
6541 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
6542 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
6543 ui_out_field_int (uiout, "bkptno", b->number);
6544 }
6545 return PRINT_SRC_AND_LOC;
6546}
6547
6548static void
6549print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6550{
6551 if (addressprint)
6552 {
6553 annotate_field (4);
6554 if (b->loc == NULL || b->loc->shlib_disabled)
6555 ui_out_field_string (uiout, "addr", "<PENDING>");
6556 else
6557 ui_out_field_core_addr (uiout, "addr", b->loc->address);
6558 }
6559 annotate_field (5);
6560 if (b->loc)
6561 *last_addr = b->loc->address;
6562 if (strstr (b->addr_string, "throw") != NULL)
6563 ui_out_field_string (uiout, "what", "exception throw");
6564 else
6565 ui_out_field_string (uiout, "what", "exception catch");
6566}
6567
6568static void
6569print_mention_exception_catchpoint (struct breakpoint *b)
6570{
6571 int bp_temp;
6572 int bp_throw;
6573
6574 bp_temp = b->loc->owner->disposition == disp_del;
6575 bp_throw = strstr (b->addr_string, "throw") != NULL;
6576 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ")
6577 : _("Catchpoint "));
6578 ui_out_field_int (uiout, "bkptno", b->number);
6579 ui_out_text (uiout, bp_throw ? _(" (throw)")
6580 : _(" (catch)"));
6581}
6582
6583static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6584 print_exception_catchpoint,
6585 print_one_exception_catchpoint,
6586 print_mention_exception_catchpoint
6587};
6588
6589static int
6590handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6591 enum exception_event_kind ex_event, int from_tty)
6592{
6593 char *trigger_func_name;
6594
6595 if (ex_event == EX_EVENT_CATCH)
6596 trigger_func_name = "__cxa_begin_catch";
6597 else
6598 trigger_func_name = "__cxa_throw";
6599
6600 break_command_really (trigger_func_name, cond_string, -1,
6601 0 /* condition and thread are valid. */,
6602 tempflag, 0,
6603 0,
6604 AUTO_BOOLEAN_TRUE /* pending */,
6605 &gnu_v3_exception_catchpoint_ops, from_tty);
6606
6607 return 1;
6608}
6609
6610/* Deal with "catch catch" and "catch throw" commands */
6611
6612static void
6613catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6614 int tempflag, int from_tty)
6615{
6616 char *cond_string = NULL;
6617 struct symtab_and_line *sal = NULL;
6618
6619 ep_skip_leading_whitespace (&arg);
6620
6621 cond_string = ep_parse_optional_if_clause (&arg);
6622
6623 if ((*arg != '\0') && !isspace (*arg))
6624 error (_("Junk at end of arguments."));
6625
6626 if ((ex_event != EX_EVENT_THROW) &&
6627 (ex_event != EX_EVENT_CATCH))
6628 error (_("Unsupported or unknown exception event; cannot catch it"));
6629
6630 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6631 return;
6632
6633 warning (_("Unsupported with this platform/compiler combination."));
6634}
6635
6636/* Create a breakpoint struct for Ada exception catchpoints. */
6637
6638static void
6639create_ada_exception_breakpoint (struct symtab_and_line sal,
6640 char *addr_string,
6641 char *exp_string,
6642 char *cond_string,
6643 struct expression *cond,
6644 struct breakpoint_ops *ops,
6645 int tempflag,
6646 int from_tty)
6647{
6648 struct breakpoint *b;
6649
6650 if (from_tty)
6651 {
6652 describe_other_breakpoints (sal.pc, sal.section, -1);
6653 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6654 version for exception catchpoints, because two catchpoints
6655 used for different exception names will use the same address.
6656 In this case, a "breakpoint ... also set at..." warning is
6657 unproductive. Besides. the warning phrasing is also a bit
6658 inapropriate, we should use the word catchpoint, and tell
6659 the user what type of catchpoint it is. The above is good
6660 enough for now, though. */
6661 }
6662
6663 b = set_raw_breakpoint (sal, bp_breakpoint);
6664 set_breakpoint_count (breakpoint_count + 1);
6665
6666 b->enable_state = bp_enabled;
6667 b->disposition = tempflag ? disp_del : disp_donttouch;
6668 b->number = breakpoint_count;
6669 b->ignore_count = 0;
6670 b->loc->cond = cond;
6671 b->addr_string = addr_string;
6672 b->language = language_ada;
6673 b->cond_string = cond_string;
6674 b->exp_string = exp_string;
6675 b->thread = -1;
6676 b->ops = ops;
6677
6678 mention (b);
6679 update_global_location_list ();
6680}
6681
6682/* Implement the "catch exception" command. */
6683
6684static void
6685catch_ada_exception_command (char *arg, int tempflag, int from_tty)
6686{
6687 struct symtab_and_line sal;
6688 enum bptype type;
6689 char *addr_string = NULL;
6690 char *exp_string = NULL;
6691 char *cond_string = NULL;
6692 struct expression *cond = NULL;
6693 struct breakpoint_ops *ops = NULL;
6694
6695 sal = ada_decode_exception_location (arg, &addr_string, &exp_string,
6696 &cond_string, &cond, &ops);
6697 create_ada_exception_breakpoint (sal, addr_string, exp_string,
6698 cond_string, cond, ops, tempflag,
6699 from_tty);
6700}
6701
6702/* Implement the "catch assert" command. */
6703
6704static void
6705catch_assert_command (char *arg, int tempflag, int from_tty)
6706{
6707 struct symtab_and_line sal;
6708 char *addr_string = NULL;
6709 struct breakpoint_ops *ops = NULL;
6710
6711 sal = ada_decode_assert_location (arg, &addr_string, &ops);
6712 create_ada_exception_breakpoint (sal, addr_string, NULL, NULL, NULL, ops,
6713 tempflag, from_tty);
6714}
6715
6716static void
6717catch_command_1 (char *arg, int tempflag, int from_tty)
6718{
6719
6720 /* The first argument may be an event name, such as "start" or "load".
6721 If so, then handle it as such. If it doesn't match an event name,
6722 then attempt to interpret it as an exception name. (This latter is
6723 the v4.16-and-earlier GDB meaning of the "catch" command.)
6724
6725 First, try to find the bounds of what might be an event name. */
6726 char *arg1_start = arg;
6727 char *arg1_end;
6728 int arg1_length;
6729
6730 if (arg1_start == NULL)
6731 {
6732 /* Old behaviour was to use pre-v-4.16 syntax */
6733 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6734 /* return; */
6735 /* Now, this is not allowed */
6736 error (_("Catch requires an event name."));
6737
6738 }
6739 arg1_end = ep_find_event_name_end (arg1_start);
6740 if (arg1_end == NULL)
6741 error (_("catch requires an event"));
6742 arg1_length = arg1_end + 1 - arg1_start;
6743
6744 /* Try to match what we found against known event names. */
6745 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6746 {
6747 error (_("Catch of signal not yet implemented"));
6748 }
6749 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6750 {
6751 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6752 tempflag, from_tty);
6753 }
6754 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6755 {
6756 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6757 tempflag, from_tty);
6758 }
6759 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6760 {
6761 error (_("Catch of thread_start not yet implemented"));
6762 }
6763 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6764 {
6765 error (_("Catch of thread_exit not yet implemented"));
6766 }
6767 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6768 {
6769 error (_("Catch of thread_join not yet implemented"));
6770 }
6771 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6772 {
6773 error (_("Catch of start not yet implemented"));
6774 }
6775 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6776 {
6777 error (_("Catch of exit not yet implemented"));
6778 }
6779 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6780 {
6781 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6782 }
6783 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6784 {
6785 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6786 }
6787 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6788 {
6789 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6790 }
6791 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6792 {
6793 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6794 }
6795 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6796 {
6797 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6798 }
6799 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6800 {
6801 error (_("Catch of stop not yet implemented"));
6802 }
6803 else if (strncmp (arg1_start, "exception", arg1_length) == 0)
6804 {
6805 catch_ada_exception_command (arg1_end + 1, tempflag, from_tty);
6806 }
6807
6808 else if (strncmp (arg1_start, "assert", arg1_length) == 0)
6809 {
6810 catch_assert_command (arg1_end + 1, tempflag, from_tty);
6811 }
6812
6813 /* This doesn't appear to be an event name */
6814
6815 else
6816 {
6817 /* Pre-v.4.16 behaviour was to treat the argument
6818 as the name of an exception */
6819 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6820 /* Now this is not allowed */
6821 error (_("Unknown event kind specified for catch"));
6822
6823 }
6824}
6825
6826static void
6827catch_command (char *arg, int from_tty)
6828{
6829 catch_command_1 (arg, 0, from_tty);
6830}
6831\f
6832
6833static void
6834tcatch_command (char *arg, int from_tty)
6835{
6836 catch_command_1 (arg, 1, from_tty);
6837}
6838
6839/* Delete breakpoints by address or line. */
6840
6841static void
6842clear_command (char *arg, int from_tty)
6843{
6844 struct breakpoint *b;
6845 VEC(breakpoint_p) *found = 0;
6846 int ix;
6847 int default_match;
6848 struct symtabs_and_lines sals;
6849 struct symtab_and_line sal;
6850 int i;
6851
6852 if (arg)
6853 {
6854 sals = decode_line_spec (arg, 1);
6855 default_match = 0;
6856 }
6857 else
6858 {
6859 sals.sals = (struct symtab_and_line *)
6860 xmalloc (sizeof (struct symtab_and_line));
6861 make_cleanup (xfree, sals.sals);
6862 init_sal (&sal); /* initialize to zeroes */
6863 sal.line = default_breakpoint_line;
6864 sal.symtab = default_breakpoint_symtab;
6865 sal.pc = default_breakpoint_address;
6866 if (sal.symtab == 0)
6867 error (_("No source file specified."));
6868
6869 sals.sals[0] = sal;
6870 sals.nelts = 1;
6871
6872 default_match = 1;
6873 }
6874
6875 /* We don't call resolve_sal_pc here. That's not
6876 as bad as it seems, because all existing breakpoints
6877 typically have both file/line and pc set. So, if
6878 clear is given file/line, we can match this to existing
6879 breakpoint without obtaining pc at all.
6880
6881 We only support clearing given the address explicitly
6882 present in breakpoint table. Say, we've set breakpoint
6883 at file:line. There were several PC values for that file:line,
6884 due to optimization, all in one block.
6885 We've picked one PC value. If "clear" is issued with another
6886 PC corresponding to the same file:line, the breakpoint won't
6887 be cleared. We probably can still clear the breakpoint, but
6888 since the other PC value is never presented to user, user
6889 can only find it by guessing, and it does not seem important
6890 to support that. */
6891
6892 /* For each line spec given, delete bps which correspond
6893 to it. Do it in two passes, solely to preserve the current
6894 behavior that from_tty is forced true if we delete more than
6895 one breakpoint. */
6896
6897 found = NULL;
6898 for (i = 0; i < sals.nelts; i++)
6899 {
6900 /* If exact pc given, clear bpts at that pc.
6901 If line given (pc == 0), clear all bpts on specified line.
6902 If defaulting, clear all bpts on default line
6903 or at default pc.
6904
6905 defaulting sal.pc != 0 tests to do
6906
6907 0 1 pc
6908 1 1 pc _and_ line
6909 0 0 line
6910 1 0 <can't happen> */
6911
6912 sal = sals.sals[i];
6913
6914 /* Find all matching breakpoints and add them to
6915 'found'. */
6916 ALL_BREAKPOINTS (b)
6917 {
6918 int match = 0;
6919 /* Are we going to delete b? */
6920 if (b->type != bp_none
6921 && b->type != bp_watchpoint
6922 && b->type != bp_hardware_watchpoint
6923 && b->type != bp_read_watchpoint
6924 && b->type != bp_access_watchpoint)
6925 {
6926 struct bp_location *loc = b->loc;
6927 for (; loc; loc = loc->next)
6928 {
6929 int pc_match = sal.pc
6930 && (loc->address == sal.pc)
6931 && (!section_is_overlay (loc->section)
6932 || loc->section == sal.section);
6933 int line_match = ((default_match || (0 == sal.pc))
6934 && b->source_file != NULL
6935 && sal.symtab != NULL
6936 && strcmp (b->source_file, sal.symtab->filename) == 0
6937 && b->line_number == sal.line);
6938 if (pc_match || line_match)
6939 {
6940 match = 1;
6941 break;
6942 }
6943 }
6944 }
6945
6946 if (match)
6947 VEC_safe_push(breakpoint_p, found, b);
6948 }
6949 }
6950 /* Now go thru the 'found' chain and delete them. */
6951 if (VEC_empty(breakpoint_p, found))
6952 {
6953 if (arg)
6954 error (_("No breakpoint at %s."), arg);
6955 else
6956 error (_("No breakpoint at this line."));
6957 }
6958
6959 if (VEC_length(breakpoint_p, found) > 1)
6960 from_tty = 1; /* Always report if deleted more than one */
6961 if (from_tty)
6962 {
6963 if (VEC_length(breakpoint_p, found) == 1)
6964 printf_unfiltered (_("Deleted breakpoint "));
6965 else
6966 printf_unfiltered (_("Deleted breakpoints "));
6967 }
6968 breakpoints_changed ();
6969
6970 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
6971 {
6972 if (from_tty)
6973 printf_unfiltered ("%d ", b->number);
6974 delete_breakpoint (b);
6975 }
6976 if (from_tty)
6977 putchar_unfiltered ('\n');
6978}
6979\f
6980/* Delete breakpoint in BS if they are `delete' breakpoints and
6981 all breakpoints that are marked for deletion, whether hit or not.
6982 This is called after any breakpoint is hit, or after errors. */
6983
6984void
6985breakpoint_auto_delete (bpstat bs)
6986{
6987 struct breakpoint *b, *temp;
6988
6989 for (; bs; bs = bs->next)
6990 if (bs->breakpoint_at
6991 && bs->breakpoint_at->owner
6992 && bs->breakpoint_at->owner->disposition == disp_del
6993 && bs->stop)
6994 delete_breakpoint (bs->breakpoint_at->owner);
6995
6996 ALL_BREAKPOINTS_SAFE (b, temp)
6997 {
6998 if (b->disposition == disp_del_at_next_stop)
6999 delete_breakpoint (b);
7000 }
7001}
7002
7003static void
7004update_global_location_list (void)
7005{
7006 struct breakpoint *b;
7007 struct bp_location **next = &bp_location_chain;
7008 struct bp_location *loc;
7009 struct bp_location *loc2;
7010 struct gdb_exception e;
7011 VEC(bp_location_p) *old_locations = NULL;
7012 int ret;
7013 int ix;
7014
7015 /* Store old locations for future reference. */
7016 for (loc = bp_location_chain; loc; loc = loc->global_next)
7017 VEC_safe_push (bp_location_p, old_locations, loc);
7018
7019 bp_location_chain = NULL;
7020 ALL_BREAKPOINTS (b)
7021 {
7022 for (loc = b->loc; loc; loc = loc->next)
7023 {
7024 *next = loc;
7025 next = &(loc->global_next);
7026 *next = NULL;
7027 }
7028 }
7029
7030 /* Identify bp_location instances that are no longer present in the new
7031 list, and therefore should be freed. Note that it's not necessary that
7032 those locations should be removed from inferior -- if there's another
7033 location at the same address (previously marked as duplicate),
7034 we don't need to remove/insert the location. */
7035 for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
7036 {
7037 /* Tells if 'loc' is found amoung the new locations. If not, we
7038 have to free it. */
7039 int found_object = 0;
7040 /* Tells if the location should remain inserted in the target. */
7041 int keep_in_target = 0;
7042 int removed = 0;
7043 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7044 if (loc2 == loc)
7045 {
7046 found_object = 1;
7047 break;
7048 }
7049
7050 /* If this location is no longer present, and inserted, look if there's
7051 maybe a new location at the same address. If so, mark that one
7052 inserted, and don't remove this one. This is needed so that we
7053 don't have a time window where a breakpoint at certain location is not
7054 inserted. */
7055
7056 if (loc->inserted)
7057 {
7058 /* If the location is inserted now, we might have to remove it. */
7059
7060 if (found_object && should_be_inserted (loc))
7061 {
7062 /* The location is still present in the location list, and still
7063 should be inserted. Don't do anything. */
7064 keep_in_target = 1;
7065 }
7066 else
7067 {
7068 /* The location is either no longer present, or got disabled.
7069 See if there's another location at the same address, in which
7070 case we don't need to remove this one from the target. */
7071 if (breakpoint_address_is_meaningful (loc->owner))
7072 for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
7073 {
7074 /* For the sake of should_insert_location. The
7075 call to check_duplicates will fix up this later. */
7076 loc2->duplicate = 0;
7077 if (should_be_inserted (loc2)
7078 && loc2 != loc && loc2->address == loc->address)
7079 {
7080 loc2->inserted = 1;
7081 loc2->target_info = loc->target_info;
7082 keep_in_target = 1;
7083 break;
7084 }
7085 }
7086 }
7087
7088 if (!keep_in_target)
7089 {
7090 if (remove_breakpoint (loc, mark_uninserted))
7091 {
7092 /* This is just about all we can do. We could keep this
7093 location on the global list, and try to remove it next
7094 time, but there's no particular reason why we will
7095 succeed next time.
7096
7097 Note that at this point, loc->owner is still valid,
7098 as delete_breakpoint frees the breakpoint only
7099 after calling us. */
7100 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7101 loc->owner->number);
7102 }
7103 removed = 1;
7104 }
7105 }
7106
7107 if (!found_object)
7108 {
7109 if (removed)
7110 {
7111 /* This location was removed from the targets. In non-stop mode,
7112 a race condition is possible where we've removed a breakpoint,
7113 but stop events for that breakpoint are already queued and will
7114 arrive later. To suppress spurious SIGTRAPs reported to user,
7115 we keep this breakpoint location for a bit, and will retire it
7116 after we see 3 * thread_count events.
7117 The theory here is that reporting of events should,
7118 "on the average", be fair, so after that many event we'll see
7119 events from all threads that have anything of interest, and no
7120 longer need to keep this breakpoint. This is just a
7121 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7122 which is usability issue, but not a correctness problem. */
7123 loc->events_till_retirement = 3 * (thread_count () + 1);
7124 loc->owner = NULL;
7125 }
7126
7127 free_bp_location (loc);
7128 }
7129 }
7130
7131 ALL_BREAKPOINTS (b)
7132 {
7133 check_duplicates (b);
7134 }
7135
7136 if (always_inserted_mode && target_has_execution)
7137 insert_breakpoint_locations ();
7138}
7139
7140void
7141breakpoint_retire_moribund (void)
7142{
7143 struct bp_location *loc;
7144 int ix;
7145
7146 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
7147 if (--(loc->events_till_retirement) == 0)
7148 {
7149 free_bp_location (loc);
7150 VEC_unordered_remove (bp_location_p, moribund_locations, ix);
7151 --ix;
7152 }
7153}
7154
7155static void
7156update_global_location_list_nothrow (void)
7157{
7158 struct gdb_exception e;
7159 TRY_CATCH (e, RETURN_MASK_ERROR)
7160 update_global_location_list ();
7161}
7162
7163/* Delete a breakpoint and clean up all traces of it in the data
7164 structures. */
7165
7166void
7167delete_breakpoint (struct breakpoint *bpt)
7168{
7169 struct breakpoint *b;
7170 bpstat bs;
7171 struct bp_location *loc, *next;
7172
7173 gdb_assert (bpt != NULL);
7174
7175 /* Has this bp already been deleted? This can happen because multiple
7176 lists can hold pointers to bp's. bpstat lists are especial culprits.
7177
7178 One example of this happening is a watchpoint's scope bp. When the
7179 scope bp triggers, we notice that the watchpoint is out of scope, and
7180 delete it. We also delete its scope bp. But the scope bp is marked
7181 "auto-deleting", and is already on a bpstat. That bpstat is then
7182 checked for auto-deleting bp's, which are deleted.
7183
7184 A real solution to this problem might involve reference counts in bp's,
7185 and/or giving them pointers back to their referencing bpstat's, and
7186 teaching delete_breakpoint to only free a bp's storage when no more
7187 references were extent. A cheaper bandaid was chosen. */
7188 if (bpt->type == bp_none)
7189 return;
7190
7191 if (deprecated_delete_breakpoint_hook)
7192 deprecated_delete_breakpoint_hook (bpt);
7193 breakpoint_delete_event (bpt->number);
7194
7195 if (breakpoint_chain == bpt)
7196 breakpoint_chain = bpt->next;
7197
7198 ALL_BREAKPOINTS (b)
7199 if (b->next == bpt)
7200 {
7201 b->next = bpt->next;
7202 break;
7203 }
7204
7205 free_command_lines (&bpt->commands);
7206 if (bpt->cond_string != NULL)
7207 xfree (bpt->cond_string);
7208 if (bpt->addr_string != NULL)
7209 xfree (bpt->addr_string);
7210 if (bpt->exp != NULL)
7211 xfree (bpt->exp);
7212 if (bpt->exp_string != NULL)
7213 xfree (bpt->exp_string);
7214 if (bpt->val != NULL)
7215 value_free (bpt->val);
7216 if (bpt->source_file != NULL)
7217 xfree (bpt->source_file);
7218 if (bpt->dll_pathname != NULL)
7219 xfree (bpt->dll_pathname);
7220 if (bpt->triggered_dll_pathname != NULL)
7221 xfree (bpt->triggered_dll_pathname);
7222 if (bpt->exec_pathname != NULL)
7223 xfree (bpt->exec_pathname);
7224
7225 /* Be sure no bpstat's are pointing at it after it's been freed. */
7226 /* FIXME, how can we find all bpstat's?
7227 We just check stop_bpstat for now. Note that we cannot just
7228 remove bpstats pointing at bpt from the stop_bpstat list
7229 entirely, as breakpoint commands are associated with the bpstat;
7230 if we remove it here, then the later call to
7231 bpstat_do_actions (&stop_bpstat);
7232 in event-top.c won't do anything, and temporary breakpoints
7233 with commands won't work. */
7234 for (bs = stop_bpstat; bs; bs = bs->next)
7235 if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt)
7236 {
7237 bs->breakpoint_at = NULL;
7238 bs->old_val = NULL;
7239 /* bs->commands will be freed later. */
7240 }
7241
7242 /* Now that breakpoint is removed from breakpoint
7243 list, update the global location list. This
7244 will remove locations that used to belong to
7245 this breakpoint. Do this before freeing
7246 the breakpoint itself, since remove_breakpoint
7247 looks at location's owner. It might be better
7248 design to have location completely self-contained,
7249 but it's not the case now. */
7250 update_global_location_list ();
7251
7252
7253 /* On the chance that someone will soon try again to delete this same
7254 bp, we mark it as deleted before freeing its storage. */
7255 bpt->type = bp_none;
7256
7257 xfree (bpt);
7258}
7259
7260static void
7261do_delete_breakpoint_cleanup (void *b)
7262{
7263 delete_breakpoint (b);
7264}
7265
7266struct cleanup *
7267make_cleanup_delete_breakpoint (struct breakpoint *b)
7268{
7269 return make_cleanup (do_delete_breakpoint_cleanup, b);
7270}
7271
7272void
7273delete_command (char *arg, int from_tty)
7274{
7275 struct breakpoint *b, *temp;
7276
7277 dont_repeat ();
7278
7279 if (arg == 0)
7280 {
7281 int breaks_to_delete = 0;
7282
7283 /* Delete all breakpoints if no argument.
7284 Do not delete internal or call-dummy breakpoints, these
7285 have to be deleted with an explicit breakpoint number argument. */
7286 ALL_BREAKPOINTS (b)
7287 {
7288 if (b->type != bp_call_dummy &&
7289 b->type != bp_shlib_event &&
7290 b->type != bp_thread_event &&
7291 b->type != bp_overlay_event &&
7292 b->number >= 0)
7293 {
7294 breaks_to_delete = 1;
7295 break;
7296 }
7297 }
7298
7299 /* Ask user only if there are some breakpoints to delete. */
7300 if (!from_tty
7301 || (breaks_to_delete && query (_("Delete all breakpoints? "))))
7302 {
7303 ALL_BREAKPOINTS_SAFE (b, temp)
7304 {
7305 if (b->type != bp_call_dummy &&
7306 b->type != bp_shlib_event &&
7307 b->type != bp_thread_event &&
7308 b->type != bp_overlay_event &&
7309 b->number >= 0)
7310 delete_breakpoint (b);
7311 }
7312 }
7313 }
7314 else
7315 map_breakpoint_numbers (arg, delete_breakpoint);
7316}
7317
7318static int
7319all_locations_are_pending (struct bp_location *loc)
7320{
7321 for (; loc; loc = loc->next)
7322 if (!loc->shlib_disabled)
7323 return 0;
7324 return 1;
7325}
7326
7327/* Subroutine of update_breakpoint_locations to simplify it.
7328 Return non-zero if multiple fns in list LOC have the same name.
7329 Null names are ignored. */
7330
7331static int
7332ambiguous_names_p (struct bp_location *loc)
7333{
7334 struct bp_location *l;
7335 htab_t htab = htab_create_alloc (13, htab_hash_string,
7336 (int (*) (const void *, const void *)) streq,
7337 NULL, xcalloc, xfree);
7338
7339 for (l = loc; l != NULL; l = l->next)
7340 {
7341 const char **slot;
7342 const char *name = l->function_name;
7343
7344 /* Allow for some names to be NULL, ignore them. */
7345 if (name == NULL)
7346 continue;
7347
7348 slot = (const char **) htab_find_slot (htab, (const void *) name,
7349 INSERT);
7350 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7351 NULL. */
7352 if (*slot != NULL)
7353 {
7354 htab_delete (htab);
7355 return 1;
7356 }
7357 *slot = name;
7358 }
7359
7360 htab_delete (htab);
7361 return 0;
7362}
7363
7364static void
7365update_breakpoint_locations (struct breakpoint *b,
7366 struct symtabs_and_lines sals)
7367{
7368 int i;
7369 char *s;
7370 struct bp_location *existing_locations = b->loc;
7371
7372 /* If there's no new locations, and all existing locations
7373 are pending, don't do anything. This optimizes
7374 the common case where all locations are in the same
7375 shared library, that was unloaded. We'd like to
7376 retain the location, so that when the library
7377 is loaded again, we don't loose the enabled/disabled
7378 status of the individual locations. */
7379 if (all_locations_are_pending (existing_locations) && sals.nelts == 0)
7380 return;
7381
7382 b->loc = NULL;
7383
7384 for (i = 0; i < sals.nelts; ++i)
7385 {
7386 struct bp_location *new_loc =
7387 add_location_to_breakpoint (b, b->type, &(sals.sals[i]));
7388
7389 /* Reparse conditions, they might contain references to the
7390 old symtab. */
7391 if (b->cond_string != NULL)
7392 {
7393 struct gdb_exception e;
7394
7395 s = b->cond_string;
7396 TRY_CATCH (e, RETURN_MASK_ERROR)
7397 {
7398 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc),
7399 0);
7400 }
7401 if (e.reason < 0)
7402 {
7403 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7404 b->number, e.message);
7405 new_loc->enabled = 0;
7406 }
7407 }
7408
7409 if (b->source_file != NULL)
7410 xfree (b->source_file);
7411 if (sals.sals[i].symtab == NULL)
7412 b->source_file = NULL;
7413 else
7414 b->source_file =
7415 savestring (sals.sals[i].symtab->filename,
7416 strlen (sals.sals[i].symtab->filename));
7417
7418 if (b->line_number == 0)
7419 b->line_number = sals.sals[i].line;
7420 }
7421
7422 /* If possible, carry over 'disable' status from existing breakpoints. */
7423 {
7424 struct bp_location *e = existing_locations;
7425 /* If there are multiple breakpoints with the same function name,
7426 e.g. for inline functions, comparing function names won't work.
7427 Instead compare pc addresses; this is just a heuristic as things
7428 may have moved, but in practice it gives the correct answer
7429 often enough until a better solution is found. */
7430 int have_ambiguous_names = ambiguous_names_p (b->loc);
7431
7432 for (; e; e = e->next)
7433 {
7434 if (!e->enabled && e->function_name)
7435 {
7436 struct bp_location *l = b->loc;
7437 if (have_ambiguous_names)
7438 {
7439 for (; l; l = l->next)
7440 if (e->address == l->address)
7441 {
7442 l->enabled = 0;
7443 break;
7444 }
7445 }
7446 else
7447 {
7448 for (; l; l = l->next)
7449 if (l->function_name
7450 && strcmp (e->function_name, l->function_name) == 0)
7451 {
7452 l->enabled = 0;
7453 break;
7454 }
7455 }
7456 }
7457 }
7458 }
7459
7460 update_global_location_list ();
7461}
7462
7463
7464/* Reset a breakpoint given it's struct breakpoint * BINT.
7465 The value we return ends up being the return value from catch_errors.
7466 Unused in this case. */
7467
7468static int
7469breakpoint_re_set_one (void *bint)
7470{
7471 /* get past catch_errs */
7472 struct breakpoint *b = (struct breakpoint *) bint;
7473 struct value *mark;
7474 int i;
7475 int not_found = 0;
7476 int *not_found_ptr = &not_found;
7477 struct symtabs_and_lines sals = {};
7478 struct symtabs_and_lines expanded;
7479 char *s;
7480 enum enable_state save_enable;
7481 struct gdb_exception e;
7482
7483
7484 switch (b->type)
7485 {
7486 case bp_none:
7487 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7488 b->number);
7489 return 0;
7490 case bp_breakpoint:
7491 case bp_hardware_breakpoint:
7492 case bp_catch_load:
7493 case bp_catch_unload:
7494 if (b->addr_string == NULL)
7495 {
7496 /* Anything without a string can't be re-set. */
7497 delete_breakpoint (b);
7498 return 0;
7499 }
7500
7501 set_language (b->language);
7502 input_radix = b->input_radix;
7503 s = b->addr_string;
7504 TRY_CATCH (e, RETURN_MASK_ERROR)
7505 {
7506 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL,
7507 not_found_ptr);
7508 }
7509 if (e.reason < 0)
7510 {
7511 int not_found_and_ok = 0;
7512 /* For pending breakpoints, it's expected that parsing
7513 will fail until the right shared library is loaded.
7514 User has already told to create pending breakpoints and
7515 don't need extra messages. If breakpoint is in bp_shlib_disabled
7516 state, then user already saw the message about that breakpoint
7517 being disabled, and don't want to see more errors. */
7518 if (not_found
7519 && (b->condition_not_parsed
7520 || (b->loc && b->loc->shlib_disabled)
7521 || b->enable_state == bp_disabled))
7522 not_found_and_ok = 1;
7523
7524 if (!not_found_and_ok)
7525 {
7526 /* We surely don't want to warn about the same breakpoint
7527 10 times. One solution, implemented here, is disable
7528 the breakpoint on error. Another solution would be to
7529 have separate 'warning emitted' flag. Since this
7530 happens only when a binary has changed, I don't know
7531 which approach is better. */
7532 b->enable_state = bp_disabled;
7533 throw_exception (e);
7534 }
7535 }
7536
7537 if (not_found)
7538 break;
7539
7540 gdb_assert (sals.nelts == 1);
7541 resolve_sal_pc (&sals.sals[0]);
7542 if (b->condition_not_parsed && s && s[0])
7543 {
7544 char *cond_string = 0;
7545 int thread = -1;
7546 find_condition_and_thread (s, sals.sals[0].pc,
7547 &cond_string, &thread);
7548 if (cond_string)
7549 b->cond_string = cond_string;
7550 b->thread = thread;
7551 b->condition_not_parsed = 0;
7552 }
7553 expanded = expand_line_sal_maybe (sals.sals[0]);
7554 update_breakpoint_locations (b, expanded);
7555
7556 xfree (sals.sals);
7557 break;
7558
7559 case bp_watchpoint:
7560 case bp_hardware_watchpoint:
7561 case bp_read_watchpoint:
7562 case bp_access_watchpoint:
7563 /* Watchpoint can be either on expression using entirely global variables,
7564 or it can be on local variables.
7565
7566 Watchpoints of the first kind are never auto-deleted, and even persist
7567 across program restarts. Since they can use variables from shared
7568 libraries, we need to reparse expression as libraries are loaded
7569 and unloaded.
7570
7571 Watchpoints on local variables can also change meaning as result
7572 of solib event. For example, if a watchpoint uses both a local and
7573 a global variables in expression, it's a local watchpoint, but
7574 unloading of a shared library will make the expression invalid.
7575 This is not a very common use case, but we still re-evaluate
7576 expression, to avoid surprises to the user.
7577
7578 Note that for local watchpoints, we re-evaluate it only if
7579 watchpoints frame id is still valid. If it's not, it means
7580 the watchpoint is out of scope and will be deleted soon. In fact,
7581 I'm not sure we'll ever be called in this case.
7582
7583 If a local watchpoint's frame id is still valid, then
7584 b->exp_valid_block is likewise valid, and we can safely use it.
7585
7586 Don't do anything about disabled watchpoints, since they will
7587 be reevaluated again when enabled. */
7588 update_watchpoint (b, 1 /* reparse */);
7589 break;
7590 /* We needn't really do anything to reset these, since the mask
7591 that requests them is unaffected by e.g., new libraries being
7592 loaded. */
7593 case bp_catch_fork:
7594 case bp_catch_vfork:
7595 case bp_catch_exec:
7596 break;
7597
7598 default:
7599 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type);
7600 /* fall through */
7601 /* Delete overlay event breakpoints; they will be reset later by
7602 breakpoint_re_set. */
7603 case bp_overlay_event:
7604 delete_breakpoint (b);
7605 break;
7606
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:
7610
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:
7614
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 case bp_longjmp:
7625 case bp_longjmp_resume:
7626 break;
7627 }
7628
7629 return 0;
7630}
7631
7632/* Re-set all breakpoints after symbols have been re-loaded. */
7633void
7634breakpoint_re_set (void)
7635{
7636 struct breakpoint *b, *temp;
7637 enum language save_language;
7638 int save_input_radix;
7639
7640 save_language = current_language->la_language;
7641 save_input_radix = input_radix;
7642 ALL_BREAKPOINTS_SAFE (b, temp)
7643 {
7644 /* Format possible error msg */
7645 char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
7646 b->number);
7647 struct cleanup *cleanups = make_cleanup (xfree, message);
7648 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
7649 do_cleanups (cleanups);
7650 }
7651 set_language (save_language);
7652 input_radix = save_input_radix;
7653
7654 create_overlay_event_breakpoint ("_ovly_debug_event");
7655}
7656\f
7657/* Reset the thread number of this breakpoint:
7658
7659 - If the breakpoint is for all threads, leave it as-is.
7660 - Else, reset it to the current thread for inferior_ptid. */
7661void
7662breakpoint_re_set_thread (struct breakpoint *b)
7663{
7664 if (b->thread != -1)
7665 {
7666 if (in_thread_list (inferior_ptid))
7667 b->thread = pid_to_thread_id (inferior_ptid);
7668 }
7669}
7670
7671/* Set ignore-count of breakpoint number BPTNUM to COUNT.
7672 If from_tty is nonzero, it prints a message to that effect,
7673 which ends with a period (no newline). */
7674
7675void
7676set_ignore_count (int bptnum, int count, int from_tty)
7677{
7678 struct breakpoint *b;
7679
7680 if (count < 0)
7681 count = 0;
7682
7683 ALL_BREAKPOINTS (b)
7684 if (b->number == bptnum)
7685 {
7686 b->ignore_count = count;
7687 if (from_tty)
7688 {
7689 if (count == 0)
7690 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7691 bptnum);
7692 else if (count == 1)
7693 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7694 bptnum);
7695 else
7696 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7697 count, bptnum);
7698 }
7699 breakpoints_changed ();
7700 breakpoint_modify_event (b->number);
7701 return;
7702 }
7703
7704 error (_("No breakpoint number %d."), bptnum);
7705}
7706
7707/* Clear the ignore counts of all breakpoints. */
7708void
7709breakpoint_clear_ignore_counts (void)
7710{
7711 struct breakpoint *b;
7712
7713 ALL_BREAKPOINTS (b)
7714 b->ignore_count = 0;
7715}
7716
7717/* Command to set ignore-count of breakpoint N to COUNT. */
7718
7719static void
7720ignore_command (char *args, int from_tty)
7721{
7722 char *p = args;
7723 int num;
7724
7725 if (p == 0)
7726 error_no_arg (_("a breakpoint number"));
7727
7728 num = get_number (&p);
7729 if (num == 0)
7730 error (_("bad breakpoint number: '%s'"), args);
7731 if (*p == 0)
7732 error (_("Second argument (specified ignore-count) is missing."));
7733
7734 set_ignore_count (num,
7735 longest_to_int (value_as_long (parse_and_eval (p))),
7736 from_tty);
7737 if (from_tty)
7738 printf_filtered ("\n");
7739}
7740\f
7741/* Call FUNCTION on each of the breakpoints
7742 whose numbers are given in ARGS. */
7743
7744static void
7745map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7746{
7747 char *p = args;
7748 char *p1;
7749 int num;
7750 struct breakpoint *b, *tmp;
7751 int match;
7752
7753 if (p == 0)
7754 error_no_arg (_("one or more breakpoint numbers"));
7755
7756 while (*p)
7757 {
7758 match = 0;
7759 p1 = p;
7760
7761 num = get_number_or_range (&p1);
7762 if (num == 0)
7763 {
7764 warning (_("bad breakpoint number at or near '%s'"), p);
7765 }
7766 else
7767 {
7768 ALL_BREAKPOINTS_SAFE (b, tmp)
7769 if (b->number == num)
7770 {
7771 struct breakpoint *related_breakpoint = b->related_breakpoint;
7772 match = 1;
7773 function (b);
7774 if (related_breakpoint)
7775 function (related_breakpoint);
7776 break;
7777 }
7778 if (match == 0)
7779 printf_unfiltered (_("No breakpoint number %d.\n"), num);
7780 }
7781 p = p1;
7782 }
7783}
7784
7785static struct bp_location *
7786find_location_by_number (char *number)
7787{
7788 char *dot = strchr (number, '.');
7789 char *p1;
7790 int bp_num;
7791 int loc_num;
7792 struct breakpoint *b;
7793 struct bp_location *loc;
7794
7795 *dot = '\0';
7796
7797 p1 = number;
7798 bp_num = get_number_or_range (&p1);
7799 if (bp_num == 0)
7800 error (_("Bad breakpoint number '%s'"), number);
7801
7802 ALL_BREAKPOINTS (b)
7803 if (b->number == bp_num)
7804 {
7805 break;
7806 }
7807
7808 if (!b || b->number != bp_num)
7809 error (_("Bad breakpoint number '%s'"), number);
7810
7811 p1 = dot+1;
7812 loc_num = get_number_or_range (&p1);
7813 if (loc_num == 0)
7814 error (_("Bad breakpoint location number '%s'"), number);
7815
7816 --loc_num;
7817 loc = b->loc;
7818 for (;loc_num && loc; --loc_num, loc = loc->next)
7819 ;
7820 if (!loc)
7821 error (_("Bad breakpoint location number '%s'"), dot+1);
7822
7823 return loc;
7824}
7825
7826
7827/* Set ignore-count of breakpoint number BPTNUM to COUNT.
7828 If from_tty is nonzero, it prints a message to that effect,
7829 which ends with a period (no newline). */
7830
7831void
7832disable_breakpoint (struct breakpoint *bpt)
7833{
7834 /* Never disable a watchpoint scope breakpoint; we want to
7835 hit them when we leave scope so we can delete both the
7836 watchpoint and its scope breakpoint at that time. */
7837 if (bpt->type == bp_watchpoint_scope)
7838 return;
7839
7840 /* You can't disable permanent breakpoints. */
7841 if (bpt->enable_state == bp_permanent)
7842 return;
7843
7844 bpt->enable_state = bp_disabled;
7845
7846 update_global_location_list ();
7847
7848 if (deprecated_modify_breakpoint_hook)
7849 deprecated_modify_breakpoint_hook (bpt);
7850 breakpoint_modify_event (bpt->number);
7851}
7852
7853static void
7854disable_command (char *args, int from_tty)
7855{
7856 struct breakpoint *bpt;
7857 if (args == 0)
7858 ALL_BREAKPOINTS (bpt)
7859 switch (bpt->type)
7860 {
7861 case bp_none:
7862 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7863 bpt->number);
7864 continue;
7865 case bp_breakpoint:
7866 case bp_catch_load:
7867 case bp_catch_unload:
7868 case bp_catch_fork:
7869 case bp_catch_vfork:
7870 case bp_catch_exec:
7871 case bp_hardware_breakpoint:
7872 case bp_watchpoint:
7873 case bp_hardware_watchpoint:
7874 case bp_read_watchpoint:
7875 case bp_access_watchpoint:
7876 disable_breakpoint (bpt);
7877 default:
7878 continue;
7879 }
7880 else if (strchr (args, '.'))
7881 {
7882 struct bp_location *loc = find_location_by_number (args);
7883 if (loc)
7884 loc->enabled = 0;
7885 update_global_location_list ();
7886 }
7887 else
7888 map_breakpoint_numbers (args, disable_breakpoint);
7889}
7890
7891static void
7892do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7893{
7894 int target_resources_ok, other_type_used;
7895 struct value *mark;
7896
7897 if (bpt->type == bp_hardware_breakpoint)
7898 {
7899 int i;
7900 i = hw_breakpoint_used_count ();
7901 target_resources_ok =
7902 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7903 i + 1, 0);
7904 if (target_resources_ok == 0)
7905 error (_("No hardware breakpoint support in the target."));
7906 else if (target_resources_ok < 0)
7907 error (_("Hardware breakpoints used exceeds limit."));
7908 }
7909
7910 if (bpt->type == bp_watchpoint ||
7911 bpt->type == bp_hardware_watchpoint ||
7912 bpt->type == bp_read_watchpoint ||
7913 bpt->type == bp_access_watchpoint)
7914 {
7915 struct frame_id saved_frame_id;
7916
7917 saved_frame_id = get_frame_id (get_selected_frame (NULL));
7918 if (bpt->exp_valid_block != NULL)
7919 {
7920 struct frame_info *fr =
7921 fr = frame_find_by_id (bpt->watchpoint_frame);
7922 if (fr == NULL)
7923 {
7924 printf_filtered (_("\
7925Cannot enable watchpoint %d because the block in which its expression\n\
7926is valid is not currently in scope.\n"), bpt->number);
7927 return;
7928 }
7929 select_frame (fr);
7930 }
7931
7932 if (bpt->val)
7933 value_free (bpt->val);
7934 mark = value_mark ();
7935 fetch_watchpoint_value (bpt->exp, &bpt->val, NULL, NULL);
7936 if (bpt->val)
7937 release_value (bpt->val);
7938 bpt->val_valid = 1;
7939
7940 if (bpt->type == bp_hardware_watchpoint ||
7941 bpt->type == bp_read_watchpoint ||
7942 bpt->type == bp_access_watchpoint)
7943 {
7944 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7945 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7946
7947 /* Hack around 'unused var' error for some targets here */
7948 (void) mem_cnt, (void) i;
7949 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7950 bpt->type, i + mem_cnt, other_type_used);
7951 /* we can consider of type is bp_hardware_watchpoint, convert to
7952 bp_watchpoint in the following condition */
7953 if (target_resources_ok < 0)
7954 {
7955 printf_filtered (_("\
7956Cannot enable watchpoint %d because target watch resources\n\
7957have been allocated for other watchpoints.\n"), bpt->number);
7958 value_free_to_mark (mark);
7959 return;
7960 }
7961 }
7962
7963 select_frame (frame_find_by_id (saved_frame_id));
7964 value_free_to_mark (mark);
7965 }
7966
7967 if (bpt->enable_state != bp_permanent)
7968 bpt->enable_state = bp_enabled;
7969 bpt->disposition = disposition;
7970 update_global_location_list ();
7971 breakpoints_changed ();
7972
7973 if (deprecated_modify_breakpoint_hook)
7974 deprecated_modify_breakpoint_hook (bpt);
7975 breakpoint_modify_event (bpt->number);
7976}
7977
7978
7979void
7980enable_breakpoint (struct breakpoint *bpt)
7981{
7982 do_enable_breakpoint (bpt, bpt->disposition);
7983}
7984
7985/* The enable command enables the specified breakpoints (or all defined
7986 breakpoints) so they once again become (or continue to be) effective
7987 in stopping the inferior. */
7988
7989static void
7990enable_command (char *args, int from_tty)
7991{
7992 struct breakpoint *bpt;
7993 if (args == 0)
7994 ALL_BREAKPOINTS (bpt)
7995 switch (bpt->type)
7996 {
7997 case bp_none:
7998 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7999 bpt->number);
8000 continue;
8001 case bp_breakpoint:
8002 case bp_catch_load:
8003 case bp_catch_unload:
8004 case bp_catch_fork:
8005 case bp_catch_vfork:
8006 case bp_catch_exec:
8007 case bp_hardware_breakpoint:
8008 case bp_watchpoint:
8009 case bp_hardware_watchpoint:
8010 case bp_read_watchpoint:
8011 case bp_access_watchpoint:
8012 enable_breakpoint (bpt);
8013 default:
8014 continue;
8015 }
8016 else if (strchr (args, '.'))
8017 {
8018 struct bp_location *loc = find_location_by_number (args);
8019 if (loc)
8020 loc->enabled = 1;
8021 update_global_location_list ();
8022 }
8023 else
8024 map_breakpoint_numbers (args, enable_breakpoint);
8025}
8026
8027static void
8028enable_once_breakpoint (struct breakpoint *bpt)
8029{
8030 do_enable_breakpoint (bpt, disp_disable);
8031}
8032
8033static void
8034enable_once_command (char *args, int from_tty)
8035{
8036 map_breakpoint_numbers (args, enable_once_breakpoint);
8037}
8038
8039static void
8040enable_delete_breakpoint (struct breakpoint *bpt)
8041{
8042 do_enable_breakpoint (bpt, disp_del);
8043}
8044
8045static void
8046enable_delete_command (char *args, int from_tty)
8047{
8048 map_breakpoint_numbers (args, enable_delete_breakpoint);
8049}
8050\f
8051static void
8052set_breakpoint_cmd (char *args, int from_tty)
8053{
8054}
8055
8056static void
8057show_breakpoint_cmd (char *args, int from_tty)
8058{
8059}
8060
8061/* Use default_breakpoint_'s, or nothing if they aren't valid. */
8062
8063struct symtabs_and_lines
8064decode_line_spec_1 (char *string, int funfirstline)
8065{
8066 struct symtabs_and_lines sals;
8067 if (string == 0)
8068 error (_("Empty line specification."));
8069 if (default_breakpoint_valid)
8070 sals = decode_line_1 (&string, funfirstline,
8071 default_breakpoint_symtab,
8072 default_breakpoint_line,
8073 (char ***) NULL, NULL);
8074 else
8075 sals = decode_line_1 (&string, funfirstline,
8076 (struct symtab *) NULL, 0, (char ***) NULL, NULL);
8077 if (*string)
8078 error (_("Junk at end of line specification: %s"), string);
8079 return sals;
8080}
8081
8082/* Create and insert a raw software breakpoint at PC. Return an
8083 identifier, which should be used to remove the breakpoint later.
8084 In general, places which call this should be using something on the
8085 breakpoint chain instead; this function should be eliminated
8086 someday. */
8087
8088void *
8089deprecated_insert_raw_breakpoint (CORE_ADDR pc)
8090{
8091 struct bp_target_info *bp_tgt;
8092
8093 bp_tgt = xmalloc (sizeof (struct bp_target_info));
8094 memset (bp_tgt, 0, sizeof (struct bp_target_info));
8095
8096 bp_tgt->placed_address = pc;
8097 if (target_insert_breakpoint (bp_tgt) != 0)
8098 {
8099 /* Could not insert the breakpoint. */
8100 xfree (bp_tgt);
8101 return NULL;
8102 }
8103
8104 return bp_tgt;
8105}
8106
8107/* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8108
8109int
8110deprecated_remove_raw_breakpoint (void *bp)
8111{
8112 struct bp_target_info *bp_tgt = bp;
8113 int ret;
8114
8115 ret = target_remove_breakpoint (bp_tgt);
8116 xfree (bp_tgt);
8117
8118 return ret;
8119}
8120
8121/* One (or perhaps two) breakpoints used for software single stepping. */
8122
8123static void *single_step_breakpoints[2];
8124
8125/* Create and insert a breakpoint for software single step. */
8126
8127void
8128insert_single_step_breakpoint (CORE_ADDR next_pc)
8129{
8130 void **bpt_p;
8131
8132 if (single_step_breakpoints[0] == NULL)
8133 bpt_p = &single_step_breakpoints[0];
8134 else
8135 {
8136 gdb_assert (single_step_breakpoints[1] == NULL);
8137 bpt_p = &single_step_breakpoints[1];
8138 }
8139
8140 /* NOTE drow/2006-04-11: A future improvement to this function would be
8141 to only create the breakpoints once, and actually put them on the
8142 breakpoint chain. That would let us use set_raw_breakpoint. We could
8143 adjust the addresses each time they were needed. Doing this requires
8144 corresponding changes elsewhere where single step breakpoints are
8145 handled, however. So, for now, we use this. */
8146
8147 *bpt_p = deprecated_insert_raw_breakpoint (next_pc);
8148 if (*bpt_p == NULL)
8149 error (_("Could not insert single-step breakpoint at 0x%s"),
8150 paddr_nz (next_pc));
8151}
8152
8153/* Remove and delete any breakpoints used for software single step. */
8154
8155void
8156remove_single_step_breakpoints (void)
8157{
8158 gdb_assert (single_step_breakpoints[0] != NULL);
8159
8160 /* See insert_single_step_breakpoint for more about this deprecated
8161 call. */
8162 deprecated_remove_raw_breakpoint (single_step_breakpoints[0]);
8163 single_step_breakpoints[0] = NULL;
8164
8165 if (single_step_breakpoints[1] != NULL)
8166 {
8167 deprecated_remove_raw_breakpoint (single_step_breakpoints[1]);
8168 single_step_breakpoints[1] = NULL;
8169 }
8170}
8171
8172/* Check whether a software single-step breakpoint is inserted at PC. */
8173
8174static int
8175single_step_breakpoint_inserted_here_p (CORE_ADDR pc)
8176{
8177 int i;
8178
8179 for (i = 0; i < 2; i++)
8180 {
8181 struct bp_target_info *bp_tgt = single_step_breakpoints[i];
8182 if (bp_tgt && bp_tgt->placed_address == pc)
8183 return 1;
8184 }
8185
8186 return 0;
8187}
8188
8189int breakpoints_always_inserted_mode (void)
8190{
8191 return always_inserted_mode;
8192}
8193
8194\f
8195/* This help string is used for the break, hbreak, tbreak and thbreak commands.
8196 It is defined as a macro to prevent duplication.
8197 COMMAND should be a string constant containing the name of the command. */
8198#define BREAK_ARGS_HELP(command) \
8199command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8200LOCATION may be a line number, function name, or \"*\" and an address.\n\
8201If a line number is specified, break at start of code for that line.\n\
8202If a function is specified, break at start of code for that function.\n\
8203If an address is specified, break at that exact address.\n\
8204With no LOCATION, uses current execution address of selected stack frame.\n\
8205This is useful for breaking on return to a stack frame.\n\
8206\n\
8207THREADNUM is the number from \"info threads\".\n\
8208CONDITION is a boolean expression.\n\
8209\n\
8210Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8211\n\
8212Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8213
8214void
8215_initialize_breakpoint (void)
8216{
8217 static struct cmd_list_element *breakpoint_set_cmdlist;
8218 static struct cmd_list_element *breakpoint_show_cmdlist;
8219 struct cmd_list_element *c;
8220
8221 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib);
8222
8223 breakpoint_chain = 0;
8224 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8225 before a breakpoint is set. */
8226 breakpoint_count = 0;
8227
8228 add_com ("ignore", class_breakpoint, ignore_command, _("\
8229Set ignore-count of breakpoint number N to COUNT.\n\
8230Usage is `ignore N COUNT'."));
8231 if (xdb_commands)
8232 add_com_alias ("bc", "ignore", class_breakpoint, 1);
8233
8234 add_com ("commands", class_breakpoint, commands_command, _("\
8235Set commands to be executed when a breakpoint is hit.\n\
8236Give breakpoint number as argument after \"commands\".\n\
8237With no argument, the targeted breakpoint is the last one set.\n\
8238The commands themselves follow starting on the next line.\n\
8239Type a line containing \"end\" to indicate the end of them.\n\
8240Give \"silent\" as the first line to make the breakpoint silent;\n\
8241then no output is printed when it is hit, except what the commands print."));
8242
8243 add_com ("condition", class_breakpoint, condition_command, _("\
8244Specify breakpoint number N to break only if COND is true.\n\
8245Usage is `condition N COND', where N is an integer and COND is an\n\
8246expression to be evaluated whenever breakpoint N is reached."));
8247
8248 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
8249Set a temporary breakpoint.\n\
8250Like \"break\" except the breakpoint is only temporary,\n\
8251so it will be deleted when hit. Equivalent to \"break\" followed\n\
8252by using \"enable delete\" on the breakpoint number.\n\
8253\n"
8254BREAK_ARGS_HELP ("tbreak")));
8255 set_cmd_completer (c, location_completer);
8256
8257 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\
8258Set a hardware assisted breakpoint.\n\
8259Like \"break\" except the breakpoint requires hardware support,\n\
8260some target hardware may not have this support.\n\
8261\n"
8262BREAK_ARGS_HELP ("hbreak")));
8263 set_cmd_completer (c, location_completer);
8264
8265 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\
8266Set a temporary hardware assisted breakpoint.\n\
8267Like \"hbreak\" except the breakpoint is only temporary,\n\
8268so it will be deleted when hit.\n\
8269\n"
8270BREAK_ARGS_HELP ("thbreak")));
8271 set_cmd_completer (c, location_completer);
8272
8273 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
8274Enable some breakpoints.\n\
8275Give breakpoint numbers (separated by spaces) as arguments.\n\
8276With no subcommand, breakpoints are enabled until you command otherwise.\n\
8277This is used to cancel the effect of the \"disable\" command.\n\
8278With a subcommand you can enable temporarily."),
8279 &enablelist, "enable ", 1, &cmdlist);
8280 if (xdb_commands)
8281 add_com ("ab", class_breakpoint, enable_command, _("\
8282Enable some breakpoints.\n\
8283Give breakpoint numbers (separated by spaces) as arguments.\n\
8284With no subcommand, breakpoints are enabled until you command otherwise.\n\
8285This is used to cancel the effect of the \"disable\" command.\n\
8286With a subcommand you can enable temporarily."));
8287
8288 add_com_alias ("en", "enable", class_breakpoint, 1);
8289
8290 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
8291Enable some breakpoints.\n\
8292Give breakpoint numbers (separated by spaces) as arguments.\n\
8293This is used to cancel the effect of the \"disable\" command.\n\
8294May be abbreviated to simply \"enable\".\n"),
8295 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
8296
8297 add_cmd ("once", no_class, enable_once_command, _("\
8298Enable breakpoints for one hit. Give breakpoint numbers.\n\
8299If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8300 &enablebreaklist);
8301
8302 add_cmd ("delete", no_class, enable_delete_command, _("\
8303Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8304If a breakpoint is hit while enabled in this fashion, it is deleted."),
8305 &enablebreaklist);
8306
8307 add_cmd ("delete", no_class, enable_delete_command, _("\
8308Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8309If a breakpoint is hit while enabled in this fashion, it is deleted."),
8310 &enablelist);
8311
8312 add_cmd ("once", no_class, enable_once_command, _("\
8313Enable breakpoints for one hit. Give breakpoint numbers.\n\
8314If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8315 &enablelist);
8316
8317 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
8318Disable some breakpoints.\n\
8319Arguments are breakpoint numbers with spaces in between.\n\
8320To disable all breakpoints, give no argument.\n\
8321A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8322 &disablelist, "disable ", 1, &cmdlist);
8323 add_com_alias ("dis", "disable", class_breakpoint, 1);
8324 add_com_alias ("disa", "disable", class_breakpoint, 1);
8325 if (xdb_commands)
8326 add_com ("sb", class_breakpoint, disable_command, _("\
8327Disable some breakpoints.\n\
8328Arguments are breakpoint numbers with spaces in between.\n\
8329To disable all breakpoints, give no argument.\n\
8330A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8331
8332 add_cmd ("breakpoints", class_alias, disable_command, _("\
8333Disable some breakpoints.\n\
8334Arguments are breakpoint numbers with spaces in between.\n\
8335To disable all breakpoints, give no argument.\n\
8336A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8337This command may be abbreviated \"disable\"."),
8338 &disablelist);
8339
8340 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
8341Delete some breakpoints or auto-display expressions.\n\
8342Arguments are breakpoint numbers with spaces in between.\n\
8343To delete all breakpoints, give no argument.\n\
8344\n\
8345Also a prefix command for deletion of other GDB objects.\n\
8346The \"unset\" command is also an alias for \"delete\"."),
8347 &deletelist, "delete ", 1, &cmdlist);
8348 add_com_alias ("d", "delete", class_breakpoint, 1);
8349 add_com_alias ("del", "delete", class_breakpoint, 1);
8350 if (xdb_commands)
8351 add_com ("db", class_breakpoint, delete_command, _("\
8352Delete some breakpoints.\n\
8353Arguments are breakpoint numbers with spaces in between.\n\
8354To delete all breakpoints, give no argument.\n"));
8355
8356 add_cmd ("breakpoints", class_alias, delete_command, _("\
8357Delete some breakpoints or auto-display expressions.\n\
8358Arguments are breakpoint numbers with spaces in between.\n\
8359To delete all breakpoints, give no argument.\n\
8360This command may be abbreviated \"delete\"."),
8361 &deletelist);
8362
8363 add_com ("clear", class_breakpoint, clear_command, _("\
8364Clear breakpoint at specified line or function.\n\
8365Argument may be line number, function name, or \"*\" and an address.\n\
8366If line number is specified, all breakpoints in that line are cleared.\n\
8367If function is specified, breakpoints at beginning of function are cleared.\n\
8368If an address is specified, breakpoints at that address are cleared.\n\
8369\n\
8370With no argument, clears all breakpoints in the line that the selected frame\n\
8371is executing in.\n\
8372\n\
8373See also the \"delete\" command which clears breakpoints by number."));
8374
8375 c = add_com ("break", class_breakpoint, break_command, _("\
8376Set breakpoint at specified line or function.\n"
8377BREAK_ARGS_HELP ("break")));
8378 set_cmd_completer (c, location_completer);
8379
8380 add_com_alias ("b", "break", class_run, 1);
8381 add_com_alias ("br", "break", class_run, 1);
8382 add_com_alias ("bre", "break", class_run, 1);
8383 add_com_alias ("brea", "break", class_run, 1);
8384
8385 if (xdb_commands)
8386 {
8387 add_com_alias ("ba", "break", class_breakpoint, 1);
8388 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
8389 }
8390
8391 if (dbx_commands)
8392 {
8393 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\
8394Break in function/address or break at a line in the current file."),
8395 &stoplist, "stop ", 1, &cmdlist);
8396 add_cmd ("in", class_breakpoint, stopin_command,
8397 _("Break in function or address."), &stoplist);
8398 add_cmd ("at", class_breakpoint, stopat_command,
8399 _("Break at a line in the current file."), &stoplist);
8400 add_com ("status", class_info, breakpoints_info, _("\
8401Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8402The \"Type\" column indicates one of:\n\
8403\tbreakpoint - normal breakpoint\n\
8404\twatchpoint - watchpoint\n\
8405The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8406the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8407breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8408address and file/line number respectively.\n\
8409\n\
8410Convenience variable \"$_\" and default examine address for \"x\"\n\
8411are set to the address of the last breakpoint listed unless the command\n\
8412is prefixed with \"server \".\n\n\
8413Convenience variable \"$bpnum\" contains the number of the last\n\
8414breakpoint set."));
8415 }
8416
8417 add_info ("breakpoints", breakpoints_info, _("\
8418Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8419The \"Type\" column indicates one of:\n\
8420\tbreakpoint - normal breakpoint\n\
8421\twatchpoint - watchpoint\n\
8422The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8423the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8424breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8425address and file/line number respectively.\n\
8426\n\
8427Convenience variable \"$_\" and default examine address for \"x\"\n\
8428are set to the address of the last breakpoint listed unless the command\n\
8429is prefixed with \"server \".\n\n\
8430Convenience variable \"$bpnum\" contains the number of the last\n\
8431breakpoint set."));
8432
8433 if (xdb_commands)
8434 add_com ("lb", class_breakpoint, breakpoints_info, _("\
8435Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8436The \"Type\" column indicates one of:\n\
8437\tbreakpoint - normal breakpoint\n\
8438\twatchpoint - watchpoint\n\
8439The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8440the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8441breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8442address and file/line number respectively.\n\
8443\n\
8444Convenience variable \"$_\" and default examine address for \"x\"\n\
8445are set to the address of the last breakpoint listed unless the command\n\
8446is prefixed with \"server \".\n\n\
8447Convenience variable \"$bpnum\" contains the number of the last\n\
8448breakpoint set."));
8449
8450 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
8451Status of all breakpoints, or breakpoint number NUMBER.\n\
8452The \"Type\" column indicates one of:\n\
8453\tbreakpoint - normal breakpoint\n\
8454\twatchpoint - watchpoint\n\
8455\tlongjmp - internal breakpoint used to step through longjmp()\n\
8456\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8457\tuntil - internal breakpoint used by the \"until\" command\n\
8458\tfinish - internal breakpoint used by the \"finish\" command\n\
8459The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8460the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8461breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8462address and file/line number respectively.\n\
8463\n\
8464Convenience variable \"$_\" and default examine address for \"x\"\n\
8465are set to the address of the last breakpoint listed unless the command\n\
8466is prefixed with \"server \".\n\n\
8467Convenience variable \"$bpnum\" contains the number of the last\n\
8468breakpoint set."),
8469 &maintenanceinfolist);
8470
8471 add_com ("catch", class_breakpoint, catch_command, _("\
8472Set catchpoints to catch events.\n\
8473Raised signals may be caught:\n\
8474\tcatch signal - all signals\n\
8475\tcatch signal <signame> - a particular signal\n\
8476Raised exceptions may be caught:\n\
8477\tcatch throw - all exceptions, when thrown\n\
8478\tcatch throw <exceptname> - a particular exception, when thrown\n\
8479\tcatch catch - all exceptions, when caught\n\
8480\tcatch catch <exceptname> - a particular exception, when caught\n\
8481Thread or process events may be caught:\n\
8482\tcatch thread_start - any threads, just after creation\n\
8483\tcatch thread_exit - any threads, just before expiration\n\
8484\tcatch thread_join - any threads, just after joins\n\
8485Process events may be caught:\n\
8486\tcatch start - any processes, just after creation\n\
8487\tcatch exit - any processes, just before expiration\n\
8488\tcatch fork - calls to fork()\n\
8489\tcatch vfork - calls to vfork()\n\
8490\tcatch exec - calls to exec()\n\
8491Dynamically-linked library events may be caught:\n\
8492\tcatch load - loads of any library\n\
8493\tcatch load <libname> - loads of a particular library\n\
8494\tcatch unload - unloads of any library\n\
8495\tcatch unload <libname> - unloads of a particular library\n\
8496The act of your program's execution stopping may also be caught:\n\
8497\tcatch stop\n\n\
8498C++ exceptions may be caught:\n\
8499\tcatch throw - all exceptions, when thrown\n\
8500\tcatch catch - all exceptions, when caught\n\
8501Ada exceptions may be caught:\n\
8502\tcatch exception - all exceptions, when raised\n\
8503\tcatch exception <name> - a particular exception, when raised\n\
8504\tcatch exception unhandled - all unhandled exceptions, when raised\n\
8505\tcatch assert - all failed assertions, when raised\n\
8506\n\
8507Do \"help set follow-fork-mode\" for info on debugging your program\n\
8508after a fork or vfork is caught.\n\n\
8509Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8510
8511 add_com ("tcatch", class_breakpoint, tcatch_command, _("\
8512Set temporary catchpoints to catch events.\n\
8513Args like \"catch\" command.\n\
8514Like \"catch\" except the catchpoint is only temporary,\n\
8515so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8516by using \"enable delete\" on the catchpoint number."));
8517
8518 c = add_com ("watch", class_breakpoint, watch_command, _("\
8519Set a watchpoint for an expression.\n\
8520A watchpoint stops execution of your program whenever the value of\n\
8521an expression changes."));
8522 set_cmd_completer (c, expression_completer);
8523
8524 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\
8525Set a read watchpoint for an expression.\n\
8526A watchpoint stops execution of your program whenever the value of\n\
8527an expression is read."));
8528 set_cmd_completer (c, expression_completer);
8529
8530 c = add_com ("awatch", class_breakpoint, awatch_command, _("\
8531Set a watchpoint for an expression.\n\
8532A watchpoint stops execution of your program whenever the value of\n\
8533an expression is either read or written."));
8534 set_cmd_completer (c, expression_completer);
8535
8536 add_info ("watchpoints", breakpoints_info,
8537 _("Synonym for ``info breakpoints''."));
8538
8539
8540 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8541 respond to changes - contrary to the description. */
8542 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support,
8543 &can_use_hw_watchpoints, _("\
8544Set debugger's willingness to use watchpoint hardware."), _("\
8545Show debugger's willingness to use watchpoint hardware."), _("\
8546If zero, gdb will not use hardware for new watchpoints, even if\n\
8547such is available. (However, any hardware watchpoints that were\n\
8548created before setting this to nonzero, will continue to use watchpoint\n\
8549hardware.)"),
8550 NULL,
8551 show_can_use_hw_watchpoints,
8552 &setlist, &showlist);
8553
8554 can_use_hw_watchpoints = 1;
8555
8556 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
8557Breakpoint specific settings\n\
8558Configure various breakpoint-specific variables such as\n\
8559pending breakpoint behavior"),
8560 &breakpoint_set_cmdlist, "set breakpoint ",
8561 0/*allow-unknown*/, &setlist);
8562 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
8563Breakpoint specific settings\n\
8564Configure various breakpoint-specific variables such as\n\
8565pending breakpoint behavior"),
8566 &breakpoint_show_cmdlist, "show breakpoint ",
8567 0/*allow-unknown*/, &showlist);
8568
8569 add_setshow_auto_boolean_cmd ("pending", no_class,
8570 &pending_break_support, _("\
8571Set debugger's behavior regarding pending breakpoints."), _("\
8572Show debugger's behavior regarding pending breakpoints."), _("\
8573If on, an unrecognized breakpoint location will cause gdb to create a\n\
8574pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8575an error. If auto, an unrecognized breakpoint location results in a\n\
8576user-query to see if a pending breakpoint should be created."),
8577 NULL,
8578 show_pending_break_support,
8579 &breakpoint_set_cmdlist,
8580 &breakpoint_show_cmdlist);
8581
8582 pending_break_support = AUTO_BOOLEAN_AUTO;
8583
8584 add_setshow_boolean_cmd ("auto-hw", no_class,
8585 &automatic_hardware_breakpoints, _("\
8586Set automatic usage of hardware breakpoints."), _("\
8587Show automatic usage of hardware breakpoints."), _("\
8588If set, the debugger will automatically use hardware breakpoints for\n\
8589breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8590a warning will be emitted for such breakpoints."),
8591 NULL,
8592 show_automatic_hardware_breakpoints,
8593 &breakpoint_set_cmdlist,
8594 &breakpoint_show_cmdlist);
8595
8596 add_setshow_boolean_cmd ("always-inserted", class_support,
8597 &always_inserted_mode, _("\
8598Set mode for inserting breakpoints."), _("\
8599Show mode for inserting breakpoints."), _("\
8600When this mode is off (which is the default), breakpoints are inserted in\n\
8601inferior when it is resumed, and removed when execution stops. When this\n\
8602mode is on, breakpoints are inserted immediately and removed only when\n\
8603the user deletes the breakpoint."),
8604 NULL,
8605 &show_always_inserted_mode,
8606 &breakpoint_set_cmdlist,
8607 &breakpoint_show_cmdlist);
8608
8609 automatic_hardware_breakpoints = 1;
8610}
This page took 0.071628 seconds and 4 git commands to generate.