6 /* Copyright (C) 1995,1996,1998,1999,2000,2001,2002,2004,2008
7 * Free Software Foundation, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 3 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #include "libguile/__scm.h"
29 #include "libguile/options.h"
33 * Here comes some definitions for the debugging machinery.
34 * It might seem strange to represent debug flags as ints,
35 * but consider that any particular piece of code is normally
36 * only interested in one flag at a time. This is then
37 * the most efficient representation.
43 /* scm_debug_opts is defined in eval.c.
48 SCM_API
int scm_debug_mode_p
;
49 SCM_API
int scm_check_entry_p
;
50 SCM_API
int scm_check_apply_p
;
51 SCM_API
int scm_check_exit_p
;
52 SCM_API
int scm_check_memoize_p
;
54 #define SCM_RESET_DEBUG_MODE \
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_check_memoize_p = (SCM_MEMOIZE_P)\
63 && scm_is_true (SCM_MEMOIZE_HDLR);\
64 scm_debug_mode_p = SCM_DEVAL_P\
65 || scm_check_memoize_p || scm_check_entry_p || scm_check_apply_p || scm_check_exit_p;\
71 typedef union scm_t_debug_info
73 struct { SCM exp
, env
; } e
;
74 struct { SCM proc
, args
; } a
;
78 SCM_API
long scm_debug_eframe_size
;
80 typedef struct scm_t_debug_frame
82 struct scm_t_debug_frame
*prev
;
84 scm_t_debug_info
*vect
;
85 scm_t_debug_info
*info
;
88 #define SCM_EVALFRAME (0L << 11)
89 #define SCM_APPLYFRAME (1L << 11)
90 #define SCM_VOIDFRAME (3L << 11)
91 #define SCM_MACROEXPF (1L << 10)
92 #define SCM_TAILREC (1L << 9)
93 #define SCM_TRACED_FRAME (1L << 8)
94 #define SCM_ARGS_READY (1L << 7)
95 #define SCM_DOVERFLOW (1L << 6)
96 #define SCM_MAX_FRAME_SIZE 63
98 #define SCM_FRAMETYPE (3L << 11)
100 #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME)
101 #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME)
102 #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME)
103 #define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0)
104 #define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0)
105 #define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0)
106 #define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0)
107 #define SCM_MACROEXPP(x) (((x).status & SCM_MACROEXPF) != 0)
108 #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
109 #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
110 #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
111 #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
112 #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
113 #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
114 #define SCM_SET_MACROEXP(x) ((x).status |= SCM_MACROEXPF)
115 #define SCM_CLEAR_MACROEXP(x) ((x).status &= ~SCM_MACROEXPF)
120 SCM_API scm_t_bits scm_tc16_debugobj
;
122 #define SCM_DEBUGOBJP(x) \
123 SCM_TYP16_PREDICATE (scm_tc16_debugobj, x)
124 #define SCM_DEBUGOBJ_FRAME(x) \
125 ((scm_t_debug_frame *) SCM_CELL_WORD_1 (x))
126 #define SCM_SET_DEBUGOBJ_FRAME(x, f) SCM_SET_CELL_WORD_1 (x, f)
131 SCM_API scm_t_bits scm_tc16_memoized
;
133 #define SCM_MEMOIZEDP(x) SCM_TYP16_PREDICATE (scm_tc16_memoized, x)
134 #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CELL_OBJECT_1 (x))
135 #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CELL_OBJECT_1 (x))
139 SCM_API SCM
scm_debug_object_p (SCM obj
);
140 SCM_API SCM
scm_local_eval (SCM exp
, SCM env
);
141 SCM_API SCM
scm_reverse_lookup (SCM env
, SCM data
);
142 SCM_API SCM
scm_sys_start_stack (SCM info_id
, SCM thunk
);
143 SCM_API SCM
scm_procedure_environment (SCM proc
);
144 SCM_API SCM
scm_procedure_module (SCM proc
);
145 SCM_API SCM
scm_procedure_source (SCM proc
);
146 SCM_API SCM
scm_procedure_name (SCM proc
);
147 SCM_API SCM
scm_memoized_environment (SCM m
);
148 SCM_API SCM
scm_make_memoized (SCM exp
, SCM env
);
149 SCM_API SCM
scm_memoized_p (SCM obj
);
150 SCM_API SCM
scm_with_traps (SCM thunk
);
151 SCM_API SCM
scm_evaluator_traps (SCM setting
);
152 SCM_API SCM
scm_debug_options (SCM setting
);
153 SCM_API SCM
scm_make_debugobj (scm_t_debug_frame
*debug
);
155 SCM_INTERNAL SCM
scm_i_unmemoize_expr (SCM memoized
);
156 SCM_INTERNAL
void scm_init_debug (void);
159 SCM_API SCM
scm_memcons (SCM car
, SCM cdr
, SCM env
);
160 SCM_API SCM
scm_mem_to_proc (SCM obj
);
161 SCM_API SCM
scm_proc_to_mem (SCM obj
);
162 SCM_API SCM
scm_debug_hang (SCM obj
);
163 #endif /*GUILE_DEBUG*/
165 #if SCM_ENABLE_DEPRECATED == 1
167 #define CHECK_ENTRY scm_check_entry_p
168 #define CHECK_APPLY scm_check_apply_p
169 #define CHECK_EXIT scm_check_exit_p
171 /* Deprecated in guile 1.7.0 on 2004-03-29. */
172 #define SCM_DEBUGGINGP scm_debug_mode_p
173 #define scm_debug_mode scm_debug_mode_p
177 #endif /* SCM_DEBUG_H */