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