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