* alist.h, append.h, arbiters.h, async.h, boolean.h, chars.h,
[bpt/guile.git] / libguile / debug.h
CommitLineData
c7ecd529
MD
1/* classes: h_files */
2
3#ifndef DEBUGH
4#define DEBUGH
5/* Copyright (C) 1995,1996 Mikael Djurfeldt
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program 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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, 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 */
48\f
49
50#include "options.h"
b4309c3c 51#include "libguile/__scm.h"
c7ecd529
MD
52
53\f
54
55/*
56 * Here comes some definitions for the debugging machinery.
57 * It might seem strange to represent debug flags as ints,
58 * but consider that any particular piece of code is normally
59 * only interested in one flag at a time. This is then
60 * the most efficient representation.
61 */
62
63/* {Options}
64 */
65
5e8d7fd4
MD
66/* scm_debug_opts and scm_evaluator_trap_table are defined in eval.c.
67 */
68
c7ecd529
MD
69extern scm_option scm_debug_opts[];
70
5e8d7fd4
MD
71#define SCM_CHEAPTRAPS_P scm_debug_opts[0].val
72#define SCM_BREAKPOINTS_P scm_debug_opts[1].val
73#define SCM_TRACE_P scm_debug_opts[2].val
74#define SCM_REC_PROCNAMES_P scm_debug_opts[3].val
75#define SCM_BACKWARDS_P scm_debug_opts[4].val
76#define SCM_N_FRAMES scm_debug_opts[5].val
77#define SCM_BACKTRACE_DEPTH scm_debug_opts[6].val
78#define SCM_BACKTRACE_P scm_debug_opts[7].val
79#define SCM_DEVAL_P scm_debug_opts[8].val
80#define SCM_STACK_LIMIT scm_debug_opts[9].val
81#define SCM_N_DEBUG_OPTIONS 10
c7ecd529
MD
82
83extern scm_option scm_evaluator_trap_table[];
84
5e8d7fd4
MD
85#define SCM_ENTER_FRAME_P scm_evaluator_trap_table[0].val
86#define SCM_APPLY_FRAME_P scm_evaluator_trap_table[1].val
87#define SCM_EXIT_FRAME_P scm_evaluator_trap_table[2].val
88#define SCM_N_EVALUATOR_TRAPS 3
c7ecd529
MD
89
90#ifdef __STDC__
91extern SCM (*scm_ceval_ptr) (SCM exp, SCM env);
92#else
93extern SCM (*scm_ceval_ptr) ();
94#endif
5e8d7fd4
MD
95extern int scm_debug_mode;
96extern int scm_check_entry_p, scm_check_apply_p, scm_check_exit_p;
c7ecd529 97
5e8d7fd4
MD
98#define CHECK_ENTRY scm_check_entry_p
99#define CHECK_APPLY scm_check_apply_p
100#define CHECK_EXIT scm_check_exit_p
c7ecd529 101
5e8d7fd4 102#define SCM_RESET_DEBUG_MODE \
c7ecd529 103{\
5e8d7fd4
MD
104 if (SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P) CHECK_ENTRY = 1;\
105 if (SCM_APPLY_FRAME_P || SCM_TRACE_P) CHECK_APPLY = 1;\
106 if (SCM_EXIT_FRAME_P || SCM_TRACE_P) CHECK_EXIT = 1;\
107 scm_debug_mode = SCM_DEVAL_P || SCM_BACKTRACE_P || CHECK_ENTRY || CHECK_APPLY || CHECK_EXIT;\
108 scm_ceval_ptr = scm_debug_mode ? scm_deval : scm_ceval;\
c7ecd529
MD
109}
110
111
112/* {Evaluator}
113 */
114
115typedef union scm_debug_info
116{
117 struct { SCM exp, env; } e;
118 struct { SCM proc, args; } a;
119} scm_debug_info;
120
121extern int scm_debug_eframe_size;
122
123typedef struct scm_debug_frame
124{
125 struct scm_debug_frame *prev;
126 long status;
127 scm_debug_info vect[1];
128} scm_debug_frame;
129
130extern scm_debug_frame *last_debug_info_frame;
131
5e8d7fd4
MD
132#define SCM_TAILREC (1L << 10)
133#define SCM_TRACED_FRAME (1L << 9)
134#define SCM_APPLYFRAME (1L << 8)
135#define SCM_ARGS_READY (1L << 7)
136#define SCM_DOVERFLOW (1L << 6)
137#define SCM_MAX_FRAME_SIZE 63 /* also used as a mask for the size field */
138
139#define SCM_EVALFRAMEP(x) (((x).status & SCM_APPLYFRAME) == 0)
140#define SCM_APPLYFRAMEP(x) (((x).status & SCM_APPLYFRAME) != 0)
141#define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0)
142#define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0)
143#define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0)
144#define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0)
145#define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
146#define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
147#define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
148#define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
149#define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
150#define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
151
152#define SCM_DEBUGGINGP scm_debug_mode
153#define SCM_DSIDEVAL(x, env) if NIMP(x) scm_deval((x), (env))
c7ecd529
MD
154
155/* {Memoized Source}
156 */
157
158extern long scm_tc16_memoized;
159
160#define SCM_MEMOIZEDP(x) (scm_tc16_memoized == SCM_TYP16 (x))
161#define SCM_MEMOEXP(x) SCM_CAR (SCM_CDR (x))
162#define SCM_MEMOENV(x) SCM_CDR (SCM_CDR (x))
163
164\f
165
166#ifdef __STDC__
167extern SCM scm_unmemoize (SCM memoized);
168extern SCM scm_make_debugobj (scm_debug_frame* debug);
169extern void scm_init_debug (void);
170#else
171extern SCM scm_unmemoize ();
172extern SCM scm_make_debugobj ();
173extern void scm_init_debug ();
174#endif
175
176#endif /* DEBUGH */