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