Remove else clause to #if UI_OUT.
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
CommitLineData
c906108c 1/* Everything about breakpoints, for GDB.
8926118c
AC
2
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
5 Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24#include "defs.h"
25#include <ctype.h>
26#include "symtab.h"
27#include "frame.h"
28#include "breakpoint.h"
29#include "gdbtypes.h"
30#include "expression.h"
31#include "gdbcore.h"
32#include "gdbcmd.h"
33#include "value.h"
34#include "command.h"
35#include "inferior.h"
36#include "gdbthread.h"
37#include "target.h"
38#include "language.h"
39#include "gdb_string.h"
40#include "demangle.h"
41#include "annotate.h"
42#include "symfile.h"
43#include "objfiles.h"
c5f0f3d0 44#include "linespec.h"
c94fdfd0 45#include "completer.h"
5b7f31a4 46#include "gdb.h"
8b93c638 47#include "ui-out.h"
c906108c 48
104c1213
JM
49#include "gdb-events.h"
50
c906108c
SS
51/* Prototypes for local functions. */
52
c2c6d25f
JM
53static void until_break_command_continuation (struct continuation_arg *arg);
54
a14ed312 55static void catch_command_1 (char *, int, int);
c906108c 56
a14ed312 57static void enable_delete_command (char *, int);
c906108c 58
a14ed312 59static void enable_delete_breakpoint (struct breakpoint *);
c906108c 60
a14ed312 61static void enable_once_command (char *, int);
c906108c 62
a14ed312 63static void enable_once_breakpoint (struct breakpoint *);
c906108c 64
a14ed312 65static void disable_command (char *, int);
c906108c 66
a14ed312 67static void enable_command (char *, int);
c906108c 68
a14ed312 69static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
c906108c 70
a14ed312 71static void ignore_command (char *, int);
c906108c 72
a14ed312 73static int breakpoint_re_set_one (PTR);
c906108c 74
a14ed312 75static void clear_command (char *, int);
c906108c 76
a14ed312 77static void catch_command (char *, int);
c906108c 78
a14ed312 79static void handle_gnu_4_16_catch_command (char *, int, int);
c906108c 80
a14ed312 81static struct symtabs_and_lines get_catch_sals (int);
c906108c 82
a14ed312 83static void watch_command (char *, int);
c906108c 84
a14ed312 85static int can_use_hardware_watchpoint (struct value *);
c906108c 86
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. */
752 if (overlay_debugging && b->section &&
753 section_is_overlay (b->section))
754 {
755 CORE_ADDR addr;
756
757 addr = overlay_unmapped_address (b->address, b->section);
758 val = target_insert_breakpoint (addr, b->shadow_contents);
759 /* This would be the time to check val, to see if the
760 breakpoint write to the load address succeeded.
761 However, this might be an ordinary occurrance, eg. if
762 the unmapped overlay is in ROM. */
763 val = 0; /* in case unmapped address failed */
764 if (section_is_mapped (b->section))
765 val = target_insert_breakpoint (b->address,
766 b->shadow_contents);
767 }
768 else /* ordinary (non-overlay) address */
769 val = target_insert_breakpoint (b->address, b->shadow_contents);
770 }
771 if (val)
772 {
773 /* Can't set the breakpoint. */
c906108c 774#if defined (DISABLE_UNSETTABLE_BREAK)
c5aa993b
JM
775 if (DISABLE_UNSETTABLE_BREAK (b->address))
776 {
777 /* See also: disable_breakpoints_in_shlibs. */
778 val = 0;
b5de0fa7 779 b->enable_state = bp_shlib_disabled;
c5aa993b
JM
780 if (!disabled_breaks)
781 {
782 target_terminal_ours_for_output ();
53a5351d
JM
783 warning ("Cannot insert breakpoint %d:", b->number);
784 warning ("Temporarily disabling shared library breakpoints:");
c5aa993b
JM
785 }
786 disabled_breaks = 1;
53a5351d 787 warning ("breakpoint #%d ", b->number);
c5aa993b
JM
788 }
789 else
c906108c 790#endif
c5aa993b
JM
791 {
792 target_terminal_ours_for_output ();
53a5351d 793 warning ("Cannot insert breakpoint %d:", b->number);
c906108c 794#ifdef ONE_PROCESS_WRITETEXT
53a5351d 795 warning ("The same program may be running in another process.");
c906108c 796#endif
53a5351d 797 memory_error (val, b->address); /* which bombs us out */
c5aa993b
JM
798 }
799 }
800 else
801 b->inserted = 1;
53a5351d
JM
802
803 if (val)
804 return_val = val; /* remember failure */
c5aa993b 805 }
c906108c 806 else if (ep_is_exception_catchpoint (b)
b5de0fa7
EZ
807 && b->enable_state != bp_disabled
808 && b->enable_state != bp_shlib_disabled
809 && b->enable_state != bp_call_disabled
c5aa993b
JM
810 && !b->inserted
811 && !b->duplicate)
c906108c
SS
812
813 {
c5aa993b
JM
814 /* If we get here, we must have a callback mechanism for exception
815 events -- with g++ style embedded label support, we insert
816 ordinary breakpoints and not catchpoints. */
53a5351d
JM
817 /* Format possible error message */
818 sprintf (message, message1, b->number);
c5aa993b
JM
819
820 val = target_insert_breakpoint (b->address, b->shadow_contents);
821 if (val)
822 {
823 /* Couldn't set breakpoint for some reason */
824 target_terminal_ours_for_output ();
53a5351d
JM
825 warning ("Cannot insert catchpoint %d; disabling it.",
826 b->number);
b5de0fa7 827 b->enable_state = bp_disabled;
c5aa993b
JM
828 }
829 else
830 {
831 /* Bp set, now make sure callbacks are enabled */
c906108c 832 int val;
c5aa993b 833 args_for_catchpoint_enable args;
53a5351d
JM
834 args.kind = b->type == bp_catch_catch ?
835 EX_EVENT_CATCH : EX_EVENT_THROW;
b5de0fa7 836 args.enable_p = 1;
c906108c
SS
837 val = catch_errors (cover_target_enable_exception_callback,
838 &args,
839 message, RETURN_MASK_ALL);
840 if (val != 0 && val != -1)
841 {
842 b->inserted = 1;
843 }
c5aa993b 844 /* Check if something went wrong; val == 0 can be ignored */
c906108c
SS
845 if (val == -1)
846 {
c5aa993b 847 /* something went wrong */
c906108c 848 target_terminal_ours_for_output ();
53a5351d
JM
849 warning ("Cannot insert catchpoint %d; disabling it.",
850 b->number);
b5de0fa7 851 b->enable_state = bp_disabled;
c906108c 852 }
c5aa993b 853 }
53a5351d
JM
854
855 if (val)
856 return_val = val; /* remember failure */
c906108c
SS
857 }
858
c5aa993b
JM
859 else if ((b->type == bp_hardware_watchpoint ||
860 b->type == bp_read_watchpoint ||
861 b->type == bp_access_watchpoint)
b5de0fa7
EZ
862 && b->enable_state == bp_enabled
863 && b->disposition != disp_del_at_next_stop
c5aa993b
JM
864 && !b->inserted
865 && !b->duplicate)
866 {
867 struct frame_info *saved_frame;
868 int saved_level, within_current_scope;
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. */
c5aa993b 1280 if (overlay_debugging && b->section &&
c906108c
SS
1281 section_is_overlay (b->section))
1282 {
1283 CORE_ADDR addr;
1284
1285 addr = overlay_unmapped_address (b->address, b->section);
1286 val = target_remove_breakpoint (addr, b->shadow_contents);
1287 /* This would be the time to check val, to see if the
c5aa993b
JM
1288 shadow breakpoint write to the load address succeeded.
1289 However, this might be an ordinary occurrance, eg. if
1290 the unmapped overlay is in ROM. */
1291 val = 0; /* in case unmapped address failed */
c906108c 1292 if (section_is_mapped (b->section))
c5aa993b 1293 val = target_remove_breakpoint (b->address,
c906108c
SS
1294 b->shadow_contents);
1295 }
c5aa993b
JM
1296 else /* ordinary (non-overlay) address */
1297 val = target_remove_breakpoint (b->address, b->shadow_contents);
c906108c
SS
1298 }
1299 if (val)
1300 return val;
1301 b->inserted = (is == mark_inserted);
1302 }
1303 else if ((b->type == bp_hardware_watchpoint ||
c5aa993b
JM
1304 b->type == bp_read_watchpoint ||
1305 b->type == bp_access_watchpoint)
b5de0fa7 1306 && b->enable_state == bp_enabled
c5aa993b 1307 && !b->duplicate)
c906108c 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
JM
1512 {
1513 if (overlay_debugging &&
1514 section_is_overlay (b->section) &&
1515 !section_is_mapped (b->section))
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
JM
1539 {
1540 if (overlay_debugging &&
1541 section_is_overlay (b->section) &&
1542 !section_is_mapped (b->section))
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
JM
1600 {
1601 if (overlay_debugging &&
1602 section_is_overlay (b->section) &&
1603 !section_is_mapped (b->section))
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 */
2389 if (b->address != bp_addr || /* address doesn't match or */
2390 (overlay_debugging && /* overlay doesn't match */
2391 section_is_overlay (b->section) &&
2392 !section_is_mapped (b->section)))
c906108c
SS
2393 continue;
2394
c5aa993b
JM
2395 if (b->type == bp_hardware_breakpoint
2396 && b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2397 continue;
2398
c5aa993b
JM
2399 /* Is this a catchpoint of a load or unload? If so, did we
2400 get a load or unload of the specified library? If not,
2401 ignore it. */
2402 if ((b->type == bp_catch_load)
c906108c 2403#if defined(SOLIB_HAVE_LOAD_EVENT)
39f77062 2404 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
c5aa993b 2405 || ((b->dll_pathname != NULL)
53a5351d 2406 && (strcmp (b->dll_pathname,
39f77062
KB
2407 SOLIB_LOADED_LIBRARY_PATHNAME (
2408 PIDGET (inferior_ptid)))
53a5351d 2409 != 0)))
c906108c 2410#endif
c5aa993b
JM
2411 )
2412 continue;
2413
2414 if ((b->type == bp_catch_unload)
c906108c 2415#if defined(SOLIB_HAVE_UNLOAD_EVENT)
39f77062 2416 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
c5aa993b 2417 || ((b->dll_pathname != NULL)
53a5351d 2418 && (strcmp (b->dll_pathname,
39f77062
KB
2419 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2420 PIDGET (inferior_ptid)))
53a5351d 2421 != 0)))
c906108c 2422#endif
c5aa993b
JM
2423 )
2424 continue;
c906108c 2425
c5aa993b 2426 if ((b->type == bp_catch_fork)
39f77062
KB
2427 && !target_has_forked (PIDGET (inferior_ptid),
2428 &b->forked_inferior_pid))
c5aa993b 2429 continue;
c906108c 2430
c5aa993b 2431 if ((b->type == bp_catch_vfork)
39f77062
KB
2432 && !target_has_vforked (PIDGET (inferior_ptid),
2433 &b->forked_inferior_pid))
c5aa993b 2434 continue;
c906108c 2435
c5aa993b 2436 if ((b->type == bp_catch_exec)
39f77062 2437 && !target_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
c5aa993b 2438 continue;
c906108c 2439
c5aa993b
JM
2440 if (ep_is_exception_catchpoint (b) &&
2441 !(current_exception_event = target_get_current_exception_event ()))
2442 continue;
c906108c 2443
c5aa993b
JM
2444 /* Come here if it's a watchpoint, or if the break address matches */
2445
2446 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2447
2448 /* Watchpoints may change this, if not found to have triggered. */
2449 bs->stop = 1;
2450 bs->print = 1;
2451
2452 sprintf (message, message1, b->number);
53a5351d
JM
2453 if (b->type == bp_watchpoint ||
2454 b->type == bp_hardware_watchpoint)
c5aa993b 2455 {
53a5351d
JM
2456 switch (catch_errors (watchpoint_check, bs, message,
2457 RETURN_MASK_ALL))
c5aa993b
JM
2458 {
2459 case WP_DELETED:
2460 /* We've already printed what needs to be printed. */
4ce44c66
JM
2461 /* Actually this is superfluous, because by the time we
2462 call print_it_typical() the wp will be already deleted,
2463 and the function will return immediately. */
c5aa993b
JM
2464 bs->print_it = print_it_done;
2465 /* Stop. */
2466 break;
2467 case WP_VALUE_CHANGED:
2468 /* Stop. */
2469 ++(b->hit_count);
2470 break;
2471 case WP_VALUE_NOT_CHANGED:
2472 /* Don't stop. */
2473 bs->print_it = print_it_noop;
2474 bs->stop = 0;
c5aa993b
JM
2475 continue;
2476 default:
2477 /* Can't happen. */
2478 /* FALLTHROUGH */
2479 case 0:
2480 /* Error from catch_errors. */
2481 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2482 if (b->related_breakpoint)
b5de0fa7
EZ
2483 b->related_breakpoint->disposition = disp_del_at_next_stop;
2484 b->disposition = disp_del_at_next_stop;
c5aa993b
JM
2485 /* We've already printed what needs to be printed. */
2486 bs->print_it = print_it_done;
2487
2488 /* Stop. */
2489 break;
2490 }
2491 }
53a5351d
JM
2492 else if (b->type == bp_read_watchpoint ||
2493 b->type == bp_access_watchpoint)
c5aa993b
JM
2494 {
2495 CORE_ADDR addr;
278cd55f 2496 struct value *v;
c5aa993b
JM
2497 int found = 0;
2498
2499 addr = target_stopped_data_address ();
2500 if (addr == 0)
2501 continue;
2502 for (v = b->val_chain; v; v = v->next)
2503 {
5c44784c
JM
2504 if (VALUE_LVAL (v) == lval_memory
2505 && ! VALUE_LAZY (v))
c5aa993b 2506 {
2e70b7b9
MS
2507 struct type *vtype = check_typedef (VALUE_TYPE (v));
2508
2509 if (v == b->val_chain
2510 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2511 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2512 {
2513 CORE_ADDR vaddr;
2514
2515 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2516 /* Exact match not required. Within range is
2517 sufficient. */
2518 if (addr >= vaddr &&
2519 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2520 found = 1;
2521 }
c5aa993b
JM
2522 }
2523 }
2524 if (found)
53a5351d
JM
2525 switch (catch_errors (watchpoint_check, bs, message,
2526 RETURN_MASK_ALL))
c906108c
SS
2527 {
2528 case WP_DELETED:
2529 /* We've already printed what needs to be printed. */
2530 bs->print_it = print_it_done;
2531 /* Stop. */
2532 break;
2533 case WP_VALUE_CHANGED:
99e5c1c8
MS
2534 if (b->type == bp_read_watchpoint)
2535 {
2536 /* Don't stop: read watchpoints shouldn't fire if
2537 the value has changed. This is for targets which
2538 cannot set read-only watchpoints. */
2539 bs->print_it = print_it_noop;
2540 bs->stop = 0;
2541 continue;
2542 }
2543 ++(b->hit_count);
2544 break;
c5aa993b 2545 case WP_VALUE_NOT_CHANGED:
c906108c
SS
2546 /* Stop. */
2547 ++(b->hit_count);
2548 break;
c906108c
SS
2549 default:
2550 /* Can't happen. */
c906108c
SS
2551 case 0:
2552 /* Error from catch_errors. */
2553 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2554 if (b->related_breakpoint)
b5de0fa7
EZ
2555 b->related_breakpoint->disposition = disp_del_at_next_stop;
2556 b->disposition = disp_del_at_next_stop;
c906108c
SS
2557 /* We've already printed what needs to be printed. */
2558 bs->print_it = print_it_done;
c906108c
SS
2559 break;
2560 }
53a5351d
JM
2561 else /* found == 0 */
2562 {
2563 /* This is a case where some watchpoint(s) triggered,
2564 but not at the address of this watchpoint (FOUND
2565 was left zero). So don't print anything for this
2566 watchpoint. */
2567 bs->print_it = print_it_noop;
2568 bs->stop = 0;
2569 continue;
2570 }
c5aa993b
JM
2571 }
2572 else
2573 {
2574 /* By definition, an encountered breakpoint is a triggered
2575 breakpoint. */
2576 ++(b->hit_count);
c906108c 2577
c5aa993b
JM
2578 real_breakpoint = 1;
2579 }
2580
ed9a39eb
JM
2581 if (b->frame &&
2582 b->frame != (get_current_frame ())->frame)
c5aa993b
JM
2583 bs->stop = 0;
2584 else
2585 {
2586 int value_is_zero = 0;
2587
2588 if (b->cond)
2589 {
2590 /* Need to select the frame, with all that implies
2591 so that the conditions will have the right context. */
2592 select_frame (get_current_frame (), 0);
2593 value_is_zero
2594 = catch_errors (breakpoint_cond_eval, (b->cond),
2595 "Error in testing breakpoint condition:\n",
2596 RETURN_MASK_ALL);
2597 /* FIXME-someday, should give breakpoint # */
2598 free_all_values ();
2599 }
2600 if (b->cond && value_is_zero)
2601 {
2602 bs->stop = 0;
2603 /* Don't consider this a hit. */
2604 --(b->hit_count);
2605 }
2606 else if (b->ignore_count > 0)
2607 {
2608 b->ignore_count--;
5c44784c 2609 annotate_ignore_count_change ();
c5aa993b
JM
2610 bs->stop = 0;
2611 }
2612 else
2613 {
2614 /* We will stop here */
b5de0fa7
EZ
2615 if (b->disposition == disp_disable)
2616 b->enable_state = bp_disabled;
c5aa993b
JM
2617 bs->commands = b->commands;
2618 if (b->silent)
2619 bs->print = 0;
2620 if (bs->commands &&
2621 (STREQ ("silent", bs->commands->line) ||
2622 (xdb_commands && STREQ ("Q", bs->commands->line))))
2623 {
2624 bs->commands = bs->commands->next;
c906108c 2625 bs->print = 0;
c5aa993b
JM
2626 }
2627 }
2628 }
2629 /* Print nothing for this entry if we dont stop or if we dont print. */
2630 if (bs->stop == 0 || bs->print == 0)
2631 bs->print_it = print_it_noop;
2632 }
c906108c
SS
2633
2634 bs->next = NULL; /* Terminate the chain */
2635 bs = root_bs->next; /* Re-grab the head of the chain */
2636
2637 if (real_breakpoint && bs)
2638 {
c5aa993b 2639 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
c906108c 2640 {
c5aa993b 2641 if (DECR_PC_AFTER_HW_BREAK != 0)
c906108c
SS
2642 {
2643 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2644 write_pc (*pc);
2645 }
2646 }
2647 else
2648 {
2649 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2650 {
2651 *pc = bp_addr;
2652#if defined (SHIFT_INST_REGS)
c5aa993b 2653 SHIFT_INST_REGS ();
c906108c
SS
2654#else /* No SHIFT_INST_REGS. */
2655 write_pc (bp_addr);
2656#endif /* No SHIFT_INST_REGS. */
2657 }
2658 }
2659 }
2660
2661 /* The value of a hardware watchpoint hasn't changed, but the
2662 intermediate memory locations we are watching may have. */
c5aa993b 2663 if (bs && !bs->stop &&
c906108c
SS
2664 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2665 bs->breakpoint_at->type == bp_read_watchpoint ||
2666 bs->breakpoint_at->type == bp_access_watchpoint))
2667 {
2668 remove_breakpoints ();
2669 insert_breakpoints ();
2670 }
2671 return bs;
2672}
2673\f
2674/* Tell what to do about this bpstat. */
2675struct bpstat_what
fba45db2 2676bpstat_what (bpstat bs)
c906108c
SS
2677{
2678 /* Classify each bpstat as one of the following. */
c5aa993b
JM
2679 enum class
2680 {
2681 /* This bpstat element has no effect on the main_action. */
2682 no_effect = 0,
2683
2684 /* There was a watchpoint, stop but don't print. */
2685 wp_silent,
c906108c 2686
c5aa993b
JM
2687 /* There was a watchpoint, stop and print. */
2688 wp_noisy,
c906108c 2689
c5aa993b
JM
2690 /* There was a breakpoint but we're not stopping. */
2691 bp_nostop,
c906108c 2692
c5aa993b
JM
2693 /* There was a breakpoint, stop but don't print. */
2694 bp_silent,
c906108c 2695
c5aa993b
JM
2696 /* There was a breakpoint, stop and print. */
2697 bp_noisy,
c906108c 2698
c5aa993b
JM
2699 /* We hit the longjmp breakpoint. */
2700 long_jump,
c906108c 2701
c5aa993b
JM
2702 /* We hit the longjmp_resume breakpoint. */
2703 long_resume,
c906108c 2704
c5aa993b
JM
2705 /* We hit the step_resume breakpoint. */
2706 step_resume,
c906108c 2707
c5aa993b
JM
2708 /* We hit the through_sigtramp breakpoint. */
2709 through_sig,
c906108c 2710
c5aa993b
JM
2711 /* We hit the shared library event breakpoint. */
2712 shlib_event,
c906108c 2713
c5aa993b
JM
2714 /* We caught a shared library event. */
2715 catch_shlib_event,
c906108c 2716
c5aa993b
JM
2717 /* This is just used to count how many enums there are. */
2718 class_last
c906108c
SS
2719 };
2720
2721 /* Here is the table which drives this routine. So that we can
2722 format it pretty, we define some abbreviations for the
2723 enum bpstat_what codes. */
2724#define kc BPSTAT_WHAT_KEEP_CHECKING
2725#define ss BPSTAT_WHAT_STOP_SILENT
2726#define sn BPSTAT_WHAT_STOP_NOISY
2727#define sgl BPSTAT_WHAT_SINGLE
2728#define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2729#define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2730#define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2731#define sr BPSTAT_WHAT_STEP_RESUME
2732#define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2733#define shl BPSTAT_WHAT_CHECK_SHLIBS
2734#define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2735
2736/* "Can't happen." Might want to print an error message.
2737 abort() is not out of the question, but chances are GDB is just
2738 a bit confused, not unusable. */
2739#define err BPSTAT_WHAT_STOP_NOISY
2740
2741 /* Given an old action and a class, come up with a new action. */
2742 /* One interesting property of this table is that wp_silent is the same
2743 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2744 after stopping, the check for whether to step over a breakpoint
2745 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
53a5351d
JM
2746 reference to how we stopped. We retain separate wp_silent and
2747 bp_silent codes in case we want to change that someday.
43ff13b4
JM
2748
2749 Another possibly interesting property of this table is that
2750 there's a partial ordering, priority-like, of the actions. Once
2751 you've decided that some action is appropriate, you'll never go
2752 back and decide something of a lower priority is better. The
2753 ordering is:
2754
7e73cedf 2755 kc < clr sgl shl shlr slr sn sr ss ts
c5aa993b
JM
2756 sgl < clrs shl shlr slr sn sr ss ts
2757 slr < err shl shlr sn sr ss ts
2758 clr < clrs err shl shlr sn sr ss ts
2759 clrs < err shl shlr sn sr ss ts
2760 ss < shl shlr sn sr ts
2761 sn < shl shlr sr ts
2762 sr < shl shlr ts
2763 shl < shlr
2764 ts <
2765 shlr <
2766
43ff13b4
JM
2767 What I think this means is that we don't need a damned table
2768 here. If you just put the rows and columns in the right order,
2769 it'd look awfully regular. We could simply walk the bpstat list
2770 and choose the highest priority action we find, with a little
2771 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2772 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2773 is messy anyway). */
c906108c
SS
2774
2775 /* step_resume entries: a step resume breakpoint overrides another
2776 breakpoint of signal handling (see comment in wait_for_inferior
2777 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2778 /* We handle the through_sigtramp_breakpoint the same way; having both
2779 one of those and a step_resume_breakpoint is probably very rare (?). */
2780
2781 static const enum bpstat_what_main_action
c5aa993b
JM
2782 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2783 {
2784 /* old action */
2785 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2786 */
2787/*no_effect */
2788 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2789/*wp_silent */
2790 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2791/*wp_noisy */
2792 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2793/*bp_nostop */
2794 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2795/*bp_silent */
2796 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2797/*bp_noisy */
2798 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2799/*long_jump */
a48bb0b3 2800 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
c5aa993b
JM
2801/*long_resume */
2802 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2803/*step_resume */
2804 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2805/*through_sig */
2806 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2807/*shlib */
2808 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2809/*catch_shlib */
2810 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2811 };
c906108c
SS
2812
2813#undef kc
2814#undef ss
2815#undef sn
2816#undef sgl
2817#undef slr
2818#undef clr
2819#undef clrs
2820#undef err
2821#undef sr
2822#undef ts
2823#undef shl
2824#undef shlr
2825 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
2826 struct bpstat_what retval;
2827
2828 retval.call_dummy = 0;
2829 for (; bs != NULL; bs = bs->next)
2830 {
2831 enum class bs_class = no_effect;
2832 if (bs->breakpoint_at == NULL)
2833 /* I suspect this can happen if it was a momentary breakpoint
2834 which has since been deleted. */
2835 continue;
2836 switch (bs->breakpoint_at->type)
2837 {
2838 case bp_none:
2839 continue;
2840
2841 case bp_breakpoint:
2842 case bp_hardware_breakpoint:
2843 case bp_until:
2844 case bp_finish:
2845 if (bs->stop)
2846 {
2847 if (bs->print)
2848 bs_class = bp_noisy;
2849 else
2850 bs_class = bp_silent;
2851 }
2852 else
2853 bs_class = bp_nostop;
2854 break;
2855 case bp_watchpoint:
2856 case bp_hardware_watchpoint:
2857 case bp_read_watchpoint:
2858 case bp_access_watchpoint:
2859 if (bs->stop)
2860 {
2861 if (bs->print)
2862 bs_class = wp_noisy;
2863 else
2864 bs_class = wp_silent;
2865 }
2866 else
53a5351d
JM
2867 /* There was a watchpoint, but we're not stopping.
2868 This requires no further action. */
c906108c
SS
2869 bs_class = no_effect;
2870 break;
2871 case bp_longjmp:
2872 bs_class = long_jump;
2873 break;
2874 case bp_longjmp_resume:
2875 bs_class = long_resume;
2876 break;
2877 case bp_step_resume:
2878 if (bs->stop)
2879 {
2880 bs_class = step_resume;
2881 }
2882 else
2883 /* It is for the wrong frame. */
2884 bs_class = bp_nostop;
2885 break;
2886 case bp_through_sigtramp:
2887 bs_class = through_sig;
2888 break;
2889 case bp_watchpoint_scope:
2890 bs_class = bp_nostop;
2891 break;
c5aa993b
JM
2892 case bp_shlib_event:
2893 bs_class = shlib_event;
2894 break;
c4093a6a
JM
2895 case bp_thread_event:
2896 bs_class = bp_nostop;
2897 break;
c5aa993b
JM
2898 case bp_catch_load:
2899 case bp_catch_unload:
2900 /* Only if this catchpoint triggered should we cause the
2901 step-out-of-dld behaviour. Otherwise, we ignore this
2902 catchpoint. */
2903 if (bs->stop)
2904 bs_class = catch_shlib_event;
2905 else
2906 bs_class = no_effect;
2907 break;
2908 case bp_catch_fork:
2909 case bp_catch_vfork:
2910 case bp_catch_exec:
2911 if (bs->stop)
2912 {
2913 if (bs->print)
2914 bs_class = bp_noisy;
2915 else
2916 bs_class = bp_silent;
2917 }
2918 else
53a5351d
JM
2919 /* There was a catchpoint, but we're not stopping.
2920 This requires no further action. */
c5aa993b
JM
2921 bs_class = no_effect;
2922 break;
2923 case bp_catch_catch:
2924 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
2925 bs_class = bp_nostop;
2926 else if (bs->stop)
2927 bs_class = bs->print ? bp_noisy : bp_silent;
2928 break;
2929 case bp_catch_throw:
2930 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
2931 bs_class = bp_nostop;
2932 else if (bs->stop)
2933 bs_class = bs->print ? bp_noisy : bp_silent;
c906108c 2934 break;
c906108c 2935 case bp_call_dummy:
53a5351d
JM
2936 /* Make sure the action is stop (silent or noisy),
2937 so infrun.c pops the dummy frame. */
c906108c
SS
2938 bs_class = bp_silent;
2939 retval.call_dummy = 1;
2940 break;
2941 }
c5aa993b 2942 current_action = table[(int) bs_class][(int) current_action];
c906108c
SS
2943 }
2944 retval.main_action = current_action;
2945 return retval;
2946}
2947
2948/* Nonzero if we should step constantly (e.g. watchpoints on machines
2949 without hardware support). This isn't related to a specific bpstat,
2950 just to things like whether watchpoints are set. */
2951
c5aa993b 2952int
fba45db2 2953bpstat_should_step (void)
c906108c
SS
2954{
2955 struct breakpoint *b;
2956 ALL_BREAKPOINTS (b)
b5de0fa7 2957 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3172dc30 2958 return 1;
c906108c
SS
2959 return 0;
2960}
2961
2962/* Nonzero if there are enabled hardware watchpoints. */
2963int
fba45db2 2964bpstat_have_active_hw_watchpoints (void)
c906108c
SS
2965{
2966 struct breakpoint *b;
2967 ALL_BREAKPOINTS (b)
b5de0fa7 2968 if ((b->enable_state == bp_enabled) &&
c5aa993b
JM
2969 (b->inserted) &&
2970 ((b->type == bp_hardware_watchpoint) ||
2971 (b->type == bp_read_watchpoint) ||
2972 (b->type == bp_access_watchpoint)))
3172dc30 2973 return 1;
c906108c
SS
2974 return 0;
2975}
c906108c 2976\f
c5aa993b 2977
c906108c
SS
2978/* Given a bpstat that records zero or more triggered eventpoints, this
2979 function returns another bpstat which contains only the catchpoints
2980 on that first list, if any. */
2981void
fba45db2 2982bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
c5aa993b
JM
2983{
2984 struct bpstats root_bs[1];
2985 bpstat bs = root_bs;
2986 struct breakpoint *ep;
2987 char *dll_pathname;
2988
c906108c
SS
2989 bpstat_clear (cp_list);
2990 root_bs->next = NULL;
c5aa993b
JM
2991
2992 for (; ep_list != NULL; ep_list = ep_list->next)
c906108c
SS
2993 {
2994 /* Is this eventpoint a catchpoint? If not, ignore it. */
2995 ep = ep_list->breakpoint_at;
2996 if (ep == NULL)
c5aa993b
JM
2997 break;
2998 if ((ep->type != bp_catch_load) &&
2999 (ep->type != bp_catch_unload) &&
3000 (ep->type != bp_catch_catch) &&
53a5351d
JM
3001 (ep->type != bp_catch_throw))
3002 /* pai: (temp) ADD fork/vfork here!! */
c5aa993b
JM
3003 continue;
3004
c906108c
SS
3005 /* Yes; add it to the list. */
3006 bs = bpstat_alloc (ep, bs);
3007 *bs = *ep_list;
3008 bs->next = NULL;
3009 bs = root_bs->next;
c5aa993b 3010
c906108c
SS
3011#if defined(SOLIB_ADD)
3012 /* Also, for each triggered catchpoint, tag it with the name of
3013 the library that caused this trigger. (We copy the name now,
3014 because it's only guaranteed to be available NOW, when the
3015 catchpoint triggers. Clients who may wish to know the name
3016 later must get it from the catchpoint itself.) */
3017 if (ep->triggered_dll_pathname != NULL)
b8c9b27d 3018 xfree (ep->triggered_dll_pathname);
c906108c 3019 if (ep->type == bp_catch_load)
39f77062
KB
3020 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3021 PIDGET (inferior_ptid));
c906108c 3022 else
39f77062
KB
3023 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3024 PIDGET (inferior_ptid));
c906108c
SS
3025#else
3026 dll_pathname = NULL;
3027#endif
3028 if (dll_pathname)
3029 {
53a5351d
JM
3030 ep->triggered_dll_pathname = (char *)
3031 xmalloc (strlen (dll_pathname) + 1);
c906108c
SS
3032 strcpy (ep->triggered_dll_pathname, dll_pathname);
3033 }
3034 else
3035 ep->triggered_dll_pathname = NULL;
3036 }
c5aa993b 3037
c906108c
SS
3038 *cp_list = bs;
3039}
3040
c4093a6a 3041/* Print B to gdb_stdout. */
c906108c 3042static void
c4093a6a
JM
3043print_one_breakpoint (struct breakpoint *b,
3044 CORE_ADDR *last_addr)
c906108c 3045{
c906108c
SS
3046 register struct command_line *l;
3047 register struct symbol *sym;
c4093a6a
JM
3048 struct ep_type_description
3049 {
3050 enum bptype type;
3051 char *description;
3052 };
3053 static struct ep_type_description bptypes[] =
c906108c 3054 {
c5aa993b
JM
3055 {bp_none, "?deleted?"},
3056 {bp_breakpoint, "breakpoint"},
c906108c 3057 {bp_hardware_breakpoint, "hw breakpoint"},
c5aa993b
JM
3058 {bp_until, "until"},
3059 {bp_finish, "finish"},
3060 {bp_watchpoint, "watchpoint"},
c906108c 3061 {bp_hardware_watchpoint, "hw watchpoint"},
c5aa993b
JM
3062 {bp_read_watchpoint, "read watchpoint"},
3063 {bp_access_watchpoint, "acc watchpoint"},
3064 {bp_longjmp, "longjmp"},
3065 {bp_longjmp_resume, "longjmp resume"},
3066 {bp_step_resume, "step resume"},
3067 {bp_through_sigtramp, "sigtramp"},
3068 {bp_watchpoint_scope, "watchpoint scope"},
3069 {bp_call_dummy, "call dummy"},
3070 {bp_shlib_event, "shlib events"},
c4093a6a 3071 {bp_thread_event, "thread events"},
c5aa993b
JM
3072 {bp_catch_load, "catch load"},
3073 {bp_catch_unload, "catch unload"},
3074 {bp_catch_fork, "catch fork"},
3075 {bp_catch_vfork, "catch vfork"},
3076 {bp_catch_exec, "catch exec"},
3077 {bp_catch_catch, "catch catch"},
3078 {bp_catch_throw, "catch throw"}
3079 };
c4093a6a 3080
c5aa993b
JM
3081 static char *bpdisps[] =
3082 {"del", "dstp", "dis", "keep"};
c2c6d25f 3083 static char bpenables[] = "nynny";
c906108c 3084 char wrap_indent[80];
8b93c638
JM
3085 struct ui_stream *stb = ui_out_stream_new (uiout);
3086 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
c906108c 3087
c4093a6a 3088 annotate_record ();
666547aa 3089 ui_out_tuple_begin (uiout, "bkpt");
c4093a6a
JM
3090
3091 /* 1 */
3092 annotate_field (0);
8b93c638 3093 ui_out_field_int (uiout, "number", b->number);
c4093a6a
JM
3094
3095 /* 2 */
3096 annotate_field (1);
3097 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3098 || ((int) b->type != bptypes[(int) b->type].type))
8e65ff28
AC
3099 internal_error (__FILE__, __LINE__,
3100 "bptypes table does not describe type #%d.",
c4093a6a 3101 (int) b->type);
8b93c638 3102 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
c4093a6a
JM
3103
3104 /* 3 */
3105 annotate_field (2);
8b93c638 3106 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
c4093a6a
JM
3107
3108 /* 4 */
3109 annotate_field (3);
b5de0fa7 3110 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
8b93c638 3111 ui_out_spaces (uiout, 2);
c4093a6a
JM
3112
3113 /* 5 and 6 */
3114 strcpy (wrap_indent, " ");
3115 if (addressprint)
75ac9d7b
MS
3116 {
3117 if (TARGET_ADDR_BIT <= 32)
3118 strcat (wrap_indent, " ");
3119 else
3120 strcat (wrap_indent, " ");
3121 }
c4093a6a 3122 switch (b->type)
c5aa993b 3123 {
c4093a6a 3124 case bp_none:
8e65ff28
AC
3125 internal_error (__FILE__, __LINE__,
3126 "print_one_breakpoint: bp_none encountered\n");
c4093a6a 3127 break;
c906108c 3128
c4093a6a
JM
3129 case bp_watchpoint:
3130 case bp_hardware_watchpoint:
3131 case bp_read_watchpoint:
3132 case bp_access_watchpoint:
3133 /* Field 4, the address, is omitted (which makes the columns
3134 not line up too nicely with the headers, but the effect
3135 is relatively readable). */
8b93c638
JM
3136 if (addressprint)
3137 ui_out_field_skip (uiout, "addr");
3138 annotate_field (5);
3139 print_expression (b->exp, stb->stream);
3140 ui_out_field_stream (uiout, "what", stb);
c4093a6a
JM
3141 break;
3142
3143 case bp_catch_load:
3144 case bp_catch_unload:
3145 /* Field 4, the address, is omitted (which makes the columns
3146 not line up too nicely with the headers, but the effect
3147 is relatively readable). */
8b93c638
JM
3148 if (addressprint)
3149 ui_out_field_skip (uiout, "addr");
3150 annotate_field (5);
3151 if (b->dll_pathname == NULL)
3152 {
3153 ui_out_field_string (uiout, "what", "<any library>");
3154 ui_out_spaces (uiout, 1);
3155 }
3156 else
3157 {
3158 ui_out_text (uiout, "library \"");
3159 ui_out_field_string (uiout, "what", b->dll_pathname);
3160 ui_out_text (uiout, "\" ");
3161 }
c4093a6a
JM
3162 break;
3163
3164 case bp_catch_fork:
3165 case bp_catch_vfork:
3166 /* Field 4, the address, is omitted (which makes the columns
3167 not line up too nicely with the headers, but the effect
3168 is relatively readable). */
8b93c638
JM
3169 if (addressprint)
3170 ui_out_field_skip (uiout, "addr");
3171 annotate_field (5);
3172 if (b->forked_inferior_pid != 0)
3173 {
3174 ui_out_text (uiout, "process ");
3175 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3176 ui_out_spaces (uiout, 1);
3177 }
c4093a6a
JM
3178
3179 case bp_catch_exec:
3180 /* Field 4, the address, is omitted (which makes the columns
3181 not line up too nicely with the headers, but the effect
3182 is relatively readable). */
8b93c638
JM
3183 if (addressprint)
3184 ui_out_field_skip (uiout, "addr");
3185 annotate_field (5);
3186 if (b->exec_pathname != NULL)
3187 {
3188 ui_out_text (uiout, "program \"");
3189 ui_out_field_string (uiout, "what", b->exec_pathname);
3190 ui_out_text (uiout, "\" ");
3191 }
c4093a6a 3192 break;
c906108c 3193
c4093a6a
JM
3194 case bp_catch_catch:
3195 /* Field 4, the address, is omitted (which makes the columns
3196 not line up too nicely with the headers, but the effect
3197 is relatively readable). */
8b93c638
JM
3198 if (addressprint)
3199 ui_out_field_skip (uiout, "addr");
3200 annotate_field (5);
3201 ui_out_field_string (uiout, "what", "exception catch");
3202 ui_out_spaces (uiout, 1);
c4093a6a 3203 break;
c906108c 3204
c4093a6a
JM
3205 case bp_catch_throw:
3206 /* Field 4, the address, is omitted (which makes the columns
3207 not line up too nicely with the headers, but the effect
3208 is relatively readable). */
8b93c638
JM
3209 if (addressprint)
3210 ui_out_field_skip (uiout, "addr");
3211 annotate_field (5);
3212 ui_out_field_string (uiout, "what", "exception throw");
3213 ui_out_spaces (uiout, 1);
c4093a6a
JM
3214 break;
3215
3216 case bp_breakpoint:
3217 case bp_hardware_breakpoint:
3218 case bp_until:
3219 case bp_finish:
3220 case bp_longjmp:
3221 case bp_longjmp_resume:
3222 case bp_step_resume:
3223 case bp_through_sigtramp:
3224 case bp_watchpoint_scope:
3225 case bp_call_dummy:
3226 case bp_shlib_event:
3227 case bp_thread_event:
8b93c638
JM
3228 if (addressprint)
3229 {
3230 annotate_field (4);
3231 ui_out_field_core_addr (uiout, "addr", b->address);
3232 }
3233 annotate_field (5);
3234 *last_addr = b->address;
3235 if (b->source_file)
3236 {
3237 sym = find_pc_sect_function (b->address, b->section);
3238 if (sym)
3239 {
3240 ui_out_text (uiout, "in ");
3241 ui_out_field_string (uiout, "func",
3242 SYMBOL_SOURCE_NAME (sym));
3243 ui_out_wrap_hint (uiout, wrap_indent);
3244 ui_out_text (uiout, " at ");
3245 }
3246 ui_out_field_string (uiout, "file", b->source_file);
3247 ui_out_text (uiout, ":");
3248 ui_out_field_int (uiout, "line", b->line_number);
3249 }
3250 else
3251 {
3252 print_address_symbolic (b->address, stb->stream, demangle, "");
3253 ui_out_field_stream (uiout, "at", stb);
3254 }
c4093a6a
JM
3255 break;
3256 }
3257
3258 if (b->thread != -1)
3259 {
8b93c638
JM
3260 /* FIXME: This seems to be redundant and lost here; see the
3261 "stop only in" line a little further down. */
3262 ui_out_text (uiout, " thread ");
3263 ui_out_field_int (uiout, "thread", b->thread);
c4093a6a
JM
3264 }
3265
8b93c638 3266 ui_out_text (uiout, "\n");
c4093a6a
JM
3267
3268 if (b->frame)
3269 {
3270 annotate_field (6);
8b93c638
JM
3271 ui_out_text (uiout, "\tstop only in stack frame at ");
3272 ui_out_field_core_addr (uiout, "frame", b->frame);
3273 ui_out_text (uiout, "\n");
c4093a6a
JM
3274 }
3275
3276 if (b->cond)
3277 {
3278 annotate_field (7);
8b93c638
JM
3279 ui_out_text (uiout, "\tstop only if ");
3280 print_expression (b->cond, stb->stream);
3281 ui_out_field_stream (uiout, "cond", stb);
3282 ui_out_text (uiout, "\n");
c4093a6a
JM
3283 }
3284
3285 if (b->thread != -1)
3286 {
3287 /* FIXME should make an annotation for this */
8b93c638
JM
3288 ui_out_text (uiout, "\tstop only in thread ");
3289 ui_out_field_int (uiout, "thread", b->thread);
3290 ui_out_text (uiout, "\n");
c4093a6a
JM
3291 }
3292
3293 if (show_breakpoint_hit_counts && b->hit_count)
3294 {
3295 /* FIXME should make an annotation for this */
8b93c638
JM
3296 if (ep_is_catchpoint (b))
3297 ui_out_text (uiout, "\tcatchpoint");
3298 else
3299 ui_out_text (uiout, "\tbreakpoint");
3300 ui_out_text (uiout, " already hit ");
3301 ui_out_field_int (uiout, "times", b->hit_count);
3302 if (b->hit_count == 1)
3303 ui_out_text (uiout, " time\n");
3304 else
3305 ui_out_text (uiout, " times\n");
c4093a6a
JM
3306 }
3307
fb40c209
AC
3308 /* Output the count also if it is zero, but only if this is
3309 mi. FIXME: Should have a better test for this. */
9dc5e2a9 3310 if (ui_out_is_mi_like_p (uiout))
fb40c209
AC
3311 if (show_breakpoint_hit_counts && b->hit_count == 0)
3312 ui_out_field_int (uiout, "times", b->hit_count);
8b93c638 3313
c4093a6a
JM
3314 if (b->ignore_count)
3315 {
3316 annotate_field (8);
8b93c638
JM
3317 ui_out_text (uiout, "\tignore next ");
3318 ui_out_field_int (uiout, "ignore", b->ignore_count);
3319 ui_out_text (uiout, " hits\n");
c4093a6a
JM
3320 }
3321
3322 if ((l = b->commands))
3323 {
3324 annotate_field (9);
666547aa 3325 ui_out_tuple_begin (uiout, "script");
8b93c638 3326 print_command_lines (uiout, l, 4);
666547aa 3327 ui_out_tuple_end (uiout);
c4093a6a 3328 }
666547aa 3329 ui_out_tuple_end (uiout);
8b93c638 3330 do_cleanups (old_chain);
c4093a6a 3331}
c5aa993b 3332
c4093a6a
JM
3333struct captured_breakpoint_query_args
3334 {
3335 int bnum;
3336 };
c5aa993b 3337
c4093a6a 3338static int
2b65245e 3339do_captured_breakpoint_query (struct ui_out *uiout, void *data)
c4093a6a
JM
3340{
3341 struct captured_breakpoint_query_args *args = data;
3342 register struct breakpoint *b;
3343 CORE_ADDR dummy_addr = 0;
3344 ALL_BREAKPOINTS (b)
3345 {
3346 if (args->bnum == b->number)
c5aa993b 3347 {
c4093a6a
JM
3348 print_one_breakpoint (b, &dummy_addr);
3349 return GDB_RC_OK;
c5aa993b 3350 }
c4093a6a
JM
3351 }
3352 return GDB_RC_NONE;
3353}
c5aa993b 3354
c4093a6a 3355enum gdb_rc
2b65245e 3356gdb_breakpoint_query (struct ui_out *uiout, int bnum)
c4093a6a
JM
3357{
3358 struct captured_breakpoint_query_args args;
3359 args.bnum = bnum;
3360 /* For the moment we don't trust print_one_breakpoint() to not throw
3361 an error. */
2b65245e
AC
3362 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3363 NULL, RETURN_MASK_ALL);
c4093a6a 3364}
c5aa993b 3365
7f3b0473
AC
3366/* Return non-zero if B is user settable (breakpoints, watchpoints,
3367 catchpoints, et.al.). */
3368
3369static int
3370user_settable_breakpoint (const struct breakpoint *b)
3371{
3372 return (b->type == bp_breakpoint
3373 || b->type == bp_catch_load
3374 || b->type == bp_catch_unload
3375 || b->type == bp_catch_fork
3376 || b->type == bp_catch_vfork
3377 || b->type == bp_catch_exec
3378 || b->type == bp_catch_catch
3379 || b->type == bp_catch_throw
3380 || b->type == bp_hardware_breakpoint
3381 || b->type == bp_watchpoint
3382 || b->type == bp_read_watchpoint
3383 || b->type == bp_access_watchpoint
3384 || b->type == bp_hardware_watchpoint);
3385}
3386
3387/* Print information on user settable breakpoint (watchpoint, etc)
3388 number BNUM. If BNUM is -1 print all user settable breakpoints.
3389 If ALLFLAG is non-zero, include non- user settable breakpoints. */
c906108c 3390
c4093a6a 3391static void
fba45db2 3392breakpoint_1 (int bnum, int allflag)
c4093a6a
JM
3393{
3394 register struct breakpoint *b;
3395 CORE_ADDR last_addr = (CORE_ADDR) -1;
7f3b0473 3396 int nr_printable_breakpoints;
c4093a6a 3397
7f3b0473
AC
3398 /* Compute the number of rows in the table. */
3399 nr_printable_breakpoints = 0;
3400 ALL_BREAKPOINTS (b)
3401 if (bnum == -1
3402 || bnum == b->number)
3403 {
3404 if (allflag || user_settable_breakpoint (b))
3405 nr_printable_breakpoints++;
3406 }
3407
8b93c638 3408 if (addressprint)
d63f1d40 3409 ui_out_table_begin (uiout, 6, nr_printable_breakpoints, "BreakpointTable");
8b93c638 3410 else
d63f1d40 3411 ui_out_table_begin (uiout, 5, nr_printable_breakpoints, "BreakpointTable");
8b93c638 3412
7f3b0473 3413 if (nr_printable_breakpoints > 0)
d7faa9e7
AC
3414 annotate_breakpoints_headers ();
3415 if (nr_printable_breakpoints > 0)
3416 annotate_field (0);
3417 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3418 if (nr_printable_breakpoints > 0)
3419 annotate_field (1);
3420 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3421 if (nr_printable_breakpoints > 0)
3422 annotate_field (2);
3423 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3424 if (nr_printable_breakpoints > 0)
3425 annotate_field (3);
3426 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3427 if (addressprint)
7f3b0473 3428 {
d7faa9e7
AC
3429 if (nr_printable_breakpoints > 0)
3430 annotate_field (4);
7f3b0473 3431 if (TARGET_ADDR_BIT <= 32)
b25959ec 3432 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
7f3b0473 3433 else
b25959ec 3434 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
7f3b0473 3435 }
d7faa9e7
AC
3436 if (nr_printable_breakpoints > 0)
3437 annotate_field (5);
3438 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3439 ui_out_table_body (uiout);
3440 if (nr_printable_breakpoints > 0)
3441 annotate_breakpoints_table ();
7f3b0473 3442
c4093a6a
JM
3443 ALL_BREAKPOINTS (b)
3444 if (bnum == -1
3445 || bnum == b->number)
3446 {
3447 /* We only print out user settable breakpoints unless the
3448 allflag is set. */
7f3b0473
AC
3449 if (allflag || user_settable_breakpoint (b))
3450 print_one_breakpoint (b, &last_addr);
c4093a6a
JM
3451 }
3452
698384cd 3453 ui_out_table_end (uiout);
698384cd 3454
7f3b0473 3455 if (nr_printable_breakpoints == 0)
c906108c 3456 {
8b93c638
JM
3457 if (bnum == -1)
3458 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3459 else
3460 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3461 bnum);
c906108c
SS
3462 }
3463 else
c4093a6a
JM
3464 {
3465 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3466 that a comparison of an unsigned with -1 is always false. */
3467 if (last_addr != (CORE_ADDR) -1)
3468 set_next_address (last_addr);
3469 }
c906108c 3470
c4093a6a
JM
3471 /* FIXME? Should this be moved up so that it is only called when
3472 there have been breakpoints? */
c906108c
SS
3473 annotate_breakpoints_table_end ();
3474}
3475
3476/* ARGSUSED */
3477static void
fba45db2 3478breakpoints_info (char *bnum_exp, int from_tty)
c906108c
SS
3479{
3480 int bnum = -1;
3481
3482 if (bnum_exp)
bb518678 3483 bnum = parse_and_eval_long (bnum_exp);
c906108c
SS
3484
3485 breakpoint_1 (bnum, 0);
3486}
3487
c906108c 3488/* ARGSUSED */
7a292a7a 3489static void
fba45db2 3490maintenance_info_breakpoints (char *bnum_exp, int from_tty)
c906108c
SS
3491{
3492 int bnum = -1;
3493
3494 if (bnum_exp)
bb518678 3495 bnum = parse_and_eval_long (bnum_exp);
c906108c
SS
3496
3497 breakpoint_1 (bnum, 1);
3498}
3499
c906108c
SS
3500/* Print a message describing any breakpoints set at PC. */
3501
3502static void
fba45db2 3503describe_other_breakpoints (CORE_ADDR pc, asection *section)
c906108c
SS
3504{
3505 register int others = 0;
3506 register struct breakpoint *b;
3507
3508 ALL_BREAKPOINTS (b)
3509 if (b->address == pc)
c5aa993b
JM
3510 if (overlay_debugging == 0 ||
3511 b->section == section)
3512 others++;
c906108c
SS
3513 if (others > 0)
3514 {
3515 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3516 ALL_BREAKPOINTS (b)
3517 if (b->address == pc)
c5aa993b
JM
3518 if (overlay_debugging == 0 ||
3519 b->section == section)
3520 {
3521 others--;
d85310f7
MS
3522 printf_filtered ("%d%s%s ",
3523 b->number,
b5de0fa7
EZ
3524 ((b->enable_state == bp_disabled ||
3525 b->enable_state == bp_shlib_disabled ||
3526 b->enable_state == bp_call_disabled) ? " (disabled)"
3527 : b->enable_state == bp_permanent ? " (permanent)"
d85310f7
MS
3528 : ""),
3529 (others > 1) ? ","
3530 : ((others == 1) ? " and" : ""));
c5aa993b 3531 }
c906108c
SS
3532 printf_filtered ("also set at pc ");
3533 print_address_numeric (pc, 1, gdb_stdout);
3534 printf_filtered (".\n");
3535 }
3536}
3537\f
3538/* Set the default place to put a breakpoint
3539 for the `break' command with no arguments. */
3540
3541void
fba45db2
KB
3542set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3543 int line)
c906108c
SS
3544{
3545 default_breakpoint_valid = valid;
3546 default_breakpoint_address = addr;
3547 default_breakpoint_symtab = symtab;
3548 default_breakpoint_line = line;
3549}
3550
e4f237da
KB
3551/* Return true iff it is meaningful to use the address member of
3552 BPT. For some breakpoint types, the address member is irrelevant
3553 and it makes no sense to attempt to compare it to other addresses
3554 (or use it for any other purpose either).
3555
3556 More specifically, each of the following breakpoint types will always
3557 have a zero valued address and we don't want check_duplicates() to mark
3558 breakpoints of any of these types to be a duplicate of an actual
3559 breakpoint at address zero:
3560
3561 bp_watchpoint
3562 bp_hardware_watchpoint
3563 bp_read_watchpoint
3564 bp_access_watchpoint
3565 bp_catch_exec
3566 bp_longjmp_resume
3567 bp_catch_fork
3568 bp_catch_vork */
3569
3570static int
3571breakpoint_address_is_meaningful (struct breakpoint *bpt)
3572{
3573 enum bptype type = bpt->type;
3574
3575 return (type != bp_watchpoint
3576 && type != bp_hardware_watchpoint
3577 && type != bp_read_watchpoint
3578 && type != bp_access_watchpoint
3579 && type != bp_catch_exec
3580 && type != bp_longjmp_resume
3581 && type != bp_catch_fork
3582 && type != bp_catch_vfork);
3583}
3584
9f60f21b 3585/* Rescan breakpoints at the same address and section as BPT,
c906108c 3586 marking the first one as "first" and any others as "duplicates".
c2c6d25f 3587 This is so that the bpt instruction is only inserted once.
9f60f21b
JB
3588 If we have a permanent breakpoint at the same place as BPT, make
3589 that one the official one, and the rest as duplicates. */
c906108c
SS
3590
3591static void
9f60f21b 3592check_duplicates (struct breakpoint *bpt)
c906108c
SS
3593{
3594 register struct breakpoint *b;
3595 register int count = 0;
c2c6d25f 3596 struct breakpoint *perm_bp = 0;
9f60f21b
JB
3597 CORE_ADDR address = bpt->address;
3598 asection *section = bpt->section;
c906108c 3599
e4f237da 3600 if (! breakpoint_address_is_meaningful (bpt))
c906108c
SS
3601 return;
3602
3603 ALL_BREAKPOINTS (b)
b5de0fa7
EZ
3604 if (b->enable_state != bp_disabled
3605 && b->enable_state != bp_shlib_disabled
3606 && b->enable_state != bp_call_disabled
c906108c 3607 && b->address == address
e4f237da
KB
3608 && (overlay_debugging == 0 || b->section == section)
3609 && breakpoint_address_is_meaningful (b))
c5aa993b 3610 {
c2c6d25f 3611 /* Have we found a permanent breakpoint? */
b5de0fa7 3612 if (b->enable_state == bp_permanent)
c2c6d25f
JM
3613 {
3614 perm_bp = b;
3615 break;
3616 }
3617
c5aa993b
JM
3618 count++;
3619 b->duplicate = count > 1;
3620 }
c2c6d25f
JM
3621
3622 /* If we found a permanent breakpoint at this address, go over the
3623 list again and declare all the other breakpoints there to be the
3624 duplicates. */
3625 if (perm_bp)
3626 {
3627 perm_bp->duplicate = 0;
3628
3629 /* Permanent breakpoint should always be inserted. */
3630 if (! perm_bp->inserted)
8e65ff28
AC
3631 internal_error (__FILE__, __LINE__,
3632 "allegedly permanent breakpoint is not "
c2c6d25f
JM
3633 "actually inserted");
3634
3635 ALL_BREAKPOINTS (b)
3636 if (b != perm_bp)
3637 {
3638 if (b->inserted)
8e65ff28
AC
3639 internal_error (__FILE__, __LINE__,
3640 "another breakpoint was inserted on top of "
c2c6d25f
JM
3641 "a permanent breakpoint");
3642
b5de0fa7
EZ
3643 if (b->enable_state != bp_disabled
3644 && b->enable_state != bp_shlib_disabled
3645 && b->enable_state != bp_call_disabled
c2c6d25f 3646 && b->address == address
e4f237da
KB
3647 && (overlay_debugging == 0 || b->section == section)
3648 && breakpoint_address_is_meaningful (b))
c2c6d25f
JM
3649 b->duplicate = 1;
3650 }
3651 }
c906108c
SS
3652}
3653
4d28f7a8
KB
3654/* set_raw_breakpoint() is a low level routine for allocating and
3655 partially initializing a breakpoint of type BPTYPE. The newly
3656 created breakpoint's address, section, source file name, and line
3657 number are provided by SAL. The newly created and partially
3658 initialized breakpoint is added to the breakpoint chain and
3659 is also returned as the value of this function.
c906108c 3660
4d28f7a8
KB
3661 It is expected that the caller will complete the initialization of
3662 the newly created breakpoint struct as well as output any status
3663 information regarding the creation of a new breakpoint. In
3664 particular, set_raw_breakpoint() does NOT set the breakpoint
3665 number! Care should be taken to not allow an error() to occur
3666 prior to completing the initialization of the breakpoint. If this
3667 should happen, a bogus breakpoint will be left on the chain. */
c906108c
SS
3668
3669struct breakpoint *
4d28f7a8 3670set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
c906108c
SS
3671{
3672 register struct breakpoint *b, *b1;
3673
3674 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3675 memset (b, 0, sizeof (*b));
3676 b->address = sal.pc;
3677 if (sal.symtab == NULL)
3678 b->source_file = NULL;
3679 else
3680 b->source_file = savestring (sal.symtab->filename,
3681 strlen (sal.symtab->filename));
3682 b->section = sal.section;
4d28f7a8 3683 b->type = bptype;
c906108c
SS
3684 b->language = current_language->la_language;
3685 b->input_radix = input_radix;
3686 b->thread = -1;
3687 b->line_number = sal.line;
b5de0fa7 3688 b->enable_state = bp_enabled;
c906108c
SS
3689 b->next = 0;
3690 b->silent = 0;
3691 b->ignore_count = 0;
3692 b->commands = NULL;
3693 b->frame = 0;
3694 b->dll_pathname = NULL;
3695 b->triggered_dll_pathname = NULL;
3696 b->forked_inferior_pid = 0;
3697 b->exec_pathname = NULL;
3698
3699 /* Add this breakpoint to the end of the chain
3700 so that a list of breakpoints will come out in order
3701 of increasing numbers. */
3702
3703 b1 = breakpoint_chain;
3704 if (b1 == 0)
3705 breakpoint_chain = b;
3706 else
3707 {
3708 while (b1->next)
3709 b1 = b1->next;
3710 b1->next = b;
3711 }
3712
9f60f21b 3713 check_duplicates (b);
c906108c
SS
3714 breakpoints_changed ();
3715
3716 return b;
3717}
3718
c2c6d25f
JM
3719
3720/* Note that the breakpoint object B describes a permanent breakpoint
3721 instruction, hard-wired into the inferior's code. */
3722void
3723make_breakpoint_permanent (struct breakpoint *b)
3724{
b5de0fa7 3725 b->enable_state = bp_permanent;
c2c6d25f
JM
3726
3727 /* By definition, permanent breakpoints are already present in the code. */
3728 b->inserted = 1;
3729}
3730
c906108c
SS
3731#ifdef GET_LONGJMP_TARGET
3732
3733static void
fba45db2 3734create_longjmp_breakpoint (char *func_name)
c906108c
SS
3735{
3736 struct symtab_and_line sal;
3737 struct breakpoint *b;
3738
c5aa993b 3739 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3740 if (func_name != NULL)
3741 {
3742 struct minimal_symbol *m;
3743
53a5351d
JM
3744 m = lookup_minimal_symbol_text (func_name, NULL,
3745 (struct objfile *) NULL);
c906108c
SS
3746 if (m)
3747 sal.pc = SYMBOL_VALUE_ADDRESS (m);
3748 else
3749 return;
3750 }
3751 sal.section = find_pc_overlay (sal.pc);
4d28f7a8
KB
3752 b = set_raw_breakpoint (sal,
3753 func_name != NULL ? bp_longjmp : bp_longjmp_resume);
c906108c 3754
b5de0fa7
EZ
3755 b->disposition = disp_donttouch;
3756 b->enable_state = bp_disabled;
c906108c
SS
3757 b->silent = 1;
3758 if (func_name)
4fcf66da 3759 b->addr_string = xstrdup (func_name);
c906108c
SS
3760 b->number = internal_breakpoint_number--;
3761}
3762
c5aa993b 3763#endif /* #ifdef GET_LONGJMP_TARGET */
c906108c 3764
53a5351d
JM
3765/* Call this routine when stepping and nexting to enable a breakpoint
3766 if we do a longjmp(). When we hit that breakpoint, call
c906108c
SS
3767 set_longjmp_resume_breakpoint() to figure out where we are going. */
3768
3769void
fba45db2 3770enable_longjmp_breakpoint (void)
c906108c
SS
3771{
3772 register struct breakpoint *b;
3773
3774 ALL_BREAKPOINTS (b)
3775 if (b->type == bp_longjmp)
c5aa993b 3776 {
b5de0fa7 3777 b->enable_state = bp_enabled;
9f60f21b 3778 check_duplicates (b);
c5aa993b 3779 }
c906108c
SS
3780}
3781
3782void
fba45db2 3783disable_longjmp_breakpoint (void)
c906108c
SS
3784{
3785 register struct breakpoint *b;
3786
3787 ALL_BREAKPOINTS (b)
c5aa993b 3788 if (b->type == bp_longjmp
c906108c 3789 || b->type == bp_longjmp_resume)
c5aa993b 3790 {
b5de0fa7 3791 b->enable_state = bp_disabled;
9f60f21b 3792 check_duplicates (b);
c5aa993b 3793 }
c906108c
SS
3794}
3795
c4093a6a 3796struct breakpoint *
fba45db2 3797create_thread_event_breakpoint (CORE_ADDR address)
c4093a6a
JM
3798{
3799 struct breakpoint *b;
3800 struct symtab_and_line sal;
3801 char addr_string[80]; /* Surely an addr can't be longer than that. */
3802
3803 INIT_SAL (&sal); /* initialize to zeroes */
3804 sal.pc = address;
3805 sal.section = find_pc_overlay (sal.pc);
4d28f7a8 3806 b = set_raw_breakpoint (sal, bp_thread_event);
c4093a6a
JM
3807
3808 b->number = internal_breakpoint_number--;
b5de0fa7
EZ
3809 b->disposition = disp_donttouch;
3810 b->enable_state = bp_enabled;
c4093a6a
JM
3811 /* addr_string has to be used or breakpoint_re_set will delete me. */
3812 sprintf (addr_string, "*0x%s", paddr (b->address));
4fcf66da 3813 b->addr_string = xstrdup (addr_string);
c4093a6a
JM
3814
3815 return b;
3816}
3817
3818void
3819remove_thread_event_breakpoints (void)
3820{
3821 struct breakpoint *b, *temp;
3822
3823 ALL_BREAKPOINTS_SAFE (b, temp)
3824 if (b->type == bp_thread_event)
3825 delete_breakpoint (b);
3826}
3827
c906108c
SS
3828#ifdef SOLIB_ADD
3829void
fba45db2 3830remove_solib_event_breakpoints (void)
c906108c
SS
3831{
3832 register struct breakpoint *b, *temp;
3833
3834 ALL_BREAKPOINTS_SAFE (b, temp)
3835 if (b->type == bp_shlib_event)
3172dc30 3836 delete_breakpoint (b);
c906108c
SS
3837}
3838
c2c6d25f 3839struct breakpoint *
fba45db2 3840create_solib_event_breakpoint (CORE_ADDR address)
c906108c
SS
3841{
3842 struct breakpoint *b;
3843 struct symtab_and_line sal;
3844
c5aa993b 3845 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
3846 sal.pc = address;
3847 sal.section = find_pc_overlay (sal.pc);
4d28f7a8 3848 b = set_raw_breakpoint (sal, bp_shlib_event);
c906108c 3849 b->number = internal_breakpoint_number--;
b5de0fa7 3850 b->disposition = disp_donttouch;
c2c6d25f
JM
3851
3852 return b;
c906108c
SS
3853}
3854
104c1213
JM
3855/* Disable any breakpoints that are on code in shared libraries. Only
3856 apply to enabled breakpoints, disabled ones can just stay disabled. */
3857
c906108c 3858void
fba45db2 3859disable_breakpoints_in_shlibs (int silent)
c906108c 3860{
c5aa993b
JM
3861 struct breakpoint *b;
3862 int disabled_shlib_breaks = 0;
c906108c
SS
3863
3864 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3865 ALL_BREAKPOINTS (b)
c5aa993b 3866 {
c906108c 3867#if defined (PC_SOLIB)
c5aa993b
JM
3868 if (((b->type == bp_breakpoint) ||
3869 (b->type == bp_hardware_breakpoint)) &&
b5de0fa7 3870 b->enable_state == bp_enabled &&
c5aa993b
JM
3871 !b->duplicate &&
3872 PC_SOLIB (b->address))
3873 {
b5de0fa7 3874 b->enable_state = bp_shlib_disabled;
c5aa993b
JM
3875 if (!silent)
3876 {
3877 if (!disabled_shlib_breaks)
3878 {
3879 target_terminal_ours_for_output ();
53a5351d 3880 warning ("Temporarily disabling shared library breakpoints:");
c5aa993b
JM
3881 }
3882 disabled_shlib_breaks = 1;
53a5351d 3883 warning ("breakpoint #%d ", b->number);
c5aa993b
JM
3884 }
3885 }
c906108c 3886#endif
c5aa993b 3887 }
c906108c
SS
3888}
3889
3890/* Try to reenable any breakpoints in shared libraries. */
3891void
fba45db2 3892re_enable_breakpoints_in_shlibs (void)
c906108c
SS
3893{
3894 struct breakpoint *b;
3895
3896 ALL_BREAKPOINTS (b)
b5de0fa7 3897 if (b->enable_state == bp_shlib_disabled)
c5aa993b
JM
3898 {
3899 char buf[1];
c906108c 3900
c5aa993b
JM
3901 /* Do not reenable the breakpoint if the shared library
3902 is still not mapped in. */
3903 if (target_read_memory (b->address, buf, 1) == 0)
b5de0fa7 3904 b->enable_state = bp_enabled;
c5aa993b 3905 }
c906108c
SS
3906}
3907
3908#endif
3909
3910static void
fba45db2
KB
3911solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
3912 char *cond_string, enum bptype bp_kind)
c906108c 3913{
c5aa993b 3914 struct breakpoint *b;
c906108c 3915 struct symtabs_and_lines sals;
c5aa993b
JM
3916 struct cleanup *old_chain;
3917 struct cleanup *canonical_strings_chain = NULL;
c5aa993b
JM
3918 char *addr_start = hookname;
3919 char *addr_end = NULL;
3920 char **canonical = (char **) NULL;
3921 int thread = -1; /* All threads. */
3922
c906108c
SS
3923 /* Set a breakpoint on the specified hook. */
3924 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
3925 addr_end = hookname;
c5aa993b 3926
c906108c
SS
3927 if (sals.nelts == 0)
3928 {
3929 warning ("Unable to set a breakpoint on dynamic linker callback.");
3930 warning ("Suggest linking with /opt/langtools/lib/end.o.");
3931 warning ("GDB will be unable to track shl_load/shl_unload calls");
3932 return;
3933 }
3934 if (sals.nelts != 1)
3935 {
53a5351d 3936 warning ("Unable to set unique breakpoint on dynamic linker callback.");
c906108c
SS
3937 warning ("GDB will be unable to track shl_load/shl_unload calls");
3938 return;
3939 }
3940
53a5351d
JM
3941 /* Make sure that all storage allocated in decode_line_1 gets freed
3942 in case the following errors out. */
b8c9b27d 3943 old_chain = make_cleanup (xfree, sals.sals);
c5aa993b 3944 if (canonical != (char **) NULL)
c906108c 3945 {
b8c9b27d 3946 make_cleanup (xfree, canonical);
c906108c
SS
3947 canonical_strings_chain = make_cleanup (null_cleanup, 0);
3948 if (canonical[0] != NULL)
b8c9b27d 3949 make_cleanup (xfree, canonical[0]);
c906108c 3950 }
c5aa993b 3951
c906108c 3952 resolve_sal_pc (&sals.sals[0]);
c5aa993b 3953
c906108c 3954 /* Remove the canonical strings from the cleanup, they are needed below. */
c5aa993b 3955 if (canonical != (char **) NULL)
c906108c 3956 discard_cleanups (canonical_strings_chain);
c5aa993b 3957
4d28f7a8 3958 b = set_raw_breakpoint (sals.sals[0], bp_kind);
c906108c
SS
3959 set_breakpoint_count (breakpoint_count + 1);
3960 b->number = breakpoint_count;
3961 b->cond = NULL;
53a5351d
JM
3962 b->cond_string = (cond_string == NULL) ?
3963 NULL : savestring (cond_string, strlen (cond_string));
c906108c 3964 b->thread = thread;
c5aa993b
JM
3965
3966 if (canonical != (char **) NULL && canonical[0] != NULL)
c906108c
SS
3967 b->addr_string = canonical[0];
3968 else if (addr_start)
3969 b->addr_string = savestring (addr_start, addr_end - addr_start);
c5aa993b 3970
b5de0fa7
EZ
3971 b->enable_state = bp_enabled;
3972 b->disposition = tempflag ? disp_del : disp_donttouch;
c5aa993b 3973
c906108c
SS
3974 if (dll_pathname == NULL)
3975 b->dll_pathname = NULL;
3976 else
3977 {
3978 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
3979 strcpy (b->dll_pathname, dll_pathname);
3980 }
c5aa993b 3981
c906108c
SS
3982 mention (b);
3983 do_cleanups (old_chain);
3984}
3985
3986void
fba45db2
KB
3987create_solib_load_event_breakpoint (char *hookname, int tempflag,
3988 char *dll_pathname, char *cond_string)
c906108c 3989{
53a5351d
JM
3990 solib_load_unload_1 (hookname, tempflag, dll_pathname,
3991 cond_string, bp_catch_load);
c906108c
SS
3992}
3993
3994void
fba45db2
KB
3995create_solib_unload_event_breakpoint (char *hookname, int tempflag,
3996 char *dll_pathname, char *cond_string)
c906108c 3997{
53a5351d
JM
3998 solib_load_unload_1 (hookname,tempflag, dll_pathname,
3999 cond_string, bp_catch_unload);
c906108c
SS
4000}
4001
4002static void
fba45db2
KB
4003create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4004 enum bptype bp_kind)
c906108c 4005{
c5aa993b
JM
4006 struct symtab_and_line sal;
4007 struct breakpoint *b;
4008 int thread = -1; /* All threads. */
4009
4010 INIT_SAL (&sal);
c906108c
SS
4011 sal.pc = 0;
4012 sal.symtab = NULL;
4013 sal.line = 0;
c5aa993b 4014
4d28f7a8 4015 b = set_raw_breakpoint (sal, bp_kind);
c906108c
SS
4016 set_breakpoint_count (breakpoint_count + 1);
4017 b->number = breakpoint_count;
4018 b->cond = NULL;
53a5351d
JM
4019 b->cond_string = (cond_string == NULL) ?
4020 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
4021 b->thread = thread;
4022 b->addr_string = NULL;
b5de0fa7
EZ
4023 b->enable_state = bp_enabled;
4024 b->disposition = tempflag ? disp_del : disp_donttouch;
c906108c 4025 b->forked_inferior_pid = 0;
c5aa993b 4026
c906108c
SS
4027 mention (b);
4028}
4029
4030void
fba45db2 4031create_fork_event_catchpoint (int tempflag, char *cond_string)
c906108c
SS
4032{
4033 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4034}
c5aa993b 4035
c906108c 4036void
fba45db2 4037create_vfork_event_catchpoint (int tempflag, char *cond_string)
c906108c
SS
4038{
4039 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4040}
4041
4042void
fba45db2 4043create_exec_event_catchpoint (int tempflag, char *cond_string)
c906108c 4044{
c5aa993b
JM
4045 struct symtab_and_line sal;
4046 struct breakpoint *b;
4047 int thread = -1; /* All threads. */
c906108c 4048
c5aa993b 4049 INIT_SAL (&sal);
c906108c
SS
4050 sal.pc = 0;
4051 sal.symtab = NULL;
4052 sal.line = 0;
4053
4d28f7a8 4054 b = set_raw_breakpoint (sal, bp_catch_exec);
c906108c
SS
4055 set_breakpoint_count (breakpoint_count + 1);
4056 b->number = breakpoint_count;
4057 b->cond = NULL;
53a5351d
JM
4058 b->cond_string = (cond_string == NULL) ?
4059 NULL : savestring (cond_string, strlen (cond_string));
c906108c
SS
4060 b->thread = thread;
4061 b->addr_string = NULL;
b5de0fa7
EZ
4062 b->enable_state = bp_enabled;
4063 b->disposition = tempflag ? disp_del : disp_donttouch;
c906108c 4064
c906108c
SS
4065 mention (b);
4066}
4067
4068static int
fba45db2 4069hw_breakpoint_used_count (void)
c906108c
SS
4070{
4071 register struct breakpoint *b;
4072 int i = 0;
4073
4074 ALL_BREAKPOINTS (b)
c5aa993b 4075 {
b5de0fa7 4076 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
c5aa993b
JM
4077 i++;
4078 }
c906108c
SS
4079
4080 return i;
4081}
4082
4083static int
fba45db2 4084hw_watchpoint_used_count (enum bptype type, int *other_type_used)
c906108c
SS
4085{
4086 register struct breakpoint *b;
4087 int i = 0;
4088
4089 *other_type_used = 0;
4090 ALL_BREAKPOINTS (b)
c5aa993b 4091 {
b5de0fa7 4092 if (b->enable_state == bp_enabled)
c5aa993b
JM
4093 {
4094 if (b->type == type)
4095 i++;
4096 else if ((b->type == bp_hardware_watchpoint ||
4097 b->type == bp_read_watchpoint ||
4098 b->type == bp_access_watchpoint)
b5de0fa7 4099 && b->enable_state == bp_enabled)
c5aa993b
JM
4100 *other_type_used = 1;
4101 }
4102 }
c906108c
SS
4103 return i;
4104}
4105
53a5351d
JM
4106/* Call this after hitting the longjmp() breakpoint. Use this to set
4107 a new breakpoint at the target of the jmp_buf.
c906108c 4108
53a5351d
JM
4109 FIXME - This ought to be done by setting a temporary breakpoint
4110 that gets deleted automatically... */
c906108c
SS
4111
4112void
fba45db2 4113set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_info *frame)
c906108c
SS
4114{
4115 register struct breakpoint *b;
4116
4117 ALL_BREAKPOINTS (b)
4118 if (b->type == bp_longjmp_resume)
c5aa993b
JM
4119 {
4120 b->address = pc;
b5de0fa7 4121 b->enable_state = bp_enabled;
c5aa993b
JM
4122 if (frame != NULL)
4123 b->frame = frame->frame;
4124 else
4125 b->frame = 0;
9f60f21b 4126 check_duplicates (b);
c5aa993b
JM
4127 return;
4128 }
c906108c
SS
4129}
4130
4131void
fba45db2 4132disable_watchpoints_before_interactive_call_start (void)
c906108c 4133{
c5aa993b 4134 struct breakpoint *b;
c906108c
SS
4135
4136 ALL_BREAKPOINTS (b)
c5aa993b
JM
4137 {
4138 if (((b->type == bp_watchpoint)
4139 || (b->type == bp_hardware_watchpoint)
4140 || (b->type == bp_read_watchpoint)
4141 || (b->type == bp_access_watchpoint)
4142 || ep_is_exception_catchpoint (b))
b5de0fa7 4143 && (b->enable_state == bp_enabled))
c5aa993b 4144 {
b5de0fa7 4145 b->enable_state = bp_call_disabled;
9f60f21b 4146 check_duplicates (b);
c5aa993b
JM
4147 }
4148 }
c906108c
SS
4149}
4150
4151void
fba45db2 4152enable_watchpoints_after_interactive_call_stop (void)
c906108c 4153{
c5aa993b 4154 struct breakpoint *b;
c906108c
SS
4155
4156 ALL_BREAKPOINTS (b)
c5aa993b
JM
4157 {
4158 if (((b->type == bp_watchpoint)
4159 || (b->type == bp_hardware_watchpoint)
4160 || (b->type == bp_read_watchpoint)
4161 || (b->type == bp_access_watchpoint)
4162 || ep_is_exception_catchpoint (b))
b5de0fa7 4163 && (b->enable_state == bp_call_disabled))
c5aa993b 4164 {
b5de0fa7 4165 b->enable_state = bp_enabled;
9f60f21b 4166 check_duplicates (b);
c5aa993b
JM
4167 }
4168 }
c906108c
SS
4169}
4170
4171
4172/* Set a breakpoint that will evaporate an end of command
4173 at address specified by SAL.
4174 Restrict it to frame FRAME if FRAME is nonzero. */
4175
4176struct breakpoint *
fba45db2
KB
4177set_momentary_breakpoint (struct symtab_and_line sal, struct frame_info *frame,
4178 enum bptype type)
c906108c
SS
4179{
4180 register struct breakpoint *b;
4d28f7a8 4181 b = set_raw_breakpoint (sal, type);
b5de0fa7
EZ
4182 b->enable_state = bp_enabled;
4183 b->disposition = disp_donttouch;
c906108c
SS
4184 b->frame = (frame ? frame->frame : 0);
4185
4186 /* If we're debugging a multi-threaded program, then we
4187 want momentary breakpoints to be active in only a
4188 single thread of control. */
39f77062
KB
4189 if (in_thread_list (inferior_ptid))
4190 b->thread = pid_to_thread_id (inferior_ptid);
c906108c
SS
4191
4192 return b;
4193}
c906108c 4194\f
c5aa993b 4195
c906108c
SS
4196/* Tell the user we have just set a breakpoint B. */
4197
4198static void
fba45db2 4199mention (struct breakpoint *b)
c906108c
SS
4200{
4201 int say_where = 0;
8b93c638
JM
4202 struct cleanup *old_chain;
4203 struct ui_stream *stb;
4204
4205 stb = ui_out_stream_new (uiout);
b02eeafb 4206 old_chain = make_cleanup_ui_out_stream_delete (stb);
c906108c
SS
4207
4208 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4209 watchpoint) other than breakpoint creation. It should be possible to
4210 clean this up and at the same time replace the random calls to
4211 breakpoint_changed with this hook, as has already been done for
4212 delete_breakpoint_hook and so on. */
4213 if (create_breakpoint_hook)
4214 create_breakpoint_hook (b);
104c1213 4215 breakpoint_create_event (b->number);
c906108c
SS
4216
4217 switch (b->type)
4218 {
4219 case bp_none:
4220 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4221 break;
8b93c638
JM
4222 case bp_watchpoint:
4223 ui_out_text (uiout, "Watchpoint ");
666547aa 4224 ui_out_tuple_begin (uiout, "wpt");
8b93c638
JM
4225 ui_out_field_int (uiout, "number", b->number);
4226 ui_out_text (uiout, ": ");
4227 print_expression (b->exp, stb->stream);
4228 ui_out_field_stream (uiout, "exp", stb);
666547aa 4229 ui_out_tuple_end (uiout);
8b93c638
JM
4230 break;
4231 case bp_hardware_watchpoint:
4232 ui_out_text (uiout, "Hardware watchpoint ");
666547aa 4233 ui_out_tuple_begin (uiout, "wpt");
8b93c638
JM
4234 ui_out_field_int (uiout, "number", b->number);
4235 ui_out_text (uiout, ": ");
4236 print_expression (b->exp, stb->stream);
4237 ui_out_field_stream (uiout, "exp", stb);
666547aa 4238 ui_out_tuple_end (uiout);
8b93c638 4239 break;
8b93c638
JM
4240 case bp_read_watchpoint:
4241 ui_out_text (uiout, "Hardware read watchpoint ");
666547aa 4242 ui_out_tuple_begin (uiout, "hw-rwpt");
8b93c638
JM
4243 ui_out_field_int (uiout, "number", b->number);
4244 ui_out_text (uiout, ": ");
4245 print_expression (b->exp, stb->stream);
4246 ui_out_field_stream (uiout, "exp", stb);
666547aa 4247 ui_out_tuple_end (uiout);
8b93c638
JM
4248 break;
4249 case bp_access_watchpoint:
4250 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
666547aa 4251 ui_out_tuple_begin (uiout, "hw-awpt");
8b93c638
JM
4252 ui_out_field_int (uiout, "number", b->number);
4253 ui_out_text (uiout, ": ");
4254 print_expression (b->exp, stb->stream);
4255 ui_out_field_stream (uiout, "exp", stb);
666547aa 4256 ui_out_tuple_end (uiout);
8b93c638 4257 break;
c906108c 4258 case bp_breakpoint:
9dc5e2a9 4259 if (ui_out_is_mi_like_p (uiout))
fb40c209
AC
4260 {
4261 say_where = 0;
4262 break;
4263 }
c906108c
SS
4264 printf_filtered ("Breakpoint %d", b->number);
4265 say_where = 1;
4266 break;
4267 case bp_hardware_breakpoint:
9dc5e2a9 4268 if (ui_out_is_mi_like_p (uiout))
fb40c209
AC
4269 {
4270 say_where = 0;
4271 break;
4272 }
c906108c
SS
4273 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4274 say_where = 1;
4275 break;
4276 case bp_catch_load:
4277 case bp_catch_unload:
4278 printf_filtered ("Catchpoint %d (%s %s)",
c5aa993b
JM
4279 b->number,
4280 (b->type == bp_catch_load) ? "load" : "unload",
53a5351d
JM
4281 (b->dll_pathname != NULL) ?
4282 b->dll_pathname : "<any library>");
c906108c
SS
4283 break;
4284 case bp_catch_fork:
4285 case bp_catch_vfork:
4286 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
4287 b->number,
4288 (b->type == bp_catch_fork) ? "fork" : "vfork");
c906108c
SS
4289 break;
4290 case bp_catch_exec:
4291 printf_filtered ("Catchpoint %d (exec)",
c5aa993b 4292 b->number);
c906108c
SS
4293 break;
4294 case bp_catch_catch:
4295 case bp_catch_throw:
4296 printf_filtered ("Catchpoint %d (%s)",
c5aa993b
JM
4297 b->number,
4298 (b->type == bp_catch_catch) ? "catch" : "throw");
c906108c
SS
4299 break;
4300
4301 case bp_until:
4302 case bp_finish:
4303 case bp_longjmp:
4304 case bp_longjmp_resume:
4305 case bp_step_resume:
4306 case bp_through_sigtramp:
4307 case bp_call_dummy:
4308 case bp_watchpoint_scope:
4309 case bp_shlib_event:
c4093a6a 4310 case bp_thread_event:
c906108c
SS
4311 break;
4312 }
4313 if (say_where)
4314 {
4315 if (addressprint || b->source_file == NULL)
4316 {
4317 printf_filtered (" at ");
4318 print_address_numeric (b->address, 1, gdb_stdout);
4319 }
4320 if (b->source_file)
4321 printf_filtered (": file %s, line %d.",
4322 b->source_file, b->line_number);
c906108c 4323 }
8b93c638 4324 do_cleanups (old_chain);
9dc5e2a9 4325 if (ui_out_is_mi_like_p (uiout))
fb40c209 4326 return;
c906108c
SS
4327 printf_filtered ("\n");
4328}
c906108c 4329\f
c5aa993b 4330
c3f6f71d
JM
4331/* Add SALS.nelts breakpoints to the breakpoint table. For each
4332 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4333 COND[i] and COND_STRING[i] values.
4334
4335 NOTE: If the function succeeds, the caller is expected to cleanup
4336 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4337 array contents). If the function fails (error() is called), the
4338 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4339 COND and SALS arrays and each of those arrays contents. */
c906108c
SS
4340
4341static void
c3f6f71d
JM
4342create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4343 struct expression **cond, char **cond_string,
4344 enum bptype type, enum bpdisp disposition,
4345 int thread, int ignore_count, int from_tty)
c906108c 4346{
c3f6f71d
JM
4347 if (type == bp_hardware_breakpoint)
4348 {
4349 int i = hw_breakpoint_used_count ();
4350 int target_resources_ok =
4351 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4352 i + sals.nelts, 0);
4353 if (target_resources_ok == 0)
4354 error ("No hardware breakpoint support in the target.");
4355 else if (target_resources_ok < 0)
4356 error ("Hardware breakpoints used exceeds limit.");
4357 }
c906108c 4358
c3f6f71d
JM
4359 /* Now set all the breakpoints. */
4360 {
4361 int i;
4362 for (i = 0; i < sals.nelts; i++)
4363 {
4364 struct breakpoint *b;
4365 struct symtab_and_line sal = sals.sals[i];
c906108c 4366
c3f6f71d
JM
4367 if (from_tty)
4368 describe_other_breakpoints (sal.pc, sal.section);
4369
4d28f7a8 4370 b = set_raw_breakpoint (sal, type);
c3f6f71d
JM
4371 set_breakpoint_count (breakpoint_count + 1);
4372 b->number = breakpoint_count;
c3f6f71d
JM
4373 b->cond = cond[i];
4374 b->thread = thread;
4375 b->addr_string = addr_string[i];
4376 b->cond_string = cond_string[i];
4377 b->ignore_count = ignore_count;
b5de0fa7 4378 b->enable_state = bp_enabled;
c3f6f71d
JM
4379 b->disposition = disposition;
4380 mention (b);
4381 }
4382 }
4383}
c906108c 4384
c3f6f71d
JM
4385/* Parse ARG which is assumed to be a SAL specification possibly
4386 followed by conditionals. On return, SALS contains an array of SAL
4387 addresses found. ADDR_STRING contains a vector of (canonical)
4388 address strings. ARG points to the end of the SAL. */
c906108c 4389
c3f6f71d
JM
4390void
4391parse_breakpoint_sals (char **address,
4392 struct symtabs_and_lines *sals,
4393 char ***addr_string)
4394{
4395 char *addr_start = *address;
4396 *addr_string = NULL;
4397 /* If no arg given, or if first arg is 'if ', use the default
4398 breakpoint. */
4399 if ((*address) == NULL
4400 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
c906108c
SS
4401 {
4402 if (default_breakpoint_valid)
4403 {
c3f6f71d
JM
4404 struct symtab_and_line sal;
4405 INIT_SAL (&sal); /* initialize to zeroes */
4406 sals->sals = (struct symtab_and_line *)
c906108c
SS
4407 xmalloc (sizeof (struct symtab_and_line));
4408 sal.pc = default_breakpoint_address;
4409 sal.line = default_breakpoint_line;
4410 sal.symtab = default_breakpoint_symtab;
c5aa993b 4411 sal.section = find_pc_overlay (sal.pc);
c3f6f71d
JM
4412 sals->sals[0] = sal;
4413 sals->nelts = 1;
c906108c
SS
4414 }
4415 else
4416 error ("No default breakpoint address now.");
4417 }
4418 else
4419 {
c906108c 4420 /* Force almost all breakpoints to be in terms of the
c5aa993b
JM
4421 current_source_symtab (which is decode_line_1's default). This
4422 should produce the results we want almost all of the time while
4423 leaving default_breakpoint_* alone. */
c906108c
SS
4424 if (default_breakpoint_valid
4425 && (!current_source_symtab
c3f6f71d
JM
4426 || (strchr ("+-", (*address)[0]) != NULL)))
4427 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4428 default_breakpoint_line, addr_string);
c906108c 4429 else
c3f6f71d 4430 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
c906108c 4431 }
c3f6f71d
JM
4432 /* For any SAL that didn't have a canonical string, fill one in. */
4433 if (sals->nelts > 0 && *addr_string == NULL)
4434 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4435 if (addr_start != (*address))
c906108c 4436 {
c3f6f71d
JM
4437 int i;
4438 for (i = 0; i < sals->nelts; i++)
c906108c 4439 {
c3f6f71d
JM
4440 /* Add the string if not present. */
4441 if ((*addr_string)[i] == NULL)
4442 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
c906108c
SS
4443 }
4444 }
c3f6f71d 4445}
c906108c 4446
c906108c 4447
c3f6f71d
JM
4448/* Convert each SAL into a real PC. Verify that the PC can be
4449 inserted as a breakpoint. If it can't throw an error. */
c906108c 4450
c3f6f71d
JM
4451void
4452breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4453 char *address)
4454{
4455 int i;
4456 for (i = 0; i < sals->nelts; i++)
4457 {
4458 resolve_sal_pc (&sals->sals[i]);
c906108c
SS
4459
4460 /* It's possible for the PC to be nonzero, but still an illegal
4461 value on some targets.
4462
4463 For example, on HP-UX if you start gdb, and before running the
4464 inferior you try to set a breakpoint on a shared library function
4465 "foo" where the inferior doesn't call "foo" directly but does
4466 pass its address to another function call, then we do find a
4467 minimal symbol for the "foo", but it's address is invalid.
4468 (Appears to be an index into a table that the loader sets up
4469 when the inferior is run.)
4470
4471 Give the target a chance to bless sals.sals[i].pc before we
4472 try to make a breakpoint for it. */
c3f6f71d 4473 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
c5aa993b 4474 {
c3f6f71d
JM
4475 if (address == NULL)
4476 error ("Cannot break without a running program.");
4477 else
4478 error ("Cannot break on %s without a running program.",
4479 address);
c5aa993b 4480 }
c3f6f71d
JM
4481 }
4482}
4483
4484/* Set a breakpoint according to ARG (function, linenum or *address)
4485 flag: first bit : 0 non-temporary, 1 temporary.
4486 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
c5aa993b 4487
c3f6f71d 4488static void
fba45db2 4489break_command_1 (char *arg, int flag, int from_tty)
c3f6f71d
JM
4490{
4491 int tempflag, hardwareflag;
4492 struct symtabs_and_lines sals;
4493 register struct expression **cond = 0;
4494 /* Pointers in arg to the start, and one past the end, of the
4495 condition. */
4496 char **cond_string = (char **) NULL;
4497 char *addr_start = arg;
4498 char **addr_string;
4499 struct cleanup *old_chain;
4500 struct cleanup *breakpoint_chain = NULL;
4501 int i;
4502 int thread = -1;
4503 int ignore_count = 0;
4504
4505 hardwareflag = flag & BP_HARDWAREFLAG;
4506 tempflag = flag & BP_TEMPFLAG;
c906108c 4507
c3f6f71d
JM
4508 sals.sals = NULL;
4509 sals.nelts = 0;
4510 addr_string = NULL;
4511 parse_breakpoint_sals (&arg, &sals, &addr_string);
4512
4513 if (!sals.nelts)
4514 return;
4515
4516 /* Create a chain of things that always need to be cleaned up. */
4517 old_chain = make_cleanup (null_cleanup, 0);
4518
4519 /* Make sure that all storage allocated to SALS gets freed. */
b8c9b27d 4520 make_cleanup (xfree, sals.sals);
c3f6f71d
JM
4521
4522 /* Cleanup the addr_string array but not its contents. */
b8c9b27d 4523 make_cleanup (xfree, addr_string);
c3f6f71d
JM
4524
4525 /* Allocate space for all the cond expressions. */
4526 cond = xcalloc (sals.nelts, sizeof (struct expression *));
b8c9b27d 4527 make_cleanup (xfree, cond);
c3f6f71d
JM
4528
4529 /* Allocate space for all the cond strings. */
4530 cond_string = xcalloc (sals.nelts, sizeof (char **));
b8c9b27d 4531 make_cleanup (xfree, cond_string);
c3f6f71d
JM
4532
4533 /* ----------------------------- SNIP -----------------------------
4534 Anything added to the cleanup chain beyond this point is assumed
4535 to be part of a breakpoint. If the breakpoint create succeeds
4536 then the memory is not reclaimed. */
4537 breakpoint_chain = make_cleanup (null_cleanup, 0);
4538
4539 /* Mark the contents of the addr_string for cleanup. These go on
4540 the breakpoint_chain and only occure if the breakpoint create
4541 fails. */
4542 for (i = 0; i < sals.nelts; i++)
4543 {
4544 if (addr_string[i] != NULL)
b8c9b27d 4545 make_cleanup (xfree, addr_string[i]);
c3f6f71d
JM
4546 }
4547
4548 /* Resolve all line numbers to PC's and verify that the addresses
4549 are ok for the target. */
4550 breakpoint_sals_to_pc (&sals, addr_start);
4551
4552 /* Verify that condition can be parsed, before setting any
4553 breakpoints. Allocate a separate condition expression for each
4554 breakpoint. */
4555 thread = -1; /* No specific thread yet */
4556 for (i = 0; i < sals.nelts; i++)
4557 {
4558 char *tok = arg;
c906108c
SS
4559 while (tok && *tok)
4560 {
c3f6f71d
JM
4561 char *end_tok;
4562 int toklen;
4563 char *cond_start = NULL;
4564 char *cond_end = NULL;
c906108c
SS
4565 while (*tok == ' ' || *tok == '\t')
4566 tok++;
4567
4568 end_tok = tok;
4569
4570 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4571 end_tok++;
4572
4573 toklen = end_tok - tok;
4574
4575 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4576 {
4577 tok = cond_start = end_tok + 1;
c3f6f71d 4578 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
b8c9b27d 4579 make_cleanup (xfree, cond[i]);
c906108c 4580 cond_end = tok;
c3f6f71d 4581 cond_string[i] = savestring (cond_start, cond_end - cond_start);
b8c9b27d 4582 make_cleanup (xfree, cond_string[i]);
c906108c
SS
4583 }
4584 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4585 {
4586 char *tmptok;
4587
4588 tok = end_tok + 1;
4589 tmptok = tok;
4590 thread = strtol (tok, &tok, 0);
4591 if (tok == tmptok)
4592 error ("Junk after thread keyword.");
4593 if (!valid_thread_id (thread))
4594 error ("Unknown thread %d\n", thread);
4595 }
4596 else
4597 error ("Junk at end of arguments.");
4598 }
4599 }
c906108c 4600
c3f6f71d
JM
4601 create_breakpoints (sals, addr_string, cond, cond_string,
4602 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
b5de0fa7 4603 tempflag ? disp_del : disp_donttouch,
c3f6f71d
JM
4604 thread, ignore_count, from_tty);
4605
4606 if (sals.nelts > 1)
4607 {
4608 warning ("Multiple breakpoints were set.");
4609 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 4610 }
c3f6f71d
JM
4611 /* That's it. Discard the cleanups for data inserted into the
4612 breakpoint. */
4613 discard_cleanups (breakpoint_chain);
4614 /* But cleanup everything else. */
4615 do_cleanups (old_chain);
4616}
c906108c 4617
c3f6f71d
JM
4618/* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4619 linenum or *address) with COND and IGNORE_COUNT. */
c906108c 4620
c3f6f71d
JM
4621struct captured_breakpoint_args
4622 {
4623 char *address;
4624 char *condition;
4625 int hardwareflag;
4626 int tempflag;
4627 int thread;
4628 int ignore_count;
4629 };
4630
4631static int
4632do_captured_breakpoint (void *data)
4633{
4634 struct captured_breakpoint_args *args = data;
4635 struct symtabs_and_lines sals;
4636 register struct expression **cond;
4637 struct cleanup *old_chain;
4638 struct cleanup *breakpoint_chain = NULL;
4639 int i;
4640 char **addr_string;
4641 char **cond_string;
4642
4643 char *address_end;
4644
4645 /* Parse the source and lines spec. Delay check that the expression
4646 didn't contain trailing garbage until after cleanups are in
4647 place. */
4648 sals.sals = NULL;
4649 sals.nelts = 0;
4650 address_end = args->address;
4651 addr_string = NULL;
4652 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4653
4654 if (!sals.nelts)
4655 return GDB_RC_NONE;
4656
4657 /* Create a chain of things at always need to be cleaned up. */
4658 old_chain = make_cleanup (null_cleanup, 0);
4659
4660 /* Always have a addr_string array, even if it is empty. */
b8c9b27d 4661 make_cleanup (xfree, addr_string);
c3f6f71d
JM
4662
4663 /* Make sure that all storage allocated to SALS gets freed. */
b8c9b27d 4664 make_cleanup (xfree, sals.sals);
c3f6f71d
JM
4665
4666 /* Allocate space for all the cond expressions. */
4667 cond = xcalloc (sals.nelts, sizeof (struct expression *));
b8c9b27d 4668 make_cleanup (xfree, cond);
c3f6f71d
JM
4669
4670 /* Allocate space for all the cond strings. */
4671 cond_string = xcalloc (sals.nelts, sizeof (char **));
b8c9b27d 4672 make_cleanup (xfree, cond_string);
c3f6f71d
JM
4673
4674 /* ----------------------------- SNIP -----------------------------
4675 Anything added to the cleanup chain beyond this point is assumed
4676 to be part of a breakpoint. If the breakpoint create goes
4677 through then that memory is not cleaned up. */
4678 breakpoint_chain = make_cleanup (null_cleanup, 0);
4679
4680 /* Mark the contents of the addr_string for cleanup. These go on
4681 the breakpoint_chain and only occure if the breakpoint create
4682 fails. */
c906108c
SS
4683 for (i = 0; i < sals.nelts; i++)
4684 {
c3f6f71d 4685 if (addr_string[i] != NULL)
b8c9b27d 4686 make_cleanup (xfree, addr_string[i]);
c906108c
SS
4687 }
4688
c3f6f71d
JM
4689 /* Wait until now before checking for garbage at the end of the
4690 address. That way cleanups can take care of freeing any
4691 memory. */
4692 if (*address_end != '\0')
4693 error ("Garbage %s following breakpoint address", address_end);
4694
4695 /* Resolve all line numbers to PC's. */
4696 breakpoint_sals_to_pc (&sals, args->address);
4697
4698 /* Verify that conditions can be parsed, before setting any
4699 breakpoints. */
4700 for (i = 0; i < sals.nelts; i++)
c906108c 4701 {
c3f6f71d
JM
4702 if (args->condition != NULL)
4703 {
4704 char *tok = args->condition;
4705 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4706 if (*tok != '\0')
4707 error ("Garbage %s follows condition", tok);
b8c9b27d 4708 make_cleanup (xfree, cond[i]);
c3f6f71d
JM
4709 cond_string[i] = xstrdup (args->condition);
4710 }
c906108c 4711 }
c3f6f71d
JM
4712
4713 create_breakpoints (sals, addr_string, cond, cond_string,
4714 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
b5de0fa7 4715 args->tempflag ? disp_del : disp_donttouch,
c3f6f71d
JM
4716 args->thread, args->ignore_count, 0/*from-tty*/);
4717
4718 /* That's it. Discard the cleanups for data inserted into the
4719 breakpoint. */
4720 discard_cleanups (breakpoint_chain);
4721 /* But cleanup everything else. */
c906108c 4722 do_cleanups (old_chain);
c3f6f71d 4723 return GDB_RC_OK;
c906108c
SS
4724}
4725
c3f6f71d
JM
4726enum gdb_rc
4727gdb_breakpoint (char *address, char *condition,
4728 int hardwareflag, int tempflag,
4729 int thread, int ignore_count)
4730{
4731 struct captured_breakpoint_args args;
4732 args.address = address;
4733 args.condition = condition;
4734 args.hardwareflag = hardwareflag;
4735 args.tempflag = tempflag;
4736 args.thread = thread;
4737 args.ignore_count = ignore_count;
4738 return catch_errors (do_captured_breakpoint, &args,
4739 NULL, RETURN_MASK_ALL);
4740}
4741
4742
c906108c 4743static void
fba45db2 4744break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
c906108c
SS
4745{
4746 struct frame_info *frame;
4747 CORE_ADDR low, high, selected_pc = 0;
7f7e9482
AC
4748 char *extra_args = NULL;
4749 char *level_arg;
4750 char *addr_string;
c906108c
SS
4751 int extra_args_len = 0, if_arg = 0;
4752
4753 if (!arg ||
4754 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4755 {
4756
4757 if (default_breakpoint_valid)
4758 {
4759 if (selected_frame)
4760 {
4761 selected_pc = selected_frame->pc;
4762 if (arg)
4763 if_arg = 1;
4764 }
4765 else
4766 error ("No selected frame.");
4767 }
4768 else
4769 error ("No default breakpoint address now.");
4770 }
4771 else
4772 {
4773 extra_args = strchr (arg, ' ');
4774 if (extra_args)
4775 {
4776 extra_args++;
4777 extra_args_len = strlen (extra_args);
4778 level_arg = (char *) xmalloc (extra_args - arg);
4779 strncpy (level_arg, arg, extra_args - arg - 1);
4780 level_arg[extra_args - arg - 1] = '\0';
4781 }
4782 else
4783 {
4784 level_arg = (char *) xmalloc (strlen (arg) + 1);
4785 strcpy (level_arg, arg);
4786 }
4787
4788 frame = parse_frame_specification (level_arg);
4789 if (frame)
4790 selected_pc = frame->pc;
4791 else
4792 selected_pc = 0;
4793 }
4794 if (if_arg)
4795 {
4796 extra_args = arg;
c5aa993b 4797 extra_args_len = strlen (arg);
c906108c
SS
4798 }
4799
4800 if (selected_pc)
4801 {
c5aa993b 4802 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
c906108c
SS
4803 {
4804 addr_string = (char *) xmalloc (26 + extra_args_len);
4805 if (extra_args_len)
d4f3574e 4806 sprintf (addr_string, "*0x%s %s", paddr_nz (high), extra_args);
c906108c 4807 else
d4f3574e 4808 sprintf (addr_string, "*0x%s", paddr_nz (high));
c906108c 4809 break_command_1 (addr_string, flag, from_tty);
b8c9b27d 4810 xfree (addr_string);
c906108c
SS
4811 }
4812 else
4813 error ("No function contains the specified address");
4814 }
4815 else
4816 error ("Unable to set breakpoint at procedure exit");
4817}
4818
4819
4820static void
fba45db2 4821break_at_finish_command_1 (char *arg, int flag, int from_tty)
c906108c
SS
4822{
4823 char *addr_string, *break_string, *beg_addr_string;
4824 CORE_ADDR low, high;
4825 struct symtabs_and_lines sals;
4826 struct symtab_and_line sal;
4827 struct cleanup *old_chain;
7f7e9482 4828 char *extra_args = NULL;
c906108c
SS
4829 int extra_args_len = 0;
4830 int i, if_arg = 0;
4831
4832 if (!arg ||
4833 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
4834 {
4835 if (default_breakpoint_valid)
4836 {
4837 if (selected_frame)
4838 {
4839 addr_string = (char *) xmalloc (15);
d4f3574e 4840 sprintf (addr_string, "*0x%s", paddr_nz (selected_frame->pc));
c906108c
SS
4841 if (arg)
4842 if_arg = 1;
4843 }
4844 else
4845 error ("No selected frame.");
4846 }
4847 else
4848 error ("No default breakpoint address now.");
4849 }
4850 else
4851 {
4852 addr_string = (char *) xmalloc (strlen (arg) + 1);
4853 strcpy (addr_string, arg);
4854 }
4855
4856 if (if_arg)
4857 {
4858 extra_args = arg;
c5aa993b
JM
4859 extra_args_len = strlen (arg);
4860 }
4861 else if (arg)
4862 {
4863 /* get the stuff after the function name or address */
4864 extra_args = strchr (arg, ' ');
4865 if (extra_args)
4866 {
4867 extra_args++;
4868 extra_args_len = strlen (extra_args);
4869 }
c906108c 4870 }
c906108c
SS
4871
4872 sals.sals = NULL;
4873 sals.nelts = 0;
4874
c5aa993b
JM
4875 beg_addr_string = addr_string;
4876 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
4877 (char ***) NULL);
c906108c 4878
b8c9b27d
KB
4879 xfree (beg_addr_string);
4880 old_chain = make_cleanup (xfree, sals.sals);
c906108c
SS
4881 for (i = 0; (i < sals.nelts); i++)
4882 {
4883 sal = sals.sals[i];
c5aa993b 4884 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
c906108c
SS
4885 {
4886 break_string = (char *) xmalloc (extra_args_len + 26);
4887 if (extra_args_len)
d4f3574e 4888 sprintf (break_string, "*0x%s %s", paddr_nz (high), extra_args);
c906108c 4889 else
d4f3574e 4890 sprintf (break_string, "*0x%s", paddr_nz (high));
c906108c 4891 break_command_1 (break_string, flag, from_tty);
b8c9b27d 4892 xfree (break_string);
c906108c
SS
4893 }
4894 else
4895 error ("No function contains the specified address");
4896 }
4897 if (sals.nelts > 1)
4898 {
53a5351d
JM
4899 warning ("Multiple breakpoints were set.\n");
4900 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 4901 }
c5aa993b 4902 do_cleanups (old_chain);
c906108c
SS
4903}
4904
4905
4906/* Helper function for break_command_1 and disassemble_command. */
4907
4908void
fba45db2 4909resolve_sal_pc (struct symtab_and_line *sal)
c906108c
SS
4910{
4911 CORE_ADDR pc;
4912
4913 if (sal->pc == 0 && sal->symtab != NULL)
4914 {
4915 if (!find_line_pc (sal->symtab, sal->line, &pc))
4916 error ("No line %d in file \"%s\".",
4917 sal->line, sal->symtab->filename);
4918 sal->pc = pc;
4919 }
4920
4921 if (sal->section == 0 && sal->symtab != NULL)
4922 {
4923 struct blockvector *bv;
c5aa993b
JM
4924 struct block *b;
4925 struct symbol *sym;
4926 int index;
c906108c 4927
c5aa993b 4928 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
c906108c
SS
4929 if (bv != NULL)
4930 {
c5aa993b 4931 b = BLOCKVECTOR_BLOCK (bv, index);
c906108c
SS
4932 sym = block_function (b);
4933 if (sym != NULL)
4934 {
4935 fixup_symbol_section (sym, sal->symtab->objfile);
4936 sal->section = SYMBOL_BFD_SECTION (sym);
4937 }
4938 else
4939 {
4940 /* It really is worthwhile to have the section, so we'll just
c5aa993b
JM
4941 have to look harder. This case can be executed if we have
4942 line numbers but no functions (as can happen in assembly
4943 source). */
c906108c 4944
c5aa993b 4945 struct minimal_symbol *msym;
c906108c
SS
4946
4947 msym = lookup_minimal_symbol_by_pc (sal->pc);
4948 if (msym)
4949 sal->section = SYMBOL_BFD_SECTION (msym);
4950 }
4951 }
4952 }
4953}
4954
4955void
fba45db2 4956break_command (char *arg, int from_tty)
c906108c
SS
4957{
4958 break_command_1 (arg, 0, from_tty);
4959}
4960
7a292a7a 4961static void
fba45db2 4962break_at_finish_command (char *arg, int from_tty)
c906108c
SS
4963{
4964 break_at_finish_command_1 (arg, 0, from_tty);
4965}
4966
7a292a7a 4967static void
fba45db2 4968break_at_finish_at_depth_command (char *arg, int from_tty)
c906108c
SS
4969{
4970 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
4971}
4972
4973void
fba45db2 4974tbreak_command (char *arg, int from_tty)
c906108c
SS
4975{
4976 break_command_1 (arg, BP_TEMPFLAG, from_tty);
4977}
4978
7a292a7a 4979static void
fba45db2 4980tbreak_at_finish_command (char *arg, int from_tty)
c906108c
SS
4981{
4982 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
4983}
4984
4985static void
fba45db2 4986hbreak_command (char *arg, int from_tty)
c906108c
SS
4987{
4988 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
4989}
4990
4991static void
fba45db2 4992thbreak_command (char *arg, int from_tty)
c906108c
SS
4993{
4994 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
4995}
4996
4997static void
fba45db2 4998stop_command (char *arg, int from_tty)
c906108c
SS
4999{
5000 printf_filtered ("Specify the type of breakpoint to set.\n\
5001Usage: stop in <function | address>\n\
5002 stop at <line>\n");
5003}
5004
5005static void
fba45db2 5006stopin_command (char *arg, int from_tty)
c906108c
SS
5007{
5008 int badInput = 0;
5009
c5aa993b 5010 if (arg == (char *) NULL)
c906108c
SS
5011 badInput = 1;
5012 else if (*arg != '*')
5013 {
5014 char *argptr = arg;
5015 int hasColon = 0;
5016
53a5351d
JM
5017 /* look for a ':'. If this is a line number specification, then
5018 say it is bad, otherwise, it should be an address or
5019 function/method name */
c906108c 5020 while (*argptr && !hasColon)
c5aa993b
JM
5021 {
5022 hasColon = (*argptr == ':');
5023 argptr++;
5024 }
c906108c
SS
5025
5026 if (hasColon)
c5aa993b 5027 badInput = (*argptr != ':'); /* Not a class::method */
c906108c 5028 else
c5aa993b 5029 badInput = isdigit (*arg); /* a simple line number */
c906108c
SS
5030 }
5031
5032 if (badInput)
c5aa993b 5033 printf_filtered ("Usage: stop in <function | address>\n");
c906108c
SS
5034 else
5035 break_command_1 (arg, 0, from_tty);
5036}
5037
5038static void
fba45db2 5039stopat_command (char *arg, int from_tty)
c906108c
SS
5040{
5041 int badInput = 0;
5042
c5aa993b 5043 if (arg == (char *) NULL || *arg == '*') /* no line number */
c906108c
SS
5044 badInput = 1;
5045 else
5046 {
5047 char *argptr = arg;
5048 int hasColon = 0;
5049
5050 /* look for a ':'. If there is a '::' then get out, otherwise
c5aa993b 5051 it is probably a line number. */
c906108c 5052 while (*argptr && !hasColon)
c5aa993b
JM
5053 {
5054 hasColon = (*argptr == ':');
5055 argptr++;
5056 }
c906108c
SS
5057
5058 if (hasColon)
c5aa993b 5059 badInput = (*argptr == ':'); /* we have class::method */
c906108c 5060 else
c5aa993b 5061 badInput = !isdigit (*arg); /* not a line number */
c906108c
SS
5062 }
5063
5064 if (badInput)
c5aa993b 5065 printf_filtered ("Usage: stop at <line>\n");
c906108c
SS
5066 else
5067 break_command_1 (arg, 0, from_tty);
5068}
5069
5070/* ARGSUSED */
53a5351d
JM
5071/* accessflag: hw_write: watch write,
5072 hw_read: watch read,
5073 hw_access: watch access (read or write) */
c906108c 5074static void
fba45db2 5075watch_command_1 (char *arg, int accessflag, int from_tty)
c906108c
SS
5076{
5077 struct breakpoint *b;
5078 struct symtab_and_line sal;
5079 struct expression *exp;
5080 struct block *exp_valid_block;
5081 struct value *val, *mark;
5082 struct frame_info *frame;
5083 struct frame_info *prev_frame = NULL;
5084 char *exp_start = NULL;
5085 char *exp_end = NULL;
5086 char *tok, *end_tok;
5087 int toklen;
5088 char *cond_start = NULL;
5089 char *cond_end = NULL;
5090 struct expression *cond = NULL;
5091 int i, other_type_used, target_resources_ok = 0;
5092 enum bptype bp_type;
5093 int mem_cnt = 0;
5094
c5aa993b
JM
5095 INIT_SAL (&sal); /* initialize to zeroes */
5096
c906108c
SS
5097 /* Parse arguments. */
5098 innermost_block = NULL;
5099 exp_start = arg;
5100 exp = parse_exp_1 (&arg, 0, 0);
5101 exp_end = arg;
5102 exp_valid_block = innermost_block;
5103 mark = value_mark ();
5104 val = evaluate_expression (exp);
5105 release_value (val);
5106 if (VALUE_LAZY (val))
5107 value_fetch_lazy (val);
5108
5109 tok = arg;
5110 while (*tok == ' ' || *tok == '\t')
5111 tok++;
5112 end_tok = tok;
5113
5114 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5115 end_tok++;
5116
5117 toklen = end_tok - tok;
5118 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5119 {
5120 tok = cond_start = end_tok + 1;
5121 cond = parse_exp_1 (&tok, 0, 0);
5122 cond_end = tok;
5123 }
5124 if (*tok)
c5aa993b 5125 error ("Junk at end of command.");
c906108c 5126
53a5351d 5127 if (accessflag == hw_read)
c5aa993b 5128 bp_type = bp_read_watchpoint;
53a5351d 5129 else if (accessflag == hw_access)
c5aa993b
JM
5130 bp_type = bp_access_watchpoint;
5131 else
5132 bp_type = bp_hardware_watchpoint;
c906108c
SS
5133
5134 mem_cnt = can_use_hardware_watchpoint (val);
5135 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5136 error ("Expression cannot be implemented with read/access watchpoint.");
c5aa993b
JM
5137 if (mem_cnt != 0)
5138 {
5139 i = hw_watchpoint_used_count (bp_type, &other_type_used);
53a5351d
JM
5140 target_resources_ok =
5141 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5142 other_type_used);
c5aa993b 5143 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
53a5351d
JM
5144 error ("Target does not support this type of hardware watchpoint.");
5145
c5aa993b 5146 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
53a5351d 5147 error ("Target can only support one kind of HW watchpoint at a time.");
c5aa993b 5148 }
c906108c
SS
5149
5150#if defined(HPUXHPPA)
c5aa993b 5151 /* On HP-UX if you set a h/w
c906108c
SS
5152 watchpoint before the "run" command, the inferior dies with a e.g.,
5153 SIGILL once you start it. I initially believed this was due to a
5154 bad interaction between page protection traps and the initial
5155 startup sequence by the dynamic linker.
5156
5157 However, I tried avoiding that by having HP-UX's implementation of
39f77062 5158 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
c906108c
SS
5159 yet, which forced slow watches before a "run" or "attach", and it
5160 still fails somewhere in the startup code.
5161
5162 Until I figure out what's happening, I'm disallowing watches altogether
5163 before the "run" or "attach" command. We'll tell the user they must
5164 set watches after getting the program started. */
c5aa993b 5165 if (!target_has_execution)
c906108c
SS
5166 {
5167 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5168 return;
5169 }
5170#endif /* HPUXHPPA */
c5aa993b 5171
4d28f7a8
KB
5172 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5173 watchpoint could not be set. */
5174 if (!mem_cnt || target_resources_ok <= 0)
5175 bp_type = bp_watchpoint;
5176
c906108c 5177 /* Now set up the breakpoint. */
4d28f7a8 5178 b = set_raw_breakpoint (sal, bp_type);
c906108c
SS
5179 set_breakpoint_count (breakpoint_count + 1);
5180 b->number = breakpoint_count;
b5de0fa7 5181 b->disposition = disp_donttouch;
c906108c
SS
5182 b->exp = exp;
5183 b->exp_valid_block = exp_valid_block;
5184 b->exp_string = savestring (exp_start, exp_end - exp_start);
5185 b->val = val;
5186 b->cond = cond;
5187 if (cond_start)
5188 b->cond_string = savestring (cond_start, cond_end - cond_start);
5189 else
5190 b->cond_string = 0;
c5aa993b 5191
c906108c
SS
5192 frame = block_innermost_frame (exp_valid_block);
5193 if (frame)
5194 {
5195 prev_frame = get_prev_frame (frame);
5196 b->watchpoint_frame = frame->frame;
5197 }
5198 else
c5aa993b 5199 b->watchpoint_frame = (CORE_ADDR) 0;
c906108c 5200
c906108c
SS
5201 /* If the expression is "local", then set up a "watchpoint scope"
5202 breakpoint at the point where we've left the scope of the watchpoint
5203 expression. */
5204 if (innermost_block)
5205 {
5206 if (prev_frame)
5207 {
5208 struct breakpoint *scope_breakpoint;
5209 struct symtab_and_line scope_sal;
5210
5211 INIT_SAL (&scope_sal); /* initialize to zeroes */
c5aa993b 5212 scope_sal.pc = get_frame_pc (prev_frame);
c906108c
SS
5213 scope_sal.section = find_pc_overlay (scope_sal.pc);
5214
4d28f7a8
KB
5215 scope_breakpoint = set_raw_breakpoint (scope_sal,
5216 bp_watchpoint_scope);
c906108c
SS
5217 set_breakpoint_count (breakpoint_count + 1);
5218 scope_breakpoint->number = breakpoint_count;
5219
b5de0fa7 5220 scope_breakpoint->enable_state = bp_enabled;
c906108c
SS
5221
5222 /* Automatically delete the breakpoint when it hits. */
b5de0fa7 5223 scope_breakpoint->disposition = disp_del;
c906108c
SS
5224
5225 /* Only break in the proper frame (help with recursion). */
5226 scope_breakpoint->frame = prev_frame->frame;
5227
5228 /* Set the address at which we will stop. */
5229 scope_breakpoint->address = get_frame_pc (prev_frame);
5230
5231 /* The scope breakpoint is related to the watchpoint. We
5232 will need to act on them together. */
5233 b->related_breakpoint = scope_breakpoint;
5234 }
5235 }
5236 value_free_to_mark (mark);
5237 mention (b);
5238}
5239
5240/* Return count of locations need to be watched and can be handled
5241 in hardware. If the watchpoint can not be handled
5242 in hardware return zero. */
5243
5244#if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
53a5351d
JM
5245#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5246 ((BYTE_SIZE) <= (REGISTER_SIZE))
5247#endif
5248
5249#if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5250#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
6ab3a9c9 5251 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
c906108c
SS
5252#endif
5253
5254static int
fba45db2 5255can_use_hardware_watchpoint (struct value *v)
c906108c
SS
5256{
5257 int found_memory_cnt = 0;
2e70b7b9 5258 struct value *head = v;
c906108c
SS
5259
5260 /* Did the user specifically forbid us to use hardware watchpoints? */
c5aa993b 5261 if (!can_use_hw_watchpoints)
c906108c 5262 return 0;
c5aa993b 5263
5c44784c
JM
5264 /* Make sure that the value of the expression depends only upon
5265 memory contents, and values computed from them within GDB. If we
5266 find any register references or function calls, we can't use a
5267 hardware watchpoint.
5268
5269 The idea here is that evaluating an expression generates a series
5270 of values, one holding the value of every subexpression. (The
5271 expression a*b+c has five subexpressions: a, b, a*b, c, and
5272 a*b+c.) GDB's values hold almost enough information to establish
5273 the criteria given above --- they identify memory lvalues,
5274 register lvalues, computed values, etcetera. So we can evaluate
5275 the expression, and then scan the chain of values that leaves
5276 behind to decide whether we can detect any possible change to the
5277 expression's final value using only hardware watchpoints.
5278
5279 However, I don't think that the values returned by inferior
5280 function calls are special in any way. So this function may not
5281 notice that an expression involving an inferior function call
5282 can't be watched with hardware watchpoints. FIXME. */
c5aa993b 5283 for (; v; v = v->next)
c906108c 5284 {
5c44784c 5285 if (VALUE_LVAL (v) == lval_memory)
c906108c 5286 {
5c44784c
JM
5287 if (VALUE_LAZY (v))
5288 /* A lazy memory lvalue is one that GDB never needed to fetch;
5289 we either just used its address (e.g., `a' in `a.b') or
5290 we never needed it at all (e.g., `a' in `a,b'). */
5291 ;
53a5351d 5292 else
5c44784c
JM
5293 {
5294 /* Ahh, memory we actually used! Check if we can cover
5295 it with hardware watchpoints. */
2e70b7b9
MS
5296 struct type *vtype = check_typedef (VALUE_TYPE (v));
5297
5298 /* We only watch structs and arrays if user asked for it
5299 explicitly, never if they just happen to appear in a
5300 middle of some value chain. */
5301 if (v == head
5302 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5303 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5304 {
5305 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5306 int len = TYPE_LENGTH (VALUE_TYPE (v));
5307
5308 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5309 return 0;
5310 else
5311 found_memory_cnt++;
5312 }
5c44784c 5313 }
c5aa993b 5314 }
c906108c 5315 else if (v->lval != not_lval && v->modifiable == 0)
53a5351d
JM
5316 return 0; /* ??? What does this represent? */
5317 else if (v->lval == lval_register)
5318 return 0; /* cannot watch a register with a HW watchpoint */
c906108c
SS
5319 }
5320
5321 /* The expression itself looks suitable for using a hardware
5322 watchpoint, but give the target machine a chance to reject it. */
5323 return found_memory_cnt;
5324}
5325
8b93c638 5326void
fba45db2 5327watch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
5328{
5329 watch_command (arg, from_tty);
5330}
8926118c 5331
c5aa993b 5332static void
fba45db2 5333watch_command (char *arg, int from_tty)
c906108c 5334{
53a5351d 5335 watch_command_1 (arg, hw_write, from_tty);
c906108c
SS
5336}
5337
8b93c638 5338void
fba45db2 5339rwatch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
5340{
5341 rwatch_command (arg, from_tty);
5342}
8926118c 5343
c5aa993b 5344static void
fba45db2 5345rwatch_command (char *arg, int from_tty)
c906108c 5346{
53a5351d 5347 watch_command_1 (arg, hw_read, from_tty);
c906108c
SS
5348}
5349
8b93c638 5350void
fba45db2 5351awatch_command_wrapper (char *arg, int from_tty)
8b93c638
JM
5352{
5353 awatch_command (arg, from_tty);
5354}
8926118c 5355
c5aa993b 5356static void
fba45db2 5357awatch_command (char *arg, int from_tty)
c906108c 5358{
53a5351d 5359 watch_command_1 (arg, hw_access, from_tty);
c906108c 5360}
c906108c 5361\f
c5aa993b 5362
43ff13b4 5363/* Helper routines for the until_command routine in infcmd.c. Here
c906108c
SS
5364 because it uses the mechanisms of breakpoints. */
5365
43ff13b4
JM
5366/* This function is called by fetch_inferior_event via the
5367 cmd_continuation pointer, to complete the until command. It takes
5368 care of cleaning up the temporary breakpoints set up by the until
5369 command. */
c2c6d25f
JM
5370static void
5371until_break_command_continuation (struct continuation_arg *arg)
43ff13b4 5372{
0d06e24b
JM
5373 struct cleanup *cleanups;
5374
57e687d9 5375 cleanups = (struct cleanup *) arg->data.pointer;
0d06e24b 5376 do_exec_cleanups (cleanups);
43ff13b4
JM
5377}
5378
c906108c
SS
5379/* ARGSUSED */
5380void
fba45db2 5381until_break_command (char *arg, int from_tty)
c906108c
SS
5382{
5383 struct symtabs_and_lines sals;
5384 struct symtab_and_line sal;
5385 struct frame_info *prev_frame = get_prev_frame (selected_frame);
5386 struct breakpoint *breakpoint;
5387 struct cleanup *old_chain;
0d06e24b
JM
5388 struct continuation_arg *arg1;
5389
c906108c
SS
5390
5391 clear_proceed_status ();
5392
5393 /* Set a breakpoint where the user wants it and at return from
5394 this function */
c5aa993b 5395
c906108c
SS
5396 if (default_breakpoint_valid)
5397 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
c5aa993b 5398 default_breakpoint_line, (char ***) NULL);
c906108c 5399 else
53a5351d
JM
5400 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5401 0, (char ***) NULL);
c5aa993b 5402
c906108c
SS
5403 if (sals.nelts != 1)
5404 error ("Couldn't get information on specified line.");
c5aa993b 5405
c906108c 5406 sal = sals.sals[0];
b8c9b27d 5407 xfree (sals.sals); /* malloc'd, so freed */
c5aa993b 5408
c906108c
SS
5409 if (*arg)
5410 error ("Junk at end of arguments.");
c5aa993b 5411
c906108c 5412 resolve_sal_pc (&sal);
c5aa993b 5413
c906108c 5414 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
c5aa993b 5415
6426a772 5416 if (!event_loop_p || !target_can_async_p ())
4d6140d9 5417 old_chain = make_cleanup_delete_breakpoint (breakpoint);
43ff13b4 5418 else
4d6140d9 5419 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
43ff13b4
JM
5420
5421 /* If we are running asynchronously, and the target supports async
5422 execution, we are not waiting for the target to stop, in the call
5423 tp proceed, below. This means that we cannot delete the
5424 brekpoints until the target has actually stopped. The only place
5425 where we get a chance to do that is in fetch_inferior_event, so
5426 we must set things up for that. */
5427
6426a772 5428 if (event_loop_p && target_can_async_p ())
43ff13b4 5429 {
0d06e24b
JM
5430 /* In this case the arg for the continuation is just the point
5431 in the exec_cleanups chain from where to start doing
5432 cleanups, because all the continuation does is the cleanups in
5433 the exec_cleanup_chain. */
5434 arg1 =
5435 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
57e687d9
MS
5436 arg1->next = NULL;
5437 arg1->data.pointer = old_chain;
0d06e24b
JM
5438
5439 add_continuation (until_break_command_continuation, arg1);
43ff13b4 5440 }
c906108c
SS
5441
5442 /* Keep within the current frame */
c5aa993b 5443
c906108c
SS
5444 if (prev_frame)
5445 {
5446 sal = find_pc_line (prev_frame->pc, 0);
5447 sal.pc = prev_frame->pc;
5448 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
6426a772 5449 if (!event_loop_p || !target_can_async_p ())
4d6140d9 5450 make_cleanup_delete_breakpoint (breakpoint);
43ff13b4 5451 else
4d6140d9 5452 make_exec_cleanup_delete_breakpoint (breakpoint);
c906108c 5453 }
c5aa993b 5454
c906108c 5455 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
43ff13b4
JM
5456 /* Do the cleanups now, anly if we are not running asynchronously,
5457 of if we are, but the target is still synchronous. */
6426a772 5458 if (!event_loop_p || !target_can_async_p ())
c5aa993b 5459 do_cleanups (old_chain);
c906108c
SS
5460}
5461\f
5462#if 0
5463/* These aren't used; I don't konw what they were for. */
5464/* Set a breakpoint at the catch clause for NAME. */
5465static int
fba45db2 5466catch_breakpoint (char *name)
c906108c
SS
5467{
5468}
5469
5470static int
fba45db2 5471disable_catch_breakpoint (void)
c906108c
SS
5472{
5473}
5474
5475static int
fba45db2 5476delete_catch_breakpoint (void)
c906108c
SS
5477{
5478}
5479
5480static int
fba45db2 5481enable_catch_breakpoint (void)
c906108c
SS
5482{
5483}
5484#endif /* 0 */
5485
5486struct sal_chain
5487{
5488 struct sal_chain *next;
5489 struct symtab_and_line sal;
5490};
5491
7a292a7a 5492#if 0
c906108c
SS
5493/* Not really used -- invocation in handle_gnu_4_16_catch_command
5494 had been commented out in the v.4.16 sources, and stays
5495 disabled there now because "catch NAME" syntax isn't allowed.
5496 pai/1997-07-11 */
5497/* This isn't used; I don't know what it was for. */
5498/* For each catch clause identified in ARGS, run FUNCTION
5499 with that clause as an argument. */
5500static struct symtabs_and_lines
831662b3 5501map_catch_names (char *args, int (*function) ())
c906108c
SS
5502{
5503 register char *p = args;
5504 register char *p1;
5505 struct symtabs_and_lines sals;
5506#if 0
5507 struct sal_chain *sal_chain = 0;
5508#endif
5509
5510 if (p == 0)
5511 error_no_arg ("one or more catch names");
5512
5513 sals.nelts = 0;
5514 sals.sals = NULL;
5515
5516 while (*p)
5517 {
5518 p1 = p;
5519 /* Don't swallow conditional part. */
5520 if (p1[0] == 'i' && p1[1] == 'f'
5521 && (p1[2] == ' ' || p1[2] == '\t'))
5522 break;
5523
5524 if (isalpha (*p1))
5525 {
5526 p1++;
5527 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
5528 p1++;
5529 }
5530
5531 if (*p1 && *p1 != ' ' && *p1 != '\t')
5532 error ("Arguments must be catch names.");
5533
5534 *p1 = 0;
5535#if 0
5536 if (function (p))
5537 {
5538 struct sal_chain *next = (struct sal_chain *)
c5aa993b 5539 alloca (sizeof (struct sal_chain));
c906108c
SS
5540 next->next = sal_chain;
5541 next->sal = get_catch_sal (p);
5542 sal_chain = next;
5543 goto win;
5544 }
5545#endif
5546 printf_unfiltered ("No catch clause for exception %s.\n", p);
5547#if 0
5548 win:
5549#endif
5550 p = p1;
c5aa993b
JM
5551 while (*p == ' ' || *p == '\t')
5552 p++;
c906108c
SS
5553 }
5554}
7a292a7a 5555#endif
c906108c
SS
5556
5557/* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5558
5559static struct symtabs_and_lines
fba45db2 5560get_catch_sals (int this_level_only)
c906108c
SS
5561{
5562 register struct blockvector *bl;
5563 register struct block *block;
5564 int index, have_default = 0;
5565 CORE_ADDR pc;
5566 struct symtabs_and_lines sals;
5567 struct sal_chain *sal_chain = 0;
5568 char *blocks_searched;
5569
5570 /* Not sure whether an error message is always the correct response,
5571 but it's better than a core dump. */
5572 if (selected_frame == NULL)
5573 error ("No selected frame.");
5574 block = get_frame_block (selected_frame);
5575 pc = selected_frame->pc;
5576
5577 sals.nelts = 0;
5578 sals.sals = NULL;
5579
5580 if (block == 0)
5581 error ("No symbol table info available.\n");
5582
5583 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
5584 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5585 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
5586
5587 while (block != 0)
5588 {
5589 CORE_ADDR end = BLOCK_END (block) - 4;
5590 int last_index;
5591
5592 if (bl != blockvector_for_pc (end, &index))
5593 error ("blockvector blotch");
5594 if (BLOCKVECTOR_BLOCK (bl, index) != block)
5595 error ("blockvector botch");
5596 last_index = BLOCKVECTOR_NBLOCKS (bl);
5597 index += 1;
5598
5599 /* Don't print out blocks that have gone by. */
5600 while (index < last_index
5601 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
5602 index++;
5603
5604 while (index < last_index
5605 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
5606 {
5607 if (blocks_searched[index] == 0)
5608 {
5609 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
c906108c
SS
5610 register int i;
5611 register struct symbol *sym;
5612
e88c90f2 5613 ALL_BLOCK_SYMBOLS (b, i, sym)
c906108c 5614 {
c906108c
SS
5615 if (STREQ (SYMBOL_NAME (sym), "default"))
5616 {
5617 if (have_default)
5618 continue;
5619 have_default = 1;
5620 }
5621 if (SYMBOL_CLASS (sym) == LOC_LABEL)
5622 {
5623 struct sal_chain *next = (struct sal_chain *)
c5aa993b 5624 alloca (sizeof (struct sal_chain));
c906108c 5625 next->next = sal_chain;
53a5351d
JM
5626 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym),
5627 0);
c906108c
SS
5628 sal_chain = next;
5629 }
5630 }
5631 blocks_searched[index] = 1;
5632 }
5633 index++;
5634 }
5635 if (have_default)
5636 break;
5637 if (sal_chain && this_level_only)
5638 break;
5639
5640 /* After handling the function's top-level block, stop.
c5aa993b
JM
5641 Don't continue to its superblock, the block of
5642 per-file symbols. */
c906108c
SS
5643 if (BLOCK_FUNCTION (block))
5644 break;
5645 block = BLOCK_SUPERBLOCK (block);
5646 }
5647
5648 if (sal_chain)
5649 {
5650 struct sal_chain *tmp_chain;
5651
5652 /* Count the number of entries. */
5653 for (index = 0, tmp_chain = sal_chain; tmp_chain;
5654 tmp_chain = tmp_chain->next)
5655 index++;
5656
5657 sals.nelts = index;
5658 sals.sals = (struct symtab_and_line *)
5659 xmalloc (index * sizeof (struct symtab_and_line));
5660 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
5661 sals.sals[index] = sal_chain->sal;
5662 }
5663
5664 return sals;
5665}
5666
5667static void
fba45db2 5668ep_skip_leading_whitespace (char **s)
c906108c 5669{
c5aa993b
JM
5670 if ((s == NULL) || (*s == NULL))
5671 return;
5672 while (isspace (**s))
5673 *s += 1;
c906108c 5674}
c5aa993b 5675
c906108c
SS
5676/* This function examines a string, and attempts to find a token
5677 that might be an event name in the leading characters. If a
5678 possible match is found, a pointer to the last character of
5679 the token is returned. Else, NULL is returned. */
53a5351d 5680
c906108c 5681static char *
fba45db2 5682ep_find_event_name_end (char *arg)
c906108c 5683{
c5aa993b
JM
5684 char *s = arg;
5685 char *event_name_end = NULL;
5686
c906108c
SS
5687 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5688 if (arg == NULL)
5689 return NULL;
c5aa993b 5690
c906108c 5691 /* We break out of the loop when we find a token delimiter.
c5aa993b
JM
5692 Basically, we're looking for alphanumerics and underscores;
5693 anything else delimites the token. */
c906108c
SS
5694 while (*s != '\0')
5695 {
c5aa993b
JM
5696 if (!isalnum (*s) && (*s != '_'))
5697 break;
c906108c
SS
5698 event_name_end = s;
5699 s++;
5700 }
c5aa993b 5701
c906108c
SS
5702 return event_name_end;
5703}
5704
c5aa993b 5705
c906108c
SS
5706/* This function attempts to parse an optional "if <cond>" clause
5707 from the arg string. If one is not found, it returns NULL.
c5aa993b 5708
c906108c
SS
5709 Else, it returns a pointer to the condition string. (It does not
5710 attempt to evaluate the string against a particular block.) And,
5711 it updates arg to point to the first character following the parsed
5712 if clause in the arg string. */
53a5351d 5713
c906108c 5714static char *
fba45db2 5715ep_parse_optional_if_clause (char **arg)
c906108c 5716{
c5aa993b
JM
5717 char *cond_string;
5718
5719 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
c906108c 5720 return NULL;
c5aa993b 5721
c906108c
SS
5722 /* Skip the "if" keyword. */
5723 (*arg) += 2;
c5aa993b 5724
c906108c
SS
5725 /* Skip any extra leading whitespace, and record the start of the
5726 condition string. */
5727 ep_skip_leading_whitespace (arg);
5728 cond_string = *arg;
c5aa993b 5729
c906108c
SS
5730 /* Assume that the condition occupies the remainder of the arg string. */
5731 (*arg) += strlen (cond_string);
c5aa993b 5732
c906108c
SS
5733 return cond_string;
5734}
c5aa993b 5735
c906108c
SS
5736/* This function attempts to parse an optional filename from the arg
5737 string. If one is not found, it returns NULL.
c5aa993b 5738
c906108c
SS
5739 Else, it returns a pointer to the parsed filename. (This function
5740 makes no attempt to verify that a file of that name exists, or is
5741 accessible.) And, it updates arg to point to the first character
5742 following the parsed filename in the arg string.
c5aa993b 5743
c906108c
SS
5744 Note that clients needing to preserve the returned filename for
5745 future access should copy it to their own buffers. */
5746static char *
fba45db2 5747ep_parse_optional_filename (char **arg)
c906108c 5748{
c5aa993b
JM
5749 static char filename[1024];
5750 char *arg_p = *arg;
5751 int i;
5752 char c;
5753
c906108c
SS
5754 if ((*arg_p == '\0') || isspace (*arg_p))
5755 return NULL;
c5aa993b
JM
5756
5757 for (i = 0;; i++)
c906108c
SS
5758 {
5759 c = *arg_p;
5760 if (isspace (c))
c5aa993b 5761 c = '\0';
c906108c
SS
5762 filename[i] = c;
5763 if (c == '\0')
c5aa993b 5764 break;
c906108c
SS
5765 arg_p++;
5766 }
5767 *arg = arg_p;
c5aa993b 5768
c906108c
SS
5769 return filename;
5770}
c5aa993b 5771
c906108c
SS
5772/* Commands to deal with catching events, such as signals, exceptions,
5773 process start/exit, etc. */
c5aa993b
JM
5774
5775typedef enum
5776{
5777 catch_fork, catch_vfork
5778}
5779catch_fork_kind;
5780
e514a9d6 5781#if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
a14ed312
KB
5782static void catch_fork_command_1 (catch_fork_kind fork_kind,
5783 char *arg, int tempflag, int from_tty);
7a292a7a 5784
c906108c 5785static void
fba45db2
KB
5786catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5787 int from_tty)
c906108c 5788{
c5aa993b
JM
5789 char *cond_string = NULL;
5790
c906108c 5791 ep_skip_leading_whitespace (&arg);
c5aa993b 5792
c906108c 5793 /* The allowed syntax is:
c5aa993b
JM
5794 catch [v]fork
5795 catch [v]fork if <cond>
5796
c906108c
SS
5797 First, check if there's an if clause. */
5798 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5799
c906108c
SS
5800 if ((*arg != '\0') && !isspace (*arg))
5801 error ("Junk at end of arguments.");
c5aa993b 5802
c906108c
SS
5803 /* If this target supports it, create a fork or vfork catchpoint
5804 and enable reporting of such events. */
c5aa993b
JM
5805 switch (fork_kind)
5806 {
5807 case catch_fork:
c906108c
SS
5808 create_fork_event_catchpoint (tempflag, cond_string);
5809 break;
c5aa993b 5810 case catch_vfork:
c906108c
SS
5811 create_vfork_event_catchpoint (tempflag, cond_string);
5812 break;
c5aa993b 5813 default:
c906108c
SS
5814 error ("unsupported or unknown fork kind; cannot catch it");
5815 break;
c5aa993b 5816 }
c906108c 5817}
e514a9d6 5818#endif
c906108c 5819
e514a9d6 5820#if defined(CHILD_INSERT_EXEC_CATCHPOINT)
c906108c 5821static void
fba45db2 5822catch_exec_command_1 (char *arg, int tempflag, int from_tty)
c906108c 5823{
c5aa993b 5824 char *cond_string = NULL;
c906108c
SS
5825
5826 ep_skip_leading_whitespace (&arg);
5827
5828 /* The allowed syntax is:
c5aa993b
JM
5829 catch exec
5830 catch exec if <cond>
c906108c
SS
5831
5832 First, check if there's an if clause. */
5833 cond_string = ep_parse_optional_if_clause (&arg);
5834
5835 if ((*arg != '\0') && !isspace (*arg))
5836 error ("Junk at end of arguments.");
5837
5838 /* If this target supports it, create an exec catchpoint
5839 and enable reporting of such events. */
5840 create_exec_event_catchpoint (tempflag, cond_string);
5841}
e514a9d6 5842#endif
c5aa993b 5843
c906108c
SS
5844#if defined(SOLIB_ADD)
5845static void
fba45db2 5846catch_load_command_1 (char *arg, int tempflag, int from_tty)
c906108c 5847{
c5aa993b
JM
5848 char *dll_pathname = NULL;
5849 char *cond_string = NULL;
5850
c906108c 5851 ep_skip_leading_whitespace (&arg);
c5aa993b 5852
c906108c 5853 /* The allowed syntax is:
c5aa993b
JM
5854 catch load
5855 catch load if <cond>
5856 catch load <filename>
5857 catch load <filename> if <cond>
5858
c906108c
SS
5859 The user is not allowed to specify the <filename> after an
5860 if clause.
c5aa993b 5861
c906108c 5862 We'll ignore the pathological case of a file named "if".
c5aa993b 5863
c906108c
SS
5864 First, check if there's an if clause. If so, then there
5865 cannot be a filename. */
5866 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5867
c906108c
SS
5868 /* If there was an if clause, then there cannot be a filename.
5869 Else, there might be a filename and an if clause. */
5870 if (cond_string == NULL)
5871 {
5872 dll_pathname = ep_parse_optional_filename (&arg);
5873 ep_skip_leading_whitespace (&arg);
5874 cond_string = ep_parse_optional_if_clause (&arg);
5875 }
c5aa993b 5876
c906108c
SS
5877 if ((*arg != '\0') && !isspace (*arg))
5878 error ("Junk at end of arguments.");
c5aa993b 5879
c906108c
SS
5880 /* Create a load breakpoint that only triggers when a load of
5881 the specified dll (or any dll, if no pathname was specified)
5882 occurs. */
39f77062 5883 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
53a5351d 5884 dll_pathname, cond_string);
c906108c 5885}
c5aa993b 5886
c906108c 5887static void
fba45db2 5888catch_unload_command_1 (char *arg, int tempflag, int from_tty)
c906108c 5889{
c5aa993b
JM
5890 char *dll_pathname = NULL;
5891 char *cond_string = NULL;
5892
c906108c 5893 ep_skip_leading_whitespace (&arg);
c5aa993b 5894
c906108c 5895 /* The allowed syntax is:
c5aa993b
JM
5896 catch unload
5897 catch unload if <cond>
5898 catch unload <filename>
5899 catch unload <filename> if <cond>
5900
c906108c
SS
5901 The user is not allowed to specify the <filename> after an
5902 if clause.
c5aa993b 5903
c906108c 5904 We'll ignore the pathological case of a file named "if".
c5aa993b 5905
c906108c
SS
5906 First, check if there's an if clause. If so, then there
5907 cannot be a filename. */
5908 cond_string = ep_parse_optional_if_clause (&arg);
c5aa993b 5909
c906108c
SS
5910 /* If there was an if clause, then there cannot be a filename.
5911 Else, there might be a filename and an if clause. */
5912 if (cond_string == NULL)
5913 {
5914 dll_pathname = ep_parse_optional_filename (&arg);
5915 ep_skip_leading_whitespace (&arg);
5916 cond_string = ep_parse_optional_if_clause (&arg);
5917 }
c5aa993b 5918
c906108c
SS
5919 if ((*arg != '\0') && !isspace (*arg))
5920 error ("Junk at end of arguments.");
c5aa993b 5921
c906108c
SS
5922 /* Create an unload breakpoint that only triggers when an unload of
5923 the specified dll (or any dll, if no pathname was specified)
5924 occurs. */
39f77062 5925 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
53a5351d 5926 dll_pathname, cond_string);
c906108c
SS
5927}
5928#endif /* SOLIB_ADD */
5929
5930/* Commands to deal with catching exceptions. */
5931
5932/* Set a breakpoint at the specified callback routine for an
c5aa993b 5933 exception event callback */
c906108c
SS
5934
5935static void
fba45db2
KB
5936create_exception_catchpoint (int tempflag, char *cond_string,
5937 enum exception_event_kind ex_event,
5938 struct symtab_and_line *sal)
c906108c 5939{
c5aa993b 5940 struct breakpoint *b;
c5aa993b 5941 int thread = -1; /* All threads. */
4d28f7a8 5942 enum bptype bptype;
c906108c 5943
c5aa993b 5944 if (!sal) /* no exception support? */
c906108c
SS
5945 return;
5946
c906108c
SS
5947 switch (ex_event)
5948 {
c5aa993b 5949 case EX_EVENT_THROW:
4d28f7a8 5950 bptype = bp_catch_throw;
c5aa993b
JM
5951 break;
5952 case EX_EVENT_CATCH:
4d28f7a8 5953 bptype = bp_catch_catch;
c5aa993b
JM
5954 break;
5955 default: /* error condition */
c5aa993b 5956 error ("Internal error -- invalid catchpoint kind");
c906108c 5957 }
4d28f7a8
KB
5958
5959 b = set_raw_breakpoint (*sal, bptype);
5960 set_breakpoint_count (breakpoint_count + 1);
5961 b->number = breakpoint_count;
5962 b->cond = NULL;
5963 b->cond_string = (cond_string == NULL) ?
5964 NULL : savestring (cond_string, strlen (cond_string));
5965 b->thread = thread;
5966 b->addr_string = NULL;
b5de0fa7
EZ
5967 b->enable_state = bp_enabled;
5968 b->disposition = tempflag ? disp_del : disp_donttouch;
c906108c
SS
5969 mention (b);
5970}
5971
c5aa993b 5972/* Deal with "catch catch" and "catch throw" commands */
c906108c
SS
5973
5974static void
fba45db2
KB
5975catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
5976 int tempflag, int from_tty)
c906108c 5977{
c5aa993b
JM
5978 char *cond_string = NULL;
5979 struct symtab_and_line *sal = NULL;
5980
c906108c 5981 ep_skip_leading_whitespace (&arg);
c5aa993b 5982
c906108c
SS
5983 cond_string = ep_parse_optional_if_clause (&arg);
5984
5985 if ((*arg != '\0') && !isspace (*arg))
5986 error ("Junk at end of arguments.");
5987
5988 if ((ex_event != EX_EVENT_THROW) &&
5989 (ex_event != EX_EVENT_CATCH))
5990 error ("Unsupported or unknown exception event; cannot catch it");
5991
5992 /* See if we can find a callback routine */
5993 sal = target_enable_exception_callback (ex_event, 1);
5994
c5aa993b 5995 if (sal)
c906108c
SS
5996 {
5997 /* We have callbacks from the runtime system for exceptions.
c5aa993b 5998 Set a breakpoint on the sal found, if no errors */
c906108c 5999 if (sal != (struct symtab_and_line *) -1)
c5aa993b 6000 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
c906108c 6001 else
53a5351d 6002 return; /* something went wrong with setting up callbacks */
c906108c 6003 }
c5aa993b 6004 else
c906108c
SS
6005 {
6006 /* No callbacks from runtime system for exceptions.
6007 Try GNU C++ exception breakpoints using labels in debug info. */
6008 if (ex_event == EX_EVENT_CATCH)
c5aa993b
JM
6009 {
6010 handle_gnu_4_16_catch_command (arg, tempflag, from_tty);
6011 }
c906108c 6012 else if (ex_event == EX_EVENT_THROW)
c5aa993b
JM
6013 {
6014 /* Set a breakpoint on __raise_exception () */
6015
53a5351d
JM
6016 warning ("Unsupported with this platform/compiler combination.");
6017 warning ("Perhaps you can achieve the effect you want by setting");
6018 warning ("a breakpoint on __raise_exception().");
c5aa993b 6019 }
c906108c
SS
6020 }
6021}
6022
6023/* Cover routine to allow wrapping target_enable_exception_catchpoints
6024 inside a catch_errors */
6025
6026static int
fba45db2 6027cover_target_enable_exception_callback (PTR arg)
c906108c
SS
6028{
6029 args_for_catchpoint_enable *args = arg;
6030 struct symtab_and_line *sal;
b5de0fa7 6031 sal = target_enable_exception_callback (args->kind, args->enable_p);
c906108c
SS
6032 if (sal == NULL)
6033 return 0;
6034 else if (sal == (struct symtab_and_line *) -1)
6035 return -1;
6036 else
c5aa993b 6037 return 1; /*is valid */
c906108c
SS
6038}
6039
6040
6041
6042/* This is the original v.4.16 and earlier version of the
6043 catch_command_1() function. Now that other flavours of "catch"
6044 have been introduced, and since exception handling can be handled
6045 in other ways (through target ops) also, this is used only for the
6046 GNU C++ exception handling system.
6047 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6048 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6049 there was no code in GDB 4.16 for "catch throw".
c5aa993b 6050
c906108c
SS
6051 Called from catch_exception_command_1 () */
6052
6053
6054static void
fba45db2 6055handle_gnu_4_16_catch_command (char *arg, int tempflag, int from_tty)
c906108c
SS
6056{
6057 /* First, translate ARG into something we can deal with in terms
6058 of breakpoints. */
6059
6060 struct symtabs_and_lines sals;
6061 struct symtab_and_line sal;
6062 register struct expression *cond = 0;
6063 register struct breakpoint *b;
6064 char *save_arg;
6065 int i;
6066
c5aa993b 6067 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
6068
6069 /* If no arg given, or if first arg is 'if ', all active catch clauses
6070 are breakpointed. */
6071
c5aa993b 6072 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
c906108c
SS
6073 && (arg[2] == ' ' || arg[2] == '\t')))
6074 {
6075 /* Grab all active catch clauses. */
6076 sals = get_catch_sals (0);
6077 }
6078 else
6079 {
6080 /* Grab selected catch clauses. */
6081 error ("catch NAME not implemented");
6082
6083#if 0
6084 /* Not sure why this code has been disabled. I'm leaving
6085 it disabled. We can never come here now anyway
6086 since we don't allow the "catch NAME" syntax.
c5aa993b 6087 pai/1997-07-11 */
c906108c
SS
6088
6089 /* This isn't used; I don't know what it was for. */
6090 sals = map_catch_names (arg, catch_breakpoint);
6091#endif
6092 }
6093
c5aa993b 6094 if (!sals.nelts)
c906108c
SS
6095 return;
6096
6097 save_arg = arg;
6098 for (i = 0; i < sals.nelts; i++)
6099 {
6100 resolve_sal_pc (&sals.sals[i]);
c5aa993b 6101
c906108c
SS
6102 while (arg && *arg)
6103 {
6104 if (arg[0] == 'i' && arg[1] == 'f'
6105 && (arg[2] == ' ' || arg[2] == '\t'))
c5aa993b 6106 cond = parse_exp_1 ((arg += 2, &arg),
c906108c
SS
6107 block_for_pc (sals.sals[i].pc), 0);
6108 else
6109 error ("Junk at end of arguments.");
6110 }
6111 arg = save_arg;
6112 }
6113
6114 for (i = 0; i < sals.nelts; i++)
6115 {
6116 sal = sals.sals[i];
6117
6118 if (from_tty)
6119 describe_other_breakpoints (sal.pc, sal.section);
6120
53a5351d
JM
6121 /* Important -- this is an ordinary breakpoint. For platforms
6122 with callback support for exceptions,
6123 create_exception_catchpoint() will create special bp types
6124 (bp_catch_catch and bp_catch_throw), and there is code in
6125 insert_breakpoints() and elsewhere that depends on that. */
4d28f7a8
KB
6126 b = set_raw_breakpoint (sal, bp_breakpoint);
6127 set_breakpoint_count (breakpoint_count + 1);
6128 b->number = breakpoint_count;
c906108c
SS
6129
6130 b->cond = cond;
b5de0fa7
EZ
6131 b->enable_state = bp_enabled;
6132 b->disposition = tempflag ? disp_del : disp_donttouch;
c906108c
SS
6133
6134 mention (b);
6135 }
6136
6137 if (sals.nelts > 1)
6138 {
53a5351d
JM
6139 warning ("Multiple breakpoints were set.");
6140 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
c906108c 6141 }
b8c9b27d 6142 xfree (sals.sals);
c906108c
SS
6143}
6144
6145#if 0
6146/* This creates a temporary internal breakpoint
6147 just to placate infrun */
6148static struct breakpoint *
fba45db2 6149create_temp_exception_breakpoint (CORE_ADDR pc)
c906108c
SS
6150{
6151 struct symtab_and_line sal;
6152 struct breakpoint *b;
6153
c5aa993b 6154 INIT_SAL (&sal);
c906108c
SS
6155 sal.pc = pc;
6156 sal.symtab = NULL;
6157 sal.line = 0;
6158
4d28f7a8 6159 b = set_raw_breakpoint (sal, bp_breakpoint);
c906108c 6160
b5de0fa7
EZ
6161 b->disposition = disp_del;
6162 b->enable_state = bp_enabled;
c906108c
SS
6163 b->silent = 1;
6164 b->number = internal_breakpoint_number--;
6165 return b;
6166}
6167#endif
6168
6169static void
fba45db2 6170catch_command_1 (char *arg, int tempflag, int from_tty)
c906108c 6171{
c5aa993b 6172
c906108c
SS
6173 /* The first argument may be an event name, such as "start" or "load".
6174 If so, then handle it as such. If it doesn't match an event name,
6175 then attempt to interpret it as an exception name. (This latter is
6176 the v4.16-and-earlier GDB meaning of the "catch" command.)
c5aa993b 6177
c906108c 6178 First, try to find the bounds of what might be an event name. */
c5aa993b
JM
6179 char *arg1_start = arg;
6180 char *arg1_end;
6181 int arg1_length;
6182
c906108c
SS
6183 if (arg1_start == NULL)
6184 {
c5aa993b 6185 /* Old behaviour was to use pre-v-4.16 syntax */
c906108c
SS
6186 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6187 /* return; */
c5aa993b 6188 /* Now, this is not allowed */
c906108c
SS
6189 error ("Catch requires an event name.");
6190
6191 }
6192 arg1_end = ep_find_event_name_end (arg1_start);
6193 if (arg1_end == NULL)
6194 error ("catch requires an event");
6195 arg1_length = arg1_end + 1 - arg1_start;
c5aa993b 6196
c906108c
SS
6197 /* Try to match what we found against known event names. */
6198 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6199 {
6200 error ("Catch of signal not yet implemented");
6201 }
6202 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6203 {
53a5351d
JM
6204 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6205 tempflag, from_tty);
c906108c
SS
6206 }
6207 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6208 {
53a5351d
JM
6209 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6210 tempflag, from_tty);
c906108c
SS
6211 }
6212 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6213 {
6214 error ("Catch of thread_start not yet implemented");
6215 }
6216 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6217 {
6218 error ("Catch of thread_exit not yet implemented");
6219 }
6220 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6221 {
6222 error ("Catch of thread_join not yet implemented");
6223 }
6224 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6225 {
6226 error ("Catch of start not yet implemented");
6227 }
6228 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6229 {
6230 error ("Catch of exit not yet implemented");
6231 }
6232 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6233 {
6234#if defined(CHILD_INSERT_FORK_CATCHPOINT)
c5aa993b 6235 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
6236#else
6237 error ("Catch of fork not yet implemented");
6238#endif
6239 }
6240 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6241 {
6242#if defined(CHILD_INSERT_VFORK_CATCHPOINT)
c5aa993b 6243 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
c906108c
SS
6244#else
6245 error ("Catch of vfork not yet implemented");
6246#endif
6247 }
6248 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6249 {
6250#if defined(CHILD_INSERT_EXEC_CATCHPOINT)
c5aa993b 6251 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
6252#else
6253 error ("Catch of exec not yet implemented");
6254#endif
6255 }
6256 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6257 {
6258#if defined(SOLIB_ADD)
c5aa993b 6259 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
6260#else
6261 error ("Catch of load not implemented");
6262#endif
6263 }
6264 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6265 {
6266#if defined(SOLIB_ADD)
c5aa993b 6267 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
c906108c
SS
6268#else
6269 error ("Catch of load not implemented");
6270#endif
6271 }
6272 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6273 {
6274 error ("Catch of stop not yet implemented");
6275 }
c5aa993b 6276
c906108c
SS
6277 /* This doesn't appear to be an event name */
6278
6279 else
6280 {
6281 /* Pre-v.4.16 behaviour was to treat the argument
c5aa993b 6282 as the name of an exception */
c906108c 6283 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
c5aa993b 6284 /* Now this is not allowed */
c906108c
SS
6285 error ("Unknown event kind specified for catch");
6286
6287 }
6288}
6289
6290/* Used by the gui, could be made a worker for other things. */
6291
6292struct breakpoint *
fba45db2 6293set_breakpoint_sal (struct symtab_and_line sal)
c906108c
SS
6294{
6295 struct breakpoint *b;
4d28f7a8 6296 b = set_raw_breakpoint (sal, bp_breakpoint);
c906108c
SS
6297 set_breakpoint_count (breakpoint_count + 1);
6298 b->number = breakpoint_count;
c906108c
SS
6299 b->cond = 0;
6300 b->thread = -1;
6301 return b;
6302}
6303
6304#if 0
6305/* These aren't used; I don't know what they were for. */
6306/* Disable breakpoints on all catch clauses described in ARGS. */
6307static void
fba45db2 6308disable_catch (char *args)
c906108c
SS
6309{
6310 /* Map the disable command to catch clauses described in ARGS. */
6311}
6312
6313/* Enable breakpoints on all catch clauses described in ARGS. */
6314static void
fba45db2 6315enable_catch (char *args)
c906108c
SS
6316{
6317 /* Map the disable command to catch clauses described in ARGS. */
6318}
6319
6320/* Delete breakpoints on all catch clauses in the active scope. */
6321static void
fba45db2 6322delete_catch (char *args)
c906108c
SS
6323{
6324 /* Map the delete command to catch clauses described in ARGS. */
6325}
6326#endif /* 0 */
6327
6328static void
fba45db2 6329catch_command (char *arg, int from_tty)
c906108c
SS
6330{
6331 catch_command_1 (arg, 0, from_tty);
6332}
6333\f
6334
6335static void
fba45db2 6336tcatch_command (char *arg, int from_tty)
c906108c
SS
6337{
6338 catch_command_1 (arg, 1, from_tty);
6339}
6340
6341
6342static void
fba45db2 6343clear_command (char *arg, int from_tty)
c906108c
SS
6344{
6345 register struct breakpoint *b, *b1;
6346 int default_match;
6347 struct symtabs_and_lines sals;
6348 struct symtab_and_line sal;
6349 register struct breakpoint *found;
6350 int i;
6351
6352 if (arg)
6353 {
6354 sals = decode_line_spec (arg, 1);
6355 default_match = 0;
6356 }
6357 else
6358 {
c5aa993b 6359 sals.sals = (struct symtab_and_line *)
c906108c 6360 xmalloc (sizeof (struct symtab_and_line));
c5aa993b 6361 INIT_SAL (&sal); /* initialize to zeroes */
c906108c
SS
6362 sal.line = default_breakpoint_line;
6363 sal.symtab = default_breakpoint_symtab;
6364 sal.pc = default_breakpoint_address;
6365 if (sal.symtab == 0)
6366 error ("No source file specified.");
6367
6368 sals.sals[0] = sal;
6369 sals.nelts = 1;
6370
6371 default_match = 1;
6372 }
6373
6374 /* For each line spec given, delete bps which correspond
6375 to it. We do this in two loops: the first loop looks at
6376 the initial bp(s) in the chain which should be deleted,
6377 the second goes down the rest of the chain looking ahead
6378 one so it can take those bps off the chain without messing
6379 up the chain. */
6380
6381
6382 for (i = 0; i < sals.nelts; i++)
6383 {
6384 /* If exact pc given, clear bpts at that pc.
c5aa993b
JM
6385 If line given (pc == 0), clear all bpts on specified line.
6386 If defaulting, clear all bpts on default line
c906108c 6387 or at default pc.
c5aa993b
JM
6388
6389 defaulting sal.pc != 0 tests to do
6390
6391 0 1 pc
6392 1 1 pc _and_ line
6393 0 0 line
6394 1 0 <can't happen> */
c906108c
SS
6395
6396 sal = sals.sals[i];
6397 found = (struct breakpoint *) 0;
6398
6399
6400 while (breakpoint_chain
c5aa993b
JM
6401 /* Why don't we check here that this is not
6402 a watchpoint, etc., as we do below?
6403 I can't make it fail, but don't know
6404 what's stopping the failure: a watchpoint
6405 of the same address as "sal.pc" should
6406 wind up being deleted. */
6407
6408 && (((sal.pc && (breakpoint_chain->address == sal.pc)) &&
6409 (overlay_debugging == 0 ||
6410 breakpoint_chain->section == sal.section))
6411 || ((default_match || (0 == sal.pc))
6412 && breakpoint_chain->source_file != NULL
6413 && sal.symtab != NULL
6414 && STREQ (breakpoint_chain->source_file, sal.symtab->filename)
6415 && breakpoint_chain->line_number == sal.line)))
c906108c
SS
6416
6417 {
6418 b1 = breakpoint_chain;
6419 breakpoint_chain = b1->next;
6420 b1->next = found;
6421 found = b1;
6422 }
6423
6424 ALL_BREAKPOINTS (b)
6425
c5aa993b
JM
6426 while (b->next
6427 && b->next->type != bp_none
6428 && b->next->type != bp_watchpoint
6429 && b->next->type != bp_hardware_watchpoint
6430 && b->next->type != bp_read_watchpoint
6431 && b->next->type != bp_access_watchpoint
6432 && (((sal.pc && (b->next->address == sal.pc)) &&
6433 (overlay_debugging == 0 ||
6434 b->next->section == sal.section))
6435 || ((default_match || (0 == sal.pc))
6436 && b->next->source_file != NULL
6437 && sal.symtab != NULL
6438 && STREQ (b->next->source_file, sal.symtab->filename)
6439 && b->next->line_number == sal.line)))
c906108c
SS
6440
6441
c5aa993b
JM
6442 {
6443 b1 = b->next;
6444 b->next = b1->next;
6445 b1->next = found;
6446 found = b1;
6447 }
c906108c
SS
6448
6449 if (found == 0)
6450 {
6451 if (arg)
6452 error ("No breakpoint at %s.", arg);
6453 else
6454 error ("No breakpoint at this line.");
6455 }
6456
c5aa993b
JM
6457 if (found->next)
6458 from_tty = 1; /* Always report if deleted more than one */
6459 if (from_tty)
6460 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
c906108c
SS
6461 breakpoints_changed ();
6462 while (found)
6463 {
c5aa993b
JM
6464 if (from_tty)
6465 printf_unfiltered ("%d ", found->number);
c906108c
SS
6466 b1 = found->next;
6467 delete_breakpoint (found);
6468 found = b1;
6469 }
c5aa993b
JM
6470 if (from_tty)
6471 putchar_unfiltered ('\n');
c906108c 6472 }
b8c9b27d 6473 xfree (sals.sals);
c906108c
SS
6474}
6475\f
6476/* Delete breakpoint in BS if they are `delete' breakpoints and
6477 all breakpoints that are marked for deletion, whether hit or not.
6478 This is called after any breakpoint is hit, or after errors. */
6479
6480void
fba45db2 6481breakpoint_auto_delete (bpstat bs)
c906108c
SS
6482{
6483 struct breakpoint *b, *temp;
6484
6485 for (; bs; bs = bs->next)
b5de0fa7 6486 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
c906108c
SS
6487 && bs->stop)
6488 delete_breakpoint (bs->breakpoint_at);
6489
6490 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 6491 {
b5de0fa7 6492 if (b->disposition == disp_del_at_next_stop)
c5aa993b
JM
6493 delete_breakpoint (b);
6494 }
c906108c
SS
6495}
6496
53a5351d
JM
6497/* Delete a breakpoint and clean up all traces of it in the data
6498 structures. */
c906108c
SS
6499
6500void
fba45db2 6501delete_breakpoint (struct breakpoint *bpt)
c906108c
SS
6502{
6503 register struct breakpoint *b;
6504 register bpstat bs;
6505
6506 if (bpt == NULL)
6507 error ("Internal error (attempted to delete a NULL breakpoint)");
6508
6509
6510 /* Has this bp already been deleted? This can happen because multiple
6511 lists can hold pointers to bp's. bpstat lists are especial culprits.
6512
6513 One example of this happening is a watchpoint's scope bp. When the
6514 scope bp triggers, we notice that the watchpoint is out of scope, and
6515 delete it. We also delete its scope bp. But the scope bp is marked
6516 "auto-deleting", and is already on a bpstat. That bpstat is then
6517 checked for auto-deleting bp's, which are deleted.
6518
6519 A real solution to this problem might involve reference counts in bp's,
6520 and/or giving them pointers back to their referencing bpstat's, and
6521 teaching delete_breakpoint to only free a bp's storage when no more
6522 references were extent. A cheaper bandaid was chosen. */
6523 if (bpt->type == bp_none)
6524 return;
6525
6526 if (delete_breakpoint_hook)
6527 delete_breakpoint_hook (bpt);
104c1213 6528 breakpoint_delete_event (bpt->number);
c906108c
SS
6529
6530 if (bpt->inserted)
2e663524 6531 remove_breakpoint (bpt, mark_inserted);
c5aa993b 6532
c906108c
SS
6533 if (breakpoint_chain == bpt)
6534 breakpoint_chain = bpt->next;
6535
6536 /* If we have callback-style exception catchpoints, don't go through
6537 the adjustments to the C++ runtime library etc. if the inferior
6538 isn't actually running. target_enable_exception_callback for a
6539 null target ops vector gives an undesirable error message, so we
6540 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
c5aa993b 6541 exceptions are supported in this way, it's OK for now. FIXME */
c906108c
SS
6542 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6543 {
6544 static char message1[] = "Error in deleting catchpoint %d:\n";
6545 static char message[sizeof (message1) + 30];
6546 args_for_catchpoint_enable args;
6547
53a5351d
JM
6548 /* Format possible error msg */
6549 sprintf (message, message1, bpt->number);
6550 args.kind = bpt->type == bp_catch_catch ?
6551 EX_EVENT_CATCH : EX_EVENT_THROW;
b5de0fa7 6552 args.enable_p = 0;
c906108c
SS
6553 catch_errors (cover_target_enable_exception_callback, &args,
6554 message, RETURN_MASK_ALL);
6555 }
6556
6557
6558 ALL_BREAKPOINTS (b)
6559 if (b->next == bpt)
c5aa993b
JM
6560 {
6561 b->next = bpt->next;
6562 break;
6563 }
c906108c 6564
9f60f21b 6565 check_duplicates (bpt);
c906108c
SS
6566 /* If this breakpoint was inserted, and there is another breakpoint
6567 at the same address, we need to insert the other breakpoint. */
6568 if (bpt->inserted
6569 && bpt->type != bp_hardware_watchpoint
6570 && bpt->type != bp_read_watchpoint
6571 && bpt->type != bp_access_watchpoint
6572 && bpt->type != bp_catch_fork
6573 && bpt->type != bp_catch_vfork
6574 && bpt->type != bp_catch_exec)
6575 {
6576 ALL_BREAKPOINTS (b)
6577 if (b->address == bpt->address
6578 && b->section == bpt->section
6579 && !b->duplicate
b5de0fa7
EZ
6580 && b->enable_state != bp_disabled
6581 && b->enable_state != bp_shlib_disabled
6582 && b->enable_state != bp_call_disabled)
c5aa993b
JM
6583 {
6584 int val;
53a5351d 6585
c2c6d25f
JM
6586 /* We should never reach this point if there is a permanent
6587 breakpoint at the same address as the one being deleted.
6588 If there is a permanent breakpoint somewhere, it should
6589 always be the only one inserted. */
b5de0fa7 6590 if (b->enable_state == bp_permanent)
8e65ff28
AC
6591 internal_error (__FILE__, __LINE__,
6592 "another breakpoint was inserted on top of "
c2c6d25f
JM
6593 "a permanent breakpoint");
6594
53a5351d
JM
6595 if (b->type == bp_hardware_breakpoint)
6596 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6597 else
6598 val = target_insert_breakpoint (b->address, b->shadow_contents);
6599
c5aa993b
JM
6600 if (val != 0)
6601 {
6602 target_terminal_ours_for_output ();
53a5351d 6603 warning ("Cannot insert breakpoint %d:", b->number);
c5aa993b
JM
6604 memory_error (val, b->address); /* which bombs us out */
6605 }
6606 else
6607 b->inserted = 1;
6608 }
c906108c
SS
6609 }
6610
6611 free_command_lines (&bpt->commands);
6612 if (bpt->cond)
b8c9b27d 6613 xfree (bpt->cond);
c906108c 6614 if (bpt->cond_string != NULL)
b8c9b27d 6615 xfree (bpt->cond_string);
c906108c 6616 if (bpt->addr_string != NULL)
b8c9b27d 6617 xfree (bpt->addr_string);
c906108c 6618 if (bpt->exp != NULL)
b8c9b27d 6619 xfree (bpt->exp);
c906108c 6620 if (bpt->exp_string != NULL)
b8c9b27d 6621 xfree (bpt->exp_string);
c906108c
SS
6622 if (bpt->val != NULL)
6623 value_free (bpt->val);
6624 if (bpt->source_file != NULL)
b8c9b27d 6625 xfree (bpt->source_file);
c906108c 6626 if (bpt->dll_pathname != NULL)
b8c9b27d 6627 xfree (bpt->dll_pathname);
c906108c 6628 if (bpt->triggered_dll_pathname != NULL)
b8c9b27d 6629 xfree (bpt->triggered_dll_pathname);
c906108c 6630 if (bpt->exec_pathname != NULL)
b8c9b27d 6631 xfree (bpt->exec_pathname);
c906108c
SS
6632
6633 /* Be sure no bpstat's are pointing at it after it's been freed. */
6634 /* FIXME, how can we find all bpstat's?
6635 We just check stop_bpstat for now. */
6636 for (bs = stop_bpstat; bs; bs = bs->next)
6637 if (bs->breakpoint_at == bpt)
6638 {
6639 bs->breakpoint_at = NULL;
6640
6641 /* we'd call bpstat_clear_actions, but that free's stuff and due
6642 to the multiple pointers pointing to one item with no
6643 reference counts found anywhere through out the bpstat's (how
6644 do you spell fragile?), we don't want to free things twice --
6645 better a memory leak than a corrupt malloc pool! */
6646 bs->commands = NULL;
6647 bs->old_val = NULL;
6648 }
6649 /* On the chance that someone will soon try again to delete this same
6650 bp, we mark it as deleted before freeing its storage. */
6651 bpt->type = bp_none;
6652
b8c9b27d 6653 xfree (bpt);
c906108c
SS
6654}
6655
4d6140d9
AC
6656static void
6657do_delete_breakpoint_cleanup (void *b)
6658{
6659 delete_breakpoint (b);
6660}
6661
6662struct cleanup *
6663make_cleanup_delete_breakpoint (struct breakpoint *b)
6664{
6665 return make_cleanup (do_delete_breakpoint_cleanup, b);
6666}
6667
6668struct cleanup *
6669make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6670{
6671 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6672}
6673
c906108c 6674void
fba45db2 6675delete_command (char *arg, int from_tty)
c906108c
SS
6676{
6677 struct breakpoint *b, *temp;
6678
6679 if (arg == 0)
6680 {
6681 int breaks_to_delete = 0;
6682
6683 /* Delete all breakpoints if no argument.
c5aa993b
JM
6684 Do not delete internal or call-dummy breakpoints, these
6685 have to be deleted with an explicit breakpoint number argument. */
6686 ALL_BREAKPOINTS (b)
6687 {
6688 if (b->type != bp_call_dummy &&
6689 b->type != bp_shlib_event &&
c4093a6a 6690 b->type != bp_thread_event &&
c5aa993b
JM
6691 b->number >= 0)
6692 breaks_to_delete = 1;
6693 }
c906108c
SS
6694
6695 /* Ask user only if there are some breakpoints to delete. */
6696 if (!from_tty
6697 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6698 {
c5aa993b
JM
6699 ALL_BREAKPOINTS_SAFE (b, temp)
6700 {
6701 if (b->type != bp_call_dummy &&
6702 b->type != bp_shlib_event &&
c4093a6a 6703 b->type != bp_thread_event &&
c5aa993b
JM
6704 b->number >= 0)
6705 delete_breakpoint (b);
6706 }
c906108c
SS
6707 }
6708 }
6709 else
6710 map_breakpoint_numbers (arg, delete_breakpoint);
6711}
6712
6713/* Reset a breakpoint given it's struct breakpoint * BINT.
6714 The value we return ends up being the return value from catch_errors.
6715 Unused in this case. */
6716
6717static int
fba45db2 6718breakpoint_re_set_one (PTR bint)
c906108c 6719{
53a5351d
JM
6720 /* get past catch_errs */
6721 struct breakpoint *b = (struct breakpoint *) bint;
c906108c
SS
6722 struct value *mark;
6723 int i;
6724 struct symtabs_and_lines sals;
6725 char *s;
b5de0fa7 6726 enum enable_state save_enable;
c906108c
SS
6727
6728 switch (b->type)
6729 {
6730 case bp_none:
53a5351d
JM
6731 warning ("attempted to reset apparently deleted breakpoint #%d?",
6732 b->number);
c906108c
SS
6733 return 0;
6734 case bp_breakpoint:
6735 case bp_hardware_breakpoint:
6736 case bp_catch_load:
6737 case bp_catch_unload:
6738 if (b->addr_string == NULL)
6739 {
6740 /* Anything without a string can't be re-set. */
6741 delete_breakpoint (b);
6742 return 0;
6743 }
b18c45ed
AC
6744 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6745
6746 ``And a hack it is, although Apple's Darwin version of GDB
6747 contains an almost identical hack to implement a "future
6748 break" command. It seems to work in many real world cases,
6749 but it is easy to come up with a test case where the patch
6750 doesn't help at all.''
6751
6752 ``It seems that the way GDB implements breakpoints - in -
6753 shared - libraries was designed for a.out shared library
6754 systems (SunOS 4) where shared libraries were loaded at a
6755 fixed address in memory. Since ELF shared libraries can (and
6756 will) be loaded at any address in memory, things break.
6757 Fixing this is not trivial. Therefore, I'm not sure whether
6758 we should add this hack to the branch only. I cannot
6759 guarantee that things will be fixed on the trunk in the near
6760 future.''
6761
6762 In case we have a problem, disable this breakpoint. We'll
6763 restore its status if we succeed. Don't disable a
6764 shlib_disabled breakpoint though. There's a fair chance we
6765 can't re-set it if the shared library it's in hasn't been
6766 loaded yet. */
b5de0fa7 6767 save_enable = b->enable_state;
b18c45ed
AC
6768 if (b->enable_state != bp_shlib_disabled)
6769 b->enable_state = bp_disabled;
c906108c
SS
6770
6771 set_language (b->language);
6772 input_radix = b->input_radix;
6773 s = b->addr_string;
c5aa993b 6774 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
6775 for (i = 0; i < sals.nelts; i++)
6776 {
6777 resolve_sal_pc (&sals.sals[i]);
6778
6779 /* Reparse conditions, they might contain references to the
6780 old symtab. */
6781 if (b->cond_string != NULL)
6782 {
6783 s = b->cond_string;
6784 if (b->cond)
b8c9b27d 6785 xfree (b->cond);
c906108c
SS
6786 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6787 }
6788
c5aa993b 6789 /* We need to re-set the breakpoint if the address changes... */
c906108c 6790 if (b->address != sals.sals[i].pc
c5aa993b
JM
6791 /* ...or new and old breakpoints both have source files, and
6792 the source file name or the line number changes... */
c906108c
SS
6793 || (b->source_file != NULL
6794 && sals.sals[i].symtab != NULL
6795 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6796 || b->line_number != sals.sals[i].line)
c906108c 6797 )
c5aa993b
JM
6798 /* ...or we switch between having a source file and not having
6799 one. */
6800 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6801 )
c906108c
SS
6802 {
6803 if (b->source_file != NULL)
b8c9b27d 6804 xfree (b->source_file);
c906108c
SS
6805 if (sals.sals[i].symtab == NULL)
6806 b->source_file = NULL;
6807 else
6808 b->source_file =
6809 savestring (sals.sals[i].symtab->filename,
6810 strlen (sals.sals[i].symtab->filename));
6811 b->line_number = sals.sals[i].line;
6812 b->address = sals.sals[i].pc;
6813
c5aa993b
JM
6814 /* Used to check for duplicates here, but that can
6815 cause trouble, as it doesn't check for disable
6816 breakpoints. */
c906108c
SS
6817
6818 mention (b);
6819
6820 /* Might be better to do this just once per breakpoint_re_set,
c5aa993b 6821 rather than once for every breakpoint. */
c906108c
SS
6822 breakpoints_changed ();
6823 }
6824 b->section = sals.sals[i].section;
b5de0fa7 6825 b->enable_state = save_enable; /* Restore it, this worked. */
c906108c
SS
6826
6827
c5aa993b 6828 /* Now that this is re-enabled, check_duplicates
c906108c 6829 can be used. */
9f60f21b 6830 check_duplicates (b);
c906108c
SS
6831
6832 }
b8c9b27d 6833 xfree (sals.sals);
c906108c
SS
6834 break;
6835
6836 case bp_watchpoint:
6837 case bp_hardware_watchpoint:
6838 case bp_read_watchpoint:
6839 case bp_access_watchpoint:
6840 innermost_block = NULL;
53a5351d
JM
6841 /* The issue arises of what context to evaluate this in. The
6842 same one as when it was set, but what does that mean when
6843 symbols have been re-read? We could save the filename and
6844 functionname, but if the context is more local than that, the
6845 best we could do would be something like how many levels deep
6846 and which index at that particular level, but that's going to
6847 be less stable than filenames or function names. */
6848
c906108c
SS
6849 /* So for now, just use a global context. */
6850 if (b->exp)
b8c9b27d 6851 xfree (b->exp);
c906108c
SS
6852 b->exp = parse_expression (b->exp_string);
6853 b->exp_valid_block = innermost_block;
6854 mark = value_mark ();
6855 if (b->val)
6856 value_free (b->val);
6857 b->val = evaluate_expression (b->exp);
6858 release_value (b->val);
6859 if (VALUE_LAZY (b->val))
6860 value_fetch_lazy (b->val);
6861
6862 if (b->cond_string != NULL)
6863 {
6864 s = b->cond_string;
6865 if (b->cond)
b8c9b27d 6866 xfree (b->cond);
c5aa993b 6867 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
c906108c 6868 }
b5de0fa7 6869 if (b->enable_state == bp_enabled)
c906108c
SS
6870 mention (b);
6871 value_free_to_mark (mark);
6872 break;
c5aa993b
JM
6873 case bp_catch_catch:
6874 case bp_catch_throw:
c906108c 6875 break;
c5aa993b
JM
6876 /* We needn't really do anything to reset these, since the mask
6877 that requests them is unaffected by e.g., new libraries being
6878 loaded. */
c906108c
SS
6879 case bp_catch_fork:
6880 case bp_catch_vfork:
6881 case bp_catch_exec:
6882 break;
c5aa993b 6883
c906108c
SS
6884 default:
6885 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6886 /* fall through */
c5aa993b
JM
6887 /* Delete longjmp breakpoints, they will be reset later by
6888 breakpoint_re_set. */
c906108c
SS
6889 case bp_longjmp:
6890 case bp_longjmp_resume:
6891 delete_breakpoint (b);
6892 break;
6893
c5aa993b
JM
6894 /* This breakpoint is special, it's set up when the inferior
6895 starts and we really don't want to touch it. */
c906108c
SS
6896 case bp_shlib_event:
6897
c4093a6a
JM
6898 /* Like bp_shlib_event, this breakpoint type is special.
6899 Once it is set up, we do not want to touch it. */
6900 case bp_thread_event:
6901
c5aa993b
JM
6902 /* Keep temporary breakpoints, which can be encountered when we step
6903 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6904 Otherwise these should have been blown away via the cleanup chain
6905 or by breakpoint_init_inferior when we rerun the executable. */
c906108c
SS
6906 case bp_until:
6907 case bp_finish:
6908 case bp_watchpoint_scope:
6909 case bp_call_dummy:
6910 case bp_step_resume:
6911 break;
6912 }
6913
6914 return 0;
6915}
6916
6917/* Re-set all breakpoints after symbols have been re-loaded. */
6918void
fba45db2 6919breakpoint_re_set (void)
c906108c
SS
6920{
6921 struct breakpoint *b, *temp;
6922 enum language save_language;
6923 int save_input_radix;
6924 static char message1[] = "Error in re-setting breakpoint %d:\n";
c5aa993b
JM
6925 char message[sizeof (message1) + 30 /* slop */ ];
6926
c906108c
SS
6927 save_language = current_language->la_language;
6928 save_input_radix = input_radix;
6929 ALL_BREAKPOINTS_SAFE (b, temp)
c5aa993b 6930 {
53a5351d
JM
6931 /* Format possible error msg */
6932 sprintf (message, message1, b->number);
c5aa993b
JM
6933 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6934 }
c906108c
SS
6935 set_language (save_language);
6936 input_radix = save_input_radix;
6937
6938#ifdef GET_LONGJMP_TARGET
6939 create_longjmp_breakpoint ("longjmp");
6940 create_longjmp_breakpoint ("_longjmp");
6941 create_longjmp_breakpoint ("siglongjmp");
6942 create_longjmp_breakpoint ("_siglongjmp");
6943 create_longjmp_breakpoint (NULL);
6944#endif
6945
6946#if 0
6947 /* Took this out (temporarily at least), since it produces an extra
6948 blank line at startup. This messes up the gdbtests. -PB */
6949 /* Blank line to finish off all those mention() messages we just printed. */
6950 printf_filtered ("\n");
6951#endif
6952}
6953\f
6954/* Set ignore-count of breakpoint number BPTNUM to COUNT.
6955 If from_tty is nonzero, it prints a message to that effect,
6956 which ends with a period (no newline). */
6957
6958/* Reset the thread number of this breakpoint:
6959
6960 - If the breakpoint is for all threads, leave it as-is.
39f77062 6961 - Else, reset it to the current thread for inferior_ptid. */
c906108c 6962void
fba45db2 6963breakpoint_re_set_thread (struct breakpoint *b)
c906108c
SS
6964{
6965 if (b->thread != -1)
6966 {
39f77062
KB
6967 if (in_thread_list (inferior_ptid))
6968 b->thread = pid_to_thread_id (inferior_ptid);
c906108c
SS
6969 }
6970}
6971
6972void
fba45db2 6973set_ignore_count (int bptnum, int count, int from_tty)
c906108c
SS
6974{
6975 register struct breakpoint *b;
6976
6977 if (count < 0)
6978 count = 0;
6979
6980 ALL_BREAKPOINTS (b)
6981 if (b->number == bptnum)
c5aa993b
JM
6982 {
6983 b->ignore_count = count;
6984 if (!from_tty)
c906108c 6985 return;
c5aa993b
JM
6986 else if (count == 0)
6987 printf_filtered ("Will stop next time breakpoint %d is reached.",
6988 bptnum);
6989 else if (count == 1)
6990 printf_filtered ("Will ignore next crossing of breakpoint %d.",
6991 bptnum);
6992 else
6993 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
6994 count, bptnum);
6995 breakpoints_changed ();
6996 return;
6997 }
c906108c
SS
6998
6999 error ("No breakpoint number %d.", bptnum);
7000}
7001
7002/* Clear the ignore counts of all breakpoints. */
7003void
fba45db2 7004breakpoint_clear_ignore_counts (void)
c906108c
SS
7005{
7006 struct breakpoint *b;
7007
7008 ALL_BREAKPOINTS (b)
7009 b->ignore_count = 0;
7010}
7011
7012/* Command to set ignore-count of breakpoint N to COUNT. */
7013
7014static void
fba45db2 7015ignore_command (char *args, int from_tty)
c906108c
SS
7016{
7017 char *p = args;
7018 register int num;
7019
7020 if (p == 0)
7021 error_no_arg ("a breakpoint number");
c5aa993b 7022
c906108c 7023 num = get_number (&p);
5c44784c
JM
7024 if (num == 0)
7025 error ("bad breakpoint number: '%s'", args);
c906108c
SS
7026 if (*p == 0)
7027 error ("Second argument (specified ignore-count) is missing.");
7028
7029 set_ignore_count (num,
7030 longest_to_int (value_as_long (parse_and_eval (p))),
7031 from_tty);
7032 printf_filtered ("\n");
7033 breakpoints_changed ();
7034}
7035\f
7036/* Call FUNCTION on each of the breakpoints
7037 whose numbers are given in ARGS. */
7038
7039static void
831662b3 7040map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
c906108c
SS
7041{
7042 register char *p = args;
7043 char *p1;
7044 register int num;
5c44784c 7045 register struct breakpoint *b, *tmp;
11cf8741 7046 int match;
c906108c
SS
7047
7048 if (p == 0)
7049 error_no_arg ("one or more breakpoint numbers");
7050
7051 while (*p)
7052 {
11cf8741 7053 match = 0;
c906108c 7054 p1 = p;
c5aa993b 7055
5c44784c
JM
7056 num = get_number_or_range (&p1);
7057 if (num == 0)
c5aa993b 7058 {
5c44784c
JM
7059 warning ("bad breakpoint number at or near '%s'", p);
7060 }
7061 else
7062 {
7063 ALL_BREAKPOINTS_SAFE (b, tmp)
7064 if (b->number == num)
7065 {
7066 struct breakpoint *related_breakpoint = b->related_breakpoint;
11cf8741 7067 match = 1;
5c44784c
JM
7068 function (b);
7069 if (related_breakpoint)
7070 function (related_breakpoint);
11cf8741 7071 break;
5c44784c 7072 }
11cf8741
JM
7073 if (match == 0)
7074 printf_unfiltered ("No breakpoint number %d.\n", num);
c5aa993b 7075 }
c906108c
SS
7076 p = p1;
7077 }
7078}
7079
7080void
fba45db2 7081disable_breakpoint (struct breakpoint *bpt)
c906108c
SS
7082{
7083 /* Never disable a watchpoint scope breakpoint; we want to
7084 hit them when we leave scope so we can delete both the
7085 watchpoint and its scope breakpoint at that time. */
7086 if (bpt->type == bp_watchpoint_scope)
7087 return;
7088
c2c6d25f 7089 /* You can't disable permanent breakpoints. */
b5de0fa7 7090 if (bpt->enable_state == bp_permanent)
c2c6d25f
JM
7091 return;
7092
b5de0fa7 7093 bpt->enable_state = bp_disabled;
c906108c 7094
9f60f21b 7095 check_duplicates (bpt);
c906108c
SS
7096
7097 if (modify_breakpoint_hook)
7098 modify_breakpoint_hook (bpt);
104c1213 7099 breakpoint_modify_event (bpt->number);
c906108c
SS
7100}
7101
7102/* ARGSUSED */
7103static void
fba45db2 7104disable_command (char *args, int from_tty)
c906108c
SS
7105{
7106 register struct breakpoint *bpt;
7107 if (args == 0)
7108 ALL_BREAKPOINTS (bpt)
7109 switch (bpt->type)
c5aa993b
JM
7110 {
7111 case bp_none:
53a5351d
JM
7112 warning ("attempted to disable apparently deleted breakpoint #%d?",
7113 bpt->number);
c5aa993b
JM
7114 continue;
7115 case bp_breakpoint:
7116 case bp_catch_load:
7117 case bp_catch_unload:
7118 case bp_catch_fork:
7119 case bp_catch_vfork:
7120 case bp_catch_exec:
7121 case bp_catch_catch:
7122 case bp_catch_throw:
7123 case bp_hardware_breakpoint:
7124 case bp_watchpoint:
7125 case bp_hardware_watchpoint:
7126 case bp_read_watchpoint:
7127 case bp_access_watchpoint:
7128 disable_breakpoint (bpt);
7129 default:
7130 continue;
7131 }
c906108c
SS
7132 else
7133 map_breakpoint_numbers (args, disable_breakpoint);
7134}
7135
7136static void
fba45db2 7137do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
c906108c
SS
7138{
7139 struct frame_info *save_selected_frame = NULL;
7140 int save_selected_frame_level = -1;
7141 int target_resources_ok, other_type_used;
7142 struct value *mark;
7143
7144 if (bpt->type == bp_hardware_breakpoint)
7145 {
7146 int i;
c5aa993b 7147 i = hw_breakpoint_used_count ();
53a5351d
JM
7148 target_resources_ok =
7149 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7150 i + 1, 0);
c906108c 7151 if (target_resources_ok == 0)
c5aa993b 7152 error ("No hardware breakpoint support in the target.");
c906108c 7153 else if (target_resources_ok < 0)
c5aa993b 7154 error ("Hardware breakpoints used exceeds limit.");
c906108c
SS
7155 }
7156
b5de0fa7
EZ
7157 if (bpt->enable_state != bp_permanent)
7158 bpt->enable_state = bp_enabled;
c906108c 7159 bpt->disposition = disposition;
9f60f21b 7160 check_duplicates (bpt);
c906108c
SS
7161 breakpoints_changed ();
7162
53a5351d
JM
7163 if (bpt->type == bp_watchpoint ||
7164 bpt->type == bp_hardware_watchpoint ||
7165 bpt->type == bp_read_watchpoint ||
7166 bpt->type == bp_access_watchpoint)
c906108c
SS
7167 {
7168 if (bpt->exp_valid_block != NULL)
7169 {
7170 struct frame_info *fr =
7171
c5aa993b
JM
7172 /* Ensure that we have the current frame. Else, this
7173 next query may pessimistically be answered as, "No,
7174 not within current scope". */
7175 get_current_frame ();
7176 fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
c906108c
SS
7177 if (fr == NULL)
7178 {
7179 printf_filtered ("\
7180Cannot enable watchpoint %d because the block in which its expression\n\
7181is valid is not currently in scope.\n", bpt->number);
b5de0fa7 7182 bpt->enable_state = bp_disabled;
c906108c
SS
7183 return;
7184 }
7185
7186 save_selected_frame = selected_frame;
7187 save_selected_frame_level = selected_frame_level;
7188 select_frame (fr, -1);
7189 }
7190
7191 value_free (bpt->val);
7192 mark = value_mark ();
7193 bpt->val = evaluate_expression (bpt->exp);
7194 release_value (bpt->val);
7195 if (VALUE_LAZY (bpt->val))
7196 value_fetch_lazy (bpt->val);
7197
7198 if (bpt->type == bp_hardware_watchpoint ||
c5aa993b
JM
7199 bpt->type == bp_read_watchpoint ||
7200 bpt->type == bp_access_watchpoint)
7201 {
7202 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7203 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7204
7205 /* Hack around 'unused var' error for some targets here */
7206 (void) mem_cnt, i;
7207 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7208 bpt->type, i + mem_cnt, other_type_used);
7209 /* we can consider of type is bp_hardware_watchpoint, convert to
7210 bp_watchpoint in the following condition */
7211 if (target_resources_ok < 0)
7212 {
7213 printf_filtered ("\
c906108c
SS
7214Cannot enable watchpoint %d because target watch resources\n\
7215have been allocated for other watchpoints.\n", bpt->number);
b5de0fa7 7216 bpt->enable_state = bp_disabled;
c5aa993b
JM
7217 value_free_to_mark (mark);
7218 return;
7219 }
7220 }
c906108c
SS
7221
7222 if (save_selected_frame_level >= 0)
c6902688 7223 select_frame (save_selected_frame, save_selected_frame_level);
c906108c
SS
7224 value_free_to_mark (mark);
7225 }
7226 if (modify_breakpoint_hook)
7227 modify_breakpoint_hook (bpt);
104c1213 7228 breakpoint_modify_event (bpt->number);
c906108c
SS
7229}
7230
7231void
fba45db2 7232enable_breakpoint (struct breakpoint *bpt)
c906108c
SS
7233{
7234 do_enable_breakpoint (bpt, bpt->disposition);
7235}
7236
7237/* The enable command enables the specified breakpoints (or all defined
7238 breakpoints) so they once again become (or continue to be) effective
7239 in stopping the inferior. */
7240
7241/* ARGSUSED */
7242static void
fba45db2 7243enable_command (char *args, int from_tty)
c906108c
SS
7244{
7245 register struct breakpoint *bpt;
7246 if (args == 0)
7247 ALL_BREAKPOINTS (bpt)
7248 switch (bpt->type)
c5aa993b
JM
7249 {
7250 case bp_none:
53a5351d
JM
7251 warning ("attempted to enable apparently deleted breakpoint #%d?",
7252 bpt->number);
c5aa993b
JM
7253 continue;
7254 case bp_breakpoint:
7255 case bp_catch_load:
7256 case bp_catch_unload:
7257 case bp_catch_fork:
7258 case bp_catch_vfork:
7259 case bp_catch_exec:
7260 case bp_catch_catch:
7261 case bp_catch_throw:
7262 case bp_hardware_breakpoint:
7263 case bp_watchpoint:
7264 case bp_hardware_watchpoint:
7265 case bp_read_watchpoint:
7266 case bp_access_watchpoint:
7267 enable_breakpoint (bpt);
7268 default:
7269 continue;
7270 }
c906108c
SS
7271 else
7272 map_breakpoint_numbers (args, enable_breakpoint);
7273}
7274
7275static void
fba45db2 7276enable_once_breakpoint (struct breakpoint *bpt)
c906108c 7277{
b5de0fa7 7278 do_enable_breakpoint (bpt, disp_disable);
c906108c
SS
7279}
7280
7281/* ARGSUSED */
7282static void
fba45db2 7283enable_once_command (char *args, int from_tty)
c906108c
SS
7284{
7285 map_breakpoint_numbers (args, enable_once_breakpoint);
7286}
7287
7288static void
fba45db2 7289enable_delete_breakpoint (struct breakpoint *bpt)
c906108c 7290{
b5de0fa7 7291 do_enable_breakpoint (bpt, disp_del);
c906108c
SS
7292}
7293
7294/* ARGSUSED */
7295static void
fba45db2 7296enable_delete_command (char *args, int from_tty)
c906108c
SS
7297{
7298 map_breakpoint_numbers (args, enable_delete_breakpoint);
7299}
7300\f
7301/* Use default_breakpoint_'s, or nothing if they aren't valid. */
7302
7303struct symtabs_and_lines
fba45db2 7304decode_line_spec_1 (char *string, int funfirstline)
c906108c
SS
7305{
7306 struct symtabs_and_lines sals;
7307 if (string == 0)
7308 error ("Empty line specification.");
7309 if (default_breakpoint_valid)
7310 sals = decode_line_1 (&string, funfirstline,
53a5351d
JM
7311 default_breakpoint_symtab,
7312 default_breakpoint_line,
c5aa993b 7313 (char ***) NULL);
c906108c
SS
7314 else
7315 sals = decode_line_1 (&string, funfirstline,
c5aa993b 7316 (struct symtab *) NULL, 0, (char ***) NULL);
c906108c
SS
7317 if (*string)
7318 error ("Junk at end of line specification: %s", string);
7319 return sals;
7320}
7321\f
7322void
fba45db2 7323_initialize_breakpoint (void)
c906108c
SS
7324{
7325 struct cmd_list_element *c;
7326
7327 breakpoint_chain = 0;
7328 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7329 before a breakpoint is set. */
7330 breakpoint_count = 0;
7331
7332 add_com ("ignore", class_breakpoint, ignore_command,
7333 "Set ignore-count of breakpoint number N to COUNT.\n\
7334Usage is `ignore N COUNT'.");
7335 if (xdb_commands)
c5aa993b 7336 add_com_alias ("bc", "ignore", class_breakpoint, 1);
c906108c
SS
7337
7338 add_com ("commands", class_breakpoint, commands_command,
7339 "Set commands to be executed when a breakpoint is hit.\n\
7340Give breakpoint number as argument after \"commands\".\n\
7341With no argument, the targeted breakpoint is the last one set.\n\
7342The commands themselves follow starting on the next line.\n\
7343Type a line containing \"end\" to indicate the end of them.\n\
7344Give \"silent\" as the first line to make the breakpoint silent;\n\
7345then no output is printed when it is hit, except what the commands print.");
7346
7347 add_com ("condition", class_breakpoint, condition_command,
7348 "Specify breakpoint number N to break only if COND is true.\n\
7349Usage is `condition N COND', where N is an integer and COND is an\n\
7350expression to be evaluated whenever breakpoint N is reached. ");
7351
c94fdfd0
EZ
7352 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7353 "Set a temporary breakpoint. Args like \"break\" command.\n\
c906108c
SS
7354Like \"break\" except the breakpoint is only temporary,\n\
7355so it will be deleted when hit. Equivalent to \"break\" followed\n\
7356by using \"enable delete\" on the breakpoint number.");
c94fdfd0
EZ
7357 c->completer = location_completer;
7358
7359 c = add_com ("txbreak", class_breakpoint, tbreak_at_finish_command,
7360 "Set temporary breakpoint at procedure exit. Either there should\n\
c906108c 7361be no argument or the argument must be a depth.\n");
c94fdfd0 7362 c->completer = location_completer;
c906108c 7363
c94fdfd0
EZ
7364 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7365 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
c906108c
SS
7366Like \"break\" except the breakpoint requires hardware support,\n\
7367some target hardware may not have this support.");
c94fdfd0 7368 c->completer = location_completer;
c906108c 7369
c94fdfd0
EZ
7370 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7371 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
c906108c
SS
7372Like \"hbreak\" except the breakpoint is only temporary,\n\
7373so it will be deleted when hit.");
c94fdfd0 7374 c->completer = location_completer;
c906108c
SS
7375
7376 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7377 "Enable some breakpoints.\n\
7378Give breakpoint numbers (separated by spaces) as arguments.\n\
7379With no subcommand, breakpoints are enabled until you command otherwise.\n\
7380This is used to cancel the effect of the \"disable\" command.\n\
7381With a subcommand you can enable temporarily.",
7382 &enablelist, "enable ", 1, &cmdlist);
7383 if (xdb_commands)
c5aa993b
JM
7384 add_com ("ab", class_breakpoint, enable_command,
7385 "Enable some breakpoints.\n\
c906108c
SS
7386Give breakpoint numbers (separated by spaces) as arguments.\n\
7387With no subcommand, breakpoints are enabled until you command otherwise.\n\
7388This is used to cancel the effect of the \"disable\" command.\n\
7389With a subcommand you can enable temporarily.");
7390
7391 add_com_alias ("en", "enable", class_breakpoint, 1);
7392
7393 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
c5aa993b 7394 "Enable some breakpoints.\n\
c906108c
SS
7395Give breakpoint numbers (separated by spaces) as arguments.\n\
7396This is used to cancel the effect of the \"disable\" command.\n\
7397May be abbreviated to simply \"enable\".\n",
c5aa993b 7398 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
c906108c
SS
7399
7400 add_cmd ("once", no_class, enable_once_command,
7401 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7402If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7403 &enablebreaklist);
7404
7405 add_cmd ("delete", no_class, enable_delete_command,
7406 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7407If a breakpoint is hit while enabled in this fashion, it is deleted.",
7408 &enablebreaklist);
7409
7410 add_cmd ("delete", no_class, enable_delete_command,
7411 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7412If a breakpoint is hit while enabled in this fashion, it is deleted.",
7413 &enablelist);
7414
7415 add_cmd ("once", no_class, enable_once_command,
7416 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7417If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7418 &enablelist);
7419
7420 add_prefix_cmd ("disable", class_breakpoint, disable_command,
c5aa993b 7421 "Disable some breakpoints.\n\
c906108c
SS
7422Arguments are breakpoint numbers with spaces in between.\n\
7423To disable all breakpoints, give no argument.\n\
7424A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7425 &disablelist, "disable ", 1, &cmdlist);
7426 add_com_alias ("dis", "disable", class_breakpoint, 1);
7427 add_com_alias ("disa", "disable", class_breakpoint, 1);
7428 if (xdb_commands)
c5aa993b
JM
7429 add_com ("sb", class_breakpoint, disable_command,
7430 "Disable some breakpoints.\n\
c906108c
SS
7431Arguments are breakpoint numbers with spaces in between.\n\
7432To disable all breakpoints, give no argument.\n\
7433A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7434
7435 add_cmd ("breakpoints", class_alias, disable_command,
7436 "Disable some breakpoints.\n\
7437Arguments are breakpoint numbers with spaces in between.\n\
7438To disable all breakpoints, give no argument.\n\
7439A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7440This command may be abbreviated \"disable\".",
7441 &disablelist);
7442
7443 add_prefix_cmd ("delete", class_breakpoint, delete_command,
c5aa993b 7444 "Delete some breakpoints or auto-display expressions.\n\
c906108c
SS
7445Arguments are breakpoint numbers with spaces in between.\n\
7446To delete all breakpoints, give no argument.\n\
7447\n\
7448Also a prefix command for deletion of other GDB objects.\n\
7449The \"unset\" command is also an alias for \"delete\".",
7450 &deletelist, "delete ", 1, &cmdlist);
7451 add_com_alias ("d", "delete", class_breakpoint, 1);
7452 if (xdb_commands)
7453 add_com ("db", class_breakpoint, delete_command,
c5aa993b 7454 "Delete some breakpoints.\n\
c906108c
SS
7455Arguments are breakpoint numbers with spaces in between.\n\
7456To delete all breakpoints, give no argument.\n");
7457
7458 add_cmd ("breakpoints", class_alias, delete_command,
7459 "Delete some breakpoints or auto-display expressions.\n\
7460Arguments are breakpoint numbers with spaces in between.\n\
7461To delete all breakpoints, give no argument.\n\
7462This command may be abbreviated \"delete\".",
7463 &deletelist);
7464
7465 add_com ("clear", class_breakpoint, clear_command,
7466 concat ("Clear breakpoint at specified line or function.\n\
7467Argument may be line number, function name, or \"*\" and an address.\n\
7468If line number is specified, all breakpoints in that line are cleared.\n\
7469If function is specified, breakpoints at beginning of function are cleared.\n\
7470If an address is specified, breakpoints at that address are cleared.\n\n",
c5aa993b 7471 "With no argument, clears all breakpoints in the line that the selected frame\n\
c906108c
SS
7472is executing in.\n\
7473\n\
7474See also the \"delete\" command which clears breakpoints by number.", NULL));
7475
c94fdfd0
EZ
7476 c = add_com ("break", class_breakpoint, break_command,
7477 concat ("Set breakpoint at specified line or function.\n\
c906108c
SS
7478Argument may be line number, function name, or \"*\" and an address.\n\
7479If line number is specified, break at start of code for that line.\n\
7480If function is specified, break at start of code for that function.\n\
7481If an address is specified, break at that exact address.\n",
c5aa993b 7482 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
7483This is useful for breaking on return to a stack frame.\n\
7484\n\
7485Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7486\n\
7487Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
c94fdfd0
EZ
7488 c->completer = location_completer;
7489
c906108c
SS
7490 add_com_alias ("b", "break", class_run, 1);
7491 add_com_alias ("br", "break", class_run, 1);
7492 add_com_alias ("bre", "break", class_run, 1);
7493 add_com_alias ("brea", "break", class_run, 1);
7494
c5aa993b
JM
7495 add_com ("xbreak", class_breakpoint, break_at_finish_command,
7496 concat ("Set breakpoint at procedure exit. \n\
c906108c
SS
7497Argument may be function name, or \"*\" and an address.\n\
7498If function is specified, break at end of code for that function.\n\
7499If an address is specified, break at the end of the function that contains \n\
7500that exact address.\n",
c5aa993b 7501 "With no arg, uses current execution address of selected stack frame.\n\
c906108c
SS
7502This is useful for breaking on return to a stack frame.\n\
7503\n\
7504Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7505\n\
7506Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7507 add_com_alias ("xb", "xbreak", class_breakpoint, 1);
7508 add_com_alias ("xbr", "xbreak", class_breakpoint, 1);
7509 add_com_alias ("xbre", "xbreak", class_breakpoint, 1);
7510 add_com_alias ("xbrea", "xbreak", class_breakpoint, 1);
7511
7512 if (xdb_commands)
7513 {
7514 add_com_alias ("ba", "break", class_breakpoint, 1);
7515 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7516 add_com ("bx", class_breakpoint, break_at_finish_at_depth_command,
c5aa993b 7517 "Set breakpoint at procedure exit. Either there should\n\
c906108c
SS
7518be no argument or the argument must be a depth.\n");
7519 }
7520
7521 if (dbx_commands)
7522 {
c5aa993b
JM
7523 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7524 "Break in function/address or break at a line in the current file.",
7525 &stoplist, "stop ", 1, &cmdlist);
7526 add_cmd ("in", class_breakpoint, stopin_command,
7527 "Break in function or address.\n", &stoplist);
7528 add_cmd ("at", class_breakpoint, stopat_command,
7529 "Break at a line in the current file.\n", &stoplist);
7530 add_com ("status", class_info, breakpoints_info,
7531 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
7532The \"Type\" column indicates one of:\n\
7533\tbreakpoint - normal breakpoint\n\
7534\twatchpoint - watchpoint\n\
7535The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
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 }
7544
7545 add_info ("breakpoints", breakpoints_info,
7546 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7547The \"Type\" column indicates one of:\n\
7548\tbreakpoint - normal breakpoint\n\
7549\twatchpoint - watchpoint\n\
7550The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7551the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7552breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7553address and file/line number respectively.\n\n",
c5aa993b 7554 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
7555are set to the address of the last breakpoint listed.\n\n\
7556Convenience variable \"$bpnum\" contains the number of the last\n\
7557breakpoint set.", NULL));
7558
7559 if (xdb_commands)
c5aa993b
JM
7560 add_com ("lb", class_breakpoint, breakpoints_info,
7561 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
7562The \"Type\" column indicates one of:\n\
7563\tbreakpoint - normal breakpoint\n\
7564\twatchpoint - watchpoint\n\
7565The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7566the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7567breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7568address and file/line number respectively.\n\n",
c5aa993b 7569 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
7570are set to the address of the last breakpoint listed.\n\n\
7571Convenience variable \"$bpnum\" contains the number of the last\n\
7572breakpoint set.", NULL));
7573
c906108c 7574 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
c5aa993b 7575 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
c906108c
SS
7576The \"Type\" column indicates one of:\n\
7577\tbreakpoint - normal breakpoint\n\
7578\twatchpoint - watchpoint\n\
7579\tlongjmp - internal breakpoint used to step through longjmp()\n\
7580\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7581\tuntil - internal breakpoint used by the \"until\" command\n\
7582\tfinish - internal breakpoint used by the \"finish\" command\n",
c5aa993b 7583 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
c906108c
SS
7584the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7585breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7586address and file/line number respectively.\n\n",
c5aa993b 7587 "Convenience variable \"$_\" and default examine address for \"x\"\n\
c906108c
SS
7588are set to the address of the last breakpoint listed.\n\n\
7589Convenience variable \"$bpnum\" contains the number of the last\n\
7590breakpoint set.", NULL),
7591 &maintenanceinfolist);
7592
c906108c 7593 add_com ("catch", class_breakpoint, catch_command,
c5aa993b 7594 "Set catchpoints to catch events.\n\
c906108c
SS
7595Raised signals may be caught:\n\
7596\tcatch signal - all signals\n\
7597\tcatch signal <signame> - a particular signal\n\
7598Raised exceptions may be caught:\n\
7599\tcatch throw - all exceptions, when thrown\n\
7600\tcatch throw <exceptname> - a particular exception, when thrown\n\
7601\tcatch catch - all exceptions, when caught\n\
7602\tcatch catch <exceptname> - a particular exception, when caught\n\
7603Thread or process events may be caught:\n\
7604\tcatch thread_start - any threads, just after creation\n\
7605\tcatch thread_exit - any threads, just before expiration\n\
7606\tcatch thread_join - any threads, just after joins\n\
7607Process events may be caught:\n\
7608\tcatch start - any processes, just after creation\n\
7609\tcatch exit - any processes, just before expiration\n\
7610\tcatch fork - calls to fork()\n\
7611\tcatch vfork - calls to vfork()\n\
7612\tcatch exec - calls to exec()\n\
7613Dynamically-linked library events may be caught:\n\
7614\tcatch load - loads of any library\n\
7615\tcatch load <libname> - loads of a particular library\n\
7616\tcatch unload - unloads of any library\n\
7617\tcatch unload <libname> - unloads of a particular library\n\
7618The act of your program's execution stopping may also be caught:\n\
7619\tcatch stop\n\n\
7620C++ exceptions may be caught:\n\
7621\tcatch throw - all exceptions, when thrown\n\
7622\tcatch catch - all exceptions, when caught\n\
7623\n\
7624Do \"help set follow-fork-mode\" for info on debugging your program\n\
7625after a fork or vfork is caught.\n\n\
7626Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
c5aa993b 7627
c906108c 7628 add_com ("tcatch", class_breakpoint, tcatch_command,
c5aa993b 7629 "Set temporary catchpoints to catch events.\n\
c906108c
SS
7630Args like \"catch\" command.\n\
7631Like \"catch\" except the catchpoint is only temporary,\n\
7632so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7633by using \"enable delete\" on the catchpoint number.");
c5aa993b 7634
c94fdfd0
EZ
7635 c = add_com ("watch", class_breakpoint, watch_command,
7636 "Set a watchpoint for an expression.\n\
c906108c
SS
7637A watchpoint stops execution of your program whenever the value of\n\
7638an expression changes.");
c94fdfd0 7639 c->completer = location_completer;
c906108c 7640
c94fdfd0
EZ
7641 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7642 "Set a read watchpoint for an expression.\n\
c906108c
SS
7643A watchpoint stops execution of your program whenever the value of\n\
7644an expression is read.");
c94fdfd0 7645 c->completer = location_completer;
c906108c 7646
c94fdfd0
EZ
7647 c = add_com ("awatch", class_breakpoint, awatch_command,
7648 "Set a watchpoint for an expression.\n\
c906108c
SS
7649A watchpoint stops execution of your program whenever the value of\n\
7650an expression is either read or written.");
c94fdfd0 7651 c->completer = location_completer;
c906108c
SS
7652
7653 add_info ("watchpoints", breakpoints_info,
7654 "Synonym for ``info breakpoints''.");
7655
7656
7657 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
c5aa993b
JM
7658 (char *) &can_use_hw_watchpoints,
7659 "Set debugger's willingness to use watchpoint hardware.\n\
c906108c
SS
7660If zero, gdb will not use hardware for new watchpoints, even if\n\
7661such is available. (However, any hardware watchpoints that were\n\
7662created before setting this to nonzero, will continue to use watchpoint\n\
7663hardware.)",
c5aa993b 7664 &setlist);
c906108c
SS
7665 add_show_from_set (c, &showlist);
7666
7667 can_use_hw_watchpoints = 1;
7668}
This page took 0.548037 seconds and 4 git commands to generate.