Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 5bcfde4

Browse files
author
Mike McLaughlin
authored
Add environment variable (COMPlus_EnableDiagnostics) to disable debugging and profiling. (#15878)
To disable the named pipes and semaphores created on linux execute "export COMPlus_EnableDiagnostics=0" before start the .NET Core program. On Windows execute "set COMPlus_EnableDiagnostics=0" and on Linux execute "export "COMPlus_EnableDiagnostics=0" Removed the "Telesto" registry entry (old unnecessary Silverlight code) and Watson (always true) checks. For issues #11769 and #8844.
1 parent 3e619d7 commit 5bcfde4

File tree

4 files changed

+44
-74
lines changed

4 files changed

+44
-74
lines changed

src/debug/daccess/enummem.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ HRESULT ClrDataAccess::EnumMemCLRStatic(IN CLRDataEnumMemoryFlags flags)
273273
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_runtimeLoadedBaseAddress.EnumMem(); )
274274
#endif // !FEATURE_PAL
275275

276-
// These are the structures that are pointed by global pointers and we care.
277-
// Some may reside in heap and some may reside as a static byte array in mscorwks.dll
278-
// That is ok. We will report them explicitly.
279-
//
276+
// These are the structures that are pointed by global pointers and we care.
277+
// Some may reside in heap and some may reside as a static byte array in mscorwks.dll
278+
// That is ok. We will report them explicitly.
279+
//
280280
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pConfig.EnumMem(); )
281281
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pPredefinedArrayTypes.EnumMem(); )
282282
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pObjectClass.EnumMem(); )
@@ -295,14 +295,17 @@ HRESULT ClrDataAccess::EnumMemCLRStatic(IN CLRDataEnumMemoryFlags flags)
295295
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pFreeObjectMethodTable.EnumMem(); )
296296
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_fHostConfig.EnumMem(); )
297297

298-
// These two static pointers are pointed to static data of byte[]
299-
// then run constructor in place
300-
//
298+
// These two static pointers are pointed to static data of byte[]
299+
// then run constructor in place
300+
//
301301
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( SystemDomain::m_pSystemDomain.EnumMem(); )
302302
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( SharedDomain::m_pSharedDomain.EnumMem(); )
303303
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pDebugger.EnumMem(); )
304304
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pEEInterface.EnumMem(); )
305-
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pDebugInterface.EnumMem(); )
305+
if (g_pDebugInterface != nullptr)
306+
{
307+
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED(g_pDebugInterface.EnumMem(); )
308+
}
306309
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_pEEDbgInterfaceImpl.EnumMem(); )
307310
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_CORDebuggerControlFlags.EnumMem(); )
308311
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED( g_Mscorlib.EnumMem(); )

src/debug/ee/debugger.cpp

Lines changed: 29 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,29 +1883,6 @@ CLR_ENGINE_METRICS g_CLREngineMetrics = {
18831883
CorDebugVersion_4_0,
18841884
&g_hContinueStartupEvent};
18851885

1886-
1887-
bool IsTelestoDebugPackInstalled()
1888-
{
1889-
RegKeyHolder hKey;
1890-
if (ERROR_SUCCESS != WszRegOpenKeyEx(HKEY_LOCAL_MACHINE, FRAMEWORK_REGISTRY_KEY_W, 0, KEY_READ, &hKey))
1891-
return false;
1892-
1893-
bool debugPackInstalled = false;
1894-
1895-
DWORD cbValue = 0;
1896-
1897-
if (ERROR_SUCCESS == WszRegQueryValueEx(hKey, CLRConfig::EXTERNAL_DbgPackShimPath, NULL, NULL, NULL, &cbValue))
1898-
{
1899-
if (cbValue != 0)
1900-
{
1901-
debugPackInstalled = true;
1902-
}
1903-
}
1904-
1905-
// RegCloseKey called by holder
1906-
return debugPackInstalled;
1907-
}
1908-
19091886
#define StartupNotifyEventNamePrefix W("TelestoStartupEvent_")
19101887
const int cchEventNameBufferSize = sizeof(StartupNotifyEventNamePrefix)/sizeof(WCHAR) + 8; // + hex DWORD (8). NULL terminator is included in sizeof(StartupNotifyEventNamePrefix)
19111888
HANDLE OpenStartupNotificationEvent()
@@ -1917,7 +1894,7 @@ HANDLE OpenStartupNotificationEvent()
19171894
return WszOpenEvent(MAXIMUM_ALLOWED | SYNCHRONIZE | EVENT_MODIFY_STATE, FALSE, szEventName);
19181895
}
19191896

