* Makefile.am: Added modules.c, modules.x, modules.h.
[bpt/guile.git] / libguile / debug.c
CommitLineData
f0e9217a 1/* Debugging extensions for Guile
7dc6e754 2 * Copyright (C) 1995, 1996, 1997, 1998 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
MD
45
46#include <stdio.h>
47#include "_scm.h"
20e6290e 48#include "eval.h"
a6e350dd 49#include "stackchk.h"
20e6290e
JB
50#include "throw.h"
51#include "genio.h"
41d3b325 52#include "macros.h"
20e6290e
JB
53#include "smob.h"
54#include "procprop.h"
55#include "srcprop.h"
56#include "alist.h"
57#include "continuations.h"
58#include "strports.h"
59#include "read.h"
60#include "feature.h"
260b1416 61#include "dynwind.h"
f0e9217a 62
20e6290e 63#include "debug.h"
f0e9217a
MD
64\f
65
66/* {Run time control of the debugging evaluator}
67 */
68
5e8d7fd4 69SCM_PROC (s_debug_options, "debug-options-interface", 0, 1, 0, scm_debug_options);
1cc91f1b 70
f0e9217a 71SCM
5e8d7fd4
MD
72scm_debug_options (setting)
73 SCM setting;
f0e9217a
MD
74{
75 SCM ans;
76 SCM_DEFER_INTS;
5e8d7fd4
MD
77 ans = scm_options (setting,
78 scm_debug_opts,
79 SCM_N_DEBUG_OPTIONS,
80 s_debug_options);
f0e9217a 81#ifndef SCM_RECKLESS
5e8d7fd4 82 if (!(1 <= SCM_N_FRAMES && SCM_N_FRAMES <= SCM_MAX_FRAME_SIZE))
f0e9217a 83 {
5e8d7fd4 84 scm_options (ans, scm_debug_opts, SCM_N_DEBUG_OPTIONS, s_debug_options);
52859adf 85 scm_out_of_range (s_debug_options, setting);
f0e9217a
MD
86 }
87#endif
5e8d7fd4 88 SCM_RESET_DEBUG_MODE;
a6e350dd 89 scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P;
5e8d7fd4 90 scm_debug_eframe_size = 2 * SCM_N_FRAMES;
f0e9217a
MD
91 SCM_ALLOW_INTS
92 return ans;
93}
94
260b1416
MD
95SCM_PROC (s_with_traps, "with-traps", 1, 0, 0, scm_with_traps);
96
97static void
98with_traps_before (void *data)
99{
100 int *trap_flag = data;
101 *trap_flag = SCM_TRAPS_P;
102 SCM_TRAPS_P = 1;
103}
104
105static void
106with_traps_after (void *data)
107{
108 int *trap_flag = data;
109 SCM_TRAPS_P = *trap_flag;
110}
111
112static SCM
113with_traps_inner (void *data)
114{
115 SCM thunk = (SCM) data;
116 return scm_apply (thunk, SCM_EOL, SCM_EOL);
117}
1cc91f1b 118
f0e9217a 119SCM
260b1416 120scm_with_traps (SCM thunk)
f0e9217a 121{
260b1416
MD
122 int trap_flag;
123 SCM_ASSERT (SCM_NFALSEP (scm_thunk_p (thunk)),
124 thunk,
125 SCM_ARG1,
126 s_with_traps);
127 return scm_internal_dynamic_wind (with_traps_before,
128 with_traps_inner,
129 with_traps_after,
130 (void *) thunk,
131 &trap_flag);
f0e9217a
MD
132}
133
134\f
135static SCM scm_i_source, scm_i_more;
136static SCM scm_i_proc, scm_i_args, scm_i_eval_args;
137static SCM scm_i_procname;
138
139/* {Memoized Source}
140 */
141
142long scm_tc16_memoized;
143
1cc91f1b
JB
144
145static int prinmemoized SCM_P ((SCM obj, SCM port, scm_print_state *pstate));
146
f0e9217a 147static int
9882ea19 148prinmemoized (obj, port, pstate)
f0e9217a
MD
149 SCM obj;
150 SCM port;
9882ea19 151 scm_print_state *pstate;
f0e9217a 152{
9882ea19 153 int writingp = SCM_WRITINGP (pstate);
b7f3516f 154 scm_puts ("#<memoized ", port);
9882ea19 155 SCM_SET_WRITINGP (pstate, 1);
33b97402
MD
156#ifdef GUILE_DEBUG
157 scm_iprin1 (SCM_MEMOIZED_EXP (obj), port, pstate);
158#else
9882ea19 159 scm_iprin1 (scm_unmemoize (obj), port, pstate);
33b97402 160#endif
9882ea19 161 SCM_SET_WRITINGP (pstate, writingp);
b7f3516f 162 scm_putc ('>', port);
f0e9217a
MD
163 return 1;
164}
165
166static scm_smobfuns memoizedsmob =
167{scm_markcdr, scm_free0, prinmemoized, 0};
168
169SCM_PROC (s_memoized_p, "memoized?", 1, 0, 0, scm_memoized_p);
1cc91f1b 170
f0e9217a
MD
171SCM
172scm_memoized_p (obj)
173 SCM obj;
f0e9217a
MD
174{
175 return SCM_NIMP (obj) && SCM_MEMOIZEDP (obj) ? SCM_BOOL_T : SCM_BOOL_F;
176}
177
f0e9217a 178SCM
bba4bfdb 179scm_make_memoized (exp, env)
1cc91f1b
JB
180 SCM exp;
181 SCM env;
f0e9217a 182{
6c179711 183 /* *fixme* Check that env is a valid environment. */
f0e9217a 184 register SCM z, ans;
f83e2737 185 SCM_ENTER_A_SECTION;
f0e9217a 186 SCM_NEWCELL (z);
a6c64c3c 187 SCM_SETCDR (z, env);
f83e2737 188 SCM_SETCAR (z, exp);
f0e9217a 189 SCM_NEWCELL (ans);
a6c64c3c 190 SCM_SETCDR (ans, z);
f83e2737
MD
191 SCM_SETCAR (ans, scm_tc16_memoized);
192 SCM_EXIT_A_SECTION;
f0e9217a
MD
193 return ans;
194}
195
33b97402
MD
196#ifdef GUILE_DEBUG
197/*
198 * Some primitives for construction of memoized code
199 *
200 * - procedure: memcons CAR CDR [ENV]
201 *
202 * Construct a pair, encapsulated in a memoized object.
203 *
204 * The CAR and CDR can be either normal or memoized. If ENV isn't
205 * specified, the top-level environment of the current module will
206 * be assumed. All environments must match.
207 *
208 * - procedure: make-gloc VARIABLE [ENV]
209 *
210 * Return a gloc, encapsulated in a memoized object.
211 *
212 * (Glocs can't exist in normal list structures, since they will
213 * be mistaken for structs.)
214 *
215 * - procedure: gloc? OBJECT
216 *
217 * Return #t if OBJECT is a memoized gloc.
218 *
219 * - procedure: make-iloc FRAME BINDING CDRP
220 *
221 * Return an iloc referring to frame no. FRAME, binding
222 * no. BINDING. If CDRP is non-#f, the iloc is referring to a
223 * frame consisting of a single pair, with the value stored in the
224 * CDR.
225 *
226 * - procedure: iloc? OBJECT
227 *
228 * Return #t if OBJECT is an iloc.
229 *
230 * - procedure: mem->proc MEMOIZED
231 *
232 * Construct a closure from the memoized lambda expression MEMOIZED
233 *
234 * WARNING! The code is not copied!
235 *
236 * - procedure: proc->mem CLOSURE
237 *
238 * Turn the closure CLOSURE into a memoized object.
239 *
240 * WARNING! The code is not copied!
241 *
242 * - constant: SCM_IM_AND
243 * - constant: SCM_IM_BEGIN
244 * - constant: SCM_IM_CASE
245 * - constant: SCM_IM_COND
246 * - constant: SCM_IM_DO
247 * - constant: SCM_IM_IF
248 * - constant: SCM_IM_LAMBDA
249 * - constant: SCM_IM_LET
250 * - constant: SCM_IM_LETSTAR
251 * - constant: SCM_IM_LETREC
252 * - constant: SCM_IM_OR
253 * - constant: SCM_IM_QUOTE
254 * - constant: SCM_IM_SET
255 * - constant: SCM_IM_DEFINE
256 * - constant: SCM_IM_APPLY
257 * - constant: SCM_IM_CONT
258 */
259
260#include "variable.h"
261#include "procs.h"
262
263SCM_PROC (s_make_gloc, "make-gloc", 1, 1, 0, scm_make_gloc);
264
265SCM
266scm_make_gloc (var, env)
267 SCM var;
268 SCM env;
269{
270#if 1 /* Unsafe */
271 if (SCM_NIMP (var) && SCM_CONSP (var))
272 var = scm_cons (SCM_BOOL_F, var);
273 else
274#endif
275 SCM_ASSERT (SCM_NIMP (var) && SCM_VARIABLEP (var),
276 var,
277 SCM_ARG1,
278 s_make_gloc);
279 if (SCM_UNBNDP (env))
280 env = scm_top_level_env (SCM_CDR (scm_top_level_lookup_closure_var));
281 else
282 SCM_ASSERT (SCM_NULLP (env) || (SCM_NIMP (env) && SCM_CONSP (env)),
283 env,
284 SCM_ARG2,
285 s_make_gloc);
286 return scm_make_memoized (SCM_VARVCELL (var) + 1, env);
287}
288
289SCM_PROC (s_gloc_p, "gloc?", 1, 0, 0, scm_gloc_p);
290
291SCM
292scm_gloc_p (obj)
293 SCM obj;
294{
295 return ((SCM_NIMP (obj)
296 && SCM_MEMOIZEDP (obj)
297 && (SCM_MEMOIZED_EXP (obj) & 7) == 1)
298 ? SCM_BOOL_T
299 : SCM_BOOL_F);
300}
301
302SCM_PROC (s_make_iloc, "make-iloc", 3, 0, 0, scm_make_iloc);
303
304SCM
305scm_make_iloc (frame, binding, cdrp)
306 SCM frame;
307 SCM binding;
308 SCM cdrp;
309{
310 SCM_ASSERT (SCM_INUMP (frame), frame, SCM_ARG1, s_make_iloc);
311 SCM_ASSERT (SCM_INUMP (binding), binding, SCM_ARG2, s_make_iloc);
312 return (SCM_ILOC00
313 + SCM_IFRINC * SCM_INUM (frame)
314 + (SCM_NFALSEP (cdrp) ? SCM_ICDR : 0)
315 + SCM_IDINC * SCM_INUM (binding));
316}
317
318SCM_PROC (s_iloc_p, "iloc?", 1, 0, 0, scm_iloc_p);
319
320SCM
321scm_iloc_p (obj)
322 SCM obj;
323{
324 return SCM_ILOCP (obj) ? SCM_BOOL_T : SCM_BOOL_F;
325}
326
327SCM_PROC (s_memcons, "memcons", 2, 1, 0, scm_memcons);
328
329SCM
330scm_memcons (car, cdr, env)
331 SCM car;
332 SCM cdr;
333 SCM env;
334{
335 if (SCM_NIMP (car) && SCM_MEMOIZEDP (car))
336 {
337 /*fixme* environments may be two different but equal top-level envs */
338 if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (car) != env)
339 scm_misc_error (s_memcons,
340 "environment mismatch arg1 <-> arg3",
341 scm_cons2 (car, env, SCM_EOL));
342 else
343 env = SCM_MEMOIZED_ENV (car);
344 car = SCM_MEMOIZED_EXP (car);
345 }
346 if (SCM_NIMP (cdr) && SCM_MEMOIZEDP (cdr))
347 {
348 if (!SCM_UNBNDP (env) && SCM_MEMOIZED_ENV (cdr) != env)
349 scm_misc_error (s_memcons,
350 "environment mismatch arg2 <-> arg3",
351 scm_cons2 (cdr, env, SCM_EOL));
352 else
353 env = SCM_MEMOIZED_ENV (cdr);
354 cdr = SCM_MEMOIZED_EXP (cdr);
355 }
356 if (SCM_UNBNDP (env))
357 env = scm_top_level_env (SCM_CDR (scm_top_level_lookup_closure_var));
358 else
359 SCM_ASSERT (SCM_NULLP (env) || (SCM_NIMP (env) && SCM_CONSP (env)),
360 env,
361 SCM_ARG3,
362 s_make_iloc);
363 return scm_make_memoized (scm_cons (car, cdr), env);
364}
365
366SCM_PROC (s_mem_to_proc, "mem->proc", 1, 0, 0, scm_mem_to_proc);
367
368SCM
369scm_mem_to_proc (obj)
370 SCM obj;
371{
372 SCM env;
373 SCM_ASSERT (SCM_NIMP (obj) && SCM_MEMOIZEDP (obj),
374 obj,
375 SCM_ARG1,
376 s_mem_to_proc);
377 env = SCM_MEMOIZED_ENV (obj);
378 obj = SCM_MEMOIZED_EXP (obj);
379 if (!(SCM_NIMP (obj) && SCM_CAR (obj) == SCM_IM_LAMBDA))
380 scm_misc_error (s_mem_to_proc,
381 "expected lambda expression",
382 scm_cons (obj, SCM_EOL));
383 return scm_closure (SCM_CDR (obj), env);
384}
385
386SCM_PROC (s_proc_to_mem, "proc->mem", 1, 0, 0, scm_proc_to_mem);
387
388SCM
389scm_proc_to_mem (obj)
390 SCM obj;
391{
392 SCM_ASSERT (SCM_NIMP (obj) && SCM_CLOSUREP (obj),
393 obj,
394 SCM_ARG1,
395 s_proc_to_mem);
396 return scm_make_memoized (scm_cons (SCM_IM_LAMBDA, SCM_CODE (obj)),
397 SCM_ENV (obj));
398}
399
400#endif /* GUILE_DEBUG */
401
f0e9217a 402SCM_PROC (s_unmemoize, "unmemoize", 1, 0, 0, scm_unmemoize);
1cc91f1b 403
f0e9217a
MD
404SCM
405scm_unmemoize (m)
406 SCM m;
f0e9217a 407{
6c179711 408 SCM_ASSERT (SCM_NIMP (m) && SCM_MEMOIZEDP (m), m, SCM_ARG1, s_unmemoize);
bfe3154c 409 return scm_unmemocopy (SCM_MEMOIZED_EXP (m), SCM_MEMOIZED_ENV (m));
f0e9217a
MD
410}
411
412SCM_PROC (s_memoized_environment, "memoized-environment", 1, 0, 0, scm_memoized_environment);
1cc91f1b 413
f0e9217a
MD
414SCM
415scm_memoized_environment (m)
416 SCM m;
f0e9217a 417{
6c179711 418 SCM_ASSERT (SCM_NIMP (m) && SCM_MEMOIZEDP (m), m, SCM_ARG1, s_unmemoize);
bfe3154c 419 return SCM_MEMOIZED_ENV (m);
f0e9217a
MD
420}
421
422SCM_PROC (s_procedure_name, "procedure-name", 1, 0, 0, scm_procedure_name);
1cc91f1b 423
f0e9217a
MD
424SCM
425scm_procedure_name (proc)
426 SCM proc;
f0e9217a
MD
427{
428 SCM_ASSERT(scm_procedure_p (proc) == SCM_BOOL_T,
429 proc,
430 SCM_ARG1,
431 s_procedure_name);
432 switch (SCM_TYP7 (proc)) {
433 case scm_tcs_closures:
c6b8a41a 434 case scm_tc7_cclo:
f0e9217a
MD
435 {
436 SCM name = scm_procedure_property (proc, scm_i_name);
437#if 0
80ea260c 438 /* Source property scm_i_procname not implemented yet... */
f0e9217a
MD
439 SCM name = scm_source_property (SCM_CAR (SCM_CDR (SCM_CODE (proc))), scm_i_procname);
440 if (SCM_FALSEP (name))
441 name = scm_procedure_property (proc, scm_i_name);
442#endif
80ea260c
MD
443 if (SCM_FALSEP (name))
444 name = scm_procedure_property (proc, scm_i_inner_name);
f0e9217a
MD
445 return name;
446 }
447 case scm_tcs_subrs:
448 return SCM_SNAME (proc);
449 default:
450 return SCM_BOOL_F;
451 }
452}
453
454SCM_PROC (s_procedure_source, "procedure-source", 1, 0, 0, scm_procedure_source);
1cc91f1b 455
f0e9217a
MD
456SCM
457scm_procedure_source (proc)
458 SCM proc;
f0e9217a
MD
459{
460 SCM_ASSERT(SCM_NIMP (proc), proc, SCM_ARG1, s_procedure_source);
461 switch (SCM_TYP7 (proc)) {
462 case scm_tcs_closures:
463 {
464 SCM src;
465 src = scm_source_property (SCM_CDR (SCM_CODE (proc)), scm_i_copy);
466 if (src != SCM_BOOL_F)
467 return scm_cons2 (scm_i_lambda, SCM_CAR (SCM_CODE (proc)), src);
468 src = SCM_CODE (proc);
469 return scm_cons (scm_i_lambda,
470 scm_unmemocopy (src,
e2806c10 471 SCM_EXTEND_ENV (SCM_CAR (src),
f0e9217a
MD
472 SCM_EOL,
473 SCM_ENV (proc))));
474 }
475 case scm_tc7_contin:
476 case scm_tcs_subrs:
477#ifdef CCLO
478 case scm_tc7_cclo:
479#endif
480 /* It would indeed be a nice thing if we supplied source even for
481 built in procedures! */
482 return scm_procedure_property (proc, scm_i_source);
483 default:
484 scm_wta (proc, (char *) SCM_ARG1, s_procedure_source);
485 return 0;
486 }
487}
488
489SCM_PROC (s_procedure_environment, "procedure-environment", 1, 0, 0, scm_procedure_environment);
1cc91f1b 490
f0e9217a
MD
491SCM
492scm_procedure_environment (proc)
493 SCM proc;
f0e9217a
MD
494{
495 SCM_ASSERT (SCM_NIMP (proc), proc, SCM_ARG1, s_procedure_environment);
496 switch (SCM_TYP7 (proc)) {
497 case scm_tcs_closures:
498 return SCM_ENV (proc);
499 case scm_tc7_contin:
500 case scm_tcs_subrs:
501#ifdef CCLO
502 case scm_tc7_cclo:
503#endif
504 return SCM_EOL;
505 default:
506 scm_wta (proc, (char *) SCM_ARG1, s_procedure_environment);
507 return 0;
508 }
509}
510
bfe3154c 511\f
f0e9217a
MD
512
513/* Eval in a local environment. We would like to have the ability to
e38ecb05
MD
514 * evaluate in a specified local environment, but due to the
515 * memoization this isn't normally possible. We solve it by copying
516 * the code before evaluating. One solution would be to have eval.c
517 * generate yet another evaluator. They are not very big actually.
f0e9217a 518 */
6c179711 519SCM_PROC (s_local_eval, "local-eval", 1, 1, 0, scm_local_eval);
1cc91f1b 520
f0e9217a
MD
521SCM
522scm_local_eval (exp, env)
523 SCM exp;
524 SCM env;
f0e9217a 525{
6c179711
MD
526 if (SCM_UNBNDP (env))
527 {
b210cb73 528 SCM_ASSERT (SCM_NIMP (exp) && SCM_MEMOIZEDP (exp), exp, SCM_ARG1, s_local_eval);
6c179711
MD
529 return scm_eval_3 (SCM_MEMOIZED_EXP (exp), 0, SCM_MEMOIZED_ENV (exp));
530 }
f0e9217a
MD
531 return scm_eval_3 (exp, 1, env);
532}
533
bfe3154c 534SCM
9fa2c7b1
MD
535scm_start_stack (id, exp, env)
536 SCM id;
bfe3154c
MD
537 SCM exp;
538 SCM env;
539{
540 SCM answer;
c6b8a41a 541 scm_debug_frame vframe;
c0ab1b8d 542 scm_debug_info vframe_vect_body;
9fa2c7b1
MD
543 vframe.prev = scm_last_debug_frame;
544 vframe.status = SCM_VOIDFRAME;
545 vframe.vect = &vframe_vect_body;
546 vframe.vect[0].id = id;
547 scm_last_debug_frame = &vframe;
cb412265 548 answer = scm_eval_3 (exp, 1, env);
9fa2c7b1
MD
549 scm_last_debug_frame = vframe.prev;
550 return answer;
551}
552
553static char s_start_stack[] = "start-stack";
8a04c1a2 554static SCM
9fa2c7b1
MD
555scm_m_start_stack (exp, env)
556 SCM exp;
557 SCM env;
558{
bfe3154c 559 exp = SCM_CDR (exp);
c6b8a41a 560 SCM_ASSERT (SCM_NIMP (exp)
e38ecb05 561 && SCM_ECONSP (exp)
c6b8a41a 562 && SCM_NIMP (SCM_CDR (exp))
e38ecb05 563 && SCM_ECONSP (SCM_CDR (exp))
c6b8a41a 564 && SCM_NULLP (SCM_CDDR (exp)),
bfe3154c
MD
565 exp,
566 SCM_WNA,
567 s_start_stack);
9fa2c7b1 568 return scm_start_stack (scm_eval_car (exp, env), SCM_CADR (exp), env);
bfe3154c 569}
f0e9217a
MD
570
571/* {Debug Objects}
572 *
573 * The debugging evaluator throws these on frame traps.
574 */
575
576long scm_tc16_debugobj;
577
1cc91f1b
JB
578static int prindebugobj SCM_P ((SCM obj, SCM port, scm_print_state *pstate));
579
f0e9217a 580static int
1cc91f1b 581prindebugobj (obj, port, pstate)
9882ea19
MD
582 SCM obj;
583 SCM port;
584 scm_print_state *pstate;
f0e9217a 585{
b7f3516f 586 scm_puts ("#<debug-object ", port);
bfe3154c 587 scm_intprint (SCM_DEBUGOBJ_FRAME (obj), 16, port);
b7f3516f 588 scm_putc ('>', port);
f0e9217a
MD
589 return 1;
590}
591
592static scm_smobfuns debugobjsmob =
dc53f026 593{0, scm_free0, prindebugobj, 0};
f0e9217a
MD
594
595SCM_PROC (s_debug_object_p, "debug-object?", 1, 0, 0, scm_debug_object_p);
1cc91f1b 596
f0e9217a
MD
597SCM
598scm_debug_object_p (obj)
599 SCM obj;
f0e9217a 600{
bfe3154c 601 return SCM_NIMP (obj) && SCM_DEBUGOBJP (obj) ? SCM_BOOL_T : SCM_BOOL_F;
f0e9217a
MD
602}
603
1cc91f1b 604
f0e9217a
MD
605SCM
606scm_make_debugobj (frame)
607 scm_debug_frame *frame;
f0e9217a
MD
608{
609 register SCM z;
f0e9217a 610 SCM_NEWCELL (z);
f83e2737 611 SCM_ENTER_A_SECTION;
a6c64c3c 612 SCM_SET_DEBUGOBJ_FRAME (z, (SCM) frame);
f83e2737
MD
613 SCM_SETCAR (z, scm_tc16_debugobj);
614 SCM_EXIT_A_SECTION;
f0e9217a
MD
615 return z;
616}
617
f0e9217a
MD
618\f
619
fe57f652
MD
620/* Undocumented debugging procedure */
621#ifdef GUILE_DEBUG
e38ecb05
MD
622SCM_PROC (s_debug_hang, "debug-hang", 0, 1, 0, scm_debug_hang);
623
624SCM
625scm_debug_hang (obj)
626 SCM obj;
627{
628 int go = 0;
629 while (!go) ;
630 return SCM_UNSPECIFIED;
631}
fe57f652 632#endif
e38ecb05
MD
633
634\f
635
f0e9217a
MD
636void
637scm_init_debug ()
638{
5e8d7fd4 639 scm_init_opts (scm_debug_options, scm_debug_opts, SCM_N_DEBUG_OPTIONS);
ee340120 640
f0e9217a
MD
641 scm_tc16_memoized = scm_newsmob (&memoizedsmob);
642 scm_tc16_debugobj = scm_newsmob (&debugobjsmob);
643
644 scm_i_procname = SCM_CAR (scm_sysintern ("procname", SCM_UNDEFINED));
645 scm_i_more = SCM_CAR (scm_sysintern ("...", SCM_UNDEFINED));
646 scm_i_source = SCM_CAR (scm_sysintern ("source", SCM_UNDEFINED));
647 scm_i_proc = SCM_CAR (scm_sysintern ("proc", SCM_UNDEFINED));
648 scm_i_args = SCM_CAR (scm_sysintern ("args", SCM_UNDEFINED));
649 scm_i_eval_args = SCM_CAR (scm_sysintern ("eval-args", SCM_UNDEFINED));
650
bfe3154c 651 scm_make_synt (s_start_stack, scm_makacro, scm_m_start_stack);
33b97402
MD
652
653#ifdef GUILE_DEBUG
654 scm_sysintern ("SCM_IM_AND", SCM_IM_AND);
655 scm_sysintern ("SCM_IM_BEGIN", SCM_IM_BEGIN);
656 scm_sysintern ("SCM_IM_CASE", SCM_IM_CASE);
657 scm_sysintern ("SCM_IM_COND", SCM_IM_COND);
658 scm_sysintern ("SCM_IM_DO", SCM_IM_DO);
659 scm_sysintern ("SCM_IM_IF", SCM_IM_IF);
660 scm_sysintern ("SCM_IM_LAMBDA", SCM_IM_LAMBDA);
661 scm_sysintern ("SCM_IM_LET", SCM_IM_LET);
662 scm_sysintern ("SCM_IM_LETSTAR", SCM_IM_LETSTAR);
663 scm_sysintern ("SCM_IM_LETREC", SCM_IM_LETREC);
664 scm_sysintern ("SCM_IM_OR", SCM_IM_OR);
665 scm_sysintern ("SCM_IM_QUOTE", SCM_IM_QUOTE);
666 scm_sysintern ("SCM_IM_SET", SCM_IM_SET);
667 scm_sysintern ("SCM_IM_DEFINE", SCM_IM_DEFINE);
668 scm_sysintern ("SCM_IM_APPLY", SCM_IM_APPLY);
669 scm_sysintern ("SCM_IM_CONT", SCM_IM_CONT);
670#endif
f0e9217a
MD
671 scm_add_feature ("debug-extensions");
672
673#include "debug.x"
674}