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