* value.c (value_virtual_fn_field): Handle the situation where
[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
92fb1f2e 44static void catch_command_1 PARAMS ((char *, int, int));
30875e1c 45
92fb1f2e 46static void enable_delete_command PARAMS ((char *, int));
30875e1c 47
92fb1f2e 48static void enable_delete_breakpoint PARAMS ((struct breakpoint *));
30875e1c 49
92fb1f2e 50static void enable_once_command PARAMS ((char *, int));
30875e1c 51
92fb1f2e 52static void enable_once_breakpoint PARAMS ((struct breakpoint *));
30875e1c 53
92fb1f2e 54static void disable_command PARAMS ((char *, int));
30875e1c 55
92fb1f2e 56static void enable_command PARAMS ((char *, int));
30875e1c 57
92fb1f2e
SS
58static void map_breakpoint_numbers PARAMS ((char *,
59 void (*)(struct breakpoint *)));
30875e1c 60
92fb1f2e 61static void ignore_command PARAMS ((char *, int));
30875e1c 62
92fb1f2e 63static int breakpoint_re_set_one PARAMS ((char *));
30875e1c 64
92fb1f2e 65static void clear_command PARAMS ((char *, int));
30875e1c 66
92fb1f2e 67static void catch_command PARAMS ((char *, int));
30875e1c 68
92fb1f2e 69static struct symtabs_and_lines get_catch_sals PARAMS ((int));
30875e1c 70
92fb1f2e 71static void watch_command PARAMS ((char *, int));
30875e1c 72
92fb1f2e 73static int can_use_hardware_watchpoint PARAMS ((struct value *));
999dd04b 74
92fb1f2e 75static void tbreak_command PARAMS ((char *, int));
30875e1c 76
92fb1f2e 77static void break_command_1 PARAMS ((char *, int, int));
30875e1c 78
92fb1f2e 79static void mention PARAMS ((struct breakpoint *));
30875e1c 80
92fb1f2e 81struct breakpoint *set_raw_breakpoint PARAMS ((struct symtab_and_line));
30875e1c 82
92fb1f2e 83static void check_duplicates PARAMS ((CORE_ADDR, asection *));
30875e1c 84
92fb1f2e 85static void describe_other_breakpoints PARAMS ((CORE_ADDR, asection *));
30875e1c 86
92fb1f2e 87static void breakpoints_info PARAMS ((char *, int));
30875e1c 88
92fb1f2e 89static void breakpoint_1 PARAMS ((int, int));
30875e1c 90
92fb1f2e 91static bpstat bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
30875e1c 92
92fb1f2e 93static int breakpoint_cond_eval PARAMS ((char *));
30875e1c 94
92fb1f2e 95static void cleanup_executing_breakpoints PARAMS ((PTR));
30875e1c 96
92fb1f2e 97static void commands_command PARAMS ((char *, int));
30875e1c 98
92fb1f2e 99static void condition_command PARAMS ((char *, int));
30875e1c 100
92fb1f2e 101static int get_number PARAMS ((char **));
30875e1c 102
92fb1f2e 103static int remove_breakpoint PARAMS ((struct breakpoint *));
30875e1c 104
92fb1f2e 105static int print_it_normal PARAMS ((bpstat));
b607efe7 106
92fb1f2e 107static int watchpoint_check PARAMS ((char *));
b607efe7 108
92fb1f2e 109static int print_it_done PARAMS ((bpstat));
b607efe7 110
92fb1f2e 111static int print_it_noop PARAMS ((bpstat));
b607efe7 112
92fb1f2e 113static void maintenance_info_breakpoints PARAMS ((char *, int));
b607efe7
FF
114
115#ifdef GET_LONGJMP_TARGET
92fb1f2e 116static void create_longjmp_breakpoint PARAMS ((char *));
b607efe7
FF
117#endif
118
92fb1f2e 119static int hw_breakpoint_used_count PARAMS ((void));
b607efe7 120
92fb1f2e 121static int hw_watchpoint_used_count PARAMS ((enum bptype, int *));
b607efe7 122
92fb1f2e 123static void hbreak_command PARAMS ((char *, int));
b607efe7 124
92fb1f2e 125static void thbreak_command PARAMS ((char *, int));
b607efe7 126
92fb1f2e 127static void watch_command_1 PARAMS ((char *, int, int));
b607efe7 128
92fb1f2e 129static void rwatch_command PARAMS ((char *, int));
b607efe7 130
92fb1f2e 131static void awatch_command PARAMS ((char *, int));
b607efe7 132
92fb1f2e
SS
133static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp));
134
135/* Prototypes for exported functions. */
136
137void delete_command PARAMS ((char *, int));
138
139void _initialize_breakpoint PARAMS ((void));
140
141void set_breakpoint_count PARAMS ((int));
b607efe7 142
bd5635a1 143extern int addressprint; /* Print machine addresses? */
bd5635a1 144
6b038bd9
DT
145#if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD)
146static int internal_breakpoint_number = -1;
147#endif
148
bd5635a1
RP
149/* Are we executing breakpoint commands? */
150static int executing_breakpoint_commands;
151
cba0d141
JG
152/* Walk the following statement or block through all breakpoints.
153 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
154 breakpoint. */
155
bd5635a1
RP
156#define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
157
cba0d141
JG
158#define ALL_BREAKPOINTS_SAFE(b,tmp) \
159 for (b = breakpoint_chain; \
160 b? (tmp=b->next, 1): 0; \
161 b = tmp)
162
6b038bd9
DT
163/* True if SHIFT_INST_REGS defined, false otherwise. */
164
165int must_shift_inst_regs =
166#if defined(SHIFT_INST_REGS)
1671
168#else
1690
170#endif
171;
172
9f577285
SS
173/* True if breakpoint hit counts should be displayed in breakpoint info. */
174
175int show_breakpoint_hit_counts = 1;
176
bd5635a1
RP
177/* Chain of all breakpoints defined. */
178
e8bf33c4 179struct breakpoint *breakpoint_chain;
bd5635a1
RP
180
181/* Number of last breakpoint made. */
182
895cc8ab 183int breakpoint_count;
bd5635a1
RP
184
185/* Set breakpoint count to NUM. */
9f577285 186
895cc8ab 187void
bd5635a1
RP
188set_breakpoint_count (num)
189 int num;
190{
191 breakpoint_count = num;
192 set_internalvar (lookup_internalvar ("bpnum"),
06b6c733 193 value_from_longest (builtin_type_int, (LONGEST) num));
bd5635a1
RP
194}
195
9f577285
SS
196/* Used in run_command to zero the hit count when a new run starts. */
197
198void
199clear_breakpoint_hit_counts ()
200{
201 struct breakpoint *b;
202
203 ALL_BREAKPOINTS (b)
204 b->hit_count = 0;
205}
206
bd5635a1
RP
207/* Default address, symtab and line to put a breakpoint at
208 for "break" command with no arg.
209 if default_breakpoint_valid is zero, the other three are
210 not valid, and "break" with no arg is an error.
211
212 This set by print_stack_frame, which calls set_default_breakpoint. */
213
214int default_breakpoint_valid;
215CORE_ADDR default_breakpoint_address;
216struct symtab *default_breakpoint_symtab;
217int default_breakpoint_line;
bd5635a1
RP
218\f
219/* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
220 Advance *PP after the string and any trailing whitespace.
221
222 Currently the string can either be a number or "$" followed by the name
223 of a convenience variable. Making it an expression wouldn't work well
224 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
225static int
226get_number (pp)
227 char **pp;
228{
229 int retval;
230 char *p = *pp;
231
232 if (p == NULL)
233 /* Empty line means refer to the last breakpoint. */
234 return breakpoint_count;
235 else if (*p == '$')
236 {
237 /* Make a copy of the name, so we can null-terminate it
238 to pass to lookup_internalvar(). */
239 char *varname;
240 char *start = ++p;
82a2edfb 241 value_ptr val;
bd5635a1
RP
242
243 while (isalnum (*p) || *p == '_')
244 p++;
245 varname = (char *) alloca (p - start + 1);
246 strncpy (varname, start, p - start);
247 varname[p - start] = '\0';
248 val = value_of_internalvar (lookup_internalvar (varname));
249 if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
250 error (
251"Convenience variables used to specify breakpoints must have integer values."
252 );
253 retval = (int) value_as_long (val);
254 }
255 else
256 {
80ba48f5
SG
257 if (*p == '-')
258 ++p;
bd5635a1
RP
259 while (*p >= '0' && *p <= '9')
260 ++p;
261 if (p == *pp)
262 /* There is no number here. (e.g. "cond a == b"). */
263 error_no_arg ("breakpoint number");
264 retval = atoi (*pp);
265 }
266 if (!(isspace (*p) || *p == '\0'))
267 error ("breakpoint number expected");
268 while (isspace (*p))
269 p++;
270 *pp = p;
271 return retval;
272}
273\f
274/* condition N EXP -- set break condition of breakpoint N to EXP. */
275
276static void
277condition_command (arg, from_tty)
278 char *arg;
279 int from_tty;
280{
281 register struct breakpoint *b;
282 char *p;
283 register int bnum;
284
285 if (arg == 0)
286 error_no_arg ("breakpoint number");
287
288 p = arg;
289 bnum = get_number (&p);
290
291 ALL_BREAKPOINTS (b)
292 if (b->number == bnum)
293 {
294 if (b->cond)
295 {
c8950965 296 free ((PTR)b->cond);
bd5635a1
RP
297 b->cond = 0;
298 }
299 if (b->cond_string != NULL)
c8950965 300 free ((PTR)b->cond_string);
bd5635a1
RP
301
302 if (*p == 0)
303 {
304 b->cond = 0;
305 b->cond_string = NULL;
306 if (from_tty)
423e9664 307 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
bd5635a1
RP
308 }
309 else
310 {
311 arg = p;
312 /* I don't know if it matters whether this is the string the user
313 typed in or the decompiled expression. */
314 b->cond_string = savestring (arg, strlen (arg));
d3b9c0df 315 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
bd5635a1
RP
316 if (*arg)
317 error ("Junk at end of expression");
318 }
16726dd1 319 breakpoints_changed ();
bd5635a1
RP
320 return;
321 }
322
323 error ("No breakpoint number %d.", bnum);
324}
325
bdbd5f50 326/* ARGSUSED */
bd5635a1
RP
327static void
328commands_command (arg, from_tty)
329 char *arg;
330 int from_tty;
331{
332 register struct breakpoint *b;
333 char *p;
334 register int bnum;
335 struct command_line *l;
336
337 /* If we allowed this, we would have problems with when to
338 free the storage, if we change the commands currently
339 being read from. */
340
341 if (executing_breakpoint_commands)
342 error ("Can't use the \"commands\" command among a breakpoint's commands.");
343
344 p = arg;
345 bnum = get_number (&p);
346 if (p && *p)
347 error ("Unexpected extra arguments following breakpoint number.");
348
349 ALL_BREAKPOINTS (b)
350 if (b->number == bnum)
351 {
41756e56
FF
352 char tmpbuf[128];
353 sprintf (tmpbuf, "Type commands for when breakpoint %d is hit, one per line.", bnum);
354 l = read_command_lines (tmpbuf, from_tty);
bd5635a1
RP
355 free_command_lines (&b->commands);
356 b->commands = l;
6c803036 357 breakpoints_changed ();
bd5635a1
RP
358 return;
359 }
360 error ("No breakpoint number %d.", bnum);
361}
362\f
31ef19fc
JK
363extern int memory_breakpoint_size; /* from mem-break.c */
364
365/* Like target_read_memory() but if breakpoints are inserted, return
30875e1c
SG
366 the shadow contents instead of the breakpoints themselves.
367
368 Read "memory data" from whatever target or inferior we have.
369 Returns zero if successful, errno value if not. EIO is used
370 for address out of bounds. If breakpoints are inserted, returns
371 shadow contents, not the breakpoints themselves. From breakpoint.c. */
372
31ef19fc
JK
373int
374read_memory_nobpt (memaddr, myaddr, len)
375 CORE_ADDR memaddr;
376 char *myaddr;
377 unsigned len;
378{
379 int status;
380 struct breakpoint *b;
381
382 if (memory_breakpoint_size < 0)
5af4f5f6
JK
383 /* No breakpoints on this machine. FIXME: This should be
384 dependent on the debugging target. Probably want
385 target_insert_breakpoint to return a size, saying how many
386 bytes of the shadow contents are used, or perhaps have
387 something like target_xfer_shadow. */
31ef19fc
JK
388 return target_read_memory (memaddr, myaddr, len);
389
390 ALL_BREAKPOINTS (b)
391 {
999dd04b
JL
392 if (b->type == bp_watchpoint
393 || b->type == bp_hardware_watchpoint
11054881
KH
394 || b->type == bp_read_watchpoint
395 || b->type == bp_access_watchpoint
999dd04b 396 || !b->inserted)
31ef19fc
JK
397 continue;
398 else if (b->address + memory_breakpoint_size <= memaddr)
399 /* The breakpoint is entirely before the chunk of memory
400 we are reading. */
401 continue;
402 else if (b->address >= memaddr + len)
403 /* The breakpoint is entirely after the chunk of memory we
404 are reading. */
405 continue;
406 else
407 {
408 /* Copy the breakpoint from the shadow contents, and recurse
409 for the things before and after. */
410
411 /* Addresses and length of the part of the breakpoint that
412 we need to copy. */
413 CORE_ADDR membpt = b->address;
414 unsigned int bptlen = memory_breakpoint_size;
415 /* Offset within shadow_contents. */
416 int bptoffset = 0;
417
418 if (membpt < memaddr)
419 {
420 /* Only copy the second part of the breakpoint. */
421 bptlen -= memaddr - membpt;
422 bptoffset = memaddr - membpt;
423 membpt = memaddr;
424 }
425
426 if (membpt + bptlen > memaddr + len)
427 {
428 /* Only copy the first part of the breakpoint. */
429 bptlen -= (membpt + bptlen) - (memaddr + len);
430 }
431
4ed3a9ea
FF
432 memcpy (myaddr + membpt - memaddr,
433 b->shadow_contents + bptoffset, bptlen);
31ef19fc
JK
434
435 if (membpt > memaddr)
436 {
437 /* Copy the section of memory before the breakpoint. */
438 status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
439 if (status != 0)
440 return status;
441 }
442
443 if (membpt + bptlen < memaddr + len)
444 {
445 /* Copy the section of memory after the breakpoint. */
446 status = read_memory_nobpt
447 (membpt + bptlen,
448 myaddr + membpt + bptlen - memaddr,
449 memaddr + len - (membpt + bptlen));
450 if (status != 0)
451 return status;
452 }
453 return 0;
454 }
455 }
456 /* Nothing overlaps. Just call read_memory_noerr. */
457 return target_read_memory (memaddr, myaddr, len);
458}
459\f
bd5635a1
RP
460/* insert_breakpoints is used when starting or continuing the program.
461 remove_breakpoints is used when the program stops.
462 Both return zero if successful,
463 or an `errno' value if could not write the inferior. */
464
465int
466insert_breakpoints ()
467{
fa3764e2 468 register struct breakpoint *b, *temp;
bd5635a1
RP
469 int val = 0;
470 int disabled_breaks = 0;
471
fa3764e2 472 ALL_BREAKPOINTS_SAFE (b, temp)
30875e1c 473 if (b->type != bp_watchpoint
999dd04b 474 && b->type != bp_hardware_watchpoint
11054881
KH
475 && b->type != bp_read_watchpoint
476 && b->type != bp_access_watchpoint
bd5635a1 477 && b->enable != disabled
fa3764e2 478 && b->enable != shlib_disabled
bd5635a1
RP
479 && ! b->inserted
480 && ! b->duplicate)
481 {
11054881
KH
482 if (b->type == bp_hardware_breakpoint)
483 val = target_insert_hw_breakpoint(b->address, b->shadow_contents);
484 else
6b038bd9
DT
485 {
486 /* Check to see if breakpoint is in an overlay section;
487 if so, we should set the breakpoint at the LMA address.
488 Only if the section is currently mapped should we ALSO
489 set a break at the VMA address. */
490 if (overlay_debugging && b->section &&
491 section_is_overlay (b->section))
492 {
493 CORE_ADDR addr;
494
495 addr = overlay_unmapped_address (b->address, b->section);
496 val = target_insert_breakpoint (addr, b->shadow_contents);
497 /* This would be the time to check val, to see if the
498 breakpoint write to the load address succeeded.
499 However, this might be an ordinary occurrance, eg. if
500 the unmapped overlay is in ROM. */
501 val = 0; /* in case unmapped address failed */
502 if (section_is_mapped (b->section))
503 val = target_insert_breakpoint (b->address,
504 b->shadow_contents);
505 }
506 else /* ordinary (non-overlay) address */
507 val = target_insert_breakpoint(b->address, b->shadow_contents);
508 }
bd5635a1
RP
509 if (val)
510 {
511 /* Can't set the breakpoint. */
512#if defined (DISABLE_UNSETTABLE_BREAK)
513 if (DISABLE_UNSETTABLE_BREAK (b->address))
514 {
515 val = 0;
fa3764e2 516 b->enable = shlib_disabled;
bd5635a1
RP
517 if (!disabled_breaks)
518 {
05052b63 519 target_terminal_ours_for_output ();
199b2450 520 fprintf_unfiltered (gdb_stderr,
2d313932 521 "Cannot insert breakpoint %d:\n", b->number);
fa3764e2 522 printf_filtered ("Temporarily disabling shared library breakpoints:\n");
bd5635a1
RP
523 }
524 disabled_breaks = 1;
525 printf_filtered ("%d ", b->number);
526 }
527 else
528#endif
529 {
05052b63 530 target_terminal_ours_for_output ();
199b2450 531 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
d3b9c0df 532#ifdef ONE_PROCESS_WRITETEXT
199b2450 533 fprintf_unfiltered (gdb_stderr,
2d313932 534 "The same program may be running in another process.\n");
d3b9c0df 535#endif
bd5635a1
RP
536 memory_error (val, b->address); /* which bombs us out */
537 }
538 }
539 else
540 b->inserted = 1;
541 }
11054881
KH
542 else if ((b->type == bp_hardware_watchpoint ||
543 b->type == bp_read_watchpoint ||
544 b->type == bp_access_watchpoint)
999dd04b
JL
545 && b->enable == enabled
546 && ! b->inserted
547 && ! b->duplicate)
548 {
706dc3ce 549 struct frame_info *saved_frame;
999dd04b
JL
550 int saved_level, within_current_scope;
551 value_ptr mark = value_mark ();
552 value_ptr v;
553
554 /* Save the current frame and level so we can restore it after
555 evaluating the watchpoint expression on its own frame. */
556 saved_frame = selected_frame;
557 saved_level = selected_frame_level;
558
559 /* Determine if the watchpoint is within scope. */
560 if (b->exp_valid_block == NULL)
561 within_current_scope = 1;
562 else
563 {
6b038bd9
DT
564 struct frame_info *fi;
565
566 /* There might be no current frame at this moment if we are
567 resuming from a step over a breakpoint.
568 Set up current frame before trying to find the watchpoint
569 frame. */
570 get_current_frame ();
571 fi = find_frame_addr_in_frame_chain (b->watchpoint_frame);
706dc3ce 572 within_current_scope = (fi != NULL);
999dd04b 573 if (within_current_scope)
706dc3ce 574 select_frame (fi, -1);
999dd04b
JL
575 }
576
577 if (within_current_scope)
578 {
579 /* Evaluate the expression and cut the chain of values
580 produced off from the value chain. */
581 v = evaluate_expression (b->exp);
582 value_release_to_mark (mark);
583
584 b->val_chain = v;
585 b->inserted = 1;
586
587 /* Look at each value on the value chain. */
588 for ( ; v; v=v->next)
589 {
590 /* If it's a memory location, then we must watch it. */
591 if (v->lval == lval_memory)
592 {
11054881 593 int addr, len, type;
999dd04b
JL
594
595 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
596 len = TYPE_LENGTH (VALUE_TYPE (v));
11054881
KH
597 type = 0;
598 if (b->type == bp_read_watchpoint)
599 type = 1;
600 else if (b->type == bp_access_watchpoint)
601 type = 2;
602
603 val = target_insert_watchpoint (addr, len, type);
999dd04b
JL
604 if (val == -1)
605 {
606 b->inserted = 0;
607 break;
608 }
609 val = 0;
610 }
611 }
612 /* Failure to insert a watchpoint on any memory value in the
613 value chain brings us here. */
614 if (!b->inserted)
615 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
616 b->number);
617 }
618 else
619 {
620 printf_filtered ("\
621Hardware watchpoint %d deleted because the program has left the block in\n\
622which its expression is valid.\n", b->number);
623 if (b->related_breakpoint)
6b038bd9 624 b->related_breakpoint->disposition = del_at_next_stop;
e51481f9 625 b->disposition = del_at_next_stop;
999dd04b
JL
626 }
627
628 /* Restore the frame and level. */
629 select_frame (saved_frame, saved_level);
630 }
bd5635a1
RP
631 if (disabled_breaks)
632 printf_filtered ("\n");
633 return val;
634}
635
999dd04b 636
bd5635a1
RP
637int
638remove_breakpoints ()
639{
640 register struct breakpoint *b;
641 int val;
642
bd5635a1 643 ALL_BREAKPOINTS (b)
999dd04b
JL
644 {
645 if (b->inserted)
646 {
647 val = remove_breakpoint (b);
648 if (val != 0)
649 return val;
650 }
651 }
652 return 0;
653}
bd5635a1 654
999dd04b
JL
655
656static int
657remove_breakpoint (b)
658 struct breakpoint *b;
659{
660 int val;
661
662 if (b->type != bp_watchpoint
11054881
KH
663 && b->type != bp_hardware_watchpoint
664 && b->type != bp_read_watchpoint
665 && b->type != bp_access_watchpoint)
999dd04b 666 {
11054881
KH
667 if (b->type == bp_hardware_breakpoint)
668 val = target_remove_hw_breakpoint(b->address, b->shadow_contents);
669 else
6b038bd9
DT
670 {
671 /* Check to see if breakpoint is in an overlay section;
672 if so, we should remove the breakpoint at the LMA address.
673 If that is not equal to the raw address, then we should
674 presumable remove the breakpoint there as well. */
675 if (overlay_debugging && b->section &&
676 section_is_overlay (b->section))
677 {
678 CORE_ADDR addr;
679
680 addr = overlay_unmapped_address (b->address, b->section);
681 val = target_remove_breakpoint (addr, b->shadow_contents);
682 /* This would be the time to check val, to see if the
683 shadow breakpoint write to the load address succeeded.
684 However, this might be an ordinary occurrance, eg. if
685 the unmapped overlay is in ROM. */
686 val = 0; /* in case unmapped address failed */
687 if (section_is_mapped (b->section))
688 val = target_remove_breakpoint (b->address,
689 b->shadow_contents);
690 }
691 else /* ordinary (non-overlay) address */
692 val = target_remove_breakpoint(b->address, b->shadow_contents);
693 }
999dd04b
JL
694 if (val)
695 return val;
696 b->inserted = 0;
697 }
11054881
KH
698 else if ((b->type == bp_hardware_watchpoint ||
699 b->type == bp_read_watchpoint ||
700 b->type == bp_access_watchpoint)
999dd04b
JL
701 && b->enable == enabled
702 && ! b->duplicate)
703 {
704 value_ptr v, n;
705
706 b->inserted = 0;
707 /* Walk down the saved value chain. */
708 for (v = b->val_chain; v; v = v->next)
709 {
710 /* For each memory reference remove the watchpoint
711 at that address. */
712 if (v->lval == lval_memory)
713 {
6b038bd9 714 int addr, len, type;
999dd04b
JL
715
716 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
717 len = TYPE_LENGTH (VALUE_TYPE (v));
6b038bd9
DT
718 type = 0;
719 if (b->type == bp_read_watchpoint)
720 type = 1;
721 else if (b->type == bp_access_watchpoint)
722 type = 2;
723
724 val = target_remove_watchpoint (addr, len, type);
999dd04b
JL
725 if (val == -1)
726 b->inserted = 1;
727 val = 0;
728 }
729 }
730 /* Failure to remove any of the hardware watchpoints comes here. */
731 if (b->inserted)
0fe1522a
SG
732 warning ("Hardware watchpoint %d: Could not remove watchpoint\n",
733 b->number);
999dd04b
JL
734
735 /* Free the saved value chain. We will construct a new one
736 the next time the watchpoint is inserted. */
737 for (v = b->val_chain; v; v = n)
738 {
739 n = v->next;
740 value_free (v);
741 }
742 b->val_chain = NULL;
743 }
bd5635a1
RP
744 return 0;
745}
746
cf3e377e 747/* Clear the "inserted" flag in all breakpoints. */
bd5635a1
RP
748
749void
750mark_breakpoints_out ()
751{
752 register struct breakpoint *b;
753
754 ALL_BREAKPOINTS (b)
755 b->inserted = 0;
756}
757
cf3e377e
JK
758/* Clear the "inserted" flag in all breakpoints and delete any breakpoints
759 which should go away between runs of the program. */
760
761void
762breakpoint_init_inferior ()
763{
764 register struct breakpoint *b, *temp;
765
766 ALL_BREAKPOINTS_SAFE (b, temp)
767 {
768 b->inserted = 0;
769
e51481f9
JL
770 switch (b->type)
771 {
772 case bp_call_dummy:
773 case bp_watchpoint_scope:
999dd04b 774
e51481f9
JL
775 /* If the call dummy breakpoint is at the entry point it will
776 cause problems when the inferior is rerun, so we better
777 get rid of it.
999dd04b 778
e51481f9
JL
779 Also get rid of scope breakpoints. */
780 delete_breakpoint (b);
781 break;
782
783 case bp_watchpoint:
784 case bp_hardware_watchpoint:
785 case bp_read_watchpoint:
786 case bp_access_watchpoint:
787
788 /* Likewise for watchpoints on local expressions. */
789 if (b->exp_valid_block != NULL)
790 delete_breakpoint (b);
791 break;
792
793 default:
794 break;
795 }
cf3e377e
JK
796 }
797}
798
bd5635a1
RP
799/* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
800 When continuing from a location with a breakpoint,
801 we actually single step once before calling insert_breakpoints. */
802
803int
804breakpoint_here_p (pc)
805 CORE_ADDR pc;
806{
807 register struct breakpoint *b;
808
809 ALL_BREAKPOINTS (b)
6b038bd9
DT
810 if (b->enable == enabled
811 && b->address == pc) /* bp is enabled and matches pc */
ad3b8c4a
JM
812 {
813 if (overlay_debugging &&
814 section_is_overlay (b->section) &&
815 !section_is_mapped (b->section))
816 continue; /* unmapped overlay -- can't be a match */
817 else
818 return 1;
819 }
6b038bd9
DT
820
821 return 0;
822}
823
824/* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(), but it
825 only returns true if there is actually a breakpoint inserted at PC. */
826
827int
828breakpoint_inserted_here_p (pc)
829 CORE_ADDR pc;
830{
831 register struct breakpoint *b;
832
833 ALL_BREAKPOINTS (b)
834 if (b->inserted
835 && b->address == pc) /* bp is inserted and matches pc */
ad3b8c4a
JM
836 {
837 if (overlay_debugging &&
838 section_is_overlay (b->section) &&
839 !section_is_mapped (b->section))
840 continue; /* unmapped overlay -- can't be a match */
841 else
842 return 1;
843 }
bd5635a1
RP
844
845 return 0;
846}
199b2450 847
05052b63
JK
848/* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
849 because figuring out the saved SP would take too much time, at least using
850 get_saved_register on the 68k. This means that for this function to
851 work right a port must use the bp_call_dummy breakpoint. */
852
853int
854frame_in_dummy (frame)
706dc3ce 855 struct frame_info *frame;
05052b63 856{
6b038bd9
DT
857#ifdef CALL_DUMMY
858#ifdef USE_GENERIC_DUMMY_FRAMES
859 return generic_pc_in_call_dummy (frame->pc, frame->frame);
860#else
05052b63
JK
861 struct breakpoint *b;
862
863 ALL_BREAKPOINTS (b)
864 {
6b038bd9 865 static ULONGEST dummy[] = CALL_DUMMY;
d7e7e851 866
05052b63 867 if (b->type == bp_call_dummy
d7e7e851
JK
868 && b->frame == frame->frame
869
870 /* We need to check the PC as well as the frame on the sparc,
871 for signals.exp in the testsuite. */
872 && (frame->pc
873 >= (b->address
874 - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE))
875 && frame->pc <= b->address)
05052b63
JK
876 return 1;
877 }
6b038bd9 878#endif /* GENERIC_DUMMY_FRAMES */
d7e7e851 879#endif /* CALL_DUMMY */
05052b63
JK
880 return 0;
881}
882
199b2450
TL
883/* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
884 is valid for process/thread PID. */
885
886int
887breakpoint_thread_match (pc, pid)
888 CORE_ADDR pc;
889 int pid;
890{
891 struct breakpoint *b;
892 int thread;
893
894 thread = pid_to_thread_id (pid);
895
896 ALL_BREAKPOINTS (b)
897 if (b->enable != disabled
fa3764e2 898 && b->enable != shlib_disabled
199b2450
TL
899 && b->address == pc
900 && (b->thread == -1 || b->thread == thread))
ad3b8c4a
JM
901 {
902 if (overlay_debugging &&
903 section_is_overlay (b->section) &&
904 !section_is_mapped (b->section))
905 continue; /* unmapped overlay -- can't be a match */
906 else
907 return 1;
908 }
199b2450
TL
909
910 return 0;
911}
912
bd5635a1
RP
913\f
914/* bpstat stuff. External routines' interfaces are documented
915 in breakpoint.h. */
30875e1c
SG
916
917/* Clear a bpstat so that it says we are not at any breakpoint.
918 Also free any storage that is part of a bpstat. */
919
bd5635a1
RP
920void
921bpstat_clear (bsp)
922 bpstat *bsp;
923{
924 bpstat p;
925 bpstat q;
926
927 if (bsp == 0)
928 return;
929 p = *bsp;
930 while (p != NULL)
931 {
932 q = p->next;
933 if (p->old_val != NULL)
934 value_free (p->old_val);
c8950965 935 free ((PTR)p);
bd5635a1
RP
936 p = q;
937 }
938 *bsp = NULL;
939}
940
30875e1c
SG
941/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
942 is part of the bpstat is copied as well. */
943
bd5635a1
RP
944bpstat
945bpstat_copy (bs)
946 bpstat bs;
947{
948 bpstat p = NULL;
949 bpstat tmp;
fee933f1 950 bpstat retval = NULL;
bd5635a1
RP
951
952 if (bs == NULL)
953 return bs;
954
955 for (; bs != NULL; bs = bs->next)
956 {
957 tmp = (bpstat) xmalloc (sizeof (*tmp));
4ed3a9ea 958 memcpy (tmp, bs, sizeof (*tmp));
bd5635a1
RP
959 if (p == NULL)
960 /* This is the first thing in the chain. */
961 retval = tmp;
962 else
963 p->next = tmp;
964 p = tmp;
965 }
966 p->next = NULL;
967 return retval;
968}
969
30875e1c
SG
970/* Find the bpstat associated with this breakpoint */
971
972bpstat
973bpstat_find_breakpoint(bsp, breakpoint)
974 bpstat bsp;
975 struct breakpoint *breakpoint;
976{
977 if (bsp == NULL) return NULL;
978
979 for (;bsp != NULL; bsp = bsp->next) {
980 if (bsp->breakpoint_at == breakpoint) return bsp;
981 }
982 return NULL;
983}
984
985/* Return the breakpoint number of the first breakpoint we are stopped
986 at. *BSP upon return is a bpstat which points to the remaining
987 breakpoints stopped at (but which is not guaranteed to be good for
988 anything but further calls to bpstat_num).
989 Return 0 if passed a bpstat which does not indicate any breakpoints. */
990
bd5635a1
RP
991int
992bpstat_num (bsp)
993 bpstat *bsp;
994{
995 struct breakpoint *b;
996
997 if ((*bsp) == NULL)
998 return 0; /* No more breakpoint values */
999 else
1000 {
1001 b = (*bsp)->breakpoint_at;
1002 *bsp = (*bsp)->next;
1003 if (b == NULL)
1004 return -1; /* breakpoint that's been deleted since */
1005 else
1006 return b->number; /* We have its number */
1007 }
1008}
1009
30875e1c
SG
1010/* Modify BS so that the actions will not be performed. */
1011
bd5635a1
RP
1012void
1013bpstat_clear_actions (bs)
1014 bpstat bs;
1015{
1016 for (; bs != NULL; bs = bs->next)
1017 {
1018 bs->commands = NULL;
1019 if (bs->old_val != NULL)
1020 {
1021 value_free (bs->old_val);
1022 bs->old_val = NULL;
1023 }
1024 }
1025}
1026
bdbd5f50
JG
1027/* Stub for cleaning up our state if we error-out of a breakpoint command */
1028/* ARGSUSED */
1029static void
1030cleanup_executing_breakpoints (ignore)
b607efe7 1031 PTR ignore;
bdbd5f50
JG
1032{
1033 executing_breakpoint_commands = 0;
1034}
1035
bd5635a1
RP
1036/* Execute all the commands associated with all the breakpoints at this
1037 location. Any of these commands could cause the process to proceed
1038 beyond this point, etc. We look out for such changes by checking
1039 the global "breakpoint_proceeded" after each command. */
30875e1c 1040
bd5635a1
RP
1041void
1042bpstat_do_actions (bsp)
1043 bpstat *bsp;
1044{
1045 bpstat bs;
bdbd5f50 1046 struct cleanup *old_chain;
e8bf33c4 1047 struct command_line *cmd;
bdbd5f50 1048
647e52ea
SG
1049 /* Avoid endless recursion if a `source' command is contained
1050 in bs->commands. */
1051 if (executing_breakpoint_commands)
1052 return;
1053
bdbd5f50
JG
1054 executing_breakpoint_commands = 1;
1055 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
bd5635a1
RP
1056
1057top:
1058 bs = *bsp;
1059
bd5635a1
RP
1060 breakpoint_proceeded = 0;
1061 for (; bs != NULL; bs = bs->next)
1062 {
e8bf33c4
JK
1063 cmd = bs->commands;
1064 while (cmd != NULL)
bd5635a1 1065 {
0f8cdd9b 1066 execute_control_command (cmd);
e8bf33c4 1067 cmd = cmd->next;
bd5635a1 1068 }
e8bf33c4
JK
1069 if (breakpoint_proceeded)
1070 /* The inferior is proceeded by the command; bomb out now.
1071 The bpstat chain has been blown away by wait_for_inferior.
1072 But since execution has stopped again, there is a new bpstat
1073 to look at, so start over. */
1074 goto top;
1075 else
1076 bs->commands = NULL;
bd5635a1 1077 }
bd5635a1
RP
1078
1079 executing_breakpoint_commands = 0;
bdbd5f50 1080 discard_cleanups (old_chain);
bd5635a1
RP
1081}
1082
8af68e4e
JK
1083/* This is the normal print_it function for a bpstat. In the future,
1084 much of this logic could (should?) be moved to bpstat_stop_status,
1085 by having it set different print_it functions. */
30875e1c 1086
8af68e4e
JK
1087static int
1088print_it_normal (bs)
bd5635a1
RP
1089 bpstat bs;
1090{
1091 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1092 which has since been deleted. */
8af68e4e 1093 if (bs->breakpoint_at == NULL
30875e1c 1094 || (bs->breakpoint_at->type != bp_breakpoint
11054881 1095 && bs->breakpoint_at->type != bp_hardware_breakpoint
999dd04b 1096 && bs->breakpoint_at->type != bp_watchpoint
11054881
KH
1097 && bs->breakpoint_at->type != bp_read_watchpoint
1098 && bs->breakpoint_at->type != bp_access_watchpoint
999dd04b 1099 && bs->breakpoint_at->type != bp_hardware_watchpoint))
bd5635a1 1100 return 0;
bd5635a1 1101
11054881
KH
1102 if (bs->breakpoint_at->type == bp_breakpoint ||
1103 bs->breakpoint_at->type == bp_hardware_breakpoint)
bd5635a1
RP
1104 {
1105 /* I think the user probably only wants to see one breakpoint
1106 number, not all of them. */
f2d9c058 1107 annotate_breakpoint (bs->breakpoint_at->number);
bd5635a1
RP
1108 printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
1109 return 0;
1110 }
11054881
KH
1111 else if ((bs->old_val != NULL) &&
1112 (bs->breakpoint_at->type == bp_watchpoint ||
1113 bs->breakpoint_at->type == bp_access_watchpoint ||
1114 bs->breakpoint_at->type == bp_hardware_watchpoint))
bd5635a1 1115 {
f2d9c058 1116 annotate_watchpoint (bs->breakpoint_at->number);
11054881 1117 mention (bs->breakpoint_at);
bd5635a1 1118 printf_filtered ("\nOld value = ");
199b2450 1119 value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
bd5635a1 1120 printf_filtered ("\nNew value = ");
199b2450 1121 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
bd5635a1
RP
1122 Val_pretty_default);
1123 printf_filtered ("\n");
1124 value_free (bs->old_val);
1125 bs->old_val = NULL;
bd2f0c85
JL
1126 /* More than one watchpoint may have been triggered. */
1127 return -1;
bd5635a1 1128 }
11054881
KH
1129 else if (bs->breakpoint_at->type == bp_access_watchpoint ||
1130 bs->breakpoint_at->type == bp_read_watchpoint)
1131 {
1132 mention (bs->breakpoint_at);
1133 printf_filtered ("\nValue = ");
1134 value_print (bs->breakpoint_at->val, gdb_stdout, 0,
1135 Val_pretty_default);
1136 printf_filtered ("\n");
1137 return -1;
1138 }
8af68e4e
JK
1139 /* We can't deal with it. Maybe another member of the bpstat chain can. */
1140 return -1;
1141}
1142
1143/* Print a message indicating what happened. Returns nonzero to
1144 say that only the source line should be printed after this (zero
1145 return means print the frame as well as the source line). */
3f031adf 1146/* Currently we always return zero. */
8af68e4e
JK
1147int
1148bpstat_print (bs)
1149 bpstat bs;
1150{
1151 int val;
1152
1153 if (bs == NULL)
1154 return 0;
bd5635a1 1155
8af68e4e
JK
1156 val = (*bs->print_it) (bs);
1157 if (val >= 0)
1158 return val;
1159
fcb887ff
JK
1160 /* Maybe another breakpoint in the chain caused us to stop.
1161 (Currently all watchpoints go on the bpstat whether hit or
1162 not. That probably could (should) be changed, provided care is taken
1163 with respect to bpstat_explains_signal). */
1164 if (bs->next)
1165 return bpstat_print (bs->next);
1166
cabd4da6 1167 /* We reached the end of the chain without printing anything. */
bd5635a1
RP
1168 return 0;
1169}
1170
1171/* Evaluate the expression EXP and return 1 if value is zero.
1172 This is used inside a catch_errors to evaluate the breakpoint condition.
bdbd5f50 1173 The argument is a "struct expression *" that has been cast to char * to
bd5635a1
RP
1174 make it pass through catch_errors. */
1175
1176static int
1177breakpoint_cond_eval (exp)
bdbd5f50 1178 char *exp;
bd5635a1 1179{
11054881
KH
1180 value_ptr mark = value_mark ();
1181 int i = !value_true (evaluate_expression ((struct expression *)exp));
1182 value_free_to_mark (mark);
1183 return i;
bd5635a1
RP
1184}
1185
1186/* Allocate a new bpstat and chain it to the current one. */
1187
1188static bpstat
1189bpstat_alloc (b, cbs)
1190 register struct breakpoint *b;
1191 bpstat cbs; /* Current "bs" value */
1192{
1193 bpstat bs;
1194
1195 bs = (bpstat) xmalloc (sizeof (*bs));
1196 cbs->next = bs;
1197 bs->breakpoint_at = b;
1198 /* If the condition is false, etc., don't do the commands. */
1199 bs->commands = NULL;
bd5635a1 1200 bs->old_val = NULL;
8af68e4e 1201 bs->print_it = print_it_normal;
bd5635a1
RP
1202 return bs;
1203}
fa99ebe1 1204\f
8af68e4e
JK
1205/* Possible return values for watchpoint_check (this can't be an enum
1206 because of check_errors). */
999dd04b
JL
1207/* The watchpoint has been deleted. */
1208#define WP_DELETED 1
8af68e4e
JK
1209/* The value has changed. */
1210#define WP_VALUE_CHANGED 2
1211/* The value has not changed. */
1212#define WP_VALUE_NOT_CHANGED 3
1213
e8bf33c4
JK
1214#define BP_TEMPFLAG 1
1215#define BP_HARDWAREFLAG 2
1216
8af68e4e 1217/* Check watchpoint condition. */
557f3a0e 1218
8af68e4e
JK
1219static int
1220watchpoint_check (p)
fe675038 1221 char *p;
8af68e4e
JK
1222{
1223 bpstat bs = (bpstat) p;
11054881 1224 struct breakpoint *b;
2b576293
C
1225 struct frame_info *fr;
1226 int within_current_scope;
999dd04b 1227
557f3a0e
SS
1228 b = bs->breakpoint_at;
1229
1230 if (b->exp_valid_block == NULL)
8af68e4e 1231 within_current_scope = 1;
fa99ebe1
JK
1232 else
1233 {
706dc3ce
JL
1234 /* There is no current frame at this moment. If we're going to have
1235 any chance of handling watchpoints on local variables, we'll need
1236 the frame chain (so we can determine if we're in scope). */
1237 reinit_frame_cache();
557f3a0e 1238 fr = find_frame_addr_in_frame_chain (b->watchpoint_frame);
999dd04b 1239 within_current_scope = (fr != NULL);
fa99ebe1
JK
1240 if (within_current_scope)
1241 /* If we end up stopping, the current frame will get selected
1242 in normal_stop. So this call to select_frame won't affect
1243 the user. */
1244 select_frame (fr, -1);
1245 }
1246
8af68e4e
JK
1247 if (within_current_scope)
1248 {
1249 /* We use value_{,free_to_}mark because it could be a
1250 *long* time before we return to the command level and
cef4c2e7
PS
1251 call free_all_values. We can't call free_all_values because
1252 we might be in the middle of evaluating a function call. */
8af68e4e 1253
82a2edfb
JK
1254 value_ptr mark = value_mark ();
1255 value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp);
557f3a0e 1256 if (!value_equal (b->val, new_val))
8af68e4e
JK
1257 {
1258 release_value (new_val);
1259 value_free_to_mark (mark);
557f3a0e
SS
1260 bs->old_val = b->val;
1261 b->val = new_val;
8af68e4e
JK
1262 /* We will stop here */
1263 return WP_VALUE_CHANGED;
1264 }
1265 else
1266 {
1267 /* Nothing changed, don't do anything. */
1268 value_free_to_mark (mark);
1269 /* We won't stop here */
1270 return WP_VALUE_NOT_CHANGED;
1271 }
1272 }
1273 else
1274 {
1275 /* This seems like the only logical thing to do because
1276 if we temporarily ignored the watchpoint, then when
1277 we reenter the block in which it is valid it contains
1278 garbage (in the case of a function, it may have two
1279 garbage values, one before and one after the prologue).
1280 So we can't even detect the first assignment to it and
1281 watch after that (since the garbage may or may not equal
1282 the first value assigned). */
8af68e4e 1283 printf_filtered ("\
999dd04b 1284Watchpoint %d deleted because the program has left the block in\n\
8af68e4e 1285which its expression is valid.\n", bs->breakpoint_at->number);
557f3a0e 1286 if (b->related_breakpoint)
6b038bd9 1287 b->related_breakpoint->disposition = del_at_next_stop;
e51481f9 1288 b->disposition = del_at_next_stop;
999dd04b 1289
999dd04b 1290 return WP_DELETED;
8af68e4e
JK
1291 }
1292}
1293
1294/* This is used when everything which needs to be printed has
1295 already been printed. But we still want to print the frame. */
1296static int
cabd4da6 1297print_it_done (bs)
8af68e4e
JK
1298 bpstat bs;
1299{
1300 return 0;
1301}
1302
cabd4da6
JK
1303/* This is used when nothing should be printed for this bpstat entry. */
1304
1305static int
1306print_it_noop (bs)
1307 bpstat bs;
1308{
1309 return -1;
1310}
1311
cb6b0202 1312/* Get a bpstat associated with having just stopped at address *PC
706dc3ce 1313 and frame address CORE_ADDRESS. Update *PC to point at the
cb6b0202
JK
1314 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1315 if this is known to not be a real breakpoint (it could still be a
1316 watchpoint, though). */
1317
bd5635a1
RP
1318/* Determine whether we stopped at a breakpoint, etc, or whether we
1319 don't understand this stop. Result is a chain of bpstat's such that:
1320
1321 if we don't understand the stop, the result is a null pointer.
1322
cb6b0202 1323 if we understand why we stopped, the result is not null.
bd5635a1
RP
1324
1325 Each element of the chain refers to a particular breakpoint or
1326 watchpoint at which we have stopped. (We may have stopped for
2d313932 1327 several reasons concurrently.)
bd5635a1
RP
1328
1329 Each element of the chain has valid next, breakpoint_at,
1330 commands, FIXME??? fields.
1331
1332 */
1333
bd5635a1 1334bpstat
16726dd1 1335bpstat_stop_status (pc, not_a_breakpoint)
bd5635a1 1336 CORE_ADDR *pc;
cb6b0202 1337 int not_a_breakpoint;
bd5635a1 1338{
fa3764e2 1339 register struct breakpoint *b, *temp;
bd5635a1
RP
1340 CORE_ADDR bp_addr;
1341 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1342 int real_breakpoint = 0;
1343 /* Root of the chain of bpstat's */
e8bf33c4 1344 struct bpstats root_bs[1];
bd5635a1
RP
1345 /* Pointer to the last thing in the chain currently. */
1346 bpstat bs = root_bs;
11054881
KH
1347 static char message1[] =
1348 "Error evaluating expression for watchpoint %d\n";
1349 char message[sizeof (message1) + 30 /* slop */];
bd5635a1
RP
1350
1351 /* Get the address where the breakpoint would have been. */
1352 bp_addr = *pc - DECR_PC_AFTER_BREAK;
1353
fa3764e2 1354 ALL_BREAKPOINTS_SAFE (b, temp)
bd5635a1 1355 {
fa3764e2
JL
1356 if (b->enable == disabled
1357 || b->enable == shlib_disabled)
bd5635a1 1358 continue;
30875e1c 1359
999dd04b
JL
1360 if (b->type != bp_watchpoint
1361 && b->type != bp_hardware_watchpoint
11054881
KH
1362 && b->type != bp_read_watchpoint
1363 && b->type != bp_access_watchpoint
6b038bd9
DT
1364 && b->type != bp_hardware_breakpoint) /* a non-watchpoint bp */
1365 if (b->address != bp_addr || /* address doesn't match or */
1366 (overlay_debugging && /* overlay doesn't match */
1367 section_is_overlay (b->section) &&
1368 !section_is_mapped (b->section)))
1369 continue;
bd5635a1 1370
11054881
KH
1371 if (b->type == bp_hardware_breakpoint
1372 && b->address != (bp_addr - DECR_PC_AFTER_HW_BREAK))
1373 continue;
1374
999dd04b
JL
1375 if (b->type != bp_watchpoint
1376 && b->type != bp_hardware_watchpoint
11054881
KH
1377 && b->type != bp_read_watchpoint
1378 && b->type != bp_access_watchpoint
999dd04b 1379 && not_a_breakpoint)
cb6b0202
JK
1380 continue;
1381
30875e1c
SG
1382 /* Come here if it's a watchpoint, or if the break address matches */
1383
9f577285
SS
1384 ++(b->hit_count);
1385
bd5635a1
RP
1386 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
1387
cabd4da6
JK
1388 bs->stop = 1;
1389 bs->print = 1;
bd5635a1 1390
11054881 1391 sprintf (message, message1, b->number);
999dd04b 1392 if (b->type == bp_watchpoint || b->type == bp_hardware_watchpoint)
bd5635a1 1393 {
fe675038
JK
1394 switch (catch_errors (watchpoint_check, (char *) bs, message,
1395 RETURN_MASK_ALL))
bd5635a1 1396 {
999dd04b 1397 case WP_DELETED:
8af68e4e 1398 /* We've already printed what needs to be printed. */
cabd4da6 1399 bs->print_it = print_it_done;
8af68e4e
JK
1400 /* Stop. */
1401 break;
1402 case WP_VALUE_CHANGED:
1403 /* Stop. */
1404 break;
1405 case WP_VALUE_NOT_CHANGED:
1406 /* Don't stop. */
cabd4da6
JK
1407 bs->print_it = print_it_noop;
1408 bs->stop = 0;
92fb1f2e
SS
1409 /* Don't consider this a hit. */
1410 --(b->hit_count);
bd5635a1 1411 continue;
8af68e4e
JK
1412 default:
1413 /* Can't happen. */
1414 /* FALLTHROUGH */
1415 case 0:
1416 /* Error from catch_errors. */
999dd04b
JL
1417 printf_filtered ("Watchpoint %d deleted.\n", b->number);
1418 if (b->related_breakpoint)
6b038bd9 1419 b->related_breakpoint->disposition = del_at_next_stop;
e51481f9 1420 b->disposition = del_at_next_stop;
8af68e4e 1421 /* We've already printed what needs to be printed. */
cabd4da6 1422 bs->print_it = print_it_done;
999dd04b 1423
8af68e4e
JK
1424 /* Stop. */
1425 break;
bd5635a1
RP
1426 }
1427 }
11054881
KH
1428 else if (b->type == bp_read_watchpoint || b->type == bp_access_watchpoint)
1429 {
1430 CORE_ADDR addr;
1431 value_ptr v;
1432 int found = 0;
1433
1434 addr = target_stopped_data_address();
1435 if (addr == 0) continue;
1436 for (v = b->val_chain; v; v = v->next)
1437 {
1438 if (v->lval == lval_memory)
1439 {
1440 CORE_ADDR vaddr;
1441
1442 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1443 if (addr == vaddr)
1444 found = 1;
1445 }
1446 }
1447 if (found)
1448 switch (catch_errors (watchpoint_check, (char *) bs, message,
1449 RETURN_MASK_ALL))
1450 {
1451 case WP_DELETED:
1452 /* We've already printed what needs to be printed. */
1453 bs->print_it = print_it_done;
1454 /* Stop. */
1455 break;
1456 case WP_VALUE_CHANGED:
1457 case WP_VALUE_NOT_CHANGED:
1458 /* Stop. */
1459 break;
1460 default:
1461 /* Can't happen. */
1462 case 0:
1463 /* Error from catch_errors. */
1464 printf_filtered ("Watchpoint %d deleted.\n", b->number);
e51481f9 1465 if (b->related_breakpoint)
6b038bd9 1466 b->related_breakpoint->disposition = del_at_next_stop;
e51481f9 1467 b->disposition = del_at_next_stop;
11054881
KH
1468 /* We've already printed what needs to be printed. */
1469 bs->print_it = print_it_done;
1470 break;
1471 }
1472 }
6b038bd9 1473 else if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
bd5635a1
RP
1474 real_breakpoint = 1;
1475
6ee2da94
FCE
1476 if (b->frame && b->frame != (get_current_frame ())->frame &&
1477 (b->type == bp_step_resume &&
1478 (get_current_frame ())->frame INNER_THAN b->frame))
cabd4da6 1479 bs->stop = 0;
bd5635a1
RP
1480 else
1481 {
fee933f1 1482 int value_is_zero = 0;
bd5635a1
RP
1483
1484 if (b->cond)
1485 {
1486 /* Need to select the frame, with all that implies
1487 so that the conditions will have the right context. */
1488 select_frame (get_current_frame (), 0);
bdbd5f50
JG
1489 value_is_zero
1490 = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
fe675038
JK
1491 "Error in testing breakpoint condition:\n",
1492 RETURN_MASK_ALL);
06b6c733 1493 /* FIXME-someday, should give breakpoint # */
bd5635a1
RP
1494 free_all_values ();
1495 }
bdbd5f50 1496 if (b->cond && value_is_zero)
bd5635a1 1497 {
cabd4da6 1498 bs->stop = 0;
92fb1f2e
SS
1499 /* Don't consider this a hit. */
1500 --(b->hit_count);
bd5635a1
RP
1501 }
1502 else if (b->ignore_count > 0)
1503 {
1504 b->ignore_count--;
cabd4da6 1505 bs->stop = 0;
bd5635a1
RP
1506 }
1507 else
1508 {
1509 /* We will stop here */
30875e1c 1510 if (b->disposition == disable)
bd5635a1
RP
1511 b->enable = disabled;
1512 bs->commands = b->commands;
1513 if (b->silent)
cabd4da6 1514 bs->print = 0;
2d313932 1515 if (bs->commands && STREQ ("silent", bs->commands->line))
bd5635a1
RP
1516 {
1517 bs->commands = bs->commands->next;
cabd4da6 1518 bs->print = 0;
bd5635a1
RP
1519 }
1520 }
1521 }
cabd4da6
JK
1522 /* Print nothing for this entry if we dont stop or if we dont print. */
1523 if (bs->stop == 0 || bs->print == 0)
1524 bs->print_it = print_it_noop;
bd5635a1
RP
1525 }
1526
1527 bs->next = NULL; /* Terminate the chain */
1528 bs = root_bs->next; /* Re-grab the head of the chain */
6b038bd9
DT
1529
1530 if ((DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs) && bs)
bd5635a1 1531 {
bd5635a1
RP
1532 if (real_breakpoint)
1533 {
1534 *pc = bp_addr;
1535#if defined (SHIFT_INST_REGS)
817ac7f8 1536 SHIFT_INST_REGS();
bd5635a1
RP
1537#else /* No SHIFT_INST_REGS. */
1538 write_pc (bp_addr);
1539#endif /* No SHIFT_INST_REGS. */
1540 }
bd5635a1 1541 }
999dd04b
JL
1542
1543 /* The value of a hardware watchpoint hasn't changed, but the
1544 intermediate memory locations we are watching may have. */
11054881
KH
1545 if (bs && ! bs->stop &&
1546 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
1547 bs->breakpoint_at->type == bp_read_watchpoint ||
1548 bs->breakpoint_at->type == bp_access_watchpoint))
999dd04b
JL
1549 {
1550 remove_breakpoints ();
1551 insert_breakpoints ();
1552 }
bd5635a1
RP
1553 return bs;
1554}
cabd4da6
JK
1555\f
1556/* Tell what to do about this bpstat. */
fe675038 1557struct bpstat_what
cabd4da6
JK
1558bpstat_what (bs)
1559 bpstat bs;
1560{
1561 /* Classify each bpstat as one of the following. */
1562 enum class {
fe675038
JK
1563 /* This bpstat element has no effect on the main_action. */
1564 no_effect = 0,
cabd4da6
JK
1565
1566 /* There was a watchpoint, stop but don't print. */
1567 wp_silent,
1568
1569 /* There was a watchpoint, stop and print. */
1570 wp_noisy,
1571
1572 /* There was a breakpoint but we're not stopping. */
1573 bp_nostop,
1574
1575 /* There was a breakpoint, stop but don't print. */
1576 bp_silent,
1577
1578 /* There was a breakpoint, stop and print. */
1579 bp_noisy,
1580
1581 /* We hit the longjmp breakpoint. */
1582 long_jump,
1583
1584 /* We hit the longjmp_resume breakpoint. */
1585 long_resume,
1586
d7e7e851
JK
1587 /* We hit the step_resume breakpoint. */
1588 step_resume,
1589
bcc37718
JK
1590 /* We hit the through_sigtramp breakpoint. */
1591 through_sig,
1592
27b6a1fa
JL
1593 /* We hit the shared library event breakpoint. */
1594 shlib_event,
1595
cabd4da6
JK
1596 /* This is just used to count how many enums there are. */
1597 class_last
1598 };
1599
1600 /* Here is the table which drives this routine. So that we can
1601 format it pretty, we define some abbreviations for the
1602 enum bpstat_what codes. */
27b6a1fa
JL
1603#define kc BPSTAT_WHAT_KEEP_CHECKING
1604#define ss BPSTAT_WHAT_STOP_SILENT
1605#define sn BPSTAT_WHAT_STOP_NOISY
1606#define sgl BPSTAT_WHAT_SINGLE
1607#define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
1608#define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1609#define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
d7e7e851 1610#define sr BPSTAT_WHAT_STEP_RESUME
bcc37718 1611#define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
27b6a1fa 1612#define shl BPSTAT_WHAT_CHECK_SHLIBS
d7e7e851 1613
cabd4da6
JK
1614/* "Can't happen." Might want to print an error message.
1615 abort() is not out of the question, but chances are GDB is just
1616 a bit confused, not unusable. */
1617#define err BPSTAT_WHAT_STOP_NOISY
1618
1619 /* Given an old action and a class, come up with a new action. */
84d59861
JK
1620 /* One interesting property of this table is that wp_silent is the same
1621 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1622 after stopping, the check for whether to step over a breakpoint
1623 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1624 reference to how we stopped. We retain separate wp_silent and bp_silent
1625 codes in case we want to change that someday. */
d7e7e851
JK
1626
1627 /* step_resume entries: a step resume breakpoint overrides another
1628 breakpoint of signal handling (see comment in wait_for_inferior
1629 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
bcc37718
JK
1630 /* We handle the through_sigtramp_breakpoint the same way; having both
1631 one of those and a step_resume_breakpoint is probably very rare (?). */
d7e7e851 1632
fe675038 1633 static const enum bpstat_what_main_action
cabd4da6
JK
1634 table[(int)class_last][(int)BPSTAT_WHAT_LAST] =
1635 {
1636 /* old action */
27b6a1fa 1637 /* kc ss sn sgl slr clr clrs sr ts shl
bcc37718 1638 */
27b6a1fa
JL
1639/*no_effect*/ {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl},
1640/*wp_silent*/ {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl},
1641/*wp_noisy*/ {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl},
1642/*bp_nostop*/ {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl},
1643/*bp_silent*/ {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl},
1644/*bp_noisy*/ {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl},
1645/*long_jump*/ {slr, ss, sn, slr, err, err, err, sr, ts, shl},
1646/*long_resume*/ {clr, ss, sn, clrs, err, err, err, sr, ts, shl},
1647/*step_resume*/ {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl},
1648/*through_sig*/ {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl},
1649/*shlib*/ {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl}
cabd4da6 1650 };
27b6a1fa
JL
1651#undef kc
1652#undef ss
1653#undef sn
1654#undef sgl
1655#undef slr
1656#undef clr
1657#undef clrs
cabd4da6 1658#undef err
bcc37718
JK
1659#undef sr
1660#undef ts
27b6a1fa 1661#undef shl
fe675038 1662 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
84d59861 1663 struct bpstat_what retval;
cabd4da6 1664
cef4c2e7 1665 retval.call_dummy = 0;
cabd4da6
JK
1666 for (; bs != NULL; bs = bs->next)
1667 {
fee933f1 1668 enum class bs_class = no_effect;
cabd4da6
JK
1669 if (bs->breakpoint_at == NULL)
1670 /* I suspect this can happen if it was a momentary breakpoint
1671 which has since been deleted. */
1672 continue;
1673 switch (bs->breakpoint_at->type)
1674 {
1675 case bp_breakpoint:
11054881 1676 case bp_hardware_breakpoint:
cabd4da6
JK
1677 case bp_until:
1678 case bp_finish:
1679 if (bs->stop)
1680 {
1681 if (bs->print)
1682 bs_class = bp_noisy;
1683 else
1684 bs_class = bp_silent;
1685 }
1686 else
1687 bs_class = bp_nostop;
1688 break;
1689 case bp_watchpoint:
999dd04b 1690 case bp_hardware_watchpoint:
11054881
KH
1691 case bp_read_watchpoint:
1692 case bp_access_watchpoint:
cabd4da6
JK
1693 if (bs->stop)
1694 {
1695 if (bs->print)
1696 bs_class = wp_noisy;
1697 else
1698 bs_class = wp_silent;
1699 }
1700 else
fe675038
JK
1701 /* There was a watchpoint, but we're not stopping. This requires
1702 no further action. */
1703 bs_class = no_effect;
cabd4da6
JK
1704 break;
1705 case bp_longjmp:
1706 bs_class = long_jump;
1707 break;
1708 case bp_longjmp_resume:
1709 bs_class = long_resume;
1710 break;
fe675038 1711 case bp_step_resume:
fe675038
JK
1712 if (bs->stop)
1713 {
d7e7e851 1714 bs_class = step_resume;
fe675038
JK
1715 }
1716 else
1717 /* It is for the wrong frame. */
1718 bs_class = bp_nostop;
bcc37718
JK
1719 break;
1720 case bp_through_sigtramp:
1721 bs_class = through_sig;
fe675038 1722 break;
999dd04b
JL
1723 case bp_watchpoint_scope:
1724 bs_class = bp_nostop;
1725 break;
27b6a1fa
JL
1726 case bp_shlib_event:
1727 bs_class = shlib_event;
1728 break;
84d59861
JK
1729 case bp_call_dummy:
1730 /* Make sure the action is stop (silent or noisy), so infrun.c
1731 pops the dummy frame. */
1732 bs_class = bp_silent;
1733 retval.call_dummy = 1;
bb7b3800 1734 break;
cabd4da6
JK
1735 }
1736 current_action = table[(int)bs_class][(int)current_action];
1737 }
84d59861
JK
1738 retval.main_action = current_action;
1739 return retval;
cabd4da6 1740}
bd5635a1 1741
30875e1c
SG
1742/* Nonzero if we should step constantly (e.g. watchpoints on machines
1743 without hardware support). This isn't related to a specific bpstat,
1744 just to things like whether watchpoints are set. */
1745
bd5635a1
RP
1746int
1747bpstat_should_step ()
1748{
1749 struct breakpoint *b;
1750 ALL_BREAKPOINTS (b)
30875e1c 1751 if (b->enable == enabled && b->type == bp_watchpoint)
bd5635a1
RP
1752 return 1;
1753 return 0;
1754}
1755\f
1756/* Print information on breakpoint number BNUM, or -1 if all.
1757 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1758 is nonzero, process only watchpoints. */
1759
1760static void
c8950965 1761breakpoint_1 (bnum, allflag)
bd5635a1 1762 int bnum;
80ba48f5 1763 int allflag;
bd5635a1
RP
1764{
1765 register struct breakpoint *b;
1766 register struct command_line *l;
1767 register struct symbol *sym;
1768 CORE_ADDR last_addr = (CORE_ADDR)-1;
30875e1c 1769 int found_a_breakpoint = 0;
11054881
KH
1770 static char *bptypes[] = {"breakpoint", "hw breakpoint",
1771 "until", "finish", "watchpoint",
1772 "hw watchpoint", "read watchpoint",
1773 "acc watchpoint", "longjmp",
999dd04b 1774 "longjmp resume", "step resume",
27b6a1fa
JL
1775 "sigtramp",
1776 "watchpoint scope", "call dummy",
1777 "shlib events" };
e51481f9 1778 static char *bpdisps[] = {"del", "dstp", "dis", "keep"};
647e52ea 1779 static char bpenables[] = "nyn";
0a62ff36 1780 char wrap_indent[80];
30875e1c 1781
bd5635a1 1782 ALL_BREAKPOINTS (b)
30875e1c
SG
1783 if (bnum == -1
1784 || bnum == b->number)
bd5635a1 1785 {
80ba48f5
SG
1786/* We only print out user settable breakpoints unless the allflag is set. */
1787 if (!allflag
1788 && b->type != bp_breakpoint
11054881 1789 && b->type != bp_hardware_breakpoint
999dd04b 1790 && b->type != bp_watchpoint
11054881
KH
1791 && b->type != bp_read_watchpoint
1792 && b->type != bp_access_watchpoint
999dd04b 1793 && b->type != bp_hardware_watchpoint)
80ba48f5
SG
1794 continue;
1795
30875e1c 1796 if (!found_a_breakpoint++)
47ebe8fd 1797 {
f2d9c058
KH
1798 annotate_breakpoints_headers ();
1799
1800 annotate_field (0);
1801 printf_filtered ("Num ");
1802 annotate_field (1);
1803 printf_filtered ("Type ");
1804 annotate_field (2);
1805 printf_filtered ("Disp ");
1806 annotate_field (3);
1807 printf_filtered ("Enb ");
1808 if (addressprint)
1809 {
1810 annotate_field (4);
1811 printf_filtered ("Address ");
1812 }
1813 annotate_field (5);
1814 printf_filtered ("What\n");
1815
1816 annotate_breakpoints_table ();
1817 }
1818
1819 annotate_record ();
1820 annotate_field (0);
1821 printf_filtered ("%-3d ", b->number);
1822 annotate_field (1);
1823 printf_filtered ("%-14s ", bptypes[(int)b->type]);
1824 annotate_field (2);
1825 printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
1826 annotate_field (3);
47ebe8fd
JK
1827 printf_filtered ("%-3c ", bpenables[(int)b->enable]);
1828
0a62ff36
JK
1829 strcpy (wrap_indent, " ");
1830 if (addressprint)
1831 strcat (wrap_indent, " ");
30875e1c 1832 switch (b->type)
bd5635a1 1833 {
30875e1c 1834 case bp_watchpoint:
999dd04b 1835 case bp_hardware_watchpoint:
11054881
KH
1836 case bp_read_watchpoint:
1837 case bp_access_watchpoint:
47ebe8fd
JK
1838 /* Field 4, the address, is omitted (which makes the columns
1839 not line up too nicely with the headers, but the effect
1840 is relatively readable). */
9f577285 1841 annotate_field (5);
199b2450 1842 print_expression (b->exp, gdb_stdout);
30875e1c 1843 break;
84d59861 1844
30875e1c 1845 case bp_breakpoint:
11054881 1846 case bp_hardware_breakpoint:
80ba48f5
SG
1847 case bp_until:
1848 case bp_finish:
1849 case bp_longjmp:
1850 case bp_longjmp_resume:
84d59861 1851 case bp_step_resume:
bcc37718 1852 case bp_through_sigtramp:
999dd04b 1853 case bp_watchpoint_scope:
bb7b3800 1854 case bp_call_dummy:
27b6a1fa 1855 case bp_shlib_event:
bd5635a1 1856 if (addressprint)
47ebe8fd 1857 {
f2d9c058 1858 annotate_field (4);
47ebe8fd
JK
1859 /* FIXME-32x64: need a print_address_numeric with
1860 field width */
1861 printf_filtered
1862 ("%s ",
1863 local_hex_string_custom
1864 ((unsigned long) b->address, "08l"));
1865 }
1866
f2d9c058 1867 annotate_field (5);
bd5635a1
RP
1868
1869 last_addr = b->address;
d889f6b7 1870 if (b->source_file)
bd5635a1 1871 {
6b038bd9 1872 sym = find_pc_sect_function (b->address, b->section);
bd5635a1
RP
1873 if (sym)
1874 {
199b2450
TL
1875 fputs_filtered ("in ", gdb_stdout);
1876 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
0a62ff36 1877 wrap_here (wrap_indent);
199b2450 1878 fputs_filtered (" at ", gdb_stdout);
bd5635a1 1879 }
199b2450 1880 fputs_filtered (b->source_file, gdb_stdout);
bd5635a1
RP
1881 printf_filtered (":%d", b->line_number);
1882 }
1883 else
199b2450 1884 print_address_symbolic (b->address, gdb_stdout, demangle, " ");
fee933f1 1885 break;
bd5635a1
RP
1886 }
1887
1888 printf_filtered ("\n");
1889
1890 if (b->frame)
833e0d94 1891 {
f2d9c058 1892 annotate_field (6);
47ebe8fd 1893
833e0d94 1894 printf_filtered ("\tstop only in stack frame at ");
d24c0599 1895 print_address_numeric (b->frame, 1, gdb_stdout);
833e0d94 1896 printf_filtered ("\n");
bcc37718 1897 }
47ebe8fd 1898
bd5635a1
RP
1899 if (b->cond)
1900 {
f2d9c058 1901 annotate_field (7);
47ebe8fd 1902
bd5635a1 1903 printf_filtered ("\tstop only if ");
199b2450 1904 print_expression (b->cond, gdb_stdout);
bd5635a1
RP
1905 printf_filtered ("\n");
1906 }
47ebe8fd 1907
647e52ea
SG
1908 if (b->thread != -1)
1909 {
1910 /* FIXME should make an annotation for this */
1911 printf_filtered ("\tstop only in thread %d\n", b->thread);
1912 }
1913
9f577285
SS
1914 if (show_breakpoint_hit_counts && b->hit_count)
1915 {
1916 /* FIXME should make an annotation for this */
1917
16726dd1
JK
1918 printf_filtered ("\tbreakpoint already hit %d time%s\n",
1919 b->hit_count, (b->hit_count == 1 ? "" : "s"));
9f577285
SS
1920 }
1921
bd5635a1 1922 if (b->ignore_count)
47ebe8fd 1923 {
f2d9c058 1924 annotate_field (8);
47ebe8fd
JK
1925
1926 printf_filtered ("\tignore next %d hits\n", b->ignore_count);
1927 }
1928
bd5635a1 1929 if ((l = b->commands))
47ebe8fd 1930 {
f2d9c058 1931 annotate_field (9);
47ebe8fd
JK
1932
1933 while (l)
1934 {
0f8cdd9b 1935 print_command_line (l, 4);
47ebe8fd
JK
1936 l = l->next;
1937 }
1938 }
bd5635a1
RP
1939 }
1940
fee933f1
RP
1941 if (!found_a_breakpoint)
1942 {
1943 if (bnum == -1)
1944 printf_filtered ("No breakpoints or watchpoints.\n");
1945 else
1946 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
1947 }
30875e1c
SG
1948 else
1949 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1950 that a comparison of an unsigned with -1 is always false. */
1951 if (last_addr != (CORE_ADDR)-1)
1952 set_next_address (last_addr);
47ebe8fd 1953
f2d9c058 1954 annotate_breakpoints_table_end ();
bd5635a1
RP
1955}
1956
bdbd5f50 1957/* ARGSUSED */
bd5635a1
RP
1958static void
1959breakpoints_info (bnum_exp, from_tty)
1960 char *bnum_exp;
1961 int from_tty;
1962{
1963 int bnum = -1;
1964
1965 if (bnum_exp)
1966 bnum = parse_and_eval_address (bnum_exp);
1967
c8950965 1968 breakpoint_1 (bnum, 0);
80ba48f5
SG
1969}
1970
9b280a7f
JG
1971#if MAINTENANCE_CMDS
1972
80ba48f5
SG
1973/* ARGSUSED */
1974static void
9b280a7f 1975maintenance_info_breakpoints (bnum_exp, from_tty)
80ba48f5
SG
1976 char *bnum_exp;
1977 int from_tty;
1978{
1979 int bnum = -1;
1980
1981 if (bnum_exp)
1982 bnum = parse_and_eval_address (bnum_exp);
1983
c8950965 1984 breakpoint_1 (bnum, 1);
bd5635a1
RP
1985}
1986
9b280a7f
JG
1987#endif
1988
bd5635a1
RP
1989/* Print a message describing any breakpoints set at PC. */
1990
1991static void
6b038bd9
DT
1992describe_other_breakpoints (pc, section)
1993 CORE_ADDR pc;
1994 asection *section;
bd5635a1
RP
1995{
1996 register int others = 0;
1997 register struct breakpoint *b;
1998
1999 ALL_BREAKPOINTS (b)
2000 if (b->address == pc)
6b038bd9
DT
2001 if (overlay_debugging == 0 ||
2002 b->section == section)
2003 others++;
bd5635a1
RP
2004 if (others > 0)
2005 {
833e0d94 2006 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
bd5635a1
RP
2007 ALL_BREAKPOINTS (b)
2008 if (b->address == pc)
6b038bd9
DT
2009 if (overlay_debugging == 0 ||
2010 b->section == section)
2011 {
2012 others--;
2013 printf_filtered
2014 ("%d%s%s ",
2015 b->number,
2016 ((b->enable == disabled || b->enable == shlib_disabled)
2017 ? " (disabled)" : ""),
2018 (others > 1) ? "," : ((others == 1) ? " and" : ""));
2019 }
833e0d94 2020 printf_filtered ("also set at pc ");
d24c0599 2021 print_address_numeric (pc, 1, gdb_stdout);
833e0d94 2022 printf_filtered (".\n");
bd5635a1
RP
2023 }
2024}
2025\f
2026/* Set the default place to put a breakpoint
2027 for the `break' command with no arguments. */
2028
2029void
2030set_default_breakpoint (valid, addr, symtab, line)
2031 int valid;
2032 CORE_ADDR addr;
2033 struct symtab *symtab;
2034 int line;
2035{
2036 default_breakpoint_valid = valid;
2037 default_breakpoint_address = addr;
2038 default_breakpoint_symtab = symtab;
2039 default_breakpoint_line = line;
2040}
2041
2042/* Rescan breakpoints at address ADDRESS,
2043 marking the first one as "first" and any others as "duplicates".
2044 This is so that the bpt instruction is only inserted once. */
2045
2046static void
6b038bd9 2047check_duplicates (address, section)
bd5635a1 2048 CORE_ADDR address;
6b038bd9 2049 asection *section;
bd5635a1
RP
2050{
2051 register struct breakpoint *b;
2052 register int count = 0;
2053
30875e1c 2054 if (address == 0) /* Watchpoints are uninteresting */
f266e564
JK
2055 return;
2056
bd5635a1 2057 ALL_BREAKPOINTS (b)
fa3764e2
JL
2058 if (b->enable != disabled
2059 && b->enable != shlib_disabled
6b038bd9
DT
2060 && b->address == address
2061 && (overlay_debugging == 0 || b->section == section))
bd5635a1
RP
2062 {
2063 count++;
2064 b->duplicate = count > 1;
2065 }
2066}
2067
2068/* Low level routine to set a breakpoint.
2069 Takes as args the three things that every breakpoint must have.
2070 Returns the breakpoint object so caller can set other things.
2071 Does not set the breakpoint number!
f266e564
JK
2072 Does not print anything.
2073
2074 ==> This routine should not be called if there is a chance of later
2075 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
2076 your arguments BEFORE calling this routine! */
bd5635a1 2077
895cc8ab 2078struct breakpoint *
bd5635a1
RP
2079set_raw_breakpoint (sal)
2080 struct symtab_and_line sal;
2081{
2082 register struct breakpoint *b, *b1;
2083
2084 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
4ed3a9ea 2085 memset (b, 0, sizeof (*b));
bd5635a1 2086 b->address = sal.pc;
d889f6b7
JK
2087 if (sal.symtab == NULL)
2088 b->source_file = NULL;
2089 else
2090 b->source_file = savestring (sal.symtab->filename,
2091 strlen (sal.symtab->filename));
6b038bd9 2092 b->section = sal.section;
706dc3ce
JL
2093 b->language = current_language->la_language;
2094 b->input_radix = input_radix;
199b2450 2095 b->thread = -1;
bd5635a1
RP
2096 b->line_number = sal.line;
2097 b->enable = enabled;
2098 b->next = 0;
2099 b->silent = 0;
2100 b->ignore_count = 0;
2101 b->commands = NULL;
30875e1c 2102 b->frame = 0;
bd5635a1
RP
2103
2104 /* Add this breakpoint to the end of the chain
2105 so that a list of breakpoints will come out in order
2106 of increasing numbers. */
2107
2108 b1 = breakpoint_chain;
2109 if (b1 == 0)
2110 breakpoint_chain = b;
2111 else
2112 {
2113 while (b1->next)
2114 b1 = b1->next;
2115 b1->next = b;
2116 }
2117
6b038bd9 2118 check_duplicates (sal.pc, sal.section);
6c803036 2119 breakpoints_changed ();
bd5635a1
RP
2120
2121 return b;
2122}
2123
39ce6829
PS
2124#ifdef GET_LONGJMP_TARGET
2125
30875e1c 2126static void
cd10c7e3 2127create_longjmp_breakpoint (func_name)
30875e1c 2128 char *func_name;
30875e1c 2129{
30875e1c
SG
2130 struct symtab_and_line sal;
2131 struct breakpoint *b;
2132
6b038bd9 2133 INIT_SAL (&sal); /* initialize to zeroes */
30875e1c
SG
2134 if (func_name != NULL)
2135 {
2136 struct minimal_symbol *m;
2137
e8bf33c4 2138 m = lookup_minimal_symbol_text (func_name, NULL, (struct objfile *)NULL);
30875e1c 2139 if (m)
2d313932 2140 sal.pc = SYMBOL_VALUE_ADDRESS (m);
30875e1c
SG
2141 else
2142 return;
2143 }
6b038bd9 2144 sal.section = find_pc_overlay (sal.pc);
cd10c7e3 2145 b = set_raw_breakpoint (sal);
30875e1c
SG
2146 if (!b) return;
2147
80ba48f5 2148 b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
30875e1c
SG
2149 b->disposition = donttouch;
2150 b->enable = disabled;
2151 b->silent = 1;
80ba48f5
SG
2152 if (func_name)
2153 b->addr_string = strsave(func_name);
2154 b->number = internal_breakpoint_number--;
30875e1c 2155}
30875e1c 2156
39ce6829
PS
2157#endif /* #ifdef GET_LONGJMP_TARGET */
2158
30875e1c
SG
2159/* Call this routine when stepping and nexting to enable a breakpoint if we do
2160 a longjmp(). When we hit that breakpoint, call
2161 set_longjmp_resume_breakpoint() to figure out where we are going. */
2162
2163void
2164enable_longjmp_breakpoint()
2165{
80ba48f5
SG
2166 register struct breakpoint *b;
2167
2168 ALL_BREAKPOINTS (b)
2169 if (b->type == bp_longjmp)
9b280a7f
JG
2170 {
2171 b->enable = enabled;
6b038bd9 2172 check_duplicates (b->address, b->section);
9b280a7f 2173 }
30875e1c
SG
2174}
2175
2176void
2177disable_longjmp_breakpoint()
2178{
80ba48f5
SG
2179 register struct breakpoint *b;
2180
2181 ALL_BREAKPOINTS (b)
9b280a7f 2182 if ( b->type == bp_longjmp
80ba48f5 2183 || b->type == bp_longjmp_resume)
9b280a7f
JG
2184 {
2185 b->enable = disabled;
6b038bd9 2186 check_duplicates (b->address, b->section);
9b280a7f 2187 }
30875e1c
SG
2188}
2189
27b6a1fa
JL
2190#ifdef SOLIB_ADD
2191void
2192remove_solib_event_breakpoints ()
2193{
fa3764e2 2194 register struct breakpoint *b, *temp;
27b6a1fa 2195
fa3764e2 2196 ALL_BREAKPOINTS_SAFE (b, temp)
27b6a1fa
JL
2197 if (b->type == bp_shlib_event)
2198 delete_breakpoint (b);
2199}
2200
2201void
2202create_solib_event_breakpoint (address)
2203 CORE_ADDR address;
2204{
2205 struct breakpoint *b;
2206 struct symtab_and_line sal;
2207
6b038bd9 2208 INIT_SAL (&sal); /* initialize to zeroes */
27b6a1fa 2209 sal.pc = address;
6b038bd9 2210 sal.section = find_pc_overlay (sal.pc);
27b6a1fa
JL
2211 b = set_raw_breakpoint (sal);
2212 b->number = internal_breakpoint_number--;
2213 b->disposition = donttouch;
2214 b->type = bp_shlib_event;
2215}
fa3764e2
JL
2216
2217/* Try to reenable any breakpoints in shared libraries. */
2218void
2219re_enable_breakpoints_in_shlibs ()
2220{
2221 struct breakpoint *b;
2222
2223 ALL_BREAKPOINTS (b)
2224 if (b->enable == shlib_disabled)
2225 {
2226 char buf[1];
2227
2228 /* Do not reenable the breakpoint if the shared library
2229 is still not mapped in. */
2230 if (target_read_memory (b->address, buf, 1) == 0)
2231 b->enable = enabled;
2232 }
2233}
2234
27b6a1fa
JL
2235#endif
2236
b607efe7 2237static int
11054881
KH
2238hw_breakpoint_used_count()
2239{
2240 register struct breakpoint *b;
2241 int i = 0;
2242
2243 ALL_BREAKPOINTS (b)
2244 {
2245 if (b->type == bp_hardware_breakpoint && b->enable == enabled)
2246 i++;
2247 }
2248
2249 return i;
2250}
2251
b607efe7 2252static int
11054881
KH
2253hw_watchpoint_used_count(type, other_type_used)
2254 enum bptype type;
2255 int *other_type_used;
2256{
2257 register struct breakpoint *b;
2258 int i = 0;
2259
2260 *other_type_used = 0;
2261 ALL_BREAKPOINTS (b)
2262 {
2263 if (b->enable == enabled)
2264 {
2265 if (b->type == type) i++;
2266 else if ((b->type == bp_hardware_watchpoint ||
2267 b->type == bp_read_watchpoint ||
2268 b->type == bp_access_watchpoint)
2269 && b->enable == enabled)
2270 *other_type_used = 1;
2271 }
2272 }
2273 return i;
2274}
2275
30875e1c
SG
2276/* Call this after hitting the longjmp() breakpoint. Use this to set a new
2277 breakpoint at the target of the jmp_buf.
80ba48f5
SG
2278
2279 FIXME - This ought to be done by setting a temporary breakpoint that gets
2280 deleted automatically...
30875e1c
SG
2281*/
2282
2283void
2284set_longjmp_resume_breakpoint(pc, frame)
2285 CORE_ADDR pc;
706dc3ce 2286 struct frame_info *frame;
30875e1c 2287{
80ba48f5
SG
2288 register struct breakpoint *b;
2289
2290 ALL_BREAKPOINTS (b)
2291 if (b->type == bp_longjmp_resume)
2292 {
2293 b->address = pc;
2294 b->enable = enabled;
2295 if (frame != NULL)
706dc3ce 2296 b->frame = frame->frame;
80ba48f5
SG
2297 else
2298 b->frame = 0;
6b038bd9 2299 check_duplicates (b->address, b->section);
80ba48f5
SG
2300 return;
2301 }
30875e1c
SG
2302}
2303
bd5635a1
RP
2304/* Set a breakpoint that will evaporate an end of command
2305 at address specified by SAL.
2306 Restrict it to frame FRAME if FRAME is nonzero. */
2307
30875e1c
SG
2308struct breakpoint *
2309set_momentary_breakpoint (sal, frame, type)
bd5635a1 2310 struct symtab_and_line sal;
706dc3ce 2311 struct frame_info *frame;
30875e1c 2312 enum bptype type;
bd5635a1
RP
2313{
2314 register struct breakpoint *b;
2315 b = set_raw_breakpoint (sal);
30875e1c
SG
2316 b->type = type;
2317 b->enable = enabled;
2318 b->disposition = donttouch;
706dc3ce 2319 b->frame = (frame ? frame->frame : 0);
2b576293
C
2320
2321 /* If we're debugging a multi-threaded program, then we
2322 want momentary breakpoints to be active in only a
2323 single thread of control. */
2324 if (in_thread_list (inferior_pid))
2325 b->thread = pid_to_thread_id (inferior_pid);
2326
30875e1c 2327 return b;
bd5635a1
RP
2328}
2329
bd5635a1
RP
2330\f
2331/* Tell the user we have just set a breakpoint B. */
9f577285 2332
bd5635a1
RP
2333static void
2334mention (b)
2335 struct breakpoint *b;
2336{
9f577285
SS
2337 int say_where = 0;
2338
d2a85f11
JMD
2339 /* FIXME: This is misplaced; mention() is called by things (like hitting a
2340 watchpoint) other than breakpoint creation. It should be possible to
2341 clean this up and at the same time replace the random calls to
2342 breakpoint_changed with this hook, as has already been done for
2343 delete_breakpoint_hook and so on. */
754e5da2
SG
2344 if (create_breakpoint_hook)
2345 create_breakpoint_hook (b);
2346
30875e1c 2347 switch (b->type)
bd5635a1 2348 {
30875e1c 2349 case bp_watchpoint:
bd5635a1 2350 printf_filtered ("Watchpoint %d: ", b->number);
199b2450 2351 print_expression (b->exp, gdb_stdout);
30875e1c 2352 break;
999dd04b
JL
2353 case bp_hardware_watchpoint:
2354 printf_filtered ("Hardware watchpoint %d: ", b->number);
2355 print_expression (b->exp, gdb_stdout);
2356 break;
11054881
KH
2357 case bp_read_watchpoint:
2358 printf_filtered ("Hardware read watchpoint %d: ", b->number);
2359 print_expression (b->exp, gdb_stdout);
2360 break;
2361 case bp_access_watchpoint:
2362 printf_filtered ("Hardware access(read/write) watchpoint %d: ",b->number);
2363 print_expression (b->exp, gdb_stdout);
2364 break;
30875e1c 2365 case bp_breakpoint:
9f577285
SS
2366 printf_filtered ("Breakpoint %d", b->number);
2367 say_where = 1;
51b57ded 2368 break;
11054881 2369 case bp_hardware_breakpoint:
9f577285
SS
2370 printf_filtered ("Hardware assisted breakpoint %d", b->number);
2371 say_where = 1;
11054881 2372 break;
51b57ded
FF
2373 case bp_until:
2374 case bp_finish:
2375 case bp_longjmp:
2376 case bp_longjmp_resume:
fee933f1 2377 case bp_step_resume:
bcc37718 2378 case bp_through_sigtramp:
199b2450 2379 case bp_call_dummy:
999dd04b 2380 case bp_watchpoint_scope:
fa3764e2 2381 case bp_shlib_event:
51b57ded 2382 break;
bd5635a1 2383 }
9f577285
SS
2384 if (say_where)
2385 {
2386 if (addressprint || b->source_file == NULL)
2387 {
2388 printf_filtered (" at ");
2389 print_address_numeric (b->address, 1, gdb_stdout);
2390 }
2391 if (b->source_file)
2392 printf_filtered (": file %s, line %d.",
2393 b->source_file, b->line_number);
2394 }
bd5635a1
RP
2395 printf_filtered ("\n");
2396}
2397
bd5635a1
RP
2398\f
2399/* Set a breakpoint according to ARG (function, linenum or *address)
11054881
KH
2400 flag: first bit : 0 non-temporary, 1 temporary.
2401 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
bd5635a1
RP
2402
2403static void
11054881 2404break_command_1 (arg, flag, from_tty)
bd5635a1 2405 char *arg;
11054881 2406 int flag, from_tty;
bd5635a1 2407{
11054881 2408 int tempflag, hardwareflag;
bd5635a1
RP
2409 struct symtabs_and_lines sals;
2410 struct symtab_and_line sal;
2411 register struct expression *cond = 0;
2412 register struct breakpoint *b;
2413
2414 /* Pointers in arg to the start, and one past the end, of the condition. */
2415 char *cond_start = NULL;
fee933f1 2416 char *cond_end = NULL;
bd5635a1
RP
2417 /* Pointers in arg to the start, and one past the end,
2418 of the address part. */
2419 char *addr_start = NULL;
fee933f1 2420 char *addr_end = NULL;
d889f6b7 2421 struct cleanup *old_chain;
fee933f1 2422 struct cleanup *canonical_strings_chain = NULL;
d889f6b7 2423 char **canonical = (char **)NULL;
bd5635a1 2424 int i;
199b2450 2425 int thread;
bd5635a1 2426
e8bf33c4
JK
2427 hardwareflag = flag & BP_HARDWAREFLAG;
2428 tempflag = flag & BP_TEMPFLAG;
11054881 2429
bd5635a1
RP
2430 sals.sals = NULL;
2431 sals.nelts = 0;
2432
6b038bd9 2433 INIT_SAL (&sal); /* initialize to zeroes */
bd5635a1
RP
2434
2435 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2436
2437 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
2438 && (arg[2] == ' ' || arg[2] == '\t')))
2439 {
2440 if (default_breakpoint_valid)
2441 {
2442 sals.sals = (struct symtab_and_line *)
2443 xmalloc (sizeof (struct symtab_and_line));
2444 sal.pc = default_breakpoint_address;
2445 sal.line = default_breakpoint_line;
2446 sal.symtab = default_breakpoint_symtab;
6b038bd9 2447 sal.section = find_pc_overlay (sal.pc);
bd5635a1
RP
2448 sals.sals[0] = sal;
2449 sals.nelts = 1;
2450 }
2451 else
2452 error ("No default breakpoint address now.");
2453 }
2454 else
2455 {
2456 addr_start = arg;
2457
2458 /* Force almost all breakpoints to be in terms of the
2459 current_source_symtab (which is decode_line_1's default). This
2460 should produce the results we want almost all of the time while
2461 leaving default_breakpoint_* alone. */
2462 if (default_breakpoint_valid
2463 && (!current_source_symtab
2464 || (arg && (*arg == '+' || *arg == '-'))))
2465 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
d889f6b7 2466 default_breakpoint_line, &canonical);
bd5635a1 2467 else
d889f6b7 2468 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
bd5635a1
RP
2469
2470 addr_end = arg;
2471 }
2472
2473 if (! sals.nelts)
2474 return;
2475
d889f6b7
JK
2476 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2477 the following `for' loop errors out. */
2478 old_chain = make_cleanup (free, sals.sals);
2479 if (canonical != (char **)NULL)
2480 {
2481 make_cleanup (free, canonical);
2482 canonical_strings_chain = make_cleanup (null_cleanup, 0);
2483 for (i = 0; i < sals.nelts; i++)
2484 {
2485 if (canonical[i] != NULL)
2486 make_cleanup (free, canonical[i]);
2487 }
2488 }
2489
199b2450
TL
2490 thread = -1; /* No specific thread yet */
2491
30875e1c
SG
2492 /* Resolve all line numbers to PC's, and verify that conditions
2493 can be parsed, before setting any breakpoints. */
bd5635a1
RP
2494 for (i = 0; i < sals.nelts; i++)
2495 {
199b2450
TL
2496 char *tok, *end_tok;
2497 int toklen;
2498
30875e1c 2499 resolve_sal_pc (&sals.sals[i]);
bd5635a1 2500
199b2450
TL
2501 tok = arg;
2502
2503 while (tok && *tok)
bd5635a1 2504 {
199b2450
TL
2505 while (*tok == ' ' || *tok == '\t')
2506 tok++;
2507
2508 end_tok = tok;
2509
2510 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
2511 end_tok++;
2512
2513 toklen = end_tok - tok;
2514
2515 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
2516 {
2517 tok = cond_start = end_tok + 1;
2518 cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
2519 cond_end = tok;
2520 }
2521 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
bd5635a1 2522 {
199b2450
TL
2523 char *tmptok;
2524
2525 tok = end_tok + 1;
2526 tmptok = tok;
2527 thread = strtol (tok, &tok, 0);
2528 if (tok == tmptok)
2529 error ("Junk after thread keyword.");
2530 if (!valid_thread_id (thread))
2531 error ("Unknown thread %d\n", thread);
bd5635a1
RP
2532 }
2533 else
2534 error ("Junk at end of arguments.");
2535 }
bd5635a1 2536 }
11054881
KH
2537 if (hardwareflag)
2538 {
557f3a0e
SS
2539 int i, target_resources_ok;
2540
2541 i = hw_breakpoint_used_count ();
2542 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
2543 bp_hardware_breakpoint, i + sals.nelts, 0);
11054881
KH
2544 if (target_resources_ok == 0)
2545 error ("No hardware breakpoint support in the target.");
2546 else if (target_resources_ok < 0)
2547 error ("Hardware breakpoints used exceeds limit.");
2548 }
bd5635a1 2549
d889f6b7
JK
2550 /* Remove the canonical strings from the cleanup, they are needed below. */
2551 if (canonical != (char **)NULL)
2552 discard_cleanups (canonical_strings_chain);
2553
30875e1c 2554 /* Now set all the breakpoints. */
bd5635a1
RP
2555 for (i = 0; i < sals.nelts; i++)
2556 {
2557 sal = sals.sals[i];
2558
2559 if (from_tty)
6b038bd9 2560 describe_other_breakpoints (sal.pc, sal.section);
bd5635a1
RP
2561
2562 b = set_raw_breakpoint (sal);
2563 set_breakpoint_count (breakpoint_count + 1);
2564 b->number = breakpoint_count;
11054881 2565 b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint;
bd5635a1 2566 b->cond = cond;
199b2450 2567 b->thread = thread;
0a97f6c4 2568
d889f6b7
JK
2569 /* If a canonical line spec is needed use that instead of the
2570 command string. */
2571 if (canonical != (char **)NULL && canonical[i] != NULL)
2572 b->addr_string = canonical[i];
2573 else if (addr_start)
bd5635a1
RP
2574 b->addr_string = savestring (addr_start, addr_end - addr_start);
2575 if (cond_start)
2576 b->cond_string = savestring (cond_start, cond_end - cond_start);
2577
30875e1c 2578 b->enable = enabled;
e8bf33c4 2579 b->disposition = tempflag ? del : donttouch;
bd5635a1
RP
2580 mention (b);
2581 }
2582
2583 if (sals.nelts > 1)
2584 {
833e0d94
JK
2585 printf_filtered ("Multiple breakpoints were set.\n");
2586 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
bd5635a1 2587 }
d889f6b7 2588 do_cleanups (old_chain);
bd5635a1
RP
2589}
2590
30875e1c
SG
2591/* Helper function for break_command_1 and disassemble_command. */
2592
2593void
2594resolve_sal_pc (sal)
2595 struct symtab_and_line *sal;
2596{
2597 CORE_ADDR pc;
2598
6b038bd9 2599 if (sal->pc == 0 && sal->symtab != NULL)
30875e1c 2600 {
895cc8ab 2601 if (!find_line_pc (sal->symtab, sal->line, &pc))
30875e1c
SG
2602 error ("No line %d in file \"%s\".",
2603 sal->line, sal->symtab->filename);
2604 sal->pc = pc;
2605 }
6b038bd9
DT
2606
2607 if (sal->section == 0 && sal->symtab != NULL)
2608 {
2609 struct blockvector *bv;
2610 struct block *b;
2611 struct symbol *sym;
2612 int index;
2613
2614 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
895cc8ab 2615 if (bv != NULL)
6b038bd9 2616 {
895cc8ab
KS
2617 b = BLOCKVECTOR_BLOCK (bv, index);
2618 sym = block_function (b);
2619 if (sym != NULL)
2620 {
2621 fixup_symbol_section (sym, sal->symtab->objfile);
6ee2da94
FCE
2622 sal->section = SYMBOL_BFD_SECTION (sym);
2623 }
2624 else
2625 {
2626 /* It really is worthwhile to have the section, so we'll just
2627 have to look harder. This case can be executed if we have
2628 line numbers but no functions (as can happen in assembly
2629 source). */
2630
2631 struct minimal_symbol *msym;
2632
2633 msym = lookup_minimal_symbol_by_pc (sal->pc);
2634 if (msym)
2635 sal->section = SYMBOL_BFD_SECTION (msym);
895cc8ab 2636 }
6b038bd9
DT
2637 }
2638 }
30875e1c
SG
2639}
2640
bd5635a1
RP
2641void
2642break_command (arg, from_tty)
2643 char *arg;
2644 int from_tty;
2645{
2646 break_command_1 (arg, 0, from_tty);
2647}
2648
2649static void
2650tbreak_command (arg, from_tty)
2651 char *arg;
2652 int from_tty;
2653{
11054881
KH
2654 break_command_1 (arg, BP_TEMPFLAG, from_tty);
2655}
2656
2657static void
2658hbreak_command (arg, from_tty)
2659 char *arg;
2660 int from_tty;
2661{
2662 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
2663}
2664
2665static void
2666thbreak_command (arg, from_tty)
2667 char *arg;
2668 int from_tty;
2669{
2670 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
bd5635a1
RP
2671}
2672
bdbd5f50 2673/* ARGSUSED */
11054881
KH
2674/* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write)
2675*/
bd5635a1 2676static void
11054881 2677watch_command_1 (arg, accessflag, from_tty)
bd5635a1 2678 char *arg;
11054881 2679 int accessflag;
bd5635a1
RP
2680 int from_tty;
2681{
2682 struct breakpoint *b;
2683 struct symtab_and_line sal;
f266e564
JK
2684 struct expression *exp;
2685 struct block *exp_valid_block;
11054881 2686 struct value *val, *mark;
b607efe7
FF
2687 struct frame_info *frame;
2688 struct frame_info *prev_frame = NULL;
11054881
KH
2689 char *exp_start = NULL;
2690 char *exp_end = NULL;
2691 char *tok, *end_tok;
2692 int toklen;
2693 char *cond_start = NULL;
2694 char *cond_end = NULL;
2695 struct expression *cond = NULL;
6b038bd9 2696 int i, other_type_used, target_resources_ok = 0;
11054881
KH
2697 enum bptype bp_type;
2698 int mem_cnt = 0;
bd5635a1 2699
6b038bd9 2700 INIT_SAL (&sal); /* initialize to zeroes */
bd5635a1 2701
f266e564
JK
2702 /* Parse arguments. */
2703 innermost_block = NULL;
11054881
KH
2704 exp_start = arg;
2705 exp = parse_exp_1 (&arg, 0, 0);
2706 exp_end = arg;
f266e564 2707 exp_valid_block = innermost_block;
11054881 2708 mark = value_mark ();
f266e564
JK
2709 val = evaluate_expression (exp);
2710 release_value (val);
2d313932
JK
2711 if (VALUE_LAZY (val))
2712 value_fetch_lazy (val);
f266e564 2713
11054881
KH
2714 tok = arg;
2715 while (*tok == ' ' || *tok == '\t')
2716 tok++;
2717 end_tok = tok;
2718
2719 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
2720 end_tok++;
2721
2722 toklen = end_tok - tok;
2723 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
2724 {
2725 tok = cond_start = end_tok + 1;
2726 cond = parse_exp_1 (&tok, 0, 0);
2727 cond_end = tok;
2728 }
2729 if (*tok)
2730 error("Junk at end of command.");
2731
2732 if (accessflag == 1) bp_type = bp_read_watchpoint;
2733 else if (accessflag == 2) bp_type = bp_access_watchpoint;
2734 else bp_type = bp_hardware_watchpoint;
2735
2736 mem_cnt = can_use_hardware_watchpoint (val);
2737 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
2738 error ("Expression cannot be implemented with read/access watchpoint.");
2739 if (mem_cnt != 0) {
2740 i = hw_watchpoint_used_count (bp_type, &other_type_used);
2741 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
2742 bp_type, i + mem_cnt, other_type_used);
2743 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
2744 error ("Target does not have this type of hardware watchpoint support.");
2745 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
2746 error ("Target resources have been allocated for other types of watchpoints.");
2747 }
2748
f266e564 2749 /* Now set up the breakpoint. */
bd5635a1
RP
2750 b = set_raw_breakpoint (sal);
2751 set_breakpoint_count (breakpoint_count + 1);
2752 b->number = breakpoint_count;
30875e1c 2753 b->disposition = donttouch;
f266e564
JK
2754 b->exp = exp;
2755 b->exp_valid_block = exp_valid_block;
11054881 2756 b->exp_string = savestring (exp_start, exp_end - exp_start);
f266e564 2757 b->val = val;
11054881
KH
2758 b->cond = cond;
2759 if (cond_start)
2760 b->cond_string = savestring (cond_start, cond_end - cond_start);
2761 else
2762 b->cond_string = 0;
2763
999dd04b
JL
2764 frame = block_innermost_frame (exp_valid_block);
2765 if (frame)
2766 {
2767 prev_frame = get_prev_frame (frame);
706dc3ce 2768 b->watchpoint_frame = frame->frame;
999dd04b
JL
2769 }
2770 else
9e8db445 2771 b->watchpoint_frame = (CORE_ADDR)0;
999dd04b 2772
11054881
KH
2773 if (mem_cnt && target_resources_ok > 0)
2774 b->type = bp_type;
999dd04b
JL
2775 else
2776 b->type = bp_watchpoint;
2777
2778 /* If the expression is "local", then set up a "watchpoint scope"
2779 breakpoint at the point where we've left the scope of the watchpoint
2780 expression. */
2781 if (innermost_block)
2782 {
999dd04b
JL
2783 if (prev_frame)
2784 {
6b038bd9
DT
2785 struct breakpoint *scope_breakpoint;
2786 struct symtab_and_line scope_sal;
2787
2788 INIT_SAL (&scope_sal); /* initialize to zeroes */
2789 scope_sal.pc = get_frame_pc (prev_frame);
2790 scope_sal.section = find_pc_overlay (scope_sal.pc);
2791
999dd04b
JL
2792 scope_breakpoint = set_raw_breakpoint (scope_sal);
2793 set_breakpoint_count (breakpoint_count + 1);
2794 scope_breakpoint->number = breakpoint_count;
2795
2796 scope_breakpoint->type = bp_watchpoint_scope;
2797 scope_breakpoint->enable = enabled;
2798
2799 /* Automatically delete the breakpoint when it hits. */
e8bf33c4 2800 scope_breakpoint->disposition = del;
999dd04b
JL
2801
2802 /* Only break in the proper frame (help with recursion). */
2803 scope_breakpoint->frame = prev_frame->frame;
2804
2805 /* Set the address at which we will stop. */
2806 scope_breakpoint->address = get_frame_pc (prev_frame);
2807
2808 /* The scope breakpoint is related to the watchpoint. We
2809 will need to act on them together. */
2810 b->related_breakpoint = scope_breakpoint;
2811 }
2812 }
11054881 2813 value_free_to_mark (mark);
bd5635a1
RP
2814 mention (b);
2815}
999dd04b 2816
11054881
KH
2817/* Return count of locations need to be watched and can be handled
2818 in hardware. If the watchpoint can not be handled
999dd04b
JL
2819 in hardware return zero. */
2820
2821static int
11054881
KH
2822can_use_hardware_watchpoint (v)
2823 struct value *v;
999dd04b 2824{
11054881 2825 int found_memory_cnt = 0;
999dd04b
JL
2826
2827 /* Make sure all the intermediate values are in memory. Also make sure
2828 we found at least one memory expression. Guards against watch 0x12345,
2829 which is meaningless, but could cause errors if one tries to insert a
2830 hardware watchpoint for the constant expression. */
11054881 2831 for ( ; v; v = v->next)
999dd04b 2832 {
11054881
KH
2833 if (v->lval == lval_memory)
2834 {
2835 if (TYPE_LENGTH (VALUE_TYPE (v)) <= REGISTER_SIZE)
2836 found_memory_cnt++;
2837 }
2838 else if (v->lval != not_lval && v->modifiable == 0)
999dd04b 2839 return 0;
999dd04b
JL
2840 }
2841
2842 /* The expression itself looks suitable for using a hardware
2843 watchpoint, but give the target machine a chance to reject it. */
11054881
KH
2844 return found_memory_cnt;
2845}
2846
2847static void watch_command (arg, from_tty)
2848 char *arg;
2849 int from_tty;
2850{
2851 watch_command_1 (arg, 0, from_tty);
2852}
2853
2854static void rwatch_command (arg, from_tty)
2855 char *arg;
2856 int from_tty;
2857{
2858 watch_command_1 (arg, 1, from_tty);
2859}
2860
2861static void awatch_command (arg, from_tty)
2862 char *arg;
2863 int from_tty;
2864{
2865 watch_command_1 (arg, 2, from_tty);
999dd04b
JL
2866}
2867
bd5635a1 2868\f
706dc3ce
JL
2869/* Helper routine for the until_command routine in infcmd.c. Here
2870 because it uses the mechanisms of breakpoints. */
2871
bdbd5f50 2872/* ARGSUSED */
bd5635a1
RP
2873void
2874until_break_command (arg, from_tty)
2875 char *arg;
2876 int from_tty;
2877{
2878 struct symtabs_and_lines sals;
2879 struct symtab_and_line sal;
706dc3ce 2880 struct frame_info *prev_frame = get_prev_frame (selected_frame);
30875e1c
SG
2881 struct breakpoint *breakpoint;
2882 struct cleanup *old_chain;
bd5635a1
RP
2883
2884 clear_proceed_status ();
2885
2886 /* Set a breakpoint where the user wants it and at return from
2887 this function */
2888
2889 if (default_breakpoint_valid)
2890 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
d889f6b7 2891 default_breakpoint_line, (char ***)NULL);
bd5635a1 2892 else
d889f6b7 2893 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL);
bd5635a1
RP
2894
2895 if (sals.nelts != 1)
2896 error ("Couldn't get information on specified line.");
2897
2898 sal = sals.sals[0];
c8950965 2899 free ((PTR)sals.sals); /* malloc'd, so freed */
bd5635a1
RP
2900
2901 if (*arg)
2902 error ("Junk at end of arguments.");
2903
30875e1c 2904 resolve_sal_pc (&sal);
bd5635a1 2905
30875e1c 2906 breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
bd5635a1 2907
ad3b8c4a 2908 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
30875e1c 2909
bd5635a1
RP
2910 /* Keep within the current frame */
2911
2912 if (prev_frame)
2913 {
706dc3ce
JL
2914 sal = find_pc_line (prev_frame->pc, 0);
2915 sal.pc = prev_frame->pc;
30875e1c 2916 breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
ad3b8c4a 2917 make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
bd5635a1
RP
2918 }
2919
d7e7e851 2920 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
30875e1c 2921 do_cleanups(old_chain);
bd5635a1
RP
2922}
2923\f
bdbd5f50
JG
2924#if 0
2925/* These aren't used; I don't konw what they were for. */
bd5635a1
RP
2926/* Set a breakpoint at the catch clause for NAME. */
2927static int
2928catch_breakpoint (name)
2929 char *name;
2930{
2931}
2932
2933static int
2934disable_catch_breakpoint ()
2935{
2936}
2937
2938static int
2939delete_catch_breakpoint ()
2940{
2941}
2942
2943static int
2944enable_catch_breakpoint ()
2945{
2946}
bdbd5f50 2947#endif /* 0 */
bd5635a1
RP
2948
2949struct sal_chain
2950{
2951 struct sal_chain *next;
2952 struct symtab_and_line sal;
2953};
2954
bdbd5f50
JG
2955#if 0
2956/* This isn't used; I don't know what it was for. */
bd5635a1
RP
2957/* For each catch clause identified in ARGS, run FUNCTION
2958 with that clause as an argument. */
2959static struct symtabs_and_lines
2960map_catch_names (args, function)
2961 char *args;
2962 int (*function)();
2963{
2964 register char *p = args;
2965 register char *p1;
2966 struct symtabs_and_lines sals;
bdbd5f50 2967#if 0
bd5635a1 2968 struct sal_chain *sal_chain = 0;
bdbd5f50 2969#endif
bd5635a1
RP
2970
2971 if (p == 0)
2972 error_no_arg ("one or more catch names");
2973
2974 sals.nelts = 0;
2975 sals.sals = NULL;
2976
2977 while (*p)
2978 {
2979 p1 = p;
2980 /* Don't swallow conditional part. */
2981 if (p1[0] == 'i' && p1[1] == 'f'
2982 && (p1[2] == ' ' || p1[2] == '\t'))
2983 break;
2984
2985 if (isalpha (*p1))
2986 {
2987 p1++;
2988 while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
2989 p1++;
2990 }
2991
2992 if (*p1 && *p1 != ' ' && *p1 != '\t')
2993 error ("Arguments must be catch names.");
2994
2995 *p1 = 0;
2996#if 0
2997 if (function (p))
2998 {
6b038bd9
DT
2999 struct sal_chain *next = (struct sal_chain *)
3000 alloca (sizeof (struct sal_chain));
bd5635a1
RP
3001 next->next = sal_chain;
3002 next->sal = get_catch_sal (p);
3003 sal_chain = next;
3004 goto win;
3005 }
3006#endif
199b2450 3007 printf_unfiltered ("No catch clause for exception %s.\n", p);
bdbd5f50 3008#if 0
bd5635a1 3009 win:
bdbd5f50 3010#endif
bd5635a1
RP
3011 p = p1;
3012 while (*p == ' ' || *p == '\t') p++;
3013 }
3014}
bdbd5f50 3015#endif /* 0 */
bd5635a1
RP
3016
3017/* This shares a lot of code with `print_frame_label_vars' from stack.c. */
3018
3019static struct symtabs_and_lines
3020get_catch_sals (this_level_only)
3021 int this_level_only;
3022{
bd5635a1 3023 register struct blockvector *bl;
777bef06 3024 register struct block *block;
bd5635a1 3025 int index, have_default = 0;
777bef06 3026 CORE_ADDR pc;
bd5635a1
RP
3027 struct symtabs_and_lines sals;
3028 struct sal_chain *sal_chain = 0;
3029 char *blocks_searched;
3030
777bef06
JK
3031 /* Not sure whether an error message is always the correct response,
3032 but it's better than a core dump. */
3033 if (selected_frame == NULL)
3034 error ("No selected frame.");
3035 block = get_frame_block (selected_frame);
706dc3ce 3036 pc = selected_frame->pc;
777bef06 3037
bd5635a1
RP
3038 sals.nelts = 0;
3039 sals.sals = NULL;
3040
3041 if (block == 0)
3042 error ("No symbol table info available.\n");
3043
3044 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
3045 blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
4ed3a9ea 3046 memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
bd5635a1
RP
3047
3048 while (block != 0)
3049 {
3050 CORE_ADDR end = BLOCK_END (block) - 4;
3051 int last_index;
3052
3053 if (bl != blockvector_for_pc (end, &index))
3054 error ("blockvector blotch");
3055 if (BLOCKVECTOR_BLOCK (bl, index) != block)
3056 error ("blockvector botch");
3057 last_index = BLOCKVECTOR_NBLOCKS (bl);
3058 index += 1;
3059
3060 /* Don't print out blocks that have gone by. */
3061 while (index < last_index
3062 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
3063 index++;
3064
3065 while (index < last_index
3066 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
3067 {
3068 if (blocks_searched[index] == 0)
3069 {
3070 struct block *b = BLOCKVECTOR_BLOCK (bl, index);
3071 int nsyms;
3072 register int i;
3073 register struct symbol *sym;
3074
3075 nsyms = BLOCK_NSYMS (b);
3076
3077 for (i = 0; i < nsyms; i++)
3078 {
3079 sym = BLOCK_SYM (b, i);
2d313932 3080 if (STREQ (SYMBOL_NAME (sym), "default"))
bd5635a1
RP
3081 {
3082 if (have_default)
3083 continue;
3084 have_default = 1;
3085 }
3086 if (SYMBOL_CLASS (sym) == LOC_LABEL)
3087 {
3088 struct sal_chain *next = (struct sal_chain *)
3089 alloca (sizeof (struct sal_chain));
3090 next->next = sal_chain;
3091 next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
3092 sal_chain = next;
3093 }
3094 }
3095 blocks_searched[index] = 1;
3096 }
3097 index++;
3098 }
3099 if (have_default)
3100 break;
3101 if (sal_chain && this_level_only)
3102 break;
3103
3104 /* After handling the function's top-level block, stop.
3105 Don't continue to its superblock, the block of
3106 per-file symbols. */
3107 if (BLOCK_FUNCTION (block))
3108 break;
3109 block = BLOCK_SUPERBLOCK (block);
3110 }
3111
3112 if (sal_chain)
3113 {
3114 struct sal_chain *tmp_chain;
3115
3116 /* Count the number of entries. */
3117 for (index = 0, tmp_chain = sal_chain; tmp_chain;
3118 tmp_chain = tmp_chain->next)
3119 index++;
3120
3121 sals.nelts = index;
3122 sals.sals = (struct symtab_and_line *)
3123 xmalloc (index * sizeof (struct symtab_and_line));
3124 for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
3125 sals.sals[index] = sal_chain->sal;
3126 }
3127
3128 return sals;
3129}
3130
3131/* Commands to deal with catching exceptions. */
3132
30875e1c 3133static void
bd5635a1
RP
3134catch_command_1 (arg, tempflag, from_tty)
3135 char *arg;
3136 int tempflag;
3137 int from_tty;
3138{
3139 /* First, translate ARG into something we can deal with in terms
3140 of breakpoints. */
3141
3142 struct symtabs_and_lines sals;
3143 struct symtab_and_line sal;
3144 register struct expression *cond = 0;
3145 register struct breakpoint *b;
3146 char *save_arg;
3147 int i;
bd5635a1 3148
6b038bd9 3149 INIT_SAL (&sal); /* initialize to zeroes */
bd5635a1
RP
3150
3151 /* If no arg given, or if first arg is 'if ', all active catch clauses
3152 are breakpointed. */
3153
3154 if (!arg || (arg[0] == 'i' && arg[1] == 'f'
3155 && (arg[2] == ' ' || arg[2] == '\t')))
3156 {
3157 /* Grab all active catch clauses. */
3158 sals = get_catch_sals (0);
3159 }
3160 else
3161 {
3162 /* Grab selected catch clauses. */
fe675038 3163 error ("catch NAME not implemented");
bdbd5f50
JG
3164#if 0
3165 /* This isn't used; I don't know what it was for. */
bd5635a1 3166 sals = map_catch_names (arg, catch_breakpoint);
bdbd5f50 3167#endif
bd5635a1
RP
3168 }
3169
3170 if (! sals.nelts)
3171 return;
3172
3173 save_arg = arg;
3174 for (i = 0; i < sals.nelts; i++)
3175 {
30875e1c 3176 resolve_sal_pc (&sals.sals[i]);
bd5635a1
RP
3177
3178 while (arg && *arg)
3179 {
3180 if (arg[0] == 'i' && arg[1] == 'f'
3181 && (arg[2] == ' ' || arg[2] == '\t'))
30875e1c
SG
3182 cond = parse_exp_1 ((arg += 2, &arg),
3183 block_for_pc (sals.sals[i].pc), 0);
bd5635a1
RP
3184 else
3185 error ("Junk at end of arguments.");
3186 }
3187 arg = save_arg;
bd5635a1
RP
3188 }
3189
3190 for (i = 0; i < sals.nelts; i++)
3191 {
3192 sal = sals.sals[i];
3193
3194 if (from_tty)
6b038bd9 3195 describe_other_breakpoints (sal.pc, sal.section);
bd5635a1
RP
3196
3197 b = set_raw_breakpoint (sal);
30875e1c
SG
3198 set_breakpoint_count (breakpoint_count + 1);
3199 b->number = breakpoint_count;
3200 b->type = bp_breakpoint;
bd5635a1 3201 b->cond = cond;
30875e1c 3202 b->enable = enabled;
e8bf33c4 3203 b->disposition = tempflag ? del : donttouch;
bd5635a1 3204
d889f6b7 3205 mention (b);
bd5635a1
RP
3206 }
3207
3208 if (sals.nelts > 1)
3209 {
199b2450
TL
3210 printf_unfiltered ("Multiple breakpoints were set.\n");
3211 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
bd5635a1 3212 }
c8950965 3213 free ((PTR)sals.sals);
bd5635a1
RP
3214}
3215
e8bf33c4
JK
3216/* Used by the gui, could be made a worker for other things. */
3217
3218struct breakpoint *
3219set_breakpoint_sal (sal)
6b038bd9 3220 struct symtab_and_line sal;
e8bf33c4
JK
3221{
3222 struct breakpoint *b;
3223 b = set_raw_breakpoint (sal);
3224 set_breakpoint_count (breakpoint_count + 1);
3225 b->number = breakpoint_count;
3226 b->type = bp_breakpoint;
3227 b->cond = 0;
3228 b->thread = -1;
3229 return b;
3230}
3231
bdbd5f50
JG
3232#if 0
3233/* These aren't used; I don't know what they were for. */
bd5635a1
RP
3234/* Disable breakpoints on all catch clauses described in ARGS. */
3235static void
3236disable_catch (args)
3237 char *args;
3238{
3239 /* Map the disable command to catch clauses described in ARGS. */
3240}
3241
3242/* Enable breakpoints on all catch clauses described in ARGS. */
3243static void
3244enable_catch (args)
3245 char *args;
3246{
3247 /* Map the disable command to catch clauses described in ARGS. */
3248}
3249
3250/* Delete breakpoints on all catch clauses in the active scope. */
3251static void
3252delete_catch (args)
3253 char *args;
3254{
3255 /* Map the delete command to catch clauses described in ARGS. */
3256}
bdbd5f50 3257#endif /* 0 */
bd5635a1
RP
3258
3259static void
3260catch_command (arg, from_tty)
3261 char *arg;
3262 int from_tty;
3263{
3264 catch_command_1 (arg, 0, from_tty);
3265}
3266\f
3267static void
3268clear_command (arg, from_tty)
3269 char *arg;
3270 int from_tty;
3271{
3272 register struct breakpoint *b, *b1;
3273 struct symtabs_and_lines sals;
3274 struct symtab_and_line sal;
3275 register struct breakpoint *found;
3276 int i;
3277
3278 if (arg)
3279 {
3280 sals = decode_line_spec (arg, 1);
3281 }
3282 else
3283 {
6b038bd9
DT
3284 sals.sals = (struct symtab_and_line *)
3285 xmalloc (sizeof (struct symtab_and_line));
3286 INIT_SAL (&sal); /* initialize to zeroes */
bd5635a1
RP
3287 sal.line = default_breakpoint_line;
3288 sal.symtab = default_breakpoint_symtab;
bd5635a1
RP
3289 if (sal.symtab == 0)
3290 error ("No source file specified.");
3291
3292 sals.sals[0] = sal;
3293 sals.nelts = 1;
3294 }
3295
3296 for (i = 0; i < sals.nelts; i++)
3297 {
3298 /* If exact pc given, clear bpts at that pc.
3299 But if sal.pc is zero, clear all bpts on specified line. */
3300 sal = sals.sals[i];
3301 found = (struct breakpoint *) 0;
6b038bd9 3302
bd5635a1 3303 while (breakpoint_chain
d889f6b7 3304 && (sal.pc
6b038bd9
DT
3305 ? (breakpoint_chain->address == sal.pc &&
3306 (overlay_debugging == 0 ||
3307 breakpoint_chain->section == sal.section))
d889f6b7
JK
3308 : (breakpoint_chain->source_file != NULL
3309 && sal.symtab != NULL
3310 && STREQ (breakpoint_chain->source_file,
3311 sal.symtab->filename)
bd5635a1
RP
3312 && breakpoint_chain->line_number == sal.line)))
3313 {
3314 b1 = breakpoint_chain;
3315 breakpoint_chain = b1->next;
3316 b1->next = found;
3317 found = b1;
3318 }
3319
3320 ALL_BREAKPOINTS (b)
3321 while (b->next
30875e1c 3322 && b->next->type != bp_watchpoint
999dd04b 3323 && b->next->type != bp_hardware_watchpoint
11054881
KH
3324 && b->next->type != bp_read_watchpoint
3325 && b->next->type != bp_access_watchpoint
d889f6b7 3326 && (sal.pc
6b038bd9
DT
3327 ? (b->next->address == sal.pc &&
3328 (overlay_debugging == 0 ||
3329 b->next->section == sal.section))
d889f6b7
JK
3330 : (b->next->source_file != NULL
3331 && sal.symtab != NULL
3332 && STREQ (b->next->source_file, sal.symtab->filename)
bd5635a1
RP
3333 && b->next->line_number == sal.line)))
3334 {
3335 b1 = b->next;
3336 b->next = b1->next;
3337 b1->next = found;
3338 found = b1;
3339 }
3340
3341 if (found == 0)
3342 {
3343 if (arg)
3344 error ("No breakpoint at %s.", arg);
3345 else
3346 error ("No breakpoint at this line.");
3347 }
3348
3349 if (found->next) from_tty = 1; /* Always report if deleted more than one */
199b2450 3350 if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6c803036 3351 breakpoints_changed ();
bd5635a1
RP
3352 while (found)
3353 {
199b2450 3354 if (from_tty) printf_unfiltered ("%d ", found->number);
bd5635a1
RP
3355 b1 = found->next;
3356 delete_breakpoint (found);
3357 found = b1;
3358 }
199b2450 3359 if (from_tty) putchar_unfiltered ('\n');
bd5635a1 3360 }
c8950965 3361 free ((PTR)sals.sals);
bd5635a1
RP
3362}
3363\f
e51481f9
JL
3364/* Delete breakpoint in BS if they are `delete' breakpoints and
3365 all breakpoints that are marked for deletion, whether hit or not.
bd5635a1
RP
3366 This is called after any breakpoint is hit, or after errors. */
3367
3368void
3369breakpoint_auto_delete (bs)
3370 bpstat bs;
3371{
e51481f9
JL
3372 struct breakpoint *b, *temp;
3373
bd5635a1 3374 for (; bs; bs = bs->next)
e8bf33c4 3375 if (bs->breakpoint_at && bs->breakpoint_at->disposition == del
cef4c2e7 3376 && bs->stop)
bd5635a1 3377 delete_breakpoint (bs->breakpoint_at);
e51481f9
JL
3378
3379 ALL_BREAKPOINTS_SAFE (b, temp)
3380 {
3381 if (b->disposition == del_at_next_stop)
3382 delete_breakpoint (b);
3383 }
bd5635a1
RP
3384}
3385
3386/* Delete a breakpoint and clean up all traces of it in the data structures. */
3387
30875e1c 3388void
bd5635a1
RP
3389delete_breakpoint (bpt)
3390 struct breakpoint *bpt;
3391{
3392 register struct breakpoint *b;
3393 register bpstat bs;
3394
754e5da2
SG
3395 if (delete_breakpoint_hook)
3396 delete_breakpoint_hook (bpt);
3397
bd5635a1 3398 if (bpt->inserted)
999dd04b
JL
3399 remove_breakpoint (bpt);
3400
bd5635a1
RP
3401 if (breakpoint_chain == bpt)
3402 breakpoint_chain = bpt->next;
3403
3404 ALL_BREAKPOINTS (b)
3405 if (b->next == bpt)
3406 {
3407 b->next = bpt->next;
3408 break;
3409 }
3410
6b038bd9 3411 check_duplicates (bpt->address, bpt->section);
fe675038
JK
3412 /* If this breakpoint was inserted, and there is another breakpoint
3413 at the same address, we need to insert the other breakpoint. */
999dd04b 3414 if (bpt->inserted
11054881
KH
3415 && bpt->type != bp_hardware_watchpoint
3416 && bpt->type != bp_read_watchpoint
3417 && bpt->type != bp_access_watchpoint)
fe675038
JK
3418 {
3419 ALL_BREAKPOINTS (b)
ebad9e90 3420 if (b->address == bpt->address
6b038bd9 3421 && b->section == bpt->section
ebad9e90 3422 && !b->duplicate
fa3764e2
JL
3423 && b->enable != disabled
3424 && b->enable != shlib_disabled)
fe675038
JK
3425 {
3426 int val;
3427 val = target_insert_breakpoint (b->address, b->shadow_contents);
3428 if (val != 0)
3429 {
05052b63 3430 target_terminal_ours_for_output ();
199b2450 3431 fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
fe675038
JK
3432 memory_error (val, b->address); /* which bombs us out */
3433 }
3434 else
3435 b->inserted = 1;
3436 }
3437 }
bd5635a1
RP
3438
3439 free_command_lines (&bpt->commands);
3440 if (bpt->cond)
d889f6b7 3441 free (bpt->cond);
bd5635a1 3442 if (bpt->cond_string != NULL)
d889f6b7 3443 free (bpt->cond_string);
bd5635a1 3444 if (bpt->addr_string != NULL)
d889f6b7 3445 free (bpt->addr_string);
39ce6829
PS
3446 if (bpt->exp != NULL)
3447 free (bpt->exp);
0eaaa46a 3448 if (bpt->exp_string != NULL)
d889f6b7 3449 free (bpt->exp_string);
39ce6829
PS
3450 if (bpt->val != NULL)
3451 value_free (bpt->val);
d889f6b7
JK
3452 if (bpt->source_file != NULL)
3453 free (bpt->source_file);
bd5635a1 3454
bd5635a1 3455 /* Be sure no bpstat's are pointing at it after it's been freed. */
05052b63
JK
3456 /* FIXME, how can we find all bpstat's?
3457 We just check stop_bpstat for now. */
bd5635a1
RP
3458 for (bs = stop_bpstat; bs; bs = bs->next)
3459 if (bs->breakpoint_at == bpt)
3460 bs->breakpoint_at = NULL;
c8950965 3461 free ((PTR)bpt);
bd5635a1
RP
3462}
3463
895cc8ab 3464void
bd5635a1
RP
3465delete_command (arg, from_tty)
3466 char *arg;
3467 int from_tty;
3468{
6b038bd9 3469 struct breakpoint *b, *temp;
bd5635a1
RP
3470
3471 if (arg == 0)
3472 {
895cc8ab
KS
3473 int breaks_to_delete = 0;
3474
3475 /* Delete all breakpoints if no argument.
3476 Do not delete internal or call-dummy breakpoints, these
3477 have to be deleted with an explicit breakpoint number argument. */
3478 ALL_BREAKPOINTS (b)
3479 {
3480 if (b->type != bp_call_dummy && b->number >= 0)
3481 breaks_to_delete = 1;
3482 }
3483
bd5635a1
RP
3484 /* Ask user only if there are some breakpoints to delete. */
3485 if (!from_tty
895cc8ab 3486 || (breaks_to_delete && query ("Delete all breakpoints? ")))
bd5635a1 3487 {
895cc8ab
KS
3488 ALL_BREAKPOINTS_SAFE (b, temp)
3489 {
3490 if (b->type != bp_call_dummy && b->number >= 0)
3491 delete_breakpoint (b);
3492 }
bd5635a1
RP
3493 }
3494 }
3495 else
3496 map_breakpoint_numbers (arg, delete_breakpoint);
3497}
3498
bdbd5f50
JG
3499/* Reset a breakpoint given it's struct breakpoint * BINT.
3500 The value we return ends up being the return value from catch_errors.
3501 Unused in this case. */
3502
3503static int
bd5635a1 3504breakpoint_re_set_one (bint)
bdbd5f50 3505 char *bint;
bd5635a1
RP
3506{
3507 struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */
11054881 3508 struct value *mark;
bd5635a1
RP
3509 int i;
3510 struct symtabs_and_lines sals;
bd5635a1 3511 char *s;
30875e1c 3512 enum enable save_enable;
bd5635a1 3513
80ba48f5 3514 switch (b->type)
bd5635a1 3515 {
80ba48f5 3516 case bp_breakpoint:
11054881 3517 case bp_hardware_breakpoint:
80ba48f5
SG
3518 if (b->addr_string == NULL)
3519 {
3520 /* Anything without a string can't be re-set. */
3521 delete_breakpoint (b);
3522 return 0;
3523 }
30875e1c
SG
3524 /* In case we have a problem, disable this breakpoint. We'll restore
3525 its status if we succeed. */
3526 save_enable = b->enable;
3527 b->enable = disabled;
3528
706dc3ce
JL
3529 set_language (b->language);
3530 input_radix = b->input_radix;
bd5635a1 3531 s = b->addr_string;
d889f6b7 3532 sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL);
bd5635a1
RP
3533 for (i = 0; i < sals.nelts; i++)
3534 {
30875e1c 3535 resolve_sal_pc (&sals.sals[i]);
fee933f1
RP
3536
3537 /* Reparse conditions, they might contain references to the
3538 old symtab. */
3539 if (b->cond_string != NULL)
3540 {
3541 s = b->cond_string;
3542 if (b->cond)
3543 free ((PTR)b->cond);
3544 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
3545 }
3546
3547 /* We need to re-set the breakpoint if the address changes...*/
d889f6b7 3548 if (b->address != sals.sals[i].pc
fee933f1
RP
3549 /* ...or new and old breakpoints both have source files, and
3550 the source file name or the line number changes... */
d889f6b7
JK
3551 || (b->source_file != NULL
3552 && sals.sals[i].symtab != NULL
3553 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
3554 || b->line_number != sals.sals[i].line)
fee933f1
RP
3555 )
3556 /* ...or we switch between having a source file and not having
3557 one. */
3558 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
3559 )
bd5635a1 3560 {
d889f6b7
JK
3561 if (b->source_file != NULL)
3562 free (b->source_file);
3563 if (sals.sals[i].symtab == NULL)
3564 b->source_file = NULL;
3565 else
3566 b->source_file =
3567 savestring (sals.sals[i].symtab->filename,
3568 strlen (sals.sals[i].symtab->filename));
8537ba60
SG
3569 b->line_number = sals.sals[i].line;
3570 b->address = sals.sals[i].pc;
6b038bd9 3571 check_duplicates (b->address, b->section);
bd5635a1 3572
8537ba60 3573 mention (b);
6c803036
JK
3574
3575 /* Might be better to do this just once per breakpoint_re_set,
3576 rather than once for every breakpoint. */
3577 breakpoints_changed ();
8537ba60 3578 }
6b038bd9 3579 b->section = sals.sals[i].section;
30875e1c 3580 b->enable = save_enable; /* Restore it, this worked. */
bd5635a1 3581 }
c8950965 3582 free ((PTR)sals.sals);
80ba48f5 3583 break;
2d313932 3584
80ba48f5 3585 case bp_watchpoint:
999dd04b 3586 case bp_hardware_watchpoint:
11054881
KH
3587 case bp_read_watchpoint:
3588 case bp_access_watchpoint:
0eaaa46a 3589 innermost_block = NULL;
0a97f6c4
JK
3590 /* The issue arises of what context to evaluate this in. The same
3591 one as when it was set, but what does that mean when symbols have
3592 been re-read? We could save the filename and functionname, but
3593 if the context is more local than that, the best we could do would
3594 be something like how many levels deep and which index at that
3595 particular level, but that's going to be less stable than filenames
3596 or functionnames. */
3597 /* So for now, just use a global context. */
39ce6829
PS
3598 if (b->exp)
3599 free ((PTR)b->exp);
0eaaa46a
JK
3600 b->exp = parse_expression (b->exp_string);
3601 b->exp_valid_block = innermost_block;
11054881 3602 mark = value_mark ();
39ce6829
PS
3603 if (b->val)
3604 value_free (b->val);
0eaaa46a
JK
3605 b->val = evaluate_expression (b->exp);
3606 release_value (b->val);
3607 if (VALUE_LAZY (b->val))
3608 value_fetch_lazy (b->val);
3609
2d313932
JK
3610 if (b->cond_string != NULL)
3611 {
3612 s = b->cond_string;
39ce6829
PS
3613 if (b->cond)
3614 free ((PTR)b->cond);
2d313932
JK
3615 b->cond = parse_exp_1 (&s, (struct block *)0, 0);
3616 }
cabd4da6
JK
3617 if (b->enable == enabled)
3618 mention (b);
11054881 3619 value_free_to_mark (mark);
80ba48f5 3620 break;
2d313932 3621
80ba48f5
SG
3622 default:
3623 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
2d313932 3624 /* fall through */
fa3764e2
JL
3625 /* Delete longjmp breakpoints, they will be reset later by
3626 breakpoint_re_set. */
80ba48f5
SG
3627 case bp_longjmp:
3628 case bp_longjmp_resume:
3629 delete_breakpoint (b);
3630 break;
27b6a1fa
JL
3631
3632 /* This breakpoint is special, it's set up when the inferior
3633 starts and we really don't want to touch it. */
3634 case bp_shlib_event:
fa3764e2
JL
3635
3636 /* Keep temporary breakpoints, which can be encountered when we step
3637 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
3638 Otherwise these should have been blown away via the cleanup chain
3639 or by breakpoint_init_inferior when we rerun the executable. */
3640 case bp_until:
3641 case bp_finish:
3642 case bp_watchpoint_scope:
3643 case bp_call_dummy:
3644 case bp_step_resume:
27b6a1fa 3645 break;
bd5635a1 3646 }
80ba48f5 3647
bdbd5f50 3648 return 0;
bd5635a1
RP
3649}
3650
3651/* Re-set all breakpoints after symbols have been re-loaded. */
3652void
3653breakpoint_re_set ()
3654{
cba0d141 3655 struct breakpoint *b, *temp;
706dc3ce
JL
3656 enum language save_language;
3657 int save_input_radix;
30875e1c
SG
3658 static char message1[] = "Error in re-setting breakpoint %d:\n";
3659 char message[sizeof (message1) + 30 /* slop */];
bd5635a1 3660
706dc3ce
JL
3661 save_language = current_language->la_language;
3662 save_input_radix = input_radix;
cba0d141 3663 ALL_BREAKPOINTS_SAFE (b, temp)
bd5635a1 3664 {
2d313932 3665 sprintf (message, message1, b->number); /* Format possible error msg */
fe675038
JK
3666 catch_errors (breakpoint_re_set_one, (char *) b, message,
3667 RETURN_MASK_ALL);
bd5635a1 3668 }
706dc3ce
JL
3669 set_language (save_language);
3670 input_radix = save_input_radix;
bd5635a1 3671
cd10c7e3
SG
3672#ifdef GET_LONGJMP_TARGET
3673 create_longjmp_breakpoint ("longjmp");
3674 create_longjmp_breakpoint ("_longjmp");
3675 create_longjmp_breakpoint ("siglongjmp");
6b038bd9 3676 create_longjmp_breakpoint ("_siglongjmp");
cd10c7e3
SG
3677 create_longjmp_breakpoint (NULL);
3678#endif
80ba48f5 3679
1eeba686 3680#if 0
0fe1522a 3681 /* Took this out (temporarily at least), since it produces an extra
1eeba686 3682 blank line at startup. This messes up the gdbtests. -PB */
bd5635a1
RP
3683 /* Blank line to finish off all those mention() messages we just printed. */
3684 printf_filtered ("\n");
1eeba686 3685#endif
bd5635a1
RP
3686}
3687\f
3688/* Set ignore-count of breakpoint number BPTNUM to COUNT.
3689 If from_tty is nonzero, it prints a message to that effect,
3690 which ends with a period (no newline). */
3691
3692void
3693set_ignore_count (bptnum, count, from_tty)
3694 int bptnum, count, from_tty;
3695{
3696 register struct breakpoint *b;
3697
3698 if (count < 0)
3699 count = 0;
3700
3701 ALL_BREAKPOINTS (b)
3702 if (b->number == bptnum)
3703 {
3704 b->ignore_count = count;
3705 if (!from_tty)
3706 return;
3707 else if (count == 0)
423e9664
SG
3708 printf_filtered ("Will stop next time breakpoint %d is reached.",
3709 bptnum);
bd5635a1 3710 else if (count == 1)
423e9664
SG
3711 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3712 bptnum);
bd5635a1 3713 else
423e9664 3714 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
bd5635a1 3715 count, bptnum);
6c803036 3716 breakpoints_changed ();
bd5635a1
RP
3717 return;
3718 }
3719
3720 error ("No breakpoint number %d.", bptnum);
3721}
3722
3723/* Clear the ignore counts of all breakpoints. */
3724void
3725breakpoint_clear_ignore_counts ()
3726{
3727 struct breakpoint *b;
3728
3729 ALL_BREAKPOINTS (b)
3730 b->ignore_count = 0;
3731}
3732
3733/* Command to set ignore-count of breakpoint N to COUNT. */
3734
3735static void
3736ignore_command (args, from_tty)
3737 char *args;
3738 int from_tty;
3739{
3740 char *p = args;
3741 register int num;
3742
3743 if (p == 0)
3744 error_no_arg ("a breakpoint number");
3745
3746 num = get_number (&p);
3747
3748 if (*p == 0)
3749 error ("Second argument (specified ignore-count) is missing.");
3750
bdbd5f50
JG
3751 set_ignore_count (num,
3752 longest_to_int (value_as_long (parse_and_eval (p))),
3753 from_tty);
423e9664 3754 printf_filtered ("\n");
6c803036 3755 breakpoints_changed ();
bd5635a1
RP
3756}
3757\f
3758/* Call FUNCTION on each of the breakpoints
3759 whose numbers are given in ARGS. */
3760
3761static void
3762map_breakpoint_numbers (args, function)
3763 char *args;
30875e1c 3764 void (*function) PARAMS ((struct breakpoint *));
bd5635a1
RP
3765{
3766 register char *p = args;
3767 char *p1;
3768 register int num;
3769 register struct breakpoint *b;
3770
3771 if (p == 0)
3772 error_no_arg ("one or more breakpoint numbers");
3773
3774 while (*p)
3775 {
3776 p1 = p;
3777
3778 num = get_number (&p1);
3779
3780 ALL_BREAKPOINTS (b)
3781 if (b->number == num)
3782 {
999dd04b 3783 struct breakpoint *related_breakpoint = b->related_breakpoint;
bd5635a1 3784 function (b);
999dd04b
JL
3785 if (related_breakpoint)
3786 function (related_breakpoint);
bd5635a1
RP
3787 goto win;
3788 }
199b2450 3789 printf_unfiltered ("No breakpoint number %d.\n", num);
bd5635a1
RP
3790 win:
3791 p = p1;
3792 }
3793}
3794
e8bf33c4 3795void
bd5635a1
RP
3796disable_breakpoint (bpt)
3797 struct breakpoint *bpt;
3798{
999dd04b
JL
3799 /* Never disable a watchpoint scope breakpoint; we want to
3800 hit them when we leave scope so we can delete both the
3801 watchpoint and its scope breakpoint at that time. */
3802 if (bpt->type == bp_watchpoint_scope)
3803 return;
3804
bd5635a1
RP
3805 bpt->enable = disabled;
3806
6b038bd9 3807 check_duplicates (bpt->address, bpt->section);
e8bf33c4
JK
3808
3809 if (modify_breakpoint_hook)
3810 modify_breakpoint_hook (bpt);
bd5635a1
RP
3811}
3812
bdbd5f50 3813/* ARGSUSED */
bd5635a1
RP
3814static void
3815disable_command (args, from_tty)
3816 char *args;
3817 int from_tty;
3818{
3819 register struct breakpoint *bpt;
3820 if (args == 0)
3821 ALL_BREAKPOINTS (bpt)
423e9664
SG
3822 switch (bpt->type)
3823 {
3824 case bp_breakpoint:
11054881
KH
3825 case bp_hardware_breakpoint:
3826 case bp_watchpoint:
3827 case bp_hardware_watchpoint:
3828 case bp_read_watchpoint:
3829 case bp_access_watchpoint:
423e9664
SG
3830 disable_breakpoint (bpt);
3831 default:
3832 continue;
3833 }
bd5635a1
RP
3834 else
3835 map_breakpoint_numbers (args, disable_breakpoint);
3836}
3837
3838static void
3f37b696 3839do_enable_breakpoint (bpt, disposition)
bd5635a1 3840 struct breakpoint *bpt;
3f37b696 3841 enum bpdisp disposition;
bd5635a1 3842{
706dc3ce 3843 struct frame_info *save_selected_frame = NULL;
11054881
KH
3844 int save_selected_frame_level = -1;
3845 int target_resources_ok, other_type_used;
3846 struct value *mark;
3847
3f37b696
FF
3848 if (bpt->type == bp_hardware_breakpoint)
3849 {
11054881
KH
3850 int i;
3851 i = hw_breakpoint_used_count();
3852 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3853 bp_hardware_breakpoint, i+1, 0);
3854 if (target_resources_ok == 0)
3855 error ("No hardware breakpoint support in the target.");
3856 else if (target_resources_ok < 0)
3857 error ("Hardware breakpoints used exceeds limit.");
3858 }
3859
30875e1c 3860 bpt->enable = enabled;
3f37b696 3861 bpt->disposition = disposition;
6b038bd9 3862 check_duplicates (bpt->address, bpt->section);
6c803036 3863 breakpoints_changed ();
11054881
KH
3864
3865 if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint ||
3866 bpt->type == bp_read_watchpoint || bpt->type == bp_access_watchpoint)
3867 {
3868 if (bpt->exp_valid_block != NULL)
3869 {
706dc3ce
JL
3870 struct frame_info *fr =
3871 find_frame_addr_in_frame_chain (bpt->watchpoint_frame);
11054881
KH
3872 if (fr == NULL)
3873 {
3874 printf_filtered ("\
3875Cannot enable watchpoint %d because the block in which its expression\n\
3876is valid is not currently in scope.\n", bpt->number);
3877 bpt->enable = disabled;
3878 return;
3879 }
3880
3881 save_selected_frame = selected_frame;
3882 save_selected_frame_level = selected_frame_level;
3883 select_frame (fr, -1);
3884 }
3885
3886 value_free (bpt->val);
3887 mark = value_mark ();
3888 bpt->val = evaluate_expression (bpt->exp);
3889 release_value (bpt->val);
3890 if (VALUE_LAZY (bpt->val))
3891 value_fetch_lazy (bpt->val);
3892
3893 if (bpt->type == bp_hardware_watchpoint ||
3894 bpt->type == bp_read_watchpoint ||
3895 bpt->type == bp_access_watchpoint)
3896 {
3897 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
3f37b696
FF
3898 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
3899
ad3b8c4a
JM
3900 /* Hack around 'unused var' error for some targets here */
3901 (void) mem_cnt, i;
11054881 3902 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3f37b696 3903 bpt->type, i + mem_cnt, other_type_used);
11054881
KH
3904 /* we can consider of type is bp_hardware_watchpoint, convert to
3905 bp_watchpoint in the following condition */
3906 if (target_resources_ok < 0)
3907 {
3908 printf_filtered("\
3909Cannot enable watchpoint %d because target watch resources\n\
3910have been allocated for other watchpoints.\n", bpt->number);
3f37b696
FF
3911 bpt->enable = disabled;
3912 value_free_to_mark (mark);
3913 return;
11054881
KH
3914 }
3915 }
3916
3917 if (save_selected_frame_level >= 0)
3918 select_frame (save_selected_frame, save_selected_frame_level);
3919 value_free_to_mark (mark);
3920 }
3f37b696
FF
3921 if (modify_breakpoint_hook)
3922 modify_breakpoint_hook (bpt);
3923}
3924
3925void
3926enable_breakpoint (bpt)
3927 struct breakpoint *bpt;
3928{
895cc8ab 3929 do_enable_breakpoint (bpt, bpt->disposition);
3f37b696
FF
3930}
3931
3932/* The enable command enables the specified breakpoints (or all defined
3933 breakpoints) so they once again become (or continue to be) effective
3934 in stopping the inferior. */
3935
3936/* ARGSUSED */
3937static void
3938enable_command (args, from_tty)
3939 char *args;
3940 int from_tty;
3941{
3942 register struct breakpoint *bpt;
3943 if (args == 0)
3944 ALL_BREAKPOINTS (bpt)
3945 switch (bpt->type)
3946 {
3947 case bp_breakpoint:
3948 case bp_hardware_breakpoint:
3949 case bp_watchpoint:
3950 case bp_hardware_watchpoint:
3951 case bp_read_watchpoint:
3952 case bp_access_watchpoint:
3953 enable_breakpoint (bpt);
3954 default:
3955 continue;
3956 }
3957 else
3958 map_breakpoint_numbers (args, enable_breakpoint);
3959}
3960
3961static void
3962enable_once_breakpoint (bpt)
3963 struct breakpoint *bpt;
3964{
3965 do_enable_breakpoint (bpt, disable);
bd5635a1
RP
3966}
3967
bdbd5f50 3968/* ARGSUSED */
bd5635a1
RP
3969static void
3970enable_once_command (args, from_tty)
3971 char *args;
3972 int from_tty;
3973{
3974 map_breakpoint_numbers (args, enable_once_breakpoint);
3975}
3976
3977static void
3978enable_delete_breakpoint (bpt)
3979 struct breakpoint *bpt;
3980{
3f37b696 3981 do_enable_breakpoint (bpt, del);
bd5635a1
RP
3982}
3983
bdbd5f50 3984/* ARGSUSED */
bd5635a1
RP
3985static void
3986enable_delete_command (args, from_tty)
3987 char *args;
3988 int from_tty;
3989{
3990 map_breakpoint_numbers (args, enable_delete_breakpoint);
3991}
3992\f
706dc3ce
JL
3993/* Use default_breakpoint_'s, or nothing if they aren't valid. */
3994
bd5635a1
RP
3995struct symtabs_and_lines
3996decode_line_spec_1 (string, funfirstline)
3997 char *string;
3998 int funfirstline;
3999{
4000 struct symtabs_and_lines sals;
4001 if (string == 0)
4002 error ("Empty line specification.");
4003 if (default_breakpoint_valid)
4004 sals = decode_line_1 (&string, funfirstline,
d889f6b7
JK
4005 default_breakpoint_symtab, default_breakpoint_line,
4006 (char ***)NULL);
bd5635a1 4007 else
d889f6b7
JK
4008 sals = decode_line_1 (&string, funfirstline,
4009 (struct symtab *)NULL, 0, (char ***)NULL);
bd5635a1
RP
4010 if (*string)
4011 error ("Junk at end of line specification: %s", string);
4012 return sals;
4013}
4014\f
bd5635a1
RP
4015void
4016_initialize_breakpoint ()
4017{
4018 breakpoint_chain = 0;
4019 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
4020 before a breakpoint is set. */
4021 breakpoint_count = 0;
4022
4023 add_com ("ignore", class_breakpoint, ignore_command,
557f3a0e
SS
4024 "Set ignore-count of breakpoint number N to COUNT.\n\
4025Usage is `ignore N COUNT'.");
bd5635a1
RP
4026
4027 add_com ("commands", class_breakpoint, commands_command,
4028 "Set commands to be executed when a breakpoint is hit.\n\
4029Give breakpoint number as argument after \"commands\".\n\
4030With no argument, the targeted breakpoint is the last one set.\n\
4031The commands themselves follow starting on the next line.\n\
4032Type a line containing \"end\" to indicate the end of them.\n\
4033Give \"silent\" as the first line to make the breakpoint silent;\n\
4034then no output is printed when it is hit, except what the commands print.");
4035
4036 add_com ("condition", class_breakpoint, condition_command,
4037 "Specify breakpoint number N to break only if COND is true.\n\
557f3a0e
SS
4038Usage is `condition N COND', where N is an integer and COND is an\n\
4039expression to be evaluated whenever breakpoint N is reached. ");
bd5635a1
RP
4040
4041 add_com ("tbreak", class_breakpoint, tbreak_command,
4042 "Set a temporary breakpoint. Args like \"break\" command.\n\
c4de6b30
JK
4043Like \"break\" except the breakpoint is only temporary,\n\
4044so it will be deleted when hit. Equivalent to \"break\" followed\n\
4045by using \"enable delete\" on the breakpoint number.");
bd5635a1 4046
11054881
KH
4047 add_com ("hbreak", class_breakpoint, hbreak_command,
4048 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
4049Like \"break\" except the breakpoint requires hardware support,\n\
4050some target hardware may not have this support.");
4051
4052 add_com ("thbreak", class_breakpoint, thbreak_command,
4053 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
4054Like \"hbreak\" except the breakpoint is only temporary,\n\
4055so it will be deleted when hit.");
4056
bd5635a1
RP
4057 add_prefix_cmd ("enable", class_breakpoint, enable_command,
4058 "Enable some breakpoints.\n\
4059Give breakpoint numbers (separated by spaces) as arguments.\n\
4060With no subcommand, breakpoints are enabled until you command otherwise.\n\
4061This is used to cancel the effect of the \"disable\" command.\n\
4062With a subcommand you can enable temporarily.",
4063 &enablelist, "enable ", 1, &cmdlist);
4064
895cc8ab
KS
4065 add_com_alias ("en", "enable", class_breakpoint, 1);
4066
bd5635a1
RP
4067 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
4068 "Enable some breakpoints.\n\
4069Give breakpoint numbers (separated by spaces) as arguments.\n\
4070This is used to cancel the effect of the \"disable\" command.\n\
4071May be abbreviated to simply \"enable\".\n",
4072 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
4073
4074 add_cmd ("once", no_class, enable_once_command,
4075 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
bd2f0c85 4076If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
bd5635a1
RP
4077 &enablebreaklist);
4078
4079 add_cmd ("delete", no_class, enable_delete_command,
4080 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
4081If a breakpoint is hit while enabled in this fashion, it is deleted.",
4082 &enablebreaklist);
4083
4084 add_cmd ("delete", no_class, enable_delete_command,
4085 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
4086If a breakpoint is hit while enabled in this fashion, it is deleted.",
4087 &enablelist);
4088
4089 add_cmd ("once", no_class, enable_once_command,
4090 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
bd2f0c85 4091If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
bd5635a1
RP
4092 &enablelist);
4093
4094 add_prefix_cmd ("disable", class_breakpoint, disable_command,
4095 "Disable some breakpoints.\n\
4096Arguments are breakpoint numbers with spaces in between.\n\
4097To disable all breakpoints, give no argument.\n\
4098A disabled breakpoint is not forgotten, but has no effect until reenabled.",
4099 &disablelist, "disable ", 1, &cmdlist);
4100 add_com_alias ("dis", "disable", class_breakpoint, 1);
4101 add_com_alias ("disa", "disable", class_breakpoint, 1);
4102
4103 add_cmd ("breakpoints", class_alias, disable_command,
4104 "Disable some breakpoints.\n\
4105Arguments are breakpoint numbers with spaces in between.\n\
4106To disable all breakpoints, give no argument.\n\
4107A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
4108This command may be abbreviated \"disable\".",
4109 &disablelist);
4110
4111 add_prefix_cmd ("delete", class_breakpoint, delete_command,
4112 "Delete some breakpoints or auto-display expressions.\n\
4113Arguments are breakpoint numbers with spaces in between.\n\
4114To delete all breakpoints, give no argument.\n\
4115\n\
4116Also a prefix command for deletion of other GDB objects.\n\
4117The \"unset\" command is also an alias for \"delete\".",
4118 &deletelist, "delete ", 1, &cmdlist);
4119 add_com_alias ("d", "delete", class_breakpoint, 1);
bd5635a1
RP
4120
4121 add_cmd ("breakpoints", class_alias, delete_command,
4122 "Delete some breakpoints or auto-display expressions.\n\
4123Arguments are breakpoint numbers with spaces in between.\n\
4124To delete all breakpoints, give no argument.\n\
4125This command may be abbreviated \"delete\".",
4126 &deletelist);
4127
4128 add_com ("clear", class_breakpoint, clear_command,
706dc3ce 4129 concat ("Clear breakpoint at specified line or function.\n\
bd5635a1
RP
4130Argument may be line number, function name, or \"*\" and an address.\n\
4131If line number is specified, all breakpoints in that line are cleared.\n\
4132If function is specified, breakpoints at beginning of function are cleared.\n\
706dc3ce
JL
4133If an address is specified, breakpoints at that address are cleared.\n\n",
4134"With no argument, clears all breakpoints in the line that the selected frame\n\
bd5635a1
RP
4135is executing in.\n\
4136\n\
706dc3ce 4137See also the \"delete\" command which clears breakpoints by number.", NULL));
bd5635a1
RP
4138
4139 add_com ("break", class_breakpoint, break_command,
706dc3ce 4140 concat ("Set breakpoint at specified line or function.\n\
bd5635a1
RP
4141Argument may be line number, function name, or \"*\" and an address.\n\
4142If line number is specified, break at start of code for that line.\n\
4143If function is specified, break at start of code for that function.\n\
706dc3ce
JL
4144If an address is specified, break at that exact address.\n",
4145"With no arg, uses current execution address of selected stack frame.\n\
bd5635a1
RP
4146This is useful for breaking on return to a stack frame.\n\
4147\n\
4148Multiple breakpoints at one place are permitted, and useful if conditional.\n\
4149\n\
706dc3ce 4150Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
bd5635a1
RP
4151 add_com_alias ("b", "break", class_run, 1);
4152 add_com_alias ("br", "break", class_run, 1);
4153 add_com_alias ("bre", "break", class_run, 1);
4154 add_com_alias ("brea", "break", class_run, 1);
4155
4156 add_info ("breakpoints", breakpoints_info,
706dc3ce 4157 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
80ba48f5 4158The \"Type\" column indicates one of:\n\
423e9664
SG
4159\tbreakpoint - normal breakpoint\n\
4160\twatchpoint - watchpoint\n\
80ba48f5
SG
4161The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
4162the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
4163breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
706dc3ce
JL
4164address and file/line number respectively.\n\n",
4165"Convenience variable \"$_\" and default examine address for \"x\"\n\
80ba48f5
SG
4166are set to the address of the last breakpoint listed.\n\n\
4167Convenience variable \"$bpnum\" contains the number of the last\n\
706dc3ce 4168breakpoint set.", NULL));
80ba48f5 4169
9b280a7f
JG
4170#if MAINTENANCE_CMDS
4171
4172 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
706dc3ce 4173 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
80ba48f5 4174The \"Type\" column indicates one of:\n\
423e9664
SG
4175\tbreakpoint - normal breakpoint\n\
4176\twatchpoint - watchpoint\n\
4177\tlongjmp - internal breakpoint used to step through longjmp()\n\
4178\tlongjmp resume - internal breakpoint at the target of longjmp()\n\
4179\tuntil - internal breakpoint used by the \"until\" command\n\
706dc3ce
JL
4180\tfinish - internal breakpoint used by the \"finish\" command\n",
4181"The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
80ba48f5
SG
4182the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
4183breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
706dc3ce
JL
4184address and file/line number respectively.\n\n",
4185"Convenience variable \"$_\" and default examine address for \"x\"\n\
bd5635a1
RP
4186are set to the address of the last breakpoint listed.\n\n\
4187Convenience variable \"$bpnum\" contains the number of the last\n\
706dc3ce 4188breakpoint set.", NULL),
9b280a7f
JG
4189 &maintenanceinfolist);
4190
4191#endif /* MAINTENANCE_CMDS */
bd5635a1
RP
4192
4193 add_com ("catch", class_breakpoint, catch_command,
4194 "Set breakpoints to catch exceptions that are raised.\n\
4195Argument may be a single exception to catch, multiple exceptions\n\
4196to catch, or the default exception \"default\". If no arguments\n\
4197are given, breakpoints are set at all exception handlers catch clauses\n\
4198within the current scope.\n\
4199\n\
4200A condition specified for the catch applies to all breakpoints set\n\
4201with this command\n\
4202\n\
4203Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
4204
4205 add_com ("watch", class_breakpoint, watch_command,
4206 "Set a watchpoint for an expression.\n\
4207A watchpoint stops execution of your program whenever the value of\n\
4208an expression changes.");
4209
11054881
KH
4210 add_com ("rwatch", class_breakpoint, rwatch_command,
4211 "Set a read watchpoint for an expression.\n\
4212A watchpoint stops execution of your program whenever the value of\n\
4213an expression is read.");
4214
4215 add_com ("awatch", class_breakpoint, awatch_command,
4216 "Set a watchpoint for an expression.\n\
4217A watchpoint stops execution of your program whenever the value of\n\
4218an expression is either read or written.");
4219
c8950965
JG
4220 add_info ("watchpoints", breakpoints_info,
4221 "Synonym for ``info breakpoints''.");
9f577285 4222
bd5635a1 4223}
This page took 0.533084 seconds and 4 git commands to generate.