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