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