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

Commit 39b1ec6

Browse files
committed
Code changes for firing etw events when a pdb is dynamically loaded. This corresponds to the following user story: 1200238. As a profiler developer, I want to access PDB content for dynamic assemblies in the ETW event stream, so that I can show my users source for their callstack frames.
The main function in eventtrace.cpp, EmitCodeSymbols, divides the pdb stream into appropriate chunks and transmits them as events in order. There are helper functions which have been taken from the corresponding code in Desktop (Netfxdev1) to provide a dynamically loaded pdb through the profiler authored by Noah. The test uses EventToSymbols, which is based on TraceEventParser to turn on the CodeSymbols and ModuleLoad keywords and listens for events that send out pdb chunks. It then concatenates the chunks to create the pdb on disk. The BigPdb.cs program loads a dll and pdb dynamically, which triggers the events by the runtime. Once the pdb is recreated, it is compared with the original to make sure there are no differences and if not, the test is declared as passed. The test also uses an EventSource event to transmit a unique cookie to make sure the pdb created corresponds to the process under test, in case there are mulitple instances of the test running. [tfs-changeset: 1535373]
1 parent 1dafc0b commit 39b1ec6

File tree

7 files changed

+372
-7
lines changed

7 files changed

+372
-7
lines changed

src/gc/env/etmdummy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
#define FireEtwDebugIPCEventEnd() 0
170170
#define FireEtwDebugExceptionProcessingStart() 0
171171
#define FireEtwDebugExceptionProcessingEnd() 0
172+
#define FireEtwCodeSymbols(ModuleId, TotalChunks, ChunkNumber, ChunkLength, Chunk, ClrInstanceID) 0
172173
#define FireEtwCLRStackWalkDCStart(ClrInstanceID, Reserved1, Reserved2, FrameCount, Stack) 0
173174
#define FireEtwMethodDCStart(MethodID, ModuleID, MethodStartAddress, MethodSize, MethodToken, MethodFlags) 0
174175
#define FireEtwMethodDCStart_V1(MethodID, ModuleID, MethodStartAddress, MethodSize, MethodToken, MethodFlags, ClrInstanceID) 0

src/inc/eventtracebase.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,22 @@ namespace ETW
730730
static VOID RuntimeInformation(INT32 type);
731731
#else
732732
static VOID RuntimeInformation(INT32 type) {};
733+
#endif // FEATURE_EVENT_TRACE
734+
};
735+
736+
class CodeSymbolLog
737+
{
738+
public:
739+
#ifdef FEATURE_EVENT_TRACE
740+
static VOID EmitCodeSymbols(Module* pModule);
741+
static HRESULT GetInMemorySymbolsLength(Module* pModule, DWORD* pCountSymbolBytes);
742+
static HRESULT ReadInMemorySymbols(Module* pmodule, DWORD symbolsReadOffset, BYTE* pSymbolBytes,
743+
DWORD countSymbolBytes, DWORD* pCountSymbolBytesRead);
744+
#else
745+
static VOID EmitCodeSymbols(Module* pModule) {}
746+
static HRESULT GetInMemorySymbolsLength(Module* pModule, DWORD* pCountSymbolBytes) { return S_OK; }
747+
static HRESULT ReadInMemorySymbols(Module* pmodule, DWORD symbolsReadOffset, BYTE* pSymbolBytes,
748+
DWORD countSymbolBytes, DWORD* pCountSymbolBytesRead) { return S_OK; }
733749
#endif // FEATURE_EVENT_TRACE
734750
};
735751
};

src/pal/prebuilt/inc/clretwall.h

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Routine Description:
218218
#endif
219219
#endif // MCGEN_DISABLE_PROVIDER_CODE_GENERATION
220220
//+
221-
// Provider Microsoft-Windows-DotNETRuntime Event Count 166
221+
// Provider Microsoft-Windows-DotNETRuntime Event Count 167
222222
//+
223223
EXTERN_C __declspec(selectany) const GUID MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER = {0xe13c0d23, 0xccbc, 0x4e12, {0x93, 0x1b, 0xd9, 0xcc, 0x2e, 0xee, 0x27, 0xe4}};
224224

