7451246a21c2f3bf3422f091332a4dd59b573d9f
[platform/upstream/coreclr.git] / src / vm / eedbginterfaceimpl.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5
6 /*
7  *
8  * COM+99 EE to Debugger Interface Implementation
9  *
10  */
11 #ifndef _eedbginterfaceimpl_h_
12 #define _eedbginterfaceimpl_h_
13
14 #ifdef DEBUGGING_SUPPORTED
15
16 #include "common.h"
17 #include "corpriv.h"
18 #include "hash.h"
19 #include "class.h"
20 #include "excep.h"
21 #include "field.h"
22 #include "eetwain.h"
23 #include "jitinterface.h"
24 #include "stubmgr.h"
25
26 #include "eedbginterface.h"
27 #include "debugdebugger.h"
28
29 #ifdef FEATURE_PREJIT
30 #include "corcompile.h"
31 #endif // FEATURE_PREJIT
32
33 #include "eeconfig.h"
34 #include "pefile.h"
35
36 class EEDbgInterfaceImpl : public EEDebugInterface
37 {
38     VPTR_VTABLE_CLASS_AND_CTOR(EEDbgInterfaceImpl, EEDebugInterface);
39
40 public:
41
42     virtual ~EEDbgInterfaceImpl() {}
43
44 #ifndef DACCESS_COMPILE
45
46     //
47     // Setup and global data used by this interface.
48     //
49     static FORCEINLINE void Init(void)
50     {
51         g_pEEDbgInterfaceImpl = new EEDbgInterfaceImpl(); // new throws on failure
52     }
53
54     //
55     // Cleanup any global data used by this interface.
56     //
57     static void Terminate(void);
58
59 #endif // #ifndef DACCESS_COMPILE
60
61     Thread* GetThread(void);
62
63     void SetEEThreadPtr(VOID* newPtr);
64
65     StackWalkAction StackWalkFramesEx(Thread* pThread,
66                                              PREGDISPLAY pRD,
67                                              PSTACKWALKFRAMESCALLBACK pCallback,
68                                              VOID* pData,
69                                       unsigned int flags);
70
71     Frame *GetFrame(CrawlFrame *pCF);
72
73     bool InitRegDisplay(Thread* pThread,
74                         const PREGDISPLAY pRD,
75             const PT_CONTEXT pctx,
76                         bool validContext);
77
78     BOOL IsStringObject(Object* o);
79
80     BOOL IsTypedReference(MethodTable* pMT);
81
82     WCHAR* StringObjectGetBuffer(StringObject* so);
83
84     DWORD StringObjectGetStringLength(StringObject* so);
85
86     void* GetObjectFromHandle(OBJECTHANDLE handle);
87
88     OBJECTHANDLE GetHandleFromObject(void *obj,
89                               bool fStrongNewRef,
90                               AppDomain *pAppDomain);
91
92     void DbgDestroyHandle(OBJECTHANDLE oh,
93                           bool fStrongNewRef);
94
95     OBJECTHANDLE GetThreadException(Thread *pThread);
96
97     bool IsThreadExceptionNull(Thread *pThread);
98
99     void ClearThreadException(Thread *pThread);
100
101     bool StartSuspendForDebug(AppDomain *pAppDomain,
102                               BOOL fHoldingThreadStoreLock);
103
104     bool SweepThreadsForDebug(bool forceSync);
105
106     void ResumeFromDebug(AppDomain *pAppDomain);
107
108     void MarkThreadForDebugSuspend(Thread* pRuntimeThread);
109
110     void MarkThreadForDebugStepping(Thread* pRuntimeThread,
111                                     bool onOff);
112
113     void SetThreadFilterContext(Thread *thread,
114                                 T_CONTEXT *context);
115
116     T_CONTEXT *GetThreadFilterContext(Thread *thread);
117
118     VOID *GetThreadDebuggerWord(Thread *thread);
119
120     void SetThreadDebuggerWord(Thread *thread,
121                                VOID *dw);
122
123     BOOL IsManagedNativeCode(const BYTE *address);
124
125     MethodDesc *GetNativeCodeMethodDesc(const PCODE address) DAC_UNEXPECTED();
126
127 #ifndef USE_GC_INFO_DECODER
128     BOOL IsInPrologOrEpilog(const BYTE *address,
129                             size_t* prologSize);
130 #endif
131
132     void DetermineIfOffsetsInFilterOrHandler(const BYTE *functionAddress,
133                                                   DebugOffsetToHandlerInfo *pOffsetToHandlerInfo,
134                                                   unsigned offsetToHandlerInfoLength);
135
136     void GetMethodRegionInfo(const PCODE pStart, 
137                              PCODE     * pCold, 
138                              size_t *hotSize,
139                              size_t *coldSize);
140
141 #if defined(WIN64EXCEPTIONS)
142     DWORD GetFuncletStartOffsets(const BYTE *pStart, DWORD* pStartOffsets, DWORD dwLength);
143     StackFrame FindParentStackFrame(CrawlFrame* pCF);
144 #endif // WIN64EXCEPTIONS
145
146     size_t GetFunctionSize(MethodDesc *pFD) DAC_UNEXPECTED();
147
148     const PCODE GetFunctionAddress(MethodDesc *pFD);
149
150     void DisablePreemptiveGC(void);
151
152     void EnablePreemptiveGC(void);
153
154     bool IsPreemptiveGCDisabled(void);
155
156     DWORD MethodDescIsStatic(MethodDesc *pFD);
157
158     Module *MethodDescGetModule(MethodDesc *pFD);
159
160     COR_ILMETHOD* MethodDescGetILHeader(MethodDesc *pFD);
161
162     ULONG MethodDescGetRVA(MethodDesc *pFD);
163
164     MethodDesc *FindLoadedMethodRefOrDef(Module* pModule,
165                                           mdToken memberRef);
166
167     MethodDesc *LoadMethodDef(Module* pModule,
168                               mdMethodDef methodDef,
169                               DWORD numGenericArgs = 0,
170                               TypeHandle *pGenericArgs = NULL,
171                               TypeHandle *pOwnerTypeRes = NULL);
172
173     TypeHandle FindLoadedClass(Module *pModule,
174                              mdTypeDef classToken);
175
176     TypeHandle FindLoadedInstantiation(Module *pModule,
177                                        mdTypeDef typeDef,
178                                        DWORD numGenericArgs,
179                                        TypeHandle *pGenericArgs);
180
181     TypeHandle FindLoadedFnptrType(TypeHandle *inst,
182                                    DWORD ntypars);
183
184     TypeHandle FindLoadedPointerOrByrefType(CorElementType et,
185                                             TypeHandle elemtype);
186
187     TypeHandle FindLoadedArrayType(CorElementType et,
188                                    TypeHandle elemtype,
189                                    unsigned rank);
190
191     TypeHandle FindLoadedElementType(CorElementType et);
192
193     TypeHandle LoadClass(Module *pModule,
194                        mdTypeDef classToken);
195
196     TypeHandle LoadInstantiation(Module *pModule,
197                                  mdTypeDef typeDef,
198                                  DWORD numGenericArgs,
199                                  TypeHandle *pGenericArgs);
200
201     TypeHandle LoadArrayType(CorElementType et,
202                              TypeHandle elemtype,
203                              unsigned rank);
204
205     TypeHandle LoadPointerOrByrefType(CorElementType et,
206                                       TypeHandle elemtype);
207
208     TypeHandle LoadFnptrType(TypeHandle *inst,
209                              DWORD ntypars);
210
211     TypeHandle LoadElementType(CorElementType et);
212     
213     __checkReturn 
214     HRESULT GetMethodImplProps(Module *pModule,
215                                mdToken tk,
216                                DWORD *pRVA,
217                                DWORD *pImplFlags);
218     
219     HRESULT GetParentToken(Module *pModule,
220                            mdToken tk,
221                            mdToken *pParentToken);
222
223     void MarkDebuggerAttached(void);
224
225     void MarkDebuggerUnattached(void);
226
227 #ifdef EnC_SUPPORTED
228
229     // Apply an EnC edit to the specified module
230     // This function should never return.
231     HRESULT EnCApplyChanges(EditAndContinueModule *pModule,
232                             DWORD cbMetadata,
233                             BYTE *pMetadata,
234                             DWORD cbIL,
235                             BYTE *pIL);
236
237     // Remap execution to the latest version of an edited method
238     void ResumeInUpdatedFunction(EditAndContinueModule *pModule,
239                                  MethodDesc *pFD,
240                                  void *debuggerFuncHandle,
241                                  SIZE_T resumeIP,
242                                  T_CONTEXT *pContext);
243   #endif // EnC_SUPPORTED
244
245     bool CrawlFrameIsGcSafe(CrawlFrame *pCF);
246
247     bool IsStub(const BYTE *ip);
248
249     bool DetectHandleILStubs(Thread *thread);
250
251     bool TraceStub(const BYTE *ip,
252                    TraceDestination *trace);
253
254     bool FollowTrace(TraceDestination *trace);
255
256     bool TraceFrame(Thread *thread,
257                     Frame *frame,
258                     BOOL fromPatch,
259                     TraceDestination *trace,
260                     REGDISPLAY *regs);
261
262     bool TraceManager(Thread *thread,
263                       StubManager *stubManager,
264                       TraceDestination *trace,
265                       T_CONTEXT *context,
266                       BYTE **pRetAddr);
267
268     void EnableTraceCall(Thread *thread);
269
270     void DisableTraceCall(Thread *thread);
271
272     void GetRuntimeOffsets(SIZE_T *pTLSIndex,
273                            SIZE_T *pTLSIsSpecialIndex,
274                            SIZE_T *pTLSCantStopIndex,
275                            SIZE_T *pEEThreadStateOffset,
276                            SIZE_T *pEEThreadStateNCOffset,
277                            SIZE_T *pEEThreadPGCDisabledOffset,
278                            DWORD  *pEEThreadPGCDisabledValue,
279                            SIZE_T *pEEThreadDebuggerWordOffset,
280                            SIZE_T *pEEThreadFrameOffset,
281                            SIZE_T *pEEThreadMaxNeededSize,
282                            DWORD  *pEEThreadSteppingStateMask,
283                            DWORD  *pEEMaxFrameValue,
284                            SIZE_T *pEEThreadDebuggerFilterContextOffset,
285                            SIZE_T *pEEThreadCantStopOffset,
286                            SIZE_T *pEEFrameNextOffset,
287                            DWORD  *pEEIsManagedExceptionStateMask);
288
289     void DebuggerModifyingLogSwitch (int iNewLevel,
290                                      const WCHAR *pLogSwitchName);
291
292     HRESULT SetIPFromSrcToDst(Thread *pThread,
293                               SLOT addrStart,
294                               DWORD offFrom,
295                               DWORD offTo,
296                               bool fCanSetIPOnly,
297                               PREGDISPLAY pReg,
298                               PT_CONTEXT pCtx,
299                               void *pDji,
300                               EHRangeTree *pEHRT);
301
302     void SetDebugState(Thread *pThread,
303                        CorDebugThreadState state);
304
305     void SetAllDebugState(Thread *et,
306                           CorDebugThreadState state);
307
308     // This is pretty much copied from VM\COMSynchronizable's
309     // INT32 __stdcall ThreadNative::GetThreadState, so propogate changes
310     // to both functions
311     CorDebugUserState GetPartialUserState( Thread *pThread );
312
313 #ifdef FEATURE_PREJIT
314 #ifndef DACCESS_COMPILE
315     virtual void SetNGENDebugFlags(BOOL fAllowOpt)
316     {
317         LIMITED_METHOD_CONTRACT;
318         PEFile::SetNGENDebugFlags(fAllowOpt);
319     }
320
321     virtual void GetNGENDebugFlags(BOOL *fAllowOpt)
322     {
323         LIMITED_METHOD_CONTRACT;
324         PEFile::GetNGENDebugFlags(fAllowOpt);
325     }
326 #endif
327 #endif // FEATURE_PREJIT
328
329 #ifdef DACCESS_COMPILE
330     virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
331 #endif
332
333     virtual unsigned GetSizeForCorElementType(CorElementType etyp);
334
335 #ifndef DACCESS_COMPILE
336     virtual BOOL ObjIsInstanceOf(Object *pElement, TypeHandle toTypeHnd);
337 #endif
338     
339     virtual void ClearAllDebugInterfaceReferences(void);
340     
341 #ifndef DACCESS_COMPILE
342 #ifdef _DEBUG
343     virtual void ObjectRefFlush(Thread *pThread);
344 #endif
345 #endif
346 };
347
348 #endif // DEBUGGING_SUPPORTED
349
350 #endif // _eedbginterfaceimpl_h_