* srfi-1.c (srfi1_for_each): Corrected argument checking for the
[bpt/guile.git] / libguile / debug.c
CommitLineData
68baa7e7 1/* Debugging extensions for Guile
4ba5f279 2 * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation
ee340120
MD
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; see the file COPYING. If not, write to
82892bed
JB
16 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307 USA
ee340120
MD
18 *
19 * As a special exception, the Free Software Foundation gives permission
20 * for additional uses of the text contained in its release of GUILE.
21 *
22 * The exception is that, if you link the GUILE library with other files
23 * to produce an executable, this does not by itself cause the
24 * resulting executable to be covered by the GNU General Public License.
25 * Your use of that executable is in no way restricted on account of
26 * linking the GUILE library code into it.
27 *
28 * This exception does not however invalidate any other reasons why
29 * the executable file might be covered by the GNU General Public License.
30 *
31 * This exception applies only to the code released by the
32 * Free Software Foundation under the name GUILE. If you copy
33 * code from other Free Software Foundation releases into a copy of
34 * GUILE, as the General Public License permits, the exception does
35 * not apply to the code that you add in this way. To avoid misleading
36 * anyone as to the status of such modified files, you must delete
37 * this exception notice from them.
38 *
39 * If you write modifications of your own for GUILE, it is your choice
40 * whether to permit this exception to apply to your modifications.
41 * If you do not wish that, delete this exception notice.
42 *
43 * The author can be reached at djurfeldt@nada.kth.se
82892bed 44 * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */
f0e9217a 45
1bbd0b84
GB
46
47
a0599745
MD
48#include "libguile/_scm.h"
49#include "libguile/eval.h"
37c56aec 50#include "libguile/list.h"
a0599745
MD
51#include "libguile/stackchk.h"
52#include "libguile/throw.h"
53#include "libguile/macros.h"
54#include "libguile/smob.h"
55#include "libguile/procprop.h"
56#include "libguile/srcprop.h"
57#include "libguile/alist.h"
58#include "libguile/continuations.h"
59#include "libguile/strports.h"
60#include "libguile/read.h"
61#include "libguile/feature.h"
62#include "libguile/dynwind.h"
63#include "libguile/modules.h"
64#include "libguile/ports.h"
65#include "libguile/root.h"
b06a8b87 66#include "libguile/fluids.h"
a0599745
MD
67
68#include "libguile/validate.h"
69#include "libguile/debug.h"
f0e9217a
MD
70\f
71
72/* {Run time control of the debugging evaluator}
73 */
74
a1ec6916 75SCM_DEFINE (scm_debug_options, "debug-options-interface", 0, 1, 0,
1bbd0b84 76 (SCM setting),
ba94f79e
MG
77 "Option interface for the debug options. Instead of using\n"
78 "this procedure directly, use the procedures @code{debug-enable},\n"
3939e9df 79 "@code{debug-disable}, @code{debug-set!} and @code{debug-options}.")
1bbd0b84 80#define FUNC_NAME s_scm_debug_options
f0e9217a
MD
81{
82 SCM ans;
83 SCM_DEFER_INTS;
8505e285 84 ans = scm_options (setting, scm_debug_opts, SCM_N_DEBUG_OPTIONS, FUNC_NAME);
5e8d7fd4 85 if (!(1 <= SCM_N_FRAMES && SCM_N_FRAMES <= SCM_MAX_FRAME_SIZE))
f0e9217a 86 {
1bbd0b84 87 scm_options (ans, scm_debug_opts, SCM_N_DEBUG_OPTIONS, FUNC_NAME);
1e76143f 88 SCM_OUT_OF_RANGE (1, setting);
f0e9217a 89 }
5e8d7fd4 90 SCM_RESET_DEBUG_MODE;
a6e350dd 91 scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P;
5e8d7fd4 92 scm_debug_eframe_size = 2 * SCM_N_FRAMES;
bfc69694 93 SCM_ALLOW_INTS;
f0e9217a
MD
94 return ans;
95}
1bbd0b84 96#undef FUNC_NAME
260b1416
MD
97
98static void
99with_traps_before (void *data)
100{
101 int *trap_flag = data;
102 *trap_flag = SCM_TRAPS_P;
103 SCM_TRAPS_P = 1;
104}
105
106static void
107with_traps_after (void *data)
108{
109 int *trap_flag = data;
110 SCM_TRAPS_P = *trap_flag;
111}
112
113static SCM
114with_traps_inner (void *data)
115{
451e591c 116 SCM thunk = SCM_PACK (data);
fdc28395 117 return scm_call_0 (thunk);
260b1416 118}
1cc91f1b 119
a1ec6916 120SCM_DEFINE (scm_with_traps, "with-traps", 1, 0, 0,
1bbd0b84 121 (SCM thunk),
ba94f79e 122 "Call @var{thunk} with traps enabled.")
1bbd0b84 123#define FUNC_NAME s_scm_with_traps
f0e9217a 124{
260b1416 125 int trap_flag;
34d19ef6 126 SCM_VALIDATE_THUNK (1, thunk);
260b1416
MD
127 return scm_internal_dynamic_wind (with_traps_before,
128 with_traps_inner,
129 with_traps_after,
451e591c 130 (void *) SCM_UNPACK (thunk),
260b1416 131 &trap_flag);
f0e9217a 132}
1bbd0b84 133#undef FUNC_NAME
f0e9217a
MD
134
135\f
85db4a2c
DH
136
137SCM_SYMBOL (scm_sym_procname, "procname");
138SCM_SYMBOL (scm_sym_dots, "...");
139SCM_SYMBOL (scm_sym_source, "source");
f0e9217a
MD
140
141/* {Memoized Source}
142 */
143
92c2555f 144scm_t_bits scm_tc16_memoized;
1cc91f1b 145
f0e9217a 146static int
e841c3e0 147memoized_print (SCM obj, SCM port, scm_print_state *pstate)
f0e9217a 148{
9882ea19 149 int writingp = SCM_WRITINGP (pstate);
b7f3516f 150 scm_puts ("#<memoized ", port);
9882ea19 151 SCM_SET_WRITINGP (pstate, 1);
33b97402
MD
152#ifdef GUILE_DEBUG
153 scm_iprin1 (SCM_MEMOIZED_EXP (obj), port, pstate);
154#else
9882ea19 155 scm_iprin1 (scm_unmemoize (obj), port, pstate);
33b97402 156#endif
9882ea19 157 SCM_SET_WRITINGP (pstate, writingp);
b7f3516f 158 scm_putc ('>', port);
f0e9217a
MD
159 return 1;
160}
161
a1ec6916 162SCM_DEFINE (scm_memoized_p, "memoized?", 1, 0, 0,
1bbd0b84 163 (SCM obj),
ba94f79e 164 "Return @code{#t} if @var{obj} is memoized.")
1bbd0b84 165#define FUNC_NAME s_scm_memoized_p
f0e9217a 166{
0c95b57d 167 return SCM_BOOL(SCM_MEMOIZEDP (obj));
f0e9217a 168}
1bbd0b84 169#undef FUNC_NAME
f0e9217a 170
f0e9217a 171SCM
1bbd0b84 172scm_make_memoized (SCM exp, SCM env)
f0e9217a 173{
6c179711 174 /* *fixme* Check that env is a valid environment. */
f0e9217a 175 register SCM z, ans;
f83e2737 176 SCM_ENTER_A_SECTION;
cffcab30
DH
177 SCM_NEWSMOB (z, SCM_UNPACK (exp), SCM_UNPACK (env));
178 SCM_NEWSMOB (ans, scm_tc16_memoized, SCM_UNPACK (z));
f83e2737 179 SCM_EXIT_A_SECTION;
f0e9217a
MD
180 return ans;
181}
182
33b97402
MD
183#ifdef GUILE_DEBUG
184/*
185 * Some primitives for construction of memoized code
186 *
187 * - procedure: memcons CAR CDR [ENV]
188 *
189 * Construct a pair, encapsulated in a memoized object.
190 *
191 * The CAR and CDR can be either normal or memoized. If ENV isn't
192 * specified, the top-level environment of the current module will
193 * be assumed. All environments must match.
194 *
33b97402
MD
195 * - procedure: make-iloc FRAME BINDING CDRP
196 *
197 * Return an iloc referring to frame no. FRAME, binding
198 * no. BINDING. If CDRP is non-#f, the iloc is referring to a
199 * frame consisting of a single pair, with the value stored in the
200 * CDR.
201 *
202 * - procedure: iloc? OBJECT
203 *
204 * Return #t if OBJECT is an iloc.
205 *
206 * - procedure: mem->proc MEMOIZED
207 *
208 * Construct a closure from the memoized lambda expression MEMOIZED
209 *
210 * WARNING! The code is not copied!
211 *
212 * - procedure: proc->mem CLOSURE
213 *
214 * Turn the closure CLOSURE into a memoized object.
215 *
216 * WARNING! The code is not copied!
217 *
218 * - constant: SCM_IM_AND
219 * - constant: SCM_IM_BEGIN
220 * - constant: SCM_IM_CASE
221 * - constant: SCM_IM_COND
222 * - constant: SCM_IM_DO
223 * - constant: SCM_IM_IF
224 * - constant: SCM_IM_LAMBDA
225 * - constant: SCM_IM_LET
226 * - constant: SCM_IM_LETSTAR
227 * - constant: SCM_IM_LETREC
228 * - constant: SCM_IM_OR
229 * - constant: SCM_IM_QUOTE
230 * - constant: SCM_IM_SET
231 * - constant: SCM_IM_DEFINE
232 * - constant: SCM_IM_APPLY
233 * - constant: SCM_IM_CONT
bbab09f6 234 * - constant: SCM_IM_DISPATCH
33b97402
MD
235 */
236
a0599745
MD
237#include "libguile/variable.h"
238#include "libguile/procs.h"
33b97402 239
a1ec6916 240SCM_DEFINE (scm_make_iloc, "make-iloc", 3, 0, 0,
1bbd0b84 241 (SCM frame, SCM binding, SCM cdrp),
ba94f79e
MG
242 "Return a new iloc with frame offset @var{frame}, binding\n"
243 "offset @var{binding} and the cdr flag @var{cdrp}.")
1bbd0b84 244#define FUNC_NAME s_scm_make_iloc
33b97402 245{
34d19ef6
HWN
246 SCM_VALIDATE_INUM (1, frame);
247 SCM_VALIDATE_INUM (2, binding);
4ba5f279
MD
248 return SCM_MAKE_ILOC (SCM_INUM (frame),
249 SCM_INUM (binding),
250 !SCM_FALSEP (cdrp));
33b97402 251}
1bbd0b84 252#undef FUNC_NAME
33b97402 253
a1ec6916 254SCM_DEFINE (scm_iloc_p, "iloc?", 1, 0, 0,
1bbd0b84 255 (SCM obj),
ba94f79e 256 "Return @code{#t} if @var{obj} is an iloc.")
0f981281 257#define FUNC_NAME s_scm_iloc_p
33b97402 258{
1bbd0b84 259 return SCM_BOOL(SCM_ILOCP (obj));
33b97402 260}
1bbd0b84 261#undef FUNC_NAME
33b97402 262
a1ec6916 263SCM_DEFINE (scm_memcons, "memcons", 2, 1, 0,
1bbd0b84 264 (SCM car, SCM cdr, SCM env),
ba94f79e
MG
265 "Return a new memoized cons cell with @var{car} and @var{cdr}\n"
266 "as members and @var{env} as the environment.")
1bbd0b84 267#define FUNC_NAME s_scm_memcons
33b97402 268{
0c95b57d 269 if (SCM_MEMOIZEDP (car))
33b97402
MD
270 {
271 /*fixme* environments may be two different but equal top-level envs */
272 if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (car) != env)
e8e9b690 273 SCM_MISC_ERROR ("environment mismatch arg1 <-> arg3",
37c56aec 274 scm_list_2 (car, env));
33b97402
MD
275 else
276 env = SCM_MEMOIZED_ENV (car);
277 car = SCM_MEMOIZED_EXP (car);
278 }
0c95b57d 279 if (SCM_MEMOIZEDP (cdr))
33b97402
MD
280 {
281 if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (cdr) != env)
e8e9b690 282 SCM_MISC_ERROR ("environment mismatch arg2 <-> arg3",
37c56aec 283 scm_list_2 (cdr, env));
33b97402
MD
284 else
285 env = SCM_MEMOIZED_ENV (cdr);
286 cdr = SCM_MEMOIZED_EXP (cdr);
287 }
288 if (SCM_UNBNDP (env))
7e73eaee 289 env = scm_top_level_env (SCM_TOP_LEVEL_LOOKUP_CLOSURE);
33b97402 290 else
34d19ef6 291 SCM_VALIDATE_NULLORCONS (3, env);
33b97402
MD
292 return scm_make_memoized (scm_cons (car, cdr), env);
293}
1bbd0b84 294#undef FUNC_NAME
33b97402 295
a1ec6916 296SCM_DEFINE (scm_mem_to_proc, "mem->proc", 1, 0, 0,
1bbd0b84 297 (SCM obj),
ba94f79e
MG
298 "Convert a memoized object (which must be a lambda expression)\n"
299 "to a procedure.")
1bbd0b84 300#define FUNC_NAME s_scm_mem_to_proc
33b97402
MD
301{
302 SCM env;
34d19ef6 303 SCM_VALIDATE_MEMOIZED (1, obj);
33b97402
MD
304 env = SCM_MEMOIZED_ENV (obj);
305 obj = SCM_MEMOIZED_EXP (obj);
aa5e5d63 306 if (!SCM_CONSP (obj) || !SCM_EQ_P (SCM_CAR (obj), SCM_IM_LAMBDA))
37c56aec 307 SCM_MISC_ERROR ("expected lambda expression", scm_list_1 (obj));
33b97402
MD
308 return scm_closure (SCM_CDR (obj), env);
309}
1bbd0b84 310#undef FUNC_NAME
33b97402 311
a1ec6916 312SCM_DEFINE (scm_proc_to_mem, "proc->mem", 1, 0, 0,
1bbd0b84 313 (SCM obj),
ba94f79e 314 "Convert a procedure to a memoized object.")
1bbd0b84 315#define FUNC_NAME s_scm_proc_to_mem
33b97402 316{
5623a9b4 317 SCM_VALIDATE_CLOSURE (1, obj);
33b97402
MD
318 return scm_make_memoized (scm_cons (SCM_IM_LAMBDA, SCM_CODE (obj)),
319 SCM_ENV (obj));
320}
1bbd0b84 321#undef FUNC_NAME
33b97402
MD
322
323#endif /* GUILE_DEBUG */
324
a1ec6916 325SCM_DEFINE (scm_unmemoize, "unmemoize", 1, 0, 0,
1bbd0b84 326 (SCM m),
ba94f79e 327 "Unmemoize the memoized expression @var{m},")
1bbd0b84 328#define FUNC_NAME s_scm_unmemoize
f0e9217a 329{
34d19ef6 330 SCM_VALIDATE_MEMOIZED (1, m);
bfe3154c 331 return scm_unmemocopy (SCM_MEMOIZED_EXP (m), SCM_MEMOIZED_ENV (m));
f0e9217a 332}
1bbd0b84 333#undef FUNC_NAME
f0e9217a 334
a1ec6916 335SCM_DEFINE (scm_memoized_environment, "memoized-environment", 1, 0, 0,
1bbd0b84 336 (SCM m),
ba94f79e 337 "Return the environment of the memoized expression @var{m}.")
1bbd0b84 338#define FUNC_NAME s_scm_memoized_environment
f0e9217a 339{
34d19ef6 340 SCM_VALIDATE_MEMOIZED (1, m);
bfe3154c 341 return SCM_MEMOIZED_ENV (m);
f0e9217a 342}
1bbd0b84 343#undef FUNC_NAME
f0e9217a 344
a1ec6916 345SCM_DEFINE (scm_procedure_name, "procedure-name", 1, 0, 0,
1bbd0b84 346 (SCM proc),
ba94f79e 347 "Return the name of the procedure @var{proc}")
1bbd0b84 348#define FUNC_NAME s_scm_procedure_name
f0e9217a 349{
34d19ef6 350 SCM_VALIDATE_PROC (1, proc);
f0e9217a 351 switch (SCM_TYP7 (proc)) {
a726dd9d
MD
352 case scm_tcs_subrs:
353 return SCM_SNAME (proc);
354 default:
f0e9217a 355 {
63c51b9a 356 SCM name = scm_procedure_property (proc, scm_sym_name);
f0e9217a 357#if 0
63c51b9a 358 /* Source property scm_sym_procname not implemented yet... */
f9450cdb 359 SCM name = scm_source_property (SCM_CAR (SCM_CLOSURE_BODY (proc)), scm_sym_procname);
f0e9217a 360 if (SCM_FALSEP (name))
63c51b9a 361 name = scm_procedure_property (proc, scm_sym_name);
f0e9217a 362#endif
c75512d6
MD
363 if (SCM_FALSEP (name) && SCM_CLOSUREP (proc))
364 name = scm_reverse_lookup (SCM_ENV (proc), proc);
f0e9217a
MD
365 return name;
366 }
f0e9217a
MD
367 }
368}
1bbd0b84 369#undef FUNC_NAME
f0e9217a 370
a1ec6916 371SCM_DEFINE (scm_procedure_source, "procedure-source", 1, 0, 0,
1bbd0b84 372 (SCM proc),
ba94f79e 373 "Return the source of the procedure @var{proc}.")
1bbd0b84 374#define FUNC_NAME s_scm_procedure_source
f0e9217a 375{
34d19ef6 376 SCM_VALIDATE_NIM (1, proc);
f0e9217a
MD
377 switch (SCM_TYP7 (proc)) {
378 case scm_tcs_closures:
379 {
4daecfee 380 SCM formals = SCM_CLOSURE_FORMALS (proc);
f9450cdb 381 SCM src = scm_source_property (SCM_CLOSURE_BODY (proc), scm_sym_copy);
4daecfee
DH
382 if (!SCM_FALSEP (src))
383 return scm_cons2 (scm_sym_lambda, formals, src);
63c51b9a 384 return scm_cons (scm_sym_lambda,
4daecfee
DH
385 scm_unmemocopy (SCM_CODE (proc),
386 SCM_EXTEND_ENV (formals,
387 SCM_EOL,
388 SCM_ENV (proc))));
f0e9217a 389 }
f0e9217a
MD
390 case scm_tcs_subrs:
391#ifdef CCLO
392 case scm_tc7_cclo:
393#endif
394 /* It would indeed be a nice thing if we supplied source even for
395 built in procedures! */
63c51b9a 396 return scm_procedure_property (proc, scm_sym_source);
f0e9217a 397 default:
276dd677
DH
398 SCM_WRONG_TYPE_ARG (1, proc);
399 /* not reached */
f0e9217a
MD
400 }
401}
1bbd0b84 402#undef FUNC_NAME
f0e9217a 403
a1ec6916 404SCM_DEFINE (scm_procedure_environment, "procedure-environment", 1, 0, 0,
1bbd0b84 405 (SCM proc),
ba94f79e 406 "Return the environment of the procedure @var{proc}.")
1bbd0b84 407#define FUNC_NAME s_scm_procedure_environment
f0e9217a 408{
34d19ef6 409 SCM_VALIDATE_NIM (1, proc);
f0e9217a
MD
410 switch (SCM_TYP7 (proc)) {
411 case scm_tcs_closures:
412 return SCM_ENV (proc);
f0e9217a
MD
413 case scm_tcs_subrs:
414#ifdef CCLO
415 case scm_tc7_cclo:
416#endif
417 return SCM_EOL;
418 default:
276dd677
DH
419 SCM_WRONG_TYPE_ARG (1, proc);
420 /* not reached */
f0e9217a
MD
421 }
422}
1bbd0b84 423#undef FUNC_NAME
f0e9217a 424
bfe3154c 425\f
f0e9217a
MD
426
427/* Eval in a local environment. We would like to have the ability to
e38ecb05
MD
428 * evaluate in a specified local environment, but due to the
429 * memoization this isn't normally possible. We solve it by copying
430 * the code before evaluating. One solution would be to have eval.c
431 * generate yet another evaluator. They are not very big actually.
f0e9217a 432 */
a1ec6916 433SCM_DEFINE (scm_local_eval, "local-eval", 1, 1, 0,
1bbd0b84 434 (SCM exp, SCM env),
b380b885
MD
435 "Evaluate @var{exp} in its environment. If @var{env} is supplied,\n"
436 "it is the environment in which to evaluate @var{exp}. Otherwise,\n"
437 "@var{exp} must be a memoized code object (in which case, its environment\n"
438 "is implicit).")
1bbd0b84 439#define FUNC_NAME s_scm_local_eval
f0e9217a 440{
6c179711
MD
441 if (SCM_UNBNDP (env))
442 {
82b3290d
MD
443 SCM_VALIDATE_MEMOIZED (1, exp);
444 return scm_i_eval_x (SCM_MEMOIZED_EXP (exp), SCM_MEMOIZED_ENV (exp));
6c179711 445 }
82b3290d 446 return scm_i_eval (exp, env);
f0e9217a 447}
1bbd0b84 448#undef FUNC_NAME
f0e9217a 449
c75512d6 450#if 0
1bbd0b84 451SCM_REGISTER_PROC (s_reverse_lookup, "reverse-lookup", 2, 0, 0, scm_reverse_lookup);
c75512d6
MD
452#endif
453
454SCM
455scm_reverse_lookup (SCM env, SCM data)
456{
22a52da1 457 while (SCM_CONSP (env) && SCM_CONSP (SCM_CAR (env)))
c75512d6 458 {
22a52da1
DH
459 SCM names = SCM_CAAR (env);
460 SCM values = SCM_CDAR (env);
0c95b57d 461 while (SCM_CONSP (names))
c75512d6 462 {
cffcab30 463 if (SCM_EQ_P (SCM_CAR (values), data))
c75512d6
MD
464 return SCM_CAR (names);
465 names = SCM_CDR (names);
466 values = SCM_CDR (values);
467 }
22a52da1 468 if (!SCM_NULLP (names) && SCM_EQ_P (values, data))
c75512d6
MD
469 return names;
470 env = SCM_CDR (env);
471 }
472 return SCM_BOOL_F;
473}
474
bfe3154c 475SCM
6e8d25a6 476scm_start_stack (SCM id, SCM exp, SCM env)
bfe3154c
MD
477{
478 SCM answer;
92c2555f
MV
479 scm_t_debug_frame vframe;
480 scm_t_debug_info vframe_vect_body;
9fa2c7b1
MD
481 vframe.prev = scm_last_debug_frame;
482 vframe.status = SCM_VOIDFRAME;
483 vframe.vect = &vframe_vect_body;
484 vframe.vect[0].id = id;
485 scm_last_debug_frame = &vframe;
82b3290d 486 answer = scm_i_eval (exp, env);
9fa2c7b1
MD
487 scm_last_debug_frame = vframe.prev;
488 return answer;
489}
490
b8229a3b
MS
491SCM_SYNTAX(s_start_stack, "start-stack", scm_makacro, scm_m_start_stack);
492
8a04c1a2 493static SCM
6e8d25a6 494scm_m_start_stack (SCM exp, SCM env)
68baa7e7 495#define FUNC_NAME s_start_stack
9fa2c7b1 496{
bfe3154c 497 exp = SCM_CDR (exp);
904a077d
MV
498 if (!SCM_CONSP (exp)
499 || !SCM_CONSP (SCM_CDR (exp))
68baa7e7
DH
500 || !SCM_NULLP (SCM_CDDR (exp)))
501 SCM_WRONG_NUM_ARGS ();
9fa2c7b1 502 return scm_start_stack (scm_eval_car (exp, env), SCM_CADR (exp), env);
bfe3154c 503}
68baa7e7
DH
504#undef FUNC_NAME
505
f0e9217a
MD
506
507/* {Debug Objects}
508 *
509 * The debugging evaluator throws these on frame traps.
510 */
511
92c2555f 512scm_t_bits scm_tc16_debugobj;
f0e9217a 513
f0e9217a 514static int
e81d98ec 515debugobj_print (SCM obj, SCM port, scm_print_state *pstate SCM_UNUSED)
f0e9217a 516{
b7f3516f 517 scm_puts ("#<debug-object ", port);
37c56aec 518 scm_intprint ((long) SCM_DEBUGOBJ_FRAME (obj), 16, port);
b7f3516f 519 scm_putc ('>', port);
f0e9217a
MD
520 return 1;
521}
522
a1ec6916 523SCM_DEFINE (scm_debug_object_p, "debug-object?", 1, 0, 0,
1bbd0b84 524 (SCM obj),
ba94f79e 525 "Return @code{#t} if @var{obj} is a debug object.")
1bbd0b84 526#define FUNC_NAME s_scm_debug_object_p
f0e9217a 527{
0c95b57d 528 return SCM_BOOL(SCM_DEBUGOBJP (obj));
f0e9217a 529}
1bbd0b84 530#undef FUNC_NAME
f0e9217a 531
1cc91f1b 532
f0e9217a 533SCM
92c2555f 534scm_make_debugobj (scm_t_debug_frame *frame)
f0e9217a 535{
228a24ef 536 return scm_cell (scm_tc16_debugobj, (scm_t_bits) frame);
f0e9217a
MD
537}
538
f0e9217a
MD
539\f
540
fe57f652
MD
541/* Undocumented debugging procedure */
542#ifdef GUILE_DEBUG
a1ec6916 543SCM_DEFINE (scm_debug_hang, "debug-hang", 0, 1, 0,
1bbd0b84 544 (SCM obj),
ba94f79e
MG
545 "Go into an endless loop, which can be only terminated with\n"
546 "a debugger.")
1bbd0b84 547#define FUNC_NAME s_scm_debug_hang
e38ecb05
MD
548{
549 int go = 0;
550 while (!go) ;
551 return SCM_UNSPECIFIED;
552}
1bbd0b84 553#undef FUNC_NAME
fe57f652 554#endif
e38ecb05
MD
555
556\f
557
f0e9217a
MD
558void
559scm_init_debug ()
560{
5e8d7fd4 561 scm_init_opts (scm_debug_options, scm_debug_opts, SCM_N_DEBUG_OPTIONS);
ee340120 562
e841c3e0
KN
563 scm_tc16_memoized = scm_make_smob_type ("memoized", 0);
564 scm_set_smob_mark (scm_tc16_memoized, scm_markcdr);
565 scm_set_smob_print (scm_tc16_memoized, memoized_print);
23a62151 566
e841c3e0
KN
567 scm_tc16_debugobj = scm_make_smob_type ("debug-object", 0);
568 scm_set_smob_print (scm_tc16_debugobj, debugobj_print);
f0e9217a 569
33b97402 570#ifdef GUILE_DEBUG
1be6b49c
ML
571 scm_c_define ("SCM_IM_AND", SCM_IM_AND);
572 scm_c_define ("SCM_IM_BEGIN", SCM_IM_BEGIN);
573 scm_c_define ("SCM_IM_CASE", SCM_IM_CASE);
574 scm_c_define ("SCM_IM_COND", SCM_IM_COND);
575 scm_c_define ("SCM_IM_DO", SCM_IM_DO);
576 scm_c_define ("SCM_IM_IF", SCM_IM_IF);
577 scm_c_define ("SCM_IM_LAMBDA", SCM_IM_LAMBDA);
578 scm_c_define ("SCM_IM_LET", SCM_IM_LET);
579 scm_c_define ("SCM_IM_LETSTAR", SCM_IM_LETSTAR);
580 scm_c_define ("SCM_IM_LETREC", SCM_IM_LETREC);
581 scm_c_define ("SCM_IM_OR", SCM_IM_OR);
582 scm_c_define ("SCM_IM_QUOTE", SCM_IM_QUOTE);
583 scm_c_define ("SCM_IM_SET_X", SCM_IM_SET_X);
584 scm_c_define ("SCM_IM_DEFINE", SCM_IM_DEFINE);
585 scm_c_define ("SCM_IM_APPLY", SCM_IM_APPLY);
586 scm_c_define ("SCM_IM_CONT", SCM_IM_CONT);
587 scm_c_define ("SCM_IM_DISPATCH", SCM_IM_DISPATCH);
33b97402 588#endif
f0e9217a
MD
589 scm_add_feature ("debug-extensions");
590
a0599745 591#include "libguile/debug.x"
f0e9217a 592}
89e00824
ML
593
594/*
595 Local Variables:
596 c-file-style: "gnu"
597 End:
598*/