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