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