* From Peter Schauer:
[platform/upstream/binutils.git] / gdb / breakpoint.h
1 /* Data structures associated with breakpoints in GDB.
2    Copyright (C) 1992, 1993, 1994, 1995, 1996 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_breakpoint,                /* Normal breakpoint */
42   bp_hardware_breakpoint,       /* Hardware assisted breakpoint */
43   bp_until,                     /* used by until command */
44   bp_finish,                    /* used by finish command */
45   bp_watchpoint,                /* Watchpoint */
46   bp_hardware_watchpoint,       /* Hardware assisted watchpoint */
47   bp_read_watchpoint,           /* read watchpoint, (hardware assisted) */
48   bp_access_watchpoint,         /* access watchpoint, (hardware assisted) */
49   bp_longjmp,                   /* secret breakpoint to find longjmp() */
50   bp_longjmp_resume,            /* secret breakpoint to escape longjmp() */
51
52   /* Used by wait_for_inferior for stepping over subroutine calls, for
53      stepping over signal handlers, and for skipping prologues.  */
54   bp_step_resume,
55
56   /* Used by wait_for_inferior for stepping over signal handlers.  */
57   bp_through_sigtramp,
58
59   /* Used to detect when a watchpoint expression has gone out of
60      scope.  These breakpoints are usually not visible to the user.
61
62      This breakpoint has some interesting properties:
63
64        1) There's always a 1:1 mapping between watchpoints
65        on local variables and watchpoint_scope breakpoints.
66
67        2) It automatically deletes itself and the watchpoint it's
68        associated with when hit.
69
70        3) It can never be disabled.  */
71   bp_watchpoint_scope,
72
73   /* The breakpoint at the end of a call dummy.  */
74   /* FIXME: What if the function we are calling longjmp()s out of the
75      call, or the user gets out with the "return" command?  We currently
76      have no way of cleaning up the breakpoint in these (obscure) situations.
77      (Probably can solve this by noticing longjmp, "return", etc., it's
78      similar to noticing when a watchpoint on a local variable goes out
79      of scope (with hardware support for watchpoints)).  */
80   bp_call_dummy,
81
82   /* Some dynamic linkers (HP, maybe Solaris) can arrange for special
83      code in the inferior to run when significant events occur in the
84      dynamic linker (for example a library is loaded or unloaded).
85
86      By placing a breakpoint in this magic code GDB will get control
87      when these significant events occur.  GDB can then re-examine
88      the dynamic linker's data structures to discover any newly loaded
89      dynamic libraries.  */
90   bp_shlib_event
91 };
92
93 /* States of enablement of breakpoint. */
94
95 enum enable { disabled, enabled, shlib_disabled};
96
97 /* Disposition of breakpoint.  Ie: what to do after hitting it. */
98
99 enum bpdisp {
100   del,                          /* Delete it */
101   del_at_next_stop,             /* Delete at next stop, whether hit or not */
102   disable,                      /* Disable it */
103   donttouch                     /* Leave it alone */
104 };
105
106 /* Note that the ->silent field is not currently used by any commands
107    (though the code is in there if it was to be, and set_raw_breakpoint
108    does set it to 0).  I implemented it because I thought it would be
109    useful for a hack I had to put in; I'm going to leave it in because
110    I can see how there might be times when it would indeed be useful */
111
112 /* This is for a breakpoint or a watchpoint.  */
113
114 struct breakpoint
115 {
116   struct breakpoint *next;
117   /* Type of breakpoint. */
118   enum bptype type;
119   /* Zero means disabled; remember the info but don't break here.  */
120   enum enable enable;
121   /* What to do with this breakpoint after we hit it. */
122   enum bpdisp disposition;
123   /* Number assigned to distinguish breakpoints.  */
124   int number;
125
126   /* Address to break at, or NULL if not a breakpoint.  */
127   CORE_ADDR address;
128
129   /* Line number of this address.  Only matters if address is
130      non-NULL.  */
131
132   int line_number;
133
134   /* Source file name of this address.  Only matters if address is
135      non-NULL.  */
136
137   char *source_file;
138
139   /* Non-zero means a silent breakpoint (don't print frame info
140      if we stop here). */
141   unsigned char silent;
142   /* Number of stops at this breakpoint that should
143      be continued automatically before really stopping.  */
144   int ignore_count;
145   /* "Real" contents of byte where breakpoint has been inserted.
146      Valid only when breakpoints are in the program.  Under the complete
147      control of the target insert_breakpoint and remove_breakpoint routines.
148      No other code should assume anything about the value(s) here.  */
149   char shadow_contents[BREAKPOINT_MAX];
150   /* Nonzero if this breakpoint is now inserted.  Only matters if address
151      is non-NULL.  */
152   char inserted;
153   /* Nonzero if this is not the first breakpoint in the list
154      for the given address.  Only matters if address is non-NULL.  */
155   char duplicate;
156   /* Chain of command lines to execute when this breakpoint is hit.  */
157   struct command_line *commands;
158   /* Stack depth (address of frame).  If nonzero, break only if fp
159      equals this.  */
160   CORE_ADDR frame;
161   /* Conditional.  Break only if this expression's value is nonzero.  */
162   struct expression *cond;
163
164   /* String we used to set the breakpoint (malloc'd).  Only matters if
165      address is non-NULL.  */
166   char *addr_string;
167   /* Language we used to set the breakpoint.  */
168   enum language language;
169   /* Input radix we used to set the breakpoint.  */
170   int input_radix;
171   /* String form of the breakpoint condition (malloc'd), or NULL if there
172      is no condition.  */
173   char *cond_string;
174   /* String form of exp (malloc'd), or NULL if none.  */
175   char *exp_string;
176
177   /* The expression we are watching, or NULL if not a watchpoint.  */
178   struct expression *exp;
179   /* The largest block within which it is valid, or NULL if it is
180      valid anywhere (e.g. consists just of global symbols).  */
181   struct block *exp_valid_block;
182   /* Value of the watchpoint the last time we checked it.  */
183   value_ptr val;
184
185   /* Holds the value chain for a hardware watchpoint expression.  */
186   value_ptr val_chain;
187
188   /* Holds the address of the related watchpoint_scope breakpoint
189      when using watchpoints on local variables (might the concept
190      of a related breakpoint be useful elsewhere, if not just call
191      it the watchpoint_scope breakpoint or something like that. FIXME).  */
192   struct breakpoint *related_breakpoint; 
193
194   /* Holds the frame address which identifies the frame this watchpoint
195      should be evaluated in, or NULL if the watchpoint should be evaluated
196      on the outermost frame.  */
197   CORE_ADDR watchpoint_frame;
198
199   /* Thread number for thread-specific breakpoint, or -1 if don't care */
200   int thread;
201
202   /* Count of the number of times this breakpoint was taken, dumped
203      with the info, but not used for anything else.  Useful for
204      seeing how many times you hit a break prior to the program
205      aborting, so you can back up to just before the abort.  */
206   int hit_count;
207
208 };
209 \f
210 /* The following stuff is an abstract data type "bpstat" ("breakpoint status").
211    This provides the ability to determine whether we have stopped at a
212    breakpoint, and what we should do about it.  */
213
214 typedef struct bpstats *bpstat;
215
216 /* Interface:  */
217 /* Clear a bpstat so that it says we are not at any breakpoint.
218    Also free any storage that is part of a bpstat.  */
219 extern void bpstat_clear PARAMS ((bpstat *));
220
221 /* Return a copy of a bpstat.  Like "bs1 = bs2" but all storage that
222    is part of the bpstat is copied as well.  */
223 extern bpstat bpstat_copy PARAMS ((bpstat));
224
225 extern bpstat bpstat_stop_status PARAMS ((CORE_ADDR *, int));
226 \f
227 /* This bpstat_what stuff tells wait_for_inferior what to do with a
228    breakpoint (a challenging task).  */
229
230 enum bpstat_what_main_action {
231   /* Perform various other tests; that is, this bpstat does not
232      say to perform any action (e.g. failed watchpoint and nothing
233      else).  */
234   BPSTAT_WHAT_KEEP_CHECKING,
235
236   /* Rather than distinguish between noisy and silent stops here, it
237      might be cleaner to have bpstat_print make that decision (also
238      taking into account stop_print_frame and source_only).  But the
239      implications are a bit scary (interaction with auto-displays, etc.),
240      so I won't try it.  */
241      
242   /* Stop silently.  */
243   BPSTAT_WHAT_STOP_SILENT,
244
245   /* Stop and print.  */
246   BPSTAT_WHAT_STOP_NOISY,
247
248   /* Remove breakpoints, single step once, then put them back in and
249      go back to what we were doing.  It's possible that this should be
250      removed from the main_action and put into a separate field, to more
251      cleanly handle BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE.  */
252   BPSTAT_WHAT_SINGLE,
253
254   /* Set longjmp_resume breakpoint, remove all other breakpoints,
255      and continue.  The "remove all other breakpoints" part is required
256      if we are also stepping over another breakpoint as well as doing
257      the longjmp handling.  */
258   BPSTAT_WHAT_SET_LONGJMP_RESUME,
259
260   /* Clear longjmp_resume breakpoint, then handle as
261      BPSTAT_WHAT_KEEP_CHECKING.  */
262   BPSTAT_WHAT_CLEAR_LONGJMP_RESUME,
263
264   /* Clear longjmp_resume breakpoint, then handle as BPSTAT_WHAT_SINGLE.  */
265   BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE,
266
267   /* Clear step resume breakpoint, and keep checking.  */
268   BPSTAT_WHAT_STEP_RESUME,
269
270   /* Clear through_sigtramp breakpoint, muck with trap_expected, and keep
271      checking.  */
272   BPSTAT_WHAT_THROUGH_SIGTRAMP,
273
274   /* Check the dynamic linker's data structures for new libraries, then
275      keep checking.  */
276   BPSTAT_WHAT_CHECK_SHLIBS,
277
278   /* This is just used to keep track of how many enums there are.  */
279   BPSTAT_WHAT_LAST
280 };
281
282 struct bpstat_what {
283   enum bpstat_what_main_action main_action;
284
285   /* Did we hit a call dummy breakpoint?  This only goes with a main_action
286      of BPSTAT_WHAT_STOP_SILENT or BPSTAT_WHAT_STOP_NOISY (the concept of
287      continuing from a call dummy without popping the frame is not a
288      useful one).  */
289   int call_dummy;
290 };
291
292 /* Tell what to do about this bpstat.  */
293 struct bpstat_what bpstat_what PARAMS ((bpstat));
294 \f
295 /* Find the bpstat associated with a breakpoint.  NULL otherwise. */
296 bpstat bpstat_find_breakpoint PARAMS ((bpstat, struct breakpoint *));
297
298 /* Nonzero if a signal that we got in wait() was due to circumstances
299    explained by the BS.  */
300 /* Currently that is true if we have hit a breakpoint, or if there is
301    a watchpoint enabled.  */
302 #define bpstat_explains_signal(bs) ((bs) != NULL)
303
304 /* Nonzero if we should step constantly (e.g. watchpoints on machines
305    without hardware support).  This isn't related to a specific bpstat,
306    just to things like whether watchpoints are set.  */
307 extern int bpstat_should_step PARAMS ((void));
308
309 /* Print a message indicating what happened.  Returns nonzero to
310    say that only the source line should be printed after this (zero
311    return means print the frame as well as the source line).  */
312 extern int bpstat_print PARAMS ((bpstat));
313
314 /* Return the breakpoint number of the first breakpoint we are stopped
315    at.  *BSP upon return is a bpstat which points to the remaining
316    breakpoints stopped at (but which is not guaranteed to be good for
317    anything but further calls to bpstat_num).
318    Return 0 if passed a bpstat which does not indicate any breakpoints.  */
319 extern int bpstat_num PARAMS ((bpstat *));
320
321 /* Perform actions associated with having stopped at *BSP.  Actually, we just
322    use this for breakpoint commands.  Perhaps other actions will go here
323    later, but this is executed at a late time (from the command loop).  */
324 extern void bpstat_do_actions PARAMS ((bpstat *));
325
326 /* Modify BS so that the actions will not be performed.  */
327 extern void bpstat_clear_actions PARAMS ((bpstat));
328
329 /* Implementation:  */
330 struct bpstats
331 {
332   /* Linked list because there can be two breakpoints at the
333      same place, and a bpstat reflects the fact that both have been hit.  */
334   bpstat next;
335   /* Breakpoint that we are at.  */
336   struct breakpoint *breakpoint_at;
337   /* Commands left to be done.  */
338   struct command_line *commands;
339   /* Old value associated with a watchpoint.  */
340   value_ptr old_val;
341
342   /* Nonzero if this breakpoint tells us to print the frame.  */
343   char print;
344
345   /* Nonzero if this breakpoint tells us to stop.  */
346   char stop;
347
348   /* Function called by bpstat_print to print stuff associated with
349      this element of the bpstat chain.  Returns 0 or 1 just like
350      bpstat_print, or -1 if it can't deal with it.  */
351   int (*print_it) PARAMS((bpstat bs));
352 };
353 \f
354 /* Prototypes for breakpoint-related functions.  */
355
356 #ifdef __STDC__         /* Forward declarations for prototypes */
357 struct frame_info;
358 #endif
359
360 extern int breakpoint_here_p PARAMS ((CORE_ADDR));
361
362 extern int frame_in_dummy PARAMS ((struct frame_info *));
363
364 extern int breakpoint_thread_match PARAMS ((CORE_ADDR, int));
365
366 extern void until_break_command PARAMS ((char *, int));
367
368 extern void breakpoint_re_set PARAMS ((void));
369
370 extern void clear_momentary_breakpoints PARAMS ((void));
371
372 extern struct breakpoint *set_momentary_breakpoint
373   PARAMS ((struct symtab_and_line, struct frame_info *, enum bptype));
374
375 extern void set_ignore_count PARAMS ((int, int, int));
376
377 extern void set_default_breakpoint PARAMS ((int, CORE_ADDR, struct symtab *, int));
378
379 extern void mark_breakpoints_out PARAMS ((void));
380
381 extern void breakpoint_init_inferior PARAMS ((void));
382
383 extern void delete_breakpoint PARAMS ((struct breakpoint *));
384
385 extern void breakpoint_auto_delete PARAMS ((bpstat));
386
387 extern void breakpoint_clear_ignore_counts PARAMS ((void));
388
389 extern void break_command PARAMS ((char *, int));
390
391 extern int insert_breakpoints PARAMS ((void));
392
393 extern int remove_breakpoints PARAMS ((void));
394
395 extern void enable_longjmp_breakpoint PARAMS ((void));
396
397 extern void disable_longjmp_breakpoint PARAMS ((void));
398
399 extern void set_longjmp_resume_breakpoint PARAMS ((CORE_ADDR,
400                                                    struct frame_info *));
401  
402 extern void clear_breakpoint_hit_counts PARAMS ((void));
403
404 /* The following are for displays, which aren't really breakpoints, but
405    here is as good a place as any for them.  */
406
407 extern void disable_current_display PARAMS ((void));
408
409 extern void do_displays PARAMS ((void));
410
411 extern void disable_display PARAMS ((int));
412
413 extern void clear_displays PARAMS ((void));
414
415 extern void disable_breakpoint PARAMS ((struct breakpoint *));
416
417 extern void enable_breakpoint PARAMS ((struct breakpoint *));
418
419 extern void create_solib_event_breakpoint PARAMS ((CORE_ADDR));
420
421 extern void remove_solib_event_breakpoints PARAMS ((void));
422
423 extern void re_enable_breakpoints_in_shlibs PARAMS ((void));
424
425 #endif /* !defined (BREAKPOINT_H) */