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