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

Commit 1e07644

Browse files
Mike McLaughlindanmoseley
authored andcommitted
Fix xplat debugging perf problem. (#19911) (#20054)
Issue #18705 Add threadId to DebuggerIPCEvent so we don't need to use the slow DAC functions (because of extra memory reads) to get it. Fixed CorDBIPC_BUFFER_SIZE on arm builds.
1 parent 048b6b5 commit 1e07644

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

src/debug/di/dbgtransportpipeline.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -357,29 +357,12 @@ BOOL DbgTransportPipeline::WaitForDebugEvent(DEBUG_EVENT * pEvent, DWORD dwTimeo
357357
m_pTransport->GetNextEvent(m_pIPCEvent, CorDBIPC_BUFFER_SIZE);
358358

359359
pEvent->dwProcessId = m_pIPCEvent->processId;
360+
pEvent->dwThreadId = m_pIPCEvent->threadId;
360361
_ASSERTE(m_dwProcessId == m_pIPCEvent->processId);
361362

362-
// We are supposed to return a thread ID in the DEBUG_EVENT back to our caller.
363-
// However, we don't actually store the thread ID in the DebuggerIPCEvent anymore. Instead,
364-
// we just get a VMPTR_Thread, and so we need to find the thread ID associated with the VMPTR_Thread.
365-
pEvent->dwThreadId = 0;
366-
HRESULT hr = S_OK;
367-
EX_TRY
368-
{
369-
if (!m_pIPCEvent->vmThread.IsNull())
370-
{
371-
pEvent->dwThreadId = pProcess->GetDAC()->TryGetVolatileOSThreadID(m_pIPCEvent->vmThread);
372-
}
373-
}
374-
EX_CATCH_HRESULT(hr);
375-
if (FAILED(hr))
376-
{
377-
return FALSE;
378-
}
379-
380363
// The Windows implementation stores the target address of the IPC event in the debug event.
381364
// We can do that for Mac debugging, but that would require the caller to do another cross-machine
382-
// ReadProcessMemory(). Since we have all the data in-proc already, we just store a local address.
365+
// ReadProcessMemory(). Since we have all the data in-proc already, we just store a local address.
383366
//
384367
// @dbgtodo Mac - We are using -1 as a dummy base address right now.
385368
// Currently Mac remote debugging doesn't really support multi-instance.

src/debug/ee/debugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,7 @@ class Debugger : public DebugInterface
26792679
ipce->hr = S_OK;
26802680

26812681
ipce->processId = m_processId;
2682+
ipce->threadId = 0;
26822683
// AppDomain, Thread, are already initialized
26832684
}
26842685

@@ -2709,6 +2710,7 @@ class Debugger : public DebugInterface
27092710
ipce->type = type;
27102711
ipce->hr = S_OK;
27112712
ipce->processId = m_processId;
2713+
ipce->threadId = pThread ? pThread->GetOSThreadId() : 0;
27122714
ipce->vmAppDomain = vmAppDomain;
27132715
ipce->vmThread.SetRawPtr(pThread);
27142716
}

src/debug/inc/dbgipcevents.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,15 @@ struct MSLAYOUT DebuggerIPCRuntimeOffsets
179179
// aren't any embedded buffers in the DebuggerIPCControlBlock).
180180

181181
#if defined(DBG_TARGET_X86) || defined(DBG_TARGET_ARM)
182-
#define CorDBIPC_BUFFER_SIZE (2088) // hand tuned to ensure that ipc block in IPCHeader.h fits in 1 page.
182+
#ifdef _WIN64
183+
#define CorDBIPC_BUFFER_SIZE 2104
184+
#else
185+
#define CorDBIPC_BUFFER_SIZE 2092
186+
#endif
183187
#else // !_TARGET_X86_ && !_TARGET_ARM_
184-
// This is the size of a DebuggerIPCEvent. You will hit an assert in Cordb::Initialize() (DI\process.cpp)
188+
// This is the size of a DebuggerIPCEvent. You will hit an assert in Cordb::Initialize() (di\rsmain.cpp)
185189
// if this is not defined correctly. AMD64 actually has a page size of 0x1000, not 0x2000.
186-
#define CorDBIPC_BUFFER_SIZE 4016 // (4016 + 6) * 2 + 148 = 8192 (two (DebuggerIPCEvent + alignment padding) +
187-
// other fields = page size)
190+
#define CorDBIPC_BUFFER_SIZE 4016 // (4016 + 6) * 2 + 148 = 8192 (two (DebuggerIPCEvent + alignment padding) + other fields = page size)
188191
#endif // DBG_TARGET_X86 || DBG_TARGET_ARM
189192

190193
//
@@ -1907,6 +1910,7 @@ struct MSLAYOUT DebuggerIPCEvent
19071910
DebuggerIPCEvent* next;
19081911
DebuggerIPCEventType type;
19091912
DWORD processId;
1913+
DWORD threadId;
19101914
VMPTR_AppDomain vmAppDomain;
19111915
VMPTR_Thread vmThread;
19121916

0 commit comments

Comments
 (0)