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