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