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