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