From 56fce2f9f3e2b45acf85205c37000797f5f24d23 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 6 Nov 2017 12:56:00 -0800 Subject: Cleanup BCLDebug (#14868) - Delete BCLDebug and related types since it was replaced by the public System.Diagnostic.Debug - Preserve commented out or conditionally compiled logging in a few place where it seemed potentially useful Fixes #11389 --- src/vm/debugdebugger.cpp | 430 ----------------------------------------------- 1 file changed, 430 deletions(-) (limited to 'src/vm/debugdebugger.cpp') diff --git a/src/vm/debugdebugger.cpp b/src/vm/debugdebugger.cpp index 489c623df9..8d8557a76b 100644 --- a/src/vm/debugdebugger.cpp +++ b/src/vm/debugdebugger.cpp @@ -32,8 +32,6 @@ #include "eemessagebox.h" #include "stackwalk.h" -LogHashTable g_sLogHashTable; - #ifndef DACCESS_COMPILE //---------------------------------------------------------------------------- // @@ -1219,432 +1217,4 @@ void DebugStackTrace::DebugStackTraceElement::InitPass2() } } -FCIMPL4(INT32, DebuggerAssert::ShowDefaultAssertDialog, - StringObject* strConditionUNSAFE, - StringObject* strMessageUNSAFE, - StringObject* strStackTraceUNSAFE, - StringObject* strWindowTitleUNSAFE - ) -{ - CONTRACTL - { - FCALL_CHECK; - PRECONDITION(CheckPointer(strConditionUNSAFE, NULL_OK)); - PRECONDITION(CheckPointer(strMessageUNSAFE, NULL_OK)); - PRECONDITION(CheckPointer(strStackTraceUNSAFE, NULL_OK)); - PRECONDITION(CheckPointer(strWindowTitleUNSAFE, NULL_OK)); - } - CONTRACTL_END; - - int result = IDRETRY; - - struct _gc { - STRINGREF strCondition; - STRINGREF strMessage; - STRINGREF strStackTrace; - STRINGREF strWindowTitle; - } gc; - - gc.strCondition = (STRINGREF) ObjectToOBJECTREF(strConditionUNSAFE); - gc.strMessage = (STRINGREF) ObjectToOBJECTREF(strMessageUNSAFE); - gc.strStackTrace = (STRINGREF) ObjectToOBJECTREF(strStackTraceUNSAFE); - gc.strWindowTitle = (STRINGREF) ObjectToOBJECTREF(strWindowTitleUNSAFE); - - HELPER_METHOD_FRAME_BEGIN_RET_PROTECT(gc); - - StackSString condition; - StackSString message; - StackSString stackTrace; - StackSString windowTitle; - - if (gc.strCondition != NULL) - gc.strCondition->GetSString(condition); - if (gc.strMessage != NULL) - gc.strMessage->GetSString(message); - if (gc.strStackTrace != NULL) - gc.strStackTrace->GetSString(stackTrace); - if (gc.strWindowTitle != NULL) - gc.strWindowTitle->GetSString(windowTitle); - - StackSString msgText; - if (gc.strCondition != NULL) { - msgText.Append(W("Expression: ")); - msgText.Append(condition); - msgText.Append(W("\n")); - } - msgText.Append(W("Description: ")); - msgText.Append(message); - - StackSString stackTraceText; - if (gc.strStackTrace != NULL) { - stackTraceText.Append(W("Stack Trace:\n")); - stackTraceText.Append(stackTrace); - } - - if (gc.strWindowTitle == NULL) { - windowTitle.Set(W("Assert Failure")); - } - - if (NoGuiOnAssert()) - { - fwprintf(stderr, W("%s\n%s\n%s\n"), windowTitle.GetUnicode(), msgText.GetUnicode(), stackTraceText.GetUnicode()); - result = FailTerminate; - } - else - { - // We're taking a string from managed code, and we can't be sure it doesn't have stuff like %s or \n in it. - // So, pass a format string of %s and pass the text as a vararg to our message box method. - // Also, varargs and StackSString don't mix. Convert to string first. - const WCHAR* msgTextAsUnicode = msgText.GetUnicode(); - result = EEMessageBoxNonLocalizedNonFatal(W("%s"), windowTitle, stackTraceText, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION, msgTextAsUnicode); - - // map the user's choice to the values recognized by - // the System.Diagnostics.Assert package - if (result == IDRETRY) - { - result = FailDebug; - } - else if (result == IDIGNORE) - { - result = FailIgnore; - } - else - { - result = FailTerminate; - } - } - - HELPER_METHOD_FRAME_END(); - return result; -} -FCIMPLEND - - -FCIMPL1( void, Log::AddLogSwitch, - LogSwitchObject* logSwitchUNSAFE - ) -{ - CONTRACTL - { - FCALL_CHECK; - PRECONDITION(CheckPointer(logSwitchUNSAFE)); - } - CONTRACTL_END; - - Thread *pThread = GetThread(); - _ASSERTE(pThread); - - HRESULT hresult = S_OK; - - struct _gc { - LOGSWITCHREF m_LogSwitch; - STRINGREF Name; - OBJECTREF tempObj; - STRINGREF strrefParentName; - } gc; - - ZeroMemory(&gc, sizeof(gc)); - - HELPER_METHOD_FRAME_BEGIN_PROTECT(gc); - - gc.m_LogSwitch = (LOGSWITCHREF)ObjectToOBJECTREF(logSwitchUNSAFE); - - // From the given args, extract the LogSwitch name - gc.Name = ((LogSwitchObject*) OBJECTREFToObject(gc.m_LogSwitch))->GetName(); - - _ASSERTE( gc.Name != NULL ); - WCHAR *pstrCategoryName = NULL; - int iCategoryLength = 0; - WCHAR wszParentName [MAX_LOG_SWITCH_NAME_LEN+1]; - WCHAR wszSwitchName [MAX_LOG_SWITCH_NAME_LEN+1]; - wszParentName [0] = W('\0'); - wszSwitchName [0] = W('\0'); - - // extract the (WCHAR) name from the STRINGREF object - gc.Name->RefInterpretGetStringValuesDangerousForGC(&pstrCategoryName, &iCategoryLength); - - _ASSERTE (iCategoryLength > 0); - wcsncpy_s(wszSwitchName, COUNTOF(wszSwitchName), pstrCategoryName, _TRUNCATE); - - // check if an entry with this name already exists in the hash table. - // Duplicates are not allowed. - // : access to the hashtable is not synchronized! - if(g_sLogHashTable.GetEntryFromHashTable(pstrCategoryName) != NULL) - { - hresult = TYPE_E_DUPLICATEID; - } - else - { - // Create a strong reference handle to the LogSwitch object - OBJECTHANDLE ObjHandle = pThread->GetDomain()->CreateStrongHandle(NULL); - StoreObjectInHandle(ObjHandle, ObjectToOBJECTREF(gc.m_LogSwitch)); - // Use ObjectFromHandle(ObjHandle) to get back the object. - - hresult = g_sLogHashTable.AddEntryToHashTable(pstrCategoryName, ObjHandle); - - // If we failed to insert this into the hash table, destroy the handle so - // that we don't leak it. - if (FAILED(hresult)) - { - ::DestroyStrongHandle(ObjHandle); - } - -#ifdef DEBUGGING_SUPPORTED - if (hresult == S_OK) - { - // tell the attached debugger about this switch - if (CORDebuggerAttached()) - { - int iLevel = gc.m_LogSwitch->GetLevel(); - WCHAR *pstrParentName = NULL; - int iParentNameLength = 0; - - gc.tempObj = gc.m_LogSwitch->GetParent(); - - LogSwitchObject* pParent = (LogSwitchObject*) OBJECTREFToObject( gc.tempObj ); - - if (pParent != NULL) - { - // From the given args, extract the ParentLogSwitch's name - gc.strrefParentName = pParent->GetName(); - - // extract the (WCHAR) name from the STRINGREF object - gc.strrefParentName->RefInterpretGetStringValuesDangerousForGC(&pstrParentName, &iParentNameLength ); - - if (iParentNameLength > MAX_LOG_SWITCH_NAME_LEN) - { - wcsncpy_s (wszParentName, COUNTOF(wszParentName), pstrParentName, _TRUNCATE); - } - else - { - wcscpy_s (wszParentName, COUNTOF(wszParentName), pstrParentName); - } - } - - g_pDebugInterface->SendLogSwitchSetting (iLevel, SWITCH_CREATE, wszSwitchName, wszParentName ); - } - } -#endif // DEBUGGING_SUPPORTED - } - - HELPER_METHOD_FRAME_END(); -} -FCIMPLEND - - -FCIMPL3(void, Log::ModifyLogSwitch, - INT32 Level, - StringObject* strLogSwitchNameUNSAFE, - StringObject* strParentNameUNSAFE - ) -{ - CONTRACTL - { - FCALL_CHECK; - PRECONDITION(CheckPointer(strLogSwitchNameUNSAFE)); - PRECONDITION(CheckPointer(strParentNameUNSAFE)); - } - CONTRACTL_END; - - STRINGREF strLogSwitchName = (STRINGREF) ObjectToOBJECTREF(strLogSwitchNameUNSAFE); - STRINGREF strParentName = (STRINGREF) ObjectToOBJECTREF(strParentNameUNSAFE); - - HELPER_METHOD_FRAME_BEGIN_2(strLogSwitchName, strParentName); - - _ASSERTE (strLogSwitchName != NULL); - - WCHAR *pstrLogSwitchName = NULL; - WCHAR *pstrParentName = NULL; - int iSwitchNameLength = 0; - int iParentNameLength = 0; - WCHAR wszParentName [MAX_LOG_SWITCH_NAME_LEN+1]; - WCHAR wszSwitchName [MAX_LOG_SWITCH_NAME_LEN+1]; - wszParentName [0] = W('\0'); - wszSwitchName [0] = W('\0'); - - // extract the (WCHAR) name from the STRINGREF object - strLogSwitchName->RefInterpretGetStringValuesDangerousForGC ( - &pstrLogSwitchName, - &iSwitchNameLength); - - if (iSwitchNameLength > MAX_LOG_SWITCH_NAME_LEN) - { - wcsncpy_s (wszSwitchName, COUNTOF(wszSwitchName), pstrLogSwitchName, _TRUNCATE); - } - else - { - wcscpy_s (wszSwitchName, COUNTOF(wszSwitchName), pstrLogSwitchName); - } - - // extract the (WCHAR) name from the STRINGREF object - strParentName->RefInterpretGetStringValuesDangerousForGC ( - &pstrParentName, - &iParentNameLength); - - if (iParentNameLength > MAX_LOG_SWITCH_NAME_LEN) - { - wcsncpy_s (wszParentName, COUNTOF(wszParentName), pstrParentName, _TRUNCATE); - } - else - { - wcscpy_s (wszParentName, COUNTOF(wszParentName), pstrParentName); - } - -#ifdef DEBUGGING_SUPPORTED - if (g_pDebugInterface) - { - g_pDebugInterface->SendLogSwitchSetting (Level, - SWITCH_MODIFY, - wszSwitchName, - wszParentName - ); - } -#endif // DEBUGGING_SUPPORTED - - HELPER_METHOD_FRAME_END(); -} -FCIMPLEND - - -void Log::DebuggerModifyingLogSwitch (int iNewLevel, - const WCHAR *pLogSwitchName - ) -{ - CONTRACTL - { - GC_NOTRIGGER; - } - CONTRACTL_END; - - // check if an entry with this name exists in the hash table. - OBJECTHANDLE ObjHandle = g_sLogHashTable.GetEntryFromHashTable (pLogSwitchName); - if ( ObjHandle != NULL) - { - OBJECTREF obj = ObjectFromHandle (ObjHandle); - LogSwitchObject *pLogSwitch = (LogSwitchObject *)(OBJECTREFToObject (obj)); - - pLogSwitch->SetLevel (iNewLevel); - } -} - - -// Note: Caller should ensure that it's not adding a duplicate -// entry by calling GetEntryFromHashTable before calling this -// function. -HRESULT LogHashTable::AddEntryToHashTable (const WCHAR *pKey, - OBJECTHANDLE pData - ) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - } - CONTRACTL_END; - - HashElement *pElement; - - // check that the length is non-zero - if (pKey == NULL) - { - return (E_INVALIDARG); - } - - int iHashKey = 0; - int iLength = (int)wcslen (pKey); - - for (int i= 0; iSetData (pData, pKey); - - if (m_Buckets [iHashKey] == NULL) - { - m_Buckets [iHashKey] = pElement; - } - else - { - pElement->SetNext (m_Buckets [iHashKey]); - m_Buckets [iHashKey] = pElement; - } - - return S_OK; -} - - -OBJECTHANDLE LogHashTable::GetEntryFromHashTable (const WCHAR *pKey) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - } - CONTRACTL_END; - - if (pKey == NULL) - { - return NULL; - } - - int iHashKey = 0; - int iLength = (int)wcslen (pKey); - - // Calculate the hash value of the given key - for (int i= 0; iGetKey(), pKey) == 0) - { - return (pElement->GetData()); - } - - pElement = pElement->GetNext(); - } - - return NULL; -} - -// -// Returns a textual representation of the current stack trace. The format of the stack -// trace is the same as returned by StackTrace.ToString. -// -void GetManagedStackTraceString(BOOL fNeedFileInfo, SString &result) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - // Switch to cooperative GC mode before we call into managed code. - GCX_COOP(); - - MethodDescCallSite managedHelper(METHOD__STACK_TRACE__GET_MANAGED_STACK_TRACE_HELPER); - ARG_SLOT args[] = - { - BoolToArgSlot(fNeedFileInfo) - }; - - STRINGREF resultStringRef = (STRINGREF) managedHelper.Call_RetOBJECTREF(args); - resultStringRef->GetSString(result); -} - #endif // !DACCESS_COMPILE -- cgit v1.2.3