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