|
|
1.1 root 1: /* Everything about breakpoints, for GDB.
2: Copyright (C) 1986, 1987 Free Software Foundation, Inc.
3:
4: GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5: WARRANTY. No author or distributor accepts responsibility to anyone
6: for the consequences of using it or for whether it serves any
7: particular purpose or works at all, unless he says so in writing.
8: Refer to the GDB General Public License for full details.
9:
10: Everyone is granted permission to copy, modify and redistribute GDB,
11: but only under the conditions described in the GDB General Public
12: License. A copy of this license is supposed to have been given to you
13: along with GDB so you can know your rights and responsibilities. It
14: should be in a file named COPYING. Among other things, the copyright
15: notice and this notice must be preserved on all copies.
16:
17: In other words, go ahead and share GDB, but don't try to stop
18: anyone else from sharing it farther. Help stamp out software hoarding!
19: */
20:
21: #include "defs.h"
22: #include "initialize.h"
23: #include "param.h"
24: #include "symtab.h"
25: #include "frame.h"
26:
27: #include <stdio.h>
28:
29: /* This is the sequence of bytes we insert for a breakpoint. */
30:
31: static char break_insn[] = BREAKPOINT;
32:
33: /* States of enablement of breakpoint.
34: `temporary' means disable when hit.
35: `once' means delete when hit. */
36:
37: enum enable { disabled, enabled, temporary, delete};
38:
39: struct breakpoint
40: {
41: struct breakpoint *next;
42: /* Number assigned to distinguish breakpoints. */
43: int number;
44: /* Address to break at. */
45: CORE_ADDR address;
46: /* Line number of this address. Redundant. */
47: int line_number;
48: /* Symtab of file of this address. Redundant. */
49: struct symtab *symtab;
50: /* Zero means disabled; remember the info but don't break here. */
51: enum enable enable;
52: /* Number of stops at this breakpoint that should
53: be continued automatically before really stopping. */
54: int ignore_count;
55: /* "Real" contents of byte where breakpoint has been inserted.
56: Valid only when breakpoints are in the program. */
57: char shadow_contents[sizeof break_insn];
58: /* Nonzero if this breakpoint is now inserted. */
59: char inserted;
60: /* Nonzero if this is not the first breakpoint in the list
61: for the given address. */
62: char duplicate;
63: /* Chain of command lines to execute when this breakpoint is hit. */
64: struct command_line *commands;
65: /* Stack depth (frame). If nonzero, break only if fp equals this. */
66: FRAME frame;
67: /* Conditional. Break only if this expression's value is nonzero. */
68: struct expression *cond;
69: };
70:
71: #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
72:
73: /* Chain of all breakpoints defined. */
74:
75: struct breakpoint *breakpoint_chain;
76:
77: /* Number of last breakpoint made. */
78:
79: static int breakpoint_count;
80:
81: /* Default address, symtab and line to put a breakpoint at
82: for "break" command with no arg.
83: if default_breakpoint_valid is zero, the other three are
84: not valid, and "break" with no arg is an error.
85:
86: This set by print_stack_frame, which calls set_default_breakpoint. */
87:
88: int default_breakpoint_valid;
89: CORE_ADDR default_breakpoint_address;
90: struct symtab *default_breakpoint_symtab;
91: int default_breakpoint_line;
92:
93: /* Remaining commands (not yet executed)
94: of last breakpoint hit. */
95:
96: struct command_line *breakpoint_commands;
97:
98: START_FILE
99:
100: extern char *read_line ();
101:
102: static void delete_breakpoint ();
103: void clear_momentary_breakpoints ();
104: void breakpoint_auto_delete ();
105:
106: /* condition N EXP -- set break condition of breakpoint N to EXP. */
107:
108: static void
109: condition_command (arg, from_tty)
110: char *arg;
111: int from_tty;
112: {
113: register struct breakpoint *b;
114: register char *p;
115: register int bnum;
116: register struct expression *expr;
117:
118: if (arg == 0)
119: error_no_arg ("breakpoint number");
120:
121: p = arg;
122: while (*p >= '0' && *p <= '9') p++;
123: bnum = atoi (arg);
124:
125: ALL_BREAKPOINTS (b)
126: if (b->number == bnum)
127: {
128: if (b->cond)
129: free (b->cond);
130: if (*p == 0)
131: {
132: b->cond = 0;
133: if (from_tty)
134: printf ("Breakpoint %d now unconditional.\n", bnum);
135: }
136: else
137: {
138: if (*p != ' ' && *p != '\t')
139: error ("Arguments must be an integer (breakpoint number) and an expression.");
140:
141: /* Find start of expression */
142: while (*p == ' ' || *p == '\t') p++;
143:
144: arg = p;
145: b->cond = (struct expression *) parse_c_1 (&arg, block_for_pc (b->address));
146: }
147: return;
148: }
149:
150: error ("No breakpoint number %d.", bnum);
151: }
152:
153: static void
154: commands_command (arg)
155: char *arg;
156: {
157: register struct breakpoint *b;
158: register char *p, *p1;
159: register int bnum;
160: struct command_line *l;
161:
162: if (arg == 0)
163: error_no_arg ("breakpoint number");
164:
165: /* If we allowed this, we would have problems with when to
166: free the storage, if we change the commands currently
167: being read from. */
168:
169: if (breakpoint_commands)
170: error ("Can't use the \"commands\" command among a breakpoint's commands.");
171:
172: p = arg;
173: if (! (*p >= '0' && *p <= '9'))
174: error ("Argument must be integer (a breakpoint number).");
175:
176: while (*p >= '0' && *p <= '9') p++;
177: if (*p)
178: error ("Unexpected extra arguments following breakpoint number.");
179:
180: bnum = atoi (arg);
181:
182: ALL_BREAKPOINTS (b)
183: if (b->number == bnum)
184: {
185: if (input_from_terminal_p ())
186: printf ("Type commands for when breakpoint %d is hit, one per line.\n\
187: End with a line saying just \"end\".\n", bnum);
188: l = read_command_lines ();
189: free_command_lines (&b->commands);
190: b->commands = l;
191: return;
192: }
193: error ("No breakpoint number %d.", bnum);
194: }
195:
196: /* Called from command loop to execute the commands
197: associated with the breakpoint we just stopped at. */
198:
199: void
200: do_breakpoint_commands ()
201: {
202: while (breakpoint_commands)
203: {
1.1.1.2 ! root 204: char *line = breakpoint_commands->line;
! 205: breakpoint_commands = breakpoint_commands->next;
! 206: execute_command (line, 0);
! 207: /* If command was "cont", breakpoint_commands is now 0,
! 208: of if we stopped at yet another breakpoint which has commands,
! 209: it is now the commands for the new breakpoint. */
1.1 root 210: }
211: clear_momentary_breakpoints ();
212: }
213:
214: /* Used when the program is proceeded, to eliminate any remaining
215: commands attached to the previous breakpoint we stopped at. */
216:
217: void
218: clear_breakpoint_commands ()
219: {
220: breakpoint_commands = 0;
221: breakpoint_auto_delete (0);
222: }
1.1.1.2 ! root 223:
! 224: /* Functions to get and set the current list of pending
! 225: breakpoint commands. These are used by run_stack_dummy
! 226: to preserve the commands around a function call. */
! 227:
! 228: struct command_line *
! 229: get_breakpoint_commands ()
! 230: {
! 231: return breakpoint_commands;
! 232: }
! 233:
! 234: void
! 235: set_breakpoint_commands (cmds)
! 236: struct command_line *cmds;
! 237: {
! 238: breakpoint_commands = cmds;
! 239: }
1.1 root 240:
241: /* insert_breakpoints is used when starting or continuing the program.
242: remove_breakpoints is used when the program stops.
1.1.1.2 ! root 243: Both return zero if successful,
! 244: or an `errno' value if could not write the inferior. */
1.1 root 245:
246: int
247: insert_breakpoints ()
248: {
249: register struct breakpoint *b;
1.1.1.2 ! root 250: int val;
1.1 root 251:
252: /* printf ("Inserting breakpoints.\n"); */
253: ALL_BREAKPOINTS (b)
254: if (b->enable != disabled && ! b->inserted && ! b->duplicate)
255: {
256: read_memory (b->address, b->shadow_contents, sizeof break_insn);
1.1.1.2 ! root 257: val = write_memory (b->address, break_insn, sizeof break_insn);
! 258: if (val)
! 259: return val;
1.1 root 260: /* printf ("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
261: b->address, b->shadow_contents[0], b->shadow_contents[1]); */
262: b->inserted = 1;
263: }
264: return 0;
265: }
266:
267: int
268: remove_breakpoints ()
269: {
270: register struct breakpoint *b;
1.1.1.2 ! root 271: int val;
1.1 root 272:
273: /* printf ("Removing breakpoints.\n"); */
274: ALL_BREAKPOINTS (b)
275: if (b->inserted)
276: {
1.1.1.2 ! root 277: val = write_memory (b->address, b->shadow_contents, sizeof break_insn);
! 278: if (val)
! 279: return val;
1.1 root 280: b->inserted = 0;
281: /* printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
282: b->address, b->shadow_contents[0], b->shadow_contents[1]); */
283: }
284:
285: return 0;
286: }
287:
288: /* Clear the "inserted" flag in all breakpoints.
289: This is done when the inferior is loaded. */
290:
291: int
292: mark_breakpoints_out ()
293: {
294: register struct breakpoint *b;
295:
296: ALL_BREAKPOINTS (b)
297: b->inserted = 0;
298: }
299:
300: /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
301: When continuing from a location with a breakpoint,
302: we actually single step once before calling insert_breakpoints. */
303:
304: int
305: breakpoint_here_p (pc)
306: CORE_ADDR pc;
307: {
308: register struct breakpoint *b;
309:
310: ALL_BREAKPOINTS (b)
311: if (b->enable != disabled && b->address == pc)
312: return 1;
313:
314: return 0;
315: }
316:
317: /* Return 0 if PC is not the address just after a breakpoint,
318: or -1 if breakpoint says do not stop now,
319: or -2 if breakpoint says it has deleted itself and don't stop,
320: or -3 if hit a breakpoint number -3 (delete when program stops),
321: or else the number of the breakpoint,
322: with 0x1000000 added for a silent breakpoint. */
323:
324: int
325: breakpoint_stop_status (pc, frame)
326: CORE_ADDR pc;
327: FRAME frame;
328: {
329: register struct breakpoint *b;
330: register int cont = 0;
331:
332: /* Get the address where the breakpoint would have been. */
333: pc -= DECR_PC_AFTER_BREAK;
334:
335: ALL_BREAKPOINTS (b)
336: if (b->enable != disabled && b->address == pc)
337: {
338: if (b->frame && b->frame != frame)
339: cont = -1;
340: else
341: {
342: int value_zero;
343: if (b->cond)
344: {
345: value_zero = value_zerop (evaluate_expression (b->cond));
346: free_all_values ();
347: }
348: if (b->cond && value_zero)
349: {
350: cont = -1;
351: }
352: else if (b->ignore_count > 0)
353: {
354: b->ignore_count--;
355: cont = -1;
356: }
357: else
358: {
359: if (b->enable == temporary)
360: b->enable = disabled;
361: breakpoint_commands = b->commands;
362: if (breakpoint_commands
363: && !strcmp ("silent", breakpoint_commands->line))
364: {
365: breakpoint_commands = breakpoint_commands->next;
366: return 0x1000000 + b->number;
367: }
368: return b->number;
369: }
370: }
371: }
372:
373: return cont;
374: }
375:
376: static void
377: breakpoint_1 (bnum)
378: int bnum;
379: {
380: register struct breakpoint *b;
381: register struct command_line *l;
382: register struct symbol *sym;
383: CORE_ADDR last_addr = -1;
384:
385: ALL_BREAKPOINTS (b)
386: if (bnum == -1 || bnum == b->number)
387: {
388: printf ("#%-3d %c 0x%08x ", b->number,
389: "nyod"[(int) b->enable],
390: b->address);
391: last_addr = b->address;
392: if (b->symtab)
393: {
394: sym = find_pc_function (b->address);
395: if (sym)
396: printf (" in %s (%s line %d)", SYMBOL_NAME (sym),
397: b->symtab->filename, b->line_number);
398: else
399: printf ("%s line %d", b->symtab->filename, b->line_number);
400: }
401: printf ("\n");
402:
403: if (b->ignore_count)
404: printf ("\tignore next %d hits\n", b->ignore_count);
405: if (b->frame)
406: printf ("\tstop only in stack frame at 0x%x\n", b->frame);
407: if (b->cond)
408: {
409: printf ("\tbreak only if ");
410: print_expression (b->cond, stdout);
411: printf ("\n");
412: }
413: if (l = b->commands)
414: while (l)
415: {
416: printf ("\t%s\n", l->line);
417: l = l->next;
418: }
419: }
420:
421: if (last_addr != -1)
422: set_next_address (last_addr);
423: }
424:
425: static void
426: breakpoints_info (bnum_exp)
427: char *bnum_exp;
428: {
429: int bnum = -1;
430:
431: if (bnum_exp)
432: bnum = parse_and_eval_address (bnum_exp);
433: else if (breakpoint_chain == 0)
434: printf ("No breakpoints.\n");
435: else
436: printf ("Breakpoints:\n\
437: Num Enb Address Where\n");
438:
439: breakpoint_1 (bnum);
440: }
1.1.1.2 ! root 441:
! 442: /* Print a message describing any breakpoints set at PC. */
! 443:
! 444: static void
! 445: describe_other_breakpoints (pc)
! 446: register CORE_ADDR pc;
! 447: {
! 448: register int others = 0;
! 449: register struct breakpoint *b;
! 450:
! 451: ALL_BREAKPOINTS (b)
! 452: if (b->address == pc)
! 453: others++;
! 454: if (others > 0)
! 455: {
! 456: printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
! 457: ALL_BREAKPOINTS (b)
! 458: if (b->address == pc)
! 459: {
! 460: others--;
! 461: printf ("%d%s%s ",
! 462: b->number,
! 463: (b->enable == disabled) ? " (disabled)" : "",
! 464: (others > 1) ? "," : ((others == 1) ? " and" : ""));
! 465: }
! 466: printf (" also set at pc 0x%x\n", pc);
! 467: }
! 468: }
1.1 root 469:
1.1.1.2 ! root 470: /* Set the default place to put a breakpoint
! 471: for the `break' command with no arguments. */
! 472:
1.1 root 473: void
474: set_default_breakpoint (valid, addr, symtab, line)
475: int valid;
476: CORE_ADDR addr;
477: struct symtab *symtab;
478: int line;
479: {
480: default_breakpoint_valid = valid;
481: default_breakpoint_address = addr;
482: default_breakpoint_symtab = symtab;
483: default_breakpoint_line = line;
484: }
485:
486: /* Rescan breakpoints at address ADDRESS,
487: marking the first one as "first" and any others as "duplicates".
488: This is so that the bpt instruction is only inserted once. */
489:
490: static void
491: check_duplicates (address)
492: CORE_ADDR address;
493: {
494: register struct breakpoint *b;
495: register int count = 0;
496:
497: ALL_BREAKPOINTS (b)
498: if (b->enable != disabled && b->address == address)
499: {
500: count++;
501: b->duplicate = count > 1;
502: }
503: }
504:
505: /* Low level routine to set a breakpoint.
506: Takes as args the three things that every breakpoint must have.
507: Returns the breakpoint object so caller can set other things.
508: Does not set the breakpoint number!
509: Does not print anything. */
510:
511: static struct breakpoint *
512: set_raw_breakpoint (sal)
513: struct symtab_and_line sal;
514: {
515: register struct breakpoint *b, *b1;
516:
517: b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
518: bzero (b, sizeof *b);
519: b->address = sal.pc;
520: b->symtab = sal.symtab;
521: b->line_number = sal.line;
522: b->enable = enabled;
523: b->next = 0;
524:
525: /* Add this breakpoint to the end of the chain
526: so that a list of breakpoints will come out in order
527: of increasing numbers. */
528:
529: b1 = breakpoint_chain;
530: if (b1 == 0)
531: breakpoint_chain = b;
532: else
533: {
534: while (b1->next)
535: b1 = b1->next;
536: b1->next = b;
537: }
538:
539: check_duplicates (sal.pc);
540:
541: return b;
542: }
543:
544: /* Set a breakpoint that will evaporate an end of command
545: at address specified by SAL.
546: Restrict it to frame FRAME if FRAME is nonzero. */
547:
548: void
549: set_momentary_breakpoint (sal, frame)
550: struct symtab_and_line sal;
551: FRAME frame;
552: {
553: register struct breakpoint *b;
554: b = set_raw_breakpoint (sal);
555: b->number = -3;
556: b->enable = delete;
557: b->frame = frame;
558: }
559:
560: void
561: clear_momentary_breakpoints ()
562: {
563: register struct breakpoint *b;
564: ALL_BREAKPOINTS (b)
565: if (b->number == -3)
566: {
567: delete_breakpoint (b);
568: break;
569: }
570: }
571:
1.1.1.2 ! root 572: /* Set a breakpoint from a symtab and line.
! 573: If TEMPFLAG is nonzero, it is a temporary breakpoint.
! 574: Print the same confirmation messages that the breakpoint command prints. */
! 575:
! 576: void
! 577: set_breakpoint (s, line, tempflag)
! 578: struct symtab *s;
! 579: int line;
! 580: int tempflag;
! 581: {
! 582: register struct breakpoint *b;
! 583: struct symtab_and_line sal;
! 584:
! 585: sal.symtab = s;
! 586: sal.line = line;
! 587: sal.pc = find_line_pc (sal.symtab, sal.line);
! 588: if (sal.pc == 0)
! 589: error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename);
! 590: else
! 591: {
! 592: describe_other_breakpoints (sal.pc);
! 593:
! 594: b = set_raw_breakpoint (sal);
! 595: b->number = ++breakpoint_count;
! 596: b->cond = 0;
! 597: if (tempflag)
! 598: b->enable = temporary;
! 599:
! 600: printf ("Breakpoint %d at 0x%x", b->number, b->address);
! 601: if (b->symtab)
! 602: printf (": file %s, line %d.", b->symtab->filename, b->line_number);
! 603: printf ("\n");
! 604: }
! 605: }
! 606:
1.1 root 607: /* Set a breakpoint according to ARG (function, linenum or *address)
608: and make it temporary if TEMPFLAG is nonzero. */
609:
610: static void
611: break_command_1 (arg, tempflag, from_tty)
612: char *arg;
613: int tempflag, from_tty;
614: {
615: struct symtab_and_line sal;
616: register struct expression *cond = 0;
617: register struct breakpoint *b;
618:
619: sal.pc = 0;
620:
621: if (arg)
622: {
623: sal = decode_line_1 (&arg, 1, 0, 0);
624:
625: if (sal.pc == 0 && sal.symtab != 0)
626: {
627: sal.pc = find_line_pc (sal.symtab, sal.line);
628: if (sal.pc == 0)
629: error ("No line %d in file \"%s\".",
630: sal.line, sal.symtab->filename);
631: }
632:
633: while (*arg)
634: {
635: if (arg[0] == 'i' && arg[1] == 'f'
636: && (arg[2] == ' ' || arg[2] == '\t'))
637: cond = (struct expression *) parse_c_1 ((arg += 2, &arg),
638: block_for_pc (sal.pc));
639: else
640: error ("Junk at end of arguments.");
641: }
642: }
643: else if (default_breakpoint_valid)
644: {
645: sal.pc = default_breakpoint_address;
646: sal.line = default_breakpoint_line;
647: sal.symtab = default_breakpoint_symtab;
648: }
649: else
650: error ("No default breakpoint address now.");
651:
1.1.1.2 ! root 652: if (from_tty)
! 653: describe_other_breakpoints (sal.pc);
! 654:
1.1 root 655: b = set_raw_breakpoint (sal);
656: b->number = ++breakpoint_count;
657: b->cond = cond;
658: if (tempflag)
659: b->enable = temporary;
660:
661: printf ("Breakpoint %d at 0x%x", b->number, b->address);
662: if (b->symtab)
663: printf (": file %s, line %d.", b->symtab->filename, b->line_number);
664: printf ("\n");
665: }
666:
667: static void
668: break_command (arg, from_tty)
669: char *arg;
670: int from_tty;
671: {
672: break_command_1 (arg, 0, from_tty);
673: }
674:
675: static void
676: tbreak_command (arg, from_tty)
677: char *arg;
678: int from_tty;
679: {
680: break_command_1 (arg, 1, from_tty);
681: }
682:
683: static void
684: clear_command (arg, from_tty)
685: char *arg;
686: int from_tty;
687: {
688: register struct breakpoint *b, *b1;
689: struct symtab_and_line sal;
690: register struct breakpoint *found;
691:
692: if (arg)
693: sal = decode_line_spec (arg, 1);
694: else
695: {
696: sal.line = default_breakpoint_line;
697: sal.symtab = default_breakpoint_symtab;
698: sal.pc = 0;
699: if (sal.symtab == 0)
700: error ("No source file specified.");
701: }
702:
703: /* If exact pc given, clear bpts at that pc.
704: But if sal.pc is zero, clear all bpts on specified line. */
705:
706: found = (struct breakpoint *) 0;
707: while (breakpoint_chain
708: && (sal.pc ? breakpoint_chain->address == sal.pc
709: : (breakpoint_chain->symtab == sal.symtab
710: && breakpoint_chain->line_number == sal.line)))
711: {
712: b1 = breakpoint_chain;
713: breakpoint_chain = b1->next;
714: b1->next = found;
715: found = b1;
716: }
717:
718: ALL_BREAKPOINTS (b)
719: while (b->next
720: && (sal.pc ? b->next->address == sal.pc
721: : (b->next->symtab == sal.symtab
722: && b->next->line_number == sal.line)))
723: {
724: b1 = b->next;
725: b->next = b1->next;
726: b1->next = found;
727: found = b1;
728: }
729:
730: if (found == 0)
731: error ("No breakpoint at %s.", arg);
732:
733: if (found->next) from_tty = 1; /* Alwats report if deleted more than one */
734: if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
735: while (found)
736: {
737: if (from_tty) printf ("%d ", found->number);
738: b1 = found->next;
739: delete_breakpoint (found);
740: found = b1;
741: }
742: if (from_tty) putchar ('\n');
743: }
744:
745: /* Delete breakpoint number BNUM if it is a `delete' breakpoint.
746: This is called after breakpoint BNUM has been hit.
747: Also delete any breakpoint numbered -3 unless there are breakpoint
748: commands to be executed. */
749:
750: void
751: breakpoint_auto_delete (bnum)
752: int bnum;
753: {
754: register struct breakpoint *b;
755: if (bnum != 0)
756: ALL_BREAKPOINTS (b)
757: if (b->number == bnum)
758: {
759: if (b->enable == delete)
760: delete_breakpoint (b);
761: break;
762: }
763: if (breakpoint_commands == 0)
764: clear_momentary_breakpoints ();
765: }
766:
767: static void
768: delete_breakpoint (bpt)
769: struct breakpoint *bpt;
770: {
771: register struct breakpoint *b;
772:
773: if (bpt->inserted)
774: write_memory (bpt->address, bpt->shadow_contents, sizeof break_insn);
775:
776: if (breakpoint_chain == bpt)
777: breakpoint_chain = bpt->next;
778:
779: ALL_BREAKPOINTS (b)
780: if (b->next == bpt)
781: {
782: b->next = bpt->next;
783: break;
784: }
785:
786: check_duplicates (bpt->address);
787:
788: free_command_lines (&bpt->commands);
789: if (bpt->cond)
790: free (bpt->cond);
791: free (bpt);
792: }
793:
794: void map_breakpoint_numbers ();
795:
796: static void
797: delete_command (arg, from_tty)
798: char *arg;
799: int from_tty;
800: {
801: register struct breakpoint *b, *b1;
802:
803: if (arg == 0)
804: {
805: if (!from_tty || query ("Delete all breakpoints? "))
806: {
807: /* No arg; clear all breakpoints. */
808: while (breakpoint_chain)
809: delete_breakpoint (breakpoint_chain);
810: }
811: }
812: else
813: map_breakpoint_numbers (arg, delete_breakpoint);
814: }
815:
816: /* Delete all breakpoints.
817: Done when new symtabs are loaded, since the break condition expressions
818: may become invalid, and the breakpoints are probably wrong anyway. */
819:
820: void
821: clear_breakpoints ()
822: {
823: delete_command (0, 0);
824: }
825:
826: /* Set ignore-count of breakpoint number BPTNUM to COUNT.
827: If from_tty is nonzero, it prints a message to that effect,
828: which ends with a period (no newline). */
829:
830: void
831: set_ignore_count (bptnum, count, from_tty)
832: int bptnum, count, from_tty;
833: {
834: register struct breakpoint *b;
835:
836: if (count < 0)
837: count = 0;
838:
839: ALL_BREAKPOINTS (b)
840: if (b->number == bptnum)
841: {
842: b->ignore_count = count;
843: if (!from_tty)
844: return;
845: else if (count == 0)
846: printf ("Will stop next time breakpoint %d is reached.", bptnum);
847: else if (count == 1)
848: printf ("Will ignore next crossing of breakpoint %d.", bptnum);
849: else
850: printf ("Will ignore next %d crossings of breakpoint %d.",
851: count, bptnum);
852: return;
853: }
854:
855: error ("No breakpoint number %d.", bptnum);
856: }
857:
858: /* Command to set ignore-count of breakpoint N to COUNT. */
859:
860: static void
861: ignore_command (args, from_tty)
862: char *args;
863: int from_tty;
864: {
865: register char *p;
866: register int num;
1.1.1.2 ! root 867:
! 868: if (p == 0)
! 869: error_no_arg ("a breakpoint number");
1.1 root 870:
871: p = args;
872: while (*p >= '0' && *p <= '9') p++;
873: if (*p && *p != ' ' && *p != '\t')
874: error ("First argument must be a breakpoint number.");
875:
876: num = atoi (args);
877:
878: if (*p == 0)
879: error ("Second argument (specified ignore-count) is missing.");
880:
881: set_ignore_count (num, parse_and_eval_address (p), from_tty);
882: printf ("\n");
883: }
884:
885: /* Call FUNCTION on each of the breakpoints
886: whose numbers are given in ARGS. */
887:
888: static void
889: map_breakpoint_numbers (args, function)
890: char *args;
891: void (*function) ();
892: {
893: register char *p = args;
894: register char *p1;
895: register int num;
896: register struct breakpoint *b;
897:
898: if (p == 0)
899: error_no_arg ("one or more breakpoint numbers");
900:
901: while (*p)
902: {
903: p1 = p;
904: while (*p1 >= '0' && *p1 <= '9') p1++;
905: if (*p1 && *p1 != ' ' && *p1 != '\t')
906: error ("Arguments must be breakpoint numbers.");
907:
908: num = atoi (p);
909:
910: ALL_BREAKPOINTS (b)
911: if (b->number == num)
912: {
913: function (b);
914: goto win;
915: }
916: printf ("No breakpoint number %d.\n", num);
917: win:
918: p = p1;
919: while (*p == ' ' || *p == '\t') p++;
920: }
921: }
922:
923: static void
924: enable_breakpoint (bpt)
925: struct breakpoint *bpt;
926: {
927: bpt->enable = enabled;
928:
929: check_duplicates (bpt->address);
930: }
931:
932: static void
933: enable_command (args)
934: char *args;
935: {
936: map_breakpoint_numbers (args, enable_breakpoint);
937: }
938:
939: static void
940: disable_breakpoint (bpt)
941: struct breakpoint *bpt;
942: {
943: bpt->enable = disabled;
944:
945: check_duplicates (bpt->address);
946: }
947:
948: static void
949: disable_command (args)
950: char *args;
951: {
952: register struct breakpoint *bpt;
953: if (args == 0)
954: ALL_BREAKPOINTS (bpt)
955: disable_breakpoint (bpt);
956: else
957: map_breakpoint_numbers (args, disable_breakpoint);
958: }
959:
960: static void
961: enable_once_breakpoint (bpt)
962: struct breakpoint *bpt;
963: {
964: bpt->enable = temporary;
965:
966: check_duplicates (bpt->address);
967: }
968:
969: static void
970: enable_once_command (args)
971: char *args;
972: {
973: map_breakpoint_numbers (args, enable_once_breakpoint);
974: }
975:
976: static void
977: enable_delete_breakpoint (bpt)
978: struct breakpoint *bpt;
979: {
980: bpt->enable = delete;
981:
982: check_duplicates (bpt->address);
983: }
984:
985: static void
986: enable_delete_command (args)
987: char *args;
988: {
989: map_breakpoint_numbers (args, enable_delete_breakpoint);
990: }
991:
992:
993: /* Chain containing all defined enable commands. */
994:
995: struct cmd_list_element *enablelist;
996:
997: extern struct cmd_list_element *cmdlist;
998:
999: static
1000: initialize ()
1001: {
1002: breakpoint_chain = 0;
1003: breakpoint_count = 0;
1004: enablelist = 0;
1005:
1006: add_com ("ignore", class_breakpoint, ignore_command,
1007: "Set ignore-count of breakpoint number N to COUNT.");
1008:
1009: add_com ("commands", class_breakpoint, commands_command,
1010: "Set commands to be executed when a breakpoint is hit.\n\
1011: Give breakpoint number as argument after \"commands\".\n\
1012: The commands themselves follow starting on the next line.\n\
1013: Type a line containing \"end\" to indicate the end of them.\n\
1014: Give \"silent\" as the first line to make the breakpoint silent;\n\
1015: then no output is printed when it is hit, except what the commands print.");
1016:
1017: add_com ("condition", class_breakpoint, condition_command,
1018: "Specify breakpoint number N to break only if COND is true.\n\
1019: N is an integer; COND is a C expression to be evaluated whenever\n\
1020: breakpoint N is reached. Actually break only when COND is nonzero.");
1021:
1022: add_com ("tbreak", class_breakpoint, tbreak_command,
1023: "Set a temporary breakpoint. Args like \"break\" command.\n\
1024: Like \"break\" except the breakpoint is only enabled temporarily,\n\
1025: so it will be disabled when hit. Equivalent to \"break\" followed\n\
1026: by using \"enable once\" on the breakpoint number.");
1027:
1028: add_prefix_cmd ("enable", class_breakpoint, enable_command,
1029: "Enable some breakpoints. Give breakpoint numbers as arguments.\n\
1030: With no subcommand, breakpoints are enabled until you command otherwise.\n\
1031: This is used to cancel the effect of the \"disable\" command.\n\
1032: With a subcommand you can enable temporarily.",
1033: &enablelist, "enable ", 1, &cmdlist);
1034:
1035: add_cmd ("delete", 0, enable_delete_command,
1036: "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
1037: If a breakpoint is hit while enabled in this fashion, it is deleted.",
1038: &enablelist);
1039:
1040: add_cmd ("once", 0, enable_once_command,
1041: "Enable breakpoints for one hit. Give breakpoint numbers.\n\
1042: If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
1043: See the \"tbreak\" command which sets a breakpoint and enables it once.",
1044: &enablelist);
1045:
1046: add_com ("disable", class_breakpoint, disable_command,
1047: "Disable some breakpoints. Give breakpoint numbers as arguments.\n\
1048: With no arguments, disable all breakpoints.\n\
1049: A disabled breakpoint is not forgotten,\n\
1050: but it has no effect until enabled again.");
1051: add_com_alias ("dis", "disable", class_breakpoint, 1);
1052:
1053: add_com ("delete", class_breakpoint, delete_command,
1054: "Delete breakpoints, specifying breakpoint numbers; or all breakpoints.\n\
1055: Arguments are breakpoint numbers with spaces in between.\n\
1056: To delete all breakpoints, give no argument.");
1057: add_com_alias ("d", "delete", class_breakpoint, 1);
1058:
1059: add_com ("clear", class_breakpoint, clear_command,
1060: "Clear breakpoint at specified line or function.\n\
1061: Argument may be line number, function name, or \"*\" and an address.\n\
1062: If line number is specified, all breakpoints in that line are cleared.\n\
1063: If function is specified, breakpoints at beginning of function are cleared.\n\
1064: If an address is specified, breakpoints at that address are cleared.\n\n\
1065: With no argument, clears all breakpoints in the line that the selected frame\n\
1066: is executing in.\n\
1067: \n\
1068: See also the \"delete\" command which clears breakpoints by number.");
1069:
1070: add_com ("break", class_breakpoint, break_command,
1071: "Set breakpoint at specified line or function.\n\
1072: Argument may be line number, function name, or \"*\" and an address.\n\
1073: If line number is specified, break at start of code for that line.\n\
1074: If function is specified, break at start of code for that function.\n\
1075: If an address is specified, break at that exact address.\n\
1076: With no arg, uses current execution address of selected stack frame.\n\
1077: This is useful for breaking on return to a stack frame.\n\
1078: \n\
1079: Multiple breakpoints at one place are permitted, and useful if conditional.\n\
1080: \n\
1081: Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
1082: add_com_alias ("b", "break", class_run, 1);
1083: add_com_alias ("br", "break", class_run, 1);
1084: add_com_alias ("bre", "break", class_run, 1);
1085: add_com_alias ("brea", "break", class_run, 1);
1086:
1087: add_info ("breakpoints", breakpoints_info,
1088: "Status of all breakpoints, or breakpoint number NUMBER.\n\
1.1.1.2 ! root 1089: Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
1.1 root 1090: \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
1091: Then come the address and the file/line number.\n\n\
1092: Convenience variable \"$_\" and default examine address for \"x\"\n\
1093: are set to the address of the last breakpoint listed.");
1094: }
1095:
1096: END_FILE
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.