Author: hyperion
Date: Wed Feb 28 03:04:36 2007
New Revision: 25915
URL:
http://svn.reactos.org/svn/reactos?rev=25915&view=rev
Log:
modified include/reactos/libs/pseh/framebased.h
- final reformatting/cleanup fixes
- fixed regression introduced in 25908
modified include/reactos/libs/pseh/framebased.h
modified include/reactos/libs/pseh/framebased/internal.h
modified lib/pseh/framebased.c
- per-frame tracing support for PSEH. Prints detailed debugging traces with DbgPrint when
enabled. New defines _SEH_ENABLE_TRACE, _SEH_ENABLE_TRACE_LIB and _SEH_DO_DEFAULT_TRACING,
new macros _SEH_EnableTracing() and _SEH_DisableTracing(), new constants
_SEH_DO_TRACE_XXX. Please test it
See issue #2069 for more details.
Modified:
trunk/reactos/include/reactos/libs/pseh/framebased.h
trunk/reactos/include/reactos/libs/pseh/framebased/internal.h
trunk/reactos/lib/pseh/framebased.c
Modified: trunk/reactos/include/reactos/libs/pseh/framebased.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/pseh/…
==============================================================================
--- trunk/reactos/include/reactos/libs/pseh/framebased.h (original)
+++ trunk/reactos/include/reactos/libs/pseh/framebased.h Wed Feb 28 03:04:36 2007
@@ -46,6 +46,12 @@
# define _SEHJmpBuf_t jmp_buf
#endif
+#ifdef __cplusplus
+# define _SEH_INIT_CONST static const
+#else
+# define _SEH_INIT_CONST register const
+#endif
+
typedef struct __SEHFrame
{
_SEHPortableFrame_t SEH_Header;
@@ -193,7 +199,7 @@
_SEHEnterTry(&_SEHTryLevel.ST_Header); \
\
{ \
- static const int _SEHScopeKind = 0; \
+ _SEH_INIT_CONST int _SEHScopeKind = 0; \
(void)_SEHScopeKind; \
\
if(_SEHSetJmp(_SEHTryLevel.ST_JmpBuf) == 0) \
@@ -232,35 +238,29 @@
/* New syntax */
-#ifdef __cplusplus
-# define _SEH2_INIT_CONST static const
-#else
-# define _SEH2_INIT_CONST register const
-#endif
-
#define _SEH_LEAVE break
#define _SEH_TRY \
{ \
- _SEH2_INIT_CONST int _SEH2TopTryLevel = (_SEHScopeKind != 0); \
- _SEHPortableFrame_t * const _SEH2CurPortableFrame = _SEHPortableFrame; \
+ _SEH_INIT_CONST int _SEHTopTryLevel = (_SEHScopeKind != 0); \
+ _SEHPortableFrame_t * const _SEHCurPortableFrame = _SEHPortableFrame; \
\
{ \
- static const int _SEHScopeKind = 0; \
- register int _SEH2State = 0; \
- register int _SEH2Handle = 0; \
- _SEHFrame_t _SEH2Frame; \
- _SEHTryLevel_t _SEH2TryLevel; \
+ _SEH_INIT_CONST int _SEHScopeKind = 0; \
+ register int _SEHState = 0; \
+ register int _SEHHandle = 0; \
+ _SEHFrame_t _SEHFrame; \
+ _SEHTryLevel_t _SEHTryLevel; \
_SEHPortableFrame_t * const _SEHPortableFrame = \
- _SEH2TopTryLevel ? &_SEH2Frame.SEH_Header : _SEH2CurPortableFrame; \
+ _SEHTopTryLevel ? &_SEHFrame.SEH_Header : _SEHCurPortableFrame; \
\
(void)_SEHScopeKind; \
(void)_SEHPortableFrame; \
- (void)_SEH2Handle; \
+ (void)_SEHHandle; \
\
for(;;) \
{ \
- if(_SEH2State) \
+ if(_SEHState) \
{ \
for(;;) \
{ \
@@ -278,21 +278,23 @@
{ \
_SEH_DECLARE_HANDLERS((FILTER_), 0); \
\
- _SEH2TryLevel.ST_Header.SPT_Handlers = &_SEHHandlers; \
- \
- if(_SEH2TopTryLevel) \
+ _SEHTryLevel.ST_Header.SPT_Handlers = &_SEHHandlers; \
+ \
+ if(_SEHTopTryLevel) \
{ \
if(&_SEHLocals != _SEHDummyLocals) \
- _SEH2Frame.SEH_Locals = &_SEHLocals; \
- \
- _SEH2Frame.SEH_Header.SPF_Handler = _SEHCompilerSpecificHandler; \
- _SEHEnterFrame(&_SEH2Frame.SEH_Header, &_SEH2TryLevel.ST_Header); \
+ _SEHFrame.SEH_Locals = &_SEHLocals; \
+ \
+ _SEH_InitializeTracing(); \
+ _SEHFrame.SEH_Header.SPF_Handler = _SEHCompilerSpecificHandler; \
+ _SEHEnterFrame(&_SEHFrame.SEH_Header, &_SEHTryLevel.ST_Header); \
} \
else \
- _SEHEnterTry(&_SEH2TryLevel.ST_Header); \
- \
- if((_SEH2Handle = _SEHSetJmp(_SEH2TryLevel.ST_JmpBuf)) == 0) \
- { \
+ _SEHEnterTry(&_SEHTryLevel.ST_Header); \
+ \
+ if((_SEHHandle = _SEHSetJmp(_SEHTryLevel.ST_JmpBuf)) == 0) \
+ { \
+ ++ _SEHState; \
continue; \
} \
else \
@@ -306,7 +308,7 @@
\
_SEHLeave(); \
\
- if(_SEH2Handle) \
+ if(_SEHHandle) \
{
#define _SEH_FINALLY(FINALLY_) \
@@ -322,27 +324,29 @@
{ \
_SEH_DECLARE_HANDLERS(0, (FINALLY_)); \
\
- _SEH2TryLevel.ST_Header.SPT_Handlers = &_SEHHandlers; \
- \
- if(_SEH2TopTryLevel) \
+ _SEHTryLevel.ST_Header.SPT_Handlers = &_SEHHandlers; \
+ \
+ if(_SEHTopTryLevel) \
{ \
if(&_SEHLocals != _SEHDummyLocals) \
- _SEH2Frame.SEH_Locals = &_SEHLocals; \
- \
- _SEH2Frame.SEH_Header.SPF_Handler = 0; \
- _SEHEnterFrame(&_SEH2Frame.SEH_Header, &_SEH2TryLevel.ST_Header); \
+ _SEHFrame.SEH_Locals = &_SEHLocals; \
+ \
+ _SEH_InitializeTracing(); \
+ _SEHFrame.SEH_Header.SPF_Handler = 0; \
+ _SEHEnterFrame(&_SEHFrame.SEH_Header, &_SEHTryLevel.ST_Header); \
} \
else \
- _SEHEnterTry(&_SEH2TryLevel.ST_Header); \
- \
- ++ _SEH2State; \
+ _SEHEnterTry(&_SEHTryLevel.ST_Header); \
+ \
+ ++ _SEHState; \
continue; \
} \
\
break; \
} \
\
- (FINALLY_)(&_SEH2Frame.SEH_Header); \
+ (FINALLY_)(&_SEHFrame.SEH_Header); \
+ \
if(0) \
{
@@ -357,6 +361,15 @@
#define _SEH_GetExceptionPointers _SEHX_GetExceptionPointers
#define _SEH_AbnormalTermination _SEHX_AbnormalTermination
+#define _SEH_EnableTracing(LEVEL_) ((void)(_SEHPortableFrame->SPF_Tracing =
(LEVEL_)))
+#define _SEH_DisableTracing() ((void)(_SEHPortableFrame->SPF_Tracing =
_SEH_DO_TRACE_NONE))
+
+#ifdef _SEH_ENABLE_TRACE
+#define _SEH_InitializeTracing() (_SEH_EnableTracing(_SEH_DO_DEFAULT_TRACING))
+#else
+#define _SEH_InitializeTracing() ((void)0)
+#endif
+
#endif
/* EOF */
Modified: trunk/reactos/include/reactos/libs/pseh/framebased/internal.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/pseh/…
==============================================================================
--- trunk/reactos/include/reactos/libs/pseh/framebased/internal.h (original)
+++ trunk/reactos/include/reactos/libs/pseh/framebased/internal.h Wed Feb 28 03:04:36
2007
@@ -22,6 +22,23 @@
#ifndef KJK_PSEH_FRAMEBASED_INTERNAL_H_
#define KJK_PSEH_FRAMEBASED_INTERNAL_H_
+
+#define _SEH_DO_TRACE_ENTER_LEAVE (1 << 0)
+#define _SEH_DO_TRACE_EXCEPTION_RECORD (1 << 1)
+#define _SEH_DO_TRACE_CONTEXT (1 << 2)
+#define _SEH_DO_TRACE_UNWIND (1 << 3)
+#define _SEH_DO_TRACE_TRYLEVEL (1 << 4)
+#define _SEH_DO_TRACE_CALL_FILTER (1 << 5)
+#define _SEH_DO_TRACE_FILTER (1 << 6)
+#define _SEH_DO_TRACE_CALL_HANDLER (1 << 7)
+#define _SEH_DO_TRACE_CALL_FINALLY (1 << 8)
+
+#define _SEH_DO_TRACE_NONE (0)
+#define _SEH_DO_TRACE_ALL (-1)
+
+#ifndef _SEH_DO_DEFAULT_TRACING
+#define _SEH_DO_DEFAULT_TRACING _SEH_DO_TRACE_NONE
+#endif
struct _EXCEPTION_RECORD;
struct _EXCEPTION_POINTERS;
@@ -81,6 +98,7 @@
unsigned long SPF_Code;
_SEHHandler_t SPF_Handler;
_SEHPortableTryLevel_t * SPF_TopTryLevel;
+ int SPF_Tracing;
}
_SEHPortableFrame_t;
Modified: trunk/reactos/lib/pseh/framebased.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/pseh/framebased.c?rev=…
==============================================================================
--- trunk/reactos/lib/pseh/framebased.c (original)
+++ trunk/reactos/lib/pseh/framebased.c Wed Feb 28 03:04:36 2007
@@ -31,6 +31,248 @@
#include <excpt.h>
+/* Tracing */
+#ifdef _SEH_ENABLE_TRACE_LIB
+extern unsigned long __cdecl DbgPrint(const char * format, ...);
+
+#define _SEH_TRACE_HEADER_(FRAME_) \
+ DbgPrint("[PSEH:%p]%s:%d:", FRAME_, __FILE__, __LINE__);
+
+#define _SEH_TRACE_TRAILER_ \
+ DbgPrint("\n");
+
+#define _SEH_FILTER_RET_STRING_(RET_) \
+ (((int)(RET_) < 0) ? "_SEH_CONTINUE_EXECUTION" : (((int)(RET_) > 0) ?
"_SEH_EXECUTE_HANDLER" : "_SEH_CONTINUE_SEARCH"))
+
+#define _SEH_TRACE_LINE_(FRAME_, ARGS_) \
+{ \
+ _SEH_TRACE_HEADER_(FRAME_); \
+ DbgPrint ARGS_; \
+ _SEH_TRACE_TRAILER_; \
+}
+
+#define _SEH_TRACE_ENTER(FRAME_, FUNCNAME_, ARGS_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_ENTER_LEAVE) \
+ { \
+ _SEH_TRACE_HEADER_(FRAME_); \
+ DbgPrint(">>> %s(", (FUNCNAME_)); \
+ DbgPrint ARGS_; \
+ DbgPrint(")"); \
+ _SEH_TRACE_TRAILER_; \
+ } \
+}
+
+#define _SEH_TRACE_LEAVE(FRAME_, FUNCNAME_, ARGS_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_ENTER_LEAVE) \
+ { \
+ _SEH_TRACE_HEADER_(FRAME_); \
+ DbgPrint("<<< %s => ", (FUNCNAME_)); \
+ DbgPrint ARGS_; \
+ _SEH_TRACE_TRAILER_; \
+ } \
+}
+
+#define _SEH_TRACE_EXCEPTION_RECORD(FRAME_, ER_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_EXCEPTION_RECORD) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "ExceptionRecord %p = { ExceptionCode : %08X, ExceptionFlags : %08X,
ExceptionRecord : %p, ExceptionAddress : %p }", \
+ (ER_), \
+ (ER_)->ExceptionCode, \
+ (ER_)->ExceptionFlags, \
+ (ER_)->ExceptionRecord, \
+ (ER_)->ExceptionAddress \
+ ) \
+ ); \
+ } \
+}
+
+#ifdef _X86_
+#define _SEH_TRACE_CONTEXT(FRAME_, CONTEXT_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_CONTEXT) \
+ { \
+ if(((CONTEXT_)->ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "eax=%08X ebx=%08X ecx=%08X edx=%08X esi=%08X edi=%08X", \
+ (CONTEXT_)->Eax, \
+ (CONTEXT_)->Ebx, \
+ (CONTEXT_)->Ecx, \
+ (CONTEXT_)->Edx, \
+ (CONTEXT_)->Esi, \
+ (CONTEXT_)->Edi \
+ ) \
+ ); \
+ } \
+ \
+ if(((CONTEXT_)->ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "eip=%08X esp=%08X ebp=%08X efl=%08X cs=%08X ss=%08X", \
+ (CONTEXT_)->Eip, \
+ (CONTEXT_)->Esp, \
+ (CONTEXT_)->Ebp, \
+ (CONTEXT_)->EFlags, \
+ (CONTEXT_)->SegCs, \
+ (CONTEXT_)->SegSs \
+ ) \
+ ); \
+ } \
+ \
+ if(((CONTEXT_)->ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "ds=%08X es=%08X fs=%08X gs=%08X", \
+ (CONTEXT_)->SegDs, \
+ (CONTEXT_)->SegEs, \
+ (CONTEXT_)->SegFs, \
+ (CONTEXT_)->SegGs \
+ ) \
+ ); \
+ } \
+ } \
+}
+#else
+#error Unsupported platform.
+#endif
+
+#define _SEH_TRACE_UNWIND(FRAME_, ARGS_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_UNWIND) \
+ { \
+ _SEH_TRACE_LINE_((FRAME_), ARGS_); \
+ } \
+}
+
+#define _SEH_TRACE_TRYLEVEL(FRAME_, TRYLEVEL_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_TRYLEVEL) \
+ { \
+ _SEH_TRACE_LINE_((FRAME_), ("trylevel %p, filter %p", (TRYLEVEL_),
(TRYLEVEL_)->SPT_Handlers->SH_Filter)); \
+ } \
+}
+
+#define _SEH_TRACE_ENTER_CALL_FILTER(FRAME_, TRYLEVEL_, ER_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_CALL_FILTER) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "trylevel %p, calling filter %p, ExceptionCode %08X", \
+ (TRYLEVEL_), \
+ (TRYLEVEL_)->SPT_Handlers->SH_Filter, \
+ (ER_)->ExceptionCode \
+ ) \
+ ); \
+ } \
+}
+
+#define _SEH_TRACE_LEAVE_CALL_FILTER(FRAME_, TRYLEVEL_, RET_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_CALL_FILTER) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "trylevel %p, filter %p => %s", \
+ (TRYLEVEL_), \
+ (TRYLEVEL_)->SPT_Handlers->SH_Filter, \
+ _SEH_FILTER_RET_STRING_(RET_) \
+ ) \
+ ); \
+ } \
+}
+
+#define _SEH_TRACE_FILTER(FRAME_, TRYLEVEL_, RET_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_FILTER) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "trylevel %p => %s", \
+ (TRYLEVEL_), \
+ _SEH_FILTER_RET_STRING_(RET_) \
+ ) \
+ ); \
+ } \
+}
+
+#define _SEH_TRACE_ENTER_CALL_HANDLER(FRAME_, TRYLEVEL_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_CALL_HANDLER) \
+ { \
+ _SEH_TRACE_LINE_((FRAME_), ("trylevel %p, handling", (TRYLEVEL_))); \
+ } \
+}
+
+#define _SEH_TRACE_ENTER_CALL_FINALLY(FRAME_, TRYLEVEL_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_CALL_FINALLY) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "trylevel %p, calling exit routine %p", \
+ (TRYLEVEL_), \
+ (TRYLEVEL_)->SPT_Handlers->SH_Finally \
+ ) \
+ ); \
+ } \
+}
+
+#define _SEH_TRACE_LEAVE_CALL_FINALLY(FRAME_, TRYLEVEL_) \
+{ \
+ if((FRAME_)->SPF_Tracing & _SEH_DO_TRACE_CALL_FINALLY) \
+ { \
+ _SEH_TRACE_LINE_ \
+ ( \
+ (FRAME_), \
+ ( \
+ "trylevel %p, exit routine %p returned", \
+ (TRYLEVEL_), \
+ (TRYLEVEL_)->SPT_Handlers->SH_Finally \
+ ) \
+ ); \
+ } \
+}
+
+#else
+#define _SEH_TRACE_ENTER(FRAME_, FUNCNAME_, ARGS_)
+#define _SEH_TRACE_LEAVE(FRAME_, FUNCNAME_, ARGS_)
+#define _SEH_TRACE_EXCEPTION_RECORD(FRAME_, ER_)
+#define _SEH_TRACE_CONTEXT(FRAME_, CONTEXT_)
+#define _SEH_TRACE_UNWIND(FRAME_, ARGS_)
+#define _SEH_TRACE_TRYLEVEL(FRAME_, TRYLEVEL_)
+#define _SEH_TRACE_ENTER_CALL_FILTER(FRAME_, TRYLEVEL_, ER_)
+#define _SEH_TRACE_LEAVE_CALL_FILTER(FRAME_, TRYLEVEL_, RET_)
+#define _SEH_TRACE_FILTER(FRAME_, TRYLEVEL_, RET_)
+#define _SEH_TRACE_ENTER_CALL_HANDLER(FRAME_, TRYLEVEL_)
+#define _SEH_TRACE_ENTER_CALL_FINALLY(FRAME_, TRYLEVEL_)
+#define _SEH_TRACE_LEAVE_CALL_FINALLY(FRAME_, TRYLEVEL_)
+#endif
+
/* Assembly helpers, see i386/framebased.asm */
extern void __cdecl _SEHCleanHandlerEnvironment(void);
extern struct __SEHRegistration * __cdecl _SEHRegisterFrame(_SEHRegistration_t *);
@@ -49,6 +291,8 @@
)
{
_SEHPortableTryLevel_t * trylevel;
+
+ _SEH_TRACE_UNWIND(frame, ("enter local unwind from %p to %p",
frame->SPF_TopTryLevel, dsttrylevel));
for
(
@@ -64,8 +308,14 @@
pfnFinally = trylevel->SPT_Handlers->SH_Finally;
if(pfnFinally)
+ {
+ _SEH_TRACE_ENTER_CALL_FINALLY(frame, trylevel);
pfnFinally(frame);
+ _SEH_TRACE_LEAVE_CALL_FINALLY(frame, trylevel);
+ }
}
+
+ _SEH_TRACE_UNWIND(frame, ("leave local unwind from %p to %p",
frame->SPF_TopTryLevel, dsttrylevel));
}
static void __cdecl _SEHCallHandler
@@ -76,7 +326,9 @@
{
_SEHGlobalUnwind(frame);
_SEHLocalUnwind(frame, trylevel);
+ _SEH_TRACE_ENTER_CALL_HANDLER(frame, trylevel);
frame->SPF_Handler(trylevel);
+ /* ASSERT(0); */
}
static int __cdecl _SEHFrameHandler
@@ -93,9 +345,29 @@
frame = EstablisherFrame;
+ _SEH_TRACE_ENTER
+ (
+ frame,
+ "_SEHFrameHandler",
+ (
+ "%p, %p, %p, %p",
+ ExceptionRecord,
+ EstablisherFrame,
+ ContextRecord,
+ DispatcherContext
+ )
+ );
+
+ _SEH_TRACE_EXCEPTION_RECORD(frame, ExceptionRecord);
+ _SEH_TRACE_CONTEXT(frame, ContextRecord);
+
/* Unwinding */
if(ExceptionRecord->ExceptionFlags & (4 | 2))
+ {
+ _SEH_TRACE_UNWIND(frame, ("enter forced unwind"));
_SEHLocalUnwind(frame, NULL);
+ _SEH_TRACE_UNWIND(frame, ("leave forced unwind"));
+ }
/* Handling */
else
{
@@ -115,6 +387,8 @@
)
{
_SEHFilter_t pfnFilter = trylevel->SPT_Handlers->SH_Filter;
+
+ _SEH_TRACE_TRYLEVEL(frame, trylevel);
switch((UINT_PTR)pfnFilter)
{
@@ -135,7 +409,9 @@
ep.ExceptionRecord = ExceptionRecord;
ep.ContextRecord = ContextRecord;
+ _SEH_TRACE_ENTER_CALL_FILTER(frame, trylevel, ExceptionRecord);
ret = pfnFilter(&ep, frame);
+ _SEH_TRACE_LEAVE_CALL_FILTER(frame, trylevel, ret);
}
else
ret = _SEH_CONTINUE_SEARCH;
@@ -144,9 +420,14 @@
}
}
+ _SEH_TRACE_FILTER(frame, trylevel, ret);
+
/* _SEH_CONTINUE_EXECUTION */
if(ret < 0)
+ {
+ _SEH_TRACE_LEAVE(frame, "_SEHFrameHandler",
("ExceptionContinueExecution"));
return ExceptionContinueExecution;
+ }
/* _SEH_EXECUTE_HANDLER */
else if(ret > 0)
_SEHCallHandler(frame, trylevel);
@@ -158,6 +439,7 @@
/* FALLTHROUGH */
}
+ _SEH_TRACE_LEAVE(frame, "_SEHFrameHandler",
("ExceptionContinueSearch"));
return ExceptionContinueSearch;
}