Bug Summary

File:src/gnu/usr.bin/binutils/gdb/breakpoint.c
Warning:line 6468, column 7
Value stored to 'cond_string' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

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