home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / gdb / breakpoint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-13  |  14.3 KB  |  420 lines

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