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