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