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