Merge commit 'e20d7001c3f7150400169fecb0bf0eefdf122fe2' into vm-check
[bpt/guile.git] / libguile / debug.c
index ca9d085..5d0e208 100644 (file)
@@ -1,5 +1,5 @@
 /* Debugging extensions for Guile
- * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003 Free Software Foundation
+ * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2006, 2008, 2009 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
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include "libguile/_scm.h"
+#include "libguile/async.h"
 #include "libguile/eval.h"
 #include "libguile/list.h"
 #include "libguile/stackchk.h"
 #include "libguile/root.h"
 #include "libguile/fluids.h"
 #include "libguile/objects.h"
+#include "libguile/programs.h"
 
 #include "libguile/validate.h"
 #include "libguile/debug.h"
+
+#include "libguile/private-options.h"
 \f
 
+
 /* {Run time control of the debugging evaluator}
  */
 
@@ -54,21 +62,28 @@ SCM_DEFINE (scm_debug_options, "debug-options-interface", 0, 1, 0,
 #define FUNC_NAME s_scm_debug_options
 {
   SCM ans;
-  SCM_DEFER_INTS;
-  ans = scm_options (setting, scm_debug_opts, SCM_N_DEBUG_OPTIONS, FUNC_NAME);
+
+  scm_dynwind_begin (0);
+  scm_dynwind_critical_section (SCM_BOOL_F);
+
+  ans = scm_options (setting, scm_debug_opts, FUNC_NAME);
   if (!(1 <= SCM_N_FRAMES && SCM_N_FRAMES <= SCM_MAX_FRAME_SIZE))
     {
-      scm_options (ans, scm_debug_opts, SCM_N_DEBUG_OPTIONS, FUNC_NAME);
+      scm_options (ans, scm_debug_opts, FUNC_NAME);
       SCM_OUT_OF_RANGE (1, setting);
     }
   SCM_RESET_DEBUG_MODE;
+#ifdef STACK_CHECKING
   scm_stack_checking_enabled_p = SCM_STACK_CHECKING_P;
+#endif
   scm_debug_eframe_size = 2 * SCM_N_FRAMES;
-  SCM_ALLOW_INTS;
+
+  scm_dynwind_end ();
   return ans;
 }
 #undef FUNC_NAME
 
+
 static void
 with_traps_before (void *data)
 {
@@ -107,7 +122,6 @@ SCM_DEFINE (scm_with_traps, "with-traps", 1, 0, 0,
 #undef FUNC_NAME
 
 \f
-
 SCM_SYMBOL (scm_sym_procname, "procname");
 SCM_SYMBOL (scm_sym_dots, "...");
 SCM_SYMBOL (scm_sym_source, "source");
@@ -142,12 +156,7 @@ SCM
 scm_make_memoized (SCM exp, SCM env)
 {
   /* *fixme* Check that env is a valid environment. */
-  register SCM z, ans;
-  SCM_ENTER_A_SECTION;
-  SCM_NEWSMOB (z, SCM_UNPACK (exp), SCM_UNPACK (env));
-  SCM_NEWSMOB (ans, scm_tc16_memoized, SCM_UNPACK (z));
-  SCM_EXIT_A_SECTION;
-  return ans;
+  SCM_RETURN_NEWSMOB (scm_tc16_memoized, SCM_UNPACK (scm_cons (exp, env)));
 }
 
 #ifdef GUILE_DEBUG
@@ -306,6 +315,8 @@ SCM_DEFINE (scm_procedure_name, "procedure-name", 1, 0, 0,
 #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;
     }
   }
@@ -346,9 +357,6 @@ SCM_DEFINE (scm_procedure_source, "procedure-source", 1, 0, 0,
     if (!SCM_SMOB_DESCRIPTOR (proc).apply)
       break;
   case scm_tcs_subrs:
-#ifdef CCLO
-  case scm_tc7_cclo:
-#endif
   procprop:
     /* It would indeed be a nice thing if we supplied source even for
        built in procedures! */
@@ -379,9 +387,6 @@ SCM_DEFINE (scm_procedure_environment, "procedure-environment", 1, 0, 0,
   case scm_tcs_closures:
     return SCM_ENV (proc);
   case scm_tcs_subrs:
-#ifdef CCLO
-  case scm_tc7_cclo:
-#endif
     return SCM_EOL;
   default:
     SCM_WRONG_TYPE_ARG (1, proc);
@@ -440,38 +445,25 @@ scm_reverse_lookup (SCM env, SCM data)
   return SCM_BOOL_F;
 }
 
-SCM
-scm_start_stack (SCM id, SCM exp, SCM env)
+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
 {
   SCM answer;
   scm_t_debug_frame vframe;
   scm_t_debug_info vframe_vect_body;
-  vframe.prev = scm_last_debug_frame;
+  vframe.prev = scm_i_last_debug_frame ();
   vframe.status = SCM_VOIDFRAME;
   vframe.vect = &vframe_vect_body;
   vframe.vect[0].id = id;
-  scm_last_debug_frame = &vframe;
-  answer = scm_i_eval (exp, env);
-  scm_last_debug_frame = vframe.prev;
+  scm_i_set_last_debug_frame (&vframe);
+  answer = scm_call_0 (thunk);
+  scm_i_set_last_debug_frame (vframe.prev);
   return answer;
 }
-
-SCM_SYNTAX(s_start_stack, "start-stack", scm_makacro, scm_m_start_stack);
-
-static SCM
-scm_m_start_stack (SCM exp, SCM env)
-#define FUNC_NAME s_start_stack
-{
-  exp = SCM_CDR (exp);
-  if (!scm_is_pair (exp) 
-      || !scm_is_pair (SCM_CDR (exp))
-      || !scm_is_null (SCM_CDDR (exp)))
-    SCM_WRONG_NUM_ARGS ();
-  return scm_start_stack (scm_eval_car (exp, env), SCM_CADR (exp), env);
-}
 #undef FUNC_NAME
 
-
 /* {Debug Objects}
  *
  * The debugging evaluator throws these on frame traps.
@@ -526,7 +518,7 @@ SCM_DEFINE (scm_debug_hang, "debug-hang", 0, 1, 0,
 void
 scm_init_debug ()
 {
-  scm_init_opts (scm_debug_options, scm_debug_opts, SCM_N_DEBUG_OPTIONS);
+  scm_init_opts (scm_debug_options, scm_debug_opts);
 
   scm_tc16_memoized = scm_make_smob_type ("memoized", 0);
   scm_set_smob_mark (scm_tc16_memoized, scm_markcdr);