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