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