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