debug.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* classes: h_files */
  2. #ifndef DEBUGH
  3. #define DEBUGH
  4. /* Copyright (C) 1995,1996,1998, 1999, 2000, 2002 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., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307 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_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_N_DEBUG_OPTIONS 13
  75. extern SCM (*scm_ceval_ptr) (SCM exp, SCM env);
  76. extern int scm_debug_mode;
  77. extern int scm_check_entry_p, scm_check_apply_p, scm_check_exit_p;
  78. #define CHECK_ENTRY scm_check_entry_p
  79. #define CHECK_APPLY scm_check_apply_p
  80. #define CHECK_EXIT scm_check_exit_p
  81. #define SCM_RESET_DEBUG_MODE \
  82. do {\
  83. CHECK_ENTRY = SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P;\
  84. CHECK_APPLY = SCM_APPLY_FRAME_P || SCM_TRACE_P;\
  85. CHECK_EXIT = SCM_EXIT_FRAME_P || SCM_TRACE_P;\
  86. scm_debug_mode = SCM_DEVAL_P || CHECK_ENTRY || CHECK_APPLY || CHECK_EXIT;\
  87. scm_ceval_ptr = scm_debug_mode ? scm_deval : scm_ceval;\
  88. } while (0)
  89. /* {Evaluator}
  90. */
  91. typedef union scm_debug_info
  92. {
  93. struct { SCM exp, env; } e;
  94. struct { SCM proc, args; } a;
  95. SCM id;
  96. } scm_debug_info;
  97. extern int scm_debug_eframe_size;
  98. typedef struct scm_debug_frame
  99. {
  100. struct scm_debug_frame *prev;
  101. long status;
  102. scm_debug_info *vect;
  103. scm_debug_info *info;
  104. } scm_debug_frame;
  105. #ifndef USE_THREADS
  106. extern scm_debug_frame *scm_last_debug_frame;
  107. #endif
  108. #define SCM_EVALFRAME (0L << 11)
  109. #define SCM_APPLYFRAME (1L << 11)
  110. #define SCM_VOIDFRAME (3L << 11)
  111. #define SCM_MACROEXPF (1L << 10)
  112. #define SCM_TAILREC (1L << 9)
  113. #define SCM_TRACED_FRAME (1L << 8)
  114. #define SCM_ARGS_READY (1L << 7)
  115. #define SCM_DOVERFLOW (1L << 6)
  116. #define SCM_MAX_FRAME_SIZE 63 /* also used as a mask for the size field */
  117. #define SCM_FRAMETYPE (3L << 11)
  118. #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME)
  119. #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME)
  120. #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME)
  121. #define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0)
  122. #define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0)
  123. #define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0)
  124. #define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0)
  125. #define SCM_MACROEXPP(x) (((x).status & SCM_MACROEXPF) != 0)
  126. #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
  127. #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
  128. #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
  129. #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
  130. #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
  131. #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
  132. #define SCM_SET_MACROEXP(x) ((x).status |= SCM_MACROEXPF)
  133. #define SCM_CLEAR_MACROEXP(x) ((x).status &= ~SCM_MACROEXPF)
  134. #define SCM_DEBUGGINGP scm_debug_mode
  135. #define SCM_DSIDEVAL(x, env) if NIMP(x) scm_deval((x), (env))
  136. /* {Debug Objects}
  137. */
  138. extern long scm_tc16_debugobj;
  139. #define SCM_DEBUGOBJP(x) (SCM_NIMP (x) \
  140. && (SCM_TYP16 (x) == scm_tc16_debugobj))
  141. #define SCM_DEBUGOBJ_FRAME(x) (SCM_CELL_WORD_1 (x))
  142. #define SCM_SET_DEBUGOBJ_FRAME(x, f) (SCM_SET_CELL_WORD_1 (x, f))
  143. /* {Memoized Source}
  144. */
  145. extern long scm_tc16_memoized;
  146. #define SCM_MEMOIZEDP(x) (SCM_NIMP(x) && (scm_tc16_memoized == SCM_TYP16 (x)))
  147. #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CDR (x))
  148. #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CDR (x))
  149. extern SCM * scm_lookup_cstr (char *str, int len, SCM env);
  150. extern SCM * scm_lookup_soft (SCM var, SCM genv);
  151. extern SCM scm_evstr (char *str);
  152. extern SCM scm_eval_string (SCM str);
  153. extern int scm_ready_p (void);
  154. extern void debug_print (SCM obj);
  155. extern SCM scm_debug_object_p (SCM obj);
  156. extern SCM scm_local_eval (SCM exp, SCM env);
  157. extern SCM scm_reverse_lookup (SCM env, SCM data);
  158. extern SCM scm_start_stack (SCM id, SCM exp, SCM env);
  159. extern SCM scm_procedure_environment (SCM proc);
  160. extern SCM scm_procedure_source (SCM proc);
  161. extern SCM scm_procedure_name (SCM proc);
  162. extern SCM scm_memoized_environment (SCM m);
  163. extern SCM scm_make_memoized (SCM exp, SCM env);
  164. extern SCM scm_memoized_p (SCM obj);
  165. extern SCM scm_with_traps (SCM thunk);
  166. extern SCM scm_evaluator_traps (SCM setting);
  167. extern SCM scm_debug_options (SCM setting);
  168. extern SCM scm_unmemoize (SCM memoized);
  169. extern SCM scm_make_debugobj (scm_debug_frame* debug);
  170. extern void scm_init_debug (void);
  171. #ifdef GUILE_DEBUG
  172. extern SCM scm_make_gloc (SCM var, SCM env);
  173. extern SCM scm_gloc_p (SCM obj);
  174. extern SCM scm_make_iloc (SCM frame, SCM binding, SCM cdrp);
  175. extern SCM scm_iloc_p (SCM obj);
  176. extern SCM scm_memcons (SCM car, SCM cdr, SCM env);
  177. extern SCM scm_mem_to_proc (SCM obj);
  178. extern SCM scm_proc_to_mem (SCM obj);
  179. extern SCM scm_debug_hang (SCM obj);
  180. #endif /*GUILE_DEBUG*/
  181. #endif /* DEBUGH */
  182. /*
  183. Local Variables:
  184. c-file-style: "gnu"
  185. End:
  186. */