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