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