/* Debugging extensions for Guile
- * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006, 2008, 2009 Free Software Foundation
+ * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006, 2008, 2009, 2010, 2011, 2012 Free Software Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#include "libguile/throw.h"
#include "libguile/macros.h"
#include "libguile/smob.h"
+#include "libguile/struct.h"
#include "libguile/procprop.h"
#include "libguile/srcprop.h"
#include "libguile/alist.h"
\f
+/*
+ * Debugging options.
+ */
+
+scm_t_option scm_debug_opts[] = {
+ { SCM_OPTION_BOOLEAN, "backwards", 0,
+ "Display backtrace in anti-chronological order." },
+ { SCM_OPTION_INTEGER, "width", 79, "Maximal width of backtrace." },
+ { SCM_OPTION_INTEGER, "depth", 20, "Maximal length of printed backtrace." },
+ { SCM_OPTION_BOOLEAN, "backtrace", 1, "Show backtrace on error." },
+ /* This default stack limit will be overridden by init_stack_limit(),
+ if we have getrlimit() and the stack limit is not INFINITY. But it is still
+ important, as some systems have both the soft and the hard limits set to
+ INFINITY; in that case we fall back to this value.
+
+ The situation is aggravated by certain compilers, which can consume
+ "beaucoup de stack", as they say in France.
+
+ See http://thread.gmane.org/gmane.lisp.guile.devel/8599/focus=8662 for
+ more discussion. This setting is 640 KB on 32-bit arches (should be enough
+ for anyone!) or a whoppin' 1280 KB on 64-bit arches.
+ */
+ { SCM_OPTION_INTEGER, "stack", 160000, "Stack size limit (measured in words; 0 = no check)." },
+ { SCM_OPTION_SCM, "show-file-name", SCM_BOOL_T_BITS,
+ "Show file names and line numbers "
+ "in backtraces when not `#f'. A value of `base' "
+ "displays only base names, while `#t' displays full names."},
+ { SCM_OPTION_BOOLEAN, "warn-deprecated", 0,
+ "Warn when deprecated features are used." },
+ { 0 },
+};
+
+
/* {Run time control of the debugging evaluator}
*/
scm_dynwind_critical_section (SCM_BOOL_F);
ans = scm_options (setting, scm_debug_opts, FUNC_NAME);
- if (SCM_N_FRAMES < 1)
- {
- scm_options (ans, scm_debug_opts, FUNC_NAME);
- SCM_OUT_OF_RANGE (1, setting);
- }
#ifdef STACK_CHECKING
scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P;
#endif
}
#undef FUNC_NAME
-
-static void
-with_traps_before (void *data)
-{
- int *trap_flag = data;
- *trap_flag = SCM_TRAPS_P;
- SCM_TRAPS_P = 1;
-}
-
-static void
-with_traps_after (void *data)
-{
- int *trap_flag = data;
- SCM_TRAPS_P = *trap_flag;
-}
-
-static SCM
-with_traps_inner (void *data)
-{
- SCM thunk = SCM_PACK ((scm_t_bits) data);
- return scm_call_0 (thunk);
-}
-
-SCM_DEFINE (scm_with_traps, "with-traps", 1, 0, 0,
- (SCM thunk),
- "Call @var{thunk} with traps enabled.")
-#define FUNC_NAME s_scm_with_traps
-{
- int trap_flag;
- SCM_VALIDATE_THUNK (1, thunk);
- return scm_internal_dynamic_wind (with_traps_before,
- with_traps_inner,
- with_traps_after,
- (void *) SCM_UNPACK (thunk),
- &trap_flag);
-}
-#undef FUNC_NAME
-
\f
-SCM_SYMBOL (scm_sym_procname, "procname");
-SCM_SYMBOL (scm_sym_dots, "...");
SCM_SYMBOL (scm_sym_source, "source");
SCM_DEFINE (scm_procedure_name, "procedure-name", 1, 0, 0,
#define FUNC_NAME s_scm_procedure_name
{
SCM_VALIDATE_PROC (1, proc);
- switch (SCM_TYP7 (proc)) {
- case scm_tc7_gsubr:
- return SCM_SUBR_NAME (proc);
- default:
- {
- SCM name = scm_procedure_property (proc, scm_sym_name);
-#if 0
- /* Source property scm_sym_procname not implemented yet... */
- SCM name = scm_source_property (SCM_CAR (SCM_CLOSURE_BODY (proc)), scm_sym_procname);
- if (scm_is_false (name))
- name = scm_procedure_property (proc, scm_sym_name);
-#endif
- if (scm_is_false (name) && SCM_CLOSUREP (proc))
- name = scm_reverse_lookup (SCM_ENV (proc), proc);
- if (scm_is_false (name) && SCM_PROGRAM_P (proc))
- name = scm_program_name (proc);
- return name;
- }
- }
+ while (SCM_STRUCTP (proc) && SCM_STRUCT_APPLICABLE_P (proc))
+ proc = SCM_STRUCT_PROCEDURE (proc);
+ return scm_procedure_property (proc, scm_sym_name);
}
#undef FUNC_NAME
break;
proc = SCM_STRUCT_PROCEDURE (proc);
continue;
- case scm_tc7_pws:
- proc = SCM_PROCEDURE (proc);
- continue;
default:
break;
}
}
#undef FUNC_NAME
-SCM_DEFINE (scm_procedure_module, "procedure-module", 1, 0, 0,
- (SCM proc),
- "Return the module that was current when @var{proc} was defined.")
-#define FUNC_NAME s_scm_procedure_module
-{
- SCM_VALIDATE_PROC (SCM_ARG1, proc);
-
- if (scm_is_true (scm_program_p (proc)))
- return scm_program_module (proc);
- else if (SCM_CLOSUREP (proc))
- {
- SCM env = SCM_ENV (proc);
- while (scm_is_pair (env))
- env = scm_cdr (env);
- return env;
- }
- else
- return SCM_BOOL_F;
-}
-#undef FUNC_NAME
-
\f
return SCM_BOOL_F;
}
-SCM_DEFINE (scm_sys_start_stack, "%start-stack", 2, 0, 0,
- (SCM id, SCM thunk),
- "Call @var{thunk} on an evaluator stack tagged with @var{id}.")
-#define FUNC_NAME s_scm_sys_start_stack
-{
- return scm_vm_call_with_new_stack (scm_the_vm (), thunk, id);
-}
-#undef FUNC_NAME
-
\f
/* Undocumented debugging procedure */
#undef FUNC_NAME
#endif
+SCM
+scm_local_eval (SCM exp, SCM env)
+{
+ static SCM local_eval_var = SCM_UNDEFINED;
+ static scm_i_pthread_mutex_t local_eval_var_mutex
+ = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+
+ scm_i_scm_pthread_mutex_lock (&local_eval_var_mutex);
+ if (SCM_UNBNDP (local_eval_var))
+ local_eval_var = scm_c_public_variable ("ice-9 local-eval", "local-eval");
+ scm_i_pthread_mutex_unlock (&local_eval_var_mutex);
+
+ return scm_call_2 (SCM_VARIABLE_REF (local_eval_var), exp, env);
+}
+
static void
init_stack_limit (void)
{