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