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