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