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