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