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