import gdb-19990422 snapshot
[platform/upstream/binutils.git] / gdb / breakpoint.h
1 /* Data structures associated with breakpoints in GDB.
2    Copyright (C) 1992, 93, 94, 95, 96, 98, 1999 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 #if !defined (BREAKPOINT_H)
21 #define BREAKPOINT_H 1
22
23 #include "frame.h"
24 #include "value.h"
25
26 /* This is the maximum number of bytes a breakpoint instruction can take.
27    Feel free to increase it.  It's just used in a few places to size
28    arrays that should be independent of the target architecture.  */
29
30 #define BREAKPOINT_MAX  16
31 \f
32 /* Type of breakpoint. */
33 /* FIXME In the future, we should fold all other breakpoint-like things into
34    here.  This includes:
35
36    * single-step (for machines where we have to simulate single stepping)
37       (probably, though perhaps it is better for it to look as much as
38       possible like a single-step to wait_for_inferior).  */
39
40 enum bptype {
41   bp_none = 0,                  /* Eventpoint has been deleted. */
42   bp_breakpoint,                /* Normal breakpoint */
43   bp_hardware_breakpoint,       /* Hardware assisted breakpoint */
44   bp_until,                     /* used by until command */
45   bp_finish,                    /* used by finish command */
46   bp_watchpoint,                /* Watchpoint */
47   bp_hardware_watchpoint,       /* Hardware assisted watchpoint */
48   bp_read_watchpoint,           /* read watchpoint, (hardware assisted) */
49   bp_access_watchpoint,         /* access watchpoint, (hardware assisted) */
50   bp_longjmp,                   /* secret breakpoint to find longjmp() */
51   bp_longjmp_resume,            /* secret breakpoint to escape longjmp() */
52
53   /* Used by wait_for_inferior for stepping over subroutine calls, for
54      stepping over signal handlers, and for skipping prologues.  */
55   bp_step_resume,
56
57   /* Used by wait_for_inferior for stepping over signal handlers.  */
58   bp_through_sigtramp,
59
60   /* Used to detect when a watchpoint expression has gone out of
61      scope.  These breakpoints are usually not visible to the user.
62
63      This breakpoint has some interesting properties:
64
65        1) There's always a 1:1 mapping between watchpoints
66        on local variables and watchpoint_scope breakpoints.
67
68        2) It automatically deletes itself and the watchpoint it's
69        associated with when hit.
70
71        3) It can never be disabled.  */
72   bp_watchpoint_scope,
73
74   /* The breakpoint at the end of a call dummy.  */
75   /* FIXME: What if the function we are calling longjmp()s out of the
76      call, or the user gets out with the "return" command?  We currently
77      have no way of cleaning up the breakpoint in these (obscure) situations.
78      (Probably can solve this by noticing longjmp, "return", etc., it's
79      similar to noticing when a watchpoint on a local variable goes out
80      of scope (with hardware support for watchpoints)).  */
81   bp_call_dummy,
82
83   /* Some dynamic linkers (HP, maybe Solaris) can arrange for special
84      code in the inferior to run when significant events occur in the
85      dynamic linker (for example a library is loaded or unloaded).
86
87      By placing a breakpoint in this magic code GDB will get control
88      when these significant events occur.  GDB can then re-examine
89      the dynamic linker's data structures to discover any newly loaded
90      dynamic libraries.  */
91   bp_shlib_event,
92  
93   /* These breakpoints are used to implement the "catch load" command
94      on platforms whose dynamic linkers support such functionality.  */
95   bp_catch_load,
96  
97   /* These breakpoints are used to implement the "catch unload" command
98      on platforms whose dynamic linkers support such functionality.  */
99   bp_catch_unload,
100  
101   /* These are not really breakpoints, but are catchpoints that
102      implement the "catch fork", "catch vfork" and "catch exec" commands
103      on platforms whose kernel support such functionality.  (I.e.,
104      kernels which can raise an event when a fork or exec occurs, as
105      opposed to the debugger setting breakpoints on functions named
106      "fork" or "exec".) */
107   bp_catch_fork,
108   bp_catch_vfork,
109   bp_catch_exec,
110
111   /* These are catchpoints to implement "catch catch" and "catch throw"
112      commands for C++ exception handling. */
113   bp_catch_catch,
114   bp_catch_throw
115
116  
117 };
118
119 /* States of enablement of breakpoint. */
120
121 enum enable { 
122   disabled,           /* The eventpoint is inactive, and cannot trigger. */
123   enabled,            /* The eventpoint is active, and can trigger. */
124   shlib_disabled,     /* The eventpoint's address is within an unloaded solib.
125                          The eventpoint will be automatically enabled & reset
126                          when that solib is loaded. */
127   call_disabled       /* The eventpoint has been disabled while a call into
128                          the inferior is "in flight", because some eventpoints
129                          interfere with the implementation of a call on some
130                          targets.  The eventpoint will be automatically enabled
131                          & reset when the call "lands" (either completes, or
132                          stops at another eventpoint). */
133 };
134
135
136 /* Disposition of breakpoint.  Ie: what to do after hitting it. */
137
138 enum bpdisp {
139   del,                          /* Delete it */
140   del_at_next_stop,             /* Delete at next stop, whether hit or not */
141   disable,                      /* Disable it */
142   donttouch                     /* Leave it alone */
143 };
144
145 /* Note that the ->silent field is not currently used by any commands
146    (though the code is in there if it was to be, and set_raw_breakpoint
147    does set it to 0).  I implemented it because I thought it would be
148    useful for a hack I had to put in; I'm going to leave it in because
149    I can see how there might be times when it would indeed be useful */
150
151 /* This is for a breakpoint or a watchpoint.  */
152
153 struct breakpoint
154 {
155   struct breakpoint *next;
156   /* Type of breakpoint. */
157   enum bptype type;
158   /* Zero means disabled; remember the info but don't break here.  */
159   enum enable enable;
160   /* What to do with this breakpoint after we hit it. */
161   enum bpdisp disposition;
162   /* Number assigned to distinguish breakpoints.  */
163   int number;
164
165   /* Address to break at, or NULL if not a breakpoint.  */
166   CORE_ADDR address;
167
168   /* Line number of this address.  Only matters if address is
169      non-NULL.  */
170
171   int line_number;
172
173   /* Source file name of this address.  Only matters if address is
174      non-NULL.  */
175
176   char *source_file;
177
178   /* Non-zero means a silent breakpoint (don't print frame info
179      if we stop here). */
180   unsigned char silent;
181   /* Number of stops at this breakpoint that should
182      be continued automatically before really stopping.  */
183   int ignore_count;
184   /* "Real" contents of byte where breakpoint has been inserted.
185      Valid only when breakpoints are in the program.  Under the complete
186      control of the target insert_breakpoint and remove_breakpoint routines.
187      No other code should assume anything about the value(s) here.  */
188   char shadow_contents[BREAKPOINT_MAX];
189   /* Nonzero if this breakpoint is now inserted.  Only matters if address
190      is non-NULL.  */
191   char inserted;
192   /* Nonzero if this is not the first breakpoint in the list
193      for the given address.  Only matters if address is non-NULL.  */
194   char duplicate;
195   /* Chain of command lines to execute when this breakpoint is hit.  */
196   struct command_line *commands;
197   /* Stack depth (address of frame).  If nonzero, break only if fp
198      equals this.  */
199   CORE_ADDR frame;
200   /* Conditional.  Break only if this expression's value is nonzero.  */
201   struct expression *cond;
202
203   /* String we used to set the breakpoint (malloc'd).  Only matters if
204      address is non-NULL.  */
205   char *addr_string;
206   /* Language we used to set the breakpoint.  */
207   enum language language;
208   /* Input radix we used to set the breakpoint.  */
209   int input_radix;
210   /* String form of the breakpoint condition (malloc'd), or NULL if there
211      is no condition.  */
212   char *cond_string;
213   /* String form of exp (malloc'd), or NULL if none.  */
214   char *exp_string;
215
216   /* The expression we are watching, or NULL if not a watchpoint.  */
217   struct expression *exp;
218   /* The largest block within which it is valid, or NULL if it is
219      valid anywhere (e.g. consists just of global symbols).  */
220   struct block *exp_valid_block;
221   /* Value of the watchpoint the last time we checked it.  */
222   value_ptr val;
223
224   /* Holds the value chain for a hardware watchpoint expression.  */
225   value_ptr val_chain;
226
227   /* Holds the address of the related watchpoint_scope breakpoint
228      when using watchpoints on local variables (might the concept
229      of a related breakpoint be useful elsewhere, if not just call
230      it the watchpoint_scope breakpoint or something like that. FIXME).  */
231   struct breakpoint *related_breakpoint; 
232
233   /* Holds the frame address which identifies the frame this watchpoint
234      should be evaluated in, or NULL if the watchpoint should be evaluated
235      on the outermost frame.  */
236   CORE_ADDR watchpoint_frame;
237
238   /* Thread number for thread-specific breakpoint, or -1 if don't care */
239   int thread;
240
241   /* Count of the number of times this breakpoint was taken, dumped
242      with the info, but not used for anything else.  Useful for
243      seeing how many times you hit a break prior to the program
244      aborting, so you can back up to just before the abort.  */
245   int hit_count;
246
247   /* Filename of a dynamically-linked library (dll), used for bp_catch_load
248      and bp_catch_unload (malloc'd), or NULL if any library is significant.  */
249   char *  dll_pathname;
250  
251   /* Filename of a dll whose state change (e.g., load or unload)
252      triggered this catchpoint.  This field is only vaid immediately
253      after this catchpoint has triggered.  */
254   char *  triggered_dll_pathname;
255  
256   /* Process id of a child process whose forking triggered this catchpoint.
257      This field is only vaid immediately after this catchpoint has triggered.  */
258   int  forked_inferior_pid;
259  
260   /* Filename of a program whose exec triggered this catchpoint.  This
261      field is only vaid immediately after this catchpoint has triggered.  */
262   char *  exec_pathname;
263   
264   asection *section;
265 };
266 \f
267 /* The following stuff is an abstract data type "bpstat" ("breakpoint status").
268    This provides the ability to determine whether we have stopped at a
269    breakpoint, and what we should do about it.  */
270
271 typedef struct bpstats *bpstat;
272
273 /* Interface:  */
274 /* Clear a bpstat so that it says we are not at any breakpoint.
275    Also free any storage that is part of a bpstat.  */
276 extern void bpstat_clear PARAMS ((bpstat *));
277
278 /* Return a copy of a bpstat.  Like "bs1 = bs2" but all storage that
279    is part of the bpstat is copied as well.  */
280 extern bpstat bpstat_copy PARAMS ((bpstat));
281
282 extern bpstat bpstat_stop_status PARAMS ((CORE_ADDR *, int));
283 \f
284 /* This bpstat_what stuff tells wait_for_inferior what to do with a
285    breakpoint (a challenging task).  */
286
287 enum bpstat_what_main_action {
288   /* Perform various other tests; that is, this bpstat does not
289      say to perform any action (e.g. failed watchpoint and nothing
290      else).  */
291   BPSTAT_WHAT_KEEP_CHECKING,
292
293   /* Rather than distinguish between noisy and silent stops here, it
294      might be cleaner to have bpstat_print make that decision (also
295      taking into account stop_print_frame and source_only).  But the
296      implications are a bit scary (interaction with auto-displays, etc.),
297      so I won't try it.  */
298      
299   /* Stop silently.  */
300   BPSTAT_WHAT_STOP_SILENT,
301
302   /* Stop and print.  */
303   BPSTAT_WHAT_STOP_NOISY,
304
305   /* Remove breakpoints, single step once, then put them back in and
306      go back to what we were doing.  It's possible that this should be
307      removed from the main_action and put into a separate field, to more
308      cleanly handle BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE.  */
309   BPSTAT_WHAT_SINGLE,
310
311   /* Set longjmp_resume breakpoint, remove all other breakpoints,
312      and continue.  The "remove all other breakpoints" part is required
313      if we are also stepping over another breakpoint as well as doing
314      the longjmp handling.  */
315   BPSTAT_WHAT_SET_LONGJMP_RESUME,
316
317   /* Clear longjmp_resume breakpoint, then handle as
318      BPSTAT_WHAT_KEEP_CHECKING.  */
319   BPSTAT_WHAT_CLEAR_LONGJMP_RESUME,
320
321   /* Clear longjmp_resume breakpoint, then handle as BPSTAT_WHAT_SINGLE.  */
322   BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE,
323
324   /* Clear step resume breakpoint, and keep checking.  */
325   BPSTAT_WHAT_STEP_RESUME,
326
327   /* Clear through_sigtramp breakpoint, muck with trap_expected, and keep
328      checking.  */
329   BPSTAT_WHAT_THROUGH_SIGTRAMP,
330
331   /* Check the dynamic linker's data structures for new libraries, then
332      keep checking.  */
333   BPSTAT_WHAT_CHECK_SHLIBS,
334
335   /* Check the dynamic linker's data structures for new libraries, then
336      resume out of the dynamic linker's callback, stop and print.  */
337   BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK,
338
339   /* This is just used to keep track of how many enums there are.  */
340   BPSTAT_WHAT_LAST
341 };
342
343 struct bpstat_what {
344   enum bpstat_what_main_action main_action;
345
346   /* Did we hit a call dummy breakpoint?  This only goes with a main_action
347      of BPSTAT_WHAT_STOP_SILENT or BPSTAT_WHAT_STOP_NOISY (the concept of
348      continuing from a call dummy without popping the frame is not a
349      useful one).  */
350   int call_dummy;
351 };
352
353 /* Tell what to do about this bpstat.  */
354 struct bpstat_what bpstat_what PARAMS ((bpstat));
355 \f
356 /* Find the bpstat associated with a breakpoint.  NULL otherwise. */
357 bpstat bpstat_find_breakpoint PARAMS ((bpstat, struct breakpoint *));
358
359 /* Find a step_resume breakpoint associated with this bpstat.
360    (If there are multiple step_resume bp's on the list, this function
361    will arbitrarily pick one.)
362
363    It is an error to use this function if BPSTAT doesn't contain a
364    step_resume breakpoint.
365
366    See wait_for_inferior's use of this function.
367    */
368 extern struct breakpoint *
369 bpstat_find_step_resume_breakpoint PARAMS ((bpstat));
370
371 /* Nonzero if a signal that we got in wait() was due to circumstances
372    explained by the BS.  */
373 /* Currently that is true if we have hit a breakpoint, or if there is
374    a watchpoint enabled.  */
375 #define bpstat_explains_signal(bs) ((bs) != NULL)
376
377 /* Nonzero if we should step constantly (e.g. watchpoints on machines
378    without hardware support).  This isn't related to a specific bpstat,
379    just to things like whether watchpoints are set.  */
380 extern int bpstat_should_step PARAMS ((void));
381
382 /* Nonzero if there are enabled hardware watchpoints. */
383 extern int bpstat_have_active_hw_watchpoints PARAMS ((void));
384
385 /* Print a message indicating what happened.  Returns nonzero to
386    say that only the source line should be printed after this (zero
387    return means print the frame as well as the source line).  */
388 extern int bpstat_print PARAMS ((bpstat));
389
390 /* Return the breakpoint number of the first breakpoint we are stopped
391    at.  *BSP upon return is a bpstat which points to the remaining
392    breakpoints stopped at (but which is not guaranteed to be good for
393    anything but further calls to bpstat_num).
394    Return 0 if passed a bpstat which does not indicate any breakpoints.  */
395 extern int bpstat_num PARAMS ((bpstat *));
396
397 /* Perform actions associated with having stopped at *BSP.  Actually, we just
398    use this for breakpoint commands.  Perhaps other actions will go here
399    later, but this is executed at a late time (from the command loop).  */
400 extern void bpstat_do_actions PARAMS ((bpstat *));
401
402 /* Modify BS so that the actions will not be performed.  */
403 extern void bpstat_clear_actions PARAMS ((bpstat));
404
405 /* Given a bpstat that records zero or more triggered eventpoints, this
406    function returns another bpstat which contains only the catchpoints
407    on that first list, if any.
408    */
409 extern void bpstat_get_triggered_catchpoints PARAMS ((bpstat, bpstat *));
410  
411 /* Implementation:  */
412 struct bpstats
413 {
414   /* Linked list because there can be two breakpoints at the
415      same place, and a bpstat reflects the fact that both have been hit.  */
416   bpstat next;
417   /* Breakpoint that we are at.  */
418   struct breakpoint *breakpoint_at;
419   /* Commands left to be done.  */
420   struct command_line *commands;
421   /* Old value associated with a watchpoint.  */
422   value_ptr old_val;
423
424   /* Nonzero if this breakpoint tells us to print the frame.  */
425   char print;
426
427   /* Nonzero if this breakpoint tells us to stop.  */
428   char stop;
429
430   /* Function called by bpstat_print to print stuff associated with
431      this element of the bpstat chain.  Returns 0 or 1 just like
432      bpstat_print, or -1 if it can't deal with it.  */
433   int (*print_it) PARAMS((bpstat bs));
434 };
435
436 enum inf_context
437 {
438   inf_starting,
439   inf_running,
440   inf_exited
441 };
442
443 \f
444 /* Prototypes for breakpoint-related functions.  */
445
446 #ifdef __STDC__         /* Forward declarations for prototypes */
447 struct frame_info;
448 #endif
449
450 extern int breakpoint_here_p PARAMS ((CORE_ADDR));
451
452 extern int breakpoint_inserted_here_p PARAMS ((CORE_ADDR));
453
454 extern int frame_in_dummy PARAMS ((struct frame_info *));
455
456 extern int breakpoint_thread_match PARAMS ((CORE_ADDR, int));
457
458 extern void until_break_command PARAMS ((char *, int));
459
460 extern void breakpoint_re_set PARAMS ((void));
461
462 extern void breakpoint_re_set_thread PARAMS ((struct breakpoint *));
463
464 extern int ep_is_exception_catchpoint PARAMS ((struct breakpoint *));
465
466 extern struct breakpoint *set_momentary_breakpoint
467   PARAMS ((struct symtab_and_line, struct frame_info *, enum bptype));
468
469 extern void set_ignore_count PARAMS ((int, int, int));
470
471 extern void set_default_breakpoint PARAMS ((int, CORE_ADDR, struct symtab *, int));
472
473 extern void mark_breakpoints_out PARAMS ((void));
474
475 extern void breakpoint_init_inferior PARAMS ((enum inf_context));
476
477 extern void delete_breakpoint PARAMS ((struct breakpoint *));
478
479 extern void breakpoint_auto_delete PARAMS ((bpstat));
480
481 extern void breakpoint_clear_ignore_counts PARAMS ((void));
482
483 extern void break_command PARAMS ((char *, int));
484
485 extern void tbreak_command PARAMS ((char *, int));
486
487 extern int insert_breakpoints PARAMS ((void));
488
489 extern int remove_breakpoints PARAMS ((void));
490
491 /* This function can be used to physically insert eventpoints from the
492    specified traced inferior process, without modifying the breakpoint
493    package's state.  This can be useful for those targets which support
494    following the processes of a fork() or vfork() system call, when both
495    of the resulting two processes are to be followed.  */
496 extern int reattach_breakpoints PARAMS ((int));
497
498 /* This function can be used to update the breakpoint package's state
499    after an exec() system call has been executed.
500
501    This function causes the following:
502
503      - All eventpoints are marked "not inserted".
504      - All eventpoints with a symbolic address are reset such that
505        the symbolic address must be reevaluated before the eventpoints
506        can be reinserted.
507      - The solib breakpoints are explicitly removed from the breakpoint
508        list.
509      - A step-resume breakpoint, if any, is explicitly removed from the
510        breakpoint list.
511      - All eventpoints without a symbolic address are removed from the
512        breakpoint list. */
513 extern void update_breakpoints_after_exec PARAMS ((void));
514
515 /* This function can be used to physically remove hardware breakpoints
516    and watchpoints from the specified traced inferior process, without
517    modifying the breakpoint package's state.  This can be useful for
518    those targets which support following the processes of a fork() or
519    vfork() system call, when one of the resulting two processes is to
520    be detached and allowed to run free.
521  
522    It is an error to use this function on the process whose id is
523    inferior_pid.  */
524 extern int detach_breakpoints PARAMS ((int));
525  
526 extern void enable_longjmp_breakpoint PARAMS ((void));
527
528 extern void disable_longjmp_breakpoint PARAMS ((void));
529
530 extern void set_longjmp_resume_breakpoint PARAMS ((CORE_ADDR,
531                                                    struct frame_info *));
532 /* These functions respectively disable or reenable all currently
533    enabled watchpoints.  When disabled, the watchpoints are marked
534    call_disabled.  When reenabled, they are marked enabled.
535
536    The intended client of these functions is infcmd.c\run_stack_dummy.
537
538    The inferior must be stopped, and all breakpoints removed, when
539    these functions are used.
540
541    The need for these functions is that on some targets (e.g., HP-UX),
542    gdb is unable to unwind through the dummy frame that is pushed as
543    part of the implementation of a call command.  Watchpoints can
544    cause the inferior to stop in places where this frame is visible,
545    and that can cause execution control to become very confused.
546
547    Note that if a user sets breakpoints in an interactively call
548    function, the call_disabled watchpoints will have been reenabled
549    when the first such breakpoint is reached.  However, on targets
550    that are unable to unwind through the call dummy frame, watches
551    of stack-based storage may then be deleted, because gdb will
552    believe that their watched storage is out of scope.  (Sigh.) */
553 extern void
554 disable_watchpoints_before_interactive_call_start PARAMS ((void));
555
556 extern void
557 enable_watchpoints_after_interactive_call_stop PARAMS ((void));
558
559  
560 extern void clear_breakpoint_hit_counts PARAMS ((void));
561
562 /* The following are for displays, which aren't really breakpoints, but
563    here is as good a place as any for them.  */
564
565 extern void disable_current_display PARAMS ((void));
566
567 extern void do_displays PARAMS ((void));
568
569 extern void disable_display PARAMS ((int));
570
571 extern void clear_displays PARAMS ((void));
572
573 extern void disable_breakpoint PARAMS ((struct breakpoint *));
574
575 extern void enable_breakpoint PARAMS ((struct breakpoint *));
576
577 extern void create_solib_event_breakpoint PARAMS ((CORE_ADDR));
578
579 extern void remove_solib_event_breakpoints PARAMS ((void));
580
581 extern void disable_breakpoints_in_shlibs PARAMS ((int silent));
582
583 extern void re_enable_breakpoints_in_shlibs PARAMS ((void));
584
585 extern void create_solib_load_event_breakpoint PARAMS ((char *, int, char *, char *));
586  
587 extern void create_solib_unload_event_breakpoint PARAMS ((char *, int, char *, char *));
588  
589 extern void create_fork_event_catchpoint PARAMS ((int, char *));
590  
591 extern void create_vfork_event_catchpoint PARAMS ((int, char *));
592
593 extern void create_exec_event_catchpoint PARAMS ((int, char *));
594  
595 /* This function returns TRUE if ep is a catchpoint. */
596 extern int ep_is_catchpoint PARAMS ((struct breakpoint *));
597  
598 /* This function returns TRUE if ep is a catchpoint of a
599    shared library (aka dynamically-linked library) event,
600    such as a library load or unload. */
601 extern int ep_is_shlib_catchpoint PARAMS ((struct breakpoint *));
602  
603 extern struct breakpoint *set_breakpoint_sal PARAMS ((struct symtab_and_line));
604
605 #endif /* !defined (BREAKPOINT_H) */