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