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