241ef332e2e304bee9d31d9750e87a28174717a0
[platform/upstream/coreclr.git] / src / vm / eedbginterface.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 // COM+99 EE to Debugger Interface Header
6 //
7
8
9
10 #ifndef _eedbginterface_h_
11 #define _eedbginterface_h_
12
13 #include "common.h"
14 #include "corpriv.h"
15 #include "hash.h"
16 #include "class.h"
17 #include "excep.h"
18 #include "threads.h"
19 #include "field.h"
20 #include "stackwalk.h"
21
22 #ifdef EnC_SUPPORTED
23 #include "encee.h"
24 #endif
25
26 #include "cordebug.h"
27 #include "../debug/inc/common.h"
28
29 class MethodDesc;
30 class Frame;
31 //
32 // The purpose of this object is to provide EE funcationality back to
33 // the debugger. This represents the entire set of EE functions used
34 // by the debugger.
35 //
36 // We will make this interface smaller over time to minimize the link
37 // between the EE and the Debugger.
38 //  
39 //
40 typedef BOOL (*HashMapEnumCallback)(HashMap* h,
41                                     void* pData,
42                                     ULONG value);
43
44 typedef enum AttachAppDomainEventsEnum
45 {
46     ONLY_SEND_APP_DOMAIN_CREATE_EVENTS,
47     DONT_SEND_CLASS_EVENTS,
48     ONLY_SEND_CLASS_EVENTS
49 } AttachAppDomainEventsEnum;
50
51 typedef VPTR(class EEDebugInterface) PTR_EEDebugInterface;
52
53 // Used for communicating EH Handler info between the LS and EE (DetermineIfOffsetsInFilterOrHandler)
54 struct DebugOffsetToHandlerInfo 
55 {
56     // Native offset of interest, or -1 if this entry should be ignored
57     SIZE_T offset;
58
59     // Set to true by the EE if the specified native offset is in an EH filter or handler.
60     BOOL isInFilterOrHandler;
61 };
62
63 class EEDebugInterface
64 {
65     VPTR_BASE_VTABLE_CLASS_AND_CTOR(EEDebugInterface);
66
67 public:
68
69     //
70     // Functions exported from the EE to the debugger.
71     //
72
73     virtual Thread* GetThread(void) = 0;
74
75 #ifndef DACCESS_COMPILE
76
77     virtual void SetEEThreadPtr(VOID* newPtr) = 0;
78
79     virtual StackWalkAction StackWalkFramesEx(Thread* pThread,
80                                               PREGDISPLAY pRD,
81                                               PSTACKWALKFRAMESCALLBACK pCallback,
82                                               VOID* pData,
83                                               unsigned int flags) = 0;
84
85     virtual Frame *GetFrame(CrawlFrame*) = 0;
86
87     virtual bool InitRegDisplay(Thread* pThread,
88                                 const PREGDISPLAY pRD,
89                                 const PT_CONTEXT pctx,
90                                 bool validContext) = 0;
91
92     virtual BOOL IsStringObject(Object* o) = 0;
93
94     virtual BOOL IsTypedReference(MethodTable* pMT) = 0;
95
96     virtual WCHAR* StringObjectGetBuffer(StringObject* so) = 0;
97
98     virtual DWORD StringObjectGetStringLength(StringObject* so) = 0;
99
100     virtual void *GetObjectFromHandle(OBJECTHANDLE handle) = 0;
101
102     virtual OBJECTHANDLE GetHandleFromObject(void *obj,
103                                       bool fStrongNewRef,
104                                       AppDomain *pAppDomain) = 0;
105
106     virtual void DbgDestroyHandle( OBJECTHANDLE oh, bool fStrongNewRef ) = 0;
107
108     virtual OBJECTHANDLE GetThreadException(Thread *pThread) = 0;
109
110     virtual bool IsThreadExceptionNull(Thread *pThread) = 0;
111
112     virtual void ClearThreadException(Thread *pThread) = 0;
113
114     virtual bool StartSuspendForDebug(AppDomain *pAppDomain,
115                                       BOOL fHoldingThreadStoreLock = FALSE) = 0;
116
117     virtual void ResumeFromDebug(AppDomain *pAppDomain)= 0;
118
119     virtual void MarkThreadForDebugSuspend(Thread* pRuntimeThread) = 0;
120
121     virtual void MarkThreadForDebugStepping(Thread* pRuntimeThread,
122                                             bool onOff) = 0;
123
124     virtual void SetThreadFilterContext(Thread *thread,
125                                         T_CONTEXT *context) = 0;
126
127     virtual T_CONTEXT *GetThreadFilterContext(Thread *thread) = 0;
128
129     virtual VOID *GetThreadDebuggerWord(Thread *thread) = 0;
130
131     virtual void SetThreadDebuggerWord(Thread *thread,
132                                        VOID *dw) = 0;
133
134     virtual BOOL IsManagedNativeCode(const BYTE *address) = 0;
135
136 #endif // #ifndef DACCESS_COMPILE
137
138     virtual MethodDesc *GetNativeCodeMethodDesc(const PCODE address) = 0;
139
140 #ifndef DACCESS_COMPILE
141
142 #ifndef USE_GC_INFO_DECODER
143     virtual BOOL IsInPrologOrEpilog(const BYTE *address,
144                                     size_t* prologSize) = 0;
145 #endif
146
147     // Determine whether certain native offsets of the specified function are within
148     // an exception filter or handler.
149     virtual void DetermineIfOffsetsInFilterOrHandler(const BYTE *functionAddress,
150                                                           DebugOffsetToHandlerInfo *pOffsetToHandlerInfo,
151                                                           unsigned offsetToHandlerInfoLength) = 0;
152
153 #endif // #ifndef DACCESS_COMPILE
154
155     virtual void GetMethodRegionInfo(const PCODE    pStart, 
156                                            PCODE  * pCold, 
157                                            size_t * hotSize, 
158                                            size_t * coldSize) = 0;
159
160 #if defined(WIN64EXCEPTIONS)
161     virtual DWORD GetFuncletStartOffsets(const BYTE *pStart, DWORD* pStartOffsets, DWORD dwLength) = 0;
162     virtual StackFrame FindParentStackFrame(CrawlFrame* pCF) = 0;
163 #endif // WIN64EXCEPTIONS
164
165     virtual size_t GetFunctionSize(MethodDesc *pFD) = 0;
166
167     virtual const PCODE GetFunctionAddress(MethodDesc *pFD) = 0;
168
169 #ifndef DACCESS_COMPILE
170
171 #ifdef EnC_SUPPORTED
172
173     // Apply an EnC edit
174     virtual HRESULT EnCApplyChanges(EditAndContinueModule *pModule,
175                                     DWORD cbMetadata,
176                                     BYTE *pMetadata,
177                                     DWORD cbIL,
178                                     BYTE *pIL) = 0;
179
180     // Perform an EnC remap to resume execution in the new version of a method (doesn't return)
181     virtual void ResumeInUpdatedFunction(EditAndContinueModule *pModule,
182                                          MethodDesc *pFD,
183                                          void *debuggerFuncHandle,
184                                          SIZE_T resumeIP,
185                                          CONTEXT *pContext) = 0;
186 #endif //EnC_SUPPORTED
187
188     //
189     // New methods to support the new debugger.
190     //
191
192     virtual MethodDesc *FindLoadedMethodRefOrDef(Module* pModule,
193                                                    mdMemberRef memberRef) = 0;
194
195     virtual MethodDesc *LoadMethodDef(Module* pModule,
196                                       mdMethodDef methodDef,
197                                       DWORD numGenericArgs = 0,
198                                       TypeHandle *pGenericArgs = NULL,
199                                       TypeHandle *pOwnerType = NULL) = 0;
200
201     // These will lookup a type, and if it's not loaded, return the null TypeHandle
202     virtual TypeHandle FindLoadedClass(Module *pModule,
203                                      mdTypeDef classToken) = 0;
204
205     virtual TypeHandle FindLoadedElementType(CorElementType et) = 0;
206
207     virtual TypeHandle FindLoadedInstantiation(Module *pModule,
208                                                mdTypeDef typeDef,
209                                                DWORD ntypars,
210                                                TypeHandle *inst) = 0;
211
212     virtual TypeHandle FindLoadedFnptrType(TypeHandle *inst,
213                                            DWORD ntypars) = 0;
214
215     virtual TypeHandle FindLoadedPointerOrByrefType(CorElementType et,
216                                                     TypeHandle elemtype) = 0;
217
218     virtual TypeHandle FindLoadedArrayType(CorElementType et,
219                                            TypeHandle elemtype,
220                                            unsigned rank) = 0;
221
222     // These will lookup a type, and if it's not loaded, will load and run
223     // the class init etc.
224     virtual TypeHandle LoadClass(Module *pModule,
225                                mdTypeDef classToken) = 0;
226
227     virtual TypeHandle LoadElementType(CorElementType et) = 0;
228
229     virtual TypeHandle LoadInstantiation(Module *pModule,
230                                          mdTypeDef typeDef,
231                                          DWORD ntypars,
232                                          TypeHandle *inst) = 0;
233
234     virtual TypeHandle LoadFnptrType(TypeHandle *inst,
235                                      DWORD ntypars) = 0;
236
237     virtual TypeHandle LoadPointerOrByrefType(CorElementType et,
238                                               TypeHandle elemtype) = 0;
239
240     virtual TypeHandle LoadArrayType(CorElementType et,
241                                      TypeHandle elemtype,
242                                      unsigned rank) = 0;
243     
244     __checkReturn 
245     virtual HRESULT GetMethodImplProps(Module *pModule,
246                                        mdToken tk,
247                                        DWORD *pRVA,
248                                        DWORD *pImplFlags) = 0;
249
250     virtual HRESULT GetParentToken(Module *pModule,
251                                    mdToken tk,
252                                    mdToken *pParentToken) = 0;
253
254     virtual bool IsPreemptiveGCDisabled(void) = 0;
255
256     virtual void DisablePreemptiveGC(void) = 0;
257
258     virtual void EnablePreemptiveGC(void) = 0;
259
260     virtual DWORD MethodDescIsStatic(MethodDesc *pFD) = 0;
261
262 #endif // #ifndef DACCESS_COMPILE
263
264     virtual Module *MethodDescGetModule(MethodDesc *pFD) = 0;
265
266 #ifndef DACCESS_COMPILE
267
268     virtual COR_ILMETHOD* MethodDescGetILHeader(MethodDesc *pFD) = 0;
269
270     virtual ULONG MethodDescGetRVA(MethodDesc *pFD) = 0;
271
272     virtual void MarkDebuggerAttached(void) = 0;
273
274     virtual void MarkDebuggerUnattached(void) = 0;
275
276     virtual bool CrawlFrameIsGcSafe(CrawlFrame *pCF) = 0;
277
278     virtual bool SweepThreadsForDebug(bool forceSync) = 0;
279
280    virtual void GetRuntimeOffsets(SIZE_T *pTLSIndex,
281                                   SIZE_T *pTLSIsSpecialIndex,
282                                   SIZE_T *pTLSCantStopIndex,
283                                   SIZE_T *pEEThreadStateOffset,
284                                   SIZE_T *pEEThreadStateNCOffset,
285                                   SIZE_T *pEEThreadPGCDisabledOffset,
286                                   DWORD  *pEEThreadPGCDisabledValue,
287                                   SIZE_T *pEEThreadDebuggerWordOffset,
288                                   SIZE_T *pEEThreadFrameOffset,
289                                   SIZE_T *pEEThreadMaxNeededSize,
290                                   DWORD  *pEEThreadSteppingStateMask,
291                                   DWORD  *pEEMaxFrameValue,
292                                   SIZE_T *pEEThreadDebuggerFilterContextOffset,
293                                   SIZE_T *pEEThreadCantStopMask,
294                                   SIZE_T *pEEFrameNextOffset,
295                                   DWORD  *pEEIsManagedExceptionStateMask) = 0;
296
297     virtual bool IsStub(const BYTE *ip) = 0;
298
299 #endif // #ifndef DACCESS_COMPILE
300
301     virtual bool DetectHandleILStubs(Thread *thread) = 0;
302
303     virtual bool TraceStub(const BYTE *ip, TraceDestination *trace) = 0;
304
305 #ifndef DACCESS_COMPILE
306
307     virtual bool FollowTrace(TraceDestination *trace) = 0;
308
309     virtual bool TraceFrame(Thread *thread,
310                             Frame *frame,
311                             BOOL fromPatch,
312                             TraceDestination *trace,
313                             REGDISPLAY *regs) = 0;
314
315     virtual bool TraceManager(Thread *thread,
316                               StubManager *stubManager,
317                               TraceDestination *trace,
318                               T_CONTEXT *context,
319                               BYTE **pRetAddr) = 0;
320
321     virtual void EnableTraceCall(Thread *thread) = 0;
322     virtual void DisableTraceCall(Thread *thread) = 0;
323
324 #endif // #ifndef DACCESS_COMPILE
325
326 #ifndef DACCESS_COMPILE
327
328     virtual void DebuggerModifyingLogSwitch (int iNewLevel,
329                                              const WCHAR *pLogSwitchName) = 0;
330
331     virtual HRESULT SetIPFromSrcToDst(Thread *pThread,
332                           SLOT addrStart,
333                           DWORD offFrom,
334                           DWORD offTo,
335                           bool fCanSetIPOnly,
336                           PREGDISPLAY pReg,
337                           PT_CONTEXT pCtx,
338                           void *pDji,
339                           EHRangeTree *pEHRT) = 0;
340
341     virtual void SetDebugState(Thread *pThread,
342                                CorDebugThreadState state) = 0;
343
344     virtual void SetAllDebugState(Thread *et,
345                                   CorDebugThreadState state) = 0;
346
347     virtual CorDebugUserState GetPartialUserState( Thread *pThread ) = 0;
348
349 #ifdef FEATURE_PREJIT
350 #ifndef DACCESS_COMPILE
351     virtual void SetNGENDebugFlags(BOOL fAllowOpt) = 0;
352
353     virtual void GetNGENDebugFlags(BOOL *fAllowOpt) = 0;
354 #endif
355 #endif // FEATURE_PREJIT
356
357 #endif // #ifndef DACCESS_COMPILE
358
359 #ifdef DACCESS_COMPILE
360     virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags) = 0;
361 #endif
362
363     virtual unsigned GetSizeForCorElementType(CorElementType etyp) = 0;
364
365 #ifndef DACCESS_COMPILE
366     virtual BOOL ObjIsInstanceOf(Object *pElement, TypeHandle toTypeHnd) = 0;
367 #endif
368
369     virtual void ClearAllDebugInterfaceReferences(void) = 0;
370
371 #ifndef DACCESS_COMPILE
372 #ifdef _DEBUG
373     virtual void ObjectRefFlush(Thread *pThread) = 0;
374 #endif
375 #endif
376 };
377
378 #endif // _eedbginterface_h_