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