/* Get IL to native offsets map */ HRESULT GetMethodNativeMap(MethodDesc* methodDesc, ULONG32* numMap, DebuggerILToNativeMap** map) { // Use the DebugInfoStore to get IL->Native maps. // It doesn't matter whether we're jitted, ngenned etc. DebugInfoRequest request; TADDR nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); request.InitFromStartingAddr(methodDesc, nativeCodeStartAddr); // Bounds info. ULONG32 countMapCopy; NewHolder<ICorDebugInfo::OffsetMapping> mapCopy(NULL); BOOL success = DebugInfoManager::GetBoundariesAndVars(request, DebugInfoStoreNew, NULL, // allocator &countMapCopy, &mapCopy, NULL, NULL); if (!success) { return E_FAIL; } // Need to convert map formats. *numMap = countMapCopy; *map = new (nothrow) DebuggerILToNativeMap[countMapCopy]; if (!*map) { return E_OUTOFMEMORY; } ULONG32 i; for (i = 0; i < *numMap; i++) { (*map)[i].ilOffset = mapCopy[i].ilOffset; (*map)[i].nativeStartOffset = mapCopy[i].nativeOffset; if (i > 0) { (*map)[i - 1].nativeEndOffset = (*map)[i].nativeStartOffset; } (*map)[i].source = mapCopy[i].source; } if (*numMap >= 1) { (*map)[i - 1].nativeEndOffset = 0; } return S_OK; }
// Returns TRUE if caller should resume execution. BOOL AdjustContextForVirtualStub( EXCEPTION_RECORD *pExceptionRecord, CONTEXT *pContext) { LIMITED_METHOD_CONTRACT; Thread * pThread = GetThread(); // We may not have a managed thread object. Example is an AV on the helper thread. // (perhaps during StubManager::IsStub) if (pThread == NULL) { return FALSE; } PCODE f_IP = GetIP(pContext); TADDR pInstr = PCODEToPINSTR(f_IP); VirtualCallStubManager::StubKind sk; VirtualCallStubManager::FindStubManager(f_IP, &sk); if (sk == VirtualCallStubManager::SK_DISPATCH) { if (*PTR_WORD(pInstr) != DISPATCH_STUB_FIRST_WORD) { _ASSERTE(!"AV in DispatchStub at unknown instruction"); return FALSE; } } else if (sk == VirtualCallStubManager::SK_RESOLVE) { if (*PTR_WORD(pInstr) != RESOLVE_STUB_FIRST_WORD) { _ASSERTE(!"AV in ResolveStub at unknown instruction"); return FALSE; } } else { return FALSE; } PCODE callsite = GetAdjustedCallAddress(GetLR(pContext)); // Lr must already have been saved before calling so it should not be necessary to restore Lr pExceptionRecord->ExceptionAddress = (PVOID)callsite; SetIP(pContext, callsite); return TRUE; }