| 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 StackWalkAction StackWalkFramesEx(Thread* pThread, |
| 78 | PREGDISPLAY pRD, |
| 79 | PSTACKWALKFRAMESCALLBACK pCallback, |
| 80 | VOID* pData, |
| 81 | unsigned int flags) = 0; |
| 82 | |
| 83 | virtual Frame *GetFrame(CrawlFrame*) = 0; |
| 84 | |
| 85 | virtual bool InitRegDisplay(Thread* pThread, |
| 86 | const PREGDISPLAY pRD, |
| 87 | const PT_CONTEXT pctx, |
| 88 | bool validContext) = 0; |
| 89 | |
| 90 | virtual BOOL IsStringObject(Object* o) = 0; |
| 91 | |
| 92 | virtual BOOL IsTypedReference(MethodTable* pMT) = 0; |
| 93 | |
| 94 | virtual WCHAR* StringObjectGetBuffer(StringObject* so) = 0; |
| 95 | |
| 96 | virtual DWORD StringObjectGetStringLength(StringObject* so) = 0; |
| 97 | |
| 98 | virtual void *GetObjectFromHandle(OBJECTHANDLE handle) = 0; |
| 99 | |
| 100 | virtual OBJECTHANDLE GetHandleFromObject(void *obj, |
| 101 | bool fStrongNewRef, |
| 102 | AppDomain *pAppDomain) = 0; |
| 103 | |
| 104 | virtual void DbgDestroyHandle( OBJECTHANDLE oh, bool fStrongNewRef ) = 0; |
| 105 | |
| 106 | virtual OBJECTHANDLE GetThreadException(Thread *pThread) = 0; |
| 107 | |
| 108 | virtual bool IsThreadExceptionNull(Thread *pThread) = 0; |
| 109 | |
| 110 | virtual void ClearThreadException(Thread *pThread) = 0; |
| 111 | |
| 112 | virtual bool StartSuspendForDebug(AppDomain *pAppDomain, |
| 113 | BOOL fHoldingThreadStoreLock = FALSE) = 0; |
| 114 | |
| 115 | virtual void ResumeFromDebug(AppDomain *pAppDomain)= 0; |
| 116 | |
| 117 | virtual void MarkThreadForDebugSuspend(Thread* pRuntimeThread) = 0; |
| 118 | |
| 119 | virtual void MarkThreadForDebugStepping(Thread* pRuntimeThread, |
| 120 | bool onOff) = 0; |
| 121 | |
| 122 | virtual void SetThreadFilterContext(Thread *thread, |
| 123 | T_CONTEXT *context) = 0; |
| 124 | |
| 125 | virtual T_CONTEXT *GetThreadFilterContext(Thread *thread) = 0; |
| 126 | |
| 127 | #ifdef FEATURE_INTEROP_DEBUGGING |
| 128 | virtual VOID *GetThreadDebuggerWord() = 0; |
| 129 | |
| 130 | virtual void SetThreadDebuggerWord(VOID *dw) = 0; |
| 131 | #endif |
| 132 | |
| 133 | virtual BOOL IsManagedNativeCode(const BYTE *address) = 0; |
| 134 | |
| 135 | #endif // #ifndef DACCESS_COMPILE |
| 136 | |
| 137 | virtual PCODE GetNativeCodeStartAddress(PCODE address) = 0; |
| 138 | |
| 139 | virtual MethodDesc *GetNativeCodeMethodDesc(const PCODE address) = 0; |
| 140 | |
| 141 | #ifndef DACCESS_COMPILE |
| 142 | |
| 143 | #ifndef USE_GC_INFO_DECODER |
| 144 | virtual BOOL IsInPrologOrEpilog(const BYTE *address, |
| 145 | size_t* prologSize) = 0; |
| 146 | #endif |
| 147 | |
| 148 | // Determine whether certain native offsets of the specified function are within |
| 149 | // an exception filter or handler. |
| 150 | virtual void DetermineIfOffsetsInFilterOrHandler(const BYTE *functionAddress, |
| 151 | DebugOffsetToHandlerInfo *pOffsetToHandlerInfo, |
| 152 | unsigned offsetToHandlerInfoLength) = 0; |
| 153 | |
| 154 | #endif // #ifndef DACCESS_COMPILE |
| 155 | |
| 156 | virtual void GetMethodRegionInfo(const PCODE pStart, |
| 157 | PCODE * pCold, |
| 158 | size_t * hotSize, |
| 159 | size_t * coldSize) = 0; |
| 160 | |
| 161 | #if defined(WIN64EXCEPTIONS) |
| 162 | virtual DWORD GetFuncletStartOffsets(const BYTE *pStart, DWORD* pStartOffsets, DWORD dwLength) = 0; |
| 163 | virtual StackFrame FindParentStackFrame(CrawlFrame* pCF) = 0; |
| 164 | #endif // WIN64EXCEPTIONS |
| 165 | |
| 166 | virtual size_t GetFunctionSize(MethodDesc *pFD) = 0; |
| 167 | |
| 168 | virtual PCODE GetFunctionAddress(MethodDesc *pFD) = 0; |
| 169 | |
| 170 | #ifndef DACCESS_COMPILE |
| 171 | |
| 172 | #ifdef EnC_SUPPORTED |
| 173 | |
| 174 | // Apply an EnC edit |
| 175 | virtual HRESULT EnCApplyChanges(EditAndContinueModule *pModule, |
| 176 | DWORD cbMetadata, |
| 177 | BYTE *pMetadata, |
| 178 | DWORD cbIL, |
| 179 | BYTE *pIL) = 0; |
| 180 | |
| 181 | // Perform an EnC remap to resume execution in the new version of a method (doesn't return) |
| 182 | virtual void ResumeInUpdatedFunction(EditAndContinueModule *pModule, |
| 183 | MethodDesc *pFD, |
| 184 | void *debuggerFuncHandle, |
| 185 | SIZE_T resumeIP, |
| 186 | CONTEXT *pContext) = 0; |
| 187 | #endif //EnC_SUPPORTED |
| 188 | |
| 189 | // |
| 190 | // New methods to support the new debugger. |
| 191 | // |
| 192 | |
| 193 | virtual MethodDesc *FindLoadedMethodRefOrDef(Module* pModule, |
| 194 | mdMemberRef memberRef) = 0; |
| 195 | |
| 196 | virtual MethodDesc *LoadMethodDef(Module* pModule, |
| 197 | mdMethodDef methodDef, |
| 198 | DWORD numGenericArgs = 0, |
| 199 | TypeHandle *pGenericArgs = NULL, |
| 200 | TypeHandle *pOwnerType = NULL) = 0; |
| 201 | |
| 202 | // These will lookup a type, and if it's not loaded, return the null TypeHandle |
| 203 | virtual TypeHandle FindLoadedClass(Module *pModule, |
| 204 | mdTypeDef classToken) = 0; |
| 205 | |
| 206 | virtual TypeHandle FindLoadedElementType(CorElementType et) = 0; |
| 207 | |
| 208 | virtual TypeHandle FindLoadedInstantiation(Module *pModule, |
| 209 | mdTypeDef typeDef, |
| 210 | DWORD ntypars, |
| 211 | TypeHandle *inst) = 0; |
| 212 | |
| 213 | virtual TypeHandle FindLoadedFnptrType(TypeHandle *inst, |
| 214 | DWORD ntypars) = 0; |
| 215 | |
| 216 | virtual TypeHandle FindLoadedPointerOrByrefType(CorElementType et, |
| 217 | TypeHandle elemtype) = 0; |
| 218 | |
| 219 | virtual TypeHandle FindLoadedArrayType(CorElementType et, |
| 220 | TypeHandle elemtype, |
| 221 | unsigned rank) = 0; |
| 222 | |
| 223 | // These will lookup a type, and if it's not loaded, will load and run |
| 224 | // the class init etc. |
| 225 | virtual TypeHandle LoadClass(Module *pModule, |
| 226 | mdTypeDef classToken) = 0; |
| 227 | |
| 228 | virtual TypeHandle LoadElementType(CorElementType et) = 0; |
| 229 | |
| 230 | virtual TypeHandle LoadInstantiation(Module *pModule, |
| 231 | mdTypeDef typeDef, |
| 232 | DWORD ntypars, |
| 233 | TypeHandle *inst) = 0; |
| 234 | |
| 235 | virtual TypeHandle LoadFnptrType(TypeHandle *inst, |
| 236 | DWORD ntypars) = 0; |
| 237 | |
| 238 | virtual TypeHandle LoadPointerOrByrefType(CorElementType et, |
| 239 | TypeHandle elemtype) = 0; |
| 240 | |
| 241 | virtual TypeHandle LoadArrayType(CorElementType et, |
| 242 | TypeHandle elemtype, |
| 243 | unsigned rank) = 0; |
| 244 | |
| 245 | __checkReturn |
| 246 | virtual HRESULT GetMethodImplProps(Module *pModule, |
| 247 | mdToken tk, |
| 248 | DWORD *pRVA, |
| 249 | DWORD *pImplFlags) = 0; |
| 250 | |
| 251 | virtual HRESULT GetParentToken(Module *pModule, |
| 252 | mdToken tk, |
| 253 | mdToken *pParentToken) = 0; |
| 254 | |
| 255 | virtual bool IsPreemptiveGCDisabled(void) = 0; |
| 256 | |
| 257 | virtual void DisablePreemptiveGC(void) = 0; |
| 258 | |
| 259 | virtual void EnablePreemptiveGC(void) = 0; |
| 260 | |
| 261 | virtual DWORD MethodDescIsStatic(MethodDesc *pFD) = 0; |
| 262 | |
| 263 | #endif // #ifndef DACCESS_COMPILE |
| 264 | |
| 265 | virtual Module *MethodDescGetModule(MethodDesc *pFD) = 0; |
| 266 | |
| 267 | #ifndef DACCESS_COMPILE |
| 268 | |
| 269 | virtual COR_ILMETHOD* (MethodDesc *pFD) = 0; |
| 270 | |
| 271 | virtual ULONG MethodDescGetRVA(MethodDesc *pFD) = 0; |
| 272 | |
| 273 | virtual void MarkDebuggerAttached(void) = 0; |
| 274 | |
| 275 | virtual void MarkDebuggerUnattached(void) = 0; |
| 276 | |
| 277 | virtual bool CrawlFrameIsGcSafe(CrawlFrame *pCF) = 0; |
| 278 | |
| 279 | virtual bool SweepThreadsForDebug(bool forceSync) = 0; |
| 280 | |
| 281 | virtual void GetRuntimeOffsets(SIZE_T *pTLSIndex, |
| 282 | SIZE_T *pTLSIsSpecialIndex, |
| 283 | SIZE_T *pTLSCantStopIndex, |
| 284 | SIZE_T *pEEThreadStateOffset, |
| 285 | SIZE_T *pEEThreadStateNCOffset, |
| 286 | SIZE_T *pEEThreadPGCDisabledOffset, |
| 287 | DWORD *pEEThreadPGCDisabledValue, |
| 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 | #ifndef DACCESS_COMPILE |
| 378 | virtual BOOL AdjustContextForWriteBarrierForDebugger(CONTEXT* context) = 0; |
| 379 | #endif |
| 380 | }; |
| 381 | |
| 382 | #endif // _eedbginterface_h_ |
| 383 | |