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