共用方式為


ICorDebugVariableHome 介面

表示函數的局部變數或引數。

Methods

方法 Description
GetArgumentIndex 方法 取得函數引數的索引。
GetCode 方法 取得包含此 ICorDebugVariableHome 物件的 「ICorDebugCode」 實例。
GetLiveRange 方法 取得此變數所處的原生範圍。
GetLocationType 方法 取得變數原生位置的類型。
GetOffset 方法 從變數的基本暫存器取得位移。
GetRegister 方法 取得包含位置類型為 的 VLT_REGISTER變數的暫存器,以及位置類型 VLT_REGISTER_RELATIVE為 的變數的基本暫存器。
GetSlotIndex 方法 取得局部變數的受管理插槽索引。

Example

下列程式碼片段會使用名為 pCode4的 ICorDebugCode4 物件。

ICorDebugCode4 *pCode4 = NULL;
pCode->QueryInterface(IID_ICorDebugCode4, &pCode4);

ICorDebugVariableEnum *pVarLocEnum = NULL;
pCode4->EnumerateVariableHomes(&pVarLocEnum);

// retrieve local variables and arguments
ULONG celt = 0;
pVarLocEnum->GetCount(&celt);
ICorDebugVariableHome **homes = new ICorDebugVariableHome *[celt];
ULONG celtFetched = 0;
pVarLocEnum->Next(celt, homes, &celtFetched);

for (int i = 0; i < celtFetched; i++)
{
    VariableLocationType locType = VLT_INVALID;
    homes[i].GetLocationType(&locType);
    switch (locType)
    {
    case VLT_REGISTER:
        CorDebugRegister register = 0;
        locals[i].GetRegister(&register);
        // now we know which register it is in
        break;
    case VLT_REGISTER_RELATIVE:
        CorDebugRegister baseRegister = 0;
        LONG offset = 0;
        locals[i].GetRegister(&register);
        locals[i].GetOffset(&offset);
        // now we know the register-relative offset
        break;
    case VLT_INVALID:
        // handle case where we can't access the location
        break;
    }
}

需求

平台: 請參閱 .NET 支援的作業系統

標題: CorDebug.idl、CorDebug.h

圖書館: CorGuids.lib

.NET 版本: 從 .NET Framework 4.6.2 開始提供

另請參閱