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