Commit 2a159904 authored by ussrhero's avatar ussrhero

added static field modifier fot .Net objects

parent ac3ca71c
......@@ -326,4 +326,32 @@ void MetaDataProvider::getFields(mdTypeDef typeDef, NetFieldList& fields)
}
}
bool MetaDataProvider::isStaticField(mdFieldDef fieldDef)
{
std::vector<wchar_t> fieldNameBuf(0x100);
ULONG fieldNameLen;
mdTypeDef typeDef;
DWORD fieldAttr;
HRESULT hres = m_metaDataImport->GetFieldProps(
fieldDef,
&typeDef,
&fieldNameBuf.front(),
fieldNameBuf.size(),
&fieldNameLen,
&fieldAttr,
NULL,
NULL,
NULL,
NULL,
NULL);
if ( FAILED(hres) )
throw DbgException("Failed IMetaDataImport::GetFieldProps");
return (fieldAttr & CorFieldAttr::fdStatic) != 0;
}
}
......@@ -47,6 +47,8 @@ public:
void getFields(mdTypeDef typeDef, NetFieldList& fields);
bool isStaticField(mdFieldDef fieldDef);
private:
MetaDataProvider(ICorDebugModule* module);
......
......@@ -164,7 +164,11 @@ FieldsList NetObjectClass::getFieldsByType(ICorDebugType* corType)
for( auto field : fieldList )
{
fields.push_back( { field.first, field.second, corClass } );
const std::wstring& fieldName = field.first;
const mdFieldDef& fieldDef = field.second;
bool isStatic = m_metaDataProvder->isStaticField(fieldDef);
fields.push_back( { fieldName, fieldDef, corClass, isStatic } );
}
return fields;
......@@ -199,6 +203,11 @@ TypedVarPtr NetObjectClass::getElement( const std::wstring& fieldName )
}
}
if ( fieldDesc.isStatic )
{
throw DbgException("Cannot get static field value");
}
CComPtr<ICorDebugValue> fieldValue;
HRESULT hres = m_objectValue->GetFieldValue( fieldDesc.debugClass, fieldDesc.token, &fieldValue );
if (FAILED(hres))
......@@ -224,25 +233,40 @@ std::wstring NetObjectClass::str()
for ( auto field : m_fields )
{
CComPtr<ICorDebugValue> fieldValue;
MEMOFFSET_64 fieldAddress = 0;
if ( SUCCEEDED(m_objectValue->GetFieldValue( field.debugClass, field.token, &fieldValue ) ) &&
SUCCEEDED(fieldValue->GetAddress(&fieldAddress) ) )
{
MEMOFFSET_REL fieldOffset = static_cast<MEMOFFSET_REL>(fieldAddress - this->getAddress());
sstr << L" +" << std::right << std::setw(4) << std::setfill(L'0') << std::hex << fieldOffset;
sstr << L" " << std::left << std::setw(24) << std::setfill(L' ') << field.name << ':';
sstr << L" " << getElementValue(fieldValue)->printValue();
}
else
if ( field.isStatic )
{
sstr << L" ---- " << std::left << std::setw(24) << std::setfill(L' ') << field.name << ':';
std::wstring qualStr = L"static ";
qualStr +=field.name;
sstr << L" ---- " << std::left << std::setw(24) << std::setfill(L' ') << qualStr << L':';
sstr << L" " << L"Failed to get value";
sstr << std::endl;
}
}
sstr << std::endl;
for ( auto field : m_fields )
{
if ( !field.isStatic )
{
CComPtr<ICorDebugValue> fieldValue;
MEMOFFSET_64 fieldAddress = 0;
if ( SUCCEEDED(m_objectValue->GetFieldValue( field.debugClass, field.token, &fieldValue ) ) &&
SUCCEEDED(fieldValue->GetAddress(&fieldAddress) ) )
{
MEMOFFSET_REL fieldOffset = static_cast<MEMOFFSET_REL>(fieldAddress - this->getAddress());
sstr << L" +" << std::right << std::setw(4) << std::setfill(L'0') << std::hex << fieldOffset;
sstr << L" " << std::left << std::setw(24) << std::setfill(L' ') << field.name << L':';
sstr << L" " << getElementValue(fieldValue)->printValue();
}
else
{
sstr << L" ---- " << std::left << std::setw(24) << std::setfill(L' ') << field.name << L':';
sstr << L" " << L"Failed to get value";
}
sstr << std::endl;
}
}
return sstr.str();
......
......@@ -180,6 +180,7 @@ struct FieldDesc
std::wstring name;
mdFieldDef token;
CComPtr<ICorDebugClass> debugClass;
bool isStatic;
};
typedef std::vector< FieldDesc > FieldsList;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment