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