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