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