[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/engine cvm.h,1.42,1.43 cvm_dasm.c,1.48,
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/engine cvm.h,1.42,1.43 cvm_dasm.c,1.48,1.49 cvm_except.c,1.21,1.22 cvm_lengths.c,1.11,1.12cvmc_except.c,1.7,1.8 |
Date: |
Tue, 15 Apr 2003 20:39:36 -0400 |
Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv25658/engine
Modified Files:
cvm.h cvm_dasm.c cvm_except.c cvm_lengths.c cvmc_except.c
Log Message:
Add the "set_stack_trace" instruction to CVM, to initialize exception
stack traces at the point of throw.
Index: cvm.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -r1.42 -r1.43
*** cvm.h 24 Feb 2003 00:45:59 -0000 1.42
--- cvm.h 16 Apr 2003 00:39:34 -0000 1.43
***************
*** 413,416 ****
--- 413,417 ----
#define COP_PREFIX_THROW 0x1C
#define COP_PREFIX_THROW_CALLER 0x1D
+ #define COP_PREFIX_SET_STACK_TRACE 0x1E
/*
Index: cvm_dasm.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_dasm.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -r1.48 -r1.49
*** cvm_dasm.c 24 Feb 2003 00:45:59 -0000 1.48
--- cvm_dasm.c 16 Apr 2003 00:39:34 -0000 1.49
***************
*** 468,476 ****
{"throw", CVM_OPER_NONE},
{"throw_caller", CVM_OPER_NONE},
!
! /*
! * Reserved opcodes.
! */
! {"preserved_1e", CVM_OPER_NONE},
/*
--- 468,472 ----
{"throw", CVM_OPER_NONE},
{"throw_caller", CVM_OPER_NONE},
! {"set_stack_trace", CVM_OPER_NONE},
/*
Index: cvm_except.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_except.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** cvm_except.c 14 Apr 2003 00:17:05 -0000 1.21
--- cvm_except.c 16 Apr 2003 00:39:34 -0000 1.22
***************
*** 21,24 ****
--- 21,102 ----
#if defined(IL_CVM_GLOBALS)
+ #if defined(IL_CONFIG_REFLECTION) && defined(IL_CONFIG_DEBUG_LINES)
+
+ /*
+ * Find the "stackTrace" field within "System.Exception" and then set.
+ */
+ static int FindAndSetStackTrace(ILExecThread *thread, ILObject *object)
+ {
+ ILObject *trace;
+ ILCallFrame *callFrame;
+ ILField *field;
+
+ /* Find the "stackTrace" field within the "Exception" class */
+ field = ILExecThreadLookupField
+ (thread, "System.Exception", "stackTrace",
+ "[vSystem.Diagnostics.PackedStackFrame;");
+ if(field)
+ {
+ /* Push the current frame data onto the stack temporarily
+ so that "GetExceptionStackTrace" can find it */
+ if(thread->numFrames < thread->maxFrames)
+ {
+ callFrame =
&(thread->frameStack[(thread->numFrames)++]);
+ }
+ else if((callFrame = _ILAllocCallFrame(thread)) == 0)
+ {
+ /* We ran out of memory trying to push the frame */
+ return 0;
+ }
+ callFrame->method = thread->method;
+ callFrame->pc = thread->pc;
+ callFrame->frame = thread->frame;
+ callFrame->exceptHeight = thread->exceptHeight;
+ callFrame->permissions = 0;
+
+ /* Get the stack trace and pop the frame */
+ trace = (ILObject
*)_IL_StackFrame_GetExceptionStackTrace(thread);
+ --(thread->numFrames);
+ if(!trace)
+ {
+ /* We ran out of memory obtaining the stack trace */
+ return 0;
+ }
+
+ /* Write the stack trace into the object */
+ *((ILObject **)(((unsigned char *)object) + field->offset)) =
trace;
+ }
+ return 1;
+ }
+
+ /*
+ * Set the stack trace for an exception to the current call context.
+ */
+ static void SetExceptionStackTrace(ILExecThread *thread, ILObject *object)
+ {
+ ILClass *classInfo;
+ if(!object)
+ {
+ return;
+ }
+ classInfo = ILExecThreadLookupClass(thread, "System.Exception");
+ if(!classInfo)
+ {
+ return;
+ }
+ if(!ILClassInheritsFrom(GetObjectClass(object), classInfo))
+ {
+ return;
+ }
+ if(!FindAndSetStackTrace(thread, object))
+ {
+ /* We ran out of memory while allocating the stack trace,
+ but it isn't serious: we can just throw without the trace */
+ thread->thrownException = 0;
+ }
+ }
+
+ #endif /* IL_CONFIG_REFLECTION && IL_CONFIG_DEBUG_LINES */
+
void *_ILSystemException(ILExecThread *thread, const char *className)
{
***************
*** 36,82 ****
{
#if defined(IL_CONFIG_REFLECTION) && defined(IL_CONFIG_DEBUG_LINES)
! ILObject *trace;
! ILCallFrame *callFrame;
! ILField *field;
!
! /* Find the "stackTrace" field within the "Exception" class */
! field = ILExecThreadLookupField
! (thread, "System.Exception", "stackTrace",
! "[vSystem.Diagnostics.PackedStackFrame;");
! if(field)
{
! /* Push the current frame data onto the stack
temporarily
! so that "GetExceptionStackTrace" can find it */
! if(thread->numFrames < thread->maxFrames)
! {
! callFrame =
&(thread->frameStack[(thread->numFrames)++]);
! }
! else if((callFrame = _ILAllocCallFrame(thread)) == 0)
! {
! /* We ran out of memory trying to push the
frame */
! object = thread->thrownException;
! thread->thrownException = 0;
! return object;
! }
! callFrame->method = thread->method;
! callFrame->pc = thread->pc;
! callFrame->frame = thread->frame;
! callFrame->exceptHeight = thread->exceptHeight;
! callFrame->permissions = 0;
!
! /* Get the stack trace and pop the frame */
! trace = (ILObject
*)_IL_StackFrame_GetExceptionStackTrace(thread);
! --(thread->numFrames);
! if(!trace)
! {
! /* We ran out of memory obtaining the stack
trace */
! object = thread->thrownException;
! thread->thrownException = 0;
! return object;
! }
!
! /* Write the stack trace into the object */
! *((ILObject **)(((unsigned char *)object) +
field->offset))
! = trace;
}
#endif /* IL_CONFIG_REFLECTION && IL_CONFIG_DEBUG_LINES */
--- 114,122 ----
{
#if defined(IL_CONFIG_REFLECTION) && defined(IL_CONFIG_DEBUG_LINES)
! if(!FindAndSetStackTrace(thread, object))
{
! /* We ran out of memory: pick up the
"OutOfMemoryException" */
! object = thread->thrownException;
! thread->thrownException = 0;
}
#endif /* IL_CONFIG_REFLECTION && IL_CONFIG_DEBUG_LINES */
***************
*** 325,328 ****
--- 365,403 ----
}
/* Not reached */
+
+ /**
+ * <opcode name="set_stack_trace" group="Exception handling instructions">
+ * <operation>Set the stack trace in an exception object at
+ * the throw point</operation>
+ *
+ * <format>prefix<fsep/>set_stack_trace</format>
+ * <dformat>{set_stack_trace}</dformat>
+ *
+ * <form name="set_stack_trace" code="COP_PREFIX_SET_STACK_TRACE"/>
+ *
+ * <before>..., object</before>
+ * <after>..., object</after>
+ *
+ * <description>The <i>object</i> is popped from the stack as
+ * type <code>ptr</code>; information about the current method's
+ * stack calling context is written into <i>object</i>; and then
+ * <i>object</i> is pushed back onto the stack.</description>
+ *
+ * <notes>This opcode will have no effect if <i>object</i> is
+ * <code>null</code>, or if its class does not inherit from
+ * <code>System.Exception</code>.</notes>
+ * </opcode>
+ */
+ VMCASE(COP_PREFIX_SET_STACK_TRACE):
+ {
+ /* Set the stack trace within an exception object */
+ #if defined(IL_CONFIG_REFLECTION) && defined(IL_CONFIG_DEBUG_LINES)
+ COPY_STATE_TO_THREAD();
+ SetExceptionStackTrace(thread, stacktop[-1].ptrValue);
+ RESTORE_STATE_FROM_THREAD();
+ #endif
+ MODIFY_PC_AND_STACK(CVMP_LEN_NONE, 0);
+ }
+ VMBREAK(COP_PREFIX_SET_STACK_TRACE);
#endif /* IL_CVM_PREFIX */
Index: cvm_lengths.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_lengths.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** cvm_lengths.c 24 Feb 2003 00:45:59 -0000 1.11
--- cvm_lengths.c 16 Apr 2003 00:39:34 -0000 1.12
***************
*** 426,434 ****
/* throw */ CVMP_LEN_NONE,
/* throw_caller */ CVMP_LEN_NONE,
!
! /*
! * Reserved opcodes.
! */
! /* preserved_1e */ CVMP_LEN_NONE,
/*
--- 426,430 ----
/* throw */ CVMP_LEN_NONE,
/* throw_caller */ CVMP_LEN_NONE,
! /* set_stack_trace */ CVMP_LEN_NONE,
/*
Index: cvmc_except.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc_except.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** cvmc_except.c 16 May 2002 04:48:10 -0000 1.7
--- cvmc_except.c 16 Apr 2003 00:39:34 -0000 1.8
***************
*** 81,84 ****
--- 81,85 ----
static void CVMCoder_Throw(ILCoder *coder, int inCurrentMethod)
{
+ CVMP_OUT_NONE(COP_PREFIX_SET_STACK_TRACE);
if(inCurrentMethod)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/engine cvm.h,1.42,1.43 cvm_dasm.c,1.48,1.49 cvm_except.c,1.21,1.22 cvm_lengths.c,1.11,1.12cvmc_except.c,1.7,1.8,
Rhys Weatherley <address@hidden> <=