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