1920-
void NotifyDebuggerOfTelestoStartup()
1897+
void NotifyDebuggerOfStartup()
19211898
{
19221899
// Create the continue event first so that we guarantee that any
19231900
// enumeration of this process will get back a valid continue event
@@ -1978,26 +1955,9 @@ HRESULT Debugger::Startup(void)
19781955
_ASSERTE(g_pEEInterface != NULL);
19791956

19801957
#if !defined(FEATURE_PAL)
1981-
if (IsWatsonEnabled() || IsTelestoDebugPackInstalled())
1982-
{
1983-
// Iff the debug pack is installed, then go through the telesto debugging pipeline.
1984-
LOG((LF_CORDB, LL_INFO10, "Debugging service is enabled because debug pack is installed or Watson support is enabled)\n"));
1985-
1986-
// This may block while an attach occurs.
1987-
NotifyDebuggerOfTelestoStartup();
1988-
}
1989-
else
1990-
{
1991-
// On Windows, it's actually safe to finish the initialization here even without the debug pack.
1992-
// However, doing so causes a perf regression because we used to bail out early if the debug
1993-
// pack is not installed.
1994-
//
1995-
// Unlike Windows, we can't continue executing this function if the debug pack is not installed.
1996-
// The transport requires the debug pack to be present. Otherwise it'll raise a fatal error.
1997-
return S_FALSE;
1998-
}
1958+
// This may block while an attach occurs.
1959+
NotifyDebuggerOfStartup();
19991960
#endif // !FEATURE_PAL
2000-
20011961
{
20021962
DebuggerLockHolder dbgLockHolder(this);
20031963

@@ -2008,7 +1968,6 @@ HRESULT Debugger::Startup(void)
20081968
// threads running and throwing debug events. Keep these stress procs separate so that
20091969
// we can focus on certain problem areas.
20101970
#ifdef _DEBUG
2011-
20121971
g_DbgShouldntUseDebugger = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_DbgNoDebugger) != 0;
20131972

20141973

@@ -2076,6 +2035,29 @@ HRESULT Debugger::Startup(void)
20762035

20772036
InitializeHijackFunctionAddress();
20782037

2038+
// Also initialize the AppDomainEnumerationIPCBlock
2039+
#if !defined(FEATURE_IPCMAN) || defined(FEATURE_DBGIPC_TRANSPORT_VM)
2040+
m_pAppDomainCB = new (nothrow) AppDomainEnumerationIPCBlock();
2041+
#else
2042+
m_pAppDomainCB = g_pIPCManagerInterface->GetAppDomainBlock();
2043+
#endif
2044+
2045+
if (m_pAppDomainCB == NULL)
2046+
{
2047+
LOG((LF_CORDB, LL_INFO100, "D::S: Failed to get AppDomain IPC block from IPCManager.\n"));
2048+
ThrowHR(E_FAIL);
2049+
}
2050+
2051+
hr = InitAppDomainIPC();
2052+
_ASSERTE(SUCCEEDED(hr)); // throws on error.
2053+
2054+
// Allows the debugger (and profiler) diagnostics to be disabled so resources like
2055+
// the named pipes and semaphores are not created.
2056+
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableDiagnostics) == 0)
2057+
{
2058+
return S_OK;
2059+
}
2060+
20792061
// Create the runtime controller thread, a.k.a, the debug helper thread.
20802062
// Don't use the interop-safe heap b/c we don't want to lazily create it.
20812063
m_pRCThread = new DebuggerRCThread(this);
@@ -2101,22 +2083,6 @@ HRESULT Debugger::Startup(void)
21012083

21022084
RaiseStartupNotification();
21032085

