Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Everything about breakpoints, for GDB. |
2 | Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999 | |
c5aa993b | 3 | Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
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. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include <ctype.h> | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
27 | #include "gdbtypes.h" | |
28 | #include "expression.h" | |
29 | #include "gdbcore.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "value.h" | |
32 | #include "command.h" | |
33 | #include "inferior.h" | |
34 | #include "gdbthread.h" | |
35 | #include "target.h" | |
36 | #include "language.h" | |
37 | #include "gdb_string.h" | |
38 | #include "demangle.h" | |
39 | #include "annotate.h" | |
40 | #include "symfile.h" | |
41 | #include "objfiles.h" | |
42 | ||
43 | /* Prototypes for local functions. */ | |
44 | ||
45 | static void | |
46 | catch_command_1 PARAMS ((char *, int, int)); | |
47 | ||
48 | static void | |
49 | enable_delete_command PARAMS ((char *, int)); | |
50 | ||
51 | static void | |
52 | enable_delete_breakpoint PARAMS ((struct breakpoint *)); | |
53 | ||
54 | static void | |
55 | enable_once_command PARAMS ((char *, int)); | |
56 | ||
57 | static void | |
58 | enable_once_breakpoint PARAMS ((struct breakpoint *)); | |
59 | ||
60 | static void | |
61 | disable_command PARAMS ((char *, int)); | |
62 | ||
63 | static void | |
64 | enable_command PARAMS ((char *, int)); | |
65 | ||
66 | static void | |
c5aa993b | 67 | map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *))); |
c906108c SS |
68 | |
69 | static void | |
70 | ignore_command PARAMS ((char *, int)); | |
71 | ||
72 | static int breakpoint_re_set_one PARAMS ((PTR)); | |
73 | ||
74 | static void | |
75 | clear_command PARAMS ((char *, int)); | |
76 | ||
77 | static void | |
78 | catch_command PARAMS ((char *, int)); | |
79 | ||
80 | static void | |
81 | handle_gnu_4_16_catch_command PARAMS ((char *, int, 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 | ||
89 | static int | |
90 | can_use_hardware_watchpoint PARAMS ((struct value *)); | |
91 | ||
7a292a7a SS |
92 | static void break_at_finish_command PARAMS ((char *, int)); |
93 | static void break_at_finish_at_depth_command PARAMS ((char *, int)); | |
94 | ||
c906108c SS |
95 | void |
96 | tbreak_command PARAMS ((char *, int)); | |
97 | ||
7a292a7a SS |
98 | static void tbreak_at_finish_command PARAMS ((char *, int)); |
99 | ||
c906108c SS |
100 | static void |
101 | break_command_1 PARAMS ((char *, int, int)); | |
102 | ||
103 | static void | |
104 | mention PARAMS ((struct breakpoint *)); | |
105 | ||
106 | struct breakpoint * | |
c5aa993b | 107 | set_raw_breakpoint PARAMS ((struct symtab_and_line)); |
c906108c SS |
108 | |
109 | static void | |
110 | check_duplicates PARAMS ((CORE_ADDR, asection *)); | |
111 | ||
112 | static void | |
113 | describe_other_breakpoints PARAMS ((CORE_ADDR, asection *)); | |
114 | ||
115 | static void | |
116 | breakpoints_info PARAMS ((char *, int)); | |
117 | ||
118 | static void | |
119 | breakpoint_1 PARAMS ((int, int)); | |
120 | ||
121 | static bpstat | |
c5aa993b | 122 | bpstat_alloc PARAMS ((struct breakpoint *, bpstat)); |
c906108c SS |
123 | |
124 | static int breakpoint_cond_eval PARAMS ((PTR)); | |
125 | ||
126 | static void | |
127 | cleanup_executing_breakpoints PARAMS ((PTR)); | |
128 | ||
129 | static void | |
130 | commands_command PARAMS ((char *, int)); | |
131 | ||
132 | static void | |
133 | condition_command PARAMS ((char *, int)); | |
134 | ||
135 | static int | |
136 | get_number PARAMS ((char **)); | |
137 | ||
138 | void | |
139 | set_breakpoint_count PARAMS ((int)); | |
140 | ||
141 | #if 0 | |
142 | static struct breakpoint * | |
c5aa993b | 143 | create_temp_exception_breakpoint PARAMS ((CORE_ADDR)); |
c906108c SS |
144 | #endif |
145 | ||
c5aa993b JM |
146 | typedef enum |
147 | { | |
148 | mark_inserted, | |
149 | mark_uninserted | |
150 | } | |
151 | insertion_state_t; | |
c906108c SS |
152 | |
153 | static int | |
154 | remove_breakpoint PARAMS ((struct breakpoint *, insertion_state_t)); | |
155 | ||
156 | static int print_it_normal PARAMS ((bpstat)); | |
157 | ||
c5aa993b JM |
158 | typedef struct |
159 | { | |
160 | enum exception_event_kind kind; | |
161 | int enable; | |
162 | } | |
163 | args_for_catchpoint_enable; | |
c906108c SS |
164 | |
165 | static int watchpoint_check PARAMS ((PTR)); | |
166 | ||
167 | static int cover_target_enable_exception_callback PARAMS ((PTR)); | |
168 | ||
169 | static int print_it_done PARAMS ((bpstat)); | |
170 | ||
171 | static int print_it_noop PARAMS ((bpstat)); | |
172 | ||
173 | static void maintenance_info_breakpoints PARAMS ((char *, int)); | |
174 | ||
175 | #ifdef GET_LONGJMP_TARGET | |
176 | static void create_longjmp_breakpoint PARAMS ((char *)); | |
177 | #endif | |
178 | ||
179 | static int hw_breakpoint_used_count PARAMS ((void)); | |
180 | ||
181 | static int hw_watchpoint_used_count PARAMS ((enum bptype, int *)); | |
182 | ||
183 | static void hbreak_command PARAMS ((char *, int)); | |
184 | ||
185 | static void thbreak_command PARAMS ((char *, int)); | |
186 | ||
187 | static void watch_command_1 PARAMS ((char *, int, int)); | |
188 | ||
189 | static void rwatch_command PARAMS ((char *, int)); | |
190 | ||
191 | static void awatch_command PARAMS ((char *, int)); | |
192 | ||
193 | static void do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp)); | |
194 | ||
53a5351d JM |
195 | static void solib_load_unload_1 PARAMS ((char *hookname, |
196 | int tempflag, | |
197 | char *dll_pathname, | |
198 | char *cond_string, | |
199 | enum bptype bp_kind)); | |
7a292a7a | 200 | |
53a5351d JM |
201 | static void create_fork_vfork_event_catchpoint PARAMS ((int tempflag, |
202 | char *cond_string, | |
203 | enum bptype bp_kind)); | |
7a292a7a | 204 | |
53a5351d JM |
205 | static void break_at_finish_at_depth_command_1 PARAMS ((char *arg, |
206 | int flag, | |
207 | int from_tty)); | |
7a292a7a | 208 | |
53a5351d JM |
209 | static void break_at_finish_command_1 PARAMS ((char *arg, |
210 | int flag, | |
211 | int from_tty)); | |
7a292a7a SS |
212 | |
213 | static void stop_command PARAMS ((char *arg, int from_tty)); | |
214 | ||
215 | static void stopin_command PARAMS ((char *arg, int from_tty)); | |
216 | ||
217 | static void stopat_command PARAMS ((char *arg, int from_tty)); | |
218 | ||
219 | static char *ep_find_event_name_end PARAMS ((char *arg)); | |
220 | ||
221 | static char *ep_parse_optional_if_clause PARAMS ((char **arg)); | |
222 | ||
223 | static char *ep_parse_optional_filename PARAMS ((char **arg)); | |
224 | ||
53a5351d JM |
225 | static void catch_exec_command_1 PARAMS ((char *arg, int tempflag, |
226 | int from_tty)); | |
7a292a7a | 227 | |
53a5351d JM |
228 | static void create_exception_catchpoint |
229 | PARAMS ((int tempflag, char *cond_string, | |
230 | enum exception_event_kind ex_event, | |
231 | struct symtab_and_line * sal)); | |
7a292a7a | 232 | |
53a5351d JM |
233 | static void catch_exception_command_1 |
234 | PARAMS ((enum exception_event_kind ex_event, | |
235 | char *arg, int tempflag, int from_tty)); | |
7a292a7a SS |
236 | |
237 | static void tcatch_command PARAMS ((char *arg, int from_tty)); | |
238 | ||
239 | static void ep_skip_leading_whitespace PARAMS ((char **s)); | |
240 | ||
c906108c SS |
241 | /* Prototypes for exported functions. */ |
242 | ||
243 | static void | |
244 | awatch_command PARAMS ((char *, int)); | |
245 | ||
246 | static void | |
247 | do_enable_breakpoint PARAMS ((struct breakpoint *, enum bpdisp)); | |
248 | ||
249 | /* If FALSE, gdb will not use hardware support for watchpoints, even | |
250 | if such is available. */ | |
251 | static int can_use_hw_watchpoints; | |
252 | ||
253 | void delete_command PARAMS ((char *, int)); | |
254 | ||
255 | void _initialize_breakpoint PARAMS ((void)); | |
256 | ||
257 | void set_breakpoint_count PARAMS ((int)); | |
258 | ||
c5aa993b | 259 | extern int addressprint; /* Print machine addresses? */ |
c906108c SS |
260 | |
261 | #if defined (GET_LONGJMP_TARGET) || defined (SOLIB_ADD) | |
262 | static int internal_breakpoint_number = -1; | |
263 | #endif | |
264 | ||
265 | /* Are we executing breakpoint commands? */ | |
266 | static int executing_breakpoint_commands; | |
267 | ||
268 | /* Walk the following statement or block through all breakpoints. | |
269 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
270 | breakpoint. */ | |
271 | ||
272 | #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) | |
273 | ||
274 | #define ALL_BREAKPOINTS_SAFE(b,tmp) \ | |
275 | for (b = breakpoint_chain; \ | |
276 | b? (tmp=b->next, 1): 0; \ | |
277 | b = tmp) | |
278 | ||
279 | /* True if SHIFT_INST_REGS defined, false otherwise. */ | |
280 | ||
281 | int must_shift_inst_regs = | |
282 | #if defined(SHIFT_INST_REGS) | |
283 | 1 | |
284 | #else | |
285 | 0 | |
286 | #endif | |
c5aa993b | 287 | ; |
c906108c SS |
288 | |
289 | /* True if breakpoint hit counts should be displayed in breakpoint info. */ | |
290 | ||
291 | int show_breakpoint_hit_counts = 1; | |
292 | ||
293 | /* Chain of all breakpoints defined. */ | |
294 | ||
295 | struct breakpoint *breakpoint_chain; | |
296 | ||
297 | /* Number of last breakpoint made. */ | |
298 | ||
299 | int breakpoint_count; | |
300 | ||
c5aa993b JM |
301 | /* Pointer to current exception event record */ |
302 | static struct exception_event_record *current_exception_event; | |
c906108c SS |
303 | |
304 | /* Indicator of whether exception catchpoints should be nuked | |
305 | between runs of a program */ | |
306 | int exception_catchpoints_are_fragile = 0; | |
c5aa993b | 307 | |
c906108c SS |
308 | /* Indicator of when exception catchpoints set-up should be |
309 | reinitialized -- e.g. when program is re-run */ | |
310 | int exception_support_initialized = 0; | |
311 | ||
312 | /* This function returns a pointer to the string representation of the | |
313 | pathname of the dynamically-linked library that has just been | |
314 | loaded. | |
315 | ||
316 | This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE, | |
317 | or undefined results are guaranteed. | |
318 | ||
319 | This string's contents are only valid immediately after the | |
320 | inferior has stopped in the dynamic linker hook, and becomes | |
321 | invalid as soon as the inferior is continued. Clients should make | |
322 | a copy of this string if they wish to continue the inferior and | |
323 | then access the string. */ | |
324 | ||
325 | #ifndef SOLIB_LOADED_LIBRARY_PATHNAME | |
326 | #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) "" | |
327 | #endif | |
328 | ||
329 | /* This function returns a pointer to the string representation of the | |
330 | pathname of the dynamically-linked library that has just been | |
331 | unloaded. | |
332 | ||
333 | This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is | |
334 | TRUE, or undefined results are guaranteed. | |
335 | ||
336 | This string's contents are only valid immediately after the | |
337 | inferior has stopped in the dynamic linker hook, and becomes | |
338 | invalid as soon as the inferior is continued. Clients should make | |
339 | a copy of this string if they wish to continue the inferior and | |
340 | then access the string. */ | |
341 | ||
342 | #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME | |
343 | #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) "" | |
344 | #endif | |
345 | ||
346 | /* This function is called by the "catch load" command. It allows the | |
347 | debugger to be notified by the dynamic linker when a specified | |
348 | library file (or any library file, if filename is NULL) is loaded. */ | |
349 | ||
350 | #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK | |
351 | #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \ | |
352 | error ("catch of library loads not yet implemented on this platform") | |
353 | #endif | |
354 | ||
355 | /* This function is called by the "catch unload" command. It allows | |
356 | the debugger to be notified by the dynamic linker when a specified | |
357 | library file (or any library file, if filename is NULL) is | |
358 | unloaded. */ | |
359 | ||
360 | #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK | |
361 | #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \ | |
362 | error ("catch of library unloads not yet implemented on this platform") | |
363 | #endif | |
364 | ||
365 | /* Set breakpoint count to NUM. */ | |
366 | ||
367 | void | |
368 | set_breakpoint_count (num) | |
369 | int num; | |
370 | { | |
371 | breakpoint_count = num; | |
372 | set_internalvar (lookup_internalvar ("bpnum"), | |
373 | value_from_longest (builtin_type_int, (LONGEST) num)); | |
374 | } | |
375 | ||
376 | /* Used in run_command to zero the hit count when a new run starts. */ | |
377 | ||
378 | void | |
379 | clear_breakpoint_hit_counts () | |
380 | { | |
381 | struct breakpoint *b; | |
382 | ||
383 | ALL_BREAKPOINTS (b) | |
384 | b->hit_count = 0; | |
385 | } | |
386 | ||
387 | /* Default address, symtab and line to put a breakpoint at | |
388 | for "break" command with no arg. | |
389 | if default_breakpoint_valid is zero, the other three are | |
390 | not valid, and "break" with no arg is an error. | |
391 | ||
392 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
393 | ||
394 | int default_breakpoint_valid; | |
395 | CORE_ADDR default_breakpoint_address; | |
396 | struct symtab *default_breakpoint_symtab; | |
397 | int default_breakpoint_line; | |
398 | \f | |
399 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
400 | Advance *PP after the string and any trailing whitespace. | |
401 | ||
402 | Currently the string can either be a number or "$" followed by the name | |
403 | of a convenience variable. Making it an expression wouldn't work well | |
404 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */ | |
405 | static int | |
406 | get_number (pp) | |
407 | char **pp; | |
408 | { | |
409 | int retval; | |
410 | char *p = *pp; | |
411 | ||
412 | if (p == NULL) | |
413 | /* Empty line means refer to the last breakpoint. */ | |
414 | return breakpoint_count; | |
415 | else if (*p == '$') | |
416 | { | |
417 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 418 | to pass to lookup_internalvar(). */ |
c906108c SS |
419 | char *varname; |
420 | char *start = ++p; | |
421 | value_ptr val; | |
422 | ||
423 | while (isalnum (*p) || *p == '_') | |
424 | p++; | |
425 | varname = (char *) alloca (p - start + 1); | |
426 | strncpy (varname, start, p - start); | |
427 | varname[p - start] = '\0'; | |
428 | val = value_of_internalvar (lookup_internalvar (varname)); | |
429 | if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT) | |
430 | error ( | |
53a5351d | 431 | "Convenience variables used to specify breakpoints must have integer values." |
c5aa993b | 432 | ); |
c906108c SS |
433 | retval = (int) value_as_long (val); |
434 | } | |
435 | else | |
436 | { | |
437 | if (*p == '-') | |
438 | ++p; | |
439 | while (*p >= '0' && *p <= '9') | |
440 | ++p; | |
441 | if (p == *pp) | |
442 | /* There is no number here. (e.g. "cond a == b"). */ | |
443 | error_no_arg ("breakpoint number"); | |
444 | retval = atoi (*pp); | |
445 | } | |
446 | if (!(isspace (*p) || *p == '\0')) | |
447 | error ("breakpoint number expected"); | |
448 | while (isspace (*p)) | |
449 | p++; | |
450 | *pp = p; | |
451 | return retval; | |
452 | } | |
453 | \f | |
454 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
455 | ||
456 | static void | |
457 | condition_command (arg, from_tty) | |
458 | char *arg; | |
459 | int from_tty; | |
460 | { | |
461 | register struct breakpoint *b; | |
462 | char *p; | |
463 | register int bnum; | |
464 | ||
465 | if (arg == 0) | |
466 | error_no_arg ("breakpoint number"); | |
467 | ||
468 | p = arg; | |
469 | bnum = get_number (&p); | |
470 | ||
471 | ALL_BREAKPOINTS (b) | |
472 | if (b->number == bnum) | |
c5aa993b JM |
473 | { |
474 | if (b->cond) | |
475 | { | |
476 | free ((PTR) b->cond); | |
477 | b->cond = 0; | |
478 | } | |
479 | if (b->cond_string != NULL) | |
480 | free ((PTR) b->cond_string); | |
c906108c | 481 | |
c5aa993b JM |
482 | if (*p == 0) |
483 | { | |
484 | b->cond = 0; | |
485 | b->cond_string = NULL; | |
486 | if (from_tty) | |
487 | printf_filtered ("Breakpoint %d now unconditional.\n", bnum); | |
488 | } | |
489 | else | |
490 | { | |
491 | arg = p; | |
492 | /* I don't know if it matters whether this is the string the user | |
493 | typed in or the decompiled expression. */ | |
494 | b->cond_string = savestring (arg, strlen (arg)); | |
495 | b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0); | |
496 | if (*arg) | |
497 | error ("Junk at end of expression"); | |
498 | } | |
499 | breakpoints_changed (); | |
500 | return; | |
501 | } | |
c906108c SS |
502 | |
503 | error ("No breakpoint number %d.", bnum); | |
504 | } | |
505 | ||
506 | /* ARGSUSED */ | |
507 | static void | |
508 | commands_command (arg, from_tty) | |
509 | char *arg; | |
510 | int from_tty; | |
511 | { | |
512 | register struct breakpoint *b; | |
513 | char *p; | |
514 | register int bnum; | |
515 | struct command_line *l; | |
516 | ||
517 | /* If we allowed this, we would have problems with when to | |
518 | free the storage, if we change the commands currently | |
519 | being read from. */ | |
520 | ||
521 | if (executing_breakpoint_commands) | |
522 | error ("Can't use the \"commands\" command among a breakpoint's commands."); | |
523 | ||
524 | p = arg; | |
525 | bnum = get_number (&p); | |
526 | if (p && *p) | |
527 | error ("Unexpected extra arguments following breakpoint number."); | |
c5aa993b | 528 | |
c906108c SS |
529 | ALL_BREAKPOINTS (b) |
530 | if (b->number == bnum) | |
c5aa993b JM |
531 | { |
532 | char tmpbuf[128]; | |
53a5351d JM |
533 | sprintf (tmpbuf, |
534 | "Type commands for when breakpoint %d is hit, one per line.", | |
535 | bnum); | |
c5aa993b JM |
536 | l = read_command_lines (tmpbuf, from_tty); |
537 | free_command_lines (&b->commands); | |
538 | b->commands = l; | |
539 | breakpoints_changed (); | |
540 | return; | |
541 | } | |
c906108c SS |
542 | error ("No breakpoint number %d.", bnum); |
543 | } | |
544 | \f | |
545 | /* Like target_read_memory() but if breakpoints are inserted, return | |
546 | the shadow contents instead of the breakpoints themselves. | |
547 | ||
548 | Read "memory data" from whatever target or inferior we have. | |
549 | Returns zero if successful, errno value if not. EIO is used | |
550 | for address out of bounds. If breakpoints are inserted, returns | |
551 | shadow contents, not the breakpoints themselves. From breakpoint.c. */ | |
552 | ||
553 | int | |
554 | read_memory_nobpt (memaddr, myaddr, len) | |
555 | CORE_ADDR memaddr; | |
556 | char *myaddr; | |
557 | unsigned len; | |
558 | { | |
559 | int status; | |
560 | struct breakpoint *b; | |
561 | CORE_ADDR bp_addr = 0; | |
562 | int bp_size = 0; | |
563 | ||
564 | if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL) | |
565 | /* No breakpoints on this machine. */ | |
566 | return target_read_memory (memaddr, myaddr, len); | |
c5aa993b | 567 | |
c906108c | 568 | ALL_BREAKPOINTS (b) |
c5aa993b JM |
569 | { |
570 | if (b->type == bp_none) | |
53a5351d JM |
571 | warning ("reading through apparently deleted breakpoint #%d?", |
572 | b->number); | |
c5aa993b JM |
573 | |
574 | /* memory breakpoint? */ | |
575 | if (b->type == bp_watchpoint | |
576 | || b->type == bp_hardware_watchpoint | |
577 | || b->type == bp_read_watchpoint | |
578 | || b->type == bp_access_watchpoint) | |
579 | continue; | |
580 | /* bp in memory? */ | |
581 | if (!b->inserted) | |
582 | continue; | |
583 | /* Addresses and length of the part of the breakpoint that | |
584 | we need to copy. */ | |
585 | /* XXXX The m68k, sh and h8300 have different local and remote | |
586 | breakpoint values. BREAKPOINT_FROM_PC still manages to | |
587 | correctly determine the breakpoints memory address and size | |
588 | for these targets. */ | |
589 | bp_addr = b->address; | |
590 | bp_size = 0; | |
591 | if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL) | |
592 | continue; | |
593 | if (bp_size == 0) | |
594 | /* bp isn't valid */ | |
595 | continue; | |
596 | if (bp_addr + bp_size <= memaddr) | |
597 | /* The breakpoint is entirely before the chunk of memory we | |
598 | are reading. */ | |
599 | continue; | |
600 | if (bp_addr >= memaddr + len) | |
601 | /* The breakpoint is entirely after the chunk of memory we are | |
602 | reading. */ | |
603 | continue; | |
604 | /* Copy the breakpoint from the shadow contents, and recurse for | |
605 | the things before and after. */ | |
c906108c | 606 | { |
c5aa993b JM |
607 | /* Offset within shadow_contents. */ |
608 | int bptoffset = 0; | |
c906108c | 609 | |
c5aa993b JM |
610 | if (bp_addr < memaddr) |
611 | { | |
612 | /* Only copy the second part of the breakpoint. */ | |
613 | bp_size -= memaddr - bp_addr; | |
614 | bptoffset = memaddr - bp_addr; | |
615 | bp_addr = memaddr; | |
616 | } | |
617 | ||
618 | if (bp_addr + bp_size > memaddr + len) | |
619 | { | |
620 | /* Only copy the first part of the breakpoint. */ | |
621 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
622 | } | |
623 | ||
624 | memcpy (myaddr + bp_addr - memaddr, | |
625 | b->shadow_contents + bptoffset, bp_size); | |
626 | ||
627 | if (bp_addr > memaddr) | |
628 | { | |
629 | /* Copy the section of memory before the breakpoint. */ | |
630 | status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr); | |
631 | if (status != 0) | |
632 | return status; | |
633 | } | |
634 | ||
635 | if (bp_addr + bp_size < memaddr + len) | |
636 | { | |
637 | /* Copy the section of memory after the breakpoint. */ | |
638 | status = read_memory_nobpt | |
639 | (bp_addr + bp_size, | |
640 | myaddr + bp_addr + bp_size - memaddr, | |
641 | memaddr + len - (bp_addr + bp_size)); | |
642 | if (status != 0) | |
643 | return status; | |
644 | } | |
645 | return 0; | |
c906108c | 646 | } |
c5aa993b | 647 | } |
c906108c SS |
648 | /* Nothing overlaps. Just call read_memory_noerr. */ |
649 | return target_read_memory (memaddr, myaddr, len); | |
650 | } | |
c906108c | 651 | \f |
c5aa993b | 652 | |
c906108c SS |
653 | /* insert_breakpoints is used when starting or continuing the program. |
654 | remove_breakpoints is used when the program stops. | |
655 | Both return zero if successful, | |
656 | or an `errno' value if could not write the inferior. */ | |
657 | ||
658 | int | |
659 | insert_breakpoints () | |
660 | { | |
661 | register struct breakpoint *b, *temp; | |
53a5351d | 662 | int return_val = 0; /* return success code. */ |
c906108c SS |
663 | int val = 0; |
664 | int disabled_breaks = 0; | |
665 | ||
666 | static char message1[] = "Error inserting catchpoint %d:\n"; | |
667 | static char message[sizeof (message1) + 30]; | |
668 | ||
669 | ||
670 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
671 | { |
672 | if (b->type != bp_watchpoint | |
673 | && b->type != bp_hardware_watchpoint | |
674 | && b->type != bp_read_watchpoint | |
675 | && b->type != bp_access_watchpoint | |
676 | && b->type != bp_catch_fork | |
677 | && b->type != bp_catch_vfork | |
678 | && b->type != bp_catch_exec | |
679 | && b->type != bp_catch_throw | |
680 | && b->type != bp_catch_catch | |
681 | && b->enable != disabled | |
682 | && b->enable != shlib_disabled | |
683 | && b->enable != call_disabled | |
684 | && !b->inserted | |
685 | && !b->duplicate) | |
686 | { | |
687 | if (b->type == bp_hardware_breakpoint) | |
688 | val = target_insert_hw_breakpoint (b->address, b->shadow_contents); | |
689 | else | |
690 | { | |
691 | /* Check to see if breakpoint is in an overlay section; | |
692 | if so, we should set the breakpoint at the LMA address. | |
693 | Only if the section is currently mapped should we ALSO | |
694 | set a break at the VMA address. */ | |
695 | if (overlay_debugging && b->section && | |
696 | section_is_overlay (b->section)) | |
697 | { | |
698 | CORE_ADDR addr; | |
699 | ||
700 | addr = overlay_unmapped_address (b->address, b->section); | |
701 | val = target_insert_breakpoint (addr, b->shadow_contents); | |
702 | /* This would be the time to check val, to see if the | |
703 | breakpoint write to the load address succeeded. | |
704 | However, this might be an ordinary occurrance, eg. if | |
705 | the unmapped overlay is in ROM. */ | |
706 | val = 0; /* in case unmapped address failed */ | |
707 | if (section_is_mapped (b->section)) | |
708 | val = target_insert_breakpoint (b->address, | |
709 | b->shadow_contents); | |
710 | } | |
711 | else /* ordinary (non-overlay) address */ | |
712 | val = target_insert_breakpoint (b->address, b->shadow_contents); | |
713 | } | |
714 | if (val) | |
715 | { | |
716 | /* Can't set the breakpoint. */ | |
c906108c | 717 | #if defined (DISABLE_UNSETTABLE_BREAK) |
c5aa993b JM |
718 | if (DISABLE_UNSETTABLE_BREAK (b->address)) |
719 | { | |
720 | /* See also: disable_breakpoints_in_shlibs. */ | |
721 | val = 0; | |
722 | b->enable = shlib_disabled; | |
723 | if (!disabled_breaks) | |
724 | { | |
725 | target_terminal_ours_for_output (); | |
53a5351d JM |
726 | warning ("Cannot insert breakpoint %d:", b->number); |
727 | warning ("Temporarily disabling shared library breakpoints:"); | |
c5aa993b JM |
728 | } |
729 | disabled_breaks = 1; | |
53a5351d | 730 | warning ("breakpoint #%d ", b->number); |
c5aa993b JM |
731 | } |
732 | else | |
c906108c | 733 | #endif |
c5aa993b JM |
734 | { |
735 | target_terminal_ours_for_output (); | |
53a5351d | 736 | warning ("Cannot insert breakpoint %d:", b->number); |
c906108c | 737 | #ifdef ONE_PROCESS_WRITETEXT |
53a5351d | 738 | warning ("The same program may be running in another process."); |
c906108c | 739 | #endif |
53a5351d | 740 | memory_error (val, b->address); /* which bombs us out */ |
c5aa993b JM |
741 | } |
742 | } | |
743 | else | |
744 | b->inserted = 1; | |
53a5351d JM |
745 | |
746 | if (val) | |
747 | return_val = val; /* remember failure */ | |
c5aa993b | 748 | } |
c906108c | 749 | else if (ep_is_exception_catchpoint (b) |
c5aa993b JM |
750 | && b->enable != disabled |
751 | && b->enable != shlib_disabled | |
752 | && b->enable != call_disabled | |
753 | && !b->inserted | |
754 | && !b->duplicate) | |
c906108c SS |
755 | |
756 | { | |
c5aa993b JM |
757 | /* If we get here, we must have a callback mechanism for exception |
758 | events -- with g++ style embedded label support, we insert | |
759 | ordinary breakpoints and not catchpoints. */ | |
53a5351d JM |
760 | /* Format possible error message */ |
761 | sprintf (message, message1, b->number); | |
c5aa993b JM |
762 | |
763 | val = target_insert_breakpoint (b->address, b->shadow_contents); | |
764 | if (val) | |
765 | { | |
766 | /* Couldn't set breakpoint for some reason */ | |
767 | target_terminal_ours_for_output (); | |
53a5351d JM |
768 | warning ("Cannot insert catchpoint %d; disabling it.", |
769 | b->number); | |
c5aa993b JM |
770 | b->enable = disabled; |
771 | } | |
772 | else | |
773 | { | |
774 | /* Bp set, now make sure callbacks are enabled */ | |
c906108c | 775 | int val; |
c5aa993b | 776 | args_for_catchpoint_enable args; |
53a5351d JM |
777 | args.kind = b->type == bp_catch_catch ? |
778 | EX_EVENT_CATCH : EX_EVENT_THROW; | |
c906108c SS |
779 | args.enable = 1; |
780 | val = catch_errors (cover_target_enable_exception_callback, | |
781 | &args, | |
782 | message, RETURN_MASK_ALL); | |
783 | if (val != 0 && val != -1) | |
784 | { | |
785 | b->inserted = 1; | |
786 | } | |
c5aa993b | 787 | /* Check if something went wrong; val == 0 can be ignored */ |
c906108c SS |
788 | if (val == -1) |
789 | { | |
c5aa993b | 790 | /* something went wrong */ |
c906108c | 791 | target_terminal_ours_for_output (); |
53a5351d JM |
792 | warning ("Cannot insert catchpoint %d; disabling it.", |
793 | b->number); | |
c906108c SS |
794 | b->enable = disabled; |
795 | } | |
c5aa993b | 796 | } |
53a5351d JM |
797 | |
798 | if (val) | |
799 | return_val = val; /* remember failure */ | |
c906108c SS |
800 | } |
801 | ||
c5aa993b JM |
802 | else if ((b->type == bp_hardware_watchpoint || |
803 | b->type == bp_read_watchpoint || | |
804 | b->type == bp_access_watchpoint) | |
805 | && b->enable == enabled | |
806 | && !b->inserted | |
807 | && !b->duplicate) | |
808 | { | |
809 | struct frame_info *saved_frame; | |
810 | int saved_level, within_current_scope; | |
811 | value_ptr mark = value_mark (); | |
812 | value_ptr v; | |
813 | ||
814 | /* Save the current frame and level so we can restore it after | |
815 | evaluating the watchpoint expression on its own frame. */ | |
816 | saved_frame = selected_frame; | |
817 | saved_level = selected_frame_level; | |
818 | ||
819 | /* Determine if the watchpoint is within scope. */ | |
820 | if (b->exp_valid_block == NULL) | |
821 | within_current_scope = 1; | |
822 | else | |
823 | { | |
824 | struct frame_info *fi; | |
825 | ||
826 | /* There might be no current frame at this moment if we are | |
827 | resuming from a step over a breakpoint. | |
828 | Set up current frame before trying to find the watchpoint | |
829 | frame. */ | |
830 | get_current_frame (); | |
831 | fi = find_frame_addr_in_frame_chain (b->watchpoint_frame); | |
832 | within_current_scope = (fi != NULL); | |
833 | if (within_current_scope) | |
834 | select_frame (fi, -1); | |
835 | } | |
836 | ||
837 | if (within_current_scope) | |
838 | { | |
839 | /* Evaluate the expression and cut the chain of values | |
840 | produced off from the value chain. */ | |
841 | v = evaluate_expression (b->exp); | |
842 | value_release_to_mark (mark); | |
843 | ||
844 | b->val_chain = v; | |
845 | b->inserted = 1; | |
846 | ||
847 | /* Look at each value on the value chain. */ | |
848 | for (; v; v = v->next) | |
849 | { | |
850 | /* If it's a memory location, then we must watch it. */ | |
851 | if (v->lval == lval_memory) | |
852 | { | |
853 | int addr, len, type; | |
854 | ||
855 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
856 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
53a5351d | 857 | type = hw_write; |
c5aa993b | 858 | if (b->type == bp_read_watchpoint) |
53a5351d | 859 | type = hw_read; |
c5aa993b | 860 | else if (b->type == bp_access_watchpoint) |
53a5351d | 861 | type = hw_access; |
c5aa993b JM |
862 | |
863 | val = target_insert_watchpoint (addr, len, type); | |
864 | if (val == -1) | |
865 | { | |
866 | b->inserted = 0; | |
867 | break; | |
868 | } | |
869 | val = 0; | |
870 | } | |
871 | } | |
872 | /* Failure to insert a watchpoint on any memory value in the | |
873 | value chain brings us here. */ | |
874 | if (!b->inserted) | |
53a5351d JM |
875 | { |
876 | remove_breakpoint (b, mark_uninserted); | |
877 | warning ("Could not insert hardware watchpoint %d.", | |
878 | b->number); | |
879 | val = -1; | |
880 | } | |
c5aa993b JM |
881 | } |
882 | else | |
883 | { | |
53a5351d JM |
884 | printf_filtered ("Hardware watchpoint %d deleted", b->number); |
885 | printf_filtered ("because the program has left the block \n"); | |
886 | printf_filtered ("in which its expression is valid.\n"); | |
c5aa993b JM |
887 | if (b->related_breakpoint) |
888 | b->related_breakpoint->disposition = del_at_next_stop; | |
889 | b->disposition = del_at_next_stop; | |
890 | } | |
c906108c | 891 | |
c5aa993b JM |
892 | /* Restore the frame and level. */ |
893 | if ((saved_frame != selected_frame) || | |
894 | (saved_level != selected_frame_level)) | |
895 | select_and_print_frame (saved_frame, saved_level); | |
53a5351d JM |
896 | |
897 | if (val) | |
898 | return_val = val; /* remember failure */ | |
c5aa993b JM |
899 | } |
900 | else if ((b->type == bp_catch_fork | |
901 | || b->type == bp_catch_vfork | |
902 | || b->type == bp_catch_exec) | |
903 | && b->enable == enabled | |
904 | && !b->inserted | |
905 | && !b->duplicate) | |
906 | { | |
907 | val = -1; | |
908 | switch (b->type) | |
909 | { | |
910 | case bp_catch_fork: | |
911 | val = target_insert_fork_catchpoint (inferior_pid); | |
912 | break; | |
913 | case bp_catch_vfork: | |
914 | val = target_insert_vfork_catchpoint (inferior_pid); | |
915 | break; | |
916 | case bp_catch_exec: | |
917 | val = target_insert_exec_catchpoint (inferior_pid); | |
918 | break; | |
919 | default: | |
53a5351d | 920 | warning ("Internal error, %s line %d.", __FILE__, __LINE__); |
c5aa993b JM |
921 | break; |
922 | } | |
923 | if (val < 0) | |
924 | { | |
925 | target_terminal_ours_for_output (); | |
53a5351d | 926 | warning ("Cannot insert catchpoint %d.", b->number); |
c5aa993b JM |
927 | } |
928 | else | |
929 | b->inserted = 1; | |
53a5351d JM |
930 | |
931 | if (val) | |
932 | return_val = val; /* remember failure */ | |
c5aa993b JM |
933 | } |
934 | } | |
c906108c | 935 | |
53a5351d | 936 | return return_val; |
c906108c SS |
937 | } |
938 | ||
939 | ||
940 | int | |
941 | remove_breakpoints () | |
942 | { | |
943 | register struct breakpoint *b; | |
944 | int val; | |
945 | ||
946 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
947 | { |
948 | if (b->inserted) | |
949 | { | |
950 | val = remove_breakpoint (b, mark_uninserted); | |
951 | if (val != 0) | |
952 | return val; | |
953 | } | |
954 | } | |
c906108c SS |
955 | return 0; |
956 | } | |
957 | ||
958 | int | |
959 | reattach_breakpoints (pid) | |
c5aa993b | 960 | int pid; |
c906108c SS |
961 | { |
962 | register struct breakpoint *b; | |
963 | int val; | |
c5aa993b | 964 | int saved_inferior_pid = inferior_pid; |
c906108c | 965 | |
53a5351d JM |
966 | /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */ |
967 | inferior_pid = pid; /* Because remove_breakpoint will use this global. */ | |
c906108c | 968 | ALL_BREAKPOINTS (b) |
c5aa993b JM |
969 | { |
970 | if (b->inserted) | |
971 | { | |
972 | remove_breakpoint (b, mark_inserted); | |
973 | if (b->type == bp_hardware_breakpoint) | |
974 | val = target_insert_hw_breakpoint (b->address, b->shadow_contents); | |
975 | else | |
976 | val = target_insert_breakpoint (b->address, b->shadow_contents); | |
977 | if (val != 0) | |
978 | { | |
979 | inferior_pid = saved_inferior_pid; | |
980 | return val; | |
981 | } | |
982 | } | |
983 | } | |
c906108c SS |
984 | inferior_pid = saved_inferior_pid; |
985 | return 0; | |
986 | } | |
987 | ||
988 | void | |
989 | update_breakpoints_after_exec () | |
990 | { | |
c5aa993b JM |
991 | struct breakpoint *b; |
992 | struct breakpoint *temp; | |
c906108c SS |
993 | |
994 | /* Doing this first prevents the badness of having delete_breakpoint() | |
995 | write a breakpoint's current "shadow contents" to lift the bp. That | |
996 | shadow is NOT valid after an exec()! */ | |
997 | mark_breakpoints_out (); | |
998 | ||
999 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1000 | { |
1001 | /* Solib breakpoints must be explicitly reset after an exec(). */ | |
1002 | if (b->type == bp_shlib_event) | |
1003 | { | |
1004 | delete_breakpoint (b); | |
1005 | continue; | |
1006 | } | |
c906108c | 1007 | |
c5aa993b JM |
1008 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1009 | if (b->type == bp_step_resume) | |
1010 | { | |
1011 | delete_breakpoint (b); | |
1012 | continue; | |
1013 | } | |
1014 | ||
1015 | /* Ditto the sigtramp handler breakpoints. */ | |
1016 | if (b->type == bp_through_sigtramp) | |
1017 | { | |
1018 | delete_breakpoint (b); | |
1019 | continue; | |
1020 | } | |
1021 | ||
1022 | /* Ditto the exception-handling catchpoints. */ | |
1023 | if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw)) | |
1024 | { | |
1025 | delete_breakpoint (b); | |
1026 | continue; | |
1027 | } | |
1028 | ||
1029 | /* Don't delete an exec catchpoint, because else the inferior | |
1030 | won't stop when it ought! | |
1031 | ||
1032 | Similarly, we probably ought to keep vfork catchpoints, 'cause | |
53a5351d JM |
1033 | on this target, we may not be able to stop when the vfork is |
1034 | seen, but only when the subsequent exec is seen. (And because | |
1035 | deleting fork catchpoints here but not vfork catchpoints will | |
1036 | seem mysterious to users, keep those too.) | |
c5aa993b JM |
1037 | |
1038 | ??rehrauer: Let's hope that merely clearing out this catchpoint's | |
1039 | target address field, if any, is sufficient to have it be reset | |
1040 | automagically. Certainly on HP-UX that's true. */ | |
1041 | if ((b->type == bp_catch_exec) || | |
1042 | (b->type == bp_catch_vfork) || | |
1043 | (b->type == bp_catch_fork)) | |
1044 | { | |
1045 | b->address = (CORE_ADDR) NULL; | |
1046 | continue; | |
1047 | } | |
1048 | ||
1049 | /* bp_finish is a special case. The only way we ought to be able | |
1050 | to see one of these when an exec() has happened, is if the user | |
1051 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1052 | carries them to the call-site of the current callee, by setting | |
1053 | a temporary bp there and resuming. But in this case, the finish | |
1054 | will carry them entirely through the vfork & exec. | |
1055 | ||
1056 | We don't want to allow a bp_finish to remain inserted now. But | |
1057 | we can't safely delete it, 'cause finish_command has a handle to | |
1058 | the bp on a bpstat, and will later want to delete it. There's a | |
1059 | chance (and I've seen it happen) that if we delete the bp_finish | |
1060 | here, that its storage will get reused by the time finish_command | |
1061 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1062 | We really must allow finish_command to delete a bp_finish. | |
1063 | ||
53a5351d JM |
1064 | In the absense of a general solution for the "how do we know |
1065 | it's safe to delete something others may have handles to?" | |
1066 | problem, what we'll do here is just uninsert the bp_finish, and | |
1067 | let finish_command delete it. | |
1068 | ||
1069 | (We know the bp_finish is "doomed" in the sense that it's | |
1070 | momentary, and will be deleted as soon as finish_command sees | |
1071 | the inferior stopped. So it doesn't matter that the bp's | |
1072 | address is probably bogus in the new a.out, unlike e.g., the | |
1073 | solib breakpoints.) */ | |
c5aa993b | 1074 | |
c5aa993b JM |
1075 | if (b->type == bp_finish) |
1076 | { | |
1077 | continue; | |
1078 | } | |
1079 | ||
1080 | /* Without a symbolic address, we have little hope of the | |
1081 | pre-exec() address meaning the same thing in the post-exec() | |
1082 | a.out. */ | |
1083 | if (b->addr_string == NULL) | |
1084 | { | |
1085 | delete_breakpoint (b); | |
1086 | continue; | |
1087 | } | |
1088 | ||
1089 | /* If this breakpoint has survived the above battery of checks, then | |
1090 | it must have a symbolic address. Be sure that it gets reevaluated | |
1091 | to a target address, rather than reusing the old evaluation. */ | |
1092 | b->address = (CORE_ADDR) NULL; | |
1093 | } | |
c906108c SS |
1094 | } |
1095 | ||
1096 | int | |
1097 | detach_breakpoints (pid) | |
c5aa993b | 1098 | int pid; |
c906108c SS |
1099 | { |
1100 | register struct breakpoint *b; | |
1101 | int val; | |
c5aa993b JM |
1102 | int saved_inferior_pid = inferior_pid; |
1103 | ||
c906108c SS |
1104 | if (pid == inferior_pid) |
1105 | error ("Cannot detach breakpoints of inferior_pid"); | |
c5aa993b | 1106 | |
53a5351d JM |
1107 | /* FIXME: use a cleanup, to insure that inferior_pid gets replaced! */ |
1108 | inferior_pid = pid; /* Because remove_breakpoint will use this global. */ | |
c906108c | 1109 | ALL_BREAKPOINTS (b) |
c5aa993b JM |
1110 | { |
1111 | if (b->inserted) | |
1112 | { | |
1113 | val = remove_breakpoint (b, mark_inserted); | |
1114 | if (val != 0) | |
1115 | { | |
1116 | inferior_pid = saved_inferior_pid; | |
1117 | return val; | |
1118 | } | |
1119 | } | |
1120 | } | |
c906108c SS |
1121 | inferior_pid = saved_inferior_pid; |
1122 | return 0; | |
1123 | } | |
1124 | ||
1125 | static int | |
1126 | remove_breakpoint (b, is) | |
1127 | struct breakpoint *b; | |
c5aa993b | 1128 | insertion_state_t is; |
c906108c SS |
1129 | { |
1130 | int val; | |
c5aa993b | 1131 | |
c906108c | 1132 | if (b->type == bp_none) |
53a5351d JM |
1133 | warning ("attempted to remove apparently deleted breakpoint #%d?", |
1134 | b->number); | |
c906108c SS |
1135 | |
1136 | if (b->type != bp_watchpoint | |
1137 | && b->type != bp_hardware_watchpoint | |
1138 | && b->type != bp_read_watchpoint | |
1139 | && b->type != bp_access_watchpoint | |
1140 | && b->type != bp_catch_fork | |
1141 | && b->type != bp_catch_vfork | |
1142 | && b->type != bp_catch_exec | |
1143 | && b->type != bp_catch_catch | |
1144 | && b->type != bp_catch_throw) | |
c5aa993b | 1145 | |
c906108c SS |
1146 | { |
1147 | if (b->type == bp_hardware_breakpoint) | |
c5aa993b | 1148 | val = target_remove_hw_breakpoint (b->address, b->shadow_contents); |
c906108c SS |
1149 | else |
1150 | { | |
1151 | /* Check to see if breakpoint is in an overlay section; | |
1152 | if so, we should remove the breakpoint at the LMA address. | |
1153 | If that is not equal to the raw address, then we should | |
1154 | presumable remove the breakpoint there as well. */ | |
c5aa993b | 1155 | if (overlay_debugging && b->section && |
c906108c SS |
1156 | section_is_overlay (b->section)) |
1157 | { | |
1158 | CORE_ADDR addr; | |
1159 | ||
1160 | addr = overlay_unmapped_address (b->address, b->section); | |
1161 | val = target_remove_breakpoint (addr, b->shadow_contents); | |
1162 | /* This would be the time to check val, to see if the | |
c5aa993b JM |
1163 | shadow breakpoint write to the load address succeeded. |
1164 | However, this might be an ordinary occurrance, eg. if | |
1165 | the unmapped overlay is in ROM. */ | |
1166 | val = 0; /* in case unmapped address failed */ | |
c906108c | 1167 | if (section_is_mapped (b->section)) |
c5aa993b | 1168 | val = target_remove_breakpoint (b->address, |
c906108c SS |
1169 | b->shadow_contents); |
1170 | } | |
c5aa993b JM |
1171 | else /* ordinary (non-overlay) address */ |
1172 | val = target_remove_breakpoint (b->address, b->shadow_contents); | |
c906108c SS |
1173 | } |
1174 | if (val) | |
1175 | return val; | |
1176 | b->inserted = (is == mark_inserted); | |
1177 | } | |
1178 | else if ((b->type == bp_hardware_watchpoint || | |
c5aa993b JM |
1179 | b->type == bp_read_watchpoint || |
1180 | b->type == bp_access_watchpoint) | |
c906108c | 1181 | && b->enable == enabled |
c5aa993b | 1182 | && !b->duplicate) |
c906108c SS |
1183 | { |
1184 | value_ptr v, n; | |
c5aa993b | 1185 | |
c906108c SS |
1186 | b->inserted = (is == mark_inserted); |
1187 | /* Walk down the saved value chain. */ | |
1188 | for (v = b->val_chain; v; v = v->next) | |
1189 | { | |
1190 | /* For each memory reference remove the watchpoint | |
1191 | at that address. */ | |
1192 | if (v->lval == lval_memory) | |
1193 | { | |
1194 | int addr, len, type; | |
c5aa993b | 1195 | |
c906108c SS |
1196 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); |
1197 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
53a5351d | 1198 | type = hw_write; |
c906108c | 1199 | if (b->type == bp_read_watchpoint) |
53a5351d | 1200 | type = hw_read; |
c906108c | 1201 | else if (b->type == bp_access_watchpoint) |
53a5351d | 1202 | type = hw_access; |
c906108c SS |
1203 | |
1204 | val = target_remove_watchpoint (addr, len, type); | |
1205 | if (val == -1) | |
1206 | b->inserted = 1; | |
1207 | val = 0; | |
1208 | } | |
1209 | } | |
1210 | /* Failure to remove any of the hardware watchpoints comes here. */ | |
1211 | if ((is == mark_uninserted) && (b->inserted)) | |
53a5351d | 1212 | warning ("Could not remove hardware watchpoint %d.", |
c906108c | 1213 | b->number); |
c5aa993b | 1214 | |
c906108c | 1215 | /* Free the saved value chain. We will construct a new one |
c5aa993b | 1216 | the next time the watchpoint is inserted. */ |
c906108c SS |
1217 | for (v = b->val_chain; v; v = n) |
1218 | { | |
1219 | n = v->next; | |
1220 | value_free (v); | |
1221 | } | |
1222 | b->val_chain = NULL; | |
1223 | } | |
1224 | else if ((b->type == bp_catch_fork || | |
c5aa993b JM |
1225 | b->type == bp_catch_vfork || |
1226 | b->type == bp_catch_exec) | |
c906108c | 1227 | && b->enable == enabled |
c5aa993b | 1228 | && !b->duplicate) |
c906108c SS |
1229 | { |
1230 | val = -1; | |
1231 | switch (b->type) | |
c5aa993b JM |
1232 | { |
1233 | case bp_catch_fork: | |
1234 | val = target_remove_fork_catchpoint (inferior_pid); | |
1235 | break; | |
1236 | case bp_catch_vfork: | |
1237 | val = target_remove_vfork_catchpoint (inferior_pid); | |
1238 | break; | |
1239 | case bp_catch_exec: | |
1240 | val = target_remove_exec_catchpoint (inferior_pid); | |
1241 | break; | |
ac9a91a7 | 1242 | default: |
53a5351d | 1243 | warning ("Internal error, %s line %d.", __FILE__, __LINE__); |
ac9a91a7 | 1244 | break; |
c5aa993b | 1245 | } |
c906108c SS |
1246 | if (val) |
1247 | return val; | |
1248 | b->inserted = (is == mark_inserted); | |
1249 | } | |
1250 | else if ((b->type == bp_catch_catch || | |
c5aa993b JM |
1251 | b->type == bp_catch_throw) |
1252 | && b->enable == enabled | |
1253 | && !b->duplicate) | |
c906108c SS |
1254 | { |
1255 | ||
c5aa993b | 1256 | val = target_remove_breakpoint (b->address, b->shadow_contents); |
c906108c | 1257 | if (val) |
c5aa993b | 1258 | return val; |
c906108c SS |
1259 | b->inserted = (is == mark_inserted); |
1260 | } | |
1261 | else if (ep_is_exception_catchpoint (b) | |
c5aa993b JM |
1262 | && b->inserted /* sometimes previous insert doesn't happen */ |
1263 | && b->enable == enabled | |
1264 | && !b->duplicate) | |
c906108c SS |
1265 | { |
1266 | ||
c5aa993b | 1267 | val = target_remove_breakpoint (b->address, b->shadow_contents); |
c906108c | 1268 | if (val) |
c5aa993b JM |
1269 | return val; |
1270 | ||
c906108c SS |
1271 | b->inserted = (is == mark_inserted); |
1272 | } | |
1273 | ||
1274 | return 0; | |
1275 | } | |
1276 | ||
1277 | /* Clear the "inserted" flag in all breakpoints. */ | |
1278 | ||
1279 | void | |
1280 | mark_breakpoints_out () | |
1281 | { | |
1282 | register struct breakpoint *b; | |
1283 | ||
1284 | ALL_BREAKPOINTS (b) | |
1285 | b->inserted = 0; | |
1286 | } | |
1287 | ||
53a5351d JM |
1288 | /* Clear the "inserted" flag in all breakpoints and delete any |
1289 | breakpoints which should go away between runs of the program. | |
c906108c SS |
1290 | |
1291 | Plus other such housekeeping that has to be done for breakpoints | |
1292 | between runs. | |
1293 | ||
53a5351d JM |
1294 | Note: this function gets called at the end of a run (by |
1295 | generic_mourn_inferior) and when a run begins (by | |
1296 | init_wait_for_inferior). */ | |
c906108c SS |
1297 | |
1298 | ||
1299 | ||
1300 | void | |
1301 | breakpoint_init_inferior (context) | |
c5aa993b | 1302 | enum inf_context context; |
c906108c SS |
1303 | { |
1304 | register struct breakpoint *b, *temp; | |
1305 | static int warning_needed = 0; | |
1306 | ||
1307 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
1308 | { |
1309 | b->inserted = 0; | |
c906108c | 1310 | |
c5aa993b JM |
1311 | switch (b->type) |
1312 | { | |
1313 | case bp_call_dummy: | |
1314 | case bp_watchpoint_scope: | |
c906108c | 1315 | |
c5aa993b JM |
1316 | /* If the call dummy breakpoint is at the entry point it will |
1317 | cause problems when the inferior is rerun, so we better | |
1318 | get rid of it. | |
c906108c | 1319 | |
c5aa993b JM |
1320 | Also get rid of scope breakpoints. */ |
1321 | delete_breakpoint (b); | |
1322 | break; | |
c906108c | 1323 | |
c5aa993b JM |
1324 | case bp_watchpoint: |
1325 | case bp_hardware_watchpoint: | |
1326 | case bp_read_watchpoint: | |
1327 | case bp_access_watchpoint: | |
c906108c | 1328 | |
c5aa993b JM |
1329 | /* Likewise for watchpoints on local expressions. */ |
1330 | if (b->exp_valid_block != NULL) | |
1331 | delete_breakpoint (b); | |
1332 | break; | |
1333 | default: | |
1334 | /* Likewise for exception catchpoints in dynamic-linked | |
1335 | executables where required */ | |
1336 | if (ep_is_exception_catchpoint (b) && | |
1337 | exception_catchpoints_are_fragile) | |
1338 | { | |
1339 | warning_needed = 1; | |
c906108c | 1340 | delete_breakpoint (b); |
c5aa993b JM |
1341 | } |
1342 | break; | |
1343 | } | |
1344 | } | |
c906108c SS |
1345 | |
1346 | if (exception_catchpoints_are_fragile) | |
1347 | exception_support_initialized = 0; | |
1348 | ||
c5aa993b | 1349 | /* Don't issue the warning unless it's really needed... */ |
c906108c SS |
1350 | if (warning_needed && (context != inf_exited)) |
1351 | { | |
53a5351d JM |
1352 | warning ("Exception catchpoints from last run were deleted."); |
1353 | warning ("You must reinsert them explicitly."); | |
c906108c | 1354 | warning_needed = 0; |
c5aa993b | 1355 | } |
c906108c SS |
1356 | } |
1357 | ||
53a5351d JM |
1358 | /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at |
1359 | PC. When continuing from a location with a breakpoint, we actually | |
1360 | single step once before calling insert_breakpoints. */ | |
c906108c SS |
1361 | |
1362 | int | |
1363 | breakpoint_here_p (pc) | |
1364 | CORE_ADDR pc; | |
1365 | { | |
1366 | register struct breakpoint *b; | |
1367 | ||
1368 | ALL_BREAKPOINTS (b) | |
1369 | if (b->enable == enabled | |
1370 | && b->enable != shlib_disabled | |
1371 | && b->enable != call_disabled | |
1372 | && b->address == pc) /* bp is enabled and matches pc */ | |
c5aa993b JM |
1373 | { |
1374 | if (overlay_debugging && | |
1375 | section_is_overlay (b->section) && | |
1376 | !section_is_mapped (b->section)) | |
1377 | continue; /* unmapped overlay -- can't be a match */ | |
1378 | else | |
1379 | return 1; | |
1380 | } | |
c906108c SS |
1381 | |
1382 | return 0; | |
1383 | } | |
1384 | ||
53a5351d JM |
1385 | /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(), |
1386 | but it only returns true if there is actually a breakpoint inserted | |
1387 | at PC. */ | |
c906108c SS |
1388 | |
1389 | int | |
1390 | breakpoint_inserted_here_p (pc) | |
1391 | CORE_ADDR pc; | |
1392 | { | |
1393 | register struct breakpoint *b; | |
1394 | ||
1395 | ALL_BREAKPOINTS (b) | |
1396 | if (b->inserted | |
1397 | && b->address == pc) /* bp is inserted and matches pc */ | |
c5aa993b JM |
1398 | { |
1399 | if (overlay_debugging && | |
1400 | section_is_overlay (b->section) && | |
1401 | !section_is_mapped (b->section)) | |
1402 | continue; /* unmapped overlay -- can't be a match */ | |
1403 | else | |
1404 | return 1; | |
1405 | } | |
c906108c SS |
1406 | |
1407 | return 0; | |
1408 | } | |
1409 | ||
53a5351d JM |
1410 | /* Return nonzero if FRAME is a dummy frame. We can't use |
1411 | PC_IN_CALL_DUMMY because figuring out the saved SP would take too | |
1412 | much time, at least using get_saved_register on the 68k. This | |
1413 | means that for this function to work right a port must use the | |
1414 | bp_call_dummy breakpoint. */ | |
c906108c SS |
1415 | |
1416 | int | |
1417 | frame_in_dummy (frame) | |
1418 | struct frame_info *frame; | |
1419 | { | |
c906108c SS |
1420 | struct breakpoint *b; |
1421 | ||
c5aa993b | 1422 | if (!CALL_DUMMY_P) |
7a292a7a SS |
1423 | return 0; |
1424 | ||
1425 | if (USE_GENERIC_DUMMY_FRAMES) | |
1426 | return generic_pc_in_call_dummy (frame->pc, frame->frame, frame->frame); | |
c5aa993b | 1427 | |
c906108c | 1428 | ALL_BREAKPOINTS (b) |
c5aa993b JM |
1429 | { |
1430 | if (b->type == bp_call_dummy | |
1431 | && b->frame == frame->frame | |
1432 | /* We need to check the PC as well as the frame on the sparc, | |
1433 | for signals.exp in the testsuite. */ | |
1434 | && (frame->pc | |
1435 | >= (b->address | |
1436 | - SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * REGISTER_SIZE)) | |
1437 | && frame->pc <= b->address) | |
1438 | return 1; | |
1439 | } | |
c906108c SS |
1440 | return 0; |
1441 | } | |
1442 | ||
1443 | /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC | |
1444 | is valid for process/thread PID. */ | |
1445 | ||
1446 | int | |
1447 | breakpoint_thread_match (pc, pid) | |
1448 | CORE_ADDR pc; | |
1449 | int pid; | |
1450 | { | |
1451 | struct breakpoint *b; | |
1452 | int thread; | |
1453 | ||
1454 | thread = pid_to_thread_id (pid); | |
1455 | ||
1456 | ALL_BREAKPOINTS (b) | |
1457 | if (b->enable != disabled | |
1458 | && b->enable != shlib_disabled | |
1459 | && b->enable != call_disabled | |
1460 | && b->address == pc | |
1461 | && (b->thread == -1 || b->thread == thread)) | |
c5aa993b JM |
1462 | { |
1463 | if (overlay_debugging && | |
1464 | section_is_overlay (b->section) && | |
1465 | !section_is_mapped (b->section)) | |
1466 | continue; /* unmapped overlay -- can't be a match */ | |
1467 | else | |
1468 | return 1; | |
1469 | } | |
c906108c SS |
1470 | |
1471 | return 0; | |
1472 | } | |
c906108c | 1473 | \f |
c5aa993b | 1474 | |
c906108c SS |
1475 | /* bpstat stuff. External routines' interfaces are documented |
1476 | in breakpoint.h. */ | |
1477 | ||
1478 | int | |
1479 | ep_is_catchpoint (ep) | |
c5aa993b | 1480 | struct breakpoint *ep; |
c906108c SS |
1481 | { |
1482 | return | |
1483 | (ep->type == bp_catch_load) | |
1484 | || (ep->type == bp_catch_unload) | |
1485 | || (ep->type == bp_catch_fork) | |
1486 | || (ep->type == bp_catch_vfork) | |
1487 | || (ep->type == bp_catch_exec) | |
1488 | || (ep->type == bp_catch_catch) | |
1489 | || (ep->type == bp_catch_throw) | |
1490 | ||
1491 | ||
c5aa993b | 1492 | /* ??rehrauer: Add more kinds here, as are implemented... */ |
c906108c SS |
1493 | ; |
1494 | } | |
c5aa993b | 1495 | |
c906108c SS |
1496 | int |
1497 | ep_is_shlib_catchpoint (ep) | |
c5aa993b | 1498 | struct breakpoint *ep; |
c906108c SS |
1499 | { |
1500 | return | |
1501 | (ep->type == bp_catch_load) | |
1502 | || (ep->type == bp_catch_unload) | |
1503 | ; | |
1504 | } | |
1505 | ||
1506 | int | |
1507 | ep_is_exception_catchpoint (ep) | |
c5aa993b | 1508 | struct breakpoint *ep; |
c906108c SS |
1509 | { |
1510 | return | |
1511 | (ep->type == bp_catch_catch) | |
1512 | || (ep->type == bp_catch_throw) | |
1513 | ; | |
1514 | } | |
1515 | ||
1516 | /* Clear a bpstat so that it says we are not at any breakpoint. | |
1517 | Also free any storage that is part of a bpstat. */ | |
1518 | ||
1519 | void | |
1520 | bpstat_clear (bsp) | |
1521 | bpstat *bsp; | |
1522 | { | |
1523 | bpstat p; | |
1524 | bpstat q; | |
1525 | ||
1526 | if (bsp == 0) | |
1527 | return; | |
1528 | p = *bsp; | |
1529 | while (p != NULL) | |
1530 | { | |
1531 | q = p->next; | |
1532 | if (p->old_val != NULL) | |
1533 | value_free (p->old_val); | |
c5aa993b | 1534 | free ((PTR) p); |
c906108c SS |
1535 | p = q; |
1536 | } | |
1537 | *bsp = NULL; | |
1538 | } | |
1539 | ||
1540 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
1541 | is part of the bpstat is copied as well. */ | |
1542 | ||
1543 | bpstat | |
1544 | bpstat_copy (bs) | |
1545 | bpstat bs; | |
1546 | { | |
1547 | bpstat p = NULL; | |
1548 | bpstat tmp; | |
1549 | bpstat retval = NULL; | |
1550 | ||
1551 | if (bs == NULL) | |
1552 | return bs; | |
1553 | ||
1554 | for (; bs != NULL; bs = bs->next) | |
1555 | { | |
1556 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
1557 | memcpy (tmp, bs, sizeof (*tmp)); | |
1558 | if (p == NULL) | |
1559 | /* This is the first thing in the chain. */ | |
1560 | retval = tmp; | |
1561 | else | |
1562 | p->next = tmp; | |
1563 | p = tmp; | |
1564 | } | |
1565 | p->next = NULL; | |
1566 | return retval; | |
1567 | } | |
1568 | ||
1569 | /* Find the bpstat associated with this breakpoint */ | |
1570 | ||
1571 | bpstat | |
c5aa993b | 1572 | bpstat_find_breakpoint (bsp, breakpoint) |
c906108c SS |
1573 | bpstat bsp; |
1574 | struct breakpoint *breakpoint; | |
1575 | { | |
c5aa993b JM |
1576 | if (bsp == NULL) |
1577 | return NULL; | |
c906108c | 1578 | |
c5aa993b JM |
1579 | for (; bsp != NULL; bsp = bsp->next) |
1580 | { | |
1581 | if (bsp->breakpoint_at == breakpoint) | |
1582 | return bsp; | |
1583 | } | |
c906108c SS |
1584 | return NULL; |
1585 | } | |
1586 | ||
1587 | /* Find a step_resume breakpoint associated with this bpstat. | |
1588 | (If there are multiple step_resume bp's on the list, this function | |
1589 | will arbitrarily pick one.) | |
1590 | ||
1591 | It is an error to use this function if BPSTAT doesn't contain a | |
1592 | step_resume breakpoint. | |
1593 | ||
1594 | See wait_for_inferior's use of this function. */ | |
1595 | struct breakpoint * | |
1596 | bpstat_find_step_resume_breakpoint (bsp) | |
c5aa993b | 1597 | bpstat bsp; |
c906108c SS |
1598 | { |
1599 | if (bsp == NULL) | |
1600 | error ("Internal error (bpstat_find_step_resume_breakpoint)"); | |
1601 | ||
1602 | for (; bsp != NULL; bsp = bsp->next) | |
1603 | { | |
1604 | if ((bsp->breakpoint_at != NULL) && | |
c5aa993b JM |
1605 | (bsp->breakpoint_at->type == bp_step_resume)) |
1606 | return bsp->breakpoint_at; | |
c906108c SS |
1607 | } |
1608 | ||
1609 | error ("Internal error (no step_resume breakpoint found)"); | |
1610 | } | |
1611 | ||
1612 | ||
1613 | /* Return the breakpoint number of the first breakpoint we are stopped | |
1614 | at. *BSP upon return is a bpstat which points to the remaining | |
1615 | breakpoints stopped at (but which is not guaranteed to be good for | |
1616 | anything but further calls to bpstat_num). | |
1617 | Return 0 if passed a bpstat which does not indicate any breakpoints. */ | |
1618 | ||
1619 | int | |
1620 | bpstat_num (bsp) | |
1621 | bpstat *bsp; | |
1622 | { | |
1623 | struct breakpoint *b; | |
1624 | ||
1625 | if ((*bsp) == NULL) | |
1626 | return 0; /* No more breakpoint values */ | |
1627 | else | |
1628 | { | |
1629 | b = (*bsp)->breakpoint_at; | |
1630 | *bsp = (*bsp)->next; | |
1631 | if (b == NULL) | |
1632 | return -1; /* breakpoint that's been deleted since */ | |
1633 | else | |
c5aa993b | 1634 | return b->number; /* We have its number */ |
c906108c SS |
1635 | } |
1636 | } | |
1637 | ||
1638 | /* Modify BS so that the actions will not be performed. */ | |
1639 | ||
1640 | void | |
1641 | bpstat_clear_actions (bs) | |
1642 | bpstat bs; | |
1643 | { | |
1644 | for (; bs != NULL; bs = bs->next) | |
1645 | { | |
1646 | bs->commands = NULL; | |
1647 | if (bs->old_val != NULL) | |
1648 | { | |
1649 | value_free (bs->old_val); | |
1650 | bs->old_val = NULL; | |
1651 | } | |
1652 | } | |
1653 | } | |
1654 | ||
1655 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ | |
1656 | /* ARGSUSED */ | |
1657 | static void | |
1658 | cleanup_executing_breakpoints (ignore) | |
1659 | PTR ignore; | |
1660 | { | |
1661 | executing_breakpoint_commands = 0; | |
1662 | } | |
1663 | ||
1664 | /* Execute all the commands associated with all the breakpoints at this | |
1665 | location. Any of these commands could cause the process to proceed | |
1666 | beyond this point, etc. We look out for such changes by checking | |
1667 | the global "breakpoint_proceeded" after each command. */ | |
1668 | ||
1669 | void | |
1670 | bpstat_do_actions (bsp) | |
1671 | bpstat *bsp; | |
1672 | { | |
1673 | bpstat bs; | |
1674 | struct cleanup *old_chain; | |
1675 | struct command_line *cmd; | |
1676 | ||
1677 | /* Avoid endless recursion if a `source' command is contained | |
1678 | in bs->commands. */ | |
1679 | if (executing_breakpoint_commands) | |
1680 | return; | |
1681 | ||
1682 | executing_breakpoint_commands = 1; | |
1683 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
1684 | ||
1685 | top: | |
1686 | /* Note that (as of this writing), our callers all appear to | |
1687 | be passing us the address of global stop_bpstat. And, if | |
1688 | our calls to execute_control_command cause the inferior to | |
1689 | proceed, that global (and hence, *bsp) will change. | |
1690 | ||
1691 | We must be careful to not touch *bsp unless the inferior | |
1692 | has not proceeded. */ | |
1693 | ||
1694 | /* This pointer will iterate over the list of bpstat's. */ | |
1695 | bs = *bsp; | |
1696 | ||
1697 | breakpoint_proceeded = 0; | |
1698 | for (; bs != NULL; bs = bs->next) | |
1699 | { | |
1700 | cmd = bs->commands; | |
1701 | while (cmd != NULL) | |
1702 | { | |
1703 | execute_control_command (cmd); | |
1704 | ||
1705 | if (breakpoint_proceeded) | |
1706 | break; | |
1707 | else | |
1708 | cmd = cmd->next; | |
1709 | } | |
1710 | if (breakpoint_proceeded) | |
1711 | /* The inferior is proceeded by the command; bomb out now. | |
1712 | The bpstat chain has been blown away by wait_for_inferior. | |
1713 | But since execution has stopped again, there is a new bpstat | |
1714 | to look at, so start over. */ | |
1715 | goto top; | |
1716 | else | |
1717 | bs->commands = NULL; | |
1718 | } | |
1719 | ||
1720 | executing_breakpoint_commands = 0; | |
1721 | discard_cleanups (old_chain); | |
1722 | } | |
1723 | ||
1724 | /* This is the normal print_it function for a bpstat. In the future, | |
1725 | much of this logic could (should?) be moved to bpstat_stop_status, | |
1726 | by having it set different print_it functions. | |
1727 | ||
1728 | Current scheme: When we stop, bpstat_print() is called. | |
1729 | It loops through the bpstat list of things causing this stop, | |
1730 | calling the print_it function for each one. The default | |
1731 | print_it function, used for breakpoints, is print_it_normal(). | |
1732 | (Also see print_it_noop() and print_it_done()). | |
c5aa993b | 1733 | |
c906108c SS |
1734 | Return values from this routine (used by bpstat_print() to |
1735 | decide what to do): | |
1736 | 1: Means we printed something, and we do *not* desire that | |
c5aa993b | 1737 | something to be followed by a location. |
c906108c | 1738 | 0: Means we printed something, and we *do* desire that |
c5aa993b | 1739 | something to be followed by a location. |
c906108c SS |
1740 | -1: Means we printed nothing. */ |
1741 | ||
1742 | static int | |
1743 | print_it_normal (bs) | |
1744 | bpstat bs; | |
1745 | { | |
1746 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint | |
1747 | which has since been deleted. */ | |
1748 | if (bs->breakpoint_at == NULL | |
1749 | || (bs->breakpoint_at->type != bp_breakpoint | |
c5aa993b JM |
1750 | && bs->breakpoint_at->type != bp_catch_load |
1751 | && bs->breakpoint_at->type != bp_catch_unload | |
1752 | && bs->breakpoint_at->type != bp_catch_fork | |
1753 | && bs->breakpoint_at->type != bp_catch_vfork | |
1754 | && bs->breakpoint_at->type != bp_catch_exec | |
1755 | && bs->breakpoint_at->type != bp_catch_catch | |
1756 | && bs->breakpoint_at->type != bp_catch_throw | |
c906108c SS |
1757 | && bs->breakpoint_at->type != bp_hardware_breakpoint |
1758 | && bs->breakpoint_at->type != bp_watchpoint | |
1759 | && bs->breakpoint_at->type != bp_read_watchpoint | |
1760 | && bs->breakpoint_at->type != bp_access_watchpoint | |
1761 | && bs->breakpoint_at->type != bp_hardware_watchpoint)) | |
1762 | return -1; | |
1763 | ||
1764 | if (ep_is_shlib_catchpoint (bs->breakpoint_at)) | |
1765 | { | |
1766 | annotate_catchpoint (bs->breakpoint_at->number); | |
1767 | printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); | |
1768 | if (bs->breakpoint_at->type == bp_catch_load) | |
c5aa993b | 1769 | printf_filtered ("loaded"); |
c906108c | 1770 | else if (bs->breakpoint_at->type == bp_catch_unload) |
c5aa993b | 1771 | printf_filtered ("unloaded"); |
c906108c SS |
1772 | printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname); |
1773 | return 0; | |
1774 | } | |
1775 | else if (bs->breakpoint_at->type == bp_catch_fork || | |
c5aa993b | 1776 | bs->breakpoint_at->type == bp_catch_vfork) |
c906108c SS |
1777 | { |
1778 | annotate_catchpoint (bs->breakpoint_at->number); | |
1779 | printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); | |
1780 | if (bs->breakpoint_at->type == bp_catch_fork) | |
c5aa993b | 1781 | printf_filtered ("forked"); |
c906108c | 1782 | else if (bs->breakpoint_at->type == bp_catch_vfork) |
c5aa993b | 1783 | printf_filtered ("vforked"); |
53a5351d JM |
1784 | printf_filtered (" process %d), ", |
1785 | bs->breakpoint_at->forked_inferior_pid); | |
c906108c SS |
1786 | return 0; |
1787 | } | |
1788 | else if (bs->breakpoint_at->type == bp_catch_exec) | |
1789 | { | |
1790 | annotate_catchpoint (bs->breakpoint_at->number); | |
1791 | printf_filtered ("\nCatchpoint %d (exec'd %s), ", | |
c5aa993b JM |
1792 | bs->breakpoint_at->number, |
1793 | bs->breakpoint_at->exec_pathname); | |
c906108c SS |
1794 | return 0; |
1795 | } | |
c5aa993b | 1796 | else if (bs->breakpoint_at->type == bp_catch_catch) |
c906108c | 1797 | { |
53a5351d JM |
1798 | if (current_exception_event && |
1799 | (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH)) | |
c5aa993b JM |
1800 | { |
1801 | annotate_catchpoint (bs->breakpoint_at->number); | |
53a5351d JM |
1802 | printf_filtered ("\nCatchpoint %d (exception caught), ", |
1803 | bs->breakpoint_at->number); | |
c5aa993b JM |
1804 | printf_filtered ("throw location "); |
1805 | if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE) | |
1806 | printf_filtered ("%s:%d", | |
1807 | CURRENT_EXCEPTION_THROW_FILE, | |
1808 | CURRENT_EXCEPTION_THROW_LINE); | |
1809 | else | |
1810 | printf_filtered ("unknown"); | |
1811 | ||
1812 | printf_filtered (", catch location "); | |
1813 | if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE) | |
1814 | printf_filtered ("%s:%d", | |
1815 | CURRENT_EXCEPTION_CATCH_FILE, | |
1816 | CURRENT_EXCEPTION_CATCH_LINE); | |
1817 | else | |
1818 | printf_filtered ("unknown"); | |
1819 | ||
1820 | printf_filtered ("\n"); | |
53a5351d | 1821 | return 1; /* don't bother to print location frame info */ |
c5aa993b | 1822 | } |
c906108c | 1823 | else |
c5aa993b | 1824 | { |
53a5351d | 1825 | return -1; /* really throw, some other bpstat will handle it */ |
c5aa993b | 1826 | } |
c906108c SS |
1827 | } |
1828 | else if (bs->breakpoint_at->type == bp_catch_throw) | |
1829 | { | |
53a5351d JM |
1830 | if (current_exception_event && |
1831 | (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW)) | |
c5aa993b JM |
1832 | { |
1833 | annotate_catchpoint (bs->breakpoint_at->number); | |
53a5351d JM |
1834 | printf_filtered ("\nCatchpoint %d (exception thrown), ", |
1835 | bs->breakpoint_at->number); | |
c5aa993b JM |
1836 | printf_filtered ("throw location "); |
1837 | if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE) | |
1838 | printf_filtered ("%s:%d", | |
1839 | CURRENT_EXCEPTION_THROW_FILE, | |
1840 | CURRENT_EXCEPTION_THROW_LINE); | |
1841 | else | |
1842 | printf_filtered ("unknown"); | |
1843 | ||
1844 | printf_filtered (", catch location "); | |
1845 | if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE) | |
1846 | printf_filtered ("%s:%d", | |
1847 | CURRENT_EXCEPTION_CATCH_FILE, | |
1848 | CURRENT_EXCEPTION_CATCH_LINE); | |
1849 | else | |
1850 | printf_filtered ("unknown"); | |
1851 | ||
1852 | printf_filtered ("\n"); | |
53a5351d | 1853 | return 1; /* don't bother to print location frame info */ |
c5aa993b | 1854 | } |
c906108c | 1855 | else |
c5aa993b | 1856 | { |
53a5351d | 1857 | return -1; /* really catch, some other bpstat willhandle it */ |
c5aa993b | 1858 | } |
c906108c SS |
1859 | } |
1860 | ||
1861 | else if (bs->breakpoint_at->type == bp_breakpoint || | |
c5aa993b | 1862 | bs->breakpoint_at->type == bp_hardware_breakpoint) |
c906108c SS |
1863 | { |
1864 | /* I think the user probably only wants to see one breakpoint | |
c5aa993b | 1865 | number, not all of them. */ |
c906108c SS |
1866 | annotate_breakpoint (bs->breakpoint_at->number); |
1867 | printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number); | |
1868 | return 0; | |
1869 | } | |
1870 | else if ((bs->old_val != NULL) && | |
c5aa993b JM |
1871 | (bs->breakpoint_at->type == bp_watchpoint || |
1872 | bs->breakpoint_at->type == bp_access_watchpoint || | |
1873 | bs->breakpoint_at->type == bp_hardware_watchpoint)) | |
c906108c SS |
1874 | { |
1875 | annotate_watchpoint (bs->breakpoint_at->number); | |
1876 | mention (bs->breakpoint_at); | |
1877 | printf_filtered ("\nOld value = "); | |
1878 | value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default); | |
1879 | printf_filtered ("\nNew value = "); | |
1880 | value_print (bs->breakpoint_at->val, gdb_stdout, 0, | |
1881 | Val_pretty_default); | |
1882 | printf_filtered ("\n"); | |
1883 | value_free (bs->old_val); | |
1884 | bs->old_val = NULL; | |
1885 | /* More than one watchpoint may have been triggered. */ | |
1886 | return -1; | |
1887 | } | |
1888 | else if (bs->breakpoint_at->type == bp_access_watchpoint || | |
1889 | bs->breakpoint_at->type == bp_read_watchpoint) | |
1890 | { | |
1891 | mention (bs->breakpoint_at); | |
1892 | printf_filtered ("\nValue = "); | |
1893 | value_print (bs->breakpoint_at->val, gdb_stdout, 0, | |
c5aa993b | 1894 | Val_pretty_default); |
c906108c SS |
1895 | printf_filtered ("\n"); |
1896 | return -1; | |
1897 | } | |
53a5351d JM |
1898 | /* We can't deal with it. |
1899 | Maybe another member of the bpstat chain can. */ | |
c906108c SS |
1900 | return -1; |
1901 | } | |
1902 | ||
1903 | /* Print a message indicating what happened. | |
1904 | This is called from normal_stop(). | |
1905 | The input to this routine is the head of the bpstat list - a list | |
1906 | of the eventpoints that caused this stop. | |
1907 | This routine calls the "print_it" routine(s) associated | |
1908 | with these eventpoints. This will print (for example) | |
1909 | the "Breakpoint n," part of the output. | |
1910 | The return value of this routine is one of: | |
1911 | ||
1912 | -1: Means we printed nothing | |
1913 | 0: Means we printed something, and expect subsequent | |
c5aa993b JM |
1914 | code to print the location. An example is |
1915 | "Breakpoint 1, " which should be followed by | |
1916 | the location. | |
c906108c | 1917 | 1 : Means we printed something, but there is no need |
c5aa993b JM |
1918 | to also print the location part of the message. |
1919 | An example is the catch/throw messages, which | |
1920 | don't require a location appended to the end. */ | |
c906108c SS |
1921 | |
1922 | int | |
1923 | bpstat_print (bs) | |
1924 | bpstat bs; | |
1925 | { | |
1926 | int val; | |
c5aa993b | 1927 | |
c906108c SS |
1928 | if (bs == NULL) |
1929 | return -1; | |
1930 | ||
1931 | val = (*bs->print_it) (bs); | |
1932 | if (val >= 0) | |
1933 | return val; | |
c5aa993b | 1934 | |
c906108c | 1935 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
1936 | (Currently all watchpoints go on the bpstat whether hit or not. |
1937 | That probably could (should) be changed, provided care is taken | |
c906108c SS |
1938 | with respect to bpstat_explains_signal). */ |
1939 | if (bs->next) | |
1940 | return bpstat_print (bs->next); | |
1941 | ||
1942 | /* We reached the end of the chain without printing anything. */ | |
1943 | return -1; | |
1944 | } | |
1945 | ||
1946 | /* Evaluate the expression EXP and return 1 if value is zero. | |
1947 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
1948 | The argument is a "struct expression *" that has been cast to char * to | |
1949 | make it pass through catch_errors. */ | |
1950 | ||
1951 | static int | |
1952 | breakpoint_cond_eval (exp) | |
1953 | PTR exp; | |
1954 | { | |
1955 | value_ptr mark = value_mark (); | |
c5aa993b | 1956 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
1957 | value_free_to_mark (mark); |
1958 | return i; | |
1959 | } | |
1960 | ||
1961 | /* Allocate a new bpstat and chain it to the current one. */ | |
1962 | ||
1963 | static bpstat | |
1964 | bpstat_alloc (b, cbs) | |
1965 | register struct breakpoint *b; | |
c5aa993b | 1966 | bpstat cbs; /* Current "bs" value */ |
c906108c SS |
1967 | { |
1968 | bpstat bs; | |
1969 | ||
1970 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
1971 | cbs->next = bs; | |
1972 | bs->breakpoint_at = b; | |
1973 | /* If the condition is false, etc., don't do the commands. */ | |
1974 | bs->commands = NULL; | |
1975 | bs->old_val = NULL; | |
1976 | bs->print_it = print_it_normal; | |
1977 | return bs; | |
1978 | } | |
1979 | \f | |
1980 | /* Possible return values for watchpoint_check (this can't be an enum | |
1981 | because of check_errors). */ | |
1982 | /* The watchpoint has been deleted. */ | |
1983 | #define WP_DELETED 1 | |
1984 | /* The value has changed. */ | |
1985 | #define WP_VALUE_CHANGED 2 | |
1986 | /* The value has not changed. */ | |
1987 | #define WP_VALUE_NOT_CHANGED 3 | |
1988 | ||
1989 | #define BP_TEMPFLAG 1 | |
1990 | #define BP_HARDWAREFLAG 2 | |
1991 | ||
1992 | /* Check watchpoint condition. */ | |
1993 | ||
1994 | static int | |
1995 | watchpoint_check (p) | |
1996 | PTR p; | |
1997 | { | |
1998 | bpstat bs = (bpstat) p; | |
1999 | struct breakpoint *b; | |
2000 | struct frame_info *fr; | |
2001 | int within_current_scope; | |
2002 | ||
2003 | b = bs->breakpoint_at; | |
2004 | ||
2005 | if (b->exp_valid_block == NULL) | |
2006 | within_current_scope = 1; | |
2007 | else | |
2008 | { | |
2009 | /* There is no current frame at this moment. If we're going to have | |
c5aa993b JM |
2010 | any chance of handling watchpoints on local variables, we'll need |
2011 | the frame chain (so we can determine if we're in scope). */ | |
2012 | reinit_frame_cache (); | |
c906108c SS |
2013 | fr = find_frame_addr_in_frame_chain (b->watchpoint_frame); |
2014 | within_current_scope = (fr != NULL); | |
2015 | if (within_current_scope) | |
2016 | /* If we end up stopping, the current frame will get selected | |
2017 | in normal_stop. So this call to select_frame won't affect | |
2018 | the user. */ | |
2019 | select_frame (fr, -1); | |
2020 | } | |
c5aa993b | 2021 | |
c906108c SS |
2022 | if (within_current_scope) |
2023 | { | |
2024 | /* We use value_{,free_to_}mark because it could be a | |
2025 | *long* time before we return to the command level and | |
c5aa993b JM |
2026 | call free_all_values. We can't call free_all_values because |
2027 | we might be in the middle of evaluating a function call. */ | |
c906108c SS |
2028 | |
2029 | value_ptr mark = value_mark (); | |
2030 | value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp); | |
2031 | if (!value_equal (b->val, new_val)) | |
2032 | { | |
2033 | release_value (new_val); | |
2034 | value_free_to_mark (mark); | |
2035 | bs->old_val = b->val; | |
2036 | b->val = new_val; | |
2037 | /* We will stop here */ | |
2038 | return WP_VALUE_CHANGED; | |
2039 | } | |
2040 | else | |
2041 | { | |
2042 | /* Nothing changed, don't do anything. */ | |
2043 | value_free_to_mark (mark); | |
2044 | /* We won't stop here */ | |
2045 | return WP_VALUE_NOT_CHANGED; | |
2046 | } | |
2047 | } | |
2048 | else | |
2049 | { | |
2050 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
2051 | if we temporarily ignored the watchpoint, then when |
2052 | we reenter the block in which it is valid it contains | |
2053 | garbage (in the case of a function, it may have two | |
2054 | garbage values, one before and one after the prologue). | |
2055 | So we can't even detect the first assignment to it and | |
2056 | watch after that (since the garbage may or may not equal | |
2057 | the first value assigned). */ | |
c906108c SS |
2058 | printf_filtered ("\ |
2059 | Watchpoint %d deleted because the program has left the block in\n\ | |
2060 | which its expression is valid.\n", bs->breakpoint_at->number); | |
2061 | if (b->related_breakpoint) | |
2062 | b->related_breakpoint->disposition = del_at_next_stop; | |
2063 | b->disposition = del_at_next_stop; | |
2064 | ||
2065 | return WP_DELETED; | |
2066 | } | |
2067 | } | |
2068 | ||
2069 | /* This is used when everything which needs to be printed has | |
2070 | already been printed. But we still want to print the frame. */ | |
2071 | ||
2072 | /* Background: When we stop, bpstat_print() is called. | |
2073 | It loops through the bpstat list of things causing this stop, | |
2074 | calling the print_it function for each one. The default | |
2075 | print_it function, used for breakpoints, is print_it_normal(). | |
2076 | Also see print_it_noop() and print_it_done() are the other | |
2077 | two possibilities. See comments in bpstat_print() and | |
2078 | in header of print_it_normal() for more detail. */ | |
2079 | ||
2080 | static int | |
2081 | print_it_done (bs) | |
2082 | bpstat bs; | |
2083 | { | |
2084 | return 0; | |
2085 | } | |
2086 | ||
2087 | /* This is used when nothing should be printed for this bpstat entry. */ | |
2088 | /* Background: When we stop, bpstat_print() is called. | |
2089 | It loops through the bpstat list of things causing this stop, | |
2090 | calling the print_it function for each one. The default | |
2091 | print_it function, used for breakpoints, is print_it_normal(). | |
2092 | Also see print_it_noop() and print_it_done() are the other | |
2093 | two possibilities. See comments in bpstat_print() and | |
2094 | in header of print_it_normal() for more detail. */ | |
2095 | ||
2096 | static int | |
2097 | print_it_noop (bs) | |
2098 | bpstat bs; | |
2099 | { | |
2100 | return -1; | |
2101 | } | |
2102 | ||
2103 | /* Get a bpstat associated with having just stopped at address *PC | |
2104 | and frame address CORE_ADDRESS. Update *PC to point at the | |
2105 | breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero | |
2106 | if this is known to not be a real breakpoint (it could still be a | |
2107 | watchpoint, though). */ | |
2108 | ||
2109 | /* Determine whether we stopped at a breakpoint, etc, or whether we | |
2110 | don't understand this stop. Result is a chain of bpstat's such that: | |
2111 | ||
c5aa993b | 2112 | if we don't understand the stop, the result is a null pointer. |
c906108c | 2113 | |
c5aa993b | 2114 | if we understand why we stopped, the result is not null. |
c906108c | 2115 | |
c5aa993b JM |
2116 | Each element of the chain refers to a particular breakpoint or |
2117 | watchpoint at which we have stopped. (We may have stopped for | |
2118 | several reasons concurrently.) | |
c906108c | 2119 | |
c5aa993b JM |
2120 | Each element of the chain has valid next, breakpoint_at, |
2121 | commands, FIXME??? fields. */ | |
c906108c SS |
2122 | |
2123 | bpstat | |
2124 | bpstat_stop_status (pc, not_a_breakpoint) | |
2125 | CORE_ADDR *pc; | |
2126 | int not_a_breakpoint; | |
2127 | { | |
2128 | register struct breakpoint *b, *temp; | |
2129 | CORE_ADDR bp_addr; | |
2130 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ | |
2131 | int real_breakpoint = 0; | |
2132 | /* Root of the chain of bpstat's */ | |
2133 | struct bpstats root_bs[1]; | |
2134 | /* Pointer to the last thing in the chain currently. */ | |
2135 | bpstat bs = root_bs; | |
2136 | static char message1[] = | |
c5aa993b JM |
2137 | "Error evaluating expression for watchpoint %d\n"; |
2138 | char message[sizeof (message1) + 30 /* slop */ ]; | |
c906108c SS |
2139 | |
2140 | /* Get the address where the breakpoint would have been. */ | |
2141 | bp_addr = *pc - DECR_PC_AFTER_BREAK; | |
2142 | ||
2143 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
2144 | { |
2145 | if (b->enable == disabled | |
2146 | || b->enable == shlib_disabled | |
2147 | || b->enable == call_disabled) | |
2148 | continue; | |
2149 | ||
2150 | if (b->type != bp_watchpoint | |
2151 | && b->type != bp_hardware_watchpoint | |
2152 | && b->type != bp_read_watchpoint | |
2153 | && b->type != bp_access_watchpoint | |
2154 | && b->type != bp_hardware_breakpoint | |
2155 | && b->type != bp_catch_fork | |
2156 | && b->type != bp_catch_vfork | |
2157 | && b->type != bp_catch_exec | |
2158 | && b->type != bp_catch_catch | |
2159 | && b->type != bp_catch_throw) /* a non-watchpoint bp */ | |
2160 | if (b->address != bp_addr || /* address doesn't match or */ | |
2161 | (overlay_debugging && /* overlay doesn't match */ | |
2162 | section_is_overlay (b->section) && | |
2163 | !section_is_mapped (b->section))) | |
c906108c SS |
2164 | continue; |
2165 | ||
c5aa993b JM |
2166 | if (b->type == bp_hardware_breakpoint |
2167 | && b->address != (*pc - DECR_PC_AFTER_HW_BREAK)) | |
2168 | continue; | |
2169 | ||
2170 | if (b->type != bp_watchpoint | |
2171 | && b->type != bp_hardware_watchpoint | |
2172 | && b->type != bp_read_watchpoint | |
2173 | && b->type != bp_access_watchpoint | |
2174 | && not_a_breakpoint) | |
2175 | continue; | |
2176 | ||
2177 | /* Is this a catchpoint of a load or unload? If so, did we | |
2178 | get a load or unload of the specified library? If not, | |
2179 | ignore it. */ | |
2180 | if ((b->type == bp_catch_load) | |
c906108c | 2181 | #if defined(SOLIB_HAVE_LOAD_EVENT) |
c5aa993b JM |
2182 | && (!SOLIB_HAVE_LOAD_EVENT (inferior_pid) |
2183 | || ((b->dll_pathname != NULL) | |
53a5351d JM |
2184 | && (strcmp (b->dll_pathname, |
2185 | SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid)) | |
2186 | != 0))) | |
c906108c | 2187 | #endif |
c5aa993b JM |
2188 | ) |
2189 | continue; | |
2190 | ||
2191 | if ((b->type == bp_catch_unload) | |
c906108c | 2192 | #if defined(SOLIB_HAVE_UNLOAD_EVENT) |
c5aa993b JM |
2193 | && (!SOLIB_HAVE_UNLOAD_EVENT (inferior_pid) |
2194 | || ((b->dll_pathname != NULL) | |
53a5351d JM |
2195 | && (strcmp (b->dll_pathname, |
2196 | SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid)) | |
2197 | != 0))) | |
c906108c | 2198 | #endif |
c5aa993b JM |
2199 | ) |
2200 | continue; | |
c906108c | 2201 | |
c5aa993b JM |
2202 | if ((b->type == bp_catch_fork) |
2203 | && !target_has_forked (inferior_pid, &b->forked_inferior_pid)) | |
2204 | continue; | |
c906108c | 2205 | |
c5aa993b JM |
2206 | if ((b->type == bp_catch_vfork) |
2207 | && !target_has_vforked (inferior_pid, &b->forked_inferior_pid)) | |
2208 | continue; | |
c906108c | 2209 | |
c5aa993b JM |
2210 | if ((b->type == bp_catch_exec) |
2211 | && !target_has_execd (inferior_pid, &b->exec_pathname)) | |
2212 | continue; | |
c906108c | 2213 | |
c5aa993b JM |
2214 | if (ep_is_exception_catchpoint (b) && |
2215 | !(current_exception_event = target_get_current_exception_event ())) | |
2216 | continue; | |
c906108c | 2217 | |
c5aa993b JM |
2218 | /* Come here if it's a watchpoint, or if the break address matches */ |
2219 | ||
2220 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ | |
2221 | ||
2222 | /* Watchpoints may change this, if not found to have triggered. */ | |
2223 | bs->stop = 1; | |
2224 | bs->print = 1; | |
2225 | ||
2226 | sprintf (message, message1, b->number); | |
53a5351d JM |
2227 | if (b->type == bp_watchpoint || |
2228 | b->type == bp_hardware_watchpoint) | |
c5aa993b | 2229 | { |
53a5351d JM |
2230 | switch (catch_errors (watchpoint_check, bs, message, |
2231 | RETURN_MASK_ALL)) | |
c5aa993b JM |
2232 | { |
2233 | case WP_DELETED: | |
2234 | /* We've already printed what needs to be printed. */ | |
2235 | bs->print_it = print_it_done; | |
2236 | /* Stop. */ | |
2237 | break; | |
2238 | case WP_VALUE_CHANGED: | |
2239 | /* Stop. */ | |
2240 | ++(b->hit_count); | |
2241 | break; | |
2242 | case WP_VALUE_NOT_CHANGED: | |
2243 | /* Don't stop. */ | |
2244 | bs->print_it = print_it_noop; | |
2245 | bs->stop = 0; | |
2246 | /* Don't consider this a hit. */ | |
2247 | --(b->hit_count); | |
2248 | continue; | |
2249 | default: | |
2250 | /* Can't happen. */ | |
2251 | /* FALLTHROUGH */ | |
2252 | case 0: | |
2253 | /* Error from catch_errors. */ | |
2254 | printf_filtered ("Watchpoint %d deleted.\n", b->number); | |
2255 | if (b->related_breakpoint) | |
2256 | b->related_breakpoint->disposition = del_at_next_stop; | |
2257 | b->disposition = del_at_next_stop; | |
2258 | /* We've already printed what needs to be printed. */ | |
2259 | bs->print_it = print_it_done; | |
2260 | ||
2261 | /* Stop. */ | |
2262 | break; | |
2263 | } | |
2264 | } | |
53a5351d JM |
2265 | else if (b->type == bp_read_watchpoint || |
2266 | b->type == bp_access_watchpoint) | |
c5aa993b JM |
2267 | { |
2268 | CORE_ADDR addr; | |
2269 | value_ptr v; | |
2270 | int found = 0; | |
2271 | ||
2272 | addr = target_stopped_data_address (); | |
2273 | if (addr == 0) | |
2274 | continue; | |
2275 | for (v = b->val_chain; v; v = v->next) | |
2276 | { | |
2277 | if (v->lval == lval_memory) | |
2278 | { | |
2279 | CORE_ADDR vaddr; | |
2280 | ||
2281 | vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
53a5351d JM |
2282 | /* Exact match not required. Within range is sufficient. |
2283 | */ | |
2284 | if (addr >= vaddr && | |
2285 | addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v))) | |
c5aa993b JM |
2286 | found = 1; |
2287 | } | |
2288 | } | |
2289 | if (found) | |
53a5351d JM |
2290 | switch (catch_errors (watchpoint_check, bs, message, |
2291 | RETURN_MASK_ALL)) | |
c906108c SS |
2292 | { |
2293 | case WP_DELETED: | |
2294 | /* We've already printed what needs to be printed. */ | |
2295 | bs->print_it = print_it_done; | |
2296 | /* Stop. */ | |
2297 | break; | |
2298 | case WP_VALUE_CHANGED: | |
c5aa993b | 2299 | case WP_VALUE_NOT_CHANGED: |
c906108c SS |
2300 | /* Stop. */ |
2301 | ++(b->hit_count); | |
2302 | break; | |
c906108c SS |
2303 | default: |
2304 | /* Can't happen. */ | |
c906108c SS |
2305 | case 0: |
2306 | /* Error from catch_errors. */ | |
2307 | printf_filtered ("Watchpoint %d deleted.\n", b->number); | |
2308 | if (b->related_breakpoint) | |
2309 | b->related_breakpoint->disposition = del_at_next_stop; | |
2310 | b->disposition = del_at_next_stop; | |
2311 | /* We've already printed what needs to be printed. */ | |
2312 | bs->print_it = print_it_done; | |
c906108c SS |
2313 | break; |
2314 | } | |
53a5351d JM |
2315 | else /* found == 0 */ |
2316 | { | |
2317 | /* This is a case where some watchpoint(s) triggered, | |
2318 | but not at the address of this watchpoint (FOUND | |
2319 | was left zero). So don't print anything for this | |
2320 | watchpoint. */ | |
2321 | bs->print_it = print_it_noop; | |
2322 | bs->stop = 0; | |
2323 | continue; | |
2324 | } | |
c5aa993b JM |
2325 | } |
2326 | else | |
2327 | { | |
2328 | /* By definition, an encountered breakpoint is a triggered | |
2329 | breakpoint. */ | |
2330 | ++(b->hit_count); | |
c906108c | 2331 | |
c5aa993b JM |
2332 | real_breakpoint = 1; |
2333 | } | |
2334 | ||
2335 | if (b->frame && b->frame != (get_current_frame ())->frame && | |
2336 | (b->type == bp_step_resume && | |
2337 | (INNER_THAN (get_current_frame ()->frame, b->frame)))) | |
2338 | bs->stop = 0; | |
2339 | else | |
2340 | { | |
2341 | int value_is_zero = 0; | |
2342 | ||
2343 | if (b->cond) | |
2344 | { | |
2345 | /* Need to select the frame, with all that implies | |
2346 | so that the conditions will have the right context. */ | |
2347 | select_frame (get_current_frame (), 0); | |
2348 | value_is_zero | |
2349 | = catch_errors (breakpoint_cond_eval, (b->cond), | |
2350 | "Error in testing breakpoint condition:\n", | |
2351 | RETURN_MASK_ALL); | |
2352 | /* FIXME-someday, should give breakpoint # */ | |
2353 | free_all_values (); | |
2354 | } | |
2355 | if (b->cond && value_is_zero) | |
2356 | { | |
2357 | bs->stop = 0; | |
2358 | /* Don't consider this a hit. */ | |
2359 | --(b->hit_count); | |
2360 | } | |
2361 | else if (b->ignore_count > 0) | |
2362 | { | |
2363 | b->ignore_count--; | |
2364 | bs->stop = 0; | |
2365 | } | |
2366 | else | |
2367 | { | |
2368 | /* We will stop here */ | |
2369 | if (b->disposition == disable) | |
2370 | b->enable = disabled; | |
2371 | bs->commands = b->commands; | |
2372 | if (b->silent) | |
2373 | bs->print = 0; | |
2374 | if (bs->commands && | |
2375 | (STREQ ("silent", bs->commands->line) || | |
2376 | (xdb_commands && STREQ ("Q", bs->commands->line)))) | |
2377 | { | |
2378 | bs->commands = bs->commands->next; | |
c906108c | 2379 | bs->print = 0; |
c5aa993b JM |
2380 | } |
2381 | } | |
2382 | } | |
2383 | /* Print nothing for this entry if we dont stop or if we dont print. */ | |
2384 | if (bs->stop == 0 || bs->print == 0) | |
2385 | bs->print_it = print_it_noop; | |
2386 | } | |
c906108c SS |
2387 | |
2388 | bs->next = NULL; /* Terminate the chain */ | |
2389 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
2390 | ||
2391 | if (real_breakpoint && bs) | |
2392 | { | |
c5aa993b | 2393 | if (bs->breakpoint_at->type == bp_hardware_breakpoint) |
c906108c | 2394 | { |
c5aa993b | 2395 | if (DECR_PC_AFTER_HW_BREAK != 0) |
c906108c SS |
2396 | { |
2397 | *pc = *pc - DECR_PC_AFTER_HW_BREAK; | |
2398 | write_pc (*pc); | |
2399 | } | |
2400 | } | |
2401 | else | |
2402 | { | |
2403 | if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs) | |
2404 | { | |
2405 | *pc = bp_addr; | |
2406 | #if defined (SHIFT_INST_REGS) | |
c5aa993b | 2407 | SHIFT_INST_REGS (); |
c906108c SS |
2408 | #else /* No SHIFT_INST_REGS. */ |
2409 | write_pc (bp_addr); | |
2410 | #endif /* No SHIFT_INST_REGS. */ | |
2411 | } | |
2412 | } | |
2413 | } | |
2414 | ||
2415 | /* The value of a hardware watchpoint hasn't changed, but the | |
2416 | intermediate memory locations we are watching may have. */ | |
c5aa993b | 2417 | if (bs && !bs->stop && |
c906108c SS |
2418 | (bs->breakpoint_at->type == bp_hardware_watchpoint || |
2419 | bs->breakpoint_at->type == bp_read_watchpoint || | |
2420 | bs->breakpoint_at->type == bp_access_watchpoint)) | |
2421 | { | |
2422 | remove_breakpoints (); | |
2423 | insert_breakpoints (); | |
2424 | } | |
2425 | return bs; | |
2426 | } | |
2427 | \f | |
2428 | /* Tell what to do about this bpstat. */ | |
2429 | struct bpstat_what | |
2430 | bpstat_what (bs) | |
2431 | bpstat bs; | |
2432 | { | |
2433 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
2434 | enum class |
2435 | { | |
2436 | /* This bpstat element has no effect on the main_action. */ | |
2437 | no_effect = 0, | |
2438 | ||
2439 | /* There was a watchpoint, stop but don't print. */ | |
2440 | wp_silent, | |
c906108c | 2441 | |
c5aa993b JM |
2442 | /* There was a watchpoint, stop and print. */ |
2443 | wp_noisy, | |
c906108c | 2444 | |
c5aa993b JM |
2445 | /* There was a breakpoint but we're not stopping. */ |
2446 | bp_nostop, | |
c906108c | 2447 | |
c5aa993b JM |
2448 | /* There was a breakpoint, stop but don't print. */ |
2449 | bp_silent, | |
c906108c | 2450 | |
c5aa993b JM |
2451 | /* There was a breakpoint, stop and print. */ |
2452 | bp_noisy, | |
c906108c | 2453 | |
c5aa993b JM |
2454 | /* We hit the longjmp breakpoint. */ |
2455 | long_jump, | |
c906108c | 2456 | |
c5aa993b JM |
2457 | /* We hit the longjmp_resume breakpoint. */ |
2458 | long_resume, | |
c906108c | 2459 | |
c5aa993b JM |
2460 | /* We hit the step_resume breakpoint. */ |
2461 | step_resume, | |
c906108c | 2462 | |
c5aa993b JM |
2463 | /* We hit the through_sigtramp breakpoint. */ |
2464 | through_sig, | |
c906108c | 2465 | |
c5aa993b JM |
2466 | /* We hit the shared library event breakpoint. */ |
2467 | shlib_event, | |
c906108c | 2468 | |
c5aa993b JM |
2469 | /* We caught a shared library event. */ |
2470 | catch_shlib_event, | |
c906108c | 2471 | |
c5aa993b JM |
2472 | /* This is just used to count how many enums there are. */ |
2473 | class_last | |
c906108c SS |
2474 | }; |
2475 | ||
2476 | /* Here is the table which drives this routine. So that we can | |
2477 | format it pretty, we define some abbreviations for the | |
2478 | enum bpstat_what codes. */ | |
2479 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
2480 | #define ss BPSTAT_WHAT_STOP_SILENT | |
2481 | #define sn BPSTAT_WHAT_STOP_NOISY | |
2482 | #define sgl BPSTAT_WHAT_SINGLE | |
2483 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
2484 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
2485 | #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE | |
2486 | #define sr BPSTAT_WHAT_STEP_RESUME | |
2487 | #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP | |
2488 | #define shl BPSTAT_WHAT_CHECK_SHLIBS | |
2489 | #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK | |
2490 | ||
2491 | /* "Can't happen." Might want to print an error message. | |
2492 | abort() is not out of the question, but chances are GDB is just | |
2493 | a bit confused, not unusable. */ | |
2494 | #define err BPSTAT_WHAT_STOP_NOISY | |
2495 | ||
2496 | /* Given an old action and a class, come up with a new action. */ | |
2497 | /* One interesting property of this table is that wp_silent is the same | |
2498 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
2499 | after stopping, the check for whether to step over a breakpoint | |
2500 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
2501 | reference to how we stopped. We retain separate wp_silent and |
2502 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
2503 | |
2504 | Another possibly interesting property of this table is that | |
2505 | there's a partial ordering, priority-like, of the actions. Once | |
2506 | you've decided that some action is appropriate, you'll never go | |
2507 | back and decide something of a lower priority is better. The | |
2508 | ordering is: | |
2509 | ||
c5aa993b JM |
2510 | kc < clr sgl shl slr sn sr ss ts |
2511 | sgl < clrs shl shlr slr sn sr ss ts | |
2512 | slr < err shl shlr sn sr ss ts | |
2513 | clr < clrs err shl shlr sn sr ss ts | |
2514 | clrs < err shl shlr sn sr ss ts | |
2515 | ss < shl shlr sn sr ts | |
2516 | sn < shl shlr sr ts | |
2517 | sr < shl shlr ts | |
2518 | shl < shlr | |
2519 | ts < | |
2520 | shlr < | |
2521 | ||
43ff13b4 JM |
2522 | What I think this means is that we don't need a damned table |
2523 | here. If you just put the rows and columns in the right order, | |
2524 | it'd look awfully regular. We could simply walk the bpstat list | |
2525 | and choose the highest priority action we find, with a little | |
2526 | logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/ | |
2527 | CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says | |
2528 | is messy anyway). */ | |
c906108c SS |
2529 | |
2530 | /* step_resume entries: a step resume breakpoint overrides another | |
2531 | breakpoint of signal handling (see comment in wait_for_inferior | |
2532 | at first IN_SIGTRAMP where we set the step_resume breakpoint). */ | |
2533 | /* We handle the through_sigtramp_breakpoint the same way; having both | |
2534 | one of those and a step_resume_breakpoint is probably very rare (?). */ | |
2535 | ||
2536 | static const enum bpstat_what_main_action | |
c5aa993b JM |
2537 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
2538 | { | |
2539 | /* old action */ | |
2540 | /* kc ss sn sgl slr clr clrs sr ts shl shlr | |
2541 | */ | |
2542 | /*no_effect */ | |
2543 | {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr}, | |
2544 | /*wp_silent */ | |
2545 | {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, | |
2546 | /*wp_noisy */ | |
2547 | {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, | |
2548 | /*bp_nostop */ | |
2549 | {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr}, | |
2550 | /*bp_silent */ | |
2551 | {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, | |
2552 | /*bp_noisy */ | |
2553 | {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, | |
2554 | /*long_jump */ | |
2555 | {slr, ss, sn, slr, err, err, err, sr, ts, shl, shlr}, | |
2556 | /*long_resume */ | |
2557 | {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr}, | |
2558 | /*step_resume */ | |
2559 | {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr}, | |
2560 | /*through_sig */ | |
2561 | {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr}, | |
2562 | /*shlib */ | |
2563 | {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr}, | |
2564 | /*catch_shlib */ | |
2565 | {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr} | |
2566 | }; | |
c906108c SS |
2567 | |
2568 | #undef kc | |
2569 | #undef ss | |
2570 | #undef sn | |
2571 | #undef sgl | |
2572 | #undef slr | |
2573 | #undef clr | |
2574 | #undef clrs | |
2575 | #undef err | |
2576 | #undef sr | |
2577 | #undef ts | |
2578 | #undef shl | |
2579 | #undef shlr | |
2580 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; | |
2581 | struct bpstat_what retval; | |
2582 | ||
2583 | retval.call_dummy = 0; | |
2584 | for (; bs != NULL; bs = bs->next) | |
2585 | { | |
2586 | enum class bs_class = no_effect; | |
2587 | if (bs->breakpoint_at == NULL) | |
2588 | /* I suspect this can happen if it was a momentary breakpoint | |
2589 | which has since been deleted. */ | |
2590 | continue; | |
2591 | switch (bs->breakpoint_at->type) | |
2592 | { | |
2593 | case bp_none: | |
2594 | continue; | |
2595 | ||
2596 | case bp_breakpoint: | |
2597 | case bp_hardware_breakpoint: | |
2598 | case bp_until: | |
2599 | case bp_finish: | |
2600 | if (bs->stop) | |
2601 | { | |
2602 | if (bs->print) | |
2603 | bs_class = bp_noisy; | |
2604 | else | |
2605 | bs_class = bp_silent; | |
2606 | } | |
2607 | else | |
2608 | bs_class = bp_nostop; | |
2609 | break; | |
2610 | case bp_watchpoint: | |
2611 | case bp_hardware_watchpoint: | |
2612 | case bp_read_watchpoint: | |
2613 | case bp_access_watchpoint: | |
2614 | if (bs->stop) | |
2615 | { | |
2616 | if (bs->print) | |
2617 | bs_class = wp_noisy; | |
2618 | else | |
2619 | bs_class = wp_silent; | |
2620 | } | |
2621 | else | |
53a5351d JM |
2622 | /* There was a watchpoint, but we're not stopping. |
2623 | This requires no further action. */ | |
c906108c SS |
2624 | bs_class = no_effect; |
2625 | break; | |
2626 | case bp_longjmp: | |
2627 | bs_class = long_jump; | |
2628 | break; | |
2629 | case bp_longjmp_resume: | |
2630 | bs_class = long_resume; | |
2631 | break; | |
2632 | case bp_step_resume: | |
2633 | if (bs->stop) | |
2634 | { | |
2635 | bs_class = step_resume; | |
2636 | } | |
2637 | else | |
2638 | /* It is for the wrong frame. */ | |
2639 | bs_class = bp_nostop; | |
2640 | break; | |
2641 | case bp_through_sigtramp: | |
2642 | bs_class = through_sig; | |
2643 | break; | |
2644 | case bp_watchpoint_scope: | |
2645 | bs_class = bp_nostop; | |
2646 | break; | |
c5aa993b JM |
2647 | case bp_shlib_event: |
2648 | bs_class = shlib_event; | |
2649 | break; | |
2650 | case bp_catch_load: | |
2651 | case bp_catch_unload: | |
2652 | /* Only if this catchpoint triggered should we cause the | |
2653 | step-out-of-dld behaviour. Otherwise, we ignore this | |
2654 | catchpoint. */ | |
2655 | if (bs->stop) | |
2656 | bs_class = catch_shlib_event; | |
2657 | else | |
2658 | bs_class = no_effect; | |
2659 | break; | |
2660 | case bp_catch_fork: | |
2661 | case bp_catch_vfork: | |
2662 | case bp_catch_exec: | |
2663 | if (bs->stop) | |
2664 | { | |
2665 | if (bs->print) | |
2666 | bs_class = bp_noisy; | |
2667 | else | |
2668 | bs_class = bp_silent; | |
2669 | } | |
2670 | else | |
53a5351d JM |
2671 | /* There was a catchpoint, but we're not stopping. |
2672 | This requires no further action. */ | |
c5aa993b JM |
2673 | bs_class = no_effect; |
2674 | break; | |
2675 | case bp_catch_catch: | |
2676 | if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH) | |
2677 | bs_class = bp_nostop; | |
2678 | else if (bs->stop) | |
2679 | bs_class = bs->print ? bp_noisy : bp_silent; | |
2680 | break; | |
2681 | case bp_catch_throw: | |
2682 | if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW) | |
2683 | bs_class = bp_nostop; | |
2684 | else if (bs->stop) | |
2685 | bs_class = bs->print ? bp_noisy : bp_silent; | |
c906108c | 2686 | break; |
c906108c | 2687 | case bp_call_dummy: |
53a5351d JM |
2688 | /* Make sure the action is stop (silent or noisy), |
2689 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
2690 | bs_class = bp_silent; |
2691 | retval.call_dummy = 1; | |
2692 | break; | |
2693 | } | |
c5aa993b | 2694 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
2695 | } |
2696 | retval.main_action = current_action; | |
2697 | return retval; | |
2698 | } | |
2699 | ||
2700 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
2701 | without hardware support). This isn't related to a specific bpstat, | |
2702 | just to things like whether watchpoints are set. */ | |
2703 | ||
c5aa993b | 2704 | int |
c906108c SS |
2705 | bpstat_should_step () |
2706 | { | |
2707 | struct breakpoint *b; | |
2708 | ALL_BREAKPOINTS (b) | |
2709 | if (b->enable == enabled && b->type == bp_watchpoint) | |
c5aa993b | 2710 | return 1; |
c906108c SS |
2711 | return 0; |
2712 | } | |
2713 | ||
2714 | /* Nonzero if there are enabled hardware watchpoints. */ | |
2715 | int | |
2716 | bpstat_have_active_hw_watchpoints () | |
2717 | { | |
2718 | struct breakpoint *b; | |
2719 | ALL_BREAKPOINTS (b) | |
2720 | if ((b->enable == enabled) && | |
c5aa993b JM |
2721 | (b->inserted) && |
2722 | ((b->type == bp_hardware_watchpoint) || | |
2723 | (b->type == bp_read_watchpoint) || | |
2724 | (b->type == bp_access_watchpoint))) | |
2725 | return 1; | |
c906108c SS |
2726 | return 0; |
2727 | } | |
c906108c | 2728 | \f |
c5aa993b | 2729 | |
c906108c SS |
2730 | /* Given a bpstat that records zero or more triggered eventpoints, this |
2731 | function returns another bpstat which contains only the catchpoints | |
2732 | on that first list, if any. */ | |
2733 | void | |
2734 | bpstat_get_triggered_catchpoints (ep_list, cp_list) | |
c5aa993b JM |
2735 | bpstat ep_list; |
2736 | bpstat *cp_list; | |
2737 | { | |
2738 | struct bpstats root_bs[1]; | |
2739 | bpstat bs = root_bs; | |
2740 | struct breakpoint *ep; | |
2741 | char *dll_pathname; | |
2742 | ||
c906108c SS |
2743 | bpstat_clear (cp_list); |
2744 | root_bs->next = NULL; | |
c5aa993b JM |
2745 | |
2746 | for (; ep_list != NULL; ep_list = ep_list->next) | |
c906108c SS |
2747 | { |
2748 | /* Is this eventpoint a catchpoint? If not, ignore it. */ | |
2749 | ep = ep_list->breakpoint_at; | |
2750 | if (ep == NULL) | |
c5aa993b JM |
2751 | break; |
2752 | if ((ep->type != bp_catch_load) && | |
2753 | (ep->type != bp_catch_unload) && | |
2754 | (ep->type != bp_catch_catch) && | |
53a5351d JM |
2755 | (ep->type != bp_catch_throw)) |
2756 | /* pai: (temp) ADD fork/vfork here!! */ | |
c5aa993b JM |
2757 | continue; |
2758 | ||
c906108c SS |
2759 | /* Yes; add it to the list. */ |
2760 | bs = bpstat_alloc (ep, bs); | |
2761 | *bs = *ep_list; | |
2762 | bs->next = NULL; | |
2763 | bs = root_bs->next; | |
c5aa993b | 2764 | |
c906108c SS |
2765 | #if defined(SOLIB_ADD) |
2766 | /* Also, for each triggered catchpoint, tag it with the name of | |
2767 | the library that caused this trigger. (We copy the name now, | |
2768 | because it's only guaranteed to be available NOW, when the | |
2769 | catchpoint triggers. Clients who may wish to know the name | |
2770 | later must get it from the catchpoint itself.) */ | |
2771 | if (ep->triggered_dll_pathname != NULL) | |
c5aa993b | 2772 | free (ep->triggered_dll_pathname); |
c906108c | 2773 | if (ep->type == bp_catch_load) |
c5aa993b | 2774 | dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (inferior_pid); |
c906108c | 2775 | else |
c5aa993b | 2776 | dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (inferior_pid); |
c906108c SS |
2777 | #else |
2778 | dll_pathname = NULL; | |
2779 | #endif | |
2780 | if (dll_pathname) | |
2781 | { | |
53a5351d JM |
2782 | ep->triggered_dll_pathname = (char *) |
2783 | xmalloc (strlen (dll_pathname) + 1); | |
c906108c SS |
2784 | strcpy (ep->triggered_dll_pathname, dll_pathname); |
2785 | } | |
2786 | else | |
2787 | ep->triggered_dll_pathname = NULL; | |
2788 | } | |
c5aa993b | 2789 | |
c906108c SS |
2790 | *cp_list = bs; |
2791 | } | |
2792 | ||
2793 | /* Print information on breakpoint number BNUM, or -1 if all. | |
2794 | If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS | |
2795 | is nonzero, process only watchpoints. */ | |
2796 | ||
c5aa993b JM |
2797 | typedef struct |
2798 | { | |
2799 | enum bptype type; | |
2800 | char *description; | |
2801 | } | |
2802 | ep_type_description_t; | |
c906108c SS |
2803 | |
2804 | static void | |
2805 | breakpoint_1 (bnum, allflag) | |
2806 | int bnum; | |
2807 | int allflag; | |
2808 | { | |
2809 | register struct breakpoint *b; | |
2810 | register struct command_line *l; | |
2811 | register struct symbol *sym; | |
c5aa993b | 2812 | CORE_ADDR last_addr = (CORE_ADDR) - 1; |
c906108c | 2813 | int found_a_breakpoint = 0; |
c5aa993b | 2814 | static ep_type_description_t bptypes[] = |
c906108c | 2815 | { |
c5aa993b JM |
2816 | {bp_none, "?deleted?"}, |
2817 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 2818 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
2819 | {bp_until, "until"}, |
2820 | {bp_finish, "finish"}, | |
2821 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 2822 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
2823 | {bp_read_watchpoint, "read watchpoint"}, |
2824 | {bp_access_watchpoint, "acc watchpoint"}, | |
2825 | {bp_longjmp, "longjmp"}, | |
2826 | {bp_longjmp_resume, "longjmp resume"}, | |
2827 | {bp_step_resume, "step resume"}, | |
2828 | {bp_through_sigtramp, "sigtramp"}, | |
2829 | {bp_watchpoint_scope, "watchpoint scope"}, | |
2830 | {bp_call_dummy, "call dummy"}, | |
2831 | {bp_shlib_event, "shlib events"}, | |
2832 | {bp_catch_load, "catch load"}, | |
2833 | {bp_catch_unload, "catch unload"}, | |
2834 | {bp_catch_fork, "catch fork"}, | |
2835 | {bp_catch_vfork, "catch vfork"}, | |
2836 | {bp_catch_exec, "catch exec"}, | |
2837 | {bp_catch_catch, "catch catch"}, | |
2838 | {bp_catch_throw, "catch throw"} | |
2839 | }; | |
2840 | ||
2841 | static char *bpdisps[] = | |
2842 | {"del", "dstp", "dis", "keep"}; | |
c906108c SS |
2843 | static char bpenables[] = "nyn"; |
2844 | char wrap_indent[80]; | |
2845 | ||
392a587b | 2846 | |
53a5351d | 2847 | |
c906108c SS |
2848 | ALL_BREAKPOINTS (b) |
2849 | if (bnum == -1 | |
2850 | || bnum == b->number) | |
c5aa993b | 2851 | { |
c906108c | 2852 | /* We only print out user settable breakpoints unless the allflag is set. */ |
c5aa993b JM |
2853 | if (!allflag |
2854 | && b->type != bp_breakpoint | |
2855 | && b->type != bp_catch_load | |
2856 | && b->type != bp_catch_unload | |
2857 | && b->type != bp_catch_fork | |
2858 | && b->type != bp_catch_vfork | |
2859 | && b->type != bp_catch_exec | |
2860 | && b->type != bp_catch_catch | |
2861 | && b->type != bp_catch_throw | |
2862 | && b->type != bp_hardware_breakpoint | |
2863 | && b->type != bp_watchpoint | |
2864 | && b->type != bp_read_watchpoint | |
2865 | && b->type != bp_access_watchpoint | |
2866 | && b->type != bp_hardware_watchpoint) | |
2867 | continue; | |
c906108c | 2868 | |
c5aa993b JM |
2869 | if (!found_a_breakpoint++) |
2870 | { | |
2871 | annotate_breakpoints_headers (); | |
2872 | ||
2873 | annotate_field (0); | |
2874 | printf_filtered ("Num "); | |
2875 | annotate_field (1); | |
2876 | printf_filtered ("Type "); | |
2877 | annotate_field (2); | |
2878 | printf_filtered ("Disp "); | |
2879 | annotate_field (3); | |
2880 | printf_filtered ("Enb "); | |
2881 | if (addressprint) | |
2882 | { | |
2883 | annotate_field (4); | |
2884 | printf_filtered ("Address "); | |
2885 | } | |
2886 | annotate_field (5); | |
2887 | printf_filtered ("What\n"); | |
c906108c | 2888 | |
c5aa993b JM |
2889 | annotate_breakpoints_table (); |
2890 | } | |
c906108c | 2891 | |
c5aa993b JM |
2892 | annotate_record (); |
2893 | annotate_field (0); | |
2894 | printf_filtered ("%-3d ", b->number); | |
2895 | annotate_field (1); | |
2896 | if ((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0]))) | |
2897 | error ("bptypes table does not describe type #%d.", (int) b->type); | |
2898 | if ((int) b->type != bptypes[(int) b->type].type) | |
2899 | error ("bptypes table does not describe type #%d?", (int) b->type); | |
2900 | printf_filtered ("%-14s ", bptypes[(int) b->type].description); | |
2901 | annotate_field (2); | |
2902 | printf_filtered ("%-4s ", bpdisps[(int) b->disposition]); | |
2903 | annotate_field (3); | |
2904 | printf_filtered ("%-3c ", bpenables[(int) b->enable]); | |
2905 | ||
2906 | strcpy (wrap_indent, " "); | |
2907 | if (addressprint) | |
2908 | strcat (wrap_indent, " "); | |
2909 | switch (b->type) | |
2910 | { | |
2911 | case bp_watchpoint: | |
2912 | case bp_hardware_watchpoint: | |
2913 | case bp_read_watchpoint: | |
2914 | case bp_access_watchpoint: | |
2915 | /* Field 4, the address, is omitted (which makes the columns | |
2916 | not line up too nicely with the headers, but the effect | |
2917 | is relatively readable). */ | |
2918 | annotate_field (5); | |
2919 | print_expression (b->exp, gdb_stdout); | |
2920 | break; | |
c906108c | 2921 | |
c5aa993b JM |
2922 | case bp_catch_load: |
2923 | case bp_catch_unload: | |
2924 | /* Field 4, the address, is omitted (which makes the columns | |
2925 | not line up too nicely with the headers, but the effect | |
2926 | is relatively readable). */ | |
2927 | annotate_field (5); | |
2928 | if (b->dll_pathname == NULL) | |
2929 | printf_filtered ("<any library> "); | |
2930 | else | |
2931 | printf_filtered ("library \"%s\" ", b->dll_pathname); | |
2932 | break; | |
c906108c | 2933 | |
c5aa993b JM |
2934 | case bp_catch_fork: |
2935 | case bp_catch_vfork: | |
2936 | /* Field 4, the address, is omitted (which makes the columns | |
2937 | not line up too nicely with the headers, but the effect | |
2938 | is relatively readable). */ | |
2939 | annotate_field (5); | |
2940 | if (b->forked_inferior_pid != 0) | |
2941 | printf_filtered ("process %d ", b->forked_inferior_pid); | |
2942 | break; | |
c906108c | 2943 | |
c5aa993b JM |
2944 | case bp_catch_exec: |
2945 | /* Field 4, the address, is omitted (which makes the columns | |
2946 | not line up too nicely with the headers, but the effect | |
2947 | is relatively readable). */ | |
2948 | annotate_field (5); | |
2949 | if (b->exec_pathname != NULL) | |
2950 | printf_filtered ("program \"%s\" ", b->exec_pathname); | |
2951 | break; | |
2952 | case bp_catch_catch: | |
2953 | /* Field 4, the address, is omitted (which makes the columns | |
2954 | not line up too nicely with the headers, but the effect | |
2955 | is relatively readable). */ | |
2956 | annotate_field (5); | |
2957 | printf_filtered ("exception catch "); | |
2958 | break; | |
2959 | case bp_catch_throw: | |
2960 | /* Field 4, the address, is omitted (which makes the columns | |
2961 | not line up too nicely with the headers, but the effect | |
2962 | is relatively readable). */ | |
2963 | annotate_field (5); | |
2964 | printf_filtered ("exception throw "); | |
2965 | break; | |
c906108c | 2966 | |
c5aa993b JM |
2967 | case bp_breakpoint: |
2968 | case bp_hardware_breakpoint: | |
2969 | case bp_until: | |
2970 | case bp_finish: | |
2971 | case bp_longjmp: | |
2972 | case bp_longjmp_resume: | |
2973 | case bp_step_resume: | |
2974 | case bp_through_sigtramp: | |
2975 | case bp_watchpoint_scope: | |
2976 | case bp_call_dummy: | |
2977 | case bp_shlib_event: | |
2978 | if (addressprint) | |
2979 | { | |
2980 | annotate_field (4); | |
2981 | /* FIXME-32x64: need a print_address_numeric with | |
2982 | field width */ | |
2983 | printf_filtered | |
2984 | ("%s ", | |
2985 | local_hex_string_custom | |
2986 | ((unsigned long) b->address, "08l")); | |
2987 | } | |
c906108c | 2988 | |
c5aa993b | 2989 | annotate_field (5); |
c906108c | 2990 | |
c5aa993b JM |
2991 | last_addr = b->address; |
2992 | if (b->source_file) | |
2993 | { | |
2994 | sym = find_pc_sect_function (b->address, b->section); | |
2995 | if (sym) | |
2996 | { | |
2997 | fputs_filtered ("in ", gdb_stdout); | |
2998 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout); | |
2999 | wrap_here (wrap_indent); | |
3000 | fputs_filtered (" at ", gdb_stdout); | |
3001 | } | |
3002 | fputs_filtered (b->source_file, gdb_stdout); | |
3003 | printf_filtered (":%d", b->line_number); | |
3004 | } | |
3005 | else | |
3006 | print_address_symbolic (b->address, gdb_stdout, demangle, " "); | |
3007 | break; | |
3008 | } | |
c906108c | 3009 | |
c5aa993b JM |
3010 | if (b->thread != -1) |
3011 | printf_filtered (" thread %d", b->thread); | |
c906108c | 3012 | |
c5aa993b | 3013 | printf_filtered ("\n"); |
c906108c | 3014 | |
c5aa993b JM |
3015 | if (b->frame) |
3016 | { | |
3017 | annotate_field (6); | |
c906108c | 3018 | |
c5aa993b JM |
3019 | printf_filtered ("\tstop only in stack frame at "); |
3020 | print_address_numeric (b->frame, 1, gdb_stdout); | |
3021 | printf_filtered ("\n"); | |
3022 | } | |
c906108c | 3023 | |
c5aa993b JM |
3024 | if (b->cond) |
3025 | { | |
3026 | annotate_field (7); | |
c906108c | 3027 | |
c5aa993b JM |
3028 | printf_filtered ("\tstop only if "); |
3029 | print_expression (b->cond, gdb_stdout); | |
3030 | printf_filtered ("\n"); | |
3031 | } | |
3032 | ||
3033 | if (b->thread != -1) | |
3034 | { | |
3035 | /* FIXME should make an annotation for this */ | |
3036 | printf_filtered ("\tstop only in thread %d\n", b->thread); | |
3037 | } | |
3038 | ||
3039 | if (show_breakpoint_hit_counts && b->hit_count) | |
3040 | { | |
3041 | /* FIXME should make an annotation for this */ | |
3042 | if (ep_is_catchpoint (b)) | |
3043 | printf_filtered ("\tcatchpoint"); | |
3044 | else | |
3045 | printf_filtered ("\tbreakpoint"); | |
3046 | printf_filtered (" already hit %d time%s\n", | |
3047 | b->hit_count, (b->hit_count == 1 ? "" : "s")); | |
3048 | } | |
3049 | ||
3050 | if (b->ignore_count) | |
3051 | { | |
3052 | annotate_field (8); | |
3053 | ||
3054 | printf_filtered ("\tignore next %d hits\n", b->ignore_count); | |
3055 | } | |
3056 | ||
3057 | if ((l = b->commands)) | |
3058 | { | |
3059 | annotate_field (9); | |
3060 | ||
3061 | while (l) | |
3062 | { | |
3063 | print_command_line (l, 4, gdb_stdout); | |
3064 | l = l->next; | |
3065 | } | |
3066 | } | |
3067 | } | |
c906108c SS |
3068 | |
3069 | if (!found_a_breakpoint) | |
3070 | { | |
3071 | if (bnum == -1) | |
c5aa993b | 3072 | printf_filtered ("No breakpoints or watchpoints.\n"); |
c906108c | 3073 | else |
c5aa993b | 3074 | printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum); |
c906108c SS |
3075 | } |
3076 | else | |
3077 | /* Compare against (CORE_ADDR)-1 in case some compiler decides | |
3078 | that a comparison of an unsigned with -1 is always false. */ | |
c5aa993b JM |
3079 | if (last_addr != (CORE_ADDR) - 1) |
3080 | set_next_address (last_addr); | |
c906108c SS |
3081 | |
3082 | annotate_breakpoints_table_end (); | |
3083 | } | |
3084 | ||
3085 | /* ARGSUSED */ | |
3086 | static void | |
3087 | breakpoints_info (bnum_exp, from_tty) | |
3088 | char *bnum_exp; | |
3089 | int from_tty; | |
3090 | { | |
3091 | int bnum = -1; | |
3092 | ||
3093 | if (bnum_exp) | |
3094 | bnum = parse_and_eval_address (bnum_exp); | |
3095 | ||
3096 | breakpoint_1 (bnum, 0); | |
3097 | } | |
3098 | ||
c906108c | 3099 | /* ARGSUSED */ |
7a292a7a | 3100 | static void |
c906108c SS |
3101 | maintenance_info_breakpoints (bnum_exp, from_tty) |
3102 | char *bnum_exp; | |
3103 | int from_tty; | |
3104 | { | |
3105 | int bnum = -1; | |
3106 | ||
3107 | if (bnum_exp) | |
3108 | bnum = parse_and_eval_address (bnum_exp); | |
3109 | ||
3110 | breakpoint_1 (bnum, 1); | |
3111 | } | |
3112 | ||
c906108c SS |
3113 | /* Print a message describing any breakpoints set at PC. */ |
3114 | ||
3115 | static void | |
3116 | describe_other_breakpoints (pc, section) | |
3117 | CORE_ADDR pc; | |
3118 | asection *section; | |
3119 | { | |
3120 | register int others = 0; | |
3121 | register struct breakpoint *b; | |
3122 | ||
3123 | ALL_BREAKPOINTS (b) | |
3124 | if (b->address == pc) | |
c5aa993b JM |
3125 | if (overlay_debugging == 0 || |
3126 | b->section == section) | |
3127 | others++; | |
c906108c SS |
3128 | if (others > 0) |
3129 | { | |
3130 | printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : ""); | |
3131 | ALL_BREAKPOINTS (b) | |
3132 | if (b->address == pc) | |
c5aa993b JM |
3133 | if (overlay_debugging == 0 || |
3134 | b->section == section) | |
3135 | { | |
3136 | others--; | |
3137 | printf_filtered | |
3138 | ("%d%s%s ", | |
3139 | b->number, | |
53a5351d JM |
3140 | ((b->enable == disabled || |
3141 | b->enable == shlib_disabled || | |
3142 | b->enable == call_disabled) | |
c5aa993b JM |
3143 | ? " (disabled)" : ""), |
3144 | (others > 1) ? "," : ((others == 1) ? " and" : "")); | |
3145 | } | |
c906108c SS |
3146 | printf_filtered ("also set at pc "); |
3147 | print_address_numeric (pc, 1, gdb_stdout); | |
3148 | printf_filtered (".\n"); | |
3149 | } | |
3150 | } | |
3151 | \f | |
3152 | /* Set the default place to put a breakpoint | |
3153 | for the `break' command with no arguments. */ | |
3154 | ||
3155 | void | |
3156 | set_default_breakpoint (valid, addr, symtab, line) | |
3157 | int valid; | |
3158 | CORE_ADDR addr; | |
3159 | struct symtab *symtab; | |
3160 | int line; | |
3161 | { | |
3162 | default_breakpoint_valid = valid; | |
3163 | default_breakpoint_address = addr; | |
3164 | default_breakpoint_symtab = symtab; | |
3165 | default_breakpoint_line = line; | |
3166 | } | |
3167 | ||
3168 | /* Rescan breakpoints at address ADDRESS, | |
3169 | marking the first one as "first" and any others as "duplicates". | |
3170 | This is so that the bpt instruction is only inserted once. */ | |
3171 | ||
3172 | static void | |
3173 | check_duplicates (address, section) | |
3174 | CORE_ADDR address; | |
3175 | asection *section; | |
3176 | { | |
3177 | register struct breakpoint *b; | |
3178 | register int count = 0; | |
3179 | ||
3180 | if (address == 0) /* Watchpoints are uninteresting */ | |
3181 | return; | |
3182 | ||
3183 | ALL_BREAKPOINTS (b) | |
3184 | if (b->enable != disabled | |
3185 | && b->enable != shlib_disabled | |
3186 | && b->enable != call_disabled | |
3187 | && b->address == address | |
3188 | && (overlay_debugging == 0 || b->section == section)) | |
c5aa993b JM |
3189 | { |
3190 | count++; | |
3191 | b->duplicate = count > 1; | |
3192 | } | |
c906108c SS |
3193 | } |
3194 | ||
3195 | /* Low level routine to set a breakpoint. | |
3196 | Takes as args the three things that every breakpoint must have. | |
3197 | Returns the breakpoint object so caller can set other things. | |
3198 | Does not set the breakpoint number! | |
3199 | Does not print anything. | |
3200 | ||
3201 | ==> This routine should not be called if there is a chance of later | |
3202 | error(); otherwise it leaves a bogus breakpoint on the chain. Validate | |
3203 | your arguments BEFORE calling this routine! */ | |
3204 | ||
3205 | struct breakpoint * | |
3206 | set_raw_breakpoint (sal) | |
3207 | struct symtab_and_line sal; | |
3208 | { | |
3209 | register struct breakpoint *b, *b1; | |
3210 | ||
3211 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
3212 | memset (b, 0, sizeof (*b)); | |
3213 | b->address = sal.pc; | |
3214 | if (sal.symtab == NULL) | |
3215 | b->source_file = NULL; | |
3216 | else | |
3217 | b->source_file = savestring (sal.symtab->filename, | |
3218 | strlen (sal.symtab->filename)); | |
3219 | b->section = sal.section; | |
3220 | b->language = current_language->la_language; | |
3221 | b->input_radix = input_radix; | |
3222 | b->thread = -1; | |
3223 | b->line_number = sal.line; | |
3224 | b->enable = enabled; | |
3225 | b->next = 0; | |
3226 | b->silent = 0; | |
3227 | b->ignore_count = 0; | |
3228 | b->commands = NULL; | |
3229 | b->frame = 0; | |
3230 | b->dll_pathname = NULL; | |
3231 | b->triggered_dll_pathname = NULL; | |
3232 | b->forked_inferior_pid = 0; | |
3233 | b->exec_pathname = NULL; | |
3234 | ||
3235 | /* Add this breakpoint to the end of the chain | |
3236 | so that a list of breakpoints will come out in order | |
3237 | of increasing numbers. */ | |
3238 | ||
3239 | b1 = breakpoint_chain; | |
3240 | if (b1 == 0) | |
3241 | breakpoint_chain = b; | |
3242 | else | |
3243 | { | |
3244 | while (b1->next) | |
3245 | b1 = b1->next; | |
3246 | b1->next = b; | |
3247 | } | |
3248 | ||
3249 | check_duplicates (sal.pc, sal.section); | |
3250 | breakpoints_changed (); | |
3251 | ||
3252 | return b; | |
3253 | } | |
3254 | ||
3255 | #ifdef GET_LONGJMP_TARGET | |
3256 | ||
3257 | static void | |
3258 | create_longjmp_breakpoint (func_name) | |
3259 | char *func_name; | |
3260 | { | |
3261 | struct symtab_and_line sal; | |
3262 | struct breakpoint *b; | |
3263 | ||
c5aa993b | 3264 | INIT_SAL (&sal); /* initialize to zeroes */ |
c906108c SS |
3265 | if (func_name != NULL) |
3266 | { | |
3267 | struct minimal_symbol *m; | |
3268 | ||
53a5351d JM |
3269 | m = lookup_minimal_symbol_text (func_name, NULL, |
3270 | (struct objfile *) NULL); | |
c906108c SS |
3271 | if (m) |
3272 | sal.pc = SYMBOL_VALUE_ADDRESS (m); | |
3273 | else | |
3274 | return; | |
3275 | } | |
3276 | sal.section = find_pc_overlay (sal.pc); | |
3277 | b = set_raw_breakpoint (sal); | |
c5aa993b JM |
3278 | if (!b) |
3279 | return; | |
c906108c SS |
3280 | |
3281 | b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume; | |
3282 | b->disposition = donttouch; | |
3283 | b->enable = disabled; | |
3284 | b->silent = 1; | |
3285 | if (func_name) | |
c5aa993b | 3286 | b->addr_string = strsave (func_name); |
c906108c SS |
3287 | b->number = internal_breakpoint_number--; |
3288 | } | |
3289 | ||
c5aa993b | 3290 | #endif /* #ifdef GET_LONGJMP_TARGET */ |
c906108c | 3291 | |
53a5351d JM |
3292 | /* Call this routine when stepping and nexting to enable a breakpoint |
3293 | if we do a longjmp(). When we hit that breakpoint, call | |
c906108c SS |
3294 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
3295 | ||
3296 | void | |
c5aa993b | 3297 | enable_longjmp_breakpoint () |
c906108c SS |
3298 | { |
3299 | register struct breakpoint *b; | |
3300 | ||
3301 | ALL_BREAKPOINTS (b) | |
3302 | if (b->type == bp_longjmp) | |
c5aa993b JM |
3303 | { |
3304 | b->enable = enabled; | |
3305 | check_duplicates (b->address, b->section); | |
3306 | } | |
c906108c SS |
3307 | } |
3308 | ||
3309 | void | |
c5aa993b | 3310 | disable_longjmp_breakpoint () |
c906108c SS |
3311 | { |
3312 | register struct breakpoint *b; | |
3313 | ||
3314 | ALL_BREAKPOINTS (b) | |
c5aa993b | 3315 | if (b->type == bp_longjmp |
c906108c | 3316 | || b->type == bp_longjmp_resume) |
c5aa993b JM |
3317 | { |
3318 | b->enable = disabled; | |
3319 | check_duplicates (b->address, b->section); | |
3320 | } | |
c906108c SS |
3321 | } |
3322 | ||
3323 | #ifdef SOLIB_ADD | |
3324 | void | |
3325 | remove_solib_event_breakpoints () | |
3326 | { | |
3327 | register struct breakpoint *b, *temp; | |
3328 | ||
3329 | ALL_BREAKPOINTS_SAFE (b, temp) | |
3330 | if (b->type == bp_shlib_event) | |
c5aa993b | 3331 | delete_breakpoint (b); |
c906108c SS |
3332 | } |
3333 | ||
3334 | void | |
3335 | create_solib_event_breakpoint (address) | |
3336 | CORE_ADDR address; | |
3337 | { | |
3338 | struct breakpoint *b; | |
3339 | struct symtab_and_line sal; | |
3340 | ||
c5aa993b | 3341 | INIT_SAL (&sal); /* initialize to zeroes */ |
c906108c SS |
3342 | sal.pc = address; |
3343 | sal.section = find_pc_overlay (sal.pc); | |
3344 | b = set_raw_breakpoint (sal); | |
3345 | b->number = internal_breakpoint_number--; | |
3346 | b->disposition = donttouch; | |
3347 | b->type = bp_shlib_event; | |
3348 | } | |
3349 | ||
3350 | void | |
3351 | disable_breakpoints_in_shlibs (silent) | |
3352 | int silent; | |
3353 | { | |
c5aa993b JM |
3354 | struct breakpoint *b; |
3355 | int disabled_shlib_breaks = 0; | |
c906108c SS |
3356 | |
3357 | /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */ | |
3358 | ALL_BREAKPOINTS (b) | |
c5aa993b | 3359 | { |
c906108c | 3360 | #if defined (PC_SOLIB) |
c5aa993b JM |
3361 | if (((b->type == bp_breakpoint) || |
3362 | (b->type == bp_hardware_breakpoint)) && | |
3363 | (b->enable != shlib_disabled) && | |
3364 | (b->enable != call_disabled) && | |
3365 | !b->duplicate && | |
3366 | PC_SOLIB (b->address)) | |
3367 | { | |
3368 | b->enable = shlib_disabled; | |
3369 | if (!silent) | |
3370 | { | |
3371 | if (!disabled_shlib_breaks) | |
3372 | { | |
3373 | target_terminal_ours_for_output (); | |
53a5351d | 3374 | warning ("Temporarily disabling shared library breakpoints:"); |
c5aa993b JM |
3375 | } |
3376 | disabled_shlib_breaks = 1; | |
53a5351d | 3377 | warning ("breakpoint #%d ", b->number); |
c5aa993b JM |
3378 | } |
3379 | } | |
c906108c | 3380 | #endif |
c5aa993b | 3381 | } |
c906108c SS |
3382 | } |
3383 | ||
3384 | /* Try to reenable any breakpoints in shared libraries. */ | |
3385 | void | |
3386 | re_enable_breakpoints_in_shlibs () | |
3387 | { | |
3388 | struct breakpoint *b; | |
3389 | ||
3390 | ALL_BREAKPOINTS (b) | |
3391 | if (b->enable == shlib_disabled) | |
c5aa993b JM |
3392 | { |
3393 | char buf[1]; | |
c906108c | 3394 | |
c5aa993b JM |
3395 | /* Do not reenable the breakpoint if the shared library |
3396 | is still not mapped in. */ | |
3397 | if (target_read_memory (b->address, buf, 1) == 0) | |
3398 | b->enable = enabled; | |
3399 | } | |
c906108c SS |
3400 | } |
3401 | ||
3402 | #endif | |
3403 | ||
3404 | static void | |
53a5351d | 3405 | solib_load_unload_1 (hookname, tempflag, dll_pathname, cond_string, bp_kind) |
7a292a7a SS |
3406 | char *hookname; |
3407 | int tempflag; | |
3408 | char *dll_pathname; | |
3409 | char *cond_string; | |
3410 | enum bptype bp_kind; | |
c906108c | 3411 | { |
c5aa993b | 3412 | struct breakpoint *b; |
c906108c | 3413 | struct symtabs_and_lines sals; |
c5aa993b JM |
3414 | struct symtab_and_line sal; |
3415 | struct cleanup *old_chain; | |
3416 | struct cleanup *canonical_strings_chain = NULL; | |
3417 | int i; | |
3418 | char *addr_start = hookname; | |
3419 | char *addr_end = NULL; | |
3420 | char **canonical = (char **) NULL; | |
3421 | int thread = -1; /* All threads. */ | |
3422 | ||
c906108c SS |
3423 | /* Set a breakpoint on the specified hook. */ |
3424 | sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical); | |
3425 | addr_end = hookname; | |
c5aa993b | 3426 | |
c906108c SS |
3427 | if (sals.nelts == 0) |
3428 | { | |
3429 | warning ("Unable to set a breakpoint on dynamic linker callback."); | |
3430 | warning ("Suggest linking with /opt/langtools/lib/end.o."); | |
3431 | warning ("GDB will be unable to track shl_load/shl_unload calls"); | |
3432 | return; | |
3433 | } | |
3434 | if (sals.nelts != 1) | |
3435 | { | |
53a5351d | 3436 | warning ("Unable to set unique breakpoint on dynamic linker callback."); |
c906108c SS |
3437 | warning ("GDB will be unable to track shl_load/shl_unload calls"); |
3438 | return; | |
3439 | } | |
3440 | ||
53a5351d JM |
3441 | /* Make sure that all storage allocated in decode_line_1 gets freed |
3442 | in case the following errors out. */ | |
c906108c | 3443 | old_chain = make_cleanup (free, sals.sals); |
c5aa993b | 3444 | if (canonical != (char **) NULL) |
c906108c SS |
3445 | { |
3446 | make_cleanup (free, canonical); | |
3447 | canonical_strings_chain = make_cleanup (null_cleanup, 0); | |
3448 | if (canonical[0] != NULL) | |
c5aa993b | 3449 | make_cleanup (free, canonical[0]); |
c906108c | 3450 | } |
c5aa993b | 3451 | |
c906108c | 3452 | resolve_sal_pc (&sals.sals[0]); |
c5aa993b | 3453 | |
c906108c | 3454 | /* Remove the canonical strings from the cleanup, they are needed below. */ |
c5aa993b | 3455 | if (canonical != (char **) NULL) |
c906108c | 3456 | discard_cleanups (canonical_strings_chain); |
c5aa993b | 3457 | |
c906108c SS |
3458 | b = set_raw_breakpoint (sals.sals[0]); |
3459 | set_breakpoint_count (breakpoint_count + 1); | |
3460 | b->number = breakpoint_count; | |
3461 | b->cond = NULL; | |
53a5351d JM |
3462 | b->cond_string = (cond_string == NULL) ? |
3463 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c | 3464 | b->thread = thread; |
c5aa993b JM |
3465 | |
3466 | if (canonical != (char **) NULL && canonical[0] != NULL) | |
c906108c SS |
3467 | b->addr_string = canonical[0]; |
3468 | else if (addr_start) | |
3469 | b->addr_string = savestring (addr_start, addr_end - addr_start); | |
c5aa993b | 3470 | |
c906108c SS |
3471 | b->enable = enabled; |
3472 | b->disposition = tempflag ? del : donttouch; | |
c5aa993b | 3473 | |
c906108c SS |
3474 | if (dll_pathname == NULL) |
3475 | b->dll_pathname = NULL; | |
3476 | else | |
3477 | { | |
3478 | b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1); | |
3479 | strcpy (b->dll_pathname, dll_pathname); | |
3480 | } | |
3481 | b->type = bp_kind; | |
c5aa993b | 3482 | |
c906108c SS |
3483 | mention (b); |
3484 | do_cleanups (old_chain); | |
3485 | } | |
3486 | ||
3487 | void | |
53a5351d JM |
3488 | create_solib_load_event_breakpoint (hookname, tempflag, |
3489 | dll_pathname, cond_string) | |
c5aa993b JM |
3490 | char *hookname; |
3491 | int tempflag; | |
3492 | char *dll_pathname; | |
3493 | char *cond_string; | |
c906108c | 3494 | { |
53a5351d JM |
3495 | solib_load_unload_1 (hookname, tempflag, dll_pathname, |
3496 | cond_string, bp_catch_load); | |
c906108c SS |
3497 | } |
3498 | ||
3499 | void | |
53a5351d JM |
3500 | create_solib_unload_event_breakpoint (hookname, tempflag, |
3501 | dll_pathname, cond_string) | |
c5aa993b JM |
3502 | char *hookname; |
3503 | int tempflag; | |
3504 | char *dll_pathname; | |
3505 | char *cond_string; | |
c906108c | 3506 | { |
53a5351d JM |
3507 | solib_load_unload_1 (hookname,tempflag, dll_pathname, |
3508 | cond_string, bp_catch_unload); | |
c906108c SS |
3509 | } |
3510 | ||
3511 | static void | |
3512 | create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_kind) | |
7a292a7a SS |
3513 | int tempflag; |
3514 | char *cond_string; | |
3515 | enum bptype bp_kind; | |
c906108c | 3516 | { |
c5aa993b JM |
3517 | struct symtab_and_line sal; |
3518 | struct breakpoint *b; | |
3519 | int thread = -1; /* All threads. */ | |
3520 | ||
3521 | INIT_SAL (&sal); | |
c906108c SS |
3522 | sal.pc = 0; |
3523 | sal.symtab = NULL; | |
3524 | sal.line = 0; | |
c5aa993b | 3525 | |
c906108c SS |
3526 | b = set_raw_breakpoint (sal); |
3527 | set_breakpoint_count (breakpoint_count + 1); | |
3528 | b->number = breakpoint_count; | |
3529 | b->cond = NULL; | |
53a5351d JM |
3530 | b->cond_string = (cond_string == NULL) ? |
3531 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c SS |
3532 | b->thread = thread; |
3533 | b->addr_string = NULL; | |
3534 | b->enable = enabled; | |
3535 | b->disposition = tempflag ? del : donttouch; | |
3536 | b->forked_inferior_pid = 0; | |
c5aa993b | 3537 | |
c906108c | 3538 | b->type = bp_kind; |
c5aa993b | 3539 | |
c906108c SS |
3540 | mention (b); |
3541 | } | |
3542 | ||
3543 | void | |
3544 | create_fork_event_catchpoint (tempflag, cond_string) | |
c5aa993b JM |
3545 | int tempflag; |
3546 | char *cond_string; | |
c906108c SS |
3547 | { |
3548 | create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork); | |
3549 | } | |
c5aa993b | 3550 | |
c906108c SS |
3551 | void |
3552 | create_vfork_event_catchpoint (tempflag, cond_string) | |
c5aa993b JM |
3553 | int tempflag; |
3554 | char *cond_string; | |
c906108c SS |
3555 | { |
3556 | create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork); | |
3557 | } | |
3558 | ||
3559 | void | |
3560 | create_exec_event_catchpoint (tempflag, cond_string) | |
c5aa993b JM |
3561 | int tempflag; |
3562 | char *cond_string; | |
c906108c | 3563 | { |
c5aa993b JM |
3564 | struct symtab_and_line sal; |
3565 | struct breakpoint *b; | |
3566 | int thread = -1; /* All threads. */ | |
c906108c | 3567 | |
c5aa993b | 3568 | INIT_SAL (&sal); |
c906108c SS |
3569 | sal.pc = 0; |
3570 | sal.symtab = NULL; | |
3571 | sal.line = 0; | |
3572 | ||
3573 | b = set_raw_breakpoint (sal); | |
3574 | set_breakpoint_count (breakpoint_count + 1); | |
3575 | b->number = breakpoint_count; | |
3576 | b->cond = NULL; | |
53a5351d JM |
3577 | b->cond_string = (cond_string == NULL) ? |
3578 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c SS |
3579 | b->thread = thread; |
3580 | b->addr_string = NULL; | |
3581 | b->enable = enabled; | |
3582 | b->disposition = tempflag ? del : donttouch; | |
3583 | ||
3584 | b->type = bp_catch_exec; | |
3585 | ||
3586 | mention (b); | |
3587 | } | |
3588 | ||
3589 | static int | |
c5aa993b | 3590 | hw_breakpoint_used_count () |
c906108c SS |
3591 | { |
3592 | register struct breakpoint *b; | |
3593 | int i = 0; | |
3594 | ||
3595 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
3596 | { |
3597 | if (b->type == bp_hardware_breakpoint && b->enable == enabled) | |
3598 | i++; | |
3599 | } | |
c906108c SS |
3600 | |
3601 | return i; | |
3602 | } | |
3603 | ||
3604 | static int | |
c5aa993b JM |
3605 | hw_watchpoint_used_count (type, other_type_used) |
3606 | enum bptype type; | |
3607 | int *other_type_used; | |
c906108c SS |
3608 | { |
3609 | register struct breakpoint *b; | |
3610 | int i = 0; | |
3611 | ||
3612 | *other_type_used = 0; | |
3613 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
3614 | { |
3615 | if (b->enable == enabled) | |
3616 | { | |
3617 | if (b->type == type) | |
3618 | i++; | |
3619 | else if ((b->type == bp_hardware_watchpoint || | |
3620 | b->type == bp_read_watchpoint || | |
3621 | b->type == bp_access_watchpoint) | |
3622 | && b->enable == enabled) | |
3623 | *other_type_used = 1; | |
3624 | } | |
3625 | } | |
c906108c SS |
3626 | return i; |
3627 | } | |
3628 | ||
53a5351d JM |
3629 | /* Call this after hitting the longjmp() breakpoint. Use this to set |
3630 | a new breakpoint at the target of the jmp_buf. | |
c906108c | 3631 | |
53a5351d JM |
3632 | FIXME - This ought to be done by setting a temporary breakpoint |
3633 | that gets deleted automatically... */ | |
c906108c SS |
3634 | |
3635 | void | |
c5aa993b | 3636 | set_longjmp_resume_breakpoint (pc, frame) |
c906108c SS |
3637 | CORE_ADDR pc; |
3638 | struct frame_info *frame; | |
3639 | { | |
3640 | register struct breakpoint *b; | |
3641 | ||
3642 | ALL_BREAKPOINTS (b) | |
3643 | if (b->type == bp_longjmp_resume) | |
c5aa993b JM |
3644 | { |
3645 | b->address = pc; | |
3646 | b->enable = enabled; | |
3647 | if (frame != NULL) | |
3648 | b->frame = frame->frame; | |
3649 | else | |
3650 | b->frame = 0; | |
3651 | check_duplicates (b->address, b->section); | |
3652 | return; | |
3653 | } | |
c906108c SS |
3654 | } |
3655 | ||
3656 | void | |
3657 | disable_watchpoints_before_interactive_call_start () | |
3658 | { | |
c5aa993b | 3659 | struct breakpoint *b; |
c906108c SS |
3660 | |
3661 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
3662 | { |
3663 | if (((b->type == bp_watchpoint) | |
3664 | || (b->type == bp_hardware_watchpoint) | |
3665 | || (b->type == bp_read_watchpoint) | |
3666 | || (b->type == bp_access_watchpoint) | |
3667 | || ep_is_exception_catchpoint (b)) | |
3668 | && (b->enable == enabled)) | |
3669 | { | |
3670 | b->enable = call_disabled; | |
3671 | check_duplicates (b->address, b->section); | |
3672 | } | |
3673 | } | |
c906108c SS |
3674 | } |
3675 | ||
3676 | void | |
3677 | enable_watchpoints_after_interactive_call_stop () | |
3678 | { | |
c5aa993b | 3679 | struct breakpoint *b; |
c906108c SS |
3680 | |
3681 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
3682 | { |
3683 | if (((b->type == bp_watchpoint) | |
3684 | || (b->type == bp_hardware_watchpoint) | |
3685 | || (b->type == bp_read_watchpoint) | |
3686 | || (b->type == bp_access_watchpoint) | |
3687 | || ep_is_exception_catchpoint (b)) | |
3688 | && (b->enable == call_disabled)) | |
3689 | { | |
3690 | b->enable = enabled; | |
3691 | check_duplicates (b->address, b->section); | |
3692 | } | |
3693 | } | |
c906108c SS |
3694 | } |
3695 | ||
3696 | ||
3697 | /* Set a breakpoint that will evaporate an end of command | |
3698 | at address specified by SAL. | |
3699 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
3700 | ||
3701 | struct breakpoint * | |
3702 | set_momentary_breakpoint (sal, frame, type) | |
3703 | struct symtab_and_line sal; | |
3704 | struct frame_info *frame; | |
3705 | enum bptype type; | |
3706 | { | |
3707 | register struct breakpoint *b; | |
3708 | b = set_raw_breakpoint (sal); | |
3709 | b->type = type; | |
3710 | b->enable = enabled; | |
3711 | b->disposition = donttouch; | |
3712 | b->frame = (frame ? frame->frame : 0); | |
3713 | ||
3714 | /* If we're debugging a multi-threaded program, then we | |
3715 | want momentary breakpoints to be active in only a | |
3716 | single thread of control. */ | |
3717 | if (in_thread_list (inferior_pid)) | |
3718 | b->thread = pid_to_thread_id (inferior_pid); | |
3719 | ||
3720 | return b; | |
3721 | } | |
c906108c | 3722 | \f |
c5aa993b | 3723 | |
c906108c SS |
3724 | /* Tell the user we have just set a breakpoint B. */ |
3725 | ||
3726 | static void | |
3727 | mention (b) | |
3728 | struct breakpoint *b; | |
3729 | { | |
3730 | int say_where = 0; | |
3731 | ||
3732 | /* FIXME: This is misplaced; mention() is called by things (like hitting a | |
3733 | watchpoint) other than breakpoint creation. It should be possible to | |
3734 | clean this up and at the same time replace the random calls to | |
3735 | breakpoint_changed with this hook, as has already been done for | |
3736 | delete_breakpoint_hook and so on. */ | |
3737 | if (create_breakpoint_hook) | |
3738 | create_breakpoint_hook (b); | |
3739 | ||
3740 | switch (b->type) | |
3741 | { | |
3742 | case bp_none: | |
3743 | printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number); | |
3744 | break; | |
3745 | case bp_watchpoint: | |
3746 | printf_filtered ("Watchpoint %d: ", b->number); | |
3747 | print_expression (b->exp, gdb_stdout); | |
3748 | break; | |
3749 | case bp_hardware_watchpoint: | |
3750 | printf_filtered ("Hardware watchpoint %d: ", b->number); | |
3751 | print_expression (b->exp, gdb_stdout); | |
3752 | break; | |
3753 | case bp_read_watchpoint: | |
3754 | printf_filtered ("Hardware read watchpoint %d: ", b->number); | |
3755 | print_expression (b->exp, gdb_stdout); | |
3756 | break; | |
3757 | case bp_access_watchpoint: | |
53a5351d JM |
3758 | printf_filtered ("Hardware access (read/write) watchpoint %d: ", |
3759 | b->number); | |
c906108c SS |
3760 | print_expression (b->exp, gdb_stdout); |
3761 | break; | |
3762 | case bp_breakpoint: | |
3763 | printf_filtered ("Breakpoint %d", b->number); | |
3764 | say_where = 1; | |
3765 | break; | |
3766 | case bp_hardware_breakpoint: | |
3767 | printf_filtered ("Hardware assisted breakpoint %d", b->number); | |
3768 | say_where = 1; | |
3769 | break; | |
3770 | case bp_catch_load: | |
3771 | case bp_catch_unload: | |
3772 | printf_filtered ("Catchpoint %d (%s %s)", | |
c5aa993b JM |
3773 | b->number, |
3774 | (b->type == bp_catch_load) ? "load" : "unload", | |
53a5351d JM |
3775 | (b->dll_pathname != NULL) ? |
3776 | b->dll_pathname : "<any library>"); | |
c906108c SS |
3777 | break; |
3778 | case bp_catch_fork: | |
3779 | case bp_catch_vfork: | |
3780 | printf_filtered ("Catchpoint %d (%s)", | |
c5aa993b JM |
3781 | b->number, |
3782 | (b->type == bp_catch_fork) ? "fork" : "vfork"); | |
c906108c SS |
3783 | break; |
3784 | case bp_catch_exec: | |
3785 | printf_filtered ("Catchpoint %d (exec)", | |
c5aa993b | 3786 | b->number); |
c906108c SS |
3787 | break; |
3788 | case bp_catch_catch: | |
3789 | case bp_catch_throw: | |
3790 | printf_filtered ("Catchpoint %d (%s)", | |
c5aa993b JM |
3791 | b->number, |
3792 | (b->type == bp_catch_catch) ? "catch" : "throw"); | |
c906108c SS |
3793 | break; |
3794 | ||
3795 | case bp_until: | |
3796 | case bp_finish: | |
3797 | case bp_longjmp: | |
3798 | case bp_longjmp_resume: | |
3799 | case bp_step_resume: | |
3800 | case bp_through_sigtramp: | |
3801 | case bp_call_dummy: | |
3802 | case bp_watchpoint_scope: | |
3803 | case bp_shlib_event: | |
3804 | break; | |
3805 | } | |
3806 | if (say_where) | |
3807 | { | |
3808 | if (addressprint || b->source_file == NULL) | |
3809 | { | |
3810 | printf_filtered (" at "); | |
3811 | print_address_numeric (b->address, 1, gdb_stdout); | |
3812 | } | |
3813 | if (b->source_file) | |
3814 | printf_filtered (": file %s, line %d.", | |
3815 | b->source_file, b->line_number); | |
c5aa993b JM |
3816 | TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, b, 1)); |
3817 | TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos)); | |
c906108c SS |
3818 | } |
3819 | printf_filtered ("\n"); | |
3820 | } | |
c906108c | 3821 | \f |
c5aa993b | 3822 | |
c906108c SS |
3823 | /* Set a breakpoint according to ARG (function, linenum or *address) |
3824 | flag: first bit : 0 non-temporary, 1 temporary. | |
c5aa993b | 3825 | second bit : 0 normal breakpoint, 1 hardware breakpoint. */ |
c906108c SS |
3826 | |
3827 | static void | |
3828 | break_command_1 (arg, flag, from_tty) | |
3829 | char *arg; | |
3830 | int flag, from_tty; | |
3831 | { | |
3832 | int tempflag, hardwareflag; | |
3833 | struct symtabs_and_lines sals; | |
3834 | struct symtab_and_line sal; | |
3835 | register struct expression *cond = 0; | |
3836 | register struct breakpoint *b; | |
3837 | ||
3838 | /* Pointers in arg to the start, and one past the end, of the condition. */ | |
3839 | char *cond_start = NULL; | |
3840 | char *cond_end = NULL; | |
3841 | /* Pointers in arg to the start, and one past the end, | |
3842 | of the address part. */ | |
3843 | char *addr_start = NULL; | |
3844 | char *addr_end = NULL; | |
3845 | struct cleanup *old_chain; | |
3846 | struct cleanup *canonical_strings_chain = NULL; | |
c5aa993b | 3847 | char **canonical = (char **) NULL; |
c906108c SS |
3848 | int i; |
3849 | int thread; | |
3850 | ||
3851 | hardwareflag = flag & BP_HARDWAREFLAG; | |
3852 | tempflag = flag & BP_TEMPFLAG; | |
3853 | ||
3854 | sals.sals = NULL; | |
3855 | sals.nelts = 0; | |
3856 | ||
c5aa993b | 3857 | INIT_SAL (&sal); /* initialize to zeroes */ |
c906108c SS |
3858 | |
3859 | /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ | |
3860 | ||
c5aa993b | 3861 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' |
c906108c SS |
3862 | && (arg[2] == ' ' || arg[2] == '\t'))) |
3863 | { | |
3864 | if (default_breakpoint_valid) | |
3865 | { | |
c5aa993b | 3866 | sals.sals = (struct symtab_and_line *) |
c906108c SS |
3867 | xmalloc (sizeof (struct symtab_and_line)); |
3868 | sal.pc = default_breakpoint_address; | |
3869 | sal.line = default_breakpoint_line; | |
3870 | sal.symtab = default_breakpoint_symtab; | |
c5aa993b | 3871 | sal.section = find_pc_overlay (sal.pc); |
c906108c SS |
3872 | sals.sals[0] = sal; |
3873 | sals.nelts = 1; | |
3874 | } | |
3875 | else | |
3876 | error ("No default breakpoint address now."); | |
3877 | } | |
3878 | else | |
3879 | { | |
3880 | addr_start = arg; | |
3881 | ||
3882 | /* Force almost all breakpoints to be in terms of the | |
c5aa993b JM |
3883 | current_source_symtab (which is decode_line_1's default). This |
3884 | should produce the results we want almost all of the time while | |
3885 | leaving default_breakpoint_* alone. */ | |
c906108c SS |
3886 | if (default_breakpoint_valid |
3887 | && (!current_source_symtab | |
3888 | || (arg && (*arg == '+' || *arg == '-')))) | |
3889 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
3890 | default_breakpoint_line, &canonical); | |
3891 | else | |
c5aa993b | 3892 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, &canonical); |
c906108c SS |
3893 | |
3894 | addr_end = arg; | |
3895 | } | |
c5aa993b JM |
3896 | |
3897 | if (!sals.nelts) | |
c906108c SS |
3898 | return; |
3899 | ||
53a5351d JM |
3900 | /* Make sure that all storage allocated in decode_line_1 gets freed |
3901 | in case the following `for' loop errors out. */ | |
c906108c | 3902 | old_chain = make_cleanup (free, sals.sals); |
c5aa993b | 3903 | if (canonical != (char **) NULL) |
c906108c SS |
3904 | { |
3905 | make_cleanup (free, canonical); | |
3906 | canonical_strings_chain = make_cleanup (null_cleanup, 0); | |
3907 | for (i = 0; i < sals.nelts; i++) | |
3908 | { | |
3909 | if (canonical[i] != NULL) | |
3910 | make_cleanup (free, canonical[i]); | |
3911 | } | |
3912 | } | |
3913 | ||
3914 | thread = -1; /* No specific thread yet */ | |
3915 | ||
3916 | /* Resolve all line numbers to PC's, and verify that conditions | |
3917 | can be parsed, before setting any breakpoints. */ | |
3918 | for (i = 0; i < sals.nelts; i++) | |
3919 | { | |
3920 | char *tok, *end_tok; | |
3921 | int toklen; | |
3922 | ||
3923 | resolve_sal_pc (&sals.sals[i]); | |
3924 | ||
3925 | /* It's possible for the PC to be nonzero, but still an illegal | |
3926 | value on some targets. | |
3927 | ||
3928 | For example, on HP-UX if you start gdb, and before running the | |
3929 | inferior you try to set a breakpoint on a shared library function | |
3930 | "foo" where the inferior doesn't call "foo" directly but does | |
3931 | pass its address to another function call, then we do find a | |
3932 | minimal symbol for the "foo", but it's address is invalid. | |
3933 | (Appears to be an index into a table that the loader sets up | |
3934 | when the inferior is run.) | |
3935 | ||
3936 | Give the target a chance to bless sals.sals[i].pc before we | |
3937 | try to make a breakpoint for it. */ | |
c5aa993b JM |
3938 | if (PC_REQUIRES_RUN_BEFORE_USE (sals.sals[i].pc)) |
3939 | { | |
53a5351d JM |
3940 | error ("Cannot break on %s without a running program.", |
3941 | addr_start); | |
c5aa993b JM |
3942 | } |
3943 | ||
c906108c SS |
3944 | tok = arg; |
3945 | ||
3946 | while (tok && *tok) | |
3947 | { | |
3948 | while (*tok == ' ' || *tok == '\t') | |
3949 | tok++; | |
3950 | ||
3951 | end_tok = tok; | |
3952 | ||
3953 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
3954 | end_tok++; | |
3955 | ||
3956 | toklen = end_tok - tok; | |
3957 | ||
3958 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
3959 | { | |
3960 | tok = cond_start = end_tok + 1; | |
3961 | cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); | |
3962 | cond_end = tok; | |
3963 | } | |
3964 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
3965 | { | |
3966 | char *tmptok; | |
3967 | ||
3968 | tok = end_tok + 1; | |
3969 | tmptok = tok; | |
3970 | thread = strtol (tok, &tok, 0); | |
3971 | if (tok == tmptok) | |
3972 | error ("Junk after thread keyword."); | |
3973 | if (!valid_thread_id (thread)) | |
3974 | error ("Unknown thread %d\n", thread); | |
3975 | } | |
3976 | else | |
3977 | error ("Junk at end of arguments."); | |
3978 | } | |
3979 | } | |
3980 | if (hardwareflag) | |
3981 | { | |
3982 | int i, target_resources_ok; | |
3983 | ||
c5aa993b | 3984 | i = hw_breakpoint_used_count (); |
53a5351d JM |
3985 | target_resources_ok = |
3986 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
3987 | i + sals.nelts, 0); | |
c906108c SS |
3988 | if (target_resources_ok == 0) |
3989 | error ("No hardware breakpoint support in the target."); | |
3990 | else if (target_resources_ok < 0) | |
c5aa993b | 3991 | error ("Hardware breakpoints used exceeds limit."); |
c906108c SS |
3992 | } |
3993 | ||
3994 | /* Remove the canonical strings from the cleanup, they are needed below. */ | |
c5aa993b | 3995 | if (canonical != (char **) NULL) |
c906108c SS |
3996 | discard_cleanups (canonical_strings_chain); |
3997 | ||
3998 | /* Now set all the breakpoints. */ | |
3999 | for (i = 0; i < sals.nelts; i++) | |
4000 | { | |
4001 | sal = sals.sals[i]; | |
4002 | ||
4003 | if (from_tty) | |
4004 | describe_other_breakpoints (sal.pc, sal.section); | |
4005 | ||
4006 | b = set_raw_breakpoint (sal); | |
4007 | set_breakpoint_count (breakpoint_count + 1); | |
4008 | b->number = breakpoint_count; | |
4009 | b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint; | |
4010 | b->cond = cond; | |
4011 | b->thread = thread; | |
4012 | ||
4013 | /* If a canonical line spec is needed use that instead of the | |
c5aa993b JM |
4014 | command string. */ |
4015 | if (canonical != (char **) NULL && canonical[i] != NULL) | |
c906108c SS |
4016 | b->addr_string = canonical[i]; |
4017 | else if (addr_start) | |
4018 | b->addr_string = savestring (addr_start, addr_end - addr_start); | |
4019 | if (cond_start) | |
4020 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
c5aa993b | 4021 | |
c906108c SS |
4022 | b->enable = enabled; |
4023 | b->disposition = tempflag ? del : donttouch; | |
4024 | mention (b); | |
4025 | } | |
4026 | ||
4027 | if (sals.nelts > 1) | |
4028 | { | |
53a5351d JM |
4029 | warning ("Multiple breakpoints were set."); |
4030 | warning ("Use the \"delete\" command to delete unwanted breakpoints."); | |
c906108c SS |
4031 | } |
4032 | do_cleanups (old_chain); | |
4033 | } | |
4034 | ||
4035 | static void | |
4036 | break_at_finish_at_depth_command_1 (arg, flag, from_tty) | |
4037 | char *arg; | |
4038 | int flag; | |
4039 | int from_tty; | |
4040 | { | |
4041 | struct frame_info *frame; | |
4042 | CORE_ADDR low, high, selected_pc = 0; | |
4043 | char *extra_args, *level_arg, *addr_string; | |
4044 | int extra_args_len = 0, if_arg = 0; | |
4045 | ||
4046 | if (!arg || | |
4047 | (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) | |
4048 | { | |
4049 | ||
4050 | if (default_breakpoint_valid) | |
4051 | { | |
4052 | if (selected_frame) | |
4053 | { | |
4054 | selected_pc = selected_frame->pc; | |
4055 | if (arg) | |
4056 | if_arg = 1; | |
4057 | } | |
4058 | else | |
4059 | error ("No selected frame."); | |
4060 | } | |
4061 | else | |
4062 | error ("No default breakpoint address now."); | |
4063 | } | |
4064 | else | |
4065 | { | |
4066 | extra_args = strchr (arg, ' '); | |
4067 | if (extra_args) | |
4068 | { | |
4069 | extra_args++; | |
4070 | extra_args_len = strlen (extra_args); | |
4071 | level_arg = (char *) xmalloc (extra_args - arg); | |
4072 | strncpy (level_arg, arg, extra_args - arg - 1); | |
4073 | level_arg[extra_args - arg - 1] = '\0'; | |
4074 | } | |
4075 | else | |
4076 | { | |
4077 | level_arg = (char *) xmalloc (strlen (arg) + 1); | |
4078 | strcpy (level_arg, arg); | |
4079 | } | |
4080 | ||
4081 | frame = parse_frame_specification (level_arg); | |
4082 | if (frame) | |
4083 | selected_pc = frame->pc; | |
4084 | else | |
4085 | selected_pc = 0; | |
4086 | } | |
4087 | if (if_arg) | |
4088 | { | |
4089 | extra_args = arg; | |
c5aa993b | 4090 | extra_args_len = strlen (arg); |
c906108c SS |
4091 | } |
4092 | ||
4093 | if (selected_pc) | |
4094 | { | |
c5aa993b | 4095 | if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high)) |
c906108c SS |
4096 | { |
4097 | addr_string = (char *) xmalloc (26 + extra_args_len); | |
4098 | if (extra_args_len) | |
4099 | sprintf (addr_string, "*0x%x %s", high, extra_args); | |
4100 | else | |
4101 | sprintf (addr_string, "*0x%x", high); | |
4102 | break_command_1 (addr_string, flag, from_tty); | |
4103 | free (addr_string); | |
4104 | } | |
4105 | else | |
4106 | error ("No function contains the specified address"); | |
4107 | } | |
4108 | else | |
4109 | error ("Unable to set breakpoint at procedure exit"); | |
4110 | } | |
4111 | ||
4112 | ||
4113 | static void | |
4114 | break_at_finish_command_1 (arg, flag, from_tty) | |
4115 | char *arg; | |
4116 | int flag; | |
4117 | int from_tty; | |
4118 | { | |
4119 | char *addr_string, *break_string, *beg_addr_string; | |
4120 | CORE_ADDR low, high; | |
4121 | struct symtabs_and_lines sals; | |
4122 | struct symtab_and_line sal; | |
4123 | struct cleanup *old_chain; | |
4124 | char *extra_args; | |
4125 | int extra_args_len = 0; | |
4126 | int i, if_arg = 0; | |
4127 | ||
4128 | if (!arg || | |
4129 | (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) | |
4130 | { | |
4131 | if (default_breakpoint_valid) | |
4132 | { | |
4133 | if (selected_frame) | |
4134 | { | |
4135 | addr_string = (char *) xmalloc (15); | |
4136 | sprintf (addr_string, "*0x%x", selected_frame->pc); | |
4137 | if (arg) | |
4138 | if_arg = 1; | |
4139 | } | |
4140 | else | |
4141 | error ("No selected frame."); | |
4142 | } | |
4143 | else | |
4144 | error ("No default breakpoint address now."); | |
4145 | } | |
4146 | else | |
4147 | { | |
4148 | addr_string = (char *) xmalloc (strlen (arg) + 1); | |
4149 | strcpy (addr_string, arg); | |
4150 | } | |
4151 | ||
4152 | if (if_arg) | |
4153 | { | |
4154 | extra_args = arg; | |
c5aa993b JM |
4155 | extra_args_len = strlen (arg); |
4156 | } | |
4157 | else if (arg) | |
4158 | { | |
4159 | /* get the stuff after the function name or address */ | |
4160 | extra_args = strchr (arg, ' '); | |
4161 | if (extra_args) | |
4162 | { | |
4163 | extra_args++; | |
4164 | extra_args_len = strlen (extra_args); | |
4165 | } | |
c906108c | 4166 | } |
c906108c SS |
4167 | |
4168 | sals.sals = NULL; | |
4169 | sals.nelts = 0; | |
4170 | ||
c5aa993b JM |
4171 | beg_addr_string = addr_string; |
4172 | sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0, | |
4173 | (char ***) NULL); | |
c906108c SS |
4174 | |
4175 | free (beg_addr_string); | |
4176 | old_chain = make_cleanup (free, sals.sals); | |
4177 | for (i = 0; (i < sals.nelts); i++) | |
4178 | { | |
4179 | sal = sals.sals[i]; | |
c5aa993b | 4180 | if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high)) |
c906108c SS |
4181 | { |
4182 | break_string = (char *) xmalloc (extra_args_len + 26); | |
4183 | if (extra_args_len) | |
4184 | sprintf (break_string, "*0x%x %s", high, extra_args); | |
4185 | else | |
4186 | sprintf (break_string, "*0x%x", high); | |
4187 | break_command_1 (break_string, flag, from_tty); | |
c5aa993b | 4188 | free (break_string); |
c906108c SS |
4189 | } |
4190 | else | |
4191 | error ("No function contains the specified address"); | |
4192 | } | |
4193 | if (sals.nelts > 1) | |
4194 | { | |
53a5351d JM |
4195 | warning ("Multiple breakpoints were set.\n"); |
4196 | warning ("Use the \"delete\" command to delete unwanted breakpoints."); | |
c906108c | 4197 | } |
c5aa993b | 4198 | do_cleanups (old_chain); |
c906108c SS |
4199 | } |
4200 | ||
4201 | ||
4202 | /* Helper function for break_command_1 and disassemble_command. */ | |
4203 | ||
4204 | void | |
4205 | resolve_sal_pc (sal) | |
4206 | struct symtab_and_line *sal; | |
4207 | { | |
4208 | CORE_ADDR pc; | |
4209 | ||
4210 | if (sal->pc == 0 && sal->symtab != NULL) | |
4211 | { | |
4212 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
4213 | error ("No line %d in file \"%s\".", | |
4214 | sal->line, sal->symtab->filename); | |
4215 | sal->pc = pc; | |
4216 | } | |
4217 | ||
4218 | if (sal->section == 0 && sal->symtab != NULL) | |
4219 | { | |
4220 | struct blockvector *bv; | |
c5aa993b JM |
4221 | struct block *b; |
4222 | struct symbol *sym; | |
4223 | int index; | |
c906108c | 4224 | |
c5aa993b | 4225 | bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab); |
c906108c SS |
4226 | if (bv != NULL) |
4227 | { | |
c5aa993b | 4228 | b = BLOCKVECTOR_BLOCK (bv, index); |
c906108c SS |
4229 | sym = block_function (b); |
4230 | if (sym != NULL) | |
4231 | { | |
4232 | fixup_symbol_section (sym, sal->symtab->objfile); | |
4233 | sal->section = SYMBOL_BFD_SECTION (sym); | |
4234 | } | |
4235 | else | |
4236 | { | |
4237 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
4238 | have to look harder. This case can be executed if we have |
4239 | line numbers but no functions (as can happen in assembly | |
4240 | source). */ | |
c906108c | 4241 | |
c5aa993b | 4242 | struct minimal_symbol *msym; |
c906108c SS |
4243 | |
4244 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
4245 | if (msym) | |
4246 | sal->section = SYMBOL_BFD_SECTION (msym); | |
4247 | } | |
4248 | } | |
4249 | } | |
4250 | } | |
4251 | ||
4252 | void | |
4253 | break_command (arg, from_tty) | |
4254 | char *arg; | |
4255 | int from_tty; | |
4256 | { | |
4257 | break_command_1 (arg, 0, from_tty); | |
4258 | } | |
4259 | ||
7a292a7a | 4260 | static void |
c906108c SS |
4261 | break_at_finish_command (arg, from_tty) |
4262 | char *arg; | |
4263 | int from_tty; | |
4264 | { | |
4265 | break_at_finish_command_1 (arg, 0, from_tty); | |
4266 | } | |
4267 | ||
7a292a7a | 4268 | static void |
c906108c SS |
4269 | break_at_finish_at_depth_command (arg, from_tty) |
4270 | char *arg; | |
4271 | int from_tty; | |
4272 | { | |
4273 | break_at_finish_at_depth_command_1 (arg, 0, from_tty); | |
4274 | } | |
4275 | ||
4276 | void | |
4277 | tbreak_command (arg, from_tty) | |
4278 | char *arg; | |
4279 | int from_tty; | |
4280 | { | |
4281 | break_command_1 (arg, BP_TEMPFLAG, from_tty); | |
4282 | } | |
4283 | ||
7a292a7a | 4284 | static void |
c906108c SS |
4285 | tbreak_at_finish_command (arg, from_tty) |
4286 | char *arg; | |
4287 | int from_tty; | |
4288 | { | |
4289 | break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty); | |
4290 | } | |
4291 | ||
4292 | static void | |
4293 | hbreak_command (arg, from_tty) | |
4294 | char *arg; | |
4295 | int from_tty; | |
4296 | { | |
4297 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); | |
4298 | } | |
4299 | ||
4300 | static void | |
4301 | thbreak_command (arg, from_tty) | |
4302 | char *arg; | |
4303 | int from_tty; | |
4304 | { | |
4305 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); | |
4306 | } | |
4307 | ||
4308 | static void | |
4309 | stop_command (arg, from_tty) | |
4310 | char *arg; | |
4311 | int from_tty; | |
4312 | { | |
4313 | printf_filtered ("Specify the type of breakpoint to set.\n\ | |
4314 | Usage: stop in <function | address>\n\ | |
4315 | stop at <line>\n"); | |
4316 | } | |
4317 | ||
4318 | static void | |
4319 | stopin_command (arg, from_tty) | |
4320 | char *arg; | |
4321 | int from_tty; | |
4322 | { | |
4323 | int badInput = 0; | |
4324 | ||
c5aa993b | 4325 | if (arg == (char *) NULL) |
c906108c SS |
4326 | badInput = 1; |
4327 | else if (*arg != '*') | |
4328 | { | |
4329 | char *argptr = arg; | |
4330 | int hasColon = 0; | |
4331 | ||
53a5351d JM |
4332 | /* look for a ':'. If this is a line number specification, then |
4333 | say it is bad, otherwise, it should be an address or | |
4334 | function/method name */ | |
c906108c | 4335 | while (*argptr && !hasColon) |
c5aa993b JM |
4336 | { |
4337 | hasColon = (*argptr == ':'); | |
4338 | argptr++; | |
4339 | } | |
c906108c SS |
4340 | |
4341 | if (hasColon) | |
c5aa993b | 4342 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 4343 | else |
c5aa993b | 4344 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
4345 | } |
4346 | ||
4347 | if (badInput) | |
c5aa993b | 4348 | printf_filtered ("Usage: stop in <function | address>\n"); |
c906108c SS |
4349 | else |
4350 | break_command_1 (arg, 0, from_tty); | |
4351 | } | |
4352 | ||
4353 | static void | |
4354 | stopat_command (arg, from_tty) | |
4355 | char *arg; | |
4356 | int from_tty; | |
4357 | { | |
4358 | int badInput = 0; | |
4359 | ||
c5aa993b | 4360 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
4361 | badInput = 1; |
4362 | else | |
4363 | { | |
4364 | char *argptr = arg; | |
4365 | int hasColon = 0; | |
4366 | ||
4367 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 4368 | it is probably a line number. */ |
c906108c | 4369 | while (*argptr && !hasColon) |
c5aa993b JM |
4370 | { |
4371 | hasColon = (*argptr == ':'); | |
4372 | argptr++; | |
4373 | } | |
c906108c SS |
4374 | |
4375 | if (hasColon) | |
c5aa993b | 4376 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 4377 | else |
c5aa993b | 4378 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
4379 | } |
4380 | ||
4381 | if (badInput) | |
c5aa993b | 4382 | printf_filtered ("Usage: stop at <line>\n"); |
c906108c SS |
4383 | else |
4384 | break_command_1 (arg, 0, from_tty); | |
4385 | } | |
4386 | ||
4387 | /* ARGSUSED */ | |
53a5351d JM |
4388 | /* accessflag: hw_write: watch write, |
4389 | hw_read: watch read, | |
4390 | hw_access: watch access (read or write) */ | |
c906108c SS |
4391 | static void |
4392 | watch_command_1 (arg, accessflag, from_tty) | |
4393 | char *arg; | |
4394 | int accessflag; | |
4395 | int from_tty; | |
4396 | { | |
4397 | struct breakpoint *b; | |
4398 | struct symtab_and_line sal; | |
4399 | struct expression *exp; | |
4400 | struct block *exp_valid_block; | |
4401 | struct value *val, *mark; | |
4402 | struct frame_info *frame; | |
4403 | struct frame_info *prev_frame = NULL; | |
4404 | char *exp_start = NULL; | |
4405 | char *exp_end = NULL; | |
4406 | char *tok, *end_tok; | |
4407 | int toklen; | |
4408 | char *cond_start = NULL; | |
4409 | char *cond_end = NULL; | |
4410 | struct expression *cond = NULL; | |
4411 | int i, other_type_used, target_resources_ok = 0; | |
4412 | enum bptype bp_type; | |
4413 | int mem_cnt = 0; | |
4414 | ||
c5aa993b JM |
4415 | INIT_SAL (&sal); /* initialize to zeroes */ |
4416 | ||
c906108c SS |
4417 | /* Parse arguments. */ |
4418 | innermost_block = NULL; | |
4419 | exp_start = arg; | |
4420 | exp = parse_exp_1 (&arg, 0, 0); | |
4421 | exp_end = arg; | |
4422 | exp_valid_block = innermost_block; | |
4423 | mark = value_mark (); | |
4424 | val = evaluate_expression (exp); | |
4425 | release_value (val); | |
4426 | if (VALUE_LAZY (val)) | |
4427 | value_fetch_lazy (val); | |
4428 | ||
4429 | tok = arg; | |
4430 | while (*tok == ' ' || *tok == '\t') | |
4431 | tok++; | |
4432 | end_tok = tok; | |
4433 | ||
4434 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
4435 | end_tok++; | |
4436 | ||
4437 | toklen = end_tok - tok; | |
4438 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
4439 | { | |
4440 | tok = cond_start = end_tok + 1; | |
4441 | cond = parse_exp_1 (&tok, 0, 0); | |
4442 | cond_end = tok; | |
4443 | } | |
4444 | if (*tok) | |
c5aa993b | 4445 | error ("Junk at end of command."); |
c906108c | 4446 | |
53a5351d | 4447 | if (accessflag == hw_read) |
c5aa993b | 4448 | bp_type = bp_read_watchpoint; |
53a5351d | 4449 | else if (accessflag == hw_access) |
c5aa993b JM |
4450 | bp_type = bp_access_watchpoint; |
4451 | else | |
4452 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
4453 | |
4454 | mem_cnt = can_use_hardware_watchpoint (val); | |
4455 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
4456 | error ("Expression cannot be implemented with read/access watchpoint."); | |
c5aa993b JM |
4457 | if (mem_cnt != 0) |
4458 | { | |
4459 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d JM |
4460 | target_resources_ok = |
4461 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt, | |
4462 | other_type_used); | |
c5aa993b | 4463 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
53a5351d JM |
4464 | error ("Target does not support this type of hardware watchpoint."); |
4465 | ||
c5aa993b | 4466 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
53a5351d | 4467 | error ("Target can only support one kind of HW watchpoint at a time."); |
c5aa993b | 4468 | } |
c906108c SS |
4469 | |
4470 | #if defined(HPUXHPPA) | |
c5aa993b | 4471 | /* On HP-UX if you set a h/w |
c906108c SS |
4472 | watchpoint before the "run" command, the inferior dies with a e.g., |
4473 | SIGILL once you start it. I initially believed this was due to a | |
4474 | bad interaction between page protection traps and the initial | |
4475 | startup sequence by the dynamic linker. | |
4476 | ||
4477 | However, I tried avoiding that by having HP-UX's implementation of | |
4478 | TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_pid | |
4479 | yet, which forced slow watches before a "run" or "attach", and it | |
4480 | still fails somewhere in the startup code. | |
4481 | ||
4482 | Until I figure out what's happening, I'm disallowing watches altogether | |
4483 | before the "run" or "attach" command. We'll tell the user they must | |
4484 | set watches after getting the program started. */ | |
c5aa993b | 4485 | if (!target_has_execution) |
c906108c SS |
4486 | { |
4487 | warning ("can't do that without a running program; try \"break main\", \"run\" first"); | |
4488 | return; | |
4489 | } | |
4490 | #endif /* HPUXHPPA */ | |
c5aa993b | 4491 | |
c906108c SS |
4492 | /* Now set up the breakpoint. */ |
4493 | b = set_raw_breakpoint (sal); | |
4494 | set_breakpoint_count (breakpoint_count + 1); | |
4495 | b->number = breakpoint_count; | |
4496 | b->disposition = donttouch; | |
4497 | b->exp = exp; | |
4498 | b->exp_valid_block = exp_valid_block; | |
4499 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
4500 | b->val = val; | |
4501 | b->cond = cond; | |
4502 | if (cond_start) | |
4503 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
4504 | else | |
4505 | b->cond_string = 0; | |
c5aa993b | 4506 | |
c906108c SS |
4507 | frame = block_innermost_frame (exp_valid_block); |
4508 | if (frame) | |
4509 | { | |
4510 | prev_frame = get_prev_frame (frame); | |
4511 | b->watchpoint_frame = frame->frame; | |
4512 | } | |
4513 | else | |
c5aa993b | 4514 | b->watchpoint_frame = (CORE_ADDR) 0; |
c906108c SS |
4515 | |
4516 | if (mem_cnt && target_resources_ok > 0) | |
4517 | b->type = bp_type; | |
4518 | else | |
4519 | b->type = bp_watchpoint; | |
4520 | ||
4521 | /* If the expression is "local", then set up a "watchpoint scope" | |
4522 | breakpoint at the point where we've left the scope of the watchpoint | |
4523 | expression. */ | |
4524 | if (innermost_block) | |
4525 | { | |
4526 | if (prev_frame) | |
4527 | { | |
4528 | struct breakpoint *scope_breakpoint; | |
4529 | struct symtab_and_line scope_sal; | |
4530 | ||
4531 | INIT_SAL (&scope_sal); /* initialize to zeroes */ | |
c5aa993b | 4532 | scope_sal.pc = get_frame_pc (prev_frame); |
c906108c SS |
4533 | scope_sal.section = find_pc_overlay (scope_sal.pc); |
4534 | ||
4535 | scope_breakpoint = set_raw_breakpoint (scope_sal); | |
4536 | set_breakpoint_count (breakpoint_count + 1); | |
4537 | scope_breakpoint->number = breakpoint_count; | |
4538 | ||
4539 | scope_breakpoint->type = bp_watchpoint_scope; | |
4540 | scope_breakpoint->enable = enabled; | |
4541 | ||
4542 | /* Automatically delete the breakpoint when it hits. */ | |
4543 | scope_breakpoint->disposition = del; | |
4544 | ||
4545 | /* Only break in the proper frame (help with recursion). */ | |
4546 | scope_breakpoint->frame = prev_frame->frame; | |
4547 | ||
4548 | /* Set the address at which we will stop. */ | |
4549 | scope_breakpoint->address = get_frame_pc (prev_frame); | |
4550 | ||
4551 | /* The scope breakpoint is related to the watchpoint. We | |
4552 | will need to act on them together. */ | |
4553 | b->related_breakpoint = scope_breakpoint; | |
4554 | } | |
4555 | } | |
4556 | value_free_to_mark (mark); | |
4557 | mention (b); | |
4558 | } | |
4559 | ||
4560 | /* Return count of locations need to be watched and can be handled | |
4561 | in hardware. If the watchpoint can not be handled | |
4562 | in hardware return zero. */ | |
4563 | ||
4564 | #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT) | |
53a5351d JM |
4565 | #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \ |
4566 | ((BYTE_SIZE) <= (REGISTER_SIZE)) | |
4567 | #endif | |
4568 | ||
4569 | #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT) | |
4570 | #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \ | |
4571 | TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN) | |
c906108c SS |
4572 | #endif |
4573 | ||
4574 | static int | |
4575 | can_use_hardware_watchpoint (v) | |
4576 | struct value *v; | |
4577 | { | |
4578 | int found_memory_cnt = 0; | |
4579 | ||
4580 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 4581 | if (!can_use_hw_watchpoints) |
c906108c | 4582 | return 0; |
c5aa993b | 4583 | |
c906108c SS |
4584 | /* Make sure all the intermediate values are in memory. Also make sure |
4585 | we found at least one memory expression. Guards against watch 0x12345, | |
4586 | which is meaningless, but could cause errors if one tries to insert a | |
4587 | hardware watchpoint for the constant expression. */ | |
c5aa993b | 4588 | for (; v; v = v->next) |
c906108c SS |
4589 | { |
4590 | if (v->lval == lval_memory) | |
4591 | { | |
53a5351d JM |
4592 | CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); |
4593 | int len = TYPE_LENGTH (VALUE_TYPE (v)); | |
4594 | ||
4595 | if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len)) | |
4596 | return 0; | |
4597 | else | |
c906108c | 4598 | found_memory_cnt++; |
c5aa993b | 4599 | } |
c906108c | 4600 | else if (v->lval != not_lval && v->modifiable == 0) |
53a5351d JM |
4601 | return 0; /* ??? What does this represent? */ |
4602 | else if (v->lval == lval_register) | |
4603 | return 0; /* cannot watch a register with a HW watchpoint */ | |
c906108c SS |
4604 | } |
4605 | ||
4606 | /* The expression itself looks suitable for using a hardware | |
4607 | watchpoint, but give the target machine a chance to reject it. */ | |
4608 | return found_memory_cnt; | |
4609 | } | |
4610 | ||
c5aa993b JM |
4611 | static void |
4612 | watch_command (arg, from_tty) | |
c906108c SS |
4613 | char *arg; |
4614 | int from_tty; | |
4615 | { | |
53a5351d | 4616 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
4617 | } |
4618 | ||
c5aa993b JM |
4619 | static void |
4620 | rwatch_command (arg, from_tty) | |
c906108c SS |
4621 | char *arg; |
4622 | int from_tty; | |
4623 | { | |
53a5351d | 4624 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
4625 | } |
4626 | ||
c5aa993b JM |
4627 | static void |
4628 | awatch_command (arg, from_tty) | |
c906108c SS |
4629 | char *arg; |
4630 | int from_tty; | |
4631 | { | |
53a5351d | 4632 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 4633 | } |
c906108c | 4634 | \f |
c5aa993b | 4635 | |
43ff13b4 | 4636 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
4637 | because it uses the mechanisms of breakpoints. */ |
4638 | ||
43ff13b4 JM |
4639 | /* This function is called by fetch_inferior_event via the |
4640 | cmd_continuation pointer, to complete the until command. It takes | |
4641 | care of cleaning up the temporary breakpoints set up by the until | |
4642 | command. */ | |
4643 | void | |
4644 | until_break_command_continuation (arg) | |
4645 | struct continuation_arg *arg; | |
4646 | { | |
4647 | /* Do all the exec cleanups, which at this point should only be the | |
4648 | one set up in the first part of the until_break_command | |
4649 | function. */ | |
4650 | do_exec_cleanups (ALL_CLEANUPS); | |
4651 | } | |
4652 | ||
c906108c SS |
4653 | /* ARGSUSED */ |
4654 | void | |
4655 | until_break_command (arg, from_tty) | |
4656 | char *arg; | |
4657 | int from_tty; | |
4658 | { | |
4659 | struct symtabs_and_lines sals; | |
4660 | struct symtab_and_line sal; | |
4661 | struct frame_info *prev_frame = get_prev_frame (selected_frame); | |
4662 | struct breakpoint *breakpoint; | |
4663 | struct cleanup *old_chain; | |
43ff13b4 | 4664 | struct continuation_arg *arg1, *arg2; |
c906108c SS |
4665 | |
4666 | clear_proceed_status (); | |
4667 | ||
4668 | /* Set a breakpoint where the user wants it and at return from | |
4669 | this function */ | |
c5aa993b | 4670 | |
c906108c SS |
4671 | if (default_breakpoint_valid) |
4672 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
c5aa993b | 4673 | default_breakpoint_line, (char ***) NULL); |
c906108c | 4674 | else |
53a5351d JM |
4675 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
4676 | 0, (char ***) NULL); | |
c5aa993b | 4677 | |
c906108c SS |
4678 | if (sals.nelts != 1) |
4679 | error ("Couldn't get information on specified line."); | |
c5aa993b | 4680 | |
c906108c | 4681 | sal = sals.sals[0]; |
c5aa993b JM |
4682 | free ((PTR) sals.sals); /* malloc'd, so freed */ |
4683 | ||
c906108c SS |
4684 | if (*arg) |
4685 | error ("Junk at end of arguments."); | |
c5aa993b | 4686 | |
c906108c | 4687 | resolve_sal_pc (&sal); |
c5aa993b | 4688 | |
c906108c | 4689 | breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until); |
c5aa993b | 4690 | |
43ff13b4 | 4691 | if (!async_p || !target_has_async) |
53a5351d JM |
4692 | old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, |
4693 | breakpoint); | |
43ff13b4 JM |
4694 | else |
4695 | make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint); | |
4696 | ||
4697 | /* If we are running asynchronously, and the target supports async | |
4698 | execution, we are not waiting for the target to stop, in the call | |
4699 | tp proceed, below. This means that we cannot delete the | |
4700 | brekpoints until the target has actually stopped. The only place | |
4701 | where we get a chance to do that is in fetch_inferior_event, so | |
4702 | we must set things up for that. */ | |
4703 | ||
4704 | if (async_p && target_has_async) | |
4705 | { | |
4706 | /* In this case we don't need args for the continuation, because | |
c5aa993b JM |
4707 | all it needs to do is do the cleanups in the |
4708 | exec_cleanup_chain, which will be only those inserted by this | |
4709 | function. We can get away by using ALL_CLEANUPS. */ | |
43ff13b4 JM |
4710 | add_continuation (until_break_command_continuation, NULL); |
4711 | } | |
c906108c SS |
4712 | |
4713 | /* Keep within the current frame */ | |
c5aa993b | 4714 | |
c906108c SS |
4715 | if (prev_frame) |
4716 | { | |
4717 | sal = find_pc_line (prev_frame->pc, 0); | |
4718 | sal.pc = prev_frame->pc; | |
4719 | breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until); | |
43ff13b4 JM |
4720 | if (!async_p || !target_has_async) |
4721 | make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint); | |
4722 | else | |
4723 | make_exec_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint); | |
c906108c | 4724 | } |
c5aa993b | 4725 | |
c906108c | 4726 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
43ff13b4 JM |
4727 | /* Do the cleanups now, anly if we are not running asynchronously, |
4728 | of if we are, but the target is still synchronous. */ | |
4729 | if (!async_p || !target_has_async) | |
c5aa993b | 4730 | do_cleanups (old_chain); |
c906108c SS |
4731 | } |
4732 | \f | |
4733 | #if 0 | |
4734 | /* These aren't used; I don't konw what they were for. */ | |
4735 | /* Set a breakpoint at the catch clause for NAME. */ | |
4736 | static int | |
4737 | catch_breakpoint (name) | |
4738 | char *name; | |
4739 | { | |
4740 | } | |
4741 | ||
4742 | static int | |
4743 | disable_catch_breakpoint () | |
4744 | { | |
4745 | } | |
4746 | ||
4747 | static int | |
4748 | delete_catch_breakpoint () | |
4749 | { | |
4750 | } | |
4751 | ||
4752 | static int | |
4753 | enable_catch_breakpoint () | |
4754 | { | |
4755 | } | |
4756 | #endif /* 0 */ | |
4757 | ||
4758 | struct sal_chain | |
4759 | { | |
4760 | struct sal_chain *next; | |
4761 | struct symtab_and_line sal; | |
4762 | }; | |
4763 | ||
7a292a7a | 4764 | #if 0 |
c906108c SS |
4765 | /* Not really used -- invocation in handle_gnu_4_16_catch_command |
4766 | had been commented out in the v.4.16 sources, and stays | |
4767 | disabled there now because "catch NAME" syntax isn't allowed. | |
4768 | pai/1997-07-11 */ | |
4769 | /* This isn't used; I don't know what it was for. */ | |
4770 | /* For each catch clause identified in ARGS, run FUNCTION | |
4771 | with that clause as an argument. */ | |
4772 | static struct symtabs_and_lines | |
4773 | map_catch_names (args, function) | |
4774 | char *args; | |
c5aa993b | 4775 | int (*function) (); |
c906108c SS |
4776 | { |
4777 | register char *p = args; | |
4778 | register char *p1; | |
4779 | struct symtabs_and_lines sals; | |
4780 | #if 0 | |
4781 | struct sal_chain *sal_chain = 0; | |
4782 | #endif | |
4783 | ||
4784 | if (p == 0) | |
4785 | error_no_arg ("one or more catch names"); | |
4786 | ||
4787 | sals.nelts = 0; | |
4788 | sals.sals = NULL; | |
4789 | ||
4790 | while (*p) | |
4791 | { | |
4792 | p1 = p; | |
4793 | /* Don't swallow conditional part. */ | |
4794 | if (p1[0] == 'i' && p1[1] == 'f' | |
4795 | && (p1[2] == ' ' || p1[2] == '\t')) | |
4796 | break; | |
4797 | ||
4798 | if (isalpha (*p1)) | |
4799 | { | |
4800 | p1++; | |
4801 | while (isalnum (*p1) || *p1 == '_' || *p1 == '$') | |
4802 | p1++; | |
4803 | } | |
4804 | ||
4805 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
4806 | error ("Arguments must be catch names."); | |
4807 | ||
4808 | *p1 = 0; | |
4809 | #if 0 | |
4810 | if (function (p)) | |
4811 | { | |
4812 | struct sal_chain *next = (struct sal_chain *) | |
c5aa993b | 4813 | alloca (sizeof (struct sal_chain)); |
c906108c SS |
4814 | next->next = sal_chain; |
4815 | next->sal = get_catch_sal (p); | |
4816 | sal_chain = next; | |
4817 | goto win; | |
4818 | } | |
4819 | #endif | |
4820 | printf_unfiltered ("No catch clause for exception %s.\n", p); | |
4821 | #if 0 | |
4822 | win: | |
4823 | #endif | |
4824 | p = p1; | |
c5aa993b JM |
4825 | while (*p == ' ' || *p == '\t') |
4826 | p++; | |
c906108c SS |
4827 | } |
4828 | } | |
7a292a7a | 4829 | #endif |
c906108c SS |
4830 | |
4831 | /* This shares a lot of code with `print_frame_label_vars' from stack.c. */ | |
4832 | ||
4833 | static struct symtabs_and_lines | |
4834 | get_catch_sals (this_level_only) | |
4835 | int this_level_only; | |
4836 | { | |
4837 | register struct blockvector *bl; | |
4838 | register struct block *block; | |
4839 | int index, have_default = 0; | |
4840 | CORE_ADDR pc; | |
4841 | struct symtabs_and_lines sals; | |
4842 | struct sal_chain *sal_chain = 0; | |
4843 | char *blocks_searched; | |
4844 | ||
4845 | /* Not sure whether an error message is always the correct response, | |
4846 | but it's better than a core dump. */ | |
4847 | if (selected_frame == NULL) | |
4848 | error ("No selected frame."); | |
4849 | block = get_frame_block (selected_frame); | |
4850 | pc = selected_frame->pc; | |
4851 | ||
4852 | sals.nelts = 0; | |
4853 | sals.sals = NULL; | |
4854 | ||
4855 | if (block == 0) | |
4856 | error ("No symbol table info available.\n"); | |
4857 | ||
4858 | bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); | |
4859 | blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); | |
4860 | memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); | |
4861 | ||
4862 | while (block != 0) | |
4863 | { | |
4864 | CORE_ADDR end = BLOCK_END (block) - 4; | |
4865 | int last_index; | |
4866 | ||
4867 | if (bl != blockvector_for_pc (end, &index)) | |
4868 | error ("blockvector blotch"); | |
4869 | if (BLOCKVECTOR_BLOCK (bl, index) != block) | |
4870 | error ("blockvector botch"); | |
4871 | last_index = BLOCKVECTOR_NBLOCKS (bl); | |
4872 | index += 1; | |
4873 | ||
4874 | /* Don't print out blocks that have gone by. */ | |
4875 | while (index < last_index | |
4876 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) | |
4877 | index++; | |
4878 | ||
4879 | while (index < last_index | |
4880 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) | |
4881 | { | |
4882 | if (blocks_searched[index] == 0) | |
4883 | { | |
4884 | struct block *b = BLOCKVECTOR_BLOCK (bl, index); | |
4885 | int nsyms; | |
4886 | register int i; | |
4887 | register struct symbol *sym; | |
4888 | ||
4889 | nsyms = BLOCK_NSYMS (b); | |
4890 | ||
4891 | for (i = 0; i < nsyms; i++) | |
4892 | { | |
4893 | sym = BLOCK_SYM (b, i); | |
4894 | if (STREQ (SYMBOL_NAME (sym), "default")) | |
4895 | { | |
4896 | if (have_default) | |
4897 | continue; | |
4898 | have_default = 1; | |
4899 | } | |
4900 | if (SYMBOL_CLASS (sym) == LOC_LABEL) | |
4901 | { | |
4902 | struct sal_chain *next = (struct sal_chain *) | |
c5aa993b | 4903 | alloca (sizeof (struct sal_chain)); |
c906108c | 4904 | next->next = sal_chain; |
53a5351d JM |
4905 | next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), |
4906 | 0); | |
c906108c SS |
4907 | sal_chain = next; |
4908 | } | |
4909 | } | |
4910 | blocks_searched[index] = 1; | |
4911 | } | |
4912 | index++; | |
4913 | } | |
4914 | if (have_default) | |
4915 | break; | |
4916 | if (sal_chain && this_level_only) | |
4917 | break; | |
4918 | ||
4919 | /* After handling the function's top-level block, stop. | |
c5aa993b JM |
4920 | Don't continue to its superblock, the block of |
4921 | per-file symbols. */ | |
c906108c SS |
4922 | if (BLOCK_FUNCTION (block)) |
4923 | break; | |
4924 | block = BLOCK_SUPERBLOCK (block); | |
4925 | } | |
4926 | ||
4927 | if (sal_chain) | |
4928 | { | |
4929 | struct sal_chain *tmp_chain; | |
4930 | ||
4931 | /* Count the number of entries. */ | |
4932 | for (index = 0, tmp_chain = sal_chain; tmp_chain; | |
4933 | tmp_chain = tmp_chain->next) | |
4934 | index++; | |
4935 | ||
4936 | sals.nelts = index; | |
4937 | sals.sals = (struct symtab_and_line *) | |
4938 | xmalloc (index * sizeof (struct symtab_and_line)); | |
4939 | for (index = 0; sal_chain; sal_chain = sal_chain->next, index++) | |
4940 | sals.sals[index] = sal_chain->sal; | |
4941 | } | |
4942 | ||
4943 | return sals; | |
4944 | } | |
4945 | ||
4946 | static void | |
4947 | ep_skip_leading_whitespace (s) | |
7a292a7a | 4948 | char **s; |
c906108c | 4949 | { |
c5aa993b JM |
4950 | if ((s == NULL) || (*s == NULL)) |
4951 | return; | |
4952 | while (isspace (**s)) | |
4953 | *s += 1; | |
c906108c | 4954 | } |
c5aa993b | 4955 | |
c906108c SS |
4956 | /* This function examines a string, and attempts to find a token |
4957 | that might be an event name in the leading characters. If a | |
4958 | possible match is found, a pointer to the last character of | |
4959 | the token is returned. Else, NULL is returned. */ | |
53a5351d | 4960 | |
c906108c SS |
4961 | static char * |
4962 | ep_find_event_name_end (arg) | |
7a292a7a | 4963 | char *arg; |
c906108c | 4964 | { |
c5aa993b JM |
4965 | char *s = arg; |
4966 | char *event_name_end = NULL; | |
4967 | ||
c906108c SS |
4968 | /* If we could depend upon the presense of strrpbrk, we'd use that... */ |
4969 | if (arg == NULL) | |
4970 | return NULL; | |
c5aa993b | 4971 | |
c906108c | 4972 | /* We break out of the loop when we find a token delimiter. |
c5aa993b JM |
4973 | Basically, we're looking for alphanumerics and underscores; |
4974 | anything else delimites the token. */ | |
c906108c SS |
4975 | while (*s != '\0') |
4976 | { | |
c5aa993b JM |
4977 | if (!isalnum (*s) && (*s != '_')) |
4978 | break; | |
c906108c SS |
4979 | event_name_end = s; |
4980 | s++; | |
4981 | } | |
c5aa993b | 4982 | |
c906108c SS |
4983 | return event_name_end; |
4984 | } | |
4985 | ||
c5aa993b | 4986 | |
c906108c SS |
4987 | /* This function attempts to parse an optional "if <cond>" clause |
4988 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 4989 | |
c906108c SS |
4990 | Else, it returns a pointer to the condition string. (It does not |
4991 | attempt to evaluate the string against a particular block.) And, | |
4992 | it updates arg to point to the first character following the parsed | |
4993 | if clause in the arg string. */ | |
53a5351d | 4994 | |
c906108c SS |
4995 | static char * |
4996 | ep_parse_optional_if_clause (arg) | |
7a292a7a | 4997 | char **arg; |
c906108c | 4998 | { |
c5aa993b JM |
4999 | char *cond_string; |
5000 | ||
5001 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 5002 | return NULL; |
c5aa993b | 5003 | |
c906108c SS |
5004 | /* Skip the "if" keyword. */ |
5005 | (*arg) += 2; | |
c5aa993b | 5006 | |
c906108c SS |
5007 | /* Skip any extra leading whitespace, and record the start of the |
5008 | condition string. */ | |
5009 | ep_skip_leading_whitespace (arg); | |
5010 | cond_string = *arg; | |
c5aa993b | 5011 | |
c906108c SS |
5012 | /* Assume that the condition occupies the remainder of the arg string. */ |
5013 | (*arg) += strlen (cond_string); | |
c5aa993b | 5014 | |
c906108c SS |
5015 | return cond_string; |
5016 | } | |
c5aa993b | 5017 | |
c906108c SS |
5018 | /* This function attempts to parse an optional filename from the arg |
5019 | string. If one is not found, it returns NULL. | |
c5aa993b | 5020 | |
c906108c SS |
5021 | Else, it returns a pointer to the parsed filename. (This function |
5022 | makes no attempt to verify that a file of that name exists, or is | |
5023 | accessible.) And, it updates arg to point to the first character | |
5024 | following the parsed filename in the arg string. | |
c5aa993b | 5025 | |
c906108c SS |
5026 | Note that clients needing to preserve the returned filename for |
5027 | future access should copy it to their own buffers. */ | |
5028 | static char * | |
5029 | ep_parse_optional_filename (arg) | |
7a292a7a | 5030 | char **arg; |
c906108c | 5031 | { |
c5aa993b JM |
5032 | static char filename[1024]; |
5033 | char *arg_p = *arg; | |
5034 | int i; | |
5035 | char c; | |
5036 | ||
c906108c SS |
5037 | if ((*arg_p == '\0') || isspace (*arg_p)) |
5038 | return NULL; | |
c5aa993b JM |
5039 | |
5040 | for (i = 0;; i++) | |
c906108c SS |
5041 | { |
5042 | c = *arg_p; | |
5043 | if (isspace (c)) | |
c5aa993b | 5044 | c = '\0'; |
c906108c SS |
5045 | filename[i] = c; |
5046 | if (c == '\0') | |
c5aa993b | 5047 | break; |
c906108c SS |
5048 | arg_p++; |
5049 | } | |
5050 | *arg = arg_p; | |
c5aa993b | 5051 | |
c906108c SS |
5052 | return filename; |
5053 | } | |
c5aa993b | 5054 | |
c906108c SS |
5055 | /* Commands to deal with catching events, such as signals, exceptions, |
5056 | process start/exit, etc. */ | |
c5aa993b JM |
5057 | |
5058 | typedef enum | |
5059 | { | |
5060 | catch_fork, catch_vfork | |
5061 | } | |
5062 | catch_fork_kind; | |
5063 | ||
53a5351d JM |
5064 | static void catch_fork_command_1 PARAMS ((catch_fork_kind fork_kind, |
5065 | char *arg, | |
5066 | int tempflag, | |
5067 | int from_tty)); | |
7a292a7a | 5068 | |
c906108c SS |
5069 | static void |
5070 | catch_fork_command_1 (fork_kind, arg, tempflag, from_tty) | |
7a292a7a SS |
5071 | catch_fork_kind fork_kind; |
5072 | char *arg; | |
5073 | int tempflag; | |
5074 | int from_tty; | |
c906108c | 5075 | { |
c5aa993b JM |
5076 | char *cond_string = NULL; |
5077 | ||
c906108c | 5078 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 5079 | |
c906108c | 5080 | /* The allowed syntax is: |
c5aa993b JM |
5081 | catch [v]fork |
5082 | catch [v]fork if <cond> | |
5083 | ||
c906108c SS |
5084 | First, check if there's an if clause. */ |
5085 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 5086 | |
c906108c SS |
5087 | if ((*arg != '\0') && !isspace (*arg)) |
5088 | error ("Junk at end of arguments."); | |
c5aa993b | 5089 | |
c906108c SS |
5090 | /* If this target supports it, create a fork or vfork catchpoint |
5091 | and enable reporting of such events. */ | |
c5aa993b JM |
5092 | switch (fork_kind) |
5093 | { | |
5094 | case catch_fork: | |
c906108c SS |
5095 | create_fork_event_catchpoint (tempflag, cond_string); |
5096 | break; | |
c5aa993b | 5097 | case catch_vfork: |
c906108c SS |
5098 | create_vfork_event_catchpoint (tempflag, cond_string); |
5099 | break; | |
c5aa993b | 5100 | default: |
c906108c SS |
5101 | error ("unsupported or unknown fork kind; cannot catch it"); |
5102 | break; | |
c5aa993b | 5103 | } |
c906108c SS |
5104 | } |
5105 | ||
5106 | static void | |
5107 | catch_exec_command_1 (arg, tempflag, from_tty) | |
7a292a7a SS |
5108 | char *arg; |
5109 | int tempflag; | |
5110 | int from_tty; | |
c906108c | 5111 | { |
c5aa993b | 5112 | char *cond_string = NULL; |
c906108c SS |
5113 | |
5114 | ep_skip_leading_whitespace (&arg); | |
5115 | ||
5116 | /* The allowed syntax is: | |
c5aa993b JM |
5117 | catch exec |
5118 | catch exec if <cond> | |
c906108c SS |
5119 | |
5120 | First, check if there's an if clause. */ | |
5121 | cond_string = ep_parse_optional_if_clause (&arg); | |
5122 | ||
5123 | if ((*arg != '\0') && !isspace (*arg)) | |
5124 | error ("Junk at end of arguments."); | |
5125 | ||
5126 | /* If this target supports it, create an exec catchpoint | |
5127 | and enable reporting of such events. */ | |
5128 | create_exec_event_catchpoint (tempflag, cond_string); | |
5129 | } | |
c5aa993b | 5130 | |
c906108c SS |
5131 | #if defined(SOLIB_ADD) |
5132 | static void | |
5133 | catch_load_command_1 (arg, tempflag, from_tty) | |
c5aa993b JM |
5134 | char *arg; |
5135 | int tempflag; | |
5136 | int from_tty; | |
c906108c | 5137 | { |
c5aa993b JM |
5138 | char *dll_pathname = NULL; |
5139 | char *cond_string = NULL; | |
5140 | ||
c906108c | 5141 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 5142 | |
c906108c | 5143 | /* The allowed syntax is: |
c5aa993b JM |
5144 | catch load |
5145 | catch load if <cond> | |
5146 | catch load <filename> | |
5147 | catch load <filename> if <cond> | |
5148 | ||
c906108c SS |
5149 | The user is not allowed to specify the <filename> after an |
5150 | if clause. | |
c5aa993b | 5151 | |
c906108c | 5152 | We'll ignore the pathological case of a file named "if". |
c5aa993b | 5153 | |
c906108c SS |
5154 | First, check if there's an if clause. If so, then there |
5155 | cannot be a filename. */ | |
5156 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 5157 | |
c906108c SS |
5158 | /* If there was an if clause, then there cannot be a filename. |
5159 | Else, there might be a filename and an if clause. */ | |
5160 | if (cond_string == NULL) | |
5161 | { | |
5162 | dll_pathname = ep_parse_optional_filename (&arg); | |
5163 | ep_skip_leading_whitespace (&arg); | |
5164 | cond_string = ep_parse_optional_if_clause (&arg); | |
5165 | } | |
c5aa993b | 5166 | |
c906108c SS |
5167 | if ((*arg != '\0') && !isspace (*arg)) |
5168 | error ("Junk at end of arguments."); | |
c5aa993b | 5169 | |
c906108c SS |
5170 | /* Create a load breakpoint that only triggers when a load of |
5171 | the specified dll (or any dll, if no pathname was specified) | |
5172 | occurs. */ | |
53a5351d JM |
5173 | SOLIB_CREATE_CATCH_LOAD_HOOK (inferior_pid, tempflag, |
5174 | dll_pathname, cond_string); | |
c906108c | 5175 | } |
c5aa993b | 5176 | |
c906108c SS |
5177 | static void |
5178 | catch_unload_command_1 (arg, tempflag, from_tty) | |
c5aa993b JM |
5179 | char *arg; |
5180 | int tempflag; | |
5181 | int from_tty; | |
c906108c | 5182 | { |
c5aa993b JM |
5183 | char *dll_pathname = NULL; |
5184 | char *cond_string = NULL; | |
5185 | ||
c906108c | 5186 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 5187 | |
c906108c | 5188 | /* The allowed syntax is: |
c5aa993b JM |
5189 | catch unload |
5190 | catch unload if <cond> | |
5191 | catch unload <filename> | |
5192 | catch unload <filename> if <cond> | |
5193 | ||
c906108c SS |
5194 | The user is not allowed to specify the <filename> after an |
5195 | if clause. | |
c5aa993b | 5196 | |
c906108c | 5197 | We'll ignore the pathological case of a file named "if". |
c5aa993b | 5198 | |
c906108c SS |
5199 | First, check if there's an if clause. If so, then there |
5200 | cannot be a filename. */ | |
5201 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 5202 | |
c906108c SS |
5203 | /* If there was an if clause, then there cannot be a filename. |
5204 | Else, there might be a filename and an if clause. */ | |
5205 | if (cond_string == NULL) | |
5206 | { | |
5207 | dll_pathname = ep_parse_optional_filename (&arg); | |
5208 | ep_skip_leading_whitespace (&arg); | |
5209 | cond_string = ep_parse_optional_if_clause (&arg); | |
5210 | } | |
c5aa993b | 5211 | |
c906108c SS |
5212 | if ((*arg != '\0') && !isspace (*arg)) |
5213 | error ("Junk at end of arguments."); | |
c5aa993b | 5214 | |
c906108c SS |
5215 | /* Create an unload breakpoint that only triggers when an unload of |
5216 | the specified dll (or any dll, if no pathname was specified) | |
5217 | occurs. */ | |
53a5351d JM |
5218 | SOLIB_CREATE_CATCH_UNLOAD_HOOK (inferior_pid, tempflag, |
5219 | dll_pathname, cond_string); | |
c906108c SS |
5220 | } |
5221 | #endif /* SOLIB_ADD */ | |
5222 | ||
5223 | /* Commands to deal with catching exceptions. */ | |
5224 | ||
5225 | /* Set a breakpoint at the specified callback routine for an | |
c5aa993b | 5226 | exception event callback */ |
c906108c SS |
5227 | |
5228 | static void | |
5229 | create_exception_catchpoint (tempflag, cond_string, ex_event, sal) | |
7a292a7a SS |
5230 | int tempflag; |
5231 | char *cond_string; | |
5232 | enum exception_event_kind ex_event; | |
5233 | struct symtab_and_line *sal; | |
c906108c | 5234 | { |
c5aa993b JM |
5235 | struct breakpoint *b; |
5236 | int i; | |
5237 | int thread = -1; /* All threads. */ | |
c906108c | 5238 | |
c5aa993b | 5239 | if (!sal) /* no exception support? */ |
c906108c SS |
5240 | return; |
5241 | ||
5242 | b = set_raw_breakpoint (*sal); | |
5243 | set_breakpoint_count (breakpoint_count + 1); | |
5244 | b->number = breakpoint_count; | |
5245 | b->cond = NULL; | |
53a5351d JM |
5246 | b->cond_string = (cond_string == NULL) ? |
5247 | NULL : savestring (cond_string, strlen (cond_string)); | |
c906108c SS |
5248 | b->thread = thread; |
5249 | b->addr_string = NULL; | |
5250 | b->enable = enabled; | |
5251 | b->disposition = tempflag ? del : donttouch; | |
5252 | switch (ex_event) | |
5253 | { | |
c5aa993b JM |
5254 | case EX_EVENT_THROW: |
5255 | b->type = bp_catch_throw; | |
5256 | break; | |
5257 | case EX_EVENT_CATCH: | |
5258 | b->type = bp_catch_catch; | |
5259 | break; | |
5260 | default: /* error condition */ | |
5261 | b->type = bp_none; | |
5262 | b->enable = disabled; | |
5263 | error ("Internal error -- invalid catchpoint kind"); | |
c906108c SS |
5264 | } |
5265 | mention (b); | |
5266 | } | |
5267 | ||
c5aa993b | 5268 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
5269 | |
5270 | static void | |
5271 | catch_exception_command_1 (ex_event, arg, tempflag, from_tty) | |
7a292a7a SS |
5272 | enum exception_event_kind ex_event; |
5273 | char *arg; | |
5274 | int tempflag; | |
5275 | int from_tty; | |
c906108c | 5276 | { |
c5aa993b JM |
5277 | char *cond_string = NULL; |
5278 | struct symtab_and_line *sal = NULL; | |
5279 | ||
c906108c | 5280 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 5281 | |
c906108c SS |
5282 | cond_string = ep_parse_optional_if_clause (&arg); |
5283 | ||
5284 | if ((*arg != '\0') && !isspace (*arg)) | |
5285 | error ("Junk at end of arguments."); | |
5286 | ||
5287 | if ((ex_event != EX_EVENT_THROW) && | |
5288 | (ex_event != EX_EVENT_CATCH)) | |
5289 | error ("Unsupported or unknown exception event; cannot catch it"); | |
5290 | ||
5291 | /* See if we can find a callback routine */ | |
5292 | sal = target_enable_exception_callback (ex_event, 1); | |
5293 | ||
c5aa993b | 5294 | if (sal) |
c906108c SS |
5295 | { |
5296 | /* We have callbacks from the runtime system for exceptions. | |
c5aa993b | 5297 | Set a breakpoint on the sal found, if no errors */ |
c906108c | 5298 | if (sal != (struct symtab_and_line *) -1) |
c5aa993b | 5299 | create_exception_catchpoint (tempflag, cond_string, ex_event, sal); |
c906108c | 5300 | else |
53a5351d | 5301 | return; /* something went wrong with setting up callbacks */ |
c906108c | 5302 | } |
c5aa993b | 5303 | else |
c906108c SS |
5304 | { |
5305 | /* No callbacks from runtime system for exceptions. | |
5306 | Try GNU C++ exception breakpoints using labels in debug info. */ | |
5307 | if (ex_event == EX_EVENT_CATCH) | |
c5aa993b JM |
5308 | { |
5309 | handle_gnu_4_16_catch_command (arg, tempflag, from_tty); | |
5310 | } | |
c906108c | 5311 | else if (ex_event == EX_EVENT_THROW) |
c5aa993b JM |
5312 | { |
5313 | /* Set a breakpoint on __raise_exception () */ | |
5314 | ||
53a5351d JM |
5315 | warning ("Unsupported with this platform/compiler combination."); |
5316 | warning ("Perhaps you can achieve the effect you want by setting"); | |
5317 | warning ("a breakpoint on __raise_exception()."); | |
c5aa993b | 5318 | } |
c906108c SS |
5319 | } |
5320 | } | |
5321 | ||
5322 | /* Cover routine to allow wrapping target_enable_exception_catchpoints | |
5323 | inside a catch_errors */ | |
5324 | ||
5325 | static int | |
5326 | cover_target_enable_exception_callback (arg) | |
c5aa993b | 5327 | PTR arg; |
c906108c SS |
5328 | { |
5329 | args_for_catchpoint_enable *args = arg; | |
5330 | struct symtab_and_line *sal; | |
5331 | sal = target_enable_exception_callback (args->kind, args->enable); | |
5332 | if (sal == NULL) | |
5333 | return 0; | |
5334 | else if (sal == (struct symtab_and_line *) -1) | |
5335 | return -1; | |
5336 | else | |
c5aa993b | 5337 | return 1; /*is valid */ |
c906108c SS |
5338 | } |
5339 | ||
5340 | ||
5341 | ||
5342 | /* This is the original v.4.16 and earlier version of the | |
5343 | catch_command_1() function. Now that other flavours of "catch" | |
5344 | have been introduced, and since exception handling can be handled | |
5345 | in other ways (through target ops) also, this is used only for the | |
5346 | GNU C++ exception handling system. | |
5347 | Note: Only the "catch" flavour of GDB 4.16 is handled here. The | |
5348 | "catch NAME" is now no longer allowed in catch_command_1(). Also, | |
5349 | there was no code in GDB 4.16 for "catch throw". | |
c5aa993b | 5350 | |
c906108c SS |
5351 | Called from catch_exception_command_1 () */ |
5352 | ||
5353 | ||
5354 | static void | |
5355 | handle_gnu_4_16_catch_command (arg, tempflag, from_tty) | |
5356 | char *arg; | |
5357 | int tempflag; | |
5358 | int from_tty; | |
5359 | { | |
5360 | /* First, translate ARG into something we can deal with in terms | |
5361 | of breakpoints. */ | |
5362 | ||
5363 | struct symtabs_and_lines sals; | |
5364 | struct symtab_and_line sal; | |
5365 | register struct expression *cond = 0; | |
5366 | register struct breakpoint *b; | |
5367 | char *save_arg; | |
5368 | int i; | |
5369 | ||
c5aa993b | 5370 | INIT_SAL (&sal); /* initialize to zeroes */ |
c906108c SS |
5371 | |
5372 | /* If no arg given, or if first arg is 'if ', all active catch clauses | |
5373 | are breakpointed. */ | |
5374 | ||
c5aa993b | 5375 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' |
c906108c SS |
5376 | && (arg[2] == ' ' || arg[2] == '\t'))) |
5377 | { | |
5378 | /* Grab all active catch clauses. */ | |
5379 | sals = get_catch_sals (0); | |
5380 | } | |
5381 | else | |
5382 | { | |
5383 | /* Grab selected catch clauses. */ | |
5384 | error ("catch NAME not implemented"); | |
5385 | ||
5386 | #if 0 | |
5387 | /* Not sure why this code has been disabled. I'm leaving | |
5388 | it disabled. We can never come here now anyway | |
5389 | since we don't allow the "catch NAME" syntax. | |
c5aa993b | 5390 | pai/1997-07-11 */ |
c906108c SS |
5391 | |
5392 | /* This isn't used; I don't know what it was for. */ | |
5393 | sals = map_catch_names (arg, catch_breakpoint); | |
5394 | #endif | |
5395 | } | |
5396 | ||
c5aa993b | 5397 | if (!sals.nelts) |
c906108c SS |
5398 | return; |
5399 | ||
5400 | save_arg = arg; | |
5401 | for (i = 0; i < sals.nelts; i++) | |
5402 | { | |
5403 | resolve_sal_pc (&sals.sals[i]); | |
c5aa993b | 5404 | |
c906108c SS |
5405 | while (arg && *arg) |
5406 | { | |
5407 | if (arg[0] == 'i' && arg[1] == 'f' | |
5408 | && (arg[2] == ' ' || arg[2] == '\t')) | |
c5aa993b | 5409 | cond = parse_exp_1 ((arg += 2, &arg), |
c906108c SS |
5410 | block_for_pc (sals.sals[i].pc), 0); |
5411 | else | |
5412 | error ("Junk at end of arguments."); | |
5413 | } | |
5414 | arg = save_arg; | |
5415 | } | |
5416 | ||
5417 | for (i = 0; i < sals.nelts; i++) | |
5418 | { | |
5419 | sal = sals.sals[i]; | |
5420 | ||
5421 | if (from_tty) | |
5422 | describe_other_breakpoints (sal.pc, sal.section); | |
5423 | ||
5424 | b = set_raw_breakpoint (sal); | |
5425 | set_breakpoint_count (breakpoint_count + 1); | |
5426 | b->number = breakpoint_count; | |
53a5351d JM |
5427 | |
5428 | /* Important -- this is an ordinary breakpoint. For platforms | |
5429 | with callback support for exceptions, | |
5430 | create_exception_catchpoint() will create special bp types | |
5431 | (bp_catch_catch and bp_catch_throw), and there is code in | |
5432 | insert_breakpoints() and elsewhere that depends on that. */ | |
5433 | b->type = bp_breakpoint; | |
c906108c SS |
5434 | |
5435 | b->cond = cond; | |
5436 | b->enable = enabled; | |
5437 | b->disposition = tempflag ? del : donttouch; | |
5438 | ||
5439 | mention (b); | |
5440 | } | |
5441 | ||
5442 | if (sals.nelts > 1) | |
5443 | { | |
53a5351d JM |
5444 | warning ("Multiple breakpoints were set."); |
5445 | warning ("Use the \"delete\" command to delete unwanted breakpoints."); | |
c906108c | 5446 | } |
c5aa993b | 5447 | free ((PTR) sals.sals); |
c906108c SS |
5448 | } |
5449 | ||
5450 | #if 0 | |
5451 | /* This creates a temporary internal breakpoint | |
5452 | just to placate infrun */ | |
5453 | static struct breakpoint * | |
5454 | create_temp_exception_breakpoint (pc) | |
c5aa993b | 5455 | CORE_ADDR pc; |
c906108c SS |
5456 | { |
5457 | struct symtab_and_line sal; | |
5458 | struct breakpoint *b; | |
5459 | ||
c5aa993b | 5460 | INIT_SAL (&sal); |
c906108c SS |
5461 | sal.pc = pc; |
5462 | sal.symtab = NULL; | |
5463 | sal.line = 0; | |
5464 | ||
5465 | b = set_raw_breakpoint (sal); | |
5466 | if (!b) | |
5467 | error ("Internal error -- couldn't set temp exception breakpoint"); | |
5468 | ||
5469 | b->type = bp_breakpoint; | |
5470 | b->disposition = del; | |
5471 | b->enable = enabled; | |
5472 | b->silent = 1; | |
5473 | b->number = internal_breakpoint_number--; | |
5474 | return b; | |
5475 | } | |
5476 | #endif | |
5477 | ||
5478 | static void | |
5479 | catch_command_1 (arg, tempflag, from_tty) | |
c5aa993b JM |
5480 | char *arg; |
5481 | int tempflag; | |
5482 | int from_tty; | |
c906108c | 5483 | { |
c5aa993b | 5484 | |
c906108c SS |
5485 | /* The first argument may be an event name, such as "start" or "load". |
5486 | If so, then handle it as such. If it doesn't match an event name, | |
5487 | then attempt to interpret it as an exception name. (This latter is | |
5488 | the v4.16-and-earlier GDB meaning of the "catch" command.) | |
c5aa993b | 5489 | |
c906108c | 5490 | First, try to find the bounds of what might be an event name. */ |
c5aa993b JM |
5491 | char *arg1_start = arg; |
5492 | char *arg1_end; | |
5493 | int arg1_length; | |
5494 | ||
c906108c SS |
5495 | if (arg1_start == NULL) |
5496 | { | |
c5aa993b | 5497 | /* Old behaviour was to use pre-v-4.16 syntax */ |
c906108c SS |
5498 | /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ |
5499 | /* return; */ | |
c5aa993b | 5500 | /* Now, this is not allowed */ |
c906108c SS |
5501 | error ("Catch requires an event name."); |
5502 | ||
5503 | } | |
5504 | arg1_end = ep_find_event_name_end (arg1_start); | |
5505 | if (arg1_end == NULL) | |
5506 | error ("catch requires an event"); | |
5507 | arg1_length = arg1_end + 1 - arg1_start; | |
c5aa993b | 5508 | |
c906108c SS |
5509 | /* Try to match what we found against known event names. */ |
5510 | if (strncmp (arg1_start, "signal", arg1_length) == 0) | |
5511 | { | |
5512 | error ("Catch of signal not yet implemented"); | |
5513 | } | |
5514 | else if (strncmp (arg1_start, "catch", arg1_length) == 0) | |
5515 | { | |
53a5351d JM |
5516 | catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1, |
5517 | tempflag, from_tty); | |
c906108c SS |
5518 | } |
5519 | else if (strncmp (arg1_start, "throw", arg1_length) == 0) | |
5520 | { | |
53a5351d JM |
5521 | catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1, |
5522 | tempflag, from_tty); | |
c906108c SS |
5523 | } |
5524 | else if (strncmp (arg1_start, "thread_start", arg1_length) == 0) | |
5525 | { | |
5526 | error ("Catch of thread_start not yet implemented"); | |
5527 | } | |
5528 | else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0) | |
5529 | { | |
5530 | error ("Catch of thread_exit not yet implemented"); | |
5531 | } | |
5532 | else if (strncmp (arg1_start, "thread_join", arg1_length) == 0) | |
5533 | { | |
5534 | error ("Catch of thread_join not yet implemented"); | |
5535 | } | |
5536 | else if (strncmp (arg1_start, "start", arg1_length) == 0) | |
5537 | { | |
5538 | error ("Catch of start not yet implemented"); | |
5539 | } | |
5540 | else if (strncmp (arg1_start, "exit", arg1_length) == 0) | |
5541 | { | |
5542 | error ("Catch of exit not yet implemented"); | |
5543 | } | |
5544 | else if (strncmp (arg1_start, "fork", arg1_length) == 0) | |
5545 | { | |
5546 | #if defined(CHILD_INSERT_FORK_CATCHPOINT) | |
c5aa993b | 5547 | catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty); |
c906108c SS |
5548 | #else |
5549 | error ("Catch of fork not yet implemented"); | |
5550 | #endif | |
5551 | } | |
5552 | else if (strncmp (arg1_start, "vfork", arg1_length) == 0) | |
5553 | { | |
5554 | #if defined(CHILD_INSERT_VFORK_CATCHPOINT) | |
c5aa993b | 5555 | catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty); |
c906108c SS |
5556 | #else |
5557 | error ("Catch of vfork not yet implemented"); | |
5558 | #endif | |
5559 | } | |
5560 | else if (strncmp (arg1_start, "exec", arg1_length) == 0) | |
5561 | { | |
5562 | #if defined(CHILD_INSERT_EXEC_CATCHPOINT) | |
c5aa993b | 5563 | catch_exec_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
5564 | #else |
5565 | error ("Catch of exec not yet implemented"); | |
5566 | #endif | |
5567 | } | |
5568 | else if (strncmp (arg1_start, "load", arg1_length) == 0) | |
5569 | { | |
5570 | #if defined(SOLIB_ADD) | |
c5aa993b | 5571 | catch_load_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
5572 | #else |
5573 | error ("Catch of load not implemented"); | |
5574 | #endif | |
5575 | } | |
5576 | else if (strncmp (arg1_start, "unload", arg1_length) == 0) | |
5577 | { | |
5578 | #if defined(SOLIB_ADD) | |
c5aa993b | 5579 | catch_unload_command_1 (arg1_end + 1, tempflag, from_tty); |
c906108c SS |
5580 | #else |
5581 | error ("Catch of load not implemented"); | |
5582 | #endif | |
5583 | } | |
5584 | else if (strncmp (arg1_start, "stop", arg1_length) == 0) | |
5585 | { | |
5586 | error ("Catch of stop not yet implemented"); | |
5587 | } | |
c5aa993b | 5588 | |
c906108c SS |
5589 | /* This doesn't appear to be an event name */ |
5590 | ||
5591 | else | |
5592 | { | |
5593 | /* Pre-v.4.16 behaviour was to treat the argument | |
c5aa993b | 5594 | as the name of an exception */ |
c906108c | 5595 | /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ |
c5aa993b | 5596 | /* Now this is not allowed */ |
c906108c SS |
5597 | error ("Unknown event kind specified for catch"); |
5598 | ||
5599 | } | |
5600 | } | |
5601 | ||
5602 | /* Used by the gui, could be made a worker for other things. */ | |
5603 | ||
5604 | struct breakpoint * | |
5605 | set_breakpoint_sal (sal) | |
5606 | struct symtab_and_line sal; | |
5607 | { | |
5608 | struct breakpoint *b; | |
5609 | b = set_raw_breakpoint (sal); | |
5610 | set_breakpoint_count (breakpoint_count + 1); | |
5611 | b->number = breakpoint_count; | |
5612 | b->type = bp_breakpoint; | |
5613 | b->cond = 0; | |
5614 | b->thread = -1; | |
5615 | return b; | |
5616 | } | |
5617 | ||
5618 | #if 0 | |
5619 | /* These aren't used; I don't know what they were for. */ | |
5620 | /* Disable breakpoints on all catch clauses described in ARGS. */ | |
5621 | static void | |
5622 | disable_catch (args) | |
5623 | char *args; | |
5624 | { | |
5625 | /* Map the disable command to catch clauses described in ARGS. */ | |
5626 | } | |
5627 | ||
5628 | /* Enable breakpoints on all catch clauses described in ARGS. */ | |
5629 | static void | |
5630 | enable_catch (args) | |
5631 | char *args; | |
5632 | { | |
5633 | /* Map the disable command to catch clauses described in ARGS. */ | |
5634 | } | |
5635 | ||
5636 | /* Delete breakpoints on all catch clauses in the active scope. */ | |
5637 | static void | |
5638 | delete_catch (args) | |
5639 | char *args; | |
5640 | { | |
5641 | /* Map the delete command to catch clauses described in ARGS. */ | |
5642 | } | |
5643 | #endif /* 0 */ | |
5644 | ||
5645 | static void | |
5646 | catch_command (arg, from_tty) | |
5647 | char *arg; | |
5648 | int from_tty; | |
5649 | { | |
5650 | catch_command_1 (arg, 0, from_tty); | |
5651 | } | |
5652 | \f | |
5653 | ||
5654 | static void | |
5655 | tcatch_command (arg, from_tty) | |
5656 | char *arg; | |
5657 | int from_tty; | |
5658 | { | |
5659 | catch_command_1 (arg, 1, from_tty); | |
5660 | } | |
5661 | ||
5662 | ||
5663 | static void | |
5664 | clear_command (arg, from_tty) | |
5665 | char *arg; | |
5666 | int from_tty; | |
5667 | { | |
5668 | register struct breakpoint *b, *b1; | |
5669 | int default_match; | |
5670 | struct symtabs_and_lines sals; | |
5671 | struct symtab_and_line sal; | |
5672 | register struct breakpoint *found; | |
5673 | int i; | |
5674 | ||
5675 | if (arg) | |
5676 | { | |
5677 | sals = decode_line_spec (arg, 1); | |
5678 | default_match = 0; | |
5679 | } | |
5680 | else | |
5681 | { | |
c5aa993b | 5682 | sals.sals = (struct symtab_and_line *) |
c906108c | 5683 | xmalloc (sizeof (struct symtab_and_line)); |
c5aa993b | 5684 | INIT_SAL (&sal); /* initialize to zeroes */ |
c906108c SS |
5685 | sal.line = default_breakpoint_line; |
5686 | sal.symtab = default_breakpoint_symtab; | |
5687 | sal.pc = default_breakpoint_address; | |
5688 | if (sal.symtab == 0) | |
5689 | error ("No source file specified."); | |
5690 | ||
5691 | sals.sals[0] = sal; | |
5692 | sals.nelts = 1; | |
5693 | ||
5694 | default_match = 1; | |
5695 | } | |
5696 | ||
5697 | /* For each line spec given, delete bps which correspond | |
5698 | to it. We do this in two loops: the first loop looks at | |
5699 | the initial bp(s) in the chain which should be deleted, | |
5700 | the second goes down the rest of the chain looking ahead | |
5701 | one so it can take those bps off the chain without messing | |
5702 | up the chain. */ | |
5703 | ||
5704 | ||
5705 | for (i = 0; i < sals.nelts; i++) | |
5706 | { | |
5707 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
5708 | If line given (pc == 0), clear all bpts on specified line. |
5709 | If defaulting, clear all bpts on default line | |
c906108c | 5710 | or at default pc. |
c5aa993b JM |
5711 | |
5712 | defaulting sal.pc != 0 tests to do | |
5713 | ||
5714 | 0 1 pc | |
5715 | 1 1 pc _and_ line | |
5716 | 0 0 line | |
5717 | 1 0 <can't happen> */ | |
c906108c SS |
5718 | |
5719 | sal = sals.sals[i]; | |
5720 | found = (struct breakpoint *) 0; | |
5721 | ||
5722 | ||
5723 | while (breakpoint_chain | |
c5aa993b JM |
5724 | /* Why don't we check here that this is not |
5725 | a watchpoint, etc., as we do below? | |
5726 | I can't make it fail, but don't know | |
5727 | what's stopping the failure: a watchpoint | |
5728 | of the same address as "sal.pc" should | |
5729 | wind up being deleted. */ | |
5730 | ||
5731 | && (((sal.pc && (breakpoint_chain->address == sal.pc)) && | |
5732 | (overlay_debugging == 0 || | |
5733 | breakpoint_chain->section == sal.section)) | |
5734 | || ((default_match || (0 == sal.pc)) | |
5735 | && breakpoint_chain->source_file != NULL | |
5736 | && sal.symtab != NULL | |
5737 | && STREQ (breakpoint_chain->source_file, sal.symtab->filename) | |
5738 | && breakpoint_chain->line_number == sal.line))) | |
c906108c SS |
5739 | |
5740 | { | |
5741 | b1 = breakpoint_chain; | |
5742 | breakpoint_chain = b1->next; | |
5743 | b1->next = found; | |
5744 | found = b1; | |
5745 | } | |
5746 | ||
5747 | ALL_BREAKPOINTS (b) | |
5748 | ||
c5aa993b JM |
5749 | while (b->next |
5750 | && b->next->type != bp_none | |
5751 | && b->next->type != bp_watchpoint | |
5752 | && b->next->type != bp_hardware_watchpoint | |
5753 | && b->next->type != bp_read_watchpoint | |
5754 | && b->next->type != bp_access_watchpoint | |
5755 | && (((sal.pc && (b->next->address == sal.pc)) && | |
5756 | (overlay_debugging == 0 || | |
5757 | b->next->section == sal.section)) | |
5758 | || ((default_match || (0 == sal.pc)) | |
5759 | && b->next->source_file != NULL | |
5760 | && sal.symtab != NULL | |
5761 | && STREQ (b->next->source_file, sal.symtab->filename) | |
5762 | && b->next->line_number == sal.line))) | |
c906108c SS |
5763 | |
5764 | ||
c5aa993b JM |
5765 | { |
5766 | b1 = b->next; | |
5767 | b->next = b1->next; | |
5768 | b1->next = found; | |
5769 | found = b1; | |
5770 | } | |
c906108c SS |
5771 | |
5772 | if (found == 0) | |
5773 | { | |
5774 | if (arg) | |
5775 | error ("No breakpoint at %s.", arg); | |
5776 | else | |
5777 | error ("No breakpoint at this line."); | |
5778 | } | |
5779 | ||
c5aa993b JM |
5780 | if (found->next) |
5781 | from_tty = 1; /* Always report if deleted more than one */ | |
5782 | if (from_tty) | |
5783 | printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : ""); | |
c906108c SS |
5784 | breakpoints_changed (); |
5785 | while (found) | |
5786 | { | |
c5aa993b JM |
5787 | if (from_tty) |
5788 | printf_unfiltered ("%d ", found->number); | |
c906108c SS |
5789 | b1 = found->next; |
5790 | delete_breakpoint (found); | |
5791 | found = b1; | |
5792 | } | |
c5aa993b JM |
5793 | if (from_tty) |
5794 | putchar_unfiltered ('\n'); | |
c906108c | 5795 | } |
c5aa993b | 5796 | free ((PTR) sals.sals); |
c906108c SS |
5797 | } |
5798 | \f | |
5799 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
5800 | all breakpoints that are marked for deletion, whether hit or not. | |
5801 | This is called after any breakpoint is hit, or after errors. */ | |
5802 | ||
5803 | void | |
5804 | breakpoint_auto_delete (bs) | |
5805 | bpstat bs; | |
5806 | { | |
5807 | struct breakpoint *b, *temp; | |
5808 | ||
5809 | for (; bs; bs = bs->next) | |
c5aa993b | 5810 | if (bs->breakpoint_at && bs->breakpoint_at->disposition == del |
c906108c SS |
5811 | && bs->stop) |
5812 | delete_breakpoint (bs->breakpoint_at); | |
5813 | ||
5814 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b JM |
5815 | { |
5816 | if (b->disposition == del_at_next_stop) | |
5817 | delete_breakpoint (b); | |
5818 | } | |
c906108c SS |
5819 | } |
5820 | ||
53a5351d JM |
5821 | /* Delete a breakpoint and clean up all traces of it in the data |
5822 | structures. */ | |
c906108c SS |
5823 | |
5824 | void | |
5825 | delete_breakpoint (bpt) | |
5826 | struct breakpoint *bpt; | |
5827 | { | |
5828 | register struct breakpoint *b; | |
5829 | register bpstat bs; | |
5830 | ||
5831 | if (bpt == NULL) | |
5832 | error ("Internal error (attempted to delete a NULL breakpoint)"); | |
5833 | ||
5834 | ||
5835 | /* Has this bp already been deleted? This can happen because multiple | |
5836 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
5837 | ||
5838 | One example of this happening is a watchpoint's scope bp. When the | |
5839 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
5840 | delete it. We also delete its scope bp. But the scope bp is marked | |
5841 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
5842 | checked for auto-deleting bp's, which are deleted. | |
5843 | ||
5844 | A real solution to this problem might involve reference counts in bp's, | |
5845 | and/or giving them pointers back to their referencing bpstat's, and | |
5846 | teaching delete_breakpoint to only free a bp's storage when no more | |
5847 | references were extent. A cheaper bandaid was chosen. */ | |
5848 | if (bpt->type == bp_none) | |
5849 | return; | |
5850 | ||
5851 | if (delete_breakpoint_hook) | |
5852 | delete_breakpoint_hook (bpt); | |
5853 | ||
5854 | if (bpt->inserted) | |
5855 | remove_breakpoint (bpt, mark_uninserted); | |
c5aa993b | 5856 | |
c906108c SS |
5857 | if (breakpoint_chain == bpt) |
5858 | breakpoint_chain = bpt->next; | |
5859 | ||
5860 | /* If we have callback-style exception catchpoints, don't go through | |
5861 | the adjustments to the C++ runtime library etc. if the inferior | |
5862 | isn't actually running. target_enable_exception_callback for a | |
5863 | null target ops vector gives an undesirable error message, so we | |
5864 | check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's | |
c5aa993b | 5865 | exceptions are supported in this way, it's OK for now. FIXME */ |
c906108c SS |
5866 | if (ep_is_exception_catchpoint (bpt) && target_has_execution) |
5867 | { | |
5868 | static char message1[] = "Error in deleting catchpoint %d:\n"; | |
5869 | static char message[sizeof (message1) + 30]; | |
5870 | args_for_catchpoint_enable args; | |
5871 | ||
53a5351d JM |
5872 | /* Format possible error msg */ |
5873 | sprintf (message, message1, bpt->number); | |
5874 | args.kind = bpt->type == bp_catch_catch ? | |
5875 | EX_EVENT_CATCH : EX_EVENT_THROW; | |
c906108c SS |
5876 | args.enable = 0; |
5877 | catch_errors (cover_target_enable_exception_callback, &args, | |
5878 | message, RETURN_MASK_ALL); | |
5879 | } | |
5880 | ||
5881 | ||
5882 | ALL_BREAKPOINTS (b) | |
5883 | if (b->next == bpt) | |
c5aa993b JM |
5884 | { |
5885 | b->next = bpt->next; | |
5886 | break; | |
5887 | } | |
c906108c SS |
5888 | |
5889 | /* Before turning off the visuals for the bp, check to see that | |
5890 | there are no other bps at the same address. */ | |
5891 | if (tui_version) | |
5892 | { | |
5893 | int clearIt; | |
5894 | ||
5895 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5896 | { |
5897 | clearIt = (b->address != bpt->address); | |
5898 | if (!clearIt) | |
5899 | break; | |
5900 | } | |
c906108c SS |
5901 | |
5902 | if (clearIt) | |
c5aa993b JM |
5903 | { |
5904 | TUIDO (((TuiOpaqueFuncPtr) tui_vAllSetHasBreakAt, bpt, 0)); | |
5905 | TUIDO (((TuiOpaqueFuncPtr) tuiUpdateAllExecInfos)); | |
5906 | } | |
c906108c SS |
5907 | } |
5908 | ||
5909 | check_duplicates (bpt->address, bpt->section); | |
5910 | /* If this breakpoint was inserted, and there is another breakpoint | |
5911 | at the same address, we need to insert the other breakpoint. */ | |
5912 | if (bpt->inserted | |
5913 | && bpt->type != bp_hardware_watchpoint | |
5914 | && bpt->type != bp_read_watchpoint | |
5915 | && bpt->type != bp_access_watchpoint | |
5916 | && bpt->type != bp_catch_fork | |
5917 | && bpt->type != bp_catch_vfork | |
5918 | && bpt->type != bp_catch_exec) | |
5919 | { | |
5920 | ALL_BREAKPOINTS (b) | |
5921 | if (b->address == bpt->address | |
5922 | && b->section == bpt->section | |
5923 | && !b->duplicate | |
5924 | && b->enable != disabled | |
5925 | && b->enable != shlib_disabled | |
5926 | && b->enable != call_disabled) | |
c5aa993b JM |
5927 | { |
5928 | int val; | |
53a5351d JM |
5929 | |
5930 | if (b->type == bp_hardware_breakpoint) | |
5931 | val = target_insert_hw_breakpoint (b->address, b->shadow_contents); | |
5932 | else | |
5933 | val = target_insert_breakpoint (b->address, b->shadow_contents); | |
5934 | ||
c5aa993b JM |
5935 | if (val != 0) |
5936 | { | |
5937 | target_terminal_ours_for_output (); | |
53a5351d | 5938 | warning ("Cannot insert breakpoint %d:", b->number); |
c5aa993b JM |
5939 | memory_error (val, b->address); /* which bombs us out */ |
5940 | } | |
5941 | else | |
5942 | b->inserted = 1; | |
5943 | } | |
c906108c SS |
5944 | } |
5945 | ||
5946 | free_command_lines (&bpt->commands); | |
5947 | if (bpt->cond) | |
5948 | free (bpt->cond); | |
5949 | if (bpt->cond_string != NULL) | |
5950 | free (bpt->cond_string); | |
5951 | if (bpt->addr_string != NULL) | |
5952 | free (bpt->addr_string); | |
5953 | if (bpt->exp != NULL) | |
5954 | free (bpt->exp); | |
5955 | if (bpt->exp_string != NULL) | |
5956 | free (bpt->exp_string); | |
5957 | if (bpt->val != NULL) | |
5958 | value_free (bpt->val); | |
5959 | if (bpt->source_file != NULL) | |
5960 | free (bpt->source_file); | |
5961 | if (bpt->dll_pathname != NULL) | |
5962 | free (bpt->dll_pathname); | |
5963 | if (bpt->triggered_dll_pathname != NULL) | |
5964 | free (bpt->triggered_dll_pathname); | |
5965 | if (bpt->exec_pathname != NULL) | |
5966 | free (bpt->exec_pathname); | |
5967 | ||
5968 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
5969 | /* FIXME, how can we find all bpstat's? | |
5970 | We just check stop_bpstat for now. */ | |
5971 | for (bs = stop_bpstat; bs; bs = bs->next) | |
5972 | if (bs->breakpoint_at == bpt) | |
5973 | { | |
5974 | bs->breakpoint_at = NULL; | |
5975 | ||
5976 | /* we'd call bpstat_clear_actions, but that free's stuff and due | |
5977 | to the multiple pointers pointing to one item with no | |
5978 | reference counts found anywhere through out the bpstat's (how | |
5979 | do you spell fragile?), we don't want to free things twice -- | |
5980 | better a memory leak than a corrupt malloc pool! */ | |
5981 | bs->commands = NULL; | |
5982 | bs->old_val = NULL; | |
5983 | } | |
5984 | /* On the chance that someone will soon try again to delete this same | |
5985 | bp, we mark it as deleted before freeing its storage. */ | |
5986 | bpt->type = bp_none; | |
5987 | ||
c5aa993b | 5988 | free ((PTR) bpt); |
c906108c SS |
5989 | } |
5990 | ||
5991 | void | |
5992 | delete_command (arg, from_tty) | |
5993 | char *arg; | |
5994 | int from_tty; | |
5995 | { | |
5996 | struct breakpoint *b, *temp; | |
5997 | ||
5998 | if (arg == 0) | |
5999 | { | |
6000 | int breaks_to_delete = 0; | |
6001 | ||
6002 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
6003 | Do not delete internal or call-dummy breakpoints, these |
6004 | have to be deleted with an explicit breakpoint number argument. */ | |
6005 | ALL_BREAKPOINTS (b) | |
6006 | { | |
6007 | if (b->type != bp_call_dummy && | |
6008 | b->type != bp_shlib_event && | |
6009 | b->number >= 0) | |
6010 | breaks_to_delete = 1; | |
6011 | } | |
c906108c SS |
6012 | |
6013 | /* Ask user only if there are some breakpoints to delete. */ | |
6014 | if (!from_tty | |
6015 | || (breaks_to_delete && query ("Delete all breakpoints? "))) | |
6016 | { | |
c5aa993b JM |
6017 | ALL_BREAKPOINTS_SAFE (b, temp) |
6018 | { | |
6019 | if (b->type != bp_call_dummy && | |
6020 | b->type != bp_shlib_event && | |
6021 | b->number >= 0) | |
6022 | delete_breakpoint (b); | |
6023 | } | |
c906108c SS |
6024 | } |
6025 | } | |
6026 | else | |
6027 | map_breakpoint_numbers (arg, delete_breakpoint); | |
6028 | } | |
6029 | ||
6030 | /* Reset a breakpoint given it's struct breakpoint * BINT. | |
6031 | The value we return ends up being the return value from catch_errors. | |
6032 | Unused in this case. */ | |
6033 | ||
6034 | static int | |
6035 | breakpoint_re_set_one (bint) | |
6036 | PTR bint; | |
6037 | { | |
53a5351d JM |
6038 | /* get past catch_errs */ |
6039 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
6040 | struct value *mark; |
6041 | int i; | |
6042 | struct symtabs_and_lines sals; | |
6043 | char *s; | |
6044 | enum enable save_enable; | |
6045 | ||
6046 | switch (b->type) | |
6047 | { | |
6048 | case bp_none: | |
53a5351d JM |
6049 | warning ("attempted to reset apparently deleted breakpoint #%d?", |
6050 | b->number); | |
c906108c SS |
6051 | return 0; |
6052 | case bp_breakpoint: | |
6053 | case bp_hardware_breakpoint: | |
6054 | case bp_catch_load: | |
6055 | case bp_catch_unload: | |
6056 | if (b->addr_string == NULL) | |
6057 | { | |
6058 | /* Anything without a string can't be re-set. */ | |
6059 | delete_breakpoint (b); | |
6060 | return 0; | |
6061 | } | |
6062 | /* In case we have a problem, disable this breakpoint. We'll restore | |
c5aa993b | 6063 | its status if we succeed. */ |
c906108c SS |
6064 | save_enable = b->enable; |
6065 | b->enable = disabled; | |
6066 | ||
6067 | set_language (b->language); | |
6068 | input_radix = b->input_radix; | |
6069 | s = b->addr_string; | |
c5aa993b | 6070 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL); |
c906108c SS |
6071 | for (i = 0; i < sals.nelts; i++) |
6072 | { | |
6073 | resolve_sal_pc (&sals.sals[i]); | |
6074 | ||
6075 | /* Reparse conditions, they might contain references to the | |
6076 | old symtab. */ | |
6077 | if (b->cond_string != NULL) | |
6078 | { | |
6079 | s = b->cond_string; | |
6080 | if (b->cond) | |
c5aa993b | 6081 | free ((PTR) b->cond); |
c906108c SS |
6082 | b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); |
6083 | } | |
6084 | ||
c5aa993b | 6085 | /* We need to re-set the breakpoint if the address changes... */ |
c906108c | 6086 | if (b->address != sals.sals[i].pc |
c5aa993b JM |
6087 | /* ...or new and old breakpoints both have source files, and |
6088 | the source file name or the line number changes... */ | |
c906108c SS |
6089 | || (b->source_file != NULL |
6090 | && sals.sals[i].symtab != NULL | |
6091 | && (!STREQ (b->source_file, sals.sals[i].symtab->filename) | |
6092 | || b->line_number != sals.sals[i].line) | |
c906108c | 6093 | ) |
c5aa993b JM |
6094 | /* ...or we switch between having a source file and not having |
6095 | one. */ | |
6096 | || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL)) | |
6097 | ) | |
c906108c SS |
6098 | { |
6099 | if (b->source_file != NULL) | |
6100 | free (b->source_file); | |
6101 | if (sals.sals[i].symtab == NULL) | |
6102 | b->source_file = NULL; | |
6103 | else | |
6104 | b->source_file = | |
6105 | savestring (sals.sals[i].symtab->filename, | |
6106 | strlen (sals.sals[i].symtab->filename)); | |
6107 | b->line_number = sals.sals[i].line; | |
6108 | b->address = sals.sals[i].pc; | |
6109 | ||
c5aa993b JM |
6110 | /* Used to check for duplicates here, but that can |
6111 | cause trouble, as it doesn't check for disable | |
6112 | breakpoints. */ | |
c906108c SS |
6113 | |
6114 | mention (b); | |
6115 | ||
6116 | /* Might be better to do this just once per breakpoint_re_set, | |
c5aa993b | 6117 | rather than once for every breakpoint. */ |
c906108c SS |
6118 | breakpoints_changed (); |
6119 | } | |
6120 | b->section = sals.sals[i].section; | |
6121 | b->enable = save_enable; /* Restore it, this worked. */ | |
6122 | ||
6123 | ||
c5aa993b | 6124 | /* Now that this is re-enabled, check_duplicates |
c906108c | 6125 | can be used. */ |
c5aa993b | 6126 | check_duplicates (b->address, b->section); |
c906108c SS |
6127 | |
6128 | } | |
c5aa993b | 6129 | free ((PTR) sals.sals); |
c906108c SS |
6130 | break; |
6131 | ||
6132 | case bp_watchpoint: | |
6133 | case bp_hardware_watchpoint: | |
6134 | case bp_read_watchpoint: | |
6135 | case bp_access_watchpoint: | |
6136 | innermost_block = NULL; | |
53a5351d JM |
6137 | /* The issue arises of what context to evaluate this in. The |
6138 | same one as when it was set, but what does that mean when | |
6139 | symbols have been re-read? We could save the filename and | |
6140 | functionname, but if the context is more local than that, the | |
6141 | best we could do would be something like how many levels deep | |
6142 | and which index at that particular level, but that's going to | |
6143 | be less stable than filenames or function names. */ | |
6144 | ||
c906108c SS |
6145 | /* So for now, just use a global context. */ |
6146 | if (b->exp) | |
c5aa993b | 6147 | free ((PTR) b->exp); |
c906108c SS |
6148 | b->exp = parse_expression (b->exp_string); |
6149 | b->exp_valid_block = innermost_block; | |
6150 | mark = value_mark (); | |
6151 | if (b->val) | |
6152 | value_free (b->val); | |
6153 | b->val = evaluate_expression (b->exp); | |
6154 | release_value (b->val); | |
6155 | if (VALUE_LAZY (b->val)) | |
6156 | value_fetch_lazy (b->val); | |
6157 | ||
6158 | if (b->cond_string != NULL) | |
6159 | { | |
6160 | s = b->cond_string; | |
6161 | if (b->cond) | |
c5aa993b JM |
6162 | free ((PTR) b->cond); |
6163 | b->cond = parse_exp_1 (&s, (struct block *) 0, 0); | |
c906108c SS |
6164 | } |
6165 | if (b->enable == enabled) | |
6166 | mention (b); | |
6167 | value_free_to_mark (mark); | |
6168 | break; | |
c5aa993b JM |
6169 | case bp_catch_catch: |
6170 | case bp_catch_throw: | |
c906108c | 6171 | break; |
c5aa993b JM |
6172 | /* We needn't really do anything to reset these, since the mask |
6173 | that requests them is unaffected by e.g., new libraries being | |
6174 | loaded. */ | |
c906108c SS |
6175 | case bp_catch_fork: |
6176 | case bp_catch_vfork: | |
6177 | case bp_catch_exec: | |
6178 | break; | |
c5aa993b | 6179 | |
c906108c SS |
6180 | default: |
6181 | printf_filtered ("Deleting unknown breakpoint type %d\n", b->type); | |
6182 | /* fall through */ | |
c5aa993b JM |
6183 | /* Delete longjmp breakpoints, they will be reset later by |
6184 | breakpoint_re_set. */ | |
c906108c SS |
6185 | case bp_longjmp: |
6186 | case bp_longjmp_resume: | |
6187 | delete_breakpoint (b); | |
6188 | break; | |
6189 | ||
c5aa993b JM |
6190 | /* This breakpoint is special, it's set up when the inferior |
6191 | starts and we really don't want to touch it. */ | |
c906108c SS |
6192 | case bp_shlib_event: |
6193 | ||
c5aa993b JM |
6194 | /* Keep temporary breakpoints, which can be encountered when we step |
6195 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
6196 | Otherwise these should have been blown away via the cleanup chain | |
6197 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
6198 | case bp_until: |
6199 | case bp_finish: | |
6200 | case bp_watchpoint_scope: | |
6201 | case bp_call_dummy: | |
6202 | case bp_step_resume: | |
6203 | break; | |
6204 | } | |
6205 | ||
6206 | return 0; | |
6207 | } | |
6208 | ||
6209 | /* Re-set all breakpoints after symbols have been re-loaded. */ | |
6210 | void | |
6211 | breakpoint_re_set () | |
6212 | { | |
6213 | struct breakpoint *b, *temp; | |
6214 | enum language save_language; | |
6215 | int save_input_radix; | |
6216 | static char message1[] = "Error in re-setting breakpoint %d:\n"; | |
c5aa993b JM |
6217 | char message[sizeof (message1) + 30 /* slop */ ]; |
6218 | ||
c906108c SS |
6219 | save_language = current_language->la_language; |
6220 | save_input_radix = input_radix; | |
6221 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 6222 | { |
53a5351d JM |
6223 | /* Format possible error msg */ |
6224 | sprintf (message, message1, b->number); | |
c5aa993b JM |
6225 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
6226 | } | |
c906108c SS |
6227 | set_language (save_language); |
6228 | input_radix = save_input_radix; | |
6229 | ||
6230 | #ifdef GET_LONGJMP_TARGET | |
6231 | create_longjmp_breakpoint ("longjmp"); | |
6232 | create_longjmp_breakpoint ("_longjmp"); | |
6233 | create_longjmp_breakpoint ("siglongjmp"); | |
6234 | create_longjmp_breakpoint ("_siglongjmp"); | |
6235 | create_longjmp_breakpoint (NULL); | |
6236 | #endif | |
6237 | ||
6238 | #if 0 | |
6239 | /* Took this out (temporarily at least), since it produces an extra | |
6240 | blank line at startup. This messes up the gdbtests. -PB */ | |
6241 | /* Blank line to finish off all those mention() messages we just printed. */ | |
6242 | printf_filtered ("\n"); | |
6243 | #endif | |
6244 | } | |
6245 | \f | |
6246 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. | |
6247 | If from_tty is nonzero, it prints a message to that effect, | |
6248 | which ends with a period (no newline). */ | |
6249 | ||
6250 | /* Reset the thread number of this breakpoint: | |
6251 | ||
6252 | - If the breakpoint is for all threads, leave it as-is. | |
6253 | - Else, reset it to the current thread for inferior_pid. */ | |
6254 | void | |
6255 | breakpoint_re_set_thread (b) | |
c5aa993b | 6256 | struct breakpoint *b; |
c906108c SS |
6257 | { |
6258 | if (b->thread != -1) | |
6259 | { | |
6260 | if (in_thread_list (inferior_pid)) | |
c5aa993b | 6261 | b->thread = pid_to_thread_id (inferior_pid); |
c906108c SS |
6262 | } |
6263 | } | |
6264 | ||
6265 | void | |
6266 | set_ignore_count (bptnum, count, from_tty) | |
6267 | int bptnum, count, from_tty; | |
6268 | { | |
6269 | register struct breakpoint *b; | |
6270 | ||
6271 | if (count < 0) | |
6272 | count = 0; | |
6273 | ||
6274 | ALL_BREAKPOINTS (b) | |
6275 | if (b->number == bptnum) | |
c5aa993b JM |
6276 | { |
6277 | b->ignore_count = count; | |
6278 | if (!from_tty) | |
c906108c | 6279 | return; |
c5aa993b JM |
6280 | else if (count == 0) |
6281 | printf_filtered ("Will stop next time breakpoint %d is reached.", | |
6282 | bptnum); | |
6283 | else if (count == 1) | |
6284 | printf_filtered ("Will ignore next crossing of breakpoint %d.", | |
6285 | bptnum); | |
6286 | else | |
6287 | printf_filtered ("Will ignore next %d crossings of breakpoint %d.", | |
6288 | count, bptnum); | |
6289 | breakpoints_changed (); | |
6290 | return; | |
6291 | } | |
c906108c SS |
6292 | |
6293 | error ("No breakpoint number %d.", bptnum); | |
6294 | } | |
6295 | ||
6296 | /* Clear the ignore counts of all breakpoints. */ | |
6297 | void | |
6298 | breakpoint_clear_ignore_counts () | |
6299 | { | |
6300 | struct breakpoint *b; | |
6301 | ||
6302 | ALL_BREAKPOINTS (b) | |
6303 | b->ignore_count = 0; | |
6304 | } | |
6305 | ||
6306 | /* Command to set ignore-count of breakpoint N to COUNT. */ | |
6307 | ||
6308 | static void | |
6309 | ignore_command (args, from_tty) | |
6310 | char *args; | |
6311 | int from_tty; | |
6312 | { | |
6313 | char *p = args; | |
6314 | register int num; | |
6315 | ||
6316 | if (p == 0) | |
6317 | error_no_arg ("a breakpoint number"); | |
c5aa993b | 6318 | |
c906108c SS |
6319 | num = get_number (&p); |
6320 | ||
6321 | if (*p == 0) | |
6322 | error ("Second argument (specified ignore-count) is missing."); | |
6323 | ||
6324 | set_ignore_count (num, | |
6325 | longest_to_int (value_as_long (parse_and_eval (p))), | |
6326 | from_tty); | |
6327 | printf_filtered ("\n"); | |
6328 | breakpoints_changed (); | |
6329 | } | |
6330 | \f | |
6331 | /* Call FUNCTION on each of the breakpoints | |
6332 | whose numbers are given in ARGS. */ | |
6333 | ||
6334 | static void | |
6335 | map_breakpoint_numbers (args, function) | |
6336 | char *args; | |
6337 | void (*function) PARAMS ((struct breakpoint *)); | |
6338 | { | |
6339 | register char *p = args; | |
6340 | char *p1; | |
6341 | register int num; | |
6342 | register struct breakpoint *b; | |
6343 | ||
6344 | if (p == 0) | |
6345 | error_no_arg ("one or more breakpoint numbers"); | |
6346 | ||
6347 | while (*p) | |
6348 | { | |
6349 | p1 = p; | |
c5aa993b | 6350 | |
c906108c SS |
6351 | num = get_number (&p1); |
6352 | ||
6353 | ALL_BREAKPOINTS (b) | |
6354 | if (b->number == num) | |
c5aa993b JM |
6355 | { |
6356 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
6357 | function (b); | |
6358 | if (related_breakpoint) | |
6359 | function (related_breakpoint); | |
6360 | goto win; | |
6361 | } | |
c906108c SS |
6362 | printf_unfiltered ("No breakpoint number %d.\n", num); |
6363 | win: | |
6364 | p = p1; | |
6365 | } | |
6366 | } | |
6367 | ||
6368 | void | |
6369 | disable_breakpoint (bpt) | |
6370 | struct breakpoint *bpt; | |
6371 | { | |
6372 | /* Never disable a watchpoint scope breakpoint; we want to | |
6373 | hit them when we leave scope so we can delete both the | |
6374 | watchpoint and its scope breakpoint at that time. */ | |
6375 | if (bpt->type == bp_watchpoint_scope) | |
6376 | return; | |
6377 | ||
6378 | bpt->enable = disabled; | |
6379 | ||
6380 | check_duplicates (bpt->address, bpt->section); | |
6381 | ||
6382 | if (modify_breakpoint_hook) | |
6383 | modify_breakpoint_hook (bpt); | |
6384 | } | |
6385 | ||
6386 | /* ARGSUSED */ | |
6387 | static void | |
6388 | disable_command (args, from_tty) | |
6389 | char *args; | |
6390 | int from_tty; | |
6391 | { | |
6392 | register struct breakpoint *bpt; | |
6393 | if (args == 0) | |
6394 | ALL_BREAKPOINTS (bpt) | |
6395 | switch (bpt->type) | |
c5aa993b JM |
6396 | { |
6397 | case bp_none: | |
53a5351d JM |
6398 | warning ("attempted to disable apparently deleted breakpoint #%d?", |
6399 | bpt->number); | |
c5aa993b JM |
6400 | continue; |
6401 | case bp_breakpoint: | |
6402 | case bp_catch_load: | |
6403 | case bp_catch_unload: | |
6404 | case bp_catch_fork: | |
6405 | case bp_catch_vfork: | |
6406 | case bp_catch_exec: | |
6407 | case bp_catch_catch: | |
6408 | case bp_catch_throw: | |
6409 | case bp_hardware_breakpoint: | |
6410 | case bp_watchpoint: | |
6411 | case bp_hardware_watchpoint: | |
6412 | case bp_read_watchpoint: | |
6413 | case bp_access_watchpoint: | |
6414 | disable_breakpoint (bpt); | |
6415 | default: | |
6416 | continue; | |
6417 | } | |
c906108c SS |
6418 | else |
6419 | map_breakpoint_numbers (args, disable_breakpoint); | |
6420 | } | |
6421 | ||
6422 | static void | |
6423 | do_enable_breakpoint (bpt, disposition) | |
6424 | struct breakpoint *bpt; | |
6425 | enum bpdisp disposition; | |
6426 | { | |
6427 | struct frame_info *save_selected_frame = NULL; | |
6428 | int save_selected_frame_level = -1; | |
6429 | int target_resources_ok, other_type_used; | |
6430 | struct value *mark; | |
6431 | ||
6432 | if (bpt->type == bp_hardware_breakpoint) | |
6433 | { | |
6434 | int i; | |
c5aa993b | 6435 | i = hw_breakpoint_used_count (); |
53a5351d JM |
6436 | target_resources_ok = |
6437 | TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, | |
6438 | i + 1, 0); | |
c906108c | 6439 | if (target_resources_ok == 0) |
c5aa993b | 6440 | error ("No hardware breakpoint support in the target."); |
c906108c | 6441 | else if (target_resources_ok < 0) |
c5aa993b | 6442 | error ("Hardware breakpoints used exceeds limit."); |
c906108c SS |
6443 | } |
6444 | ||
6445 | bpt->enable = enabled; | |
6446 | bpt->disposition = disposition; | |
6447 | check_duplicates (bpt->address, bpt->section); | |
6448 | breakpoints_changed (); | |
6449 | ||
53a5351d JM |
6450 | if (bpt->type == bp_watchpoint || |
6451 | bpt->type == bp_hardware_watchpoint || | |
6452 | bpt->type == bp_read_watchpoint || | |
6453 | bpt->type == bp_access_watchpoint) | |
c906108c SS |
6454 | { |
6455 | if (bpt->exp_valid_block != NULL) | |
6456 | { | |
6457 | struct frame_info *fr = | |
6458 | ||
c5aa993b JM |
6459 | /* Ensure that we have the current frame. Else, this |
6460 | next query may pessimistically be answered as, "No, | |
6461 | not within current scope". */ | |
6462 | get_current_frame (); | |
6463 | fr = find_frame_addr_in_frame_chain (bpt->watchpoint_frame); | |
c906108c SS |
6464 | if (fr == NULL) |
6465 | { | |
6466 | printf_filtered ("\ | |
6467 | Cannot enable watchpoint %d because the block in which its expression\n\ | |
6468 | is valid is not currently in scope.\n", bpt->number); | |
6469 | bpt->enable = disabled; | |
6470 | return; | |
6471 | } | |
6472 | ||
6473 | save_selected_frame = selected_frame; | |
6474 | save_selected_frame_level = selected_frame_level; | |
6475 | select_frame (fr, -1); | |
6476 | } | |
6477 | ||
6478 | value_free (bpt->val); | |
6479 | mark = value_mark (); | |
6480 | bpt->val = evaluate_expression (bpt->exp); | |
6481 | release_value (bpt->val); | |
6482 | if (VALUE_LAZY (bpt->val)) | |
6483 | value_fetch_lazy (bpt->val); | |
6484 | ||
6485 | if (bpt->type == bp_hardware_watchpoint || | |
c5aa993b JM |
6486 | bpt->type == bp_read_watchpoint || |
6487 | bpt->type == bp_access_watchpoint) | |
6488 | { | |
6489 | int i = hw_watchpoint_used_count (bpt->type, &other_type_used); | |
6490 | int mem_cnt = can_use_hardware_watchpoint (bpt->val); | |
6491 | ||
6492 | /* Hack around 'unused var' error for some targets here */ | |
6493 | (void) mem_cnt, i; | |
6494 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT ( | |
6495 | bpt->type, i + mem_cnt, other_type_used); | |
6496 | /* we can consider of type is bp_hardware_watchpoint, convert to | |
6497 | bp_watchpoint in the following condition */ | |
6498 | if (target_resources_ok < 0) | |
6499 | { | |
6500 | printf_filtered ("\ | |
c906108c SS |
6501 | Cannot enable watchpoint %d because target watch resources\n\ |
6502 | have been allocated for other watchpoints.\n", bpt->number); | |
c5aa993b JM |
6503 | bpt->enable = disabled; |
6504 | value_free_to_mark (mark); | |
6505 | return; | |
6506 | } | |
6507 | } | |
c906108c SS |
6508 | |
6509 | if (save_selected_frame_level >= 0) | |
53a5351d JM |
6510 | select_and_print_frame (save_selected_frame, |
6511 | save_selected_frame_level); | |
c906108c SS |
6512 | value_free_to_mark (mark); |
6513 | } | |
6514 | if (modify_breakpoint_hook) | |
6515 | modify_breakpoint_hook (bpt); | |
6516 | } | |
6517 | ||
6518 | void | |
6519 | enable_breakpoint (bpt) | |
6520 | struct breakpoint *bpt; | |
6521 | { | |
6522 | do_enable_breakpoint (bpt, bpt->disposition); | |
6523 | } | |
6524 | ||
6525 | /* The enable command enables the specified breakpoints (or all defined | |
6526 | breakpoints) so they once again become (or continue to be) effective | |
6527 | in stopping the inferior. */ | |
6528 | ||
6529 | /* ARGSUSED */ | |
6530 | static void | |
6531 | enable_command (args, from_tty) | |
6532 | char *args; | |
6533 | int from_tty; | |
6534 | { | |
6535 | register struct breakpoint *bpt; | |
6536 | if (args == 0) | |
6537 | ALL_BREAKPOINTS (bpt) | |
6538 | switch (bpt->type) | |
c5aa993b JM |
6539 | { |
6540 | case bp_none: | |
53a5351d JM |
6541 | warning ("attempted to enable apparently deleted breakpoint #%d?", |
6542 | bpt->number); | |
c5aa993b JM |
6543 | continue; |
6544 | case bp_breakpoint: | |
6545 | case bp_catch_load: | |
6546 | case bp_catch_unload: | |
6547 | case bp_catch_fork: | |
6548 | case bp_catch_vfork: | |
6549 | case bp_catch_exec: | |
6550 | case bp_catch_catch: | |
6551 | case bp_catch_throw: | |
6552 | case bp_hardware_breakpoint: | |
6553 | case bp_watchpoint: | |
6554 | case bp_hardware_watchpoint: | |
6555 | case bp_read_watchpoint: | |
6556 | case bp_access_watchpoint: | |
6557 | enable_breakpoint (bpt); | |
6558 | default: | |
6559 | continue; | |
6560 | } | |
c906108c SS |
6561 | else |
6562 | map_breakpoint_numbers (args, enable_breakpoint); | |
6563 | } | |
6564 | ||
6565 | static void | |
6566 | enable_once_breakpoint (bpt) | |
6567 | struct breakpoint *bpt; | |
6568 | { | |
6569 | do_enable_breakpoint (bpt, disable); | |
6570 | } | |
6571 | ||
6572 | /* ARGSUSED */ | |
6573 | static void | |
6574 | enable_once_command (args, from_tty) | |
6575 | char *args; | |
6576 | int from_tty; | |
6577 | { | |
6578 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
6579 | } | |
6580 | ||
6581 | static void | |
6582 | enable_delete_breakpoint (bpt) | |
6583 | struct breakpoint *bpt; | |
6584 | { | |
6585 | do_enable_breakpoint (bpt, del); | |
6586 | } | |
6587 | ||
6588 | /* ARGSUSED */ | |
6589 | static void | |
6590 | enable_delete_command (args, from_tty) | |
6591 | char *args; | |
6592 | int from_tty; | |
6593 | { | |
6594 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
6595 | } | |
6596 | \f | |
6597 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ | |
6598 | ||
6599 | struct symtabs_and_lines | |
6600 | decode_line_spec_1 (string, funfirstline) | |
6601 | char *string; | |
6602 | int funfirstline; | |
6603 | { | |
6604 | struct symtabs_and_lines sals; | |
6605 | if (string == 0) | |
6606 | error ("Empty line specification."); | |
6607 | if (default_breakpoint_valid) | |
6608 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
6609 | default_breakpoint_symtab, |
6610 | default_breakpoint_line, | |
c5aa993b | 6611 | (char ***) NULL); |
c906108c SS |
6612 | else |
6613 | sals = decode_line_1 (&string, funfirstline, | |
c5aa993b | 6614 | (struct symtab *) NULL, 0, (char ***) NULL); |
c906108c SS |
6615 | if (*string) |
6616 | error ("Junk at end of line specification: %s", string); | |
6617 | return sals; | |
6618 | } | |
6619 | \f | |
6620 | void | |
6621 | _initialize_breakpoint () | |
6622 | { | |
6623 | struct cmd_list_element *c; | |
6624 | ||
6625 | breakpoint_chain = 0; | |
6626 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
6627 | before a breakpoint is set. */ | |
6628 | breakpoint_count = 0; | |
6629 | ||
6630 | add_com ("ignore", class_breakpoint, ignore_command, | |
6631 | "Set ignore-count of breakpoint number N to COUNT.\n\ | |
6632 | Usage is `ignore N COUNT'."); | |
6633 | if (xdb_commands) | |
c5aa993b | 6634 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c SS |
6635 | |
6636 | add_com ("commands", class_breakpoint, commands_command, | |
6637 | "Set commands to be executed when a breakpoint is hit.\n\ | |
6638 | Give breakpoint number as argument after \"commands\".\n\ | |
6639 | With no argument, the targeted breakpoint is the last one set.\n\ | |
6640 | The commands themselves follow starting on the next line.\n\ | |
6641 | Type a line containing \"end\" to indicate the end of them.\n\ | |
6642 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
6643 | then no output is printed when it is hit, except what the commands print."); | |
6644 | ||
6645 | add_com ("condition", class_breakpoint, condition_command, | |
6646 | "Specify breakpoint number N to break only if COND is true.\n\ | |
6647 | Usage is `condition N COND', where N is an integer and COND is an\n\ | |
6648 | expression to be evaluated whenever breakpoint N is reached. "); | |
6649 | ||
6650 | add_com ("tbreak", class_breakpoint, tbreak_command, | |
6651 | "Set a temporary breakpoint. Args like \"break\" command.\n\ | |
6652 | Like \"break\" except the breakpoint is only temporary,\n\ | |
6653 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
6654 | by using \"enable delete\" on the breakpoint number."); | |
c5aa993b JM |
6655 | add_com ("txbreak", class_breakpoint, tbreak_at_finish_command, |
6656 | "Set temporary breakpoint at procedure exit. Either there should\n\ | |
c906108c SS |
6657 | be no argument or the argument must be a depth.\n"); |
6658 | ||
6659 | add_com ("hbreak", class_breakpoint, hbreak_command, | |
6660 | "Set a hardware assisted breakpoint. Args like \"break\" command.\n\ | |
6661 | Like \"break\" except the breakpoint requires hardware support,\n\ | |
6662 | some target hardware may not have this support."); | |
6663 | ||
6664 | add_com ("thbreak", class_breakpoint, thbreak_command, | |
6665 | "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\ | |
6666 | Like \"hbreak\" except the breakpoint is only temporary,\n\ | |
6667 | so it will be deleted when hit."); | |
6668 | ||
6669 | add_prefix_cmd ("enable", class_breakpoint, enable_command, | |
6670 | "Enable some breakpoints.\n\ | |
6671 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
6672 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
6673 | This is used to cancel the effect of the \"disable\" command.\n\ | |
6674 | With a subcommand you can enable temporarily.", | |
6675 | &enablelist, "enable ", 1, &cmdlist); | |
6676 | if (xdb_commands) | |
c5aa993b JM |
6677 | add_com ("ab", class_breakpoint, enable_command, |
6678 | "Enable some breakpoints.\n\ | |
c906108c SS |
6679 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
6680 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
6681 | This is used to cancel the effect of the \"disable\" command.\n\ | |
6682 | With a subcommand you can enable temporarily."); | |
6683 | ||
6684 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
6685 | ||
6686 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, | |
c5aa993b | 6687 | "Enable some breakpoints.\n\ |
c906108c SS |
6688 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
6689 | This is used to cancel the effect of the \"disable\" command.\n\ | |
6690 | May be abbreviated to simply \"enable\".\n", | |
c5aa993b | 6691 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c SS |
6692 | |
6693 | add_cmd ("once", no_class, enable_once_command, | |
6694 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
6695 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", | |
6696 | &enablebreaklist); | |
6697 | ||
6698 | add_cmd ("delete", no_class, enable_delete_command, | |
6699 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
6700 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
6701 | &enablebreaklist); | |
6702 | ||
6703 | add_cmd ("delete", no_class, enable_delete_command, | |
6704 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
6705 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
6706 | &enablelist); | |
6707 | ||
6708 | add_cmd ("once", no_class, enable_once_command, | |
6709 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
6710 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", | |
6711 | &enablelist); | |
6712 | ||
6713 | add_prefix_cmd ("disable", class_breakpoint, disable_command, | |
c5aa993b | 6714 | "Disable some breakpoints.\n\ |
c906108c SS |
6715 | Arguments are breakpoint numbers with spaces in between.\n\ |
6716 | To disable all breakpoints, give no argument.\n\ | |
6717 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", | |
6718 | &disablelist, "disable ", 1, &cmdlist); | |
6719 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
6720 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
6721 | if (xdb_commands) | |
c5aa993b JM |
6722 | add_com ("sb", class_breakpoint, disable_command, |
6723 | "Disable some breakpoints.\n\ | |
c906108c SS |
6724 | Arguments are breakpoint numbers with spaces in between.\n\ |
6725 | To disable all breakpoints, give no argument.\n\ | |
6726 | A disabled breakpoint is not forgotten, but has no effect until reenabled."); | |
6727 | ||
6728 | add_cmd ("breakpoints", class_alias, disable_command, | |
6729 | "Disable some breakpoints.\n\ | |
6730 | Arguments are breakpoint numbers with spaces in between.\n\ | |
6731 | To disable all breakpoints, give no argument.\n\ | |
6732 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
6733 | This command may be abbreviated \"disable\".", | |
6734 | &disablelist); | |
6735 | ||
6736 | add_prefix_cmd ("delete", class_breakpoint, delete_command, | |
c5aa993b | 6737 | "Delete some breakpoints or auto-display expressions.\n\ |
c906108c SS |
6738 | Arguments are breakpoint numbers with spaces in between.\n\ |
6739 | To delete all breakpoints, give no argument.\n\ | |
6740 | \n\ | |
6741 | Also a prefix command for deletion of other GDB objects.\n\ | |
6742 | The \"unset\" command is also an alias for \"delete\".", | |
6743 | &deletelist, "delete ", 1, &cmdlist); | |
6744 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
6745 | if (xdb_commands) | |
6746 | add_com ("db", class_breakpoint, delete_command, | |
c5aa993b | 6747 | "Delete some breakpoints.\n\ |
c906108c SS |
6748 | Arguments are breakpoint numbers with spaces in between.\n\ |
6749 | To delete all breakpoints, give no argument.\n"); | |
6750 | ||
6751 | add_cmd ("breakpoints", class_alias, delete_command, | |
6752 | "Delete some breakpoints or auto-display expressions.\n\ | |
6753 | Arguments are breakpoint numbers with spaces in between.\n\ | |
6754 | To delete all breakpoints, give no argument.\n\ | |
6755 | This command may be abbreviated \"delete\".", | |
6756 | &deletelist); | |
6757 | ||
6758 | add_com ("clear", class_breakpoint, clear_command, | |
6759 | concat ("Clear breakpoint at specified line or function.\n\ | |
6760 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
6761 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
6762 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
6763 | If an address is specified, breakpoints at that address are cleared.\n\n", | |
c5aa993b | 6764 | "With no argument, clears all breakpoints in the line that the selected frame\n\ |
c906108c SS |
6765 | is executing in.\n\ |
6766 | \n\ | |
6767 | See also the \"delete\" command which clears breakpoints by number.", NULL)); | |
6768 | ||
6769 | add_com ("break", class_breakpoint, break_command, | |
6770 | concat ("Set breakpoint at specified line or function.\n\ | |
6771 | Argument may be line number, function name, or \"*\" and an address.\n\ | |
6772 | If line number is specified, break at start of code for that line.\n\ | |
6773 | If function is specified, break at start of code for that function.\n\ | |
6774 | If an address is specified, break at that exact address.\n", | |
c5aa993b | 6775 | "With no arg, uses current execution address of selected stack frame.\n\ |
c906108c SS |
6776 | This is useful for breaking on return to a stack frame.\n\ |
6777 | \n\ | |
6778 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
6779 | \n\ | |
6780 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)); | |
6781 | add_com_alias ("b", "break", class_run, 1); | |
6782 | add_com_alias ("br", "break", class_run, 1); | |
6783 | add_com_alias ("bre", "break", class_run, 1); | |
6784 | add_com_alias ("brea", "break", class_run, 1); | |
6785 | ||
c5aa993b JM |
6786 | add_com ("xbreak", class_breakpoint, break_at_finish_command, |
6787 | concat ("Set breakpoint at procedure exit. \n\ | |
c906108c SS |
6788 | Argument may be function name, or \"*\" and an address.\n\ |
6789 | If function is specified, break at end of code for that function.\n\ | |
6790 | If an address is specified, break at the end of the function that contains \n\ | |
6791 | that exact address.\n", | |
c5aa993b | 6792 | "With no arg, uses current execution address of selected stack frame.\n\ |
c906108c SS |
6793 | This is useful for breaking on return to a stack frame.\n\ |
6794 | \n\ | |
6795 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
6796 | \n\ | |
6797 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)); | |
6798 | add_com_alias ("xb", "xbreak", class_breakpoint, 1); | |
6799 | add_com_alias ("xbr", "xbreak", class_breakpoint, 1); | |
6800 | add_com_alias ("xbre", "xbreak", class_breakpoint, 1); | |
6801 | add_com_alias ("xbrea", "xbreak", class_breakpoint, 1); | |
6802 | ||
6803 | if (xdb_commands) | |
6804 | { | |
6805 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
6806 | add_com_alias ("bu", "ubreak", class_breakpoint, 1); | |
6807 | add_com ("bx", class_breakpoint, break_at_finish_at_depth_command, | |
c5aa993b | 6808 | "Set breakpoint at procedure exit. Either there should\n\ |
c906108c SS |
6809 | be no argument or the argument must be a depth.\n"); |
6810 | } | |
6811 | ||
6812 | if (dbx_commands) | |
6813 | { | |
c5aa993b JM |
6814 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, |
6815 | "Break in function/address or break at a line in the current file.", | |
6816 | &stoplist, "stop ", 1, &cmdlist); | |
6817 | add_cmd ("in", class_breakpoint, stopin_command, | |
6818 | "Break in function or address.\n", &stoplist); | |
6819 | add_cmd ("at", class_breakpoint, stopat_command, | |
6820 | "Break at a line in the current file.\n", &stoplist); | |
6821 | add_com ("status", class_info, breakpoints_info, | |
6822 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
6823 | The \"Type\" column indicates one of:\n\ |
6824 | \tbreakpoint - normal breakpoint\n\ | |
6825 | \twatchpoint - watchpoint\n\ | |
6826 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
6827 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
6828 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
6829 | address and file/line number respectively.\n\n", | |
c5aa993b | 6830 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
6831 | are set to the address of the last breakpoint listed.\n\n\ |
6832 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
6833 | breakpoint set.", NULL)); | |
6834 | } | |
6835 | ||
6836 | add_info ("breakpoints", breakpoints_info, | |
6837 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
6838 | The \"Type\" column indicates one of:\n\ | |
6839 | \tbreakpoint - normal breakpoint\n\ | |
6840 | \twatchpoint - watchpoint\n\ | |
6841 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
6842 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
6843 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
6844 | address and file/line number respectively.\n\n", | |
c5aa993b | 6845 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
6846 | are set to the address of the last breakpoint listed.\n\n\ |
6847 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
6848 | breakpoint set.", NULL)); | |
6849 | ||
6850 | if (xdb_commands) | |
c5aa993b JM |
6851 | add_com ("lb", class_breakpoint, breakpoints_info, |
6852 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
6853 | The \"Type\" column indicates one of:\n\ |
6854 | \tbreakpoint - normal breakpoint\n\ | |
6855 | \twatchpoint - watchpoint\n\ | |
6856 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
6857 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
6858 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
6859 | address and file/line number respectively.\n\n", | |
c5aa993b | 6860 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
6861 | are set to the address of the last breakpoint listed.\n\n\ |
6862 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
6863 | breakpoint set.", NULL)); | |
6864 | ||
c906108c | 6865 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, |
c5aa993b | 6866 | concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
6867 | The \"Type\" column indicates one of:\n\ |
6868 | \tbreakpoint - normal breakpoint\n\ | |
6869 | \twatchpoint - watchpoint\n\ | |
6870 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
6871 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
6872 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
6873 | \tfinish - internal breakpoint used by the \"finish\" command\n", | |
c5aa993b | 6874 | "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
c906108c SS |
6875 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
6876 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
6877 | address and file/line number respectively.\n\n", | |
c5aa993b | 6878 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
c906108c SS |
6879 | are set to the address of the last breakpoint listed.\n\n\ |
6880 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
6881 | breakpoint set.", NULL), | |
6882 | &maintenanceinfolist); | |
6883 | ||
c906108c | 6884 | add_com ("catch", class_breakpoint, catch_command, |
c5aa993b | 6885 | "Set catchpoints to catch events.\n\ |
c906108c SS |
6886 | Raised signals may be caught:\n\ |
6887 | \tcatch signal - all signals\n\ | |
6888 | \tcatch signal <signame> - a particular signal\n\ | |
6889 | Raised exceptions may be caught:\n\ | |
6890 | \tcatch throw - all exceptions, when thrown\n\ | |
6891 | \tcatch throw <exceptname> - a particular exception, when thrown\n\ | |
6892 | \tcatch catch - all exceptions, when caught\n\ | |
6893 | \tcatch catch <exceptname> - a particular exception, when caught\n\ | |
6894 | Thread or process events may be caught:\n\ | |
6895 | \tcatch thread_start - any threads, just after creation\n\ | |
6896 | \tcatch thread_exit - any threads, just before expiration\n\ | |
6897 | \tcatch thread_join - any threads, just after joins\n\ | |
6898 | Process events may be caught:\n\ | |
6899 | \tcatch start - any processes, just after creation\n\ | |
6900 | \tcatch exit - any processes, just before expiration\n\ | |
6901 | \tcatch fork - calls to fork()\n\ | |
6902 | \tcatch vfork - calls to vfork()\n\ | |
6903 | \tcatch exec - calls to exec()\n\ | |
6904 | Dynamically-linked library events may be caught:\n\ | |
6905 | \tcatch load - loads of any library\n\ | |
6906 | \tcatch load <libname> - loads of a particular library\n\ | |
6907 | \tcatch unload - unloads of any library\n\ | |
6908 | \tcatch unload <libname> - unloads of a particular library\n\ | |
6909 | The act of your program's execution stopping may also be caught:\n\ | |
6910 | \tcatch stop\n\n\ | |
6911 | C++ exceptions may be caught:\n\ | |
6912 | \tcatch throw - all exceptions, when thrown\n\ | |
6913 | \tcatch catch - all exceptions, when caught\n\ | |
6914 | \n\ | |
6915 | Do \"help set follow-fork-mode\" for info on debugging your program\n\ | |
6916 | after a fork or vfork is caught.\n\n\ | |
6917 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
c5aa993b | 6918 | |
c906108c | 6919 | add_com ("tcatch", class_breakpoint, tcatch_command, |
c5aa993b | 6920 | "Set temporary catchpoints to catch events.\n\ |
c906108c SS |
6921 | Args like \"catch\" command.\n\ |
6922 | Like \"catch\" except the catchpoint is only temporary,\n\ | |
6923 | so it will be deleted when hit. Equivalent to \"catch\" followed\n\ | |
6924 | by using \"enable delete\" on the catchpoint number."); | |
c5aa993b JM |
6925 | |
6926 | add_com ("watch", class_breakpoint, watch_command, | |
c906108c SS |
6927 | "Set a watchpoint for an expression.\n\ |
6928 | A watchpoint stops execution of your program whenever the value of\n\ | |
6929 | an expression changes."); | |
6930 | ||
6931 | add_com ("rwatch", class_breakpoint, rwatch_command, | |
6932 | "Set a read watchpoint for an expression.\n\ | |
6933 | A watchpoint stops execution of your program whenever the value of\n\ | |
6934 | an expression is read."); | |
6935 | ||
6936 | add_com ("awatch", class_breakpoint, awatch_command, | |
6937 | "Set a watchpoint for an expression.\n\ | |
6938 | A watchpoint stops execution of your program whenever the value of\n\ | |
6939 | an expression is either read or written."); | |
6940 | ||
6941 | add_info ("watchpoints", breakpoints_info, | |
6942 | "Synonym for ``info breakpoints''."); | |
6943 | ||
6944 | ||
6945 | c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger, | |
c5aa993b JM |
6946 | (char *) &can_use_hw_watchpoints, |
6947 | "Set debugger's willingness to use watchpoint hardware.\n\ | |
c906108c SS |
6948 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
6949 | such is available. (However, any hardware watchpoints that were\n\ | |
6950 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
6951 | hardware.)", | |
c5aa993b | 6952 | &setlist); |
c906108c SS |
6953 | add_show_from_set (c, &showlist); |
6954 | ||
6955 | can_use_hw_watchpoints = 1; | |
6956 | } |