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