]>
Commit | Line | Data |
---|---|---|
7b4ac7e1 | 1 | /* Everything about breakpoints, for GDB. |
4187119d | 2 | Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. |
7b4ac7e1 | 3 | |
4187119d | 4 | This file is part of GDB. |
7b4ac7e1 | 5 | |
4187119d | 6 | GDB is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 1, or (at your option) | |
9 | any later version. | |
7b4ac7e1 | 10 | |
4187119d | 11 | GDB is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GDB; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
7b4ac7e1 | 19 | |
7a67dd45 | 20 | #include <stdio.h> |
7b4ac7e1 | 21 | #include "defs.h" |
7b4ac7e1 | 22 | #include "param.h" |
23 | #include "symtab.h" | |
24 | #include "frame.h" | |
25 | ||
7b4ac7e1 | 26 | /* This is the sequence of bytes we insert for a breakpoint. */ |
27 | ||
28 | static char break_insn[] = BREAKPOINT; | |
29 | ||
30 | /* States of enablement of breakpoint. | |
31 | `temporary' means disable when hit. | |
e91b87a3 | 32 | `delete' means delete when hit. */ |
7b4ac7e1 | 33 | |
34 | enum enable { disabled, enabled, temporary, delete}; | |
35 | ||
e91b87a3 | 36 | /* Not that the ->silent field is not currently used by any commands |
37 | (though the code is in there if it was to be and set_raw_breakpoint | |
38 | does set it to 0). I implemented it because I thought it would be | |
39 | useful for a hack I had to put in; I'm going to leave it in because | |
40 | I can see how there might be times when it would indeed be useful */ | |
41 | ||
7b4ac7e1 | 42 | struct breakpoint |
43 | { | |
44 | struct breakpoint *next; | |
45 | /* Number assigned to distinguish breakpoints. */ | |
46 | int number; | |
47 | /* Address to break at. */ | |
48 | CORE_ADDR address; | |
49 | /* Line number of this address. Redundant. */ | |
50 | int line_number; | |
51 | /* Symtab of file of this address. Redundant. */ | |
52 | struct symtab *symtab; | |
53 | /* Zero means disabled; remember the info but don't break here. */ | |
54 | enum enable enable; | |
e91b87a3 | 55 | /* Non-zero means a silent breakpoint (don't print frame info |
56 | if we stop here). */ | |
57 | unsigned char silent; | |
7b4ac7e1 | 58 | /* Number of stops at this breakpoint that should |
59 | be continued automatically before really stopping. */ | |
60 | int ignore_count; | |
61 | /* "Real" contents of byte where breakpoint has been inserted. | |
62 | Valid only when breakpoints are in the program. */ | |
63 | char shadow_contents[sizeof break_insn]; | |
64 | /* Nonzero if this breakpoint is now inserted. */ | |
65 | char inserted; | |
66 | /* Nonzero if this is not the first breakpoint in the list | |
67 | for the given address. */ | |
68 | char duplicate; | |
69 | /* Chain of command lines to execute when this breakpoint is hit. */ | |
70 | struct command_line *commands; | |
e91b87a3 | 71 | /* Stack depth (address of frame). If nonzero, break only if fp |
72 | equals this. */ | |
73 | FRAME_ADDR frame; | |
7b4ac7e1 | 74 | /* Conditional. Break only if this expression's value is nonzero. */ |
75 | struct expression *cond; | |
76 | }; | |
77 | ||
78 | #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) | |
79 | ||
80 | /* Chain of all breakpoints defined. */ | |
81 | ||
82 | struct breakpoint *breakpoint_chain; | |
83 | ||
84 | /* Number of last breakpoint made. */ | |
85 | ||
86 | static int breakpoint_count; | |
87 | ||
88 | /* Default address, symtab and line to put a breakpoint at | |
89 | for "break" command with no arg. | |
90 | if default_breakpoint_valid is zero, the other three are | |
91 | not valid, and "break" with no arg is an error. | |
92 | ||
93 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
94 | ||
95 | int default_breakpoint_valid; | |
96 | CORE_ADDR default_breakpoint_address; | |
97 | struct symtab *default_breakpoint_symtab; | |
98 | int default_breakpoint_line; | |
99 | ||
100 | /* Remaining commands (not yet executed) | |
101 | of last breakpoint hit. */ | |
102 | ||
103 | struct command_line *breakpoint_commands; | |
104 | ||
7b4ac7e1 | 105 | static void delete_breakpoint (); |
106 | void clear_momentary_breakpoints (); | |
107 | void breakpoint_auto_delete (); | |
4187119d | 108 | |
109 | /* Flag indicating extra verbosity for xgdb. */ | |
110 | extern int xgdb_verbose; | |
7b4ac7e1 | 111 | \f |
112 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
113 | ||
114 | static void | |
115 | condition_command (arg, from_tty) | |
116 | char *arg; | |
117 | int from_tty; | |
118 | { | |
119 | register struct breakpoint *b; | |
120 | register char *p; | |
121 | register int bnum; | |
122 | register struct expression *expr; | |
123 | ||
124 | if (arg == 0) | |
125 | error_no_arg ("breakpoint number"); | |
126 | ||
127 | p = arg; | |
128 | while (*p >= '0' && *p <= '9') p++; | |
4187119d | 129 | if (p == arg) |
130 | /* There is no number here. (e.g. "cond a == b"). */ | |
131 | error_no_arg ("breakpoint number"); | |
7b4ac7e1 | 132 | bnum = atoi (arg); |
133 | ||
134 | ALL_BREAKPOINTS (b) | |
135 | if (b->number == bnum) | |
136 | { | |
137 | if (b->cond) | |
138 | free (b->cond); | |
139 | if (*p == 0) | |
140 | { | |
141 | b->cond = 0; | |
142 | if (from_tty) | |
143 | printf ("Breakpoint %d now unconditional.\n", bnum); | |
144 | } | |
145 | else | |
146 | { | |
147 | if (*p != ' ' && *p != '\t') | |
148 | error ("Arguments must be an integer (breakpoint number) and an expression."); | |
149 | ||
150 | /* Find start of expression */ | |
151 | while (*p == ' ' || *p == '\t') p++; | |
152 | ||
153 | arg = p; | |
632ea0cc | 154 | b->cond = (struct expression *) parse_c_1 (&arg, block_for_pc (b->address), 0); |
155 | if (*arg) | |
156 | error ("Junk at end of expression"); | |
7b4ac7e1 | 157 | } |
158 | return; | |
159 | } | |
160 | ||
161 | error ("No breakpoint number %d.", bnum); | |
162 | } | |
163 | ||
164 | static void | |
165 | commands_command (arg) | |
166 | char *arg; | |
167 | { | |
168 | register struct breakpoint *b; | |
169 | register char *p, *p1; | |
170 | register int bnum; | |
171 | struct command_line *l; | |
172 | ||
7b4ac7e1 | 173 | /* If we allowed this, we would have problems with when to |
174 | free the storage, if we change the commands currently | |
175 | being read from. */ | |
176 | ||
177 | if (breakpoint_commands) | |
178 | error ("Can't use the \"commands\" command among a breakpoint's commands."); | |
179 | ||
e91b87a3 | 180 | /* Allow commands by itself to refer to the last breakpoint. */ |
181 | if (arg == 0) | |
182 | bnum = breakpoint_count; | |
183 | else | |
184 | { | |
185 | p = arg; | |
186 | if (! (*p >= '0' && *p <= '9')) | |
187 | error ("Argument must be integer (a breakpoint number)."); | |
188 | ||
189 | while (*p >= '0' && *p <= '9') p++; | |
190 | if (*p) | |
191 | error ("Unexpected extra arguments following breakpoint number."); | |
192 | ||
193 | bnum = atoi (arg); | |
194 | } | |
7b4ac7e1 | 195 | |
196 | ALL_BREAKPOINTS (b) | |
197 | if (b->number == bnum) | |
198 | { | |
199 | if (input_from_terminal_p ()) | |
3bf57d21 | 200 | { |
201 | printf ("Type commands for when breakpoint %d is hit, one per line.\n\ | |
7b4ac7e1 | 202 | End with a line saying just \"end\".\n", bnum); |
3bf57d21 | 203 | fflush (stdout); |
204 | } | |
7b4ac7e1 | 205 | l = read_command_lines (); |
206 | free_command_lines (&b->commands); | |
207 | b->commands = l; | |
208 | return; | |
209 | } | |
210 | error ("No breakpoint number %d.", bnum); | |
211 | } | |
212 | ||
213 | /* Called from command loop to execute the commands | |
214 | associated with the breakpoint we just stopped at. */ | |
215 | ||
216 | void | |
217 | do_breakpoint_commands () | |
218 | { | |
219 | while (breakpoint_commands) | |
220 | { | |
221 | char *line = breakpoint_commands->line; | |
222 | breakpoint_commands = breakpoint_commands->next; | |
223 | execute_command (line, 0); | |
224 | /* If command was "cont", breakpoint_commands is now 0, | |
225 | of if we stopped at yet another breakpoint which has commands, | |
226 | it is now the commands for the new breakpoint. */ | |
227 | } | |
228 | clear_momentary_breakpoints (); | |
229 | } | |
230 | ||
231 | /* Used when the program is proceeded, to eliminate any remaining | |
232 | commands attached to the previous breakpoint we stopped at. */ | |
233 | ||
234 | void | |
235 | clear_breakpoint_commands () | |
236 | { | |
237 | breakpoint_commands = 0; | |
238 | breakpoint_auto_delete (0); | |
239 | } | |
240 | ||
241 | /* Functions to get and set the current list of pending | |
242 | breakpoint commands. These are used by run_stack_dummy | |
243 | to preserve the commands around a function call. */ | |
244 | ||
245 | struct command_line * | |
246 | get_breakpoint_commands () | |
247 | { | |
248 | return breakpoint_commands; | |
249 | } | |
250 | ||
251 | void | |
252 | set_breakpoint_commands (cmds) | |
253 | struct command_line *cmds; | |
254 | { | |
255 | breakpoint_commands = cmds; | |
256 | } | |
257 | \f | |
258 | /* insert_breakpoints is used when starting or continuing the program. | |
259 | remove_breakpoints is used when the program stops. | |
260 | Both return zero if successful, | |
261 | or an `errno' value if could not write the inferior. */ | |
262 | ||
263 | int | |
264 | insert_breakpoints () | |
265 | { | |
266 | register struct breakpoint *b; | |
267 | int val; | |
268 | ||
e91b87a3 | 269 | #ifdef BREAKPOINT_DEBUG |
270 | printf ("Inserting breakpoints.\n"); | |
271 | #endif /* BREAKPOINT_DEBUG */ | |
272 | ||
7b4ac7e1 | 273 | ALL_BREAKPOINTS (b) |
274 | if (b->enable != disabled && ! b->inserted && ! b->duplicate) | |
275 | { | |
276 | read_memory (b->address, b->shadow_contents, sizeof break_insn); | |
277 | val = write_memory (b->address, break_insn, sizeof break_insn); | |
278 | if (val) | |
279 | return val; | |
e91b87a3 | 280 | #ifdef BREAKPOINT_DEBUG |
281 | printf ("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n", | |
282 | b->address, b->shadow_contents[0], b->shadow_contents[1]); | |
283 | #endif /* BREAKPOINT_DEBUG */ | |
7b4ac7e1 | 284 | b->inserted = 1; |
285 | } | |
286 | return 0; | |
287 | } | |
288 | ||
289 | int | |
290 | remove_breakpoints () | |
291 | { | |
292 | register struct breakpoint *b; | |
293 | int val; | |
294 | ||
e91b87a3 | 295 | #ifdef BREAKPOINT_DEBUG |
296 | printf ("Removing breakpoints.\n"); | |
297 | #endif /* BREAKPOINT_DEBUG */ | |
298 | ||
7b4ac7e1 | 299 | ALL_BREAKPOINTS (b) |
300 | if (b->inserted) | |
301 | { | |
302 | val = write_memory (b->address, b->shadow_contents, sizeof break_insn); | |
303 | if (val) | |
304 | return val; | |
305 | b->inserted = 0; | |
e91b87a3 | 306 | #ifdef BREAKPOINT_DEBUG |
307 | printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n", | |
308 | b->address, b->shadow_contents[0], b->shadow_contents[1]); | |
309 | #endif /* BREAKPOINT_DEBUG */ | |
7b4ac7e1 | 310 | } |
311 | ||
312 | return 0; | |
313 | } | |
314 | ||
315 | /* Clear the "inserted" flag in all breakpoints. | |
316 | This is done when the inferior is loaded. */ | |
317 | ||
e91b87a3 | 318 | void |
7b4ac7e1 | 319 | mark_breakpoints_out () |
320 | { | |
321 | register struct breakpoint *b; | |
322 | ||
323 | ALL_BREAKPOINTS (b) | |
324 | b->inserted = 0; | |
325 | } | |
326 | ||
327 | /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC. | |
328 | When continuing from a location with a breakpoint, | |
329 | we actually single step once before calling insert_breakpoints. */ | |
330 | ||
331 | int | |
332 | breakpoint_here_p (pc) | |
333 | CORE_ADDR pc; | |
334 | { | |
335 | register struct breakpoint *b; | |
336 | ||
337 | ALL_BREAKPOINTS (b) | |
338 | if (b->enable != disabled && b->address == pc) | |
339 | return 1; | |
340 | ||
341 | return 0; | |
342 | } | |
343 | ||
3bf57d21 | 344 | /* Evaluate the expression EXP and return 1 if value is zero. |
345 | This is used inside a catch_errors to evaluate the breakpoint condition. */ | |
346 | ||
347 | int | |
348 | breakpoint_cond_eval (exp) | |
349 | struct expression *exp; | |
350 | { | |
351 | return value_zerop (evaluate_expression (exp)); | |
352 | } | |
353 | ||
7b4ac7e1 | 354 | /* Return 0 if PC is not the address just after a breakpoint, |
355 | or -1 if breakpoint says do not stop now, | |
356 | or -2 if breakpoint says it has deleted itself and don't stop, | |
357 | or -3 if hit a breakpoint number -3 (delete when program stops), | |
358 | or else the number of the breakpoint, | |
e91b87a3 | 359 | with 0x1000000 added (or subtracted, for a negative return value) for |
360 | a silent breakpoint. */ | |
7b4ac7e1 | 361 | |
362 | int | |
e91b87a3 | 363 | breakpoint_stop_status (pc, frame_address) |
7b4ac7e1 | 364 | CORE_ADDR pc; |
e91b87a3 | 365 | FRAME_ADDR frame_address; |
7b4ac7e1 | 366 | { |
367 | register struct breakpoint *b; | |
368 | register int cont = 0; | |
369 | ||
370 | /* Get the address where the breakpoint would have been. */ | |
371 | pc -= DECR_PC_AFTER_BREAK; | |
372 | ||
373 | ALL_BREAKPOINTS (b) | |
374 | if (b->enable != disabled && b->address == pc) | |
375 | { | |
e91b87a3 | 376 | if (b->frame && b->frame != frame_address) |
7b4ac7e1 | 377 | cont = -1; |
378 | else | |
379 | { | |
380 | int value_zero; | |
381 | if (b->cond) | |
382 | { | |
4187119d | 383 | /* Need to select the frame, with all that implies |
384 | so that the conditions will have the right context. */ | |
385 | select_frame (get_current_frame (), 0); | |
3bf57d21 | 386 | value_zero |
387 | = catch_errors (breakpoint_cond_eval, b->cond, | |
388 | "Error occurred in testing breakpoint condition."); | |
7b4ac7e1 | 389 | free_all_values (); |
390 | } | |
391 | if (b->cond && value_zero) | |
392 | { | |
393 | cont = -1; | |
394 | } | |
395 | else if (b->ignore_count > 0) | |
396 | { | |
397 | b->ignore_count--; | |
398 | cont = -1; | |
399 | } | |
400 | else | |
401 | { | |
402 | if (b->enable == temporary) | |
403 | b->enable = disabled; | |
404 | breakpoint_commands = b->commands; | |
e91b87a3 | 405 | if (b->silent |
406 | || (breakpoint_commands | |
407 | && !strcmp ("silent", breakpoint_commands->line))) | |
7b4ac7e1 | 408 | { |
e91b87a3 | 409 | if (breakpoint_commands) |
410 | breakpoint_commands = breakpoint_commands->next; | |
411 | return (b->number > 0 ? | |
412 | 0x1000000 + b->number : | |
413 | b->number - 0x1000000); | |
7b4ac7e1 | 414 | } |
415 | return b->number; | |
416 | } | |
417 | } | |
418 | } | |
419 | ||
420 | return cont; | |
421 | } | |
422 | \f | |
423 | static void | |
424 | breakpoint_1 (bnum) | |
425 | int bnum; | |
426 | { | |
427 | register struct breakpoint *b; | |
428 | register struct command_line *l; | |
429 | register struct symbol *sym; | |
4187119d | 430 | CORE_ADDR last_addr = (CORE_ADDR)-1; |
7b4ac7e1 | 431 | |
432 | ALL_BREAKPOINTS (b) | |
433 | if (bnum == -1 || bnum == b->number) | |
434 | { | |
4187119d | 435 | printf_filtered ("#%-3d %c 0x%08x ", b->number, |
7b4ac7e1 | 436 | "nyod"[(int) b->enable], |
437 | b->address); | |
438 | last_addr = b->address; | |
439 | if (b->symtab) | |
440 | { | |
441 | sym = find_pc_function (b->address); | |
442 | if (sym) | |
4187119d | 443 | printf_filtered (" in %s (%s line %d)", SYMBOL_NAME (sym), |
444 | b->symtab->filename, b->line_number); | |
7b4ac7e1 | 445 | else |
4187119d | 446 | printf_filtered ("%s line %d", b->symtab->filename, b->line_number); |
447 | } | |
448 | else | |
449 | { | |
450 | char *name; | |
451 | int addr; | |
452 | ||
453 | if (find_pc_partial_function (b->address, &name, &addr)) | |
454 | { | |
455 | if (b->address - addr) | |
456 | printf_filtered ("<%s+%d>", name, b->address - addr); | |
457 | else | |
458 | printf_filtered ("<%s>", name); | |
459 | } | |
7b4ac7e1 | 460 | } |
4187119d | 461 | |
462 | printf_filtered ("\n"); | |
7b4ac7e1 | 463 | |
464 | if (b->ignore_count) | |
4187119d | 465 | printf_filtered ("\tignore next %d hits\n", b->ignore_count); |
7b4ac7e1 | 466 | if (b->frame) |
4187119d | 467 | printf_filtered ("\tstop only in stack frame at 0x%x\n", b->frame); |
7b4ac7e1 | 468 | if (b->cond) |
469 | { | |
4187119d | 470 | printf_filtered ("\tbreak only if "); |
7b4ac7e1 | 471 | print_expression (b->cond, stdout); |
4187119d | 472 | printf_filtered ("\n"); |
7b4ac7e1 | 473 | } |
474 | if (l = b->commands) | |
475 | while (l) | |
476 | { | |
4187119d | 477 | printf_filtered ("\t%s\n", l->line); |
7b4ac7e1 | 478 | l = l->next; |
479 | } | |
480 | } | |
481 | ||
4187119d | 482 | /* Compare against (CORE_ADDR)-1 in case some compiler decides |
483 | that a comparison of an unsigned with -1 is always false. */ | |
484 | if (last_addr != (CORE_ADDR)-1) | |
7b4ac7e1 | 485 | set_next_address (last_addr); |
486 | } | |
487 | ||
488 | static void | |
489 | breakpoints_info (bnum_exp) | |
490 | char *bnum_exp; | |
491 | { | |
492 | int bnum = -1; | |
493 | ||
494 | if (bnum_exp) | |
495 | bnum = parse_and_eval_address (bnum_exp); | |
496 | else if (breakpoint_chain == 0) | |
4187119d | 497 | printf_filtered ("No breakpoints.\n"); |
7b4ac7e1 | 498 | else |
4187119d | 499 | printf_filtered ("Breakpoints:\n\ |
7b4ac7e1 | 500 | Num Enb Address Where\n"); |
501 | ||
502 | breakpoint_1 (bnum); | |
503 | } | |
504 | ||
505 | /* Print a message describing any breakpoints set at PC. */ | |
506 | ||
507 | static void | |
508 | describe_other_breakpoints (pc) | |
509 | register CORE_ADDR pc; | |
510 | { | |
511 | register int others = 0; | |
512 | register struct breakpoint *b; | |
513 | ||
514 | ALL_BREAKPOINTS (b) | |
515 | if (b->address == pc) | |
516 | others++; | |
517 | if (others > 0) | |
518 | { | |
519 | printf ("Note: breakpoint%s ", (others > 1) ? "s" : ""); | |
520 | ALL_BREAKPOINTS (b) | |
521 | if (b->address == pc) | |
522 | { | |
523 | others--; | |
524 | printf ("%d%s%s ", | |
525 | b->number, | |
526 | (b->enable == disabled) ? " (disabled)" : "", | |
527 | (others > 1) ? "," : ((others == 1) ? " and" : "")); | |
528 | } | |
7a67dd45 | 529 | printf ("also set at pc 0x%x.\n", pc); |
7b4ac7e1 | 530 | } |
531 | } | |
532 | \f | |
533 | /* Set the default place to put a breakpoint | |
534 | for the `break' command with no arguments. */ | |
535 | ||
536 | void | |
537 | set_default_breakpoint (valid, addr, symtab, line) | |
538 | int valid; | |
539 | CORE_ADDR addr; | |
540 | struct symtab *symtab; | |
541 | int line; | |
542 | { | |
543 | default_breakpoint_valid = valid; | |
544 | default_breakpoint_address = addr; | |
545 | default_breakpoint_symtab = symtab; | |
546 | default_breakpoint_line = line; | |
547 | } | |
548 | ||
549 | /* Rescan breakpoints at address ADDRESS, | |
550 | marking the first one as "first" and any others as "duplicates". | |
551 | This is so that the bpt instruction is only inserted once. */ | |
552 | ||
553 | static void | |
554 | check_duplicates (address) | |
555 | CORE_ADDR address; | |
556 | { | |
557 | register struct breakpoint *b; | |
558 | register int count = 0; | |
559 | ||
560 | ALL_BREAKPOINTS (b) | |
561 | if (b->enable != disabled && b->address == address) | |
562 | { | |
563 | count++; | |
564 | b->duplicate = count > 1; | |
565 | } | |
566 | } | |
567 | ||
568 | /* Low level routine to set a breakpoint. | |
569 | Takes as args the three things that every breakpoint must have. | |
570 | Returns the breakpoint object so caller can set other things. | |
571 | Does not set the breakpoint number! | |
572 | Does not print anything. */ | |
573 | ||
574 | static struct breakpoint * | |
575 | set_raw_breakpoint (sal) | |
576 | struct symtab_and_line sal; | |
577 | { | |
578 | register struct breakpoint *b, *b1; | |
579 | ||
580 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
581 | bzero (b, sizeof *b); | |
582 | b->address = sal.pc; | |
583 | b->symtab = sal.symtab; | |
584 | b->line_number = sal.line; | |
585 | b->enable = enabled; | |
586 | b->next = 0; | |
e91b87a3 | 587 | b->silent = 0; |
7b4ac7e1 | 588 | |
589 | /* Add this breakpoint to the end of the chain | |
590 | so that a list of breakpoints will come out in order | |
591 | of increasing numbers. */ | |
592 | ||
593 | b1 = breakpoint_chain; | |
594 | if (b1 == 0) | |
595 | breakpoint_chain = b; | |
596 | else | |
597 | { | |
598 | while (b1->next) | |
599 | b1 = b1->next; | |
600 | b1->next = b; | |
601 | } | |
602 | ||
603 | check_duplicates (sal.pc); | |
604 | ||
605 | return b; | |
606 | } | |
607 | ||
608 | /* Set a breakpoint that will evaporate an end of command | |
609 | at address specified by SAL. | |
610 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
611 | ||
612 | void | |
613 | set_momentary_breakpoint (sal, frame) | |
614 | struct symtab_and_line sal; | |
615 | FRAME frame; | |
616 | { | |
617 | register struct breakpoint *b; | |
618 | b = set_raw_breakpoint (sal); | |
619 | b->number = -3; | |
620 | b->enable = delete; | |
e91b87a3 | 621 | b->frame = (frame ? FRAME_FP (frame) : 0); |
7b4ac7e1 | 622 | } |
623 | ||
624 | void | |
625 | clear_momentary_breakpoints () | |
626 | { | |
627 | register struct breakpoint *b; | |
628 | ALL_BREAKPOINTS (b) | |
629 | if (b->number == -3) | |
630 | { | |
631 | delete_breakpoint (b); | |
632 | break; | |
633 | } | |
634 | } | |
635 | \f | |
636 | /* Set a breakpoint from a symtab and line. | |
637 | If TEMPFLAG is nonzero, it is a temporary breakpoint. | |
638 | Print the same confirmation messages that the breakpoint command prints. */ | |
639 | ||
640 | void | |
641 | set_breakpoint (s, line, tempflag) | |
642 | struct symtab *s; | |
643 | int line; | |
644 | int tempflag; | |
645 | { | |
646 | register struct breakpoint *b; | |
647 | struct symtab_and_line sal; | |
648 | ||
649 | sal.symtab = s; | |
650 | sal.line = line; | |
651 | sal.pc = find_line_pc (sal.symtab, sal.line); | |
652 | if (sal.pc == 0) | |
653 | error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename); | |
654 | else | |
655 | { | |
656 | describe_other_breakpoints (sal.pc); | |
657 | ||
658 | b = set_raw_breakpoint (sal); | |
659 | b->number = ++breakpoint_count; | |
660 | b->cond = 0; | |
661 | if (tempflag) | |
662 | b->enable = temporary; | |
663 | ||
664 | printf ("Breakpoint %d at 0x%x", b->number, b->address); | |
665 | if (b->symtab) | |
666 | printf (": file %s, line %d.", b->symtab->filename, b->line_number); | |
667 | printf ("\n"); | |
668 | } | |
669 | } | |
670 | \f | |
671 | /* Set a breakpoint according to ARG (function, linenum or *address) | |
e91b87a3 | 672 | and make it temporary if TEMPFLAG is nonzero. */ |
7b4ac7e1 | 673 | |
674 | static void | |
e91b87a3 | 675 | break_command_1 (arg, tempflag, from_tty) |
7b4ac7e1 | 676 | char *arg; |
e91b87a3 | 677 | int tempflag, from_tty; |
7b4ac7e1 | 678 | { |
bb7592f0 | 679 | struct symtabs_and_lines sals; |
7b4ac7e1 | 680 | struct symtab_and_line sal; |
681 | register struct expression *cond = 0; | |
682 | register struct breakpoint *b; | |
bb7592f0 | 683 | char *save_arg; |
684 | int i; | |
e91b87a3 | 685 | CORE_ADDR pc; |
bb7592f0 | 686 | |
687 | sals.sals = NULL; | |
688 | sals.nelts = 0; | |
7b4ac7e1 | 689 | |
bb7592f0 | 690 | sal.line = sal.pc = sal.end = 0; |
691 | sal.symtab = 0; | |
7b4ac7e1 | 692 | |
e91b87a3 | 693 | /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ |
7b4ac7e1 | 694 | |
e91b87a3 | 695 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' |
696 | && (arg[2] == ' ' || arg[2] == '\t'))) | |
697 | { | |
698 | if (default_breakpoint_valid) | |
7b4ac7e1 | 699 | { |
e91b87a3 | 700 | sals.sals = (struct symtab_and_line *) |
701 | malloc (sizeof (struct symtab_and_line)); | |
702 | sal.pc = default_breakpoint_address; | |
703 | sal.line = default_breakpoint_line; | |
704 | sal.symtab = default_breakpoint_symtab; | |
705 | sals.sals[0] = sal; | |
706 | sals.nelts = 1; | |
7b4ac7e1 | 707 | } |
e91b87a3 | 708 | else |
709 | error ("No default breakpoint address now."); | |
7b4ac7e1 | 710 | } |
711 | else | |
4187119d | 712 | /* Force almost all breakpoints to be in terms of the |
713 | current_source_symtab (which is decode_line_1's default). This | |
714 | should produce the results we want almost all of the time while | |
715 | leaving default_breakpoint_* alone. */ | |
716 | if (default_breakpoint_valid | |
717 | && (!current_source_symtab | |
718 | || (arg && (*arg == '+' || *arg == '-')))) | |
e91b87a3 | 719 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, |
720 | default_breakpoint_line); | |
721 | else | |
722 | sals = decode_line_1 (&arg, 1, 0, 0); | |
723 | ||
724 | if (! sals.nelts) | |
725 | return; | |
7b4ac7e1 | 726 | |
e91b87a3 | 727 | save_arg = arg; |
bb7592f0 | 728 | for (i = 0; i < sals.nelts; i++) |
729 | { | |
730 | sal = sals.sals[i]; | |
e91b87a3 | 731 | if (sal.pc == 0 && sal.symtab != 0) |
732 | { | |
733 | pc = find_line_pc (sal.symtab, sal.line); | |
734 | if (pc == 0) | |
735 | error ("No line %d in file \"%s\".", | |
736 | sal.line, sal.symtab->filename); | |
737 | } | |
738 | else | |
739 | pc = sal.pc; | |
740 | ||
741 | while (arg && *arg) | |
742 | { | |
743 | if (arg[0] == 'i' && arg[1] == 'f' | |
744 | && (arg[2] == ' ' || arg[2] == '\t')) | |
745 | cond = (struct expression *) parse_c_1 ((arg += 2, &arg), | |
746 | block_for_pc (pc), 0); | |
747 | else | |
748 | error ("Junk at end of arguments."); | |
bb7592f0 | 749 | } |
e91b87a3 | 750 | arg = save_arg; |
751 | sals.sals[i].pc = pc; | |
752 | } | |
753 | ||
754 | for (i = 0; i < sals.nelts; i++) | |
755 | { | |
756 | sal = sals.sals[i]; | |
632ea0cc | 757 | |
bb7592f0 | 758 | if (from_tty) |
759 | describe_other_breakpoints (sal.pc); | |
760 | ||
761 | b = set_raw_breakpoint (sal); | |
762 | b->number = ++breakpoint_count; | |
763 | b->cond = cond; | |
764 | if (tempflag) | |
765 | b->enable = temporary; | |
766 | ||
767 | printf ("Breakpoint %d at 0x%x", b->number, b->address); | |
768 | if (b->symtab) | |
769 | printf (": file %s, line %d.", b->symtab->filename, b->line_number); | |
770 | printf ("\n"); | |
771 | } | |
e91b87a3 | 772 | |
773 | if (sals.nelts > 1) | |
774 | { | |
775 | printf ("Multiple breakpoints were set.\n"); | |
776 | printf ("Use the \"delete\" command to delete unwanted breakpoints.\n"); | |
777 | } | |
bb7592f0 | 778 | free (sals.sals); |
7b4ac7e1 | 779 | } |
780 | ||
781 | static void | |
782 | break_command (arg, from_tty) | |
783 | char *arg; | |
784 | int from_tty; | |
785 | { | |
e91b87a3 | 786 | break_command_1 (arg, 0, from_tty); |
7b4ac7e1 | 787 | } |
788 | ||
789 | static void | |
790 | tbreak_command (arg, from_tty) | |
791 | char *arg; | |
792 | int from_tty; | |
793 | { | |
e91b87a3 | 794 | break_command_1 (arg, 1, from_tty); |
795 | } | |
796 | \f | |
797 | /* | |
798 | * Helper routine for the until_command routine in infcmd.c. Here | |
799 | * because it uses the mechanisms of breakpoints. | |
800 | */ | |
801 | void | |
4187119d | 802 | until_break_command (arg, from_tty) |
e91b87a3 | 803 | char *arg; |
804 | int from_tty; | |
805 | { | |
806 | struct symtabs_and_lines sals; | |
807 | struct symtab_and_line sal; | |
4187119d | 808 | FRAME prev_frame = get_prev_frame (selected_frame); |
809 | ||
810 | clear_proceed_status (); | |
e91b87a3 | 811 | |
812 | /* Set a breakpoint where the user wants it and at return from | |
813 | this function */ | |
814 | ||
815 | if (default_breakpoint_valid) | |
816 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
817 | default_breakpoint_line); | |
818 | else | |
819 | sals = decode_line_1 (&arg, 1, 0, 0); | |
820 | ||
821 | if (sals.nelts != 1) | |
822 | error ("Couldn't get information on specified line."); | |
823 | ||
824 | sal = sals.sals[0]; | |
825 | free (sals.sals); /* malloc'd, so freed */ | |
826 | ||
827 | if (*arg) | |
828 | error ("Junk at end of arguments."); | |
829 | ||
830 | if (sal.pc == 0 && sal.symtab != 0) | |
831 | sal.pc = find_line_pc (sal.symtab, sal.line); | |
832 | ||
833 | if (sal.pc == 0) | |
834 | error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename); | |
835 | ||
4187119d | 836 | set_momentary_breakpoint (sal, selected_frame); |
e91b87a3 | 837 | |
838 | /* Keep within the current frame */ | |
839 | ||
840 | if (prev_frame) | |
841 | { | |
842 | struct frame_info *fi; | |
843 | ||
844 | fi = get_frame_info (prev_frame); | |
845 | sal = find_pc_line (fi->pc, 0); | |
846 | sal.pc = fi->pc; | |
847 | set_momentary_breakpoint (sal, prev_frame); | |
848 | } | |
849 | ||
850 | proceed (-1, -1, 0); | |
7b4ac7e1 | 851 | } |
852 | \f | |
853 | static void | |
854 | clear_command (arg, from_tty) | |
855 | char *arg; | |
856 | int from_tty; | |
857 | { | |
858 | register struct breakpoint *b, *b1; | |
bb7592f0 | 859 | struct symtabs_and_lines sals; |
7b4ac7e1 | 860 | struct symtab_and_line sal; |
861 | register struct breakpoint *found; | |
bb7592f0 | 862 | int i; |
7b4ac7e1 | 863 | |
864 | if (arg) | |
e91b87a3 | 865 | { |
866 | sals = decode_line_spec (arg, 1); | |
867 | } | |
7b4ac7e1 | 868 | else |
869 | { | |
bb7592f0 | 870 | sals.sals = (struct symtab_and_line *) malloc (sizeof (struct symtab_and_line)); |
7b4ac7e1 | 871 | sal.line = default_breakpoint_line; |
872 | sal.symtab = default_breakpoint_symtab; | |
873 | sal.pc = 0; | |
874 | if (sal.symtab == 0) | |
875 | error ("No source file specified."); | |
7b4ac7e1 | 876 | |
bb7592f0 | 877 | sals.sals[0] = sal; |
878 | sals.nelts = 1; | |
879 | } | |
3bf57d21 | 880 | |
bb7592f0 | 881 | for (i = 0; i < sals.nelts; i++) |
7b4ac7e1 | 882 | { |
bb7592f0 | 883 | /* If exact pc given, clear bpts at that pc. |
884 | But if sal.pc is zero, clear all bpts on specified line. */ | |
885 | sal = sals.sals[i]; | |
886 | found = (struct breakpoint *) 0; | |
887 | while (breakpoint_chain | |
888 | && (sal.pc ? breakpoint_chain->address == sal.pc | |
889 | : (breakpoint_chain->symtab == sal.symtab | |
890 | && breakpoint_chain->line_number == sal.line))) | |
891 | { | |
892 | b1 = breakpoint_chain; | |
893 | breakpoint_chain = b1->next; | |
894 | b1->next = found; | |
895 | found = b1; | |
896 | } | |
7b4ac7e1 | 897 | |
bb7592f0 | 898 | ALL_BREAKPOINTS (b) |
899 | while (b->next | |
900 | && (sal.pc ? b->next->address == sal.pc | |
901 | : (b->next->symtab == sal.symtab | |
902 | && b->next->line_number == sal.line))) | |
903 | { | |
904 | b1 = b->next; | |
905 | b->next = b1->next; | |
906 | b1->next = found; | |
907 | found = b1; | |
908 | } | |
7b4ac7e1 | 909 | |
bb7592f0 | 910 | if (found == 0) |
911 | error ("No breakpoint at %s.", arg); | |
7b4ac7e1 | 912 | |
bb7592f0 | 913 | if (found->next) from_tty = 1; /* Always report if deleted more than one */ |
914 | if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : ""); | |
915 | while (found) | |
916 | { | |
917 | if (from_tty) printf ("%d ", found->number); | |
918 | b1 = found->next; | |
919 | delete_breakpoint (found); | |
920 | found = b1; | |
921 | } | |
922 | if (from_tty) putchar ('\n'); | |
7b4ac7e1 | 923 | } |
bb7592f0 | 924 | free (sals.sals); |
7b4ac7e1 | 925 | } |
e91b87a3 | 926 | \f |
7b4ac7e1 | 927 | /* Delete breakpoint number BNUM if it is a `delete' breakpoint. |
928 | This is called after breakpoint BNUM has been hit. | |
929 | Also delete any breakpoint numbered -3 unless there are breakpoint | |
930 | commands to be executed. */ | |
931 | ||
932 | void | |
933 | breakpoint_auto_delete (bnum) | |
934 | int bnum; | |
935 | { | |
936 | register struct breakpoint *b; | |
937 | if (bnum != 0) | |
938 | ALL_BREAKPOINTS (b) | |
939 | if (b->number == bnum) | |
940 | { | |
941 | if (b->enable == delete) | |
942 | delete_breakpoint (b); | |
943 | break; | |
944 | } | |
945 | if (breakpoint_commands == 0) | |
946 | clear_momentary_breakpoints (); | |
947 | } | |
948 | ||
949 | static void | |
950 | delete_breakpoint (bpt) | |
951 | struct breakpoint *bpt; | |
952 | { | |
953 | register struct breakpoint *b; | |
954 | ||
955 | if (bpt->inserted) | |
956 | write_memory (bpt->address, bpt->shadow_contents, sizeof break_insn); | |
957 | ||
958 | if (breakpoint_chain == bpt) | |
959 | breakpoint_chain = bpt->next; | |
960 | ||
961 | ALL_BREAKPOINTS (b) | |
962 | if (b->next == bpt) | |
963 | { | |
964 | b->next = bpt->next; | |
965 | break; | |
966 | } | |
967 | ||
968 | check_duplicates (bpt->address); | |
969 | ||
970 | free_command_lines (&bpt->commands); | |
971 | if (bpt->cond) | |
972 | free (bpt->cond); | |
4187119d | 973 | |
974 | if (xgdb_verbose && bpt->number >=0) | |
975 | printf ("breakpoint #%d deleted\n", bpt->number); | |
976 | ||
7b4ac7e1 | 977 | free (bpt); |
978 | } | |
979 | ||
e91b87a3 | 980 | static void map_breakpoint_numbers (); |
7b4ac7e1 | 981 | |
982 | static void | |
983 | delete_command (arg, from_tty) | |
984 | char *arg; | |
985 | int from_tty; | |
986 | { | |
987 | register struct breakpoint *b, *b1; | |
988 | ||
989 | if (arg == 0) | |
990 | { | |
4187119d | 991 | /* Ask user only if there are some breakpoints to delete. */ |
992 | if (!from_tty | |
993 | || breakpoint_chain && query ("Delete all breakpoints? ")) | |
7b4ac7e1 | 994 | { |
995 | /* No arg; clear all breakpoints. */ | |
996 | while (breakpoint_chain) | |
997 | delete_breakpoint (breakpoint_chain); | |
998 | } | |
999 | } | |
1000 | else | |
1001 | map_breakpoint_numbers (arg, delete_breakpoint); | |
1002 | } | |
1003 | ||
1004 | /* Delete all breakpoints. | |
1005 | Done when new symtabs are loaded, since the break condition expressions | |
1006 | may become invalid, and the breakpoints are probably wrong anyway. */ | |
1007 | ||
1008 | void | |
1009 | clear_breakpoints () | |
1010 | { | |
1011 | delete_command (0, 0); | |
1012 | } | |
1013 | \f | |
1014 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. | |
1015 | If from_tty is nonzero, it prints a message to that effect, | |
1016 | which ends with a period (no newline). */ | |
1017 | ||
1018 | void | |
1019 | set_ignore_count (bptnum, count, from_tty) | |
1020 | int bptnum, count, from_tty; | |
1021 | { | |
1022 | register struct breakpoint *b; | |
1023 | ||
1024 | if (count < 0) | |
1025 | count = 0; | |
1026 | ||
1027 | ALL_BREAKPOINTS (b) | |
1028 | if (b->number == bptnum) | |
1029 | { | |
1030 | b->ignore_count = count; | |
1031 | if (!from_tty) | |
1032 | return; | |
1033 | else if (count == 0) | |
1034 | printf ("Will stop next time breakpoint %d is reached.", bptnum); | |
1035 | else if (count == 1) | |
1036 | printf ("Will ignore next crossing of breakpoint %d.", bptnum); | |
1037 | else | |
1038 | printf ("Will ignore next %d crossings of breakpoint %d.", | |
1039 | count, bptnum); | |
1040 | return; | |
1041 | } | |
1042 | ||
1043 | error ("No breakpoint number %d.", bptnum); | |
1044 | } | |
1045 | ||
7a67dd45 | 1046 | /* Clear the ignore counts of all breakpoints. */ |
1047 | void | |
1048 | breakpoint_clear_ignore_counts () | |
1049 | { | |
1050 | struct breakpoint *b; | |
1051 | ||
1052 | ALL_BREAKPOINTS (b) | |
1053 | b->ignore_count = 0; | |
1054 | } | |
1055 | ||
7b4ac7e1 | 1056 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
1057 | ||
1058 | static void | |
1059 | ignore_command (args, from_tty) | |
1060 | char *args; | |
1061 | int from_tty; | |
1062 | { | |
3bf57d21 | 1063 | register char *p = args; |
7b4ac7e1 | 1064 | register int num; |
1065 | ||
1066 | if (p == 0) | |
1067 | error_no_arg ("a breakpoint number"); | |
1068 | ||
7b4ac7e1 | 1069 | while (*p >= '0' && *p <= '9') p++; |
1070 | if (*p && *p != ' ' && *p != '\t') | |
1071 | error ("First argument must be a breakpoint number."); | |
1072 | ||
1073 | num = atoi (args); | |
1074 | ||
1075 | if (*p == 0) | |
1076 | error ("Second argument (specified ignore-count) is missing."); | |
1077 | ||
1078 | set_ignore_count (num, parse_and_eval_address (p), from_tty); | |
1079 | printf ("\n"); | |
1080 | } | |
1081 | \f | |
1082 | /* Call FUNCTION on each of the breakpoints | |
1083 | whose numbers are given in ARGS. */ | |
1084 | ||
1085 | static void | |
1086 | map_breakpoint_numbers (args, function) | |
1087 | char *args; | |
1088 | void (*function) (); | |
1089 | { | |
1090 | register char *p = args; | |
1091 | register char *p1; | |
1092 | register int num; | |
1093 | register struct breakpoint *b; | |
1094 | ||
1095 | if (p == 0) | |
1096 | error_no_arg ("one or more breakpoint numbers"); | |
1097 | ||
1098 | while (*p) | |
1099 | { | |
1100 | p1 = p; | |
1101 | while (*p1 >= '0' && *p1 <= '9') p1++; | |
1102 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
1103 | error ("Arguments must be breakpoint numbers."); | |
1104 | ||
1105 | num = atoi (p); | |
1106 | ||
1107 | ALL_BREAKPOINTS (b) | |
1108 | if (b->number == num) | |
1109 | { | |
1110 | function (b); | |
1111 | goto win; | |
1112 | } | |
1113 | printf ("No breakpoint number %d.\n", num); | |
1114 | win: | |
1115 | p = p1; | |
1116 | while (*p == ' ' || *p == '\t') p++; | |
1117 | } | |
1118 | } | |
1119 | ||
1120 | static void | |
1121 | enable_breakpoint (bpt) | |
1122 | struct breakpoint *bpt; | |
1123 | { | |
1124 | bpt->enable = enabled; | |
1125 | ||
4187119d | 1126 | if (xgdb_verbose && bpt->number >= 0) |
1127 | printf ("breakpoint #%d enabled\n", bpt->number); | |
1128 | ||
7b4ac7e1 | 1129 | check_duplicates (bpt->address); |
1130 | } | |
1131 | ||
1132 | static void | |
1133 | enable_command (args) | |
1134 | char *args; | |
1135 | { | |
4187119d | 1136 | struct breakpoint *bpt; |
1137 | if (args == 0) | |
1138 | ALL_BREAKPOINTS (bpt) | |
1139 | enable_breakpoint (bpt); | |
1140 | else | |
1141 | map_breakpoint_numbers (args, enable_breakpoint); | |
7b4ac7e1 | 1142 | } |
1143 | ||
1144 | static void | |
1145 | disable_breakpoint (bpt) | |
1146 | struct breakpoint *bpt; | |
1147 | { | |
1148 | bpt->enable = disabled; | |
1149 | ||
4187119d | 1150 | if (xgdb_verbose && bpt->number >= 0) |
1151 | printf ("breakpoint #%d disabled\n", bpt->number); | |
1152 | ||
7b4ac7e1 | 1153 | check_duplicates (bpt->address); |
1154 | } | |
1155 | ||
1156 | static void | |
1157 | disable_command (args) | |
1158 | char *args; | |
1159 | { | |
1160 | register struct breakpoint *bpt; | |
1161 | if (args == 0) | |
1162 | ALL_BREAKPOINTS (bpt) | |
1163 | disable_breakpoint (bpt); | |
1164 | else | |
1165 | map_breakpoint_numbers (args, disable_breakpoint); | |
1166 | } | |
1167 | ||
1168 | static void | |
1169 | enable_once_breakpoint (bpt) | |
1170 | struct breakpoint *bpt; | |
1171 | { | |
1172 | bpt->enable = temporary; | |
1173 | ||
1174 | check_duplicates (bpt->address); | |
1175 | } | |
1176 | ||
1177 | static void | |
1178 | enable_once_command (args) | |
1179 | char *args; | |
1180 | { | |
1181 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
1182 | } | |
1183 | ||
1184 | static void | |
1185 | enable_delete_breakpoint (bpt) | |
1186 | struct breakpoint *bpt; | |
1187 | { | |
1188 | bpt->enable = delete; | |
1189 | ||
1190 | check_duplicates (bpt->address); | |
1191 | } | |
1192 | ||
1193 | static void | |
1194 | enable_delete_command (args) | |
1195 | char *args; | |
1196 | { | |
1197 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
1198 | } | |
1199 | \f | |
e91b87a3 | 1200 | /* |
1201 | * Use default_breakpoint_'s, or nothing if they aren't valid. | |
1202 | */ | |
1203 | struct symtabs_and_lines | |
1204 | decode_line_spec_1 (string, funfirstline) | |
1205 | char *string; | |
1206 | int funfirstline; | |
1207 | { | |
1208 | struct symtabs_and_lines sals; | |
1209 | if (string == 0) | |
1210 | error ("Empty line specification."); | |
1211 | if (default_breakpoint_valid) | |
1212 | sals = decode_line_1 (&string, funfirstline, | |
1213 | default_breakpoint_symtab, default_breakpoint_line); | |
1214 | else | |
1215 | sals = decode_line_1 (&string, funfirstline, 0, 0); | |
1216 | if (*string) | |
1217 | error ("Junk at end of line specification: %s", string); | |
1218 | return sals; | |
1219 | } | |
1220 | \f | |
7b4ac7e1 | 1221 | |
1222 | /* Chain containing all defined enable commands. */ | |
1223 | ||
e91b87a3 | 1224 | extern struct cmd_list_element |
1225 | *enablelist, *disablelist, | |
1226 | *deletelist, *enablebreaklist; | |
7b4ac7e1 | 1227 | |
1228 | extern struct cmd_list_element *cmdlist; | |
1229 | ||
e91b87a3 | 1230 | void |
1231 | _initialize_breakpoint () | |
7b4ac7e1 | 1232 | { |
1233 | breakpoint_chain = 0; | |
1234 | breakpoint_count = 0; | |
7b4ac7e1 | 1235 | |
1236 | add_com ("ignore", class_breakpoint, ignore_command, | |
1237 | "Set ignore-count of breakpoint number N to COUNT."); | |
1238 | ||
1239 | add_com ("commands", class_breakpoint, commands_command, | |
1240 | "Set commands to be executed when a breakpoint is hit.\n\ | |
1241 | Give breakpoint number as argument after \"commands\".\n\ | |
e91b87a3 | 1242 | With no argument, the targeted breakpoint is the last one set.\n\ |
7b4ac7e1 | 1243 | The commands themselves follow starting on the next line.\n\ |
1244 | Type a line containing \"end\" to indicate the end of them.\n\ | |
1245 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1246 | then no output is printed when it is hit, except what the commands print."); | |
1247 | ||
1248 | add_com ("condition", class_breakpoint, condition_command, | |
1249 | "Specify breakpoint number N to break only if COND is true.\n\ | |
1250 | N is an integer; COND is a C expression to be evaluated whenever\n\ | |
1251 | breakpoint N is reached. Actually break only when COND is nonzero."); | |
1252 | ||
1253 | add_com ("tbreak", class_breakpoint, tbreak_command, | |
1254 | "Set a temporary breakpoint. Args like \"break\" command.\n\ | |
1255 | Like \"break\" except the breakpoint is only enabled temporarily,\n\ | |
1256 | so it will be disabled when hit. Equivalent to \"break\" followed\n\ | |
1257 | by using \"enable once\" on the breakpoint number."); | |
1258 | ||
1259 | add_prefix_cmd ("enable", class_breakpoint, enable_command, | |
e91b87a3 | 1260 | "Enable some breakpoints or auto-display expressions.\n\ |
1261 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
7b4ac7e1 | 1262 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
1263 | This is used to cancel the effect of the \"disable\" command.\n\ | |
e91b87a3 | 1264 | With a subcommand you can enable temporarily.\n\ |
1265 | \n\ | |
1266 | The \"display\" subcommand applies to auto-displays instead of breakpoints.", | |
7b4ac7e1 | 1267 | &enablelist, "enable ", 1, &cmdlist); |
1268 | ||
e91b87a3 | 1269 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, |
1270 | "Enable some breakpoints or auto-display expressions.\n\ | |
1271 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
1272 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
1273 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1274 | May be abbreviates to simply \"enable\".\n\ | |
1275 | With a subcommand you can enable temporarily.", | |
1276 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); | |
1277 | ||
1278 | add_cmd ("once", no_class, enable_once_command, | |
1279 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
1280 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ | |
1281 | See the \"tbreak\" command which sets a breakpoint and enables it once.", | |
1282 | &enablebreaklist); | |
1283 | ||
1284 | add_cmd ("delete", no_class, enable_delete_command, | |
1285 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
1286 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
1287 | &enablebreaklist); | |
1288 | ||
1289 | add_cmd ("delete", no_class, enable_delete_command, | |
7b4ac7e1 | 1290 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
1291 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
1292 | &enablelist); | |
1293 | ||
e91b87a3 | 1294 | add_cmd ("once", no_class, enable_once_command, |
7b4ac7e1 | 1295 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
1296 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ | |
1297 | See the \"tbreak\" command which sets a breakpoint and enables it once.", | |
1298 | &enablelist); | |
1299 | ||
e91b87a3 | 1300 | add_prefix_cmd ("disable", class_breakpoint, disable_command, |
1301 | "Disable some breakpoints or auto-display expressions.\n\ | |
1302 | Arguments are breakpoint numbers with spaces in between.\n\ | |
1303 | To disable all breakpoints, give no argument.\n\ | |
1304 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1305 | \n\ | |
1306 | The \"display\" subcommand applies to auto-displays instead of breakpoints.", | |
1307 | &disablelist, "disable ", 1, &cmdlist); | |
7b4ac7e1 | 1308 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
1c997a4a | 1309 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
7b4ac7e1 | 1310 | |
e91b87a3 | 1311 | add_abbrev_cmd ("breakpoints", class_breakpoint, disable_command, |
1312 | "Disable some breakpoints or auto-display expressions.\n\ | |
1313 | Arguments are breakpoint numbers with spaces in between.\n\ | |
1314 | To disable all breakpoints, give no argument.\n\ | |
1315 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1316 | This command may be abbreviated \"disable\".", | |
1317 | &disablelist); | |
1318 | ||
1319 | add_prefix_cmd ("delete", class_breakpoint, delete_command, | |
1320 | "Delete some breakpoints or auto-display expressions.\n\ | |
7b4ac7e1 | 1321 | Arguments are breakpoint numbers with spaces in between.\n\ |
e91b87a3 | 1322 | To delete all breakpoints, give no argument.\n\ |
1323 | \n\ | |
4187119d | 1324 | Also a prefix command for deletion of other GDB objects.\n\ |
1325 | The \"unset\" command is also an alias for \"delete\".", | |
e91b87a3 | 1326 | &deletelist, "delete ", 1, &cmdlist); |
7b4ac7e1 | 1327 | add_com_alias ("d", "delete", class_breakpoint, 1); |
4187119d | 1328 | add_com_alias ("unset", "delete", class_alias, 1); |
e91b87a3 | 1329 | |
4187119d | 1330 | add_cmd ("breakpoints", class_alias, delete_command, |
e91b87a3 | 1331 | "Delete some breakpoints or auto-display expressions.\n\ |
1332 | Arguments are breakpoint numbers with spaces in between.\n\ | |
1333 | To delete all breakpoints, give no argument.\n\ | |
1334 | This command may be abbreviated \"delete\".", | |
1335 | &deletelist); | |
7b4ac7e1 | 1336 | |
1337 | add_com ("clear", class_breakpoint, clear_command, | |
1338 | "Clear breakpoint at specified line or function.\n\ | |
1339 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
1340 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
1341 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1342 | If an address is specified, breakpoints at that address are cleared.\n\n\ | |
1343 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
1344 | is executing in.\n\ | |
1345 | \n\ | |
1346 | See also the \"delete\" command which clears breakpoints by number."); | |
1347 | ||
1348 | add_com ("break", class_breakpoint, break_command, | |
1349 | "Set breakpoint at specified line or function.\n\ | |
1350 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
1351 | If line number is specified, break at start of code for that line.\n\ | |
1352 | If function is specified, break at start of code for that function.\n\ | |
1353 | If an address is specified, break at that exact address.\n\ | |
1354 | With no arg, uses current execution address of selected stack frame.\n\ | |
1355 | This is useful for breaking on return to a stack frame.\n\ | |
1356 | \n\ | |
1357 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
1358 | \n\ | |
1359 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
1360 | add_com_alias ("b", "break", class_run, 1); | |
1361 | add_com_alias ("br", "break", class_run, 1); | |
1362 | add_com_alias ("bre", "break", class_run, 1); | |
1363 | add_com_alias ("brea", "break", class_run, 1); | |
1364 | ||
1365 | add_info ("breakpoints", breakpoints_info, | |
1366 | "Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
1367 | Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\ | |
1368 | \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\ | |
1369 | Then come the address and the file/line number.\n\n\ | |
1370 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
1371 | are set to the address of the last breakpoint listed."); | |
1372 | } | |
1373 |