2104-
// Also initialize the AppDomainEnumerationIPCBlock
2105-
#if !defined(FEATURE_IPCMAN) || defined(FEATURE_DBGIPC_TRANSPORT_VM)
2106-
m_pAppDomainCB = new (nothrow) AppDomainEnumerationIPCBlock();
2107-
#else
2108-
m_pAppDomainCB = g_pIPCManagerInterface->GetAppDomainBlock();
2109-
#endif
2110-
2111-
if (m_pAppDomainCB == NULL)
2112-
{
2113-
LOG((LF_CORDB, LL_INFO100, "D::S: Failed to get AppDomain IPC block from IPCManager.\n"));
2114-
ThrowHR(E_FAIL);
2115-
}
2116-
2117-
hr = InitAppDomainIPC();
2118-
_ASSERTE(SUCCEEDED(hr)); // throws on error.
2119-
21202086
// See if we need to spin up the helper thread now, rather than later.
21212087
DebuggerIPCControlBlock* pIPCControlBlock = m_pRCThread->GetDCB();
21222088
(void)pIPCControlBlock; //prevent "unused variable" error from GCC
@@ -7220,7 +7186,8 @@ void Debugger::JitAttach(Thread * pThread, EXCEPTION_POINTERS * pExceptionInfo,
72207186
}
72217187
CONTRACTL_END;
72227188

7223-
if (IsDebuggerPresent())
7189+
// Don't do anything if there is a native debugger already attached or the debugging support has been disabled.
7190+
if (IsDebuggerPresent() || m_pRCThread == NULL)
72247191
return;
72257192

72267193
GCX_PREEMP_EEINTERFACE_TOGGLE_IFTHREAD();
@@ -14169,8 +14136,7 @@ DWORD Debugger::GetHelperThreadID(void )
1416914136
{
1417014137
LIMITED_METHOD_CONTRACT;
1417114138

14172-
return m_pRCThread->GetDCB()
14173-
->m_temporaryHelperThreadId;
14139+
return m_pRCThread ? m_pRCThread->GetDCB()->m_temporaryHelperThreadId : 0;
1417414140
}
1417514141

1417614142

src/debug/ee/debugger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,10 +3950,10 @@ class IPCHostSecurityAttributeHolder
39503950
#if _DEBUG
39513951

39523952
#define MAY_DO_HELPER_THREAD_DUTY_THROWS_CONTRACT \
3953-
if (!m_pRCThread->IsRCThreadReady()) { THROWS; } else { NOTHROW; }
3953+
if ((m_pRCThread == NULL) || !m_pRCThread->IsRCThreadReady()) { THROWS; } else { NOTHROW; }
39543954

39553955
#define MAY_DO_HELPER_THREAD_DUTY_GC_TRIGGERS_CONTRACT \
3956-
if (!m_pRCThread->IsRCThreadReady() || (GetThread() != NULL)) { GC_TRIGGERS; } else { GC_NOTRIGGER; }
3956+
if ((m_pRCThread == NULL) || !m_pRCThread->IsRCThreadReady() || (GetThread() != NULL)) { GC_TRIGGERS; } else { GC_NOTRIGGER; }
39573957

39583958
#define GC_TRIGGERS_FROM_GETJITINFO if (GetThreadNULLOk() != NULL) { GC_TRIGGERS; } else { GC_NOTRIGGER; }
39593959

src/inc/clrconfigvalues.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ CONFIG_DWORD_INFO_EX(INTERNAL_D__FCE, W("D::FCE"), 0, "allows an assert when cra
190190
//
191191
// Debugger
192192
//
193-
CONFIG_DWORD_INFO_EX(INTERNAL_DbgBreakIfLocksUnavailable, W("DbgBreakIfLocksUnavailable"), 0, "allows an assert when the debugger can't take a lock ", CLRConfig::REGUTIL_default)
193+
RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_EnableDiagnostics, W("EnableDiagnostics"), 1, "allows the debugger and profiler diagnostics to be disabled", CLRConfig::REGUTIL_default)
194+
CONFIG_DWORD_INFO_EX(INTERNAL_DbgBreakIfLocksUnavailable, W("DbgBreakIfLocksUnavailable"), 0, "allows an assert when the debugger can't take a lock", CLRConfig::REGUTIL_default)
194195
CONFIG_DWORD_INFO_EX(INTERNAL_DbgBreakOnErr, W("DbgBreakOnErr"), 0, "allows an assert when we get a failing hresult", CLRConfig::REGUTIL_default)
195196
CONFIG_DWORD_INFO_EX(INTERNAL_DbgBreakOnMapPatchToDJI, W("DbgBreakOnMapPatchToDJI"), 0, "allows an assert when mapping a patch to an address", CLRConfig::REGUTIL_default)
196197
CONFIG_DWORD_INFO_EX(INTERNAL_DbgBreakOnRawInt3, W("DbgBreakOnRawInt3"), 0, "allows an assert for test coverage for debug break or other int3 breaks", CLRConfig::REGUTIL_default)

0 commit comments

Comments
 (0)