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