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