Skip to content

Commit 7be3790

Browse files
Mike McLaughlinhoyosjs
Mike McLaughlin
andauthored
Add logging callback to DAC EnumMemoryRegion API (#73599)
* Add logging callback to DAC EnumMemoryRegion API Add the ICLRDataEnumMemoryRegionsLoggingCallback interface so createdump can receive logging from the EnumMemoryRegion API. Add logging to MethodTable EnumMemoryRegion for invalid EEClass/Canonical MT. * Add checked build logging after waitpid for createdump to help diagnose issue #72755. * Add more DAC logging * Code review feedback Co-authored-by: Juan Hoyos <[email protected]>
1 parent 834abed commit 7be3790

File tree

13 files changed

+286
-18
lines changed

13 files changed

+286
-18
lines changed

src/coreclr/debug/createdump/crashinfo.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ CrashInfo::QueryInterface(
8888
AddRef();
8989
return S_OK;
9090
}
91+
else if (InterfaceId == IID_ICLRDataLoggingCallback)
92+
{
93+
*Interface = (ICLRDataLoggingCallback*)this;
94+
AddRef();
95+
return S_OK;
96+
}
9197
else
9298
{
9399
*Interface = nullptr;
@@ -122,6 +128,14 @@ CrashInfo::EnumMemoryRegion(
122128
return S_OK;
123129
}
124130

131+
HRESULT STDMETHODCALLTYPE
132+
CrashInfo::LogMessage(
133+
/* [in] */ LPCSTR message)
134+
{
135+
Trace("%s", message);
136+
return S_OK;
137+
}
138+
125139
//
126140
// Gather all the necessary crash dump info.
127141
//

src/coreclr/debug/createdump/crashinfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern const std::string GetDirectory(const std::string& fileName);
3535
extern std::string FormatString(const char* format, ...);
3636
extern std::string FormatGuid(const GUID* guid);
3737

38-
class CrashInfo : public ICLRDataEnumMemoryRegionsCallback,
38+
class CrashInfo : public ICLRDataEnumMemoryRegionsCallback, public ICLRDataLoggingCallback,
3939
#ifdef __APPLE__
4040
public MachOReader
4141
#else
@@ -135,6 +135,9 @@ class CrashInfo : public ICLRDataEnumMemoryRegionsCallback,
135135
// ICLRDataEnumMemoryRegionsCallback
136136
virtual HRESULT STDMETHODCALLTYPE EnumMemoryRegion(/* [in] */ CLRDATA_ADDRESS address, /* [in] */ ULONG32 size);
137137

138+
// ICLRDataLoggingCallback
139+
virtual HRESULT STDMETHODCALLTYPE LogMessage( /* [in] */ LPCSTR message);
140+
138141
private:
139142
#ifdef __APPLE__
140143
bool EnumerateMemoryRegions();

src/coreclr/debug/daccess/daccess.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,6 +3155,7 @@ ClrDataAccess::ClrDataAccess(ICorDebugDataTarget * pTarget, ICLRDataTarget * pLe
31553155

31563156
m_enumMemCb = NULL;
31573157
m_updateMemCb = NULL;
3158+
m_logMessageCb = NULL;
31583159
m_enumMemFlags = (CLRDataEnumMemoryFlags)-1; // invalid
31593160
m_jitNotificationTable = NULL;
31603161
m_gcNotificationTable = NULL;
@@ -6364,6 +6365,27 @@ bool ClrDataAccess::DacUpdateMemoryRegion(TADDR addr, TSIZE_T bufferSize, BYTE*
63646365
return true;
63656366
}
63666367

6368+
//
6369+
// DacLogMessage - logs a message to an external DAC client
6370+
//
6371+
// Parameters:
6372+
// message - message to log
6373+
//
6374+
void DacLogMessage(LPCSTR format, ...)
6375+
{
6376+
SUPPORTS_DAC_HOST_ONLY;
6377+
6378+
if (g_dacImpl->IsLogMessageEnabled())
6379+
{
6380+
va_list args;
6381+
va_start(args, format);
6382+
char buffer[1024];
6383+
_vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, format, args);
6384+
g_dacImpl->LogMessage(buffer);
6385+
va_end(args);
6386+
}
6387+
}
6388+
63676389
//
63686390
// Check whether a region of target memory is fully readable.
63696391
//

src/coreclr/debug/daccess/dacfn.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ DacInstantiateTypeByAddressHelper(TADDR addr, ULONG32 size, bool throwEx, bool f
471471
g_dacImpl->m_instances.ReturnAlloc(inst);
472472
if (throwEx)
473473
{
474+
DacLogMessage("DacReadAll(%p, %08x) FAILED %08x\n", addr, size, status);
474475
DacError(status);
475476
}
476477
return NULL;

src/coreclr/debug/daccess/dacimpl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,19 @@ class ClrDataAccess
13371337
bool ReportMem(TADDR addr, TSIZE_T size, bool fExpectSuccess = true);
13381338
bool DacUpdateMemoryRegion(TADDR addr, TSIZE_T bufferSize, BYTE* buffer);
13391339

1340+
inline bool IsLogMessageEnabled()
1341+
{
1342+
return m_logMessageCb != NULL;
1343+
}
1344+
1345+
void LogMessage(LPCSTR message)
1346+
{
1347+
if (m_logMessageCb != NULL)
1348+
{
1349+
m_logMessageCb->LogMessage(message);
1350+
}
1351+
}
1352+
13401353
void ClearDumpStats();
13411354
JITNotification* GetHostJitNotificationTable();
13421355
GcNotification* GetHostGcNotificationTable();
@@ -1448,6 +1461,7 @@ class ClrDataAccess
14481461
MDImportsCache m_mdImports;
14491462
ICLRDataEnumMemoryRegionsCallback* m_enumMemCb;
14501463
ICLRDataEnumMemoryRegionsCallback2* m_updateMemCb;
1464+
ICLRDataLoggingCallback* m_logMessageCb;
14511465
CLRDataEnumMemoryFlags m_enumMemFlags;
14521466
JITNotification* m_jitNotificationTable;
14531467
GcNotification* m_gcNotificationTable;

src/coreclr/debug/daccess/enummem.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,9 @@ ClrDataAccess::EnumMemoryRegions(IN ICLRDataEnumMemoryRegionsCallback* callback,
19371937
// It is expected to fail on pre Win8 OSes.
19381938
callback->QueryInterface(IID_ICLRDataEnumMemoryRegionsCallback2, (void **)&m_updateMemCb);
19391939

1940+
// QI for optional logging callback that createdump uses
1941+
callback->QueryInterface(IID_ICLRDataLoggingCallback, (void **)&m_logMessageCb);
1942+
19401943
EX_TRY
19411944
{
19421945
ClearDumpStats();
@@ -2000,6 +2003,11 @@ ClrDataAccess::EnumMemoryRegions(IN ICLRDataEnumMemoryRegionsCallback* callback,
20002003
m_updateMemCb->Release();
20012004
m_updateMemCb = NULL;
20022005
}
2006+
if (m_logMessageCb)
2007+
{
2008+
m_logMessageCb->Release();
2009+
m_logMessageCb = NULL;
2010+
}
20032011
m_enumMemCb = NULL;
20042012

20052013
DAC_LEAVE();

src/coreclr/inc/clrdata.idl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import "unknwn.idl";
2525
interface ICLRDataEnumMemoryRegions;
2626
interface ICLRDataEnumMemoryRegionsCallback;
2727
interface ICLRDataEnumMemoryRegionsCallback2;
28+
interface ICLRDataEnumMemoryRegionsCallback3;
2829
interface ICLRDataTarget;
2930
interface ICLRDataTarget2;
3031
interface ICLRMetadataLocator;
@@ -287,6 +288,20 @@ interface ICLRDataEnumMemoryRegionsCallback2 : ICLRDataEnumMemoryRegionsCallback
287288
[in, size_is(bufferSize)] BYTE* buffer);
288289
}
289290

291+
/*
292+
* Optional callback interface for logging EnumMemoryRegions operations and errors.
293+
*/
294+
[
295+
object,
296+
local,
297+
uuid(F315248D-8B79-49DB-B184-37426559F703)
298+
]
299+
interface ICLRDataLoggingCallback : IUnknown
300+
{
301+
HRESULT LogMessage(
302+
[in] LPCSTR message);
303+
}
304+
290305
/*
291306
* Flags for controlling which memory regions are enumerated.
292307
*/

src/coreclr/inc/daccess.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,15 @@ HRESULT DacWriteHostInstance(PVOID host, bool throwEx);
710710
// gathering cancelation for details see
711711
// code:ClrDataAccess.EnumMemoryRegionsWrapper
712712

713+
extern void DacLogMessage(LPCSTR format, ...);
714+
713715
// This is usable in EX_TRY exactly how RethrowTerminalExceptions et cetera
714716
#define RethrowCancelExceptions \
715717
if (GET_EXCEPTION()->GetHR() == COR_E_OPERATIONCANCELED) \
716718
{ \
717719
EX_RETHROW; \
718-
}
720+
} \
721+
DacLogMessage("DAC exception caught at %s:%d\n", __FILE__, __LINE__);
719722

720723
// Occasionally it's necessary to allocate some host memory for
721724
// instance data that's created on the fly and so doesn't directly

src/coreclr/pal/prebuilt/idl/clrdata_i.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
/* link this file in with the server and any clients */
77

88

9-
/* File created by MIDL compiler version 8.01.0622 */
10-
/* at Mon Jan 18 19:14:07 2038
11-
*/
12-
/* Compiler settings for C:/ssd/runtime/src/coreclr/inc/clrdata.idl:
13-
Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.01.0622
9+
/* File created by MIDL compiler version 8.01.0626 */
10+
/* Compiler settings for clrdata.idl:
11+
Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0626
1412
protocol : dce , ms_ext, c_ext, robust
1513
error checks: allocation ref bounds_check enum stub_data
1614
VC __declspec() decoration level:
@@ -89,6 +87,9 @@ MIDL_DEFINE_GUID(IID, IID_ICLRDataEnumMemoryRegionsCallback,0xBCDD6908,0xBA2D,0x
8987
MIDL_DEFINE_GUID(IID, IID_ICLRDataEnumMemoryRegionsCallback2,0x3721A26F,0x8B91,0x4D98,0xA3,0x88,0xDB,0x17,0xB3,0x56,0xFA,0xDB);
9088

9189

90+
MIDL_DEFINE_GUID(IID, IID_ICLRDataLoggingCallback,0xF315248D,0x8B79,0x49DB,0xB1,0x84,0x37,0x42,0x65,0x59,0xF7,0x03);
91+
92+
9293
MIDL_DEFINE_GUID(IID, IID_ICLRDataEnumMemoryRegions,0x471c35b4,0x7c2f,0x4ef0,0xa9,0x45,0x00,0xf8,0xc3,0x80,0x56,0xf1);
9394

9495
#undef MIDL_DEFINE_GUID

0 commit comments

Comments
 (0)