debug.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* classes: h_files */
  2. #ifndef SCM_DEBUG_H
  3. #define SCM_DEBUG_H
  4. /* Copyright (C) 1995,1996,1998,1999,2000,2001 Free Software Foundation
  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, or (at your option)
  9. * 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 software; see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301 USA
  20. *
  21. * As a special exception, the Free Software Foundation gives permission
  22. * for additional uses of the text contained in its release of GUILE.
  23. *
  24. * The exception is that, if you link the GUILE library with other files
  25. * to produce an executable, this does not by itself cause the
  26. * resulting executable to be covered by the GNU General Public License.
  27. * Your use of that executable is in no way restricted on account of
  28. * linking the GUILE library code into it.
  29. *
  30. * This exception does not however invalidate any other reasons why
  31. * the executable file might be covered by the GNU General Public License.
  32. *
  33. * This exception applies only to the code released by the
  34. * Free Software Foundation under the name GUILE. If you copy
  35. * code from other Free Software Foundation releases into a copy of
  36. * GUILE, as the General Public License permits, the exception does
  37. * not apply to the code that you add in this way. To avoid misleading
  38. * anyone as to the status of such modified files, you must delete
  39. * this exception notice from them.
  40. *
  41. * If you write modifications of your own for GUILE, it is your choice
  42. * whether to permit this exception to apply to your modifications.
  43. * If you do not wish that, delete this exception notice.
  44. *
  45. * The author can be reached at djurfeldt@nada.kth.se
  46. * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */
  47. #include "libguile/__scm.h"
  48. #include "libguile/options.h"
  49. /*
  50. * Here comes some definitions for the debugging machinery.
  51. * It might seem strange to represent debug flags as ints,
  52. * but consider that any particular piece of code is normally
  53. * only interested in one flag at a time. This is then
  54. * the most efficient representation.
  55. */
  56. /* {Options}
  57. */
  58. /* scm_debug_opts is defined in eval.c.
  59. */
  60. extern scm_t_option scm_debug_opts[];
  61. #define SCM_CHEAPTRAPS_P scm_debug_opts[0].val
  62. #define SCM_BREAKPOINTS_P scm_debug_opts[1].val
  63. #define SCM_TRACE_P scm_debug_opts[2].val
  64. #define SCM_REC_PROCNAMES_P scm_debug_opts[3].val
  65. #define SCM_BACKWARDS_P scm_debug_opts[4].val
  66. #define SCM_BACKTRACE_WIDTH scm_debug_opts[5].val
  67. #define SCM_BACKTRACE_INDENT scm_debug_opts[6].val
  68. #define SCM_N_FRAMES scm_debug_opts[7].val
  69. #define SCM_BACKTRACE_MAXDEPTH scm_debug_opts[8].val
  70. #define SCM_BACKTRACE_DEPTH scm_debug_opts[9].val
  71. #define SCM_BACKTRACE_P scm_debug_opts[10].val
  72. #define SCM_DEVAL_P scm_debug_opts[11].val
  73. #define SCM_STACK_LIMIT scm_debug_opts[12].val
  74. #define SCM_SHOW_FILE_NAME scm_debug_opts[13].val
  75. #define SCM_N_DEBUG_OPTIONS 14
  76. extern SCM (*scm_ceval_ptr) (SCM exp, SCM env);
  77. extern int scm_debug_mode;
  78. extern int scm_check_entry_p, scm_check_apply_p, scm_check_exit_p;
  79. #define CHECK_ENTRY scm_check_entry_p
  80. #define CHECK_APPLY scm_check_apply_p
  81. #define CHECK_EXIT scm_check_exit_p
  82. #define SCM_RESET_DEBUG_MODE \
  83. do {\
  84. CHECK_ENTRY = (SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P)\
  85. && SCM_NFALSEP (SCM_ENTER_FRAME_HDLR);\
  86. CHECK_APPLY = (SCM_APPLY_FRAME_P || SCM_TRACE_P)\
  87. && SCM_NFALSEP (SCM_APPLY_FRAME_HDLR);\
  88. CHECK_EXIT = (SCM_EXIT_FRAME_P || SCM_TRACE_P)\
  89. && SCM_NFALSEP (SCM_EXIT_FRAME_HDLR);\
  90. scm_debug_mode = SCM_DEVAL_P || CHECK_ENTRY || CHECK_APPLY || CHECK_EXIT;\
  91. scm_ceval_ptr = scm_debug_mode ? scm_deval : scm_ceval;\
  92. } while (0)
  93. /* {Evaluator}
  94. */
  95. typedef union scm_t_debug_info
  96. {
  97. struct { SCM exp, env; } e;
  98. struct { SCM proc, args; } a;
  99. SCM id;
  100. } scm_t_debug_info;
  101. extern long scm_debug_eframe_size;
  102. typedef struct scm_t_debug_frame
  103. {
  104. struct scm_t_debug_frame *prev;
  105. long status;
  106. scm_t_debug_info *vect;
  107. scm_t_debug_info *info;
  108. } scm_t_debug_frame;
  109. #if (SCM_DEBUG_DEPRECATED == 0)
  110. # define scm_debug_info scm_t_debug_info
  111. # define scm_debug_frame scm_t_debug_frame
  112. #endif
  113. #ifndef USE_THREADS
  114. extern scm_t_debug_frame *scm_last_debug_frame;
  115. #endif
  116. #define SCM_EVALFRAME (0L << 11)
  117. #define SCM_APPLYFRAME (1L << 11)
  118. #define SCM_VOIDFRAME (3L << 11)
  119. #define SCM_MACROEXPF (1L << 10)
  120. #define SCM_TAILREC (1L << 9)
  121. #define SCM_TRACED_FRAME (1L << 8)
  122. #define SCM_ARGS_READY (1L << 7)
  123. #define SCM_DOVERFLOW (1L << 6)
  124. #define SCM_MAX_FRAME_SIZE 63
  125. #define SCM_FRAMETYPE (3L << 11)
  126. #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME)
  127. #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME)
  128. #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME)
  129. #define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0)
  130. #define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0)
  131. #define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0)
  132. #define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0)
  133. #define SCM_MACROEXPP(x) (((x).status & SCM_MACROEXPF) != 0)
  134. #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
  135. #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
  136. #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
  137. #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
  138. #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
  139. #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
  140. #define SCM_SET_MACROEXP(x) ((x).status |= SCM_MACROEXPF)
  141. #define SCM_CLEAR_MACROEXP(x) ((x).status &= ~SCM_MACROEXPF)
  142. #define SCM_DEBUGGINGP scm_debug_mode
  143. #define SCM_DSIDEVAL(x, env) if NIMP(x) scm_deval((x), (env))
  144. /* {Debug Objects}
  145. */
  146. extern scm_t_bits scm_tc16_debugobj;
  147. #define SCM_DEBUGOBJP(x) \
  148. SCM_TYP16_PREDICATE (scm_tc16_debugobj, x)
  149. #define SCM_DEBUGOBJ_FRAME(x) \
  150. ((scm_t_debug_frame *) SCM_CELL_WORD_1 (x))
  151. #define SCM_SET_DEBUGOBJ_FRAME(x, f) SCM_SET_CELL_WORD_1 (x, f)
  152. /* {Memoized Source}
  153. */
  154. extern scm_t_bits scm_tc16_memoized;
  155. #define SCM_MEMOIZEDP(x) SCM_TYP16_PREDICATE (scm_tc16_memoized, x)
  156. #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CELL_OBJECT_1 (x))
  157. #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CELL_OBJECT_1 (x))
  158. extern int scm_ready_p (void);
  159. extern void debug_print (SCM obj);
  160. extern SCM scm_debug_object_p (SCM obj);
  161. extern SCM scm_local_eval (SCM exp, SCM env);
  162. extern SCM scm_reverse_lookup (SCM env, SCM data);
  163. extern SCM scm_start_stack (SCM id, SCM exp, SCM env);
  164. extern SCM scm_procedure_environment (SCM proc);
  165. extern SCM scm_procedure_source (SCM proc);
  166. extern SCM scm_procedure_name (SCM proc);
  167. extern SCM scm_memoized_environment (SCM m);
  168. extern SCM scm_make_memoized (SCM exp, SCM env);
  169. extern SCM scm_memoized_p (SCM obj);
  170. extern SCM scm_with_traps (SCM thunk);
  171. extern SCM scm_evaluator_traps (SCM setting);
  172. extern SCM scm_debug_options (SCM setting);
  173. extern SCM scm_unmemoize (SCM memoized);
  174. extern SCM scm_make_debugobj (scm_t_debug_frame *debug);
  175. extern void scm_init_debug (void);
  176. #ifdef GUILE_DEBUG
  177. extern SCM scm_make_gloc (SCM var, SCM env);
  178. extern SCM scm_gloc_p (SCM obj);
  179. extern SCM scm_make_iloc (SCM frame, SCM binding, SCM cdrp);
  180. extern SCM scm_iloc_p (SCM obj);
  181. extern SCM scm_memcons (SCM car, SCM cdr, SCM env);
  182. extern SCM scm_mem_to_proc (SCM obj);
  183. extern SCM scm_proc_to_mem (SCM obj);
  184. extern SCM scm_debug_hang (SCM obj);
  185. #endif /*GUILE_DEBUG*/
  186. #endif /* SCM_DEBUG_H */
  187. /*
  188. Local Variables:
  189. c-file-style: "gnu"
  190. End:
  191. */