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