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