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