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