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