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 | 19 | |
bd5635a1 | 20 | #include "defs.h" |
1eeba686 | 21 | #include <ctype.h> |
bd5635a1 RP |
22 | #include "symtab.h" |
23 | #include "frame.h" | |
24 | #include "breakpoint.h" | |
30875e1c | 25 | #include "gdbtypes.h" |
bd5635a1 RP |
26 | #include "expression.h" |
27 | #include "gdbcore.h" | |
28 | #include "gdbcmd.h" | |
29 | #include "value.h" | |
30 | #include "ctype.h" | |
31 | #include "command.h" | |
32 | #include "inferior.h" | |
199b2450 | 33 | #include "thread.h" |
bd5635a1 | 34 | #include "target.h" |
d3b9c0df | 35 | #include "language.h" |
bd5635a1 | 36 | #include <string.h> |
423e9664 | 37 | #include "demangle.h" |
1c95d7ab | 38 | #include "annotate.h" |
bd5635a1 | 39 | |
30875e1c SG |
40 | /* local function prototypes */ |
41 | ||
42 | static void | |
43 | catch_command_1 PARAMS ((char *, int, int)); | |
44 | ||
45 | static void | |
46 | enable_delete_command PARAMS ((char *, int)); | |
47 | ||
48 | static void | |
49 | enable_delete_breakpoint PARAMS ((struct breakpoint *)); | |
50 | ||
51 | static void | |
52 | enable_once_command PARAMS ((char *, int)); | |
53 | ||
54 | static void | |
55 | enable_once_breakpoint PARAMS ((struct breakpoint *)); | |
56 | ||
57 | static void | |
58 | disable_command PARAMS ((char *, int)); | |
59 | ||
60 | static void | |
61 | disable_breakpoint PARAMS ((struct breakpoint *)); | |
62 | ||
63 | static void | |
64 | enable_command PARAMS ((char *, int)); | |
65 | ||
66 | static void | |
67 | enable_breakpoint PARAMS ((struct breakpoint *)); | |
68 | ||
69 | static void | |
70 | map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *))); | |
71 | ||
72 | static void | |
73 | ignore_command PARAMS ((char *, int)); | |
74 | ||
75 | static int | |
76 | breakpoint_re_set_one PARAMS ((char *)); | |
77 | ||
78 | static void | |
79 | delete_command PARAMS ((char *, int)); | |
80 | ||
81 | static void | |
82 | clear_command PARAMS ((char *, int)); | |
83 | ||
84 | static void | |
85 | catch_command PARAMS ((char *, int)); | |
86 | ||
87 | static struct symtabs_and_lines | |
88 | get_catch_sals PARAMS ((int)); | |
89 | ||
90 | static void | |
91 | watch_command PARAMS ((char *, int)); | |
92 | ||
999dd04b JL |
93 | static int |
94 | can_use_hardware_watchpoint PARAMS ((struct breakpoint *)); | |
95 | ||
30875e1c SG |
96 | static void |
97 | tbreak_command PARAMS ((char *, int)); | |
98 | ||
99 | static void | |
100 | break_command_1 PARAMS ((char *, int, int)); | |
101 | ||
102 | static void | |
103 | mention PARAMS ((struct breakpoint *)); | |
104 | ||
105 | static struct breakpoint * | |
106 | set_raw_breakpoint PARAMS ((struct symtab_and_line)); | |
107 | ||
108 | static void | |
109 | check_duplicates PARAMS ((CORE_ADDR)); | |
110 | ||
111 | static void | |
112 | describe_other_breakpoints PARAMS ((CORE_ADDR)); | |
113 | ||
30875e1c SG |
114 | static void |
115 | breakpoints_info PARAMS ((char *, int)); | |
116 | ||
117 | static void | |
423e9664 | 118 | breakpoint_1 PARAMS ((int, int)); |
30875e1c SG |
119 | |
120 | static bpstat | |
121 | bpstat_alloc PARAMS ((struct breakpoint *, bpstat)); | |
122 | ||
123 | static int | |
124 | breakpoint_cond_eval PARAMS ((char *)); | |
125 | ||
126 | static void | |
127 | cleanup_executing_breakpoints PARAMS ((int)); | |
128 | ||
129 | static void | |
130 | commands_command PARAMS ((char *, int)); | |
131 | ||
132 | static void | |
133 | condition_command PARAMS ((char *, int)); | |
134 | ||
135 | static int | |
136 | get_number PARAMS ((char **)); | |
137 | ||
138 | static void | |
139 | set_breakpoint_count PARAMS ((int)); | |
140 | ||
999dd04b JL |
141 | static int |
142 | remove_breakpoint PARAMS ((struct breakpoint *)); | |
30875e1c | 143 | |
bd5635a1 RP |
144 | extern int addressprint; /* Print machine addresses? */ |
145 | extern int demangle; /* Print de-mangled symbol names? */ | |
146 | ||
bd5635a1 RP |
147 | /* Are we executing breakpoint commands? */ |
148 | static int executing_breakpoint_commands; | |
149 | ||
cba0d141 JG |
150 | /* Walk the following statement or block through all breakpoints. |
151 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
152 | breakpoint. */ | |
153 | ||
bd5635a1 RP |
154 | #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) |
155 | ||
cba0d141 JG |
156 | #define ALL_BREAKPOINTS_SAFE(b,tmp) \ |
157 | for (b = breakpoint_chain; \ | |
158 | b? (tmp=b->next, 1): 0; \ | |
159 | b = tmp) | |
160 | ||
999dd04b JL |
161 | /* By default no support for hardware watchpoints is assumed. */ |
162 | #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT | |
163 | #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(B) 0 | |
164 | #define target_remove_watchpoint(ADDR,LEN) -1 | |
165 | #define target_insert_watchpoint(ADDR,LEN) -1 | |
166 | #endif | |
167 | ||
bd5635a1 RP |
168 | /* Chain of all breakpoints defined. */ |
169 | ||
05052b63 | 170 | static struct breakpoint *breakpoint_chain; |
bd5635a1 RP |
171 | |
172 | /* Number of last breakpoint made. */ | |
173 | ||
174 | static int breakpoint_count; | |
175 | ||
176 | /* Set breakpoint count to NUM. */ | |
177 | static void | |
178 | set_breakpoint_count (num) | |
179 | int num; | |
180 | { | |
181 | breakpoint_count = num; | |
182 | set_internalvar (lookup_internalvar ("bpnum"), | |
06b6c733 | 183 | value_from_longest (builtin_type_int, (LONGEST) num)); |
bd5635a1 RP |
184 | } |
185 | ||
186 | /* Default address, symtab and line to put a breakpoint at | |
187 | for "break" command with no arg. | |
188 | if default_breakpoint_valid is zero, the other three are | |
189 | not valid, and "break" with no arg is an error. | |
190 | ||
191 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
192 | ||
193 | int default_breakpoint_valid; | |
194 | CORE_ADDR default_breakpoint_address; | |
195 | struct symtab *default_breakpoint_symtab; | |
196 | int default_breakpoint_line; | |
bd5635a1 RP |
197 | \f |
198 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
199 | Advance *PP after the string and any trailing whitespace. | |
200 | ||
201 | Currently the string can either be a number or "$" followed by the name | |
202 | of a convenience variable. Making it an expression wouldn't work well | |
203 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */ | |
204 | static int | |
205 | get_number (pp) | |
206 | char **pp; | |
207 | { | |
208 | int retval; | |
209 | char *p = *pp; | |
210 | ||
211 | if (p == NULL) | |
212 | /* Empty line means refer to the last breakpoint. */ | |
213 | return breakpoint_count; | |
214 | else if (*p == '$') | |
215 | { | |
216 | /* Make a copy of the name, so we can null-terminate it | |
217 | to pass to lookup_internalvar(). */ | |
218 | char *varname; | |
219 | char *start = ++p; | |
82a2edfb | 220 | value_ptr val; |
bd5635a1 RP |
221 | |
222 | while (isalnum (*p) || *p == '_') | |
223 | p++; | |
224 | varname = (char *) alloca (p - start + 1); | |
225 | strncpy (varname, start, p - start); | |
226 | varname[p - start] = '\0'; | |
227 | val = value_of_internalvar (lookup_internalvar (varname)); | |
228 | if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT) | |
229 | error ( | |
230 | "Convenience variables used to specify breakpoints must have integer values." | |
231 | ); | |
232 | retval = (int) value_as_long (val); | |
233 | } | |
234 | else | |
235 | { | |
80ba48f5 SG |
236 | if (*p == '-') |
237 | ++p; | |
bd5635a1 RP |
238 | while (*p >= '0' && *p <= '9') |
239 | ++p; | |
240 | if (p == *pp) | |
241 | /* There is no number here. (e.g. "cond a == b"). */ | |
242 | error_no_arg ("breakpoint number"); | |
243 | retval = atoi (*pp); | |
244 | } | |
245 | if (!(isspace (*p) || *p == '\0')) | |
246 | error ("breakpoint number expected"); | |
247 | while (isspace (*p)) | |
248 | p++; | |
249 | *pp = p; | |
250 | return retval; | |
251 | } | |
252 | \f | |
253 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
254 | ||
255 | static void | |
256 | condition_command (arg, from_tty) | |
257 | char *arg; | |
258 | int from_tty; | |
259 | { | |
260 | register struct breakpoint *b; | |
261 | char *p; | |
262 | register int bnum; | |
263 | ||
264 | if (arg == 0) | |
265 | error_no_arg ("breakpoint number"); | |
266 | ||
267 | p = arg; | |
268 | bnum = get_number (&p); | |
269 | ||
270 | ALL_BREAKPOINTS (b) | |
271 | if (b->number == bnum) | |
272 | { | |
273 | if (b->cond) | |
274 | { | |
c8950965 | 275 | free ((PTR)b->cond); |
bd5635a1 RP |
276 | b->cond = 0; |
277 | } | |
278 | if (b->cond_string != NULL) | |
c8950965 | 279 | free ((PTR)b->cond_string); |
bd5635a1 RP |
280 | |
281 | if (*p == 0) | |
282 | { | |
283 | b->cond = 0; | |
284 | b->cond_string = NULL; | |
285 | if (from_tty) | |
423e9664 | 286 | printf_filtered ("Breakpoint %d now unconditional.\n", bnum); |
bd5635a1 RP |
287 | } |
288 | else | |
289 | { | |
290 | arg = p; | |
291 | /* I don't know if it matters whether this is the string the user | |
292 | typed in or the decompiled expression. */ | |
293 | b->cond_string = savestring (arg, strlen (arg)); | |
d3b9c0df | 294 | b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0); |
bd5635a1 RP |
295 | if (*arg) |
296 | error ("Junk at end of expression"); | |
297 | } | |
298 | return; | |
299 | } | |
300 | ||
301 | error ("No breakpoint number %d.", bnum); | |
302 | } | |
303 | ||
bdbd5f50 | 304 | /* ARGSUSED */ |
bd5635a1 RP |
305 | static void |
306 | commands_command (arg, from_tty) | |
307 | char *arg; | |
308 | int from_tty; | |
309 | { | |
310 | register struct breakpoint *b; | |
311 | char *p; | |
312 | register int bnum; | |
313 | struct command_line *l; | |
314 | ||
315 | /* If we allowed this, we would have problems with when to | |
316 | free the storage, if we change the commands currently | |
317 | being read from. */ | |
318 | ||
319 | if (executing_breakpoint_commands) | |
320 | error ("Can't use the \"commands\" command among a breakpoint's commands."); | |
321 | ||
322 | p = arg; | |
323 | bnum = get_number (&p); | |
324 | if (p && *p) | |
325 | error ("Unexpected extra arguments following breakpoint number."); | |
326 | ||
327 | ALL_BREAKPOINTS (b) | |
328 | if (b->number == bnum) | |
329 | { | |
bdbd5f50 | 330 | if (from_tty && input_from_terminal_p ()) |
9b280a7f | 331 | printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\ |
bd5635a1 | 332 | End with a line saying just \"end\".\n", bnum); |
bd5635a1 RP |
333 | l = read_command_lines (); |
334 | free_command_lines (&b->commands); | |
335 | b->commands = l; | |
6c803036 | 336 | breakpoints_changed (); |
bd5635a1 RP |
337 | return; |
338 | } | |
339 | error ("No breakpoint number %d.", bnum); | |
340 | } | |
341 | \f | |
31ef19fc JK |
342 | extern int memory_breakpoint_size; /* from mem-break.c */ |
343 | ||
344 | /* Like target_read_memory() but if breakpoints are inserted, return | |
30875e1c SG |
345 | the shadow contents instead of the breakpoints themselves. |
346 | ||
347 | Read "memory data" from whatever target or inferior we have. | |
348 | Returns zero if successful, errno value if not. EIO is used | |
349 | for address out of bounds. If breakpoints are inserted, returns | |
350 | shadow contents, not the breakpoints themselves. From breakpoint.c. */ | |
351 | ||
31ef19fc JK |
352 | int |
353 | read_memory_nobpt (memaddr, myaddr, len) | |
354 | CORE_ADDR memaddr; | |
355 | char *myaddr; | |
356 | unsigned len; | |
357 | { | |
358 | int status; | |
359 | struct breakpoint *b; | |
360 | ||
361 | if (memory_breakpoint_size < 0) | |
5af4f5f6 JK |
362 | /* No breakpoints on this machine. FIXME: This should be |
363 | dependent on the debugging target. Probably want | |
364 | target_insert_breakpoint to return a size, saying how many | |
365 | bytes of the shadow contents are used, or perhaps have | |
366 | something like target_xfer_shadow. */ | |
31ef19fc JK |
367 | return target_read_memory (memaddr, myaddr, len); |
368 | ||
369 | ALL_BREAKPOINTS (b) | |
370 | { | |
999dd04b JL |
371 | if (b->type == bp_watchpoint |
372 | || b->type == bp_hardware_watchpoint | |
373 | || !b->inserted) | |
31ef19fc JK |
374 | continue; |
375 | else if (b->address + memory_breakpoint_size <= memaddr) | |
376 | /* The breakpoint is entirely before the chunk of memory | |
377 | we are reading. */ | |
378 | continue; | |
379 | else if (b->address >= memaddr + len) | |
380 | /* The breakpoint is entirely after the chunk of memory we | |
381 | are reading. */ | |
382 | continue; | |
383 | else | |
384 | { | |
385 | /* Copy the breakpoint from the shadow contents, and recurse | |
386 | for the things before and after. */ | |
387 | ||
388 | /* Addresses and length of the part of the breakpoint that | |
389 | we need to copy. */ | |
390 | CORE_ADDR membpt = b->address; | |
391 | unsigned int bptlen = memory_breakpoint_size; | |
392 | /* Offset within shadow_contents. */ | |
393 | int bptoffset = 0; | |
394 | ||
395 | if (membpt < memaddr) | |
396 | { | |
397 | /* Only copy the second part of the breakpoint. */ | |
398 | bptlen -= memaddr - membpt; | |
399 | bptoffset = memaddr - membpt; | |
400 | membpt = memaddr; | |
401 | } | |
402 | ||
403 | if (membpt + bptlen > memaddr + len) | |
404 | { | |
405 | /* Only copy the first part of the breakpoint. */ | |
406 | bptlen -= (membpt + bptlen) - (memaddr + len); | |
407 | } | |
408 | ||
4ed3a9ea FF |
409 | memcpy (myaddr + membpt - memaddr, |
410 | b->shadow_contents + bptoffset, bptlen); | |
31ef19fc JK |
411 | |
412 | if (membpt > memaddr) | |
413 | { | |
414 | /* Copy the section of memory before the breakpoint. */ | |
415 | status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr); | |
416 | if (status != 0) | |
417 | return status; | |
418 | } | |
419 | ||
420 | if (membpt + bptlen < memaddr + len) | |
421 | { | |
422 | /* Copy the section of memory after the breakpoint. */ | |
423 | status = read_memory_nobpt | |
424 | (membpt + bptlen, | |
425 | myaddr + membpt + bptlen - memaddr, | |
426 | memaddr + len - (membpt + bptlen)); | |
427 | if (status != 0) | |
428 | return status; | |
429 | } | |
430 | return 0; | |
431 | } | |
432 | } | |
433 | /* Nothing overlaps. Just call read_memory_noerr. */ | |
434 | return target_read_memory (memaddr, myaddr, len); | |
435 | } | |
436 | \f | |
bd5635a1 RP |
437 | /* insert_breakpoints is used when starting or continuing the program. |
438 | remove_breakpoints is used when the program stops. | |
439 | Both return zero if successful, | |
440 | or an `errno' value if could not write the inferior. */ | |
441 | ||
442 | int | |
443 | insert_breakpoints () | |
444 | { | |
445 | register struct breakpoint *b; | |
446 | int val = 0; | |
447 | int disabled_breaks = 0; | |
448 | ||
449 | ALL_BREAKPOINTS (b) | |
30875e1c | 450 | if (b->type != bp_watchpoint |
999dd04b | 451 | && b->type != bp_hardware_watchpoint |
bd5635a1 RP |
452 | && b->enable != disabled |
453 | && ! b->inserted | |
454 | && ! b->duplicate) | |
455 | { | |
456 | val = target_insert_breakpoint(b->address, b->shadow_contents); | |
457 | if (val) | |
458 | { | |
459 | /* Can't set the breakpoint. */ | |
460 | #if defined (DISABLE_UNSETTABLE_BREAK) | |
461 | if (DISABLE_UNSETTABLE_BREAK (b->address)) | |
462 | { | |
463 | val = 0; | |
464 | b->enable = disabled; | |
465 | if (!disabled_breaks) | |
466 | { | |
05052b63 | 467 | target_terminal_ours_for_output (); |
199b2450 | 468 | fprintf_unfiltered (gdb_stderr, |
2d313932 | 469 | "Cannot insert breakpoint %d:\n", b->number); |
bd5635a1 RP |
470 | printf_filtered ("Disabling shared library breakpoints:\n"); |
471 | } | |
472 | disabled_breaks = 1; | |
473 | printf_filtered ("%d ", b->number); | |
474 | } | |
475 | else | |
476 | #endif | |
477 | { | |
05052b63 | 478 | target_terminal_ours_for_output (); |
199b2450 | 479 | fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number); |
d3b9c0df | 480 | #ifdef ONE_PROCESS_WRITETEXT |
199b2450 | 481 | fprintf_unfiltered (gdb_stderr, |
2d313932 | 482 | "The same program may be running in another process.\n"); |
d3b9c0df | 483 | #endif |
bd5635a1 RP |
484 | memory_error (val, b->address); /* which bombs us out */ |
485 | } | |
486 | } | |
487 | else | |
488 | b->inserted = 1; | |
489 | } | |
999dd04b JL |
490 | else if (b->type == bp_hardware_watchpoint |
491 | && b->enable == enabled | |
492 | && ! b->inserted | |
493 | && ! b->duplicate) | |
494 | { | |
495 | FRAME saved_frame; | |
496 | int saved_level, within_current_scope; | |
497 | value_ptr mark = value_mark (); | |
498 | value_ptr v; | |
499 | ||
500 | /* Save the current frame and level so we can restore it after | |
501 | evaluating the watchpoint expression on its own frame. */ | |
502 | saved_frame = selected_frame; | |
503 | saved_level = selected_frame_level; | |
504 | ||
505 | /* Determine if the watchpoint is within scope. */ | |
506 | if (b->exp_valid_block == NULL) | |
507 | within_current_scope = 1; | |
508 | else | |
509 | { | |
510 | FRAME fr = find_frame_addr_in_frame_chain (b->watchpoint_frame); | |
511 | within_current_scope = (fr != NULL); | |
512 | if (within_current_scope) | |
513 | select_frame (fr, -1); | |
514 | } | |
515 | ||
516 | if (within_current_scope) | |
517 | { | |
518 | /* Evaluate the expression and cut the chain of values | |
519 | produced off from the value chain. */ | |
520 | v = evaluate_expression (b->exp); | |
521 | value_release_to_mark (mark); | |
522 | ||
523 | b->val_chain = v; | |
524 | b->inserted = 1; | |
525 | ||
526 | /* Look at each value on the value chain. */ | |
527 | for ( ; v; v=v->next) | |
528 | { | |
529 | /* If it's a memory location, then we must watch it. */ | |
530 | if (v->lval == lval_memory) | |
531 | { | |
532 | int addr, len; | |
533 | ||
534 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
535 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
536 | val = target_insert_watchpoint (addr, len); | |
537 | if (val == -1) | |
538 | { | |
539 | b->inserted = 0; | |
540 | break; | |
541 | } | |
542 | val = 0; | |
543 | } | |
544 | } | |
545 | /* Failure to insert a watchpoint on any memory value in the | |
546 | value chain brings us here. */ | |
547 | if (!b->inserted) | |
548 | warning ("Hardware watchpoint %d: Could not insert watchpoint\n", | |
549 | b->number); | |
550 | } | |
551 | else | |
552 | { | |
553 | printf_filtered ("\ | |
554 | Hardware watchpoint %d deleted because the program has left the block in\n\ | |
555 | which its expression is valid.\n", b->number); | |
556 | if (b->related_breakpoint) | |
557 | delete_breakpoint (b->related_breakpoint); | |
558 | delete_breakpoint (b); | |
559 | } | |
560 | ||
561 | /* Restore the frame and level. */ | |
562 | select_frame (saved_frame, saved_level); | |
563 | } | |
bd5635a1 RP |
564 | if (disabled_breaks) |
565 | printf_filtered ("\n"); | |
566 | return val; | |
567 | } | |
568 | ||
999dd04b | 569 | |
bd5635a1 RP |
570 | int |
571 | remove_breakpoints () | |
572 | { | |
573 | register struct breakpoint *b; | |
574 | int val; | |
575 | ||
bd5635a1 | 576 | ALL_BREAKPOINTS (b) |
999dd04b JL |
577 | { |
578 | if (b->inserted) | |
579 | { | |
580 | val = remove_breakpoint (b); | |
581 | if (val != 0) | |
582 | return val; | |
583 | } | |
584 | } | |
585 | return 0; | |
586 | } | |
bd5635a1 | 587 | |
999dd04b JL |
588 | |
589 | static int | |
590 | remove_breakpoint (b) | |
591 | struct breakpoint *b; | |
592 | { | |
593 | int val; | |
594 | ||
595 | if (b->type != bp_watchpoint | |
596 | && b->type != bp_hardware_watchpoint) | |
597 | { | |
598 | val = target_remove_breakpoint(b->address, b->shadow_contents); | |
599 | if (val) | |
600 | return val; | |
601 | b->inserted = 0; | |
602 | } | |
603 | else if (b->type == bp_hardware_watchpoint | |
604 | && b->enable == enabled | |
605 | && ! b->duplicate) | |
606 | { | |
607 | value_ptr v, n; | |
608 | ||
609 | b->inserted = 0; | |
610 | /* Walk down the saved value chain. */ | |
611 | for (v = b->val_chain; v; v = v->next) | |
612 | { | |
613 | /* For each memory reference remove the watchpoint | |
614 | at that address. */ | |
615 | if (v->lval == lval_memory) | |
616 | { | |
617 | int addr, len; | |
618 | ||
619 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
620 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
621 | val = target_remove_watchpoint (addr, len); | |
622 | if (val == -1) | |
623 | b->inserted = 1; | |
624 | val = 0; | |
625 | } | |
626 | } | |
627 | /* Failure to remove any of the hardware watchpoints comes here. */ | |
628 | if (b->inserted) | |
629 | error ("Hardware watchpoint %d: Could not remove watchpoint\n", | |
630 | b->number); | |
631 | ||
632 | /* Free the saved value chain. We will construct a new one | |
633 | the next time the watchpoint is inserted. */ | |
634 | for (v = b->val_chain; v; v = n) | |
635 | { | |
636 | n = v->next; | |
637 | value_free (v); | |
638 | } | |
639 | b->val_chain = NULL; | |
640 | } | |
bd5635a1 RP |
641 | return 0; |
642 | } | |
643 | ||
cf3e377e | 644 | /* Clear the "inserted" flag in all breakpoints. */ |
bd5635a1 RP |
645 | |
646 | void | |
647 | mark_breakpoints_out () | |
648 | { | |
649 | register struct breakpoint *b; | |
650 | ||
651 | ALL_BREAKPOINTS (b) | |
652 | b->inserted = 0; | |
653 | } | |
654 | ||
cf3e377e JK |
655 | /* Clear the "inserted" flag in all breakpoints and delete any breakpoints |
656 | which should go away between runs of the program. */ | |
657 | ||
658 | void | |
659 | breakpoint_init_inferior () | |
660 | { | |
661 | register struct breakpoint *b, *temp; | |
662 | ||
663 | ALL_BREAKPOINTS_SAFE (b, temp) | |
664 | { | |
665 | b->inserted = 0; | |
666 | ||
667 | /* If the call dummy breakpoint is at the entry point it will | |
668 | cause problems when the inferior is rerun, so we better | |
669 | get rid of it. */ | |
670 | if (b->type == bp_call_dummy) | |
671 | delete_breakpoint (b); | |
999dd04b JL |
672 | |
673 | /* Likewise for scope breakpoints. */ | |
674 | if (b->type == bp_watchpoint_scope) | |
675 | delete_breakpoint (b); | |
676 | ||
677 | /* Likewise for watchpoints on local expressions. */ | |
678 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
679 | && b->exp_valid_block != NULL) | |
680 | delete_breakpoint (b); | |
cf3e377e JK |
681 | } |
682 | } | |
683 | ||
bd5635a1 RP |
684 | /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC. |
685 | When continuing from a location with a breakpoint, | |
686 | we actually single step once before calling insert_breakpoints. */ | |
687 | ||
688 | int | |
689 | breakpoint_here_p (pc) | |
690 | CORE_ADDR pc; | |
691 | { | |
692 | register struct breakpoint *b; | |
693 | ||
694 | ALL_BREAKPOINTS (b) | |
695 | if (b->enable != disabled && b->address == pc) | |
696 | return 1; | |
697 | ||
698 | return 0; | |
699 | } | |
199b2450 | 700 | |
05052b63 JK |
701 | /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY |
702 | because figuring out the saved SP would take too much time, at least using | |
703 | get_saved_register on the 68k. This means that for this function to | |
704 | work right a port must use the bp_call_dummy breakpoint. */ | |
705 | ||
706 | int | |
707 | frame_in_dummy (frame) | |
708 | FRAME frame; | |
709 | { | |
710 | struct breakpoint *b; | |
711 | ||
d7e7e851 | 712 | #ifdef CALL_DUMMY |
05052b63 JK |
713 | ALL_BREAKPOINTS (b) |
714 | { | |
d7e7e851 JK |
715 | static unsigned LONGEST dummy[] = CALL_DUMMY; |
716 | ||
05052b63 | 717 | if (b->type == bp_call_dummy |
d7e7e851 JK |
718 | && b->frame == frame->frame |
719 | ||
720 | /* We need to check the PC as well as the frame on the sparc, | |
721 | for signals.exp in the testsuite. */ | |
722 | && (frame->pc | |
723 | >= (b->address | |
724 | - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE)) | |
725 | && frame->pc <= b->address) | |
05052b63 JK |
726 | return 1; |
727 | } | |
d7e7e851 | 728 | #endif /* CALL_DUMMY */ |
05052b63 JK |
729 | return 0; |
730 | } | |
731 | ||
199b2450 TL |
732 | /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC |
733 | is valid for process/thread PID. */ | |
734 | ||
735 | int | |
736 | breakpoint_thread_match (pc, pid) | |
737 | CORE_ADDR pc; | |
738 | int pid; | |
739 | { | |
740 | struct breakpoint *b; | |
741 | int thread; | |
742 | ||
743 | thread = pid_to_thread_id (pid); | |
744 | ||
745 | ALL_BREAKPOINTS (b) | |
746 | if (b->enable != disabled | |
747 | && b->address == pc | |
748 | && (b->thread == -1 || b->thread == thread)) | |
749 | return 1; | |
750 | ||
751 | return 0; | |
752 | } | |
753 | ||
bd5635a1 RP |
754 | \f |
755 | /* bpstat stuff. External routines' interfaces are documented | |
756 | in breakpoint.h. */ | |
30875e1c SG |
757 | |
758 | /* Clear a bpstat so that it says we are not at any breakpoint. | |
759 | Also free any storage that is part of a bpstat. */ | |
760 | ||
bd5635a1 RP |
761 | void |
762 | bpstat_clear (bsp) | |
763 | bpstat *bsp; | |
764 | { | |
765 | bpstat p; | |
766 | bpstat q; | |
767 | ||
768 | if (bsp == 0) | |
769 | return; | |
770 | p = *bsp; | |
771 | while (p != NULL) | |
772 | { | |
773 | q = p->next; | |
774 | if (p->old_val != NULL) | |
775 | value_free (p->old_val); | |
c8950965 | 776 | free ((PTR)p); |
bd5635a1 RP |
777 | p = q; |
778 | } | |
779 | *bsp = NULL; | |
780 | } | |
781 | ||
30875e1c SG |
782 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
783 | is part of the bpstat is copied as well. */ | |
784 | ||
bd5635a1 RP |
785 | bpstat |
786 | bpstat_copy (bs) | |
787 | bpstat bs; | |
788 | { | |
789 | bpstat p = NULL; | |
790 | bpstat tmp; | |
fee933f1 | 791 | bpstat retval = NULL; |
bd5635a1 RP |
792 | |
793 | if (bs == NULL) | |
794 | return bs; | |
795 | ||
796 | for (; bs != NULL; bs = bs->next) | |
797 | { | |
798 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4ed3a9ea | 799 | memcpy (tmp, bs, sizeof (*tmp)); |
bd5635a1 RP |
800 | if (p == NULL) |
801 | /* This is the first thing in the chain. */ | |
802 | retval = tmp; | |
803 | else | |
804 | p->next = tmp; | |
805 | p = tmp; | |
806 | } | |
807 | p->next = NULL; | |
808 | return retval; | |
809 | } | |
810 | ||
30875e1c SG |
811 | /* Find the bpstat associated with this breakpoint */ |
812 | ||
813 | bpstat | |
814 | bpstat_find_breakpoint(bsp, breakpoint) | |
815 | bpstat bsp; | |
816 | struct breakpoint *breakpoint; | |
817 | { | |
818 | if (bsp == NULL) return NULL; | |
819 | ||
820 | for (;bsp != NULL; bsp = bsp->next) { | |
821 | if (bsp->breakpoint_at == breakpoint) return bsp; | |
822 | } | |
823 | return NULL; | |
824 | } | |
825 | ||
826 | /* Return the breakpoint number of the first breakpoint we are stopped | |
827 | at. *BSP upon return is a bpstat which points to the remaining | |
828 | breakpoints stopped at (but which is not guaranteed to be good for | |
829 | anything but further calls to bpstat_num). | |
830 | Return 0 if passed a bpstat which does not indicate any breakpoints. */ | |
831 | ||
bd5635a1 RP |
832 | int |
833 | bpstat_num (bsp) | |
834 | bpstat *bsp; | |
835 | { | |
836 | struct breakpoint *b; | |
837 | ||
838 | if ((*bsp) == NULL) | |
839 | return 0; /* No more breakpoint values */ | |
840 | else | |
841 | { | |
842 | b = (*bsp)->breakpoint_at; | |
843 | *bsp = (*bsp)->next; | |
844 | if (b == NULL) | |
845 | return -1; /* breakpoint that's been deleted since */ | |
846 | else | |
847 | return b->number; /* We have its number */ | |
848 | } | |
849 | } | |
850 | ||
30875e1c SG |
851 | /* Modify BS so that the actions will not be performed. */ |
852 | ||
bd5635a1 RP |
853 | void |
854 | bpstat_clear_actions (bs) | |
855 | bpstat bs; | |
856 | { | |
857 | for (; bs != NULL; bs = bs->next) | |
858 | { | |
859 | bs->commands = NULL; | |
860 | if (bs->old_val != NULL) | |
861 | { | |
862 | value_free (bs->old_val); | |
863 | bs->old_val = NULL; | |
864 | } | |
865 | } | |
866 | } | |
867 | ||
bdbd5f50 JG |
868 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
869 | /* ARGSUSED */ | |
870 | static void | |
871 | cleanup_executing_breakpoints (ignore) | |
872 | int ignore; | |
873 | { | |
874 | executing_breakpoint_commands = 0; | |
875 | } | |
876 | ||
bd5635a1 RP |
877 | /* Execute all the commands associated with all the breakpoints at this |
878 | location. Any of these commands could cause the process to proceed | |
879 | beyond this point, etc. We look out for such changes by checking | |
880 | the global "breakpoint_proceeded" after each command. */ | |
30875e1c | 881 | |
bd5635a1 RP |
882 | void |
883 | bpstat_do_actions (bsp) | |
884 | bpstat *bsp; | |
885 | { | |
886 | bpstat bs; | |
bdbd5f50 JG |
887 | struct cleanup *old_chain; |
888 | ||
889 | executing_breakpoint_commands = 1; | |
890 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
bd5635a1 RP |
891 | |
892 | top: | |
893 | bs = *bsp; | |
894 | ||
bd5635a1 RP |
895 | breakpoint_proceeded = 0; |
896 | for (; bs != NULL; bs = bs->next) | |
897 | { | |
898 | while (bs->commands) | |
899 | { | |
900 | char *line = bs->commands->line; | |
901 | bs->commands = bs->commands->next; | |
902 | execute_command (line, 0); | |
903 | /* If the inferior is proceeded by the command, bomb out now. | |
904 | The bpstat chain has been blown away by wait_for_inferior. | |
905 | But since execution has stopped again, there is a new bpstat | |
906 | to look at, so start over. */ | |
907 | if (breakpoint_proceeded) | |
908 | goto top; | |
909 | } | |
910 | } | |
bd5635a1 RP |
911 | |
912 | executing_breakpoint_commands = 0; | |
bdbd5f50 | 913 | discard_cleanups (old_chain); |
bd5635a1 RP |
914 | } |
915 | ||
8af68e4e JK |
916 | /* This is the normal print_it function for a bpstat. In the future, |
917 | much of this logic could (should?) be moved to bpstat_stop_status, | |
918 | by having it set different print_it functions. */ | |
30875e1c | 919 | |
8af68e4e JK |
920 | static int |
921 | print_it_normal (bs) | |
bd5635a1 RP |
922 | bpstat bs; |
923 | { | |
924 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint | |
925 | which has since been deleted. */ | |
8af68e4e | 926 | if (bs->breakpoint_at == NULL |
30875e1c | 927 | || (bs->breakpoint_at->type != bp_breakpoint |
999dd04b JL |
928 | && bs->breakpoint_at->type != bp_watchpoint |
929 | && bs->breakpoint_at->type != bp_hardware_watchpoint)) | |
bd5635a1 | 930 | return 0; |
bd5635a1 | 931 | |
30875e1c | 932 | if (bs->breakpoint_at->type == bp_breakpoint) |
bd5635a1 RP |
933 | { |
934 | /* I think the user probably only wants to see one breakpoint | |
935 | number, not all of them. */ | |
1c95d7ab | 936 | annotate_breakpoint (bs->breakpoint_at->number); |
bd5635a1 RP |
937 | printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number); |
938 | return 0; | |
939 | } | |
1c95d7ab | 940 | |
bd5635a1 RP |
941 | if (bs->old_val != NULL) |
942 | { | |
1c95d7ab | 943 | annotate_watchpoint (bs->breakpoint_at->number); |
bd5635a1 | 944 | printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number); |
199b2450 | 945 | print_expression (bs->breakpoint_at->exp, gdb_stdout); |
bd5635a1 | 946 | printf_filtered ("\nOld value = "); |
199b2450 | 947 | value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default); |
bd5635a1 | 948 | printf_filtered ("\nNew value = "); |
199b2450 | 949 | value_print (bs->breakpoint_at->val, gdb_stdout, 0, |
bd5635a1 RP |
950 | Val_pretty_default); |
951 | printf_filtered ("\n"); | |
952 | value_free (bs->old_val); | |
953 | bs->old_val = NULL; | |
bd2f0c85 JL |
954 | /* More than one watchpoint may have been triggered. */ |
955 | return -1; | |
bd5635a1 | 956 | } |
8af68e4e JK |
957 | /* We can't deal with it. Maybe another member of the bpstat chain can. */ |
958 | return -1; | |
959 | } | |
960 | ||
961 | /* Print a message indicating what happened. Returns nonzero to | |
962 | say that only the source line should be printed after this (zero | |
963 | return means print the frame as well as the source line). */ | |
3f031adf | 964 | /* Currently we always return zero. */ |
8af68e4e JK |
965 | int |
966 | bpstat_print (bs) | |
967 | bpstat bs; | |
968 | { | |
969 | int val; | |
970 | ||
971 | if (bs == NULL) | |
972 | return 0; | |
bd5635a1 | 973 | |
8af68e4e JK |
974 | val = (*bs->print_it) (bs); |
975 | if (val >= 0) | |
976 | return val; | |
977 | ||
fcb887ff JK |
978 | /* Maybe another breakpoint in the chain caused us to stop. |
979 | (Currently all watchpoints go on the bpstat whether hit or | |
980 | not. That probably could (should) be changed, provided care is taken | |
981 | with respect to bpstat_explains_signal). */ | |
982 | if (bs->next) | |
983 | return bpstat_print (bs->next); | |
984 | ||
cabd4da6 | 985 | /* We reached the end of the chain without printing anything. */ |
bd5635a1 RP |
986 | return 0; |
987 | } | |
988 | ||
989 | /* Evaluate the expression EXP and return 1 if value is zero. | |
990 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
bdbd5f50 | 991 | The argument is a "struct expression *" that has been cast to char * to |
bd5635a1 RP |
992 | make it pass through catch_errors. */ |
993 | ||
994 | static int | |
995 | breakpoint_cond_eval (exp) | |
bdbd5f50 | 996 | char *exp; |
bd5635a1 | 997 | { |
d3b9c0df | 998 | return !value_true (evaluate_expression ((struct expression *)exp)); |
bd5635a1 RP |
999 | } |
1000 | ||
1001 | /* Allocate a new bpstat and chain it to the current one. */ | |
1002 | ||
1003 | static bpstat | |
1004 | bpstat_alloc (b, cbs) | |
1005 | register struct breakpoint *b; | |
1006 | bpstat cbs; /* Current "bs" value */ | |
1007 | { | |
1008 | bpstat bs; | |
1009 | ||
1010 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
1011 | cbs->next = bs; | |
1012 | bs->breakpoint_at = b; | |
1013 | /* If the condition is false, etc., don't do the commands. */ | |
1014 | bs->commands = NULL; | |
bd5635a1 | 1015 | bs->old_val = NULL; |
8af68e4e | 1016 | bs->print_it = print_it_normal; |
bd5635a1 RP |
1017 | return bs; |
1018 | } | |
fa99ebe1 | 1019 | \f |
999dd04b | 1020 | |
bd5635a1 | 1021 | |
8af68e4e JK |
1022 | /* Possible return values for watchpoint_check (this can't be an enum |
1023 | because of check_errors). */ | |
999dd04b JL |
1024 | /* The watchpoint has been deleted. */ |
1025 | #define WP_DELETED 1 | |
8af68e4e JK |
1026 | /* The value has changed. */ |
1027 | #define WP_VALUE_CHANGED 2 | |
1028 | /* The value has not changed. */ | |
1029 | #define WP_VALUE_NOT_CHANGED 3 | |
1030 | ||
1031 | /* Check watchpoint condition. */ | |
1032 | static int | |
1033 | watchpoint_check (p) | |
fe675038 | 1034 | char *p; |
8af68e4e JK |
1035 | { |
1036 | bpstat bs = (bpstat) p; | |
999dd04b JL |
1037 | FRAME saved_frame, fr; |
1038 | int within_current_scope, saved_level; | |
1039 | ||
1040 | /* Save the current frame and level so we can restore it after | |
1041 | evaluating the watchpoint expression on its own frame. */ | |
1042 | saved_frame = selected_frame; | |
1043 | saved_level = selected_frame_level; | |
8af68e4e | 1044 | |
fa99ebe1 | 1045 | if (bs->breakpoint_at->exp_valid_block == NULL) |
8af68e4e | 1046 | within_current_scope = 1; |
fa99ebe1 JK |
1047 | else |
1048 | { | |
999dd04b JL |
1049 | fr = find_frame_addr_in_frame_chain (bs->breakpoint_at->watchpoint_frame); |
1050 | within_current_scope = (fr != NULL); | |
fa99ebe1 JK |
1051 | if (within_current_scope) |
1052 | /* If we end up stopping, the current frame will get selected | |
1053 | in normal_stop. So this call to select_frame won't affect | |
1054 | the user. */ | |
1055 | select_frame (fr, -1); | |
1056 | } | |
1057 | ||
8af68e4e JK |
1058 | if (within_current_scope) |
1059 | { | |
1060 | /* We use value_{,free_to_}mark because it could be a | |
1061 | *long* time before we return to the command level and | |
cef4c2e7 PS |
1062 | call free_all_values. We can't call free_all_values because |
1063 | we might be in the middle of evaluating a function call. */ | |
8af68e4e | 1064 | |
82a2edfb JK |
1065 | value_ptr mark = value_mark (); |
1066 | value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp); | |
8af68e4e JK |
1067 | if (!value_equal (bs->breakpoint_at->val, new_val)) |
1068 | { | |
1069 | release_value (new_val); | |
1070 | value_free_to_mark (mark); | |
1071 | bs->old_val = bs->breakpoint_at->val; | |
1072 | bs->breakpoint_at->val = new_val; | |
1073 | /* We will stop here */ | |
999dd04b | 1074 | select_frame (saved_frame, saved_level); |
8af68e4e JK |
1075 | return WP_VALUE_CHANGED; |
1076 | } | |
1077 | else | |
1078 | { | |
1079 | /* Nothing changed, don't do anything. */ | |
1080 | value_free_to_mark (mark); | |
1081 | /* We won't stop here */ | |
999dd04b | 1082 | select_frame (saved_frame, saved_level); |
8af68e4e JK |
1083 | return WP_VALUE_NOT_CHANGED; |
1084 | } | |
1085 | } | |
1086 | else | |
1087 | { | |
1088 | /* This seems like the only logical thing to do because | |
1089 | if we temporarily ignored the watchpoint, then when | |
1090 | we reenter the block in which it is valid it contains | |
1091 | garbage (in the case of a function, it may have two | |
1092 | garbage values, one before and one after the prologue). | |
1093 | So we can't even detect the first assignment to it and | |
1094 | watch after that (since the garbage may or may not equal | |
1095 | the first value assigned). */ | |
8af68e4e | 1096 | printf_filtered ("\ |
999dd04b | 1097 | Watchpoint %d deleted because the program has left the block in\n\ |
8af68e4e | 1098 | which its expression is valid.\n", bs->breakpoint_at->number); |
999dd04b JL |
1099 | if (bs->breakpoint_at->related_breakpoint) |
1100 | delete_breakpoint (bs->breakpoint_at->related_breakpoint); | |
1101 | delete_breakpoint (bs->breakpoint_at); | |
1102 | ||
1103 | select_frame (saved_frame, saved_level); | |
1104 | return WP_DELETED; | |
8af68e4e JK |
1105 | } |
1106 | } | |
1107 | ||
1108 | /* This is used when everything which needs to be printed has | |
1109 | already been printed. But we still want to print the frame. */ | |
1110 | static int | |
cabd4da6 | 1111 | print_it_done (bs) |
8af68e4e JK |
1112 | bpstat bs; |
1113 | { | |
1114 | return 0; | |
1115 | } | |
1116 | ||
cabd4da6 JK |
1117 | /* This is used when nothing should be printed for this bpstat entry. */ |
1118 | ||
1119 | static int | |
1120 | print_it_noop (bs) | |
1121 | bpstat bs; | |
1122 | { | |
1123 | return -1; | |
1124 | } | |
1125 | ||
cb6b0202 JK |
1126 | /* Get a bpstat associated with having just stopped at address *PC |
1127 | and frame address FRAME_ADDRESS. Update *PC to point at the | |
1128 | breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero | |
1129 | if this is known to not be a real breakpoint (it could still be a | |
1130 | watchpoint, though). */ | |
1131 | ||
bd5635a1 RP |
1132 | /* Determine whether we stopped at a breakpoint, etc, or whether we |
1133 | don't understand this stop. Result is a chain of bpstat's such that: | |
1134 | ||
1135 | if we don't understand the stop, the result is a null pointer. | |
1136 | ||
cb6b0202 | 1137 | if we understand why we stopped, the result is not null. |
bd5635a1 RP |
1138 | |
1139 | Each element of the chain refers to a particular breakpoint or | |
1140 | watchpoint at which we have stopped. (We may have stopped for | |
2d313932 | 1141 | several reasons concurrently.) |
bd5635a1 RP |
1142 | |
1143 | Each element of the chain has valid next, breakpoint_at, | |
1144 | commands, FIXME??? fields. | |
1145 | ||
1146 | */ | |
1147 | ||
bd5635a1 | 1148 | bpstat |
cb6b0202 | 1149 | bpstat_stop_status (pc, frame_address, not_a_breakpoint) |
bd5635a1 RP |
1150 | CORE_ADDR *pc; |
1151 | FRAME_ADDR frame_address; | |
cb6b0202 | 1152 | int not_a_breakpoint; |
bd5635a1 RP |
1153 | { |
1154 | register struct breakpoint *b; | |
bd5635a1 | 1155 | CORE_ADDR bp_addr; |
bdbd5f50 | 1156 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
bd5635a1 RP |
1157 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ |
1158 | int real_breakpoint = 0; | |
bdbd5f50 | 1159 | #endif |
bd5635a1 | 1160 | /* Root of the chain of bpstat's */ |
cba0d141 | 1161 | struct bpstat root_bs[1]; |
bd5635a1 RP |
1162 | /* Pointer to the last thing in the chain currently. */ |
1163 | bpstat bs = root_bs; | |
1164 | ||
1165 | /* Get the address where the breakpoint would have been. */ | |
1166 | bp_addr = *pc - DECR_PC_AFTER_BREAK; | |
1167 | ||
1168 | ALL_BREAKPOINTS (b) | |
1169 | { | |
bd5635a1 RP |
1170 | if (b->enable == disabled) |
1171 | continue; | |
30875e1c | 1172 | |
999dd04b JL |
1173 | if (b->type != bp_watchpoint |
1174 | && b->type != bp_hardware_watchpoint | |
1175 | && b->address != bp_addr) | |
bd5635a1 RP |
1176 | continue; |
1177 | ||
999dd04b JL |
1178 | if (b->type != bp_watchpoint |
1179 | && b->type != bp_hardware_watchpoint | |
1180 | && not_a_breakpoint) | |
cb6b0202 JK |
1181 | continue; |
1182 | ||
30875e1c SG |
1183 | /* Come here if it's a watchpoint, or if the break address matches */ |
1184 | ||
bd5635a1 RP |
1185 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ |
1186 | ||
cabd4da6 JK |
1187 | bs->stop = 1; |
1188 | bs->print = 1; | |
bd5635a1 | 1189 | |
999dd04b | 1190 | if (b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) |
bd5635a1 | 1191 | { |
8af68e4e JK |
1192 | static char message1[] = |
1193 | "Error evaluating expression for watchpoint %d\n"; | |
1194 | char message[sizeof (message1) + 30 /* slop */]; | |
1195 | sprintf (message, message1, b->number); | |
fe675038 JK |
1196 | switch (catch_errors (watchpoint_check, (char *) bs, message, |
1197 | RETURN_MASK_ALL)) | |
bd5635a1 | 1198 | { |
999dd04b | 1199 | case WP_DELETED: |
8af68e4e | 1200 | /* We've already printed what needs to be printed. */ |
cabd4da6 | 1201 | bs->print_it = print_it_done; |
8af68e4e JK |
1202 | /* Stop. */ |
1203 | break; | |
1204 | case WP_VALUE_CHANGED: | |
1205 | /* Stop. */ | |
1206 | break; | |
1207 | case WP_VALUE_NOT_CHANGED: | |
1208 | /* Don't stop. */ | |
cabd4da6 JK |
1209 | bs->print_it = print_it_noop; |
1210 | bs->stop = 0; | |
bd5635a1 | 1211 | continue; |
8af68e4e JK |
1212 | default: |
1213 | /* Can't happen. */ | |
1214 | /* FALLTHROUGH */ | |
1215 | case 0: | |
1216 | /* Error from catch_errors. */ | |
999dd04b JL |
1217 | printf_filtered ("Watchpoint %d deleted.\n", b->number); |
1218 | if (b->related_breakpoint) | |
1219 | delete_breakpoint (b->related_breakpoint); | |
1220 | delete_breakpoint (b); | |
8af68e4e | 1221 | /* We've already printed what needs to be printed. */ |
cabd4da6 | 1222 | bs->print_it = print_it_done; |
999dd04b | 1223 | |
8af68e4e JK |
1224 | /* Stop. */ |
1225 | break; | |
bd5635a1 RP |
1226 | } |
1227 | } | |
bdbd5f50 | 1228 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
bd5635a1 RP |
1229 | else |
1230 | real_breakpoint = 1; | |
bdbd5f50 | 1231 | #endif |
bd5635a1 RP |
1232 | |
1233 | if (b->frame && b->frame != frame_address) | |
cabd4da6 | 1234 | bs->stop = 0; |
bd5635a1 RP |
1235 | else |
1236 | { | |
fee933f1 | 1237 | int value_is_zero = 0; |
bd5635a1 RP |
1238 | |
1239 | if (b->cond) | |
1240 | { | |
1241 | /* Need to select the frame, with all that implies | |
1242 | so that the conditions will have the right context. */ | |
1243 | select_frame (get_current_frame (), 0); | |
bdbd5f50 JG |
1244 | value_is_zero |
1245 | = catch_errors (breakpoint_cond_eval, (char *)(b->cond), | |
fe675038 JK |
1246 | "Error in testing breakpoint condition:\n", |
1247 | RETURN_MASK_ALL); | |
06b6c733 | 1248 | /* FIXME-someday, should give breakpoint # */ |
bd5635a1 RP |
1249 | free_all_values (); |
1250 | } | |
bdbd5f50 | 1251 | if (b->cond && value_is_zero) |
bd5635a1 | 1252 | { |
cabd4da6 | 1253 | bs->stop = 0; |
bd5635a1 RP |
1254 | } |
1255 | else if (b->ignore_count > 0) | |
1256 | { | |
1257 | b->ignore_count--; | |
cabd4da6 | 1258 | bs->stop = 0; |
bd5635a1 RP |
1259 | } |
1260 | else | |
1261 | { | |
1262 | /* We will stop here */ | |
30875e1c | 1263 | if (b->disposition == disable) |
bd5635a1 RP |
1264 | b->enable = disabled; |
1265 | bs->commands = b->commands; | |
1266 | if (b->silent) | |
cabd4da6 | 1267 | bs->print = 0; |
2d313932 | 1268 | if (bs->commands && STREQ ("silent", bs->commands->line)) |
bd5635a1 RP |
1269 | { |
1270 | bs->commands = bs->commands->next; | |
cabd4da6 | 1271 | bs->print = 0; |
bd5635a1 RP |
1272 | } |
1273 | } | |
1274 | } | |
cabd4da6 JK |
1275 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
1276 | if (bs->stop == 0 || bs->print == 0) | |
1277 | bs->print_it = print_it_noop; | |
bd5635a1 RP |
1278 | } |
1279 | ||
1280 | bs->next = NULL; /* Terminate the chain */ | |
1281 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
cabd4da6 | 1282 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
bd5635a1 RP |
1283 | if (bs) |
1284 | { | |
bd5635a1 RP |
1285 | if (real_breakpoint) |
1286 | { | |
1287 | *pc = bp_addr; | |
1288 | #if defined (SHIFT_INST_REGS) | |
817ac7f8 | 1289 | SHIFT_INST_REGS(); |
bd5635a1 RP |
1290 | #else /* No SHIFT_INST_REGS. */ |
1291 | write_pc (bp_addr); | |
1292 | #endif /* No SHIFT_INST_REGS. */ | |
1293 | } | |
bd5635a1 | 1294 | } |
cabd4da6 | 1295 | #endif /* DECR_PC_AFTER_BREAK != 0. */ |
999dd04b JL |
1296 | |
1297 | /* The value of a hardware watchpoint hasn't changed, but the | |
1298 | intermediate memory locations we are watching may have. */ | |
1299 | if (bs && ! bs->stop | |
1300 | && bs->breakpoint_at->type == bp_hardware_watchpoint) | |
1301 | { | |
1302 | remove_breakpoints (); | |
1303 | insert_breakpoints (); | |
1304 | } | |
bd5635a1 RP |
1305 | return bs; |
1306 | } | |
cabd4da6 JK |
1307 | \f |
1308 | /* Tell what to do about this bpstat. */ | |
fe675038 | 1309 | struct bpstat_what |
cabd4da6 JK |
1310 | bpstat_what (bs) |
1311 | bpstat bs; | |
1312 | { | |
1313 | /* Classify each bpstat as one of the following. */ | |
1314 | enum class { | |
fe675038 JK |
1315 | /* This bpstat element has no effect on the main_action. */ |
1316 | no_effect = 0, | |
cabd4da6 JK |
1317 | |
1318 | /* There was a watchpoint, stop but don't print. */ | |
1319 | wp_silent, | |
1320 | ||
1321 | /* There was a watchpoint, stop and print. */ | |
1322 | wp_noisy, | |
1323 | ||
1324 | /* There was a breakpoint but we're not stopping. */ | |
1325 | bp_nostop, | |
1326 | ||
1327 | /* There was a breakpoint, stop but don't print. */ | |
1328 | bp_silent, | |
1329 | ||
1330 | /* There was a breakpoint, stop and print. */ | |
1331 | bp_noisy, | |
1332 | ||
1333 | /* We hit the longjmp breakpoint. */ | |
1334 | long_jump, | |
1335 | ||
1336 | /* We hit the longjmp_resume breakpoint. */ | |
1337 | long_resume, | |
1338 | ||
d7e7e851 JK |
1339 | /* We hit the step_resume breakpoint. */ |
1340 | step_resume, | |
1341 | ||
bcc37718 JK |
1342 | /* We hit the through_sigtramp breakpoint. */ |
1343 | through_sig, | |
1344 | ||
cabd4da6 JK |
1345 | /* This is just used to count how many enums there are. */ |
1346 | class_last | |
1347 | }; | |
1348 | ||
1349 | /* Here is the table which drives this routine. So that we can | |
1350 | format it pretty, we define some abbreviations for the | |
1351 | enum bpstat_what codes. */ | |
1352 | #define keep_c BPSTAT_WHAT_KEEP_CHECKING | |
1353 | #define stop_s BPSTAT_WHAT_STOP_SILENT | |
1354 | #define stop_n BPSTAT_WHAT_STOP_NOISY | |
1355 | #define single BPSTAT_WHAT_SINGLE | |
1356 | #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
1357 | #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
1358 | #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE | |
d7e7e851 | 1359 | #define sr BPSTAT_WHAT_STEP_RESUME |
bcc37718 | 1360 | #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP |
d7e7e851 | 1361 | |
cabd4da6 JK |
1362 | /* "Can't happen." Might want to print an error message. |
1363 | abort() is not out of the question, but chances are GDB is just | |
1364 | a bit confused, not unusable. */ | |
1365 | #define err BPSTAT_WHAT_STOP_NOISY | |
1366 | ||
1367 | /* Given an old action and a class, come up with a new action. */ | |
84d59861 JK |
1368 | /* One interesting property of this table is that wp_silent is the same |
1369 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
1370 | after stopping, the check for whether to step over a breakpoint | |
1371 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
1372 | reference to how we stopped. We retain separate wp_silent and bp_silent | |
1373 | codes in case we want to change that someday. */ | |
d7e7e851 JK |
1374 | |
1375 | /* step_resume entries: a step resume breakpoint overrides another | |
1376 | breakpoint of signal handling (see comment in wait_for_inferior | |
1377 | at first IN_SIGTRAMP where we set the step_resume breakpoint). */ | |
bcc37718 JK |
1378 | /* We handle the through_sigtramp_breakpoint the same way; having both |
1379 | one of those and a step_resume_breakpoint is probably very rare (?). */ | |
d7e7e851 | 1380 | |
fe675038 | 1381 | static const enum bpstat_what_main_action |
cabd4da6 JK |
1382 | table[(int)class_last][(int)BPSTAT_WHAT_LAST] = |
1383 | { | |
1384 | /* old action */ | |
bcc37718 JK |
1385 | /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts |
1386 | */ | |
1387 | /*no_effect*/ {keep_c,stop_s,stop_n,single, setlr , clrlr , clrlrs, sr, ts}, | |
1388 | /*wp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts}, | |
1389 | /*wp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts}, | |
1390 | /*bp_nostop*/ {single,stop_s,stop_n,single, setlr , clrlrs, clrlrs, sr, ts}, | |
1391 | /*bp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts}, | |
1392 | /*bp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts}, | |
1393 | /*long_jump*/ {setlr ,stop_s,stop_n,setlr , err , err , err , sr, ts}, | |
1394 | /*long_resume*/ {clrlr ,stop_s,stop_n,clrlrs, err , err , err , sr, ts}, | |
1395 | /*step_resume*/ {sr ,sr ,sr ,sr , sr , sr , sr , sr, ts}, | |
1396 | /*through_sig*/ {ts ,ts ,ts ,ts , ts , ts , ts , ts, ts} | |
cabd4da6 JK |
1397 | }; |
1398 | #undef keep_c | |
1399 | #undef stop_s | |
1400 | #undef stop_n | |
1401 | #undef single | |
1402 | #undef setlr | |
1403 | #undef clrlr | |
1404 | #undef clrlrs | |
1405 | #undef err | |
bcc37718 JK |
1406 | #undef sr |
1407 | #undef ts | |
fe675038 | 1408 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
84d59861 | 1409 | struct bpstat_what retval; |
cabd4da6 | 1410 | |
cef4c2e7 | 1411 | retval.call_dummy = 0; |
cabd4da6 JK |
1412 | for (; bs != NULL; bs = bs->next) |
1413 | { | |
fee933f1 | 1414 | enum class bs_class = no_effect; |
cabd4da6 JK |
1415 | if (bs->breakpoint_at == NULL) |
1416 | /* I suspect this can happen if it was a momentary breakpoint | |
1417 | which has since been deleted. */ | |
1418 | continue; | |
1419 | switch (bs->breakpoint_at->type) | |
1420 | { | |
1421 | case bp_breakpoint: | |
1422 | case bp_until: | |
1423 | case bp_finish: | |
1424 | if (bs->stop) | |
1425 | { | |
1426 | if (bs->print) | |
1427 | bs_class = bp_noisy; | |
1428 | else | |
1429 | bs_class = bp_silent; | |
1430 | } | |
1431 | else | |
1432 | bs_class = bp_nostop; | |
1433 | break; | |
1434 | case bp_watchpoint: | |
999dd04b | 1435 | case bp_hardware_watchpoint: |
cabd4da6 JK |
1436 | if (bs->stop) |
1437 | { | |
1438 | if (bs->print) | |
1439 | bs_class = wp_noisy; | |
1440 | else | |
1441 | bs_class = wp_silent; | |
1442 | } | |
1443 | else | |
fe675038 JK |
1444 | /* There was a watchpoint, but we're not stopping. This requires |
1445 | no further action. */ | |
1446 | bs_class = no_effect; | |
cabd4da6 JK |
1447 | break; |
1448 | case bp_longjmp: | |
1449 | bs_class = long_jump; | |
1450 | break; | |
1451 | case bp_longjmp_resume: | |
1452 | bs_class = long_resume; | |
1453 | break; | |
fe675038 | 1454 | case bp_step_resume: |
fe675038 JK |
1455 | if (bs->stop) |
1456 | { | |
d7e7e851 | 1457 | bs_class = step_resume; |
fe675038 JK |
1458 | } |
1459 | else | |
1460 | /* It is for the wrong frame. */ | |
1461 | bs_class = bp_nostop; | |
bcc37718 JK |
1462 | break; |
1463 | case bp_through_sigtramp: | |
1464 | bs_class = through_sig; | |
fe675038 | 1465 | break; |
999dd04b JL |
1466 | case bp_watchpoint_scope: |
1467 | bs_class = bp_nostop; | |
1468 | break; | |
1469 | ||
84d59861 JK |
1470 | case bp_call_dummy: |
1471 | /* Make sure the action is stop (silent or noisy), so infrun.c | |
1472 | pops the dummy frame. */ | |
1473 | bs_class = bp_silent; | |
1474 | retval.call_dummy = 1; | |
bb7b3800 | 1475 | break; |
cabd4da6 JK |
1476 | } |
1477 | current_action = table[(int)bs_class][(int)current_action]; | |
1478 | } | |
84d59861 JK |
1479 | retval.main_action = current_action; |
1480 | return retval; | |
cabd4da6 | 1481 | } |
bd5635a1 | 1482 | |
30875e1c SG |
1483 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
1484 | without hardware support). This isn't related to a specific bpstat, | |
1485 | just to things like whether watchpoints are set. */ | |
1486 | ||
bd5635a1 RP |
1487 | int |
1488 | bpstat_should_step () | |
1489 | { | |
1490 | struct breakpoint *b; | |
1491 | ALL_BREAKPOINTS (b) | |
30875e1c | 1492 | if (b->enable == enabled && b->type == bp_watchpoint) |
bd5635a1 RP |
1493 | return 1; |
1494 | return 0; | |
1495 | } | |
1496 | \f | |
1497 | /* Print information on breakpoint number BNUM, or -1 if all. | |
1498 | If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS | |
1499 | is nonzero, process only watchpoints. */ | |
1500 | ||
1501 | static void | |
c8950965 | 1502 | breakpoint_1 (bnum, allflag) |
bd5635a1 | 1503 | int bnum; |
80ba48f5 | 1504 | int allflag; |
bd5635a1 RP |
1505 | { |
1506 | register struct breakpoint *b; | |
1507 | register struct command_line *l; | |
1508 | register struct symbol *sym; | |
1509 | CORE_ADDR last_addr = (CORE_ADDR)-1; | |
30875e1c SG |
1510 | int found_a_breakpoint = 0; |
1511 | static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint", | |
999dd04b JL |
1512 | "hardware watchpoint", "longjmp", |
1513 | "longjmp resume", "step resume", | |
1514 | "watchpoint scope", "call dummy" }; | |
80ba48f5 | 1515 | static char *bpdisps[] = {"del", "dis", "keep"}; |
30875e1c | 1516 | static char bpenables[] = "ny"; |
0a62ff36 | 1517 | char wrap_indent[80]; |
30875e1c | 1518 | |
bd5635a1 | 1519 | ALL_BREAKPOINTS (b) |
30875e1c SG |
1520 | if (bnum == -1 |
1521 | || bnum == b->number) | |
bd5635a1 | 1522 | { |
80ba48f5 SG |
1523 | /* We only print out user settable breakpoints unless the allflag is set. */ |
1524 | if (!allflag | |
1525 | && b->type != bp_breakpoint | |
999dd04b JL |
1526 | && b->type != bp_watchpoint |
1527 | && b->type != bp_hardware_watchpoint) | |
80ba48f5 SG |
1528 | continue; |
1529 | ||
30875e1c | 1530 | if (!found_a_breakpoint++) |
47ebe8fd | 1531 | { |
20b3c1aa JK |
1532 | annotate_breakpoints_headers (); |
1533 | ||
1c95d7ab | 1534 | annotate_field (0); |
47ebe8fd | 1535 | printf_filtered ("Num "); |
1c95d7ab | 1536 | annotate_field (1); |
47ebe8fd | 1537 | printf_filtered ("Type "); |
1c95d7ab | 1538 | annotate_field (2); |
47ebe8fd | 1539 | printf_filtered ("Disp "); |
1c95d7ab | 1540 | annotate_field (3); |
47ebe8fd JK |
1541 | printf_filtered ("Enb "); |
1542 | if (addressprint) | |
1543 | { | |
1c95d7ab | 1544 | annotate_field (4); |
47ebe8fd JK |
1545 | printf_filtered ("Address "); |
1546 | } | |
1c95d7ab | 1547 | annotate_field (5); |
47ebe8fd JK |
1548 | printf_filtered ("What\n"); |
1549 | ||
1c95d7ab | 1550 | annotate_breakpoints_table (); |
47ebe8fd JK |
1551 | } |
1552 | ||
1c95d7ab JK |
1553 | annotate_record (); |
1554 | annotate_field (0); | |
47ebe8fd | 1555 | printf_filtered ("%-3d ", b->number); |
1c95d7ab | 1556 | annotate_field (1); |
47ebe8fd | 1557 | printf_filtered ("%-14s ", bptypes[(int)b->type]); |
1c95d7ab | 1558 | annotate_field (2); |
47ebe8fd | 1559 | printf_filtered ("%-4s ", bpdisps[(int)b->disposition]); |
1c95d7ab | 1560 | annotate_field (3); |
47ebe8fd JK |
1561 | printf_filtered ("%-3c ", bpenables[(int)b->enable]); |
1562 | ||
0a62ff36 JK |
1563 | strcpy (wrap_indent, " "); |
1564 | if (addressprint) | |
1565 | strcat (wrap_indent, " "); | |
30875e1c | 1566 | switch (b->type) |
bd5635a1 | 1567 | { |
30875e1c | 1568 | case bp_watchpoint: |
999dd04b | 1569 | case bp_hardware_watchpoint: |
47ebe8fd JK |
1570 | /* Field 4, the address, is omitted (which makes the columns |
1571 | not line up too nicely with the headers, but the effect | |
1572 | is relatively readable). */ | |
1c95d7ab | 1573 | annotate_field (5); |
199b2450 | 1574 | print_expression (b->exp, gdb_stdout); |
30875e1c | 1575 | break; |
84d59861 | 1576 | |
30875e1c | 1577 | case bp_breakpoint: |
80ba48f5 SG |
1578 | case bp_until: |
1579 | case bp_finish: | |
1580 | case bp_longjmp: | |
1581 | case bp_longjmp_resume: | |
84d59861 | 1582 | case bp_step_resume: |
bcc37718 | 1583 | case bp_through_sigtramp: |
999dd04b | 1584 | case bp_watchpoint_scope: |
bb7b3800 | 1585 | case bp_call_dummy: |
bd5635a1 | 1586 | if (addressprint) |
47ebe8fd | 1587 | { |
1c95d7ab | 1588 | annotate_field (4); |
47ebe8fd JK |
1589 | /* FIXME-32x64: need a print_address_numeric with |
1590 | field width */ | |
1591 | printf_filtered | |
1592 | ("%s ", | |
1593 | local_hex_string_custom | |
1594 | ((unsigned long) b->address, "08l")); | |
1595 | } | |
1596 | ||
1c95d7ab | 1597 | annotate_field (5); |
bd5635a1 RP |
1598 | |
1599 | last_addr = b->address; | |
d889f6b7 | 1600 | if (b->source_file) |
bd5635a1 RP |
1601 | { |
1602 | sym = find_pc_function (b->address); | |
1603 | if (sym) | |
1604 | { | |
199b2450 TL |
1605 | fputs_filtered ("in ", gdb_stdout); |
1606 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout); | |
0a62ff36 | 1607 | wrap_here (wrap_indent); |
199b2450 | 1608 | fputs_filtered (" at ", gdb_stdout); |
bd5635a1 | 1609 | } |
199b2450 | 1610 | fputs_filtered (b->source_file, gdb_stdout); |
bd5635a1 RP |
1611 | printf_filtered (":%d", b->line_number); |
1612 | } | |
1613 | else | |
199b2450 | 1614 | print_address_symbolic (b->address, gdb_stdout, demangle, " "); |
fee933f1 | 1615 | break; |
bd5635a1 RP |
1616 | } |
1617 | ||
1618 | printf_filtered ("\n"); | |
1619 | ||
1620 | if (b->frame) | |
833e0d94 | 1621 | { |
1c95d7ab | 1622 | annotate_field (6); |
47ebe8fd | 1623 | |
833e0d94 | 1624 | printf_filtered ("\tstop only in stack frame at "); |
d24c0599 | 1625 | print_address_numeric (b->frame, 1, gdb_stdout); |
833e0d94 | 1626 | printf_filtered ("\n"); |
bcc37718 | 1627 | } |
47ebe8fd | 1628 | |
bd5635a1 RP |
1629 | if (b->cond) |
1630 | { | |
1c95d7ab | 1631 | annotate_field (7); |
47ebe8fd | 1632 | |
bd5635a1 | 1633 | printf_filtered ("\tstop only if "); |
199b2450 | 1634 | print_expression (b->cond, gdb_stdout); |
bd5635a1 RP |
1635 | printf_filtered ("\n"); |
1636 | } | |
47ebe8fd | 1637 | |
bd5635a1 | 1638 | if (b->ignore_count) |
47ebe8fd | 1639 | { |
1c95d7ab | 1640 | annotate_field (8); |
47ebe8fd JK |
1641 | |
1642 | printf_filtered ("\tignore next %d hits\n", b->ignore_count); | |
1643 | } | |
1644 | ||
bd5635a1 | 1645 | if ((l = b->commands)) |
47ebe8fd | 1646 | { |
1c95d7ab | 1647 | annotate_field (9); |
47ebe8fd JK |
1648 | |
1649 | while (l) | |
1650 | { | |
1651 | fputs_filtered ("\t", gdb_stdout); | |
1652 | fputs_filtered (l->line, gdb_stdout); | |
1653 | fputs_filtered ("\n", gdb_stdout); | |
1654 | l = l->next; | |
1655 | } | |
1656 | } | |
bd5635a1 RP |
1657 | } |
1658 | ||
fee933f1 RP |
1659 | if (!found_a_breakpoint) |
1660 | { | |
1661 | if (bnum == -1) | |
1662 | printf_filtered ("No breakpoints or watchpoints.\n"); | |
1663 | else | |
1664 | printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum); | |
1665 | } | |
30875e1c SG |
1666 | else |
1667 | /* Compare against (CORE_ADDR)-1 in case some compiler decides | |
1668 | that a comparison of an unsigned with -1 is always false. */ | |
1669 | if (last_addr != (CORE_ADDR)-1) | |
1670 | set_next_address (last_addr); | |
47ebe8fd | 1671 | |
1c95d7ab | 1672 | annotate_breakpoints_table_end (); |
bd5635a1 RP |
1673 | } |
1674 | ||
bdbd5f50 | 1675 | /* ARGSUSED */ |
bd5635a1 RP |
1676 | static void |
1677 | breakpoints_info (bnum_exp, from_tty) | |
1678 | char *bnum_exp; | |
1679 | int from_tty; | |
1680 | { | |
1681 | int bnum = -1; | |
1682 | ||
1683 | if (bnum_exp) | |
1684 | bnum = parse_and_eval_address (bnum_exp); | |
1685 | ||
c8950965 | 1686 | breakpoint_1 (bnum, 0); |
80ba48f5 SG |
1687 | } |
1688 | ||
9b280a7f JG |
1689 | #if MAINTENANCE_CMDS |
1690 | ||
80ba48f5 SG |
1691 | /* ARGSUSED */ |
1692 | static void | |
9b280a7f | 1693 | maintenance_info_breakpoints (bnum_exp, from_tty) |
80ba48f5 SG |
1694 | char *bnum_exp; |
1695 | int from_tty; | |
1696 | { | |
1697 | int bnum = -1; | |
1698 | ||
1699 | if (bnum_exp) | |
1700 | bnum = parse_and_eval_address (bnum_exp); | |
1701 | ||
c8950965 | 1702 | breakpoint_1 (bnum, 1); |
bd5635a1 RP |
1703 | } |
1704 | ||
9b280a7f JG |
1705 | #endif |
1706 | ||
bd5635a1 RP |
1707 | /* Print a message describing any breakpoints set at PC. */ |
1708 | ||
1709 | static void | |
1710 | describe_other_breakpoints (pc) | |
1711 | register CORE_ADDR pc; | |
1712 | { | |
1713 | register int others = 0; | |
1714 | register struct breakpoint *b; | |
1715 | ||
1716 | ALL_BREAKPOINTS (b) | |
1717 | if (b->address == pc) | |
1718 | others++; | |
1719 | if (others > 0) | |
1720 | { | |
833e0d94 | 1721 | printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : ""); |
bd5635a1 RP |
1722 | ALL_BREAKPOINTS (b) |
1723 | if (b->address == pc) | |
1724 | { | |
1725 | others--; | |
833e0d94 JK |
1726 | printf_filtered |
1727 | ("%d%s%s ", | |
1728 | b->number, | |
1729 | (b->enable == disabled) ? " (disabled)" : "", | |
1730 | (others > 1) ? "," : ((others == 1) ? " and" : "")); | |
bd5635a1 | 1731 | } |
833e0d94 | 1732 | printf_filtered ("also set at pc "); |
d24c0599 | 1733 | print_address_numeric (pc, 1, gdb_stdout); |
833e0d94 | 1734 | printf_filtered (".\n"); |
bd5635a1 RP |
1735 | } |
1736 | } | |
1737 | \f | |
1738 | /* Set the default place to put a breakpoint | |
1739 | for the `break' command with no arguments. */ | |
1740 | ||
1741 | void | |
1742 | set_default_breakpoint (valid, addr, symtab, line) | |
1743 | int valid; | |
1744 | CORE_ADDR addr; | |
1745 | struct symtab *symtab; | |
1746 | int line; | |
1747 | { | |
1748 | default_breakpoint_valid = valid; | |
1749 | default_breakpoint_address = addr; | |
1750 | default_breakpoint_symtab = symtab; | |
1751 | default_breakpoint_line = line; | |
1752 | } | |
1753 | ||
1754 | /* Rescan breakpoints at address ADDRESS, | |
1755 | marking the first one as "first" and any others as "duplicates". | |
1756 | This is so that the bpt instruction is only inserted once. */ | |
1757 | ||
1758 | static void | |
1759 | check_duplicates (address) | |
1760 | CORE_ADDR address; | |
1761 | { | |
1762 | register struct breakpoint *b; | |
1763 | register int count = 0; | |
1764 | ||
30875e1c | 1765 | if (address == 0) /* Watchpoints are uninteresting */ |
f266e564 JK |
1766 | return; |
1767 | ||
bd5635a1 RP |
1768 | ALL_BREAKPOINTS (b) |
1769 | if (b->enable != disabled && b->address == address) | |
1770 | { | |
1771 | count++; | |
1772 | b->duplicate = count > 1; | |
1773 | } | |
1774 | } | |
1775 | ||
1776 | /* Low level routine to set a breakpoint. | |
1777 | Takes as args the three things that every breakpoint must have. | |
1778 | Returns the breakpoint object so caller can set other things. | |
1779 | Does not set the breakpoint number! | |
f266e564 JK |
1780 | Does not print anything. |
1781 | ||
1782 | ==> This routine should not be called if there is a chance of later | |
1783 | error(); otherwise it leaves a bogus breakpoint on the chain. Validate | |
1784 | your arguments BEFORE calling this routine! */ | |
bd5635a1 RP |
1785 | |
1786 | static struct breakpoint * | |
1787 | set_raw_breakpoint (sal) | |
1788 | struct symtab_and_line sal; | |
1789 | { | |
1790 | register struct breakpoint *b, *b1; | |
1791 | ||
1792 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4ed3a9ea | 1793 | memset (b, 0, sizeof (*b)); |
bd5635a1 | 1794 | b->address = sal.pc; |
d889f6b7 JK |
1795 | if (sal.symtab == NULL) |
1796 | b->source_file = NULL; | |
1797 | else | |
1798 | b->source_file = savestring (sal.symtab->filename, | |
1799 | strlen (sal.symtab->filename)); | |
199b2450 | 1800 | b->thread = -1; |
bd5635a1 RP |
1801 | b->line_number = sal.line; |
1802 | b->enable = enabled; | |
1803 | b->next = 0; | |
1804 | b->silent = 0; | |
1805 | b->ignore_count = 0; | |
1806 | b->commands = NULL; | |
30875e1c | 1807 | b->frame = 0; |
bd5635a1 RP |
1808 | |
1809 | /* Add this breakpoint to the end of the chain | |
1810 | so that a list of breakpoints will come out in order | |
1811 | of increasing numbers. */ | |
1812 | ||
1813 | b1 = breakpoint_chain; | |
1814 | if (b1 == 0) | |
1815 | breakpoint_chain = b; | |
1816 | else | |
1817 | { | |
1818 | while (b1->next) | |
1819 | b1 = b1->next; | |
1820 | b1->next = b; | |
1821 | } | |
1822 | ||
1823 | check_duplicates (sal.pc); | |
6c803036 | 1824 | breakpoints_changed (); |
bd5635a1 RP |
1825 | |
1826 | return b; | |
1827 | } | |
1828 | ||
30875e1c | 1829 | static void |
80ba48f5 | 1830 | create_longjmp_breakpoint(func_name) |
30875e1c | 1831 | char *func_name; |
30875e1c | 1832 | { |
30875e1c SG |
1833 | struct symtab_and_line sal; |
1834 | struct breakpoint *b; | |
80ba48f5 | 1835 | static int internal_breakpoint_number = -1; |
30875e1c | 1836 | |
30875e1c SG |
1837 | if (func_name != NULL) |
1838 | { | |
1839 | struct minimal_symbol *m; | |
1840 | ||
1841 | m = lookup_minimal_symbol(func_name, (struct objfile *)NULL); | |
1842 | if (m) | |
2d313932 | 1843 | sal.pc = SYMBOL_VALUE_ADDRESS (m); |
30875e1c SG |
1844 | else |
1845 | return; | |
1846 | } | |
1847 | else | |
1848 | sal.pc = 0; | |
1849 | ||
1850 | sal.symtab = NULL; | |
1851 | sal.line = 0; | |
30875e1c | 1852 | |
80ba48f5 | 1853 | b = set_raw_breakpoint(sal); |
30875e1c SG |
1854 | if (!b) return; |
1855 | ||
80ba48f5 | 1856 | b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume; |
30875e1c SG |
1857 | b->disposition = donttouch; |
1858 | b->enable = disabled; | |
1859 | b->silent = 1; | |
80ba48f5 SG |
1860 | if (func_name) |
1861 | b->addr_string = strsave(func_name); | |
1862 | b->number = internal_breakpoint_number--; | |
30875e1c | 1863 | } |
30875e1c SG |
1864 | |
1865 | /* Call this routine when stepping and nexting to enable a breakpoint if we do | |
1866 | a longjmp(). When we hit that breakpoint, call | |
1867 | set_longjmp_resume_breakpoint() to figure out where we are going. */ | |
1868 | ||
1869 | void | |
1870 | enable_longjmp_breakpoint() | |
1871 | { | |
80ba48f5 SG |
1872 | register struct breakpoint *b; |
1873 | ||
1874 | ALL_BREAKPOINTS (b) | |
1875 | if (b->type == bp_longjmp) | |
9b280a7f JG |
1876 | { |
1877 | b->enable = enabled; | |
1878 | check_duplicates (b->address); | |
1879 | } | |
30875e1c SG |
1880 | } |
1881 | ||
1882 | void | |
1883 | disable_longjmp_breakpoint() | |
1884 | { | |
80ba48f5 SG |
1885 | register struct breakpoint *b; |
1886 | ||
1887 | ALL_BREAKPOINTS (b) | |
9b280a7f | 1888 | if ( b->type == bp_longjmp |
80ba48f5 | 1889 | || b->type == bp_longjmp_resume) |
9b280a7f JG |
1890 | { |
1891 | b->enable = disabled; | |
1892 | check_duplicates (b->address); | |
1893 | } | |
30875e1c SG |
1894 | } |
1895 | ||
1896 | /* Call this after hitting the longjmp() breakpoint. Use this to set a new | |
1897 | breakpoint at the target of the jmp_buf. | |
80ba48f5 SG |
1898 | |
1899 | FIXME - This ought to be done by setting a temporary breakpoint that gets | |
1900 | deleted automatically... | |
30875e1c SG |
1901 | */ |
1902 | ||
1903 | void | |
1904 | set_longjmp_resume_breakpoint(pc, frame) | |
1905 | CORE_ADDR pc; | |
1906 | FRAME frame; | |
1907 | { | |
80ba48f5 SG |
1908 | register struct breakpoint *b; |
1909 | ||
1910 | ALL_BREAKPOINTS (b) | |
1911 | if (b->type == bp_longjmp_resume) | |
1912 | { | |
1913 | b->address = pc; | |
1914 | b->enable = enabled; | |
1915 | if (frame != NULL) | |
1916 | b->frame = FRAME_FP(frame); | |
1917 | else | |
1918 | b->frame = 0; | |
9b280a7f | 1919 | check_duplicates (b->address); |
80ba48f5 SG |
1920 | return; |
1921 | } | |
30875e1c SG |
1922 | } |
1923 | ||
bd5635a1 RP |
1924 | /* Set a breakpoint that will evaporate an end of command |
1925 | at address specified by SAL. | |
1926 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
1927 | ||
30875e1c SG |
1928 | struct breakpoint * |
1929 | set_momentary_breakpoint (sal, frame, type) | |
bd5635a1 RP |
1930 | struct symtab_and_line sal; |
1931 | FRAME frame; | |
30875e1c | 1932 | enum bptype type; |
bd5635a1 RP |
1933 | { |
1934 | register struct breakpoint *b; | |
1935 | b = set_raw_breakpoint (sal); | |
30875e1c SG |
1936 | b->type = type; |
1937 | b->enable = enabled; | |
1938 | b->disposition = donttouch; | |
bd5635a1 | 1939 | b->frame = (frame ? FRAME_FP (frame) : 0); |
30875e1c | 1940 | return b; |
bd5635a1 RP |
1941 | } |
1942 | ||
30875e1c | 1943 | #if 0 |
bd5635a1 RP |
1944 | void |
1945 | clear_momentary_breakpoints () | |
1946 | { | |
1947 | register struct breakpoint *b; | |
1948 | ALL_BREAKPOINTS (b) | |
30875e1c | 1949 | if (b->disposition == delete) |
bd5635a1 RP |
1950 | { |
1951 | delete_breakpoint (b); | |
1952 | break; | |
1953 | } | |
1954 | } | |
30875e1c | 1955 | #endif |
bd5635a1 RP |
1956 | \f |
1957 | /* Tell the user we have just set a breakpoint B. */ | |
1958 | static void | |
1959 | mention (b) | |
1960 | struct breakpoint *b; | |
1961 | { | |
30875e1c | 1962 | switch (b->type) |
bd5635a1 | 1963 | { |
30875e1c | 1964 | case bp_watchpoint: |
bd5635a1 | 1965 | printf_filtered ("Watchpoint %d: ", b->number); |
199b2450 | 1966 | print_expression (b->exp, gdb_stdout); |
30875e1c | 1967 | break; |
999dd04b JL |
1968 | case bp_hardware_watchpoint: |
1969 | printf_filtered ("Hardware watchpoint %d: ", b->number); | |
1970 | print_expression (b->exp, gdb_stdout); | |
1971 | break; | |
30875e1c | 1972 | case bp_breakpoint: |
833e0d94 | 1973 | printf_filtered ("Breakpoint %d at ", b->number); |
d24c0599 | 1974 | print_address_numeric (b->address, 1, gdb_stdout); |
d889f6b7 | 1975 | if (b->source_file) |
bd5635a1 | 1976 | printf_filtered (": file %s, line %d.", |
d889f6b7 | 1977 | b->source_file, b->line_number); |
51b57ded FF |
1978 | break; |
1979 | case bp_until: | |
1980 | case bp_finish: | |
1981 | case bp_longjmp: | |
1982 | case bp_longjmp_resume: | |
fee933f1 | 1983 | case bp_step_resume: |
bcc37718 | 1984 | case bp_through_sigtramp: |
199b2450 | 1985 | case bp_call_dummy: |
999dd04b | 1986 | case bp_watchpoint_scope: |
51b57ded | 1987 | break; |
bd5635a1 RP |
1988 | } |
1989 | printf_filtered ("\n"); | |
1990 | } | |
1991 | ||
1992 | #if 0 | |
1993 | /* Nobody calls this currently. */ | |
1994 | /* Set a breakpoint from a symtab and line. | |
1995 | If TEMPFLAG is nonzero, it is a temporary breakpoint. | |
1996 | ADDR_STRING is a malloc'd string holding the name of where we are | |
1997 | setting the breakpoint. This is used later to re-set it after the | |
1998 | program is relinked and symbols are reloaded. | |
1999 | Print the same confirmation messages that the breakpoint command prints. */ | |
2000 | ||
2001 | void | |
2002 | set_breakpoint (s, line, tempflag, addr_string) | |
2003 | struct symtab *s; | |
2004 | int line; | |
2005 | int tempflag; | |
2006 | char *addr_string; | |
2007 | { | |
2008 | register struct breakpoint *b; | |
2009 | struct symtab_and_line sal; | |
2010 | ||
2011 | sal.symtab = s; | |
2012 | sal.line = line; | |
30875e1c SG |
2013 | sal.pc = 0; |
2014 | resolve_sal_pc (&sal); /* Might error out */ | |
2015 | describe_other_breakpoints (sal.pc); | |
bd5635a1 | 2016 | |
30875e1c SG |
2017 | b = set_raw_breakpoint (sal); |
2018 | set_breakpoint_count (breakpoint_count + 1); | |
2019 | b->number = breakpoint_count; | |
2020 | b->type = bp_breakpoint; | |
2021 | b->cond = 0; | |
2022 | b->addr_string = addr_string; | |
2023 | b->enable = enabled; | |
2024 | b->disposition = tempflag ? delete : donttouch; | |
bd5635a1 | 2025 | |
30875e1c | 2026 | mention (b); |
bd5635a1 | 2027 | } |
30875e1c | 2028 | #endif /* 0 */ |
bd5635a1 RP |
2029 | \f |
2030 | /* Set a breakpoint according to ARG (function, linenum or *address) | |
2031 | and make it temporary if TEMPFLAG is nonzero. */ | |
2032 | ||
2033 | static void | |
2034 | break_command_1 (arg, tempflag, from_tty) | |
2035 | char *arg; | |
2036 | int tempflag, from_tty; | |
2037 | { | |
2038 | struct symtabs_and_lines sals; | |
2039 | struct symtab_and_line sal; | |
2040 | register struct expression *cond = 0; | |
2041 | register struct breakpoint *b; | |
2042 | ||
2043 | /* Pointers in arg to the start, and one past the end, of the condition. */ | |
2044 | char *cond_start = NULL; | |
fee933f1 | 2045 | char *cond_end = NULL; |
bd5635a1 RP |
2046 | /* Pointers in arg to the start, and one past the end, |
2047 | of the address part. */ | |
2048 | char *addr_start = NULL; | |
fee933f1 | 2049 | char *addr_end = NULL; |
d889f6b7 | 2050 | struct cleanup *old_chain; |
fee933f1 | 2051 | struct cleanup *canonical_strings_chain = NULL; |
d889f6b7 | 2052 | char **canonical = (char **)NULL; |
bd5635a1 | 2053 | int i; |
199b2450 | 2054 | int thread; |
bd5635a1 RP |
2055 | |
2056 | sals.sals = NULL; | |
2057 | sals.nelts = 0; | |
2058 | ||
2059 | sal.line = sal.pc = sal.end = 0; | |
2060 | sal.symtab = 0; | |
2061 | ||
2062 | /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ | |
2063 | ||
2064 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' | |
2065 | && (arg[2] == ' ' || arg[2] == '\t'))) | |
2066 | { | |
2067 | if (default_breakpoint_valid) | |
2068 | { | |
2069 | sals.sals = (struct symtab_and_line *) | |
2070 | xmalloc (sizeof (struct symtab_and_line)); | |
2071 | sal.pc = default_breakpoint_address; | |
2072 | sal.line = default_breakpoint_line; | |
2073 | sal.symtab = default_breakpoint_symtab; | |
2074 | sals.sals[0] = sal; | |
2075 | sals.nelts = 1; | |
2076 | } | |
2077 | else | |
2078 | error ("No default breakpoint address now."); | |
2079 | } | |
2080 | else | |
2081 | { | |
2082 | addr_start = arg; | |
2083 | ||
2084 | /* Force almost all breakpoints to be in terms of the | |
2085 | current_source_symtab (which is decode_line_1's default). This | |
2086 | should produce the results we want almost all of the time while | |
2087 | leaving default_breakpoint_* alone. */ | |
2088 | if (default_breakpoint_valid | |
2089 | && (!current_source_symtab | |
2090 | || (arg && (*arg == '+' || *arg == '-')))) | |
2091 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
d889f6b7 | 2092 | default_breakpoint_line, &canonical); |
bd5635a1 | 2093 | else |
d889f6b7 | 2094 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical); |
bd5635a1 RP |
2095 | |
2096 | addr_end = arg; | |
2097 | } | |
2098 | ||
2099 | if (! sals.nelts) | |
2100 | return; | |
2101 | ||
d889f6b7 JK |
2102 | /* Make sure that all storage allocated in decode_line_1 gets freed in case |
2103 | the following `for' loop errors out. */ | |
2104 | old_chain = make_cleanup (free, sals.sals); | |
2105 | if (canonical != (char **)NULL) | |
2106 | { | |
2107 | make_cleanup (free, canonical); | |
2108 | canonical_strings_chain = make_cleanup (null_cleanup, 0); | |
2109 | for (i = 0; i < sals.nelts; i++) | |
2110 | { | |
2111 | if (canonical[i] != NULL) | |
2112 | make_cleanup (free, canonical[i]); | |
2113 | } | |
2114 | } | |
2115 | ||
199b2450 TL |
2116 | thread = -1; /* No specific thread yet */ |
2117 | ||
30875e1c SG |
2118 | /* Resolve all line numbers to PC's, and verify that conditions |
2119 | can be parsed, before setting any breakpoints. */ | |
bd5635a1 RP |
2120 | for (i = 0; i < sals.nelts; i++) |
2121 | { | |
199b2450 TL |
2122 | char *tok, *end_tok; |
2123 | int toklen; | |
2124 | ||
30875e1c | 2125 | resolve_sal_pc (&sals.sals[i]); |
bd5635a1 | 2126 | |
199b2450 TL |
2127 | tok = arg; |
2128 | ||
2129 | while (tok && *tok) | |
bd5635a1 | 2130 | { |
199b2450 TL |
2131 | while (*tok == ' ' || *tok == '\t') |
2132 | tok++; | |
2133 | ||
2134 | end_tok = tok; | |
2135 | ||
2136 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
2137 | end_tok++; | |
2138 | ||
2139 | toklen = end_tok - tok; | |
2140 | ||
2141 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
2142 | { | |
2143 | tok = cond_start = end_tok + 1; | |
2144 | cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); | |
2145 | cond_end = tok; | |
2146 | } | |
2147 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
bd5635a1 | 2148 | { |
199b2450 TL |
2149 | char *tmptok; |
2150 | ||
2151 | tok = end_tok + 1; | |
2152 | tmptok = tok; | |
2153 | thread = strtol (tok, &tok, 0); | |
2154 | if (tok == tmptok) | |
2155 | error ("Junk after thread keyword."); | |
2156 | if (!valid_thread_id (thread)) | |
2157 | error ("Unknown thread %d\n", thread); | |
bd5635a1 RP |
2158 | } |
2159 | else | |
2160 | error ("Junk at end of arguments."); | |
2161 | } | |
bd5635a1 RP |
2162 | } |
2163 | ||
d889f6b7 JK |
2164 | /* Remove the canonical strings from the cleanup, they are needed below. */ |
2165 | if (canonical != (char **)NULL) | |
2166 | discard_cleanups (canonical_strings_chain); | |
2167 | ||
30875e1c | 2168 | /* Now set all the breakpoints. */ |
bd5635a1 RP |
2169 | for (i = 0; i < sals.nelts; i++) |
2170 | { | |
2171 | sal = sals.sals[i]; | |
2172 | ||
2173 | if (from_tty) | |
2174 | describe_other_breakpoints (sal.pc); | |
2175 | ||
2176 | b = set_raw_breakpoint (sal); | |
2177 | set_breakpoint_count (breakpoint_count + 1); | |
2178 | b->number = breakpoint_count; | |
30875e1c | 2179 | b->type = bp_breakpoint; |
bd5635a1 | 2180 | b->cond = cond; |
199b2450 | 2181 | b->thread = thread; |
0a97f6c4 | 2182 | |
d889f6b7 JK |
2183 | /* If a canonical line spec is needed use that instead of the |
2184 | command string. */ | |
2185 | if (canonical != (char **)NULL && canonical[i] != NULL) | |
2186 | b->addr_string = canonical[i]; | |
2187 | else if (addr_start) | |
bd5635a1 RP |
2188 | b->addr_string = savestring (addr_start, addr_end - addr_start); |
2189 | if (cond_start) | |
2190 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
2191 | ||
30875e1c SG |
2192 | b->enable = enabled; |
2193 | b->disposition = tempflag ? delete : donttouch; | |
bd5635a1 RP |
2194 | |
2195 | mention (b); | |
2196 | } | |
2197 | ||
2198 | if (sals.nelts > 1) | |
2199 | { | |
833e0d94 JK |
2200 | printf_filtered ("Multiple breakpoints were set.\n"); |
2201 | printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n"); | |
bd5635a1 | 2202 | } |
d889f6b7 | 2203 | do_cleanups (old_chain); |
bd5635a1 RP |
2204 | } |
2205 | ||
30875e1c SG |
2206 | /* Helper function for break_command_1 and disassemble_command. */ |
2207 | ||
2208 | void | |
2209 | resolve_sal_pc (sal) | |
2210 | struct symtab_and_line *sal; | |
2211 | { | |
2212 | CORE_ADDR pc; | |
2213 | ||
2214 | if (sal->pc == 0 && sal->symtab != 0) | |
2215 | { | |
2216 | pc = find_line_pc (sal->symtab, sal->line); | |
2217 | if (pc == 0) | |
2218 | error ("No line %d in file \"%s\".", | |
2219 | sal->line, sal->symtab->filename); | |
2220 | sal->pc = pc; | |
2221 | } | |
2222 | } | |
2223 | ||
bd5635a1 RP |
2224 | void |
2225 | break_command (arg, from_tty) | |
2226 | char *arg; | |
2227 | int from_tty; | |
2228 | { | |
2229 | break_command_1 (arg, 0, from_tty); | |
2230 | } | |
2231 | ||
2232 | static void | |
2233 | tbreak_command (arg, from_tty) | |
2234 | char *arg; | |
2235 | int from_tty; | |
2236 | { | |
2237 | break_command_1 (arg, 1, from_tty); | |
2238 | } | |
2239 | ||
bdbd5f50 | 2240 | /* ARGSUSED */ |
bd5635a1 RP |
2241 | static void |
2242 | watch_command (arg, from_tty) | |
2243 | char *arg; | |
2244 | int from_tty; | |
2245 | { | |
2246 | struct breakpoint *b; | |
2247 | struct symtab_and_line sal; | |
f266e564 JK |
2248 | struct expression *exp; |
2249 | struct block *exp_valid_block; | |
2250 | struct value *val; | |
999dd04b | 2251 | FRAME frame, prev_frame; |
bd5635a1 | 2252 | |
30875e1c | 2253 | sal.pc = 0; |
bd5635a1 RP |
2254 | sal.symtab = NULL; |
2255 | sal.line = 0; | |
2256 | ||
f266e564 JK |
2257 | /* Parse arguments. */ |
2258 | innermost_block = NULL; | |
d3b9c0df | 2259 | exp = parse_expression (arg); |
f266e564 JK |
2260 | exp_valid_block = innermost_block; |
2261 | val = evaluate_expression (exp); | |
2262 | release_value (val); | |
2d313932 JK |
2263 | if (VALUE_LAZY (val)) |
2264 | value_fetch_lazy (val); | |
f266e564 JK |
2265 | |
2266 | /* Now set up the breakpoint. */ | |
bd5635a1 RP |
2267 | b = set_raw_breakpoint (sal); |
2268 | set_breakpoint_count (breakpoint_count + 1); | |
2269 | b->number = breakpoint_count; | |
30875e1c | 2270 | b->disposition = donttouch; |
f266e564 JK |
2271 | b->exp = exp; |
2272 | b->exp_valid_block = exp_valid_block; | |
2273 | b->val = val; | |
bd5635a1 RP |
2274 | b->cond = 0; |
2275 | b->cond_string = NULL; | |
0eaaa46a | 2276 | b->exp_string = savestring (arg, strlen (arg)); |
999dd04b JL |
2277 | |
2278 | frame = block_innermost_frame (exp_valid_block); | |
2279 | if (frame) | |
2280 | { | |
2281 | prev_frame = get_prev_frame (frame); | |
2282 | b->watchpoint_frame = FRAME_FP (frame); | |
2283 | } | |
2284 | else | |
9e8db445 | 2285 | b->watchpoint_frame = (CORE_ADDR)0; |
999dd04b JL |
2286 | |
2287 | if (can_use_hardware_watchpoint (b)) | |
2288 | b->type = bp_hardware_watchpoint; | |
2289 | else | |
2290 | b->type = bp_watchpoint; | |
2291 | ||
2292 | /* If the expression is "local", then set up a "watchpoint scope" | |
2293 | breakpoint at the point where we've left the scope of the watchpoint | |
2294 | expression. */ | |
2295 | if (innermost_block) | |
2296 | { | |
2297 | struct breakpoint *scope_breakpoint; | |
2298 | struct symtab_and_line scope_sal; | |
2299 | ||
2300 | if (prev_frame) | |
2301 | { | |
2302 | scope_sal.pc = get_frame_pc (prev_frame); | |
2303 | scope_sal.symtab = NULL; | |
2304 | scope_sal.line = 0; | |
2305 | ||
2306 | scope_breakpoint = set_raw_breakpoint (scope_sal); | |
2307 | set_breakpoint_count (breakpoint_count + 1); | |
2308 | scope_breakpoint->number = breakpoint_count; | |
2309 | ||
2310 | scope_breakpoint->type = bp_watchpoint_scope; | |
2311 | scope_breakpoint->enable = enabled; | |
2312 | ||
2313 | /* Automatically delete the breakpoint when it hits. */ | |
2314 | scope_breakpoint->disposition = delete; | |
2315 | ||
2316 | /* Only break in the proper frame (help with recursion). */ | |
2317 | scope_breakpoint->frame = prev_frame->frame; | |
2318 | ||
2319 | /* Set the address at which we will stop. */ | |
2320 | scope_breakpoint->address = get_frame_pc (prev_frame); | |
2321 | ||
2322 | /* The scope breakpoint is related to the watchpoint. We | |
2323 | will need to act on them together. */ | |
2324 | b->related_breakpoint = scope_breakpoint; | |
2325 | } | |
2326 | } | |
2327 | ||
bd5635a1 RP |
2328 | mention (b); |
2329 | } | |
999dd04b JL |
2330 | |
2331 | /* Return nonzero if the watchpoint described by B can be handled | |
2332 | completely in hardware. If the watchpoint can not be handled | |
2333 | in hardware return zero. */ | |
2334 | ||
2335 | static int | |
2336 | can_use_hardware_watchpoint (b) | |
2337 | struct breakpoint *b; | |
2338 | { | |
2339 | value_ptr mark = value_mark (); | |
2340 | value_ptr v = evaluate_expression (b->exp); | |
2341 | int found_memory = 0; | |
2342 | ||
2343 | /* Make sure all the intermediate values are in memory. Also make sure | |
2344 | we found at least one memory expression. Guards against watch 0x12345, | |
2345 | which is meaningless, but could cause errors if one tries to insert a | |
2346 | hardware watchpoint for the constant expression. */ | |
2347 | for ( ; v != mark; v = v->next) | |
2348 | { | |
2349 | if (!(v->lval == lval_memory) | |
2350 | || v->lval == not_lval | |
2351 | || (v->lval != not_lval | |
fad466eb | 2352 | && v->modifiable == 0)) |
999dd04b JL |
2353 | return 0; |
2354 | else | |
2355 | if (v->lval == lval_memory) | |
2356 | found_memory = 1; | |
2357 | } | |
2358 | ||
2359 | /* The expression itself looks suitable for using a hardware | |
2360 | watchpoint, but give the target machine a chance to reject it. */ | |
2361 | return found_memory && TARGET_CAN_USE_HARDWARE_WATCHPOINT (b); | |
2362 | } | |
2363 | ||
bd5635a1 RP |
2364 | \f |
2365 | /* | |
2366 | * Helper routine for the until_command routine in infcmd.c. Here | |
2367 | * because it uses the mechanisms of breakpoints. | |
2368 | */ | |
bdbd5f50 | 2369 | /* ARGSUSED */ |
bd5635a1 RP |
2370 | void |
2371 | until_break_command (arg, from_tty) | |
2372 | char *arg; | |
2373 | int from_tty; | |
2374 | { | |
2375 | struct symtabs_and_lines sals; | |
2376 | struct symtab_and_line sal; | |
2377 | FRAME prev_frame = get_prev_frame (selected_frame); | |
30875e1c SG |
2378 | struct breakpoint *breakpoint; |
2379 | struct cleanup *old_chain; | |
bd5635a1 RP |
2380 | |
2381 | clear_proceed_status (); | |
2382 | ||
2383 | /* Set a breakpoint where the user wants it and at return from | |
2384 | this function */ | |
2385 | ||
2386 | if (default_breakpoint_valid) | |
2387 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
d889f6b7 | 2388 | default_breakpoint_line, (char ***)NULL); |
bd5635a1 | 2389 | else |
d889f6b7 | 2390 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL); |
bd5635a1 RP |
2391 | |
2392 | if (sals.nelts != 1) | |
2393 | error ("Couldn't get information on specified line."); | |
2394 | ||
2395 | sal = sals.sals[0]; | |
c8950965 | 2396 | free ((PTR)sals.sals); /* malloc'd, so freed */ |
bd5635a1 RP |
2397 | |
2398 | if (*arg) | |
2399 | error ("Junk at end of arguments."); | |
2400 | ||
30875e1c | 2401 | resolve_sal_pc (&sal); |
bd5635a1 | 2402 | |
30875e1c | 2403 | breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until); |
bd5635a1 | 2404 | |
30875e1c SG |
2405 | old_chain = make_cleanup(delete_breakpoint, breakpoint); |
2406 | ||
bd5635a1 RP |
2407 | /* Keep within the current frame */ |
2408 | ||
2409 | if (prev_frame) | |
2410 | { | |
2411 | struct frame_info *fi; | |
2412 | ||
2413 | fi = get_frame_info (prev_frame); | |
2414 | sal = find_pc_line (fi->pc, 0); | |
2415 | sal.pc = fi->pc; | |
30875e1c SG |
2416 | breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until); |
2417 | make_cleanup(delete_breakpoint, breakpoint); | |
bd5635a1 RP |
2418 | } |
2419 | ||
d7e7e851 | 2420 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
30875e1c | 2421 | do_cleanups(old_chain); |
bd5635a1 RP |
2422 | } |
2423 | \f | |
bdbd5f50 JG |
2424 | #if 0 |
2425 | /* These aren't used; I don't konw what they were for. */ | |
bd5635a1 RP |
2426 | /* Set a breakpoint at the catch clause for NAME. */ |
2427 | static int | |
2428 | catch_breakpoint (name) | |
2429 | char *name; | |
2430 | { | |
2431 | } | |
2432 | ||
2433 | static int | |
2434 | disable_catch_breakpoint () | |
2435 | { | |
2436 | } | |
2437 | ||
2438 | static int | |
2439 | delete_catch_breakpoint () | |
2440 | { | |
2441 | } | |
2442 | ||
2443 | static int | |
2444 | enable_catch_breakpoint () | |
2445 | { | |
2446 | } | |
bdbd5f50 | 2447 | #endif /* 0 */ |
bd5635a1 RP |
2448 | |
2449 | struct sal_chain | |
2450 | { | |
2451 | struct sal_chain *next; | |
2452 | struct symtab_and_line sal; | |
2453 | }; | |
2454 | ||
bdbd5f50 JG |
2455 | #if 0 |
2456 | /* This isn't used; I don't know what it was for. */ | |
bd5635a1 RP |
2457 | /* For each catch clause identified in ARGS, run FUNCTION |
2458 | with that clause as an argument. */ | |
2459 | static struct symtabs_and_lines | |
2460 | map_catch_names (args, function) | |
2461 | char *args; | |
2462 | int (*function)(); | |
2463 | { | |
2464 | register char *p = args; | |
2465 | register char *p1; | |
2466 | struct symtabs_and_lines sals; | |
bdbd5f50 | 2467 | #if 0 |
bd5635a1 | 2468 | struct sal_chain *sal_chain = 0; |
bdbd5f50 | 2469 | #endif |
bd5635a1 RP |
2470 | |
2471 | if (p == 0) | |
2472 | error_no_arg ("one or more catch names"); | |
2473 | ||
2474 | sals.nelts = 0; | |
2475 | sals.sals = NULL; | |
2476 | ||
2477 | while (*p) | |
2478 | { | |
2479 | p1 = p; | |
2480 | /* Don't swallow conditional part. */ | |
2481 | if (p1[0] == 'i' && p1[1] == 'f' | |
2482 | && (p1[2] == ' ' || p1[2] == '\t')) | |
2483 | break; | |
2484 | ||
2485 | if (isalpha (*p1)) | |
2486 | { | |
2487 | p1++; | |
2488 | while (isalnum (*p1) || *p1 == '_' || *p1 == '$') | |
2489 | p1++; | |
2490 | } | |
2491 | ||
2492 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
2493 | error ("Arguments must be catch names."); | |
2494 | ||
2495 | *p1 = 0; | |
2496 | #if 0 | |
2497 | if (function (p)) | |
2498 | { | |
2499 | struct sal_chain *next | |
2500 | = (struct sal_chain *)alloca (sizeof (struct sal_chain)); | |
2501 | next->next = sal_chain; | |
2502 | next->sal = get_catch_sal (p); | |
2503 | sal_chain = next; | |
2504 | goto win; | |
2505 | } | |
2506 | #endif | |
199b2450 | 2507 | printf_unfiltered ("No catch clause for exception %s.\n", p); |
bdbd5f50 | 2508 | #if 0 |
bd5635a1 | 2509 | win: |
bdbd5f50 | 2510 | #endif |
bd5635a1 RP |
2511 | p = p1; |
2512 | while (*p == ' ' || *p == '\t') p++; | |
2513 | } | |
2514 | } | |
bdbd5f50 | 2515 | #endif /* 0 */ |
bd5635a1 RP |
2516 | |
2517 | /* This shares a lot of code with `print_frame_label_vars' from stack.c. */ | |
2518 | ||
2519 | static struct symtabs_and_lines | |
2520 | get_catch_sals (this_level_only) | |
2521 | int this_level_only; | |
2522 | { | |
bd5635a1 | 2523 | register struct blockvector *bl; |
777bef06 | 2524 | register struct block *block; |
bd5635a1 | 2525 | int index, have_default = 0; |
777bef06 JK |
2526 | struct frame_info *fi; |
2527 | CORE_ADDR pc; | |
bd5635a1 RP |
2528 | struct symtabs_and_lines sals; |
2529 | struct sal_chain *sal_chain = 0; | |
2530 | char *blocks_searched; | |
2531 | ||
777bef06 JK |
2532 | /* Not sure whether an error message is always the correct response, |
2533 | but it's better than a core dump. */ | |
2534 | if (selected_frame == NULL) | |
2535 | error ("No selected frame."); | |
2536 | block = get_frame_block (selected_frame); | |
2537 | fi = get_frame_info (selected_frame); | |
2538 | pc = fi->pc; | |
2539 | ||
bd5635a1 RP |
2540 | sals.nelts = 0; |
2541 | sals.sals = NULL; | |
2542 | ||
2543 | if (block == 0) | |
2544 | error ("No symbol table info available.\n"); | |
2545 | ||
2546 | bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); | |
2547 | blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); | |
4ed3a9ea | 2548 | memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); |
bd5635a1 RP |
2549 | |
2550 | while (block != 0) | |
2551 | { | |
2552 | CORE_ADDR end = BLOCK_END (block) - 4; | |
2553 | int last_index; | |
2554 | ||
2555 | if (bl != blockvector_for_pc (end, &index)) | |
2556 | error ("blockvector blotch"); | |
2557 | if (BLOCKVECTOR_BLOCK (bl, index) != block) | |
2558 | error ("blockvector botch"); | |
2559 | last_index = BLOCKVECTOR_NBLOCKS (bl); | |
2560 | index += 1; | |
2561 | ||
2562 | /* Don't print out blocks that have gone by. */ | |
2563 | while (index < last_index | |
2564 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) | |
2565 | index++; | |
2566 | ||
2567 | while (index < last_index | |
2568 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) | |
2569 | { | |
2570 | if (blocks_searched[index] == 0) | |
2571 | { | |
2572 | struct block *b = BLOCKVECTOR_BLOCK (bl, index); | |
2573 | int nsyms; | |
2574 | register int i; | |
2575 | register struct symbol *sym; | |
2576 | ||
2577 | nsyms = BLOCK_NSYMS (b); | |
2578 | ||
2579 | for (i = 0; i < nsyms; i++) | |
2580 | { | |
2581 | sym = BLOCK_SYM (b, i); | |
2d313932 | 2582 | if (STREQ (SYMBOL_NAME (sym), "default")) |
bd5635a1 RP |
2583 | { |
2584 | if (have_default) | |
2585 | continue; | |
2586 | have_default = 1; | |
2587 | } | |
2588 | if (SYMBOL_CLASS (sym) == LOC_LABEL) | |
2589 | { | |
2590 | struct sal_chain *next = (struct sal_chain *) | |
2591 | alloca (sizeof (struct sal_chain)); | |
2592 | next->next = sal_chain; | |
2593 | next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); | |
2594 | sal_chain = next; | |
2595 | } | |
2596 | } | |
2597 | blocks_searched[index] = 1; | |
2598 | } | |
2599 | index++; | |
2600 | } | |
2601 | if (have_default) | |
2602 | break; | |
2603 | if (sal_chain && this_level_only) | |
2604 | break; | |
2605 | ||
2606 | /* After handling the function's top-level block, stop. | |
2607 | Don't continue to its superblock, the block of | |
2608 | per-file symbols. */ | |
2609 | if (BLOCK_FUNCTION (block)) | |
2610 | break; | |
2611 | block = BLOCK_SUPERBLOCK (block); | |
2612 | } | |
2613 | ||
2614 | if (sal_chain) | |
2615 | { | |
2616 | struct sal_chain *tmp_chain; | |
2617 | ||
2618 | /* Count the number of entries. */ | |
2619 | for (index = 0, tmp_chain = sal_chain; tmp_chain; | |
2620 | tmp_chain = tmp_chain->next) | |
2621 | index++; | |
2622 | ||
2623 | sals.nelts = index; | |
2624 | sals.sals = (struct symtab_and_line *) | |
2625 | xmalloc (index * sizeof (struct symtab_and_line)); | |
2626 | for (index = 0; sal_chain; sal_chain = sal_chain->next, index++) | |
2627 | sals.sals[index] = sal_chain->sal; | |
2628 | } | |
2629 | ||
2630 | return sals; | |
2631 | } | |
2632 | ||
2633 | /* Commands to deal with catching exceptions. */ | |
2634 | ||
30875e1c | 2635 | static void |
bd5635a1 RP |
2636 | catch_command_1 (arg, tempflag, from_tty) |
2637 | char *arg; | |
2638 | int tempflag; | |
2639 | int from_tty; | |
2640 | { | |
2641 | /* First, translate ARG into something we can deal with in terms | |
2642 | of breakpoints. */ | |
2643 | ||
2644 | struct symtabs_and_lines sals; | |
2645 | struct symtab_and_line sal; | |
2646 | register struct expression *cond = 0; | |
2647 | register struct breakpoint *b; | |
2648 | char *save_arg; | |
2649 | int i; | |
bd5635a1 RP |
2650 | |
2651 | sal.line = sal.pc = sal.end = 0; | |
2652 | sal.symtab = 0; | |
2653 | ||
2654 | /* If no arg given, or if first arg is 'if ', all active catch clauses | |
2655 | are breakpointed. */ | |
2656 | ||
2657 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' | |
2658 | && (arg[2] == ' ' || arg[2] == '\t'))) | |
2659 | { | |
2660 | /* Grab all active catch clauses. */ | |
2661 | sals = get_catch_sals (0); | |
2662 | } | |
2663 | else | |
2664 | { | |
2665 | /* Grab selected catch clauses. */ | |
fe675038 | 2666 | error ("catch NAME not implemented"); |
bdbd5f50 JG |
2667 | #if 0 |
2668 | /* This isn't used; I don't know what it was for. */ | |
bd5635a1 | 2669 | sals = map_catch_names (arg, catch_breakpoint); |
bdbd5f50 | 2670 | #endif |
bd5635a1 RP |
2671 | } |
2672 | ||
2673 | if (! sals.nelts) | |
2674 | return; | |
2675 | ||
2676 | save_arg = arg; | |
2677 | for (i = 0; i < sals.nelts; i++) | |
2678 | { | |
30875e1c | 2679 | resolve_sal_pc (&sals.sals[i]); |
bd5635a1 RP |
2680 | |
2681 | while (arg && *arg) | |
2682 | { | |
2683 | if (arg[0] == 'i' && arg[1] == 'f' | |
2684 | && (arg[2] == ' ' || arg[2] == '\t')) | |
30875e1c SG |
2685 | cond = parse_exp_1 ((arg += 2, &arg), |
2686 | block_for_pc (sals.sals[i].pc), 0); | |
bd5635a1 RP |
2687 | else |
2688 | error ("Junk at end of arguments."); | |
2689 | } | |
2690 | arg = save_arg; | |
bd5635a1 RP |
2691 | } |
2692 | ||
2693 | for (i = 0; i < sals.nelts; i++) | |
2694 | { | |
2695 | sal = sals.sals[i]; | |
2696 | ||
2697 | if (from_tty) | |
2698 | describe_other_breakpoints (sal.pc); | |
2699 | ||
2700 | b = set_raw_breakpoint (sal); | |
30875e1c SG |
2701 | set_breakpoint_count (breakpoint_count + 1); |
2702 | b->number = breakpoint_count; | |
2703 | b->type = bp_breakpoint; | |
bd5635a1 | 2704 | b->cond = cond; |
30875e1c SG |
2705 | b->enable = enabled; |
2706 | b->disposition = tempflag ? delete : donttouch; | |
bd5635a1 | 2707 | |
d889f6b7 | 2708 | mention (b); |
bd5635a1 RP |
2709 | } |
2710 | ||
2711 | if (sals.nelts > 1) | |
2712 | { | |
199b2450 TL |
2713 | printf_unfiltered ("Multiple breakpoints were set.\n"); |
2714 | printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n"); | |
bd5635a1 | 2715 | } |
c8950965 | 2716 | free ((PTR)sals.sals); |
bd5635a1 RP |
2717 | } |
2718 | ||
bdbd5f50 JG |
2719 | #if 0 |
2720 | /* These aren't used; I don't know what they were for. */ | |
bd5635a1 RP |
2721 | /* Disable breakpoints on all catch clauses described in ARGS. */ |
2722 | static void | |
2723 | disable_catch (args) | |
2724 | char *args; | |
2725 | { | |
2726 | /* Map the disable command to catch clauses described in ARGS. */ | |
2727 | } | |
2728 | ||
2729 | /* Enable breakpoints on all catch clauses described in ARGS. */ | |
2730 | static void | |
2731 | enable_catch (args) | |
2732 | char *args; | |
2733 | { | |
2734 | /* Map the disable command to catch clauses described in ARGS. */ | |
2735 | } | |
2736 | ||
2737 | /* Delete breakpoints on all catch clauses in the active scope. */ | |
2738 | static void | |
2739 | delete_catch (args) | |
2740 | char *args; | |
2741 | { | |
2742 | /* Map the delete command to catch clauses described in ARGS. */ | |
2743 | } | |
bdbd5f50 | 2744 | #endif /* 0 */ |
bd5635a1 RP |
2745 | |
2746 | static void | |
2747 | catch_command (arg, from_tty) | |
2748 | char *arg; | |
2749 | int from_tty; | |
2750 | { | |
2751 | catch_command_1 (arg, 0, from_tty); | |
2752 | } | |
2753 | \f | |
2754 | static void | |
2755 | clear_command (arg, from_tty) | |
2756 | char *arg; | |
2757 | int from_tty; | |
2758 | { | |
2759 | register struct breakpoint *b, *b1; | |
2760 | struct symtabs_and_lines sals; | |
2761 | struct symtab_and_line sal; | |
2762 | register struct breakpoint *found; | |
2763 | int i; | |
2764 | ||
2765 | if (arg) | |
2766 | { | |
2767 | sals = decode_line_spec (arg, 1); | |
2768 | } | |
2769 | else | |
2770 | { | |
2771 | sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); | |
2772 | sal.line = default_breakpoint_line; | |
2773 | sal.symtab = default_breakpoint_symtab; | |
2774 | sal.pc = 0; | |
2775 | if (sal.symtab == 0) | |
2776 | error ("No source file specified."); | |
2777 | ||
2778 | sals.sals[0] = sal; | |
2779 | sals.nelts = 1; | |
2780 | } | |
2781 | ||
2782 | for (i = 0; i < sals.nelts; i++) | |
2783 | { | |
2784 | /* If exact pc given, clear bpts at that pc. | |
2785 | But if sal.pc is zero, clear all bpts on specified line. */ | |
2786 | sal = sals.sals[i]; | |
2787 | found = (struct breakpoint *) 0; | |
2788 | while (breakpoint_chain | |
d889f6b7 JK |
2789 | && (sal.pc |
2790 | ? breakpoint_chain->address == sal.pc | |
2791 | : (breakpoint_chain->source_file != NULL | |
2792 | && sal.symtab != NULL | |
2793 | && STREQ (breakpoint_chain->source_file, | |
2794 | sal.symtab->filename) | |
bd5635a1 RP |
2795 | && breakpoint_chain->line_number == sal.line))) |
2796 | { | |
2797 | b1 = breakpoint_chain; | |
2798 | breakpoint_chain = b1->next; | |
2799 | b1->next = found; | |
2800 | found = b1; | |
2801 | } | |
2802 | ||
2803 | ALL_BREAKPOINTS (b) | |
2804 | while (b->next | |
30875e1c | 2805 | && b->next->type != bp_watchpoint |
999dd04b | 2806 | && b->next->type != bp_hardware_watchpoint |
d889f6b7 JK |
2807 | && (sal.pc |
2808 | ? b->next->address == sal.pc | |
2809 | : (b->next->source_file != NULL | |
2810 | && sal.symtab != NULL | |
2811 | && STREQ (b->next->source_file, sal.symtab->filename) | |
bd5635a1 RP |
2812 | && b->next->line_number == sal.line))) |
2813 | { | |
2814 | b1 = b->next; | |
2815 | b->next = b1->next; | |
2816 | b1->next = found; | |
2817 | found = b1; | |
2818 | } | |
2819 | ||
2820 | if (found == 0) | |
2821 | { | |
2822 | if (arg) | |
2823 | error ("No breakpoint at %s.", arg); | |
2824 | else | |
2825 | error ("No breakpoint at this line."); | |
2826 | } | |
2827 | ||
2828 | if (found->next) from_tty = 1; /* Always report if deleted more than one */ | |
199b2450 | 2829 | if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : ""); |
6c803036 | 2830 | breakpoints_changed (); |
bd5635a1 RP |
2831 | while (found) |
2832 | { | |
199b2450 | 2833 | if (from_tty) printf_unfiltered ("%d ", found->number); |
bd5635a1 RP |
2834 | b1 = found->next; |
2835 | delete_breakpoint (found); | |
2836 | found = b1; | |
2837 | } | |
199b2450 | 2838 | if (from_tty) putchar_unfiltered ('\n'); |
bd5635a1 | 2839 | } |
c8950965 | 2840 | free ((PTR)sals.sals); |
bd5635a1 RP |
2841 | } |
2842 | \f | |
2843 | /* Delete breakpoint in BS if they are `delete' breakpoints. | |
2844 | This is called after any breakpoint is hit, or after errors. */ | |
2845 | ||
2846 | void | |
2847 | breakpoint_auto_delete (bs) | |
2848 | bpstat bs; | |
2849 | { | |
2850 | for (; bs; bs = bs->next) | |
cef4c2e7 PS |
2851 | if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete |
2852 | && bs->stop) | |
bd5635a1 RP |
2853 | delete_breakpoint (bs->breakpoint_at); |
2854 | } | |
2855 | ||
2856 | /* Delete a breakpoint and clean up all traces of it in the data structures. */ | |
2857 | ||
30875e1c | 2858 | void |
bd5635a1 RP |
2859 | delete_breakpoint (bpt) |
2860 | struct breakpoint *bpt; | |
2861 | { | |
2862 | register struct breakpoint *b; | |
2863 | register bpstat bs; | |
2864 | ||
2865 | if (bpt->inserted) | |
999dd04b JL |
2866 | remove_breakpoint (bpt); |
2867 | ||
bd5635a1 RP |
2868 | if (breakpoint_chain == bpt) |
2869 | breakpoint_chain = bpt->next; | |
2870 | ||
2871 | ALL_BREAKPOINTS (b) | |
2872 | if (b->next == bpt) | |
2873 | { | |
2874 | b->next = bpt->next; | |
2875 | break; | |
2876 | } | |
2877 | ||
2878 | check_duplicates (bpt->address); | |
fe675038 JK |
2879 | /* If this breakpoint was inserted, and there is another breakpoint |
2880 | at the same address, we need to insert the other breakpoint. */ | |
999dd04b JL |
2881 | if (bpt->inserted |
2882 | && bpt->type != bp_hardware_watchpoint) | |
fe675038 JK |
2883 | { |
2884 | ALL_BREAKPOINTS (b) | |
ebad9e90 JK |
2885 | if (b->address == bpt->address |
2886 | && !b->duplicate | |
2887 | && b->enable != disabled) | |
fe675038 JK |
2888 | { |
2889 | int val; | |
2890 | val = target_insert_breakpoint (b->address, b->shadow_contents); | |
2891 | if (val != 0) | |
2892 | { | |
05052b63 | 2893 | target_terminal_ours_for_output (); |
199b2450 | 2894 | fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number); |
fe675038 JK |
2895 | memory_error (val, b->address); /* which bombs us out */ |
2896 | } | |
2897 | else | |
2898 | b->inserted = 1; | |
2899 | } | |
2900 | } | |
bd5635a1 RP |
2901 | |
2902 | free_command_lines (&bpt->commands); | |
2903 | if (bpt->cond) | |
d889f6b7 | 2904 | free (bpt->cond); |
bd5635a1 | 2905 | if (bpt->cond_string != NULL) |
d889f6b7 | 2906 | free (bpt->cond_string); |
bd5635a1 | 2907 | if (bpt->addr_string != NULL) |
d889f6b7 | 2908 | free (bpt->addr_string); |
0eaaa46a | 2909 | if (bpt->exp_string != NULL) |
d889f6b7 JK |
2910 | free (bpt->exp_string); |
2911 | if (bpt->source_file != NULL) | |
2912 | free (bpt->source_file); | |
bd5635a1 | 2913 | |
6c803036 | 2914 | breakpoints_changed (); |
bd5635a1 RP |
2915 | |
2916 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
05052b63 JK |
2917 | /* FIXME, how can we find all bpstat's? |
2918 | We just check stop_bpstat for now. */ | |
bd5635a1 RP |
2919 | for (bs = stop_bpstat; bs; bs = bs->next) |
2920 | if (bs->breakpoint_at == bpt) | |
2921 | bs->breakpoint_at = NULL; | |
c8950965 | 2922 | free ((PTR)bpt); |
bd5635a1 RP |
2923 | } |
2924 | ||
bd5635a1 RP |
2925 | static void |
2926 | delete_command (arg, from_tty) | |
2927 | char *arg; | |
2928 | int from_tty; | |
2929 | { | |
2930 | ||
2931 | if (arg == 0) | |
2932 | { | |
2933 | /* Ask user only if there are some breakpoints to delete. */ | |
2934 | if (!from_tty | |
2935 | || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0))) | |
2936 | { | |
2937 | /* No arg; clear all breakpoints. */ | |
2938 | while (breakpoint_chain) | |
2939 | delete_breakpoint (breakpoint_chain); | |
2940 | } | |
2941 | } | |
2942 | else | |
2943 | map_breakpoint_numbers (arg, delete_breakpoint); | |
2944 | } | |
2945 | ||
bdbd5f50 JG |
2946 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
2947 | The value we return ends up being the return value from catch_errors. | |
2948 | Unused in this case. */ | |
2949 | ||
2950 | static int | |
bd5635a1 | 2951 | breakpoint_re_set_one (bint) |
bdbd5f50 | 2952 | char *bint; |
bd5635a1 RP |
2953 | { |
2954 | struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */ | |
2955 | int i; | |
2956 | struct symtabs_and_lines sals; | |
bd5635a1 | 2957 | char *s; |
30875e1c | 2958 | enum enable save_enable; |
bd5635a1 | 2959 | |
80ba48f5 | 2960 | switch (b->type) |
bd5635a1 | 2961 | { |
80ba48f5 SG |
2962 | case bp_breakpoint: |
2963 | if (b->addr_string == NULL) | |
2964 | { | |
2965 | /* Anything without a string can't be re-set. */ | |
2966 | delete_breakpoint (b); | |
2967 | return 0; | |
2968 | } | |
30875e1c SG |
2969 | /* In case we have a problem, disable this breakpoint. We'll restore |
2970 | its status if we succeed. */ | |
2971 | save_enable = b->enable; | |
2972 | b->enable = disabled; | |
2973 | ||
bd5635a1 | 2974 | s = b->addr_string; |
d889f6b7 | 2975 | sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL); |
bd5635a1 RP |
2976 | for (i = 0; i < sals.nelts; i++) |
2977 | { | |
30875e1c | 2978 | resolve_sal_pc (&sals.sals[i]); |
fee933f1 RP |
2979 | |
2980 | /* Reparse conditions, they might contain references to the | |
2981 | old symtab. */ | |
2982 | if (b->cond_string != NULL) | |
2983 | { | |
2984 | s = b->cond_string; | |
2985 | if (b->cond) | |
2986 | free ((PTR)b->cond); | |
2987 | b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); | |
2988 | } | |
2989 | ||
2990 | /* We need to re-set the breakpoint if the address changes...*/ | |
d889f6b7 | 2991 | if (b->address != sals.sals[i].pc |
fee933f1 RP |
2992 | /* ...or new and old breakpoints both have source files, and |
2993 | the source file name or the line number changes... */ | |
d889f6b7 JK |
2994 | || (b->source_file != NULL |
2995 | && sals.sals[i].symtab != NULL | |
2996 | && (!STREQ (b->source_file, sals.sals[i].symtab->filename) | |
2997 | || b->line_number != sals.sals[i].line) | |
fee933f1 RP |
2998 | ) |
2999 | /* ...or we switch between having a source file and not having | |
3000 | one. */ | |
3001 | || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL)) | |
3002 | ) | |
bd5635a1 | 3003 | { |
d889f6b7 JK |
3004 | if (b->source_file != NULL) |
3005 | free (b->source_file); | |
3006 | if (sals.sals[i].symtab == NULL) | |
3007 | b->source_file = NULL; | |
3008 | else | |
3009 | b->source_file = | |
3010 | savestring (sals.sals[i].symtab->filename, | |
3011 | strlen (sals.sals[i].symtab->filename)); | |
8537ba60 SG |
3012 | b->line_number = sals.sals[i].line; |
3013 | b->address = sals.sals[i].pc; | |
bd5635a1 | 3014 | |
8537ba60 | 3015 | check_duplicates (b->address); |
bd5635a1 | 3016 | |
8537ba60 | 3017 | mention (b); |
6c803036 JK |
3018 | |
3019 | /* Might be better to do this just once per breakpoint_re_set, | |
3020 | rather than once for every breakpoint. */ | |
3021 | breakpoints_changed (); | |
8537ba60 | 3022 | } |
30875e1c | 3023 | b->enable = save_enable; /* Restore it, this worked. */ |
bd5635a1 | 3024 | } |
c8950965 | 3025 | free ((PTR)sals.sals); |
80ba48f5 | 3026 | break; |
2d313932 | 3027 | |
80ba48f5 | 3028 | case bp_watchpoint: |
999dd04b | 3029 | case bp_hardware_watchpoint: |
0eaaa46a | 3030 | innermost_block = NULL; |
0a97f6c4 JK |
3031 | /* The issue arises of what context to evaluate this in. The same |
3032 | one as when it was set, but what does that mean when symbols have | |
3033 | been re-read? We could save the filename and functionname, but | |
3034 | if the context is more local than that, the best we could do would | |
3035 | be something like how many levels deep and which index at that | |
3036 | particular level, but that's going to be less stable than filenames | |
3037 | or functionnames. */ | |
3038 | /* So for now, just use a global context. */ | |
0eaaa46a JK |
3039 | b->exp = parse_expression (b->exp_string); |
3040 | b->exp_valid_block = innermost_block; | |
3041 | b->val = evaluate_expression (b->exp); | |
3042 | release_value (b->val); | |
3043 | if (VALUE_LAZY (b->val)) | |
3044 | value_fetch_lazy (b->val); | |
3045 | ||
2d313932 JK |
3046 | if (b->cond_string != NULL) |
3047 | { | |
3048 | s = b->cond_string; | |
3049 | b->cond = parse_exp_1 (&s, (struct block *)0, 0); | |
3050 | } | |
cabd4da6 JK |
3051 | if (b->enable == enabled) |
3052 | mention (b); | |
80ba48f5 | 3053 | break; |
2d313932 | 3054 | |
80ba48f5 SG |
3055 | default: |
3056 | printf_filtered ("Deleting unknown breakpoint type %d\n", b->type); | |
2d313932 | 3057 | /* fall through */ |
80ba48f5 SG |
3058 | case bp_until: |
3059 | case bp_finish: | |
3060 | case bp_longjmp: | |
3061 | case bp_longjmp_resume: | |
999dd04b | 3062 | case bp_watchpoint_scope: |
cf3e377e | 3063 | case bp_call_dummy: |
80ba48f5 SG |
3064 | delete_breakpoint (b); |
3065 | break; | |
bd5635a1 | 3066 | } |
80ba48f5 | 3067 | |
bdbd5f50 | 3068 | return 0; |
bd5635a1 RP |
3069 | } |
3070 | ||
3071 | /* Re-set all breakpoints after symbols have been re-loaded. */ | |
3072 | void | |
3073 | breakpoint_re_set () | |
3074 | { | |
cba0d141 | 3075 | struct breakpoint *b, *temp; |
30875e1c SG |
3076 | static char message1[] = "Error in re-setting breakpoint %d:\n"; |
3077 | char message[sizeof (message1) + 30 /* slop */]; | |
bd5635a1 | 3078 | |
cba0d141 | 3079 | ALL_BREAKPOINTS_SAFE (b, temp) |
bd5635a1 | 3080 | { |
2d313932 | 3081 | sprintf (message, message1, b->number); /* Format possible error msg */ |
fe675038 JK |
3082 | catch_errors (breakpoint_re_set_one, (char *) b, message, |
3083 | RETURN_MASK_ALL); | |
bd5635a1 RP |
3084 | } |
3085 | ||
80ba48f5 SG |
3086 | create_longjmp_breakpoint("longjmp"); |
3087 | create_longjmp_breakpoint("_longjmp"); | |
3088 | create_longjmp_breakpoint("siglongjmp"); | |
3089 | create_longjmp_breakpoint(NULL); | |
3090 | ||
1eeba686 PB |
3091 | #if 0 |
3092 | /* Took this out (temporaliy at least), since it produces an extra | |
3093 | blank line at startup. This messes up the gdbtests. -PB */ | |
bd5635a1 RP |
3094 | /* Blank line to finish off all those mention() messages we just printed. */ |
3095 | printf_filtered ("\n"); | |
1eeba686 | 3096 | #endif |
bd5635a1 RP |
3097 | } |
3098 | \f | |
3099 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. | |
3100 | If from_tty is nonzero, it prints a message to that effect, | |
3101 | which ends with a period (no newline). */ | |
3102 | ||
3103 | void | |
3104 | set_ignore_count (bptnum, count, from_tty) | |
3105 | int bptnum, count, from_tty; | |
3106 | { | |
3107 | register struct breakpoint *b; | |
3108 | ||
3109 | if (count < 0) | |
3110 | count = 0; | |
3111 | ||
3112 | ALL_BREAKPOINTS (b) | |
3113 | if (b->number == bptnum) | |
3114 | { | |
3115 | b->ignore_count = count; | |
3116 | if (!from_tty) | |
3117 | return; | |
3118 | else if (count == 0) | |
423e9664 SG |
3119 | printf_filtered ("Will stop next time breakpoint %d is reached.", |
3120 | bptnum); | |
bd5635a1 | 3121 | else if (count == 1) |
423e9664 SG |
3122 | printf_filtered ("Will ignore next crossing of breakpoint %d.", |
3123 | bptnum); | |
bd5635a1 | 3124 | else |
423e9664 | 3125 | printf_filtered ("Will ignore next %d crossings of breakpoint %d.", |
bd5635a1 | 3126 | count, bptnum); |
6c803036 | 3127 | breakpoints_changed (); |
bd5635a1 RP |
3128 | return; |
3129 | } | |
3130 | ||
3131 | error ("No breakpoint number %d.", bptnum); | |
3132 | } | |
3133 | ||
3134 | /* Clear the ignore counts of all breakpoints. */ | |
3135 | void | |
3136 | breakpoint_clear_ignore_counts () | |
3137 | { | |
3138 | struct breakpoint *b; | |
3139 | ||
3140 | ALL_BREAKPOINTS (b) | |
3141 | b->ignore_count = 0; | |
3142 | } | |
3143 | ||
3144 | /* Command to set ignore-count of breakpoint N to COUNT. */ | |
3145 | ||
3146 | static void | |
3147 | ignore_command (args, from_tty) | |
3148 | char *args; | |
3149 | int from_tty; | |
3150 | { | |
3151 | char *p = args; | |
3152 | register int num; | |
3153 | ||
3154 | if (p == 0) | |
3155 | error_no_arg ("a breakpoint number"); | |
3156 | ||
3157 | num = get_number (&p); | |
3158 | ||
3159 | if (*p == 0) | |
3160 | error ("Second argument (specified ignore-count) is missing."); | |
3161 | ||
bdbd5f50 JG |
3162 | set_ignore_count (num, |
3163 | longest_to_int (value_as_long (parse_and_eval (p))), | |
3164 | from_tty); | |
423e9664 | 3165 | printf_filtered ("\n"); |
6c803036 | 3166 | breakpoints_changed (); |
bd5635a1 RP |
3167 | } |
3168 | \f | |
3169 | /* Call FUNCTION on each of the breakpoints | |
3170 | whose numbers are given in ARGS. */ | |
3171 | ||
3172 | static void | |
3173 | map_breakpoint_numbers (args, function) | |
3174 | char *args; | |
30875e1c | 3175 | void (*function) PARAMS ((struct breakpoint *)); |
bd5635a1 RP |
3176 | { |
3177 | register char *p = args; | |
3178 | char *p1; | |
3179 | register int num; | |
3180 | register struct breakpoint *b; | |
3181 | ||
3182 | if (p == 0) | |
3183 | error_no_arg ("one or more breakpoint numbers"); | |
3184 | ||
3185 | while (*p) | |
3186 | { | |
3187 | p1 = p; | |
3188 | ||
3189 | num = get_number (&p1); | |
3190 | ||
3191 | ALL_BREAKPOINTS (b) | |
3192 | if (b->number == num) | |
3193 | { | |
999dd04b | 3194 | struct breakpoint *related_breakpoint = b->related_breakpoint; |
bd5635a1 | 3195 | function (b); |
999dd04b JL |
3196 | if (related_breakpoint) |
3197 | function (related_breakpoint); | |
bd5635a1 RP |
3198 | goto win; |
3199 | } | |
199b2450 | 3200 | printf_unfiltered ("No breakpoint number %d.\n", num); |
bd5635a1 RP |
3201 | win: |
3202 | p = p1; | |
3203 | } | |
3204 | } | |
3205 | ||
3206 | static void | |
3207 | enable_breakpoint (bpt) | |
3208 | struct breakpoint *bpt; | |
3209 | { | |
fee933f1 | 3210 | FRAME save_selected_frame = NULL; |
fa99ebe1 JK |
3211 | int save_selected_frame_level = -1; |
3212 | ||
bd5635a1 RP |
3213 | bpt->enable = enabled; |
3214 | ||
6c803036 | 3215 | breakpoints_changed (); |
bd5635a1 RP |
3216 | |
3217 | check_duplicates (bpt->address); | |
999dd04b | 3218 | if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint) |
bd5635a1 | 3219 | { |
fa99ebe1 | 3220 | if (bpt->exp_valid_block != NULL) |
f266e564 | 3221 | { |
999dd04b | 3222 | FRAME fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame); |
fa99ebe1 JK |
3223 | if (fr == NULL) |
3224 | { | |
3225 | printf_filtered ("\ | |
f266e564 JK |
3226 | Cannot enable watchpoint %d because the block in which its expression\n\ |
3227 | is valid is not currently in scope.\n", bpt->number); | |
fa99ebe1 JK |
3228 | bpt->enable = disabled; |
3229 | return; | |
3230 | } | |
999dd04b | 3231 | |
fa99ebe1 JK |
3232 | save_selected_frame = selected_frame; |
3233 | save_selected_frame_level = selected_frame_level; | |
3234 | select_frame (fr, -1); | |
f266e564 JK |
3235 | } |
3236 | ||
bd5635a1 RP |
3237 | value_free (bpt->val); |
3238 | ||
3239 | bpt->val = evaluate_expression (bpt->exp); | |
3240 | release_value (bpt->val); | |
2d313932 JK |
3241 | if (VALUE_LAZY (bpt->val)) |
3242 | value_fetch_lazy (bpt->val); | |
fa99ebe1 JK |
3243 | |
3244 | if (save_selected_frame_level >= 0) | |
3245 | select_frame (save_selected_frame, save_selected_frame_level); | |
bd5635a1 RP |
3246 | } |
3247 | } | |
3248 | ||
bdbd5f50 | 3249 | /* ARGSUSED */ |
bd5635a1 RP |
3250 | static void |
3251 | enable_command (args, from_tty) | |
3252 | char *args; | |
3253 | int from_tty; | |
3254 | { | |
3255 | struct breakpoint *bpt; | |
3256 | if (args == 0) | |
3257 | ALL_BREAKPOINTS (bpt) | |
423e9664 SG |
3258 | switch (bpt->type) |
3259 | { | |
3260 | case bp_breakpoint: | |
3261 | case bp_watchpoint: | |
999dd04b | 3262 | case bp_hardware_watchpoint: |
423e9664 SG |
3263 | enable_breakpoint (bpt); |
3264 | default: | |
3265 | continue; | |
3266 | } | |
bd5635a1 RP |
3267 | else |
3268 | map_breakpoint_numbers (args, enable_breakpoint); | |
3269 | } | |
3270 | ||
3271 | static void | |
3272 | disable_breakpoint (bpt) | |
3273 | struct breakpoint *bpt; | |
3274 | { | |
999dd04b JL |
3275 | /* Never disable a watchpoint scope breakpoint; we want to |
3276 | hit them when we leave scope so we can delete both the | |
3277 | watchpoint and its scope breakpoint at that time. */ | |
3278 | if (bpt->type == bp_watchpoint_scope) | |
3279 | return; | |
3280 | ||
bd5635a1 RP |
3281 | bpt->enable = disabled; |
3282 | ||
6c803036 | 3283 | breakpoints_changed (); |
bd5635a1 RP |
3284 | |
3285 | check_duplicates (bpt->address); | |
3286 | } | |
3287 | ||
bdbd5f50 | 3288 | /* ARGSUSED */ |
bd5635a1 RP |
3289 | static void |
3290 | disable_command (args, from_tty) | |
3291 | char *args; | |
3292 | int from_tty; | |
3293 | { | |
3294 | register struct breakpoint *bpt; | |
3295 | if (args == 0) | |
3296 | ALL_BREAKPOINTS (bpt) | |
423e9664 SG |
3297 | switch (bpt->type) |
3298 | { | |
3299 | case bp_breakpoint: | |
3300 | case bp_watchpoint: | |
999dd04b | 3301 | case bp_hardware_watchpoint: |
423e9664 SG |
3302 | disable_breakpoint (bpt); |
3303 | default: | |
3304 | continue; | |
3305 | } | |
bd5635a1 RP |
3306 | else |
3307 | map_breakpoint_numbers (args, disable_breakpoint); | |
3308 | } | |
3309 | ||
3310 | static void | |
3311 | enable_once_breakpoint (bpt) | |
3312 | struct breakpoint *bpt; | |
3313 | { | |
30875e1c SG |
3314 | bpt->enable = enabled; |
3315 | bpt->disposition = disable; | |
bd5635a1 RP |
3316 | |
3317 | check_duplicates (bpt->address); | |
6c803036 | 3318 | breakpoints_changed (); |
bd5635a1 RP |
3319 | } |
3320 | ||
bdbd5f50 | 3321 | /* ARGSUSED */ |
bd5635a1 RP |
3322 | static void |
3323 | enable_once_command (args, from_tty) | |
3324 | char *args; | |
3325 | int from_tty; | |
3326 | { | |
3327 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
3328 | } | |
3329 | ||
3330 | static void | |
3331 | enable_delete_breakpoint (bpt) | |
3332 | struct breakpoint *bpt; | |
3333 | { | |
30875e1c SG |
3334 | bpt->enable = enabled; |
3335 | bpt->disposition = delete; | |
bd5635a1 RP |
3336 | |
3337 | check_duplicates (bpt->address); | |
6c803036 | 3338 | breakpoints_changed (); |
bd5635a1 RP |
3339 | } |
3340 | ||
bdbd5f50 | 3341 | /* ARGSUSED */ |
bd5635a1 RP |
3342 | static void |
3343 | enable_delete_command (args, from_tty) | |
3344 | char *args; | |
3345 | int from_tty; | |
3346 | { | |
3347 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
3348 | } | |
3349 | \f | |
3350 | /* | |
3351 | * Use default_breakpoint_'s, or nothing if they aren't valid. | |
3352 | */ | |
3353 | struct symtabs_and_lines | |
3354 | decode_line_spec_1 (string, funfirstline) | |
3355 | char *string; | |
3356 | int funfirstline; | |
3357 | { | |
3358 | struct symtabs_and_lines sals; | |
3359 | if (string == 0) | |
3360 | error ("Empty line specification."); | |
3361 | if (default_breakpoint_valid) | |
3362 | sals = decode_line_1 (&string, funfirstline, | |
d889f6b7 JK |
3363 | default_breakpoint_symtab, default_breakpoint_line, |
3364 | (char ***)NULL); | |
bd5635a1 | 3365 | else |
d889f6b7 JK |
3366 | sals = decode_line_1 (&string, funfirstline, |
3367 | (struct symtab *)NULL, 0, (char ***)NULL); | |
bd5635a1 RP |
3368 | if (*string) |
3369 | error ("Junk at end of line specification: %s", string); | |
3370 | return sals; | |
3371 | } | |
3372 | \f | |
bd5635a1 RP |
3373 | void |
3374 | _initialize_breakpoint () | |
3375 | { | |
3376 | breakpoint_chain = 0; | |
3377 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
3378 | before a breakpoint is set. */ | |
3379 | breakpoint_count = 0; | |
3380 | ||
3381 | add_com ("ignore", class_breakpoint, ignore_command, | |
3382 | "Set ignore-count of breakpoint number N to COUNT."); | |
3383 | ||
3384 | add_com ("commands", class_breakpoint, commands_command, | |
3385 | "Set commands to be executed when a breakpoint is hit.\n\ | |
3386 | Give breakpoint number as argument after \"commands\".\n\ | |
3387 | With no argument, the targeted breakpoint is the last one set.\n\ | |
3388 | The commands themselves follow starting on the next line.\n\ | |
3389 | Type a line containing \"end\" to indicate the end of them.\n\ | |
3390 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
3391 | then no output is printed when it is hit, except what the commands print."); | |
3392 | ||
3393 | add_com ("condition", class_breakpoint, condition_command, | |
3394 | "Specify breakpoint number N to break only if COND is true.\n\ | |
d3b9c0df JG |
3395 | N is an integer; COND is an expression to be evaluated whenever\n\ |
3396 | breakpoint N is reached. "); | |
bd5635a1 RP |
3397 | |
3398 | add_com ("tbreak", class_breakpoint, tbreak_command, | |
3399 | "Set a temporary breakpoint. Args like \"break\" command.\n\ | |
c4de6b30 JK |
3400 | Like \"break\" except the breakpoint is only temporary,\n\ |
3401 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
3402 | by using \"enable delete\" on the breakpoint number."); | |
bd5635a1 RP |
3403 | |
3404 | add_prefix_cmd ("enable", class_breakpoint, enable_command, | |
3405 | "Enable some breakpoints.\n\ | |
3406 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
3407 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
3408 | This is used to cancel the effect of the \"disable\" command.\n\ | |
3409 | With a subcommand you can enable temporarily.", | |
3410 | &enablelist, "enable ", 1, &cmdlist); | |
3411 | ||
3412 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, | |
3413 | "Enable some breakpoints.\n\ | |
3414 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
3415 | This is used to cancel the effect of the \"disable\" command.\n\ | |
3416 | May be abbreviated to simply \"enable\".\n", | |
3417 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); | |
3418 | ||
3419 | add_cmd ("once", no_class, enable_once_command, | |
3420 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
bd2f0c85 | 3421 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", |
bd5635a1 RP |
3422 | &enablebreaklist); |
3423 | ||
3424 | add_cmd ("delete", no_class, enable_delete_command, | |
3425 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
3426 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
3427 | &enablebreaklist); | |
3428 | ||
3429 | add_cmd ("delete", no_class, enable_delete_command, | |
3430 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
3431 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
3432 | &enablelist); | |
3433 | ||
3434 | add_cmd ("once", no_class, enable_once_command, | |
3435 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
bd2f0c85 | 3436 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", |
bd5635a1 RP |
3437 | &enablelist); |
3438 | ||
3439 | add_prefix_cmd ("disable", class_breakpoint, disable_command, | |
3440 | "Disable some breakpoints.\n\ | |
3441 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3442 | To disable all breakpoints, give no argument.\n\ | |
3443 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", | |
3444 | &disablelist, "disable ", 1, &cmdlist); | |
3445 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
3446 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
3447 | ||
3448 | add_cmd ("breakpoints", class_alias, disable_command, | |
3449 | "Disable some breakpoints.\n\ | |
3450 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3451 | To disable all breakpoints, give no argument.\n\ | |
3452 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
3453 | This command may be abbreviated \"disable\".", | |
3454 | &disablelist); | |
3455 | ||
3456 | add_prefix_cmd ("delete", class_breakpoint, delete_command, | |
3457 | "Delete some breakpoints or auto-display expressions.\n\ | |
3458 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3459 | To delete all breakpoints, give no argument.\n\ | |
3460 | \n\ | |
3461 | Also a prefix command for deletion of other GDB objects.\n\ | |
3462 | The \"unset\" command is also an alias for \"delete\".", | |
3463 | &deletelist, "delete ", 1, &cmdlist); | |
3464 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
bd5635a1 RP |
3465 | |
3466 | add_cmd ("breakpoints", class_alias, delete_command, | |
3467 | "Delete some breakpoints or auto-display expressions.\n\ | |
3468 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3469 | To delete all breakpoints, give no argument.\n\ | |
3470 | This command may be abbreviated \"delete\".", | |
3471 | &deletelist); | |
3472 | ||
3473 | add_com ("clear", class_breakpoint, clear_command, | |
3474 | "Clear breakpoint at specified line or function.\n\ | |
3475 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
3476 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
3477 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
3478 | If an address is specified, breakpoints at that address are cleared.\n\n\ | |
3479 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
3480 | is executing in.\n\ | |
3481 | \n\ | |
3482 | See also the \"delete\" command which clears breakpoints by number."); | |
3483 | ||
3484 | add_com ("break", class_breakpoint, break_command, | |
3485 | "Set breakpoint at specified line or function.\n\ | |
3486 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
3487 | If line number is specified, break at start of code for that line.\n\ | |
3488 | If function is specified, break at start of code for that function.\n\ | |
3489 | If an address is specified, break at that exact address.\n\ | |
3490 | With no arg, uses current execution address of selected stack frame.\n\ | |
3491 | This is useful for breaking on return to a stack frame.\n\ | |
3492 | \n\ | |
3493 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
3494 | \n\ | |
3495 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
3496 | add_com_alias ("b", "break", class_run, 1); | |
3497 | add_com_alias ("br", "break", class_run, 1); | |
3498 | add_com_alias ("bre", "break", class_run, 1); | |
3499 | add_com_alias ("brea", "break", class_run, 1); | |
3500 | ||
3501 | add_info ("breakpoints", breakpoints_info, | |
80ba48f5 SG |
3502 | "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
3503 | The \"Type\" column indicates one of:\n\ | |
423e9664 SG |
3504 | \tbreakpoint - normal breakpoint\n\ |
3505 | \twatchpoint - watchpoint\n\ | |
80ba48f5 SG |
3506 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
3507 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
3508 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
3509 | address and file/line number respectively.\n\n\ | |
3510 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
3511 | are set to the address of the last breakpoint listed.\n\n\ | |
3512 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
3513 | breakpoint set."); | |
3514 | ||
9b280a7f JG |
3515 | #if MAINTENANCE_CMDS |
3516 | ||
3517 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, | |
bd5635a1 | 3518 | "Status of all breakpoints, or breakpoint number NUMBER.\n\ |
80ba48f5 | 3519 | The \"Type\" column indicates one of:\n\ |
423e9664 SG |
3520 | \tbreakpoint - normal breakpoint\n\ |
3521 | \twatchpoint - watchpoint\n\ | |
3522 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
3523 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
3524 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
3525 | \tfinish - internal breakpoint used by the \"finish\" command\n\ | |
80ba48f5 SG |
3526 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
3527 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
3528 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
3529 | address and file/line number respectively.\n\n\ | |
bd5635a1 RP |
3530 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
3531 | are set to the address of the last breakpoint listed.\n\n\ | |
3532 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
9b280a7f JG |
3533 | breakpoint set.", |
3534 | &maintenanceinfolist); | |
3535 | ||
3536 | #endif /* MAINTENANCE_CMDS */ | |
bd5635a1 RP |
3537 | |
3538 | add_com ("catch", class_breakpoint, catch_command, | |
3539 | "Set breakpoints to catch exceptions that are raised.\n\ | |
3540 | Argument may be a single exception to catch, multiple exceptions\n\ | |
3541 | to catch, or the default exception \"default\". If no arguments\n\ | |
3542 | are given, breakpoints are set at all exception handlers catch clauses\n\ | |
3543 | within the current scope.\n\ | |
3544 | \n\ | |
3545 | A condition specified for the catch applies to all breakpoints set\n\ | |
3546 | with this command\n\ | |
3547 | \n\ | |
3548 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
3549 | ||
3550 | add_com ("watch", class_breakpoint, watch_command, | |
3551 | "Set a watchpoint for an expression.\n\ | |
3552 | A watchpoint stops execution of your program whenever the value of\n\ | |
3553 | an expression changes."); | |
3554 | ||
c8950965 JG |
3555 | add_info ("watchpoints", breakpoints_info, |
3556 | "Synonym for ``info breakpoints''."); | |
bd5635a1 | 3557 | } |
1eeba686 | 3558 | |
2d313932 JK |
3559 | /* OK, when we call objfile_relocate, we need to relocate breakpoints |
3560 | too. breakpoint_re_set is not a good choice--for example, if | |
3561 | addr_string contains just a line number without a file name the | |
3562 | breakpoint might get set in a different file. In general, there is | |
3563 | no need to go all the way back to the user's string (though this might | |
3564 | work if some effort were made to canonicalize it), since symtabs and | |
3565 | everything except addresses are still valid. | |
1eeba686 | 3566 | |
2d313932 JK |
3567 | Probably the best way to solve this is to have each breakpoint save |
3568 | the objfile and the section number that was used to set it (if set | |
3569 | by "*addr", probably it is best to use find_pc_line to get a symtab | |
3570 | and use the objfile and block_line_section for that symtab). Then | |
3571 | objfile_relocate can call fixup_breakpoints with the objfile and | |
3572 | the new_offsets, and it can relocate only the appropriate breakpoints. */ | |
1eeba686 | 3573 | |
2d313932 JK |
3574 | #ifdef IBM6000_TARGET |
3575 | /* But for now, just kludge it based on the concept that before an | |
3576 | objfile is relocated the breakpoint is below 0x10000000, and afterwards | |
3577 | it is higher, so that way we only relocate each breakpoint once. */ | |
1eeba686 | 3578 | |
1eeba686 PB |
3579 | void |
3580 | fixup_breakpoints (low, high, delta) | |
3581 | CORE_ADDR low; | |
3582 | CORE_ADDR high; | |
3583 | CORE_ADDR delta; | |
3584 | { | |
3585 | struct breakpoint *b; | |
1eeba686 PB |
3586 | |
3587 | ALL_BREAKPOINTS (b) | |
3588 | { | |
3589 | if (b->address >= low && b->address <= high) | |
3590 | b->address += delta; | |
3591 | } | |
3592 | } | |
3593 | #endif |