Index: src/efuns.c
===================================================================
--- src/efuns.c	(Revision 2441)
+++ src/efuns.c	(Arbeitskopie)
@@ -8376,6 +8376,10 @@
             put_string(&res, new_mstring(sbuf.buf));
             strbuf_free(&sbuf);
         }
+        else if (sp->u.number == DIT_CURRENT_DEPTH)
+        {
+            put_number(&res, control_stack_depth());
+        }
         else
             errorf("bad arg 2 to debug_info(): %"PRIdPINT", expected 0..2\n"
                  , sp->u.number);
Index: src/interpret.c
===================================================================
--- src/interpret.c	(Revision 2441)
+++ src/interpret.c	(Arbeitskopie)
@@ -19537,6 +19537,15 @@
 #endif /* TRACE_CODE */
 
 /*-------------------------------------------------------------------------*/
+int control_stack_depth (void)
+  /* Returns the number of frames on the control stack. Can be used to estimate
+   * the still available stack depth in recursive code.
+   */
+{
+    return (csp - CONTROL_STACK) + 1; 
+} /* control_stack_depth() */
+
+/*-------------------------------------------------------------------------*/
 static INLINE int
 caller_stack_depth(void)
 /* static helper function for f_caller_stack_depth() and f_caller_stack() for
Index: src/interpret.h
===================================================================
--- src/interpret.h	(Revision 2441)
+++ src/interpret.h	(Arbeitskopie)
@@ -246,5 +246,6 @@
 extern void count_interpreter_refs(void);
 #endif
 
+extern int  stack_depth(void);
 
 #endif /* INTERPRET_H__ */
Index: mudlib/sys/debug_info.h
===================================================================
--- mudlib/sys/debug_info.h	(Revision 2441)
+++ mudlib/sys/debug_info.h	(Arbeitskopie)
@@ -25,6 +25,7 @@
 #define DIT_ERROR          1  /* Return the last error call chain as an array */
 #define DIT_UNCAUGHT_ERROR 2  /* Return the last uncaught error call chain */
 #define DIT_STR_CURRENT    3  /* Return the current call chain as a string */
+#define DIT_CURRENT_DEPTH  4  /* Return the current control stack depth */
 
 /* Indices into the array resulting from debug_info(DINFO_DATA, DID_STATUS)
  */