@@ -371,6 +371,8 @@ EXTERN_C __declspec(selectany) const GUID ThreadId = {0x641994c5, 0x16f2, 0x4123
371371
EXTERN_C __declspec(selectany) const GUID DebugIPCEventId = {0xec2f3703, 0x8321, 0x4301, {0xbd, 0x51, 0x2c, 0xb9, 0xa0, 0x9f, 0x31, 0xb1}};
372372
#define CLR_EXCEPTION_PROCESSING_TASK 0x1a
373373
EXTERN_C __declspec(selectany) const GUID DebugExceptionProcessingId = {0xc4412198, 0xef03, 0x47f1, {0x9b, 0xd1, 0x11, 0xc6, 0x63, 0x7a, 0x20, 0x62}};
374+
#define CLR_CODE_SYMBOLS_TASK 0x1e
375+
EXTERN_C __declspec(selectany) const GUID CodeSymbolsId = {0x53aedf69, 0x2049, 0x4f7d, {0x93, 0x45, 0xd3, 0x01, 0x8b, 0x5c, 0x4d, 0x80}};
374376
//
375377
// Keyword
376378
//
@@ -403,6 +405,7 @@ EXTERN_C __declspec(selectany) const GUID DebugExceptionProcessingId = {0xc44121
403405
#define CLR_THREADTRANSFER_KEYWORD 0x80000000
404406
#define CLR_DEBUGGER_KEYWORD 0x100000000
405407
#define CLR_MONITORING_KEYWORD 0x200000000
408+
#define CLR_CODESYMBOLS_KEYWORD 0x400000000
406409

407410
//
408411
// Event Descriptors
@@ -739,6 +742,8 @@ EXTERN_C __declspec(selectany) const EVENT_DESCRIPTOR DebugExceptionProcessingSt
739742
#define DebugExceptionProcessingStart_value 0xf2
740743
EXTERN_C __declspec(selectany) const EVENT_DESCRIPTOR DebugExceptionProcessingEnd = {0xf3, 0x0, 0x0, 0x4, 0x2, 0x1a, 0x100000000};
741744
#define DebugExceptionProcessingEnd_value 0xf3
745+
EXTERN_C __declspec(selectany) const EVENT_DESCRIPTOR CodeSymbols = {0x104, 0x0, 0x0, 0x5, 0x1, 0x1e, 0x400000000};
746+
#define CodeSymbols_value 0x104
742747

743748
//
744749
// Note on Generate Code from Manifest Windows Vista and above
@@ -768,9 +773,9 @@ EXTERN_C __declspec(selectany) const EVENT_DESCRIPTOR DebugExceptionProcessingEn
768773
//
769774

770775
EXTERN_C __declspec(selectany) DECLSPEC_CACHEALIGN ULONG Microsoft_Windows_DotNETRuntimeEnableBits[1];
771-
EXTERN_C __declspec(selectany) const ULONGLONG Microsoft_Windows_DotNETRuntimeKeywords[31] = {0x1, 0x1, 0x10001, 0x80000, 0x100000, 0x200000, 0x400000, 0x2, 0x2000000, 0x10000, 0x10000, 0x80010000, 0x80010000, 0x0, 0x200008000, 0x8000, 0x4000, 0x40000000, 0x800, 0x10800, 0x2000, 0x30, 0x10, 0x1000, 0x20000, 0x8, 0x20000008, 0x20000000, 0x400, 0x400, 0x100000000};
772-
EXTERN_C __declspec(selectany) const UCHAR Microsoft_Windows_DotNETRuntimeLevels[31] = {4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 2, 4, 4, 0, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 5, 4, 4};
773-
EXTERN_C __declspec(selectany) MCGEN_TRACE_CONTEXT MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context = {0, 0, 0, 0, 0, 0, 0, 0, 31, Microsoft_Windows_DotNETRuntimeEnableBits, Microsoft_Windows_DotNETRuntimeKeywords, Microsoft_Windows_DotNETRuntimeLevels};
776+
EXTERN_C __declspec(selectany) const ULONGLONG Microsoft_Windows_DotNETRuntimeKeywords[32] = {0x1, 0x1, 0x10001, 0x80000, 0x100000, 0x200000, 0x400000, 0x2, 0x2000000, 0x10000, 0x10000, 0x80010000, 0x80010000, 0x0, 0x200008000, 0x8000, 0x4000, 0x40000000, 0x800, 0x10800, 0x2000, 0x30, 0x10, 0x1000, 0x20000, 0x8, 0x20000008, 0x20000000, 0x400, 0x400, 0x100000000, 0x400000000};
777+
EXTERN_C __declspec(selectany) const UCHAR Microsoft_Windows_DotNETRuntimeLevels[32] = {4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 2, 4, 4, 0, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 5, 4, 4, 5};
778+
EXTERN_C __declspec(selectany) MCGEN_TRACE_CONTEXT MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context = {0, 0, 0, 0, 0, 0, 0, 0, 32, Microsoft_Windows_DotNETRuntimeEnableBits, Microsoft_Windows_DotNETRuntimeKeywords, Microsoft_Windows_DotNETRuntimeLevels};
774779

775780
EXTERN_C __declspec(selectany) REGHANDLE Microsoft_Windows_DotNETRuntimeHandle = (REGHANDLE)0;
776781

@@ -3191,6 +3196,20 @@ Routine Description:
31913196
CoTemplateEventDescriptor(Microsoft_Windows_DotNETRuntimeHandle, &DebugExceptionProcessingEnd)\
31923197
: ERROR_SUCCESS\
31933198

3199+
//
3200+
// Enablement check macro for CodeSymbols
3201+
//
3202+
3203+
#define EventEnabledCodeSymbols() ((Microsoft_Windows_DotNETRuntimeEnableBits[0] & 0x80000000) != 0)
3204+
3205+
//
3206+
// Event Macro for CodeSymbols
3207+
//
3208+
#define FireEtwCodeSymbols(ModuleId, TotalChunks, ChunkNumber, ChunkLength, Chunk, ClrInstanceID)\
3209+
EventEnabledCodeSymbols() ?\
3210+
CoTemplate_xhhqbh(Microsoft_Windows_DotNETRuntimeHandle, &CodeSymbols, ModuleId, TotalChunks, ChunkNumber, ChunkLength, Chunk, ClrInstanceID)\
3211+
: ERROR_SUCCESS\
3212+
31943213
#endif // MCGEN_DISABLE_PROVIDER_CODE_GENERATION
31953214

31963215
//+
@@ -10909,6 +10928,54 @@ MCGEN_CALLOUT(RegHandle,
1090910928
}
1091010929
#endif
1091110930

10931+
//
10932+
//Template from manifest : CodeSymbols
10933+
//
10934+
#ifndef CoTemplate_xhhqbh_def
10935+
#define CoTemplate_xhhqbh_def
10936+
ETW_INLINE
10937+
ULONG
10938+
CoTemplate_xhhqbh(
10939+
_In_ REGHANDLE RegHandle,
10940+
_In_ PCEVENT_DESCRIPTOR Descriptor,
10941+
_In_ unsigned __int64 _Arg0,
10942+
_In_ const unsigned short _Arg1,
10943+
_In_ const unsigned short _Arg2,
10944+
_In_ const unsigned int _Arg3,
10945+
_In_reads_(_Arg3) const BYTE* _Arg4,
10946+
_In_ const unsigned short _Arg5
10947+
)
10948+
{
10949+
#define ARGUMENT_COUNT_xhhqbh 6
10950+
ULONG Error = ERROR_SUCCESS;
10951+
10952+
EVENT_DATA_DESCRIPTOR EventData[ARGUMENT_COUNT_xhhqbh];
10953+
10954+
EventDataDescCreate(&EventData[0], &_Arg0, sizeof(unsigned __int64) );
10955+
10956+
EventDataDescCreate(&EventData[1], &_Arg1, sizeof(const unsigned short) );
10957+
10958+
EventDataDescCreate(&EventData[2], &_Arg2, sizeof(const unsigned short) );
10959+
10960+
EventDataDescCreate(&EventData[3], &_Arg3, sizeof(const unsigned int) );
10961+
10962+
EventDataDescCreate(&EventData[4], _Arg4, (ULONG)sizeof(char)*_Arg3);
10963+
10964+
EventDataDescCreate(&EventData[5], &_Arg5, sizeof(const unsigned short) );
10965+
10966+
Error = EventWrite(RegHandle, Descriptor, ARGUMENT_COUNT_xhhqbh, EventData);
10967+
10968+
#ifdef MCGEN_CALLOUT
10969+
MCGEN_CALLOUT(RegHandle,
10970+
Descriptor,
10971+
ARGUMENT_COUNT_xhhqbh,
10972+
EventData);
10973+
#endif
10974+
10975+
return Error;
10976+
}
10977+
#endif
10978+
1091210979
//
1091310980
//Template from manifest : StressLog
1091410981
//
@@ -12438,6 +12505,7 @@ MCGEN_CALLOUT(RegHandle,
1243812505
#define MSG_RuntimePublisher_ThreadTransferKeywordMessage 0x10000020L
1243912506
#define MSG_RuntimePublisher_DebuggerKeywordMessage 0x10000021L
1244012507
#define MSG_RuntimePublisher_MonitoringKeywordMessage 0x10000022L
12508+
#define MSG_RuntimePublisher_CodeSymbolsKeywordMessage 0x10000023L
1244112509
#define MSG_RundownPublisher_LoaderKeywordMessage 0x11000004L
1244212510
#define MSG_RundownPublisher_JitKeywordMessage 0x11000005L
1244312511
#define MSG_RundownPublisher_NGenKeywordMessage 0x11000006L
@@ -12725,6 +12793,7 @@ MCGEN_CALLOUT(RegHandle,
1272512793
#define MSG_RuntimePublisher_ExceptionCatchTaskMessage 0x7000001BL
1272612794
#define MSG_RuntimePublisher_ExceptionFinallyTaskMessage 0x7000001CL
1272712795
#define MSG_RuntimePublisher_ExceptionFilterTaskMessage 0x7000001DL
12796+
#define MSG_RuntimePublisher_CodeSymbolsTaskMessage 0x7000001EL
1272812797
#define MSG_RundownPublisher_MethodTaskMessage 0x71000001L
1272912798
#define MSG_RundownPublisher_LoaderTaskMessage 0x71000002L
1273012799
#define MSG_RundownPublisher_StackTaskMessage 0x7100000BL
@@ -12848,6 +12917,7 @@ MCGEN_CALLOUT(RegHandle,
1284812917
#define MSG_RuntimePublisher_GCMarkWithTypeEventMessage 0xB00000CAL
1284912918
#define MSG_RuntimePublisher_ExceptionExceptionHandlingEventMessage 0xB00000FAL
1285012919
#define MSG_RuntimePublisher_ExceptionExceptionHandlingNoneEventMessage 0xB00000FBL
12920+
#define MSG_RuntimePublisher_CodeSymbolsEventMessage 0xB0000104L
1285112921
#define MSG_RuntimePublisher_GCStart_V1EventMessage 0xB0010001L
1285212922
#define MSG_RuntimePublisher_GCEnd_V1EventMessage 0xB0010002L
1285312923
#define MSG_RuntimePublisher_GCRestartEEEnd_V1EventMessage 0xB0010003L

src/pal/prebuilt/inc/etmdummy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
#define FireEtwDebugIPCEventEnd() 0
170170
#define FireEtwDebugExceptionProcessingStart() 0
171171
#define FireEtwDebugExceptionProcessingEnd() 0
172+
#define FireEtwCodeSymbols(ModuleId, TotalChunks, ChunkNumber, ChunkLength, Chunk, ClrInstanceID) 0
172173
#define FireEtwCLRStackWalkDCStart(ClrInstanceID, Reserved1, Reserved2, FrameCount, Stack) 0
173174
#define FireEtwMethodDCStart(MethodID, ModuleID, MethodStartAddress, MethodSize, MethodToken, MethodFlags) 0
174175
#define FireEtwMethodDCStart_V1(MethodID, ModuleID, MethodStartAddress, MethodSize, MethodToken, MethodFlags, ClrInstanceID) 0

src/vm/ClrEtwAll.man

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
message="$(string.RuntimePublisher.DebuggerKeywordMessage)" symbol="CLR_DEBUGGER_KEYWORD" />
7474
<keyword name="MonitoringKeyword" mask="0x200000000"
7575
message="$(string.RuntimePublisher.MonitoringKeywordMessage)" symbol="CLR_MONITORING_KEYWORD" />
76+
<keyword name="CodeSymbolsKeyword" mask="0x400000000"
77+
message="$(string.RuntimePublisher.CodeSymbolsKeywordMessage)" symbol="CLR_CODESYMBOLS_KEYWORD" />
7678
</keywords>
7779
<!--Tasks-->
7880
<tasks>
@@ -362,7 +364,13 @@
362364
<opcodes>
363365
</opcodes>
364366
</task>
365-
<!--Next available ID is 30-->
367+
<task name="CodeSymbols" symbol="CLR_CODE_SYMBOLS_TASK"
368+
value="30" eventGUID="{53aedf69-2049-4f7d-9345-d3018b5c4d80}"
369+
message="$(string.RuntimePublisher.CodeSymbolsTaskMessage)">
370+
<opcodes>
371+
</opcodes>
372+
</task>
373+
<!--Next available ID is 31-->
366374
</tasks>
367375
<!--Maps-->
368376
<maps>
@@ -2249,6 +2257,25 @@
22492257
</UserData>
22502258
</template>
22512259

2260+
<template tid="CodeSymbols">
2261+
<data name="ModuleId" inType="win:UInt64" />
2262+
<data name="TotalChunks" inType="win:UInt16" />
2263+
<data name="ChunkNumber" inType="win:UInt16" />
2264+
<data name="ChunkLength" inType="win:UInt32" />
2265+
<data name="Chunk" inType="win:Binary" length="ChunkLength"/>
2266+
<data name="ClrInstanceID" inType="win:UInt16" />
2267+
<UserData>
2268+
<CodeSymbols xmlns="myNs">
2269+
<ClrInstanceID> %1 </ClrInstanceID>
2270+
<ModuleId> %2 </ModuleId>
2271+
<TotalChunks> %3 </TotalChunks>
2272+
<ChunkNumber> %4 </ChunkNumber>
2273+
<ChunkLength> %5 </ChunkLength>
2274+
<Chunk> %6 </Chunk>
2275+
</CodeSymbols>
2276+
</UserData>
2277+
</template>
2278+
22522279
</templates>
22532280

22542281
<events>
@@ -3121,6 +3148,12 @@
31213148
keywords="DebuggerKeyword" opcode="win:Stop"
31223149
task="DebugExceptionProcessing"
31233150
symbol="DebugExceptionProcessingEnd" />
3151+
3152+
<!-- CLR Code Symbol Emission events 260-269 -->
3153+
<event value="260" version="0" level="win:Verbose" template="CodeSymbols"
3154+
keywords="CodeSymbolsKeyword" opcode="win:Start"
3155+
task="CodeSymbols"
3156+
symbol="CodeSymbols" message="$(string.RuntimePublisher.CodeSymbolsEventMessage)"/>
31243157
</events>
31253158
</provider>
31263159

@@ -6262,6 +6295,7 @@
62626295
<string id="RuntimePublisher.MethodJitTailCallSucceededEventMessage" value="MethodBeingCompiledNamespace=%1;%nMethodBeingCompiledName=%2;%nMethodBeingCompiledNameSignature=%3;%nCallerNamespace=%4;%nCallerName=%5;%nCallerNameSignature=%6;%nCalleeNamespace=%7;%nCalleeName=%8;%nCalleeNameSignature=%9;%nTailPrefix=%10;%nTailCallType=%11;%nClrInstanceID=%12" />
62636296
<string id="RuntimePublisher.SetGCHandleEventMessage" value="HandleID=%1;%nObjectID=%2;%nKind=%3;%nGeneration=%4;%nAppDomainID=%5;%nClrInstanceID=%6" />
62646297
<string id="RuntimePublisher.DestroyGCHandleEventMessage" value="HandleID=%1;%nClrInstanceID=%2" />
6298+
<string id="RuntimePublisher.CodeSymbolsEventMessage" value="%nClrInstanceId=%1;%nModuleId=%2;%nTotalChunks=%3;%nChunkNumber=%4;%nChunkLength=%5;%nChunk=%6" />
62656299
<string id="RundownPublisher.MethodDCStartEventMessage" value="MethodID=%1;%nModuleID=%2;%nMethodStartAddress=%3;%nMethodSize=%4;%nMethodToken=%5;%nMethodFlags=%6" />
62666300
<string id="RundownPublisher.MethodDCStart_V1EventMessage" value="MethodID=%1;%nModuleID=%2;%nMethodStartAddress=%3;%nMethodSize=%4;%nMethodToken=%5;%nMethodFlags=%6;%nClrInstanceID=%7" />
62676301
<string id="RundownPublisher.MethodDCStart_V2EventMessage" value="MethodID=%1;%nModuleID=%2;%nMethodStartAddress=%3;%nMethodSize=%4;%nMethodToken=%5;%nMethodFlags=%6;%nClrInstanceID=%7;%nReJITID=%8" />
@@ -6416,6 +6450,7 @@
64166450
<string id="RuntimePublisher.ThreadTaskMessage" value="Thread" />
64176451
<string id="RuntimePublisher.DebugIPCEventTaskMessage" value="DebugIPCEvent" />
64186452
<string id="RuntimePublisher.DebugExceptionProcessingTaskMessage" value="DebugExceptionProcessing" />
6453+
<string id="RuntimePublisher.CodeSymbolsTaskMessage" value="CodeSymbols" />
64196454
<string id="RundownPublisher.EEStartupTaskMessage" value="Runtime" />
64206455
<string id="RundownPublisher.MethodTaskMessage" value="Method" />
64216456
<string id="RundownPublisher.LoaderTaskMessage" value="Loader" />
@@ -6689,6 +6724,7 @@
66896724
<string id="RuntimePublisher.ThreadTransferKeywordMessage" value="ThreadTransfer" />
66906725
<string id="RuntimePublisher.DebuggerKeywordMessage" value="Debugger" />
66916726
<string id="RuntimePublisher.MonitoringKeywordMessage" value="Monitoring" />
6727+
<string id="RuntimePublisher.CodeSymbolsKeywordMessage" value="CodeSymbols" />
66926728
<string id="RundownPublisher.LoaderKeywordMessage" value="Loader" />
66936729
<string id="RundownPublisher.JitKeywordMessage" value="Jit" />
66946730
<string id="RundownPublisher.JittedMethodILToNativeMapRundownKeywordMessage" value="JittedMethodILToNativeMapRundown" />

src/vm/ceeload.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4467,8 +4467,7 @@ void Module::SetSymbolBytes(LPCBYTE pbSyms, DWORD cbSyms)
44674467
&cbWritten);
44684468
IfFailThrow(HRESULT_FROM_WIN32(dwError));
44694469

4470-
// Don't eager load the diasymreader
4471-
4470+
ETW::CodeSymbolLog::EmitCodeSymbols(this);
44724471
// Tell the debugger that symbols have been loaded for this
44734472
// module. We iterate through all domains which contain this
44744473
// module's assembly, and send a debugger notify for each one.

0 commit comments

Comments
 (0)