debug.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* classes: h_files */
  2. #ifndef SCM_DEBUG_H
  3. #define SCM_DEBUG_H
  4. /* Copyright (C) 1995,1996,1998,1999,2000,2001,2002,2004
  5. * Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libguile/__scm.h"
  22. #include "libguile/options.h"
  23. /*
  24. * Here comes some definitions for the debugging machinery.
  25. * It might seem strange to represent debug flags as ints,
  26. * but consider that any particular piece of code is normally
  27. * only interested in one flag at a time. This is then
  28. * the most efficient representation.
  29. */
  30. /* {Options}
  31. */
  32. /* scm_debug_opts is defined in eval.c.
  33. */
  34. SCM_API scm_t_option scm_debug_opts[];
  35. #define SCM_BREAKPOINTS_P scm_debug_opts[1].val
  36. #define SCM_TRACE_P scm_debug_opts[2].val
  37. #define SCM_REC_PROCNAMES_P scm_debug_opts[3].val
  38. #define SCM_BACKWARDS_P scm_debug_opts[4].val
  39. #define SCM_BACKTRACE_WIDTH scm_debug_opts[5].val
  40. #define SCM_BACKTRACE_INDENT scm_debug_opts[6].val
  41. #define SCM_N_FRAMES scm_debug_opts[7].val
  42. #define SCM_BACKTRACE_MAXDEPTH scm_debug_opts[8].val
  43. #define SCM_BACKTRACE_DEPTH scm_debug_opts[9].val
  44. #define SCM_BACKTRACE_P scm_debug_opts[10].val
  45. #define SCM_DEVAL_P scm_debug_opts[11].val
  46. #define SCM_STACK_LIMIT scm_debug_opts[12].val
  47. #define SCM_SHOW_FILE_NAME scm_debug_opts[13].val
  48. #define SCM_WARN_DEPRECATED scm_debug_opts[14].val
  49. #define SCM_N_DEBUG_OPTIONS 15
  50. SCM_API int scm_debug_mode_p;
  51. SCM_API int scm_check_entry_p;
  52. SCM_API int scm_check_apply_p;
  53. SCM_API int scm_check_exit_p;
  54. #define SCM_RESET_DEBUG_MODE \
  55. do {\
  56. scm_check_entry_p = (SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P)\
  57. && scm_is_true (SCM_ENTER_FRAME_HDLR);\
  58. scm_check_apply_p = (SCM_APPLY_FRAME_P || SCM_TRACE_P)\
  59. && scm_is_true (SCM_APPLY_FRAME_HDLR);\
  60. scm_check_exit_p = (SCM_EXIT_FRAME_P || SCM_TRACE_P)\
  61. && scm_is_true (SCM_EXIT_FRAME_HDLR);\
  62. scm_debug_mode_p = SCM_DEVAL_P\
  63. || scm_check_entry_p || scm_check_apply_p || scm_check_exit_p;\
  64. } while (0)
  65. /* {Evaluator}
  66. */
  67. typedef union scm_t_debug_info
  68. {
  69. struct { SCM exp, env; } e;
  70. struct { SCM proc, args; } a;
  71. SCM id;
  72. } scm_t_debug_info;
  73. SCM_API long scm_debug_eframe_size;
  74. typedef struct scm_t_debug_frame
  75. {
  76. struct scm_t_debug_frame *prev;
  77. long status;
  78. scm_t_debug_info *vect;
  79. scm_t_debug_info *info;
  80. } scm_t_debug_frame;
  81. #define SCM_EVALFRAME (0L << 11)
  82. #define SCM_APPLYFRAME (1L << 11)
  83. #define SCM_VOIDFRAME (3L << 11)
  84. #define SCM_MACROEXPF (1L << 10)
  85. #define SCM_TAILREC (1L << 9)
  86. #define SCM_TRACED_FRAME (1L << 8)
  87. #define SCM_ARGS_READY (1L << 7)
  88. #define SCM_DOVERFLOW (1L << 6)
  89. #define SCM_MAX_FRAME_SIZE 63
  90. #define SCM_FRAMETYPE (3L << 11)
  91. #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME)
  92. #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME)
  93. #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME)
  94. #define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0)
  95. #define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0)
  96. #define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0)
  97. #define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0)
  98. #define SCM_MACROEXPP(x) (((x).status & SCM_MACROEXPF) != 0)
  99. #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
  100. #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
  101. #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
  102. #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
  103. #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
  104. #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
  105. #define SCM_SET_MACROEXP(x) ((x).status |= SCM_MACROEXPF)
  106. #define SCM_CLEAR_MACROEXP(x) ((x).status &= ~SCM_MACROEXPF)
  107. /* {Debug Objects}
  108. */
  109. SCM_API scm_t_bits scm_tc16_debugobj;
  110. #define SCM_DEBUGOBJP(x) \
  111. SCM_TYP16_PREDICATE (scm_tc16_debugobj, x)
  112. #define SCM_DEBUGOBJ_FRAME(x) \
  113. ((scm_t_debug_frame *) SCM_CELL_WORD_1 (x))
  114. #define SCM_SET_DEBUGOBJ_FRAME(x, f) SCM_SET_CELL_WORD_1 (x, f)
  115. /* {Memoized Source}
  116. */
  117. SCM_API scm_t_bits scm_tc16_memoized;
  118. #define SCM_MEMOIZEDP(x) SCM_TYP16_PREDICATE (scm_tc16_memoized, x)
  119. #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CELL_OBJECT_1 (x))
  120. #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CELL_OBJECT_1 (x))
  121. SCM_API SCM scm_debug_object_p (SCM obj);
  122. SCM_API SCM scm_local_eval (SCM exp, SCM env);
  123. SCM_API SCM scm_reverse_lookup (SCM env, SCM data);
  124. SCM_API SCM scm_start_stack (SCM info_id, SCM exp, SCM env);
  125. SCM_API SCM scm_procedure_environment (SCM proc);
  126. SCM_API SCM scm_procedure_source (SCM proc);
  127. SCM_API SCM scm_procedure_name (SCM proc);
  128. SCM_API SCM scm_memoized_environment (SCM m);
  129. SCM_API SCM scm_make_memoized (SCM exp, SCM env);
  130. SCM_API SCM scm_memoized_p (SCM obj);
  131. SCM_API SCM scm_with_traps (SCM thunk);
  132. SCM_API SCM scm_evaluator_traps (SCM setting);
  133. SCM_API SCM scm_debug_options (SCM setting);
  134. SCM_API SCM scm_make_debugobj (scm_t_debug_frame *debug);
  135. SCM_API SCM scm_i_unmemoize_expr (SCM memoized);
  136. SCM_API void scm_init_debug (void);
  137. #ifdef GUILE_DEBUG
  138. SCM_API SCM scm_memcons (SCM car, SCM cdr, SCM env);
  139. SCM_API SCM scm_mem_to_proc (SCM obj);
  140. SCM_API SCM scm_proc_to_mem (SCM obj);
  141. SCM_API SCM scm_debug_hang (SCM obj);
  142. #endif /*GUILE_DEBUG*/
  143. #if SCM_ENABLE_DEPRECATED == 1
  144. #define CHECK_ENTRY scm_check_entry_p
  145. #define CHECK_APPLY scm_check_apply_p
  146. #define CHECK_EXIT scm_check_exit_p
  147. /* Deprecated in guile 1.7.0 on 2004-03-29. */
  148. #define SCM_DEBUGGINGP scm_debug_mode_p
  149. #define scm_debug_mode scm_debug_mode_p
  150. #endif
  151. #endif /* SCM_DEBUG_H */
  152. /*
  153. Local Variables:
  154. c-file-style: "gnu"
  155. End:
  156. */