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