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