77// ---------------------------------------------------------------------------------------
88
99#include " cor_profiler.h"
10+ #include " logger.h"
1011
1112#ifndef _WIN32
1213#include < dlfcn.h>
@@ -22,51 +23,105 @@ EXTERN_C BOOL STDAPICALLTYPE IsProfilerAttached()
2223EXTERN_C VOID STDAPICALLTYPE GetAssemblyAndSymbolsBytes (BYTE** pAssemblyArray, int * assemblySize, BYTE** pSymbolsArray,
2324 int * symbolsSize)
2425{
25- return trace::profiler->GetAssemblyAndSymbolsBytes (pAssemblyArray, assemblySize, pSymbolsArray, symbolsSize);
26+ if (trace::profiler == nullptr )
27+ {
28+ trace::Logger::Error (" Error in GetAssemblyAndSymbolsBytes call. Tracer CLR Profiler was not initialized." );
29+ return ;
30+ }
31+
32+ trace::profiler->GetAssemblyAndSymbolsBytes (pAssemblyArray, assemblySize, pSymbolsArray, symbolsSize);
2633}
2734
2835EXTERN_C VOID STDAPICALLTYPE InitializeProfiler (WCHAR* id, trace::CallTargetDefinition* items, int size)
2936{
30- return trace::profiler->InitializeProfiler (id, items, size);
37+ if (trace::profiler == nullptr )
38+ {
39+ trace::Logger::Error (" Error in InitializeProfiler call. Tracer CLR Profiler was not initialized." );
40+ return ;
41+ }
42+
43+ trace::profiler->InitializeProfiler (id, items, size);
3144}
3245
3346EXTERN_C VOID STDAPICALLTYPE RemoveCallTargetDefinitions (WCHAR* id, trace::CallTargetDefinition* items, int size)
3447{
35- return trace::profiler->RemoveCallTargetDefinitions (id, items, size);
48+ if (trace::profiler == nullptr )
49+ {
50+ trace::Logger::Error (" Error in RemoveCallTargetDefinitions call. Tracer CLR Profiler was not initialized." );
51+ return ;
52+ }
53+
54+ trace::profiler->RemoveCallTargetDefinitions (id, items, size);
3655}
3756
3857EXTERN_C VOID STDAPICALLTYPE EnableByRefInstrumentation ()
3958{
40- return trace::profiler->EnableByRefInstrumentation ();
59+ if (trace::profiler == nullptr )
60+ {
61+ trace::Logger::Error (" Error in EnableByRefInstrumentation call. Tracer CLR Profiler was not initialized." );
62+ return ;
63+ }
64+
65+ trace::profiler->EnableByRefInstrumentation ();
4166}
4267
4368EXTERN_C VOID STDAPICALLTYPE EnableCallTargetStateByRef ()
4469{
45- return trace::profiler->EnableCallTargetStateByRef ();
70+ if (trace::profiler == nullptr )
71+ {
72+ trace::Logger::Error (" Error in EnableCallTargetStateByRef call. Tracer CLR Profiler was not initialized." );
73+ return ;
74+ }
75+
76+ trace::profiler->EnableCallTargetStateByRef ();
4677}
4778
4879EXTERN_C VOID STDAPICALLTYPE AddDerivedInstrumentations (WCHAR* id, trace::CallTargetDefinition* items, int size)
4980{
50- return trace::profiler->AddDerivedInstrumentations (id, items, size);
81+ if (trace::profiler == nullptr )
82+ {
83+ trace::Logger::Error (" Error in AddDerivedInstrumentations call. Tracer CLR Profiler was not initialized." );
84+ return ;
85+ }
86+
87+ trace::profiler->AddDerivedInstrumentations (id, items, size);
5188}
5289
5390EXTERN_C VOID STDAPICALLTYPE AddInterfaceInstrumentations (WCHAR* id, trace::CallTargetDefinition* items, int size)
5491{
55- return trace::profiler->AddInterfaceInstrumentations (id, items, size);
92+ if (trace::profiler == nullptr )
93+ {
94+ trace::Logger::Error (" Error in AddInterfaceInstrumentations call. Tracer CLR Profiler was not initialized." );
95+ return ;
96+ }
97+
98+ trace::profiler->AddInterfaceInstrumentations (id, items, size);
5699}
57100
58101EXTERN_C VOID STDAPICALLTYPE AddTraceAttributeInstrumentation (WCHAR* id, WCHAR* integration_assembly_name_ptr,
59102 WCHAR* integration_type_name_ptr)
60103{
61- return trace::profiler->AddTraceAttributeInstrumentation (id, integration_assembly_name_ptr,
104+ if (trace::profiler == nullptr )
105+ {
106+ trace::Logger::Error (" Error in AddTraceAttributeInstrumentation call. Tracer CLR Profiler was not initialized." );
107+ return ;
108+ }
109+
110+ trace::profiler->AddTraceAttributeInstrumentation (id, integration_assembly_name_ptr,
62111 integration_type_name_ptr);
63112}
64113
65114EXTERN_C VOID STDAPICALLTYPE InitializeTraceMethods (WCHAR* id, WCHAR* integration_assembly_name_ptr,
66115 WCHAR* integration_type_name_ptr, WCHAR* configuration_string_ptr)
67116{
68- return trace::profiler->InitializeTraceMethods (id, integration_assembly_name_ptr, integration_type_name_ptr,
69- configuration_string_ptr);
117+ if (trace::profiler == nullptr )
118+ {
119+ trace::Logger::Error (" Error in InitializeTraceMethods call. Tracer CLR Profiler was not initialized." );
120+ return ;
121+ }
122+
123+ trace::profiler->InitializeTraceMethods (id, integration_assembly_name_ptr, integration_type_name_ptr,
124+ configuration_string_ptr);
70125}
71126
72127EXTERN_C VOID STDAPICALLTYPE InstrumentProbes (
@@ -79,22 +134,46 @@ EXTERN_C VOID STDAPICALLTYPE InstrumentProbes(
79134 debugger::DebuggerRemoveProbesDefinition* revertProbes,
80135 int revertProbesLength)
81136{
82- return trace::profiler->InstrumentProbes (methodProbes, methodProbesLength, lineProbes, lineProbesLength, spanProbes, spanProbesLength, revertProbes, revertProbesLength);
137+ if (trace::profiler == nullptr )
138+ {
139+ trace::Logger::Error (" Error in InstrumentProbes call. Tracer CLR Profiler was not initialized." );
140+ return ;
141+ }
142+
143+ trace::profiler->InstrumentProbes (methodProbes, methodProbesLength, lineProbes, lineProbesLength, spanProbes, spanProbesLength, revertProbes, revertProbesLength);
83144}
84145
85146EXTERN_C int STDAPICALLTYPE GetProbesStatuses (WCHAR** probeIds, int probeIdsLength, debugger::DebuggerProbeStatus* probeStatuses)
86147{
148+ if (trace::profiler == nullptr )
149+ {
150+ trace::Logger::Error (" Error in GetProbesStatuses call. Tracer CLR Profiler was not initialized." );
151+ return 0 ;
152+ }
153+
87154 return trace::profiler->GetProbesStatuses (probeIds, probeIdsLength, probeStatuses);
88155}
89156
90157EXTERN_C VOID STDAPICALLTYPE DisableTracerCLRProfiler ()
91158{
92- return trace::profiler->DisableTracerCLRProfiler ();
159+ if (trace::profiler == nullptr )
160+ {
161+ trace::Logger::Error (" Error in DisableTracerCLRProfiler call. Tracer CLR Profiler was not initialized." );
162+ return ;
163+ }
164+
165+ trace::profiler->DisableTracerCLRProfiler ();
93166}
94167
95168EXTERN_C VOID STDAPICALLTYPE RegisterIastAspects (WCHAR** aspects, int aspectsLength)
96169{
97- return trace::profiler->RegisterIastAspects (aspects, aspectsLength);
170+ if (trace::profiler == nullptr )
171+ {
172+ trace::Logger::Error (" Error in RegisterIastAspects call. Tracer CLR Profiler was not initialized." );
173+ return ;
174+ }
175+
176+ trace::profiler->RegisterIastAspects (aspects, aspectsLength);
98177}
99178
100179
0 commit comments