/* * This is a part of the BugTrap package. * Copyright (c) 2005-2009 IntelleSoft. * All rights reserved. * * Description: Managed to unmanaged code thunks. * Author: Maksim Pyatkovskiy. * * This source code is only intended as a supplement to the * BugTrap package reference and related electronic documentation * provided with the product. See these sources for detailed * information regarding the BugTrap package. */ #pragma once #ifdef _MANAGED #include "Encoding.h" #include "SymEngineNet.h" using namespace IntelleSoft::BugTrap; class CNetStackTrace { public: struct CNetStackTraceEntry { CNetStackTraceEntry(void); WCHAR m_szAssembly[MAX_PATH]; WCHAR m_szILOffset[32]; WCHAR m_szNativeOffset[32]; WCHAR m_szType[256]; WCHAR m_szMethod[256]; WCHAR m_szMethodSignature[256]; WCHAR m_szSourceFile[MAX_PATH]; WCHAR m_szLineNumber[16]; WCHAR m_szColumnNumber[16]; WCHAR m_szLineInfo[64]; }; struct CNetErrorInfo : public CNetStackTraceEntry { CNetErrorInfo(void); WCHAR m_szException[128]; WCHAR m_szMessage[256]; WCHAR m_szAppDomainName[MAX_PATH]; WCHAR m_szAppDomainID[16]; WCHAR m_szProcessName[MAX_PATH]; WCHAR m_szProcessID[16]; }; CNetStackTrace(void); CNetStackTrace(gcroot exception); CNetStackTrace(gcroot thread); void InitStackTrace(void); bool GetFirstStackTraceEntry(CNetStackTraceEntry& rEntry); bool GetNextStackTraceEntry(CNetStackTraceEntry& rEntry); bool GetFirstStackTraceString(CUTF8EncStream& rEncStream); bool GetNextStackTraceString(CUTF8EncStream& rEncStream); bool GetErrorInfo(CNetErrorInfo& rErrorInfo); bool GetErrorString(CStrStream& rStream); bool GetErrorString(CUTF8EncStream& rEncStream); private: CNetStackTrace(const CNetStackTrace& rStackTrace); CNetStackTrace& operator=(const CNetStackTrace& rStackTrace); void GetStackTraceString(const CNetStackTraceEntry& rEntry, CUTF8EncStream& rEncStream); gcroot m_gcStackFrameEnumerator; gcroot m_gcException; }; class CNetAssemblies { public: struct CAssemblyInfo { CAssemblyInfo(void); WCHAR m_szName[MAX_PATH]; WCHAR m_szVersion[64]; WCHAR m_szFileVersion[64]; WCHAR m_szCodeBase[MAX_PATH]; }; CNetAssemblies(void); void InitAssemblies(void); bool GetFirstAssembly(CNetAssemblies::CAssemblyInfo& rAssemblyInfo); bool GetNextAssembly(CNetAssemblies::CAssemblyInfo& rAssemblyInfo); private: gcroot m_gcAssemblyEnumerator; }; #pragma managed ///////////////////////////////////////////////////////////////////////////////// namespace NetThunks { inline bool IsNetException(void) { return (ExceptionHandler::Exception != nullptr); } inline gcroot GetNetException(void) { return ExceptionHandler::Exception; } void GetThreadInfo(gcroot gcThread, DWORD& dwThreadID, PWSTR pszThreadName, DWORD dwThreadNameSize); void GetAppDomainInfo(DWORD& dwAppDomainID, PWSTR pszAppDomainName, DWORD dwAppDomainSize); inline void GetThreadInfo(DWORD& dwThreadID, PWSTR pszThreadName, DWORD dwThreadNameSize) { GetThreadInfo(Thread::CurrentThread, dwThreadID, pszThreadName, dwThreadNameSize); } gcroot EnumStackFrames(void); gcroot EnumStackFrames(gcroot exception); gcroot EnumStackFrames(gcroot thread); void InitStackTrace(gcroot gcStackFrameEnumerator); bool GetFirstStackTraceEntry(gcroot gcStackFrameEnumerator, CNetStackTrace::CNetStackTraceEntry& rEntry); bool GetNextStackTraceEntry(gcroot gcStackFrameEnumerator, CNetStackTrace::CNetStackTraceEntry& rEntry); bool GetErrorInfo(gcroot gcStackFrameEnumerator, CNetStackTrace::CNetErrorInfo& rErrorInfo); void GetNetVersion(PWSTR pszNetVersion, DWORD dwNetVersionSize); gcroot EnumAssemblies(void); void InitAssemblies(gcroot gcAssemblyEnumerator); bool GetFirstAssembly(gcroot gcAssemblyEnumerator, CNetAssemblies::CAssemblyInfo& rAssemblyInfo); bool GetNextAssembly(gcroot gcAssemblyEnumerator, CNetAssemblies::CAssemblyInfo& rAssemblyInfo); bool ReadVersionInfo(void); void FireBeforeUnhandledExceptionEvent(void); void FireAfterUnhandledExceptionEvent(void); void FlushTraceListeners(void); inline gcroot GetCurrentThread(void) { return gcroot(Thread::CurrentThread); } inline gcroot GetInnerException(gcroot gcException) { Exception^ exception = gcException; return gcroot(exception->InnerException); } #if 0 template inline bool IsNull(gcroot gcObject) { T^ object = gcObject; return (object == nullptr); } #else bool IsNull(gcroot gcObject); #endif } #pragma unmanaged /////////////////////////////////////////////////////////////////////////////// inline CNetStackTrace::CNetStackTrace(void) : m_gcStackFrameEnumerator(NetThunks::EnumStackFrames()) { } inline CNetStackTrace::CNetStackTrace(gcroot exception) : m_gcStackFrameEnumerator(NetThunks::EnumStackFrames(exception)), m_gcException(exception) { } inline CNetStackTrace::CNetStackTrace(gcroot thread) : m_gcStackFrameEnumerator(NetThunks::EnumStackFrames(thread)) { } inline void CNetStackTrace::InitStackTrace(void) { NetThunks::InitStackTrace(m_gcStackFrameEnumerator); } inline bool CNetStackTrace::GetFirstStackTraceEntry(CNetStackTraceEntry& rEntry) { return NetThunks::GetFirstStackTraceEntry(m_gcStackFrameEnumerator, rEntry); } inline bool CNetStackTrace::GetNextStackTraceEntry(CNetStackTraceEntry& rEntry) { return NetThunks::GetNextStackTraceEntry(m_gcStackFrameEnumerator, rEntry); } inline bool CNetStackTrace::GetErrorInfo(CNetErrorInfo& rErrorInfo) { return NetThunks::GetErrorInfo(m_gcStackFrameEnumerator, rErrorInfo); } inline CNetAssemblies::CNetAssemblies(void) : m_gcAssemblyEnumerator(NetThunks::EnumAssemblies()) { } inline void CNetAssemblies::InitAssemblies(void) { NetThunks::InitAssemblies(m_gcAssemblyEnumerator); } inline bool CNetAssemblies::GetFirstAssembly(CNetAssemblies::CAssemblyInfo& rAssemblyInfo) { return NetThunks::GetFirstAssembly(m_gcAssemblyEnumerator, rAssemblyInfo); } inline bool CNetAssemblies::GetNextAssembly(CNetAssemblies::CAssemblyInfo& rAssemblyInfo) { return NetThunks::GetNextAssembly(m_gcAssemblyEnumerator, rAssemblyInfo); } #endif // _MANAGED