Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Everything about breakpoints, for GDB. |
2 | Copyright (C) 1986, 1987, 1989, 1990 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. */ | |
19 | ||
20 | #include <stdio.h> | |
21 | #include <ctype.h> | |
22 | #include "defs.h" | |
23 | #include "param.h" | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
27 | #include "expression.h" | |
28 | #include "gdbcore.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "value.h" | |
31 | #include "ctype.h" | |
32 | #include "command.h" | |
33 | #include "inferior.h" | |
34 | #include "target.h" | |
35 | #include <string.h> | |
36 | ||
37 | extern int addressprint; /* Print machine addresses? */ | |
38 | extern int demangle; /* Print de-mangled symbol names? */ | |
39 | ||
40 | extern int catch_errors (); | |
41 | extern void set_next_address (); /* ...for x/ command */ | |
42 | ||
43 | /* Are we executing breakpoint commands? */ | |
44 | static int executing_breakpoint_commands; | |
45 | ||
46 | /* States of enablement of breakpoint. | |
47 | `temporary' means disable when hit. | |
48 | `delete' means delete when hit. */ | |
49 | ||
50 | enum enable { disabled, enabled, temporary, delete}; | |
51 | ||
52 | /* Not that the ->silent field is not currently used by any commands | |
53 | (though the code is in there if it was to be and set_raw_breakpoint | |
54 | does set it to 0). I implemented it because I thought it would be | |
55 | useful for a hack I had to put in; I'm going to leave it in because | |
56 | I can see how there might be times when it would indeed be useful */ | |
57 | ||
58 | /* This is for a breakpoint or a watchpoint. */ | |
59 | ||
60 | struct breakpoint | |
61 | { | |
62 | struct breakpoint *next; | |
63 | /* Number assigned to distinguish breakpoints. */ | |
64 | int number; | |
65 | /* Address to break at, or NULL if not a breakpoint. */ | |
66 | CORE_ADDR address; | |
67 | /* Line number of this address. Redundant. Only matters if address | |
68 | is non-NULL. */ | |
69 | int line_number; | |
70 | /* Symtab of file of this address. Redundant. Only matters if address | |
71 | is non-NULL. */ | |
72 | struct symtab *symtab; | |
73 | /* Zero means disabled; remember the info but don't break here. */ | |
74 | enum enable enable; | |
75 | /* Non-zero means a silent breakpoint (don't print frame info | |
76 | if we stop here). */ | |
77 | unsigned char silent; | |
78 | /* Number of stops at this breakpoint that should | |
79 | be continued automatically before really stopping. */ | |
80 | int ignore_count; | |
81 | /* "Real" contents of byte where breakpoint has been inserted. | |
82 | Valid only when breakpoints are in the program. Under the complete | |
83 | control of the target insert_breakpoint and remove_breakpoint routines. | |
84 | No other code should assume anything about the value(s) here. */ | |
85 | char shadow_contents[BREAKPOINT_MAX]; | |
86 | /* Nonzero if this breakpoint is now inserted. Only matters if address | |
87 | is non-NULL. */ | |
88 | char inserted; | |
89 | /* Nonzero if this is not the first breakpoint in the list | |
90 | for the given address. Only matters if address is non-NULL. */ | |
91 | char duplicate; | |
92 | /* Chain of command lines to execute when this breakpoint is hit. */ | |
93 | struct command_line *commands; | |
94 | /* Stack depth (address of frame). If nonzero, break only if fp | |
95 | equals this. */ | |
96 | FRAME_ADDR frame; | |
97 | /* Conditional. Break only if this expression's value is nonzero. */ | |
98 | struct expression *cond; | |
99 | ||
100 | /* String we used to set the breakpoint (malloc'd). Only matters if | |
101 | address is non-NULL. */ | |
102 | char *addr_string; | |
103 | /* String form of the breakpoint condition (malloc'd), or NULL if there | |
104 | is no condition. */ | |
105 | char *cond_string; | |
106 | ||
107 | /* The expression we are watching, or NULL if not a watchpoint. */ | |
108 | struct expression *exp; | |
109 | /* The largest block within which it is valid, or NULL if it is | |
110 | valid anywhere (e.g. consists just of global symbols). */ | |
111 | struct block *exp_valid_block; | |
112 | /* Value of the watchpoint the last time we checked it. */ | |
113 | value val; | |
114 | }; | |
115 | ||
116 | #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) | |
117 | ||
118 | /* Chain of all breakpoints defined. */ | |
119 | ||
120 | struct breakpoint *breakpoint_chain; | |
121 | ||
122 | /* Number of last breakpoint made. */ | |
123 | ||
124 | static int breakpoint_count; | |
125 | ||
126 | /* Set breakpoint count to NUM. */ | |
127 | static void | |
128 | set_breakpoint_count (num) | |
129 | int num; | |
130 | { | |
131 | breakpoint_count = num; | |
132 | set_internalvar (lookup_internalvar ("bpnum"), | |
133 | value_from_long (builtin_type_int, (LONGEST) num)); | |
134 | } | |
135 | ||
136 | /* Default address, symtab and line to put a breakpoint at | |
137 | for "break" command with no arg. | |
138 | if default_breakpoint_valid is zero, the other three are | |
139 | not valid, and "break" with no arg is an error. | |
140 | ||
141 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
142 | ||
143 | int default_breakpoint_valid; | |
144 | CORE_ADDR default_breakpoint_address; | |
145 | struct symtab *default_breakpoint_symtab; | |
146 | int default_breakpoint_line; | |
147 | ||
148 | static void delete_breakpoint (); | |
149 | void breakpoint_auto_delete (); | |
150 | ||
151 | /* Flag indicating extra verbosity for xgdb. */ | |
152 | extern int xgdb_verbose; | |
153 | \f | |
154 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
155 | Advance *PP after the string and any trailing whitespace. | |
156 | ||
157 | Currently the string can either be a number or "$" followed by the name | |
158 | of a convenience variable. Making it an expression wouldn't work well | |
159 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */ | |
160 | static int | |
161 | get_number (pp) | |
162 | char **pp; | |
163 | { | |
164 | int retval; | |
165 | char *p = *pp; | |
166 | ||
167 | if (p == NULL) | |
168 | /* Empty line means refer to the last breakpoint. */ | |
169 | return breakpoint_count; | |
170 | else if (*p == '$') | |
171 | { | |
172 | /* Make a copy of the name, so we can null-terminate it | |
173 | to pass to lookup_internalvar(). */ | |
174 | char *varname; | |
175 | char *start = ++p; | |
176 | value val; | |
177 | ||
178 | while (isalnum (*p) || *p == '_') | |
179 | p++; | |
180 | varname = (char *) alloca (p - start + 1); | |
181 | strncpy (varname, start, p - start); | |
182 | varname[p - start] = '\0'; | |
183 | val = value_of_internalvar (lookup_internalvar (varname)); | |
184 | if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT) | |
185 | error ( | |
186 | "Convenience variables used to specify breakpoints must have integer values." | |
187 | ); | |
188 | retval = (int) value_as_long (val); | |
189 | } | |
190 | else | |
191 | { | |
192 | while (*p >= '0' && *p <= '9') | |
193 | ++p; | |
194 | if (p == *pp) | |
195 | /* There is no number here. (e.g. "cond a == b"). */ | |
196 | error_no_arg ("breakpoint number"); | |
197 | retval = atoi (*pp); | |
198 | } | |
199 | if (!(isspace (*p) || *p == '\0')) | |
200 | error ("breakpoint number expected"); | |
201 | while (isspace (*p)) | |
202 | p++; | |
203 | *pp = p; | |
204 | return retval; | |
205 | } | |
206 | \f | |
207 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
208 | ||
209 | static void | |
210 | condition_command (arg, from_tty) | |
211 | char *arg; | |
212 | int from_tty; | |
213 | { | |
214 | register struct breakpoint *b; | |
215 | char *p; | |
216 | register int bnum; | |
217 | ||
218 | if (arg == 0) | |
219 | error_no_arg ("breakpoint number"); | |
220 | ||
221 | p = arg; | |
222 | bnum = get_number (&p); | |
223 | ||
224 | ALL_BREAKPOINTS (b) | |
225 | if (b->number == bnum) | |
226 | { | |
227 | if (b->cond) | |
228 | { | |
229 | free (b->cond); | |
230 | b->cond = 0; | |
231 | } | |
232 | if (b->cond_string != NULL) | |
233 | free (b->cond_string); | |
234 | ||
235 | if (*p == 0) | |
236 | { | |
237 | b->cond = 0; | |
238 | b->cond_string = NULL; | |
239 | if (from_tty) | |
240 | printf ("Breakpoint %d now unconditional.\n", bnum); | |
241 | } | |
242 | else | |
243 | { | |
244 | arg = p; | |
245 | /* I don't know if it matters whether this is the string the user | |
246 | typed in or the decompiled expression. */ | |
247 | b->cond_string = savestring (arg, strlen (arg)); | |
248 | b->cond = parse_c_1 (&arg, block_for_pc (b->address), 0); | |
249 | if (*arg) | |
250 | error ("Junk at end of expression"); | |
251 | } | |
252 | return; | |
253 | } | |
254 | ||
255 | error ("No breakpoint number %d.", bnum); | |
256 | } | |
257 | ||
258 | static void | |
259 | commands_command (arg, from_tty) | |
260 | char *arg; | |
261 | int from_tty; | |
262 | { | |
263 | register struct breakpoint *b; | |
264 | char *p; | |
265 | register int bnum; | |
266 | struct command_line *l; | |
267 | ||
268 | /* If we allowed this, we would have problems with when to | |
269 | free the storage, if we change the commands currently | |
270 | being read from. */ | |
271 | ||
272 | if (executing_breakpoint_commands) | |
273 | error ("Can't use the \"commands\" command among a breakpoint's commands."); | |
274 | ||
275 | p = arg; | |
276 | bnum = get_number (&p); | |
277 | if (p && *p) | |
278 | error ("Unexpected extra arguments following breakpoint number."); | |
279 | ||
280 | ALL_BREAKPOINTS (b) | |
281 | if (b->number == bnum) | |
282 | { | |
283 | if (input_from_terminal_p ()) | |
284 | { | |
285 | printf ("Type commands for when breakpoint %d is hit, one per line.\n\ | |
286 | End with a line saying just \"end\".\n", bnum); | |
287 | fflush (stdout); | |
288 | } | |
289 | l = read_command_lines (); | |
290 | free_command_lines (&b->commands); | |
291 | b->commands = l; | |
292 | return; | |
293 | } | |
294 | error ("No breakpoint number %d.", bnum); | |
295 | } | |
296 | \f | |
297 | /* insert_breakpoints is used when starting or continuing the program. | |
298 | remove_breakpoints is used when the program stops. | |
299 | Both return zero if successful, | |
300 | or an `errno' value if could not write the inferior. */ | |
301 | ||
302 | int | |
303 | insert_breakpoints () | |
304 | { | |
305 | register struct breakpoint *b; | |
306 | int val = 0; | |
307 | int disabled_breaks = 0; | |
308 | ||
309 | ALL_BREAKPOINTS (b) | |
310 | if (b->address != NULL | |
311 | && b->enable != disabled | |
312 | && ! b->inserted | |
313 | && ! b->duplicate) | |
314 | { | |
315 | val = target_insert_breakpoint(b->address, b->shadow_contents); | |
316 | if (val) | |
317 | { | |
318 | /* Can't set the breakpoint. */ | |
319 | #if defined (DISABLE_UNSETTABLE_BREAK) | |
320 | if (DISABLE_UNSETTABLE_BREAK (b->address)) | |
321 | { | |
322 | val = 0; | |
323 | b->enable = disabled; | |
324 | if (!disabled_breaks) | |
325 | { | |
326 | fprintf (stderr, | |
327 | "Cannot insert breakpoint %d:\n", b->number); | |
328 | printf_filtered ("Disabling shared library breakpoints:\n"); | |
329 | } | |
330 | disabled_breaks = 1; | |
331 | printf_filtered ("%d ", b->number); | |
332 | } | |
333 | else | |
334 | #endif | |
335 | { | |
336 | fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number); | |
337 | memory_error (val, b->address); /* which bombs us out */ | |
338 | } | |
339 | } | |
340 | else | |
341 | b->inserted = 1; | |
342 | } | |
343 | if (disabled_breaks) | |
344 | printf_filtered ("\n"); | |
345 | return val; | |
346 | } | |
347 | ||
348 | int | |
349 | remove_breakpoints () | |
350 | { | |
351 | register struct breakpoint *b; | |
352 | int val; | |
353 | ||
354 | #ifdef BREAKPOINT_DEBUG | |
355 | printf ("Removing breakpoints.\n"); | |
356 | #endif /* BREAKPOINT_DEBUG */ | |
357 | ||
358 | ALL_BREAKPOINTS (b) | |
359 | if (b->address != NULL && b->inserted) | |
360 | { | |
361 | val = target_remove_breakpoint(b->address, b->shadow_contents); | |
362 | if (val) | |
363 | return val; | |
364 | b->inserted = 0; | |
365 | #ifdef BREAKPOINT_DEBUG | |
366 | printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n", | |
367 | b->address, b->shadow_contents[0], b->shadow_contents[1]); | |
368 | #endif /* BREAKPOINT_DEBUG */ | |
369 | } | |
370 | ||
371 | return 0; | |
372 | } | |
373 | ||
374 | /* Clear the "inserted" flag in all breakpoints. | |
375 | This is done when the inferior is loaded. */ | |
376 | ||
377 | void | |
378 | mark_breakpoints_out () | |
379 | { | |
380 | register struct breakpoint *b; | |
381 | ||
382 | ALL_BREAKPOINTS (b) | |
383 | b->inserted = 0; | |
384 | } | |
385 | ||
386 | /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC. | |
387 | When continuing from a location with a breakpoint, | |
388 | we actually single step once before calling insert_breakpoints. */ | |
389 | ||
390 | int | |
391 | breakpoint_here_p (pc) | |
392 | CORE_ADDR pc; | |
393 | { | |
394 | register struct breakpoint *b; | |
395 | ||
396 | ALL_BREAKPOINTS (b) | |
397 | if (b->enable != disabled && b->address == pc) | |
398 | return 1; | |
399 | ||
400 | return 0; | |
401 | } | |
402 | \f | |
403 | /* bpstat stuff. External routines' interfaces are documented | |
404 | in breakpoint.h. */ | |
405 | void | |
406 | bpstat_clear (bsp) | |
407 | bpstat *bsp; | |
408 | { | |
409 | bpstat p; | |
410 | bpstat q; | |
411 | ||
412 | if (bsp == 0) | |
413 | return; | |
414 | p = *bsp; | |
415 | while (p != NULL) | |
416 | { | |
417 | q = p->next; | |
418 | if (p->old_val != NULL) | |
419 | value_free (p->old_val); | |
420 | free (p); | |
421 | p = q; | |
422 | } | |
423 | *bsp = NULL; | |
424 | } | |
425 | ||
426 | bpstat | |
427 | bpstat_copy (bs) | |
428 | bpstat bs; | |
429 | { | |
430 | bpstat p = NULL; | |
431 | bpstat tmp; | |
432 | bpstat retval; | |
433 | ||
434 | if (bs == NULL) | |
435 | return bs; | |
436 | ||
437 | for (; bs != NULL; bs = bs->next) | |
438 | { | |
439 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
440 | bcopy (bs, tmp, sizeof (*tmp)); | |
441 | if (p == NULL) | |
442 | /* This is the first thing in the chain. */ | |
443 | retval = tmp; | |
444 | else | |
445 | p->next = tmp; | |
446 | p = tmp; | |
447 | } | |
448 | p->next = NULL; | |
449 | return retval; | |
450 | } | |
451 | ||
452 | int | |
453 | bpstat_num (bsp) | |
454 | bpstat *bsp; | |
455 | { | |
456 | struct breakpoint *b; | |
457 | ||
458 | if ((*bsp) == NULL) | |
459 | return 0; /* No more breakpoint values */ | |
460 | else | |
461 | { | |
462 | b = (*bsp)->breakpoint_at; | |
463 | *bsp = (*bsp)->next; | |
464 | if (b == NULL) | |
465 | return -1; /* breakpoint that's been deleted since */ | |
466 | else | |
467 | return b->number; /* We have its number */ | |
468 | } | |
469 | } | |
470 | ||
471 | void | |
472 | bpstat_clear_actions (bs) | |
473 | bpstat bs; | |
474 | { | |
475 | for (; bs != NULL; bs = bs->next) | |
476 | { | |
477 | bs->commands = NULL; | |
478 | if (bs->old_val != NULL) | |
479 | { | |
480 | value_free (bs->old_val); | |
481 | bs->old_val = NULL; | |
482 | } | |
483 | } | |
484 | } | |
485 | ||
486 | /* Execute all the commands associated with all the breakpoints at this | |
487 | location. Any of these commands could cause the process to proceed | |
488 | beyond this point, etc. We look out for such changes by checking | |
489 | the global "breakpoint_proceeded" after each command. */ | |
490 | void | |
491 | bpstat_do_actions (bsp) | |
492 | bpstat *bsp; | |
493 | { | |
494 | bpstat bs; | |
495 | ||
496 | top: | |
497 | bs = *bsp; | |
498 | ||
499 | executing_breakpoint_commands = 1; | |
500 | breakpoint_proceeded = 0; | |
501 | for (; bs != NULL; bs = bs->next) | |
502 | { | |
503 | while (bs->commands) | |
504 | { | |
505 | char *line = bs->commands->line; | |
506 | bs->commands = bs->commands->next; | |
507 | execute_command (line, 0); | |
508 | /* If the inferior is proceeded by the command, bomb out now. | |
509 | The bpstat chain has been blown away by wait_for_inferior. | |
510 | But since execution has stopped again, there is a new bpstat | |
511 | to look at, so start over. */ | |
512 | if (breakpoint_proceeded) | |
513 | goto top; | |
514 | } | |
515 | } | |
516 | clear_momentary_breakpoints (); | |
517 | ||
518 | executing_breakpoint_commands = 0; | |
519 | } | |
520 | ||
521 | int | |
522 | bpstat_print (bs) | |
523 | bpstat bs; | |
524 | { | |
525 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint | |
526 | which has since been deleted. */ | |
527 | if (bs == NULL || bs->breakpoint_at == NULL) | |
528 | return 0; | |
529 | ||
530 | /* If bpstat_stop_status says don't print, OK, we won't. An example | |
531 | circumstance is when we single-stepped for both a watchpoint and | |
532 | for a "stepi" instruction. The bpstat says that the watchpoint | |
533 | explains the stop, but we shouldn't print because the watchpoint's | |
534 | value didn't change -- and the real reason we are stopping here | |
535 | rather than continuing to step (as the watchpoint would've had us do) | |
536 | is because of the "stepi". */ | |
537 | if (!bs->print) | |
538 | return 0; | |
539 | ||
540 | if (bs->breakpoint_at->address != NULL) | |
541 | { | |
542 | /* I think the user probably only wants to see one breakpoint | |
543 | number, not all of them. */ | |
544 | printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number); | |
545 | return 0; | |
546 | } | |
547 | ||
548 | if (bs->old_val != NULL) | |
549 | { | |
550 | printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number); | |
551 | print_expression (bs->breakpoint_at->exp, stdout); | |
552 | printf_filtered ("\nOld value = "); | |
553 | value_print (bs->old_val, stdout, 0, Val_pretty_default); | |
554 | printf_filtered ("\nNew value = "); | |
555 | value_print (bs->breakpoint_at->val, stdout, 0, | |
556 | Val_pretty_default); | |
557 | printf_filtered ("\n"); | |
558 | value_free (bs->old_val); | |
559 | bs->old_val = NULL; | |
560 | return 1; | |
561 | } | |
562 | ||
563 | fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n"); | |
564 | return 0; | |
565 | } | |
566 | ||
567 | /* Evaluate the expression EXP and return 1 if value is zero. | |
568 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
569 | The argument is a "struct expression *" that has been cast to int to | |
570 | make it pass through catch_errors. */ | |
571 | ||
572 | static int | |
573 | breakpoint_cond_eval (exp) | |
574 | int exp; | |
575 | { | |
576 | return value_zerop (evaluate_expression ((struct expression *)exp)); | |
577 | } | |
578 | ||
579 | /* Allocate a new bpstat and chain it to the current one. */ | |
580 | ||
581 | static bpstat | |
582 | bpstat_alloc (b, cbs) | |
583 | register struct breakpoint *b; | |
584 | bpstat cbs; /* Current "bs" value */ | |
585 | { | |
586 | bpstat bs; | |
587 | ||
588 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
589 | cbs->next = bs; | |
590 | bs->breakpoint_at = b; | |
591 | /* If the condition is false, etc., don't do the commands. */ | |
592 | bs->commands = NULL; | |
593 | bs->momentary = b->number == -3; | |
594 | bs->old_val = NULL; | |
595 | return bs; | |
596 | } | |
597 | ||
598 | /* Determine whether we stopped at a breakpoint, etc, or whether we | |
599 | don't understand this stop. Result is a chain of bpstat's such that: | |
600 | ||
601 | if we don't understand the stop, the result is a null pointer. | |
602 | ||
603 | if we understand why we stopped, the result is not null, and | |
604 | the first element of the chain contains summary "stop" and | |
605 | "print" flags for the whole chain. | |
606 | ||
607 | Each element of the chain refers to a particular breakpoint or | |
608 | watchpoint at which we have stopped. (We may have stopped for | |
609 | several reasons.) | |
610 | ||
611 | Each element of the chain has valid next, breakpoint_at, | |
612 | commands, FIXME??? fields. | |
613 | ||
614 | */ | |
615 | ||
616 | ||
617 | bpstat | |
618 | bpstat_stop_status (pc, frame_address) | |
619 | CORE_ADDR *pc; | |
620 | FRAME_ADDR frame_address; | |
621 | { | |
622 | register struct breakpoint *b; | |
623 | int stop = 0; | |
624 | int print = 0; | |
625 | CORE_ADDR bp_addr; | |
626 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ | |
627 | int real_breakpoint = 0; | |
628 | /* Root of the chain of bpstat's */ | |
629 | struct bpstat__struct root_bs[1]; | |
630 | /* Pointer to the last thing in the chain currently. */ | |
631 | bpstat bs = root_bs; | |
632 | ||
633 | /* Get the address where the breakpoint would have been. */ | |
634 | bp_addr = *pc - DECR_PC_AFTER_BREAK; | |
635 | ||
636 | ALL_BREAKPOINTS (b) | |
637 | { | |
638 | int this_bp_stop; | |
639 | int this_bp_print; | |
640 | ||
641 | if (b->enable == disabled) | |
642 | continue; | |
643 | if (b->address != NULL && b->address != bp_addr) | |
644 | continue; | |
645 | ||
646 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ | |
647 | ||
648 | this_bp_stop = 1; | |
649 | this_bp_print = 1; | |
650 | ||
651 | if (b->exp != NULL) /* Watchpoint */ | |
652 | { | |
653 | int within_current_scope; | |
654 | if (b->exp_valid_block != NULL) | |
655 | within_current_scope = | |
656 | contained_in (get_selected_block (), b->exp_valid_block); | |
657 | else | |
658 | within_current_scope = 1; | |
659 | ||
660 | if (within_current_scope) | |
661 | { | |
662 | value new_val = evaluate_expression (b->exp); | |
663 | release_value (new_val); | |
664 | if (!value_equal (b->val, new_val)) | |
665 | { | |
666 | bs->old_val = b->val; | |
667 | b->val = new_val; | |
668 | /* We will stop here */ | |
669 | } | |
670 | else | |
671 | { | |
672 | /* Nothing changed, don't do anything. */ | |
673 | value_free (new_val); | |
674 | continue; | |
675 | /* We won't stop here */ | |
676 | } | |
677 | } | |
678 | else | |
679 | { | |
680 | /* This seems like the only logical thing to do because | |
681 | if we temporarily ignored the watchpoint, then when | |
682 | we reenter the block in which it is valid it contains | |
683 | garbage (in the case of a function, it may have two | |
684 | garbage values, one before and one after the prologue). | |
685 | So we can't even detect the first assignment to it and | |
686 | watch after that (since the garbage may or may not equal | |
687 | the first value assigned). */ | |
688 | b->enable = disabled; | |
689 | printf_filtered ("\ | |
690 | Watchpoint %d disabled because the program has left the block in\n\ | |
691 | which its expression is valid.\n", b->number); | |
692 | /* We won't stop here */ | |
693 | /* FIXME, maybe we should stop here!!! */ | |
694 | continue; | |
695 | } | |
696 | } | |
697 | else | |
698 | real_breakpoint = 1; | |
699 | ||
700 | if (b->frame && b->frame != frame_address) | |
701 | this_bp_stop = 0; | |
702 | else | |
703 | { | |
704 | int value_zero; | |
705 | ||
706 | if (b->cond) | |
707 | { | |
708 | /* Need to select the frame, with all that implies | |
709 | so that the conditions will have the right context. */ | |
710 | select_frame (get_current_frame (), 0); | |
711 | value_zero | |
712 | = catch_errors (breakpoint_cond_eval, (int)(b->cond), | |
713 | "Error occurred in testing breakpoint condition."); | |
714 | free_all_values (); | |
715 | } | |
716 | if (b->cond && value_zero) | |
717 | { | |
718 | this_bp_stop = 0; | |
719 | } | |
720 | else if (b->ignore_count > 0) | |
721 | { | |
722 | b->ignore_count--; | |
723 | this_bp_stop = 0; | |
724 | } | |
725 | else | |
726 | { | |
727 | /* We will stop here */ | |
728 | if (b->enable == temporary) | |
729 | b->enable = disabled; | |
730 | bs->commands = b->commands; | |
731 | if (b->silent) | |
732 | this_bp_print = 0; | |
733 | if (bs->commands && !strcmp ("silent", bs->commands->line)) | |
734 | { | |
735 | bs->commands = bs->commands->next; | |
736 | this_bp_print = 0; | |
737 | } | |
738 | } | |
739 | } | |
740 | if (this_bp_stop) | |
741 | stop = 1; | |
742 | if (this_bp_print) | |
743 | print = 1; | |
744 | } | |
745 | ||
746 | bs->next = NULL; /* Terminate the chain */ | |
747 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
748 | if (bs) | |
749 | { | |
750 | bs->stop = stop; | |
751 | bs->print = print; | |
752 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) | |
753 | if (real_breakpoint) | |
754 | { | |
755 | *pc = bp_addr; | |
756 | #if defined (SHIFT_INST_REGS) | |
757 | { | |
758 | CORE_ADDR pc = read_register (PC_REGNUM); | |
759 | CORE_ADDR npc = read_register (NPC_REGNUM); | |
760 | if (pc != npc) | |
761 | { | |
762 | write_register (NNPC_REGNUM, npc); | |
763 | write_register (NPC_REGNUM, pc); | |
764 | } | |
765 | } | |
766 | #else /* No SHIFT_INST_REGS. */ | |
767 | write_pc (bp_addr); | |
768 | #endif /* No SHIFT_INST_REGS. */ | |
769 | } | |
770 | #endif /* DECR_PC_AFTER_BREAK != 0. */ | |
771 | } | |
772 | return bs; | |
773 | } | |
774 | ||
775 | int | |
776 | bpstat_should_step () | |
777 | { | |
778 | struct breakpoint *b; | |
779 | ALL_BREAKPOINTS (b) | |
780 | if (b->enable != disabled && b->exp != NULL) | |
781 | return 1; | |
782 | return 0; | |
783 | } | |
784 | \f | |
785 | /* Print information on breakpoint number BNUM, or -1 if all. | |
786 | If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS | |
787 | is nonzero, process only watchpoints. */ | |
788 | ||
789 | static void | |
790 | breakpoint_1 (bnum, watchpoints) | |
791 | int bnum; | |
792 | int watchpoints; | |
793 | { | |
794 | register struct breakpoint *b; | |
795 | register struct command_line *l; | |
796 | register struct symbol *sym; | |
797 | CORE_ADDR last_addr = (CORE_ADDR)-1; | |
798 | int header_printed = 0; | |
799 | ||
800 | ALL_BREAKPOINTS (b) | |
801 | if (bnum == -1 || bnum == b->number) | |
802 | { | |
803 | if (b->address == NULL && !watchpoints) | |
804 | { | |
805 | if (bnum == -1) | |
806 | continue; | |
807 | error ("That is a watchpoint, not a breakpoint."); | |
808 | } | |
809 | if (b->address != NULL && watchpoints) | |
810 | { | |
811 | if (bnum == -1) | |
812 | continue; | |
813 | error ("That is a breakpoint, not a watchpoint."); | |
814 | } | |
815 | ||
816 | if (!header_printed) | |
817 | { | |
818 | if (watchpoints) | |
819 | printf_filtered (" Enb Expression\n"); | |
820 | else if (addressprint) | |
821 | printf_filtered (" Enb Address Where\n"); | |
822 | else | |
823 | printf_filtered (" Enb Where\n"); | |
824 | header_printed = 1; | |
825 | } | |
826 | ||
827 | printf_filtered ("#%-3d %c ", b->number, "nyod"[(int) b->enable]); | |
828 | if (b->address == NULL) | |
829 | print_expression (b->exp, stdout); | |
830 | else | |
831 | { | |
832 | if (addressprint) | |
833 | printf_filtered (" 0x%08x ", b->address); | |
834 | ||
835 | last_addr = b->address; | |
836 | if (b->symtab) | |
837 | { | |
838 | sym = find_pc_function (b->address); | |
839 | if (sym) | |
840 | { | |
841 | fputs_filtered (" in ", stdout); | |
842 | fputs_demangled (SYMBOL_NAME (sym), stdout, 1); | |
843 | fputs_filtered (" at ", stdout); | |
844 | } | |
845 | fputs_filtered (b->symtab->filename, stdout); | |
846 | printf_filtered (":%d", b->line_number); | |
847 | } | |
848 | else | |
849 | print_address_symbolic (b->address, stdout, demangle); | |
850 | } | |
851 | ||
852 | printf_filtered ("\n"); | |
853 | ||
854 | if (b->frame) | |
855 | printf_filtered ("\tstop only in stack frame at 0x%x\n", b->frame); | |
856 | if (b->cond) | |
857 | { | |
858 | printf_filtered ("\tstop only if "); | |
859 | print_expression (b->cond, stdout); | |
860 | printf_filtered ("\n"); | |
861 | } | |
862 | if (b->ignore_count) | |
863 | printf_filtered ("\tignore next %d hits\n", b->ignore_count); | |
864 | if ((l = b->commands)) | |
865 | while (l) | |
866 | { | |
867 | fputs_filtered ("\t", stdout); | |
868 | fputs_filtered (l->line, stdout); | |
869 | fputs_filtered ("\n", stdout); | |
870 | l = l->next; | |
871 | } | |
872 | } | |
873 | ||
874 | if (!header_printed) | |
875 | { | |
876 | char *which = watchpoints ? "watch" : "break"; | |
877 | if (bnum == -1) | |
878 | printf_filtered ("No %spoints.\n", which); | |
879 | else | |
880 | printf_filtered ("No %spoint numbered %d.\n", which, bnum); | |
881 | } | |
882 | ||
883 | /* Compare against (CORE_ADDR)-1 in case some compiler decides | |
884 | that a comparison of an unsigned with -1 is always false. */ | |
885 | if (last_addr != (CORE_ADDR)-1) | |
886 | set_next_address (last_addr); | |
887 | } | |
888 | ||
889 | static void | |
890 | breakpoints_info (bnum_exp, from_tty) | |
891 | char *bnum_exp; | |
892 | int from_tty; | |
893 | { | |
894 | int bnum = -1; | |
895 | ||
896 | if (bnum_exp) | |
897 | bnum = parse_and_eval_address (bnum_exp); | |
898 | ||
899 | breakpoint_1 (bnum, 0); | |
900 | } | |
901 | ||
902 | static void | |
903 | watchpoints_info (bnum_exp, from_tty) | |
904 | char *bnum_exp; | |
905 | int from_tty; | |
906 | { | |
907 | int bnum = -1; | |
908 | ||
909 | if (bnum_exp) | |
910 | bnum = parse_and_eval_address (bnum_exp); | |
911 | ||
912 | breakpoint_1 (bnum, 1); | |
913 | } | |
914 | ||
915 | /* Print a message describing any breakpoints set at PC. */ | |
916 | ||
917 | static void | |
918 | describe_other_breakpoints (pc) | |
919 | register CORE_ADDR pc; | |
920 | { | |
921 | register int others = 0; | |
922 | register struct breakpoint *b; | |
923 | ||
924 | ALL_BREAKPOINTS (b) | |
925 | if (b->address == pc) | |
926 | others++; | |
927 | if (others > 0) | |
928 | { | |
929 | printf ("Note: breakpoint%s ", (others > 1) ? "s" : ""); | |
930 | ALL_BREAKPOINTS (b) | |
931 | if (b->address == pc) | |
932 | { | |
933 | others--; | |
934 | printf ("%d%s%s ", | |
935 | b->number, | |
936 | (b->enable == disabled) ? " (disabled)" : "", | |
937 | (others > 1) ? "," : ((others == 1) ? " and" : "")); | |
938 | } | |
939 | printf ("also set at pc 0x%x.\n", pc); | |
940 | } | |
941 | } | |
942 | \f | |
943 | /* Set the default place to put a breakpoint | |
944 | for the `break' command with no arguments. */ | |
945 | ||
946 | void | |
947 | set_default_breakpoint (valid, addr, symtab, line) | |
948 | int valid; | |
949 | CORE_ADDR addr; | |
950 | struct symtab *symtab; | |
951 | int line; | |
952 | { | |
953 | default_breakpoint_valid = valid; | |
954 | default_breakpoint_address = addr; | |
955 | default_breakpoint_symtab = symtab; | |
956 | default_breakpoint_line = line; | |
957 | } | |
958 | ||
959 | /* Rescan breakpoints at address ADDRESS, | |
960 | marking the first one as "first" and any others as "duplicates". | |
961 | This is so that the bpt instruction is only inserted once. */ | |
962 | ||
963 | static void | |
964 | check_duplicates (address) | |
965 | CORE_ADDR address; | |
966 | { | |
967 | register struct breakpoint *b; | |
968 | register int count = 0; | |
969 | ||
970 | ALL_BREAKPOINTS (b) | |
971 | if (b->enable != disabled && b->address == address) | |
972 | { | |
973 | count++; | |
974 | b->duplicate = count > 1; | |
975 | } | |
976 | } | |
977 | ||
978 | /* Low level routine to set a breakpoint. | |
979 | Takes as args the three things that every breakpoint must have. | |
980 | Returns the breakpoint object so caller can set other things. | |
981 | Does not set the breakpoint number! | |
982 | Does not print anything. */ | |
983 | ||
984 | static struct breakpoint * | |
985 | set_raw_breakpoint (sal) | |
986 | struct symtab_and_line sal; | |
987 | { | |
988 | register struct breakpoint *b, *b1; | |
989 | ||
990 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
991 | bzero (b, sizeof *b); | |
992 | b->address = sal.pc; | |
993 | b->symtab = sal.symtab; | |
994 | b->line_number = sal.line; | |
995 | b->enable = enabled; | |
996 | b->next = 0; | |
997 | b->silent = 0; | |
998 | b->ignore_count = 0; | |
999 | b->commands = NULL; | |
1000 | b->frame = NULL; | |
1001 | ||
1002 | /* Add this breakpoint to the end of the chain | |
1003 | so that a list of breakpoints will come out in order | |
1004 | of increasing numbers. */ | |
1005 | ||
1006 | b1 = breakpoint_chain; | |
1007 | if (b1 == 0) | |
1008 | breakpoint_chain = b; | |
1009 | else | |
1010 | { | |
1011 | while (b1->next) | |
1012 | b1 = b1->next; | |
1013 | b1->next = b; | |
1014 | } | |
1015 | ||
1016 | check_duplicates (sal.pc); | |
1017 | ||
1018 | return b; | |
1019 | } | |
1020 | ||
1021 | /* Set a breakpoint that will evaporate an end of command | |
1022 | at address specified by SAL. | |
1023 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
1024 | ||
1025 | void | |
1026 | set_momentary_breakpoint (sal, frame) | |
1027 | struct symtab_and_line sal; | |
1028 | FRAME frame; | |
1029 | { | |
1030 | register struct breakpoint *b; | |
1031 | b = set_raw_breakpoint (sal); | |
1032 | b->number = -3; | |
1033 | b->enable = delete; | |
1034 | b->frame = (frame ? FRAME_FP (frame) : 0); | |
1035 | } | |
1036 | ||
1037 | void | |
1038 | clear_momentary_breakpoints () | |
1039 | { | |
1040 | register struct breakpoint *b; | |
1041 | ALL_BREAKPOINTS (b) | |
1042 | if (b->number == -3) | |
1043 | { | |
1044 | delete_breakpoint (b); | |
1045 | break; | |
1046 | } | |
1047 | } | |
1048 | \f | |
1049 | /* Tell the user we have just set a breakpoint B. */ | |
1050 | static void | |
1051 | mention (b) | |
1052 | struct breakpoint *b; | |
1053 | { | |
1054 | if (b->exp) | |
1055 | { | |
1056 | printf_filtered ("Watchpoint %d: ", b->number); | |
1057 | print_expression (b->exp, stdout); | |
1058 | } | |
1059 | else | |
1060 | { | |
1061 | printf_filtered ("Breakpoint %d at 0x%x", b->number, b->address); | |
1062 | if (b->symtab) | |
1063 | printf_filtered (": file %s, line %d.", | |
1064 | b->symtab->filename, b->line_number); | |
1065 | } | |
1066 | printf_filtered ("\n"); | |
1067 | } | |
1068 | ||
1069 | #if 0 | |
1070 | /* Nobody calls this currently. */ | |
1071 | /* Set a breakpoint from a symtab and line. | |
1072 | If TEMPFLAG is nonzero, it is a temporary breakpoint. | |
1073 | ADDR_STRING is a malloc'd string holding the name of where we are | |
1074 | setting the breakpoint. This is used later to re-set it after the | |
1075 | program is relinked and symbols are reloaded. | |
1076 | Print the same confirmation messages that the breakpoint command prints. */ | |
1077 | ||
1078 | void | |
1079 | set_breakpoint (s, line, tempflag, addr_string) | |
1080 | struct symtab *s; | |
1081 | int line; | |
1082 | int tempflag; | |
1083 | char *addr_string; | |
1084 | { | |
1085 | register struct breakpoint *b; | |
1086 | struct symtab_and_line sal; | |
1087 | ||
1088 | sal.symtab = s; | |
1089 | sal.line = line; | |
1090 | sal.pc = find_line_pc (sal.symtab, sal.line); | |
1091 | if (sal.pc == 0) | |
1092 | error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename); | |
1093 | else | |
1094 | { | |
1095 | describe_other_breakpoints (sal.pc); | |
1096 | ||
1097 | b = set_raw_breakpoint (sal); | |
1098 | set_breakpoint_count (breakpoint_count + 1); | |
1099 | b->number = breakpoint_count; | |
1100 | b->cond = 0; | |
1101 | b->addr_string = addr_string; | |
1102 | if (tempflag) | |
1103 | b->enable = temporary; | |
1104 | ||
1105 | mention (b); | |
1106 | } | |
1107 | } | |
1108 | #endif | |
1109 | \f | |
1110 | /* Set a breakpoint according to ARG (function, linenum or *address) | |
1111 | and make it temporary if TEMPFLAG is nonzero. */ | |
1112 | ||
1113 | static void | |
1114 | break_command_1 (arg, tempflag, from_tty) | |
1115 | char *arg; | |
1116 | int tempflag, from_tty; | |
1117 | { | |
1118 | struct symtabs_and_lines sals; | |
1119 | struct symtab_and_line sal; | |
1120 | register struct expression *cond = 0; | |
1121 | register struct breakpoint *b; | |
1122 | ||
1123 | /* Pointers in arg to the start, and one past the end, of the condition. */ | |
1124 | char *cond_start = NULL; | |
1125 | char *cond_end; | |
1126 | /* Pointers in arg to the start, and one past the end, | |
1127 | of the address part. */ | |
1128 | char *addr_start = NULL; | |
1129 | char *addr_end; | |
1130 | ||
1131 | int i; | |
1132 | CORE_ADDR pc; | |
1133 | ||
1134 | sals.sals = NULL; | |
1135 | sals.nelts = 0; | |
1136 | ||
1137 | sal.line = sal.pc = sal.end = 0; | |
1138 | sal.symtab = 0; | |
1139 | ||
1140 | /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ | |
1141 | ||
1142 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' | |
1143 | && (arg[2] == ' ' || arg[2] == '\t'))) | |
1144 | { | |
1145 | if (default_breakpoint_valid) | |
1146 | { | |
1147 | sals.sals = (struct symtab_and_line *) | |
1148 | xmalloc (sizeof (struct symtab_and_line)); | |
1149 | sal.pc = default_breakpoint_address; | |
1150 | sal.line = default_breakpoint_line; | |
1151 | sal.symtab = default_breakpoint_symtab; | |
1152 | sals.sals[0] = sal; | |
1153 | sals.nelts = 1; | |
1154 | } | |
1155 | else | |
1156 | error ("No default breakpoint address now."); | |
1157 | } | |
1158 | else | |
1159 | { | |
1160 | addr_start = arg; | |
1161 | ||
1162 | /* Force almost all breakpoints to be in terms of the | |
1163 | current_source_symtab (which is decode_line_1's default). This | |
1164 | should produce the results we want almost all of the time while | |
1165 | leaving default_breakpoint_* alone. */ | |
1166 | if (default_breakpoint_valid | |
1167 | && (!current_source_symtab | |
1168 | || (arg && (*arg == '+' || *arg == '-')))) | |
1169 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
1170 | default_breakpoint_line); | |
1171 | else | |
1172 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0); | |
1173 | ||
1174 | addr_end = arg; | |
1175 | } | |
1176 | ||
1177 | if (! sals.nelts) | |
1178 | return; | |
1179 | ||
1180 | for (i = 0; i < sals.nelts; i++) | |
1181 | { | |
1182 | sal = sals.sals[i]; | |
1183 | if (sal.pc == 0 && sal.symtab != 0) | |
1184 | { | |
1185 | pc = find_line_pc (sal.symtab, sal.line); | |
1186 | if (pc == 0) | |
1187 | error ("No line %d in file \"%s\".", | |
1188 | sal.line, sal.symtab->filename); | |
1189 | } | |
1190 | else | |
1191 | pc = sal.pc; | |
1192 | ||
1193 | while (arg && *arg) | |
1194 | { | |
1195 | if (arg[0] == 'i' && arg[1] == 'f' | |
1196 | && (arg[2] == ' ' || arg[2] == '\t')) | |
1197 | { | |
1198 | arg += 2; | |
1199 | cond_start = arg; | |
1200 | cond = parse_c_1 (&arg, block_for_pc (pc), 0); | |
1201 | cond_end = arg; | |
1202 | } | |
1203 | else | |
1204 | error ("Junk at end of arguments."); | |
1205 | } | |
1206 | sals.sals[i].pc = pc; | |
1207 | } | |
1208 | ||
1209 | for (i = 0; i < sals.nelts; i++) | |
1210 | { | |
1211 | sal = sals.sals[i]; | |
1212 | ||
1213 | if (from_tty) | |
1214 | describe_other_breakpoints (sal.pc); | |
1215 | ||
1216 | b = set_raw_breakpoint (sal); | |
1217 | set_breakpoint_count (breakpoint_count + 1); | |
1218 | b->number = breakpoint_count; | |
1219 | b->cond = cond; | |
1220 | ||
1221 | if (addr_start) | |
1222 | b->addr_string = savestring (addr_start, addr_end - addr_start); | |
1223 | if (cond_start) | |
1224 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
1225 | ||
1226 | if (tempflag) | |
1227 | b->enable = temporary; | |
1228 | ||
1229 | mention (b); | |
1230 | } | |
1231 | ||
1232 | if (sals.nelts > 1) | |
1233 | { | |
1234 | printf ("Multiple breakpoints were set.\n"); | |
1235 | printf ("Use the \"delete\" command to delete unwanted breakpoints.\n"); | |
1236 | } | |
1237 | free (sals.sals); | |
1238 | } | |
1239 | ||
1240 | void | |
1241 | break_command (arg, from_tty) | |
1242 | char *arg; | |
1243 | int from_tty; | |
1244 | { | |
1245 | break_command_1 (arg, 0, from_tty); | |
1246 | } | |
1247 | ||
1248 | static void | |
1249 | tbreak_command (arg, from_tty) | |
1250 | char *arg; | |
1251 | int from_tty; | |
1252 | { | |
1253 | break_command_1 (arg, 1, from_tty); | |
1254 | } | |
1255 | ||
1256 | static void | |
1257 | watch_command (arg, from_tty) | |
1258 | char *arg; | |
1259 | int from_tty; | |
1260 | { | |
1261 | struct breakpoint *b; | |
1262 | struct symtab_and_line sal; | |
1263 | ||
1264 | sal.pc = NULL; | |
1265 | sal.symtab = NULL; | |
1266 | sal.line = 0; | |
1267 | ||
1268 | b = set_raw_breakpoint (sal); | |
1269 | set_breakpoint_count (breakpoint_count + 1); | |
1270 | b->number = breakpoint_count; | |
1271 | innermost_block = NULL; | |
1272 | b->exp = parse_c_expression (arg); | |
1273 | b->exp_valid_block = innermost_block; | |
1274 | b->val = evaluate_expression (b->exp); | |
1275 | release_value (b->val); | |
1276 | b->cond = 0; | |
1277 | b->cond_string = NULL; | |
1278 | mention (b); | |
1279 | } | |
1280 | \f | |
1281 | /* | |
1282 | * Helper routine for the until_command routine in infcmd.c. Here | |
1283 | * because it uses the mechanisms of breakpoints. | |
1284 | */ | |
1285 | void | |
1286 | until_break_command (arg, from_tty) | |
1287 | char *arg; | |
1288 | int from_tty; | |
1289 | { | |
1290 | struct symtabs_and_lines sals; | |
1291 | struct symtab_and_line sal; | |
1292 | FRAME prev_frame = get_prev_frame (selected_frame); | |
1293 | ||
1294 | clear_proceed_status (); | |
1295 | ||
1296 | /* Set a breakpoint where the user wants it and at return from | |
1297 | this function */ | |
1298 | ||
1299 | if (default_breakpoint_valid) | |
1300 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
1301 | default_breakpoint_line); | |
1302 | else | |
1303 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0); | |
1304 | ||
1305 | if (sals.nelts != 1) | |
1306 | error ("Couldn't get information on specified line."); | |
1307 | ||
1308 | sal = sals.sals[0]; | |
1309 | free (sals.sals); /* malloc'd, so freed */ | |
1310 | ||
1311 | if (*arg) | |
1312 | error ("Junk at end of arguments."); | |
1313 | ||
1314 | if (sal.pc == 0 && sal.symtab != 0) | |
1315 | sal.pc = find_line_pc (sal.symtab, sal.line); | |
1316 | ||
1317 | if (sal.pc == 0) | |
1318 | error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename); | |
1319 | ||
1320 | set_momentary_breakpoint (sal, selected_frame); | |
1321 | ||
1322 | /* Keep within the current frame */ | |
1323 | ||
1324 | if (prev_frame) | |
1325 | { | |
1326 | struct frame_info *fi; | |
1327 | ||
1328 | fi = get_frame_info (prev_frame); | |
1329 | sal = find_pc_line (fi->pc, 0); | |
1330 | sal.pc = fi->pc; | |
1331 | set_momentary_breakpoint (sal, prev_frame); | |
1332 | } | |
1333 | ||
1334 | proceed (-1, -1, 0); | |
1335 | } | |
1336 | \f | |
1337 | /* Set a breakpoint at the catch clause for NAME. */ | |
1338 | static int | |
1339 | catch_breakpoint (name) | |
1340 | char *name; | |
1341 | { | |
1342 | } | |
1343 | ||
1344 | static int | |
1345 | disable_catch_breakpoint () | |
1346 | { | |
1347 | } | |
1348 | ||
1349 | static int | |
1350 | delete_catch_breakpoint () | |
1351 | { | |
1352 | } | |
1353 | ||
1354 | static int | |
1355 | enable_catch_breakpoint () | |
1356 | { | |
1357 | } | |
1358 | ||
1359 | struct sal_chain | |
1360 | { | |
1361 | struct sal_chain *next; | |
1362 | struct symtab_and_line sal; | |
1363 | }; | |
1364 | ||
1365 | /* For each catch clause identified in ARGS, run FUNCTION | |
1366 | with that clause as an argument. */ | |
1367 | static struct symtabs_and_lines | |
1368 | map_catch_names (args, function) | |
1369 | char *args; | |
1370 | int (*function)(); | |
1371 | { | |
1372 | register char *p = args; | |
1373 | register char *p1; | |
1374 | struct symtabs_and_lines sals; | |
1375 | struct sal_chain *sal_chain = 0; | |
1376 | ||
1377 | if (p == 0) | |
1378 | error_no_arg ("one or more catch names"); | |
1379 | ||
1380 | sals.nelts = 0; | |
1381 | sals.sals = NULL; | |
1382 | ||
1383 | while (*p) | |
1384 | { | |
1385 | p1 = p; | |
1386 | /* Don't swallow conditional part. */ | |
1387 | if (p1[0] == 'i' && p1[1] == 'f' | |
1388 | && (p1[2] == ' ' || p1[2] == '\t')) | |
1389 | break; | |
1390 | ||
1391 | if (isalpha (*p1)) | |
1392 | { | |
1393 | p1++; | |
1394 | while (isalnum (*p1) || *p1 == '_' || *p1 == '$') | |
1395 | p1++; | |
1396 | } | |
1397 | ||
1398 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
1399 | error ("Arguments must be catch names."); | |
1400 | ||
1401 | *p1 = 0; | |
1402 | #if 0 | |
1403 | if (function (p)) | |
1404 | { | |
1405 | struct sal_chain *next | |
1406 | = (struct sal_chain *)alloca (sizeof (struct sal_chain)); | |
1407 | next->next = sal_chain; | |
1408 | next->sal = get_catch_sal (p); | |
1409 | sal_chain = next; | |
1410 | goto win; | |
1411 | } | |
1412 | #endif | |
1413 | printf ("No catch clause for exception %s.\n", p); | |
1414 | win: | |
1415 | p = p1; | |
1416 | while (*p == ' ' || *p == '\t') p++; | |
1417 | } | |
1418 | } | |
1419 | ||
1420 | /* This shares a lot of code with `print_frame_label_vars' from stack.c. */ | |
1421 | ||
1422 | static struct symtabs_and_lines | |
1423 | get_catch_sals (this_level_only) | |
1424 | int this_level_only; | |
1425 | { | |
1426 | extern struct blockvector *blockvector_for_pc (); | |
1427 | register struct blockvector *bl; | |
1428 | register struct block *block = get_frame_block (selected_frame); | |
1429 | int index, have_default = 0; | |
1430 | struct frame_info *fi = get_frame_info (selected_frame); | |
1431 | CORE_ADDR pc = fi->pc; | |
1432 | struct symtabs_and_lines sals; | |
1433 | struct sal_chain *sal_chain = 0; | |
1434 | char *blocks_searched; | |
1435 | ||
1436 | sals.nelts = 0; | |
1437 | sals.sals = NULL; | |
1438 | ||
1439 | if (block == 0) | |
1440 | error ("No symbol table info available.\n"); | |
1441 | ||
1442 | bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); | |
1443 | blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); | |
1444 | bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); | |
1445 | ||
1446 | while (block != 0) | |
1447 | { | |
1448 | CORE_ADDR end = BLOCK_END (block) - 4; | |
1449 | int last_index; | |
1450 | ||
1451 | if (bl != blockvector_for_pc (end, &index)) | |
1452 | error ("blockvector blotch"); | |
1453 | if (BLOCKVECTOR_BLOCK (bl, index) != block) | |
1454 | error ("blockvector botch"); | |
1455 | last_index = BLOCKVECTOR_NBLOCKS (bl); | |
1456 | index += 1; | |
1457 | ||
1458 | /* Don't print out blocks that have gone by. */ | |
1459 | while (index < last_index | |
1460 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) | |
1461 | index++; | |
1462 | ||
1463 | while (index < last_index | |
1464 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) | |
1465 | { | |
1466 | if (blocks_searched[index] == 0) | |
1467 | { | |
1468 | struct block *b = BLOCKVECTOR_BLOCK (bl, index); | |
1469 | int nsyms; | |
1470 | register int i; | |
1471 | register struct symbol *sym; | |
1472 | ||
1473 | nsyms = BLOCK_NSYMS (b); | |
1474 | ||
1475 | for (i = 0; i < nsyms; i++) | |
1476 | { | |
1477 | sym = BLOCK_SYM (b, i); | |
1478 | if (! strcmp (SYMBOL_NAME (sym), "default")) | |
1479 | { | |
1480 | if (have_default) | |
1481 | continue; | |
1482 | have_default = 1; | |
1483 | } | |
1484 | if (SYMBOL_CLASS (sym) == LOC_LABEL) | |
1485 | { | |
1486 | struct sal_chain *next = (struct sal_chain *) | |
1487 | alloca (sizeof (struct sal_chain)); | |
1488 | next->next = sal_chain; | |
1489 | next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); | |
1490 | sal_chain = next; | |
1491 | } | |
1492 | } | |
1493 | blocks_searched[index] = 1; | |
1494 | } | |
1495 | index++; | |
1496 | } | |
1497 | if (have_default) | |
1498 | break; | |
1499 | if (sal_chain && this_level_only) | |
1500 | break; | |
1501 | ||
1502 | /* After handling the function's top-level block, stop. | |
1503 | Don't continue to its superblock, the block of | |
1504 | per-file symbols. */ | |
1505 | if (BLOCK_FUNCTION (block)) | |
1506 | break; | |
1507 | block = BLOCK_SUPERBLOCK (block); | |
1508 | } | |
1509 | ||
1510 | if (sal_chain) | |
1511 | { | |
1512 | struct sal_chain *tmp_chain; | |
1513 | ||
1514 | /* Count the number of entries. */ | |
1515 | for (index = 0, tmp_chain = sal_chain; tmp_chain; | |
1516 | tmp_chain = tmp_chain->next) | |
1517 | index++; | |
1518 | ||
1519 | sals.nelts = index; | |
1520 | sals.sals = (struct symtab_and_line *) | |
1521 | xmalloc (index * sizeof (struct symtab_and_line)); | |
1522 | for (index = 0; sal_chain; sal_chain = sal_chain->next, index++) | |
1523 | sals.sals[index] = sal_chain->sal; | |
1524 | } | |
1525 | ||
1526 | return sals; | |
1527 | } | |
1528 | ||
1529 | /* Commands to deal with catching exceptions. */ | |
1530 | ||
1531 | void | |
1532 | catch_command_1 (arg, tempflag, from_tty) | |
1533 | char *arg; | |
1534 | int tempflag; | |
1535 | int from_tty; | |
1536 | { | |
1537 | /* First, translate ARG into something we can deal with in terms | |
1538 | of breakpoints. */ | |
1539 | ||
1540 | struct symtabs_and_lines sals; | |
1541 | struct symtab_and_line sal; | |
1542 | register struct expression *cond = 0; | |
1543 | register struct breakpoint *b; | |
1544 | char *save_arg; | |
1545 | int i; | |
1546 | CORE_ADDR pc; | |
1547 | ||
1548 | sal.line = sal.pc = sal.end = 0; | |
1549 | sal.symtab = 0; | |
1550 | ||
1551 | /* If no arg given, or if first arg is 'if ', all active catch clauses | |
1552 | are breakpointed. */ | |
1553 | ||
1554 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' | |
1555 | && (arg[2] == ' ' || arg[2] == '\t'))) | |
1556 | { | |
1557 | /* Grab all active catch clauses. */ | |
1558 | sals = get_catch_sals (0); | |
1559 | } | |
1560 | else | |
1561 | { | |
1562 | /* Grab selected catch clauses. */ | |
1563 | error ("catch NAME not implemeneted"); | |
1564 | sals = map_catch_names (arg, catch_breakpoint); | |
1565 | } | |
1566 | ||
1567 | if (! sals.nelts) | |
1568 | return; | |
1569 | ||
1570 | save_arg = arg; | |
1571 | for (i = 0; i < sals.nelts; i++) | |
1572 | { | |
1573 | sal = sals.sals[i]; | |
1574 | if (sal.pc == 0 && sal.symtab != 0) | |
1575 | { | |
1576 | pc = find_line_pc (sal.symtab, sal.line); | |
1577 | if (pc == 0) | |
1578 | error ("No line %d in file \"%s\".", | |
1579 | sal.line, sal.symtab->filename); | |
1580 | } | |
1581 | else | |
1582 | pc = sal.pc; | |
1583 | ||
1584 | while (arg && *arg) | |
1585 | { | |
1586 | if (arg[0] == 'i' && arg[1] == 'f' | |
1587 | && (arg[2] == ' ' || arg[2] == '\t')) | |
1588 | cond = (struct expression *) parse_c_1 ((arg += 2, &arg), | |
1589 | block_for_pc (pc), 0); | |
1590 | else | |
1591 | error ("Junk at end of arguments."); | |
1592 | } | |
1593 | arg = save_arg; | |
1594 | sals.sals[i].pc = pc; | |
1595 | } | |
1596 | ||
1597 | for (i = 0; i < sals.nelts; i++) | |
1598 | { | |
1599 | sal = sals.sals[i]; | |
1600 | ||
1601 | if (from_tty) | |
1602 | describe_other_breakpoints (sal.pc); | |
1603 | ||
1604 | b = set_raw_breakpoint (sal); | |
1605 | b->number = ++breakpoint_count; | |
1606 | b->cond = cond; | |
1607 | if (tempflag) | |
1608 | b->enable = temporary; | |
1609 | ||
1610 | printf ("Breakpoint %d at 0x%x", b->number, b->address); | |
1611 | if (b->symtab) | |
1612 | printf (": file %s, line %d.", b->symtab->filename, b->line_number); | |
1613 | printf ("\n"); | |
1614 | } | |
1615 | ||
1616 | if (sals.nelts > 1) | |
1617 | { | |
1618 | printf ("Multiple breakpoints were set.\n"); | |
1619 | printf ("Use the \"delete\" command to delete unwanted breakpoints.\n"); | |
1620 | } | |
1621 | free (sals.sals); | |
1622 | } | |
1623 | ||
1624 | /* Disable breakpoints on all catch clauses described in ARGS. */ | |
1625 | static void | |
1626 | disable_catch (args) | |
1627 | char *args; | |
1628 | { | |
1629 | /* Map the disable command to catch clauses described in ARGS. */ | |
1630 | } | |
1631 | ||
1632 | /* Enable breakpoints on all catch clauses described in ARGS. */ | |
1633 | static void | |
1634 | enable_catch (args) | |
1635 | char *args; | |
1636 | { | |
1637 | /* Map the disable command to catch clauses described in ARGS. */ | |
1638 | } | |
1639 | ||
1640 | /* Delete breakpoints on all catch clauses in the active scope. */ | |
1641 | static void | |
1642 | delete_catch (args) | |
1643 | char *args; | |
1644 | { | |
1645 | /* Map the delete command to catch clauses described in ARGS. */ | |
1646 | } | |
1647 | ||
1648 | static void | |
1649 | catch_command (arg, from_tty) | |
1650 | char *arg; | |
1651 | int from_tty; | |
1652 | { | |
1653 | catch_command_1 (arg, 0, from_tty); | |
1654 | } | |
1655 | \f | |
1656 | static void | |
1657 | clear_command (arg, from_tty) | |
1658 | char *arg; | |
1659 | int from_tty; | |
1660 | { | |
1661 | register struct breakpoint *b, *b1; | |
1662 | struct symtabs_and_lines sals; | |
1663 | struct symtab_and_line sal; | |
1664 | register struct breakpoint *found; | |
1665 | int i; | |
1666 | ||
1667 | if (arg) | |
1668 | { | |
1669 | sals = decode_line_spec (arg, 1); | |
1670 | } | |
1671 | else | |
1672 | { | |
1673 | sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); | |
1674 | sal.line = default_breakpoint_line; | |
1675 | sal.symtab = default_breakpoint_symtab; | |
1676 | sal.pc = 0; | |
1677 | if (sal.symtab == 0) | |
1678 | error ("No source file specified."); | |
1679 | ||
1680 | sals.sals[0] = sal; | |
1681 | sals.nelts = 1; | |
1682 | } | |
1683 | ||
1684 | for (i = 0; i < sals.nelts; i++) | |
1685 | { | |
1686 | /* If exact pc given, clear bpts at that pc. | |
1687 | But if sal.pc is zero, clear all bpts on specified line. */ | |
1688 | sal = sals.sals[i]; | |
1689 | found = (struct breakpoint *) 0; | |
1690 | while (breakpoint_chain | |
1691 | && (sal.pc ? breakpoint_chain->address == sal.pc | |
1692 | : (breakpoint_chain->symtab == sal.symtab | |
1693 | && breakpoint_chain->line_number == sal.line))) | |
1694 | { | |
1695 | b1 = breakpoint_chain; | |
1696 | breakpoint_chain = b1->next; | |
1697 | b1->next = found; | |
1698 | found = b1; | |
1699 | } | |
1700 | ||
1701 | ALL_BREAKPOINTS (b) | |
1702 | while (b->next | |
1703 | && b->next->address != NULL | |
1704 | && (sal.pc ? b->next->address == sal.pc | |
1705 | : (b->next->symtab == sal.symtab | |
1706 | && b->next->line_number == sal.line))) | |
1707 | { | |
1708 | b1 = b->next; | |
1709 | b->next = b1->next; | |
1710 | b1->next = found; | |
1711 | found = b1; | |
1712 | } | |
1713 | ||
1714 | if (found == 0) | |
1715 | { | |
1716 | if (arg) | |
1717 | error ("No breakpoint at %s.", arg); | |
1718 | else | |
1719 | error ("No breakpoint at this line."); | |
1720 | } | |
1721 | ||
1722 | if (found->next) from_tty = 1; /* Always report if deleted more than one */ | |
1723 | if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : ""); | |
1724 | while (found) | |
1725 | { | |
1726 | if (from_tty) printf ("%d ", found->number); | |
1727 | b1 = found->next; | |
1728 | delete_breakpoint (found); | |
1729 | found = b1; | |
1730 | } | |
1731 | if (from_tty) putchar ('\n'); | |
1732 | } | |
1733 | free (sals.sals); | |
1734 | } | |
1735 | \f | |
1736 | /* Delete breakpoint in BS if they are `delete' breakpoints. | |
1737 | This is called after any breakpoint is hit, or after errors. */ | |
1738 | ||
1739 | void | |
1740 | breakpoint_auto_delete (bs) | |
1741 | bpstat bs; | |
1742 | { | |
1743 | for (; bs; bs = bs->next) | |
1744 | if (bs->breakpoint_at && bs->breakpoint_at->enable == delete) | |
1745 | delete_breakpoint (bs->breakpoint_at); | |
1746 | } | |
1747 | ||
1748 | /* Delete a breakpoint and clean up all traces of it in the data structures. */ | |
1749 | ||
1750 | static void | |
1751 | delete_breakpoint (bpt) | |
1752 | struct breakpoint *bpt; | |
1753 | { | |
1754 | register struct breakpoint *b; | |
1755 | register bpstat bs; | |
1756 | ||
1757 | if (bpt->inserted) | |
1758 | target_remove_breakpoint(bpt->address, bpt->shadow_contents); | |
1759 | ||
1760 | if (breakpoint_chain == bpt) | |
1761 | breakpoint_chain = bpt->next; | |
1762 | ||
1763 | ALL_BREAKPOINTS (b) | |
1764 | if (b->next == bpt) | |
1765 | { | |
1766 | b->next = bpt->next; | |
1767 | break; | |
1768 | } | |
1769 | ||
1770 | check_duplicates (bpt->address); | |
1771 | ||
1772 | free_command_lines (&bpt->commands); | |
1773 | if (bpt->cond) | |
1774 | free (bpt->cond); | |
1775 | if (bpt->cond_string != NULL) | |
1776 | free (bpt->cond_string); | |
1777 | if (bpt->addr_string != NULL) | |
1778 | free (bpt->addr_string); | |
1779 | ||
1780 | if (xgdb_verbose && bpt->number >=0) | |
1781 | printf ("breakpoint #%d deleted\n", bpt->number); | |
1782 | ||
1783 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
1784 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */ | |
1785 | for (bs = stop_bpstat; bs; bs = bs->next) | |
1786 | if (bs->breakpoint_at == bpt) | |
1787 | bs->breakpoint_at = NULL; | |
1788 | free (bpt); | |
1789 | } | |
1790 | ||
1791 | static void map_breakpoint_numbers (); | |
1792 | ||
1793 | static void | |
1794 | delete_command (arg, from_tty) | |
1795 | char *arg; | |
1796 | int from_tty; | |
1797 | { | |
1798 | ||
1799 | if (arg == 0) | |
1800 | { | |
1801 | /* Ask user only if there are some breakpoints to delete. */ | |
1802 | if (!from_tty | |
1803 | || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0))) | |
1804 | { | |
1805 | /* No arg; clear all breakpoints. */ | |
1806 | while (breakpoint_chain) | |
1807 | delete_breakpoint (breakpoint_chain); | |
1808 | } | |
1809 | } | |
1810 | else | |
1811 | map_breakpoint_numbers (arg, delete_breakpoint); | |
1812 | } | |
1813 | ||
1814 | static void | |
1815 | breakpoint_re_set_one (bint) | |
1816 | int bint; | |
1817 | { | |
1818 | struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */ | |
1819 | int i; | |
1820 | struct symtabs_and_lines sals; | |
1821 | struct symtab_and_line sal; | |
1822 | char *s; | |
1823 | ||
1824 | if (b->address != NULL && b->addr_string != NULL) | |
1825 | { | |
1826 | s = b->addr_string; | |
1827 | sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0); | |
1828 | for (i = 0; i < sals.nelts; i++) | |
1829 | { | |
1830 | sal = sals.sals[i]; | |
1831 | ||
1832 | b->symtab = sal.symtab; | |
1833 | b->line_number = sal.line; | |
1834 | if (sal.pc == 0 && sal.symtab != 0) | |
1835 | { | |
1836 | sal.pc = find_line_pc (sal.symtab, sal.line); | |
1837 | if (sal.pc == 0) | |
1838 | error ("No line %d in file \"%s\".", | |
1839 | sal.line, sal.symtab->filename); | |
1840 | } | |
1841 | b->address = sal.pc; | |
1842 | ||
1843 | if (b->cond_string != NULL) | |
1844 | { | |
1845 | s = b->cond_string; | |
1846 | b->cond = parse_c_1 (&s, block_for_pc (sal.pc), 0); | |
1847 | } | |
1848 | ||
1849 | check_duplicates (b->address); | |
1850 | ||
1851 | mention (b); | |
1852 | } | |
1853 | free (sals.sals); | |
1854 | } | |
1855 | else | |
1856 | { | |
1857 | /* Anything without a string can't be re-set. */ | |
1858 | delete_breakpoint (b); | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | /* Re-set all breakpoints after symbols have been re-loaded. */ | |
1863 | void | |
1864 | breakpoint_re_set () | |
1865 | { | |
1866 | struct breakpoint *b; | |
1867 | ||
1868 | ALL_BREAKPOINTS (b) | |
1869 | { | |
1870 | b->symtab = 0; /* Be sure we don't point to old dead symtab */ | |
1871 | (void) catch_errors (breakpoint_re_set_one, (int) b, | |
1872 | "Error in re-setting breakpoint"); | |
1873 | } | |
1874 | ||
1875 | /* Blank line to finish off all those mention() messages we just printed. */ | |
1876 | printf_filtered ("\n"); | |
1877 | } | |
1878 | \f | |
1879 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. | |
1880 | If from_tty is nonzero, it prints a message to that effect, | |
1881 | which ends with a period (no newline). */ | |
1882 | ||
1883 | void | |
1884 | set_ignore_count (bptnum, count, from_tty) | |
1885 | int bptnum, count, from_tty; | |
1886 | { | |
1887 | register struct breakpoint *b; | |
1888 | ||
1889 | if (count < 0) | |
1890 | count = 0; | |
1891 | ||
1892 | ALL_BREAKPOINTS (b) | |
1893 | if (b->number == bptnum) | |
1894 | { | |
1895 | b->ignore_count = count; | |
1896 | if (!from_tty) | |
1897 | return; | |
1898 | else if (count == 0) | |
1899 | printf ("Will stop next time breakpoint %d is reached.", bptnum); | |
1900 | else if (count == 1) | |
1901 | printf ("Will ignore next crossing of breakpoint %d.", bptnum); | |
1902 | else | |
1903 | printf ("Will ignore next %d crossings of breakpoint %d.", | |
1904 | count, bptnum); | |
1905 | return; | |
1906 | } | |
1907 | ||
1908 | error ("No breakpoint number %d.", bptnum); | |
1909 | } | |
1910 | ||
1911 | /* Clear the ignore counts of all breakpoints. */ | |
1912 | void | |
1913 | breakpoint_clear_ignore_counts () | |
1914 | { | |
1915 | struct breakpoint *b; | |
1916 | ||
1917 | ALL_BREAKPOINTS (b) | |
1918 | b->ignore_count = 0; | |
1919 | } | |
1920 | ||
1921 | /* Command to set ignore-count of breakpoint N to COUNT. */ | |
1922 | ||
1923 | static void | |
1924 | ignore_command (args, from_tty) | |
1925 | char *args; | |
1926 | int from_tty; | |
1927 | { | |
1928 | char *p = args; | |
1929 | register int num; | |
1930 | ||
1931 | if (p == 0) | |
1932 | error_no_arg ("a breakpoint number"); | |
1933 | ||
1934 | num = get_number (&p); | |
1935 | ||
1936 | if (*p == 0) | |
1937 | error ("Second argument (specified ignore-count) is missing."); | |
1938 | ||
1939 | set_ignore_count (num, parse_and_eval_address (p), from_tty); | |
1940 | printf ("\n"); | |
1941 | } | |
1942 | \f | |
1943 | /* Call FUNCTION on each of the breakpoints | |
1944 | whose numbers are given in ARGS. */ | |
1945 | ||
1946 | static void | |
1947 | map_breakpoint_numbers (args, function) | |
1948 | char *args; | |
1949 | void (*function) (); | |
1950 | { | |
1951 | register char *p = args; | |
1952 | char *p1; | |
1953 | register int num; | |
1954 | register struct breakpoint *b; | |
1955 | ||
1956 | if (p == 0) | |
1957 | error_no_arg ("one or more breakpoint numbers"); | |
1958 | ||
1959 | while (*p) | |
1960 | { | |
1961 | p1 = p; | |
1962 | ||
1963 | num = get_number (&p1); | |
1964 | ||
1965 | ALL_BREAKPOINTS (b) | |
1966 | if (b->number == num) | |
1967 | { | |
1968 | function (b); | |
1969 | goto win; | |
1970 | } | |
1971 | printf ("No breakpoint number %d.\n", num); | |
1972 | win: | |
1973 | p = p1; | |
1974 | } | |
1975 | } | |
1976 | ||
1977 | static void | |
1978 | enable_breakpoint (bpt) | |
1979 | struct breakpoint *bpt; | |
1980 | { | |
1981 | bpt->enable = enabled; | |
1982 | ||
1983 | if (xgdb_verbose && bpt->number >= 0) | |
1984 | printf ("breakpoint #%d enabled\n", bpt->number); | |
1985 | ||
1986 | check_duplicates (bpt->address); | |
1987 | if (bpt->val != NULL) | |
1988 | { | |
1989 | value_free (bpt->val); | |
1990 | ||
1991 | bpt->val = evaluate_expression (bpt->exp); | |
1992 | release_value (bpt->val); | |
1993 | } | |
1994 | } | |
1995 | ||
1996 | static void | |
1997 | enable_command (args, from_tty) | |
1998 | char *args; | |
1999 | int from_tty; | |
2000 | { | |
2001 | struct breakpoint *bpt; | |
2002 | if (args == 0) | |
2003 | ALL_BREAKPOINTS (bpt) | |
2004 | enable_breakpoint (bpt); | |
2005 | else | |
2006 | map_breakpoint_numbers (args, enable_breakpoint); | |
2007 | } | |
2008 | ||
2009 | static void | |
2010 | disable_breakpoint (bpt) | |
2011 | struct breakpoint *bpt; | |
2012 | { | |
2013 | bpt->enable = disabled; | |
2014 | ||
2015 | if (xgdb_verbose && bpt->number >= 0) | |
2016 | printf ("breakpoint #%d disabled\n", bpt->number); | |
2017 | ||
2018 | check_duplicates (bpt->address); | |
2019 | } | |
2020 | ||
2021 | static void | |
2022 | disable_command (args, from_tty) | |
2023 | char *args; | |
2024 | int from_tty; | |
2025 | { | |
2026 | register struct breakpoint *bpt; | |
2027 | if (args == 0) | |
2028 | ALL_BREAKPOINTS (bpt) | |
2029 | disable_breakpoint (bpt); | |
2030 | else | |
2031 | map_breakpoint_numbers (args, disable_breakpoint); | |
2032 | } | |
2033 | ||
2034 | static void | |
2035 | enable_once_breakpoint (bpt) | |
2036 | struct breakpoint *bpt; | |
2037 | { | |
2038 | bpt->enable = temporary; | |
2039 | ||
2040 | check_duplicates (bpt->address); | |
2041 | } | |
2042 | ||
2043 | static void | |
2044 | enable_once_command (args, from_tty) | |
2045 | char *args; | |
2046 | int from_tty; | |
2047 | { | |
2048 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
2049 | } | |
2050 | ||
2051 | static void | |
2052 | enable_delete_breakpoint (bpt) | |
2053 | struct breakpoint *bpt; | |
2054 | { | |
2055 | bpt->enable = delete; | |
2056 | ||
2057 | check_duplicates (bpt->address); | |
2058 | } | |
2059 | ||
2060 | static void | |
2061 | enable_delete_command (args, from_tty) | |
2062 | char *args; | |
2063 | int from_tty; | |
2064 | { | |
2065 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
2066 | } | |
2067 | \f | |
2068 | /* | |
2069 | * Use default_breakpoint_'s, or nothing if they aren't valid. | |
2070 | */ | |
2071 | struct symtabs_and_lines | |
2072 | decode_line_spec_1 (string, funfirstline) | |
2073 | char *string; | |
2074 | int funfirstline; | |
2075 | { | |
2076 | struct symtabs_and_lines sals; | |
2077 | if (string == 0) | |
2078 | error ("Empty line specification."); | |
2079 | if (default_breakpoint_valid) | |
2080 | sals = decode_line_1 (&string, funfirstline, | |
2081 | default_breakpoint_symtab, default_breakpoint_line); | |
2082 | else | |
2083 | sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0); | |
2084 | if (*string) | |
2085 | error ("Junk at end of line specification: %s", string); | |
2086 | return sals; | |
2087 | } | |
2088 | \f | |
2089 | ||
2090 | /* Chain containing all defined enable commands. */ | |
2091 | ||
2092 | extern struct cmd_list_element | |
2093 | *enablelist, *disablelist, | |
2094 | *deletelist, *enablebreaklist; | |
2095 | ||
2096 | extern struct cmd_list_element *cmdlist; | |
2097 | ||
2098 | void | |
2099 | _initialize_breakpoint () | |
2100 | { | |
2101 | breakpoint_chain = 0; | |
2102 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
2103 | before a breakpoint is set. */ | |
2104 | breakpoint_count = 0; | |
2105 | ||
2106 | add_com ("ignore", class_breakpoint, ignore_command, | |
2107 | "Set ignore-count of breakpoint number N to COUNT."); | |
2108 | ||
2109 | add_com ("commands", class_breakpoint, commands_command, | |
2110 | "Set commands to be executed when a breakpoint is hit.\n\ | |
2111 | Give breakpoint number as argument after \"commands\".\n\ | |
2112 | With no argument, the targeted breakpoint is the last one set.\n\ | |
2113 | The commands themselves follow starting on the next line.\n\ | |
2114 | Type a line containing \"end\" to indicate the end of them.\n\ | |
2115 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
2116 | then no output is printed when it is hit, except what the commands print."); | |
2117 | ||
2118 | add_com ("condition", class_breakpoint, condition_command, | |
2119 | "Specify breakpoint number N to break only if COND is true.\n\ | |
2120 | N is an integer; COND is a C expression to be evaluated whenever\n\ | |
2121 | breakpoint N is reached. Actually break only when COND is nonzero."); | |
2122 | ||
2123 | add_com ("tbreak", class_breakpoint, tbreak_command, | |
2124 | "Set a temporary breakpoint. Args like \"break\" command.\n\ | |
2125 | Like \"break\" except the breakpoint is only enabled temporarily,\n\ | |
2126 | so it will be disabled when hit. Equivalent to \"break\" followed\n\ | |
2127 | by using \"enable once\" on the breakpoint number."); | |
2128 | ||
2129 | add_prefix_cmd ("enable", class_breakpoint, enable_command, | |
2130 | "Enable some breakpoints.\n\ | |
2131 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
2132 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
2133 | This is used to cancel the effect of the \"disable\" command.\n\ | |
2134 | With a subcommand you can enable temporarily.", | |
2135 | &enablelist, "enable ", 1, &cmdlist); | |
2136 | ||
2137 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, | |
2138 | "Enable some breakpoints.\n\ | |
2139 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
2140 | This is used to cancel the effect of the \"disable\" command.\n\ | |
2141 | May be abbreviated to simply \"enable\".\n", | |
2142 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); | |
2143 | ||
2144 | add_cmd ("once", no_class, enable_once_command, | |
2145 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
2146 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ | |
2147 | See the \"tbreak\" command which sets a breakpoint and enables it once.", | |
2148 | &enablebreaklist); | |
2149 | ||
2150 | add_cmd ("delete", no_class, enable_delete_command, | |
2151 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
2152 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
2153 | &enablebreaklist); | |
2154 | ||
2155 | add_cmd ("delete", no_class, enable_delete_command, | |
2156 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
2157 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
2158 | &enablelist); | |
2159 | ||
2160 | add_cmd ("once", no_class, enable_once_command, | |
2161 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
2162 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ | |
2163 | See the \"tbreak\" command which sets a breakpoint and enables it once.", | |
2164 | &enablelist); | |
2165 | ||
2166 | add_prefix_cmd ("disable", class_breakpoint, disable_command, | |
2167 | "Disable some breakpoints.\n\ | |
2168 | Arguments are breakpoint numbers with spaces in between.\n\ | |
2169 | To disable all breakpoints, give no argument.\n\ | |
2170 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", | |
2171 | &disablelist, "disable ", 1, &cmdlist); | |
2172 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
2173 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
2174 | ||
2175 | add_cmd ("breakpoints", class_alias, disable_command, | |
2176 | "Disable some breakpoints.\n\ | |
2177 | Arguments are breakpoint numbers with spaces in between.\n\ | |
2178 | To disable all breakpoints, give no argument.\n\ | |
2179 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
2180 | This command may be abbreviated \"disable\".", | |
2181 | &disablelist); | |
2182 | ||
2183 | add_prefix_cmd ("delete", class_breakpoint, delete_command, | |
2184 | "Delete some breakpoints or auto-display expressions.\n\ | |
2185 | Arguments are breakpoint numbers with spaces in between.\n\ | |
2186 | To delete all breakpoints, give no argument.\n\ | |
2187 | \n\ | |
2188 | Also a prefix command for deletion of other GDB objects.\n\ | |
2189 | The \"unset\" command is also an alias for \"delete\".", | |
2190 | &deletelist, "delete ", 1, &cmdlist); | |
2191 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
2192 | add_com_alias ("unset", "delete", class_alias, 1); | |
2193 | ||
2194 | add_cmd ("breakpoints", class_alias, delete_command, | |
2195 | "Delete some breakpoints or auto-display expressions.\n\ | |
2196 | Arguments are breakpoint numbers with spaces in between.\n\ | |
2197 | To delete all breakpoints, give no argument.\n\ | |
2198 | This command may be abbreviated \"delete\".", | |
2199 | &deletelist); | |
2200 | ||
2201 | add_com ("clear", class_breakpoint, clear_command, | |
2202 | "Clear breakpoint at specified line or function.\n\ | |
2203 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
2204 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
2205 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
2206 | If an address is specified, breakpoints at that address are cleared.\n\n\ | |
2207 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
2208 | is executing in.\n\ | |
2209 | \n\ | |
2210 | See also the \"delete\" command which clears breakpoints by number."); | |
2211 | ||
2212 | add_com ("break", class_breakpoint, break_command, | |
2213 | "Set breakpoint at specified line or function.\n\ | |
2214 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
2215 | If line number is specified, break at start of code for that line.\n\ | |
2216 | If function is specified, break at start of code for that function.\n\ | |
2217 | If an address is specified, break at that exact address.\n\ | |
2218 | With no arg, uses current execution address of selected stack frame.\n\ | |
2219 | This is useful for breaking on return to a stack frame.\n\ | |
2220 | \n\ | |
2221 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
2222 | \n\ | |
2223 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
2224 | add_com_alias ("b", "break", class_run, 1); | |
2225 | add_com_alias ("br", "break", class_run, 1); | |
2226 | add_com_alias ("bre", "break", class_run, 1); | |
2227 | add_com_alias ("brea", "break", class_run, 1); | |
2228 | ||
2229 | add_info ("breakpoints", breakpoints_info, | |
2230 | "Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
2231 | Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\ | |
2232 | \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\ | |
2233 | Then come the address and the file/line number.\n\n\ | |
2234 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
2235 | are set to the address of the last breakpoint listed.\n\n\ | |
2236 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
2237 | breakpoint set."); | |
2238 | ||
2239 | add_com ("catch", class_breakpoint, catch_command, | |
2240 | "Set breakpoints to catch exceptions that are raised.\n\ | |
2241 | Argument may be a single exception to catch, multiple exceptions\n\ | |
2242 | to catch, or the default exception \"default\". If no arguments\n\ | |
2243 | are given, breakpoints are set at all exception handlers catch clauses\n\ | |
2244 | within the current scope.\n\ | |
2245 | \n\ | |
2246 | A condition specified for the catch applies to all breakpoints set\n\ | |
2247 | with this command\n\ | |
2248 | \n\ | |
2249 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
2250 | ||
2251 | add_com ("watch", class_breakpoint, watch_command, | |
2252 | "Set a watchpoint for an expression.\n\ | |
2253 | A watchpoint stops execution of your program whenever the value of\n\ | |
2254 | an expression changes."); | |
2255 | ||
2256 | add_info ("watchpoints", watchpoints_info, | |
2257 | "Status of all watchpoints, or watchpoint number NUMBER.\n\ | |
2258 | Second column is \"y\" for enabled watchpoints, \"n\" for disabled."); | |
2259 | } |