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