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