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