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