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