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